just-bash 3.6.0 → 3.6.2

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 (891) hide show
  1. package/CHANGELOG.md +59 -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/dist-Q3QP7DWN.js +141 -0
  94. package/dist/bin/chunks/du-M2PB5NUH.js +3 -0
  95. package/dist/bin/chunks/env-EUSAZGWO.js +3 -0
  96. package/dist/bin/chunks/expand-B4CPOZN5.js +3 -0
  97. package/dist/bin/chunks/expr-AQBMSEFL.js +3 -0
  98. package/dist/bin/chunks/file-22CVQBNS.js +3 -0
  99. package/dist/bin/chunks/find-QYLHUYOP.js +3 -0
  100. package/dist/bin/chunks/flag-coverage-CTPK5ZWJ.js +3 -0
  101. package/dist/bin/chunks/fold-E6A5I4DW.js +3 -0
  102. package/dist/bin/chunks/grep-HI55D7F7.js +3 -0
  103. package/dist/bin/chunks/gzip-2GJMVXCF.js +3 -0
  104. package/dist/bin/chunks/head-ZQIB2GSI.js +3 -0
  105. package/dist/bin/chunks/html-to-markdown-7ZNLM4SQ.js +3 -0
  106. package/dist/bin/chunks/join-KCYMLQ3V.js +3 -0
  107. package/dist/bin/chunks/jq-KNI4FJIL.js +3 -0
  108. package/dist/bin/chunks/js-exec-OWDAX677.js +1617 -0
  109. package/dist/bin/chunks/ls-QCAGDEDW.js +3 -0
  110. package/dist/bin/chunks/md5sum-OPJ77ZY7.js +3 -0
  111. package/dist/bin/chunks/mkdir-3XFSFVPC.js +3 -0
  112. package/dist/bin/chunks/mktemp-5FA55IJS.js +3 -0
  113. package/dist/bin/chunks/mv-UASF6NAX.js +3 -0
  114. package/dist/bin/chunks/nl-HUDE6DQC.js +3 -0
  115. package/dist/bin/chunks/od-CECQKF5P.js +3 -0
  116. package/dist/bin/chunks/paste-SH5RZ4ZO.js +3 -0
  117. package/dist/bin/chunks/printf-PQKUEWX5.js +3 -0
  118. package/dist/bin/chunks/python3-UE36ZXQT.js +23 -0
  119. package/dist/bin/chunks/readlink-4Z75K3AI.js +3 -0
  120. package/dist/bin/chunks/rev-6SA3VC3J.js +3 -0
  121. package/dist/bin/chunks/rg-ULWB5MQG.js +3 -0
  122. package/dist/bin/chunks/rm-NPIAQT6U.js +3 -0
  123. package/dist/bin/chunks/rmdir-57J3AGQU.js +3 -0
  124. package/dist/bin/chunks/sed-XV7BZPKI.js +3 -0
  125. package/dist/bin/chunks/seq-ZVBT2JEI.js +3 -0
  126. package/dist/bin/chunks/sha1sum-JGOB5K4J.js +3 -0
  127. package/dist/bin/chunks/sha256sum-S5DS6Q6N.js +3 -0
  128. package/dist/bin/chunks/sort-UOMFLGRW.js +3 -0
  129. package/dist/bin/chunks/split-IBL3NIVH.js +3 -0
  130. package/dist/bin/chunks/sqlite3-YIM3BYLS.js +3 -0
  131. package/dist/bin/chunks/stat-RKSIL4YV.js +3 -0
  132. package/dist/bin/chunks/strings-AL7T5GDQ.js +3 -0
  133. package/dist/bin/chunks/tac-36B6LBNS.js +3 -0
  134. package/dist/bin/chunks/tail-G4PLDIOK.js +3 -0
  135. package/dist/bin/chunks/tar-YG6SY2RU.js +3 -0
  136. package/dist/bin/chunks/tee-NP4ULCWD.js +3 -0
  137. package/dist/bin/chunks/time-ZMFJL7MD.js +3 -0
  138. package/dist/bin/chunks/timeout-EJIGKZUX.js +3 -0
  139. package/dist/bin/chunks/touch-YE5LMLLE.js +3 -0
  140. package/dist/bin/chunks/tr-7KFUMSUF.js +3 -0
  141. package/dist/bin/chunks/unexpand-67EBVEPB.js +3 -0
  142. package/dist/bin/chunks/uniq-SZDRNEYK.js +3 -0
  143. package/dist/bin/chunks/wc-VLOME6PL.js +3 -0
  144. package/dist/bin/chunks/xan-FVGJAHFV.js +3 -0
  145. package/dist/bin/chunks/xan-view-LYATQWQB.js +3 -0
  146. package/dist/bin/chunks/xargs-CLQL2WFV.js +3 -0
  147. package/dist/bin/chunks/yes-OOBLAITP.js +3 -0
  148. package/dist/bin/chunks/yq-YQ4YFM26.js +3 -0
  149. package/dist/bin/just-bash.js +347 -345
  150. package/dist/bin/shell/chunks/awk2-EPZ2CEQT.js +3 -0
  151. package/dist/bin/shell/chunks/base64-D7ZXJQN6.js +3 -0
  152. package/dist/bin/shell/chunks/bash-4Q4RMIZL.js +3 -0
  153. package/dist/bin/shell/chunks/cat-AST5Y57Y.js +3 -0
  154. package/dist/bin/shell/chunks/chmod-BFP7P5CD.js +3 -0
  155. package/dist/bin/shell/chunks/chunk-26O2G5LX.js +34 -0
  156. package/dist/bin/shell/chunks/chunk-2RDKEB6Z.js +15 -0
  157. package/dist/bin/shell/chunks/chunk-35U2THFB.js +3 -0
  158. package/dist/bin/shell/chunks/chunk-3F7UWBEM.js +17 -0
  159. package/dist/bin/shell/chunks/chunk-3WLAERUX.js +3 -0
  160. package/dist/bin/shell/chunks/chunk-3WZIZUMC.js +8 -0
  161. package/dist/bin/shell/chunks/chunk-4ARWO6Y3.js +4 -0
  162. package/dist/bin/shell/chunks/chunk-4HVMRZ5N.js +8 -0
  163. package/dist/bin/shell/chunks/chunk-5AS7PRVN.js +34 -0
  164. package/dist/bin/shell/chunks/chunk-5GYAEVIB.js +10 -0
  165. package/dist/bin/shell/chunks/chunk-5IPYW47P.js +27 -0
  166. package/dist/bin/shell/chunks/chunk-5ZTIV6TI.js +20 -0
  167. package/dist/bin/shell/chunks/chunk-6C2YS7G6.js +14 -0
  168. package/dist/bin/shell/chunks/chunk-74MYVPDY.js +3 -0
  169. package/dist/bin/shell/chunks/chunk-74UP5NWP.js +3 -0
  170. package/dist/bin/shell/chunks/chunk-7DPD5PK3.js +3 -0
  171. package/dist/bin/shell/chunks/chunk-7LJGZPVP.js +18 -0
  172. package/dist/bin/shell/chunks/chunk-7NEXHFSS.js +3 -0
  173. package/dist/bin/shell/chunks/chunk-7XFMCB5C.js +21 -0
  174. package/dist/bin/shell/chunks/chunk-A53Y4KDG.js +7 -0
  175. package/dist/bin/shell/chunks/chunk-AALAYQ6J.js +17 -0
  176. package/dist/bin/shell/chunks/chunk-AM4WIHAG.js +10 -0
  177. package/dist/bin/shell/chunks/chunk-BC5OXEFJ.js +3 -0
  178. package/dist/bin/shell/chunks/chunk-C5ABXV4P.js +15 -0
  179. package/dist/bin/shell/chunks/chunk-CT6P7ILU.js +3 -0
  180. package/dist/bin/shell/chunks/chunk-CYHG3NVG.js +9 -0
  181. package/dist/bin/shell/chunks/chunk-D7PDAJWE.js +7 -0
  182. package/dist/bin/shell/chunks/chunk-DB3G3UVZ.js +5 -0
  183. package/dist/bin/shell/chunks/chunk-EIUU35ZP.js +37 -0
  184. package/dist/bin/shell/chunks/chunk-EMHJNKV5.js +20 -0
  185. package/dist/bin/shell/chunks/chunk-EPWMLTS6.js +9 -0
  186. package/dist/bin/shell/chunks/chunk-F4QFFLWZ.js +8 -0
  187. package/dist/bin/shell/chunks/chunk-F5R5O2Y6.js +9 -0
  188. package/dist/bin/shell/chunks/chunk-FBEYY2HM.js +13 -0
  189. package/dist/bin/shell/chunks/chunk-FIJBWMXU.js +12 -0
  190. package/dist/bin/shell/chunks/chunk-FMVH4N2P.js +5 -0
  191. package/dist/bin/shell/chunks/chunk-G6W2HMNY.js +7 -0
  192. package/dist/bin/shell/chunks/chunk-GFI5BHZX.js +3 -0
  193. package/dist/bin/shell/chunks/chunk-GJAVHEWO.js +143 -0
  194. package/dist/bin/shell/chunks/chunk-GUVSOVQU.js +8 -0
  195. package/dist/bin/shell/chunks/chunk-H22PAKR6.js +3 -0
  196. package/dist/bin/shell/chunks/chunk-HXOJHK2Z.js +8 -0
  197. package/dist/bin/shell/chunks/chunk-IAAYIH44.js +3 -0
  198. package/dist/bin/shell/chunks/chunk-J7W2CRXT.js +7 -0
  199. package/dist/bin/shell/chunks/chunk-JNWWOKCN.js +6 -0
  200. package/dist/bin/shell/chunks/chunk-JQLGE4OW.js +22 -0
  201. package/dist/bin/shell/chunks/chunk-K3U4M4MF.js +7 -0
  202. package/dist/bin/shell/chunks/chunk-KRXYOWIP.js +12 -0
  203. package/dist/bin/shell/chunks/chunk-L4L2QFS4.js +10 -0
  204. package/dist/bin/shell/chunks/chunk-LU6ZEQNN.js +13 -0
  205. package/dist/bin/shell/chunks/chunk-MLMKRR7L.js +12 -0
  206. package/dist/bin/shell/chunks/chunk-MVN5WALS.js +7 -0
  207. package/dist/bin/shell/chunks/chunk-MYOGTYIH.js +22 -0
  208. package/dist/bin/shell/chunks/chunk-NF5LHCVV.js +275 -0
  209. package/dist/bin/shell/chunks/chunk-OUGDZVL6.js +10 -0
  210. package/dist/bin/shell/chunks/chunk-QCNQD6ME.js +11 -0
  211. package/dist/bin/shell/chunks/chunk-QIDBJNMB.js +3 -0
  212. package/dist/bin/shell/chunks/chunk-QKTQYL37.js +9 -0
  213. package/dist/bin/shell/chunks/chunk-R6CMNMNX.js +22 -0
  214. package/dist/bin/shell/chunks/chunk-RCP3WQND.js +7 -0
  215. package/dist/bin/shell/chunks/chunk-RJG4JS32.js +6 -0
  216. package/dist/bin/shell/chunks/chunk-SIMSIBUA.js +13 -0
  217. package/dist/bin/shell/chunks/chunk-TNB7M24H.js +87 -0
  218. package/dist/bin/shell/chunks/chunk-TU6P6AC2.js +4 -0
  219. package/dist/bin/shell/chunks/chunk-TX4WSLXK.js +101 -0
  220. package/dist/bin/shell/chunks/chunk-U4UY6P77.js +3 -0
  221. package/dist/bin/shell/chunks/chunk-U5BNATW4.js +3 -0
  222. package/dist/bin/shell/chunks/chunk-U7VJCJQR.js +16 -0
  223. package/dist/bin/shell/chunks/chunk-VJE2PQW6.js +15 -0
  224. package/dist/bin/shell/chunks/chunk-W4ENG3BR.js +44 -0
  225. package/dist/bin/shell/chunks/chunk-XUFO4QPW.js +65 -0
  226. package/dist/bin/shell/chunks/chunk-XVKL2UZA.js +4 -0
  227. package/dist/bin/shell/chunks/chunk-YCUNLSHF.js +12 -0
  228. package/dist/bin/shell/chunks/chunk-YDH7Q5WV.js +6 -0
  229. package/dist/bin/shell/chunks/chunk-YDWLU56G.js +26 -0
  230. package/dist/bin/shell/chunks/chunk-YILPYZYP.js +16 -0
  231. package/dist/bin/shell/chunks/chunk-YZQ4SVJV.js +13 -0
  232. package/dist/bin/shell/chunks/chunk-ZKLKNN6B.js +3 -0
  233. package/dist/bin/shell/chunks/column-EGAQ7QMC.js +3 -0
  234. package/dist/bin/shell/chunks/comm-JEJ6GWEA.js +3 -0
  235. package/dist/bin/shell/chunks/cp-7AH7TSQ6.js +3 -0
  236. package/dist/bin/shell/chunks/curl-7FCZQCFU.js +31 -0
  237. package/dist/bin/shell/chunks/cut-OVTLUT2B.js +3 -0
  238. package/dist/bin/shell/chunks/date-MKP5YWWY.js +3 -0
  239. package/dist/bin/shell/chunks/diff-R6QTSWD2.js +3 -0
  240. package/dist/bin/shell/chunks/dist-Q3QP7DWN.js +141 -0
  241. package/dist/bin/shell/chunks/du-M2PB5NUH.js +3 -0
  242. package/dist/bin/shell/chunks/env-EUSAZGWO.js +3 -0
  243. package/dist/bin/shell/chunks/expand-B4CPOZN5.js +3 -0
  244. package/dist/bin/shell/chunks/expr-AQBMSEFL.js +3 -0
  245. package/dist/bin/shell/chunks/file-22CVQBNS.js +3 -0
  246. package/dist/bin/shell/chunks/find-QYLHUYOP.js +3 -0
  247. package/dist/bin/shell/chunks/flag-coverage-CTPK5ZWJ.js +3 -0
  248. package/dist/bin/shell/chunks/fold-E6A5I4DW.js +3 -0
  249. package/dist/bin/shell/chunks/grep-HI55D7F7.js +3 -0
  250. package/dist/bin/shell/chunks/gzip-2GJMVXCF.js +3 -0
  251. package/dist/bin/shell/chunks/head-ZQIB2GSI.js +3 -0
  252. package/dist/bin/shell/chunks/html-to-markdown-7ZNLM4SQ.js +3 -0
  253. package/dist/bin/shell/chunks/join-KCYMLQ3V.js +3 -0
  254. package/dist/bin/shell/chunks/jq-KNI4FJIL.js +3 -0
  255. package/dist/bin/shell/chunks/js-exec-OWDAX677.js +1617 -0
  256. package/dist/bin/shell/chunks/ls-QCAGDEDW.js +3 -0
  257. package/dist/bin/shell/chunks/md5sum-OPJ77ZY7.js +3 -0
  258. package/dist/bin/shell/chunks/mkdir-3XFSFVPC.js +3 -0
  259. package/dist/bin/shell/chunks/mktemp-5FA55IJS.js +3 -0
  260. package/dist/bin/shell/chunks/mv-UASF6NAX.js +3 -0
  261. package/dist/bin/shell/chunks/nl-HUDE6DQC.js +3 -0
  262. package/dist/bin/shell/chunks/od-CECQKF5P.js +3 -0
  263. package/dist/bin/shell/chunks/paste-SH5RZ4ZO.js +3 -0
  264. package/dist/bin/shell/chunks/printf-PQKUEWX5.js +3 -0
  265. package/dist/bin/shell/chunks/python3-UE36ZXQT.js +23 -0
  266. package/dist/bin/shell/chunks/readlink-4Z75K3AI.js +3 -0
  267. package/dist/bin/shell/chunks/rev-6SA3VC3J.js +3 -0
  268. package/dist/bin/shell/chunks/rg-ULWB5MQG.js +3 -0
  269. package/dist/bin/shell/chunks/rm-NPIAQT6U.js +3 -0
  270. package/dist/bin/shell/chunks/rmdir-57J3AGQU.js +3 -0
  271. package/dist/bin/shell/chunks/sed-XV7BZPKI.js +3 -0
  272. package/dist/bin/shell/chunks/seq-ZVBT2JEI.js +3 -0
  273. package/dist/bin/shell/chunks/sha1sum-JGOB5K4J.js +3 -0
  274. package/dist/bin/shell/chunks/sha256sum-S5DS6Q6N.js +3 -0
  275. package/dist/bin/shell/chunks/sort-UOMFLGRW.js +3 -0
  276. package/dist/bin/shell/chunks/split-IBL3NIVH.js +3 -0
  277. package/dist/bin/shell/chunks/sqlite3-YIM3BYLS.js +3 -0
  278. package/dist/bin/shell/chunks/stat-RKSIL4YV.js +3 -0
  279. package/dist/bin/shell/chunks/strings-AL7T5GDQ.js +3 -0
  280. package/dist/bin/shell/chunks/tac-36B6LBNS.js +3 -0
  281. package/dist/bin/shell/chunks/tail-G4PLDIOK.js +3 -0
  282. package/dist/bin/shell/chunks/tar-YG6SY2RU.js +3 -0
  283. package/dist/bin/shell/chunks/tee-NP4ULCWD.js +3 -0
  284. package/dist/bin/shell/chunks/time-ZMFJL7MD.js +3 -0
  285. package/dist/bin/shell/chunks/timeout-EJIGKZUX.js +3 -0
  286. package/dist/bin/shell/chunks/touch-YE5LMLLE.js +3 -0
  287. package/dist/bin/shell/chunks/tr-7KFUMSUF.js +3 -0
  288. package/dist/bin/shell/chunks/unexpand-67EBVEPB.js +3 -0
  289. package/dist/bin/shell/chunks/uniq-SZDRNEYK.js +3 -0
  290. package/dist/bin/shell/chunks/wc-VLOME6PL.js +3 -0
  291. package/dist/bin/shell/chunks/xan-FVGJAHFV.js +3 -0
  292. package/dist/bin/shell/chunks/xan-view-LYATQWQB.js +3 -0
  293. package/dist/bin/shell/chunks/xargs-CLQL2WFV.js +3 -0
  294. package/dist/bin/shell/chunks/yes-OOBLAITP.js +3 -0
  295. package/dist/bin/shell/chunks/yq-YQ4YFM26.js +3 -0
  296. package/dist/bin/shell/shell.js +385 -383
  297. package/dist/bundle/browser.js +873 -863
  298. package/dist/bundle/chunks/awk2-LEEKKBPN.js +2 -0
  299. package/dist/bundle/chunks/base64-GBEVK7UP.js +2 -0
  300. package/dist/bundle/chunks/bash-QTX2IUM4.js +2 -0
  301. package/dist/bundle/chunks/cat-UBR2ABBH.js +2 -0
  302. package/dist/bundle/chunks/chmod-5VBARXGU.js +2 -0
  303. package/dist/bundle/chunks/chunk-2LOOLBWC.js +33 -0
  304. package/dist/bundle/chunks/chunk-34XJ6PLO.js +20 -0
  305. package/dist/bundle/chunks/chunk-3DUKINTI.js +7 -0
  306. package/dist/bundle/chunks/chunk-3VXY25LY.js +2 -0
  307. package/dist/bundle/chunks/chunk-5G2D2EZB.js +7 -0
  308. package/dist/bundle/chunks/chunk-5Q4R6KJE.js +4 -0
  309. package/dist/bundle/chunks/chunk-5ZVTEBKG.js +7 -0
  310. package/dist/bundle/chunks/chunk-77XFWF43.js +13 -0
  311. package/dist/bundle/chunks/chunk-B2EYYRZX.js +9 -0
  312. package/dist/bundle/chunks/chunk-BC3VKZCL.js +10 -0
  313. package/dist/bundle/chunks/chunk-BEIP3OYT.js +6 -0
  314. package/dist/bundle/chunks/chunk-BLTFJFWH.js +2 -0
  315. package/dist/bundle/chunks/chunk-C2GCPQ2D.js +15 -0
  316. package/dist/bundle/chunks/chunk-CGCA7SGA.js +25 -0
  317. package/dist/bundle/chunks/chunk-CIY4XCGA.js +2 -0
  318. package/dist/bundle/chunks/chunk-CXBOPNEG.js +11 -0
  319. package/dist/bundle/chunks/chunk-CYJQAYUX.js +142 -0
  320. package/dist/bundle/chunks/chunk-D55UUXDJ.js +100 -0
  321. package/dist/bundle/chunks/chunk-EOMWWW4L.js +33 -0
  322. package/dist/bundle/chunks/chunk-ER6ZGLPS.js +26 -0
  323. package/dist/bundle/chunks/chunk-EZHC6HLV.js +3 -0
  324. package/dist/bundle/chunks/chunk-FBRDM6EM.js +12 -0
  325. package/dist/bundle/chunks/chunk-FDAXSABU.js +11 -0
  326. package/dist/bundle/chunks/chunk-FEKEA5Y2.js +2 -0
  327. package/dist/bundle/chunks/chunk-GEANXVKK.js +15 -0
  328. package/dist/bundle/chunks/chunk-GIQ3LRFL.js +21 -0
  329. package/dist/bundle/chunks/chunk-HBIJBKHP.js +14 -0
  330. package/dist/bundle/chunks/chunk-IDYF47VD.js +11 -0
  331. package/dist/bundle/chunks/chunk-IH6MZAKK.js +6 -0
  332. package/dist/bundle/chunks/chunk-IIWAWB3H.js +274 -0
  333. package/dist/bundle/chunks/chunk-IQGNPH54.js +8 -0
  334. package/dist/bundle/chunks/chunk-IVYY6YFV.js +7 -0
  335. package/dist/bundle/chunks/chunk-IXOG2DXK.js +14 -0
  336. package/dist/bundle/chunks/chunk-J6QAN4PZ.js +6 -0
  337. package/dist/bundle/chunks/chunk-JMGGZYF2.js +2 -0
  338. package/dist/bundle/chunks/chunk-JU5GJH4X.js +9 -0
  339. package/dist/bundle/chunks/chunk-JWGTQTBU.js +16 -0
  340. package/dist/bundle/chunks/chunk-KQSMX4HM.js +11 -0
  341. package/dist/bundle/chunks/chunk-KZMK2KYL.js +43 -0
  342. package/dist/bundle/chunks/chunk-L4MC7WH4.js +14 -0
  343. package/dist/bundle/chunks/chunk-L5AKA7GO.js +5 -0
  344. package/dist/bundle/chunks/chunk-LBKOJW6K.js +2 -0
  345. package/dist/bundle/chunks/chunk-LNJ6EIKX.js +2 -0
  346. package/dist/bundle/chunks/chunk-LQXMSLW5.js +16 -0
  347. package/dist/bundle/chunks/chunk-MOOFDAFS.js +7 -0
  348. package/dist/bundle/chunks/chunk-N3VQQRLQ.js +8 -0
  349. package/dist/bundle/chunks/chunk-NJUHQKMR.js +3 -0
  350. package/dist/bundle/chunks/chunk-NOZTFL4F.js +12 -0
  351. package/dist/bundle/chunks/chunk-OEZKBUXP.js +8 -0
  352. package/dist/bundle/chunks/chunk-OZMQI3HV.js +17 -0
  353. package/dist/bundle/chunks/chunk-POI4XBDP.js +6 -0
  354. package/dist/bundle/chunks/chunk-PV2DCWLJ.js +6 -0
  355. package/dist/bundle/chunks/chunk-Q6ZH76O4.js +2 -0
  356. package/dist/bundle/chunks/chunk-QECDICRF.js +9 -0
  357. package/dist/bundle/chunks/chunk-QJTRVYQA.js +5 -0
  358. package/dist/bundle/chunks/chunk-QZPG6UCH.js +9 -0
  359. package/dist/bundle/chunks/chunk-R23EAHN5.js +2 -0
  360. package/dist/bundle/chunks/chunk-R3HY2GCO.js +3 -0
  361. package/dist/bundle/chunks/chunk-RQTEROQ5.js +6 -0
  362. package/dist/bundle/chunks/chunk-SAE7VUIM.js +21 -0
  363. package/dist/bundle/chunks/chunk-SBG7KYI4.js +12 -0
  364. package/dist/bundle/chunks/chunk-SRNYBHIU.js +21 -0
  365. package/dist/bundle/chunks/chunk-T7CFNHX6.js +2 -0
  366. package/dist/bundle/chunks/chunk-U3UTFNHI.js +2 -0
  367. package/dist/bundle/chunks/chunk-UQZ5HJXB.js +64 -0
  368. package/dist/bundle/chunks/chunk-US6XQQ6W.js +19 -0
  369. package/dist/bundle/chunks/chunk-UZ4TKNEJ.js +2 -0
  370. package/dist/bundle/chunks/chunk-VW6FDS6X.js +2 -0
  371. package/dist/bundle/chunks/chunk-W4A6TADR.js +36 -0
  372. package/dist/bundle/chunks/chunk-WAL3MOLR.js +6 -0
  373. package/dist/bundle/chunks/chunk-WFEUQRHM.js +2 -0
  374. package/dist/bundle/chunks/chunk-WNAEYQTE.js +8 -0
  375. package/dist/bundle/chunks/chunk-WOSSFIAE.js +12 -0
  376. package/dist/bundle/chunks/chunk-WTG3OCY4.js +5 -0
  377. package/dist/bundle/chunks/chunk-XIEMQVCO.js +19 -0
  378. package/dist/bundle/chunks/chunk-YFGP6M45.js +7 -0
  379. package/dist/bundle/chunks/chunk-ZARLSKBF.js +2 -0
  380. package/dist/bundle/chunks/chunk-ZVANIJV2.js +4 -0
  381. package/dist/bundle/chunks/column-46NX3HG3.js +2 -0
  382. package/dist/bundle/chunks/comm-QHEYSM4I.js +2 -0
  383. package/dist/bundle/chunks/cp-AQ4Y4WVV.js +2 -0
  384. package/dist/bundle/chunks/curl-LMCQFYWH.js +30 -0
  385. package/dist/bundle/chunks/cut-A6NXJGOH.js +2 -0
  386. package/dist/bundle/chunks/date-YMEJ62OQ.js +2 -0
  387. package/dist/bundle/chunks/diff-SECJC7CN.js +2 -0
  388. package/dist/bundle/chunks/du-JOLY42MC.js +2 -0
  389. package/dist/bundle/chunks/env-MI6QVNMM.js +2 -0
  390. package/dist/bundle/chunks/expand-YVEZTU7W.js +2 -0
  391. package/dist/bundle/chunks/expr-U7WETT5R.js +2 -0
  392. package/dist/bundle/chunks/file-6QDI3H7G.js +2 -0
  393. package/dist/bundle/chunks/find-UYQIFSZI.js +2 -0
  394. package/dist/bundle/chunks/flag-coverage-5YCE6ILG.js +2 -0
  395. package/dist/bundle/chunks/fold-A24KLKHY.js +2 -0
  396. package/dist/bundle/chunks/grep-ZELVZ7JB.js +2 -0
  397. package/dist/bundle/chunks/gzip-3IFADYVU.js +2 -0
  398. package/dist/bundle/chunks/head-5YWCKNNQ.js +2 -0
  399. package/dist/bundle/chunks/html-to-markdown-EOWI2I5J.js +2 -0
  400. package/dist/bundle/chunks/join-MSZXRLNV.js +2 -0
  401. package/dist/bundle/chunks/jq-MKA6BDYV.js +2 -0
  402. package/dist/bundle/chunks/js-exec-CNDWLKWB.js +1616 -0
  403. package/dist/bundle/chunks/ls-WMN4WCCI.js +2 -0
  404. package/dist/bundle/chunks/md5sum-OCX4NZ2Q.js +2 -0
  405. package/dist/bundle/chunks/mkdir-YJMG55FX.js +2 -0
  406. package/dist/bundle/chunks/mktemp-RA55VAN3.js +2 -0
  407. package/dist/bundle/chunks/mv-NTJL2AHI.js +2 -0
  408. package/dist/bundle/chunks/nl-Z5DVHZ3S.js +2 -0
  409. package/dist/bundle/chunks/od-TRWBMEIO.js +2 -0
  410. package/dist/bundle/chunks/paste-VPYCLIL6.js +2 -0
  411. package/dist/bundle/chunks/printf-BNADL4RX.js +2 -0
  412. package/dist/bundle/chunks/python3-TIKLWPZJ.js +22 -0
  413. package/dist/bundle/chunks/readlink-HGACDFRD.js +2 -0
  414. package/dist/bundle/chunks/rev-W57N4M5B.js +2 -0
  415. package/dist/bundle/chunks/rg-IN3KT335.js +2 -0
  416. package/dist/bundle/chunks/rm-CDVWO5CO.js +2 -0
  417. package/dist/bundle/chunks/rmdir-HI3UE4KQ.js +2 -0
  418. package/dist/bundle/chunks/sed-MXZDFQ7I.js +2 -0
  419. package/dist/bundle/chunks/seq-E3UP3G65.js +2 -0
  420. package/dist/bundle/chunks/sha1sum-QUWYL7G6.js +2 -0
  421. package/dist/bundle/chunks/sha256sum-FGHIABMA.js +2 -0
  422. package/dist/bundle/chunks/sort-ATCMEITA.js +2 -0
  423. package/dist/bundle/chunks/split-YZFCWIZI.js +2 -0
  424. package/dist/bundle/chunks/sqlite3-JL36RFBZ.js +2 -0
  425. package/dist/bundle/chunks/stat-APUQD6WQ.js +2 -0
  426. package/dist/bundle/chunks/strings-WA2ZGNUN.js +2 -0
  427. package/dist/bundle/chunks/tac-OCV6R4TG.js +2 -0
  428. package/dist/bundle/chunks/tail-IBKQAMFW.js +2 -0
  429. package/dist/bundle/chunks/tar-WJV4DGKA.js +2 -0
  430. package/dist/bundle/chunks/tee-VOXQ2UGV.js +2 -0
  431. package/dist/bundle/chunks/time-GOHAC6VO.js +2 -0
  432. package/dist/bundle/chunks/timeout-FVGYB3MD.js +2 -0
  433. package/dist/bundle/chunks/touch-57OKADDG.js +2 -0
  434. package/dist/bundle/chunks/tr-M4D6SICQ.js +2 -0
  435. package/dist/bundle/chunks/unexpand-SYZZ5ZBE.js +2 -0
  436. package/dist/bundle/chunks/uniq-TUUUYPVF.js +2 -0
  437. package/dist/bundle/chunks/wc-HQPGW3KR.js +2 -0
  438. package/dist/bundle/chunks/xan-CZJZCC57.js +2 -0
  439. package/dist/bundle/chunks/xan-view-HETEUD3G.js +2 -0
  440. package/dist/bundle/chunks/xargs-WFPZZ3FK.js +2 -0
  441. package/dist/bundle/chunks/yes-ACSNSE7T.js +2 -0
  442. package/dist/bundle/chunks/yq-XDJLIJPZ.js +2 -0
  443. package/dist/bundle/index.cjs +1042 -993
  444. package/dist/bundle/index.js +345 -343
  445. package/dist/commands/awk/interpreter/fields.d.ts +16 -0
  446. package/dist/commands/js-exec/module-shims.d.ts +1 -1
  447. package/dist/commands/rg/rg-options.d.ts +2 -0
  448. package/dist/commands/search-engine/matcher.d.ts +2 -0
  449. package/dist/interpreter/builtin-dispatch.d.ts +9 -3
  450. package/dist/interpreter/fd-table.d.ts +4 -1
  451. package/dist/interpreter/helpers/errors.d.ts +5 -0
  452. package/dist/interpreter/pipeline-execution.d.ts +1 -1
  453. package/dist/interpreter/redirections.d.ts +25 -10
  454. package/dist/interpreter/types.d.ts +2 -0
  455. package/dist/types.d.ts +15 -0
  456. package/dist/utils/string-builder.d.ts +9 -0
  457. package/package.json +2 -2
  458. package/dist/bin/chunks/awk2-U22OR5B5.js +0 -3
  459. package/dist/bin/chunks/base64-2KKH5BCT.js +0 -3
  460. package/dist/bin/chunks/bash-CFCBBWVH.js +0 -3
  461. package/dist/bin/chunks/cat-V45MVNBT.js +0 -3
  462. package/dist/bin/chunks/chmod-A54R4UUQ.js +0 -3
  463. package/dist/bin/chunks/chunk-2NJJXU4K.js +0 -27
  464. package/dist/bin/chunks/chunk-2YLY6FJA.js +0 -10
  465. package/dist/bin/chunks/chunk-3LKMI5IX.js +0 -34
  466. package/dist/bin/chunks/chunk-3VSWQCPN.js +0 -18
  467. package/dist/bin/chunks/chunk-44SKMHU6.js +0 -16
  468. package/dist/bin/chunks/chunk-5SKEZPTU.js +0 -12
  469. package/dist/bin/chunks/chunk-5SR55TXB.js +0 -16
  470. package/dist/bin/chunks/chunk-6D75E4LV.js +0 -3
  471. package/dist/bin/chunks/chunk-6DAR25KN.js +0 -12
  472. package/dist/bin/chunks/chunk-6SAZRW7E.js +0 -15
  473. package/dist/bin/chunks/chunk-723HNGID.js +0 -13
  474. package/dist/bin/chunks/chunk-7FGDUBSN.js +0 -14
  475. package/dist/bin/chunks/chunk-7X4QBCFW.js +0 -36
  476. package/dist/bin/chunks/chunk-AINNAQBQ.js +0 -6
  477. package/dist/bin/chunks/chunk-AL7RVSF4.js +0 -8
  478. package/dist/bin/chunks/chunk-ARYCSNJJ.js +0 -101
  479. package/dist/bin/chunks/chunk-BCJ42NCM.js +0 -15
  480. package/dist/bin/chunks/chunk-BJF6B4YW.js +0 -22
  481. package/dist/bin/chunks/chunk-BOXG6XBN.js +0 -143
  482. package/dist/bin/chunks/chunk-CPKBPQ2C.js +0 -3
  483. package/dist/bin/chunks/chunk-DA3RFNKK.js +0 -17
  484. package/dist/bin/chunks/chunk-DH7M46D3.js +0 -20
  485. package/dist/bin/chunks/chunk-DTGQQKI2.js +0 -87
  486. package/dist/bin/chunks/chunk-ECZAFQ22.js +0 -9
  487. package/dist/bin/chunks/chunk-ETWDDV6I.js +0 -10
  488. package/dist/bin/chunks/chunk-HFW2LXQV.js +0 -13
  489. package/dist/bin/chunks/chunk-HRKG3ZK2.js +0 -8
  490. package/dist/bin/chunks/chunk-I4IRHQDW.js +0 -3
  491. package/dist/bin/chunks/chunk-IKUY74NG.js +0 -3
  492. package/dist/bin/chunks/chunk-ILXMFIYG.js +0 -7
  493. package/dist/bin/chunks/chunk-IMVXTSPG.js +0 -275
  494. package/dist/bin/chunks/chunk-ISW2U76N.js +0 -17
  495. package/dist/bin/chunks/chunk-K5KT6DMM.js +0 -4
  496. package/dist/bin/chunks/chunk-KG2KXL4Y.js +0 -3
  497. package/dist/bin/chunks/chunk-LCP3IKI7.js +0 -9
  498. package/dist/bin/chunks/chunk-LG6IN6SW.js +0 -34
  499. package/dist/bin/chunks/chunk-LMFAALLO.js +0 -21
  500. package/dist/bin/chunks/chunk-LXFMIXGA.js +0 -3
  501. package/dist/bin/chunks/chunk-M5ZBECGM.js +0 -22
  502. package/dist/bin/chunks/chunk-MA6BMA4M.js +0 -3
  503. package/dist/bin/chunks/chunk-MPQMTLXN.js +0 -3
  504. package/dist/bin/chunks/chunk-MUIYG2RB.js +0 -65
  505. package/dist/bin/chunks/chunk-MYTNZ7MA.js +0 -7
  506. package/dist/bin/chunks/chunk-NGMFI3RH.js +0 -15
  507. package/dist/bin/chunks/chunk-NLMTGTSG.js +0 -11
  508. package/dist/bin/chunks/chunk-O74FSWB4.js +0 -4
  509. package/dist/bin/chunks/chunk-OBVTFHVP.js +0 -7
  510. package/dist/bin/chunks/chunk-OOKVPG5D.js +0 -6
  511. package/dist/bin/chunks/chunk-PL4EU7Y2.js +0 -3
  512. package/dist/bin/chunks/chunk-Q3LE3Y66.js +0 -13
  513. package/dist/bin/chunks/chunk-QCGH2ZOW.js +0 -13
  514. package/dist/bin/chunks/chunk-QKWMWSV3.js +0 -3
  515. package/dist/bin/chunks/chunk-QL33F2W6.js +0 -8
  516. package/dist/bin/chunks/chunk-S5Z7DMIE.js +0 -26
  517. package/dist/bin/chunks/chunk-SQ7SZZMW.js +0 -8
  518. package/dist/bin/chunks/chunk-SQUH76NP.js +0 -3
  519. package/dist/bin/chunks/chunk-TGRZ42DS.js +0 -12
  520. package/dist/bin/chunks/chunk-THTKNRO6.js +0 -7
  521. package/dist/bin/chunks/chunk-TQXLQEIT.js +0 -9
  522. package/dist/bin/chunks/chunk-TZ3S7MY6.js +0 -12
  523. package/dist/bin/chunks/chunk-U6BXPMLD.js +0 -7
  524. package/dist/bin/chunks/chunk-U6DBRMD5.js +0 -5
  525. package/dist/bin/chunks/chunk-URRH3GPG.js +0 -10
  526. package/dist/bin/chunks/chunk-VBU3UEG5.js +0 -7
  527. package/dist/bin/chunks/chunk-VLWZ6L7C.js +0 -4
  528. package/dist/bin/chunks/chunk-VTHA5UK5.js +0 -7
  529. package/dist/bin/chunks/chunk-WBST7XJW.js +0 -9
  530. package/dist/bin/chunks/chunk-WDV2ECOC.js +0 -3
  531. package/dist/bin/chunks/chunk-WEQ5WM2M.js +0 -20
  532. package/dist/bin/chunks/chunk-WFVCEB5T.js +0 -3
  533. package/dist/bin/chunks/chunk-WZ7MIBLR.js +0 -37
  534. package/dist/bin/chunks/chunk-X45GP3AQ.js +0 -3
  535. package/dist/bin/chunks/chunk-XEQ7KSRM.js +0 -5
  536. package/dist/bin/chunks/chunk-YIANER7Y.js +0 -8
  537. package/dist/bin/chunks/chunk-YYZSYLJO.js +0 -6
  538. package/dist/bin/chunks/chunk-Z3KAV6YJ.js +0 -10
  539. package/dist/bin/chunks/chunk-Z5KICK5X.js +0 -22
  540. package/dist/bin/chunks/column-LHHS4D3K.js +0 -3
  541. package/dist/bin/chunks/comm-URDMZCXL.js +0 -3
  542. package/dist/bin/chunks/cp-HPLQA35N.js +0 -3
  543. package/dist/bin/chunks/curl-FIRG3RB6.js +0 -31
  544. package/dist/bin/chunks/cut-KP3S36XS.js +0 -3
  545. package/dist/bin/chunks/date-FJUBX7TJ.js +0 -3
  546. package/dist/bin/chunks/diff-JSJ56EOK.js +0 -3
  547. package/dist/bin/chunks/dist-4NZ74CRE.js +0 -141
  548. package/dist/bin/chunks/du-WEF5YWQK.js +0 -3
  549. package/dist/bin/chunks/env-2TSVF4W7.js +0 -3
  550. package/dist/bin/chunks/expand-P6SNTBGZ.js +0 -3
  551. package/dist/bin/chunks/expr-FLWT4OCO.js +0 -3
  552. package/dist/bin/chunks/file-JLUCGBCB.js +0 -3
  553. package/dist/bin/chunks/find-XGVQ6N6L.js +0 -3
  554. package/dist/bin/chunks/flag-coverage-4JYKIAVV.js +0 -3
  555. package/dist/bin/chunks/fold-YEY7X54W.js +0 -3
  556. package/dist/bin/chunks/grep-DCPCPQOS.js +0 -3
  557. package/dist/bin/chunks/gzip-6DZIKNBW.js +0 -3
  558. package/dist/bin/chunks/head-TLFXMM2T.js +0 -3
  559. package/dist/bin/chunks/html-to-markdown-E22RLT2U.js +0 -3
  560. package/dist/bin/chunks/join-UQKXU2QP.js +0 -3
  561. package/dist/bin/chunks/jq-GDM3OBBK.js +0 -3
  562. package/dist/bin/chunks/js-exec-VU6F6WLS.js +0 -1578
  563. package/dist/bin/chunks/ls-67NUUIYT.js +0 -3
  564. package/dist/bin/chunks/md5sum-Z6KAYGDK.js +0 -3
  565. package/dist/bin/chunks/mkdir-AWDWRBKC.js +0 -3
  566. package/dist/bin/chunks/mktemp-L6OGMDUO.js +0 -3
  567. package/dist/bin/chunks/mv-4BJSOT4Y.js +0 -3
  568. package/dist/bin/chunks/nl-XHWFVVKH.js +0 -3
  569. package/dist/bin/chunks/od-SI75GLRE.js +0 -3
  570. package/dist/bin/chunks/paste-5TSIBDF7.js +0 -3
  571. package/dist/bin/chunks/printf-CNXNRQ3I.js +0 -3
  572. package/dist/bin/chunks/python3-GUWCSSDP.js +0 -23
  573. package/dist/bin/chunks/readlink-URO5XTBB.js +0 -3
  574. package/dist/bin/chunks/rev-CZTQCNOZ.js +0 -3
  575. package/dist/bin/chunks/rg-RVULUPDH.js +0 -3
  576. package/dist/bin/chunks/rm-UCUTHC3I.js +0 -3
  577. package/dist/bin/chunks/rmdir-J3HM7GGM.js +0 -3
  578. package/dist/bin/chunks/sed-MCLGHZOI.js +0 -3
  579. package/dist/bin/chunks/seq-I54NZE75.js +0 -3
  580. package/dist/bin/chunks/sha1sum-CATBXX76.js +0 -3
  581. package/dist/bin/chunks/sha256sum-YGSNBVY3.js +0 -3
  582. package/dist/bin/chunks/sort-M3DO25D5.js +0 -3
  583. package/dist/bin/chunks/split-VZO7223N.js +0 -3
  584. package/dist/bin/chunks/sqlite3-HXVFVP4Z.js +0 -3
  585. package/dist/bin/chunks/stat-UJ37RBMM.js +0 -3
  586. package/dist/bin/chunks/strings-J2X2Z6N2.js +0 -3
  587. package/dist/bin/chunks/tac-DG4BMYM5.js +0 -3
  588. package/dist/bin/chunks/tail-5TSF5YM4.js +0 -3
  589. package/dist/bin/chunks/tar-ZGZZDQXO.js +0 -3
  590. package/dist/bin/chunks/tee-L4HKV5PD.js +0 -3
  591. package/dist/bin/chunks/time-J2DAZUIN.js +0 -3
  592. package/dist/bin/chunks/timeout-ATTDYXLX.js +0 -3
  593. package/dist/bin/chunks/touch-TVQAUQOG.js +0 -3
  594. package/dist/bin/chunks/tr-6RPFASYV.js +0 -3
  595. package/dist/bin/chunks/unexpand-JPOQORZF.js +0 -3
  596. package/dist/bin/chunks/uniq-K5VRDP4Q.js +0 -3
  597. package/dist/bin/chunks/wc-VSQBRD6B.js +0 -3
  598. package/dist/bin/chunks/xan-CCS53B7D.js +0 -3
  599. package/dist/bin/chunks/xan-view-KOXASOEV.js +0 -3
  600. package/dist/bin/chunks/xargs-HMISWW4I.js +0 -3
  601. package/dist/bin/chunks/yes-ELH3XQWY.js +0 -3
  602. package/dist/bin/chunks/yq-GSCDUHGM.js +0 -3
  603. package/dist/bin/shell/chunks/awk2-U22OR5B5.js +0 -3
  604. package/dist/bin/shell/chunks/base64-2KKH5BCT.js +0 -3
  605. package/dist/bin/shell/chunks/bash-CFCBBWVH.js +0 -3
  606. package/dist/bin/shell/chunks/cat-V45MVNBT.js +0 -3
  607. package/dist/bin/shell/chunks/chmod-A54R4UUQ.js +0 -3
  608. package/dist/bin/shell/chunks/chunk-2NJJXU4K.js +0 -27
  609. package/dist/bin/shell/chunks/chunk-2YLY6FJA.js +0 -10
  610. package/dist/bin/shell/chunks/chunk-3LKMI5IX.js +0 -34
  611. package/dist/bin/shell/chunks/chunk-3VSWQCPN.js +0 -18
  612. package/dist/bin/shell/chunks/chunk-44SKMHU6.js +0 -16
  613. package/dist/bin/shell/chunks/chunk-5SKEZPTU.js +0 -12
  614. package/dist/bin/shell/chunks/chunk-5SR55TXB.js +0 -16
  615. package/dist/bin/shell/chunks/chunk-6D75E4LV.js +0 -3
  616. package/dist/bin/shell/chunks/chunk-6DAR25KN.js +0 -12
  617. package/dist/bin/shell/chunks/chunk-6SAZRW7E.js +0 -15
  618. package/dist/bin/shell/chunks/chunk-723HNGID.js +0 -13
  619. package/dist/bin/shell/chunks/chunk-7FGDUBSN.js +0 -14
  620. package/dist/bin/shell/chunks/chunk-7X4QBCFW.js +0 -36
  621. package/dist/bin/shell/chunks/chunk-AINNAQBQ.js +0 -6
  622. package/dist/bin/shell/chunks/chunk-AL7RVSF4.js +0 -8
  623. package/dist/bin/shell/chunks/chunk-ARYCSNJJ.js +0 -101
  624. package/dist/bin/shell/chunks/chunk-BCJ42NCM.js +0 -15
  625. package/dist/bin/shell/chunks/chunk-BJF6B4YW.js +0 -22
  626. package/dist/bin/shell/chunks/chunk-BOXG6XBN.js +0 -143
  627. package/dist/bin/shell/chunks/chunk-CPKBPQ2C.js +0 -3
  628. package/dist/bin/shell/chunks/chunk-DA3RFNKK.js +0 -17
  629. package/dist/bin/shell/chunks/chunk-DH7M46D3.js +0 -20
  630. package/dist/bin/shell/chunks/chunk-DTGQQKI2.js +0 -87
  631. package/dist/bin/shell/chunks/chunk-ECZAFQ22.js +0 -9
  632. package/dist/bin/shell/chunks/chunk-ETWDDV6I.js +0 -10
  633. package/dist/bin/shell/chunks/chunk-HFW2LXQV.js +0 -13
  634. package/dist/bin/shell/chunks/chunk-HRKG3ZK2.js +0 -8
  635. package/dist/bin/shell/chunks/chunk-I4IRHQDW.js +0 -3
  636. package/dist/bin/shell/chunks/chunk-IKUY74NG.js +0 -3
  637. package/dist/bin/shell/chunks/chunk-ILXMFIYG.js +0 -7
  638. package/dist/bin/shell/chunks/chunk-IMVXTSPG.js +0 -275
  639. package/dist/bin/shell/chunks/chunk-ISW2U76N.js +0 -17
  640. package/dist/bin/shell/chunks/chunk-K5KT6DMM.js +0 -4
  641. package/dist/bin/shell/chunks/chunk-KG2KXL4Y.js +0 -3
  642. package/dist/bin/shell/chunks/chunk-LCP3IKI7.js +0 -9
  643. package/dist/bin/shell/chunks/chunk-LG6IN6SW.js +0 -34
  644. package/dist/bin/shell/chunks/chunk-LMFAALLO.js +0 -21
  645. package/dist/bin/shell/chunks/chunk-LXFMIXGA.js +0 -3
  646. package/dist/bin/shell/chunks/chunk-M5ZBECGM.js +0 -22
  647. package/dist/bin/shell/chunks/chunk-MA6BMA4M.js +0 -3
  648. package/dist/bin/shell/chunks/chunk-MPQMTLXN.js +0 -3
  649. package/dist/bin/shell/chunks/chunk-MUIYG2RB.js +0 -65
  650. package/dist/bin/shell/chunks/chunk-MYTNZ7MA.js +0 -7
  651. package/dist/bin/shell/chunks/chunk-NGMFI3RH.js +0 -15
  652. package/dist/bin/shell/chunks/chunk-NLMTGTSG.js +0 -11
  653. package/dist/bin/shell/chunks/chunk-O74FSWB4.js +0 -4
  654. package/dist/bin/shell/chunks/chunk-OBVTFHVP.js +0 -7
  655. package/dist/bin/shell/chunks/chunk-OOKVPG5D.js +0 -6
  656. package/dist/bin/shell/chunks/chunk-PL4EU7Y2.js +0 -3
  657. package/dist/bin/shell/chunks/chunk-Q3LE3Y66.js +0 -13
  658. package/dist/bin/shell/chunks/chunk-QCGH2ZOW.js +0 -13
  659. package/dist/bin/shell/chunks/chunk-QKWMWSV3.js +0 -3
  660. package/dist/bin/shell/chunks/chunk-QL33F2W6.js +0 -8
  661. package/dist/bin/shell/chunks/chunk-S5Z7DMIE.js +0 -26
  662. package/dist/bin/shell/chunks/chunk-SQ7SZZMW.js +0 -8
  663. package/dist/bin/shell/chunks/chunk-SQUH76NP.js +0 -3
  664. package/dist/bin/shell/chunks/chunk-TGRZ42DS.js +0 -12
  665. package/dist/bin/shell/chunks/chunk-THTKNRO6.js +0 -7
  666. package/dist/bin/shell/chunks/chunk-TQXLQEIT.js +0 -9
  667. package/dist/bin/shell/chunks/chunk-TZ3S7MY6.js +0 -12
  668. package/dist/bin/shell/chunks/chunk-U6BXPMLD.js +0 -7
  669. package/dist/bin/shell/chunks/chunk-U6DBRMD5.js +0 -5
  670. package/dist/bin/shell/chunks/chunk-URRH3GPG.js +0 -10
  671. package/dist/bin/shell/chunks/chunk-VBU3UEG5.js +0 -7
  672. package/dist/bin/shell/chunks/chunk-VLWZ6L7C.js +0 -4
  673. package/dist/bin/shell/chunks/chunk-VTHA5UK5.js +0 -7
  674. package/dist/bin/shell/chunks/chunk-WBST7XJW.js +0 -9
  675. package/dist/bin/shell/chunks/chunk-WDV2ECOC.js +0 -3
  676. package/dist/bin/shell/chunks/chunk-WEQ5WM2M.js +0 -20
  677. package/dist/bin/shell/chunks/chunk-WFVCEB5T.js +0 -3
  678. package/dist/bin/shell/chunks/chunk-WZ7MIBLR.js +0 -37
  679. package/dist/bin/shell/chunks/chunk-X45GP3AQ.js +0 -3
  680. package/dist/bin/shell/chunks/chunk-XEQ7KSRM.js +0 -5
  681. package/dist/bin/shell/chunks/chunk-YIANER7Y.js +0 -8
  682. package/dist/bin/shell/chunks/chunk-YYZSYLJO.js +0 -6
  683. package/dist/bin/shell/chunks/chunk-Z3KAV6YJ.js +0 -10
  684. package/dist/bin/shell/chunks/chunk-Z5KICK5X.js +0 -22
  685. package/dist/bin/shell/chunks/column-LHHS4D3K.js +0 -3
  686. package/dist/bin/shell/chunks/comm-URDMZCXL.js +0 -3
  687. package/dist/bin/shell/chunks/cp-HPLQA35N.js +0 -3
  688. package/dist/bin/shell/chunks/curl-FIRG3RB6.js +0 -31
  689. package/dist/bin/shell/chunks/cut-KP3S36XS.js +0 -3
  690. package/dist/bin/shell/chunks/date-FJUBX7TJ.js +0 -3
  691. package/dist/bin/shell/chunks/diff-JSJ56EOK.js +0 -3
  692. package/dist/bin/shell/chunks/dist-4NZ74CRE.js +0 -141
  693. package/dist/bin/shell/chunks/du-WEF5YWQK.js +0 -3
  694. package/dist/bin/shell/chunks/env-2TSVF4W7.js +0 -3
  695. package/dist/bin/shell/chunks/expand-P6SNTBGZ.js +0 -3
  696. package/dist/bin/shell/chunks/expr-FLWT4OCO.js +0 -3
  697. package/dist/bin/shell/chunks/file-JLUCGBCB.js +0 -3
  698. package/dist/bin/shell/chunks/find-XGVQ6N6L.js +0 -3
  699. package/dist/bin/shell/chunks/flag-coverage-4JYKIAVV.js +0 -3
  700. package/dist/bin/shell/chunks/fold-YEY7X54W.js +0 -3
  701. package/dist/bin/shell/chunks/grep-DCPCPQOS.js +0 -3
  702. package/dist/bin/shell/chunks/gzip-6DZIKNBW.js +0 -3
  703. package/dist/bin/shell/chunks/head-TLFXMM2T.js +0 -3
  704. package/dist/bin/shell/chunks/html-to-markdown-E22RLT2U.js +0 -3
  705. package/dist/bin/shell/chunks/join-UQKXU2QP.js +0 -3
  706. package/dist/bin/shell/chunks/jq-GDM3OBBK.js +0 -3
  707. package/dist/bin/shell/chunks/js-exec-VU6F6WLS.js +0 -1578
  708. package/dist/bin/shell/chunks/ls-67NUUIYT.js +0 -3
  709. package/dist/bin/shell/chunks/md5sum-Z6KAYGDK.js +0 -3
  710. package/dist/bin/shell/chunks/mkdir-AWDWRBKC.js +0 -3
  711. package/dist/bin/shell/chunks/mktemp-L6OGMDUO.js +0 -3
  712. package/dist/bin/shell/chunks/mv-4BJSOT4Y.js +0 -3
  713. package/dist/bin/shell/chunks/nl-XHWFVVKH.js +0 -3
  714. package/dist/bin/shell/chunks/od-SI75GLRE.js +0 -3
  715. package/dist/bin/shell/chunks/paste-5TSIBDF7.js +0 -3
  716. package/dist/bin/shell/chunks/printf-CNXNRQ3I.js +0 -3
  717. package/dist/bin/shell/chunks/python3-GUWCSSDP.js +0 -23
  718. package/dist/bin/shell/chunks/readlink-URO5XTBB.js +0 -3
  719. package/dist/bin/shell/chunks/rev-CZTQCNOZ.js +0 -3
  720. package/dist/bin/shell/chunks/rg-RVULUPDH.js +0 -3
  721. package/dist/bin/shell/chunks/rm-UCUTHC3I.js +0 -3
  722. package/dist/bin/shell/chunks/rmdir-J3HM7GGM.js +0 -3
  723. package/dist/bin/shell/chunks/sed-MCLGHZOI.js +0 -3
  724. package/dist/bin/shell/chunks/seq-I54NZE75.js +0 -3
  725. package/dist/bin/shell/chunks/sha1sum-CATBXX76.js +0 -3
  726. package/dist/bin/shell/chunks/sha256sum-YGSNBVY3.js +0 -3
  727. package/dist/bin/shell/chunks/sort-M3DO25D5.js +0 -3
  728. package/dist/bin/shell/chunks/split-VZO7223N.js +0 -3
  729. package/dist/bin/shell/chunks/sqlite3-HXVFVP4Z.js +0 -3
  730. package/dist/bin/shell/chunks/stat-UJ37RBMM.js +0 -3
  731. package/dist/bin/shell/chunks/strings-J2X2Z6N2.js +0 -3
  732. package/dist/bin/shell/chunks/tac-DG4BMYM5.js +0 -3
  733. package/dist/bin/shell/chunks/tail-5TSF5YM4.js +0 -3
  734. package/dist/bin/shell/chunks/tar-ZGZZDQXO.js +0 -3
  735. package/dist/bin/shell/chunks/tee-L4HKV5PD.js +0 -3
  736. package/dist/bin/shell/chunks/time-J2DAZUIN.js +0 -3
  737. package/dist/bin/shell/chunks/timeout-ATTDYXLX.js +0 -3
  738. package/dist/bin/shell/chunks/touch-TVQAUQOG.js +0 -3
  739. package/dist/bin/shell/chunks/tr-6RPFASYV.js +0 -3
  740. package/dist/bin/shell/chunks/unexpand-JPOQORZF.js +0 -3
  741. package/dist/bin/shell/chunks/uniq-K5VRDP4Q.js +0 -3
  742. package/dist/bin/shell/chunks/wc-VSQBRD6B.js +0 -3
  743. package/dist/bin/shell/chunks/xan-CCS53B7D.js +0 -3
  744. package/dist/bin/shell/chunks/xan-view-KOXASOEV.js +0 -3
  745. package/dist/bin/shell/chunks/xargs-HMISWW4I.js +0 -3
  746. package/dist/bin/shell/chunks/yes-ELH3XQWY.js +0 -3
  747. package/dist/bin/shell/chunks/yq-GSCDUHGM.js +0 -3
  748. package/dist/bundle/chunks/awk2-V7KYQWCD.js +0 -2
  749. package/dist/bundle/chunks/base64-QPSYZAAJ.js +0 -2
  750. package/dist/bundle/chunks/bash-HIEWVHJ2.js +0 -2
  751. package/dist/bundle/chunks/cat-54BXBS6X.js +0 -2
  752. package/dist/bundle/chunks/chmod-4OPV4QKK.js +0 -2
  753. package/dist/bundle/chunks/chunk-2KNTH3KH.js +0 -9
  754. package/dist/bundle/chunks/chunk-2VWG4LDT.js +0 -11
  755. package/dist/bundle/chunks/chunk-2WBUTDF5.js +0 -2
  756. package/dist/bundle/chunks/chunk-3HDTNUL3.js +0 -6
  757. package/dist/bundle/chunks/chunk-3KWM4FFA.js +0 -12
  758. package/dist/bundle/chunks/chunk-4AKAIZPW.js +0 -15
  759. package/dist/bundle/chunks/chunk-4IMUNIUJ.js +0 -21
  760. package/dist/bundle/chunks/chunk-5ATEFZLC.js +0 -4
  761. package/dist/bundle/chunks/chunk-5BMPT6SF.js +0 -19
  762. package/dist/bundle/chunks/chunk-5QWGR2WA.js +0 -21
  763. package/dist/bundle/chunks/chunk-5UTZMNI5.js +0 -64
  764. package/dist/bundle/chunks/chunk-5VCAQBXL.js +0 -17
  765. package/dist/bundle/chunks/chunk-65LVAUWW.js +0 -7
  766. package/dist/bundle/chunks/chunk-6D3WD6YU.js +0 -3
  767. package/dist/bundle/chunks/chunk-6R4OQQWP.js +0 -16
  768. package/dist/bundle/chunks/chunk-6WGIZV3E.js +0 -13
  769. package/dist/bundle/chunks/chunk-72JHTO7E.js +0 -2
  770. package/dist/bundle/chunks/chunk-7GA3QWJJ.js +0 -33
  771. package/dist/bundle/chunks/chunk-7M672HB6.js +0 -21
  772. package/dist/bundle/chunks/chunk-AFFAMSJT.js +0 -14
  773. package/dist/bundle/chunks/chunk-ANCQ4SCV.js +0 -2
  774. package/dist/bundle/chunks/chunk-B3NGH6KE.js +0 -5
  775. package/dist/bundle/chunks/chunk-B5Z5HTFY.js +0 -14
  776. package/dist/bundle/chunks/chunk-B6OSJB22.js +0 -26
  777. package/dist/bundle/chunks/chunk-BM3X75NC.js +0 -36
  778. package/dist/bundle/chunks/chunk-CGI6V2HW.js +0 -11
  779. package/dist/bundle/chunks/chunk-CHHWTPDH.js +0 -3
  780. package/dist/bundle/chunks/chunk-D5ZJISRS.js +0 -11
  781. package/dist/bundle/chunks/chunk-DIRWTBKE.js +0 -19
  782. package/dist/bundle/chunks/chunk-DIWMSSQY.js +0 -2
  783. package/dist/bundle/chunks/chunk-DPZVOEUP.js +0 -6
  784. package/dist/bundle/chunks/chunk-EFORKKSH.js +0 -8
  785. package/dist/bundle/chunks/chunk-EGTVQWAP.js +0 -20
  786. package/dist/bundle/chunks/chunk-EJFBIRMD.js +0 -6
  787. package/dist/bundle/chunks/chunk-EQQGPAXI.js +0 -9
  788. package/dist/bundle/chunks/chunk-EXXOLIVE.js +0 -35
  789. package/dist/bundle/chunks/chunk-FIMO5HLX.js +0 -2
  790. package/dist/bundle/chunks/chunk-FT6ODGOU.js +0 -2
  791. package/dist/bundle/chunks/chunk-FZRQOL3C.js +0 -7
  792. package/dist/bundle/chunks/chunk-GLAFXDZC.js +0 -4
  793. package/dist/bundle/chunks/chunk-GN6CQ3J4.js +0 -2
  794. package/dist/bundle/chunks/chunk-H42OAUJL.js +0 -12
  795. package/dist/bundle/chunks/chunk-H53EPEGD.js +0 -12
  796. package/dist/bundle/chunks/chunk-HDOXCDVK.js +0 -7
  797. package/dist/bundle/chunks/chunk-HIQEVPXM.js +0 -2
  798. package/dist/bundle/chunks/chunk-J2OBOJ64.js +0 -2
  799. package/dist/bundle/chunks/chunk-LVDUF74R.js +0 -7
  800. package/dist/bundle/chunks/chunk-M4LDT7V7.js +0 -6
  801. package/dist/bundle/chunks/chunk-MDE25PQK.js +0 -15
  802. package/dist/bundle/chunks/chunk-MHDZERK4.js +0 -6
  803. package/dist/bundle/chunks/chunk-MHZF23KB.js +0 -33
  804. package/dist/bundle/chunks/chunk-N6W6FM4N.js +0 -8
  805. package/dist/bundle/chunks/chunk-NRLE7KYI.js +0 -6
  806. package/dist/bundle/chunks/chunk-OB46N7Q7.js +0 -2
  807. package/dist/bundle/chunks/chunk-OQ7C4FYO.js +0 -2
  808. package/dist/bundle/chunks/chunk-P5BOIHWV.js +0 -6
  809. package/dist/bundle/chunks/chunk-PPDMRIJ7.js +0 -11
  810. package/dist/bundle/chunks/chunk-PPHGMG47.js +0 -142
  811. package/dist/bundle/chunks/chunk-R6ZGLVXI.js +0 -9
  812. package/dist/bundle/chunks/chunk-RCRHDT54.js +0 -274
  813. package/dist/bundle/chunks/chunk-RIIUVFUS.js +0 -7
  814. package/dist/bundle/chunks/chunk-SQX6WQXB.js +0 -7
  815. package/dist/bundle/chunks/chunk-SRB6FXRH.js +0 -2
  816. package/dist/bundle/chunks/chunk-T4INBNHX.js +0 -8
  817. package/dist/bundle/chunks/chunk-TUQG2YRH.js +0 -5
  818. package/dist/bundle/chunks/chunk-U7UNEMLJ.js +0 -2
  819. package/dist/bundle/chunks/chunk-UHHCL65P.js +0 -3
  820. package/dist/bundle/chunks/chunk-UK2K3DHN.js +0 -8
  821. package/dist/bundle/chunks/chunk-VDJ53ESK.js +0 -9
  822. package/dist/bundle/chunks/chunk-VGCXKMXN.js +0 -10
  823. package/dist/bundle/chunks/chunk-W5DWRFSU.js +0 -2
  824. package/dist/bundle/chunks/chunk-W5J5ADJF.js +0 -100
  825. package/dist/bundle/chunks/chunk-XHFP44Y4.js +0 -5
  826. package/dist/bundle/chunks/chunk-Y32R7EZP.js +0 -25
  827. package/dist/bundle/chunks/chunk-Y62SXZKJ.js +0 -12
  828. package/dist/bundle/chunks/chunk-YUFU7O6I.js +0 -16
  829. package/dist/bundle/chunks/chunk-YZH7FUSY.js +0 -14
  830. package/dist/bundle/chunks/column-F5JDBRV6.js +0 -2
  831. package/dist/bundle/chunks/comm-DTWKU2MC.js +0 -2
  832. package/dist/bundle/chunks/cp-LTFB4EUA.js +0 -2
  833. package/dist/bundle/chunks/curl-XCX2ZQEA.js +0 -30
  834. package/dist/bundle/chunks/cut-IRSHL3BB.js +0 -2
  835. package/dist/bundle/chunks/date-FN2DXAEE.js +0 -2
  836. package/dist/bundle/chunks/diff-VDB6RXHO.js +0 -2
  837. package/dist/bundle/chunks/du-DOWSRLXR.js +0 -2
  838. package/dist/bundle/chunks/env-VUUMB47B.js +0 -2
  839. package/dist/bundle/chunks/expand-2BPPGGSM.js +0 -2
  840. package/dist/bundle/chunks/expr-GZ4DABKB.js +0 -2
  841. package/dist/bundle/chunks/file-UI6QJAAU.js +0 -2
  842. package/dist/bundle/chunks/find-JTXDH3MR.js +0 -2
  843. package/dist/bundle/chunks/flag-coverage-EDO3VM43.js +0 -2
  844. package/dist/bundle/chunks/fold-QJBPHRFJ.js +0 -2
  845. package/dist/bundle/chunks/grep-OZCR76FT.js +0 -2
  846. package/dist/bundle/chunks/gzip-GQC6CWVL.js +0 -2
  847. package/dist/bundle/chunks/head-J6RVJFRS.js +0 -2
  848. package/dist/bundle/chunks/html-to-markdown-7OG5VWYG.js +0 -2
  849. package/dist/bundle/chunks/join-KQ4Z5OD4.js +0 -2
  850. package/dist/bundle/chunks/jq-FCG2IUBK.js +0 -2
  851. package/dist/bundle/chunks/js-exec-NDLXDUBN.js +0 -1577
  852. package/dist/bundle/chunks/ls-MQTYWW4T.js +0 -2
  853. package/dist/bundle/chunks/md5sum-JEDX55KS.js +0 -2
  854. package/dist/bundle/chunks/mkdir-4A5W3RXH.js +0 -2
  855. package/dist/bundle/chunks/mktemp-XKIE5N3X.js +0 -2
  856. package/dist/bundle/chunks/mv-ZPIATQJL.js +0 -2
  857. package/dist/bundle/chunks/nl-RFXH2GNX.js +0 -2
  858. package/dist/bundle/chunks/od-LUHOH7CG.js +0 -2
  859. package/dist/bundle/chunks/paste-U57ZU47S.js +0 -2
  860. package/dist/bundle/chunks/printf-V42QCPHL.js +0 -2
  861. package/dist/bundle/chunks/python3-SDFCGIU4.js +0 -22
  862. package/dist/bundle/chunks/readlink-YNNS6F7K.js +0 -2
  863. package/dist/bundle/chunks/rev-EPOS3MFH.js +0 -2
  864. package/dist/bundle/chunks/rg-F4SX2PHI.js +0 -2
  865. package/dist/bundle/chunks/rm-3XUUYAXQ.js +0 -2
  866. package/dist/bundle/chunks/rmdir-OGSEXEF4.js +0 -2
  867. package/dist/bundle/chunks/sed-MBB5SXGD.js +0 -2
  868. package/dist/bundle/chunks/seq-IN77HD3S.js +0 -2
  869. package/dist/bundle/chunks/sha1sum-BLPZJ6MP.js +0 -2
  870. package/dist/bundle/chunks/sha256sum-VJZ4PHQ4.js +0 -2
  871. package/dist/bundle/chunks/sort-PV2NEQHF.js +0 -2
  872. package/dist/bundle/chunks/split-6R2TSQY6.js +0 -2
  873. package/dist/bundle/chunks/sqlite3-7MBPFI6W.js +0 -2
  874. package/dist/bundle/chunks/stat-YLVJ4L67.js +0 -2
  875. package/dist/bundle/chunks/strings-WTD7Q2EF.js +0 -2
  876. package/dist/bundle/chunks/tac-YXC4HBTR.js +0 -2
  877. package/dist/bundle/chunks/tail-UGFWX3YY.js +0 -2
  878. package/dist/bundle/chunks/tar-BNHPWTOY.js +0 -2
  879. package/dist/bundle/chunks/tee-OOWSWHRQ.js +0 -2
  880. package/dist/bundle/chunks/time-N6J6DC6C.js +0 -2
  881. package/dist/bundle/chunks/timeout-ZHCL5KTP.js +0 -2
  882. package/dist/bundle/chunks/touch-W4DF6Z4T.js +0 -2
  883. package/dist/bundle/chunks/tr-4NGL47UU.js +0 -2
  884. package/dist/bundle/chunks/unexpand-YD5BWFH4.js +0 -2
  885. package/dist/bundle/chunks/uniq-OVOW532K.js +0 -2
  886. package/dist/bundle/chunks/wc-RUR7HE5O.js +0 -2
  887. package/dist/bundle/chunks/xan-7R3I2DJO.js +0 -2
  888. package/dist/bundle/chunks/xan-view-S4ZILLPU.js +0 -2
  889. package/dist/bundle/chunks/xargs-L7TJHOJT.js +0 -2
  890. package/dist/bundle/chunks/yes-I7SAR7XX.js +0 -2
  891. package/dist/bundle/chunks/yq-IOMBQYB2.js +0 -2
@@ -1,62 +1,62 @@
1
1
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
2
- import{a as Ft,b as Mt,c as ot}from"./chunks/chunk-353VO5TF.js";import{a as Mr,b as ir}from"./chunks/chunk-SRB6FXRH.js";import{a as _r,b as Tr,c as nr,d as rr}from"./chunks/chunk-43OP7DFL.js";import{c as ai,e as $a,f as Ca}from"./chunks/chunk-XZ34OGNM.js";import{a as Qt}from"./chunks/chunk-J2OBOJ64.js";import{a as oi}from"./chunks/chunk-L2UW7DWF.js";import{a as Zt,b as Ye,c as ar}from"./chunks/chunk-DLL7UR66.js";import{a as or,b as Pa}from"./chunks/chunk-CHWP6GRK.js";import{a as ge}from"./chunks/chunk-7GA3QWJJ.js";import{a as zt,b as Ce}from"./chunks/chunk-CBM6J4AL.js";import"./chunks/chunk-6D3WD6YU.js";import{d as Gt,e as Tn}from"./chunks/chunk-DIWMSSQY.js";import"./chunks/chunk-STHBFACM.js";import{a as xa}from"./chunks/chunk-RK2WBVP4.js";import{a as W,b as Lt,c as z,d as yt,e as Ht,f as it,g as Ln}from"./chunks/chunk-YUSFCOM7.js";import{a as _n,b as Qe,c as Ke,d as Le,e as Ve,f as ze,g as q,h as le,i as Xe,j as jt,k as Lr,l as $,m as Ue,n as qt,o as Fr,p as st}from"./chunks/chunk-EFORKKSH.js";import{a as M,b as sr,c as wn,d as Qf,e as Ut,f as si,g as In,h as Kf,i as _t,j as ii,k as Xf,l as Yf}from"./chunks/chunk-GN6CQ3J4.js";import{a as Tt}from"./chunks/chunk-W5DWRFSU.js";import{a as kt}from"./chunks/chunk-FOCWZZDE.js";import{a as ri}from"./chunks/chunk-NCUTH6QL.js";var En=[{name:"echo",load:async()=>(await import("./chunks/echo-PLLZYM2L.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-54BXBS6X.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-V42QCPHL.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-MQTYWW4T.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-4A5W3RXH.js")).mkdirCommand},{name:"mktemp",load:async()=>(await import("./chunks/mktemp-XKIE5N3X.js")).mktempCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-OGSEXEF4.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-W4DF6Z4T.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-3XUUYAXQ.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-LTFB4EUA.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-ZPIATQJL.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-OPY2ZVGQ.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-4OPV4QKK.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-76BPYV5F.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-YNNS6F7K.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-J6RVJFRS.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-UGFWX3YY.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-RUR7HE5O.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-YLVJ4L67.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-OZCR76FT.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-OZCR76FT.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-OZCR76FT.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-F4SX2PHI.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-MBB5SXGD.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-V7KYQWCD.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-PV2NEQHF.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-OVOW532K.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-DTWKU2MC.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-IRSHL3BB.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-U57ZU47S.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-4NGL47UU.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-EPOS3MFH.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-RFXH2GNX.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-QJBPHRFJ.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-2BPPGGSM.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-YD5BWFH4.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-WTD7Q2EF.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-6R2TSQY6.js")).split},{name:"column",load:async()=>(await import("./chunks/column-F5JDBRV6.js")).column},{name:"join",load:async()=>(await import("./chunks/join-KQ4Z5OD4.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-OOWSWHRQ.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-JTXDH3MR.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-SJZQ5W65.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-Z2ZMOOW2.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-7OOL2MH6.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-DOWSRLXR.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-VUUMB47B.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-VUUMB47B.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-T5TO5GWK.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-T5TO5GWK.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-3N762S3K.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-L7TJHOJT.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-QUBPEGGU.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-QUBPEGGU.js")).falseCommand},{name:"yes",load:async()=>(await import("./chunks/yes-I7SAR7XX.js")).yesCommand},{name:"clear",load:async()=>(await import("./chunks/clear-KPIUNI6K.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-HIEWVHJ2.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-HIEWVHJ2.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-FCG2IUBK.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-QPSYZAAJ.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-VDB6RXHO.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-FN2DXAEE.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-3QNP3BGR.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-ZHCL5KTP.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-N6J6DC6C.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-IN77HD3S.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-GZ4DABKB.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-JEDX55KS.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-BLPZJ6MP.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-VJZ4PHQ4.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-UI6QJAAU.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-7OG5VWYG.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-62M75TSG.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-UWVKETYW.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-YXC4HBTR.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-CESD3CQR.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-KR6E7UIR.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-LUHOH7CG.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-GQC6CWVL.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-GQC6CWVL.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-GQC6CWVL.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(En.push({name:"tar",load:async()=>(await import("./chunks/tar-BNHPWTOY.js")).tarCommand}),En.push({name:"yq",load:async()=>(await import("./chunks/yq-IOMBQYB2.js")).yqCommand}),En.push({name:"xan",load:async()=>(await import("./chunks/xan-7R3I2DJO.js")).xanCommand}),En.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-7MBPFI6W.js")).sqlite3Command}));var Br=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Br.push({name:"python3",load:async()=>(await import("./chunks/python3-SDFCGIU4.js")).python3Command}),Br.push({name:"python",load:async()=>(await import("./chunks/python3-SDFCGIU4.js")).pythonCommand}));var Wr=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Wr.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-NDLXDUBN.js")).jsExecCommand}),Wr.push({name:"node",load:async()=>(await import("./chunks/js-exec-NDLXDUBN.js")).nodeStubCommand}));var Ra=[{name:"curl",load:async()=>(await import("./chunks/curl-XCX2ZQEA.js")).curlCommand}],Na=new Map;function Vr(e){return{name:e.name,async execute(t,n){let r=Na.get(e.name);if(r||(r=await Ce.runTrustedAsync(()=>ir(e.load(),n.signal,`bash: ${e.name} was cancelled before it started
3
- `)),Na.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await ir(import("./chunks/flag-coverage-EDO3VM43.js"),n.signal,`bash: ${e.name} was cancelled before it started
4
- `);s(n.coverage,e.name,t)}return r.execute(t,n)}}}function Jf(){return En.map(e=>e.name)}function ed(){return Ra.map(e=>e.name)}function Oa(e){return(e?En.filter(n=>e.includes(n.name)):En).map(Vr)}function Da(){return Ra.map(Vr)}function td(){return Br.map(e=>e.name)}function Ia(){return Br.map(Vr)}function nd(){return Wr.map(e=>e.name)}function _a(){return Wr.map(Vr)}var Ta=new WeakMap,La=new WeakSet;function zr(e){let t=Ta.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),Ta.set(e,t),La.add(t)),t}function Fa(e){return La.has(e)}var Ma={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},rd={...Ma,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 Ur(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?rd:Ma;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 sd(e){let{executionLimits:t,executionLimitProfile:n,fs:r,stdin:s=si,...i}=e;return{fs:r,fsIdentity:i.fsIdentity??zr(r),cwd:"/",env:new Map,stdin:s,limits:Ur(t,n),...i}}function Ba(e){return"load"in e&&typeof e.load=="function"}function id(e,t,n={}){return{name:e,trusted:n.trusted!==!1,execute:t}}function Wa(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}Ca.call(a,s,i)};return{name:e.name,trusted:e.trusted!==!1,async execute(a,l){if(!t){let u,f=new Promise((d,h)=>{u={resolve:d,reject:h},r.add(u)});n||o();try{t=await ir(f,l.signal,`bash: ${e.name} was cancelled before it started
5
- `)}finally{u&&r.delete(u)}}let c=t;if(!c)throw new Error(`Failed to load command: ${e.name}`);return c.execute(a,l)}}}var Va=Object.freeze(Object.create(null)),jr=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 $(`${s}: ${t} work limit exceeded (${r})`,"iterations")),n>this.limits.maxWorkUnits-this.workUnits&&this.fail(new $(`${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 $(`${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 $(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 $(`${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:M(n);(!Number.isSafeInteger(s)||s<0||s>o)&&this.fail(new $(`${r}: invalid ${t} accounting`,"output_size"));let a=o-s;return a>this.limits.maxOutputSize-this.outputBytes&&this.fail(new $(`${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 $(`${n}: unauthorized output accounting release`,"output_size")),(!Number.isSafeInteger(t)||t<0||t>this.outputBytes)&&this.fail(new $(`${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 $(`${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 Ue("",`bash: ${t} aborted
2
+ import{a as Ft,b as Mt,c as it}from"./chunks/chunk-353VO5TF.js";import{a as Wr,b as or}from"./chunks/chunk-LBKOJW6K.js";import{a as Lr,b as Fr,c as rr,d as sr}from"./chunks/chunk-43OP7DFL.js";import{c as fi,e as Oa,f as Da}from"./chunks/chunk-XZ34OGNM.js";import{a as Qt}from"./chunks/chunk-BLTFJFWH.js";import{a as ui}from"./chunks/chunk-L2UW7DWF.js";import{a as Zt,b as Ye,c as lr}from"./chunks/chunk-DLL7UR66.js";import{a as ar,b as Ra}from"./chunks/chunk-CHWP6GRK.js";import{a as ge}from"./chunks/chunk-EOMWWW4L.js";import{a as zt,b as Ce}from"./chunks/chunk-CBM6J4AL.js";import"./chunks/chunk-NJUHQKMR.js";import{d as Gt,e as Ln}from"./chunks/chunk-Q6ZH76O4.js";import"./chunks/chunk-STHBFACM.js";import{a as Na}from"./chunks/chunk-RK2WBVP4.js";import{a as j,b as Lt,c as q,d as mt,e as Ht,f as st,g as Fn}from"./chunks/chunk-YUSFCOM7.js";import{a as Tn,b as Qe,c as Ke,d as Le,e as Ve,f as ze,g as G,h as le,i as Xe,j as jt,k as Mr,l as C,m as Ue,n as qt,o as Br,p as rt}from"./chunks/chunk-IQGNPH54.js";import{a as V,b as ir,c as wn,d as td,e as Ut,f as li,g as _n,h as nd,i as _t,j as ci,k as rd,l as sd}from"./chunks/chunk-U3UTFNHI.js";import{a as Tt,b as Ca}from"./chunks/chunk-WFEUQRHM.js";import{a as kt}from"./chunks/chunk-FOCWZZDE.js";import{a as ai}from"./chunks/chunk-NCUTH6QL.js";var En=[{name:"echo",load:async()=>(await import("./chunks/echo-PLLZYM2L.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-UBR2ABBH.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-BNADL4RX.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-WMN4WCCI.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-YJMG55FX.js")).mkdirCommand},{name:"mktemp",load:async()=>(await import("./chunks/mktemp-RA55VAN3.js")).mktempCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-HI3UE4KQ.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-57OKADDG.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-CDVWO5CO.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-AQ4Y4WVV.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-NTJL2AHI.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-OPY2ZVGQ.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-5VBARXGU.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-76BPYV5F.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-HGACDFRD.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-5YWCKNNQ.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-IBKQAMFW.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-HQPGW3KR.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-APUQD6WQ.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-ZELVZ7JB.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-ZELVZ7JB.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-ZELVZ7JB.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-IN3KT335.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-MXZDFQ7I.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-LEEKKBPN.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-ATCMEITA.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-TUUUYPVF.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-QHEYSM4I.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-A6NXJGOH.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-VPYCLIL6.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-M4D6SICQ.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-W57N4M5B.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-Z5DVHZ3S.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-A24KLKHY.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-YVEZTU7W.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-SYZZ5ZBE.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-WA2ZGNUN.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-YZFCWIZI.js")).split},{name:"column",load:async()=>(await import("./chunks/column-46NX3HG3.js")).column},{name:"join",load:async()=>(await import("./chunks/join-MSZXRLNV.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-VOXQ2UGV.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-UYQIFSZI.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-SJZQ5W65.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-Z2ZMOOW2.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-7OOL2MH6.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-JOLY42MC.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-MI6QVNMM.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-MI6QVNMM.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-T5TO5GWK.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-T5TO5GWK.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-3N762S3K.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-WFPZZ3FK.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-QUBPEGGU.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-QUBPEGGU.js")).falseCommand},{name:"yes",load:async()=>(await import("./chunks/yes-ACSNSE7T.js")).yesCommand},{name:"clear",load:async()=>(await import("./chunks/clear-KPIUNI6K.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-QTX2IUM4.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-QTX2IUM4.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-MKA6BDYV.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-GBEVK7UP.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-SECJC7CN.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-YMEJ62OQ.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-3QNP3BGR.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-FVGYB3MD.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-GOHAC6VO.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-E3UP3G65.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-U7WETT5R.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-OCX4NZ2Q.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-QUWYL7G6.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-FGHIABMA.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-6QDI3H7G.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-EOWI2I5J.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-62M75TSG.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-UWVKETYW.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-OCV6R4TG.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-CESD3CQR.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-KR6E7UIR.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-TRWBMEIO.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-3IFADYVU.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-3IFADYVU.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-3IFADYVU.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(En.push({name:"tar",load:async()=>(await import("./chunks/tar-WJV4DGKA.js")).tarCommand}),En.push({name:"yq",load:async()=>(await import("./chunks/yq-XDJLIJPZ.js")).yqCommand}),En.push({name:"xan",load:async()=>(await import("./chunks/xan-CZJZCC57.js")).xanCommand}),En.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-JL36RFBZ.js")).sqlite3Command}));var Vr=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Vr.push({name:"python3",load:async()=>(await import("./chunks/python3-TIKLWPZJ.js")).python3Command}),Vr.push({name:"python",load:async()=>(await import("./chunks/python3-TIKLWPZJ.js")).pythonCommand}));var zr=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(zr.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-CNDWLKWB.js")).jsExecCommand}),zr.push({name:"node",load:async()=>(await import("./chunks/js-exec-CNDWLKWB.js")).nodeStubCommand}));var _a=[{name:"curl",load:async()=>(await import("./chunks/curl-LMCQFYWH.js")).curlCommand}],Ia=new Map;function Ur(e){return{name:e.name,async execute(t,n){let r=Ia.get(e.name);if(r||(r=await Ce.runTrustedAsync(()=>or(e.load(),n.signal,`bash: ${e.name} was cancelled before it started
3
+ `)),Ia.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await or(import("./chunks/flag-coverage-5YCE6ILG.js"),n.signal,`bash: ${e.name} was cancelled before it started
4
+ `);s(n.coverage,e.name,t)}return r.execute(t,n)}}}function id(){return En.map(e=>e.name)}function od(){return _a.map(e=>e.name)}function Ta(e){return(e?En.filter(n=>e.includes(n.name)):En).map(Ur)}function La(){return _a.map(Ur)}function ad(){return Vr.map(e=>e.name)}function Fa(){return Vr.map(Ur)}function ld(){return zr.map(e=>e.name)}function Ma(){return zr.map(Ur)}var Ba=new WeakMap,Wa=new WeakSet;function jr(e){let t=Ba.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),Ba.set(e,t),Wa.add(t)),t}function Va(e){return Wa.has(e)}var za={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},cd={...za,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 qr(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?cd:za;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 ud(e){let{executionLimits:t,executionLimitProfile:n,fs:r,stdin:s=li,...i}=e;return{fs:r,fsIdentity:i.fsIdentity??jr(r),cwd:"/",env:new Map,stdin:s,limits:qr(t,n),...i}}function Ua(e){return"load"in e&&typeof e.load=="function"}function fd(e,t,n={}){return{name:e,trusted:n.trusted!==!1,execute:t}}function ja(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}Da.call(a,s,i)};return{name:e.name,trusted:e.trusted!==!1,async execute(a,l){if(!t){let u,f=new Promise((d,h)=>{u={resolve:d,reject:h},r.add(u)});n||o();try{t=await or(f,l.signal,`bash: ${e.name} was cancelled before it started
5
+ `)}finally{u&&r.delete(u)}}let c=t;if(!c)throw new Error(`Failed to load command: ${e.name}`);return c.execute(a,l)}}}var qa=Object.freeze(Object.create(null)),Gr=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:V(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!==qa&&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 Ue("",`bash: ${t} aborted
6
6
  `)),Date.now()-this.startedAt>this.limits.maxExecutionTimeMs&&this.fail(new Ue("",`bash: ${t} exceeded execution deadline (${this.limits.maxExecutionTimeMs}ms)
7
- `))}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=nr(()=>a({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(rr(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 $(`maximum nested execution depth (${this.limits.maxExecDepth}) exceeded`,"recursion"))}};function za(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 Ua(e,t,n="pipeline"){e.relinquishOutput(t,n,Va)}var bn=new TextEncoder;function od(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var gt=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:M(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:M(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):od(s)?this.writeFileSync(r,s.content,void 0,{mode:s.mode,mtime:s.mtime}):this.writeFileSync(r,s)}ensureParentDirs(t){let n=yt(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){z(t,"write");let i=W(t);this.ensureParentDirs(i);let o=ot(r);this.assertCanAllocate(i,this.contentByteLength(n,o));let a=Ft(n,o);this.setEntry(i,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}writeFileLazy(t,n,r){z(t,"write");let s=W(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 Ce.runTrustedAsync(async()=>n.lazy()),s=typeof r=="string"?bn.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=ot(n);return Mt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Mt(n,"binary")}async readFileBuffer(t){z(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:bn.encode(s.content)}return r.content instanceof Uint8Array?r.content:bn.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){z(t,"append");let s=W(t),i=this.data.get(s);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=ot(r),a=this.contentByteLength(n,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(s,l));let c="content"in l&&l.content instanceof Uint8Array?l.content:bn.encode("content"in l?l.content:"");this.assertCanAllocate(s,c.byteLength+a);let u=Ft(n,o),f=new Uint8Array(c.length+u.length);f.set(c),f.set(u,c.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){z(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=bn.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){z(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=bn.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=W(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),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(s),s=Ln(s,l.target),l=this.data.get(s),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let n=W(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,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(s),s=Ln(s,a.target),a=this.data.get(s),l++}if(l>=c)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";z(t,n.directory?"mkdir":"write");let s=W(t),i=yt(s),o=i==="/"?"/":this.resolvePathWithSymlinks(i),a=it(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){z(t,"mkdir");let r=W(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=yt(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){z(t,"scandir");let n=W(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=Ln(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 c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,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){z(t,"rm");let r=W(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=it(r,o);await this.rm(a,n)}}}this.deleteEntry(r)}async cp(t,n,r){z(t,"cp"),z(n,"cp");let s=W(t),i=W(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:bn.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(Lt(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 c=it(s,l),u=it(i,l);await this.cp(c,u,r)}}}async mv(t,n){z(t,"mv"),z(n,"mv");let r=W(t),s=W(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"&&Lt(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(it(r,a),it(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 Ht(t,n)}async chmod(t,n){z(t,"chmod");let r=W(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){z(n,"symlink");let r=W(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){z(t,"link"),z(n,"link");let r=W(t),s=W(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){z(t,"readlink");let n=W(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){z(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){z(t,"utimes");let s=W(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 ja="5.1.0(1)-release",qa="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function ci(e){let{pid:t,ppid:n,uid:r,gid:s}=e;return`Name: bash
7
+ `))}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=rr(()=>a({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(sr(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 Ga(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 Ha(e,t,n="pipeline"){e.relinquishOutput(t,n,qa)}var bn=new TextEncoder;function dd(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var yt=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:V(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:V(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):dd(s)?this.writeFileSync(r,s.content,void 0,{mode:s.mode,mtime:s.mtime}):this.writeFileSync(r,s)}ensureParentDirs(t){let n=mt(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=j(t);this.ensureParentDirs(i);let o=it(r);this.assertCanAllocate(i,this.contentByteLength(n,o));let a=Ft(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=j(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 Ce.runTrustedAsync(async()=>n.lazy()),s=typeof r=="string"?bn.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=it(n);return Mt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Mt(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:bn.encode(s.content)}return r.content instanceof Uint8Array?r.content:bn.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){q(t,"append");let s=j(t),i=this.data.get(s);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=it(r),a=this.contentByteLength(n,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(s,l));let c="content"in l&&l.content instanceof Uint8Array?l.content:bn.encode("content"in l?l.content:"");this.assertCanAllocate(s,c.byteLength+a);let u=Ft(n,o),f=new Uint8Array(c.length+u.length);f.set(c),f.set(u,c.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=bn.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=bn.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=j(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),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(s),s=Fn(s,l.target),l=this.data.get(s),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let n=j(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,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(s),s=Fn(s,a.target),a=this.data.get(s),l++}if(l>=c)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=j(t),i=mt(s),o=i==="/"?"/":this.resolvePathWithSymlinks(i),a=st(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=j(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=mt(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=j(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=Fn(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 c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,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=j(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=st(r,o);await this.rm(a,n)}}}this.deleteEntry(r)}async cp(t,n,r){q(t,"cp"),q(n,"cp");let s=j(t),i=j(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:bn.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(Lt(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 c=st(s,l),u=st(i,l);await this.cp(c,u,r)}}}async mv(t,n){q(t,"mv"),q(n,"mv");let r=j(t),s=j(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"&&Lt(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(st(r,a),st(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 Ht(t,n)}async chmod(t,n){q(t,"chmod");let r=j(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=j(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=j(t),s=j(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=j(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=j(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 Za="5.1.0(1)-release",Qa="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function hi(e){let{pid:t,ppid:n,uid:r,gid:s}=e;return`Name: bash
8
8
  State: R (running)
9
9
  Pid: ${t}
10
10
  PPid: ${n}
11
11
  Uid: ${r} ${r} ${r} ${r}
12
12
  Gid: ${s} ${s} ${s} ${s}
13
- `}function ad(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function ld(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 cd(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 ud(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${qa}
13
+ `}function hd(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function pd(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 md(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 yd(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Qa}
14
14
  `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
15
- `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>ci(t)):e.writeFileSync("/proc/self/status",ci(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 Ga(e,t,n={pid:1,ppid:0,uid:1e3,gid:1e3}){if(ad(e)){let r=fd(e);ld(r,t),cd(r),ud(r,n)}}function fd(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 Kt=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new gt,t?.mounts)for(let{mountPoint:n,filesystem:r}of t.mounts)this.mount(n,r)}mount(t,n){this.validateMountPath(t);let r=W(t);this.validateMount(r),this.mounts.set(r,n)}unmount(t){let n=W(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=W(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){z(t,"access");let n=W(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=W(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 In(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=W(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=W(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=W(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=W(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=W(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 xa(t,s);let a=yt(o);return a!=="/"&&this.getChildMountPoints(yt(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=W(t),r=new Set,s=null,{fs:i,relativePath:o}=this.routePath(t);try{let l=await i.readdir(o);for(let c of l)r.add(c)}catch(l){let c=l.code,u=l.message||"";if(c!=="ENOENT"&&!u.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=W(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&&Lt(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=W(t);if((await this.stat(t)).isDirectory&&Lt(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 Ht(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=W(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=W(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=it(t,o),l=it(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 Me(e){return{kind:e.kind,elements:new Map(e.elements)}}function at(e){return new Map(Array.from(e??[],([t,n])=>[t,Me(n)]))}function xe(e,t){return e.state.arrays?.get(t)}function lr(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 Xt(e,t,n){let r=lr(e,t,n);return r.kind=n,r}function Ne(e,t){return e.state.arrays?.has(t)??!1}function ae(e,t,n){return xe(e,t)?.elements.get(String(n))}function Yt(e,t,n){return xe(e,t)?.elements.has(String(n))??!1}function G(e,t,n,r,s){let i=lr(e,t,s),o=String(n);if(!i.elements.has(o)&&i.elements.size>=e.limits.maxArrayElements)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(M(r)>e.limits.maxStringLength)throw new $(`array value string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");i.elements.set(o,r)}function Sn(e,t,n,r=!1){let s=new Set(r?[]:xe(e,t)?.elements.keys()??[]);for(let i of n)if(s.add(String(i)),s.size>e.limits.maxArrayElements)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements")}function An(e,t,n){return xe(e,t)?.elements.delete(String(n))??!1}function cr(e,t){e.state.arrays?.delete(t),e.state.associativeArrays?.delete(t)}function ve(e,t){return Array.from(xe(e,t)?.elements.keys()??[]).filter(r=>/^(0|[1-9]\d*)$/.test(r)).map(Number).sort((r,s)=>r-s)}function Ee(e,t){lr(e,t,e.state.associativeArrays?.has(t)?"associative":"indexed").elements.clear()}function xt(e,t){return Array.from(xe(e,t)?.elements.keys()??[]).sort()}function Gr(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function ui(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=Gr(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=[],c=a?2:1,u=o.slice(c);u&&l.push({type:"Literal",value:u});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?l.push({type:"Literal",value:dd(d)}):l.push(d)}return{key:r,valueParts:l,append:a}}function dd(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 Mn(n.word)}).join(",")}}`}function Mn(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}`:""}`:Mn(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",n.user&&(t+=n.user);break}return t}var hd=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],pd=["braceexpand","hashall","interactive-comments"];function fi(e){let t=[],n=[...pd.map(r=>({name:r,enabled:!0})),...hd.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 Bn(e){e.state.env.set("SHELLOPTS",fi(e.state.options))}var md=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function di(e){let t=[];for(let n of md)e[n]&&t.push(n);return t.join(":")}function hi(e){e.state.env.set("BASHOPTS",di(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 Ha(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 Hr(e,t){let n="",r=t,s=0,i=!1,o,a=l=>l===" "||l===" "||l===`
15
+ `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>hi(t)):e.writeFileSync("/proc/self/status",hi(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 Ka(e,t,n={pid:1,ppid:0,uid:1e3,gid:1e3}){if(hd(e)){let r=gd(e);pd(r,t),md(r),yd(r,n)}}function gd(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 Kt=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new yt,t?.mounts)for(let{mountPoint:n,filesystem:r}of t.mounts)this.mount(n,r)}mount(t,n){this.validateMountPath(t);let r=j(t);this.validateMount(r),this.mounts.set(r,n)}unmount(t){let n=j(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=j(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=j(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=j(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 _n(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=j(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=j(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=j(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=j(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=j(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 Na(t,s);let a=mt(o);return a!=="/"&&this.getChildMountPoints(mt(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=j(t),r=new Set,s=null,{fs:i,relativePath:o}=this.routePath(t);try{let l=await i.readdir(o);for(let c of l)r.add(c)}catch(l){let c=l.code,u=l.message||"";if(c!=="ENOENT"&&!u.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=j(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&&Lt(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=j(t);if((await this.stat(t)).isDirectory&&Lt(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 Ht(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=j(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=j(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=st(t,o),l=st(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 Me(e){return{kind:e.kind,elements:new Map(e.elements)}}function ot(e){return new Map(Array.from(e??[],([t,n])=>[t,Me(n)]))}function ke(e,t){return e.state.arrays?.get(t)}function cr(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 Xt(e,t,n){let r=cr(e,t,n);return r.kind=n,r}function Ne(e,t){return e.state.arrays?.has(t)??!1}function ae(e,t,n){return ke(e,t)?.elements.get(String(n))}function Yt(e,t,n){return ke(e,t)?.elements.has(String(n))??!1}function H(e,t,n,r,s){let i=cr(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(V(r)>e.limits.maxStringLength)throw new C(`array value string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");i.elements.set(o,r)}function Sn(e,t,n,r=!1){let s=new Set(r?[]:ke(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 An(e,t,n){return ke(e,t)?.elements.delete(String(n))??!1}function ur(e,t){e.state.arrays?.delete(t),e.state.associativeArrays?.delete(t)}function Ae(e,t){return Array.from(ke(e,t)?.elements.keys()??[]).filter(r=>/^(0|[1-9]\d*)$/.test(r)).map(Number).sort((r,s)=>r-s)}function Ee(e,t){cr(e,t,e.state.associativeArrays?.has(t)?"associative":"indexed").elements.clear()}function xt(e,t){return Array.from(ke(e,t)?.elements.keys()??[]).sort()}function Zr(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function pi(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=Zr(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=[],c=a?2:1,u=o.slice(c);u&&l.push({type:"Literal",value:u});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?l.push({type:"Literal",value:wd(d)}):l.push(d)}return{key:r,valueParts:l,append:a}}function wd(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 Bn(n.word)}).join(",")}}`}function Bn(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}`:""}`:Bn(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",n.user&&(t+=n.user);break}return t}var Ed=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],bd=["braceexpand","hashall","interactive-comments"];function Qr(e){let t=[],n=[...bd.map(r=>({name:r,enabled:!0})),...Ed.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 Wn(e){e.state.env.set("SHELLOPTS",Qr(e.state.options))}var Sd=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Kr(e){let t=[];for(let n of Sd)e[n]&&t.push(n);return t.join(":")}function mi(e){e.state.env.set("BASHOPTS",Kr(e.state.shoptOptions))}var M={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 Xa(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 Xr(e,t){let n="",r=t,s=0,i=!1,o,a=l=>l===" "||l===" "||l===`
16
16
  `||l===";"||l==="&"||l==="|"||l==="<"||l===">"||l==="("||l===")";for(;r<e.length;){let l=e[r];if(l==="'"){let c=s>0;for(c||(i=!0),c&&(n+=l),r++;r<e.length&&e[r]!=="'";)n+=e[r],r++;r<e.length?(c&&(n+=e[r]),r++):o=l;continue}if(l==='"'){let c=s>0;for(c||(i=!0),c&&(n+=l),r++;r<e.length&&e[r]!=='"';){if(e[r]==="\\"&&r+1<e.length){if(c){n+=e.slice(r,r+2),r+=2;continue}let u=e[r+1];if(u==="$"||u==="`"||u==='"'||u==="\\"||u===`
17
17
  `){r+=2,u!==`
18
18
  `&&(n+=u);continue}}n+=e[r],r++}r<e.length?(c&&(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 c=e[r+1];c!==`
19
- `&&(n+=c),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 yd(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(`
20
- `,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 Za(e,t,n){let r=1,s=t,i=!1,o=!1,a=0,l=!1,c="",u=[],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 h=s+2,p=!1;for(e[h]==="-"&&(p=!0,h++);e[h]===" "||e[h]===" ";)h++;let{delim:m,endPos:E,unclosedQuote:S,unclosedSubstitution:y}=Hr(e,h);if(S&&n(`unexpected EOF while looking for matching \`${S}'`),y&&n("unexpected EOF while looking for matching `)'"),m.length>0){u.push({delim:m,stripTabs:p}),c="",s=E;continue}}if(d===`
21
- `&&u.length>0){let h=yd(e,s,u);u.length=0,c="",s=h;continue}d==="'"?(i=!0,c=""):d==='"'?(o=!0,c=""):d==="\\"&&s+1<e.length?(s++,c=""):/[a-zA-Z_]/.test(d)?c+=d:(c==="case"?(a++,l=!1):c==="in"&&a>0?l=!0:c==="esac"&&a>0&&(a--,l=!1),c="",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 Qa(e,t,n,r){let s=t+2,i=Za(e,s,r),o=e.slice(s,i),l=n().parse(o);return{part:F.commandSubstitution(l,!1),endIndex:i+1}}function Ka(e,t,n,r){let s=e[t]==="<"?"input":"output",i=t+2,o=Za(e,i,r),a=n().parse(e.slice(i,o));return{part:F.processSubstitution(a,s),endIndex:o+1}}function Xa(e,t,n,r,s){let o=t+1,a="";for(;o<e.length&&e[o]!=="`";)if(e[o]==="\\"){let u=e[o+1];u==="$"||u==="`"||u==="\\"||u===`
19
+ `&&(n+=c),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 Ad(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(`
20
+ `,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 Ya(e,t,n){let r=1,s=t,i=!1,o=!1,a=0,l=!1,c="",u=[],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 h=s+2,p=!1;for(e[h]==="-"&&(p=!0,h++);e[h]===" "||e[h]===" ";)h++;let{delim:m,endPos:y,unclosedQuote:b,unclosedSubstitution:w}=Xr(e,h);if(b&&n(`unexpected EOF while looking for matching \`${b}'`),w&&n("unexpected EOF while looking for matching `)'"),m.length>0){u.push({delim:m,stripTabs:p}),c="",s=y;continue}}if(d===`
21
+ `&&u.length>0){let h=Ad(e,s,u);u.length=0,c="",s=h;continue}d==="'"?(i=!0,c=""):d==='"'?(o=!0,c=""):d==="\\"&&s+1<e.length?(s++,c=""):/[a-zA-Z_]/.test(d)?c+=d:(c==="case"?(a++,l=!1):c==="in"&&a>0?l=!0:c==="esac"&&a>0&&(a--,l=!1),c="",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 Ja(e,t,n,r){let s=t+2,i=Ya(e,s,r),o=e.slice(s,i),l=n().parse(o);return{part:M.commandSubstitution(l,!1),endIndex:i+1}}function el(e,t,n,r){let s=e[t]==="<"?"input":"output",i=t+2,o=Ya(e,i,r),a=n().parse(e.slice(i,o));return{part:M.processSubstitution(a,s),endIndex:o+1}}function tl(e,t,n,r,s){let o=t+1,a="";for(;o<e.length&&e[o]!=="`";)if(e[o]==="\\"){let u=e[o+1];u==="$"||u==="`"||u==="\\"||u===`
22
22
  `||n&&u==='"'?(u!==`
23
- `&&(a+=u),o+=2):(a+=e[o],o++)}else a+=e[o],o++;o>=e.length&&s("unexpected EOF while looking for matching ``'");let c=r().parse(a);return{part:F.commandSubstitution(c,!0),endIndex:o+1}}var gd=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 Je=class extends Error{line;column;constructor(t,n,r){super(`line ${n}: ${t}`),this.line=n,this.column=r,this.name="LexerError"}},pi=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]]),wd=new Set(pi.values());function mi(e){return wd.has(e)}function Ya(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 Ja(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 Ed=[[";",";","&",w.SEMI_SEMI_AND],["<","<","<",w.TLESS],["&",">",">",w.AND_DGREAT]],bd=[["[","[",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]],Sd=new Map([["|",w.PIPE],["&",w.AMP],[";",w.SEMICOLON],["(",w.LPAREN],[")",w.RPAREN],["<",w.LESS],[">",w.GREAT]]);function Ad(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function el(e){return e===" "||e===" "||e===`
24
- `||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var Zr=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];pendingHeredocDelimiterMode;dparenDepth=0;maxHeredocSize;constructor(t,n){this.input=t,this.maxHeredocSize=n?.maxHeredocSize??gd}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]===`
23
+ `&&(a+=u),o+=2):(a+=e[o],o++)}else a+=e[o],o++;o>=e.length&&s("unexpected EOF while looking for matching ``'");let c=r().parse(a);return{part:M.commandSubstitution(c,!0),endIndex:o+1}}var vd=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 Je=class extends Error{line;column;constructor(t,n,r){super(`line ${n}: ${t}`),this.line=n,this.column=r,this.name="LexerError"}},yi=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]]),kd=new Set(yi.values());function gi(e){return kd.has(e)}function nl(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 rl(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 xd=[[";",";","&",g.SEMI_SEMI_AND],["<","<","<",g.TLESS],["&",">",">",g.AND_DGREAT]],Pd=[["[","[",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]],$d=new Map([["|",g.PIPE],["&",g.AMP],[";",g.SEMICOLON],["(",g.LPAREN],[")",g.RPAREN],["<",g.LESS],[">",g.GREAT]]);function Cd(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function sl(e){return e===" "||e===" "||e===`
24
+ `||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var Yr=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];pendingHeredocDelimiterMode;dparenDepth=0;maxHeredocSize;constructor(t,n){this.input=t,this.maxHeredocSize=n?.maxHeredocSize??vd}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]===`
25
25
  `)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!==`
26
26
  `&&!(i==="#"&&this.dparenDepth===0))return this.readHeredocDelimiterToken(n,r,s,l);if(i==="#"&&this.dparenDepth===0)return this.readComment(n,r,s);if(i===`
27
- `)return this.pos=n+1,this.line++,this.column=1,{type:w.NEWLINE,value:`
28
- `,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[u,f,d,h]of Ed)if(i===u&&o===f&&a===d)return this.pos=n+3,this.column=s+3,this.makeToken(h,u+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 u=this.tokens[this.tokens.length-1];return this.dparenDepth===0&&u?.end===n&&(u.type===w.LESS||u.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[u,f,d]of bd)if(!(u==="("&&f==="("||u===")"&&f===")")&&!(this.dparenDepth>0&&u===";"&&(d===w.DSEMI||d===w.SEMI_AND||d===w.SEMI_SEMI_AND))&&i===u&&o===f){if(d===w.DBRACK_START||d===w.DBRACK_END){let h=t[n+2];if(h!==void 0&&h!==" "&&h!==" "&&h!==`
29
- `&&h!==";"&&h!=="&"&&h!=="|"&&h!=="("&&h!==")"&&h!=="<"&&h!==">")break}return this.pos=n+2,this.column=s+2,this.makeToken(d,u+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 c=Sd.get(i);if(c!==void 0)return this.pos=n+1,this.column=s+1,this.makeToken(c,i,n,r,s);if(i==="{"){let u=this.scanFdVariable(n);return u!==null?(this.pos=u.end,this.column=s+(u.end-n),{type:w.FD_VARIABLE,value:u.varname,start:n,end:u.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!==`
30
- `?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 c=l;for(;c<r&&(n[c]===" "||n[c]===" ");)c++;if(c>=r)return!1;let u=n[c];if(u==="="&&n[c+1]!=="="||u===`
27
+ `)return this.pos=n+1,this.line++,this.column=1,{type:g.NEWLINE,value:`
28
+ `,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[u,f,d,h]of xd)if(i===u&&o===f&&a===d)return this.pos=n+3,this.column=s+3,this.makeToken(h,u+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 u=this.tokens[this.tokens.length-1];return this.dparenDepth===0&&u?.end===n&&(u.type===g.LESS||u.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[u,f,d]of Pd)if(!(u==="("&&f==="("||u===")"&&f===")")&&!(this.dparenDepth>0&&u===";"&&(d===g.DSEMI||d===g.SEMI_AND||d===g.SEMI_SEMI_AND))&&i===u&&o===f){if(d===g.DBRACK_START||d===g.DBRACK_END){let h=t[n+2];if(h!==void 0&&h!==" "&&h!==" "&&h!==`
29
+ `&&h!==";"&&h!=="&"&&h!=="|"&&h!=="("&&h!==")"&&h!=="<"&&h!==">")break}return this.pos=n+2,this.column=s+2,this.makeToken(d,u+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 c=$d.get(i);if(c!==void 0)return this.pos=n+1,this.column=s+1,this.makeToken(c,i,n,r,s);if(i==="{"){let u=this.scanFdVariable(n);return u!==null?(this.pos=u.end,this.column=s+(u.end-n),{type:g.FD_VARIABLE,value:u.varname,start:n,end:u.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!==`
30
+ `?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 c=l;for(;c<r&&(n[c]===" "||n[c]===" ");)c++;if(c>=r)return!1;let u=n[c];if(u==="="&&n[c+1]!=="="||u===`
31
31
  `||l===c&&/[+\-*/%<>&|^!~?:]/.test(u)&&u!=="-"||u===")"&&n[c+1]===")")return!1;if(c>l&&(u==="-"||u==='"'||u==="'"||u==="$"||/[a-zA-Z_/.]/.test(u))){let f=c;for(;f<r&&n[f]!==`
32
32
  `;){if(n[f]===")")return!0;f++}return!1}if(u===")"){let f=c+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]!==`
33
- `;)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===`
34
- `||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===`
35
- `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">"){let b=s.slice(a,o);this.pos=o,this.column=r+(o-a);let v=pi.get(b);if(v!==void 0)return{type:v,value:b,start:t,end:o,line:n,column:r};let k=Ja(b);return k>0&&Ya(b.slice(0,k))?{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,c=this.line,u="",f=!1,d=!1,h=!1,p=!1,m=s[o]==='"'||s[o]==="'",E=!1,S=0;for(;o<i;){let g=s[o];if(!h&&!p){if(g==="("&&u.length>0&&"@*+?!".includes(u[u.length-1])){let b=this.scanExtglobPattern(o);if(b!==null){u+=b.content,o=b.end,l+=b.content.length;continue}}if(g==="["&&S===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){let b=o+1<i?s[o+1]:"";if(b==="^"||b==="!"){u+=g,o++,l++;continue}S=1,u+=g,o++,l++;continue}}else if(g==="["&&S>0){u.length>0&&u[u.length-1]!=="\\"&&S++,u+=g,o++,l++;continue}else if(g==="]"&&S>0){u.length>0&&u[u.length-1]!=="\\"&&S--,u+=g,o++,l++;continue}if(S>0){if(g===`
36
- `)break;u+=g,o++,l++;continue}if(g===" "||g===" "||g===`
37
- `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">")break}if(g==="$"&&o+1<i&&s[o+1]==="'"&&!h&&!p){for(u+="$'",o+=2,l+=2;o<i&&s[o]!=="'";)s[o]==="\\"&&o+1<i?(u+=s[o]+s[o+1],o+=2,l+=2):(u+=s[o],o++,l++);o<i&&(u+="'",o++,l++);continue}if(g==="$"&&o+1<i&&s[o+1]==='"'&&!h&&!p){o++,l++,p=!0,f=!0,u===""&&(m=!0),o++,l++;continue}if(g==="'"&&!p){if(h)if(h=!1,!m||E)u+=g;else{let b=o+1<i?s[o+1]:"";b&&!el(b)&&b!=="'"&&(b==='"'?(E=!0,u+=g,d=!1,f=!1):(E=!0,u+=g))}else h=!0,m&&!E?(d=!0,f=!0):u+=g;o++,l++;continue}if(g==='"'&&!h){if(p)if(p=!1,!m||E)u+=g;else{let b=o+1<i?s[o+1]:"";b&&!el(b)&&b!=='"'&&(b==="'"?(E=!0,u+=g,d=!1,f=!1):(E=!0,u+=g))}else p=!0,m&&!E?f=!0:u+=g;o++,l++;continue}if(g==="\\"&&!h&&o+1<i){let b=s[o+1];if(b===`
38
- `){o+=2,c++,l=1;continue}if(p){if(b==='"'||b==="\\"||b==="$"||b==="`"||b===`
39
- `){if(b===`
40
- `){o+=2,l=1,c++;continue}u+=g+b,o+=2,l+=2;continue}}else{u+=g+b,o+=2,l+=2;continue}}if(g==="$"&&o+1<i&&s[o+1]==="("&&!h){u+=g,o++,l++,u+=s[o],o++,l++;let b=1,v=!1,k=!1,A=0,P=!1,N="",x=[],C=s[o]==="("&&!this.dollarDparenIsSubshell(o),D=C?1:0;for(;b>0&&o<i;){let V=s[o];if(u+=V,v)V==="'"&&(v=!1);else if(k)V==="\\"&&o+1<i?(u+=s[o+1],o++,l++):V==='"'&&(k=!1);else{if(V==="("&&s[o+1]==="("?D++:V===")"&&s[o+1]===")"&&D>0&&D--,D===0&&V==="<"&&s[o+1]==="<"&&s[o+2]!=="<"){let K=o+2,R=!1;for(s[K]==="-"&&(R=!0,K++);s[K]===" "||s[K]===" ";)K++;let{delim:U,endPos:j,unclosedQuote:I,unclosedSubstitution:_}=Hr(s,K);if(I)throw new Je(`unexpected EOF while looking for matching \`${I}'`,c,l);if(_)throw new Je("unexpected EOF while looking for matching `)'",c,l);if(U.length>0){u+=s.slice(o+1,j),l+=j-o,x.push({delim:U,stripTabs:R}),o=j;continue}}if(V===`
41
- `&&x.length>0){c++,l=0;let K=o+1;for(let{delim:R,stripTabs:U}of x)for(;!(K>=i);){let j=s.indexOf(`
42
- `,K);j===-1&&(j=i);let I=s.slice(K,j),_=U?I.replace(/^\t+/,""):I;u+=s.slice(K,Math.min(j+1,i)),j<i&&c++;let B=j>=i;if(K=j+1,_===R||B)break}x.length=0,l=0,o=Math.min(K,i);continue}if(V==="'")v=!0,N="";else if(V==='"')k=!0,N="";else if(V==="\\"&&o+1<i)u+=s[o+1],o++,l++,N="";else if(V==="$"&&o+1<i&&s[o+1]==="{"){o++,l++,u+=s[o],o++,l++;let K=1,R=!1,U=!1;for(;K>0&&o<i;){let j=s[o];if(j==="\\"&&o+1<i&&!R){u+=j,o++,l++,u+=s[o],o++,l++;continue}u+=j,R?j==="'"&&(R=!1):U?j==='"'&&(U=!1):j==="'"?R=!0:j==='"'?U=!0:j==="{"?K++:j==="}"&&K--,j===`
43
- `?(c++,l=0):l++,o++}N="";continue}else if(V==="#"&&!C&&(N===""||/\s/.test(s[o-1]||""))){for(;o+1<i&&s[o+1]!==`
44
- `;)o++,l++,u+=s[o];N=""}else/[a-zA-Z_]/.test(V)?N+=V:(N==="case"?(A++,P=!1):N==="in"&&A>0?P=!0:N==="esac"&&A>0&&(A--,P=!1),N="",V==="("?o>0&&s[o-1]==="$"?b++:P||b++:V===")"?P?P=!1:b--:V===";"&&A>0&&(o+1<i&&s[o+1]===";"||o+1<i&&s[o+1]==="&")&&(P=!0))}V===`
45
- `&&(c++,l=0,N=""),o++,l++}continue}if(g==="$"&&o+1<i&&s[o+1]==="["&&!h){u+=g,o++,l++,u+=s[o],o++,l++;let b=1;for(;b>0&&o<i;){let v=s[o];u+=v,v==="["?b++:v==="]"?b--:v===`
46
- `&&(c++,l=0),o++,l++}continue}if(g==="$"&&o+1<i&&s[o+1]==="{"&&!h){u+=g,o++,l++,u+=s[o],o++,l++;let b=1,v=!1,k=!1,A=c,P=l,N=c,x=l;for(;b>0&&o<i;){let C=s[o];if(C==="\\"&&o+1<i&&s[o+1]===`
47
- `){o+=2,c++,l=1;continue}if(C==="\\"&&o+1<i&&!v){u+=C,o++,l++,u+=s[o],o++,l++;continue}u+=C,v?C==="'"&&(v=!1):k?C==='"'&&(k=!1):C==="'"?(v=!0,A=c,P=l):C==='"'?(k=!0,N=c,x=l):C==="{"?b++:C==="}"&&b--,C===`
48
- `&&(c++,l=0),o++,l++}if(v)throw new Je("unexpected EOF while looking for matching `''",A,P);if(k)throw new Je("unexpected EOF while looking for matching `\"'",N,x);continue}if(g==="$"&&o+1<i&&!h){let b=s[o+1];if(b==="#"||b==="?"||b==="$"||b==="!"||b==="@"||b==="*"||b==="-"||b>="0"&&b<="9"){u+=g+b,o+=2,l+=2;continue}}if(g==="`"&&!h){for(u+=g,o++,l++;o<i&&s[o]!=="`";){let b=s[o];u+=b,b==="\\"&&o+1<i&&(u+=s[o+1],o++,l++),b===`
49
- `&&(c++,l=0),o++,l++}o<i&&(u+=s[o],o++,l++);continue}u+=g,o++,g===`
50
- `?(c++,l=1):l++}if(this.pos=o,this.column=l,this.line=c,E&&m&&(u=s[t]+u,f=!1,d=!1),h||p){let g=h?"'":'"';throw new Je(`unexpected EOF while looking for matching \`${g}'`,n,r)}if(!m&&u.length>=2){if(u[0]==="'"&&u[u.length-1]==="'"){let g=u.slice(1,-1);!g.includes("'")&&!g.includes('"')&&(u=g,f=!0,d=!0)}else if(u[0]==='"'&&u[u.length-1]==='"'){let g=u.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||(u=g,f=!0,d=!1)}}if(u==="")return{type:w.WORD,value:"",start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d};let y=pi.get(u);if(!f&&y!==void 0)return{type:y,value:u,start:t,end:o,line:n,column:r};if(!m){let g=Ja(u);if(g>0&&Ya(u.slice(0,g)))return{type:w.ASSIGNMENT_WORD,value:u,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(u)?{type:w.NUMBER,value:u,start:t,end:o,line:n,column:r}:Ad(u)?{type:w.NAME,value:u,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}:{type:w.WORD,value:u,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="",c="";for(;;){for(a="";this.pos<this.input.length&&this.input[this.pos]!==`
33
+ `;)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===`
34
+ `||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===`
35
+ `||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">"){let S=s.slice(a,o);this.pos=o,this.column=r+(o-a);let v=yi.get(S);if(v!==void 0)return{type:v,value:S,start:t,end:o,line:n,column:r};let A=rl(S);return A>0&&nl(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,c=this.line,u="",f=!1,d=!1,h=!1,p=!1,m=s[o]==='"'||s[o]==="'",y=!1,b=0;for(;o<i;){let E=s[o];if(!h&&!p){if(E==="("&&u.length>0&&"@*+?!".includes(u[u.length-1])){let S=this.scanExtglobPattern(o);if(S!==null){u+=S.content,o=S.end,l+=S.content.length;continue}}if(E==="["&&b===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){let S=o+1<i?s[o+1]:"";if(S==="^"||S==="!"){u+=E,o++,l++;continue}b=1,u+=E,o++,l++;continue}}else if(E==="["&&b>0){u.length>0&&u[u.length-1]!=="\\"&&b++,u+=E,o++,l++;continue}else if(E==="]"&&b>0){u.length>0&&u[u.length-1]!=="\\"&&b--,u+=E,o++,l++;continue}if(b>0){if(E===`
36
+ `)break;u+=E,o++,l++;continue}if(E===" "||E===" "||E===`
37
+ `||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">")break}if(E==="$"&&o+1<i&&s[o+1]==="'"&&!h&&!p){for(u+="$'",o+=2,l+=2;o<i&&s[o]!=="'";)s[o]==="\\"&&o+1<i?(u+=s[o]+s[o+1],o+=2,l+=2):(u+=s[o],o++,l++);o<i&&(u+="'",o++,l++);continue}if(E==="$"&&o+1<i&&s[o+1]==='"'&&!h&&!p){o++,l++,p=!0,f=!0,u===""&&(m=!0),o++,l++;continue}if(E==="'"&&!p){if(h)if(h=!1,!m||y)u+=E;else{let S=o+1<i?s[o+1]:"";S&&!sl(S)&&S!=="'"&&(S==='"'?(y=!0,u+=E,d=!1,f=!1):(y=!0,u+=E))}else h=!0,m&&!y?(d=!0,f=!0):u+=E;o++,l++;continue}if(E==='"'&&!h){if(p)if(p=!1,!m||y)u+=E;else{let S=o+1<i?s[o+1]:"";S&&!sl(S)&&S!=='"'&&(S==="'"?(y=!0,u+=E,d=!1,f=!1):(y=!0,u+=E))}else p=!0,m&&!y?f=!0:u+=E;o++,l++;continue}if(E==="\\"&&!h&&o+1<i){let S=s[o+1];if(S===`
38
+ `){o+=2,c++,l=1;continue}if(p){if(S==='"'||S==="\\"||S==="$"||S==="`"||S===`
39
+ `){if(S===`
40
+ `){o+=2,l=1,c++;continue}u+=E+S,o+=2,l+=2;continue}}else{u+=E+S,o+=2,l+=2;continue}}if(E==="$"&&o+1<i&&s[o+1]==="("&&!h){u+=E,o++,l++,u+=s[o],o++,l++;let S=1,v=!1,A=!1,k=0,x=!1,D="",$=[],N=s[o]==="("&&!this.dollarDparenIsSubshell(o),O=N?1:0;for(;S>0&&o<i;){let R=s[o];if(u+=R,v)R==="'"&&(v=!1);else if(A)R==="\\"&&o+1<i?(u+=s[o+1],o++,l++):R==='"'&&(A=!1);else{if(R==="("&&s[o+1]==="("?O++:R===")"&&s[o+1]===")"&&O>0&&O--,O===0&&R==="<"&&s[o+1]==="<"&&s[o+2]!=="<"){let W=o+2,P=!1;for(s[W]==="-"&&(P=!0,W++);s[W]===" "||s[W]===" ";)W++;let{delim:B,endPos:U,unclosedQuote:_,unclosedSubstitution:T}=Xr(s,W);if(_)throw new Je(`unexpected EOF while looking for matching \`${_}'`,c,l);if(T)throw new Je("unexpected EOF while looking for matching `)'",c,l);if(B.length>0){u+=s.slice(o+1,U),l+=U-o,$.push({delim:B,stripTabs:P}),o=U;continue}}if(R===`
41
+ `&&$.length>0){c++,l=0;let W=o+1;for(let{delim:P,stripTabs:B}of $)for(;!(W>=i);){let U=s.indexOf(`
42
+ `,W);U===-1&&(U=i);let _=s.slice(W,U),T=B?_.replace(/^\t+/,""):_;u+=s.slice(W,Math.min(U+1,i)),U<i&&c++;let z=U>=i;if(W=U+1,T===P||z)break}$.length=0,l=0,o=Math.min(W,i);continue}if(R==="'")v=!0,D="";else if(R==='"')A=!0,D="";else if(R==="\\"&&o+1<i)u+=s[o+1],o++,l++,D="";else if(R==="$"&&o+1<i&&s[o+1]==="{"){o++,l++,u+=s[o],o++,l++;let W=1,P=!1,B=!1;for(;W>0&&o<i;){let U=s[o];if(U==="\\"&&o+1<i&&!P){u+=U,o++,l++,u+=s[o],o++,l++;continue}u+=U,P?U==="'"&&(P=!1):B?U==='"'&&(B=!1):U==="'"?P=!0:U==='"'?B=!0:U==="{"?W++:U==="}"&&W--,U===`
43
+ `?(c++,l=0):l++,o++}D="";continue}else if(R==="#"&&!N&&(D===""||/\s/.test(s[o-1]||""))){for(;o+1<i&&s[o+1]!==`
44
+ `;)o++,l++,u+=s[o];D=""}else/[a-zA-Z_]/.test(R)?D+=R:(D==="case"?(k++,x=!1):D==="in"&&k>0?x=!0:D==="esac"&&k>0&&(k--,x=!1),D="",R==="("?o>0&&s[o-1]==="$"?S++:x||S++:R===")"?x?x=!1:S--:R===";"&&k>0&&(o+1<i&&s[o+1]===";"||o+1<i&&s[o+1]==="&")&&(x=!0))}R===`
45
+ `&&(c++,l=0,D=""),o++,l++}continue}if(E==="$"&&o+1<i&&s[o+1]==="["&&!h){u+=E,o++,l++,u+=s[o],o++,l++;let S=1;for(;S>0&&o<i;){let v=s[o];u+=v,v==="["?S++:v==="]"?S--:v===`
46
+ `&&(c++,l=0),o++,l++}continue}if(E==="$"&&o+1<i&&s[o+1]==="{"&&!h){u+=E,o++,l++,u+=s[o],o++,l++;let S=1,v=!1,A=!1,k=c,x=l,D=c,$=l;for(;S>0&&o<i;){let N=s[o];if(N==="\\"&&o+1<i&&s[o+1]===`
47
+ `){o+=2,c++,l=1;continue}if(N==="\\"&&o+1<i&&!v){u+=N,o++,l++,u+=s[o],o++,l++;continue}u+=N,v?N==="'"&&(v=!1):A?N==='"'&&(A=!1):N==="'"?(v=!0,k=c,x=l):N==='"'?(A=!0,D=c,$=l):N==="{"?S++:N==="}"&&S--,N===`
48
+ `&&(c++,l=0),o++,l++}if(v)throw new Je("unexpected EOF while looking for matching `''",k,x);if(A)throw new Je("unexpected EOF while looking for matching `\"'",D,$);continue}if(E==="$"&&o+1<i&&!h){let S=s[o+1];if(S==="#"||S==="?"||S==="$"||S==="!"||S==="@"||S==="*"||S==="-"||S>="0"&&S<="9"){u+=E+S,o+=2,l+=2;continue}}if(E==="`"&&!h){for(u+=E,o++,l++;o<i&&s[o]!=="`";){let S=s[o];u+=S,S==="\\"&&o+1<i&&(u+=s[o+1],o++,l++),S===`
49
+ `&&(c++,l=0),o++,l++}o<i&&(u+=s[o],o++,l++);continue}u+=E,o++,E===`
50
+ `?(c++,l=1):l++}if(this.pos=o,this.column=l,this.line=c,y&&m&&(u=s[t]+u,f=!1,d=!1),h||p){let E=h?"'":'"';throw new Je(`unexpected EOF while looking for matching \`${E}'`,n,r)}if(!m&&u.length>=2){if(u[0]==="'"&&u[u.length-1]==="'"){let E=u.slice(1,-1);!E.includes("'")&&!E.includes('"')&&(u=E,f=!0,d=!0)}else if(u[0]==='"'&&u[u.length-1]==='"'){let E=u.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||(u=E,f=!0,d=!1)}}if(u==="")return{type:g.WORD,value:"",start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d};let w=yi.get(u);if(!f&&w!==void 0)return{type:w,value:u,start:t,end:o,line:n,column:r};if(!m){let E=rl(u);if(E>0&&nl(u.slice(0,E)))return{type:g.ASSIGNMENT_WORD,value:u,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(u)?{type:g.NUMBER,value:u,start:t,end:o,line:n,column:r}:Cd(u)?{type:g.NAME,value:u,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}:{type:g.WORD,value:u,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="",c="";for(;;){for(a="";this.pos<this.input.length&&this.input[this.pos]!==`
51
51
  `;)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(c+=a,t.quoted||f%2===0||this.pos+1>=this.input.length)break;c=c.slice(0,-1),l+=`${a}
52
52
  `,this.pos++,this.line++,this.column=1}if((t.stripTabs?c.replace(/^\t+/,""):c)===t.delimiter){o=!0,this.pos<this.input.length&&this.input[this.pos]===`
53
53
  `&&(this.pos++,this.line++,this.column=1);break}if(i+=l,i+=a,this.pos<this.input.length&&this.input[this.pos]===`
54
54
  `?(i+=`
55
55
  `,this.pos++,this.line++,this.column=1):a.length>0&&(i+=`
56
- `),i.length>this.maxHeredocSize)throw new Je(`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:c,unclosedSubstitution:u}=Hr(i,t);if(c)throw new Je(`unexpected EOF while looking for matching \`${c}'`,n,r);if(u)throw new Je("unexpected EOF while looking for matching `)'",n,r);if(a===t)throw new Je("Expected here-document delimiter",n,r);let f=n,d=r;for(let h=t;h<a;h++)i[h]===`
57
- `?(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===`
56
+ `),i.length>this.maxHeredocSize)throw new Je(`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:c,unclosedSubstitution:u}=Xr(i,t);if(c)throw new Je(`unexpected EOF while looking for matching \`${c}'`,n,r);if(u)throw new Je("unexpected EOF while looking for matching `)'",n,r);if(a===t)throw new Je("Expected here-document delimiter",n,r);let f=n,d=r;for(let h=t;h<a;h++)i[h]===`
57
+ `?(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===`
58
58
  `||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 c=s[o];if(c===" "||c===" "||c===`
59
- `||c===";"||c==="&"||c==="|"||c==="("||c===")"||c==="<"||c===">")break;if(c==="{"){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(c==="}"){o++,a++;continue}if(c==="$"&&o+1<i&&s[o+1]==="("){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="("?u++:s[o]===")"&&u--,o++,a++;continue}if(c==="$"&&o+1<i&&s[o+1]==="{"){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="{"?u++:s[o]==="}"&&u--,o++,a++;continue}if(c==="`"){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===`
59
+ `||c===";"||c==="&"||c==="|"||c==="("||c===")"||c==="<"||c===">")break;if(c==="{"){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(c==="}"){o++,a++;continue}if(c==="$"&&o+1<i&&s[o+1]==="("){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="("?u++:s[o]===")"&&u--,o++,a++;continue}if(c==="$"&&o+1<i&&s[o+1]==="{"){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="{"?u++:s[o]==="}"&&u--,o++,a++;continue}if(c==="`"){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===`
60
60
  `||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===`
61
61
  `||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===`
62
62
  `)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 u=n[s];if(s===i){if(!(u>="a"&&u<="z"||u>="A"&&u<="Z"||u==="_"))return null}else if(!(u>="a"&&u<="z"||u>="A"&&u<="Z"||u>="0"&&u<="9"||u==="_"))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 c=n[s];if(o){c==="'"&&(o=!1),c===`
@@ -64,215 +64,216 @@ Gid: ${s} ${s} ${s} ${s}
64
64
  `&&(l=!0),s++;continue}if(c==="'"){o=!0,s++;continue}if(c==='"'){a=!0,s++;continue}if(c==="\\"){s+=2;continue}if(c===`
65
65
  `&&(l=!0),c==="("){i++,s++;continue}if(c===")"){if(i--,i===1){let u=s+1;if(u<r&&n[u]===")")return!1;let f=u,d=!1;for(;f<r&&(n[f]===" "||n[f]===" "||n[f]===`
66
66
  `);)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 c=s+1;if(c<r&&n[c]===")")return!1;let u=c,f=!1;for(;u<r&&(n[u]===" "||n[u]===" "||n[u]===`
67
- `);)f=!0,u++;if(f&&u<r&&n[u]===")")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 yi=1e6,ur=1e5,vd=1e6,tl=200,Re;(function(e){e[e.Default=0]="Default",e[e.Assignment=1]="Assignment",e[e.NoBraceExpansion=2]="NoBraceExpansion",e[e.Regex=4]="Regex"})(Re||(Re={}));var nl=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]),rl=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS]),sl=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]),Pe=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"}},Qr=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>vd)throw new Pe("Maximum parse iterations exceeded (possible infinite loop)",t,n)}chargeTokens(t,n=1,r=1){if(this.tokens+=t,this.tokens>ur)throw new Pe(`Too many tokens: cumulative count exceeds limit of ${ur}`,n,r)}enter(t,n){if(this.depth++,this.depth>tl)throw this.depth--,new Pe(`Maximum parser nesting depth exceeded (${tl})`,t,n);let r=!0;return()=>{r&&(r=!1,this.depth--)}}};function ye(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
68
- `){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var Kr=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function fr(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 il(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 ol(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+=`
69
- `;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 al(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 kd(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 re(e,t){let n=kd(t),{expr:r,pos:s}=Wn(e,n,0),i=ye(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 Ge(e,t){return ye(e,t)>=e.length}function Wn(e,t,n){return xd(e,t,n)}function vn(e,t,n){return e.withDepth(()=>Wn(e,t,n))}function xd(e,t,n){let{expr:r,pos:s}=dr(e,t,n);for(s=ye(t,s);t[s]===",";){if(s++,Ge(t,s))return qe(",",s);let{expr:o,pos:a}=dr(e,t,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=ye(t,a)}return{expr:r,pos:s}}function dr(e,t,n){let{expr:r,pos:s}=Pd(e,t,n);if(s=ye(t,s),t[s]==="?"){s++;let{expr:i,pos:o}=vn(e,t,s);if(s=ye(t,o),t[s]===":"){s++;let{expr:a,pos:l}=vn(e,t,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:a},pos:l}}}return{expr:r,pos:s}}function Pd(e,t,n){let{expr:r,pos:s}=ll(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="||";){if(s+=2,Ge(t,s))return qe("||",s);let{expr:o,pos:a}=ll(e,t,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=a}return{expr:r,pos:s}}function ll(e,t,n){let{expr:r,pos:s}=cl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="&&";){if(s+=2,Ge(t,s))return qe("&&",s);let{expr:o,pos:a}=cl(e,t,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=a}return{expr:r,pos:s}}function cl(e,t,n){let{expr:r,pos:s}=ul(e,t,n);for(;s=ye(t,s),t[s]==="|"&&t[s+1]!=="|";){if(s++,Ge(t,s))return qe("|",s);let{expr:o,pos:a}=ul(e,t,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=a}return{expr:r,pos:s}}function ul(e,t,n){let{expr:r,pos:s}=fl(e,t,n);for(;s=ye(t,s),t[s]==="^";){if(s++,Ge(t,s))return qe("^",s);let{expr:o,pos:a}=fl(e,t,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=a}return{expr:r,pos:s}}function fl(e,t,n){let{expr:r,pos:s}=dl(e,t,n);for(;s=ye(t,s),t[s]==="&"&&t[s+1]!=="&";){if(s++,Ge(t,s))return qe("&",s);let{expr:o,pos:a}=dl(e,t,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=a}return{expr:r,pos:s}}function dl(e,t,n){let{expr:r,pos:s}=hl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="=="||t.slice(s,s+2)==="!=";){let i=t.slice(s,s+2);if(s+=2,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=hl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function hl(e,t,n){let{expr:r,pos:s}=gi(e,t,n);for(;;)if(s=ye(t,s),t.slice(s,s+2)==="<="||t.slice(s,s+2)===">="){let i=t.slice(s,s+2);if(s+=2,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=gi(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++,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=gi(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function gi(e,t,n){let{expr:r,pos:s}=pl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="<<"||t.slice(s,s+2)===">>";){let i=t.slice(s,s+2);if(s+=2,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=pl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function pl(e,t,n){let{expr:r,pos:s}=ml(e,t,n);for(;s=ye(t,s),(t[s]==="+"||t[s]==="-")&&t[s+1]!==t[s];){let i=t[s];if(s++,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=ml(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function ml(e,t,n){let{expr:r,pos:s}=Xr(e,t,n);for(;;)if(s=ye(t,s),t[s]==="*"&&t[s+1]!=="*"){if(s++,Ge(t,s))return qe("*",s);let{expr:o,pos:a}=Xr(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++,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=Xr(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function Xr(e,t,n){let{expr:r,pos:s}=wi(e,t,n),i=ye(t,s);if(t.slice(i,i+2)==="**"){if(i+=2,Ge(t,i))return qe("**",i);let{expr:a,pos:l}=e.withDepth(()=>Xr(e,t,i));return{expr:{type:"ArithBinary",operator:"**",left:r,right:a},pos:l}}return{expr:r,pos:s}}function wi(e,t,n){let r=ye(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(()=>wi(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(()=>wi(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}return Cd(e,t,r)}function $d(e,t){let n=e[t];return n==="$"||n==="`"}function Cd(e,t,n){let{expr:r,pos:s}=yl(e,t,n,!1),i=[r];for(;$d(t,s);){let{expr:a,pos:l}=yl(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}=vn(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=ye(t,s),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let a of Kr)if(t.slice(s,s+a.length)===a&&t.slice(s,s+a.length+1)!=="=="){s+=a.length;let{expr:l,pos:c}=e.withDepth(()=>dr(e,t,s));return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r.nameExpr,subscript:r.subscript,value:l},pos:c}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r,value:l},pos:c}:{expr:{type:"ArithAssignment",operator:a,variable:r.name,value:l},pos:c}}}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 yl(e,t,n,r=!1){let s=ye(t,n),i=il(vn,e,t,s);if(i)return i;let o=ol(t,s);if(o)return o;let a=al(t,s);if(a)return a;if(t.slice(s,s+2)==="$("&&t[s+2]!=="("){s+=2;let c=1,u=s;for(;s<t.length&&c>0;)t[s]==="("?c++:t[s]===")"&&c--,c>0&&s++;let f=t.slice(u,s);return s++,{expr:{type:"ArithCommandSubst",command:f},pos:s}}if(t[s]==="`"){s++;let c=s;for(;s<t.length&&t[s]!=="`";)s++;let u=t.slice(c,s);return t[s]==="`"&&s++,{expr:{type:"ArithCommandSubst",command:u},pos:s}}if(t[s]==="("){s++;let{expr:c,pos:u}=vn(e,t,s);return s=ye(t,u),t[s]===")"&&s++,{expr:{type:"ArithGroup",expression:c},pos:s}}if(t[s]==="'"){s++;let c="";for(;s<t.length&&t[s]!=="'";)c+=t[s],s++;t[s]==="'"&&s++;let u=Number.parseInt(c,10);return{expr:{type:"ArithSingleQuote",content:c,value:Number.isNaN(u)?0:u},pos:s}}if(t[s]==='"'){s++;let c="";for(;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?(c+=t[s+1],s+=2):(c+=t[s],s++);t[s]==='"'&&s++;let u=c.trim();if(!u)return{expr:{type:"ArithNumber",value:0},pos:s};let{expr:f}=vn(e,u,0);return{expr:f,pos:s}}if(/[0-9]/.test(t[s])){let c="",u=!1,f=!1;for(;s<t.length;){let h=t[s];if(u)if(/[0-9a-zA-Z@_]/.test(h))c+=h,s++;else break;else if(h==="#")u=!0,c+=h,s++;else if(c==="0"&&(h==="x"||h==="X")&&s+1<t.length&&/[0-9a-fA-F]/.test(t[s+1]))f=!0,c+=h,s++;else if(f&&/[0-9a-fA-F]/.test(h))c+=h,s++;else if(!f&&/[0-9]/.test(h))c+=h,s++;else break}if(s<t.length&&/[a-zA-Z_]/.test(t[s])){let h=c;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)h+=t[s],s++;return{expr:{type:"ArithSyntaxError",errorToken:h,message:`${h}: value too great for base (error token is "${h}")`},pos:s}}if(t[s]==="."&&/[0-9]/.test(t[s+1]))throw new le(`${c}.${t[s+1]}...: syntax error: invalid arithmetic operator`);if(t[s]==="["){let h=t.slice(s).trim();return{expr:{type:"ArithNumberSubscript",number:c,errorToken:h},pos:t.length}}return{expr:{type:"ArithNumber",value:fr(c)},pos:s}}if(t[s]==="$"&&t[s+1]==="{"){let c=s+2,u=1,f=c;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;let d=t.slice(c,f),h=f+1;if(t[h]==="#"){let p=h+1;for(;p<t.length&&/[0-9a-zA-Z@_]/.test(t[p]);)p++;let m=t.slice(h+1,p);return{expr:{type:"ArithDynamicBase",baseExpr:d,value:m},pos:p}}if(/[0-9]/.test(t[h])||t[h]==="x"||t[h]==="X"){let p=h;if(t[h]==="x"||t[h]==="X")for(p++;p<t.length&&/[0-9a-fA-F]/.test(t[p]);)p++;else for(;p<t.length&&/[0-9]/.test(t[p]);)p++;let m=t.slice(h,p);return{expr:{type:"ArithDynamicNumber",prefix:d,suffix:m},pos:p}}return s=h,{expr:{type:"ArithBracedExpansion",content:d},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[0-9]/.test(t[s+1])){s++;let c="";for(;s<t.length&&/[0-9]/.test(t[s]);)c+=t[s],s++;return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:!0},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[*@#?\-!$]/.test(t[s+1])){let c=t[s+1];return s+=2,{expr:{type:"ArithSpecialVar",name:c},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 c="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)c+=t[s],s++;if(t[s]==="["&&!r){s++;let u;if(t[s]==="'"||t[s]==='"'){let d=t[s];for(s++,u="";s<t.length&&t[s]!==d;)u+=t[s],s++;t[s]===d&&s++,s=ye(t,s),t[s]==="]"&&s++}let f;if(u===void 0){let{expr:d,pos:h}=vn(e,t,s);f=d,s=h,t[s]==="]"&&s++}if(s=ye(t,s),t[s]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:c,index:f},pos:s};if(!r){for(let d of Kr)if(t.slice(s,s+d.length)===d&&t.slice(s,s+d.length+1)!=="=="){s+=d.length;let{expr:h,pos:p}=e.withDepth(()=>dr(e,t,s));return{expr:{type:"ArithAssignment",operator:d,variable:c,subscript:f,stringKey:u,value:h},pos:p}}}return{expr:{type:"ArithArrayElement",array:c,index:f,stringKey:u},pos:s}}if(s=ye(t,s),!r){for(let u of Kr)if(t.slice(s,s+u.length)===u&&t.slice(s,s+u.length+1)!=="=="){s+=u.length;let{expr:f,pos:d}=e.withDepth(()=>dr(e,t,s));return{expr:{type:"ArithAssignment",operator:u,variable:c,value:f},pos:d}}}return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:l},pos:s}}if(t[s]==="#"){let c=s+1;for(;c<t.length&&t[c]!==`
70
- `;)c++;let u=t.slice(s,c).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:u,message:`${u}: syntax error: invalid arithmetic operator (error token is "${u}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:s}}var Yr=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 Nd(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 El(e,t,n){let r=n+1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;return r}function Ei(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 kn(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 bl(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=Rd(t,r);o===-1?(s+=i,r++):(s+=t.slice(r,o+1),r=o+1)}else break}return{pattern:s,endIndex:r}}function Rd(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 Al(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+=`
71
- `,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 c=t.slice(l+2,l+4),u=parseInt(c,16);if(!Number.isNaN(u)&&c.length>0)a.push(u),l+=2+c.length;else break}a.length>0?(r+=Nd(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 c=parseInt(a,8);r+=String.fromCharCode(c),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 bi(e,t){let n=t.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:re(e,n)}function wl(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 vl(e,t,n,r){let s=Ei(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:wl(i).map(u=>e.withDepth(()=>({type:"Word",word:F.word(r(e,u,!1,!1,!1))})))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:wl(i).map(u=>({type:"Word",word:F.word([F.literal(u)])}))},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 kl(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 hr(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:rl.has(r.type)}if(n===w.FD_VARIABLE){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:sl.has(r.type)}return!e.isProcessSubstitutionStart()&&nl.has(n)}function Jr(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=kl(e,r.type);if(r.type===w.DLESS||r.type===w.DLESSDASH)return Od(e,t,n,r.type===w.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return F.redirection(s,i,t,n)}function Od(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 vi(e){let t=e.getSourceLine(),n=[],r=null,s=[],i=[];for(;e.check(w.ASSIGNMENT_WORD)||hr(e);)e.checkIterationLimit(),e.check(w.ASSIGNMENT_WORD)?n.push(Dd(e)):i.push(Jr(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=F.word([F.literal(a.value)])}for(;(!e.isStatementEnd()||e.check(w.RBRACE))&&!e.check(w.PIPE,w.PIPE_AMP);)if(e.checkIterationLimit(),hr(e))i.push(Jr(e));else if(e.check(w.ASSIGNMENT_WORD)){let a=e.advance(),l=a.value,c=l.endsWith("="),u=l.endsWith("=(");if((c||u)&&(u||e.check(w.LPAREN))){let f=u?l.slice(0,-2):l.slice(0,-1);u||e.expect(w.LPAREN);let d=Ai(e);e.expect(w.RPAREN);let h=d.map(m=>Si(e,m)),p=`${f}=(${h.join(" ")})`;s.push(e.parseWordFromString(p,!1,!1,!0))}else{let f=e.parseWordFromString(l,a.quoted,a.singleQuoted,!0);s.push(e.parseAdjacentWordParts(f.parts,a.end,Re.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=F.simpleCommand(r,s,n,i);return o.line=t,o}function Dd(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=Yr(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(w.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return F.assignment(d,null,a,f)}if(l===""&&e.check(w.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=Ai(e);e.expect(w.RPAREN);let h=i!==void 0?`${s}[${i}]`:s;return F.assignment(h,null,a,d)}}let c=l?e.parseWordFromString(l,t.quoted,t.singleQuoted,!0):null;t.end===e.current().start&&e.isProcessSubstitutionStart()&&(c=e.parseAdjacentWordParts(c?.parts??[],t.end,Re.Assignment));let u=i!==void 0?`${s}[${i}]`:s;return F.assignment(u,c,a,null)}var Id=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 Ai(e){let t=[];for(e.skipNewlines();!e.check(w.RPAREN,w.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):Id.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function ki(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 c=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${c}'`)}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 F.ifNode(n,i,o)}function xi(e,t){let n=e.expect(w.FOR);if(e.check(w.DPAREN_START))return Td(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 F.forNode(s,i,o,a)}function Td(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=re(e,o[0].trim())),o[1].trim()&&(s=re(e,o[1].trim())),o[2].trim()&&(i=re(e,o[2].trim())),e.skipNewlines(),e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines();let c;e.check(w.LBRACE)?(e.advance(),c=e.parseCompoundList(),e.expect(w.RBRACE)):(e.expect(w.DO),c=e.parseCompoundList(),e.expect(w.DONE));let u=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:s,update:i,body:c,redirections:u,line:n}}function Pi(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 F.whileNode(n,r,s)}function $i(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 F.untilNode(n,r,s)}function Ci(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=Ld(e);if(o&&r.push(o),e.skipNewlines(),e.getPos()===i&&!o)break}e.expect(w.ESAC);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.caseNode(n,r,s)}function Ld(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=";;&"),F.caseItem(t,n,r)}function Ni(e,t){e.expect(w.LPAREN);let n=e.parseCompoundList();e.expect(w.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.subshell(n,r)}function Ri(e,t){e.expect(w.LBRACE);let n=e.parseCompoundList();e.expect(w.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.group(n,r)}var Md=["-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"],Bd=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function Pl(e){return e.isWord()||e.check(w.LBRACE)||e.check(w.RBRACE)||e.check(w.ASSIGNMENT_WORD)}function $l(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 Di(e){return e.skipNewlines(),Wd(e)}function Wd(e){let t=Cl(e);for(e.skipNewlines();e.check(w.OR_OR);){e.advance(),e.skipNewlines();let n=Cl(e);t={type:"CondOr",left:t,right:n},e.skipNewlines()}return t}function Cl(e){let t=Oi(e);for(e.skipNewlines();e.check(w.AND_AND);){e.advance(),e.skipNewlines();let n=Oi(e);t={type:"CondAnd",left:t,right:n},e.skipNewlines()}return t}function Oi(e){return e.skipNewlines(),e.check(w.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:e.withDepth(()=>Oi(e))}):Vd(e)}function Vd(e){if(e.check(w.LPAREN)){e.advance();let t=e.withDepth(()=>Di(e));return e.expect(w.RPAREN),{type:"CondGroup",expression:t}}if(Pl(e)){let t=e.current(),n=t.value;if(Md.includes(n)&&!t.quoted){if(e.advance(),e.check(w.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()&&Bd.includes(e.current().value)){let s=e.advance().value,i;return s==="=~"?i=zd(e):s==="=="||s==="!="?i=$l(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=$l(e);return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function zd(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 jd(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 pr(e){return e.length>0?e:[F.literal("")]}function qd(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 Gd(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 Hd(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 u=Ei(e,t,s,"[","]");if(a+=`[${Yr(t.slice(s+1,u))}]`,s=u+1,t[s]==="["){let f=1,d=s;for(;d<t.length&&f>0;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let h=t.slice(n+2,d);return{part:F.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:d+1}}}if(a===""&&!i&&!o&&t[s]!=="}"){let u=1,f=s;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;if(u>0)throw new Pe("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 c=null;if(i){let u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Ii(e,t,s,a,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):(c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="")}else c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="";else if(t[s]==="*"||t[s]==="@"&&!/[QPaAEKkuUL]/.test(t[s+1]||"")){let f=t[s];s++,c={type:"VarNamePrefix",prefix:a,star:f==="*"},a=""}else if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Ii(e,t,s,a,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):c={type:"Indirection"}}else c={type:"Indirection"}}else if(o)if(t[s]===":")for(c={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`):c={type:"Length"};if(!c&&s<t.length&&t[s]!=="}"){let u=Ii(e,t,s,a,r);c=u.operation,s=u.endIndex}if(s<t.length&&t[s]!=="}"){let u=t[s];if(!/[:\-+=?#%/^,@[]/.test(u)){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 Pe("unexpected EOF while looking for matching '}'",0,0);return{part:F.parameterExpansion(a,c),endIndex:s+1}}function Ii(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=kn(e,t,i),y=t.slice(i,S),g=e.withDepth(()=>Jt(e,y,!1,!1,!0,!1,s,!1,!1,!0)),b=F.word(pr(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 c=kn(e,t,i),u=t.slice(i,c),f=-1,d=0,h=0;for(let E=0;E<u.length;E++){let S=u[E];if(S==="("||S==="[")d++;else if(S===")"||S==="]")d--;else if(S==="?"&&d===0)h++;else if(S===":"&&d===0)if(h>0)h--;else{f=E;break}}let p=f>=0?u.slice(0,f):u,m=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:bi(e,p),length:m!==null?bi(e,m):null},endIndex:c}}if("-=?+".includes(o)){i++;let l=kn(e,t,i),c=t.slice(i,l),u=e.withDepth(()=>Jt(e,c,!1,!1,!0,!1,s,!1,!1,!0)),f=F.word(pr(u));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:c?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,c=o==="#"?"prefix":"suffix";i+=l?2:1;let u=kn(e,t,i),f=t.slice(i,u),d=e.withDepth(()=>Jt(e,f,!1,!1,!1));return{operation:{type:"PatternRemoval",pattern:F.word(pr(d)),side:c,greedy:l},endIndex:u}}if(o==="/"){let l=a==="/";i+=l?2:1;let c=null;t[i]==="#"?(c="start",i++):t[i]==="%"&&(c="end",i++);let u;c!==null&&(t[i]==="/"||t[i]==="}")?u=i:u=bl(e,t,i);let f=t.slice(i,u),d=e.withDepth(()=>Jt(e,f,!1,!1,!1)),h=F.word(pr(d)),p=null,m=u;if(t[u]==="/"){let E=u+1,S=kn(e,t,E),y=t.slice(E,S),g=e.withDepth(()=>Jt(e,y,!1,!1,!1));p=F.word(pr(g)),m=S}return{operation:{type:"PatternReplacement",pattern:h,replacement:p,all:l,anchor:c},endIndex:m}}if(o==="^"||o===","){let l=a===o,c=o==="^"?"upper":"lower";i+=l?2:1;let u=kn(e,t,i),f=t.slice(i,u),d=f?F.word([F.literal(f)]):null;return{operation:{type:"CaseModification",direction:c,all:l,pattern:d},endIndex:u}}return o==="@"&&/[QPaAEKkuUL]/.test(a)?{operation:{type:"Transform",operator:a},endIndex:i+2}:{operation:null,endIndex:i}}function _i(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),c=re(e,l);return{part:F.arithmeticExpansion(c),endIndex:a+1}}}return i==="("?e.parseCommandSubstitution(t,n):i==="{"?Hd(e,t,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?Gd(e,t,n):{part:F.literal("$"),endIndex:s}}function Nl(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}=_i(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 Zd(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:c}=_i(e,t,s,!0);l&&r.push(l),s=c;continue}if(a==="`"){o();let{part:l,endIndex:c}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=c;continue}i+=a,s++}return o(),{part:F.doubleQuoted(r),endIndex:s}}function Jt(e,t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!0){if(r)return[F.singleQuoted(t)];if(n){let m=Nl(e,t);return[F.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=Nl(e,m);return[F.doubleQuoted(S)]}}let f=[],d=0,h="",p=()=>{h&&(f.push(F.literal(h)),h="")};for(;d<t.length;){let m=t[d];if(m==="\\"&&d+1<t.length){let E=t[d+1];if(l){p(),f.push(F.escaped(E)),d+=2;continue}if(!i&&!o){E!==`
72
- `&&(p(),f.push(F.escaped(E))),d+=2;continue}let S=i?E==="$"||E==="`"||E===`
73
- `:E==="$"||E==="`"||E==='"'||E==="'"||E===`
74
- `||c&&E==="}",y=o?"*?[]\\".includes(E):"*?[]\\(){}.^+".includes(E);S?E!==`
75
- `&&(h+=E):y?(p(),f.push(F.escaped(E))):h+=`\\${E}`,d+=2;continue}if(m==="'"&&!o&&!i){p();let E=t.indexOf("'",d+1);if(E===-1){h+=t.slice(d);break}f.push(F.singleQuoted(t.slice(d+1,E))),d=E+1;continue}if(m==='"'&&!i){p();let{part:E,endIndex:S}=Zd(e,t,d+1);f.push(E),d=S+1;continue}if(m==="$"&&t[d+1]==="'"){p();let{part:E,endIndex:S}=Al(e,t,d+2);f.push(E),d=S;continue}if(m==="$"){p();let{part:E,endIndex:S}=_i(e,t,d);E&&f.push(E),d=S;continue}if(m==="`"){p();let{part:E,endIndex:S}=e.parseBacktickSubstitution(t,d);f.push(E),d=S;continue}if((m==="<"||m===">")&&t[d+1]==="("&&!i&&!o){p();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&&u||E==="="||s&&E===":"){let y=El(e,t,d),g=t[y];if(g===void 0||g==="/"||g===":"){p();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=qd(t,d+1);if(E!==-1){p();let S=t.slice(d,E+1);f.push({type:"Glob",pattern:S}),d=E+1;continue}}if(m==="*"||m==="?"||m==="["){p();let{pattern:E,endIndex:S}=Sl(e,t,d);f.push({type:"Glob",pattern:l?jd(E):E}),d=S;continue}if(m==="{"&&!s&&!a&&!i){let E=vl(e,t,d,Jt);if(E){p(),f.push(E.part),d=E.endIndex;continue}}h+=m,d++}return p(),f}var Z=class e{tokens=[];pos=0;pendingHeredocs=[];parseBudget;ownsParseBudget;_input="";processLineState;constructor(t){this.parseBudget=t??new Qr,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>yi)throw new Pe(`Input too large: ${t.length} bytes exceeds limit of ${yi}`,1,1);this._input=t,this.processLineState=void 0;let s=new Zr(t,n);if(this.tokens=s.tokenize(),this.tokens.length>ur)throw new Pe(`Too many tokens: ${this.tokens.length} exceeds limit of ${ur}`,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 Pe(n||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let n=this.current();throw new Pe(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=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(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||hr(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 F.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(),F.statement([F.pipeline([F.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 c=this.parsePipeline();n.push(c)}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 F.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 c=this.parseCommand();i.push(c)}return F.pipeline(i,s,t,n,o.length>0?o:void 0)}parseCommand(){if(this.currentTokenJoinsProcessSubstitution())return vi(this);let t=this.current();switch(t.type){case w.IF:return ki(this);case w.FOR:return xi(this);case w.WHILE:return Pi(this);case w.UNTIL:return $i(this);case w.CASE:return Ci(this);case w.LPAREN:return Ni(this);case w.LBRACE:return Ri(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:mi(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():vi(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=F.subshell(t,[]);return F.subshell([F.statement([F.pipeline([r],!1,!1,!1)])],n)}isWord(){return this.isWordToken(Re.Default)||this.isProcessSubstitutionStart()||this.currentTokenJoinsProcessSubstitution()}isWordToken(t){let n=this.current().type;return n===w.WORD||n===w.NAME||n===w.NUMBER||mi(n)||n===w.BANG||n===w.ASSIGNMENT_WORD&&(t&Re.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(Re.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=Re.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=Re.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(Re.NoBraceExpansion)}parseWordForRegex(){return this.parseWord(Re.NoBraceExpansion|Re.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?F.word([F.literal(t.type===w.FD_VARIABLE?`{${t.value}}`:t.value)]):this.parseWordFromString(t.value,t.quoted,t.singleQuoted,(n&Re.Assignment)!==0,!1,(n&Re.NoBraceExpansion)!==0,(n&Re.Regex)!==0,r)}parseWordFromString(t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!0){let c=Jt(this,t,n,r,s,i,!1,o,a,!1,l);return F.word(c)}parseCommandSubstitution(t,n){return Qa(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitutionFromString(t,n){return Ka(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=F.script(this.parseCompoundList())}finally{this.processLineState=n}return this.check(w.EOF)&&this.error("unexpected EOF while looking for matching `)'"),this.expect(w.RPAREN),F.processSubstitution(s,t.type===w.LESS?"input":"output")}parseBacktickSubstitution(t,n,r=!1){return Xa(t,n,r,()=>new e(this.parseBudget),s=>this.error(s))}isDollarDparenSubshell(t,n){return Ha(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(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 c=this.current().value,u=n.length>0?n[n.length-1]:"";n.length>0&&!n.endsWith(" ")&&!(c==="="&&/[|&^+\-*/%<>]$/.test(n))&&!(c==="<"&&u==="<")&&!(c===">"&&u===">")&&(n+=" "),n+=c,this.advance()}}o||this.expect(w.DPAREN_END);let a=this.parseArithmeticExpression(n.trim()),l=this.parseOptionalRedirections();return F.arithmeticCommand(a,l,this.getSourceLine(t))}parseConditionalCommand(){let t=this.expect(w.DBRACK_START),n=Di(this);this.expect(w.DBRACK_END);let r=this.parseOptionalRedirections();return F.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 Pe("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 F.functionDef(t,n,r)}parseCompoundCommandBody(t){let n=t?.forFunctionBody;if(this.check(w.LBRACE))return Ri(this,{skipRedirections:n});if(this.check(w.LPAREN))return Ni(this,{skipRedirections:n});if(this.check(w.IF))return ki(this,{skipRedirections:n});if(this.check(w.FOR))return xi(this,{skipRedirections:n});if(this.check(w.WHILE))return Pi(this,{skipRedirections:n});if(this.check(w.UNTIL))return $i(this,{skipRedirections:n});if(this.check(w.CASE))return Ci(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(;hr(this);){this.checkIterationLimit();let n=this.pos;if(t.push(Jr(this)),this.pos===n)break}return t}parseArithmeticExpression(t){return re(this,t)}};function He(e,t){return new Z().parse(e,t)}function mr(e){return Pn(e)}function Pn(e){return e.statements.map(Rl).join(`
76
- `)}function Rl(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(Kd(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let n=t.join(" ");return e.background&&(n+=" &"),n}function Kd(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(Ol(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 Ol(e){switch(e.type){case"SimpleCommand":return Xd(e);case"If":return oh(e);case"For":return ah(e);case"CStyleFor":return lh(e);case"While":return ch(e);case"Until":return uh(e);case"Case":return fh(e);case"Subshell":return hh(e);case"Group":return ph(e);case"ArithmeticCommand":return mh(e);case"ConditionalCommand":return yh(e);case"FunctionDef":return gh(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function Xd(e){let t=[];for(let n of e.assignments)t.push(Yd(n));e.name&&t.push(we(e.name));for(let n of e.args)t.push(we(n));for(let n of e.redirections)t.push(_l(n));return t.join(" ")}function Yd(e){let t=e.append?"+=":"=";if(e.array){let n=e.array.map(we).join(" ");return`${e.name}${t}(${n})`}return e.value?`${e.name}${t}${we(e.value)}`:`${e.name}${t}`}function we(e){return e.parts.map(t=>es(t,!1)).join("")}function en(e){return e.parts.map(t=>es(t,!0)).join("")}function es(e,t){switch(e.type){case"Literal":return t?eh(e.value):Jd(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(n=>es(n,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Dl(e);case"CommandSubstitution":return e.legacy?`\`${Pn(e.body)}\``:`$(${Pn(e.body)})`;case"ArithmeticExpansion":return`$((${he(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${Pn(e.body)})`:`>(${Pn(e.body)})`;case"BraceExpansion":return sh(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 Jd(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function eh(e){return e.replace(/[$`"\\]/g,"\\$&")}function th(e,t){return e.parts.map(n=>nh(n,t)).join("")}function nh(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Dl(e);case"CommandSubstitution":return e.legacy?`\`${Pn(e.body)}\``:`$(${Pn(e.body)})`;case"ArithmeticExpansion":return`$((${he(e.expression.expression)}))`;default:return es(e,!1)}}function Dl(e){return e.operation?`\${${Il(e.parameter,e.operation)}}`:rh(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function rh(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function Il(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${en(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${en(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?en(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${en(t.word)}`;case"Substring":{let n=he(t.offset.expression);return t.length?`${e}:${n}:${he(t.length.expression)}`:`${e}:${n}`}case"PatternRemoval":{let n=t.side==="prefix"?"#":"%",r=t.greedy?`${n}${n}`:n;return`${e}${r}${en(t.pattern)}`}case"PatternReplacement":{let n="/";t.all?n="//":t.anchor==="start"?n="/#":t.anchor==="end"&&(n="/%");let r=t.replacement?`/${en(t.replacement)}`:"";return`${e}${n}${en(t.pattern)}${r}`}case"CaseModification":{let n=t.direction==="upper"?"^":",",r=t.all?`${n}${n}`:n,s=t.pattern?en(t.pattern):"";return`${e}${r}${s}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${Il(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 sh(e){return`{${e.items.map(ih).join(",")}}`}function ih(e){if(e.type==="Word")return we(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 _l(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=th(n.content,n.quoted);return`${t}${e.operator}${r}
77
- ${s}${n.delimiter}`}return e.operator==="<<<"?`${t}<<< ${we(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${we(e.target)}`:`${t}${e.operator} ${we(e.target)}`}function wt(e){return e.length===0?"":` ${e.map(_l).join(" ")}`}function lt(e){return e.map(Rl).join(`
78
- `)}function oh(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} ${lt(r.condition)}; then
79
- ${lt(r.body)}`)}return e.elseBody&&t.push(`else
80
- ${lt(e.elseBody)}`),`${t.join(`
67
+ `);)f=!0,u++;if(f&&u<r&&n[u]===")")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 wi=1e6,fr=1e5,Nd=1e6,il=200,Re;(function(e){e[e.Default=0]="Default",e[e.Assignment=1]="Assignment",e[e.NoBraceExpansion=2]="NoBraceExpansion",e[e.Regex=4]="Regex"})(Re||(Re={}));var ol=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]),al=new Set([g.LESS,g.GREAT,g.DLESS,g.DGREAT,g.LESSAND,g.GREATAND,g.LESSGREAT,g.DLESSDASH,g.CLOBBER,g.TLESS]),ll=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]),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"}},Jr=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>Nd)throw new xe("Maximum parse iterations exceeded (possible infinite loop)",t,n)}chargeTokens(t,n=1,r=1){if(this.tokens+=t,this.tokens>fr)throw new xe(`Too many tokens: cumulative count exceeds limit of ${fr}`,n,r)}enter(t,n){if(this.depth++,this.depth>il)throw this.depth--,new xe(`Maximum parser nesting depth exceeded (${il})`,t,n);let r=!0;return()=>{r&&(r=!1,this.depth--)}}};function ye(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
68
+ `){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var es=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function dr(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 cl(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 ul(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+=`
69
+ `;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 fl(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 Rd(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 re(e,t){let n=Rd(t),{expr:r,pos:s}=Vn(e,n,0),i=ye(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 Ge(e,t){return ye(e,t)>=e.length}function Vn(e,t,n){return Od(e,t,n)}function vn(e,t,n){return e.withDepth(()=>Vn(e,t,n))}function Od(e,t,n){let{expr:r,pos:s}=hr(e,t,n);for(s=ye(t,s);t[s]===",";){if(s++,Ge(t,s))return qe(",",s);let{expr:o,pos:a}=hr(e,t,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=ye(t,a)}return{expr:r,pos:s}}function hr(e,t,n){let{expr:r,pos:s}=Dd(e,t,n);if(s=ye(t,s),t[s]==="?"){s++;let{expr:i,pos:o}=vn(e,t,s);if(s=ye(t,o),t[s]===":"){s++;let{expr:a,pos:l}=vn(e,t,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:a},pos:l}}}return{expr:r,pos:s}}function Dd(e,t,n){let{expr:r,pos:s}=dl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="||";){if(s+=2,Ge(t,s))return qe("||",s);let{expr:o,pos:a}=dl(e,t,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=a}return{expr:r,pos:s}}function dl(e,t,n){let{expr:r,pos:s}=hl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="&&";){if(s+=2,Ge(t,s))return qe("&&",s);let{expr:o,pos:a}=hl(e,t,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=a}return{expr:r,pos:s}}function hl(e,t,n){let{expr:r,pos:s}=pl(e,t,n);for(;s=ye(t,s),t[s]==="|"&&t[s+1]!=="|";){if(s++,Ge(t,s))return qe("|",s);let{expr:o,pos:a}=pl(e,t,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=a}return{expr:r,pos:s}}function pl(e,t,n){let{expr:r,pos:s}=ml(e,t,n);for(;s=ye(t,s),t[s]==="^";){if(s++,Ge(t,s))return qe("^",s);let{expr:o,pos:a}=ml(e,t,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=a}return{expr:r,pos:s}}function ml(e,t,n){let{expr:r,pos:s}=yl(e,t,n);for(;s=ye(t,s),t[s]==="&"&&t[s+1]!=="&";){if(s++,Ge(t,s))return qe("&",s);let{expr:o,pos:a}=yl(e,t,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=a}return{expr:r,pos:s}}function yl(e,t,n){let{expr:r,pos:s}=gl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="=="||t.slice(s,s+2)==="!=";){let i=t.slice(s,s+2);if(s+=2,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=gl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function gl(e,t,n){let{expr:r,pos:s}=Ei(e,t,n);for(;;)if(s=ye(t,s),t.slice(s,s+2)==="<="||t.slice(s,s+2)===">="){let i=t.slice(s,s+2);if(s+=2,Ge(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++,Ge(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}=wl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="<<"||t.slice(s,s+2)===">>";){let i=t.slice(s,s+2);if(s+=2,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=wl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function wl(e,t,n){let{expr:r,pos:s}=El(e,t,n);for(;s=ye(t,s),(t[s]==="+"||t[s]==="-")&&t[s+1]!==t[s];){let i=t[s];if(s++,Ge(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}=ts(e,t,n);for(;;)if(s=ye(t,s),t[s]==="*"&&t[s+1]!=="*"){if(s++,Ge(t,s))return qe("*",s);let{expr:o,pos:a}=ts(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++,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=ts(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function ts(e,t,n){let{expr:r,pos:s}=bi(e,t,n),i=ye(t,s);if(t.slice(i,i+2)==="**"){if(i+=2,Ge(t,i))return qe("**",i);let{expr:a,pos:l}=e.withDepth(()=>ts(e,t,i));return{expr:{type:"ArithBinary",operator:"**",left:r,right:a},pos:l}}return{expr:r,pos:s}}function bi(e,t,n){let r=ye(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(()=>bi(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(()=>bi(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}return _d(e,t,r)}function Id(e,t){let n=e[t];return n==="$"||n==="`"}function _d(e,t,n){let{expr:r,pos:s}=bl(e,t,n,!1),i=[r];for(;Id(t,s);){let{expr:a,pos:l}=bl(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}=vn(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=ye(t,s),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let a of es)if(t.slice(s,s+a.length)===a&&t.slice(s,s+a.length+1)!=="=="){s+=a.length;let{expr:l,pos:c}=e.withDepth(()=>hr(e,t,s));return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r.nameExpr,subscript:r.subscript,value:l},pos:c}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r,value:l},pos:c}:{expr:{type:"ArithAssignment",operator:a,variable:r.name,value:l},pos:c}}}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 bl(e,t,n,r=!1){let s=ye(t,n),i=cl(vn,e,t,s);if(i)return i;let o=ul(t,s);if(o)return o;let a=fl(t,s);if(a)return a;if(t.slice(s,s+2)==="$("&&t[s+2]!=="("){s+=2;let c=1,u=s;for(;s<t.length&&c>0;)t[s]==="("?c++:t[s]===")"&&c--,c>0&&s++;let f=t.slice(u,s);return s++,{expr:{type:"ArithCommandSubst",command:f},pos:s}}if(t[s]==="`"){s++;let c=s;for(;s<t.length&&t[s]!=="`";)s++;let u=t.slice(c,s);return t[s]==="`"&&s++,{expr:{type:"ArithCommandSubst",command:u},pos:s}}if(t[s]==="("){s++;let{expr:c,pos:u}=vn(e,t,s);return s=ye(t,u),t[s]===")"&&s++,{expr:{type:"ArithGroup",expression:c},pos:s}}if(t[s]==="'"){s++;let c="";for(;s<t.length&&t[s]!=="'";)c+=t[s],s++;t[s]==="'"&&s++;let u=Number.parseInt(c,10);return{expr:{type:"ArithSingleQuote",content:c,value:Number.isNaN(u)?0:u},pos:s}}if(t[s]==='"'){s++;let c="";for(;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?(c+=t[s+1],s+=2):(c+=t[s],s++);t[s]==='"'&&s++;let u=c.trim();if(!u)return{expr:{type:"ArithNumber",value:0},pos:s};let{expr:f}=vn(e,u,0);return{expr:f,pos:s}}if(/[0-9]/.test(t[s])){let c="",u=!1,f=!1;for(;s<t.length;){let h=t[s];if(u)if(/[0-9a-zA-Z@_]/.test(h))c+=h,s++;else break;else if(h==="#")u=!0,c+=h,s++;else if(c==="0"&&(h==="x"||h==="X")&&s+1<t.length&&/[0-9a-fA-F]/.test(t[s+1]))f=!0,c+=h,s++;else if(f&&/[0-9a-fA-F]/.test(h))c+=h,s++;else if(!f&&/[0-9]/.test(h))c+=h,s++;else break}if(s<t.length&&/[a-zA-Z_]/.test(t[s])){let h=c;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)h+=t[s],s++;return{expr:{type:"ArithSyntaxError",errorToken:h,message:`${h}: value too great for base (error token is "${h}")`},pos:s}}if(t[s]==="."&&/[0-9]/.test(t[s+1]))throw new le(`${c}.${t[s+1]}...: syntax error: invalid arithmetic operator`);if(t[s]==="["){let h=t.slice(s).trim();return{expr:{type:"ArithNumberSubscript",number:c,errorToken:h},pos:t.length}}return{expr:{type:"ArithNumber",value:dr(c)},pos:s}}if(t[s]==="$"&&t[s+1]==="{"){let c=s+2,u=1,f=c;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;let d=t.slice(c,f),h=f+1;if(t[h]==="#"){let p=h+1;for(;p<t.length&&/[0-9a-zA-Z@_]/.test(t[p]);)p++;let m=t.slice(h+1,p);return{expr:{type:"ArithDynamicBase",baseExpr:d,value:m},pos:p}}if(/[0-9]/.test(t[h])||t[h]==="x"||t[h]==="X"){let p=h;if(t[h]==="x"||t[h]==="X")for(p++;p<t.length&&/[0-9a-fA-F]/.test(t[p]);)p++;else for(;p<t.length&&/[0-9]/.test(t[p]);)p++;let m=t.slice(h,p);return{expr:{type:"ArithDynamicNumber",prefix:d,suffix:m},pos:p}}return s=h,{expr:{type:"ArithBracedExpansion",content:d},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[0-9]/.test(t[s+1])){s++;let c="";for(;s<t.length&&/[0-9]/.test(t[s]);)c+=t[s],s++;return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:!0},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[*@#?\-!$]/.test(t[s+1])){let c=t[s+1];return s+=2,{expr:{type:"ArithSpecialVar",name:c},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 c="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)c+=t[s],s++;if(t[s]==="["&&!r){s++;let u;if(t[s]==="'"||t[s]==='"'){let d=t[s];for(s++,u="";s<t.length&&t[s]!==d;)u+=t[s],s++;t[s]===d&&s++,s=ye(t,s),t[s]==="]"&&s++}let f;if(u===void 0){let{expr:d,pos:h}=vn(e,t,s);f=d,s=h,t[s]==="]"&&s++}if(s=ye(t,s),t[s]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:c,index:f},pos:s};if(!r){for(let d of es)if(t.slice(s,s+d.length)===d&&t.slice(s,s+d.length+1)!=="=="){s+=d.length;let{expr:h,pos:p}=e.withDepth(()=>hr(e,t,s));return{expr:{type:"ArithAssignment",operator:d,variable:c,subscript:f,stringKey:u,value:h},pos:p}}}return{expr:{type:"ArithArrayElement",array:c,index:f,stringKey:u},pos:s}}if(s=ye(t,s),!r){for(let u of es)if(t.slice(s,s+u.length)===u&&t.slice(s,s+u.length+1)!=="=="){s+=u.length;let{expr:f,pos:d}=e.withDepth(()=>hr(e,t,s));return{expr:{type:"ArithAssignment",operator:u,variable:c,value:f},pos:d}}}return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:l},pos:s}}if(t[s]==="#"){let c=s+1;for(;c<t.length&&t[c]!==`
70
+ `;)c++;let u=t.slice(s,c).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:u,message:`${u}: syntax error: invalid arithmetic operator (error token is "${u}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:s}}var ns=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 Td(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 vl(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 kn(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 kl(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 xl(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 Pl(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+=`
71
+ `,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 c=t.slice(l+2,l+4),u=parseInt(c,16);if(!Number.isNaN(u)&&c.length>0)a.push(u),l+=2+c.length;else break}a.length>0?(r+=Td(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 c=parseInt(a,8);r+=String.fromCharCode(c),s=l;break}default:r+=i,s++}else r+=i,s++}return s<t.length&&t[s]==="'"&&s++,{part:M.literal(r),endIndex:s}}function Ai(e,t){let n=t.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:re(e,n)}function Al(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 $l(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:Al(i).map(u=>e.withDepth(()=>({type:"Word",word:M.word(r(e,u,!1,!1,!1))})))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:Al(i).map(u=>({type:"Word",word:M.word([M.literal(u)])}))},endIndex:s+1}:null}function vi(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(vi(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 Cl(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 pr(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:al.has(r.type)}if(n===g.FD_VARIABLE){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:ll.has(r.type)}return!e.isProcessSubstitutionStart()&&ol.has(n)}function rs(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=Cl(e,r.type);if(r.type===g.DLESS||r.type===g.DLESSDASH)return Fd(e,t,n,r.type===g.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return M.redirection(s,i,t,n)}function Fd(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=M.redirection(r?"<<-":"<<",M.hereDoc(i,M.word([]),r,o),t,n);return e.addPendingHeredoc(a,i,r,o),a}function xi(e){let t=e.getSourceLine(),n=[],r=null,s=[],i=[];for(;e.check(g.ASSIGNMENT_WORD)||pr(e);)e.checkIterationLimit(),e.check(g.ASSIGNMENT_WORD)?n.push(Md(e)):i.push(rs(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=M.word([M.literal(a.value)])}for(;(!e.isStatementEnd()||e.check(g.RBRACE))&&!e.check(g.PIPE,g.PIPE_AMP);)if(e.checkIterationLimit(),pr(e))i.push(rs(e));else if(e.check(g.ASSIGNMENT_WORD)){let a=e.advance(),l=a.value,c=l.endsWith("="),u=l.endsWith("=(");if((c||u)&&(u||e.check(g.LPAREN))){let f=u?l.slice(0,-2):l.slice(0,-1);u||e.expect(g.LPAREN);let d=ki(e);e.expect(g.RPAREN);let h=d.map(m=>vi(e,m)),p=`${f}=(${h.join(" ")})`;s.push(e.parseWordFromString(p,!1,!1,!0))}else{let f=e.parseWordFromString(l,a.quoted,a.singleQuoted,!0);s.push(e.parseAdjacentWordParts(f.parts,a.end,Re.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=M.simpleCommand(r,s,n,i);return o.line=t,o}function Md(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=ns(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=ki(e);e.expect(g.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return M.assignment(d,null,a,f)}if(l===""&&e.check(g.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=ki(e);e.expect(g.RPAREN);let h=i!==void 0?`${s}[${i}]`:s;return M.assignment(h,null,a,d)}}let c=l?e.parseWordFromString(l,t.quoted,t.singleQuoted,!0):null;t.end===e.current().start&&e.isProcessSubstitutionStart()&&(c=e.parseAdjacentWordParts(c?.parts??[],t.end,Re.Assignment));let u=i!==void 0?`${s}[${i}]`:s;return M.assignment(u,c,a,null)}var Bd=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 ki(e){let t=[];for(e.skipNewlines();!e.check(g.RPAREN,g.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):Bd.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function Pi(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 c=e.check(g.FI)?"fi":e.check(g.ELSE)?"else":e.check(g.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${c}'`)}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 M.ifNode(n,i,o)}function $i(e,t){let n=e.expect(g.FOR);if(e.check(g.DPAREN_START))return Vd(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 M.forNode(s,i,o,a)}function Vd(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=re(e,o[0].trim())),o[1].trim()&&(s=re(e,o[1].trim())),o[2].trim()&&(i=re(e,o[2].trim())),e.skipNewlines(),e.check(g.SEMICOLON)&&e.advance(),e.skipNewlines();let c;e.check(g.LBRACE)?(e.advance(),c=e.parseCompoundList(),e.expect(g.RBRACE)):(e.expect(g.DO),c=e.parseCompoundList(),e.expect(g.DONE));let u=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:s,update:i,body:c,redirections:u,line:n}}function Ci(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 M.whileNode(n,r,s)}function Ni(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 M.untilNode(n,r,s)}function Ri(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=zd(e);if(o&&r.push(o),e.skipNewlines(),e.getPos()===i&&!o)break}e.expect(g.ESAC);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return M.caseNode(n,r,s)}function zd(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=";;&"),M.caseItem(t,n,r)}function Oi(e,t){e.expect(g.LPAREN);let n=e.parseCompoundList();e.expect(g.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return M.subshell(n,r)}function Di(e,t){e.expect(g.LBRACE);let n=e.parseCompoundList();e.expect(g.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return M.group(n,r)}var jd=["-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"],qd=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function Rl(e){return e.isWord()||e.check(g.LBRACE)||e.check(g.RBRACE)||e.check(g.ASSIGNMENT_WORD)}function Ol(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 _i(e){return e.skipNewlines(),Gd(e)}function Gd(e){let t=Dl(e);for(e.skipNewlines();e.check(g.OR_OR);){e.advance(),e.skipNewlines();let n=Dl(e);t={type:"CondOr",left:t,right:n},e.skipNewlines()}return t}function Dl(e){let t=Ii(e);for(e.skipNewlines();e.check(g.AND_AND);){e.advance(),e.skipNewlines();let n=Ii(e);t={type:"CondAnd",left:t,right:n},e.skipNewlines()}return t}function Ii(e){return e.skipNewlines(),e.check(g.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:e.withDepth(()=>Ii(e))}):Hd(e)}function Hd(e){if(e.check(g.LPAREN)){e.advance();let t=e.withDepth(()=>_i(e));return e.expect(g.RPAREN),{type:"CondGroup",expression:t}}if(Rl(e)){let t=e.current(),n=t.value;if(jd.includes(n)&&!t.quoted){if(e.advance(),e.check(g.DBRACK_END)&&e.error(`Expected operand after ${n}`),Rl(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()&&qd.includes(e.current().value)){let s=e.advance().value,i;return s==="=~"?i=Zd(e):s==="=="||s==="!="?i=Ol(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=Ol(e);return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function Zd(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 Kd(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 mr(e){return e.length>0?e:[M.literal("")]}function Xd(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 Yd(e,t,n){let r=n+1,s=t[r];if("@*#?$!-0123456789".includes(s))return{part:M.parameterExpansion(s),endIndex:r+1};let i="";for(;r<t.length&&/[a-zA-Z0-9_]/.test(t[r]);)i+=t[r],r++;return{part:M.parameterExpansion(i),endIndex:r}}function Jd(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 u=Si(e,t,s,"[","]");if(a+=`[${ns(t.slice(s+1,u))}]`,s=u+1,t[s]==="["){let f=1,d=s;for(;d<t.length&&f>0;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let h=t.slice(n+2,d);return{part:M.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:d+1}}}if(a===""&&!i&&!o&&t[s]!=="}"){let u=1,f=s;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;if(u>0)throw new xe("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(n+2,f);return{part:M.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let c=null;if(i){let u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Ti(e,t,s,a,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):(c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="")}else c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="";else if(t[s]==="*"||t[s]==="@"&&!/[QPaAEKkuUL]/.test(t[s+1]||"")){let f=t[s];s++,c={type:"VarNamePrefix",prefix:a,star:f==="*"},a=""}else if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Ti(e,t,s,a,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):c={type:"Indirection"}}else c={type:"Indirection"}}else if(o)if(t[s]===":")for(c={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`):c={type:"Length"};if(!c&&s<t.length&&t[s]!=="}"){let u=Ti(e,t,s,a,r);c=u.operation,s=u.endIndex}if(s<t.length&&t[s]!=="}"){let u=t[s];if(!/[:\-+=?#%/^,@[]/.test(u)){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:M.parameterExpansion(a,c),endIndex:s+1}}function Ti(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=kn(e,t,i),w=t.slice(i,b),E=e.withDepth(()=>Jt(e,w,!1,!1,!0,!1,s,!1,!1,!0)),S=M.word(mr(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 c=kn(e,t,i),u=t.slice(i,c),f=-1,d=0,h=0;for(let y=0;y<u.length;y++){let b=u[y];if(b==="("||b==="[")d++;else if(b===")"||b==="]")d--;else if(b==="?"&&d===0)h++;else if(b===":"&&d===0)if(h>0)h--;else{f=y;break}}let p=f>=0?u.slice(0,f):u,m=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:Ai(e,p),length:m!==null?Ai(e,m):null},endIndex:c}}if("-=?+".includes(o)){i++;let l=kn(e,t,i),c=t.slice(i,l),u=e.withDepth(()=>Jt(e,c,!1,!1,!0,!1,s,!1,!1,!0)),f=M.word(mr(u));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:c?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,c=o==="#"?"prefix":"suffix";i+=l?2:1;let u=kn(e,t,i),f=t.slice(i,u),d=e.withDepth(()=>Jt(e,f,!1,!1,!1));return{operation:{type:"PatternRemoval",pattern:M.word(mr(d)),side:c,greedy:l},endIndex:u}}if(o==="/"){let l=a==="/";i+=l?2:1;let c=null;t[i]==="#"?(c="start",i++):t[i]==="%"&&(c="end",i++);let u;c!==null&&(t[i]==="/"||t[i]==="}")?u=i:u=kl(e,t,i);let f=t.slice(i,u),d=e.withDepth(()=>Jt(e,f,!1,!1,!1)),h=M.word(mr(d)),p=null,m=u;if(t[u]==="/"){let y=u+1,b=kn(e,t,y),w=t.slice(y,b),E=e.withDepth(()=>Jt(e,w,!1,!1,!1));p=M.word(mr(E)),m=b}return{operation:{type:"PatternReplacement",pattern:h,replacement:p,all:l,anchor:c},endIndex:m}}if(o==="^"||o===","){let l=a===o,c=o==="^"?"upper":"lower";i+=l?2:1;let u=kn(e,t,i),f=t.slice(i,u),d=f?M.word([M.literal(f)]):null;return{operation:{type:"CaseModification",direction:c,all:l,pattern:d},endIndex:u}}return o==="@"&&/[QPaAEKkuUL]/.test(a)?{operation:{type:"Transform",operator:a},endIndex:i+2}:{operation:null,endIndex:i}}function Li(e,t,n,r=!1){let s=n+1;if(s>=t.length)return{part:M.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),c=re(e,l);return{part:M.arithmeticExpansion(c),endIndex:a+1}}}return i==="("?e.parseCommandSubstitution(t,n):i==="{"?Jd(e,t,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?Yd(e,t,n):{part:M.literal("$"),endIndex:s}}function Il(e,t){let n=[],r=0,s="",i=()=>{s&&(n.push(M.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}=Li(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 eh(e,t,n){let r=[],s=n,i="",o=()=>{i&&(r.push(M.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:c}=Li(e,t,s,!0);l&&r.push(l),s=c;continue}if(a==="`"){o();let{part:l,endIndex:c}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=c;continue}i+=a,s++}return o(),{part:M.doubleQuoted(r),endIndex:s}}function Jt(e,t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!0){if(r)return[M.singleQuoted(t)];if(n){let m=Il(e,t);return[M.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=Il(e,m);return[M.doubleQuoted(b)]}}let f=[],d=0,h="",p=()=>{h&&(f.push(M.literal(h)),h="")};for(;d<t.length;){let m=t[d];if(m==="\\"&&d+1<t.length){let y=t[d+1];if(l){p(),f.push(M.escaped(y)),d+=2;continue}if(!i&&!o){y!==`
72
+ `&&(p(),f.push(M.escaped(y))),d+=2;continue}let b=i?y==="$"||y==="`"||y===`
73
+ `:y==="$"||y==="`"||y==='"'||y==="'"||y===`
74
+ `||c&&y==="}",w=o?"*?[]\\".includes(y):"*?[]\\(){}.^+".includes(y);b?y!==`
75
+ `&&(h+=y):w?(p(),f.push(M.escaped(y))):h+=`\\${y}`,d+=2;continue}if(m==="'"&&!o&&!i){p();let y=t.indexOf("'",d+1);if(y===-1){h+=t.slice(d);break}f.push(M.singleQuoted(t.slice(d+1,y))),d=y+1;continue}if(m==='"'&&!i){p();let{part:y,endIndex:b}=eh(e,t,d+1);f.push(y),d=b+1;continue}if(m==="$"&&t[d+1]==="'"){p();let{part:y,endIndex:b}=Pl(e,t,d+2);f.push(y),d=b;continue}if(m==="$"){p();let{part:y,endIndex:b}=Li(e,t,d);y&&f.push(y),d=b;continue}if(m==="`"){p();let{part:y,endIndex:b}=e.parseBacktickSubstitution(t,d);f.push(y),d=b;continue}if((m==="<"||m===">")&&t[d+1]==="("&&!i&&!o){p();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&&u||y==="="||s&&y===":"){let w=vl(e,t,d),E=t[w];if(E===void 0||E==="/"||E===":"){p();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=Xd(t,d+1);if(y!==-1){p();let b=t.slice(d,y+1);f.push({type:"Glob",pattern:b}),d=y+1;continue}}if(m==="*"||m==="?"||m==="["){p();let{pattern:y,endIndex:b}=xl(e,t,d);f.push({type:"Glob",pattern:l?Kd(y):y}),d=b;continue}if(m==="{"&&!s&&!a&&!i){let y=$l(e,t,d,Jt);if(y){p(),f.push(y.part),d=y.endIndex;continue}}h+=m,d++}return p(),f}var Q=class e{tokens=[];pos=0;pendingHeredocs=[];parseBudget;ownsParseBudget;_input="";processLineState;constructor(t){this.parseBudget=t??new Jr,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>wi)throw new xe(`Input too large: ${t.length} bytes exceeds limit of ${wi}`,1,1);this._input=t,this.processLineState=void 0;let s=new Yr(t,n);if(this.tokens=s.tokenize(),this.tokens.length>fr)throw new xe(`Too many tokens: ${this.tokens.length} exceeds limit of ${fr}`,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(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=M.word([M.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),t.redirect.target=M.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||pr(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 M.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(),M.statement([M.pipeline([M.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 c=this.parsePipeline();n.push(c)}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 M.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 c=this.parseCommand();i.push(c)}return M.pipeline(i,s,t,n,o.length>0?o:void 0)}parseCommand(){if(this.currentTokenJoinsProcessSubstitution())return xi(this);let t=this.current();switch(t.type){case g.IF:return Pi(this);case g.FOR:return $i(this);case g.WHILE:return Ci(this);case g.UNTIL:return Ni(this);case g.CASE:return Ri(this);case g.LPAREN:return Oi(this);case g.LBRACE:return Di(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:gi(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():xi(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=M.subshell(t,[]);return M.subshell([M.statement([M.pipeline([r],!1,!1,!1)])],n)}isWord(){return this.isWordToken(Re.Default)||this.isProcessSubstitutionStart()||this.currentTokenJoinsProcessSubstitution()}isWordToken(t){let n=this.current().type;return n===g.WORD||n===g.NAME||n===g.NUMBER||gi(n)||n===g.BANG||n===g.ASSIGNMENT_WORD&&(t&Re.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(Re.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=Re.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=Re.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 M.word(t)}parseWordNoBraceExpansion(){return this.parseWord(Re.NoBraceExpansion)}parseWordForRegex(){return this.parseWord(Re.NoBraceExpansion|Re.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?M.word([M.literal(t.type===g.FD_VARIABLE?`{${t.value}}`:t.value)]):this.parseWordFromString(t.value,t.quoted,t.singleQuoted,(n&Re.Assignment)!==0,!1,(n&Re.NoBraceExpansion)!==0,(n&Re.Regex)!==0,r)}parseWordFromString(t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!0){let c=Jt(this,t,n,r,s,i,!1,o,a,!1,l);return M.word(c)}parseCommandSubstitution(t,n){return Ja(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitutionFromString(t,n){return el(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=M.script(this.parseCompoundList())}finally{this.processLineState=n}return this.check(g.EOF)&&this.error("unexpected EOF while looking for matching `)'"),this.expect(g.RPAREN),M.processSubstitution(s,t.type===g.LESS?"input":"output")}parseBacktickSubstitution(t,n,r=!1){return tl(t,n,r,()=>new e(this.parseBudget),s=>this.error(s))}isDollarDparenSubshell(t,n){return Xa(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:M.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 c=this.current().value,u=n.length>0?n[n.length-1]:"";n.length>0&&!n.endsWith(" ")&&!(c==="="&&/[|&^+\-*/%<>]$/.test(n))&&!(c==="<"&&u==="<")&&!(c===">"&&u===">")&&(n+=" "),n+=c,this.advance()}}o||this.expect(g.DPAREN_END);let a=this.parseArithmeticExpression(n.trim()),l=this.parseOptionalRedirections();return M.arithmeticCommand(a,l,this.getSourceLine(t))}parseConditionalCommand(){let t=this.expect(g.DBRACK_START),n=_i(this);this.expect(g.DBRACK_END);let r=this.parseOptionalRedirections();return M.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 xe("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 M.functionDef(t,n,r)}parseCompoundCommandBody(t){let n=t?.forFunctionBody;if(this.check(g.LBRACE))return Di(this,{skipRedirections:n});if(this.check(g.LPAREN))return Oi(this,{skipRedirections:n});if(this.check(g.IF))return Pi(this,{skipRedirections:n});if(this.check(g.FOR))return $i(this,{skipRedirections:n});if(this.check(g.WHILE))return Ci(this,{skipRedirections:n});if(this.check(g.UNTIL))return Ni(this,{skipRedirections:n});if(this.check(g.CASE))return Ri(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(;pr(this);){this.checkIterationLimit();let n=this.pos;if(t.push(rs(this)),this.pos===n)break}return t}parseArithmeticExpression(t){return re(this,t)}};function He(e,t){return new Q().parse(e,t)}function yr(e){return Pn(e)}function Pn(e){return e.statements.map(_l).join(`
76
+ `)}function _l(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(nh(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let n=t.join(" ");return e.background&&(n+=" &"),n}function nh(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(Tl(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 Tl(e){switch(e.type){case"SimpleCommand":return rh(e);case"If":return dh(e);case"For":return hh(e);case"CStyleFor":return ph(e);case"While":return mh(e);case"Until":return yh(e);case"Case":return gh(e);case"Subshell":return Eh(e);case"Group":return bh(e);case"ArithmeticCommand":return Sh(e);case"ConditionalCommand":return Ah(e);case"FunctionDef":return vh(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function rh(e){let t=[];for(let n of e.assignments)t.push(sh(n));e.name&&t.push(we(e.name));for(let n of e.args)t.push(we(n));for(let n of e.redirections)t.push(Ml(n));return t.join(" ")}function sh(e){let t=e.append?"+=":"=";if(e.array){let n=e.array.map(we).join(" ");return`${e.name}${t}(${n})`}return e.value?`${e.name}${t}${we(e.value)}`:`${e.name}${t}`}function we(e){return e.parts.map(t=>ss(t,!1)).join("")}function en(e){return e.parts.map(t=>ss(t,!0)).join("")}function ss(e,t){switch(e.type){case"Literal":return t?oh(e.value):ih(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(n=>ss(n,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Ll(e);case"CommandSubstitution":return e.legacy?`\`${Pn(e.body)}\``:`$(${Pn(e.body)})`;case"ArithmeticExpansion":return`$((${he(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${Pn(e.body)})`:`>(${Pn(e.body)})`;case"BraceExpansion":return uh(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 ih(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function oh(e){return e.replace(/[$`"\\]/g,"\\$&")}function ah(e,t){return e.parts.map(n=>lh(n,t)).join("")}function lh(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Ll(e);case"CommandSubstitution":return e.legacy?`\`${Pn(e.body)}\``:`$(${Pn(e.body)})`;case"ArithmeticExpansion":return`$((${he(e.expression.expression)}))`;default:return ss(e,!1)}}function Ll(e){return e.operation?`\${${Fl(e.parameter,e.operation)}}`:ch(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function ch(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function Fl(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${en(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${en(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?en(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${en(t.word)}`;case"Substring":{let n=he(t.offset.expression);return t.length?`${e}:${n}:${he(t.length.expression)}`:`${e}:${n}`}case"PatternRemoval":{let n=t.side==="prefix"?"#":"%",r=t.greedy?`${n}${n}`:n;return`${e}${r}${en(t.pattern)}`}case"PatternReplacement":{let n="/";t.all?n="//":t.anchor==="start"?n="/#":t.anchor==="end"&&(n="/%");let r=t.replacement?`/${en(t.replacement)}`:"";return`${e}${n}${en(t.pattern)}${r}`}case"CaseModification":{let n=t.direction==="upper"?"^":",",r=t.all?`${n}${n}`:n,s=t.pattern?en(t.pattern):"";return`${e}${r}${s}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${Fl(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 uh(e){return`{${e.items.map(fh).join(",")}}`}function fh(e){if(e.type==="Word")return we(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 Ml(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=ah(n.content,n.quoted);return`${t}${e.operator}${r}
77
+ ${s}${n.delimiter}`}return e.operator==="<<<"?`${t}<<< ${we(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${we(e.target)}`:`${t}${e.operator} ${we(e.target)}`}function gt(e){return e.length===0?"":` ${e.map(Ml).join(" ")}`}function at(e){return e.map(_l).join(`
78
+ `)}function dh(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} ${at(r.condition)}; then
79
+ ${at(r.body)}`)}return e.elseBody&&t.push(`else
80
+ ${at(e.elseBody)}`),`${t.join(`
81
81
  `)}
82
- fi${wt(e.redirections)}`}function ah(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let n=e.words.map(we).join(" ");t=`for ${e.variable} in ${n}`}return`${t}; do
83
- ${lt(e.body)}
84
- done${wt(e.redirections)}`}function lh(e){let t=e.init?he(e.init.expression):"",n=e.condition?he(e.condition.expression):"",r=e.update?he(e.update.expression):"";return`for ((${t}; ${n}; ${r})); do
85
- ${lt(e.body)}
86
- done${wt(e.redirections)}`}function ch(e){return`while ${lt(e.condition)}; do
87
- ${lt(e.body)}
88
- done${wt(e.redirections)}`}function uh(e){return`until ${lt(e.condition)}; do
89
- ${lt(e.body)}
90
- done${wt(e.redirections)}`}function fh(e){let t=e.items.map(dh).join(`
82
+ fi${gt(e.redirections)}`}function hh(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let n=e.words.map(we).join(" ");t=`for ${e.variable} in ${n}`}return`${t}; do
83
+ ${at(e.body)}
84
+ done${gt(e.redirections)}`}function ph(e){let t=e.init?he(e.init.expression):"",n=e.condition?he(e.condition.expression):"",r=e.update?he(e.update.expression):"";return`for ((${t}; ${n}; ${r})); do
85
+ ${at(e.body)}
86
+ done${gt(e.redirections)}`}function mh(e){return`while ${at(e.condition)}; do
87
+ ${at(e.body)}
88
+ done${gt(e.redirections)}`}function yh(e){return`until ${at(e.condition)}; do
89
+ ${at(e.body)}
90
+ done${gt(e.redirections)}`}function gh(e){let t=e.items.map(wh).join(`
91
91
  `);return`case ${we(e.word)} in
92
92
  ${t}
93
- esac${wt(e.redirections)}`}function dh(e){let t=e.patterns.map(we).join(" | "),n=lt(e.body);return n?`${t})
93
+ esac${gt(e.redirections)}`}function wh(e){let t=e.patterns.map(we).join(" | "),n=at(e.body);return n?`${t})
94
94
  ${n}
95
95
  ${e.terminator}`:`${t})
96
- ${e.terminator}`}function hh(e){return`(${lt(e.body)})${wt(e.redirections)}`}function ph(e){return`{ ${lt(e.body)}; }${wt(e.redirections)}`}function mh(e){return`((${he(e.expression.expression)}))${wt(e.redirections)}`}function yh(e){return`[[ ${xn(e.expression)} ]]${wt(e.redirections)}`}function gh(e){let t=Ol(e.body);return`${e.name}() ${t}${wt(e.redirections)}`}function he(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`${he(e.left)} ${e.operator} ${he(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${he(e.operand)}`:`${he(e.operand)}${e.operator}`;case"ArithTernary":return`${he(e.condition)} ? ${he(e.consequent)} : ${he(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${he(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${he(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${he(e.target)}[${he(e.subscript)}]`:he(e.target)} ${e.operator} ${he(e.value)}`;case"ArithDynamicElement":return`${he(e.nameExpr)}[${he(e.subscript)}]`;case"ArithGroup":return`(${he(e.expression)})`;case"ArithNested":return`$((${he(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}[${he(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(he).join("");case"ArithDoubleSubscript":return`${e.array}[${he(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 xn(e){switch(e.type){case"CondBinary":return`${we(e.left)} ${e.operator} ${we(e.right)}`;case"CondUnary":return`${e.operator} ${we(e.operand)}`;case"CondNot":return`! ${xn(e.operand)}`;case"CondAnd":return`${xn(e.left)} && ${xn(e.right)}`;case"CondOr":return`${xn(e.left)} || ${xn(e.right)}`;case"CondGroup":return`( ${xn(e.expression)} )`;case"CondWord":return we(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var wh="BASH_ALIAS_";function ts(e,t,n,r){let s=M(t);if(s>n-r.value)throw new $(`alias expansion exceeds string length limit (${n} bytes)`,"string_length");return r.value+=s,e+t}function Tl(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function Ll(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function Fl(e,t){return e.env.get(`${wh}${t}`)}function Bl(e,t,n){return Wl(e,t,n)}function Wl(e,t,n,r=!0){if(!t.name||!Tl(t.name))return t;let s=Ll(t.name);if(!s)return t;let i=Fl(e,s);if(!i||n.has(s))return t;try{n.add(s);let o=new Z,a={value:0},l=ts("",i,e.limits.maxStringLength,a),c=i.endsWith(" ");if(!c)for(let h of t.args){let p=we(h);l=ts(l,` ${p}`,e.limits.maxStringLength,a)}let u;try{u=o.parse(l)}catch(h){if(h instanceof Pe)throw h;return t}if(u.statements.length!==1||u.statements[0].pipelines.length!==1||u.statements[0].pipelines[0].commands.length!==1)return Ml(e,t,i);let f=u.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return Ml(e,t,i);let d={...f,assignments:[...t.assignments,...f.assignments],redirections:[...f.redirections,...t.redirections],line:t.line};if(c&&t.args.length>0){d={...d,args:[...d.args,...t.args]};let h=1;for(;r&&d.args.length>0;){let p=d.args[0];if(!Tl(p))break;let m=Ll(p),E=m?Fl(e,m):null;if(!E)break;if(h>=e.limits.maxCallDepth)throw new $(`alias expansion depth limit exceeded (${e.limits.maxCallDepth})`,"recursion");h++;let S={type:"SimpleCommand",name:p,args:d.args.slice(1),assignments:[],redirections:[]},y=Wl(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 Ml(e,t,n){let r={value:0},s=ts("",n,e.limits.maxStringLength,r);for(let c of t.args){let u=we(c);s=ts(s,` ${u}`,e.limits.maxStringLength,r)}let i=new Z,o=i.parseWordFromString("eval",!1,!1),a=0;for(let c of s)c==="'"&&a++;if(r.value+2+a*3>e.limits.maxStringLength)throw new $(`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 Eh=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 Ti(e){return Eh.get(e)??""}function Vl(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 zl(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 c=e.slice(s+2,l),u=Ti(c);i+=u,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,c=s+1===o;l||c?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+="$",ge(t)}function Li(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 Fi(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 Ul=5,tn=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=Vl(i))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new $(`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 zl(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>Ul))throw new $(`Glob pattern has too many ** segments (max ${Ul})`,"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(c=>c!==""),s=-1;for(let c=0;c<r.length;c++)if(this.hasGlobChars(r[c])){s=c;break}if(s===-1)return[t];let i,o;if(s===0)n?(i="/",o="/"):(i=this.cwd,o="");else{let c=r.slice(0,s);n?(i=`/${c.join("/")}`,o=`/${c.join("/")}`):(i=this.fs.resolvePath(this.cwd,c.join("/")),o=c.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=[],c=[...a],u=this.dotglob||this.hasGlobignore;if(s.startsWith(".")||this.dotglob){let d=a.some(p=>p.name==="."),h=a.some(p=>p.name==="..");d||c.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),h||c.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of c)if(!(d.name.startsWith(".")&&!s.startsWith(".")&&!u)&&this.matchPattern(d.name,s)){let h=t==="/"?`/${d.name}`:`${t}/${d.name}`,p;n===""?p=d.name:n==="/"?p=`/${d.name}`:p=`${n}/${d.name}`,i.length===0?l.push(Promise.resolve([p])):d.isDirectory&&l.push(this.expandSegments(h,p,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=[],c=[...a],u=this.dotglob||this.hasGlobignore;(s.startsWith(".")||this.dotglob)&&(a.includes(".")||c.push("."),a.includes("..")||c.push(".."));for(let d of c)if(!(d.startsWith(".")&&!s.startsWith(".")&&!u)&&this.matchPattern(d,s)){let h=t==="/"?`/${d}`:`${t}/${d}`,p;n===""?p=d:n==="/"?p=`/${d}`:p=`${n}/${d}`,i.length===0?l.push(Promise.resolve([p])):l.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(h)).isDirectory)return this.expandSegments(h,p,i)}catch(m){if(m instanceof $)throw m}return[]})())}let f=await Promise.all(l);for(let d of f)o.push(...d)}}catch(a){if(a instanceof $)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 c of i){let u=t==="."?c.name:`${t}/${c.name}`;c.isDirectory&&o.push(u)}let a=t==="."?n:`${t}/${n}`,l=await this.expandRecursive(a);r.push(...l);for(let c=0;c<o.length;c+=100){let u=o.slice(c,c+100);await Promise.all(u.map(f=>this.walkDirectoryMultiGlobstar(f,n,r)))}}else{this.checkOpsLimit();let o=await this.fs.readdir(s),a=[];for(let u of o){let f=t==="."?u:`${t}/${u}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&a.push(f)}catch(h){if(h instanceof $)throw h}}let l=t==="."?n:`${t}/${n}`,c=await this.expandRecursive(l);r.push(...c);for(let u=0;u<a.length;u+=100){let f=a.slice(u,u+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,n,r)))}}}catch(i){if(i instanceof $)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 c=t==="."?l.name:`${t}/${l.name}`;l.isDirectory?a.push(c):n&&this.matchPattern(l.name,n)&&o.push(c)}r.push(...o);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u,n,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(s),o=[];for(let l=0;l<i.length;l+=100){let c=i.slice(l,l+100),u=await Promise.all(c.map(async f=>{let d=t==="."?f:`${t}/${f}`,h=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let p=await this.fs.stat(h);return{name:f,path:d,isDirectory:p.isDirectory}}catch(p){if(p instanceof $)throw p;return null}}));o.push(...u.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 c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,n,r)))}}}catch(i){if(i instanceof $)throw i}}matchPattern(t,n){return this.patternToRegex(n).test(t)}patternToRegex(t){let n=this.patternToRegexStr(t);return ge(`^${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=Li(t,s+1);if(o!==-1){let a=t.slice(s+2,o),l=Fi(a),c=l.map(f=>this.patternToRegexStr(f)),u=c.length>0?c.join("|"):"(?:)";if(i==="@")n+=`(?:${u})`;else if(i==="*")n+=`(?:${u})*`;else if(i==="+")n+=`(?:${u})+`;else if(i==="?")n+=`(?:${u})?`;else if(i==="!")if(o<t.length-1){let d=l.map(p=>this.computePatternLength(p));if(d.every(p=>p!==null)&&d.every(p=>p===d[0])&&d[0]!==null){let p=d[0];if(p===0)n+="(?:.+)";else{let m=[];p>0&&m.push(`.{0,${p-1}}`),m.push(`.{${p+1},}`),m.push(`(?!(?:${u})).{${p}}`),n+=`(?:${m.join("|")})`}}else n+=`(?:(?!(?:${u})).)*?`}else n+=`(?!(?:${u})$).*`;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 u=t.indexOf(":]",l+2);if(u!==-1){l=u+2;continue}}if(t[l]==="]")break;l++}let c=o;for(;o<t.length&&t[o]!=="]";){if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let u=t.indexOf(":]",o+2);if(u!==-1){let f=t.slice(o+2,u),d=Ti(f);a+=d,o=u+2;continue}}if(t[o]==="\\"&&o+1<t.length){a+=`\\${t[o+1]}`,o+=2;continue}if(t[o]==="-"){let u=o===c,f=o+1===l;u||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=Li(t,r+1);if(o!==-1){if(i==="@"){let a=t.slice(r+2,o),c=Fi(a).map(u=>this.computePatternLength(u));if(c.every(u=>u!==null)&&c.every(u=>u===c[0])){n+=c[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 Mi(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 bh(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 jl(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 yr(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 c of l.parts)c.type==="ParameterExpansion"&&(c.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!c.operation||c.operation.type==="PatternRemoval"||c.operation.type==="PatternReplacement")&&(s=!0),(c.operation?.type==="VarNamePrefix"||c.operation?.type==="ArrayKeys")&&(o=!0),c.operation?.type==="Indirection"&&(a=!0));l.type==="CommandSubstitution"&&(n=!0),l.type==="ParameterExpansion"&&(i=!0,(l.parameter==="@"||l.parameter==="*")&&(r=!0),bh(l)&&(t=!0),(l.operation?.type==="VarNamePrefix"||l.operation?.type==="ArrayKeys")&&(o=!0),l.operation?.type==="Indirection"&&(a=!0)),l.type==="Glob"&&Mi(l.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i,hasVarNamePrefixExpansion:o,hasIndirection:a}}var Sh=`
97
- `;function $n(e,t){if(e>=t)throw new $(`array element limit exceeded (${t})`,"array_elements")}function Bi(e,t,n,r,s){$n(e.length,s),$n(t.length,s),e.push(n),t.push(r)}function ke(e){return e.get("IFS")??Sh}function Oe(e){return e.get("IFS")===""}function ns(e){let t=ke(e);if(t==="")return!0;for(let n of t)if(n!==" "&&n!==" "&&n!==`
98
- `)return!1;return!0}function ql(e){let t=!1,n=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?n.push(`\\${r}`):r===" "?n.push("\\t"):r===`
99
- `?n.push("\\n"):n.push(r);return t&&n.push("\\-"),n.join("")}function X(e){let t=e.get("IFS");if(t===void 0)return" ";let n=t.codePointAt(0);return n===void 0?"":String.fromCodePoint(n)}var Ah=`
100
- `;function vh(e){return Ah.includes(e)}function Wi(e){let t=new Set,n=new Set;for(let r of e)vh(r)?t.add(r):n.add(r);return{whitespace:t,nonWhitespace:n}}function Vi(e,t,n,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:($n(0,n),{words:[e],wordStarts:[0]});let{whitespace:i,nonWhitespace:o}=Wi(t),a=[],l=[],c=0;for(;c<e.length&&i.has(e[c]);)c++;if(c>=e.length)return{words:[],wordStarts:[]};if(o.has(e[c]))for(Bi(a,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&!(r!==void 0&&a.length>=r);){let u=c;for(;c<e.length;){let f=e[c];if(!s&&f==="\\"){c++,c<e.length&&c++;continue}if(i.has(f)||o.has(f))break;c++}if(Bi(a,l,e.substring(u,c),u,n),c>=e.length)break;for(;c<e.length&&i.has(e[c]);)c++;if(c<e.length&&o.has(e[c])){for(c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&o.has(e[c])&&!(r!==void 0&&a.length>=r);)for(Bi(a,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++}}return{words:a,wordStarts:l}}function rs(e,t,n){if(t==="")return e&&$n(0,n),{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=Wi(t),i=[],o=0,a=!1,l=!1,c=o;for(;o<e.length&&r.has(e[o]);)o++;if(o>c&&(a=!0),o>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[o]))for($n(i.length,n),i.push(""),o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length;){let u=o;for(;o<e.length;){let d=e[o];if(r.has(d)||s.has(d))break;o++}if($n(i.length,n),i.push(e.substring(u,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($n(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 de(e,t,n){return rs(e,t,n).words}function kh(e,t){for(let n of e)if(t.has(n))return!0;return!1}function Gl(e,t,n){if(t==="")return e;let{whitespace:r,nonWhitespace:s}=Wi(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,c=o.length-2;for(;c>=0&&o[c]==="\\";)l++,c--;if(l%2===1)return o}let a=o.substring(0,o.length-1);if(!kh(a,s))return a}return o}function ue(e,t){return e.state.namerefs?.has(t)??!1}function Bt(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function Hl(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Zl(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function Ql(e,t){return e.state.invalidNamerefs?.has(t)??!1}function zi(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function ss(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let s=n[1],i=Ne(e,s),o=e.state.associativeArrays?.has(s)??!1;return i||o}return Ne(e,t)?!0:e.state.env.has(t)}function Be(e,t,n=100){if(!ue(e,t)||Ql(e,t))return t;let r=new Set,s=t;for(;n-- >0;){if(r.has(s))return;if(r.add(s),!ue(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 Cn(e,t){if(ue(e,t))return e.state.env.get(t)}function is(e,t,n,r=100){if(!ue(e,t)||Ql(e,t))return t;let s=new Set,i=t;for(;r-- >0;){if(s.has(i))return;if(s.add(i),!ue(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)&&ss(e,n)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(o))return i;i=o}}function Kl(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 Q(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)?xt(e,t).map(i=>[i,ae(e,t,i)??""]):ve(e,t).map(s=>[s,ae(e,t,s)??""])}function Et(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)?Ne(e,t):Ne(e,t)}async function ie(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(X(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 ja;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 ze("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 ze("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 ze("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new Xe(`\${${t}}`);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let i=r[1],o=r[2];if(ue(e,i)){let u=Be(e,i);if(u&&u!==i){if(u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";i=u}}if(o==="@"||o==="*"){let u=Q(e,i);if(u.length>0){let d=o==="*"?X(e.state.env):" ",h=M(d)*(u.length-1);for(let[,p]of u)if(h+=M(p),h>e.limits.maxStringLength)throw new $(`array expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return u.map(([,p])=>p).join(d)}let f=e.state.env.get(i);return f!==void 0?f:""}if(i==="FUNCNAME"){let u=Number.parseInt(o,10);return!Number.isNaN(u)&&u>=0?e.state.funcNameStack?.[u]??"":""}if(i==="BASH_LINENO"){let u=Number.parseInt(o,10);if(!Number.isNaN(u)&&u>=0){let f=e.state.callLineStack?.[u];return f!==void 0?String(f):""}return""}if(i==="BASH_SOURCE"){let u=Number.parseInt(o,10);return!Number.isNaN(u)&&u>=0?e.state.sourceStack?.[u]??"":""}if(e.state.associativeArrays?.has(i)){let u=Gr(o);u=Kl(e,u);let f=ae(e,i,u);if(f===void 0&&n&&e.state.options.nounset)throw new ze(`${i}[${o}]`);return f||""}let l;if(/^-?\d+$/.test(o))l=Number.parseInt(o,10);else try{let u=new Z,f=re(u,o);l=await J(e,f.expression)}catch{let u=e.state.env.get(o);l=u?Number.parseInt(u,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let u=Q(e,i),f=e.state.currentLine;if(u.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${i}: bad array subscript
96
+ ${e.terminator}`}function Eh(e){return`(${at(e.body)})${gt(e.redirections)}`}function bh(e){return`{ ${at(e.body)}; }${gt(e.redirections)}`}function Sh(e){return`((${he(e.expression.expression)}))${gt(e.redirections)}`}function Ah(e){return`[[ ${xn(e.expression)} ]]${gt(e.redirections)}`}function vh(e){let t=Tl(e.body);return`${e.name}() ${t}${gt(e.redirections)}`}function he(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`${he(e.left)} ${e.operator} ${he(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${he(e.operand)}`:`${he(e.operand)}${e.operator}`;case"ArithTernary":return`${he(e.condition)} ? ${he(e.consequent)} : ${he(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${he(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${he(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${he(e.target)}[${he(e.subscript)}]`:he(e.target)} ${e.operator} ${he(e.value)}`;case"ArithDynamicElement":return`${he(e.nameExpr)}[${he(e.subscript)}]`;case"ArithGroup":return`(${he(e.expression)})`;case"ArithNested":return`$((${he(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}[${he(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(he).join("");case"ArithDoubleSubscript":return`${e.array}[${he(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 xn(e){switch(e.type){case"CondBinary":return`${we(e.left)} ${e.operator} ${we(e.right)}`;case"CondUnary":return`${e.operator} ${we(e.operand)}`;case"CondNot":return`! ${xn(e.operand)}`;case"CondAnd":return`${xn(e.left)} && ${xn(e.right)}`;case"CondOr":return`${xn(e.left)} || ${xn(e.right)}`;case"CondGroup":return`( ${xn(e.expression)} )`;case"CondWord":return we(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var kh="BASH_ALIAS_";function is(e,t,n,r){let s=V(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 Bl(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function Wl(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function Vl(e,t){return e.env.get(`${kh}${t}`)}function Ul(e,t,n){return jl(e,t,n)}function jl(e,t,n,r=!0){if(!t.name||!Bl(t.name))return t;let s=Wl(t.name);if(!s)return t;let i=Vl(e,s);if(!i||n.has(s))return t;try{n.add(s);let o=new Q,a={value:0},l=is("",i,e.limits.maxStringLength,a),c=i.endsWith(" ");if(!c)for(let h of t.args){let p=we(h);l=is(l,` ${p}`,e.limits.maxStringLength,a)}let u;try{u=o.parse(l)}catch(h){if(h instanceof xe)throw h;return t}if(u.statements.length!==1||u.statements[0].pipelines.length!==1||u.statements[0].pipelines[0].commands.length!==1)return zl(e,t,i);let f=u.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return zl(e,t,i);let d={...f,assignments:[...t.assignments,...f.assignments],redirections:[...f.redirections,...t.redirections],line:t.line};if(c&&t.args.length>0){d={...d,args:[...d.args,...t.args]};let h=1;for(;r&&d.args.length>0;){let p=d.args[0];if(!Bl(p))break;let m=Wl(p),y=m?Vl(e,m):null;if(!y)break;if(h>=e.limits.maxCallDepth)throw new C(`alias expansion depth limit exceeded (${e.limits.maxCallDepth})`,"recursion");h++;let b={type:"SimpleCommand",name:p,args:d.args.slice(1),assignments:[],redirections:[]},w=jl(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 zl(e,t,n){let r={value:0},s=is("",n,e.limits.maxStringLength,r);for(let c of t.args){let u=we(c);s=is(s,` ${u}`,e.limits.maxStringLength,r)}let i=new Q,o=i.parseWordFromString("eval",!1,!1),a=0;for(let c of s)c==="'"&&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 xh=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 Fi(e){return xh.get(e)??""}function ql(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 Gl(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 c=e.slice(s+2,l),u=Fi(c);i+=u,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,c=s+1===o;l||c?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+="$",ge(t)}function Mi(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 Hl=5,tn=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=ql(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 Gl(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>Hl))throw new C(`Glob pattern has too many ** segments (max ${Hl})`,"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(c=>c!==""),s=-1;for(let c=0;c<r.length;c++)if(this.hasGlobChars(r[c])){s=c;break}if(s===-1)return[t];let i,o;if(s===0)n?(i="/",o="/"):(i=this.cwd,o="");else{let c=r.slice(0,s);n?(i=`/${c.join("/")}`,o=`/${c.join("/")}`):(i=this.fs.resolvePath(this.cwd,c.join("/")),o=c.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=[],c=[...a],u=this.dotglob||this.hasGlobignore;if(s.startsWith(".")||this.dotglob){let d=a.some(p=>p.name==="."),h=a.some(p=>p.name==="..");d||c.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),h||c.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of c)if(!(d.name.startsWith(".")&&!s.startsWith(".")&&!u)&&this.matchPattern(d.name,s)){let h=t==="/"?`/${d.name}`:`${t}/${d.name}`,p;n===""?p=d.name:n==="/"?p=`/${d.name}`:p=`${n}/${d.name}`,i.length===0?l.push(Promise.resolve([p])):d.isDirectory&&l.push(this.expandSegments(h,p,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=[],c=[...a],u=this.dotglob||this.hasGlobignore;(s.startsWith(".")||this.dotglob)&&(a.includes(".")||c.push("."),a.includes("..")||c.push(".."));for(let d of c)if(!(d.startsWith(".")&&!s.startsWith(".")&&!u)&&this.matchPattern(d,s)){let h=t==="/"?`/${d}`:`${t}/${d}`,p;n===""?p=d:n==="/"?p=`/${d}`:p=`${n}/${d}`,i.length===0?l.push(Promise.resolve([p])):l.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(h)).isDirectory)return this.expandSegments(h,p,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 c of i){let u=t==="."?c.name:`${t}/${c.name}`;c.isDirectory&&o.push(u)}let a=t==="."?n:`${t}/${n}`,l=await this.expandRecursive(a);r.push(...l);for(let c=0;c<o.length;c+=100){let u=o.slice(c,c+100);await Promise.all(u.map(f=>this.walkDirectoryMultiGlobstar(f,n,r)))}}else{this.checkOpsLimit();let o=await this.fs.readdir(s),a=[];for(let u of o){let f=t==="."?u:`${t}/${u}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&a.push(f)}catch(h){if(h instanceof C)throw h}}let l=t==="."?n:`${t}/${n}`,c=await this.expandRecursive(l);r.push(...c);for(let u=0;u<a.length;u+=100){let f=a.slice(u,u+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 c=t==="."?l.name:`${t}/${l.name}`;l.isDirectory?a.push(c):n&&this.matchPattern(l.name,n)&&o.push(c)}r.push(...o);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u,n,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(s),o=[];for(let l=0;l<i.length;l+=100){let c=i.slice(l,l+100),u=await Promise.all(c.map(async f=>{let d=t==="."?f:`${t}/${f}`,h=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let p=await this.fs.stat(h);return{name:f,path:d,isDirectory:p.isDirectory}}catch(p){if(p instanceof C)throw p;return null}}));o.push(...u.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 c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u.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 ge(`^${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=Mi(t,s+1);if(o!==-1){let a=t.slice(s+2,o),l=Bi(a),c=l.map(f=>this.patternToRegexStr(f)),u=c.length>0?c.join("|"):"(?:)";if(i==="@")n+=`(?:${u})`;else if(i==="*")n+=`(?:${u})*`;else if(i==="+")n+=`(?:${u})+`;else if(i==="?")n+=`(?:${u})?`;else if(i==="!")if(o<t.length-1){let d=l.map(p=>this.computePatternLength(p));if(d.every(p=>p!==null)&&d.every(p=>p===d[0])&&d[0]!==null){let p=d[0];if(p===0)n+="(?:.+)";else{let m=[];p>0&&m.push(`.{0,${p-1}}`),m.push(`.{${p+1},}`),m.push(`(?!(?:${u})).{${p}}`),n+=`(?:${m.join("|")})`}}else n+=`(?:(?!(?:${u})).)*?`}else n+=`(?!(?:${u})$).*`;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 u=t.indexOf(":]",l+2);if(u!==-1){l=u+2;continue}}if(t[l]==="]")break;l++}let c=o;for(;o<t.length&&t[o]!=="]";){if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let u=t.indexOf(":]",o+2);if(u!==-1){let f=t.slice(o+2,u),d=Fi(f);a+=d,o=u+2;continue}}if(t[o]==="\\"&&o+1<t.length){a+=`\\${t[o+1]}`,o+=2;continue}if(t[o]==="-"){let u=o===c,f=o+1===l;u||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=Mi(t,r+1);if(o!==-1){if(i==="@"){let a=t.slice(r+2,o),c=Bi(a).map(u=>this.computePatternLength(u));if(c.every(u=>u!==null)&&c.every(u=>u===c[0])){n+=c[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 Wi(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 Ph(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 Zl(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 gr(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 c of l.parts)c.type==="ParameterExpansion"&&(c.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!c.operation||c.operation.type==="PatternRemoval"||c.operation.type==="PatternReplacement")&&(s=!0),(c.operation?.type==="VarNamePrefix"||c.operation?.type==="ArrayKeys")&&(o=!0),c.operation?.type==="Indirection"&&(a=!0));l.type==="CommandSubstitution"&&(n=!0),l.type==="ParameterExpansion"&&(i=!0,(l.parameter==="@"||l.parameter==="*")&&(r=!0),Ph(l)&&(t=!0),(l.operation?.type==="VarNamePrefix"||l.operation?.type==="ArrayKeys")&&(o=!0),l.operation?.type==="Indirection"&&(a=!0)),l.type==="Glob"&&Wi(l.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i,hasVarNamePrefixExpansion:o,hasIndirection:a}}var $h=`
97
+ `;function $n(e,t){if(e>=t)throw new C(`array element limit exceeded (${t})`,"array_elements")}function Vi(e,t,n,r,s){$n(e.length,s),$n(t.length,s),e.push(n),t.push(r)}function ve(e){return e.get("IFS")??$h}function Oe(e){return e.get("IFS")===""}function os(e){let t=ve(e);if(t==="")return!0;for(let n of t)if(n!==" "&&n!==" "&&n!==`
98
+ `)return!1;return!0}function Ql(e){let t=!1,n=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?n.push(`\\${r}`):r===" "?n.push("\\t"):r===`
99
+ `?n.push("\\n"):n.push(r);return t&&n.push("\\-"),n.join("")}function X(e){let t=e.get("IFS");if(t===void 0)return" ";let n=t.codePointAt(0);return n===void 0?"":String.fromCodePoint(n)}var Ch=`
100
+ `;function Nh(e){return Ch.includes(e)}function zi(e){let t=new Set,n=new Set;for(let r of e)Nh(r)?t.add(r):n.add(r);return{whitespace:t,nonWhitespace:n}}function Ui(e,t,n,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:($n(0,n),{words:[e],wordStarts:[0]});let{whitespace:i,nonWhitespace:o}=zi(t),a=[],l=[],c=0;for(;c<e.length&&i.has(e[c]);)c++;if(c>=e.length)return{words:[],wordStarts:[]};if(o.has(e[c]))for(Vi(a,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&!(r!==void 0&&a.length>=r);){let u=c;for(;c<e.length;){let f=e[c];if(!s&&f==="\\"){c++,c<e.length&&c++;continue}if(i.has(f)||o.has(f))break;c++}if(Vi(a,l,e.substring(u,c),u,n),c>=e.length)break;for(;c<e.length&&i.has(e[c]);)c++;if(c<e.length&&o.has(e[c])){for(c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&o.has(e[c])&&!(r!==void 0&&a.length>=r);)for(Vi(a,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++}}return{words:a,wordStarts:l}}function as(e,t,n){if(t==="")return e&&$n(0,n),{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=zi(t),i=[],o=0,a=!1,l=!1,c=o;for(;o<e.length&&r.has(e[o]);)o++;if(o>c&&(a=!0),o>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[o]))for($n(i.length,n),i.push(""),o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length;){let u=o;for(;o<e.length;){let d=e[o];if(r.has(d)||s.has(d))break;o++}if($n(i.length,n),i.push(e.substring(u,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($n(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 de(e,t,n){return as(e,t,n).words}function Rh(e,t){for(let n of e)if(t.has(n))return!0;return!1}function Kl(e,t,n){if(t==="")return e;let{whitespace:r,nonWhitespace:s}=zi(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,c=o.length-2;for(;c>=0&&o[c]==="\\";)l++,c--;if(l%2===1)return o}let a=o.substring(0,o.length-1);if(!Rh(a,s))return a}return o}function ue(e,t){return e.state.namerefs?.has(t)??!1}function Bt(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function Xl(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Yl(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function Jl(e,t){return e.state.invalidNamerefs?.has(t)??!1}function ji(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function ls(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let s=n[1],i=Ne(e,s),o=e.state.associativeArrays?.has(s)??!1;return i||o}return Ne(e,t)?!0:e.state.env.has(t)}function Be(e,t,n=100){if(!ue(e,t)||Jl(e,t))return t;let r=new Set,s=t;for(;n-- >0;){if(r.has(s))return;if(r.add(s),!ue(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 Cn(e,t){if(ue(e,t))return e.state.env.get(t)}function cs(e,t,n,r=100){if(!ue(e,t)||Jl(e,t))return t;let s=new Set,i=t;for(;r-- >0;){if(s.has(i))return;if(s.add(i),!ue(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)&&ls(e,n)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(o))return i;i=o}}function ec(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 K(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)?xt(e,t).map(i=>[i,ae(e,t,i)??""]):Ae(e,t).map(s=>[s,ae(e,t,s)??""])}function wt(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)?Ne(e,t):Ne(e,t)}async function ie(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(X(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 Za;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 ze("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 ze("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 ze("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new Xe(`\${${t}}`);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let i=r[1],o=r[2];if(ue(e,i)){let u=Be(e,i);if(u&&u!==i){if(u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";i=u}}if(o==="@"||o==="*"){let u=K(e,i);if(u.length>0){let d=o==="*"?X(e.state.env):" ",h=V(d)*(u.length-1);for(let[,p]of u)if(h+=V(p),h>e.limits.maxStringLength)throw new C(`array expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return u.map(([,p])=>p).join(d)}let f=e.state.env.get(i);return f!==void 0?f:""}if(i==="FUNCNAME"){let u=Number.parseInt(o,10);return!Number.isNaN(u)&&u>=0?e.state.funcNameStack?.[u]??"":""}if(i==="BASH_LINENO"){let u=Number.parseInt(o,10);if(!Number.isNaN(u)&&u>=0){let f=e.state.callLineStack?.[u];return f!==void 0?String(f):""}return""}if(i==="BASH_SOURCE"){let u=Number.parseInt(o,10);return!Number.isNaN(u)&&u>=0?e.state.sourceStack?.[u]??"":""}if(e.state.associativeArrays?.has(i)){let u=Zr(o);u=ec(e,u);let f=ae(e,i,u);if(f===void 0&&n&&e.state.options.nounset)throw new ze(`${i}[${o}]`);return f||""}let l;if(/^-?\d+$/.test(o))l=Number.parseInt(o,10);else try{let u=new Q,f=re(u,o);l=await J(e,f.expression)}catch{let u=e.state.env.get(o);l=u?Number.parseInt(u,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let u=K(e,i),f=e.state.currentLine;if(u.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${i}: bad array subscript
101
101
  `,"";let h=Math.max(...u.map(([m])=>typeof m=="number"?m:0))+1+l;return h<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${i}: bad array subscript
102
- `,""):ae(e,i,h)||""}let c=ae(e,i,l);if(c!==void 0)return c;if(l===0){let u=e.state.env.get(i);if(u!==void 0)return u}if(n&&e.state.options.nounset)throw new ze(`${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 ze(t);return i||""}if(ue(e,t)){let i=Be(e,t);if(i===void 0)return"";if(i!==t)return await ie(e,i,n);let o=e.state.env.get(t);if((o===void 0||o==="")&&n&&e.state.options.nounset)throw new ze(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(Et(e,t)){let i=ae(e,t,0);if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new ze(t);return""}if(n&&e.state.options.nounset)throw new ze(t);return""}async function $t(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(ue(e,s)){let l=Be(e,s);if(l&&l!==s){if(l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;s=l}}if(i==="@"||i==="*")return Q(e,s).length>0?!0:e.state.env.has(s);if(e.state.associativeArrays?.has(s)){let l=Kl(e,Gr(i));return Yt(e,s,l)}let a;if(/^-?\d+$/.test(i))a=Number.parseInt(i,10);else try{let l=new Z,c=re(l,i);a=await J(e,c.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=Q(e,s);if(l.length===0)return!1;let u=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+a;return u<0?!1:Yt(e,s,u)}return Yt(e,s,a)}if(ue(e,t)){let s=Be(e,t);return s===void 0||s===t?e.state.env.has(t):$t(e,s)}return e.state.env.has(t)?!0:Et(e,t)?Yt(e,t,0):!1}async function Xl(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 ie(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 ie(e,i);n+=o,r=s;continue}if(/[*@#?\-!$]/.test(t[r+1]||"")){let s=t[r+1],i=await ie(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 ie(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 Ui(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 c=n.slice(o+2,l-1);if(e.execFn){let u=await e.execFn(c,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.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 c=n.slice(o+2,l-1),u=await ie(e,c);i+=u,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),c=await ie(e,l);i+=c,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 c=await e.execFn(l,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}o=a+1}else i+=n[o],o++;return i}var gr=1e4,ji={maxResults:gr,maxStringBytes:10*1024*1024};function os(e,t,n,r){if(e.length>=n.maxResults)return!1;let s=M(t);if(s>n.maxStringBytes-r.value)throw new $(`brace expansion string limit exceeded (${n.maxStringBytes} bytes)`,"string_length");return e.push(t),r.value+=s,!0}function xh(e,t,n,r,s,i=ji){let o=n??1;o===0&&(o=1);let a=Math.abs(o),l=[],c=0;if(r?.match(/^-?0\d/)&&(c=Math.max(c,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(c=Math.max(c,s.replace(/^-/,"").length)),c>i.maxStringBytes)throw new $(`brace expansion padding limit exceeded (${i.maxStringBytes} bytes)`,"string_length");let u={value:0},f=d=>{if(c>0){let h=d<0,p=String(Math.abs(d)).padStart(c,"0");return h?`-${p}`:p}return String(d)};if(e<=t)for(let d=e,h=0;d<=t&&h<gr&&os(l,f(d),i,u);d+=a,h++);else for(let d=e,h=0;d>=t&&h<gr&&os(l,f(d),i,u);d-=a,h++);return l}function Ph(e,t,n,r=ji){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",c=e>="a"&&e<="z",u=t>="A"&&t<="Z",f=t>="a"&&t<="z";if(l&&f||c&&u){let p=n!==void 0?`..${n}`:"";throw new Lr(`{${e}..${t}${p}}: invalid sequence`)}let d=[],h={value:0};if(i<=o)for(let p=i,m=0;p<=o&&m<gr&&os(d,String.fromCharCode(p),r,h);p+=a,m++);else for(let p=i,m=0;p>=o&&m<gr&&os(d,String.fromCharCode(p),r,h);p-=a,m++);return d}function qi(e,t,n,r,s,i=ji){let o=n!==void 0?`..${n}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:xh(e,t,n,r,s,i),literal:`{${e}..${t}${o}}`}:typeof e=="string"&&typeof t=="string"?{expanded:Ph(e,t,n,i),literal:`{${e}..${t}${o}}`}:{expanded:null,literal:`{${e}..${t}${o}}`}}function Yl(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 Ct(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function Gi(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 et(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function Vn(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function ce(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function oe(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=$h(e,s+1);if(o!==-1){let a=e.slice(s+2,o),c=Ch(a).map(f=>oe(f,t,n)),u=c.length>0?c.join("|"):"(?:)";i==="@"?r+=`(?:${u})`:i==="*"?r+=`(?:${u})*`:i==="+"?r+=`(?:${u})+`:i==="?"?r+=`(?:${u})?`:i==="!"&&(r+=`(?!(?:${u})$).*`),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=Nh(e,s);if(o===-1)r+="\\[",s++;else{let a=e.slice(s+1,o);r+=Rh(a),s=o+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,s++):(r+=i,s++)}return r}function $h(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 Ch(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 Nh(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 Rh(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+=Dh(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 Oh=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 Dh(e){return Oh.get(e)??""}async function nn(e,t,n,r,s){let i="",o=e.state.shoptOptions.extglob;for(let a of t.parts)if(a.type==="Glob")i+=oe(a.pattern,n,o);else if(a.type==="Literal")i+=oe(a.value,n,o);else if(a.type==="SingleQuoted"||a.type==="Escaped")i+=ce(a.value);else if(a.type==="DoubleQuoted"){let l=await r(e,a.parts);i+=ce(l)}else if(a.type==="ParameterExpansion"){let l=await s(e,a);i+=oe(l,n,o)}else{let l=await s(e,a);i+=ce(l)}return i}function bt(e,t,n,r,s){if(r==="prefix")return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),ge(`^${n}`,"s").replace(t,"");let i=ge(`${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=ge(`^(?:.*)(${n})$`,"s").exec(t);if(!o)return t;let a=o[1]??"";return t.slice(0,t.length-a.length)}function zn(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 as(e,t,n,r,s){let i=new Tn(e.limits.maxStringLength,"pattern replacement",()=>new $(`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 Jl(e){let t=[],n=0;return{append(r){let s=M(r);if(s>e-n)throw new $(`prompt expansion exceeds string length limit (${e} bytes)`,"string_length");r&&t.push(r),n+=s},build:()=>t.join("")}}function Ih(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=Jl(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 wr(e,t){let n=Jl(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")||"/",c=a.startsWith(l)?`~${a.slice(l.length)}`:a,u=a.split("/").pop()||a,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],p=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(`
103
- `),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(c),r+=2;break;case"W":n.append(u),r+=2;break;case"d":{let S=String(f.getDate()).padStart(2," ");n.append(`${d[f.getDay()]} ${h[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(Ih(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(p),r+=2;break;case"!":n.append(p),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 rn(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`
102
+ `,""):ae(e,i,h)||""}let c=ae(e,i,l);if(c!==void 0)return c;if(l===0){let u=e.state.env.get(i);if(u!==void 0)return u}if(n&&e.state.options.nounset)throw new ze(`${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 ze(t);return i||""}if(ue(e,t)){let i=Be(e,t);if(i===void 0)return"";if(i!==t)return await ie(e,i,n);let o=e.state.env.get(t);if((o===void 0||o==="")&&n&&e.state.options.nounset)throw new ze(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(wt(e,t)){let i=ae(e,t,0);if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new ze(t);return""}if(n&&e.state.options.nounset)throw new ze(t);return""}async function $t(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(ue(e,s)){let l=Be(e,s);if(l&&l!==s){if(l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;s=l}}if(i==="@"||i==="*")return K(e,s).length>0?!0:e.state.env.has(s);if(e.state.associativeArrays?.has(s)){let l=ec(e,Zr(i));return Yt(e,s,l)}let a;if(/^-?\d+$/.test(i))a=Number.parseInt(i,10);else try{let l=new Q,c=re(l,i);a=await J(e,c.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=K(e,s);if(l.length===0)return!1;let u=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+a;return u<0?!1:Yt(e,s,u)}return Yt(e,s,a)}if(ue(e,t)){let s=Be(e,t);return s===void 0||s===t?e.state.env.has(t):$t(e,s)}return e.state.env.has(t)?!0:wt(e,t)?Yt(e,t,0):!1}async function tc(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 ie(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 ie(e,i);n+=o,r=s;continue}if(/[*@#?\-!$]/.test(t[r+1]||"")){let s=t[r+1],i=await ie(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 ie(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 qi(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 c=n.slice(o+2,l-1);if(e.execFn){let u=await e.execFn(c,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.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 c=n.slice(o+2,l-1),u=await ie(e,c);i+=u,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),c=await ie(e,l);i+=c,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 c=await e.execFn(l,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}o=a+1}else i+=n[o],o++;return i}var wr=1e4,Gi={maxResults:wr,maxStringBytes:10*1024*1024};function us(e,t,n,r){if(e.length>=n.maxResults)return!1;let s=V(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 Oh(e,t,n,r,s,i=Gi){let o=n??1;o===0&&(o=1);let a=Math.abs(o),l=[],c=0;if(r?.match(/^-?0\d/)&&(c=Math.max(c,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(c=Math.max(c,s.replace(/^-/,"").length)),c>i.maxStringBytes)throw new C(`brace expansion padding limit exceeded (${i.maxStringBytes} bytes)`,"string_length");let u={value:0},f=d=>{if(c>0){let h=d<0,p=String(Math.abs(d)).padStart(c,"0");return h?`-${p}`:p}return String(d)};if(e<=t)for(let d=e,h=0;d<=t&&h<wr&&us(l,f(d),i,u);d+=a,h++);else for(let d=e,h=0;d>=t&&h<wr&&us(l,f(d),i,u);d-=a,h++);return l}function Dh(e,t,n,r=Gi){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",c=e>="a"&&e<="z",u=t>="A"&&t<="Z",f=t>="a"&&t<="z";if(l&&f||c&&u){let p=n!==void 0?`..${n}`:"";throw new Mr(`{${e}..${t}${p}}: invalid sequence`)}let d=[],h={value:0};if(i<=o)for(let p=i,m=0;p<=o&&m<wr&&us(d,String.fromCharCode(p),r,h);p+=a,m++);else for(let p=i,m=0;p>=o&&m<wr&&us(d,String.fromCharCode(p),r,h);p-=a,m++);return d}function Hi(e,t,n,r,s,i=Gi){let o=n!==void 0?`..${n}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:Oh(e,t,n,r,s,i),literal:`{${e}..${t}${o}}`}:typeof e=="string"&&typeof t=="string"?{expanded:Dh(e,t,n,i),literal:`{${e}..${t}${o}}`}:{expanded:null,literal:`{${e}..${t}${o}}`}}function nc(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 Ct(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function Zi(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 et(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function zn(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function ce(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function oe(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=Ih(e,s+1);if(o!==-1){let a=e.slice(s+2,o),c=_h(a).map(f=>oe(f,t,n)),u=c.length>0?c.join("|"):"(?:)";i==="@"?r+=`(?:${u})`:i==="*"?r+=`(?:${u})*`:i==="+"?r+=`(?:${u})+`:i==="?"?r+=`(?:${u})?`:i==="!"&&(r+=`(?!(?:${u})$).*`),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=Th(e,s);if(o===-1)r+="\\[",s++;else{let a=e.slice(s+1,o);r+=Lh(a),s=o+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,s++):(r+=i,s++)}return r}function Ih(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 _h(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 Th(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 Lh(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+=Mh(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 Fh=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 Mh(e){return Fh.get(e)??""}async function nn(e,t,n,r,s){let i="",o=e.state.shoptOptions.extglob;for(let a of t.parts)if(a.type==="Glob")i+=oe(a.pattern,n,o);else if(a.type==="Literal")i+=oe(a.value,n,o);else if(a.type==="SingleQuoted"||a.type==="Escaped")i+=ce(a.value);else if(a.type==="DoubleQuoted"){let l=await r(e,a.parts);i+=ce(l)}else if(a.type==="ParameterExpansion"){let l=await s(e,a);i+=oe(l,n,o)}else{let l=await s(e,a);i+=ce(l)}return i}function Et(e,t,n,r,s){if(r==="prefix")return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),ge(`^${n}`,"s").replace(t,"");let i=ge(`${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=ge(`^(?:.*)(${n})$`,"s").exec(t);if(!o)return t;let a=o[1]??"";return t.slice(0,t.length-a.length)}function Un(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 fs(e,t,n,r,s){let i=new Ln(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 rc(e){let t=[],n=0;return{append(r){let s=V(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 Bh(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=rc(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 Er(e,t){let n=rc(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")||"/",c=a.startsWith(l)?`~${a.slice(l.length)}`:a,u=a.split("/").pop()||a,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],p=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(`
103
+ `),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(c),r+=2;break;case"W":n.append(u),r+=2;break;case"d":{let b=String(f.getDate()).padStart(2," ");n.append(`${d[f.getDay()]} ${h[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(Bh(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(p),r+=2;break;case"!":n.append(p),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 rn(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`
104
104
  `: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 Ze(e,t){e.state.readonlyVars=e.state.readonlyVars||new Set,e.state.readonlyVars.add(t)}function We(e,t){return e.state.readonlyVars?.has(t)??!1}function fe(e,t,n="bash"){if(We(e,t)){let r=`${n}: ${t}: readonly variable
105
- `;throw new q(1,"",r)}return null}function St(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 ls(e,t){e.state.exportedVars?.delete(t)}function sn(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let n="",r=xe(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"),ue(e,t)&&(n+="n"),We(e,t)&&(n+="r"),e.state.exportedVars?.has(t)&&(n+="x"),n}async function ec(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 Hi(e){if(/^(?:\d+|[@*#?$!-])$/.test(e))throw new q(1,"",`bash: $${e}: cannot assign in this way
106
- `)}async function tc(e,t,n,r,s){e.coverage?.hit("bash:expansion:assign_default");let i=r.isUnset||n.checkEmpty&&r.isEmpty;if(i&&Hi(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,c]=a;if(c==="@"||c==="*")throw new q(1,"",`${e.state.expansionStderr||""}bash: ${t}: bad array subscript
107
- `);let u;if(/^\d+$/.test(c))u=Number.parseInt(c,10);else{try{let f=new Z,d=re(f,c);u=await J(e,d.expression)}catch{let f=e.state.env.get(c);u=f?Number.parseInt(f,10):0}Number.isNaN(u)&&(u=0)}G(e,l,u,o)}else e.state.env.set(t,o);return o}return r.effectiveValue}async function nc(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}
108
- `)}return r.effectiveValue}async function rc(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 sc(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_removal");let i=n.pattern?await nn(e,n.pattern,n.greedy,r,s):"";return bt(e,t,i,n.side,n.greedy)}async function ic(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",o=e.state.shoptOptions.extglob;if(n.pattern)for(let c of n.pattern.parts)if(c.type==="Glob")i+=oe(c.pattern,!0,o);else if(c.type==="Literal")i+=oe(c.value,!0,o);else if(c.type==="SingleQuoted"||c.type==="Escaped")i+=ce(c.value);else if(c.type==="DoubleQuoted"){let u=await r(e,c.parts);i+=ce(u)}else if(c.type==="ParameterExpansion"){let u=await s(e,c);i+=oe(u,!0,o)}else{let u=await s(e,c);i+=ce(u)}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 c=ge(i,l);return as(e,t,c,a,n.all)}catch(c){if(c instanceof $)throw c;return t}}function Zi(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=Q(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)&&Et(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=ae(e,t,0)||"";return String([...s].length)}return String([...n].length)}async function oc(e,t,n,r){e.coverage?.hit("bash:expansion:substring");let s=await J(e,r.offset.expression),i=r.length?await J(e,r.length.expression):void 0;if(t==="@"||t==="*"){let c=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let p=1;p<=c;p++)u.push(e.state.env.get(String(p))||"");let f=e.state.env.get("0")||"bash",d,h;if(s<=0)if(d=[f,...u],s<0){if(h=d.length+s,h<0)return""}else h=0;else d=u,h=s-1;if(h<0||h>=d.length)return"";if(i!==void 0){let p=i<0?d.length+i:h+i;return d.slice(h,Math.max(h,p)).join(" ")}return d.slice(h).join(" ")}let o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(o){let c=o[1];if(e.state.associativeArrays?.has(c))throw new q(1,"",`bash: \${${c}[@]: 0: 3}: bad substitution
109
- `);let u=Q(e,c),f=0;if(s<0){if(u.length>0){let d=u[u.length-1][0],p=(typeof d=="number"?d:0)+1+s;if(p<0||(f=u.findIndex(([m])=>typeof m=="number"&&m>=p),f<0))return""}}else if(f=u.findIndex(([d])=>typeof d=="number"&&d>=s),f<0)return"";if(i!==void 0){if(i<0)throw new le(`${o[1]}[@]: substring expression < 0`);return u.slice(f,f+i).map(([,d])=>d).join(" ")}return u.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 c=a.length+i;return a.slice(l,Math.max(l,c)).join("")}return a.slice(l,l+i).join("")}return a.slice(l).join("")}async function ac(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+=oe(f.pattern,!0,i);else if(f.type==="Literal")o+=oe(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")o+=ce(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);o+=ce(d)}else if(f.type==="ParameterExpansion"){let d=await s(e,f);o+=oe(d,!0,i)}let a=ge(`^(?:${o})$`),l=n.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),c="",u=!1;for(let f of t)!n.all&&u?c+=f:a.test(f)?(c+=l(f),u=!0):c+=f;return c}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 lc(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 Q(e,i[1]).map(([,c])=>rn(c)).join(" ");if(i&&s.operator==="a")return sn(e,i[1]);let o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(o&&s.operator==="a")return sn(e,o[1]);switch(s.operator){case"Q":return r?"":rn(n);case"P":return wr(e,n);case"a":return sn(e,t);case"A":return r?"":`${t}=${rn(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`
110
- `;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?"":rn(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 cc(e,t,n,r,s,i,o=!1){if(e.coverage?.hit("bash:expansion:indirection"),ue(e,t))return Cn(e,t)||"";let a=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(s.innerOp?.type==="UseAlternative")return"";throw new Xe(`\${!${t}}`)}let l=n;if(a&&(l===""||l.includes(" ")))throw new Xe(`\${!${t}}`);let c=l.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(c&&c[1].includes("~"))throw new Xe(`\${!${t}}`);if(s.innerOp){let u={type:"ParameterExpansion",parameter:l,operation:s.innerOp};return i(e,u,o)}return await ie(e,l)}function uc(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=Q(e,t.array).map(([s])=>String(s));return t.star?r.join(X(e.state.env)):r.join(" ")}function fc(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let n=zn(e,t.prefix);return t.star?n.join(X(e.state.env)):n.join(" ")}function dc(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=Q(e,o);return l.length===0?{isEmpty:!0,effectiveValue:""}:a==="*"?{isEmpty:r?n==="":!1,effectiveValue:n}:{isEmpty:l.length===1&&l.every(([,c])=>c===""),effectiveValue:n}}return{isEmpty:n==="",effectiveValue:n}}function on(e,t){e.lastExitCode=t,e.env.set("?",String(t)),e.lastSubstitutionExitCode=t}function _h(e){switch(e.operator){case"<":case"<&":case"<<":case"<<-":case"<<<":case"<>":return e.fd===null||e.fd===0;default:return!1}}function cs(e,t){return t.some(_h)?0:e.lastSubstitutionExitCode??0}function hc(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 pc(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 us(e,t){let n=new Z,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=at(e.state.arrays),a=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let c=await e.executeScript(r),u=c.exitCode;return e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.suppressVerbose=l,on(e.state,u),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr),e.state.bashPid=s,c.stdout.replace(/\n+$/,"")}catch(c){if(e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.bashPid=s,e.state.suppressVerbose=l,c instanceof $)throw c;return c instanceof q?(on(e.state,c.exitCode),c.stdout?.replace(/\n+$/,"")??""):""}}function Qi(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+=et(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=Th(e,a);n+=et(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 Th(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 mc(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+=et(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 Lh(e,a);n+=et(l),r=i+1;continue}}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=pc(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await us(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 us(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 Lh(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=pc(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await us(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 us(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 Ki(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 an(e,t){return t.split(":").map(n=>Ki(e,n)).join(":")}function De(e,t,n,r){if(e.length>n-t.length)throw new $(`${r} element limit exceeded (${n})`,"array_elements");for(let s of t)e.push(s)}async function Fh(e,t,n,r){let s="";for(let i of t.parts)if(i.type==="Glob")s+=oe(i.pattern,!0,e.state.shoptOptions.extglob);else if(i.type==="Literal")s+=oe(i.value,!0,e.state.shoptOptions.extglob);else if(i.type==="SingleQuoted"||i.type==="Escaped")s+=ce(i.value);else if(i.type==="DoubleQuoted"){let o=await n(e,i.parts);s+=ce(o)}else if(i.type==="ParameterExpansion"){let o=await r(e,i);s+=oe(o,!0,e.state.shoptOptions.extglob)}else{let o=await r(e,i);s+=ce(o)}return s}async function yc(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]==="*",c=i.operation,u=Q(e,a),f=u.map(([,E])=>E);if(u.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="";c.pattern&&(d=await Fh(e,c.pattern,n,r));let h=c.replacement?await n(e,c.replacement.parts):"",p=d;c.anchor==="start"?p=`^${d}`:c.anchor==="end"&&(p=`${d}$`);let m=[];try{let E=ge(p,c.all?"g":"");for(let S of f)m.push(E.replace(S,h))}catch{m.push(...f)}if(l){let E=X(e.state.env);return{values:[m.join(E)],quoted:!0}}return{values:m,quoted:!0}}async function gc(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]==="*",c=i.operation,u=Q(e,a),f=u.map(([,p])=>p);if(u.length===0){let p=e.state.env.get(a);p!==void 0&&f.push(p)}if(f.length===0)return{values:[],quoted:!0};let d=c.pattern?await nn(e,c.pattern,c.greedy,n,r):"",h=[];for(let p of f)h.push(bt(e,p,d,c.side,c.greedy));if(l){let p=X(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}async function wc(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 c=Q(e,l),u=c.length>0||e.state.env.has(l),f=c.length===0||c.length===1&&c.every(([,h])=>h===""),d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=u&&!(d&&f):o=!u||d&&f,!o){if(c.length>0){let p=c.map(([,m])=>m);if(a){let m=X(e.state.env);return{values:[p.join(m)],quoted:!0}}return{values:p,quoted:!0}}let h=e.state.env.get(l);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}else{let l=r.parameter,c=await $t(e,l),u=await ie(e,l,!1),f=u==="",d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=c&&!(d&&f):o=!c||d&&f,!o)return{values:[u],quoted:!0}}if(s.type==="AssignDefault")return null;if(o&&s.word){let l=s.word.parts,c=null,u=!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){c=d[1],u=d[2]==="*";break}}if(c){let f=Q(e,c);if(f.length>0){let h=f.map(([,p])=>p);if(u||a){let p=X(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}let d=e.state.env.get(c);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}return null}async function Ec(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,c=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]==="*",c=E.operation;break}}}if(o===-1||o===0&&o===i.parts.length-1)return null;let u="";for(let m=0;m<o;m++)u+=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=Q(e,a),h=d.map(([,m])=>m);if(d.length===0){let m=e.state.env.get(a);if(m!==void 0)h=[m];else{if(l)return{values:[u+f],quoted:!0};let E=u+f;return{values:E?[E]:[],quoted:!0}}}if(c?.type==="PatternRemoval"){let m=c,E=m.pattern?await nn(e,m.pattern,m.greedy,s,r):"";h=h.map(S=>bt(e,S,E,m.side,m.greedy))}else if(c?.type==="PatternReplacement"){let m=c,E="";if(m.pattern)for(let g of m.pattern.parts)if(g.type==="Glob")E+=oe(g.pattern,!0,e.state.shoptOptions.extglob);else if(g.type==="Literal")E+=oe(g.value,!0,e.state.shoptOptions.extglob);else if(g.type==="SingleQuoted"||g.type==="Escaped")E+=ce(g.value);else if(g.type==="DoubleQuoted"){let b=await s(e,g.parts);E+=ce(b)}else if(g.type==="ParameterExpansion"){let b=await r(e,g);E+=oe(b,!0,e.state.shoptOptions.extglob)}else{let b=await r(e,g);E+=ce(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=ge(y,m.all?"g":"");h=h.map(b=>g.replace(b,S))}catch{}}if(l){let m=X(e.state.env);return{values:[u+h.join(m)+f],quoted:!0}}return h.length===1?{values:[u+h[0]+f],quoted:!0}:{values:[u+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function bc(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 h=0;h<s.parts.length;h++){let p=s.parts[h];if(p.type==="ParameterExpansion"&&!p.operation){let m=p.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(m){i=h,o=m[1],a=m[2]==="*";break}}}if(i===-1)return null;let l="";for(let h=0;h<i;h++)l+=await r(e,s.parts[h]);let c="";for(let h=i+1;h<s.parts.length;h++)c+=await r(e,s.parts[h]);let u=Q(e,o),f=u.map(([,h])=>h);if(u.length===0){let h=e.state.env.get(o);if(h!==void 0)return{values:[l+h+c],quoted:!0};if(a)return{values:[l+c],quoted:!0};let p=l+c;return{values:p?[p]:[],quoted:!0}}if(a){let h=X(e.state.env);return{values:[l+f.join(h)+c],quoted:!0}}return f.length===1?{values:[l+f[0]+c],quoted:!0}:{values:[l+f[0],...f.slice(1,-1),f[f.length-1]+c],quoted:!0}}async function Sc(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
111
- `);let c=l.offset?await n(e,l.offset.expression):0,u=l.length?await n(e,l.length.expression):void 0,f=Q(e,o);if(f.length>e.limits.maxArrayElements)throw new $(`array transform element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let d=0;if(c<0){if(f.length>0){let p=f[f.length-1][0],E=(typeof p=="number"?p:0)+1+c;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(([p])=>typeof p=="number"&&p>=c),d<0&&(d=f.length);let h;if(u!==void 0){if(u<0)throw new le(`${o}[@]: substring expression < 0`);h=f.slice(d,d+u).map(([,p])=>p)}else h=f.slice(d).map(([,p])=>p);if(h.length===0)return{values:[],quoted:!0};if(a){let p=X(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}function Ac(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=Q(e,i);if(l.length===0){let d=e.state.env.get(i);if(d!==void 0){let h;switch(a.operator){case"a":h="";break;case"P":h=wr(e,d);break;case"Q":h=rn(d);break;default:h=d}if(M(h)>e.limits.maxStringLength)throw new $(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[h],quoted:!0}}return o?{values:[""],quoted:!0}:{values:[],quoted:!0}}let c=sn(e,i),u=[],f=0;for(let[,d]of l){let h;switch(a.operator){case"a":h=c;break;case"P":h=wr(e,d);break;case"Q":h=rn(d);break;case"u":h=d.charAt(0).toUpperCase()+d.slice(1);break;case"U":h=d.toUpperCase();break;case"L":h=d.toLowerCase();break;default:h=d}let p=M(h);if(p>e.limits.maxStringLength-f)throw new $(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u.push(h),f+=p}if(o){let d=X(e.state.env);if(Math.max(0,u.length-1)*M(d)>e.limits.maxStringLength-f)throw new $(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u.join(d)],quoted:!0}}return{values:u,quoted:!0}}function vc(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(ue(e,i)){let l=Cn(e,i);if(l?.endsWith("[@]")||l?.endsWith("[*]"))return{values:[],quoted:!0}}let o=Q(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 kc(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)||!ue(e,s))return null;let i=Cn(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=Q(e,a);if(l.length>0)return{values:l.map(([,u])=>u),quoted:!0};let c=e.state.env.get(a);return c!==void 0?{values:[c],quoted:!0}:{values:[],quoted:!0}}async function xc(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 ie(e,o.parameter),c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c){if(!a.innerOp&&(l==="@"||l==="*")){let p=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let E=1;E<=p;E++)m.push(e.state.env.get(String(E))||"");return l==="*"?{values:[m.join(X(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let u=c[1],f=c[2]==="*",d=Q(e,u);if(a.innerOp){if(a.innerOp.type==="Substring")return Mh(e,d,u,f,a.innerOp);if(a.innerOp.type==="DefaultValue"||a.innerOp.type==="UseAlternative"||a.innerOp.type==="AssignDefault"||a.innerOp.type==="ErrorIfUnset")return Bh(e,d,u,f,a.innerOp,s);if(a.innerOp.type==="Transform"&&a.innerOp.operator==="a"){let m=sn(e,u),E=d.map(()=>m);return f?{values:[E.join(X(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let p=[];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);p.push(y)}finally{S!==void 0?e.state.env.set("_indirect_elem_",S):e.state.env.delete("_indirect_elem_")}}return f?{values:[p.join(X(e.state.env))],quoted:!0}:{values:p,quoted:!0}}if(d.length>0){let p=d.map(([,m])=>m);return f?{values:[p.join(X(e.state.env))],quoted:!0}:{values:p,quoted:!0}}let h=e.state.env.get(u);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}async function Mh(e,t,n,r,s){let i=s.offset?await J(e,s.offset.expression):0,o=s.length?await J(e,s.length.expression):void 0,a=0;if(i<0){if(t.length>0){let u=t[t.length-1][0],d=(typeof u=="number"?u:0)+1+i;if(d<0)return{values:[],quoted:!0};if(a=t.findIndex(([h])=>typeof h=="number"&&h>=d),a<0)return{values:[],quoted:!0}}}else if(a=t.findIndex(([u])=>typeof u=="number"&&u>=i),a<0)return{values:[],quoted:!0};let l;if(o!==void 0){if(o<0)throw new le(`${n}[@]: substring expression < 0`);l=t.slice(a,a+o)}else l=t.slice(a);let c=l.map(([,u])=>u);return r?{values:[c.join(X(e.state.env))],quoted:!0}:{values:c,quoted:!0}}async function Bh(e,t,n,r,s,i){let o=s.checkEmpty??!1,a=t.map(([,u])=>u),l=t.length===0,c=t.length===0;if(s.type==="UseAlternative")return!c&&!(o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(s.type==="DefaultValue")return(c||o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:r?{values:[a.join(X(e.state.env))],quoted:!0}:{values:a,quoted:!0};if(s.type==="AssignDefault"){if((c||o&&l)&&s.word){let f=await i(e,s.word.parts,!0);return G(e,n,0,f),{values:[f],quoted:!0}}return r?{values:[a.join(X(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return r?{values:[a.join(X(e.state.env))],quoted:!0}:{values:a,quoted:!0}}async function Pc(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 ie(e,o.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!l)return null;let c=await $t(e,n.parameter),u=await ie(e,n.parameter)==="",f=r.checkEmpty??!1,d;if(r.type==="UseAlternative"?d=c&&!(f&&u):d=!c||f&&u,d){let h=l[1],p=l[2]==="*",m=Q(e,h);if(m.length>0){let S=m.map(([,y])=>y);return p?{values:[S.join(X(e.state.env))],quoted:!0}:{values:S,quoted:!0}}let E=e.state.env.get(h);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function $c(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],c=(await ie(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c)return null;let u=await ie(e,n.parameter),f=await $t(e,n.parameter),d=u==="",h=s.checkEmpty??!1,p;if(s.type==="UseAlternative"?p=f&&!(h&&d):p=!f||h&&d,p){let m=c[1],E=c[2]==="*",S=Q(e,m);if(S.length>0){let g=S.map(([,b])=>b);return E?{values:[g.join(X(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 Cc(e){let t=Number.parseInt(e.state.env.get("#")||"0",10);if(t>e.limits.maxArrayElements)throw new $(`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=M(i);if(o>e.limits.maxStringLength-r)throw new $(`positional parameter string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n.push(i),r+=o}return n}function fs(e,t,n){if(M(t)>n-M(e))throw new $(`positional expansion string limit exceeded (${n} bytes)`,"string_length");return e+t}function Xi(e,t,n,r){if(e.length>=r.limits.maxArrayElements)throw new $(`positional expansion element limit exceeded (${r.limits.maxArrayElements})`,"array_elements");let s=M(t);if(s>r.limits.maxStringLength-n.value)throw new $(`positional expansion string limit exceeded (${r.limits.maxStringLength} bytes)`,"string_length");e.push(t),n.value+=s}async function Nc(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,c=l.offset?await n(e,l.offset.expression):0,u=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 h=e.state.env.get("0")||"bash",p;if(c<=0){let y=[h,...d],g=y.length+c;if(g<0)p=[];else{let b=c<0?g:0;if(u!==void 0){let v=u<0?y.length+u:b+u;p=y.slice(b,Math.max(b,v))}else p=y.slice(b)}}else{let y=c-1;if(y>=d.length)p=[];else if(u!==void 0){let g=u<0?d.length+u:y+u;p=d.slice(y,Math.max(y,g))}else p=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(p.length===0){let y=m+E;return{values:y?[y]:[],quoted:!0}}if(o){let y=X(e.state.env);return{values:[m+p.join(y)+E],quoted:!0}}return p.length===1?{values:[m+p[0]+E],quoted:!0}:{values:[m+p[0],...p.slice(1,-1),p[p.length-1]+E],quoted:!0}}async function Rc(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,c=Cc(e),u="";for(let y=0;y<i;y++)u=fs(u,await n(e,s.parts[y]),e.limits.maxStringLength);let f="";for(let y=i+1;y<s.parts.length;y++)f=fs(f,await n(e,s.parts[y]),e.limits.maxStringLength);if(c.length===0){let y=u+f;return{values:y?[y]:[],quoted:!0}}let d="";if(l.pattern)for(let y of l.pattern.parts)if(y.type==="Glob")d+=oe(y.pattern,!0,e.state.shoptOptions.extglob);else if(y.type==="Literal")d+=oe(y.value,!0,e.state.shoptOptions.extglob);else if(y.type==="SingleQuoted"||y.type==="Escaped")d+=ce(y.value);else if(y.type==="DoubleQuoted"){let g=await r(e,y.parts);d+=ce(g)}else if(y.type==="ParameterExpansion"){let g=await n(e,y);d+=oe(g,!0,e.state.shoptOptions.extglob)}else{let g=await n(e,y);d+=ce(g)}let h=l.replacement?await r(e,l.replacement.parts):"",p=d;l.anchor==="start"?p=`^${d}`:l.anchor==="end"&&(p=`${d}$`);let m=[],E={value:0};try{let y=ge(p,l.all?"g":"");for(let g of c){let b=0;y.lastIndex=0;for(let x=y.exec(g);x&&(b++,!!l.all);x=y.exec(g))x[0].length===0&&y.lastIndex++;let v=M(g),k=M(h),A=0,P=/\$(?:\$|&|\d+|<[^>]+>|`|')/g;for(;P.exec(h)!==null;)A++;if(v+b*k+b*A*v>e.limits.maxStringLength-E.value)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");Xi(m,y.replace(g,h),E,e)}}catch(y){if(y instanceof $)throw y;for(let g of c)Xi(m,g,E,e)}if(o){let y=X(e.state.env);if(E.value+Math.max(0,m.length-1)*M(y)+M(u)+M(f)>e.limits.maxStringLength)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+m.join(y)+f],quoted:!0}}if(M(u)+E.value+M(f)>e.limits.maxStringLength)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return m.length===1?{values:[u+m[0]+f],quoted:!0}:{values:[u+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function Oc(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,c=Cc(e),u="";for(let S=0;S<i;S++)u=fs(u,await n(e,s.parts[S]),e.limits.maxStringLength);let f="";for(let S=i+1;S<s.parts.length;S++)f=fs(f,await n(e,s.parts[S]),e.limits.maxStringLength);if(c.length===0){let S=u+f;return{values:S?[S]:[],quoted:!0}}let d="",h=e.state.shoptOptions.extglob;if(l.pattern)for(let S of l.pattern.parts)if(S.type==="Glob")d+=oe(S.pattern,l.greedy,h);else if(S.type==="Literal")d+=oe(S.value,l.greedy,h);else if(S.type==="SingleQuoted"||S.type==="Escaped")d+=ce(S.value);else if(S.type==="DoubleQuoted"){let y=await r(e,S.parts);d+=ce(y)}else if(S.type==="ParameterExpansion"){let y=await n(e,S);d+=oe(y,l.greedy,h)}else{let y=await n(e,S);d+=ce(y)}let p=[],m={value:0};for(let S of c)Xi(p,bt(e,S,d,l.side,l.greedy),m,e);if(o){let S=X(e.state.env);if(m.value+Math.max(0,p.length-1)*M(S)+M(u)+M(f)>e.limits.maxStringLength)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+p.join(S)+f],quoted:!0}}if(M(u)+m.value+M(f)>e.limits.maxStringLength)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return p.length===1?{values:[u+p[0]+f],quoted:!0}:{values:[u+p[0],...p.slice(1,-1),p[p.length-1]+f],quoted:!0}}async function Dc(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 h=r.parts[d];if(h.type==="ParameterExpansion"&&(h.parameter==="@"||h.parameter==="*")){s=d,i=h.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 c="";for(let d=s+1;d<r.parts.length;d++)c+=await n(e,r.parts[d]);if(a===0){if(i)return{values:[l+c],quoted:!0};let d=l+c;return{values:d?[d]:[],quoted:!0}}let u=[];for(let d=1;d<=a;d++)u.push(e.state.env.get(String(d))||"");if(i){let d=X(e.state.env);return{values:[l+u.join(d)+c],quoted:!0}}return u.length===1?{values:[l+u[0]+c],quoted:!0}:{values:[l+u[0],...u.slice(1,-1),u[u.length-1]+c],quoted:!0}}function Nt(e,t,n,r){if(t.length>=e.limits.maxArrayElements)throw new $(`unquoted expansion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let s=M(n);if(s>e.limits.maxStringLength-r.value)throw new $(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");t.push(n),r.value+=s}function Yi(e,t,n,r){let s=M(n),i=Math.max(0,t.length-1);if(s>0&&i>Math.floor((e.limits.maxStringLength-r)/s))throw new $(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return t.join(n)}function Wh(e){return new tn(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 ds(e,t){if(e.state.options.noglob)return t;let n=Wh(e),r=[];for(let s of t)if(Ct(s,e.state.shoptOptions.extglob)){let i=await n.expand(s);if(i.length>0)De(r,i,e.limits.maxArrayElements,"unquoted glob expansion");else{if(n.hasFailglob())throw new jt(s);n.hasNullglob()||r.push(s)}}else r.push(s);return r}async function Ic(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 k=v.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(k){s=b,i=k[1],o=k[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,c=Q(e,i),u=c.map(([,b])=>b);if(c.length===0){let b=e.state.env.get(i);b!==void 0&&(u=[b])}if(u.length===0)return{values:[],quoted:!1};let f="";if(l.pattern)for(let b of l.pattern.parts)if(b.type==="Glob")f+=oe(b.pattern,!0,e.state.shoptOptions.extglob);else if(b.type==="Literal")f+=oe(b.value,!0,e.state.shoptOptions.extglob);else if(b.type==="SingleQuoted"||b.type==="Escaped")f+=ce(b.value);else if(b.type==="DoubleQuoted"){let v=await n(e,b.parts);f+=ce(v)}else if(b.type==="ParameterExpansion"){let v=await r(e,b);f+=oe(v,!0,e.state.shoptOptions.extglob)}else{let v=await r(e,b);f+=ce(v)}let d=l.replacement?await n(e,l.replacement.parts):"",h=f;l.anchor==="start"?h=`^${f}`:l.anchor==="end"&&(h=`${f}$`);let p=[],m={value:0};try{let b=ge(h,l.all?"g":"");for(let v of u)Nt(e,p,as(e,v,b,d,l.all),m)}catch(b){if(b instanceof $)throw b;for(let v of u)Nt(e,p,v,m)}let E=ke(e.state.env),S=Oe(e.state.env);if(o){let b=X(e.state.env),v=Yi(e,p,b,m.value);return S?{values:v?[v]:[],quoted:!1}:{values:de(v,E,e.limits.maxArrayElements),quoted:!1}}if(S)return{values:p,quoted:!1};let y=[],g={value:0};for(let b of p)if(b==="")Nt(e,y,"",g);else for(let v of de(b,E,e.limits.maxArrayElements))Nt(e,y,v,g);return{values:y,quoted:!1}}async function _c(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,c=Q(e,i),u=c.map(([,y])=>y);if(c.length===0){let y=e.state.env.get(i);y!==void 0&&(u=[y])}if(u.length===0)return{values:[],quoted:!1};let f=l.pattern?await nn(e,l.pattern,l.greedy,n,r):"",d=[],h={value:0};for(let y of u)Nt(e,d,bt(e,y,f,l.side,l.greedy),h);let p=ke(e.state.env),m=Oe(e.state.env);if(o){let y=X(e.state.env),g=Yi(e,d,y,h.value);return m?{values:g?[g]:[],quoted:!1}:{values:de(g,p,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[],S={value:0};for(let y of d)if(y==="")Nt(e,E,"",S);else for(let g of de(y,p,e.limits.maxArrayElements))Nt(e,E,g,S);return{values:E,quoted:!1}}async function Tc(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),c=[];for(let y=1;y<=l;y++)c.push(e.state.env.get(String(y))||"");if(c.length===0)return{values:[],quoted:!1};let u="",f=e.state.shoptOptions.extglob;if(a.pattern)for(let y of a.pattern.parts)if(y.type==="Glob")u+=oe(y.pattern,a.greedy,f);else if(y.type==="Literal")u+=oe(y.value,a.greedy,f);else if(y.type==="SingleQuoted"||y.type==="Escaped")u+=ce(y.value);else if(y.type==="DoubleQuoted"){let g=await n(e,y.parts);u+=ce(g)}else if(y.type==="ParameterExpansion"){let g=await r(e,y);u+=oe(g,a.greedy,f)}else{let g=await r(e,y);u+=ce(g)}let d=[],h={value:0};for(let y of c)Nt(e,d,bt(e,y,u,a.side,a.greedy),h);let p=ke(e.state.env),m=Oe(e.state.env);if(i){let y=X(e.state.env),g=Yi(e,d,y,h.value);return m?{values:g?[g]:[],quoted:!1}:{values:de(g,p,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[],S={value:0};for(let y of d)if(y==="")Nt(e,E,"",S);else for(let g of de(y,p,e.limits.maxArrayElements))Nt(e,E,g,S);return{values:E,quoted:!1}}async function Lc(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,c=a.length?await n(e,a.length.expression):void 0,u=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let g=1;g<=u;g++)f.push(e.state.env.get(String(g))||"");let d=e.state.env.get("0")||"bash",h;if(l<=0){let g=[d,...f],b=g.length+l;if(b<0)h=[];else{let v=l<0?b:0;if(c!==void 0){let k=c<0?g.length+c:v+c;h=g.slice(v,Math.max(v,k))}else h=g.slice(v)}}else{let g=l-1;if(g>=f.length)h=[];else if(c!==void 0){let b=c<0?f.length+c:g+c;h=f.slice(g,Math.max(g,b))}else h=f.slice(g)}let p="";for(let g=0;g<s;g++)p+=await r(e,t[g]);let m="";for(let g=s+1;g<t.length;g++)m+=await r(e,t[g]);let E=ke(e.state.env),S=Oe(e.state.env);if(h.length===0){let g=p+m;return g?S?{values:[g],quoted:!1}:{values:de(g,E,e.limits.maxArrayElements),quoted:!1}:{values:[],quoted:!1}}let y;if(i){let g=X(e.state.env),b=p+h.join(g)+m;S?y=b?[b]:[]:y=de(b,E,e.limits.maxArrayElements)}else if(S)h.length===1?y=[p+h[0]+m]:y=[p+h[0],...h.slice(1,-1),h[h.length-1]+m];else{y=[];for(let g=0;g<h.length;g++){let b=h[g];if(g===0&&(b=p+b),g===h.length-1&&(b=b+m),b==="")y.push("");else{let v=de(b,E,e.limits.maxArrayElements);De(y,v,e.limits.maxArrayElements,"unquoted expansion")}}}return{values:await ds(e,y),quoted:!1}}async function Fc(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 c=1;c<=r;c++)s.push(e.state.env.get(String(c))||"");let i=ke(e.state.env),o=Oe(e.state.env),a=ns(e.state.env),l;if(n)if(o)l=s.filter(c=>c!=="");else{let c=X(e.state.env),u=s.join(c);l=de(u,i,e.limits.maxArrayElements)}else if(o)l=s.filter(c=>c!=="");else if(a){l=[];for(let c of s){if(c==="")continue;let u=de(c,i,e.limits.maxArrayElements);De(l,u,e.limits.maxArrayElements,"unquoted expansion")}}else{l=[];for(let c of s)if(c==="")l.push("");else{let u=de(c,i,e.limits.maxArrayElements);De(l,u,e.limits.maxArrayElements,"unquoted expansion")}for(;l.length>0&&l[l.length-1]==="";)l.pop()}return{values:await ds(e,l),quoted:!1}}async function Mc(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=Q(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=ke(e.state.env),l=Oe(e.state.env),c=ns(e.state.env),u;if(s)if(l)u=o.filter(f=>f!=="");else{let f=X(e.state.env),d=o.join(f);u=de(d,a,e.limits.maxArrayElements)}else if(l)u=o.filter(f=>f!=="");else if(c){u=[];for(let f of o){if(f==="")continue;let d=de(f,a,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}}else{u=[];for(let f of o)if(f==="")u.push("");else{let d=de(f,a,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}for(;u.length>0&&u[u.length-1]==="";)u.pop()}return{values:await ds(e,u),quoted:!1}}function Bc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let n=t[0].operation,r=zn(e,n.prefix);if(r.length===0)return{values:[],quoted:!1};let s=ke(e.state.env),i=Oe(e.state.env),o;if(n.star)if(i)o=r;else{let a=X(e.state.env),l=r.join(a);o=de(l,s,e.limits.maxArrayElements)}else if(i)o=r;else{o=[];for(let a of r){let l=de(a,s,e.limits.maxArrayElements);De(o,l,e.limits.maxArrayElements,"unquoted expansion")}}return{values:o,quoted:!1}}function Wc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let n=t[0].operation,s=Q(e,n.array).map(([l])=>String(l));if(s.length===0)return{values:[],quoted:!1};let i=ke(e.state.env),o=Oe(e.state.env),a;if(n.star)if(o)a=s;else{let l=X(e.state.env),c=s.join(l);a=de(c,i,e.limits.maxArrayElements)}else if(o)a=s;else{a=[];for(let l of s){let c=de(l,i,e.limits.maxArrayElements);De(a,c,e.limits.maxArrayElements,"unquoted expansion")}}return{values:a,quoted:!1}}async function Vc(e,t,n){let r=-1;for(let d=0;d<t.length;d++){let h=t[d];if(h.type==="ParameterExpansion"&&(h.parameter==="@"||h.parameter==="*")&&!h.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=ke(e.state.env),c=Oe(e.state.env),u=ns(e.state.env);if(s===0){let d=o+a;return{values:d?[d]:[],quoted:!1}}let f;{let d=[];for(let h=0;h<i.length;h++){let p=i[h];h===0&&(p=o+p),h===i.length-1&&(p=p+a),d.push(p)}if(c)f=d.filter(h=>h!=="");else if(u){f=[];for(let h of d){if(h==="")continue;let p=de(h,l,e.limits.maxArrayElements);De(f,p,e.limits.maxArrayElements,"unquoted expansion")}}else{f=[];for(let h of d)if(h==="")f.push("");else{let p=de(h,l,e.limits.maxArrayElements);De(f,p,e.limits.maxArrayElements,"unquoted expansion")}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await ds(e,f),quoted:!1}}async function jc(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:c,hasIndirection:u}=yr(r),d=n.hasBraceExpansion(r)?await n.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return Vh(e,d,s);let h=await zh(e,r,a,c,u,n);if(h!==null)return h;let p=await jh(e,r,n);if(p!==null)return p;let m=await qh(e,r,n);if(m!==null)return m;let E=await Hh(e,r,n.expandPart);if(E!==null)return Uc(e,E);if((i||o||l)&&!Oe(e.state.env)){let y=ke(e.state.env),g=n.buildIfsCharClassPattern(y),b=await n.smartWordSplit(e,r,y,g,n.expandPart);return Uc(e,b)}let S=await n.expandWordAsync(e,t);return Zh(e,t,r,S,s,n.expandWordForGlobbing)}async function Vh(e,t,n){let r=[];for(let s of t)if(!(!n&&s===""))if(!n&&!e.state.options.noglob&&Ct(s,e.state.shoptOptions.extglob)){let i=await hs(e,s);De(r,i,e.limits.maxArrayElements,"brace/glob expansion")}else r.push(s);return{values:r,quoted:!1}}async function zh(e,t,n,r,s,i){if(n){let o=vc(e,t);if(o!==null)return o}{let o=kc(e,t);if(o!==null)return o}{let o=await wc(e,t);if(o!==null)return o}{let o=await Ec(e,t,n,i.expandPart,i.expandWordPartsAsync);if(o!==null)return o}{let o=await bc(e,t,n,i.expandPart);if(o!==null)return o}{let o=await Sc(e,t,i.evaluateArithmetic);if(o!==null)return o}{let o=Ac(e,t);if(o!==null)return o}{let o=await yc(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}{let o=await gc(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let o=Uh(e,t);if(o!==null)return o}{let o=await xc(e,t,s,i.expandParameterAsync,i.expandWordPartsAsync);if(o!==null)return o}{let o=await Pc(e,t);if(o!==null)return o}{let o=await $c(e,t);if(o!==null)return o}return null}function Uh(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=zn(e,r.prefix);return r.star?{values:[s.join(X(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=Q(e,r.array).map(([o])=>String(o));return r.star?{values:[i.join(X(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function jh(e,t,n){{let r=await Nc(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await Rc(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Oc(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Dc(e,t,n.expandPart);if(r!==null)return r}return null}async function qh(e,t,n){{let r=await Ic(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await _c(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Tc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Lc(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await Fc(e,t);if(r!==null)return r}{let r=await Mc(e,t);if(r!==null)return r}{let r=Bc(e,t);if(r!==null)return r}{let r=Wc(e,t);if(r!==null)return r}{let r=await Vc(e,t,n.expandPart);if(r!==null)return r}return null}function zc(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 Gh(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=Q(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=X(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 Hh(e,t,n){if(t.length<2)return null;let r=!1;for(let l of t)if(zc(l)){r=!0;break}if(!r)return null;let s=ke(e.state.env),i=Oe(e.state.env),o=[];for(let l of t){let c=zc(l);if(c&&l.type==="DoubleQuoted"){let u=await Gh(e,l,c,n);o.push(u)}else if(l.type==="DoubleQuoted"||l.type==="SingleQuoted"){let u=await n(e,l);o.push([u])}else if(l.type==="Literal")o.push([l.value]);else if(l.type==="ParameterExpansion"){let u=await n(e,l);if(i)o.push(u?[u]:[]);else{let f=de(u,s,e.limits.maxArrayElements);o.push(f)}}else{let u=await n(e,l);if(i)o.push(u?[u]:[]);else{let f=de(u,s,e.limits.maxArrayElements);o.push(f)}}}let a=[];for(let l of o)if(l.length!==0)if(a.length===0)De(a,l,e.limits.maxArrayElements,"word expansion");else{let c=a.length-1;a[c]=a[c]+l[0];for(let u=1;u<l.length;u++)a.push(l[u])}return a}async function Uc(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let n=[];for(let r of t)if(Ct(r,e.state.shoptOptions.extglob)){let s=await hs(e,r);De(n,s,e.limits.maxArrayElements,"glob expansion")}else n.push(r);return{values:n,quoted:!1}}async function hs(e,t){let n=new tn(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 jt(t);return n.hasNullglob()?[]:[t]}async function Zh(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(Ct(a,e.state.shoptOptions.extglob)){let c=await hs(e,a);if(c.length>0&&c[0]!==a)return{values:c,quoted:!1};if(c.length===0)return{values:[],quoted:!1}}let l=Gi(r);if(!Oe(e.state.env)){let c=ke(e.state.env);return{values:de(l,c,e.limits.maxArrayElements),quoted:!1}}return{values:[l],quoted:!1}}if(!s&&!e.state.options.noglob&&Ct(r,e.state.shoptOptions.extglob)){let a=await i(e,t);if(Ct(a,e.state.shoptOptions.extglob)){let l=await hs(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=Gi(r);if(!Oe(e.state.env)){let l=ke(e.state.env);return{values:de(a,l,e.limits.maxArrayElements),quoted:!1}}return{values:[a],quoted:!1}}return{values:[r],quoted:s}}function Fe(e,t,n){if(t.length>=e.limits.maxArrayElements)throw new $(`word splitting element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");t.push(n)}async function Gc(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 $t(e,t.parameter),o=await ie(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"&&Hi(t.parameter),r.parts):null}function Qh(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(n=>n.type==="Literal"):!1}async function Kh(e,t){if(t.type!=="ParameterExpansion")return null;let n=await Gc(e,t);if(!n||n.length<=1)return null;let r=n.some(i=>Qh(i)),s=n.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&s?n:null}function Xh(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?Mi(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&jl(e))}async function Hc(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let d=t[0],h=await Gc(e,d);if(h&&h.length>0&&h.length>1&&h.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&h.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return qc(e,h,n,r,s)}let i=[],o=!1;for(let d of t){let h=Xh(d),p=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=h?await Kh(e,d):null,E=await s(e,d);i.push({value:E,isSplittable:h,isQuoted:p,mixedDefaultParts:m??void 0}),h&&(o=!0)}if(!o){let d=i.map(h=>h.value).join("");return d?[d]:[]}let a=[],l="",c=!1,u=!1,f=!1;for(let d of i)if(!d.isSplittable)u?d.isQuoted&&d.value===""?(l!==""&&Fe(e,a,l),Fe(e,a,""),c=!0,l="",u=!1,f=!0):d.value!==""?(l!==""&&Fe(e,a,l),l=d.value,u=!1,f=!1):(l+=d.value,f=!1):(l+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let h=await qc(e,d.mixedDefaultParts,n,r,s);if(h.length!==0)if(h.length===1)l+=h[0],c=!0;else{l+=h[0],Fe(e,a,l),c=!0;for(let p=1;p<h.length-1;p++)Fe(e,a,h[p]);l=h[h.length-1]}u=!1,f=!1}else{let{words:h,hadLeadingDelimiter:p,hadTrailingDelimiter:m}=rs(d.value,n,e.limits.maxArrayElements);if(f&&p&&l===""&&(Fe(e,a,""),c=!0),h.length===0)m&&(u=!0);else if(h.length===1)l+=h[0],c=!0,u=m;else{l+=h[0],Fe(e,a,l),c=!0;for(let E=1;E<h.length-1;E++)Fe(e,a,h[E]);l=h[h.length-1],u=m}f=!1}return l!==""?Fe(e,a,l):a.length===0&&c&&Fe(e,a,""),a}function Yh(e,t){return e.length>0&&t.includes(e[0])}async function qc(e,t,n,r,s){let i=[];for(let u of t){let d=!(u.type==="DoubleQuoted"||u.type==="SingleQuoted"),h=await s(e,u);i.push({value:h,isSplittable:d})}let o=[],a="",l=!1,c=!1;for(let u of i)if(!u.isSplittable)c&&u.value!==""?(a!==""&&Fe(e,o,a),a=u.value,c=!1):a+=u.value;else{Yh(u.value,n)&&a!==""&&(Fe(e,o,a),a="",l=!0);let{words:d,hadTrailingDelimiter:h}=rs(u.value,n,e.limits.maxArrayElements);if(d.length===0)h&&(c=!0);else if(d.length===1)a+=d[0],l=!0,c=h;else{a+=d[0],Fe(e,o,a),l=!0;for(let p=1;p<d.length-1;p++)Fe(e,o,d[p]);a=d[d.length-1],c=h}}return a!==""?Fe(e,o,a):o.length===0&&l&&Fe(e,o,""),o}function Zc(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Qc(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}var ps="/dev/fd",Xc=63,Jh=10,Kc=Xc-Jh+1,Ji=class extends gt{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} '${ps}${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 ep(e){let t=new Ji(n=>Yc(e).some(r=>r.path===`${ps}${n}`));e.fs=new Kt({base:e.fs,mounts:[{mountPoint:ps,filesystem:t}]}),e.state.processSubstitutionFsMounted=!0}async function tp(e,t,n){try{await e.fs.writeFile(t,n,"binary");return}catch(r){if(e.state.processSubstitutionFsMounted)throw r;ep(e)}await e.fs.writeFile(t,n,"binary")}async function np(e,t){try{await e.fs.rm(t,{force:!0})}catch{}}function Yc(e){let t=e.state.processSubstitutions;if(t)return t;let n=[];return e.state.processSubstitutions=n,n}async function Jc(e,t,n){let r=e.substitutionDepth??0,s=e.limits.maxSubstitutionDepth;if(r>=s)throw new $(`Process substitution nesting limit exceeded (${s})`,"substitution_depth");let i=e.substitutionDepth,o=new Map(e.state.env),a=at(e.state.arrays),l=e.state.cwd,c=e.state.bashPid,u=e.state.suppressVerbose,f=e.state.groupStdin,d=e.state.lastExitCode,h=e.state.env.get("?"),p=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 $)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=c,e.state.suppressVerbose=u,e.state.groupStdin=f,e.state.lastExitCode=d,e.state.lastSubstitutionExitCode=p,h!==void 0?e.state.env.set("?",h):e.state.env.delete("?")}return m}async function eu(e,t){let n=Yc(e);if(n.length>=Kc)throw new $(`Process substitution limit exceeded (${Kc} concurrent)`,"file_descriptors");let r="";if(t.direction==="input"){let o=await Jc(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 $(`process substitution: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")}let s=Xc-n.length,i=`${ps}/${s}`;n.push({fd:s,path:i,direction:t.direction,body:t.body});try{await tp(e,i,r)}catch(o){throw n.pop(),o}return i}function tu(e){return e.state.processSubstitutions?.length??0}var rp={stdout:"",stderr:""};async function eo(e,t){let n=e.state.processSubstitutions;if(!n||n.length<=t)return rp;let r="",s="";for(;n.length>t;){let i=n[n.length-1],o="";if(i.direction==="output")try{o=await In(e.fs,i.path)}catch{}if(await np(e,i.path),n.pop(),i.direction==="output"){let a=await Jc(e,i.body,o);r+=_t(a),s+=a.stderr}}return{stdout:r,stderr:s}}function ln(e,t,n){if(e.length>t)throw new $(`${n}: string length limit exceeded (${t} bytes)`,"string_length")}async function At(e,t,n=!1){let r=[],s=0;for(let i of t){let o=await tt(e,i,n);if(s+=M(o),s>e.limits.maxStringLength)throw new $(`parameter word string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");r.push(o)}return r.join("")}function sp(e){return Qc(e)}function ru(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!sp(t))return!1;return!0}function ip(e,t,n=!1){let r=Zc(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 Qi(e,t.pattern);default:return null}}async function se(e,t){return no(e,t)}async function su(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped")n.push(Vn(r.value));else if(r.type==="SingleQuoted")n.push(r.value);else if(r.type==="DoubleQuoted"){let s=await At(e,r.parts);n.push(s)}else if(r.type==="TildeExpansion"){let s=await tt(e,r);n.push(Vn(s))}else n.push(await tt(e,r));return n.join("")}async function iu(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(et(r.value));else if(r.type==="DoubleQuoted"){let s=await At(e,r.parts);n.push(et(s))}else n.push(await tt(e,r));return n.join("")}async function ou(e,t){let n=[];for(let r of t.parts)if(r.type==="SingleQuoted")n.push(et(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 At(e,r.parts);n.push(et(s))}else r.type==="Glob"?hc(r.pattern)?n.push(await mc(e,r.pattern)):n.push(Qi(e,r.pattern)):r.type==="Literal"?n.push(r.value):n.push(await tt(e,r));return n.join("")}function ys(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&ys(t.parts))return!0;return!1}var nu=1e5;async function au(e,t,n={count:0}){let r=()=>{n.count++,e.executionScope.consumeLimited("brace_operations",1,Math.min(nu,e.limits.maxBraceExpansionResults),"brace expansion")},s=(o,a)=>{if(o.length>=e.limits.maxBraceExpansionResults)throw new $(`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,c="";for(let d of o.items)if(d.type==="Range"){let h=qi(d.start,d.end,d.step,d.startStr,d.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(h.expanded)for(let p of h.expanded)s(a,p);else{l=!0,c=h.literal;break}}else{let h=await au(e,d.word.parts,n);for(let p of h){let m=[];for(let E of p)typeof E=="string"?m.push(E):m.push(await tt(e,E));s(a,m.join(""))}}if(l){for(let d of i)r(),d.push(c);continue}if(i.length*a.length>e.limits.maxBraceExpansionResults||n.count>nu)throw new $(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");let f=[];for(let d of i)for(let h of a){if(f.length>=e.limits.maxBraceExpansionResults)throw new $(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),f.push([...d,h])}i=f}else for(let a of i)r(),a.push(o);return i}async function lu(e,t){let n=t.parts;if(!ys(n))return[await se(e,t)];let r=await au(e,n),s=[];for(let i of r){let o=[];for(let a of i)typeof a=="string"?o.push(a):o.push(await tt(e,a));s.push(Ki(e,o.join("")))}return s}function op(){return{expandWordAsync:no,expandWordForGlobbing:ou,expandWordWithBracesAsync:lu,expandWordPartsAsync:At,expandPart:tt,expandParameterAsync:ms,hasBraceExpansion:ys,evaluateArithmetic:J,buildIfsCharClassPattern:ql,smartWordSplit:Hc}}async function vt(e,t){return jc(e,t,op())}function ap(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function to(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 cu(e,t){if(to(e,t))return{error:`bash: $@: ambiguous redirect
112
- `};let n=t.parts,{hasQuoted:r}=yr(n);if(ys(n)&&(await lu(e,t)).length>1)return{error:`bash: ${n.map(h=>h.type==="Literal"?h.value:h.type==="BraceExpansion"?`{${h.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
113
- `};let s=await no(e,t),{hasParamExpansion:i,hasCommandSub:o}=yr(n);if((i||o)&&!r&&!Oe(e.state.env)){let f=ke(e.state.env);if(de(s,f,e.limits.maxArrayElements).length>1)return{error:`bash: $${ap(n)}: ambiguous redirect
114
- `}}if(r||e.state.options.noglob||n.some(f=>f.type==="ProcessSubstitution"))return{target:s};let l=await ou(e,t);if(!Ct(l,e.state.shoptOptions.extglob))return{target:s};let c=new tn(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")}),u=await c.expand(l);return u.length===0?c.hasFailglob()?{error:`bash: no match: ${s}
105
+ `;throw new G(1,"",r)}return null}function bt(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 ds(e,t){e.state.exportedVars?.delete(t)}function sn(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let n="",r=ke(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"),ue(e,t)&&(n+="n"),We(e,t)&&(n+="r"),e.state.exportedVars?.has(t)&&(n+="x"),n}async function sc(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 Qi(e){if(/^(?:\d+|[@*#?$!-])$/.test(e))throw new G(1,"",`bash: $${e}: cannot assign in this way
106
+ `)}async function ic(e,t,n,r,s){e.coverage?.hit("bash:expansion:assign_default");let i=r.isUnset||n.checkEmpty&&r.isEmpty;if(i&&Qi(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,c]=a;if(c==="@"||c==="*")throw new G(1,"",`${e.state.expansionStderr||""}bash: ${t}: bad array subscript
107
+ `);let u;if(/^\d+$/.test(c))u=Number.parseInt(c,10);else{try{let f=new Q,d=re(f,c);u=await J(e,d.expression)}catch{let f=e.state.env.get(c);u=f?Number.parseInt(f,10):0}Number.isNaN(u)&&(u=0)}H(e,l,u,o)}else e.state.env.set(t,o);return o}return r.effectiveValue}async function oc(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 G(1,"",`bash: ${o}
108
+ `)}return r.effectiveValue}async function ac(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 lc(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_removal");let i=n.pattern?await nn(e,n.pattern,n.greedy,r,s):"";return Et(e,t,i,n.side,n.greedy)}async function cc(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",o=e.state.shoptOptions.extglob;if(n.pattern)for(let c of n.pattern.parts)if(c.type==="Glob")i+=oe(c.pattern,!0,o);else if(c.type==="Literal")i+=oe(c.value,!0,o);else if(c.type==="SingleQuoted"||c.type==="Escaped")i+=ce(c.value);else if(c.type==="DoubleQuoted"){let u=await r(e,c.parts);i+=ce(u)}else if(c.type==="ParameterExpansion"){let u=await s(e,c);i+=oe(u,!0,o)}else{let u=await s(e,c);i+=ce(u)}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 c=ge(i,l);return fs(e,t,c,a,n.all)}catch(c){if(c instanceof C)throw c;return t}}function Ki(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=K(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)&&wt(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=ae(e,t,0)||"";return String([...s].length)}return String([...n].length)}async function uc(e,t,n,r){e.coverage?.hit("bash:expansion:substring");let s=await J(e,r.offset.expression),i=r.length?await J(e,r.length.expression):void 0;if(t==="@"||t==="*"){let c=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let p=1;p<=c;p++)u.push(e.state.env.get(String(p))||"");let f=e.state.env.get("0")||"bash",d,h;if(s<=0)if(d=[f,...u],s<0){if(h=d.length+s,h<0)return""}else h=0;else d=u,h=s-1;if(h<0||h>=d.length)return"";if(i!==void 0){let p=i<0?d.length+i:h+i;return d.slice(h,Math.max(h,p)).join(" ")}return d.slice(h).join(" ")}let o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(o){let c=o[1];if(e.state.associativeArrays?.has(c))throw new G(1,"",`bash: \${${c}[@]: 0: 3}: bad substitution
109
+ `);let u=K(e,c),f=0;if(s<0){if(u.length>0){let d=u[u.length-1][0],p=(typeof d=="number"?d:0)+1+s;if(p<0||(f=u.findIndex(([m])=>typeof m=="number"&&m>=p),f<0))return""}}else if(f=u.findIndex(([d])=>typeof d=="number"&&d>=s),f<0)return"";if(i!==void 0){if(i<0)throw new le(`${o[1]}[@]: substring expression < 0`);return u.slice(f,f+i).map(([,d])=>d).join(" ")}return u.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 c=a.length+i;return a.slice(l,Math.max(l,c)).join("")}return a.slice(l,l+i).join("")}return a.slice(l).join("")}async function fc(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+=oe(f.pattern,!0,i);else if(f.type==="Literal")o+=oe(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")o+=ce(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);o+=ce(d)}else if(f.type==="ParameterExpansion"){let d=await s(e,f);o+=oe(d,!0,i)}let a=ge(`^(?:${o})$`),l=n.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),c="",u=!1;for(let f of t)!n.all&&u?c+=f:a.test(f)?(c+=l(f),u=!0):c+=f;return c}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 dc(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 K(e,i[1]).map(([,c])=>rn(c)).join(" ");if(i&&s.operator==="a")return sn(e,i[1]);let o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(o&&s.operator==="a")return sn(e,o[1]);switch(s.operator){case"Q":return r?"":rn(n);case"P":return Er(e,n);case"a":return sn(e,t);case"A":return r?"":`${t}=${rn(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`
110
+ `;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?"":rn(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 hc(e,t,n,r,s,i,o=!1){if(e.coverage?.hit("bash:expansion:indirection"),ue(e,t))return Cn(e,t)||"";let a=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(s.innerOp?.type==="UseAlternative")return"";throw new Xe(`\${!${t}}`)}let l=n;if(a&&(l===""||l.includes(" ")))throw new Xe(`\${!${t}}`);let c=l.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(c&&c[1].includes("~"))throw new Xe(`\${!${t}}`);if(s.innerOp){let u={type:"ParameterExpansion",parameter:l,operation:s.innerOp};return i(e,u,o)}return await ie(e,l)}function pc(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=K(e,t.array).map(([s])=>String(s));return t.star?r.join(X(e.state.env)):r.join(" ")}function mc(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let n=Un(e,t.prefix);return t.star?n.join(X(e.state.env)):n.join(" ")}function yc(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=K(e,o);return l.length===0?{isEmpty:!0,effectiveValue:""}:a==="*"?{isEmpty:r?n==="":!1,effectiveValue:n}:{isEmpty:l.length===1&&l.every(([,c])=>c===""),effectiveValue:n}}return{isEmpty:n==="",effectiveValue:n}}function on(e,t){e.lastExitCode=t,e.env.set("?",String(t)),e.lastSubstitutionExitCode=t}function Wh(e){switch(e.operator){case"<":case"<&":case"<<":case"<<-":case"<<<":case"<>":return e.fd===null||e.fd===0;default:return!1}}function hs(e,t){return t.some(Wh)?0:e.lastSubstitutionExitCode??0}function gc(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 wc(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 ps(e,t){let n=new Q,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=ot(e.state.arrays),a=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let c=await e.executeScript(r),u=c.exitCode;return e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.suppressVerbose=l,on(e.state,u),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr),e.state.bashPid=s,c.stdout.replace(/\n+$/,"")}catch(c){if(e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.bashPid=s,e.state.suppressVerbose=l,c instanceof C)throw c;return c instanceof G?(on(e.state,c.exitCode),c.stdout?.replace(/\n+$/,"")??""):""}}function Xi(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+=et(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=Vh(e,a);n+=et(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 Vh(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 Ec(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+=et(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 zh(e,a);n+=et(l),r=i+1;continue}}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=wc(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await ps(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 ps(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 zh(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=wc(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await ps(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 ps(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 Yi(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 an(e,t){return t.split(":").map(n=>Yi(e,n)).join(":")}function De(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 Uh(e,t,n,r){let s="";for(let i of t.parts)if(i.type==="Glob")s+=oe(i.pattern,!0,e.state.shoptOptions.extglob);else if(i.type==="Literal")s+=oe(i.value,!0,e.state.shoptOptions.extglob);else if(i.type==="SingleQuoted"||i.type==="Escaped")s+=ce(i.value);else if(i.type==="DoubleQuoted"){let o=await n(e,i.parts);s+=ce(o)}else if(i.type==="ParameterExpansion"){let o=await r(e,i);s+=oe(o,!0,e.state.shoptOptions.extglob)}else{let o=await r(e,i);s+=ce(o)}return s}async function bc(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]==="*",c=i.operation,u=K(e,a),f=u.map(([,y])=>y);if(u.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="";c.pattern&&(d=await Uh(e,c.pattern,n,r));let h=c.replacement?await n(e,c.replacement.parts):"",p=d;c.anchor==="start"?p=`^${d}`:c.anchor==="end"&&(p=`${d}$`);let m=[];try{let y=ge(p,c.all?"g":"");for(let b of f)m.push(y.replace(b,h))}catch{m.push(...f)}if(l){let y=X(e.state.env);return{values:[m.join(y)],quoted:!0}}return{values:m,quoted:!0}}async function Sc(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]==="*",c=i.operation,u=K(e,a),f=u.map(([,p])=>p);if(u.length===0){let p=e.state.env.get(a);p!==void 0&&f.push(p)}if(f.length===0)return{values:[],quoted:!0};let d=c.pattern?await nn(e,c.pattern,c.greedy,n,r):"",h=[];for(let p of f)h.push(Et(e,p,d,c.side,c.greedy));if(l){let p=X(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}async function Ac(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 c=K(e,l),u=c.length>0||e.state.env.has(l),f=c.length===0||c.length===1&&c.every(([,h])=>h===""),d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=u&&!(d&&f):o=!u||d&&f,!o){if(c.length>0){let p=c.map(([,m])=>m);if(a){let m=X(e.state.env);return{values:[p.join(m)],quoted:!0}}return{values:p,quoted:!0}}let h=e.state.env.get(l);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}else{let l=r.parameter,c=await $t(e,l),u=await ie(e,l,!1),f=u==="",d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=c&&!(d&&f):o=!c||d&&f,!o)return{values:[u],quoted:!0}}if(s.type==="AssignDefault")return null;if(o&&s.word){let l=s.word.parts,c=null,u=!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){c=d[1],u=d[2]==="*";break}}if(c){let f=K(e,c);if(f.length>0){let h=f.map(([,p])=>p);if(u||a){let p=X(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}let d=e.state.env.get(c);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}return null}async function vc(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,c=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]==="*",c=y.operation;break}}}if(o===-1||o===0&&o===i.parts.length-1)return null;let u="";for(let m=0;m<o;m++)u+=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=K(e,a),h=d.map(([,m])=>m);if(d.length===0){let m=e.state.env.get(a);if(m!==void 0)h=[m];else{if(l)return{values:[u+f],quoted:!0};let y=u+f;return{values:y?[y]:[],quoted:!0}}}if(c?.type==="PatternRemoval"){let m=c,y=m.pattern?await nn(e,m.pattern,m.greedy,s,r):"";h=h.map(b=>Et(e,b,y,m.side,m.greedy))}else if(c?.type==="PatternReplacement"){let m=c,y="";if(m.pattern)for(let E of m.pattern.parts)if(E.type==="Glob")y+=oe(E.pattern,!0,e.state.shoptOptions.extglob);else if(E.type==="Literal")y+=oe(E.value,!0,e.state.shoptOptions.extglob);else if(E.type==="SingleQuoted"||E.type==="Escaped")y+=ce(E.value);else if(E.type==="DoubleQuoted"){let S=await s(e,E.parts);y+=ce(S)}else if(E.type==="ParameterExpansion"){let S=await r(e,E);y+=oe(S,!0,e.state.shoptOptions.extglob)}else{let S=await r(e,E);y+=ce(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=ge(w,m.all?"g":"");h=h.map(S=>E.replace(S,b))}catch{}}if(l){let m=X(e.state.env);return{values:[u+h.join(m)+f],quoted:!0}}return h.length===1?{values:[u+h[0]+f],quoted:!0}:{values:[u+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function kc(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 h=0;h<s.parts.length;h++){let p=s.parts[h];if(p.type==="ParameterExpansion"&&!p.operation){let m=p.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(m){i=h,o=m[1],a=m[2]==="*";break}}}if(i===-1)return null;let l="";for(let h=0;h<i;h++)l+=await r(e,s.parts[h]);let c="";for(let h=i+1;h<s.parts.length;h++)c+=await r(e,s.parts[h]);let u=K(e,o),f=u.map(([,h])=>h);if(u.length===0){let h=e.state.env.get(o);if(h!==void 0)return{values:[l+h+c],quoted:!0};if(a)return{values:[l+c],quoted:!0};let p=l+c;return{values:p?[p]:[],quoted:!0}}if(a){let h=X(e.state.env);return{values:[l+f.join(h)+c],quoted:!0}}return f.length===1?{values:[l+f[0]+c],quoted:!0}:{values:[l+f[0],...f.slice(1,-1),f[f.length-1]+c],quoted:!0}}async function xc(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 G(1,"",`bash: \${${o}[@]: 0: 3}: bad substitution
111
+ `);let c=l.offset?await n(e,l.offset.expression):0,u=l.length?await n(e,l.length.expression):void 0,f=K(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(c<0){if(f.length>0){let p=f[f.length-1][0],y=(typeof p=="number"?p:0)+1+c;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(([p])=>typeof p=="number"&&p>=c),d<0&&(d=f.length);let h;if(u!==void 0){if(u<0)throw new le(`${o}[@]: substring expression < 0`);h=f.slice(d,d+u).map(([,p])=>p)}else h=f.slice(d).map(([,p])=>p);if(h.length===0)return{values:[],quoted:!0};if(a){let p=X(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}function Pc(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=K(e,i);if(l.length===0){let d=e.state.env.get(i);if(d!==void 0){let h;switch(a.operator){case"a":h="";break;case"P":h=Er(e,d);break;case"Q":h=rn(d);break;default:h=d}if(V(h)>e.limits.maxStringLength)throw new C(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[h],quoted:!0}}return o?{values:[""],quoted:!0}:{values:[],quoted:!0}}let c=sn(e,i),u=[],f=0;for(let[,d]of l){let h;switch(a.operator){case"a":h=c;break;case"P":h=Er(e,d);break;case"Q":h=rn(d);break;case"u":h=d.charAt(0).toUpperCase()+d.slice(1);break;case"U":h=d.toUpperCase();break;case"L":h=d.toLowerCase();break;default:h=d}let p=V(h);if(p>e.limits.maxStringLength-f)throw new C(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u.push(h),f+=p}if(o){let d=X(e.state.env);if(Math.max(0,u.length-1)*V(d)>e.limits.maxStringLength-f)throw new C(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u.join(d)],quoted:!0}}return{values:u,quoted:!0}}function $c(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(ue(e,i)){let l=Cn(e,i);if(l?.endsWith("[@]")||l?.endsWith("[*]"))return{values:[],quoted:!0}}let o=K(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 Cc(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)||!ue(e,s))return null;let i=Cn(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=K(e,a);if(l.length>0)return{values:l.map(([,u])=>u),quoted:!0};let c=e.state.env.get(a);return c!==void 0?{values:[c],quoted:!0}:{values:[],quoted:!0}}async function Nc(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 ie(e,o.parameter),c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c){if(!a.innerOp&&(l==="@"||l==="*")){let p=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let y=1;y<=p;y++)m.push(e.state.env.get(String(y))||"");return l==="*"?{values:[m.join(X(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let u=c[1],f=c[2]==="*",d=K(e,u);if(a.innerOp){if(a.innerOp.type==="Substring")return jh(e,d,u,f,a.innerOp);if(a.innerOp.type==="DefaultValue"||a.innerOp.type==="UseAlternative"||a.innerOp.type==="AssignDefault"||a.innerOp.type==="ErrorIfUnset")return qh(e,d,u,f,a.innerOp,s);if(a.innerOp.type==="Transform"&&a.innerOp.operator==="a"){let m=sn(e,u),y=d.map(()=>m);return f?{values:[y.join(X(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let p=[];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);p.push(w)}finally{b!==void 0?e.state.env.set("_indirect_elem_",b):e.state.env.delete("_indirect_elem_")}}return f?{values:[p.join(X(e.state.env))],quoted:!0}:{values:p,quoted:!0}}if(d.length>0){let p=d.map(([,m])=>m);return f?{values:[p.join(X(e.state.env))],quoted:!0}:{values:p,quoted:!0}}let h=e.state.env.get(u);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}async function jh(e,t,n,r,s){let i=s.offset?await J(e,s.offset.expression):0,o=s.length?await J(e,s.length.expression):void 0,a=0;if(i<0){if(t.length>0){let u=t[t.length-1][0],d=(typeof u=="number"?u:0)+1+i;if(d<0)return{values:[],quoted:!0};if(a=t.findIndex(([h])=>typeof h=="number"&&h>=d),a<0)return{values:[],quoted:!0}}}else if(a=t.findIndex(([u])=>typeof u=="number"&&u>=i),a<0)return{values:[],quoted:!0};let l;if(o!==void 0){if(o<0)throw new le(`${n}[@]: substring expression < 0`);l=t.slice(a,a+o)}else l=t.slice(a);let c=l.map(([,u])=>u);return r?{values:[c.join(X(e.state.env))],quoted:!0}:{values:c,quoted:!0}}async function qh(e,t,n,r,s,i){let o=s.checkEmpty??!1,a=t.map(([,u])=>u),l=t.length===0,c=t.length===0;if(s.type==="UseAlternative")return!c&&!(o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(s.type==="DefaultValue")return(c||o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:r?{values:[a.join(X(e.state.env))],quoted:!0}:{values:a,quoted:!0};if(s.type==="AssignDefault"){if((c||o&&l)&&s.word){let f=await i(e,s.word.parts,!0);return H(e,n,0,f),{values:[f],quoted:!0}}return r?{values:[a.join(X(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return r?{values:[a.join(X(e.state.env))],quoted:!0}:{values:a,quoted:!0}}async function Rc(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 ie(e,o.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!l)return null;let c=await $t(e,n.parameter),u=await ie(e,n.parameter)==="",f=r.checkEmpty??!1,d;if(r.type==="UseAlternative"?d=c&&!(f&&u):d=!c||f&&u,d){let h=l[1],p=l[2]==="*",m=K(e,h);if(m.length>0){let b=m.map(([,w])=>w);return p?{values:[b.join(X(e.state.env))],quoted:!0}:{values:b,quoted:!0}}let y=e.state.env.get(h);return y!==void 0?{values:[y],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function Oc(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],c=(await ie(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c)return null;let u=await ie(e,n.parameter),f=await $t(e,n.parameter),d=u==="",h=s.checkEmpty??!1,p;if(s.type==="UseAlternative"?p=f&&!(h&&d):p=!f||h&&d,p){let m=c[1],y=c[2]==="*",b=K(e,m);if(b.length>0){let E=b.map(([,S])=>S);return y?{values:[E.join(X(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 Dc(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=V(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 ms(e,t,n){if(V(t)>n-V(e))throw new C(`positional expansion string limit exceeded (${n} bytes)`,"string_length");return e+t}function Ji(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=V(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 Ic(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,c=l.offset?await n(e,l.offset.expression):0,u=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 h=e.state.env.get("0")||"bash",p;if(c<=0){let w=[h,...d],E=w.length+c;if(E<0)p=[];else{let S=c<0?E:0;if(u!==void 0){let v=u<0?w.length+u:S+u;p=w.slice(S,Math.max(S,v))}else p=w.slice(S)}}else{let w=c-1;if(w>=d.length)p=[];else if(u!==void 0){let E=u<0?d.length+u:w+u;p=d.slice(w,Math.max(w,E))}else p=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(p.length===0){let w=m+y;return{values:w?[w]:[],quoted:!0}}if(o){let w=X(e.state.env);return{values:[m+p.join(w)+y],quoted:!0}}return p.length===1?{values:[m+p[0]+y],quoted:!0}:{values:[m+p[0],...p.slice(1,-1),p[p.length-1]+y],quoted:!0}}async function _c(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,c=Dc(e),u="";for(let w=0;w<i;w++)u=ms(u,await n(e,s.parts[w]),e.limits.maxStringLength);let f="";for(let w=i+1;w<s.parts.length;w++)f=ms(f,await n(e,s.parts[w]),e.limits.maxStringLength);if(c.length===0){let w=u+f;return{values:w?[w]:[],quoted:!0}}let d="";if(l.pattern)for(let w of l.pattern.parts)if(w.type==="Glob")d+=oe(w.pattern,!0,e.state.shoptOptions.extglob);else if(w.type==="Literal")d+=oe(w.value,!0,e.state.shoptOptions.extglob);else if(w.type==="SingleQuoted"||w.type==="Escaped")d+=ce(w.value);else if(w.type==="DoubleQuoted"){let E=await r(e,w.parts);d+=ce(E)}else if(w.type==="ParameterExpansion"){let E=await n(e,w);d+=oe(E,!0,e.state.shoptOptions.extglob)}else{let E=await n(e,w);d+=ce(E)}let h=l.replacement?await r(e,l.replacement.parts):"",p=d;l.anchor==="start"?p=`^${d}`:l.anchor==="end"&&(p=`${d}$`);let m=[],y={value:0};try{let w=ge(p,l.all?"g":"");for(let E of c){let S=0;w.lastIndex=0;for(let $=w.exec(E);$&&(S++,!!l.all);$=w.exec(E))$[0].length===0&&w.lastIndex++;let v=V(E),A=V(h),k=0,x=/\$(?:\$|&|\d+|<[^>]+>|`|')/g;for(;x.exec(h)!==null;)k++;if(v+S*A+S*k*v>e.limits.maxStringLength-y.value)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");Ji(m,w.replace(E,h),y,e)}}catch(w){if(w instanceof C)throw w;for(let E of c)Ji(m,E,y,e)}if(o){let w=X(e.state.env);if(y.value+Math.max(0,m.length-1)*V(w)+V(u)+V(f)>e.limits.maxStringLength)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+m.join(w)+f],quoted:!0}}if(V(u)+y.value+V(f)>e.limits.maxStringLength)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return m.length===1?{values:[u+m[0]+f],quoted:!0}:{values:[u+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function Tc(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,c=Dc(e),u="";for(let b=0;b<i;b++)u=ms(u,await n(e,s.parts[b]),e.limits.maxStringLength);let f="";for(let b=i+1;b<s.parts.length;b++)f=ms(f,await n(e,s.parts[b]),e.limits.maxStringLength);if(c.length===0){let b=u+f;return{values:b?[b]:[],quoted:!0}}let d="",h=e.state.shoptOptions.extglob;if(l.pattern)for(let b of l.pattern.parts)if(b.type==="Glob")d+=oe(b.pattern,l.greedy,h);else if(b.type==="Literal")d+=oe(b.value,l.greedy,h);else if(b.type==="SingleQuoted"||b.type==="Escaped")d+=ce(b.value);else if(b.type==="DoubleQuoted"){let w=await r(e,b.parts);d+=ce(w)}else if(b.type==="ParameterExpansion"){let w=await n(e,b);d+=oe(w,l.greedy,h)}else{let w=await n(e,b);d+=ce(w)}let p=[],m={value:0};for(let b of c)Ji(p,Et(e,b,d,l.side,l.greedy),m,e);if(o){let b=X(e.state.env);if(m.value+Math.max(0,p.length-1)*V(b)+V(u)+V(f)>e.limits.maxStringLength)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+p.join(b)+f],quoted:!0}}if(V(u)+m.value+V(f)>e.limits.maxStringLength)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return p.length===1?{values:[u+p[0]+f],quoted:!0}:{values:[u+p[0],...p.slice(1,-1),p[p.length-1]+f],quoted:!0}}async function Lc(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 h=r.parts[d];if(h.type==="ParameterExpansion"&&(h.parameter==="@"||h.parameter==="*")){s=d,i=h.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 c="";for(let d=s+1;d<r.parts.length;d++)c+=await n(e,r.parts[d]);if(a===0){if(i)return{values:[l+c],quoted:!0};let d=l+c;return{values:d?[d]:[],quoted:!0}}let u=[];for(let d=1;d<=a;d++)u.push(e.state.env.get(String(d))||"");if(i){let d=X(e.state.env);return{values:[l+u.join(d)+c],quoted:!0}}return u.length===1?{values:[l+u[0]+c],quoted:!0}:{values:[l+u[0],...u.slice(1,-1),u[u.length-1]+c],quoted:!0}}function Nt(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=V(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 eo(e,t,n,r){let s=V(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 Gh(e){return new tn(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 ys(e,t){if(e.state.options.noglob)return t;let n=Gh(e),r=[];for(let s of t)if(Ct(s,e.state.shoptOptions.extglob)){let i=await n.expand(s);if(i.length>0)De(r,i,e.limits.maxArrayElements,"unquoted glob expansion");else{if(n.hasFailglob())throw new jt(s);n.hasNullglob()||r.push(s)}}else r.push(s);return r}async function Fc(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,c=K(e,i),u=c.map(([,S])=>S);if(c.length===0){let S=e.state.env.get(i);S!==void 0&&(u=[S])}if(u.length===0)return{values:[],quoted:!1};let f="";if(l.pattern)for(let S of l.pattern.parts)if(S.type==="Glob")f+=oe(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")f+=oe(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=ce(S.value);else if(S.type==="DoubleQuoted"){let v=await n(e,S.parts);f+=ce(v)}else if(S.type==="ParameterExpansion"){let v=await r(e,S);f+=oe(v,!0,e.state.shoptOptions.extglob)}else{let v=await r(e,S);f+=ce(v)}let d=l.replacement?await n(e,l.replacement.parts):"",h=f;l.anchor==="start"?h=`^${f}`:l.anchor==="end"&&(h=`${f}$`);let p=[],m={value:0};try{let S=ge(h,l.all?"g":"");for(let v of u)Nt(e,p,fs(e,v,S,d,l.all),m)}catch(S){if(S instanceof C)throw S;for(let v of u)Nt(e,p,v,m)}let y=ve(e.state.env),b=Oe(e.state.env);if(o){let S=X(e.state.env),v=eo(e,p,S,m.value);return b?{values:v?[v]:[],quoted:!1}:{values:de(v,y,e.limits.maxArrayElements),quoted:!1}}if(b)return{values:p,quoted:!1};let w=[],E={value:0};for(let S of p)if(S==="")Nt(e,w,"",E);else for(let v of de(S,y,e.limits.maxArrayElements))Nt(e,w,v,E);return{values:w,quoted:!1}}async function Mc(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,c=K(e,i),u=c.map(([,w])=>w);if(c.length===0){let w=e.state.env.get(i);w!==void 0&&(u=[w])}if(u.length===0)return{values:[],quoted:!1};let f=l.pattern?await nn(e,l.pattern,l.greedy,n,r):"",d=[],h={value:0};for(let w of u)Nt(e,d,Et(e,w,f,l.side,l.greedy),h);let p=ve(e.state.env),m=Oe(e.state.env);if(o){let w=X(e.state.env),E=eo(e,d,w,h.value);return m?{values:E?[E]:[],quoted:!1}:{values:de(E,p,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let y=[],b={value:0};for(let w of d)if(w==="")Nt(e,y,"",b);else for(let E of de(w,p,e.limits.maxArrayElements))Nt(e,y,E,b);return{values:y,quoted:!1}}async function Bc(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),c=[];for(let w=1;w<=l;w++)c.push(e.state.env.get(String(w))||"");if(c.length===0)return{values:[],quoted:!1};let u="",f=e.state.shoptOptions.extglob;if(a.pattern)for(let w of a.pattern.parts)if(w.type==="Glob")u+=oe(w.pattern,a.greedy,f);else if(w.type==="Literal")u+=oe(w.value,a.greedy,f);else if(w.type==="SingleQuoted"||w.type==="Escaped")u+=ce(w.value);else if(w.type==="DoubleQuoted"){let E=await n(e,w.parts);u+=ce(E)}else if(w.type==="ParameterExpansion"){let E=await r(e,w);u+=oe(E,a.greedy,f)}else{let E=await r(e,w);u+=ce(E)}let d=[],h={value:0};for(let w of c)Nt(e,d,Et(e,w,u,a.side,a.greedy),h);let p=ve(e.state.env),m=Oe(e.state.env);if(i){let w=X(e.state.env),E=eo(e,d,w,h.value);return m?{values:E?[E]:[],quoted:!1}:{values:de(E,p,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let y=[],b={value:0};for(let w of d)if(w==="")Nt(e,y,"",b);else for(let E of de(w,p,e.limits.maxArrayElements))Nt(e,y,E,b);return{values:y,quoted:!1}}async function Wc(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,c=a.length?await n(e,a.length.expression):void 0,u=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let E=1;E<=u;E++)f.push(e.state.env.get(String(E))||"");let d=e.state.env.get("0")||"bash",h;if(l<=0){let E=[d,...f],S=E.length+l;if(S<0)h=[];else{let v=l<0?S:0;if(c!==void 0){let A=c<0?E.length+c:v+c;h=E.slice(v,Math.max(v,A))}else h=E.slice(v)}}else{let E=l-1;if(E>=f.length)h=[];else if(c!==void 0){let S=c<0?f.length+c:E+c;h=f.slice(E,Math.max(E,S))}else h=f.slice(E)}let p="";for(let E=0;E<s;E++)p+=await r(e,t[E]);let m="";for(let E=s+1;E<t.length;E++)m+=await r(e,t[E]);let y=ve(e.state.env),b=Oe(e.state.env);if(h.length===0){let E=p+m;return E?b?{values:[E],quoted:!1}:{values:de(E,y,e.limits.maxArrayElements),quoted:!1}:{values:[],quoted:!1}}let w;if(i){let E=X(e.state.env),S=p+h.join(E)+m;b?w=S?[S]:[]:w=de(S,y,e.limits.maxArrayElements)}else if(b)h.length===1?w=[p+h[0]+m]:w=[p+h[0],...h.slice(1,-1),h[h.length-1]+m];else{w=[];for(let E=0;E<h.length;E++){let S=h[E];if(E===0&&(S=p+S),E===h.length-1&&(S=S+m),S==="")w.push("");else{let v=de(S,y,e.limits.maxArrayElements);De(w,v,e.limits.maxArrayElements,"unquoted expansion")}}}return{values:await ys(e,w),quoted:!1}}async function Vc(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 c=1;c<=r;c++)s.push(e.state.env.get(String(c))||"");let i=ve(e.state.env),o=Oe(e.state.env),a=os(e.state.env),l;if(n)if(o)l=s.filter(c=>c!=="");else{let c=X(e.state.env),u=s.join(c);l=de(u,i,e.limits.maxArrayElements)}else if(o)l=s.filter(c=>c!=="");else if(a){l=[];for(let c of s){if(c==="")continue;let u=de(c,i,e.limits.maxArrayElements);De(l,u,e.limits.maxArrayElements,"unquoted expansion")}}else{l=[];for(let c of s)if(c==="")l.push("");else{let u=de(c,i,e.limits.maxArrayElements);De(l,u,e.limits.maxArrayElements,"unquoted expansion")}for(;l.length>0&&l[l.length-1]==="";)l.pop()}return{values:await ys(e,l),quoted:!1}}async function zc(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=K(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=ve(e.state.env),l=Oe(e.state.env),c=os(e.state.env),u;if(s)if(l)u=o.filter(f=>f!=="");else{let f=X(e.state.env),d=o.join(f);u=de(d,a,e.limits.maxArrayElements)}else if(l)u=o.filter(f=>f!=="");else if(c){u=[];for(let f of o){if(f==="")continue;let d=de(f,a,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}}else{u=[];for(let f of o)if(f==="")u.push("");else{let d=de(f,a,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}for(;u.length>0&&u[u.length-1]==="";)u.pop()}return{values:await ys(e,u),quoted:!1}}function Uc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let n=t[0].operation,r=Un(e,n.prefix);if(r.length===0)return{values:[],quoted:!1};let s=ve(e.state.env),i=Oe(e.state.env),o;if(n.star)if(i)o=r;else{let a=X(e.state.env),l=r.join(a);o=de(l,s,e.limits.maxArrayElements)}else if(i)o=r;else{o=[];for(let a of r){let l=de(a,s,e.limits.maxArrayElements);De(o,l,e.limits.maxArrayElements,"unquoted expansion")}}return{values:o,quoted:!1}}function jc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let n=t[0].operation,s=K(e,n.array).map(([l])=>String(l));if(s.length===0)return{values:[],quoted:!1};let i=ve(e.state.env),o=Oe(e.state.env),a;if(n.star)if(o)a=s;else{let l=X(e.state.env),c=s.join(l);a=de(c,i,e.limits.maxArrayElements)}else if(o)a=s;else{a=[];for(let l of s){let c=de(l,i,e.limits.maxArrayElements);De(a,c,e.limits.maxArrayElements,"unquoted expansion")}}return{values:a,quoted:!1}}async function qc(e,t,n){let r=-1;for(let d=0;d<t.length;d++){let h=t[d];if(h.type==="ParameterExpansion"&&(h.parameter==="@"||h.parameter==="*")&&!h.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=ve(e.state.env),c=Oe(e.state.env),u=os(e.state.env);if(s===0){let d=o+a;return{values:d?[d]:[],quoted:!1}}let f;{let d=[];for(let h=0;h<i.length;h++){let p=i[h];h===0&&(p=o+p),h===i.length-1&&(p=p+a),d.push(p)}if(c)f=d.filter(h=>h!=="");else if(u){f=[];for(let h of d){if(h==="")continue;let p=de(h,l,e.limits.maxArrayElements);De(f,p,e.limits.maxArrayElements,"unquoted expansion")}}else{f=[];for(let h of d)if(h==="")f.push("");else{let p=de(h,l,e.limits.maxArrayElements);De(f,p,e.limits.maxArrayElements,"unquoted expansion")}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await ys(e,f),quoted:!1}}async function Zc(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:c,hasIndirection:u}=gr(r),d=n.hasBraceExpansion(r)?await n.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return Hh(e,d,s);let h=await Zh(e,r,a,c,u,n);if(h!==null)return h;let p=await Kh(e,r,n);if(p!==null)return p;let m=await Xh(e,r,n);if(m!==null)return m;let y=await Jh(e,r,n.expandPart);if(y!==null)return Hc(e,y);if((i||o||l)&&!Oe(e.state.env)){let w=ve(e.state.env),E=n.buildIfsCharClassPattern(w),S=await n.smartWordSplit(e,r,w,E,n.expandPart);return Hc(e,S)}let b=await n.expandWordAsync(e,t);return ep(e,t,r,b,s,n.expandWordForGlobbing)}async function Hh(e,t,n){let r=[];for(let s of t)if(!(!n&&s===""))if(!n&&!e.state.options.noglob&&Ct(s,e.state.shoptOptions.extglob)){let i=await gs(e,s);De(r,i,e.limits.maxArrayElements,"brace/glob expansion")}else r.push(s);return{values:r,quoted:!1}}async function Zh(e,t,n,r,s,i){if(n){let o=$c(e,t);if(o!==null)return o}{let o=Cc(e,t);if(o!==null)return o}{let o=await Ac(e,t);if(o!==null)return o}{let o=await vc(e,t,n,i.expandPart,i.expandWordPartsAsync);if(o!==null)return o}{let o=await kc(e,t,n,i.expandPart);if(o!==null)return o}{let o=await xc(e,t,i.evaluateArithmetic);if(o!==null)return o}{let o=Pc(e,t);if(o!==null)return o}{let o=await bc(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}{let o=await Sc(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let o=Qh(e,t);if(o!==null)return o}{let o=await Nc(e,t,s,i.expandParameterAsync,i.expandWordPartsAsync);if(o!==null)return o}{let o=await Rc(e,t);if(o!==null)return o}{let o=await Oc(e,t);if(o!==null)return o}return null}function Qh(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=Un(e,r.prefix);return r.star?{values:[s.join(X(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=K(e,r.array).map(([o])=>String(o));return r.star?{values:[i.join(X(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function Kh(e,t,n){{let r=await Ic(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await _c(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Tc(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Lc(e,t,n.expandPart);if(r!==null)return r}return null}async function Xh(e,t,n){{let r=await Fc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Mc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Bc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Wc(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await Vc(e,t);if(r!==null)return r}{let r=await zc(e,t);if(r!==null)return r}{let r=Uc(e,t);if(r!==null)return r}{let r=jc(e,t);if(r!==null)return r}{let r=await qc(e,t,n.expandPart);if(r!==null)return r}return null}function Gc(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 Yh(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=K(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=X(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 Jh(e,t,n){if(t.length<2)return null;let r=!1;for(let l of t)if(Gc(l)){r=!0;break}if(!r)return null;let s=ve(e.state.env),i=Oe(e.state.env),o=[];for(let l of t){let c=Gc(l);if(c&&l.type==="DoubleQuoted"){let u=await Yh(e,l,c,n);o.push(u)}else if(l.type==="DoubleQuoted"||l.type==="SingleQuoted"){let u=await n(e,l);o.push([u])}else if(l.type==="Literal")o.push([l.value]);else if(l.type==="ParameterExpansion"){let u=await n(e,l);if(i)o.push(u?[u]:[]);else{let f=de(u,s,e.limits.maxArrayElements);o.push(f)}}else{let u=await n(e,l);if(i)o.push(u?[u]:[]);else{let f=de(u,s,e.limits.maxArrayElements);o.push(f)}}}let a=[];for(let l of o)if(l.length!==0)if(a.length===0)De(a,l,e.limits.maxArrayElements,"word expansion");else{let c=a.length-1;a[c]=a[c]+l[0];for(let u=1;u<l.length;u++)a.push(l[u])}return a}async function Hc(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let n=[];for(let r of t)if(Ct(r,e.state.shoptOptions.extglob)){let s=await gs(e,r);De(n,s,e.limits.maxArrayElements,"glob expansion")}else n.push(r);return{values:n,quoted:!1}}async function gs(e,t){let n=new tn(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 jt(t);return n.hasNullglob()?[]:[t]}async function ep(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(Ct(a,e.state.shoptOptions.extglob)){let c=await gs(e,a);if(c.length>0&&c[0]!==a)return{values:c,quoted:!1};if(c.length===0)return{values:[],quoted:!1}}let l=Zi(r);if(!Oe(e.state.env)){let c=ve(e.state.env);return{values:de(l,c,e.limits.maxArrayElements),quoted:!1}}return{values:[l],quoted:!1}}if(!s&&!e.state.options.noglob&&Ct(r,e.state.shoptOptions.extglob)){let a=await i(e,t);if(Ct(a,e.state.shoptOptions.extglob)){let l=await gs(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=Zi(r);if(!Oe(e.state.env)){let l=ve(e.state.env);return{values:de(a,l,e.limits.maxArrayElements),quoted:!1}}return{values:[a],quoted:!1}}return{values:[r],quoted:s}}function Fe(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 Kc(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 $t(e,t.parameter),o=await ie(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"&&Qi(t.parameter),r.parts):null}function tp(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(n=>n.type==="Literal"):!1}async function np(e,t){if(t.type!=="ParameterExpansion")return null;let n=await Kc(e,t);if(!n||n.length<=1)return null;let r=n.some(i=>tp(i)),s=n.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&s?n:null}function rp(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?Wi(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&Zl(e))}async function Xc(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let d=t[0],h=await Kc(e,d);if(h&&h.length>0&&h.length>1&&h.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&h.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return Qc(e,h,n,r,s)}let i=[],o=!1;for(let d of t){let h=rp(d),p=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=h?await np(e,d):null,y=await s(e,d);i.push({value:y,isSplittable:h,isQuoted:p,mixedDefaultParts:m??void 0}),h&&(o=!0)}if(!o){let d=i.map(h=>h.value).join("");return d?[d]:[]}let a=[],l="",c=!1,u=!1,f=!1;for(let d of i)if(!d.isSplittable)u?d.isQuoted&&d.value===""?(l!==""&&Fe(e,a,l),Fe(e,a,""),c=!0,l="",u=!1,f=!0):d.value!==""?(l!==""&&Fe(e,a,l),l=d.value,u=!1,f=!1):(l+=d.value,f=!1):(l+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let h=await Qc(e,d.mixedDefaultParts,n,r,s);if(h.length!==0)if(h.length===1)l+=h[0],c=!0;else{l+=h[0],Fe(e,a,l),c=!0;for(let p=1;p<h.length-1;p++)Fe(e,a,h[p]);l=h[h.length-1]}u=!1,f=!1}else{let{words:h,hadLeadingDelimiter:p,hadTrailingDelimiter:m}=as(d.value,n,e.limits.maxArrayElements);if(f&&p&&l===""&&(Fe(e,a,""),c=!0),h.length===0)m&&(u=!0);else if(h.length===1)l+=h[0],c=!0,u=m;else{l+=h[0],Fe(e,a,l),c=!0;for(let y=1;y<h.length-1;y++)Fe(e,a,h[y]);l=h[h.length-1],u=m}f=!1}return l!==""?Fe(e,a,l):a.length===0&&c&&Fe(e,a,""),a}function sp(e,t){return e.length>0&&t.includes(e[0])}async function Qc(e,t,n,r,s){let i=[];for(let u of t){let d=!(u.type==="DoubleQuoted"||u.type==="SingleQuoted"),h=await s(e,u);i.push({value:h,isSplittable:d})}let o=[],a="",l=!1,c=!1;for(let u of i)if(!u.isSplittable)c&&u.value!==""?(a!==""&&Fe(e,o,a),a=u.value,c=!1):a+=u.value;else{sp(u.value,n)&&a!==""&&(Fe(e,o,a),a="",l=!0);let{words:d,hadTrailingDelimiter:h}=as(u.value,n,e.limits.maxArrayElements);if(d.length===0)h&&(c=!0);else if(d.length===1)a+=d[0],l=!0,c=h;else{a+=d[0],Fe(e,o,a),l=!0;for(let p=1;p<d.length-1;p++)Fe(e,o,d[p]);a=d[d.length-1],c=h}}return a!==""?Fe(e,o,a):o.length===0&&l&&Fe(e,o,""),o}function Yc(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Jc(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}var ws="/dev/fd",tu=63,ip=10,eu=tu-ip+1,to=class extends yt{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} '${ws}${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 op(e){let t=new to(n=>nu(e).some(r=>r.path===`${ws}${n}`));e.fs=new Kt({base:e.fs,mounts:[{mountPoint:ws,filesystem:t}]}),e.state.processSubstitutionFsMounted=!0}async function ap(e,t,n){try{await e.fs.writeFile(t,n,"binary");return}catch(r){if(e.state.processSubstitutionFsMounted)throw r;op(e)}await e.fs.writeFile(t,n,"binary")}async function lp(e,t){try{await e.fs.rm(t,{force:!0})}catch{}}function nu(e){let t=e.state.processSubstitutions;if(t)return t;let n=[];return e.state.processSubstitutions=n,n}async function ru(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=ot(e.state.arrays),l=e.state.cwd,c=e.state.bashPid,u=e.state.suppressVerbose,f=e.state.groupStdin,d=e.state.lastExitCode,h=e.state.env.get("?"),p=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 G)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=c,e.state.suppressVerbose=u,e.state.groupStdin=f,e.state.lastExitCode=d,e.state.lastSubstitutionExitCode=p,h!==void 0?e.state.env.set("?",h):e.state.env.delete("?")}return m}async function su(e,t){let n=nu(e);if(n.length>=eu)throw new C(`Process substitution limit exceeded (${eu} concurrent)`,"file_descriptors");let r="";if(t.direction==="input"){let o=await ru(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=tu-n.length,i=`${ws}/${s}`;n.push({fd:s,path:i,direction:t.direction,body:t.body});try{await ap(e,i,r)}catch(o){throw n.pop(),o}return i}function iu(e){return e.state.processSubstitutions?.length??0}var cp={stdout:"",stderr:""};async function no(e,t){let n=e.state.processSubstitutions;if(!n||n.length<=t)return cp;let r="",s="";for(;n.length>t;){let i=n[n.length-1],o="";if(i.direction==="output")try{o=await _n(e.fs,i.path)}catch{}if(await lp(e,i.path),n.pop(),i.direction==="output"){let a=await ru(e,i.body,o);r+=_t(a),s+=a.stderr}}return{stdout:r,stderr:s}}function ln(e,t,n){if(e.length>t)throw new C(`${n}: string length limit exceeded (${t} bytes)`,"string_length")}async function St(e,t,n=!1){let r=[],s=0;for(let i of t){let o=await tt(e,i,n);if(s+=V(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 up(e){return Jc(e)}function au(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!up(t))return!1;return!0}function fp(e,t,n=!1){let r=Yc(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 Xi(e,t.pattern);default:return null}}async function se(e,t){return so(e,t)}async function lu(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped")n.push(zn(r.value));else if(r.type==="SingleQuoted")n.push(r.value);else if(r.type==="DoubleQuoted"){let s=await St(e,r.parts);n.push(s)}else if(r.type==="TildeExpansion"){let s=await tt(e,r);n.push(zn(s))}else n.push(await tt(e,r));return n.join("")}async function cu(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(et(r.value));else if(r.type==="DoubleQuoted"){let s=await St(e,r.parts);n.push(et(s))}else n.push(await tt(e,r));return n.join("")}async function uu(e,t){let n=[];for(let r of t.parts)if(r.type==="SingleQuoted")n.push(et(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 St(e,r.parts);n.push(et(s))}else r.type==="Glob"?gc(r.pattern)?n.push(await Ec(e,r.pattern)):n.push(Xi(e,r.pattern)):r.type==="Literal"?n.push(r.value):n.push(await tt(e,r));return n.join("")}function bs(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&bs(t.parts))return!0;return!1}var ou=1e5;async function fu(e,t,n={count:0}){let r=()=>{n.count++,e.executionScope.consumeLimited("brace_operations",1,Math.min(ou,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,c="";for(let d of o.items)if(d.type==="Range"){let h=Hi(d.start,d.end,d.step,d.startStr,d.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(h.expanded)for(let p of h.expanded)s(a,p);else{l=!0,c=h.literal;break}}else{let h=await fu(e,d.word.parts,n);for(let p of h){let m=[];for(let y of p)typeof y=="string"?m.push(y):m.push(await tt(e,y));s(a,m.join(""))}}if(l){for(let d of i)r(),d.push(c);continue}if(i.length*a.length>e.limits.maxBraceExpansionResults||n.count>ou)throw new C(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");let f=[];for(let d of i)for(let h 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,h])}i=f}else for(let a of i)r(),a.push(o);return i}async function du(e,t){let n=t.parts;if(!bs(n))return[await se(e,t)];let r=await fu(e,n),s=[];for(let i of r){let o=[];for(let a of i)typeof a=="string"?o.push(a):o.push(await tt(e,a));s.push(Yi(e,o.join("")))}return s}function dp(){return{expandWordAsync:so,expandWordForGlobbing:uu,expandWordWithBracesAsync:du,expandWordPartsAsync:St,expandPart:tt,expandParameterAsync:Es,hasBraceExpansion:bs,evaluateArithmetic:J,buildIfsCharClassPattern:Ql,smartWordSplit:Xc}}async function At(e,t){return Zc(e,t,dp())}function hp(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function ro(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(ro(e,t))return{error:`bash: $@: ambiguous redirect
112
+ `};let n=t.parts,{hasQuoted:r}=gr(n);if(bs(n)&&(await du(e,t)).length>1)return{error:`bash: ${n.map(h=>h.type==="Literal"?h.value:h.type==="BraceExpansion"?`{${h.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
113
+ `};let s=await so(e,t),{hasParamExpansion:i,hasCommandSub:o}=gr(n);if((i||o)&&!r&&!Oe(e.state.env)){let f=ve(e.state.env);if(de(s,f,e.limits.maxArrayElements).length>1)return{error:`bash: $${hp(n)}: ambiguous redirect
114
+ `}}if(r||e.state.options.noglob||n.some(f=>f.type==="ProcessSubstitution"))return{target:s};let l=await uu(e,t);if(!Ct(l,e.state.shoptOptions.extglob))return{target:s};let c=new tn(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")}),u=await c.expand(l);return u.length===0?c.hasFailglob()?{error:`bash: no match: ${s}
115
115
  `}:{target:s}:u.length===1?{target:u[0]}:{error:`bash: ${s}: ambiguous redirect
116
- `}}async function no(e,t){let n=t.parts,r=n.length;if(r===1){let o=await tt(e,n[0]);return ln(o,e.limits.maxStringLength,"word expansion"),o}let s=[];for(let o=0;o<r;o++)s.push(await tt(e,n[o]));let i=s.join("");return ln(i,e.limits.maxStringLength,"word expansion"),i}async function tt(e,t,n=!1){if(t.type==="ParameterExpansion")return ms(e,t,n);let r=ip(e,t,n);if(r!==null)return r;switch(t.type){case"DoubleQuoted":{let s=[];for(let i of t.parts)s.push(await tt(e,i,!0));return s.join("")}case"CommandSubstitution":{let s=Yl(t.body);if(s)try{let h=await se(e,s.target),p=h.startsWith("/")?h:`${e.state.cwd}/${h}`,m=await e.fs.readFile(p);on(e.state,0);let E=m.replace(/\n+$/,"");return ln(E,e.limits.maxStringLength,"command substitution"),E}catch(h){if(h instanceof $)throw h;return on(e.state,1),""}let i=e.substitutionDepth??0,o=e.limits.maxSubstitutionDepth;if(i>=o)throw new $(`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 c=new Map(e.state.env),u=at(e.state.arrays),f=e.state.cwd,d=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let h=await e.executeScript(t.body),p=h.exitCode;e.state.env=c,e.state.arrays=u,e.state.cwd=f,e.state.suppressVerbose=d,on(e.state,p),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr),e.state.bashPid=l,e.substitutionDepth=a;let m=h.stdout.replace(/\n+$/,"");return ln(m,e.limits.maxStringLength,"command substitution"),m}catch(h){if(e.state.env=c,e.state.arrays=u,e.state.cwd=f,e.state.bashPid=l,e.substitutionDepth=a,e.state.suppressVerbose=d,h instanceof $)throw h;if(h instanceof q){on(e.state,h.exitCode),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr);let p=h.stdout.replace(/\n+$/,"");return ln(p,e.limits.maxStringLength,"command substitution"),p}throw h}}case"ProcessSubstitution":return eu(e,t);case"ArithmeticExpansion":{let s=t.expression.originalText;if(s&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(s)){let o=await Xl(e,s),a=new Z,l=re(a,o);return String(await J(e,l.expression,!0))}return String(await J(e,t.expression.expression,!0))}case"BraceExpansion":{let s=[];for(let i of t.items)if(i.type==="Range"){let o=qi(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 se(e,i.word));return s.join(" ")}default:return""}}async function ms(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,h]=i;if(e.state.associativeArrays?.has(d)||h.includes("$(")||h.includes("`")||h.includes("${")){let m=await Ui(e,h);r=`${d}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ue(e,r)){let d=Be(e,r);if(d&&d!==r){let h=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(h){let[,p,m]=h;if(e.state.associativeArrays?.has(p)||m.includes("$(")||m.includes("`")||m.includes("${")){let S=await Ui(e,m);r=`${p}[${S}]`}}}}if(s?.type==="Length"&&/^[a-zA-Z_][a-zA-Z0-9_]*\[[@*]\]$/.test(r))return Zi(e,r,"");let o=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),a=await ie(e,r,!o);if(!s)return a;let l=!await $t(e,r),{isEmpty:c,effectiveValue:u}=dc(e,r,a,n),f={value:a,isUnset:l,isEmpty:c,effectiveValue:u,inDoubleQuotes:n};switch(s.type){case"DefaultValue":return ec(e,s,f,At);case"AssignDefault":return tc(e,r,s,f,At);case"ErrorIfUnset":return nc(e,r,s,f,At);case"UseAlternative":return rc(e,s,f,At);case"PatternRemoval":{let d=await sc(e,a,s,At,tt);return ln(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await ic(e,a,s,At,tt);return ln(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return Zi(e,r,a);case"LengthSliceError":throw new Xe(r);case"BadSubstitution":throw new Xe(s.text);case"Substring":return oc(e,r,a,s);case"CaseModification":{let d=await ac(e,a,s,At,ms);return ln(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return lc(e,r,a,l,s);case"Indirection":return cc(e,r,a,l,s,ms,n);case"ArrayKeys":return uc(e,s);case"VarNamePrefix":return fc(e,s);default:return a}}function fu(){return{visited:new Set,depth:0}}function lp(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new le("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new le("division by 0");return e%t;case"**":if(t<0)throw new le("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 uu(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 cp(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function up(e,t){let n=e.state.env.get(t);if(n!==void 0)return n;let r=ae(e,t,0);return r!==void 0?r:await ie(e,t)}async function fp(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 Z,{expr:o,pos:a}=Wn(i,s,0);if(a<s.length){let l=s.slice(a).trim(),c=l.split(/\s+/)[0]||l;throw new le(`syntax error in expression (error token is "${c}")`,"","")}return await jn(e,o,!1,n)}async function gs(e,t,n,r){if(r.depth>100)throw new le("maximum variable indirection depth exceeded");if(r.visited.has(t))throw new le(`arithmetic variable cycle detected at ${t}`);r.visited.add(t),r.depth++;try{return await fp(e,n,r)}finally{r.depth--,r.visited.delete(t)}}async function ro(e,t,n){if(n.depth>100)throw new le("maximum variable indirection depth exceeded");if(n.visited.has(t))throw new le(`arithmetic variable cycle detected at ${t}`);n.visited.add(t),n.depth++;try{let r=await up(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 ro(e,i,n);let o=new Z,{expr:a,pos:l}=Wn(o,i,0);if(l<i.length){let c=i.slice(l).trim(),u=c.split(/\s+/)[0]||c;throw new le(`${i}: syntax error in expression (error token is "${u}")`)}return await jn(e,a,!1,n)}finally{n.depth--,n.visited.delete(t)}}async function ws(e,t){if(t.startsWith("#")){let f=t.slice(1),d=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(d){let p=d[1],m=Q(e,p);return String(m.length)}let h=e.state.env.get(f)||"";return String(h.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 ie(e,t);let i=t.slice(0,r),o=t.slice(r+s.length),a=e.state.env.get(i),l=a===void 0,c=a==="",u=s.startsWith(":");switch(s){case":-":case"-":return l||u&&c?o:a||"";case":=":case"=":return l||u&&c?(e.state.env.set(i,o),o):a||"";case":+":case"+":return!(l||u&&c)?o:"";case":?":case"?":{if(l||u&&c)throw new Error(o||`${i}: parameter null or not set`);return a||""}default:return a||""}}async function J(e,t,n=!1){return jn(e,t,n,fu())}async function jn(e,t,n,r){let s=(i,o=n)=>jn(e,i,o,r);switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new le("value too great for base");return t.value;case"ArithVariable":return await ro(e,t.name,r);case"ArithSpecialVar":{let o=(await ie(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 Z,{expr:c}=Wn(l,o,0);return await s(c)}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 ws(e,t.content);return Number.parseInt(i,10)||0}case"ArithDynamicBase":{let i=await ws(e,t.baseExpr),o=Number.parseInt(i,10);if(o<2||o>64)return 0;let a=`${o}#${t.value}`;return fr(a)}case"ArithDynamicNumber":{let o=await ws(e,t.prefix)+t.suffix;return fr(o)}case"ArithArrayElement":{let i=e.state.associativeArrays?.has(t.array),o=async a=>{let l=ae(e,t.array,a);return l!==void 0?await gs(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 ie(e,t.index.name);return await o(a)}if(t.index){let a=await s(t.index);if(a<0){let u=Q(e,t.array),f=e.state.currentLine;if(u.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
116
+ `}}async function so(e,t){let n=t.parts,r=n.length;if(r===1){let o=await tt(e,n[0]);return ln(o,e.limits.maxStringLength,"word expansion"),o}let s=[];for(let o=0;o<r;o++)s.push(await tt(e,n[o]));let i=s.join("");return ln(i,e.limits.maxStringLength,"word expansion"),i}async function tt(e,t,n=!1){if(t.type==="ParameterExpansion")return Es(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 tt(e,i,!0));return s.join("")}case"CommandSubstitution":{let s=nc(t.body);if(s)try{let h=await se(e,s.target),p=h.startsWith("/")?h:`${e.state.cwd}/${h}`,m=await e.fs.readFile(p);on(e.state,0);let y=m.replace(/\n+$/,"");return ln(y,e.limits.maxStringLength,"command substitution"),y}catch(h){if(h instanceof C)throw h;return on(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 c=new Map(e.state.env),u=ot(e.state.arrays),f=e.state.cwd,d=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let h=await e.executeScript(t.body),p=h.exitCode;e.state.env=c,e.state.arrays=u,e.state.cwd=f,e.state.suppressVerbose=d,on(e.state,p),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr),e.state.bashPid=l,e.substitutionDepth=a;let m=h.stdout.replace(/\n+$/,"");return ln(m,e.limits.maxStringLength,"command substitution"),m}catch(h){if(e.state.env=c,e.state.arrays=u,e.state.cwd=f,e.state.bashPid=l,e.substitutionDepth=a,e.state.suppressVerbose=d,h instanceof C)throw h;if(h instanceof G){on(e.state,h.exitCode),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr);let p=h.stdout.replace(/\n+$/,"");return ln(p,e.limits.maxStringLength,"command substitution"),p}throw h}}case"ProcessSubstitution":return su(e,t);case"ArithmeticExpansion":{let s=t.expression.originalText;if(s&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(s)){let o=await tc(e,s),a=new Q,l=re(a,o);return String(await J(e,l.expression,!0))}return String(await J(e,t.expression.expression,!0))}case"BraceExpansion":{let s=[];for(let i of t.items)if(i.type==="Range"){let o=Hi(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 se(e,i.word));return s.join(" ")}default:return""}}async function Es(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,h]=i;if(e.state.associativeArrays?.has(d)||h.includes("$(")||h.includes("`")||h.includes("${")){let m=await qi(e,h);r=`${d}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ue(e,r)){let d=Be(e,r);if(d&&d!==r){let h=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(h){let[,p,m]=h;if(e.state.associativeArrays?.has(p)||m.includes("$(")||m.includes("`")||m.includes("${")){let b=await qi(e,m);r=`${p}[${b}]`}}}}if(s?.type==="Length"&&/^[a-zA-Z_][a-zA-Z0-9_]*\[[@*]\]$/.test(r))return Ki(e,r,"");let o=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),a=await ie(e,r,!o);if(!s)return a;let l=!await $t(e,r),{isEmpty:c,effectiveValue:u}=yc(e,r,a,n),f={value:a,isUnset:l,isEmpty:c,effectiveValue:u,inDoubleQuotes:n};switch(s.type){case"DefaultValue":return sc(e,s,f,St);case"AssignDefault":return ic(e,r,s,f,St);case"ErrorIfUnset":return oc(e,r,s,f,St);case"UseAlternative":return ac(e,s,f,St);case"PatternRemoval":{let d=await lc(e,a,s,St,tt);return ln(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await cc(e,a,s,St,tt);return ln(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return Ki(e,r,a);case"LengthSliceError":throw new Xe(r);case"BadSubstitution":throw new Xe(s.text);case"Substring":return uc(e,r,a,s);case"CaseModification":{let d=await fc(e,a,s,St,Es);return ln(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return dc(e,r,a,l,s);case"Indirection":return hc(e,r,a,l,s,Es,n);case"ArrayKeys":return pc(e,s);case"VarNamePrefix":return mc(e,s);default:return a}}function mu(){return{visited:new Set,depth:0}}function pp(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new le("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new le("division by 0");return e%t;case"**":if(t<0)throw new le("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 pu(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 mp(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function yp(e,t){let n=e.state.env.get(t);if(n!==void 0)return n;let r=ae(e,t,0);return r!==void 0?r:await ie(e,t)}async function gp(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 Q,{expr:o,pos:a}=Vn(i,s,0);if(a<s.length){let l=s.slice(a).trim(),c=l.split(/\s+/)[0]||l;throw new le(`syntax error in expression (error token is "${c}")`,"","")}return await qn(e,o,!1,n)}async function Ss(e,t,n,r){if(r.depth>100)throw new le("maximum variable indirection depth exceeded");if(r.visited.has(t))throw new le(`arithmetic variable cycle detected at ${t}`);r.visited.add(t),r.depth++;try{return await gp(e,n,r)}finally{r.depth--,r.visited.delete(t)}}async function io(e,t,n){if(n.depth>100)throw new le("maximum variable indirection depth exceeded");if(n.visited.has(t))throw new le(`arithmetic variable cycle detected at ${t}`);n.visited.add(t),n.depth++;try{let r=await yp(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 io(e,i,n);let o=new Q,{expr:a,pos:l}=Vn(o,i,0);if(l<i.length){let c=i.slice(l).trim(),u=c.split(/\s+/)[0]||c;throw new le(`${i}: syntax error in expression (error token is "${u}")`)}return await qn(e,a,!1,n)}finally{n.depth--,n.visited.delete(t)}}async function As(e,t){if(t.startsWith("#")){let f=t.slice(1),d=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(d){let p=d[1],m=K(e,p);return String(m.length)}let h=e.state.env.get(f)||"";return String(h.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 ie(e,t);let i=t.slice(0,r),o=t.slice(r+s.length),a=e.state.env.get(i),l=a===void 0,c=a==="",u=s.startsWith(":");switch(s){case":-":case"-":return l||u&&c?o:a||"";case":=":case"=":return l||u&&c?(e.state.env.set(i,o),o):a||"";case":+":case"+":return!(l||u&&c)?o:"";case":?":case"?":{if(l||u&&c)throw new Error(o||`${i}: parameter null or not set`);return a||""}default:return a||""}}async function J(e,t,n=!1){return qn(e,t,n,mu())}async function qn(e,t,n,r){let s=(i,o=n)=>qn(e,i,o,r);switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new le("value too great for base");return t.value;case"ArithVariable":return await io(e,t.name,r);case"ArithSpecialVar":{let o=(await ie(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 Q,{expr:c}=Vn(l,o,0);return await s(c)}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 As(e,t.content);return Number.parseInt(i,10)||0}case"ArithDynamicBase":{let i=await As(e,t.baseExpr),o=Number.parseInt(i,10);if(o<2||o>64)return 0;let a=`${o}#${t.value}`;return dr(a)}case"ArithDynamicNumber":{let o=await As(e,t.prefix)+t.suffix;return dr(o)}case"ArithArrayElement":{let i=e.state.associativeArrays?.has(t.array),o=async a=>{let l=ae(e,t.array,a);return l!==void 0?await Ss(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 ie(e,t.index.name);return await o(a)}if(t.index){let a=await s(t.index);if(a<0){let u=K(e,t.array),f=e.state.currentLine;if(u.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
117
117
  `,0;let h=Math.max(...u.map(([p])=>typeof p=="number"?p:0))+1+a;if(h<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
118
- `,0;a=h}let l=`${t.array}[${a}]`,c=ae(e,t.array,a);if(c!==void 0)return gs(e,l,c,r);if(a===0){let u=e.state.env.get(t.array);if(u!==void 0)return gs(e,t.array,u,r)}if(e.state.options.nounset&&!(e.state.env.has(t.array)||Ne(e,t.array)))throw new ze(`${t.array}[${a}]`);return 0}return 0}case"ArithDoubleSubscript":throw new le("double subscript","","");case"ArithNumberSubscript":throw new le(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new le(t.message,"","",!0);case"ArithSingleQuote":{if(n)throw new le(`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 lp(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 ie(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 ie(e,t.operand.index.name);else if(t.operand.index){let f=await s(t.operand.index);l=String(f)}else return i;let c=Number.parseInt(ae(e,o,l)||"0",10)||0,u=t.operator==="++"?c+1:c-1;return G(e,o,l,String(u),a?"associative":"indexed"),t.prefix?u:c}if(t.operand.type==="ArithConcat"){let o="";for(let a of t.operand.parts)o+=await Un(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 Un(e,a,n,r);else t.operand.nameExpr.type==="ArithVariable"&&(o=t.operand.nameExpr.hasDollarPrefix?await ie(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(ae(e,o,a)||"0",10)||0,c=t.operator==="++"?l+1:l-1;return G(e,o,a,String(c)),t.prefix?c:l}}return i}return cp(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 ie(e,t.subscript.name)||"\\";else if(d){let h=await s(t.subscript);a=String(h)}else{let h=await s(t.subscript);if(h<0){let p=Q(e,i);p.length>0&&(h=Math.max(...p.map(([E])=>typeof E=="number"?E:0))+1+h)}a=String(h)}}let l=a===void 0?e.state.env.get(o):ae(e,i,a),c=Number.parseInt(l||"0",10)||0,u=await s(t.value),f=uu(c,u,t.operator);return a===void 0?e.state.env.set(o,String(f)):G(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 Un(e,o,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)?await ro(e,i,r):Number.parseInt(i,10)||0}case"ArithDynamicAssignment":{let i="";if(t.target.type==="ArithConcat")for(let u of t.target.parts)i+=await Un(e,u,n,r);else t.target.type==="ArithVariable"&&(i=t.target.hasDollarPrefix?await ie(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 u=await s(t.subscript);o=`${i}_${u}`}let a=Number.parseInt(e.state.env.get(o)||"0",10)||0,l=await s(t.value),c=uu(a,l,t.operator);return e.state.env.set(o,String(c)),c}case"ArithDynamicElement":{let i="";if(t.nameExpr.type==="ArithConcat")for(let c of t.nameExpr.parts)i+=await Un(e,c,n,r);else t.nameExpr.type==="ArithVariable"&&(i=t.nameExpr.hasDollarPrefix?await ie(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?gs(e,a,l,r):0}default:return 0}}async function Un(e,t,n=!1,r=fu()){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await jn(e,t,n,r));case"ArithVariable":return t.hasDollarPrefix?await ie(e,t.name):t.name;case"ArithSpecialVar":return await ie(e,t.name);case"ArithBracedExpansion":return await ws(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 Un(e,i,n,r);return s}default:return String(await jn(e,t,n,r))}}async function du(e,t){let n="",r=0;for(let k of t.parts){let A=k.type==="Literal"?k.value:"\0",P=M(A);if(P>e.limits.maxStringLength-r)throw new $(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n+=A,r+=P}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=[],c=!1,u="",f=0,d=0,h=!1,p=!0,m=k=>{let A=M(k);if(A>e.limits.maxStringLength-d-f)throw new $(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u+=k,f+=A},E=(k,A=!1)=>{if(a.length>=e.limits.maxArrayElements)throw new $(`array assignment element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let P=M(k);if(P>e.limits.maxStringLength-d)throw new $(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");a.push(k),l.push(A),d+=P},S=()=>{E(u,p),u="",f=0,h=!1,p=!0};for(let k of t.parts)if(k.type==="Literal"){let A=k.value;if(!c){let P=A.indexOf("=(");P!==-1&&(c=!0,A=A.slice(P+2))}if(c){A.endsWith(")")&&(A=A.slice(0,-1));for(let P of A)/\s/.test(P)?(u||h)&&S():m(P)}}else if(c)if(k.type==="BraceExpansion")if(/^\[.+\]=/.test(u))m(Mn({type:"Word",parts:[k]}));else{(u||h)&&S();let P=await vt(e,{type:"Word",parts:[k]});for(let N of P.values)E(N)}else{(k.type==="SingleQuoted"||k.type==="DoubleQuoted"||k.type==="Escaped")&&(h=!0),p=!1;let A=await se(e,{type:"Word",parts:[k]});m(A)}(u||h)&&S();let y=a.splice(0),g=l.splice(0);d=0;for(let k=0;k<y.length;k++){let A=y[k];if(!g[k]){E(A);continue}let P=A.match(/^(\[[^\]]+\]=)(.*)$/s);if(P){let N=an(e,P[2]);A=P[1]+N}if(A.includes("{")&&A.includes("}")){let N=new Z().parseWordFromString(A,!1,!1);if(N.parts.some(x=>x.type==="BraceExpansion")){let x=await vt(e,N);for(let C of x.values)E(C);continue}}E(A)}let b=[`${i}${o}(`],v=M(b[0]);for(let k=0;k<a.length;k++){let A=a[k],P,N=A.match(/^(\[[^\]]+\]=)(.*)$/s);if(N){let D=N[2].replace(/\\/g,"\\\\").replace(/"/g,'\\"');P=`${N[1]}"${D}"`}else A===""?P="''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(A)&&!A.startsWith("'")&&!A.startsWith('"')?P=`'${A.replace(/'/g,"'\\''")}'`:P=A;let x=`${k>0?" ":""}${P}`,C=M(x);if(C+1>e.limits.maxStringLength-v)throw new $(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");b.push(x),v+=C}return b.push(")"),b.join("")}async function hu(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),c=o.value.slice(r+a),u=t.parts.slice(n+1),f="";for(let m of i)f+=await se(e,{type:"Word",parts:[m]});f+=l;let d={type:"Word",parts:c!==""?[{type:"Literal",value:c},...u]:u},h=d.parts.length>0?await se(e,d):"";return`${f}${s?"+=":"="}${h}`}var dp=["tar","yq","xan","sqlite3","python3","python"];function pu(e){return dp.includes(e)}var te=Object.freeze({stdout:"",stderr:"",exitCode:0,internalStdinConsumed:0});function ee(e=""){return{stdout:e,stderr:"",exitCode:0}}function T(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function L(e,t,n){return{stdout:e,stderr:t,exitCode:n}}function be(e){return{stdout:"",stderr:"",exitCode:e?0:1,internalStdinConsumed:0}}function cn(e,t,n="",r=""){throw new $(e,t,n,r)}function mu(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new $(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function so(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new qt;return te}if(t.length>1)throw new q(1,"",`bash: break: too many arguments
119
- `);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
120
- `);n=r}throw new Qe(n)}async function io(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(h=>h);for(let h of d){let p=h.startsWith("/")?`${h}/${n}`:`${e.state.cwd}/${h}/${n}`;try{if((await e.fs.stat(p)).isDirectory){n=p,r=!0;break}}catch{}}}}let l=(n.startsWith("/")?n:`${e.state.cwd}/${n}`).split("/").filter(f=>f&&f!=="."),c="";for(let f of l)if(f==="..")c=c.split("/").slice(0,-1).join("/")||"/";else{c=c?`${c}/${f}`:`/${f}`;try{if(!(await e.fs.stat(c)).isDirectory)return T(`bash: cd: ${n}: Not a directory
121
- `)}catch{return T(`bash: cd: ${n}: No such file or directory
122
- `)}}let u=c||"/";if(s)try{u=await e.fs.realpath(u)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=u,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),ee(r?`${u}
123
- `:"")}function oo(e,t){return e.fs.resolvePath(e.state.cwd,t)}var hp=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function Es(e){return hp.includes(e)}async function bs(e,t,n){let r=oo(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 pp=["-nt","-ot","-ef"];function Ss(e){return pp.includes(e)}async function As(e,t,n,r){let s=oo(e,n),i=oo(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,c]=await Promise.all([e.fs.stat(s),e.fs.stat(i)]);return l.dev!==void 0&&l.ino!==void 0&&c.dev!==void 0&&c.ino!==void 0?l.dev===c.dev&&l.ino===c.ino:l.identity&&c.identity?l.identity===c.identity:!1}catch{return!1}default:return!1}}var mp=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function vs(e){return mp.has(e)}function ks(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 Er(e){return e==="="||e==="=="||e==="!="}function xs(e,t,n,r=!1,s=!1,i=!1,o=256){if(r){let l=qn(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 yp=new Set(["-z","-n"]);function Ps(e){return yp.has(e)}function $s(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Cs(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,c)=>e.state.env.get(c)||""),Yt(e,r,a)}let o;try{let a=new Z,l=re(a,s);o=await J(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=ve(e,r),l=e.state.currentLine;if(a.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
118
+ `,0;a=h}let l=`${t.array}[${a}]`,c=ae(e,t.array,a);if(c!==void 0)return Ss(e,l,c,r);if(a===0){let u=e.state.env.get(t.array);if(u!==void 0)return Ss(e,t.array,u,r)}if(e.state.options.nounset&&!(e.state.env.has(t.array)||Ne(e,t.array)))throw new ze(`${t.array}[${a}]`);return 0}return 0}case"ArithDoubleSubscript":throw new le("double subscript","","");case"ArithNumberSubscript":throw new le(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new le(t.message,"","",!0);case"ArithSingleQuote":{if(n)throw new le(`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 pp(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 ie(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 ie(e,t.operand.index.name);else if(t.operand.index){let f=await s(t.operand.index);l=String(f)}else return i;let c=Number.parseInt(ae(e,o,l)||"0",10)||0,u=t.operator==="++"?c+1:c-1;return H(e,o,l,String(u),a?"associative":"indexed"),t.prefix?u:c}if(t.operand.type==="ArithConcat"){let o="";for(let a of t.operand.parts)o+=await jn(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 jn(e,a,n,r);else t.operand.nameExpr.type==="ArithVariable"&&(o=t.operand.nameExpr.hasDollarPrefix?await ie(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(ae(e,o,a)||"0",10)||0,c=t.operator==="++"?l+1:l-1;return H(e,o,a,String(c)),t.prefix?c:l}}return i}return mp(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 ie(e,t.subscript.name)||"\\";else if(d){let h=await s(t.subscript);a=String(h)}else{let h=await s(t.subscript);if(h<0){let p=K(e,i);p.length>0&&(h=Math.max(...p.map(([y])=>typeof y=="number"?y:0))+1+h)}a=String(h)}}let l=a===void 0?e.state.env.get(o):ae(e,i,a),c=Number.parseInt(l||"0",10)||0,u=await s(t.value),f=pu(c,u,t.operator);return a===void 0?e.state.env.set(o,String(f)):H(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 jn(e,o,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)?await io(e,i,r):Number.parseInt(i,10)||0}case"ArithDynamicAssignment":{let i="";if(t.target.type==="ArithConcat")for(let u of t.target.parts)i+=await jn(e,u,n,r);else t.target.type==="ArithVariable"&&(i=t.target.hasDollarPrefix?await ie(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 u=await s(t.subscript);o=`${i}_${u}`}let a=Number.parseInt(e.state.env.get(o)||"0",10)||0,l=await s(t.value),c=pu(a,l,t.operator);return e.state.env.set(o,String(c)),c}case"ArithDynamicElement":{let i="";if(t.nameExpr.type==="ArithConcat")for(let c of t.nameExpr.parts)i+=await jn(e,c,n,r);else t.nameExpr.type==="ArithVariable"&&(i=t.nameExpr.hasDollarPrefix?await ie(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?Ss(e,a,l,r):0}default:return 0}}async function jn(e,t,n=!1,r=mu()){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await qn(e,t,n,r));case"ArithVariable":return t.hasDollarPrefix?await ie(e,t.name):t.name;case"ArithSpecialVar":return await ie(e,t.name);case"ArithBracedExpansion":return await As(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 jn(e,i,n,r);return s}default:return String(await qn(e,t,n,r))}}async function yu(e,t){let n="",r=0;for(let A of t.parts){let k=A.type==="Literal"?A.value:"\0",x=V(k);if(x>e.limits.maxStringLength-r)throw new C(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n+=k,r+=x}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=[],c=!1,u="",f=0,d=0,h=!1,p=!0,m=A=>{let k=V(A);if(k>e.limits.maxStringLength-d-f)throw new C(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u+=A,f+=k},y=(A,k=!1)=>{if(a.length>=e.limits.maxArrayElements)throw new C(`array assignment element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let x=V(A);if(x>e.limits.maxStringLength-d)throw new C(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");a.push(A),l.push(k),d+=x},b=()=>{y(u,p),u="",f=0,h=!1,p=!0};for(let A of t.parts)if(A.type==="Literal"){let k=A.value;if(!c){let x=k.indexOf("=(");x!==-1&&(c=!0,k=k.slice(x+2))}if(c){k.endsWith(")")&&(k=k.slice(0,-1));for(let x of k)/\s/.test(x)?(u||h)&&b():m(x)}}else if(c)if(A.type==="BraceExpansion")if(/^\[.+\]=/.test(u))m(Bn({type:"Word",parts:[A]}));else{(u||h)&&b();let x=await At(e,{type:"Word",parts:[A]});for(let D of x.values)y(D)}else{(A.type==="SingleQuoted"||A.type==="DoubleQuoted"||A.type==="Escaped")&&(h=!0),p=!1;let k=await se(e,{type:"Word",parts:[A]});m(k)}(u||h)&&b();let w=a.splice(0),E=l.splice(0);d=0;for(let A=0;A<w.length;A++){let k=w[A];if(!E[A]){y(k);continue}let x=k.match(/^(\[[^\]]+\]=)(.*)$/s);if(x){let D=an(e,x[2]);k=x[1]+D}if(k.includes("{")&&k.includes("}")){let D=new Q().parseWordFromString(k,!1,!1);if(D.parts.some($=>$.type==="BraceExpansion")){let $=await At(e,D);for(let N of $.values)y(N);continue}}y(k)}let S=[`${i}${o}(`],v=V(S[0]);for(let A=0;A<a.length;A++){let k=a[A],x,D=k.match(/^(\[[^\]]+\]=)(.*)$/s);if(D){let O=D[2].replace(/\\/g,"\\\\").replace(/"/g,'\\"');x=`${D[1]}"${O}"`}else k===""?x="''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(k)&&!k.startsWith("'")&&!k.startsWith('"')?x=`'${k.replace(/'/g,"'\\''")}'`:x=k;let $=`${A>0?" ":""}${x}`,N=V($);if(N+1>e.limits.maxStringLength-v)throw new C(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");S.push($),v+=N}return S.push(")"),S.join("")}async function gu(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),c=o.value.slice(r+a),u=t.parts.slice(n+1),f="";for(let m of i)f+=await se(e,{type:"Word",parts:[m]});f+=l;let d={type:"Word",parts:c!==""?[{type:"Literal",value:c},...u]:u},h=d.parts.length>0?await se(e,d):"";return`${f}${s?"+=":"="}${h}`}var wp=["tar","yq","xan","sqlite3","python3","python"];function wu(e){return wp.includes(e)}var te=Object.freeze({stdout:"",stderr:"",exitCode:0,internalStdinConsumed:0});function ee(e=""){return{stdout:e,stderr:"",exitCode:0}}function L(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function F(e,t,n){return{stdout:e,stderr:t,exitCode:n}}function be(e){return{stdout:"",stderr:"",exitCode:e?0:1,internalStdinConsumed:0}}function cn(e,t,n="",r=""){throw new C(e,t,n,r)}function Eu(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 oo(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new qt;return te}if(t.length>1)throw new G(1,"",`bash: break: too many arguments
119
+ `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new G(128,"",`bash: break: ${t[0]}: numeric argument required
120
+ `);n=r}throw new Qe(n)}async function ao(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
121
+ `);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(h=>h);for(let h of d){let p=h.startsWith("/")?`${h}/${n}`:`${e.state.cwd}/${h}/${n}`;try{if((await e.fs.stat(p)).isDirectory){n=p,r=!0;break}}catch{}}}}let l=(n.startsWith("/")?n:`${e.state.cwd}/${n}`).split("/").filter(f=>f&&f!=="."),c="";for(let f of l)if(f==="..")c=c.split("/").slice(0,-1).join("/")||"/";else{c=c?`${c}/${f}`:`/${f}`;try{if(!(await e.fs.stat(c)).isDirectory)return L(`bash: cd: ${n}: Not a directory
122
+ `)}catch{return L(`bash: cd: ${n}: No such file or directory
123
+ `)}}let u=c||"/";if(s)try{u=await e.fs.realpath(u)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=u,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),ee(r?`${n===""?"":u}
124
+ `:"")}function lo(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Ep=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function vs(e){return Ep.includes(e)}async function ks(e,t,n){let r=lo(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 bp=["-nt","-ot","-ef"];function xs(e){return bp.includes(e)}async function Ps(e,t,n,r){let s=lo(e,n),i=lo(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,c]=await Promise.all([e.fs.stat(s),e.fs.stat(i)]);return l.dev!==void 0&&l.ino!==void 0&&c.dev!==void 0&&c.ino!==void 0?l.dev===c.dev&&l.ino===c.ino:l.identity&&c.identity?l.identity===c.identity:!1}catch{return!1}default:return!1}}var Sp=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function $s(e){return Sp.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 br(e){return e==="="||e==="=="||e==="!="}function Ns(e,t,n,r=!1,s=!1,i=!1,o=256){if(r){let l=Gn(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 Ap=new Set(["-z","-n"]);function Rs(e){return Ap.has(e)}function Os(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Ds(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,c)=>e.state.env.get(c)||""),Yt(e,r,a)}let o;try{let a=new Q,l=re(a,s);o=await J(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=Ae(e,r),l=e.state.currentLine;if(a.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
124
125
  `,!1;if(o=Math.max(...a)+1+o,o<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
125
- `,!1}return Yt(e,r,o)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?xt(e,t).length>0:ve(e,t).length>0}async function un(e,t){switch(t.type){case"CondBinary":{let n=await se(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 se(e,t.right);s=Vn(i)}else s=await su(e,t.right);else Er(t.operator)&&!r?s=await iu(e,t.right):s=await se(e,t.right);if(Er(t.operator)){let i=e.state.shoptOptions.nocasematch;return xs(t.operator,n,s,!r,i,!0,e.limits.maxCallDepth)}if(vs(t.operator))return ks(t.operator,await gu(e,n),await gu(e,s));if(Ss(t.operator))return As(e,t.operator,n,s);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=Sp(s),l=ge(o,i?"i":"").match(n);if(Ee(e,"BASH_REMATCH"),l)for(let c=0;c<l.length;c++)G(e,"BASH_REMATCH",c,l[c]||"");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 se(e,t.operand);return Es(t.operator)?bs(e,t.operator,n):Ps(t.operator)?$s(t.operator,n):t.operator==="-v"?await Cs(e,n):t.operator==="-o"?lo(e,n):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await se(e,t.operand.expression.word)})`!=="":!await un(e,t.operand);case"CondAnd":return await un(e,t.left)?await un(e,t.right):!1;case"CondOr":return await un(e,t.left)?!0:await un(e,t.right);case"CondGroup":return await un(e,t.expression);case"CondWord":return await se(e,t.word)!=="";default:return!1}}async function br(e,t){if(t.length===0)return L("","",1);if(t.length===1)return be(!!t[0]);if(t.length===2){let r=t[0],s=t[1];return r==="("?T(`test: '(' without matching ')'
126
- `,2):Es(r)?be(await bs(e,r,s)):Ps(r)?be($s(r,s)):r==="!"?be(!s):r==="-v"?be(await Cs(e,s)):r==="-o"?be(lo(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"?T(`test: ${r}: unary operator expected
127
- `,2):L("","",1)}if(t.length===3){let r=t[0],s=t[1],i=t[2];if(Er(s))return be(xs(s,r,i));if(vs(s)){let o=Ns(r),a=Ns(i);return!o.valid||!a.valid?L("","",2):be(ks(s,o.value,a.value))}if(Ss(s))return be(await As(e,s,r,i));switch(s){case"-a":return be(r!==""&&i!=="");case"-o":return be(r!==""||i!=="");case">":return be(r>i);case"<":return be(r<i)}if(r==="!"){let o=await br(e,[s,i]);return L("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(r==="("&&i===")")return be(s!=="")}if(t.length===4){if(t[0]==="!"){let r=await br(e,t.slice(1));return L("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(t[0]==="("&&t[3]===")")return br(e,[t[1],t[2]])}let n=await Eu(e,t,0);return n.pos<t.length?T(`test: too many arguments
128
- `,2):be(n.value)}async function Eu(e,t,n){return gp(e,t,n)}async function gp(e,t,n){let{value:r,pos:s}=await yu(e,t,n);for(;t[s]==="-o";){let i=await yu(e,t,s+1);r=r||i.value,s=i.pos}return{value:r,pos:s}}async function yu(e,t,n){let{value:r,pos:s}=await ao(e,t,n);for(;t[s]==="-a";){let i=await ao(e,t,s+1);r=r&&i.value,s=i.pos}return{value:r,pos:s}}async function ao(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 ao(e,t,n+1);return{value:!s,pos:i}}return wp(e,t,n)}finally{r.release()}}async function wp(e,t,n){let r=t[n];if(r==="("){let{value:i,pos:o}=await Eu(e,t,n+1);return{value:i,pos:t[o]===")"?o+1:o}}let s=t[n+1];if(Er(s)){let i=r,o=t[n+2]??"";return{value:xs(s,i,o),pos:n+3}}if(vs(s)){let i=Ns(r),o=Ns(t[n+2]??"0");return!i.valid||!o.valid?{value:!1,pos:n+3}:{value:ks(s,i.value,o.value),pos:n+3}}if(Ss(s)){let i=r,o=t[n+2]??"";return{value:await As(e,s,i,o),pos:n+3}}if(Es(r)){let i=t[n+1]??"";return{value:await bs(e,r,i),pos:n+2}}if(Ps(r)){let i=t[n+1]??"";return{value:$s(r,i),pos:n+2}}if(r==="-v"){let i=t[n+1]??"";return{value:await Cs(e,i),pos:n+2}}if(r==="-o"){let i=t[n+1]??"";return{value:lo(e,i),pos:n+2}}return{value:r!==void 0&&r!=="",pos:n+1}}function qn(e,t,n=!1,r=!1,s=256){r&&Ep(t,s);let i=`^${bu(t,r)}$`;return ge(i,n?"is":"s").test(e)}function Ep(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 $(`extglob maximum depth (${t}) exceeded`,"recursion")}else e[s]===")"&&r.length>0&&r.pop()&&n--}}function bu(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=Su(e,r+1);if(i!==-1){let o=e.slice(r+2,i),a=Au(o),l=a.map(u=>bu(u,t)),c=l.length>0?l.join("|"):"(?:)";if(s==="@")n+=`(?:${c})`;else if(s==="*")n+=`(?:${c})*`;else if(s==="+")n+=`(?:${c})+`;else if(s==="?")n+=`(?:${c})?`;else if(s==="!")if(i<e.length-1){let f=a.map(h=>vu(h,t));if(f.every(h=>h!==null)&&f.every(h=>h===f[0])&&f[0]!==null){let h=f[0];if(h===0)n+="(?:.+)";else{let p=[];h>0&&p.push(`.{0,${h-1}}`),p.push(`.{${h+1},}`),p.push(`(?!(?:${c})).{${h}}`),n+=`(?:${p.join("|")})`}}else n+=`(?:(?!(?:${c})).)*?`}else n+=`(?!(?:${c})$).*`;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 Su(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 Au(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 vu(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=Su(e,r+1);if(i!==-1){if(s==="@"){let o=e.slice(r+2,i),l=Au(o).map(c=>vu(c,t));if(l.every(c=>c!==null)&&l.every(c=>c===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 lo(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 gu(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 wu(t);try{let n=new Z,r=re(n,t);return await J(e,r.expression)}catch{return wu(t)}}function bp(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 wu(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=bp(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 Ns(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 Sp(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=Ap(e,n);t+=r.converted,n=r.endIndex}else t+=e[n],n++;return t}function Ap(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 c=e.indexOf(":]",n+2);if(c!==-1){let u=e.slice(n+2,c);o+=vp(u),n=c+2;continue}}if(l==="["&&n+1<e.length){let c=e[n+1];if(c==="."||c==="="){let u=`${c}]`,f=e.indexOf(u,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 vp(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 co(e,t,n){if(n&&e.length>=n.maxElements)throw new $(`array element limit exceeded (${n.maxElements})`,"array_elements");e.push(t)}function Wt(e,t){if(t&&M(e)>t.maxStringBytes)throw new $(`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===`
129
- `)&&!s&&!i){a&&(co(n,r,t),r="",a=!1);continue}r+=l,a=!0}return a&&co(n,r,t),n}function Rs(e,t){if(t&&M(e)>t.maxStringBytes)throw new $(`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++;co(n,[s,i],t)}return n}function ku(e,t){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(n)return{name:n[1],isArray:!0,arrayElements:Wt(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 kp(e,t){try{let n=new Z,r=re(n,t);return await J(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}async function xu(e,t,n={}){let{name:r,isArray:s,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:l=!1,checkReadonly:c=!0}=n;if(c){let u=fe(e,r);if(u)return u}if(s&&i){e.executionScope.consumeWork(i.length,"array assignment");let u=xe(e,r),f=u?Me(u):void 0,d=e.state.env.get(r);try{Ee(e,r);for(let h=0;h<i.length;h++)G(e,r,h,i[h]);e.state.env.delete(r)}catch(h){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),h}}else if(a!==void 0&&o!==void 0){let u=await kp(e,a);G(e,r,u,o)}else o!==void 0&&e.state.env.set(r,o);return l&&Ze(e,r),null}function fn(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function uo(e,t){return e.state.localVarDepth?.get(t)}function Os(e,t){e.state.localVarDepth?.delete(t)}function Pu(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 Ds(e,t){let n=e.state.localVarStack?.get(t);if(!(!n||n.length===0))return n.pop()}function $u(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 fo=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Cu(e){return fo.has(e)}var ho=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Gn=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 po="__file__:",mo="__file_append__:",wo="__rw__:",yo="__dupout__:",go="__dupin__:",Se=3;function xp(e){let t=e.slice(wo.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 Nu(e,t){let n=Number.parseInt(e.slice(t.length),10);return Number.isNaN(n)?null:n}function Pp(e){if(e.startsWith(po))return{kind:"output",path:e.slice(po.length),append:!1};if(e.startsWith(mo))return{kind:"output",path:e.slice(mo.length),append:!0};if(e.startsWith(wo)){let t=xp(e);if(t)return{kind:"readwrite",...t}}if(e.startsWith(yo)){let t=Nu(e,yo);if(t!==null)return{kind:"dup-out",sourceFd:t}}if(e.startsWith(go)){let t=Nu(e,go);if(t!==null)return{kind:"dup-in",sourceFd:t}}return{kind:"input",content:e}}function Eo(e){switch(e.kind){case"input":return e.content;case"output":return`${e.append?mo:po}${e.path}`;case"readwrite":return`${wo}${e.path.length}:${e.path}:${e.position}:${e.content}`;case"dup-out":return`${yo}${e.sourceFd}`;case"dup-in":return`${go}${e.sourceFd}`;case"closed":throw new Error("Closed descriptors have no table encoding")}}function $p(e){return e.state.fileDescriptors??=new Map,e.state.fileDescriptors}function Cp(e,t,n){n?(e.state.inputFds??=new Set,e.state.inputFds.add(t)):e.state.inputFds?.delete(t)}function Hn(e,t){return e.state.fdAliases?.get(t)}function dn(e,t){return[...Hn(e,t)??[t]]}function Ru(e,t){let n=Hn(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 bo(e,t,n){if(t===n)return;e.state.fdAliases??=new Map;let r=Hn(e,n)??new Set([n]);r.add(t);for(let s of r)e.state.fdAliases.set(s,r)}function Is(e,t){return e.state.fileDescriptors?.get(t)}function nt(e,t){let n=Is(e,t);if(n!==void 0)return e.state.inputFds?.has(t)?{kind:"input",content:n}:Pp(n)}function Nn(e,t){return e.state.fileDescriptors?.has(t)===!0}function So(e,t,n,r){let s=$p(e);s.has(t)||mu(e),s.set(t,n),Cp(e,t,r)}function _s(e,t,n,r=!1){Ru(e,t),So(e,t,n,r)}function ct(e,t,n){_s(e,t,Eo(n),n.kind==="input")}function Rt(e,t){e.state.fileDescriptors?.delete(t),e.state.inputFds?.delete(t),Ru(e,t)}function Ts(e,t,n){let r=Is(e,n);return r===void 0?!1:(_s(e,t,r,e.state.inputFds?.has(n)===!0),bo(e,t,n),!0)}function Ao(e,t,n){let r=Is(e,n);if(r===void 0)return!1;if(t===n)return!0;let s=e.state.inputFds?.has(n)===!0,i=[...Hn(e,n)??[]].filter(a=>a!==n);Rt(e,n),_s(e,t,r,s);let o=i.find(a=>Nn(e,a));return o!==void 0&&bo(e,t,o),!0}function Ls(e,t){let n=nt(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 hn(e,t,n){let r=nt(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=Eo(s),o=s.kind==="input";for(let a of Hn(e,t)??[t])So(e,a,i,o)}async function vo(e,t,n,r,s){if(t.kind==="output")return await e.fs.appendFile(t.path,r,s),!0;let o=n.map(u=>nt(e,u)).find(u=>u?.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 c=Eo(l);for(let u of n)Nn(e,u)&&So(e,u,c,!1);return!0}function pn(e,t,n){if(t.has(n))return;let r=Hn(e,n);t.set(n,{raw:Is(e,n),isInput:e.state.inputFds?.has(n)===!0,aliases:r?[...r].filter(s=>s!==n):[]})}function Fs(e,t){let n=e.state.fileDescriptors;if(n)for(let[r,{raw:s,isInput:i,aliases:o}]of t){if(s===void 0){Rt(e,r);continue}_s(e,r,s,i);let a=o.find(l=>n.has(l));a!==void 0&&bo(e,r,a)}}function ko(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 Ou(e){if(e.fdVariable)return!1;let t=ko(e);return t!==null&&t>=Se}async function Np(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
126
+ `,!1}return Yt(e,r,o)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?xt(e,t).length>0:Ae(e,t).length>0}async function un(e,t){switch(t.type){case"CondBinary":{let n=await se(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 se(e,t.right);s=zn(i)}else s=await lu(e,t.right);else br(t.operator)&&!r?s=await cu(e,t.right):s=await se(e,t.right);if(br(t.operator)){let i=e.state.shoptOptions.nocasematch;return Ns(t.operator,n,s,!r,i,!0,e.limits.maxCallDepth)}if($s(t.operator))return Cs(t.operator,await Su(e,n),await Su(e,s));if(xs(t.operator))return Ps(e,t.operator,n,s);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=$p(s),l=ge(o,i?"i":"").match(n);if(Ee(e,"BASH_REMATCH"),l)for(let c=0;c<l.length;c++)H(e,"BASH_REMATCH",c,l[c]||"");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 se(e,t.operand);return vs(t.operator)?ks(e,t.operator,n):Rs(t.operator)?Os(t.operator,n):t.operator==="-v"?await Ds(e,n):t.operator==="-o"?uo(e,n):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await se(e,t.operand.expression.word)})`!=="":!await un(e,t.operand);case"CondAnd":return await un(e,t.left)?await un(e,t.right):!1;case"CondOr":return await un(e,t.left)?!0:await un(e,t.right);case"CondGroup":return await un(e,t.expression);case"CondWord":return await se(e,t.word)!=="";default:return!1}}async function Sr(e,t){if(t.length===0)return F("","",1);if(t.length===1)return be(!!t[0]);if(t.length===2){let r=t[0],s=t[1];return r==="("?L(`test: '(' without matching ')'
127
+ `,2):vs(r)?be(await ks(e,r,s)):Rs(r)?be(Os(r,s)):r==="!"?be(!s):r==="-v"?be(await Ds(e,s)):r==="-o"?be(uo(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
128
+ `,2):F("","",1)}if(t.length===3){let r=t[0],s=t[1],i=t[2];if(br(s))return be(Ns(s,r,i));if($s(s)){let o=Is(r),a=Is(i);return!o.valid||!a.valid?F("","",2):be(Cs(s,o.value,a.value))}if(xs(s))return be(await Ps(e,s,r,i));switch(s){case"-a":return be(r!==""&&i!=="");case"-o":return be(r!==""||i!=="");case">":return be(r>i);case"<":return be(r<i)}if(r==="!"){let o=await Sr(e,[s,i]);return F("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(r==="("&&i===")")return be(s!=="")}if(t.length===4){if(t[0]==="!"){let r=await Sr(e,t.slice(1));return F("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(t[0]==="("&&t[3]===")")return Sr(e,[t[1],t[2]])}let n=await vu(e,t,0);return n.pos<t.length?L(`test: too many arguments
129
+ `,2):be(n.value)}async function vu(e,t,n){return vp(e,t,n)}async function vp(e,t,n){let{value:r,pos:s}=await bu(e,t,n);for(;t[s]==="-o";){let i=await bu(e,t,s+1);r=r||i.value,s=i.pos}return{value:r,pos:s}}async function bu(e,t,n){let{value:r,pos:s}=await co(e,t,n);for(;t[s]==="-a";){let i=await co(e,t,s+1);r=r&&i.value,s=i.pos}return{value:r,pos:s}}async function co(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 co(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 vu(e,t,n+1);return{value:i,pos:t[o]===")"?o+1:o}}let s=t[n+1];if(br(s)){let i=r,o=t[n+2]??"";return{value:Ns(s,i,o),pos:n+3}}if($s(s)){let i=Is(r),o=Is(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(xs(s)){let i=r,o=t[n+2]??"";return{value:await Ps(e,s,i,o),pos:n+3}}if(vs(r)){let i=t[n+1]??"";return{value:await ks(e,r,i),pos:n+2}}if(Rs(r)){let i=t[n+1]??"";return{value:Os(r,i),pos:n+2}}if(r==="-v"){let i=t[n+1]??"";return{value:await Ds(e,i),pos:n+2}}if(r==="-o"){let i=t[n+1]??"";return{value:uo(e,i),pos:n+2}}return{value:r!==void 0&&r!=="",pos:n+1}}function Gn(e,t,n=!1,r=!1,s=256){r&&xp(t,s);let i=`^${ku(t,r)}$`;return ge(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 C(`extglob maximum depth (${t}) exceeded`,"recursion")}else e[s]===")"&&r.length>0&&r.pop()&&n--}}function ku(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=xu(e,r+1);if(i!==-1){let o=e.slice(r+2,i),a=Pu(o),l=a.map(u=>ku(u,t)),c=l.length>0?l.join("|"):"(?:)";if(s==="@")n+=`(?:${c})`;else if(s==="*")n+=`(?:${c})*`;else if(s==="+")n+=`(?:${c})+`;else if(s==="?")n+=`(?:${c})?`;else if(s==="!")if(i<e.length-1){let f=a.map(h=>$u(h,t));if(f.every(h=>h!==null)&&f.every(h=>h===f[0])&&f[0]!==null){let h=f[0];if(h===0)n+="(?:.+)";else{let p=[];h>0&&p.push(`.{0,${h-1}}`),p.push(`.{${h+1},}`),p.push(`(?!(?:${c})).{${h}}`),n+=`(?:${p.join("|")})`}}else n+=`(?:(?!(?:${c})).)*?`}else n+=`(?!(?:${c})$).*`;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 xu(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 Pu(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 $u(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=xu(e,r+1);if(i!==-1){if(s==="@"){let o=e.slice(r+2,i),l=Pu(o).map(c=>$u(c,t));if(l.every(c=>c!==null)&&l.every(c=>c===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 uo(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 Su(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 Au(t);try{let n=new Q,r=re(n,t);return await J(e,r.expression)}catch{return Au(t)}}function Pp(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 Au(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=Pp(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 Is(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 $p(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=Cp(e,n);t+=r.converted,n=r.endIndex}else t+=e[n],n++;return t}function Cp(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 c=e.indexOf(":]",n+2);if(c!==-1){let u=e.slice(n+2,c);o+=Np(u),n=c+2;continue}}if(l==="["&&n+1<e.length){let c=e[n+1];if(c==="."||c==="="){let u=`${c}]`,f=e.indexOf(u,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 Np(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 fo(e,t,n){if(n&&e.length>=n.maxElements)throw new C(`array element limit exceeded (${n.maxElements})`,"array_elements");e.push(t)}function Wt(e,t){if(t&&V(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===`
130
+ `)&&!s&&!i){a&&(fo(n,r,t),r="",a=!1);continue}r+=l,a=!0}return a&&fo(n,r,t),n}function _s(e,t){if(t&&V(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++;fo(n,[s,i],t)}return n}function Cu(e,t){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(n)return{name:n[1],isArray:!0,arrayElements:Wt(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 Rp(e,t){try{let n=new Q,r=re(n,t);return await J(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}async function Nu(e,t,n={}){let{name:r,isArray:s,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:l=!1,checkReadonly:c=!0}=n;if(c){let u=fe(e,r);if(u)return u}if(s&&i){e.executionScope.consumeWork(i.length,"array assignment");let u=ke(e,r),f=u?Me(u):void 0,d=e.state.env.get(r);try{Ee(e,r);for(let h=0;h<i.length;h++)H(e,r,h,i[h]);e.state.env.delete(r)}catch(h){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),h}}else if(a!==void 0&&o!==void 0){let u=await Rp(e,a);H(e,r,u,o)}else o!==void 0&&e.state.env.set(r,o);return l&&Ze(e,r),null}function fn(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function ho(e,t){return e.state.localVarDepth?.get(t)}function Ts(e,t){e.state.localVarDepth?.delete(t)}function Ru(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 Ls(e,t){let n=e.state.localVarStack?.get(t);if(!(!n||n.length===0))return n.pop()}function Ou(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 po=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Du(e){return po.has(e)}var mo=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Hn=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 yo="__file__:",go="__file_append__:",bo="__rw__:",wo="__dupout__:",Eo="__dupin__:",Pe=3;function Op(e){let t=e.slice(bo.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 Iu(e,t){let n=Number.parseInt(e.slice(t.length),10);return Number.isNaN(n)?null:n}function Dp(e){if(e.startsWith(yo))return{kind:"output",path:e.slice(yo.length),append:!1};if(e.startsWith(go))return{kind:"output",path:e.slice(go.length),append:!0};if(e.startsWith(bo)){let t=Op(e);if(t)return{kind:"readwrite",...t}}if(e.startsWith(wo)){let t=Iu(e,wo);if(t!==null)return{kind:"dup-out",sourceFd:t}}if(e.startsWith(Eo)){let t=Iu(e,Eo);if(t!==null)return{kind:"dup-in",sourceFd:t}}return{kind:"input",content:e}}function So(e){switch(e.kind){case"input":return e.content;case"output":return`${e.append?go:yo}${e.path}`;case"readwrite":return`${bo}${e.path.length}:${e.path}:${e.position}:${e.content}`;case"dup-out":return`${wo}${e.sourceFd}`;case"dup-in":return`${Eo}${e.sourceFd}`;case"closed":throw new Error("Closed descriptors have no table encoding")}}function Ip(e){return e.state.fileDescriptors??=new Map,e.state.fileDescriptors}function _p(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 dn(e,t){return[...Zn(e,t)??[t]]}function _u(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 Ao(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 Fs(e,t){return e.state.fileDescriptors?.get(t)}function lt(e,t){let n=Fs(e,t);if(n===void 0)return;let r=e.state.inputFds?.has(t)?{kind:"input",content:n}:Dp(n);return e.state.deviceFds?.has(t)&&(r.kind==="input"||r.kind==="readwrite")?{...r,device:!0}:r}function Nn(e,t){return e.state.fileDescriptors?.has(t)===!0}function vo(e,t,n,r,s=!1){let i=Ip(e);i.has(t)||Eu(e),i.set(t,n),_p(e,t,r),s?(e.state.deviceFds??=new Set,e.state.deviceFds.add(t)):e.state.deviceFds?.delete(t)}function Ms(e,t,n,r=!1,s=!1){_u(e,t),vo(e,t,n,r,s)}function vt(e,t,n){Ms(e,t,So(n),n.kind==="input",(n.kind==="input"||n.kind==="readwrite")&&n.device===!0)}function Rt(e,t){e.state.fileDescriptors?.delete(t),e.state.inputFds?.delete(t),e.state.deviceFds?.delete(t),_u(e,t)}function Bs(e,t,n){let r=Fs(e,n);return r===void 0?!1:(Ms(e,t,r,e.state.inputFds?.has(n)===!0,e.state.deviceFds?.has(n)===!0),Ao(e,t,n),!0)}function ko(e,t,n){let r=Fs(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);Rt(e,n),Ms(e,t,r,s,i);let a=o.find(l=>Nn(e,l));return a!==void 0&&Ao(e,t,a),!0}function Ws(e,t){let n=lt(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 hn(e,t,n){let r=lt(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=So(s),o=s.kind==="input";for(let a of Zn(e,t)??[t])vo(e,a,i,o,s.device===!0)}async function xo(e,t,n,r,s){if(t.kind==="output")return await e.fs.appendFile(t.path,r,s),!0;let o=n.map(u=>lt(e,u)).find(u=>u?.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 c=So(l);for(let u of n)Nn(e,u)&&vo(e,u,c,!1,l.device===!0);return!0}function pn(e,t,n){if(t.has(n))return;let r=Zn(e,n);t.set(n,{raw:Fs(e,n),isInput:e.state.inputFds?.has(n)===!0,isDevice:e.state.deviceFds?.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,isDevice:o,aliases:a}]of t){if(s===void 0){Rt(e,r);continue}Ms(e,r,s,i,o);let l=a.find(c=>n.has(c));l!==void 0&&Ao(e,r,l)}}function Po(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 Tu(e){if(e.fdVariable)return!1;let t=Po(e);return t!==null&&t>=Pe}async function Tp(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
130
131
  `;if(r.checkNoclobber&&e.state.options.noclobber&&!r.isClobber&&n!=="/dev/null")return`bash: ${n}: cannot overwrite existing file
131
132
  `}catch{return`bash: ${n}: cannot open redirect target
132
- `}return null}function Du(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 Sr="scoped",_u="bare",Tu="persistent",Rp=e=>new $(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors"),Op=(e,t)=>Nn(e,t)||(e.state.fileDescriptors?.size??0)<e.limits.maxFileDescriptors,Iu=e=>{let t=Math.max(e.state.nextFd??10,10);for(;Nn(e,t);)t+=1;return t},Ms=e=>{let t=e.endsWith("-"),n=t?e.slice(0,-1):e;return/^\d+$/.test(n)?{sourceFd:Number.parseInt(n,10),move:t}:null},Dp=(e,t,n)=>{let r=nt(e,t);return t<Se?r?{kind:"entry",entry:r,descriptors:dn(e,t)}:{kind:"standard",fd:t}:r?n?r.kind==="input"||r.kind==="readwrite"||r.kind==="dup-in"?{kind:"entry",entry:r,descriptors:dn(e,t)}:null:r.kind==="output"||r.kind==="readwrite"||r.kind==="dup-out"?{kind:"entry",entry:r,descriptors:dn(e,t)}:null:null};async function Zn(e,t,n,r,s=!0){let i=e.fs.resolvePath(e.state.cwd,t),o=await Np(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
133
- `,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
134
- `,1)}}return{entry:{kind:"output",path:i,append:n}}}async function xo(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
135
- `,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
136
- `,1)}}}}var Ip=async(e,t)=>{let n=await se(e,t.content);return t.stripTabs?n.split(`
133
+ `}return null}var Rn="/dev/null",zs=new Set([Rn,"/dev/zero","/dev/random","/dev/urandom"]);function Lu(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 Ar(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===Rn?{kind:"discard"}:{kind:"descriptor",source:e}:{kind:"invalid-output",fd:t}}var vr="scoped",Mu="bare",Bu="persistent",Lp=e=>new C(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors"),Fp=(e,t)=>Nn(e,t)||(e.state.fileDescriptors?.size??0)<e.limits.maxFileDescriptors,Fu=e=>{let t=Math.max(e.state.nextFd??10,10);for(;Nn(e,t);)t+=1;return t},$o=e=>{let t=e.endsWith("-"),n=t?e.slice(0,-1):e;return/^\d+$/.test(n)?{sourceFd:Number.parseInt(n,10),move:t}:null},Mp=(e,t,n)=>{let r=lt(e,t);return r?n?r.kind==="input"||r.kind==="readwrite"||r.kind==="dup-in"?{kind:"entry",entry:r,descriptors:dn(e,t)}:null:r.kind==="output"||r.kind==="readwrite"||r.kind==="dup-out"?{kind:"entry",entry:r,descriptors:dn(e,t)}:null:null},Bp=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===Rn)return{entry:{kind:"output",path:Rn,append:n}};let o=await Tp(e,i,t,{checkNoclobber:!n,isClobber:r});if(o)return{error:F("",o,1)};if(t==="/dev/full")return{error:F("",`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){let l=Ca(a),c=l&&Bp.get(l);if(c)return{error:F("",`bash: ${t}: ${c}
135
+ `,1)};if(!s)throw a;return{error:F("",`bash: ${t}: cannot open redirect target
136
+ `,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===Rn?"":await e.fs.readFile(r);return n?{entry:{kind:"readwrite",path:r,position:0,content:s,device:zs.has(r)}}:{entry:{kind:"input",content:s,device:zs.has(r)}}}catch{if(!n)return{error:F("",`bash: ${t}: No such file or directory
137
+ `,1)};try{return await e.fs.writeFile(r,"","binary"),{entry:{kind:"readwrite",path:r,position:0,content:"",device:zs.has(r)}}}catch{return{error:F("",`bash: ${t}: No such file or directory
138
+ `,1)}}}}var Wp=async(e,t)=>{let n=await se(e,t.content);return t.stripTabs?n.split(`
137
139
  `).map(r=>r.replace(/^\t+/,"")).join(`
138
- `):n};async function _p(e,t,n,r){let s=new Map,i=new Map,o=(y,g)=>e.state.closedStandardFds?.has(y)?{kind:"closed"}:nt(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,c,u=-1,f=a.get(0);f?.kind==="input"?(c=f.content,u=0):f?.kind==="readwrite"&&(c=f.content.slice(f.position),u=0);let d=()=>({targets:s,dupSources:i,standardRoutes:a,stdin:c,stdinSourceFd:u,error:null}),h=async(y,g,b)=>{let v={...d(),error:await mn(e,y,t.slice(0,g),s,i,a)};return b?{...v,errorCause:b}:v},p=async(y,g)=>{if(Op(e,y))return null;let b=Rp(e);return h(L("",b.stderr,$.EXIT_CODE),g,b)},m=(y,g)=>{y!==null&&y<Se&&a.set(y,g),r.policy==="persistent"&&y!==null&&y<Se&&(e.state.closedStandardFds?.delete(y),ct(e,y,g))},E=(y,g)=>{a.set(y,g),pn(e,r.standardSnapshot,y),r.standardClosedSnapshot.has(y)||r.standardClosedSnapshot.set(y,e.state.closedStandardFds?.has(y)===!0),e.state.closedStandardFds?.delete(y),ct(e,y,g)},S=(y,g)=>{if(y<Se){let b=a.get(y);return b?.kind==="closed"?null:b?{kind:"entry",entry:b,descriptors:dn(e,y)}:{kind:"standard",fd:y}}return Dp(e,y,g)};for(let y=0;y<t.length;y++){let g=t[y],b=ko(g);if(g.target.type==="HereDoc"){let A=await Ip(e,g.target);if(g.fdVariable){try{fe(e,g.fdVariable)}catch(x){if(!(x instanceof q))throw x;return h(L(x.stdout,x.stderr,x.exitCode),y,x)}let P=Iu(e),N=await p(P,y);if(N)return N;pn(e,r.fdVariableSnapshot,P),r.fdVariableEnv.has(g.fdVariable)||r.fdVariableEnv.set(g.fdVariable,e.state.env.get(g.fdVariable)),ct(e,P,{kind:"input",content:A}),e.state.env.set(g.fdVariable,String(P)),e.state.nextFd=P+1}else if(b!==null&&b>=Se){let P=await p(b,y);if(P)return P;pn(e,l,b),ct(e,b,{kind:"input",content:A})}else if(b===0||b===null)c=Ut(A),u=-1,m(b,{kind:"input",content:c});else{let P={kind:"input",content:A};r.policy==="persistent"?m(b,P):E(b,P)}continue}let v,k=g.operator===">&"||g.operator==="<&";if(k){if(to(e,g.target))return h(L("",`bash: $@: ambiguous redirect
139
- `,1),y);v=await se(e,g.target)}else if(g.operator==="<<<")v=await se(e,g.target);else{let A=await cu(e,g.target);if("error"in A)return h(L("",A.error,1),y);v=A.target}if(s.set(y,v),v.includes("\0"))return h(L("",`bash: ${v.replace(/\0/g,"")}: No such file or directory
140
- `,1),y);if(g.fdVariable){try{fe(e,g.fdVariable)}catch(D){if(!(D instanceof q))throw D;return h(L(D.stdout,D.stderr,D.exitCode),y,D)}if(k&&v==="-"){let D=Number.parseInt(e.state.env.get(g.fdVariable)??"",10);Number.isNaN(D)||(pn(e,r.fdVariableSnapshot,D),Rt(e,D));continue}let A=Iu(e),P=k?Ms(v):null;if(P&&!S(P.sourceFd,g.operator==="<&"))return h(L("",`bash: ${P.sourceFd}: Bad file descriptor
141
- `,1),y);if(!(P?.move===!0&&P.sourceFd>=Se)){let D=await p(A,y);if(D)return D}pn(e,r.fdVariableSnapshot,A),r.fdVariableEnv.has(g.fdVariable)||r.fdVariableEnv.set(g.fdVariable,e.state.env.get(g.fdVariable));let x,C;if(k){let D=P;if(D){let V=S(D.sourceFd,g.operator==="<&");if(!V)return h(L("",`bash: ${D.sourceFd}: Bad file descriptor
142
- `,1),y);C=D,V.kind==="standard"?x={kind:g.operator==="<&"?"dup-in":"dup-out",sourceFd:V.fd}:D.sourceFd<Se&&(x=V.entry)}else{if(g.operator==="<&")return h(L("",`bash: ${v}: ambiguous redirect
143
- `,1),y);let V=await Zn(e,v,!1,!1);if(V.error)return h(V.error,y);x=V.entry}}else if(g.operator===">"||g.operator===">|"||g.operator===">>"||g.operator==="&>"||g.operator==="&>>"){let D=g.operator===">>"||g.operator==="&>>",V=await Zn(e,v,D,g.operator===">|");if(V.error)return h(V.error,y);x=V.entry}else if(g.operator==="<<<")x={kind:"input",content:`${v}
144
- `};else if(g.operator==="<"||g.operator==="<>"){let D=await xo(e,v,g.operator==="<>");if(D.error)return h(D.error,y);x=D.entry}if(C&&C.sourceFd>=Se){if(!(C.move?Ao(e,A,C.sourceFd):Ts(e,A,C.sourceFd)))return h(L("",`bash: ${C.sourceFd}: Bad file descriptor
145
- `,1),y)}else x&&ct(e,A,x);C?.move&&C.sourceFd!==A&&C.sourceFd<Se&&Rt(e,C.sourceFd),e.state.env.set(g.fdVariable,String(A)),e.state.nextFd=A+1;continue}if(Ou(g)){let A=b;if(k&&v==="-"){pn(e,l,A),Rt(e,A);continue}let P=k?Ms(v):null;if(P&&!S(P.sourceFd,g.operator==="<&"))return h(L("",`bash: ${P.sourceFd}: Bad file descriptor
146
- `,1),y);if(!(P?.move===!0&&P.sourceFd>=Se)){let x=await p(A,y);if(x)return x}if(pn(e,l,A),k){let x=P;if(!x){if(g.operator==="<&")return h(L("",`bash: ${v}: ambiguous redirect
147
- `,1),y);let D=await Zn(e,v,!1,!1);if(D.error)return h(D.error,y);ct(e,A,D.entry);continue}let C=S(x.sourceFd,g.operator==="<&");if(!C)return h(L("",`bash: ${x.sourceFd}: Bad file descriptor
148
- `,1),y);if(C.kind==="standard")ct(e,A,{kind:g.operator==="<&"?"dup-in":"dup-out",sourceFd:C.fd});else if(x.sourceFd<Se)ct(e,A,C.entry);else if(!(x.move?Ao(e,A,x.sourceFd):Ts(e,A,x.sourceFd)))return h(L("",`bash: ${x.sourceFd}: Bad file descriptor
149
- `,1),y);x.move&&x.sourceFd!==A&&x.sourceFd<Se&&Rt(e,x.sourceFd);continue}if(g.operator===">"||g.operator===">|"||g.operator===">>"){let x=await Zn(e,v,g.operator===">>",g.operator===">|");if(x.error)return h(x.error,y);ct(e,A,x.entry)}else if(g.operator==="<<<")ct(e,A,{kind:"input",content:`${v}
150
- `});else if(g.operator==="<"||g.operator==="<>"){let x=await xo(e,v,g.operator==="<>");if(x.error)return h(x.error,y);ct(e,A,x.entry)}continue}if(k){if(v==="-"){b===0&&(c="",u=-1),b!==null&&b<Se&&(a.set(b,{kind:"closed"}),r.policy==="persistent"&&(Rt(e,b),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(b)));continue}let A=Ms(v);if(!A){if(g.operator==="<&")return h(L("",`bash: ${v}: ambiguous redirect
151
- `,1),y);let N=await Zn(e,v,!1,!1,!1);if(N.error)return h(N.error,y);let x=N.entry;i.set(y,{kind:"entry",entry:x,descriptors:[]}),g.fd==null?(m(1,x),m(2,x)):m(b,x);continue}let P=S(A.sourceFd,g.operator==="<&");if(!P)return h(L("",`bash: ${A.sourceFd}: Bad file descriptor
152
- `,1),y);if(i.set(y,P),P.kind==="entry"&&r.policy==="persistent"&&b!==null&&b<Se&&A.sourceFd>=Se){if(!Ts(e,b,A.sourceFd))return h(L("",`bash: ${A.sourceFd}: Bad file descriptor
153
- `,1),y);a.set(b,nt(e,b)),e.state.closedStandardFds?.delete(b)}else P.kind==="standard"?m(b,{kind:g.operator==="<&"?"dup-in":"dup-out",sourceFd:P.fd}):m(b,P.entry);if(g.operator==="<&"&&b===0)if(P.kind==="standard")c=P.fd===0?n:"",u=-1;else if(P.entry.kind==="input"||P.entry.kind==="readwrite"){let N=A.sourceFd<Se&&!Nn(e,A.sourceFd)?{content:P.entry.kind==="input"?P.entry.content:P.entry.content.slice(P.entry.position)}:Ls(e,A.sourceFd);if("error"in N)return h(L("",`bash: ${A.sourceFd}: Bad file descriptor
154
- `,1),y);c=N.content,u=Nn(e,A.sourceFd)?A.sourceFd:-1}else c=n,u=-1;A.move&&(A.sourceFd>=Se?Rt(e,A.sourceFd):(a.set(A.sourceFd,{kind:"closed"}),r.policy==="persistent"&&(Rt(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 h(A.error,y);let P=A.entry;g.operator==="&>"||g.operator==="&>>"?(m(1,P),m(2,P)):m(b,P);continue}if(g.operator==="<<<")c=Ut(`${v}
155
- `),u=-1,m(b,{kind:"input",content:c});else if(g.operator==="<"){let A=e.fs.resolvePath(e.state.cwd,v);try{c=await In(e.fs,A),u=-1,m(b,{kind:"input",content:c})}catch{return h(L("",`bash: ${v}: No such file or directory
156
- `,1),y)}}else if(g.operator==="<>"){let A=await xo(e,v,!0);if(A.error)return h(A.error,y);let P=A.entry;m(b,P),b===0&&P.kind==="readwrite"&&(c=P.content,u=-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="")=>_p(e,t,i,r),finish:()=>{if(!s){if(s=!0,n!=="persistent"&&Fs(e,r.numericSnapshot),n!=="persistent"){Fs(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"){Fs(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 Kn(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 Po(e,t,n,r){let s=t instanceof q||t instanceof Le||t instanceof Ve?t.exitCode:t instanceof $?$.EXIT_CODE:0,i=await mn(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:M(i.stdout),stderr:M(i.stderr)}}async function rt(e,t,n,r){let s=Qn(e,t,Sr),i;try{if(i=await s.prepare(n),i.error)return Kn(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 mn(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 _n)||!i||await Po(e,o,t,i),o}finally{s.finish()}}async function mn(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:c,exitCode:u}=t,d=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",h=b=>d,p={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?p:b.fd===2?m:null},S=b=>{let v=i.get(b)??nt(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:dn(e,b)}}:null:null};p=S(1)??p,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 k=r.get(b);if(k!==void 0)switch(v.operator){case">":case">|":case">>":{let A=v.fd??1;if(A!==1&&A!==2)break;let P=v.operator===">>";if(k==="/dev/stdout"){A===2&&(m=p);break}if(k==="/dev/stderr"){A===1&&(p=m);break}if(k==="/dev/full"){c+=`bash: echo: write error: No space left on device
157
- `,u=1,A===1&&(l="");break}if(k==="/dev/null"&&A===2){m={kind:"discard"};break}let N=e.fs.resolvePath(e.state.cwd,k);A===1?p={kind:"file",path:N,append:P}:m={kind:"file",path:N,append:P};break}case">&":case"<&":{let A=v.fd??(v.operator==="<&"?0:1);if(A>=Se||A===0)break;if(k==="-"){A===1?p={kind:"discard"}:m={kind:"discard"};break}let P=E(s.get(b));if(!P)break;v.fd==null&&Ms(k)===null?(p=P,m=P):A===1?p=P:A===2&&(m=P);break}case"&>":{p={kind:"file",path:e.fs.resolvePath(e.state.cwd,k),append:!1},m=p;break}case"&>>":{p={kind:"file",path:e.fs.resolvePath(e.state.cwd,k),append:!0},m=p;break}}}if(l!==""||c!==""){let b=l,v=c;l="",c="",p.kind==="invalid-output"&&b!==""&&(b="",v+=`${a?"":"bash: "}${o}: write error: Bad file descriptor
158
- `,u=1),m.kind==="invalid-output"&&(v="");let k=async(A,P,N)=>{A.append?await e.fs.appendFile(A.path,P,N):await e.fs.writeFile(A.path,P,N)};if(p===m&&(p.kind==="file"||p.kind==="descriptor")){let A=b+v;A!==""&&(p.kind==="file"?await k(p,A,h(A)):await vo(e,p.source.entry,p.source.descriptors,A,h(A)))}else for(let[A,P,N]of[[b,p,!0],[v,m,!1]])if(A!=="")switch(P.kind){case"live-stdout":l+=A;break;case"live-stderr":c+=A;break;case"file":await k(P,A,N?h(A):Du(A));break;case"descriptor":await vo(e,P.source.entry,P.source.descriptors,A,N?h(A):Du(A));break;case"invalid-output":break;case"discard":break}}let y=L(l,c,u);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=M(y.stdout),k=M(y.stderr),A=Math.min(v,b);y.internalOutputAccounting={stdout:A,stderr:Math.min(k,b-A)},e.executionScope.accountResult(y,"redirection")}else t.internalOutputAccounting&&(y.internalOutputAccounting=t.internalOutputAccounting);return y}function Lu(e,t){if(e.state.options.posix&&fo.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
159
- `;throw new q(2,"",r)}let n={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,n),te}async function Bs(e,t,n,r="",s,i=!1){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,cn(`${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 h=0;h<l;h++){let p=String(h+1);o.set(p,e.state.env.get(p)),h<n.length?e.state.env.set(p,n[h]):e.state.env.delete(p)}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 c=!1,u=()=>{if(c)return;c=!0;let h=e.state.localScopes.length-1,p=e.state.localScopes.pop(),m=e.state.localArrayScopes?.pop();if(p)for(let[E,S]of p)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,Me(S)),e.state.associativeArrays??=new Set,S.kind==="associative"?e.state.associativeArrays.add(E):e.state.associativeArrays.delete(E))}if($u(e,h),e.state.fullyUnsetLocals)for(let[E,S]of e.state.fullyUnsetLocals.entries())S===h&&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,Sr);try{if(f=await d.prepare(r),f.error)return Kn(f);let h=f.stdin??r,p=i||f.stdin!==void 0||r!=="",m=await e.executeCommand(t.body,h,p);return mn(e,m,t.redirections,f.targets,f.dupSources,f.standardRoutes)}catch(h){if(h instanceof _n&&f&&(await Po(e,h,t.redirections,f),h instanceof Le))return L(h.stdout,h.stderr,h.exitCode);throw h}finally{d.finish(),u()}}var Mu=e=>e.type==="Escaped"?F.literal(`\\${e.value}`):e.type==="DoubleQuoted"?{...e,parts:e.parts.map(Mu)}:e,Bu=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],No=[".",":","[","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"],Tp=["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"],Lp=No;async function Ro(e,t){let n=[],r=null,s="",i="",o=null,a=!1,l=!1,c=!1,u=null,f=null,d=null,h=[],p=["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 k=0;k<t.length;k++){let A=t[k];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(k++,k>=t.length)return T(`compgen: -A: option requires an argument
160
- `,2);let P=t[k];if(!p.includes(P))return T(`compgen: ${P}: invalid action name
161
- `,2);n.push(P)}else if(A==="-W"){if(k++,k>=t.length)return T(`compgen: -W: option requires an argument
162
- `,2);r=t[k]}else if(A==="-P"){if(k++,k>=t.length)return T(`compgen: -P: option requires an argument
163
- `,2);s=t[k]}else if(A==="-S"){if(k++,k>=t.length)return T(`compgen: -S: option requires an argument
164
- `,2);i=t[k]}else if(A==="-o"){if(k++,k>=t.length)return T(`compgen: -o: option requires an argument
165
- `,2);let P=t[k];if(P==="plusdirs")a=!0;else if(P==="dirnames")l=!0;else if(P==="default")c=!0;else if(!(P==="filenames"||P==="nospace"||P==="bashdefault"||P==="noquote"))return T(`compgen: ${P}: invalid option name
166
- `,2)}else if(A==="-F"){if(k++,k>=t.length)return T(`compgen: -F: option requires an argument
167
- `,2);f=t[k]}else if(A==="-C"){if(k++,k>=t.length)return T(`compgen: -C: option requires an argument
168
- `,2);d=t[k]}else if(A==="-X"){if(k++,k>=t.length)return T(`compgen: -X: option requires an argument
169
- `,2);u=t[k]}else if(A==="-G"){if(k++,k>=t.length)return T(`compgen: -G: option requires an argument
170
- `,2)}else if(A==="--"){h.push(...t.slice(k+1));break}else A.startsWith("-")||h.push(A)}o=h[0]??null;let m=[],E=new Set,S=()=>e.limits.maxArrayElements-m.length,y=k=>{for(let A of k){if(m.length>=e.limits.maxArrayElements)throw new $(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(M(A)>e.limits.maxStringLength)throw new $(`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 k=await $o(e,o,S());y(k)}if(c){let k=await Fu(e,o,S());y(k)}for(let k of n)if(k==="variable"){let A=Fp(e,o,S());y(A)}else if(k==="export"){let A=Mp(e,o,S());y(A)}else if(k==="function"){let A=Bp(e,o,S());y(A)}else if(k==="builtin"){let A=Wp(e,o,S());y(A)}else if(k==="keyword"){let A=Vp(e,o,S());y(A)}else if(k==="alias"){let A=zp(e,o,S());y(A)}else if(k==="shopt"){let A=Up(e,o,S());y(A)}else if(k==="helptopic"){let A=jp(e,o,S());y(A)}else if(k==="directory"){let A=await $o(e,o,S());y(A)}else if(k==="file"){let A=await Fu(e,o,S());y(A)}else if(k==="user"){let A=qp(e,o,S());y(A)}else if(k==="command"){let A=await Gp(e,o,S());y(A)}if(r!==null)try{let k=await Hp(e,r),A=Zp(e,k,S(),o);for(let P of A)y([P])}catch(k){if(k instanceof $)throw k;return L("","",1)}if(a){let k=await $o(e,o,S(),E);for(let A of k)E.has(A)||y([A])}let g="";if(f!==null){let k=e.state.functions.get(f);if(k){let A=new Map,P=xe(e,"COMP_WORDS"),N=P?Me(P):void 0;Ee(e,"COMP_WORDS"),lr(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 x=xe(e,"COMPREPLY"),C=x?Me(x):void 0,D=e.state.env.get("COMPREPLY");Ee(e,"COMPREPLY"),e.state.env.delete("COMPREPLY");let V=["compgen",h[0]??"",""];try{let K=await Bs(e,k,V,"");if(K.exitCode!==0)return Co(e,A),Xn(e,"COMP_WORDS",N),Xn(e,"COMPREPLY",C),D!==void 0&&e.state.env.set("COMPREPLY",D),L("",K.stderr,1);g=K.stdout;let R=Qp(e,S());y(R)}catch(K){if(K instanceof $)throw K;return Co(e,A),Xn(e,"COMP_WORDS",N),Xn(e,"COMPREPLY",C),D!==void 0&&e.state.env.set("COMPREPLY",D),L("","",1)}Co(e,A),Xn(e,"COMP_WORDS",N),Xn(e,"COMPREPLY",C),D!==void 0&&e.state.env.set("COMPREPLY",D)}}if(d!==null)try{let k=He(d),A=await e.executeScript(k);if(A.exitCode!==0)return L("",A.stderr,A.exitCode);if(A.stdout)for(let P of Kp(A.stdout))P.length>0&&y([P])}catch(k){if(k.name==="ParseException")return T(`compgen: -C: ${k.message}
171
- `,2);throw k}let b=m;if(u!==null){let k=u.startsWith("!"),A=k?u.slice(1):u;b=m.filter(P=>{let N=qn(P,A,!1,!0,e.limits.maxCallDepth);return k?N:!N})}if(b.length===0&&o!==null)return L(g,"",1);let v=new Tn(e.limits.maxOutputSize,"compgen");v.append(g);for(let k of b)v.append(s).append(k).append(i).append(`
172
- `);return ee(v.build())}function Fp(e,t,n){let r=ut(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 Mp(e,t,n){let r=ut(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 Bp(e,t,n){let r=ut(e,t,n);for(let s of e.state.functions.keys())r.add(s);return r.build()}function Wp(e,t,n){let r=ut(e,t,n);for(let s of No)r.add(s);return r.build()}function Vp(e,t,n){let r=ut(e,t,n);for(let s of Bu)r.add(s);return r.build()}function zp(e,t,n){let r=ut(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 Up(e,t,n){let r=ut(e,t,n);for(let s of Tp)r.add(s);return r.build()}function jp(e,t,n){let r=ut(e,t,n);for(let s of Lp)r.add(s);return r.build()}async function $o(e,t,n=e.limits.maxArrayElements,r){let s=ut(e,null,n,r);try{let i=e.state.cwd,o=t??"";if(t){let l=t.lastIndexOf("/");if(l!==-1){let c=t.slice(0,l)||"/";o=t.slice(l+1),c.startsWith("/")?i=c:i=`${e.state.cwd}/${c}`}}let a=await e.fs.readdir(i);for(let l of a){e.executionScope.consumeWork(1,"compgen directory scan");let c=`${i}/${l}`;try{if((await e.fs.stat(c)).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(u){if(u instanceof $)throw u}}}catch(i){if(i instanceof $)throw i}return s.build()}async function Fu(e,t,n=e.limits.maxArrayElements){let r=ut(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("/"),c=t.slice(0,l+1);r.add(c+a)}else r.add(a)}catch(s){if(s instanceof $)throw s}return r.build()}function qp(e,t,n){let r=ut(e,t,n);return r.add("root"),r.add("nobody"),r.build()}async function Gp(e,t,n){let r=ut(e,t,n);for(let i of No)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 Bu)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 $)throw o}return r.build()}function ut(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 $(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(M(i)>e.limits.maxStringLength)throw new $(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");s.add(i)}},build(){return Array.from(s).sort()}}}async function Hp(e,t){let r=new Z().parseWordFromString(t,!1,!1);return await se(e,F.word(r.parts.map(Mu)))}function Zp(e,t,n,r){let s=e.state.env.get("IFS")??`
173
- `;if(s.length===0){if(r!==null&&!t.startsWith(r))return[];if(n===0)throw new $(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");return[t]}let i=new Set(s.split("")),o=[],a=u=>{if(!(r!==null&&!u.startsWith(r))){if(o.length>=n)throw new $(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");o.push(u)}},l="",c=0;for(;c<t.length;){let u=t[c];if(u==="\\"&&c+1<t.length){let f=t[c+1];l+=f,c+=2}else i.has(u)?(l.length>0&&(a(l),l=""),c++):(l+=u,c++)}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 Xn(e,t,n){e.state.arrays??=new Map,n?e.state.arrays.set(t,Me(n)):e.state.arrays.delete(t)}function Qp(e,t){let n=[],r=s=>{if(n.length>=t)throw new $(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");n.push(s)};if(Ne(e,"COMPREPLY")){let s=Q(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*Kp(e){let t=0;for(;t<=e.length;){let n=e.indexOf(`
174
- `,t),r=n===-1?e.length:n;if(r>t&&(yield e.slice(t,r)),n===-1)return;t=n+1}}function Ar(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n===127)return!0}return!1}function Oo(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 Wu(e){if(Ar(e))return Vu(e);if(e==="")return 2;if(/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e))return M(e);let t=M(e)+2;for(let n of e)n==="'"&&(t+=3);return t}function Ae(e){return Ar(e)?Oo(e):e===""?"''":/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Ws(e){if(Ar(e))return Vu(e);let t=M(e)+2;for(let n of e)(n==="\\"||n==='"'||n==="$"||n==="`")&&t++;return t}function yn(e){return Ar(e)?Oo(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}function Vu(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+=M(n)}return t}function vr(e){return Ar(e)?Oo(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}var Xp=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Io(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=!1,i,o,a,l=[],c=[],u=[];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 T(`complete: -W: option requires an argument
175
- `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return T(`complete: -F: option requires an argument
176
- `,2);o=t[f]}else if(d==="-o"){if(f++,f>=t.length)return T(`complete: -o: option requires an argument
177
- `,2);let h=t[f];if(!Xp.includes(h))return T(`complete: ${h}: invalid option name
178
- `,2);l.push(h)}else if(d==="-A"){if(f++,f>=t.length)return T(`complete: -A: option requires an argument
179
- `,2);c.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return T(`complete: -C: option requires an argument
180
- `,2);a=t[f]}else if(d==="-G"){if(f++,f>=t.length)return T(`complete: -G: option requires an argument
181
- `,2)}else if(d==="-P"){if(f++,f>=t.length)return T(`complete: -P: option requires an argument
182
- `,2)}else if(d==="-S"){if(f++,f>=t.length)return T(`complete: -S: option requires an argument
183
- `,2)}else if(d==="-X"){if(f++,f>=t.length)return T(`complete: -X: option requires an argument
184
- `,2)}else if(d==="--"){u.push(...t.slice(f+1));break}else d.startsWith("-")||u.push(d)}if(r){if(u.length===0)return e.state.completionSpecs.clear(),e.state.defaultCompletionSpec=void 0,e.state.emptyCompletionSpec=void 0,ee("");for(let f of u)e.state.completionSpecs.delete(f);return ee("")}if(n)return u.length===0?Do(e):Do(e,u);if(t.length===0||u.length===0&&!i&&!o&&!a&&l.length===0&&c.length===0&&!s)return Do(e);if(o&&u.length===0&&!s)return T(`complete: -F: option requires a command name
185
- `,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),c.length>0&&(f.actions=c),e.state.defaultCompletionSpec=f,ee("")}for(let f of u){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),c.length>0&&(d.actions=c),e.state.completionSpecs.set(f,d)}return ee("")}function Do(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
186
- `;return L("",i,1)}return ee("")}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(`
140
+ `):n};async function Vp(e,t,n,r){let s=(v,A)=>e.state.closedStandardFds?.has(v)?{kind:"closed"}:lt(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:Ar({kind:"entry",entry:i.get(1),descriptors:dn(e,1)},1),stderr:Ar({kind:"entry",entry:i.get(2),descriptors:dn(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===Rn?{kind:"discard"}:{kind:"file",path:v.path,append:v.append},c=r.numericSnapshot,u,f=-1,d=!1,h=!1,p=i.get(0);p?.kind==="input"?(u=p.content,f=0,h=p.device===!0):p?.kind==="readwrite"?(u=p.content.slice(p.position),f=0,h=p.device===!0):p?.kind==="closed"&&(u="",h=!0);let m=()=>({outputRoutes:o,stdin:u,stdinSourceFd:f,stdinReplaced:d,stdinUnavailable:h,error:null}),y=async(v,A,k)=>{let x={...m(),error:await mn(e,v,A>0,o)};return k?{...x,errorCause:k}:x},b=async(v,A)=>{if(Fp(e,v))return null;let k=Lp(e);return y(F("",k.stderr,C.EXIT_CODE),A,k)},w=(v,A,k)=>{v!==null&&v<Pe&&i.set(v,A),(v===1||v===2)&&a(v,k??Ar({kind:"entry",entry:A,descriptors:r.policy==="persistent"?[v]:[]},v)),r.policy==="persistent"&&v!==null&&v<Pe&&(e.state.closedStandardFds?.delete(v),vt(e,v,A))},E=(v,A)=>{i.set(v,A),(v===1||v===2)&&a(v,Ar({kind:"entry",entry:A,descriptors:[]},v)),pn(e,r.standardSnapshot,v),r.standardClosedSnapshot.has(v)||r.standardClosedSnapshot.set(v,e.state.closedStandardFds?.has(v)===!0),e.state.closedStandardFds?.delete(v),vt(e,v,A)},S=(v,A)=>{if(v<Pe){let k=i.get(v);return k?.kind==="closed"?null:{kind:"entry",entry:k,descriptors:dn(e,v)}}return Mp(e,v,A)};for(let v=0;v<t.length;v++){let A=t[v],k=Po(A);if(A.target.type==="HereDoc"){let $=await Wp(e,A.target);if(A.fdVariable){try{fe(e,A.fdVariable)}catch(R){if(!(R instanceof G))throw R;return y(F(R.stdout,R.stderr,R.exitCode),v,R)}let N=Fu(e),O=await b(N,v);if(O)return O;pn(e,r.fdVariableSnapshot,N),r.fdVariableEnv.has(A.fdVariable)||r.fdVariableEnv.set(A.fdVariable,e.state.env.get(A.fdVariable)),vt(e,N,{kind:"input",content:$}),e.state.env.set(A.fdVariable,String(N)),e.state.nextFd=N+1}else if(k!==null&&k>=Pe){let N=await b(k,v);if(N)return N;pn(e,c,k),vt(e,k,{kind:"input",content:$})}else if(k===0||k===null)u=Ut($),f=-1,w(k,{kind:"input",content:u}),d=!0,h=!1;else{let N={kind:"input",content:$};r.policy==="persistent"?w(k,N):E(k,N)}continue}let x,D=A.operator===">&"||A.operator==="<&";if(D){if(ro(e,A.target))return y(F("",`bash: $@: ambiguous redirect
141
+ `,1),v);x=await se(e,A.target)}else if(A.operator==="<<<")x=await se(e,A.target);else{let $=await hu(e,A.target);if("error"in $)return y(F("",$.error,1),v);x=$.target}if(x.includes("\0"))return y(F("",`bash: ${x.replace(/\0/g,"")}: No such file or directory
142
+ `,1),v);if(A.fdVariable){try{fe(e,A.fdVariable)}catch(P){if(!(P instanceof G))throw P;return y(F(P.stdout,P.stderr,P.exitCode),v,P)}if(D&&x==="-"){let P=Number.parseInt(e.state.env.get(A.fdVariable)??"",10);Number.isNaN(P)||(pn(e,r.fdVariableSnapshot,P),Rt(e,P));continue}let $=Fu(e),N=D?$o(x):null;if(N&&!S(N.sourceFd,A.operator==="<&"))return y(F("",`bash: ${N.sourceFd}: Bad file descriptor
143
+ `,1),v);if(!(N?.move===!0&&N.sourceFd>=Pe)){let P=await b($,v);if(P)return P}pn(e,r.fdVariableSnapshot,$),r.fdVariableEnv.has(A.fdVariable)||r.fdVariableEnv.set(A.fdVariable,e.state.env.get(A.fdVariable));let R,W;if(D){let P=N;if(P){let B=S(P.sourceFd,A.operator==="<&");if(!B)return y(F("",`bash: ${P.sourceFd}: Bad file descriptor
144
+ `,1),v);W=P,P.sourceFd<Pe&&(R=B.entry)}else{if(A.operator==="<&")return y(F("",`bash: ${x}: ambiguous redirect
145
+ `,1),v);let B=await Qn(e,x,!1,!1);if(B.error)return y(B.error,v);R=B.entry}}else if(A.operator===">"||A.operator===">|"||A.operator===">>"||A.operator==="&>"||A.operator==="&>>"){let P=A.operator===">>"||A.operator==="&>>",B=await Qn(e,x,P,A.operator===">|");if(B.error)return y(B.error,v);R=B.entry}else if(A.operator==="<<<")R={kind:"input",content:`${x}
146
+ `};else if(A.operator==="<"||A.operator==="<>"){let P=await Co(e,x,A.operator==="<>");if(P.error)return y(P.error,v);R=P.entry}if(W&&W.sourceFd>=Pe){if(!(W.move?ko(e,$,W.sourceFd):Bs(e,$,W.sourceFd)))return y(F("",`bash: ${W.sourceFd}: Bad file descriptor
147
+ `,1),v)}else R&&vt(e,$,R);W?.move&&W.sourceFd!==$&&W.sourceFd<Pe&&Rt(e,W.sourceFd),e.state.env.set(A.fdVariable,String($)),e.state.nextFd=$+1;continue}if(Tu(A)){let $=k;if(D&&x==="-"){pn(e,c,$),Rt(e,$);continue}let N=D?$o(x):null;if(N&&!S(N.sourceFd,A.operator==="<&"))return y(F("",`bash: ${N.sourceFd}: Bad file descriptor
148
+ `,1),v);if(!(N?.move===!0&&N.sourceFd>=Pe)){let R=await b($,v);if(R)return R}if(pn(e,c,$),D){let R=N;if(!R){if(A.operator==="<&")return y(F("",`bash: ${x}: ambiguous redirect
149
+ `,1),v);let P=await Qn(e,x,!1,!1);if(P.error)return y(P.error,v);vt(e,$,P.entry);continue}let W=S(R.sourceFd,A.operator==="<&");if(!W)return y(F("",`bash: ${R.sourceFd}: Bad file descriptor
150
+ `,1),v);if(R.sourceFd<Pe)vt(e,$,W.entry);else if(!(R.move?ko(e,$,R.sourceFd):Bs(e,$,R.sourceFd)))return y(F("",`bash: ${R.sourceFd}: Bad file descriptor
151
+ `,1),v);R.move&&R.sourceFd!==$&&R.sourceFd<Pe&&Rt(e,R.sourceFd);continue}if(A.operator===">"||A.operator===">|"||A.operator===">>"){let R=await Qn(e,x,A.operator===">>",A.operator===">|");if(R.error)return y(R.error,v);vt(e,$,R.entry)}else if(A.operator==="<<<")vt(e,$,{kind:"input",content:`${x}
152
+ `});else if(A.operator==="<"||A.operator==="<>"){let R=await Co(e,x,A.operator==="<>");if(R.error)return y(R.error,v);vt(e,$,R.entry)}continue}if(D){if(x==="-"){k===0&&(u="",f=-1,d=!0,h=!0),k!==null&&k<Pe&&(i.set(k,{kind:"closed"}),(k===1||k===2)&&a(k,{kind:"invalid-output",fd:k}),r.policy==="persistent"&&(Rt(e,k),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(k)));continue}let $=$o(x);if(!$){if(A.operator==="<&")return y(F("",`bash: ${x}: ambiguous redirect
153
+ `,1),v);let R=await Qn(e,x,!1,!1,!1);if(R.error)return y(R.error,v);let W=R.entry,P=l(W);A.fd==null?(w(1,W,P),w(2,W,P)):w(k,W,P);continue}let N=S($.sourceFd,A.operator==="<&");if(!N)return y(F("",`bash: ${$.sourceFd}: Bad file descriptor
154
+ `,1),v);let O=$.sourceFd===1?o.stdout:$.sourceFd===2?o.stderr:Ar(N,k===2?2:1);if(r.policy==="persistent"&&k!==null&&k<Pe&&$.sourceFd>=Pe){if(!Bs(e,k,$.sourceFd))return y(F("",`bash: ${$.sourceFd}: Bad file descriptor
155
+ `,1),v);i.set(k,lt(e,k)),e.state.closedStandardFds?.delete(k),a(k,O)}else w(k,N.entry,O);if(A.operator==="<&"&&k===0)if(N.entry.kind==="input"||N.entry.kind==="readwrite"){let R=$.sourceFd<Pe&&!Nn(e,$.sourceFd)?{content:N.entry.kind==="input"?N.entry.content:N.entry.content.slice(N.entry.position)}:Ws(e,$.sourceFd);if("error"in R)return y(F("",`bash: ${$.sourceFd}: Bad file descriptor
156
+ `,1),v);u=R.content,f=Nn(e,$.sourceFd)?$.sourceFd:-1,d=!0,h=N.entry.device===!0}else u=n,f=-1,d=!1,h=!1;$.move&&($.sourceFd>=Pe?Rt(e,$.sourceFd):(i.set($.sourceFd,{kind:"closed"}),($.sourceFd===1||$.sourceFd===2)&&a($.sourceFd,{kind:"invalid-output",fd:$.sourceFd}),r.policy==="persistent"&&(Rt(e,$.sourceFd),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add($.sourceFd))));continue}if(A.operator===">"||A.operator===">|"||A.operator===">>"||A.operator==="&>"||A.operator==="&>>"){let $=await Qn(e,x,A.operator===">>"||A.operator==="&>>",A.operator===">|",!1);if($.error)return y($.error,v);let N=$.entry,O=l(N);A.operator==="&>"||A.operator==="&>>"?(w(1,N,O),w(2,N,O)):w(k,N,O);continue}if(A.operator==="<<<"){let $=Ut(`${x}
157
+ `);w(k,{kind:"input",content:$}),k===0&&(u=$,f=-1,d=!0,h=!1)}else if(A.operator==="<"){let $=e.fs.resolvePath(e.state.cwd,x);try{let N=$===Rn?"":await _n(e.fs,$),O=zs.has($);w(k,{kind:"input",content:N,device:O}),k===0&&(u=N,f=-1,d=!0,h=O)}catch{return y(F("",`bash: ${x}: No such file or directory
158
+ `,1),v)}}else if(A.operator==="<>"){let $=await Co(e,x,!0);if($.error)return y($.error,v);let N=$.entry;w(k,N),k===0&&N.kind==="readwrite"&&(u=N.content,f=-1,d=!0,h=N.device===!0)}}return m()}function Kn(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="")=>Vp(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 Xn(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 No(e,t,n,r){let s=t instanceof G||t instanceof Le||t instanceof Ve?t.exitCode:t instanceof C?C.EXIT_CODE:0,i=await mn(e,F(t.stdout,t.stderr,s),n.length>0,r.outputRoutes);t.stdout=i.stdout,t.stderr=i.stderr,t.internalOutputAccounting=i.internalOutputAccounting??{stdout:V(i.stdout),stderr:V(i.stderr)}}async function nt(e,t,n,r){let s=Kn(e,t,vr),i;try{if(i=await s.prepare(n),i.error)return Xn(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 mn(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 Tn)||!i||await No(e,o,t,i),o}finally{s.finish()}}async function mn(e,t,n,r,s="bash",i=!1){n&&(t=e.executionScope.accountResult(t,"redirection"));let{stdout:o,stderr:a,exitCode:l}=t,u=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",f=y=>u,{stdout:d,stderr:h}=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
159
+ `,l=1),h.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===h&&(d.kind==="file"||d.kind==="descriptor")){let E=y+b;E!==""&&(d.kind==="file"?await w(d,E,f(E)):await xo(e,d.source.entry,d.source.descriptors,E,f(E)))}else for(let[E,S,v]of[[y,d,!0],[b,h,!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):Lu(E));break;case"descriptor":await xo(e,S.source.entry,S.source.descriptors,E,v?f(E):Lu(E));break;case"invalid-output":break;case"discard":break}}let p=F(o,a,l);if(t.stdoutKind&&(p.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(p.stdoutEncoding="binary"),t.internalPipeStatusOverride&&(p.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=V(p.stdout),w=V(p.stderr),E=Math.min(b,y);p.internalOutputAccounting={stdout:E,stderr:Math.min(w,y-E)},e.executionScope.accountResult(p,"redirection")}else t.internalOutputAccounting&&(p.internalOutputAccounting=t.internalOutputAccounting);return p}function Wu(e,t){if(e.state.options.posix&&po.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
160
+ `;throw new G(2,"",r)}let n={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,n),te}async function Us(e,t,n,r="",s,i=!1){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,cn(`${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 h=0;h<l;h++){let p=String(h+1);o.set(p,e.state.env.get(p)),h<n.length?e.state.env.set(p,n[h]):e.state.env.delete(p)}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 c=!1,u=()=>{if(c)return;c=!0;let h=e.state.localScopes.length-1,p=e.state.localScopes.pop(),m=e.state.localArrayScopes?.pop();if(p)for(let[y,b]of p)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,Me(b)),e.state.associativeArrays??=new Set,b.kind==="associative"?e.state.associativeArrays.add(y):e.state.associativeArrays.delete(y))}if(Ou(e,h),e.state.fullyUnsetLocals)for(let[y,b]of e.state.fullyUnsetLocals.entries())b===h&&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=Kn(e,t.redirections,vr);try{if(f=await d.prepare(r),f.error)return Xn(f);let h=f.stdin??r,p=i||f.stdin!==void 0||r!=="",m=await e.executeCommand(t.body,h,p);return mn(e,m,t.redirections.length>0,f.outputRoutes)}catch(h){if(h instanceof Tn&&f&&(await No(e,h,t.redirections,f),h instanceof Le))return F(h.stdout,h.stderr,h.exitCode);throw h}finally{d.finish(),u()}}var zu=e=>e.type==="Escaped"?M.literal(`\\${e.value}`):e.type==="DoubleQuoted"?{...e,parts:e.parts.map(zu)}:e,Uu=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],Do=[".",":","[","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"],zp=["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"],Up=Do;async function Io(e,t){let n=[],r=null,s="",i="",o=null,a=!1,l=!1,c=!1,u=null,f=null,d=null,h=[],p=["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 k=t[A];if(k==="-v")n.push("variable");else if(k==="-e")n.push("export");else if(k==="-f")n.push("file");else if(k==="-d")n.push("directory");else if(k==="-k")n.push("keyword");else if(k==="-A"){if(A++,A>=t.length)return L(`compgen: -A: option requires an argument
161
+ `,2);let x=t[A];if(!p.includes(x))return L(`compgen: ${x}: invalid action name
162
+ `,2);n.push(x)}else if(k==="-W"){if(A++,A>=t.length)return L(`compgen: -W: option requires an argument
163
+ `,2);r=t[A]}else if(k==="-P"){if(A++,A>=t.length)return L(`compgen: -P: option requires an argument
164
+ `,2);s=t[A]}else if(k==="-S"){if(A++,A>=t.length)return L(`compgen: -S: option requires an argument
165
+ `,2);i=t[A]}else if(k==="-o"){if(A++,A>=t.length)return L(`compgen: -o: option requires an argument
166
+ `,2);let x=t[A];if(x==="plusdirs")a=!0;else if(x==="dirnames")l=!0;else if(x==="default")c=!0;else if(!(x==="filenames"||x==="nospace"||x==="bashdefault"||x==="noquote"))return L(`compgen: ${x}: invalid option name
167
+ `,2)}else if(k==="-F"){if(A++,A>=t.length)return L(`compgen: -F: option requires an argument
168
+ `,2);f=t[A]}else if(k==="-C"){if(A++,A>=t.length)return L(`compgen: -C: option requires an argument
169
+ `,2);d=t[A]}else if(k==="-X"){if(A++,A>=t.length)return L(`compgen: -X: option requires an argument
170
+ `,2);u=t[A]}else if(k==="-G"){if(A++,A>=t.length)return L(`compgen: -G: option requires an argument
171
+ `,2)}else if(k==="--"){h.push(...t.slice(A+1));break}else k.startsWith("-")||h.push(k)}o=h[0]??null;let m=[],y=new Set,b=()=>e.limits.maxArrayElements-m.length,w=A=>{for(let k of A){if(m.length>=e.limits.maxArrayElements)throw new C(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(V(k)>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(k),y.add(k)}};if(l){let A=await Ro(e,o,b());w(A)}if(c){let A=await Vu(e,o,b());w(A)}for(let A of n)if(A==="variable"){let k=jp(e,o,b());w(k)}else if(A==="export"){let k=qp(e,o,b());w(k)}else if(A==="function"){let k=Gp(e,o,b());w(k)}else if(A==="builtin"){let k=Hp(e,o,b());w(k)}else if(A==="keyword"){let k=Zp(e,o,b());w(k)}else if(A==="alias"){let k=Qp(e,o,b());w(k)}else if(A==="shopt"){let k=Kp(e,o,b());w(k)}else if(A==="helptopic"){let k=Xp(e,o,b());w(k)}else if(A==="directory"){let k=await Ro(e,o,b());w(k)}else if(A==="file"){let k=await Vu(e,o,b());w(k)}else if(A==="user"){let k=Yp(e,o,b());w(k)}else if(A==="command"){let k=await Jp(e,o,b());w(k)}if(r!==null)try{let A=await em(e,r),k=tm(e,A,b(),o);for(let x of k)w([x])}catch(A){if(A instanceof C)throw A;return F("","",1)}if(a){let A=await Ro(e,o,b(),y);for(let k of A)y.has(k)||w([k])}let E="";if(f!==null){let A=e.state.functions.get(f);if(A){let k=new Map,x=ke(e,"COMP_WORDS"),D=x?Me(x):void 0;Ee(e,"COMP_WORDS"),cr(e,"COMP_WORDS"),k.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),k.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),k.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let $=ke(e,"COMPREPLY"),N=$?Me($):void 0,O=e.state.env.get("COMPREPLY");Ee(e,"COMPREPLY"),e.state.env.delete("COMPREPLY");let R=["compgen",h[0]??"",""];try{let W=await Us(e,A,R,"");if(W.exitCode!==0)return Oo(e,k),Yn(e,"COMP_WORDS",D),Yn(e,"COMPREPLY",N),O!==void 0&&e.state.env.set("COMPREPLY",O),F("",W.stderr,1);E=W.stdout;let P=nm(e,b());w(P)}catch(W){if(W instanceof C)throw W;return Oo(e,k),Yn(e,"COMP_WORDS",D),Yn(e,"COMPREPLY",N),O!==void 0&&e.state.env.set("COMPREPLY",O),F("","",1)}Oo(e,k),Yn(e,"COMP_WORDS",D),Yn(e,"COMPREPLY",N),O!==void 0&&e.state.env.set("COMPREPLY",O)}}if(d!==null)try{let A=He(d),k=await e.executeScript(A);if(k.exitCode!==0)return F("",k.stderr,k.exitCode);if(k.stdout)for(let x of rm(k.stdout))x.length>0&&w([x])}catch(A){if(A.name==="ParseException")return L(`compgen: -C: ${A.message}
172
+ `,2);throw A}let S=m;if(u!==null){let A=u.startsWith("!"),k=A?u.slice(1):u;S=m.filter(x=>{let D=Gn(x,k,!1,!0,e.limits.maxCallDepth);return A?D:!D})}if(S.length===0&&o!==null)return F(E,"",1);let v=new Ln(e.limits.maxOutputSize,"compgen");v.append(E);for(let A of S)v.append(s).append(A).append(i).append(`
173
+ `);return ee(v.build())}function jp(e,t,n){let r=ct(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 qp(e,t,n){let r=ct(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 Gp(e,t,n){let r=ct(e,t,n);for(let s of e.state.functions.keys())r.add(s);return r.build()}function Hp(e,t,n){let r=ct(e,t,n);for(let s of Do)r.add(s);return r.build()}function Zp(e,t,n){let r=ct(e,t,n);for(let s of Uu)r.add(s);return r.build()}function Qp(e,t,n){let r=ct(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 Kp(e,t,n){let r=ct(e,t,n);for(let s of zp)r.add(s);return r.build()}function Xp(e,t,n){let r=ct(e,t,n);for(let s of Up)r.add(s);return r.build()}async function Ro(e,t,n=e.limits.maxArrayElements,r){let s=ct(e,null,n,r);try{let i=e.state.cwd,o=t??"";if(t){let l=t.lastIndexOf("/");if(l!==-1){let c=t.slice(0,l)||"/";o=t.slice(l+1),c.startsWith("/")?i=c:i=`${e.state.cwd}/${c}`}}let a=await e.fs.readdir(i);for(let l of a){e.executionScope.consumeWork(1,"compgen directory scan");let c=`${i}/${l}`;try{if((await e.fs.stat(c)).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(u){if(u instanceof C)throw u}}}catch(i){if(i instanceof C)throw i}return s.build()}async function Vu(e,t,n=e.limits.maxArrayElements){let r=ct(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("/"),c=t.slice(0,l+1);r.add(c+a)}else r.add(a)}catch(s){if(s instanceof C)throw s}return r.build()}function Yp(e,t,n){let r=ct(e,t,n);return r.add("root"),r.add("nobody"),r.build()}async function Jp(e,t,n){let r=ct(e,t,n);for(let i of Do)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 Uu)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 ct(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(V(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 em(e,t){let r=new Q().parseWordFromString(t,!1,!1);return await se(e,M.word(r.parts.map(zu)))}function tm(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 C(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");return[t]}let i=new Set(s.split("")),o=[],a=u=>{if(!(r!==null&&!u.startsWith(r))){if(o.length>=n)throw new C(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");o.push(u)}},l="",c=0;for(;c<t.length;){let u=t[c];if(u==="\\"&&c+1<t.length){let f=t[c+1];l+=f,c+=2}else i.has(u)?(l.length>0&&(a(l),l=""),c++):(l+=u,c++)}return l.length>0&&a(l),o}function Oo(e,t){for(let[n,r]of t)r===void 0?e.state.env.delete(n):e.state.env.set(n,r)}function Yn(e,t,n){e.state.arrays??=new Map,n?e.state.arrays.set(t,Me(n)):e.state.arrays.delete(t)}function nm(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(Ne(e,"COMPREPLY")){let s=K(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*rm(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 kr(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n===127)return!0}return!1}function _o(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 ju(e){if(kr(e))return qu(e);if(e==="")return 2;if(/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e))return V(e);let t=V(e)+2;for(let n of e)n==="'"&&(t+=3);return t}function Se(e){return kr(e)?_o(e):e===""?"''":/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function js(e){if(kr(e))return qu(e);let t=V(e)+2;for(let n of e)(n==="\\"||n==='"'||n==="$"||n==="`")&&t++;return t}function yn(e){return kr(e)?_o(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}function qu(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+=V(n)}return t}function xr(e){return kr(e)?_o(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}var sm=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Lo(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=!1,i,o,a,l=[],c=[],u=[];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
176
+ `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return L(`complete: -F: option requires an argument
177
+ `,2);o=t[f]}else if(d==="-o"){if(f++,f>=t.length)return L(`complete: -o: option requires an argument
178
+ `,2);let h=t[f];if(!sm.includes(h))return L(`complete: ${h}: invalid option name
179
+ `,2);l.push(h)}else if(d==="-A"){if(f++,f>=t.length)return L(`complete: -A: option requires an argument
180
+ `,2);c.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return L(`complete: -C: option requires an argument
181
+ `,2);a=t[f]}else if(d==="-G"){if(f++,f>=t.length)return L(`complete: -G: option requires an argument
182
+ `,2)}else if(d==="-P"){if(f++,f>=t.length)return L(`complete: -P: option requires an argument
183
+ `,2)}else if(d==="-S"){if(f++,f>=t.length)return L(`complete: -S: option requires an argument
184
+ `,2)}else if(d==="-X"){if(f++,f>=t.length)return L(`complete: -X: option requires an argument
185
+ `,2)}else if(d==="--"){u.push(...t.slice(f+1));break}else d.startsWith("-")||u.push(d)}if(r){if(u.length===0)return e.state.completionSpecs.clear(),e.state.defaultCompletionSpec=void 0,e.state.emptyCompletionSpec=void 0,ee("");for(let f of u)e.state.completionSpecs.delete(f);return ee("")}if(n)return u.length===0?To(e):To(e,u);if(t.length===0||u.length===0&&!i&&!o&&!a&&l.length===0&&c.length===0&&!s)return To(e);if(o&&u.length===0&&!s)return L(`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),c.length>0&&(f.actions=c),e.state.defaultCompletionSpec=f,ee("")}for(let f of u){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),c.length>0&&(d.actions=c),e.state.completionSpecs.set(f,d)}return ee("")}function To(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 F("",i,1)}return ee("")}let r=[],s=t||Array.from(n.keys());for(let i of s){let o=n.get(i);if(!o){if(t)return F(r.join(`
187
188
  `)+(r.length>0?`
188
189
  `:""),`complete: ${i}: no completion specification
189
- `,1);continue}let a="complete";if(o.options)for(let l of o.options)a+=` -o ${Ae(l)}`;if(o.actions)for(let l of o.actions)a+=` -A ${Ae(l)}`;o.wordlist!==void 0&&(o.wordlist.includes(" ")||o.wordlist.includes("'")?a+=` -W ${Ae(o.wordlist)}`:a+=` -W ${Ae(o.wordlist)}`),o.function!==void 0&&(a+=` -F ${Ae(o.function)}`),o.command!==void 0&&(a+=` -C ${Ae(o.command)}`),o.isDefault&&(a+=" -D"),a+=`${i.startsWith("-")?" -- ":" "}${Ae(i)}`,r.push(a)}if(!t&&e.state.defaultCompletionSpec){let i=e.state.defaultCompletionSpec,o="complete";for(let a of i.options??[])o+=` -o ${Ae(a)}`;for(let a of i.actions??[])o+=` -A ${Ae(a)}`;i.wordlist!==void 0&&(o+=` -W ${Ae(i.wordlist)}`),i.function!==void 0&&(o+=` -F ${Ae(i.function)}`),i.command!==void 0&&(o+=` -C ${Ae(i.command)}`),o+=" -D",r.push(o)}return r.length===0?ee(""):ee(`${r.join(`
190
+ `,1);continue}let a="complete";if(o.options)for(let l of o.options)a+=` -o ${Se(l)}`;if(o.actions)for(let l of o.actions)a+=` -A ${Se(l)}`;o.wordlist!==void 0&&(o.wordlist.includes(" ")||o.wordlist.includes("'")?a+=` -W ${Se(o.wordlist)}`:a+=` -W ${Se(o.wordlist)}`),o.function!==void 0&&(a+=` -F ${Se(o.function)}`),o.command!==void 0&&(a+=` -C ${Se(o.command)}`),o.isDefault&&(a+=" -D"),a+=`${i.startsWith("-")?" -- ":" "}${Se(i)}`,r.push(a)}if(!t&&e.state.defaultCompletionSpec){let i=e.state.defaultCompletionSpec,o="complete";for(let a of i.options??[])o+=` -o ${Se(a)}`;for(let a of i.actions??[])o+=` -A ${Se(a)}`;i.wordlist!==void 0&&(o+=` -W ${Se(i.wordlist)}`),i.function!==void 0&&(o+=` -F ${Se(i.function)}`),i.command!==void 0&&(o+=` -C ${Se(i.command)}`),o+=" -D",r.push(o)}return r.length===0?ee(""):ee(`${r.join(`
190
191
  `)}
191
- `)}var zu=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function _o(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 T(`compopt: -o: option requires an argument
192
- `,2);let c=t[a];if(!zu.includes(c))return T(`compopt: ${c}: invalid option name
193
- `,2);s.push(c)}else if(l==="+o"){if(a++,a>=t.length)return T(`compopt: +o: option requires an argument
194
- `,2);let c=t[a];if(!zu.includes(c))return T(`compopt: ${c}: invalid option name
195
- `,2);i.push(c)}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 c of s)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.defaultCompletionSpec=a,ee("")}if(r){let a=e.state.emptyCompletionSpec??Object.create(null),l=new Set(a.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.emptyCompletionSpec=a,ee("")}if(o.length>0){for(let a of o){let l=e.state.completionSpecs.get(a)??{},c=new Set(l.options??[]);for(let u of s)c.add(u);for(let u of i)c.delete(u);l.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set(a,l)}return ee("")}return T(`compopt: not currently executing completion function
196
- `,1)}function To(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new qt;return te}if(t.length>1)throw new q(1,"",`bash: continue: too many arguments
197
- `);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
198
- `);n=r}throw new Ke(n)}function Uu(e,t){let n="";return e.state.integerVars?.has(t)&&(n+="i"),e.state.lowercaseVars?.has(t)&&(n+="l"),ue(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 Lo(e){return Ae(e)}function Fo(e){return`'${e.replace(/'/g,"'\\''")}'`}function ju(e,t){let n="",r="",s=!1;for(let i of t){let o=Uu(e,i);if(e.state.associativeArrays?.has(i)){let u=xt(e,i);if(u.length===0)n+=`declare -A ${i}=()
199
- `;else{let f=u.map(d=>{let h=ae(e,i,d)??"",p=Lo(h);return`[${Fo(d)}]=${p}`});n+=`declare -A ${i}=(${f.join(" ")})
200
- `}continue}let l=ve(e,i);if(l.length>0){let u=l.map(f=>{let d=ae(e,i,f)??"";return`[${f}]=${yn(d)}`});n+=`declare -a ${i}=(${u.join(" ")})
192
+ `)}var Gu=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Fo(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
193
+ `,2);let c=t[a];if(!Gu.includes(c))return L(`compopt: ${c}: invalid option name
194
+ `,2);s.push(c)}else if(l==="+o"){if(a++,a>=t.length)return L(`compopt: +o: option requires an argument
195
+ `,2);let c=t[a];if(!Gu.includes(c))return L(`compopt: ${c}: invalid option name
196
+ `,2);i.push(c)}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 c of s)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.defaultCompletionSpec=a,ee("")}if(r){let a=e.state.emptyCompletionSpec??Object.create(null),l=new Set(a.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.emptyCompletionSpec=a,ee("")}if(o.length>0){for(let a of o){let l=e.state.completionSpecs.get(a)??{},c=new Set(l.options??[]);for(let u of s)c.add(u);for(let u of i)c.delete(u);l.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set(a,l)}return ee("")}return L(`compopt: not currently executing completion function
197
+ `,1)}function Mo(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new qt;return te}if(t.length>1)throw new G(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 G(1,"",`bash: continue: ${t[0]}: numeric argument required
199
+ `);n=r}throw new Ke(n)}function Hu(e,t){let n="";return e.state.integerVars?.has(t)&&(n+="i"),e.state.lowercaseVars?.has(t)&&(n+="l"),ue(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 Bo(e){return Se(e)}function Wo(e){return`'${e.replace(/'/g,"'\\''")}'`}function Zu(e,t){let n="",r="",s=!1;for(let i of t){let o=Hu(e,i);if(e.state.associativeArrays?.has(i)){let u=xt(e,i);if(u.length===0)n+=`declare -A ${i}=()
200
+ `;else{let f=u.map(d=>{let h=ae(e,i,d)??"",p=Bo(h);return`[${Wo(d)}]=${p}`});n+=`declare -A ${i}=(${f.join(" ")})
201
+ `}continue}let l=Ae(e,i);if(l.length>0){let u=l.map(f=>{let d=ae(e,i,f)??"";return`[${f}]=${yn(d)}`});n+=`declare -a ${i}=(${u.join(" ")})
201
202
  `;continue}if(Ne(e,i)){n+=`declare -a ${i}=()
202
- `;continue}let c=e.state.env.get(i);if(c!==void 0)n+=`declare ${o} ${i}=${vr(c)}
203
+ `;continue}let c=e.state.env.get(i);if(c!==void 0)n+=`declare ${o} ${i}=${xr(c)}
203
204
  `;else{let u=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);u||f?n+=`declare ${o} ${i}
204
205
  `:(r+=`bash: declare: ${i}: not found
205
- `,s=!0)}}return L(n,r,s?1:0)}function qu(e,t){let{filterExport:n,filterReadonly:r,filterNameref:s,filterIndexedArray:i,filterAssocArray:o}=t,a=n||r||s||i||o,l="",c=new Set;for(let f of e.state.env.keys())f.startsWith("BASH_")||c.add(f);for(let f of e.state.arrays?.keys()??[])c.add(f);if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())c.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)c.add(f);let u=Array.from(c).sort();for(let f of u){let d=Uu(e,f),h=e.state.associativeArrays?.has(f),p=ve(e,f),m=!h&&Ne(e,f);if(a&&(o&&!h||i&&!m||n&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||s&&!ue(e,f)))continue;if(h){let S=xt(e,f);if(S.length===0)l+=`declare -A ${f}=()
206
- `;else{let y=S.map(g=>{let b=ae(e,f,g)??"",v=Lo(b);return`[${Fo(g)}]=${v}`});l+=`declare -A ${f}=(${y.join(" ")})
207
- `}continue}if(p.length>0){let S=p.map(y=>{let g=ae(e,f,y)??"";return`[${y}]=${yn(g)}`});l+=`declare -a ${f}=(${S.join(" ")})
206
+ `,s=!0)}}return F(n,r,s?1:0)}function Qu(e,t){let{filterExport:n,filterReadonly:r,filterNameref:s,filterIndexedArray:i,filterAssocArray:o}=t,a=n||r||s||i||o,l="",c=new Set;for(let f of e.state.env.keys())f.startsWith("BASH_")||c.add(f);for(let f of e.state.arrays?.keys()??[])c.add(f);if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())c.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)c.add(f);let u=Array.from(c).sort();for(let f of u){let d=Hu(e,f),h=e.state.associativeArrays?.has(f),p=Ae(e,f),m=!h&&Ne(e,f);if(a&&(o&&!h||i&&!m||n&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||s&&!ue(e,f)))continue;if(h){let b=xt(e,f);if(b.length===0)l+=`declare -A ${f}=()
207
+ `;else{let w=b.map(E=>{let S=ae(e,f,E)??"",v=Bo(S);return`[${Wo(E)}]=${v}`});l+=`declare -A ${f}=(${w.join(" ")})
208
+ `}continue}if(p.length>0){let b=p.map(w=>{let E=ae(e,f,w)??"";return`[${w}]=${yn(E)}`});l+=`declare -a ${f}=(${b.join(" ")})
208
209
  `;continue}if(Ne(e,f)){l+=`declare -a ${f}=()
209
- `;continue}let E=e.state.env.get(f);E!==void 0&&(l+=`declare ${d} ${f}=${vr(E)}
210
- `)}return ee(l)}function Gu(e){let t="",n=Array.from(e.state.associativeArrays??[]).sort();for(let r of n){let s=xt(e,r);if(s.length===0)t+=`declare -A ${r}=()
211
- `;else{let i=s.map(o=>{let a=ae(e,r,o)??"",l=Lo(a);return`[${Fo(o)}]=${l}`});t+=`declare -A ${r}=(${i.join(" ")})
212
- `}}return ee(t)}function Hu(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=ve(e,s);if(i.length===0)t+=`declare -a ${s}=()
210
+ `;continue}let y=e.state.env.get(f);y!==void 0&&(l+=`declare ${d} ${f}=${xr(y)}
211
+ `)}return ee(l)}function Ku(e){let t="",n=Array.from(e.state.associativeArrays??[]).sort();for(let r of n){let s=xt(e,r);if(s.length===0)t+=`declare -A ${r}=()
212
+ `;else{let i=s.map(o=>{let a=ae(e,r,o)??"",l=Bo(a);return`[${Wo(o)}]=${l}`});t+=`declare -A ${r}=(${i.join(" ")})
213
+ `}}return ee(t)}function Xu(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=Ae(e,s);if(i.length===0)t+=`declare -a ${s}=()
213
214
  `;else{let o=i.map(a=>{let l=ae(e,s,a)??"";return`[${a}]=${yn(l)}`});t+=`declare -a ${s}=(${o.join(" ")})
214
- `}}return ee(t)}function Zu(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)||ve(e,s).length>0||Ne(e,s))continue;let a=e.state.env.get(s);a!==void 0&&(t+=`${s}=${Ae(a)}
215
- `)}return ee(t)}function Mo(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function kr(e,t){return e.state.integerVars?.has(t)??!1}function Bo(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Yp(e,t){return e.state.lowercaseVars?.has(t)??!1}function Wo(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Jp(e,t){return e.state.uppercaseVars?.has(t)??!1}function Yn(e,t,n){return Yp(e,t)?n.toLowerCase():Jp(e,t)?n.toUpperCase():n}async function Qu(e,t){try{let n=new Z,r=re(n,t),s=await J(e,r.expression);return String(s)}catch{return"0"}}function em(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 Vo(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!1,f=!1,d=!1,h=!1,p=!1,m=!1,E=!1,S=!1,y=[];for(let x=0;x<t.length;x++){let C=t[x];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")c=!0;else if(C==="+a")u=!0;else if(C==="+x")f=!0;else if(C==="--"){y.push(...t.slice(x+1));break}else if(C.startsWith("+")){for(let D of C.slice(1))if(D==="n")c=!0;else if(D==="a")u=!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
216
- `,2)}}}else if(C==="-i")d=!0;else if(C==="-l")h=!0;else if(C==="-u")p=!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")h=!0;else if(D==="u")p=!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
217
- `,2);else y.push(C)}let b=e.state.localScopes.length>0&&!S,v=x=>{if(!b)return;let C=e.state.localScopes[e.state.localScopes.length-1];C.has(x)||C.set(x,e.state.env.get(x))},k=x=>{if(!b)return;let C=e.state.localScopes[e.state.localScopes.length-1];for(C.has(x)||C.set(x,e.state.env.get(x)),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(x)){let V=xe(e,x);D.set(x,V?Me(V):void 0)}},A=x=>{b&&fn(e,x)};if(E){if(y.length===0){let D=Array.from(e.state.functions.keys()).sort(),V="";for(let K of D)V+=`declare -f ${K}
218
- `;return ee(V)}let x=!0,C="";for(let D of y)e.state.functions.has(D)?C+=`${D}
219
- `:x=!1;return L(C,"",x?0:1)}if(m){if(y.length===0){let C="",D=Array.from(e.state.functions.keys()).sort();for(let V of D)C+=`${V} ()
215
+ `}}return ee(t)}function Yu(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)||Ae(e,s).length>0||Ne(e,s))continue;let a=e.state.env.get(s);a!==void 0&&(t+=`${s}=${Se(a)}
216
+ `)}return ee(t)}function Vo(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function Pr(e,t){return e.state.integerVars?.has(t)??!1}function zo(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function im(e,t){return e.state.lowercaseVars?.has(t)??!1}function Uo(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function om(e,t){return e.state.uppercaseVars?.has(t)??!1}function Jn(e,t,n){return im(e,t)?n.toLowerCase():om(e,t)?n.toUpperCase():n}async function Ju(e,t){try{let n=new Q,r=re(n,t),s=await J(e,r.expression);return String(s)}catch{return"0"}}function am(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 jo(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!1,f=!1,d=!1,h=!1,p=!1,m=!1,y=!1,b=!1,w=[];for(let $=0;$<t.length;$++){let N=t[$];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")c=!0;else if(N==="+a")u=!0;else if(N==="+x")f=!0;else if(N==="--"){w.push(...t.slice($+1));break}else if(N.startsWith("+")){for(let O of N.slice(1))if(O==="n")c=!0;else if(O==="a")u=!0;else if(O==="x")f=!0;else if(O!=="r"){if(O!=="i"){if(!(O==="f"||O==="F"))return F("",`bash: typeset: +${O}: invalid option
217
+ `,2)}}}else if(N==="-i")d=!0;else if(N==="-l")h=!0;else if(N==="-u")p=!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 O of N.slice(1))if(O==="a")r=!0;else if(O==="A")s=!0;else if(O==="r")i=!0;else if(O==="x")o=!0;else if(O==="p")a=!0;else if(O==="n")l=!0;else if(O==="i")d=!0;else if(O==="l")h=!0;else if(O==="u")p=!0;else if(O==="f")m=!0;else if(O==="F")y=!0;else if(O==="g")b=!0;else return F("",`bash: typeset: -${O}: invalid option
218
+ `,2);else w.push(N)}let S=e.state.localScopes.length>0&&!b,v=$=>{if(!S)return;let N=e.state.localScopes[e.state.localScopes.length-1];N.has($)||N.set($,e.state.env.get($))},A=$=>{if(!S)return;let N=e.state.localScopes[e.state.localScopes.length-1];for(N.has($)||N.set($,e.state.env.get($)),e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let O=e.state.localArrayScopes.at(-1);if(O&&!O.has($)){let R=ke(e,$);O.set($,R?Me(R):void 0)}},k=$=>{S&&fn(e,$)};if(y){if(w.length===0){let O=Array.from(e.state.functions.keys()).sort(),R="";for(let W of O)R+=`declare -f ${W}
219
+ `;return ee(R)}let $=!0,N="";for(let O of w)e.state.functions.has(O)?N+=`${O}
220
+ `:$=!1;return F(N,"",$?0:1)}if(m){if(w.length===0){let N="",O=Array.from(e.state.functions.keys()).sort();for(let R of O)N+=`${R} ()
220
221
  {
221
222
  # function body
222
223
  }
223
- `;return ee(C)}let x=!0;for(let C of y)e.state.functions.has(C)||(x=!1);return L("","",x?0:1)}if(a&&y.length>0)return ju(e,y);if(a&&y.length===0)return qu(e,{filterExport:o,filterReadonly:i,filterNameref:l,filterIndexedArray:r,filterAssocArray:s});if(y.length===0&&s&&!a)return Gu(e);if(y.length===0&&r&&!a)return Hu(e);if(y.length===0&&!a)return Zu(e);let P="",N=0;for(let x of y){let C=x.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(C&&!u){let R=C[1],U=C[2],j=fe(e,R);if(j)return j;if(s&&ve(e,R).length>0){P+=`bash: declare: ${R}: cannot convert indexed to associative array
224
- `,N=1;continue}if((r||!s&&!r)&&e.state.associativeArrays?.has(R)){P+=`bash: declare: ${R}: cannot convert associative to indexed array
225
- `,N=1;continue}let I=s&&U.includes("[")?Rs(U,n):void 0,_=I===void 0?Wt(U,{...n,maxElements:s?n.maxElements*2:n.maxElements}):void 0;if(e.executionScope.consumeWork(I?.length??_?.length??0,"declare array assignment"),k(R),s?(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(R),Xt(e,R,"associative")):Xt(e,R,"indexed"),Ee(e,R),e.state.env.delete(R),s&&U.includes("["))for(let[B,ne]of I??[])G(e,R,B,an(e,ne),"associative");else if(s){let B=_??[];for(let ne=0;ne<B.length;ne+=2){let Y=B[ne],Te=ne+1<B.length?B[ne+1]:"";G(e,R,Y,Te,"associative")}}else{let B=_??[];if(B.some(Y=>/^\[[^\]]+\]=/.test(Y))){let Y=0;for(let Te of B){let ht=Te.match(/^\[([^\]]+)\]=(.*)$/);if(ht){let Dt=ht[1],pt=ht[2],mt;if(/^-?\d+$/.test(Dt))mt=Number.parseInt(Dt,10);else try{let It=new Z,Zf=re(It,Dt);mt=await J(e,Zf.expression)}catch{mt=0}G(e,R,mt,an(e,pt)),Y=mt+1}else G(e,R,Y,Te),Y++}}else for(let Y=0;Y<B.length;Y++)G(e,R,Y,B[Y])}A(R),i&&Ze(e,R),o&&St(e,R);continue}if(c){let R=x.includes("=")?x.slice(0,x.indexOf("=")):x;if(Hl(e,R),!x.includes("="))continue}if(f){let R=x.includes("=")?x.slice(0,x.indexOf("=")):x;if(ls(e,R),!x.includes("="))continue}let D=em(x);if(D){let{name:R,indexExpr:U,value:j}=D,I=fe(e,R);if(I)return I;k(R);let _;try{let B=new Z,ne=re(B,U);_=await J(e,ne.expression)}catch{let B=parseInt(U,10);_=Number.isNaN(B)?0:B}G(e,R,_,j),A(R),i&&Ze(e,R),o&&St(e,R);continue}let V=x.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(V&&!u){let R=V[1],U=V[2],j=fe(e,R);if(j)return j;k(R);let I=Wt(U,n);if(e.state.associativeArrays?.has(R)){let _=Rs(U,n);e.executionScope.consumeWork(_.length,"declare array append"),Sn(e,R,_.map(([B])=>B));for(let[B,ne]of _)G(e,R,B,ne,"associative")}else{e.executionScope.consumeWork(I.length,"declare array append");let _=ve(e,R),B=0,ne=e.state.env.get(R);_.length===0&&ne!==void 0?(G(e,R,0,ne),e.state.env.delete(R),B=1):_.length>0&&(B=Math.max(..._)+1),Sn(e,R,Array.from({length:I.length},(Y,Te)=>B+Te));for(let Y=0;Y<I.length;Y++)G(e,R,B+Y,I[Y])}A(R),i&&Ze(e,R),o&&St(e,R);continue}let K=x.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(K){let R=K[1],U=K[2],j=fe(e,R);if(j)return j;v(R),d&&Mo(e,R),h&&Bo(e,R),p&&Wo(e,R);let _=ve(e,R).length>0||e.state.associativeArrays?.has(R);if(kr(e,R)){let B=e.state.env.get(R)??"0",ne=parseInt(B,10)||0,Y=parseInt(await Qu(e,U),10)||0;U=String(ne+Y),e.state.env.set(R,U)}else if(_){U=Yn(e,R,U);let B=ae(e,R,0)??"";G(e,R,0,Gt([B,U],"",e.limits.maxStringLength,"declare append"))}else{U=Yn(e,R,U);let B=e.state.env.get(R)??"";e.state.env.set(R,Gt([B,U],"",e.limits.maxStringLength,"declare append"))}A(R),i&&Ze(e,R),o&&St(e,R),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(R));continue}if(x.includes("=")){let R=x.indexOf("="),U=x.slice(0,R),j=x.slice(R+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(U)){P+=`bash: typeset: \`${U}': not a valid identifier
226
- `,N=1;continue}let I=fe(e,U);if(I)return I;if(v(U),l){if(j!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(j)){P+=`bash: declare: \`${j}': invalid variable name for name reference
227
- `,N=1;continue}e.state.env.set(U,j),Bt(e,U),j!==""&&ss(e,j)&&zi(e,U),A(U),i&&Ze(e,U),o&&St(e,U);continue}if(d&&Mo(e,U),h&&Bo(e,U),p&&Wo(e,U),kr(e,U)&&(j=await Qu(e,j)),j=Yn(e,U,j),ue(e,U)){let _=Be(e,U);_&&_!==U?e.state.env.set(_,j):e.state.env.set(U,j)}else e.state.env.set(U,j);A(U),i&&Ze(e,U),o&&St(e,U),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(U))}else{let R=x;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(R)){P+=`bash: typeset: \`${R}': not a valid identifier
228
- `,N=1;continue}if(r||s?k(R):v(R),l){Bt(e,R);let j=e.state.env.get(R);j!==void 0&&j!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(j)?Zl(e,R):j&&ss(e,j)&&zi(e,R),A(R),i&&Ze(e,R),o&&St(e,R);continue}if(d&&Mo(e,R),h&&Bo(e,R),p&&Wo(e,R),s){if(ve(e,R).length>0){P+=`bash: declare: ${R}: cannot convert indexed to associative array
229
- `,N=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(R),Xt(e,R,"associative")}let U=Ne(e,R);!e.state.env.has(R)&&!U&&(r||s?Xt(e,R,s?"associative":"indexed"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(R))),A(R),i&&Ze(e,R),o&&St(e,R)}}return L("",P,N)}async function zo(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 c of l){let u=e.state.env.get(c);if(u!==void 0){let f=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${c}="${f}"
230
- `}}return ee(a)}for(let a of o){let l=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(l){let d=l[1],h=l[2],p=fe(e,d);if(p)return p;let m=Wt(h,n);if(e.state.associativeArrays?.has(d)){let E=Rs(h,n);e.executionScope.consumeWork(E.length,"readonly array append"),Sn(e,d,E.map(([S])=>S));for(let[S,y]of E)G(e,d,S,y,"associative")}else{e.executionScope.consumeWork(m.length,"readonly array append");let E=ve(e,d),S=0,y=e.state.env.get(d);E.length===0&&y!==void 0?(G(e,d,0,y),e.state.env.delete(d),S=1):E.length>0&&(S=Math.max(...E)+1),Sn(e,d,Array.from({length:m.length},(g,b)=>S+b));for(let g=0;g<m.length;g++)G(e,d,S+g,m[g])}Ze(e,d);continue}let c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c){let d=c[1],h=c[2],p=fe(e,d);if(p)return p;let m=e.state.env.get(d)??"";e.state.env.set(d,Gt([m,h],"",e.limits.maxStringLength,"readonly append")),Ze(e,d);continue}let u=ku(a,n);if(u.value===void 0&&!u.isArray){Ze(e,u.name);continue}let f=await xu(e,u,{makeReadonly:!0});if(f)return f}return te}function Uo(e){return e.state.directoryStack??=[],e.state.directoryStack}function xr(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function tm(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 jo(e,t){let n=Uo(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 T(`bash: pushd: too many arguments
231
- `,2);r=t[a+1],a++}}else{if(l.startsWith("-")&&l!=="-")return T(`bash: pushd: ${l}: invalid option
232
- `,2);if(r!==void 0)return T(`bash: pushd: too many arguments
233
- `,2);r=l}}if(r===void 0){if(n.length<2)return T(`bash: pushd: no other directory
234
- `,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=tm(s);try{if(!(await e.fs.stat(s)).isDirectory)return T(`bash: pushd: ${r}: Not a directory
235
- `,1)}catch{return T(`bash: pushd: ${r}: No such file or directory
236
- `,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=>xr(a,i)).join(" ")}
237
- `;return ee(o)}function qo(e,t){let n=Uo(e);for(let o of t)if(o!=="--")return o.startsWith("-")&&o!=="-"?T(`bash: popd: ${o}: invalid option
238
- `,2):T(`bash: popd: too many arguments
239
- `,2);if(n.length===0)return T(`bash: popd: directory stack empty
240
- `,1);let r=n.shift();if(!r)return T(`bash: popd: directory stack empty
241
- `,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=>xr(o,s)).join(" ")}
242
- `;return ee(i)}function Go(e,t){let n=Uo(e),r=!1,s=!1,i=!1,o=!1;for(let u of t)if(u!=="--")if(u.startsWith("-"))for(let f of u.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 T(`bash: dirs: -${f}: invalid option
243
- `,2);else return T(`bash: dirs: too many arguments
244
- `,1);if(r)return e.state.directoryStack=[],te;let a=[e.state.cwd,...n],l=e.state.env.get("HOME")||"",c;return o?(c=a.map((u,f)=>{let d=s?u:xr(u,l);return` ${f} ${d}`}).join(`
224
+ `;return ee(N)}let $=!0;for(let N of w)e.state.functions.has(N)||($=!1);return F("","",$?0:1)}if(a&&w.length>0)return Zu(e,w);if(a&&w.length===0)return Qu(e,{filterExport:o,filterReadonly:i,filterNameref:l,filterIndexedArray:r,filterAssocArray:s});if(w.length===0&&s&&!a)return Ku(e);if(w.length===0&&r&&!a)return Xu(e);if(w.length===0&&!a)return Yu(e);let x="",D=0;for(let $ of w){let N=$.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(N&&!u){let P=N[1],B=N[2],U=fe(e,P);if(U)return U;if(s&&Ae(e,P).length>0){x+=`bash: declare: ${P}: cannot convert indexed to associative array
225
+ `,D=1;continue}if((r||!s&&!r)&&e.state.associativeArrays?.has(P)){x+=`bash: declare: ${P}: cannot convert associative to indexed array
226
+ `,D=1;continue}let _=s&&B.includes("[")?_s(B,n):void 0,T=_===void 0?Wt(B,{...n,maxElements:s?n.maxElements*2:n.maxElements}):void 0;if(e.executionScope.consumeWork(_?.length??T?.length??0,"declare array assignment"),A(P),s?(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(P),Xt(e,P,"associative")):Xt(e,P,"indexed"),Ee(e,P),e.state.env.delete(P),s&&B.includes("["))for(let[z,ne]of _??[])H(e,P,z,an(e,ne),"associative");else if(s){let z=T??[];for(let ne=0;ne<z.length;ne+=2){let Y=z[ne],Te=ne+1<z.length?z[ne+1]:"";H(e,P,Y,Te,"associative")}}else{let z=T??[];if(z.some(Y=>/^\[[^\]]+\]=/.test(Y))){let Y=0;for(let Te of z){let dt=Te.match(/^\[([^\]]+)\]=(.*)$/);if(dt){let Dt=dt[1],ht=dt[2],pt;if(/^-?\d+$/.test(Dt))pt=Number.parseInt(Dt,10);else try{let It=new Q,ed=re(It,Dt);pt=await J(e,ed.expression)}catch{pt=0}H(e,P,pt,an(e,ht)),Y=pt+1}else H(e,P,Y,Te),Y++}}else for(let Y=0;Y<z.length;Y++)H(e,P,Y,z[Y])}k(P),i&&Ze(e,P),o&&bt(e,P);continue}if(c){let P=$.includes("=")?$.slice(0,$.indexOf("=")):$;if(Xl(e,P),!$.includes("="))continue}if(f){let P=$.includes("=")?$.slice(0,$.indexOf("=")):$;if(ds(e,P),!$.includes("="))continue}let O=am($);if(O){let{name:P,indexExpr:B,value:U}=O,_=fe(e,P);if(_)return _;A(P);let T;try{let z=new Q,ne=re(z,B);T=await J(e,ne.expression)}catch{let z=parseInt(B,10);T=Number.isNaN(z)?0:z}H(e,P,T,U),k(P),i&&Ze(e,P),o&&bt(e,P);continue}let R=$.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(R&&!u){let P=R[1],B=R[2],U=fe(e,P);if(U)return U;A(P);let _=Wt(B,n);if(e.state.associativeArrays?.has(P)){let T=_s(B,n);e.executionScope.consumeWork(T.length,"declare array append"),Sn(e,P,T.map(([z])=>z));for(let[z,ne]of T)H(e,P,z,ne,"associative")}else{e.executionScope.consumeWork(_.length,"declare array append");let T=Ae(e,P),z=0,ne=e.state.env.get(P);T.length===0&&ne!==void 0?(H(e,P,0,ne),e.state.env.delete(P),z=1):T.length>0&&(z=Math.max(...T)+1),Sn(e,P,Array.from({length:_.length},(Y,Te)=>z+Te));for(let Y=0;Y<_.length;Y++)H(e,P,z+Y,_[Y])}k(P),i&&Ze(e,P),o&&bt(e,P);continue}let W=$.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(W){let P=W[1],B=W[2],U=fe(e,P);if(U)return U;v(P),d&&Vo(e,P),h&&zo(e,P),p&&Uo(e,P);let T=Ae(e,P).length>0||e.state.associativeArrays?.has(P);if(Pr(e,P)){let z=e.state.env.get(P)??"0",ne=parseInt(z,10)||0,Y=parseInt(await Ju(e,B),10)||0;B=String(ne+Y),e.state.env.set(P,B)}else if(T){B=Jn(e,P,B);let z=ae(e,P,0)??"";H(e,P,0,Gt([z,B],"",e.limits.maxStringLength,"declare append"))}else{B=Jn(e,P,B);let z=e.state.env.get(P)??"";e.state.env.set(P,Gt([z,B],"",e.limits.maxStringLength,"declare append"))}k(P),i&&Ze(e,P),o&&bt(e,P),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(P));continue}if($.includes("=")){let P=$.indexOf("="),B=$.slice(0,P),U=$.slice(P+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(B)){x+=`bash: typeset: \`${B}': not a valid identifier
227
+ `,D=1;continue}let _=fe(e,B);if(_)return _;if(v(B),l){if(U!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(U)){x+=`bash: declare: \`${U}': invalid variable name for name reference
228
+ `,D=1;continue}e.state.env.set(B,U),Bt(e,B),U!==""&&ls(e,U)&&ji(e,B),k(B),i&&Ze(e,B),o&&bt(e,B);continue}if(d&&Vo(e,B),h&&zo(e,B),p&&Uo(e,B),Pr(e,B)&&(U=await Ju(e,U)),U=Jn(e,B,U),ue(e,B)){let T=Be(e,B);T&&T!==B?e.state.env.set(T,U):e.state.env.set(B,U)}else e.state.env.set(B,U);k(B),i&&Ze(e,B),o&&bt(e,B),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(B))}else{let P=$;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(P)){x+=`bash: typeset: \`${P}': not a valid identifier
229
+ `,D=1;continue}if(r||s?A(P):v(P),l){Bt(e,P);let U=e.state.env.get(P);U!==void 0&&U!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(U)?Yl(e,P):U&&ls(e,U)&&ji(e,P),k(P),i&&Ze(e,P),o&&bt(e,P);continue}if(d&&Vo(e,P),h&&zo(e,P),p&&Uo(e,P),s){if(Ae(e,P).length>0){x+=`bash: declare: ${P}: cannot convert indexed to associative array
230
+ `,D=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(P),Xt(e,P,"associative")}let B=Ne(e,P);!e.state.env.has(P)&&!B&&(r||s?Xt(e,P,s?"associative":"indexed"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(P))),k(P),i&&Ze(e,P),o&&bt(e,P)}}return F("",x,D)}async function qo(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 c of l){let u=e.state.env.get(c);if(u!==void 0){let f=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${c}="${f}"
231
+ `}}return ee(a)}for(let a of o){let l=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(l){let d=l[1],h=l[2],p=fe(e,d);if(p)return p;let m=Wt(h,n);if(e.state.associativeArrays?.has(d)){let y=_s(h,n);e.executionScope.consumeWork(y.length,"readonly array append"),Sn(e,d,y.map(([b])=>b));for(let[b,w]of y)H(e,d,b,w,"associative")}else{e.executionScope.consumeWork(m.length,"readonly array append");let y=Ae(e,d),b=0,w=e.state.env.get(d);y.length===0&&w!==void 0?(H(e,d,0,w),e.state.env.delete(d),b=1):y.length>0&&(b=Math.max(...y)+1),Sn(e,d,Array.from({length:m.length},(E,S)=>b+S));for(let E=0;E<m.length;E++)H(e,d,b+E,m[E])}Ze(e,d);continue}let c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c){let d=c[1],h=c[2],p=fe(e,d);if(p)return p;let m=e.state.env.get(d)??"";e.state.env.set(d,Gt([m,h],"",e.limits.maxStringLength,"readonly append")),Ze(e,d);continue}let u=Cu(a,n);if(u.value===void 0&&!u.isArray){Ze(e,u.name);continue}let f=await Nu(e,u,{makeReadonly:!0});if(f)return f}return te}function Go(e){return e.state.directoryStack??=[],e.state.directoryStack}function $r(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function lm(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 Ho(e,t){let n=Go(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
232
+ `,2);r=t[a+1],a++}}else{if(l.startsWith("-")&&l!=="-")return L(`bash: pushd: ${l}: invalid option
233
+ `,2);if(r!==void 0)return L(`bash: pushd: too many arguments
234
+ `,2);r=l}}if(r===void 0){if(n.length<2)return L(`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=lm(s);try{if(!(await e.fs.stat(s)).isDirectory)return L(`bash: pushd: ${r}: Not a directory
236
+ `,1)}catch{return L(`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=>$r(a,i)).join(" ")}
238
+ `;return ee(o)}function Zo(e,t){let n=Go(e);for(let o of t)if(o!=="--")return o.startsWith("-")&&o!=="-"?L(`bash: popd: ${o}: invalid option
239
+ `,2):L(`bash: popd: too many arguments
240
+ `,2);if(n.length===0)return L(`bash: popd: directory stack empty
241
+ `,1);let r=n.shift();if(!r)return L(`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=>$r(o,s)).join(" ")}
243
+ `;return ee(i)}function Qo(e,t){let n=Go(e),r=!1,s=!1,i=!1,o=!1;for(let u of t)if(u!=="--")if(u.startsWith("-"))for(let f of u.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
244
+ `,2);else return L(`bash: dirs: too many arguments
245
+ `,1);if(r)return e.state.directoryStack=[],te;let a=[e.state.cwd,...n],l=e.state.env.get("HOME")||"",c;return o?(c=a.map((u,f)=>{let d=s?u:$r(u,l);return` ${f} ${d}`}).join(`
245
246
  `),c+=`
246
- `):i?c=a.map(u=>s?u:xr(u,l)).join(`
247
+ `):i?c=a.map(u=>s?u:$r(u,l)).join(`
247
248
  `)+`
248
- `:c=a.map(u=>s?u:xr(u,l)).join(" ")+`
249
- `,ee(c)}async function Vs(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 T(`bash: eval: ${l}: invalid option
249
+ `:c=a.map(u=>s?u:$r(u,l)).join(" ")+`
250
+ `,ee(c)}async function qs(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
250
251
  eval: usage: eval [arg ...]
251
- `,2)}if(s.length===0)return te;let i=s.join(" ");if(i.trim()==="")return te;let o=e.state.groupStdin,a=r||n!==void 0&&n!=="";a&&(e.state.groupStdin=n??"");try{let l=He(i);return await e.executeScript(l)}catch(l){if(l instanceof Qe||l instanceof Ke||l instanceof Le||l instanceof q)throw l;if(l.name==="ParseException")return T(`bash: eval: ${l.message}
252
- `);throw l}finally{(a||o!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=o)}}function Ho(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
253
- `,n=2;else{let i=BigInt(s);n=Number((i%256n+256n)%256n)}}throw new q(n,"",r)}function Zo(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 c of l){let u=e.state.env.get(c);u!==void 0&&(o+=`declare -x ${c}=${vr(u)}
254
- `)}return ee(o)}if(n){for(let o of r){let a,l;if(o.includes("=")){let c=o.indexOf("=");a=o.slice(0,c),l=o.slice(c+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return L("",`bash: export: \`${o}': not a valid identifier
255
- `,1);l!==void 0&&(fe(e,a),e.state.env.set(a,l)),ls(e,a)}return te}let s="",i=0;for(let o of r){let a,l,c=!1,u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(u)a=u[1],l=u[2],c=!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
256
- `,i=1;continue}if(l!==void 0)if(fe(e,a),c){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,"");St(e,a)}return L("",s,i)}function zs(e,t){if(t.length<2)return T(`bash: getopts: usage: getopts optstring name [arg ...]
257
- `);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 c=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 u=a[l-1];if(!u||u==="-"||!u.startsWith("-"))return s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};if(u==="--")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=c===0?1:c,d=u[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),zs(e,t);let h=o.indexOf(d);if(h===-1){let m="";return i?e.state.env.set("OPTARG",d):m=`bash: illegal option -- ${d}
252
+ `,2)}if(s.length===0)return te;let i=s.join(" ");if(i.trim()==="")return te;let o=e.state.groupStdin,a=r||n!==void 0&&n!=="";a&&(e.state.groupStdin=n??"");try{let l=He(i);return await e.executeScript(l)}catch(l){if(l instanceof Qe||l instanceof Ke||l instanceof Le||l instanceof G)throw l;if(l.name==="ParseException")return L(`bash: eval: ${l.message}
253
+ `);throw l}finally{(a||o!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=o)}}function Ko(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 G(n,"",r)}function Xo(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 c of l){let u=e.state.env.get(c);u!==void 0&&(o+=`declare -x ${c}=${xr(u)}
255
+ `)}return ee(o)}if(n){for(let o of r){let a,l;if(o.includes("=")){let c=o.indexOf("=");a=o.slice(0,c),l=o.slice(c+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return F("",`bash: export: \`${o}': not a valid identifier
256
+ `,1);l!==void 0&&(fe(e,a),e.state.env.set(a,l)),ds(e,a)}return te}let s="",i=0;for(let o of r){let a,l,c=!1,u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(u)a=u[1],l=u[2],c=!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(fe(e,a),c){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,"");bt(e,a)}return F("",s,i)}function Gs(e,t){if(t.length<2)return L(`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 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 c=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 u=a[l-1];if(!u||u==="-"||!u.startsWith("-"))return s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};if(u==="--")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=c===0?1:c,d=u[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),Gs(e,t);let h=o.indexOf(d);if(h===-1){let m="";return i?e.state.env.set("OPTARG",d):m=`bash: illegal option -- ${d}
258
259
  `,s||e.state.env.set(r,"?"),f+1<u.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(h+1<o.length&&o[h+1]===":")if(f+1<u.length)e.state.env.set("OPTARG",u.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}
259
- `,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<u.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 Qo(e,t){e.state.hashTable||(e.state.hashTable=new Map);let n=!1,r=!1,s=!1,i=!1,o=!1,a="",l=[],c=0;for(;c<t.length;){let p=t[c];if(p==="--"){c++,l.push(...t.slice(c));break}if(p==="-r")n=!0,c++;else if(p==="-d")r=!0,c++;else if(p==="-l")s=!0,c++;else if(p==="-t")o=!0,c++;else if(p==="-p"){if(i=!0,c++,c>=t.length)return T(`bash: hash: -p: option requires an argument
260
- `,1);a=t[c],c++}else if(p.startsWith("-")&&p.length>1){for(let m of p.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"?T(`bash: hash: -p: option requires an argument
261
- `,1):T(`bash: hash: -${m}: invalid option
262
- `,1);c++}else l.push(p),c++}if(n)return e.state.hashTable.clear(),te;if(r){if(l.length===0)return T(`bash: hash: -d: option requires an argument
263
- `,1);let p=!1,m="";for(let E of l)e.state.hashTable.has(E)?e.state.hashTable.delete(E):(m+=`bash: hash: ${E}: not found
264
- `,p=!0);return p?T(m,1):te}if(o){if(l.length===0)return T(`bash: hash: -t: option requires an argument
265
- `,1);let p="",m=!1,E="";for(let S of l){let y=e.state.hashTable.get(S);y?l.length>1?p+=`${S} ${y}
266
- `:p+=`${y}
267
- `:(E+=`bash: hash: ${S}: not found
268
- `,m=!0)}return m?{exitCode:1,stdout:p,stderr:E}:ee(p)}if(i){if(l.length===0)return T(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
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<u.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 Yo(e,t){e.state.hashTable||(e.state.hashTable=new Map);let n=!1,r=!1,s=!1,i=!1,o=!1,a="",l=[],c=0;for(;c<t.length;){let p=t[c];if(p==="--"){c++,l.push(...t.slice(c));break}if(p==="-r")n=!0,c++;else if(p==="-d")r=!0,c++;else if(p==="-l")s=!0,c++;else if(p==="-t")o=!0,c++;else if(p==="-p"){if(i=!0,c++,c>=t.length)return L(`bash: hash: -p: option requires an argument
261
+ `,1);a=t[c],c++}else if(p.startsWith("-")&&p.length>1){for(let m of p.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
262
+ `,1):L(`bash: hash: -${m}: invalid option
263
+ `,1);c++}else l.push(p),c++}if(n)return e.state.hashTable.clear(),te;if(r){if(l.length===0)return L(`bash: hash: -d: option requires an argument
264
+ `,1);let p=!1,m="";for(let y of l)e.state.hashTable.has(y)?e.state.hashTable.delete(y):(m+=`bash: hash: ${y}: not found
265
+ `,p=!0);return p?L(m,1):te}if(o){if(l.length===0)return L(`bash: hash: -t: option requires an argument
266
+ `,1);let p="",m=!1,y="";for(let b of l){let w=e.state.hashTable.get(b);w?l.length>1?p+=`${b} ${w}
267
+ `:p+=`${w}
268
+ `:(y+=`bash: hash: ${b}: not found
269
+ `,m=!0)}return m?{exitCode:1,stdout:p,stderr:y}:ee(p)}if(i){if(l.length===0)return L(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
269
270
  `,1);let p=l[0];return e.state.hashTable.set(p,a),te}if(l.length===0){if(e.state.hashTable.size===0)return ee(`hash: hash table empty
270
- `);let p="";if(s)for(let[m,E]of e.state.hashTable){let S=m.startsWith("-")?" --":"";p+=`builtin hash -p ${Ae(E)}${S} ${Ae(m)}
271
+ `);let p="";if(s)for(let[m,y]of e.state.hashTable){let b=m.startsWith("-")?" --":"";p+=`builtin hash -p ${Se(y)}${b} ${Se(m)}
271
272
  `}else{p=`hits command
272
273
  `;for(let[,m]of e.state.hashTable)p+=` 1 ${m}
273
274
  `}return ee(p)}let u=!1,f="",h=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let p of l){if(p.includes("/")){f+=`bash: hash: ${p}: cannot use / in name
274
- `,u=!0;continue}let m=!1;for(let E of h){if(!E)continue;let S=`${E}/${p}`;if(await e.fs.exists(S)){e.state.hashTable.set(p,S),m=!0;break}}m||(f+=`bash: hash: ${p}: not found
275
- `,u=!0)}return u?T(f,1):te}var Ku=new Map([[":",[": [arguments]",`Null command.
275
+ `,u=!0;continue}let m=!1;for(let y of h){if(!y)continue;let b=`${y}/${p}`;if(await e.fs.exists(b)){e.state.hashTable.set(p,b),m=!0;break}}m||(f+=`bash: hash: ${p}: not found
276
+ `,u=!0)}return u?L(f,1):te}var ef=new Map([[":",[": [arguments]",`Null command.
276
277
  No effect; the command does nothing.
277
278
  Exit Status:
278
279
  Always succeeds.`]],[".",[". filename [arguments]",`Execute commands from a file in the current shell.
@@ -617,37 +618,37 @@ eval: usage: eval [arg ...]
617
618
  job specification, and reports its termination status.
618
619
  Exit Status:
619
620
  Returns the status of the last ID; fails if ID is invalid or an invalid
620
- option is given.`]]]),Xu=[...Ku.keys()].sort();function Ko(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 c=1;c<l.length;c++){let u=l[c];if(u==="s")n=!0;else return T(`bash: help: -${u}: invalid option
621
- `,2)}s++}else r.push(l),s++}if(r.length===0)return rm();let i="",o=!1,a="";for(let l of r){let c=nm(l);if(c.length===0){a+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
622
- `,o=!0;continue}for(let u of c){let f=Ku.get(u);if(!f)continue;let[d,h]=f;n?i+=`${u}: ${d}
621
+ option is given.`]]]),tf=[...ef.keys()].sort();function Jo(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 c=1;c<l.length;c++){let u=l[c];if(u==="s")n=!0;else return L(`bash: help: -${u}: invalid option
622
+ `,2)}s++}else r.push(l),s++}if(r.length===0)return um();let i="",o=!1,a="";for(let l of r){let c=cm(l);if(c.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 u of c){let f=ef.get(u);if(!f)continue;let[d,h]=f;n?i+=`${u}: ${d}
623
624
  `:i+=`${u}: ${d}
624
625
  ${h}
625
- `}}return{exitCode:o?1:0,stdout:i,stderr:a}}function nm(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),n=ge(`^${t}$`);return Xu.filter(r=>n.test(r))}function rm(){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=Xu.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 ee(`${e.join(`
626
+ `}}return{exitCode:o?1:0,stdout:i,stderr:a}}function cm(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),n=ge(`^${t}$`);return tf.filter(r=>n.test(r))}function um(){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=tf.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 ee(`${e.join(`
626
627
  `)}
627
- `)}function sm(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 Xo(e,t){if(t.length===0)return T(`bash: let: expression expected
628
- `);let n=sm(t),r=0;for(let s of n)try{let o=He(`(( ${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 J(e,a.expression.expression))}}catch(i){return T(`bash: let: ${s}: ${i.message}
629
- `)}return L("","",r===0?1:0)}async function Yo(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength};if(e.state.localScopes.length===0)return T(`bash: local: can only be used in a function
630
- `);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 h=xe(e,d);s.set(d,h?Me(h):void 0)}},o="",a=0,l=!1,c=!1,u=!1,f=[];for(let d of t)if(d==="-n")l=!0;else if(d==="-a")c=!0;else if(d==="-p")u=!0;else if(d.startsWith("-")&&!d.includes("="))for(let h of d.slice(1))h==="n"?l=!0:h==="a"?c=!0:h==="p"&&(u=!0);else f.push(d);if(f.length===0){let d="",h=Array.from(r.keys()).sort();for(let p of h){let m=e.state.env.get(p);m!==void 0&&(d+=`${p}=${m}
631
- `)}return L(d,"",0)}for(let d of f){let h,p,m=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(m){h=m[1];let b=m[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(h)){o+=`bash: local: \`${d}': not a valid identifier
632
- `,a=1;continue}fe(e,h,"bash");let v=Wt(b,n);e.executionScope.consumeWork(v.length,"local array assignment"),i(h),Ee(e,h),Xt(e,h,"indexed");for(let k=0;k<v.length;k++)G(e,h,k,v[k]);fn(e,h),l&&Bt(e,h);continue}let E=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(E){h=E[1];let b=E[2];fe(e,h,"bash"),i(h);let v=Wt(b,n);e.executionScope.consumeWork(v.length,"local array append");let k=ve(e,h),A=0,P=e.state.env.get(h);k.length===0&&P!==void 0?(G(e,h,0,P),e.state.env.delete(h),A=1):k.length>0&&(A=Math.max(...k)+1),Sn(e,h,Array.from({length:v.length},(N,x)=>A+x));for(let N=0;N<v.length;N++)G(e,h,A+N,v[N]);fn(e,h),l&&Bt(e,h);continue}let S=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(S){h=S[1];let b=S[2];fe(e,h,"bash"),r.has(h)||r.set(h,e.state.env.get(h));let v=e.state.env.get(h)??"";e.state.env.set(h,Gt([v,b],"",e.limits.maxStringLength,"local append")),fn(e,h),l&&Bt(e,h);continue}let y=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(y){h=y[1];let b=y[2],v=y[3];fe(e,h,"bash"),i(h);let k;try{let A=new Z,P=re(A,b);k=await J(e,P.expression)}catch{let A=parseInt(b,10);k=Number.isNaN(A)?0:A}G(e,h,k,v),fn(e,h),l&&Bt(e,h);continue}if(d.includes("=")){let b=d.indexOf("=");h=d.slice(0,b),p=d.slice(b+1)}else h=d;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(h)){o+=`bash: local: \`${d}': not a valid identifier
633
- `,a=1;continue}let g=r.has(h);if(p!==void 0){let b=e.state.env.get(h);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(h),k=e.state.mutatedTempEnvVars?.has(h);if(!v&&!k)for(let A=e.state.tempEnvBindings.length-1;A>=0;A--){let P=e.state.tempEnvBindings[A];if(P.has(h)){b=P.get(h);break}}}Pu(e,h,b)}if(!g){let b=e.state.env.get(h);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let k=e.state.tempEnvBindings[v];if(k.has(h)){b=k.get(h);break}}r.set(h,b),c&&i(h)}if(c&&p===void 0)Ee(e,h),Xt(e,h,"indexed");else if(p!==void 0){if(fe(e,h,"bash"),l&&p!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(p)){o+=`bash: local: \`${p}': invalid variable name for name reference
634
- `,a=1;continue}e.state.env.set(h,p),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(h))}else{let b=e.state.tempEnvBindings?.some(v=>v.has(h));!g&&!b&&e.state.env.delete(h)}fn(e,h),l&&Bt(e,h)}return L("",o,a)}function Jo(e,t,n){let r=`
635
- `,s=0,i=0,o=0,a=!1,l="MAPFILE",c=0;for(;c<t.length;){let y=t[c];y==="-d"&&c+1<t.length?(r=t[c+1]===""?"\0":t[c+1]||`
636
- `,c+=2):y==="-n"&&c+1<t.length?(s=Number.parseInt(t[c+1],10)||0,c+=2):y==="-O"&&c+1<t.length?(i=Number.parseInt(t[c+1],10)||0,c+=2):y==="-s"&&c+1<t.length?(o=Number.parseInt(t[c+1],10)||0,c+=2):y==="-t"?(a=!0,c++):y==="-u"||y==="-C"||y==="-c"?c+=2:(y.startsWith("-")||(l=y),c++)}if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l))return L("",`mapfile: ${l}: not a valid identifier
637
- `,1);if(!Number.isSafeInteger(i)||i<0)return L("",`mapfile: invalid array origin
638
- `,1);fe(e,l,"mapfile");let u=n;!u&&e.state.groupStdin!==void 0&&(u=e.state.groupStdin);let f=[],d=0,h=0,p=0,m=e.limits.maxArrayElements,E=y=>{if(M(y)>e.limits.maxStringLength)throw new $(`mapfile: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");f.push(y)};for(;d<u.length;){e.executionScope.consumeWork(1,"mapfile input");let y=u.indexOf(r,d);if(y===-1){if(d<u.length){if(p<o)p++;else if(s===0||h<s){let v=u.slice(d),k=v.indexOf("\0");if(k!==-1&&(v=v.substring(0,k)),f.length>=m)return L("",`mapfile: array element limit exceeded (${m})
639
- `,1);E(v),h++}}break}let g=u.slice(d,y),b=g.indexOf("\0");if(b!==-1&&(g=g.substring(0,b)),!a&&r!=="\0"&&(g+=r),d=y+r.length,p<o){p++;continue}if(s>0&&h>=s)break;if(f.length>=m)return L("",`mapfile: array element limit exceeded (${m})
640
- `,1);E(g),h++}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})
641
- `,1);i===0&&Ee(e,l);for(let y=0;y<f.length;y++)G(e,l,i+y,f[y]);return e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=""),{...L("","",0),internalStdinConsumed:u.length}}function ea(e,t,n,r=-1){let s=!1,i=`
642
- `,o="",a=-1,l=-1,c=null,u=-1,f=-1,d=[],h=0,p=!1,m=(I,_)=>{let B=1;for(;B<I.length;){let ne=I[B];if(ne==="r")s=!0,B++;else if(ne==="s")B++;else{if(ne==="d")return B+1<I.length?(i=I.substring(B+1),{nextArgIndex:_+1}):_+1<t.length?(i=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(ne==="n"){if(B+1<I.length){let Y=I.substring(B+1);return a=Number.parseInt(Y,10),(Number.isNaN(a)||a<0)&&(p=!0,a=0),{nextArgIndex:_+1}}else if(_+1<t.length)return a=Number.parseInt(t[_+1],10),(Number.isNaN(a)||a<0)&&(p=!0,a=0),{nextArgIndex:_+2};return{nextArgIndex:_+1}}else if(ne==="N"){if(B+1<I.length){let Y=I.substring(B+1);return l=Number.parseInt(Y,10),(Number.isNaN(l)||l<0)&&(p=!0,l=0),{nextArgIndex:_+1}}else if(_+1<t.length)return l=Number.parseInt(t[_+1],10),(Number.isNaN(l)||l<0)&&(p=!0,l=0),{nextArgIndex:_+2};return{nextArgIndex:_+1}}else{if(ne==="a")return B+1<I.length?(c=I.substring(B+1),{nextArgIndex:_+1}):_+1<t.length?(c=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(ne==="p")return B+1<I.length?(o=I.substring(B+1),{nextArgIndex:_+1}):_+1<t.length?(o=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(ne==="u"){if(B+1<I.length){let Y=I.substring(B+1);return u=Number.parseInt(Y,10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:_+1}}else if(_+1<t.length)return u=Number.parseInt(t[_+1],10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:_+2};return{nextArgIndex:_+1}}else if(ne==="t"){if(B+1<I.length){let Y=I.substring(B+1);return f=Number.parseFloat(Y),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(ne==="e"||ne==="i"||ne==="P"){if(ne==="i"&&_+1<t.length)return{nextArgIndex:_+2};B++}else B++}}}return{nextArgIndex:_+1}};for(;h<t.length;){let I=t[h];if(I.startsWith("-")&&I.length>1&&I!=="--"){let _=m(I,h);if(_.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(_.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=_.nextArgIndex}else if(I==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push(I),h++}if(p)return L("","",1);d.length===0&&c===null&&d.push("REPLY");let E=new Set;c&&E.add(c);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
643
- `,1);fe(e,I,"bash")}if(f===0){if(c)Ee(e,c);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=nt(e,u),g=u>0&&!(y?.kind==="dup-in"&&y.sourceFd===0);if(g){let I=Ls(e,u);if("error"in I){let B=I.error==="write-only"||u===1||u===2?`bash: read: read error: ${u}: Bad file descriptor
628
+ `)}function fm(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 ea(e,t){if(t.length===0)return L(`bash: let: expression expected
629
+ `);let n=fm(t),r=0;for(let s of n)try{let o=He(`(( ${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 J(e,a.expression.expression))}}catch(i){return L(`bash: let: ${s}: ${i.message}
630
+ `)}return F("","",r===0?1:0)}async function ta(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
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 h=ke(e,d);s.set(d,h?Me(h):void 0)}},o="",a=0,l=!1,c=!1,u=!1,f=[];for(let d of t)if(d==="-n")l=!0;else if(d==="-a")c=!0;else if(d==="-p")u=!0;else if(d.startsWith("-")&&!d.includes("="))for(let h of d.slice(1))h==="n"?l=!0:h==="a"?c=!0:h==="p"&&(u=!0);else f.push(d);if(f.length===0){let d="",h=Array.from(r.keys()).sort();for(let p of h){let m=e.state.env.get(p);m!==void 0&&(d+=`${p}=${m}
632
+ `)}return F(d,"",0)}for(let d of f){let h,p,m=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(m){h=m[1];let S=m[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(h)){o+=`bash: local: \`${d}': not a valid identifier
633
+ `,a=1;continue}fe(e,h,"bash");let v=Wt(S,n);e.executionScope.consumeWork(v.length,"local array assignment"),i(h),Ee(e,h),Xt(e,h,"indexed");for(let A=0;A<v.length;A++)H(e,h,A,v[A]);fn(e,h),l&&Bt(e,h);continue}let y=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(y){h=y[1];let S=y[2];fe(e,h,"bash"),i(h);let v=Wt(S,n);e.executionScope.consumeWork(v.length,"local array append");let A=Ae(e,h),k=0,x=e.state.env.get(h);A.length===0&&x!==void 0?(H(e,h,0,x),e.state.env.delete(h),k=1):A.length>0&&(k=Math.max(...A)+1),Sn(e,h,Array.from({length:v.length},(D,$)=>k+$));for(let D=0;D<v.length;D++)H(e,h,k+D,v[D]);fn(e,h),l&&Bt(e,h);continue}let b=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(b){h=b[1];let S=b[2];fe(e,h,"bash"),r.has(h)||r.set(h,e.state.env.get(h));let v=e.state.env.get(h)??"";e.state.env.set(h,Gt([v,S],"",e.limits.maxStringLength,"local append")),fn(e,h),l&&Bt(e,h);continue}let w=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(w){h=w[1];let S=w[2],v=w[3];fe(e,h,"bash"),i(h);let A;try{let k=new Q,x=re(k,S);A=await J(e,x.expression)}catch{let k=parseInt(S,10);A=Number.isNaN(k)?0:k}H(e,h,A,v),fn(e,h),l&&Bt(e,h);continue}if(d.includes("=")){let S=d.indexOf("=");h=d.slice(0,S),p=d.slice(S+1)}else h=d;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(h)){o+=`bash: local: \`${d}': not a valid identifier
634
+ `,a=1;continue}let E=r.has(h);if(p!==void 0){let S=e.state.env.get(h);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(h),A=e.state.mutatedTempEnvVars?.has(h);if(!v&&!A)for(let k=e.state.tempEnvBindings.length-1;k>=0;k--){let x=e.state.tempEnvBindings[k];if(x.has(h)){S=x.get(h);break}}}Ru(e,h,S)}if(!E){let S=e.state.env.get(h);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let A=e.state.tempEnvBindings[v];if(A.has(h)){S=A.get(h);break}}r.set(h,S),c&&i(h)}if(c&&p===void 0)Ee(e,h),Xt(e,h,"indexed");else if(p!==void 0){if(fe(e,h,"bash"),l&&p!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(p)){o+=`bash: local: \`${p}': invalid variable name for name reference
635
+ `,a=1;continue}e.state.env.set(h,p),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(h))}else{let S=e.state.tempEnvBindings?.some(v=>v.has(h));!E&&!S&&e.state.env.delete(h)}fn(e,h),l&&Bt(e,h)}return F("",o,a)}function na(e,t,n){let r=`
636
+ `,s=0,i=0,o=0,a=!1,l="MAPFILE",c=0;for(;c<t.length;){let w=t[c];w==="-d"&&c+1<t.length?(r=t[c+1]===""?"\0":t[c+1]||`
637
+ `,c+=2):w==="-n"&&c+1<t.length?(s=Number.parseInt(t[c+1],10)||0,c+=2):w==="-O"&&c+1<t.length?(i=Number.parseInt(t[c+1],10)||0,c+=2):w==="-s"&&c+1<t.length?(o=Number.parseInt(t[c+1],10)||0,c+=2):w==="-t"?(a=!0,c++):w==="-u"||w==="-C"||w==="-c"?c+=2:(w.startsWith("-")||(l=w),c++)}if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l))return F("",`mapfile: ${l}: not a valid identifier
638
+ `,1);if(!Number.isSafeInteger(i)||i<0)return F("",`mapfile: invalid array origin
639
+ `,1);fe(e,l,"mapfile");let u=n;!u&&e.state.groupStdin!==void 0&&(u=e.state.groupStdin);let f=[],d=0,h=0,p=0,m=e.limits.maxArrayElements,y=w=>{if(V(w)>e.limits.maxStringLength)throw new C(`mapfile: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");f.push(w)};for(;d<u.length;){e.executionScope.consumeWork(1,"mapfile input");let w=u.indexOf(r,d);if(w===-1){if(d<u.length){if(p<o)p++;else if(s===0||h<s){let v=u.slice(d),A=v.indexOf("\0");if(A!==-1&&(v=v.substring(0,A)),f.length>=m)return F("",`mapfile: array element limit exceeded (${m})
640
+ `,1);y(v),h++}}break}let E=u.slice(d,w),S=E.indexOf("\0");if(S!==-1&&(E=E.substring(0,S)),!a&&r!=="\0"&&(E+=r),d=w+r.length,p<o){p++;continue}if(s>0&&h>=s)break;if(f.length>=m)return F("",`mapfile: array element limit exceeded (${m})
641
+ `,1);y(E),h++}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 F("",`mapfile: array element limit exceeded (${m})
642
+ `,1);i===0&&Ee(e,l);for(let w=0;w<f.length;w++)H(e,l,i+w,f[w]);return e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=""),{...F("","",0),internalStdinConsumed:u.length}}function ra(e,t,n,r=-1){let s=!1,i=`
643
+ `,o="",a=-1,l=-1,c=null,u=-1,f=-1,d=[],h=0,p=!1,m=(_,T)=>{let z=1;for(;z<_.length;){let ne=_[z];if(ne==="r")s=!0,z++;else if(ne==="s")z++;else{if(ne==="d")return z+1<_.length?(i=_.substring(z+1),{nextArgIndex:T+1}):T+1<t.length?(i=t[T+1],{nextArgIndex:T+2}):{nextArgIndex:T+1};if(ne==="n"){if(z+1<_.length){let Y=_.substring(z+1);return a=Number.parseInt(Y,10),(Number.isNaN(a)||a<0)&&(p=!0,a=0),{nextArgIndex:T+1}}else if(T+1<t.length)return a=Number.parseInt(t[T+1],10),(Number.isNaN(a)||a<0)&&(p=!0,a=0),{nextArgIndex:T+2};return{nextArgIndex:T+1}}else if(ne==="N"){if(z+1<_.length){let Y=_.substring(z+1);return l=Number.parseInt(Y,10),(Number.isNaN(l)||l<0)&&(p=!0,l=0),{nextArgIndex:T+1}}else if(T+1<t.length)return l=Number.parseInt(t[T+1],10),(Number.isNaN(l)||l<0)&&(p=!0,l=0),{nextArgIndex:T+2};return{nextArgIndex:T+1}}else{if(ne==="a")return z+1<_.length?(c=_.substring(z+1),{nextArgIndex:T+1}):T+1<t.length?(c=t[T+1],{nextArgIndex:T+2}):{nextArgIndex:T+1};if(ne==="p")return z+1<_.length?(o=_.substring(z+1),{nextArgIndex:T+1}):T+1<t.length?(o=t[T+1],{nextArgIndex:T+2}):{nextArgIndex:T+1};if(ne==="u"){if(z+1<_.length){let Y=_.substring(z+1);return u=Number.parseInt(Y,10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:T+1}}else if(T+1<t.length)return u=Number.parseInt(t[T+1],10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:T+2};return{nextArgIndex:T+1}}else if(ne==="t"){if(z+1<_.length){let Y=_.substring(z+1);return f=Number.parseFloat(Y),Number.isNaN(f)&&(f=0),{nextArgIndex:T+1}}else if(T+1<t.length)return f=Number.parseFloat(t[T+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:T+2};return{nextArgIndex:T+1}}else if(ne==="e"||ne==="i"||ne==="P"){if(ne==="i"&&T+1<t.length)return{nextArgIndex:T+2};z++}else z++}}}return{nextArgIndex:T+1}};for(;h<t.length;){let _=t[h];if(_.startsWith("-")&&_.length>1&&_!=="--"){let T=m(_,h);if(T.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(T.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=T.nextArgIndex}else if(_==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push(_),h++}if(p)return F("","",1);d.length===0&&c===null&&d.push("REPLY");let y=new Set;c&&y.add(c);for(let _ of d)y.add(_);l>=0&&d.length===0&&y.add("REPLY");for(let _ of y){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(_))return F("",`bash: read: \`${_}': not a valid identifier
644
+ `,1);fe(e,_,"bash")}if(f===0){if(c)Ee(e,c);else{for(let _ of d)e.state.env.set(_,"");d.length===0&&e.state.env.set("REPLY","")}return F("","",0)}if(f<0&&f!==-1)return F("","",1);let b=n,w=lt(e,u),E=u>0&&!(w?.kind==="dup-in"&&w.sourceFd===0);if(E){let _=Ws(e,u);if("error"in _){let z=_.error==="write-only"||u===1||u===2?`bash: read: read error: ${u}: Bad file descriptor
644
645
  `:`bash: read: ${u}: invalid file descriptor: Bad file descriptor
645
- `;return L("",B,1)}S=I.content}else!S&&e.state.groupStdin!==void 0&&(S=e.state.groupStdin);let b=i===""?"\0":i,v="",k=0,A=I=>{let _=M(I);if(_>e.limits.maxStringLength-k)throw new $(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");v+=I,k+=_},P=I=>{if(M(I)>e.limits.maxStringLength)throw new $(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")},N=0,x=!0,C=I=>{g?hn(e,u,I):r>=0?hn(e,r,I):e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=S.substring(I),e.state.groupStdinSourceFd!==void 0&&hn(e,e.state.groupStdinSourceFd,I))};if(l>=0){let I=Math.min(l,S.length);v=S.substring(0,I),P(v),N=I,x=I>=l,C(N);let _=d[0]||"REPLY";e.state.env.set(_,v);for(let B=1;B<d.length;B++)e.state.env.set(d[B],"");return L("","",x?0:1)}else if(a>=0){let I=0,_=0,B=!1;for(;_<S.length&&I<a;){let ne=S[_];if(ne===b){N=_+1,B=!0;break}if(!s&&ne==="\\"&&_+1<S.length){let Y=S[_+1];if(Y===b&&b===`
646
- `){_+=2,N=_;continue}if(Y===b){_+=2,I++,A(Y),N=_;continue}A(Y),_+=2,I++,N=_}else A(ne),_++,I++,N=_}x=I>=a||B,C(N)}else{N=0;let I=0;for(;I<S.length;){let _=S[I];if(_===b){N=I+b.length,x=!0;break}if(!s&&_==="\\"&&I+1<S.length){let B=S[I+1];if(B===`
647
- `){I+=2;continue}if(B===b){A(B),I+=2;continue}A(_),A(B),I+=2;continue}A(_),I++}if(I>=S.length&&(x=!1,N=I,v.length===0&&S.length===0)){for(let _ of d)e.state.env.set(_,"");return c&&Ee(e,c),L("","",1)}C(N)}b===`
646
+ `;return F("",z,1)}b=_.content}else!b&&e.state.groupStdin!==void 0&&(b=e.state.groupStdin);let S=i===""?"\0":i,v="",A=0,k=_=>{let T=V(_);if(T>e.limits.maxStringLength-A)throw new C(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");v+=_,A+=T},x=_=>{if(V(_)>e.limits.maxStringLength)throw new C(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")},D=0,$=!0,N=_=>{E?hn(e,u,_):r>=0?hn(e,r,_):e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=b.substring(_),e.state.groupStdinSourceFd!==void 0&&hn(e,e.state.groupStdinSourceFd,_))};if(l>=0){let _=Math.min(l,b.length);v=b.substring(0,_),x(v),D=_,$=_>=l,N(D);let T=d[0]||"REPLY";e.state.env.set(T,v);for(let z=1;z<d.length;z++)e.state.env.set(d[z],"");return F("","",$?0:1)}else if(a>=0){let _=0,T=0,z=!1;for(;T<b.length&&_<a;){let ne=b[T];if(ne===S){D=T+1,z=!0;break}if(!s&&ne==="\\"&&T+1<b.length){let Y=b[T+1];if(Y===S&&S===`
647
+ `){T+=2,D=T;continue}if(Y===S){T+=2,_++,k(Y),D=T;continue}k(Y),T+=2,_++,D=T}else k(ne),T++,_++,D=T}$=_>=a||z,N(D)}else{D=0;let _=0;for(;_<b.length;){let T=b[_];if(T===S){D=_+S.length,$=!0;break}if(!s&&T==="\\"&&_+1<b.length){let z=b[_+1];if(z===`
648
+ `){_+=2;continue}if(z===S){k(z),_+=2;continue}k(T),k(z),_+=2;continue}k(T),_++}if(_>=b.length&&($=!1,D=_,v.length===0&&b.length===0)){for(let T of d)e.state.env.set(T,"");return c&&Ee(e,c),F("","",1)}N(D)}S===`
648
649
  `&&v.endsWith(`
649
- `)&&(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("","",x?0:1);let V=ke(e.state.env),K=e.limits.maxArrayElements;if(c){let{words:I}=Vi(v,V,K,void 0,s);Ee(e,c);for(let _=0;_<I.length;_++)G(e,c,_,D(I[_]));return L("","",x?0:1)}let R=d.length,{words:U,wordStarts:j}=Vi(v,V,K,R,s);for(let I=0;I<d.length;I++){let _=d[I];if(I<d.length-1)e.state.env.set(_,D(U[I]??""));else if(I<j.length){let B=v.substring(j[I]);B=Gl(B,V,s),B=D(B),e.state.env.set(_,B)}else e.state.env.set(_,"")}return L("","",x?0:1)}function ta(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return T("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 T(`bash: return: ${r}: numeric argument required
650
- `,2);n=(s%256+256)%256}throw new Le(n)}var Pr=`set: usage: set [-eux] [+eux] [-o option] [+o option]
650
+ `)&&(v=v.slice(0,-1));let O=_=>s?_:_.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",O(v)),F("","",$?0:1);let R=ve(e.state.env),W=e.limits.maxArrayElements;if(c){let{words:_}=Ui(v,R,W,void 0,s);Ee(e,c);for(let T=0;T<_.length;T++)H(e,c,T,O(_[T]));return F("","",$?0:1)}let P=d.length,{words:B,wordStarts:U}=Ui(v,R,W,P,s);for(let _=0;_<d.length;_++){let T=d[_];if(_<d.length-1)e.state.env.set(T,O(B[_]??""));else if(_<U.length){let z=v.substring(U[_]);z=Kl(z,R,s),z=O(z),e.state.env.set(T,z)}else e.state.env.set(T,"")}return F("","",$?0:1)}function sa(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
651
+ `,2);n=(s%256+256)%256}throw new Le(n)}var Cr=`set: usage: set [-eux] [+eux] [-o option] [+o option]
651
652
  Options:
652
653
  -e Exit immediately if a command exits with non-zero status
653
654
  +e Disable -e
@@ -663,96 +664,96 @@ Options:
663
664
  +o pipefail Disable pipefail
664
665
  -o xtrace Same as -x
665
666
  +o xtrace Disable xtrace
666
- `,Yu=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]]),Us=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]]),tf=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],nf=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function na(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,Bn(e))}function im(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function om(e,t,n){let r=ve(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=ae(e,n,i)??"";s>0&&t.append(" "),t.append(`[${i}]=`),t.reserve(Ws(o)),t.append(yn(o))}t.append(")")}function am(e,t){if(/^[a-zA-Z0-9_]+$/.test(t)){e.append(t);return}e.reserve(Ws(t)),e.append(yn(t))}function lm(e,t,n){let r=xt(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=ae(e,n,i)??"";s>0&&t.append(" "),t.append("["),am(t,i),t.append("]="),t.reserve(Ws(o)),t.append(yn(o))}t.append(" )")}function cm(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 um(e){return e.state.associativeArrays??new Set}function Ju(e){let t=tf.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),n=nf.map(r=>`${r.padEnd(16)}off`);return`${[...t,...n].sort().join(`
667
+ `,nf=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]]),Hs=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]]),of=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],af=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function ia(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,Wn(e))}function dm(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function hm(e,t,n){let r=Ae(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=ae(e,n,i)??"";s>0&&t.append(" "),t.append(`[${i}]=`),t.reserve(js(o)),t.append(yn(o))}t.append(")")}function pm(e,t){if(/^[a-zA-Z0-9_]+$/.test(t)){e.append(t);return}e.reserve(js(t)),e.append(yn(t))}function mm(e,t,n){let r=xt(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=ae(e,n,i)??"";s>0&&t.append(" "),t.append("["),pm(t,i),t.append("]="),t.reserve(js(o)),t.append(yn(o))}t.append(" )")}function ym(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 gm(e){return e.state.associativeArrays??new Set}function rf(e){let t=of.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),n=af.map(r=>`${r.padEnd(16)}off`);return`${[...t,...n].sort().join(`
667
668
  `)}
668
- `}function ef(e){let t=tf.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),n=nf.map(r=>`set +o ${r}`);return`${[...t,...n].sort().join(`
669
+ `}function sf(e){let t=of.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),n=af.map(r=>`set +o ${r}`);return`${[...t,...n].sort().join(`
669
670
  `)}
670
- `}function sa(e,t){if(t.includes("--help"))return ee(Pr);if(t.length===0){let i=cm(e),o=um(e),a=[];for(let[u,f]of e.state.env)/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)&&(i.has(u)||o.has(u)||a.push([u,f]));let l=[...a.map(([u,f])=>({kind:"scalar",name:u,value:f})),...Array.from(i,u=>({kind:"indexed",name:u})),...Array.from(o,u=>({kind:"associative",name:u}))];l.sort((u,f)=>u.name<f.name?-1:u.name>f.name?1:0);let c=new Tn(e.limits.maxOutputSize,"set");for(let u of l)e.executionScope.consumeWork(1,"set variable listing"),u.kind==="scalar"?(c.append(u.name).append("="),c.reserve(Wu(u.value)),c.append(Ae(u.value))):u.kind==="indexed"?om(e,c,u.name):lm(e,c,u.name),c.append(`
671
- `);return ee(c.build())}let n=[],r=()=>n.length>0?ee(n.join("")):te,s=0;for(;s<t.length;){let i=t[s];if((i==="-o"||i==="+o")&&im(t,s)){let o=t[s+1];if(!Us.has(o)){let a=`bash: set: ${o}: invalid option name
672
- ${Pr}`;if(e.state.options.posix)throw new st(1,"",a);return T(a)}na(e,Us.get(o)??null,i==="-o"),s+=2;continue}if(i==="-o"){n.push(Ju(e)),s++;continue}if(i==="+o"){n.push(ef(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 c=i[l];if(c==="o"){let u=s+1+a;if(u<t.length&&!t[u].startsWith("-")&&!t[u].startsWith("+")){let d=t[u];if(!Us.has(d)){let h=`bash: set: ${d}: invalid option name
673
- ${Pr}`;if(e.state.options.posix)throw new st(1,"",h);return T(h)}na(e,Us.get(d)??null,o),a++;continue}n.push(o?Ju(e):ef(e));continue}if(!Yu.has(c)){let u=`bash: set: ${i[0]}${c}: invalid option
674
- ${Pr}`;if(e.state.options.posix)throw new st(1,"",u);return T(u)}na(e,Yu.get(c)??null,o)}s+=1+a;continue}if(i==="--")return ra(e,t.slice(s+1)),r();if(i==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,Bn(e),s+1<t.length)return ra(e,t.slice(s+1)),r();s++;continue}if(i==="+"){s++;continue}if(i.startsWith("-")||i.startsWith("+")){let o=`bash: set: ${i}: invalid option
675
- ${Pr}`;if(e.state.options.posix)throw new st(1,"",o);return T(o)}return ra(e,t.slice(s)),r()}return r()}function ra(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 ia(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
676
- `;if(e.state.options.posix)throw new st(1,"",a);return T(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
677
- `;if(e.state.options.posix)throw new st(1,"",o);return T(o)}if(n===0)return te;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(" ")),te}async function oa(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
678
- `,2);let r=n[0],s=null,i=null;if(r.includes("/")){let c=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(c),s=c}catch{}}else{let u=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of u){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 T(`bash: ${r}: No such file or directory
679
- `);let o=new Map;if(n.length>1){for(let u=1;u<=9;u++)o.set(String(u),e.state.env.get(String(u)));o.set("#",e.state.env.get("#")),o.set("@",e.state.env.get("@"));let c=n.slice(1);e.state.env.set("#",String(c.length)),e.state.env.set("@",c.join(" "));for(let u=0;u<c.length&&u<9;u++)e.state.env.set(String(u+1),c[u]);for(let u=c.length+1;u<=9;u++)e.state.env.delete(String(u))}let a=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=a,n.length>1)for(let[c,u]of o)u===void 0?e.state.env.delete(c):e.state.env.set(c,u)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new $(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let c=He(i),u=await e.executeScript(c);return l(),u}catch(c){if(l(),c instanceof q)throw c;if(c instanceof Le)return L(c.stdout,c.stderr,c.exitCode);if(c.name==="ParseException")return T(`bash: ${r}: ${c.message}
680
- `);throw c}}function rf(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function fm(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function sf(e,t){if(fm(t))return null;try{let n=new Z,r=re(n,t);return await J(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}function of(e,t){if(e.state.localVarStack?.has(t)){let r=Ds(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)Os(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),aa(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),Os(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||Os(e,t),!0}}return!1}function aa(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 af(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 Z().parseWordFromString(n,!0,!1);return se(e,s)}if(t.includes("$")){let r=new Z().parseWordFromString(t,!1,!1);return se(e,r)}return t}async function la(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 c=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(c){let d=c[1],h=c[2];if(We(e,d)){r+=`bash: unset: ${d}: cannot unset: readonly variable
681
- `,s=1;continue}if(h==="@"||h==="*"){cr(e,d),e.state.env.delete(d);continue}let p=e.state.associativeArrays?.has(d);if(p){let g=await af(e,h);An(e,d,g);continue}let m=Et(e,d),E=e.state.declaredVars?.has(d);if((e.state.env.has(d)||E)&&!m&&!p){r+=`bash: unset: ${d}: not an array variable
682
- `,s=1;continue}let y=await sf(e,h);if(y===null&&m){r+=`bash: unset: ${h}: not a valid identifier
683
- `,s=1;continue}if(y===null)continue;if(y<0){let g=Q(e,d),b=g.length,v=e.state.currentLine;if(b===0){r+=`bash: line ${v}: unset: [${y}]: bad array subscript
684
- `,s=1;continue}let k=b+y;if(k<0){r+=`bash: line ${v}: unset: [${y}]: bad array subscript
685
- `,s=1;continue}let A=g[k][0];An(e,d,A);continue}An(e,d,y);continue}if(!rf(i)){r+=`bash: unset: \`${i}': not a valid identifier
671
+ `}function aa(e,t){if(t.includes("--help"))return ee(Cr);if(t.length===0){let i=ym(e),o=gm(e),a=[];for(let[u,f]of e.state.env)/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)&&(i.has(u)||o.has(u)||a.push([u,f]));let l=[...a.map(([u,f])=>({kind:"scalar",name:u,value:f})),...Array.from(i,u=>({kind:"indexed",name:u})),...Array.from(o,u=>({kind:"associative",name:u}))];l.sort((u,f)=>u.name<f.name?-1:u.name>f.name?1:0);let c=new Ln(e.limits.maxOutputSize,"set");for(let u of l)e.executionScope.consumeWork(1,"set variable listing"),u.kind==="scalar"?(c.append(u.name).append("="),c.reserve(ju(u.value)),c.append(Se(u.value))):u.kind==="indexed"?hm(e,c,u.name):mm(e,c,u.name),c.append(`
672
+ `);return ee(c.build())}let n=[],r=()=>n.length>0?ee(n.join("")):te,s=0;for(;s<t.length;){let i=t[s];if((i==="-o"||i==="+o")&&dm(t,s)){let o=t[s+1];if(!Hs.has(o)){let a=`bash: set: ${o}: invalid option name
673
+ ${Cr}`;if(e.state.options.posix)throw new rt(1,"",a);return L(a)}ia(e,Hs.get(o)??null,i==="-o"),s+=2;continue}if(i==="-o"){n.push(rf(e)),s++;continue}if(i==="+o"){n.push(sf(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 c=i[l];if(c==="o"){let u=s+1+a;if(u<t.length&&!t[u].startsWith("-")&&!t[u].startsWith("+")){let d=t[u];if(!Hs.has(d)){let h=`bash: set: ${d}: invalid option name
674
+ ${Cr}`;if(e.state.options.posix)throw new rt(1,"",h);return L(h)}ia(e,Hs.get(d)??null,o),a++;continue}n.push(o?rf(e):sf(e));continue}if(!nf.has(c)){let u=`bash: set: ${i[0]}${c}: invalid option
675
+ ${Cr}`;if(e.state.options.posix)throw new rt(1,"",u);return L(u)}ia(e,nf.get(c)??null,o)}s+=1+a;continue}if(i==="--")return oa(e,t.slice(s+1)),r();if(i==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,Wn(e),s+1<t.length)return oa(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
+ ${Cr}`;if(e.state.options.posix)throw new rt(1,"",o);return L(o)}return oa(e,t.slice(s)),r()}return r()}function oa(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 la(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 rt(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
678
+ `;if(e.state.options.posix)throw new rt(1,"",o);return L(o)}if(n===0)return te;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(" ")),te}async function ca(e,t){let n=t;if(n.length>0&&n[0]==="--"&&(n=n.slice(1)),n.length===0)return F("",`bash: source: filename argument required
679
+ `,2);let r=n[0],s=null,i=null;if(r.includes("/")){let c=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(c),s=c}catch{}}else{let u=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of u){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
680
+ `);let o=new Map;if(n.length>1){for(let u=1;u<=9;u++)o.set(String(u),e.state.env.get(String(u)));o.set("#",e.state.env.get("#")),o.set("@",e.state.env.get("@"));let c=n.slice(1);e.state.env.set("#",String(c.length)),e.state.env.set("@",c.join(" "));for(let u=0;u<c.length&&u<9;u++)e.state.env.set(String(u+1),c[u]);for(let u=c.length+1;u<=9;u++)e.state.env.delete(String(u))}let a=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=a,n.length>1)for(let[c,u]of o)u===void 0?e.state.env.delete(c):e.state.env.set(c,u)};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 c=He(i),u=await e.executeScript(c);return l(),u}catch(c){if(l(),c instanceof G)throw c;if(c instanceof Le)return F(c.stdout,c.stderr,c.exitCode);if(c.name==="ParseException")return L(`bash: ${r}: ${c.message}
681
+ `);throw c}}function lf(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function wm(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function cf(e,t){if(wm(t))return null;try{let n=new Q,r=re(n,t);return await J(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}function uf(e,t){if(e.state.localVarStack?.has(t)){let r=Ls(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)Ts(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),ua(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),Ts(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||Ts(e,t),!0}}return!1}function ua(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 ff(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 Q().parseWordFromString(n,!0,!1);return se(e,s)}if(t.includes("$")){let r=new Q().parseWordFromString(t,!1,!1);return se(e,r)}return t}async function fa(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 c=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(c){let d=c[1],h=c[2];if(We(e,d)){r+=`bash: unset: ${d}: cannot unset: readonly variable
682
+ `,s=1;continue}if(h==="@"||h==="*"){ur(e,d),e.state.env.delete(d);continue}let p=e.state.associativeArrays?.has(d);if(p){let E=await ff(e,h);An(e,d,E);continue}let m=wt(e,d),y=e.state.declaredVars?.has(d);if((e.state.env.has(d)||y)&&!m&&!p){r+=`bash: unset: ${d}: not an array variable
683
+ `,s=1;continue}let w=await cf(e,h);if(w===null&&m){r+=`bash: unset: ${h}: not a valid identifier
684
+ `,s=1;continue}if(w===null)continue;if(w<0){let E=K(e,d),S=E.length,v=e.state.currentLine;if(S===0){r+=`bash: line ${v}: unset: [${w}]: bad array subscript
685
+ `,s=1;continue}let A=S+w;if(A<0){r+=`bash: line ${v}: unset: [${w}]: bad array subscript
686
+ `,s=1;continue}let k=E[A][0];An(e,d,k);continue}An(e,d,w);continue}if(!lf(i)){r+=`bash: unset: \`${i}': not a valid identifier
686
687
  `,s=1;continue}let u=i;if(ue(e,i)){let d=Be(e,i);d&&d!==i&&(u=d)}if(We(e,u)){r+=`bash: unset: ${u}: cannot unset: readonly variable
687
- `,s=1;continue}cr(e,u);let f=uo(e,u);if(f!==void 0&&f!==e.state.callDepth)of(e,u);else if(e.state.fullyUnsetLocals?.has(u))e.state.env.delete(u);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(u),h=e.state.mutatedTempEnvVars?.has(u);if((d||h)&&e.state.localVarStack?.has(u)){let p=Ds(e,u);p?p.value===void 0?e.state.env.delete(u):e.state.env.set(u,p.value):e.state.env.delete(u)}else e.state.env.delete(u)}else aa(e,u)||e.state.env.delete(u);e.state.exportedVars?.delete(u);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let c=o[1],u=o[2];if(We(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable
688
- `,s=1;continue}if(u==="@"||u==="*"){cr(e,c),e.state.env.delete(c);continue}let f=e.state.associativeArrays?.has(c);if(f){let m=await af(e,u);An(e,c,m);continue}let d=Et(e,c);if(e.state.env.has(c)&&!d&&!f){r+=`bash: unset: ${c}: not an array variable
689
- `,s=1;continue}let p=await sf(e,u);if(p===null&&d){r+=`bash: unset: ${u}: not a valid identifier
690
- `,s=1;continue}if(p===null)continue;if(p<0){let m=Q(e,c),E=m.length,S=e.state.currentLine;if(E===0){r+=`bash: line ${S}: unset: [${p}]: bad array subscript
691
- `,s=1;continue}let y=E+p;if(y<0){r+=`bash: line ${S}: unset: [${p}]: bad array subscript
692
- `,s=1;continue}let g=m[y][0];An(e,c,g);continue}An(e,c,p);continue}if(!rf(i)){r+=`bash: unset: \`${i}': not a valid identifier
688
+ `,s=1;continue}ur(e,u);let f=ho(e,u);if(f!==void 0&&f!==e.state.callDepth)uf(e,u);else if(e.state.fullyUnsetLocals?.has(u))e.state.env.delete(u);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(u),h=e.state.mutatedTempEnvVars?.has(u);if((d||h)&&e.state.localVarStack?.has(u)){let p=Ls(e,u);p?p.value===void 0?e.state.env.delete(u):e.state.env.set(u,p.value):e.state.env.delete(u)}else e.state.env.delete(u)}else ua(e,u)||e.state.env.delete(u);e.state.exportedVars?.delete(u);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let c=o[1],u=o[2];if(We(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable
689
+ `,s=1;continue}if(u==="@"||u==="*"){ur(e,c),e.state.env.delete(c);continue}let f=e.state.associativeArrays?.has(c);if(f){let m=await ff(e,u);An(e,c,m);continue}let d=wt(e,c);if(e.state.env.has(c)&&!d&&!f){r+=`bash: unset: ${c}: not an array variable
690
+ `,s=1;continue}let p=await cf(e,u);if(p===null&&d){r+=`bash: unset: ${u}: not a valid identifier
691
+ `,s=1;continue}if(p===null)continue;if(p<0){let m=K(e,c),y=m.length,b=e.state.currentLine;if(y===0){r+=`bash: line ${b}: unset: [${p}]: bad array subscript
692
+ `,s=1;continue}let w=y+p;if(w<0){r+=`bash: line ${b}: unset: [${p}]: bad array subscript
693
+ `,s=1;continue}let E=m[w][0];An(e,c,E);continue}An(e,c,p);continue}if(!lf(i)){r+=`bash: unset: \`${i}': not a valid identifier
693
694
  `,s=1;continue}let a=i;if(ue(e,i)){let c=Be(e,i);c&&c!==i&&(a=c)}if(We(e,a)){r+=`bash: unset: ${a}: cannot unset: readonly variable
694
- `,s=1;continue}cr(e,a);let l=uo(e,a);if(l!==void 0&&l!==e.state.callDepth)of(e,a);else if(e.state.fullyUnsetLocals?.has(a))e.state.env.delete(a);else if(l!==void 0){let c=e.state.accessedTempEnvVars?.has(a),u=e.state.mutatedTempEnvVars?.has(a);if((c||u)&&e.state.localVarStack?.has(a)){let f=Ds(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 aa(e,a)||e.state.env.delete(a);e.state.exportedVars?.delete(a),e.state.functions.delete(i)}return L("",r,s)}function Ot(e,t,n,r){let s=n+M(t)+1;if(s>r)throw new $(`shopt: output size limit exceeded (${r} bytes)`,"output_size");return e.push(t),s}var ca=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],dm=["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 js(e){return ca.includes(e)}function hm(e){return dm.includes(e)}function lf(e,t){let n=e.limits.maxArrayElements;if(t.length>n)throw new $(`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,c=[],u=0;for(;u<t.length;){let E=t[u];if(E==="--"){u++;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
695
- `}}}u++}else break}for(;u<t.length;)c.push(t[u]),u++;if(l)return pm(e,c,s,i,o,a);if(s&&i)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
696
- `};if(c.length===0){if(s||i){let S=[];for(let y of ca){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(`
695
+ `,s=1;continue}ur(e,a);let l=ho(e,a);if(l!==void 0&&l!==e.state.callDepth)uf(e,a);else if(e.state.fullyUnsetLocals?.has(a))e.state.env.delete(a);else if(l!==void 0){let c=e.state.accessedTempEnvVars?.has(a),u=e.state.mutatedTempEnvVars?.has(a);if((c||u)&&e.state.localVarStack?.has(a)){let f=Ls(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 ua(e,a)||e.state.env.delete(a);e.state.exportedVars?.delete(a),e.state.functions.delete(i)}return F("",r,s)}function Ot(e,t,n,r){let s=n+V(t)+1;if(s>r)throw new C(`shopt: output size limit exceeded (${r} bytes)`,"output_size");return e.push(t),s}var da=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],Em=["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 Zs(e){return da.includes(e)}function bm(e){return Em.includes(e)}function df(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,c=[],u=0;for(;u<t.length;){let y=t[u];if(y==="--"){u++;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
696
+ `}}}u++}else break}for(;u<t.length;)c.push(t[u]),u++;if(l)return Sm(e,c,s,i,o,a);if(s&&i)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
697
+ `};if(c.length===0){if(s||i){let b=[];for(let w of da){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(`
697
698
  `)}
698
- `:"",stderr:""}}let E=[];for(let S of ca){let y=e.state.shoptOptions[S];E.push(o?`shopt ${y?"-s":"-u"} ${S}`:`${S} ${y?"on":"off"}`)}return{exitCode:0,stdout:`${E.join(`
699
+ `:"",stderr:""}}let y=[];for(let b of da){let w=e.state.shoptOptions[b];y.push(o?`shopt ${w?"-s":"-u"} ${b}`:`${b} ${w?"on":"off"}`)}return{exitCode:0,stdout:`${y.join(`
699
700
  `)}
700
- `,stderr:""}}let f=!1,d=[],h=0,p=[],m=0;for(let E of c){if(!js(E)&&!hm(E)){h=Ot(d,`shopt: ${E}: invalid shell option name`,h,r),f=!0;continue}if(s)js(E)&&(e.state.shoptOptions[E]=!0,hi(e));else if(i)js(E)&&(e.state.shoptOptions[E]=!1,hi(e));else if(js(E)){let S=e.state.shoptOptions[E];a?S||(f=!0):o?(m=Ot(p,`shopt ${S?"-s":"-u"} ${E}`,m,r),S||(f=!0)):(m=Ot(p,`${E} ${S?"on":"off"}`,m,r),S||(f=!0))}else a?f=!0:o?(m=Ot(p,`shopt -u ${E}`,m,r),f=!0):(m=Ot(p,`${E} off`,m,r),f=!0)}return{exitCode:f?1:0,stdout:p.length>0?`${p.join(`
701
+ `,stderr:""}}let f=!1,d=[],h=0,p=[],m=0;for(let y of c){if(!Zs(y)&&!bm(y)){h=Ot(d,`shopt: ${y}: invalid shell option name`,h,r),f=!0;continue}if(s)Zs(y)&&(e.state.shoptOptions[y]=!0,mi(e));else if(i)Zs(y)&&(e.state.shoptOptions[y]=!1,mi(e));else if(Zs(y)){let b=e.state.shoptOptions[y];a?b||(f=!0):o?(m=Ot(p,`shopt ${b?"-s":"-u"} ${y}`,m,r),b||(f=!0)):(m=Ot(p,`${y} ${b?"on":"off"}`,m,r),b||(f=!0))}else a?f=!0:o?(m=Ot(p,`shopt -u ${y}`,m,r),f=!0):(m=Ot(p,`${y} off`,m,r),f=!0)}return{exitCode:f?1:0,stdout:p.length>0?`${p.join(`
701
702
  `)}
702
703
  `:"",stderr:d.length>0?`${d.join(`
703
704
  `)}
704
- `:""}}function pm(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"],c=[...a.keys(),...l].sort();if(t.length===0){let m=[];for(let E of c){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(`
705
+ `:""}}function Sm(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"],c=[...a.keys(),...l].sort();if(t.length===0){let m=[];for(let y of c){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(`
705
706
  `)}
706
- `:"",stderr:""}}let u=!1,f=[],d=0,h=[],p=0;for(let m of t){let E=a.has(m),S=l.includes(m);if(!E&&!S){d=Ot(f,`shopt: ${m}: invalid option name`,d,o),u=!0;continue}if(S){n||r||(i?u=!0:s?(p=Ot(h,`set +o ${m}`,p,o),u=!0):(p=Ot(h,`${m} off`,p,o),u=!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,Bn(e);else if(r)e.state.options[y]=!1,Bn(e);else{let g=e.state.options[y];i?g||(u=!0):s?(p=Ot(h,`set ${g?"-o":"+o"} ${m}`,p,o),g||(u=!0)):(p=Ot(h,`${m} ${g?"on":"off"}`,p,o),g||(u=!0))}}return{exitCode:u?1:0,stdout:h.length>0?`${h.join(`
707
+ `:"",stderr:""}}let u=!1,f=[],d=0,h=[],p=0;for(let m of t){let y=a.has(m),b=l.includes(m);if(!y&&!b){d=Ot(f,`shopt: ${m}: invalid option name`,d,o),u=!0;continue}if(b){n||r||(i?u=!0:s?(p=Ot(h,`set +o ${m}`,p,o),u=!0):(p=Ot(h,`${m} off`,p,o),u=!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,Wn(e);else if(r)e.state.options[w]=!1,Wn(e);else{let E=e.state.options[w];i?E||(u=!0):s?(p=Ot(h,`set ${E?"-o":"+o"} ${m}`,p,o),E||(u=!0)):(p=Ot(h,`${m} ${E?"on":"off"}`,p,o),E||(u=!0))}}return{exitCode:u?1:0,stdout:h.length>0?`${h.join(`
707
708
  `)}
708
709
  `:"",stderr:f.length>0?`${f.join(`
709
710
  `)}
710
- `:""}}function qs(e,t){return e===`/bin/${t}`||e===`/usr/bin/${t}`}async function cf(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,c=e.commands.get(l);return c&&qs(o,l)?{cmd:c,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&&qs(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 c=await e.fs.stat(l);if(c.isDirectory)continue;let u=(c.mode&73)!==0,f=e.commands.get(t),d=qs(l,t);if(f&&d)return{cmd:f,path:l};if(u){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 Gs(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(qs(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 mm(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function pe(e,t,n,r){return((...s)=>{or(t,n,`${r} call`);let i=e(...s);return mm(i)?i.then(o=>(or(t,n,`${r} post-await`),o),o=>{throw or(t,n,`${r} post-await`),o}):(or(t,n,`${r} return`),i)})}function ym(e,t,n){let r={readFile:pe(e.readFile.bind(e),t,n,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:pe(e.readFileBytes.bind(e),t,n,"fs.readFileBytes")}:Object.create(null),readFileBuffer:pe(e.readFileBuffer.bind(e),t,n,"fs.readFileBuffer"),writeFile:pe(e.writeFile.bind(e),t,n,"fs.writeFile"),appendFile:pe(e.appendFile.bind(e),t,n,"fs.appendFile"),exists:pe(e.exists.bind(e),t,n,"fs.exists"),stat:pe(e.stat.bind(e),t,n,"fs.stat"),mkdir:pe(e.mkdir.bind(e),t,n,"fs.mkdir"),readdir:pe(e.readdir.bind(e),t,n,"fs.readdir"),rm:pe(e.rm.bind(e),t,n,"fs.rm"),cp:pe(e.cp.bind(e),t,n,"fs.cp"),mv:pe(e.mv.bind(e),t,n,"fs.mv"),resolvePath:pe(e.resolvePath.bind(e),t,n,"fs.resolvePath"),getAllPaths:pe(e.getAllPaths.bind(e),t,n,"fs.getAllPaths"),chmod:pe(e.chmod.bind(e),t,n,"fs.chmod"),symlink:pe(e.symlink.bind(e),t,n,"fs.symlink"),link:pe(e.link.bind(e),t,n,"fs.link"),readlink:pe(e.readlink.bind(e),t,n,"fs.readlink"),lstat:pe(e.lstat.bind(e),t,n,"fs.lstat"),realpath:pe(e.realpath.bind(e),t,n,"fs.realpath"),utimes:pe(e.utimes.bind(e),t,n,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=pe(e.readdirWithFileTypes.bind(e),t,n,"fs.readdirWithFileTypes")),e.createExclusive&&(r.createExclusive=pe(e.createExclusive.bind(e),t,n,"fs.createExclusive")),r}function ua(e,t){if(!e.requireDefenseContext)return e;let n=`command:${t}`,r=Object.getOwnPropertyDescriptors(e);r.fs={value:ym(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=pe(e.exec,e.requireDefenseContext,n,"exec")),e.origCommand&&(s.origCommand=pe(e.origCommand,e.requireDefenseContext,n,"origCommand")),e.fetch&&(s.fetch=pe(e.fetch,e.requireDefenseContext,n,"fetch")),e.sleep&&(s.sleep=pe(e.sleep,e.requireDefenseContext,n,"sleep")),e.getRegisteredCommands&&(s.getRegisteredCommands=pe(e.getRegisteredCommands,e.requireDefenseContext,n,"getRegisteredCommands")),s}var uf="+ ";async function ff(e){let t=e.state.env.get("PS4");if(t===void 0)return uf;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 Z().parseWordFromString(t,!1,!1);return await se(e,a)}catch(o){if(o instanceof le&&!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
711
- `,t||uf}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 gm(e){return e.map(t=>wm(t)).join(" ")}function wm(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let n=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
711
+ `:""}}function Qs(e,t){return e===`/bin/${t}`||e===`/usr/bin/${t}`}async function hf(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,c=e.commands.get(l);return c&&Qs(o,l)?{cmd:c,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&&Qs(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 c=await e.fs.stat(l);if(c.isDirectory)continue;let u=(c.mode&73)!==0,f=e.commands.get(t),d=Qs(l,t);if(f&&d)return{cmd:f,path:l};if(u){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 Ks(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(Qs(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 Am(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function pe(e,t,n,r){return((...s)=>{ar(t,n,`${r} call`);let i=e(...s);return Am(i)?i.then(o=>(ar(t,n,`${r} post-await`),o),o=>{throw ar(t,n,`${r} post-await`),o}):(ar(t,n,`${r} return`),i)})}function vm(e,t,n){let r={readFile:pe(e.readFile.bind(e),t,n,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:pe(e.readFileBytes.bind(e),t,n,"fs.readFileBytes")}:Object.create(null),readFileBuffer:pe(e.readFileBuffer.bind(e),t,n,"fs.readFileBuffer"),writeFile:pe(e.writeFile.bind(e),t,n,"fs.writeFile"),appendFile:pe(e.appendFile.bind(e),t,n,"fs.appendFile"),exists:pe(e.exists.bind(e),t,n,"fs.exists"),stat:pe(e.stat.bind(e),t,n,"fs.stat"),mkdir:pe(e.mkdir.bind(e),t,n,"fs.mkdir"),readdir:pe(e.readdir.bind(e),t,n,"fs.readdir"),rm:pe(e.rm.bind(e),t,n,"fs.rm"),cp:pe(e.cp.bind(e),t,n,"fs.cp"),mv:pe(e.mv.bind(e),t,n,"fs.mv"),resolvePath:pe(e.resolvePath.bind(e),t,n,"fs.resolvePath"),getAllPaths:pe(e.getAllPaths.bind(e),t,n,"fs.getAllPaths"),chmod:pe(e.chmod.bind(e),t,n,"fs.chmod"),symlink:pe(e.symlink.bind(e),t,n,"fs.symlink"),link:pe(e.link.bind(e),t,n,"fs.link"),readlink:pe(e.readlink.bind(e),t,n,"fs.readlink"),lstat:pe(e.lstat.bind(e),t,n,"fs.lstat"),realpath:pe(e.realpath.bind(e),t,n,"fs.realpath"),utimes:pe(e.utimes.bind(e),t,n,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=pe(e.readdirWithFileTypes.bind(e),t,n,"fs.readdirWithFileTypes")),e.createExclusive&&(r.createExclusive=pe(e.createExclusive.bind(e),t,n,"fs.createExclusive")),r}function ha(e,t){if(!e.requireDefenseContext)return e;let n=`command:${t}`,r=Object.getOwnPropertyDescriptors(e);r.fs={value:vm(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=pe(e.exec,e.requireDefenseContext,n,"exec")),e.origCommand&&(s.origCommand=pe(e.origCommand,e.requireDefenseContext,n,"origCommand")),e.fetch&&(s.fetch=pe(e.fetch,e.requireDefenseContext,n,"fetch")),e.sleep&&(s.sleep=pe(e.sleep,e.requireDefenseContext,n,"sleep")),e.getRegisteredCommands&&(s.getRegisteredCommands=pe(e.getRegisteredCommands,e.requireDefenseContext,n,"getRegisteredCommands")),s}var pf="+ ";async function mf(e){let t=e.state.env.get("PS4");if(t===void 0)return pf;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 Q().parseWordFromString(t,!1,!1);return await se(e,a)}catch(o){if(o instanceof le&&!o.fatal)return t;if(o instanceof Tn||o instanceof Error&&o.name==="AbortError")throw o;return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
712
+ `,t||pf}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 km(e){return e.map(t=>xm(t)).join(" ")}function xm(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let n=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
712
713
  `),s=e.includes(" "),i=e.includes("\\"),o=e.includes("'");if(n||r||s||i){let l="";for(let c of e){let u=c.charCodeAt(0);c===`
713
- `?l+="\\n":c===" "?l+="\\t":c==="\\"?l+="\\\\":c==="'"?l+="'":c==='"'?l+='"':u<32||u===127?u<256?l+=`\\x${u.toString(16).padStart(2,"0")}`:l+=`\\u${u.toString(16).padStart(4,"0")}`:l+=c}return`$'${l}'`}return o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function df(e,t,n){if(!e.state.options.xtrace)return"";let r=await ff(e),s=[t,...n],i=gm(s);return`${r}${i}
714
- `}async function hf(e,t,n){return e.state.options.xtrace?`${await ff(e)}${t}=${n}
715
- `:""}function Hs(e,t,n){return Gt([t,n],"",e.limits.maxStringLength,"array assignment")}async function pf(e,t){let n=new Map,r="";for(let s of t.assignments){let i=s.name;if(s.array){let u=await Em(e,t,i,s.array,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};if(r+=u.xtraceOutput,u.continueToNext)continue}let o=s.value?await se(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
716
- `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let u=await km(e,t,l[1],l[2],o,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};if(u.continueToNext)continue}let c=await xm(e,t,i,o,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};r+=c.xtraceOutput,c.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:n}}async function Em(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
717
- `,1)};if(ue(e,n)){let p=Cn(e,n);if(p===void 0||p==="")throw new q(1,"","");let m=Be(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
714
+ `?l+="\\n":c===" "?l+="\\t":c==="\\"?l+="\\\\":c==="'"?l+="'":c==='"'?l+='"':u<32||u===127?u<256?l+=`\\x${u.toString(16).padStart(2,"0")}`:l+=`\\u${u.toString(16).padStart(4,"0")}`:l+=c}return`$'${l}'`}return o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function yf(e,t,n){if(!e.state.options.xtrace)return"";let r=await mf(e),s=[t,...n],i=km(s);return`${r}${i}
715
+ `}async function gf(e,t,n){return e.state.options.xtrace?`${await mf(e)}${t}=${n}
716
+ `:""}function Xs(e,t,n){return Gt([t,n],"",e.limits.maxStringLength,"array assignment")}async function wf(e,t){let n=new Map,r="";for(let s of t.assignments){let i=s.name;if(s.array){let u=await Pm(e,t,i,s.array,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};if(r+=u.xtraceOutput,u.continueToNext)continue}let o=s.value?await se(e,s.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:F("",`bash: ${i}: bad array subscript
717
+ `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let u=await Om(e,t,l[1],l[2],o,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};if(u.continueToNext)continue}let c=await Dm(e,t,i,o,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};r+=c.xtraceOutput,c.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:n}}async function Pm(e,t,n,r,s,i){let o="";if(/\[.+\]$/.test(n))return{continueToNext:!1,xtraceOutput:"",error:F("",`bash: ${n}: cannot assign list to array member
718
+ `,1)};if(ue(e,n)){let p=Cn(e,n);if(p===void 0||p==="")throw new G(1,"","");let m=Be(e,n);if(m&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(m))return{continueToNext:!1,xtraceOutput:"",error:F("",`bash: ${n}: cannot assign list to array member
718
719
  `,1)}}if(We(e,n)){if(t.name)return o+=`bash: ${n}: readonly variable
719
- `,{continueToNext:!0,xtraceOutput:o};let p=fe(e,n);if(p)return{continueToNext:!1,xtraceOutput:"",error:p}}let a=e.state.associativeArrays?.has(n),l=xe(e,n),c=l?Me(l):void 0,u=e.state.env.get(n),f=()=>{e.state.arrays??=new Map,c?e.state.arrays.set(n,c):e.state.arrays.delete(n),u===void 0?e.state.env.delete(n):e.state.env.set(n,u)},d=bm(r),h=()=>{Ee(e,n),e.state.env.delete(n)};try{a&&d?await Sm(e,t,n,r,s,h,p=>{o+=p}):d?await Am(e,n,r,s,h):await vm(e,n,r,s,h)}catch(p){throw f(),p}if(t.name){i.set(n,e.state.env.get(n));let m=`(${r.map(E=>Mn(E)).join(" ")})`;e.state.env.set(n,m)}return{continueToNext:!0,xtraceOutput:o}}function bm(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 Sm(e,t,n,r,s,i,o){let a=[];for(let l of r){if(a.length>=e.limits.maxArrayElements)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let c=ui(l);if(c){let{key:u,valueParts:f,append:d}=c,h;f.length>0?(h=await se(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(h=an(e,h))):h="",a.push({type:"keyed",key:u,value:h,append:d})}else{let u=await se(e,l);a.push({type:"invalid",expandedValue:u})}}e.executionScope.consumeWork(a.length,"associative array assignment"),s||i();for(let l of a)if(l.type==="keyed")if(l.append){let c=ae(e,n,l.key)??"";G(e,n,l.key,Hs(e,c,l.value),"associative")}else G(e,n,l.key,l.value,"associative");else{let c=t.line??e.state.currentLine??1;o(`bash: line ${c}: ${n}: ${l.expandedValue}: must use subscript when assigning associative array
720
- `)}}async function Am(e,t,n,r,s){let i=[],o=0;for(let l of n){let c=ui(l);if(c){if(o>=e.limits.maxArrayElements)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let{key:u,valueParts:f,append:d}=c,h;f.length>0?(h=await se(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(h=an(e,h))):h="",i.push({type:"keyed",indexExpr:u,value:h,append:d}),o++}else{let u=await vt(e,l);if(u.values.length>e.limits.maxArrayElements-o)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push({type:"non-keyed",values:u.values}),o+=u.values.length}}e.executionScope.consumeWork(o,"indexed array assignment"),r||s();let a=0;for(let l of i)if(l.type==="keyed"){let c;try{let u=new Z,f=re(u,l.indexExpr);c=await J(e,f.expression,!1)}catch{if(/^-?\d+$/.test(l.indexExpr))c=Number.parseInt(l.indexExpr,10);else{let u=e.state.env.get(l.indexExpr);c=u?Number.parseInt(u,10):0,Number.isNaN(c)&&(c=0)}}if(l.append){let u=ae(e,t,c)??"";G(e,t,c,Hs(e,u,l.value))}else G(e,t,c,l.value);a=c+1}else for(let c of l.values)G(e,t,a++,c)}async function vm(e,t,n,r,s){let i=[];for(let a of n){let l=await vt(e,a);for(let c of l.values){if(i.length>=e.limits.maxArrayElements)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push(c)}}let o=0;if(e.executionScope.consumeWork(i.length,"indexed array assignment"),r){let a=Q(e,t);if(a.length>0)o=Math.max(...a.map(([c])=>typeof c=="number"?c:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(G(e,t,0,l),e.state.env.delete(t),o=1)}}else s();for(let a=0;a<i.length;a++)G(e,t,o+a,i[a])}async function km(e,t,n,r,s,i,o){let a=n;if(ue(e,n)){let f=Be(e,n);if(f&&f!==n){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: \`${f}': not a valid identifier
721
- `,1)};a=f}}if(We(e,a)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=fe(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l=e.state.associativeArrays?.has(a),c;if(l)c=await mf(e,r);else{let f=await fa(e,a,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};c=String(f.index)}let u=i?Hs(e,ae(e,a,c)||"",s):s;return t.name||G(e,a,c,u,l?"associative":"indexed"),{continueToNext:!0,xtraceOutput:""}}async function mf(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 Z().parseWordFromString(r,!0,!1);n=await se(e,i)}else if(t.includes("$")){let s=new Z().parseWordFromString(t,!1,!1);n=await se(e,s)}else n=t;return n}async function fa(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 Z,o=re(i,r);s=await J(e,o.expression,!1)}catch(i){if(i instanceof q)throw i;if(i instanceof le){let l=`bash: line ${e.state.currentLine}: ${n}: ${i.message}
722
- `;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
723
- `,1)}}Number.isNaN(s)&&(s=0)}if(s<0){let i=Q(e,t);if(i.length===0){let a=e.state.currentLine;return{index:0,error:L("",`bash: line ${a}: ${t}[${n}]: bad array subscript
724
- `,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
725
- `,1)}}}return{index:s}}async function xm(e,t,n,r,s,i){let o="",a=n,l=null;if(ue(e,n)){let f=is(e,n,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: ${n}: circular name reference
720
+ `,{continueToNext:!0,xtraceOutput:o};let p=fe(e,n);if(p)return{continueToNext:!1,xtraceOutput:"",error:p}}let a=e.state.associativeArrays?.has(n),l=ke(e,n),c=l?Me(l):void 0,u=e.state.env.get(n),f=()=>{e.state.arrays??=new Map,c?e.state.arrays.set(n,c):e.state.arrays.delete(n),u===void 0?e.state.env.delete(n):e.state.env.set(n,u)},d=$m(r),h=()=>{Ee(e,n),e.state.env.delete(n)};try{a&&d?await Cm(e,t,n,r,s,h,p=>{o+=p}):d?await Nm(e,n,r,s,h):await Rm(e,n,r,s,h)}catch(p){throw f(),p}if(t.name){i.set(n,e.state.env.get(n));let m=`(${r.map(y=>Bn(y)).join(" ")})`;e.state.env.set(n,m)}return{continueToNext:!0,xtraceOutput:o}}function $m(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 Cm(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 c=pi(l);if(c){let{key:u,valueParts:f,append:d}=c,h;f.length>0?(h=await se(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(h=an(e,h))):h="",a.push({type:"keyed",key:u,value:h,append:d})}else{let u=await se(e,l);a.push({type:"invalid",expandedValue:u})}}e.executionScope.consumeWork(a.length,"associative array assignment"),s||i();for(let l of a)if(l.type==="keyed")if(l.append){let c=ae(e,n,l.key)??"";H(e,n,l.key,Xs(e,c,l.value),"associative")}else H(e,n,l.key,l.value,"associative");else{let c=t.line??e.state.currentLine??1;o(`bash: line ${c}: ${n}: ${l.expandedValue}: must use subscript when assigning associative array
721
+ `)}}async function Nm(e,t,n,r,s){let i=[],o=0;for(let l of n){let c=pi(l);if(c){if(o>=e.limits.maxArrayElements)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let{key:u,valueParts:f,append:d}=c,h;f.length>0?(h=await se(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(h=an(e,h))):h="",i.push({type:"keyed",indexExpr:u,value:h,append:d}),o++}else{let u=await At(e,l);if(u.values.length>e.limits.maxArrayElements-o)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push({type:"non-keyed",values:u.values}),o+=u.values.length}}e.executionScope.consumeWork(o,"indexed array assignment"),r||s();let a=0;for(let l of i)if(l.type==="keyed"){let c;try{let u=new Q,f=re(u,l.indexExpr);c=await J(e,f.expression,!1)}catch{if(/^-?\d+$/.test(l.indexExpr))c=Number.parseInt(l.indexExpr,10);else{let u=e.state.env.get(l.indexExpr);c=u?Number.parseInt(u,10):0,Number.isNaN(c)&&(c=0)}}if(l.append){let u=ae(e,t,c)??"";H(e,t,c,Xs(e,u,l.value))}else H(e,t,c,l.value);a=c+1}else for(let c of l.values)H(e,t,a++,c)}async function Rm(e,t,n,r,s){let i=[];for(let a of n){let l=await At(e,a);for(let c of l.values){if(i.length>=e.limits.maxArrayElements)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push(c)}}let o=0;if(e.executionScope.consumeWork(i.length,"indexed array assignment"),r){let a=K(e,t);if(a.length>0)o=Math.max(...a.map(([c])=>typeof c=="number"?c:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(H(e,t,0,l),e.state.env.delete(t),o=1)}}else s();for(let a=0;a<i.length;a++)H(e,t,o+a,i[a])}async function Om(e,t,n,r,s,i,o){let a=n;if(ue(e,n)){let f=Be(e,n);if(f&&f!==n){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:F("",`bash: \`${f}': not a valid identifier
722
+ `,1)};a=f}}if(We(e,a)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=fe(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l=e.state.associativeArrays?.has(a),c;if(l)c=await Ef(e,r);else{let f=await pa(e,a,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};c=String(f.index)}let u=i?Xs(e,ae(e,a,c)||"",s):s;return t.name||H(e,a,c,u,l?"associative":"indexed"),{continueToNext:!0,xtraceOutput:""}}async function Ef(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 Q().parseWordFromString(r,!0,!1);n=await se(e,i)}else if(t.includes("$")){let s=new Q().parseWordFromString(t,!1,!1);n=await se(e,s)}else n=t;return n}async function pa(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 Q,o=re(i,r);s=await J(e,o.expression,!1)}catch(i){if(i instanceof G)throw i;if(i instanceof le){let l=`bash: line ${e.state.currentLine}: ${n}: ${i.message}
723
+ `;if(i.fatal)throw new G(1,"",l);return{index:0,error:F("",l,1)}}let o=e.state.currentLine;return{index:0,error:F("",`bash: line ${o}: ${t}[${n}]: bad array subscript
724
+ `,1)}}Number.isNaN(s)&&(s=0)}if(s<0){let i=K(e,t);if(i.length===0){let a=e.state.currentLine;return{index:0,error:F("",`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:F("",`bash: line ${a}: ${t}[${n}]: bad array subscript
726
+ `,1)}}}return{index:s}}async function Dm(e,t,n,r,s,i){let o="",a=n,l=null;if(ue(e,n)){let f=cs(e,n,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:F("",`bash: ${n}: circular name reference
726
727
  `,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(We(e,a)){if(t.name)return o+=`bash: ${a}: readonly variable
727
- `,{continueToNext:!0,xtraceOutput:o};let f=fe(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let c;if(kr(e,a))try{let f=new Z;if(s){let h=`(${e.state.env.get(a)||"0"}) + (${r})`,p=re(f,h);c=String(await J(e,p.expression))}else{let d=re(f,r);c=String(await J(e,d.expression))}}catch{c="0"}else{let f=Et(e,a)?ae(e,a,0):e.state.env.get(a);c=s?Hs(e,f||"",r):r}c=Yn(e,a,c),o+=await hf(e,a,c);let u;return l?u=await Pm(e,l):Et(e,a)&&(u="0"),t.name?u===void 0&&(i.set(a,e.state.env.get(a)),e.state.env.set(a,c)):(u===void 0?e.state.env.set(a,c):G(e,a,u,c),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 Pm(e,t){let{arrayName:n,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(n))return mf(e,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let o=new Z,a=re(o,r);i=await J(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=Q(e,n);o.length>0&&(i=Math.max(...o.map(l=>l[0]))+1+i)}return String(i)}async function wf(e,t,n,r){let s=!1,i=!1,o=!1,a=!1,l=!1,c=[];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 c.push(m);let u="",f="",d=0,h=!1,p=!1;for(let m of c){let E=!1;if(o){if(a){let k=await r(m);if(k.length>0){for(let A of k)u+=`${A}
728
- `;h=!0,E=!0}}else{let k=await n(m);k&&(u+=`${k}
729
- `,h=!0,E=!0)}E||(p=!0);continue}let S=!l&&e.state.functions.has(m);if(a&&S){if(!i)if(s)u+=`function
730
- `;else{let k=e.state.functions.get(m),A=k?yf(m,k):`${m} is a function
731
- `;u+=A}E=!0}let y=e.state.env.get(`BASH_ALIAS_${m}`);if(y!==void 0&&(a||!E)&&(i||(s?u+=`alias
732
- `:u+=`${m} is aliased to \`${y}'
733
- `),E=!0,!a)||ho.has(m)&&(a||!E)&&(i||(s?u+=`keyword
728
+ `,{continueToNext:!0,xtraceOutput:o};let f=fe(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let c;if(Pr(e,a))try{let f=new Q;if(s){let h=`(${e.state.env.get(a)||"0"}) + (${r})`,p=re(f,h);c=String(await J(e,p.expression))}else{let d=re(f,r);c=String(await J(e,d.expression))}}catch{c="0"}else{let f=wt(e,a)?ae(e,a,0):e.state.env.get(a);c=s?Xs(e,f||"",r):r}c=Jn(e,a,c),o+=await gf(e,a,c);let u;return l?u=await Im(e,l):wt(e,a)&&(u="0"),t.name?u===void 0&&(i.set(a,e.state.env.get(a)),e.state.env.set(a,c)):(u===void 0?e.state.env.set(a,c):H(e,a,u,c),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 Im(e,t){let{arrayName:n,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(n))return Ef(e,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let o=new Q,a=re(o,r);i=await J(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=K(e,n);o.length>0&&(i=Math.max(...o.map(l=>l[0]))+1+i)}return String(i)}async function Af(e,t,n,r){let s=!1,i=!1,o=!1,a=!1,l=!1,c=[];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 c.push(m);let u="",f="",d=0,h=!1,p=!1;for(let m of c){let y=!1;if(o){if(a){let A=await r(m);if(A.length>0){for(let k of A)u+=`${k}
729
+ `;h=!0,y=!0}}else{let A=await n(m);A&&(u+=`${A}
730
+ `,h=!0,y=!0)}y||(p=!0);continue}let b=!l&&e.state.functions.has(m);if(a&&b){if(!i)if(s)u+=`function
731
+ `;else{let A=e.state.functions.get(m),k=A?bf(m,A):`${m} is a function
732
+ `;u+=k}y=!0}let w=e.state.env.get(`BASH_ALIAS_${m}`);if(w!==void 0&&(a||!y)&&(i||(s?u+=`alias
733
+ `:u+=`${m} is aliased to \`${w}'
734
+ `),y=!0,!a)||mo.has(m)&&(a||!y)&&(i||(s?u+=`keyword
734
735
  `:u+=`${m} is a shell keyword
735
- `),E=!0,!a))continue;if(!a&&S&&!E){if(!i)if(s)u+=`function
736
- `;else{let k=e.state.functions.get(m),A=k?yf(m,k):`${m} is a function
737
- `;u+=A}E=!0;continue}if(!(Gn.has(m)&&(a||!E)&&(i||(s?u+=`builtin
736
+ `),y=!0,!a))continue;if(!a&&b&&!y){if(!i)if(s)u+=`function
737
+ `;else{let A=e.state.functions.get(m),k=A?bf(m,A):`${m} is a function
738
+ `;u+=k}y=!0;continue}if(!(Hn.has(m)&&(a||!y)&&(i||(s?u+=`builtin
738
739
  `:u+=`${m} is a shell builtin
739
- `),E=!0,!a))){if(a){let k=await r(m);for(let A of k)i?u+=`${A}
740
- `:s?u+=`file
741
- `:u+=`${m} is ${A}
742
- `,h=!0,E=!0}else if(!E){let k=await n(m);k&&(i?u+=`${k}
740
+ `),y=!0,!a))){if(a){let A=await r(m);for(let k of A)i?u+=`${k}
743
741
  `:s?u+=`file
744
742
  `:u+=`${m} is ${k}
745
- `,h=!0,E=!0)}if(!E&&(p=!0,!s&&!i)){let k=!0;if(m.includes("/")){let A=e.fs.resolvePath(e.state.cwd,m);await e.fs.exists(A)&&(k=!1)}k&&(f+=`bash: type: ${m}: not found
746
- `)}}}return i?d=p&&!h?1:0:d=p?1:0,L(u,f,d)}function yf(e,t){let n;return t.body.type==="Group"?n=t.body.body.map(s=>$r(s)).join("; "):n=$r(t.body),`${e} is a function
743
+ `,h=!0,y=!0}else if(!y){let A=await n(m);A&&(i?u+=`${A}
744
+ `:s?u+=`file
745
+ `:u+=`${m} is ${A}
746
+ `,h=!0,y=!0)}if(!y&&(p=!0,!s&&!i)){let A=!0;if(m.includes("/")){let k=e.fs.resolvePath(e.state.cwd,m);await e.fs.exists(k)&&(A=!1)}A&&(f+=`bash: type: ${m}: not found
747
+ `)}}}return i?d=p&&!h?1:0:d=p?1:0,F(u,f,d)}function bf(e,t){let n;return t.body.type==="Group"?n=t.body.body.map(s=>Nr(s)).join("; "):n=Nr(t.body),`${e} is a function
747
748
  ${e} ()
748
749
  {
749
750
  ${n}
750
751
  }
751
- `}function $r(e){if(Array.isArray(e))return e.map(t=>$r(t)).join("; ");if(e.type==="Statement"){let t=[];for(let n=0;n<e.pipelines.length;n++){let r=e.pipelines[n];t.push($m(r)),e.operators[n]&&t.push(e.operators[n])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,n=[];t.name&&n.push(gf(t.name));for(let r of t.args)n.push(gf(r));return n.join(" ")}return e.type==="Group"?`{ ${e.body.map(r=>$r(r)).join("; ")}; }`:"..."}function gf(e){return e.parts.map(Ef).join("")}function Ef(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(Ef).join("")}"`;default:return we(F.word([e]))}}function $m(e){let t=e.commands.map(n=>$r(n));return(e.negated?"! ":"")+t.join(" | ")}async function bf(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}"
752
+ `}function Nr(e){if(Array.isArray(e))return e.map(t=>Nr(t)).join("; ");if(e.type==="Statement"){let t=[];for(let n=0;n<e.pipelines.length;n++){let r=e.pipelines[n];t.push(_m(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=>Nr(r)).join("; ")}; }`:"..."}function Sf(e){return e.parts.map(vf).join("")}function vf(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(vf).join("")}"`;default:return we(M.word([e]))}}function _m(e){let t=e.commands.map(n=>Nr(n));return(e.negated?"! ":"")+t.join(" | ")}async function kf(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}"
752
753
  `:s+=`alias ${a}='${l}'
753
- `;else if(ho.has(a))r?s+=`${a} is a shell keyword
754
+ `;else if(mo.has(a))r?s+=`${a} is a shell keyword
754
755
  `:s+=`${a}
755
- `;else if(Gn.has(a))r?s+=`${a} is a shell builtin
756
+ `;else if(Hn.has(a))r?s+=`${a} is a shell builtin
756
757
  `:s+=`${a}
757
758
  `;else if(e.state.functions.has(a))r?s+=`${a} is a function
758
759
  `:s+=`${a}
@@ -762,52 +763,53 @@ ${e} ()
762
763
  `),o=1)}else if(e.commands.has(a)){let u=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of u){if(!d)continue;let h=`${d}/${a}`;try{let p=await e.fs.stat(h);if(!p.isDirectory&&(p.mode&73)!==0){f=h;break}}catch{}}f||(f=`/usr/bin/${a}`),r?s+=`${a} is ${f}
763
764
  `:s+=`${f}
764
765
  `}else r&&(i+=`${a}: not found
765
- `),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 Af(e,t){let n=!0,r=e.signal?new AbortController:void 0,s=new WeakMap,i=()=>{if(!n)throw new Ue("",`bash: ${t} used its context after cancellation
766
- `)},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"&&Fa(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 h=Object.getPrototypeOf(f);if(Array.isArray(f)||h===Object.prototype||h===null){let E=Array.isArray(f)?[]:Object.create(h);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 p=new Map,m=new $a(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(p.has(S))return p.get(S);let g=(...b)=>(i(),o(Reflect.apply(y,E,b)));return p.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)))),c=f=>({value:f,enumerable:!0,configurable:!0,writable:!0}),u=Object.getOwnPropertyDescriptors(e);return Object.assign(u,{fs:c(a(e.fs)),env:c(a(e.env)),limits:c(Object.freeze({...e.limits})),exportedEnv:c(e.exportedEnv?Object.freeze({...e.exportedEnv}):void 0),executionScope:c(e.executionScope?a(e.executionScope):void 0),fileDescriptors:c(e.fileDescriptors?a(e.fileDescriptors):void 0),coverage:c(e.coverage?a(e.coverage):void 0),assignShellVariable:c(l(e.assignShellVariable)),exec:c(l(e.exec)),origCommand:c(l(e.origCommand)),execWithInheritedStdin:c(l(e.execWithInheritedStdin)),fetch:c(l(e.fetch)),getRegisteredCommands:c(l(e.getRegisteredCommands)),sleep:c(l(e.sleep)),trace:c(l(e.trace)),invokeTool:c(l(e.invokeTool)),signal:c(r?.signal)}),{context:Object.defineProperties(Object.create(Object.getPrototypeOf(e)),u),revoke(){n=!1,r?.signal.aborted||r?.abort(new Ue("",`bash: ${t} context revoked
767
- `))}}}async function Cm(e,t,n,r,s,i){let o=s.remainingTimeMs()??t.limits.maxExecutionTimeMs,a=t.limits.maxExtensionCleanupTimeMs,l,c,u,d=Promise.resolve().then(e).then(p=>({kind:"result",result:p}),p=>({kind:"error",error:p})),h=new Promise(p=>{let m=()=>{n(),p({kind:"abort"})};c=m,i?.addEventListener("abort",m,{once:!0}),i?.aborted&&m(),l=nr(()=>{n(),p({kind:"deadline"})},o)});try{let p=await Promise.race([d,h]);if(p.kind==="result")return p.result;if(p.kind==="error")throw p.error;n();let m=await Promise.race([d.then(()=>!0),new Promise(S=>{u=nr(()=>S(!1),a)})]),E=p.kind==="deadline"?new Ue("",`bash: ${r} exceeded its execution deadline
766
+ `),o=1}return F(s,i,o)}async function xf(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 Pf(e,t){let n=!0,r=e.signal?new AbortController:void 0,s=new WeakMap,i=()=>{if(!n)throw new Ue("",`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"&&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 h=Object.getPrototypeOf(f);if(Array.isArray(f)||h===Object.prototype||h===null){let y=Array.isArray(f)?[]:Object.create(h);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 p=new Map,m=new Oa(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(p.has(b))return p.get(b);let E=(...S)=>(i(),o(Reflect.apply(w,y,S)));return p.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)))),c=f=>({value:f,enumerable:!0,configurable:!0,writable:!0}),u=Object.getOwnPropertyDescriptors(e);return Object.assign(u,{fs:c(a(e.fs)),env:c(a(e.env)),limits:c(Object.freeze({...e.limits})),exportedEnv:c(e.exportedEnv?Object.freeze({...e.exportedEnv}):void 0),executionScope:c(e.executionScope?a(e.executionScope):void 0),fileDescriptors:c(e.fileDescriptors?a(e.fileDescriptors):void 0),coverage:c(e.coverage?a(e.coverage):void 0),assignShellVariable:c(l(e.assignShellVariable)),exec:c(l(e.exec)),origCommand:c(l(e.origCommand)),execWithInheritedStdin:c(l(e.execWithInheritedStdin)),fetch:c(l(e.fetch)),getRegisteredCommands:c(l(e.getRegisteredCommands)),sleep:c(l(e.sleep)),trace:c(l(e.trace)),invokeTool:c(l(e.invokeTool)),signal:c(r?.signal)}),{context:Object.defineProperties(Object.create(Object.getPrototypeOf(e)),u),revoke(){n=!1,r?.signal.aborted||r?.abort(new Ue("",`bash: ${t} context revoked
768
+ `))}}}async function Tm(e,t,n,r,s,i){let o=s.remainingTimeMs()??t.limits.maxExecutionTimeMs,a=t.limits.maxExtensionCleanupTimeMs,l,c,u,d=Promise.resolve().then(e).then(p=>({kind:"result",result:p}),p=>({kind:"error",error:p})),h=new Promise(p=>{let m=()=>{n(),p({kind:"abort"})};c=m,i?.addEventListener("abort",m,{once:!0}),i?.aborted&&m(),l=rr(()=>{n(),p({kind:"deadline"})},o)});try{let p=await Promise.race([d,h]);if(p.kind==="result")return p.result;if(p.kind==="error")throw p.error;n();let m=await Promise.race([d.then(()=>!0),new Promise(b=>{u=rr(()=>b(!1),a)})]),y=p.kind==="deadline"?new Ue("",`bash: ${r} exceeded its execution deadline
768
769
  `):new Ue("",`bash: execution aborted
769
- `);throw m||s.poisonAfterAbort(E),E}finally{n(),rr(l),rr(u),c&&i?.removeEventListener("abort",c)}}async function vf(e,t,n,r,s,i,o,a,l=!1){let{ctx:c,runCommand:u}=e;if(c.coverage&&Gn.has(t)&&c.coverage.hit(`bash:builtin:${t}`),t==="export")return Zo(c,n);if(t==="unset")return la(c,n);if(t==="exit")return Ho(c,n);if(t==="local")return Yo(c,n);if(t==="set")return sa(c,n);if(t==="break")return so(c,n);if(t==="continue")return To(c,n);if(t==="return")return ta(c,n);if(t==="eval"&&c.state.options.posix)return Vs(c,n,s,l);if(t==="shift")return ia(c,n);if(t==="getopts")return zs(c,n);if(t==="compgen")return Ro(c,n);if(t==="complete")return Io(c,n);if(t==="compopt")return _o(c,n);if(t==="pushd")return await jo(c,n);if(t==="popd")return qo(c,n);if(t==="dirs")return Go(c,n);if(t==="source"||t===".")return oa(c,n);if(t==="read")return ea(c,n,s,a);if(t==="mapfile"||t==="readarray")return Jo(c,n,s);if(t==="declare"||t==="typeset")return Vo(c,n);if(t==="readonly")return zo(c,n);if(!i){let f=c.state.functions.get(t);if(f)return Bs(c,f,n,s,void 0,l)}if(t==="__just_bash_tee_restore"){if(n.length===0||n.length>c.limits.maxArrayElements)return T(`bash: invalid internal pipeline status restore
770
- `,2);let f=[];for(let p of n){if(!/^(?:0|[1-9][0-9]{0,2})$/.test(p))return T(`bash: invalid internal pipeline status restore
771
- `,2);let m=Number(p);if(!Number.isSafeInteger(m)||m>255)return T(`bash: invalid internal pipeline status restore
772
- `,2);f.push(m)}let d=f[f.length-1]??0,h=[...f].reverse().find(p=>p!==0);return{stdout:"",stderr:"",exitCode:c.state.options.pipefail&&h!==void 0?h:d,internalPipeStatusOverride:f}}if(t==="eval")return Vs(c,n,s,l);if(t==="cd")return await io(c,n);if(t===":"||t==="true")return te;if(t==="false")return be(!1);if(t==="let")return Xo(c,n);if(t==="command")return Nm(e,n,s,l);if(t==="builtin")return Rm(e,n,s,l);if(t==="shopt")return lf(c,n);if(t==="exec"){if(n.length===0)return te;let[f,...d]=n;return{...await u(f,d,[],s,!1,!1,-1,l),internalProducerOmitsShellPrefix:!0}}if(t==="wait")return te;if(t==="type")return await wf(c,n,f=>Sf(c,f),f=>Gs(c,f));if(t==="hash")return Qo(c,n);if(t==="help")return Ko(c,n);if(t==="["||t==="test"){let f=n;if(t==="["){if(n[n.length-1]!=="]")return T("[: missing `]'\n",2);f=n.slice(0,-1)}return br(c,f)}return null}async function Nm(e,t,n,r=!1){let{ctx:s,runCommand:i}=e;if(t.length===0)return te;let o=!1,a=!1,l=!1,c=t;for(;c.length>0&&c[0].startsWith("-");){let d=c[0];if(d==="--"){c=c.slice(1);break}for(let h of d.slice(1))h==="p"?o=!0:h==="V"?a=!0:h==="v"&&(l=!0);c=c.slice(1)}if(c.length===0)return te;if(l||a)return await bf(s,c,l,a);let[u,...f]=c;return i(u,f,[],n,!0,o,-1,r)}async function Rm(e,t,n,r=!1){let{runCommand:s}=e;if(t.length===0)return te;let i=t;if(i[0]==="--"&&(i=i.slice(1),i.length===0))return te;let o=i[0];if(o!=="__just_bash_tee_restore"&&!Gn.has(o))return T(`bash: builtin: ${o}: not a shell builtin
773
- `);let[,...a]=i;return s(o,a,[],n,!0,!1,-1,r)}async function kf(e,t,n,r,s){let{ctx:i,buildExportedEnv:o,executeUserScript:a}=e,c=await cf(i,t,s?"/usr/bin:/bin":void 0);if(!c)return pu(t)?T(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
774
- `,127):T(`bash: ${t}: command not found
775
- `,127);if("error"in c)return c.error==="permission_denied"?T(`bash: ${t}: Permission denied
776
- `,126):T(`bash: ${t}: No such file or directory
777
- `,127);if("script"in c)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,c.path)),await a(c.path,n,r);let{cmd:u,path:f}=c;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",h=!1,p=o();i.state.fileDescriptors??=new Map;let m={fs:i.fs,fsIdentity:zr(i.fs),cwd:i.state.cwd,env:i.state.env,assignShellVariable:async(v,k,A)=>{if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v))throw new Error(`${v}: not a valid identifier`);let P=A===void 0?v:`${v}[${A}]`,N=is(i,v,k);if(N===void 0)throw new Error(`${v}: circular name reference`);if(N===null)return;let x=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(?:\[(.*)\])?$/);if(!x)throw new Error(`${P}: not a valid identifier`);let C=x[1],D=x[2]??A;if(We(i,v)||We(i,C))throw new Error(`${C}: readonly variable`);if(D===void 0)i.state.env.set(C,k);else{let V=i.state.associativeArrays?.has(C)?"associative":"indexed";if(V==="associative"){G(i,C,D,k,V);return}let K=await fa(i,C,D);if(K.error)throw new q(K.error.exitCode,K.error.stdout,K.error.stderr);G(i,C,K.index,k,V)}},exportedEnv:p,get stdin(){return h=!0,d},limits:i.limits,executionScope:u.internalIsExtension?za(i.executionScope):i.executionScope,exec:(v,k)=>i.execFn(v,k,!1),execWithInheritedStdin:(v,k)=>i.execFn(v,{...k,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=u.internalOriginalCommand,S=()=>{};if(E){let v=Object.getOwnPropertyDescriptors(m);v.executionScope={value:i.executionScope,enumerable:!0,configurable:!0,writable:!0};let k=Object.defineProperties(Object.create(Object.getPrototypeOf(m)),v),A=Af(k,E.name),P=ua(A.context,E.name);S=A.revoke,m.origCommand=N=>{let x=()=>E.execute(N,P);return E.trusted?Ce.runTrustedAsync(x):Ce.runUntrustedAsync(x)}}let y=Af(m,t),g=ua(y.context,t),b=()=>{y.revoke(),S()};try{let v=()=>Pa(i.requireDefenseContext,"command",`${t} execution`,()=>u.execute(n,g)),k=()=>Cm(v,g,b,t,i.executionScope,i.state.signal),A=u.trusted?await Ce.runTrustedAsync(k):await k();return{...A,internalStdinConsumed:A.internalStdinConsumed??(h?r.length:0)}}catch(v){if(v instanceof $||v instanceof Ue||v instanceof zt)throw v;return T(`${t}: ${kt(Tt(v))}
778
- `)}}async function da(e,t){let n=e.state.inCondition;e.state.inCondition=!0;let r=new Qt(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 Zs=0;function Jn(e,t){return e.state.lastExitCode=t,e.state.env.set("?",String(t)),t}function Cr(e,t,n,r){if(e instanceof Qe)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:Zs};if(e instanceof Ke)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:Zs};if(e instanceof Le||e instanceof Ve||e instanceof q||e instanceof $)return e.prependOutput(t,n),{action:"rethrow",stdout:t,stderr:n,error:e};let s=Tt(e);return{action:"error",stdout:t,stderr:`${n}${s}
779
- `,exitCode:1}}function xf(e,t){return e!==void 0?{owns:!0,stdin:e}:t!==""?{owns:!0,stdin:t}:{owns:!1}}var gn=class{ctx;stdoutChunks=[];stderrChunks=[];totalBytes=0;constructor(t){this.ctx=t}append(t,n){let r=M(t)+M(n);r>this.ctx.limits.maxOutputSize-this.totalBytes&&cn(`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:M(n),stderr:M(r)}}}};async function ha(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(Fr(s)||s instanceof Ve||s instanceof q||s instanceof $||s instanceof qt)throw s.prependOutput(n.stdout,n.stderr),s;return n.appendUnaccounted("",`${Tt(s)}
780
- `),n.build(1)}return n.build(r)}async function Pf(e,t){return rt(e,t.redirections,"",()=>Om(e,t))}async function Om(e,t){let n=new gn(e);for(let r of t.clauses){let s=await da(e,r.condition);if(n.append(s.stdout,s.stderr),s.exitCode===0)return ha(e,r.body,n)}return t.elseBody?ha(e,t.elseBody,n):n.build(0)}async function $f(e,t){return rt(e,t.redirections,"",()=>Dm(e,t))}async function Dm(e,t){let n=new gn(e),r=0,s=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return T(`bash: \`${t.variable}': not a valid identifier
781
- `);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 vt(e,o);De(i,a.values,e.limits.maxArrayElements,"for-loop expansion")}}catch(o){if(o instanceof jt)return{stdout:"",stderr:o.stderr,exitCode:1};throw o}e.state.loopDepth++;try{for(let o of i){s++,s>e.limits.maxLoopIterations&&cn(`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=Cr(a,n.stdout,n.stderr,e.state.loopDepth);if(n.replace(l.stdout,l.stderr),l.exitCode!==void 0&&(r=Jn(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 Cf(e,t){return rt(e,t.redirections,"",()=>Im(e,t))}async function Im(e,t){let n=t.line;n!==void 0&&(e.state.currentLine=n);let r=new gn(e),s=0,i=0;t.init&&await J(e,t.init.expression),e.state.loopDepth++;try{for(;i++,i>e.limits.maxLoopIterations&&cn(`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 J(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=Cr(o,r.stdout,r.stderr,e.state.loopDepth);if(r.replace(a.stdout,a.stderr),a.exitCode!==void 0&&(s=Jn(e,a.exitCode)),a.action==="break")break;if(a.action==="continue"){t.update&&await J(e,t.update.expression);continue}if(a.action==="error")return r.build(a.exitCode??1);throw a.error}t.update&&await J(e,t.update.expression)}}finally{e.state.loopDepth--}return r.build(s)}async function Nf(e,t,n=""){return rt(e,t.redirections,n,r=>_m(e,t,n,r))}async function _m(e,t,n,r){let s=new gn(e),i=0,o=0,a=xf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&cn(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let c=0,u=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let p=await e.executeStatement(h);s.append(p.stdout,p.stderr),c=p.exitCode}}catch(h){if(h instanceof Qe){if(s.append(h.stdout,h.stderr),h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=s.stdout,h.stderr=s.stderr,e.state.inCondition=d,h;u=!0}else if(h instanceof Ke){if(s.append(h.stdout,h.stderr),h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=s.stdout,h.stderr=s.stderr,e.state.inCondition=d,h;f=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if((u||f)&&(i=Jn(e,Zs)),u)break;if(!f){if(c!==0)break;try{for(let h of t.body){let p=await e.executeStatement(h);s.append(p.stdout,p.stderr),i=p.exitCode}}catch(h){let p=Cr(h,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(p.stdout,p.stderr),p.exitCode!==void 0&&(i=Jn(e,p.exitCode)),p.action==="break")break;if(p.action==="continue")continue;if(p.action==="error")return s.build(p.exitCode??1);throw p.error}}}}finally{e.state.loopDepth--,a.owns&&(e.state.groupStdin=l)}return s.build(i)}async function Rf(e,t,n=""){return rt(e,t.redirections,n,r=>Tm(e,t,n,r))}async function Tm(e,t,n,r){let s=new gn(e),i=0,o=0,a=xf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&cn(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let c=await da(e,t.condition);if(s.append(c.stdout,c.stderr),c.exitCode===0)break;try{for(let u of t.body){let f=await e.executeStatement(u);s.append(f.stdout,f.stderr),i=f.exitCode}}catch(u){let f=Cr(u,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(f.stdout,f.stderr),f.exitCode!==void 0&&(i=Jn(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 Of(e,t){return rt(e,t.redirections,"",()=>Lm(e,t))}async function Lm(e,t){let n=new gn(e),r=0,s=await se(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 c of a.patterns){let u=await se(e,c);ru(c)&&(u=et(u));let f=e.state.shoptOptions.nocasematch,d=e.state.shoptOptions.extglob;if(qn(s,u,f,d,e.limits.maxCallDepth)){l=!0;break}}if(l){let c=await ha(e,a.body,n);if(n.replace(c.stdout,c.stderr),r=c.exitCode,a.terminator===";;")break;a.terminator===";&"?i=!0:i=!1}else i=!1}return n.build(r)}function pa(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 Df(e,t,n){let r=t.timed?ai():0,s="",i=te,o=0,a=[],l="",c=0,u=t.commands.length>1,f=e.state.lastArg,d=e.state.groupStdin,h=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;u&&(e.state.lastArg="",e.state.groupStdin=v?d:void 0,e.state.groupStdinSourceFd=v?h:void 0);let k=u&&(!b||!e.state.shoptOptions.lastpipe),A=k?new Map(e.state.env):null,P=k?at(e.state.arrays):null,N,x=e.executionScope.outputBytesUsed;try{e.state.commandCount=e.executionScope.chargeCommand(),N=await n(g,s)}catch(C){if(C instanceof Xe)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 Ve&&t.commands.length>1)N={stdout:C.stdout,stderr:C.stderr,exitCode:C.exitCode};else throw A&&(e.state.env=A,e.state.arrays=P??new Map),C}finally{u&&(v&&(d=e.state.groupStdin,h=e.state.groupStdinSourceFd),e.state.groupStdin=d,e.state.groupStdinSourceFd=h)}if(A&&(e.state.env=A,e.state.arrays=P??new Map),N=e.executionScope.accountResult(N,"pipeline",e.executionScope.outputBytesUsed-x),!b){let C=t.pipeStderr?.[y]??!1,D=N.internalOutputAccounting?.stdout??0,V=C?N.internalOutputAccounting?.stderr??0:0;Ua(e.executionScope,D+V,"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=Ut(N.stderr)+_t(N):(s=_t(N),l+=N.stderr,c+=N.internalOutputAccounting?.stderr??0),i={stdout:"",stderr:"",exitCode:N.exitCode})}l&&(i={...i,stderr:l+i.stderr,internalOutputAccounting:{stdout:i.internalOutputAccounting?.stdout??0,stderr:c+(i.internalOutputAccounting?.stderr??0)}});let p=t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand",m=i.internalPipeStatusOverride??a;if(p){Ee(e,"PIPESTATUS");for(let y=0;y<m.length;y++)G(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=(ai()-r)/1e3,b=Math.floor(g/60),v=g%60,k;t.timePosix?k=`real ${g.toFixed(2)}
770
+ `);throw m||s.poisonAfterAbort(y),y}finally{n(),sr(l),sr(u),c&&i?.removeEventListener("abort",c)}}async function $f(e,t,n,r,s,i,o,a,l=!1,c=!1,u=!1){let{ctx:f,runCommand:d}=e;if(f.coverage&&Hn.has(t)&&f.coverage.hit(`bash:builtin:${t}`),t==="export")return Xo(f,n);if(t==="unset")return fa(f,n);if(t==="exit")return Ko(f,n);if(t==="local")return ta(f,n);if(t==="set")return aa(f,n);if(t==="break")return oo(f,n);if(t==="continue")return Mo(f,n);if(t==="return")return sa(f,n);if(t==="eval"&&f.state.options.posix)return qs(f,n,s,l);if(t==="shift")return la(f,n);if(t==="getopts")return Gs(f,n);if(t==="compgen")return Io(f,n);if(t==="complete")return Lo(f,n);if(t==="compopt")return Fo(f,n);if(t==="pushd")return await Ho(f,n);if(t==="popd")return Zo(f,n);if(t==="dirs")return Qo(f,n);if(t==="source"||t===".")return ca(f,n);if(t==="read")return ra(f,n,s,a);if(t==="mapfile"||t==="readarray")return na(f,n,s);if(t==="declare"||t==="typeset")return jo(f,n);if(t==="readonly")return qo(f,n);if(!i){let h=f.state.functions.get(t);if(h)return Us(f,h,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
771
+ `,2);let h=[];for(let y of n){if(!/^(?:0|[1-9][0-9]{0,2})$/.test(y))return L(`bash: invalid internal pipeline status restore
772
+ `,2);let b=Number(y);if(!Number.isSafeInteger(b)||b>255)return L(`bash: invalid internal pipeline status restore
773
+ `,2);h.push(b)}let p=h[h.length-1]??0,m=[...h].reverse().find(y=>y!==0);return{stdout:"",stderr:"",exitCode:f.state.options.pipefail&&m!==void 0?m:p,internalPipeStatusOverride:h}}if(t==="eval")return qs(f,n,s,l);if(t==="cd")return await ao(f,n);if(t===":"||t==="true")return te;if(t==="false")return be(!1);if(t==="let")return ea(f,n);if(t==="command")return Lm(e,n,s,l,c,u);if(t==="builtin")return Fm(e,n,s,l,c,u);if(t==="shopt")return df(f,n);if(t==="exec"){if(n.length===0)return te;let[h,...p]=n;return{...await d(h,p,[],s,!1,!1,-1,l,c,u),internalProducerOmitsShellPrefix:!0}}if(t==="wait")return te;if(t==="type")return await Af(f,n,h=>xf(f,h),h=>Ks(f,h));if(t==="hash")return Yo(f,n);if(t==="help")return Jo(f,n);if(t==="["||t==="test"){let h=n;if(t==="["){if(n[n.length-1]!=="]")return L("[: missing `]'\n",2);h=n.slice(0,-1)}return Sr(f,h)}return null}async function Lm(e,t,n,r=!1,s=!1,i=!1){let{ctx:o,runCommand:a}=e;if(t.length===0)return te;let l=!1,c=!1,u=!1,f=t;for(;f.length>0&&f[0].startsWith("-");){let p=f[0];if(p==="--"){f=f.slice(1);break}for(let m of p.slice(1))m==="p"?l=!0:m==="V"?c=!0:m==="v"&&(u=!0);f=f.slice(1)}if(f.length===0)return te;if(u||c)return await kf(o,f,u,c);let[d,...h]=f;return a(d,h,[],n,!0,l,-1,r,s,i)}async function Fm(e,t,n,r=!1,s=!1,i=!1){let{runCommand:o}=e;if(t.length===0)return te;let a=t;if(a[0]==="--"&&(a=a.slice(1),a.length===0))return te;let l=a[0];if(l!=="__just_bash_tee_restore"&&!Hn.has(l))return L(`bash: builtin: ${l}: not a shell builtin
774
+ `);let[,...c]=a;return o(l,c,[],n,!0,!1,-1,r,s,i)}async function Cf(e,t,n,r,s,i=!1,o=!1){let{ctx:a,buildExportedEnv:l,executeUserScript:c}=e,f=await hf(a,t,s?"/usr/bin:/bin":void 0);if(!f)return wu(t)?L(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
775
+ `,127):L(`bash: ${t}: command not found
776
+ `,127);if("error"in f)return f.error==="permission_denied"?L(`bash: ${t}: Permission denied
777
+ `,126):L(`bash: ${t}: No such file or directory
778
+ `,127);if("script"in f)return t.includes("/")||(a.state.hashTable||(a.state.hashTable=new Map),a.state.hashTable.set(t,f.path)),await c(f.path,n,r);let{cmd:d,path:h}=f;t.includes("/")||(a.state.hashTable||(a.state.hashTable=new Map),a.state.hashTable.set(t,h));let p=i||o||r.length>0,m=p?r:a.state.groupStdin||"",y=!1,b=l();a.state.fileDescriptors??=new Map;let w={fs:a.fs,fsIdentity:jr(a.fs),cwd:a.state.cwd,env:a.state.env,assignShellVariable:async(x,D,$)=>{if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(x))throw new Error(`${x}: not a valid identifier`);let N=$===void 0?x:`${x}[${$}]`,O=cs(a,x,D);if(O===void 0)throw new Error(`${x}: circular name reference`);if(O===null)return;let R=O.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(?:\[(.*)\])?$/);if(!R)throw new Error(`${N}: not a valid identifier`);let W=R[1],P=R[2]??$;if(We(a,x)||We(a,W))throw new Error(`${W}: readonly variable`);if(P===void 0)a.state.env.set(W,D);else{let B=a.state.associativeArrays?.has(W)?"associative":"indexed";if(B==="associative"){H(a,W,P,D,B);return}let U=await pa(a,W,P);if(U.error)throw new G(U.error.exitCode,U.error.stdout,U.error.stderr);H(a,W,U.index,D,B)}},exportedEnv:b,get stdin(){return y=!0,m},stdinProvided:p,stdinUnavailable:o,limits:a.limits,executionScope:d.internalIsExtension?Ga(a.executionScope):a.executionScope,exec:(x,D)=>a.execFn(x,D,!1),execWithInheritedStdin:(x,D)=>a.execFn(x,{...D,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 x=Object.getOwnPropertyDescriptors(w);x.executionScope={value:a.executionScope,enumerable:!0,configurable:!0,writable:!0};let D=Object.defineProperties(Object.create(Object.getPrototypeOf(w)),x),$=Pf(D,E.name),N=ha($.context,E.name);S=$.revoke,w.origCommand=O=>{let R=()=>E.execute(O,N);return E.trusted?Ce.runTrustedAsync(R):Ce.runUntrustedAsync(R)}}let v=Pf(w,t),A=ha(v.context,t),k=()=>{v.revoke(),S()};try{let x=()=>Ra(a.requireDefenseContext,"command",`${t} execution`,()=>d.execute(n,A)),D=()=>Tm(x,A,k,t,a.executionScope,a.state.signal),$=d.trusted?await Ce.runTrustedAsync(D):await D();return{...$,internalStdinConsumed:$.internalStdinConsumed??(y?r.length:0)}}catch(x){if(x instanceof C||x instanceof Ue||x instanceof zt)throw x;return L(`${t}: ${kt(Tt(x))}
779
+ `)}}async function ma(e,t){let n=e.state.inCondition;e.state.inCondition=!0;let r=new Qt(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 Ys=0;function er(e,t){return e.state.lastExitCode=t,e.state.env.set("?",String(t)),t}function Rr(e,t,n,r){if(e instanceof Qe)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:Ys};if(e instanceof Ke)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:Ys};if(e instanceof Le||e instanceof Ve||e instanceof G||e instanceof C)return e.prependOutput(t,n),{action:"rethrow",stdout:t,stderr:n,error:e};let s=Tt(e);return{action:"error",stdout:t,stderr:`${n}${s}
780
+ `,exitCode:1}}function Nf(e,t){return e!==void 0?{owns:!0,stdin:e}:t!==""?{owns:!0,stdin:t}:{owns:!1}}var gn=class{ctx;stdoutChunks=[];stderrChunks=[];totalBytes=0;constructor(t){this.ctx=t}append(t,n){let r=V(t)+V(n);r>this.ctx.limits.maxOutputSize-this.totalBytes&&cn(`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:V(n),stderr:V(r)}}}};async function ya(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(Br(s)||s instanceof Ve||s instanceof G||s instanceof C||s instanceof qt)throw s.prependOutput(n.stdout,n.stderr),s;return n.appendUnaccounted("",`${Tt(s)}
781
+ `),n.build(1)}return n.build(r)}async function Rf(e,t){return nt(e,t.redirections,"",()=>Mm(e,t))}async function Mm(e,t){let n=new gn(e);for(let r of t.clauses){let s=await ma(e,r.condition);if(n.append(s.stdout,s.stderr),s.exitCode===0)return ya(e,r.body,n)}return t.elseBody?ya(e,t.elseBody,n):n.build(0)}async function Of(e,t){return nt(e,t.redirections,"",()=>Bm(e,t))}async function Bm(e,t){let n=new gn(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
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 At(e,o);De(i,a.values,e.limits.maxArrayElements,"for-loop expansion")}}catch(o){if(o instanceof jt)return{stdout:"",stderr:o.stderr,exitCode:1};throw o}e.state.loopDepth++;try{for(let o of i){s++,s>e.limits.maxLoopIterations&&cn(`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=Rr(a,n.stdout,n.stderr,e.state.loopDepth);if(n.replace(l.stdout,l.stderr),l.exitCode!==void 0&&(r=er(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 nt(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 gn(e),s=0,i=0;t.init&&await J(e,t.init.expression),e.state.loopDepth++;try{for(;i++,i>e.limits.maxLoopIterations&&cn(`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 J(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=Rr(o,r.stdout,r.stderr,e.state.loopDepth);if(r.replace(a.stdout,a.stderr),a.exitCode!==void 0&&(s=er(e,a.exitCode)),a.action==="break")break;if(a.action==="continue"){t.update&&await J(e,t.update.expression);continue}if(a.action==="error")return r.build(a.exitCode??1);throw a.error}t.update&&await J(e,t.update.expression)}}finally{e.state.loopDepth--}return r.build(s)}async function If(e,t,n=""){return nt(e,t.redirections,n,r=>Vm(e,t,n,r))}async function Vm(e,t,n,r){let s=new gn(e),i=0,o=0,a=Nf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&cn(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let c=0,u=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let p=await e.executeStatement(h);s.append(p.stdout,p.stderr),c=p.exitCode}}catch(h){if(h instanceof Qe){if(s.append(h.stdout,h.stderr),h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=s.stdout,h.stderr=s.stderr,e.state.inCondition=d,h;u=!0}else if(h instanceof Ke){if(s.append(h.stdout,h.stderr),h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=s.stdout,h.stderr=s.stderr,e.state.inCondition=d,h;f=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if((u||f)&&(i=er(e,Ys)),u)break;if(!f){if(c!==0)break;try{for(let h of t.body){let p=await e.executeStatement(h);s.append(p.stdout,p.stderr),i=p.exitCode}}catch(h){let p=Rr(h,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(p.stdout,p.stderr),p.exitCode!==void 0&&(i=er(e,p.exitCode)),p.action==="break")break;if(p.action==="continue")continue;if(p.action==="error")return s.build(p.exitCode??1);throw p.error}}}}finally{e.state.loopDepth--,a.owns&&(e.state.groupStdin=l)}return s.build(i)}async function _f(e,t,n=""){return nt(e,t.redirections,n,r=>zm(e,t,n,r))}async function zm(e,t,n,r){let s=new gn(e),i=0,o=0,a=Nf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&cn(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let c=await ma(e,t.condition);if(s.append(c.stdout,c.stderr),c.exitCode===0)break;try{for(let u of t.body){let f=await e.executeStatement(u);s.append(f.stdout,f.stderr),i=f.exitCode}}catch(u){let f=Rr(u,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(f.stdout,f.stderr),f.exitCode!==void 0&&(i=er(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 Tf(e,t){return nt(e,t.redirections,"",()=>Um(e,t))}async function Um(e,t){let n=new gn(e),r=0,s=await se(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 c of a.patterns){let u=await se(e,c);au(c)&&(u=et(u));let f=e.state.shoptOptions.nocasematch,d=e.state.shoptOptions.extglob;if(Gn(s,u,f,d,e.limits.maxCallDepth)){l=!0;break}}if(l){let c=await ya(e,a.body,n);if(n.replace(c.stdout,c.stderr),r=c.exitCode,a.terminator===";;")break;a.terminator===";&"?i=!0:i=!1}else i=!1}return n.build(r)}function ga(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 Lf(e,t,n){let r=t.timed?fi():0,s="",i=te,o=0,a=[],l="",c=0,u=t.commands.length>1,f=e.state.lastArg,d=e.state.groupStdin,h=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;u&&(e.state.lastArg="",e.state.groupStdin=v?d:void 0,e.state.groupStdinSourceFd=v?h:void 0);let A=u&&(!S||!e.state.shoptOptions.lastpipe),k=A?new Map(e.state.env):null,x=A?ot(e.state.arrays):null,D,$=e.executionScope.outputBytesUsed;try{e.state.commandCount=e.executionScope.chargeCommand(),D=await n(E,s,!v)}catch(N){if(N instanceof Xe)D={stdout:N.stdout,stderr:N.stderr,exitCode:1};else if(N instanceof G&&t.commands.length>1)D={stdout:N.stdout,stderr:N.stderr,exitCode:N.exitCode};else if(N instanceof Ve&&t.commands.length>1)D={stdout:N.stdout,stderr:N.stderr,exitCode:N.exitCode};else throw k&&(e.state.env=k,e.state.arrays=x??new Map),N}finally{u&&(v&&(d=e.state.groupStdin,h=e.state.groupStdinSourceFd),e.state.groupStdin=d,e.state.groupStdinSourceFd=h)}if(k&&(e.state.env=k,e.state.arrays=x??new Map),D=e.executionScope.accountResult(D,"pipeline",e.executionScope.outputBytesUsed-$),!S){let N=t.pipeStderr?.[w]??!1,O=D.internalOutputAccounting?.stdout??0,R=N?D.internalOutputAccounting?.stderr??0:0;Ha(e.executionScope,O+R,"pipeline"),D={...D,internalOutputAccounting:{stdout:0,stderr:N?0:D.internalOutputAccounting?.stderr??0}}}a.push(D.exitCode),D.exitCode!==0&&(o=D.exitCode),S?i=D:(t.pipeStderr?.[w]??!1?s=Ut(D.stderr)+_t(D):(s=_t(D),l+=D.stderr,c+=D.internalOutputAccounting?.stderr??0),i={stdout:"",stderr:"",exitCode:D.exitCode})}l&&(i={...i,stderr:l+i.stderr,internalOutputAccounting:{stdout:i.internalOutputAccounting?.stdout??0,stderr:c+(i.internalOutputAccounting?.stderr??0)}});let p=t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand",m=i.internalPipeStatusOverride??a;if(p){Ee(e,"PIPESTATUS");for(let w=0;w<m.length;w++)H(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=(fi()-r)/1e3,S=Math.floor(E/60),v=E%60,A;t.timePosix?A=`real ${E.toFixed(2)}
782
783
  user 0.00
783
784
  sys 0.00
784
- `:k=`
785
- real ${`${b}m${v.toFixed(3)}s`}
785
+ `:A=`
786
+ real ${`${S}m${v.toFixed(3)}s`}
786
787
  user 0m0.000s
787
788
  sys 0m0.000s
788
- `,i={...i,stderr:i.stderr+k}}u&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=f),i=e.executionScope.accountResult(i,"pipeline");let{internalPipeStatusOverride:E,...S}=i;return S}function ma(e){return e?{...e,options:e.options?[...e.options]:void 0,actions:e.actions?[...e.actions]:void 0}:void 0}function Fm(e){return e?new Map(Array.from(e,([t,n])=>[t,ma(n)])):void 0}function Mm(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 Bm(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 ya(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=at(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=Mm(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=Bm(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=Fm(e.completionSpecs),e.defaultCompletionSpec=ma(e.defaultCompletionSpec),e.emptyCompletionSpec=ma(e.emptyCompletionSpec);let n=!1;return()=>{n||(n=!0,Object.assign(e,t))}}async function If(e,t,n,r,s=!1){let i=e.state.loopDepth,o=new Map;for(let l of e.state.fileDescriptors?.keys()??[]){let c=nt(e,l);c&&o.set(l,c)}let a=ya(e.state);e.state.parentHasLoopContext=i>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++;try{return await rt(e,t.redirections,n,l=>Vm(e,t,l.stdin??n,r,s||l.stdin!==void 0))}finally{let l=new Map;for(let[c,u]of o){let f=nt(e,c),d=u.kind==="input"&&f?.kind==="input"?u.content.length-f.content.length:u.kind==="readwrite"&&f?.kind==="readwrite"&&u.path===f.path?f.position-u.position:0;if(d<=0)continue;let h=Math.min(...dn(e,c));l.set(h,Math.max(l.get(h)??0,d))}a();for(let[c,u]of l)hn(e,c,u)}}async function Vm(e,t,n,r,s){(s||n)&&(e.state.groupStdin=n);let i=new Qt(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 $)throw i.prependTo(a),a;return a instanceof qt||a instanceof Qe||a instanceof Ke?(i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(0)):a instanceof q||a instanceof Le||a instanceof Ve?(i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(a.exitCode)):(i.append("stderr",`${Tt(a)}
789
- `),i.build(1))}return i.build(o)}async function _f(e,t,n,r,s=!1){return rt(e,t.redirections,n,i=>zm(e,t,n,r,s,i))}async function zm(e,t,n,r,s,i){let o=new Qt(e.executionScope,"group"),a=0,l=i.stdin??n,c=s||n!==""||i.stdin!==void 0,u=e.state.groupStdin;c&&(e.state.groupStdin=l);let f=()=>{(c||u!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=u)};try{for(let d of t.body){let h=await r(d);o.appendResult(h),a=h.exitCode}}catch(d){if(f(),d instanceof $)throw o.prependTo(d),d;if(Fr(d)||d instanceof Ve||d instanceof q)throw d.prependOutput(o.stdout,o.stderr),d;return o.append("stderr",`${Tt(d)}
790
- `),o.build(1)}return f(),o.build(a)}async function Tf(e,t,n,r,s){let i;try{i=await e.fs.readFile(t)}catch{return T(`bash: ${t}: No such file or directory
789
+ `,i={...i,stderr:i.stderr+A}}u&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=f),i=e.executionScope.accountResult(i,"pipeline");let{internalPipeStatusOverride:y,...b}=i;return b}function wa(e){return e?{...e,options:e.options?[...e.options]:void 0,actions:e.actions?[...e.actions]:void 0}:void 0}function jm(e){return e?new Map(Array.from(e,([t,n])=>[t,wa(n)])):void 0}function qm(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 Hm(e){return e?new Map(Array.from(e,([t,n])=>[t,n.map(r=>({...r}))])):void 0}function Ea(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=ot(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=qm(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=Hm(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=jm(e.completionSpecs),e.defaultCompletionSpec=wa(e.defaultCompletionSpec),e.emptyCompletionSpec=wa(e.emptyCompletionSpec);let n=!1;return()=>{n||(n=!0,Object.assign(e,t))}}async function Ff(e,t,n,r,s=!1){let i=e.state.loopDepth,o=new Map;for(let l of e.state.fileDescriptors?.keys()??[]){let c=lt(e,l);c&&o.set(l,c)}let a=Ea(e.state);e.state.parentHasLoopContext=i>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++;try{return await nt(e,t.redirections,n,l=>Zm(e,t,l.stdin??n,r,s||l.stdin!==void 0))}finally{let l=new Map;for(let[c,u]of o){let f=lt(e,c),d=u.kind==="input"&&f?.kind==="input"?u.content.length-f.content.length:u.kind==="readwrite"&&f?.kind==="readwrite"&&u.path===f.path?f.position-u.position:0;if(d<=0)continue;let h=Math.min(...dn(e,c));l.set(h,Math.max(l.get(h)??0,d))}a();for(let[c,u]of l)hn(e,c,u)}}async function Zm(e,t,n,r,s){(s||n)&&(e.state.groupStdin=n);let i=new Qt(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 qt||a instanceof Qe||a instanceof Ke?(i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(0)):a instanceof G||a instanceof Le||a instanceof Ve?(i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(a.exitCode)):(i.append("stderr",`${Tt(a)}
790
+ `),i.build(1))}return i.build(o)}async function Mf(e,t,n,r,s=!1){return nt(e,t.redirections,n,i=>Qm(e,t,n,r,s,i))}async function Qm(e,t,n,r,s,i){let o=new Qt(e.executionScope,"group"),a=0,l=i.stdin??n,c=s||n!==""||i.stdin!==void 0,u=e.state.groupStdin;c&&(e.state.groupStdin=l);let f=()=>{(c||u!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=u)};try{for(let d of t.body){let h=await r(d);o.appendResult(h),a=h.exitCode}}catch(d){if(f(),d instanceof C)throw o.prependTo(d),d;if(Br(d)||d instanceof Ve||d instanceof G)throw d.prependOutput(o.stdout,o.stderr),d;return o.append("stderr",`${Tt(d)}
791
+ `),o.build(1)}return f(),o.build(a)}async function Bf(e,t,n,r,s){let i;try{i=await e.fs.readFile(t)}catch{return L(`bash: ${t}: No such file or directory
791
792
  `,127)}if(i.startsWith("#!")){let l=i.indexOf(`
792
- `);l!==-1&&(i=i.slice(l+1))}let o=e.state.loopDepth,a=ya(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 c=new Z().parse(i),u=await s(c);return a(),u}catch(l){if(a(),l instanceof q)return L(l.stdout,l.stderr,l.exitCode);if(l instanceof $)throw l;if(l.name==="ParseException")return T(`bash: ${t}: ${l.message}
793
- `);throw l}}function Um(e){throw new TypeError(`Unsupported command node: ${JSON.stringify(e)}`)}var Nr=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||Ce.isInSandboxedContext())return;let n=`interpreter ${t} attempted outside defense context`;throw new zt(n,{timestamp:Date.now(),type:"missing_defense_context",message:n,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:Ce.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 Qt(this.ctx.executionScope,"script");for(let s of t.statements)try{let i=await this.executeStatement(s);r.appendResult(i,ii(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 st)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:Zt(this.ctx.state.env)};if(i instanceof $)throw r.prependTo(i),i;if(i instanceof Ve)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:Zt(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:Zt(this.ctx.state.env)};if(i instanceof Xe)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:Zt(this.ctx.state.env)};if(i instanceof le){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 Lr){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 Qe||i instanceof Ke){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 Le&&i.prependOutput(r.stdout,r.stderr),i}return{...r.build(n),env:Zt(this.ctx.state.env)}}async executeUserScript(t,n,r=""){return Tf(this.ctx,t,n,r,s=>this.executeScript(s))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Ue;if(t.deferredError)throw new Pe(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return te;this.ctx.state.errexitSafe=!1;let n=new Qt(this.ctx.executionScope,"statement");this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&n.append("stderr",`${t.sourceText}
794
- `);let r=0,s=-1,i=!1;try{for(let l=0;l<t.pipelines.length;l++){let c=t.pipelines[l],u=l>0?t.operators[l-1]:null;if(u==="&&"&&r!==0||u==="||"&&r===0)continue;let f=await this.executePipeline(c);n.appendResult(f,ii(f)),r=f.exitCode,s=l,i=c.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 Ve(r);throw l.prependOutput(n.stdout,n.stderr),l}return n.build(r)}async executePipeline(t){return Df(this.ctx,t,(n,r)=>this.executeCommand(n,r))}async executeCommand(t,n,r=!1){let s=tu(this.ctx),i;try{i=await this.executeCommandInner(t,n,r)}catch(a){throw await eo(this.ctx,s).catch(()=>{}),a}let o=await eo(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 Pf(this.ctx,t);case"For":return $f(this.ctx,t);case"CStyleFor":return Cf(this.ctx,t);case"While":return Nf(this.ctx,t,n);case"Until":return Rf(this.ctx,t,n);case"Case":return Of(this.ctx,t);case"Subshell":return this.executeSubshell(t,n,r);case"Group":return this.executeGroup(t,n,r);case"FunctionDef":return Lu(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return Um(t)}}async executeSimpleCommand(t,n){let r;try{return await this.executeSimpleCommandInner(t,n,s=>{r=s})}catch(s){if(r?.finish(),s instanceof jt)return T(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 x=t,C=0;for(;;){let D=this.expandAlias(x);if(D===x)break;if(C>=this.ctx.limits.maxCallDepth)throw new $(`alias expansion depth limit exceeded (${this.ctx.limits.maxCallDepth})`,"recursion");C++,x=D}this.aliasExpansionStack.clear(),x!==t&&(t=x)}this.ctx.state.expansionStderr="",this.ctx.state.lastSubstitutionExitCode=null;let s=await pf(this.ctx,t);if(s.error)return s.error;let i=s.tempAssignments,o=s.xtraceOutput,a=()=>{for(let[x,C]of i)C===void 0?this.ctx.state.env.delete(x):this.ctx.state.env.set(x,C)};if(!t.name){if(t.redirections.length>0){let C=Qn(this.ctx,t.redirections,_u);r(C);let D=await C.prepare(n);if(D.error){if(a(),!D.errorCause)return C.finish(),D.error;try{return Kn(D)}finally{C.finish()}}let V=L("",o,cs(this.ctx.state,t.redirections)),K=await mn(this.ctx,V,t.redirections,D.targets,D.dupSources,D.standardRoutes);return C.finish(),K}this.ctx.state.lastArg="";let x=(this.ctx.state.expansionStderr||"")+o;return this.ctx.state.expansionStderr="",L("",x,cs(this.ctx.state,[]))}let l=t.name&&pa(t.name,["local","declare","typeset","export","readonly"]),c=Array.from(i.keys());if(c.length>0&&!l){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let x of c)this.ctx.state.tempExportedVars.add(x)}let u=await se(this.ctx,t.name),f=[],d=[],h=(x,C)=>{if(f.length>=this.ctx.limits.maxArrayElements)throw new $(`expanded argument element limit exceeded (${this.ctx.limits.maxArrayElements})`,"array_elements");f.push(x),d.push(C)};if(pa(t.name,["local","declare","typeset","export","readonly"])&&(u==="local"||u==="declare"||u==="typeset"||u==="export"||u==="readonly"))for(let x of t.args){let C=await du(this.ctx,x);if(C)h(C,!0);else{let D=await hu(this.ctx,x);if(D!==null)h(D,!0);else{let V=await vt(this.ctx,x);for(let K of V.values)h(K,V.quoted)}}}else for(let x of t.args){let C=await vt(this.ctx,x);for(let D of C.values)h(D,C.quoted)}let m=t.name.parts.every(x=>x.type==="CommandSubstitution"||x.type==="ParameterExpansion"||x.type==="ArithmeticExpansion");!u&&m&&f.length>0&&(u=f.shift(),d.shift());let E=Qn(this.ctx,t.redirections,u==="exec"?Tu:Sr);r(E);let S=await E.prepare(n);if(S.error)return a(),S.errorCause?Kn(S):(E.finish(),S.error);let y=S.stdinSourceFd,g=S.stdin!==void 0;if(S.stdin!==void 0&&(n=S.stdin),!u)return m?(E.finish(),L("","",cs(this.ctx.state,t.redirections))):(E.finish(),T(`bash: : command not found
795
- `,127));if(u==="exec"&&(f.length===0||f[0]==="--")){for(let[x,C]of i)C===void 0?this.ctx.state.env.delete(x):this.ctx.state.env.set(x,C);if(this.ctx.state.tempExportedVars)for(let x of i.keys())this.ctx.state.tempExportedVars.delete(x);return E.finish(),te}if(this.ctx.state.extraArgs){let x=this.ctx.state.extraArgs;this.ctx.state.extraArgs=void 0;for(let C of x)h(C,!0)}let b=await df(this.ctx,u,f);i.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(i)));let v,k=null;try{v=await this.runCommand(u,f,d,n,!1,!1,y,g)}catch(x){if(x instanceof Qe||x instanceof Ke)k=x,v=te;else throw x}y>=0&&u!=="read"&&hn(this.ctx,y,v.internalStdinConsumed??0);let A=o+b;if(A&&(v={...v,stderr:A+v.stderr}),v=await mn(this.ctx,v,t.redirections,S.targets,S.dupSources,S.standardRoutes,v.internalProducerCommand??u,v.internalProducerOmitsShellPrefix),E.finish(),k)throw k;if(f.length>0){let x=f[f.length-1];if((u==="declare"||u==="local"||u==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(x)){let C=x.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);C&&(x=C[1])}this.ctx.state.lastArg=x}else this.ctx.state.lastArg=u;let P=Cu(u)&&u!=="unset"&&u!=="eval";if(!this.ctx.state.options.posix||!P)for(let[x,C]of i)this.ctx.state.fullyUnsetLocals?.has(x)||(C===void 0?this.ctx.state.env.delete(x):this.ctx.state.env.set(x,C));if(this.ctx.state.tempExportedVars)for(let x of i.keys())this.ctx.state.tempExportedVars.delete(x);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 c={ctx:this.ctx,runCommand:(d,h,p,m,E,S,y,g)=>this.runCommand(d,h,p,m,E,S,y,g),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(d,h,p)=>this.executeUserScript(d,h,p)},u=await vf(c,t,n,r,s,i,o,a,l);return u!==null?u.internalProducerCommand===void 0?{...u,internalProducerCommand:t}:u:{...await kf(c,t,n,s,o),internalProducerCommand:t}}aliasExpansionStack=new Set;expandAlias(t){return Bl({env:this.ctx.state.env,limits:this.ctx.limits},t,this.aliasExpansionStack)}async findCommandInPath(t){return Gs(this.ctx,t)}async executeSubshell(t,n="",r=!1){return If(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeGroup(t,n="",r=!1){return _f(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeArithmeticCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),rt(this.ctx,t.redirections,"",async()=>{try{let n=await J(this.ctx,t.expression.expression),r=be(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){return T(`bash: arithmetic expression: ${n.message}
796
- `)}})}async executeConditionalCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),rt(this.ctx,t.redirections,"",async()=>{try{let n=await un(this.ctx,t.expression),r=be(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 le?1:2;return T(`bash: conditional expression: ${n.message}
797
- `,r)}})}};function ga(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function jm(e){let t=ga(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var qm=3;function Lf(e){let t=e;for(let n=0;n<qm;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 Gm(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function wa(e,t){let n=ga(e);if(!n)return!1;let r=jm(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&Lf(n.pathname)?!1:Gm(n.pathname,r.pathPrefix)}function Ff(e){return typeof e=="string"?e:e.url}function Mf(e,t){return!t||t.length===0?!1:t.some(n=>wa(e,Ff(n)))}function Ea(e){let t=Hm(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=Bf(t);if(n)return Qs(n);let r=Qm(t);return r?Km(r):!1}function Hm(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function Zm(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 Bf(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>Zm(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,c]=r;return l>255||c>16777215?null:[l,c>>>16&255,c>>>8&255,c&255]}if(t.length===3){let[l,c,u]=r;return l>255||c>255||u>65535?null:[l,c,u>>>8&255,u&255]}let[s,i,o,a]=r;return s>255||i>255||o>255||a>255?null:[s,i,o,a]}function Qm(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=Bf(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,c=o.map(l),u=a.map(l);if(c.some(m=>m===null)||u.some(m=>m===null))return null;let f=n?2:0,d=c.length+u.length+f,h=0;if(r===1){if(h=8-d,h<0)return null}else if(d!==8)return null;let p=[...c,...new Array(h).fill(0),...u];return n&&(p.push(n[0]<<8|n[1]),p.push(n[2]<<8|n[3])),p.length===8?p:null}function Qs(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 Km(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 Qs(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 Qs(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 Qs(s)}return!1}function Wf(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=Ff(n);if(!ga(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!==""&&Lf(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 ft=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},Rn=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},Vt=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Ks=class extends Error{constructor(t,n){super(`HTTP method '${t}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}},On=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var Xm=20,Ym=3e4,Jm=10485760,ey=["GET","HEAD"],Rr;typeof __BROWSER__<"u"&&__BROWSER__?Rr=null:(Rr=import("guarded-fetch"),Rr.catch(()=>{}));var ty=new Set(["GET","HEAD","OPTIONS"]),ny=new Set([301,302,303,307,308]);function Or(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function ry(e){if(e?.aborted)throw Or(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=Wf(t);if(b.length>0)throw new Error(`Invalid network allow-list:
798
- ${b.join(`
799
- `)}`)}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 k of r)if(wa(b,k.url)&&k.transform){v||(v=new Headers);for(let A of k.transform)for(let[P,N]of Object.entries(A.headers))v.set(P,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??Xm,o=e.timeoutMs??Ym,a=e.maxResponseSize??Jm,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??ey,c=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),u=[];for(let b of t){let v=typeof b=="string"?b:b.url;try{u.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?c?{allowedHosts:void 0,skipSsrfCheckForAllowedHosts:void 0}:{allowedHosts:[f(b)],skipSsrfCheckForAllowedHosts:!0}:{allowedHosts:u,skipSsrfCheckForAllowedHosts:!c}}function h(b){try{return Ea(new URL(b).hostname)}catch{return!1}}async function p(b,v){let k={method:v.method,headers:v.headers,signal:v.signal,redirect:"manual"};return v.body!==void 0&&(k.body=v.body),await(n??globalThis.fetch)(b,k)}function m(b){if(!e.dangerouslyAllowFullInternetAccess&&!Mf(b,t))throw new ft(b)}function E(b){if(!c)return;let v;try{v=new URL(b)}catch{throw new ft(b,"invalid URL")}if(Ea(v.hostname))throw new ft(b,"private/loopback IP address blocked")}function S(b){if(e.dangerouslyAllowFullInternetAccess)return;let v=b.toUpperCase();if(!l.includes(v))throw new Ks(v,l)}function y(b,v,k,A){if(!k.isGuardedFetchError(b))return b;let P=b,{onRedirectHop:N,subReason:x}=A;switch(P.code){case"host_not_allowed":case"protocol_not_allowed":return N?new Vt(v):new ft(v);case"hostname_unsafe":return N?new Vt(v):new ft(v,x==="dns_resolution_failed"?"DNS resolution failed for private IP check":"hostname resolves to private/loopback IP address");case"redirect_to_unsafe_host":return new Vt(v);case"too_many_redirects":return new Rn(i);case"response_too_large":return new On(a);default:return b}}async function g(b,v={}){let k=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 P=v.maxRedirects??i,N=Math.min(i,P),x=v.timeoutMs!==void 0?Math.min(v.timeoutMs,o):o,C=new AbortController,D=_r(()=>C.abort(new DOMException("The operation was aborted","AbortError")),x),V=Mr(v.signal,C.signal);try{m(b),E(b),S(k);let K=Rr?await Rr:null,R=b,U=0,j=[],I=k,_=v.body,B=v.headers,ne=!1;for(;;){ry(V.signal);let Y=await Ce.runTrustedAsync(async()=>{let Te=B;if(ne&&Te){let It=Te instanceof Headers?new Headers(Te):new Headers(Te);It.delete("authorization"),It.delete("cookie"),Te=It}let ht=s(R),Dt=iy(Te,ht),pt={method:I,headers:Dt,signal:V.signal,followRedirects:!1,timeoutMs:x,sanitizeHeaders:!1};if(_&&!ty.has(I)&&(pt.body=_),Object.assign(pt,d(R)),!K||h(R)){if(c)throw new ft(R,"DNS pinning unavailable for private IP enforcement");return await p(R,pt)}c?n&&(pt.fetch=n):(pt.fetch=n??globalThis.fetch,pt.dispatcher=null);let mt;pt.onUrlBlocked=It=>{mt=It.subReason};try{return await K.guardedFetch(R,pt)}catch(It){throw y(It,R,K,{onRedirectHop:U>0,subReason:mt})}});if(ny.has(Y.status)&&A){let Te=Y.headers.get("location");if(!Te)return await Vf(Y,R,a,V.signal,j);j.push({status:Y.status,statusText:Y.statusText,headers:zf(Y.headers)});let ht=new URL(Te,R).href;await ba(sy(Y),V.signal);try{m(ht),E(ht)}catch(mt){throw V.signal?.aborted?Or(V.signal):mt instanceof ft?new Vt(ht):mt}let Dt=Y.status;if(((Dt===301||Dt===302)&&I==="POST"||Dt===303&&I!=="GET"&&I!=="HEAD")&&(I="GET",_=void 0,S(I)),new URL(ht).origin!==new URL(R).origin&&(ne=!0),U++,U>N)throw new Rn(N);R=ht;continue}return await Vf(Y,R,a,V.signal,j)}}finally{Tr(D),V.cleanup()}}return g}async function ba(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),Or(t);let n,r=new Promise((s,i)=>{n=()=>i(Or(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function sy(e){e.body&&!e.body.locked&&await e.body.cancel()}function iy(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 zf(e){let t=Object.create(null);return e.forEach((n,r)=>{t[r.toLowerCase()]=n}),t}async function Vf(e,t,n,r,s){let i=zf(e.headers);if(n>0){let l=e.headers.get("content-length");if(l){let c=parseInt(l,10);if(!Number.isNaN(c)&&c>n)throw new On(n)}}let o;if(n>0&&e.body){let l=e.body.getReader(),c=[],u=0;try{for(;;){let{done:d,value:h}=await ba(l.read(),r);if(d)break;if(h){if(u+=h.byteLength,u>n)throw await l.cancel(),new On(n);c.push(h)}}}catch(d){throw r?.aborted&&await l.cancel(Or(r)).catch(()=>{}),d}o=new Uint8Array(u);let f=0;for(let d of c)o.set(d,f),f+=d.byteLength}else{let l=await ba(e.arrayBuffer(),r);if(n>0&&l.byteLength>n)throw new On(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 Dr(e,t){if(e.length>t||M(e)>t)throw new $(`script input size limit exceeded (${t} bytes)`,"string_length")}var Ir=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;invokeToolFn;transformPlugins=[];state;constructor(t={}){this.limits=Ur({...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 gt(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",`
800
- `],["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",fi(this.state.options)),this.state.env.set("BASHOPTS",di(this.state.shoptOptions)),Ga(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&(n instanceof gt||n instanceof Kt))try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of Oa(t.commands))this.registerBundledCommand(o);if(t.fetch||t.network)for(let o of Da())this.registerBundledCommand(o);if(t.python)for(let o of Ia())this.registerBundledCommand(o);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let o of _a())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(Ba(o)){let a=Wa(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,c)=>t.execute(l,c)};this.commands.set(t.name,o);let a=this.fs;if(typeof a.writeFileSync=="function"){let l=`#!/bin/bash
793
+ `);l!==-1&&(i=i.slice(l+1))}let o=e.state.loopDepth,a=Ea(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 c=new Q().parse(i),u=await s(c);return a(),u}catch(l){if(a(),l instanceof G)return F(l.stdout,l.stderr,l.exitCode);if(l instanceof C)throw l;if(l.name==="ParseException")return L(`bash: ${t}: ${l.message}
794
+ `);throw l}}function Km(e){throw new TypeError(`Unsupported command node: ${JSON.stringify(e)}`)}var Or=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||Ce.isInSandboxedContext())return;let n=`interpreter ${t} attempted outside defense context`;throw new zt(n,{timestamp:Date.now(),type:"missing_defense_context",message:n,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:Ce.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 Qt(this.ctx.executionScope,"script");for(let s of t.statements)try{let i=await this.executeStatement(s);r.appendResult(i,ci(i)),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(i){if(i instanceof G)throw i.prependOutput(r.stdout,r.stderr),i;if(i instanceof rt)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:Zt(this.ctx.state.env)};if(i instanceof C)throw r.prependTo(i),i;if(i instanceof Ve)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:Zt(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:Zt(this.ctx.state.env)};if(i instanceof Xe)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:Zt(this.ctx.state.env)};if(i instanceof le){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 Mr){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 Qe||i instanceof Ke){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 Le&&i.prependOutput(r.stdout,r.stderr),i}return{...r.build(n),env:Zt(this.ctx.state.env)}}async executeUserScript(t,n,r=""){return Bf(this.ctx,t,n,r,s=>this.executeScript(s))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Ue;if(t.deferredError)throw new xe(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return te;this.ctx.state.errexitSafe=!1;let n=new Qt(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 c=t.pipelines[l],u=l>0?t.operators[l-1]:null;if(u==="&&"&&r!==0||u==="||"&&r===0)continue;let f=await this.executePipeline(c);n.appendResult(f,ci(f)),r=f.exitCode,s=l,i=c.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 Ve(r);throw l.prependOutput(n.stdout,n.stderr),l}return n.build(r)}async executePipeline(t){return Lf(this.ctx,t,(n,r,s)=>this.executeCommand(n,r,s))}async executeCommand(t,n,r=!1){let s=iu(this.ctx),i;try{i=await this.executeCommandInner(t,n,r)}catch(a){throw await no(this.ctx,s).catch(()=>{}),a}let o=await no(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 Rf(this.ctx,t);case"For":return Of(this.ctx,t);case"CStyleFor":return Df(this.ctx,t);case"While":return If(this.ctx,t,n);case"Until":return _f(this.ctx,t,n);case"Case":return Tf(this.ctx,t);case"Subshell":return this.executeSubshell(t,n,r);case"Group":return this.executeGroup(t,n,r);case"FunctionDef":return Wu(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return Km(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 jt)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 O=t,R=0;for(;;){let W=this.expandAlias(O);if(W===O)break;if(R>=this.ctx.limits.maxCallDepth)throw new C(`alias expansion depth limit exceeded (${this.ctx.limits.maxCallDepth})`,"recursion");R++,O=W}this.aliasExpansionStack.clear(),O!==t&&(t=O)}this.ctx.state.expansionStderr="",this.ctx.state.lastSubstitutionExitCode=null;let i=await wf(this.ctx,t);if(i.error)return i.error;let o=i.tempAssignments,a=i.xtraceOutput,l=()=>{for(let[O,R]of o)R===void 0?this.ctx.state.env.delete(O):this.ctx.state.env.set(O,R)};if(!t.name){if(t.redirections.length>0){let R=Kn(this.ctx,t.redirections,Mu);s(R);let W=await R.prepare(n);if(W.error){if(l(),!W.errorCause)return R.finish(),W.error;try{return Xn(W)}finally{R.finish()}}let P=F("",a,hs(this.ctx.state,t.redirections)),B=await mn(this.ctx,P,t.redirections.length>0,W.outputRoutes);return R.finish(),B}this.ctx.state.lastArg="";let O=(this.ctx.state.expansionStderr||"")+a;return this.ctx.state.expansionStderr="",F("",O,hs(this.ctx.state,[]))}let c=t.name&&ga(t.name,["local","declare","typeset","export","readonly"]),u=Array.from(o.keys());if(u.length>0&&!c){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let O of u)this.ctx.state.tempExportedVars.add(O)}let f=await se(this.ctx,t.name),d=[],h=[],p=(O,R)=>{if(d.length>=this.ctx.limits.maxArrayElements)throw new C(`expanded argument element limit exceeded (${this.ctx.limits.maxArrayElements})`,"array_elements");d.push(O),h.push(R)};if(ga(t.name,["local","declare","typeset","export","readonly"])&&(f==="local"||f==="declare"||f==="typeset"||f==="export"||f==="readonly"))for(let O of t.args){let R=await yu(this.ctx,O);if(R)p(R,!0);else{let W=await gu(this.ctx,O);if(W!==null)p(W,!0);else{let P=await At(this.ctx,O);for(let B of P.values)p(B,P.quoted)}}}else for(let O of t.args){let R=await At(this.ctx,O);for(let W of R.values)p(W,R.quoted)}let y=t.name.parts.every(O=>O.type==="CommandSubstitution"||O.type==="ParameterExpansion"||O.type==="ArithmeticExpansion");!f&&y&&d.length>0&&(f=d.shift(),h.shift());let b=Kn(this.ctx,t.redirections,f==="exec"?Bu:vr);s(b);let w=await b.prepare(n);if(w.error)return l(),w.errorCause?Xn(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(),F("","",hs(this.ctx.state,t.redirections))):(b.finish(),L(`bash: : command not found
796
+ `,127));if(f==="exec"&&(d.length===0||d[0]==="--")){for(let[O,R]of o)R===void 0?this.ctx.state.env.delete(O):this.ctx.state.env.set(O,R);if(this.ctx.state.tempExportedVars)for(let O of o.keys())this.ctx.state.tempExportedVars.delete(O);return b.finish(),te}if(this.ctx.state.extraArgs){let O=this.ctx.state.extraArgs;this.ctx.state.extraArgs=void 0;for(let R of O)p(R,!0)}let A=await yf(this.ctx,f,d);o.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(o)));let k,x=null;try{k=await this.runCommand(f,d,h,n,!1,!1,E,S,v,w.stdinUnavailable)}catch(O){if(O instanceof Qe||O instanceof Ke)x=O,k=te;else throw O}E>=0&&f!=="read"&&hn(this.ctx,E,k.internalStdinConsumed??0);let D=a+A;if(D&&(k={...k,stderr:D+k.stderr}),k=await mn(this.ctx,k,t.redirections.length>0,w.outputRoutes,k.internalProducerCommand??f,k.internalProducerOmitsShellPrefix),b.finish(),x)throw x;if(d.length>0){let O=d[d.length-1];if((f==="declare"||f==="local"||f==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(O)){let R=O.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);R&&(O=R[1])}this.ctx.state.lastArg=O}else this.ctx.state.lastArg=f;let $=Du(f)&&f!=="unset"&&f!=="eval";if(!this.ctx.state.options.posix||!$)for(let[O,R]of o)this.ctx.state.fullyUnsetLocals?.has(O)||(R===void 0?this.ctx.state.env.delete(O):this.ctx.state.env.set(O,R));if(this.ctx.state.tempExportedVars)for(let O of o.keys())this.ctx.state.tempExportedVars.delete(O);return o.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(k={...k,stderr:this.ctx.state.expansionStderr+k.stderr},this.ctx.state.expansionStderr=""),k}async runCommand(t,n,r,s,i=!1,o=!1,a=-1,l=!1,c=!1,u=!1){let f={ctx:this.ctx,runCommand:(p,m,y,b,w,E,S,v,A,k)=>this.runCommand(p,m,y,b,w,E,S,v,A,k),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(p,m,y)=>this.executeUserScript(p,m,y)},d=await $f(f,t,n,r,s,i,o,a,l,c,u);return d!==null?d.internalProducerCommand===void 0?{...d,internalProducerCommand:t}:d:{...await Cf(f,t,n,s,o,c,u),internalProducerCommand:t}}aliasExpansionStack=new Set;expandAlias(t){return Ul({env:this.ctx.state.env,limits:this.ctx.limits},t,this.aliasExpansionStack)}async findCommandInPath(t){return Ks(this.ctx,t)}async executeSubshell(t,n="",r=!1){return Ff(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeGroup(t,n="",r=!1){return Mf(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeArithmeticCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),nt(this.ctx,t.redirections,"",async()=>{try{let n=await J(this.ctx,t.expression.expression),r=be(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}
797
+ `)}})}async executeConditionalCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),nt(this.ctx,t.redirections,"",async()=>{try{let n=await un(this.ctx,t.expression),r=be(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 le?1:2;return L(`bash: conditional expression: ${n.message}
798
+ `,r)}})}};function ba(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function Xm(e){let t=ba(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var Ym=3;function Wf(e){let t=e;for(let n=0;n<Ym;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 Jm(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function Sa(e,t){let n=ba(e);if(!n)return!1;let r=Xm(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&Wf(n.pathname)?!1:Jm(n.pathname,r.pathPrefix)}function Vf(e){return typeof e=="string"?e:e.url}function zf(e,t){return!t||t.length===0?!1:t.some(n=>Sa(e,Vf(n)))}function Aa(e){let t=ey(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=Uf(t);if(n)return Js(n);let r=ny(t);return r?ry(r):!1}function ey(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function ty(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 Uf(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>ty(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,c]=r;return l>255||c>16777215?null:[l,c>>>16&255,c>>>8&255,c&255]}if(t.length===3){let[l,c,u]=r;return l>255||c>255||u>65535?null:[l,c,u>>>8&255,u&255]}let[s,i,o,a]=r;return s>255||i>255||o>255||a>255?null:[s,i,o,a]}function ny(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=Uf(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,c=o.map(l),u=a.map(l);if(c.some(m=>m===null)||u.some(m=>m===null))return null;let f=n?2:0,d=c.length+u.length+f,h=0;if(r===1){if(h=8-d,h<0)return null}else if(d!==8)return null;let p=[...c,...new Array(h).fill(0),...u];return n&&(p.push(n[0]<<8|n[1]),p.push(n[2]<<8|n[3])),p.length===8?p:null}function Js(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 ry(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 Js(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 Js(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 Js(s)}return!1}function jf(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=Vf(n);if(!ba(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!==""&&Wf(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 ut=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},On=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},Vt=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},ei=class extends Error{constructor(t,n){super(`HTTP method '${t}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}},Dn=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var sy=20,iy=3e4,oy=10485760,ay=["GET","HEAD"],Dr;typeof __BROWSER__<"u"&&__BROWSER__?Dr=null:(Dr=import("guarded-fetch"),Dr.catch(()=>{}));var ly=new Set(["GET","HEAD","OPTIONS"]),cy=new Set([301,302,303,307,308]);function Ir(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function uy(e){if(e?.aborted)throw Ir(e)}function ka(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=jf(t);if(S.length>0)throw new Error(`Invalid network allow-list:
799
+ ${S.join(`
800
+ `)}`)}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 k of A.transform)for(let[x,D]of Object.entries(k.headers))v.set(x,D)}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??sy,o=e.timeoutMs??iy,a=e.maxResponseSize??oy,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??ay,c=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),u=[];for(let S of t){let v=typeof S=="string"?S:S.url;try{u.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?c?{allowedHosts:void 0,skipSsrfCheckForAllowedHosts:void 0}:{allowedHosts:[f(S)],skipSsrfCheckForAllowedHosts:!0}:{allowedHosts:u,skipSsrfCheckForAllowedHosts:!c}}function h(S){try{return Aa(new URL(S).hostname)}catch{return!1}}async function p(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&&!zf(S,t))throw new ut(S)}function y(S){if(!c)return;let v;try{v=new URL(S)}catch{throw new ut(S,"invalid URL")}if(Aa(v.hostname))throw new ut(S,"private/loopback IP address blocked")}function b(S){if(e.dangerouslyAllowFullInternetAccess)return;let v=S.toUpperCase();if(!l.includes(v))throw new ei(v,l)}function w(S,v,A,k){if(!A.isGuardedFetchError(S))return S;let x=S,{onRedirectHop:D,subReason:$}=k;switch(x.code){case"host_not_allowed":case"protocol_not_allowed":return D?new Vt(v):new ut(v);case"hostname_unsafe":return D?new Vt(v):new ut(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 Vt(v);case"too_many_redirects":return new On(i);case"response_too_large":return new Dn(a);default:return S}}async function E(S,v={}){let A=v.method?.toUpperCase()??"GET",k=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 x=v.maxRedirects??i,D=Math.min(i,x),$=v.timeoutMs!==void 0?Math.min(v.timeoutMs,o):o,N=new AbortController,O=Lr(()=>N.abort(new DOMException("The operation was aborted","AbortError")),$),R=Wr(v.signal,N.signal);try{m(S),y(S),b(A);let W=Dr?await Dr:null,P=S,B=0,U=[],_=A,T=v.body,z=v.headers,ne=!1;for(;;){uy(R.signal);let Y=await Ce.runTrustedAsync(async()=>{let Te=z;if(ne&&Te){let It=Te instanceof Headers?new Headers(Te):new Headers(Te);It.delete("authorization"),It.delete("cookie"),Te=It}let dt=s(P),Dt=dy(Te,dt),ht={method:_,headers:Dt,signal:R.signal,followRedirects:!1,timeoutMs:$,sanitizeHeaders:!1};if(T&&!ly.has(_)&&(ht.body=T),Object.assign(ht,d(P)),!W||h(P)){if(c)throw new ut(P,"DNS pinning unavailable for private IP enforcement");return await p(P,ht)}c?n&&(ht.fetch=n):(ht.fetch=n??globalThis.fetch,ht.dispatcher=null);let pt;ht.onUrlBlocked=It=>{pt=It.subReason};try{return await W.guardedFetch(P,ht)}catch(It){throw w(It,P,W,{onRedirectHop:B>0,subReason:pt})}});if(cy.has(Y.status)&&k){let Te=Y.headers.get("location");if(!Te)return await qf(Y,P,a,R.signal,U);U.push({status:Y.status,statusText:Y.statusText,headers:Gf(Y.headers)});let dt=new URL(Te,P).href;await va(fy(Y),R.signal);try{m(dt),y(dt)}catch(pt){throw R.signal?.aborted?Ir(R.signal):pt instanceof ut?new Vt(dt):pt}let Dt=Y.status;if(((Dt===301||Dt===302)&&_==="POST"||Dt===303&&_!=="GET"&&_!=="HEAD")&&(_="GET",T=void 0,b(_)),new URL(dt).origin!==new URL(P).origin&&(ne=!0),B++,B>D)throw new On(D);P=dt;continue}return await qf(Y,P,a,R.signal,U)}}finally{Fr(O),R.cleanup()}}return E}async function va(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),Ir(t);let n,r=new Promise((s,i)=>{n=()=>i(Ir(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function fy(e){e.body&&!e.body.locked&&await e.body.cancel()}function dy(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 Gf(e){let t=Object.create(null);return e.forEach((n,r)=>{t[r.toLowerCase()]=n}),t}async function qf(e,t,n,r,s){let i=Gf(e.headers);if(n>0){let l=e.headers.get("content-length");if(l){let c=parseInt(l,10);if(!Number.isNaN(c)&&c>n)throw new Dn(n)}}let o;if(n>0&&e.body){let l=e.body.getReader(),c=[],u=0;try{for(;;){let{done:d,value:h}=await va(l.read(),r);if(d)break;if(h){if(u+=h.byteLength,u>n)throw await l.cancel(),new Dn(n);c.push(h)}}}catch(d){throw r?.aborted&&await l.cancel(Ir(r)).catch(()=>{}),d}o=new Uint8Array(u);let f=0;for(let d of c)o.set(d,f),f+=d.byteLength}else{let l=await va(e.arrayBuffer(),r);if(n>0&&l.byteLength>n)throw new Dn(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 _r(e,t){if(e.length>t||V(e)>t)throw new C(`script input size limit exceeded (${t} bytes)`,"string_length")}var Hf="/usr/bin:/bin",Zf=[["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"]],Tr=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;invokeToolFn;transformPlugins=[];state;constructor(t={}){this.limits=qr({...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 yt(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",Hf],["IFS",`
801
+ `],...Zf,["PWD",r],["OLDPWD",r],["OPTIND","1"],...Object.entries(t.env??{})]);if(t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=ka(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",Qr(this.state.options)),this.state.env.set("BASHOPTS",Kr(this.state.shoptOptions)),Ka(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&(n instanceof yt||n instanceof Kt))try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of Ta(t.commands))this.registerBundledCommand(o);if(t.fetch||t.network)for(let o of La())this.registerBundledCommand(o);if(t.python)for(let o of Fa())this.registerBundledCommand(o);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let o of Ma())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(Ua(o)){let a=ja(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,c)=>t.execute(l,c)};this.commands.set(t.name,o);let a=this.fs;if(typeof a.writeFileSync=="function"){let l=`#!/bin/bash
801
802
  # Built-in command: ${t.name}
802
- `;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=jf(t.stdout),t.stderr=jf(t.stderr),t}async exec(t,n){let r=new jr(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
803
- `,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,c=Mr(i,n?.signal),u=n?{...n,signal:c.signal}:{signal:c.signal};try{if(r.assertExecDepth(s),Dr(t,this.limits.maxSourceBytes),!t.trim())return{stdout:"",stderr:"",exitCode:0,env:Ye(this.state.env,u.env)};this.logger?.info("exec",{command:t});let f=u.cwd??this.state.cwd,d,h=f;if(u.cwd)if(u.env&&"PWD"in u.env)d=u.env.PWD;else if(u.env&&!("PWD"in u.env))try{d=await this.fs.realpath(f),h=d}catch{d=f}else d=f;let p=u.replaceEnv?new Map:new Map(this.state.env);if(u.env)for(let[g,b]of Object.entries(u.env))p.set(g,b);d!==void 0&&p.set("PWD",d);let m={...this.state,env:p,arrays:u.replaceEnv?new Map:at(this.state.arrays),cwd:h,previousDir:u.env?.OLDPWD??this.state.previousDir,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:ly(u.stdin,u.stdinKind,this.limits.maxInputBytes,this.limits.maxStringLength,r,o),signal:u.signal,extraArgs:u.args},E=t;u.rawScript||(E=Uf(t));let S=this.defenseInDepthConfig?Ce.getInstance(this.defenseInDepthConfig):null,y=S?.activate();try{let g=async()=>{let b=He(E,{maxHeredocSize:this.limits.maxHeredocSize}),v;if(this.transformPlugins.length>0){let x=Object.create(null);for(let C of this.transformPlugins){let D=C.transform({ast:b,metadata:x});b=D.ast,D.metadata&&(x=ar(x,D.metadata))}v=x}let k={fs:this.fs,commands:this.commands,limits:this.limits,executionScope:r,exec:(x,C,D=!1)=>this.execInScope(x,C,r,s+1,u.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 Nr(k,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:Ye(this.state.env,u.env)});if(g instanceof st)return l({stdout:g.stdout,stderr:g.stderr,exitCode:g.exitCode,env:Ye(this.state.env,u.env)});if(g instanceof le)return l({stdout:g.stdout,stderr:g.stderr,exitCode:1,env:Ye(this.state.env,u.env)});if(g instanceof Ue)return l({stdout:g.stdout,stderr:g.stderr,exitCode:124,env:Ye(this.state.env,u.env)});if(g instanceof $)return l({stdout:g.stdout,stderr:kt(g.stderr),exitCode:$.EXIT_CODE,internalOutputAccounting:g.internalOutputAccounting,env:Ye(this.state.env,u.env)});if(g instanceof zt)return l({stdout:"",stderr:`bash: security violation: ${kt(g.message)}
804
- `,exitCode:1,env:Ye(this.state.env,u.env)});if(g.name==="ParseException")return l({stdout:"",stderr:`bash: syntax error: ${kt(g.message)}
805
- `,exitCode:2,env:Ye(this.state.env,u.env)});if(g instanceof Je)return l({stdout:"",stderr:`bash: ${kt(g.message)}
806
- `,exitCode:2,env:Ye(this.state.env,u.env)});if(g instanceof RangeError)return l({stdout:"",stderr:`bash: ${kt(g.message)}
807
- `,exitCode:1,env:Ye(this.state.env,u.env)});throw g}finally{y?.deactivate()}}catch(f){if(f instanceof Ue)return l({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:Ye(this.state.env,u.env)});if(f instanceof $)return l({stdout:f.stdout,stderr:kt(f.stderr),exitCode:$.EXIT_CODE,internalOutputAccounting:f.internalOutputAccounting,env:Ye(this.state.env,u.env)});throw f}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 Zt(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){Dr(t,this.limits.maxSourceBytes);let n=Uf(t),r=He(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=ar(s,o.metadata))}return{script:mr(r),ast:r,metadata:s}}};function oy(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 Uf(e){let t=e.split(`
808
- `),n=[],r=[],s="none";for(let i=0;i<t.length;i++){let o=t[i];if(r.length>0){let u=r[r.length-1];if((u.stripTabs?o.replace(/^\t+/,""):o)===u.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=oy(o,a),a!=="none")continue;let c=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let u of l.matchAll(c)){let f=u[1]==="-",d=u[3];r.push({delimiter:d,stripTabs:f})}}return n.join(`
809
- `)}var ay=new TextDecoder("utf-8",{fatal:!0});function jf(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 ay.decode(n)}catch{return e}}function ly(e,t,n,r,s,i){if(e===void 0)return;let o=t==="bytes"?e.length:M(e);if(o>n||o>r)throw new $(`stdin size limit exceeded (${Math.min(n,r)} bytes)`,"string_length");return i||s.consumeInput(o,"stdin"),t==="bytes"?e:Ut(e)}import*as me from"node:fs";import*as _e from"node:path";import*as dt from"node:fs";import*as $e from"node:path";function Ie(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 Dn(e,t){try{let n=dt.realpathSync(e);return Ie(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=$e.dirname(e);if(r===e)return null;let s=Dn(r,t);if(s===null)return null;try{if(dt.lstatSync(e).isSymbolicLink()){let o=dt.readlinkSync(e),a=$e.isAbsolute(o)?o:$e.resolve($e.dirname(e),o),l=Dn(a,t);return l===null?null:l}}catch{}return $e.join(s,$e.basename(e))}return null}}function Xs(e,t,n){let r=Dn(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(dt.lstatSync(s).isSymbolicLink())return null}catch{}return r}function Ys(e,t){if(!dt.existsSync(e))throw new Error(`${t} root does not exist`);if(!dt.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function qf(e,t){if(!$e.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=dt.realpathSync(e)}catch{n=$e.resolve(e)}return Ie(n,t)?{withinRoot:!0,relativePath:n.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:$e.basename(e)}}function Js(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 cy=["ELOOP","EFBIG","EPERM"],uy="/home/user/project",er=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=_e.resolve(t.root);let n=t.mountPoint??uy;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,Ys(this.root,"OverlayFs"),this.canonicalRoot=me.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=W(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=W(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=W(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=_e.join(this.root,r),i=_e.resolve(s);return Ie(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?Dn(t,this.canonicalRoot):Xs(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=_e.dirname(t),r=this.resolveRealPath_(n);return r===null?null:_e.join(r,_e.basename(t))}sanitizeError(t,n,r){Js(t,n,r,cy)}ensureParentDirs(t){let n=yt(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=W(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 me.promises.lstat(r),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=ot(n);return Mt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Mt(n,"binary")}async readFileBuffer(t,n=new Set){z(t,"open");let r=W(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 c=this.resolveSymlink(r,s.target);return this.readFileBuffer(c,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((c,u)=>c+u.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 c of s.appendChunks)a.set(c,l),l+=c.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 me.promises.lstat(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${t}'`);let c=await me.promises.readlink(i),u=this.realTargetToVirtual(r,c),f=this.resolveSymlink(r,u);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?me.constants.O_RDONLY:me.constants.O_RDONLY|me.constants.O_NOFOLLOW,l=await me.promises.open(i,a);try{let c=await l.readFile();return new Uint8Array(c)}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){z(t,"write"),this.assertWritable(`write '${t}'`);let s=W(t);this.ensureParentDirs(s);let i=ot(r),o=Ft(n,i);this.setMemoryEntry(s,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(s)}async appendFile(t,n,r){z(t,"append"),this.assertWritable(`append '${t}'`);let s=W(t),i=ot(r),o=Ft(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){z(t,"stat");let r=W(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 me.promises.lstat(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let a=await me.promises.readlink(i),l=this.realTargetToVirtual(r,a),c=this.resolveSymlink(r,l);return this.stat(c,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){z(t,"lstat");let n=W(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 me.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 Ln(t,n)}realTargetToVirtual(t,n){let r=qf(n,this.canonicalRoot);if(r.withinRoot){if(!_e.isAbsolute(n))return n;let s=r.relativePath;return this.mountPoint==="/"?s:`${this.mountPoint}${s}`}return r.safeName}async mkdir(t,n){z(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=W(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=yt(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),c=l.split("/")[0];c&&!l.includes("/",c.length)&&s.add(c)}for(let[a,l]of this.memory)if(a!==n&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!s.has(u)&&!c.includes("/",1)&&r.set(u,{name:u,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 me.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 me.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=W(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 me.promises.lstat(l)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let u=await me.promises.readlink(l),f=this.realTargetToVirtual(r,u),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";z(t,r),this.assertWritable(`${r} '${t}'`);let s=W(t);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);let i=yt(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=it(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){z(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){z(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){z(t,"rm"),this.assertWritable(`rm '${t}'`);let r=W(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 me.lstatSync(r),!0}catch{return!1}}async cp(t,n,r){z(t,"cp"),z(n,"cp"),this.assertWritable(`cp '${n}'`);let s=W(t),i=W(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(Lt(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 c of l){let u=s==="/"?`/${c}`:`${s}/${c}`,f=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(u,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 Ht(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=me.readdirSync(r);for(let i of s){let o=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(o))continue;n.add(o);let a=_e.join(r,i);me.lstatSync(a).isDirectory()&&this.scanRealFs(o,n)}}catch{}}async chmod(t,n){z(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=W(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}'`);z(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=W(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){z(t,"link"),z(n,"link"),this.assertWritable(`link '${n}'`);let r=W(t),s=W(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){z(t,"readlink");let n=W(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 me.promises.readlink(s);if(!_e.isAbsolute(i)){let o=_e.resolve(_e.dirname(s),i),a;try{a=me.realpathSync(o)}catch{a=o}if(!Ie(a,this.canonicalRoot))return _e.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){z(t,"realpath");let n=W(t),r=new Set,s=async a=>{let l=a==="/"?[]:a.slice(1).split("/"),c="";for(let u of l){if(c=`${c}/${u}`,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(c),d=0,h=40;for(;f&&f.type==="symlink"&&d<h;){if(r.add(c),c=this.resolveSymlink(c,f.target),d++,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(c)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let p=this.toRealPath(c),m=this.resolveRealPath_(p);if(m)try{if((await me.promises.lstat(m)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let S=await me.promises.readlink(m),y=this.realTargetToVirtual(c,S);return r.add(c),c=this.resolveSymlink(c,y),s(c)}}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_(p);if(E)try{if((await me.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 c||"/"},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){z(t,"utimes"),this.assertWritable(`utimes '${t}'`);let s=W(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})}};import{randomBytes as fy}from"node:crypto";import*as O from"node:fs";import*as H from"node:path";var dy=["EACCES","escaping sandbox","EFBIG","ENOTSUP"],ei=class e{static activeMutationRoots=new Set;static pendingMutations=[];root;canonicalRoot;maxFileReadSize;maxCopyOnWriteSize;maxCopySize;allowSymlinks;constructor(t){this.root=H.resolve(t.root),this.maxFileReadSize=t.maxFileReadSize??10485760,this.maxCopyOnWriteSize=t.maxCopyOnWriteSize??104857600,this.maxCopySize=t.maxCopySize??0,this.allowSymlinks=t.allowSymlinks??!1,Ys(this.root,"ReadWriteFs"),this.canonicalRoot=O.realpathSync(this.root)}resolveAndValidate(t,n){let r=this.allowSymlinks?Dn(t,this.canonicalRoot):Xs(t,this.root,this.canonicalRoot);if(r===null)throw new Error(`EACCES: permission denied, '${n}' resolves outside sandbox`);return r}validateParent(t,n){let r=H.dirname(t),s=this.resolveAndValidate(r,n);return H.join(s,H.basename(t))}toRealPath(t){let n=W(t),r=H.join(this.root,n);return H.resolve(r)}async readFile(t,n){let r=await this.readFileBuffer(t),s=ot(n);return Mt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Mt(n,"binary")}async readFileBuffer(t){z(t,"open");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{let s=this.allowSymlinks?O.constants.O_RDONLY:O.constants.O_RDONLY|O.constants.O_NOFOLLOW,i=await O.promises.open(r,s);try{if(this.maxFileReadSize>0){let a=await i.stat();if(a.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${a.size} bytes, max ${this.maxFileReadSize})`)}let o=await i.readFile();return new Uint8Array(o)}finally{await i.close()}}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(i.code==="EISDIR")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(i.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(s,t,"open")}}async writeFile(t,n,r){await this.withFilesystemMutation(()=>this.writeFileUnlocked(t,n,r))}async writeFileUnlocked(t,n,r){z(t,"write");let s=this.toRealPath(t),i=this.resolveAndValidate(s,t),o=ot(r),a=Ft(n,o),l=H.dirname(i);try{await O.promises.mkdir(l,{recursive:!0}),i=this.resolveAndValidate(s,t);let c=this.allowSymlinks?0:O.constants.O_NOFOLLOW,u=null;try{let f=await O.promises.lstat(i);if(!f.isFile()&&!f.isDirectory())throw new Error(`EACCES: cannot write special file '${t}'`);let d=await O.promises.open(i,O.constants.O_WRONLY|O.constants.O_NONBLOCK|c);try{if(u=await d.stat(),!u.isFile())throw new Error(`EACCES: cannot write special file '${t}'`);if(u.nlink<=1){await d.truncate(0),await d.writeFile(a);return}}finally{await d.close()}}catch(f){if(f.code!=="ENOENT")throw f}await this.replaceFile(i,a,u)}catch(c){if(c.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(c,t,"write")}}async appendFile(t,n,r){await this.withFilesystemMutation(()=>this.appendFileUnlocked(t,n,r))}async appendFileUnlocked(t,n,r){z(t,"append");let s=this.toRealPath(t),i=ot(r),o=Ft(n,i),a=this.resolveAndValidate(s,t),l=H.dirname(a);try{await O.promises.mkdir(l,{recursive:!0}),a=this.resolveAndValidate(s,t);let c=this.allowSymlinks?0:O.constants.O_NOFOLLOW,u=null;try{let d=await O.promises.lstat(a);if(!d.isFile()&&!d.isDirectory())throw new Error(`EACCES: cannot append special file '${t}'`);let h=await O.promises.open(a,O.constants.O_WRONLY|O.constants.O_APPEND|O.constants.O_NONBLOCK|c);try{if(u=await h.stat(),!u.isFile())throw new Error(`EACCES: cannot append special file '${t}'`);if(u.nlink<=1){await h.writeFile(o);return}}finally{await h.close()}}catch(d){if(d.code!=="ENOENT")throw d}if(!u){await this.replaceFile(a,o,null);return}this.assertCopyOnWriteSize(u.size,"append",t);let f=await this.openCopySource(a);try{let d=await f.stat();if(!d.isFile()||d.dev!==u.dev||d.ino!==u.ino)throw new Error(`EACCES: file identity changed, append '${t}'`);await this.replaceFile(a,o,d,{handle:f,size:u.size})}finally{await f.close()}}catch(c){if(c.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(c,t,"append")}}async withFilesystemMutation(t){return new Promise((n,r)=>{e.pendingMutations.push({root:this.canonicalRoot,start:()=>{e.activeMutationRoots.add(this.canonicalRoot),t().then(n,r).finally(()=>{e.activeMutationRoots.delete(this.canonicalRoot),e.drainMutationQueue()})}}),e.drainMutationQueue()})}static drainMutationQueue(){for(let t=0;t<e.pendingMutations.length;){let n=e.pendingMutations[t];if([...e.activeMutationRoots].some(s=>Ie(n.root,s)||Ie(s,n.root))){t++;continue}e.pendingMutations.splice(t,1),n.start()}}assertCopyOnWriteSize(t,n,r){if(this.maxCopyOnWriteSize>0&&t>this.maxCopyOnWriteSize)throw new Error(`EFBIG: file too large for copy-on-write ${n} '${r}' (${t} bytes, max ${this.maxCopyOnWriteSize})`)}assertCopySize(t,n){if(this.maxCopySize>0&&t.size>this.maxCopySize)throw new Error(`EFBIG: file too large to copy '${n}' (${t.size} bytes, max ${this.maxCopySize})`)}randomTransactionToken(){return fy(16).toString("hex")}async openCopySource(t){let n=this.allowSymlinks?0:O.constants.O_NOFOLLOW,r=O.constants.O_RDONLY|O.constants.O_NONBLOCK|n,s=O.constants.O_NOATIME;if(process.platform!=="linux"||s===void 0)return O.promises.open(t,r);try{return await O.promises.open(t,r|s)}catch(i){if(i.code!=="EPERM")throw i;return O.promises.open(t,r)}}async replaceFile(t,n,r,s,i,o=!1){let a=H.dirname(t),l="",c=null,u=r===null?438:384;for(let p=0;p<16;p++){l=H.join(a,`.just-bash-write-${this.randomTransactionToken()}`);try{c=await O.promises.open(l,O.constants.O_WRONLY|O.constants.O_CREAT|O.constants.O_EXCL,u);break}catch(m){if(m.code!=="EEXIST")throw m}}if(!c)throw new Error(`EEXIST: replacement write '${t}'`);let f=c,d=await f.stat(),h=!1;try{try{let m=0,E=async S=>{let y=0;for(;y<S.byteLength;){let{bytesWritten:g}=await f.write(S,y,S.byteLength-y,m+y);if(g===0)throw new Error("EIO: replacement write made no progress");y+=g}m+=y};if(s){let S=Buffer.allocUnsafe(65536),y=0,g=s.size;for(;g>0;){let b=Math.min(S.length,g),{bytesRead:v}=await s.handle.read(S,0,b,y);if(v===0)break;await E(S.subarray(0,v)),y+=v,g-=v}}if(await E(n),r!==null&&await f.chmod(r.mode&(o?4095:511)),i)await f.utimes(i.atime,i.mtime);else if(r!==null){let S=await f.stat();await f.utimes(r.atime,S.mtime)}}finally{await f.close(),c=null}let p=await O.promises.lstat(l);if(!p.isFile()||p.dev!==d.dev||p.ino!==d.ino)throw new Error("EACCES: replacement staging entry changed");await O.promises.rename(l,t),h=!0}finally{c&&await c.close().catch(()=>{}),h||await O.promises.rm(l,{force:!0}).catch(()=>{})}}async exists(t){if(t.includes("\0"))return!1;let n=this.toRealPath(t);try{let r=this.resolveAndValidate(n,t);return await O.promises.access(r),!0}catch{return!1}}async stat(t){z(t,"stat");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{let s=await O.promises.lstat(r);if(!this.allowSymlinks&&s.isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);return{isFile:s.isFile(),isDirectory:s.isDirectory(),isSymbolicLink:s.isSymbolicLink(),mode:s.mode,size:s.size,mtime:s.mtime,dev:s.dev,ino:s.ino,identity:`real:${s.dev}:${s.ino}`}}catch(s){if(s.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(s,t,"stat")}}async lstat(t){z(t,"lstat");let n=this.toRealPath(t),r=n===this.root?this.resolveAndValidate(n,t):this.validateParent(n,t);try{let s=await O.promises.lstat(r);return{isFile:s.isFile(),isDirectory:s.isDirectory(),isSymbolicLink:s.isSymbolicLink(),mode:s.mode,size:s.size,mtime:s.mtime,dev:s.dev,ino:s.ino,identity:`real:${s.dev}:${s.ino}`}}catch(s){if(s.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(s,t,"lstat")}}async mkdir(t,n){await this.withFilesystemMutation(()=>this.mkdirUnlocked(t,n))}async createExclusive(t,n){await this.withFilesystemMutation(()=>this.createExclusiveUnlocked(t,n))}async assertCreatedInsideRoot(t,n,r,s,i){let o=!1;try{let a=this.resolveAndValidate(n,r),l=await O.promises.lstat(a);o=a===t&&l.dev===i.dev&&l.ino===i.ino}catch{o=!1}if(!o)throw new Error(`EACCES: permission denied, '${r}' resolves outside sandbox during ${s}`)}async createExclusiveUnlocked(t,n){let r=n.directory?"mkdir":"open";z(t,r);let s=this.toRealPath(t),i=s===this.root?this.resolveAndValidate(s,t):this.validateParent(s,t);try{if(n.directory){await O.promises.mkdir(i,{mode:n.mode});let l=await O.promises.open(i,O.constants.O_RDONLY|(O.constants.O_DIRECTORY??0)|(this.allowSymlinks?0:O.constants.O_NOFOLLOW));try{await this.assertCreatedInsideRoot(i,s,t,r,await l.stat())}finally{await l.close()}return}let o=this.allowSymlinks?0:O.constants.O_NOFOLLOW,a=await O.promises.open(i,O.constants.O_WRONLY|O.constants.O_CREAT|O.constants.O_EXCL|o,n.mode);try{await this.assertCreatedInsideRoot(i,s,t,r,await a.stat())}finally{await a.close()}}catch(o){let a=o;if(a.code==="EEXIST")throw new Error(`EEXIST: file already exists, ${r} '${t}'`);if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);this.sanitizeError(o,t,r)}}async mkdirUnlocked(t,n){z(t,"mkdir");let r=this.toRealPath(t),s=r===this.root?this.resolveAndValidate(r,t):this.validateParent(r,t);try{await O.promises.mkdir(s,{recursive:n?.recursive})}catch(i){let o=i;if(o.code==="EEXIST")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.sanitizeError(i,t,"mkdir")}}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){z(t,"scandir");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{if(!this.allowSymlinks&&(await O.promises.lstat(r)).isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);return(await O.promises.readdir(r,{withFileTypes:!0})).map(i=>({name:i.name,isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink()})).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(i.code==="ENOTDIR")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);this.sanitizeError(s,t,"scandir")}}async rm(t,n){await this.withFilesystemMutation(()=>this.rmUnlocked(t,n))}async rmUnlocked(t,n){z(t,"rm");let r=this.toRealPath(t),s=this.validateParent(r,t);try{let i=await O.promises.lstat(s);if(!this.allowSymlinks&&i.isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);await O.promises.rm(s,{recursive:n?.recursive??!1,force:n?.force??!1})}catch(i){let o=i;if(o.code==="ENOENT"){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(o.code==="ENOTEMPTY")throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);this.sanitizeError(i,t,"rm")}}async cp(t,n,r){await this.withFilesystemMutation(()=>this.cpUnlocked(t,n,r))}async cpUnlocked(t,n,r){z(t,"cp"),z(n,"cp");let s=this.toRealPath(t),i=this.toRealPath(n),o=this.validateParent(s,t),a=this.resolveAndValidate(i,n),l;try{l=await O.promises.lstat(o)}catch(c){if(c.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, cp '${t}'`);this.sanitizeError(c,t,"cp")}if(l.isDirectory()&&Ie(a,o))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);if(!l.isDirectory())try{let c=this.validateParent(i,n),u=await O.promises.lstat(c);if(l.dev===u.dev&&l.ino===u.ino)throw new Error(`EINVAL: cannot copy '${t}' onto itself, '${n}'`)}catch(c){if(c.code!=="ENOENT")throw c}if(l.isFile())try{let c=await O.promises.stat(a);if(l.dev===c.dev&&l.ino===c.ino)throw new Error(`EINVAL: cannot copy '${t}' onto itself, '${n}'`)}catch(c){if(c.code!=="ENOENT")throw c}try{await this.preflightCopyTree(o,t)}catch(c){this.sanitizeError(c,t,"cp")}if(l.isFile()||l.isSymbolicLink())try{await O.promises.mkdir(H.dirname(a),{recursive:!0}),this.resolveAndValidate(i,n)}catch(c){this.sanitizeError(c,n,"cp")}try{await this.copyTreeEntry(o,i,t,n,r?.recursive??!1)}catch(c){let u=c;if(u.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(u.code==="EISDIR")throw new Error(`EISDIR: is a directory, cp '${t}'`);this.sanitizeError(c,t,"cp")}}async copyTreeEntry(t,n,r,s,i){let o=await O.promises.lstat(t);if(o.isFile()){this.assertCopySize(o,r);let a=this.resolveAndValidate(n,s),l=await this.assertCopyDestinationWritable(a,s),c=await this.openCopySource(t);try{let u=await c.stat();if(!u.isFile()||u.dev!==o.dev||u.ino!==o.ino)throw new Error(`EACCES: file identity changed, cp '${r}'`);await this.replaceFile(a,new Uint8Array(0),l??o,{handle:c,size:o.size})}finally{await c.close()}return}if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`EACCES: permission denied, cp '${r}' contains a symlink`);let a=await O.promises.readlink(t),l=H.isAbsolute(a)?await this.toVirtualAbsoluteSymlinkTarget(a,r):a;await this.replaceSymlink(n,s,l);return}if(o.isDirectory()){if(!i)throw new Error(`EISDIR: is a directory, cp '${r}'`);let a=this.resolveAndValidate(n,s);await O.promises.mkdir(a,{recursive:!0}),a=this.resolveAndValidate(n,s);for(let l of await O.promises.readdir(t))await this.copyTreeEntry(H.join(t,l),H.join(n,l),H.join(r,l),H.join(s,l),!0);await O.promises.chmod(a,o.mode&4095);return}throw new Error(`EINVAL: unsupported file type, cp '${r}'`)}async assertCopyDestinationWritable(t,n){let r;try{r=await O.promises.lstat(t)}catch(o){if(o.code==="ENOENT")return null;throw o}if(!r.isFile()){if(r.isDirectory())return r;throw new Error(`EACCES: cannot copy over special file '${n}'`)}let s=this.allowSymlinks?0:O.constants.O_NOFOLLOW,i=await O.promises.open(t,O.constants.O_WRONLY|O.constants.O_NONBLOCK|s);try{let o=await i.stat();if(!o.isFile()||o.dev!==r.dev||o.ino!==r.ino)throw new Error(`EACCES: destination changed, cp '${n}'`)}finally{await i.close()}return r}async replaceSymlink(t,n,r){let s=this.validateParent(t,n),i=H.dirname(W(n)),o="",a="",l="",c=null;for(let f=0;f<16;f++){let d=`.just-bash-copy-link-${this.randomTransactionToken()}`;o=i==="/"?`/${d}`:`${i}/${d}`,a=this.toRealPath(o);try{await this.symlinkUnlocked(r,o),l=this.validateParent(a,o),c=await O.promises.lstat(l);break}catch(h){let p=h;if(p.code!=="EEXIST"&&!p.message.startsWith("EEXIST:"))throw h}}if(!c)throw new Error(`EEXIST: replacement symlink '${n}'`);let u=!1;try{let f=await O.promises.lstat(l);if(!f.isSymbolicLink()||f.dev!==c.dev||f.ino!==c.ino)throw new Error("EACCES: replacement symlink entry changed");await O.promises.rename(l,s),u=!0}finally{!u&&l&&await O.promises.rm(l,{force:!0}).catch(()=>{})}}async toVirtualAbsoluteSymlinkTarget(t,n){let r=H.resolve(t),s=await O.promises.realpath(r),i=await O.promises.realpath(H.dirname(r)),o=H.join(i,H.basename(r));if(!Ie(s,this.canonicalRoot)||!Ie(o,this.canonicalRoot))throw new Error(`EACCES: permission denied, cp '${n}' contains an unsafe symlink`);return o.slice(this.canonicalRoot.length)||"/"}async preflightCopyTree(t,n,r=new Set){let s=await O.promises.lstat(t),i=`${s.dev}:${s.ino}`;if(r.has(i))throw new Error(`ELOOP: cp '${n}' contains a cycle`);if(s.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`EACCES: permission denied, cp '${n}' contains a symlink`);let o=await O.promises.realpath(t);if(!Ie(o,this.canonicalRoot))throw new Error(`EACCES: permission denied, cp '${n}' contains an unsafe symlink`);return}if(s.isDirectory()){r.add(i);try{let o=await O.promises.readdir(t);for(let a of o)await this.preflightCopyTree(H.join(t,a),H.join(n,a),r)}finally{r.delete(i)}}}async mv(t,n){await this.withFilesystemMutation(()=>this.mvUnlocked(t,n))}async mvUnlocked(t,n){z(t,"mv"),z(n,"mv");let r=this.toRealPath(t),s=this.toRealPath(n),i=this.validateParent(r,t),o=this.validateParent(s,n),a;try{a=await O.promises.lstat(i)}catch(c){if(c.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);this.sanitizeError(c,t,"mv")}if(a.isDirectory()&&this.isSameOrDescendantIdentity(i,o))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);try{if(a.isSymbolicLink()){let c=await O.promises.readlink(i),u=H.resolve(H.dirname(o),c),f=await O.promises.realpath(u).catch(()=>u);if(!Ie(f,this.canonicalRoot))throw new Error(`EACCES: permission denied, mv '${t}' -> '${n}' would create symlink escaping sandbox`)}}catch(c){let u=c;if(u.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(u.message?.includes("EACCES")||u.message?.includes("escaping sandbox"))throw c}let l=H.dirname(o);try{await O.promises.mkdir(l,{recursive:!0})}catch(c){this.sanitizeError(c,n,"mv")}try{await O.promises.rename(i,o)}catch(c){let u=c;if(u.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(u.code==="EXDEV"){await this.moveAcrossDevices(t,n);return}this.sanitizeError(c,t,"mv")}try{if(O.lstatSync(o).isDirectory()&&this.findEscapingSymlinks(o).length>0)throw await O.promises.rename(o,i),new Error(`EACCES: permission denied, mv '${t}' -> '${n}' would create symlinks escaping sandbox`)}catch(c){if(c.message?.includes("EACCES")||c.message?.includes("escaping sandbox"))throw c;await O.promises.rename(o,i).catch(()=>{}),this.sanitizeError(c,n,"mv")}}isSameOrDescendantIdentity(t,n){let r=t,s=n;try{r=O.realpathSync(t)}catch{}try{s=O.realpathSync(n)}catch{try{let i=O.realpathSync(H.dirname(n));s=H.join(i,H.basename(n))}catch{}}return Ie(s,r)}async uniqueTransactionPath(t,n){let r=H.posix.dirname(t);for(let s=0;s<16;s++){let i=H.posix.join(r,`.just-bash-mv-${n}-${this.randomTransactionToken()}`);if(!await this.exists(i))return i}throw new Error(`EEXIST: mv '${t}'`)}async moveAcrossDevices(t,n){let r=await this.uniqueTransactionPath(n,"stage"),s=await this.uniqueTransactionPath(n,"backup"),i=await this.uniqueTransactionPath(t,"source"),o=this.validateParent(this.toRealPath(r),r),a=this.validateParent(this.toRealPath(s),s),l=this.validateParent(this.toRealPath(t),t),c=this.validateParent(this.toRealPath(i),i),u=this.validateParent(this.toRealPath(n),n),f=!1,d=!1,h=!1,p=async()=>{h&&await O.promises.rename(c,l).catch(()=>{}),d&&await O.promises.rm(u,{recursive:!0,force:!0}).catch(()=>{}),f&&await O.promises.rename(a,u).catch(()=>{}),await O.promises.rm(o,{recursive:!0,force:!0}).catch(()=>{})};try{if(await this.cpUnlocked(t,r,{recursive:!0}),(await O.promises.lstat(o)).isDirectory()&&this.findEscapingSymlinks(o).length>0)throw new Error(`EACCES: permission denied, mv '${t}' -> '${n}' would create symlinks escaping sandbox`);try{await O.promises.rename(u,a),f=!0}catch(E){if(E.code!=="ENOENT")throw E}await O.promises.rename(o,u),d=!0,await O.promises.rename(l,c),h=!0,await O.promises.rm(c,{recursive:!0,force:!1}),h=!1,f&&await O.promises.rm(a,{recursive:!0,force:!0}).catch(()=>{})}catch(m){await p(),this.sanitizeError(m,t,"mv")}}resolvePath(t,n){return Ht(t,n)}getAllPaths(){let t=[];return this.scanDir("/",t),t}sanitizeError(t,n,r){Js(t,n,r,dy)}findEscapingSymlinks(t){let n=[],r=O.readdirSync(t);for(let s of r){let i=H.join(t,s),o=O.lstatSync(i);if(o.isSymbolicLink()){let a=O.readlinkSync(i),l=H.resolve(t,a),c;try{c=O.realpathSync(l)}catch(u){if(u.code!=="ENOENT")throw u;c=l}Ie(c,this.canonicalRoot)||n.push(i)}else o.isDirectory()&&n.push(...this.findEscapingSymlinks(i))}return n}scanDir(t,n){let r=this.toRealPath(t),s;try{s=this.resolveAndValidate(r,t)}catch{return}try{let i=O.readdirSync(s);for(let o of i){let a=t==="/"?`/${o}`:`${t}/${o}`;n.push(a);let l=H.join(s,o);O.lstatSync(l).isDirectory()&&this.scanDir(a,n)}}catch{}}async chmod(t,n){await this.withFilesystemMutation(()=>this.chmodUnlocked(t,n))}async chmodUnlocked(t,n){z(t,"chmod");let r=this.toRealPath(t),s=this.resolveAndValidate(r,t);try{let i=await O.promises.lstat(s);if(!i.isFile()){if(!i.isDirectory()&&i.nlink>1)throw new Error(`EACCES: cannot chmod multiply-linked special file '${t}'`);await O.promises.chmod(s,n);return}if(i.nlink<=1){await O.promises.chmod(s,n);return}this.assertCopyOnWriteSize(i.size,"chmod",t);let o=await this.openCopySource(s);try{let a=await o.stat();if(!a.isFile())throw new Error(`EACCES: file type changed, chmod '${t}'`);await this.replaceFile(s,new Uint8Array(0),{mode:n,atime:a.atime,mtime:a.mtime},{handle:o,size:a.size},{atime:a.atime,mtime:a.mtime},!0)}finally{await o.close()}}catch(i){let o=i;if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);if(o.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(i,t,"chmod")}}async symlink(t,n){await this.withFilesystemMutation(()=>this.symlinkUnlocked(t,n))}async symlinkUnlocked(t,n){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${n}'`);z(n,"symlink");let r=this.toRealPath(n),s=this.validateParent(r,n),i=W(n),o=W(H.dirname(i)),a=t.startsWith("/")?W(t):W(o==="/"?`/${t}`:`${o}/${t}`),l=H.join(this.canonicalRoot,a),c=H.dirname(s),u=t.startsWith("/")?l:H.relative(c,l)||".";try{await O.promises.symlink(u,s)}catch(f){if(f.code==="EEXIST")throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.sanitizeError(f,n,"symlink")}}async link(t,n){await this.withFilesystemMutation(()=>this.linkUnlocked(t,n))}async linkUnlocked(t,n){z(t,"link"),z(n,"link");let r=this.toRealPath(t),s=this.toRealPath(n),i=this.resolveAndValidate(r,t),o=s===this.root?this.resolveAndValidate(s,n):this.validateParent(s,n);try{await O.promises.link(i,o)}catch(a){let l=a;if(l.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(l.code==="EEXIST")throw new Error(`EEXIST: file already exists, link '${n}'`);if(l.code==="EPERM")throw new Error(`EPERM: operation not permitted, link '${t}'`);this.sanitizeError(a,t,"link")}}async readlink(t){z(t,"readlink");let n=this.toRealPath(t),r=n===this.root?this.resolveAndValidate(n,t):this.validateParent(n,t);try{let s=await O.promises.readlink(r),i=W(t),o=H.dirname(i),a=H.isAbsolute(s)?s:H.resolve(H.dirname(r),s),l=await O.promises.realpath(a).catch(()=>a);if(Ie(l,this.canonicalRoot)){let c=l.slice(this.canonicalRoot.length)||"/";return o==="/"?c.startsWith("/")?c.slice(1)||".":c:H.relative(o,c)}return H.basename(s)}catch(s){let i=s;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(s,t,"readlink")}}async realpath(t){z(t,"realpath");let n=this.toRealPath(t);try{this.resolveAndValidate(n,t)}catch{throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}let r;try{r=await O.promises.realpath(n)}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);if(i.code==="ELOOP")throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);this.sanitizeError(s,t,"realpath")}if(Ie(r,this.canonicalRoot))return r.slice(this.canonicalRoot.length)||"/";throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}async utimes(t,n,r){await this.withFilesystemMutation(()=>this.utimesUnlocked(t,n,r))}async utimesUnlocked(t,n,r){z(t,"utimes");let s=this.toRealPath(t),i=this.resolveAndValidate(s,t);try{let o=await O.promises.lstat(i);if(!o.isFile()){if(!o.isDirectory()&&o.nlink>1)throw new Error(`EACCES: cannot change times on multiply-linked special file '${t}'`);await O.promises.utimes(i,n,r);return}if(o.nlink<=1){await O.promises.utimes(i,n,r);return}this.assertCopyOnWriteSize(o.size,"utimes",t);let a=await this.openCopySource(i);try{let l=await a.stat();if(!l.isFile())throw new Error(`EACCES: file type changed, utimes '${t}'`);await this.replaceFile(i,new Uint8Array(0),l,{handle:a,size:l.size},{atime:n,mtime:r},!0)}finally{await a.close()}}catch(o){let a=o;if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);if(a.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(o,t,"utimes")}}};var tr=class{cmdId;cwd;startedAt;exitCode;bashEnv;cmdLine;env;explicitCwd;signal;timeoutMs;abortController=new AbortController;timeoutId;externalAbortListener;resultPromise;constructor(t,n,r,s,i=!1,o,a){this.cmdId=crypto.randomUUID(),this.cwd=r,this.startedAt=new Date,this.bashEnv=t,this.cmdLine=n,this.env=s,this.explicitCwd=i,this.signal=o,this.timeoutMs=a,this.setupCancellation(),this.resultPromise=this.execute()}setupCancellation(){if(this.signal&&(this.signal.aborted?this.abortController.abort(this.signal.reason):(this.externalAbortListener=()=>{this.abortController.abort(this.signal?.reason)},this.signal.addEventListener("abort",this.externalAbortListener,{once:!0}))),this.timeoutMs!==void 0){let t=Math.max(0,this.timeoutMs);this.timeoutId=_r(()=>{this.abortController.abort(new Error(`sandbox command timeout after ${t}ms`))},t)}}cleanupCancellation(){this.timeoutId!==void 0&&(Tr(this.timeoutId),this.timeoutId=void 0),this.signal&&this.externalAbortListener&&(this.signal.removeEventListener("abort",this.externalAbortListener),this.externalAbortListener=void 0)}async execute(){let t={cwd:this.explicitCwd?this.cwd:void 0,env:this.env,signal:this.abortController.signal};try{let n=await this.bashEnv.exec(this.cmdLine,t);return this.exitCode=n.exitCode,n}finally{this.cleanupCancellation()}}async*logs(){let t=await this.resultPromise;t.stdout&&(yield{type:"stdout",data:t.stdout,timestamp:new Date}),t.stderr&&(yield{type:"stderr",data:t.stderr,timestamp:new Date})}async wait(){return await this.resultPromise,this}async output(){let t=await this.resultPromise;return t.stdout+t.stderr}async stdout(){return(await this.resultPromise).stdout}async stderr(){return(await this.resultPromise).stderr}async kill(){this.abortController.abort(new Error("command killed"))}};var ti=class e{bashEnv;timeoutMs;constructor(t,n){this.bashEnv=t,this.timeoutMs=n}static async create(t){let n=t?.fs;if(t?.overlayRoot){if(t?.fs)throw new Error("Cannot specify both 'fs' and 'overlayRoot' options");n=new er({root:t.overlayRoot})}let r=new Ir({env:t?.env,cwd:t?.cwd,fs:n,maxCallDepth:t?.maxCallDepth,maxCommandCount:t?.maxCommandCount,maxLoopIterations:t?.maxLoopIterations,network:t?.network,defenseInDepth:t?.defenseInDepth,python:t?.python,javascript:t?.javascript,commands:t?.commands,customCommands:t?.customCommands,fetch:t?.fetch});return new e(r,t?.timeoutMs)}async runCommand(t,n,r){let s,i,o,a,l=!1,c,u;if(typeof t=="object"){let m=t,E=[m.cmd,...m.args??[]];s=oi(E),i=m.cwd,o=m.env,a=m.signal,l=m.detached??!1,c=m.stdout,u=m.stderr}else if(Array.isArray(n)){let m=r;s=oi([t,...n]),a=m?.signal}else{s=t;let m=n;i=m?.cwd,o=m?.env}let f=i??this.bashEnv.getCwd(),d=i!==void 0,h=new tr(this.bashEnv,s,f,o,d,a,this.timeoutMs);if(l)return h;let p=await h.wait();if(c){let m=await h.stdout();m&&c.write(m)}if(u){let m=await h.stderr();m&&u.write(m)}return p}async writeFiles(t){let n=this.bashEnv.getCwd();for(let[r,s]of Object.entries(t)){let i;typeof s=="string"?i=s:s.encoding==="base64"?i=Buffer.from(s.content,"base64").toString("utf-8"):i=s.content;let o=this.bashEnv.fs.resolvePath(n,r),a=o.substring(0,o.lastIndexOf("/"))||"/";a!=="/"&&await this.bashEnv.fs.mkdir(a,{recursive:!0}),await this.bashEnv.writeFile(o,i)}}async readFile(t,n){let r=await this.bashEnv.readFile(t);return n==="base64"?Buffer.from(r).toString("base64"):r}async mkDir(t,n){let r=this.bashEnv.fs.resolvePath(this.bashEnv.getCwd(),t);await this.bashEnv.fs.mkdir(r,{recursive:n?.recursive??!1})}async stop(){}async extendTimeout(t){}get domain(){}get bashEnvInstance(){return this.bashEnv}};var ni=class{violations=[];violationsByType=new Map;options;constructor(t={}){this.options={maxViolationsPerType:t.maxViolationsPerType??100,maxViolationsTotal:t.maxViolationsTotal??1e3,includeStackTraces:t.includeStackTraces??!0,onViolation:t.onViolation??(()=>{}),logToConsole:t.logToConsole??!1}}record(t){let n=this.options.includeStackTraces?t:{...t,stack:void 0};this.violations.unshift(n),this.violations.length>this.options.maxViolationsTotal&&(this.violations.length=this.options.maxViolationsTotal);let r=this.violationsByType.get(t.type);r||(r=[],this.violationsByType.set(t.type,r)),r.length<this.options.maxViolationsPerType&&r.push(n),this.options.logToConsole&&console.warn(`[SecurityViolation] ${t.type}: ${t.message}`,t.path),this.options.onViolation(n)}getViolations(){return[...this.violations]}getViolationsByType(t){return[...this.violationsByType.get(t)??[]]}getSummary(){let t=[];for(let[n,r]of this.violationsByType){if(r.length===0)continue;let s=new Set,i=Number.POSITIVE_INFINITY,o=0;for(let a of r)s.add(a.path),i=Math.min(i,a.timestamp),o=Math.max(o,a.timestamp);t.push({type:n,count:r.length,firstSeen:i,lastSeen:o,paths:Array.from(s)})}return t.sort((n,r)=>r.count-n.count),t}getTotalCount(){return this.violations.length}hasViolations(){return this.violations.length>0}clear(){this.violations=[],this.violationsByType.clear()}createCallback(){return t=>this.record(t)}};function Gf(){return e=>{console.warn("[DefenseInDepth] Security violation detected:",`
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=Kf(t.stdout),t.stderr=Kf(t.stderr),t}async exec(t,n){let r=new Gr(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,l){let c=d=>a?this.logResult(d):d,u=Wr(i,n?.signal),f=n?{...n,signal:u.signal}:{signal:u.signal};try{if(r.assertExecDepth(s),_r(t,this.limits.maxSourceBytes),!t.trim())return{stdout:"",stderr:"",exitCode:0,env:Ye(this.state.env,f.env)};this.logger?.info("exec",{command:t});let d=f.cwd??this.state.cwd,h,p=d;if(f.cwd)if(f.env&&"PWD"in f.env)h=f.env.PWD;else if(f.env&&!("PWD"in f.env))try{h=await this.fs.realpath(d),p=h}catch{h=d}else h=d;let m=f.replaceEnv||f.newShell,y=m?new Map:new Map((l??this.state).env);if(f.env)for(let[x,D]of Object.entries(f.env))y.set(x,D);h!==void 0&&y.set("PWD",h);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 x of Object.keys(f.env??{}))/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(x)&&w.add(x);h!==void 0&&w.add("PWD")}if(f.newShell){y.has("PATH")||y.set("PATH",Hf);for(let[x,D]of Zf)y.has(x)||y.set(x,D);y.set("IFS",`
805
+ `),y.set("OPTIND","1"),y.set("SHELLOPTS",Qr(this.state.options)),y.set("BASHOPTS",Kr(this.state.shoptOptions))}let E=l&&!f.newShell?l:this.state,S={...this.state,env:y,exportedVars:w,arrays:m?new Map:ot(this.state.arrays),cwd:p,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:my(f.stdin,f.stdinKind,this.limits.maxInputBytes,this.limits.maxStringLength,r,o),signal:f.signal,extraArgs:f.args},v=t;f.rawScript||(v=Qf(t));let A=this.defenseInDepthConfig?Ce.getInstance(this.defenseInDepthConfig):null,k=A?.activate();try{let x=async()=>{let D=He(v,{maxHeredocSize:this.limits.maxHeredocSize}),$;if(this.transformPlugins.length>0){let P=Object.create(null);for(let B of this.transformPlugins){let U=B.transform({ast:D,metadata:P});D=U.ast,U.metadata&&(P=lr(P,U.metadata))}$=P}let N={fs:this.fs,commands:this.commands,limits:this.limits,executionScope:r,exec:(P,B,U=!1)=>this.execInScope(P,B,r,s+1,f.signal,U,!0,S),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:A?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},W=await new Or(N,S).executeScript(D);return $&&(W.metadata=$),c(W)};return k?await k.run(x):await x()}catch(x){if(x instanceof G)return c({stdout:x.stdout,stderr:x.stderr,exitCode:x.exitCode,internalOutputAccounting:x.internalOutputAccounting,env:Ye(this.state.env,f.env)});if(x instanceof rt)return c({stdout:x.stdout,stderr:x.stderr,exitCode:x.exitCode,env:Ye(this.state.env,f.env)});if(x instanceof le)return c({stdout:x.stdout,stderr:x.stderr,exitCode:1,env:Ye(this.state.env,f.env)});if(x instanceof Ue)return c({stdout:x.stdout,stderr:x.stderr,exitCode:124,env:Ye(this.state.env,f.env)});if(x instanceof C)return c({stdout:x.stdout,stderr:kt(x.stderr),exitCode:C.EXIT_CODE,internalOutputAccounting:x.internalOutputAccounting,env:Ye(this.state.env,f.env)});if(x instanceof zt)return c({stdout:"",stderr:`bash: security violation: ${kt(x.message)}
806
+ `,exitCode:1,env:Ye(this.state.env,f.env)});if(x.name==="ParseException")return c({stdout:"",stderr:`bash: syntax error: ${kt(x.message)}
807
+ `,exitCode:2,env:Ye(this.state.env,f.env)});if(x instanceof Je)return c({stdout:"",stderr:`bash: ${kt(x.message)}
808
+ `,exitCode:2,env:Ye(this.state.env,f.env)});if(x instanceof RangeError)return c({stdout:"",stderr:`bash: ${kt(x.message)}
809
+ `,exitCode:1,env:Ye(this.state.env,f.env)});throw x}finally{k?.deactivate()}}catch(d){if(d instanceof Ue)return c({stdout:d.stdout,stderr:d.stderr,exitCode:124,env:Ye(this.state.env,f.env)});if(d instanceof C)return c({stdout:d.stdout,stderr:kt(d.stderr),exitCode:C.EXIT_CODE,internalOutputAccounting:d.internalOutputAccounting,env:Ye(this.state.env,f.env)});throw d}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 Zt(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){_r(t,this.limits.maxSourceBytes);let n=Qf(t),r=He(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=lr(s,o.metadata))}return{script:yr(r),ast:r,metadata:s}}};function hy(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 Qf(e){let t=e.split(`
810
+ `),n=[],r=[],s="none";for(let i=0;i<t.length;i++){let o=t[i];if(r.length>0){let u=r[r.length-1];if((u.stripTabs?o.replace(/^\t+/,""):o)===u.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=hy(o,a),a!=="none")continue;let c=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let u of l.matchAll(c)){let f=u[1]==="-",d=u[3];r.push({delimiter:d,stripTabs:f})}}return n.join(`
811
+ `)}var py=new TextDecoder("utf-8",{fatal:!0});function Kf(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 py.decode(n)}catch{return e}}function my(e,t,n,r,s,i){if(e===void 0)return;let o=t==="bytes"?e.length:V(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:Ut(e)}import*as me from"node:fs";import*as _e from"node:path";import*as ft from"node:fs";import*as $e from"node:path";function Ie(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 In(e,t){try{let n=ft.realpathSync(e);return Ie(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=$e.dirname(e);if(r===e)return null;let s=In(r,t);if(s===null)return null;try{if(ft.lstatSync(e).isSymbolicLink()){let o=ft.readlinkSync(e),a=$e.isAbsolute(o)?o:$e.resolve($e.dirname(e),o),l=In(a,t);return l===null?null:l}}catch{}return $e.join(s,$e.basename(e))}return null}}function ti(e,t,n){let r=In(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(ft.lstatSync(s).isSymbolicLink())return null}catch{}return r}function ni(e,t){if(!ft.existsSync(e))throw new Error(`${t} root does not exist`);if(!ft.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function Xf(e,t){if(!$e.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=ft.realpathSync(e)}catch{n=$e.resolve(e)}return Ie(n,t)?{withinRoot:!0,relativePath:n.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:$e.basename(e)}}function ri(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 yy=["ELOOP","EFBIG","EPERM"],gy="/home/user/project",tr=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=_e.resolve(t.root);let n=t.mountPoint??gy;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,ni(this.root,"OverlayFs"),this.canonicalRoot=me.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=j(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=j(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=j(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=_e.join(this.root,r),i=_e.resolve(s);return Ie(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?In(t,this.canonicalRoot):ti(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=_e.dirname(t),r=this.resolveRealPath_(n);return r===null?null:_e.join(r,_e.basename(t))}sanitizeError(t,n,r){ri(t,n,r,yy)}ensureParentDirs(t){let n=mt(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=j(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 me.promises.lstat(r),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=it(n);return Mt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Mt(n,"binary")}async readFileBuffer(t,n=new Set){q(t,"open");let r=j(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 c=this.resolveSymlink(r,s.target);return this.readFileBuffer(c,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((c,u)=>c+u.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 c of s.appendChunks)a.set(c,l),l+=c.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 me.promises.lstat(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${t}'`);let c=await me.promises.readlink(i),u=this.realTargetToVirtual(r,c),f=this.resolveSymlink(r,u);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?me.constants.O_RDONLY:me.constants.O_RDONLY|me.constants.O_NOFOLLOW,l=await me.promises.open(i,a);try{let c=await l.readFile();return new Uint8Array(c)}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=j(t);this.ensureParentDirs(s);let i=it(r),o=Ft(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=j(t),i=it(r),o=Ft(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=j(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 me.promises.lstat(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let a=await me.promises.readlink(i),l=this.realTargetToVirtual(r,a),c=this.resolveSymlink(r,l);return this.stat(c,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=j(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 me.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 Fn(t,n)}realTargetToVirtual(t,n){let r=Xf(n,this.canonicalRoot);if(r.withinRoot){if(!_e.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=j(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=mt(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),c=l.split("/")[0];c&&!l.includes("/",c.length)&&s.add(c)}for(let[a,l]of this.memory)if(a!==n&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!s.has(u)&&!c.includes("/",1)&&r.set(u,{name:u,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 me.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 me.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=j(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 me.promises.lstat(l)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let u=await me.promises.readlink(l),f=this.realTargetToVirtual(r,u),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=j(t);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);let i=mt(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=st(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=j(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 me.lstatSync(r),!0}catch{return!1}}async cp(t,n,r){q(t,"cp"),q(n,"cp"),this.assertWritable(`cp '${n}'`);let s=j(t),i=j(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(Lt(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 c of l){let u=s==="/"?`/${c}`:`${s}/${c}`,f=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(u,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 Ht(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=me.readdirSync(r);for(let i of s){let o=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(o))continue;n.add(o);let a=_e.join(r,i);me.lstatSync(a).isDirectory()&&this.scanRealFs(o,n)}}catch{}}async chmod(t,n){q(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=j(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=j(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=j(t),s=j(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=j(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 me.promises.readlink(s);if(!_e.isAbsolute(i)){let o=_e.resolve(_e.dirname(s),i),a;try{a=me.realpathSync(o)}catch{a=o}if(!Ie(a,this.canonicalRoot))return _e.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=j(t),r=new Set,s=async a=>{let l=a==="/"?[]:a.slice(1).split("/"),c="";for(let u of l){if(c=`${c}/${u}`,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(c),d=0,h=40;for(;f&&f.type==="symlink"&&d<h;){if(r.add(c),c=this.resolveSymlink(c,f.target),d++,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(c)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let p=this.toRealPath(c),m=this.resolveRealPath_(p);if(m)try{if((await me.promises.lstat(m)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let b=await me.promises.readlink(m),w=this.realTargetToVirtual(c,b);return r.add(c),c=this.resolveSymlink(c,w),s(c)}}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_(p);if(y)try{if((await me.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 c||"/"},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=j(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})}};import{randomBytes as wy}from"node:crypto";import*as I from"node:fs";import*as Z from"node:path";var Ey=["EACCES","escaping sandbox","EFBIG","ENOTSUP"],si=class e{static activeMutationRoots=new Set;static pendingMutations=[];root;canonicalRoot;maxFileReadSize;maxCopyOnWriteSize;maxCopySize;allowSymlinks;constructor(t){this.root=Z.resolve(t.root),this.maxFileReadSize=t.maxFileReadSize??10485760,this.maxCopyOnWriteSize=t.maxCopyOnWriteSize??104857600,this.maxCopySize=t.maxCopySize??0,this.allowSymlinks=t.allowSymlinks??!1,ni(this.root,"ReadWriteFs"),this.canonicalRoot=I.realpathSync(this.root)}resolveAndValidate(t,n){let r=this.allowSymlinks?In(t,this.canonicalRoot):ti(t,this.root,this.canonicalRoot);if(r===null)throw new Error(`EACCES: permission denied, '${n}' resolves outside sandbox`);return r}validateParent(t,n){let r=Z.dirname(t),s=this.resolveAndValidate(r,n);return Z.join(s,Z.basename(t))}toRealPath(t){let n=j(t),r=Z.join(this.root,n);return Z.resolve(r)}async readFile(t,n){let r=await this.readFileBuffer(t),s=it(n);return Mt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Mt(n,"binary")}async readFileBuffer(t){q(t,"open");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{let s=this.allowSymlinks?I.constants.O_RDONLY:I.constants.O_RDONLY|I.constants.O_NOFOLLOW,i=await I.promises.open(r,s);try{if(this.maxFileReadSize>0){let a=await i.stat();if(a.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${a.size} bytes, max ${this.maxFileReadSize})`)}let o=await i.readFile();return new Uint8Array(o)}finally{await i.close()}}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(i.code==="EISDIR")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(i.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(s,t,"open")}}async writeFile(t,n,r){await this.withFilesystemMutation(()=>this.writeFileUnlocked(t,n,r))}async writeFileUnlocked(t,n,r){q(t,"write");let s=this.toRealPath(t),i=this.resolveAndValidate(s,t),o=it(r),a=Ft(n,o),l=Z.dirname(i);try{await I.promises.mkdir(l,{recursive:!0}),i=this.resolveAndValidate(s,t);let c=this.allowSymlinks?0:I.constants.O_NOFOLLOW,u=null;try{let f=await I.promises.lstat(i);if(!f.isFile()&&!f.isDirectory())throw new Error(`EACCES: cannot write special file '${t}'`);let d=await I.promises.open(i,I.constants.O_WRONLY|I.constants.O_NONBLOCK|c);try{if(u=await d.stat(),!u.isFile())throw new Error(`EACCES: cannot write special file '${t}'`);if(u.nlink<=1){await d.truncate(0),await d.writeFile(a);return}}finally{await d.close()}}catch(f){if(f.code!=="ENOENT")throw f}await this.replaceFile(i,a,u)}catch(c){if(c.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(c,t,"write")}}async appendFile(t,n,r){await this.withFilesystemMutation(()=>this.appendFileUnlocked(t,n,r))}async appendFileUnlocked(t,n,r){q(t,"append");let s=this.toRealPath(t),i=it(r),o=Ft(n,i),a=this.resolveAndValidate(s,t),l=Z.dirname(a);try{await I.promises.mkdir(l,{recursive:!0}),a=this.resolveAndValidate(s,t);let c=this.allowSymlinks?0:I.constants.O_NOFOLLOW,u=null;try{let d=await I.promises.lstat(a);if(!d.isFile()&&!d.isDirectory())throw new Error(`EACCES: cannot append special file '${t}'`);let h=await I.promises.open(a,I.constants.O_WRONLY|I.constants.O_APPEND|I.constants.O_NONBLOCK|c);try{if(u=await h.stat(),!u.isFile())throw new Error(`EACCES: cannot append special file '${t}'`);if(u.nlink<=1){await h.writeFile(o);return}}finally{await h.close()}}catch(d){if(d.code!=="ENOENT")throw d}if(!u){await this.replaceFile(a,o,null);return}this.assertCopyOnWriteSize(u.size,"append",t);let f=await this.openCopySource(a);try{let d=await f.stat();if(!d.isFile()||d.dev!==u.dev||d.ino!==u.ino)throw new Error(`EACCES: file identity changed, append '${t}'`);await this.replaceFile(a,o,d,{handle:f,size:u.size})}finally{await f.close()}}catch(c){if(c.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(c,t,"append")}}async withFilesystemMutation(t){return new Promise((n,r)=>{e.pendingMutations.push({root:this.canonicalRoot,start:()=>{e.activeMutationRoots.add(this.canonicalRoot),t().then(n,r).finally(()=>{e.activeMutationRoots.delete(this.canonicalRoot),e.drainMutationQueue()})}}),e.drainMutationQueue()})}static drainMutationQueue(){for(let t=0;t<e.pendingMutations.length;){let n=e.pendingMutations[t];if([...e.activeMutationRoots].some(s=>Ie(n.root,s)||Ie(s,n.root))){t++;continue}e.pendingMutations.splice(t,1),n.start()}}assertCopyOnWriteSize(t,n,r){if(this.maxCopyOnWriteSize>0&&t>this.maxCopyOnWriteSize)throw new Error(`EFBIG: file too large for copy-on-write ${n} '${r}' (${t} bytes, max ${this.maxCopyOnWriteSize})`)}assertCopySize(t,n){if(this.maxCopySize>0&&t.size>this.maxCopySize)throw new Error(`EFBIG: file too large to copy '${n}' (${t.size} bytes, max ${this.maxCopySize})`)}randomTransactionToken(){return wy(16).toString("hex")}async openCopySource(t){let n=this.allowSymlinks?0:I.constants.O_NOFOLLOW,r=I.constants.O_RDONLY|I.constants.O_NONBLOCK|n,s=I.constants.O_NOATIME;if(process.platform!=="linux"||s===void 0)return I.promises.open(t,r);try{return await I.promises.open(t,r|s)}catch(i){if(i.code!=="EPERM")throw i;return I.promises.open(t,r)}}async replaceFile(t,n,r,s,i,o=!1){let a=Z.dirname(t),l="",c=null,u=r===null?438:384;for(let p=0;p<16;p++){l=Z.join(a,`.just-bash-write-${this.randomTransactionToken()}`);try{c=await I.promises.open(l,I.constants.O_WRONLY|I.constants.O_CREAT|I.constants.O_EXCL,u);break}catch(m){if(m.code!=="EEXIST")throw m}}if(!c)throw new Error(`EEXIST: replacement write '${t}'`);let f=c,d=await f.stat(),h=!1;try{try{let m=0,y=async b=>{let w=0;for(;w<b.byteLength;){let{bytesWritten:E}=await f.write(b,w,b.byteLength-w,m+w);if(E===0)throw new Error("EIO: replacement write made no progress");w+=E}m+=w};if(s){let b=Buffer.allocUnsafe(65536),w=0,E=s.size;for(;E>0;){let S=Math.min(b.length,E),{bytesRead:v}=await s.handle.read(b,0,S,w);if(v===0)break;await y(b.subarray(0,v)),w+=v,E-=v}}if(await y(n),r!==null&&await f.chmod(r.mode&(o?4095:511)),i)await f.utimes(i.atime,i.mtime);else if(r!==null){let b=await f.stat();await f.utimes(r.atime,b.mtime)}}finally{await f.close(),c=null}let p=await I.promises.lstat(l);if(!p.isFile()||p.dev!==d.dev||p.ino!==d.ino)throw new Error("EACCES: replacement staging entry changed");await I.promises.rename(l,t),h=!0}finally{c&&await c.close().catch(()=>{}),h||await I.promises.rm(l,{force:!0}).catch(()=>{})}}async exists(t){if(t.includes("\0"))return!1;let n=this.toRealPath(t);try{let r=this.resolveAndValidate(n,t);return await I.promises.access(r),!0}catch{return!1}}async stat(t){q(t,"stat");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{let s=await I.promises.lstat(r);if(!this.allowSymlinks&&s.isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);return{isFile:s.isFile(),isDirectory:s.isDirectory(),isSymbolicLink:s.isSymbolicLink(),mode:s.mode,size:s.size,mtime:s.mtime,dev:s.dev,ino:s.ino,identity:`real:${s.dev}:${s.ino}`}}catch(s){if(s.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(s,t,"stat")}}async lstat(t){q(t,"lstat");let n=this.toRealPath(t),r=n===this.root?this.resolveAndValidate(n,t):this.validateParent(n,t);try{let s=await I.promises.lstat(r);return{isFile:s.isFile(),isDirectory:s.isDirectory(),isSymbolicLink:s.isSymbolicLink(),mode:s.mode,size:s.size,mtime:s.mtime,dev:s.dev,ino:s.ino,identity:`real:${s.dev}:${s.ino}`}}catch(s){if(s.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(s,t,"lstat")}}async mkdir(t,n){await this.withFilesystemMutation(()=>this.mkdirUnlocked(t,n))}async createExclusive(t,n){await this.withFilesystemMutation(()=>this.createExclusiveUnlocked(t,n))}async assertCreatedInsideRoot(t,n,r,s,i){let o=!1;try{let a=this.resolveAndValidate(n,r),l=await I.promises.lstat(a);o=a===t&&l.dev===i.dev&&l.ino===i.ino}catch{o=!1}if(!o)throw new Error(`EACCES: permission denied, '${r}' resolves outside sandbox during ${s}`)}async createExclusiveUnlocked(t,n){let r=n.directory?"mkdir":"open";q(t,r);let s=this.toRealPath(t),i=s===this.root?this.resolveAndValidate(s,t):this.validateParent(s,t);try{if(n.directory){await I.promises.mkdir(i,{mode:n.mode});let l=await I.promises.open(i,I.constants.O_RDONLY|(I.constants.O_DIRECTORY??0)|(this.allowSymlinks?0:I.constants.O_NOFOLLOW));try{await this.assertCreatedInsideRoot(i,s,t,r,await l.stat())}finally{await l.close()}return}let o=this.allowSymlinks?0:I.constants.O_NOFOLLOW,a=await I.promises.open(i,I.constants.O_WRONLY|I.constants.O_CREAT|I.constants.O_EXCL|o,n.mode);try{await this.assertCreatedInsideRoot(i,s,t,r,await a.stat())}finally{await a.close()}}catch(o){let a=o;if(a.code==="EEXIST")throw new Error(`EEXIST: file already exists, ${r} '${t}'`);if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);this.sanitizeError(o,t,r)}}async mkdirUnlocked(t,n){q(t,"mkdir");let r=this.toRealPath(t),s=r===this.root?this.resolveAndValidate(r,t):this.validateParent(r,t);try{await I.promises.mkdir(s,{recursive:n?.recursive})}catch(i){let o=i;if(o.code==="EEXIST")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.sanitizeError(i,t,"mkdir")}}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){q(t,"scandir");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{if(!this.allowSymlinks&&(await I.promises.lstat(r)).isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);return(await I.promises.readdir(r,{withFileTypes:!0})).map(i=>({name:i.name,isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink()})).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(i.code==="ENOTDIR")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);this.sanitizeError(s,t,"scandir")}}async rm(t,n){await this.withFilesystemMutation(()=>this.rmUnlocked(t,n))}async rmUnlocked(t,n){q(t,"rm");let r=this.toRealPath(t),s=this.validateParent(r,t);try{let i=await I.promises.lstat(s);if(!this.allowSymlinks&&i.isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);await I.promises.rm(s,{recursive:n?.recursive??!1,force:n?.force??!1})}catch(i){let o=i;if(o.code==="ENOENT"){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(o.code==="ENOTEMPTY")throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);this.sanitizeError(i,t,"rm")}}async cp(t,n,r){await this.withFilesystemMutation(()=>this.cpUnlocked(t,n,r))}async cpUnlocked(t,n,r){q(t,"cp"),q(n,"cp");let s=this.toRealPath(t),i=this.toRealPath(n),o=this.validateParent(s,t),a=this.resolveAndValidate(i,n),l;try{l=await I.promises.lstat(o)}catch(c){if(c.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, cp '${t}'`);this.sanitizeError(c,t,"cp")}if(l.isDirectory()&&Ie(a,o))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);if(!l.isDirectory())try{let c=this.validateParent(i,n),u=await I.promises.lstat(c);if(l.dev===u.dev&&l.ino===u.ino)throw new Error(`EINVAL: cannot copy '${t}' onto itself, '${n}'`)}catch(c){if(c.code!=="ENOENT")throw c}if(l.isFile())try{let c=await I.promises.stat(a);if(l.dev===c.dev&&l.ino===c.ino)throw new Error(`EINVAL: cannot copy '${t}' onto itself, '${n}'`)}catch(c){if(c.code!=="ENOENT")throw c}try{await this.preflightCopyTree(o,t)}catch(c){this.sanitizeError(c,t,"cp")}if(l.isFile()||l.isSymbolicLink())try{await I.promises.mkdir(Z.dirname(a),{recursive:!0}),this.resolveAndValidate(i,n)}catch(c){this.sanitizeError(c,n,"cp")}try{await this.copyTreeEntry(o,i,t,n,r?.recursive??!1)}catch(c){let u=c;if(u.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(u.code==="EISDIR")throw new Error(`EISDIR: is a directory, cp '${t}'`);this.sanitizeError(c,t,"cp")}}async copyTreeEntry(t,n,r,s,i){let o=await I.promises.lstat(t);if(o.isFile()){this.assertCopySize(o,r);let a=this.resolveAndValidate(n,s),l=await this.assertCopyDestinationWritable(a,s),c=await this.openCopySource(t);try{let u=await c.stat();if(!u.isFile()||u.dev!==o.dev||u.ino!==o.ino)throw new Error(`EACCES: file identity changed, cp '${r}'`);await this.replaceFile(a,new Uint8Array(0),l??o,{handle:c,size:o.size})}finally{await c.close()}return}if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`EACCES: permission denied, cp '${r}' contains a symlink`);let a=await I.promises.readlink(t),l=Z.isAbsolute(a)?await this.toVirtualAbsoluteSymlinkTarget(a,r):a;await this.replaceSymlink(n,s,l);return}if(o.isDirectory()){if(!i)throw new Error(`EISDIR: is a directory, cp '${r}'`);let a=this.resolveAndValidate(n,s);await I.promises.mkdir(a,{recursive:!0}),a=this.resolveAndValidate(n,s);for(let l of await I.promises.readdir(t))await this.copyTreeEntry(Z.join(t,l),Z.join(n,l),Z.join(r,l),Z.join(s,l),!0);await I.promises.chmod(a,o.mode&4095);return}throw new Error(`EINVAL: unsupported file type, cp '${r}'`)}async assertCopyDestinationWritable(t,n){let r;try{r=await I.promises.lstat(t)}catch(o){if(o.code==="ENOENT")return null;throw o}if(!r.isFile()){if(r.isDirectory())return r;throw new Error(`EACCES: cannot copy over special file '${n}'`)}let s=this.allowSymlinks?0:I.constants.O_NOFOLLOW,i=await I.promises.open(t,I.constants.O_WRONLY|I.constants.O_NONBLOCK|s);try{let o=await i.stat();if(!o.isFile()||o.dev!==r.dev||o.ino!==r.ino)throw new Error(`EACCES: destination changed, cp '${n}'`)}finally{await i.close()}return r}async replaceSymlink(t,n,r){let s=this.validateParent(t,n),i=Z.dirname(j(n)),o="",a="",l="",c=null;for(let f=0;f<16;f++){let d=`.just-bash-copy-link-${this.randomTransactionToken()}`;o=i==="/"?`/${d}`:`${i}/${d}`,a=this.toRealPath(o);try{await this.symlinkUnlocked(r,o),l=this.validateParent(a,o),c=await I.promises.lstat(l);break}catch(h){let p=h;if(p.code!=="EEXIST"&&!p.message.startsWith("EEXIST:"))throw h}}if(!c)throw new Error(`EEXIST: replacement symlink '${n}'`);let u=!1;try{let f=await I.promises.lstat(l);if(!f.isSymbolicLink()||f.dev!==c.dev||f.ino!==c.ino)throw new Error("EACCES: replacement symlink entry changed");await I.promises.rename(l,s),u=!0}finally{!u&&l&&await I.promises.rm(l,{force:!0}).catch(()=>{})}}async toVirtualAbsoluteSymlinkTarget(t,n){let r=Z.resolve(t),s=await I.promises.realpath(r),i=await I.promises.realpath(Z.dirname(r)),o=Z.join(i,Z.basename(r));if(!Ie(s,this.canonicalRoot)||!Ie(o,this.canonicalRoot))throw new Error(`EACCES: permission denied, cp '${n}' contains an unsafe symlink`);return o.slice(this.canonicalRoot.length)||"/"}async preflightCopyTree(t,n,r=new Set){let s=await I.promises.lstat(t),i=`${s.dev}:${s.ino}`;if(r.has(i))throw new Error(`ELOOP: cp '${n}' contains a cycle`);if(s.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`EACCES: permission denied, cp '${n}' contains a symlink`);let o=await I.promises.realpath(t);if(!Ie(o,this.canonicalRoot))throw new Error(`EACCES: permission denied, cp '${n}' contains an unsafe symlink`);return}if(s.isDirectory()){r.add(i);try{let o=await I.promises.readdir(t);for(let a of o)await this.preflightCopyTree(Z.join(t,a),Z.join(n,a),r)}finally{r.delete(i)}}}async mv(t,n){await this.withFilesystemMutation(()=>this.mvUnlocked(t,n))}async mvUnlocked(t,n){q(t,"mv"),q(n,"mv");let r=this.toRealPath(t),s=this.toRealPath(n),i=this.validateParent(r,t),o=this.validateParent(s,n),a;try{a=await I.promises.lstat(i)}catch(c){if(c.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);this.sanitizeError(c,t,"mv")}if(a.isDirectory()&&this.isSameOrDescendantIdentity(i,o))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);try{if(a.isSymbolicLink()){let c=await I.promises.readlink(i),u=Z.resolve(Z.dirname(o),c),f=await I.promises.realpath(u).catch(()=>u);if(!Ie(f,this.canonicalRoot))throw new Error(`EACCES: permission denied, mv '${t}' -> '${n}' would create symlink escaping sandbox`)}}catch(c){let u=c;if(u.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(u.message?.includes("EACCES")||u.message?.includes("escaping sandbox"))throw c}let l=Z.dirname(o);try{await I.promises.mkdir(l,{recursive:!0})}catch(c){this.sanitizeError(c,n,"mv")}try{await I.promises.rename(i,o)}catch(c){let u=c;if(u.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(u.code==="EXDEV"){await this.moveAcrossDevices(t,n);return}this.sanitizeError(c,t,"mv")}try{if(I.lstatSync(o).isDirectory()&&this.findEscapingSymlinks(o).length>0)throw await I.promises.rename(o,i),new Error(`EACCES: permission denied, mv '${t}' -> '${n}' would create symlinks escaping sandbox`)}catch(c){if(c.message?.includes("EACCES")||c.message?.includes("escaping sandbox"))throw c;await I.promises.rename(o,i).catch(()=>{}),this.sanitizeError(c,n,"mv")}}isSameOrDescendantIdentity(t,n){let r=t,s=n;try{r=I.realpathSync(t)}catch{}try{s=I.realpathSync(n)}catch{try{let i=I.realpathSync(Z.dirname(n));s=Z.join(i,Z.basename(n))}catch{}}return Ie(s,r)}async uniqueTransactionPath(t,n){let r=Z.posix.dirname(t);for(let s=0;s<16;s++){let i=Z.posix.join(r,`.just-bash-mv-${n}-${this.randomTransactionToken()}`);if(!await this.exists(i))return i}throw new Error(`EEXIST: mv '${t}'`)}async moveAcrossDevices(t,n){let r=await this.uniqueTransactionPath(n,"stage"),s=await this.uniqueTransactionPath(n,"backup"),i=await this.uniqueTransactionPath(t,"source"),o=this.validateParent(this.toRealPath(r),r),a=this.validateParent(this.toRealPath(s),s),l=this.validateParent(this.toRealPath(t),t),c=this.validateParent(this.toRealPath(i),i),u=this.validateParent(this.toRealPath(n),n),f=!1,d=!1,h=!1,p=async()=>{h&&await I.promises.rename(c,l).catch(()=>{}),d&&await I.promises.rm(u,{recursive:!0,force:!0}).catch(()=>{}),f&&await I.promises.rename(a,u).catch(()=>{}),await I.promises.rm(o,{recursive:!0,force:!0}).catch(()=>{})};try{if(await this.cpUnlocked(t,r,{recursive:!0}),(await I.promises.lstat(o)).isDirectory()&&this.findEscapingSymlinks(o).length>0)throw new Error(`EACCES: permission denied, mv '${t}' -> '${n}' would create symlinks escaping sandbox`);try{await I.promises.rename(u,a),f=!0}catch(y){if(y.code!=="ENOENT")throw y}await I.promises.rename(o,u),d=!0,await I.promises.rename(l,c),h=!0,await I.promises.rm(c,{recursive:!0,force:!1}),h=!1,f&&await I.promises.rm(a,{recursive:!0,force:!0}).catch(()=>{})}catch(m){await p(),this.sanitizeError(m,t,"mv")}}resolvePath(t,n){return Ht(t,n)}getAllPaths(){let t=[];return this.scanDir("/",t),t}sanitizeError(t,n,r){ri(t,n,r,Ey)}findEscapingSymlinks(t){let n=[],r=I.readdirSync(t);for(let s of r){let i=Z.join(t,s),o=I.lstatSync(i);if(o.isSymbolicLink()){let a=I.readlinkSync(i),l=Z.resolve(t,a),c;try{c=I.realpathSync(l)}catch(u){if(u.code!=="ENOENT")throw u;c=l}Ie(c,this.canonicalRoot)||n.push(i)}else o.isDirectory()&&n.push(...this.findEscapingSymlinks(i))}return n}scanDir(t,n){let r=this.toRealPath(t),s;try{s=this.resolveAndValidate(r,t)}catch{return}try{let i=I.readdirSync(s);for(let o of i){let a=t==="/"?`/${o}`:`${t}/${o}`;n.push(a);let l=Z.join(s,o);I.lstatSync(l).isDirectory()&&this.scanDir(a,n)}}catch{}}async chmod(t,n){await this.withFilesystemMutation(()=>this.chmodUnlocked(t,n))}async chmodUnlocked(t,n){q(t,"chmod");let r=this.toRealPath(t),s=this.resolveAndValidate(r,t);try{let i=await I.promises.lstat(s);if(!i.isFile()){if(!i.isDirectory()&&i.nlink>1)throw new Error(`EACCES: cannot chmod multiply-linked special file '${t}'`);await I.promises.chmod(s,n);return}if(i.nlink<=1){await I.promises.chmod(s,n);return}this.assertCopyOnWriteSize(i.size,"chmod",t);let o=await this.openCopySource(s);try{let a=await o.stat();if(!a.isFile())throw new Error(`EACCES: file type changed, chmod '${t}'`);await this.replaceFile(s,new Uint8Array(0),{mode:n,atime:a.atime,mtime:a.mtime},{handle:o,size:a.size},{atime:a.atime,mtime:a.mtime},!0)}finally{await o.close()}}catch(i){let o=i;if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);if(o.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(i,t,"chmod")}}async symlink(t,n){await this.withFilesystemMutation(()=>this.symlinkUnlocked(t,n))}async symlinkUnlocked(t,n){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${n}'`);q(n,"symlink");let r=this.toRealPath(n),s=this.validateParent(r,n),i=j(n),o=j(Z.dirname(i)),a=t.startsWith("/")?j(t):j(o==="/"?`/${t}`:`${o}/${t}`),l=Z.join(this.canonicalRoot,a),c=Z.dirname(s),u=t.startsWith("/")?l:Z.relative(c,l)||".";try{await I.promises.symlink(u,s)}catch(f){if(f.code==="EEXIST")throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.sanitizeError(f,n,"symlink")}}async link(t,n){await this.withFilesystemMutation(()=>this.linkUnlocked(t,n))}async linkUnlocked(t,n){q(t,"link"),q(n,"link");let r=this.toRealPath(t),s=this.toRealPath(n),i=this.resolveAndValidate(r,t),o=s===this.root?this.resolveAndValidate(s,n):this.validateParent(s,n);try{await I.promises.link(i,o)}catch(a){let l=a;if(l.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(l.code==="EEXIST")throw new Error(`EEXIST: file already exists, link '${n}'`);if(l.code==="EPERM")throw new Error(`EPERM: operation not permitted, link '${t}'`);this.sanitizeError(a,t,"link")}}async readlink(t){q(t,"readlink");let n=this.toRealPath(t),r=n===this.root?this.resolveAndValidate(n,t):this.validateParent(n,t);try{let s=await I.promises.readlink(r),i=j(t),o=Z.dirname(i),a=Z.isAbsolute(s)?s:Z.resolve(Z.dirname(r),s),l=await I.promises.realpath(a).catch(()=>a);if(Ie(l,this.canonicalRoot)){let c=l.slice(this.canonicalRoot.length)||"/";return o==="/"?c.startsWith("/")?c.slice(1)||".":c:Z.relative(o,c)}return Z.basename(s)}catch(s){let i=s;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(s,t,"readlink")}}async realpath(t){q(t,"realpath");let n=this.toRealPath(t);try{this.resolveAndValidate(n,t)}catch{throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}let r;try{r=await I.promises.realpath(n)}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);if(i.code==="ELOOP")throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);this.sanitizeError(s,t,"realpath")}if(Ie(r,this.canonicalRoot))return r.slice(this.canonicalRoot.length)||"/";throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}async utimes(t,n,r){await this.withFilesystemMutation(()=>this.utimesUnlocked(t,n,r))}async utimesUnlocked(t,n,r){q(t,"utimes");let s=this.toRealPath(t),i=this.resolveAndValidate(s,t);try{let o=await I.promises.lstat(i);if(!o.isFile()){if(!o.isDirectory()&&o.nlink>1)throw new Error(`EACCES: cannot change times on multiply-linked special file '${t}'`);await I.promises.utimes(i,n,r);return}if(o.nlink<=1){await I.promises.utimes(i,n,r);return}this.assertCopyOnWriteSize(o.size,"utimes",t);let a=await this.openCopySource(i);try{let l=await a.stat();if(!l.isFile())throw new Error(`EACCES: file type changed, utimes '${t}'`);await this.replaceFile(i,new Uint8Array(0),l,{handle:a,size:l.size},{atime:n,mtime:r},!0)}finally{await a.close()}}catch(o){let a=o;if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);if(a.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(o,t,"utimes")}}};var nr=class{cmdId;cwd;startedAt;exitCode;bashEnv;cmdLine;env;explicitCwd;signal;timeoutMs;abortController=new AbortController;timeoutId;externalAbortListener;resultPromise;constructor(t,n,r,s,i=!1,o,a){this.cmdId=crypto.randomUUID(),this.cwd=r,this.startedAt=new Date,this.bashEnv=t,this.cmdLine=n,this.env=s,this.explicitCwd=i,this.signal=o,this.timeoutMs=a,this.setupCancellation(),this.resultPromise=this.execute()}setupCancellation(){if(this.signal&&(this.signal.aborted?this.abortController.abort(this.signal.reason):(this.externalAbortListener=()=>{this.abortController.abort(this.signal?.reason)},this.signal.addEventListener("abort",this.externalAbortListener,{once:!0}))),this.timeoutMs!==void 0){let t=Math.max(0,this.timeoutMs);this.timeoutId=Lr(()=>{this.abortController.abort(new Error(`sandbox command timeout after ${t}ms`))},t)}}cleanupCancellation(){this.timeoutId!==void 0&&(Fr(this.timeoutId),this.timeoutId=void 0),this.signal&&this.externalAbortListener&&(this.signal.removeEventListener("abort",this.externalAbortListener),this.externalAbortListener=void 0)}async execute(){let t={cwd:this.explicitCwd?this.cwd:void 0,env:this.env,signal:this.abortController.signal};try{let n=await this.bashEnv.exec(this.cmdLine,t);return this.exitCode=n.exitCode,n}finally{this.cleanupCancellation()}}async*logs(){let t=await this.resultPromise;t.stdout&&(yield{type:"stdout",data:t.stdout,timestamp:new Date}),t.stderr&&(yield{type:"stderr",data:t.stderr,timestamp:new Date})}async wait(){return await this.resultPromise,this}async output(){let t=await this.resultPromise;return t.stdout+t.stderr}async stdout(){return(await this.resultPromise).stdout}async stderr(){return(await this.resultPromise).stderr}async kill(){this.abortController.abort(new Error("command killed"))}};var ii=class e{bashEnv;timeoutMs;constructor(t,n){this.bashEnv=t,this.timeoutMs=n}static async create(t){let n=t?.fs;if(t?.overlayRoot){if(t?.fs)throw new Error("Cannot specify both 'fs' and 'overlayRoot' options");n=new tr({root:t.overlayRoot})}let r=new Tr({env:t?.env,cwd:t?.cwd,fs:n,maxCallDepth:t?.maxCallDepth,maxCommandCount:t?.maxCommandCount,maxLoopIterations:t?.maxLoopIterations,network:t?.network,defenseInDepth:t?.defenseInDepth,python:t?.python,javascript:t?.javascript,commands:t?.commands,customCommands:t?.customCommands,fetch:t?.fetch});return new e(r,t?.timeoutMs)}async runCommand(t,n,r){let s,i,o,a,l=!1,c,u;if(typeof t=="object"){let m=t,y=[m.cmd,...m.args??[]];s=ui(y),i=m.cwd,o=m.env,a=m.signal,l=m.detached??!1,c=m.stdout,u=m.stderr}else if(Array.isArray(n)){let m=r;s=ui([t,...n]),a=m?.signal}else{s=t;let m=n;i=m?.cwd,o=m?.env}let f=i??this.bashEnv.getCwd(),d=i!==void 0,h=new nr(this.bashEnv,s,f,o,d,a,this.timeoutMs);if(l)return h;let p=await h.wait();if(c){let m=await h.stdout();m&&c.write(m)}if(u){let m=await h.stderr();m&&u.write(m)}return p}async writeFiles(t){let n=this.bashEnv.getCwd();for(let[r,s]of Object.entries(t)){let i;typeof s=="string"?i=s:s.encoding==="base64"?i=Buffer.from(s.content,"base64").toString("utf-8"):i=s.content;let o=this.bashEnv.fs.resolvePath(n,r),a=o.substring(0,o.lastIndexOf("/"))||"/";a!=="/"&&await this.bashEnv.fs.mkdir(a,{recursive:!0}),await this.bashEnv.writeFile(o,i)}}async readFile(t,n){let r=await this.bashEnv.readFile(t);return n==="base64"?Buffer.from(r).toString("base64"):r}async mkDir(t,n){let r=this.bashEnv.fs.resolvePath(this.bashEnv.getCwd(),t);await this.bashEnv.fs.mkdir(r,{recursive:n?.recursive??!1})}async stop(){}async extendTimeout(t){}get domain(){}get bashEnvInstance(){return this.bashEnv}};var oi=class{violations=[];violationsByType=new Map;options;constructor(t={}){this.options={maxViolationsPerType:t.maxViolationsPerType??100,maxViolationsTotal:t.maxViolationsTotal??1e3,includeStackTraces:t.includeStackTraces??!0,onViolation:t.onViolation??(()=>{}),logToConsole:t.logToConsole??!1}}record(t){let n=this.options.includeStackTraces?t:{...t,stack:void 0};this.violations.unshift(n),this.violations.length>this.options.maxViolationsTotal&&(this.violations.length=this.options.maxViolationsTotal);let r=this.violationsByType.get(t.type);r||(r=[],this.violationsByType.set(t.type,r)),r.length<this.options.maxViolationsPerType&&r.push(n),this.options.logToConsole&&console.warn(`[SecurityViolation] ${t.type}: ${t.message}`,t.path),this.options.onViolation(n)}getViolations(){return[...this.violations]}getViolationsByType(t){return[...this.violationsByType.get(t)??[]]}getSummary(){let t=[];for(let[n,r]of this.violationsByType){if(r.length===0)continue;let s=new Set,i=Number.POSITIVE_INFINITY,o=0;for(let a of r)s.add(a.path),i=Math.min(i,a.timestamp),o=Math.max(o,a.timestamp);t.push({type:n,count:r.length,firstSeen:i,lastSeen:o,paths:Array.from(s)})}return t.sort((n,r)=>r.count-n.count),t}getTotalCount(){return this.violations.length}hasViolations(){return this.violations.length>0}clear(){this.violations=[],this.violationsByType.clear()}createCallback(){return t=>this.record(t)}};function Yf(){return e=>{console.warn("[DefenseInDepth] Security violation detected:",`
810
812
  Type: ${e.type}`,`
811
813
  Path: ${e.path}`,`
812
814
  Message: ${e.message}`,e.executionId?`
813
- ExecutionId: ${e.executionId}`:"")}}var Hf=null;try{let e=process.getBuiltinModule,t=typeof e=="function"?e("module"):typeof ri=="function"?ri("node:module"):null;Hf=t?.Module??t?.default??null,typeof e=="function"&&e("worker_threads")?.isMainThread===!1&&e("crypto")?.randomUUID?.()}catch{Hf=null}var Aa=class{maxSourceBytes;plugins=[];constructor(t=67108864){if(this.maxSourceBytes=t,!Number.isSafeInteger(t)||t<0)throw new Error("BashTransformPipeline: invalid maxSourceBytes")}use(t){return this.plugins.push(t),this}transform(t){Dr(t,this.maxSourceBytes);let n=He(t),r=Object.create(null);for(let s of this.plugins){let i=s.transform({ast:n,metadata:r});n=i.ast,i.metadata&&(r=ar(r,i.metadata))}return{script:mr(n),ast:n,metadata:r}}};var va=class{name="command-collector";transform(t){let n=new Set;return this.walkScript(t.ast,n),{ast:t.ast,metadata:{commands:[...n].sort()}}}walkScript(t,n){for(let r of t.statements)this.walkStatement(r,n)}walkStatement(t,n){for(let r of t.pipelines)this.walkPipeline(r,n)}walkPipeline(t,n){for(let r of t.commands)this.walkCommand(r,n)}walkCommand(t,n){switch(t.type){case"SimpleCommand":if(t.name){let r=this.extractName(t.name);r&&n.add(r)}t.name&&this.walkWordParts(t.name.parts,n);for(let r of t.args)this.walkWordParts(r.parts,n);for(let r of t.assignments)if(r.value&&this.walkWordParts(r.value.parts,n),r.array)for(let s of r.array)this.walkWordParts(s.parts,n);break;case"If":for(let r of t.clauses){for(let s of r.condition)this.walkStatement(s,n);for(let s of r.body)this.walkStatement(s,n)}if(t.elseBody)for(let r of t.elseBody)this.walkStatement(r,n);break;case"For":if(t.words)for(let r of t.words)this.walkWordParts(r.parts,n);for(let r of t.body)this.walkStatement(r,n);break;case"CStyleFor":for(let r of t.body)this.walkStatement(r,n);break;case"While":case"Until":for(let r of t.condition)this.walkStatement(r,n);for(let r of t.body)this.walkStatement(r,n);break;case"Case":this.walkWordParts(t.word.parts,n);for(let r of t.items)for(let s of r.body)this.walkStatement(s,n);break;case"Subshell":case"Group":for(let r of t.body)this.walkStatement(r,n);break;case"ArithmeticCommand":case"ConditionalCommand":break;case"FunctionDef":this.walkCommand(t.body,n);break}}walkWordParts(t,n){for(let r of t)switch(r.type){case"CommandSubstitution":this.walkScript(r.body,n);break;case"ProcessSubstitution":this.walkScript(r.body,n);break;case"DoubleQuoted":this.walkWordParts(r.parts,n);break;case"ParameterExpansion":r.operation&&this.walkParameterOp(r.operation,n);break}}walkParameterOp(t,n){switch(t.type){case"DefaultValue":case"AssignDefault":case"UseAlternative":this.walkWordParts(t.word.parts,n);break;case"ErrorIfUnset":t.word&&this.walkWordParts(t.word.parts,n);break;case"PatternRemoval":this.walkWordParts(t.pattern.parts,n);break;case"PatternReplacement":this.walkWordParts(t.pattern.parts,n),t.replacement&&this.walkWordParts(t.replacement.parts,n);break;case"CaseModification":t.pattern&&this.walkWordParts(t.pattern.parts,n);break;case"Indirection":t.innerOp&&this.walkParameterOp(t.innerOp,n);break}}extractName(t){return t.parts.length===1&&t.parts[0].type==="Literal"?t.parts[0].value:null}};var ka=class{name="tee";options;counter=0;constructor(t){this.options=t}transform(t){let n=[],r=this.options.timestamp??new Date;return{ast:this.transformScript(t.ast,n,r),metadata:{teeFiles:n}}}formatTimestamp(t){return t.toISOString().replace(/:/g,"-")}generateStdoutPath(t,n,r){let s=this.formatTimestamp(r),i=String(t).padStart(3,"0");if(z(this.options.outputDir,"create tee output"),!this.options.outputDir.startsWith("/")||this.options.outputDir.split("/").includes(".."))throw new Error("tee output directory must be an absolute safe path");let o=W(this.options.outputDir),a=this.encodeCommandName(n),l=W(`${o}/${s}-${i}-${a}.stdout.txt`);if(o!=="/"&&!l.startsWith(`${o}/`))throw new Error("tee output path escapes configured output directory");return l}encodeCommandName(t){if(/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(t))return t;let n=2166136261;for(let s=0;s<t.length;s++)n^=t.charCodeAt(s),n=Math.imul(n,16777619)>>>0;return`${t.replace(/[^A-Za-z0-9_-]/g,"_").replace(/^_+|_+$/g,"").slice(0,32)||"command"}-${n.toString(16).padStart(8,"0")}`}transformScript(t,n,r){return{...t,statements:t.statements.map(s=>this.transformStatement(s,n,r))}}transformStatement(t,n,r){let s=[],i=[];for(let o=0;o<t.pipelines.length;o++){let a=t.pipelines[o];o>0&&i.push(t.operators[o-1]);let l=this.transformPipeline(a,n,r);s.push(l.pipeline),l.origCmdNewIndices!==null&&(i.push(";"),s.push(this.makePipestatusRestore(l.origCmdNewIndices,l.negated)))}return{...t,pipelines:s,operators:i}}transformPipeline(t,n,r){if(t.commands.length<=1)return{pipeline:t,origCmdNewIndices:null,negated:!1};let s=[],i=[],o=[],a=!1;for(let l=0;l<t.commands.length;l++){let c=t.commands[l],u=l===t.commands.length-1;if(c.type!=="SimpleCommand"||!c.name||!this.shouldTarget(c)){o.push(s.length),s.push(c),u||i.push(t.pipeStderr?.[l]??!1);continue}let f=this.getCommandName(c.name)??"unknown",d=this.counter++,h=this.generateStdoutPath(d,f,r),p=this.makeTeeCommand(h),m=this.serializeCommand(c);n.push({commandIndex:d,commandName:f,command:m,stdoutFile:h}),o.push(s.length),s.push(c),i.push(t.pipeStderr?.[l]??!1),s.push(p),u||i.push(!1),a=!0}return a?{pipeline:{...t,negated:!1,commands:s,pipeStderr:i.length>0?i:void 0},origCmdNewIndices:o,negated:t.negated}:{pipeline:t,origCmdNewIndices:null,negated:!1}}makePipestatusRestore(t,n){return{type:"Pipeline",commands:[{type:"SimpleCommand",assignments:[],name:{type:"Word",parts:[{type:"Literal",value:"builtin"}]},args:[{type:"Word",parts:[{type:"Literal",value:"__just_bash_tee_restore"}]},...t.map(r=>({type:"Word",parts:[{type:"ParameterExpansion",parameter:`PIPESTATUS[${r}]`,operation:null}]}))],redirections:[]}],negated:n}}shouldTarget(t){if(!this.options.targetCommandPattern)return!0;let n=this.getCommandName(t.name);return n!==null&&this.options.targetCommandPattern.test(n)}getCommandName(t){return t&&t.parts.length===1&&t.parts[0].type==="Literal"?t.parts[0].value:null}serializeCommand(t){let n=[];t.name&&n.push(we(t.name));for(let r of t.args)n.push(we(r));return n.join(" ")}makeTeeCommand(t){return{type:"SimpleCommand",assignments:[],name:{type:"Word",parts:[{type:"Literal",value:"tee"}]},args:[{type:"Word",parts:[{type:"Literal",value:t}]}],redirections:[]}}};export{Ir as Bash,Aa as BashTransformPipeline,va as CommandCollectorPlugin,Ce as DefenseInDepthBox,si as EMPTY_BYTES,gt as InMemoryFs,Kt as MountableFs,ft as NetworkAccessDeniedError,er as OverlayFs,ei as ReadWriteFs,Vt as RedirectNotAllowedError,ti as Sandbox,tr as SandboxCommand,zt as SecurityViolationError,ni as SecurityViolationLogger,ka as TeePlugin,Rn as TooManyRedirectsError,Yf as bytesOutput,sd as createCommandContext,Gf as createConsoleViolationCallback,Qf as decodeBytesToUtf8,id as defineCommand,Ut as encodeUtf8ToBytes,Jf as getCommandNames,nd as getJavaScriptCommandNames,ed as getNetworkCommandNames,td as getPythonCommandNames,wn as latin1FromBytes,He as parse,mr as serialize,_t as stdoutAsBytes,Kf as stdoutKind,Xf as textOutput,sr as unsafeBytesFromLatin1};
815
+ ExecutionId: ${e.executionId}`:"")}}var Jf=null;try{let e=process.getBuiltinModule,t=typeof e=="function"?e("module"):typeof ai=="function"?ai("node:module"):null;Jf=t?.Module??t?.default??null,typeof e=="function"&&e("worker_threads")?.isMainThread===!1&&e("crypto")?.randomUUID?.()}catch{Jf=null}var xa=class{maxSourceBytes;plugins=[];constructor(t=67108864){if(this.maxSourceBytes=t,!Number.isSafeInteger(t)||t<0)throw new Error("BashTransformPipeline: invalid maxSourceBytes")}use(t){return this.plugins.push(t),this}transform(t){_r(t,this.maxSourceBytes);let n=He(t),r=Object.create(null);for(let s of this.plugins){let i=s.transform({ast:n,metadata:r});n=i.ast,i.metadata&&(r=lr(r,i.metadata))}return{script:yr(n),ast:n,metadata:r}}};var Pa=class{name="command-collector";transform(t){let n=new Set;return this.walkScript(t.ast,n),{ast:t.ast,metadata:{commands:[...n].sort()}}}walkScript(t,n){for(let r of t.statements)this.walkStatement(r,n)}walkStatement(t,n){for(let r of t.pipelines)this.walkPipeline(r,n)}walkPipeline(t,n){for(let r of t.commands)this.walkCommand(r,n)}walkCommand(t,n){switch(t.type){case"SimpleCommand":if(t.name){let r=this.extractName(t.name);r&&n.add(r)}t.name&&this.walkWordParts(t.name.parts,n);for(let r of t.args)this.walkWordParts(r.parts,n);for(let r of t.assignments)if(r.value&&this.walkWordParts(r.value.parts,n),r.array)for(let s of r.array)this.walkWordParts(s.parts,n);break;case"If":for(let r of t.clauses){for(let s of r.condition)this.walkStatement(s,n);for(let s of r.body)this.walkStatement(s,n)}if(t.elseBody)for(let r of t.elseBody)this.walkStatement(r,n);break;case"For":if(t.words)for(let r of t.words)this.walkWordParts(r.parts,n);for(let r of t.body)this.walkStatement(r,n);break;case"CStyleFor":for(let r of t.body)this.walkStatement(r,n);break;case"While":case"Until":for(let r of t.condition)this.walkStatement(r,n);for(let r of t.body)this.walkStatement(r,n);break;case"Case":this.walkWordParts(t.word.parts,n);for(let r of t.items)for(let s of r.body)this.walkStatement(s,n);break;case"Subshell":case"Group":for(let r of t.body)this.walkStatement(r,n);break;case"ArithmeticCommand":case"ConditionalCommand":break;case"FunctionDef":this.walkCommand(t.body,n);break}}walkWordParts(t,n){for(let r of t)switch(r.type){case"CommandSubstitution":this.walkScript(r.body,n);break;case"ProcessSubstitution":this.walkScript(r.body,n);break;case"DoubleQuoted":this.walkWordParts(r.parts,n);break;case"ParameterExpansion":r.operation&&this.walkParameterOp(r.operation,n);break}}walkParameterOp(t,n){switch(t.type){case"DefaultValue":case"AssignDefault":case"UseAlternative":this.walkWordParts(t.word.parts,n);break;case"ErrorIfUnset":t.word&&this.walkWordParts(t.word.parts,n);break;case"PatternRemoval":this.walkWordParts(t.pattern.parts,n);break;case"PatternReplacement":this.walkWordParts(t.pattern.parts,n),t.replacement&&this.walkWordParts(t.replacement.parts,n);break;case"CaseModification":t.pattern&&this.walkWordParts(t.pattern.parts,n);break;case"Indirection":t.innerOp&&this.walkParameterOp(t.innerOp,n);break}}extractName(t){return t.parts.length===1&&t.parts[0].type==="Literal"?t.parts[0].value:null}};var $a=class{name="tee";options;counter=0;constructor(t){this.options=t}transform(t){let n=[],r=this.options.timestamp??new Date;return{ast:this.transformScript(t.ast,n,r),metadata:{teeFiles:n}}}formatTimestamp(t){return t.toISOString().replace(/:/g,"-")}generateStdoutPath(t,n,r){let s=this.formatTimestamp(r),i=String(t).padStart(3,"0");if(q(this.options.outputDir,"create tee output"),!this.options.outputDir.startsWith("/")||this.options.outputDir.split("/").includes(".."))throw new Error("tee output directory must be an absolute safe path");let o=j(this.options.outputDir),a=this.encodeCommandName(n),l=j(`${o}/${s}-${i}-${a}.stdout.txt`);if(o!=="/"&&!l.startsWith(`${o}/`))throw new Error("tee output path escapes configured output directory");return l}encodeCommandName(t){if(/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(t))return t;let n=2166136261;for(let s=0;s<t.length;s++)n^=t.charCodeAt(s),n=Math.imul(n,16777619)>>>0;return`${t.replace(/[^A-Za-z0-9_-]/g,"_").replace(/^_+|_+$/g,"").slice(0,32)||"command"}-${n.toString(16).padStart(8,"0")}`}transformScript(t,n,r){return{...t,statements:t.statements.map(s=>this.transformStatement(s,n,r))}}transformStatement(t,n,r){let s=[],i=[];for(let o=0;o<t.pipelines.length;o++){let a=t.pipelines[o];o>0&&i.push(t.operators[o-1]);let l=this.transformPipeline(a,n,r);s.push(l.pipeline),l.origCmdNewIndices!==null&&(i.push(";"),s.push(this.makePipestatusRestore(l.origCmdNewIndices,l.negated)))}return{...t,pipelines:s,operators:i}}transformPipeline(t,n,r){if(t.commands.length<=1)return{pipeline:t,origCmdNewIndices:null,negated:!1};let s=[],i=[],o=[],a=!1;for(let l=0;l<t.commands.length;l++){let c=t.commands[l],u=l===t.commands.length-1;if(c.type!=="SimpleCommand"||!c.name||!this.shouldTarget(c)){o.push(s.length),s.push(c),u||i.push(t.pipeStderr?.[l]??!1);continue}let f=this.getCommandName(c.name)??"unknown",d=this.counter++,h=this.generateStdoutPath(d,f,r),p=this.makeTeeCommand(h),m=this.serializeCommand(c);n.push({commandIndex:d,commandName:f,command:m,stdoutFile:h}),o.push(s.length),s.push(c),i.push(t.pipeStderr?.[l]??!1),s.push(p),u||i.push(!1),a=!0}return a?{pipeline:{...t,negated:!1,commands:s,pipeStderr:i.length>0?i:void 0},origCmdNewIndices:o,negated:t.negated}:{pipeline:t,origCmdNewIndices:null,negated:!1}}makePipestatusRestore(t,n){return{type:"Pipeline",commands:[{type:"SimpleCommand",assignments:[],name:{type:"Word",parts:[{type:"Literal",value:"builtin"}]},args:[{type:"Word",parts:[{type:"Literal",value:"__just_bash_tee_restore"}]},...t.map(r=>({type:"Word",parts:[{type:"ParameterExpansion",parameter:`PIPESTATUS[${r}]`,operation:null}]}))],redirections:[]}],negated:n}}shouldTarget(t){if(!this.options.targetCommandPattern)return!0;let n=this.getCommandName(t.name);return n!==null&&this.options.targetCommandPattern.test(n)}getCommandName(t){return t&&t.parts.length===1&&t.parts[0].type==="Literal"?t.parts[0].value:null}serializeCommand(t){let n=[];t.name&&n.push(we(t.name));for(let r of t.args)n.push(we(r));return n.join(" ")}makeTeeCommand(t){return{type:"SimpleCommand",assignments:[],name:{type:"Word",parts:[{type:"Literal",value:"tee"}]},args:[{type:"Word",parts:[{type:"Literal",value:t}]}],redirections:[]}}};export{Tr as Bash,xa as BashTransformPipeline,Pa as CommandCollectorPlugin,Ce as DefenseInDepthBox,li as EMPTY_BYTES,yt as InMemoryFs,Kt as MountableFs,ut as NetworkAccessDeniedError,tr as OverlayFs,si as ReadWriteFs,Vt as RedirectNotAllowedError,ii as Sandbox,nr as SandboxCommand,zt as SecurityViolationError,oi as SecurityViolationLogger,$a as TeePlugin,On as TooManyRedirectsError,sd as bytesOutput,ud as createCommandContext,Yf as createConsoleViolationCallback,td as decodeBytesToUtf8,fd as defineCommand,Ut as encodeUtf8ToBytes,id as getCommandNames,ld as getJavaScriptCommandNames,od as getNetworkCommandNames,ad as getPythonCommandNames,wn as latin1FromBytes,He as parse,yr as serialize,_t as stdoutAsBytes,nd as stdoutKind,rd as textOutput,ir as unsafeBytesFromLatin1};