just-bash 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1160) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +72 -9
  3. package/dist/Bash.d.ts +12 -4
  4. package/dist/abort-signals.d.ts +10 -0
  5. package/dist/bin/chunks/alias-3R4G6HQY.js +3 -0
  6. package/dist/bin/chunks/awk2-7UZLEPVX.js +3 -0
  7. package/dist/bin/chunks/base64-W6FVFNXJ.js +3 -0
  8. package/dist/bin/chunks/basename-C4CRGDXP.js +3 -0
  9. package/dist/bin/chunks/bash-CFCBBWVH.js +3 -0
  10. package/dist/bin/chunks/cat-5YECZSFQ.js +3 -0
  11. package/dist/bin/chunks/chmod-45TMYSW2.js +3 -0
  12. package/dist/bin/chunks/chunk-23OI2XDJ.js +20 -0
  13. package/dist/bin/chunks/chunk-2OQ5HPZE.js +7 -0
  14. package/dist/bin/chunks/chunk-2YLY6FJA.js +10 -0
  15. package/dist/bin/chunks/chunk-3HUI54BW.js +143 -0
  16. package/dist/bin/chunks/chunk-3OYRDLJJ.js +101 -0
  17. package/dist/bin/chunks/chunk-3PCPQIUD.js +3 -0
  18. package/dist/bin/chunks/chunk-3VSWQCPN.js +18 -0
  19. package/dist/bin/chunks/chunk-43E7AR6A.js +3 -0
  20. package/dist/bin/chunks/chunk-46CDVHZ3.js +5 -0
  21. package/dist/bin/chunks/chunk-4SQKKW2M.js +3 -0
  22. package/dist/bin/chunks/chunk-5SKEZPTU.js +12 -0
  23. package/dist/bin/chunks/chunk-6D75E4LV.js +3 -0
  24. package/dist/bin/chunks/chunk-6SAZRW7E.js +15 -0
  25. package/dist/bin/chunks/chunk-7FGDUBSN.js +14 -0
  26. package/dist/bin/chunks/chunk-7I6MNC5I.js +3 -0
  27. package/dist/bin/chunks/chunk-B7RRNV3A.js +22 -0
  28. package/dist/bin/chunks/chunk-BCJ42NCM.js +15 -0
  29. package/dist/bin/chunks/chunk-BNYIXXC2.js +3 -0
  30. package/dist/bin/chunks/chunk-BPWZ7ADB.js +8 -0
  31. package/dist/bin/chunks/chunk-BWRQ5HYX.js +9 -0
  32. package/dist/bin/chunks/chunk-CB4SODHK.js +34 -0
  33. package/dist/bin/chunks/chunk-CC2AQ6B7.js +15 -0
  34. package/dist/bin/chunks/chunk-CPKBPQ2C.js +3 -0
  35. package/dist/bin/chunks/chunk-CPTQXTBJ.js +3 -0
  36. package/dist/bin/chunks/chunk-D3MUBZ4P.js +65 -0
  37. package/dist/bin/chunks/chunk-DN2YCFOR.js +3 -0
  38. package/dist/bin/chunks/chunk-DSZQ22OX.js +12 -0
  39. package/dist/bin/chunks/chunk-E5VZGTZ6.js +10 -0
  40. package/dist/bin/chunks/chunk-ETWDDV6I.js +10 -0
  41. package/dist/bin/chunks/chunk-GEUCQ4AB.js +10 -0
  42. package/dist/bin/chunks/chunk-H4BRFPKY.js +3 -0
  43. package/dist/bin/chunks/chunk-IAAPXDHN.js +11 -0
  44. package/dist/bin/chunks/chunk-ISW2U76N.js +17 -0
  45. package/dist/bin/chunks/chunk-JQER3HUP.js +20 -0
  46. package/dist/bin/chunks/chunk-K5KT6DMM.js +4 -0
  47. package/dist/bin/chunks/chunk-KG2KXL4Y.js +3 -0
  48. package/dist/bin/chunks/chunk-LCP3IKI7.js +9 -0
  49. package/dist/bin/chunks/chunk-LGERQ5TD.js +22 -0
  50. package/dist/bin/chunks/chunk-LNFTLSWJ.js +22 -0
  51. package/dist/bin/chunks/chunk-LUHU7UUN.js +7 -0
  52. package/dist/bin/chunks/chunk-LXFMIXGA.js +3 -0
  53. package/dist/bin/chunks/chunk-MYTNZ7MA.js +7 -0
  54. package/dist/bin/chunks/chunk-MZM7RVYU.js +8 -0
  55. package/dist/bin/chunks/chunk-NGD6G5ZG.js +9 -0
  56. package/dist/bin/chunks/chunk-NJ67YJRE.js +6 -0
  57. package/dist/bin/chunks/chunk-NQQ3X7MZ.js +36 -0
  58. package/dist/bin/chunks/chunk-O74FSWB4.js +4 -0
  59. package/dist/bin/chunks/chunk-OKU677H3.js +87 -0
  60. package/dist/bin/chunks/chunk-P6NPCASY.js +11 -0
  61. package/dist/bin/chunks/chunk-PKWK3LQM.js +22 -0
  62. package/dist/bin/chunks/chunk-PQPFDJFF.js +34 -0
  63. package/dist/bin/chunks/chunk-PRKSLEHG.js +291 -0
  64. package/dist/bin/chunks/chunk-PUZGSIMN.js +15 -0
  65. package/dist/bin/chunks/chunk-Q3LE3Y66.js +13 -0
  66. package/dist/bin/chunks/chunk-QAYU7HPM.js +7 -0
  67. package/dist/bin/chunks/chunk-QES5OSUC.js +3 -0
  68. package/dist/bin/chunks/chunk-QF7PPON7.js +16 -0
  69. package/dist/bin/chunks/chunk-QK6BXSHU.js +13 -0
  70. package/dist/bin/chunks/chunk-RYQB6GQ7.js +11 -0
  71. package/dist/bin/chunks/chunk-SSK3N7FN.js +3 -0
  72. package/dist/bin/chunks/chunk-TL4JI2SL.js +38 -0
  73. package/dist/bin/chunks/chunk-TPU3OX2A.js +3 -0
  74. package/dist/bin/chunks/chunk-TW2IJRUF.js +3 -0
  75. package/dist/bin/chunks/chunk-TZ3S7MY6.js +12 -0
  76. package/dist/bin/chunks/chunk-VGR3NA3H.js +13 -0
  77. package/dist/bin/chunks/chunk-VLWZ6L7C.js +4 -0
  78. package/dist/bin/chunks/chunk-VTAIIBJT.js +16 -0
  79. package/dist/bin/chunks/chunk-VTHA5UK5.js +7 -0
  80. package/dist/bin/chunks/chunk-VY2K25J4.js +16 -0
  81. package/dist/bin/chunks/chunk-W4U4QOZF.js +7 -0
  82. package/dist/bin/chunks/chunk-WDV2ECOC.js +3 -0
  83. package/dist/bin/chunks/chunk-WFVCEB5T.js +3 -0
  84. package/dist/bin/chunks/chunk-WSLBBXPJ.js +12 -0
  85. package/dist/bin/chunks/chunk-WWOUFMMY.js +3 -0
  86. package/dist/bin/chunks/chunk-WYTPLN2M.js +11 -0
  87. package/dist/bin/chunks/chunk-X5VUGFUL.js +3 -0
  88. package/dist/bin/chunks/chunk-X63MJBLH.js +26 -0
  89. package/dist/bin/chunks/chunk-XAAXPEOP.js +6 -0
  90. package/dist/bin/chunks/chunk-XEQ7KSRM.js +5 -0
  91. package/dist/bin/chunks/chunk-YIANER7Y.js +8 -0
  92. package/dist/bin/chunks/chunk-YMELOXDK.js +13 -0
  93. package/dist/bin/chunks/chunk-YTL6DXBO.js +11 -0
  94. package/dist/bin/chunks/chunk-YYZSYLJO.js +6 -0
  95. package/dist/bin/chunks/chunk-ZXIW4JPL.js +22 -0
  96. package/dist/bin/chunks/clear-OE52K3TM.js +3 -0
  97. package/dist/bin/chunks/column-7VBJL757.js +3 -0
  98. package/dist/bin/chunks/comm-URDMZCXL.js +3 -0
  99. package/dist/bin/chunks/cp-MF5GADQN.js +3 -0
  100. package/dist/bin/chunks/curl-FS5LAEYI.js +30 -0
  101. package/dist/bin/chunks/cut-QOTYBJJJ.js +3 -0
  102. package/dist/bin/chunks/date-FJUBX7TJ.js +3 -0
  103. package/dist/bin/chunks/diff-YXZZCUSQ.js +3 -0
  104. package/dist/bin/chunks/dirname-TPUFCYF6.js +3 -0
  105. package/dist/bin/chunks/du-A3UGHIKJ.js +3 -0
  106. package/dist/bin/chunks/echo-4OUEL7QB.js +3 -0
  107. package/dist/bin/chunks/env-2TSVF4W7.js +3 -0
  108. package/dist/bin/chunks/expand-P6SNTBGZ.js +3 -0
  109. package/dist/bin/chunks/expr-56X7LYOS.js +3 -0
  110. package/dist/bin/chunks/file-SQSOBJLR.js +3 -0
  111. package/dist/bin/chunks/find-XY2NTAT5.js +3 -0
  112. package/dist/bin/chunks/flag-coverage-WGSE667D.js +3 -0
  113. package/dist/bin/chunks/fold-YEY7X54W.js +3 -0
  114. package/dist/bin/chunks/grep-CMT2H2S7.js +3 -0
  115. package/dist/bin/chunks/gzip-DJSFJOY6.js +3 -0
  116. package/dist/bin/chunks/head-KPRH4HKC.js +3 -0
  117. package/dist/bin/chunks/help-HVIDHJ6M.js +3 -0
  118. package/dist/bin/chunks/history-3HAU45KT.js +3 -0
  119. package/dist/bin/chunks/hostname-2I76DUQL.js +3 -0
  120. package/dist/bin/chunks/html-to-markdown-WUBAMB4O.js +3 -0
  121. package/dist/bin/chunks/join-UQKXU2QP.js +3 -0
  122. package/dist/bin/chunks/jq-ACCMBTSD.js +3 -0
  123. package/dist/bin/chunks/js-exec-4KNUPGHA.js +99 -0
  124. package/dist/bin/chunks/js-exec-worker.js +187 -110
  125. package/dist/bin/chunks/ln-XSDIE6SU.js +3 -0
  126. package/dist/bin/chunks/ls-FTHYNINH.js +3 -0
  127. package/dist/bin/chunks/md5sum-Z6KAYGDK.js +3 -0
  128. package/dist/bin/chunks/mkdir-74BP5NTG.js +3 -0
  129. package/dist/bin/chunks/mv-YG75IRRE.js +3 -0
  130. package/dist/bin/chunks/nl-XHWFVVKH.js +3 -0
  131. package/dist/bin/chunks/od-A7CW5RMS.js +3 -0
  132. package/dist/bin/chunks/paste-YJLYVJMP.js +3 -0
  133. package/dist/bin/chunks/printf-F2KOCULO.js +3 -0
  134. package/dist/bin/chunks/pwd-YKLNXWZI.js +3 -0
  135. package/dist/bin/chunks/python3-AYUQQRCR.js +14 -0
  136. package/dist/bin/chunks/readlink-HMHVGSAM.js +3 -0
  137. package/dist/bin/chunks/rev-CZTQCNOZ.js +3 -0
  138. package/dist/bin/chunks/rg-JRKJ6I4X.js +3 -0
  139. package/dist/bin/chunks/rm-3PLW4O4B.js +3 -0
  140. package/dist/bin/chunks/rmdir-DCJ3XJRR.js +3 -0
  141. package/dist/bin/chunks/sed-QJ2LNV2N.js +3 -0
  142. package/dist/bin/chunks/seq-Q4LZ6EXV.js +3 -0
  143. package/dist/bin/chunks/sha1sum-CATBXX76.js +3 -0
  144. package/dist/bin/chunks/sha256sum-YGSNBVY3.js +3 -0
  145. package/dist/bin/chunks/sleep-FUDWGDCE.js +3 -0
  146. package/dist/bin/chunks/sort-M3DO25D5.js +3 -0
  147. package/dist/bin/chunks/split-7IYQYKOW.js +3 -0
  148. package/dist/bin/chunks/sqlite3-ZXF6BGDW.js +3 -0
  149. package/dist/bin/chunks/sqlite3-worker.js +316 -173
  150. package/dist/bin/chunks/stat-Y5D3VPLG.js +3 -0
  151. package/dist/bin/chunks/strings-J2X2Z6N2.js +3 -0
  152. package/dist/bin/chunks/tac-DG4BMYM5.js +3 -0
  153. package/dist/bin/chunks/tail-QISQLA3I.js +3 -0
  154. package/dist/bin/chunks/tar-TB2XWXF6.js +3 -0
  155. package/dist/bin/chunks/tee-L4HKV5PD.js +3 -0
  156. package/dist/bin/chunks/time-LF7BTSK5.js +3 -0
  157. package/dist/bin/chunks/timeout-TDOV6JDA.js +3 -0
  158. package/dist/bin/chunks/touch-TVQAUQOG.js +3 -0
  159. package/dist/bin/chunks/tr-AR6EK7JH.js +3 -0
  160. package/dist/bin/chunks/tree-ZGP6NPGS.js +3 -0
  161. package/dist/bin/chunks/true-KFTJGQLQ.js +3 -0
  162. package/dist/bin/chunks/undici-JES22UVU.js +141 -0
  163. package/dist/bin/chunks/unexpand-JPOQORZF.js +3 -0
  164. package/dist/bin/chunks/uniq-K5VRDP4Q.js +3 -0
  165. package/dist/bin/chunks/wc-VSQBRD6B.js +3 -0
  166. package/dist/bin/chunks/which-4TPGVSBZ.js +3 -0
  167. package/dist/bin/chunks/whoami-B5HDVKW6.js +3 -0
  168. package/dist/bin/chunks/worker.js +212 -105
  169. package/dist/bin/chunks/xan-D6US4ZGL.js +3 -0
  170. package/dist/bin/chunks/xan-view-QGKWT354.js +3 -0
  171. package/dist/bin/chunks/xargs-HMISWW4I.js +3 -0
  172. package/dist/bin/chunks/yq-EYV7HLKK.js +3 -0
  173. package/dist/bin/just-bash.js +412 -387
  174. package/dist/bin/shell/chunks/alias-3R4G6HQY.js +3 -0
  175. package/dist/bin/shell/chunks/awk2-7UZLEPVX.js +3 -0
  176. package/dist/bin/shell/chunks/base64-W6FVFNXJ.js +3 -0
  177. package/dist/bin/shell/chunks/basename-C4CRGDXP.js +3 -0
  178. package/dist/bin/shell/chunks/bash-CFCBBWVH.js +3 -0
  179. package/dist/bin/shell/chunks/cat-5YECZSFQ.js +3 -0
  180. package/dist/bin/shell/chunks/chmod-45TMYSW2.js +3 -0
  181. package/dist/bin/shell/chunks/chunk-23OI2XDJ.js +20 -0
  182. package/dist/bin/shell/chunks/chunk-2OQ5HPZE.js +7 -0
  183. package/dist/bin/shell/chunks/chunk-2YLY6FJA.js +10 -0
  184. package/dist/bin/shell/chunks/chunk-3HUI54BW.js +143 -0
  185. package/dist/bin/shell/chunks/chunk-3OYRDLJJ.js +101 -0
  186. package/dist/bin/shell/chunks/chunk-3PCPQIUD.js +3 -0
  187. package/dist/bin/shell/chunks/chunk-3VSWQCPN.js +18 -0
  188. package/dist/bin/shell/chunks/chunk-43E7AR6A.js +3 -0
  189. package/dist/bin/shell/chunks/chunk-46CDVHZ3.js +5 -0
  190. package/dist/bin/shell/chunks/chunk-4SQKKW2M.js +3 -0
  191. package/dist/bin/shell/chunks/chunk-5SKEZPTU.js +12 -0
  192. package/dist/bin/shell/chunks/chunk-6D75E4LV.js +3 -0
  193. package/dist/bin/shell/chunks/chunk-6SAZRW7E.js +15 -0
  194. package/dist/bin/shell/chunks/chunk-7FGDUBSN.js +14 -0
  195. package/dist/bin/shell/chunks/chunk-7I6MNC5I.js +3 -0
  196. package/dist/bin/shell/chunks/chunk-B7RRNV3A.js +22 -0
  197. package/dist/bin/shell/chunks/chunk-BCJ42NCM.js +15 -0
  198. package/dist/bin/shell/chunks/chunk-BNYIXXC2.js +3 -0
  199. package/dist/bin/shell/chunks/chunk-BPWZ7ADB.js +8 -0
  200. package/dist/bin/shell/chunks/chunk-BWRQ5HYX.js +9 -0
  201. package/dist/bin/shell/chunks/chunk-CB4SODHK.js +34 -0
  202. package/dist/bin/shell/chunks/chunk-CC2AQ6B7.js +15 -0
  203. package/dist/bin/shell/chunks/chunk-CPKBPQ2C.js +3 -0
  204. package/dist/bin/shell/chunks/chunk-CPTQXTBJ.js +3 -0
  205. package/dist/bin/shell/chunks/chunk-D3MUBZ4P.js +65 -0
  206. package/dist/bin/shell/chunks/chunk-DN2YCFOR.js +3 -0
  207. package/dist/bin/shell/chunks/chunk-DSZQ22OX.js +12 -0
  208. package/dist/bin/shell/chunks/chunk-E5VZGTZ6.js +10 -0
  209. package/dist/bin/shell/chunks/chunk-ETWDDV6I.js +10 -0
  210. package/dist/bin/shell/chunks/chunk-GEUCQ4AB.js +10 -0
  211. package/dist/bin/shell/chunks/chunk-H4BRFPKY.js +3 -0
  212. package/dist/bin/shell/chunks/chunk-IAAPXDHN.js +11 -0
  213. package/dist/bin/shell/chunks/chunk-ISW2U76N.js +17 -0
  214. package/dist/bin/shell/chunks/chunk-JQER3HUP.js +20 -0
  215. package/dist/bin/shell/chunks/chunk-K5KT6DMM.js +4 -0
  216. package/dist/bin/shell/chunks/chunk-KG2KXL4Y.js +3 -0
  217. package/dist/bin/shell/chunks/chunk-LCP3IKI7.js +9 -0
  218. package/dist/bin/shell/chunks/chunk-LGERQ5TD.js +22 -0
  219. package/dist/bin/shell/chunks/chunk-LNFTLSWJ.js +22 -0
  220. package/dist/bin/shell/chunks/chunk-LUHU7UUN.js +7 -0
  221. package/dist/bin/shell/chunks/chunk-LXFMIXGA.js +3 -0
  222. package/dist/bin/shell/chunks/chunk-MYTNZ7MA.js +7 -0
  223. package/dist/bin/shell/chunks/chunk-MZM7RVYU.js +8 -0
  224. package/dist/bin/shell/chunks/chunk-NGD6G5ZG.js +9 -0
  225. package/dist/bin/shell/chunks/chunk-NJ67YJRE.js +6 -0
  226. package/dist/bin/shell/chunks/chunk-NQQ3X7MZ.js +36 -0
  227. package/dist/bin/shell/chunks/chunk-O74FSWB4.js +4 -0
  228. package/dist/bin/shell/chunks/chunk-OKU677H3.js +87 -0
  229. package/dist/bin/shell/chunks/chunk-P6NPCASY.js +11 -0
  230. package/dist/bin/shell/chunks/chunk-PKWK3LQM.js +22 -0
  231. package/dist/bin/shell/chunks/chunk-PQPFDJFF.js +34 -0
  232. package/dist/bin/shell/chunks/chunk-PRKSLEHG.js +291 -0
  233. package/dist/bin/shell/chunks/chunk-PUZGSIMN.js +15 -0
  234. package/dist/bin/shell/chunks/chunk-Q3LE3Y66.js +13 -0
  235. package/dist/bin/shell/chunks/chunk-QAYU7HPM.js +7 -0
  236. package/dist/bin/shell/chunks/chunk-QES5OSUC.js +3 -0
  237. package/dist/bin/shell/chunks/chunk-QF7PPON7.js +16 -0
  238. package/dist/bin/shell/chunks/chunk-QK6BXSHU.js +13 -0
  239. package/dist/bin/shell/chunks/chunk-RYQB6GQ7.js +11 -0
  240. package/dist/bin/shell/chunks/chunk-SSK3N7FN.js +3 -0
  241. package/dist/bin/shell/chunks/chunk-TL4JI2SL.js +38 -0
  242. package/dist/bin/shell/chunks/chunk-TPU3OX2A.js +3 -0
  243. package/dist/bin/shell/chunks/chunk-TW2IJRUF.js +3 -0
  244. package/dist/bin/shell/chunks/chunk-TZ3S7MY6.js +12 -0
  245. package/dist/bin/shell/chunks/chunk-VGR3NA3H.js +13 -0
  246. package/dist/bin/shell/chunks/chunk-VLWZ6L7C.js +4 -0
  247. package/dist/bin/shell/chunks/chunk-VTAIIBJT.js +16 -0
  248. package/dist/bin/shell/chunks/chunk-VTHA5UK5.js +7 -0
  249. package/dist/bin/shell/chunks/chunk-VY2K25J4.js +16 -0
  250. package/dist/bin/shell/chunks/chunk-W4U4QOZF.js +7 -0
  251. package/dist/bin/shell/chunks/chunk-WDV2ECOC.js +3 -0
  252. package/dist/bin/shell/chunks/chunk-WFVCEB5T.js +3 -0
  253. package/dist/bin/shell/chunks/chunk-WSLBBXPJ.js +12 -0
  254. package/dist/bin/shell/chunks/chunk-WWOUFMMY.js +3 -0
  255. package/dist/bin/shell/chunks/chunk-WYTPLN2M.js +11 -0
  256. package/dist/bin/shell/chunks/chunk-X5VUGFUL.js +3 -0
  257. package/dist/bin/shell/chunks/chunk-X63MJBLH.js +26 -0
  258. package/dist/bin/shell/chunks/chunk-XAAXPEOP.js +6 -0
  259. package/dist/bin/shell/chunks/chunk-XEQ7KSRM.js +5 -0
  260. package/dist/bin/shell/chunks/chunk-YIANER7Y.js +8 -0
  261. package/dist/bin/shell/chunks/chunk-YMELOXDK.js +13 -0
  262. package/dist/bin/shell/chunks/chunk-YTL6DXBO.js +11 -0
  263. package/dist/bin/shell/chunks/chunk-YYZSYLJO.js +6 -0
  264. package/dist/bin/shell/chunks/chunk-ZXIW4JPL.js +22 -0
  265. package/dist/bin/shell/chunks/clear-OE52K3TM.js +3 -0
  266. package/dist/bin/shell/chunks/column-7VBJL757.js +3 -0
  267. package/dist/bin/shell/chunks/comm-URDMZCXL.js +3 -0
  268. package/dist/bin/shell/chunks/cp-MF5GADQN.js +3 -0
  269. package/dist/bin/shell/chunks/curl-FS5LAEYI.js +30 -0
  270. package/dist/bin/shell/chunks/cut-QOTYBJJJ.js +3 -0
  271. package/dist/bin/shell/chunks/date-FJUBX7TJ.js +3 -0
  272. package/dist/bin/shell/chunks/diff-YXZZCUSQ.js +3 -0
  273. package/dist/bin/shell/chunks/dirname-TPUFCYF6.js +3 -0
  274. package/dist/bin/shell/chunks/du-A3UGHIKJ.js +3 -0
  275. package/dist/bin/shell/chunks/echo-4OUEL7QB.js +3 -0
  276. package/dist/bin/shell/chunks/env-2TSVF4W7.js +3 -0
  277. package/dist/bin/shell/chunks/expand-P6SNTBGZ.js +3 -0
  278. package/dist/bin/shell/chunks/expr-56X7LYOS.js +3 -0
  279. package/dist/bin/shell/chunks/file-SQSOBJLR.js +3 -0
  280. package/dist/bin/shell/chunks/find-XY2NTAT5.js +3 -0
  281. package/dist/bin/shell/chunks/flag-coverage-WGSE667D.js +3 -0
  282. package/dist/bin/shell/chunks/fold-YEY7X54W.js +3 -0
  283. package/dist/bin/shell/chunks/grep-CMT2H2S7.js +3 -0
  284. package/dist/bin/shell/chunks/gzip-DJSFJOY6.js +3 -0
  285. package/dist/bin/shell/chunks/head-KPRH4HKC.js +3 -0
  286. package/dist/bin/shell/chunks/help-HVIDHJ6M.js +3 -0
  287. package/dist/bin/shell/chunks/history-3HAU45KT.js +3 -0
  288. package/dist/bin/shell/chunks/hostname-2I76DUQL.js +3 -0
  289. package/dist/bin/shell/chunks/html-to-markdown-WUBAMB4O.js +3 -0
  290. package/dist/bin/shell/chunks/join-UQKXU2QP.js +3 -0
  291. package/dist/bin/shell/chunks/jq-ACCMBTSD.js +3 -0
  292. package/dist/bin/shell/chunks/js-exec-4KNUPGHA.js +99 -0
  293. package/dist/bin/shell/chunks/ln-XSDIE6SU.js +3 -0
  294. package/dist/bin/shell/chunks/ls-FTHYNINH.js +3 -0
  295. package/dist/bin/shell/chunks/md5sum-Z6KAYGDK.js +3 -0
  296. package/dist/bin/shell/chunks/mkdir-74BP5NTG.js +3 -0
  297. package/dist/bin/shell/chunks/mv-YG75IRRE.js +3 -0
  298. package/dist/bin/shell/chunks/nl-XHWFVVKH.js +3 -0
  299. package/dist/bin/shell/chunks/od-A7CW5RMS.js +3 -0
  300. package/dist/bin/shell/chunks/paste-YJLYVJMP.js +3 -0
  301. package/dist/bin/shell/chunks/printf-F2KOCULO.js +3 -0
  302. package/dist/bin/shell/chunks/pwd-YKLNXWZI.js +3 -0
  303. package/dist/bin/shell/chunks/python3-AYUQQRCR.js +14 -0
  304. package/dist/bin/shell/chunks/readlink-HMHVGSAM.js +3 -0
  305. package/dist/bin/shell/chunks/rev-CZTQCNOZ.js +3 -0
  306. package/dist/bin/shell/chunks/rg-JRKJ6I4X.js +3 -0
  307. package/dist/bin/shell/chunks/rm-3PLW4O4B.js +3 -0
  308. package/dist/bin/shell/chunks/rmdir-DCJ3XJRR.js +3 -0
  309. package/dist/bin/shell/chunks/sed-QJ2LNV2N.js +3 -0
  310. package/dist/bin/shell/chunks/seq-Q4LZ6EXV.js +3 -0
  311. package/dist/bin/shell/chunks/sha1sum-CATBXX76.js +3 -0
  312. package/dist/bin/shell/chunks/sha256sum-YGSNBVY3.js +3 -0
  313. package/dist/bin/shell/chunks/sleep-FUDWGDCE.js +3 -0
  314. package/dist/bin/shell/chunks/sort-M3DO25D5.js +3 -0
  315. package/dist/bin/shell/chunks/split-7IYQYKOW.js +3 -0
  316. package/dist/bin/shell/chunks/sqlite3-ZXF6BGDW.js +3 -0
  317. package/dist/bin/shell/chunks/stat-Y5D3VPLG.js +3 -0
  318. package/dist/bin/shell/chunks/strings-J2X2Z6N2.js +3 -0
  319. package/dist/bin/shell/chunks/tac-DG4BMYM5.js +3 -0
  320. package/dist/bin/shell/chunks/tail-QISQLA3I.js +3 -0
  321. package/dist/bin/shell/chunks/tar-TB2XWXF6.js +3 -0
  322. package/dist/bin/shell/chunks/tee-L4HKV5PD.js +3 -0
  323. package/dist/bin/shell/chunks/time-LF7BTSK5.js +3 -0
  324. package/dist/bin/shell/chunks/timeout-TDOV6JDA.js +3 -0
  325. package/dist/bin/shell/chunks/touch-TVQAUQOG.js +3 -0
  326. package/dist/bin/shell/chunks/tr-AR6EK7JH.js +3 -0
  327. package/dist/bin/shell/chunks/tree-ZGP6NPGS.js +3 -0
  328. package/dist/bin/shell/chunks/true-KFTJGQLQ.js +3 -0
  329. package/dist/bin/shell/chunks/undici-JES22UVU.js +141 -0
  330. package/dist/bin/shell/chunks/unexpand-JPOQORZF.js +3 -0
  331. package/dist/bin/shell/chunks/uniq-K5VRDP4Q.js +3 -0
  332. package/dist/bin/shell/chunks/wc-VSQBRD6B.js +3 -0
  333. package/dist/bin/shell/chunks/which-4TPGVSBZ.js +3 -0
  334. package/dist/bin/shell/chunks/whoami-B5HDVKW6.js +3 -0
  335. package/dist/bin/shell/chunks/xan-D6US4ZGL.js +3 -0
  336. package/dist/bin/shell/chunks/xan-view-QGKWT354.js +3 -0
  337. package/dist/bin/shell/chunks/xargs-HMISWW4I.js +3 -0
  338. package/dist/bin/shell/chunks/yq-EYV7HLKK.js +3 -0
  339. package/dist/bin/shell/shell.js +413 -391
  340. package/dist/bounded-builder.d.ts +37 -0
  341. package/dist/browser.d.ts +3 -3
  342. package/dist/bundle/browser.js +869 -832
  343. package/dist/bundle/chunks/alias-T5TO5GWK.js +2 -0
  344. package/dist/bundle/chunks/awk2-IPNBFNH2.js +2 -0
  345. package/dist/bundle/chunks/base64-OXGTKKDA.js +2 -0
  346. package/dist/bundle/chunks/basename-SJZQ5W65.js +2 -0
  347. package/dist/bundle/chunks/bash-HIEWVHJ2.js +2 -0
  348. package/dist/bundle/chunks/cat-636HYSH4.js +2 -0
  349. package/dist/bundle/chunks/chmod-4CIOYX5Q.js +2 -0
  350. package/dist/bundle/chunks/chunk-273265WK.js +6 -0
  351. package/dist/bundle/chunks/chunk-2KNTH3KH.js +9 -0
  352. package/dist/bundle/chunks/chunk-2VWG4LDT.js +11 -0
  353. package/dist/bundle/chunks/chunk-3DHFIWMM.js +15 -0
  354. package/dist/bundle/chunks/chunk-5ATEFZLC.js +4 -0
  355. package/dist/bundle/chunks/chunk-5HXWWNWH.js +11 -0
  356. package/dist/bundle/chunks/chunk-5KGKXQF6.js +142 -0
  357. package/dist/bundle/chunks/chunk-5VCAQBXL.js +17 -0
  358. package/dist/bundle/chunks/chunk-65Z4QURM.js +12 -0
  359. package/dist/bundle/chunks/chunk-6D3WD6YU.js +3 -0
  360. package/dist/bundle/chunks/chunk-6IUGGJ2Y.js +8 -0
  361. package/dist/bundle/chunks/chunk-6R4OQQWP.js +16 -0
  362. package/dist/bundle/chunks/chunk-6WGIZV3E.js +13 -0
  363. package/dist/bundle/chunks/chunk-AFFAMSJT.js +14 -0
  364. package/dist/bundle/chunks/chunk-AH7VTVWU.js +2 -0
  365. package/dist/bundle/chunks/chunk-AI5LSBJC.js +2 -0
  366. package/dist/bundle/chunks/chunk-AMLHAS2N.js +15 -0
  367. package/dist/bundle/chunks/chunk-ANCQ4SCV.js +2 -0
  368. package/dist/bundle/chunks/chunk-B3NGH6KE.js +5 -0
  369. package/dist/bundle/chunks/chunk-B5Z5HTFY.js +14 -0
  370. package/dist/bundle/chunks/chunk-BRJERIF4.js +2 -0
  371. package/dist/bundle/chunks/chunk-CHHWTPDH.js +3 -0
  372. package/dist/bundle/chunks/chunk-CN3HTJTZ.js +11 -0
  373. package/dist/bundle/chunks/chunk-D3W7DTI6.js +9 -0
  374. package/dist/bundle/chunks/chunk-E3D4WVAH.js +21 -0
  375. package/dist/bundle/chunks/chunk-EAQUR2NP.js +25 -0
  376. package/dist/bundle/chunks/chunk-EFORKKSH.js +8 -0
  377. package/dist/bundle/chunks/chunk-EJFBIRMD.js +6 -0
  378. package/dist/bundle/chunks/chunk-ELHOZMBD.js +10 -0
  379. package/dist/bundle/chunks/chunk-EQQGPAXI.js +9 -0
  380. package/dist/bundle/chunks/chunk-EWWPEE2G.js +37 -0
  381. package/dist/bundle/chunks/chunk-FBXMKFE2.js +2 -0
  382. package/dist/bundle/chunks/chunk-FIMO5HLX.js +2 -0
  383. package/dist/bundle/chunks/chunk-FT6ODGOU.js +2 -0
  384. package/dist/bundle/chunks/chunk-G4SEENI7.js +6 -0
  385. package/dist/bundle/chunks/chunk-GN6CQ3J4.js +2 -0
  386. package/dist/bundle/chunks/chunk-HW6ZCMM5.js +9 -0
  387. package/dist/bundle/chunks/chunk-IBRT3OJS.js +2 -0
  388. package/dist/bundle/chunks/chunk-INDA53JL.js +21 -0
  389. package/dist/bundle/chunks/chunk-INHMNORI.js +6 -0
  390. package/dist/bundle/chunks/chunk-J2OBOJ64.js +2 -0
  391. package/dist/bundle/chunks/chunk-JCPCQREJ.js +15 -0
  392. package/dist/bundle/chunks/chunk-JYQ6MII2.js +33 -0
  393. package/dist/bundle/chunks/chunk-K3XJ2WT4.js +2 -0
  394. package/dist/bundle/chunks/chunk-KIGPB52X.js +2 -0
  395. package/dist/bundle/chunks/chunk-KKVPMNSS.js +5 -0
  396. package/dist/bundle/chunks/chunk-LGLR6TFP.js +7 -0
  397. package/dist/bundle/chunks/chunk-LJRVJXUI.js +2 -0
  398. package/dist/bundle/chunks/chunk-LVDUF74R.js +7 -0
  399. package/dist/bundle/chunks/chunk-MAWVZWRK.js +12 -0
  400. package/dist/bundle/chunks/chunk-MF4F4ZPP.js +7 -0
  401. package/dist/bundle/chunks/chunk-MFGH46GH.js +14 -0
  402. package/dist/bundle/chunks/chunk-N4TGZ6H7.js +7 -0
  403. package/dist/bundle/chunks/chunk-NCUTH6QL.js +2 -0
  404. package/dist/bundle/chunks/chunk-NNH4ERNJ.js +100 -0
  405. package/dist/bundle/chunks/chunk-NOPXHH6G.js +290 -0
  406. package/dist/bundle/chunks/chunk-OQ7C4FYO.js +2 -0
  407. package/dist/bundle/chunks/chunk-ORDZCFFT.js +2 -0
  408. package/dist/bundle/chunks/chunk-OTYP7VVT.js +21 -0
  409. package/dist/bundle/chunks/chunk-P5BOIHWV.js +6 -0
  410. package/dist/bundle/chunks/chunk-PJWSSENQ.js +5 -0
  411. package/dist/bundle/chunks/chunk-PMYUC5JF.js +12 -0
  412. package/dist/bundle/chunks/chunk-POIWRLUV.js +6 -0
  413. package/dist/bundle/chunks/chunk-PPDMRIJ7.js +11 -0
  414. package/dist/bundle/chunks/chunk-QTLI5LUD.js +21 -0
  415. package/dist/bundle/chunks/chunk-R2FBRMDU.js +14 -0
  416. package/dist/bundle/chunks/chunk-RAHPENCM.js +35 -0
  417. package/dist/bundle/chunks/chunk-SELXJ5KQ.js +10 -0
  418. package/dist/bundle/chunks/chunk-T2RHALUC.js +64 -0
  419. package/dist/bundle/chunks/chunk-UB6T3UHL.js +8 -0
  420. package/dist/bundle/chunks/chunk-UBTKJ6MG.js +4 -0
  421. package/dist/bundle/chunks/chunk-UHHCL65P.js +3 -0
  422. package/dist/bundle/chunks/chunk-UK4BO5W3.js +2 -0
  423. package/dist/bundle/chunks/chunk-UTKGYVUZ.js +7 -0
  424. package/dist/bundle/chunks/chunk-VECGTAPW.js +10 -0
  425. package/dist/bundle/chunks/chunk-VOSNSQE2.js +2 -0
  426. package/dist/bundle/chunks/chunk-WENIVVEE.js +19 -0
  427. package/dist/bundle/chunks/chunk-WHHRIZS3.js +10 -0
  428. package/dist/bundle/chunks/chunk-WZQNMEQW.js +2 -0
  429. package/dist/bundle/chunks/chunk-XVL654YD.js +33 -0
  430. package/dist/bundle/chunks/chunk-Y3DGIAIG.js +21 -0
  431. package/dist/bundle/chunks/chunk-Y62SXZKJ.js +12 -0
  432. package/dist/bundle/chunks/chunk-YOUUMJLJ.js +10 -0
  433. package/dist/bundle/chunks/chunk-YUSFCOM7.js +2 -0
  434. package/dist/bundle/chunks/clear-KPIUNI6K.js +2 -0
  435. package/dist/bundle/chunks/column-LKMDIDCH.js +2 -0
  436. package/dist/bundle/chunks/comm-DTWKU2MC.js +2 -0
  437. package/dist/bundle/chunks/cp-FKTQRFYJ.js +2 -0
  438. package/dist/bundle/chunks/curl-DEHFBW27.js +29 -0
  439. package/dist/bundle/chunks/cut-RWPUW5FY.js +2 -0
  440. package/dist/bundle/chunks/date-FN2DXAEE.js +2 -0
  441. package/dist/bundle/chunks/diff-CSARC7WF.js +2 -0
  442. package/dist/bundle/chunks/dirname-Z2ZMOOW2.js +2 -0
  443. package/dist/bundle/chunks/du-PR3M44X6.js +2 -0
  444. package/dist/bundle/chunks/echo-HZOVZAPR.js +2 -0
  445. package/dist/bundle/chunks/env-VUUMB47B.js +2 -0
  446. package/dist/bundle/chunks/expand-2BPPGGSM.js +2 -0
  447. package/dist/bundle/chunks/expr-SHRJJ4PX.js +2 -0
  448. package/dist/bundle/chunks/file-YC4YEI4P.js +2 -0
  449. package/dist/bundle/chunks/find-DWWMZFO5.js +2 -0
  450. package/dist/bundle/chunks/flag-coverage-THYQHOT3.js +2 -0
  451. package/dist/bundle/chunks/fold-QJBPHRFJ.js +2 -0
  452. package/dist/bundle/chunks/grep-S6SNTIHZ.js +2 -0
  453. package/dist/bundle/chunks/gzip-BTI6CWY4.js +2 -0
  454. package/dist/bundle/chunks/head-UCOA3VQC.js +2 -0
  455. package/dist/bundle/chunks/help-QDDMBDU7.js +2 -0
  456. package/dist/bundle/chunks/history-3N762S3K.js +2 -0
  457. package/dist/bundle/chunks/hostname-CESD3CQR.js +2 -0
  458. package/dist/bundle/chunks/html-to-markdown-NUF6QEX4.js +2 -0
  459. package/dist/bundle/chunks/join-KQ4Z5OD4.js +2 -0
  460. package/dist/bundle/chunks/jq-D6N4QCAJ.js +2 -0
  461. package/dist/bundle/chunks/js-exec-PNUEDFT5.js +98 -0
  462. package/dist/bundle/chunks/js-exec-worker.js +187 -110
  463. package/dist/bundle/chunks/ln-VYDFOFNO.js +2 -0
  464. package/dist/bundle/chunks/ls-R5CQLZQM.js +2 -0
  465. package/dist/bundle/chunks/md5sum-JEDX55KS.js +2 -0
  466. package/dist/bundle/chunks/mkdir-WDDKK2P3.js +2 -0
  467. package/dist/bundle/chunks/mv-XSJA2FNL.js +2 -0
  468. package/dist/bundle/chunks/nl-RFXH2GNX.js +2 -0
  469. package/dist/bundle/chunks/od-YXD2NNIU.js +2 -0
  470. package/dist/bundle/chunks/paste-ZU3EODNI.js +2 -0
  471. package/dist/bundle/chunks/printf-QHD2JRWQ.js +2 -0
  472. package/dist/bundle/chunks/pwd-76BPYV5F.js +2 -0
  473. package/dist/bundle/chunks/python3-QDNG2UXX.js +13 -0
  474. package/dist/bundle/chunks/readlink-IY6QKK2P.js +2 -0
  475. package/dist/bundle/chunks/rev-EPOS3MFH.js +2 -0
  476. package/dist/bundle/chunks/rg-OUJZ5DH6.js +2 -0
  477. package/dist/bundle/chunks/rm-JQ4GDKDD.js +2 -0
  478. package/dist/bundle/chunks/rmdir-WZKAT6M5.js +2 -0
  479. package/dist/bundle/chunks/sed-TZIPJOGL.js +2 -0
  480. package/dist/bundle/chunks/seq-5R2GKXC6.js +2 -0
  481. package/dist/bundle/chunks/sha1sum-BLPZJ6MP.js +2 -0
  482. package/dist/bundle/chunks/sha256sum-VJZ4PHQ4.js +2 -0
  483. package/dist/bundle/chunks/sleep-VPYWSKDR.js +2 -0
  484. package/dist/bundle/chunks/sort-PV2NEQHF.js +2 -0
  485. package/dist/bundle/chunks/split-KNDNAFPT.js +2 -0
  486. package/dist/bundle/chunks/sqlite3-WWZJZW37.js +2 -0
  487. package/dist/bundle/chunks/sqlite3-worker.js +316 -173
  488. package/dist/bundle/chunks/stat-MLNSW25G.js +2 -0
  489. package/dist/bundle/chunks/strings-WTD7Q2EF.js +2 -0
  490. package/dist/bundle/chunks/tac-YXC4HBTR.js +2 -0
  491. package/dist/bundle/chunks/tail-G3W6PNG3.js +2 -0
  492. package/dist/bundle/chunks/tar-GLX6QUHW.js +2 -0
  493. package/dist/bundle/chunks/tee-OOWSWHRQ.js +2 -0
  494. package/dist/bundle/chunks/time-NERE2JJ2.js +2 -0
  495. package/dist/bundle/chunks/timeout-SYQCWBMZ.js +2 -0
  496. package/dist/bundle/chunks/touch-W4DF6Z4T.js +2 -0
  497. package/dist/bundle/chunks/tr-3KPFH3J4.js +2 -0
  498. package/dist/bundle/chunks/tree-7OOL2MH6.js +2 -0
  499. package/dist/bundle/chunks/true-QUBPEGGU.js +2 -0
  500. package/dist/bundle/chunks/undici-HCLAUJT3.js +140 -0
  501. package/dist/bundle/chunks/unexpand-YD5BWFH4.js +2 -0
  502. package/dist/bundle/chunks/uniq-OVOW532K.js +2 -0
  503. package/dist/bundle/chunks/wc-RUR7HE5O.js +2 -0
  504. package/dist/bundle/chunks/which-UWVKETYW.js +2 -0
  505. package/dist/bundle/chunks/whoami-KR6E7UIR.js +2 -0
  506. package/dist/bundle/chunks/worker.js +212 -105
  507. package/dist/bundle/chunks/xan-KKPV2TJ3.js +2 -0
  508. package/dist/bundle/chunks/xan-view-47P277LZ.js +2 -0
  509. package/dist/bundle/chunks/xargs-L7TJHOJT.js +2 -0
  510. package/dist/bundle/chunks/yq-ZGB3W46S.js +2 -0
  511. package/dist/bundle/index.cjs +1450 -1263
  512. package/dist/bundle/index.js +407 -386
  513. package/dist/commands/alias/alias.d.ts +3 -3
  514. package/dist/commands/awk/awk2.d.ts +3 -3
  515. package/dist/commands/awk/builtins.d.ts +1 -1
  516. package/dist/commands/awk/interpreter/context.d.ts +13 -0
  517. package/dist/commands/awk/lexer.d.ts +2 -1
  518. package/dist/commands/awk/parser2-print.d.ts +3 -0
  519. package/dist/commands/awk/parser2.d.ts +15 -0
  520. package/dist/commands/base64/base64.d.ts +2 -2
  521. package/dist/commands/basename/basename.d.ts +2 -2
  522. package/dist/commands/bash/bash.d.ts +3 -3
  523. package/dist/commands/cat/cat.d.ts +2 -2
  524. package/dist/commands/chmod/chmod.d.ts +2 -2
  525. package/dist/commands/clear/clear.d.ts +2 -2
  526. package/dist/commands/column/column.d.ts +2 -2
  527. package/dist/commands/comm/comm.d.ts +2 -2
  528. package/dist/commands/compression/codec-budget.d.ts +35 -0
  529. package/dist/commands/cp/cp.d.ts +2 -2
  530. package/dist/commands/curl/curl.d.ts +2 -2
  531. package/dist/commands/curl/form.d.ts +3 -1
  532. package/dist/commands/curl/types.d.ts +30 -25
  533. package/dist/commands/cut/cut.d.ts +2 -2
  534. package/dist/commands/date/date.d.ts +2 -2
  535. package/dist/commands/diff/diff.d.ts +2 -2
  536. package/dist/commands/dirname/dirname.d.ts +2 -2
  537. package/dist/commands/du/du.d.ts +2 -2
  538. package/dist/commands/echo/echo.d.ts +2 -2
  539. package/dist/commands/env/env.d.ts +3 -3
  540. package/dist/commands/expand/expand.d.ts +2 -2
  541. package/dist/commands/expand/unexpand.d.ts +2 -2
  542. package/dist/commands/expr/expr.d.ts +2 -2
  543. package/dist/commands/file/file.d.ts +2 -2
  544. package/dist/commands/find/find.d.ts +2 -2
  545. package/dist/commands/find/matcher.d.ts +0 -16
  546. package/dist/commands/find/types.d.ts +3 -2
  547. package/dist/commands/fold/fold.d.ts +2 -2
  548. package/dist/commands/grep/grep.d.ts +4 -4
  549. package/dist/commands/gzip/gzip.d.ts +4 -4
  550. package/dist/commands/head/head-tail-shared.d.ts +2 -2
  551. package/dist/commands/head/head.d.ts +2 -2
  552. package/dist/commands/help/help.d.ts +2 -2
  553. package/dist/commands/history/history.d.ts +2 -2
  554. package/dist/commands/hostname/hostname.d.ts +2 -2
  555. package/dist/commands/html-to-markdown/html-to-markdown.d.ts +2 -2
  556. package/dist/commands/join/join.d.ts +2 -2
  557. package/dist/commands/jq/jq.d.ts +3 -3
  558. package/dist/commands/js-exec/fetch-polyfill.d.ts +1 -1
  559. package/dist/commands/js-exec/js-exec-worker.d.ts +1 -0
  560. package/dist/commands/js-exec/js-exec.d.ts +5 -3
  561. package/dist/commands/ln/ln.d.ts +2 -2
  562. package/dist/commands/ls/ls.d.ts +2 -2
  563. package/dist/commands/md5sum/checksum.d.ts +2 -2
  564. package/dist/commands/md5sum/md5sum.d.ts +2 -2
  565. package/dist/commands/md5sum/sha1sum.d.ts +2 -2
  566. package/dist/commands/md5sum/sha256sum.d.ts +2 -2
  567. package/dist/commands/mkdir/mkdir.d.ts +2 -2
  568. package/dist/commands/mv/mv.d.ts +2 -2
  569. package/dist/commands/nl/nl.d.ts +2 -2
  570. package/dist/commands/od/od.d.ts +2 -2
  571. package/dist/commands/paste/paste.d.ts +2 -2
  572. package/dist/commands/printf/escapes.d.ts +5 -3
  573. package/dist/commands/printf/printf.d.ts +2 -2
  574. package/dist/commands/printf/strftime.d.ts +6 -1
  575. package/dist/commands/pwd/pwd.d.ts +2 -2
  576. package/dist/commands/python3/python3.d.ts +3 -3
  577. package/dist/commands/python3/worker.d.ts +2 -0
  578. package/dist/commands/query-engine/builtins/control-builtins.d.ts +1 -1
  579. package/dist/commands/query-engine/builtins/path-builtins.d.ts +1 -1
  580. package/dist/commands/query-engine/evaluator.d.ts +15 -1
  581. package/dist/commands/query-engine/json-output.d.ts +11 -0
  582. package/dist/commands/query-engine/parser.d.ts +6 -1
  583. package/dist/commands/query-engine/safe-object.d.ts +9 -8
  584. package/dist/commands/query-engine/value-operations.d.ts +4 -1
  585. package/dist/commands/readlink/readlink.d.ts +2 -2
  586. package/dist/commands/registry.d.ts +5 -5
  587. package/dist/commands/rev/rev.d.ts +2 -2
  588. package/dist/commands/rg/rg-search.d.ts +2 -2
  589. package/dist/commands/rg/rg.d.ts +2 -2
  590. package/dist/commands/rm/rm.d.ts +2 -2
  591. package/dist/commands/rmdir/rmdir.d.ts +2 -2
  592. package/dist/commands/search-engine/matcher.d.ts +6 -0
  593. package/dist/commands/sed/lexer.d.ts +3 -1
  594. package/dist/commands/sed/parser.d.ts +4 -1
  595. package/dist/commands/sed/sed.d.ts +2 -2
  596. package/dist/commands/seq/seq.d.ts +2 -2
  597. package/dist/commands/sleep/sleep.d.ts +2 -2
  598. package/dist/commands/sort/sort.d.ts +2 -2
  599. package/dist/commands/split/split.d.ts +2 -2
  600. package/dist/commands/sqlite3/formatters.d.ts +2 -0
  601. package/dist/commands/sqlite3/sqlite3.d.ts +3 -2
  602. package/dist/commands/sqlite3/worker.d.ts +5 -0
  603. package/dist/commands/sqlite3/worker.js +316 -173
  604. package/dist/commands/stat/stat.d.ts +2 -2
  605. package/dist/commands/strings/strings.d.ts +2 -2
  606. package/dist/commands/tac/tac.d.ts +2 -2
  607. package/dist/commands/tail/tail.d.ts +2 -2
  608. package/dist/commands/tar/archive.d.ts +29 -14
  609. package/dist/commands/tar/bzip2-compress.d.ts +2 -1
  610. package/dist/commands/tar/tar.d.ts +2 -2
  611. package/dist/commands/tee/tee.d.ts +2 -2
  612. package/dist/commands/time/time.d.ts +2 -2
  613. package/dist/commands/timeout/timeout.d.ts +2 -2
  614. package/dist/commands/touch/touch.d.ts +2 -2
  615. package/dist/commands/tr/tr.d.ts +2 -2
  616. package/dist/commands/tree/tree.d.ts +2 -2
  617. package/dist/commands/true/true.d.ts +3 -3
  618. package/dist/commands/uniq/uniq.d.ts +2 -2
  619. package/dist/commands/wc/wc.d.ts +2 -2
  620. package/dist/commands/which/which.d.ts +2 -2
  621. package/dist/commands/whoami/whoami.d.ts +2 -2
  622. package/dist/commands/worker-request-controller.d.ts +36 -0
  623. package/dist/commands/xan/aggregation.d.ts +13 -3
  624. package/dist/commands/xan/bounded-output.d.ts +4 -0
  625. package/dist/commands/xan/column-selection.d.ts +2 -1
  626. package/dist/commands/xan/csv.d.ts +29 -4
  627. package/dist/commands/xan/moonblade-parser.d.ts +11 -2
  628. package/dist/commands/xan/moonblade-to-jq.d.ts +2 -2
  629. package/dist/commands/xan/moonblade-tokenizer.d.ts +8 -1
  630. package/dist/commands/xan/xan-agg.d.ts +5 -5
  631. package/dist/commands/xan/xan-columns.d.ts +5 -5
  632. package/dist/commands/xan/xan-core.d.ts +7 -7
  633. package/dist/commands/xan/xan-data.d.ts +8 -8
  634. package/dist/commands/xan/xan-filter.d.ts +5 -5
  635. package/dist/commands/xan/xan-map.d.ts +3 -3
  636. package/dist/commands/xan/xan-reshape.d.ts +6 -6
  637. package/dist/commands/xan/xan-simple.d.ts +7 -7
  638. package/dist/commands/xan/xan-view.d.ts +3 -3
  639. package/dist/commands/xan/xan.d.ts +2 -2
  640. package/dist/commands/xargs/xargs.d.ts +2 -2
  641. package/dist/commands/yq/formats.d.ts +5 -4
  642. package/dist/commands/yq/yq.d.ts +3 -3
  643. package/dist/custom-commands.d.ts +25 -2
  644. package/dist/encoding.d.ts +5 -3
  645. package/dist/execution-output.d.ts +28 -0
  646. package/dist/execution-scope.d.ts +89 -0
  647. package/dist/fatal-execution-error.d.ts +5 -0
  648. package/dist/fs/identity.d.ts +9 -0
  649. package/dist/fs/in-memory-fs/in-memory-fs.d.ts +24 -1
  650. package/dist/fs/interface.d.ts +4 -0
  651. package/dist/fs/overlay-fs/overlay-fs.d.ts +13 -0
  652. package/dist/fs/path-utils.d.ts +2 -0
  653. package/dist/fs/read-write-fs/read-write-fs.d.ts +11 -0
  654. package/dist/fs/real-fs-utils.d.ts +1 -1
  655. package/dist/fs/traversal.d.ts +98 -0
  656. package/dist/index.d.cts +4 -4
  657. package/dist/index.d.ts +4 -4
  658. package/dist/interpreter/alias-expansion.d.ts +4 -0
  659. package/dist/interpreter/builtins/declare-array-parsing.d.ts +6 -2
  660. package/dist/interpreter/builtins/index.d.ts +0 -1
  661. package/dist/interpreter/builtins/variable-assignment.d.ts +4 -1
  662. package/dist/interpreter/conditionals.d.ts +1 -1
  663. package/dist/interpreter/defense-aware-command-context.d.ts +2 -2
  664. package/dist/interpreter/errors.d.ts +7 -17
  665. package/dist/interpreter/expansion/brace-range.d.ts +5 -1
  666. package/dist/interpreter/expansion/pattern-removal.d.ts +2 -3
  667. package/dist/interpreter/expansion/pattern-replacement.d.ts +4 -0
  668. package/dist/interpreter/expansion/tilde.d.ts +2 -0
  669. package/dist/interpreter/helpers/array.d.ts +16 -3
  670. package/dist/interpreter/helpers/bounded-array.d.ts +2 -0
  671. package/dist/interpreter/helpers/condition.d.ts +2 -5
  672. package/dist/interpreter/helpers/ifs.d.ts +3 -3
  673. package/dist/interpreter/helpers/quoting.d.ts +2 -0
  674. package/dist/interpreter/helpers/string-compare.d.ts +1 -1
  675. package/dist/interpreter/interpreter.d.ts +4 -8
  676. package/dist/interpreter/redirections.d.ts +5 -2
  677. package/dist/interpreter/simple-command-assignments.d.ts +7 -0
  678. package/dist/interpreter/state-transaction.d.ts +7 -0
  679. package/dist/interpreter/types.d.ts +24 -8
  680. package/dist/limits.d.ts +76 -17
  681. package/dist/network/dns-pin.d.ts +23 -32
  682. package/dist/network/fetch.d.ts +4 -0
  683. package/dist/network/types.d.ts +10 -1
  684. package/dist/parser/parser.d.ts +5 -2
  685. package/dist/parser/types.d.ts +10 -1
  686. package/dist/source-limit.d.ts +2 -0
  687. package/dist/timers.d.ts +12 -0
  688. package/dist/types.d.ts +43 -7
  689. package/dist/utils/file-reader.d.ts +5 -3
  690. package/package.json +10 -5
  691. package/dist/bin/chunks/alias-YRVAW27Y.js +0 -3
  692. package/dist/bin/chunks/awk2-UFCNQFCV.js +0 -3
  693. package/dist/bin/chunks/base64-EGKVQIBC.js +0 -3
  694. package/dist/bin/chunks/basename-F3AQ4KAQ.js +0 -3
  695. package/dist/bin/chunks/bash-BEG4JB7K.js +0 -3
  696. package/dist/bin/chunks/cat-NBL6MU5H.js +0 -3
  697. package/dist/bin/chunks/chmod-S564JCJW.js +0 -3
  698. package/dist/bin/chunks/chunk-2AIXTPH2.js +0 -9
  699. package/dist/bin/chunks/chunk-2GG3NVC4.js +0 -10
  700. package/dist/bin/chunks/chunk-2ZAK22BG.js +0 -9
  701. package/dist/bin/chunks/chunk-3WIMLJM7.js +0 -8
  702. package/dist/bin/chunks/chunk-47WZ2U6M.js +0 -9
  703. package/dist/bin/chunks/chunk-4BNS566Q.js +0 -4
  704. package/dist/bin/chunks/chunk-52FZYTIX.js +0 -34
  705. package/dist/bin/chunks/chunk-5KX5YUWT.js +0 -37
  706. package/dist/bin/chunks/chunk-5XSZHUEI.js +0 -15
  707. package/dist/bin/chunks/chunk-63LSI3D6.js +0 -17
  708. package/dist/bin/chunks/chunk-6FYCU7QB.js +0 -3
  709. package/dist/bin/chunks/chunk-6JKLDBRW.js +0 -18
  710. package/dist/bin/chunks/chunk-6WJQNLR2.js +0 -7
  711. package/dist/bin/chunks/chunk-7HK63L6Y.js +0 -3
  712. package/dist/bin/chunks/chunk-7NDRU2ZN.js +0 -5
  713. package/dist/bin/chunks/chunk-7VCQWCSH.js +0 -15
  714. package/dist/bin/chunks/chunk-AFAD5U2A.js +0 -8
  715. package/dist/bin/chunks/chunk-AZH64XMJ.js +0 -3
  716. package/dist/bin/chunks/chunk-BKQLXMS6.js +0 -36
  717. package/dist/bin/chunks/chunk-BPZJYOUA.js +0 -33
  718. package/dist/bin/chunks/chunk-BZP56QBM.js +0 -24
  719. package/dist/bin/chunks/chunk-C6JOQKE2.js +0 -22
  720. package/dist/bin/chunks/chunk-CX5CEEGI.js +0 -11
  721. package/dist/bin/chunks/chunk-D7YFPDMV.js +0 -22
  722. package/dist/bin/chunks/chunk-DHIKZU63.js +0 -3
  723. package/dist/bin/chunks/chunk-DWECIBLJ.js +0 -3
  724. package/dist/bin/chunks/chunk-FEENTUVZ.js +0 -18
  725. package/dist/bin/chunks/chunk-FYCT4DWY.js +0 -6
  726. package/dist/bin/chunks/chunk-G7ZWT7BT.js +0 -9
  727. package/dist/bin/chunks/chunk-GTO74SFS.js +0 -7
  728. package/dist/bin/chunks/chunk-HMCRB24D.js +0 -15
  729. package/dist/bin/chunks/chunk-HWNCK5BB.js +0 -10
  730. package/dist/bin/chunks/chunk-HZR3FOJM.js +0 -288
  731. package/dist/bin/chunks/chunk-ISLENKSH.js +0 -7
  732. package/dist/bin/chunks/chunk-IX7LKVVH.js +0 -15
  733. package/dist/bin/chunks/chunk-JDFKEXLG.js +0 -12
  734. package/dist/bin/chunks/chunk-JJC4ENJL.js +0 -13
  735. package/dist/bin/chunks/chunk-JSZBZ2XU.js +0 -3
  736. package/dist/bin/chunks/chunk-JXLDT4KX.js +0 -4
  737. package/dist/bin/chunks/chunk-KMZUSEWI.js +0 -12
  738. package/dist/bin/chunks/chunk-KWCO3YXP.js +0 -17
  739. package/dist/bin/chunks/chunk-LNVSXNT7.js +0 -3
  740. package/dist/bin/chunks/chunk-LX2H4DPL.js +0 -6
  741. package/dist/bin/chunks/chunk-MLUOPG3W.js +0 -3
  742. package/dist/bin/chunks/chunk-MNWK4UIM.js +0 -22
  743. package/dist/bin/chunks/chunk-MP77TJMM.js +0 -6
  744. package/dist/bin/chunks/chunk-MTK7VLZG.js +0 -12
  745. package/dist/bin/chunks/chunk-N3FQJLPZ.js +0 -17
  746. package/dist/bin/chunks/chunk-N6YW4W3Z.js +0 -29
  747. package/dist/bin/chunks/chunk-NMMVECGD.js +0 -14
  748. package/dist/bin/chunks/chunk-NXYVRP6D.js +0 -11
  749. package/dist/bin/chunks/chunk-NYIPFY36.js +0 -3
  750. package/dist/bin/chunks/chunk-OVVMB2JI.js +0 -7
  751. package/dist/bin/chunks/chunk-OXZSG3ZZ.js +0 -7
  752. package/dist/bin/chunks/chunk-PKE7GKU5.js +0 -3
  753. package/dist/bin/chunks/chunk-PSJORJRS.js +0 -6
  754. package/dist/bin/chunks/chunk-R36DS2UF.js +0 -20
  755. package/dist/bin/chunks/chunk-RKBWTGBZ.js +0 -7
  756. package/dist/bin/chunks/chunk-RO3XCUVQ.js +0 -141
  757. package/dist/bin/chunks/chunk-RVGYO2OU.js +0 -3
  758. package/dist/bin/chunks/chunk-SF2OLINE.js +0 -12
  759. package/dist/bin/chunks/chunk-TIRU5FOD.js +0 -101
  760. package/dist/bin/chunks/chunk-TKYWUEON.js +0 -13
  761. package/dist/bin/chunks/chunk-UI7CV277.js +0 -20
  762. package/dist/bin/chunks/chunk-UNWZQG7U.js +0 -3
  763. package/dist/bin/chunks/chunk-UOMNSQEZ.js +0 -10
  764. package/dist/bin/chunks/chunk-W5OBQVJ2.js +0 -6
  765. package/dist/bin/chunks/chunk-WDWNEHHE.js +0 -9
  766. package/dist/bin/chunks/chunk-WHUKZ3K3.js +0 -85
  767. package/dist/bin/chunks/chunk-XHCCSVP6.js +0 -9
  768. package/dist/bin/chunks/chunk-XPTYN6UE.js +0 -8
  769. package/dist/bin/chunks/chunk-XRUDFQG5.js +0 -7
  770. package/dist/bin/chunks/chunk-Y2IUEWQD.js +0 -11
  771. package/dist/bin/chunks/chunk-Y5OWCEDV.js +0 -64
  772. package/dist/bin/chunks/chunk-ZFUVUYWG.js +0 -15
  773. package/dist/bin/chunks/chunk-ZZP3RSWL.js +0 -4
  774. package/dist/bin/chunks/clear-FGNEKYDU.js +0 -3
  775. package/dist/bin/chunks/column-QLGOK3XM.js +0 -3
  776. package/dist/bin/chunks/comm-PLYUTVP3.js +0 -3
  777. package/dist/bin/chunks/cp-HYXTMN3D.js +0 -3
  778. package/dist/bin/chunks/curl-DCSPNPEW.js +0 -27
  779. package/dist/bin/chunks/cut-JNQTCQY7.js +0 -3
  780. package/dist/bin/chunks/date-OFYBOAUE.js +0 -3
  781. package/dist/bin/chunks/diff-LZ4WRLIF.js +0 -3
  782. package/dist/bin/chunks/dirname-VCINTLPD.js +0 -3
  783. package/dist/bin/chunks/du-4LRQIGRG.js +0 -3
  784. package/dist/bin/chunks/echo-KCOHTNDF.js +0 -3
  785. package/dist/bin/chunks/env-FNVYNLGB.js +0 -3
  786. package/dist/bin/chunks/expand-CB7FG7LQ.js +0 -3
  787. package/dist/bin/chunks/expr-6A2XZORA.js +0 -3
  788. package/dist/bin/chunks/file-GRZLWDVH.js +0 -3
  789. package/dist/bin/chunks/find-5OZWMYCV.js +0 -3
  790. package/dist/bin/chunks/flag-coverage-CAST5CDE.js +0 -3
  791. package/dist/bin/chunks/fold-7YEITA5L.js +0 -3
  792. package/dist/bin/chunks/grep-KKBXRB73.js +0 -3
  793. package/dist/bin/chunks/gzip-ZJP5VIAQ.js +0 -3
  794. package/dist/bin/chunks/head-B6GFQHKF.js +0 -3
  795. package/dist/bin/chunks/help-CGUEOGXQ.js +0 -3
  796. package/dist/bin/chunks/history-AQQWW3QB.js +0 -3
  797. package/dist/bin/chunks/hostname-USNWOQCK.js +0 -3
  798. package/dist/bin/chunks/html-to-markdown-3HJ7L7NL.js +0 -3
  799. package/dist/bin/chunks/join-WRM6S6CO.js +0 -3
  800. package/dist/bin/chunks/jq-3V5HDGLJ.js +0 -3
  801. package/dist/bin/chunks/js-exec-F7JAZ4ZQ.js +0 -98
  802. package/dist/bin/chunks/ln-LP4HMCSM.js +0 -3
  803. package/dist/bin/chunks/ls-KBNHNZWQ.js +0 -3
  804. package/dist/bin/chunks/md5sum-ZNYCDRQL.js +0 -3
  805. package/dist/bin/chunks/mkdir-P4DKRCDX.js +0 -3
  806. package/dist/bin/chunks/mv-QQK4FQX6.js +0 -3
  807. package/dist/bin/chunks/nl-6TVYE4ZB.js +0 -3
  808. package/dist/bin/chunks/od-Y3E3QXOL.js +0 -3
  809. package/dist/bin/chunks/paste-LYNFXXCM.js +0 -3
  810. package/dist/bin/chunks/printf-MR3FXCDE.js +0 -3
  811. package/dist/bin/chunks/pwd-FCNDA467.js +0 -3
  812. package/dist/bin/chunks/python3-R5OFWJIH.js +0 -13
  813. package/dist/bin/chunks/readlink-25V57VOL.js +0 -3
  814. package/dist/bin/chunks/rev-AJECDD4L.js +0 -3
  815. package/dist/bin/chunks/rg-DZKA632H.js +0 -3
  816. package/dist/bin/chunks/rm-ECNUFR66.js +0 -3
  817. package/dist/bin/chunks/rmdir-DLOHIA7Q.js +0 -3
  818. package/dist/bin/chunks/sed-IGRH7EGG.js +0 -3
  819. package/dist/bin/chunks/seq-UXDJE6FB.js +0 -3
  820. package/dist/bin/chunks/sha1sum-5QZSNFY3.js +0 -3
  821. package/dist/bin/chunks/sha256sum-DI7JAVAU.js +0 -3
  822. package/dist/bin/chunks/sleep-RPGCUUGX.js +0 -3
  823. package/dist/bin/chunks/sort-HQPAFL76.js +0 -3
  824. package/dist/bin/chunks/split-F6FSB5KI.js +0 -3
  825. package/dist/bin/chunks/sqlite3-7TRACAE7.js +0 -3
  826. package/dist/bin/chunks/stat-BD6KT3BP.js +0 -3
  827. package/dist/bin/chunks/strings-6PE3YMPO.js +0 -3
  828. package/dist/bin/chunks/tac-NERJXVOM.js +0 -3
  829. package/dist/bin/chunks/tail-24F643A4.js +0 -3
  830. package/dist/bin/chunks/tar-5HK3VMV2.js +0 -3
  831. package/dist/bin/chunks/tee-5B7P2QRJ.js +0 -3
  832. package/dist/bin/chunks/time-FN6VJGRS.js +0 -3
  833. package/dist/bin/chunks/timeout-ZARIAF3K.js +0 -3
  834. package/dist/bin/chunks/touch-DFGSVIX7.js +0 -3
  835. package/dist/bin/chunks/tr-QQZYZ3CH.js +0 -3
  836. package/dist/bin/chunks/tree-6D7SMPUR.js +0 -3
  837. package/dist/bin/chunks/true-SKL4L7JP.js +0 -3
  838. package/dist/bin/chunks/unexpand-3JWOSSBQ.js +0 -3
  839. package/dist/bin/chunks/uniq-Q5UH5NL3.js +0 -3
  840. package/dist/bin/chunks/wc-4HXNTHY3.js +0 -3
  841. package/dist/bin/chunks/which-LCXKCLFC.js +0 -3
  842. package/dist/bin/chunks/whoami-TZDZDU7T.js +0 -3
  843. package/dist/bin/chunks/xan-TCTFON2Q.js +0 -3
  844. package/dist/bin/chunks/xan-view-XBMA362V.js +0 -3
  845. package/dist/bin/chunks/xargs-VTFN762K.js +0 -3
  846. package/dist/bin/chunks/yq-OB6PB5GY.js +0 -3
  847. package/dist/bin/shell/chunks/alias-YRVAW27Y.js +0 -3
  848. package/dist/bin/shell/chunks/awk2-UFCNQFCV.js +0 -3
  849. package/dist/bin/shell/chunks/base64-EGKVQIBC.js +0 -3
  850. package/dist/bin/shell/chunks/basename-F3AQ4KAQ.js +0 -3
  851. package/dist/bin/shell/chunks/bash-BEG4JB7K.js +0 -3
  852. package/dist/bin/shell/chunks/cat-NBL6MU5H.js +0 -3
  853. package/dist/bin/shell/chunks/chmod-S564JCJW.js +0 -3
  854. package/dist/bin/shell/chunks/chunk-2AIXTPH2.js +0 -9
  855. package/dist/bin/shell/chunks/chunk-2GG3NVC4.js +0 -10
  856. package/dist/bin/shell/chunks/chunk-2ZAK22BG.js +0 -9
  857. package/dist/bin/shell/chunks/chunk-3WIMLJM7.js +0 -8
  858. package/dist/bin/shell/chunks/chunk-47WZ2U6M.js +0 -9
  859. package/dist/bin/shell/chunks/chunk-4BNS566Q.js +0 -4
  860. package/dist/bin/shell/chunks/chunk-52FZYTIX.js +0 -34
  861. package/dist/bin/shell/chunks/chunk-5KX5YUWT.js +0 -37
  862. package/dist/bin/shell/chunks/chunk-5XSZHUEI.js +0 -15
  863. package/dist/bin/shell/chunks/chunk-63LSI3D6.js +0 -17
  864. package/dist/bin/shell/chunks/chunk-6FYCU7QB.js +0 -3
  865. package/dist/bin/shell/chunks/chunk-6JKLDBRW.js +0 -18
  866. package/dist/bin/shell/chunks/chunk-6WJQNLR2.js +0 -7
  867. package/dist/bin/shell/chunks/chunk-7HK63L6Y.js +0 -3
  868. package/dist/bin/shell/chunks/chunk-7NDRU2ZN.js +0 -5
  869. package/dist/bin/shell/chunks/chunk-7VCQWCSH.js +0 -15
  870. package/dist/bin/shell/chunks/chunk-AFAD5U2A.js +0 -8
  871. package/dist/bin/shell/chunks/chunk-AZH64XMJ.js +0 -3
  872. package/dist/bin/shell/chunks/chunk-BKQLXMS6.js +0 -36
  873. package/dist/bin/shell/chunks/chunk-BPZJYOUA.js +0 -33
  874. package/dist/bin/shell/chunks/chunk-BZP56QBM.js +0 -24
  875. package/dist/bin/shell/chunks/chunk-C6JOQKE2.js +0 -22
  876. package/dist/bin/shell/chunks/chunk-CX5CEEGI.js +0 -11
  877. package/dist/bin/shell/chunks/chunk-D7YFPDMV.js +0 -22
  878. package/dist/bin/shell/chunks/chunk-DHIKZU63.js +0 -3
  879. package/dist/bin/shell/chunks/chunk-DWECIBLJ.js +0 -3
  880. package/dist/bin/shell/chunks/chunk-FEENTUVZ.js +0 -18
  881. package/dist/bin/shell/chunks/chunk-FYCT4DWY.js +0 -6
  882. package/dist/bin/shell/chunks/chunk-G7ZWT7BT.js +0 -9
  883. package/dist/bin/shell/chunks/chunk-GTO74SFS.js +0 -7
  884. package/dist/bin/shell/chunks/chunk-HMCRB24D.js +0 -15
  885. package/dist/bin/shell/chunks/chunk-HWNCK5BB.js +0 -10
  886. package/dist/bin/shell/chunks/chunk-HZR3FOJM.js +0 -288
  887. package/dist/bin/shell/chunks/chunk-ISLENKSH.js +0 -7
  888. package/dist/bin/shell/chunks/chunk-IX7LKVVH.js +0 -15
  889. package/dist/bin/shell/chunks/chunk-JDFKEXLG.js +0 -12
  890. package/dist/bin/shell/chunks/chunk-JJC4ENJL.js +0 -13
  891. package/dist/bin/shell/chunks/chunk-JSZBZ2XU.js +0 -3
  892. package/dist/bin/shell/chunks/chunk-JXLDT4KX.js +0 -4
  893. package/dist/bin/shell/chunks/chunk-KMZUSEWI.js +0 -12
  894. package/dist/bin/shell/chunks/chunk-KWCO3YXP.js +0 -17
  895. package/dist/bin/shell/chunks/chunk-LNVSXNT7.js +0 -3
  896. package/dist/bin/shell/chunks/chunk-LX2H4DPL.js +0 -6
  897. package/dist/bin/shell/chunks/chunk-MLUOPG3W.js +0 -3
  898. package/dist/bin/shell/chunks/chunk-MNWK4UIM.js +0 -22
  899. package/dist/bin/shell/chunks/chunk-MP77TJMM.js +0 -6
  900. package/dist/bin/shell/chunks/chunk-MTK7VLZG.js +0 -12
  901. package/dist/bin/shell/chunks/chunk-N3FQJLPZ.js +0 -17
  902. package/dist/bin/shell/chunks/chunk-N6YW4W3Z.js +0 -29
  903. package/dist/bin/shell/chunks/chunk-NMMVECGD.js +0 -14
  904. package/dist/bin/shell/chunks/chunk-NXYVRP6D.js +0 -11
  905. package/dist/bin/shell/chunks/chunk-NYIPFY36.js +0 -3
  906. package/dist/bin/shell/chunks/chunk-OVVMB2JI.js +0 -7
  907. package/dist/bin/shell/chunks/chunk-OXZSG3ZZ.js +0 -7
  908. package/dist/bin/shell/chunks/chunk-PKE7GKU5.js +0 -3
  909. package/dist/bin/shell/chunks/chunk-PSJORJRS.js +0 -6
  910. package/dist/bin/shell/chunks/chunk-R36DS2UF.js +0 -20
  911. package/dist/bin/shell/chunks/chunk-RKBWTGBZ.js +0 -7
  912. package/dist/bin/shell/chunks/chunk-RO3XCUVQ.js +0 -141
  913. package/dist/bin/shell/chunks/chunk-RVGYO2OU.js +0 -3
  914. package/dist/bin/shell/chunks/chunk-SF2OLINE.js +0 -12
  915. package/dist/bin/shell/chunks/chunk-TIRU5FOD.js +0 -101
  916. package/dist/bin/shell/chunks/chunk-TKYWUEON.js +0 -13
  917. package/dist/bin/shell/chunks/chunk-UI7CV277.js +0 -20
  918. package/dist/bin/shell/chunks/chunk-UNWZQG7U.js +0 -3
  919. package/dist/bin/shell/chunks/chunk-UOMNSQEZ.js +0 -10
  920. package/dist/bin/shell/chunks/chunk-W5OBQVJ2.js +0 -6
  921. package/dist/bin/shell/chunks/chunk-WDWNEHHE.js +0 -9
  922. package/dist/bin/shell/chunks/chunk-WHUKZ3K3.js +0 -85
  923. package/dist/bin/shell/chunks/chunk-XHCCSVP6.js +0 -9
  924. package/dist/bin/shell/chunks/chunk-XPTYN6UE.js +0 -8
  925. package/dist/bin/shell/chunks/chunk-XRUDFQG5.js +0 -7
  926. package/dist/bin/shell/chunks/chunk-Y2IUEWQD.js +0 -11
  927. package/dist/bin/shell/chunks/chunk-Y5OWCEDV.js +0 -64
  928. package/dist/bin/shell/chunks/chunk-ZFUVUYWG.js +0 -15
  929. package/dist/bin/shell/chunks/chunk-ZZP3RSWL.js +0 -4
  930. package/dist/bin/shell/chunks/clear-FGNEKYDU.js +0 -3
  931. package/dist/bin/shell/chunks/column-QLGOK3XM.js +0 -3
  932. package/dist/bin/shell/chunks/comm-PLYUTVP3.js +0 -3
  933. package/dist/bin/shell/chunks/cp-HYXTMN3D.js +0 -3
  934. package/dist/bin/shell/chunks/curl-DCSPNPEW.js +0 -27
  935. package/dist/bin/shell/chunks/cut-JNQTCQY7.js +0 -3
  936. package/dist/bin/shell/chunks/date-OFYBOAUE.js +0 -3
  937. package/dist/bin/shell/chunks/diff-LZ4WRLIF.js +0 -3
  938. package/dist/bin/shell/chunks/dirname-VCINTLPD.js +0 -3
  939. package/dist/bin/shell/chunks/du-4LRQIGRG.js +0 -3
  940. package/dist/bin/shell/chunks/echo-KCOHTNDF.js +0 -3
  941. package/dist/bin/shell/chunks/env-FNVYNLGB.js +0 -3
  942. package/dist/bin/shell/chunks/expand-CB7FG7LQ.js +0 -3
  943. package/dist/bin/shell/chunks/expr-6A2XZORA.js +0 -3
  944. package/dist/bin/shell/chunks/file-GRZLWDVH.js +0 -3
  945. package/dist/bin/shell/chunks/find-5OZWMYCV.js +0 -3
  946. package/dist/bin/shell/chunks/flag-coverage-CAST5CDE.js +0 -3
  947. package/dist/bin/shell/chunks/fold-7YEITA5L.js +0 -3
  948. package/dist/bin/shell/chunks/grep-KKBXRB73.js +0 -3
  949. package/dist/bin/shell/chunks/gzip-ZJP5VIAQ.js +0 -3
  950. package/dist/bin/shell/chunks/head-B6GFQHKF.js +0 -3
  951. package/dist/bin/shell/chunks/help-CGUEOGXQ.js +0 -3
  952. package/dist/bin/shell/chunks/history-AQQWW3QB.js +0 -3
  953. package/dist/bin/shell/chunks/hostname-USNWOQCK.js +0 -3
  954. package/dist/bin/shell/chunks/html-to-markdown-3HJ7L7NL.js +0 -3
  955. package/dist/bin/shell/chunks/join-WRM6S6CO.js +0 -3
  956. package/dist/bin/shell/chunks/jq-3V5HDGLJ.js +0 -3
  957. package/dist/bin/shell/chunks/js-exec-F7JAZ4ZQ.js +0 -98
  958. package/dist/bin/shell/chunks/ln-LP4HMCSM.js +0 -3
  959. package/dist/bin/shell/chunks/ls-KBNHNZWQ.js +0 -3
  960. package/dist/bin/shell/chunks/md5sum-ZNYCDRQL.js +0 -3
  961. package/dist/bin/shell/chunks/mkdir-P4DKRCDX.js +0 -3
  962. package/dist/bin/shell/chunks/mv-QQK4FQX6.js +0 -3
  963. package/dist/bin/shell/chunks/nl-6TVYE4ZB.js +0 -3
  964. package/dist/bin/shell/chunks/od-Y3E3QXOL.js +0 -3
  965. package/dist/bin/shell/chunks/paste-LYNFXXCM.js +0 -3
  966. package/dist/bin/shell/chunks/printf-MR3FXCDE.js +0 -3
  967. package/dist/bin/shell/chunks/pwd-FCNDA467.js +0 -3
  968. package/dist/bin/shell/chunks/python3-R5OFWJIH.js +0 -13
  969. package/dist/bin/shell/chunks/readlink-25V57VOL.js +0 -3
  970. package/dist/bin/shell/chunks/rev-AJECDD4L.js +0 -3
  971. package/dist/bin/shell/chunks/rg-DZKA632H.js +0 -3
  972. package/dist/bin/shell/chunks/rm-ECNUFR66.js +0 -3
  973. package/dist/bin/shell/chunks/rmdir-DLOHIA7Q.js +0 -3
  974. package/dist/bin/shell/chunks/sed-IGRH7EGG.js +0 -3
  975. package/dist/bin/shell/chunks/seq-UXDJE6FB.js +0 -3
  976. package/dist/bin/shell/chunks/sha1sum-5QZSNFY3.js +0 -3
  977. package/dist/bin/shell/chunks/sha256sum-DI7JAVAU.js +0 -3
  978. package/dist/bin/shell/chunks/sleep-RPGCUUGX.js +0 -3
  979. package/dist/bin/shell/chunks/sort-HQPAFL76.js +0 -3
  980. package/dist/bin/shell/chunks/split-F6FSB5KI.js +0 -3
  981. package/dist/bin/shell/chunks/sqlite3-7TRACAE7.js +0 -3
  982. package/dist/bin/shell/chunks/stat-BD6KT3BP.js +0 -3
  983. package/dist/bin/shell/chunks/strings-6PE3YMPO.js +0 -3
  984. package/dist/bin/shell/chunks/tac-NERJXVOM.js +0 -3
  985. package/dist/bin/shell/chunks/tail-24F643A4.js +0 -3
  986. package/dist/bin/shell/chunks/tar-5HK3VMV2.js +0 -3
  987. package/dist/bin/shell/chunks/tee-5B7P2QRJ.js +0 -3
  988. package/dist/bin/shell/chunks/time-FN6VJGRS.js +0 -3
  989. package/dist/bin/shell/chunks/timeout-ZARIAF3K.js +0 -3
  990. package/dist/bin/shell/chunks/touch-DFGSVIX7.js +0 -3
  991. package/dist/bin/shell/chunks/tr-QQZYZ3CH.js +0 -3
  992. package/dist/bin/shell/chunks/tree-6D7SMPUR.js +0 -3
  993. package/dist/bin/shell/chunks/true-SKL4L7JP.js +0 -3
  994. package/dist/bin/shell/chunks/unexpand-3JWOSSBQ.js +0 -3
  995. package/dist/bin/shell/chunks/uniq-Q5UH5NL3.js +0 -3
  996. package/dist/bin/shell/chunks/wc-4HXNTHY3.js +0 -3
  997. package/dist/bin/shell/chunks/which-LCXKCLFC.js +0 -3
  998. package/dist/bin/shell/chunks/whoami-TZDZDU7T.js +0 -3
  999. package/dist/bin/shell/chunks/xan-TCTFON2Q.js +0 -3
  1000. package/dist/bin/shell/chunks/xan-view-XBMA362V.js +0 -3
  1001. package/dist/bin/shell/chunks/xargs-VTFN762K.js +0 -3
  1002. package/dist/bin/shell/chunks/yq-OB6PB5GY.js +0 -3
  1003. package/dist/bundle/chunks/alias-RTYYYW3D.js +0 -2
  1004. package/dist/bundle/chunks/awk2-SREAOJRG.js +0 -2
  1005. package/dist/bundle/chunks/base64-WIGL46P3.js +0 -2
  1006. package/dist/bundle/chunks/basename-UB3CIYNI.js +0 -2
  1007. package/dist/bundle/chunks/bash-F4KHPMTX.js +0 -2
  1008. package/dist/bundle/chunks/cat-LPZ6XNHG.js +0 -2
  1009. package/dist/bundle/chunks/chmod-TFEPA42X.js +0 -2
  1010. package/dist/bundle/chunks/chunk-27JIFWUR.js +0 -3
  1011. package/dist/bundle/chunks/chunk-2VDTE5BV.js +0 -14
  1012. package/dist/bundle/chunks/chunk-2VJJEDV2.js +0 -8
  1013. package/dist/bundle/chunks/chunk-4I3HOE5Z.js +0 -21
  1014. package/dist/bundle/chunks/chunk-4JLVZKHC.js +0 -8
  1015. package/dist/bundle/chunks/chunk-4WKZNNJK.js +0 -2
  1016. package/dist/bundle/chunks/chunk-55LZFN6S.js +0 -36
  1017. package/dist/bundle/chunks/chunk-5MV7Q5QB.js +0 -5
  1018. package/dist/bundle/chunks/chunk-6L65G6A7.js +0 -17
  1019. package/dist/bundle/chunks/chunk-6NYPZ4NX.js +0 -8
  1020. package/dist/bundle/chunks/chunk-6Y4TGEZL.js +0 -140
  1021. package/dist/bundle/chunks/chunk-7CSMHFIJ.js +0 -33
  1022. package/dist/bundle/chunks/chunk-AAGO7IQ5.js +0 -11
  1023. package/dist/bundle/chunks/chunk-AX2X3SZS.js +0 -11
  1024. package/dist/bundle/chunks/chunk-AXMYAPFA.js +0 -9
  1025. package/dist/bundle/chunks/chunk-BU36VZYL.js +0 -4
  1026. package/dist/bundle/chunks/chunk-BZUGFHVS.js +0 -2
  1027. package/dist/bundle/chunks/chunk-CJFAMHFC.js +0 -7
  1028. package/dist/bundle/chunks/chunk-CN5XGDNN.js +0 -6
  1029. package/dist/bundle/chunks/chunk-CQV3EITV.js +0 -2
  1030. package/dist/bundle/chunks/chunk-DVJY2RAX.js +0 -2
  1031. package/dist/bundle/chunks/chunk-FLMHFDSN.js +0 -5
  1032. package/dist/bundle/chunks/chunk-GE6OQDB2.js +0 -10
  1033. package/dist/bundle/chunks/chunk-GHB6M7KA.js +0 -2
  1034. package/dist/bundle/chunks/chunk-GRQJA2J7.js +0 -21
  1035. package/dist/bundle/chunks/chunk-H2TS57O5.js +0 -5
  1036. package/dist/bundle/chunks/chunk-H7WISVP3.js +0 -6
  1037. package/dist/bundle/chunks/chunk-HAIOEUEV.js +0 -63
  1038. package/dist/bundle/chunks/chunk-HBVMHTO5.js +0 -2
  1039. package/dist/bundle/chunks/chunk-IZ6KBTV7.js +0 -100
  1040. package/dist/bundle/chunks/chunk-J3LJZWL2.js +0 -6
  1041. package/dist/bundle/chunks/chunk-JA7M2FXG.js +0 -16
  1042. package/dist/bundle/chunks/chunk-JNYYVLEL.js +0 -35
  1043. package/dist/bundle/chunks/chunk-JTMQLUCH.js +0 -16
  1044. package/dist/bundle/chunks/chunk-K5JMLDHX.js +0 -13
  1045. package/dist/bundle/chunks/chunk-KAPG5ONA.js +0 -2
  1046. package/dist/bundle/chunks/chunk-KSBHIW2H.js +0 -19
  1047. package/dist/bundle/chunks/chunk-KTL5PAHY.js +0 -5
  1048. package/dist/bundle/chunks/chunk-KTPCYKBB.js +0 -3
  1049. package/dist/bundle/chunks/chunk-KWGBQNTV.js +0 -32
  1050. package/dist/bundle/chunks/chunk-MFDPAVC6.js +0 -14
  1051. package/dist/bundle/chunks/chunk-MFRETFZB.js +0 -6
  1052. package/dist/bundle/chunks/chunk-MIZIUC5M.js +0 -8
  1053. package/dist/bundle/chunks/chunk-MJLETYZI.js +0 -14
  1054. package/dist/bundle/chunks/chunk-MTHXXA6H.js +0 -6
  1055. package/dist/bundle/chunks/chunk-NGPDJCUE.js +0 -5
  1056. package/dist/bundle/chunks/chunk-OVH44QKR.js +0 -11
  1057. package/dist/bundle/chunks/chunk-PDUL32DM.js +0 -16
  1058. package/dist/bundle/chunks/chunk-PYDWFCTN.js +0 -11
  1059. package/dist/bundle/chunks/chunk-QAJKDPNS.js +0 -2
  1060. package/dist/bundle/chunks/chunk-QM4DZQWX.js +0 -287
  1061. package/dist/bundle/chunks/chunk-R4IFXNY5.js +0 -28
  1062. package/dist/bundle/chunks/chunk-R4QNMLOB.js +0 -12
  1063. package/dist/bundle/chunks/chunk-RBQG6ZUG.js +0 -3
  1064. package/dist/bundle/chunks/chunk-RCXNPPJY.js +0 -17
  1065. package/dist/bundle/chunks/chunk-S2BIZAWY.js +0 -7
  1066. package/dist/bundle/chunks/chunk-SAI2SPQQ.js +0 -8
  1067. package/dist/bundle/chunks/chunk-SETW5JBN.js +0 -9
  1068. package/dist/bundle/chunks/chunk-SJYEXC2Z.js +0 -14
  1069. package/dist/bundle/chunks/chunk-SY4HAUHP.js +0 -2
  1070. package/dist/bundle/chunks/chunk-TA74ENH7.js +0 -14
  1071. package/dist/bundle/chunks/chunk-TC2WHAIS.js +0 -2
  1072. package/dist/bundle/chunks/chunk-VACKIICN.js +0 -5
  1073. package/dist/bundle/chunks/chunk-VBLMIJON.js +0 -6
  1074. package/dist/bundle/chunks/chunk-WKPK7M56.js +0 -10
  1075. package/dist/bundle/chunks/chunk-WM5IJFMP.js +0 -8
  1076. package/dist/bundle/chunks/chunk-WPGQVBSY.js +0 -6
  1077. package/dist/bundle/chunks/chunk-WVRWIZF5.js +0 -23
  1078. package/dist/bundle/chunks/chunk-XEKXHOPO.js +0 -2
  1079. package/dist/bundle/chunks/chunk-XPK7ZFVA.js +0 -12
  1080. package/dist/bundle/chunks/chunk-XZUZRAAC.js +0 -10
  1081. package/dist/bundle/chunks/chunk-Y4LIDHSD.js +0 -7
  1082. package/dist/bundle/chunks/chunk-YRNR2VHY.js +0 -21
  1083. package/dist/bundle/chunks/chunk-YS4NUBYX.js +0 -9
  1084. package/dist/bundle/chunks/chunk-YWOZZRSK.js +0 -2
  1085. package/dist/bundle/chunks/chunk-ZDIT6ST5.js +0 -7
  1086. package/dist/bundle/chunks/clear-HKGFEOF6.js +0 -2
  1087. package/dist/bundle/chunks/column-PVOEF65J.js +0 -2
  1088. package/dist/bundle/chunks/comm-5QMYEAJL.js +0 -2
  1089. package/dist/bundle/chunks/cp-BISAAS7A.js +0 -2
  1090. package/dist/bundle/chunks/curl-PAWGO3EH.js +0 -26
  1091. package/dist/bundle/chunks/cut-NDMV7SPO.js +0 -2
  1092. package/dist/bundle/chunks/date-XKUEQ4WF.js +0 -2
  1093. package/dist/bundle/chunks/diff-TT4M7WM3.js +0 -2
  1094. package/dist/bundle/chunks/dirname-MPHRFUTI.js +0 -2
  1095. package/dist/bundle/chunks/du-572XNP42.js +0 -2
  1096. package/dist/bundle/chunks/echo-NDWZZHPO.js +0 -2
  1097. package/dist/bundle/chunks/env-DLFRY633.js +0 -2
  1098. package/dist/bundle/chunks/expand-T2TH4TBQ.js +0 -2
  1099. package/dist/bundle/chunks/expr-YLACLCSM.js +0 -2
  1100. package/dist/bundle/chunks/file-IPZJC3FQ.js +0 -2
  1101. package/dist/bundle/chunks/find-T5TGGXUU.js +0 -2
  1102. package/dist/bundle/chunks/flag-coverage-OHLSWDU5.js +0 -2
  1103. package/dist/bundle/chunks/fold-XR2JMFCW.js +0 -2
  1104. package/dist/bundle/chunks/grep-VUESTEZ7.js +0 -2
  1105. package/dist/bundle/chunks/gzip-HF3D26QX.js +0 -2
  1106. package/dist/bundle/chunks/head-AEMOMQSZ.js +0 -2
  1107. package/dist/bundle/chunks/help-HZ6M2CKN.js +0 -2
  1108. package/dist/bundle/chunks/history-WYYKSLSZ.js +0 -2
  1109. package/dist/bundle/chunks/hostname-C4HQXXUP.js +0 -2
  1110. package/dist/bundle/chunks/html-to-markdown-LXXMVQ3V.js +0 -2
  1111. package/dist/bundle/chunks/join-YIABB6WR.js +0 -2
  1112. package/dist/bundle/chunks/jq-OPEF5OPR.js +0 -2
  1113. package/dist/bundle/chunks/js-exec-SR6IMNWM.js +0 -97
  1114. package/dist/bundle/chunks/ln-4LGSXXGD.js +0 -2
  1115. package/dist/bundle/chunks/ls-ZJGQER7M.js +0 -2
  1116. package/dist/bundle/chunks/md5sum-LU7RVIB7.js +0 -2
  1117. package/dist/bundle/chunks/mkdir-MEPGZOB6.js +0 -2
  1118. package/dist/bundle/chunks/mv-W5BIQ646.js +0 -2
  1119. package/dist/bundle/chunks/nl-Q2L5XQWZ.js +0 -2
  1120. package/dist/bundle/chunks/od-RDSM4TQJ.js +0 -2
  1121. package/dist/bundle/chunks/paste-ABCY7E6C.js +0 -2
  1122. package/dist/bundle/chunks/printf-JPOOWRJC.js +0 -2
  1123. package/dist/bundle/chunks/pwd-WE6EN5AV.js +0 -2
  1124. package/dist/bundle/chunks/python3-JPCH6LLN.js +0 -12
  1125. package/dist/bundle/chunks/readlink-OPJF4DL5.js +0 -2
  1126. package/dist/bundle/chunks/rev-GCV6X22K.js +0 -2
  1127. package/dist/bundle/chunks/rg-EBMD72T4.js +0 -2
  1128. package/dist/bundle/chunks/rm-SSGETQVQ.js +0 -2
  1129. package/dist/bundle/chunks/rmdir-OC4ZLPYA.js +0 -2
  1130. package/dist/bundle/chunks/sed-DX2SGXMF.js +0 -2
  1131. package/dist/bundle/chunks/seq-M5EC7Q57.js +0 -2
  1132. package/dist/bundle/chunks/sha1sum-O6DM3TPQ.js +0 -2
  1133. package/dist/bundle/chunks/sha256sum-WPVZLZPS.js +0 -2
  1134. package/dist/bundle/chunks/sleep-HZ4QEFOK.js +0 -2
  1135. package/dist/bundle/chunks/sort-VW2NIZHW.js +0 -2
  1136. package/dist/bundle/chunks/split-NBMH43M2.js +0 -2
  1137. package/dist/bundle/chunks/sqlite3-UE3PJTDQ.js +0 -2
  1138. package/dist/bundle/chunks/stat-CD34IZ4P.js +0 -2
  1139. package/dist/bundle/chunks/strings-MCXFXPDL.js +0 -2
  1140. package/dist/bundle/chunks/tac-BQ7EDZW2.js +0 -2
  1141. package/dist/bundle/chunks/tail-GJMTLMNE.js +0 -2
  1142. package/dist/bundle/chunks/tar-WIZ3PDF4.js +0 -2
  1143. package/dist/bundle/chunks/tee-SGANDVNY.js +0 -2
  1144. package/dist/bundle/chunks/time-FCZCDIAM.js +0 -2
  1145. package/dist/bundle/chunks/timeout-VDIEAB4R.js +0 -2
  1146. package/dist/bundle/chunks/touch-UA33VN3N.js +0 -2
  1147. package/dist/bundle/chunks/tr-JNNR5JMS.js +0 -2
  1148. package/dist/bundle/chunks/tree-YLD52CNT.js +0 -2
  1149. package/dist/bundle/chunks/true-FHQXJXBE.js +0 -2
  1150. package/dist/bundle/chunks/unexpand-2TKXAENW.js +0 -2
  1151. package/dist/bundle/chunks/uniq-DMFKT3AB.js +0 -2
  1152. package/dist/bundle/chunks/wc-TZFYWFLA.js +0 -2
  1153. package/dist/bundle/chunks/which-XEM24D5D.js +0 -2
  1154. package/dist/bundle/chunks/whoami-XMTX52VE.js +0 -2
  1155. package/dist/bundle/chunks/xan-LKYWG2QQ.js +0 -2
  1156. package/dist/bundle/chunks/xan-view-YATJ4KAA.js +0 -2
  1157. package/dist/bundle/chunks/xargs-VDP7DLOU.js +0 -2
  1158. package/dist/bundle/chunks/yq-TVZ7R3O7.js +0 -2
  1159. package/dist/interpreter/helpers/statements.d.ts +0 -20
  1160. package/dist/interpreter/helpers/tilde.d.ts +0 -13
@@ -1,232 +1,239 @@
1
1
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
2
- import{a as ft,b as dt,c as je}from"./chunks/chunk-WNH3HOQA.js";import{c as Bn}from"./chunks/chunk-HBVMHTO5.js";import{a as ks,b as Ns}from"./chunks/chunk-SY4HAUHP.js";import{a as zn}from"./chunks/chunk-L2UW7DWF.js";import{a as bt,b as qe,c as cs}from"./chunks/chunk-DLL7UR66.js";import{a as ls,b as Di}from"./chunks/chunk-KAPG5ONA.js";import{a as gt,b as Ie}from"./chunks/chunk-VACKIICN.js";import{a as le}from"./chunks/chunk-7CSMHFIJ.js";import{a as os,b as _s,c as xc,d as yt,e as Cc,f as xs,g as Dc,h as Cs,i as Vn,j as Rc,k as Ic}from"./chunks/chunk-XEKXHOPO.js";import{a as Oe,b as Te,c as ke,d as ze,e as Le,f as Z,g as se,h as Me,i as wt,j as Ds,k as X,l as Rs,m as Et,n as Is,o as Be}from"./chunks/chunk-SAI2SPQQ.js";import"./chunks/chunk-STHBFACM.js";import{a as ut}from"./chunks/chunk-FOCWZZDE.js";import{a as ct}from"./chunks/chunk-W5DWRFSU.js";import{a as Fn}from"./chunks/chunk-BZUGFHVS.js";var Rt=[{name:"echo",load:async()=>(await import("./chunks/echo-NDWZZHPO.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-LPZ6XNHG.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-JPOOWRJC.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-ZJGQER7M.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-MEPGZOB6.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-OC4ZLPYA.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-UA33VN3N.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-SSGETQVQ.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-BISAAS7A.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-W5BIQ646.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-4LGSXXGD.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-TFEPA42X.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-WE6EN5AV.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-OPJF4DL5.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-AEMOMQSZ.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-GJMTLMNE.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-TZFYWFLA.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-CD34IZ4P.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-VUESTEZ7.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-VUESTEZ7.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-VUESTEZ7.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-EBMD72T4.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-DX2SGXMF.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-SREAOJRG.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-VW2NIZHW.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-DMFKT3AB.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-5QMYEAJL.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-NDMV7SPO.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-ABCY7E6C.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-JNNR5JMS.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-GCV6X22K.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-Q2L5XQWZ.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-XR2JMFCW.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-T2TH4TBQ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-2TKXAENW.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-MCXFXPDL.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-NBMH43M2.js")).split},{name:"column",load:async()=>(await import("./chunks/column-PVOEF65J.js")).column},{name:"join",load:async()=>(await import("./chunks/join-YIABB6WR.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-SGANDVNY.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-T5TGGXUU.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-UB3CIYNI.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-MPHRFUTI.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-YLD52CNT.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-572XNP42.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-DLFRY633.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-DLFRY633.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-RTYYYW3D.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-RTYYYW3D.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-WYYKSLSZ.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-VDP7DLOU.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-FHQXJXBE.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-FHQXJXBE.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-HKGFEOF6.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-F4KHPMTX.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-F4KHPMTX.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-OPEF5OPR.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-WIGL46P3.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-TT4M7WM3.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-XKUEQ4WF.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-HZ4QEFOK.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-VDIEAB4R.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-FCZCDIAM.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-M5EC7Q57.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-YLACLCSM.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-LU7RVIB7.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-O6DM3TPQ.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-WPVZLZPS.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-IPZJC3FQ.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-LXXMVQ3V.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-HZ6M2CKN.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-XEM24D5D.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-BQ7EDZW2.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-C4HQXXUP.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-XMTX52VE.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-RDSM4TQJ.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-HF3D26QX.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-HF3D26QX.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-HF3D26QX.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Rt.push({name:"tar",load:async()=>(await import("./chunks/tar-WIZ3PDF4.js")).tarCommand}),Rt.push({name:"yq",load:async()=>(await import("./chunks/yq-TVZ7R3O7.js")).yqCommand}),Rt.push({name:"xan",load:async()=>(await import("./chunks/xan-LKYWG2QQ.js")).xanCommand}),Rt.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-UE3PJTDQ.js")).sqlite3Command}));var Os=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Os.push({name:"python3",load:async()=>(await import("./chunks/python3-JPCH6LLN.js")).python3Command}),Os.push({name:"python",load:async()=>(await import("./chunks/python3-JPCH6LLN.js")).pythonCommand}));var Ts=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ts.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-SR6IMNWM.js")).jsExecCommand}),Ts.push({name:"node",load:async()=>(await import("./chunks/js-exec-SR6IMNWM.js")).nodeStubCommand}));var Ii=[{name:"curl",load:async()=>(await import("./chunks/curl-PAWGO3EH.js")).curlCommand}],Ri=new Map;function Ls(e){return{name:e.name,async execute(t,s){let r=Ri.get(e.name);if(r||(r=await Ie.runTrustedAsync(()=>e.load()),Ri.set(e.name,r)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:n}=await import("./chunks/flag-coverage-OHLSWDU5.js");n(s.coverage,e.name,t)}return r.execute(t,s)}}}function Oc(){return Rt.map(e=>e.name)}function Tc(){return Ii.map(e=>e.name)}function Oi(e){return(e?Rt.filter(s=>e.includes(s.name)):Rt).map(Ls)}function Ti(){return Ii.map(Ls)}function Lc(){return Os.map(e=>e.name)}function Li(){return Os.map(Ls)}function Mc(){return Ts.map(e=>e.name)}function Mi(){return Ts.map(Ls)}function Wi(e){return"load"in e&&typeof e.load=="function"}function Wc(e,t){return{name:e,trusted:!0,execute:t}}function Fi(e){let t=null;return{name:e.name,trusted:!0,async execute(s,r){return t||(t=await e.load()),t.execute(s,r)}}}function L(e){if(!e||e==="/")return"/";let t=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;t.startsWith("/")||(t=`/${t}`);let s=t.split("/").filter(n=>n&&n!=="."),r=[];for(let n of s)n===".."?r.pop():r.push(n);return`/${r.join("/")}`||"/"}function M(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}function It(e){let t=L(e);if(t==="/")return"/";let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}function vt(e,t){if(t.startsWith("/"))return L(t);let s=e==="/"?`/${t}`:`${e}/${t}`;return L(s)}function St(e,t){return e==="/"?`/${t}`:`${e}/${t}`}function zt(e,t){if(t.startsWith("/"))return L(t);let s=It(e);return L(St(s,t))}var Bt=new TextEncoder;function Fc(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var ht=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,r]of Object.entries(t))typeof r=="function"?this.writeFileLazy(s,r):Fc(r)?this.writeFileSync(s,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(s,r)}ensureParentDirs(t){let s=It(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,r,n){M(t,"write");let i=L(t);this.ensureParentDirs(i);let a=je(r),l=ft(s,a);this.data.set(i,{type:"file",content:l,mode:n?.mode??420,mtime:n?.mtime??new Date})}writeFileLazy(t,s,r){M(t,"write");let n=L(t);this.ensureParentDirs(n),this.data.set(n,{type:"file",lazy:s,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,s){let r=await s.lazy(),i={type:"file",content:typeof r=="string"?Bt.encode(r):r,mode:s.mode,mtime:s.mtime};return this.data.set(t,i),i}async readFile(t,s){let r=await this.readFileBuffer(t),n=je(s);return dt(r,n)}async readFileBytes(t){let s=await this.readFileBuffer(t);return dt(s,"binary")}async readFileBuffer(t){M(t,"open");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);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 n=await this.materializeLazy(s,r);return n.content instanceof Uint8Array?n.content:Bt.encode(n.content)}return r.content instanceof Uint8Array?r.content:Bt.encode(r.content)}async writeFile(t,s,r){this.writeFileSync(t,s,r)}async appendFile(t,s,r){M(t,"append");let n=L(t),i=this.data.get(n);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let a=je(r),l=ft(s,a);if(i?.type==="file"){let o=i;"lazy"in o&&(o=await this.materializeLazy(n,o));let u="content"in o&&o.content instanceof Uint8Array?o.content:Bt.encode("content"in o?o.content:""),c=new Uint8Array(u.length+l.length);c.set(u),c.set(l,u.length),this.data.set(n,{type:"file",content:c,mode:o.mode,mtime:new Date})}else this.writeFileSync(t,s,r)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){M(t,"stat");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Bt.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}async lstat(t){M(t,"lstat");let s=this.resolveIntermediateSymlinks(t),r=this.data.get(s);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(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Bt.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}resolveIntermediateSymlinks(t){let s=L(t);if(s==="/")return"/";let r=s.slice(1).split("/");if(r.length<=1)return s;let n="",i=new Set;for(let a=0;a<r.length-1;a++){let l=r[a];n=`${n}/${l}`;let o=this.data.get(n),u=0,c=40;for(;o&&o.type==="symlink"&&u<c;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(n),n=zt(n,o.target),o=this.data.get(n),u++}if(u>=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${n}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let s=L(t);if(s==="/")return"/";let r=s.slice(1).split("/"),n="",i=new Set;for(let a of r){n=`${n}/${a}`;let l=this.data.get(n),o=0,u=40;for(;l&&l.type==="symlink"&&o<u;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(n),n=zt(n,l.target),l=this.data.get(n),o++}if(o>=u)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return n}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){M(t,"mkdir");let r=L(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let n=It(r);if(n!=="/"&&!this.data.has(n))if(s?.recursive)this.mkdirSync(n,{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){M(t,"scandir");let s=L(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Set;for(;r&&r.type==="symlink";){if(n.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);n.add(s),s=zt(s,r.target),r=this.data.get(s)}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=s==="/"?"/":`${s}/`,a=new Map;for(let[l,o]of this.data.entries())if(l!==s&&l.startsWith(i)){let u=l.slice(i.length),c=u.split("/")[0];c&&!u.includes("/",c.length)&&!a.has(c)&&a.set(c,{name:c,isFile:o.type==="file",isDirectory:o.type==="directory",isSymbolicLink:o.type==="symlink"})}return Array.from(a.values()).sort((l,o)=>l.name<o.name?-1:l.name>o.name?1:0)}async rm(t,s){M(t,"rm");let r=L(t),n=this.data.get(r);if(!n){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(n.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of i){let l=St(r,a);await this.rm(l,s)}}}this.data.delete(r)}async cp(t,s,r){M(t,"cp"),M(s,"cp");let n=L(t),i=L(s),a=this.data.get(n);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(a.type==="file")if(this.ensureParentDirs(i),"content"in a){let l=a.content instanceof Uint8Array?new Uint8Array(a.content):a.content;this.data.set(i,{...a,content:l})}else this.data.set(i,{...a});else if(a.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(n);for(let o of l){let u=St(n,o),c=St(i,o);await this.cp(u,c,r)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){return vt(t,s)}async chmod(t,s){M(t,"chmod");let r=L(t),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);n.mode=s}async symlink(t,s){M(s,"symlink");let r=L(s);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){M(t,"link"),M(s,"link");let r=L(t),n=L(s),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(n))throw new Error(`EEXIST: file already exists, link '${s}'`);let a=i;"lazy"in a&&(a=await this.materializeLazy(r,a)),this.ensureParentDirs(n),this.data.set(n,{type:"file",content:a.content,mode:a.mode,mtime:a.mtime})}async readlink(t){M(t,"readlink");let s=L(t),r=this.data.get(s);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){M(t,"realpath");let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,r){M(t,"utimes");let n=L(t),i=this.resolvePathWithSymlinks(n),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=r}};var Vi="5.1.0(1)-release",zi="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function jn(e){let{pid:t,ppid:s,uid:r,gid:n}=e;return`Name: bash
2
+ import{a as xt,b as Pt,c as nt}from"./chunks/chunk-WNH3HOQA.js";import{a as pr}from"./chunks/chunk-BRJERIF4.js";import{c as Ms,e as Ta}from"./chunks/chunk-KIGPB52X.js";import{a as dr,b as hr,c as Tn,d as Ln}from"./chunks/chunk-K3XJ2WT4.js";import{a as Lt}from"./chunks/chunk-J2OBOJ64.js";import{a as Ls}from"./chunks/chunk-L2UW7DWF.js";import{a as Tt,b as Ke,c as Fn}from"./chunks/chunk-DLL7UR66.js";import{a as Wn,b as _a}from"./chunks/chunk-AI5LSBJC.js";import{a as ye}from"./chunks/chunk-XVL654YD.js";import{a as Ct,b as Ie}from"./chunks/chunk-UBTKJ6MG.js";import"./chunks/chunk-6D3WD6YU.js";import{c as It,d as hn}from"./chunks/chunk-AH7VTVWU.js";import"./chunks/chunk-STHBFACM.js";import{a as B,b as vt,c as F,d as pn,e as _t,f as At,g as mn}from"./chunks/chunk-YUSFCOM7.js";import{a as Ia,b as Ze,c as He,d as Me,e as et,f as Be,g as H,h as oe,i as Qe,j as Rt,k as gr,l as P,m as We,n as Ot,o as wr,p as tt}from"./chunks/chunk-EFORKKSH.js";import{a as M,b as Mn,c as Bn,d as ju,e as Dt,f as _s,g as mr,h as Gu,i as yr,j as Ts,k as Zu,l as Hu}from"./chunks/chunk-GN6CQ3J4.js";import{a as ht}from"./chunks/chunk-FOCWZZDE.js";import{a as St}from"./chunks/chunk-W5DWRFSU.js";import{a as Is}from"./chunks/chunk-NCUTH6QL.js";var en=[{name:"echo",load:async()=>(await import("./chunks/echo-HZOVZAPR.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-636HYSH4.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-QHD2JRWQ.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-R5CQLZQM.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-WDDKK2P3.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-WZKAT6M5.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-W4DF6Z4T.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-JQ4GDKDD.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-FKTQRFYJ.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-XSJA2FNL.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-VYDFOFNO.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-4CIOYX5Q.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-76BPYV5F.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-IY6QKK2P.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-UCOA3VQC.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-G3W6PNG3.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-RUR7HE5O.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-MLNSW25G.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-S6SNTIHZ.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-S6SNTIHZ.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-S6SNTIHZ.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-OUJZ5DH6.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-TZIPJOGL.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-IPNBFNH2.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-RWPUW5FY.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-ZU3EODNI.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-3KPFH3J4.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-KNDNAFPT.js")).split},{name:"column",load:async()=>(await import("./chunks/column-LKMDIDCH.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-DWWMZFO5.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-PR3M44X6.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:"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-D6N4QCAJ.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-OXGTKKDA.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-CSARC7WF.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-FN2DXAEE.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-VPYWSKDR.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-SYQCWBMZ.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-NERE2JJ2.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-5R2GKXC6.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-SHRJJ4PX.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-YC4YEI4P.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-NUF6QEX4.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-QDDMBDU7.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-YXD2NNIU.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-BTI6CWY4.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-BTI6CWY4.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-BTI6CWY4.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(en.push({name:"tar",load:async()=>(await import("./chunks/tar-GLX6QUHW.js")).tarCommand}),en.push({name:"yq",load:async()=>(await import("./chunks/yq-ZGB3W46S.js")).yqCommand}),en.push({name:"xan",load:async()=>(await import("./chunks/xan-KKPV2TJ3.js")).xanCommand}),en.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-WWZJZW37.js")).sqlite3Command}));var Er=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Er.push({name:"python3",load:async()=>(await import("./chunks/python3-QDNG2UXX.js")).python3Command}),Er.push({name:"python",load:async()=>(await import("./chunks/python3-QDNG2UXX.js")).pythonCommand}));var br=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(br.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-PNUEDFT5.js")).jsExecCommand}),br.push({name:"node",load:async()=>(await import("./chunks/js-exec-PNUEDFT5.js")).nodeStubCommand}));var Ma=[{name:"curl",load:async()=>(await import("./chunks/curl-DEHFBW27.js")).curlCommand}],La=new Map;function Sr(e){return{name:e.name,async execute(t,n){let r=La.get(e.name);if(r||(r=await Ie.runTrustedAsync(()=>e.load()),La.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await import("./chunks/flag-coverage-THYQHOT3.js");s(n.coverage,e.name,t)}return r.execute(t,n)}}}function Qu(){return en.map(e=>e.name)}function Ku(){return Ma.map(e=>e.name)}function Ba(e){return(e?en.filter(n=>e.includes(n.name)):en).map(Sr)}function Wa(){return Ma.map(Sr)}function Xu(){return Er.map(e=>e.name)}function Fa(){return Er.map(Sr)}function Yu(){return br.map(e=>e.name)}function Va(){return br.map(Sr)}var za=new WeakMap,qa=new WeakSet;function vr(e){let t=za.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),za.set(e,t),qa.add(t)),t}function Ua(e){return qa.has(e)}var ja={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,maxGlobOperations:1e6,maxStringLength:67108864,maxArrayElements:1e6,maxHeredocSize:67108864,maxSubstitutionDepth:50,maxBraceExpansionResults:1e5,maxOutputSize:268435456,maxFileDescriptors:4096,maxSourceDepth:100},Ju={...ja,maxSourceBytes:8*1024*1024,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,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 Ar(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?Ju:ja;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,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 ef(e){let{executionLimits:t,executionLimitProfile:n,fs:r,stdin:s=_s,...i}=e;return{fs:r,fsIdentity:i.fsIdentity??vr(r),cwd:"/",env:new Map,stdin:s,limits:Ar(t,n),...i}}function Ga(e){return"load"in e&&typeof e.load=="function"}function tf(e,t,n={}){return{name:e,trusted:n.trusted!==!1,execute:t}}function Za(e){let t=null,n=null;return{name:e.name,trusted:e.trusted!==!1,async execute(r,s){if(!t){let a=n;a||(a=e.load().then(o=>(t=o,o)),n=a);try{t=await a}catch(o){throw n===a&&(n=null),o}}let i=t;if(!i)throw new Error(`Failed to load command: ${e.name}`);return i.execute(r,s)}}}var Ha=Object.freeze(Object.create(null)),xr=class{limits;signal;commandCount=0;workUnits=0;liveBytes=0;inputBytes=0;outputBytes=0;countersByKind=new Map;bytesByKind=new Map;depthByKind=new Map;cleanupCallbacks=[];poisoned;closed=!1;startedAt=Date.now();get remainingLiveBytes(){return Math.max(0,this.limits.maxLiveBytes-this.liveBytes)}get outputBytesUsed(){return this.outputBytes}constructor(t,n=void 0){this.limits=t,this.signal=n}fail(t){throw this.poisoned??=t,this.poisoned}poisonAfterAbort(t){this.poisoned??=t}assertUsable(){if(this.poisoned)throw this.poisoned;if(this.closed)throw new Error("execution budget is already closed");this.throwIfAborted()}chargeCommand(){return this.consume("commands",1,"execution")}consumeWork(t=1,n="execution"){return this.consume("work",t,n)}consumeLimited(t,n,r,s=t){this.assertUsable();let i=this.countersByKind.get(t)??0;return(!Number.isSafeInteger(n)||n<0||!Number.isSafeInteger(r)||r<0||n>r-i)&&this.fail(new P(`${s}: ${t} work limit exceeded (${r})`,"iterations")),n>this.limits.maxWorkUnits-this.workUnits&&this.fail(new P(`${s}: aggregate work limit exceeded (${this.limits.maxWorkUnits})`,"iterations")),this.countersByKind.set(t,i+n),this.workUnits+=n,i+n}consumeInput(t,n="execution"){return this.assertUsable(),(!Number.isSafeInteger(t)||t<0||t>this.limits.maxInputBytes-this.inputBytes)&&this.fail(new P(`${n}: aggregate input size limit exceeded (${this.limits.maxInputBytes} bytes)`,"string_length")),this.inputBytes+=t,this.inputBytes}consume(t,n=1,r=t){this.assertUsable();let s=this.countersByKind.get(t)??0,i=t==="commands"?this.commandCount:this.workUnits,a=t==="commands"?this.limits.maxCommandCount:this.limits.maxWorkUnits;(!Number.isSafeInteger(n)||n<0||n>a-i)&&this.fail(new P(t==="commands"?`too many commands executed (>${a}), increase executionLimits.maxCommandCount`:`${r}: ${t} work limit exceeded (${a})`,t==="commands"?"commands":"iterations"));let o=i+n;return t==="commands"?this.commandCount=o:this.workUnits=o,this.countersByKind.set(t,s+n),o}reserveBytes(t,n,r){this.assertUsable();let s=typeof t=="string"?t:"live",i=typeof t=="string"?n:t,a=typeof t=="string"?r??s:n??"execution";(!Number.isSafeInteger(i)||i<0||i>this.limits.maxLiveBytes-this.liveBytes)&&this.fail(new P(`${a}: live byte limit exceeded (${this.limits.maxLiveBytes} bytes)`,"string_length")),this.liveBytes+=i,this.bytesByKind.set(s,(this.bytesByKind.get(s)??0)+i);let o=!1;return{release:()=>{if(o)return;o=!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 a=i==="bytes"?n.length:M(n);(!Number.isSafeInteger(s)||s<0||s>a)&&this.fail(new P(`${r}: invalid ${t} accounting`,"output_size"));let o=a-s;return o>this.limits.maxOutputSize-this.outputBytes&&this.fail(new P(`${r}: total output size exceeded (>${this.limits.maxOutputSize} bytes), increase executionLimits.maxOutputSize`,"output_size")),this.outputBytes+=o,a}accountResult(t,n="execution",r=Number.POSITIVE_INFINITY){let s=t.internalOutputAccounting,i=Math.min(s?.stdout??0,r),a=Math.min(s?.stderr??0,Math.max(0,r-i)),o=this.appendOutput("stdout",t.stdout,n,i,t.stdoutKind==="bytes"||t.stdoutEncoding==="binary"?"bytes":"text"),l=this.appendOutput("stderr",t.stderr,n,a);return Object.isExtensible(t)?(t.internalOutputAccounting={stdout:o,stderr:l},t):o===0&&l===0?t:{...t,internalOutputAccounting:{stdout:o,stderr:l}}}relinquishOutput(t,n,r){this.assertUsable(),r!==Ha&&this.fail(new P(`${n}: unauthorized output accounting release`,"output_size")),(!Number.isSafeInteger(t)||t<0||t>this.outputBytes)&&this.fail(new P(`${n}: invalid output accounting release`,"output_size")),this.outputBytes-=t}enterDepth(t,n=this.limits.maxCallDepth,r){this.assertUsable();let s=typeof n=="number"?n:this.limits.maxCallDepth,i=typeof n=="string"?n:r??t,a=this.depthByKind.get(t)??0;a>=s&&this.fail(new P(`${i}: maximum depth (${s}) exceeded`,"recursion")),this.depthByKind.set(t,a+1);let o=!1;return{release:()=>{if(o)return;o=!0;let l=(this.depthByKind.get(t)??1)-1;l<=0?this.depthByKind.delete(t):this.depthByKind.set(t,l)}}}throwIfAborted(t="execution"){this.signal?.aborted&&this.fail(new We("",`bash: ${t} aborted
3
+ `)),Date.now()-this.startedAt>this.limits.maxExecutionTimeMs&&this.fail(new We("",`bash: ${t} exceeded execution deadline (${this.limits.maxExecutionTimeMs}ms)
4
+ `))}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,a=await Promise.race([Promise.resolve().then(this.cleanupCallbacks[r]).then(()=>({ok:!0}),o=>({ok:!1,error:o})),new Promise(o=>{i=Tn(()=>o({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(Ln(i),!a.ok&&(t.push(a.error),Date.now()>=n))break}catch(s){t.push(s)}if(this.cleanupCallbacks.length=0,this.depthByKind.clear(),this.bytesByKind.clear(),this.liveBytes=0,t.length>0)throw new AggregateError(t,"execution cleanup failed")}assertExecDepth(t){this.assertUsable(),t>this.limits.maxExecDepth&&this.fail(new P(`maximum nested execution depth (${this.limits.maxExecDepth}) exceeded`,"recursion"))}};function Qa(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 Ka(e,t,n="pipeline"){e.relinquishOutput(t,n,Ha)}var tn=new TextEncoder;function nf(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var $t=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 a=this.wouldReleaseBytes(r),o=i instanceof Uint8Array?this.contentReferences.has(i)?0:i.byteLength:this.storedByteLength(i);if(o>this.maxTotalBytes-this.retainedBytes+a)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+=o-a,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):nf(s)?this.writeFileSync(r,s.content,void 0,{mode:s.mode,mtime:s.mtime}):this.writeFileSync(r,s)}ensureParentDirs(t){let n=pn(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){F(t,"write");let i=B(t);this.ensureParentDirs(i);let a=nt(r);this.assertCanAllocate(i,this.contentByteLength(n,a));let o=xt(n,a);this.setEntry(i,{type:"file",content:o,mode:s?.mode??420,mtime:s?.mtime??new Date})}writeFileLazy(t,n,r){F(t,"write");let s=B(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 n.lazy(),s=typeof r=="string"?tn.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=nt(n);return Pt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Pt(n,"binary")}async readFileBuffer(t){F(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:tn.encode(s.content)}return r.content instanceof Uint8Array?r.content:tn.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){F(t,"append");let s=B(t),i=this.data.get(s);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let a=nt(r),o=this.contentByteLength(n,a);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:tn.encode("content"in l?l.content:"");this.assertCanAllocate(s,c.byteLength+o);let u=xt(n,a),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){F(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=tn.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){F(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=tn.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=B(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",i=new Set;for(let a=0;a<r.length-1;a++){let o=r[a];s=`${s}/${o}`;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=mn(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=B(t);if(n==="/")return"/";let r=n.slice(1).split("/"),s="",i=new Set;for(let a of r){s=`${s}/${a}`;let o=this.data.get(s),l=0,c=40;for(;o&&o.type==="symlink"&&l<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(s),s=mn(s,o.target),o=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)}mkdirSync(t,n){F(t,"mkdir");let r=B(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=pn(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){F(t,"scandir");let n=B(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=mn(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}/`,a=new Map;for(let[o,l]of this.data.entries())if(o!==n&&o.startsWith(i)){let c=o.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!a.has(u)&&a.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(a.values()).sort((o,l)=>o.name<l.name?-1:o.name>l.name?1:0)}async rm(t,n){F(t,"rm");let r=B(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 a of i){let o=At(r,a);await this.rm(o,n)}}}this.deleteEntry(r)}async cp(t,n,r){F(t,"cp"),F(n,"cp");let s=B(t),i=B(n),a=this.data.get(s);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(a.type==="file")if(this.ensureParentDirs(i),"content"in a){let o=a.content instanceof Uint8Array?a.content.byteLength:tn.encode(a.content).byteLength;this.assertCanAllocate(i,o);let l=a.content instanceof Uint8Array?new Uint8Array(a.content):a.content;this.setEntry(i,{...a,content:l})}else this.setEntry(i,{...a});else if(a.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(vt(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(s);for(let l of o){let c=At(s,l),u=At(i,l);await this.cp(c,u,r)}}}async mv(t,n){F(t,"mv"),F(n,"mv");let r=B(t),s=B(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"&&vt(r,s))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);if(i.type==="directory"){await this.mkdir(s,{recursive:!0});let a=await this.readdir(r);for(let o of a)await this.mv(At(r,o),At(s,o));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 _t(t,n)}async chmod(t,n){F(t,"chmod");let r=B(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){F(n,"symlink");let r=B(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){F(t,"link"),F(n,"link");let r=B(t),s=B(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 a=i;"lazy"in a&&(a=await this.materializeLazy(r,a)),this.ensureParentDirs(s);let o={type:"file",content:a.content,mode:a.mode,mtime:a.mtime};this.entryIdentities.set(o,this.identityFor(a)),this.setEntry(s,o)}async readlink(t){F(t,"readlink");let n=B(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){F(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){F(t,"utimes");let s=B(t),i=this.resolvePathWithSymlinks(s),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=r}};var Xa="5.1.0(1)-release",Ya="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function Ws(e){let{pid:t,ppid:n,uid:r,gid:s}=e;return`Name: bash
3
5
  State: R (running)
4
6
  Pid: ${t}
5
- PPid: ${s}
7
+ PPid: ${n}
6
8
  Uid: ${r} ${r} ${r} ${r}
7
- Gid: ${n} ${n} ${n} ${n}
8
- `}function Vc(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function zc(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 Bc(e){e.mkdirSync("/dev",{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 qc(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${zi}
9
+ Gid: ${s} ${s} ${s} ${s}
10
+ `}function rf(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function sf(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 af(e){e.mkdirSync("/dev",{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 of(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Ya}
9
11
  `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
10
- `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>jn(t)):e.writeFileSync("/proc/self/status",jn(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 Bi(e,t,s={pid:1,ppid:0,uid:1e3,gid:1e3}){Vc(e)&&(zc(e,t),Bc(e),qc(e,s))}var jc=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],Uc=["braceexpand","hashall","interactive-comments"];function Un(e){let t=[],s=[...Uc.map(r=>({name:r,enabled:!0})),...jc.map(r=>({name:r,enabled:e[r]}))].sort((r,n)=>r.name.localeCompare(n.name));for(let r of s)r.enabled&&t.push(r.name);return t.join(":")}function jt(e){e.state.env.set("SHELLOPTS",Un(e.state.options))}var Zc=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Zn(e){let t=[];for(let s of Zc)e[s]&&t.push(s);return t.join(":")}function Gn(e){e.state.env.set("BASHOPTS",Zn(e.state.shoptOptions))}var I={script(e){return{type:"Script",statements:e}},statement(e,t=[],s=!1,r,n){let i={type:"Statement",pipelines:e,operators:t,background:s};return r&&(i.deferredError=r),n!==void 0&&(i.sourceText=n),i},pipeline(e,t=!1,s=!1,r=!1,n){return{type:"Pipeline",commands:e,negated:t,timed:s,timePosix:r,pipeStderr:n}},simpleCommand(e,t=[],s=[],r=[]){return{type:"SimpleCommand",name:e,args:t,assignments:s,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}},assignment(e,t,s=!1,r=null){return{type:"Assignment",name:e,value:t,append:s,array:r}},redirection(e,t,s=null,r){let n={type:"Redirection",fd:s,operator:e,target:t};return r&&(n.fdVariable=r),n},hereDoc(e,t,s=!1,r=!1){return{type:"HereDoc",delimiter:e,content:t,stripTabs:s,quoted:r}},ifNode(e,t=null,s=[]){return{type:"If",clauses:e,elseBody:t,redirections:s}},forNode(e,t,s,r=[]){return{type:"For",variable:e,words:t,body:s,redirections:r}},whileNode(e,t,s=[]){return{type:"While",condition:e,body:t,redirections:s}},untilNode(e,t,s=[]){return{type:"Until",condition:e,body:t,redirections:s}},caseNode(e,t,s=[]){return{type:"Case",word:e,items:t,redirections:s}},caseItem(e,t,s=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:s}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,s=[],r){return{type:"FunctionDef",name:e,body:t,redirections:s,sourceFile:r}},conditionalCommand(e,t=[],s){return{type:"ConditionalCommand",expression:e,redirections:t,line:s}},arithmeticCommand(e,t=[],s){return{type:"ArithmeticCommand",expression:e,redirections:t,line:s}}};function qi(e,t){let s=e.length,r=t+3,n=2,i=!1,a=!1;for(;r<s&&n>0;){let l=e[r];if(i){l==="'"&&(i=!1),r++;continue}if(a){if(l==="\\"){r+=2;continue}l==='"'&&(a=!1),r++;continue}if(l==="'"){i=!0,r++;continue}if(l==='"'){a=!0,r++;continue}if(l==="\\"){r+=2;continue}if(l==="("){n++,r++;continue}if(l===")"){if(n--,n===1){let o=r+1;return!(o<s&&e[o]===")")}if(n===0)return!1;r++;continue}if(n===1&&(l==="|"&&r+1<s&&e[r+1]==="|"||l==="&"&&r+1<s&&e[r+1]==="&"||l==="|"&&r+1<s&&e[r+1]!=="|"))return!0;r++}return!1}function Hn(e,t){let s="",r=t,n=i=>i===" "||i===" "||i===`
11
- `||i===";"||i==="&"||i==="|"||i==="<"||i===">"||i==="("||i===")";for(;r<e.length;){let i=e[r];if(i==="'"){for(r++;r<e.length&&e[r]!=="'";)s+=e[r],r++;r<e.length&&r++;continue}if(i==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length&&r++,s+=e[r],r++;r<e.length&&r++;continue}if(i==="\\"&&r+1<e.length){s+=e[r+1],r+=2;continue}if(n(i))break;s+=i,r++}return{delim:s,endPos:r}}function Gc(e,t,s){let r=t+1;for(let{delim:n,stripTabs:i}of s)for(;;){if(r>=e.length)return e.length;let a=e.indexOf(`
12
- `,r);a===-1&&(a=e.length);let l=e.slice(r,a);if(i&&(l=l.replace(/^\t+/,"")),l===n){r=a+1;break}if(a>=e.length)return e.length;r=a+1}return Math.min(r,e.length)}function ji(e,t,s,r){let n=t+2,i=1,a=n,l=!1,o=!1,u=0,c=!1,f="",d=[],h=0;for(;a<e.length&&i>0;){let b=e[a];if(l)b==="'"&&(l=!1);else if(o)b==="\\"&&a+1<e.length?a++:b==='"'&&(o=!1);else{if(b==="("&&e[a+1]==="("?h++:b===")"&&e[a+1]===")"&&h>0&&h--,h===0&&b==="<"&&e[a+1]==="<"&&e[a+2]!=="<"){let v=a+2,E=!1;for(e[v]==="-"&&(E=!0,v++);e[v]===" "||e[v]===" ";)v++;let{delim:w,endPos:S}=Hn(e,v);if(w.length>0){d.push({delim:w,stripTabs:E}),f="",a=S;continue}}if(b===`
13
- `&&d.length>0){let v=Gc(e,a,d);d.length=0,f="",a=v;continue}b==="'"?(l=!0,f=""):b==='"'?(o=!0,f=""):b==="\\"&&a+1<e.length?(a++,f=""):/[a-zA-Z_]/.test(b)?f+=b:(f==="case"?(u++,c=!1):f==="in"&&u>0?c=!0:f==="esac"&&u>0&&(u--,c=!1),f="",b==="("?a>0&&e[a-1]==="$"?i++:c||i++:b===")"?c?c=!1:i--:b===";"&&u>0&&a+1<e.length&&e[a+1]===";"&&(c=!0))}i>0&&a++}i>0&&r("unexpected EOF while looking for matching `)'");let m=e.slice(n,a),y=s().parse(m);return{part:I.commandSubstitution(y,!1),endIndex:a+1}}function Ui(e,t,s,r,n){let a=t+1,l="";for(;a<e.length&&e[a]!=="`";)if(e[a]==="\\"){let c=e[a+1];c==="$"||c==="`"||c==="\\"||c===`
14
- `||s&&c==='"'?(c!==`
15
- `&&(l+=c),a+=2):(l+=e[a],a++)}else l+=e[a],a++;a>=e.length&&n("unexpected EOF while looking for matching ``'");let u=r().parse(l);return{part:I.commandSubstitution(u,!0),endIndex:a+1}}var Hc=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 At=class extends Error{line;column;constructor(t,s,r){super(`line ${s}: ${t}`),this.line=s,this.column=r,this.name="LexerError"}},Zi=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]]);function Gi(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return!1;let s=e.slice(t[0].length);if(s===""||s==="+")return!0;if(s[0]==="["){let r=0,n=0;for(;n<s.length;n++)if(s[n]==="[")r++;else if(s[n]==="]"&&(r--,r===0))break;if(r!==0||n>=s.length)return!1;let i=s.slice(n+1);return i===""||i==="+"}return!1}function Hi(e){let t=0;for(let s=0;s<e.length;s++){let r=e[s];if(r==="[")t++;else if(r==="]")t--;else{if(t===0&&r==="=")return s;if(t===0&&r==="+"&&e[s+1]==="=")return s+1}}return-1}var Qc=[[";",";","&",g.SEMI_SEMI_AND],["<","<","<",g.TLESS],["&",">",">",g.AND_DGREAT]],Kc=[["[","[",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]],Xc=new Map([["|",g.PIPE],["&",g.AMP],[";",g.SEMICOLON],["(",g.LPAREN],[")",g.RPAREN],["<",g.LESS],[">",g.GREAT]]);function Yc(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Qi(e){return e===" "||e===" "||e===`
16
- `||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var Ws=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];dparenDepth=0;maxHeredocSize;constructor(t,s){this.input=t,this.maxHeredocSize=s?.maxHeredocSize??Hc}tokenize(){let s=this.input.length,r=this.tokens,n=this.pendingHeredocs;for(;this.pos<s;){if(n.length>0&&r.length>0&&r[r.length-1].type===g.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=s)break;let i=this.nextToken();i&&r.push(i)}return r.push({type:g.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let t=this.input,s=t.length,r=this.pos,n=this.column,i=this.line;for(;r<s;){let a=t[r];if(a===" "||a===" ")r++,n++;else if(a==="\\"&&t[r+1]===`
17
- `)r+=2,i++,n=1;else break}this.pos=r,this.column=n,this.line=i}nextToken(){let t=this.input,s=this.pos,r=this.line,n=this.column,i=t[s],a=t[s+1],l=t[s+2];if(i==="#"&&this.dparenDepth===0)return this.readComment(s,r,n);if(i===`
18
- `)return this.pos=s+1,this.line++,this.column=1,{type:g.NEWLINE,value:`
19
- `,start:s,end:s+1,line:r,column:n};if(i==="<"&&a==="<"&&l==="-")return this.pos=s+3,this.column=n+3,this.registerHeredocFromLookahead(!0),this.makeToken(g.DLESSDASH,"<<-",s,r,n);for(let[u,c,f,d]of Qc)if(i===u&&a===c&&l===f)return this.pos=s+3,this.column=n+3,this.makeToken(d,u+c+f,s,r,n);if(i==="<"&&a==="<")return this.pos=s+2,this.column=n+2,this.registerHeredocFromLookahead(!1),this.makeToken(g.DLESS,"<<",s,r,n);if(i==="("&&a==="(")return this.dparenDepth>0?(this.pos=s+1,this.column=n+1,this.dparenDepth++,this.makeToken(g.LPAREN,"(",s,r,n)):this.looksLikeNestedSubshells(s+2)||this.dparenClosesWithSpacedParens(s+2)?(this.pos=s+1,this.column=n+1,this.makeToken(g.LPAREN,"(",s,r,n)):(this.pos=s+2,this.column=n+2,this.dparenDepth=1,this.makeToken(g.DPAREN_START,"((",s,r,n));if(i===")"&&a===")")return this.dparenDepth===1?(this.pos=s+2,this.column=n+2,this.dparenDepth=0,this.makeToken(g.DPAREN_END,"))",s,r,n)):this.dparenDepth>1?(this.pos=s+1,this.column=n+1,this.dparenDepth--,this.makeToken(g.RPAREN,")",s,r,n)):(this.pos=s+1,this.column=n+1,this.makeToken(g.RPAREN,")",s,r,n));for(let[u,c,f]of Kc)if(!(u==="("&&c==="("||u===")"&&c===")")&&!(this.dparenDepth>0&&u===";"&&(f===g.DSEMI||f===g.SEMI_AND||f===g.SEMI_SEMI_AND))&&i===u&&a===c){if(f===g.DBRACK_START||f===g.DBRACK_END){let d=t[s+2];if(d!==void 0&&d!==" "&&d!==" "&&d!==`
20
- `&&d!==";"&&d!=="&"&&d!=="|"&&d!=="("&&d!==")"&&d!=="<"&&d!==">")break}return this.pos=s+2,this.column=n+2,this.makeToken(f,u+c,s,r,n)}if(i==="("&&this.dparenDepth>0)return this.pos=s+1,this.column=n+1,this.dparenDepth++,this.makeToken(g.LPAREN,"(",s,r,n);if(i===")"&&this.dparenDepth>1)return this.pos=s+1,this.column=n+1,this.dparenDepth--,this.makeToken(g.RPAREN,")",s,r,n);let o=Xc.get(i);if(o!==void 0)return this.pos=s+1,this.column=n+1,this.makeToken(o,i,s,r,n);if(i==="{"){let u=this.scanFdVariable(s);return u!==null?(this.pos=u.end,this.column=n+(u.end-s),{type:g.FD_VARIABLE,value:u.varname,start:s,end:u.end,line:r,column:n}):a==="}"?(this.pos=s+2,this.column=n+2,{type:g.WORD,value:"{}",start:s,end:s+2,line:r,column:n,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(s)!==null?this.readWordWithBraceExpansion(s,r,n):this.scanLiteralBraceWord(s)!==null?this.readWordWithBraceExpansion(s,r,n):a!==void 0&&a!==" "&&a!==" "&&a!==`
21
- `?this.readWord(s,r,n):(this.pos=s+1,this.column=n+1,this.makeToken(g.LBRACE,"{",s,r,n))}return i==="}"?this.isWordCharFollowing(s+1)?this.readWord(s,r,n):(this.pos=s+1,this.column=n+1,this.makeToken(g.RBRACE,"}",s,r,n)):i==="!"?a==="="?(this.pos=s+2,this.column=n+2,this.makeToken(g.WORD,"!=",s,r,n)):(this.pos=s+1,this.column=n+1,this.makeToken(g.BANG,"!",s,r,n)):this.readWord(s,r,n)}looksLikeNestedSubshells(t){let s=this.input,r=s.length,n=t;for(;n<r&&(s[n]===" "||s[n]===" ");)n++;if(n>=r)return!1;let i=s[n];if(i==="(")return this.looksLikeNestedSubshells(n+1);let a=/[a-zA-Z_]/.test(i),l=i==="!"||i==="[";if(!a&&!l)return!1;let o=n;for(;o<r&&/[a-zA-Z0-9_\-.]/.test(s[o]);)o++;if(o===n)return l;let u=o;for(;u<r&&(s[u]===" "||s[u]===" ");)u++;if(u>=r)return!1;let c=s[u];if(c==="="&&s[u+1]!=="="||c===`
22
- `||o===u&&/[+\-*/%<>&|^!~?:]/.test(c)&&c!=="-"||c===")"&&s[u+1]===")")return!1;if(u>o&&(c==="-"||c==='"'||c==="'"||c==="$"||/[a-zA-Z_/.]/.test(c))){let f=u;for(;f<r&&s[f]!==`
23
- `;){if(s[f]===")")return!0;f++}return!1}if(c===")"){let f=u+1;for(;f<r&&(s[f]===" "||s[f]===" ");)f++;if(s[f]==="|"&&s[f+1]==="|"||s[f]==="&"&&s[f+1]==="&"||s[f]===";"||s[f]==="|"&&s[f+1]!=="|")return!0}return!1}makeToken(t,s,r,n,i){return{type:t,value:s,start:r,end:this.pos,line:n,column:i}}readComment(t,s,r){let n=this.input,i=n.length,a=this.pos;for(;a<i&&n[a]!==`
24
- `;)a++;let l=n.slice(t,a);return this.pos=a,this.column=r+(a-t),{type:g.COMMENT,value:l,start:t,end:a,line:s,column:r}}readWord(t,s,r){let n=this.input,i=n.length,a=this.pos,l=a;for(;a<i;){let E=n[a];if(E===" "||E===" "||E===`
25
- `||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">"||E==="'"||E==='"'||E==="\\"||E==="$"||E==="`"||E==="{"||E==="}"||E==="~"||E==="*"||E==="?"||E==="[")break;a++}if(a>l){let E=n[a];if(!(E==="("&&a>l&&"@*+?!".includes(n[a-1]))){if(a>=i||E===" "||E===" "||E===`
26
- `||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">"){let w=n.slice(l,a);this.pos=a,this.column=r+(a-l);let S=Zi.get(w);if(S!==void 0)return{type:S,value:w,start:t,end:a,line:s,column:r};let A=Hi(w);return A>0&&Gi(w.slice(0,A))?{type:g.ASSIGNMENT_WORD,value:w,start:t,end:a,line:s,column:r}:/^[0-9]+$/.test(w)?{type:g.NUMBER,value:w,start:t,end:a,line:s,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(w)?{type:g.NAME,value:w,start:t,end:a,line:s,column:r,quoted:!1,singleQuoted:!1}:{type:g.WORD,value:w,start:t,end:a,line:s,column:r,quoted:!1,singleQuoted:!1}}}}a=this.pos;let o=this.column,u=this.line,c="",f=!1,d=!1,h=!1,m=!1,p=n[a]==='"'||n[a]==="'",y=!1,b=0;for(;a<i;){let E=n[a];if(!h&&!m){if(E==="("&&c.length>0&&"@*+?!".includes(c[c.length-1])){let w=this.scanExtglobPattern(a);if(w!==null){c+=w.content,a=w.end,o+=w.content.length;continue}}if(E==="["&&b===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){let w=a+1<i?n[a+1]:"";if(w==="^"||w==="!"){c+=E,a++,o++;continue}b=1,c+=E,a++,o++;continue}}else if(E==="["&&b>0){c.length>0&&c[c.length-1]!=="\\"&&b++,c+=E,a++,o++;continue}else if(E==="]"&&b>0){c.length>0&&c[c.length-1]!=="\\"&&b--,c+=E,a++,o++;continue}if(b>0){if(E===`
27
- `)break;c+=E,a++,o++;continue}if(E===" "||E===" "||E===`
28
- `||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">")break}if(E==="$"&&a+1<i&&n[a+1]==="'"&&!h&&!m){for(c+="$'",a+=2,o+=2;a<i&&n[a]!=="'";)n[a]==="\\"&&a+1<i?(c+=n[a]+n[a+1],a+=2,o+=2):(c+=n[a],a++,o++);a<i&&(c+="'",a++,o++);continue}if(E==="$"&&a+1<i&&n[a+1]==='"'&&!h&&!m){a++,o++,m=!0,f=!0,c===""&&(p=!0),a++,o++;continue}if(E==="'"&&!m){if(h)if(h=!1,!p||y)c+=E;else{let w=a+1<i?n[a+1]:"";w&&!Qi(w)&&w!=="'"&&(w==='"'?(y=!0,c+=E,d=!1,f=!1):(y=!0,c+=E))}else h=!0,p&&!y?(d=!0,f=!0):c+=E;a++,o++;continue}if(E==='"'&&!h){if(m)if(m=!1,!p||y)c+=E;else{let w=a+1<i?n[a+1]:"";w&&!Qi(w)&&w!=='"'&&(w==="'"?(y=!0,c+=E,d=!1,f=!1):(y=!0,c+=E))}else m=!0,p&&!y?f=!0:c+=E;a++,o++;continue}if(E==="\\"&&!h&&a+1<i){let w=n[a+1];if(w===`
29
- `){a+=2,u++,o=1;continue}if(m){if(w==='"'||w==="\\"||w==="$"||w==="`"||w===`
30
- `){if(w===`
31
- `){a+=2,o=1,u++;continue}c+=E+w,a+=2,o+=2;continue}}else{w==="\\"||w==='"'||w==="'"||w==="`"||w==="*"||w==="?"||w==="["||w==="]"||w==="("||w===")"||w==="$"||w==="-"||w==="."||w==="^"||w==="+"||w==="{"||w==="}"?c+=E+w:c+=w,a+=2,o+=2;continue}}if(E==="$"&&a+1<i&&n[a+1]==="("&&!h){c+=E,a++,o++,c+=n[a],a++,o++;let w=1,S=!1,A=!1,$=0,R=!1,C="",F=[],k=n[a]==="("&&!this.dollarDparenIsSubshell(a),x=k?1:0;for(;w>0&&a<i;){let D=n[a];if(c+=D,S)D==="'"&&(S=!1);else if(A)D==="\\"&&a+1<i?(c+=n[a+1],a++,o++):D==='"'&&(A=!1);else{if(D==="("&&n[a+1]==="("?x++:D===")"&&n[a+1]===")"&&x>0&&x--,x===0&&D==="<"&&n[a+1]==="<"&&n[a+2]!=="<"){let P=a+2,O=!1;for(n[P]==="-"&&(O=!0,P++);n[P]===" "||n[P]===" ";)P++;let{delim:z,endPos:U}=Hn(n,P);if(z.length>0){c+=n.slice(a+1,U),o+=U-a,F.push({delim:z,stripTabs:O}),a=U;continue}}if(D===`
32
- `&&F.length>0){u++,o=0;let P=a+1;for(let{delim:O,stripTabs:z}of F)for(;!(P>=i);){let U=n.indexOf(`
33
- `,P);U===-1&&(U=i);let ee=n.slice(P,U),fe=z?ee.replace(/^\t+/,""):ee;c+=n.slice(P,Math.min(U+1,i)),U<i&&u++;let ge=U>=i;if(P=U+1,fe===O||ge)break}F.length=0,o=0,a=Math.min(P,i);continue}if(D==="'")S=!0,C="";else if(D==='"')A=!0,C="";else if(D==="\\"&&a+1<i)c+=n[a+1],a++,o++,C="";else if(D==="$"&&a+1<i&&n[a+1]==="{"){a++,o++,c+=n[a],a++,o++;let P=1,O=!1,z=!1;for(;P>0&&a<i;){let U=n[a];if(U==="\\"&&a+1<i&&!O){c+=U,a++,o++,c+=n[a],a++,o++;continue}c+=U,O?U==="'"&&(O=!1):z?U==='"'&&(z=!1):U==="'"?O=!0:U==='"'?z=!0:U==="{"?P++:U==="}"&&P--,U===`
34
- `?(u++,o=0):o++,a++}C="";continue}else if(D==="#"&&!k&&(C===""||/\s/.test(n[a-1]||""))){for(;a+1<i&&n[a+1]!==`
35
- `;)a++,o++,c+=n[a];C=""}else/[a-zA-Z_]/.test(D)?C+=D:(C==="case"?($++,R=!1):C==="in"&&$>0?R=!0:C==="esac"&&$>0&&($--,R=!1),C="",D==="("?a>0&&n[a-1]==="$"?w++:R||w++:D===")"?R?R=!1:w--:D===";"&&$>0&&(a+1<i&&n[a+1]===";"||a+1<i&&n[a+1]==="&")&&(R=!0))}D===`
36
- `&&(u++,o=0,C=""),a++,o++}continue}if(E==="$"&&a+1<i&&n[a+1]==="["&&!h){c+=E,a++,o++,c+=n[a],a++,o++;let w=1;for(;w>0&&a<i;){let S=n[a];c+=S,S==="["?w++:S==="]"?w--:S===`
37
- `&&(u++,o=0),a++,o++}continue}if(E==="$"&&a+1<i&&n[a+1]==="{"&&!h){c+=E,a++,o++,c+=n[a],a++,o++;let w=1,S=!1,A=!1,$=u,R=o,C=u,F=o;for(;w>0&&a<i;){let k=n[a];if(k==="\\"&&a+1<i&&n[a+1]===`
38
- `){a+=2,u++,o=1;continue}if(k==="\\"&&a+1<i&&!S){c+=k,a++,o++,c+=n[a],a++,o++;continue}c+=k,S?k==="'"&&(S=!1):A?k==='"'&&(A=!1):k==="'"?(S=!0,$=u,R=o):k==='"'?(A=!0,C=u,F=o):k==="{"?w++:k==="}"&&w--,k===`
39
- `&&(u++,o=0),a++,o++}if(S)throw new At("unexpected EOF while looking for matching `''",$,R);if(A)throw new At("unexpected EOF while looking for matching `\"'",C,F);continue}if(E==="$"&&a+1<i&&!h){let w=n[a+1];if(w==="#"||w==="?"||w==="$"||w==="!"||w==="@"||w==="*"||w==="-"||w>="0"&&w<="9"){c+=E+w,a+=2,o+=2;continue}}if(E==="`"&&!h){for(c+=E,a++,o++;a<i&&n[a]!=="`";){let w=n[a];c+=w,w==="\\"&&a+1<i&&(c+=n[a+1],a++,o++),w===`
40
- `&&(u++,o=0),a++,o++}a<i&&(c+=n[a],a++,o++);continue}c+=E,a++,E===`
41
- `?(u++,o=1):o++}if(this.pos=a,this.column=o,this.line=u,y&&p&&(c=n[t]+c,f=!1,d=!1),h||m){let E=h?"'":'"';throw new At(`unexpected EOF while looking for matching \`${E}'`,s,r)}if(!p&&c.length>=2){if(c[0]==="'"&&c[c.length-1]==="'"){let E=c.slice(1,-1);!E.includes("'")&&!E.includes('"')&&(c=E,f=!0,d=!0)}else if(c[0]==='"'&&c[c.length-1]==='"'){let E=c.slice(1,-1),w=!1;for(let S=0;S<E.length;S++){if(E[S]==='"'){w=!0;break}E[S]==="\\"&&S+1<E.length&&S++}w||(c=E,f=!0,d=!1)}}if(c==="")return{type:g.WORD,value:"",start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d};let v=Zi.get(c);if(!f&&v!==void 0)return{type:v,value:c,start:t,end:a,line:s,column:r};if(!p){let E=Hi(c);if(E>0&&Gi(c.slice(0,E)))return{type:g.ASSIGNMENT_WORD,value:c,start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(c)?{type:g.NUMBER,value:c,start:t,end:a,line:s,column:r}:Yc(c)?{type:g.NAME,value:c,start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d}:{type:g.WORD,value:c,start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let s=this.pos,r=this.line,n=this.column,i="";for(;this.pos<this.input.length;){let a="";for(;this.pos<this.input.length&&this.input[this.pos]!==`
12
+ `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>Ws(t)):e.writeFileSync("/proc/self/status",Ws(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 Ja(e,t,n={pid:1,ppid:0,uid:1e3,gid:1e3}){rf(e)&&(sf(e,t),af(e),of(e,n))}function _e(e){return{kind:e.kind,elements:new Map(e.elements)}}function pt(e){return new Map(Array.from(e??[],([t,n])=>[t,_e(n)]))}function Ae(e,t){return e.state.arrays?.get(t)}function Vn(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 Mt(e,t,n){let r=Vn(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 Ae(e,t)?.elements.get(String(n))}function Bt(e,t,n){return Ae(e,t)?.elements.has(String(n))??!1}function q(e,t,n,r,s){let i=Vn(e,t,s),a=String(n);if(!i.elements.has(a)&&i.elements.size>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(M(r)>e.limits.maxStringLength)throw new P(`array value string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");i.elements.set(a,r)}function nn(e,t,n,r=!1){let s=new Set(r?[]:Ae(e,t)?.elements.keys()??[]);for(let i of n)if(s.add(String(i)),s.size>e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements")}function rn(e,t,n){return Ae(e,t)?.elements.delete(String(n))??!1}function zn(e,t){e.state.arrays?.delete(t),e.state.associativeArrays?.delete(t)}function Se(e,t){return Array.from(Ae(e,t)?.elements.keys()??[]).filter(r=>/^(0|[1-9]\d*)$/.test(r)).map(Number).sort((r,s)=>r-s)}function ge(e,t){Vn(e,t,e.state.associativeArrays?.has(t)?"associative":"indexed").elements.clear()}function mt(e,t){return Array.from(Ae(e,t)?.elements.keys()??[]).sort()}function $r(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function Fs(e){if(e.parts.length<2)return null;let t=e.parts[0],n=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let r,s=n,i=1;if(n.type==="Literal"&&n.value.startsWith("]")){let f=n.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))r=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let d=e.parts[2];if(d.type!=="Literal"||!d.value.startsWith("=")&&!d.value.startsWith("+="))return null;r=t.pattern.slice(1),s=d,i=2}else return null}else if(t.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(n.type==="SingleQuoted")r=n.value;else{r="";for(let d of n.parts)(d.type==="Literal"||d.type==="Escaped")&&(r+=d.value)}s=f,i=2}else if(t.pattern.endsWith("]")){if(n.type!=="Literal"||!n.value.startsWith("=")&&!n.value.startsWith("+="))return null;r=t.pattern.slice(1,-1)}else return null;r=$r(r);let a;if(s.type!=="Literal")return null;s.value.startsWith("]=")||s.value.startsWith("]+=")?a=s.value.slice(1):a=s.value;let o=a.startsWith("+=");if(!o&&!a.startsWith("="))return null;let l=[],c=o?2:1,u=a.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:lf(d)}):l.push(d)}return{key:r,valueParts:l,append:o}}function lf(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 gn(n.word)}).join(",")}}`}function gn(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}`:""}`:gn(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",n.user&&(t+=n.user);break}return t}var cf=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],uf=["braceexpand","hashall","interactive-comments"];function Vs(e){let t=[],n=[...uf.map(r=>({name:r,enabled:!0})),...cf.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",Vs(e.state.options))}var ff=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function zs(e){let t=[];for(let n of ff)e[n]&&t.push(n);return t.join(":")}function qs(e){e.state.env.set("BASHOPTS",zs(e.state.shoptOptions))}var L={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}},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){return{type:"HereDoc",delimiter:e,content:t,stripTabs:n,quoted:r}},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 eo(e,t){let n=e.length,r=t+3,s=2,i=!1,a=!1;for(;r<n&&s>0;){let o=e[r];if(i){o==="'"&&(i=!1),r++;continue}if(a){if(o==="\\"){r+=2;continue}o==='"'&&(a=!1),r++;continue}if(o==="'"){i=!0,r++;continue}if(o==='"'){a=!0,r++;continue}if(o==="\\"){r+=2;continue}if(o==="("){s++,r++;continue}if(o===")"){if(s--,s===1){let l=r+1;return!(l<n&&e[l]===")")}if(s===0)return!1;r++;continue}if(s===1&&(o==="|"&&r+1<n&&e[r+1]==="|"||o==="&"&&r+1<n&&e[r+1]==="&"||o==="|"&&r+1<n&&e[r+1]!=="|"))return!0;r++}return!1}function Us(e,t){let n="",r=t,s=i=>i===" "||i===" "||i===`
13
+ `||i===";"||i==="&"||i==="|"||i==="<"||i===">"||i==="("||i===")";for(;r<e.length;){let i=e[r];if(i==="'"){for(r++;r<e.length&&e[r]!=="'";)n+=e[r],r++;r<e.length&&r++;continue}if(i==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length&&r++,n+=e[r],r++;r<e.length&&r++;continue}if(i==="\\"&&r+1<e.length){n+=e[r+1],r+=2;continue}if(s(i))break;n+=i,r++}return{delim:n,endPos:r}}function df(e,t,n){let r=t+1;for(let{delim:s,stripTabs:i}of n)for(;;){if(r>=e.length)return e.length;let a=e.indexOf(`
14
+ `,r);a===-1&&(a=e.length);let o=e.slice(r,a);if(i&&(o=o.replace(/^\t+/,"")),o===s){r=a+1;break}if(a>=e.length)return e.length;r=a+1}return Math.min(r,e.length)}function to(e,t,n,r){let s=t+2,i=1,a=s,o=!1,l=!1,c=0,u=!1,f="",d=[],h=0;for(;a<e.length&&i>0;){let b=e[a];if(o)b==="'"&&(o=!1);else if(l)b==="\\"&&a+1<e.length?a++:b==='"'&&(l=!1);else{if(b==="("&&e[a+1]==="("?h++:b===")"&&e[a+1]===")"&&h>0&&h--,h===0&&b==="<"&&e[a+1]==="<"&&e[a+2]!=="<"){let g=a+2,w=!1;for(e[g]==="-"&&(w=!0,g++);e[g]===" "||e[g]===" ";)g++;let{delim:S,endPos:A}=Us(e,g);if(S.length>0){d.push({delim:S,stripTabs:w}),f="",a=A;continue}}if(b===`
15
+ `&&d.length>0){let g=df(e,a,d);d.length=0,f="",a=g;continue}b==="'"?(o=!0,f=""):b==='"'?(l=!0,f=""):b==="\\"&&a+1<e.length?(a++,f=""):/[a-zA-Z_]/.test(b)?f+=b:(f==="case"?(c++,u=!1):f==="in"&&c>0?u=!0:f==="esac"&&c>0&&(c--,u=!1),f="",b==="("?a>0&&e[a-1]==="$"?i++:u||i++:b===")"?u?u=!1:i--:b===";"&&c>0&&a+1<e.length&&e[a+1]===";"&&(u=!0))}i>0&&a++}i>0&&r("unexpected EOF while looking for matching `)'");let p=e.slice(s,a),E=n().parse(p);return{part:L.commandSubstitution(E,!1),endIndex:a+1}}function no(e,t,n,r,s){let a=t+1,o="";for(;a<e.length&&e[a]!=="`";)if(e[a]==="\\"){let u=e[a+1];u==="$"||u==="`"||u==="\\"||u===`
16
+ `||n&&u==='"'?(u!==`
17
+ `&&(o+=u),a+=2):(o+=e[a],a++)}else o+=e[a],a++;a>=e.length&&s("unexpected EOF while looking for matching ``'");let c=r().parse(o);return{part:L.commandSubstitution(c,!0),endIndex:a+1}}var hf=10485760,y;(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"})(y||(y={}));var Wt=class extends Error{line;column;constructor(t,n,r){super(`line ${n}: ${t}`),this.line=n,this.column=r,this.name="LexerError"}},ro=new Map([["if",y.IF],["then",y.THEN],["else",y.ELSE],["elif",y.ELIF],["fi",y.FI],["for",y.FOR],["while",y.WHILE],["until",y.UNTIL],["do",y.DO],["done",y.DONE],["case",y.CASE],["esac",y.ESAC],["in",y.IN],["function",y.FUNCTION],["select",y.SELECT],["time",y.TIME],["coproc",y.COPROC]]);function so(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 io(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 pf=[[";",";","&",y.SEMI_SEMI_AND],["<","<","<",y.TLESS],["&",">",">",y.AND_DGREAT]],mf=[["[","[",y.DBRACK_START],["]","]",y.DBRACK_END],["(","(",y.DPAREN_START],[")",")",y.DPAREN_END],["&","&",y.AND_AND],["|","|",y.OR_OR],[";",";",y.DSEMI],[";","&",y.SEMI_AND],["|","&",y.PIPE_AMP],[">",">",y.DGREAT],["<","&",y.LESSAND],[">","&",y.GREATAND],["<",">",y.LESSGREAT],[">","|",y.CLOBBER],["&",">",y.AND_GREAT]],yf=new Map([["|",y.PIPE],["&",y.AMP],[";",y.SEMICOLON],["(",y.LPAREN],[")",y.RPAREN],["<",y.LESS],[">",y.GREAT]]);function gf(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function ao(e){return e===" "||e===" "||e===`
18
+ `||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var kr=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];dparenDepth=0;maxHeredocSize;constructor(t,n){this.input=t,this.maxHeredocSize=n?.maxHeredocSize??hf}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===y.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=n)break;let i=this.nextToken();i&&r.push(i)}return r.push({type:y.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 a=t[r];if(a===" "||a===" ")r++,s++;else if(a==="\\"&&t[r+1]===`
19
+ `)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],a=t[n+1],o=t[n+2];if(i==="#"&&this.dparenDepth===0)return this.readComment(n,r,s);if(i===`
20
+ `)return this.pos=n+1,this.line++,this.column=1,{type:y.NEWLINE,value:`
21
+ `,start:n,end:n+1,line:r,column:s};if(i==="<"&&a==="<"&&o==="-")return this.pos=n+3,this.column=s+3,this.registerHeredocFromLookahead(!0),this.makeToken(y.DLESSDASH,"<<-",n,r,s);for(let[c,u,f,d]of pf)if(i===c&&a===u&&o===f)return this.pos=n+3,this.column=s+3,this.makeToken(d,c+u+f,n,r,s);if(i==="<"&&a==="<")return this.pos=n+2,this.column=s+2,this.registerHeredocFromLookahead(!1),this.makeToken(y.DLESS,"<<",n,r,s);if(i==="("&&a==="(")return this.dparenDepth>0?(this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(y.LPAREN,"(",n,r,s)):this.looksLikeNestedSubshells(n+2)||this.dparenClosesWithSpacedParens(n+2)?(this.pos=n+1,this.column=s+1,this.makeToken(y.LPAREN,"(",n,r,s)):(this.pos=n+2,this.column=s+2,this.dparenDepth=1,this.makeToken(y.DPAREN_START,"((",n,r,s));if(i===")"&&a===")")return this.dparenDepth===1?(this.pos=n+2,this.column=s+2,this.dparenDepth=0,this.makeToken(y.DPAREN_END,"))",n,r,s)):this.dparenDepth>1?(this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(y.RPAREN,")",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(y.RPAREN,")",n,r,s));for(let[c,u,f]of mf)if(!(c==="("&&u==="("||c===")"&&u===")")&&!(this.dparenDepth>0&&c===";"&&(f===y.DSEMI||f===y.SEMI_AND||f===y.SEMI_SEMI_AND))&&i===c&&a===u){if(f===y.DBRACK_START||f===y.DBRACK_END){let d=t[n+2];if(d!==void 0&&d!==" "&&d!==" "&&d!==`
22
+ `&&d!==";"&&d!=="&"&&d!=="|"&&d!=="("&&d!==")"&&d!=="<"&&d!==">")break}return this.pos=n+2,this.column=s+2,this.makeToken(f,c+u,n,r,s)}if(i==="("&&this.dparenDepth>0)return this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(y.LPAREN,"(",n,r,s);if(i===")"&&this.dparenDepth>1)return this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(y.RPAREN,")",n,r,s);let l=yf.get(i);if(l!==void 0)return this.pos=n+1,this.column=s+1,this.makeToken(l,i,n,r,s);if(i==="{"){let c=this.scanFdVariable(n);return c!==null?(this.pos=c.end,this.column=s+(c.end-n),{type:y.FD_VARIABLE,value:c.varname,start:n,end:c.end,line:r,column:s}):a==="}"?(this.pos=n+2,this.column=s+2,{type:y.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):a!==void 0&&a!==" "&&a!==" "&&a!==`
23
+ `?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(y.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(y.RBRACE,"}",n,r,s)):i==="!"?a==="="?(this.pos=n+2,this.column=s+2,this.makeToken(y.WORD,"!=",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(y.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 a=/[a-zA-Z_]/.test(i),o=i==="!"||i==="[";if(!a&&!o)return!1;let l=s;for(;l<r&&/[a-zA-Z0-9_\-.]/.test(n[l]);)l++;if(l===s)return o;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===`
24
+ `||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]!==`
25
+ `;){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,a=this.pos;for(;a<i&&s[a]!==`
26
+ `;)a++;let o=s.slice(t,a);return this.pos=a,this.column=r+(a-t),{type:y.COMMENT,value:o,start:t,end:a,line:n,column:r}}readWord(t,n,r){let s=this.input,i=s.length,a=this.pos,o=a;for(;a<i;){let w=s[a];if(w===" "||w===" "||w===`
27
+ `||w===";"||w==="&"||w==="|"||w==="("||w===")"||w==="<"||w===">"||w==="'"||w==='"'||w==="\\"||w==="$"||w==="`"||w==="{"||w==="}"||w==="~"||w==="*"||w==="?"||w==="[")break;a++}if(a>o){let w=s[a];if(!(w==="("&&a>o&&"@*+?!".includes(s[a-1]))){if(a>=i||w===" "||w===" "||w===`
28
+ `||w===";"||w==="&"||w==="|"||w==="("||w===")"||w==="<"||w===">"){let S=s.slice(o,a);this.pos=a,this.column=r+(a-o);let A=ro.get(S);if(A!==void 0)return{type:A,value:S,start:t,end:a,line:n,column:r};let v=io(S);return v>0&&so(S.slice(0,v))?{type:y.ASSIGNMENT_WORD,value:S,start:t,end:a,line:n,column:r}:/^[0-9]+$/.test(S)?{type:y.NUMBER,value:S,start:t,end:a,line:n,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(S)?{type:y.NAME,value:S,start:t,end:a,line:n,column:r,quoted:!1,singleQuoted:!1}:{type:y.WORD,value:S,start:t,end:a,line:n,column:r,quoted:!1,singleQuoted:!1}}}}a=this.pos;let l=this.column,c=this.line,u="",f=!1,d=!1,h=!1,p=!1,m=s[a]==='"'||s[a]==="'",E=!1,b=0;for(;a<i;){let w=s[a];if(!h&&!p){if(w==="("&&u.length>0&&"@*+?!".includes(u[u.length-1])){let S=this.scanExtglobPattern(a);if(S!==null){u+=S.content,a=S.end,l+=S.content.length;continue}}if(w==="["&&b===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){let S=a+1<i?s[a+1]:"";if(S==="^"||S==="!"){u+=w,a++,l++;continue}b=1,u+=w,a++,l++;continue}}else if(w==="["&&b>0){u.length>0&&u[u.length-1]!=="\\"&&b++,u+=w,a++,l++;continue}else if(w==="]"&&b>0){u.length>0&&u[u.length-1]!=="\\"&&b--,u+=w,a++,l++;continue}if(b>0){if(w===`
29
+ `)break;u+=w,a++,l++;continue}if(w===" "||w===" "||w===`
30
+ `||w===";"||w==="&"||w==="|"||w==="("||w===")"||w==="<"||w===">")break}if(w==="$"&&a+1<i&&s[a+1]==="'"&&!h&&!p){for(u+="$'",a+=2,l+=2;a<i&&s[a]!=="'";)s[a]==="\\"&&a+1<i?(u+=s[a]+s[a+1],a+=2,l+=2):(u+=s[a],a++,l++);a<i&&(u+="'",a++,l++);continue}if(w==="$"&&a+1<i&&s[a+1]==='"'&&!h&&!p){a++,l++,p=!0,f=!0,u===""&&(m=!0),a++,l++;continue}if(w==="'"&&!p){if(h)if(h=!1,!m||E)u+=w;else{let S=a+1<i?s[a+1]:"";S&&!ao(S)&&S!=="'"&&(S==='"'?(E=!0,u+=w,d=!1,f=!1):(E=!0,u+=w))}else h=!0,m&&!E?(d=!0,f=!0):u+=w;a++,l++;continue}if(w==='"'&&!h){if(p)if(p=!1,!m||E)u+=w;else{let S=a+1<i?s[a+1]:"";S&&!ao(S)&&S!=='"'&&(S==="'"?(E=!0,u+=w,d=!1,f=!1):(E=!0,u+=w))}else p=!0,m&&!E?f=!0:u+=w;a++,l++;continue}if(w==="\\"&&!h&&a+1<i){let S=s[a+1];if(S===`
31
+ `){a+=2,c++,l=1;continue}if(p){if(S==='"'||S==="\\"||S==="$"||S==="`"||S===`
32
+ `){if(S===`
33
+ `){a+=2,l=1,c++;continue}u+=w+S,a+=2,l+=2;continue}}else{S==="\\"||S==='"'||S==="'"||S==="`"||S==="*"||S==="?"||S==="["||S==="]"||S==="("||S===")"||S==="$"||S==="-"||S==="."||S==="^"||S==="+"||S==="{"||S==="}"?u+=w+S:u+=S,a+=2,l+=2;continue}}if(w==="$"&&a+1<i&&s[a+1]==="("&&!h){u+=w,a++,l++,u+=s[a],a++,l++;let S=1,A=!1,v=!1,x=0,N=!1,D="",O=[],_=s[a]==="("&&!this.dollarDparenIsSubshell(a),V=_?1:0;for(;S>0&&a<i;){let J=s[a];if(u+=J,A)J==="'"&&(A=!1);else if(v)J==="\\"&&a+1<i?(u+=s[a+1],a++,l++):J==='"'&&(v=!1);else{if(J==="("&&s[a+1]==="("?V++:J===")"&&s[a+1]===")"&&V>0&&V--,V===0&&J==="<"&&s[a+1]==="<"&&s[a+2]!=="<"){let ee=a+2,C=!1;for(s[ee]==="-"&&(C=!0,ee++);s[ee]===" "||s[ee]===" ";)ee++;let{delim:$,endPos:k}=Us(s,ee);if($.length>0){u+=s.slice(a+1,k),l+=k-a,O.push({delim:$,stripTabs:C}),a=k;continue}}if(J===`
34
+ `&&O.length>0){c++,l=0;let ee=a+1;for(let{delim:C,stripTabs:$}of O)for(;!(ee>=i);){let k=s.indexOf(`
35
+ `,ee);k===-1&&(k=i);let W=s.slice(ee,k),Q=$?W.replace(/^\t+/,""):W;u+=s.slice(ee,Math.min(k+1,i)),k<i&&c++;let G=k>=i;if(ee=k+1,Q===C||G)break}O.length=0,l=0,a=Math.min(ee,i);continue}if(J==="'")A=!0,D="";else if(J==='"')v=!0,D="";else if(J==="\\"&&a+1<i)u+=s[a+1],a++,l++,D="";else if(J==="$"&&a+1<i&&s[a+1]==="{"){a++,l++,u+=s[a],a++,l++;let ee=1,C=!1,$=!1;for(;ee>0&&a<i;){let k=s[a];if(k==="\\"&&a+1<i&&!C){u+=k,a++,l++,u+=s[a],a++,l++;continue}u+=k,C?k==="'"&&(C=!1):$?k==='"'&&($=!1):k==="'"?C=!0:k==='"'?$=!0:k==="{"?ee++:k==="}"&&ee--,k===`
36
+ `?(c++,l=0):l++,a++}D="";continue}else if(J==="#"&&!_&&(D===""||/\s/.test(s[a-1]||""))){for(;a+1<i&&s[a+1]!==`
37
+ `;)a++,l++,u+=s[a];D=""}else/[a-zA-Z_]/.test(J)?D+=J:(D==="case"?(x++,N=!1):D==="in"&&x>0?N=!0:D==="esac"&&x>0&&(x--,N=!1),D="",J==="("?a>0&&s[a-1]==="$"?S++:N||S++:J===")"?N?N=!1:S--:J===";"&&x>0&&(a+1<i&&s[a+1]===";"||a+1<i&&s[a+1]==="&")&&(N=!0))}J===`
38
+ `&&(c++,l=0,D=""),a++,l++}continue}if(w==="$"&&a+1<i&&s[a+1]==="["&&!h){u+=w,a++,l++,u+=s[a],a++,l++;let S=1;for(;S>0&&a<i;){let A=s[a];u+=A,A==="["?S++:A==="]"?S--:A===`
39
+ `&&(c++,l=0),a++,l++}continue}if(w==="$"&&a+1<i&&s[a+1]==="{"&&!h){u+=w,a++,l++,u+=s[a],a++,l++;let S=1,A=!1,v=!1,x=c,N=l,D=c,O=l;for(;S>0&&a<i;){let _=s[a];if(_==="\\"&&a+1<i&&s[a+1]===`
40
+ `){a+=2,c++,l=1;continue}if(_==="\\"&&a+1<i&&!A){u+=_,a++,l++,u+=s[a],a++,l++;continue}u+=_,A?_==="'"&&(A=!1):v?_==='"'&&(v=!1):_==="'"?(A=!0,x=c,N=l):_==='"'?(v=!0,D=c,O=l):_==="{"?S++:_==="}"&&S--,_===`
41
+ `&&(c++,l=0),a++,l++}if(A)throw new Wt("unexpected EOF while looking for matching `''",x,N);if(v)throw new Wt("unexpected EOF while looking for matching `\"'",D,O);continue}if(w==="$"&&a+1<i&&!h){let S=s[a+1];if(S==="#"||S==="?"||S==="$"||S==="!"||S==="@"||S==="*"||S==="-"||S>="0"&&S<="9"){u+=w+S,a+=2,l+=2;continue}}if(w==="`"&&!h){for(u+=w,a++,l++;a<i&&s[a]!=="`";){let S=s[a];u+=S,S==="\\"&&a+1<i&&(u+=s[a+1],a++,l++),S===`
42
+ `&&(c++,l=0),a++,l++}a<i&&(u+=s[a],a++,l++);continue}u+=w,a++,w===`
43
+ `?(c++,l=1):l++}if(this.pos=a,this.column=l,this.line=c,E&&m&&(u=s[t]+u,f=!1,d=!1),h||p){let w=h?"'":'"';throw new Wt(`unexpected EOF while looking for matching \`${w}'`,n,r)}if(!m&&u.length>=2){if(u[0]==="'"&&u[u.length-1]==="'"){let w=u.slice(1,-1);!w.includes("'")&&!w.includes('"')&&(u=w,f=!0,d=!0)}else if(u[0]==='"'&&u[u.length-1]==='"'){let w=u.slice(1,-1),S=!1;for(let A=0;A<w.length;A++){if(w[A]==='"'){S=!0;break}w[A]==="\\"&&A+1<w.length&&A++}S||(u=w,f=!0,d=!1)}}if(u==="")return{type:y.WORD,value:"",start:t,end:a,line:n,column:r,quoted:f,singleQuoted:d};let g=ro.get(u);if(!f&&g!==void 0)return{type:g,value:u,start:t,end:a,line:n,column:r};if(!m){let w=io(u);if(w>0&&so(u.slice(0,w)))return{type:y.ASSIGNMENT_WORD,value:u,start:t,end:a,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(u)?{type:y.NUMBER,value:u,start:t,end:a,line:n,column:r}:gf(u)?{type:y.NAME,value:u,start:t,end:a,line:n,column:r,quoted:f,singleQuoted:d}:{type:y.WORD,value:u,start:t,end:a,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="";for(;this.pos<this.input.length;){let a="";for(;this.pos<this.input.length&&this.input[this.pos]!==`
42
44
  `;)a+=this.input[this.pos],this.pos++,this.column++;if((t.stripTabs?a.replace(/^\t+/,""):a)===t.delimiter){this.pos<this.input.length&&this.input[this.pos]===`
43
- `&&(this.pos++,this.line++,this.column=1);break}if(i+=a,i.length>this.maxHeredocSize)throw new At(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,n);this.pos<this.input.length&&this.input[this.pos]===`
45
+ `&&(this.pos++,this.line++,this.column=1);break}if(i+=a,i.length>this.maxHeredocSize)throw new Wt(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,s);this.pos<this.input.length&&this.input[this.pos]===`
44
46
  `&&(i+=`
45
- `,this.pos++,this.line++,this.column=1)}this.tokens.push({type:g.HEREDOC_CONTENT,value:i,start:s,end:this.pos,line:r,column:n})}}addPendingHeredoc(t,s,r){this.pendingHeredocs.push({delimiter:t,stripTabs:s,quoted:r})}registerHeredocFromLookahead(t){let s=this.pos,r=this.column;for(;this.pos<this.input.length&&(this.input[this.pos]===" "||this.input[this.pos]===" ");)this.pos++,this.column++;let n="",i=!1;for(;this.pos<this.input.length;){let a=this.input[this.pos];if(/[\s;<>&|()]/.test(a))break;if(a==="'"||a==='"'){i=!0;let l=a;for(this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]!==l;)n+=this.input[this.pos],this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]===l&&(this.pos++,this.column++)}else a==="\\"?(i=!0,this.pos++,this.column++,this.pos<this.input.length&&(n+=this.input[this.pos],this.pos++,this.column++)):(n+=a,this.pos++,this.column++)}this.pos=s,this.column=r,n&&this.pendingHeredocs.push({delimiter:n,stripTabs:t,quoted:i})}isWordCharFollowing(t){if(t>=this.input.length)return!1;let s=this.input[t];return!(s===" "||s===" "||s===`
46
- `||s===";"||s==="&"||s==="|"||s==="("||s===")"||s==="<"||s===">")}readWordWithBraceExpansion(t,s,r){let n=this.input,i=n.length,a=t,l=r;for(;a<i;){let u=n[a];if(u===" "||u===" "||u===`
47
- `||u===";"||u==="&"||u==="|"||u==="("||u===")"||u==="<"||u===">")break;if(u==="{"){if(this.scanBraceExpansion(a)!==null){let f=1;for(a++,l++;a<i&&f>0;)n[a]==="{"?f++:n[a]==="}"&&f--,a++,l++;continue}a++,l++;continue}if(u==="}"){a++,l++;continue}if(u==="$"&&a+1<i&&n[a+1]==="("){a++,l++,a++,l++;let c=1;for(;c>0&&a<i;)n[a]==="("?c++:n[a]===")"&&c--,a++,l++;continue}if(u==="$"&&a+1<i&&n[a+1]==="{"){a++,l++,a++,l++;let c=1;for(;c>0&&a<i;)n[a]==="{"?c++:n[a]==="}"&&c--,a++,l++;continue}if(u==="`"){for(a++,l++;a<i&&n[a]!=="`";)n[a]==="\\"&&a+1<i?(a+=2,l+=2):(a++,l++);a<i&&(a++,l++);continue}a++,l++}let o=n.slice(t,a);return this.pos=a,this.column=l,{type:g.WORD,value:o,start:t,end:a,line:s,column:r,quoted:!1,singleQuoted:!1}}scanBraceExpansion(t){let s=this.input,r=s.length,n=t+1,i=1,a=!1,l=!1;for(;n<r&&i>0;){let o=s[n];if(o==="{")i++,n++;else if(o==="}")i--,n++;else if(o===","&&i===1)a=!0,n++;else if(o==="."&&n+1<r&&s[n+1]===".")l=!0,n+=2;else{if(o===" "||o===" "||o===`
48
- `||o===";"||o==="&"||o==="|")return null;n++}}return i===0&&(a||l)?s.slice(t,n):null}scanLiteralBraceWord(t){let s=this.input,r=s.length,n=t+1,i=1;for(;n<r&&i>0;){let a=s[n];if(a==="{")i++,n++;else if(a==="}"){if(i--,i===0)return s.slice(t,n+1);n++}else{if(a===" "||a===" "||a===`
49
- `||a===";"||a==="&"||a==="|")return null;n++}}return null}scanExtglobPattern(t){let s=this.input,r=s.length,n=t+1,i=1;for(;n<r&&i>0;){let a=s[n];if(a==="\\"&&n+1<r){n+=2;continue}if("@*+?!".includes(a)&&n+1<r&&s[n+1]==="("){n++,i++,n++;continue}if(a==="(")i++,n++;else if(a===")")i--,n++;else{if(a===`
50
- `)return null;n++}}return i===0?{content:s.slice(t,n),end:n}:null}scanFdVariable(t){let s=this.input,r=s.length,n=t+1,i=n;for(;n<r;){let c=s[n];if(n===i){if(!(c>="a"&&c<="z"||c>="A"&&c<="Z"||c==="_"))return null}else if(!(c>="a"&&c<="z"||c>="A"&&c<="Z"||c>="0"&&c<="9"||c==="_"))break;n++}if(n===i)return null;let a=s.slice(i,n);if(n>=r||s[n]!=="}"||(n++,n>=r))return null;let l=s[n],o=n+1<r?s[n+1]:"";return l===">"||l==="<"||l==="&"&&(o===">"||o==="<")?{varname:a,end:n}:null}dollarDparenIsSubshell(t){let s=this.input,r=s.length,n=t+1,i=2,a=!1,l=!1,o=!1;for(;n<r&&i>0;){let u=s[n];if(a){u==="'"&&(a=!1),u===`
51
- `&&(o=!0),n++;continue}if(l){if(u==="\\"){n+=2;continue}u==='"'&&(l=!1),u===`
52
- `&&(o=!0),n++;continue}if(u==="'"){a=!0,n++;continue}if(u==='"'){l=!0,n++;continue}if(u==="\\"){n+=2;continue}if(u===`
53
- `&&(o=!0),u==="("){i++,n++;continue}if(u===")"){if(i--,i===1){let c=n+1;if(c<r&&s[c]===")")return!1;let f=c,d=!1;for(;f<r&&(s[f]===" "||s[f]===" "||s[f]===`
54
- `);)d=!0,f++;if(d&&f<r&&s[f]===")"||o)return!0}if(i===0)return!1;n++;continue}n++}return!1}dparenClosesWithSpacedParens(t){let s=this.input,r=s.length,n=t,i=2,a=!1,l=!1;for(;n<r&&i>0;){let o=s[n];if(a){o==="'"&&(a=!1),n++;continue}if(l){if(o==="\\"){n+=2;continue}o==='"'&&(l=!1),n++;continue}if(o==="'"){a=!0,n++;continue}if(o==='"'){l=!0,n++;continue}if(o==="\\"){n+=2;continue}if(o==="("){i++,n++;continue}if(o===")"){if(i--,i===1){let u=n+1;if(u<r&&s[u]===")")return!1;let c=u,f=!1;for(;c<r&&(s[c]===" "||s[c]===" "||s[c]===`
55
- `);)f=!0,c++;if(f&&c<r&&s[c]===")")return!0}if(i===0)return!1;n++;continue}if(i===1&&(o==="|"&&n+1<r&&s[n+1]==="|"||o==="&"&&n+1<r&&s[n+1]==="&"||o==="|"&&n+1<r&&s[n+1]!=="|"))return!0;n++}return!1}};var Qn=1e6,Kn=1e5,Ki=1e6,Xn=200,Xi=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]),Yi=new Set([g.LESS,g.GREAT,g.DLESS,g.DGREAT,g.LESSAND,g.GREATAND,g.LESSGREAT,g.DLESSDASH,g.CLOBBER,g.TLESS]),Ji=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]),Ee=class extends Error{line;column;token;constructor(t,s,r,n=void 0){super(`Parse error at ${s}:${r}: ${t}`),this.line=s,this.column=r,this.token=n,this.name="ParseException"}};function ce(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
56
- `){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var Fs=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function us(e){if(e.includes("#")){let[s,r]=e.split("#"),n=Number.parseInt(s,10);if(n<2||n>64)return Number.NaN;if(n<=36){let a=Number.parseInt(r,n);return a>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:a}let i=0;for(let a of r){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+36;else if(a==="@")l=62;else if(a==="_")l=63;else return Number.NaN;if(l>=n)return Number.NaN;if(i=i*n+l,i>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return i}if(e.startsWith("0x")||e.startsWith("0X")){let s=Number.parseInt(e.slice(2),16);return s>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:s}if(e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)){if(/[89]/.test(e))return Number.NaN;let s=Number.parseInt(e,8);return s>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:s}let t=Number.parseInt(e,10);return t>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t}function ea(e,t,s,r){if(s.slice(r,r+3)!=="$((")return null;let n=r+3,i=1,a=n;for(;n<s.length-1&&i>0;)s[n]==="("&&s[n+1]==="("?(i++,n+=2):s[n]===")"&&s[n+1]===")"?(i--,i>0&&(n+=2)):n++;let l=s.slice(a,n),{expr:o}=e(t,l,0);return n+=2,{expr:{type:"ArithNested",expression:o},pos:n}}function ta(e,t){if(e.slice(t,t+2)!=="$'")return null;let s=t+2,r="";for(;s<e.length&&e[s]!=="'";)if(e[s]==="\\"&&s+1<e.length){let i=e[s+1];switch(i){case"n":r+=`
57
- `;break;case"t":r+=" ";break;case"r":r+="\r";break;case"\\":r+="\\";break;case"'":r+="'";break;default:r+=i}s+=2}else r+=e[s],s++;e[s]==="'"&&s++;let n=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(n)?0:n},pos:s}}function sa(e,t){if(e.slice(t,t+2)!=='$"')return null;let s=t+2,r="";for(;s<e.length&&e[s]!=='"';)e[s]==="\\"&&s+1<e.length?(r+=e[s+1],s+=2):(r+=e[s],s++);e[s]==='"'&&s++;let n=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(n)?0:n},pos:s}}function Jc(e){let t="",s=0;for(;s<e.length;)if(e[s]==='"'){for(s++;s<e.length&&e[s]!=='"';)e[s]==="\\"&&s+1<e.length?(t+=e[s+1],s+=2):(t+=e[s],s++);s<e.length&&s++}else t+=e[s],s++;return t}function Y(e,t){let s=Jc(t),{expr:r,pos:n}=We(e,s,0),i=ce(s,n);if(i<s.length){let a=t.slice(i).trim();if(a)return{type:"ArithmeticExpression",originalText:t,expression:{type:"ArithSyntaxError",errorToken:a,message:`${a}: syntax error: invalid arithmetic operator (error token is "${a}")`}}}return{type:"ArithmeticExpression",expression:r,originalText:t}}function _e(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function xe(e,t){return ce(e,t)>=e.length}function We(e,t,s){return eu(e,t,s)}function eu(e,t,s){let{expr:r,pos:n}=fs(e,t,s);for(n=ce(t,n);t[n]===",";){if(n++,xe(t,n))return _e(",",n);let{expr:a,pos:l}=fs(e,t,n);r={type:"ArithBinary",operator:",",left:r,right:a},n=ce(t,l)}return{expr:r,pos:n}}function fs(e,t,s){let{expr:r,pos:n}=tu(e,t,s);if(n=ce(t,n),t[n]==="?"){n++;let{expr:i,pos:a}=We(e,t,n);if(n=ce(t,a),t[n]===":"){n++;let{expr:l,pos:o}=We(e,t,n);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:l},pos:o}}}return{expr:r,pos:n}}function tu(e,t,s){let{expr:r,pos:n}=na(e,t,s);for(;n=ce(t,n),t.slice(n,n+2)==="||";){if(n+=2,xe(t,n))return _e("||",n);let{expr:a,pos:l}=na(e,t,n);r={type:"ArithBinary",operator:"||",left:r,right:a},n=l}return{expr:r,pos:n}}function na(e,t,s){let{expr:r,pos:n}=ra(e,t,s);for(;n=ce(t,n),t.slice(n,n+2)==="&&";){if(n+=2,xe(t,n))return _e("&&",n);let{expr:a,pos:l}=ra(e,t,n);r={type:"ArithBinary",operator:"&&",left:r,right:a},n=l}return{expr:r,pos:n}}function ra(e,t,s){let{expr:r,pos:n}=ia(e,t,s);for(;n=ce(t,n),t[n]==="|"&&t[n+1]!=="|";){if(n++,xe(t,n))return _e("|",n);let{expr:a,pos:l}=ia(e,t,n);r={type:"ArithBinary",operator:"|",left:r,right:a},n=l}return{expr:r,pos:n}}function ia(e,t,s){let{expr:r,pos:n}=aa(e,t,s);for(;n=ce(t,n),t[n]==="^";){if(n++,xe(t,n))return _e("^",n);let{expr:a,pos:l}=aa(e,t,n);r={type:"ArithBinary",operator:"^",left:r,right:a},n=l}return{expr:r,pos:n}}function aa(e,t,s){let{expr:r,pos:n}=oa(e,t,s);for(;n=ce(t,n),t[n]==="&"&&t[n+1]!=="&";){if(n++,xe(t,n))return _e("&",n);let{expr:a,pos:l}=oa(e,t,n);r={type:"ArithBinary",operator:"&",left:r,right:a},n=l}return{expr:r,pos:n}}function oa(e,t,s){let{expr:r,pos:n}=la(e,t,s);for(;n=ce(t,n),t.slice(n,n+2)==="=="||t.slice(n,n+2)==="!=";){let i=t.slice(n,n+2);if(n+=2,xe(t,n))return _e(i,n);let{expr:a,pos:l}=la(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}return{expr:r,pos:n}}function la(e,t,s){let{expr:r,pos:n}=Yn(e,t,s);for(;;)if(n=ce(t,n),t.slice(n,n+2)==="<="||t.slice(n,n+2)===">="){let i=t.slice(n,n+2);if(n+=2,xe(t,n))return _e(i,n);let{expr:a,pos:l}=Yn(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}else if(t[n]==="<"||t[n]===">"){let i=t[n];if(n++,xe(t,n))return _e(i,n);let{expr:a,pos:l}=Yn(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}else break;return{expr:r,pos:n}}function Yn(e,t,s){let{expr:r,pos:n}=ca(e,t,s);for(;n=ce(t,n),t.slice(n,n+2)==="<<"||t.slice(n,n+2)===">>";){let i=t.slice(n,n+2);if(n+=2,xe(t,n))return _e(i,n);let{expr:a,pos:l}=ca(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}return{expr:r,pos:n}}function ca(e,t,s){let{expr:r,pos:n}=ua(e,t,s);for(;n=ce(t,n),(t[n]==="+"||t[n]==="-")&&t[n+1]!==t[n];){let i=t[n];if(n++,xe(t,n))return _e(i,n);let{expr:a,pos:l}=ua(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}return{expr:r,pos:n}}function ua(e,t,s){let{expr:r,pos:n}=Vs(e,t,s);for(;;)if(n=ce(t,n),t[n]==="*"&&t[n+1]!=="*"){if(n++,xe(t,n))return _e("*",n);let{expr:a,pos:l}=Vs(e,t,n);r={type:"ArithBinary",operator:"*",left:r,right:a},n=l}else if(t[n]==="/"||t[n]==="%"){let i=t[n];if(n++,xe(t,n))return _e(i,n);let{expr:a,pos:l}=Vs(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}else break;return{expr:r,pos:n}}function Vs(e,t,s){let{expr:r,pos:n}=Jn(e,t,s),i=ce(t,n);if(t.slice(i,i+2)==="**"){if(i+=2,xe(t,i))return _e("**",i);let{expr:l,pos:o}=Vs(e,t,i);return{expr:{type:"ArithBinary",operator:"**",left:r,right:l},pos:o}}return{expr:r,pos:n}}function Jn(e,t,s){let r=ce(t,s);if(t.slice(r,r+2)==="++"||t.slice(r,r+2)==="--"){let n=t.slice(r,r+2);r+=2;let{expr:i,pos:a}=Jn(e,t,r);return{expr:{type:"ArithUnary",operator:n,operand:i,prefix:!0},pos:a}}if(t[r]==="+"||t[r]==="-"||t[r]==="!"||t[r]==="~"){let n=t[r];r++;let{expr:i,pos:a}=Jn(e,t,r);return{expr:{type:"ArithUnary",operator:n,operand:i,prefix:!0},pos:a}}return nu(e,t,r)}function su(e,t){let s=e[t];return s==="$"||s==="`"}function nu(e,t,s){let{expr:r,pos:n}=fa(e,t,s,!1),i=[r];for(;su(t,n);){let{expr:l,pos:o}=fa(e,t,n,!0);i.push(l),n=o}i.length>1&&(r={type:"ArithConcat",parts:i});let a;if(t[n]==="["&&r.type==="ArithConcat"){n++;let{expr:l,pos:o}=We(e,t,n);a=l,n=o,t[n]==="]"&&n++}if(a&&r.type==="ArithConcat"&&(r={type:"ArithDynamicElement",nameExpr:r,subscript:a},a=void 0),n=ce(t,n),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let l of Fs)if(t.slice(n,n+l.length)===l&&t.slice(n,n+l.length+1)!=="=="){n+=l.length;let{expr:o,pos:u}=fs(e,t,n);return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:l,target:r.nameExpr,subscript:r.subscript,value:o},pos:u}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:l,target:r,value:o},pos:u}:{expr:{type:"ArithAssignment",operator:l,variable:r.name,value:o},pos:u}}}if(t.slice(n,n+2)==="++"||t.slice(n,n+2)==="--"){let l=t.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:l,operand:r,prefix:!1},pos:n}}return{expr:r,pos:n}}function fa(e,t,s,r=!1){let n=ce(t,s),i=ea(We,e,t,n);if(i)return i;let a=ta(t,n);if(a)return a;let l=sa(t,n);if(l)return l;if(t.slice(n,n+2)==="$("&&t[n+2]!=="("){n+=2;let u=1,c=n;for(;n<t.length&&u>0;)t[n]==="("?u++:t[n]===")"&&u--,u>0&&n++;let f=t.slice(c,n);return n++,{expr:{type:"ArithCommandSubst",command:f},pos:n}}if(t[n]==="`"){n++;let u=n;for(;n<t.length&&t[n]!=="`";)n++;let c=t.slice(u,n);return t[n]==="`"&&n++,{expr:{type:"ArithCommandSubst",command:c},pos:n}}if(t[n]==="("){n++;let{expr:u,pos:c}=We(e,t,n);return n=ce(t,c),t[n]===")"&&n++,{expr:{type:"ArithGroup",expression:u},pos:n}}if(t[n]==="'"){n++;let u="";for(;n<t.length&&t[n]!=="'";)u+=t[n],n++;t[n]==="'"&&n++;let c=Number.parseInt(u,10);return{expr:{type:"ArithSingleQuote",content:u,value:Number.isNaN(c)?0:c},pos:n}}if(t[n]==='"'){n++;let u="";for(;n<t.length&&t[n]!=='"';)t[n]==="\\"&&n+1<t.length?(u+=t[n+1],n+=2):(u+=t[n],n++);t[n]==='"'&&n++;let c=u.trim();if(!c)return{expr:{type:"ArithNumber",value:0},pos:n};let{expr:f}=We(e,c,0);return{expr:f,pos:n}}if(/[0-9]/.test(t[n])){let u="",c=!1,f=!1;for(;n<t.length;){let h=t[n];if(c)if(/[0-9a-zA-Z@_]/.test(h))u+=h,n++;else break;else if(h==="#")c=!0,u+=h,n++;else if(u==="0"&&(h==="x"||h==="X")&&n+1<t.length&&/[0-9a-fA-F]/.test(t[n+1]))f=!0,u+=h,n++;else if(f&&/[0-9a-fA-F]/.test(h))u+=h,n++;else if(!f&&/[0-9]/.test(h))u+=h,n++;else break}if(n<t.length&&/[a-zA-Z_]/.test(t[n])){let h=u;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)h+=t[n],n++;return{expr:{type:"ArithSyntaxError",errorToken:h,message:`${h}: value too great for base (error token is "${h}")`},pos:n}}if(t[n]==="."&&/[0-9]/.test(t[n+1]))throw new se(`${u}.${t[n+1]}...: syntax error: invalid arithmetic operator`);if(t[n]==="["){let h=t.slice(n).trim();return{expr:{type:"ArithNumberSubscript",number:u,errorToken:h},pos:t.length}}return{expr:{type:"ArithNumber",value:us(u)},pos:n}}if(t[n]==="$"&&t[n+1]==="{"){let u=n+2,c=1,f=u;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;let d=t.slice(u,f),h=f+1;if(t[h]==="#"){let m=h+1;for(;m<t.length&&/[0-9a-zA-Z@_]/.test(t[m]);)m++;let p=t.slice(h+1,m);return{expr:{type:"ArithDynamicBase",baseExpr:d,value:p},pos:m}}if(/[0-9]/.test(t[h])||t[h]==="x"||t[h]==="X"){let m=h;if(t[h]==="x"||t[h]==="X")for(m++;m<t.length&&/[0-9a-fA-F]/.test(t[m]);)m++;else for(;m<t.length&&/[0-9]/.test(t[m]);)m++;let p=t.slice(h,m);return{expr:{type:"ArithDynamicNumber",prefix:d,suffix:p},pos:m}}return n=h,{expr:{type:"ArithBracedExpansion",content:d},pos:n}}if(t[n]==="$"&&n+1<t.length&&/[0-9]/.test(t[n+1])){n++;let u="";for(;n<t.length&&/[0-9]/.test(t[n]);)u+=t[n],n++;return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:!0},pos:n}}if(t[n]==="$"&&n+1<t.length&&/[*@#?\-!$]/.test(t[n+1])){let u=t[n+1];return n+=2,{expr:{type:"ArithSpecialVar",name:u},pos:n}}let o=!1;if(t[n]==="$"&&n+1<t.length&&/[a-zA-Z_]/.test(t[n+1])&&(o=!0,n++),n<t.length&&/[a-zA-Z_]/.test(t[n])){let u="";for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)u+=t[n],n++;if(t[n]==="["&&!r){n++;let c;if(t[n]==="'"||t[n]==='"'){let d=t[n];for(n++,c="";n<t.length&&t[n]!==d;)c+=t[n],n++;t[n]===d&&n++,n=ce(t,n),t[n]==="]"&&n++}let f;if(c===void 0){let{expr:d,pos:h}=We(e,t,n);f=d,n=h,t[n]==="]"&&n++}if(n=ce(t,n),t[n]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:u,index:f},pos:n};if(!r){for(let d of Fs)if(t.slice(n,n+d.length)===d&&t.slice(n,n+d.length+1)!=="=="){n+=d.length;let{expr:h,pos:m}=fs(e,t,n);return{expr:{type:"ArithAssignment",operator:d,variable:u,subscript:f,stringKey:c,value:h},pos:m}}}return{expr:{type:"ArithArrayElement",array:u,index:f,stringKey:c},pos:n}}if(n=ce(t,n),!r){for(let c of Fs)if(t.slice(n,n+c.length)===c&&t.slice(n,n+c.length+1)!=="=="){n+=c.length;let{expr:f,pos:d}=fs(e,t,n);return{expr:{type:"ArithAssignment",operator:c,variable:u,value:f},pos:d}}}return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:o},pos:n}}if(t[n]==="#"){let u=n+1;for(;u<t.length&&t[u]!==`
58
- `;)u++;let c=t.slice(n,u).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:c,message:`${c}: syntax error: invalid arithmetic operator (error token is "${c}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:n}}function ru(e){let t="",s=0;for(;s<e.length;){let r=e[s];if(r<128){t+=String.fromCharCode(r),s++;continue}if((r&224)===192){if(s+1<e.length&&(e[s+1]&192)===128&&r>=194){let n=(r&31)<<6|e[s+1]&63;t+=String.fromCharCode(n),s+=2;continue}t+=String.fromCharCode(r),s++;continue}if((r&240)===224){if(s+2<e.length&&(e[s+1]&192)===128&&(e[s+2]&192)===128){if(r===224&&e[s+1]<160){t+=String.fromCharCode(r),s++;continue}let n=(r&15)<<12|(e[s+1]&63)<<6|e[s+2]&63;if(n>=55296&&n<=57343){t+=String.fromCharCode(r),s++;continue}t+=String.fromCharCode(n),s+=3;continue}t+=String.fromCharCode(r),s++;continue}if((r&248)===240&&r<=244){if(s+3<e.length&&(e[s+1]&192)===128&&(e[s+2]&192)===128&&(e[s+3]&192)===128){if(r===240&&e[s+1]<144){t+=String.fromCharCode(r),s++;continue}let n=(r&7)<<18|(e[s+1]&63)<<12|(e[s+2]&63)<<6|e[s+3]&63;if(n>1114111){t+=String.fromCharCode(r),s++;continue}t+=String.fromCodePoint(n),s+=4;continue}t+=String.fromCharCode(r),s++;continue}t+=String.fromCharCode(r),s++}return t}function pa(e,t,s){let r=s+1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;return r}function er(e,t,s,r,n){let i=1,a=s+1;for(;a<t.length&&i>0;)t[a]===r?i++:t[a]===n&&i--,i>0&&a++;return i===0?a:-1}function Ot(e,t,s){let r=s,n=1;for(;r<t.length&&n>0;){let i=t[r];if(i==="\\"&&r+1<t.length){r+=2;continue}if(i==="'"){let a=t.indexOf("'",r+1);if(a!==-1){r=a+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==="{"?n++:i==="}"&&n--,n>0&&r++}return r}function ma(e,t,s){let r=s,n=!1;for(;r<t.length;){let i=t[r];if(i==="/"&&n||i==="}")break;if(i==="'"){let a=t.indexOf("'",r+1);if(a!==-1){r=a+1,n=!0;continue}}if(i==='"'){for(r++;r<t.length&&t[r]!=='"';)t[r]==="\\"&&r+1<t.length?r+=2:r++;r<t.length&&r++,n=!0;continue}i==="\\"?(r+=2,n=!0):(r++,n=!0)}return r}function ga(e,t,s){let r=s,n="";for(;r<t.length;){let i=t[r];if(i==="*"||i==="?")n+=i,r++;else if(i==="["){let a=iu(t,r);a===-1?(n+=i,r++):(n+=t.slice(r,a+1),r=a+1)}else break}return{pattern:n,endIndex:r}}function iu(e,t){let s=t+1;for(s<e.length&&e[s]==="^"&&s++,s<e.length&&e[s]==="]"&&s++;s<e.length;){let r=e[s];if(r==="\\"&&s+1<e.length){let n=e[s+1];if(n==='"'||n==="'")return-1;s+=2;continue}if(r==="]")return s;if(r==='"'||r==="$"||r==="`")return-1;if(r==="'"){let n=e.indexOf("'",s+1);if(n!==-1){s=n+1;continue}}if(r==="["&&s+1<e.length&&e[s+1]===":"){let n=e.indexOf(":]",s+2);if(n!==-1){s=n+2;continue}}if(r==="["&&s+1<e.length&&(e[s+1]==="."||e[s+1]==="=")){let i=`${e[s+1]}]`,a=e.indexOf(i,s+2);if(a!==-1){s=a+2;continue}}s++}return-1}function ya(e,t,s){let r="",n=s;for(;n<t.length&&t[n]!=="'";){let i=t[n];if(i==="\\"&&n+1<t.length)switch(t[n+1]){case"n":r+=`
59
- `,n+=2;break;case"t":r+=" ",n+=2;break;case"r":r+="\r",n+=2;break;case"\\":r+="\\",n+=2;break;case"'":r+="'",n+=2;break;case'"':r+='"',n+=2;break;case"a":r+="\x07",n+=2;break;case"b":r+="\b",n+=2;break;case"e":case"E":r+="\x1B",n+=2;break;case"f":r+="\f",n+=2;break;case"v":r+="\v",n+=2;break;case"x":{let l=[],o=n;for(;o+1<t.length&&t[o]==="\\"&&t[o+1]==="x";){let u=t.slice(o+2,o+4),c=parseInt(u,16);if(!Number.isNaN(c)&&u.length>0)l.push(c),o+=2+u.length;else break}l.length>0?(r+=ru(l),n=o):(r+="\\x",n+=2);break}case"u":{let l=t.slice(n+2,n+6),o=parseInt(l,16);Number.isNaN(o)?(r+="\\u",n+=2):(r+=String.fromCharCode(o),n+=6);break}case"c":{if(n+2<t.length){let o=t[n+2].charCodeAt(0)&31;r+=String.fromCharCode(o),n+=3}else r+="\\c",n+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let l="",o=n+1;for(;o<t.length&&o<n+4&&/[0-7]/.test(t[o]);)l+=t[o],o++;let u=parseInt(l,8);r+=String.fromCharCode(u),n=o;break}default:r+=i,n++}else r+=i,n++}return n<t.length&&t[n]==="'"&&n++,{part:I.literal(r),endIndex:n}}function tr(e,t){let s=t.trim();return s===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:Y(e,s)}function ha(e){let t=[],s="",r=0;for(let n=0;n<e.length;n++){let i=e[n];i==="{"?(r++,s+=i):i==="}"?(r--,s+=i):i===","&&r===0?(t.push(s),s=""):s+=i}return t.push(s),t}function wa(e,t,s,r){let n=er(e,t,s,"{","}");if(n===-1)return null;let i=t.slice(s+1,n),a=i.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(a)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(a[1],10),end:Number.parseInt(a[2],10),step:a[3]?Number.parseInt(a[3],10):void 0,startStr:a[1],endStr:a[2]}]},endIndex:n+1};let l=i.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return l?{part:{type:"BraceExpansion",items:[{type:"Range",start:l[1],end:l[2],step:l[3]?Number.parseInt(l[3],10):void 0}]},endIndex:n+1}:i.includes(",")&&r?{part:{type:"BraceExpansion",items:ha(i).map(c=>({type:"Word",word:I.word(r(e,c,!1,!1,!1))}))},endIndex:n+1}:i.includes(",")?{part:{type:"BraceExpansion",items:ha(i).map(c=>({type:"Word",word:I.word([I.literal(c)])}))},endIndex:n+1}:null}function sr(e,t){let s="";for(let r of t.parts)switch(r.type){case"Literal":s+=r.value;break;case"SingleQuoted":s+=`'${r.value}'`;break;case"Escaped":s+=r.value;break;case"DoubleQuoted":s+='"';for(let n of r.parts)n.type==="Literal"||n.type==="Escaped"?s+=n.value:n.type==="ParameterExpansion"&&(s+=`\${${n.parameter}}`);s+='"';break;case"ParameterExpansion":s+=`\${${r.parameter}}`;break;case"Glob":s+=r.pattern;break;case"TildeExpansion":s+="~",r.user&&(s+=r.user);break;case"BraceExpansion":{s+="{";let n=[];for(let i of r.items)if(i.type==="Range"){let a=i.startStr??String(i.start),l=i.endStr??String(i.end);i.step!==void 0?n.push(`${a}..${l}..${i.step}`):n.push(`${a}..${l}`)}else n.push(sr(e,i.word));n.length===1&&r.items[0].type==="Range"?s+=n[0]:s+=n.join(","),s+="}";break}default:s+=r.type}return s}function Ea(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 zs(e){let t=e.current(),s=t.type;if(s===g.NUMBER){let r=e.peek(1);return t.end!==r.start?!1:Yi.has(r.type)}if(s===g.FD_VARIABLE){let r=e.peek(1);return Ji.has(r.type)}return Xi.has(s)}function Bs(e){let t=null,s;e.check(g.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(g.FD_VARIABLE)&&(s=e.advance().value);let r=e.advance(),n=Ea(e,r.type);if(r.type===g.DLESS||r.type===g.DLESSDASH)return au(e,n,t,r.type===g.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return I.redirection(n,i,t,s)}function au(e,t,s,r){e.isWord()||e.error("Expected here-document delimiter");let n=e.advance(),i=n.value,a=n.quoted||!1;(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1));let l=I.redirection(r?"<<-":"<<",I.hereDoc(i,I.word([]),r,a),s);return e.addPendingHeredoc(l,i,r,a),l}function va(e){let t=e.current().line,s=[],r=null,n=[],i=[];for(;e.check(g.ASSIGNMENT_WORD)||zs(e);)e.checkIterationLimit(),e.check(g.ASSIGNMENT_WORD)?s.push(ou(e)):i.push(Bs(e));if(e.isWord())r=e.parseWord();else if(s.length>0&&(e.check(g.DBRACK_START)||e.check(g.DPAREN_START))){let l=e.advance();r=I.word([I.literal(l.value)])}for(;(!e.isStatementEnd()||e.check(g.RBRACE))&&!e.check(g.PIPE,g.PIPE_AMP);)if(e.checkIterationLimit(),zs(e))i.push(Bs(e));else if(e.check(g.RBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(g.LBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(g.DBRACK_END)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.isWord())n.push(e.parseWord());else if(e.check(g.ASSIGNMENT_WORD)){let l=e.advance(),o=l.value,u=o.endsWith("="),c=o.endsWith("=(");if((u||c)&&(c||e.check(g.LPAREN))){let f=c?o.slice(0,-2):o.slice(0,-1);c||e.expect(g.LPAREN);let d=nr(e);e.expect(g.RPAREN);let h=d.map(p=>sr(e,p)),m=`${f}=(${h.join(" ")})`;n.push(e.parseWordFromString(m,!1,!1))}else n.push(e.parseWordFromString(o,l.quoted,l.singleQuoted))}else if(e.check(g.LPAREN))e.error("syntax error near unexpected token `('");else break;let a=I.simpleCommand(r,n,s,i);return a.line=t,a}function ou(e){let t=e.expect(g.ASSIGNMENT_WORD),s=t.value,r=s.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||e.error(`Invalid assignment: ${s}`);let n=r[0],i,a=n.length;if(s[a]==="["){let f=0,d=a+1;for(;a<s.length;a++)if(s[a]==="[")f++;else if(s[a]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${s}`),i=s.slice(d,a),a++}let l=s[a]==="+";l&&a++,s[a]!=="="&&e.error(`Invalid assignment: ${s}`),a++;let o=s.slice(a);if(o==="("){let f=nr(e);e.expect(g.RPAREN);let d=i!==void 0?`${n}[${i}]`:n;return I.assignment(d,null,l,f)}if(o===""&&e.check(g.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=nr(e);e.expect(g.RPAREN);let h=i!==void 0?`${n}[${i}]`:n;return I.assignment(h,null,l,d)}}let u=o?e.parseWordFromString(o,t.quoted,t.singleQuoted,!0):null,c=i!==void 0?`${n}[${i}]`:n;return I.assignment(c,u,l,null)}var lu=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 nr(e){let t=[];for(e.skipNewlines();!e.check(g.RPAREN,g.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):lu.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function rr(e,t){e.expect(g.IF);let s=[],r=e.parseCompoundList();e.expect(g.THEN);let n=e.parseCompoundList();if(n.length===0){let l=e.check(g.FI)?"fi":e.check(g.ELSE)?"else":e.check(g.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${l}'`)}for(s.push({condition:r,body:n});e.check(g.ELIF);){e.advance();let l=e.parseCompoundList();e.expect(g.THEN);let o=e.parseCompoundList();if(o.length===0){let u=e.check(g.FI)?"fi":e.check(g.ELSE)?"else":e.check(g.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${u}'`)}s.push({condition:l,body:o})}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 a=t?.skipRedirections?[]:e.parseOptionalRedirections();return I.ifNode(s,i,a)}function ir(e,t){let s=e.expect(g.FOR);if(e.check(g.DPAREN_START))return uu(e,t,s.line);e.isWord()||e.error("Expected variable name in for loop");let n=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 a=e.parseCompoundList();e.expect(g.DONE);let l=t?.skipRedirections?[]:e.parseOptionalRedirections();return I.forNode(n,i,a,l)}function uu(e,t,s){e.expect(g.DPAREN_START);let r=null,n=null,i=null,a=["","",""],l=0,o=0;for(;!e.check(g.DPAREN_END,g.EOF);){let f=e.advance();if(f.type===g.SEMICOLON&&o===0){if(l++,l>2)break}else f.value==="("&&o++,f.value===")"&&o--,a[l]+=f.value}e.expect(g.DPAREN_END),a[0].trim()&&(r=Y(e,a[0].trim())),a[1].trim()&&(n=Y(e,a[1].trim())),a[2].trim()&&(i=Y(e,a[2].trim())),e.skipNewlines(),e.check(g.SEMICOLON)&&e.advance(),e.skipNewlines();let u;e.check(g.LBRACE)?(e.advance(),u=e.parseCompoundList(),e.expect(g.RBRACE)):(e.expect(g.DO),u=e.parseCompoundList(),e.expect(g.DONE));let c=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:n,update:i,body:u,redirections:c,line:s}}function ar(e,t){e.expect(g.WHILE);let s=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 n=t?.skipRedirections?[]:e.parseOptionalRedirections();return I.whileNode(s,r,n)}function or(e,t){e.expect(g.UNTIL);let s=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 n=t?.skipRedirections?[]:e.parseOptionalRedirections();return I.untilNode(s,r,n)}function lr(e,t){e.expect(g.CASE),e.isWord()||e.error("Expected word after 'case'");let s=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(),a=fu(e);if(a&&r.push(a),e.skipNewlines(),e.getPos()===i&&!a)break}e.expect(g.ESAC);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return I.caseNode(s,r,n)}function fu(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 s=[];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 n=e.getPos(),i=e.parseStatement();if(i&&s.push(i),e.skipSeparators(!1),e.getPos()===n&&!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=";;&"),I.caseItem(t,s,r)}function cr(e,t){e.expect(g.LPAREN);let s=e.parseCompoundList();e.expect(g.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return I.subshell(s,r)}function ur(e,t){e.expect(g.LBRACE);let s=e.parseCompoundList();e.expect(g.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return I.group(s,r)}var hu=["-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"],pu=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function Sa(e){return e.isWord()||e.check(g.LBRACE)||e.check(g.RBRACE)||e.check(g.ASSIGNMENT_WORD)}function Aa(e){if(e.check(g.BANG)&&e.peek(1).type===g.LPAREN){e.advance(),e.advance();let t=1,s="!(";for(;t>0&&!e.check(g.EOF);)if(e.check(g.LPAREN))t++,s+="(",e.advance();else if(e.check(g.RPAREN))t--,t>0&&(s+=")"),e.advance();else if(e.isWord())s+=e.advance().value;else if(e.check(g.PIPE))s+="|",e.advance();else break;return s+=")",e.parseWordFromString(s,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function dr(e){return e.skipNewlines(),mu(e)}function mu(e){let t=$a(e);for(e.skipNewlines();e.check(g.OR_OR);){e.advance(),e.skipNewlines();let s=$a(e);t={type:"CondOr",left:t,right:s},e.skipNewlines()}return t}function $a(e){let t=fr(e);for(e.skipNewlines();e.check(g.AND_AND);){e.advance(),e.skipNewlines();let s=fr(e);t={type:"CondAnd",left:t,right:s},e.skipNewlines()}return t}function fr(e){return e.skipNewlines(),e.check(g.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:fr(e)}):gu(e)}function gu(e){if(e.check(g.LPAREN)){e.advance();let t=dr(e);return e.expect(g.RPAREN),{type:"CondGroup",expression:t}}if(Sa(e)){let t=e.current(),s=t.value;if(hu.includes(s)&&!t.quoted){if(e.advance(),e.check(g.DBRACK_END)&&e.error(`Expected operand after ${s}`),Sa(e)){let i=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:s,operand:i}}let n=e.current();e.error(`unexpected argument \`${n.value}' to conditional unary operator`)}let r=e.parseWordNoBraceExpansion();if(e.isWord()&&pu.includes(e.current().value)){let n=e.advance().value,i;return n==="=~"?i=yu(e):n==="=="||n==="!="?i=Aa(e):i=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:n,left:r,right:i}}if(e.check(g.LESS)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:r,right:n}}if(e.check(g.GREAT)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:r,right:n}}if(e.isWord()&&e.current().value==="="){e.advance();let n=Aa(e);return{type:"CondBinary",operator:"==",left:r,right:n}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function yu(e){let t=[],s=0,r=-1,n=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 a=e.current(),l=r>=0&&a.start>r;if(s===0&&l)break;if(s>0&&l){let o=n.slice(r,a.start);t.push({type:"Literal",value:o})}if(e.isWord()||e.check(g.ASSIGNMENT_WORD)){let o=e.parseWordForRegex();t.push(...o.parts),r=e.peek(-1).end}else if(e.check(g.LPAREN)){let o=e.advance();t.push({type:"Literal",value:"("}),s++,r=o.end}else if(e.check(g.DPAREN_START)){let o=e.advance();t.push({type:"Literal",value:"(("}),s+=2,r=o.end}else if(e.check(g.DPAREN_END))if(s>=2){let o=e.advance();t.push({type:"Literal",value:"))"}),s-=2,r=o.end}else{if(s===1)break;break}else if(e.check(g.RPAREN))if(s>0){let o=e.advance();t.push({type:"Literal",value:")"}),s--,r=o.end}else break;else if(e.check(g.PIPE)){let o=e.advance();t.push({type:"Literal",value:"|"}),r=o.end}else if(e.check(g.SEMICOLON))if(s>0){let o=e.advance();t.push({type:"Literal",value:";"}),r=o.end}else break;else if(s>0&&e.check(g.LESS)){let o=e.advance();t.push({type:"Literal",value:"<"}),r=o.end}else if(s>0&&e.check(g.GREAT)){let o=e.advance();t.push({type:"Literal",value:">"}),r=o.end}else if(s>0&&e.check(g.DGREAT)){let o=e.advance();t.push({type:"Literal",value:">>"}),r=o.end}else if(s>0&&e.check(g.DLESS)){let o=e.advance();t.push({type:"Literal",value:"<<"}),r=o.end}else if(s>0&&e.check(g.LESSAND)){let o=e.advance();t.push({type:"Literal",value:"<&"}),r=o.end}else if(s>0&&e.check(g.GREATAND)){let o=e.advance();t.push({type:"Literal",value:">&"}),r=o.end}else if(s>0&&e.check(g.LESSGREAT)){let o=e.advance();t.push({type:"Literal",value:"<>"}),r=o.end}else if(s>0&&e.check(g.CLOBBER)){let o=e.advance();t.push({type:"Literal",value:">|"}),r=o.end}else if(s>0&&e.check(g.TLESS)){let o=e.advance();t.push({type:"Literal",value:"<<<"}),r=o.end}else if(s>0&&e.check(g.AMP)){let o=e.advance();t.push({type:"Literal",value:"&"}),r=o.end}else if(s>0&&e.check(g.LBRACE)){let o=e.advance();t.push({type:"Literal",value:"{"}),r=o.end}else if(s>0&&e.check(g.RBRACE)){let o=e.advance();t.push({type:"Literal",value:"}"}),r=o.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function ds(e){return e.length>0?e:[I.literal("")]}function Eu(e,t){let s=1,r=t+1;for(;r<e.length&&s>0;){let n=e[r];if(n==="\\"){r+=2;continue}if("@*+?!".includes(n)&&r+1<e.length&&e[r+1]==="("){r++,s++,r++;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function bu(e,t,s){let r=s+1,n=t[r];if("@*#?$!-0123456789".includes(n))return{part:I.parameterExpansion(n),endIndex:r+1};let i="";for(;r<t.length&&/[a-zA-Z0-9_]/.test(t[r]);)i+=t[r],r++;return{part:I.parameterExpansion(i),endIndex:r}}function vu(e,t,s,r=!1){let n=s+2,i=!1;t[n]==="!"&&(i=!0,n++);let a=!1;t[n]==="#"&&!/[}:#%/^,]/.test(t[n+1]||"}")&&(a=!0,n++);let l="",o=t[n];if(/[@*#?$!-]/.test(o)&&!/[a-zA-Z0-9_]/.test(t[n+1]||""))l=o,n++;else for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)l+=t[n],n++;if(t[n]==="["){let c=er(e,t,n,"[","]");if(l+=t.slice(n,c+1),n=c+1,t[n]==="["){let f=1,d=n;for(;d<t.length&&f>0;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let h=t.slice(s+2,d);return{part:I.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:d+1}}}if(l===""&&!i&&!a&&t[n]!=="}"){let c=1,f=n;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;if(c>0)throw new Ee("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(s+2,f);return{part:I.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let u=null;if(i){let c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(c)if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=hr(e,t,n,l,r);f.operation?(u={type:"Indirection",innerOp:f.operation},n=f.endIndex):(u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},l="")}else u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},l="";else if(t[n]==="*"||t[n]==="@"&&!/[QPaAEKkuUL]/.test(t[n+1]||"")){let f=t[n];n++,u={type:"VarNamePrefix",prefix:l,star:f==="*"},l=""}else if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=hr(e,t,n,l,r);f.operation?(u={type:"Indirection",innerOp:f.operation},n=f.endIndex):u={type:"Indirection"}}else u={type:"Indirection"}}else if(a)if(t[n]===":")for(u={type:"LengthSliceError"};n<t.length&&t[n]!=="}";)n++;else t[n]!=="}"&&/[-+=?]/.test(t[n])?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):t[n]==="/"?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):u={type:"Length"};if(!u&&n<t.length&&t[n]!=="}"){let c=hr(e,t,n,l,r);u=c.operation,n=c.endIndex}if(n<t.length&&t[n]!=="}"){let c=t[n];if(!/[:\-+=?#%/^,@[]/.test(c)){let f=n;for(;f<t.length&&t[f]!=="}";)f++;let d=t.slice(s,f+1);e.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;n<t.length&&t[n]!=="}";)n++;if(n>=t.length)throw new Ee("unexpected EOF while looking for matching '}'",0,0);return{part:I.parameterExpansion(l,u),endIndex:n+1}}function hr(e,t,s,r,n=!1){let i=s,a=t[i],l=t[i+1]||"";if(a===":"){let o=l;if("-=?+".includes(o)){i+=2;let b=Ot(e,t,i),v=t.slice(i,b),E=$t(e,v,!1,!1,!0,!1,n,!1,!1,!0),w=I.word(ds(E));if(o==="-")return{operation:{type:"DefaultValue",word:w,checkEmpty:!0},endIndex:b};if(o==="=")return{operation:{type:"AssignDefault",word:w,checkEmpty:!0},endIndex:b};if(o==="?")return{operation:{type:"ErrorIfUnset",word:w,checkEmpty:!0},endIndex:b};if(o==="+")return{operation:{type:"UseAlternative",word:w,checkEmpty:!0},endIndex:b}}i++;let u=Ot(e,t,i),c=t.slice(i,u),f=-1,d=0,h=0;for(let y=0;y<c.length;y++){let b=c[y];if(b==="("||b==="[")d++;else if(b===")"||b==="]")d--;else if(b==="?"&&d===0)h++;else if(b===":"&&d===0)if(h>0)h--;else{f=y;break}}let m=f>=0?c.slice(0,f):c,p=f>=0?c.slice(f+1):null;return{operation:{type:"Substring",offset:tr(e,m),length:p!==null?tr(e,p):null},endIndex:u}}if("-=?+".includes(a)){i++;let o=Ot(e,t,i),u=t.slice(i,o),c=$t(e,u,!1,!1,!0,!1,n,!1,!1,!0),f=I.word(ds(c));if(a==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:o};if(a==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:o};if(a==="?")return{operation:{type:"ErrorIfUnset",word:u?f:null,checkEmpty:!1},endIndex:o};if(a==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:o}}if(a==="#"||a==="%"){let o=l===a,u=a==="#"?"prefix":"suffix";i+=o?2:1;let c=Ot(e,t,i),f=t.slice(i,c),d=$t(e,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:I.word(ds(d)),side:u,greedy:o},endIndex:c}}if(a==="/"){let o=l==="/";i+=o?2:1;let u=null;t[i]==="#"?(u="start",i++):t[i]==="%"&&(u="end",i++);let c;u!==null&&(t[i]==="/"||t[i]==="}")?c=i:c=ma(e,t,i);let f=t.slice(i,c),d=$t(e,f,!1,!1,!1),h=I.word(ds(d)),m=null,p=c;if(t[c]==="/"){let y=c+1,b=Ot(e,t,y),v=t.slice(y,b),E=$t(e,v,!1,!1,!1);m=I.word(ds(E)),p=b}return{operation:{type:"PatternReplacement",pattern:h,replacement:m,all:o,anchor:u},endIndex:p}}if(a==="^"||a===","){let o=l===a,u=a==="^"?"upper":"lower";i+=o?2:1;let c=Ot(e,t,i),f=t.slice(i,c),d=f?I.word([I.literal(f)]):null;return{operation:{type:"CaseModification",direction:u,all:o,pattern:d},endIndex:c}}return a==="@"&&/[QPaAEKkuUL]/.test(l)?{operation:{type:"Transform",operator:l},endIndex:i+2}:{operation:null,endIndex:i}}function pr(e,t,s,r=!1){let n=s+1;if(n>=t.length)return{part:I.literal("$"),endIndex:n};let i=t[n];if(i==="("&&t[n+1]==="(")return e.isDollarDparenSubshell(t,s)?e.parseCommandSubstitution(t,s):e.parseArithmeticExpansion(t,s);if(i==="["){let a=1,l=n+1;for(;l<t.length&&a>0;)t[l]==="["?a++:t[l]==="]"&&a--,a>0&&l++;if(a===0){let o=t.slice(n+1,l),u=Y(e,o);return{part:I.arithmeticExpansion(u),endIndex:l+1}}}return i==="("?e.parseCommandSubstitution(t,s):i==="{"?vu(e,t,s,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?bu(e,t,s):{part:I.literal("$"),endIndex:n}}function Pa(e,t){let s=[],r=0,n="",i=()=>{n&&(s.push(I.literal(n)),n="")};for(;r<t.length;){let a=t[r];if(a==="\\"&&r+1<t.length){let l=t[r+1];if(l==="$"||l==="`"||l==='"'||l==="\\"){n+=l,r+=2;continue}n+=a,r++;continue}if(a==="$"){i();let{part:l,endIndex:o}=pr(e,t,r,!0);l&&s.push(l),r=o;continue}if(a==="`"){i();let{part:l,endIndex:o}=e.parseBacktickSubstitution(t,r,!0);s.push(l),r=o;continue}n+=a,r++}return i(),s}function Su(e,t,s){let r=[],n=s,i="",a=()=>{i&&(r.push(I.literal(i)),i="")};for(;n<t.length&&t[n]!=='"';){let l=t[n];if(l==="\\"&&n+1<t.length){let o=t[n+1];if('"\\$`\n'.includes(o)){i+=o,n+=2;continue}i+=l,n++;continue}if(l==="$"){a();let{part:o,endIndex:u}=pr(e,t,n,!0);o&&r.push(o),n=u;continue}if(l==="`"){a();let{part:o,endIndex:u}=e.parseBacktickSubstitution(t,n,!0);r.push(o),n=u;continue}i+=l,n++}return a(),{part:I.doubleQuoted(r),endIndex:n}}function $t(e,t,s=!1,r=!1,n=!1,i=!1,a=!1,l=!1,o=!1,u=!1){if(r)return[I.singleQuoted(t)];if(s){let m=Pa(e,t);return[I.doubleQuoted(m)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let m=t.slice(1,-1),p=!1;for(let y=0;y<m.length;y++){if(m[y]==='"'){p=!0;break}m[y]==="\\"&&y+1<m.length&&y++}if(!p){let y=Pa(e,m);return[I.doubleQuoted(y)]}}let c=[],f=0,d="",h=()=>{d&&(c.push(I.literal(d)),d="")};for(;f<t.length;){let m=t[f];if(m==="\\"&&f+1<t.length){let p=t[f+1];if(o){h(),c.push(I.escaped(p)),f+=2;continue}let y=i?p==="$"||p==="`"||p===`
60
- `:p==="$"||p==="`"||p==='"'||p==="'"||p===`
61
- `||u&&p==="}",b=a?"*?[]\\".includes(p):"*?[]\\(){}.^+".includes(p);y?d+=p:b?(h(),c.push(I.escaped(p))):d+=`\\${p}`,f+=2;continue}if(m==="'"&&!a&&!i){h();let p=t.indexOf("'",f+1);if(p===-1){d+=t.slice(f);break}c.push(I.singleQuoted(t.slice(f+1,p))),f=p+1;continue}if(m==='"'&&!i){h();let{part:p,endIndex:y}=Su(e,t,f+1);c.push(p),f=y+1;continue}if(m==="$"&&t[f+1]==="'"){h();let{part:p,endIndex:y}=ya(e,t,f+2);c.push(p),f=y;continue}if(m==="$"){h();let{part:p,endIndex:y}=pr(e,t,f);p&&c.push(p),f=y;continue}if(m==="`"){h();let{part:p,endIndex:y}=e.parseBacktickSubstitution(t,f);c.push(p),f=y;continue}if(m==="~"){let p=f>0?t[f-1]:"";if(f===0||p==="="||n&&p===":"){let b=pa(e,t,f),v=t[b];if(v===void 0||v==="/"||v===":"){h();let E=t.slice(f+1,b)||null;c.push({type:"TildeExpansion",user:E}),f=b;continue}}}if("@*+?!".includes(m)&&f+1<t.length&&t[f+1]==="("){let p=Eu(t,f+1);if(p!==-1){h();let y=t.slice(f,p+1);c.push({type:"Glob",pattern:y}),f=p+1;continue}}if(m==="*"||m==="?"||m==="["){h();let{pattern:p,endIndex:y}=ga(e,t,f);c.push({type:"Glob",pattern:p}),f=y;continue}if(m==="{"&&!n&&!l&&!i){let p=wa(e,t,f,$t);if(p){h(),c.push(p.part),f=p.endIndex;continue}}d+=m,f++}return h(),c}var q=class e{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;parseDepth=0;_input="";getInput(){return this._input}checkIterationLimit(){if(this.parseIterations++,this.parseIterations>Ki)throw new Ee("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}enterDepth(){if(this.parseDepth++,this.parseDepth>Xn)throw new Ee(`Maximum parser nesting depth exceeded (${Xn})`,this.current().line,this.current().column);return()=>{this.parseDepth--}}parse(t,s){if(t.length>Qn)throw new Ee(`Input too large: ${t.length} bytes exceeds limit of ${Qn}`,1,1);this._input=t;let r=new Ws(t,s);if(this.tokens=r.tokenize(),this.tokens.length>Kn)throw new Ee(`Too many tokens: ${this.tokens.length} exceeds limit of ${Kn}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}parseTokens(t){return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}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}check(t,s,r,n,...i){let a=this.tokens[this.pos]?.type;return a===t||s!==void 0&&a===s||r!==void 0&&a===r||n!==void 0&&a===n?!0:i.length>0?i.includes(a):!1}expect(t,s){if(this.check(t))return this.advance();let r=this.current();throw new Ee(s||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let s=this.current();throw new Ee(t,s.line,s.column,s)}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,s,r,n){this.pendingHeredocs.push({redirect:t,delimiter:s,stripTabs:r,quoted:n})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(g.HEREDOC_CONTENT)){let s=this.advance(),r;t.quoted?r=I.word([I.literal(s.value)]):r=this.parseWordFromString(s.value,!1,!1,!1,!0),t.redirect.target=I.hereDoc(t.delimiter,r,t.stripTabs,t.quoted)}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 t===g.WORD||t===g.NAME||t===g.NUMBER||t===g.ASSIGNMENT_WORD||t===g.IF||t===g.FOR||t===g.WHILE||t===g.UNTIL||t===g.CASE||t===g.LPAREN||t===g.LBRACE||t===g.DPAREN_START||t===g.DBRACK_START||t===g.FUNCTION||t===g.BANG||t===g.TIME||t===g.IN||t===g.LESS||t===g.GREAT||t===g.DLESS||t===g.DGREAT||t===g.LESSAND||t===g.GREATAND||t===g.LESSGREAT||t===g.DLESSDASH||t===g.CLOBBER||t===g.TLESS||t===g.AND_GREAT||t===g.AND_DGREAT}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(g.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)");let n=this.checkUnexpectedToken();if(n){t.push(n),this.skipSeparators(!1);continue}let i=this.pos,a=this.parseStatement();a&&t.push(a),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.advance()}return I.script(t)}checkUnexpectedToken(){let t=this.current().type,s=this.current().value;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 \`${s}'`),t===g.RBRACE||t===g.RPAREN){let r=`syntax error near unexpected token \`${s}'`;return this.advance(),I.statement([I.pipeline([I.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:s})}return(t===g.DSEMI||t===g.SEMI_AND||t===g.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${s}'`),t===g.SEMICOLON&&this.error(`syntax error near unexpected token \`${s}'`),(t===g.PIPE||t===g.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${s}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,s=[],r=[],n=!1,i=this.parsePipeline();for(s.push(i);this.check(g.AND_AND,g.OR_OR);){let o=this.advance();r.push(o.type===g.AND_AND?"&&":"||"),this.skipNewlines();let u=this.parsePipeline();s.push(u)}this.check(g.AMP)&&(this.advance(),n=!0);let a=this.pos>0?this.tokens[this.pos-1].end:t,l=this._input.slice(t,a);return I.statement(s,r,n,void 0,l)}parsePipeline(){let t=!1,s=!1;this.check(g.TIME)&&(this.advance(),t=!0,this.check(g.WORD,g.NAME)&&this.current().value==="-p"&&(this.advance(),s=!0));let r=0;for(;this.check(g.BANG);)this.advance(),r++;let n=r%2===1,i=[],a=[],l=this.parseCommand();for(i.push(l);this.check(g.PIPE,g.PIPE_AMP);){let o=this.advance();this.skipNewlines(),a.push(o.type===g.PIPE_AMP);let u=this.parseCommand();i.push(u)}return I.pipeline(i,n,t,s,a.length>0?a:void 0)}parseCommand(){return this.check(g.IF)?rr(this):this.check(g.FOR)?ir(this):this.check(g.WHILE)?ar(this):this.check(g.UNTIL)?or(this):this.check(g.CASE)?lr(this):this.check(g.LPAREN)?cr(this):this.check(g.LBRACE)?ur(this):this.check(g.DPAREN_START)?this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand():this.check(g.DBRACK_START)?this.parseConditionalCommand():this.check(g.FUNCTION)?this.parseFunctionDef():this.check(g.NAME,g.WORD)&&this.peek(1).type===g.LPAREN&&this.peek(2).type===g.RPAREN?this.parseFunctionDef():va(this)}dparenClosesWithSpacedParens(){let t=1,s=1;for(;s<this.tokens.length-this.pos;){let r=this.peek(s);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(s+1).type===g.RPAREN))return!0;s++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(g.RPAREN),this.expect(g.RPAREN);let s=this.parseOptionalRedirections(),r=I.subshell(t,[]);return I.subshell([I.statement([I.pipeline([r],!1,!1,!1)])],s)}isWord(){let t=this.current().type;return t===g.WORD||t===g.NAME||t===g.NUMBER||t===g.IF||t===g.FOR||t===g.WHILE||t===g.UNTIL||t===g.CASE||t===g.FUNCTION||t===g.ELSE||t===g.ELIF||t===g.FI||t===g.THEN||t===g.DO||t===g.DONE||t===g.ESAC||t===g.IN||t===g.SELECT||t===g.TIME||t===g.COPROC||t===g.BANG}parseWord(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted)}parseWordNoBraceExpansion(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0)}parseWordForRegex(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0,!0)}parseWordFromString(t,s=!1,r=!1,n=!1,i=!1,a=!1,l=!1){let o=$t(this,t,s,r,n,i,!1,a,l);return I.word(o)}parseCommandSubstitution(t,s){return ji(t,s,()=>new e,r=>this.error(r))}parseBacktickSubstitution(t,s,r=!1){return Ui(t,s,r,()=>new e,n=>this.error(n))}isDollarDparenSubshell(t,s){return qi(t,s)}parseArithmeticExpansion(t,s){let r=s+3,n=1,i=0,a=r;for(;a<t.length-1&&n>0;)t[a]==="$"&&t[a+1]==="("?t[a+2]==="("?(n++,a+=3):(i++,a+=2):t[a]==="("&&t[a+1]==="("?(n++,a+=2):t[a]===")"&&t[a+1]===")"?i>0?(i--,a++):(n--,n>0&&(a+=2)):t[a]==="("?(i++,a++):(t[a]===")"&&i>0&&i--,a++);let l=t.slice(r,a),o=this.parseArithmeticExpression(l);return{part:I.arithmeticExpansion(o),endIndex:a+2}}parseArithmeticCommand(){let t=this.expect(g.DPAREN_START),s="",r=1,n=0,i=!1,a=!1;for(;r>0&&!this.check(g.EOF);){if(i){if(i=!1,n>0){n--,s+=")";continue}if(this.check(g.RPAREN)){r--,a=!0,this.advance();continue}if(this.check(g.DPAREN_END)){r--,a=!0;continue}s+=")";continue}if(this.check(g.DPAREN_START))r++,s+="((",this.advance();else if(this.check(g.DPAREN_END))n>=2?(n-=2,s+="))",this.advance()):n===1?(n--,s+=")",i=!0,this.advance()):(r--,a=!0,r>0&&(s+="))"),this.advance());else if(this.check(g.LPAREN))n++,s+="(",this.advance();else if(this.check(g.RPAREN))n>0&&n--,s+=")",this.advance();else{let u=this.current().value,c=s.length>0?s[s.length-1]:"";s.length>0&&!s.endsWith(" ")&&!(u==="="&&/[|&^+\-*/%<>]$/.test(s))&&!(u==="<"&&c==="<")&&!(u===">"&&c===">")&&(s+=" "),s+=u,this.advance()}}a||this.expect(g.DPAREN_END);let l=this.parseArithmeticExpression(s.trim()),o=this.parseOptionalRedirections();return I.arithmeticCommand(l,o,t.line)}parseConditionalCommand(){let t=this.expect(g.DBRACK_START),s=dr(this);this.expect(g.DBRACK_END);let r=this.parseOptionalRedirections();return I.conditionalCommand(s,r,t.line)}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 n=this.current();throw new Ee("Expected function name",n.line,n.column,n)}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 s=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return I.functionDef(t,s,r)}parseCompoundCommandBody(t){let s=t?.forFunctionBody;if(this.check(g.LBRACE))return ur(this,{skipRedirections:s});if(this.check(g.LPAREN))return cr(this,{skipRedirections:s});if(this.check(g.IF))return rr(this,{skipRedirections:s});if(this.check(g.FOR))return ir(this,{skipRedirections:s});if(this.check(g.WHILE))return ar(this,{skipRedirections:s});if(this.check(g.UNTIL))return or(this,{skipRedirections:s});if(this.check(g.CASE))return lr(this,{skipRedirections:s});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth(),s=[];for(this.skipNewlines();!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,n=this.parseStatement();if(n&&s.push(n),this.skipSeparators(),this.pos===r&&!n)break}return t(),s}parseOptionalRedirections(){let t=[];for(;zs(this);){this.checkIterationLimit();let s=this.pos;if(t.push(Bs(this)),this.pos===s)break}return t}parseArithmeticExpression(t){return Y(this,t)}};function Ce(e,t){return new q().parse(e,t)}var $u="BASH_ALIAS_";function ka(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function Na(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function _a(e,t){return e.env.get(`${$u}${t}`)}function mr(e,t,s){if(!t.name||!ka(t.name))return t;let r=Na(t.name);if(!r)return t;let n=_a(e,r);if(!n||s.has(r))return t;try{s.add(r);let i=new q,a=n,l=n.endsWith(" ");if(!l)for(let f of t.args){let d=Ca(f);a+=` ${d}`}let o;try{o=i.parse(a)}catch(f){if(f instanceof Ee)throw f;return t}if(o.statements.length!==1||o.statements[0].pipelines.length!==1||o.statements[0].pipelines[0].commands.length!==1)return xa(t,n);let u=o.statements[0].pipelines[0].commands[0];if(u.type!=="SimpleCommand")return xa(t,n);let c={...u,assignments:[...t.assignments,...u.assignments],redirections:[...u.redirections,...t.redirections],line:t.line};if(l&&t.args.length>0&&(c={...c,args:[...c.args,...t.args]},c.args.length>0)){let f=c.args[0];if(ka(f)){let d=Na(f);if(d&&_a(e,d)){let h={type:"SimpleCommand",name:f,args:c.args.slice(1),assignments:[],redirections:[]},m=mr(e,h,s);m!==h&&(c={...c,name:m.name,args:[...m.args]})}}}return c}catch(i){throw s.delete(r),i}}function xa(e,t){let s=t;for(let a of e.args){let l=Ca(a);s+=` ${l}`}let r=new q,n=r.parseWordFromString("eval",!1,!1),i=r.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:n,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function Ca(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${s.value}'`;break;case"DoubleQuoted":t+=`"${s.parts.map(r=>r.type==="Literal"?r.value:`$${r.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${s.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${s.expression}))`;break;case"Glob":t+=s.pattern;break;default:break}return t}var Pu=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 gr(e){return Pu.get(e)??""}function Da(e){let t=[],s="",r=0;for(;r<e.length;){let n=e[r];if(n==="["){for(s+=n,r++,r<e.length&&(e[r]==="!"||e[r]==="^")&&(s+=e[r],r++),r<e.length&&e[r]==="]"&&(s+=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){s+=e.slice(r,i+2),r=i+2;continue}}if(e[r]==="\\"&&r+1<e.length){s+=e[r]+e[r+1],r+=2;continue}s+=e[r],r++}r<e.length&&e[r]==="]"&&(s+=e[r],r++)}else n===":"?(s!==""&&t.push(s),s="",r++):n==="\\"&&r+1<e.length?(s+=n+e[r+1],r+=2):(s+=n,r++)}return s!==""&&t.push(s),t}function Ra(e){let t="^";for(let s=0;s<e.length;s++){let r=e[s];if(r==="*")t+="[^/]*";else if(r==="?")t+="[^/]";else if(r==="["){let n=s+1,i="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(i+="^",n++),n<e.length&&e[n]==="]"&&(i+="\\]",n++);let a=n;for(;a<e.length;){if(e[a]==="\\"&&a+1<e.length){a+=2;continue}if(e[a]==="["&&a+1<e.length&&e[a+1]===":"){let o=e.indexOf(":]",a+2);if(o!==-1){a=o+2;continue}}if(e[a]==="]")break;a++}let l=n;for(;n<e.length&&e[n]!=="]";){if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let o=e.indexOf(":]",n+2);if(o!==-1){let u=e.slice(n+2,o),c=gr(u);i+=c,n=o+2;continue}}if(e[n]==="\\"&&n+1<e.length){i+=`\\${e[n+1]}`,n+=2;continue}if(e[n]==="-"){let o=n===l,u=n+1===a;o||u?i+="\\-":i+="-"}else i+=e[n];n++}i+="]",t+=i,s=n}else if(r==="\\"&&s+1<e.length){let n=e[s+1];/[.+^${}()|\\*?[\]]/.test(n)?t+=`\\${n}`:t+=n,s++}else/[.+^${}()|]/.test(r)?t+=`\\${r}`:t+=r}return t+="$",le(t)}function yr(e,t){let s=1,r=t+1;for(;r<e.length&&s>0;){let n=e[r];if(n==="\\"){r+=2;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function wr(e){let t=[],s="",r=0,n=!1,i=0;for(;i<e.length;){let a=e[i];if(a==="'"&&!n){n=!0,s+="\0QUOTE_START\0",i++;continue}if(a==="'"&&n){n=!1,s+="\0QUOTE_END\0",i++;continue}if(n){s+=a,i++;continue}if(a==="\\"){s+=a,i+1<e.length?(s+=e[i+1],i+=2):i++;continue}a==="("?(r++,s+=a):a===")"?(r--,s+=a):a==="|"&&r===0?(t.push(s),s=""):s+=a,i++}return t.push(s),t}var Ia=5,Pt=class{fs;cwd;globignorePatterns=[];hasGlobignore=!1;globstar=!1;nullglob=!1;failglob=!1;dotglob=!1;extglob=!1;globskipdots=!0;ops={count:0};maxOps;constructor(t,s,r,n){this.fs=t,this.cwd=s,typeof n=="boolean"?(this.globstar=n,this.maxOps=1e5):n?(this.globstar=n.globstar??!1,this.nullglob=n.nullglob??!1,this.failglob=n.failglob??!1,this.dotglob=n.dotglob??!1,this.extglob=n.extglob??!1,this.globskipdots=n.globskipdots??!0,this.maxOps=n.maxGlobOperations??1e5):this.maxOps=1e5;let i=r?.get("GLOBIGNORE");i!==void 0&&i!==""&&(this.hasGlobignore=!0,this.globignorePatterns=Da(i))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new X(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations")}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(s=>{let r=s.split("/").pop()||s;if((this.hasGlobignore||this.globskipdots)&&(r==="."||r===".."))return!1;if(this.hasGlobignore){for(let n of this.globignorePatterns)if(this.matchGlobignorePattern(s,n))return!1}return!0})}matchGlobignorePattern(t,s){return Ra(s).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,s){let r=t.map((a,l)=>(s?.[l]??!1)||!this.isGlobPattern(a)?null:this.expand(a)),n=await Promise.all(r.map(a=>a||Promise.resolve(null))),i=[];for(let a=0;a<t.length;a++){let l=n[a];l===null?i.push(t[a]):l.length>0?i.push(...l):i.push(t[a])}return i}async expand(t){if(this.globstar){let r=t.split("/"),n=0;for(let i of r)if(i==="**"&&(n++,n>Ia))throw new X(`Glob pattern has too many ** segments (max ${Ia})`,"glob_operations")}let s;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))s=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");s=await this.expandSimple(r)}return this.filterGlobignore(s)}isGlobstarValid(t){let s=t.split("/");for(let r of s)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 s=t.startsWith("/"),r=t.split("/").filter(u=>u!==""),n=-1;for(let u=0;u<r.length;u++)if(this.hasGlobChars(r[u])){n=u;break}if(n===-1)return[t];let i,a;if(n===0)s?(i="/",a="/"):(i=this.cwd,a="");else{let u=r.slice(0,n);s?(i=`/${u.join("/")}`,a=`/${u.join("/")}`):(i=this.fs.resolvePath(this.cwd,u.join("/")),a=u.join("/"))}let l=r.slice(n);return(await this.expandSegments(i,a,l)).sort()}async expandSegments(t,s,r){if(this.checkOpsLimit(),r.length===0)return[s];let[n,...i]=r,a=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let l=await this.fs.readdirWithFileTypes(t),o=[],u=[...l],c=this.dotglob||this.hasGlobignore;if(n.startsWith(".")||this.dotglob){let d=l.some(m=>m.name==="."),h=l.some(m=>m.name==="..");d||u.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),h||u.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of u)if(!(d.name.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(d.name,n)){let h=t==="/"?`/${d.name}`:`${t}/${d.name}`,m;s===""?m=d.name:s==="/"?m=`/${d.name}`:m=`${s}/${d.name}`,i.length===0?o.push(Promise.resolve([m])):d.isDirectory&&o.push(this.expandSegments(h,m,i))}let f=await Promise.all(o);for(let d of f)a.push(...d)}else{this.checkOpsLimit();let l=await this.fs.readdir(t),o=[],u=[...l],c=this.dotglob||this.hasGlobignore;(n.startsWith(".")||this.dotglob)&&(l.includes(".")||u.push("."),l.includes("..")||u.push(".."));for(let d of u)if(!(d.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(d,n)){let h=t==="/"?`/${d}`:`${t}/${d}`,m;s===""?m=d:s==="/"?m=`/${d}`:m=`${s}/${d}`,i.length===0?o.push(Promise.resolve([m])):o.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(h)).isDirectory)return this.expandSegments(h,m,i)}catch(p){if(p instanceof X)throw p}return[]})())}let f=await Promise.all(o);for(let d of f)a.push(...d)}}catch(l){if(l instanceof X)throw l}return a}async expandRecursive(t){let s=[],r=t.indexOf("**"),n=t.slice(0,r).replace(/\/$/,"")||".",a=t.slice(r+2).replace(/^\//,"");return a.includes("**")&&this.isGlobstarValid(a)?(await this.walkDirectoryMultiGlobstar(n,a,s),[...new Set(s)].sort()):(await this.walkDirectory(n,a,s),s.sort())}async walkDirectoryMultiGlobstar(t,s,r){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let i=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(n):null;if(i){let a=[];for(let u of i){let c=t==="."?u.name:`${t}/${u.name}`;u.isDirectory&&a.push(c)}let l=t==="."?s:`${t}/${s}`,o=await this.expandRecursive(l);r.push(...o);for(let u=0;u<a.length;u+=100){let c=a.slice(u,u+100);await Promise.all(c.map(f=>this.walkDirectoryMultiGlobstar(f,s,r)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(n),l=[];for(let c of a){let f=t==="."?c:`${t}/${c}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&l.push(f)}catch(h){if(h instanceof X)throw h}}let o=t==="."?s:`${t}/${s}`,u=await this.expandRecursive(o);r.push(...u);for(let c=0;c<l.length;c+=100){let f=l.slice(c,c+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,s,r)))}}}catch(i){if(i instanceof X)throw i}}async walkDirectory(t,s,r){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let i=await this.fs.readdirWithFileTypes(n),a=[],l=[];for(let o of i){let u=t==="."?o.name:`${t}/${o.name}`;o.isDirectory?l.push(u):s&&this.matchPattern(o.name,s)&&a.push(u)}r.push(...a);for(let o=0;o<l.length;o+=100){let u=l.slice(o,o+100);await Promise.all(u.map(c=>this.walkDirectory(c,s,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(n),a=[];for(let o=0;o<i.length;o+=100){let u=i.slice(o,o+100),c=await Promise.all(u.map(async f=>{let d=t==="."?f:`${t}/${f}`,h=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let m=await this.fs.stat(h);return{name:f,path:d,isDirectory:m.isDirectory}}catch(m){if(m instanceof X)throw m;return null}}));a.push(...c.filter(f=>f!==null))}for(let o of a)!o.isDirectory&&s&&this.matchPattern(o.name,s)&&r.push(o.path);let l=a.filter(o=>o.isDirectory);for(let o=0;o<l.length;o+=100){let u=l.slice(o,o+100);await Promise.all(u.map(c=>this.walkDirectory(c.path,s,r)))}}}catch(i){if(i instanceof X)throw i}}matchPattern(t,s){return this.patternToRegex(s).test(t)}patternToRegex(t){let s=this.patternToRegexStr(t);return le(`^${s}$`)}patternToRegexStr(t){let s="",r=!1;for(let n=0;n<t.length;n++){if(t.slice(n,n+13)==="\0QUOTE_START\0"){r=!0,n+=12;continue}if(t.slice(n,n+11)==="\0QUOTE_END\0"){r=!1,n+=10;continue}let i=t[n];if(r){/[.+^${}()|\\*?[\]]/.test(i)?s+=`\\${i}`:s+=i;continue}if(this.extglob&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&n+1<t.length&&t[n+1]==="("){let a=yr(t,n+1);if(a!==-1){let l=t.slice(n+2,a),o=wr(l),u=o.map(f=>this.patternToRegexStr(f)),c=u.length>0?u.join("|"):"(?:)";if(i==="@")s+=`(?:${c})`;else if(i==="*")s+=`(?:${c})*`;else if(i==="+")s+=`(?:${c})+`;else if(i==="?")s+=`(?:${c})?`;else if(i==="!")if(a<t.length-1){let d=o.map(m=>this.computePatternLength(m));if(d.every(m=>m!==null)&&d.every(m=>m===d[0])&&d[0]!==null){let m=d[0];if(m===0)s+="(?:.+)";else{let p=[];m>0&&p.push(`.{0,${m-1}}`),p.push(`.{${m+1},}`),p.push(`(?!(?:${c})).{${m}}`),s+=`(?:${p.join("|")})`}}else s+=`(?:(?!(?:${c})).)*?`}else s+=`(?!(?:${c})$).*`;n=a;continue}}if(i==="*")s+=".*";else if(i==="?")s+=".";else if(i==="["){let a=n+1,l="[";a<t.length&&(t[a]==="^"||t[a]==="!")&&(l+="^",a++),a<t.length&&t[a]==="]"&&(l+="\\]",a++);let o=a;for(;o<t.length;){if(t[o]==="\\"&&o+1<t.length){o+=2;continue}if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let c=t.indexOf(":]",o+2);if(c!==-1){o=c+2;continue}}if(t[o]==="]")break;o++}let u=a;for(;a<t.length&&t[a]!=="]";){if(t[a]==="["&&a+1<t.length&&t[a+1]===":"){let c=t.indexOf(":]",a+2);if(c!==-1){let f=t.slice(a+2,c),d=gr(f);l+=d,a=c+2;continue}}if(t[a]==="\\"&&a+1<t.length){l+=`\\${t[a+1]}`,a+=2;continue}if(t[a]==="-"){let c=a===u,f=a+1===o;c||f?l+="\\-":l+="-"}else l+=t[a];a++}l+="]",s+=l,n=a}else if(i==="\\"&&n+1<t.length){let a=t[n+1];/[.+^${}()|\\*?[\]]/.test(a)?s+=`\\${a}`:s+=a,n++}else/[.+^${}()|]/.test(i)?s+=`\\${i}`:s+=i}return s}computePatternLength(t){let s=0,r=0,n=!1;for(;r<t.length;){if(t.slice(r,r+13)==="\0QUOTE_START\0"){n=!0,r+=13;continue}if(t.slice(r,r+11)==="\0QUOTE_END\0"){n=!1,r+=11;continue}let i=t[r];if(n){s+=1,r++;continue}if((i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&r+1<t.length&&t[r+1]==="("){let a=yr(t,r+1);if(a!==-1){if(i==="@"){let l=t.slice(r+2,a),u=wr(l).map(c=>this.computePatternLength(c));if(u.every(c=>c!==null)&&u.every(c=>c===u[0])){s+=u[0],r=a+1;continue}return null}return null}}if(i==="*")return null;if(i==="?"){s+=1,r++;continue}if(i==="["){let a=t.indexOf("]",r+1);if(a!==-1){s+=1,r=a+1;continue}s+=1,r++;continue}if(i==="\\"){s+=1,r+=2;continue}s+=1,r++}return s}};function Er(e){for(let t=0;t<e.length;t++){if(e[t]==="\\"){t++;continue}if(e[t]==="$"){let s=e[t+1];if(s==="{"||s&&/[a-zA-Z_]/.test(s))return!0}}return!1}function ku(e){if(!e.operation)return!1;let t=e.operation,s;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(s=t.word?.parts),!s)return!1;for(let r of s)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function Oa(e){if(!e.operation)return!1;let t=e.operation,s;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(s=t.word?.parts),!s||s.length===0)return!1;for(let r of s)if(r.type!=="DoubleQuoted"&&r.type!=="SingleQuoted")return!1;return!0}function hs(e){let t=!1,s=!1,r=!1,n=!1,i=!1,a=!1,l=!1;for(let o of e){if((o.type==="SingleQuoted"||o.type==="DoubleQuoted")&&(t=!0,o.type==="DoubleQuoted"))for(let u of o.parts)u.type==="ParameterExpansion"&&(u.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!u.operation||u.operation.type==="PatternRemoval"||u.operation.type==="PatternReplacement")&&(n=!0),(u.operation?.type==="VarNamePrefix"||u.operation?.type==="ArrayKeys")&&(a=!0),u.operation?.type==="Indirection"&&(l=!0));o.type==="CommandSubstitution"&&(s=!0),o.type==="ParameterExpansion"&&(i=!0,(o.parameter==="@"||o.parameter==="*")&&(r=!0),ku(o)&&(t=!0),(o.operation?.type==="VarNamePrefix"||o.operation?.type==="ArrayKeys")&&(a=!0),o.operation?.type==="Indirection"&&(l=!0)),o.type==="Glob"&&Er(o.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:s,hasArrayVar:r,hasArrayAtExpansion:n,hasParamExpansion:i,hasVarNamePrefixExpansion:a,hasIndirection:l}}function he(e,t){let s=`${t}_`,r=[];for(let n of e.state.env.keys())if(n.startsWith(s)){let i=n.slice(s.length),a=Number.parseInt(i,10);!Number.isNaN(a)&&String(a)===i&&r.push(a)}return r.sort((n,i)=>n-i)}function tt(e,t){let s=`${t}_`;for(let r of e.state.env.keys())r.startsWith(s)&&e.state.env.delete(r)}function Ge(e,t){let s=`${t}_`,r=`${t}__length`,n=[];for(let i of e.state.env.keys())if(i!==r&&i.startsWith(s)){let a=i.slice(s.length);if(a.startsWith("_length"))continue;n.push(a)}return n.sort()}function qs(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function br(e){if(e.parts.length<2)return null;let t=e.parts[0],s=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let r,n=s,i=1;if(s.type==="Literal"&&s.value.startsWith("]")){let f=s.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),n=d,i=2}else return null}else if(t.pattern==="["&&(s.type==="DoubleQuoted"||s.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(s.type==="SingleQuoted")r=s.value;else{r="";for(let d of s.parts)(d.type==="Literal"||d.type==="Escaped")&&(r+=d.value)}n=f,i=2}else if(t.pattern.endsWith("]")){if(s.type!=="Literal"||!s.value.startsWith("=")&&!s.value.startsWith("+="))return null;r=t.pattern.slice(1,-1)}else return null;r=qs(r);let a;if(n.type!=="Literal")return null;n.value.startsWith("]=")||n.value.startsWith("]+=")?a=n.value.slice(1):a=n.value;let l=a.startsWith("+=");if(!l&&!a.startsWith("="))return null;let o=[],u=l?2:1,c=a.slice(u);c&&o.push({type:"Literal",value:c});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?o.push({type:"Literal",value:Nu(d)}):o.push(d)}return{key:r,valueParts:o,append:l}}function Nu(e){return`{${e.items.map(s=>{if(s.type==="Range"){let r=s.startStr??String(s.start),n=s.endStr??String(s.end),i=`${r}..${n}`;return s.step&&(i+=`..${s.step}`),i}return Ut(s.word)}).join(",")}}`}function Ut(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value;break;case"Glob":t+=s.pattern;break;case"SingleQuoted":t+=s.value;break;case"DoubleQuoted":for(let r of s.parts)(r.type==="Literal"||r.type==="Escaped")&&(t+=r.value);break;case"Escaped":t+=s.value;break;case"BraceExpansion":t+="{",t+=s.items.map(r=>r.type==="Range"?`${r.startStr}..${r.endStr}${r.step?`..${r.step}`:""}`:Ut(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",s.user&&(t+=s.user);break}return t}function me(e){return e.get("IFS")??`
62
- `}function ve(e){return e.get("IFS")===""}function js(e){let t=me(e);if(t==="")return!0;for(let s of t)if(s!==" "&&s!==" "&&s!==`
63
- `)return!1;return!0}function Ta(e){let t=!1,s=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?s.push(`\\${r}`):r===" "?s.push("\\t"):r===`
64
- `?s.push("\\n"):s.push(r);return t&&s.push("\\-"),s.join("")}function j(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var _u=`
65
- `;function xu(e){return _u.includes(e)}function vr(e){let t=new Set,s=new Set;for(let r of e)xu(r)?t.add(r):s.add(r);return{whitespace:t,nonWhitespace:s}}function Sr(e,t,s,r){if(t==="")return e===""?{words:[],wordStarts:[]}:{words:[e],wordStarts:[0]};let{whitespace:n,nonWhitespace:i}=vr(t),a=[],l=[],o=0;for(;o<e.length&&n.has(e[o]);)o++;if(o>=e.length)return{words:[],wordStarts:[]};if(i.has(e[o]))for(a.push(""),l.push(o),o++;o<e.length&&n.has(e[o]);)o++;for(;o<e.length&&!(s!==void 0&&a.length>=s);){let u=o;for(l.push(u);o<e.length;){let c=e[o];if(!r&&c==="\\"){o++,o<e.length&&o++;continue}if(n.has(c)||i.has(c))break;o++}if(a.push(e.substring(u,o)),o>=e.length)break;for(;o<e.length&&n.has(e[o]);)o++;if(o<e.length&&i.has(e[o])){for(o++;o<e.length&&n.has(e[o]);)o++;for(;o<e.length&&i.has(e[o])&&!(s!==void 0&&a.length>=s);)for(a.push(""),l.push(o),o++;o<e.length&&n.has(e[o]);)o++}}return{words:a,wordStarts:l}}function Us(e,t){if(t==="")return{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:s,nonWhitespace:r}=vr(t),n=[],i=0,a=!1,l=!1,o=i;for(;i<e.length&&s.has(e[i]);)i++;if(i>o&&(a=!0),i>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(r.has(e[i]))for(n.push(""),i++;i<e.length&&s.has(e[i]);)i++;for(;i<e.length;){let u=i;for(;i<e.length;){let f=e[i];if(s.has(f)||r.has(f))break;i++}if(n.push(e.substring(u,i)),i>=e.length){l=!1;break}let c=i;for(;i<e.length&&s.has(e[i]);)i++;if(i<e.length&&r.has(e[i])){for(i++;i<e.length&&s.has(e[i]);)i++;for(;i<e.length&&r.has(e[i]);)for(n.push(""),i++;i<e.length&&s.has(e[i]);)i++}i>=e.length&&i>c&&(l=!0)}return{words:n,hadLeadingDelimiter:a,hadTrailingDelimiter:l}}function re(e,t){return Us(e,t).words}function Cu(e,t){for(let s of e)if(t.has(s))return!0;return!1}function La(e,t,s){if(t==="")return e;let{whitespace:r,nonWhitespace:n}=vr(t),i=e.length;for(;i>0&&r.has(e[i-1]);){if(!s&&i>=2){let l=0,o=i-2;for(;o>=0&&e[o]==="\\";)l++,o--;if(l%2===1)break}i--}let a=e.substring(0,i);if(a.length>=1&&n.has(a[a.length-1])){if(!s&&a.length>=2){let o=0,u=a.length-2;for(;u>=0&&a[u]==="\\";)o++,u--;if(o%2===1)return a}let l=a.substring(0,a.length-1);if(!Cu(l,n))return l}return a}function te(e,t){return e.state.namerefs?.has(t)??!1}function pt(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function Ma(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Wa(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function Fa(e,t){return e.state.invalidNamerefs?.has(t)??!1}function Ar(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function Zs(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],i=Array.from(e.state.env.keys()).some(l=>l.startsWith(`${n}_`)&&!l.includes("__")),a=e.state.associativeArrays?.has(n)??!1;return i||a}return Array.from(e.state.env.keys()).some(n=>n.startsWith(`${t}_`)&&!n.includes("__"))?!0:e.state.env.has(t)}function $e(e,t,s=100){if(!te(e,t)||Fa(e,t))return t;let r=new Set,n=t;for(;s-- >0;){if(r.has(n))return;if(r.add(n),!te(e,n))return n;let i=e.state.env.get(n);if(i===void 0||i===""||!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(i))return n;n=i}}function Tt(e,t){if(te(e,t))return e.state.env.get(t)}function Va(e,t,s,r=100){if(!te(e,t)||Fa(e,t))return t;let n=new Set,i=t;for(;r-- >0;){if(n.has(i))return;if(n.add(i),!te(e,i))return i;let a=e.state.env.get(i);if(a===void 0||a==="")return s!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&Zs(e,s)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(a))return i;i=a}}function Du(e,t){let s=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(r,n)=>e.state.env.get(n)??"");return s=s.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(r,n)=>e.state.env.get(n)??""),s}function B(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((i,a)=>[a,i]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((i,a)=>[a,String(i)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((i,a)=>[a,i]):e.state.associativeArrays?.has(t)?Ge(e,t).map(i=>[i,e.state.env.get(`${t}_${i}`)??""]):he(e,t).map(n=>[n,e.state.env.get(`${t}_${n}`)??""])}function He(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)?Ge(e,t).length>0:he(e,t).length>0}async function J(e,t,s=!0,r=!1){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 a="";return a+="h",e.state.options.errexit&&(a+="e"),e.state.options.noglob&&(a+="f"),e.state.options.nounset&&(a+="u"),e.state.options.verbose&&(a+="v"),e.state.options.xtrace&&(a+="x"),a+="B",e.state.options.noclobber&&(a+="C"),a+="s",a}case"*":{let a=Number.parseInt(e.state.env.get("#")||"0",10);if(a===0)return"";let l=[];for(let o=1;o<=a;o++)l.push(e.state.env.get(String(o))||"");return l.join(j(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 Vi;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let a=e.state.funcNameStack?.[0];if(a!==void 0)return a;if(s&&e.state.options.nounset)throw new Le("FUNCNAME");return""}case"BASH_LINENO":{let a=e.state.callLineStack?.[0];if(a!==void 0)return String(a);if(s&&e.state.options.nounset)throw new Le("BASH_LINENO");return""}case"BASH_SOURCE":{let a=e.state.sourceStack?.[0];if(a!==void 0)return a;if(s&&e.state.options.nounset)throw new Le("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new Me(`\${${t}}`);let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let a=n[1],l=n[2];if(te(e,a)){let f=$e(e,a);if(f&&f!==a){if(f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";a=f}}if(l==="@"||l==="*"){let f=B(e,a);if(f.length>0)return f.map(([,h])=>h).join(" ");let d=e.state.env.get(a);return d!==void 0?d:""}if(a==="FUNCNAME"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.funcNameStack?.[f]??"":""}if(a==="BASH_LINENO"){let f=Number.parseInt(l,10);if(!Number.isNaN(f)&&f>=0){let d=e.state.callLineStack?.[f];return d!==void 0?String(d):""}return""}if(a==="BASH_SOURCE"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.sourceStack?.[f]??"":""}if(e.state.associativeArrays?.has(a)){let f=qs(l);f=Du(e,f);let d=e.state.env.get(`${a}_${f}`);if(d===void 0&&s&&e.state.options.nounset)throw new Le(`${a}[${l}]`);return d||""}let u;if(/^-?\d+$/.test(l))u=Number.parseInt(l,10);else try{let f=new q,d=Y(f,l);u=await T(e,d.expression)}catch{let f=e.state.env.get(l);u=f?Number.parseInt(f,10):0,Number.isNaN(u)&&(u=0)}if(u<0){let f=B(e,a),d=e.state.currentLine;if(f.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${a}: bad array subscript
66
- `,"";let m=Math.max(...f.map(([y])=>typeof y=="number"?y:0))+1+u;return m<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${a}: bad array subscript
67
- `,""):e.state.env.get(`${a}_${m}`)||""}let c=e.state.env.get(`${a}_${u}`);if(c!==void 0)return c;if(u===0){let f=e.state.env.get(a);if(f!==void 0)return f}if(s&&e.state.options.nounset)throw new Le(`${a}[${u}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let a=e.state.env.get(t);if(a===void 0&&s&&e.state.options.nounset)throw new Le(t);return a||""}if(te(e,t)){let a=$e(e,t);if(a===void 0)return"";if(a!==t)return await J(e,a,s,r);let l=e.state.env.get(t);if((l===void 0||l==="")&&s&&e.state.options.nounset)throw new Le(t);return l||""}let i=e.state.env.get(t);if(i!==void 0)return e.state.tempEnvBindings?.some(a=>a.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),i;if(He(e,t)){let a=e.state.env.get(`${t}_0`);return a!==void 0?a:""}if(s&&e.state.options.nounset)throw new Le(t);return""}async function st(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 n=r[1],i=r[2];if(te(e,n)){let o=$e(e,n);if(o&&o!==n){if(o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;n=o}}if(i==="@"||i==="*")return B(e,n).length>0?!0:e.state.env.has(n);if(e.state.associativeArrays?.has(n)){let o=qs(i);return e.state.env.has(`${n}_${o}`)}let l;if(/^-?\d+$/.test(i))l=Number.parseInt(i,10);else try{let o=new q,u=Y(o,i);l=await T(e,u.expression)}catch{let o=e.state.env.get(i);l=o?Number.parseInt(o,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let o=B(e,n);if(o.length===0)return!1;let c=Math.max(...o.map(([f])=>typeof f=="number"?f:0))+1+l;return c<0?!1:e.state.env.has(`${n}_${c}`)}return e.state.env.has(`${n}_${l}`)}if(te(e,t)){let n=$e(e,t);return n===void 0||n===t?e.state.env.has(t):st(e,n)}return!!(e.state.env.has(t)||He(e,t))}async function za(e,t){let s="",r=0;for(;r<t.length;){if(t[r]==="$"){if(t[r+1]==="{"){let n=1,i=r+2;for(;i<t.length&&n>0;)t[i]==="{"?n++:t[i]==="}"&&n--,i++;s+=t.slice(r,i),r=i;continue}if(t[r+1]==="("){let n=1,i=r+2;for(;i<t.length&&n>0;)t[i]==="("?n++:t[i]===")"&&n--,i++;s+=t.slice(r,i),r=i;continue}if(/[a-zA-Z_]/.test(t[r+1]||"")){let n=r+1;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)n++;let i=t.slice(r+1,n),a=await J(e,i);s+=a,r=n;continue}if(/[0-9]/.test(t[r+1]||"")){let n=r+1;for(;n<t.length&&/[0-9]/.test(t[n]);)n++;let i=t.slice(r+1,n),a=await J(e,i);s+=a,r=n;continue}if(/[*@#?\-!$]/.test(t[r+1]||"")){let n=t[r+1],i=await J(e,n);s+=i,r+=2;continue}}if(t[r]==='"'){for(s+='"',r++;r<t.length&&t[r]!=='"';)if(t[r]==="$"&&/[a-zA-Z_]/.test(t[r+1]||"")){let n=r+1;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)n++;let i=t.slice(r+1,n),a=await J(e,i);s+=a,r=n}else t[r]==="\\"?(s+=t[r],r++,r<t.length&&(s+=t[r],r++)):(s+=t[r],r++);r<t.length&&(s+='"',r++);continue}s+=t[r],r++}return s}async function $r(e,t){let s=t,r=t.startsWith('"')&&t.endsWith('"'),n=t.startsWith("'")&&t.endsWith("'");if((r||n)&&(s=t.slice(1,-1)),n)return s;let i="",a=0;for(;a<s.length;)if(s[a]==="$")if(s[a+1]==="("){let l=1,o=a+2;for(;o<s.length&&l>0;)s[o]==="("&&s[o-1]==="$"||s[o]==="("?l++:s[o]===")"&&l--,o++;let u=s.slice(a+2,o-1);if(e.execFn){let c=await e.execFn(u,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}a=o}else if(s[a+1]==="{"){let l=1,o=a+2;for(;o<s.length&&l>0;)s[o]==="{"?l++:s[o]==="}"&&l--,o++;let u=s.slice(a+2,o-1),c=await J(e,u);i+=c,a=o}else if(/[a-zA-Z_]/.test(s[a+1]||"")){let l=a+1;for(;l<s.length&&/[a-zA-Z0-9_]/.test(s[l]);)l++;let o=s.slice(a+1,l),u=await J(e,o);i+=u,a=l}else i+=s[a],a++;else if(s[a]==="`"){let l=a+1;for(;l<s.length&&s[l]!=="`";)l++;let o=s.slice(a+1,l);if(e.execFn){let u=await e.execFn(o,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}a=l+1}else i+=s[a],a++;return i}var Gs=1e4;function Ru(e,t,s,r,n){let i=s??1;i===0&&(i=1);let a=Math.abs(i),l=[],o=0;r?.match(/^-?0\d/)&&(o=Math.max(o,r.replace(/^-/,"").length)),n?.match(/^-?0\d/)&&(o=Math.max(o,n.replace(/^-/,"").length));let u=c=>{if(o>0){let f=c<0,d=String(Math.abs(c)).padStart(o,"0");return f?`-${d}`:d}return String(c)};if(e<=t)for(let c=e,f=0;c<=t&&f<Gs;c+=a,f++)l.push(u(c));else for(let c=e,f=0;c>=t&&f<Gs;c-=a,f++)l.push(u(c));return l}function Iu(e,t,s){let r=s??1;r===0&&(r=1);let n=e.charCodeAt(0),i=t.charCodeAt(0),a=Math.abs(r),l=e>="A"&&e<="Z",o=e>="a"&&e<="z",u=t>="A"&&t<="Z",c=t>="a"&&t<="z";if(l&&c||o&&u){let d=s!==void 0?`..${s}`:"";throw new Ds(`{${e}..${t}${d}}: invalid sequence`)}let f=[];if(n<=i)for(let d=n,h=0;d<=i&&h<Gs;d+=a,h++)f.push(String.fromCharCode(d));else for(let d=n,h=0;d>=i&&h<Gs;d-=a,h++)f.push(String.fromCharCode(d));return f}function Pr(e,t,s,r,n){let i=s!==void 0?`..${s}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:Ru(e,t,s,r,n),literal:`{${e}..${t}${i}}`}:typeof e=="string"&&typeof t=="string"?{expanded:Iu(e,t,s),literal:`{${e}..${t}${i}}`}:{expanded:null,literal:`{${e}..${t}${i}}`}}function Ba(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 s=t.pipelines[0];if(s.negated||s.commands.length!==1)return null;let r=s.commands[0];if(r.type!=="SimpleCommand")return null;let n=r;if(n.name!==null||n.args.length!==0||n.assignments.length!==0||n.redirections.length!==1)return null;let i=n.redirections[0];return i.operator!=="<"||i.target.type!=="Word"?null:{target:i.target}}function nt(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function kr(e){let t="",s=0;for(;s<e.length;)e[s]==="\\"&&s+1<e.length?(t+=e[s+1],s+=2):(t+=e[s],s++);return t}function Fe(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function ps(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function Q(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function G(e,t,s=!1){let r="",n=0;for(;n<e.length;){let i=e[n];if(s&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&n+1<e.length&&e[n+1]==="("){let a=Ou(e,n+1);if(a!==-1){let l=e.slice(n+2,a),u=Tu(l).map(f=>G(f,t,s)),c=u.length>0?u.join("|"):"(?:)";i==="@"?r+=`(?:${c})`:i==="*"?r+=`(?:${c})*`:i==="+"?r+=`(?:${c})+`:i==="?"?r+=`(?:${c})?`:i==="!"&&(r+=`(?!(?:${c})$).*`),n=a+1;continue}}if(i==="\\")if(n+1<e.length){let a=e[n+1];/[\\^$.|+(){}[\]*?]/.test(a)?r+=`\\${a}`:r+=a,n+=2}else r+="\\\\",n++;else if(i==="*")r+=t?".*":".*?",n++;else if(i==="?")r+=".",n++;else if(i==="["){let a=Lu(e,n);if(a===-1)r+="\\[",n++;else{let l=e.slice(n+1,a);r+=Mu(l),n=a+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,n++):(r+=i,n++)}return r}function Ou(e,t){let s=1,r=t+1;for(;r<e.length&&s>0;){let n=e[r];if(n==="\\"){r+=2;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function Tu(e){let t=[],s="",r=0,n=0;for(;n<e.length;){let i=e[n];if(i==="\\"){s+=i,n+1<e.length?(s+=e[n+1],n+=2):n++;continue}i==="("?(r++,s+=i):i===")"?(r--,s+=i):i==="|"&&r===0?(t.push(s),s=""):s+=i,n++}return t.push(s),t}function Lu(e,t){let s=t+1;for(s<e.length&&e[s]==="^"&&s++,s<e.length&&e[s]==="]"&&s++;s<e.length;){if(e[s]==="\\"&&s+1<e.length){s+=2;continue}if(e[s]==="]")return s;if(e[s]==="'"){let r=e.indexOf("'",s+1);if(r!==-1){s=r+1;continue}}if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let r=e.indexOf(":]",s+2);if(r!==-1){s=r+2;continue}}s++}return-1}function Mu(e){let t="[",s=0;for((e[0]==="^"||e[0]==="!")&&(t+="^",s++);s<e.length;){if(e[s]==="'"){let n=e.indexOf("'",s+1);if(n!==-1){let i=e.slice(s+1,n);for(let a of i)a==="\\"?t+="\\\\":a==="]"?t+="\\]":a==="^"&&t==="["?t+="\\^":t+=a;s=n+1;continue}}if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let n=e.indexOf(":]",s+2);if(n!==-1){let i=e.slice(s+2,n);t+=Fu(i),s=n+2;continue}}let r=e[s];r==="\\"?s+1<e.length?(t+=`\\${e[s+1]}`,s+=2):(t+="\\\\",s++):r==="-"&&s>0&&s<e.length-1?(t+="-",s++):r==="^"&&s===0?(t+="^",s++):(r==="]"&&s===0?t+="\\]":t+=r,s++)}return t+="]",t}var Wu=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 Fu(e){return Wu.get(e)??""}function mt(e,t,s,r){if(s==="prefix")return le(`^${t}`,"s").replace(e,"");let n=le(`${t}$`,"s");if(r)return n.replace(e,"");for(let i=e.length;i>=0;i--){let a=e.slice(i);if(n.test(a))return e.slice(0,i)}return e}function Zt(e,t){let s=Array.from(e.state.env.keys()),r=new Set,n=e.state.associativeArrays??new Set,i=new Set;for(let l of s){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o&&i.add(o[1]);let u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);u&&i.add(u[1])}let a=l=>{for(let o of n){let u=`${o}_`;if(l.startsWith(u)&&l!==o)return!0}return!1};for(let l of s)if(l.startsWith(t))if(l.includes("__")){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);o?.[1].startsWith(t)&&r.add(o[1])}else if(/_\d+$/.test(l)){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o?.[1].startsWith(t)&&r.add(o[1])}else a(l)||r.add(l);return[...r].sort()}function Vu(e,t){let s=(i,a=2)=>String(i).padStart(a,"0");if(e===""){let i=s(t.getHours()),a=s(t.getMinutes()),l=s(t.getSeconds());return`${i}:${a}:${l}`}let r="",n=0;for(;n<e.length;)if(e[n]==="%"){if(n+1>=e.length){r+="%",n++;continue}let i=e[n+1];switch(i){case"H":r+=s(t.getHours());break;case"M":r+=s(t.getMinutes());break;case"S":r+=s(t.getSeconds());break;case"d":r+=s(t.getDate());break;case"m":r+=s(t.getMonth()+1);break;case"Y":r+=t.getFullYear();break;case"y":r+=s(t.getFullYear()%100);break;case"I":{let a=t.getHours()%12;a===0&&(a=12),r+=s(a);break}case"p":r+=t.getHours()<12?"AM":"PM";break;case"P":r+=t.getHours()<12?"am":"pm";break;case"%":r+="%";break;case"a":{r+=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][t.getDay()];break}case"b":{r+=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()];break}default:r+=`%${i}`}n+=2}else r+=e[n],n++;return r}function ms(e,t){let s="",r=0,n=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",i=e.state.env.get("HOSTNAME")||"localhost",a=i.split(".")[0],l=e.state.env.get("PWD")||"/",o=e.state.env.get("HOME")||"/",u=l.startsWith(o)?`~${l.slice(o.length)}`:l,c=l.split("/").pop()||l,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],m=e.state.env.get("__COMMAND_NUMBER")||"1";for(;r<t.length;){let p=t[r];if(p==="\\"){if(r+1>=t.length){s+="\\",r++;continue}let y=t[r+1];if(y>="0"&&y<="7"){let b="",v=r+1;for(;v<t.length&&v<r+4&&t[v]>="0"&&t[v]<="7";)b+=t[v],v++;let E=Number.parseInt(b,8)%256;s+=String.fromCharCode(E),r=v;continue}switch(y){case"\\":s+="\\",r+=2;break;case"a":s+="\x07",r+=2;break;case"e":s+="\x1B",r+=2;break;case"n":s+=`
68
- `,r+=2;break;case"r":s+="\r",r+=2;break;case"$":s+="$",r+=2;break;case"[":case"]":r+=2;break;case"u":s+=n,r+=2;break;case"h":s+=a,r+=2;break;case"H":s+=i,r+=2;break;case"w":s+=u,r+=2;break;case"W":s+=c,r+=2;break;case"d":{let b=String(f.getDate()).padStart(2," ");s+=`${d[f.getDay()]} ${h[f.getMonth()]} ${b}`,r+=2;break}case"t":{let b=String(f.getHours()).padStart(2,"0"),v=String(f.getMinutes()).padStart(2,"0"),E=String(f.getSeconds()).padStart(2,"0");s+=`${b}:${v}:${E}`,r+=2;break}case"T":{let b=f.getHours()%12;b===0&&(b=12);let v=String(b).padStart(2,"0"),E=String(f.getMinutes()).padStart(2,"0"),w=String(f.getSeconds()).padStart(2,"0");s+=`${v}:${E}:${w}`,r+=2;break}case"@":{let b=f.getHours()%12;b===0&&(b=12);let v=String(b).padStart(2,"0"),E=String(f.getMinutes()).padStart(2,"0"),w=f.getHours()<12?"AM":"PM";s+=`${v}:${E} ${w}`,r+=2;break}case"A":{let b=String(f.getHours()).padStart(2,"0"),v=String(f.getMinutes()).padStart(2,"0");s+=`${b}:${v}`,r+=2;break}case"D":if(r+2<t.length&&t[r+2]==="{"){let b=t.indexOf("}",r+3);if(b!==-1){let v=t.slice(r+3,b);s+=Vu(v,f),r=b+1}else s+="\\D",r+=2}else s+="\\D",r+=2;break;case"s":s+="bash",r+=2;break;case"v":s+="5.0",r+=2;break;case"V":s+="5.0.0",r+=2;break;case"j":s+="0",r+=2;break;case"l":s+="tty",r+=2;break;case"#":s+=m,r+=2;break;case"!":s+=m,r+=2;break;case"x":s+="\\x",r+=2;break;default:s+=`\\${y}`,r+=2}}else s+=p,r++}return s}function kt(e){if(e==="")return"''";if(/[\n\r\t\x00-\x1f\x7f']/.test(e)){let s="$'";for(let r of e)switch(r){case"'":s+="\\'";break;case"\\":s+="\\\\";break;case`
69
- `:s+="\\n";break;case"\r":s+="\\r";break;case" ":s+="\\t";break;default:{let n=r.charCodeAt(0);n<32||n===127?s+=`\\${n.toString(8).padStart(3,"0")}`:s+=r}}return`${s}'`}return`'${e}'`}function De(e,t){e.state.readonlyVars=e.state.readonlyVars||new Set,e.state.readonlyVars.add(t)}function rt(e,t){return e.state.readonlyVars?.has(t)??!1}function ye(e,t,s="bash"){if(rt(e,t)){let r=`${s}: ${t}: readonly variable
70
- `;throw new Z(1,"",r)}return null}function Qe(e,t){let s=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)&&!s){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 Hs(e,t){e.state.exportedVars?.delete(t)}function Nt(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let s="",r=e.state.env.has(`${t}__length`)||Array.from(e.state.env.keys()).some(i=>i.startsWith(`${t}_`)&&/^[0-9]+$/.test(i.slice(t.length+1))),n=e.state.associativeArrays?.has(t)??!1;return r&&!n&&(s+="a"),n&&(s+="A"),e.state.integerVars?.has(t)&&(s+="i"),te(e,t)&&(s+="n"),rt(e,t)&&(s+="r"),e.state.exportedVars?.has(t)&&(s+="x"),s}async function qa(e,t,s,r){return e.coverage?.hit("bash:expansion:default_value"),(s.isUnset||t.checkEmpty&&s.isEmpty)&&t.word?r(e,t.word.parts,s.inDoubleQuotes):s.effectiveValue}async function ja(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:assign_default"),(r.isUnset||s.checkEmpty&&r.isEmpty)&&s.word){let a=await n(e,s.word.parts,r.inDoubleQuotes),l=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let[,o,u]=l,c;if(/^\d+$/.test(u))c=Number.parseInt(u,10);else{try{let d=new q,h=Y(d,u);c=await T(e,h.expression)}catch{let d=e.state.env.get(u);c=d?Number.parseInt(d,10):0}Number.isNaN(c)&&(c=0)}e.state.env.set(`${o}_${c}`,a);let f=Number.parseInt(e.state.env.get(`${o}__length`)||"0",10);c>=f&&e.state.env.set(`${o}__length`,String(c+1))}else e.state.env.set(t,a);return a}return r.effectiveValue}async function Ua(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:error_if_unset"),r.isUnset||s.checkEmpty&&r.isEmpty){let a=s.word?await n(e,s.word.parts,r.inDoubleQuotes):`${t}: parameter null or not set`;throw new Z(1,"",`bash: ${a}
71
- `)}return r.effectiveValue}async function Za(e,t,s,r){return e.coverage?.hit("bash:expansion:use_alternative"),!(s.isUnset||t.checkEmpty&&s.isEmpty)&&t.word?r(e,t.word.parts,s.inDoubleQuotes):""}async function Ga(e,t,s,r,n){e.coverage?.hit("bash:expansion:pattern_removal");let i="",a=e.state.shoptOptions.extglob;if(s.pattern)for(let o of s.pattern.parts)if(o.type==="Glob")i+=G(o.pattern,s.greedy,a);else if(o.type==="Literal")i+=G(o.value,s.greedy,a);else if(o.type==="SingleQuoted"||o.type==="Escaped")i+=Q(o.value);else if(o.type==="DoubleQuoted"){let u=await r(e,o.parts);i+=Q(u)}else if(o.type==="ParameterExpansion"){let u=await n(e,o);i+=G(u,s.greedy,a)}else{let u=await n(e,o);i+=Q(u)}if(s.side==="prefix")return le(`^${i}`,"s").replace(t,"");let l=le(`${i}$`,"s");if(s.greedy)return l.replace(t,"");for(let o=t.length;o>=0;o--){let u=t.slice(o);if(l.test(u))return t.slice(0,o)}return t}async function Ha(e,t,s,r,n){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",a=e.state.shoptOptions.extglob;if(s.pattern)for(let u of s.pattern.parts)if(u.type==="Glob")i+=G(u.pattern,!0,a);else if(u.type==="Literal")i+=G(u.value,!0,a);else if(u.type==="SingleQuoted"||u.type==="Escaped")i+=Q(u.value);else if(u.type==="DoubleQuoted"){let c=await r(e,u.parts);i+=Q(c)}else if(u.type==="ParameterExpansion"){let c=await n(e,u);i+=G(c,!0,a)}else{let c=await n(e,u);i+=Q(c)}let l=s.replacement?await r(e,s.replacement.parts):"";if(s.anchor==="start"?i=`^${i}`:s.anchor==="end"&&(i=`${i}$`),i==="")return t;let o=s.all?"gs":"s";try{let u=le(i,o);if(s.all){let c="",f=0,d=0,h=e.limits.maxStringLength,m=u.exec(t);for(;m!==null&&!(m[0].length===0&&m.index===t.length);){if(c+=t.slice(f,m.index)+l,f=m.index+m[0].length,m[0].length===0&&f++,d++,d%100===0&&c.length>h)throw new X(`pattern replacement: string length limit exceeded (${h} bytes)`,"string_length");m=u.exec(t)}return c+=t.slice(f),c}return u.replace(t,l)}catch(u){if(u instanceof X)throw u;return t}}function Qa(e,t,s){e.coverage?.hit("bash:expansion:length");let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(r){let n=r[1],i=B(e,n);return i.length>0?String(i.length):e.state.env.get(n)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&He(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 n=e.state.env.get(`${t}_0`)||"";return String([...n].length)}return String([...s].length)}async function Ka(e,t,s,r){e.coverage?.hit("bash:expansion:substring");let n=await T(e,r.offset.expression),i=r.length?await T(e,r.length.expression):void 0;if(t==="@"||t==="*"){let u=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let m=1;m<=u;m++)c.push(e.state.env.get(String(m))||"");let f=e.state.env.get("0")||"bash",d,h;if(n<=0)if(d=[f,...c],n<0){if(h=d.length+n,h<0)return""}else h=0;else d=c,h=n-1;if(h<0||h>=d.length)return"";if(i!==void 0){let m=i<0?d.length+i:h+i;return d.slice(h,Math.max(h,m)).join(" ")}return d.slice(h).join(" ")}let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(a){let u=a[1];if(e.state.associativeArrays?.has(u))throw new Z(1,"",`bash: \${${u}[@]: 0: 3}: bad substitution
72
- `);let c=B(e,u),f=0;if(n<0){if(c.length>0){let d=c[c.length-1][0],m=(typeof d=="number"?d:0)+1+n;if(m<0||(f=c.findIndex(([p])=>typeof p=="number"&&p>=m),f<0))return""}}else if(f=c.findIndex(([d])=>typeof d=="number"&&d>=n),f<0)return"";if(i!==void 0){if(i<0)throw new se(`${a[1]}[@]: substring expression < 0`);return c.slice(f,f+i).map(([,d])=>d).join(" ")}return c.slice(f).map(([,d])=>d).join(" ")}let l=[...s],o=n;if(o<0&&(o=Math.max(0,l.length+o)),i!==void 0){if(i<0){let u=l.length+i;return l.slice(o,Math.max(o,u)).join("")}return l.slice(o,o+i).join("")}return l.slice(o).join("")}async function Xa(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:case_modification"),s.pattern){let i=e.state.shoptOptions.extglob,a="";for(let f of s.pattern.parts)if(f.type==="Glob")a+=G(f.pattern,!0,i);else if(f.type==="Literal")a+=G(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")a+=Q(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);a+=Q(d)}else if(f.type==="ParameterExpansion"){let d=await n(e,f);a+=G(d,!0,i)}let l=le(`^(?:${a})$`),o=s.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),u="",c=!1;for(let f of t)!s.all&&c?u+=f:l.test(f)?(u+=o(f),c=!0):u+=f;return u}return s.direction==="upper"?s.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):s.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function Ya(e,t,s,r,n){e.coverage?.hit("bash:expansion:transform");let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i&&n.operator==="Q")return B(e,i[1]).map(([,u])=>kt(u)).join(" ");if(i&&n.operator==="a")return Nt(e,i[1]);let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(a&&n.operator==="a")return Nt(e,a[1]);switch(n.operator){case"Q":return r?"":kt(s);case"P":return ms(e,s);case"a":return Nt(e,t);case"A":return r?"":`${t}=${kt(s)}`;case"E":return s.replace(/\\([\\abefnrtv'"?])/g,(l,o)=>{switch(o){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
73
- `;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return o}});case"K":case"k":return r?"":kt(s);case"u":return s.charAt(0).toUpperCase()+s.slice(1);case"U":return s.toUpperCase();case"L":return s.toLowerCase();default:return s}}async function Ja(e,t,s,r,n,i,a=!1){if(e.coverage?.hit("bash:expansion:indirection"),te(e,t))return Tt(e,t)||"";let l=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(n.innerOp?.type==="UseAlternative")return"";throw new Me(`\${!${t}}`)}let o=s;if(l&&(o===""||o.includes(" ")))throw new Me(`\${!${t}}`);let u=o.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new Me(`\${!${t}}`);if(n.innerOp){let c={type:"ParameterExpansion",parameter:o,operation:n.innerOp};return i(e,c,a)}return await J(e,o)}function eo(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=B(e,t.array).map(([n])=>String(n));return t.star?r.join(j(e.state.env)):r.join(" ")}function to(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let s=Zt(e,t.prefix);return t.star?s.join(j(e.state.env)):s.join(" ")}function so(e,t,s,r){let n=Number.parseInt(e.state.env.get("#")||"0",10),i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:n===0,effectiveValue:s};if(t==="@")return{isEmpty:n===0||n===1&&e.state.env.get("1")==="",effectiveValue:s};if(i){let[,a,l]=i,o=B(e,a);if(o.length===0)return{isEmpty:!0,effectiveValue:""};if(l==="*"){let u=j(e.state.env),c=o.map(([,f])=>f).join(u);return{isEmpty:r?c==="":!1,effectiveValue:c}}return{isEmpty:o.length===1&&o.every(([,u])=>u===""),effectiveValue:o.map(([,u])=>u).join(" ")}}return{isEmpty:s==="",effectiveValue:s}}function no(e){let t=0;for(;t<e.length;){let s=e[t];if(s==="\\"&&t+1<e.length){t+=2;continue}if(s==="'"){let r=e.indexOf("'",t+1);if(r!==-1){t=r+1;continue}}if(s==="$"&&t+1<e.length&&e[t+1]==="("||s==="`")return!0;t++}return!1}function ro(e,t){let s=1,r=t,n=!1,i=!1;for(;r<e.length&&s>0;){let a=e[r];if(a==="\\"&&!n&&r+1<e.length){r+=2;continue}if(a==="'"&&!i){n=!n,r++;continue}if(a==='"'&&!n){i=!i,r++;continue}if(!n&&!i){if(a==="(")s++;else if(a===")"&&(s--,s===0))return r}r++}return-1}async function Qs(e,t){let s=new q,r;try{r=s.parse(t)}catch{return""}let n=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let i=new Map(e.state.env),a=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let o=await e.executeScript(r),u=o.exitCode;return e.state.env=i,e.state.cwd=a,e.state.suppressVerbose=l,e.state.lastExitCode=u,e.state.env.set("?",String(u)),o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),e.state.bashPid=n,o.stdout.replace(/\n+$/,"")}catch(o){if(e.state.env=i,e.state.cwd=a,e.state.bashPid=n,e.state.suppressVerbose=l,o instanceof X)throw o;return o instanceof Z?(e.state.lastExitCode=o.exitCode,e.state.env.set("?",String(o.exitCode)),o.stdout?.replace(/\n+$/,"")??""):""}}function Nr(e,t){let s="",r=0;for(;r<t.length;){let n=t[r];if(n==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let a=t.slice(r+1,i);s+=Fe(a),r=i+1;continue}}if(n==='"'){let i=-1,a=r+1;for(;a<t.length;){if(t[a]==="\\"){a+=2;continue}if(t[a]==='"'){i=a;break}a++}if(i!==-1){let l=t.slice(r+1,i),o=zu(e,l);s+=Fe(o),r=i+1;continue}}if(n==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let a=t.indexOf("}",r+2);if(a!==-1){let l=t.slice(r+2,a);s+=e.state.env.get(l)??"",r=a+1;continue}}else if(/[a-zA-Z_]/.test(i)){let a=r+1;for(;a<t.length&&/[a-zA-Z0-9_]/.test(t[a]);)a++;let l=t.slice(r+1,a);s+=e.state.env.get(l)??"",r=a;continue}}if(n==="\\"&&r+1<t.length){s+=n+t[r+1],r+=2;continue}s+=n,r++}return s}function zu(e,t){let s="",r=0;for(;r<t.length;){let n=t[r];if(n==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){s+=i,r+=2;continue}s+=n,r++;continue}if(n==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let a=t.indexOf("}",r+2);if(a!==-1){let l=t.slice(r+2,a);s+=e.state.env.get(l)??"",r=a+1;continue}}else if(/[a-zA-Z_]/.test(i)){let a=r+1;for(;a<t.length&&/[a-zA-Z0-9_]/.test(t[a]);)a++;let l=t.slice(r+1,a);s+=e.state.env.get(l)??"",r=a;continue}}s+=n,r++}return s}async function io(e,t){let s="",r=0;for(;r<t.length;){let n=t[r];if(n==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let a=t.slice(r+1,i);s+=Fe(a),r=i+1;continue}}if(n==='"'){let i=-1,a=r+1;for(;a<t.length;){if(t[a]==="\\"){a+=2;continue}if(t[a]==='"'){i=a;break}a++}if(i!==-1){let l=t.slice(r+1,i),o=await Bu(e,l);s+=Fe(o),r=i+1;continue}}if(n==="$"&&r+1<t.length&&t[r+1]==="("){let i=ro(t,r+2);if(i!==-1){let a=t.slice(r+2,i),l=await Qs(e,a);s+=l,r=i+1;continue}}if(n==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let a=t.slice(r+1,i),l=await Qs(e,a);s+=l,r=i+1;continue}}if(n==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let a=t.indexOf("}",r+2);if(a!==-1){let l=t.slice(r+2,a);s+=e.state.env.get(l)??"",r=a+1;continue}}else if(/[a-zA-Z_]/.test(i)){let a=r+1;for(;a<t.length&&/[a-zA-Z0-9_]/.test(t[a]);)a++;let l=t.slice(r+1,a);s+=e.state.env.get(l)??"",r=a;continue}}if(n==="\\"&&r+1<t.length){s+=n+t[r+1],r+=2;continue}s+=n,r++}return s}async function Bu(e,t){let s="",r=0;for(;r<t.length;){let n=t[r];if(n==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){s+=i,r+=2;continue}s+=n,r++;continue}if(n==="$"&&r+1<t.length&&t[r+1]==="("){let i=ro(t,r+2);if(i!==-1){let a=t.slice(r+2,i),l=await Qs(e,a);s+=l,r=i+1;continue}}if(n==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let a=t.slice(r+1,i),l=await Qs(e,a);s+=l,r=i+1;continue}}if(n==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let a=t.indexOf("}",r+2);if(a!==-1){let l=t.slice(r+2,a);s+=e.state.env.get(l)??"",r=a+1;continue}}else if(/[a-zA-Z_]/.test(i)){let a=r+1;for(;a<t.length&&/[a-zA-Z0-9_]/.test(t[a]);)a++;let l=t.slice(r+1,a);s+=e.state.env.get(l)??"",r=a;continue}}s+=n,r++}return s}function ao(e,t){if(!t.startsWith("~"))return t;e.coverage?.hit("bash:expansion:tilde");let s=e.state.env.get("HOME")!==void 0?e.state.env.get("HOME"):"/home/user";if(t==="~"||t.startsWith("~/"))return s+t.slice(1);let r=1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;let n=t.slice(1,r),i=t.slice(r);return i!==""&&!i.startsWith("/")?t:n==="root"?`/root${i}`:t}async function qu(e,t,s,r){let n="";for(let i of t.parts)if(i.type==="Glob")n+=G(i.pattern,!0,e.state.shoptOptions.extglob);else if(i.type==="Literal")n+=G(i.value,!0,e.state.shoptOptions.extglob);else if(i.type==="SingleQuoted"||i.type==="Escaped")n+=Q(i.value);else if(i.type==="DoubleQuoted"){let a=await s(e,i.parts);n+=Q(a)}else if(i.type==="ParameterExpansion"){let a=await r(e,i);n+=G(a,!0,e.state.shoptOptions.extglob)}else{let a=await r(e,i);n+=Q(a)}return n}async function oo(e,t,s,r){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!=="PatternReplacement")return null;let i=n.parts[0],a=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let l=a[1],o=a[2]==="*",u=i.operation,c=B(e,l),f=c.map(([,y])=>y);if(c.length===0){let y=e.state.env.get(l);y!==void 0&&f.push(y)}if(f.length===0)return{values:[],quoted:!0};let d="";u.pattern&&(d=await qu(e,u.pattern,s,r));let h=u.replacement?await s(e,u.replacement.parts):"",m=d;u.anchor==="start"?m=`^${d}`:u.anchor==="end"&&(m=`${d}$`);let p=[];try{let y=le(m,u.all?"g":"");for(let b of f)p.push(y.replace(b,h))}catch{p.push(...f)}if(o){let y=j(e.state.env);return{values:[p.join(y)],quoted:!0}}return{values:p,quoted:!0}}async function lo(e,t,s,r){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!=="PatternRemoval")return null;let i=n.parts[0],a=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let l=a[1],o=a[2]==="*",u=i.operation,c=B(e,l),f=c.map(([,p])=>p);if(c.length===0){let p=e.state.env.get(l);p!==void 0&&f.push(p)}if(f.length===0)return{values:[],quoted:!0};let d="",h=e.state.shoptOptions.extglob;if(u.pattern)for(let p of u.pattern.parts)if(p.type==="Glob")d+=G(p.pattern,u.greedy,h);else if(p.type==="Literal")d+=G(p.value,u.greedy,h);else if(p.type==="SingleQuoted"||p.type==="Escaped")d+=Q(p.value);else if(p.type==="DoubleQuoted"){let y=await s(e,p.parts);d+=Q(y)}else if(p.type==="ParameterExpansion"){let y=await r(e,p);d+=G(y,u.greedy,h)}else{let y=await r(e,p);d+=Q(y)}let m=[];for(let p of f)m.push(mt(p,d,u.side,u.greedy));if(o){let p=j(e.state.env);return{values:[m.join(p)],quoted:!0}}return{values:m,quoted:!0}}async function co(e,t){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!=="DefaultValue"&&s.parts[0].operation?.type!=="UseAlternative"&&s.parts[0].operation?.type!=="AssignDefault")return null;let r=s.parts[0],n=r.operation,i=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/),a,l=!1;if(i){let o=i[1];l=i[2]==="*";let u=B(e,o),c=u.length>0||e.state.env.has(o),f=u.length===0||u.length===1&&u.every(([,h])=>h===""),d=n.checkEmpty??!1;if(n.type==="UseAlternative"?a=c&&!(d&&f):a=!c||d&&f,!a){if(u.length>0){let m=u.map(([,p])=>p);if(l){let p=j(e.state.env);return{values:[m.join(p)],quoted:!0}}return{values:m,quoted:!0}}let h=e.state.env.get(o);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}else{let o=r.parameter,u=await st(e,o),c=await J(e,o),f=c==="",d=n.checkEmpty??!1;if(n.type==="UseAlternative"?a=u&&!(d&&f):a=!u||d&&f,!a)return{values:[c],quoted:!0}}if(a&&n.word){let o=n.word.parts,u=null,c=!1;for(let f of o)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){u=d[1],c=d[2]==="*";break}}if(u){let f=B(e,u);if(f.length>0){let h=f.map(([,m])=>m);if(c||l){let m=j(e.state.env);return{values:[h.join(m)],quoted:!0}}return{values:h,quoted:!0}}let d=e.state.env.get(u);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}return null}async function uo(e,t,s,r,n){if(!s||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0],a=-1,l="",o=!1,u=null;for(let p=0;p<i.parts.length;p++){let y=i.parts[p];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){a=p,l=b[1],o=b[2]==="*",u=y.operation;break}}}if(a===-1||a===0&&a===i.parts.length-1)return null;let c="";for(let p=0;p<a;p++)c+=await r(e,i.parts[p]);let f="";for(let p=a+1;p<i.parts.length;p++)f+=await r(e,i.parts[p]);let d=B(e,l),h=d.map(([,p])=>p);if(d.length===0){let p=e.state.env.get(l);if(p!==void 0)h=[p];else{if(o)return{values:[c+f],quoted:!0};let y=c+f;return{values:y?[y]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let p=u,y="",b=e.state.shoptOptions.extglob;if(p.pattern)for(let v of p.pattern.parts)if(v.type==="Glob")y+=G(v.pattern,p.greedy,b);else if(v.type==="Literal")y+=G(v.value,p.greedy,b);else if(v.type==="SingleQuoted"||v.type==="Escaped")y+=Q(v.value);else if(v.type==="DoubleQuoted"){let E=await n(e,v.parts);y+=Q(E)}else if(v.type==="ParameterExpansion"){let E=await r(e,v);y+=G(E,p.greedy,b)}else{let E=await r(e,v);y+=Q(E)}h=h.map(v=>mt(v,y,p.side,p.greedy))}else if(u?.type==="PatternReplacement"){let p=u,y="";if(p.pattern)for(let E of p.pattern.parts)if(E.type==="Glob")y+=G(E.pattern,!0,e.state.shoptOptions.extglob);else if(E.type==="Literal")y+=G(E.value,!0,e.state.shoptOptions.extglob);else if(E.type==="SingleQuoted"||E.type==="Escaped")y+=Q(E.value);else if(E.type==="DoubleQuoted"){let w=await n(e,E.parts);y+=Q(w)}else if(E.type==="ParameterExpansion"){let w=await r(e,E);y+=G(w,!0,e.state.shoptOptions.extglob)}else{let w=await r(e,E);y+=Q(w)}let b=p.replacement?await n(e,p.replacement.parts):"",v=y;p.anchor==="start"?v=`^${y}`:p.anchor==="end"&&(v=`${y}$`);try{let E=le(v,p.all?"g":"");h=h.map(w=>E.replace(w,b))}catch{}}if(o){let p=j(e.state.env);return{values:[c+h.join(p)+f],quoted:!0}}return h.length===1?{values:[c+h[0]+f],quoted:!0}:{values:[c+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function fo(e,t,s,r){if(!s||t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],i=-1,a="",l=!1;for(let h=0;h<n.parts.length;h++){let m=n.parts[h];if(m.type==="ParameterExpansion"&&!m.operation){let p=m.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(p){i=h,a=p[1],l=p[2]==="*";break}}}if(i===-1)return null;let o="";for(let h=0;h<i;h++)o+=await r(e,n.parts[h]);let u="";for(let h=i+1;h<n.parts.length;h++)u+=await r(e,n.parts[h]);let c=B(e,a),f=c.map(([,h])=>h);if(c.length===0){let h=e.state.env.get(a);if(h!==void 0)return{values:[o+h+u],quoted:!0};if(l)return{values:[o+u],quoted:!0};let m=o+u;return{values:m?[m]:[],quoted:!0}}if(l){let h=j(e.state.env);return{values:[o+f.join(h)+u],quoted:!0}}return f.length===1?{values:[o+f[0]+u],quoted:!0}:{values:[o+f[0],...f.slice(1,-1),f[f.length-1]+u],quoted:!0}}async function ho(e,t,s){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 n=r.parts[0],i=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let a=i[1],l=i[2]==="*",o=n.operation;if(e.state.associativeArrays?.has(a))throw new Z(1,"",`bash: \${${a}[@]: 0: 3}: bad substitution
74
- `);let u=o.offset?await s(e,o.offset.expression):0,c=o.length?await s(e,o.length.expression):void 0,f=B(e,a),d=0;if(u<0){if(f.length>0){let m=f[f.length-1][0],y=(typeof m=="number"?m:0)+1+u;if(y<0)return{values:[],quoted:!0};d=f.findIndex(([b])=>typeof b=="number"&&b>=y),d<0&&(d=f.length)}}else d=f.findIndex(([m])=>typeof m=="number"&&m>=u),d<0&&(d=f.length);let h;if(c!==void 0){if(c<0)throw new se(`${a}[@]: substring expression < 0`);h=f.slice(d,d+c).map(([,m])=>m)}else h=f.slice(d).map(([,m])=>m);if(h.length===0)return{values:[],quoted:!0};if(l){let m=j(e.state.env);return{values:[h.join(m)],quoted:!0}}return{values:h,quoted:!0}}function po(e,t){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!=="Transform")return null;let r=s.parts[0],n=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let i=n[1],a=n[2]==="*",l=r.operation,o=B(e,i);if(o.length===0){let f=e.state.env.get(i);if(f!==void 0){let d;switch(l.operator){case"a":d="";break;case"P":d=ms(e,f);break;case"Q":d=kt(f);break;default:d=f}return{values:[d],quoted:!0}}return a?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=Nt(e,i),c;switch(l.operator){case"a":c=o.map(()=>u);break;case"P":c=o.map(([,f])=>ms(e,f));break;case"Q":c=o.map(([,f])=>kt(f));break;case"u":c=o.map(([,f])=>f.charAt(0).toUpperCase()+f.slice(1));break;case"U":c=o.map(([,f])=>f.toUpperCase());break;case"L":c=o.map(([,f])=>f.toLowerCase());break;default:c=o.map(([,f])=>f)}if(a){let f=j(e.state.env);return{values:[c.join(f)],quoted:!0}}return{values:c,quoted:!0}}function mo(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion")return null;let r=s.parts[0];if(r.operation)return null;let n=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!n)return null;let i=n[1];if(te(e,i)){let o=Tt(e,i);if(o?.endsWith("[@]")||o?.endsWith("[*]"))return{values:[],quoted:!0}}let a=B(e,i);if(a.length>0)return{values:a.map(([,o])=>o),quoted:!0};let l=e.state.env.get(i);return l!==void 0?{values:[l],quoted:!0}:{values:[],quoted:!0}}function go(e,t){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)return null;let n=s.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||!te(e,n))return null;let i=Tt(e,n);if(!i)return null;let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!a)return null;let l=a[1],o=B(e,l);if(o.length>0)return{values:o.map(([,c])=>c),quoted:!0};let u=e.state.env.get(l);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function yo(e,t,s,r,n){if(!s||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 a=i.parts[0],l=a.operation,o=await J(e,a.parameter),u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!l.innerOp&&(o==="@"||o==="*")){let m=Number.parseInt(e.state.env.get("#")||"0",10),p=[];for(let y=1;y<=m;y++)p.push(e.state.env.get(String(y))||"");return o==="*"?{values:[p.join(j(e.state.env))],quoted:!0}:{values:p,quoted:!0}}return null}let c=u[1],f=u[2]==="*",d=B(e,c);if(l.innerOp){if(l.innerOp.type==="Substring")return ju(e,d,c,f,l.innerOp);if(l.innerOp.type==="DefaultValue"||l.innerOp.type==="UseAlternative"||l.innerOp.type==="AssignDefault"||l.innerOp.type==="ErrorIfUnset")return Uu(e,d,c,f,l.innerOp,n);if(l.innerOp.type==="Transform"&&l.innerOp.operator==="a"){let p=Nt(e,c),y=d.map(()=>p);return f?{values:[y.join(j(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let m=[];for(let[,p]of d){let y={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:l.innerOp},b=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",p);try{let v=await r(e,y,!0);m.push(v)}finally{b!==void 0?e.state.env.set("_indirect_elem_",b):e.state.env.delete("_indirect_elem_")}}return f?{values:[m.join(j(e.state.env))],quoted:!0}:{values:m,quoted:!0}}if(d.length>0){let m=d.map(([,p])=>p);return f?{values:[m.join(j(e.state.env))],quoted:!0}:{values:m,quoted:!0}}let h=e.state.env.get(c);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}async function ju(e,t,s,r,n){let i=n.offset?await T(e,n.offset.expression):0,a=n.length?await T(e,n.length.expression):void 0,l=0;if(i<0){if(t.length>0){let c=t[t.length-1][0],d=(typeof c=="number"?c:0)+1+i;if(d<0)return{values:[],quoted:!0};if(l=t.findIndex(([h])=>typeof h=="number"&&h>=d),l<0)return{values:[],quoted:!0}}}else if(l=t.findIndex(([c])=>typeof c=="number"&&c>=i),l<0)return{values:[],quoted:!0};let o;if(a!==void 0){if(a<0)throw new se(`${s}[@]: substring expression < 0`);o=t.slice(l,l+a)}else o=t.slice(l);let u=o.map(([,c])=>c);return r?{values:[u.join(j(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function Uu(e,t,s,r,n,i){let a=n.checkEmpty??!1,l=t.map(([,c])=>c),o=t.length===0,u=t.length===0;if(n.type==="UseAlternative")return!u&&!(a&&o)&&n.word?{values:[await i(e,n.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(n.type==="DefaultValue")return(u||a&&o)&&n.word?{values:[await i(e,n.word.parts,!0)],quoted:!0}:r?{values:[l.join(j(e.state.env))],quoted:!0}:{values:l,quoted:!0};if(n.type==="AssignDefault"){if((u||a&&o)&&n.word){let f=await i(e,n.word.parts,!0);return e.state.env.set(`${s}_0`,f),e.state.env.set(`${s}__length`,"1"),{values:[f],quoted:!0}}return r?{values:[l.join(j(e.state.env))],quoted:!0}:{values:l,quoted:!0}}return r?{values:[l.join(j(e.state.env))],quoted:!0}:{values:l,quoted:!0}}async function wo(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let s=t[0],r=s.operation,n=r?.word;if(!n||n.parts.length!==1||n.parts[0].type!=="DoubleQuoted")return null;let i=n.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let a=i.parts[0],o=(await J(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let u=await st(e,s.parameter),c=await J(e,s.parameter)==="",f=r.checkEmpty??!1,d;if(r.type==="UseAlternative"?d=u&&!(f&&c):d=!u||f&&c,d){let h=o[1],m=o[2]==="*",p=B(e,h);if(p.length>0){let b=p.map(([,v])=>v);return m?{values:[b.join(j(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 Eo(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let s=t[0],n=s.operation.innerOp;if(!n||n.type!=="UseAlternative"&&n.type!=="DefaultValue")return null;let i=n.word;if(!i||i.parts.length!==1||i.parts[0].type!=="DoubleQuoted")return null;let a=i.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let l=a.parts[0],u=(await J(e,l.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await J(e,s.parameter),f=await st(e,s.parameter),d=c==="",h=n.checkEmpty??!1,m;if(n.type==="UseAlternative"?m=f&&!(h&&d):m=!f||h&&d,m){let p=u[1],y=u[2]==="*",b=B(e,p);if(b.length>0){let E=b.map(([,w])=>w);return y?{values:[E.join(j(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let v=e.state.env.get(p);return v!==void 0?{values:[v],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function bo(e){let t=Number.parseInt(e.state.env.get("#")||"0",10),s=[];for(let r=1;r<=t;r++)s.push(e.state.env.get(String(r))||"");return s}async function vo(e,t,s,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],i=-1,a=!1;for(let v=0;v<n.parts.length;v++){let E=n.parts[v];if(E.type==="ParameterExpansion"&&(E.parameter==="@"||E.parameter==="*")&&E.operation?.type==="Substring"){i=v,a=E.parameter==="*";break}}if(i===-1)return null;let o=n.parts[i].operation,u=o.offset?await s(e,o.offset.expression):0,c=o.length?await s(e,o.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),d=[];for(let v=1;v<=f;v++)d.push(e.state.env.get(String(v))||"");let h=e.state.env.get("0")||"bash",m;if(u<=0){let v=[h,...d],E=v.length+u;if(E<0)m=[];else{let w=u<0?E:0;if(c!==void 0){let S=c<0?v.length+c:w+c;m=v.slice(w,Math.max(w,S))}else m=v.slice(w)}}else{let v=u-1;if(v>=d.length)m=[];else if(c!==void 0){let E=c<0?d.length+c:v+c;m=d.slice(v,Math.max(v,E))}else m=d.slice(v)}let p="";for(let v=0;v<i;v++)p+=await r(e,n.parts[v]);let y="";for(let v=i+1;v<n.parts.length;v++)y+=await r(e,n.parts[v]);if(m.length===0){let v=p+y;return{values:v?[v]:[],quoted:!0}}if(a){let v=j(e.state.env);return{values:[p+m.join(v)+y],quoted:!0}}return m.length===1?{values:[p+m[0]+y],quoted:!0}:{values:[p+m[0],...m.slice(1,-1),m[m.length-1]+y],quoted:!0}}async function So(e,t,s,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],i=-1,a=!1;for(let b=0;b<n.parts.length;b++){let v=n.parts[b];if(v.type==="ParameterExpansion"&&(v.parameter==="@"||v.parameter==="*")&&v.operation?.type==="PatternReplacement"){i=b,a=v.parameter==="*";break}}if(i===-1)return null;let o=n.parts[i].operation,u=bo(e),c="";for(let b=0;b<i;b++)c+=await s(e,n.parts[b]);let f="";for(let b=i+1;b<n.parts.length;b++)f+=await s(e,n.parts[b]);if(u.length===0){let b=c+f;return{values:b?[b]:[],quoted:!0}}let d="";if(o.pattern)for(let b of o.pattern.parts)if(b.type==="Glob")d+=G(b.pattern,!0,e.state.shoptOptions.extglob);else if(b.type==="Literal")d+=G(b.value,!0,e.state.shoptOptions.extglob);else if(b.type==="SingleQuoted"||b.type==="Escaped")d+=Q(b.value);else if(b.type==="DoubleQuoted"){let v=await r(e,b.parts);d+=Q(v)}else if(b.type==="ParameterExpansion"){let v=await s(e,b);d+=G(v,!0,e.state.shoptOptions.extglob)}else{let v=await s(e,b);d+=Q(v)}let h=o.replacement?await r(e,o.replacement.parts):"",m=d;o.anchor==="start"?m=`^${d}`:o.anchor==="end"&&(m=`${d}$`);let p=[];try{let b=le(m,o.all?"g":"");for(let v of u)p.push(b.replace(v,h))}catch{p.push(...u)}if(a){let b=j(e.state.env);return{values:[c+p.join(b)+f],quoted:!0}}return p.length===1?{values:[c+p[0]+f],quoted:!0}:{values:[c+p[0],...p.slice(1,-1),p[p.length-1]+f],quoted:!0}}async function Ao(e,t,s,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],i=-1,a=!1;for(let y=0;y<n.parts.length;y++){let b=n.parts[y];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="PatternRemoval"){i=y,a=b.parameter==="*";break}}if(i===-1)return null;let o=n.parts[i].operation,u=bo(e),c="";for(let y=0;y<i;y++)c+=await s(e,n.parts[y]);let f="";for(let y=i+1;y<n.parts.length;y++)f+=await s(e,n.parts[y]);if(u.length===0){let y=c+f;return{values:y?[y]:[],quoted:!0}}let d="",h=e.state.shoptOptions.extglob;if(o.pattern)for(let y of o.pattern.parts)if(y.type==="Glob")d+=G(y.pattern,o.greedy,h);else if(y.type==="Literal")d+=G(y.value,o.greedy,h);else if(y.type==="SingleQuoted"||y.type==="Escaped")d+=Q(y.value);else if(y.type==="DoubleQuoted"){let b=await r(e,y.parts);d+=Q(b)}else if(y.type==="ParameterExpansion"){let b=await s(e,y);d+=G(b,o.greedy,h)}else{let b=await s(e,y);d+=Q(b)}let m=[];for(let y of u)m.push(mt(y,d,o.side,o.greedy));if(a){let y=j(e.state.env);return{values:[c+m.join(y)+f],quoted:!0}}return m.length===1?{values:[c+m[0]+f],quoted:!0}:{values:[c+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function $o(e,t,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0],n=-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==="*")){n=d,i=h.parameter==="*";break}}if(n===-1)return null;let a=r.parts[n];if(a.type==="ParameterExpansion"&&a.operation)return null;let l=Number.parseInt(e.state.env.get("#")||"0",10),o="";for(let d=0;d<n;d++)o+=await s(e,r.parts[d]);let u="";for(let d=n+1;d<r.parts.length;d++)u+=await s(e,r.parts[d]);if(l===0){if(i)return{values:[o+u],quoted:!0};let d=o+u;return{values:d?[d]:[],quoted:!0}}let c=[];for(let d=1;d<=l;d++)c.push(e.state.env.get(String(d))||"");if(i){let d=j(e.state.env);return{values:[o+c.join(d)+u],quoted:!0}}return c.length===1?{values:[o+c[0]+u],quoted:!0}:{values:[o+c[0],...c.slice(1,-1),c[c.length-1]+u],quoted:!0}}function Zu(e){return new Pt(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})}async function Ks(e,t){if(e.state.options.noglob)return t;let s=Zu(e),r=[];for(let n of t)if(nt(n,e.state.shoptOptions.extglob)){let i=await s.expand(n);if(i.length>0)r.push(...i);else{if(s.hasFailglob())throw new wt(n);s.hasNullglob()||r.push(n)}}else r.push(n);return r}async function Po(e,t,s,r){let n=-1,i="",a=!1;for(let v=0;v<t.length;v++){let E=t[v];if(E.type==="ParameterExpansion"&&E.operation?.type==="PatternReplacement"){let w=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(w){n=v,i=w[1],a=w[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,u=B(e,i),c=u.map(([,v])=>v);if(u.length===0){let v=e.state.env.get(i);v!==void 0&&(c=[v])}if(c.length===0)return{values:[],quoted:!1};let f="";if(o.pattern)for(let v of o.pattern.parts)if(v.type==="Glob")f+=G(v.pattern,!0,e.state.shoptOptions.extglob);else if(v.type==="Literal")f+=G(v.value,!0,e.state.shoptOptions.extglob);else if(v.type==="SingleQuoted"||v.type==="Escaped")f+=Q(v.value);else if(v.type==="DoubleQuoted"){let E=await s(e,v.parts);f+=Q(E)}else if(v.type==="ParameterExpansion"){let E=await r(e,v);f+=G(E,!0,e.state.shoptOptions.extglob)}else{let E=await r(e,v);f+=Q(E)}let d=o.replacement?await s(e,o.replacement.parts):"",h=f;o.anchor==="start"?h=`^${f}`:o.anchor==="end"&&(h=`${f}$`);let m=[];try{let v=le(h,o.all?"g":"");for(let E of c)m.push(v.replace(E,d))}catch{m.push(...c)}let p=me(e.state.env),y=ve(e.state.env);if(a){let v=j(e.state.env),E=m.join(v);return y?{values:E?[E]:[],quoted:!1}:{values:re(E,p),quoted:!1}}if(y)return{values:m,quoted:!1};let b=[];for(let v of m)v===""?b.push(""):b.push(...re(v,p));return{values:b,quoted:!1}}async function ko(e,t,s,r){let n=-1,i="",a=!1;for(let b=0;b<t.length;b++){let v=t[b];if(v.type==="ParameterExpansion"&&v.operation?.type==="PatternRemoval"){let E=v.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(E){n=b,i=E[1],a=E[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,u=B(e,i),c=u.map(([,b])=>b);if(u.length===0){let b=e.state.env.get(i);b!==void 0&&(c=[b])}if(c.length===0)return{values:[],quoted:!1};let f="",d=e.state.shoptOptions.extglob;if(o.pattern)for(let b of o.pattern.parts)if(b.type==="Glob")f+=G(b.pattern,o.greedy,d);else if(b.type==="Literal")f+=G(b.value,o.greedy,d);else if(b.type==="SingleQuoted"||b.type==="Escaped")f+=Q(b.value);else if(b.type==="DoubleQuoted"){let v=await s(e,b.parts);f+=Q(v)}else if(b.type==="ParameterExpansion"){let v=await r(e,b);f+=G(v,o.greedy,d)}else{let v=await r(e,b);f+=Q(v)}let h=[];for(let b of c)h.push(mt(b,f,o.side,o.greedy));let m=me(e.state.env),p=ve(e.state.env);if(a){let b=j(e.state.env),v=h.join(b);return p?{values:v?[v]:[],quoted:!1}:{values:re(v,m),quoted:!1}}if(p)return{values:h,quoted:!1};let y=[];for(let b of h)b===""?y.push(""):y.push(...re(b,m));return{values:y,quoted:!1}}async function No(e,t,s,r){let n=-1,i=!1;for(let y=0;y<t.length;y++){let b=t[y];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="PatternRemoval"){n=y,i=b.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let y=1;y<=o;y++)u.push(e.state.env.get(String(y))||"");if(u.length===0)return{values:[],quoted:!1};let c="",f=e.state.shoptOptions.extglob;if(l.pattern)for(let y of l.pattern.parts)if(y.type==="Glob")c+=G(y.pattern,l.greedy,f);else if(y.type==="Literal")c+=G(y.value,l.greedy,f);else if(y.type==="SingleQuoted"||y.type==="Escaped")c+=Q(y.value);else if(y.type==="DoubleQuoted"){let b=await s(e,y.parts);c+=Q(b)}else if(y.type==="ParameterExpansion"){let b=await r(e,y);c+=G(b,l.greedy,f)}else{let b=await r(e,y);c+=Q(b)}let d=[];for(let y of u)d.push(mt(y,c,l.side,l.greedy));let h=me(e.state.env),m=ve(e.state.env);if(i){let y=j(e.state.env),b=d.join(y);return m?{values:b?[b]:[],quoted:!1}:{values:re(b,h),quoted:!1}}if(m)return{values:d,quoted:!1};let p=[];for(let y of d)y===""?p.push(""):p.push(...re(y,h));return{values:p,quoted:!1}}async function _o(e,t,s,r){let n=-1,i=!1;for(let E=0;E<t.length;E++){let w=t[E];if(w.type==="ParameterExpansion"&&(w.parameter==="@"||w.parameter==="*")&&w.operation?.type==="Substring"){n=E,i=w.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=l.offset?await s(e,l.offset.expression):0,u=l.length?await s(e,l.length.expression):void 0,c=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let E=1;E<=c;E++)f.push(e.state.env.get(String(E))||"");let d=e.state.env.get("0")||"bash",h;if(o<=0){let E=[d,...f],w=E.length+o;if(w<0)h=[];else{let S=o<0?w:0;if(u!==void 0){let A=u<0?E.length+u:S+u;h=E.slice(S,Math.max(S,A))}else h=E.slice(S)}}else{let E=o-1;if(E>=f.length)h=[];else if(u!==void 0){let w=u<0?f.length+u:E+u;h=f.slice(E,Math.max(E,w))}else h=f.slice(E)}let m="";for(let E=0;E<n;E++)m+=await r(e,t[E]);let p="";for(let E=n+1;E<t.length;E++)p+=await r(e,t[E]);let y=me(e.state.env),b=ve(e.state.env);if(h.length===0){let E=m+p;return E?b?{values:[E],quoted:!1}:{values:re(E,y),quoted:!1}:{values:[],quoted:!1}}let v;if(i){let E=j(e.state.env),w=m+h.join(E)+p;b?v=w?[w]:[]:v=re(w,y)}else if(b)h.length===1?v=[m+h[0]+p]:v=[m+h[0],...h.slice(1,-1),h[h.length-1]+p];else{v=[];for(let E=0;E<h.length;E++){let w=h[E];if(E===0&&(w=m+w),E===h.length-1&&(w=w+p),w==="")v.push("");else{let S=re(w,y);v.push(...S)}}}return{values:await Ks(e,v),quoted:!1}}async function xo(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let s=t[0].parameter==="*",r=Number.parseInt(e.state.env.get("#")||"0",10);if(r===0)return{values:[],quoted:!1};let n=[];for(let u=1;u<=r;u++)n.push(e.state.env.get(String(u))||"");let i=me(e.state.env),a=ve(e.state.env),l=js(e.state.env),o;if(s)if(a)o=n.filter(u=>u!=="");else{let u=j(e.state.env),c=n.join(u);o=re(c,i)}else if(a)o=n.filter(u=>u!=="");else if(l){o=[];for(let u of n){if(u==="")continue;let c=re(u,i);o.push(...c)}}else{o=[];for(let u of n)if(u==="")o.push("");else{let c=re(u,i);o.push(...c)}for(;o.length>0&&o[o.length-1]==="";)o.pop()}return{values:await Ks(e,o),quoted:!1}}async function Co(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let s=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!s)return null;let r=s[1],n=s[2]==="*",i=B(e,r),a;if(i.length===0){let f=e.state.env.get(r);if(f!==void 0)a=[f];else return{values:[],quoted:!1}}else a=i.map(([,f])=>f);let l=me(e.state.env),o=ve(e.state.env),u=js(e.state.env),c;if(n)if(o)c=a.filter(f=>f!=="");else{let f=j(e.state.env),d=a.join(f);c=re(d,l)}else if(o)c=a.filter(f=>f!=="");else if(u){c=[];for(let f of a){if(f==="")continue;let d=re(f,l);c.push(...d)}}else{c=[];for(let f of a)if(f==="")c.push("");else{let d=re(f,l);c.push(...d)}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Ks(e,c),quoted:!1}}function Do(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let s=t[0].operation,r=Zt(e,s.prefix);if(r.length===0)return{values:[],quoted:!1};let n=me(e.state.env),i=ve(e.state.env),a;if(s.star)if(i)a=r;else{let l=j(e.state.env),o=r.join(l);a=re(o,n)}else if(i)a=r;else{a=[];for(let l of r){let o=re(l,n);a.push(...o)}}return{values:a,quoted:!1}}function Ro(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let s=t[0].operation,n=B(e,s.array).map(([o])=>String(o));if(n.length===0)return{values:[],quoted:!1};let i=me(e.state.env),a=ve(e.state.env),l;if(s.star)if(a)l=n;else{let o=j(e.state.env),u=n.join(o);l=re(u,i)}else if(a)l=n;else{l=[];for(let o of n){let u=re(o,i);l.push(...u)}}return{values:l,quoted:!1}}async function Io(e,t,s){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 n=Number.parseInt(e.state.env.get("#")||"0",10),i=[];for(let d=1;d<=n;d++)i.push(e.state.env.get(String(d))||"");let a="";for(let d=0;d<r;d++)a+=await s(e,t[d]);let l="";for(let d=r+1;d<t.length;d++)l+=await s(e,t[d]);let o=me(e.state.env),u=ve(e.state.env),c=js(e.state.env);if(n===0){let d=a+l;return{values:d?[d]:[],quoted:!1}}let f;{let d=[];for(let h=0;h<i.length;h++){let m=i[h];h===0&&(m=a+m),h===i.length-1&&(m=m+l),d.push(m)}if(u)f=d.filter(h=>h!=="");else if(c){f=[];for(let h of d){if(h==="")continue;let m=re(h,o);f.push(...m)}}else{f=[];for(let h of d)if(h==="")f.push("");else{let m=re(h,o);f.push(...m)}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Ks(e,f),quoted:!1}}async function Lo(e,t,s){e.coverage?.hit("bash:expansion:word_glob");let r=t.parts,{hasQuoted:n,hasCommandSub:i,hasArrayVar:a,hasArrayAtExpansion:l,hasParamExpansion:o,hasVarNamePrefixExpansion:u,hasIndirection:c}=hs(r),d=s.hasBraceExpansion(r)?await s.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return Gu(e,d,n);let h=await Hu(e,r,l,u,c,s);if(h!==null)return h;let m=await Ku(e,r,s);if(m!==null)return m;let p=await Xu(e,r,s);if(p!==null)return p;let y=await Ju(e,r,s.expandPart);if(y!==null)return To(e,y);if((i||a||o)&&!ve(e.state.env)){let v=me(e.state.env),E=s.buildIfsCharClassPattern(v),w=await s.smartWordSplit(e,r,v,E,s.expandPart);return To(e,w)}let b=await s.expandWordAsync(e,t);return ef(e,t,r,b,n,s.expandWordForGlobbing)}async function Gu(e,t,s){let r=[];for(let n of t)if(!(!s&&n===""))if(!s&&!e.state.options.noglob&&nt(n,e.state.shoptOptions.extglob)){let i=await Xs(e,n);r.push(...i)}else r.push(n);return{values:r,quoted:!1}}async function Hu(e,t,s,r,n,i){if(s){let a=mo(e,t);if(a!==null)return a}{let a=go(e,t);if(a!==null)return a}{let a=await co(e,t);if(a!==null)return a}{let a=await uo(e,t,s,i.expandPart,i.expandWordPartsAsync);if(a!==null)return a}{let a=await fo(e,t,s,i.expandPart);if(a!==null)return a}{let a=await ho(e,t,i.evaluateArithmetic);if(a!==null)return a}{let a=po(e,t);if(a!==null)return a}{let a=await oo(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}{let a=await lo(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let a=Qu(e,t);if(a!==null)return a}{let a=await yo(e,t,n,i.expandParameterAsync,i.expandWordPartsAsync);if(a!==null)return a}{let a=await wo(e,t);if(a!==null)return a}{let a=await Eo(e,t);if(a!==null)return a}return null}function Qu(e,t){let s=t[0];if(s.type!=="DoubleQuoted")return null;if(s.parts.length===1&&s.parts[0].type==="ParameterExpansion"&&s.parts[0].operation?.type==="VarNamePrefix"){let r=s.parts[0].operation,n=Zt(e,r.prefix);return r.star?{values:[n.join(j(e.state.env))],quoted:!0}:{values:n,quoted:!0}}if(s.parts.length===1&&s.parts[0].type==="ParameterExpansion"&&s.parts[0].operation?.type==="ArrayKeys"){let r=s.parts[0].operation,i=B(e,r.array).map(([a])=>String(a));return r.star?{values:[i.join(j(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function Ku(e,t,s){{let r=await vo(e,t,s.evaluateArithmetic,s.expandPart);if(r!==null)return r}{let r=await So(e,t,s.expandPart,s.expandWordPartsAsync);if(r!==null)return r}{let r=await Ao(e,t,s.expandPart,s.expandWordPartsAsync);if(r!==null)return r}{let r=await $o(e,t,s.expandPart);if(r!==null)return r}return null}async function Xu(e,t,s){{let r=await Po(e,t,s.expandWordPartsAsync,s.expandPart);if(r!==null)return r}{let r=await ko(e,t,s.expandWordPartsAsync,s.expandPart);if(r!==null)return r}{let r=await No(e,t,s.expandWordPartsAsync,s.expandPart);if(r!==null)return r}{let r=await _o(e,t,s.evaluateArithmetic,s.expandPart);if(r!==null)return r}{let r=await xo(e,t);if(r!==null)return r}{let r=await Co(e,t);if(r!==null)return r}{let r=Do(e,t);if(r!==null)return r}{let r=Ro(e,t);if(r!==null)return r}{let r=await Io(e,t,s.expandPart);if(r!==null)return r}return null}function Oo(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;t<e.parts.length;t++){let s=e.parts[t];if(s.type!=="ParameterExpansion"||s.operation)continue;let r=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(r)return{type:"array",name:r[1],atIndex:t,isStar:r[2]==="*"};if(s.parameter==="@"||s.parameter==="*")return{type:"positional",atIndex:t,isStar:s.parameter==="*"}}return null}async function Yu(e,t,s,r){let n="";for(let l=0;l<s.atIndex;l++)n+=await r(e,t.parts[l]);let i="";for(let l=s.atIndex+1;l<t.parts.length;l++)i+=await r(e,t.parts[l]);let a;if(s.type==="array"){if(a=B(e,s.name).map(([,o])=>o),a.length===0){let o=e.state.env.get(s.name);o!==void 0&&(a=[o])}}else{let l=Number.parseInt(e.state.env.get("#")||"0",10);a=[];for(let o=1;o<=l;o++)a.push(e.state.env.get(String(o))||"")}if(s.isStar){let l=j(e.state.env),o=a.join(l);return[n+o+i]}if(a.length===0){let l=n+i;return l?[l]:[]}return a.length===1?[n+a[0]+i]:[n+a[0],...a.slice(1,-1),a[a.length-1]+i]}async function Ju(e,t,s){if(t.length<2)return null;let r=!1;for(let o of t)if(Oo(o)){r=!0;break}if(!r)return null;let n=me(e.state.env),i=ve(e.state.env),a=[];for(let o of t){let u=Oo(o);if(u&&o.type==="DoubleQuoted"){let c=await Yu(e,o,u,s);a.push(c)}else if(o.type==="DoubleQuoted"||o.type==="SingleQuoted"){let c=await s(e,o);a.push([c])}else if(o.type==="Literal")a.push([o.value]);else if(o.type==="ParameterExpansion"){let c=await s(e,o);if(i)a.push(c?[c]:[]);else{let f=re(c,n);a.push(f)}}else{let c=await s(e,o);if(i)a.push(c?[c]:[]);else{let f=re(c,n);a.push(f)}}}let l=[];for(let o of a)if(o.length!==0)if(l.length===0)l.push(...o);else{let u=l.length-1;l[u]=l[u]+o[0];for(let c=1;c<o.length;c++)l.push(o[c])}return l}async function To(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let s=[];for(let r of t)if(nt(r,e.state.shoptOptions.extglob)){let n=await Xs(e,r);s.push(...n)}else s.push(r);return{values:s,quoted:!1}}async function Xs(e,t){let s=new Pt(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}),r=await s.expand(t);if(r.length>0)return r;if(s.hasFailglob())throw new wt(t);return s.hasNullglob()?[]:[t]}async function ef(e,t,s,r,n,i){let a=s.some(l=>l.type==="Glob");if(!e.state.options.noglob&&a){let l=await i(e,t);if(nt(l,e.state.shoptOptions.extglob)){let u=await Xs(e,l);if(u.length>0&&u[0]!==l)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let o=kr(r);if(!ve(e.state.env)){let u=me(e.state.env);return{values:re(o,u),quoted:!1}}return{values:[o],quoted:!1}}if(!n&&!e.state.options.noglob&&nt(r,e.state.shoptOptions.extglob)){let l=await i(e,t);if(nt(l,e.state.shoptOptions.extglob)){let o=await Xs(e,l);if(o.length>0&&o[0]!==l)return{values:o,quoted:!1}}}if(r===""&&!n)return{values:[],quoted:!1};if(a&&!n){let l=kr(r);if(!ve(e.state.env)){let o=me(e.state.env);return{values:re(l,o),quoted:!1}}return{values:[l],quoted:!1}}return{values:[r],quoted:n}}async function Wo(e,t){let s=t.operation;if(!s||s.type!=="DefaultValue"&&s.type!=="AssignDefault"&&s.type!=="UseAlternative")return null;let r=s.word;if(!r||r.parts.length===0)return null;let n=await st(e,t.parameter),a=await J(e,t.parameter,!1)==="",l=s.checkEmpty??!1,o;return s.type==="UseAlternative"?o=n&&!(l&&a):o=!n||l&&a,o?r.parts:null}function tf(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(s=>s.type==="Literal"):!1}async function sf(e,t){if(t.type!=="ParameterExpansion")return null;let s=await Wo(e,t);if(!s||s.length<=1)return null;let r=s.some(i=>tf(i)),n=s.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&n?s:null}function nf(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?Er(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&Oa(e))}async function Fo(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let d=t[0],h=await Wo(e,d);if(h&&h.length>0&&h.length>1&&h.some(p=>p.type==="DoubleQuoted"||p.type==="SingleQuoted")&&h.some(p=>p.type==="Literal"||p.type==="ParameterExpansion"||p.type==="CommandSubstitution"||p.type==="ArithmeticExpansion"))return Mo(e,h,s,r,n)}let i=[],a=!1;for(let d of t){let h=nf(d),m=d.type==="DoubleQuoted"||d.type==="SingleQuoted",p=h?await sf(e,d):null,y=await n(e,d);i.push({value:y,isSplittable:h,isQuoted:m,mixedDefaultParts:p??void 0}),h&&(a=!0)}if(!a){let d=i.map(h=>h.value).join("");return d?[d]:[]}let l=[],o="",u=!1,c=!1,f=!1;for(let d of i)if(!d.isSplittable)c?d.isQuoted&&d.value===""?(o!==""&&l.push(o),l.push(""),u=!0,o="",c=!1,f=!0):d.value!==""?(o!==""&&l.push(o),o=d.value,c=!1,f=!1):(o+=d.value,f=!1):(o+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let h=await Mo(e,d.mixedDefaultParts,s,r,n);if(h.length!==0)if(h.length===1)o+=h[0],u=!0;else{o+=h[0],l.push(o),u=!0;for(let m=1;m<h.length-1;m++)l.push(h[m]);o=h[h.length-1]}c=!1,f=!1}else{let{words:h,hadLeadingDelimiter:m,hadTrailingDelimiter:p}=Us(d.value,s);if(f&&m&&o===""&&(l.push(""),u=!0),h.length===0)p&&(c=!0);else if(h.length===1)o+=h[0],u=!0,c=p;else{o+=h[0],l.push(o),u=!0;for(let y=1;y<h.length-1;y++)l.push(h[y]);o=h[h.length-1],c=p}f=!1}return o!==""?l.push(o):l.length===0&&u&&l.push(""),l}function rf(e,t){return e.length>0&&t.includes(e[0])}async function Mo(e,t,s,r,n){let i=[];for(let c of t){let d=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),h=await n(e,c);i.push({value:h,isSplittable:d})}let a=[],l="",o=!1,u=!1;for(let c of i)if(!c.isSplittable)u&&c.value!==""?(l!==""&&a.push(l),l=c.value,u=!1):l+=c.value;else{rf(c.value,s)&&l!==""&&(a.push(l),l="",o=!0);let{words:d,hadTrailingDelimiter:h}=Us(c.value,s);if(d.length===0)h&&(u=!0);else if(d.length===1)l+=d[0],o=!0,u=h;else{l+=d[0],a.push(l),o=!0;for(let m=1;m<d.length-1;m++)a.push(d[m]);l=d[d.length-1],u=h}}return l!==""?a.push(l):a.length===0&&o&&a.push(""),a}function Vo(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function zo(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}function _t(e,t,s){if(e.length>t)throw new X(`${s}: string length limit exceeded (${t} bytes)`,"string_length")}async function Ke(e,t,s=!1){let r=[];for(let n of t)r.push(await Ve(e,n,s));return r.join("")}function af(e){return zo(e)}function Bo(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!af(t))return!1;return!0}function of(e,t,s=!1){let r=Vo(t);if(r!==null)return r;switch(t.type){case"TildeExpansion":return s?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 Nr(e,t.pattern);default:return null}}async function V(e,t){return xr(e,t)}async function qo(e,t){let s=[];for(let r of t.parts)if(r.type==="Escaped")s.push(`\\${r.value}`);else if(r.type==="SingleQuoted")s.push(r.value);else if(r.type==="DoubleQuoted"){let n=await Ke(e,r.parts);s.push(n)}else if(r.type==="TildeExpansion"){let n=await Ve(e,r);s.push(ps(n))}else s.push(await Ve(e,r));return s.join("")}async function jo(e,t){let s=[];for(let r of t.parts)if(r.type==="Escaped"){let n=r.value;"()|*?[]".includes(n)?s.push(`\\${n}`):s.push(n)}else if(r.type==="SingleQuoted")s.push(Fe(r.value));else if(r.type==="DoubleQuoted"){let n=await Ke(e,r.parts);s.push(Fe(n))}else s.push(await Ve(e,r));return s.join("")}async function Uo(e,t){let s=[];for(let r of t.parts)if(r.type==="SingleQuoted")s.push(Fe(r.value));else if(r.type==="Escaped"){let n=r.value;"*?[]\\()|".includes(n)?s.push(`\\${n}`):s.push(n)}else if(r.type==="DoubleQuoted"){let n=await Ke(e,r.parts);s.push(Fe(n))}else r.type==="Glob"?no(r.pattern)?s.push(await io(e,r.pattern)):s.push(Nr(e,r.pattern)):r.type==="Literal"?s.push(r.value):s.push(await Ve(e,r));return s.join("")}function Js(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&Js(t.parts))return!0;return!1}var _r=1e5;async function Zo(e,t,s={count:0}){if(s.count>_r)return[[]];let r=[[]];for(let n of t)if(n.type==="BraceExpansion"){let i=[],a=!1,l="";for(let c of n.items)if(c.type==="Range"){let f=Pr(c.start,c.end,c.step,c.startStr,c.endStr);if(f.expanded)for(let d of f.expanded)s.count++,i.push(d);else{a=!0,l=f.literal;break}}else{let f=await Zo(e,c.word.parts,s);for(let d of f){s.count++;let h=[];for(let m of d)typeof m=="string"?h.push(m):h.push(await Ve(e,m));i.push(h.join(""))}}if(a){for(let c of r)s.count++,c.push(l);continue}if(r.length*i.length>e.limits.maxBraceExpansionResults||s.count>_r)return r;let u=[];for(let c of r)for(let f of i){if(s.count++,s.count>_r)return u.length>0?u:r;u.push([...c,f])}r=u}else for(let i of r)s.count++,i.push(n);return r}async function Go(e,t){let s=t.parts;if(!Js(s))return[await V(e,t)];let r=await Zo(e,s),n=[];for(let i of r){let a=[];for(let l of i)typeof l=="string"?a.push(l):a.push(await Ve(e,l));n.push(ao(e,a.join("")))}return n}function lf(){return{expandWordAsync:xr,expandWordForGlobbing:Uo,expandWordWithBracesAsync:Go,expandWordPartsAsync:Ke,expandPart:Ve,expandParameterAsync:Ys,hasBraceExpansion:Js,evaluateArithmetic:T,buildIfsCharClassPattern:Ta,smartWordSplit:Fo}}async function it(e,t){return Lo(e,t,lf())}function cf(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function en(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function r(n){for(let i of n)if(i.type==="DoubleQuoted"){for(let a of i.parts)if(a.type==="ParameterExpansion"&&a.parameter==="@"&&!a.operation)return!0}return!1}return r(t.parts)}async function tn(e,t){if(en(e,t))return{error:`bash: $@: ambiguous redirect
75
- `};let s=t.parts,{hasQuoted:r}=hs(s);if(Js(s)&&(await Go(e,t)).length>1)return{error:`bash: ${s.map(h=>h.type==="Literal"?h.value:h.type==="BraceExpansion"?`{${h.items.map(p=>{if(p.type==="Range"){let y=p.step?`..${p.step}`:"";return`${p.startStr??p.start}..${p.endStr??p.end}${y}`}return p.word.parts.map(y=>y.type==="Literal"?y.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect
76
- `};let n=await xr(e,t),{hasParamExpansion:i,hasCommandSub:a}=hs(s);if((i||a)&&!r&&!ve(e.state.env)){let f=me(e.state.env);if(re(n,f).length>1)return{error:`bash: $${cf(s)}: ambiguous redirect
77
- `}}if(r||e.state.options.noglob)return{target:n};let o=await Uo(e,t);if(!nt(o,e.state.shoptOptions.extglob))return{target:n};let u=new Pt(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}),c=await u.expand(o);return c.length===0?u.hasFailglob()?{error:`bash: no match: ${n}
78
- `}:{target:n}:c.length===1?{target:c[0]}:{error:`bash: ${n}: ambiguous redirect
79
- `}}async function xr(e,t){let s=t.parts,r=s.length;if(r===1){let a=await Ve(e,s[0]);return _t(a,e.limits.maxStringLength,"word expansion"),a}let n=[];for(let a=0;a<r;a++)n.push(await Ve(e,s[a]));let i=n.join("");return _t(i,e.limits.maxStringLength,"word expansion"),i}async function Ve(e,t,s=!1){if(t.type==="ParameterExpansion")return Ys(e,t,s);let r=of(e,t,s);if(r!==null)return r;switch(t.type){case"DoubleQuoted":{let n=[];for(let i of t.parts)n.push(await Ve(e,i,!0));return n.join("")}case"CommandSubstitution":{let n=Ba(t.body);if(n)try{let d=await V(e,n.target),h=d.startsWith("/")?d:`${e.state.cwd}/${d}`,m=await e.fs.readFile(h);e.state.lastExitCode=0,e.state.env.set("?","0");let p=m.replace(/\n+$/,"");return _t(p,e.limits.maxStringLength,"command substitution"),p}catch(d){if(d instanceof X)throw d;return e.state.lastExitCode=1,e.state.env.set("?","1"),""}let i=e.substitutionDepth??0,a=e.limits.maxSubstitutionDepth;if(i>=a)throw new X(`Command substitution nesting limit exceeded (${a})`,"substitution_depth");let l=e.substitutionDepth;e.substitutionDepth=i+1;let o=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let u=new Map(e.state.env),c=e.state.cwd,f=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let d=await e.executeScript(t.body),h=d.exitCode;e.state.env=u,e.state.cwd=c,e.state.suppressVerbose=f,e.state.lastExitCode=h,e.state.env.set("?",String(h)),d.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+d.stderr),e.state.bashPid=o,e.substitutionDepth=l;let m=d.stdout.replace(/\n+$/,"");return _t(m,e.limits.maxStringLength,"command substitution"),m}catch(d){if(e.state.env=u,e.state.cwd=c,e.state.bashPid=o,e.substitutionDepth=l,e.state.suppressVerbose=f,d instanceof X)throw d;if(d instanceof Z){e.state.lastExitCode=d.exitCode,e.state.env.set("?",String(d.exitCode)),d.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+d.stderr);let h=d.stdout.replace(/\n+$/,"");return _t(h,e.limits.maxStringLength,"command substitution"),h}throw d}}case"ArithmeticExpansion":{let n=t.expression.originalText;if(n&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(n)){let a=await za(e,n),l=new q,o=Y(l,a);return String(await T(e,o.expression,!0))}return String(await T(e,t.expression.expression,!0))}case"BraceExpansion":{let n=[];for(let i of t.items)if(i.type==="Range"){let a=Pr(i.start,i.end,i.step,i.startStr,i.endStr);if(a.expanded)n.push(...a.expanded);else return a.literal}else n.push(await V(e,i.word));return n.join(" ")}default:return""}}async function Ys(e,t,s=!1){let{parameter:r}=t,{operation:n}=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 p=await $r(e,h);r=`${d}[${p}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&te(e,r)){let d=$e(e,r);if(d&&d!==r){let h=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(h){let[,m,p]=h;if(e.state.associativeArrays?.has(m)||p.includes("$(")||p.includes("`")||p.includes("${")){let b=await $r(e,p);r=`${m}[${b}]`}}}}let a=n&&(n.type==="DefaultValue"||n.type==="AssignDefault"||n.type==="UseAlternative"||n.type==="ErrorIfUnset"),l=await J(e,r,!a);if(!n)return l;let o=!await st(e,r),{isEmpty:u,effectiveValue:c}=so(e,r,l,s),f={value:l,isUnset:o,isEmpty:u,effectiveValue:c,inDoubleQuotes:s};switch(n.type){case"DefaultValue":return qa(e,n,f,Ke);case"AssignDefault":return ja(e,r,n,f,Ke);case"ErrorIfUnset":return Ua(e,r,n,f,Ke);case"UseAlternative":return Za(e,n,f,Ke);case"PatternRemoval":{let d=await Ga(e,l,n,Ke,Ve);return _t(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await Ha(e,l,n,Ke,Ve);return _t(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return Qa(e,r,l);case"LengthSliceError":throw new Me(r);case"BadSubstitution":throw new Me(n.text);case"Substring":return Ka(e,r,l,n);case"CaseModification":{let d=await Xa(e,l,n,Ke,Ys);return _t(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return Ya(e,r,l,o,n);case"Indirection":return Ja(e,r,l,o,n,Ys,s);case"ArrayKeys":return eo(e,n);case"VarNamePrefix":return to(e,n);default:return l}}function uf(e,t,s){switch(s){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new se("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new se("division by 0");return e%t;case"**":if(t<0)throw new se("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 Ho(e,t,s){switch(s){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 ff(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function df(e,t){let s=e.state.env.get(t);if(s!==void 0)return s;let r=e.state.env.get(`${t}_0`);return r!==void 0?r:await J(e,t)}function hf(e){if(!e)return 0;let t=Number.parseInt(e,10);if(!Number.isNaN(t)&&/^-?\d+$/.test(e.trim()))return t;let s=e.trim();if(!s)return 0;try{let r=new q,{expr:n,pos:i}=We(r,s,0);if(i<s.length){let a=s.slice(i).trim().split(/\s+/)[0];throw new se(`${s}: syntax error in expression (error token is "${a}")`)}return n.type==="ArithNumber"?n.value:t||0}catch(r){if(r instanceof se)throw r;let n=s.split(/\s+/).slice(1)[0]||s;throw new se(`${s}: syntax error in expression (error token is "${n}")`)}}async function Cr(e,t){if(!t)return 0;let s=Number.parseInt(t,10);if(!Number.isNaN(s)&&/^-?\d+$/.test(t.trim()))return s;let r=t.trim();if(!r)return 0;let n=new q,{expr:i,pos:a}=We(n,r,0);if(a<r.length){let l=r.slice(a).trim(),o=l.split(/\s+/)[0]||l;throw new se(`syntax error in expression (error token is "${o}")`,"","")}return await T(e,i)}async function Dr(e,t,s=new Set,r=0){if(r>100)throw new se("maximum variable indirection depth exceeded");if(s.has(t))return 0;s.add(t);let n=await df(e,t);if(!n)return 0;let i=Number.parseInt(n,10);if(!Number.isNaN(i)&&/^-?\d+$/.test(n.trim()))return i;let a=n.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return await Dr(e,a,s,r+1);let l=new q,{expr:o,pos:u}=We(l,a,0);if(u<a.length){let c=a.slice(u).trim(),f=c.split(/\s+/)[0]||c;throw new se(`${a}: syntax error in expression (error token is "${f}")`)}return await T(e,o)}async function sn(e,t){if(t.startsWith("#")){let f=t.slice(1),d=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(d){let m=d[1],p=B(e,m);return String(p.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 s=[":-",":=",":?",":+","-","=","?","+"],r=-1,n="";for(let f of s){let d=t.indexOf(f);d>0&&(r===-1||d<r)&&(r=d,n=f)}if(r===-1)return await J(e,t);let i=t.slice(0,r),a=t.slice(r+n.length),l=e.state.env.get(i),o=l===void 0,u=l==="",c=n.startsWith(":");switch(n){case":-":case"-":return o||c&&u?a:l||"";case":=":case"=":return o||c&&u?(e.state.env.set(i,a),a):l||"";case":+":case"+":return!(o||c&&u)?a:"";case":?":case"?":{if(o||c&&u)throw new Error(a||`${i}: parameter null or not set`);return l||""}default:return l||""}}async function T(e,t,s=!1){switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new se("value too great for base");return t.value;case"ArithVariable":return await Dr(e,t.name);case"ArithSpecialVar":{let n=(await J(e,t.name)).trim();if(!n)return 0;let i=Number.parseInt(n,10);if(!Number.isNaN(i)&&/^-?\d+$/.test(n))return i;let a=new q,{expr:l}=We(a,n,0);return await T(e,l)}case"ArithNested":return await T(e,t.expression);case"ArithCommandSubst":{if(e.execFn){let r=await e.execFn(t.command,{signal:e.state.signal});r.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+r.stderr);let n=r.stdout.trim();return Number.parseInt(n,10)||0}return 0}case"ArithBracedExpansion":{let r=await sn(e,t.content);return Number.parseInt(r,10)||0}case"ArithDynamicBase":{let r=await sn(e,t.baseExpr),n=Number.parseInt(r,10);if(n<2||n>64)return 0;let i=`${n}#${t.value}`;return us(i)}case"ArithDynamicNumber":{let n=await sn(e,t.prefix)+t.suffix;return us(n)}case"ArithArrayElement":{let r=e.state.associativeArrays?.has(t.array),n=async i=>{let a=e.state.env.get(i);return a!==void 0?await Cr(e,a):0};if(t.stringKey!==void 0)return await n(`${t.array}_${t.stringKey}`);if(r&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await n(`${t.array}_${t.index.name}`);if(r&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let i=await J(e,t.index.name);return await n(`${t.array}_${i}`)}if(t.index){let i=await T(e,t.index,s);if(i<0){let o=B(e,t.array),u=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript
80
- `,0;let f=Math.max(...o.map(([d])=>typeof d=="number"?d:0))+1+i;if(f<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript
81
- `,0;i=f}let a=`${t.array}_${i}`,l=e.state.env.get(a);if(l!==void 0)return Cr(e,l);if(i===0){let o=e.state.env.get(t.array);if(o!==void 0)return Cr(e,o)}if(e.state.options.nounset&&!Array.from(e.state.env.keys()).some(u=>u===t.array||u.startsWith(`${t.array}_`)))throw new Le(`${t.array}[${i}]`);return 0}return 0}case"ArithDoubleSubscript":throw new se("double subscript","","");case"ArithNumberSubscript":throw new se(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new se(t.message,"","",!0);case"ArithSingleQuote":{if(s)throw new se(`syntax error: operand expected (error token is "'${t.content}'")`);return t.value}case"ArithBinary":{if(t.operator==="||")return await T(e,t.left,s)||await T(e,t.right,s)?1:0;if(t.operator==="&&")return await T(e,t.left,s)&&await T(e,t.right,s)?1:0;let r=await T(e,t.left,s),n=await T(e,t.right,s);return uf(r,n,t.operator)}case"ArithUnary":{let r=await T(e,t.operand,s);if(t.operator==="++"||t.operator==="--"){if(t.operand.type==="ArithVariable"){let n=t.operand.name,i=Number.parseInt(await J(e,n),10)||0,a=t.operator==="++"?i+1:i-1;return e.state.env.set(n,String(a)),t.prefix?a:i}if(t.operand.type==="ArithArrayElement"){let n=t.operand.array,i=e.state.associativeArrays?.has(n),a;if(t.operand.stringKey!==void 0)a=`${n}_${t.operand.stringKey}`;else if(i&&t.operand.index?.type==="ArithVariable"&&!t.operand.index.hasDollarPrefix)a=`${n}_${t.operand.index.name}`;else if(i&&t.operand.index?.type==="ArithVariable"&&t.operand.index.hasDollarPrefix){let u=await J(e,t.operand.index.name);a=`${n}_${u}`}else if(t.operand.index){let u=await T(e,t.operand.index,s);a=`${n}_${u}`}else return r;let l=Number.parseInt(e.state.env.get(a)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(a,String(o)),t.prefix?o:l}if(t.operand.type==="ArithConcat"){let n="";for(let i of t.operand.parts)n+=await Gt(e,i,s);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let i=Number.parseInt(e.state.env.get(n)||"0",10)||0,a=t.operator==="++"?i+1:i-1;return e.state.env.set(n,String(a)),t.prefix?a:i}}if(t.operand.type==="ArithDynamicElement"){let n="";if(t.operand.nameExpr.type==="ArithConcat")for(let i of t.operand.nameExpr.parts)n+=await Gt(e,i,s);else t.operand.nameExpr.type==="ArithVariable"&&(n=t.operand.nameExpr.hasDollarPrefix?await J(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let i=await T(e,t.operand.subscript,s),a=`${n}_${i}`,l=Number.parseInt(e.state.env.get(a)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(a,String(o)),t.prefix?o:l}}return r}return ff(r,t.operator)}case"ArithTernary":return await T(e,t.condition,s)?await T(e,t.consequent,s):await T(e,t.alternate,s);case"ArithAssignment":{let r=t.variable,n=r;if(t.stringKey!==void 0)n=`${r}_${t.stringKey}`;else if(t.subscript){let o=e.state.associativeArrays?.has(r);if(o&&t.subscript.type==="ArithVariable"&&!t.subscript.hasDollarPrefix)n=`${r}_${t.subscript.name}`;else if(o&&t.subscript.type==="ArithVariable"&&t.subscript.hasDollarPrefix){let u=await J(e,t.subscript.name);n=`${r}_${u||"\\"}`}else if(o){let u=await T(e,t.subscript,s);n=`${r}_${u}`}else{let u=await T(e,t.subscript,s);if(u<0){let c=B(e,r);c.length>0&&(u=Math.max(...c.map(([d])=>typeof d=="number"?d:0))+1+u)}n=`${r}_${u}`}}let i=Number.parseInt(e.state.env.get(n)||"0",10)||0,a=await T(e,t.value,s),l=Ho(i,a,t.operator);return e.state.env.set(n,String(l)),l}case"ArithGroup":return await T(e,t.expression,s);case"ArithConcat":{let r="";for(let n of t.parts)r+=await Gt(e,n,s);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)?await Dr(e,r):Number.parseInt(r,10)||0}case"ArithDynamicAssignment":{let r="";if(t.target.type==="ArithConcat")for(let o of t.target.parts)r+=await Gt(e,o,s);else t.target.type==="ArithVariable"&&(r=t.target.hasDollarPrefix?await J(e,t.target.name):t.target.name);if(!r||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r))return 0;let n=r;if(t.subscript){let o=await T(e,t.subscript,s);n=`${r}_${o}`}let i=Number.parseInt(e.state.env.get(n)||"0",10)||0,a=await T(e,t.value,s),l=Ho(i,a,t.operator);return e.state.env.set(n,String(l)),l}case"ArithDynamicElement":{let r="";if(t.nameExpr.type==="ArithConcat")for(let l of t.nameExpr.parts)r+=await Gt(e,l,s);else t.nameExpr.type==="ArithVariable"&&(r=t.nameExpr.hasDollarPrefix?await J(e,t.nameExpr.name):t.nameExpr.name);if(!r||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r))return 0;let n=await T(e,t.subscript,s),i=`${r}_${n}`,a=e.state.env.get(i);return a!==void 0?hf(a):0}default:return 0}}async function Gt(e,t,s=!1){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await T(e,t,s));case"ArithVariable":return t.hasDollarPrefix?await J(e,t.name):t.name;case"ArithSpecialVar":return await J(e,t.name);case"ArithBracedExpansion":return await sn(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command,{signal:e.state.signal})).stdout.trim():"0";case"ArithConcat":{let r="";for(let n of t.parts)r+=await Gt(e,n,s);return r}default:return String(await T(e,t,s))}}async function Qo(e,t){let s=t.parts.map(c=>c.type==="Literal"?c.value:"\0").join(""),r=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!r||!s.endsWith(")"))return null;let n=r[1],i=[],a=!1,l="",o=!1;for(let c of t.parts)if(c.type==="Literal"){let f=c.value;if(!a){let d=f.indexOf("=(");d!==-1&&(a=!0,f=f.slice(d+2))}if(a){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(l||o)&&(i.push(l),l="",o=!1):h&&(l+=h)}}else if(a)if(c.type==="BraceExpansion")if(/^\[.+\]=/.test(l))l+=Ut({type:"Word",parts:[c]});else{(l||o)&&(i.push(l),l="",o=!1);let d=await it(e,{type:"Word",parts:[c]});i.push(...d.values)}else{(c.type==="SingleQuoted"||c.type==="DoubleQuoted"||c.type==="Escaped")&&(o=!0);let f=await V(e,{type:"Word",parts:[c]});l+=f}(l||o)&&i.push(l);let u=i.map(c=>/^\[.+\]=/.test(c)?c:c===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(c)&&!c.startsWith("'")&&!c.startsWith('"')?`'${c.replace(/'/g,"'\\''")}'`:c);return`${n}=(${u.join(" ")})`}async function Ko(e,t){let s=-1,r=-1,n=!1;for(let p=0;p<t.parts.length;p++){let y=t.parts[p];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)){s=p,r=b,n=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(E)){s=p,r=b,n=!0;break}}let v=y.value.indexOf("=");if(v!==-1&&(v===0||y.value[v-1]!=="+")){let E=y.value.slice(0,v);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(E)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(E)){s=p,r=v;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),a=t.parts[s];if(a.type!=="Literal")return null;let l=n?2:1,o=a.value.slice(0,r),u=a.value.slice(r+l),c=t.parts.slice(s+1),f="";for(let p of i)f+=await V(e,{type:"Word",parts:[p]});f+=o;let d={type:"Word",parts:u!==""?[{type:"Literal",value:u},...c]:c},h=d.parts.length>0?await V(e,d):"";return`${f}${n?"+=":"="}${h}`}var pf=["tar","yq","xan","sqlite3","python3","python"];function Xo(e){return pf.includes(e)}var K=Object.freeze({stdout:"",stderr:"",exitCode:0});function H(e=""){return{stdout:e,stderr:"",exitCode:0}}function N(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function _(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function pe(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function at(e,t,s="",r=""){throw new X(e,t,s,r)}function Ae(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new X(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function Rr(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Et;return K}if(t.length>1)throw new Z(1,"",`bash: break: too many arguments
82
- `);let s=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new Z(128,"",`bash: break: ${t[0]}: numeric argument required
83
- `);s=r}throw new Oe(s)}async function Ir(e,t){let s,r=!1,n=!1,i=0;for(;i<t.length;)if(t[i]==="--"){i++;break}else if(t[i]==="-L")n=!1,i++;else if(t[i]==="-P")n=!0,i++;else if(t[i].startsWith("-")&&t[i]!=="-")i++;else break;let a=t.slice(i);if(a.length===0||a[0]==="~"?s=e.state.env.get("HOME")||"/":a[0]==="-"?(s=e.state.previousDir,r=!0):s=a[0],!s.startsWith("/")&&!s.startsWith("./")&&!s.startsWith("../")&&s!=="."&&s!==".."){let f=e.state.env.get("CDPATH");if(f){let d=f.split(":").filter(h=>h);for(let h of d){let m=h.startsWith("/")?`${h}/${s}`:`${e.state.cwd}/${h}/${s}`;try{if((await e.fs.stat(m)).isDirectory){s=m,r=!0;break}}catch{}}}}let o=(s.startsWith("/")?s:`${e.state.cwd}/${s}`).split("/").filter(f=>f&&f!=="."),u="";for(let f of o)if(f==="..")u=u.split("/").slice(0,-1).join("/")||"/";else{u=u?`${u}/${f}`:`/${f}`;try{if(!(await e.fs.stat(u)).isDirectory)return N(`bash: cd: ${s}: Not a directory
84
- `)}catch{return N(`bash: cd: ${s}: No such file or directory
85
- `)}}let c=u||"/";if(n)try{c=await e.fs.realpath(c)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=c,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),H(r?`${c}
86
- `:"")}function Or(e,t){return e.fs.resolvePath(e.state.cwd,t)}var mf=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function nn(e){return mf.includes(e)}async function rn(e,t,s){let r=Or(e,s);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 gf=["-nt","-ot","-ef"];function an(e){return gf.includes(e)}async function on(e,t,s,r){let n=Or(e,s),i=Or(e,r);switch(t){case"-nt":try{let a=await e.fs.stat(n),l=await e.fs.stat(i);return a.mtime>l.mtime}catch{return!1}case"-ot":try{let a=await e.fs.stat(n),l=await e.fs.stat(i);return a.mtime<l.mtime}catch{return!1}case"-ef":try{if(!await e.fs.exists(n)||!await e.fs.exists(i))return!1;let a=e.fs.resolvePath(e.state.cwd,n),l=e.fs.resolvePath(e.state.cwd,i);return a===l}catch{return!1}default:return!1}}var yf=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function ln(e){return yf.has(e)}function cn(e,t,s){switch(e){case"-eq":return t===s;case"-ne":return t!==s;case"-lt":return t<s;case"-le":return t<=s;case"-gt":return t>s;case"-ge":return t>=s}}function gs(e){return e==="="||e==="=="||e==="!="}function un(e,t,s,r=!1,n=!1,i=!1){if(r){let l=Ht(t,s,n,i);return e==="!="?!l:l}if(n){let l=t.toLowerCase()===s.toLowerCase();return e==="!="?!l:l}let a=t===s;return e==="!="?!a:a}var wf=new Set(["-z","-n"]);function fn(e){return wf.has(e)}function dn(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function hn(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let r=s[1],n=s[2];if(e.state.associativeArrays?.has(r)){let l=n;return(l.startsWith("'")&&l.endsWith("'")||l.startsWith('"')&&l.endsWith('"'))&&(l=l.slice(1,-1)),l=l.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(o,u)=>e.state.env.get(u)||""),e.state.env.has(`${r}_${l}`)}let a;try{let l=new q,o=Y(l,n);a=await T(e,o.expression)}catch{if(/^-?\d+$/.test(n))a=Number.parseInt(n,10);else{let l=e.state.env.get(n);a=l?Number.parseInt(l,10):0}}if(a<0){let l=he(e,r),o=e.state.currentLine;if(l.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${o}: ${r}: bad array subscript
87
- `,!1;if(a=Math.max(...l)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${o}: ${r}: bad array subscript
88
- `,!1}return e.state.env.has(`${r}_${a}`)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?Ge(e,t).length>0:he(e,t).length>0}async function xt(e,t){switch(t.type){case"CondBinary":{let s=await V(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!=="=~"),n;if(t.operator==="=~")if(r){let i=await V(e,t.right);n=ps(i)}else n=await qo(e,t.right);else gs(t.operator)&&!r?n=await jo(e,t.right):n=await V(e,t.right);if(gs(t.operator)){let i=e.state.shoptOptions.nocasematch;return un(t.operator,s,n,!r,i,!0)}if(ln(t.operator))return cn(t.operator,await Jo(e,s),await Jo(e,n));if(an(t.operator))return on(e,t.operator,s,n);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=Sf(n),o=le(a,i?"i":"").match(s);if(tt(e,"BASH_REMATCH"),o)for(let u=0;u<o.length;u++)e.state.env.set(`BASH_REMATCH_${u}`,o[u]||"");return o!==null}catch{throw new Error("syntax error in regular expression")}case"<":return s<n;case">":return s>n;default:return!1}}case"CondUnary":{let s=await V(e,t.operand);return nn(t.operator)?rn(e,t.operator,s):fn(t.operator)?dn(t.operator,s):t.operator==="-v"?await hn(e,s):t.operator==="-o"?Lr(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await V(e,t.operand.expression.word)})`!=="":!await xt(e,t.operand);case"CondAnd":return await xt(e,t.left)?await xt(e,t.right):!1;case"CondOr":return await xt(e,t.left)?!0:await xt(e,t.right);case"CondGroup":return await xt(e,t.expression);case"CondWord":return await V(e,t.word)!=="";default:return!1}}async function ys(e,t){if(t.length===0)return _("","",1);if(t.length===1)return pe(!!t[0]);if(t.length===2){let r=t[0],n=t[1];return r==="("?N(`test: '(' without matching ')'
89
- `,2):nn(r)?pe(await rn(e,r,n)):fn(r)?pe(dn(r,n)):r==="!"?pe(!n):r==="-v"?pe(await hn(e,n)):r==="-o"?pe(Lr(e,n)):r==="="||r==="=="||r==="!="||r==="<"||r===">"||r==="-eq"||r==="-ne"||r==="-lt"||r==="-le"||r==="-gt"||r==="-ge"||r==="-nt"||r==="-ot"||r==="-ef"?N(`test: ${r}: unary operator expected
90
- `,2):_("","",1)}if(t.length===3){let r=t[0],n=t[1],i=t[2];if(gs(n))return pe(un(n,r,i));if(ln(n)){let a=pn(r),l=pn(i);return!a.valid||!l.valid?_("","",2):pe(cn(n,a.value,l.value))}if(an(n))return pe(await on(e,n,r,i));switch(n){case"-a":return pe(r!==""&&i!=="");case"-o":return pe(r!==""||i!=="");case">":return pe(r>i);case"<":return pe(r<i)}if(r==="!"){let a=await ys(e,[n,i]);return _("",a.stderr,a.exitCode===0?1:a.exitCode===1?0:a.exitCode)}if(r==="("&&i===")")return pe(n!=="")}if(t.length===4){if(t[0]==="!"){let r=await ys(e,t.slice(1));return _("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(t[0]==="("&&t[3]===")")return ys(e,[t[1],t[2]])}let s=await tl(e,t,0);return s.pos<t.length?N(`test: too many arguments
91
- `,2):pe(s.value)}async function tl(e,t,s){return Ef(e,t,s)}async function Ef(e,t,s){let{value:r,pos:n}=await Yo(e,t,s);for(;t[n]==="-o";){let i=await Yo(e,t,n+1);r=r||i.value,n=i.pos}return{value:r,pos:n}}async function Yo(e,t,s){let{value:r,pos:n}=await Tr(e,t,s);for(;t[n]==="-a";){let i=await Tr(e,t,n+1);r=r&&i.value,n=i.pos}return{value:r,pos:n}}async function Tr(e,t,s){if(t[s]==="!"){let{value:r,pos:n}=await Tr(e,t,s+1);return{value:!r,pos:n}}return bf(e,t,s)}async function bf(e,t,s){let r=t[s];if(r==="("){let{value:i,pos:a}=await tl(e,t,s+1);return{value:i,pos:t[a]===")"?a+1:a}}let n=t[s+1];if(gs(n)){let i=r,a=t[s+2]??"";return{value:un(n,i,a),pos:s+3}}if(ln(n)){let i=pn(r),a=pn(t[s+2]??"0");return!i.valid||!a.valid?{value:!1,pos:s+3}:{value:cn(n,i.value,a.value),pos:s+3}}if(an(n)){let i=r,a=t[s+2]??"";return{value:await on(e,n,i,a),pos:s+3}}if(nn(r)){let i=t[s+1]??"";return{value:await rn(e,r,i),pos:s+2}}if(fn(r)){let i=t[s+1]??"";return{value:dn(r,i),pos:s+2}}if(r==="-v"){let i=t[s+1]??"";return{value:await hn(e,i),pos:s+2}}if(r==="-o"){let i=t[s+1]??"";return{value:Lr(e,i),pos:s+2}}return{value:r!==void 0&&r!=="",pos:s+1}}function Ht(e,t,s=!1,r=!1){let n=`^${sl(t,r)}$`;return le(n,s?"is":"s").test(e)}function sl(e,t){let s="";for(let r=0;r<e.length;r++){let n=e[r];if(t&&(n==="@"||n==="*"||n==="+"||n==="?"||n==="!")&&r+1<e.length&&e[r+1]==="("){let i=nl(e,r+1);if(i!==-1){let a=e.slice(r+2,i),l=rl(a),o=l.map(c=>sl(c,t)),u=o.length>0?o.join("|"):"(?:)";if(n==="@")s+=`(?:${u})`;else if(n==="*")s+=`(?:${u})*`;else if(n==="+")s+=`(?:${u})+`;else if(n==="?")s+=`(?:${u})?`;else if(n==="!")if(i<e.length-1){let f=l.map(h=>il(h,t));if(f.every(h=>h!==null)&&f.every(h=>h===f[0])&&f[0]!==null){let h=f[0];if(h===0)s+="(?:.+)";else{let m=[];h>0&&m.push(`.{0,${h-1}}`),m.push(`.{${h+1},}`),m.push(`(?!(?:${u})).{${h}}`),s+=`(?:${m.join("|")})`}}else s+=`(?:(?!(?:${u})).)*?`}else s+=`(?!(?:${u})$).*`;r=i;continue}}if(n==="\\")if(r+1<e.length){let i=e[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,r++}else s+="\\\\";else if(n==="*")s+=".*";else if(n==="?")s+=".";else if(n==="["){let i=e.indexOf("]",r+1);i!==-1?(s+=e.slice(r,i+1),r=i):s+="\\["}else/[\\^$.|+(){}]/.test(n)?s+=`\\${n}`:s+=n}return s}function nl(e,t){let s=1,r=t+1;for(;r<e.length&&s>0;){let n=e[r];if(n==="\\"){r+=2;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function rl(e){let t=[],s="",r=0,n=0;for(;n<e.length;){let i=e[n];if(i==="\\"){s+=i,n+1<e.length?(s+=e[n+1],n+=2):n++;continue}i==="("?(r++,s+=i):i===")"?(r--,s+=i):i==="|"&&r===0?(t.push(s),s=""):s+=i,n++}return t.push(s),t}function il(e,t){let s=0,r=0;for(;r<e.length;){let n=e[r];if(t&&(n==="@"||n==="*"||n==="+"||n==="?"||n==="!")&&r+1<e.length&&e[r+1]==="("){let i=nl(e,r+1);if(i!==-1){if(n==="@"){let a=e.slice(r+2,i),o=rl(a).map(u=>il(u,t));if(o.every(u=>u!==null)&&o.every(u=>u===o[0])){s+=o[0],r=i+1;continue}return null}return null}}if(n==="*")return null;if(n==="?"){s+=1,r++;continue}if(n==="["){let i=e.indexOf("]",r+1);if(i!==-1){s+=1,r=i+1;continue}s+=1,r++;continue}if(n==="\\"){s+=1,r+=2;continue}s+=1,r++}return s}function Lr(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 Jo(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 el(t);try{let s=new q,r=Y(s,t);return await T(e,r.expression)}catch{return el(t)}}function vf(e,t){let s=0;for(let r of e){let n;if(r>="0"&&r<="9")n=r.charCodeAt(0)-48;else if(r>="a"&&r<="z")n=r.charCodeAt(0)-97+10;else if(r>="A"&&r<="Z")n=r.charCodeAt(0)-65+36;else if(r==="@")n=62;else if(r==="_")n=63;else return Number.NaN;if(n>=t)return Number.NaN;s=s*t+n}return s}function el(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 s,r=e.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(r){let n=Number.parseInt(r[1],10);n>=2&&n<=64?s=vf(r[2],n):s=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?s=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?s=Number.parseInt(e,8):s=Number.parseInt(e,10);return Number.isNaN(s)&&(s=0),t?-s:s}function pn(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 s=Number.parseInt(e,10);return Number.isNaN(s)?{value:0,valid:!1}:{value:t?-s:s,valid:!0}}function Sf(e){let t="",s=0;for(;s<e.length;)if(e[s]==="\\"&&s+1<e.length)t+=e[s]+e[s+1],s+=2;else if(e[s]==="["){let r=Af(e,s);t+=r.converted,s=r.endIndex}else t+=e[s],s++;return t}function Af(e,t){let s=t+1,r="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(r+="^",s++);let n=!1;s<e.length&&e[s]==="]"&&(n=!0,s++);let i=!1;s<e.length&&e[s]==="["&&s+1<e.length&&e[s+1]!==":"&&(i=!0,s++);let a="",l=!1;for(;s<e.length;){let o=e[s];if(o==="]"){l=!0,s++;break}if(o==="["&&s+1<e.length&&e[s+1]===":"){let u=e.indexOf(":]",s+2);if(u!==-1){let c=e.slice(s+2,u);a+=$f(c),s=u+2;continue}}if(o==="["&&s+1<e.length){let u=e[s+1];if(u==="."||u==="="){let c=`${u}]`,f=e.indexOf(c,s+2);if(f!==-1){let d=e.slice(s+2,f);a+=d,s=f+2;continue}}}if(o==="\\"&&s+1<e.length){a+=o+e[s+1],s+=2;continue}a+=o,s++}return l?(n&&(r+="\\]"),i&&(r+="\\["),r+=a,r+="]",{converted:r,endIndex:s}):{converted:"\\[",endIndex:t+1}}function $f(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 ot(e){let t=[],s="",r=!1,n=!1,i=!1,a=!1;for(let l of e){if(i){s+=l,i=!1,a=!0;continue}if(l==="\\"){i=!0;continue}if(l==="'"&&!n){r||(a=!0),r=!r;continue}if(l==='"'&&!r){n||(a=!0),n=!n;continue}if((l===" "||l===" "||l===`
92
- `)&&!r&&!n){a&&(t.push(s),s="",a=!1);continue}s+=l,a=!0}return a&&t.push(s),t}function mn(e){let t=[],s=0;for(;s<e.length;){for(;s<e.length&&/\s/.test(e[s]);)s++;if(s>=e.length)break;if(e[s]!=="["){s++;continue}s++;let r="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)r+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&e[s]!=="]"&&e[s]!=="=";)r+=e[s],s++;for(;s<e.length&&e[s]!=="]";)s++;if(e[s]==="]"&&s++,e[s]!=="=")continue;s++;let n="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)e[s]==="\\"&&s+1<e.length&&s++,n+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&!/\s/.test(e[s]);)n+=e[s],s++;t.push([r,n])}return t}function al(e){let t=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(t)return{name:t[1],isArray:!0,arrayElements:ot(t[2])};let s=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(s)return{name:s[1],isArray:!1,arrayIndex:s[2],value:s[3]};if(e.includes("=")){let r=e.indexOf("=");return{name:e.slice(0,r),isArray:!1,value:e.slice(r+1)}}return{name:e,isArray:!1}}async function Pf(e,t){try{let s=new q,r=Y(s,t);return await T(e,r.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}async function ol(e,t,s={}){let{name:r,isArray:n,arrayElements:i,value:a,arrayIndex:l}=t,{makeReadonly:o=!1,checkReadonly:u=!0}=s;if(u){let c=ye(e,r);if(c)return c}if(n&&i){for(let c=0;c<i.length;c++)e.state.env.set(`${r}_${c}`,i[c]);e.state.env.set(`${r}__length`,String(i.length))}else if(l!==void 0&&a!==void 0){let c=await Pf(e,l);e.state.env.set(`${r}_${c}`,a);let f=parseInt(e.state.env.get(`${r}__length`)??"0",10);c>=f&&e.state.env.set(`${r}__length`,String(c+1))}else a!==void 0&&e.state.env.set(r,a);return o&&De(e,r),null}function Ct(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function Qt(e,t){return e.state.localVarDepth?.get(t)}function gn(e,t){e.state.localVarDepth?.delete(t)}function ll(e,t,s){e.state.localVarStack=e.state.localVarStack||new Map;let r=e.state.localVarStack.get(t)||[];r.push({value:s,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,r)}function yn(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function cl(e,t){if(e.state.localVarStack)for(let[s,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(s)}}var Mr=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function ul(e){return Mr.has(e)}var Wr=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Kt=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"]);async function wn(e,t,s,r){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory
93
- `;if(r.checkNoclobber&&e.state.options.noclobber&&!r.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file
94
- `}catch{}return null}function Xt(e){let s=Math.min(e.length,8192);for(let r=0;r<s;r++)if(e.charCodeAt(r)>127)return"utf8";return"binary"}function kf(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let r=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(r)||r<0)return null;let n=s+1,i=t.slice(n,n+r),a=n+r+1,l=t.slice(a),o=l.indexOf(":");if(o===-1)return null;let u=Number.parseInt(l.slice(0,o),10);if(Number.isNaN(u)||u<0)return null;let c=l.slice(o+1);return{path:i,position:u,content:c}}async function fl(e,t){let s=new Map;for(let r=0;r<t.length;r++){let n=t[r];if(n.target.type==="HereDoc")continue;if(n.operator===">&"||n.operator==="<&"){if(en(e,n.target))return{targets:s,error:`bash: $@: ambiguous redirect
95
- `};s.set(r,await V(e,n.target))}else{let a=await tn(e,n.target);if("error"in a)return{targets:s,error:a.error};s.set(r,a.target)}}return{targets:s}}function Nf(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd,s=e.limits.maxFileDescriptors;if(t>=s)throw new Error(`bash: cannot allocate file descriptor: too many open files (max ${s})`);return e.state.nextFd++,t}async function En(e,t){for(let s of t){if(!s.fdVariable)continue;if(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),(s.operator===">&"||s.operator==="<&")&&s.target.type==="Word"&&await V(e,s.target)==="-"){let i=e.state.env.get(s.fdVariable);if(i!==void 0){let a=Number.parseInt(i,10);Number.isNaN(a)||e.state.fileDescriptors.delete(a)}continue}let r=Nf(e);if(e.state.env.set(s.fdVariable,String(r)),s.target.type==="Word"){let n=await V(e,s.target);if(s.operator===">&"||s.operator==="<&"){let i=Number.parseInt(n,10);if(!Number.isNaN(i)){let a=e.state.fileDescriptors.get(i);a!==void 0&&(Ae(e),e.state.fileDescriptors.set(r,a));continue}}if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let i=e.fs.resolvePath(e.state.cwd,n);(s.operator===">"||s.operator===">|"||s.operator==="&>")&&await e.fs.writeFile(i,"","binary"),Ae(e),e.state.fileDescriptors.set(r,`__file__:${i}`)}else if(s.operator==="<<<")Ae(e),e.state.fileDescriptors.set(r,`${n}
96
- `);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,n),a=await e.fs.readFile(i);Ae(e),e.state.fileDescriptors.set(r,a)}catch{return _("",`bash: ${n}: No such file or directory
97
- `,1)}}}return null}async function lt(e,t){for(let s of t){if(s.target.type==="HereDoc")continue;let r=s.operator===">&";if(s.operator!==">"&&s.operator!==">|"&&s.operator!=="&>"&&!r)continue;let n;if(r){if(n=await V(e,s.target),n==="-"||!Number.isNaN(Number.parseInt(n,10))||s.fd!=null)continue}else{let l=await tn(e,s.target);if("error"in l)return _("",l.error,1);n=l.target}let i=e.fs.resolvePath(e.state.cwd,n),a=s.operator===">|";if(i.includes("\0"))return _("",`bash: ${n}: No such file or directory
98
- `,1);try{let l=await e.fs.stat(i);if(l.isDirectory)return _("",`bash: ${n}: Is a directory
99
- `,1);if(e.state.options.noclobber&&!a&&!l.isDirectory&&n!=="/dev/null")return _("",`bash: ${n}: cannot overwrite existing file
100
- `,1)}catch{}if(n!=="/dev/null"&&n!=="/dev/stdout"&&n!=="/dev/stderr"&&n!=="/dev/full"&&await e.fs.writeFile(i,"","binary"),n==="/dev/full")return _("",`bash: /dev/full: No space left on device
101
- `,1)}return null}async function ue(e,t,s,r){let{stdout:n,stderr:i,exitCode:a}=t,o=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",u=p=>o,c={kind:"live-stdout"},f={kind:"live-stderr"};for(let p=0;p<s.length;p++){let y=s[p];if(y.target.type==="HereDoc")continue;let b,v=r?.get(p);if(v!==void 0)b=v;else if(y.operator===">&"||y.operator==="<&"){if(en(e,y.target)){i+=`bash: $@: ambiguous redirect
102
- `,a=1,n="";continue}b=await V(e,y.target)}else{let w=await tn(e,y.target);if("error"in w){i+=w.error,a=1,n="";continue}b=w.target}if(!y.fdVariable){if(b.includes("\0")){i+=`bash: ${b.replace(/\0/g,"")}: No such file or directory
103
- `,a=1,n="";continue}switch(y.operator){case">":case">|":case">>":{let E=y.fd??1;if(E!==1&&E!==2)break;let w=y.operator===">>",S=y.operator===">|";if(b==="/dev/stdout"){E===2&&(f=c);break}if(b==="/dev/stderr"){E===1&&(c=f);break}if(b==="/dev/full"){i+=`bash: echo: write error: No space left on device
104
- `,a=1,E===1&&(n="");break}if(b==="/dev/null"&&E===2){f={kind:"discard"};break}let A=e.fs.resolvePath(e.state.cwd,b),$=await wn(e,A,b,{...w?{}:{checkNoclobber:!0,isClobber:S}});if($){i+=$,a=1,E===1&&(n="");break}w?await e.fs.appendFile(A,"","binary"):await e.fs.writeFile(A,"","binary"),E===1?c={kind:"file",path:A,append:w}:f={kind:"file",path:A,append:w};break}case">&":case"<&":{let E=y.fd??1;if(b==="-")break;if(b.endsWith("-")){let w=b.slice(0,-1),S=Number.parseInt(w,10);if(!Number.isNaN(S)){let A=e.state.fileDescriptors?.get(S);A!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(E,A),S>=3&&e.state.fileDescriptors?.delete(S)):S===1||S===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(E,`__dupout__:${S}`)):S===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(E,`__dupin__:${S}`)):S>=3&&(i+=`bash: ${S}: Bad file descriptor
105
- `,a=1)}break}if(b==="2"||b==="&2")E===1&&(c=f);else if(b==="1"||b==="&1")E===2?f=c:(n+=i,i="");else{let w=Number.parseInt(b,10);if(Number.isNaN(w)){if(y.operator===">&"){let S=e.fs.resolvePath(e.state.cwd,b),A=await wn(e,S,b,{checkNoclobber:!0});if(A){i=A,a=1,n="";break}await e.fs.writeFile(S,"","binary"),y.fd==null?(c={kind:"file",path:S,append:!1},f=c):E===1?c={kind:"file",path:S,append:!1}:E===2&&(f={kind:"file",path:S,append:!1})}}else{let S=e.state.fileDescriptors?.get(w);if(S?.startsWith("__file__:")){let A=S.slice(9);E===1?(await e.fs.appendFile(A,n,u(n)),n=""):E===2&&(await e.fs.appendFile(A,i,Xt(i)),i="")}else if(S?.startsWith("__rw__:")){let A=kf(S);A&&(E===1?(await e.fs.appendFile(A.path,n,u(n)),n=""):E===2&&(await e.fs.appendFile(A.path,i,Xt(i)),i=""))}else if(S?.startsWith("__dupout__:")){let A=Number.parseInt(S.slice(11),10);if(A!==1)if(A===2)E===1&&(i+=n,n="");else{let $=e.state.fileDescriptors?.get(A);if($?.startsWith("__file__:")){let R=$.slice(9);E===1?(await e.fs.appendFile(R,n,u(n)),n=""):E===2&&(await e.fs.appendFile(R,i,Xt(i)),i="")}}}else S?.startsWith("__dupin__:")?(i+=`bash: ${w}: Bad file descriptor
106
- `,a=1,n=""):w>=3&&(i+=`bash: ${w}: Bad file descriptor
107
- `,a=1,n="")}}break}case"&>":{if(b==="/dev/full"){i=`bash: echo: write error: No space left on device
108
- `,a=1,n="";break}let E=e.fs.resolvePath(e.state.cwd,b),w=await wn(e,E,b,{checkNoclobber:!0});if(w){i=w,a=1,n="";break}await e.fs.writeFile(E,"","binary"),c={kind:"file",path:E,append:!1},f=c;break}case"&>>":{if(b==="/dev/full"){i=`bash: echo: write error: No space left on device
109
- `,a=1,n="";break}let E=e.fs.resolvePath(e.state.cwd,b),w=await wn(e,E,b,{});if(w){i=w,a=1,n="";break}await e.fs.appendFile(E,"","binary"),c={kind:"file",path:E,append:!0},f=c;break}}}}if(n!==""||i!==""){let p=n,y=i;n="",i="";let b=async(v,E,w)=>{v.append?await e.fs.appendFile(v.path,E,w):await e.fs.writeFile(v.path,E,w)};if(c===f&&c.kind==="file"){let v=p+y;v!==""&&await b(c,v,u(v))}else for(let[v,E,w]of[[p,c,!0],[y,f,!1]])if(v!=="")switch(E.kind){case"live-stdout":n+=v;break;case"live-stderr":i+=v;break;case"file":await b(E,v,w?u(v):Xt(v));break;case"discard":break}}let d=e.state.fileDescriptors?.get(1);if(d){if(d==="__dupout__:2")i+=n,n="";else if(d.startsWith("__file__:")){let p=d.slice(9);await e.fs.appendFile(p,n,u(n)),n=""}else if(d.startsWith("__file_append__:")){let p=d.slice(16);await e.fs.appendFile(p,n,u(n)),n=""}}let h=e.state.fileDescriptors?.get(2);if(h){if(h==="__dupout__:1")n+=i,i="";else if(h.startsWith("__file__:")){let p=h.slice(9);await e.fs.appendFile(p,i,Xt(i)),i=""}else if(h.startsWith("__file_append__:")){let p=h.slice(16);await e.fs.appendFile(p,i,Xt(i)),i=""}}let m=_(n,i,a);return t.stdoutKind&&(m.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(m.stdoutEncoding="binary"),m}function dl(e,t){if(e.state.options.posix&&Mr.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
110
- `;throw new Z(2,"",r)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),K}async function _f(e,t){let s="";for(let r of t)if((r.operator==="<<"||r.operator==="<<-")&&r.target.type==="HereDoc"){let n=r.target,i=await V(e,n.content);n.stripTabs&&(i=i.split(`
111
- `).map(l=>l.replace(/^\t+/,"")).join(`
112
- `)),(r.fd??0)===0&&(s=i)}else if(r.operator==="<<<"&&r.target.type==="Word")s=`${await V(e,r.target)}
113
- `;else if(r.operator==="<"&&r.target.type==="Word"){let n=await V(e,r.target),i=e.fs.resolvePath(e.state.cwd,n);try{s=await e.fs.readFile(i)}catch{}}return s}async function bn(e,t,s,r="",n){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,at(`${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(n??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i=new Map;for(let u=0;u<s.length;u++)i.set(String(u+1),e.state.env.get(String(u+1))),e.state.env.set(String(u+1),s[u]);i.set("@",e.state.env.get("@")),i.set("#",e.state.env.get("#")),e.state.env.set("@",s.join(" ")),e.state.env.set("#",String(s.length));let a=()=>{let u=e.state.localScopes.length-1,c=e.state.localScopes.pop();if(c)for(let[f,d]of c)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);if(cl(e,u),e.state.fullyUnsetLocals)for(let[f,d]of e.state.fullyUnsetLocals.entries())d===u&&e.state.fullyUnsetLocals.delete(f);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let f=e.state.localExportedVars.pop();if(f)for(let d of f)e.state.exportedVars?.delete(d)}for(let[f,d]of i)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},{targets:l,error:o}=await fl(e,t.redirections);if(o)return a(),_("",o,1);try{let u=await _f(e,t.redirections),c=r||u,f=await e.executeCommand(t.body,c);return a(),ue(e,f,t.redirections,l)}catch(u){if(a(),u instanceof ke){let c=_(u.stdout,u.stderr,u.exitCode);return ue(e,c,t.redirections,l)}throw u}}var pl=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],Vr=[".",":","[","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"],xf=["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"],Cf=Vr;async function zr(e,t){let s=[],r=null,n="",i="",a=null,l=!1,o=!1,u=!1,c=null,f=null,d=null,h=[],m=["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 w=0;w<t.length;w++){let S=t[w];if(S==="-v")s.push("variable");else if(S==="-e")s.push("export");else if(S==="-f")s.push("file");else if(S==="-d")s.push("directory");else if(S==="-k")s.push("keyword");else if(S==="-A"){if(w++,w>=t.length)return N(`compgen: -A: option requires an argument
114
- `,2);let A=t[w];if(!m.includes(A))return N(`compgen: ${A}: invalid action name
115
- `,2);s.push(A)}else if(S==="-W"){if(w++,w>=t.length)return N(`compgen: -W: option requires an argument
116
- `,2);r=t[w]}else if(S==="-P"){if(w++,w>=t.length)return N(`compgen: -P: option requires an argument
117
- `,2);n=t[w]}else if(S==="-S"){if(w++,w>=t.length)return N(`compgen: -S: option requires an argument
118
- `,2);i=t[w]}else if(S==="-o"){if(w++,w>=t.length)return N(`compgen: -o: option requires an argument
119
- `,2);let A=t[w];if(A==="plusdirs")l=!0;else if(A==="dirnames")o=!0;else if(A==="default")u=!0;else if(!(A==="filenames"||A==="nospace"||A==="bashdefault"||A==="noquote"))return N(`compgen: ${A}: invalid option name
120
- `,2)}else if(S==="-F"){if(w++,w>=t.length)return N(`compgen: -F: option requires an argument
121
- `,2);f=t[w]}else if(S==="-C"){if(w++,w>=t.length)return N(`compgen: -C: option requires an argument
122
- `,2);d=t[w]}else if(S==="-X"){if(w++,w>=t.length)return N(`compgen: -X: option requires an argument
123
- `,2);c=t[w]}else if(S==="-G"){if(w++,w>=t.length)return N(`compgen: -G: option requires an argument
124
- `,2)}else if(S==="--"){h.push(...t.slice(w+1));break}else S.startsWith("-")||h.push(S)}a=h[0]??null;let p=[];if(o){let w=await Fr(e,a);p.push(...w)}if(u){let w=await hl(e,a);p.push(...w)}for(let w of s)if(w==="variable"){let S=Df(e,a);p.push(...S)}else if(w==="export"){let S=Rf(e,a);p.push(...S)}else if(w==="function"){let S=If(e,a);p.push(...S)}else if(w==="builtin"){let S=Of(a);p.push(...S)}else if(w==="keyword"){let S=Tf(a);p.push(...S)}else if(w==="alias"){let S=Lf(e,a);p.push(...S)}else if(w==="shopt"){let S=Mf(a);p.push(...S)}else if(w==="helptopic"){let S=Wf(a);p.push(...S)}else if(w==="directory"){let S=await Fr(e,a);p.push(...S)}else if(w==="file"){let S=await hl(e,a);p.push(...S)}else if(w==="user"){let S=Ff(a);p.push(...S)}else if(w==="command"){let S=await Vf(e,a);p.push(...S)}if(r!==null)try{let w=await zf(e,r),S=Bf(e,w);for(let A of S)(a===null||A.startsWith(a))&&p.push(A)}catch{return _("","",1)}if(l){let w=await Fr(e,a);for(let S of w)p.includes(S)||p.push(S)}let y="";if(f!==null){let w=e.state.functions.get(f);if(w){let S=new Map;S.set("COMP_WORDS__length",e.state.env.get("COMP_WORDS__length")),e.state.env.set("COMP_WORDS__length","0"),S.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),S.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),S.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let A=new Map;for(let R of e.state.env.keys())(R==="COMPREPLY"||R.startsWith("COMPREPLY_")||R==="COMPREPLY__length")&&(A.set(R,e.state.env.get(R)),e.state.env.delete(R));let $=["compgen",h[0]??"",""];try{let R=await bn(e,w,$,"");if(R.exitCode!==0)return Yt(e,S),Yt(e,A),_("",R.stderr,1);y=R.stdout;let C=qf(e);p.push(...C)}catch{return Yt(e,S),Yt(e,A),_("","",1)}Yt(e,S),Yt(e,A)}}if(d!==null)try{let w=Ce(d),S=await e.executeScript(w);if(S.exitCode!==0)return _("",S.stderr,S.exitCode);if(S.stdout){let A=S.stdout.split(`
125
- `);for(let $ of A)$.length>0&&p.push($)}}catch(w){if(w.name==="ParseException")return N(`compgen: -C: ${w.message}
126
- `,2);throw w}let b=p;if(c!==null){let w=c.startsWith("!"),S=w?c.slice(1):c;b=p.filter(A=>{let $=Ht(A,S,!1,!0);return w?$:!$})}if(b.length===0&&a!==null)return _(y,"",1);let v=b.map(w=>`${n}${w}${i}`).join(`
127
- `),E=y+(v?`${v}
128
- `:"");return H(E)}function Df(e,t){let s=new Set;for(let n of e.state.env.keys()){if(n.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(n)||n.endsWith("__length"))continue;let i=n.split("_")[0];/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)?s.add(n):i&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)&&e.state.env.has(`${i}__length`)&&s.add(i)}let r=Array.from(s);return t!==null&&(r=r.filter(n=>n.startsWith(t))),r.sort()}function Rf(e,t){let s=e.state.exportedVars??new Set,r=Array.from(s);return t!==null&&(r=r.filter(n=>n.startsWith(t))),r=r.filter(n=>n.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(n)||n.endsWith("__length")?!1:e.state.env.has(n)),r.sort()}function If(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(r=>r.startsWith(t))),s.sort()}function Of(e){let t=[...Vr];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Tf(e){let t=[...pl];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Lf(e,t){let s=[];for(let n of e.state.env.keys())if(n.startsWith("BASH_ALIAS_")){let i=n.slice(11);s.push(i)}let r=s;return t!==null&&(r=r.filter(n=>n.startsWith(t))),r.sort()}function Mf(e){let t=[...xf];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Wf(e){let t=[...Cf];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function Fr(e,t){let s=[];try{let r=e.state.cwd,n=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";n=t.slice(a+1),l.startsWith("/")?r=l:r=`${e.state.cwd}/${l}`}}let i=await e.fs.readdir(r);for(let a of i){let l=`${r}/${a}`;try{if((await e.fs.stat(l)).isDirectory&&(!n||a.startsWith(n)))if(t?.includes("/")){let u=t.lastIndexOf("/"),c=t.slice(0,u+1);s.push(c+a)}else s.push(a)}catch{}}}catch{}return s.sort()}async function hl(e,t){let s=[];try{let r=e.state.cwd,n=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";n=t.slice(a+1),l.startsWith("/")?r=l:r=`${e.state.cwd}/${l}`}}let i=await e.fs.readdir(r);for(let a of i)if(!n||a.startsWith(n))if(t?.includes("/")){let l=t.lastIndexOf("/"),o=t.slice(0,l+1);s.push(o+a)}else s.push(a)}catch{}return s.sort()}function Ff(e){return["root","nobody"]}async function Vf(e,t){let s=new Set;for(let i of Vr)s.add(i);for(let i of e.state.functions.keys())s.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&s.add(i.slice(11));for(let i of pl)s.add(i);let r=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of r.split(":"))if(i)try{let a=await e.fs.readdir(i);for(let l of a)s.add(l)}catch{}let n=Array.from(s);return t!==null&&(n=n.filter(i=>i.startsWith(t))),n.sort()}async function zf(e,t){let r=new q().parseWordFromString(t,!1,!1);return await V(e,r)}function Bf(e,t){let s=e.state.env.get("IFS")??`
129
- `;if(s.length===0)return[t];let r=new Set(s.split("")),n=[],i="",a=0;for(;a<t.length;){let l=t[a];if(l==="\\"&&a+1<t.length){let o=t[a+1];i+=o,a+=2}else r.has(l)?(i.length>0&&(n.push(i),i=""),a++):(i+=l,a++)}return i.length>0&&n.push(i),n}function Yt(e,t){for(let[s,r]of t)r===void 0?e.state.env.delete(s):e.state.env.set(s,r)}function qf(e){let t=[];if(e.state.env.get("COMPREPLY__length")!==void 0){let n=B(e,"COMPREPLY");for(let[,i]of n)t.push(i)}else{let n=e.state.env.get("COMPREPLY");n!==void 0&&t.push(n)}return t}var jf=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function qr(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,r=!1,n=!1,i,a,l,o=[],u=[],c=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-p")s=!0;else if(d==="-r")r=!0;else if(d==="-D")n=!0;else if(d==="-W"){if(f++,f>=t.length)return N(`complete: -W: option requires an argument
130
- `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return N(`complete: -F: option requires an argument
131
- `,2);a=t[f]}else if(d==="-o"){if(f++,f>=t.length)return N(`complete: -o: option requires an argument
132
- `,2);let h=t[f];if(!jf.includes(h))return N(`complete: ${h}: invalid option name
133
- `,2);o.push(h)}else if(d==="-A"){if(f++,f>=t.length)return N(`complete: -A: option requires an argument
134
- `,2);u.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return N(`complete: -C: option requires an argument
135
- `,2);l=t[f]}else if(d==="-G"){if(f++,f>=t.length)return N(`complete: -G: option requires an argument
136
- `,2)}else if(d==="-P"){if(f++,f>=t.length)return N(`complete: -P: option requires an argument
137
- `,2)}else if(d==="-S"){if(f++,f>=t.length)return N(`complete: -S: option requires an argument
138
- `,2)}else if(d==="-X"){if(f++,f>=t.length)return N(`complete: -X: option requires an argument
139
- `,2)}else if(d==="--"){c.push(...t.slice(f+1));break}else d.startsWith("-")||c.push(d)}if(r){if(c.length===0)return e.state.completionSpecs.clear(),H("");for(let f of c)e.state.completionSpecs.delete(f);return H("")}if(s)return c.length===0?Br(e):Br(e,c);if(t.length===0||c.length===0&&!i&&!a&&!l&&o.length===0&&u.length===0&&!n)return Br(e);if(a&&c.length===0&&!n)return N(`complete: -F: option requires a command name
140
- `,2);if(n){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),a!==void 0&&(f.function=a),l!==void 0&&(f.command=l),o.length>0&&(f.options=o),u.length>0&&(f.actions=u),e.state.completionSpecs.set("__default__",f),H("")}for(let f of c){let d=Object.create(null);i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),l!==void 0&&(d.command=l),o.length>0&&(d.options=o),u.length>0&&(d.actions=u),e.state.completionSpecs.set(f,d)}return H("")}function Br(e,t){let s=e.state.completionSpecs;if(!s||s.size===0){if(t&&t.length>0){let i="";for(let a of t)i+=`complete: ${a}: no completion specification
141
- `;return _("",i,1)}return H("")}let r=[],n=t||Array.from(s.keys());for(let i of n){if(i==="__default__")continue;let a=s.get(i);if(!a){if(t)return _(r.join(`
47
+ `,this.pos++,this.line++,this.column=1)}this.tokens.push({type:y.HEREDOC_CONTENT,value:i,start:n,end:this.pos,line:r,column:s})}}addPendingHeredoc(t,n,r){this.pendingHeredocs.push({delimiter:t,stripTabs:n,quoted:r})}registerHeredocFromLookahead(t){let n=this.pos,r=this.column;for(;this.pos<this.input.length&&(this.input[this.pos]===" "||this.input[this.pos]===" ");)this.pos++,this.column++;let s="",i=!1;for(;this.pos<this.input.length;){let a=this.input[this.pos];if(/[\s;<>&|()]/.test(a))break;if(a==="'"||a==='"'){i=!0;let o=a;for(this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]!==o;)s+=this.input[this.pos],this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]===o&&(this.pos++,this.column++)}else a==="\\"?(i=!0,this.pos++,this.column++,this.pos<this.input.length&&(s+=this.input[this.pos],this.pos++,this.column++)):(s+=a,this.pos++,this.column++)}this.pos=n,this.column=r,s&&this.pendingHeredocs.push({delimiter:s,stripTabs:t,quoted:i})}isWordCharFollowing(t){if(t>=this.input.length)return!1;let n=this.input[t];return!(n===" "||n===" "||n===`
48
+ `||n===";"||n==="&"||n==="|"||n==="("||n===")"||n==="<"||n===">")}readWordWithBraceExpansion(t,n,r){let s=this.input,i=s.length,a=t,o=r;for(;a<i;){let c=s[a];if(c===" "||c===" "||c===`
49
+ `||c===";"||c==="&"||c==="|"||c==="("||c===")"||c==="<"||c===">")break;if(c==="{"){if(this.scanBraceExpansion(a)!==null){let f=1;for(a++,o++;a<i&&f>0;)s[a]==="{"?f++:s[a]==="}"&&f--,a++,o++;continue}a++,o++;continue}if(c==="}"){a++,o++;continue}if(c==="$"&&a+1<i&&s[a+1]==="("){a++,o++,a++,o++;let u=1;for(;u>0&&a<i;)s[a]==="("?u++:s[a]===")"&&u--,a++,o++;continue}if(c==="$"&&a+1<i&&s[a+1]==="{"){a++,o++,a++,o++;let u=1;for(;u>0&&a<i;)s[a]==="{"?u++:s[a]==="}"&&u--,a++,o++;continue}if(c==="`"){for(a++,o++;a<i&&s[a]!=="`";)s[a]==="\\"&&a+1<i?(a+=2,o+=2):(a++,o++);a<i&&(a++,o++);continue}a++,o++}let l=s.slice(t,a);return this.pos=a,this.column=o,{type:y.WORD,value:l,start:t,end:a,line:n,column:r,quoted:!1,singleQuoted:!1}}scanBraceExpansion(t){let n=this.input,r=n.length,s=t+1,i=1,a=!1,o=!1;for(;s<r&&i>0;){let l=n[s];if(l==="{")i++,s++;else if(l==="}")i--,s++;else if(l===","&&i===1)a=!0,s++;else if(l==="."&&s+1<r&&n[s+1]===".")o=!0,s+=2;else{if(l===" "||l===" "||l===`
50
+ `||l===";"||l==="&"||l==="|")return null;s++}}return i===0&&(a||o)?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 a=n[s];if(a==="{")i++,s++;else if(a==="}"){if(i--,i===0)return n.slice(t,s+1);s++}else{if(a===" "||a===" "||a===`
51
+ `||a===";"||a==="&"||a==="|")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 a=n[s];if(a==="\\"&&s+1<r){s+=2;continue}if("@*+?!".includes(a)&&s+1<r&&n[s+1]==="("){s++,i++,s++;continue}if(a==="(")i++,s++;else if(a===")")i--,s++;else{if(a===`
52
+ `)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 a=n.slice(i,s);if(s>=r||n[s]!=="}"||(s++,s>=r))return null;let o=n[s],l=s+1<r?n[s+1]:"";return o===">"||o==="<"||o==="&"&&(l===">"||l==="<")?{varname:a,end:s}:null}dollarDparenIsSubshell(t){let n=this.input,r=n.length,s=t+1,i=2,a=!1,o=!1,l=!1;for(;s<r&&i>0;){let c=n[s];if(a){c==="'"&&(a=!1),c===`
53
+ `&&(l=!0),s++;continue}if(o){if(c==="\\"){s+=2;continue}c==='"'&&(o=!1),c===`
54
+ `&&(l=!0),s++;continue}if(c==="'"){a=!0,s++;continue}if(c==='"'){o=!0,s++;continue}if(c==="\\"){s+=2;continue}if(c===`
55
+ `&&(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]===`
56
+ `);)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,a=!1,o=!1;for(;s<r&&i>0;){let l=n[s];if(a){l==="'"&&(a=!1),s++;continue}if(o){if(l==="\\"){s+=2;continue}l==='"'&&(o=!1),s++;continue}if(l==="'"){a=!0,s++;continue}if(l==='"'){o=!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]===`
57
+ `);)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 js=1e6,qn=1e5,wf=1e6,oo=200,lo=new Set([y.LESS,y.GREAT,y.DLESS,y.DGREAT,y.LESSAND,y.GREATAND,y.LESSGREAT,y.DLESSDASH,y.CLOBBER,y.TLESS,y.AND_GREAT,y.AND_DGREAT]),co=new Set([y.LESS,y.GREAT,y.DLESS,y.DGREAT,y.LESSAND,y.GREATAND,y.LESSGREAT,y.DLESSDASH,y.CLOBBER,y.TLESS]),uo=new Set([y.LESS,y.GREAT,y.DLESS,y.DGREAT,y.LESSAND,y.GREATAND,y.LESSGREAT,y.DLESSDASH,y.CLOBBER,y.TLESS,y.AND_GREAT,y.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"}},Nr=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>wf)throw new xe("Maximum parse iterations exceeded (possible infinite loop)",t,n)}chargeTokens(t,n=1,r=1){if(this.tokens+=t,this.tokens>qn)throw new xe(`Too many tokens: cumulative count exceeds limit of ${qn}`,n,r)}enter(t,n){if(this.depth++,this.depth>oo)throw this.depth--,new xe(`Maximum parser nesting depth exceeded (${oo})`,t,n);let r=!0;return()=>{r&&(r=!1,this.depth--)}}};function pe(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
58
+ `){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var Cr=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function Un(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 a=0;for(let o of s){let l;if(/[0-9]/.test(o))l=o.charCodeAt(0)-48;else if(/[a-z]/.test(o))l=o.charCodeAt(0)-97+10;else if(/[A-Z]/.test(o))l=o.charCodeAt(0)-65+(i<=36?10:36);else if(o==="@")l=62;else if(o==="_")l=63;else return Number.NaN;if(l>=i)return Number.NaN;if(a=a*i+l,a>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return a}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 fo(e,t,n,r){if(n.slice(r,r+3)!=="$((")return null;let s=r+3,i=1,a=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 o=n.slice(a,s),{expr:l}=e(t,o,0);return s+=2,{expr:{type:"ArithNested",expression:l},pos:s}}function ho(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+=`
59
+ `;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 po(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 Ef(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=Ef(t),{expr:r,pos:s}=En(e,n,0),i=pe(n,s);if(i<n.length){let a=t.slice(i).trim();if(a)return{type:"ArithmeticExpression",originalText:t,expression:{type:"ArithSyntaxError",errorToken:a,message:`${a}: syntax error: invalid arithmetic operator (error token is "${a}")`}}}return{type:"ArithmeticExpression",expression:r,originalText:t}}function Ve(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function ze(e,t){return pe(e,t)>=e.length}function En(e,t,n){return bf(e,t,n)}function sn(e,t,n){return e.withDepth(()=>En(e,t,n))}function bf(e,t,n){let{expr:r,pos:s}=jn(e,t,n);for(s=pe(t,s);t[s]===",";){if(s++,ze(t,s))return Ve(",",s);let{expr:a,pos:o}=jn(e,t,s);r={type:"ArithBinary",operator:",",left:r,right:a},s=pe(t,o)}return{expr:r,pos:s}}function jn(e,t,n){let{expr:r,pos:s}=Sf(e,t,n);if(s=pe(t,s),t[s]==="?"){s++;let{expr:i,pos:a}=sn(e,t,s);if(s=pe(t,a),t[s]===":"){s++;let{expr:o,pos:l}=sn(e,t,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:o},pos:l}}}return{expr:r,pos:s}}function Sf(e,t,n){let{expr:r,pos:s}=mo(e,t,n);for(;s=pe(t,s),t.slice(s,s+2)==="||";){if(s+=2,ze(t,s))return Ve("||",s);let{expr:a,pos:o}=mo(e,t,s);r={type:"ArithBinary",operator:"||",left:r,right:a},s=o}return{expr:r,pos:s}}function mo(e,t,n){let{expr:r,pos:s}=yo(e,t,n);for(;s=pe(t,s),t.slice(s,s+2)==="&&";){if(s+=2,ze(t,s))return Ve("&&",s);let{expr:a,pos:o}=yo(e,t,s);r={type:"ArithBinary",operator:"&&",left:r,right:a},s=o}return{expr:r,pos:s}}function yo(e,t,n){let{expr:r,pos:s}=go(e,t,n);for(;s=pe(t,s),t[s]==="|"&&t[s+1]!=="|";){if(s++,ze(t,s))return Ve("|",s);let{expr:a,pos:o}=go(e,t,s);r={type:"ArithBinary",operator:"|",left:r,right:a},s=o}return{expr:r,pos:s}}function go(e,t,n){let{expr:r,pos:s}=wo(e,t,n);for(;s=pe(t,s),t[s]==="^";){if(s++,ze(t,s))return Ve("^",s);let{expr:a,pos:o}=wo(e,t,s);r={type:"ArithBinary",operator:"^",left:r,right:a},s=o}return{expr:r,pos:s}}function wo(e,t,n){let{expr:r,pos:s}=Eo(e,t,n);for(;s=pe(t,s),t[s]==="&"&&t[s+1]!=="&";){if(s++,ze(t,s))return Ve("&",s);let{expr:a,pos:o}=Eo(e,t,s);r={type:"ArithBinary",operator:"&",left:r,right:a},s=o}return{expr:r,pos:s}}function Eo(e,t,n){let{expr:r,pos:s}=bo(e,t,n);for(;s=pe(t,s),t.slice(s,s+2)==="=="||t.slice(s,s+2)==="!=";){let i=t.slice(s,s+2);if(s+=2,ze(t,s))return Ve(i,s);let{expr:a,pos:o}=bo(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}return{expr:r,pos:s}}function bo(e,t,n){let{expr:r,pos:s}=Gs(e,t,n);for(;;)if(s=pe(t,s),t.slice(s,s+2)==="<="||t.slice(s,s+2)===">="){let i=t.slice(s,s+2);if(s+=2,ze(t,s))return Ve(i,s);let{expr:a,pos:o}=Gs(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}else if(t[s]==="<"||t[s]===">"){let i=t[s];if(s++,ze(t,s))return Ve(i,s);let{expr:a,pos:o}=Gs(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}else break;return{expr:r,pos:s}}function Gs(e,t,n){let{expr:r,pos:s}=So(e,t,n);for(;s=pe(t,s),t.slice(s,s+2)==="<<"||t.slice(s,s+2)===">>";){let i=t.slice(s,s+2);if(s+=2,ze(t,s))return Ve(i,s);let{expr:a,pos:o}=So(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}return{expr:r,pos:s}}function So(e,t,n){let{expr:r,pos:s}=vo(e,t,n);for(;s=pe(t,s),(t[s]==="+"||t[s]==="-")&&t[s+1]!==t[s];){let i=t[s];if(s++,ze(t,s))return Ve(i,s);let{expr:a,pos:o}=vo(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}return{expr:r,pos:s}}function vo(e,t,n){let{expr:r,pos:s}=Dr(e,t,n);for(;;)if(s=pe(t,s),t[s]==="*"&&t[s+1]!=="*"){if(s++,ze(t,s))return Ve("*",s);let{expr:a,pos:o}=Dr(e,t,s);r={type:"ArithBinary",operator:"*",left:r,right:a},s=o}else if(t[s]==="/"||t[s]==="%"){let i=t[s];if(s++,ze(t,s))return Ve(i,s);let{expr:a,pos:o}=Dr(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}else break;return{expr:r,pos:s}}function Dr(e,t,n){let{expr:r,pos:s}=Zs(e,t,n),i=pe(t,s);if(t.slice(i,i+2)==="**"){if(i+=2,ze(t,i))return Ve("**",i);let{expr:o,pos:l}=e.withDepth(()=>Dr(e,t,i));return{expr:{type:"ArithBinary",operator:"**",left:r,right:o},pos:l}}return{expr:r,pos:s}}function Zs(e,t,n){let r=pe(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:a}=e.withDepth(()=>Zs(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:a}}if(t[r]==="+"||t[r]==="-"||t[r]==="!"||t[r]==="~"){let s=t[r];r++;let{expr:i,pos:a}=e.withDepth(()=>Zs(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:a}}return Af(e,t,r)}function vf(e,t){let n=e[t];return n==="$"||n==="`"}function Af(e,t,n){let{expr:r,pos:s}=Ao(e,t,n,!1),i=[r];for(;vf(t,s);){let{expr:o,pos:l}=Ao(e,t,s,!0);i.push(o),s=l}i.length>1&&(r={type:"ArithConcat",parts:i});let a;if(t[s]==="["&&r.type==="ArithConcat"){s++;let{expr:o,pos:l}=sn(e,t,s);a=o,s=l,t[s]==="]"&&s++}if(a&&r.type==="ArithConcat"&&(r={type:"ArithDynamicElement",nameExpr:r,subscript:a},a=void 0),s=pe(t,s),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let o of Cr)if(t.slice(s,s+o.length)===o&&t.slice(s,s+o.length+1)!=="=="){s+=o.length;let{expr:l,pos:c}=e.withDepth(()=>jn(e,t,s));return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:o,target:r.nameExpr,subscript:r.subscript,value:l},pos:c}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:o,target:r,value:l},pos:c}:{expr:{type:"ArithAssignment",operator:o,variable:r.name,value:l},pos:c}}}if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let o=t.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:o,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function Ao(e,t,n,r=!1){let s=pe(t,n),i=fo(sn,e,t,s);if(i)return i;let a=ho(t,s);if(a)return a;let o=po(t,s);if(o)return o;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}=sn(e,t,s);return s=pe(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}=sn(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 oe(`${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:Un(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=pe(t,s),t[s]==="]"&&s++}let f;if(u===void 0){let{expr:d,pos:h}=sn(e,t,s);f=d,s=h,t[s]==="]"&&s++}if(s=pe(t,s),t[s]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:c,index:f},pos:s};if(!r){for(let d of Cr)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(()=>jn(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=pe(t,s),!r){for(let u of Cr)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(()=>jn(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]!==`
60
+ `;)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}}function xf(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 $o(e,t,n){let r=n+1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;return r}function Hs(e,t,n,r,s){let i=1,a=n+1;for(;a<t.length&&i>0;)t[a]===r?i++:t[a]===s&&i--,i>0&&a++;return i===0?a:-1}function an(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 a=t.indexOf("'",r+1);if(a!==-1){r=a+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 ko(e,t,n){let r=n,s=!1;for(;r<t.length;){let i=t[r];if(i==="/"&&s||i==="}")break;if(i==="'"){let a=t.indexOf("'",r+1);if(a!==-1){r=a+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 No(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 a=Pf(t,r);a===-1?(s+=i,r++):(s+=t.slice(r,a+1),r=a+1)}else break}return{pattern:s,endIndex:r}}function Pf(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]}]`,a=e.indexOf(i,n+2);if(a!==-1){n=a+2;continue}}n++}return-1}function Co(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+=`
61
+ `,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 o=[],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)o.push(u),l+=2+c.length;else break}o.length>0?(r+=xf(o),s=l):(r+="\\x",s+=2);break}case"u":{let o=t.slice(s+2,s+6),l=parseInt(o,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 o="",l=s+1;for(;l<t.length&&l<s+4&&/[0-7]/.test(t[l]);)o+=t[l],l++;let c=parseInt(o,8);r+=String.fromCharCode(c),s=l;break}default:r+=i,s++}else r+=i,s++}return s<t.length&&t[s]==="'"&&s++,{part:L.literal(r),endIndex:s}}function Qs(e,t){let n=t.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:re(e,n)}function Po(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 Do(e,t,n,r){let s=Hs(e,t,n,"{","}");if(s===-1)return null;let i=t.slice(n+1,s),a=i.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(a)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(a[1],10),end:Number.parseInt(a[2],10),step:a[3]?Number.parseInt(a[3],10):void 0,startStr:a[1],endStr:a[2]}]},endIndex:s+1};let o=i.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return o?{part:{type:"BraceExpansion",items:[{type:"Range",start:o[1],end:o[2],step:o[3]?Number.parseInt(o[3],10):void 0}]},endIndex:s+1}:i.includes(",")&&r?{part:{type:"BraceExpansion",items:Po(i).map(u=>e.withDepth(()=>({type:"Word",word:L.word(r(e,u,!1,!1,!1))})))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:Po(i).map(u=>({type:"Word",word:L.word([L.literal(u)])}))},endIndex:s+1}:null}function Ks(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 a=i.startStr??String(i.start),o=i.endStr??String(i.end);i.step!==void 0?s.push(`${a}..${o}..${i.step}`):s.push(`${a}..${o}`)}else s.push(Ks(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 Ro(e,t){return{[y.LESS]:"<",[y.GREAT]:">",[y.DGREAT]:">>",[y.LESSAND]:"<&",[y.GREATAND]:">&",[y.LESSGREAT]:"<>",[y.CLOBBER]:">|",[y.TLESS]:"<<<",[y.AND_GREAT]:"&>",[y.AND_DGREAT]:"&>>",[y.DLESS]:"<",[y.DLESSDASH]:"<"}[t]||">"}function Rr(e){let t=e.current(),n=t.type;if(n===y.NUMBER){let r=e.peek(1);return t.end!==r.start?!1:co.has(r.type)}if(n===y.FD_VARIABLE){let r=e.peek(1);return uo.has(r.type)}return lo.has(n)}function Or(e){let t=null,n;e.check(y.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(y.FD_VARIABLE)&&(n=e.advance().value);let r=e.advance(),s=Ro(e,r.type);if(r.type===y.DLESS||r.type===y.DLESSDASH)return $f(e,s,t,r.type===y.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return L.redirection(s,i,t,n)}function $f(e,t,n,r){e.isWord()||e.error("Expected here-document delimiter");let s=e.advance(),i=s.value,a=s.quoted||!1;(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1));let o=L.redirection(r?"<<-":"<<",L.hereDoc(i,L.word([]),r,a),n);return e.addPendingHeredoc(o,i,r,a),o}function Io(e){let t=e.current().line,n=[],r=null,s=[],i=[];for(;e.check(y.ASSIGNMENT_WORD)||Rr(e);)e.checkIterationLimit(),e.check(y.ASSIGNMENT_WORD)?n.push(kf(e)):i.push(Or(e));if(e.isWord())r=e.parseWord();else if(n.length>0&&(e.check(y.DBRACK_START)||e.check(y.DPAREN_START))){let o=e.advance();r=L.word([L.literal(o.value)])}for(;(!e.isStatementEnd()||e.check(y.RBRACE))&&!e.check(y.PIPE,y.PIPE_AMP);)if(e.checkIterationLimit(),Rr(e))i.push(Or(e));else if(e.check(y.RBRACE)){let o=e.advance();s.push(e.parseWordFromString(o.value,!1,!1))}else if(e.check(y.LBRACE)){let o=e.advance();s.push(e.parseWordFromString(o.value,!1,!1))}else if(e.check(y.DBRACK_END)){let o=e.advance();s.push(e.parseWordFromString(o.value,!1,!1))}else if(e.isWord())s.push(e.parseWord());else if(e.check(y.ASSIGNMENT_WORD)){let o=e.advance(),l=o.value,c=l.endsWith("="),u=l.endsWith("=(");if((c||u)&&(u||e.check(y.LPAREN))){let f=u?l.slice(0,-2):l.slice(0,-1);u||e.expect(y.LPAREN);let d=Xs(e);e.expect(y.RPAREN);let h=d.map(m=>Ks(e,m)),p=`${f}=(${h.join(" ")})`;s.push(e.parseWordFromString(p,!1,!1,!0))}else s.push(e.parseWordFromString(l,o.quoted,o.singleQuoted,!0))}else if(e.check(y.LPAREN))e.error("syntax error near unexpected token `('");else break;let a=L.simpleCommand(r,s,n,i);return a.line=t,a}function kf(e){let t=e.expect(y.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,a=s.length;if(n[a]==="["){let f=0,d=a+1;for(;a<n.length;a++)if(n[a]==="[")f++;else if(n[a]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${n}`),i=n.slice(d,a),a++}let o=n[a]==="+";o&&a++,n[a]!=="="&&e.error(`Invalid assignment: ${n}`),a++;let l=n.slice(a);if(l==="("){let f=Xs(e);e.expect(y.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return L.assignment(d,null,o,f)}if(l===""&&e.check(y.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=Xs(e);e.expect(y.RPAREN);let h=i!==void 0?`${s}[${i}]`:s;return L.assignment(h,null,o,d)}}let c=l?e.parseWordFromString(l,t.quoted,t.singleQuoted,!0):null,u=i!==void 0?`${s}[${i}]`:s;return L.assignment(u,c,o,null)}var Nf=new Set([y.AMP,y.PIPE,y.PIPE_AMP,y.SEMICOLON,y.AND_AND,y.OR_OR,y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND]);function Xs(e){let t=[];for(e.skipNewlines();!e.check(y.RPAREN,y.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):Nf.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function Ys(e,t){e.expect(y.IF);let n=[],r=e.parseCompoundList();e.expect(y.THEN);let s=e.parseCompoundList();if(s.length===0){let o=e.check(y.FI)?"fi":e.check(y.ELSE)?"else":e.check(y.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${o}'`)}for(n.push({condition:r,body:s});e.check(y.ELIF);){e.advance();let o=e.parseCompoundList();e.expect(y.THEN);let l=e.parseCompoundList();if(l.length===0){let c=e.check(y.FI)?"fi":e.check(y.ELSE)?"else":e.check(y.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${c}'`)}n.push({condition:o,body:l})}let i=null;e.check(y.ELSE)&&(e.advance(),i=e.parseCompoundList(),i.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(y.FI);let a=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.ifNode(n,i,a)}function Js(e,t){let n=e.expect(y.FOR);if(e.check(y.DPAREN_START))return Df(e,t,n.line);e.isWord()||e.error("Expected variable name in for loop");let s=e.advance().value,i=null;if(e.skipNewlines(),e.check(y.IN))for(e.advance(),i=[];!e.check(y.SEMICOLON,y.NEWLINE,y.DO,y.EOF)&&e.isWord();)i.push(e.parseWord());e.check(y.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(y.DO);let a=e.parseCompoundList();e.expect(y.DONE);let o=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.forNode(s,i,a,o)}function Df(e,t,n){e.expect(y.DPAREN_START);let r=null,s=null,i=null,a=["","",""],o=0,l=0;for(;!e.check(y.DPAREN_END,y.EOF);){let f=e.advance();if(f.type===y.SEMICOLON&&l===0){if(o++,o>2)break}else f.value==="("&&l++,f.value===")"&&l--,a[o]+=f.value}e.expect(y.DPAREN_END),a[0].trim()&&(r=re(e,a[0].trim())),a[1].trim()&&(s=re(e,a[1].trim())),a[2].trim()&&(i=re(e,a[2].trim())),e.skipNewlines(),e.check(y.SEMICOLON)&&e.advance(),e.skipNewlines();let c;e.check(y.LBRACE)?(e.advance(),c=e.parseCompoundList(),e.expect(y.RBRACE)):(e.expect(y.DO),c=e.parseCompoundList(),e.expect(y.DONE));let u=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:s,update:i,body:c,redirections:u,line:n}}function ei(e,t){e.expect(y.WHILE);let n=e.parseCompoundList();e.expect(y.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(y.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.whileNode(n,r,s)}function ti(e,t){e.expect(y.UNTIL);let n=e.parseCompoundList();e.expect(y.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(y.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.untilNode(n,r,s)}function ni(e,t){e.expect(y.CASE),e.isWord()||e.error("Expected word after 'case'");let n=e.parseWord();e.skipNewlines(),e.expect(y.IN),e.skipNewlines();let r=[];for(;!e.check(y.ESAC,y.EOF);){e.checkIterationLimit();let i=e.getPos(),a=Rf(e);if(a&&r.push(a),e.skipNewlines(),e.getPos()===i&&!a)break}e.expect(y.ESAC);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.caseNode(n,r,s)}function Rf(e){e.check(y.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(y.PIPE));)e.advance();if(t.length===0)return null;e.expect(y.RPAREN),e.skipNewlines();let n=[];for(;!e.check(y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND,y.ESAC,y.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===y.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(y.LPAREN)&&e.peek(1).type===y.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(y.DSEMI)?(e.advance(),r=";;"):e.check(y.SEMI_AND)?(e.advance(),r=";&"):e.check(y.SEMI_SEMI_AND)&&(e.advance(),r=";;&"),L.caseItem(t,n,r)}function ri(e,t){e.expect(y.LPAREN);let n=e.parseCompoundList();e.expect(y.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.subshell(n,r)}function si(e,t){e.expect(y.LBRACE);let n=e.parseCompoundList();e.expect(y.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.group(n,r)}var If=["-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"],_f=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function _o(e){return e.isWord()||e.check(y.LBRACE)||e.check(y.RBRACE)||e.check(y.ASSIGNMENT_WORD)}function To(e){if(e.check(y.BANG)&&e.peek(1).type===y.LPAREN){e.advance(),e.advance();let t=1,n="!(";for(;t>0&&!e.check(y.EOF);)if(e.check(y.LPAREN))t++,n+="(",e.advance();else if(e.check(y.RPAREN))t--,t>0&&(n+=")"),e.advance();else if(e.isWord())n+=e.advance().value;else if(e.check(y.PIPE))n+="|",e.advance();else break;return n+=")",e.parseWordFromString(n,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function ai(e){return e.skipNewlines(),Tf(e)}function Tf(e){let t=Lo(e);for(e.skipNewlines();e.check(y.OR_OR);){e.advance(),e.skipNewlines();let n=Lo(e);t={type:"CondOr",left:t,right:n},e.skipNewlines()}return t}function Lo(e){let t=ii(e);for(e.skipNewlines();e.check(y.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(y.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:e.withDepth(()=>ii(e))}):Lf(e)}function Lf(e){if(e.check(y.LPAREN)){e.advance();let t=e.withDepth(()=>ai(e));return e.expect(y.RPAREN),{type:"CondGroup",expression:t}}if(_o(e)){let t=e.current(),n=t.value;if(If.includes(n)&&!t.quoted){if(e.advance(),e.check(y.DBRACK_END)&&e.error(`Expected operand after ${n}`),_o(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()&&_f.includes(e.current().value)){let s=e.advance().value,i;return s==="=~"?i=Mf(e):s==="=="||s==="!="?i=To(e):i=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:s,left:r,right:i}}if(e.check(y.LESS)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:r,right:s}}if(e.check(y.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=To(e);return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function Mf(e){let t=[],n=0,r=-1,s=e.getInput(),i=()=>e.check(y.DBRACK_END)||e.check(y.AND_AND)||e.check(y.OR_OR)||e.check(y.NEWLINE)||e.check(y.EOF);for(;!i();){let a=e.current(),o=r>=0&&a.start>r;if(n===0&&o)break;if(n>0&&o){let l=s.slice(r,a.start);t.push({type:"Literal",value:l})}if(e.isWord()||e.check(y.ASSIGNMENT_WORD)){let l=e.parseWordForRegex();t.push(...l.parts),r=e.peek(-1).end}else if(e.check(y.LPAREN)){let l=e.advance();t.push({type:"Literal",value:"("}),n++,r=l.end}else if(e.check(y.DPAREN_START)){let l=e.advance();t.push({type:"Literal",value:"(("}),n+=2,r=l.end}else if(e.check(y.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(y.RPAREN))if(n>0){let l=e.advance();t.push({type:"Literal",value:")"}),n--,r=l.end}else break;else if(e.check(y.PIPE)){let l=e.advance();t.push({type:"Literal",value:"|"}),r=l.end}else if(e.check(y.SEMICOLON))if(n>0){let l=e.advance();t.push({type:"Literal",value:";"}),r=l.end}else break;else if(n>0&&e.check(y.LESS)){let l=e.advance();t.push({type:"Literal",value:"<"}),r=l.end}else if(n>0&&e.check(y.GREAT)){let l=e.advance();t.push({type:"Literal",value:">"}),r=l.end}else if(n>0&&e.check(y.DGREAT)){let l=e.advance();t.push({type:"Literal",value:">>"}),r=l.end}else if(n>0&&e.check(y.DLESS)){let l=e.advance();t.push({type:"Literal",value:"<<"}),r=l.end}else if(n>0&&e.check(y.LESSAND)){let l=e.advance();t.push({type:"Literal",value:"<&"}),r=l.end}else if(n>0&&e.check(y.GREATAND)){let l=e.advance();t.push({type:"Literal",value:">&"}),r=l.end}else if(n>0&&e.check(y.LESSGREAT)){let l=e.advance();t.push({type:"Literal",value:"<>"}),r=l.end}else if(n>0&&e.check(y.CLOBBER)){let l=e.advance();t.push({type:"Literal",value:">|"}),r=l.end}else if(n>0&&e.check(y.TLESS)){let l=e.advance();t.push({type:"Literal",value:"<<<"}),r=l.end}else if(n>0&&e.check(y.AMP)){let l=e.advance();t.push({type:"Literal",value:"&"}),r=l.end}else if(n>0&&e.check(y.LBRACE)){let l=e.advance();t.push({type:"Literal",value:"{"}),r=l.end}else if(n>0&&e.check(y.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 Gn(e){return e.length>0?e:[L.literal("")]}function Wf(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 Ff(e,t,n){let r=n+1,s=t[r];if("@*#?$!-0123456789".includes(s))return{part:L.parameterExpansion(s),endIndex:r+1};let i="";for(;r<t.length&&/[a-zA-Z0-9_]/.test(t[r]);)i+=t[r],r++;return{part:L.parameterExpansion(i),endIndex:r}}function Vf(e,t,n,r=!1){let s=n+2,i=!1;t[s]==="!"&&(i=!0,s++);let a=!1;t[s]==="#"&&!/[}:#%/^,]/.test(t[s+1]||"}")&&(a=!0,s++);let o="",l=t[s];if(/[@*#?$!-]/.test(l)&&!/[a-zA-Z0-9_]/.test(t[s+1]||""))o=l,s++;else for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)o+=t[s],s++;if(t[s]==="["){let u=Hs(e,t,s,"[","]");if(o+=t.slice(s,u+1),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:L.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:d+1}}}if(o===""&&!i&&!a&&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:L.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let c=null;if(i){let u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=oi(e,t,s,o,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):(c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},o="")}else c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},o="";else if(t[s]==="*"||t[s]==="@"&&!/[QPaAEKkuUL]/.test(t[s+1]||"")){let f=t[s];s++,c={type:"VarNamePrefix",prefix:o,star:f==="*"},o=""}else if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=oi(e,t,s,o,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):c={type:"Indirection"}}else c={type:"Indirection"}}else if(a)if(t[s]===":")for(c={type:"LengthSliceError"};s<t.length&&t[s]!=="}";)s++;else t[s]!=="}"&&/[-+=?]/.test(t[s])?e.error(`\${#${o}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):t[s]==="/"?e.error(`\${#${o}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):c={type:"Length"};if(!c&&s<t.length&&t[s]!=="}"){let u=oi(e,t,s,o,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:L.parameterExpansion(o,c),endIndex:s+1}}function oi(e,t,n,r,s=!1){let i=n,a=t[i],o=t[i+1]||"";if(a===":"){let l=o;if("-=?+".includes(l)){i+=2;let b=an(e,t,i),g=t.slice(i,b),w=e.withDepth(()=>Ft(e,g,!1,!1,!0,!1,s,!1,!1,!0)),S=L.word(Gn(w));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=an(e,t,i),u=t.slice(i,c),f=-1,d=0,h=0;for(let E=0;E<u.length;E++){let b=u[E];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=E;break}}let p=f>=0?u.slice(0,f):u,m=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:Qs(e,p),length:m!==null?Qs(e,m):null},endIndex:c}}if("-=?+".includes(a)){i++;let l=an(e,t,i),c=t.slice(i,l),u=e.withDepth(()=>Ft(e,c,!1,!1,!0,!1,s,!1,!1,!0)),f=L.word(Gn(u));if(a==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:l};if(a==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:l};if(a==="?")return{operation:{type:"ErrorIfUnset",word:c?f:null,checkEmpty:!1},endIndex:l};if(a==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:l}}if(a==="#"||a==="%"){let l=o===a,c=a==="#"?"prefix":"suffix";i+=l?2:1;let u=an(e,t,i),f=t.slice(i,u),d=e.withDepth(()=>Ft(e,f,!1,!1,!1));return{operation:{type:"PatternRemoval",pattern:L.word(Gn(d)),side:c,greedy:l},endIndex:u}}if(a==="/"){let l=o==="/";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=ko(e,t,i);let f=t.slice(i,u),d=e.withDepth(()=>Ft(e,f,!1,!1,!1)),h=L.word(Gn(d)),p=null,m=u;if(t[u]==="/"){let E=u+1,b=an(e,t,E),g=t.slice(E,b),w=e.withDepth(()=>Ft(e,g,!1,!1,!1));p=L.word(Gn(w)),m=b}return{operation:{type:"PatternReplacement",pattern:h,replacement:p,all:l,anchor:c},endIndex:m}}if(a==="^"||a===","){let l=o===a,c=a==="^"?"upper":"lower";i+=l?2:1;let u=an(e,t,i),f=t.slice(i,u),d=f?L.word([L.literal(f)]):null;return{operation:{type:"CaseModification",direction:c,all:l,pattern:d},endIndex:u}}return a==="@"&&/[QPaAEKkuUL]/.test(o)?{operation:{type:"Transform",operator:o},endIndex:i+2}:{operation:null,endIndex:i}}function li(e,t,n,r=!1){let s=n+1;if(s>=t.length)return{part:L.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 a=1,o=s+1;for(;o<t.length&&a>0;)t[o]==="["?a++:t[o]==="]"&&a--,a>0&&o++;if(a===0){let l=t.slice(s+1,o),c=re(e,l);return{part:L.arithmeticExpansion(c),endIndex:o+1}}}return i==="("?e.parseCommandSubstitution(t,n):i==="{"?Vf(e,t,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?Ff(e,t,n):{part:L.literal("$"),endIndex:s}}function Mo(e,t){let n=[],r=0,s="",i=()=>{s&&(n.push(L.literal(s)),s="")};for(;r<t.length;){let a=t[r];if(a==="\\"&&r+1<t.length){let o=t[r+1];if(o==="$"||o==="`"||o==='"'||o==="\\"){s+=o,r+=2;continue}s+=a,r++;continue}if(a==="$"){i();let{part:o,endIndex:l}=li(e,t,r,!0);o&&n.push(o),r=l;continue}if(a==="`"){i();let{part:o,endIndex:l}=e.parseBacktickSubstitution(t,r,!0);n.push(o),r=l;continue}s+=a,r++}return i(),n}function zf(e,t,n){let r=[],s=n,i="",a=()=>{i&&(r.push(L.literal(i)),i="")};for(;s<t.length&&t[s]!=='"';){let o=t[s];if(o==="\\"&&s+1<t.length){let l=t[s+1];if('"\\$`\n'.includes(l)){i+=l,s+=2;continue}i+=o,s++;continue}if(o==="$"){a();let{part:l,endIndex:c}=li(e,t,s,!0);l&&r.push(l),s=c;continue}if(o==="`"){a();let{part:l,endIndex:c}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=c;continue}i+=o,s++}return a(),{part:L.doubleQuoted(r),endIndex:s}}function Ft(e,t,n=!1,r=!1,s=!1,i=!1,a=!1,o=!1,l=!1,c=!1){if(r)return[L.singleQuoted(t)];if(n){let p=Mo(e,t);return[L.doubleQuoted(p)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let p=t.slice(1,-1),m=!1;for(let E=0;E<p.length;E++){if(p[E]==='"'){m=!0;break}p[E]==="\\"&&E+1<p.length&&E++}if(!m){let E=Mo(e,p);return[L.doubleQuoted(E)]}}let u=[],f=0,d="",h=()=>{d&&(u.push(L.literal(d)),d="")};for(;f<t.length;){let p=t[f];if(p==="\\"&&f+1<t.length){let m=t[f+1];if(l){h(),u.push(L.escaped(m)),f+=2;continue}let E=i?m==="$"||m==="`"||m===`
62
+ `:m==="$"||m==="`"||m==='"'||m==="'"||m===`
63
+ `||c&&m==="}",b=a?"*?[]\\".includes(m):"*?[]\\(){}.^+".includes(m);E?d+=m:b?(h(),u.push(L.escaped(m))):d+=`\\${m}`,f+=2;continue}if(p==="'"&&!a&&!i){h();let m=t.indexOf("'",f+1);if(m===-1){d+=t.slice(f);break}u.push(L.singleQuoted(t.slice(f+1,m))),f=m+1;continue}if(p==='"'&&!i){h();let{part:m,endIndex:E}=zf(e,t,f+1);u.push(m),f=E+1;continue}if(p==="$"&&t[f+1]==="'"){h();let{part:m,endIndex:E}=Co(e,t,f+2);u.push(m),f=E;continue}if(p==="$"){h();let{part:m,endIndex:E}=li(e,t,f);m&&u.push(m),f=E;continue}if(p==="`"){h();let{part:m,endIndex:E}=e.parseBacktickSubstitution(t,f);u.push(m),f=E;continue}if(p==="~"){let m=f>0?t[f-1]:"";if(f===0||m==="="||s&&m===":"){let b=$o(e,t,f),g=t[b];if(g===void 0||g==="/"||g===":"){h();let w=t.slice(f+1,b)||null;u.push({type:"TildeExpansion",user:w}),f=b;continue}}}if("@*+?!".includes(p)&&f+1<t.length&&t[f+1]==="("){let m=Wf(t,f+1);if(m!==-1){h();let E=t.slice(f,m+1);u.push({type:"Glob",pattern:E}),f=m+1;continue}}if(p==="*"||p==="?"||p==="["){h();let{pattern:m,endIndex:E}=No(e,t,f);u.push({type:"Glob",pattern:m}),f=E;continue}if(p==="{"&&!s&&!o&&!i){let m=Do(e,t,f,Ft);if(m){h(),u.push(m.part),f=m.endIndex;continue}}d+=p,f++}return h(),u}var U=class e{tokens=[];pos=0;pendingHeredocs=[];parseBudget;ownsParseBudget;_input="";constructor(t){this.parseBudget=t??new Nr,this.ownsParseBudget=t===void 0}getInput(){return this._input}checkIterationLimit(){let t=this.current();this.parseBudget.chargeIteration(t?.line??1,t?.column??1)}enterDepth(){let t=this.current();return this.parseBudget.enter(t?.line??1,t?.column??1)}withDepth(t){let n=this.enterDepth();try{return t()}finally{n()}}parse(t,n){this.ownsParseBudget&&this.parseBudget.reset();let r=this.ownsParseBudget?void 0:this.enterDepth();try{if(t.length>js)throw new xe(`Input too large: ${t.length} bytes exceeds limit of ${js}`,1,1);this._input=t;let s=new kr(t,n);if(this.tokens=s.tokenize(),this.tokens.length>qn)throw new xe(`Too many tokens: ${this.tokens.length} exceeds limit of ${qn}`,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.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}check(t,n,r,s,...i){let a=this.tokens[this.pos]?.type;return a===t||n!==void 0&&a===n||r!==void 0&&a===r||s!==void 0&&a===s?!0:i.length>0?i.includes(a):!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(y.NEWLINE,y.COMMENT);)this.check(y.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(y.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(y.SEMICOLON,y.COMMENT)){this.advance();continue}if(t&&this.check(y.DSEMI,y.SEMI_AND,y.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(y.HEREDOC_CONTENT)){let n=this.advance(),r;t.quoted?r=L.word([L.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),t.redirect.target=L.hereDoc(t.delimiter,r,t.stripTabs,t.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(y.EOF,y.NEWLINE,y.SEMICOLON,y.AMP,y.AND_AND,y.OR_OR,y.RPAREN,y.RBRACE,y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return t===y.WORD||t===y.NAME||t===y.NUMBER||t===y.ASSIGNMENT_WORD||t===y.IF||t===y.FOR||t===y.WHILE||t===y.UNTIL||t===y.CASE||t===y.LPAREN||t===y.LBRACE||t===y.DPAREN_START||t===y.DBRACK_START||t===y.FUNCTION||t===y.BANG||t===y.TIME||t===y.IN||t===y.LESS||t===y.GREAT||t===y.DLESS||t===y.DGREAT||t===y.LESSAND||t===y.GREATAND||t===y.LESSGREAT||t===y.DLESSDASH||t===y.CLOBBER||t===y.TLESS||t===y.AND_GREAT||t===y.AND_DGREAT}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(y.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,a=this.parseStatement();a&&t.push(a),this.skipSeparators(!1),this.check(y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(y.EOF)&&this.advance()}return L.script(t)}checkUnexpectedToken(){let t=this.current().type,n=this.current().value;if((t===y.DO||t===y.DONE||t===y.THEN||t===y.ELSE||t===y.ELIF||t===y.FI||t===y.ESAC)&&this.error(`syntax error near unexpected token \`${n}'`),t===y.RBRACE||t===y.RPAREN){let r=`syntax error near unexpected token \`${n}'`;return this.advance(),L.statement([L.pipeline([L.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:n})}return(t===y.DSEMI||t===y.SEMI_AND||t===y.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),t===y.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`),(t===y.PIPE||t===y.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(y.AND_AND,y.OR_OR);){let l=this.advance();r.push(l.type===y.AND_AND?"&&":"||"),this.skipNewlines();let c=this.parsePipeline();n.push(c)}this.check(y.AMP)&&(this.advance(),s=!0);let a=this.pos>0?this.tokens[this.pos-1].end:t,o=this._input.slice(t,a);return L.statement(n,r,s,void 0,o)}parsePipeline(){let t=!1,n=!1;this.check(y.TIME)&&(this.advance(),t=!0,this.check(y.WORD,y.NAME)&&this.current().value==="-p"&&(this.advance(),n=!0));let r=0;for(;this.check(y.BANG);)this.advance(),r++;let s=r%2===1,i=[],a=[],o=this.parseCommand();for(i.push(o);this.check(y.PIPE,y.PIPE_AMP);){let l=this.advance();this.skipNewlines(),a.push(l.type===y.PIPE_AMP);let c=this.parseCommand();i.push(c)}return L.pipeline(i,s,t,n,a.length>0?a:void 0)}parseCommand(){return this.check(y.IF)?Ys(this):this.check(y.FOR)?Js(this):this.check(y.WHILE)?ei(this):this.check(y.UNTIL)?ti(this):this.check(y.CASE)?ni(this):this.check(y.LPAREN)?ri(this):this.check(y.LBRACE)?si(this):this.check(y.DPAREN_START)?this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand():this.check(y.DBRACK_START)?this.parseConditionalCommand():this.check(y.FUNCTION)?this.parseFunctionDef():this.check(y.NAME,y.WORD)&&this.peek(1).type===y.LPAREN&&this.peek(2).type===y.RPAREN?this.parseFunctionDef():Io(this)}dparenClosesWithSpacedParens(){let t=1,n=1;for(;n<this.tokens.length-this.pos;){let r=this.peek(n);if(r.type===y.EOF)return!1;if(r.type===y.DPAREN_START||r.type===y.LPAREN)t++;else if(r.type===y.DPAREN_END){if(t-=2,t<=0)return!1}else if(r.type===y.RPAREN&&(t--,t===0&&this.peek(n+1).type===y.RPAREN))return!0;n++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(y.RPAREN),this.expect(y.RPAREN);let n=this.parseOptionalRedirections(),r=L.subshell(t,[]);return L.subshell([L.statement([L.pipeline([r],!1,!1,!1)])],n)}isWord(){let t=this.current().type;return t===y.WORD||t===y.NAME||t===y.NUMBER||t===y.IF||t===y.FOR||t===y.WHILE||t===y.UNTIL||t===y.CASE||t===y.FUNCTION||t===y.ELSE||t===y.ELIF||t===y.FI||t===y.THEN||t===y.DO||t===y.DONE||t===y.ESAC||t===y.IN||t===y.SELECT||t===y.TIME||t===y.COPROC||t===y.BANG}parseWord(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted)}parseWordNoBraceExpansion(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0)}parseWordForRegex(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0,!0)}parseWordFromString(t,n=!1,r=!1,s=!1,i=!1,a=!1,o=!1){let l=Ft(this,t,n,r,s,i,!1,a,o);return L.word(l)}parseCommandSubstitution(t,n){return to(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseBacktickSubstitution(t,n,r=!1){return no(t,n,r,()=>new e(this.parseBudget),s=>this.error(s))}isDollarDparenSubshell(t,n){return eo(t,n)}parseArithmeticExpansion(t,n){let r=n+3,s=1,i=0,a=r;for(;a<t.length-1&&s>0;)t[a]==="$"&&t[a+1]==="("?t[a+2]==="("?(s++,a+=3):(i++,a+=2):t[a]==="("&&t[a+1]==="("?(s++,a+=2):t[a]===")"&&t[a+1]===")"?i>0?(i--,a++):(s--,s>0&&(a+=2)):t[a]==="("?(i++,a++):(t[a]===")"&&i>0&&i--,a++);let o=t.slice(r,a),l=this.parseArithmeticExpression(o);return{part:L.arithmeticExpansion(l),endIndex:a+2}}parseArithmeticCommand(){let t=this.expect(y.DPAREN_START),n="",r=1,s=0,i=!1,a=!1;for(;r>0&&!this.check(y.EOF);){if(i){if(i=!1,s>0){s--,n+=")";continue}if(this.check(y.RPAREN)){r--,a=!0,this.advance();continue}if(this.check(y.DPAREN_END)){r--,a=!0;continue}n+=")";continue}if(this.check(y.DPAREN_START))r++,n+="((",this.advance();else if(this.check(y.DPAREN_END))s>=2?(s-=2,n+="))",this.advance()):s===1?(s--,n+=")",i=!0,this.advance()):(r--,a=!0,r>0&&(n+="))"),this.advance());else if(this.check(y.LPAREN))s++,n+="(",this.advance();else if(this.check(y.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()}}a||this.expect(y.DPAREN_END);let o=this.parseArithmeticExpression(n.trim()),l=this.parseOptionalRedirections();return L.arithmeticCommand(o,l,t.line)}parseConditionalCommand(){let t=this.expect(y.DBRACK_START),n=ai(this);this.expect(y.DBRACK_END);let r=this.parseOptionalRedirections();return L.conditionalCommand(n,r,t.line)}parseFunctionDef(){let t;if(this.check(y.FUNCTION)){if(this.advance(),this.check(y.NAME)||this.check(y.WORD))t=this.advance().value;else{let s=this.current();throw new xe("Expected function name",s.line,s.column,s)}this.check(y.LPAREN)&&(this.advance(),this.expect(y.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(y.LPAREN),this.expect(y.RPAREN);this.skipNewlines();let n=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return L.functionDef(t,n,r)}parseCompoundCommandBody(t){let n=t?.forFunctionBody;if(this.check(y.LBRACE))return si(this,{skipRedirections:n});if(this.check(y.LPAREN))return ri(this,{skipRedirections:n});if(this.check(y.IF))return Ys(this,{skipRedirections:n});if(this.check(y.FOR))return Js(this,{skipRedirections:n});if(this.check(y.WHILE))return ei(this,{skipRedirections:n});if(this.check(y.UNTIL))return ti(this,{skipRedirections:n});if(this.check(y.CASE))return ni(this,{skipRedirections:n});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth();try{let n=[];for(this.skipNewlines();!this.check(y.EOF,y.FI,y.ELSE,y.ELIF,y.THEN,y.DO,y.DONE,y.ESAC,y.RPAREN,y.RBRACE,y.DSEMI,y.SEMI_AND,y.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(;Rr(this);){this.checkIterationLimit();let n=this.pos;if(t.push(Or(this)),this.pos===n)break}return t}parseArithmeticExpression(t){return re(this,t)}};function qe(e,t){return new U().parse(e,t)}var Uf="BASH_ALIAS_";function Ir(e,t,n,r){let s=M(t);if(s>n-r.value)throw new P(`alias expansion exceeds string length limit (${n} bytes)`,"string_length");return r.value+=s,e+t}function Bo(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function Wo(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function Fo(e,t){return e.env.get(`${Uf}${t}`)}function zo(e,t,n){return qo(e,t,n)}function qo(e,t,n,r=!0){if(!t.name||!Bo(t.name))return t;let s=Wo(t.name);if(!s)return t;let i=Fo(e,s);if(!i||n.has(s))return t;try{n.add(s);let a=new U,o={value:0},l=Ir("",i,e.limits.maxStringLength,o),c=i.endsWith(" ");if(!c)for(let h of t.args){let p=Uo(h);l=Ir(l,` ${p}`,e.limits.maxStringLength,o)}let u;try{u=a.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 Vo(e,t,i);let f=u.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return Vo(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(!Bo(p))break;let m=Wo(p),E=m?Fo(e,m):null;if(!E)break;if(h>=e.limits.maxCallDepth)throw new P(`alias expansion depth limit exceeded (${e.limits.maxCallDepth})`,"recursion");h++;let b={type:"SimpleCommand",name:p,args:d.args.slice(1),assignments:[],redirections:[]},g=qo(e,b,n,!1);if(g===b||(d={...d,name:g.name,args:[...g.args]},!E.endsWith(" ")))break}}return d}catch(a){throw n.delete(s),a}}function Vo(e,t,n){let r={value:0},s=Ir("",n,e.limits.maxStringLength,r);for(let c of t.args){let u=Uo(c);s=Ir(s,` ${u}`,e.limits.maxStringLength,r)}let i=new U,a=i.parseWordFromString("eval",!1,!1),o=0;for(let c of s)c==="'"&&o++;if(r.value+2+o*3>e.limits.maxStringLength)throw new P(`alias expansion exceeds string length limit (${e.limits.maxStringLength} bytes)`,"string_length");let l=i.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:a,args:[l],assignments:t.assignments,redirections:t.redirections,line:t.line}}function Uo(e){let t="";for(let n of e.parts)switch(n.type){case"Literal":t+=n.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${n.value}'`;break;case"DoubleQuoted":t+=`"${n.parts.map(r=>r.type==="Literal"?r.value:`$${r.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${n.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${n.expression}))`;break;case"Glob":t+=n.pattern;break;default:break}return t}var jf=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 ci(e){return jf.get(e)??""}function jo(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 Go(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 a=s;for(;a<e.length;){if(e[a]==="\\"&&a+1<e.length){a+=2;continue}if(e[a]==="["&&a+1<e.length&&e[a+1]===":"){let l=e.indexOf(":]",a+2);if(l!==-1){a=l+2;continue}}if(e[a]==="]")break;a++}let o=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=ci(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===o,c=s+1===a;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+="$",ye(t)}function ui(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 a=e[i];if(a==="'"&&!s){s=!0,n+="\0QUOTE_START\0",i++;continue}if(a==="'"&&s){s=!1,n+="\0QUOTE_END\0",i++;continue}if(s){n+=a,i++;continue}if(a==="\\"){n+=a,i+1<e.length?(n+=e[i+1],i+=2):i++;continue}a==="("?(r++,n+=a):a===")"?(r--,n+=a):a==="|"&&r===0?(t.push(n),n=""):n+=a,i++}return t.push(n),t}var Zo=5,Vt=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=jo(i))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new P(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations");this.consumeOperation?.()}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(n=>{let r=n.split("/").pop()||n;if((this.hasGlobignore||this.globskipdots)&&(r==="."||r===".."))return!1;if(this.hasGlobignore){for(let s of this.globignorePatterns)if(this.matchGlobignorePattern(n,s))return!1}return!0})}matchGlobignorePattern(t,n){return Go(n).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,n){let r=t.map((a,o)=>(n?.[o]??!1)||!this.isGlobPattern(a)?null:this.expand(a)),s=await Promise.all(r.map(a=>a||Promise.resolve(null))),i=[];for(let a=0;a<t.length;a++){let o=s[a];o===null?i.push(t[a]):o.length>0?i.push(...o):i.push(t[a])}return i}async expand(t){if(this.globstar){let r=t.split("/"),s=0;for(let i of r)if(i==="**"&&(s++,s>Zo))throw new P(`Glob pattern has too many ** segments (max ${Zo})`,"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,a;if(s===0)n?(i="/",a="/"):(i=this.cwd,a="");else{let c=r.slice(0,s);n?(i=`/${c.join("/")}`,a=`/${c.join("/")}`):(i=this.fs.resolvePath(this.cwd,c.join("/")),a=c.join("/"))}let o=r.slice(s);return(await this.expandSegments(i,a,o)).sort()}async expandSegments(t,n,r){if(this.checkOpsLimit(),r.length===0)return[n];let[s,...i]=r,a=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let o=await this.fs.readdirWithFileTypes(t),l=[],c=[...o],u=this.dotglob||this.hasGlobignore;if(s.startsWith(".")||this.dotglob){let d=o.some(p=>p.name==="."),h=o.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)a.push(...d)}else{this.checkOpsLimit();let o=await this.fs.readdir(t),l=[],c=[...o],u=this.dotglob||this.hasGlobignore;(s.startsWith(".")||this.dotglob)&&(o.includes(".")||c.push("."),o.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 P)throw m}return[]})())}let f=await Promise.all(l);for(let d of f)a.push(...d)}}catch(o){if(o instanceof P)throw o}return a}async expandRecursive(t){let n=[],r=t.indexOf("**"),s=t.slice(0,r).replace(/\/$/,"")||".",a=t.slice(r+2).replace(/^\//,"");return a.includes("**")&&this.isGlobstarValid(a)?(await this.walkDirectoryMultiGlobstar(s,a,n),[...new Set(n)].sort()):(await this.walkDirectory(s,a,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 a=[];for(let c of i){let u=t==="."?c.name:`${t}/${c.name}`;c.isDirectory&&a.push(u)}let o=t==="."?n:`${t}/${n}`,l=await this.expandRecursive(o);r.push(...l);for(let c=0;c<a.length;c+=100){let u=a.slice(c,c+100);await Promise.all(u.map(f=>this.walkDirectoryMultiGlobstar(f,n,r)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(s),o=[];for(let u of a){let f=t==="."?u:`${t}/${u}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&o.push(f)}catch(h){if(h instanceof P)throw h}}let l=t==="."?n:`${t}/${n}`,c=await this.expandRecursive(l);r.push(...c);for(let u=0;u<o.length;u+=100){let f=o.slice(u,u+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,n,r)))}}}catch(i){if(i instanceof P)throw i}}async walkDirectory(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let i=await this.fs.readdirWithFileTypes(s),a=[],o=[];for(let l of i){let c=t==="."?l.name:`${t}/${l.name}`;l.isDirectory?o.push(c):n&&this.matchPattern(l.name,n)&&a.push(c)}r.push(...a);for(let l=0;l<o.length;l+=100){let c=o.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),a=[];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 P)throw p;return null}}));a.push(...u.filter(f=>f!==null))}for(let l of a)!l.isDirectory&&n&&this.matchPattern(l.name,n)&&r.push(l.path);let o=a.filter(l=>l.isDirectory);for(let l=0;l<o.length;l+=100){let c=o.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,n,r)))}}}catch(i){if(i instanceof P)throw i}}matchPattern(t,n){return this.patternToRegex(n).test(t)}patternToRegex(t){let n=this.patternToRegexStr(t);return ye(`^${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 a=ui(t,s+1);if(a!==-1){let o=t.slice(s+2,a),l=fi(o),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(a<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=a;continue}}if(i==="*")n+=".*";else if(i==="?")n+=".";else if(i==="["){let a=s+1,o="[";a<t.length&&(t[a]==="^"||t[a]==="!")&&(o+="^",a++),a<t.length&&t[a]==="]"&&(o+="\\]",a++);let l=a;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=a;for(;a<t.length&&t[a]!=="]";){if(t[a]==="["&&a+1<t.length&&t[a+1]===":"){let u=t.indexOf(":]",a+2);if(u!==-1){let f=t.slice(a+2,u),d=ci(f);o+=d,a=u+2;continue}}if(t[a]==="\\"&&a+1<t.length){o+=`\\${t[a+1]}`,a+=2;continue}if(t[a]==="-"){let u=a===c,f=a+1===l;u||f?o+="\\-":o+="-"}else o+=t[a];a++}o+="]",n+=o,s=a}else if(i==="\\"&&s+1<t.length){let a=t[s+1];/[.+^${}()|\\*?[\]]/.test(a)?n+=`\\${a}`:n+=a,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 a=ui(t,r+1);if(a!==-1){if(i==="@"){let o=t.slice(r+2,a),c=fi(o).map(u=>this.computePatternLength(u));if(c.every(u=>u!==null)&&c.every(u=>u===c[0])){n+=c[0],r=a+1;continue}return null}return null}}if(i==="*")return null;if(i==="?"){n+=1,r++;continue}if(i==="["){let a=t.indexOf("]",r+1);if(a!==-1){n+=1,r=a+1;continue}n+=1,r++;continue}if(i==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}};function di(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 Gf(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 Ho(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 Zn(e){let t=!1,n=!1,r=!1,s=!1,i=!1,a=!1,o=!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")&&(a=!0),c.operation?.type==="Indirection"&&(o=!0));l.type==="CommandSubstitution"&&(n=!0),l.type==="ParameterExpansion"&&(i=!0,(l.parameter==="@"||l.parameter==="*")&&(r=!0),Gf(l)&&(t=!0),(l.operation?.type==="VarNamePrefix"||l.operation?.type==="ArrayKeys")&&(a=!0),l.operation?.type==="Indirection"&&(o=!0)),l.type==="Glob"&&di(l.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i,hasVarNamePrefixExpansion:a,hasIndirection:o}}var Zf=`
64
+ `;function on(e,t){if(e>=t)throw new P(`array element limit exceeded (${t})`,"array_elements")}function hi(e,t,n,r,s){on(e.length,s),on(t.length,s),e.push(n),t.push(r)}function ve(e){return e.get("IFS")??Zf}function Ce(e){return e.get("IFS")===""}function _r(e){let t=ve(e);if(t==="")return!0;for(let n of t)if(n!==" "&&n!==" "&&n!==`
65
+ `)return!1;return!0}function Qo(e){let t=!1,n=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?n.push(`\\${r}`):r===" "?n.push("\\t"):r===`
66
+ `?n.push("\\n"):n.push(r);return t&&n.push("\\-"),n.join("")}function Z(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var Hf=`
67
+ `;function Qf(e){return Hf.includes(e)}function pi(e){let t=new Set,n=new Set;for(let r of e)Qf(r)?t.add(r):n.add(r);return{whitespace:t,nonWhitespace:n}}function mi(e,t,n,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:(on(0,n),{words:[e],wordStarts:[0]});let{whitespace:i,nonWhitespace:a}=pi(t),o=[],l=[],c=0;for(;c<e.length&&i.has(e[c]);)c++;if(c>=e.length)return{words:[],wordStarts:[]};if(a.has(e[c]))for(hi(o,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&!(r!==void 0&&o.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)||a.has(f))break;c++}if(hi(o,l,e.substring(u,c),u,n),c>=e.length)break;for(;c<e.length&&i.has(e[c]);)c++;if(c<e.length&&a.has(e[c])){for(c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&a.has(e[c])&&!(r!==void 0&&o.length>=r);)for(hi(o,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++}}return{words:o,wordStarts:l}}function Tr(e,t,n){if(t==="")return e&&on(0,n),{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=pi(t),i=[],a=0,o=!1,l=!1,c=a;for(;a<e.length&&r.has(e[a]);)a++;if(a>c&&(o=!0),a>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[a]))for(on(i.length,n),i.push(""),a++;a<e.length&&r.has(e[a]);)a++;for(;a<e.length;){let u=a;for(;a<e.length;){let d=e[a];if(r.has(d)||s.has(d))break;a++}if(on(i.length,n),i.push(e.substring(u,a)),a>=e.length){l=!1;break}let f=a;for(;a<e.length&&r.has(e[a]);)a++;if(a<e.length&&s.has(e[a])){for(a++;a<e.length&&r.has(e[a]);)a++;for(;a<e.length&&s.has(e[a]);)for(on(i.length,n),i.push(""),a++;a<e.length&&r.has(e[a]);)a++}a>=e.length&&a>f&&(l=!0)}return{words:i,hadLeadingDelimiter:o,hadTrailingDelimiter:l}}function ue(e,t,n){return Tr(e,t,n).words}function Kf(e,t){for(let n of e)if(t.has(n))return!0;return!1}function Ko(e,t,n){if(t==="")return e;let{whitespace:r,nonWhitespace:s}=pi(t),i=e.length;for(;i>0&&r.has(e[i-1]);){if(!n&&i>=2){let o=0,l=i-2;for(;l>=0&&e[l]==="\\";)o++,l--;if(o%2===1)break}i--}let a=e.substring(0,i);if(a.length>=1&&s.has(a[a.length-1])){if(!n&&a.length>=2){let l=0,c=a.length-2;for(;c>=0&&a[c]==="\\";)l++,c--;if(l%2===1)return a}let o=a.substring(0,a.length-1);if(!Kf(o,s))return o}return a}function le(e,t){return e.state.namerefs?.has(t)??!1}function kt(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function Xo(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Yo(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function Jo(e,t){return e.state.invalidNamerefs?.has(t)??!1}function yi(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function Lr(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let s=n[1],i=Ne(e,s),a=e.state.associativeArrays?.has(s)??!1;return i||a}return Ne(e,t)?!0:e.state.env.has(t)}function Te(e,t,n=100){if(!le(e,t)||Jo(e,t))return t;let r=new Set,s=t;for(;n-- >0;){if(r.has(s))return;if(r.add(s),!le(e,s))return s;let i=e.state.env.get(s);if(i===void 0||i===""||!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(i))return s;s=i}}function ln(e,t){if(le(e,t))return e.state.env.get(t)}function Mr(e,t,n,r=100){if(!le(e,t)||Jo(e,t))return t;let s=new Set,i=t;for(;r-- >0;){if(s.has(i))return;if(s.add(i),!le(e,i))return i;let a=e.state.env.get(i);if(a===void 0||a==="")return n!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)&&Lr(e,n)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(a))return i;i=a}}function el(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 j(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((i,a)=>[a,i]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((i,a)=>[a,String(i)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((i,a)=>[a,i]):e.state.associativeArrays?.has(t)?mt(e,t).map(i=>[i,ae(e,t,i)??""]):Se(e,t).map(s=>[s,ae(e,t,s)??""])}function at(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,r=!1){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 a="";return a+="h",e.state.options.errexit&&(a+="e"),e.state.options.noglob&&(a+="f"),e.state.options.nounset&&(a+="u"),e.state.options.verbose&&(a+="v"),e.state.options.xtrace&&(a+="x"),a+="B",e.state.options.noclobber&&(a+="C"),a+="s",a}case"*":{let a=Number.parseInt(e.state.env.get("#")||"0",10);if(a===0)return"";let o=[];for(let l=1;l<=a;l++)o.push(e.state.env.get(String(l))||"");return o.join(Z(e.state.env))}case"0":return e.state.env.get("0")||"bash";case"PWD":return e.state.env.get("PWD")??"";case"OLDPWD":return e.state.env.get("OLDPWD")??"";case"PPID":return String(e.state.virtualPpid);case"UID":return String(e.state.virtualUid);case"EUID":return String(e.state.virtualUid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-e.state.startTime)/1e3));case"BASH_VERSION":return Xa;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let a=e.state.funcNameStack?.[0];if(a!==void 0)return a;if(n&&e.state.options.nounset)throw new Be("FUNCNAME");return""}case"BASH_LINENO":{let a=e.state.callLineStack?.[0];if(a!==void 0)return String(a);if(n&&e.state.options.nounset)throw new Be("BASH_LINENO");return""}case"BASH_SOURCE":{let a=e.state.sourceStack?.[0];if(a!==void 0)return a;if(n&&e.state.options.nounset)throw new Be("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new Qe(`\${${t}}`);let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let a=s[1],o=s[2];if(le(e,a)){let f=Te(e,a);if(f&&f!==a){if(f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";a=f}}if(o==="@"||o==="*"){let f=j(e,a);if(f.length>0)return f.map(([,h])=>h).join(" ");let d=e.state.env.get(a);return d!==void 0?d:""}if(a==="FUNCNAME"){let f=Number.parseInt(o,10);return!Number.isNaN(f)&&f>=0?e.state.funcNameStack?.[f]??"":""}if(a==="BASH_LINENO"){let f=Number.parseInt(o,10);if(!Number.isNaN(f)&&f>=0){let d=e.state.callLineStack?.[f];return d!==void 0?String(d):""}return""}if(a==="BASH_SOURCE"){let f=Number.parseInt(o,10);return!Number.isNaN(f)&&f>=0?e.state.sourceStack?.[f]??"":""}if(e.state.associativeArrays?.has(a)){let f=$r(o);f=el(e,f);let d=ae(e,a,f);if(d===void 0&&n&&e.state.options.nounset)throw new Be(`${a}[${o}]`);return d||""}let c;if(/^-?\d+$/.test(o))c=Number.parseInt(o,10);else try{let f=new U,d=re(f,o);c=await K(e,d.expression)}catch{let f=e.state.env.get(o);c=f?Number.parseInt(f,10):0,Number.isNaN(c)&&(c=0)}if(c<0){let f=j(e,a),d=e.state.currentLine;if(f.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${a}: bad array subscript
68
+ `,"";let p=Math.max(...f.map(([E])=>typeof E=="number"?E:0))+1+c;return p<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${a}: bad array subscript
69
+ `,""):ae(e,a,p)||""}let u=ae(e,a,c);if(u!==void 0)return u;if(c===0){let f=e.state.env.get(a);if(f!==void 0)return f}if(n&&e.state.options.nounset)throw new Be(`${a}[${c}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let a=e.state.env.get(t);if(a===void 0&&n&&e.state.options.nounset)throw new Be(t);return a||""}if(le(e,t)){let a=Te(e,t);if(a===void 0)return"";if(a!==t)return await ie(e,a,n,r);let o=e.state.env.get(t);if((o===void 0||o==="")&&n&&e.state.options.nounset)throw new Be(t);return o||""}let i=e.state.env.get(t);if(i!==void 0)return e.state.tempEnvBindings?.some(a=>a.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),i;if(at(e,t)){let a=ae(e,t,0);if(a!==void 0)return a;if(n&&e.state.options.nounset)throw new Be(t);return""}if(n&&e.state.options.nounset)throw new Be(t);return""}async function gt(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let s=r[1],i=r[2];if(le(e,s)){let l=Te(e,s);if(l&&l!==s){if(l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;s=l}}if(i==="@"||i==="*")return j(e,s).length>0?!0:e.state.env.has(s);if(e.state.associativeArrays?.has(s)){let l=el(e,$r(i));return Bt(e,s,l)}let o;if(/^-?\d+$/.test(i))o=Number.parseInt(i,10);else try{let l=new U,c=re(l,i);o=await K(e,c.expression)}catch{let l=e.state.env.get(i);o=l?Number.parseInt(l,10):0,Number.isNaN(o)&&(o=0)}if(o<0){let l=j(e,s);if(l.length===0)return!1;let u=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+o;return u<0?!1:Bt(e,s,u)}return Bt(e,s,o)}if(le(e,t)){let s=Te(e,t);return s===void 0||s===t?e.state.env.has(t):gt(e,s)}return e.state.env.has(t)?!0:at(e,t)?Bt(e,t,0):!1}async function tl(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),a=await ie(e,i);n+=a,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),a=await ie(e,i);n+=a,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),a=await ie(e,i);n+=a,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 gi(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="",a=0;for(;a<n.length;)if(n[a]==="$")if(n[a+1]==="("){let o=1,l=a+2;for(;l<n.length&&o>0;)n[l]==="("&&n[l-1]==="$"||n[l]==="("?o++:n[l]===")"&&o--,l++;let c=n.slice(a+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)}a=l}else if(n[a+1]==="{"){let o=1,l=a+2;for(;l<n.length&&o>0;)n[l]==="{"?o++:n[l]==="}"&&o--,l++;let c=n.slice(a+2,l-1),u=await ie(e,c);i+=u,a=l}else if(/[a-zA-Z_]/.test(n[a+1]||"")){let o=a+1;for(;o<n.length&&/[a-zA-Z0-9_]/.test(n[o]);)o++;let l=n.slice(a+1,o),c=await ie(e,l);i+=c,a=o}else i+=n[a],a++;else if(n[a]==="`"){let o=a+1;for(;o<n.length&&n[o]!=="`";)o++;let l=n.slice(a+1,o);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)}a=o+1}else i+=n[a],a++;return i}var Hn=1e4,wi={maxResults:Hn,maxStringBytes:10*1024*1024};function Br(e,t,n,r){if(e.length>=n.maxResults)return!1;let s=M(t);if(s>n.maxStringBytes-r.value)throw new P(`brace expansion string limit exceeded (${n.maxStringBytes} bytes)`,"string_length");return e.push(t),r.value+=s,!0}function Xf(e,t,n,r,s,i=wi){let a=n??1;a===0&&(a=1);let o=Math.abs(a),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 P(`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<Hn&&Br(l,f(d),i,u);d+=o,h++);else for(let d=e,h=0;d>=t&&h<Hn&&Br(l,f(d),i,u);d-=o,h++);return l}function Yf(e,t,n,r=wi){let s=n??1;s===0&&(s=1);let i=e.charCodeAt(0),a=t.charCodeAt(0),o=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 gr(`{${e}..${t}${p}}: invalid sequence`)}let d=[],h={value:0};if(i<=a)for(let p=i,m=0;p<=a&&m<Hn&&Br(d,String.fromCharCode(p),r,h);p+=o,m++);else for(let p=i,m=0;p>=a&&m<Hn&&Br(d,String.fromCharCode(p),r,h);p-=o,m++);return d}function Ei(e,t,n,r,s,i=wi){let a=n!==void 0?`..${n}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:Xf(e,t,n,r,s,i),literal:`{${e}..${t}${a}}`}:typeof e=="string"&&typeof t=="string"?{expanded:Yf(e,t,n,i),literal:`{${e}..${t}${a}}`}:{expanded:null,literal:`{${e}..${t}${a}}`}}function nl(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 wt(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function bi(e){let t="",n=0;for(;n<e.length;)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);return t}function Xe(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function Qn(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function te(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function X(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 a=Jf(e,s+1);if(a!==-1){let o=e.slice(s+2,a),c=ed(o).map(f=>X(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=a+1;continue}}if(i==="\\")if(s+1<e.length){let a=e[s+1];/[\\^$.|+(){}[\]*?]/.test(a)?r+=`\\${a}`:r+=a,s+=2}else r+="\\\\",s++;else if(i==="*")r+=t?".*":".*?",s++;else if(i==="?")r+=".",s++;else if(i==="["){let a=td(e,s);if(a===-1)r+="\\[",s++;else{let o=e.slice(s+1,a);r+=nd(o),s=a+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,s++):(r+=i,s++)}return r}function Jf(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 ed(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 td(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 nd(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 a of i)a==="\\"?t+="\\\\":a==="]"?t+="\\]":a==="^"&&t==="["?t+="\\^":t+=a;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+=sd(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 rd=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 sd(e){return rd.get(e)??""}function ot(e,t,n,r,s){if(r==="prefix")return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),ye(`^${n}`,"s").replace(t,"");let i=ye(`${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 a=ye(`^(?:.*)(${n})$`,"s").exec(t);if(!a)return t;let o=a[1]??"";return t.slice(0,t.length-o.length)}function bn(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 Wr(e,t,n,r,s){let i=new hn(e.limits.maxStringLength,"pattern replacement",()=>new P(`pattern replacement: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length"));n.lastIndex=0;let a=0,o=n.exec(t);for(;o!==null&&(e.executionScope.consumeLimited("pattern_operations",1,e.limits.maxGlobOperations,"pattern replacement"),!(s&&o[0].length===0&&o.index===t.length||(i.append(t.slice(a,o.index)),i.append(r),a=o.index+o[0].length,!s)));)o[0].length===0&&(a++,n.lastIndex<=o.index&&(n.lastIndex=o.index+1)),o=n.exec(t);return i.append(t.slice(a)),n.lastIndex=0,i.build()}function rl(e){let t=[],n=0;return{append(r){let s=M(r);if(s>e-n)throw new P(`prompt expansion exceeds string length limit (${e} bytes)`,"string_length");r&&t.push(r),n+=s},build:()=>t.join("")}}function id(e,t,n){let r=(a,o=2)=>String(a).padStart(o,"0");if(e===""){let a=r(t.getHours()),o=r(t.getMinutes()),l=r(t.getSeconds());return`${a}:${o}:${l}`}let s=rl(n),i=0;for(;i<e.length;)if(e[i]==="%"){if(i+1>=e.length){s.append("%"),i++;continue}let a=e[i+1];switch(a){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 o=t.getHours()%12;o===0&&(o=12),s.append(r(o));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 o=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];s.append(o[t.getDay()]);break}case"b":{let o=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];s.append(o[t.getMonth()]);break}default:s.append(`%${a}`)}i+=2}else s.append(e[i]),i++;return s.build()}function Kn(e,t){let n=rl(e.limits.maxStringLength),r=0,s=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",i=e.state.env.get("HOSTNAME")||"localhost",a=i.split(".")[0],o=e.state.env.get("PWD")||"/",l=e.state.env.get("HOME")||"/",c=o.startsWith(l)?`~${o.slice(l.length)}`:o,u=o.split("/").pop()||o,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 b="",g=r+1;for(;g<t.length&&g<r+4&&t[g]>="0"&&t[g]<="7";)b+=t[g],g++;let w=Number.parseInt(b,8)%256;n.append(String.fromCharCode(w)),r=g;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(`
70
+ `),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(a),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"),g=String(f.getMinutes()).padStart(2,"0"),w=String(f.getSeconds()).padStart(2,"0");n.append(`${b}:${g}:${w}`),r+=2;break}case"T":{let b=f.getHours()%12;b===0&&(b=12);let g=String(b).padStart(2,"0"),w=String(f.getMinutes()).padStart(2,"0"),S=String(f.getSeconds()).padStart(2,"0");n.append(`${g}:${w}:${S}`),r+=2;break}case"@":{let b=f.getHours()%12;b===0&&(b=12);let g=String(b).padStart(2,"0"),w=String(f.getMinutes()).padStart(2,"0"),S=f.getHours()<12?"AM":"PM";n.append(`${g}:${w} ${S}`),r+=2;break}case"A":{let b=String(f.getHours()).padStart(2,"0"),g=String(f.getMinutes()).padStart(2,"0");n.append(`${b}:${g}`),r+=2;break}case"D":if(r+2<t.length&&t[r+2]==="{"){let b=t.indexOf("}",r+3);if(b!==-1){let g=t.slice(r+3,b);n.append(id(g,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(`\\${E}`),r+=2}}else n.append(m),r++}return n.build()}function zt(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`
71
+ `: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 Ue(e,t){e.state.readonlyVars=e.state.readonlyVars||new Set,e.state.readonlyVars.add(t)}function Le(e,t){return e.state.readonlyVars?.has(t)??!1}function ce(e,t,n="bash"){if(Le(e,t)){let r=`${n}: ${t}: readonly variable
72
+ `;throw new H(1,"",r)}return null}function lt(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 Fr(e,t){e.state.exportedVars?.delete(t)}function qt(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let n="",r=Ae(e,t)?.kind==="indexed",s=e.state.associativeArrays?.has(t)??!1;return r&&!s&&(n+="a"),s&&(n+="A"),e.state.integerVars?.has(t)&&(n+="i"),le(e,t)&&(n+="n"),Le(e,t)&&(n+="r"),e.state.exportedVars?.has(t)&&(n+="x"),n}async function sl(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}async function il(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:assign_default"),(r.isUnset||n.checkEmpty&&r.isEmpty)&&n.word){let a=await s(e,n.word.parts,r.inDoubleQuotes),o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let[,l,c]=o,u;if(/^\d+$/.test(c))u=Number.parseInt(c,10);else{try{let f=new U,d=re(f,c);u=await K(e,d.expression)}catch{let f=e.state.env.get(c);u=f?Number.parseInt(f,10):0}Number.isNaN(u)&&(u=0)}q(e,l,u,a)}else e.state.env.set(t,a);return a}return r.effectiveValue}async function al(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:error_if_unset"),r.isUnset||n.checkEmpty&&r.isEmpty){let a=n.word?await s(e,n.word.parts,r.inDoubleQuotes):`${t}: parameter null or not set`;throw new H(1,"",`bash: ${a}
73
+ `)}return r.effectiveValue}async function ol(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 ll(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_removal");let i="",a=e.state.shoptOptions.extglob;if(n.pattern)for(let o of n.pattern.parts)if(o.type==="Glob")i+=X(o.pattern,n.greedy,a);else if(o.type==="Literal")i+=X(o.value,n.greedy,a);else if(o.type==="SingleQuoted"||o.type==="Escaped")i+=te(o.value);else if(o.type==="DoubleQuoted"){let l=await r(e,o.parts);i+=te(l)}else if(o.type==="ParameterExpansion"){let l=await s(e,o);i+=X(l,n.greedy,a)}else{let l=await s(e,o);i+=te(l)}return ot(e,t,i,n.side,n.greedy)}async function cl(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",a=e.state.shoptOptions.extglob;if(n.pattern)for(let c of n.pattern.parts)if(c.type==="Glob")i+=X(c.pattern,!0,a);else if(c.type==="Literal")i+=X(c.value,!0,a);else if(c.type==="SingleQuoted"||c.type==="Escaped")i+=te(c.value);else if(c.type==="DoubleQuoted"){let u=await r(e,c.parts);i+=te(u)}else if(c.type==="ParameterExpansion"){let u=await s(e,c);i+=X(u,!0,a)}else{let u=await s(e,c);i+=te(u)}let o=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=ye(i,l);return Wr(e,t,c,o,n.all)}catch(c){if(c instanceof P)throw c;return t}}function ul(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=j(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)&&at(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 fl(e,t,n,r){e.coverage?.hit("bash:expansion:substring");let s=await K(e,r.offset.expression),i=r.length?await K(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 a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(a){let c=a[1];if(e.state.associativeArrays?.has(c))throw new H(1,"",`bash: \${${c}[@]: 0: 3}: bad substitution
74
+ `);let u=j(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 oe(`${a[1]}[@]: substring expression < 0`);return u.slice(f,f+i).map(([,d])=>d).join(" ")}return u.slice(f).map(([,d])=>d).join(" ")}let o=[...n],l=s;if(l<0&&(l=Math.max(0,o.length+l)),i!==void 0){if(i<0){let c=o.length+i;return o.slice(l,Math.max(l,c)).join("")}return o.slice(l,l+i).join("")}return o.slice(l).join("")}async function dl(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:case_modification"),n.pattern){let i=e.state.shoptOptions.extglob,a="";for(let f of n.pattern.parts)if(f.type==="Glob")a+=X(f.pattern,!0,i);else if(f.type==="Literal")a+=X(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")a+=te(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);a+=te(d)}else if(f.type==="ParameterExpansion"){let d=await s(e,f);a+=X(d,!0,i)}let o=ye(`^(?:${a})$`),l=n.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),c="",u=!1;for(let f of t)!n.all&&u?c+=f:o.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 hl(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 j(e,i[1]).map(([,c])=>zt(c)).join(" ");if(i&&s.operator==="a")return qt(e,i[1]);let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(a&&s.operator==="a")return qt(e,a[1]);switch(s.operator){case"Q":return r?"":zt(n);case"P":return Kn(e,n);case"a":return qt(e,t);case"A":return r?"":`${t}=${zt(n)}`;case"E":return n.replace(/\\([\\abefnrtv'"?])/g,(o,l)=>{switch(l){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
75
+ `;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?"":zt(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 pl(e,t,n,r,s,i,a=!1){if(e.coverage?.hit("bash:expansion:indirection"),le(e,t))return ln(e,t)||"";let o=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(s.innerOp?.type==="UseAlternative")return"";throw new Qe(`\${!${t}}`)}let l=n;if(o&&(l===""||l.includes(" ")))throw new Qe(`\${!${t}}`);let c=l.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(c&&c[1].includes("~"))throw new Qe(`\${!${t}}`);if(s.innerOp){let u={type:"ParameterExpansion",parameter:l,operation:s.innerOp};return i(e,u,a)}return await ie(e,l)}function ml(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=j(e,t.array).map(([s])=>String(s));return t.star?r.join(Z(e.state.env)):r.join(" ")}function yl(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let n=bn(e,t.prefix);return t.star?n.join(Z(e.state.env)):n.join(" ")}function gl(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[,a,o]=i,l=j(e,a);if(l.length===0)return{isEmpty:!0,effectiveValue:""};if(o==="*"){let c=Z(e.state.env),u=l.map(([,f])=>f).join(c);return{isEmpty:r?u==="":!1,effectiveValue:u}}return{isEmpty:l.length===1&&l.every(([,c])=>c===""),effectiveValue:l.map(([,c])=>c).join(" ")}}return{isEmpty:n==="",effectiveValue:n}}function wl(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 El(e,t){let n=1,r=t,s=!1,i=!1;for(;r<e.length&&n>0;){let a=e[r];if(a==="\\"&&!s&&r+1<e.length){r+=2;continue}if(a==="'"&&!i){s=!s,r++;continue}if(a==='"'&&!s){i=!i,r++;continue}if(!s&&!i){if(a==="(")n++;else if(a===")"&&(n--,n===0))return r}r++}return-1}async function Vr(e,t){let n=new U,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),a=pt(e.state.arrays),o=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=a,e.state.cwd=o,e.state.suppressVerbose=l,e.state.lastExitCode=u,e.state.env.set("?",String(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=a,e.state.cwd=o,e.state.bashPid=s,e.state.suppressVerbose=l,c instanceof P)throw c;return c instanceof H?(e.state.lastExitCode=c.exitCode,e.state.env.set("?",String(c.exitCode)),c.stdout?.replace(/\n+$/,"")??""):""}}function Si(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 a=t.slice(r+1,i);n+=Xe(a),r=i+1;continue}}if(s==='"'){let i=-1,a=r+1;for(;a<t.length;){if(t[a]==="\\"){a+=2;continue}if(t[a]==='"'){i=a;break}a++}if(i!==-1){let o=t.slice(r+1,i),l=ad(e,o);n+=Xe(l),r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let a=t.indexOf("}",r+2);if(a!==-1){let o=t.slice(r+2,a);n+=e.state.env.get(o)??"",r=a+1;continue}}else if(/[a-zA-Z_]/.test(i)){let a=r+1;for(;a<t.length&&/[a-zA-Z0-9_]/.test(t[a]);)a++;let o=t.slice(r+1,a);n+=e.state.env.get(o)??"",r=a;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}function ad(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 a=t.indexOf("}",r+2);if(a!==-1){let o=t.slice(r+2,a);n+=e.state.env.get(o)??"",r=a+1;continue}}else if(/[a-zA-Z_]/.test(i)){let a=r+1;for(;a<t.length&&/[a-zA-Z0-9_]/.test(t[a]);)a++;let o=t.slice(r+1,a);n+=e.state.env.get(o)??"",r=a;continue}}n+=s,r++}return n}async function bl(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 a=t.slice(r+1,i);n+=Xe(a),r=i+1;continue}}if(s==='"'){let i=-1,a=r+1;for(;a<t.length;){if(t[a]==="\\"){a+=2;continue}if(t[a]==='"'){i=a;break}a++}if(i!==-1){let o=t.slice(r+1,i),l=await od(e,o);n+=Xe(l),r=i+1;continue}}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=El(t,r+2);if(i!==-1){let a=t.slice(r+2,i),o=await Vr(e,a);n+=o,r=i+1;continue}}if(s==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let a=t.slice(r+1,i),o=await Vr(e,a);n+=o,r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let a=t.indexOf("}",r+2);if(a!==-1){let o=t.slice(r+2,a);n+=e.state.env.get(o)??"",r=a+1;continue}}else if(/[a-zA-Z_]/.test(i)){let a=r+1;for(;a<t.length&&/[a-zA-Z0-9_]/.test(t[a]);)a++;let o=t.slice(r+1,a);n+=e.state.env.get(o)??"",r=a;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}async function od(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=El(t,r+2);if(i!==-1){let a=t.slice(r+2,i),o=await Vr(e,a);n+=o,r=i+1;continue}}if(s==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let a=t.slice(r+1,i),o=await Vr(e,a);n+=o,r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let a=t.indexOf("}",r+2);if(a!==-1){let o=t.slice(r+2,a);n+=e.state.env.get(o)??"",r=a+1;continue}}else if(/[a-zA-Z_]/.test(i)){let a=r+1;for(;a<t.length&&/[a-zA-Z0-9_]/.test(t[a]);)a++;let o=t.slice(r+1,a);n+=e.state.env.get(o)??"",r=a;continue}}n+=s,r++}return n}function vi(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 Ut(e,t){return t.split(":").map(n=>vi(e,n)).join(":")}function De(e,t,n,r){if(e.length>n-t.length)throw new P(`${r} element limit exceeded (${n})`,"array_elements");for(let s of t)e.push(s)}async function ld(e,t,n,r){let s="";for(let i of t.parts)if(i.type==="Glob")s+=X(i.pattern,!0,e.state.shoptOptions.extglob);else if(i.type==="Literal")s+=X(i.value,!0,e.state.shoptOptions.extglob);else if(i.type==="SingleQuoted"||i.type==="Escaped")s+=te(i.value);else if(i.type==="DoubleQuoted"){let a=await n(e,i.parts);s+=te(a)}else if(i.type==="ParameterExpansion"){let a=await r(e,i);s+=X(a,!0,e.state.shoptOptions.extglob)}else{let a=await r(e,i);s+=te(a)}return s}async function Sl(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],a=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let o=a[1],l=a[2]==="*",c=i.operation,u=j(e,o),f=u.map(([,E])=>E);if(u.length===0){let E=e.state.env.get(o);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let d="";c.pattern&&(d=await ld(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=ye(p,c.all?"g":"");for(let b of f)m.push(E.replace(b,h))}catch{m.push(...f)}if(l){let E=Z(e.state.env);return{values:[m.join(E)],quoted:!0}}return{values:m,quoted:!0}}async function vl(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],a=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let o=a[1],l=a[2]==="*",c=i.operation,u=j(e,o),f=u.map(([,m])=>m);if(u.length===0){let m=e.state.env.get(o);m!==void 0&&f.push(m)}if(f.length===0)return{values:[],quoted:!0};let d="",h=e.state.shoptOptions.extglob;if(c.pattern)for(let m of c.pattern.parts)if(m.type==="Glob")d+=X(m.pattern,c.greedy,h);else if(m.type==="Literal")d+=X(m.value,c.greedy,h);else if(m.type==="SingleQuoted"||m.type==="Escaped")d+=te(m.value);else if(m.type==="DoubleQuoted"){let E=await n(e,m.parts);d+=te(E)}else if(m.type==="ParameterExpansion"){let E=await r(e,m);d+=X(E,c.greedy,h)}else{let E=await r(e,m);d+=te(E)}let p=[];for(let m of f)p.push(ot(e,m,d,c.side,c.greedy));if(l){let m=Z(e.state.env);return{values:[p.join(m)],quoted:!0}}return{values:p,quoted:!0}}async function Al(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],s=r.operation,i=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/),a,o=!1;if(i){let l=i[1];o=i[2]==="*";let c=j(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"?a=u&&!(d&&f):a=!u||d&&f,!a){if(c.length>0){let p=c.map(([,m])=>m);if(o){let m=Z(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 gt(e,l),u=await ie(e,l),f=u==="",d=s.checkEmpty??!1;if(s.type==="UseAlternative"?a=c&&!(d&&f):a=!c||d&&f,!a)return{values:[u],quoted:!0}}if(a&&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=j(e,c);if(f.length>0){let h=f.map(([,p])=>p);if(u||o){let p=Z(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 xl(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0],a=-1,o="",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 b=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){a=m,o=b[1],l=b[2]==="*",c=E.operation;break}}}if(a===-1||a===0&&a===i.parts.length-1)return null;let u="";for(let m=0;m<a;m++)u+=await r(e,i.parts[m]);let f="";for(let m=a+1;m<i.parts.length;m++)f+=await r(e,i.parts[m]);let d=j(e,o),h=d.map(([,m])=>m);if(d.length===0){let m=e.state.env.get(o);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="",b=e.state.shoptOptions.extglob;if(m.pattern)for(let g of m.pattern.parts)if(g.type==="Glob")E+=X(g.pattern,m.greedy,b);else if(g.type==="Literal")E+=X(g.value,m.greedy,b);else if(g.type==="SingleQuoted"||g.type==="Escaped")E+=te(g.value);else if(g.type==="DoubleQuoted"){let w=await s(e,g.parts);E+=te(w)}else if(g.type==="ParameterExpansion"){let w=await r(e,g);E+=X(w,m.greedy,b)}else{let w=await r(e,g);E+=te(w)}h=h.map(g=>ot(e,g,E,m.side,m.greedy))}else if(c?.type==="PatternReplacement"){let m=c,E="";if(m.pattern)for(let w of m.pattern.parts)if(w.type==="Glob")E+=X(w.pattern,!0,e.state.shoptOptions.extglob);else if(w.type==="Literal")E+=X(w.value,!0,e.state.shoptOptions.extglob);else if(w.type==="SingleQuoted"||w.type==="Escaped")E+=te(w.value);else if(w.type==="DoubleQuoted"){let S=await s(e,w.parts);E+=te(S)}else if(w.type==="ParameterExpansion"){let S=await r(e,w);E+=X(S,!0,e.state.shoptOptions.extglob)}else{let S=await r(e,w);E+=te(S)}let b=m.replacement?await s(e,m.replacement.parts):"",g=E;m.anchor==="start"?g=`^${E}`:m.anchor==="end"&&(g=`${E}$`);try{let w=ye(g,m.all?"g":"");h=h.map(S=>w.replace(S,b))}catch{}}if(l){let m=Z(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 Pl(e,t,n,r){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,a="",o=!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,a=m[1],o=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=j(e,a),f=u.map(([,h])=>h);if(u.length===0){let h=e.state.env.get(a);if(h!==void 0)return{values:[l+h+c],quoted:!0};if(o)return{values:[l+c],quoted:!0};let p=l+c;return{values:p?[p]:[],quoted:!0}}if(o){let h=Z(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 $l(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 a=i[1],o=i[2]==="*",l=s.operation;if(e.state.associativeArrays?.has(a))throw new H(1,"",`bash: \${${a}[@]: 0: 3}: bad substitution
76
+ `);let c=l.offset?await n(e,l.offset.expression):0,u=l.length?await n(e,l.length.expression):void 0,f=j(e,a);if(f.length>e.limits.maxArrayElements)throw new P(`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(([b])=>typeof b=="number"&&b>=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 oe(`${a}[@]: 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(o){let p=Z(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}function kl(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],a=s[2]==="*",o=r.operation,l=j(e,i);if(l.length===0){let d=e.state.env.get(i);if(d!==void 0){let h;switch(o.operator){case"a":h="";break;case"P":h=Kn(e,d);break;case"Q":h=zt(d);break;default:h=d}if(M(h)>e.limits.maxStringLength)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[h],quoted:!0}}return a?{values:[""],quoted:!0}:{values:[],quoted:!0}}let c=qt(e,i),u=[],f=0;for(let[,d]of l){let h;switch(o.operator){case"a":h=c;break;case"P":h=Kn(e,d);break;case"Q":h=zt(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 P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u.push(h),f+=p}if(a){let d=Z(e.state.env);if(Math.max(0,u.length-1)*M(d)>e.limits.maxStringLength-f)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u.join(d)],quoted:!0}}return{values:u,quoted:!0}}function Nl(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion")return null;let r=n.parts[0];if(r.operation)return null;let s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!s)return null;let i=s[1];if(le(e,i)){let l=ln(e,i);if(l?.endsWith("[@]")||l?.endsWith("[*]"))return{values:[],quoted:!0}}let a=j(e,i);if(a.length>0)return{values:a.map(([,l])=>l),quoted:!0};let o=e.state.env.get(i);return o!==void 0?{values:[o],quoted:!0}:{values:[],quoted:!0}}function Cl(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation)return null;let s=n.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)||!le(e,s))return null;let i=ln(e,s);if(!i)return null;let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!a)return null;let o=a[1],l=j(e,o);if(l.length>0)return{values:l.map(([,u])=>u),quoted:!0};let c=e.state.env.get(o);return c!==void 0?{values:[c],quoted:!0}:{values:[],quoted:!0}}async function Dl(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 a=i.parts[0],o=a.operation,l=await ie(e,a.parameter),c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c){if(!o.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(Z(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let u=c[1],f=c[2]==="*",d=j(e,u);if(o.innerOp){if(o.innerOp.type==="Substring")return cd(e,d,u,f,o.innerOp);if(o.innerOp.type==="DefaultValue"||o.innerOp.type==="UseAlternative"||o.innerOp.type==="AssignDefault"||o.innerOp.type==="ErrorIfUnset")return ud(e,d,u,f,o.innerOp,s);if(o.innerOp.type==="Transform"&&o.innerOp.operator==="a"){let m=qt(e,u),E=d.map(()=>m);return f?{values:[E.join(Z(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let p=[];for(let[,m]of d){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:o.innerOp},b=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",m);try{let g=await r(e,E,!0);p.push(g)}finally{b!==void 0?e.state.env.set("_indirect_elem_",b):e.state.env.delete("_indirect_elem_")}}return f?{values:[p.join(Z(e.state.env))],quoted:!0}:{values:p,quoted:!0}}if(d.length>0){let p=d.map(([,m])=>m);return f?{values:[p.join(Z(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 cd(e,t,n,r,s){let i=s.offset?await K(e,s.offset.expression):0,a=s.length?await K(e,s.length.expression):void 0,o=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(o=t.findIndex(([h])=>typeof h=="number"&&h>=d),o<0)return{values:[],quoted:!0}}}else if(o=t.findIndex(([u])=>typeof u=="number"&&u>=i),o<0)return{values:[],quoted:!0};let l;if(a!==void 0){if(a<0)throw new oe(`${n}[@]: substring expression < 0`);l=t.slice(o,o+a)}else l=t.slice(o);let c=l.map(([,u])=>u);return r?{values:[c.join(Z(e.state.env))],quoted:!0}:{values:c,quoted:!0}}async function ud(e,t,n,r,s,i){let a=s.checkEmpty??!1,o=t.map(([,u])=>u),l=t.length===0,c=t.length===0;if(s.type==="UseAlternative")return!c&&!(a&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(s.type==="DefaultValue")return(c||a&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:r?{values:[o.join(Z(e.state.env))],quoted:!0}:{values:o,quoted:!0};if(s.type==="AssignDefault"){if((c||a&&l)&&s.word){let f=await i(e,s.word.parts,!0);return q(e,n,0,f),{values:[f],quoted:!0}}return r?{values:[o.join(Z(e.state.env))],quoted:!0}:{values:o,quoted:!0}}return r?{values:[o.join(Z(e.state.env))],quoted:!0}:{values:o,quoted:!0}}async function Rl(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 a=i.parts[0],l=(await ie(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!l)return null;let c=await gt(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=j(e,h);if(m.length>0){let b=m.map(([,g])=>g);return p?{values:[b.join(Z(e.state.env))],quoted:!0}:{values:b,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 Ol(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 a=i.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let o=a.parts[0],c=(await ie(e,o.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c)return null;let u=await ie(e,n.parameter),f=await gt(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]==="*",b=j(e,m);if(b.length>0){let w=b.map(([,S])=>S);return E?{values:[w.join(Z(e.state.env))],quoted:!0}:{values:w,quoted:!0}}let g=e.state.env.get(m);return g!==void 0?{values:[g],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function Il(e){let t=Number.parseInt(e.state.env.get("#")||"0",10);if(t>e.limits.maxArrayElements)throw new P(`positional parameter element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let n=[],r=0;for(let s=1;s<=t;s++){let i=e.state.env.get(String(s))||"",a=M(i);if(a>e.limits.maxStringLength-r)throw new P(`positional parameter string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n.push(i),r+=a}return n}function zr(e,t,n){if(M(t)>n-M(e))throw new P(`positional expansion string limit exceeded (${n} bytes)`,"string_length");return e+t}function Ai(e,t,n,r){if(e.length>=r.limits.maxArrayElements)throw new P(`positional expansion element limit exceeded (${r.limits.maxArrayElements})`,"array_elements");let s=M(t);if(s>r.limits.maxStringLength-n.value)throw new P(`positional expansion string limit exceeded (${r.limits.maxStringLength} bytes)`,"string_length");e.push(t),n.value+=s}async function _l(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,a=!1;for(let g=0;g<s.parts.length;g++){let w=s.parts[g];if(w.type==="ParameterExpansion"&&(w.parameter==="@"||w.parameter==="*")&&w.operation?.type==="Substring"){i=g,a=w.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 g=1;g<=f;g++)d.push(e.state.env.get(String(g))||"");let h=e.state.env.get("0")||"bash",p;if(c<=0){let g=[h,...d],w=g.length+c;if(w<0)p=[];else{let S=c<0?w:0;if(u!==void 0){let A=u<0?g.length+u:S+u;p=g.slice(S,Math.max(S,A))}else p=g.slice(S)}}else{let g=c-1;if(g>=d.length)p=[];else if(u!==void 0){let w=u<0?d.length+u:g+u;p=d.slice(g,Math.max(g,w))}else p=d.slice(g)}let m="";for(let g=0;g<i;g++)m+=await r(e,s.parts[g]);let E="";for(let g=i+1;g<s.parts.length;g++)E+=await r(e,s.parts[g]);if(p.length===0){let g=m+E;return{values:g?[g]:[],quoted:!0}}if(a){let g=Z(e.state.env);return{values:[m+p.join(g)+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 Tl(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,a=!1;for(let g=0;g<s.parts.length;g++){let w=s.parts[g];if(w.type==="ParameterExpansion"&&(w.parameter==="@"||w.parameter==="*")&&w.operation?.type==="PatternReplacement"){i=g,a=w.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=Il(e),u="";for(let g=0;g<i;g++)u=zr(u,await n(e,s.parts[g]),e.limits.maxStringLength);let f="";for(let g=i+1;g<s.parts.length;g++)f=zr(f,await n(e,s.parts[g]),e.limits.maxStringLength);if(c.length===0){let g=u+f;return{values:g?[g]:[],quoted:!0}}let d="";if(l.pattern)for(let g of l.pattern.parts)if(g.type==="Glob")d+=X(g.pattern,!0,e.state.shoptOptions.extglob);else if(g.type==="Literal")d+=X(g.value,!0,e.state.shoptOptions.extglob);else if(g.type==="SingleQuoted"||g.type==="Escaped")d+=te(g.value);else if(g.type==="DoubleQuoted"){let w=await r(e,g.parts);d+=te(w)}else if(g.type==="ParameterExpansion"){let w=await n(e,g);d+=X(w,!0,e.state.shoptOptions.extglob)}else{let w=await n(e,g);d+=te(w)}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 g=ye(p,l.all?"g":"");for(let w of c){let S=0;g.lastIndex=0;for(let O=g.exec(w);O&&(S++,!!l.all);O=g.exec(w))O[0].length===0&&g.lastIndex++;let A=M(w),v=M(h),x=0,N=/\$(?:\$|&|\d+|<[^>]+>|`|')/g;for(;N.exec(h)!==null;)x++;if(A+S*v+S*x*A>e.limits.maxStringLength-E.value)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");Ai(m,g.replace(w,h),E,e)}}catch(g){if(g instanceof P)throw g;for(let w of c)Ai(m,w,E,e)}if(a){let g=Z(e.state.env);if(E.value+Math.max(0,m.length-1)*M(g)+M(u)+M(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+m.join(g)+f],quoted:!0}}if(M(u)+E.value+M(f)>e.limits.maxStringLength)throw new P(`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 Ll(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,a=!1;for(let b=0;b<s.parts.length;b++){let g=s.parts[b];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="PatternRemoval"){i=b,a=g.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=Il(e),u="";for(let b=0;b<i;b++)u=zr(u,await n(e,s.parts[b]),e.limits.maxStringLength);let f="";for(let b=i+1;b<s.parts.length;b++)f=zr(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+=X(b.pattern,l.greedy,h);else if(b.type==="Literal")d+=X(b.value,l.greedy,h);else if(b.type==="SingleQuoted"||b.type==="Escaped")d+=te(b.value);else if(b.type==="DoubleQuoted"){let g=await r(e,b.parts);d+=te(g)}else if(b.type==="ParameterExpansion"){let g=await n(e,b);d+=X(g,l.greedy,h)}else{let g=await n(e,b);d+=te(g)}let p=[],m={value:0};for(let b of c)Ai(p,ot(e,b,d,l.side,l.greedy),m,e);if(a){let b=Z(e.state.env);if(m.value+Math.max(0,p.length-1)*M(b)+M(u)+M(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+p.join(b)+f],quoted:!0}}if(M(u)+m.value+M(f)>e.limits.maxStringLength)throw new P(`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 Ml(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 a=r.parts[s];if(a.type==="ParameterExpansion"&&a.operation)return null;let o=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(o===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<=o;d++)u.push(e.state.env.get(String(d))||"");if(i){let d=Z(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 Et(e,t,n,r){if(t.length>=e.limits.maxArrayElements)throw new P(`unquoted expansion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let s=M(n);if(s>e.limits.maxStringLength-r.value)throw new P(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");t.push(n),r.value+=s}function xi(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 P(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return t.join(n)}function fd(e){return new Vt(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 qr(e,t){if(e.state.options.noglob)return t;let n=fd(e),r=[];for(let s of t)if(wt(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 Rt(s);n.hasNullglob()||r.push(s)}}else r.push(s);return r}async function Bl(e,t,n,r){let s=-1,i="",a=!1;for(let S=0;S<t.length;S++){let A=t[S];if(A.type==="ParameterExpansion"&&A.operation?.type==="PatternReplacement"){let v=A.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(v){s=S,i=v[1],a=v[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,c=j(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+=X(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")f+=X(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=te(S.value);else if(S.type==="DoubleQuoted"){let A=await n(e,S.parts);f+=te(A)}else if(S.type==="ParameterExpansion"){let A=await r(e,S);f+=X(A,!0,e.state.shoptOptions.extglob)}else{let A=await r(e,S);f+=te(A)}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=ye(h,l.all?"g":"");for(let A of u)Et(e,p,Wr(e,A,S,d,l.all),m)}catch(S){if(S instanceof P)throw S;for(let A of u)Et(e,p,A,m)}let E=ve(e.state.env),b=Ce(e.state.env);if(a){let S=Z(e.state.env),A=xi(e,p,S,m.value);return b?{values:A?[A]:[],quoted:!1}:{values:ue(A,E,e.limits.maxArrayElements),quoted:!1}}if(b)return{values:p,quoted:!1};let g=[],w={value:0};for(let S of p)if(S==="")Et(e,g,"",w);else for(let A of ue(S,E,e.limits.maxArrayElements))Et(e,g,A,w);return{values:g,quoted:!1}}async function Wl(e,t,n,r){let s=-1,i="",a=!1;for(let w=0;w<t.length;w++){let S=t[w];if(S.type==="ParameterExpansion"&&S.operation?.type==="PatternRemoval"){let A=S.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(A){s=w,i=A[1],a=A[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,c=j(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="",d=e.state.shoptOptions.extglob;if(l.pattern)for(let w of l.pattern.parts)if(w.type==="Glob")f+=X(w.pattern,l.greedy,d);else if(w.type==="Literal")f+=X(w.value,l.greedy,d);else if(w.type==="SingleQuoted"||w.type==="Escaped")f+=te(w.value);else if(w.type==="DoubleQuoted"){let S=await n(e,w.parts);f+=te(S)}else if(w.type==="ParameterExpansion"){let S=await r(e,w);f+=X(S,l.greedy,d)}else{let S=await r(e,w);f+=te(S)}let h=[],p={value:0};for(let w of u)Et(e,h,ot(e,w,f,l.side,l.greedy),p);let m=ve(e.state.env),E=Ce(e.state.env);if(a){let w=Z(e.state.env),S=xi(e,h,w,p.value);return E?{values:S?[S]:[],quoted:!1}:{values:ue(S,m,e.limits.maxArrayElements),quoted:!1}}if(E)return{values:h,quoted:!1};let b=[],g={value:0};for(let w of h)if(w==="")Et(e,b,"",g);else for(let S of ue(w,m,e.limits.maxArrayElements))Et(e,b,S,g);return{values:b,quoted:!1}}async function Fl(e,t,n,r){let s=-1,i=!1;for(let g=0;g<t.length;g++){let w=t[g];if(w.type==="ParameterExpansion"&&(w.parameter==="@"||w.parameter==="*")&&w.operation?.type==="PatternRemoval"){s=g,i=w.parameter==="*";break}}if(s===-1)return null;let o=t[s].operation,l=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let g=1;g<=l;g++)c.push(e.state.env.get(String(g))||"");if(c.length===0)return{values:[],quoted:!1};let u="",f=e.state.shoptOptions.extglob;if(o.pattern)for(let g of o.pattern.parts)if(g.type==="Glob")u+=X(g.pattern,o.greedy,f);else if(g.type==="Literal")u+=X(g.value,o.greedy,f);else if(g.type==="SingleQuoted"||g.type==="Escaped")u+=te(g.value);else if(g.type==="DoubleQuoted"){let w=await n(e,g.parts);u+=te(w)}else if(g.type==="ParameterExpansion"){let w=await r(e,g);u+=X(w,o.greedy,f)}else{let w=await r(e,g);u+=te(w)}let d=[],h={value:0};for(let g of c)Et(e,d,ot(e,g,u,o.side,o.greedy),h);let p=ve(e.state.env),m=Ce(e.state.env);if(i){let g=Z(e.state.env),w=xi(e,d,g,h.value);return m?{values:w?[w]:[],quoted:!1}:{values:ue(w,p,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[],b={value:0};for(let g of d)if(g==="")Et(e,E,"",b);else for(let w of ue(g,p,e.limits.maxArrayElements))Et(e,E,w,b);return{values:E,quoted:!1}}async function Vl(e,t,n,r){let s=-1,i=!1;for(let w=0;w<t.length;w++){let S=t[w];if(S.type==="ParameterExpansion"&&(S.parameter==="@"||S.parameter==="*")&&S.operation?.type==="Substring"){s=w,i=S.parameter==="*";break}}if(s===-1)return null;let o=t[s].operation,l=o.offset?await n(e,o.offset.expression):0,c=o.length?await n(e,o.length.expression):void 0,u=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let w=1;w<=u;w++)f.push(e.state.env.get(String(w))||"");let d=e.state.env.get("0")||"bash",h;if(l<=0){let w=[d,...f],S=w.length+l;if(S<0)h=[];else{let A=l<0?S:0;if(c!==void 0){let v=c<0?w.length+c:A+c;h=w.slice(A,Math.max(A,v))}else h=w.slice(A)}}else{let w=l-1;if(w>=f.length)h=[];else if(c!==void 0){let S=c<0?f.length+c:w+c;h=f.slice(w,Math.max(w,S))}else h=f.slice(w)}let p="";for(let w=0;w<s;w++)p+=await r(e,t[w]);let m="";for(let w=s+1;w<t.length;w++)m+=await r(e,t[w]);let E=ve(e.state.env),b=Ce(e.state.env);if(h.length===0){let w=p+m;return w?b?{values:[w],quoted:!1}:{values:ue(w,E,e.limits.maxArrayElements),quoted:!1}:{values:[],quoted:!1}}let g;if(i){let w=Z(e.state.env),S=p+h.join(w)+m;b?g=S?[S]:[]:g=ue(S,E,e.limits.maxArrayElements)}else if(b)h.length===1?g=[p+h[0]+m]:g=[p+h[0],...h.slice(1,-1),h[h.length-1]+m];else{g=[];for(let w=0;w<h.length;w++){let S=h[w];if(w===0&&(S=p+S),w===h.length-1&&(S=S+m),S==="")g.push("");else{let A=ue(S,E,e.limits.maxArrayElements);De(g,A,e.limits.maxArrayElements,"unquoted expansion")}}}return{values:await qr(e,g),quoted:!1}}async function zl(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),a=Ce(e.state.env),o=_r(e.state.env),l;if(n)if(a)l=s.filter(c=>c!=="");else{let c=Z(e.state.env),u=s.join(c);l=ue(u,i,e.limits.maxArrayElements)}else if(a)l=s.filter(c=>c!=="");else if(o){l=[];for(let c of s){if(c==="")continue;let u=ue(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=ue(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 qr(e,l),quoted:!1}}async function ql(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=j(e,r),a;if(i.length===0){let f=e.state.env.get(r);if(f!==void 0)a=[f];else return{values:[],quoted:!1}}else a=i.map(([,f])=>f);let o=ve(e.state.env),l=Ce(e.state.env),c=_r(e.state.env),u;if(s)if(l)u=a.filter(f=>f!=="");else{let f=Z(e.state.env),d=a.join(f);u=ue(d,o,e.limits.maxArrayElements)}else if(l)u=a.filter(f=>f!=="");else if(c){u=[];for(let f of a){if(f==="")continue;let d=ue(f,o,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}}else{u=[];for(let f of a)if(f==="")u.push("");else{let d=ue(f,o,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}for(;u.length>0&&u[u.length-1]==="";)u.pop()}return{values:await qr(e,u),quoted:!1}}function Ul(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let n=t[0].operation,r=bn(e,n.prefix);if(r.length===0)return{values:[],quoted:!1};let s=ve(e.state.env),i=Ce(e.state.env),a;if(n.star)if(i)a=r;else{let o=Z(e.state.env),l=r.join(o);a=ue(l,s,e.limits.maxArrayElements)}else if(i)a=r;else{a=[];for(let o of r){let l=ue(o,s,e.limits.maxArrayElements);De(a,l,e.limits.maxArrayElements,"unquoted expansion")}}return{values:a,quoted:!1}}function jl(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let n=t[0].operation,s=j(e,n.array).map(([l])=>String(l));if(s.length===0)return{values:[],quoted:!1};let i=ve(e.state.env),a=Ce(e.state.env),o;if(n.star)if(a)o=s;else{let l=Z(e.state.env),c=s.join(l);o=ue(c,i,e.limits.maxArrayElements)}else if(a)o=s;else{o=[];for(let l of s){let c=ue(l,i,e.limits.maxArrayElements);De(o,c,e.limits.maxArrayElements,"unquoted expansion")}}return{values:o,quoted:!1}}async function Gl(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 a="";for(let d=0;d<r;d++)a+=await n(e,t[d]);let o="";for(let d=r+1;d<t.length;d++)o+=await n(e,t[d]);let l=ve(e.state.env),c=Ce(e.state.env),u=_r(e.state.env);if(s===0){let d=a+o;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=a+p),h===i.length-1&&(p=p+o),d.push(p)}if(c)f=d.filter(h=>h!=="");else if(u){f=[];for(let h of d){if(h==="")continue;let p=ue(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=ue(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 qr(e,f),quoted:!1}}async function Ql(e,t,n){e.coverage?.hit("bash:expansion:word_glob");let r=t.parts,{hasQuoted:s,hasCommandSub:i,hasArrayVar:a,hasArrayAtExpansion:o,hasParamExpansion:l,hasVarNamePrefixExpansion:c,hasIndirection:u}=Zn(r),d=n.hasBraceExpansion(r)?await n.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return dd(e,d,s);let h=await hd(e,r,o,c,u,n);if(h!==null)return h;let p=await md(e,r,n);if(p!==null)return p;let m=await yd(e,r,n);if(m!==null)return m;let E=await wd(e,r,n.expandPart);if(E!==null)return Hl(e,E);if((i||a||l)&&!Ce(e.state.env)){let g=ve(e.state.env),w=n.buildIfsCharClassPattern(g),S=await n.smartWordSplit(e,r,g,w,n.expandPart);return Hl(e,S)}let b=await n.expandWordAsync(e,t);return Ed(e,t,r,b,s,n.expandWordForGlobbing)}async function dd(e,t,n){let r=[];for(let s of t)if(!(!n&&s===""))if(!n&&!e.state.options.noglob&&wt(s,e.state.shoptOptions.extglob)){let i=await Ur(e,s);De(r,i,e.limits.maxArrayElements,"brace/glob expansion")}else r.push(s);return{values:r,quoted:!1}}async function hd(e,t,n,r,s,i){if(n){let a=Nl(e,t);if(a!==null)return a}{let a=Cl(e,t);if(a!==null)return a}{let a=await Al(e,t);if(a!==null)return a}{let a=await xl(e,t,n,i.expandPart,i.expandWordPartsAsync);if(a!==null)return a}{let a=await Pl(e,t,n,i.expandPart);if(a!==null)return a}{let a=await $l(e,t,i.evaluateArithmetic);if(a!==null)return a}{let a=kl(e,t);if(a!==null)return a}{let a=await Sl(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}{let a=await vl(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let a=pd(e,t);if(a!==null)return a}{let a=await Dl(e,t,s,i.expandParameterAsync,i.expandWordPartsAsync);if(a!==null)return a}{let a=await Rl(e,t);if(a!==null)return a}{let a=await Ol(e,t);if(a!==null)return a}return null}function pd(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=bn(e,r.prefix);return r.star?{values:[s.join(Z(e.state.env))],quoted:!0}:{values:s,quoted:!0}}if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="ArrayKeys"){let r=n.parts[0].operation,i=j(e,r.array).map(([a])=>String(a));return r.star?{values:[i.join(Z(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function md(e,t,n){{let r=await _l(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await Tl(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Ll(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Ml(e,t,n.expandPart);if(r!==null)return r}return null}async function yd(e,t,n){{let r=await Bl(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Wl(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Fl(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Vl(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await zl(e,t);if(r!==null)return r}{let r=await ql(e,t);if(r!==null)return r}{let r=Ul(e,t);if(r!==null)return r}{let r=jl(e,t);if(r!==null)return r}{let r=await Gl(e,t,n.expandPart);if(r!==null)return r}return null}function Zl(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 gd(e,t,n,r){let s="";for(let o=0;o<n.atIndex;o++)s+=await r(e,t.parts[o]);let i="";for(let o=n.atIndex+1;o<t.parts.length;o++)i+=await r(e,t.parts[o]);let a;if(n.type==="array"){if(a=j(e,n.name).map(([,l])=>l),a.length===0){let l=e.state.env.get(n.name);l!==void 0&&(a=[l])}}else{let o=Number.parseInt(e.state.env.get("#")||"0",10);a=[];for(let l=1;l<=o;l++)a.push(e.state.env.get(String(l))||"")}if(n.isStar){let o=Z(e.state.env),l=a.join(o);return[s+l+i]}if(a.length===0){let o=s+i;return o?[o]:[]}return a.length===1?[s+a[0]+i]:[s+a[0],...a.slice(1,-1),a[a.length-1]+i]}async function wd(e,t,n){if(t.length<2)return null;let r=!1;for(let l of t)if(Zl(l)){r=!0;break}if(!r)return null;let s=ve(e.state.env),i=Ce(e.state.env),a=[];for(let l of t){let c=Zl(l);if(c&&l.type==="DoubleQuoted"){let u=await gd(e,l,c,n);a.push(u)}else if(l.type==="DoubleQuoted"||l.type==="SingleQuoted"){let u=await n(e,l);a.push([u])}else if(l.type==="Literal")a.push([l.value]);else if(l.type==="ParameterExpansion"){let u=await n(e,l);if(i)a.push(u?[u]:[]);else{let f=ue(u,s,e.limits.maxArrayElements);a.push(f)}}else{let u=await n(e,l);if(i)a.push(u?[u]:[]);else{let f=ue(u,s,e.limits.maxArrayElements);a.push(f)}}}let o=[];for(let l of a)if(l.length!==0)if(o.length===0)De(o,l,e.limits.maxArrayElements,"word expansion");else{let c=o.length-1;o[c]=o[c]+l[0];for(let u=1;u<l.length;u++)o.push(l[u])}return o}async function Hl(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let n=[];for(let r of t)if(wt(r,e.state.shoptOptions.extglob)){let s=await Ur(e,r);De(n,s,e.limits.maxArrayElements,"glob expansion")}else n.push(r);return{values:n,quoted:!1}}async function Ur(e,t){let n=new Vt(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 Rt(t);return n.hasNullglob()?[]:[t]}async function Ed(e,t,n,r,s,i){let a=n.some(o=>o.type==="Glob");if(!e.state.options.noglob&&a){let o=await i(e,t);if(wt(o,e.state.shoptOptions.extglob)){let c=await Ur(e,o);if(c.length>0&&c[0]!==o)return{values:c,quoted:!1};if(c.length===0)return{values:[],quoted:!1}}let l=bi(r);if(!Ce(e.state.env)){let c=ve(e.state.env);return{values:ue(l,c,e.limits.maxArrayElements),quoted:!1}}return{values:[l],quoted:!1}}if(!s&&!e.state.options.noglob&&wt(r,e.state.shoptOptions.extglob)){let o=await i(e,t);if(wt(o,e.state.shoptOptions.extglob)){let l=await Ur(e,o);if(l.length>0&&l[0]!==o)return{values:l,quoted:!1}}}if(r===""&&!s)return{values:[],quoted:!1};if(a&&!s){let o=bi(r);if(!Ce(e.state.env)){let l=ve(e.state.env);return{values:ue(o,l,e.limits.maxArrayElements),quoted:!1}}return{values:[o],quoted:!1}}return{values:[r],quoted:s}}function Oe(e,t,n){if(t.length>=e.limits.maxArrayElements)throw new P(`word splitting element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");t.push(n)}async function Xl(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 gt(e,t.parameter),a=await ie(e,t.parameter,!1)==="",o=n.checkEmpty??!1,l;return n.type==="UseAlternative"?l=s&&!(o&&a):l=!s||o&&a,l?r.parts:null}function bd(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(n=>n.type==="Literal"):!1}async function Sd(e,t){if(t.type!=="ParameterExpansion")return null;let n=await Xl(e,t);if(!n||n.length<=1)return null;let r=n.some(i=>bd(i)),s=n.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&s?n:null}function vd(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?di(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&Ho(e))}async function Yl(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 Xl(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 Kl(e,h,n,r,s)}let i=[],a=!1;for(let d of t){let h=vd(d),p=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=h?await Sd(e,d):null,E=await s(e,d);i.push({value:E,isSplittable:h,isQuoted:p,mixedDefaultParts:m??void 0}),h&&(a=!0)}if(!a){let d=i.map(h=>h.value).join("");return d?[d]:[]}let o=[],l="",c=!1,u=!1,f=!1;for(let d of i)if(!d.isSplittable)u?d.isQuoted&&d.value===""?(l!==""&&Oe(e,o,l),Oe(e,o,""),c=!0,l="",u=!1,f=!0):d.value!==""?(l!==""&&Oe(e,o,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 Kl(e,d.mixedDefaultParts,n,r,s);if(h.length!==0)if(h.length===1)l+=h[0],c=!0;else{l+=h[0],Oe(e,o,l),c=!0;for(let p=1;p<h.length-1;p++)Oe(e,o,h[p]);l=h[h.length-1]}u=!1,f=!1}else{let{words:h,hadLeadingDelimiter:p,hadTrailingDelimiter:m}=Tr(d.value,n,e.limits.maxArrayElements);if(f&&p&&l===""&&(Oe(e,o,""),c=!0),h.length===0)m&&(u=!0);else if(h.length===1)l+=h[0],c=!0,u=m;else{l+=h[0],Oe(e,o,l),c=!0;for(let E=1;E<h.length-1;E++)Oe(e,o,h[E]);l=h[h.length-1],u=m}f=!1}return l!==""?Oe(e,o,l):o.length===0&&c&&Oe(e,o,""),o}function Ad(e,t){return e.length>0&&t.includes(e[0])}async function Kl(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 a=[],o="",l=!1,c=!1;for(let u of i)if(!u.isSplittable)c&&u.value!==""?(o!==""&&Oe(e,a,o),o=u.value,c=!1):o+=u.value;else{Ad(u.value,n)&&o!==""&&(Oe(e,a,o),o="",l=!0);let{words:d,hadTrailingDelimiter:h}=Tr(u.value,n,e.limits.maxArrayElements);if(d.length===0)h&&(c=!0);else if(d.length===1)o+=d[0],l=!0,c=h;else{o+=d[0],Oe(e,a,o),l=!0;for(let p=1;p<d.length-1;p++)Oe(e,a,d[p]);o=d[d.length-1],c=h}}return o!==""?Oe(e,a,o):a.length===0&&l&&Oe(e,a,""),a}function Jl(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function ec(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}function jt(e,t,n){if(e.length>t)throw new P(`${n}: string length limit exceeded (${t} bytes)`,"string_length")}async function ct(e,t,n=!1){let r=[];for(let s of t)r.push(await Ye(e,s,n));return r.join("")}function xd(e){return ec(e)}function nc(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!xd(t))return!1;return!0}function Pd(e,t,n=!1){let r=Jl(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 Si(e,t.pattern);default:return null}}async function z(e,t){return Pi(e,t)}async function rc(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped")n.push(`\\${r.value}`);else if(r.type==="SingleQuoted")n.push(r.value);else if(r.type==="DoubleQuoted"){let s=await ct(e,r.parts);n.push(s)}else if(r.type==="TildeExpansion"){let s=await Ye(e,r);n.push(Qn(s))}else n.push(await Ye(e,r));return n.join("")}async function sc(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped"){let s=r.value;"()|*?[]".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="SingleQuoted")n.push(Xe(r.value));else if(r.type==="DoubleQuoted"){let s=await ct(e,r.parts);n.push(Xe(s))}else n.push(await Ye(e,r));return n.join("")}async function ic(e,t){let n=[];for(let r of t.parts)if(r.type==="SingleQuoted")n.push(Xe(r.value));else if(r.type==="Escaped"){let s=r.value;"*?[]\\()|".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="DoubleQuoted"){let s=await ct(e,r.parts);n.push(Xe(s))}else r.type==="Glob"?wl(r.pattern)?n.push(await bl(e,r.pattern)):n.push(Si(e,r.pattern)):r.type==="Literal"?n.push(r.value):n.push(await Ye(e,r));return n.join("")}function Gr(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&Gr(t.parts))return!0;return!1}var tc=1e5;async function ac(e,t,n={count:0}){let r=()=>{n.count++,e.executionScope.consumeLimited("brace_operations",1,Math.min(tc,e.limits.maxBraceExpansionResults),"brace expansion")},s=(a,o)=>{if(a.length>=e.limits.maxBraceExpansionResults)throw new P(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),a.push(o)},i=[[]];for(let a of t)if(a.type==="BraceExpansion"){let o=[],l=!1,c="";for(let d of a.items)if(d.type==="Range"){let h=Ei(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(o,p);else{l=!0,c=h.literal;break}}else{let h=await ac(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 Ye(e,E));s(o,m.join(""))}}if(l){for(let d of i)r(),d.push(c);continue}if(i.length*o.length>e.limits.maxBraceExpansionResults||n.count>tc)throw new P(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");let f=[];for(let d of i)for(let h of o){if(f.length>=e.limits.maxBraceExpansionResults)throw new P(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),f.push([...d,h])}i=f}else for(let o of i)r(),o.push(a);return i}async function oc(e,t){let n=t.parts;if(!Gr(n))return[await z(e,t)];let r=await ac(e,n),s=[];for(let i of r){let a=[];for(let o of i)typeof o=="string"?a.push(o):a.push(await Ye(e,o));s.push(vi(e,a.join("")))}return s}function $d(){return{expandWordAsync:Pi,expandWordForGlobbing:ic,expandWordWithBracesAsync:oc,expandWordPartsAsync:ct,expandPart:Ye,expandParameterAsync:jr,hasBraceExpansion:Gr,evaluateArithmetic:K,buildIfsCharClassPattern:Qo,smartWordSplit:Yl}}async function ut(e,t){return Ql(e,t,$d())}function kd(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Xn(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 a of i.parts)if(a.type==="ParameterExpansion"&&a.parameter==="@"&&!a.operation)return!0}return!1}return r(t.parts)}async function Zr(e,t){if(Xn(e,t))return{error:`bash: $@: ambiguous redirect
77
+ `};let n=t.parts,{hasQuoted:r}=Zn(n);if(Gr(n)&&(await oc(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
78
+ `};let s=await Pi(e,t),{hasParamExpansion:i,hasCommandSub:a}=Zn(n);if((i||a)&&!r&&!Ce(e.state.env)){let f=ve(e.state.env);if(ue(s,f,e.limits.maxArrayElements).length>1)return{error:`bash: $${kd(n)}: ambiguous redirect
79
+ `}}if(r||e.state.options.noglob)return{target:s};let l=await ic(e,t);if(!wt(l,e.state.shoptOptions.extglob))return{target:s};let c=new Vt(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}
80
+ `}:{target:s}:u.length===1?{target:u[0]}:{error:`bash: ${s}: ambiguous redirect
81
+ `}}async function Pi(e,t){let n=t.parts,r=n.length;if(r===1){let a=await Ye(e,n[0]);return jt(a,e.limits.maxStringLength,"word expansion"),a}let s=[];for(let a=0;a<r;a++)s.push(await Ye(e,n[a]));let i=s.join("");return jt(i,e.limits.maxStringLength,"word expansion"),i}async function Ye(e,t,n=!1){if(t.type==="ParameterExpansion")return jr(e,t,n);let r=Pd(e,t,n);if(r!==null)return r;switch(t.type){case"DoubleQuoted":{let s=[];for(let i of t.parts)s.push(await Ye(e,i,!0));return s.join("")}case"CommandSubstitution":{let s=nl(t.body);if(s)try{let h=await z(e,s.target),p=h.startsWith("/")?h:`${e.state.cwd}/${h}`,m=await e.fs.readFile(p);e.state.lastExitCode=0,e.state.env.set("?","0");let E=m.replace(/\n+$/,"");return jt(E,e.limits.maxStringLength,"command substitution"),E}catch(h){if(h instanceof P)throw h;return e.state.lastExitCode=1,e.state.env.set("?","1"),""}let i=e.substitutionDepth??0,a=e.limits.maxSubstitutionDepth;if(i>=a)throw new P(`Command substitution nesting limit exceeded (${a})`,"substitution_depth");let o=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=pt(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,e.state.lastExitCode=p,e.state.env.set("?",String(p)),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr),e.state.bashPid=l,e.substitutionDepth=o;let m=h.stdout.replace(/\n+$/,"");return jt(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=o,e.state.suppressVerbose=d,h instanceof P)throw h;if(h instanceof H){e.state.lastExitCode=h.exitCode,e.state.env.set("?",String(h.exitCode)),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr);let p=h.stdout.replace(/\n+$/,"");return jt(p,e.limits.maxStringLength,"command substitution"),p}throw h}}case"ArithmeticExpansion":{let s=t.expression.originalText;if(s&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(s)){let a=await tl(e,s),o=new U,l=re(o,a);return String(await K(e,l.expression,!0))}return String(await K(e,t.expression.expression,!0))}case"BraceExpansion":{let s=[];for(let i of t.items)if(i.type==="Range"){let a=Ei(i.start,i.end,i.step,i.startStr,i.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(a.expanded)s.push(...a.expanded);else return a.literal}else s.push(await z(e,i.word));return s.join(" ")}default:return""}}async function jr(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 gi(e,h);r=`${d}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&le(e,r)){let d=Te(e,r);if(d&&d!==r){let 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 gi(e,m);r=`${p}[${b}]`}}}}let a=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),o=await ie(e,r,!a);if(!s)return o;let l=!await gt(e,r),{isEmpty:c,effectiveValue:u}=gl(e,r,o,n),f={value:o,isUnset:l,isEmpty:c,effectiveValue:u,inDoubleQuotes:n};switch(s.type){case"DefaultValue":return sl(e,s,f,ct);case"AssignDefault":return il(e,r,s,f,ct);case"ErrorIfUnset":return al(e,r,s,f,ct);case"UseAlternative":return ol(e,s,f,ct);case"PatternRemoval":{let d=await ll(e,o,s,ct,Ye);return jt(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await cl(e,o,s,ct,Ye);return jt(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return ul(e,r,o);case"LengthSliceError":throw new Qe(r);case"BadSubstitution":throw new Qe(s.text);case"Substring":return fl(e,r,o,s);case"CaseModification":{let d=await dl(e,o,s,ct,jr);return jt(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return hl(e,r,o,l,s);case"Indirection":return pl(e,r,o,l,s,jr,n);case"ArrayKeys":return ml(e,s);case"VarNamePrefix":return yl(e,s);default:return o}}function cc(){return{visited:new Set,depth:0}}function Nd(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new oe("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new oe("division by 0");return e%t;case"**":if(t<0)throw new oe("exponent less than 0");return e**t;case"<<":return e<<t;case">>":return e>>t;case"<":return e<t?1:0;case"<=":return e<=t?1:0;case">":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function lc(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 Cd(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function Dd(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 Rd(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 U,{expr:a,pos:o}=En(i,s,0);if(o<s.length){let l=s.slice(o).trim(),c=l.split(/\s+/)[0]||l;throw new oe(`syntax error in expression (error token is "${c}")`,"","")}return await vn(e,a,!1,n)}async function Hr(e,t,n,r){if(r.depth>100)throw new oe("maximum variable indirection depth exceeded");if(r.visited.has(t))throw new oe(`arithmetic variable cycle detected at ${t}`);r.visited.add(t),r.depth++;try{return await Rd(e,n,r)}finally{r.depth--,r.visited.delete(t)}}async function $i(e,t,n){if(n.depth>100)throw new oe("maximum variable indirection depth exceeded");if(n.visited.has(t))throw new oe(`arithmetic variable cycle detected at ${t}`);n.visited.add(t),n.depth++;try{let r=await Dd(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 $i(e,i,n);let a=new U,{expr:o,pos:l}=En(a,i,0);if(l<i.length){let c=i.slice(l).trim(),u=c.split(/\s+/)[0]||c;throw new oe(`${i}: syntax error in expression (error token is "${u}")`)}return await vn(e,o,!1,n)}finally{n.depth--,n.visited.delete(t)}}async function Qr(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=j(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),a=t.slice(r+s.length),o=e.state.env.get(i),l=o===void 0,c=o==="",u=s.startsWith(":");switch(s){case":-":case"-":return l||u&&c?a:o||"";case":=":case"=":return l||u&&c?(e.state.env.set(i,a),a):o||"";case":+":case"+":return!(l||u&&c)?a:"";case":?":case"?":{if(l||u&&c)throw new Error(a||`${i}: parameter null or not set`);return o||""}default:return o||""}}async function K(e,t,n=!1){return vn(e,t,n,cc())}async function vn(e,t,n,r){let s=(i,a=n)=>vn(e,i,a,r);switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new oe("value too great for base");return t.value;case"ArithVariable":return await $i(e,t.name,r);case"ArithSpecialVar":{let a=(await ie(e,t.name)).trim();if(!a)return 0;let o=Number.parseInt(a,10);if(!Number.isNaN(o)&&/^-?\d+$/.test(a))return o;let l=new U,{expr:c}=En(l,a,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 a=i.stdout.trim();return Number.parseInt(a,10)||0}return 0}case"ArithBracedExpansion":{let i=await Qr(e,t.content);return Number.parseInt(i,10)||0}case"ArithDynamicBase":{let i=await Qr(e,t.baseExpr),a=Number.parseInt(i,10);if(a<2||a>64)return 0;let o=`${a}#${t.value}`;return Un(o)}case"ArithDynamicNumber":{let a=await Qr(e,t.prefix)+t.suffix;return Un(a)}case"ArithArrayElement":{let i=e.state.associativeArrays?.has(t.array),a=async o=>{let l=ae(e,t.array,o);return l!==void 0?await Hr(e,`${t.array}[${o}]`,l,r):0};if(t.stringKey!==void 0)return await a(t.stringKey);if(i&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await a(t.index.name);if(i&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let o=await ie(e,t.index.name);return await a(o)}if(t.index){let o=await s(t.index);if(o<0){let u=j(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
82
+ `,0;let h=Math.max(...u.map(([p])=>typeof p=="number"?p:0))+1+o;if(h<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
83
+ `,0;o=h}let l=`${t.array}[${o}]`,c=ae(e,t.array,o);if(c!==void 0)return Hr(e,l,c,r);if(o===0){let u=e.state.env.get(t.array);if(u!==void 0)return Hr(e,t.array,u,r)}if(e.state.options.nounset&&!(e.state.env.has(t.array)||Ne(e,t.array)))throw new Be(`${t.array}[${o}]`);return 0}return 0}case"ArithDoubleSubscript":throw new oe("double subscript","","");case"ArithNumberSubscript":throw new oe(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new oe(t.message,"","",!0);case"ArithSingleQuote":{if(n)throw new oe(`syntax error: operand expected (error token is "'${t.content}'")`);return t.value}case"ArithBinary":{if(t.operator==="||")return await s(t.left)||await s(t.right)?1:0;if(t.operator==="&&")return await s(t.left)&&await s(t.right)?1:0;let i=await s(t.left),a=await s(t.right);return Nd(i,a,t.operator)}case"ArithUnary":{let i=await s(t.operand);if(t.operator==="++"||t.operator==="--"){if(t.operand.type==="ArithVariable"){let a=t.operand.name,o=Number.parseInt(await ie(e,a),10)||0,l=t.operator==="++"?o+1:o-1;return e.state.env.set(a,String(l)),t.prefix?l:o}if(t.operand.type==="ArithArrayElement"){let a=t.operand.array,o=e.state.associativeArrays?.has(a),l;if(t.operand.stringKey!==void 0)l=t.operand.stringKey;else if(o&&t.operand.index?.type==="ArithVariable"&&!t.operand.index.hasDollarPrefix)l=t.operand.index.name;else if(o&&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,a,l)||"0",10)||0,u=t.operator==="++"?c+1:c-1;return q(e,a,l,String(u),o?"associative":"indexed"),t.prefix?u:c}if(t.operand.type==="ArithConcat"){let a="";for(let o of t.operand.parts)a+=await Sn(e,o,n,r);if(a&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){let o=Number.parseInt(e.state.env.get(a)||"0",10)||0,l=t.operator==="++"?o+1:o-1;return e.state.env.set(a,String(l)),t.prefix?l:o}}if(t.operand.type==="ArithDynamicElement"){let a="";if(t.operand.nameExpr.type==="ArithConcat")for(let o of t.operand.nameExpr.parts)a+=await Sn(e,o,n,r);else t.operand.nameExpr.type==="ArithVariable"&&(a=t.operand.nameExpr.hasDollarPrefix?await ie(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(a&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){let o=await s(t.operand.subscript),l=Number.parseInt(ae(e,a,o)||"0",10)||0,c=t.operator==="++"?l+1:l-1;return q(e,a,o,String(c)),t.prefix?c:l}}return i}return Cd(i,t.operator)}case"ArithTernary":return await s(t.condition)?await s(t.consequent):await s(t.alternate);case"ArithAssignment":{let i=t.variable,a=i,o;if(t.stringKey!==void 0)o=t.stringKey;else if(t.subscript){let d=e.state.associativeArrays?.has(i);if(d&&t.subscript.type==="ArithVariable"&&!t.subscript.hasDollarPrefix)o=t.subscript.name;else if(d&&t.subscript.type==="ArithVariable"&&t.subscript.hasDollarPrefix)o=await ie(e,t.subscript.name)||"\\";else if(d){let h=await s(t.subscript);o=String(h)}else{let h=await s(t.subscript);if(h<0){let p=j(e,i);p.length>0&&(h=Math.max(...p.map(([E])=>typeof E=="number"?E:0))+1+h)}o=String(h)}}let l=o===void 0?e.state.env.get(a):ae(e,i,o),c=Number.parseInt(l||"0",10)||0,u=await s(t.value),f=lc(c,u,t.operator);return o===void 0?e.state.env.set(a,String(f)):q(e,i,o,String(f),e.state.associativeArrays?.has(i)?"associative":"indexed"),f}case"ArithGroup":return await s(t.expression);case"ArithConcat":{let i="";for(let a of t.parts)i+=await Sn(e,a,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)?await $i(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 Sn(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 a=i;if(t.subscript){let u=await s(t.subscript);a=`${i}_${u}`}let o=Number.parseInt(e.state.env.get(a)||"0",10)||0,l=await s(t.value),c=lc(o,l,t.operator);return e.state.env.set(a,String(c)),c}case"ArithDynamicElement":{let i="";if(t.nameExpr.type==="ArithConcat")for(let c of t.nameExpr.parts)i+=await Sn(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 a=await s(t.subscript),o=`${i}_${a}`,l=e.state.env.get(o);return l!==void 0?Hr(e,o,l,r):0}default:return 0}}async function Sn(e,t,n=!1,r=cc()){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await vn(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 Qr(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 Sn(e,i,n,r);return s}default:return String(await vn(e,t,n,r))}}async function uc(e,t){let n="",r=0;for(let A of t.parts){let v=A.type==="Literal"?A.value:"\0",x=M(v);if(x>e.limits.maxStringLength-r)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n+=v,r+=x}let s=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!s||!n.endsWith(")"))return null;let i=s[1],a=[],o=[],l=!1,c="",u=0,f=0,d=!1,h=!0,p=A=>{let v=M(A);if(v>e.limits.maxStringLength-f-u)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");c+=A,u+=v},m=(A,v=!1)=>{if(a.length>=e.limits.maxArrayElements)throw new P(`array assignment element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let x=M(A);if(x>e.limits.maxStringLength-f)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");a.push(A),o.push(v),f+=x},E=()=>{m(c,h),c="",u=0,d=!1,h=!0};for(let A of t.parts)if(A.type==="Literal"){let v=A.value;if(!l){let x=v.indexOf("=(");x!==-1&&(l=!0,v=v.slice(x+2))}if(l){v.endsWith(")")&&(v=v.slice(0,-1));for(let x of v)/\s/.test(x)?(c||d)&&E():p(x)}}else if(l)if(A.type==="BraceExpansion")if(/^\[.+\]=/.test(c))p(gn({type:"Word",parts:[A]}));else{(c||d)&&E();let x=await ut(e,{type:"Word",parts:[A]});for(let N of x.values)m(N)}else{(A.type==="SingleQuoted"||A.type==="DoubleQuoted"||A.type==="Escaped")&&(d=!0),h=!1;let v=await z(e,{type:"Word",parts:[A]});p(v)}(c||d)&&E();let b=a.splice(0),g=o.splice(0);f=0;for(let A=0;A<b.length;A++){let v=b[A];if(!g[A]){m(v);continue}let x=v.match(/^(\[[^\]]+\]=)(.*)$/s);if(x){let N=Ut(e,x[2]);v=x[1]+N}if(v.includes("{")&&v.includes("}")){let N=new U().parseWordFromString(v,!1,!1);if(N.parts.some(D=>D.type==="BraceExpansion")){let D=await ut(e,N);for(let O of D.values)m(O);continue}}m(v)}let w=[`${i}=(`],S=M(w[0]);for(let A=0;A<a.length;A++){let v=a[A],x;/^\[.+\]=/.test(v)?x=v:v===""?x="''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(v)&&!v.startsWith("'")&&!v.startsWith('"')?x=`'${v.replace(/'/g,"'\\''")}'`:x=v;let N=`${A>0?" ":""}${x}`,D=M(N);if(D+1>e.limits.maxStringLength-S)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");w.push(N),S+=D}return w.push(")"),w.join("")}async function fc(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 b=E.value.indexOf("+=");if(b!==-1){let w=E.value.slice(0,b);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(w)){n=m,r=b,s=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(w)){n=m,r=b,s=!0;break}}let g=E.value.indexOf("=");if(g!==-1&&(g===0||E.value[g-1]!=="+")){let w=E.value.slice(0,g);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(w)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(w)){n=m,r=g;break}}}}if(n===-1)return null;let i=t.parts.slice(0,n),a=t.parts[n];if(a.type!=="Literal")return null;let o=s?2:1,l=a.value.slice(0,r),c=a.value.slice(r+o),u=t.parts.slice(n+1),f="";for(let m of i)f+=await z(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 z(e,d):"";return`${f}${s?"+=":"="}${h}`}var Od=["tar","yq","xan","sqlite3","python3","python"];function dc(e){return Od.includes(e)}var ne=Object.freeze({stdout:"",stderr:"",exitCode:0});function Y(e=""){return{stdout:e,stderr:"",exitCode:0}}function R(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function I(e,t,n){return{stdout:e,stderr:t,exitCode:n}}function we(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function Gt(e,t,n="",r=""){throw new P(e,t,n,r)}function je(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new P(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function ki(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Ot;return ne}if(t.length>1)throw new H(1,"",`bash: break: too many arguments
84
+ `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new H(128,"",`bash: break: ${t[0]}: numeric argument required
85
+ `);n=r}throw new Ze(n)}async function Ni(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 a=t.slice(i);if(a.length===0||a[0]==="~"?n=e.state.env.get("HOME")||"/":a[0]==="-"?(n=e.state.previousDir,r=!0):n=a[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 R(`bash: cd: ${n}: Not a directory
86
+ `)}catch{return R(`bash: cd: ${n}: No such file or directory
87
+ `)}}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),Y(r?`${u}
88
+ `:"")}function Ci(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Id=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function Kr(e){return Id.includes(e)}async function Xr(e,t,n){let r=Ci(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 _d=["-nt","-ot","-ef"];function Yr(e){return _d.includes(e)}async function Jr(e,t,n,r){let s=Ci(e,n),i=Ci(e,r);switch(t){case"-nt":{let[a,o]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return a!==null&&(o===null||a.mtime>o.mtime)}case"-ot":{let[a,o]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return o!==null&&(a===null||a.mtime<o.mtime)}case"-ef":try{let[a,o]=await Promise.all([e.fs.realpath(s),e.fs.realpath(i)]);if(a===o)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 Td=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function es(e){return Td.has(e)}function ts(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 Yn(e){return e==="="||e==="=="||e==="!="}function ns(e,t,n,r=!1,s=!1,i=!1,a=256){if(r){let l=An(t,n,s,i,a);return e==="!="?!l:l}if(s){let l=t.toLowerCase()===n.toLowerCase();return e==="!="?!l:l}let o=t===n;return e==="!="?!o:o}var Ld=new Set(["-z","-n"]);function rs(e){return Ld.has(e)}function ss(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function is(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 o=s;return(o.startsWith("'")&&o.endsWith("'")||o.startsWith('"')&&o.endsWith('"'))&&(o=o.slice(1,-1)),o=o.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(l,c)=>e.state.env.get(c)||""),Bt(e,r,o)}let a;try{let o=new U,l=re(o,s);a=await K(e,l.expression)}catch{if(/^-?\d+$/.test(s))a=Number.parseInt(s,10);else{let o=e.state.env.get(s);a=o?Number.parseInt(o,10):0}}if(a<0){let o=Se(e,r),l=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
89
+ `,!1;if(a=Math.max(...o)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
90
+ `,!1}return Bt(e,r,a)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?mt(e,t).length>0:Se(e,t).length>0}async function Zt(e,t){switch(t.type){case"CondBinary":{let n=await z(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 z(e,t.right);s=Qn(i)}else s=await rc(e,t.right);else Yn(t.operator)&&!r?s=await sc(e,t.right):s=await z(e,t.right);if(Yn(t.operator)){let i=e.state.shoptOptions.nocasematch;return ns(t.operator,n,s,!r,i,!0,e.limits.maxCallDepth)}if(es(t.operator))return ts(t.operator,await pc(e,n),await pc(e,s));if(Yr(t.operator))return Jr(e,t.operator,n,s);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=Vd(s),l=ye(a,i?"i":"").match(n);if(ge(e,"BASH_REMATCH"),l)for(let c=0;c<l.length;c++)q(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 z(e,t.operand);return Kr(t.operator)?Xr(e,t.operator,n):rs(t.operator)?ss(t.operator,n):t.operator==="-v"?await is(e,n):t.operator==="-o"?Ri(e,n):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await z(e,t.operand.expression.word)})`!=="":!await Zt(e,t.operand);case"CondAnd":return await Zt(e,t.left)?await Zt(e,t.right):!1;case"CondOr":return await Zt(e,t.left)?!0:await Zt(e,t.right);case"CondGroup":return await Zt(e,t.expression);case"CondWord":return await z(e,t.word)!=="";default:return!1}}async function Jn(e,t){if(t.length===0)return I("","",1);if(t.length===1)return we(!!t[0]);if(t.length===2){let r=t[0],s=t[1];return r==="("?R(`test: '(' without matching ')'
91
+ `,2):Kr(r)?we(await Xr(e,r,s)):rs(r)?we(ss(r,s)):r==="!"?we(!s):r==="-v"?we(await is(e,s)):r==="-o"?we(Ri(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"?R(`test: ${r}: unary operator expected
92
+ `,2):I("","",1)}if(t.length===3){let r=t[0],s=t[1],i=t[2];if(Yn(s))return we(ns(s,r,i));if(es(s)){let a=as(r),o=as(i);return!a.valid||!o.valid?I("","",2):we(ts(s,a.value,o.value))}if(Yr(s))return we(await Jr(e,s,r,i));switch(s){case"-a":return we(r!==""&&i!=="");case"-o":return we(r!==""||i!=="");case">":return we(r>i);case"<":return we(r<i)}if(r==="!"){let a=await Jn(e,[s,i]);return I("",a.stderr,a.exitCode===0?1:a.exitCode===1?0:a.exitCode)}if(r==="("&&i===")")return we(s!=="")}if(t.length===4){if(t[0]==="!"){let r=await Jn(e,t.slice(1));return I("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(t[0]==="("&&t[3]===")")return Jn(e,[t[1],t[2]])}let n=await yc(e,t,0);return n.pos<t.length?R(`test: too many arguments
93
+ `,2):we(n.value)}async function yc(e,t,n){return Md(e,t,n)}async function Md(e,t,n){let{value:r,pos:s}=await hc(e,t,n);for(;t[s]==="-o";){let i=await hc(e,t,s+1);r=r||i.value,s=i.pos}return{value:r,pos:s}}async function hc(e,t,n){let{value:r,pos:s}=await Di(e,t,n);for(;t[s]==="-a";){let i=await Di(e,t,s+1);r=r&&i.value,s=i.pos}return{value:r,pos:s}}async function Di(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 Di(e,t,n+1);return{value:!s,pos:i}}return Bd(e,t,n)}finally{r.release()}}async function Bd(e,t,n){let r=t[n];if(r==="("){let{value:i,pos:a}=await yc(e,t,n+1);return{value:i,pos:t[a]===")"?a+1:a}}let s=t[n+1];if(Yn(s)){let i=r,a=t[n+2]??"";return{value:ns(s,i,a),pos:n+3}}if(es(s)){let i=as(r),a=as(t[n+2]??"0");return!i.valid||!a.valid?{value:!1,pos:n+3}:{value:ts(s,i.value,a.value),pos:n+3}}if(Yr(s)){let i=r,a=t[n+2]??"";return{value:await Jr(e,s,i,a),pos:n+3}}if(Kr(r)){let i=t[n+1]??"";return{value:await Xr(e,r,i),pos:n+2}}if(rs(r)){let i=t[n+1]??"";return{value:ss(r,i),pos:n+2}}if(r==="-v"){let i=t[n+1]??"";return{value:await is(e,i),pos:n+2}}if(r==="-o"){let i=t[n+1]??"";return{value:Ri(e,i),pos:n+2}}return{value:r!==void 0&&r!=="",pos:n+1}}function An(e,t,n=!1,r=!1,s=256){r&&Wd(t,s);let i=`^${gc(t,r)}$`;return ye(i,n?"is":"s").test(e)}function Wd(e,t){let n=0,r=[];for(let s=0;s<e.length;s++){if(e[s]==="\\"){s++;continue}if(e[s]==="("){let i=s>0&&"@*+?!".includes(e[s-1]);if(r.push(i),i&&n++,n>t)throw new P(`extglob maximum depth (${t}) exceeded`,"recursion")}else e[s]===")"&&r.length>0&&r.pop()&&n--}}function gc(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=wc(e,r+1);if(i!==-1){let a=e.slice(r+2,i),o=Ec(a),l=o.map(u=>gc(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=o.map(h=>bc(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 wc(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 Ec(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 bc(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=wc(e,r+1);if(i!==-1){if(s==="@"){let a=e.slice(r+2,i),l=Ec(a).map(c=>bc(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 Ri(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 pc(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 mc(t);try{let n=new U,r=re(n,t);return await K(e,r.expression)}catch{return mc(t)}}function Fd(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 mc(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=Fd(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 as(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 Vd(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=zd(e,n);t+=r.converted,n=r.endIndex}else t+=e[n],n++;return t}function zd(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 a="",o=!1;for(;n<e.length;){let l=e[n];if(l==="]"){o=!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);a+=qd(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);a+=d,n=f+2;continue}}}if(l==="\\"&&n+1<e.length){a+=l+e[n+1],n+=2;continue}a+=l,n++}return o?(s&&(r+="\\]"),i&&(r+="\\["),r+=a,r+="]",{converted:r,endIndex:n}):{converted:"\\[",endIndex:t+1}}function qd(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 Oi(e,t,n){if(n&&e.length>=n.maxElements)throw new P(`array element limit exceeded (${n.maxElements})`,"array_elements");e.push(t)}function Nt(e,t){if(t&&M(e)>t.maxStringBytes)throw new P(`array assignment string limit exceeded (${t.maxStringBytes} bytes)`,"string_length");let n=[],r="",s=!1,i=!1,a=!1,o=!1;for(let l of e){if(a){r+=l,a=!1,o=!0;continue}if(l==="\\"){a=!0;continue}if(l==="'"&&!i){s||(o=!0),s=!s;continue}if(l==='"'&&!s){i||(o=!0),i=!i;continue}if((l===" "||l===" "||l===`
94
+ `)&&!s&&!i){o&&(Oi(n,r,t),r="",o=!1);continue}r+=l,o=!0}return o&&Oi(n,r,t),n}function os(e,t){if(t&&M(e)>t.maxStringBytes)throw new P(`array assignment string limit exceeded (${t.maxStringBytes} bytes)`,"string_length");let n=[],r=0;for(;r<e.length;){for(;r<e.length&&/\s/.test(e[r]);)r++;if(r>=e.length)break;if(e[r]!=="["){r++;continue}r++;let s="";if(e[r]==="'"||e[r]==='"'){let a=e[r];for(r++;r<e.length&&e[r]!==a;)s+=e[r],r++;e[r]===a&&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 a=e[r];for(r++;r<e.length&&e[r]!==a;)e[r]==="\\"&&r+1<e.length&&r++,i+=e[r],r++;e[r]===a&&r++}else for(;r<e.length&&!/\s/.test(e[r]);)i+=e[r],r++;Oi(n,[s,i],t)}return n}function Sc(e,t){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(n)return{name:n[1],isArray:!0,arrayElements:Nt(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 Ud(e,t){try{let n=new U,r=re(n,t);return await K(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}async function vc(e,t,n={}){let{name:r,isArray:s,arrayElements:i,value:a,arrayIndex:o}=t,{makeReadonly:l=!1,checkReadonly:c=!0}=n;if(c){let u=ce(e,r);if(u)return u}if(s&&i){e.executionScope.consumeWork(i.length,"array assignment");let u=Ae(e,r),f=u?_e(u):void 0,d=e.state.env.get(r);try{ge(e,r);for(let h=0;h<i.length;h++)q(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(o!==void 0&&a!==void 0){let u=await Ud(e,o);q(e,r,u,a)}else a!==void 0&&e.state.env.set(r,a);return l&&Ue(e,r),null}function Ht(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function Ii(e,t){return e.state.localVarDepth?.get(t)}function ls(e,t){e.state.localVarDepth?.delete(t)}function Ac(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 cs(e,t){let n=e.state.localVarStack?.get(t);if(!(!n||n.length===0))return n.pop()}function xc(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 _i=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Pc(e){return _i.has(e)}var Ti=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),xn=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 us=class extends Error{};async function er(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
95
+ `;if(r.checkNoclobber&&e.state.options.noclobber&&!r.isClobber&&n!=="/dev/null")return`bash: ${n}: cannot overwrite existing file
96
+ `}catch{return`bash: ${n}: cannot open redirect target
97
+ `}return null}function Pn(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 jd(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),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),a=s+r+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let c=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let u=o.slice(l+1);return{path:i,position:c,content:u}}async function Li(e,t){let n=new Map;for(let r=0;r<t.length;r++){let s=t[r];if(s.target.type==="HereDoc")continue;if(s.operator===">&"||s.operator==="<&"){if(Xn(e,s.target))return{targets:n,error:`bash: $@: ambiguous redirect
98
+ `};n.set(r,await z(e,s.target))}else{let a=await Zr(e,s.target);if("error"in a)return{targets:n,error:a.error};n.set(r,a.target)}}return{targets:n}}function Gd(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd,n=e.limits.maxFileDescriptors;if(t>=n)throw new Error(`bash: cannot allocate file descriptor: too many open files (max ${n})`);return e.state.nextFd++,t}async function fs(e,t,n){for(let r=0;r<t.length;r++){let s=t[r];if(!s.fdVariable||s.target.type!=="Word")continue;ce(e,s.fdVariable);let i=s.operator===">&"||s.operator==="<&",a=n?.get(r);if(a===void 0)if(i){if(Xn(e,s.target))return I("",`bash: $@: ambiguous redirect
99
+ `,1);a=await z(e,s.target)}else{let c=await Zr(e,s.target);if("error"in c)return I("",c.error,1);a=c.target}if(a.includes("\0"))return I("",`bash: ${a.replace(/\0/g,"")}: No such file or directory
100
+ `,1);if(e.state.fileDescriptors??=new Map,i&&a==="-"){let c=e.state.env.get(s.fdVariable);if(c!==void 0){let u=Number.parseInt(c,10);Number.isNaN(u)||e.state.fileDescriptors.delete(u)}continue}let o;if(i){let c=Number.parseInt(a,10);Number.isNaN(c)||(o=e.state.fileDescriptors.get(c))}else if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let c=e.fs.resolvePath(e.state.cwd,a),u=s.operator===">>"||s.operator==="&>>",f=u?{checkNoclobber:!1}:{checkNoclobber:!0,isClobber:s.operator===">|"},d=await er(e,c,a,f);if(d)return I("",d,1);je(e),u?await e.fs.appendFile(c,"","binary"):await e.fs.writeFile(c,"","binary"),o=`__file__:${c}`}else if(s.operator==="<<<")o=`${a}
101
+ `;else if(s.operator==="<"||s.operator==="<>")try{let c=e.fs.resolvePath(e.state.cwd,a);o=await e.fs.readFile(c)}catch{return I("",`bash: ${a}: No such file or directory
102
+ `,1)}je(e);let l=Gd(e);e.state.env.set(s.fdVariable,String(l)),o!==void 0&&e.state.fileDescriptors.set(l,o)}return null}async function ft(e,t){for(let s of t)s.fdVariable&&ce(e,s.fdVariable);let n=await Li(e,t);if(n.error)return{targets:n.targets,error:I("",n.error,1)};let r=[];for(let s=0;s<t.length;s++){let i=t[s];if(i.target.type==="HereDoc")continue;let a=i.operator===">&";if(i.operator!==">"&&i.operator!==">|"&&i.operator!=="&>"&&!a)continue;let o=n.targets.get(s);if(o===void 0||a&&(o==="-"||!Number.isNaN(Number.parseInt(o,10))||i.fd!=null))continue;let l=e.fs.resolvePath(e.state.cwd,o),c=i.operator===">|";if(l.includes("\0"))return{targets:n.targets,error:I("",`bash: ${o}: No such file or directory
103
+ `,1)};try{if(!await e.fs.exists(l))throw new us;let f=await e.fs.stat(l);if(f.isDirectory)return{targets:n.targets,error:I("",`bash: ${o}: Is a directory
104
+ `,1)};if(e.state.options.noclobber&&!c&&!f.isDirectory&&o!=="/dev/null")return{targets:n.targets,error:I("",`bash: ${o}: cannot overwrite existing file
105
+ `,1)}}catch(u){if(!(u instanceof us))return{targets:n.targets,error:I("",`bash: ${o}: cannot open redirect target
106
+ `,1)}}if(o==="/dev/full")return{targets:n.targets,error:I("",`bash: /dev/full: No space left on device
107
+ `,1)};o!=="/dev/null"&&o!=="/dev/stdout"&&o!=="/dev/stderr"&&r.push({filePath:l,target:o})}for(let{filePath:s,target:i}of r)try{await e.fs.writeFile(s,"","binary")}catch{return{targets:n.targets,error:I("",`bash: ${i}: cannot open redirect target
108
+ `,1)}}return{targets:n.targets,error:null}}async function me(e,t,n,r){n.length>0&&(t=e.executionScope.accountResult(t,"redirection"));let{stdout:s,stderr:i,exitCode:a}=t,l=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",c=E=>l,u={kind:"live-stdout"},f={kind:"live-stderr"};for(let E=0;E<n.length;E++){let b=n[E];if(b.target.type==="HereDoc")continue;let g,w=r?.get(E);if(w!==void 0)g=w;else if(b.operator===">&"||b.operator==="<&"){if(Xn(e,b.target)){i+=`bash: $@: ambiguous redirect
109
+ `,a=1,s="";continue}g=await z(e,b.target)}else{let A=await Zr(e,b.target);if("error"in A){i+=A.error,a=1,s="";continue}g=A.target}if(!b.fdVariable){if(g.includes("\0")){i+=`bash: ${g.replace(/\0/g,"")}: No such file or directory
110
+ `,a=1,s="";continue}switch(b.operator){case">":case">|":case">>":{let S=b.fd??1;if(S!==1&&S!==2)break;let A=b.operator===">>",v=b.operator===">|";if(g==="/dev/stdout"){S===2&&(f=u);break}if(g==="/dev/stderr"){S===1&&(u=f);break}if(g==="/dev/full"){i+=`bash: echo: write error: No space left on device
111
+ `,a=1,S===1&&(s="");break}if(g==="/dev/null"&&S===2){f={kind:"discard"};break}let x=e.fs.resolvePath(e.state.cwd,g),N=await er(e,x,g,{...A?{}:{checkNoclobber:!0,isClobber:v}});if(N){i+=N,a=1,S===1&&(s="");break}A?await e.fs.appendFile(x,"","binary"):await e.fs.writeFile(x,"","binary"),S===1?u={kind:"file",path:x,append:A}:f={kind:"file",path:x,append:A};break}case">&":case"<&":{let S=b.fd??1;if(g==="-")break;if(g.endsWith("-")){let A=g.slice(0,-1),v=Number.parseInt(A,10);if(!Number.isNaN(v)){let x=e.state.fileDescriptors?.get(v);x!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(S,x),v>=3&&e.state.fileDescriptors?.delete(v)):v===1||v===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(S,`__dupout__:${v}`)):v===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(S,`__dupin__:${v}`)):v>=3&&(i+=`bash: ${v}: Bad file descriptor
112
+ `,a=1)}break}if(g==="2"||g==="&2")S===1&&(u=f);else if(g==="1"||g==="&1")S===2?f=u:(s+=i,i="");else{let A=Number.parseInt(g,10);if(Number.isNaN(A)){if(b.operator===">&"){let v=e.fs.resolvePath(e.state.cwd,g),x=await er(e,v,g,{checkNoclobber:!0});if(x){i=x,a=1,s="";break}await e.fs.writeFile(v,"","binary"),b.fd==null?(u={kind:"file",path:v,append:!1},f=u):S===1?u={kind:"file",path:v,append:!1}:S===2&&(f={kind:"file",path:v,append:!1})}}else{let v=e.state.fileDescriptors?.get(A);if(v?.startsWith("__file__:")){let x=v.slice(9);S===1?(await e.fs.appendFile(x,s,c(s)),s=""):S===2&&(await e.fs.appendFile(x,i,Pn(i)),i="")}else if(v?.startsWith("__rw__:")){let x=jd(v);x&&(S===1?(await e.fs.appendFile(x.path,s,c(s)),s=""):S===2&&(await e.fs.appendFile(x.path,i,Pn(i)),i=""))}else if(v?.startsWith("__dupout__:")){let x=Number.parseInt(v.slice(11),10);if(x!==1)if(x===2)S===1&&(i+=s,s="");else{let N=e.state.fileDescriptors?.get(x);if(N?.startsWith("__file__:")){let D=N.slice(9);S===1?(await e.fs.appendFile(D,s,c(s)),s=""):S===2&&(await e.fs.appendFile(D,i,Pn(i)),i="")}}}else v?.startsWith("__dupin__:")?(i+=`bash: ${A}: Bad file descriptor
113
+ `,a=1,s=""):A>=3&&(i+=`bash: ${A}: Bad file descriptor
114
+ `,a=1,s="")}}break}case"&>":{if(g==="/dev/full"){i=`bash: echo: write error: No space left on device
115
+ `,a=1,s="";break}let S=e.fs.resolvePath(e.state.cwd,g),A=await er(e,S,g,{checkNoclobber:!0});if(A){i=A,a=1,s="";break}await e.fs.writeFile(S,"","binary"),u={kind:"file",path:S,append:!1},f=u;break}case"&>>":{if(g==="/dev/full"){i=`bash: echo: write error: No space left on device
116
+ `,a=1,s="";break}let S=e.fs.resolvePath(e.state.cwd,g),A=await er(e,S,g,{});if(A){i=A,a=1,s="";break}await e.fs.appendFile(S,"","binary"),u={kind:"file",path:S,append:!0},f=u;break}}}}if(s!==""||i!==""){let E=s,b=i;s="",i="";let g=async(w,S,A)=>{w.append?await e.fs.appendFile(w.path,S,A):await e.fs.writeFile(w.path,S,A)};if(u===f&&u.kind==="file"){let w=E+b;w!==""&&await g(u,w,c(w))}else for(let[w,S,A]of[[E,u,!0],[b,f,!1]])if(w!=="")switch(S.kind){case"live-stdout":s+=w;break;case"live-stderr":i+=w;break;case"file":await g(S,w,A?c(w):Pn(w));break;case"discard":break}}let d=e.state.fileDescriptors?.get(1);if(d){if(d==="__dupout__:2")i+=s,s="";else if(d.startsWith("__file__:")){let E=d.slice(9);await e.fs.appendFile(E,s,c(s)),s=""}else if(d.startsWith("__file_append__:")){let E=d.slice(16);await e.fs.appendFile(E,s,c(s)),s=""}}let h=e.state.fileDescriptors?.get(2);if(h){if(h==="__dupout__:1")s+=i,i="";else if(h.startsWith("__file__:")){let E=h.slice(9);await e.fs.appendFile(E,i,Pn(i)),i=""}else if(h.startsWith("__file_append__:")){let E=h.slice(16);await e.fs.appendFile(E,i,Pn(i)),i=""}}let p=I(s,i,a);if(t.stdoutKind&&(p.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(p.stdoutEncoding="binary"),t.internalPipeStatusOverride&&(p.internalPipeStatusOverride=t.internalPipeStatusOverride),n.length>0||e.state.fileDescriptors?.has(1)===!0||e.state.fileDescriptors?.has(2)===!0){let E=(t.internalOutputAccounting?.stdout??0)+(t.internalOutputAccounting?.stderr??0),b=M(p.stdout),g=M(p.stderr),w=Math.min(b,E);p.internalOutputAccounting={stdout:w,stderr:Math.min(g,E-w)},e.executionScope.accountResult(p,"redirection")}else t.internalOutputAccounting&&(p.internalOutputAccounting=t.internalOutputAccounting);return p}function $c(e,t){if(e.state.options.posix&&_i.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
117
+ `;throw new H(2,"",r)}let n={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,n),ne}async function Zd(e,t){let n="";for(let r of t)if((r.operator==="<<"||r.operator==="<<-")&&r.target.type==="HereDoc"){let s=r.target,i=await z(e,s.content);s.stripTabs&&(i=i.split(`
118
+ `).map(o=>o.replace(/^\t+/,"")).join(`
119
+ `)),(r.fd??0)===0&&(n=i)}else if(r.operator==="<<<"&&r.target.type==="Word")n=`${await z(e,r.target)}
120
+ `;else if(r.operator==="<"&&r.target.type==="Word"){let s=await z(e,r.target),i=e.fs.resolvePath(e.state.cwd,s);try{n=await e.fs.readFile(i)}catch{}}return n}async function ds(e,t,n,r="",s){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,Gt(`${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 i=new Map,a=Number.parseInt(e.state.env.get("#")??"0",10),o=Math.max(n.length,a);for(let f=0;f<o;f++){let d=String(f+1);i.set(d,e.state.env.get(d)),f<n.length?e.state.env.set(d,n[f]):e.state.env.delete(d)}i.set("@",e.state.env.get("@")),i.set("#",e.state.env.get("#")),e.state.env.set("@",n.join(" ")),e.state.env.set("#",String(n.length));let l=!1,c=()=>{if(l)return;l=!0;let f=e.state.localScopes.length-1,d=e.state.localScopes.pop(),h=e.state.localArrayScopes?.pop();if(d)for(let[p,m]of d)m===void 0?e.state.env.delete(p):e.state.env.set(p,m);if(h){e.state.arrays??=new Map;for(let[p,m]of h)m===void 0?(e.state.arrays.delete(p),e.state.associativeArrays?.delete(p)):(e.state.arrays.set(p,_e(m)),e.state.associativeArrays??=new Set,m.kind==="associative"?e.state.associativeArrays.add(p):e.state.associativeArrays.delete(p))}if(xc(e,f),e.state.fullyUnsetLocals)for(let[p,m]of e.state.fullyUnsetLocals.entries())m===f&&e.state.fullyUnsetLocals.delete(p);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let p=e.state.localExportedVars.pop();if(p)for(let m of p)e.state.exportedVars?.delete(m)}for(let[p,m]of i)m===void 0?e.state.env.delete(p):e.state.env.set(p,m);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},u=new Map;try{let{targets:f,error:d}=await Li(e,t.redirections);if(u=f,d)return I("",d,1);let h=await Zd(e,t.redirections),p=r||h,m=await e.executeCommand(t.body,p);return me(e,m,t.redirections,u)}catch(f){if(f instanceof Me){let d=I(f.stdout,f.stderr,f.exitCode);return me(e,d,t.redirections,u)}throw f}finally{c()}}var Nc=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],Wi=[".",":","[","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"],Hd=["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"],Qd=Wi;async function Fi(e,t){let n=[],r=null,s="",i="",a=null,o=!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 v=0;v<t.length;v++){let x=t[v];if(x==="-v")n.push("variable");else if(x==="-e")n.push("export");else if(x==="-f")n.push("file");else if(x==="-d")n.push("directory");else if(x==="-k")n.push("keyword");else if(x==="-A"){if(v++,v>=t.length)return R(`compgen: -A: option requires an argument
121
+ `,2);let N=t[v];if(!p.includes(N))return R(`compgen: ${N}: invalid action name
122
+ `,2);n.push(N)}else if(x==="-W"){if(v++,v>=t.length)return R(`compgen: -W: option requires an argument
123
+ `,2);r=t[v]}else if(x==="-P"){if(v++,v>=t.length)return R(`compgen: -P: option requires an argument
124
+ `,2);s=t[v]}else if(x==="-S"){if(v++,v>=t.length)return R(`compgen: -S: option requires an argument
125
+ `,2);i=t[v]}else if(x==="-o"){if(v++,v>=t.length)return R(`compgen: -o: option requires an argument
126
+ `,2);let N=t[v];if(N==="plusdirs")o=!0;else if(N==="dirnames")l=!0;else if(N==="default")c=!0;else if(!(N==="filenames"||N==="nospace"||N==="bashdefault"||N==="noquote"))return R(`compgen: ${N}: invalid option name
127
+ `,2)}else if(x==="-F"){if(v++,v>=t.length)return R(`compgen: -F: option requires an argument
128
+ `,2);f=t[v]}else if(x==="-C"){if(v++,v>=t.length)return R(`compgen: -C: option requires an argument
129
+ `,2);d=t[v]}else if(x==="-X"){if(v++,v>=t.length)return R(`compgen: -X: option requires an argument
130
+ `,2);u=t[v]}else if(x==="-G"){if(v++,v>=t.length)return R(`compgen: -G: option requires an argument
131
+ `,2)}else if(x==="--"){h.push(...t.slice(v+1));break}else x.startsWith("-")||h.push(x)}a=h[0]??null;let m=[],E=new Set,b=()=>e.limits.maxArrayElements-m.length,g=v=>{for(let x of v){if(m.length>=e.limits.maxArrayElements)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(M(x)>e.limits.maxStringLength)throw new P(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");e.executionScope.consumeWork(1,"compgen completion"),m.push(x),E.add(x)}};if(l){let v=await Mi(e,a,b());g(v)}if(c){let v=await kc(e,a,b());g(v)}for(let v of n)if(v==="variable"){let x=Kd(e,a,b());g(x)}else if(v==="export"){let x=Xd(e,a,b());g(x)}else if(v==="function"){let x=Yd(e,a,b());g(x)}else if(v==="builtin"){let x=Jd(e,a,b());g(x)}else if(v==="keyword"){let x=eh(e,a,b());g(x)}else if(v==="alias"){let x=th(e,a,b());g(x)}else if(v==="shopt"){let x=nh(e,a,b());g(x)}else if(v==="helptopic"){let x=rh(e,a,b());g(x)}else if(v==="directory"){let x=await Mi(e,a,b());g(x)}else if(v==="file"){let x=await kc(e,a,b());g(x)}else if(v==="user"){let x=sh(e,a,b());g(x)}else if(v==="command"){let x=await ih(e,a,b());g(x)}if(r!==null)try{let v=await ah(e,r),x=oh(e,v,b(),a);for(let N of x)g([N])}catch(v){if(v instanceof P)throw v;return I("","",1)}if(o){let v=await Mi(e,a,b(),E);for(let x of v)E.has(x)||g([x])}let w="";if(f!==null){let v=e.state.functions.get(f);if(v){let x=new Map,N=Ae(e,"COMP_WORDS"),D=N?_e(N):void 0;ge(e,"COMP_WORDS"),Vn(e,"COMP_WORDS"),x.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),x.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),x.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let O=Ae(e,"COMPREPLY"),_=O?_e(O):void 0,V=e.state.env.get("COMPREPLY");ge(e,"COMPREPLY"),e.state.env.delete("COMPREPLY");let J=["compgen",h[0]??"",""];try{let ee=await ds(e,v,J,"");if(ee.exitCode!==0)return Bi(e,x),$n(e,"COMP_WORDS",D),$n(e,"COMPREPLY",_),V!==void 0&&e.state.env.set("COMPREPLY",V),I("",ee.stderr,1);w=ee.stdout;let C=lh(e,b());g(C)}catch(ee){if(ee instanceof P)throw ee;return Bi(e,x),$n(e,"COMP_WORDS",D),$n(e,"COMPREPLY",_),V!==void 0&&e.state.env.set("COMPREPLY",V),I("","",1)}Bi(e,x),$n(e,"COMP_WORDS",D),$n(e,"COMPREPLY",_),V!==void 0&&e.state.env.set("COMPREPLY",V)}}if(d!==null)try{let v=qe(d),x=await e.executeScript(v);if(x.exitCode!==0)return I("",x.stderr,x.exitCode);if(x.stdout)for(let N of ch(x.stdout))N.length>0&&g([N])}catch(v){if(v.name==="ParseException")return R(`compgen: -C: ${v.message}
132
+ `,2);throw v}let S=m;if(u!==null){let v=u.startsWith("!"),x=v?u.slice(1):u;S=m.filter(N=>{let D=An(N,x,!1,!0,e.limits.maxCallDepth);return v?D:!D})}if(S.length===0&&a!==null)return I(w,"",1);let A=new hn(e.limits.maxOutputSize,"compgen");A.append(w);for(let v of S)A.append(s).append(v).append(i).append(`
133
+ `);return Y(A.build())}function Kd(e,t,n){let r=rt(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 Xd(e,t,n){let r=rt(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 Yd(e,t,n){let r=rt(e,t,n);for(let s of e.state.functions.keys())r.add(s);return r.build()}function Jd(e,t,n){let r=rt(e,t,n);for(let s of Wi)r.add(s);return r.build()}function eh(e,t,n){let r=rt(e,t,n);for(let s of Nc)r.add(s);return r.build()}function th(e,t,n){let r=rt(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 nh(e,t,n){let r=rt(e,t,n);for(let s of Hd)r.add(s);return r.build()}function rh(e,t,n){let r=rt(e,t,n);for(let s of Qd)r.add(s);return r.build()}async function Mi(e,t,n=e.limits.maxArrayElements,r){let s=rt(e,null,n,r);try{let i=e.state.cwd,a=t??"";if(t){let l=t.lastIndexOf("/");if(l!==-1){let c=t.slice(0,l)||"/";a=t.slice(l+1),c.startsWith("/")?i=c:i=`${e.state.cwd}/${c}`}}let o=await e.fs.readdir(i);for(let l of o){e.executionScope.consumeWork(1,"compgen directory scan");let c=`${i}/${l}`;try{if((await e.fs.stat(c)).isDirectory&&(!a||l.startsWith(a)))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 P)throw u}}}catch(i){if(i instanceof P)throw i}return s.build()}async function kc(e,t,n=e.limits.maxArrayElements){let r=rt(e,null,n);try{let s=e.state.cwd,i=t??"";if(t){let o=t.lastIndexOf("/");if(o!==-1){let l=t.slice(0,o)||"/";i=t.slice(o+1),l.startsWith("/")?s=l:s=`${e.state.cwd}/${l}`}}let a=await e.fs.readdir(s);for(let o of a)if(e.executionScope.consumeWork(1,"compgen file scan"),!i||o.startsWith(i))if(t?.includes("/")){let l=t.lastIndexOf("/"),c=t.slice(0,l+1);r.add(c+o)}else r.add(o)}catch(s){if(s instanceof P)throw s}return r.build()}function sh(e,t,n){let r=rt(e,t,n);return r.add("root"),r.add("nobody"),r.build()}async function ih(e,t,n){let r=rt(e,t,n);for(let i of Wi)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 Nc)r.add(i);let s=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of s.split(":"))if(i)try{let a=await e.fs.readdir(i);for(let o of a)r.add(o)}catch(a){if(a instanceof P)throw a}return r.build()}function rt(e,t,n,r){let s=new Set;return{add(i){if(e.executionScope.consumeWork(1,"compgen candidate collection"),!(t!==null&&!i.startsWith(t))&&!r?.has(i)&&!s.has(i)){if(s.size>=n)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(M(i)>e.limits.maxStringLength)throw new P(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");s.add(i)}},build(){return Array.from(s).sort()}}}async function ah(e,t){let r=new U().parseWordFromString(t,!1,!1);return await z(e,r)}function oh(e,t,n,r){let s=e.state.env.get("IFS")??`
134
+ `;if(s.length===0){if(r!==null&&!t.startsWith(r))return[];if(n===0)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");return[t]}let i=new Set(s.split("")),a=[],o=u=>{if(!(r!==null&&!u.startsWith(r))){if(a.length>=n)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");a.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&&(o(l),l=""),c++):(l+=u,c++)}return l.length>0&&o(l),a}function Bi(e,t){for(let[n,r]of t)r===void 0?e.state.env.delete(n):e.state.env.set(n,r)}function $n(e,t,n){e.state.arrays??=new Map,n?e.state.arrays.set(t,_e(n)):e.state.arrays.delete(t)}function lh(e,t){let n=[],r=s=>{if(n.length>=t)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");n.push(s)};if(Ne(e,"COMPREPLY")){let s=j(e,"COMPREPLY");for(let[,i]of s)r(i)}else{let s=e.state.env.get("COMPREPLY");s!==void 0&&r(s)}return n}function*ch(e){let t=0;for(;t<=e.length;){let n=e.indexOf(`
135
+ `,t),r=n===-1?e.length:n;if(r>t&&(yield e.slice(t,r)),n===-1)return;t=n+1}}function tr(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n===127)return!0}return!1}function Vi(e){let t="$'";for(let n=0;n<e.length;n++){let r=e[n],s=e.charCodeAt(n);s===7?t+="\\a":s===8?t+="\\b":s===9?t+="\\t":s===10?t+="\\n":s===11?t+="\\v":s===12?t+="\\f":s===13?t+="\\r":s===27?t+="\\e":s===39?t+="\\'":s===92?t+="\\\\":s<32||s===127?t+=`\\${s.toString(8).padStart(3,"0")}`:t+=r}return t+="'",t}function Cc(e){if(tr(e))return Dc(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 Ee(e){return tr(e)?Vi(e):e===""?"''":/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function hs(e){if(tr(e))return Dc(e);let t=M(e)+2;for(let n of e)(n==="\\"||n==='"'||n==="$"||n==="`")&&t++;return t}function Qt(e){return tr(e)?Vi(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}function Dc(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 nr(e){return tr(e)?Vi(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}var uh=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function qi(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=!1,i,a,o,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 R(`complete: -W: option requires an argument
136
+ `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return R(`complete: -F: option requires an argument
137
+ `,2);a=t[f]}else if(d==="-o"){if(f++,f>=t.length)return R(`complete: -o: option requires an argument
138
+ `,2);let h=t[f];if(!uh.includes(h))return R(`complete: ${h}: invalid option name
139
+ `,2);l.push(h)}else if(d==="-A"){if(f++,f>=t.length)return R(`complete: -A: option requires an argument
140
+ `,2);c.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return R(`complete: -C: option requires an argument
141
+ `,2);o=t[f]}else if(d==="-G"){if(f++,f>=t.length)return R(`complete: -G: option requires an argument
142
+ `,2)}else if(d==="-P"){if(f++,f>=t.length)return R(`complete: -P: option requires an argument
143
+ `,2)}else if(d==="-S"){if(f++,f>=t.length)return R(`complete: -S: option requires an argument
144
+ `,2)}else if(d==="-X"){if(f++,f>=t.length)return R(`complete: -X: option requires an argument
145
+ `,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,Y("");for(let f of u)e.state.completionSpecs.delete(f);return Y("")}if(n)return u.length===0?zi(e):zi(e,u);if(t.length===0||u.length===0&&!i&&!a&&!o&&l.length===0&&c.length===0&&!s)return zi(e);if(a&&u.length===0&&!s)return R(`complete: -F: option requires a command name
146
+ `,2);if(s){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),a!==void 0&&(f.function=a),o!==void 0&&(f.command=o),l.length>0&&(f.options=l),c.length>0&&(f.actions=c),e.state.defaultCompletionSpec=f,Y("")}for(let f of u){let d=Object.create(null);i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),o!==void 0&&(d.command=o),l.length>0&&(d.options=l),c.length>0&&(d.actions=c),e.state.completionSpecs.set(f,d)}return Y("")}function zi(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 a of t)i+=`complete: ${a}: no completion specification
147
+ `;return I("",i,1)}return Y("")}let r=[],s=t||Array.from(n.keys());for(let i of s){let a=n.get(i);if(!a){if(t)return I(r.join(`
142
148
  `)+(r.length>0?`
143
149
  `:""),`complete: ${i}: no completion specification
144
- `,1);continue}let l="complete";if(a.options)for(let o of a.options)l+=` -o ${o}`;if(a.actions)for(let o of a.actions)l+=` -A ${o}`;a.wordlist!==void 0&&(a.wordlist.includes(" ")||a.wordlist.includes("'")?l+=` -W '${a.wordlist}'`:l+=` -W ${a.wordlist}`),a.function!==void 0&&(l+=` -F ${a.function}`),a.isDefault&&(l+=" -D"),l+=` ${i}`,r.push(l)}return r.length===0?H(""):H(`${r.join(`
150
+ `,1);continue}let o="complete";if(a.options)for(let l of a.options)o+=` -o ${Ee(l)}`;if(a.actions)for(let l of a.actions)o+=` -A ${Ee(l)}`;a.wordlist!==void 0&&(a.wordlist.includes(" ")||a.wordlist.includes("'")?o+=` -W ${Ee(a.wordlist)}`:o+=` -W ${Ee(a.wordlist)}`),a.function!==void 0&&(o+=` -F ${Ee(a.function)}`),a.command!==void 0&&(o+=` -C ${Ee(a.command)}`),a.isDefault&&(o+=" -D"),o+=`${i.startsWith("-")?" -- ":" "}${Ee(i)}`,r.push(o)}if(!t&&e.state.defaultCompletionSpec){let i=e.state.defaultCompletionSpec,a="complete";for(let o of i.options??[])a+=` -o ${Ee(o)}`;for(let o of i.actions??[])a+=` -A ${Ee(o)}`;i.wordlist!==void 0&&(a+=` -W ${Ee(i.wordlist)}`),i.function!==void 0&&(a+=` -F ${Ee(i.function)}`),i.command!==void 0&&(a+=` -C ${Ee(i.command)}`),a+=" -D",r.push(a)}return r.length===0?Y(""):Y(`${r.join(`
145
151
  `)}
146
- `)}var ml=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function jr(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,r=!1,n=[],i=[],a=[];for(let l=0;l<t.length;l++){let o=t[l];if(o==="-D")s=!0;else if(o==="-E")r=!0;else if(o==="-o"){if(l++,l>=t.length)return N(`compopt: -o: option requires an argument
147
- `,2);let u=t[l];if(!ml.includes(u))return N(`compopt: ${u}: invalid option name
148
- `,2);n.push(u)}else if(o==="+o"){if(l++,l>=t.length)return N(`compopt: +o: option requires an argument
149
- `,2);let u=t[l];if(!ml.includes(u))return N(`compopt: ${u}: invalid option name
150
- `,2);i.push(u)}else if(o==="--"){a.push(...t.slice(l+1));break}else!o.startsWith("-")&&!o.startsWith("+")&&a.push(o)}if(s){let l=e.state.completionSpecs.get("__default__")??{isDefault:!0},o=new Set(l.options??[]);for(let u of n)o.add(u);for(let u of i)o.delete(u);return l.options=o.size>0?Array.from(o):void 0,e.state.completionSpecs.set("__default__",l),H("")}if(r){let l=e.state.completionSpecs.get("__empty__")??{},o=new Set(l.options??[]);for(let u of n)o.add(u);for(let u of i)o.delete(u);return l.options=o.size>0?Array.from(o):void 0,e.state.completionSpecs.set("__empty__",l),H("")}if(a.length>0){for(let l of a){let o=e.state.completionSpecs.get(l)??{},u=new Set(o.options??[]);for(let c of n)u.add(c);for(let c of i)u.delete(c);o.options=u.size>0?Array.from(u):void 0,e.state.completionSpecs.set(l,o)}return H("")}return N(`compopt: not currently executing completion function
151
- `,1)}function Ur(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Et;return K}if(t.length>1)throw new Z(1,"",`bash: continue: too many arguments
152
- `);let s=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new Z(1,"",`bash: continue: ${t[0]}: numeric argument required
153
- `);s=r}throw new Te(s)}function de(e,t){let s=e.state.env.get("HOME")||"/home/user";return t.split(":").map(i=>i==="~"?s:i==="~root"?"/root":i.startsWith("~/")?s+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function Zr(e){for(let t=0;t<e.length;t++){let s=e.charCodeAt(t);if(s<32||s===127)return!0}return!1}function Gr(e){let t="$'";for(let s=0;s<e.length;s++){let r=e[s],n=e.charCodeAt(s);n===7?t+="\\a":n===8?t+="\\b":n===9?t+="\\t":n===10?t+="\\n":n===11?t+="\\v":n===12?t+="\\f":n===13?t+="\\r":n===27?t+="\\e":n===39?t+="\\'":n===92?t+="\\\\":n<32||n===127?t+=`\\${n.toString(8).padStart(3,"0")}`:t+=r}return t+="'",t}function vn(e){return Zr(e)?Gr(e):/^[a-zA-Z0-9_/.:\-@%+,=]*$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Lt(e){return Zr(e)?Gr(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Hr(e){return Zr(e)?Gr(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function gl(e,t){let s="";return e.state.integerVars?.has(t)&&(s+="i"),e.state.lowercaseVars?.has(t)&&(s+="l"),te(e,t)&&(s+="n"),e.state.readonlyVars?.has(t)&&(s+="r"),e.state.uppercaseVars?.has(t)&&(s+="u"),e.state.exportedVars?.has(t)&&(s+="x"),s===""?"--":`-${s}`}function Qr(e){return e===""?"''":/[\s'\\]/.test(e)?`'${e.replace(/'/g,"'\\''")}'`:e}function yl(e,t){let s="",r="",n=!1;for(let i of t){let a=gl(e,i);if(e.state.associativeArrays?.has(i)){let c=Ge(e,i);if(c.length===0)s+=`declare -A ${i}=()
154
- `;else{let f=c.map(d=>{let h=e.state.env.get(`${i}_${d}`)??"",m=Qr(h);return`['${d}']=${m}`});s+=`declare -A ${i}=(${f.join(" ")})
155
- `}continue}let o=he(e,i);if(o.length>0){let c=o.map(f=>{let d=e.state.env.get(`${i}_${f}`)??"";return`[${f}]=${Lt(d)}`});s+=`declare -a ${i}=(${c.join(" ")})
156
- `;continue}if(e.state.env.has(`${i}__length`)){s+=`declare -a ${i}=()
157
- `;continue}let u=e.state.env.get(i);if(u!==void 0)s+=`declare ${a} ${i}=${Hr(u)}
158
- `;else{let c=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);c||f?s+=`declare ${a} ${i}
152
+ `)}var Rc=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Ui(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=[],i=[],a=[];for(let o=0;o<t.length;o++){let l=t[o];if(l==="-D")n=!0;else if(l==="-E")r=!0;else if(l==="-o"){if(o++,o>=t.length)return R(`compopt: -o: option requires an argument
153
+ `,2);let c=t[o];if(!Rc.includes(c))return R(`compopt: ${c}: invalid option name
154
+ `,2);s.push(c)}else if(l==="+o"){if(o++,o>=t.length)return R(`compopt: +o: option requires an argument
155
+ `,2);let c=t[o];if(!Rc.includes(c))return R(`compopt: ${c}: invalid option name
156
+ `,2);i.push(c)}else if(l==="--"){a.push(...t.slice(o+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&a.push(l)}if(n){let o=e.state.defaultCompletionSpec??{isDefault:!0},l=new Set(o.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return o.options=l.size>0?Array.from(l):void 0,e.state.defaultCompletionSpec=o,Y("")}if(r){let o=e.state.emptyCompletionSpec??Object.create(null),l=new Set(o.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return o.options=l.size>0?Array.from(l):void 0,e.state.emptyCompletionSpec=o,Y("")}if(a.length>0){for(let o of a){let l=e.state.completionSpecs.get(o)??{},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(o,l)}return Y("")}return R(`compopt: not currently executing completion function
157
+ `,1)}function ji(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Ot;return ne}if(t.length>1)throw new H(1,"",`bash: continue: too many arguments
158
+ `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new H(1,"",`bash: continue: ${t[0]}: numeric argument required
159
+ `);n=r}throw new He(n)}function Oc(e,t){let n="";return e.state.integerVars?.has(t)&&(n+="i"),e.state.lowercaseVars?.has(t)&&(n+="l"),le(e,t)&&(n+="n"),e.state.readonlyVars?.has(t)&&(n+="r"),e.state.uppercaseVars?.has(t)&&(n+="u"),e.state.exportedVars?.has(t)&&(n+="x"),n===""?"--":`-${n}`}function Gi(e){return Ee(e)}function Zi(e){return`'${e.replace(/'/g,"'\\''")}'`}function Ic(e,t){let n="",r="",s=!1;for(let i of t){let a=Oc(e,i);if(e.state.associativeArrays?.has(i)){let u=mt(e,i);if(u.length===0)n+=`declare -A ${i}=()
160
+ `;else{let f=u.map(d=>{let h=ae(e,i,d)??"",p=Gi(h);return`[${Zi(d)}]=${p}`});n+=`declare -A ${i}=(${f.join(" ")})
161
+ `}continue}let l=Se(e,i);if(l.length>0){let u=l.map(f=>{let d=ae(e,i,f)??"";return`[${f}]=${Qt(d)}`});n+=`declare -a ${i}=(${u.join(" ")})
162
+ `;continue}if(Ne(e,i)){n+=`declare -a ${i}=()
163
+ `;continue}let c=e.state.env.get(i);if(c!==void 0)n+=`declare ${a} ${i}=${nr(c)}
164
+ `;else{let u=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);u||f?n+=`declare ${a} ${i}
159
165
  `:(r+=`bash: declare: ${i}: not found
160
- `,n=!0)}}return _(s,r,n?1:0)}function wl(e,t){let{filterExport:s,filterReadonly:r,filterNameref:n,filterIndexedArray:i,filterAssocArray:a}=t,l=s||r||n||i||a,o="",u=new Set;for(let f of e.state.env.keys()){if(f.startsWith("BASH_"))continue;if(f.endsWith("__length")){let h=f.slice(0,-8);u.add(h);continue}let d=f.lastIndexOf("_");if(d>0){let h=f.slice(0,d),m=f.slice(d+1);if(/^\d+$/.test(m)||e.state.associativeArrays?.has(h)){u.add(h);continue}}u.add(f)}if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())u.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)u.add(f);let c=Array.from(u).sort();for(let f of c){let d=gl(e,f),h=e.state.associativeArrays?.has(f),m=he(e,f),p=!h&&(m.length>0||e.state.env.has(`${f}__length`));if(l&&(a&&!h||i&&!p||s&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||n&&!te(e,f)))continue;if(h){let b=Ge(e,f);if(b.length===0)o+=`declare -A ${f}=()
161
- `;else{let v=b.map(E=>{let w=e.state.env.get(`${f}_${E}`)??"",S=Qr(w);return`['${E}']=${S}`});o+=`declare -A ${f}=(${v.join(" ")})
162
- `}continue}if(m.length>0){let b=m.map(v=>{let E=e.state.env.get(`${f}_${v}`)??"";return`[${v}]=${Lt(E)}`});o+=`declare -a ${f}=(${b.join(" ")})
163
- `;continue}if(e.state.env.has(`${f}__length`)){o+=`declare -a ${f}=()
164
- `;continue}let y=e.state.env.get(f);y!==void 0&&(o+=`declare ${d} ${f}=${Hr(y)}
165
- `)}return H(o)}function El(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let r of s){let n=Ge(e,r);if(n.length===0)t+=`declare -A ${r}=()
166
- `;else{let i=n.map(a=>{let l=e.state.env.get(`${r}_${a}`)??"",o=Qr(l);return`['${a}']=${o}`});t+=`declare -A ${r}=(${i.join(" ")})
167
- `}}return H(t)}function bl(e){let t="",s=new Set;for(let n of e.state.env.keys()){if(n.startsWith("BASH_"))continue;if(n.endsWith("__length")){let a=n.slice(0,-8);e.state.associativeArrays?.has(a)||s.add(a);continue}let i=n.lastIndexOf("_");if(i>0){let a=n.slice(0,i),l=n.slice(i+1);/^\d+$/.test(l)&&(e.state.associativeArrays?.has(a)||s.add(a))}}let r=Array.from(s).sort();for(let n of r){let i=he(e,n);if(i.length===0)t+=`declare -a ${n}=()
168
- `;else{let a=i.map(l=>{let o=e.state.env.get(`${n}_${l}`)??"";return`[${l}]=${Lt(o)}`});t+=`declare -a ${n}=(${a.join(" ")})
169
- `}}return H(t)}function vl(e){let t="",s=new Set;for(let n of e.state.env.keys()){if(n.startsWith("BASH_"))continue;if(n.endsWith("__length")){let a=n.slice(0,-8);s.add(a);continue}let i=n.lastIndexOf("_");if(i>0){let a=n.slice(0,i),l=n.slice(i+1);if(/^\d+$/.test(l)||e.state.associativeArrays?.has(a)){s.add(a);continue}}s.add(n)}let r=Array.from(s).sort();for(let n of r){if(e.state.associativeArrays?.has(n)||he(e,n).length>0||e.state.env.has(`${n}__length`))continue;let l=e.state.env.get(n);l!==void 0&&(t+=`${n}=${vn(l)}
170
- `)}return H(t)}function Kr(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function ws(e,t){return e.state.integerVars?.has(t)??!1}function Xr(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Uf(e,t){return e.state.lowercaseVars?.has(t)??!1}function Yr(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Zf(e,t){return e.state.uppercaseVars?.has(t)??!1}function Jt(e,t,s){return Uf(e,t)?s.toLowerCase():Zf(e,t)?s.toUpperCase():s}async function Sl(e,t){try{let s=new q,r=Y(s,t),n=await T(e,r.expression);return String(n)}catch{return"0"}}function Gf(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let s=t[0],r=s.length;if(e[r]!=="[")return null;let n=0,i=r+1;for(;r<e.length;r++)if(e[r]==="[")n++;else if(e[r]==="]"&&(n--,n===0))break;if(n!==0)return null;let a=e.slice(i,r);if(r++,e[r]!=="=")return null;r++;let l=e.slice(r);return{name:s,indexExpr:a,value:l}}async function Jr(e,t){let s=!1,r=!1,n=!1,i=!1,a=!1,l=!1,o=!1,u=!1,c=!1,f=!1,d=!1,h=!1,m=!1,p=!1,y=!1,b=[];for(let C=0;C<t.length;C++){let F=t[C];if(F==="-a")s=!0;else if(F==="-A")r=!0;else if(F==="-r")n=!0;else if(F==="-x")i=!0;else if(F==="-p")a=!0;else if(F==="-n")l=!0;else if(F==="+n")o=!0;else if(F==="+a")u=!0;else if(F==="+x")c=!0;else if(F==="--"){b.push(...t.slice(C+1));break}else if(F.startsWith("+")){for(let k of F.slice(1))if(k==="n")o=!0;else if(k==="a")u=!0;else if(k==="x")c=!0;else if(k!=="r"){if(k!=="i"){if(!(k==="f"||k==="F"))return _("",`bash: typeset: +${k}: invalid option
171
- `,2)}}}else if(F==="-i")f=!0;else if(F==="-l")d=!0;else if(F==="-u")h=!0;else if(F==="-f")m=!0;else if(F==="-F")p=!0;else if(F==="-g")y=!0;else if(F.startsWith("-"))for(let k of F.slice(1))if(k==="a")s=!0;else if(k==="A")r=!0;else if(k==="r")n=!0;else if(k==="x")i=!0;else if(k==="p")a=!0;else if(k==="n")l=!0;else if(k==="i")f=!0;else if(k==="l")d=!0;else if(k==="u")h=!0;else if(k==="f")m=!0;else if(k==="F")p=!0;else if(k==="g")y=!0;else return _("",`bash: typeset: -${k}: invalid option
172
- `,2);else b.push(F)}let E=e.state.localScopes.length>0&&!y,w=C=>{if(!E)return;let F=e.state.localScopes[e.state.localScopes.length-1];F.has(C)||F.set(C,e.state.env.get(C))},S=C=>{if(!E)return;let F=e.state.localScopes[e.state.localScopes.length-1];F.has(C)||F.set(C,e.state.env.get(C));let k=`${C}_`;for(let D of e.state.env.keys())D.startsWith(k)&&!D.includes("__")&&(F.has(D)||F.set(D,e.state.env.get(D)));let x=`${C}__length`;e.state.env.has(x)&&!F.has(x)&&F.set(x,e.state.env.get(x))},A=C=>{E&&Ct(e,C)};if(p){if(b.length===0){let k=Array.from(e.state.functions.keys()).sort(),x="";for(let D of k)x+=`declare -f ${D}
173
- `;return H(x)}let C=!0,F="";for(let k of b)e.state.functions.has(k)?F+=`${k}
174
- `:C=!1;return _(F,"",C?0:1)}if(m){if(b.length===0){let F="",k=Array.from(e.state.functions.keys()).sort();for(let x of k)F+=`${x} ()
166
+ `,s=!0)}}return I(n,r,s?1:0)}function _c(e,t){let{filterExport:n,filterReadonly:r,filterNameref:s,filterIndexedArray:i,filterAssocArray:a}=t,o=n||r||s||i||a,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=Oc(e,f),h=e.state.associativeArrays?.has(f),p=Se(e,f),m=!h&&Ne(e,f);if(o&&(a&&!h||i&&!m||n&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||s&&!le(e,f)))continue;if(h){let b=mt(e,f);if(b.length===0)l+=`declare -A ${f}=()
167
+ `;else{let g=b.map(w=>{let S=ae(e,f,w)??"",A=Gi(S);return`[${Zi(w)}]=${A}`});l+=`declare -A ${f}=(${g.join(" ")})
168
+ `}continue}if(p.length>0){let b=p.map(g=>{let w=ae(e,f,g)??"";return`[${g}]=${Qt(w)}`});l+=`declare -a ${f}=(${b.join(" ")})
169
+ `;continue}if(Ne(e,f)){l+=`declare -a ${f}=()
170
+ `;continue}let E=e.state.env.get(f);E!==void 0&&(l+=`declare ${d} ${f}=${nr(E)}
171
+ `)}return Y(l)}function Tc(e){let t="",n=Array.from(e.state.associativeArrays??[]).sort();for(let r of n){let s=mt(e,r);if(s.length===0)t+=`declare -A ${r}=()
172
+ `;else{let i=s.map(a=>{let o=ae(e,r,a)??"",l=Gi(o);return`[${Zi(a)}]=${l}`});t+=`declare -A ${r}=(${i.join(" ")})
173
+ `}}return Y(t)}function Lc(e){let t="",n=new Set(Array.from(e.state.arrays??[]).filter(([,s])=>s.kind==="indexed").map(([s])=>s)),r=Array.from(n).sort();for(let s of r){let i=Se(e,s);if(i.length===0)t+=`declare -a ${s}=()
174
+ `;else{let a=i.map(o=>{let l=ae(e,s,o)??"";return`[${o}]=${Qt(l)}`});t+=`declare -a ${s}=(${a.join(" ")})
175
+ `}}return Y(t)}function Mc(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)||Se(e,s).length>0||Ne(e,s))continue;let o=e.state.env.get(s);o!==void 0&&(t+=`${s}=${Ee(o)}
176
+ `)}return Y(t)}function Hi(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function rr(e,t){return e.state.integerVars?.has(t)??!1}function Qi(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function fh(e,t){return e.state.lowercaseVars?.has(t)??!1}function Ki(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function dh(e,t){return e.state.uppercaseVars?.has(t)??!1}function kn(e,t,n){return fh(e,t)?n.toLowerCase():dh(e,t)?n.toUpperCase():n}async function Bc(e,t){try{let n=new U,r=re(n,t),s=await K(e,r.expression);return String(s)}catch{return"0"}}function hh(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 a=e.slice(i,r);if(r++,e[r]!=="=")return null;r++;let o=e.slice(r);return{name:n,indexExpr:a,value:o}}async function Xi(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,a=!1,o=!1,l=!1,c=!1,u=!1,f=!1,d=!1,h=!1,p=!1,m=!1,E=!1,b=!1,g=[];for(let O=0;O<t.length;O++){let _=t[O];if(_==="-a")r=!0;else if(_==="-A")s=!0;else if(_==="-r")i=!0;else if(_==="-x")a=!0;else if(_==="-p")o=!0;else if(_==="-n")l=!0;else if(_==="+n")c=!0;else if(_==="+a")u=!0;else if(_==="+x")f=!0;else if(_==="--"){g.push(...t.slice(O+1));break}else if(_.startsWith("+")){for(let V of _.slice(1))if(V==="n")c=!0;else if(V==="a")u=!0;else if(V==="x")f=!0;else if(V!=="r"){if(V!=="i"){if(!(V==="f"||V==="F"))return I("",`bash: typeset: +${V}: invalid option
177
+ `,2)}}}else if(_==="-i")d=!0;else if(_==="-l")h=!0;else if(_==="-u")p=!0;else if(_==="-f")m=!0;else if(_==="-F")E=!0;else if(_==="-g")b=!0;else if(_.startsWith("-"))for(let V of _.slice(1))if(V==="a")r=!0;else if(V==="A")s=!0;else if(V==="r")i=!0;else if(V==="x")a=!0;else if(V==="p")o=!0;else if(V==="n")l=!0;else if(V==="i")d=!0;else if(V==="l")h=!0;else if(V==="u")p=!0;else if(V==="f")m=!0;else if(V==="F")E=!0;else if(V==="g")b=!0;else return I("",`bash: typeset: -${V}: invalid option
178
+ `,2);else g.push(_)}let S=e.state.localScopes.length>0&&!b,A=O=>{if(!S)return;let _=e.state.localScopes[e.state.localScopes.length-1];_.has(O)||_.set(O,e.state.env.get(O))},v=O=>{if(!S)return;let _=e.state.localScopes[e.state.localScopes.length-1];for(_.has(O)||_.set(O,e.state.env.get(O)),e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let V=e.state.localArrayScopes.at(-1);if(V&&!V.has(O)){let J=Ae(e,O);V.set(O,J?_e(J):void 0)}},x=O=>{S&&Ht(e,O)};if(E){if(g.length===0){let V=Array.from(e.state.functions.keys()).sort(),J="";for(let ee of V)J+=`declare -f ${ee}
179
+ `;return Y(J)}let O=!0,_="";for(let V of g)e.state.functions.has(V)?_+=`${V}
180
+ `:O=!1;return I(_,"",O?0:1)}if(m){if(g.length===0){let _="",V=Array.from(e.state.functions.keys()).sort();for(let J of V)_+=`${J} ()
175
181
  {
176
182
  # function body
177
183
  }
178
- `;return H(F)}let C=!0;for(let F of b)e.state.functions.has(F)||(C=!1);return _("","",C?0:1)}if(a&&b.length>0)return yl(e,b);if(a&&b.length===0)return wl(e,{filterExport:i,filterReadonly:n,filterNameref:l,filterIndexedArray:s,filterAssocArray:r});if(b.length===0&&r&&!a)return El(e);if(b.length===0&&s&&!a)return bl(e);if(b.length===0&&!a)return vl(e);let $="",R=0;for(let C of b){let F=C.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(F&&!u){let P=F[1],O=F[2];if(r&&he(e,P).length>0){$+=`bash: declare: ${P}: cannot convert indexed to associative array
179
- `,R=1;continue}if((s||!r&&!s)&&e.state.associativeArrays?.has(P)){$+=`bash: declare: ${P}: cannot convert associative to indexed array
180
- `,R=1;continue}if(S(P),r&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(P)),tt(e,P),e.state.env.delete(P),e.state.env.delete(`${P}__length`),r&&O.includes("[")){let z=mn(O);for(let[U,ee]of z){let fe=de(e,ee);e.state.env.set(`${P}_${U}`,fe)}}else if(r){let z=ot(O);for(let U=0;U<z.length;U+=2){let ee=z[U],fe=U+1<z.length?de(e,z[U+1]):"";e.state.env.set(`${P}_${ee}`,fe)}}else{let z=ot(O);if(z.some(ee=>/^\[[^\]]+\]=/.test(ee))){let ee=0;for(let fe of z){let ge=fe.match(/^\[([^\]]+)\]=(.*)$/);if(ge){let Re=ge[1],Vt=ge[2],kc=de(e,Vt),as;if(/^-?\d+$/.test(Re))as=Number.parseInt(Re,10);else try{let Nc=new q,_c=Y(Nc,Re);as=await T(e,_c.expression)}catch{as=0}e.state.env.set(`${P}_${as}`,kc),ee=as+1}else{let Re=de(e,fe);e.state.env.set(`${P}_${ee}`,Re),ee++}}}else{for(let ee=0;ee<z.length;ee++)e.state.env.set(`${P}_${ee}`,z[ee]);e.state.env.set(`${P}__length`,String(z.length))}}A(P),n&&De(e,P),i&&Qe(e,P);continue}if(o){let P=C.includes("=")?C.slice(0,C.indexOf("=")):C;if(Ma(e,P),!C.includes("="))continue}if(c){let P=C.includes("=")?C.slice(0,C.indexOf("=")):C;if(Hs(e,P),!C.includes("="))continue}let k=Gf(C);if(k){let{name:P,indexExpr:O,value:z}=k,U=ye(e,P);if(U)return U;S(P);let ee;try{let ge=new q,Re=Y(ge,O);ee=await T(e,Re.expression)}catch{let ge=parseInt(O,10);ee=Number.isNaN(ge)?0:ge}e.state.env.set(`${P}_${ee}`,z);let fe=parseInt(e.state.env.get(`${P}__length`)??"0",10);ee>=fe&&e.state.env.set(`${P}__length`,String(ee+1)),A(P),n&&De(e,P),i&&Qe(e,P);continue}let x=C.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(x&&!u){let P=x[1],O=x[2],z=ye(e,P);if(z)return z;S(P);let U=ot(O);if(e.state.associativeArrays?.has(P)){let ee=mn(O);for(let[fe,ge]of ee){let Re=de(e,ge);e.state.env.set(`${P}_${fe}`,Re)}}else{let ee=he(e,P),fe=0,ge=e.state.env.get(P);ee.length===0&&ge!==void 0?(e.state.env.set(`${P}_0`,ge),e.state.env.delete(P),fe=1):ee.length>0&&(fe=Math.max(...ee)+1);for(let Vt=0;Vt<U.length;Vt++)e.state.env.set(`${P}_${fe+Vt}`,de(e,U[Vt]));let Re=fe+U.length;e.state.env.set(`${P}__length`,String(Re))}A(P),n&&De(e,P),i&&Qe(e,P);continue}let D=C.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(D){let P=D[1],O=de(e,D[2]),z=ye(e,P);if(z)return z;w(P),f&&Kr(e,P),d&&Xr(e,P),h&&Yr(e,P);let ee=he(e,P).length>0||e.state.associativeArrays?.has(P);if(ws(e,P)){let fe=e.state.env.get(P)??"0",ge=parseInt(fe,10)||0,Re=parseInt(await Sl(e,O),10)||0;O=String(ge+Re),e.state.env.set(P,O)}else if(ee){O=Jt(e,P,O);let fe=`${P}_0`,ge=e.state.env.get(fe)??"";e.state.env.set(fe,ge+O)}else{O=Jt(e,P,O);let fe=e.state.env.get(P)??"";e.state.env.set(P,fe+O)}A(P),n&&De(e,P),i&&Qe(e,P),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(P));continue}if(C.includes("=")){let P=C.indexOf("="),O=C.slice(0,P),z=C.slice(P+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(O)){$+=`bash: typeset: \`${O}': not a valid identifier
181
- `,R=1;continue}let U=ye(e,O);if(U)return U;if(w(O),l){if(z!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(z)){$+=`bash: declare: \`${z}': invalid variable name for name reference
182
- `,R=1;continue}e.state.env.set(O,z),pt(e,O),z!==""&&Zs(e,z)&&Ar(e,O),A(O),n&&De(e,O),i&&Qe(e,O);continue}if(f&&Kr(e,O),d&&Xr(e,O),h&&Yr(e,O),ws(e,O)&&(z=await Sl(e,z)),z=Jt(e,O,z),te(e,O)){let ee=$e(e,O);ee&&ee!==O?e.state.env.set(ee,z):e.state.env.set(O,z)}else e.state.env.set(O,z);A(O),n&&De(e,O),i&&Qe(e,O),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(O))}else{let P=C;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(P)){$+=`bash: typeset: \`${P}': not a valid identifier
183
- `,R=1;continue}if(s||r?S(P):w(P),l){pt(e,P);let z=e.state.env.get(P);z!==void 0&&z!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(z)?Wa(e,P):z&&Zs(e,z)&&Ar(e,P),A(P),n&&De(e,P),i&&Qe(e,P);continue}if(f&&Kr(e,P),d&&Xr(e,P),h&&Yr(e,P),r){if(he(e,P).length>0){$+=`bash: declare: ${P}: cannot convert indexed to associative array
184
- `,R=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(P)}let O=Array.from(e.state.env.keys()).some(z=>z.startsWith(`${P}_`)&&!z.startsWith(`${P}__length`));!e.state.env.has(P)&&!O&&(s||r?e.state.env.set(`${P}__length`,"0"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(P))),A(P),n&&De(e,P),i&&Qe(e,P)}}return _("",$,R)}async function ei(e,t){let s=!1,r=!1,n=!1,i=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-a")s=!0;else if(l==="-A")r=!0;else if(l==="-p")n=!0;else if(l==="--"){i.push(...t.slice(a+1));break}else l.startsWith("-")||i.push(l)}if(i.length===0){let a="",l=Array.from(e.state.readonlyVars||[]).sort();for(let o of l){let u=e.state.env.get(o);if(u!==void 0){let c=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${o}="${c}"
185
- `}}return H(a)}for(let a of i){let l=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(l){let f=l[1],d=l[2],h=ye(e,f);if(h)return h;let m=ot(d);if(e.state.associativeArrays?.has(f)){let p=mn(d);for(let[y,b]of p){let v=de(e,b);e.state.env.set(`${f}_${y}`,v)}}else{let p=he(e,f),y=0,b=e.state.env.get(f);p.length===0&&b!==void 0?(e.state.env.set(`${f}_0`,b),e.state.env.delete(f),y=1):p.length>0&&(y=Math.max(...p)+1);for(let E=0;E<m.length;E++)e.state.env.set(`${f}_${y+E}`,de(e,m[E]));let v=y+m.length;e.state.env.set(`${f}__length`,String(v))}De(e,f);continue}let o=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(o){let f=o[1],d=de(e,o[2]),h=ye(e,f);if(h)return h;let m=e.state.env.get(f)??"";e.state.env.set(f,m+d),De(e,f);continue}let u=al(a);if(u.value===void 0&&!u.isArray){De(e,u.name);continue}let c=await ol(e,u,{makeReadonly:!0});if(c)return c}return K}function ti(e){return e.state.directoryStack??=[],e.state.directoryStack}function Es(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function Hf(e){let t=e.split("/").filter(r=>r&&r!=="."),s=[];for(let r of t)r===".."?s.pop():s.push(r);return`/${s.join("/")}`}async function si(e,t){let s=ti(e),r;for(let l=0;l<t.length;l++){let o=t[l];if(o==="--"){if(l+1<t.length){if(r!==void 0)return N(`bash: pushd: too many arguments
186
- `,2);r=t[l+1],l++}}else{if(o.startsWith("-")&&o!=="-")return N(`bash: pushd: ${o}: invalid option
187
- `,2);if(r!==void 0)return N(`bash: pushd: too many arguments
188
- `,2);r=o}}if(r===void 0){if(s.length<2)return N(`bash: pushd: no other directory
189
- `,1);let l=s[0];s[0]=s[1],s[1]=l,r=s[0]}let n;if(r.startsWith("/"))n=r;else if(r===".."){let l=e.state.cwd.split("/").filter(o=>o);l.pop(),n=`/${l.join("/")}`}else r==="."?n=e.state.cwd:r.startsWith("~")?n=(e.state.env.get("HOME")||"/")+r.slice(1):n=`${e.state.cwd}/${r}`;n=Hf(n);try{if(!(await e.fs.stat(n)).isDirectory)return N(`bash: pushd: ${r}: Not a directory
190
- `,1)}catch{return N(`bash: pushd: ${r}: No such file or directory
191
- `,1)}s.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=n,e.state.env.set("PWD",n),e.state.env.set("OLDPWD",e.state.previousDir);let i=e.state.env.get("HOME")||"",a=`${[n,...s].map(l=>Es(l,i)).join(" ")}
192
- `;return H(a)}function ni(e,t){let s=ti(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?N(`bash: popd: ${a}: invalid option
193
- `,2):N(`bash: popd: too many arguments
194
- `,2);if(s.length===0)return N(`bash: popd: directory stack empty
195
- `,1);let r=s.shift();if(!r)return N(`bash: popd: directory stack empty
196
- `,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 n=e.state.env.get("HOME")||"",i=`${[r,...s].map(a=>Es(a,n)).join(" ")}
197
- `;return H(i)}function ri(e,t){let s=ti(e),r=!1,n=!1,i=!1,a=!1;for(let c of t)if(c!=="--")if(c.startsWith("-"))for(let f of c.slice(1))if(f==="c")r=!0;else if(f==="l")n=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,a=!0;else return N(`bash: dirs: -${f}: invalid option
198
- `,2);else return N(`bash: dirs: too many arguments
199
- `,1);if(r)return e.state.directoryStack=[],K;let l=[e.state.cwd,...s],o=e.state.env.get("HOME")||"",u;return a?(u=l.map((c,f)=>{let d=n?c:Es(c,o);return` ${f} ${d}`}).join(`
200
- `),u+=`
201
- `):i?u=l.map(c=>n?c:Es(c,o)).join(`
184
+ `;return Y(_)}let O=!0;for(let _ of g)e.state.functions.has(_)||(O=!1);return I("","",O?0:1)}if(o&&g.length>0)return Ic(e,g);if(o&&g.length===0)return _c(e,{filterExport:a,filterReadonly:i,filterNameref:l,filterIndexedArray:r,filterAssocArray:s});if(g.length===0&&s&&!o)return Tc(e);if(g.length===0&&r&&!o)return Lc(e);if(g.length===0&&!o)return Mc(e);let N="",D=0;for(let O of g){let _=O.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(_&&!u){let C=_[1],$=_[2],k=ce(e,C);if(k)return k;if(s&&Se(e,C).length>0){N+=`bash: declare: ${C}: cannot convert indexed to associative array
185
+ `,D=1;continue}if((r||!s&&!r)&&e.state.associativeArrays?.has(C)){N+=`bash: declare: ${C}: cannot convert associative to indexed array
186
+ `,D=1;continue}let W=s&&$.includes("[")?os($,n):void 0,Q=W===void 0?Nt($,{...n,maxElements:s?n.maxElements*2:n.maxElements}):void 0;if(e.executionScope.consumeWork(W?.length??Q?.length??0,"declare array assignment"),v(C),s?(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(C),Mt(e,C,"associative")):Mt(e,C,"indexed"),ge(e,C),e.state.env.delete(C),s&&$.includes("["))for(let[G,ke]of W??[])q(e,C,G,Ut(e,ke),"associative");else if(s){let G=Q??[];for(let ke=0;ke<G.length;ke+=2){let be=G[ke],dn=ke+1<G.length?G[ke+1]:"";q(e,C,be,dn,"associative")}}else{let G=Q??[];if(G.some(be=>/^\[[^\]]+\]=/.test(be))){let be=0;for(let dn of G){let Rs=dn.match(/^\[([^\]]+)\]=(.*)$/);if(Rs){let Os=Rs[1],zu=Rs[2],_n;if(/^-?\d+$/.test(Os))_n=Number.parseInt(Os,10);else try{let qu=new U,Uu=re(qu,Os);_n=await K(e,Uu.expression)}catch{_n=0}q(e,C,_n,Ut(e,zu)),be=_n+1}else q(e,C,be,dn),be++}}else for(let be=0;be<G.length;be++)q(e,C,be,G[be])}x(C),i&&Ue(e,C),a&&lt(e,C);continue}if(c){let C=O.includes("=")?O.slice(0,O.indexOf("=")):O;if(Xo(e,C),!O.includes("="))continue}if(f){let C=O.includes("=")?O.slice(0,O.indexOf("=")):O;if(Fr(e,C),!O.includes("="))continue}let V=hh(O);if(V){let{name:C,indexExpr:$,value:k}=V,W=ce(e,C);if(W)return W;v(C);let Q;try{let G=new U,ke=re(G,$);Q=await K(e,ke.expression)}catch{let G=parseInt($,10);Q=Number.isNaN(G)?0:G}q(e,C,Q,k),x(C),i&&Ue(e,C),a&&lt(e,C);continue}let J=O.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(J&&!u){let C=J[1],$=J[2],k=ce(e,C);if(k)return k;v(C);let W=Nt($,n);if(e.state.associativeArrays?.has(C)){let Q=os($,n);e.executionScope.consumeWork(Q.length,"declare array append"),nn(e,C,Q.map(([G])=>G));for(let[G,ke]of Q)q(e,C,G,ke,"associative")}else{e.executionScope.consumeWork(W.length,"declare array append");let Q=Se(e,C),G=0,ke=e.state.env.get(C);Q.length===0&&ke!==void 0?(q(e,C,0,ke),e.state.env.delete(C),G=1):Q.length>0&&(G=Math.max(...Q)+1),nn(e,C,Array.from({length:W.length},(be,dn)=>G+dn));for(let be=0;be<W.length;be++)q(e,C,G+be,W[be])}x(C),i&&Ue(e,C),a&&lt(e,C);continue}let ee=O.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(ee){let C=ee[1],$=ee[2],k=ce(e,C);if(k)return k;A(C),d&&Hi(e,C),h&&Qi(e,C),p&&Ki(e,C);let Q=Se(e,C).length>0||e.state.associativeArrays?.has(C);if(rr(e,C)){let G=e.state.env.get(C)??"0",ke=parseInt(G,10)||0,be=parseInt(await Bc(e,$),10)||0;$=String(ke+be),e.state.env.set(C,$)}else if(Q){$=kn(e,C,$);let G=ae(e,C,0)??"";q(e,C,0,It([G,$],"",e.limits.maxStringLength,"declare append"))}else{$=kn(e,C,$);let G=e.state.env.get(C)??"";e.state.env.set(C,It([G,$],"",e.limits.maxStringLength,"declare append"))}x(C),i&&Ue(e,C),a&&lt(e,C),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(C));continue}if(O.includes("=")){let C=O.indexOf("="),$=O.slice(0,C),k=O.slice(C+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test($)){N+=`bash: typeset: \`${$}': not a valid identifier
187
+ `,D=1;continue}let W=ce(e,$);if(W)return W;if(A($),l){if(k!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(k)){N+=`bash: declare: \`${k}': invalid variable name for name reference
188
+ `,D=1;continue}e.state.env.set($,k),kt(e,$),k!==""&&Lr(e,k)&&yi(e,$),x($),i&&Ue(e,$),a&&lt(e,$);continue}if(d&&Hi(e,$),h&&Qi(e,$),p&&Ki(e,$),rr(e,$)&&(k=await Bc(e,k)),k=kn(e,$,k),le(e,$)){let Q=Te(e,$);Q&&Q!==$?e.state.env.set(Q,k):e.state.env.set($,k)}else e.state.env.set($,k);x($),i&&Ue(e,$),a&&lt(e,$),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add($))}else{let C=O;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(C)){N+=`bash: typeset: \`${C}': not a valid identifier
189
+ `,D=1;continue}if(r||s?v(C):A(C),l){kt(e,C);let k=e.state.env.get(C);k!==void 0&&k!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(k)?Yo(e,C):k&&Lr(e,k)&&yi(e,C),x(C),i&&Ue(e,C),a&&lt(e,C);continue}if(d&&Hi(e,C),h&&Qi(e,C),p&&Ki(e,C),s){if(Se(e,C).length>0){N+=`bash: declare: ${C}: cannot convert indexed to associative array
190
+ `,D=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(C),Mt(e,C,"associative")}let $=Ne(e,C);!e.state.env.has(C)&&!$&&(r||s?Mt(e,C,s?"associative":"indexed"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(C))),x(C),i&&Ue(e,C),a&&lt(e,C)}}return I("",N,D)}async function Yi(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,a=[];for(let o=0;o<t.length;o++){let l=t[o];if(l==="-a")r=!0;else if(l==="-A")s=!0;else if(l==="-p")i=!0;else if(l==="--"){a.push(...t.slice(o+1));break}else l.startsWith("-")||a.push(l)}if(a.length===0){let o="",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,'\\"');o+=`declare -r ${c}="${f}"
191
+ `}}return Y(o)}for(let o of a){let l=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(l){let d=l[1],h=l[2],p=ce(e,d);if(p)return p;let m=Nt(h,n);if(e.state.associativeArrays?.has(d)){let E=os(h,n);e.executionScope.consumeWork(E.length,"readonly array append"),nn(e,d,E.map(([b])=>b));for(let[b,g]of E)q(e,d,b,g,"associative")}else{e.executionScope.consumeWork(m.length,"readonly array append");let E=Se(e,d),b=0,g=e.state.env.get(d);E.length===0&&g!==void 0?(q(e,d,0,g),e.state.env.delete(d),b=1):E.length>0&&(b=Math.max(...E)+1),nn(e,d,Array.from({length:m.length},(w,S)=>b+S));for(let w=0;w<m.length;w++)q(e,d,b+w,m[w])}Ue(e,d);continue}let c=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c){let d=c[1],h=c[2],p=ce(e,d);if(p)return p;let m=e.state.env.get(d)??"";e.state.env.set(d,It([m,h],"",e.limits.maxStringLength,"readonly append")),Ue(e,d);continue}let u=Sc(o,n);if(u.value===void 0&&!u.isArray){Ue(e,u.name);continue}let f=await vc(e,u,{makeReadonly:!0});if(f)return f}return ne}function Ji(e){return e.state.directoryStack??=[],e.state.directoryStack}function sr(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function ph(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 ea(e,t){let n=Ji(e),r;for(let o=0;o<t.length;o++){let l=t[o];if(l==="--"){if(o+1<t.length){if(r!==void 0)return R(`bash: pushd: too many arguments
192
+ `,2);r=t[o+1],o++}}else{if(l.startsWith("-")&&l!=="-")return R(`bash: pushd: ${l}: invalid option
193
+ `,2);if(r!==void 0)return R(`bash: pushd: too many arguments
194
+ `,2);r=l}}if(r===void 0){if(n.length<2)return R(`bash: pushd: no other directory
195
+ `,1);let o=n[0];n[0]=n[1],n[1]=o,r=n[0]}let s;if(r.startsWith("/"))s=r;else if(r===".."){let o=e.state.cwd.split("/").filter(l=>l);o.pop(),s=`/${o.join("/")}`}else r==="."?s=e.state.cwd:r.startsWith("~")?s=(e.state.env.get("HOME")||"/")+r.slice(1):s=`${e.state.cwd}/${r}`;s=ph(s);try{if(!(await e.fs.stat(s)).isDirectory)return R(`bash: pushd: ${r}: Not a directory
196
+ `,1)}catch{return R(`bash: pushd: ${r}: No such file or directory
197
+ `,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")||"",a=`${[s,...n].map(o=>sr(o,i)).join(" ")}
198
+ `;return Y(a)}function ta(e,t){let n=Ji(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?R(`bash: popd: ${a}: invalid option
199
+ `,2):R(`bash: popd: too many arguments
200
+ `,2);if(n.length===0)return R(`bash: popd: directory stack empty
201
+ `,1);let r=n.shift();if(!r)return R(`bash: popd: directory stack empty
202
+ `,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(a=>sr(a,s)).join(" ")}
203
+ `;return Y(i)}function na(e,t){let n=Ji(e),r=!1,s=!1,i=!1,a=!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,a=!0;else return R(`bash: dirs: -${f}: invalid option
204
+ `,2);else return R(`bash: dirs: too many arguments
205
+ `,1);if(r)return e.state.directoryStack=[],ne;let o=[e.state.cwd,...n],l=e.state.env.get("HOME")||"",c;return a?(c=o.map((u,f)=>{let d=s?u:sr(u,l);return` ${f} ${d}`}).join(`
206
+ `),c+=`
207
+ `):i?c=o.map(u=>s?u:sr(u,l)).join(`
202
208
  `)+`
203
- `:u=l.map(c=>n?c:Es(c,o)).join(" ")+`
204
- `,H(u)}async function Sn(e,t,s){let r=t;if(r.length>0){let l=r[0];if(l==="--")r=r.slice(1);else if(l.startsWith("-")&&l!=="-"&&l.length>1)return N(`bash: eval: ${l}: invalid option
209
+ `:c=o.map(u=>s?u:sr(u,l)).join(" ")+`
210
+ `,Y(c)}async function ps(e,t,n){let r=t;if(r.length>0){let o=r[0];if(o==="--")r=r.slice(1);else if(o.startsWith("-")&&o!=="-"&&o.length>1)return R(`bash: eval: ${o}: invalid option
205
211
  eval: usage: eval [arg ...]
206
- `,2)}if(r.length===0)return K;let n=r.join(" ");if(n.trim()==="")return K;let i=e.state.groupStdin,a=s??e.state.groupStdin;a!==void 0&&(e.state.groupStdin=a);try{let l=Ce(n);return await e.executeScript(l)}catch(l){if(l instanceof Oe||l instanceof Te||l instanceof ke||l instanceof Z)throw l;if(l.name==="ParseException")return N(`bash: eval: ${l.message}
207
- `);throw l}finally{e.state.groupStdin=i}}function ii(e,t){let s,r="";if(t.length===0)s=e.state.lastExitCode;else{let n=t[0],i=Number.parseInt(n,10);n===""||Number.isNaN(i)||!/^-?\d+$/.test(n)?(r=`bash: exit: ${n}: numeric argument required
208
- `,s=2):s=(i%256+256)%256}throw new Z(s,"",r)}function ai(e,t){let s=!1,r=[];for(let a of t)a==="-n"?s=!0:a==="-p"||a==="--"||r.push(a);if(r.length===0&&!s){let a="",l=e.state.exportedVars??new Set,o=Array.from(l).sort();for(let u of o){let c=e.state.env.get(u);if(c!==void 0){let f=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -x ${u}="${f}"
209
- `}}return H(a)}if(s){for(let a of r){let l,o;if(a.includes("=")){let u=a.indexOf("=");l=a.slice(0,u),o=de(e,a.slice(u+1)),e.state.env.set(l,o)}else l=a;Hs(e,l)}return K}let n="",i=0;for(let a of r){let l,o,u=!1,c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c)l=c[1],o=de(e,c[2]),u=!0;else if(a.includes("=")){let f=a.indexOf("=");l=a.slice(0,f),o=de(e,a.slice(f+1))}else l=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l)){n+=`bash: export: \`${a}': not a valid identifier
210
- `,i=1;continue}if(o!==void 0)if(u){let f=e.state.env.get(l)??"";e.state.env.set(l,f+o)}else e.state.env.set(l,o);else e.state.env.has(l)||e.state.env.set(l,"");Qe(e,l)}return _("",n,i)}function An(e,t){if(t.length<2)return N(`bash: getopts: usage: getopts optstring name [arg ...]
211
- `);let s=t[0],r=t[1],n=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r),i=s.startsWith(":"),a=i?s.slice(1):s,l;if(t.length>2)l=t.slice(2);else{let p=Number.parseInt(e.state.env.get("#")||"0",10);l=[];for(let y=1;y<=p;y++)l.push(e.state.env.get(String(y))||"")}let o=Number.parseInt(e.state.env.get("OPTIND")||"1",10);o<1&&(o=1);let u=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),o>l.length)return n||e.state.env.set(r,"?"),e.state.env.set("OPTIND",String(l.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:n?2:1,stdout:"",stderr:""};let c=l[o-1];if(!c||c==="-"||!c.startsWith("-"))return n||e.state.env.set(r,"?"),{exitCode:n?2:1,stdout:"",stderr:""};if(c==="--")return e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),n||e.state.env.set(r,"?"),{exitCode:n?2:1,stdout:"",stderr:""};let f=u===0?1:u,d=c[f];if(!d)return e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),An(e,t);let h=a.indexOf(d);if(h===-1){let p="";return i?e.state.env.set("OPTARG",d):p=`bash: illegal option -- ${d}
212
- `,n||e.state.env.set(r,"?"),f+1<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(o))):(e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0")),{exitCode:n?2:0,stdout:"",stderr:p}}if(h+1<a.length&&a[h+1]===":")if(f+1<c.length)e.state.env.set("OPTARG",c.slice(f+1)),e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0");else{if(o>=l.length){let p="";return i?(e.state.env.set("OPTARG",d),n||e.state.env.set(r,":")):(p=`bash: option requires an argument -- ${d}
213
- `,n||e.state.env.set(r,"?")),e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:n?2:0,stdout:"",stderr:p}}e.state.env.set("OPTARG",l[o]),e.state.env.set("OPTIND",String(o+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(o))):(e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return n||e.state.env.set(r,d),{exitCode:n?2:0,stdout:"",stderr:""}}async function oi(e,t){e.state.hashTable||(e.state.hashTable=new Map);let s=!1,r=!1,n=!1,i=!1,a=!1,l="",o=[],u=0;for(;u<t.length;){let m=t[u];if(m==="--"){u++,o.push(...t.slice(u));break}if(m==="-r")s=!0,u++;else if(m==="-d")r=!0,u++;else if(m==="-l")n=!0,u++;else if(m==="-t")a=!0,u++;else if(m==="-p"){if(i=!0,u++,u>=t.length)return N(`bash: hash: -p: option requires an argument
214
- `,1);l=t[u],u++}else if(m.startsWith("-")&&m.length>1){for(let p of m.slice(1))if(p==="r")s=!0;else if(p==="d")r=!0;else if(p==="l")n=!0;else if(p==="t")a=!0;else return p==="p"?N(`bash: hash: -p: option requires an argument
215
- `,1):N(`bash: hash: -${p}: invalid option
216
- `,1);u++}else o.push(m),u++}if(s)return e.state.hashTable.clear(),K;if(r){if(o.length===0)return N(`bash: hash: -d: option requires an argument
217
- `,1);let m=!1,p="";for(let y of o)e.state.hashTable.has(y)?e.state.hashTable.delete(y):(p+=`bash: hash: ${y}: not found
218
- `,m=!0);return m?N(p,1):K}if(a){if(o.length===0)return N(`bash: hash: -t: option requires an argument
219
- `,1);let m="",p=!1,y="";for(let b of o){let v=e.state.hashTable.get(b);v?o.length>1?m+=`${b} ${v}
220
- `:m+=`${v}
221
- `:(y+=`bash: hash: ${b}: not found
222
- `,p=!0)}return p?{exitCode:1,stdout:m,stderr:y}:H(m)}if(i){if(o.length===0)return N(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
223
- `,1);let m=o[0];return e.state.hashTable.set(m,l),K}if(o.length===0){if(e.state.hashTable.size===0)return H(`hash: hash table empty
224
- `);let m="";if(n)for(let[p,y]of e.state.hashTable)m+=`builtin hash -p ${y} ${p}
225
- `;else{m=`hits command
226
- `;for(let[,p]of e.state.hashTable)m+=` 1 ${p}
227
- `}return H(m)}let c=!1,f="",h=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let m of o){if(m.includes("/")){f+=`bash: hash: ${m}: cannot use / in name
228
- `,c=!0;continue}let p=!1;for(let y of h){if(!y)continue;let b=`${y}/${m}`;if(await e.fs.exists(b)){e.state.hashTable.set(m,b),p=!0;break}}p||(f+=`bash: hash: ${m}: not found
229
- `,c=!0)}return c?N(f,1):K}var Al=new Map([[":",[": [arguments]",`Null command.
212
+ `,2)}if(r.length===0)return ne;let s=r.join(" ");if(s.trim()==="")return ne;let i=e.state.groupStdin,a=n??e.state.groupStdin;a!==void 0&&(e.state.groupStdin=a);try{let o=qe(s);return await e.executeScript(o)}catch(o){if(o instanceof Ze||o instanceof He||o instanceof Me||o instanceof H)throw o;if(o.name==="ParseException")return R(`bash: eval: ${o.message}
213
+ `);throw o}finally{e.state.groupStdin=i}}function ra(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
214
+ `,n=2;else{let i=BigInt(s);n=Number((i%256n+256n)%256n)}}throw new H(n,"",r)}function sa(e,t){let n=!1,r=[];for(let a of t)a==="-n"?n=!0:a==="-p"||a==="--"||r.push(a);if(r.length===0&&!n){let a="",o=e.state.exportedVars??new Set,l=Array.from(o).sort();for(let c of l){let u=e.state.env.get(c);u!==void 0&&(a+=`declare -x ${c}=${nr(u)}
215
+ `)}return Y(a)}if(n){for(let a of r){let o,l;if(a.includes("=")){let c=a.indexOf("=");o=a.slice(0,c),l=a.slice(c+1)}else o=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o))return I("",`bash: export: \`${a}': not a valid identifier
216
+ `,1);l!==void 0&&(ce(e,o),e.state.env.set(o,l)),Fr(e,o)}return ne}let s="",i=0;for(let a of r){let o,l,c=!1,u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(u)o=u[1],l=u[2],c=!0;else if(a.includes("=")){let f=a.indexOf("=");o=a.slice(0,f),l=a.slice(f+1)}else o=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){s+=`bash: export: \`${a}': not a valid identifier
217
+ `,i=1;continue}if(l!==void 0)if(ce(e,o),c){let f=e.state.env.get(o)??"";e.state.env.set(o,f+l)}else e.state.env.set(o,l);else e.state.env.has(o)||e.state.env.set(o,"");lt(e,o)}return I("",s,i)}function ms(e,t){if(t.length<2)return R(`bash: getopts: usage: getopts optstring name [arg ...]
218
+ `);let n=t[0],r=t[1],s=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r),i=n.startsWith(":"),a=i?n.slice(1):n,o;if(t.length>2)o=t.slice(2);else{let m=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let E=1;E<=m;E++)o.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>o.length)return s||e.state.env.set(r,"?"),e.state.env.set("OPTIND",String(o.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:1,stdout:"",stderr:""};let u=o[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"),ms(e,t);let h=a.indexOf(d);if(h===-1){let m="";return i?e.state.env.set("OPTARG",d):m=`bash: illegal option -- ${d}
219
+ `,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<a.length&&a[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>=o.length){let m="";return i?(e.state.env.set("OPTARG",d),s||e.state.env.set(r,":")):(m=`bash: option requires an argument -- ${d}
220
+ `,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",o[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 ia(e,t){e.state.hashTable||(e.state.hashTable=new Map);let n=!1,r=!1,s=!1,i=!1,a=!1,o="",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")a=!0,c++;else if(p==="-p"){if(i=!0,c++,c>=t.length)return R(`bash: hash: -p: option requires an argument
221
+ `,1);o=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")a=!0;else return m==="p"?R(`bash: hash: -p: option requires an argument
222
+ `,1):R(`bash: hash: -${m}: invalid option
223
+ `,1);c++}else l.push(p),c++}if(n)return e.state.hashTable.clear(),ne;if(r){if(l.length===0)return R(`bash: hash: -d: option requires an argument
224
+ `,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
225
+ `,p=!0);return p?R(m,1):ne}if(a){if(l.length===0)return R(`bash: hash: -t: option requires an argument
226
+ `,1);let p="",m=!1,E="";for(let b of l){let g=e.state.hashTable.get(b);g?l.length>1?p+=`${b} ${g}
227
+ `:p+=`${g}
228
+ `:(E+=`bash: hash: ${b}: not found
229
+ `,m=!0)}return m?{exitCode:1,stdout:p,stderr:E}:Y(p)}if(i){if(l.length===0)return R(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
230
+ `,1);let p=l[0];return e.state.hashTable.set(p,o),ne}if(l.length===0){if(e.state.hashTable.size===0)return Y(`hash: hash table empty
231
+ `);let p="";if(s)for(let[m,E]of e.state.hashTable){let b=m.startsWith("-")?" --":"";p+=`builtin hash -p ${Ee(E)}${b} ${Ee(m)}
232
+ `}else{p=`hits command
233
+ `;for(let[,m]of e.state.hashTable)p+=` 1 ${m}
234
+ `}return Y(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
235
+ `,u=!0;continue}let m=!1;for(let E of h){if(!E)continue;let b=`${E}/${p}`;if(await e.fs.exists(b)){e.state.hashTable.set(p,b),m=!0;break}}m||(f+=`bash: hash: ${p}: not found
236
+ `,u=!0)}return u?R(f,1):ne}var Wc=new Map([[":",[": [arguments]",`Null command.
230
237
  No effect; the command does nothing.
231
238
  Exit Status:
232
239
  Always succeeds.`]],[".",[". filename [arguments]",`Execute commands from a file in the current shell.
@@ -571,32 +578,35 @@ eval: usage: eval [arg ...]
571
578
  job specification, and reports its termination status.
572
579
  Exit Status:
573
580
  Returns the status of the last ID; fails if ID is invalid or an invalid
574
- option is given.`]]]),$l=[...Al.keys()].sort();function li(e,t){let s=!1,r=[],n=0;for(;n<t.length;){let o=t[n];if(o==="--"){for(n++;n<t.length;)r.push(t[n]),n++;break}if(o.startsWith("-")&&o.length>1){for(let u=1;u<o.length;u++){let c=o[u];if(c==="s")s=!0;else return N(`bash: help: -${c}: invalid option
575
- `,2)}n++}else r.push(o),n++}if(r.length===0)return Kf();let i="",a=!1,l="";for(let o of r){let u=Qf(o);if(u.length===0){l+=`bash: help: no help topics match \`${o}'. Try \`help help' or \`man -k ${o}' or \`info ${o}'.
576
- `,a=!0;continue}for(let c of u){let f=Al.get(c);if(!f)continue;let[d,h]=f;s?i+=`${c}: ${d}
577
- `:i+=`${c}: ${d}
581
+ option is given.`]]]),Fc=[...Wc.keys()].sort();function aa(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 R(`bash: help: -${u}: invalid option
582
+ `,2)}s++}else r.push(l),s++}if(r.length===0)return yh();let i="",a=!1,o="";for(let l of r){let c=mh(l);if(c.length===0){o+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
583
+ `,a=!0;continue}for(let u of c){let f=Wc.get(u);if(!f)continue;let[d,h]=f;n?i+=`${u}: ${d}
584
+ `:i+=`${u}: ${d}
578
585
  ${h}
579
- `}}return{exitCode:a?1:0,stdout:i,stderr:l}}function Qf(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),s=le(`^${t}$`);return $l.filter(r=>s.test(r))}function Kf(){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,s=$l.slice(),r=Math.ceil(s.length/2);for(let n=0;n<r;n++){let i=s[n]||"",a=s[n+r]||"",l=i.padEnd(t);e.push(a?`${l}${a}`:i)}return H(`${e.join(`
586
+ `}}return{exitCode:a?1:0,stdout:i,stderr:o}}function mh(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),n=ye(`^${t}$`);return Fc.filter(r=>n.test(r))}function yh(){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=Fc.slice(),r=Math.ceil(n.length/2);for(let s=0;s<r;s++){let i=n[s]||"",a=n[s+r]||"",o=i.padEnd(t);e.push(a?`${o}${a}`:i)}return Y(`${e.join(`
580
587
  `)}
581
- `)}function Xf(e){let t=[],s="",r=0;for(let n of e){for(let i of n)i==="("?r++:i===")"&&r--;s?s+=` ${n}`:s=n,r===0&&(t.push(s),s="")}return s&&t.push(s),t}async function ci(e,t){if(t.length===0)return N(`bash: let: expression expected
582
- `);let s=Xf(t),r=0;for(let n of s)try{let a=Ce(`(( ${n} ))`).statements[0];if(a&&a.pipelines.length>0&&a.pipelines[0].commands.length>0){let l=a.pipelines[0].commands[0];l.type==="ArithmeticCommand"&&(r=await T(e,l.expression.expression))}}catch(i){return N(`bash: let: ${n}: ${i.message}
583
- `)}return _("","",r===0?1:0)}async function ui(e,t){if(e.state.localScopes.length===0)return N(`bash: local: can only be used in a function
584
- `);let s=e.state.localScopes[e.state.localScopes.length-1],r="",n=0,i=!1,a=!1,l=!1,o=[];for(let u of t)if(u==="-n")i=!0;else if(u==="-a")a=!0;else if(u==="-p")l=!0;else if(u.startsWith("-")&&!u.includes("="))for(let c of u.slice(1))c==="n"?i=!0:c==="a"?a=!0:c==="p"&&(l=!0);else o.push(u);if(o.length===0){let u="",c=Array.from(s.keys()).filter(f=>!f.includes("_")||!f.match(/_\d+$/)).filter(f=>!f.includes("__length")).sort();for(let f of c){let d=e.state.env.get(f);d!==void 0&&(u+=`${f}=${d}
585
- `)}return _(u,"",0)}for(let u of o){let c,f,d=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){c=d[1];let b=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){r+=`bash: local: \`${u}': not a valid identifier
586
- `,n=1;continue}if(ye(e,c,"bash"),!s.has(c)){s.set(c,e.state.env.get(c));let w=`${c}_`;for(let S of e.state.env.keys())S.startsWith(w)&&!S.includes("__")&&(s.has(S)||s.set(S,e.state.env.get(S)))}let v=`${c}_`;for(let w of e.state.env.keys())w.startsWith(v)&&!w.includes("__")&&e.state.env.delete(w);let E=ot(b);for(let w=0;w<E.length;w++)e.state.env.set(`${c}_${w}`,E[w]);e.state.env.set(`${c}__length`,String(E.length)),Ct(e,c),i&&pt(e,c);continue}let h=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(h){c=h[1];let b=h[2];if(ye(e,c,"bash"),!s.has(c)){s.set(c,e.state.env.get(c));let $=`${c}_`;for(let C of e.state.env.keys())C.startsWith($)&&!C.includes("__")&&(s.has(C)||s.set(C,e.state.env.get(C)));let R=`${c}__length`;e.state.env.has(R)&&!s.has(R)&&s.set(R,e.state.env.get(R))}let v=ot(b),E=he(e,c),w=0,S=e.state.env.get(c);E.length===0&&S!==void 0?(e.state.env.set(`${c}_0`,S),e.state.env.delete(c),w=1):E.length>0&&(w=Math.max(...E)+1);for(let $=0;$<v.length;$++)e.state.env.set(`${c}_${w+$}`,de(e,v[$]));let A=w+v.length;e.state.env.set(`${c}__length`,String(A)),Ct(e,c),i&&pt(e,c);continue}let m=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(m){c=m[1];let b=de(e,m[2]);ye(e,c,"bash"),s.has(c)||s.set(c,e.state.env.get(c));let v=e.state.env.get(c)??"";e.state.env.set(c,v+b),Ct(e,c),i&&pt(e,c);continue}let p=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(p){c=p[1];let b=p[2],v=de(e,p[3]);if(ye(e,c,"bash"),!s.has(c)){s.set(c,e.state.env.get(c));let S=`${c}_`;for(let $ of e.state.env.keys())$.startsWith(S)&&!$.includes("__")&&(s.has($)||s.set($,e.state.env.get($)));let A=`${c}__length`;e.state.env.has(A)&&!s.has(A)&&s.set(A,e.state.env.get(A))}let E;try{let S=new q,A=Y(S,b);E=await T(e,A.expression)}catch{let S=parseInt(b,10);E=Number.isNaN(S)?0:S}e.state.env.set(`${c}_${E}`,v);let w=parseInt(e.state.env.get(`${c}__length`)??"0",10);E>=w&&e.state.env.set(`${c}__length`,String(E+1)),Ct(e,c),i&&pt(e,c);continue}if(u.includes("=")){let b=u.indexOf("=");c=u.slice(0,b),f=de(e,u.slice(b+1))}else c=u;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){r+=`bash: local: \`${u}': not a valid identifier
587
- `,n=1;continue}let y=s.has(c);if(f!==void 0){let b=e.state.env.get(c);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(c),E=e.state.mutatedTempEnvVars?.has(c);if(!v&&!E)for(let w=e.state.tempEnvBindings.length-1;w>=0;w--){let S=e.state.tempEnvBindings[w];if(S.has(c)){b=S.get(c);break}}}ll(e,c,b)}if(!y){let b=e.state.env.get(c);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let E=e.state.tempEnvBindings[v];if(E.has(c)){b=E.get(c);break}}if(s.set(c,b),a){let v=`${c}_`;for(let w of e.state.env.keys())w.startsWith(v)&&!w.includes("__")&&(s.has(w)||s.set(w,e.state.env.get(w)));let E=`${c}__length`;e.state.env.has(E)&&!s.has(E)&&s.set(E,e.state.env.get(E))}}if(a&&f===void 0){let b=`${c}_`;for(let v of e.state.env.keys())v.startsWith(b)&&!v.includes("__")&&e.state.env.delete(v);e.state.env.set(`${c}__length`,"0")}else if(f!==void 0){if(ye(e,c,"bash"),i&&f!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(f)){r+=`bash: local: \`${f}': invalid variable name for name reference
588
- `,n=1;continue}e.state.env.set(c,f),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(c))}else{let b=e.state.tempEnvBindings?.some(v=>v.has(c));!y&&!b&&e.state.env.delete(c)}Ct(e,c),i&&pt(e,c)}return _("",r,n)}function fi(e,t,s){let r=`
589
- `,n=0,i=0,a=0,l=!1,o="MAPFILE",u=0;for(;u<t.length;){let v=t[u];v==="-d"&&u+1<t.length?(r=t[u+1]===""?"\0":t[u+1]||`
590
- `,u+=2):v==="-n"&&u+1<t.length?(n=Number.parseInt(t[u+1],10)||0,u+=2):v==="-O"&&u+1<t.length?(i=Number.parseInt(t[u+1],10)||0,u+=2):v==="-s"&&u+1<t.length?(a=Number.parseInt(t[u+1],10)||0,u+=2):v==="-t"?(l=!0,u++):v==="-u"||v==="-C"||v==="-c"?u+=2:(v.startsWith("-")||(o=v),u++)}let c=s;!c&&e.state.groupStdin!==void 0&&(c=e.state.groupStdin);let f=[],d=c,h=0,m=0,p=e.limits?.maxArrayElements??1e5;for(;d.length>0;){let v=d.indexOf(r);if(v===-1){if(d.length>0){if(m<a)m++;else if(n===0||h<n){if(i+h>=p)return _("",`mapfile: array element limit exceeded (${p})
591
- `,1);let S=d,A=S.indexOf("\0");A!==-1&&(S=S.substring(0,A)),f.push(S),h++}}break}let E=d.substring(0,v),w=E.indexOf("\0");if(w!==-1&&(E=E.substring(0,w)),!l&&r!=="\0"&&(E+=r),d=d.substring(v+r.length),m<a){m++;continue}if(n>0&&h>=n)break;if(i+h>=p)return _("",`mapfile: array element limit exceeded (${p})
592
- `,1);f.push(E),h++}i===0&&tt(e,o);for(let v=0;v<f.length;v++)e.state.env.set(`${o}_${i+v}`,f[v]);let y=parseInt(e.state.env.get(`${o}__length`)||"0",10),b=i+f.length;return e.state.env.set(`${o}__length`,String(Math.max(y,b))),e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=""),_("","",0)}function Yf(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let r=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(r)||r<0)return null;let n=s+1,i=t.slice(n,n+r),a=n+r+1,l=t.slice(a),o=l.indexOf(":");if(o===-1)return null;let u=Number.parseInt(l.slice(0,o),10);if(Number.isNaN(u)||u<0)return null;let c=l.slice(o+1);return{path:i,position:u,content:c}}function Jf(e,t,s){return`__rw__:${e.length}:${e}:${t}:${s}`}function di(e,t,s,r=-1){let n=!1,i=`
593
- `,a="",l=-1,o=-1,u=null,c=-1,f=-1,d=[],h=0,m=!1,p=(k,x)=>{let D=1;for(;D<k.length;){let P=k[D];if(P==="r")n=!0,D++;else if(P==="s")D++;else{if(P==="d")return D+1<k.length?(i=k.substring(D+1),{nextArgIndex:x+1}):x+1<t.length?(i=t[x+1],{nextArgIndex:x+2}):{nextArgIndex:x+1};if(P==="n"){if(D+1<k.length){let O=k.substring(D+1);return l=Number.parseInt(O,10),(Number.isNaN(l)||l<0)&&(m=!0,l=0),{nextArgIndex:x+1}}else if(x+1<t.length)return l=Number.parseInt(t[x+1],10),(Number.isNaN(l)||l<0)&&(m=!0,l=0),{nextArgIndex:x+2};return{nextArgIndex:x+1}}else if(P==="N"){if(D+1<k.length){let O=k.substring(D+1);return o=Number.parseInt(O,10),(Number.isNaN(o)||o<0)&&(m=!0,o=0),{nextArgIndex:x+1}}else if(x+1<t.length)return o=Number.parseInt(t[x+1],10),(Number.isNaN(o)||o<0)&&(m=!0,o=0),{nextArgIndex:x+2};return{nextArgIndex:x+1}}else{if(P==="a")return D+1<k.length?(u=k.substring(D+1),{nextArgIndex:x+1}):x+1<t.length?(u=t[x+1],{nextArgIndex:x+2}):{nextArgIndex:x+1};if(P==="p")return D+1<k.length?(a=k.substring(D+1),{nextArgIndex:x+1}):x+1<t.length?(a=t[x+1],{nextArgIndex:x+2}):{nextArgIndex:x+1};if(P==="u"){if(D+1<k.length){let O=k.substring(D+1);return c=Number.parseInt(O,10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:x+1}}else if(x+1<t.length)return c=Number.parseInt(t[x+1],10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:x+2};return{nextArgIndex:x+1}}else if(P==="t"){if(D+1<k.length){let O=k.substring(D+1);return f=Number.parseFloat(O),Number.isNaN(f)&&(f=0),{nextArgIndex:x+1}}else if(x+1<t.length)return f=Number.parseFloat(t[x+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:x+2};return{nextArgIndex:x+1}}else if(P==="e"||P==="i"||P==="P"){if(P==="i"&&x+1<t.length)return{nextArgIndex:x+2};D++}else D++}}}return{nextArgIndex:x+1}};for(;h<t.length;){let k=t[h];if(k.startsWith("-")&&k.length>1&&k!=="--"){let x=p(k,h);if(x.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(x.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=x.nextArgIndex}else if(k==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push(k),h++}if(m)return _("","",1);if(d.length===0&&u===null&&d.push("REPLY"),f===0){if(u)tt(e,u);else{for(let k of d)e.state.env.set(k,"");d.length===0&&e.state.env.set("REPLY","")}return _("","",0)}if(f<0&&f!==-1)return _("","",1);let y=s;c>=0?e.state.fileDescriptors?y=e.state.fileDescriptors.get(c)||"":y="":!y&&e.state.groupStdin!==void 0&&(y=e.state.groupStdin);let b=i===""?"\0":i,v="",E=0,w=!0,S=k=>{if(c>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(c,y.substring(k));else if(r>=0&&e.state.fileDescriptors){let x=e.state.fileDescriptors.get(r);if(x?.startsWith("__rw__:")){let D=Yf(x);if(D){let P=D.position+k;e.state.fileDescriptors.set(r,Jf(D.path,P,D.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=y.substring(k))};if(o>=0){let k=Math.min(o,y.length);v=y.substring(0,k),E=k,w=k>=o,S(E);let x=d[0]||"REPLY";e.state.env.set(x,v);for(let D=1;D<d.length;D++)e.state.env.set(d[D],"");return _("","",w?0:1)}else if(l>=0){let k=0,x=0,D=!1;for(;x<y.length&&k<l;){let P=y[x];if(P===b){E=x+1,D=!0;break}if(!n&&P==="\\"&&x+1<y.length){let O=y[x+1];if(O===b&&b===`
594
- `){x+=2,E=x;continue}if(O===b){x+=2,k++,v+=O,E=x;continue}v+=O,x+=2,k++,E=x}else v+=P,x++,k++,E=x}w=k>=l||D,S(E)}else{E=0;let k=0;for(;k<y.length;){let x=y[k];if(x===b){E=k+b.length,w=!0;break}if(!n&&x==="\\"&&k+1<y.length){let D=y[k+1];if(D===`
595
- `){k+=2;continue}if(D===b){v+=D,k+=2;continue}v+=x,v+=D,k+=2;continue}v+=x,k++}if(k>=y.length&&(w=!1,E=k,v.length===0&&y.length===0)){for(let x of d)e.state.env.set(x,"");return u&&tt(e,u),_("","",1)}S(E)}b===`
596
- `&&v.endsWith(`
597
- `)&&(v=v.slice(0,-1));let A=k=>n?k:k.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",A(v)),_("","",w?0:1);let $=me(e.state.env);if(u){let{words:k}=Sr(v,$,void 0,n),x=e.limits?.maxArrayElements??1e5;if(k.length>x)return _("",`read: array element limit exceeded (${x})
598
- `,1);tt(e,u);for(let D=0;D<k.length;D++)e.state.env.set(`${u}_${D}`,A(k[D]));return _("","",w?0:1)}let R=d.length,{words:C,wordStarts:F}=Sr(v,$,R,n);for(let k=0;k<d.length;k++){let x=d[k];if(k<d.length-1)e.state.env.set(x,A(C[k]??""));else if(k<F.length){let D=v.substring(F[k]);D=La(D,$,n),D=A(D),e.state.env.set(x,D)}else e.state.env.set(x,"")}return _("","",w?0:1)}function hi(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return N("bash: return: can only `return' from a function or sourced script\n");let s=e.state.lastExitCode;if(t.length>0){let r=t[0],n=Number.parseInt(r,10);if(r===""||Number.isNaN(n)||!/^-?\d+$/.test(r))return N(`bash: return: ${r}: numeric argument required
599
- `,2);s=(n%256+256)%256}throw new ke(s)}var bs=`set: usage: set [-eux] [+eux] [-o option] [+o option]
588
+ `)}function gh(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 oa(e,t){if(t.length===0)return R(`bash: let: expression expected
589
+ `);let n=gh(t),r=0;for(let s of n)try{let a=qe(`(( ${s} ))`).statements[0];if(a&&a.pipelines.length>0&&a.pipelines[0].commands.length>0){let o=a.pipelines[0].commands[0];o.type==="ArithmeticCommand"&&(r=await K(e,o.expression.expression))}}catch(i){return R(`bash: let: ${s}: ${i.message}
590
+ `)}return I("","",r===0?1:0)}async function la(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength};if(e.state.localScopes.length===0)return R(`bash: local: can only be used in a function
591
+ `);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=Ae(e,d);s.set(d,h?_e(h):void 0)}},a="",o=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}
592
+ `)}return I(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)){a+=`bash: local: \`${d}': not a valid identifier
593
+ `,o=1;continue}ce(e,h,"bash");let A=Nt(S,n);e.executionScope.consumeWork(A.length,"local array assignment"),i(h),ge(e,h),Mt(e,h,"indexed");for(let v=0;v<A.length;v++)q(e,h,v,A[v]);Ht(e,h),l&&kt(e,h);continue}let E=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(E){h=E[1];let S=E[2];ce(e,h,"bash"),i(h);let A=Nt(S,n);e.executionScope.consumeWork(A.length,"local array append");let v=Se(e,h),x=0,N=e.state.env.get(h);v.length===0&&N!==void 0?(q(e,h,0,N),e.state.env.delete(h),x=1):v.length>0&&(x=Math.max(...v)+1),nn(e,h,Array.from({length:A.length},(D,O)=>x+O));for(let D=0;D<A.length;D++)q(e,h,x+D,A[D]);Ht(e,h),l&&kt(e,h);continue}let b=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(b){h=b[1];let S=b[2];ce(e,h,"bash"),r.has(h)||r.set(h,e.state.env.get(h));let A=e.state.env.get(h)??"";e.state.env.set(h,It([A,S],"",e.limits.maxStringLength,"local append")),Ht(e,h),l&&kt(e,h);continue}let g=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(g){h=g[1];let S=g[2],A=g[3];ce(e,h,"bash"),i(h);let v;try{let x=new U,N=re(x,S);v=await K(e,N.expression)}catch{let x=parseInt(S,10);v=Number.isNaN(x)?0:x}q(e,h,v,A),Ht(e,h),l&&kt(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)){a+=`bash: local: \`${d}': not a valid identifier
594
+ `,o=1;continue}let w=r.has(h);if(p!==void 0){let S=e.state.env.get(h);if(e.state.tempEnvBindings){let A=e.state.accessedTempEnvVars?.has(h),v=e.state.mutatedTempEnvVars?.has(h);if(!A&&!v)for(let x=e.state.tempEnvBindings.length-1;x>=0;x--){let N=e.state.tempEnvBindings[x];if(N.has(h)){S=N.get(h);break}}}Ac(e,h,S)}if(!w){let S=e.state.env.get(h);if(e.state.tempEnvBindings)for(let A=e.state.tempEnvBindings.length-1;A>=0;A--){let v=e.state.tempEnvBindings[A];if(v.has(h)){S=v.get(h);break}}r.set(h,S),c&&i(h)}if(c&&p===void 0)ge(e,h),Mt(e,h,"indexed");else if(p!==void 0){if(ce(e,h,"bash"),l&&p!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(p)){a+=`bash: local: \`${p}': invalid variable name for name reference
595
+ `,o=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(A=>A.has(h));!w&&!S&&e.state.env.delete(h)}Ht(e,h),l&&kt(e,h)}return I("",a,o)}function ca(e,t,n){let r=`
596
+ `,s=0,i=0,a=0,o=!1,l="MAPFILE",c=0;for(;c<t.length;){let g=t[c];g==="-d"&&c+1<t.length?(r=t[c+1]===""?"\0":t[c+1]||`
597
+ `,c+=2):g==="-n"&&c+1<t.length?(s=Number.parseInt(t[c+1],10)||0,c+=2):g==="-O"&&c+1<t.length?(i=Number.parseInt(t[c+1],10)||0,c+=2):g==="-s"&&c+1<t.length?(a=Number.parseInt(t[c+1],10)||0,c+=2):g==="-t"?(o=!0,c++):g==="-u"||g==="-C"||g==="-c"?c+=2:(g.startsWith("-")||(l=g),c++)}if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l))return I("",`mapfile: ${l}: not a valid identifier
598
+ `,1);if(!Number.isSafeInteger(i)||i<0)return I("",`mapfile: invalid array origin
599
+ `,1);ce(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=g=>{if(M(g)>e.limits.maxStringLength)throw new P(`mapfile: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");f.push(g)};for(;d<u.length;){e.executionScope.consumeWork(1,"mapfile input");let g=u.indexOf(r,d);if(g===-1){if(d<u.length){if(p<a)p++;else if(s===0||h<s){let A=u.slice(d),v=A.indexOf("\0");if(v!==-1&&(A=A.substring(0,v)),f.length>=m)return I("",`mapfile: array element limit exceeded (${m})
600
+ `,1);E(A),h++}}break}let w=u.slice(d,g),S=w.indexOf("\0");if(S!==-1&&(w=w.substring(0,S)),!o&&r!=="\0"&&(w+=r),d=g+r.length,p<a){p++;continue}if(s>0&&h>=s)break;if(f.length>=m)return I("",`mapfile: array element limit exceeded (${m})
601
+ `,1);E(w),h++}let b=new Set(i===0?[]:e.state.arrays?.get(l)?.elements.keys()??[]);for(let g=0;g<f.length;g++)if(b.add(String(i+g)),b.size>m)return I("",`mapfile: array element limit exceeded (${m})
602
+ `,1);i===0&&ge(e,l);for(let g=0;g<f.length;g++)q(e,l,i+g,f[g]);return e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=""),I("","",0)}function wh(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),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),a=s+r+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let c=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let u=o.slice(l+1);return{path:i,position:c,content:u}}function Eh(e,t,n){return`__rw__:${e.length}:${e}:${t}:${n}`}function ua(e,t,n,r=-1){let s=!1,i=`
603
+ `,a="",o=-1,l=-1,c=null,u=-1,f=-1,d=[],h=0,p=!1,m=($,k)=>{let W=1;for(;W<$.length;){let Q=$[W];if(Q==="r")s=!0,W++;else if(Q==="s")W++;else{if(Q==="d")return W+1<$.length?(i=$.substring(W+1),{nextArgIndex:k+1}):k+1<t.length?(i=t[k+1],{nextArgIndex:k+2}):{nextArgIndex:k+1};if(Q==="n"){if(W+1<$.length){let G=$.substring(W+1);return o=Number.parseInt(G,10),(Number.isNaN(o)||o<0)&&(p=!0,o=0),{nextArgIndex:k+1}}else if(k+1<t.length)return o=Number.parseInt(t[k+1],10),(Number.isNaN(o)||o<0)&&(p=!0,o=0),{nextArgIndex:k+2};return{nextArgIndex:k+1}}else if(Q==="N"){if(W+1<$.length){let G=$.substring(W+1);return l=Number.parseInt(G,10),(Number.isNaN(l)||l<0)&&(p=!0,l=0),{nextArgIndex:k+1}}else if(k+1<t.length)return l=Number.parseInt(t[k+1],10),(Number.isNaN(l)||l<0)&&(p=!0,l=0),{nextArgIndex:k+2};return{nextArgIndex:k+1}}else{if(Q==="a")return W+1<$.length?(c=$.substring(W+1),{nextArgIndex:k+1}):k+1<t.length?(c=t[k+1],{nextArgIndex:k+2}):{nextArgIndex:k+1};if(Q==="p")return W+1<$.length?(a=$.substring(W+1),{nextArgIndex:k+1}):k+1<t.length?(a=t[k+1],{nextArgIndex:k+2}):{nextArgIndex:k+1};if(Q==="u"){if(W+1<$.length){let G=$.substring(W+1);return u=Number.parseInt(G,10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:k+1}}else if(k+1<t.length)return u=Number.parseInt(t[k+1],10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:k+2};return{nextArgIndex:k+1}}else if(Q==="t"){if(W+1<$.length){let G=$.substring(W+1);return f=Number.parseFloat(G),Number.isNaN(f)&&(f=0),{nextArgIndex:k+1}}else if(k+1<t.length)return f=Number.parseFloat(t[k+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:k+2};return{nextArgIndex:k+1}}else if(Q==="e"||Q==="i"||Q==="P"){if(Q==="i"&&k+1<t.length)return{nextArgIndex:k+2};W++}else W++}}}return{nextArgIndex:k+1}};for(;h<t.length;){let $=t[h];if($.startsWith("-")&&$.length>1&&$!=="--"){let k=m($,h);if(k.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(k.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=k.nextArgIndex}else if($==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push($),h++}if(p)return I("","",1);d.length===0&&c===null&&d.push("REPLY");let E=new Set;c&&E.add(c);for(let $ of d)E.add($);l>=0&&d.length===0&&E.add("REPLY");for(let $ of E){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test($))return I("",`bash: read: \`${$}': not a valid identifier
604
+ `,1);ce(e,$,"bash")}if(f===0){if(c)ge(e,c);else{for(let $ of d)e.state.env.set($,"");d.length===0&&e.state.env.set("REPLY","")}return I("","",0)}if(f<0&&f!==-1)return I("","",1);let b=n;u>=0?e.state.fileDescriptors?b=e.state.fileDescriptors.get(u)||"":b="":!b&&e.state.groupStdin!==void 0&&(b=e.state.groupStdin);let g=i===""?"\0":i,w="",S=0,A=$=>{let k=M($);if(k>e.limits.maxStringLength-S)throw new P(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");w+=$,S+=k},v=$=>{if(M($)>e.limits.maxStringLength)throw new P(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")},x=0,N=!0,D=$=>{if(u>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(u,b.substring($));else if(r>=0&&e.state.fileDescriptors){let k=e.state.fileDescriptors.get(r);if(k?.startsWith("__rw__:")){let W=wh(k);if(W){let Q=W.position+$;e.state.fileDescriptors.set(r,Eh(W.path,Q,W.content))}}}else e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=b.substring($))};if(l>=0){let $=Math.min(l,b.length);w=b.substring(0,$),v(w),x=$,N=$>=l,D(x);let k=d[0]||"REPLY";e.state.env.set(k,w);for(let W=1;W<d.length;W++)e.state.env.set(d[W],"");return I("","",N?0:1)}else if(o>=0){let $=0,k=0,W=!1;for(;k<b.length&&$<o;){let Q=b[k];if(Q===g){x=k+1,W=!0;break}if(!s&&Q==="\\"&&k+1<b.length){let G=b[k+1];if(G===g&&g===`
605
+ `){k+=2,x=k;continue}if(G===g){k+=2,$++,A(G),x=k;continue}A(G),k+=2,$++,x=k}else A(Q),k++,$++,x=k}N=$>=o||W,D(x)}else{x=0;let $=0;for(;$<b.length;){let k=b[$];if(k===g){x=$+g.length,N=!0;break}if(!s&&k==="\\"&&$+1<b.length){let W=b[$+1];if(W===`
606
+ `){$+=2;continue}if(W===g){A(W),$+=2;continue}A(k),A(W),$+=2;continue}A(k),$++}if($>=b.length&&(N=!1,x=$,w.length===0&&b.length===0)){for(let k of d)e.state.env.set(k,"");return c&&ge(e,c),I("","",1)}D(x)}g===`
607
+ `&&w.endsWith(`
608
+ `)&&(w=w.slice(0,-1));let O=$=>s?$:$.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",O(w)),I("","",N?0:1);let _=ve(e.state.env),V=e.limits.maxArrayElements;if(c){let{words:$}=mi(w,_,V,void 0,s);ge(e,c);for(let k=0;k<$.length;k++)q(e,c,k,O($[k]));return I("","",N?0:1)}let J=d.length,{words:ee,wordStarts:C}=mi(w,_,V,J,s);for(let $=0;$<d.length;$++){let k=d[$];if($<d.length-1)e.state.env.set(k,O(ee[$]??""));else if($<C.length){let W=w.substring(C[$]);W=Ko(W,_,s),W=O(W),e.state.env.set(k,W)}else e.state.env.set(k,"")}return I("","",N?0:1)}function fa(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return R("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 R(`bash: return: ${r}: numeric argument required
609
+ `,2);n=(s%256+256)%256}throw new Me(n)}var ir=`set: usage: set [-eux] [+eux] [-o option] [+o option]
600
610
  Options:
601
611
  -e Exit immediately if a command exits with non-zero status
602
612
  +e Disable -e
@@ -612,174 +622,185 @@ Options:
612
622
  +o pipefail Disable pipefail
613
623
  -o xtrace Same as -x
614
624
  +o xtrace Disable xtrace
615
- `,Pl=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]]),$n=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]]),_l=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],xl=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function pi(e,t,s){t!==null&&(s&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=s,jt(e))}function ed(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function td(e,t){let s=he(e,t);if(s.length===0)return`${t}=()`;let r=s.map(n=>{let i=e.state.env.get(`${t}_${n}`)??"";return`[${n}]=${Lt(i)}`});return`${t}=(${r.join(" ")})`}function sd(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function nd(e,t){let s=Ge(e,t);if(s.length===0)return`${t}=()`;let r=s.map(n=>{let i=e.state.env.get(`${t}_${n}`)??"";return`[${sd(n)}]=${Lt(i)}`});return`${t}=(${r.join(" ")} )`}function rd(e){let t=new Set,s=e.state.associativeArrays??new Set;for(let r of e.state.env.keys()){let n=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(n){let i=n[1];s.has(i)||t.add(i)}}return t}function id(e){return e.state.associativeArrays??new Set}function kl(e){let t=_l.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),s=xl.map(r=>`${r.padEnd(16)}off`);return`${[...t,...s].sort().join(`
625
+ `,Vc=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]]),ys=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]]),Uc=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],jc=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function da(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 bh(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Sh(e,t,n){let r=Se(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],a=ae(e,n,i)??"";s>0&&t.append(" "),t.append(`[${i}]=`),t.reserve(hs(a)),t.append(Qt(a))}t.append(")")}function vh(e,t){if(/^[a-zA-Z0-9_]+$/.test(t)){e.append(t);return}e.reserve(hs(t)),e.append(Qt(t))}function Ah(e,t,n){let r=mt(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],a=ae(e,n,i)??"";s>0&&t.append(" "),t.append("["),vh(t,i),t.append("]="),t.reserve(hs(a)),t.append(Qt(a))}t.append(" )")}function xh(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 Ph(e){return e.state.associativeArrays??new Set}function zc(e){let t=Uc.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),n=jc.map(r=>`${r.padEnd(16)}off`);return`${[...t,...n].sort().join(`
616
626
  `)}
617
- `}function Nl(e){let t=_l.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),s=xl.map(r=>`set +o ${r}`);return`${[...t,...s].sort().join(`
627
+ `}function qc(e){let t=Uc.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),n=jc.map(r=>`set +o ${r}`);return`${[...t,...n].sort().join(`
618
628
  `)}
619
- `}function gi(e,t){if(t.includes("--help"))return H(bs);if(t.length===0){let i=rd(e),a=id(e),l=c=>{for(let f of a){let d=`${f}_`,h=`${f}__length`;if(c!==h&&c.startsWith(d)){if(c.slice(d.length).startsWith("_length"))continue;return!0}}return!1},o=[];for(let[c,f]of e.state.env){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)||i.has(c)||a.has(c))continue;let d=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(d&&i.has(d[1]))continue;let h=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);h&&i.has(h[1])||l(c)||h&&a.has(h[1])||o.push([c,f])}let u=[];for(let[c,f]of o.sort(([d],[h])=>d<h?-1:d>h?1:0))u.push(`${c}=${vn(f)}`);for(let c of[...i].sort((f,d)=>f<d?-1:f>d?1:0))u.push(td(e,c));for(let c of[...a].sort((f,d)=>f<d?-1:f>d?1:0))u.push(nd(e,c));return u.sort((c,f)=>{let d=c.split("=")[0],h=f.split("=")[0];return d<h?-1:d>h?1:0}),H(u.length>0?`${u.join(`
629
+ `}function pa(e,t){if(t.includes("--help"))return Y(ir);if(t.length===0){let i=xh(e),a=Ph(e),o=[];for(let[u,f]of e.state.env)/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)&&(i.has(u)||a.has(u)||o.push([u,f]));let l=[...o.map(([u,f])=>({kind:"scalar",name:u,value:f})),...Array.from(i,u=>({kind:"indexed",name:u})),...Array.from(a,u=>({kind:"associative",name:u}))];l.sort((u,f)=>u.name<f.name?-1:u.name>f.name?1:0);let c=new hn(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(Cc(u.value)),c.append(Ee(u.value))):u.kind==="indexed"?Sh(e,c,u.name):Ah(e,c,u.name),c.append(`
630
+ `);return Y(c.build())}let n=[],r=()=>n.length>0?Y(n.join("")):ne,s=0;for(;s<t.length;){let i=t[s];if((i==="-o"||i==="+o")&&bh(t,s)){let a=t[s+1];if(!ys.has(a)){let o=`bash: set: ${a}: invalid option name
631
+ ${ir}`;if(e.state.options.posix)throw new tt(1,"",o);return R(o)}da(e,ys.get(a)??null,i==="-o"),s+=2;continue}if(i==="-o"){n.push(zc(e)),s++;continue}if(i==="+o"){n.push(qc(e)),s++;continue}if(i.length>1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let a=i[0]==="-",o=0;for(let l=1;l<i.length;l++){let c=i[l];if(c==="o"){let u=s+1+o;if(u<t.length&&!t[u].startsWith("-")&&!t[u].startsWith("+")){let d=t[u];if(!ys.has(d)){let h=`bash: set: ${d}: invalid option name
632
+ ${ir}`;if(e.state.options.posix)throw new tt(1,"",h);return R(h)}da(e,ys.get(d)??null,a),o++;continue}n.push(a?zc(e):qc(e));continue}if(!Vc.has(c)){let u=`bash: set: ${i[0]}${c}: invalid option
633
+ ${ir}`;if(e.state.options.posix)throw new tt(1,"",u);return R(u)}da(e,Vc.get(c)??null,a)}s+=1+o;continue}if(i==="--")return ha(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 ha(e,t.slice(s+1)),r();s++;continue}if(i==="+"){s++;continue}if(i.startsWith("-")||i.startsWith("+")){let a=`bash: set: ${i}: invalid option
634
+ ${ir}`;if(e.state.options.posix)throw new tt(1,"",a);return R(a)}return ha(e,t.slice(s)),r()}return r()}function ha(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 ma(e,t){let n=1;if(t.length>0){let a=Number.parseInt(t[0],10);if(Number.isNaN(a)||a<0){let o=`bash: shift: ${t[0]}: numeric argument required
635
+ `;if(e.state.options.posix)throw new tt(1,"",o);return R(o)}n=a}let r=Number.parseInt(e.state.env.get("#")||"0",10);if(n>r){let a=`bash: shift: shift count out of range
636
+ `;if(e.state.options.posix)throw new tt(1,"",a);return R(a)}if(n===0)return ne;let s=[];for(let a=1;a<=r;a++)s.push(e.state.env.get(String(a))||"");let i=s.slice(n);for(let a=1;a<=r;a++)e.state.env.delete(String(a));for(let a=0;a<i.length;a++)e.state.env.set(String(a+1),i[a]);return e.state.env.set("#",String(i.length)),e.state.env.set("@",i.join(" ")),ne}async function ya(e,t){let n=t;if(n.length>0&&n[0]==="--"&&(n=n.slice(1)),n.length===0)return I("",`bash: source: filename argument required
637
+ `,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 R(`bash: ${r}: No such file or directory
638
+ `);let a=new Map;if(n.length>1){for(let u=1;u<=9;u++)a.set(String(u),e.state.env.get(String(u)));a.set("#",e.state.env.get("#")),a.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 o=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=o,n.length>1)for(let[c,u]of a)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 P(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let c=qe(i),u=await e.executeScript(c);return l(),u}catch(c){if(l(),c instanceof H)throw c;if(c instanceof Me)return I(c.stdout,c.stderr,c.exitCode);if(c.name==="ParseException")return R(`bash: ${r}: ${c.message}
639
+ `);throw c}}function Gc(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function $h(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function Zc(e,t){if($h(t))return null;try{let n=new U,r=re(n,t);return await K(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}function Hc(e,t){if(e.state.localVarStack?.has(t)){let r=cs(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)ls(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),ga(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),ls(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 a=!1;for(let o=r-1;o>=0;o--)if(e.state.localScopes[o].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,o+1),a=!0;break}return a||ls(e,t),!0}}return!1}function ga(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 Qc(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 U().parseWordFromString(n,!0,!1);return z(e,s)}if(t.includes("$")){let r=new U().parseWordFromString(t,!1,!1);return z(e,r)}return t}async function wa(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(Le(e,d)){r+=`bash: unset: ${d}: cannot unset: readonly variable
640
+ `,s=1;continue}if(h==="@"||h==="*"){zn(e,d),e.state.env.delete(d);continue}let p=e.state.associativeArrays?.has(d);if(p){let w=await Qc(e,h);rn(e,d,w);continue}let m=at(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
641
+ `,s=1;continue}let g=await Zc(e,h);if(g===null&&m){r+=`bash: unset: ${h}: not a valid identifier
642
+ `,s=1;continue}if(g===null)continue;if(g<0){let w=j(e,d),S=w.length,A=e.state.currentLine;if(S===0){r+=`bash: line ${A}: unset: [${g}]: bad array subscript
643
+ `,s=1;continue}let v=S+g;if(v<0){r+=`bash: line ${A}: unset: [${g}]: bad array subscript
644
+ `,s=1;continue}let x=w[v][0];rn(e,d,x);continue}rn(e,d,g);continue}if(!Gc(i)){r+=`bash: unset: \`${i}': not a valid identifier
645
+ `,s=1;continue}let u=i;if(le(e,i)){let d=Te(e,i);d&&d!==i&&(u=d)}if(Le(e,u)){r+=`bash: unset: ${u}: cannot unset: readonly variable
646
+ `,s=1;continue}zn(e,u);let f=Ii(e,u);if(f!==void 0&&f!==e.state.callDepth)Hc(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=cs(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 ga(e,u)||e.state.env.delete(u);e.state.exportedVars?.delete(u);continue}let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let c=a[1],u=a[2];if(Le(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable
647
+ `,s=1;continue}if(u==="@"||u==="*"){zn(e,c),e.state.env.delete(c);continue}let f=e.state.associativeArrays?.has(c);if(f){let m=await Qc(e,u);rn(e,c,m);continue}let d=at(e,c);if(e.state.env.has(c)&&!d&&!f){r+=`bash: unset: ${c}: not an array variable
648
+ `,s=1;continue}let p=await Zc(e,u);if(p===null&&d){r+=`bash: unset: ${u}: not a valid identifier
649
+ `,s=1;continue}if(p===null)continue;if(p<0){let m=j(e,c),E=m.length,b=e.state.currentLine;if(E===0){r+=`bash: line ${b}: unset: [${p}]: bad array subscript
650
+ `,s=1;continue}let g=E+p;if(g<0){r+=`bash: line ${b}: unset: [${p}]: bad array subscript
651
+ `,s=1;continue}let w=m[g][0];rn(e,c,w);continue}rn(e,c,p);continue}if(!Gc(i)){r+=`bash: unset: \`${i}': not a valid identifier
652
+ `,s=1;continue}let o=i;if(le(e,i)){let c=Te(e,i);c&&c!==i&&(o=c)}if(Le(e,o)){r+=`bash: unset: ${o}: cannot unset: readonly variable
653
+ `,s=1;continue}zn(e,o);let l=Ii(e,o);if(l!==void 0&&l!==e.state.callDepth)Hc(e,o);else if(e.state.fullyUnsetLocals?.has(o))e.state.env.delete(o);else if(l!==void 0){let c=e.state.accessedTempEnvVars?.has(o),u=e.state.mutatedTempEnvVars?.has(o);if((c||u)&&e.state.localVarStack?.has(o)){let f=cs(e,o);f?f.value===void 0?e.state.env.delete(o):e.state.env.set(o,f.value):e.state.env.delete(o)}else e.state.env.delete(o)}else ga(e,o)||e.state.env.delete(o);e.state.exportedVars?.delete(o),e.state.functions.delete(i)}return I("",r,s)}function bt(e,t,n,r){let s=n+M(t)+1;if(s>r)throw new P(`shopt: output size limit exceeded (${r} bytes)`,"output_size");return e.push(t),s}var Ea=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],kh=["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 gs(e){return Ea.includes(e)}function Nh(e){return kh.includes(e)}function Kc(e,t){let n=e.limits.maxArrayElements;if(t.length>n)throw new P(`shopt: argument limit exceeded (${n})`,"array_elements");let r=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),s=!1,i=!1,a=!1,o=!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 b=1;b<E.length;b++){let g=E[b];switch(g){case"s":s=!0;break;case"u":i=!0;break;case"p":a=!0;break;case"q":o=!0;break;case"o":l=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${g}: invalid option
654
+ `}}}u++}else break}for(;u<t.length;)c.push(t[u]),u++;if(l)return Ch(e,c,s,i,a,o);if(s&&i)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
655
+ `};if(c.length===0){if(s||i){let b=[];for(let g of Ea){let w=e.state.shoptOptions[g];s&&w?b.push(a?`shopt -s ${g}`:`${g} on`):i&&!w&&b.push(a?`shopt -u ${g}`:`${g} off`)}return{exitCode:0,stdout:b.length>0?`${b.join(`
620
656
  `)}
621
- `:"")}let s=[],r=()=>s.length>0?H(s.join("")):K,n=0;for(;n<t.length;){let i=t[n];if((i==="-o"||i==="+o")&&ed(t,n)){let a=t[n+1];if(!$n.has(a)){let l=`bash: set: ${a}: invalid option name
622
- ${bs}`;if(e.state.options.posix)throw new Be(1,"",l);return N(l)}pi(e,$n.get(a)??null,i==="-o"),n+=2;continue}if(i==="-o"){s.push(kl(e)),n++;continue}if(i==="+o"){s.push(Nl(e)),n++;continue}if(i.length>1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let a=i[0]==="-",l=0;for(let o=1;o<i.length;o++){let u=i[o];if(u==="o"){let c=n+1+l;if(c<t.length&&!t[c].startsWith("-")&&!t[c].startsWith("+")){let d=t[c];if(!$n.has(d)){let h=`bash: set: ${d}: invalid option name
623
- ${bs}`;if(e.state.options.posix)throw new Be(1,"",h);return N(h)}pi(e,$n.get(d)??null,a),l++;continue}s.push(a?kl(e):Nl(e));continue}if(!Pl.has(u)){let c=`bash: set: ${i[0]}${u}: invalid option
624
- ${bs}`;if(e.state.options.posix)throw new Be(1,"",c);return N(c)}pi(e,Pl.get(u)??null,a)}n+=1+l;continue}if(i==="--")return mi(e,t.slice(n+1)),r();if(i==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,jt(e),n+1<t.length)return mi(e,t.slice(n+1)),r();n++;continue}if(i==="+"){n++;continue}if(i.startsWith("-")||i.startsWith("+")){let a=`bash: set: ${i}: invalid option
625
- ${bs}`;if(e.state.options.posix)throw new Be(1,"",a);return N(a)}return mi(e,t.slice(n)),r()}return r()}function mi(e,t){let s=1;for(;e.state.env.has(String(s));)e.state.env.delete(String(s)),s++;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 yi(e,t){let s=1;if(t.length>0){let a=Number.parseInt(t[0],10);if(Number.isNaN(a)||a<0){let l=`bash: shift: ${t[0]}: numeric argument required
626
- `;if(e.state.options.posix)throw new Be(1,"",l);return N(l)}s=a}let r=Number.parseInt(e.state.env.get("#")||"0",10);if(s>r){let a=`bash: shift: shift count out of range
627
- `;if(e.state.options.posix)throw new Be(1,"",a);return N(a)}if(s===0)return K;let n=[];for(let a=1;a<=r;a++)n.push(e.state.env.get(String(a))||"");let i=n.slice(s);for(let a=1;a<=r;a++)e.state.env.delete(String(a));for(let a=0;a<i.length;a++)e.state.env.set(String(a+1),i[a]);return e.state.env.set("#",String(i.length)),e.state.env.set("@",i.join(" ")),K}async function wi(e,t){let s=t;if(s.length>0&&s[0]==="--"&&(s=s.slice(1)),s.length===0)return _("",`bash: source: filename argument required
628
- `,2);let r=s[0],n=null,i=null;if(r.includes("/")){let u=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(u),n=u}catch{}}else{let c=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of c){let d=e.fs.resolvePath(e.state.cwd,`${f}/${r}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),n=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(f),n=f}catch{}}}if(i===null)return N(`bash: ${r}: No such file or directory
629
- `);let a=new Map;if(s.length>1){for(let c=1;c<=9;c++)a.set(String(c),e.state.env.get(String(c)));a.set("#",e.state.env.get("#")),a.set("@",e.state.env.get("@"));let u=s.slice(1);e.state.env.set("#",String(u.length)),e.state.env.set("@",u.join(" "));for(let c=0;c<u.length&&c<9;c++)e.state.env.set(String(c+1),u[c]);for(let c=u.length+1;c<=9;c++)e.state.env.delete(String(c))}let l=e.state.currentSource,o=()=>{if(e.state.sourceDepth--,e.state.currentSource=l,s.length>1)for(let[u,c]of a)c===void 0?e.state.env.delete(u):e.state.env.set(u,c)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new X(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let u=Ce(i),c=await e.executeScript(u);return o(),c}catch(u){if(o(),u instanceof Z)throw u;if(u instanceof ke)return _(u.stdout,u.stderr,u.exitCode);if(u.name==="ParseException")return N(`bash: ${r}: ${u.message}
630
- `);throw u}}function Cl(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function ad(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function Dl(e,t){if(ad(t))return null;try{let s=new q,r=Y(s,t);return await T(e,r.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}function Rl(e,t){if(e.state.localVarStack?.has(t)){let r=yn(e,t);if(r){r.value===void 0?e.state.env.delete(t):e.state.env.set(t,r.value);let n=e.state.localVarStack?.get(t);if(!n||n.length===0)gn(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),Ei(e,t);else{let i=n[n.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),gn(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 n=e.state.localScopes[r];if(n.has(t)){let i=n.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),n.delete(t);let a=!1;for(let l=r-1;l>=0;l--)if(e.state.localScopes[l].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,l+1),a=!0;break}return a||gn(e,t),!0}}return!1}function Ei(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let s=e.state.tempEnvBindings.length-1;s>=0;s--){let r=e.state.tempEnvBindings[s];if(r.has(t)){let n=r.get(t);return n===void 0?e.state.env.delete(t):e.state.env.set(t,n),r.delete(t),!0}}return!1}async function Il(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let s=t.slice(1,-1),n=new q().parseWordFromString(s,!0,!1);return V(e,n)}if(t.includes("$")){let r=new q().parseWordFromString(t,!1,!1);return V(e,r)}return t}async function bi(e,t){let s="both",r="",n=0;for(let i of t){if(i==="-v"){s="variable";continue}if(i==="-f"){s="function";continue}if(s==="function"){e.state.functions.delete(i);continue}if(s==="variable"){let u=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(u){let d=u[1],h=u[2];if(h==="@"||h==="*"){let E=B(e,d);for(let[w]of E)e.state.env.delete(`${d}_${w}`);e.state.env.delete(d);continue}let m=e.state.associativeArrays?.has(d);if(m){let E=await Il(e,h);e.state.env.delete(`${d}_${E}`);continue}let p=He(e,d),y=e.state.declaredVars?.has(d);if((e.state.env.has(d)||y)&&!p&&!m){r+=`bash: unset: ${d}: not an array variable
631
- `,n=1;continue}let v=await Dl(e,h);if(v===null&&p){r+=`bash: unset: ${h}: not a valid identifier
632
- `,n=1;continue}if(v===null)continue;if(v<0){let E=B(e,d),w=E.length,S=e.state.currentLine;if(w===0){r+=`bash: line ${S}: unset: [${v}]: bad array subscript
633
- `,n=1;continue}let A=w+v;if(A<0){r+=`bash: line ${S}: unset: [${v}]: bad array subscript
634
- `,n=1;continue}let $=E[A][0];e.state.env.delete(`${d}_${$}`);continue}e.state.env.delete(`${d}_${v}`);continue}if(!Cl(i)){r+=`bash: unset: \`${i}': not a valid identifier
635
- `,n=1;continue}let c=i;if(te(e,i)){let d=$e(e,i);d&&d!==i&&(c=d)}if(rt(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable
636
- `,n=1;continue}let f=Qt(e,c);if(f!==void 0&&f!==e.state.callDepth)Rl(e,c);else if(e.state.fullyUnsetLocals?.has(c))e.state.env.delete(c);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(c),h=e.state.mutatedTempEnvVars?.has(c);if((d||h)&&e.state.localVarStack?.has(c)){let m=yn(e,c);m?m.value===void 0?e.state.env.delete(c):e.state.env.set(c,m.value):e.state.env.delete(c)}else e.state.env.delete(c)}else Ei(e,c)||e.state.env.delete(c);e.state.exportedVars?.delete(c);continue}let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let u=a[1],c=a[2];if(c==="@"||c==="*"){let p=B(e,u);for(let[y]of p)e.state.env.delete(`${u}_${y}`);e.state.env.delete(u);continue}let f=e.state.associativeArrays?.has(u);if(f){let p=await Il(e,c);e.state.env.delete(`${u}_${p}`);continue}let d=He(e,u);if(e.state.env.has(u)&&!d&&!f){r+=`bash: unset: ${u}: not an array variable
637
- `,n=1;continue}let m=await Dl(e,c);if(m===null&&d){r+=`bash: unset: ${c}: not a valid identifier
638
- `,n=1;continue}if(m===null)continue;if(m<0){let p=B(e,u),y=p.length,b=e.state.currentLine;if(y===0){r+=`bash: line ${b}: unset: [${m}]: bad array subscript
639
- `,n=1;continue}let v=y+m;if(v<0){r+=`bash: line ${b}: unset: [${m}]: bad array subscript
640
- `,n=1;continue}let E=p[v][0];e.state.env.delete(`${u}_${E}`);continue}e.state.env.delete(`${u}_${m}`);continue}if(!Cl(i)){r+=`bash: unset: \`${i}': not a valid identifier
641
- `,n=1;continue}let l=i;if(te(e,i)){let u=$e(e,i);u&&u!==i&&(l=u)}if(rt(e,l)){r+=`bash: unset: ${l}: cannot unset: readonly variable
642
- `,n=1;continue}let o=Qt(e,l);if(o!==void 0&&o!==e.state.callDepth)Rl(e,l);else if(e.state.fullyUnsetLocals?.has(l))e.state.env.delete(l);else if(o!==void 0){let u=e.state.accessedTempEnvVars?.has(l),c=e.state.mutatedTempEnvVars?.has(l);if((u||c)&&e.state.localVarStack?.has(l)){let f=yn(e,l);f?f.value===void 0?e.state.env.delete(l):e.state.env.set(l,f.value):e.state.env.delete(l)}else e.state.env.delete(l)}else Ei(e,l)||e.state.env.delete(l);e.state.exportedVars?.delete(l),e.state.functions.delete(i)}return _("",r,n)}var vi=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],od=["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 Pn(e){return vi.includes(e)}function ld(e){return od.includes(e)}function Ol(e,t){let s=!1,r=!1,n=!1,i=!1,a=!1,l=[],o=0;for(;o<t.length;){let d=t[o];if(d==="--"){o++;break}if(d.startsWith("-")&&d.length>1){for(let h=1;h<d.length;h++){let m=d[h];switch(m){case"s":s=!0;break;case"u":r=!0;break;case"p":n=!0;break;case"q":i=!0;break;case"o":a=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${m}: invalid option
643
- `}}}o++}else break}for(;o<t.length;)l.push(t[o]),o++;if(a)return cd(e,l,s,r,n,i);if(s&&r)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
644
- `};if(l.length===0){if(s||r){let h=[];for(let m of vi){let p=e.state.shoptOptions[m];s&&p?h.push(n?`shopt -s ${m}`:`${m} on`):r&&!p&&h.push(n?`shopt -u ${m}`:`${m} off`)}return{exitCode:0,stdout:h.length>0?`${h.join(`
657
+ `:"",stderr:""}}let E=[];for(let b of Ea){let g=e.state.shoptOptions[b];E.push(a?`shopt ${g?"-s":"-u"} ${b}`:`${b} ${g?"on":"off"}`)}return{exitCode:0,stdout:`${E.join(`
645
658
  `)}
646
- `:"",stderr:""}}let d=[];for(let h of vi){let m=e.state.shoptOptions[h];d.push(n?`shopt ${m?"-s":"-u"} ${h}`:`${h} ${m?"on":"off"}`)}return{exitCode:0,stdout:`${d.join(`
659
+ `,stderr:""}}let f=!1,d=[],h=0,p=[],m=0;for(let E of c){if(!gs(E)&&!Nh(E)){h=bt(d,`shopt: ${E}: invalid shell option name`,h,r),f=!0;continue}if(s)gs(E)&&(e.state.shoptOptions[E]=!0,qs(e));else if(i)gs(E)&&(e.state.shoptOptions[E]=!1,qs(e));else if(gs(E)){let b=e.state.shoptOptions[E];o?b||(f=!0):a?(m=bt(p,`shopt ${b?"-s":"-u"} ${E}`,m,r),b||(f=!0)):(m=bt(p,`${E} ${b?"on":"off"}`,m,r),b||(f=!0))}else o?f=!0:a?(m=bt(p,`shopt -u ${E}`,m,r),f=!0):(m=bt(p,`${E} off`,m,r),f=!0)}return{exitCode:f?1:0,stdout:p.length>0?`${p.join(`
647
660
  `)}
648
- `,stderr:""}}let u=!1,c="",f=[];for(let d of l){if(!Pn(d)&&!ld(d)){c+=`shopt: ${d}: invalid shell option name
649
- `,u=!0;continue}if(s)Pn(d)&&(e.state.shoptOptions[d]=!0,Gn(e));else if(r)Pn(d)&&(e.state.shoptOptions[d]=!1,Gn(e));else if(Pn(d)){let h=e.state.shoptOptions[d];i?h||(u=!0):n?(f.push(`shopt ${h?"-s":"-u"} ${d}`),h||(u=!0)):(f.push(`${d} ${h?"on":"off"}`),h||(u=!0))}else i?u=!0:n?(f.push(`shopt -u ${d}`),u=!0):(f.push(`${d} off`),u=!0)}return{exitCode:u?1:0,stdout:f.length>0?`${f.join(`
661
+ `:"",stderr:d.length>0?`${d.join(`
650
662
  `)}
651
- `:"",stderr:c}}function cd(e,t,s,r,n,i){let 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"],o=[...a.keys(),...l].sort();if(t.length===0){let d=[];for(let h of o){let m=l.includes(h),p=a.get(h),y=m||!p?!1:e.state.options[p];s&&!y||r&&y||d.push(n?`set ${y?"-o":"+o"} ${h}`:`${h} ${y?"on":"off"}`)}return{exitCode:0,stdout:d.length>0?`${d.join(`
663
+ `:""}}function Ch(e,t,n,r,s,i){let a=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),o=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=[...o.keys(),...l].sort();if(t.length===0){let m=[];for(let E of c){let b=l.includes(E),g=o.get(E),w=b||!g?!1:e.state.options[g];n&&!w||r&&w||m.push(s?`set ${w?"-o":"+o"} ${E}`:`${E} ${w?"on":"off"}`)}return{exitCode:0,stdout:m.length>0?`${m.join(`
652
664
  `)}
653
- `:"",stderr:""}}let u=!1,c="",f=[];for(let d of t){let h=a.has(d),m=l.includes(d);if(!h&&!m){c+=`shopt: ${d}: invalid option name
654
- `,u=!0;continue}if(m){s||r||(i?u=!0:n?(f.push(`set +o ${d}`),u=!0):(f.push(`${d} off`),u=!0));continue}let p=a.get(d);if(p)if(s)p==="vi"?e.state.options.emacs=!1:p==="emacs"&&(e.state.options.vi=!1),e.state.options[p]=!0,jt(e);else if(r)e.state.options[p]=!1,jt(e);else{let y=e.state.options[p];i?y||(u=!0):n?(f.push(`set ${y?"-o":"+o"} ${d}`),y||(u=!0)):(f.push(`${d} ${y?"on":"off"}`),y||(u=!0))}}return{exitCode:u?1:0,stdout:f.length>0?`${f.join(`
665
+ `:"",stderr:""}}let u=!1,f=[],d=0,h=[],p=0;for(let m of t){let E=o.has(m),b=l.includes(m);if(!E&&!b){d=bt(f,`shopt: ${m}: invalid option name`,d,a),u=!0;continue}if(b){n||r||(i?u=!0:s?(p=bt(h,`set +o ${m}`,p,a),u=!0):(p=bt(h,`${m} off`,p,a),u=!0));continue}let g=o.get(m);if(g)if(n)g==="vi"?e.state.options.emacs=!1:g==="emacs"&&(e.state.options.vi=!1),e.state.options[g]=!0,wn(e);else if(r)e.state.options[g]=!1,wn(e);else{let w=e.state.options[g];i?w||(u=!0):s?(p=bt(h,`set ${w?"-o":"+o"} ${m}`,p,a),w||(u=!0)):(p=bt(h,`${m} ${w?"on":"off"}`,p,a),w||(u=!0))}}return{exitCode:u?1:0,stdout:h.length>0?`${h.join(`
655
666
  `)}
656
- `:"",stderr:c}}async function Tl(e,t,s){if(t.includes("/")){let a=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(a))return{error:"not_found",path:a};let l=a.split("/").pop()||t,o=e.commands.get(l);try{let u=await e.fs.stat(a);return u.isDirectory?{error:"permission_denied",path:a}:o?{cmd:o,path:a}:(u.mode&73)!==0?{script:!0,path:a}:{error:"permission_denied",path:a}}catch{return{error:"not_found",path:a}}}if(!s&&e.state.hashTable){let a=e.state.hashTable.get(t);if(a)if(await e.fs.exists(a)){let l=e.commands.get(t);if(l)return{cmd:l,path:a};try{let o=await e.fs.stat(a);if(!o.isDirectory&&(o.mode&73)!==0)return{script:!0,path:a}}catch{}}else e.state.hashTable.delete(t)}let n=(s??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let a of n){if(!a)continue;let o=`${a.startsWith("/")?a:e.fs.resolvePath(e.state.cwd,a)}/${t}`;if(await e.fs.exists(o))try{let u=await e.fs.stat(o);if(u.isDirectory)continue;let c=(u.mode&73)!==0,f=e.commands.get(t),d=a==="/bin"||a==="/usr/bin";if(f&&d)return{cmd:f,path:o};if(c){if(f&&!d)return{script:!0,path:o};if(!f)return{script:!0,path:o}}}catch{}}if(!await e.fs.exists("/usr/bin")){let a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function kn(e,t){let s=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let a=await e.fs.stat(i);a.isDirectory||(a.mode&73)!==0&&s.push(t)}catch{}return s}let n=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of n){if(!i)continue;let l=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(l)){try{if((await e.fs.stat(l)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?l:`${i}/${t}`)}}return s}function ud(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function oe(e,t,s,r){return((...n)=>{ls(t,s,`${r} call`);let i=e(...n);return ud(i)?i.then(a=>(ls(t,s,`${r} post-await`),a),a=>{throw ls(t,s,`${r} post-await`),a}):(ls(t,s,`${r} return`),i)})}function fd(e,t,s){let r={readFile:oe(e.readFile.bind(e),t,s,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:oe(e.readFileBytes.bind(e),t,s,"fs.readFileBytes")}:Object.create(null),readFileBuffer:oe(e.readFileBuffer.bind(e),t,s,"fs.readFileBuffer"),writeFile:oe(e.writeFile.bind(e),t,s,"fs.writeFile"),appendFile:oe(e.appendFile.bind(e),t,s,"fs.appendFile"),exists:oe(e.exists.bind(e),t,s,"fs.exists"),stat:oe(e.stat.bind(e),t,s,"fs.stat"),mkdir:oe(e.mkdir.bind(e),t,s,"fs.mkdir"),readdir:oe(e.readdir.bind(e),t,s,"fs.readdir"),rm:oe(e.rm.bind(e),t,s,"fs.rm"),cp:oe(e.cp.bind(e),t,s,"fs.cp"),mv:oe(e.mv.bind(e),t,s,"fs.mv"),resolvePath:oe(e.resolvePath.bind(e),t,s,"fs.resolvePath"),getAllPaths:oe(e.getAllPaths.bind(e),t,s,"fs.getAllPaths"),chmod:oe(e.chmod.bind(e),t,s,"fs.chmod"),symlink:oe(e.symlink.bind(e),t,s,"fs.symlink"),link:oe(e.link.bind(e),t,s,"fs.link"),readlink:oe(e.readlink.bind(e),t,s,"fs.readlink"),lstat:oe(e.lstat.bind(e),t,s,"fs.lstat"),realpath:oe(e.realpath.bind(e),t,s,"fs.realpath"),utimes:oe(e.utimes.bind(e),t,s,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=oe(e.readdirWithFileTypes.bind(e),t,s,"fs.readdirWithFileTypes")),r}function Ll(e,t){if(!e.requireDefenseContext)return e;let s=`command:${t}`,r={...e,fs:fd(e.fs,e.requireDefenseContext,s)};return e.exec&&(r.exec=oe(e.exec,e.requireDefenseContext,s,"exec")),e.fetch&&(r.fetch=oe(e.fetch,e.requireDefenseContext,s,"fetch")),e.sleep&&(r.sleep=oe(e.sleep,e.requireDefenseContext,s,"sleep")),e.getRegisteredCommands&&(r.getRegisteredCommands=oe(e.getRegisteredCommands,e.requireDefenseContext,s,"getRegisteredCommands")),r}async function Vl(e,t,s,r){let n=!1,i=!1,a=!1,l=!1,o=!1,u=[];for(let p of t)if(p.startsWith("-")&&p.length>1)for(let y of p.slice(1))y==="t"?n=!0:y==="p"?i=!0:y==="P"?a=!0:y==="a"?l=!0:y==="f"&&(o=!0);else u.push(p);let c="",f="",d=0,h=!1,m=!1;for(let p of u){let y=!1;if(a){if(l){let A=await r(p);if(A.length>0){for(let $ of A)c+=`${$}
657
- `;h=!0,y=!0}}else{let A=await s(p);A&&(c+=`${A}
658
- `,h=!0,y=!0)}y||(m=!0);continue}let b=!o&&e.state.functions.has(p);if(l&&b){if(!i)if(n)c+=`function
659
- `;else{let A=e.state.functions.get(p),$=A?Ml(p,A):`${p} is a function
660
- `;c+=$}y=!0}let v=e.state.env.get(`BASH_ALIAS_${p}`);if(v!==void 0&&(l||!y)&&(i||(n?c+=`alias
661
- `:c+=`${p} is aliased to \`${v}'
662
- `),y=!0,!l)||Wr.has(p)&&(l||!y)&&(i||(n?c+=`keyword
663
- `:c+=`${p} is a shell keyword
664
- `),y=!0,!l))continue;if(!l&&b&&!y){if(!i)if(n)c+=`function
665
- `;else{let A=e.state.functions.get(p),$=A?Ml(p,A):`${p} is a function
666
- `;c+=$}y=!0;continue}if(!(Kt.has(p)&&(l||!y)&&(i||(n?c+=`builtin
667
- `:c+=`${p} is a shell builtin
668
- `),y=!0,!l))){if(l){let A=await r(p);for(let $ of A)i?c+=`${$}
669
- `:n?c+=`file
670
- `:c+=`${p} is ${$}
671
- `,h=!0,y=!0}else if(!y){let A=await s(p);A&&(i?c+=`${A}
672
- `:n?c+=`file
673
- `:c+=`${p} is ${A}
674
- `,h=!0,y=!0)}if(!y&&(m=!0,!n&&!i)){let A=!0;if(p.includes("/")){let $=e.fs.resolvePath(e.state.cwd,p);await e.fs.exists($)&&(A=!1)}A&&(f+=`bash: type: ${p}: not found
675
- `)}}}return i?d=m&&!h?1:0:d=m?1:0,_(c,f,d)}function Ml(e,t){let s;return t.body.type==="Group"?s=t.body.body.map(n=>vs(n)).join("; "):s=vs(t.body),`${e} is a function
667
+ `:"",stderr:f.length>0?`${f.join(`
668
+ `)}
669
+ `:""}}function ws(e,t){return e===`/bin/${t}`||e===`/usr/bin/${t}`}async function Xc(e,t,n){if(t.includes("/")){let a=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(a))return{error:"not_found",path:a};try{let o=await e.fs.stat(a);if(o.isDirectory)return{error:"permission_denied",path:a};let l=a.split("/").pop()||t,c=e.commands.get(l);return c&&ws(a,l)?{cmd:c,path:a}:(o.mode&73)!==0?{script:!0,path:a}:{error:"permission_denied",path:a}}catch{return{error:"not_found",path:a}}}if(!n&&e.state.hashTable){let a=e.state.hashTable.get(t);if(a){try{let o=await e.fs.stat(a);if(!o.isDirectory){let l=e.commands.get(t);if(l&&ws(a,t))return{cmd:l,path:a};if((o.mode&73)!==0)return{script:!0,path:a}}}catch{}e.state.hashTable.delete(t)}}let s=(n??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let a of s){if(!a)continue;let l=`${a.startsWith("/")?a:e.fs.resolvePath(e.state.cwd,a)}/${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=ws(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 a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function Es(e,t){let n=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let a=await e.fs.stat(i);a.isDirectory||(a.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 o=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(ws(o,t)&&e.commands.has(t)){n.push(o);continue}if(await e.fs.exists(o)){try{let l=await e.fs.stat(o);if(l.isDirectory||(l.mode&73)===0)continue}catch{continue}n.push(i.startsWith("/")?o:`${i}/${t}`)}}return n}function Dh(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function he(e,t,n,r){return((...s)=>{Wn(t,n,`${r} call`);let i=e(...s);return Dh(i)?i.then(a=>(Wn(t,n,`${r} post-await`),a),a=>{throw Wn(t,n,`${r} post-await`),a}):(Wn(t,n,`${r} return`),i)})}function Rh(e,t,n){let r={readFile:he(e.readFile.bind(e),t,n,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:he(e.readFileBytes.bind(e),t,n,"fs.readFileBytes")}:Object.create(null),readFileBuffer:he(e.readFileBuffer.bind(e),t,n,"fs.readFileBuffer"),writeFile:he(e.writeFile.bind(e),t,n,"fs.writeFile"),appendFile:he(e.appendFile.bind(e),t,n,"fs.appendFile"),exists:he(e.exists.bind(e),t,n,"fs.exists"),stat:he(e.stat.bind(e),t,n,"fs.stat"),mkdir:he(e.mkdir.bind(e),t,n,"fs.mkdir"),readdir:he(e.readdir.bind(e),t,n,"fs.readdir"),rm:he(e.rm.bind(e),t,n,"fs.rm"),cp:he(e.cp.bind(e),t,n,"fs.cp"),mv:he(e.mv.bind(e),t,n,"fs.mv"),resolvePath:he(e.resolvePath.bind(e),t,n,"fs.resolvePath"),getAllPaths:he(e.getAllPaths.bind(e),t,n,"fs.getAllPaths"),chmod:he(e.chmod.bind(e),t,n,"fs.chmod"),symlink:he(e.symlink.bind(e),t,n,"fs.symlink"),link:he(e.link.bind(e),t,n,"fs.link"),readlink:he(e.readlink.bind(e),t,n,"fs.readlink"),lstat:he(e.lstat.bind(e),t,n,"fs.lstat"),realpath:he(e.realpath.bind(e),t,n,"fs.realpath"),utimes:he(e.utimes.bind(e),t,n,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=he(e.readdirWithFileTypes.bind(e),t,n,"fs.readdirWithFileTypes")),r}function Yc(e,t){if(!e.requireDefenseContext)return e;let n=`command:${t}`,r={...e,fs:Rh(e.fs,e.requireDefenseContext,n)};return e.exec&&(r.exec=he(e.exec,e.requireDefenseContext,n,"exec")),e.fetch&&(r.fetch=he(e.fetch,e.requireDefenseContext,n,"fetch")),e.sleep&&(r.sleep=he(e.sleep,e.requireDefenseContext,n,"sleep")),e.getRegisteredCommands&&(r.getRegisteredCommands=he(e.getRegisteredCommands,e.requireDefenseContext,n,"getRegisteredCommands")),r}var Jc="+ ";async function eu(e){let t=e.state.env.get("PS4");if(t===void 0)return Jc;if(t==="")return"";let n=e.state.options.xtrace;e.state.options.xtrace=!1;try{let s=new U().parseWordFromString(t,!1,!1);return await z(e,s)}catch(r){if(r instanceof oe&&!r.fatal)return t;if(r instanceof Ia||r instanceof Error&&r.name==="AbortError")throw r;return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
670
+ `,t||Jc}finally{e.state.options.xtrace=n}}function Oh(e){return e.map(t=>Ih(t)).join(" ")}function Ih(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let n=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
671
+ `),s=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(n||r||s||i){let l="";for(let c of e){let u=c.charCodeAt(0);c===`
672
+ `?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 a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function tu(e,t,n){if(!e.state.options.xtrace)return"";let r=await eu(e),s=[t,...n],i=Oh(s);return`${r}${i}
673
+ `}async function nu(e,t,n){return e.state.options.xtrace?`${await eu(e)}${t}=${n}
674
+ `:""}function bs(e,t,n){return It([t,n],"",e.limits.maxStringLength,"array assignment")}async function ru(e,t){let n=new Map,r="";for(let s of t.assignments){let i=s.name;if(s.array){let u=await _h(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 a=s.value?await z(e,s.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:I("",`bash: ${i}: bad array subscript
675
+ `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let u=await Wh(e,t,l[1],l[2],a,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};if(u.continueToNext)continue}let c=await Fh(e,t,i,a,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 _h(e,t,n,r,s,i){let a="";if(/\[.+\]$/.test(n))return{continueToNext:!1,xtraceOutput:"",error:I("",`bash: ${n}: cannot assign list to array member
676
+ `,1)};if(le(e,n)){let p=ln(e,n);if(p===void 0||p==="")throw new H(1,"","");let m=Te(e,n);if(m&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(m))return{continueToNext:!1,xtraceOutput:"",error:I("",`bash: ${n}: cannot assign list to array member
677
+ `,1)}}if(Le(e,n)){if(t.name)return a+=`bash: ${n}: readonly variable
678
+ `,{continueToNext:!0,xtraceOutput:a};let p=ce(e,n);if(p)return{continueToNext:!1,xtraceOutput:"",error:p}}let o=e.state.associativeArrays?.has(n),l=Ae(e,n),c=l?_e(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=Th(r),h=()=>{ge(e,n),e.state.env.delete(n)};try{o&&d?await Lh(e,t,n,r,s,h,p=>{a+=p}):d?await Mh(e,n,r,s,h):await Bh(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=>gn(E)).join(" ")})`;e.state.env.set(n,m)}return{continueToNext:!0,xtraceOutput:a}}function Th(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 Lh(e,t,n,r,s,i,a){let o=[];for(let l of r){if(o.length>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let c=Fs(l);if(c){let{key:u,valueParts:f,append:d}=c,h;f.length>0?(h=await z(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(h=Ut(e,h))):h="",o.push({type:"keyed",key:u,value:h,append:d})}else{let u=await z(e,l);o.push({type:"invalid",expandedValue:u})}}e.executionScope.consumeWork(o.length,"associative array assignment"),s||i();for(let l of o)if(l.type==="keyed")if(l.append){let c=ae(e,n,l.key)??"";q(e,n,l.key,bs(e,c,l.value),"associative")}else q(e,n,l.key,l.value,"associative");else{let c=t.line??e.state.currentLine??1;a(`bash: line ${c}: ${n}: ${l.expandedValue}: must use subscript when assigning associative array
679
+ `)}}async function Mh(e,t,n,r,s){let i=[],a=0;for(let l of n){let c=Fs(l);if(c){if(a>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let{key:u,valueParts:f,append:d}=c,h;f.length>0?(h=await z(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(h=Ut(e,h))):h="",i.push({type:"keyed",indexExpr:u,value:h,append:d}),a++}else{let u=await ut(e,l);if(u.values.length>e.limits.maxArrayElements-a)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push({type:"non-keyed",values:u.values}),a+=u.values.length}}e.executionScope.consumeWork(a,"indexed array assignment"),r||s();let o=0;for(let l of i)if(l.type==="keyed"){let c;try{let u=new U,f=re(u,l.indexExpr);c=await K(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)??"";q(e,t,c,bs(e,u,l.value))}else q(e,t,c,l.value);o=c+1}else for(let c of l.values)q(e,t,o++,c)}async function Bh(e,t,n,r,s){let i=[];for(let o of n){let l=await ut(e,o);for(let c of l.values){if(i.length>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push(c)}}let a=0;if(e.executionScope.consumeWork(i.length,"indexed array assignment"),r){let o=j(e,t);if(o.length>0)a=Math.max(...o.map(([c])=>typeof c=="number"?c:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(q(e,t,0,l),e.state.env.delete(t),a=1)}}else s();for(let o=0;o<i.length;o++)q(e,t,a+o,i[o])}async function Wh(e,t,n,r,s,i,a){let o=n;if(le(e,n)){let f=Te(e,n);if(f&&f!==n){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:I("",`bash: \`${f}': not a valid identifier
680
+ `,1)};o=f}}if(Le(e,o)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=ce(e,o);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l=e.state.associativeArrays?.has(o),c;if(l)c=await su(e,r);else{let f=await ba(e,o,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};c=String(f.index)}let u=i?bs(e,ae(e,o,c)||"",s):s;return t.name||q(e,o,c,u,l?"associative":"indexed"),{continueToNext:!0,xtraceOutput:""}}async function su(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 U().parseWordFromString(r,!0,!1);n=await z(e,i)}else if(t.includes("$")){let s=new U().parseWordFromString(t,!1,!1);n=await z(e,s)}else n=t;return n}async function ba(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 U,a=re(i,r);s=await K(e,a.expression,!1)}catch(i){if(i instanceof H)throw i;if(i instanceof oe){let l=`bash: line ${e.state.currentLine}: ${n}: ${i.message}
681
+ `;if(i.fatal)throw new H(1,"",l);return{index:0,error:I("",l,1)}}let a=e.state.currentLine;return{index:0,error:I("",`bash: line ${a}: ${t}[${n}]: bad array subscript
682
+ `,1)}}Number.isNaN(s)&&(s=0)}if(s<0){let i=j(e,t);if(i.length===0){let o=e.state.currentLine;return{index:0,error:I("",`bash: line ${o}: ${t}[${n}]: bad array subscript
683
+ `,1)}}if(s=Math.max(...i.map(([o])=>typeof o=="number"?o:0))+1+s,s<0){let o=e.state.currentLine;return{index:0,error:I("",`bash: line ${o}: ${t}[${n}]: bad array subscript
684
+ `,1)}}}return{index:s}}async function Fh(e,t,n,r,s,i){let a="",o=n,l=null;if(le(e,n)){let f=Mr(e,n,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:I("",`bash: ${n}: circular name reference
685
+ `,1)};if(f===null)return{continueToNext:!0,xtraceOutput:""};o=f;let d=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(l={arrayName:d[1],subscriptExpr:d[2]},o=d[1])}if(Le(e,o)){if(t.name)return a+=`bash: ${o}: readonly variable
686
+ `,{continueToNext:!0,xtraceOutput:a};let f=ce(e,o);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let c;if(rr(e,o))try{let f=new U;if(s){let h=`(${e.state.env.get(o)||"0"}) + (${r})`,p=re(f,h);c=String(await K(e,p.expression))}else{let d=re(f,r);c=String(await K(e,d.expression))}}catch{c="0"}else{let f=at(e,o)?ae(e,o,0):e.state.env.get(o);c=s?bs(e,f||"",r):r}c=kn(e,o,c),a+=await nu(e,o,c);let u;return l?u=await Vh(e,l):at(e,o)&&(u="0"),t.name?u===void 0&&(i.set(o,e.state.env.get(o)),e.state.env.set(o,c)):(u===void 0?e.state.env.set(o,c):q(e,o,u,c),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(o)),e.state.tempEnvBindings?.some(f=>f.has(o))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(o))),{continueToNext:!1,xtraceOutput:a}}async function Vh(e,t){let{arrayName:n,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(n))return su(e,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let a=new U,o=re(a,r);i=await K(e,o.expression,!1)}catch{let a=e.state.env.get(r);i=a?Number.parseInt(a,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let a=j(e,n);a.length>0&&(i=Math.max(...a.map(l=>l[0]))+1+i)}return String(i)}async function lu(e,t,n,r){let s=!1,i=!1,a=!1,o=!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"?a=!0:E==="a"?o=!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(a){if(o){let v=await r(m);if(v.length>0){for(let x of v)u+=`${x}
687
+ `;h=!0,E=!0}}else{let v=await n(m);v&&(u+=`${v}
688
+ `,h=!0,E=!0)}E||(p=!0);continue}let b=!l&&e.state.functions.has(m);if(o&&b){if(!i)if(s)u+=`function
689
+ `;else{let v=e.state.functions.get(m),x=v?iu(m,v):`${m} is a function
690
+ `;u+=x}E=!0}let g=e.state.env.get(`BASH_ALIAS_${m}`);if(g!==void 0&&(o||!E)&&(i||(s?u+=`alias
691
+ `:u+=`${m} is aliased to \`${g}'
692
+ `),E=!0,!o)||Ti.has(m)&&(o||!E)&&(i||(s?u+=`keyword
693
+ `:u+=`${m} is a shell keyword
694
+ `),E=!0,!o))continue;if(!o&&b&&!E){if(!i)if(s)u+=`function
695
+ `;else{let v=e.state.functions.get(m),x=v?iu(m,v):`${m} is a function
696
+ `;u+=x}E=!0;continue}if(!(xn.has(m)&&(o||!E)&&(i||(s?u+=`builtin
697
+ `:u+=`${m} is a shell builtin
698
+ `),E=!0,!o))){if(o){let v=await r(m);for(let x of v)i?u+=`${x}
699
+ `:s?u+=`file
700
+ `:u+=`${m} is ${x}
701
+ `,h=!0,E=!0}else if(!E){let v=await n(m);v&&(i?u+=`${v}
702
+ `:s?u+=`file
703
+ `:u+=`${m} is ${v}
704
+ `,h=!0,E=!0)}if(!E&&(p=!0,!s&&!i)){let v=!0;if(m.includes("/")){let x=e.fs.resolvePath(e.state.cwd,m);await e.fs.exists(x)&&(v=!1)}v&&(f+=`bash: type: ${m}: not found
705
+ `)}}}return i?d=p&&!h?1:0:d=p?1:0,I(u,f,d)}function iu(e,t){let n;return t.body.type==="Group"?n=t.body.body.map(s=>ar(s)).join("; "):n=ar(t.body),`${e} is a function
676
706
  ${e} ()
677
707
  {
678
- ${s}
708
+ ${n}
679
709
  }
680
- `}function vs(e){if(Array.isArray(e))return e.map(t=>vs(t)).join("; ");if(e.type==="Statement"){let t=[];for(let s=0;s<e.pipelines.length;s++){let r=e.pipelines[s];t.push(dd(r)),e.operators[s]&&t.push(e.operators[s])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,s=[];t.name&&s.push(Wl(t.name));for(let r of t.args)s.push(Wl(r));return s.join(" ")}return e.type==="Group"?`{ ${e.body.map(r=>vs(r)).join("; ")}; }`:"..."}function dd(e){let t=e.commands.map(s=>vs(s));return(e.negated?"! ":"")+t.join(" | ")}function Wl(e){let t="";for(let s of e.parts)s.type==="Literal"?t+=s.value:s.type==="DoubleQuoted"?t+=`"${s.parts.map(r=>Fl(r)).join("")}"`:s.type==="SingleQuoted"?t+=`'${s.value}'`:t+=Fl(s);return t}function Fl(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function zl(e,t,s,r){let n="",i="",a=0;for(let l of t){if(!l){a=1;continue}let o=e.state.env.get(`BASH_ALIAS_${l}`);if(o!==void 0)r?n+=`${l} is an alias for "${o}"
681
- `:n+=`alias ${l}='${o}'
682
- `;else if(Wr.has(l))r?n+=`${l} is a shell keyword
683
- `:n+=`${l}
684
- `;else if(Kt.has(l))r?n+=`${l} is a shell builtin
685
- `:n+=`${l}
686
- `;else if(e.state.functions.has(l))r?n+=`${l} is a function
687
- `:n+=`${l}
688
- `;else if(l.includes("/")){let u=e.fs.resolvePath(e.state.cwd,l),c=!1;if(await e.fs.exists(u))try{let f=await e.fs.stat(u);f.isDirectory||(f.mode&73)!==0&&(r?n+=`${l} is ${l}
689
- `:n+=`${l}
690
- `,c=!0)}catch{}c||(r&&(i+=`${l}: not found
691
- `),a=1)}else if(e.commands.has(l)){let c=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of c){if(!d)continue;let h=`${d}/${l}`;try{let m=await e.fs.stat(h);if(!m.isDirectory&&(m.mode&73)!==0){f=h;break}}catch{}}f||(f=`/usr/bin/${l}`),r?n+=`${l} is ${f}
692
- `:n+=`${f}
693
- `}else r&&(i+=`${l}: not found
694
- `),a=1}return _(n,i,a)}async function Bl(e,t){if(t.includes("/")){let n=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(n)){try{let i=await e.fs.stat(n);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 n of r){if(!n)continue;let a=`${n.startsWith("/")?n:e.fs.resolvePath(e.state.cwd,n)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).isDirectory)continue}catch{continue}return`${n}/${t}`}}if(e.commands.has(t)){for(let n of r)if(n==="/usr/bin"||n==="/bin")return`${n}/${t}`;return`/usr/bin/${t}`}return null}async function ql(e,t,s,r,n,i,a,l){let{ctx:o,runCommand:u}=e;if(o.coverage&&Kt.has(t)&&o.coverage.hit(`bash:builtin:${t}`),t==="export")return ai(o,s);if(t==="unset")return bi(o,s);if(t==="exit")return ii(o,s);if(t==="local")return ui(o,s);if(t==="set")return gi(o,s);if(t==="break")return Rr(o,s);if(t==="continue")return Ur(o,s);if(t==="return")return hi(o,s);if(t==="eval"&&o.state.options.posix)return Sn(o,s,n);if(t==="shift")return yi(o,s);if(t==="getopts")return An(o,s);if(t==="compgen")return zr(o,s);if(t==="complete")return qr(o,s);if(t==="compopt")return jr(o,s);if(t==="pushd")return await si(o,s);if(t==="popd")return ni(o,s);if(t==="dirs")return ri(o,s);if(t==="source"||t===".")return wi(o,s);if(t==="read")return di(o,s,n,l);if(t==="mapfile"||t==="readarray")return fi(o,s,n);if(t==="declare"||t==="typeset")return Jr(o,s);if(t==="readonly")return ei(o,s);if(!i){let c=o.state.functions.get(t);if(c)return bn(o,c,s,n)}if(t==="eval")return Sn(o,s,n);if(t==="cd")return await Ir(o,s);if(t===":"||t==="true")return K;if(t==="false")return pe(!1);if(t==="let")return ci(o,s);if(t==="command")return hd(e,s,n);if(t==="builtin")return pd(e,s,n);if(t==="shopt")return Ol(o,s);if(t==="exec"){if(s.length===0)return K;let[c,...f]=s;return u(c,f,[],n,!1,!1,-1)}if(t==="wait")return K;if(t==="type")return await Vl(o,s,c=>Bl(o,c),c=>kn(o,c));if(t==="hash")return oi(o,s);if(t==="help")return li(o,s);if(t==="["||t==="test"){let c=s;if(t==="["){if(s[s.length-1]!=="]")return N("[: missing `]'\n",2);c=s.slice(0,-1)}return ys(o,c)}return null}async function hd(e,t,s){let{ctx:r,runCommand:n}=e;if(t.length===0)return K;let i=!1,a=!1,l=!1,o=t;for(;o.length>0&&o[0].startsWith("-");){let f=o[0];if(f==="--"){o=o.slice(1);break}for(let d of f.slice(1))d==="p"?i=!0:d==="V"?a=!0:d==="v"&&(l=!0);o=o.slice(1)}if(o.length===0)return K;if(l||a)return await zl(r,o,l,a);let[u,...c]=o;return n(u,c,[],s,!0,i,-1)}async function pd(e,t,s){let{runCommand:r}=e;if(t.length===0)return K;let n=t;if(n[0]==="--"&&(n=n.slice(1),n.length===0))return K;let i=n[0];if(!Kt.has(i))return N(`bash: builtin: ${i}: not a shell builtin
695
- `);let[,...a]=n;return r(i,a,[],s,!0,!1,-1)}async function jl(e,t,s,r,n){let{ctx:i,buildExportedEnv:a,executeUserScript:l}=e,u=await Tl(i,t,n?"/usr/bin:/bin":void 0);if(!u)return Xo(t)?N(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
696
- `,127):N(`bash: ${t}: command not found
697
- `,127);if("error"in u)return u.error==="permission_denied"?N(`bash: ${t}: Permission denied
698
- `,126):N(`bash: ${t}: No such file or directory
699
- `,127);if("script"in u)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u.path)),await l(u.path,s,r);let{cmd:c,path:f}=u;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",h=a(),m={fs:i.fs,cwd:i.state.cwd,env:i.state.env,exportedEnv:h,stdin:d,limits:i.limits,exec:i.execFn,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},p=Ll(m,t);try{let y=()=>Di(i.requireDefenseContext,"command",`${t} execution`,()=>c.execute(s,p));return c.trusted?await Ie.runTrustedAsync(()=>y()):await y()}catch(y){if(y instanceof X||y instanceof gt)throw y;return N(`${t}: ${ut(ct(y))}
700
- `)}}async function Si(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let r="",n="",i=0;try{for(let a of t){let l=await e.executeStatement(a);r+=l.stdout,n+=l.stderr,i=l.exitCode}}finally{e.state.inCondition=s}return{stdout:r,stderr:n,exitCode:i}}function Ss(e,t,s,r){if(e instanceof Oe)return t+=e.stdout,s+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"break",stdout:t,stderr:s};if(e instanceof Te)return t+=e.stdout,s+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"continue",stdout:t,stderr:s};if(e instanceof ke||e instanceof ze||e instanceof Z||e instanceof X)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let n=ct(e);return{action:"error",stdout:t,stderr:`${s}${n}
701
- `,exitCode:1}}async function Nn(e,t,s="",r=""){let n=s,i=r,a=0;try{for(let l of t){let o=await e.executeStatement(l);n+=o.stdout,i+=o.stderr,a=o.exitCode}}catch(l){if(Is(l)||l instanceof ze||l instanceof Z||l instanceof X||l instanceof Et)throw l.prependOutput(n,i),l;return{stdout:n,stderr:`${i}${ct(l)}
702
- `,exitCode:1}}return{stdout:n,stderr:i,exitCode:a}}async function Ul(e,t){let s="",r="";for(let n of t.clauses){let i=await Si(e,n.condition);if(s+=i.stdout,r+=i.stderr,i.exitCode===0)return Nn(e,n.body,s,r)}return t.elseBody?Nn(e,t.elseBody,s,r):_(s,r,0)}async function Zl(e,t){let s=await lt(e,t.redirections);if(s)return s;let r="",n="",i=0,a=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return N(`bash: \`${t.variable}': not a valid identifier
703
- `);let l=[];if(t.words===null)l=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)l=[];else try{for(let u of t.words){let c=await it(e,u);l.push(...c.values)}}catch(u){if(u instanceof wt)return{stdout:"",stderr:u.stderr,exitCode:1};throw u}e.state.loopDepth++;try{for(let u of l){a++,a>e.limits.maxLoopIterations&&at(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n),e.state.env.set(t.variable,u);try{for(let c of t.body){let f=await e.executeStatement(c);r+=f.stdout,n+=f.stderr,i=f.exitCode}}catch(c){let f=Ss(c,r,n,e.state.loopDepth);if(r=f.stdout,n=f.stderr,f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error"){let d=_(r,n,f.exitCode??1);return ue(e,d,t.redirections)}throw f.error}}}finally{e.state.loopDepth--}let o=_(r,n,i);return ue(e,o,t.redirections)}async function Gl(e,t){let s=await lt(e,t.redirections);if(s)return s;let r=t.line;r!==void 0&&(e.state.currentLine=r);let n="",i="",a=0,l=0;t.init&&await T(e,t.init.expression),e.state.loopDepth++;try{for(;l++,l>e.limits.maxLoopIterations&&at(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,i),!(t.condition&&(r!==void 0&&(e.state.currentLine=r),await T(e,t.condition.expression)===0));){try{for(let u of t.body){let c=await e.executeStatement(u);n+=c.stdout,i+=c.stderr,a=c.exitCode}}catch(u){let c=Ss(u,n,i,e.state.loopDepth);if(n=c.stdout,i=c.stderr,c.action==="break")break;if(c.action==="continue"){t.update&&await T(e,t.update.expression);continue}if(c.action==="error"){let f=_(n,i,c.exitCode??1);return ue(e,f,t.redirections)}throw c.error}t.update&&await T(e,t.update.expression)}}finally{e.state.loopDepth--}let o=_(n,i,a);return ue(e,o,t.redirections)}async function Hl(e,t,s=""){let r="",n="",i=0,a=0,l=s;for(let u of t.redirections)if((u.operator==="<<"||u.operator==="<<-")&&u.target.type==="HereDoc"){let c=u.target,f=await V(e,c.content);c.stripTabs&&(f=f.split(`
704
- `).map(d=>d.replace(/^\t+/,"")).join(`
705
- `)),l=f}else if(u.operator==="<<<"&&u.target.type==="Word")l=`${await V(e,u.target)}
706
- `;else if(u.operator==="<"&&u.target.type==="Word")try{let c=await V(e,u.target),f=e.fs.resolvePath(e.state.cwd,c);l=await e.fs.readFile(f)}catch{let c=await V(e,u.target);return N(`bash: ${c}: No such file or directory
707
- `)}let o=e.state.groupStdin;l&&(e.state.groupStdin=l),e.state.loopDepth++;try{for(;;){a++,a>e.limits.maxLoopIterations&&at(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n);let u=0,c=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let m=await e.executeStatement(h);r+=m.stdout,n+=m.stderr,u=m.exitCode}}catch(h){if(h instanceof Oe){if(r+=h.stdout,n+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=r,h.stderr=n,e.state.inCondition=d,h;c=!0}else if(h instanceof Te){if(r+=h.stdout,n+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=r,h.stderr=n,e.state.inCondition=d,h;f=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if(c)break;if(!f){if(u!==0)break;try{for(let h of t.body){let m=await e.executeStatement(h);r+=m.stdout,n+=m.stderr,i=m.exitCode}}catch(h){let m=Ss(h,r,n,e.state.loopDepth);if(r=m.stdout,n=m.stderr,m.action==="break")break;if(m.action==="continue")continue;if(m.action==="error")return _(r,n,m.exitCode??1);throw m.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=o}return _(r,n,i)}async function Ql(e,t){let s="",r="",n=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&at(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,r);let a=await Si(e,t.condition);if(s+=a.stdout,r+=a.stderr,a.exitCode===0)break;try{for(let l of t.body){let o=await e.executeStatement(l);s+=o.stdout,r+=o.stderr,n=o.exitCode}}catch(l){let o=Ss(l,s,r,e.state.loopDepth);if(s=o.stdout,r=o.stderr,o.action==="break")break;if(o.action==="continue")continue;if(o.action==="error")return _(s,r,o.exitCode??1);throw o.error}}}finally{e.state.loopDepth--}return _(s,r,n)}async function Kl(e,t){let s=await lt(e,t.redirections);if(s)return s;let r="",n="",i=0,a=await V(e,t.word),l=!1;for(let u=0;u<t.items.length;u++){let c=t.items[u],f=l;if(!l)for(let d of c.patterns){let h=await V(e,d);Bo(d)&&(h=Fe(h));let m=e.state.shoptOptions.nocasematch,p=e.state.shoptOptions.extglob;if(Ht(a,h,m,p)){f=!0;break}}if(f){let d=await Nn(e,c.body,r,n);if(r=d.stdout,n=d.stderr,i=d.exitCode,c.terminator===";;")break;c.terminator===";&"?l=!0:l=!1}else l=!1}let o=_(r,n,i);return ue(e,o,t.redirections)}function Ai(e,t){if(e.parts.length!==1)return!1;let s=e.parts[0];return s.type!=="Literal"?!1:t.includes(s.value)}function Xl(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let r=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(r)||r<0)return null;let n=s+1,i=t.slice(n,n+r),a=n+r+1,l=t.slice(a),o=l.indexOf(":");if(o===-1)return null;let u=Number.parseInt(l.slice(0,o),10);if(Number.isNaN(u)||u<0)return null;let c=l.slice(o+1);return{path:i,position:u,content:c}}var Yl="+ ";async function Jl(e){let t=e.state.env.get("PS4");if(t===void 0)return Yl;if(t==="")return"";try{let r=new q().parseWordFromString(t,!1,!1);return await V(e,r)}catch{return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
708
- `,t||Yl}}function md(e){return e.map(t=>gd(t)).join(" ")}function gd(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
709
- `),n=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(s||r||n||i){let o="";for(let u of e){let c=u.charCodeAt(0);u===`
710
- `?o+="\\n":u===" "?o+="\\t":u==="\\"?o+="\\\\":u==="'"?o+="'":u==='"'?o+='"':c<32||c===127?c<256?o+=`\\x${c.toString(16).padStart(2,"0")}`:o+=`\\u${c.toString(16).padStart(4,"0")}`:o+=u}return`$'${o}'`}return a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function ec(e,t,s){if(!e.state.options.xtrace)return"";let r=await Jl(e),n=[t,...s],i=md(n);return`${r}${i}
711
- `}async function tc(e,t,s){return e.state.options.xtrace?`${await Jl(e)}${t}=${s}
712
- `:""}async function sc(e,t,s){let r=t.timed?Bn():0,n="",i=K,a=0,l=[],o="",u=t.commands.length>1,c=e.state.lastArg;for(let d=0;d<t.commands.length;d++){let h=t.commands[d],m=d===t.commands.length-1,p=d===0;u&&(e.state.lastArg="",p||(e.state.groupStdin=void 0));let b=u&&(!m||!e.state.shoptOptions.lastpipe)?new Map(e.state.env):null,v;try{v=await s(h,n)}catch(E){if(E instanceof Me)v={stdout:E.stdout,stderr:E.stderr,exitCode:1};else if(E instanceof Z&&t.commands.length>1)v={stdout:E.stdout,stderr:E.stderr,exitCode:E.exitCode};else if(E instanceof ze&&t.commands.length>1)v={stdout:E.stdout,stderr:E.stderr,exitCode:E.exitCode};else throw b&&(e.state.env=b),E}b&&(e.state.env=b),l.push(v.exitCode),v.exitCode!==0&&(a=v.exitCode),m?i=v:(t.pipeStderr?.[d]??!1?n=yt(v.stderr)+Cs(v):(n=Cs(v),o+=v.stderr),i={stdout:"",stderr:"",exitCode:v.exitCode})}if(o&&(i={...i,stderr:o+i.stderr}),t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let d of e.state.env.keys())d.startsWith("PIPESTATUS_")&&e.state.env.delete(d);for(let d=0;d<l.length;d++)e.state.env.set(`PIPESTATUS_${d}`,String(l[d]));e.state.env.set("PIPESTATUS__length",String(l.length))}if(e.state.options.pipefail&&a!==0&&(i={...i,exitCode:a}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let h=(Bn()-r)/1e3,m=Math.floor(h/60),p=h%60,y;t.timePosix?y=`real ${h.toFixed(2)}
710
+ `}function ar(e){if(Array.isArray(e))return e.map(t=>ar(t)).join("; ");if(e.type==="Statement"){let t=[];for(let n=0;n<e.pipelines.length;n++){let r=e.pipelines[n];t.push(zh(r)),e.operators[n]&&t.push(e.operators[n])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,n=[];t.name&&n.push(au(t.name));for(let r of t.args)n.push(au(r));return n.join(" ")}return e.type==="Group"?`{ ${e.body.map(r=>ar(r)).join("; ")}; }`:"..."}function zh(e){let t=e.commands.map(n=>ar(n));return(e.negated?"! ":"")+t.join(" | ")}function au(e){let t="";for(let n of e.parts)n.type==="Literal"?t+=n.value:n.type==="DoubleQuoted"?t+=`"${n.parts.map(r=>ou(r)).join("")}"`:n.type==="SingleQuoted"?t+=`'${n.value}'`:t+=ou(n);return t}function ou(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function cu(e,t,n,r){let s="",i="",a=0;for(let o of t){if(!o){a=1;continue}let l=e.state.env.get(`BASH_ALIAS_${o}`);if(l!==void 0)r?s+=`${o} is an alias for "${l}"
711
+ `:s+=`alias ${o}='${l}'
712
+ `;else if(Ti.has(o))r?s+=`${o} is a shell keyword
713
+ `:s+=`${o}
714
+ `;else if(xn.has(o))r?s+=`${o} is a shell builtin
715
+ `:s+=`${o}
716
+ `;else if(e.state.functions.has(o))r?s+=`${o} is a function
717
+ `:s+=`${o}
718
+ `;else if(o.includes("/")){let c=e.fs.resolvePath(e.state.cwd,o),u=!1;if(await e.fs.exists(c))try{let f=await e.fs.stat(c);f.isDirectory||(f.mode&73)!==0&&(r?s+=`${o} is ${o}
719
+ `:s+=`${o}
720
+ `,u=!0)}catch{}u||(r&&(i+=`${o}: not found
721
+ `),a=1)}else if(e.commands.has(o)){let u=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of u){if(!d)continue;let h=`${d}/${o}`;try{let p=await e.fs.stat(h);if(!p.isDirectory&&(p.mode&73)!==0){f=h;break}}catch{}}f||(f=`/usr/bin/${o}`),r?s+=`${o} is ${f}
722
+ `:s+=`${f}
723
+ `}else r&&(i+=`${o}: not found
724
+ `),a=1}return I(s,i,a)}async function uu(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 a=`${s.startsWith("/")?s:e.fs.resolvePath(e.state.cwd,s)}/${t}`;if(await e.fs.exists(a)){try{let o=await e.fs.stat(a);if(o.isDirectory||(o.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 qh(e,t){let n=!0,r=e.signal?new AbortController:void 0,s=new WeakMap,i=()=>{if(!n)throw new We("",`bash: ${t} used its context after cancellation
725
+ `)},a=c=>{if(c===null||typeof c!="object"&&typeof c!="function")return c;let u=s.get(c);if(u!==void 0)return u;if(typeof c=="object"&&Ua(c))return c;if(c instanceof Uint8Array){let p=new Uint8Array(c);return s.set(c,p),p}if(c instanceof ArrayBuffer){let p=c.slice(0);return s.set(c,p),p}if(c instanceof Promise){let p=c.then(m=>(i(),a(m)));return s.set(c,p),p}if(typeof c=="function"){let p=function(...m){return i(),a(Reflect.apply(c,this,m))};return s.set(c,p),p}let f=Object.getPrototypeOf(c);if(Array.isArray(c)||f===Object.prototype||f===null){let p=Array.isArray(c)?[]:Object.create(f);s.set(c,p);let m=Object.getOwnPropertyDescriptors(c);for(let E of Object.values(m)){if("value"in E){let b=E.value;E.value=typeof b=="function"?(...g)=>(i(),a(Reflect.apply(b,c,g))):a(b)}if(E.get){let b=E.get;E.get=()=>(i(),a(Reflect.apply(b,c,[])))}if(E.set){let b=E.set;E.set=g=>{i(),Reflect.apply(b,c,[g])}}}return Object.defineProperties(p,m),p}let d=new Map,h=new Ta(c,{get(p,m){if(i(),m==="constructor"||m==="prototype"||m==="__proto__")throw new Error(`${t}: unsafe context property access`);let E=Reflect.get(p,m,p);if(typeof E!="function")return a(E);if(d.has(m))return d.get(m);let b=(...g)=>(i(),a(Reflect.apply(E,p,g)));return d.set(m,b),b},set(p,m,E){if(i(),m==="constructor"||m==="prototype"||m==="__proto__")throw new Error(`${t}: unsafe context property access`);return Reflect.set(p,m,E,p)}});return s.set(c,h),h},o=c=>a(c),l=c=>c&&((...u)=>(i(),a(c(...u))));return{context:{...e,fs:o(e.fs),env:o(e.env),limits:Object.freeze({...e.limits}),exportedEnv:e.exportedEnv?Object.freeze({...e.exportedEnv}):void 0,executionScope:e.executionScope?o(e.executionScope):void 0,fileDescriptors:e.fileDescriptors?o(e.fileDescriptors):void 0,coverage:e.coverage?o(e.coverage):void 0,assignShellVariable:l(e.assignShellVariable),exec:l(e.exec),execWithInheritedStdin:l(e.execWithInheritedStdin),fetch:l(e.fetch),getRegisteredCommands:l(e.getRegisteredCommands),sleep:l(e.sleep),trace:l(e.trace),invokeTool:l(e.invokeTool),signal:r?.signal},revoke(){n=!1,r?.signal.aborted||r?.abort(new We("",`bash: ${t} context revoked
726
+ `))}}}async function Uh(e,t,n,r,s,i){let a=s.remainingTimeMs()??t.limits.maxExecutionTimeMs,o=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=Tn(()=>{n(),p({kind:"deadline"})},a)});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=Tn(()=>b(!1),o)})]),E=p.kind==="deadline"?new We("",`bash: ${r} exceeded its execution deadline
727
+ `):new We("",`bash: execution aborted
728
+ `);throw m||s.poisonAfterAbort(E),E}finally{n(),Ln(l),Ln(u),c&&i?.removeEventListener("abort",c)}}async function fu(e,t,n,r,s,i,a,o){let{ctx:l,runCommand:c}=e;if(l.coverage&&xn.has(t)&&l.coverage.hit(`bash:builtin:${t}`),t==="export")return sa(l,n);if(t==="unset")return wa(l,n);if(t==="exit")return ra(l,n);if(t==="local")return la(l,n);if(t==="set")return pa(l,n);if(t==="break")return ki(l,n);if(t==="continue")return ji(l,n);if(t==="return")return fa(l,n);if(t==="eval"&&l.state.options.posix)return ps(l,n,s);if(t==="shift")return ma(l,n);if(t==="getopts")return ms(l,n);if(t==="compgen")return Fi(l,n);if(t==="complete")return qi(l,n);if(t==="compopt")return Ui(l,n);if(t==="pushd")return await ea(l,n);if(t==="popd")return ta(l,n);if(t==="dirs")return na(l,n);if(t==="source"||t===".")return ya(l,n);if(t==="read")return ua(l,n,s,o);if(t==="mapfile"||t==="readarray")return ca(l,n,s);if(t==="declare"||t==="typeset")return Xi(l,n);if(t==="readonly")return Yi(l,n);if(!i){let u=l.state.functions.get(t);if(u)return ds(l,u,n,s)}if(t==="__just_bash_tee_restore"){if(n.length===0||n.length>l.limits.maxArrayElements)return R(`bash: invalid internal pipeline status restore
729
+ `,2);let u=[];for(let h of n){if(!/^(?:0|[1-9][0-9]{0,2})$/.test(h))return R(`bash: invalid internal pipeline status restore
730
+ `,2);let p=Number(h);if(!Number.isSafeInteger(p)||p>255)return R(`bash: invalid internal pipeline status restore
731
+ `,2);u.push(p)}let f=u[u.length-1]??0,d=[...u].reverse().find(h=>h!==0);return{stdout:"",stderr:"",exitCode:l.state.options.pipefail&&d!==void 0?d:f,internalPipeStatusOverride:u}}if(t==="eval")return ps(l,n,s);if(t==="cd")return await Ni(l,n);if(t===":"||t==="true")return ne;if(t==="false")return we(!1);if(t==="let")return oa(l,n);if(t==="command")return jh(e,n,s);if(t==="builtin")return Gh(e,n,s);if(t==="shopt")return Kc(l,n);if(t==="exec"){if(n.length===0)return ne;let[u,...f]=n;return c(u,f,[],s,!1,!1,-1)}if(t==="wait")return ne;if(t==="type")return await lu(l,n,u=>uu(l,u),u=>Es(l,u));if(t==="hash")return ia(l,n);if(t==="help")return aa(l,n);if(t==="["||t==="test"){let u=n;if(t==="["){if(n[n.length-1]!=="]")return R("[: missing `]'\n",2);u=n.slice(0,-1)}return Jn(l,u)}return null}async function jh(e,t,n){let{ctx:r,runCommand:s}=e;if(t.length===0)return ne;let i=!1,a=!1,o=!1,l=t;for(;l.length>0&&l[0].startsWith("-");){let f=l[0];if(f==="--"){l=l.slice(1);break}for(let d of f.slice(1))d==="p"?i=!0:d==="V"?a=!0:d==="v"&&(o=!0);l=l.slice(1)}if(l.length===0)return ne;if(o||a)return await cu(r,l,o,a);let[c,...u]=l;return s(c,u,[],n,!0,i,-1)}async function Gh(e,t,n){let{runCommand:r}=e;if(t.length===0)return ne;let s=t;if(s[0]==="--"&&(s=s.slice(1),s.length===0))return ne;let i=s[0];if(i!=="__just_bash_tee_restore"&&!xn.has(i))return R(`bash: builtin: ${i}: not a shell builtin
732
+ `);let[,...a]=s;return r(i,a,[],n,!0,!1,-1)}async function du(e,t,n,r,s){let{ctx:i,buildExportedEnv:a,executeUserScript:o}=e,c=await Xc(i,t,s?"/usr/bin:/bin":void 0);if(!c)return dc(t)?R(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
733
+ `,127):R(`bash: ${t}: command not found
734
+ `,127);if("error"in c)return c.error==="permission_denied"?R(`bash: ${t}: Permission denied
735
+ `,126):R(`bash: ${t}: No such file or directory
736
+ `,127);if("script"in c)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,c.path)),await o(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=a();i.state.fileDescriptors??=new Map;let p={fs:i.fs,fsIdentity:vr(i.fs),cwd:i.state.cwd,env:i.state.env,assignShellVariable:async(b,g,w)=>{if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(b))throw new Error(`${b}: not a valid identifier`);let S=w===void 0?b:`${b}[${w}]`,A=Mr(i,b,g);if(A===void 0)throw new Error(`${b}: circular name reference`);if(A===null)return;let v=A.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(?:\[(.*)\])?$/);if(!v)throw new Error(`${S}: not a valid identifier`);let x=v[1],N=v[2]??w;if(Le(i,b)||Le(i,x))throw new Error(`${x}: readonly variable`);if(N===void 0)i.state.env.set(x,g);else{let D=i.state.associativeArrays?.has(x)?"associative":"indexed";if(D==="associative"){q(i,x,N,g,D);return}let O=await ba(i,x,N);if(O.error)throw new H(O.error.exitCode,O.error.stdout,O.error.stderr);q(i,x,O.index,g,D)}},exportedEnv:h,stdin:d,limits:i.limits,executionScope:u.internalIsExtension?Qa(i.executionScope):i.executionScope,exec:(b,g)=>i.execFn(b,g,!1),execWithInheritedStdin:(b,g)=>i.execFn(b,{...g,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},m=qh(p,t),E=Yc(m.context,t);try{let b=()=>_a(i.requireDefenseContext,"command",`${t} execution`,()=>u.execute(n,E)),g=()=>Uh(b,E,m.revoke,t,i.executionScope,i.state.signal);return u.trusted?await Ie.runTrustedAsync(g):await g()}catch(b){if(b instanceof P||b instanceof We||b instanceof Ct)throw b;return R(`${t}: ${ht(St(b))}
737
+ `)}}async function Sa(e,t){let n=e.state.inCondition;e.state.inCondition=!0;let r=new Lt(e.executionScope,"condition"),s=0;try{for(let i of t){let a=await e.executeStatement(i);r.appendResult(a),s=a.exitCode}}catch(i){throw r.prependTo(i),i}finally{e.state.inCondition=n}return r.build(s)}function or(e,t,n,r){if(e instanceof Ze)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};if(e instanceof He)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"continue",stdout:t,stderr:n};if(e instanceof Me||e instanceof et||e instanceof H||e instanceof P)return e.prependOutput(t,n),{action:"rethrow",stdout:t,stderr:n,error:e};let s=St(e);return{action:"error",stdout:t,stderr:`${n}${s}
738
+ `,exitCode:1}}var Kt=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&&Gt(`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 va(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(wr(s)||s instanceof et||s instanceof H||s instanceof P||s instanceof Ot)throw s.prependOutput(n.stdout,n.stderr),s;return n.appendUnaccounted("",`${St(s)}
739
+ `),n.build(1)}return n.build(r)}async function hu(e,t){let n=new Kt(e);for(let r of t.clauses){let s=await Sa(e,r.condition);if(n.append(s.stdout,s.stderr),s.exitCode===0)return va(e,r.body,n)}return t.elseBody?va(e,t.elseBody,n):n.build(0)}async function pu(e,t){let n=await ft(e,t.redirections);if(n.error)return n.error;let r=new Kt(e),s=0,i=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return R(`bash: \`${t.variable}': not a valid identifier
740
+ `);let a=[];if(t.words===null)a=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)a=[];else try{for(let l of t.words){let c=await ut(e,l);De(a,c.values,e.limits.maxArrayElements,"for-loop expansion")}}catch(l){if(l instanceof Rt)return{stdout:"",stderr:l.stderr,exitCode:1};throw l}e.state.loopDepth++;try{for(let l of a){i++,i>e.limits.maxLoopIterations&&Gt(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r.stdout,r.stderr),e.state.env.set(t.variable,l);try{for(let c of t.body){let u=await e.executeStatement(c);r.append(u.stdout,u.stderr),s=u.exitCode}}catch(c){let u=or(c,r.stdout,r.stderr,e.state.loopDepth);if(r.replace(u.stdout,u.stderr),u.action==="break")break;if(u.action==="continue")continue;if(u.action==="error"){let f=r.build(u.exitCode??1);return me(e,f,t.redirections,n.targets)}throw u.error}}}finally{e.state.loopDepth--}let o=r.build(s);return me(e,o,t.redirections,n.targets)}async function mu(e,t){let n=await ft(e,t.redirections);if(n.error)return n.error;let r=t.line;r!==void 0&&(e.state.currentLine=r);let s=new Kt(e),i=0,a=0;t.init&&await K(e,t.init.expression),e.state.loopDepth++;try{for(;a++,a>e.limits.maxLoopIterations&&Gt(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr),!(t.condition&&(r!==void 0&&(e.state.currentLine=r),await K(e,t.condition.expression)===0));){try{for(let l of t.body){let c=await e.executeStatement(l);s.append(c.stdout,c.stderr),i=c.exitCode}}catch(l){let c=or(l,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(c.stdout,c.stderr),c.action==="break")break;if(c.action==="continue"){t.update&&await K(e,t.update.expression);continue}if(c.action==="error"){let u=s.build(c.exitCode??1);return me(e,u,t.redirections,n.targets)}throw c.error}t.update&&await K(e,t.update.expression)}}finally{e.state.loopDepth--}let o=s.build(i);return me(e,o,t.redirections,n.targets)}async function yu(e,t,n=""){let r=new Kt(e),s=0,i=0,a=n;for(let l of t.redirections)if((l.operator==="<<"||l.operator==="<<-")&&l.target.type==="HereDoc"){let c=l.target,u=await z(e,c.content);c.stripTabs&&(u=u.split(`
741
+ `).map(f=>f.replace(/^\t+/,"")).join(`
742
+ `)),a=u}else if(l.operator==="<<<"&&l.target.type==="Word")a=`${await z(e,l.target)}
743
+ `;else if(l.operator==="<"&&l.target.type==="Word")try{let c=await z(e,l.target),u=e.fs.resolvePath(e.state.cwd,c);a=await e.fs.readFile(u)}catch{let c=await z(e,l.target);return R(`bash: ${c}: No such file or directory
744
+ `)}let o=e.state.groupStdin;a&&(e.state.groupStdin=a),e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&Gt(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r.stdout,r.stderr);let l=0,c=!1,u=!1,f=e.state.inCondition;e.state.inCondition=!0;try{for(let d of t.condition){let h=await e.executeStatement(d);r.append(h.stdout,h.stderr),l=h.exitCode}}catch(d){if(d instanceof Ze){if(r.append(d.stdout,d.stderr),d.levels>1&&e.state.loopDepth>1)throw d.levels--,d.stdout=r.stdout,d.stderr=r.stderr,e.state.inCondition=f,d;c=!0}else if(d instanceof He){if(r.append(d.stdout,d.stderr),d.levels>1&&e.state.loopDepth>1)throw d.levels--,d.stdout=r.stdout,d.stderr=r.stderr,e.state.inCondition=f,d;u=!0}else throw e.state.inCondition=f,d}finally{e.state.inCondition=f}if(c)break;if(!u){if(l!==0)break;try{for(let d of t.body){let h=await e.executeStatement(d);r.append(h.stdout,h.stderr),s=h.exitCode}}catch(d){let h=or(d,r.stdout,r.stderr,e.state.loopDepth);if(r.replace(h.stdout,h.stderr),h.action==="break")break;if(h.action==="continue")continue;if(h.action==="error")return r.build(h.exitCode??1);throw h.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=o}return r.build(s)}async function gu(e,t){let n=new Kt(e),r=0,s=0;e.state.loopDepth++;try{for(;;){s++,s>e.limits.maxLoopIterations&&Gt(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n.stdout,n.stderr);let i=await Sa(e,t.condition);if(n.append(i.stdout,i.stderr),i.exitCode===0)break;try{for(let a of t.body){let o=await e.executeStatement(a);n.append(o.stdout,o.stderr),r=o.exitCode}}catch(a){let o=or(a,n.stdout,n.stderr,e.state.loopDepth);if(n.replace(o.stdout,o.stderr),o.action==="break")break;if(o.action==="continue")continue;if(o.action==="error")return n.build(o.exitCode??1);throw o.error}}}finally{e.state.loopDepth--}return n.build(r)}async function wu(e,t){let n=await ft(e,t.redirections);if(n.error)return n.error;let r=new Kt(e),s=0,i=await z(e,t.word),a=!1;for(let l=0;l<t.items.length;l++){let c=t.items[l],u=a;if(!a)for(let f of c.patterns){let d=await z(e,f);nc(f)&&(d=Xe(d));let h=e.state.shoptOptions.nocasematch,p=e.state.shoptOptions.extglob;if(An(i,d,h,p,e.limits.maxCallDepth)){u=!0;break}}if(u){let f=await va(e,c.body,r);if(r.replace(f.stdout,f.stderr),s=f.exitCode,c.terminator===";;")break;c.terminator===";&"?a=!0:a=!1}else a=!1}let o=r.build(s);return me(e,o,t.redirections,n.targets)}function Aa(e,t){if(e.parts.length!==1)return!1;let n=e.parts[0];return n.type!=="Literal"?!1:t.includes(n.value)}function Eu(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),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),a=s+r+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let c=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let u=o.slice(l+1);return{path:i,position:c,content:u}}async function bu(e,t,n){let r=t.timed?Ms():0,s="",i=ne,a=0,o=[],l="",c=0,u=t.commands.length>1,f=e.state.lastArg;for(let E=0;E<t.commands.length;E++){let b=t.commands[E],g=E===t.commands.length-1,w=E===0;u&&(e.state.lastArg="",w||(e.state.groupStdin=void 0));let S=u&&(!g||!e.state.shoptOptions.lastpipe),A=S?new Map(e.state.env):null,v=S?pt(e.state.arrays):null,x,N=e.executionScope.outputBytesUsed;try{e.state.commandCount=e.executionScope.chargeCommand(),x=await n(b,s)}catch(D){if(D instanceof Qe)x={stdout:D.stdout,stderr:D.stderr,exitCode:1};else if(D instanceof H&&t.commands.length>1)x={stdout:D.stdout,stderr:D.stderr,exitCode:D.exitCode};else if(D instanceof et&&t.commands.length>1)x={stdout:D.stdout,stderr:D.stderr,exitCode:D.exitCode};else throw A&&(e.state.env=A,e.state.arrays=v??new Map),D}if(A&&(e.state.env=A,e.state.arrays=v??new Map),x=e.executionScope.accountResult(x,"pipeline",e.executionScope.outputBytesUsed-N),!g){let D=t.pipeStderr?.[E]??!1,O=x.internalOutputAccounting?.stdout??0,_=D?x.internalOutputAccounting?.stderr??0:0;Ka(e.executionScope,O+_,"pipeline"),x={...x,internalOutputAccounting:{stdout:0,stderr:D?0:x.internalOutputAccounting?.stderr??0}}}o.push(x.exitCode),x.exitCode!==0&&(a=x.exitCode),g?i=x:(t.pipeStderr?.[E]??!1?s=Dt(x.stderr)+yr(x):(s=yr(x),l+=x.stderr,c+=x.internalOutputAccounting?.stderr??0),i={stdout:"",stderr:"",exitCode:x.exitCode})}l&&(i={...i,stderr:l+i.stderr,internalOutputAccounting:{stdout:i.internalOutputAccounting?.stdout??0,stderr:c+(i.internalOutputAccounting?.stderr??0)}});let d=t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand",h=i.internalPipeStatusOverride??o;if(d){ge(e,"PIPESTATUS");for(let E=0;E<h.length;E++)q(e,"PIPESTATUS",E,String(h[E]))}if(e.state.options.pipefail&&a!==0&&(i={...i,exitCode:a}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let b=(Ms()-r)/1e3,g=Math.floor(b/60),w=b%60,S;t.timePosix?S=`real ${b.toFixed(2)}
713
745
  user 0.00
714
746
  sys 0.00
715
- `:y=`
716
- real ${`${m}m${p.toFixed(3)}s`}
747
+ `:S=`
748
+ real ${`${g}m${w.toFixed(3)}s`}
717
749
  user 0m0.000s
718
750
  sys 0m0.000s
719
- `,i={...i,stderr:i.stderr+y}}return u&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=c),i}async function nc(e,t){let s=new Map,r="";for(let n of t.assignments){let i=n.name;if(n.array){let c=await yd(e,t,i,n.array,n.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:c.error};if(r+=c.xtraceOutput,c.continueToNext)continue}let a=n.value?await V(e,n.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:_("",`bash: ${i}: bad array subscript
720
- `,1)};let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let c=await Sd(e,t,o[1],o[2],a,n.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:c.error};if(c.continueToNext)continue}let u=await $d(e,t,i,a,n.append,s);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:u.error};r+=u.xtraceOutput,u.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:s}}async function yd(e,t,s,r,n,i){let a="";if(/\[.+\]$/.test(s))return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: ${s}: cannot assign list to array member
721
- `,1)};if(te(e,s)){let c=Tt(e,s);if(c===void 0||c==="")throw new Z(1,"","");let f=$e(e,s);if(f&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(f))return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: ${s}: cannot assign list to array member
722
- `,1)}}if(rt(e,s)){if(t.name)return a+=`bash: ${s}: readonly variable
723
- `,{continueToNext:!0,xtraceOutput:a};let c=ye(e,s);if(c)return{continueToNext:!1,xtraceOutput:"",error:c}}let l=e.state.associativeArrays?.has(s),o=wd(r),u=()=>{let c=`${s}_`;for(let f of e.state.env.keys())f.startsWith(c)&&!f.includes("__")&&e.state.env.delete(f);e.state.env.delete(s)};if(l&&o?await Ed(e,t,s,r,n,u,c=>{a+=c}):o?await bd(e,s,r,n,u):await vd(e,s,r,n,u),t.name){i.set(s,e.state.env.get(s));let f=`(${r.map(d=>Ut(d)).join(" ")})`;e.state.env.set(s,f)}return{continueToNext:!0,xtraceOutput:a}}function wd(e){return e.some(t=>{if(t.parts.length>=2){let s=t.parts[0],r=t.parts[1];if(s.type!=="Glob"||!s.pattern.startsWith("["))return!1;if(s.pattern==="["&&(r.type==="DoubleQuoted"||r.type==="SingleQuoted")){if(t.parts.length<3)return!1;let n=t.parts[2];return n.type!=="Literal"?!1:n.value.startsWith("]=")||n.value.startsWith("]+=")}return r.type!=="Literal"?!1:r.value.startsWith("]")?r.value.startsWith("]=")||r.value.startsWith("]+="):s.pattern.endsWith("]")?r.value.startsWith("=")||r.value.startsWith("+="):!1}return!1})}async function Ed(e,t,s,r,n,i,a){let l=[];for(let o of r){let u=br(o);if(u){let{key:c,valueParts:f,append:d}=u,h;f.length>0?h=await V(e,{type:"Word",parts:f}):h="",h=de(e,h),l.push({type:"keyed",key:c,value:h,append:d})}else{let c=await V(e,o);l.push({type:"invalid",expandedValue:c})}}n||i();for(let o of l)if(o.type==="keyed")if(o.append){let u=e.state.env.get(`${s}_${o.key}`)??"";e.state.env.set(`${s}_${o.key}`,u+o.value)}else e.state.env.set(`${s}_${o.key}`,o.value);else{let u=t.line??e.state.currentLine??1;a(`bash: line ${u}: ${s}: ${o.expandedValue}: must use subscript when assigning associative array
724
- `)}}async function bd(e,t,s,r,n){let i=[];for(let l of s){let o=br(l);if(o){let{key:u,valueParts:c,append:f}=o,d;c.length>0?d=await V(e,{type:"Word",parts:c}):d="",d=de(e,d),i.push({type:"keyed",indexExpr:u,value:d,append:f})}else{let u=await it(e,l);i.push({type:"non-keyed",values:u.values})}}r||n();let a=0;for(let l of i)if(l.type==="keyed"){let o;try{let u=new q,c=Y(u,l.indexExpr);o=await T(e,c.expression,!1)}catch{if(/^-?\d+$/.test(l.indexExpr))o=Number.parseInt(l.indexExpr,10);else{let u=e.state.env.get(l.indexExpr);o=u?Number.parseInt(u,10):0,Number.isNaN(o)&&(o=0)}}if(l.append){let u=e.state.env.get(`${t}_${o}`)??"";e.state.env.set(`${t}_${o}`,u+l.value)}else e.state.env.set(`${t}_${o}`,l.value);a=o+1}else for(let o of l.values)e.state.env.set(`${t}_${a++}`,o)}async function vd(e,t,s,r,n){let i=[];for(let l of s){let o=await it(e,l);i.push(...o.values)}let a=0;if(r){let l=B(e,t);if(l.length>0)a=Math.max(...l.map(([u])=>typeof u=="number"?u:0))+1;else{let o=e.state.env.get(t);o!==void 0&&(e.state.env.set(`${t}_0`,o),e.state.env.delete(t),a=1)}}else n();for(let l=0;l<i.length;l++)e.state.env.set(`${t}_${a+l}`,i[l]);r||e.state.env.set(`${t}__length`,String(i.length))}async function Sd(e,t,s,r,n,i,a){let l=s;if(te(e,s)){let f=$e(e,s);if(f&&f!==s){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: \`${f}': not a valid identifier
725
- `,1)};l=f}}if(rt(e,l)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=ye(e,l);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let o=e.state.associativeArrays?.has(l),u;if(o)u=await rc(e,l,r);else{let f=await Ad(e,l,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};u=`${l}_${f.index}`}let c=i?(e.state.env.get(u)||"")+n:n;if(t.name)a.set(u,e.state.env.get(u)),e.state.env.set(u,c);else{let f=Qt(e,l);if(f!==void 0&&f===e.state.callDepth&&e.state.localScopes.length>0){let d=e.state.localScopes[e.state.localScopes.length-1];d.has(u)||d.set(u,e.state.env.get(u))}e.state.env.set(u,c)}return{continueToNext:!0,xtraceOutput:""}}async function rc(e,t,s){let r;if(s.startsWith("'")&&s.endsWith("'"))r=s.slice(1,-1);else if(s.startsWith('"')&&s.endsWith('"')){let n=s.slice(1,-1),a=new q().parseWordFromString(n,!0,!1);r=await V(e,a)}else if(s.includes("$")){let i=new q().parseWordFromString(s,!1,!1);r=await V(e,i)}else r=s;return`${t}_${r}`}async function Ad(e,t,s){let r=s;s.startsWith('"')&&s.endsWith('"')&&s.length>=2&&(r=s.slice(1,-1));let n;if(/^-?\d+$/.test(r))n=Number.parseInt(r,10);else{try{let i=new q,a=Y(i,r);n=await T(e,a.expression,!1)}catch(i){if(i instanceof se){let o=`bash: line ${e.state.currentLine}: ${s}: ${i.message}
726
- `;if(i.fatal)throw new Z(1,"",o);return{index:0,error:_("",o,1)}}let a=e.state.env.get(s);n=a?Number.parseInt(a,10):0}Number.isNaN(n)&&(n=0)}if(n<0){let i=B(e,t);if(i.length===0){let l=e.state.currentLine;return{index:0,error:_("",`bash: line ${l}: ${t}[${s}]: bad array subscript
727
- `,1)}}if(n=Math.max(...i.map(([l])=>typeof l=="number"?l:0))+1+n,n<0){let l=e.state.currentLine;return{index:0,error:_("",`bash: line ${l}: ${t}[${s}]: bad array subscript
728
- `,1)}}}return{index:n}}async function $d(e,t,s,r,n,i){let a="",l=s,o=null;if(te(e,s)){let f=Va(e,s,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: ${s}: circular name reference
729
- `,1)};if(f===null)return{continueToNext:!0,xtraceOutput:""};l=f;let d=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(o={arrayName:d[1],subscriptExpr:d[2]},l=d[1])}if(rt(e,l)){if(t.name)return a+=`bash: ${l}: readonly variable
730
- `,{continueToNext:!0,xtraceOutput:a};let f=ye(e,l);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let u;if(ws(e,l))try{let f=new q;if(n){let h=`(${e.state.env.get(l)||"0"}) + (${r})`,m=Y(f,h);u=String(await T(e,m.expression))}else{let d=Y(f,r);u=String(await T(e,d.expression))}}catch{u="0"}else{let f=He(e,l)?`${l}_0`:l;u=n?(e.state.env.get(f)||"")+r:r}u=Jt(e,l,u),a+=await tc(e,l,u);let c=l;return o?c=await Pd(e,o):He(e,l)&&(c=`${l}_0`),t.name?(i.set(c,e.state.env.get(c)),e.state.env.set(c,u)):(e.state.env.set(c,u),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(l)),e.state.tempEnvBindings?.some(f=>f.has(l))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(l))),{continueToNext:!1,xtraceOutput:a}}async function Pd(e,t){let{arrayName:s,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(s))return rc(e,s,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let a=new q,l=Y(a,r);i=await T(e,l.expression,!1)}catch{let a=e.state.env.get(r);i=a?Number.parseInt(a,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let a=B(e,s);a.length>0&&(i=Math.max(...a.map(o=>o[0]))+1+i)}return`${s}_${i}`}async function ic(e,t,s,r){let n=await lt(e,t.redirections);if(n)return n;let i=new Map(e.state.env),a=e.state.cwd,l={...e.state.options},o=new Map(e.state.functions),u=e.state.localScopes,c=e.state.localVarStack,f=e.state.localVarDepth,d=e.state.fullyUnsetLocals;if(e.state.localScopes=u.map($=>new Map($)),c){e.state.localVarStack=new Map;for(let[$,R]of c.entries())e.state.localVarStack.set($,R.map(C=>({...C})))}f&&(e.state.localVarDepth=new Map(f)),d&&(e.state.fullyUnsetLocals=new Map(d));let h=e.state.loopDepth,m=e.state.parentHasLoopContext;e.state.parentHasLoopContext=h>0,e.state.loopDepth=0;let p=e.state.lastArg,y=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let b=e.state.groupStdin;s&&(e.state.groupStdin=s);let v="",E="",w=0,S=()=>{e.state.env=i,e.state.cwd=a,e.state.options=l,e.state.functions=o,e.state.localScopes=u,e.state.localVarStack=c,e.state.localVarDepth=f,e.state.fullyUnsetLocals=d,e.state.loopDepth=h,e.state.parentHasLoopContext=m,e.state.groupStdin=b,e.state.bashPid=y,e.state.lastArg=p};try{for(let $ of t.body){let R=await r($);v+=R.stdout,E+=R.stderr,w=R.exitCode}}catch($){if(S(),$ instanceof X)throw $;if($ instanceof Et){v+=$.stdout,E+=$.stderr;let C=_(v,E,0);return ue(e,C,t.redirections)}if($ instanceof Oe||$ instanceof Te){v+=$.stdout,E+=$.stderr;let C=_(v,E,0);return ue(e,C,t.redirections)}if($ instanceof Z){v+=$.stdout,E+=$.stderr;let C=_(v,E,$.exitCode);return ue(e,C,t.redirections)}if($ instanceof ke){v+=$.stdout,E+=$.stderr;let C=_(v,E,$.exitCode);return ue(e,C,t.redirections)}if($ instanceof ze){let C=_(v+$.stdout,E+$.stderr,$.exitCode);return ue(e,C,t.redirections)}let R=_(v,`${E}${ct($)}
731
- `,1);return ue(e,R,t.redirections)}S();let A=_(v,E,w);return ue(e,A,t.redirections)}async function ac(e,t,s,r){let n="",i="",a=0,l=await En(e,t.redirections);if(l)return l;let o=s;for(let f of t.redirections)if((f.operator==="<<"||f.operator==="<<-")&&f.target.type==="HereDoc"){let d=f.target,h=await V(e,d.content);d.stripTabs&&(h=h.split(`
732
- `).map(p=>p.replace(/^\t+/,"")).join(`
733
- `));let m=f.fd??0;m!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),Ae(e),e.state.fileDescriptors.set(m,h)):o=h}else if(f.operator==="<<<"&&f.target.type==="Word")o=`${await V(e,f.target)}
734
- `;else if(f.operator==="<"&&f.target.type==="Word")try{let d=await V(e,f.target),h=e.fs.resolvePath(e.state.cwd,d);o=await e.fs.readFile(h)}catch{let d=await V(e,f.target);return _("",`bash: ${d}: No such file or directory
735
- `,1)}let u=e.state.groupStdin;o&&(e.state.groupStdin=o);try{for(let f of t.body){let d=await r(f);n+=d.stdout,i+=d.stderr,a=d.exitCode}}catch(f){if(e.state.groupStdin=u,f instanceof X)throw f;if(Is(f)||f instanceof ze||f instanceof Z)throw f.prependOutput(n,i),f;return _(n,`${i}${ct(f)}
736
- `,1)}e.state.groupStdin=u;let c=_(n,i,a);return ue(e,c,t.redirections)}async function oc(e,t,s,r,n){let i;try{i=await e.fs.readFile(t)}catch{return N(`bash: ${t}: No such file or directory
737
- `,127)}if(i.startsWith("#!")){let y=i.indexOf(`
738
- `);y!==-1&&(i=i.slice(y+1))}let a=new Map(e.state.env),l=e.state.cwd,o={...e.state.options},u=e.state.loopDepth,c=e.state.parentHasLoopContext,f=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,m=e.state.currentSource;e.state.parentHasLoopContext=u>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(s.length)),e.state.env.set("@",s.join(" ")),e.state.env.set("*",s.join(" "));for(let y=0;y<s.length&&y<9;y++)e.state.env.set(String(y+1),s[y]);for(let y=s.length+1;y<=9;y++)e.state.env.delete(String(y));let p=()=>{e.state.env=a,e.state.cwd=l,e.state.options=o,e.state.loopDepth=u,e.state.parentHasLoopContext=c,e.state.lastArg=f,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=m};try{let b=new q().parse(i),v=await n(b);return p(),v}catch(y){if(p(),y instanceof Z||y instanceof X)throw y;if(y.name==="ParseException")return N(`bash: ${t}: ${y.message}
739
- `);throw y}}var As=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,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||Ie.isInSandboxedContext())return;let s=`interpreter ${t} attempted outside defense context`;throw new gt(s,{timestamp:Date.now(),type:"missing_defense_context",message:s,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:Ie.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,r=new Set;if(t)for(let i of t)r.add(i);if(s)for(let i of s)r.add(i);if(r.size===0)return Object.create(null);let n=Object.create(null);for(let i of r){let a=this.ctx.state.env.get(i);a!==void 0&&(n[i]=a)}return n}async executeScript(t){this.assertDefenseContext("execution");let s="",r="",n=0,i=this.ctx.limits.maxOutputSize,a=(l,o)=>{s.length+r.length+l.length+o.length>i&&at(`total output size exceeded (>${i} bytes), increase executionLimits.maxOutputSize`,"output_size"),s+=l,r+=o};for(let l of t.statements)try{let o=await this.executeStatement(l);a(Vn(o),o.stderr),n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(o){if(o instanceof Z)throw o.prependOutput(s,r),o;if(o instanceof Be)return a(o.stdout,o.stderr),n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:bt(this.ctx.state.env)};if(o instanceof X)throw o;if(o instanceof ze)return a(o.stdout,o.stderr),n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:bt(this.ctx.state.env)};if(o instanceof Le)return a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:bt(this.ctx.state.env)};if(o instanceof Me)return a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:bt(this.ctx.state.env)};if(o instanceof se){a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(o instanceof Ds){a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(o instanceof Oe||o instanceof Te){if(this.ctx.state.loopDepth>0)throw o.prependOutput(s,r),o;a(o.stdout,o.stderr);continue}throw o instanceof ke&&o.prependOutput(s,r),o}return{stdout:s,stderr:r,exitCode:n,env:bt(this.ctx.state.env)}}async executeUserScript(t,s,r=""){return oc(this.ctx,t,s,r,n=>this.executeScript(n))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Rs;if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&at(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new Ee(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return K;this.ctx.state.errexitSafe=!1;let s="",r="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(r+=`${t.sourceText}
740
- `);let n=0,i=-1,a=!1;for(let u=0;u<t.pipelines.length;u++){let c=t.pipelines[u],f=u>0?t.operators[u-1]:null;if(f==="&&"&&n!==0||f==="||"&&n===0)continue;let d=await this.executePipeline(c);s+=Vn(d),r+=d.stderr,n=d.exitCode,i=u,a=c.negated,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}let l=i<t.pipelines.length-1,o=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=l||a||o,this.ctx.state.options.errexit&&n!==0&&i===t.pipelines.length-1&&!a&&!this.ctx.state.inCondition&&!o)throw new ze(n,s,r);return _(s,r,n)}async executePipeline(t){return sc(this.ctx,t,(s,r)=>this.executeCommand(s,r))}async executeCommand(t,s){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return Ul(this.ctx,t);case"For":return Zl(this.ctx,t);case"CStyleFor":return Gl(this.ctx,t);case"While":return Hl(this.ctx,t,s);case"Until":return Ql(this.ctx,t);case"Case":return Kl(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return dl(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return K}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(r){if(r instanceof wt)return N(r.stderr);throw r}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let w=t,S=100;for(;S>0;){let A=this.expandAlias(w);if(A===w)break;w=A,S--}this.aliasExpansionStack.clear(),w!==t&&(t=w)}this.ctx.state.expansionStderr="";let r=await nc(this.ctx,t);if(r.error)return r.error;let n=r.tempAssignments,i=r.xtraceOutput;if(!t.name){if(t.redirections.length>0){let S=await lt(this.ctx,t.redirections);if(S)return S;let A=_("",i,0);return ue(this.ctx,A,t.redirections)}this.ctx.state.lastArg="";let w=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",_("",w,this.ctx.state.lastExitCode)}let a=t.name&&Ai(t.name,["local","declare","typeset","export","readonly"]),l=Array.from(n.keys());if(l.length>0&&!a){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let w of l)this.ctx.state.tempExportedVars.add(w)}let o=await En(this.ctx,t.redirections);if(o){for(let[w,S]of n)S===void 0?this.ctx.state.env.delete(w):this.ctx.state.env.set(w,S);return o}let u=-1;for(let w of t.redirections){if((w.operator==="<<"||w.operator==="<<-")&&w.target.type==="HereDoc"){let S=w.target,A=await V(this.ctx,S.content);S.stripTabs&&(A=A.split(`
741
- `).map(R=>R.replace(/^\t+/,"")).join(`
742
- `)),A=yt(A);let $=w.fd??0;$!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),Ae(this.ctx),this.ctx.state.fileDescriptors.set($,A)):s=A;continue}if(w.operator==="<<<"&&w.target.type==="Word"){s=yt(`${await V(this.ctx,w.target)}
743
- `);continue}if(w.operator==="<"&&w.target.type==="Word")try{let S=await V(this.ctx,w.target),A=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);s=await xs(this.ctx.fs,A)}catch{let S=await V(this.ctx,w.target);for(let[A,$]of n)$===void 0?this.ctx.state.env.delete(A):this.ctx.state.env.set(A,$);return N(`bash: ${S}: No such file or directory
744
- `)}if(w.operator==="<&"&&w.target.type==="Word"){let S=await V(this.ctx,w.target),A=Number.parseInt(S,10);if(!Number.isNaN(A)&&this.ctx.state.fileDescriptors){let $=this.ctx.state.fileDescriptors.get(A);if($!==void 0)if($.startsWith("__rw__:")){let R=Xl($);R&&(s=R.content.slice(R.position),u=A)}else $.startsWith("__file__:")||$.startsWith("__file_append__:")||(s=$)}}}let c=await V(this.ctx,t.name),f=[],d=[];if(Ai(t.name,["local","declare","typeset","export","readonly"])&&(c==="local"||c==="declare"||c==="typeset"||c==="export"||c==="readonly"))for(let w of t.args){let S=await Qo(this.ctx,w);if(S)f.push(S),d.push(!0);else{let A=await Ko(this.ctx,w);if(A!==null)f.push(A),d.push(!0);else{let $=await it(this.ctx,w);for(let R of $.values)f.push(R),d.push($.quoted)}}}else for(let w of t.args){let S=await it(this.ctx,w);for(let A of S.values)f.push(A),d.push(S.quoted)}if(!c){if(t.name.parts.every(S=>S.type==="CommandSubstitution"||S.type==="ParameterExpansion"||S.type==="ArithmeticExpansion")){if(f.length>0){let S=f.shift();return d.shift(),await this.runCommand(S,f,d,s,!1,!1,u)}return _("","",this.ctx.state.lastExitCode)}return N(`bash: : command not found
745
- `,127)}if(c==="exec"&&(f.length===0||f[0]==="--")){for(let w of t.redirections){if(w.target.type==="HereDoc"||w.fdVariable)continue;let S=await V(this.ctx,w.target),A=w.fd??(w.operator==="<"||w.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),w.operator){case">":case">|":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);await this.ctx.fs.writeFile($,"","utf8"),Ae(this.ctx),this.ctx.state.fileDescriptors.set(A,`__file__:${$}`);break}case">>":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);Ae(this.ctx),this.ctx.state.fileDescriptors.set(A,`__file_append__:${$}`);break}case"<":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);try{let R=await this.ctx.fs.readFile($);Ae(this.ctx),this.ctx.state.fileDescriptors.set(A,R)}catch{return N(`bash: ${S}: No such file or directory
746
- `)}break}case"<>":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);try{let R=await this.ctx.fs.readFile($);Ae(this.ctx),this.ctx.state.fileDescriptors.set(A,`__rw__:${$.length}:${$}:0:${R}`)}catch{await this.ctx.fs.writeFile($,"","utf8"),Ae(this.ctx),this.ctx.state.fileDescriptors.set(A,`__rw__:${$.length}:${$}:0:`)}break}case">&":{if(S==="-")this.ctx.state.fileDescriptors.delete(A);else if(S.endsWith("-")){let $=S.slice(0,-1),R=Number.parseInt($,10);if(!Number.isNaN(R)){let C=this.ctx.state.fileDescriptors.get(R);C!==void 0?this.ctx.state.fileDescriptors.set(A,C):this.ctx.state.fileDescriptors.set(A,`__dupout__:${R}`),this.ctx.state.fileDescriptors.delete(R)}}else{let $=Number.parseInt(S,10);Number.isNaN($)||(Ae(this.ctx),this.ctx.state.fileDescriptors.set(A,`__dupout__:${$}`))}break}case"<&":{if(S==="-")this.ctx.state.fileDescriptors.delete(A);else if(S.endsWith("-")){let $=S.slice(0,-1),R=Number.parseInt($,10);if(!Number.isNaN(R)){let C=this.ctx.state.fileDescriptors.get(R);C!==void 0?this.ctx.state.fileDescriptors.set(A,C):this.ctx.state.fileDescriptors.set(A,`__dupin__:${R}`),this.ctx.state.fileDescriptors.delete(R)}}else{let $=Number.parseInt(S,10);Number.isNaN($)||(Ae(this.ctx),this.ctx.state.fileDescriptors.set(A,`__dupin__:${$}`))}break}}}for(let[w,S]of n)S===void 0?this.ctx.state.env.delete(w):this.ctx.state.env.set(w,S);if(this.ctx.state.tempExportedVars)for(let w of n.keys())this.ctx.state.tempExportedVars.delete(w);return K}if(this.ctx.state.extraArgs){f.push(...this.ctx.state.extraArgs);for(let w=0;w<this.ctx.state.extraArgs.length;w++)d.push(!0);this.ctx.state.extraArgs=void 0}let m=await ec(this.ctx,c,f);n.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(n)));let p,y=null;try{p=await this.runCommand(c,f,d,s,!1,!1,u)}catch(w){if(w instanceof Oe||w instanceof Te)y=w,p=K;else throw w}let b=i+m;if(b&&(p={...p,stderr:b+p.stderr}),p=await ue(this.ctx,p,t.redirections),y)throw y;if(f.length>0){let w=f[f.length-1];if((c==="declare"||c==="local"||c==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(w)){let S=w.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);S&&(w=S[1])}this.ctx.state.lastArg=w}else this.ctx.state.lastArg=c;let v=ul(c)&&c!=="unset"&&c!=="eval";if(!this.ctx.state.options.posix||!v)for(let[w,S]of n)this.ctx.state.fullyUnsetLocals?.has(w)||(S===void 0?this.ctx.state.env.delete(w):this.ctx.state.env.set(w,S));if(this.ctx.state.tempExportedVars)for(let w of n.keys())this.ctx.state.tempExportedVars.delete(w);return n.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(p={...p,stderr:this.ctx.state.expansionStderr+p.stderr},this.ctx.state.expansionStderr=""),p}async runCommand(t,s,r,n,i=!1,a=!1,l=-1){let o={ctx:this.ctx,runCommand:(c,f,d,h,m,p,y)=>this.runCommand(c,f,d,h,m,p,y),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(c,f,d)=>this.executeUserScript(c,f,d)},u=await ql(o,t,s,r,n,i,a,l);return u!==null?u:jl(o,t,s,n,a)}aliasExpansionStack=new Set;expandAlias(t){return mr(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return kn(this.ctx,t)}async executeSubshell(t,s=""){return ic(this.ctx,t,s,r=>this.executeStatement(r))}async executeGroup(t,s=""){return ac(this.ctx,t,s,r=>this.executeStatement(r))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await lt(this.ctx,t.redirections);if(s)return s;try{let r=await T(this.ctx,t.expression.expression),n=pe(r!==0);return this.ctx.state.expansionStderr&&(n={...n,stderr:this.ctx.state.expansionStderr+n.stderr},this.ctx.state.expansionStderr=""),ue(this.ctx,n,t.redirections)}catch(r){let n=N(`bash: arithmetic expression: ${r.message}
747
- `);return ue(this.ctx,n,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await lt(this.ctx,t.redirections);if(s)return s;try{let r=await xt(this.ctx,t.expression),n=pe(r);return this.ctx.state.expansionStderr&&(n={...n,stderr:this.ctx.state.expansionStderr+n.stderr},this.ctx.state.expansionStderr=""),ue(this.ctx,n,t.redirections)}catch(r){let n=r instanceof se?1:2,i=N(`bash: conditional expression: ${r.message}
748
- `,n);return ue(this.ctx,i,t.redirections)}}};var we={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,maxGlobOperations:1e5,maxStringLength:10485760,maxArrayElements:1e5,maxHeredocSize:10485760,maxSubstitutionDepth:50,maxBraceExpansionResults:1e4,maxOutputSize:10485760,maxFileDescriptors:1024,maxSourceDepth:100};function lc(e){return e?{maxCallDepth:e.maxCallDepth??we.maxCallDepth,maxCommandCount:e.maxCommandCount??we.maxCommandCount,maxLoopIterations:e.maxLoopIterations??we.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??we.maxAwkIterations,maxSedIterations:e.maxSedIterations??we.maxSedIterations,maxJqIterations:e.maxJqIterations??we.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??we.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??we.maxPythonTimeoutMs,maxJsTimeoutMs:e.maxJsTimeoutMs??we.maxJsTimeoutMs,maxGlobOperations:e.maxGlobOperations??we.maxGlobOperations,maxStringLength:e.maxStringLength??we.maxStringLength,maxArrayElements:e.maxArrayElements??we.maxArrayElements,maxHeredocSize:e.maxHeredocSize??we.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??we.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??we.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??we.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??we.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??we.maxSourceDepth}:{...we}}import{lookup as Td}from"node:dns";function $i(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function kd(e){let t=$i(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function cc(e){if(e.includes("\\"))return!0;let t=e.toLowerCase();return t.includes("%2f")||t.includes("%5c")}function Nd(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function Pi(e,t){let s=$i(e);if(!s)return!1;let r=kd(t);return!r||s.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&cc(s.pathname)?!1:Nd(s.pathname,r.pathPrefix)}function uc(e){return typeof e=="string"?e:e.url}function fc(e,t){return!t||t.length===0?!1:t.some(s=>Pi(e,uc(s)))}function ki(e){let t=_d(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let s=dc(t);if(s)return _n(s);let r=Cd(t);return r?Dd(r):!1}function _d(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function xd(e){if(!e)return null;let t=10,s=e;if(s.startsWith("0x")||s.startsWith("0X")?(t=16,s=s.slice(2)):s.length>1&&s.startsWith("0")&&(t=8),!s||t===16&&!/^[0-9a-fA-F]+$/.test(s)||t===10&&!/^\d+$/.test(s)||t===8&&!/^[0-7]+$/.test(s))return null;let r=Number.parseInt(s,t);return!Number.isFinite(r)||r<0?null:r}function dc(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let s=t.map(o=>xd(o));if(s.some(o=>o===null))return null;let r=s;if(t.length===1){let o=r[0];return o>4294967295?null:[o>>>24&255,o>>>16&255,o>>>8&255,o&255]}if(t.length===2){let[o,u]=r;return o>255||u>16777215?null:[o,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[o,u,c]=r;return o>255||u>255||c>65535?null:[o,u,c>>>8&255,c&255]}let[n,i,a,l]=r;return n>255||i>255||a>255||l>255?null:[n,i,a,l]}function Cd(e){let t=e,s=null;if(t.includes(".")){let p=t.lastIndexOf(":");if(p<0)return null;let y=t.slice(p+1),b=dc(y);if(!b)return null;s=b,t=t.slice(0,p)}let r=t.includes("::")?t.split("::").length-1:0;if(r>1)return null;let[n,i]=t.split("::"),a=n?n.split(":").filter(Boolean):[],l=i?i.split(":").filter(Boolean):[],o=p=>/^[0-9a-f]{1,4}$/i.test(p)?Number.parseInt(p,16):null,u=a.map(o),c=l.map(o);if(u.some(p=>p===null)||c.some(p=>p===null))return null;let f=s?2:0,d=u.length+c.length+f,h=0;if(r===1){if(h=8-d,h<0)return null}else if(d!==8)return null;let m=[...u,...new Array(h).fill(0),...c];return s&&(m.push(s[0]<<8|s[1]),m.push(s[2]<<8|s[3])),m.length===8?m:null}function _n(e){let[t,s]=e;return t===127||t===10||t===172&&s>=16&&s<=31||t===192&&s===168||t===169&&s===254||t===0||t===100&&s>=64&&s<=127||t===198&&(s===18||s===19)||t===192&&s===0&&e[2]===0||t===192&&s===0&&e[2]===2||t===198&&s===51&&e[2]===100||t===203&&s===0&&e[2]===113||t>=240}function Dd(e){if(e.every(n=>n===0)||e.slice(0,7).every(n=>n===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 n=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return _n(n)}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 n=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return _n(n)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let n=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return _n(n)}return!1}function hc(e){let t=[];for(let s of e){if(typeof s!="string"&&(s===null||typeof s!="object"||!("url"in s)||typeof s.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let r=uc(s);if(!$i(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!==""&&cc(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 Rd=typeof __BROWSER__<"u"&&__BROWSER__,es=null,xn=null,pc=!1;function Id(){if(es===null&&!Rd)try{let e=Fn("node:async_hooks");xn=Fn("node:dns"),es=new e.AsyncLocalStorage}catch{}}function Od(){if(pc||(Id(),!es||!xn))return;pc=!0;let e=es,t=xn.lookup;function s(...r){let n=r[0],i=e.getStore();if(typeof n!="string"||!i||i.hostname.toLowerCase()!==n.toLowerCase())return t.apply(this,r);let a={},l;if(r.length===2)l=r[1];else if(r.length>=3){let u=r[1];typeof u=="number"?a={family:u}:u&&typeof u=="object"&&(a=u),l=r[2]}if(typeof l!="function")return t.apply(this,r);let o=l;if(a.family!==void 0&&a.family!==0&&a.family!==i.family){let u=new Error(`ENOTFOUND ${n}`);u.code="ENOTFOUND",u.errno=-3008,u.syscall="getaddrinfo",u.hostname=n,process.nextTick(()=>o(u));return}process.nextTick(()=>{a.all?o(null,[{address:i.address,family:i.family}]):o(null,i.address,i.family)})}Object.defineProperty(xn,"lookup",{value:s,writable:!0,configurable:!0})}function mc(e,t){return Od(),es?es.run(e,t):t()}var Xe=class extends Error{constructor(t,s){let r=s??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},ts=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},ss=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Cn=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}},ns=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};function Ld(e){return new Promise((t,s)=>{Td(e,{all:!0},(r,n)=>{r?s(r):t(n)})})}var Md=20,Wd=3e4,Fd=10485760,Vd=["GET","HEAD"],zd=new Set(["GET","HEAD","OPTIONS"]),Bd=new Set([301,302,303,307,308]);function Ni(e){let t=e.allowedUrlPrefixes??[];if(!e.dangerouslyAllowFullInternetAccess){let h=hc(t);if(h.length>0)throw new Error(`Invalid network allow-list:
749
- ${h.join(`
750
- `)}`)}let s=[];for(let h of t)typeof h=="object"&&h.transform&&h.transform.length>0&&s.push(h);function r(h){if(s.length===0)return null;let m=null;for(let p of s)if(Pi(h,p.url)&&p.transform){m||(m=new Headers);for(let y of p.transform)for(let[b,v]of Object.entries(y.headers))m.set(b,v)}return m}let n=e.maxRedirects??Md,i=e.timeoutMs??Wd,a=e.maxResponseSize??Fd,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Vd,o=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),u=e._dnsResolve??Ld;async function c(h){if(!e.dangerouslyAllowFullInternetAccess&&!fc(h,t))throw new Xe(h);if(o)try{let m=new URL(h);if(ki(m.hostname))throw new Xe(h,"private/loopback IP address blocked");let p=m.hostname;if(/[a-zA-Z]/.test(p))try{let b=await u(p);for(let{address:E}of b)if(ki(E))throw new Xe(h,"hostname resolves to private/loopback IP address");let v=b[0];if(v)return{hostname:p,address:v.address,family:v.family===6?6:4}}catch(b){if(b instanceof Xe)throw b;let v=b?.code;if(!(v==="ENOTFOUND"||v==="ENODATA"))throw new Xe(h,"DNS resolution failed for private IP check")}}catch(m){if(m instanceof Xe)throw m}return null}function f(h){if(e.dangerouslyAllowFullInternetAccess)return;let m=h.toUpperCase();if(!l.includes(m))throw new Cn(m,l)}async function d(h,m={}){let p=m.method?.toUpperCase()??"GET",y=await c(h);f(p);let b=h,v=0,E=m.followRedirects??!0,w=m.timeoutMs!==void 0?Math.min(m.timeoutMs,i):i;for(;;){let S=new AbortController,A=ks(()=>S.abort(),w);try{let $=await Ie.runTrustedAsync(()=>{let R=r(b),C=qd(m.headers,R),F={method:p,headers:C,signal:S.signal,redirect:"manual"};return m.body&&!zd.has(p)&&(F.body=m.body),y?mc(y,()=>fetch(b,F)):fetch(b,F)});if(Bd.has($.status)&&E){let R=$.headers.get("location");if(!R)return await gc($,b,a);let C=new URL(R,b).href;try{y=await c(C)}catch{throw new ss(C)}if(v++,v>n)throw new ts(n);b=C;continue}return await gc($,b,a)}finally{Ns(A)}}}return d}function qd(e,t){if(!e&&!t)return;if(!t)return e;let s=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,n]of t)s.set(r,n);return s}async function gc(e,t,s){let r=Object.create(null);if(e.headers.forEach((i,a)=>{r[a.toLowerCase()]=i}),s>0){let i=e.headers.get("content-length");if(i){let a=parseInt(i,10);if(!Number.isNaN(a)&&a>s)throw new ns(s)}}let n;if(s>0&&e.body){let i=e.body.getReader(),a=[],l=0;for(;;){let{done:u,value:c}=await i.read();if(u)break;if(c){if(l+=c.byteLength,l>s)throw i.cancel(),new ns(s);a.push(c)}}n=new Uint8Array(l);let o=0;for(let u of a)n.set(u,o),o+=u.byteLength}else{let i=await e.arrayBuffer();if(s>0&&i.byteLength>s)throw new ns(s);n=new Uint8Array(i)}return{status:e.status,statusText:e.statusText,headers:r,body:n,url:t}}function $s(e){return Wt(e)}function Wt(e){return e.statements.map(yc).join(`
751
- `)}function yc(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(jd(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let s=t.join(" ");return e.background&&(s+=" &"),s}function jd(e){let t=[];e.timed&&t.push(e.timePosix?"time -p":"time"),e.negated&&t.push("!");let s=[];for(let n=0;n<e.commands.length;n++)if(s.push(wc(e.commands[n])),n<e.commands.length-1){let i=e.pipeStderr?.[n];s.push(i?"|&":"|")}return(t.length>0?`${t.join(" ")} `:"")+s.join(" ")}function wc(e){switch(e.type){case"SimpleCommand":return Ud(e);case"If":return eh(e);case"For":return th(e);case"CStyleFor":return sh(e);case"While":return nh(e);case"Until":return rh(e);case"Case":return ih(e);case"Subshell":return oh(e);case"Group":return lh(e);case"ArithmeticCommand":return ch(e);case"ConditionalCommand":return uh(e);case"FunctionDef":return fh(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function Ud(e){let t=[];for(let s of e.assignments)t.push(Zd(s));e.name&&t.push(be(e.name));for(let s of e.args)t.push(be(s));for(let s of e.redirections)t.push(vc(s));return t.join(" ")}function Zd(e){let t=e.append?"+=":"=";if(e.array){let s=e.array.map(be).join(" ");return`${e.name}${t}(${s})`}return e.value?`${e.name}${t}${be(e.value)}`:`${e.name}${t}`}function be(e){return e.parts.map(t=>Dn(t,!1)).join("")}function Dt(e){return e.parts.map(t=>Dn(t,!0)).join("")}function Dn(e,t){switch(e.type){case"Literal":return t?Hd(e.value):Gd(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(s=>Dn(s,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Ec(e);case"CommandSubstitution":return e.legacy?`\`${Wt(e.body)}\``:`$(${Wt(e.body)})`;case"ArithmeticExpansion":return`$((${ie(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${Wt(e.body)})`:`>(${Wt(e.body)})`;case"BraceExpansion":return Yd(e);case"TildeExpansion":return e.user!==null?`~${e.user}`:"~";case"Glob":return e.pattern;default:{let s=e;throw new Error(`Unsupported word part type: ${s.type}`)}}}function Gd(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function Hd(e){return e.replace(/[$`"\\]/g,"\\$&")}function Qd(e,t){return e.parts.map(s=>Kd(s,t)).join("")}function Kd(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Ec(e);case"CommandSubstitution":return e.legacy?`\`${Wt(e.body)}\``:`$(${Wt(e.body)})`;case"ArithmeticExpansion":return`$((${ie(e.expression.expression)}))`;default:return Dn(e,!1)}}function Ec(e){return e.operation?`\${${bc(e.parameter,e.operation)}}`:Xd(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function Xd(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function bc(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${Dt(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${Dt(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?Dt(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${Dt(t.word)}`;case"Substring":{let s=ie(t.offset.expression);return t.length?`${e}:${s}:${ie(t.length.expression)}`:`${e}:${s}`}case"PatternRemoval":{let s=t.side==="prefix"?"#":"%",r=t.greedy?`${s}${s}`:s;return`${e}${r}${Dt(t.pattern)}`}case"PatternReplacement":{let s="/";t.all?s="//":t.anchor==="start"?s="/#":t.anchor==="end"&&(s="/%");let r=t.replacement?`/${Dt(t.replacement)}`:"";return`${e}${s}${Dt(t.pattern)}${r}`}case"CaseModification":{let s=t.direction==="upper"?"^":",",r=t.all?`${s}${s}`:s,n=t.pattern?Dt(t.pattern):"";return`${e}${r}${n}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${bc(e,t.innerOp)}`:`!${e}`;case"ArrayKeys":return`!${t.array}[${t.star?"*":"@"}]`;case"VarNamePrefix":return`!${t.prefix}${t.star?"*":"@"}`;default:{let s=t;throw new Error(`Unsupported parameter operation type: ${s.type}`)}}}function Yd(e){return`{${e.items.map(Jd).join(",")}}`}function Jd(e){if(e.type==="Word")return be(e.word);let t=e.startStr??String(e.start),s=e.endStr??String(e.end);return e.step!==void 0?`${t}..${s}..${e.step}`:`${t}..${s}`}function vc(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let s=e.target,r=s.quoted?`'${s.delimiter}'`:s.delimiter,n=Qd(s.content,s.quoted);return`${t}${e.operator}${r}
752
- ${n}${s.delimiter}`}return e.operator==="<<<"?`${t}<<< ${be(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${be(e.target)}`:`${t}${e.operator} ${be(e.target)}`}function Ye(e){return e.length===0?"":` ${e.map(vc).join(" ")}`}function Ue(e){return e.map(yc).join(`
753
- `)}function eh(e){let t=[];for(let s=0;s<e.clauses.length;s++){let r=e.clauses[s],n=s===0?"if":"elif";t.push(`${n} ${Ue(r.condition)}; then
754
- ${Ue(r.body)}`)}return e.elseBody&&t.push(`else
755
- ${Ue(e.elseBody)}`),`${t.join(`
751
+ `,i={...i,stderr:i.stderr+S}}u&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=f),i=e.executionScope.accountResult(i,"pipeline");let{internalPipeStatusOverride:p,...m}=i;return m}function xa(e){return e?{...e,options:e.options?[...e.options]:void 0,actions:e.actions?[...e.actions]:void 0}:void 0}function Zh(e){return e?new Map(Array.from(e,([t,n])=>[t,xa(n)])):void 0}function Hh(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 Qh(e){return e?new Map(Array.from(e,([t,n])=>[t,n.map(r=>({...r}))])):void 0}function Pa(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,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,bashPid:e.bashPid,expansionExitCode:e.expansionExitCode,expansionStderr:e.expansionStderr};e.env=new Map(e.env),e.arrays=pt(e.arrays),e.options={...e.options},e.shoptOptions={...e.shoptOptions},e.fileDescriptors=e.fileDescriptors?new Map(e.fileDescriptors):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=Hh(e.localArrayScopes),e.localVarDepth=e.localVarDepth?new Map(e.localVarDepth):void 0,e.localVarStack=Qh(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=Zh(e.completionSpecs),e.defaultCompletionSpec=xa(e.defaultCompletionSpec),e.emptyCompletionSpec=xa(e.emptyCompletionSpec);let n=!1;return()=>{n||(n=!0,Object.assign(e,t))}}async function Su(e,t,n,r){let s=await ft(e,t.redirections);if(s.error)return s.error;let i=e.state.loopDepth,a=Pa(e.state);e.state.parentHasLoopContext=i>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,n&&(e.state.groupStdin=n);let o=new Lt(e.executionScope,"subshell"),l=0;try{for(let u of t.body){let f=await r(u);o.appendResult(f),l=f.exitCode}}catch(u){if(a(),u instanceof P)throw o.prependTo(u),u;if(u instanceof Ot){o.append("stdout",u.stdout,u.internalOutputAccounting.stdout),o.append("stderr",u.stderr,u.internalOutputAccounting.stderr);let d=o.build(0);return me(e,d,t.redirections,s.targets)}if(u instanceof Ze||u instanceof He){o.append("stdout",u.stdout,u.internalOutputAccounting.stdout),o.append("stderr",u.stderr,u.internalOutputAccounting.stderr);let d=o.build(0);return me(e,d,t.redirections,s.targets)}if(u instanceof H){o.append("stdout",u.stdout,u.internalOutputAccounting.stdout),o.append("stderr",u.stderr,u.internalOutputAccounting.stderr);let d=o.build(u.exitCode);return me(e,d,t.redirections,s.targets)}if(u instanceof Me){o.append("stdout",u.stdout,u.internalOutputAccounting.stdout),o.append("stderr",u.stderr,u.internalOutputAccounting.stderr);let d=o.build(u.exitCode);return me(e,d,t.redirections,s.targets)}if(u instanceof et){o.append("stdout",u.stdout,u.internalOutputAccounting.stdout),o.append("stderr",u.stderr,u.internalOutputAccounting.stderr);let d=o.build(u.exitCode);return me(e,d,t.redirections,s.targets)}o.append("stderr",`${St(u)}
752
+ `);let f=o.build(1);return me(e,f,t.redirections,s.targets)}a();let c=o.build(l);return me(e,c,t.redirections,s.targets)}async function vu(e,t,n,r){let s=new Lt(e.executionScope,"group"),i=0,a=await ft(e,t.redirections);if(a.error)return a.error;let o=await fs(e,t.redirections,a.targets);if(o)return o;let l=n;for(let f of t.redirections)if((f.operator==="<<"||f.operator==="<<-")&&f.target.type==="HereDoc"){let d=f.target,h=await z(e,d.content);d.stripTabs&&(h=h.split(`
753
+ `).map(m=>m.replace(/^\t+/,"")).join(`
754
+ `));let p=f.fd??0;p!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),je(e),e.state.fileDescriptors.set(p,h)):l=h}else if(f.operator==="<<<"&&f.target.type==="Word")l=`${a.targets.get(t.redirections.indexOf(f))??""}
755
+ `;else if(f.operator==="<"&&f.target.type==="Word")try{let d=a.targets.get(t.redirections.indexOf(f))??"",h=e.fs.resolvePath(e.state.cwd,d);l=await e.fs.readFile(h)}catch{let d=a.targets.get(t.redirections.indexOf(f))??"";return I("",`bash: ${d}: No such file or directory
756
+ `,1)}let c=e.state.groupStdin;l&&(e.state.groupStdin=l);try{for(let f of t.body){let d=await r(f);s.appendResult(d),i=d.exitCode}}catch(f){if(e.state.groupStdin=c,f instanceof P)throw s.prependTo(f),f;if(wr(f)||f instanceof et||f instanceof H)throw f.prependOutput(s.stdout,s.stderr),f;return s.append("stderr",`${St(f)}
757
+ `),s.build(1)}e.state.groupStdin=c;let u=s.build(i);return me(e,u,t.redirections,a.targets)}async function Au(e,t,n,r,s){let i;try{i=await e.fs.readFile(t)}catch{return R(`bash: ${t}: No such file or directory
758
+ `,127)}if(i.startsWith("#!")){let l=i.indexOf(`
759
+ `);l!==-1&&(i=i.slice(l+1))}let a=e.state.loopDepth,o=Pa(e.state);e.state.parentHasLoopContext=a>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 U().parse(i),u=await s(c);return o(),u}catch(l){if(o(),l instanceof H)return I(l.stdout,l.stderr,l.exitCode);if(l instanceof P)throw l;if(l.name==="ParseException")return R(`bash: ${t}: ${l.message}
760
+ `);throw l}}var lr=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||Ie.isInSandboxedContext())return;let n=`interpreter ${t} attempted outside defense context`;throw new Ct(n,{timestamp:Date.now(),type:"missing_defense_context",message:n,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:Ie.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 a=this.ctx.state.env.get(i);a!==void 0&&(s[i]=a)}return s}async executeScript(t){this.assertDefenseContext("execution");let n=0,r=new Lt(this.ctx.executionScope,"script");for(let s of t.statements)try{let i=await this.executeStatement(s);r.appendResult(i,Ts(i)),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(i){if(i instanceof H)throw i.prependOutput(r.stdout,r.stderr),i;if(i instanceof tt)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Tt(this.ctx.state.env)};if(i instanceof P)throw r.prependTo(i),i;if(i instanceof et)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Tt(this.ctx.state.env)};if(i instanceof Be)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Tt(this.ctx.state.env)};if(i instanceof Qe)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:Tt(this.ctx.state.env)};if(i instanceof oe){r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(i instanceof gr){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 Ze||i instanceof He){if(this.ctx.state.loopDepth>0)throw i.prependOutput(r.stdout,r.stderr),i;r.append("stdout",i.stdout),r.append("stderr",i.stderr);continue}throw i instanceof Me&&i.prependOutput(r.stdout,r.stderr),i}return{...r.build(n),env:Tt(this.ctx.state.env)}}async executeUserScript(t,n,r=""){return Au(this.ctx,t,n,r,s=>this.executeScript(s))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new We;if(t.deferredError)throw new xe(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return ne;this.ctx.state.errexitSafe=!1;let n=new Lt(this.ctx.executionScope,"statement");this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&n.append("stderr",`${t.sourceText}
761
+ `);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,Ts(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 a=s<t.pipelines.length-1,o=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=a||i||o,this.ctx.state.options.errexit&&r!==0&&s===t.pipelines.length-1&&!i&&!this.ctx.state.inCondition&&!o){let l=new et(r);throw l.prependOutput(n.stdout,n.stderr),l}return n.build(r)}async executePipeline(t){return bu(this.ctx,t,(n,r)=>this.executeCommand(n,r))}async executeCommand(t,n){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,n);case"If":return hu(this.ctx,t);case"For":return pu(this.ctx,t);case"CStyleFor":return mu(this.ctx,t);case"While":return yu(this.ctx,t,n);case"Until":return gu(this.ctx,t);case"Case":return wu(this.ctx,t);case"Subshell":return this.executeSubshell(t,n);case"Group":return this.executeGroup(t,n);case"FunctionDef":return $c(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return ne}}async executeSimpleCommand(t,n){try{return await this.executeSimpleCommandInner(t,n)}catch(r){if(r instanceof Rt)return R(r.stderr);throw r}}async executeSimpleCommandInner(t,n){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let A=t,v=0;for(;;){let x=this.expandAlias(A);if(x===A)break;if(v>=this.ctx.limits.maxCallDepth)throw new P(`alias expansion depth limit exceeded (${this.ctx.limits.maxCallDepth})`,"recursion");v++,A=x}this.aliasExpansionStack.clear(),A!==t&&(t=A)}this.ctx.state.expansionStderr="";let r=await ru(this.ctx,t);if(r.error)return r.error;let s=r.tempAssignments,i=r.xtraceOutput;if(!t.name){if(t.redirections.length>0){let v=await ft(this.ctx,t.redirections);if(v.error)return v.error;let x=I("",i,0);return me(this.ctx,x,t.redirections,v.targets)}this.ctx.state.lastArg="";let A=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",I("",A,this.ctx.state.lastExitCode)}let a=t.name&&Aa(t.name,["local","declare","typeset","export","readonly"]),o=Array.from(s.keys());if(o.length>0&&!a){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let A of o)this.ctx.state.tempExportedVars.add(A)}let l=await fs(this.ctx,t.redirections);if(l){for(let[A,v]of s)v===void 0?this.ctx.state.env.delete(A):this.ctx.state.env.set(A,v);return l}let c=-1;for(let A of t.redirections){if((A.operator==="<<"||A.operator==="<<-")&&A.target.type==="HereDoc"){let v=A.target,x=await z(this.ctx,v.content);v.stripTabs&&(x=x.split(`
762
+ `).map(D=>D.replace(/^\t+/,"")).join(`
763
+ `)),x=Dt(x);let N=A.fd??0;N!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),je(this.ctx),this.ctx.state.fileDescriptors.set(N,x)):n=x;continue}if(A.operator==="<<<"&&A.target.type==="Word"){n=Dt(`${await z(this.ctx,A.target)}
764
+ `);continue}if(A.operator==="<"&&A.target.type==="Word")try{let v=await z(this.ctx,A.target),x=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);n=await mr(this.ctx.fs,x)}catch{let v=await z(this.ctx,A.target);for(let[x,N]of s)N===void 0?this.ctx.state.env.delete(x):this.ctx.state.env.set(x,N);return R(`bash: ${v}: No such file or directory
765
+ `)}if(A.operator==="<&"&&A.target.type==="Word"){let v=await z(this.ctx,A.target),x=Number.parseInt(v,10);if(!Number.isNaN(x)&&this.ctx.state.fileDescriptors){let N=this.ctx.state.fileDescriptors.get(x);if(N!==void 0)if(N.startsWith("__rw__:")){let D=Eu(N);D&&(n=D.content.slice(D.position),c=x)}else N.startsWith("__file__:")||N.startsWith("__file_append__:")||(n=N)}}}let u=await z(this.ctx,t.name),f=[],d=[],h=(A,v)=>{if(f.length>=this.ctx.limits.maxArrayElements)throw new P(`expanded argument element limit exceeded (${this.ctx.limits.maxArrayElements})`,"array_elements");f.push(A),d.push(v)};if(Aa(t.name,["local","declare","typeset","export","readonly"])&&(u==="local"||u==="declare"||u==="typeset"||u==="export"||u==="readonly"))for(let A of t.args){let v=await uc(this.ctx,A);if(v)h(v,!0);else{let x=await fc(this.ctx,A);if(x!==null)h(x,!0);else{let N=await ut(this.ctx,A);for(let D of N.values)h(D,N.quoted)}}}else for(let A of t.args){let v=await ut(this.ctx,A);for(let x of v.values)h(x,v.quoted)}if(!u){if(t.name.parts.every(v=>v.type==="CommandSubstitution"||v.type==="ParameterExpansion"||v.type==="ArithmeticExpansion")){if(f.length>0){let v=f.shift();return d.shift(),await this.runCommand(v,f,d,n,!1,!1,c)}return I("","",this.ctx.state.lastExitCode)}return R(`bash: : command not found
766
+ `,127)}if(u==="exec"&&(f.length===0||f[0]==="--")){for(let A of t.redirections){if(A.target.type==="HereDoc"||A.fdVariable)continue;let v=await z(this.ctx,A.target),x=A.fd??(A.operator==="<"||A.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),A.operator){case">":case">|":{let N=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);await this.ctx.fs.writeFile(N,"","utf8"),je(this.ctx),this.ctx.state.fileDescriptors.set(x,`__file__:${N}`);break}case">>":{let N=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);je(this.ctx),this.ctx.state.fileDescriptors.set(x,`__file_append__:${N}`);break}case"<":{let N=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);try{let D=await this.ctx.fs.readFile(N);je(this.ctx),this.ctx.state.fileDescriptors.set(x,D)}catch{return R(`bash: ${v}: No such file or directory
767
+ `)}break}case"<>":{let N=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);try{let D=await this.ctx.fs.readFile(N);je(this.ctx),this.ctx.state.fileDescriptors.set(x,`__rw__:${N.length}:${N}:0:${D}`)}catch{await this.ctx.fs.writeFile(N,"","utf8"),je(this.ctx),this.ctx.state.fileDescriptors.set(x,`__rw__:${N.length}:${N}:0:`)}break}case">&":{if(v==="-")this.ctx.state.fileDescriptors.delete(x);else if(v.endsWith("-")){let N=v.slice(0,-1),D=Number.parseInt(N,10);if(!Number.isNaN(D)){let O=this.ctx.state.fileDescriptors.get(D);O!==void 0?this.ctx.state.fileDescriptors.set(x,O):this.ctx.state.fileDescriptors.set(x,`__dupout__:${D}`),this.ctx.state.fileDescriptors.delete(D)}}else{let N=Number.parseInt(v,10);Number.isNaN(N)||(je(this.ctx),this.ctx.state.fileDescriptors.set(x,`__dupout__:${N}`))}break}case"<&":{if(v==="-")this.ctx.state.fileDescriptors.delete(x);else if(v.endsWith("-")){let N=v.slice(0,-1),D=Number.parseInt(N,10);if(!Number.isNaN(D)){let O=this.ctx.state.fileDescriptors.get(D);O!==void 0?this.ctx.state.fileDescriptors.set(x,O):this.ctx.state.fileDescriptors.set(x,`__dupin__:${D}`),this.ctx.state.fileDescriptors.delete(D)}}else{let N=Number.parseInt(v,10);Number.isNaN(N)||(je(this.ctx),this.ctx.state.fileDescriptors.set(x,`__dupin__:${N}`))}break}}}for(let[A,v]of s)v===void 0?this.ctx.state.env.delete(A):this.ctx.state.env.set(A,v);if(this.ctx.state.tempExportedVars)for(let A of s.keys())this.ctx.state.tempExportedVars.delete(A);return ne}if(this.ctx.state.extraArgs){let A=this.ctx.state.extraArgs;this.ctx.state.extraArgs=void 0;for(let v of A)h(v,!0)}let m=await tu(this.ctx,u,f);s.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(s)));let E,b=null;try{E=await this.runCommand(u,f,d,n,!1,!1,c)}catch(A){if(A instanceof Ze||A instanceof He)b=A,E=ne;else throw A}let g=i+m;if(g&&(E={...E,stderr:g+E.stderr}),E=await me(this.ctx,E,t.redirections),b)throw b;if(f.length>0){let A=f[f.length-1];if((u==="declare"||u==="local"||u==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(A)){let v=A.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);v&&(A=v[1])}this.ctx.state.lastArg=A}else this.ctx.state.lastArg=u;let w=Pc(u)&&u!=="unset"&&u!=="eval";if(!this.ctx.state.options.posix||!w)for(let[A,v]of s)this.ctx.state.fullyUnsetLocals?.has(A)||(v===void 0?this.ctx.state.env.delete(A):this.ctx.state.env.set(A,v));if(this.ctx.state.tempExportedVars)for(let A of s.keys())this.ctx.state.tempExportedVars.delete(A);return s.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(E={...E,stderr:this.ctx.state.expansionStderr+E.stderr},this.ctx.state.expansionStderr=""),E}async runCommand(t,n,r,s,i=!1,a=!1,o=-1){let l={ctx:this.ctx,runCommand:(u,f,d,h,p,m,E)=>this.runCommand(u,f,d,h,p,m,E),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(u,f,d)=>this.executeUserScript(u,f,d)},c=await fu(l,t,n,r,s,i,a,o);return c!==null?c:du(l,t,n,s,a)}aliasExpansionStack=new Set;expandAlias(t){return zo({env:this.ctx.state.env,limits:this.ctx.limits},t,this.aliasExpansionStack)}async findCommandInPath(t){return Es(this.ctx,t)}async executeSubshell(t,n=""){return Su(this.ctx,t,n,r=>this.executeStatement(r))}async executeGroup(t,n=""){return vu(this.ctx,t,n,r=>this.executeStatement(r))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let n=await ft(this.ctx,t.redirections);if(n.error)return n.error;try{let r=await K(this.ctx,t.expression.expression),s=we(r!==0);return this.ctx.state.expansionStderr&&(s={...s,stderr:this.ctx.state.expansionStderr+s.stderr},this.ctx.state.expansionStderr=""),me(this.ctx,s,t.redirections,n.targets)}catch(r){let s=R(`bash: arithmetic expression: ${r.message}
768
+ `);return me(this.ctx,s,t.redirections,n.targets)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let n=await ft(this.ctx,t.redirections);if(n.error)return n.error;try{let r=await Zt(this.ctx,t.expression),s=we(r);return this.ctx.state.expansionStderr&&(s={...s,stderr:this.ctx.state.expansionStderr+s.stderr},this.ctx.state.expansionStderr=""),me(this.ctx,s,t.redirections,n.targets)}catch(r){let s=r instanceof oe?1:2,i=R(`bash: conditional expression: ${r.message}
769
+ `,s);return me(this.ctx,i,t.redirections,n.targets)}}};import{lookup as ap}from"node:dns";function $a(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function Kh(e){let t=$a(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var Xh=3;function xu(e){let t=e;for(let n=0;n<Xh;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 Yh(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function ka(e,t){let n=$a(e);if(!n)return!1;let r=Kh(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&xu(n.pathname)?!1:Yh(n.pathname,r.pathPrefix)}function Pu(e){return typeof e=="string"?e:e.url}function $u(e,t){return!t||t.length===0?!1:t.some(n=>ka(e,Pu(n)))}function Na(e){let t=Jh(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=ku(t);if(n)return Ss(n);let r=tp(t);return r?np(r):!1}function Jh(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function ep(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 ku(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>ep(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,a,o]=r;return s>255||i>255||a>255||o>255?null:[s,i,a,o]}function tp(e){let t=e,n=null;if(t.includes(".")){let m=t.lastIndexOf(":");if(m<0)return null;let E=t.slice(m+1),b=ku(E);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("::"),a=s?s.split(":").filter(Boolean):[],o=i?i.split(":").filter(Boolean):[],l=m=>/^[0-9a-f]{1,4}$/i.test(m)?Number.parseInt(m,16):null,c=a.map(l),u=o.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 Ss(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 np(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 Ss(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 Ss(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 Ss(s)}return!1}function Nu(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=Pu(n);if(!$a(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!==""&&xu(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 rp=typeof __BROWSER__<"u"&&__BROWSER__,Xt=class extends Error{constructor(){super("DNS pinning is unavailable in this runtime"),this.name="DnsPinningUnavailableError"}};function sp(e){let t=new Error(`ENOTFOUND ${e}`);return t.code="ENOTFOUND",t.errno=-3008,t.syscall="getaddrinfo",t.hostname=e,t}function ip(e){return(t,n,r)=>{let s=n.family==="IPv4"?4:n.family==="IPv6"?6:n.family;if(t.toLowerCase()!==e.hostname.toLowerCase()||s!==void 0&&s!==0&&s!==e.family){r(sp(t),"");return}n.all?r(null,[{address:e.address,family:e.family}]):r(null,e.address,e.family)}}var Cu=async e=>{if(rp)throw new Xt;try{let t=await import("./chunks/undici-HCLAUJT3.js"),n=new t.Agent({connections:1,pipelining:0,connect:{lookup:ip(e)}}),r=!1;return{async fetch(s,i){if(r)throw new Xt;let a=t.fetch;return await a(s,{...i,dispatcher:n})},async close(){r||(r=!0,await n.destroy())}}}catch(t){throw t instanceof Xt?t:new Xt}};var Je=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},Nn=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},Cn=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},vs=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"}};function op(e){return new Promise((t,n)=>{ap(e,{all:!0},(r,s)=>{r?n(r):t(s)})})}var lp=20,cp=3e4,up=10485760,fp=["GET","HEAD"],dp=new Set(["GET","HEAD","OPTIONS"]),hp=new Set([301,302,303,307,308]);function Rn(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function Du(e){if(e?.aborted)throw Rn(e)}async function Yt(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),Rn(t);let n,r=new Promise((s,i)=>{n=()=>i(Rn(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function pp(e,t){try{return await Yt(e,t)}catch(n){throw t?.aborted&&e.then(r=>Ie.runTrustedAsync(()=>r.close())).catch(()=>{}),n}}async function mp(e){e.body&&!e.body.locked&&await e.body.cancel()}function Ca(e){let t=e.allowedUrlPrefixes??[];if(!e.dangerouslyAllowFullInternetAccess){let E=Nu(t);if(E.length>0)throw new Error(`Invalid network allow-list:
770
+ ${E.join(`
771
+ `)}`)}let n=[];for(let E of t)typeof E=="object"&&E.transform&&E.transform.length>0&&n.push(E);function r(E){if(n.length===0)return null;let b=null;for(let g of n)if(ka(E,g.url)&&g.transform){b||(b=new Headers);for(let w of g.transform)for(let[S,A]of Object.entries(w.headers))b.set(S,A)}return b}if(e.maxRedirects!==void 0&&(!Number.isSafeInteger(e.maxRedirects)||e.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let s=e.maxRedirects??lp,i=e.timeoutMs??cp,a=e.maxResponseSize??up,o=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??fp,l=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),c=e._dnsResolve??op,u=e._createConnectionOwner??Cu;function f(E){let b=E.startsWith("[")&&E.endsWith("]")?E.slice(1,-1):E;if(/^(?:0|[1-9]\d{0,2})(?:\.(?:0|[1-9]\d{0,2})){3}$/.test(b)&&b.split(".").every(w=>Number(w)<=255))return 4;if(b.includes(":")&&!b.includes("%"))try{if(new URL(`http://[${b}]/`).hostname.length>2)return 6}catch{}return null}function d(E,b,g){let{address:w,family:S}=g;if(f(w)!==S)throw new Je(E,"DNS returned an invalid address for private IP check");return{hostname:b,address:w,family:S}}async function h(E,b){if(Du(b),!e.dangerouslyAllowFullInternetAccess&&!$u(E,t))throw new Je(E);if(!l)return null;let g;try{g=new URL(E)}catch{throw new Je(E,"invalid URL")}if(Na(g.hostname))throw new Je(E,"private/loopback IP address blocked");let w=g.hostname;if(f(w)!==null)return null;let S;try{S=await Yt(c(w),b)}catch{throw b?.aborted?Rn(b):new Je(E,"DNS resolution failed for private IP check")}if(!Array.isArray(S)||S.length===0)throw new Je(E,"DNS resolution returned no addresses for private IP check");let A=S.map(v=>d(E,w,v));for(let{address:v}of A)if(Na(v))throw new Je(E,"hostname resolves to private/loopback IP address");return A[0]}function p(E){if(e.dangerouslyAllowFullInternetAccess)return;let b=E.toUpperCase();if(!o.includes(b))throw new vs(b,o)}async function m(E,b={}){let g=b.method?.toUpperCase()??"GET",w=b.followRedirects??!0;if(b.maxRedirects!==void 0&&(!Number.isSafeInteger(b.maxRedirects)||b.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let S=b.maxRedirects??s,A=Math.min(s,S),v=b.timeoutMs!==void 0?Math.min(b.timeoutMs,i):i,x=new AbortController,N=dr(()=>x.abort(new DOMException("The operation was aborted","AbortError")),v),D=pr(b.signal,x.signal);try{let O=await h(E,D.signal);p(g);let _=E,V=0;for(;;){Du(D.signal);let J;try{let ee=await Ie.runTrustedAsync(async()=>{let C=r(_),$=yp(b.headers,C),k={method:g,headers:$,signal:D.signal,redirect:"manual"};if(b.body&&!dp.has(g)&&(k.body=b.body),!O)return await Yt(fetch(_,k),D.signal);try{return J=await pp(u(O),D.signal),await Yt(J.fetch(_,k),D.signal)}catch(W){throw W instanceof Xt?new Je(_,"DNS pinning unavailable for private IP enforcement"):W}});if(hp.has(ee.status)&&w){let C=ee.headers.get("location");if(!C)return await Ru(ee,_,a,D.signal);let $=new URL(C,_).href;await Yt(mp(ee),D.signal);try{O=await h($,D.signal)}catch{throw D.signal?.aborted?Rn(D.signal):new Cn($)}if(V++,V>A)throw new Nn(A);_=$;continue}return await Ru(ee,_,a,D.signal)}finally{if(J){let ee=J,C=Ie.runTrustedAsync(()=>ee.close());await Yt(C,D.signal)}}}}finally{hr(N),D.cleanup()}}return m}function yp(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}async function Ru(e,t,n,r){let s=Object.create(null);if(e.headers.forEach((a,o)=>{s[o.toLowerCase()]=a}),n>0){let a=e.headers.get("content-length");if(a){let o=parseInt(a,10);if(!Number.isNaN(o)&&o>n)throw new Dn(n)}}let i;if(n>0&&e.body){let a=e.body.getReader(),o=[],l=0;try{for(;;){let{done:u,value:f}=await Yt(a.read(),r);if(u)break;if(f){if(l+=f.byteLength,l>n)throw await a.cancel(),new Dn(n);o.push(f)}}}catch(u){throw r?.aborted&&await a.cancel(Rn(r)).catch(()=>{}),u}i=new Uint8Array(l);let c=0;for(let u of o)i.set(u,c),c+=u.byteLength}else{let a=await Yt(e.arrayBuffer(),r);if(n>0&&a.byteLength>n)throw new Dn(n);i=new Uint8Array(a)}return{status:e.status,statusText:e.statusText,headers:s,body:i,url:t}}function cr(e,t){if(e.length>t||M(e)>t)throw new P(`script input size limit exceeded (${t} bytes)`,"string_length")}function ur(e){return un(e)}function un(e){return e.statements.map(Ou).join(`
772
+ `)}function Ou(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(gp(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let n=t.join(" ");return e.background&&(n+=" &"),n}function gp(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(Iu(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 Iu(e){switch(e.type){case"SimpleCommand":return wp(e);case"If":return kp(e);case"For":return Np(e);case"CStyleFor":return Cp(e);case"While":return Dp(e);case"Until":return Rp(e);case"Case":return Op(e);case"Subshell":return _p(e);case"Group":return Tp(e);case"ArithmeticCommand":return Lp(e);case"ConditionalCommand":return Mp(e);case"FunctionDef":return Bp(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function wp(e){let t=[];for(let n of e.assignments)t.push(Ep(n));e.name&&t.push($e(e.name));for(let n of e.args)t.push($e(n));for(let n of e.redirections)t.push(Lu(n));return t.join(" ")}function Ep(e){let t=e.append?"+=":"=";if(e.array){let n=e.array.map($e).join(" ");return`${e.name}${t}(${n})`}return e.value?`${e.name}${t}${$e(e.value)}`:`${e.name}${t}`}function $e(e){return e.parts.map(t=>As(t,!1)).join("")}function Jt(e){return e.parts.map(t=>As(t,!0)).join("")}function As(e,t){switch(e.type){case"Literal":return t?Sp(e.value):bp(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(n=>As(n,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return _u(e);case"CommandSubstitution":return e.legacy?`\`${un(e.body)}\``:`$(${un(e.body)})`;case"ArithmeticExpansion":return`$((${fe(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${un(e.body)})`:`>(${un(e.body)})`;case"BraceExpansion":return Pp(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 bp(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function Sp(e){return e.replace(/[$`"\\]/g,"\\$&")}function vp(e,t){return e.parts.map(n=>Ap(n,t)).join("")}function Ap(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return _u(e);case"CommandSubstitution":return e.legacy?`\`${un(e.body)}\``:`$(${un(e.body)})`;case"ArithmeticExpansion":return`$((${fe(e.expression.expression)}))`;default:return As(e,!1)}}function _u(e){return e.operation?`\${${Tu(e.parameter,e.operation)}}`:xp(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function xp(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function Tu(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${Jt(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${Jt(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?Jt(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${Jt(t.word)}`;case"Substring":{let n=fe(t.offset.expression);return t.length?`${e}:${n}:${fe(t.length.expression)}`:`${e}:${n}`}case"PatternRemoval":{let n=t.side==="prefix"?"#":"%",r=t.greedy?`${n}${n}`:n;return`${e}${r}${Jt(t.pattern)}`}case"PatternReplacement":{let n="/";t.all?n="//":t.anchor==="start"?n="/#":t.anchor==="end"&&(n="/%");let r=t.replacement?`/${Jt(t.replacement)}`:"";return`${e}${n}${Jt(t.pattern)}${r}`}case"CaseModification":{let n=t.direction==="upper"?"^":",",r=t.all?`${n}${n}`:n,s=t.pattern?Jt(t.pattern):"";return`${e}${r}${s}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${Tu(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 Pp(e){return`{${e.items.map($p).join(",")}}`}function $p(e){if(e.type==="Word")return $e(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 Lu(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let n=e.target,r=n.quoted?`'${n.delimiter}'`:n.delimiter,s=vp(n.content,n.quoted);return`${t}${e.operator}${r}
773
+ ${s}${n.delimiter}`}return e.operator==="<<<"?`${t}<<< ${$e(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${$e(e.target)}`:`${t}${e.operator} ${$e(e.target)}`}function dt(e){return e.length===0?"":` ${e.map(Lu).join(" ")}`}function st(e){return e.map(Ou).join(`
774
+ `)}function kp(e){let t=[];for(let n=0;n<e.clauses.length;n++){let r=e.clauses[n],s=n===0?"if":"elif";t.push(`${s} ${st(r.condition)}; then
775
+ ${st(r.body)}`)}return e.elseBody&&t.push(`else
776
+ ${st(e.elseBody)}`),`${t.join(`
756
777
  `)}
757
- fi${Ye(e.redirections)}`}function th(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let s=e.words.map(be).join(" ");t=`for ${e.variable} in ${s}`}return`${t}; do
758
- ${Ue(e.body)}
759
- done${Ye(e.redirections)}`}function sh(e){let t=e.init?ie(e.init.expression):"",s=e.condition?ie(e.condition.expression):"",r=e.update?ie(e.update.expression):"";return`for ((${t}; ${s}; ${r})); do
760
- ${Ue(e.body)}
761
- done${Ye(e.redirections)}`}function nh(e){return`while ${Ue(e.condition)}; do
762
- ${Ue(e.body)}
763
- done${Ye(e.redirections)}`}function rh(e){return`until ${Ue(e.condition)}; do
764
- ${Ue(e.body)}
765
- done${Ye(e.redirections)}`}function ih(e){let t=e.items.map(ah).join(`
766
- `);return`case ${be(e.word)} in
778
+ fi${dt(e.redirections)}`}function Np(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let n=e.words.map($e).join(" ");t=`for ${e.variable} in ${n}`}return`${t}; do
779
+ ${st(e.body)}
780
+ done${dt(e.redirections)}`}function Cp(e){let t=e.init?fe(e.init.expression):"",n=e.condition?fe(e.condition.expression):"",r=e.update?fe(e.update.expression):"";return`for ((${t}; ${n}; ${r})); do
781
+ ${st(e.body)}
782
+ done${dt(e.redirections)}`}function Dp(e){return`while ${st(e.condition)}; do
783
+ ${st(e.body)}
784
+ done${dt(e.redirections)}`}function Rp(e){return`until ${st(e.condition)}; do
785
+ ${st(e.body)}
786
+ done${dt(e.redirections)}`}function Op(e){let t=e.items.map(Ip).join(`
787
+ `);return`case ${$e(e.word)} in
767
788
  ${t}
768
- esac${Ye(e.redirections)}`}function ah(e){let t=e.patterns.map(be).join(" | "),s=Ue(e.body);return s?`${t})
769
- ${s}
789
+ esac${dt(e.redirections)}`}function Ip(e){let t=e.patterns.map($e).join(" | "),n=st(e.body);return n?`${t})
790
+ ${n}
770
791
  ${e.terminator}`:`${t})
771
- ${e.terminator}`}function oh(e){return`(${Ue(e.body)})${Ye(e.redirections)}`}function lh(e){return`{ ${Ue(e.body)}; }${Ye(e.redirections)}`}function ch(e){return`((${ie(e.expression.expression)}))${Ye(e.redirections)}`}function uh(e){return`[[ ${Mt(e.expression)} ]]${Ye(e.redirections)}`}function fh(e){let t=wc(e.body);return`${e.name}() ${t}${Ye(e.redirections)}`}function ie(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`${ie(e.left)} ${e.operator} ${ie(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${ie(e.operand)}`:`${ie(e.operand)}${e.operator}`;case"ArithTernary":return`${ie(e.condition)} ? ${ie(e.consequent)} : ${ie(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${ie(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${ie(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${ie(e.target)}[${ie(e.subscript)}]`:ie(e.target)} ${e.operator} ${ie(e.value)}`;case"ArithDynamicElement":return`${ie(e.nameExpr)}[${ie(e.subscript)}]`;case"ArithGroup":return`(${ie(e.expression)})`;case"ArithNested":return`$((${ie(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}[${ie(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(ie).join("");case"ArithDoubleSubscript":return`${e.array}[${ie(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 Mt(e){switch(e.type){case"CondBinary":return`${be(e.left)} ${e.operator} ${be(e.right)}`;case"CondUnary":return`${e.operator} ${be(e.operand)}`;case"CondNot":return`! ${Mt(e.operand)}`;case"CondAnd":return`${Mt(e.left)} && ${Mt(e.right)}`;case"CondOr":return`${Mt(e.left)} || ${Mt(e.right)}`;case"CondGroup":return`( ${Mt(e.expression)} )`;case"CondWord":return be(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var Ps=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;invokeToolFn;transformPlugins=[];state;constructor(t={}){let s=t.fs??new ht(t.files);this.fs=s,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),n=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
772
- `],["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(this.limits=lc({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}}),t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=Ni(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:n,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,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",Un(this.state.options)),this.state.env.set("BASHOPTS",Zn(this.state.shoptOptions)),Bi(s,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&s instanceof ht)try{s.mkdirSync(r,{recursive:!0})}catch{}for(let a of Oi(t.commands))this.registerCommand(a);if(t.fetch||t.network)for(let a of Ti())this.registerCommand(a);if(t.python)for(let a of Li())this.registerCommand(a);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let a of Mi())this.registerCommand(a);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap),i.invokeTool&&(this.invokeToolFn=i.invokeTool)}if(t.customCommands)for(let a of t.customCommands)Wi(a)?this.registerCommand(Fi(a)):this.registerCommand({...a,trusted:a.trusted??!0})}registerCommand(t){this.commands.set(t.name,t);let s=this.fs;if(typeof s.writeFileSync=="function"){let r=`#!/bin/bash
792
+ ${e.terminator}`}function _p(e){return`(${st(e.body)})${dt(e.redirections)}`}function Tp(e){return`{ ${st(e.body)}; }${dt(e.redirections)}`}function Lp(e){return`((${fe(e.expression.expression)}))${dt(e.redirections)}`}function Mp(e){return`[[ ${cn(e.expression)} ]]${dt(e.redirections)}`}function Bp(e){let t=Iu(e.body);return`${e.name}() ${t}${dt(e.redirections)}`}function fe(e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return e.hasDollarPrefix?`$${e.name}`:e.name;case"ArithSpecialVar":return`$${e.name}`;case"ArithBinary":return`${fe(e.left)} ${e.operator} ${fe(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${fe(e.operand)}`:`${fe(e.operand)}${e.operator}`;case"ArithTernary":return`${fe(e.condition)} ? ${fe(e.consequent)} : ${fe(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${fe(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${fe(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${fe(e.target)}[${fe(e.subscript)}]`:fe(e.target)} ${e.operator} ${fe(e.value)}`;case"ArithDynamicElement":return`${fe(e.nameExpr)}[${fe(e.subscript)}]`;case"ArithGroup":return`(${fe(e.expression)})`;case"ArithNested":return`$((${fe(e.expression)}))`;case"ArithCommandSubst":return`$(${e.command})`;case"ArithBracedExpansion":return`\${${e.content}}`;case"ArithArrayElement":return e.stringKey!==void 0?`${e.array}[${e.stringKey}]`:e.index?`${e.array}[${fe(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(fe).join("");case"ArithDoubleSubscript":return`${e.array}[${fe(e.index)}]`;case"ArithNumberSubscript":return`${e.number}[${e.errorToken}]`;case"ArithSyntaxError":return e.errorToken;case"ArithSingleQuote":return`'${e.content}'`;default:{let t=e;throw new Error(`Unsupported arithmetic expression type: ${t.type}`)}}}function cn(e){switch(e.type){case"CondBinary":return`${$e(e.left)} ${e.operator} ${$e(e.right)}`;case"CondUnary":return`${e.operator} ${$e(e.operand)}`;case"CondNot":return`! ${cn(e.operand)}`;case"CondAnd":return`${cn(e.left)} && ${cn(e.right)}`;case"CondOr":return`${cn(e.left)} || ${cn(e.right)}`;case"CondGroup":return`( ${cn(e.expression)} )`;case"CondWord":return $e(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var fr=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;invokeToolFn;transformPlugins=[];state;constructor(t={}){this.limits=Ar({...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 $t(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",`
793
+ `],["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=Ca(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,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",Vs(this.state.options)),this.state.env.set("BASHOPTS",zs(this.state.shoptOptions)),Ja(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&n instanceof $t)try{n.mkdirSync(r,{recursive:!0})}catch{}for(let a of Ba(t.commands))this.registerBundledCommand(a);if(t.fetch||t.network)for(let a of Wa())this.registerBundledCommand(a);if(t.python)for(let a of Fa())this.registerBundledCommand(a);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let a of Va())this.registerBundledCommand(a);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap),i.invokeTool&&(this.invokeToolFn=i.invokeTool)}if(t.customCommands)for(let a of t.customCommands)if(Ga(a)){let o=Za(a);this.registerCommandInternal(o,!0)}else this.registerCommandInternal(a,!0)}registerCommand(t){this.registerCommandInternal(t,!0)}registerBundledCommand(t){this.registerCommandInternal(t,!1)}registerCommandInternal(t,n,r=n?t.trusted??!0:t.trusted){this.commands.set(t.name,{name:t.name,trusted:r,internalIsExtension:n,execute:(i,a)=>t.execute(i,a)});let s=this.fs;if(typeof s.writeFileSync=="function"){let i=`#!/bin/bash
773
794
  # Built-in command: ${t.name}
774
- `;try{s.writeFileSync(`/bin/${t.name}`,r)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,r)}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=Ac(t.stdout),t.stderr=Ac(t.stderr),t}async exec(t,s){if(this.state.callDepth===0&&(this.state.commandCount=0),this.state.commandCount++,this.state.commandCount>this.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option.
775
- `,exitCode:1,env:qe(this.state.env,s?.env)};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:qe(this.state.env,s?.env)};this.logger?.info("exec",{command:t});let r=s?.cwd??this.state.cwd,n,i=r;if(s?.cwd)if(s.env&&"PWD"in s.env)n=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{n=await this.fs.realpath(r),i=n}catch{n=r}else n=r;let a=s?.replaceEnv?new Map:new Map(this.state.env);if(s?.env)for(let[f,d]of Object.entries(s.env))a.set(f,d);n!==void 0&&a.set("PWD",n);let l={...this.state,env:a,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:ph(s?.stdin,s?.stdinKind),signal:s?.signal,extraArgs:s?.args},o=t;s?.rawScript||(o=Sc(t));let u=this.defenseInDepthConfig?Ie.getInstance(this.defenseInDepthConfig):null,c=u?.activate();try{let f=async()=>{let d=Ce(o,{maxHeredocSize:this.limits.maxHeredocSize}),h;if(this.transformPlugins.length>0){let v=Object.create(null);for(let E of this.transformPlugins){let w=E.transform({ast:d,metadata:v});d=w.ast,w.metadata&&(v=cs(v,w.metadata))}h=v}let m={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:u?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},b=await new As(m,l).executeScript(d);return h&&(b.metadata=h),this.logResult(b)};return c?await c.run(f):await f()}catch(f){if(f instanceof Z)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:qe(this.state.env,s?.env)});if(f instanceof Be)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:qe(this.state.env,s?.env)});if(f instanceof se)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:1,env:qe(this.state.env,s?.env)});if(f instanceof Rs)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:qe(this.state.env,s?.env)});if(f instanceof X)return this.logResult({stdout:f.stdout,stderr:ut(f.stderr),exitCode:X.EXIT_CODE,env:qe(this.state.env,s?.env)});if(f instanceof gt)return this.logResult({stdout:"",stderr:`bash: security violation: ${ut(f.message)}
776
- `,exitCode:1,env:qe(this.state.env,s?.env)});if(f.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${ut(f.message)}
777
- `,exitCode:2,env:qe(this.state.env,s?.env)});if(f instanceof At)return this.logResult({stdout:"",stderr:`bash: ${ut(f.message)}
778
- `,exitCode:2,env:qe(this.state.env,s?.env)});if(f instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${ut(f.message)}
779
- `,exitCode:1,env:qe(this.state.env,s?.env)});throw f}finally{c?.deactivate()}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,s){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),s)}getCwd(){return this.state.cwd}getEnv(){return bt(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){let s=Sc(t),r=Ce(s,{maxHeredocSize:this.limits.maxHeredocSize}),n=Object.create(null);for(let i of this.transformPlugins){let a=i.transform({ast:r,metadata:n});r=a.ast,a.metadata&&(n=cs(n,a.metadata))}return{script:$s(r),ast:r,metadata:n}}};function dh(e,t){let s=t;for(let r=0;r<e.length;r++){let n=e[r];if(s==="single")n==="'"&&(s="none");else if(s==="double")n==="\\"?r++:n==='"'&&(s="none");else if(n==="'")s="single";else if(n==='"')s="double";else if(n==="\\")r++;else if(n==="#"&&(r===0||/\s/.test(e[r-1])))break}return s}function Sc(e){let t=e.split(`
780
- `),s=[],r=[],n="none";for(let i=0;i<t.length;i++){let a=t[i];if(r.length>0){let c=r[r.length-1];if((c.stripTabs?a.replace(/^\t+/,""):a)===c.delimiter){s.push(a.trimStart()),r.pop();continue}s.push(a);continue}let l=n,o=l==="none"?a.trimStart():a;if(s.push(o),n=dh(a,l),l!=="none")continue;let u=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let c of o.matchAll(u)){let f=c[1]==="-",d=c[3];r.push({delimiter:d,stripTabs:f})}}return s.join(`
781
- `)}var hh=new TextDecoder("utf-8",{fatal:!0});function Ac(e){if(!e)return e;let t=!1;for(let r=0;r<e.length;r++){let n=e.charCodeAt(r);if(n>255)return e;n>127&&(t=!0)}if(!t)return e;let s=new Uint8Array(e.length);for(let r=0;r<e.length;r++)s[r]=e.charCodeAt(r);try{return hh.decode(s)}catch{return e}}function ph(e,t){if(e!==void 0)return t==="bytes"?e:yt(e)}var Rn=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new ht,t?.mounts)for(let{mountPoint:s,filesystem:r}of t.mounts)this.mount(s,r)}mount(t,s){this.validateMountPath(t);let r=L(t);this.validateMount(r),this.mounts.set(r,{mountPoint:r,filesystem:s})}unmount(t){let s=L(t);if(!this.mounts.has(s))throw new Error(`No filesystem mounted at '${t}'`);this.mounts.delete(s)}getMounts(){return Array.from(this.mounts.values()).map(t=>({mountPoint:t.mountPoint,filesystem:t.filesystem}))}isMountPoint(t){let s=L(t);return this.mounts.has(s)}validateMountPath(t){let s=t.split("/");for(let r of s)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 s of this.mounts.keys())if(s!==t){if(t.startsWith(`${s}/`))throw new Error(`Cannot mount at '${t}': inside existing mount '${s}'`);if(s.startsWith(`${t}/`))throw new Error(`Cannot mount at '${t}': would contain existing mount '${s}'`)}}routePath(t){M(t,"access");let s=L(t),r=null,n=0;for(let i of this.mounts.values()){let a=i.mountPoint;if(s===a)return{fs:i.filesystem,relativePath:"/"};s.startsWith(`${a}/`)&&a.length>n&&(r=i,n=a.length)}if(r){let i=s.slice(n);return{fs:r.filesystem,relativePath:i||"/"}}return{fs:this.baseFs,relativePath:s}}getChildMountPoints(t){let s=L(t),r=s==="/"?"/":`${s}/`,n=[];for(let i of this.mounts.keys())if(i.startsWith(r)){let l=i.slice(r.length).split("/")[0];l&&!n.includes(l)&&n.push(l)}return n}async readFile(t,s){let{fs:r,relativePath:n}=this.routePath(t);return r.readFile(n,s)}async readFileBytes(t){let{fs:s,relativePath:r}=this.routePath(t);return xs(s,r)}async readFileBuffer(t){let{fs:s,relativePath:r}=this.routePath(t);return s.readFileBuffer(r)}async writeFile(t,s,r){let{fs:n,relativePath:i}=this.routePath(t);return n.writeFile(i,s,r)}async appendFile(t,s,r){let{fs:n,relativePath:i}=this.routePath(t);return n.appendFile(i,s,r)}async exists(t){let s=L(t);if(this.mounts.has(s)||this.getChildMountPoints(s).length>0)return!0;let{fs:n,relativePath:i}=this.routePath(t);return n.exists(i)}async stat(t){let s=L(t),r=this.mounts.get(s);if(r)try{return await r.filesystem.stat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(s).length>0)try{return await this.baseFs.stat(s)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:a}=this.routePath(t);return i.stat(a)}async lstat(t){let s=L(t),r=this.mounts.get(s);if(r)try{return await r.filesystem.lstat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(s).length>0)try{return await this.baseFs.lstat(s)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:a}=this.routePath(t);return i.lstat(a)}async mkdir(t,s){let r=L(t);if(this.mounts.has(r)){if(s?.recursive)return;throw new Error(`EEXIST: directory already exists, mkdir '${t}'`)}if(this.getChildMountPoints(r).length>0&&s?.recursive)return;let{fs:i,relativePath:a}=this.routePath(t);return i.mkdir(a,s)}async readdir(t){let s=L(t),r=new Set,n=null,{fs:i,relativePath:a}=this.routePath(t);try{let o=await i.readdir(a);for(let u of o)r.add(u)}catch(o){let u=o.code,c=o.message||"";if(u!=="ENOENT"&&!c.includes("ENOENT"))throw o;n=o}let l=this.getChildMountPoints(s);for(let o of l)r.add(o);if(r.size===0&&n&&!this.mounts.has(s))throw n;return Array.from(r).sort()}async rm(t,s){let r=L(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:a}=this.routePath(t);return i.rm(a,s)}async cp(t,s,r){let n=this.routePath(t),i=this.routePath(s);return n.fs===i.fs?n.fs.cp(n.relativePath,i.relativePath,r):this.crossMountCopy(t,s,r)}async mv(t,s){let r=L(t);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot move '${t}'`);let n=this.routePath(t),i=this.routePath(s);if(n.fs===i.fs)return n.fs.mv(n.relativePath,i.relativePath);await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){return vt(t,s)}getAllPaths(){let t=new Set;for(let s of this.baseFs.getAllPaths())t.add(s);for(let s of this.mounts.keys()){let r=s.split("/").filter(Boolean),n="";for(let a of r)n=`${n}/${a}`,t.add(n);let i=this.mounts.get(s);if(i)for(let a of i.filesystem.getAllPaths())a==="/"?t.add(s):t.add(`${s}${a}`)}return Array.from(t).sort()}async chmod(t,s){let r=L(t),n=this.mounts.get(r);if(n)return n.filesystem.chmod("/",s);let{fs:i,relativePath:a}=this.routePath(t);return i.chmod(a,s)}async symlink(t,s){let{fs:r,relativePath:n}=this.routePath(s);return r.symlink(t,n)}async link(t,s){let r=this.routePath(t),n=this.routePath(s);if(r.fs!==n.fs)throw new Error(`EXDEV: cross-device link not permitted, link '${t}' -> '${s}'`);return r.fs.link(r.relativePath,n.relativePath)}async readlink(t){let{fs:s,relativePath:r}=this.routePath(t);return s.readlink(r)}async realpath(t){let s=L(t);if(this.mounts.get(s))return s;let{fs:n,relativePath:i}=this.routePath(t),a=await n.realpath(i);for(let[l,o]of this.mounts)if(s===l||s.startsWith(`${l}/`))return a==="/"?l:`${l}${a}`;return a}async crossMountCopy(t,s,r){let n=await this.lstat(t);if(n.isFile){let i=await this.readFileBuffer(t);await this.writeFile(s,i),await this.chmod(s,n.mode)}else if(n.isDirectory){if(!r?.recursive)throw new Error(`cp: ${t} is a directory (not copied)`);await this.mkdir(s,{recursive:!0});let i=await this.readdir(t);for(let a of i){let l=St(t,a),o=St(s,a);await this.crossMountCopy(l,o,r)}}else if(n.isSymbolicLink){let i=await this.readlink(t);await this.symlink(i,s)}}async utimes(t,s,r){let{fs:n,relativePath:i}=this.routePath(t);return n.utimes(i,s,r)}};import*as ae from"node:fs";import*as Se from"node:path";import*as Ze from"node:fs";import*as Pe from"node:path";function Je(e,t){if(e===t)return!0;let s=e[t.length];return(s==="/"||s==="\\")&&e.startsWith(t)}function Ft(e,t){try{let s=Ze.realpathSync(e);return Je(s,t)?s:null}catch(s){if(s.code==="ENOENT"){let r=Pe.dirname(e);if(r===e)return null;let n=Ft(r,t);if(n===null)return null;try{if(Ze.lstatSync(e).isSymbolicLink()){let a=Ze.readlinkSync(e),l=Pe.isAbsolute(a)?a:Pe.resolve(Pe.dirname(e),a);if(Ft(l,t)===null)return null}}catch{}return Pe.join(n,Pe.basename(e))}return null}}function In(e,t,s){let r=Ft(e,s);if(r===null)return null;let n=Pe.resolve(e),i=n.slice(t.length),a=r.slice(s.length);if(i!==a)return null;try{if(Ze.lstatSync(n).isSymbolicLink())return null}catch{}return r}function On(e,t){if(!Ze.existsSync(e))throw new Error(`${t} root does not exist`);if(!Ze.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function $c(e,t){if(!Pe.isAbsolute(e))return{withinRoot:!0,relativePath:e};let s;try{s=Ze.realpathSync(e)}catch{s=Pe.resolve(e)}return Je(s,t)?{withinRoot:!0,relativePath:s.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:Pe.basename(e)}}function Tn(e,t,s,r){let n=e;if(n.path===void 0){for(let a of r)if(n.message?.includes(a))throw e}let i=n.code||"EIO";throw new Error(`${i}: ${s} '${t}'`)}var mh=["ELOOP","EFBIG","EPERM"],gh="/home/user/project",rs=class{root;canonicalRoot;mountPoint;readOnly;maxFileReadSize;allowSymlinks;memory=new Map;deleted=new Set;constructor(t){this.root=Se.resolve(t.root);let s=t.mountPoint??gh;if(this.mountPoint=s==="/"?"/":s.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${s}`);this.readOnly=t.readOnly??!1,this.maxFileReadSize=t.maxFileReadSize??10485760,this.allowSymlinks=t.allowSymlinks??!1,On(this.root,"OverlayFs"),this.canonicalRoot=ae.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),s="";for(let r of t)s+=`/${r}`,this.memory.has(s)||this.memory.set(s,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.memory.set("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}mkdirSync(t,s){let n=L(t).split("/").filter(Boolean),i="";for(let a of n)i+=`/${a}`,this.memory.has(i)||this.memory.set(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,s){let r=L(t),n=this.getDirname(r);n!=="/"&&this.mkdirSync(n);let i=s instanceof Uint8Array?s:new TextEncoder().encode(s);this.memory.set(r,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let s=L(t),r=this.getRelativeToMount(s);if(r===null)return null;let n=Se.join(this.root,r),i=Se.resolve(n);return Je(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?Ft(t,this.canonicalRoot):In(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let s=Se.dirname(t),r=this.resolveRealPath_(s);return r===null?null:Se.join(r,Se.basename(t))}sanitizeError(t,s,r){Tn(t,s,r,mh)}ensureParentDirs(t){let s=It(t);s!=="/"&&(this.memory.has(s)||(this.ensureParentDirs(s),this.memory.set(s,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(s))}async existsInOverlay(t){let s=L(t);if(this.deleted.has(s))return!1;if(this.memory.has(s))return!0;let r=this.resolveRealPathParent_(this.toRealPath(s));if(!r)return!1;try{return await ae.promises.lstat(r),!0}catch{return!1}}async readFile(t,s){let r=await this.readFileBuffer(t),n=je(s);return dt(r,n)}async readFileBytes(t){let s=await this.readFileBuffer(t);return dt(s,"binary")}async readFileBuffer(t,s=new Set){M(t,"open");let r=L(t);if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(s.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let n=this.memory.get(r);if(n){if(n.type==="symlink"){let a=this.resolveSymlink(r,n.target);return this.readFileBuffer(a,s)}if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let a=await ae.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${t}'`);let u=await ae.promises.readlink(i),c=this.realTargetToVirtual(r,u),f=this.resolveSymlink(r,c);return this.readFileBuffer(f,s)}if(a.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(this.maxFileReadSize>0&&a.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${a.size} bytes, max ${this.maxFileReadSize})`);let l=this.allowSymlinks?ae.constants.O_RDONLY:ae.constants.O_RDONLY|ae.constants.O_NOFOLLOW,o=await ae.promises.open(i,l);try{let u=await o.readFile();return new Uint8Array(u)}finally{await o.close()}}catch(a){let l=a.code;if(l==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(l==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(a,t,"open")}}async writeFile(t,s,r){M(t,"write"),this.assertWritable(`write '${t}'`);let n=L(t);this.ensureParentDirs(n);let i=je(r),a=ft(s,i);this.memory.set(n,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(n)}async appendFile(t,s,r){M(t,"append"),this.assertWritable(`append '${t}'`);let n=L(t),i=je(r),a=ft(s,i),l;try{l=await this.readFileBuffer(n)}catch{l=new Uint8Array(0)}let o=new Uint8Array(l.length+a.length);o.set(l),o.set(a,l.length),this.ensureParentDirs(n),this.memory.set(n,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(n)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,s=new Set){M(t,"stat");let r=L(t);if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(s.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let n=this.memory.get(r);if(n){if(n.type==="symlink"){let l=this.resolveSymlink(r,n.target);return this.stat(l,s)}let a=0;return n.type==="file"&&(a=n.content.length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:a,mtime:n.mtime}}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let a=await ae.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let l=await ae.promises.readlink(i),o=this.realTargetToVirtual(r,l),u=this.resolveSymlink(r,o);return this.stat(u,s)}return{isFile:a.isFile(),isDirectory:a.isDirectory(),isSymbolicLink:!1,mode:a.mode,size:a.size,mtime:a.mtime}}catch(a){if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(a,t,"stat")}}async lstat(t){M(t,"lstat");let s=L(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let r=this.memory.get(s);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),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:i,mtime:r.mtime}}let n=this.resolveRealPathParent_(this.toRealPath(s));if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await ae.promises.lstat(n);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}resolveSymlink(t,s){return zt(t,s)}realTargetToVirtual(t,s){let r=$c(s,this.canonicalRoot);if(r.withinRoot){if(!Se.isAbsolute(s))return s;let n=r.relativePath;return this.mountPoint==="/"?n:`${this.mountPoint}${n}`}return r.safeName}async mkdir(t,s){M(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=L(t);if(await this.existsInOverlay(r)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=It(r);if(i!=="/"&&!await this.existsInOverlay(i))if(s?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.memory.set(r,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(r)}async readdirCore(t,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Map,n=new Set,i=s==="/"?"/":`${s}/`;for(let l of this.deleted)if(l.startsWith(i)){let o=l.slice(i.length),u=o.split("/")[0];u&&!o.includes("/",u.length)&&n.add(u)}for(let[l,o]of this.memory)if(l!==s&&l.startsWith(i)){let u=l.slice(i.length),c=u.split("/")[0];c&&!n.has(c)&&!u.includes("/",1)&&r.set(c,{name:c,isFile:o.type==="file",isDirectory:o.type==="directory",isSymbolicLink:o.type==="symlink"})}let a=this.resolveRealPath_(this.toRealPath(s));if(a)try{if(!this.allowSymlinks&&(await ae.promises.lstat(a)).isSymbolicLink()){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);return r}let l=await ae.promises.readdir(a,{withFileTypes:!0});for(let o of l)!n.has(o.name)&&!r.has(o.name)&&r.set(o.name,{name:o.name,isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:o.isSymbolicLink()})}catch(l){if(l.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else l.code!=="ENOTDIR"&&this.sanitizeError(l,t,"scandir")}return r}async resolveForReaddir(t,s=!1){let r=L(t),n=new Set,i=s,a=this.memory.get(r);for(;a&&a.type==="symlink";){if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);n.add(r),i=!0,r=this.resolveSymlink(r,a.target),a=this.memory.get(r)}if(a)return{normalized:r,outsideOverlay:!1};if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let o=this.resolveRealPath_(this.toRealPath(r));if(!o)return{normalized:r,outsideOverlay:!0};try{if((await ae.promises.lstat(o)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let c=await ae.promises.readlink(o),f=this.realTargetToVirtual(r,c),d=this.resolveSymlink(r,f);return this.resolveForReaddir(d,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async readdir(t){M(t,"scandir");let{normalized:s,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let n=await this.readdirCore(t,s);return Array.from(n.keys()).sort((i,a)=>i<a?-1:i>a?1:0)}async readdirWithFileTypes(t){M(t,"scandir");let{normalized:s,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let n=await this.readdirCore(t,s);return Array.from(n.values()).sort((i,a)=>i.name<a.name?-1:i.name>a.name?1:0)}async rm(t,s){M(t,"rm"),this.assertWritable(`rm '${t}'`);let r=L(t);if(!await this.existsInOverlay(r)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(r)).isDirectory){let a=await this.readdir(r);if(a.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let l of a){let o=r==="/"?`/${l}`:`${r}/${l}`;await this.rm(o,s)}}}}catch(i){if(i instanceof Error&&(i.message.includes("ENOTEMPTY")||i.message.includes("EISDIR")))throw i}this.memory.delete(r),this.existsOnRealFs(r)&&this.deleted.add(r)}existsOnRealFs(t){let s=this.toRealPath(t),r=this.resolveRealPathParent_(s);if(!r)return!1;try{return ae.lstatSync(r),!0}catch{return!1}}async cp(t,s,r){M(t,"cp"),M(s,"cp"),this.assertWritable(`cp '${s}'`);let n=L(t),i=L(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let l=await this.stat(n);if(l.isFile){let o=await this.readFileBuffer(n);await this.writeFile(i,o)}else if(l.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(n);for(let u of o){let c=n==="/"?`/${u}`:`${n}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(c,f,r)}}}async mv(t,s){this.assertWritable(`mv '${s}'`),await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){return vt(t,s)}getAllPaths(){let t=new Set(this.memory.keys());for(let s of this.deleted)t.delete(s);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,s){if(this.deleted.has(t))return;let r=this.resolveRealPath_(this.toRealPath(t));if(r)try{let n=ae.readdirSync(r);for(let i of n){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;s.add(a);let l=Se.join(r,i);ae.lstatSync(l).isDirectory()&&this.scanRealFs(a,s)}}catch{}}async chmod(t,s){M(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=L(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=s;return}let a=await this.stat(r);if(a.isFile){let l=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:l,mode:s,mtime:new Date})}else a.isDirectory&&this.memory.set(r,{type:"directory",mode:s,mtime:new Date})}async symlink(t,s){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${s}'`);M(s,"symlink"),this.assertWritable(`symlink '${s}'`);let r=L(s);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.memory.set(r,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(t,s){M(t,"link"),M(s,"link"),this.assertWritable(`link '${s}'`);let r=L(t),n=L(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let a=await this.stat(r);if(!a.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(n))throw new Error(`EEXIST: file already exists, link '${s}'`);let o=await this.readFileBuffer(r);this.ensureParentDirs(n),this.memory.set(n,{type:"file",content:o,mode:a.mode,mtime:new Date}),this.deleted.delete(n)}async readlink(t){M(t,"readlink");let s=L(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let r=this.memory.get(s);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}let n=this.resolveRealPathParent_(this.toRealPath(s));if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await ae.promises.readlink(n);if(!Se.isAbsolute(i)){let a=Se.resolve(Se.dirname(n),i),l;try{l=ae.realpathSync(a)}catch{l=a}if(!Je(l,this.canonicalRoot))return Se.basename(i)}return this.realTargetToVirtual(s,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){M(t,"realpath");let s=L(t),r=new Set,n=async l=>{let o=l==="/"?[]:l.slice(1).split("/"),u="";for(let c of o){if(u=`${u}/${c}`,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(u),d=0,h=40;for(;f&&f.type==="symlink"&&d<h;){if(r.add(u),u=this.resolveSymlink(u,f.target),d++,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(u)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let m=this.toRealPath(u),p=this.resolveRealPath_(m);if(p)try{if((await ae.promises.lstat(p)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let b=await ae.promises.readlink(p),v=this.realTargetToVirtual(u,b);return r.add(u),u=this.resolveSymlink(u,v),n(u)}}catch(y){if(y.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(y,t,"realpath")}else if(!this.allowSymlinks){let y=this.resolveRealPathParent_(m);if(y)try{if((await ae.promises.lstat(y)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch(b){if(b.message?.includes("ENOENT")||b.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(b,t,"realpath")}}}}return u||"/"},i=await n(s);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,s,r){M(t,"utimes"),this.assertWritable(`utimes '${t}'`);let n=L(t);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let a=this.memory.get(n);if(a){a.mtime=r;return}let l=await this.stat(n);if(l.isFile){let o=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:o,mode:l.mode,mtime:r})}else l.isDirectory&&this.memory.set(n,{type:"directory",mode:l.mode,mtime:r})}};import*as W from"node:fs";import*as ne from"node:path";var yh=["EACCES","escaping sandbox","EFBIG"],Ln=class{root;canonicalRoot;maxFileReadSize;allowSymlinks;constructor(t){this.root=ne.resolve(t.root),this.maxFileReadSize=t.maxFileReadSize??10485760,this.allowSymlinks=t.allowSymlinks??!1,On(this.root,"ReadWriteFs"),this.canonicalRoot=W.realpathSync(this.root)}resolveAndValidate(t,s){let r=this.allowSymlinks?Ft(t,this.canonicalRoot):In(t,this.root,this.canonicalRoot);if(r===null)throw new Error(`EACCES: permission denied, '${s}' resolves outside sandbox`);return r}validateParent(t,s){let r=ne.dirname(t),n=this.resolveAndValidate(r,s);return ne.join(n,ne.basename(t))}toRealPath(t){let s=L(t),r=ne.join(this.root,s);return ne.resolve(r)}async readFile(t,s){let r=await this.readFileBuffer(t),n=je(s);return dt(r,n)}async readFileBytes(t){let s=await this.readFileBuffer(t);return dt(s,"binary")}async readFileBuffer(t){M(t,"open");let s=this.toRealPath(t),r=this.resolveAndValidate(s,t);try{let n=this.allowSymlinks?W.constants.O_RDONLY:W.constants.O_RDONLY|W.constants.O_NOFOLLOW,i=await W.promises.open(r,n);try{if(this.maxFileReadSize>0){let l=await i.stat();if(l.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${l.size} bytes, max ${this.maxFileReadSize})`)}let a=await i.readFile();return new Uint8Array(a)}finally{await i.close()}}catch(n){let i=n;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(n,t,"open")}}async writeFile(t,s,r){M(t,"write");let n=this.toRealPath(t),i=this.resolveAndValidate(n,t),a=je(r),l=ft(s,a),o=ne.dirname(i);try{await W.promises.mkdir(o,{recursive:!0}),i=this.resolveAndValidate(n,t);let u=this.allowSymlinks?0:W.constants.O_NOFOLLOW,c=W.constants.O_WRONLY|W.constants.O_CREAT|W.constants.O_TRUNC|u,f=await W.promises.open(i,c,438);try{await f.writeFile(l)}finally{await f.close()}}catch(u){if(u.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(u,t,"write")}}async appendFile(t,s,r){M(t,"append");let n=this.toRealPath(t),i=this.resolveAndValidate(n,t),a=je(r),l=ft(s,a),o=ne.dirname(i);try{await W.promises.mkdir(o,{recursive:!0}),i=this.resolveAndValidate(n,t);let u=this.allowSymlinks?0:W.constants.O_NOFOLLOW,c=W.constants.O_WRONLY|W.constants.O_CREAT|W.constants.O_APPEND|u,f=await W.promises.open(i,c,438);try{await f.writeFile(l)}finally{await f.close()}}catch(u){if(u.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(u,t,"append")}}async exists(t){if(t.includes("\0"))return!1;let s=this.toRealPath(t);try{let r=this.resolveAndValidate(s,t);return await W.promises.access(r),!0}catch{return!1}}async stat(t){M(t,"stat");let s=this.toRealPath(t),r=this.resolveAndValidate(s,t);try{let n=await W.promises.lstat(r);if(!this.allowSymlinks&&n.isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);return{isFile:n.isFile(),isDirectory:n.isDirectory(),isSymbolicLink:n.isSymbolicLink(),mode:n.mode,size:n.size,mtime:n.mtime}}catch(n){if(n.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(n,t,"stat")}}async lstat(t){M(t,"lstat");let s=this.toRealPath(t),r=this.validateParent(s,t);try{let n=await W.promises.lstat(r);return{isFile:n.isFile(),isDirectory:n.isDirectory(),isSymbolicLink:n.isSymbolicLink(),mode:n.mode,size:n.size,mtime:n.mtime}}catch(n){if(n.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(n,t,"lstat")}}async mkdir(t,s){M(t,"mkdir");let r=this.toRealPath(t),n=this.resolveAndValidate(r,t);try{await W.promises.mkdir(n,{recursive:s?.recursive})}catch(i){let a=i;if(a.code==="EEXIST")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(a.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){M(t,"scandir");let s=this.toRealPath(t),r=this.resolveAndValidate(s,t);try{if(!this.allowSymlinks&&(await W.promises.lstat(r)).isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);return(await W.promises.readdir(r,{withFileTypes:!0})).map(i=>({name:i.name,isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink()})).sort((i,a)=>i.name<a.name?-1:i.name>a.name?1:0)}catch(n){let i=n;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(n,t,"scandir")}}async rm(t,s){M(t,"rm");let r=this.toRealPath(t),n=this.resolveAndValidate(r,t);try{await W.promises.rm(n,{recursive:s?.recursive??!1,force:s?.force??!1})}catch(i){let a=i;if(a.code==="ENOENT"&&!s?.force)throw new Error(`ENOENT: no such file or directory, rm '${t}'`);if(a.code==="ENOTEMPTY")throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);this.sanitizeError(i,t,"rm")}}async cp(t,s,r){M(t,"cp"),M(s,"cp");let n=this.toRealPath(t),i=this.toRealPath(s),a=this.resolveAndValidate(n,t),l=this.resolveAndValidate(i,s);try{await W.promises.cp(a,l,{recursive:r?.recursive??!1,filter:async o=>{try{if(W.lstatSync(o).isSymbolicLink()){let c=await W.promises.realpath(o).catch(()=>null);return c===null?!1:Je(c,this.canonicalRoot)}return!0}catch(u){return u.code==="ENOENT"}}})}catch(o){let u=o;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(o,t,"cp")}}async mv(t,s){M(t,"mv"),M(s,"mv");let r=this.toRealPath(t),n=this.toRealPath(s),i=this.validateParent(r,t),a=this.validateParent(n,s);try{if((await W.promises.lstat(i)).isSymbolicLink()){let u=await W.promises.readlink(i),c=ne.resolve(ne.dirname(a),u),f=await W.promises.realpath(c).catch(()=>c);if(!Je(f,this.canonicalRoot))throw new Error(`EACCES: permission denied, mv '${t}' -> '${s}' would create symlink escaping sandbox`)}}catch(o){let u=o;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 o}let l=ne.dirname(a);try{await W.promises.mkdir(l,{recursive:!0})}catch(o){this.sanitizeError(o,s,"mv")}try{await W.promises.rename(i,a)}catch(o){let u=o;if(u.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(u.code==="EXDEV"){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0});return}this.sanitizeError(o,t,"mv")}try{if(W.lstatSync(a).isDirectory()&&this.findEscapingSymlinks(a).length>0)throw await W.promises.rename(a,i),new Error(`EACCES: permission denied, mv '${t}' -> '${s}' would create symlinks escaping sandbox`)}catch(o){if(o.message?.includes("EACCES")||o.message?.includes("escaping sandbox"))throw o}}resolvePath(t,s){return vt(t,s)}getAllPaths(){let t=[];return this.scanDir("/",t),t}sanitizeError(t,s,r){Tn(t,s,r,yh)}findEscapingSymlinks(t){let s=[];try{let r=W.readdirSync(t);for(let n of r){let i=ne.join(t,n);try{let a=W.lstatSync(i);if(a.isSymbolicLink()){let l=W.readlinkSync(i),o=ne.resolve(t,l),u;try{u=W.realpathSync(o)}catch{u=o}Je(u,this.canonicalRoot)||s.push(i)}else a.isDirectory()&&s.push(...this.findEscapingSymlinks(i))}catch{}}}catch{}return s}scanDir(t,s){let r=this.toRealPath(t),n;try{n=this.resolveAndValidate(r,t)}catch{return}try{let i=W.readdirSync(n);for(let a of i){let l=t==="/"?`/${a}`:`${t}/${a}`;s.push(l);let o=ne.join(n,a);W.lstatSync(o).isDirectory()&&this.scanDir(l,s)}}catch{}}async chmod(t,s){M(t,"chmod");let r=this.toRealPath(t),n=this.resolveAndValidate(r,t);try{let i=this.allowSymlinks?W.constants.O_RDONLY:W.constants.O_RDONLY|W.constants.O_NOFOLLOW,a=await W.promises.open(n,i);try{await a.chmod(s)}finally{await a.close()}}catch(i){let a=i;if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);if(a.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(i,t,"chmod")}}async symlink(t,s){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${s}'`);M(s,"symlink");let r=this.toRealPath(s),n=this.validateParent(r,s),i=L(s),a=L(ne.dirname(i)),l=t.startsWith("/")?L(t):L(a==="/"?`/${t}`:`${a}/${t}`),o=ne.join(this.canonicalRoot,l),u=ne.dirname(n),c=t.startsWith("/")?o:ne.relative(u,o)||".";try{await W.promises.symlink(c,n)}catch(f){if(f.code==="EEXIST")throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.sanitizeError(f,s,"symlink")}}async link(t,s){M(t,"link"),M(s,"link");let r=this.toRealPath(t),n=this.toRealPath(s),i=this.resolveAndValidate(r,t),a=this.resolveAndValidate(n,s);try{await W.promises.link(i,a)}catch(l){let o=l;if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(o.code==="EEXIST")throw new Error(`EEXIST: file already exists, link '${s}'`);if(o.code==="EPERM")throw new Error(`EPERM: operation not permitted, link '${t}'`);this.sanitizeError(l,t,"link")}}async readlink(t){M(t,"readlink");let s=this.toRealPath(t),r=this.validateParent(s,t);try{let n=await W.promises.readlink(r),i=L(t),a=ne.dirname(i),l=ne.isAbsolute(n)?n:ne.resolve(ne.dirname(r),n),o=await W.promises.realpath(l).catch(()=>l);if(Je(o,this.canonicalRoot)){let u=o.slice(this.canonicalRoot.length)||"/";return a==="/"?u.startsWith("/")?u.slice(1)||".":u:ne.relative(a,u)}return ne.basename(n)}catch(n){let i=n;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(n,t,"readlink")}}async realpath(t){M(t,"realpath");let s=this.toRealPath(t);try{this.resolveAndValidate(s,t)}catch{throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}let r;try{r=await W.promises.realpath(s)}catch(n){let i=n;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(n,t,"realpath")}if(Je(r,this.canonicalRoot))return r.slice(this.canonicalRoot.length)||"/";throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}async utimes(t,s,r){M(t,"utimes");let n=this.toRealPath(t),i=this.resolveAndValidate(n,t);try{let a=this.allowSymlinks?W.constants.O_RDONLY:W.constants.O_RDONLY|W.constants.O_NOFOLLOW,l=await W.promises.open(i,a);try{await l.utimes(s,r)}finally{await l.close()}}catch(a){let l=a;if(l.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);if(l.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(a,t,"utimes")}}};var is=class{cmdId;cwd;startedAt;exitCode;bashEnv;cmdLine;env;explicitCwd;signal;timeoutMs;abortController=new AbortController;timeoutId;externalAbortListener;resultPromise;constructor(t,s,r,n,i=!1,a,l){this.cmdId=crypto.randomUUID(),this.cwd=r,this.startedAt=new Date,this.bashEnv=t,this.cmdLine=s,this.env=n,this.explicitCwd=i,this.signal=a,this.timeoutMs=l,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=ks(()=>{this.abortController.abort(new Error(`sandbox command timeout after ${t}ms`))},t)}}cleanupCancellation(){this.timeoutId!==void 0&&(Ns(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 s=await this.bashEnv.exec(this.cmdLine,t);return this.exitCode=s.exitCode,s}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 Mn=class e{bashEnv;timeoutMs;constructor(t,s){this.bashEnv=t,this.timeoutMs=s}static async create(t){let s=t?.fs;if(t?.overlayRoot){if(t?.fs)throw new Error("Cannot specify both 'fs' and 'overlayRoot' options");s=new rs({root:t.overlayRoot})}let r=new Ps({env:t?.env,cwd:t?.cwd,fs:s,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,s,r){let n,i,a,l,o=!1,u,c;if(typeof t=="object"){let p=t,y=[p.cmd,...p.args??[]];n=zn(y),i=p.cwd,a=p.env,l=p.signal,o=p.detached??!1,u=p.stdout,c=p.stderr}else if(Array.isArray(s)){let p=r;n=zn([t,...s]),l=p?.signal}else{n=t;let p=s;i=p?.cwd,a=p?.env}let f=i??this.bashEnv.getCwd(),d=i!==void 0,h=new is(this.bashEnv,n,f,a,d,l,this.timeoutMs);if(o)return h;let m=await h.wait();if(u){let p=await h.stdout();p&&u.write(p)}if(c){let p=await h.stderr();p&&c.write(p)}return m}async writeFiles(t){let s=this.bashEnv.getCwd();for(let[r,n]of Object.entries(t)){let i;typeof n=="string"?i=n:n.encoding==="base64"?i=Buffer.from(n.content,"base64").toString("utf-8"):i=n.content;let a=this.bashEnv.fs.resolvePath(s,r),l=a.substring(0,a.lastIndexOf("/"))||"/";l!=="/"&&await this.bashEnv.fs.mkdir(l,{recursive:!0}),await this.bashEnv.writeFile(a,i)}}async readFile(t,s){let r=await this.bashEnv.readFile(t);return s==="base64"?Buffer.from(r).toString("base64"):r}async mkDir(t,s){let r=this.bashEnv.fs.resolvePath(this.bashEnv.getCwd(),t);await this.bashEnv.fs.mkdir(r,{recursive:s?.recursive??!1})}async stop(){}async extendTimeout(t){}get domain(){}get bashEnvInstance(){return this.bashEnv}};var Wn=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 s=this.options.includeStackTraces?t:{...t,stack:void 0};this.violations.unshift(s),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(s),this.options.logToConsole&&console.warn(`[SecurityViolation] ${t.type}: ${t.message}`,t.path),this.options.onViolation(s)}getViolations(){return[...this.violations]}getViolationsByType(t){return[...this.violationsByType.get(t)??[]]}getSummary(){let t=[];for(let[s,r]of this.violationsByType){if(r.length===0)continue;let n=new Set,i=Number.POSITIVE_INFINITY,a=0;for(let l of r)n.add(l.path),i=Math.min(i,l.timestamp),a=Math.max(a,l.timestamp);t.push({type:s,count:r.length,firstSeen:i,lastSeen:a,paths:Array.from(n)})}return t.sort((s,r)=>r.count-s.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 Pc(){return e=>{console.warn("[DefenseInDepth] Security violation detected:",`
795
+ `;try{s.writeFileSync(`/bin/${t.name}`,i)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,i)}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=Bu(t.stdout),t.stderr=Bu(t.stderr),t}async exec(t,n){let r=new xr(this.limits,n?.signal),s;try{s=await this.execInScope(t,n,r,0,n?.signal,!1,!1)}catch(a){try{await r.close()}catch{}throw a}let i=s;try{await r.close()}catch{i={...s,stderr:`${s.stderr}bash: execution cleanup failed
796
+ `,exitCode:126}}return t.trim()?this.logResult(i):i}async execInScope(t,n,r,s,i,a=!1,o=!0){let l=f=>o?this.logResult(f):f,c=pr(i,n?.signal),u=n?{...n,signal:c.signal}:{signal:c.signal};try{if(r.assertExecDepth(s),cr(t,this.limits.maxSourceBytes),!t.trim())return{stdout:"",stderr:"",exitCode:0,env:Ke(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[w,S]of Object.entries(u.env))p.set(w,S);d!==void 0&&p.set("PWD",d);let m={...this.state,env:p,arrays:u.replaceEnv?new Map:pt(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:Vp(u.stdin,u.stdinKind,this.limits.maxInputBytes,this.limits.maxStringLength,r,a),signal:u.signal,extraArgs:u.args},E=t;u.rawScript||(E=Mu(t));let b=this.defenseInDepthConfig?Ie.getInstance(this.defenseInDepthConfig):null,g=b?.activate();try{let w=async()=>{let S=qe(E,{maxHeredocSize:this.limits.maxHeredocSize}),A;if(this.transformPlugins.length>0){let O=Object.create(null);for(let _ of this.transformPlugins){let V=_.transform({ast:S,metadata:O});S=V.ast,V.metadata&&(O=Fn(O,V.metadata))}A=O}let v={fs:this.fs,commands:this.commands,limits:this.limits,executionScope:r,exec:(O,_,V=!1)=>this.execInScope(O,_,r,s+1,u.signal,V),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:b?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},D=await new lr(v,m).executeScript(S);return A&&(D.metadata=A),l(D)};return g?await g.run(w):await w()}catch(w){if(w instanceof H)return l({stdout:w.stdout,stderr:w.stderr,exitCode:w.exitCode,env:Ke(this.state.env,u.env)});if(w instanceof tt)return l({stdout:w.stdout,stderr:w.stderr,exitCode:w.exitCode,env:Ke(this.state.env,u.env)});if(w instanceof oe)return l({stdout:w.stdout,stderr:w.stderr,exitCode:1,env:Ke(this.state.env,u.env)});if(w instanceof We)return l({stdout:w.stdout,stderr:w.stderr,exitCode:124,env:Ke(this.state.env,u.env)});if(w instanceof P)return l({stdout:w.stdout,stderr:ht(w.stderr),exitCode:P.EXIT_CODE,env:Ke(this.state.env,u.env)});if(w instanceof Ct)return l({stdout:"",stderr:`bash: security violation: ${ht(w.message)}
797
+ `,exitCode:1,env:Ke(this.state.env,u.env)});if(w.name==="ParseException")return l({stdout:"",stderr:`bash: syntax error: ${ht(w.message)}
798
+ `,exitCode:2,env:Ke(this.state.env,u.env)});if(w instanceof Wt)return l({stdout:"",stderr:`bash: ${ht(w.message)}
799
+ `,exitCode:2,env:Ke(this.state.env,u.env)});if(w instanceof RangeError)return l({stdout:"",stderr:`bash: ${ht(w.message)}
800
+ `,exitCode:1,env:Ke(this.state.env,u.env)});throw w}finally{g?.deactivate()}}catch(f){if(f instanceof We)return l({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:Ke(this.state.env,u.env)});if(f instanceof P)return l({stdout:f.stdout,stderr:ht(f.stderr),exitCode:P.EXIT_CODE,env:Ke(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 Tt(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){cr(t,this.limits.maxSourceBytes);let n=Mu(t),r=qe(n,{maxHeredocSize:this.limits.maxHeredocSize}),s=Object.create(null);for(let i of this.transformPlugins){let a=i.transform({ast:r,metadata:s});r=a.ast,a.metadata&&(s=Fn(s,a.metadata))}return{script:ur(r),ast:r,metadata:s}}};function Wp(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 Mu(e){let t=e.split(`
801
+ `),n=[],r=[],s="none";for(let i=0;i<t.length;i++){let a=t[i];if(r.length>0){let u=r[r.length-1];if((u.stripTabs?a.replace(/^\t+/,""):a)===u.delimiter){n.push(a.trimStart()),r.pop();continue}n.push(a);continue}let o=s,l=o==="none"?a.trimStart():a;if(n.push(l),s=Wp(a,o),o!=="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(`
802
+ `)}var Fp=new TextDecoder("utf-8",{fatal:!0});function Bu(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 Fp.decode(n)}catch{return e}}function Vp(e,t,n,r,s,i){if(e===void 0)return;let a=t==="bytes"?e.length:M(e);if(a>n||a>r)throw new P(`stdin size limit exceeded (${Math.min(n,r)} bytes)`,"string_length");return i||s.consumeInput(a,"stdin"),t==="bytes"?e:Dt(e)}var xs=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new $t,t?.mounts)for(let{mountPoint:n,filesystem:r}of t.mounts)this.mount(n,r)}mount(t,n){this.validateMountPath(t);let r=B(t);this.validateMount(r),this.mounts.set(r,{mountPoint:r,filesystem:n})}unmount(t){let n=B(t);if(!this.mounts.has(n))throw new Error(`No filesystem mounted at '${t}'`);this.mounts.delete(n)}getMounts(){return Array.from(this.mounts.values()).map(t=>({mountPoint:t.mountPoint,filesystem:t.filesystem}))}isMountPoint(t){let n=B(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){F(t,"access");let n=B(t),r=null,s=0;for(let i of this.mounts.values()){let a=i.mountPoint;if(n===a)return{fs:i.filesystem,relativePath:"/"};n.startsWith(`${a}/`)&&a.length>s&&(r=i,s=a.length)}if(r){let i=n.slice(s);return{fs:r.filesystem,relativePath:i||"/"}}return{fs:this.baseFs,relativePath:n}}getChildMountPoints(t){let n=B(t),r=n==="/"?"/":`${n}/`,s=[];for(let i of this.mounts.keys())if(i.startsWith(r)){let o=i.slice(r.length).split("/")[0];o&&!s.includes(o)&&s.push(o)}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 mr(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=B(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=B(t),r=this.mounts.get(n);if(r)try{return await r.filesystem.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:a}=this.routePath(t);return i.stat(a)}async lstat(t){let n=B(t),r=this.mounts.get(n);if(r)try{return await r.filesystem.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:a}=this.routePath(t);return i.lstat(a)}async mkdir(t,n){let r=B(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:a}=this.routePath(t);return i.mkdir(a,n)}async readdir(t){let n=B(t),r=new Set,s=null,{fs:i,relativePath:a}=this.routePath(t);try{let l=await i.readdir(a);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 o=this.getChildMountPoints(n);for(let l of o)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=B(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:a}=this.routePath(t);return i.rm(a,n)}async cp(t,n,r){if((await this.stat(t)).isDirectory&&vt(t,n))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);let i=this.routePath(t),a=this.routePath(n);return i.fs===a.fs?i.fs.cp(i.relativePath,a.relativePath,r):this.crossMountCopy(t,n,r)}async mv(t,n){let r=B(t);if((await this.stat(t)).isDirectory&&vt(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),a=this.routePath(n);if(i.fs===a.fs)return i.fs.mv(i.relativePath,a.relativePath);await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return _t(t,n)}getAllPaths(){let t=new Set;for(let n of this.baseFs.getAllPaths())t.add(n);for(let n of this.mounts.keys()){let r=n.split("/").filter(Boolean),s="";for(let a of r)s=`${s}/${a}`,t.add(s);let i=this.mounts.get(n);if(i)for(let a of i.filesystem.getAllPaths())a==="/"?t.add(n):t.add(`${n}${a}`)}return Array.from(t).sort()}async chmod(t,n){let r=B(t),s=this.mounts.get(r);if(s)return s.filesystem.chmod("/",n);let{fs:i,relativePath:a}=this.routePath(t);return i.chmod(a,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=B(t);if(this.mounts.get(n))return n;let{fs:s,relativePath:i}=this.routePath(t),a=await s.realpath(i);for(let[o,l]of this.mounts)if(n===o||n.startsWith(`${o}/`))return a==="/"?o:`${o}${a}`;return a}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 a of i){let o=At(t,a),l=At(n,a);await this.crossMountCopy(o,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)}};import*as de from"node:fs";import*as Re from"node:path";import*as it from"node:fs";import*as Pe from"node:path";function Ge(e,t){let n=/^[A-Za-z]:[\\/]/.test(t)?Pe.win32:Pe.posix,r=n.relative(t,e);return r===""||r!==".."&&!r.startsWith(`..${n.sep}`)&&!n.isAbsolute(r)}function fn(e,t){try{let n=it.realpathSync(e);return Ge(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=Pe.dirname(e);if(r===e)return null;let s=fn(r,t);if(s===null)return null;try{if(it.lstatSync(e).isSymbolicLink()){let a=it.readlinkSync(e),o=Pe.isAbsolute(a)?a:Pe.resolve(Pe.dirname(e),a);if(fn(o,t)===null)return null}}catch{}return Pe.join(s,Pe.basename(e))}return null}}function Ps(e,t,n){let r=fn(e,n);if(r===null)return null;let s=Pe.resolve(e),i=s.slice(t.length),a=r.slice(n.length);if(i!==a)return null;try{if(it.lstatSync(s).isSymbolicLink())return null}catch{}return r}function $s(e,t){if(!it.existsSync(e))throw new Error(`${t} root does not exist`);if(!it.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function Wu(e,t){if(!Pe.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=it.realpathSync(e)}catch{n=Pe.resolve(e)}return Ge(n,t)?{withinRoot:!0,relativePath:n.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:Pe.basename(e)}}function ks(e,t,n,r){let s=e;if(s.path===void 0){for(let a of r)if(s.message?.includes(a))throw e}let i=s.code||"EIO";throw new Error(`${i}: ${n} '${t}'`)}var zp=["ELOOP","EFBIG","EPERM"],qp="/home/user/project",On=class{root;canonicalRoot;mountPoint;readOnly;maxFileReadSize;maxMemoryBytes;allowSymlinks;memory=new Map;deleted=new Set;nextMemoryIdentity=1;retainedMemoryBytes=0;memoryEntryBytes(t){if(!t||t.type!=="file")return 0;let n=t.content.byteLength;for(let r of t.appendChunks??[])n+=r.byteLength;return n}assertMemoryCapacity(t,n=0){if(!Number.isSafeInteger(t)||t<0||t>this.maxMemoryBytes-this.retainedMemoryBytes+n)throw new Error(`ENOSPC: overlay memory byte limit exceeded (${this.maxMemoryBytes} bytes)`)}setMemoryEntry(t,n){let r=this.memoryEntryBytes(this.memory.get(t)),s=this.memoryEntryBytes(n);this.assertMemoryCapacity(s,r),this.memory.set(t,n),this.retainedMemoryBytes+=s-r}deleteMemoryEntry(t){let n=this.memory.get(t);n&&(this.retainedMemoryBytes-=this.memoryEntryBytes(n),this.memory.delete(t))}identityFor(t){return t.type==="symlink"?"":(t.identity||(t.identity=`overlay:${this.nextMemoryIdentity++}`),t.identity)}constructor(t){this.root=Re.resolve(t.root);let n=t.mountPoint??qp;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,$s(this.root,"OverlayFs"),this.canonicalRoot=de.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=B(t).split("/").filter(Boolean),i="";for(let a of s)i+=`/${a}`,this.memory.has(i)||this.setMemoryEntry(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,n){let r=B(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=B(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=Re.join(this.root,r),i=Re.resolve(s);return Ge(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?fn(t,this.canonicalRoot):Ps(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=Re.dirname(t),r=this.resolveRealPath_(n);return r===null?null:Re.join(r,Re.basename(t))}sanitizeError(t,n,r){ks(t,n,r,zp)}ensureParentDirs(t){let n=pn(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=B(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 de.promises.lstat(r),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=nt(n);return Pt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Pt(n,"binary")}async readFileBuffer(t,n=new Set){F(t,"open");let r=B(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 a=s.appendChunks.reduce((c,u)=>c+u.byteLength,s.content.byteLength);if(!Number.isSafeInteger(a))throw new Error(`EFBIG: file too large, read '${t}'`);let o=new Uint8Array(a);o.set(s.content);let l=s.content.byteLength;for(let c of s.appendChunks)o.set(c,l),l+=c.byteLength;return s.content=o,s.appendChunks=void 0,o}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let a=await de.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${t}'`);let c=await de.promises.readlink(i),u=this.realTargetToVirtual(r,c),f=this.resolveSymlink(r,u);return this.readFileBuffer(f,n)}if(a.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(this.maxFileReadSize>0&&a.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${a.size} bytes, max ${this.maxFileReadSize})`);let o=this.allowSymlinks?de.constants.O_RDONLY:de.constants.O_RDONLY|de.constants.O_NOFOLLOW,l=await de.promises.open(i,o);try{let c=await l.readFile();return new Uint8Array(c)}finally{await l.close()}}catch(a){let o=a.code;if(o==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(o==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(a,t,"open")}}async writeFile(t,n,r){F(t,"write"),this.assertWritable(`write '${t}'`);let s=B(t);this.ensureParentDirs(s);let i=nt(r),a=xt(n,i);this.setMemoryEntry(s,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(s)}async appendFile(t,n,r){F(t,"append"),this.assertWritable(`append '${t}'`);let s=B(t),i=nt(r),a=xt(n,i),o=this.memory.get(s);if(o?.type==="file"){this.assertMemoryCapacity(a.byteLength),o.appendChunks||(o.appendChunks=[]),o.appendChunks.push(a),this.retainedMemoryBytes+=a.byteLength,o.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:[a],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){F(t,"stat");let r=B(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 o=this.resolveSymlink(r,s.target);return this.stat(o,n)}let a=0;return s.type==="file"&&(a=s.content.length+(s.appendChunks?.reduce((o,l)=>o+l.byteLength,0)??0)),{isFile:s.type==="file",isDirectory:s.type==="directory",isSymbolicLink:!1,mode:s.mode,size:a,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 a=await de.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let o=await de.promises.readlink(i),l=this.realTargetToVirtual(r,o),c=this.resolveSymlink(r,l);return this.stat(c,n)}return{isFile:a.isFile(),isDirectory:a.isDirectory(),isSymbolicLink:!1,mode:a.mode,size:a.size,mtime:a.mtime,dev:a.dev,ino:a.ino}}catch(a){if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(a,t,"stat")}}async lstat(t){F(t,"lstat");let n=B(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((a,o)=>a+o.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 de.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 mn(t,n)}realTargetToVirtual(t,n){let r=Wu(n,this.canonicalRoot);if(r.withinRoot){if(!Re.isAbsolute(n))return n;let s=r.relativePath;return this.mountPoint==="/"?s:`${this.mountPoint}${s}`}return r.safeName}async mkdir(t,n){F(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=B(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=pn(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 o of this.deleted)if(o.startsWith(i)){let l=o.slice(i.length),c=l.split("/")[0];c&&!l.includes("/",c.length)&&s.add(c)}for(let[o,l]of this.memory)if(o!==n&&o.startsWith(i)){let c=o.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 a=this.resolveRealPath_(this.toRealPath(n));if(a)try{if(!this.allowSymlinks&&(await de.promises.lstat(a)).isSymbolicLink()){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);return r}let o=await de.promises.readdir(a,{withFileTypes:!0});for(let l of o)!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(o){if(o.code==="ENOENT"){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else o.code!=="ENOTDIR"&&this.sanitizeError(o,t,"scandir")}return r}async resolveForReaddir(t,n=!1){let r=B(t),s=new Set,i=n,a=this.memory.get(r);for(;a&&a.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,a.target),a=this.memory.get(r)}if(a)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 de.promises.lstat(l)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let u=await de.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 readdir(t){F(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,a)=>i<a?-1:i>a?1:0)}async readdirWithFileTypes(t){F(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,a)=>i.name<a.name?-1:i.name>a.name?1:0)}async rm(t,n){F(t,"rm"),this.assertWritable(`rm '${t}'`);let r=B(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 a=await this.readdir(r);if(a.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of a){let l=r==="/"?`/${o}`:`${r}/${o}`;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 de.lstatSync(r),!0}catch{return!1}}async cp(t,n,r){F(t,"cp"),F(n,"cp"),this.assertWritable(`cp '${n}'`);let s=B(t),i=B(n);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let o=await this.stat(s);if(o.isFile){let l=await this.readFileBuffer(s);await this.writeFile(i,l)}else if(o.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(vt(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 _t(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=de.readdirSync(r);for(let i of s){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;n.add(a);let o=Re.join(r,i);de.lstatSync(o).isDirectory()&&this.scanRealFs(a,n)}}catch{}}async chmod(t,n){F(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=B(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 a=await this.stat(r);if(a.isFile){let o=await this.readFileBuffer(r);this.setMemoryEntry(r,{type:"file",content:o,mode:n,mtime:new Date})}else a.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}'`);F(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=B(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){F(t,"link"),F(n,"link"),this.assertWritable(`link '${n}'`);let r=B(t),s=B(n);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let a=await this.stat(r);if(!a.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:a.mode,mtime:new Date,identity:a.identity??`overlay:${this.nextMemoryIdentity++}`}),this.deleted.delete(s)}async readlink(t){F(t,"readlink");let n=B(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 de.promises.readlink(s);if(!Re.isAbsolute(i)){let a=Re.resolve(Re.dirname(s),i),o;try{o=de.realpathSync(a)}catch{o=a}if(!Ge(o,this.canonicalRoot))return Re.basename(i)}return this.realTargetToVirtual(n,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){F(t,"realpath");let n=B(t),r=new Set,s=async o=>{let l=o==="/"?[]:o.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 de.promises.lstat(m)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let b=await de.promises.readlink(m),g=this.realTargetToVirtual(c,b);return r.add(c),c=this.resolveSymlink(c,g),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 de.promises.lstat(E)).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){F(t,"utimes"),this.assertWritable(`utimes '${t}'`);let s=B(t);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let a=this.memory.get(s);if(a){a.mtime=r;return}let o=await this.stat(s);if(o.isFile){let l=await this.readFileBuffer(s);this.setMemoryEntry(s,{type:"file",content:l,mode:o.mode,mtime:r})}else o.isDirectory&&this.setMemoryEntry(s,{type:"directory",mode:o.mode,mtime:r})}};import*as T from"node:fs";import*as se from"node:path";var Up=["EACCES","escaping sandbox","EFBIG"],Ns=class{root;canonicalRoot;maxFileReadSize;allowSymlinks;transactionId=0;constructor(t){this.root=se.resolve(t.root),this.maxFileReadSize=t.maxFileReadSize??10485760,this.allowSymlinks=t.allowSymlinks??!1,$s(this.root,"ReadWriteFs"),this.canonicalRoot=T.realpathSync(this.root)}resolveAndValidate(t,n){let r=this.allowSymlinks?fn(t,this.canonicalRoot):Ps(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=se.dirname(t),s=this.resolveAndValidate(r,n);return se.join(s,se.basename(t))}toRealPath(t){let n=B(t),r=se.join(this.root,n);return se.resolve(r)}async readFile(t,n){let r=await this.readFileBuffer(t),s=nt(n);return Pt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Pt(n,"binary")}async readFileBuffer(t){F(t,"open");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{let s=this.allowSymlinks?T.constants.O_RDONLY:T.constants.O_RDONLY|T.constants.O_NOFOLLOW,i=await T.promises.open(r,s);try{if(this.maxFileReadSize>0){let o=await i.stat();if(o.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${o.size} bytes, max ${this.maxFileReadSize})`)}let a=await i.readFile();return new Uint8Array(a)}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){F(t,"write");let s=this.toRealPath(t),i=this.resolveAndValidate(s,t),a=nt(r),o=xt(n,a),l=se.dirname(i);try{await T.promises.mkdir(l,{recursive:!0}),i=this.resolveAndValidate(s,t);let c=this.allowSymlinks?0:T.constants.O_NOFOLLOW,u=T.constants.O_WRONLY|T.constants.O_CREAT|T.constants.O_TRUNC|c,f=await T.promises.open(i,u,438);try{await f.writeFile(o)}finally{await f.close()}}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){F(t,"append");let s=this.toRealPath(t),i=this.resolveAndValidate(s,t),a=nt(r),o=xt(n,a),l=se.dirname(i);try{await T.promises.mkdir(l,{recursive:!0}),i=this.resolveAndValidate(s,t);let c=this.allowSymlinks?0:T.constants.O_NOFOLLOW,u=T.constants.O_WRONLY|T.constants.O_CREAT|T.constants.O_APPEND|c,f=await T.promises.open(i,u,438);try{await f.writeFile(o)}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 exists(t){if(t.includes("\0"))return!1;let n=this.toRealPath(t);try{let r=this.resolveAndValidate(n,t);return await T.promises.access(r),!0}catch{return!1}}async stat(t){F(t,"stat");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{let s=await T.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){F(t,"lstat");let n=this.toRealPath(t),r=this.validateParent(n,t);try{let s=await T.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){F(t,"mkdir");let r=this.toRealPath(t),s=this.resolveAndValidate(r,t);try{await T.promises.mkdir(s,{recursive:n?.recursive})}catch(i){let a=i;if(a.code==="EEXIST")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(a.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){F(t,"scandir");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{if(!this.allowSymlinks&&(await T.promises.lstat(r)).isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);return(await T.promises.readdir(r,{withFileTypes:!0})).map(i=>({name:i.name,isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink()})).sort((i,a)=>i.name<a.name?-1:i.name>a.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){F(t,"rm");let r=this.toRealPath(t),s=this.validateParent(r,t);try{let i=await T.promises.lstat(s);if(!this.allowSymlinks&&i.isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);await T.promises.rm(s,{recursive:n?.recursive??!1,force:n?.force??!1})}catch(i){let a=i;if(a.code==="ENOENT"){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(a.code==="ENOTEMPTY")throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);this.sanitizeError(i,t,"rm")}}async cp(t,n,r){F(t,"cp"),F(n,"cp");let s=this.toRealPath(t),i=this.toRealPath(n),a=this.resolveAndValidate(s,t),o=this.resolveAndValidate(i,n),l;try{l=await T.promises.lstat(a)}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()&&Ge(o,a))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);try{await this.preflightCopyTree(a,t)}catch(c){this.sanitizeError(c,t,"cp")}try{await T.promises.cp(a,o,{recursive:r?.recursive??!1,filter:async c=>{try{if(T.lstatSync(c).isSymbolicLink()){let f=await T.promises.realpath(c).catch(()=>null);if(f===null||!Ge(f,this.canonicalRoot))throw new Error(`EACCES: permission denied, cp '${t}' contains an unsafe symlink`);return!0}return!0}catch(u){throw u.message?.includes("EACCES")||u.message?.includes("unsafe symlink")?u:new Error(`EIO: cp '${t}' could not validate source tree`)}}})}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 preflightCopyTree(t,n,r=new Set){let s=await T.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 a=await T.promises.realpath(t);if(!Ge(a,this.canonicalRoot))throw new Error(`EACCES: permission denied, cp '${n}' contains an unsafe symlink`);return}if(s.isDirectory()){r.add(i);try{let a=await T.promises.readdir(t);for(let o of a)await this.preflightCopyTree(se.join(t,o),n,r)}finally{r.delete(i)}}}async mv(t,n){F(t,"mv"),F(n,"mv");let r=this.toRealPath(t),s=this.toRealPath(n),i=this.validateParent(r,t),a=this.validateParent(s,n),o;try{o=await T.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(o.isDirectory()&&this.isSameOrDescendantIdentity(i,a))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);try{if(o.isSymbolicLink()){let c=await T.promises.readlink(i),u=se.resolve(se.dirname(a),c),f=await T.promises.realpath(u).catch(()=>u);if(!Ge(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=se.dirname(a);try{await T.promises.mkdir(l,{recursive:!0})}catch(c){this.sanitizeError(c,n,"mv")}try{await T.promises.rename(i,a)}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(T.lstatSync(a).isDirectory()&&this.findEscapingSymlinks(a).length>0)throw await T.promises.rename(a,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 T.promises.rename(a,i).catch(()=>{}),this.sanitizeError(c,n,"mv")}}isSameOrDescendantIdentity(t,n){let r=t,s=n;try{r=T.realpathSync(t)}catch{}try{s=T.realpathSync(n)}catch{try{let i=T.realpathSync(se.dirname(n));s=se.join(i,se.basename(n))}catch{}}return Ge(s,r)}async uniqueTransactionPath(t,n){let r=se.posix.dirname(t);for(let s=0;s<100;s++){let i=this.transactionId++,a=se.posix.join(r,`.just-bash-mv-${n}-${i}`);if(!await this.exists(a))return a}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"),a=this.validateParent(this.toRealPath(r),r),o=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 T.promises.rename(c,l).catch(()=>{}),d&&await T.promises.rm(u,{recursive:!0,force:!0}).catch(()=>{}),f&&await T.promises.rename(o,u).catch(()=>{}),await T.promises.rm(a,{recursive:!0,force:!0}).catch(()=>{})};try{if(await this.cp(t,r,{recursive:!0}),this.findEscapingSymlinks(a).length>0)throw new Error(`EACCES: permission denied, mv '${t}' -> '${n}' would create symlinks escaping sandbox`);try{await T.promises.rename(u,o),f=!0}catch(m){if(m.code!=="ENOENT")throw m}await T.promises.rename(a,u),d=!0,await T.promises.rename(l,c),h=!0,await T.promises.rm(c,{recursive:!0,force:!1}),h=!1,f&&await T.promises.rm(o,{recursive:!0,force:!0}).catch(()=>{})}catch(m){await p(),this.sanitizeError(m,t,"mv")}}resolvePath(t,n){return _t(t,n)}getAllPaths(){let t=[];return this.scanDir("/",t),t}sanitizeError(t,n,r){ks(t,n,r,Up)}findEscapingSymlinks(t){let n=[],r=T.readdirSync(t);for(let s of r){let i=se.join(t,s),a=T.lstatSync(i);if(a.isSymbolicLink()){let o=T.readlinkSync(i),l=se.resolve(t,o),c;try{c=T.realpathSync(l)}catch(u){if(u.code!=="ENOENT")throw u;c=l}Ge(c,this.canonicalRoot)||n.push(i)}else a.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=T.readdirSync(s);for(let a of i){let o=t==="/"?`/${a}`:`${t}/${a}`;n.push(o);let l=se.join(s,a);T.lstatSync(l).isDirectory()&&this.scanDir(o,n)}}catch{}}async chmod(t,n){F(t,"chmod");let r=this.toRealPath(t),s=this.resolveAndValidate(r,t);try{let i=this.allowSymlinks?T.constants.O_RDONLY:T.constants.O_RDONLY|T.constants.O_NOFOLLOW,a=await T.promises.open(s,i);try{await a.chmod(n)}finally{await a.close()}}catch(i){let a=i;if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);if(a.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(i,t,"chmod")}}async symlink(t,n){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${n}'`);F(n,"symlink");let r=this.toRealPath(n),s=this.validateParent(r,n),i=B(n),a=B(se.dirname(i)),o=t.startsWith("/")?B(t):B(a==="/"?`/${t}`:`${a}/${t}`),l=se.join(this.canonicalRoot,o),c=se.dirname(s),u=t.startsWith("/")?l:se.relative(c,l)||".";try{await T.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){F(t,"link"),F(n,"link");let r=this.toRealPath(t),s=this.toRealPath(n),i=this.resolveAndValidate(r,t),a=this.resolveAndValidate(s,n);try{await T.promises.link(i,a)}catch(o){let l=o;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(o,t,"link")}}async readlink(t){F(t,"readlink");let n=this.toRealPath(t),r=this.validateParent(n,t);try{let s=await T.promises.readlink(r),i=B(t),a=se.dirname(i),o=se.isAbsolute(s)?s:se.resolve(se.dirname(r),s),l=await T.promises.realpath(o).catch(()=>o);if(Ge(l,this.canonicalRoot)){let c=l.slice(this.canonicalRoot.length)||"/";return a==="/"?c.startsWith("/")?c.slice(1)||".":c:se.relative(a,c)}return se.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){F(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 T.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(Ge(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){F(t,"utimes");let s=this.toRealPath(t),i=this.resolveAndValidate(s,t);try{let a=this.allowSymlinks?T.constants.O_RDONLY:T.constants.O_RDONLY|T.constants.O_NOFOLLOW,o=await T.promises.open(i,a);try{await o.utimes(n,r)}finally{await o.close()}}catch(a){let o=a;if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);if(o.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(a,t,"utimes")}}};var In=class{cmdId;cwd;startedAt;exitCode;bashEnv;cmdLine;env;explicitCwd;signal;timeoutMs;abortController=new AbortController;timeoutId;externalAbortListener;resultPromise;constructor(t,n,r,s,i=!1,a,o){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=a,this.timeoutMs=o,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=dr(()=>{this.abortController.abort(new Error(`sandbox command timeout after ${t}ms`))},t)}}cleanupCancellation(){this.timeoutId!==void 0&&(hr(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 Cs=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 On({root:t.overlayRoot})}let r=new fr({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,a,o,l=!1,c,u;if(typeof t=="object"){let m=t,E=[m.cmd,...m.args??[]];s=Ls(E),i=m.cwd,a=m.env,o=m.signal,l=m.detached??!1,c=m.stdout,u=m.stderr}else if(Array.isArray(n)){let m=r;s=Ls([t,...n]),o=m?.signal}else{s=t;let m=n;i=m?.cwd,a=m?.env}let f=i??this.bashEnv.getCwd(),d=i!==void 0,h=new In(this.bashEnv,s,f,a,d,o,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 a=this.bashEnv.fs.resolvePath(n,r),o=a.substring(0,a.lastIndexOf("/"))||"/";o!=="/"&&await this.bashEnv.fs.mkdir(o,{recursive:!0}),await this.bashEnv.writeFile(a,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 Ds=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,a=0;for(let o of r)s.add(o.path),i=Math.min(i,o.timestamp),a=Math.max(a,o.timestamp);t.push({type:n,count:r.length,firstSeen:i,lastSeen:a,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 Fu(){return e=>{console.warn("[DefenseInDepth] Security violation detected:",`
782
803
  Type: ${e.type}`,`
783
804
  Path: ${e.path}`,`
784
805
  Message: ${e.message}`,e.executionId?`
785
- ExecutionId: ${e.executionId}`:"")}}var _i=class{plugins=[];use(t){return this.plugins.push(t),this}transform(t){let s=Ce(t),r=Object.create(null);for(let n of this.plugins){let i=n.transform({ast:s,metadata:r});s=i.ast,i.metadata&&(r=cs(r,i.metadata))}return{script:$s(s),ast:s,metadata:r}}};var xi=class{name="command-collector";transform(t){let s=new Set;return this.walkScript(t.ast,s),{ast:t.ast,metadata:{commands:[...s].sort()}}}walkScript(t,s){for(let r of t.statements)this.walkStatement(r,s)}walkStatement(t,s){for(let r of t.pipelines)this.walkPipeline(r,s)}walkPipeline(t,s){for(let r of t.commands)this.walkCommand(r,s)}walkCommand(t,s){switch(t.type){case"SimpleCommand":if(t.name){let r=this.extractName(t.name);r&&s.add(r)}t.name&&this.walkWordParts(t.name.parts,s);for(let r of t.args)this.walkWordParts(r.parts,s);for(let r of t.assignments)if(r.value&&this.walkWordParts(r.value.parts,s),r.array)for(let n of r.array)this.walkWordParts(n.parts,s);break;case"If":for(let r of t.clauses){for(let n of r.condition)this.walkStatement(n,s);for(let n of r.body)this.walkStatement(n,s)}if(t.elseBody)for(let r of t.elseBody)this.walkStatement(r,s);break;case"For":if(t.words)for(let r of t.words)this.walkWordParts(r.parts,s);for(let r of t.body)this.walkStatement(r,s);break;case"CStyleFor":for(let r of t.body)this.walkStatement(r,s);break;case"While":case"Until":for(let r of t.condition)this.walkStatement(r,s);for(let r of t.body)this.walkStatement(r,s);break;case"Case":this.walkWordParts(t.word.parts,s);for(let r of t.items)for(let n of r.body)this.walkStatement(n,s);break;case"Subshell":case"Group":for(let r of t.body)this.walkStatement(r,s);break;case"ArithmeticCommand":case"ConditionalCommand":break;case"FunctionDef":this.walkCommand(t.body,s);break}}walkWordParts(t,s){for(let r of t)switch(r.type){case"CommandSubstitution":this.walkScript(r.body,s);break;case"ProcessSubstitution":this.walkScript(r.body,s);break;case"DoubleQuoted":this.walkWordParts(r.parts,s);break;case"ParameterExpansion":r.operation&&this.walkParameterOp(r.operation,s);break}}walkParameterOp(t,s){switch(t.type){case"DefaultValue":case"AssignDefault":case"UseAlternative":this.walkWordParts(t.word.parts,s);break;case"ErrorIfUnset":t.word&&this.walkWordParts(t.word.parts,s);break;case"PatternRemoval":this.walkWordParts(t.pattern.parts,s);break;case"PatternReplacement":this.walkWordParts(t.pattern.parts,s),t.replacement&&this.walkWordParts(t.replacement.parts,s);break;case"CaseModification":t.pattern&&this.walkWordParts(t.pattern.parts,s);break;case"Indirection":t.innerOp&&this.walkParameterOp(t.innerOp,s);break}}extractName(t){return t.parts.length===1&&t.parts[0].type==="Literal"?t.parts[0].value:null}};var Ci=class{name="tee";options;counter=0;constructor(t){this.options=t}transform(t){let s=[],r=this.options.timestamp??new Date;return{ast:this.transformScript(t.ast,s,r),metadata:{teeFiles:s}}}formatTimestamp(t){return t.toISOString().replace(/:/g,"-")}generateStdoutPath(t,s,r){let n=this.formatTimestamp(r),i=String(t).padStart(3,"0");return`${this.options.outputDir}/${n}-${i}-${s}.stdout.txt`}transformScript(t,s,r){return{...t,statements:t.statements.map(n=>this.transformStatement(n,s,r))}}transformStatement(t,s,r){let n=[],i=[];for(let a=0;a<t.pipelines.length;a++){let l=t.pipelines[a];a>0&&i.push(t.operators[a-1]);let o=this.transformPipeline(l,s,r);if(n.push(o.pipeline),o.origCmdNewIndices!==null){let u=o.origCmdNewIndices;i.push(";"),n.push(this.makePipestatusSave(u)),i.push(";"),n.push(this.makePipestatusRestore(u.length,o.negated))}}return{...t,pipelines:n,operators:i}}transformPipeline(t,s,r){if(t.commands.length<=1)return{pipeline:t,origCmdNewIndices:null,negated:!1};let n=[],i=[],a=[],l=!1;for(let o=0;o<t.commands.length;o++){let u=t.commands[o],c=o===t.commands.length-1;if(u.type!=="SimpleCommand"||!u.name||!this.shouldTarget(u)){a.push(n.length),n.push(u),c||i.push(t.pipeStderr?.[o]??!1);continue}let f=this.getCommandName(u.name)??"unknown",d=this.counter++,h=this.generateStdoutPath(d,f,r),m=this.makeTeeCommand(h),p=this.serializeCommand(u);s.push({commandIndex:d,commandName:f,command:p,stdoutFile:h}),a.push(n.length),n.push(u),i.push(t.pipeStderr?.[o]??!1),n.push(m),c||i.push(!1),l=!0}return l?{pipeline:{...t,negated:!1,commands:n,pipeStderr:i.length>0?i:void 0},origCmdNewIndices:a,negated:t.negated}:{pipeline:t,origCmdNewIndices:null,negated:!1}}makePipestatusSave(t){return{type:"Pipeline",commands:[{type:"SimpleCommand",assignments:t.map((s,r)=>({type:"Assignment",name:`__tps${r}`,value:{type:"Word",parts:[{type:"ParameterExpansion",parameter:`PIPESTATUS[${s}]`,operation:null}]},append:!1,array:null})),name:null,args:[],redirections:[]}],negated:!1}}makePipestatusRestore(t,s){let r=[];for(let n=0;n<t;n++)r.push({type:"Subshell",body:[{type:"Statement",pipelines:[{type:"Pipeline",commands:[{type:"SimpleCommand",assignments:[],name:{type:"Word",parts:[{type:"Literal",value:"exit"}]},args:[{type:"Word",parts:[{type:"ParameterExpansion",parameter:`__tps${n}`,operation:null}]}],redirections:[]}],negated:!1}],operators:[],background:!1}],redirections:[]});return{type:"Pipeline",commands:r,negated:s}}shouldTarget(t){if(!this.options.targetCommandPattern)return!0;let s=this.getCommandName(t.name);return s!==null&&this.options.targetCommandPattern.test(s)}getCommandName(t){return t&&t.parts.length===1&&t.parts[0].type==="Literal"?t.parts[0].value:null}serializeCommand(t){let s=[];t.name&&s.push(be(t.name));for(let r of t.args)s.push(be(r));return s.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{Ps as Bash,_i as BashTransformPipeline,xi as CommandCollectorPlugin,Ie as DefenseInDepthBox,Cc as EMPTY_BYTES,ht as InMemoryFs,Rn as MountableFs,Xe as NetworkAccessDeniedError,rs as OverlayFs,Ln as ReadWriteFs,ss as RedirectNotAllowedError,Mn as Sandbox,is as SandboxCommand,gt as SecurityViolationError,Wn as SecurityViolationLogger,Ci as TeePlugin,ts as TooManyRedirectsError,Ic as bytesOutput,Pc as createConsoleViolationCallback,xc as decodeBytesToUtf8,Wc as defineCommand,yt as encodeUtf8ToBytes,Oc as getCommandNames,Mc as getJavaScriptCommandNames,Tc as getNetworkCommandNames,Lc as getPythonCommandNames,_s as latin1FromBytes,Ce as parse,$s as serialize,Cs as stdoutAsBytes,Dc as stdoutKind,Rc as textOutput,os as unsafeBytesFromLatin1};
806
+ ExecutionId: ${e.executionId}`:"")}}var Vu=null;try{let e=process.getBuiltinModule,t=typeof e=="function"?e("module"):typeof Is=="function"?Is("node:module"):null;Vu=t?.Module??t?.default??null,typeof e=="function"&&e("worker_threads")?.isMainThread===!1&&e("crypto")?.randomUUID?.()}catch{Vu=null}var Da=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){cr(t,this.maxSourceBytes);let n=qe(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=Fn(r,i.metadata))}return{script:ur(n),ast:n,metadata:r}}};var Ra=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 Oa=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(F(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 a=B(this.options.outputDir),o=this.encodeCommandName(n),l=B(`${a}/${s}-${i}-${o}.stdout.txt`);if(a!=="/"&&!l.startsWith(`${a}/`))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 a=0;a<t.pipelines.length;a++){let o=t.pipelines[a];a>0&&i.push(t.operators[a-1]);let l=this.transformPipeline(o,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=[],a=[],o=!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)){a.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}),a.push(s.length),s.push(c),i.push(t.pipeStderr?.[l]??!1),s.push(p),u||i.push(!1),o=!0}return o?{pipeline:{...t,negated:!1,commands:s,pipeStderr:i.length>0?i:void 0},origCmdNewIndices:a,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($e(t.name));for(let r of t.args)n.push($e(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{fr as Bash,Da as BashTransformPipeline,Ra as CommandCollectorPlugin,Ie as DefenseInDepthBox,_s as EMPTY_BYTES,$t as InMemoryFs,xs as MountableFs,Je as NetworkAccessDeniedError,On as OverlayFs,Ns as ReadWriteFs,Cn as RedirectNotAllowedError,Cs as Sandbox,In as SandboxCommand,Ct as SecurityViolationError,Ds as SecurityViolationLogger,Oa as TeePlugin,Nn as TooManyRedirectsError,Hu as bytesOutput,ef as createCommandContext,Fu as createConsoleViolationCallback,ju as decodeBytesToUtf8,tf as defineCommand,Dt as encodeUtf8ToBytes,Qu as getCommandNames,Yu as getJavaScriptCommandNames,Ku as getNetworkCommandNames,Xu as getPythonCommandNames,Bn as latin1FromBytes,qe as parse,ur as serialize,yr as stdoutAsBytes,Gu as stdoutKind,Zu as textOutput,Mn as unsafeBytesFromLatin1};