just-bash 3.4.1 → 3.6.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 (457) hide show
  1. package/CHANGELOG.md +248 -0
  2. package/README.md +22 -9
  3. package/dist/AGENTS.md +58 -2
  4. package/dist/Bash.d.ts +4 -2
  5. package/dist/abort-signals.d.ts +10 -0
  6. package/dist/bin/chunks/awk2-U22OR5B5.js +3 -0
  7. package/dist/bin/{shell/chunks/base64-FLJ4YPHB.js → chunks/base64-2KKH5BCT.js} +1 -1
  8. package/dist/bin/chunks/{cat-2J5MA5PY.js → cat-V45MVNBT.js} +1 -1
  9. package/dist/bin/{shell/chunks/chmod-ZM5WLMZI.js → chunks/chmod-A54R4UUQ.js} +1 -1
  10. package/dist/bin/chunks/chunk-2NJJXU4K.js +27 -0
  11. package/dist/bin/{shell/chunks/chunk-BJRT4VKD.js → chunks/chunk-3LKMI5IX.js} +1 -1
  12. package/dist/bin/{shell/chunks/chunk-4APSDE57.js → chunks/chunk-44SKMHU6.js} +1 -1
  13. package/dist/bin/chunks/{chunk-GRP7L2EL.js → chunk-6DAR25KN.js} +1 -1
  14. package/dist/bin/{shell/chunks/chunk-VGR3NA3H.js → chunks/chunk-723HNGID.js} +1 -1
  15. package/dist/bin/{shell/chunks/chunk-MRPJL3ZK.js → chunks/chunk-7X4QBCFW.js} +1 -1
  16. package/dist/bin/chunks/{chunk-42AMF6EE.js → chunk-ABM5WFEO.js} +1 -1
  17. package/dist/bin/chunks/{chunk-2HFDEZUY.js → chunk-AINNAQBQ.js} +1 -1
  18. package/dist/bin/{shell/chunks/chunk-BPWZ7ADB.js → chunks/chunk-AL7RVSF4.js} +1 -1
  19. package/dist/bin/{shell/chunks/chunk-MHAGHCSO.js → chunks/chunk-ARYCSNJJ.js} +7 -7
  20. package/dist/bin/{shell/chunks/chunk-2INNLNI5.js → chunks/chunk-BJF6B4YW.js} +1 -1
  21. package/dist/bin/{shell/chunks/chunk-BZWGVRFA.js → chunks/chunk-BOXG6XBN.js} +2 -2
  22. package/dist/bin/chunks/chunk-DA3RFNKK.js +17 -0
  23. package/dist/bin/chunks/chunk-DH7M46D3.js +20 -0
  24. package/dist/bin/chunks/{chunk-2ND6MMXN.js → chunk-DTGQQKI2.js} +1 -1
  25. package/dist/bin/chunks/{chunk-YOIFOOGX.js → chunk-ECZAFQ22.js} +1 -1
  26. package/dist/bin/chunks/{chunk-PPVF2N6C.js → chunk-EFS34UUR.js} +1 -1
  27. package/dist/bin/{shell/chunks/chunk-TW2IJRUF.js → chunks/chunk-ENEHPI32.js} +1 -1
  28. package/dist/bin/chunks/chunk-HFW2LXQV.js +13 -0
  29. package/dist/bin/{shell/chunks/chunk-UHNV55NF.js → chunks/chunk-HRKG3ZK2.js} +1 -1
  30. package/dist/bin/chunks/{chunk-74TZ7ZF7.js → chunk-IKUY74NG.js} +1 -1
  31. package/dist/bin/chunks/chunk-ILXMFIYG.js +7 -0
  32. package/dist/bin/chunks/chunk-IMVXTSPG.js +275 -0
  33. package/dist/bin/chunks/chunk-J5L5DJWL.js +3 -0
  34. package/dist/bin/{shell/chunks/chunk-MF3GVFLC.js → chunks/chunk-JKS7WXGR.js} +1 -1
  35. package/dist/bin/{shell/chunks/chunk-XBX7KFWK.js → chunks/chunk-LG6IN6SW.js} +11 -11
  36. package/dist/bin/chunks/chunk-LMFAALLO.js +21 -0
  37. package/dist/bin/{shell/chunks/chunk-DYIBFLS3.js → chunks/chunk-LOU52GPJ.js} +2 -2
  38. package/dist/bin/chunks/{chunk-FB44CW33.js → chunk-M5ZBECGM.js} +1 -1
  39. package/dist/bin/chunks/chunk-MA6BMA4M.js +3 -0
  40. package/dist/bin/chunks/{chunk-Z7QCL4IA.js → chunk-MPQMTLXN.js} +1 -1
  41. package/dist/bin/chunks/{chunk-TIHFGNPS.js → chunk-MUIYG2RB.js} +1 -1
  42. package/dist/bin/chunks/{chunk-PUZGSIMN.js → chunk-NGMFI3RH.js} +1 -1
  43. package/dist/bin/{shell/chunks/chunk-RYQB6GQ7.js → chunks/chunk-NLMTGTSG.js} +1 -1
  44. package/dist/bin/chunks/{chunk-QAYU7HPM.js → chunk-OBVTFHVP.js} +1 -1
  45. package/dist/bin/chunks/{chunk-MNSMZU47.js → chunk-OOKVPG5D.js} +1 -1
  46. package/dist/bin/{shell/chunks/chunk-O2BCKSMK.js → chunks/chunk-PEJXCXSY.js} +1 -1
  47. package/dist/bin/{shell/chunks/chunk-MYEPQX6Y.js → chunks/chunk-PL4EU7Y2.js} +1 -1
  48. package/dist/bin/chunks/{chunk-QFTZKD5O.js → chunk-QCGH2ZOW.js} +1 -1
  49. package/dist/bin/chunks/chunk-QKWMWSV3.js +3 -0
  50. package/dist/bin/{shell/chunks/chunk-ISOWCECJ.js → chunks/chunk-S5Z7DMIE.js} +10 -10
  51. package/dist/bin/{shell/chunks/chunk-OLEQNRKX.js → chunks/chunk-SQ7SZZMW.js} +1 -1
  52. package/dist/bin/{shell/chunks/chunk-44MQ5AXA.js → chunks/chunk-SQUH76NP.js} +1 -1
  53. package/dist/bin/{shell/chunks/chunk-BOYPCOSV.js → chunks/chunk-TGRZ42DS.js} +1 -1
  54. package/dist/bin/chunks/{chunk-LUHU7UUN.js → chunk-THTKNRO6.js} +1 -1
  55. package/dist/bin/chunks/{chunk-VKTV45AP.js → chunk-TQXLQEIT.js} +1 -1
  56. package/dist/bin/{shell/chunks/chunk-2OQ5HPZE.js → chunks/chunk-U6BXPMLD.js} +1 -1
  57. package/dist/bin/chunks/chunk-U6DBRMD5.js +5 -0
  58. package/dist/bin/{shell/chunks/chunk-CC2AQ6B7.js → chunks/chunk-U6JTVQU6.js} +1 -1
  59. package/dist/bin/chunks/chunk-UPUFWGHR.js +3 -0
  60. package/dist/bin/chunks/{chunk-E5VZGTZ6.js → chunk-URRH3GPG.js} +1 -1
  61. package/dist/bin/chunks/{chunk-EXGPMLIE.js → chunk-VBU3UEG5.js} +1 -1
  62. package/dist/bin/chunks/chunk-VGSRQOLD.js +7 -0
  63. package/dist/bin/chunks/{chunk-GTULZ3ZD.js → chunk-WBST7XJW.js} +1 -1
  64. package/dist/bin/chunks/{chunk-ROFYAVPF.js → chunk-WEQ5WM2M.js} +1 -1
  65. package/dist/bin/{shell/chunks/chunk-BCQSUELK.js → chunks/chunk-WZ7MIBLR.js} +1 -1
  66. package/dist/bin/chunks/{chunk-H4BRFPKY.js → chunk-X45GP3AQ.js} +1 -1
  67. package/dist/bin/chunks/chunk-YQEKKZTU.js +12 -0
  68. package/dist/bin/chunks/{chunk-UNKX6YM6.js → chunk-Z3KAV6YJ.js} +1 -1
  69. package/dist/bin/chunks/{chunk-3SCW7PD5.js → chunk-Z5KICK5X.js} +1 -1
  70. package/dist/bin/chunks/{column-7VBJL757.js → column-LHHS4D3K.js} +1 -1
  71. package/dist/bin/{shell/chunks/cp-MF5GADQN.js → chunks/cp-HPLQA35N.js} +1 -1
  72. package/dist/bin/chunks/curl-FIRG3RB6.js +31 -0
  73. package/dist/bin/chunks/{cut-QOTYBJJJ.js → cut-KP3S36XS.js} +1 -1
  74. package/dist/bin/{shell/chunks/diff-YXZZCUSQ.js → chunks/diff-JSJ56EOK.js} +1 -1
  75. package/dist/bin/chunks/dist-4NZ74CRE.js +141 -0
  76. package/dist/bin/chunks/{du-A3UGHIKJ.js → du-WEF5YWQK.js} +1 -1
  77. package/dist/bin/chunks/{expr-TDF3B6QJ.js → expr-FLWT4OCO.js} +1 -1
  78. package/dist/bin/chunks/{file-AJGG7RYT.js → file-JLUCGBCB.js} +1 -1
  79. package/dist/bin/chunks/{find-6DH6TRDN.js → find-XGVQ6N6L.js} +1 -1
  80. package/dist/bin/chunks/flag-coverage-4JYKIAVV.js +3 -0
  81. package/dist/bin/chunks/{grep-WUZMZDGY.js → grep-DCPCPQOS.js} +1 -1
  82. package/dist/bin/chunks/{gzip-JA7JQBUS.js → gzip-6DZIKNBW.js} +1 -1
  83. package/dist/bin/{shell/chunks/head-YGKW3HS4.js → chunks/head-TLFXMM2T.js} +1 -1
  84. package/dist/bin/{shell/chunks/help-HVIDHJ6M.js → chunks/help-EXVKU23F.js} +1 -1
  85. package/dist/bin/chunks/{html-to-markdown-ZWL7LZIP.js → html-to-markdown-E22RLT2U.js} +1 -1
  86. package/dist/bin/chunks/{jq-5MI4V3G5.js → jq-GDM3OBBK.js} +1 -1
  87. package/dist/bin/chunks/js-exec-VU6F6WLS.js +1578 -0
  88. package/dist/bin/chunks/{ln-XSDIE6SU.js → ln-B35EKC2Q.js} +1 -1
  89. package/dist/bin/chunks/{ls-R6DAGGBH.js → ls-67NUUIYT.js} +1 -1
  90. package/dist/bin/chunks/{mkdir-74BP5NTG.js → mkdir-AWDWRBKC.js} +1 -1
  91. package/dist/bin/chunks/mktemp-L6OGMDUO.js +3 -0
  92. package/dist/bin/chunks/{mv-YG75IRRE.js → mv-4BJSOT4Y.js} +1 -1
  93. package/dist/bin/{shell/chunks/od-YCY27MMO.js → chunks/od-SI75GLRE.js} +1 -1
  94. package/dist/bin/chunks/{paste-ACKOG3XS.js → paste-5TSIBDF7.js} +1 -1
  95. package/dist/bin/chunks/python3-GUWCSSDP.js +23 -0
  96. package/dist/bin/{shell/chunks/readlink-HMHVGSAM.js → chunks/readlink-URO5XTBB.js} +1 -1
  97. package/dist/bin/{shell/chunks/rg-A3E7YM2A.js → chunks/rg-RVULUPDH.js} +1 -1
  98. package/dist/bin/{shell/chunks/rm-3PLW4O4B.js → chunks/rm-UCUTHC3I.js} +1 -1
  99. package/dist/bin/chunks/{rmdir-DCJ3XJRR.js → rmdir-J3HM7GGM.js} +1 -1
  100. package/dist/bin/{shell/chunks/sed-KJWKB22J.js → chunks/sed-MCLGHZOI.js} +1 -1
  101. package/dist/bin/chunks/{seq-Q4LZ6EXV.js → seq-I54NZE75.js} +1 -1
  102. package/dist/bin/{shell/chunks/sleep-DVFE2GSF.js → chunks/sleep-CV6B4M6W.js} +1 -1
  103. package/dist/bin/chunks/{split-XMXBXL5Q.js → split-VZO7223N.js} +1 -1
  104. package/dist/bin/chunks/{sqlite3-DNH2VLVN.js → sqlite3-HXVFVP4Z.js} +1 -1
  105. package/dist/bin/chunks/sqlite3-worker.js +75 -11
  106. package/dist/bin/chunks/{stat-5PUSTPTK.js → stat-UJ37RBMM.js} +1 -1
  107. package/dist/bin/chunks/{tail-4MB7HHIZ.js → tail-5TSF5YM4.js} +1 -1
  108. package/dist/bin/{shell/chunks/tar-FRDUJZDN.js → chunks/tar-ZGZZDQXO.js} +1 -1
  109. package/dist/bin/chunks/{time-LF7BTSK5.js → time-J2DAZUIN.js} +1 -1
  110. package/dist/bin/chunks/timeout-ATTDYXLX.js +3 -0
  111. package/dist/bin/chunks/{tr-Z6N34HZM.js → tr-6RPFASYV.js} +1 -1
  112. package/dist/bin/chunks/worker.js +88 -15
  113. package/dist/bin/chunks/{xan-VSF6ZQGZ.js → xan-CCS53B7D.js} +1 -1
  114. package/dist/bin/chunks/{xan-view-UEFBHYVN.js → xan-view-KOXASOEV.js} +1 -1
  115. package/dist/bin/chunks/yes-ELH3XQWY.js +3 -0
  116. package/dist/bin/chunks/yq-GSCDUHGM.js +3 -0
  117. package/dist/bin/just-bash.js +333 -328
  118. package/dist/bin/shell/chunks/awk2-U22OR5B5.js +3 -0
  119. package/dist/bin/{chunks/base64-FLJ4YPHB.js → shell/chunks/base64-2KKH5BCT.js} +1 -1
  120. package/dist/bin/shell/chunks/{cat-2J5MA5PY.js → cat-V45MVNBT.js} +1 -1
  121. package/dist/bin/{chunks/chmod-ZM5WLMZI.js → shell/chunks/chmod-A54R4UUQ.js} +1 -1
  122. package/dist/bin/shell/chunks/chunk-2NJJXU4K.js +27 -0
  123. package/dist/bin/{chunks/chunk-BJRT4VKD.js → shell/chunks/chunk-3LKMI5IX.js} +1 -1
  124. package/dist/bin/{chunks/chunk-4APSDE57.js → shell/chunks/chunk-44SKMHU6.js} +1 -1
  125. package/dist/bin/shell/chunks/{chunk-GRP7L2EL.js → chunk-6DAR25KN.js} +1 -1
  126. package/dist/bin/{chunks/chunk-VGR3NA3H.js → shell/chunks/chunk-723HNGID.js} +1 -1
  127. package/dist/bin/{chunks/chunk-MRPJL3ZK.js → shell/chunks/chunk-7X4QBCFW.js} +1 -1
  128. package/dist/bin/shell/chunks/{chunk-42AMF6EE.js → chunk-ABM5WFEO.js} +1 -1
  129. package/dist/bin/shell/chunks/{chunk-2HFDEZUY.js → chunk-AINNAQBQ.js} +1 -1
  130. package/dist/bin/{chunks/chunk-BPWZ7ADB.js → shell/chunks/chunk-AL7RVSF4.js} +1 -1
  131. package/dist/bin/{chunks/chunk-MHAGHCSO.js → shell/chunks/chunk-ARYCSNJJ.js} +7 -7
  132. package/dist/bin/{chunks/chunk-2INNLNI5.js → shell/chunks/chunk-BJF6B4YW.js} +1 -1
  133. package/dist/bin/{chunks/chunk-BZWGVRFA.js → shell/chunks/chunk-BOXG6XBN.js} +2 -2
  134. package/dist/bin/shell/chunks/chunk-DA3RFNKK.js +17 -0
  135. package/dist/bin/shell/chunks/chunk-DH7M46D3.js +20 -0
  136. package/dist/bin/shell/chunks/{chunk-2ND6MMXN.js → chunk-DTGQQKI2.js} +1 -1
  137. package/dist/bin/shell/chunks/{chunk-YOIFOOGX.js → chunk-ECZAFQ22.js} +1 -1
  138. package/dist/bin/shell/chunks/{chunk-PPVF2N6C.js → chunk-EFS34UUR.js} +1 -1
  139. package/dist/bin/{chunks/chunk-TW2IJRUF.js → shell/chunks/chunk-ENEHPI32.js} +1 -1
  140. package/dist/bin/shell/chunks/chunk-HFW2LXQV.js +13 -0
  141. package/dist/bin/{chunks/chunk-UHNV55NF.js → shell/chunks/chunk-HRKG3ZK2.js} +1 -1
  142. package/dist/bin/shell/chunks/{chunk-74TZ7ZF7.js → chunk-IKUY74NG.js} +1 -1
  143. package/dist/bin/shell/chunks/chunk-ILXMFIYG.js +7 -0
  144. package/dist/bin/shell/chunks/chunk-IMVXTSPG.js +275 -0
  145. package/dist/bin/shell/chunks/chunk-J5L5DJWL.js +3 -0
  146. package/dist/bin/{chunks/chunk-MF3GVFLC.js → shell/chunks/chunk-JKS7WXGR.js} +1 -1
  147. package/dist/bin/{chunks/chunk-XBX7KFWK.js → shell/chunks/chunk-LG6IN6SW.js} +11 -11
  148. package/dist/bin/shell/chunks/chunk-LMFAALLO.js +21 -0
  149. package/dist/bin/{chunks/chunk-DYIBFLS3.js → shell/chunks/chunk-LOU52GPJ.js} +2 -2
  150. package/dist/bin/shell/chunks/{chunk-FB44CW33.js → chunk-M5ZBECGM.js} +1 -1
  151. package/dist/bin/shell/chunks/chunk-MA6BMA4M.js +3 -0
  152. package/dist/bin/shell/chunks/{chunk-Z7QCL4IA.js → chunk-MPQMTLXN.js} +1 -1
  153. package/dist/bin/shell/chunks/{chunk-TIHFGNPS.js → chunk-MUIYG2RB.js} +1 -1
  154. package/dist/bin/shell/chunks/{chunk-PUZGSIMN.js → chunk-NGMFI3RH.js} +1 -1
  155. package/dist/bin/{chunks/chunk-RYQB6GQ7.js → shell/chunks/chunk-NLMTGTSG.js} +1 -1
  156. package/dist/bin/shell/chunks/{chunk-QAYU7HPM.js → chunk-OBVTFHVP.js} +1 -1
  157. package/dist/bin/shell/chunks/{chunk-MNSMZU47.js → chunk-OOKVPG5D.js} +1 -1
  158. package/dist/bin/{chunks/chunk-O2BCKSMK.js → shell/chunks/chunk-PEJXCXSY.js} +1 -1
  159. package/dist/bin/{chunks/chunk-MYEPQX6Y.js → shell/chunks/chunk-PL4EU7Y2.js} +1 -1
  160. package/dist/bin/shell/chunks/{chunk-QFTZKD5O.js → chunk-QCGH2ZOW.js} +1 -1
  161. package/dist/bin/shell/chunks/chunk-QKWMWSV3.js +3 -0
  162. package/dist/bin/{chunks/chunk-ISOWCECJ.js → shell/chunks/chunk-S5Z7DMIE.js} +10 -10
  163. package/dist/bin/{chunks/chunk-OLEQNRKX.js → shell/chunks/chunk-SQ7SZZMW.js} +1 -1
  164. package/dist/bin/{chunks/chunk-44MQ5AXA.js → shell/chunks/chunk-SQUH76NP.js} +1 -1
  165. package/dist/bin/{chunks/chunk-BOYPCOSV.js → shell/chunks/chunk-TGRZ42DS.js} +1 -1
  166. package/dist/bin/shell/chunks/{chunk-LUHU7UUN.js → chunk-THTKNRO6.js} +1 -1
  167. package/dist/bin/shell/chunks/{chunk-VKTV45AP.js → chunk-TQXLQEIT.js} +1 -1
  168. package/dist/bin/{chunks/chunk-2OQ5HPZE.js → shell/chunks/chunk-U6BXPMLD.js} +1 -1
  169. package/dist/bin/shell/chunks/chunk-U6DBRMD5.js +5 -0
  170. package/dist/bin/{chunks/chunk-CC2AQ6B7.js → shell/chunks/chunk-U6JTVQU6.js} +1 -1
  171. package/dist/bin/shell/chunks/chunk-UPUFWGHR.js +3 -0
  172. package/dist/bin/shell/chunks/{chunk-E5VZGTZ6.js → chunk-URRH3GPG.js} +1 -1
  173. package/dist/bin/shell/chunks/{chunk-EXGPMLIE.js → chunk-VBU3UEG5.js} +1 -1
  174. package/dist/bin/shell/chunks/chunk-VGSRQOLD.js +7 -0
  175. package/dist/bin/shell/chunks/{chunk-GTULZ3ZD.js → chunk-WBST7XJW.js} +1 -1
  176. package/dist/bin/shell/chunks/{chunk-ROFYAVPF.js → chunk-WEQ5WM2M.js} +1 -1
  177. package/dist/bin/{chunks/chunk-BCQSUELK.js → shell/chunks/chunk-WZ7MIBLR.js} +1 -1
  178. package/dist/bin/shell/chunks/{chunk-H4BRFPKY.js → chunk-X45GP3AQ.js} +1 -1
  179. package/dist/bin/shell/chunks/chunk-YQEKKZTU.js +12 -0
  180. package/dist/bin/shell/chunks/{chunk-UNKX6YM6.js → chunk-Z3KAV6YJ.js} +1 -1
  181. package/dist/bin/shell/chunks/{chunk-3SCW7PD5.js → chunk-Z5KICK5X.js} +1 -1
  182. package/dist/bin/shell/chunks/{column-7VBJL757.js → column-LHHS4D3K.js} +1 -1
  183. package/dist/bin/{chunks/cp-MF5GADQN.js → shell/chunks/cp-HPLQA35N.js} +1 -1
  184. package/dist/bin/shell/chunks/curl-FIRG3RB6.js +31 -0
  185. package/dist/bin/shell/chunks/{cut-QOTYBJJJ.js → cut-KP3S36XS.js} +1 -1
  186. package/dist/bin/{chunks/diff-YXZZCUSQ.js → shell/chunks/diff-JSJ56EOK.js} +1 -1
  187. package/dist/bin/shell/chunks/dist-4NZ74CRE.js +141 -0
  188. package/dist/bin/shell/chunks/{du-A3UGHIKJ.js → du-WEF5YWQK.js} +1 -1
  189. package/dist/bin/shell/chunks/{expr-TDF3B6QJ.js → expr-FLWT4OCO.js} +1 -1
  190. package/dist/bin/shell/chunks/{file-AJGG7RYT.js → file-JLUCGBCB.js} +1 -1
  191. package/dist/bin/shell/chunks/{find-6DH6TRDN.js → find-XGVQ6N6L.js} +1 -1
  192. package/dist/bin/shell/chunks/flag-coverage-4JYKIAVV.js +3 -0
  193. package/dist/bin/shell/chunks/{grep-WUZMZDGY.js → grep-DCPCPQOS.js} +1 -1
  194. package/dist/bin/shell/chunks/{gzip-JA7JQBUS.js → gzip-6DZIKNBW.js} +1 -1
  195. package/dist/bin/{chunks/head-YGKW3HS4.js → shell/chunks/head-TLFXMM2T.js} +1 -1
  196. package/dist/bin/{chunks/help-HVIDHJ6M.js → shell/chunks/help-EXVKU23F.js} +1 -1
  197. package/dist/bin/shell/chunks/{html-to-markdown-ZWL7LZIP.js → html-to-markdown-E22RLT2U.js} +1 -1
  198. package/dist/bin/shell/chunks/{jq-5MI4V3G5.js → jq-GDM3OBBK.js} +1 -1
  199. package/dist/bin/shell/chunks/js-exec-VU6F6WLS.js +1578 -0
  200. package/dist/bin/shell/chunks/{ln-XSDIE6SU.js → ln-B35EKC2Q.js} +1 -1
  201. package/dist/bin/shell/chunks/{ls-R6DAGGBH.js → ls-67NUUIYT.js} +1 -1
  202. package/dist/bin/shell/chunks/{mkdir-74BP5NTG.js → mkdir-AWDWRBKC.js} +1 -1
  203. package/dist/bin/shell/chunks/mktemp-L6OGMDUO.js +3 -0
  204. package/dist/bin/shell/chunks/{mv-YG75IRRE.js → mv-4BJSOT4Y.js} +1 -1
  205. package/dist/bin/{chunks/od-YCY27MMO.js → shell/chunks/od-SI75GLRE.js} +1 -1
  206. package/dist/bin/shell/chunks/{paste-ACKOG3XS.js → paste-5TSIBDF7.js} +1 -1
  207. package/dist/bin/shell/chunks/python3-GUWCSSDP.js +23 -0
  208. package/dist/bin/{chunks/readlink-HMHVGSAM.js → shell/chunks/readlink-URO5XTBB.js} +1 -1
  209. package/dist/bin/{chunks/rg-A3E7YM2A.js → shell/chunks/rg-RVULUPDH.js} +1 -1
  210. package/dist/bin/{chunks/rm-3PLW4O4B.js → shell/chunks/rm-UCUTHC3I.js} +1 -1
  211. package/dist/bin/shell/chunks/{rmdir-DCJ3XJRR.js → rmdir-J3HM7GGM.js} +1 -1
  212. package/dist/bin/{chunks/sed-KJWKB22J.js → shell/chunks/sed-MCLGHZOI.js} +1 -1
  213. package/dist/bin/shell/chunks/{seq-Q4LZ6EXV.js → seq-I54NZE75.js} +1 -1
  214. package/dist/bin/{chunks/sleep-DVFE2GSF.js → shell/chunks/sleep-CV6B4M6W.js} +1 -1
  215. package/dist/bin/shell/chunks/{split-XMXBXL5Q.js → split-VZO7223N.js} +1 -1
  216. package/dist/bin/shell/chunks/{sqlite3-DNH2VLVN.js → sqlite3-HXVFVP4Z.js} +1 -1
  217. package/dist/bin/shell/chunks/{stat-5PUSTPTK.js → stat-UJ37RBMM.js} +1 -1
  218. package/dist/bin/shell/chunks/{tail-4MB7HHIZ.js → tail-5TSF5YM4.js} +1 -1
  219. package/dist/bin/{chunks/tar-FRDUJZDN.js → shell/chunks/tar-ZGZZDQXO.js} +1 -1
  220. package/dist/bin/shell/chunks/{time-LF7BTSK5.js → time-J2DAZUIN.js} +1 -1
  221. package/dist/bin/shell/chunks/timeout-ATTDYXLX.js +3 -0
  222. package/dist/bin/shell/chunks/{tr-Z6N34HZM.js → tr-6RPFASYV.js} +1 -1
  223. package/dist/bin/shell/chunks/{xan-VSF6ZQGZ.js → xan-CCS53B7D.js} +1 -1
  224. package/dist/bin/shell/chunks/{xan-view-UEFBHYVN.js → xan-view-KOXASOEV.js} +1 -1
  225. package/dist/bin/shell/chunks/yes-ELH3XQWY.js +3 -0
  226. package/dist/bin/shell/chunks/yq-GSCDUHGM.js +3 -0
  227. package/dist/bin/shell/shell.js +334 -329
  228. package/dist/browser.d.ts +1 -1
  229. package/dist/bundle/browser.js +866 -836
  230. package/dist/bundle/chunks/awk2-V7KYQWCD.js +2 -0
  231. package/dist/bundle/chunks/{base64-2BAITDZF.js → base64-QPSYZAAJ.js} +1 -1
  232. package/dist/bundle/chunks/{cat-33KGN4MZ.js → cat-54BXBS6X.js} +1 -1
  233. package/dist/bundle/chunks/{chmod-APOXUPXW.js → chmod-4OPV4QKK.js} +1 -1
  234. package/dist/bundle/chunks/{chunk-IBRT3OJS.js → chunk-2WBUTDF5.js} +1 -1
  235. package/dist/bundle/chunks/{chunk-WNH3HOQA.js → chunk-353VO5TF.js} +1 -1
  236. package/dist/bundle/chunks/chunk-3HDTNUL3.js +6 -0
  237. package/dist/bundle/chunks/{chunk-XV2V56NQ.js → chunk-3KWM4FFA.js} +1 -1
  238. package/dist/bundle/chunks/{chunk-WXPNKIIH.js → chunk-43OP7DFL.js} +1 -1
  239. package/dist/bundle/chunks/{chunk-DMWNBCXJ.js → chunk-4GEHRJMD.js} +1 -1
  240. package/dist/bundle/chunks/{chunk-3CBCABOZ.js → chunk-4IMUNIUJ.js} +1 -1
  241. package/dist/bundle/chunks/chunk-5BMPT6SF.js +19 -0
  242. package/dist/bundle/chunks/{chunk-XPDOK3XY.js → chunk-5QWGR2WA.js} +1 -1
  243. package/dist/bundle/chunks/{chunk-X3TZEFQG.js → chunk-5UTZMNI5.js} +1 -1
  244. package/dist/bundle/chunks/{chunk-QPZVR6ZN.js → chunk-65LVAUWW.js} +1 -1
  245. package/dist/bundle/chunks/{chunk-YDR2IWKO.js → chunk-72JHTO7E.js} +1 -1
  246. package/dist/bundle/chunks/{chunk-KVG5FR5F.js → chunk-7GA3QWJJ.js} +11 -11
  247. package/dist/bundle/chunks/{chunk-ICQYTW7W.js → chunk-7M672HB6.js} +1 -1
  248. package/dist/bundle/chunks/chunk-B6OSJB22.js +26 -0
  249. package/dist/bundle/chunks/{chunk-N3FZSEG7.js → chunk-BM3X75NC.js} +1 -1
  250. package/dist/bundle/chunks/chunk-CBM6J4AL.js +6 -0
  251. package/dist/bundle/chunks/{chunk-FNEG7DFQ.js → chunk-CGI6V2HW.js} +1 -1
  252. package/dist/bundle/chunks/{chunk-BKUWXPEM.js → chunk-CHWP6GRK.js} +1 -1
  253. package/dist/bundle/chunks/{chunk-UL6YJ7FT.js → chunk-D5ZJISRS.js} +1 -1
  254. package/dist/bundle/chunks/{chunk-TUNYNC46.js → chunk-DIRWTBKE.js} +1 -1
  255. package/dist/bundle/chunks/chunk-DIWMSSQY.js +2 -0
  256. package/dist/bundle/chunks/{chunk-273265WK.js → chunk-DPZVOEUP.js} +1 -1
  257. package/dist/bundle/chunks/chunk-EGTVQWAP.js +20 -0
  258. package/dist/bundle/chunks/{chunk-SI5VPVOA.js → chunk-EXXOLIVE.js} +1 -1
  259. package/dist/bundle/chunks/chunk-GLAFXDZC.js +4 -0
  260. package/dist/bundle/chunks/{chunk-PMYUC5JF.js → chunk-H42OAUJL.js} +1 -1
  261. package/dist/bundle/chunks/chunk-H53EPEGD.js +12 -0
  262. package/dist/bundle/chunks/{chunk-QE275OWT.js → chunk-HDOXCDVK.js} +1 -1
  263. package/dist/bundle/chunks/{chunk-USNDURQI.js → chunk-HIQEVPXM.js} +1 -1
  264. package/dist/bundle/chunks/{chunk-G4SEENI7.js → chunk-M4LDT7V7.js} +1 -1
  265. package/dist/bundle/chunks/{chunk-MHY57JTL.js → chunk-MDE25PQK.js} +1 -1
  266. package/dist/bundle/chunks/{chunk-Q6JV5CBB.js → chunk-MHDZERK4.js} +1 -1
  267. package/dist/bundle/chunks/{chunk-5ELNHAAJ.js → chunk-MHZF23KB.js} +1 -1
  268. package/dist/bundle/chunks/{chunk-LPJEKUCB.js → chunk-N6W6FM4N.js} +1 -1
  269. package/dist/bundle/chunks/{chunk-POIWRLUV.js → chunk-NRLE7KYI.js} +1 -1
  270. package/dist/bundle/chunks/{chunk-MQKGGNPS.js → chunk-NXBUT5V2.js} +2 -2
  271. package/dist/bundle/chunks/{chunk-4HMWZAP7.js → chunk-OB46N7Q7.js} +1 -1
  272. package/dist/bundle/chunks/{chunk-ALOFNPKY.js → chunk-PPHGMG47.js} +2 -2
  273. package/dist/bundle/chunks/{chunk-UXHSH7BM.js → chunk-R6ZGLVXI.js} +1 -1
  274. package/dist/bundle/chunks/chunk-RCRHDT54.js +274 -0
  275. package/dist/bundle/chunks/{chunk-N4TGZ6H7.js → chunk-RIIUVFUS.js} +1 -1
  276. package/dist/bundle/chunks/chunk-RK2WBVP4.js +2 -0
  277. package/dist/bundle/chunks/{chunk-MLIO3BK2.js → chunk-SQX6WQXB.js} +1 -1
  278. package/dist/bundle/chunks/chunk-SRB6FXRH.js +2 -0
  279. package/dist/bundle/chunks/{chunk-7IFSXTCJ.js → chunk-T4INBNHX.js} +1 -1
  280. package/dist/bundle/chunks/{chunk-TVJ6JVK4.js → chunk-TUQG2YRH.js} +1 -1
  281. package/dist/bundle/chunks/{chunk-JA6EY7US.js → chunk-U7UNEMLJ.js} +1 -1
  282. package/dist/bundle/chunks/{chunk-GVKYQN5J.js → chunk-UK2K3DHN.js} +1 -1
  283. package/dist/bundle/chunks/{chunk-HW6ZCMM5.js → chunk-VDJ53ESK.js} +1 -1
  284. package/dist/bundle/chunks/{chunk-WHHRIZS3.js → chunk-VGCXKMXN.js} +1 -1
  285. package/dist/bundle/chunks/chunk-VOQZ5TSL.js +2 -0
  286. package/dist/bundle/chunks/{chunk-R2FBRMDU.js → chunk-VWUMR4IC.js} +1 -1
  287. package/dist/bundle/chunks/chunk-W2Z6LYL6.js +11 -0
  288. package/dist/bundle/chunks/{chunk-CFBEDNHJ.js → chunk-W5J5ADJF.js} +7 -7
  289. package/dist/bundle/chunks/{chunk-V2SOLEQN.js → chunk-XHFP44Y4.js} +1 -1
  290. package/dist/bundle/chunks/{chunk-KIGPB52X.js → chunk-XZ34OGNM.js} +1 -1
  291. package/dist/bundle/chunks/{chunk-A3D7NRT6.js → chunk-Y32R7EZP.js} +10 -10
  292. package/dist/bundle/chunks/chunk-YUFU7O6I.js +16 -0
  293. package/dist/bundle/chunks/{chunk-MFGH46GH.js → chunk-YZH7FUSY.js} +1 -1
  294. package/dist/bundle/chunks/{column-LKMDIDCH.js → column-F5JDBRV6.js} +1 -1
  295. package/dist/bundle/chunks/{cp-FKTQRFYJ.js → cp-LTFB4EUA.js} +1 -1
  296. package/dist/bundle/chunks/curl-XCX2ZQEA.js +30 -0
  297. package/dist/bundle/chunks/{cut-RWPUW5FY.js → cut-IRSHL3BB.js} +1 -1
  298. package/dist/bundle/chunks/{diff-CSARC7WF.js → diff-VDB6RXHO.js} +1 -1
  299. package/dist/bundle/chunks/{du-PR3M44X6.js → du-DOWSRLXR.js} +1 -1
  300. package/dist/bundle/chunks/{expr-UMT2OHZ7.js → expr-GZ4DABKB.js} +1 -1
  301. package/dist/bundle/chunks/{file-VEGKTTSF.js → file-UI6QJAAU.js} +1 -1
  302. package/dist/bundle/chunks/{find-PM3TD7V4.js → find-JTXDH3MR.js} +1 -1
  303. package/dist/bundle/chunks/flag-coverage-EDO3VM43.js +2 -0
  304. package/dist/bundle/chunks/{grep-5UPEO42U.js → grep-OZCR76FT.js} +1 -1
  305. package/dist/bundle/chunks/{gzip-ZINVK3M6.js → gzip-GQC6CWVL.js} +1 -1
  306. package/dist/bundle/chunks/{head-CFENJILH.js → head-J6RVJFRS.js} +1 -1
  307. package/dist/bundle/chunks/{help-QDDMBDU7.js → help-62M75TSG.js} +1 -1
  308. package/dist/bundle/chunks/{html-to-markdown-GGVR4YGL.js → html-to-markdown-7OG5VWYG.js} +1 -1
  309. package/dist/bundle/chunks/{jq-X2P7Q64K.js → jq-FCG2IUBK.js} +1 -1
  310. package/dist/bundle/chunks/js-exec-NDLXDUBN.js +1577 -0
  311. package/dist/bundle/chunks/{ln-VYDFOFNO.js → ln-OPY2ZVGQ.js} +1 -1
  312. package/dist/bundle/chunks/{ls-R5CQLZQM.js → ls-MQTYWW4T.js} +1 -1
  313. package/dist/bundle/chunks/{mkdir-WDDKK2P3.js → mkdir-4A5W3RXH.js} +1 -1
  314. package/dist/bundle/chunks/mktemp-XKIE5N3X.js +2 -0
  315. package/dist/bundle/chunks/{mv-XSJA2FNL.js → mv-ZPIATQJL.js} +1 -1
  316. package/dist/bundle/chunks/{od-BI6XJPXY.js → od-LUHOH7CG.js} +1 -1
  317. package/dist/bundle/chunks/{paste-LLZ3ZQR2.js → paste-U57ZU47S.js} +1 -1
  318. package/dist/bundle/chunks/python3-SDFCGIU4.js +22 -0
  319. package/dist/bundle/chunks/{readlink-IY6QKK2P.js → readlink-YNNS6F7K.js} +1 -1
  320. package/dist/bundle/chunks/{rg-UQE6KUBP.js → rg-F4SX2PHI.js} +1 -1
  321. package/dist/bundle/chunks/{rm-JQ4GDKDD.js → rm-3XUUYAXQ.js} +1 -1
  322. package/dist/bundle/chunks/{rmdir-WZKAT6M5.js → rmdir-OGSEXEF4.js} +1 -1
  323. package/dist/bundle/chunks/{sed-JW2JDLSI.js → sed-MBB5SXGD.js} +1 -1
  324. package/dist/bundle/chunks/{seq-5R2GKXC6.js → seq-IN77HD3S.js} +1 -1
  325. package/dist/bundle/chunks/{sleep-PPRBTSVR.js → sleep-3QNP3BGR.js} +1 -1
  326. package/dist/bundle/chunks/{split-2SD6EP72.js → split-6R2TSQY6.js} +1 -1
  327. package/dist/bundle/chunks/{sqlite3-UVVRYDAL.js → sqlite3-7MBPFI6W.js} +1 -1
  328. package/dist/bundle/chunks/sqlite3-worker.js +75 -11
  329. package/dist/bundle/chunks/{stat-6KILP5AL.js → stat-YLVJ4L67.js} +1 -1
  330. package/dist/bundle/chunks/{tail-BDNMS4FR.js → tail-UGFWX3YY.js} +1 -1
  331. package/dist/bundle/chunks/{tar-6365WH6H.js → tar-BNHPWTOY.js} +1 -1
  332. package/dist/bundle/chunks/{time-NERE2JJ2.js → time-N6J6DC6C.js} +1 -1
  333. package/dist/bundle/chunks/timeout-ZHCL5KTP.js +2 -0
  334. package/dist/bundle/chunks/{tr-3I4MDKIF.js → tr-4NGL47UU.js} +1 -1
  335. package/dist/bundle/chunks/worker.js +88 -15
  336. package/dist/bundle/chunks/{xan-HUOXKUQA.js → xan-7R3I2DJO.js} +1 -1
  337. package/dist/bundle/chunks/xan-view-S4ZILLPU.js +2 -0
  338. package/dist/bundle/chunks/yes-I7SAR7XX.js +2 -0
  339. package/dist/bundle/chunks/yq-IOMBQYB2.js +2 -0
  340. package/dist/bundle/index.cjs +2862 -1489
  341. package/dist/bundle/index.js +349 -344
  342. package/dist/commands/curl/response-formatting.d.ts +2 -2
  343. package/dist/commands/curl/types.d.ts +5 -0
  344. package/dist/commands/diff/format.d.ts +46 -0
  345. package/dist/commands/js-exec/js-exec.d.ts +1 -10
  346. package/dist/commands/js-exec/run-runtime.d.ts +10 -0
  347. package/dist/commands/mktemp/mktemp.d.ts +4 -0
  348. package/dist/commands/registry.d.ts +1 -1
  349. package/dist/commands/sqlite3/worker.js +75 -11
  350. package/dist/commands/worker-request-controller.d.ts +3 -23
  351. package/dist/commands/yes/yes.d.ts +4 -0
  352. package/dist/custom-commands.d.ts +7 -0
  353. package/dist/fs/create-exclusive.d.ts +30 -0
  354. package/dist/fs/in-memory-fs/in-memory-fs.d.ts +8 -1
  355. package/dist/fs/interface.d.ts +37 -0
  356. package/dist/fs/mountable-fs/mountable-fs.d.ts +20 -1
  357. package/dist/fs/overlay-fs/overlay-fs.d.ts +9 -1
  358. package/dist/fs/read-write-fs/read-write-fs.d.ts +27 -1
  359. package/dist/fs/traversal.d.ts +9 -0
  360. package/dist/index.d.cts +1 -1
  361. package/dist/index.d.ts +1 -1
  362. package/dist/interpreter/expansion/array-prefix-suffix.d.ts +2 -1
  363. package/dist/interpreter/expansion/parameter-ops.d.ts +1 -0
  364. package/dist/interpreter/expansion/pattern-removal.d.ts +3 -0
  365. package/dist/interpreter/expansion/variable.d.ts +1 -1
  366. package/dist/interpreter/helpers/loop.d.ts +32 -0
  367. package/dist/interpreter/helpers/substitution-status.d.ts +34 -0
  368. package/dist/interpreter/interpreter.d.ts +1 -1
  369. package/dist/interpreter/types.d.ts +8 -1
  370. package/dist/limits.d.ts +2 -0
  371. package/dist/network/allow-list/shared.d.ts +0 -8
  372. package/dist/network/dns-pin.d.ts +1 -35
  373. package/dist/network/fetch.d.ts +4 -6
  374. package/dist/network/types.d.ts +20 -2
  375. package/dist/security/blocked-globals.d.ts +60 -0
  376. package/dist/security/defense-context.d.ts +13 -0
  377. package/dist/security/defense-in-depth-box.d.ts +361 -0
  378. package/dist/security/index.d.ts +33 -0
  379. package/dist/security/safe-timestamp.d.ts +1 -0
  380. package/dist/security/security-violation-logger.d.ts +99 -0
  381. package/dist/security/trusted-globals.d.ts +25 -0
  382. package/dist/security/types.d.ts +151 -0
  383. package/dist/security/violation-error-message.d.ts +3 -0
  384. package/dist/security/wasm-callback.d.ts +6 -0
  385. package/dist/security/worker-defense-in-depth.d.ts +235 -0
  386. package/dist/transform/pipeline.d.ts +8 -0
  387. package/dist/transform/plugins/command-collector.d.ts +15 -0
  388. package/dist/transform/plugins/tee-plugin.d.ts +40 -0
  389. package/dist/transform/serialize.d.ts +4 -0
  390. package/dist/transform/types.d.ts +18 -0
  391. package/dist/types.d.ts +4 -3
  392. package/dist/worker-lifecycle.d.ts +27 -0
  393. package/package.json +15 -14
  394. package/dist/bin/chunks/awk2-C4A37H5N.js +0 -3
  395. package/dist/bin/chunks/chunk-23OI2XDJ.js +0 -20
  396. package/dist/bin/chunks/chunk-2ORJ5HTY.js +0 -276
  397. package/dist/bin/chunks/chunk-3PCPQIUD.js +0 -3
  398. package/dist/bin/chunks/chunk-7WBCA2BB.js +0 -3
  399. package/dist/bin/chunks/chunk-APV27ZZW.js +0 -21
  400. package/dist/bin/chunks/chunk-CPTQXTBJ.js +0 -3
  401. package/dist/bin/chunks/chunk-FE6GSISP.js +0 -22
  402. package/dist/bin/chunks/chunk-HL7NFZVQ.js +0 -13
  403. package/dist/bin/chunks/chunk-HWI42GQO.js +0 -7
  404. package/dist/bin/chunks/chunk-JQM3DKCH.js +0 -12
  405. package/dist/bin/chunks/chunk-TOTKK2XI.js +0 -16
  406. package/dist/bin/chunks/chunk-YTL6DXBO.js +0 -11
  407. package/dist/bin/chunks/curl-FS5LAEYI.js +0 -30
  408. package/dist/bin/chunks/flag-coverage-DOLZIUQ7.js +0 -3
  409. package/dist/bin/chunks/js-exec-DJQLXWCS.js +0 -99
  410. package/dist/bin/chunks/js-exec-worker.js +0 -4809
  411. package/dist/bin/chunks/python3-JCJHSX4Z.js +0 -14
  412. package/dist/bin/chunks/timeout-YGFHQJKX.js +0 -3
  413. package/dist/bin/chunks/undici-CKF2L2IP.js +0 -141
  414. package/dist/bin/chunks/yq-K5N5JD4N.js +0 -3
  415. package/dist/bin/shell/chunks/awk2-C4A37H5N.js +0 -3
  416. package/dist/bin/shell/chunks/chunk-23OI2XDJ.js +0 -20
  417. package/dist/bin/shell/chunks/chunk-2ORJ5HTY.js +0 -276
  418. package/dist/bin/shell/chunks/chunk-3PCPQIUD.js +0 -3
  419. package/dist/bin/shell/chunks/chunk-7WBCA2BB.js +0 -3
  420. package/dist/bin/shell/chunks/chunk-APV27ZZW.js +0 -21
  421. package/dist/bin/shell/chunks/chunk-CPTQXTBJ.js +0 -3
  422. package/dist/bin/shell/chunks/chunk-FE6GSISP.js +0 -22
  423. package/dist/bin/shell/chunks/chunk-HL7NFZVQ.js +0 -13
  424. package/dist/bin/shell/chunks/chunk-HWI42GQO.js +0 -7
  425. package/dist/bin/shell/chunks/chunk-JQM3DKCH.js +0 -12
  426. package/dist/bin/shell/chunks/chunk-TOTKK2XI.js +0 -16
  427. package/dist/bin/shell/chunks/chunk-YTL6DXBO.js +0 -11
  428. package/dist/bin/shell/chunks/curl-FS5LAEYI.js +0 -30
  429. package/dist/bin/shell/chunks/flag-coverage-DOLZIUQ7.js +0 -3
  430. package/dist/bin/shell/chunks/js-exec-DJQLXWCS.js +0 -99
  431. package/dist/bin/shell/chunks/python3-JCJHSX4Z.js +0 -14
  432. package/dist/bin/shell/chunks/timeout-YGFHQJKX.js +0 -3
  433. package/dist/bin/shell/chunks/undici-CKF2L2IP.js +0 -141
  434. package/dist/bin/shell/chunks/yq-K5N5JD4N.js +0 -3
  435. package/dist/bundle/chunks/awk2-NPLZQ3K7.js +0 -2
  436. package/dist/bundle/chunks/chunk-6DTD75TR.js +0 -275
  437. package/dist/bundle/chunks/chunk-6KK46B7Q.js +0 -12
  438. package/dist/bundle/chunks/chunk-AH7VTVWU.js +0 -2
  439. package/dist/bundle/chunks/chunk-BRJERIF4.js +0 -2
  440. package/dist/bundle/chunks/chunk-ELHOZMBD.js +0 -10
  441. package/dist/bundle/chunks/chunk-INDA53JL.js +0 -21
  442. package/dist/bundle/chunks/chunk-KBXRZGTY.js +0 -15
  443. package/dist/bundle/chunks/chunk-N3A4JVFJ.js +0 -2
  444. package/dist/bundle/chunks/chunk-UTKGYVUZ.js +0 -7
  445. package/dist/bundle/chunks/chunk-XMMV24SP.js +0 -20
  446. package/dist/bundle/chunks/chunk-YJKHREBZ.js +0 -11
  447. package/dist/bundle/chunks/chunk-ZBUZKIPX.js +0 -6
  448. package/dist/bundle/chunks/curl-DEHFBW27.js +0 -29
  449. package/dist/bundle/chunks/flag-coverage-I6UJUKQ4.js +0 -2
  450. package/dist/bundle/chunks/js-exec-XKF2B7C3.js +0 -98
  451. package/dist/bundle/chunks/js-exec-worker.js +0 -4809
  452. package/dist/bundle/chunks/python3-F5S5TYGS.js +0 -13
  453. package/dist/bundle/chunks/timeout-C6WDYPLV.js +0 -2
  454. package/dist/bundle/chunks/undici-PSPBDOYF.js +0 -140
  455. package/dist/bundle/chunks/xan-view-RT2WKDOQ.js +0 -2
  456. package/dist/bundle/chunks/yq-MI27NZ2U.js +0 -2
  457. package/dist/commands/js-exec/js-exec-worker.d.ts +0 -33
@@ -1,57 +1,60 @@
1
1
  #!/usr/bin/env node
2
2
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{a as Sn,b as An,c as _t}from"./chunks/chunk-O2BCKSMK.js";import{a as Er}from"./chunks/chunk-3PCPQIUD.js";import{c as _s,e as eo}from"./chunks/chunk-TW2IJRUF.js";import{a as Xa,b as Ya,c as qn,d as Un}from"./chunks/chunk-PPVF2N6C.js";import{a as Ot}from"./chunks/chunk-6D75E4LV.js";import{a as It,b as He,c as Os}from"./chunks/chunk-MROECM42.js";import{a as jn,b as Ja}from"./chunks/chunk-42AMF6EE.js";import{a as me}from"./chunks/chunk-XBX7KFWK.js";import{a as hn,b as _e}from"./chunks/chunk-HWI42GQO.js";import"./chunks/chunk-VLWZ6L7C.js";import{c as Dt,d as gn}from"./chunks/chunk-CPTQXTBJ.js";import"./chunks/chunk-7JZKVC3F.js";import{a as z,b as $t,c as Q,d as wn,e as En,f as xt,g as bn}from"./chunks/chunk-43E7AR6A.js";import{a as yn,b as je,c as Ge,d as Ie,e as Fe,f as Be,g as U,h as oe,i as Ze,j as Nt,k as br,l as k,m as We,n as Rt,o as Sr,p as et}from"./chunks/chunk-LCP3IKI7.js";import{a as F,c as tn,e as mn,f as Ct,g as Is}from"./chunks/chunk-CPKBPQ2C.js";import{a as mt}from"./chunks/chunk-PBOVSFTJ.js";import{a as tt}from"./chunks/chunk-I4IRHQDW.js";import"./chunks/chunk-DN2YCFOR.js";import*as xf from"node:fs";import*as kf from"node:path";import*as Pf from"node:readline";var vn=[{name:"echo",load:async()=>(await import("./chunks/echo-NYDCCFWB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-2J5MA5PY.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-CNXNRQ3I.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-R6DAGGBH.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-74BP5NTG.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-DCJ3XJRR.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-TVQAUQOG.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-3PLW4O4B.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-MF5GADQN.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-YG75IRRE.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-XSDIE6SU.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-ZM5WLMZI.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-YKLNXWZI.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-HMHVGSAM.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-YGKW3HS4.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-4MB7HHIZ.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-VSQBRD6B.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-5PUSTPTK.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-WUZMZDGY.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-WUZMZDGY.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-WUZMZDGY.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-A3E7YM2A.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-KJWKB22J.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-C4A37H5N.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-M3DO25D5.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-K5VRDP4Q.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-URDMZCXL.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-QOTYBJJJ.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-ACKOG3XS.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-Z6N34HZM.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-CZTQCNOZ.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-XHWFVVKH.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-YEY7X54W.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-P6SNTBGZ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-JPOQORZF.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-J2X2Z6N2.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-XMXBXL5Q.js")).split},{name:"column",load:async()=>(await import("./chunks/column-7VBJL757.js")).column},{name:"join",load:async()=>(await import("./chunks/join-UQKXU2QP.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-L4HKV5PD.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-6DH6TRDN.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-C4CRGDXP.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-TPUFCYF6.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-ZGP6NPGS.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-A3UGHIKJ.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-2TSVF4W7.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-2TSVF4W7.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-3R4G6HQY.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-3R4G6HQY.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-3HAU45KT.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-HMISWW4I.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-OE52K3TM.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-CFCBBWVH.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-CFCBBWVH.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-5MI4V3G5.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-FLJ4YPHB.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-YXZZCUSQ.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-FJUBX7TJ.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-DVFE2GSF.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-YGFHQJKX.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-LF7BTSK5.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-Q4LZ6EXV.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-TDF3B6QJ.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-Z6KAYGDK.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-CATBXX76.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-YGSNBVY3.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-AJGG7RYT.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-ZWL7LZIP.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-HVIDHJ6M.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-4TPGVSBZ.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-DG4BMYM5.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-2I76DUQL.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-B5HDVKW6.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-YCY27MMO.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-JA7JQBUS.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-JA7JQBUS.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-JA7JQBUS.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(vn.push({name:"tar",load:async()=>(await import("./chunks/tar-FRDUJZDN.js")).tarCommand}),vn.push({name:"yq",load:async()=>(await import("./chunks/yq-K5N5JD4N.js")).yqCommand}),vn.push({name:"xan",load:async()=>(await import("./chunks/xan-VSF6ZQGZ.js")).xanCommand}),vn.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-DNH2VLVN.js")).sqlite3Command}));var Ls=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ls.push({name:"python3",load:async()=>(await import("./chunks/python3-JCJHSX4Z.js")).python3Command}),Ls.push({name:"python",load:async()=>(await import("./chunks/python3-JCJHSX4Z.js")).pythonCommand}));var Ts=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ts.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-DJQLXWCS.js")).jsExecCommand}),Ts.push({name:"node",load:async()=>(await import("./chunks/js-exec-DJQLXWCS.js")).nodeStubCommand}));var Df=[{name:"curl",load:async()=>(await import("./chunks/curl-FS5LAEYI.js")).curlCommand}],to=new Map;function Ar(e){return{name:e.name,async execute(t,n){let r=to.get(e.name);if(r||(r=await _e.runTrustedAsync(()=>e.load()),to.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await import("./chunks/flag-coverage-DOLZIUQ7.js");s(n.coverage,e.name,t)}return r.execute(t,n)}}}function no(e){return(e?vn.filter(n=>e.includes(n.name)):vn).map(Ar)}function ro(){return Df.map(Ar)}function so(){return Ls.map(Ar)}function io(){return Ts.map(Ar)}var ao=new WeakMap,oo=new WeakSet;function Ms(e){let t=ao.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),ao.set(e,t),oo.add(t)),t}function lo(e){return oo.has(e)}var uo={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},If={...uo,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 Fs(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?If:uo;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 co(e){return"load"in e&&typeof e.load=="function"}function fo(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 po=Object.freeze(Object.create(null)),vr=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 k(`${s}: ${t} work limit exceeded (${r})`,"iterations")),n>this.limits.maxWorkUnits-this.workUnits&&this.fail(new k(`${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 k(`${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 k(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 k(`${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:F(n);(!Number.isSafeInteger(s)||s<0||s>a)&&this.fail(new k(`${r}: invalid ${t} accounting`,"output_size"));let o=a-s;return o>this.limits.maxOutputSize-this.outputBytes&&this.fail(new k(`${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!==po&&this.fail(new k(`${n}: unauthorized output accounting release`,"output_size")),(!Number.isSafeInteger(t)||t<0||t>this.outputBytes)&&this.fail(new k(`${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 k(`${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
4
- `)),Date.now()-this.startedAt>this.limits.maxExecutionTimeMs&&this.fail(new We("",`bash: ${t} exceeded execution deadline (${this.limits.maxExecutionTimeMs}ms)
5
- `))}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=qn(()=>o({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(Un(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 k(`maximum nested execution depth (${this.limits.maxExecDepth}) exceeded`,"recursion"))}};function ho(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 mo(e,t,n="pipeline"){e.relinquishOutput(t,n,po)}var nn=new TextEncoder;function Of(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var yt=class{data=new Map;entryIdentities=new WeakMap;nextEntryIdentity=1;maxTotalBytes;retainedBytes=0;contentReferences=new WeakMap;materializedContent(t){return t?.type==="file"&&"content"in t?t.content:null}storedByteLength(t){return t===null?0:t instanceof Uint8Array?t.byteLength:F(t)}wouldReleaseBytes(t){let n=this.materializedContent(t);return n===null?0:n instanceof Uint8Array?this.contentReferences.get(n)===1?n.byteLength:0:this.storedByteLength(n)}assertCanAllocate(t,n){let r=this.wouldReleaseBytes(this.data.get(t));if(!Number.isSafeInteger(n)||n<0||n>this.maxTotalBytes-this.retainedBytes+r)throw new Error(`ENOSPC: in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`)}setEntry(t,n){let r=this.data.get(t),s=this.materializedContent(r),i=this.materializedContent(n);if(s===i){this.data.set(t,n);return}let 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:F(t)}identityFor(t){let n=this.entryIdentities.get(t);return n||(n=`memfs:${this.nextEntryIdentity++}`,this.entryIdentities.set(t,n)),n}constructor(t,n={}){if(this.maxTotalBytes=n.maxTotalBytes??1024*1024*1024,!Number.isSafeInteger(this.maxTotalBytes)||this.maxTotalBytes<0)throw new Error("InMemoryFs: invalid maxTotalBytes");if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[r,s]of Object.entries(t))typeof s=="function"?this.writeFileLazy(r,s):Of(s)?this.writeFileSync(r,s.content,void 0,{mode:s.mode,mtime:s.mtime}):this.writeFileSync(r,s)}ensureParentDirs(t){let n=wn(t);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,n,r,s){Q(t,"write");let i=z(t);this.ensureParentDirs(i);let a=_t(r);this.assertCanAllocate(i,this.contentByteLength(n,a));let o=Sn(n,a);this.setEntry(i,{type:"file",content:o,mode:s?.mode??420,mtime:s?.mtime??new Date})}writeFileLazy(t,n,r){Q(t,"write");let s=z(t);this.ensureParentDirs(s),this.setEntry(s,{type:"file",lazy:n,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,n){let r=await n.lazy(),s=typeof r=="string"?nn.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=_t(n);return An(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return An(n,"binary")}async readFileBuffer(t){Q(t,"open");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in r){let s=await this.materializeLazy(n,r);return s.content instanceof Uint8Array?s.content:nn.encode(s.content)}return r.content instanceof Uint8Array?r.content:nn.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){Q(t,"append");let s=z(t),i=this.data.get(s);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let a=_t(r),o=this.contentByteLength(n,a);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(s,l));let u="content"in l&&l.content instanceof Uint8Array?l.content:nn.encode("content"in l?l.content:"");this.assertCanAllocate(s,u.byteLength+o);let c=Sn(n,a),f=new Uint8Array(u.length+c.length);f.set(u),f.set(c,u.length),this.setEntry(s,{type:"file",content:f,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,n,r)}async exists(t){if(t.includes("\0"))return!1;try{let n=this.resolvePathWithSymlinks(t);return this.data.has(n)}catch{return!1}}async stat(t){Q(t,"stat");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=nn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}async lstat(t){Q(t,"lstat");let n=this.resolveIntermediateSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=nn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}resolveIntermediateSymlinks(t){let n=z(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",i=new Set;for(let a=0;a<r.length-1;a++){let o=r[a];s=`${s}/${o}`;let l=this.data.get(s),u=0,c=40;for(;l&&l.type==="symlink"&&u<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(s),s=bn(s,l.target),l=this.data.get(s),u++}if(u>=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let n=z(t);if(n==="/")return"/";let r=n.slice(1).split("/"),s="",i=new Set;for(let a of r){s=`${s}/${a}`;let o=this.data.get(s),l=0,u=40;for(;o&&o.type==="symlink"&&l<u;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(s),s=bn(s,o.target),o=this.data.get(s),l++}if(l>=u)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return s}async mkdir(t,n){this.mkdirSync(t,n)}mkdirSync(t,n){Q(t,"mkdir");let r=z(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let s=wn(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){Q(t,"scandir");let n=z(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let s=new Set;for(;r&&r.type==="symlink";){if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(n),n=bn(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 u=o.slice(i.length),c=u.split("/")[0];c&&!u.includes("/",c.length)&&!a.has(c)&&a.set(c,{name:c,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){Q(t,"rm");let r=z(t),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(s.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of i){let o=xt(r,a);await this.rm(o,n)}}}this.deleteEntry(r)}async cp(t,n,r){Q(t,"cp"),Q(n,"cp");let s=z(t),i=z(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:nn.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($t(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 u=xt(s,l),c=xt(i,l);await this.cp(u,c,r)}}}async mv(t,n){Q(t,"mv"),Q(n,"mv");let r=z(t),s=z(n);if(r===s)return;let i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(i.type==="directory"&&$t(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(xt(r,o),xt(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 En(t,n)}async chmod(t,n){Q(t,"chmod");let r=z(t),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);s.mode=n}async symlink(t,n){Q(n,"symlink");let r=z(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,n){Q(t,"link"),Q(n,"link");let r=z(t),s=z(n),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let 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){Q(t,"readlink");let n=z(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){Q(t,"realpath");let n=this.resolvePathWithSymlinks(t);if(!this.data.has(n))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return n}async utimes(t,n,r){Q(t,"utimes");let s=z(t),i=this.resolvePathWithSymlinks(s),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=r}};var go="5.1.0(1)-release",wo="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
+ import{a as Nn,b as Rn,c as Vt}from"./chunks/chunk-PEJXCXSY.js";import{a as Cr,b as Yn}from"./chunks/chunk-MA6BMA4M.js";import{a as oo,b as lo,c as Kn,d as Xn}from"./chunks/chunk-EFS34UUR.js";import{c as Vs,e as fo,f as po}from"./chunks/chunk-ENEHPI32.js";import{a as Wt}from"./chunks/chunk-6D75E4LV.js";import{a as Bt,b as Qe,c as Ws}from"./chunks/chunk-MROECM42.js";import{a as Jn,b as co}from"./chunks/chunk-ABM5WFEO.js";import{a as me}from"./chunks/chunk-LG6IN6SW.js";import{a as vn,b as Le}from"./chunks/chunk-VGSRQOLD.js";import"./chunks/chunk-VLWZ6L7C.js";import{d as Ft,e as kn}from"./chunks/chunk-QKWMWSV3.js";import"./chunks/chunk-7JZKVC3F.js";import{a as uo}from"./chunks/chunk-UPUFWGHR.js";import{a as z,b as It,c as Q,d as dt,e as Pn,f as rt,g as Cn}from"./chunks/chunk-43E7AR6A.js";import{a as xn,b as Ge,c as He,d as Oe,e as Be,f as We,g as q,h as ae,i as Ze,j as Tt,k as kr,l as P,m as Ve,n as Mt,o as Pr,p as tt}from"./chunks/chunk-LCP3IKI7.js";import{a as M,c as cn,e as $n,f as Lt,g as Bs}from"./chunks/chunk-CPKBPQ2C.js";import{a as nt}from"./chunks/chunk-I4IRHQDW.js";import{a as St}from"./chunks/chunk-PBOVSFTJ.js";import"./chunks/chunk-DN2YCFOR.js";import*as Lf from"node:fs";import*as Tf from"node:path";import*as Mf from"node:readline";var Dn=[{name:"echo",load:async()=>(await import("./chunks/echo-NYDCCFWB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-V45MVNBT.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-CNXNRQ3I.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-67NUUIYT.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-AWDWRBKC.js")).mkdirCommand},{name:"mktemp",load:async()=>(await import("./chunks/mktemp-L6OGMDUO.js")).mktempCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-J3HM7GGM.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-TVQAUQOG.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-UCUTHC3I.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-HPLQA35N.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-4BJSOT4Y.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-B35EKC2Q.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-A54R4UUQ.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-YKLNXWZI.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-URO5XTBB.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-TLFXMM2T.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-5TSF5YM4.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-VSQBRD6B.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-UJ37RBMM.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-DCPCPQOS.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-DCPCPQOS.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-DCPCPQOS.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-RVULUPDH.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-MCLGHZOI.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-U22OR5B5.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-M3DO25D5.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-K5VRDP4Q.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-URDMZCXL.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-KP3S36XS.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-5TSIBDF7.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-6RPFASYV.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-CZTQCNOZ.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-XHWFVVKH.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-YEY7X54W.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-P6SNTBGZ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-JPOQORZF.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-J2X2Z6N2.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-VZO7223N.js")).split},{name:"column",load:async()=>(await import("./chunks/column-LHHS4D3K.js")).column},{name:"join",load:async()=>(await import("./chunks/join-UQKXU2QP.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-L4HKV5PD.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-XGVQ6N6L.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-C4CRGDXP.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-TPUFCYF6.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-ZGP6NPGS.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-WEF5YWQK.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-2TSVF4W7.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-2TSVF4W7.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-3R4G6HQY.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-3R4G6HQY.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-3HAU45KT.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-HMISWW4I.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).falseCommand},{name:"yes",load:async()=>(await import("./chunks/yes-ELH3XQWY.js")).yesCommand},{name:"clear",load:async()=>(await import("./chunks/clear-OE52K3TM.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-CFCBBWVH.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-CFCBBWVH.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-GDM3OBBK.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-2KKH5BCT.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-JSJ56EOK.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-FJUBX7TJ.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-CV6B4M6W.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-ATTDYXLX.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-J2DAZUIN.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-I54NZE75.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-FLWT4OCO.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-Z6KAYGDK.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-CATBXX76.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-YGSNBVY3.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-JLUCGBCB.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-E22RLT2U.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-EXVKU23F.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-4TPGVSBZ.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-DG4BMYM5.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-2I76DUQL.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-B5HDVKW6.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-SI75GLRE.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-6DZIKNBW.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-6DZIKNBW.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-6DZIKNBW.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Dn.push({name:"tar",load:async()=>(await import("./chunks/tar-ZGZZDQXO.js")).tarCommand}),Dn.push({name:"yq",load:async()=>(await import("./chunks/yq-GSCDUHGM.js")).yqCommand}),Dn.push({name:"xan",load:async()=>(await import("./chunks/xan-CCS53B7D.js")).xanCommand}),Dn.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-HXVFVP4Z.js")).sqlite3Command}));var zs=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(zs.push({name:"python3",load:async()=>(await import("./chunks/python3-GUWCSSDP.js")).python3Command}),zs.push({name:"python",load:async()=>(await import("./chunks/python3-GUWCSSDP.js")).pythonCommand}));var qs=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(qs.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-VU6F6WLS.js")).jsExecCommand}),qs.push({name:"node",load:async()=>(await import("./chunks/js-exec-VU6F6WLS.js")).nodeStubCommand}));var Bf=[{name:"curl",load:async()=>(await import("./chunks/curl-FIRG3RB6.js")).curlCommand}],ho=new Map;function Nr(e){return{name:e.name,async execute(t,n){let r=ho.get(e.name);if(r||(r=await Le.runTrustedAsync(()=>Yn(e.load(),n.signal,`bash: ${e.name} was cancelled before it started
4
+ `)),ho.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await Yn(import("./chunks/flag-coverage-4JYKIAVV.js"),n.signal,`bash: ${e.name} was cancelled before it started
5
+ `);s(n.coverage,e.name,t)}return r.execute(t,n)}}}function mo(e){return(e?Dn.filter(n=>e.includes(n.name)):Dn).map(Nr)}function yo(){return Bf.map(Nr)}function go(){return zs.map(Nr)}function wo(){return qs.map(Nr)}var Eo=new WeakMap,bo=new WeakSet;function Us(e){let t=Eo.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),Eo.set(e,t),bo.add(t)),t}function So(e){return bo.has(e)}var Ao={maxSourceBytes:67108864,maxExecDepth:64,maxCallDepth:100,maxCommandCount:1e5,maxLoopIterations:1e5,maxAwkIterations:1e5,maxSedIterations:1e5,maxJqIterations:1e7,maxQueryTokens:1e5,maxQueryDepth:1e3,maxQueryElements:1e6,maxAwkParserTokens:1e5,maxAwkParserDepth:256,maxAwkParserOperations:1e6,maxCsvRows:1e6,maxCsvCells:1e7,maxWorkUnits:1e8,maxTraversalEntries:1e6,maxTraversalDepth:1e3,maxTraversalWork:1e6,maxLiveBytes:536870912,maxInputBytes:536870912,maxFileSystemBytes:1073741824,maxDatabaseBytes:1073741824,maxDatabaseResultBytes:268435456,maxArchiveBytes:1073741824,maxArchiveCompressedBytes:536870912,maxArchiveEntryBytes:536870912,maxArchiveEntries:1e6,maxWorkerMessageBytes:67108864,maxExecutionTimeMs:36e5,maxExtensionCleanupTimeMs:100,maxSqliteTimeoutMs:3e4,maxPythonTimeoutMs:3e4,maxJsTimeoutMs:3e4,maxJsBridgeRequests:1e6,maxGlobOperations:1e6,maxStringLength:67108864,maxArrayElements:1e6,maxHeredocSize:67108864,maxSubstitutionDepth:50,maxBraceExpansionResults:1e5,maxOutputSize:268435456,maxFileDescriptors:4096,maxSourceDepth:100},Wf={...Ao,maxSourceBytes:8*1024*1024,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,maxJsBridgeRequests:1e5,maxExtensionCleanupTimeMs:25,maxGlobOperations:1e5,maxStringLength:10*1024*1024,maxArrayElements:1e5,maxHeredocSize:10*1024*1024,maxBraceExpansionResults:1e4,maxOutputSize:10*1024*1024,maxFileDescriptors:1024,maxQueryTokens:25e3,maxQueryDepth:256,maxQueryElements:1e5,maxAwkParserTokens:25e3,maxAwkParserDepth:128,maxAwkParserOperations:1e5,maxCsvRows:1e5,maxCsvCells:1e6,maxWorkUnits:1e5,maxTraversalEntries:1e5,maxTraversalDepth:256,maxTraversalWork:1e5,maxLiveBytes:64*1024*1024,maxInputBytes:32*1024*1024,maxFileSystemBytes:128*1024*1024,maxDatabaseBytes:64*1024*1024,maxDatabaseResultBytes:16*1024*1024,maxArchiveBytes:128*1024*1024,maxArchiveCompressedBytes:64*1024*1024,maxArchiveEntryBytes:64*1024*1024,maxArchiveEntries:1e5,maxWorkerMessageBytes:16*1024*1024,maxExecutionTimeMs:3e4};function js(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?Wf:Ao;if(!e)return{...n};let r={maxSourceBytes:e.maxSourceBytes??n.maxSourceBytes,maxExecDepth:e.maxExecDepth??n.maxExecDepth,maxCallDepth:e.maxCallDepth??n.maxCallDepth,maxCommandCount:e.maxCommandCount??n.maxCommandCount,maxLoopIterations:e.maxLoopIterations??n.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??n.maxAwkIterations,maxSedIterations:e.maxSedIterations??n.maxSedIterations,maxJqIterations:e.maxJqIterations??n.maxJqIterations,maxQueryTokens:e.maxQueryTokens??n.maxQueryTokens,maxQueryDepth:e.maxQueryDepth??n.maxQueryDepth,maxQueryElements:e.maxQueryElements??n.maxQueryElements,maxAwkParserTokens:e.maxAwkParserTokens??n.maxAwkParserTokens,maxAwkParserDepth:e.maxAwkParserDepth??n.maxAwkParserDepth,maxAwkParserOperations:e.maxAwkParserOperations??n.maxAwkParserOperations,maxCsvRows:e.maxCsvRows??n.maxCsvRows,maxCsvCells:e.maxCsvCells??n.maxCsvCells,maxWorkUnits:e.maxWorkUnits??n.maxWorkUnits,maxTraversalEntries:e.maxTraversalEntries??n.maxTraversalEntries,maxTraversalDepth:e.maxTraversalDepth??n.maxTraversalDepth,maxTraversalWork:e.maxTraversalWork??n.maxTraversalWork,maxLiveBytes:e.maxLiveBytes??n.maxLiveBytes,maxInputBytes:e.maxInputBytes??n.maxInputBytes,maxFileSystemBytes:e.maxFileSystemBytes??n.maxFileSystemBytes,maxDatabaseBytes:e.maxDatabaseBytes??n.maxDatabaseBytes,maxDatabaseResultBytes:e.maxDatabaseResultBytes??n.maxDatabaseResultBytes,maxArchiveBytes:e.maxArchiveBytes??n.maxArchiveBytes,maxArchiveCompressedBytes:e.maxArchiveCompressedBytes??n.maxArchiveCompressedBytes,maxArchiveEntryBytes:e.maxArchiveEntryBytes??n.maxArchiveEntryBytes,maxArchiveEntries:e.maxArchiveEntries??n.maxArchiveEntries,maxWorkerMessageBytes:e.maxWorkerMessageBytes??n.maxWorkerMessageBytes,maxExecutionTimeMs:e.maxExecutionTimeMs??n.maxExecutionTimeMs,maxExtensionCleanupTimeMs:e.maxExtensionCleanupTimeMs??n.maxExtensionCleanupTimeMs,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??n.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??n.maxPythonTimeoutMs,maxJsTimeoutMs:e.maxJsTimeoutMs??n.maxJsTimeoutMs,maxJsBridgeRequests:e.maxJsBridgeRequests??n.maxJsBridgeRequests,maxGlobOperations:e.maxGlobOperations??n.maxGlobOperations,maxStringLength:e.maxStringLength??n.maxStringLength,maxArrayElements:e.maxArrayElements??n.maxArrayElements,maxHeredocSize:e.maxHeredocSize??n.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??n.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??n.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??n.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??n.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??n.maxSourceDepth};for(let s of Object.keys(r)){let i=r[s];if(i!==Number.POSITIVE_INFINITY&&(!Number.isSafeInteger(i)||i<0))throw new RangeError(`${s} must be a non-negative safe integer or positive Infinity`)}return r}function vo(e){return"load"in e&&typeof e.load=="function"}function $o(e){let t=null,n=!1,r=new Set,s=o=>{t=o;for(let l of r)l.resolve(o);r.clear()},i=o=>{n=!1;for(let l of r)l.reject(o);r.clear()},a=()=>{n=!0;let o;try{o=Promise.resolve(e.load())}catch(l){i(l);return}po.call(o,s,i)};return{name:e.name,trusted:e.trusted!==!1,async execute(o,l){if(!t){let c,f=new Promise((d,p)=>{c={resolve:d,reject:p},r.add(c)});n||a();try{t=await Yn(f,l.signal,`bash: ${e.name} was cancelled before it started
6
+ `)}finally{c&&r.delete(c)}}let u=t;if(!u)throw new Error(`Failed to load command: ${e.name}`);return u.execute(o,l)}}}var xo=Object.freeze(Object.create(null)),Rr=class{limits;signal;commandCount=0;workUnits=0;liveBytes=0;inputBytes=0;outputBytes=0;countersByKind=new Map;bytesByKind=new Map;depthByKind=new Map;cleanupCallbacks=[];poisoned;closed=!1;startedAt=Date.now();get remainingLiveBytes(){return Math.max(0,this.limits.maxLiveBytes-this.liveBytes)}get outputBytesUsed(){return this.outputBytes}constructor(t,n=void 0){this.limits=t,this.signal=n}fail(t){throw this.poisoned??=t,this.poisoned}poisonAfterAbort(t){this.poisoned??=t}assertUsable(){if(this.poisoned)throw this.poisoned;if(this.closed)throw new Error("execution budget is already closed");this.throwIfAborted()}chargeCommand(){return this.consume("commands",1,"execution")}consumeWork(t=1,n="execution"){return this.consume("work",t,n)}consumeLimited(t,n,r,s=t){this.assertUsable();let i=this.countersByKind.get(t)??0;return(!Number.isSafeInteger(n)||n<0||!Number.isSafeInteger(r)||r<0||n>r-i)&&this.fail(new P(`${s}: ${t} work limit exceeded (${r})`,"iterations")),n>this.limits.maxWorkUnits-this.workUnits&&this.fail(new P(`${s}: aggregate work limit exceeded (${this.limits.maxWorkUnits})`,"iterations")),this.countersByKind.set(t,i+n),this.workUnits+=n,i+n}consumeInput(t,n="execution"){return this.assertUsable(),(!Number.isSafeInteger(t)||t<0||t>this.limits.maxInputBytes-this.inputBytes)&&this.fail(new P(`${n}: aggregate input size limit exceeded (${this.limits.maxInputBytes} bytes)`,"string_length")),this.inputBytes+=t,this.inputBytes}consume(t,n=1,r=t){this.assertUsable();let s=this.countersByKind.get(t)??0,i=t==="commands"?this.commandCount:this.workUnits,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!==xo&&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 Ve("",`bash: ${t} aborted
7
+ `)),Date.now()-this.startedAt>this.limits.maxExecutionTimeMs&&this.fail(new Ve("",`bash: ${t} exceeded execution deadline (${this.limits.maxExecutionTimeMs}ms)
8
+ `))}remainingTimeMs(){return Math.max(0,this.limits.maxExecutionTimeMs-(Date.now()-this.startedAt))}registerCleanup(t){this.assertUsable(),this.cleanupCallbacks.push(t);let n=!0;return()=>{if(!n)return;n=!1;let r=this.cleanupCallbacks.indexOf(t);r>=0&&this.cleanupCallbacks.splice(r,1)}}async close(){if(this.closed)return;this.closed=!0;let t=[],n=Date.now()+this.limits.maxExtensionCleanupTimeMs;for(let r=this.cleanupCallbacks.length-1;r>=0;r--)try{let s=n-Date.now();if(s<=0){t.push(new Error("execution cleanup grace period exceeded"));break}let i,a=await Promise.race([Promise.resolve().then(this.cleanupCallbacks[r]).then(()=>({ok:!0}),o=>({ok:!1,error:o})),new Promise(o=>{i=Kn(()=>o({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(Xn(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 ko(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 Po(e,t,n="pipeline"){e.relinquishOutput(t,n,xo)}var fn=new TextEncoder;function Vf(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var At=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):Vf(s)?this.writeFileSync(r,s.content,void 0,{mode:s.mode,mtime:s.mtime}):this.writeFileSync(r,s)}ensureParentDirs(t){let n=dt(t);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,n,r,s){Q(t,"write");let i=z(t);this.ensureParentDirs(i);let a=Vt(r);this.assertCanAllocate(i,this.contentByteLength(n,a));let o=Nn(n,a);this.setEntry(i,{type:"file",content:o,mode:s?.mode??420,mtime:s?.mtime??new Date})}writeFileLazy(t,n,r){Q(t,"write");let s=z(t);this.ensureParentDirs(s),this.setEntry(s,{type:"file",lazy:n,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,n){let r=await Le.runTrustedAsync(async()=>n.lazy()),s=typeof r=="string"?fn.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=Vt(n);return Rn(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Rn(n,"binary")}async readFileBuffer(t){Q(t,"open");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in r){let s=await this.materializeLazy(n,r);return s.content instanceof Uint8Array?s.content:fn.encode(s.content)}return r.content instanceof Uint8Array?r.content:fn.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){Q(t,"append");let s=z(t),i=this.data.get(s);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let a=Vt(r),o=this.contentByteLength(n,a);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(s,l));let u="content"in l&&l.content instanceof Uint8Array?l.content:fn.encode("content"in l?l.content:"");this.assertCanAllocate(s,u.byteLength+o);let c=Nn(n,a),f=new Uint8Array(u.length+c.length);f.set(u),f.set(c,u.length),this.setEntry(s,{type:"file",content:f,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,n,r)}async exists(t){if(t.includes("\0"))return!1;try{let n=this.resolvePathWithSymlinks(t);return this.data.has(n)}catch{return!1}}async stat(t){Q(t,"stat");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=fn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}async lstat(t){Q(t,"lstat");let n=this.resolveIntermediateSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=fn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}resolveIntermediateSymlinks(t){let n=z(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",i=new Set;for(let a=0;a<r.length-1;a++){let o=r[a];s=`${s}/${o}`;let l=this.data.get(s),u=0,c=40;for(;l&&l.type==="symlink"&&u<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(s),s=Cn(s,l.target),l=this.data.get(s),u++}if(u>=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let n=z(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,u=40;for(;o&&o.type==="symlink"&&l<u;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(s),s=Cn(s,o.target),o=this.data.get(s),l++}if(l>=u)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return s}async mkdir(t,n){this.mkdirSync(t,n)}async createExclusive(t,n){let r=n.directory?"mkdir":"open";Q(t,n.directory?"mkdir":"write");let s=z(t),i=dt(s),a=i==="/"?"/":this.resolvePathWithSymlinks(i),o=rt(a,s.slice(s.lastIndexOf("/")+1));if(this.data.has(o))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);if(a!=="/"){let l=this.data.get(a);if(!l)throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);if(l.type!=="directory")throw new Error(`ENOTDIR: not a directory, ${r} '${t}'`)}if(n.directory){this.setEntry(o,{type:"directory",mode:n.mode,mtime:new Date});return}this.assertCanAllocate(o,0),this.setEntry(o,{type:"file",content:new Uint8Array(0),mode:n.mode,mtime:new Date})}mkdirSync(t,n){Q(t,"mkdir");let r=z(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let s=dt(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){Q(t,"scandir");let n=z(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let s=new Set;for(;r&&r.type==="symlink";){if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(n),n=Cn(n,r.target),r=this.data.get(n)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=n==="/"?"/":`${n}/`,a=new Map;for(let[o,l]of this.data.entries())if(o!==n&&o.startsWith(i)){let u=o.slice(i.length),c=u.split("/")[0];c&&!u.includes("/",c.length)&&!a.has(c)&&a.set(c,{name:c,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){Q(t,"rm");let r=z(t),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(s.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of i){let o=rt(r,a);await this.rm(o,n)}}}this.deleteEntry(r)}async cp(t,n,r){Q(t,"cp"),Q(n,"cp");let s=z(t),i=z(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:fn.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(It(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 u=rt(s,l),c=rt(i,l);await this.cp(u,c,r)}}}async mv(t,n){Q(t,"mv"),Q(n,"mv");let r=z(t),s=z(n);if(r===s)return;let i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(i.type==="directory"&&It(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(rt(r,o),rt(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 Pn(t,n)}async chmod(t,n){Q(t,"chmod");let r=z(t),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);s.mode=n}async symlink(t,n){Q(n,"symlink");let r=z(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,n){Q(t,"link"),Q(n,"link");let r=z(t),s=z(n),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let 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){Q(t,"readlink");let n=z(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){Q(t,"realpath");let n=this.resolvePathWithSymlinks(t);if(!this.data.has(n))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return n}async utimes(t,n,r){Q(t,"utimes");let s=z(t),i=this.resolvePathWithSymlinks(s),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=r}};var No="5.1.0(1)-release",Ro="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function Hs(e){let{pid:t,ppid:n,uid:r,gid:s}=e;return`Name: bash
6
9
  State: R (running)
7
10
  Pid: ${t}
8
11
  PPid: ${n}
9
12
  Uid: ${r} ${r} ${r} ${r}
10
13
  Gid: ${s} ${s} ${s} ${s}
11
- `}function _f(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Lf(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 Tf(e){e.mkdirSync("/dev",{recursive:!0}),e.mkdirSync("/dev/fd",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function Mf(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${wo}
14
+ `}function zf(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function qf(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 Uf(e){e.mkdirSync("/dev",{recursive:!0}),e.mkdirSync("/dev/fd",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function jf(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Ro}
12
15
  `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
13
- `),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 Eo(e,t,n={pid:1,ppid:0,uid:1e3,gid:1e3}){_f(e)&&(Lf(e,t),Tf(e),Mf(e,n))}function Le(e){return{kind:e.kind,elements:new Map(e.elements)}}function nt(e){return new Map(Array.from(e??[],([t,n])=>[t,Le(n)]))}function ve(e,t){return e.state.arrays?.get(t)}function Gn(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 Lt(e,t,n){let r=Gn(e,t,n);return r.kind=n,r}function Pe(e,t){return e.state.arrays?.has(t)??!1}function ae(e,t,n){return ve(e,t)?.elements.get(String(n))}function Tt(e,t,n){return ve(e,t)?.elements.has(String(n))??!1}function j(e,t,n,r,s){let i=Gn(e,t,s),a=String(n);if(!i.elements.has(a)&&i.elements.size>=e.limits.maxArrayElements)throw new k(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(F(r)>e.limits.maxStringLength)throw new k(`array value string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");i.elements.set(a,r)}function rn(e,t,n,r=!1){let s=new Set(r?[]:ve(e,t)?.elements.keys()??[]);for(let i of n)if(s.add(String(i)),s.size>e.limits.maxArrayElements)throw new k(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements")}function sn(e,t,n){return ve(e,t)?.elements.delete(String(n))??!1}function Zn(e,t){e.state.arrays?.delete(t),e.state.associativeArrays?.delete(t)}function be(e,t){return Array.from(ve(e,t)?.elements.keys()??[]).filter(r=>/^(0|[1-9]\d*)$/.test(r)).map(Number).sort((r,s)=>r-s)}function ye(e,t){Gn(e,t,e.state.associativeArrays?.has(t)?"associative":"indexed").elements.clear()}function gt(e,t){return Array.from(ve(e,t)?.elements.keys()??[]).sort()}function xr(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function Vs(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=xr(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=[],u=o?2:1,c=a.slice(u);c&&l.push({type:"Literal",value:c});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?l.push({type:"Literal",value:Ff(d)}):l.push(d)}return{key:r,valueParts:l,append:o}}function Ff(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 xn(n.word)}).join(",")}}`}function xn(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}`:""}`:xn(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",n.user&&(t+=n.user);break}return t}var Bf=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],Wf=["braceexpand","hashall","interactive-comments"];function zs(e){let t=[],n=[...Wf.map(r=>({name:r,enabled:!0})),...Bf.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 kn(e){e.state.env.set("SHELLOPTS",zs(e.state.options))}var Vf=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function qs(e){let t=[];for(let n of Vf)e[n]&&t.push(n);return t.join(":")}function Us(e){e.state.env.set("BASHOPTS",qs(e.state.shoptOptions))}var T={script(e){return{type:"Script",statements:e}},statement(e,t=[],n=!1,r,s){let i={type:"Statement",pipelines:e,operators:t,background:n};return r&&(i.deferredError=r),s!==void 0&&(i.sourceText=s),i},pipeline(e,t=!1,n=!1,r=!1,s){return{type:"Pipeline",commands:e,negated:t,timed:n,timePosix:r,pipeStderr:s}},simpleCommand(e,t=[],n=[],r=[]){return{type:"SimpleCommand",name:e,args:t,assignments:n,redirections:r}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},processSubstitution(e,t){return{type:"ProcessSubstitution",body:e,direction:t}},assignment(e,t,n=!1,r=null){return{type:"Assignment",name:e,value:t,append:n,array:r}},redirection(e,t,n=null,r){let s={type:"Redirection",fd:n,operator:e,target:t};return r&&(s.fdVariable=r),s},hereDoc(e,t,n=!1,r=!1,s){let i={type:"HereDoc",delimiter:e,content:t,stripTabs:n,quoted:r};return s!==void 0&&(i.terminated=s),i},ifNode(e,t=null,n=[]){return{type:"If",clauses:e,elseBody:t,redirections:n}},forNode(e,t,n,r=[]){return{type:"For",variable:e,words:t,body:n,redirections:r}},whileNode(e,t,n=[]){return{type:"While",condition:e,body:t,redirections:n}},untilNode(e,t,n=[]){return{type:"Until",condition:e,body:t,redirections:n}},caseNode(e,t,n=[]){return{type:"Case",word:e,items:t,redirections:n}},caseItem(e,t,n=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:n}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,n=[],r){return{type:"FunctionDef",name:e,body:t,redirections:n,sourceFile:r}},conditionalCommand(e,t=[],n){return{type:"ConditionalCommand",expression:e,redirections:t,line:n}},arithmeticCommand(e,t=[],n){return{type:"ArithmeticCommand",expression:e,redirections:t,line:n}}};function bo(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 kr(e,t){let n="",r=t,s=0,i=!1,a,o=l=>l===" "||l===" "||l===`
16
+ `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>Hs(t)):e.writeFileSync("/proc/self/status",Hs(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 Do(e,t,n={pid:1,ppid:0,uid:1e3,gid:1e3}){if(zf(e)){let r=Gf(e);qf(r,t),Uf(r),jf(r,n)}}function Gf(e){let t=r=>{try{r()}catch(s){if(!(s instanceof Error&&s.message.startsWith("ENOSYS")))throw s}},n={mkdirSync:(r,s)=>t(()=>e.mkdirSync(r,s)),writeFileSync:(r,s)=>t(()=>e.writeFileSync(r,s))};return e.writeFileLazy&&(n.writeFileLazy=(r,s)=>t(()=>e.writeFileLazy?.(r,s))),n}var dn=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new At,t?.mounts)for(let{mountPoint:n,filesystem:r}of t.mounts)this.mount(n,r)}mount(t,n){this.validateMountPath(t);let r=z(t);this.validateMount(r),this.mounts.set(r,n)}unmount(t){let n=z(t);if(!this.mounts.has(n))throw new Error(`No filesystem mounted at '${t}'`);this.mounts.delete(n)}getMounts(){return Array.from(this.mounts,([t,n])=>({mountPoint:t,filesystem:n}))}isMountPoint(t){let n=z(t);return this.mounts.has(n)}validateMountPath(t){let n=t.split("/");for(let r of n)if(r==="."||r==="..")throw new Error(`Invalid mount point '${t}': contains '.' or '..' segments`)}validateMount(t){if(t==="/")throw new Error("Cannot mount at root '/'");for(let n of this.mounts.keys())if(n!==t){if(t.startsWith(`${n}/`))throw new Error(`Cannot mount at '${t}': inside existing mount '${n}'`);if(n.startsWith(`${t}/`))throw new Error(`Cannot mount at '${t}': would contain existing mount '${n}'`)}}routePath(t){Q(t,"access");let n=z(t);for(let[r,s]of this.mounts){if(n===r)return{fs:s,relativePath:"/"};if(n.startsWith(`${r}/`))return{fs:s,relativePath:n.slice(r.length)}}return{fs:this.baseFs,relativePath:n}}getChildMountPoints(t){let n=z(t),r=n==="/"?"/":`${n}/`,s=[];for(let i of this.mounts.keys())if(i.startsWith(r)){let 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 $n(n,r)}async readFileBuffer(t){let{fs:n,relativePath:r}=this.routePath(t);return n.readFileBuffer(r)}async writeFile(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.writeFile(i,n,r)}async appendFile(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.appendFile(i,n,r)}async exists(t){let n=z(t);if(this.mounts.has(n)||this.getChildMountPoints(n).length>0)return!0;let{fs:s,relativePath:i}=this.routePath(t);return s.exists(i)}async stat(t){let n=z(t),r=this.mounts.get(n);if(r)try{return await r.stat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(n).length>0)try{return await this.baseFs.stat(n)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:a}=this.routePath(t);return i.stat(a)}async lstat(t){let n=z(t),r=this.mounts.get(n);if(r)try{return await r.lstat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(n).length>0)try{return await this.baseFs.lstat(n)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:a}=this.routePath(t);return i.lstat(a)}async mkdir(t,n){let r=z(t);if(this.mounts.has(r)){if(n?.recursive)return;throw new Error(`EEXIST: directory already exists, mkdir '${t}'`)}if(this.getChildMountPoints(r).length>0&&n?.recursive)return;let{fs:i,relativePath:a}=this.routePath(t);return i.mkdir(a,n)}async createExclusive(t,n){let r=z(t),s=n.directory?"mkdir":"open";if(this.mounts.has(r))throw new Error(`EEXIST: file already exists, ${s} '${t}'`);let{fs:i,relativePath:a}=this.routePath(t);if(!i.createExclusive)throw new uo(t,s);let o=dt(a);return o!=="/"&&this.getChildMountPoints(dt(r)).length>0&&!await i.exists(o)&&await i.mkdir(o,{recursive:!0}),i.createExclusive(a,n)}mkdirSync(t,n){let{fs:r,relativePath:s}=this.routePath(t),i=r;if(!i.mkdirSync)throw new Error(`ENOSYS: function not implemented, mkdir '${t}'`);i.mkdirSync(s,n)}writeFileSync(t,n){let{fs:r,relativePath:s}=this.routePath(t),i=r;if(!i.writeFileSync)throw new Error(`ENOSYS: function not implemented, write '${t}'`);i.writeFileSync(s,n)}async readdir(t){let n=z(t),r=new Set,s=null,{fs:i,relativePath:a}=this.routePath(t);try{let l=await i.readdir(a);for(let u of l)r.add(u)}catch(l){let u=l.code,c=l.message||"";if(u!=="ENOENT"&&!c.includes("ENOENT"))throw l;s=l}let 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=z(t);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot remove '${t}'`);if(this.getChildMountPoints(r).length>0)throw new Error(`EBUSY: contains mount points, cannot remove '${t}'`);let{fs:i,relativePath:a}=this.routePath(t);return i.rm(a,n)}async cp(t,n,r){if((await this.stat(t)).isDirectory&&It(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=z(t);if((await this.stat(t)).isDirectory&&It(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 Pn(t,n)}getAllPaths(){let t=new Set;for(let n of this.baseFs.getAllPaths())t.add(n);for(let[n,r]of this.mounts){let s=n.split("/").filter(Boolean),i="";for(let a of s)i=`${i}/${a}`,t.add(i);for(let a of r.getAllPaths())a==="/"?t.add(n):t.add(`${n}${a}`)}return Array.from(t).sort()}async chmod(t,n){let r=z(t),s=this.mounts.get(r);if(s)return s.chmod("/",n);let{fs:i,relativePath: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=z(t);if(this.mounts.has(n))return n;let{fs:r,relativePath:s}=this.routePath(t),i=await r.realpath(s);for(let a of this.mounts.keys())if(n===a||n.startsWith(`${a}/`))return i==="/"?a:`${a}${i}`;return i}async crossMountCopy(t,n,r){let s=await this.lstat(t);if(s.isFile){let i=await this.readFileBuffer(t);await this.writeFile(n,i),await this.chmod(n,s.mode)}else if(s.isDirectory){if(!r?.recursive)throw new Error(`cp: ${t} is a directory (not copied)`);await this.mkdir(n,{recursive:!0});let i=await this.readdir(t);for(let a of i){let o=rt(t,a),l=rt(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)}};function Te(e){return{kind:e.kind,elements:new Map(e.elements)}}function st(e){return new Map(Array.from(e??[],([t,n])=>[t,Te(n)]))}function ve(e,t){return e.state.arrays?.get(t)}function er(e,t,n="indexed"){e.state.arrays??=new Map;let r=e.state.arrays.get(t);return r||(r={kind:n,elements:new Map},e.state.arrays.set(t,r)),r}function zt(e,t,n){let r=er(e,t,n);return r.kind=n,r}function Pe(e,t){return e.state.arrays?.has(t)??!1}function ie(e,t,n){return ve(e,t)?.elements.get(String(n))}function qt(e,t,n){return ve(e,t)?.elements.has(String(n))??!1}function U(e,t,n,r,s){let i=er(e,t,s),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 pn(e,t,n,r=!1){let s=new Set(r?[]:ve(e,t)?.elements.keys()??[]);for(let i of n)if(s.add(String(i)),s.size>e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements")}function hn(e,t,n){return ve(e,t)?.elements.delete(String(n))??!1}function tr(e,t){e.state.arrays?.delete(t),e.state.associativeArrays?.delete(t)}function be(e,t){return Array.from(ve(e,t)?.elements.keys()??[]).filter(r=>/^(0|[1-9]\d*)$/.test(r)).map(Number).sort((r,s)=>r-s)}function ye(e,t){er(e,t,e.state.associativeArrays?.has(t)?"associative":"indexed").elements.clear()}function vt(e,t){return Array.from(ve(e,t)?.elements.keys()??[]).sort()}function Ir(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function Zs(e){if(e.parts.length<2)return null;let t=e.parts[0],n=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let r,s=n,i=1;if(n.type==="Literal"&&n.value.startsWith("]")){let f=n.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))r=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let d=e.parts[2];if(d.type!=="Literal"||!d.value.startsWith("=")&&!d.value.startsWith("+="))return null;r=t.pattern.slice(1),s=d,i=2}else return null}else if(t.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(n.type==="SingleQuoted")r=n.value;else{r="";for(let d of n.parts)(d.type==="Literal"||d.type==="Escaped")&&(r+=d.value)}s=f,i=2}else if(t.pattern.endsWith("]")){if(n.type!=="Literal"||!n.value.startsWith("=")&&!n.value.startsWith("+="))return null;r=t.pattern.slice(1,-1)}else return null;r=Ir(r);let 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=[],u=o?2:1,c=a.slice(u);c&&l.push({type:"Literal",value:c});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?l.push({type:"Literal",value:Hf(d)}):l.push(d)}return{key:r,valueParts:l,append:o}}function Hf(e){return`{${e.items.map(n=>{if(n.type==="Range"){let r=n.startStr??String(n.start),s=n.endStr??String(n.end),i=`${r}..${s}`;return n.step&&(i+=`..${n.step}`),i}return On(n.word)}).join(",")}}`}function On(e){let t="";for(let n of e.parts)switch(n.type){case"Literal":t+=n.value;break;case"Glob":t+=n.pattern;break;case"SingleQuoted":t+=n.value;break;case"DoubleQuoted":for(let r of n.parts)(r.type==="Literal"||r.type==="Escaped")&&(t+=r.value);break;case"Escaped":t+=n.value;break;case"BraceExpansion":t+="{",t+=n.items.map(r=>r.type==="Range"?`${r.startStr}..${r.endStr}${r.step?`..${r.step}`:""}`:On(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",n.user&&(t+=n.user);break}return t}var Zf=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],Qf=["braceexpand","hashall","interactive-comments"];function Qs(e){let t=[],n=[...Qf.map(r=>({name:r,enabled:!0})),...Zf.map(r=>({name:r,enabled:e[r]}))].sort((r,s)=>r.name.localeCompare(s.name));for(let r of n)r.enabled&&t.push(r.name);return t.join(":")}function _n(e){e.state.env.set("SHELLOPTS",Qs(e.state.options))}var Kf=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Ks(e){let t=[];for(let n of Kf)e[n]&&t.push(n);return t.join(":")}function Xs(e){e.state.env.set("BASHOPTS",Ks(e.state.shoptOptions))}var T={script(e){return{type:"Script",statements:e}},statement(e,t=[],n=!1,r,s){let i={type:"Statement",pipelines:e,operators:t,background:n};return r&&(i.deferredError=r),s!==void 0&&(i.sourceText=s),i},pipeline(e,t=!1,n=!1,r=!1,s){return{type:"Pipeline",commands:e,negated:t,timed:n,timePosix:r,pipeStderr:s}},simpleCommand(e,t=[],n=[],r=[]){return{type:"SimpleCommand",name:e,args:t,assignments:n,redirections:r}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},processSubstitution(e,t){return{type:"ProcessSubstitution",body:e,direction:t}},assignment(e,t,n=!1,r=null){return{type:"Assignment",name:e,value:t,append:n,array:r}},redirection(e,t,n=null,r){let s={type:"Redirection",fd:n,operator:e,target:t};return r&&(s.fdVariable=r),s},hereDoc(e,t,n=!1,r=!1,s){let i={type:"HereDoc",delimiter:e,content:t,stripTabs:n,quoted:r};return s!==void 0&&(i.terminated=s),i},ifNode(e,t=null,n=[]){return{type:"If",clauses:e,elseBody:t,redirections:n}},forNode(e,t,n,r=[]){return{type:"For",variable:e,words:t,body:n,redirections:r}},whileNode(e,t,n=[]){return{type:"While",condition:e,body:t,redirections:n}},untilNode(e,t,n=[]){return{type:"Until",condition:e,body:t,redirections:n}},caseNode(e,t,n=[]){return{type:"Case",word:e,items:t,redirections:n}},caseItem(e,t,n=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:n}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,n=[],r){return{type:"FunctionDef",name:e,body:t,redirections:n,sourceFile:r}},conditionalCommand(e,t=[],n){return{type:"ConditionalCommand",expression:e,redirections:t,line:n}},arithmeticCommand(e,t=[],n){return{type:"ArithmeticCommand",expression:e,redirections:t,line:n}}};function Io(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 Or(e,t){let n="",r=t,s=0,i=!1,a,o=l=>l===" "||l===" "||l===`
14
17
  `||l===";"||l==="&"||l==="|"||l==="<"||l===">"||l==="("||l===")";for(;r<e.length;){let l=e[r];if(l==="'"){let u=s>0;for(u||(i=!0),u&&(n+=l),r++;r<e.length&&e[r]!=="'";)n+=e[r],r++;r<e.length?(u&&(n+=e[r]),r++):a=l;continue}if(l==='"'){let u=s>0;for(u||(i=!0),u&&(n+=l),r++;r<e.length&&e[r]!=='"';){if(e[r]==="\\"&&r+1<e.length){if(u){n+=e.slice(r,r+2),r+=2;continue}let c=e[r+1];if(c==="$"||c==="`"||c==='"'||c==="\\"||c===`
15
18
  `){r+=2,c!==`
16
19
  `&&(n+=c);continue}}n+=e[r],r++}r<e.length?(u&&(n+=e[r]),r++):a=l;continue}if(l==="\\"&&r+1<e.length){if(s>0){n+=e.slice(r,r+2),r+=2;continue}i=!0;let u=e[r+1];u!==`
17
- `&&(n+=u),r+=2;continue}if(s===0&&(l==="$"||l==="<"||l===">")&&e[r+1]==="("){n+=`${l}(`,s=1,r+=2;continue}if(s===0&&o(l))break;s>0&&(l==="("?s++:l===")"&&s--),n+=l,r++}return{delim:n,endPos:r,quoted:i,unclosedQuote:a,unclosedSubstitution:s>0}}function zf(e,t,n){let r=t+1;for(let{delim:s,stripTabs:i}of n)for(;;){if(r>=e.length)return e.length;let a=e.indexOf(`
18
- `,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 So(e,t,n){let r=1,s=t,i=!1,a=!1,o=0,l=!1,u="",c=[],f=0;for(;s<e.length&&r>0;){let d=e[s];if(i)d==="'"&&(i=!1);else if(a)d==="\\"&&s+1<e.length?s++:d==='"'&&(a=!1);else{if(d==="("&&e[s+1]==="("?f++:d===")"&&e[s+1]===")"&&f>0&&f--,f===0&&d==="<"&&e[s+1]==="<"&&e[s+2]!=="<"){let p=s+2,h=!1;for(e[p]==="-"&&(h=!0,p++);e[p]===" "||e[p]===" ";)p++;let{delim:m,endPos:E,unclosedQuote:b,unclosedSubstitution:g}=kr(e,p);if(b&&n(`unexpected EOF while looking for matching \`${b}'`),g&&n("unexpected EOF while looking for matching `)'"),m.length>0){c.push({delim:m,stripTabs:h}),u="",s=E;continue}}if(d===`
19
- `&&c.length>0){let p=zf(e,s,c);c.length=0,u="",s=p;continue}d==="'"?(i=!0,u=""):d==='"'?(a=!0,u=""):d==="\\"&&s+1<e.length?(s++,u=""):/[a-zA-Z_]/.test(d)?u+=d:(u==="case"?(o++,l=!1):u==="in"&&o>0?l=!0:u==="esac"&&o>0&&(o--,l=!1),u="",d==="("?s>0&&e[s-1]==="$"?r++:l||r++:d===")"?l?l=!1:r--:d===";"&&o>0&&s+1<e.length&&e[s+1]===";"&&(l=!0))}r>0&&s++}return r>0&&n("unexpected EOF while looking for matching `)'"),s}function Ao(e,t,n,r){let s=t+2,i=So(e,s,r),a=e.slice(s,i),l=n().parse(a);return{part:T.commandSubstitution(l,!1),endIndex:i+1}}function vo(e,t,n,r){let s=e[t]==="<"?"input":"output",i=t+2,a=So(e,i,r),o=n().parse(e.slice(i,a));return{part:T.processSubstitution(o,s),endIndex:a+1}}function $o(e,t,n,r,s){let a=t+1,o="";for(;a<e.length&&e[a]!=="`";)if(e[a]==="\\"){let c=e[a+1];c==="$"||c==="`"||c==="\\"||c===`
20
+ `&&(n+=u),r+=2;continue}if(s===0&&(l==="$"||l==="<"||l===">")&&e[r+1]==="("){n+=`${l}(`,s=1,r+=2;continue}if(s===0&&o(l))break;s>0&&(l==="("?s++:l===")"&&s--),n+=l,r++}return{delim:n,endPos:r,quoted:i,unclosedQuote:a,unclosedSubstitution:s>0}}function Xf(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(`
21
+ `,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 Oo(e,t,n){let r=1,s=t,i=!1,a=!1,o=0,l=!1,u="",c=[],f=0;for(;s<e.length&&r>0;){let d=e[s];if(i)d==="'"&&(i=!1);else if(a)d==="\\"&&s+1<e.length?s++:d==='"'&&(a=!1);else{if(d==="("&&e[s+1]==="("?f++:d===")"&&e[s+1]===")"&&f>0&&f--,f===0&&d==="<"&&e[s+1]==="<"&&e[s+2]!=="<"){let p=s+2,h=!1;for(e[p]==="-"&&(h=!0,p++);e[p]===" "||e[p]===" ";)p++;let{delim:m,endPos:E,unclosedQuote:S,unclosedSubstitution:y}=Or(e,p);if(S&&n(`unexpected EOF while looking for matching \`${S}'`),y&&n("unexpected EOF while looking for matching `)'"),m.length>0){c.push({delim:m,stripTabs:h}),u="",s=E;continue}}if(d===`
22
+ `&&c.length>0){let p=Xf(e,s,c);c.length=0,u="",s=p;continue}d==="'"?(i=!0,u=""):d==='"'?(a=!0,u=""):d==="\\"&&s+1<e.length?(s++,u=""):/[a-zA-Z_]/.test(d)?u+=d:(u==="case"?(o++,l=!1):u==="in"&&o>0?l=!0:u==="esac"&&o>0&&(o--,l=!1),u="",d==="("?s>0&&e[s-1]==="$"?r++:l||r++:d===")"?l?l=!1:r--:d===";"&&o>0&&s+1<e.length&&e[s+1]===";"&&(l=!0))}r>0&&s++}return r>0&&n("unexpected EOF while looking for matching `)'"),s}function _o(e,t,n,r){let s=t+2,i=Oo(e,s,r),a=e.slice(s,i),l=n().parse(a);return{part:T.commandSubstitution(l,!1),endIndex:i+1}}function Lo(e,t,n,r){let s=e[t]==="<"?"input":"output",i=t+2,a=Oo(e,i,r),o=n().parse(e.slice(i,a));return{part:T.processSubstitution(o,s),endIndex:a+1}}function To(e,t,n,r,s){let a=t+1,o="";for(;a<e.length&&e[a]!=="`";)if(e[a]==="\\"){let c=e[a+1];c==="$"||c==="`"||c==="\\"||c===`
20
23
  `||n&&c==='"'?(c!==`
21
- `&&(o+=c),a+=2):(o+=e[a],a++)}else o+=e[a],a++;a>=e.length&&s("unexpected EOF while looking for matching ``'");let u=r().parse(o);return{part:T.commandSubstitution(u,!0),endIndex:a+1}}var qf=10485760,w;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(w||(w={}));var Qe=class extends Error{line;column;constructor(t,n,r){super(`line ${n}: ${t}`),this.line=n,this.column=r,this.name="LexerError"}},js=new Map([["if",w.IF],["then",w.THEN],["else",w.ELSE],["elif",w.ELIF],["fi",w.FI],["for",w.FOR],["while",w.WHILE],["until",w.UNTIL],["do",w.DO],["done",w.DONE],["case",w.CASE],["esac",w.ESAC],["in",w.IN],["function",w.FUNCTION],["select",w.SELECT],["time",w.TIME],["coproc",w.COPROC]]),Uf=new Set(js.values());function Gs(e){return Uf.has(e)}function xo(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 ko(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 jf=[[";",";","&",w.SEMI_SEMI_AND],["<","<","<",w.TLESS],["&",">",">",w.AND_DGREAT]],Gf=[["[","[",w.DBRACK_START],["]","]",w.DBRACK_END],["(","(",w.DPAREN_START],[")",")",w.DPAREN_END],["&","&",w.AND_AND],["|","|",w.OR_OR],[";",";",w.DSEMI],[";","&",w.SEMI_AND],["|","&",w.PIPE_AMP],[">",">",w.DGREAT],["<","&",w.LESSAND],[">","&",w.GREATAND],["<",">",w.LESSGREAT],[">","|",w.CLOBBER],["&",">",w.AND_GREAT]],Zf=new Map([["|",w.PIPE],["&",w.AMP],[";",w.SEMICOLON],["(",w.LPAREN],[")",w.RPAREN],["<",w.LESS],[">",w.GREAT]]);function Hf(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Po(e){return e===" "||e===" "||e===`
22
- `||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var Pr=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];pendingHeredocDelimiterMode;dparenDepth=0;maxHeredocSize;constructor(t,n){this.input=t,this.maxHeredocSize=n?.maxHeredocSize??qf}tokenize(){let n=this.input.length,r=this.tokens,s=this.pendingHeredocs;for(;this.pos<n;){if(s.length>0&&r.length>0&&r[r.length-1].type===w.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=n)break;let i=this.nextToken();i&&r.push(i)}return s.length>0&&this.readHeredocContent(),r.push({type:w.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let t=this.input,n=t.length,r=this.pos,s=this.column,i=this.line;for(;r<n;){let a=t[r];if(a===" "||a===" ")r++,s++;else if(a==="\\"&&t[r+1]===`
24
+ `&&(o+=c),a+=2):(o+=e[a],a++)}else o+=e[a],a++;a>=e.length&&s("unexpected EOF while looking for matching ``'");let u=r().parse(o);return{part:T.commandSubstitution(u,!0),endIndex:a+1}}var Yf=10485760,w;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(w||(w={}));var Ke=class extends Error{line;column;constructor(t,n,r){super(`line ${n}: ${t}`),this.line=n,this.column=r,this.name="LexerError"}},Ys=new Map([["if",w.IF],["then",w.THEN],["else",w.ELSE],["elif",w.ELIF],["fi",w.FI],["for",w.FOR],["while",w.WHILE],["until",w.UNTIL],["do",w.DO],["done",w.DONE],["case",w.CASE],["esac",w.ESAC],["in",w.IN],["function",w.FUNCTION],["select",w.SELECT],["time",w.TIME],["coproc",w.COPROC]]),Jf=new Set(Ys.values());function Js(e){return Jf.has(e)}function Mo(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 Fo(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];if(r==="[")t++;else if(r==="]")t--;else{if(t===0&&r==="=")return n;if(t===0&&r==="+"&&e[n+1]==="=")return n+1}}return-1}var ed=[[";",";","&",w.SEMI_SEMI_AND],["<","<","<",w.TLESS],["&",">",">",w.AND_DGREAT]],td=[["[","[",w.DBRACK_START],["]","]",w.DBRACK_END],["(","(",w.DPAREN_START],[")",")",w.DPAREN_END],["&","&",w.AND_AND],["|","|",w.OR_OR],[";",";",w.DSEMI],[";","&",w.SEMI_AND],["|","&",w.PIPE_AMP],[">",">",w.DGREAT],["<","&",w.LESSAND],[">","&",w.GREATAND],["<",">",w.LESSGREAT],[">","|",w.CLOBBER],["&",">",w.AND_GREAT]],nd=new Map([["|",w.PIPE],["&",w.AMP],[";",w.SEMICOLON],["(",w.LPAREN],[")",w.RPAREN],["<",w.LESS],[">",w.GREAT]]);function rd(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Bo(e){return e===" "||e===" "||e===`
25
+ `||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var _r=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];pendingHeredocDelimiterMode;dparenDepth=0;maxHeredocSize;constructor(t,n){this.input=t,this.maxHeredocSize=n?.maxHeredocSize??Yf}tokenize(){let n=this.input.length,r=this.tokens,s=this.pendingHeredocs;for(;this.pos<n;){if(s.length>0&&r.length>0&&r[r.length-1].type===w.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=n)break;let i=this.nextToken();i&&r.push(i)}return s.length>0&&this.readHeredocContent(),r.push({type:w.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let t=this.input,n=t.length,r=this.pos,s=this.column,i=this.line;for(;r<n;){let a=t[r];if(a===" "||a===" ")r++,s++;else if(a==="\\"&&t[r+1]===`
23
26
  `)r+=2,i++,s=1;else break}this.pos=r,this.column=s,this.line=i}nextToken(){let t=this.input,n=this.pos,r=this.line,s=this.column,i=t[n],a=t[n+1],o=t[n+2],l=this.pendingHeredocDelimiterMode;if(this.pendingHeredocDelimiterMode=void 0,l!==void 0&&i!==`
24
27
  `&&!(i==="#"&&this.dparenDepth===0))return this.readHeredocDelimiterToken(n,r,s,l);if(i==="#"&&this.dparenDepth===0)return this.readComment(n,r,s);if(i===`
25
28
  `)return this.pos=n+1,this.line++,this.column=1,{type:w.NEWLINE,value:`
26
- `,start:n,end:n+1,line:r,column:s};if(i==="<"&&a==="<"&&o==="-")return this.pos=n+3,this.column=s+3,this.pendingHeredocDelimiterMode=!0,this.makeToken(w.DLESSDASH,"<<-",n,r,s);for(let[c,f,d,p]of jf)if(i===c&&a===f&&o===d)return this.pos=n+3,this.column=s+3,this.makeToken(p,c+f+d,n,r,s);if(i==="<"&&a==="<")return this.pos=n+2,this.column=s+2,this.pendingHeredocDelimiterMode=!1,this.makeToken(w.DLESS,"<<",n,r,s);if(i==="("&&a==="("){let c=this.tokens[this.tokens.length-1];return this.dparenDepth===0&&c?.end===n&&(c.type===w.LESS||c.type===w.GREAT)?(this.pos=n+1,this.column=s+1,this.makeToken(w.LPAREN,"(",n,r,s)):this.dparenDepth>0?(this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(w.LPAREN,"(",n,r,s)):this.looksLikeNestedSubshells(n+2)||this.dparenClosesWithSpacedParens(n+2)?(this.pos=n+1,this.column=s+1,this.makeToken(w.LPAREN,"(",n,r,s)):(this.pos=n+2,this.column=s+2,this.dparenDepth=1,this.makeToken(w.DPAREN_START,"((",n,r,s))}if(i===")"&&a===")")return this.dparenDepth===1?(this.pos=n+2,this.column=s+2,this.dparenDepth=0,this.makeToken(w.DPAREN_END,"))",n,r,s)):this.dparenDepth>1?(this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(w.RPAREN,")",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(w.RPAREN,")",n,r,s));for(let[c,f,d]of Gf)if(!(c==="("&&f==="("||c===")"&&f===")")&&!(this.dparenDepth>0&&c===";"&&(d===w.DSEMI||d===w.SEMI_AND||d===w.SEMI_SEMI_AND))&&i===c&&a===f){if(d===w.DBRACK_START||d===w.DBRACK_END){let p=t[n+2];if(p!==void 0&&p!==" "&&p!==" "&&p!==`
27
- `&&p!==";"&&p!=="&"&&p!=="|"&&p!=="("&&p!==")"&&p!=="<"&&p!==">")break}return this.pos=n+2,this.column=s+2,this.makeToken(d,c+f,n,r,s)}if(i==="("&&this.dparenDepth>0)return this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(w.LPAREN,"(",n,r,s);if(i===")"&&this.dparenDepth>1)return this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(w.RPAREN,")",n,r,s);let u=Zf.get(i);if(u!==void 0)return this.pos=n+1,this.column=s+1,this.makeToken(u,i,n,r,s);if(i==="{"){let c=this.scanFdVariable(n);return c!==null?(this.pos=c.end,this.column=s+(c.end-n),{type:w.FD_VARIABLE,value:c.varname,start:n,end:c.end,line:r,column:s}):a==="}"?(this.pos=n+2,this.column=s+2,{type:w.WORD,value:"{}",start:n,end:n+2,line:r,column:s,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(n)!==null?this.readWordWithBraceExpansion(n,r,s):this.scanLiteralBraceWord(n)!==null?this.readWordWithBraceExpansion(n,r,s):a!==void 0&&a!==" "&&a!==" "&&a!==`
29
+ `,start:n,end:n+1,line:r,column:s};if(i==="<"&&a==="<"&&o==="-")return this.pos=n+3,this.column=s+3,this.pendingHeredocDelimiterMode=!0,this.makeToken(w.DLESSDASH,"<<-",n,r,s);for(let[c,f,d,p]of ed)if(i===c&&a===f&&o===d)return this.pos=n+3,this.column=s+3,this.makeToken(p,c+f+d,n,r,s);if(i==="<"&&a==="<")return this.pos=n+2,this.column=s+2,this.pendingHeredocDelimiterMode=!1,this.makeToken(w.DLESS,"<<",n,r,s);if(i==="("&&a==="("){let c=this.tokens[this.tokens.length-1];return this.dparenDepth===0&&c?.end===n&&(c.type===w.LESS||c.type===w.GREAT)?(this.pos=n+1,this.column=s+1,this.makeToken(w.LPAREN,"(",n,r,s)):this.dparenDepth>0?(this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(w.LPAREN,"(",n,r,s)):this.looksLikeNestedSubshells(n+2)||this.dparenClosesWithSpacedParens(n+2)?(this.pos=n+1,this.column=s+1,this.makeToken(w.LPAREN,"(",n,r,s)):(this.pos=n+2,this.column=s+2,this.dparenDepth=1,this.makeToken(w.DPAREN_START,"((",n,r,s))}if(i===")"&&a===")")return this.dparenDepth===1?(this.pos=n+2,this.column=s+2,this.dparenDepth=0,this.makeToken(w.DPAREN_END,"))",n,r,s)):this.dparenDepth>1?(this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(w.RPAREN,")",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(w.RPAREN,")",n,r,s));for(let[c,f,d]of td)if(!(c==="("&&f==="("||c===")"&&f===")")&&!(this.dparenDepth>0&&c===";"&&(d===w.DSEMI||d===w.SEMI_AND||d===w.SEMI_SEMI_AND))&&i===c&&a===f){if(d===w.DBRACK_START||d===w.DBRACK_END){let p=t[n+2];if(p!==void 0&&p!==" "&&p!==" "&&p!==`
30
+ `&&p!==";"&&p!=="&"&&p!=="|"&&p!=="("&&p!==")"&&p!=="<"&&p!==">")break}return this.pos=n+2,this.column=s+2,this.makeToken(d,c+f,n,r,s)}if(i==="("&&this.dparenDepth>0)return this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(w.LPAREN,"(",n,r,s);if(i===")"&&this.dparenDepth>1)return this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(w.RPAREN,")",n,r,s);let u=nd.get(i);if(u!==void 0)return this.pos=n+1,this.column=s+1,this.makeToken(u,i,n,r,s);if(i==="{"){let c=this.scanFdVariable(n);return c!==null?(this.pos=c.end,this.column=s+(c.end-n),{type:w.FD_VARIABLE,value:c.varname,start:n,end:c.end,line:r,column:s}):a==="}"?(this.pos=n+2,this.column=s+2,{type:w.WORD,value:"{}",start:n,end:n+2,line:r,column:s,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(n)!==null?this.readWordWithBraceExpansion(n,r,s):this.scanLiteralBraceWord(n)!==null?this.readWordWithBraceExpansion(n,r,s):a!==void 0&&a!==" "&&a!==" "&&a!==`
28
31
  `?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(w.LBRACE,"{",n,r,s))}return i==="}"?this.isWordCharFollowing(n+1)?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(w.RBRACE,"}",n,r,s)):i==="!"?a==="="?(this.pos=n+2,this.column=s+2,this.makeToken(w.WORD,"!=",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(w.BANG,"!",n,r,s)):this.readWord(n,r,s)}looksLikeNestedSubshells(t){let n=this.input,r=n.length,s=t;for(;s<r&&(n[s]===" "||n[s]===" ");)s++;if(s>=r)return!1;let i=n[s];if(i==="(")return this.looksLikeNestedSubshells(s+1);let 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 u=l;for(;u<r&&(n[u]===" "||n[u]===" ");)u++;if(u>=r)return!1;let c=n[u];if(c==="="&&n[u+1]!=="="||c===`
29
32
  `||l===u&&/[+\-*/%<>&|^!~?:]/.test(c)&&c!=="-"||c===")"&&n[u+1]===")")return!1;if(u>l&&(c==="-"||c==='"'||c==="'"||c==="$"||/[a-zA-Z_/.]/.test(c))){let f=u;for(;f<r&&n[f]!==`
30
33
  `;){if(n[f]===")")return!0;f++}return!1}if(c===")"){let f=u+1;for(;f<r&&(n[f]===" "||n[f]===" ");)f++;if(n[f]==="|"&&n[f+1]==="|"||n[f]==="&"&&n[f+1]==="&"||n[f]===";"||n[f]==="|"&&n[f+1]!=="|")return!0}return!1}makeToken(t,n,r,s,i){return{type:t,value:n,start:r,end:this.pos,line:s,column:i}}readComment(t,n,r){let s=this.input,i=s.length,a=this.pos;for(;a<i&&s[a]!==`
31
- `;)a++;let o=s.slice(t,a);return this.pos=a,this.column=r+(a-t),{type:w.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 y=s[a];if(y===" "||y===" "||y===`
32
- `||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"||y==="'"||y==='"'||y==="\\"||y==="$"||y==="`"||y==="{"||y==="}"||y==="~"||y==="*"||y==="?"||y==="[")break;a++}if(a>o){let y=s[a];if(!(y==="("&&a>o&&"@*+?!".includes(s[a-1]))){if(a>=i||y===" "||y===" "||y===`
33
- `||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"){let S=s.slice(o,a);this.pos=a,this.column=r+(a-o);let v=js.get(S);if(v!==void 0)return{type:v,value:S,start:t,end:a,line:n,column:r};let $=ko(S);return $>0&&xo(S.slice(0,$))?{type:w.ASSIGNMENT_WORD,value:S,start:t,end:a,line:n,column:r}:/^[0-9]+$/.test(S)?{type:w.NUMBER,value:S,start:t,end:a,line:n,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(S)?{type:w.NAME,value:S,start:t,end:a,line:n,column:r,quoted:!1,singleQuoted:!1}:{type:w.WORD,value:S,start:t,end:a,line:n,column:r,quoted:!1,singleQuoted:!1}}}}a=this.pos;let l=this.column,u=this.line,c="",f=!1,d=!1,p=!1,h=!1,m=s[a]==='"'||s[a]==="'",E=!1,b=0;for(;a<i;){let y=s[a];if(!p&&!h){if(y==="("&&c.length>0&&"@*+?!".includes(c[c.length-1])){let S=this.scanExtglobPattern(a);if(S!==null){c+=S.content,a=S.end,l+=S.content.length;continue}}if(y==="["&&b===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){let S=a+1<i?s[a+1]:"";if(S==="^"||S==="!"){c+=y,a++,l++;continue}b=1,c+=y,a++,l++;continue}}else if(y==="["&&b>0){c.length>0&&c[c.length-1]!=="\\"&&b++,c+=y,a++,l++;continue}else if(y==="]"&&b>0){c.length>0&&c[c.length-1]!=="\\"&&b--,c+=y,a++,l++;continue}if(b>0){if(y===`
34
- `)break;c+=y,a++,l++;continue}if(y===" "||y===" "||y===`
35
- `||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">")break}if(y==="$"&&a+1<i&&s[a+1]==="'"&&!p&&!h){for(c+="$'",a+=2,l+=2;a<i&&s[a]!=="'";)s[a]==="\\"&&a+1<i?(c+=s[a]+s[a+1],a+=2,l+=2):(c+=s[a],a++,l++);a<i&&(c+="'",a++,l++);continue}if(y==="$"&&a+1<i&&s[a+1]==='"'&&!p&&!h){a++,l++,h=!0,f=!0,c===""&&(m=!0),a++,l++;continue}if(y==="'"&&!h){if(p)if(p=!1,!m||E)c+=y;else{let S=a+1<i?s[a+1]:"";S&&!Po(S)&&S!=="'"&&(S==='"'?(E=!0,c+=y,d=!1,f=!1):(E=!0,c+=y))}else p=!0,m&&!E?(d=!0,f=!0):c+=y;a++,l++;continue}if(y==='"'&&!p){if(h)if(h=!1,!m||E)c+=y;else{let S=a+1<i?s[a+1]:"";S&&!Po(S)&&S!=='"'&&(S==="'"?(E=!0,c+=y,d=!1,f=!1):(E=!0,c+=y))}else h=!0,m&&!E?f=!0:c+=y;a++,l++;continue}if(y==="\\"&&!p&&a+1<i){let S=s[a+1];if(S===`
36
- `){a+=2,u++,l=1;continue}if(h){if(S==='"'||S==="\\"||S==="$"||S==="`"||S===`
37
- `){if(S===`
38
- `){a+=2,l=1,u++;continue}c+=y+S,a+=2,l+=2;continue}}else{c+=y+S,a+=2,l+=2;continue}}if(y==="$"&&a+1<i&&s[a+1]==="("&&!p){c+=y,a++,l++,c+=s[a],a++,l++;let S=1,v=!1,$=!1,A=0,C=!1,N="",x=[],P=s[a]==="("&&!this.dollarDparenIsSubshell(a),R=P?1:0;for(;S>0&&a<i;){let B=s[a];if(c+=B,v)B==="'"&&(v=!1);else if($)B==="\\"&&a+1<i?(c+=s[a+1],a++,l++):B==='"'&&($=!1);else{if(B==="("&&s[a+1]==="("?R++:B===")"&&s[a+1]===")"&&R>0&&R--,R===0&&B==="<"&&s[a+1]==="<"&&s[a+2]!=="<"){let q=a+2,D=!1;for(s[q]==="-"&&(D=!0,q++);s[q]===" "||s[q]===" ";)q++;let{delim:W,endPos:V,unclosedQuote:O,unclosedSubstitution:_}=kr(s,q);if(O)throw new Qe(`unexpected EOF while looking for matching \`${O}'`,u,l);if(_)throw new Qe("unexpected EOF while looking for matching `)'",u,l);if(W.length>0){c+=s.slice(a+1,V),l+=V-a,x.push({delim:W,stripTabs:D}),a=V;continue}}if(B===`
39
- `&&x.length>0){u++,l=0;let q=a+1;for(let{delim:D,stripTabs:W}of x)for(;!(q>=i);){let V=s.indexOf(`
40
- `,q);V===-1&&(V=i);let O=s.slice(q,V),_=W?O.replace(/^\t+/,""):O;c+=s.slice(q,Math.min(V+1,i)),V<i&&u++;let M=V>=i;if(q=V+1,_===D||M)break}x.length=0,l=0,a=Math.min(q,i);continue}if(B==="'")v=!0,N="";else if(B==='"')$=!0,N="";else if(B==="\\"&&a+1<i)c+=s[a+1],a++,l++,N="";else if(B==="$"&&a+1<i&&s[a+1]==="{"){a++,l++,c+=s[a],a++,l++;let q=1,D=!1,W=!1;for(;q>0&&a<i;){let V=s[a];if(V==="\\"&&a+1<i&&!D){c+=V,a++,l++,c+=s[a],a++,l++;continue}c+=V,D?V==="'"&&(D=!1):W?V==='"'&&(W=!1):V==="'"?D=!0:V==='"'?W=!0:V==="{"?q++:V==="}"&&q--,V===`
41
- `?(u++,l=0):l++,a++}N="";continue}else if(B==="#"&&!P&&(N===""||/\s/.test(s[a-1]||""))){for(;a+1<i&&s[a+1]!==`
42
- `;)a++,l++,c+=s[a];N=""}else/[a-zA-Z_]/.test(B)?N+=B:(N==="case"?(A++,C=!1):N==="in"&&A>0?C=!0:N==="esac"&&A>0&&(A--,C=!1),N="",B==="("?a>0&&s[a-1]==="$"?S++:C||S++:B===")"?C?C=!1:S--:B===";"&&A>0&&(a+1<i&&s[a+1]===";"||a+1<i&&s[a+1]==="&")&&(C=!0))}B===`
43
- `&&(u++,l=0,N=""),a++,l++}continue}if(y==="$"&&a+1<i&&s[a+1]==="["&&!p){c+=y,a++,l++,c+=s[a],a++,l++;let S=1;for(;S>0&&a<i;){let v=s[a];c+=v,v==="["?S++:v==="]"?S--:v===`
44
- `&&(u++,l=0),a++,l++}continue}if(y==="$"&&a+1<i&&s[a+1]==="{"&&!p){c+=y,a++,l++,c+=s[a],a++,l++;let S=1,v=!1,$=!1,A=u,C=l,N=u,x=l;for(;S>0&&a<i;){let P=s[a];if(P==="\\"&&a+1<i&&s[a+1]===`
45
- `){a+=2,u++,l=1;continue}if(P==="\\"&&a+1<i&&!v){c+=P,a++,l++,c+=s[a],a++,l++;continue}c+=P,v?P==="'"&&(v=!1):$?P==='"'&&($=!1):P==="'"?(v=!0,A=u,C=l):P==='"'?($=!0,N=u,x=l):P==="{"?S++:P==="}"&&S--,P===`
46
- `&&(u++,l=0),a++,l++}if(v)throw new Qe("unexpected EOF while looking for matching `''",A,C);if($)throw new Qe("unexpected EOF while looking for matching `\"'",N,x);continue}if(y==="$"&&a+1<i&&!p){let S=s[a+1];if(S==="#"||S==="?"||S==="$"||S==="!"||S==="@"||S==="*"||S==="-"||S>="0"&&S<="9"){c+=y+S,a+=2,l+=2;continue}}if(y==="`"&&!p){for(c+=y,a++,l++;a<i&&s[a]!=="`";){let S=s[a];c+=S,S==="\\"&&a+1<i&&(c+=s[a+1],a++,l++),S===`
47
- `&&(u++,l=0),a++,l++}a<i&&(c+=s[a],a++,l++);continue}c+=y,a++,y===`
48
- `?(u++,l=1):l++}if(this.pos=a,this.column=l,this.line=u,E&&m&&(c=s[t]+c,f=!1,d=!1),p||h){let y=p?"'":'"';throw new Qe(`unexpected EOF while looking for matching \`${y}'`,n,r)}if(!m&&c.length>=2){if(c[0]==="'"&&c[c.length-1]==="'"){let y=c.slice(1,-1);!y.includes("'")&&!y.includes('"')&&(c=y,f=!0,d=!0)}else if(c[0]==='"'&&c[c.length-1]==='"'){let y=c.slice(1,-1),S=!1;for(let v=0;v<y.length;v++){if(y[v]==='"'){S=!0;break}y[v]==="\\"&&v+1<y.length&&v++}S||(c=y,f=!0,d=!1)}}if(c==="")return{type:w.WORD,value:"",start:t,end:a,line:n,column:r,quoted:f,singleQuoted:d};let g=js.get(c);if(!f&&g!==void 0)return{type:g,value:c,start:t,end:a,line:n,column:r};if(!m){let y=ko(c);if(y>0&&xo(c.slice(0,y)))return{type:w.ASSIGNMENT_WORD,value:c,start:t,end:a,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(c)?{type:w.NUMBER,value:c,start:t,end:a,line:n,column:r}:Hf(c)?{type:w.NAME,value:c,start:t,end:a,line:n,column:r,quoted:f,singleQuoted:d}:{type:w.WORD,value:c,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="",a=!1;for(;this.pos<this.input.length;){let o="",l="",u="";for(;;){for(o="";this.pos<this.input.length&&this.input[this.pos]!==`
34
+ `;)a++;let o=s.slice(t,a);return this.pos=a,this.column=r+(a-t),{type:w.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 g=s[a];if(g===" "||g===" "||g===`
35
+ `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">"||g==="'"||g==='"'||g==="\\"||g==="$"||g==="`"||g==="{"||g==="}"||g==="~"||g==="*"||g==="?"||g==="[")break;a++}if(a>o){let g=s[a];if(!(g==="("&&a>o&&"@*+?!".includes(s[a-1]))){if(a>=i||g===" "||g===" "||g===`
36
+ `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">"){let b=s.slice(o,a);this.pos=a,this.column=r+(a-o);let v=Ys.get(b);if(v!==void 0)return{type:v,value:b,start:t,end:a,line:n,column:r};let $=Fo(b);return $>0&&Mo(b.slice(0,$))?{type:w.ASSIGNMENT_WORD,value:b,start:t,end:a,line:n,column:r}:/^[0-9]+$/.test(b)?{type:w.NUMBER,value:b,start:t,end:a,line:n,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(b)?{type:w.NAME,value:b,start:t,end:a,line:n,column:r,quoted:!1,singleQuoted:!1}:{type:w.WORD,value:b,start:t,end:a,line:n,column:r,quoted:!1,singleQuoted:!1}}}}a=this.pos;let l=this.column,u=this.line,c="",f=!1,d=!1,p=!1,h=!1,m=s[a]==='"'||s[a]==="'",E=!1,S=0;for(;a<i;){let g=s[a];if(!p&&!h){if(g==="("&&c.length>0&&"@*+?!".includes(c[c.length-1])){let b=this.scanExtglobPattern(a);if(b!==null){c+=b.content,a=b.end,l+=b.content.length;continue}}if(g==="["&&S===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){let b=a+1<i?s[a+1]:"";if(b==="^"||b==="!"){c+=g,a++,l++;continue}S=1,c+=g,a++,l++;continue}}else if(g==="["&&S>0){c.length>0&&c[c.length-1]!=="\\"&&S++,c+=g,a++,l++;continue}else if(g==="]"&&S>0){c.length>0&&c[c.length-1]!=="\\"&&S--,c+=g,a++,l++;continue}if(S>0){if(g===`
37
+ `)break;c+=g,a++,l++;continue}if(g===" "||g===" "||g===`
38
+ `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">")break}if(g==="$"&&a+1<i&&s[a+1]==="'"&&!p&&!h){for(c+="$'",a+=2,l+=2;a<i&&s[a]!=="'";)s[a]==="\\"&&a+1<i?(c+=s[a]+s[a+1],a+=2,l+=2):(c+=s[a],a++,l++);a<i&&(c+="'",a++,l++);continue}if(g==="$"&&a+1<i&&s[a+1]==='"'&&!p&&!h){a++,l++,h=!0,f=!0,c===""&&(m=!0),a++,l++;continue}if(g==="'"&&!h){if(p)if(p=!1,!m||E)c+=g;else{let b=a+1<i?s[a+1]:"";b&&!Bo(b)&&b!=="'"&&(b==='"'?(E=!0,c+=g,d=!1,f=!1):(E=!0,c+=g))}else p=!0,m&&!E?(d=!0,f=!0):c+=g;a++,l++;continue}if(g==='"'&&!p){if(h)if(h=!1,!m||E)c+=g;else{let b=a+1<i?s[a+1]:"";b&&!Bo(b)&&b!=='"'&&(b==="'"?(E=!0,c+=g,d=!1,f=!1):(E=!0,c+=g))}else h=!0,m&&!E?f=!0:c+=g;a++,l++;continue}if(g==="\\"&&!p&&a+1<i){let b=s[a+1];if(b===`
39
+ `){a+=2,u++,l=1;continue}if(h){if(b==='"'||b==="\\"||b==="$"||b==="`"||b===`
40
+ `){if(b===`
41
+ `){a+=2,l=1,u++;continue}c+=g+b,a+=2,l+=2;continue}}else{c+=g+b,a+=2,l+=2;continue}}if(g==="$"&&a+1<i&&s[a+1]==="("&&!p){c+=g,a++,l++,c+=s[a],a++,l++;let b=1,v=!1,$=!1,A=0,k=!1,N="",x=[],C=s[a]==="("&&!this.dollarDparenIsSubshell(a),D=C?1:0;for(;b>0&&a<i;){let B=s[a];if(c+=B,v)B==="'"&&(v=!1);else if($)B==="\\"&&a+1<i?(c+=s[a+1],a++,l++):B==='"'&&($=!1);else{if(B==="("&&s[a+1]==="("?D++:B===")"&&s[a+1]===")"&&D>0&&D--,D===0&&B==="<"&&s[a+1]==="<"&&s[a+2]!=="<"){let H=a+2,R=!1;for(s[H]==="-"&&(R=!0,H++);s[H]===" "||s[H]===" ";)H++;let{delim:W,endPos:V,unclosedQuote:I,unclosedSubstitution:O}=Or(s,H);if(I)throw new Ke(`unexpected EOF while looking for matching \`${I}'`,u,l);if(O)throw new Ke("unexpected EOF while looking for matching `)'",u,l);if(W.length>0){c+=s.slice(a+1,V),l+=V-a,x.push({delim:W,stripTabs:R}),a=V;continue}}if(B===`
42
+ `&&x.length>0){u++,l=0;let H=a+1;for(let{delim:R,stripTabs:W}of x)for(;!(H>=i);){let V=s.indexOf(`
43
+ `,H);V===-1&&(V=i);let I=s.slice(H,V),O=W?I.replace(/^\t+/,""):I;c+=s.slice(H,Math.min(V+1,i)),V<i&&u++;let F=V>=i;if(H=V+1,O===R||F)break}x.length=0,l=0,a=Math.min(H,i);continue}if(B==="'")v=!0,N="";else if(B==='"')$=!0,N="";else if(B==="\\"&&a+1<i)c+=s[a+1],a++,l++,N="";else if(B==="$"&&a+1<i&&s[a+1]==="{"){a++,l++,c+=s[a],a++,l++;let H=1,R=!1,W=!1;for(;H>0&&a<i;){let V=s[a];if(V==="\\"&&a+1<i&&!R){c+=V,a++,l++,c+=s[a],a++,l++;continue}c+=V,R?V==="'"&&(R=!1):W?V==='"'&&(W=!1):V==="'"?R=!0:V==='"'?W=!0:V==="{"?H++:V==="}"&&H--,V===`
44
+ `?(u++,l=0):l++,a++}N="";continue}else if(B==="#"&&!C&&(N===""||/\s/.test(s[a-1]||""))){for(;a+1<i&&s[a+1]!==`
45
+ `;)a++,l++,c+=s[a];N=""}else/[a-zA-Z_]/.test(B)?N+=B:(N==="case"?(A++,k=!1):N==="in"&&A>0?k=!0:N==="esac"&&A>0&&(A--,k=!1),N="",B==="("?a>0&&s[a-1]==="$"?b++:k||b++:B===")"?k?k=!1:b--:B===";"&&A>0&&(a+1<i&&s[a+1]===";"||a+1<i&&s[a+1]==="&")&&(k=!0))}B===`
46
+ `&&(u++,l=0,N=""),a++,l++}continue}if(g==="$"&&a+1<i&&s[a+1]==="["&&!p){c+=g,a++,l++,c+=s[a],a++,l++;let b=1;for(;b>0&&a<i;){let v=s[a];c+=v,v==="["?b++:v==="]"?b--:v===`
47
+ `&&(u++,l=0),a++,l++}continue}if(g==="$"&&a+1<i&&s[a+1]==="{"&&!p){c+=g,a++,l++,c+=s[a],a++,l++;let b=1,v=!1,$=!1,A=u,k=l,N=u,x=l;for(;b>0&&a<i;){let C=s[a];if(C==="\\"&&a+1<i&&s[a+1]===`
48
+ `){a+=2,u++,l=1;continue}if(C==="\\"&&a+1<i&&!v){c+=C,a++,l++,c+=s[a],a++,l++;continue}c+=C,v?C==="'"&&(v=!1):$?C==='"'&&($=!1):C==="'"?(v=!0,A=u,k=l):C==='"'?($=!0,N=u,x=l):C==="{"?b++:C==="}"&&b--,C===`
49
+ `&&(u++,l=0),a++,l++}if(v)throw new Ke("unexpected EOF while looking for matching `''",A,k);if($)throw new Ke("unexpected EOF while looking for matching `\"'",N,x);continue}if(g==="$"&&a+1<i&&!p){let b=s[a+1];if(b==="#"||b==="?"||b==="$"||b==="!"||b==="@"||b==="*"||b==="-"||b>="0"&&b<="9"){c+=g+b,a+=2,l+=2;continue}}if(g==="`"&&!p){for(c+=g,a++,l++;a<i&&s[a]!=="`";){let b=s[a];c+=b,b==="\\"&&a+1<i&&(c+=s[a+1],a++,l++),b===`
50
+ `&&(u++,l=0),a++,l++}a<i&&(c+=s[a],a++,l++);continue}c+=g,a++,g===`
51
+ `?(u++,l=1):l++}if(this.pos=a,this.column=l,this.line=u,E&&m&&(c=s[t]+c,f=!1,d=!1),p||h){let g=p?"'":'"';throw new Ke(`unexpected EOF while looking for matching \`${g}'`,n,r)}if(!m&&c.length>=2){if(c[0]==="'"&&c[c.length-1]==="'"){let g=c.slice(1,-1);!g.includes("'")&&!g.includes('"')&&(c=g,f=!0,d=!0)}else if(c[0]==='"'&&c[c.length-1]==='"'){let g=c.slice(1,-1),b=!1;for(let v=0;v<g.length;v++){if(g[v]==='"'){b=!0;break}g[v]==="\\"&&v+1<g.length&&v++}b||(c=g,f=!0,d=!1)}}if(c==="")return{type:w.WORD,value:"",start:t,end:a,line:n,column:r,quoted:f,singleQuoted:d};let y=Ys.get(c);if(!f&&y!==void 0)return{type:y,value:c,start:t,end:a,line:n,column:r};if(!m){let g=Fo(c);if(g>0&&Mo(c.slice(0,g)))return{type:w.ASSIGNMENT_WORD,value:c,start:t,end:a,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(c)?{type:w.NUMBER,value:c,start:t,end:a,line:n,column:r}:rd(c)?{type:w.NAME,value:c,start:t,end:a,line:n,column:r,quoted:f,singleQuoted:d}:{type:w.WORD,value:c,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="",a=!1;for(;this.pos<this.input.length;){let o="",l="",u="";for(;;){for(o="";this.pos<this.input.length&&this.input[this.pos]!==`
49
52
  `;)o+=this.input[this.pos],this.pos++,this.column++;let f=0;for(let d=o.length-1;o[d]==="\\";d-=1)f+=1;if(u+=o,t.quoted||f%2===0||this.pos+1>=this.input.length)break;u=u.slice(0,-1),l+=`${o}
50
53
  `,this.pos++,this.line++,this.column=1}if((t.stripTabs?u.replace(/^\t+/,""):u)===t.delimiter){a=!0,this.pos<this.input.length&&this.input[this.pos]===`
51
54
  `&&(this.pos++,this.line++,this.column=1);break}if(i+=l,i+=o,this.pos<this.input.length&&this.input[this.pos]===`
52
55
  `?(i+=`
53
56
  `,this.pos++,this.line++,this.column=1):o.length>0&&(i+=`
54
- `),i.length>this.maxHeredocSize)throw new Qe(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,s)}this.tokens.push({type:w.HEREDOC_CONTENT,value:i,start:n,end:this.pos,line:r,column:s,heredocTerminated:a})}}readHeredocDelimiterToken(t,n,r,s){let i=this.input,{delim:a,endPos:o,quoted:l,unclosedQuote:u,unclosedSubstitution:c}=kr(i,t);if(u)throw new Qe(`unexpected EOF while looking for matching \`${u}'`,n,r);if(c)throw new Qe("unexpected EOF while looking for matching `)'",n,r);if(o===t)throw new Qe("Expected here-document delimiter",n,r);let f=n,d=r;for(let p=t;p<o;p++)i[p]===`
57
+ `),i.length>this.maxHeredocSize)throw new Ke(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,s)}this.tokens.push({type:w.HEREDOC_CONTENT,value:i,start:n,end:this.pos,line:r,column:s,heredocTerminated:a})}}readHeredocDelimiterToken(t,n,r,s){let i=this.input,{delim:a,endPos:o,quoted:l,unclosedQuote:u,unclosedSubstitution:c}=Or(i,t);if(u)throw new Ke(`unexpected EOF while looking for matching \`${u}'`,n,r);if(c)throw new Ke("unexpected EOF while looking for matching `)'",n,r);if(o===t)throw new Ke("Expected here-document delimiter",n,r);let f=n,d=r;for(let p=t;p<o;p++)i[p]===`
55
58
  `?(f+=1,d=1):d+=1;return this.pos=o,this.line=f,this.column=d,this.pendingHeredocs.push({delimiter:a,stripTabs:s,quoted:l}),{type:w.WORD,value:i.slice(t,o),start:t,end:o,line:n,column:r,quoted:l,heredocDelimiter:a}}isWordCharFollowing(t){if(t>=this.input.length)return!1;let n=this.input[t];return!(n===" "||n===" "||n===`
56
59
  `||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 u=s[a];if(u===" "||u===" "||u===`
57
60
  `||u===";"||u==="&"||u==="|"||u==="("||u===")"||u==="<"||u===">")break;if(u==="{"){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(u==="}"){a++,o++;continue}if(u==="$"&&a+1<i&&s[a+1]==="("){a++,o++,a++,o++;let c=1;for(;c>0&&a<i;)s[a]==="("?c++:s[a]===")"&&c--,a++,o++;continue}if(u==="$"&&a+1<i&&s[a+1]==="{"){a++,o++,a++,o++;let c=1;for(;c>0&&a<i;)s[a]==="{"?c++:s[a]==="}"&&c--,a++,o++;continue}if(u==="`"){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:w.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===`
@@ -62,213 +65,215 @@ Gid: ${s} ${s} ${s} ${s}
62
65
  `&&(l=!0),s++;continue}if(u==="'"){a=!0,s++;continue}if(u==='"'){o=!0,s++;continue}if(u==="\\"){s+=2;continue}if(u===`
63
66
  `&&(l=!0),u==="("){i++,s++;continue}if(u===")"){if(i--,i===1){let c=s+1;if(c<r&&n[c]===")")return!1;let f=c,d=!1;for(;f<r&&(n[f]===" "||n[f]===" "||n[f]===`
64
67
  `);)d=!0,f++;if(d&&f<r&&n[f]===")"||l)return!0}if(i===0)return!1;s++;continue}s++}return!1}dparenClosesWithSpacedParens(t){let n=this.input,r=n.length,s=t,i=2,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 u=s+1;if(u<r&&n[u]===")")return!1;let c=u,f=!1;for(;c<r&&(n[c]===" "||n[c]===" "||n[c]===`
65
- `);)f=!0,c++;if(f&&c<r&&n[c]===")")return!0}if(i===0)return!1;s++;continue}if(i===1&&(l==="|"&&s+1<r&&n[s+1]==="|"||l==="&"&&s+1<r&&n[s+1]==="&"||l==="|"&&s+1<r&&n[s+1]!=="|"))return!0;s++}return!1}};var Zs=1e6,Hn=1e5,Qf=1e6,Co=200,Ce;(function(e){e[e.Default=0]="Default",e[e.Assignment=1]="Assignment",e[e.NoBraceExpansion=2]="NoBraceExpansion",e[e.Regex=4]="Regex"})(Ce||(Ce={}));var No=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS,w.AND_GREAT,w.AND_DGREAT]),Ro=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS]),Do=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS,w.AND_GREAT,w.AND_DGREAT]),$e=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"}},Cr=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>Qf)throw new $e("Maximum parse iterations exceeded (possible infinite loop)",t,n)}chargeTokens(t,n=1,r=1){if(this.tokens+=t,this.tokens>Hn)throw new $e(`Too many tokens: cumulative count exceeds limit of ${Hn}`,n,r)}enter(t,n){if(this.depth++,this.depth>Co)throw this.depth--,new $e(`Maximum parser nesting depth exceeded (${Co})`,t,n);let r=!0;return()=>{r&&(r=!1,this.depth--)}}};function he(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
66
- `){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var Nr=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function Qn(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 Io(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 Oo(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+=`
67
- `;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 _o(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 Kf(e){let t="",n=0;for(;n<e.length;)if(e[n]==='"'){for(n++;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);n<e.length&&n++}else t+=e[n],n++;return t}function te(e,t){let n=Kf(t),{expr:r,pos:s}=Pn(e,n,0),i=he(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 ze(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function qe(e,t){return he(e,t)>=e.length}function Pn(e,t,n){return Xf(e,t,n)}function an(e,t,n){return e.withDepth(()=>Pn(e,t,n))}function Xf(e,t,n){let{expr:r,pos:s}=Kn(e,t,n);for(s=he(t,s);t[s]===",";){if(s++,qe(t,s))return ze(",",s);let{expr:a,pos:o}=Kn(e,t,s);r={type:"ArithBinary",operator:",",left:r,right:a},s=he(t,o)}return{expr:r,pos:s}}function Kn(e,t,n){let{expr:r,pos:s}=Yf(e,t,n);if(s=he(t,s),t[s]==="?"){s++;let{expr:i,pos:a}=an(e,t,s);if(s=he(t,a),t[s]===":"){s++;let{expr:o,pos:l}=an(e,t,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:o},pos:l}}}return{expr:r,pos:s}}function Yf(e,t,n){let{expr:r,pos:s}=Lo(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="||";){if(s+=2,qe(t,s))return ze("||",s);let{expr:a,pos:o}=Lo(e,t,s);r={type:"ArithBinary",operator:"||",left:r,right:a},s=o}return{expr:r,pos:s}}function Lo(e,t,n){let{expr:r,pos:s}=To(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="&&";){if(s+=2,qe(t,s))return ze("&&",s);let{expr:a,pos:o}=To(e,t,s);r={type:"ArithBinary",operator:"&&",left:r,right:a},s=o}return{expr:r,pos:s}}function To(e,t,n){let{expr:r,pos:s}=Mo(e,t,n);for(;s=he(t,s),t[s]==="|"&&t[s+1]!=="|";){if(s++,qe(t,s))return ze("|",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}=Fo(e,t,n);for(;s=he(t,s),t[s]==="^";){if(s++,qe(t,s))return ze("^",s);let{expr:a,pos:o}=Fo(e,t,s);r={type:"ArithBinary",operator:"^",left:r,right:a},s=o}return{expr:r,pos:s}}function Fo(e,t,n){let{expr:r,pos:s}=Bo(e,t,n);for(;s=he(t,s),t[s]==="&"&&t[s+1]!=="&";){if(s++,qe(t,s))return ze("&",s);let{expr:a,pos:o}=Bo(e,t,s);r={type:"ArithBinary",operator:"&",left:r,right:a},s=o}return{expr:r,pos:s}}function Bo(e,t,n){let{expr:r,pos:s}=Wo(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="=="||t.slice(s,s+2)==="!=";){let i=t.slice(s,s+2);if(s+=2,qe(t,s))return ze(i,s);let{expr:a,pos:o}=Wo(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}return{expr:r,pos:s}}function Wo(e,t,n){let{expr:r,pos:s}=Hs(e,t,n);for(;;)if(s=he(t,s),t.slice(s,s+2)==="<="||t.slice(s,s+2)===">="){let i=t.slice(s,s+2);if(s+=2,qe(t,s))return ze(i,s);let{expr:a,pos:o}=Hs(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++,qe(t,s))return ze(i,s);let{expr:a,pos:o}=Hs(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}else break;return{expr:r,pos:s}}function Hs(e,t,n){let{expr:r,pos:s}=Vo(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="<<"||t.slice(s,s+2)===">>";){let i=t.slice(s,s+2);if(s+=2,qe(t,s))return ze(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}=zo(e,t,n);for(;s=he(t,s),(t[s]==="+"||t[s]==="-")&&t[s+1]!==t[s];){let i=t[s];if(s++,qe(t,s))return ze(i,s);let{expr:a,pos:o}=zo(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}return{expr:r,pos:s}}function zo(e,t,n){let{expr:r,pos:s}=Rr(e,t,n);for(;;)if(s=he(t,s),t[s]==="*"&&t[s+1]!=="*"){if(s++,qe(t,s))return ze("*",s);let{expr:a,pos:o}=Rr(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++,qe(t,s))return ze(i,s);let{expr:a,pos:o}=Rr(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}else break;return{expr:r,pos:s}}function Rr(e,t,n){let{expr:r,pos:s}=Qs(e,t,n),i=he(t,s);if(t.slice(i,i+2)==="**"){if(i+=2,qe(t,i))return ze("**",i);let{expr:o,pos:l}=e.withDepth(()=>Rr(e,t,i));return{expr:{type:"ArithBinary",operator:"**",left:r,right:o},pos:l}}return{expr:r,pos:s}}function Qs(e,t,n){let r=he(t,n);if(t.slice(r,r+2)==="++"||t.slice(r,r+2)==="--"){let s=t.slice(r,r+2);r+=2;let{expr:i,pos:a}=e.withDepth(()=>Qs(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(()=>Qs(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:a}}return ed(e,t,r)}function Jf(e,t){let n=e[t];return n==="$"||n==="`"}function ed(e,t,n){let{expr:r,pos:s}=qo(e,t,n,!1),i=[r];for(;Jf(t,s);){let{expr:o,pos:l}=qo(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}=an(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=he(t,s),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let o of Nr)if(t.slice(s,s+o.length)===o&&t.slice(s,s+o.length+1)!=="=="){s+=o.length;let{expr:l,pos:u}=e.withDepth(()=>Kn(e,t,s));return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:o,target:r.nameExpr,subscript:r.subscript,value:l},pos:u}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:o,target:r,value:l},pos:u}:{expr:{type:"ArithAssignment",operator:o,variable:r.name,value:l},pos:u}}}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 qo(e,t,n,r=!1){let s=he(t,n),i=Io(an,e,t,s);if(i)return i;let a=Oo(t,s);if(a)return a;let o=_o(t,s);if(o)return o;if(t.slice(s,s+2)==="$("&&t[s+2]!=="("){s+=2;let u=1,c=s;for(;s<t.length&&u>0;)t[s]==="("?u++:t[s]===")"&&u--,u>0&&s++;let f=t.slice(c,s);return s++,{expr:{type:"ArithCommandSubst",command:f},pos:s}}if(t[s]==="`"){s++;let u=s;for(;s<t.length&&t[s]!=="`";)s++;let c=t.slice(u,s);return t[s]==="`"&&s++,{expr:{type:"ArithCommandSubst",command:c},pos:s}}if(t[s]==="("){s++;let{expr:u,pos:c}=an(e,t,s);return s=he(t,c),t[s]===")"&&s++,{expr:{type:"ArithGroup",expression:u},pos:s}}if(t[s]==="'"){s++;let u="";for(;s<t.length&&t[s]!=="'";)u+=t[s],s++;t[s]==="'"&&s++;let c=Number.parseInt(u,10);return{expr:{type:"ArithSingleQuote",content:u,value:Number.isNaN(c)?0:c},pos:s}}if(t[s]==='"'){s++;let u="";for(;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?(u+=t[s+1],s+=2):(u+=t[s],s++);t[s]==='"'&&s++;let c=u.trim();if(!c)return{expr:{type:"ArithNumber",value:0},pos:s};let{expr:f}=an(e,c,0);return{expr:f,pos:s}}if(/[0-9]/.test(t[s])){let u="",c=!1,f=!1;for(;s<t.length;){let p=t[s];if(c)if(/[0-9a-zA-Z@_]/.test(p))u+=p,s++;else break;else if(p==="#")c=!0,u+=p,s++;else if(u==="0"&&(p==="x"||p==="X")&&s+1<t.length&&/[0-9a-fA-F]/.test(t[s+1]))f=!0,u+=p,s++;else if(f&&/[0-9a-fA-F]/.test(p))u+=p,s++;else if(!f&&/[0-9]/.test(p))u+=p,s++;else break}if(s<t.length&&/[a-zA-Z_]/.test(t[s])){let p=u;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)p+=t[s],s++;return{expr:{type:"ArithSyntaxError",errorToken:p,message:`${p}: value too great for base (error token is "${p}")`},pos:s}}if(t[s]==="."&&/[0-9]/.test(t[s+1]))throw new oe(`${u}.${t[s+1]}...: syntax error: invalid arithmetic operator`);if(t[s]==="["){let p=t.slice(s).trim();return{expr:{type:"ArithNumberSubscript",number:u,errorToken:p},pos:t.length}}return{expr:{type:"ArithNumber",value:Qn(u)},pos:s}}if(t[s]==="$"&&t[s+1]==="{"){let u=s+2,c=1,f=u;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;let d=t.slice(u,f),p=f+1;if(t[p]==="#"){let h=p+1;for(;h<t.length&&/[0-9a-zA-Z@_]/.test(t[h]);)h++;let m=t.slice(p+1,h);return{expr:{type:"ArithDynamicBase",baseExpr:d,value:m},pos:h}}if(/[0-9]/.test(t[p])||t[p]==="x"||t[p]==="X"){let h=p;if(t[p]==="x"||t[p]==="X")for(h++;h<t.length&&/[0-9a-fA-F]/.test(t[h]);)h++;else for(;h<t.length&&/[0-9]/.test(t[h]);)h++;let m=t.slice(p,h);return{expr:{type:"ArithDynamicNumber",prefix:d,suffix:m},pos:h}}return s=p,{expr:{type:"ArithBracedExpansion",content:d},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[0-9]/.test(t[s+1])){s++;let u="";for(;s<t.length&&/[0-9]/.test(t[s]);)u+=t[s],s++;return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:!0},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[*@#?\-!$]/.test(t[s+1])){let u=t[s+1];return s+=2,{expr:{type:"ArithSpecialVar",name:u},pos:s}}let l=!1;if(t[s]==="$"&&s+1<t.length&&/[a-zA-Z_]/.test(t[s+1])&&(l=!0,s++),s<t.length&&/[a-zA-Z_]/.test(t[s])){let u="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)u+=t[s],s++;if(t[s]==="["&&!r){s++;let c;if(t[s]==="'"||t[s]==='"'){let d=t[s];for(s++,c="";s<t.length&&t[s]!==d;)c+=t[s],s++;t[s]===d&&s++,s=he(t,s),t[s]==="]"&&s++}let f;if(c===void 0){let{expr:d,pos:p}=an(e,t,s);f=d,s=p,t[s]==="]"&&s++}if(s=he(t,s),t[s]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:u,index:f},pos:s};if(!r){for(let d of Nr)if(t.slice(s,s+d.length)===d&&t.slice(s,s+d.length+1)!=="=="){s+=d.length;let{expr:p,pos:h}=e.withDepth(()=>Kn(e,t,s));return{expr:{type:"ArithAssignment",operator:d,variable:u,subscript:f,stringKey:c,value:p},pos:h}}}return{expr:{type:"ArithArrayElement",array:u,index:f,stringKey:c},pos:s}}if(s=he(t,s),!r){for(let c of Nr)if(t.slice(s,s+c.length)===c&&t.slice(s,s+c.length+1)!=="=="){s+=c.length;let{expr:f,pos:d}=e.withDepth(()=>Kn(e,t,s));return{expr:{type:"ArithAssignment",operator:c,variable:u,value:f},pos:d}}}return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:l},pos:s}}if(t[s]==="#"){let u=s+1;for(;u<t.length&&t[u]!==`
68
- `;)u++;let c=t.slice(s,u).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:c,message:`${c}: syntax error: invalid arithmetic operator (error token is "${c}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:s}}var Dr=e=>{let t,n="";for(let r=0;r<e.length;r++){let s=e[r];if(s==="\\"&&t==='"'&&r+1<e.length){n+=s+e[r+1],r+=1;continue}if(s==="'"||s==='"'){t===s?t=void 0:t||(t=s),n+=s;continue}if(s==="\\"&&!t&&r+1<e.length){let i=e[r+1];n+=i==="$"||i==="`"?`\\${i}`:i,r+=1;continue}n+=s}return n};function td(e){let t="",n=0;for(;n<e.length;){let r=e[n];if(r<128){t+=String.fromCharCode(r),n++;continue}if((r&224)===192){if(n+1<e.length&&(e[n+1]&192)===128&&r>=194){let s=(r&31)<<6|e[n+1]&63;t+=String.fromCharCode(s),n+=2;continue}t+=String.fromCharCode(r),n++;continue}if((r&240)===224){if(n+2<e.length&&(e[n+1]&192)===128&&(e[n+2]&192)===128){if(r===224&&e[n+1]<160){t+=String.fromCharCode(r),n++;continue}let s=(r&15)<<12|(e[n+1]&63)<<6|e[n+2]&63;if(s>=55296&&s<=57343){t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(s),n+=3;continue}t+=String.fromCharCode(r),n++;continue}if((r&248)===240&&r<=244){if(n+3<e.length&&(e[n+1]&192)===128&&(e[n+2]&192)===128&&(e[n+3]&192)===128){if(r===240&&e[n+1]<144){t+=String.fromCharCode(r),n++;continue}let s=(r&7)<<18|(e[n+1]&63)<<12|(e[n+2]&63)<<6|e[n+3]&63;if(s>1114111){t+=String.fromCharCode(r),n++;continue}t+=String.fromCodePoint(s),n+=4;continue}t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(r),n++}return t}function Go(e,t,n){let r=n+1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;return r}function Ks(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 on(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 Zo(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 Ho(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=nd(t,r);a===-1?(s+=i,r++):(s+=t.slice(r,a+1),r=a+1)}else break}return{pattern:s,endIndex:r}}function nd(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 Qo(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+=`
69
- `,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 u=t.slice(l+2,l+4),c=parseInt(u,16);if(!Number.isNaN(c)&&u.length>0)o.push(c),l+=2+u.length;else break}o.length>0?(r+=td(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 u=parseInt(o,8);r+=String.fromCharCode(u),s=l;break}default:r+=i,s++}else r+=i,s++}return s<t.length&&t[s]==="'"&&s++,{part:T.literal(r),endIndex:s}}function Xs(e,t){let n=t.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:te(e,n)}function jo(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 Ko(e,t,n,r){let s=Ks(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:jo(i).map(c=>e.withDepth(()=>({type:"Word",word:T.word(r(e,c,!1,!1,!1))})))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:jo(i).map(c=>({type:"Word",word:T.word([T.literal(c)])}))},endIndex:s+1}:null}function Ys(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(Ys(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 Xo(e,t){return{[w.LESS]:"<",[w.GREAT]:">",[w.DGREAT]:">>",[w.LESSAND]:"<&",[w.GREATAND]:">&",[w.LESSGREAT]:"<>",[w.CLOBBER]:">|",[w.TLESS]:"<<<",[w.AND_GREAT]:"&>",[w.AND_DGREAT]:"&>>",[w.DLESS]:"<",[w.DLESSDASH]:"<"}[t]||">"}function Xn(e){let t=e.current(),n=t.type;if(n===w.NUMBER){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:Ro.has(r.type)}if(n===w.FD_VARIABLE){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:Do.has(r.type)}return!e.isProcessSubstitutionStart()&&No.has(n)}function Ir(e){let t=null,n;e.check(w.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(w.FD_VARIABLE)&&(n=e.advance().value);let r=e.advance(),s=Xo(e,r.type);if(r.type===w.DLESS||r.type===w.DLESSDASH)return rd(e,t,n,r.type===w.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return T.redirection(s,i,t,n)}function rd(e,t,n,r){e.isWord()||e.error("Expected here-document delimiter");let s=e.advance(),i=s.heredocDelimiter??s.value,a=s.quoted||!1,o=T.redirection(r?"<<-":"<<",T.hereDoc(i,T.word([]),r,a),t,n);return e.addPendingHeredoc(o,i,r,a),o}function ei(e){let t=e.getSourceLine(),n=[],r=null,s=[],i=[];for(;e.check(w.ASSIGNMENT_WORD)||Xn(e);)e.checkIterationLimit(),e.check(w.ASSIGNMENT_WORD)?n.push(sd(e)):i.push(Ir(e));if(e.isWord())r=e.parseWord();else if(n.length>0&&(e.check(w.DBRACK_START)||e.check(w.DPAREN_START))){let o=e.advance();r=T.word([T.literal(o.value)])}for(;(!e.isStatementEnd()||e.check(w.RBRACE))&&!e.check(w.PIPE,w.PIPE_AMP);)if(e.checkIterationLimit(),Xn(e))i.push(Ir(e));else if(e.check(w.ASSIGNMENT_WORD)){let o=e.advance(),l=o.value,u=l.endsWith("="),c=l.endsWith("=(");if((u||c)&&(c||e.check(w.LPAREN))){let f=c?l.slice(0,-2):l.slice(0,-1);c||e.expect(w.LPAREN);let d=Js(e);e.expect(w.RPAREN);let p=d.map(m=>Ys(e,m)),h=`${f}=(${p.join(" ")})`;s.push(e.parseWordFromString(h,!1,!1,!0))}else{let f=e.parseWordFromString(l,o.quoted,o.singleQuoted,!0);s.push(e.parseAdjacentWordParts(f.parts,o.end,Ce.Assignment))}}else if(e.isWord())s.push(e.parseWord());else if(e.check(w.RBRACE)){let o=e.advance();s.push(e.parseWordFromString(o.value,!1,!1))}else if(e.check(w.LBRACE)){let o=e.advance();s.push(e.parseWordFromString(o.value,!1,!1))}else if(e.check(w.DBRACK_END)){let o=e.advance();s.push(e.parseWordFromString(o.value,!1,!1))}else if(e.check(w.LPAREN))e.error("syntax error near unexpected token `('");else break;let a=T.simpleCommand(r,s,n,i);return a.line=t,a}function sd(e){let t=e.expect(w.ASSIGNMENT_WORD),n=t.value,r=n.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||e.error(`Invalid assignment: ${n}`);let s=r[0],i,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=Dr(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=Js(e);e.expect(w.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return T.assignment(d,null,o,f)}if(l===""&&e.check(w.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=Js(e);e.expect(w.RPAREN);let p=i!==void 0?`${s}[${i}]`:s;return T.assignment(p,null,o,d)}}let u=l?e.parseWordFromString(l,t.quoted,t.singleQuoted,!0):null;t.end===e.current().start&&e.isProcessSubstitutionStart()&&(u=e.parseAdjacentWordParts(u?.parts??[],t.end,Ce.Assignment));let c=i!==void 0?`${s}[${i}]`:s;return T.assignment(c,u,o,null)}var id=new Set([w.AMP,w.PIPE,w.PIPE_AMP,w.SEMICOLON,w.AND_AND,w.OR_OR,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND]);function Js(e){let t=[];for(e.skipNewlines();!e.check(w.RPAREN,w.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):id.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function ti(e,t){e.expect(w.IF);let n=[],r=e.parseCompoundList();e.expect(w.THEN);let s=e.parseCompoundList();if(s.length===0){let o=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${o}'`)}for(n.push({condition:r,body:s});e.check(w.ELIF);){e.advance();let o=e.parseCompoundList();e.expect(w.THEN);let l=e.parseCompoundList();if(l.length===0){let u=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${u}'`)}n.push({condition:o,body:l})}let i=null;e.check(w.ELSE)&&(e.advance(),i=e.parseCompoundList(),i.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(w.FI);let a=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.ifNode(n,i,a)}function ni(e,t){let n=e.expect(w.FOR);if(e.check(w.DPAREN_START))return od(e,t,e.getSourceLine(n));e.isWord()||e.error("Expected variable name in for loop");let s=e.advance().value,i=null;if(e.skipNewlines(),e.check(w.IN))for(e.advance(),i=[];!e.check(w.SEMICOLON,w.NEWLINE,w.DO,w.EOF)&&e.isWord();)i.push(e.parseWord());e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(w.DO);let a=e.parseCompoundList();e.expect(w.DONE);let o=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.forNode(s,i,a,o)}function od(e,t,n){e.expect(w.DPAREN_START);let r=null,s=null,i=null,a=["","",""],o=0,l=0;for(;!e.check(w.DPAREN_END,w.EOF);){let f=e.advance();if(f.type===w.SEMICOLON&&l===0){if(o++,o>2)break}else f.value==="("&&l++,f.value===")"&&l--,a[o]+=f.value}e.expect(w.DPAREN_END),a[0].trim()&&(r=te(e,a[0].trim())),a[1].trim()&&(s=te(e,a[1].trim())),a[2].trim()&&(i=te(e,a[2].trim())),e.skipNewlines(),e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines();let u;e.check(w.LBRACE)?(e.advance(),u=e.parseCompoundList(),e.expect(w.RBRACE)):(e.expect(w.DO),u=e.parseCompoundList(),e.expect(w.DONE));let c=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:s,update:i,body:u,redirections:c,line:n}}function ri(e,t){e.expect(w.WHILE);let n=e.parseCompoundList();e.expect(w.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(w.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.whileNode(n,r,s)}function si(e,t){e.expect(w.UNTIL);let n=e.parseCompoundList();e.expect(w.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(w.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.untilNode(n,r,s)}function ii(e,t){e.expect(w.CASE),e.isWord()||e.error("Expected word after 'case'");let n=e.parseWord();e.skipNewlines(),e.expect(w.IN),e.skipNewlines();let r=[];for(;!e.check(w.ESAC,w.EOF);){e.checkIterationLimit();let i=e.getPos(),a=ld(e);if(a&&r.push(a),e.skipNewlines(),e.getPos()===i&&!a)break}e.expect(w.ESAC);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.caseNode(n,r,s)}function ld(e){e.check(w.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(w.PIPE));)e.advance();if(t.length===0)return null;e.expect(w.RPAREN),e.skipNewlines();let n=[];for(;!e.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND,w.ESAC,w.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===w.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(w.LPAREN)&&e.peek(1).type===w.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let s=e.getPos(),i=e.parseStatement();if(i&&n.push(i),e.skipSeparators(!1),e.getPos()===s&&!i)break}let r=";;";return e.check(w.DSEMI)?(e.advance(),r=";;"):e.check(w.SEMI_AND)?(e.advance(),r=";&"):e.check(w.SEMI_SEMI_AND)&&(e.advance(),r=";;&"),T.caseItem(t,n,r)}function ai(e,t){e.expect(w.LPAREN);let n=e.parseCompoundList();e.expect(w.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.subshell(n,r)}function oi(e,t){e.expect(w.LBRACE);let n=e.parseCompoundList();e.expect(w.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.group(n,r)}var cd=["-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"],fd=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function Jo(e){return e.isWord()||e.check(w.LBRACE)||e.check(w.RBRACE)||e.check(w.ASSIGNMENT_WORD)}function el(e){if(e.check(w.BANG)&&e.peek(1).type===w.LPAREN){e.advance(),e.advance();let t=1,n="!(";for(;t>0&&!e.check(w.EOF);)if(e.check(w.LPAREN))t++,n+="(",e.advance();else if(e.check(w.RPAREN))t--,t>0&&(n+=")"),e.advance();else if(e.isWord())n+=e.advance().value;else if(e.check(w.PIPE))n+="|",e.advance();else break;return n+=")",e.parseWordFromString(n,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function ui(e){return e.skipNewlines(),dd(e)}function dd(e){let t=tl(e);for(e.skipNewlines();e.check(w.OR_OR);){e.advance(),e.skipNewlines();let n=tl(e);t={type:"CondOr",left:t,right:n},e.skipNewlines()}return t}function tl(e){let t=li(e);for(e.skipNewlines();e.check(w.AND_AND);){e.advance(),e.skipNewlines();let n=li(e);t={type:"CondAnd",left:t,right:n},e.skipNewlines()}return t}function li(e){return e.skipNewlines(),e.check(w.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:e.withDepth(()=>li(e))}):pd(e)}function pd(e){if(e.check(w.LPAREN)){e.advance();let t=e.withDepth(()=>ui(e));return e.expect(w.RPAREN),{type:"CondGroup",expression:t}}if(Jo(e)){let t=e.current(),n=t.value;if(cd.includes(n)&&!t.quoted){if(e.advance(),e.check(w.DBRACK_END)&&e.error(`Expected operand after ${n}`),Jo(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()&&fd.includes(e.current().value)){let s=e.advance().value,i;return s==="=~"?i=hd(e):s==="=="||s==="!="?i=el(e):i=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:s,left:r,right:i}}if(e.check(w.LESS)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:r,right:s}}if(e.check(w.GREAT)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:r,right:s}}if(e.isWord()&&e.current().value==="="){e.advance();let s=el(e);return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function hd(e){let t=[],n=0,r=-1,s=e.getInput(),i=()=>e.check(w.DBRACK_END)||e.check(w.AND_AND)||e.check(w.OR_OR)||e.check(w.NEWLINE)||e.check(w.EOF);for(;!i();){let 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(w.ASSIGNMENT_WORD)){let l=e.parseWordForRegex();t.push(...l.parts),r=e.peek(-1).end}else if(e.check(w.LPAREN)){let l=e.advance();t.push({type:"Literal",value:"("}),n++,r=l.end}else if(e.check(w.DPAREN_START)){let l=e.advance();t.push({type:"Literal",value:"(("}),n+=2,r=l.end}else if(e.check(w.DPAREN_END))if(n>=2){let l=e.advance();t.push({type:"Literal",value:"))"}),n-=2,r=l.end}else{if(n===1)break;break}else if(e.check(w.RPAREN))if(n>0){let l=e.advance();t.push({type:"Literal",value:")"}),n--,r=l.end}else break;else if(e.check(w.PIPE)){let l=e.advance();t.push({type:"Literal",value:"|"}),r=l.end}else if(e.check(w.SEMICOLON))if(n>0){let l=e.advance();t.push({type:"Literal",value:";"}),r=l.end}else break;else if(n>0&&e.check(w.LESS)){let l=e.advance();t.push({type:"Literal",value:"<"}),r=l.end}else if(n>0&&e.check(w.GREAT)){let l=e.advance();t.push({type:"Literal",value:">"}),r=l.end}else if(n>0&&e.check(w.DGREAT)){let l=e.advance();t.push({type:"Literal",value:">>"}),r=l.end}else if(n>0&&e.check(w.DLESS)){let l=e.advance();t.push({type:"Literal",value:"<<"}),r=l.end}else if(n>0&&e.check(w.LESSAND)){let l=e.advance();t.push({type:"Literal",value:"<&"}),r=l.end}else if(n>0&&e.check(w.GREATAND)){let l=e.advance();t.push({type:"Literal",value:">&"}),r=l.end}else if(n>0&&e.check(w.LESSGREAT)){let l=e.advance();t.push({type:"Literal",value:"<>"}),r=l.end}else if(n>0&&e.check(w.CLOBBER)){let l=e.advance();t.push({type:"Literal",value:">|"}),r=l.end}else if(n>0&&e.check(w.TLESS)){let l=e.advance();t.push({type:"Literal",value:"<<<"}),r=l.end}else if(n>0&&e.check(w.AMP)){let l=e.advance();t.push({type:"Literal",value:"&"}),r=l.end}else if(n>0&&e.check(w.LBRACE)){let l=e.advance();t.push({type:"Literal",value:"{"}),r=l.end}else if(n>0&&e.check(w.RBRACE)){let l=e.advance();t.push({type:"Literal",value:"}"}),r=l.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function yd(e){let t="";for(let n=0;n<e.length;n++){let r=e[n],s=e[n+1];if(r!=="\\"||s===void 0){t+=r;continue}"\\[]^-".includes(s)&&(t+="\\"),t+=s,n++}return t}function Yn(e){return e.length>0?e:[T.literal("")]}function gd(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 wd(e,t,n){let r=n+1,s=t[r];if("@*#?$!-0123456789".includes(s))return{part:T.parameterExpansion(s),endIndex:r+1};let i="";for(;r<t.length&&/[a-zA-Z0-9_]/.test(t[r]);)i+=t[r],r++;return{part:T.parameterExpansion(i),endIndex:r}}function Ed(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 c=Ks(e,t,s,"[","]");if(o+=`[${Dr(t.slice(s+1,c))}]`,s=c+1,t[s]==="["){let f=1,d=s;for(;d<t.length&&f>0;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let p=t.slice(n+2,d);return{part:T.parameterExpansion("",{type:"BadSubstitution",text:p}),endIndex:d+1}}}if(o===""&&!i&&!a&&t[s]!=="}"){let c=1,f=s;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;if(c>0)throw new $e("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(n+2,f);return{part:T.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let u=null;if(i){let c=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(c)if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=ci(e,t,s,o,r);f.operation?(u={type:"Indirection",innerOp:f.operation},s=f.endIndex):(u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},o="")}else u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},o="";else if(t[s]==="*"||t[s]==="@"&&!/[QPaAEKkuUL]/.test(t[s+1]||"")){let f=t[s];s++,u={type:"VarNamePrefix",prefix:o,star:f==="*"},o=""}else if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=ci(e,t,s,o,r);f.operation?(u={type:"Indirection",innerOp:f.operation},s=f.endIndex):u={type:"Indirection"}}else u={type:"Indirection"}}else if(a)if(t[s]===":")for(u={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`):u={type:"Length"};if(!u&&s<t.length&&t[s]!=="}"){let c=ci(e,t,s,o,r);u=c.operation,s=c.endIndex}if(s<t.length&&t[s]!=="}"){let c=t[s];if(!/[:\-+=?#%/^,@[]/.test(c)){let f=s;for(;f<t.length&&t[f]!=="}";)f++;let d=t.slice(n,f+1);e.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<t.length&&t[s]!=="}";)s++;if(s>=t.length)throw new $e("unexpected EOF while looking for matching '}'",0,0);return{part:T.parameterExpansion(o,u),endIndex:s+1}}function ci(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=on(e,t,i),g=t.slice(i,b),y=e.withDepth(()=>Mt(e,g,!1,!1,!0,!1,s,!1,!1,!0)),S=T.word(Yn(y));if(l==="-")return{operation:{type:"DefaultValue",word:S,checkEmpty:!0},endIndex:b};if(l==="=")return{operation:{type:"AssignDefault",word:S,checkEmpty:!0},endIndex:b};if(l==="?")return{operation:{type:"ErrorIfUnset",word:S,checkEmpty:!0},endIndex:b};if(l==="+")return{operation:{type:"UseAlternative",word:S,checkEmpty:!0},endIndex:b}}i++;let u=on(e,t,i),c=t.slice(i,u),f=-1,d=0,p=0;for(let E=0;E<c.length;E++){let b=c[E];if(b==="("||b==="[")d++;else if(b===")"||b==="]")d--;else if(b==="?"&&d===0)p++;else if(b===":"&&d===0)if(p>0)p--;else{f=E;break}}let h=f>=0?c.slice(0,f):c,m=f>=0?c.slice(f+1):null;return{operation:{type:"Substring",offset:Xs(e,h),length:m!==null?Xs(e,m):null},endIndex:u}}if("-=?+".includes(a)){i++;let l=on(e,t,i),u=t.slice(i,l),c=e.withDepth(()=>Mt(e,u,!1,!1,!0,!1,s,!1,!1,!0)),f=T.word(Yn(c));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:u?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,u=a==="#"?"prefix":"suffix";i+=l?2:1;let c=on(e,t,i),f=t.slice(i,c),d=e.withDepth(()=>Mt(e,f,!1,!1,!1));return{operation:{type:"PatternRemoval",pattern:T.word(Yn(d)),side:u,greedy:l},endIndex:c}}if(a==="/"){let l=o==="/";i+=l?2:1;let u=null;t[i]==="#"?(u="start",i++):t[i]==="%"&&(u="end",i++);let c;u!==null&&(t[i]==="/"||t[i]==="}")?c=i:c=Zo(e,t,i);let f=t.slice(i,c),d=e.withDepth(()=>Mt(e,f,!1,!1,!1)),p=T.word(Yn(d)),h=null,m=c;if(t[c]==="/"){let E=c+1,b=on(e,t,E),g=t.slice(E,b),y=e.withDepth(()=>Mt(e,g,!1,!1,!1));h=T.word(Yn(y)),m=b}return{operation:{type:"PatternReplacement",pattern:p,replacement:h,all:l,anchor:u},endIndex:m}}if(a==="^"||a===","){let l=o===a,u=a==="^"?"upper":"lower";i+=l?2:1;let c=on(e,t,i),f=t.slice(i,c),d=f?T.word([T.literal(f)]):null;return{operation:{type:"CaseModification",direction:u,all:l,pattern:d},endIndex:c}}return a==="@"&&/[QPaAEKkuUL]/.test(o)?{operation:{type:"Transform",operator:o},endIndex:i+2}:{operation:null,endIndex:i}}function fi(e,t,n,r=!1){let s=n+1;if(s>=t.length)return{part:T.literal("$"),endIndex:s};let i=t[s];if(i==="("&&t[s+1]==="(")return e.isDollarDparenSubshell(t,n)?e.parseCommandSubstitution(t,n):e.parseArithmeticExpansion(t,n);if(i==="["){let 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),u=te(e,l);return{part:T.arithmeticExpansion(u),endIndex:o+1}}}return i==="("?e.parseCommandSubstitution(t,n):i==="{"?Ed(e,t,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?wd(e,t,n):{part:T.literal("$"),endIndex:s}}function nl(e,t){let n=[],r=0,s="",i=()=>{s&&(n.push(T.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}=fi(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 bd(e,t,n){let r=[],s=n,i="",a=()=>{i&&(r.push(T.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:u}=fi(e,t,s,!0);l&&r.push(l),s=u;continue}if(o==="`"){a();let{part:l,endIndex:u}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=u;continue}i+=o,s++}return a(),{part:T.doubleQuoted(r),endIndex:s}}function Mt(e,t,n=!1,r=!1,s=!1,i=!1,a=!1,o=!1,l=!1,u=!1,c=!0){if(r)return[T.singleQuoted(t)];if(n){let m=nl(e,t);return[T.doubleQuoted(m)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let m=t.slice(1,-1),E=!1;for(let b=0;b<m.length;b++){if(m[b]==='"'){E=!0;break}m[b]==="\\"&&b+1<m.length&&b++}if(!E){let b=nl(e,m);return[T.doubleQuoted(b)]}}let f=[],d=0,p="",h=()=>{p&&(f.push(T.literal(p)),p="")};for(;d<t.length;){let m=t[d];if(m==="\\"&&d+1<t.length){let E=t[d+1];if(l){h(),f.push(T.escaped(E)),d+=2;continue}if(!i&&!a){E!==`
70
- `&&(h(),f.push(T.escaped(E))),d+=2;continue}let b=i?E==="$"||E==="`"||E===`
68
+ `);)f=!0,c++;if(f&&c<r&&n[c]===")")return!0}if(i===0)return!1;s++;continue}if(i===1&&(l==="|"&&s+1<r&&n[s+1]==="|"||l==="&"&&s+1<r&&n[s+1]==="&"||l==="|"&&s+1<r&&n[s+1]!=="|"))return!0;s++}return!1}};var ei=1e6,nr=1e5,sd=1e6,Wo=200,Ce;(function(e){e[e.Default=0]="Default",e[e.Assignment=1]="Assignment",e[e.NoBraceExpansion=2]="NoBraceExpansion",e[e.Regex=4]="Regex"})(Ce||(Ce={}));var Vo=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS,w.AND_GREAT,w.AND_DGREAT]),zo=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS]),qo=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS,w.AND_GREAT,w.AND_DGREAT]),$e=class extends Error{line;column;token;constructor(t,n,r,s=void 0){super(`Parse error at ${n}:${r}: ${t}`),this.line=n,this.column=r,this.token=s,this.name="ParseException"}},Lr=class{iterations=0;tokens=0;depth=0;reset(){this.iterations=0,this.tokens=0,this.depth=0}chargeIteration(t,n){if(this.iterations++,this.iterations>sd)throw new $e("Maximum parse iterations exceeded (possible infinite loop)",t,n)}chargeTokens(t,n=1,r=1){if(this.tokens+=t,this.tokens>nr)throw new $e(`Too many tokens: cumulative count exceeds limit of ${nr}`,n,r)}enter(t,n){if(this.depth++,this.depth>Wo)throw this.depth--,new $e(`Maximum parser nesting depth exceeded (${Wo})`,t,n);let r=!0;return()=>{r&&(r=!1,this.depth--)}}};function he(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
69
+ `){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var Tr=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function rr(e){if(e.includes("#")){let n=e.split("#");if(n.length!==2)return Number.NaN;let[r,s]=n;if(!/^\d+$/.test(r)||s.length===0)return Number.NaN;let i=Number.parseInt(r,10);if(i<2||i>64)return Number.NaN;let 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 Uo(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 jo(e,t){if(e.slice(t,t+2)!=="$'")return null;let n=t+2,r="";for(;n<e.length&&e[n]!=="'";)if(e[n]==="\\"&&n+1<e.length){let i=e[n+1];switch(i){case"n":r+=`
70
+ `;break;case"t":r+=" ";break;case"r":r+="\r";break;case"\\":r+="\\";break;case"'":r+="'";break;default:r+=i}n+=2}else r+=e[n],n++;e[n]==="'"&&n++;let s=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(s)?0:s},pos:n}}function Go(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 id(e){let t="",n=0;for(;n<e.length;)if(e[n]==='"'){for(n++;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);n<e.length&&n++}else t+=e[n],n++;return t}function te(e,t){let n=id(t),{expr:r,pos:s}=Ln(e,n,0),i=he(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 qe(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function Ue(e,t){return he(e,t)>=e.length}function Ln(e,t,n){return ad(e,t,n)}function mn(e,t,n){return e.withDepth(()=>Ln(e,t,n))}function ad(e,t,n){let{expr:r,pos:s}=sr(e,t,n);for(s=he(t,s);t[s]===",";){if(s++,Ue(t,s))return qe(",",s);let{expr:a,pos:o}=sr(e,t,s);r={type:"ArithBinary",operator:",",left:r,right:a},s=he(t,o)}return{expr:r,pos:s}}function sr(e,t,n){let{expr:r,pos:s}=od(e,t,n);if(s=he(t,s),t[s]==="?"){s++;let{expr:i,pos:a}=mn(e,t,s);if(s=he(t,a),t[s]===":"){s++;let{expr:o,pos:l}=mn(e,t,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:o},pos:l}}}return{expr:r,pos:s}}function od(e,t,n){let{expr:r,pos:s}=Ho(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="||";){if(s+=2,Ue(t,s))return qe("||",s);let{expr:a,pos:o}=Ho(e,t,s);r={type:"ArithBinary",operator:"||",left:r,right:a},s=o}return{expr:r,pos:s}}function Ho(e,t,n){let{expr:r,pos:s}=Zo(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="&&";){if(s+=2,Ue(t,s))return qe("&&",s);let{expr:a,pos:o}=Zo(e,t,s);r={type:"ArithBinary",operator:"&&",left:r,right:a},s=o}return{expr:r,pos:s}}function Zo(e,t,n){let{expr:r,pos:s}=Qo(e,t,n);for(;s=he(t,s),t[s]==="|"&&t[s+1]!=="|";){if(s++,Ue(t,s))return qe("|",s);let{expr:a,pos:o}=Qo(e,t,s);r={type:"ArithBinary",operator:"|",left:r,right:a},s=o}return{expr:r,pos:s}}function Qo(e,t,n){let{expr:r,pos:s}=Ko(e,t,n);for(;s=he(t,s),t[s]==="^";){if(s++,Ue(t,s))return qe("^",s);let{expr:a,pos:o}=Ko(e,t,s);r={type:"ArithBinary",operator:"^",left:r,right:a},s=o}return{expr:r,pos:s}}function Ko(e,t,n){let{expr:r,pos:s}=Xo(e,t,n);for(;s=he(t,s),t[s]==="&"&&t[s+1]!=="&";){if(s++,Ue(t,s))return qe("&",s);let{expr:a,pos:o}=Xo(e,t,s);r={type:"ArithBinary",operator:"&",left:r,right:a},s=o}return{expr:r,pos:s}}function Xo(e,t,n){let{expr:r,pos:s}=Yo(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="=="||t.slice(s,s+2)==="!=";){let i=t.slice(s,s+2);if(s+=2,Ue(t,s))return qe(i,s);let{expr:a,pos:o}=Yo(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}return{expr:r,pos:s}}function Yo(e,t,n){let{expr:r,pos:s}=ti(e,t,n);for(;;)if(s=he(t,s),t.slice(s,s+2)==="<="||t.slice(s,s+2)===">="){let i=t.slice(s,s+2);if(s+=2,Ue(t,s))return qe(i,s);let{expr:a,pos:o}=ti(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++,Ue(t,s))return qe(i,s);let{expr:a,pos:o}=ti(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}else break;return{expr:r,pos:s}}function ti(e,t,n){let{expr:r,pos:s}=Jo(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="<<"||t.slice(s,s+2)===">>";){let i=t.slice(s,s+2);if(s+=2,Ue(t,s))return qe(i,s);let{expr:a,pos:o}=Jo(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}return{expr:r,pos:s}}function Jo(e,t,n){let{expr:r,pos:s}=el(e,t,n);for(;s=he(t,s),(t[s]==="+"||t[s]==="-")&&t[s+1]!==t[s];){let i=t[s];if(s++,Ue(t,s))return qe(i,s);let{expr:a,pos:o}=el(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}return{expr:r,pos:s}}function el(e,t,n){let{expr:r,pos:s}=Mr(e,t,n);for(;;)if(s=he(t,s),t[s]==="*"&&t[s+1]!=="*"){if(s++,Ue(t,s))return qe("*",s);let{expr:a,pos:o}=Mr(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++,Ue(t,s))return qe(i,s);let{expr:a,pos:o}=Mr(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}else break;return{expr:r,pos:s}}function Mr(e,t,n){let{expr:r,pos:s}=ni(e,t,n),i=he(t,s);if(t.slice(i,i+2)==="**"){if(i+=2,Ue(t,i))return qe("**",i);let{expr:o,pos:l}=e.withDepth(()=>Mr(e,t,i));return{expr:{type:"ArithBinary",operator:"**",left:r,right:o},pos:l}}return{expr:r,pos:s}}function ni(e,t,n){let r=he(t,n);if(t.slice(r,r+2)==="++"||t.slice(r,r+2)==="--"){let s=t.slice(r,r+2);r+=2;let{expr:i,pos:a}=e.withDepth(()=>ni(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(()=>ni(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:a}}return ud(e,t,r)}function ld(e,t){let n=e[t];return n==="$"||n==="`"}function ud(e,t,n){let{expr:r,pos:s}=tl(e,t,n,!1),i=[r];for(;ld(t,s);){let{expr:o,pos:l}=tl(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}=mn(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=he(t,s),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let o of Tr)if(t.slice(s,s+o.length)===o&&t.slice(s,s+o.length+1)!=="=="){s+=o.length;let{expr:l,pos:u}=e.withDepth(()=>sr(e,t,s));return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:o,target:r.nameExpr,subscript:r.subscript,value:l},pos:u}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:o,target:r,value:l},pos:u}:{expr:{type:"ArithAssignment",operator:o,variable:r.name,value:l},pos:u}}}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 tl(e,t,n,r=!1){let s=he(t,n),i=Uo(mn,e,t,s);if(i)return i;let a=jo(t,s);if(a)return a;let o=Go(t,s);if(o)return o;if(t.slice(s,s+2)==="$("&&t[s+2]!=="("){s+=2;let u=1,c=s;for(;s<t.length&&u>0;)t[s]==="("?u++:t[s]===")"&&u--,u>0&&s++;let f=t.slice(c,s);return s++,{expr:{type:"ArithCommandSubst",command:f},pos:s}}if(t[s]==="`"){s++;let u=s;for(;s<t.length&&t[s]!=="`";)s++;let c=t.slice(u,s);return t[s]==="`"&&s++,{expr:{type:"ArithCommandSubst",command:c},pos:s}}if(t[s]==="("){s++;let{expr:u,pos:c}=mn(e,t,s);return s=he(t,c),t[s]===")"&&s++,{expr:{type:"ArithGroup",expression:u},pos:s}}if(t[s]==="'"){s++;let u="";for(;s<t.length&&t[s]!=="'";)u+=t[s],s++;t[s]==="'"&&s++;let c=Number.parseInt(u,10);return{expr:{type:"ArithSingleQuote",content:u,value:Number.isNaN(c)?0:c},pos:s}}if(t[s]==='"'){s++;let u="";for(;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?(u+=t[s+1],s+=2):(u+=t[s],s++);t[s]==='"'&&s++;let c=u.trim();if(!c)return{expr:{type:"ArithNumber",value:0},pos:s};let{expr:f}=mn(e,c,0);return{expr:f,pos:s}}if(/[0-9]/.test(t[s])){let u="",c=!1,f=!1;for(;s<t.length;){let p=t[s];if(c)if(/[0-9a-zA-Z@_]/.test(p))u+=p,s++;else break;else if(p==="#")c=!0,u+=p,s++;else if(u==="0"&&(p==="x"||p==="X")&&s+1<t.length&&/[0-9a-fA-F]/.test(t[s+1]))f=!0,u+=p,s++;else if(f&&/[0-9a-fA-F]/.test(p))u+=p,s++;else if(!f&&/[0-9]/.test(p))u+=p,s++;else break}if(s<t.length&&/[a-zA-Z_]/.test(t[s])){let p=u;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)p+=t[s],s++;return{expr:{type:"ArithSyntaxError",errorToken:p,message:`${p}: value too great for base (error token is "${p}")`},pos:s}}if(t[s]==="."&&/[0-9]/.test(t[s+1]))throw new ae(`${u}.${t[s+1]}...: syntax error: invalid arithmetic operator`);if(t[s]==="["){let p=t.slice(s).trim();return{expr:{type:"ArithNumberSubscript",number:u,errorToken:p},pos:t.length}}return{expr:{type:"ArithNumber",value:rr(u)},pos:s}}if(t[s]==="$"&&t[s+1]==="{"){let u=s+2,c=1,f=u;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;let d=t.slice(u,f),p=f+1;if(t[p]==="#"){let h=p+1;for(;h<t.length&&/[0-9a-zA-Z@_]/.test(t[h]);)h++;let m=t.slice(p+1,h);return{expr:{type:"ArithDynamicBase",baseExpr:d,value:m},pos:h}}if(/[0-9]/.test(t[p])||t[p]==="x"||t[p]==="X"){let h=p;if(t[p]==="x"||t[p]==="X")for(h++;h<t.length&&/[0-9a-fA-F]/.test(t[h]);)h++;else for(;h<t.length&&/[0-9]/.test(t[h]);)h++;let m=t.slice(p,h);return{expr:{type:"ArithDynamicNumber",prefix:d,suffix:m},pos:h}}return s=p,{expr:{type:"ArithBracedExpansion",content:d},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[0-9]/.test(t[s+1])){s++;let u="";for(;s<t.length&&/[0-9]/.test(t[s]);)u+=t[s],s++;return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:!0},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[*@#?\-!$]/.test(t[s+1])){let u=t[s+1];return s+=2,{expr:{type:"ArithSpecialVar",name:u},pos:s}}let l=!1;if(t[s]==="$"&&s+1<t.length&&/[a-zA-Z_]/.test(t[s+1])&&(l=!0,s++),s<t.length&&/[a-zA-Z_]/.test(t[s])){let u="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)u+=t[s],s++;if(t[s]==="["&&!r){s++;let c;if(t[s]==="'"||t[s]==='"'){let d=t[s];for(s++,c="";s<t.length&&t[s]!==d;)c+=t[s],s++;t[s]===d&&s++,s=he(t,s),t[s]==="]"&&s++}let f;if(c===void 0){let{expr:d,pos:p}=mn(e,t,s);f=d,s=p,t[s]==="]"&&s++}if(s=he(t,s),t[s]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:u,index:f},pos:s};if(!r){for(let d of Tr)if(t.slice(s,s+d.length)===d&&t.slice(s,s+d.length+1)!=="=="){s+=d.length;let{expr:p,pos:h}=e.withDepth(()=>sr(e,t,s));return{expr:{type:"ArithAssignment",operator:d,variable:u,subscript:f,stringKey:c,value:p},pos:h}}}return{expr:{type:"ArithArrayElement",array:u,index:f,stringKey:c},pos:s}}if(s=he(t,s),!r){for(let c of Tr)if(t.slice(s,s+c.length)===c&&t.slice(s,s+c.length+1)!=="=="){s+=c.length;let{expr:f,pos:d}=e.withDepth(()=>sr(e,t,s));return{expr:{type:"ArithAssignment",operator:c,variable:u,value:f},pos:d}}}return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:l},pos:s}}if(t[s]==="#"){let u=s+1;for(;u<t.length&&t[u]!==`
71
+ `;)u++;let c=t.slice(s,u).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:c,message:`${c}: syntax error: invalid arithmetic operator (error token is "${c}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:s}}var Fr=e=>{let t,n="";for(let r=0;r<e.length;r++){let s=e[r];if(s==="\\"&&t==='"'&&r+1<e.length){n+=s+e[r+1],r+=1;continue}if(s==="'"||s==='"'){t===s?t=void 0:t||(t=s),n+=s;continue}if(s==="\\"&&!t&&r+1<e.length){let i=e[r+1];n+=i==="$"||i==="`"?`\\${i}`:i,r+=1;continue}n+=s}return n};function cd(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 sl(e,t,n){let r=n+1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;return r}function ri(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 yn(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 il(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 al(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=fd(t,r);a===-1?(s+=i,r++):(s+=t.slice(r,a+1),r=a+1)}else break}return{pattern:s,endIndex:r}}function fd(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 ol(e,t,n){let r="",s=n;for(;s<t.length&&t[s]!=="'";){let i=t[s];if(i==="\\"&&s+1<t.length)switch(t[s+1]){case"n":r+=`
72
+ `,s+=2;break;case"t":r+=" ",s+=2;break;case"r":r+="\r",s+=2;break;case"\\":r+="\\",s+=2;break;case"'":r+="'",s+=2;break;case'"':r+='"',s+=2;break;case"a":r+="\x07",s+=2;break;case"b":r+="\b",s+=2;break;case"e":case"E":r+="\x1B",s+=2;break;case"f":r+="\f",s+=2;break;case"v":r+="\v",s+=2;break;case"x":{let o=[],l=s;for(;l+1<t.length&&t[l]==="\\"&&t[l+1]==="x";){let u=t.slice(l+2,l+4),c=parseInt(u,16);if(!Number.isNaN(c)&&u.length>0)o.push(c),l+=2+u.length;else break}o.length>0?(r+=cd(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 u=parseInt(o,8);r+=String.fromCharCode(u),s=l;break}default:r+=i,s++}else r+=i,s++}return s<t.length&&t[s]==="'"&&s++,{part:T.literal(r),endIndex:s}}function si(e,t){let n=t.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:te(e,n)}function rl(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 ll(e,t,n,r){let s=ri(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:rl(i).map(c=>e.withDepth(()=>({type:"Word",word:T.word(r(e,c,!1,!1,!1))})))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:rl(i).map(c=>({type:"Word",word:T.word([T.literal(c)])}))},endIndex:s+1}:null}function ii(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(ii(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 ul(e,t){return{[w.LESS]:"<",[w.GREAT]:">",[w.DGREAT]:">>",[w.LESSAND]:"<&",[w.GREATAND]:">&",[w.LESSGREAT]:"<>",[w.CLOBBER]:">|",[w.TLESS]:"<<<",[w.AND_GREAT]:"&>",[w.AND_DGREAT]:"&>>",[w.DLESS]:"<",[w.DLESSDASH]:"<"}[t]||">"}function ir(e){let t=e.current(),n=t.type;if(n===w.NUMBER){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:zo.has(r.type)}if(n===w.FD_VARIABLE){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:qo.has(r.type)}return!e.isProcessSubstitutionStart()&&Vo.has(n)}function Br(e){let t=null,n;e.check(w.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(w.FD_VARIABLE)&&(n=e.advance().value);let r=e.advance(),s=ul(e,r.type);if(r.type===w.DLESS||r.type===w.DLESSDASH)return dd(e,t,n,r.type===w.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return T.redirection(s,i,t,n)}function dd(e,t,n,r){e.isWord()||e.error("Expected here-document delimiter");let s=e.advance(),i=s.heredocDelimiter??s.value,a=s.quoted||!1,o=T.redirection(r?"<<-":"<<",T.hereDoc(i,T.word([]),r,a),t,n);return e.addPendingHeredoc(o,i,r,a),o}function oi(e){let t=e.getSourceLine(),n=[],r=null,s=[],i=[];for(;e.check(w.ASSIGNMENT_WORD)||ir(e);)e.checkIterationLimit(),e.check(w.ASSIGNMENT_WORD)?n.push(pd(e)):i.push(Br(e));if(e.isWord())r=e.parseWord();else if(n.length>0&&(e.check(w.DBRACK_START)||e.check(w.DPAREN_START))){let o=e.advance();r=T.word([T.literal(o.value)])}for(;(!e.isStatementEnd()||e.check(w.RBRACE))&&!e.check(w.PIPE,w.PIPE_AMP);)if(e.checkIterationLimit(),ir(e))i.push(Br(e));else if(e.check(w.ASSIGNMENT_WORD)){let o=e.advance(),l=o.value,u=l.endsWith("="),c=l.endsWith("=(");if((u||c)&&(c||e.check(w.LPAREN))){let f=c?l.slice(0,-2):l.slice(0,-1);c||e.expect(w.LPAREN);let d=ai(e);e.expect(w.RPAREN);let p=d.map(m=>ii(e,m)),h=`${f}=(${p.join(" ")})`;s.push(e.parseWordFromString(h,!1,!1,!0))}else{let f=e.parseWordFromString(l,o.quoted,o.singleQuoted,!0);s.push(e.parseAdjacentWordParts(f.parts,o.end,Ce.Assignment))}}else if(e.isWord())s.push(e.parseWord());else if(e.check(w.RBRACE)){let o=e.advance();s.push(e.parseWordFromString(o.value,!1,!1))}else if(e.check(w.LBRACE)){let o=e.advance();s.push(e.parseWordFromString(o.value,!1,!1))}else if(e.check(w.DBRACK_END)){let o=e.advance();s.push(e.parseWordFromString(o.value,!1,!1))}else if(e.check(w.LPAREN))e.error("syntax error near unexpected token `('");else break;let a=T.simpleCommand(r,s,n,i);return a.line=t,a}function pd(e){let t=e.expect(w.ASSIGNMENT_WORD),n=t.value,r=n.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||e.error(`Invalid assignment: ${n}`);let s=r[0],i,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=Fr(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=ai(e);e.expect(w.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return T.assignment(d,null,o,f)}if(l===""&&e.check(w.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=ai(e);e.expect(w.RPAREN);let p=i!==void 0?`${s}[${i}]`:s;return T.assignment(p,null,o,d)}}let u=l?e.parseWordFromString(l,t.quoted,t.singleQuoted,!0):null;t.end===e.current().start&&e.isProcessSubstitutionStart()&&(u=e.parseAdjacentWordParts(u?.parts??[],t.end,Ce.Assignment));let c=i!==void 0?`${s}[${i}]`:s;return T.assignment(c,u,o,null)}var hd=new Set([w.AMP,w.PIPE,w.PIPE_AMP,w.SEMICOLON,w.AND_AND,w.OR_OR,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND]);function ai(e){let t=[];for(e.skipNewlines();!e.check(w.RPAREN,w.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):hd.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function li(e,t){e.expect(w.IF);let n=[],r=e.parseCompoundList();e.expect(w.THEN);let s=e.parseCompoundList();if(s.length===0){let o=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${o}'`)}for(n.push({condition:r,body:s});e.check(w.ELIF);){e.advance();let o=e.parseCompoundList();e.expect(w.THEN);let l=e.parseCompoundList();if(l.length===0){let u=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${u}'`)}n.push({condition:o,body:l})}let i=null;e.check(w.ELSE)&&(e.advance(),i=e.parseCompoundList(),i.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(w.FI);let a=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.ifNode(n,i,a)}function ui(e,t){let n=e.expect(w.FOR);if(e.check(w.DPAREN_START))return yd(e,t,e.getSourceLine(n));e.isWord()||e.error("Expected variable name in for loop");let s=e.advance().value,i=null;if(e.skipNewlines(),e.check(w.IN))for(e.advance(),i=[];!e.check(w.SEMICOLON,w.NEWLINE,w.DO,w.EOF)&&e.isWord();)i.push(e.parseWord());e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(w.DO);let a=e.parseCompoundList();e.expect(w.DONE);let o=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.forNode(s,i,a,o)}function yd(e,t,n){e.expect(w.DPAREN_START);let r=null,s=null,i=null,a=["","",""],o=0,l=0;for(;!e.check(w.DPAREN_END,w.EOF);){let f=e.advance();if(f.type===w.SEMICOLON&&l===0){if(o++,o>2)break}else f.value==="("&&l++,f.value===")"&&l--,a[o]+=f.value}e.expect(w.DPAREN_END),a[0].trim()&&(r=te(e,a[0].trim())),a[1].trim()&&(s=te(e,a[1].trim())),a[2].trim()&&(i=te(e,a[2].trim())),e.skipNewlines(),e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines();let u;e.check(w.LBRACE)?(e.advance(),u=e.parseCompoundList(),e.expect(w.RBRACE)):(e.expect(w.DO),u=e.parseCompoundList(),e.expect(w.DONE));let c=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:s,update:i,body:u,redirections:c,line:n}}function ci(e,t){e.expect(w.WHILE);let n=e.parseCompoundList();e.expect(w.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(w.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.whileNode(n,r,s)}function fi(e,t){e.expect(w.UNTIL);let n=e.parseCompoundList();e.expect(w.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(w.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.untilNode(n,r,s)}function di(e,t){e.expect(w.CASE),e.isWord()||e.error("Expected word after 'case'");let n=e.parseWord();e.skipNewlines(),e.expect(w.IN),e.skipNewlines();let r=[];for(;!e.check(w.ESAC,w.EOF);){e.checkIterationLimit();let i=e.getPos(),a=gd(e);if(a&&r.push(a),e.skipNewlines(),e.getPos()===i&&!a)break}e.expect(w.ESAC);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.caseNode(n,r,s)}function gd(e){e.check(w.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(w.PIPE));)e.advance();if(t.length===0)return null;e.expect(w.RPAREN),e.skipNewlines();let n=[];for(;!e.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND,w.ESAC,w.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===w.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(w.LPAREN)&&e.peek(1).type===w.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let s=e.getPos(),i=e.parseStatement();if(i&&n.push(i),e.skipSeparators(!1),e.getPos()===s&&!i)break}let r=";;";return e.check(w.DSEMI)?(e.advance(),r=";;"):e.check(w.SEMI_AND)?(e.advance(),r=";&"):e.check(w.SEMI_SEMI_AND)&&(e.advance(),r=";;&"),T.caseItem(t,n,r)}function pi(e,t){e.expect(w.LPAREN);let n=e.parseCompoundList();e.expect(w.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.subshell(n,r)}function hi(e,t){e.expect(w.LBRACE);let n=e.parseCompoundList();e.expect(w.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.group(n,r)}var Ed=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],bd=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function fl(e){return e.isWord()||e.check(w.LBRACE)||e.check(w.RBRACE)||e.check(w.ASSIGNMENT_WORD)}function dl(e){if(e.check(w.BANG)&&e.peek(1).type===w.LPAREN){e.advance(),e.advance();let t=1,n="!(";for(;t>0&&!e.check(w.EOF);)if(e.check(w.LPAREN))t++,n+="(",e.advance();else if(e.check(w.RPAREN))t--,t>0&&(n+=")"),e.advance();else if(e.isWord())n+=e.advance().value;else if(e.check(w.PIPE))n+="|",e.advance();else break;return n+=")",e.parseWordFromString(n,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function yi(e){return e.skipNewlines(),Sd(e)}function Sd(e){let t=pl(e);for(e.skipNewlines();e.check(w.OR_OR);){e.advance(),e.skipNewlines();let n=pl(e);t={type:"CondOr",left:t,right:n},e.skipNewlines()}return t}function pl(e){let t=mi(e);for(e.skipNewlines();e.check(w.AND_AND);){e.advance(),e.skipNewlines();let n=mi(e);t={type:"CondAnd",left:t,right:n},e.skipNewlines()}return t}function mi(e){return e.skipNewlines(),e.check(w.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:e.withDepth(()=>mi(e))}):Ad(e)}function Ad(e){if(e.check(w.LPAREN)){e.advance();let t=e.withDepth(()=>yi(e));return e.expect(w.RPAREN),{type:"CondGroup",expression:t}}if(fl(e)){let t=e.current(),n=t.value;if(Ed.includes(n)&&!t.quoted){if(e.advance(),e.check(w.DBRACK_END)&&e.error(`Expected operand after ${n}`),fl(e)){let i=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:n,operand:i}}let s=e.current();e.error(`unexpected argument \`${s.value}' to conditional unary operator`)}let r=e.parseWordNoBraceExpansion();if(e.isWord()&&bd.includes(e.current().value)){let s=e.advance().value,i;return s==="=~"?i=vd(e):s==="=="||s==="!="?i=dl(e):i=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:s,left:r,right:i}}if(e.check(w.LESS)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:r,right:s}}if(e.check(w.GREAT)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:r,right:s}}if(e.isWord()&&e.current().value==="="){e.advance();let s=dl(e);return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function vd(e){let t=[],n=0,r=-1,s=e.getInput(),i=()=>e.check(w.DBRACK_END)||e.check(w.AND_AND)||e.check(w.OR_OR)||e.check(w.NEWLINE)||e.check(w.EOF);for(;!i();){let 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(w.ASSIGNMENT_WORD)){let l=e.parseWordForRegex();t.push(...l.parts),r=e.peek(-1).end}else if(e.check(w.LPAREN)){let l=e.advance();t.push({type:"Literal",value:"("}),n++,r=l.end}else if(e.check(w.DPAREN_START)){let l=e.advance();t.push({type:"Literal",value:"(("}),n+=2,r=l.end}else if(e.check(w.DPAREN_END))if(n>=2){let l=e.advance();t.push({type:"Literal",value:"))"}),n-=2,r=l.end}else{if(n===1)break;break}else if(e.check(w.RPAREN))if(n>0){let l=e.advance();t.push({type:"Literal",value:")"}),n--,r=l.end}else break;else if(e.check(w.PIPE)){let l=e.advance();t.push({type:"Literal",value:"|"}),r=l.end}else if(e.check(w.SEMICOLON))if(n>0){let l=e.advance();t.push({type:"Literal",value:";"}),r=l.end}else break;else if(n>0&&e.check(w.LESS)){let l=e.advance();t.push({type:"Literal",value:"<"}),r=l.end}else if(n>0&&e.check(w.GREAT)){let l=e.advance();t.push({type:"Literal",value:">"}),r=l.end}else if(n>0&&e.check(w.DGREAT)){let l=e.advance();t.push({type:"Literal",value:">>"}),r=l.end}else if(n>0&&e.check(w.DLESS)){let l=e.advance();t.push({type:"Literal",value:"<<"}),r=l.end}else if(n>0&&e.check(w.LESSAND)){let l=e.advance();t.push({type:"Literal",value:"<&"}),r=l.end}else if(n>0&&e.check(w.GREATAND)){let l=e.advance();t.push({type:"Literal",value:">&"}),r=l.end}else if(n>0&&e.check(w.LESSGREAT)){let l=e.advance();t.push({type:"Literal",value:"<>"}),r=l.end}else if(n>0&&e.check(w.CLOBBER)){let l=e.advance();t.push({type:"Literal",value:">|"}),r=l.end}else if(n>0&&e.check(w.TLESS)){let l=e.advance();t.push({type:"Literal",value:"<<<"}),r=l.end}else if(n>0&&e.check(w.AMP)){let l=e.advance();t.push({type:"Literal",value:"&"}),r=l.end}else if(n>0&&e.check(w.LBRACE)){let l=e.advance();t.push({type:"Literal",value:"{"}),r=l.end}else if(n>0&&e.check(w.RBRACE)){let l=e.advance();t.push({type:"Literal",value:"}"}),r=l.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function xd(e){let t="";for(let n=0;n<e.length;n++){let r=e[n],s=e[n+1];if(r!=="\\"||s===void 0){t+=r;continue}"\\[]^-".includes(s)&&(t+="\\"),t+=s,n++}return t}function ar(e){return e.length>0?e:[T.literal("")]}function kd(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 Pd(e,t,n){let r=n+1,s=t[r];if("@*#?$!-0123456789".includes(s))return{part:T.parameterExpansion(s),endIndex:r+1};let i="";for(;r<t.length&&/[a-zA-Z0-9_]/.test(t[r]);)i+=t[r],r++;return{part:T.parameterExpansion(i),endIndex:r}}function Cd(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 c=ri(e,t,s,"[","]");if(o+=`[${Fr(t.slice(s+1,c))}]`,s=c+1,t[s]==="["){let f=1,d=s;for(;d<t.length&&f>0;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let p=t.slice(n+2,d);return{part:T.parameterExpansion("",{type:"BadSubstitution",text:p}),endIndex:d+1}}}if(o===""&&!i&&!a&&t[s]!=="}"){let c=1,f=s;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;if(c>0)throw new $e("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(n+2,f);return{part:T.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let u=null;if(i){let c=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(c)if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=gi(e,t,s,o,r);f.operation?(u={type:"Indirection",innerOp:f.operation},s=f.endIndex):(u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},o="")}else u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},o="";else if(t[s]==="*"||t[s]==="@"&&!/[QPaAEKkuUL]/.test(t[s+1]||"")){let f=t[s];s++,u={type:"VarNamePrefix",prefix:o,star:f==="*"},o=""}else if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=gi(e,t,s,o,r);f.operation?(u={type:"Indirection",innerOp:f.operation},s=f.endIndex):u={type:"Indirection"}}else u={type:"Indirection"}}else if(a)if(t[s]===":")for(u={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`):u={type:"Length"};if(!u&&s<t.length&&t[s]!=="}"){let c=gi(e,t,s,o,r);u=c.operation,s=c.endIndex}if(s<t.length&&t[s]!=="}"){let c=t[s];if(!/[:\-+=?#%/^,@[]/.test(c)){let f=s;for(;f<t.length&&t[f]!=="}";)f++;let d=t.slice(n,f+1);e.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<t.length&&t[s]!=="}";)s++;if(s>=t.length)throw new $e("unexpected EOF while looking for matching '}'",0,0);return{part:T.parameterExpansion(o,u),endIndex:s+1}}function gi(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 S=yn(e,t,i),y=t.slice(i,S),g=e.withDepth(()=>Ut(e,y,!1,!1,!0,!1,s,!1,!1,!0)),b=T.word(ar(g));if(l==="-")return{operation:{type:"DefaultValue",word:b,checkEmpty:!0},endIndex:S};if(l==="=")return{operation:{type:"AssignDefault",word:b,checkEmpty:!0},endIndex:S};if(l==="?")return{operation:{type:"ErrorIfUnset",word:b,checkEmpty:!0},endIndex:S};if(l==="+")return{operation:{type:"UseAlternative",word:b,checkEmpty:!0},endIndex:S}}i++;let u=yn(e,t,i),c=t.slice(i,u),f=-1,d=0,p=0;for(let E=0;E<c.length;E++){let S=c[E];if(S==="("||S==="[")d++;else if(S===")"||S==="]")d--;else if(S==="?"&&d===0)p++;else if(S===":"&&d===0)if(p>0)p--;else{f=E;break}}let h=f>=0?c.slice(0,f):c,m=f>=0?c.slice(f+1):null;return{operation:{type:"Substring",offset:si(e,h),length:m!==null?si(e,m):null},endIndex:u}}if("-=?+".includes(a)){i++;let l=yn(e,t,i),u=t.slice(i,l),c=e.withDepth(()=>Ut(e,u,!1,!1,!0,!1,s,!1,!1,!0)),f=T.word(ar(c));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:u?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,u=a==="#"?"prefix":"suffix";i+=l?2:1;let c=yn(e,t,i),f=t.slice(i,c),d=e.withDepth(()=>Ut(e,f,!1,!1,!1));return{operation:{type:"PatternRemoval",pattern:T.word(ar(d)),side:u,greedy:l},endIndex:c}}if(a==="/"){let l=o==="/";i+=l?2:1;let u=null;t[i]==="#"?(u="start",i++):t[i]==="%"&&(u="end",i++);let c;u!==null&&(t[i]==="/"||t[i]==="}")?c=i:c=il(e,t,i);let f=t.slice(i,c),d=e.withDepth(()=>Ut(e,f,!1,!1,!1)),p=T.word(ar(d)),h=null,m=c;if(t[c]==="/"){let E=c+1,S=yn(e,t,E),y=t.slice(E,S),g=e.withDepth(()=>Ut(e,y,!1,!1,!1));h=T.word(ar(g)),m=S}return{operation:{type:"PatternReplacement",pattern:p,replacement:h,all:l,anchor:u},endIndex:m}}if(a==="^"||a===","){let l=o===a,u=a==="^"?"upper":"lower";i+=l?2:1;let c=yn(e,t,i),f=t.slice(i,c),d=f?T.word([T.literal(f)]):null;return{operation:{type:"CaseModification",direction:u,all:l,pattern:d},endIndex:c}}return a==="@"&&/[QPaAEKkuUL]/.test(o)?{operation:{type:"Transform",operator:o},endIndex:i+2}:{operation:null,endIndex:i}}function wi(e,t,n,r=!1){let s=n+1;if(s>=t.length)return{part:T.literal("$"),endIndex:s};let i=t[s];if(i==="("&&t[s+1]==="(")return e.isDollarDparenSubshell(t,n)?e.parseCommandSubstitution(t,n):e.parseArithmeticExpansion(t,n);if(i==="["){let 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),u=te(e,l);return{part:T.arithmeticExpansion(u),endIndex:o+1}}}return i==="("?e.parseCommandSubstitution(t,n):i==="{"?Cd(e,t,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?Pd(e,t,n):{part:T.literal("$"),endIndex:s}}function hl(e,t){let n=[],r=0,s="",i=()=>{s&&(n.push(T.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}=wi(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 Nd(e,t,n){let r=[],s=n,i="",a=()=>{i&&(r.push(T.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:u}=wi(e,t,s,!0);l&&r.push(l),s=u;continue}if(o==="`"){a();let{part:l,endIndex:u}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=u;continue}i+=o,s++}return a(),{part:T.doubleQuoted(r),endIndex:s}}function Ut(e,t,n=!1,r=!1,s=!1,i=!1,a=!1,o=!1,l=!1,u=!1,c=!0){if(r)return[T.singleQuoted(t)];if(n){let m=hl(e,t);return[T.doubleQuoted(m)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let m=t.slice(1,-1),E=!1;for(let S=0;S<m.length;S++){if(m[S]==='"'){E=!0;break}m[S]==="\\"&&S+1<m.length&&S++}if(!E){let S=hl(e,m);return[T.doubleQuoted(S)]}}let f=[],d=0,p="",h=()=>{p&&(f.push(T.literal(p)),p="")};for(;d<t.length;){let m=t[d];if(m==="\\"&&d+1<t.length){let E=t[d+1];if(l){h(),f.push(T.escaped(E)),d+=2;continue}if(!i&&!a){E!==`
73
+ `&&(h(),f.push(T.escaped(E))),d+=2;continue}let S=i?E==="$"||E==="`"||E===`
71
74
  `:E==="$"||E==="`"||E==='"'||E==="'"||E===`
72
- `||u&&E==="}",g=a?"*?[]\\".includes(E):"*?[]\\(){}.^+".includes(E);b?E!==`
73
- `&&(p+=E):g?(h(),f.push(T.escaped(E))):p+=`\\${E}`,d+=2;continue}if(m==="'"&&!a&&!i){h();let E=t.indexOf("'",d+1);if(E===-1){p+=t.slice(d);break}f.push(T.singleQuoted(t.slice(d+1,E))),d=E+1;continue}if(m==='"'&&!i){h();let{part:E,endIndex:b}=bd(e,t,d+1);f.push(E),d=b+1;continue}if(m==="$"&&t[d+1]==="'"){h();let{part:E,endIndex:b}=Qo(e,t,d+2);f.push(E),d=b;continue}if(m==="$"){h();let{part:E,endIndex:b}=fi(e,t,d);E&&f.push(E),d=b;continue}if(m==="`"){h();let{part:E,endIndex:b}=e.parseBacktickSubstitution(t,d);f.push(E),d=b;continue}if((m==="<"||m===">")&&t[d+1]==="("&&!i&&!a){h();let{part:E,endIndex:b}=e.parseProcessSubstitutionFromString(t,d);f.push(E),d=b;continue}if(m==="~"){let E=d>0?t[d-1]:"";if(d===0&&c||E==="="||s&&E===":"){let g=Go(e,t,d),y=t[g];if(y===void 0||y==="/"||y===":"){h();let S=t.slice(d+1,g)||null;f.push({type:"TildeExpansion",user:S}),d=g;continue}}}if("@*+?!".includes(m)&&d+1<t.length&&t[d+1]==="("){let E=gd(t,d+1);if(E!==-1){h();let b=t.slice(d,E+1);f.push({type:"Glob",pattern:b}),d=E+1;continue}}if(m==="*"||m==="?"||m==="["){h();let{pattern:E,endIndex:b}=Ho(e,t,d);f.push({type:"Glob",pattern:l?yd(E):E}),d=b;continue}if(m==="{"&&!s&&!o&&!i){let E=Ko(e,t,d,Mt);if(E){h(),f.push(E.part),d=E.endIndex;continue}}p+=m,d++}return h(),f}var G=class e{tokens=[];pos=0;pendingHeredocs=[];parseBudget;ownsParseBudget;_input="";processLineState;constructor(t){this.parseBudget=t??new Cr,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>Zs)throw new $e(`Input too large: ${t.length} bytes exceeds limit of ${Zs}`,1,1);this._input=t,this.processLineState=void 0;let s=new Pr(t,n);if(this.tokens=s.tokenize(),this.tokens.length>Hn)throw new $e(`Too many tokens: ${this.tokens.length} exceeds limit of ${Hn}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseBudget.chargeTokens(this.tokens.length),this.parseScript()}finally{r?.()}}parseTokens(t){this.ownsParseBudget&&this.parseBudget.reset();let n=this.ownsParseBudget?void 0:this.enterDepth();try{return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.processLineState=void 0,this.parseBudget.chargeTokens(t.length),this.parseScript()}finally{n?.()}}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}getSourceLine(t=this.current()){let n=this.processLineState;return n?(n.currentPhysicalLine===void 0?n.currentPhysicalLine=t.line:t.line>n.currentPhysicalLine&&(n.currentPhysicalLine=t.line,n.currentLogicalLine+=1),n.currentLogicalLine):t.line}check(t,n,r,s,...i){let 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 $e(n||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let n=this.current();throw new $e(t,n.line,n.column,n)}skipNewlines(){for(;this.check(w.NEWLINE,w.COMMENT);)this.check(w.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(w.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(w.SEMICOLON,w.COMMENT)){this.advance();continue}if(t&&this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,n,r,s){this.pendingHeredocs.push({redirect:t,delimiter:n,stripTabs:r,quoted:s})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(w.HEREDOC_CONTENT)){let n=this.advance(),r;t.quoted?r=T.word([T.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),t.redirect.target=T.hereDoc(t.delimiter,r,t.stripTabs,t.quoted,n.heredocTerminated??!1)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(w.EOF,w.NEWLINE,w.SEMICOLON,w.AMP,w.AND_AND,w.OR_OR,w.RPAREN,w.RBRACE,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return this.isWord()||t===w.ASSIGNMENT_WORD||t===w.FD_VARIABLE||t===w.LPAREN||t===w.LBRACE||t===w.DPAREN_START||t===w.DBRACK_START||Xn(this)}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(w.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)");let s=this.checkUnexpectedToken();if(s){t.push(s),this.skipSeparators(!1);continue}let i=this.pos,a=this.parseStatement();a&&t.push(a),this.check(w.HEREDOC_CONTENT)&&this.processHeredocs(),this.skipSeparators(!1),this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(w.EOF)&&this.error(`syntax error near unexpected token \`${this.current().value}'`)}return T.script(t)}checkUnexpectedToken(){let t=this.current().type,n=this.current().value;if(this.currentTokenJoinsProcessSubstitution())return null;if((t===w.DO||t===w.DONE||t===w.THEN||t===w.ELSE||t===w.ELIF||t===w.FI||t===w.ESAC)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.RBRACE||t===w.RPAREN){let r=`syntax error near unexpected token \`${n}'`;return this.advance(),T.statement([T.pipeline([T.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:n})}return(t===w.DSEMI||t===w.SEMI_AND||t===w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`),(t===w.AMP||t===w.AND_AND||t===w.OR_OR||t===w.PIPE||t===w.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${n}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,n=[],r=[],s=!1,i=this.parsePipeline();for(n.push(i);this.check(w.AND_AND,w.OR_OR);){let l=this.advance();r.push(l.type===w.AND_AND?"&&":"||"),this.skipNewlines();let u=this.parsePipeline();n.push(u)}this.check(w.AMP)&&(this.advance(),s=!0);let a=this.pos>0?this.tokens[this.pos-1].end:t,o=this._input.slice(t,a);return T.statement(n,r,s,void 0,o)}parseTimePrefix(){if(!this.check(w.TIME)||this.currentTokenJoinsProcessSubstitution())return;this.advance();let t=!1;return this.check(w.WORD,w.NAME)&&this.current().value==="-p"&&(this.advance(),t=!0),t}parsePipeline(){let t=!1,n=!1,r=0;for(;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++;if(r===0){let l=this.parseTimePrefix();if(l!==void 0)for(t=!0,n=l;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++}let s=r%2===1,i=[],a=[],o=this.parseCommand();for(i.push(o);this.check(w.PIPE,w.PIPE_AMP);){let l=this.advance();this.skipNewlines(),a.push(l.type===w.PIPE_AMP);let u=this.parseCommand();i.push(u)}return T.pipeline(i,s,t,n,a.length>0?a:void 0)}parseCommand(){if(this.currentTokenJoinsProcessSubstitution())return ei(this);let t=this.current();switch(t.type){case w.IF:return ti(this);case w.FOR:return ni(this);case w.WHILE:return ri(this);case w.UNTIL:return si(this);case w.CASE:return ii(this);case w.LPAREN:return ai(this);case w.LBRACE:return oi(this);case w.DPAREN_START:return this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand();case w.DBRACK_START:return this.parseConditionalCommand();case w.FUNCTION:return this.parseFunctionDef();case w.TIME:break;case w.BANG:this.error(`syntax error near unexpected token \`${t.value}'`);break;default:Gs(t.type)&&this.error(`syntax error near unexpected token \`${t.value}'`)}return this.check(w.NAME,w.WORD)&&this.peek(1).type===w.LPAREN&&this.peek(2).type===w.RPAREN?this.parseFunctionDef():ei(this)}dparenClosesWithSpacedParens(){let t=1,n=1;for(;n<this.tokens.length-this.pos;){let r=this.peek(n);if(r.type===w.EOF)return!1;if(r.type===w.DPAREN_START||r.type===w.LPAREN)t++;else if(r.type===w.DPAREN_END){if(t-=2,t<=0)return!1}else if(r.type===w.RPAREN&&(t--,t===0&&this.peek(n+1).type===w.RPAREN))return!0;n++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(w.RPAREN),this.expect(w.RPAREN);let n=this.parseOptionalRedirections(),r=T.subshell(t,[]);return T.subshell([T.statement([T.pipeline([r],!1,!1,!1)])],n)}isWord(){return this.isWordToken(Ce.Default)||this.isProcessSubstitutionStart()||this.currentTokenJoinsProcessSubstitution()}isWordToken(t){let n=this.current().type;return n===w.WORD||n===w.NAME||n===w.NUMBER||Gs(n)||n===w.BANG||n===w.ASSIGNMENT_WORD&&(t&Ce.Regex)!==0}isProcessSubstitutionStart(t=0){let n=this.peek(t),r=this.peek(t+1);return(n.type===w.LESS||n.type===w.GREAT)&&r.type===w.LPAREN&&n.end===r.start}currentTokenJoinsProcessSubstitution(){return this.current().type===w.COMMENT||!this.isAdjacentWordToken(Ce.Default)?!1:this.current().end===this.peek(1).start&&this.isProcessSubstitutionStart(1)}isAdjacentWordToken(t){let n=this.current().type;return this.isWordToken(t)||n===w.ASSIGNMENT_WORD||n===w.COMMENT||n===w.LBRACE||n===w.RBRACE||n===w.DBRACK_START||n===w.DBRACK_END||n===w.FD_VARIABLE}parseWord(t=Ce.Default){if(this.isProcessSubstitutionStart())return this.parseAdjacentWordParts([],this.current().start,t);let n=this.advance(),r=this.parseWordToken(n,t);return this.parseAdjacentWordParts(r.parts,n.end,t)}parseAdjacentWordParts(t,n,r=Ce.Default){for(;n===this.current().start;){if(this.isProcessSubstitutionStart()){t.push(this.parseProcessSubstitution()),n=this.tokens[this.pos-1].end;continue}if(!this.isAdjacentWordToken(r))break;let s=this.advance();t.push(...this.parseWordToken(s,r,t.length===0).parts),n=s.end}return T.word(t)}parseWordNoBraceExpansion(){return this.parseWord(Ce.NoBraceExpansion)}parseWordForRegex(){return this.parseWord(Ce.NoBraceExpansion|Ce.Regex)}parseWordToken(t,n,r=!0){return t.type===w.LBRACE||t.type===w.RBRACE||t.type===w.DBRACK_START||t.type===w.DBRACK_END||t.type===w.FD_VARIABLE?T.word([T.literal(t.type===w.FD_VARIABLE?`{${t.value}}`:t.value)]):this.parseWordFromString(t.value,t.quoted,t.singleQuoted,(n&Ce.Assignment)!==0,!1,(n&Ce.NoBraceExpansion)!==0,(n&Ce.Regex)!==0,r)}parseWordFromString(t,n=!1,r=!1,s=!1,i=!1,a=!1,o=!1,l=!0){let u=Mt(this,t,n,r,s,i,!1,a,o,!1,l);return T.word(u)}parseCommandSubstitution(t,n){return Ao(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitutionFromString(t,n){return vo(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitution(){let t=this.advance();this.expect(w.LPAREN);let n=this.processLineState,r=this.getSourceLine(t);this.processLineState={currentLogicalLine:r};let s;try{s=T.script(this.parseCompoundList())}finally{this.processLineState=n}return this.check(w.EOF)&&this.error("unexpected EOF while looking for matching `)'"),this.expect(w.RPAREN),T.processSubstitution(s,t.type===w.LESS?"input":"output")}parseBacktickSubstitution(t,n,r=!1){return $o(t,n,r,()=>new e(this.parseBudget),s=>this.error(s))}isDollarDparenSubshell(t,n){return bo(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:T.arithmeticExpansion(l),endIndex:a+2}}parseArithmeticCommand(){let t=this.expect(w.DPAREN_START),n="",r=1,s=0,i=!1,a=!1;for(;r>0&&!this.check(w.EOF);){if(i){if(i=!1,s>0){s--,n+=")";continue}if(this.check(w.RPAREN)){r--,a=!0,this.advance();continue}if(this.check(w.DPAREN_END)){r--,a=!0;continue}n+=")";continue}if(this.check(w.DPAREN_START))r++,n+="((",this.advance();else if(this.check(w.DPAREN_END))s>=2?(s-=2,n+="))",this.advance()):s===1?(s--,n+=")",i=!0,this.advance()):(r--,a=!0,r>0&&(n+="))"),this.advance());else if(this.check(w.LPAREN))s++,n+="(",this.advance();else if(this.check(w.RPAREN))s>0&&s--,n+=")",this.advance();else{let u=this.current().value,c=n.length>0?n[n.length-1]:"";n.length>0&&!n.endsWith(" ")&&!(u==="="&&/[|&^+\-*/%<>]$/.test(n))&&!(u==="<"&&c==="<")&&!(u===">"&&c===">")&&(n+=" "),n+=u,this.advance()}}a||this.expect(w.DPAREN_END);let o=this.parseArithmeticExpression(n.trim()),l=this.parseOptionalRedirections();return T.arithmeticCommand(o,l,this.getSourceLine(t))}parseConditionalCommand(){let t=this.expect(w.DBRACK_START),n=ui(this);this.expect(w.DBRACK_END);let r=this.parseOptionalRedirections();return T.conditionalCommand(n,r,this.getSourceLine(t))}parseFunctionDef(){let t;if(this.check(w.FUNCTION)){if(this.advance(),this.check(w.NAME)||this.check(w.WORD))t=this.advance().value;else{let s=this.current();throw new $e("Expected function name",s.line,s.column,s)}this.check(w.LPAREN)&&(this.advance(),this.expect(w.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(w.LPAREN),this.expect(w.RPAREN);this.skipNewlines();let n=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return T.functionDef(t,n,r)}parseCompoundCommandBody(t){let n=t?.forFunctionBody;if(this.check(w.LBRACE))return oi(this,{skipRedirections:n});if(this.check(w.LPAREN))return ai(this,{skipRedirections:n});if(this.check(w.IF))return ti(this,{skipRedirections:n});if(this.check(w.FOR))return ni(this,{skipRedirections:n});if(this.check(w.WHILE))return ri(this,{skipRedirections:n});if(this.check(w.UNTIL))return si(this,{skipRedirections:n});if(this.check(w.CASE))return ii(this,{skipRedirections:n});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth();try{let n=[];for(this.skipNewlines();(this.currentTokenJoinsProcessSubstitution()||!this.check(w.EOF,w.FI,w.ELSE,w.ELIF,w.THEN,w.DO,w.DONE,w.ESAC,w.RPAREN,w.RBRACE,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND))&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,s=this.parseStatement();if(s&&n.push(s),this.skipSeparators(),this.pos===r&&!s)break}return n}finally{t()}}parseOptionalRedirections(){let t=[];for(;Xn(this);){this.checkIterationLimit();let n=this.pos;if(t.push(Ir(this)),this.pos===n)break}return t}parseArithmeticExpression(t){return te(this,t)}};function lt(e,t){return new G().parse(e,t)}function rl(e){return un(e)}function un(e){return e.statements.map(sl).join(`
74
- `)}function sl(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(Ad(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let n=t.join(" ");return e.background&&(n+=" &"),n}function Ad(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(il(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 il(e){switch(e.type){case"SimpleCommand":return vd(e);case"If":return Id(e);case"For":return Od(e);case"CStyleFor":return _d(e);case"While":return Ld(e);case"Until":return Td(e);case"Case":return Md(e);case"Subshell":return Bd(e);case"Group":return Wd(e);case"ArithmeticCommand":return Vd(e);case"ConditionalCommand":return zd(e);case"FunctionDef":return qd(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function vd(e){let t=[];for(let n of e.assignments)t.push($d(n));e.name&&t.push(Se(e.name));for(let n of e.args)t.push(Se(n));for(let n of e.redirections)t.push(ll(n));return t.join(" ")}function $d(e){let t=e.append?"+=":"=";if(e.array){let n=e.array.map(Se).join(" ");return`${e.name}${t}(${n})`}return e.value?`${e.name}${t}${Se(e.value)}`:`${e.name}${t}`}function Se(e){return e.parts.map(t=>Or(t,!1)).join("")}function Ft(e){return e.parts.map(t=>Or(t,!0)).join("")}function Or(e,t){switch(e.type){case"Literal":return t?kd(e.value):xd(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(n=>Or(n,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return al(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 Rd(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 xd(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function kd(e){return e.replace(/[$`"\\]/g,"\\$&")}function Pd(e,t){return e.parts.map(n=>Cd(n,t)).join("")}function Cd(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return al(e);case"CommandSubstitution":return e.legacy?`\`${un(e.body)}\``:`$(${un(e.body)})`;case"ArithmeticExpansion":return`$((${fe(e.expression.expression)}))`;default:return Or(e,!1)}}function al(e){return e.operation?`\${${ol(e.parameter,e.operation)}}`:Nd(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function Nd(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function ol(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${Ft(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${Ft(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?Ft(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${Ft(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}${Ft(t.pattern)}`}case"PatternReplacement":{let n="/";t.all?n="//":t.anchor==="start"?n="/#":t.anchor==="end"&&(n="/%");let r=t.replacement?`/${Ft(t.replacement)}`:"";return`${e}${n}${Ft(t.pattern)}${r}`}case"CaseModification":{let n=t.direction==="upper"?"^":",",r=t.all?`${n}${n}`:n,s=t.pattern?Ft(t.pattern):"";return`${e}${r}${s}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${ol(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 Rd(e){return`{${e.items.map(Dd).join(",")}}`}function Dd(e){if(e.type==="Word")return Se(e.word);let t=e.startStr??String(e.start),n=e.endStr??String(e.end);return e.step!==void 0?`${t}..${n}..${e.step}`:`${t}..${n}`}function ll(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let n=e.target;if(n.terminated===!1)throw new Error("Cannot serialize an unterminated here-document");let r=n.quoted?`'${n.delimiter}'`:n.delimiter,s=Pd(n.content,n.quoted);return`${t}${e.operator}${r}
75
- ${s}${n.delimiter}`}return e.operator==="<<<"?`${t}<<< ${Se(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${Se(e.target)}`:`${t}${e.operator} ${Se(e.target)}`}function ut(e){return e.length===0?"":` ${e.map(ll).join(" ")}`}function rt(e){return e.map(sl).join(`
76
- `)}function Id(e){let t=[];for(let n=0;n<e.clauses.length;n++){let r=e.clauses[n],s=n===0?"if":"elif";t.push(`${s} ${rt(r.condition)}; then
77
- ${rt(r.body)}`)}return e.elseBody&&t.push(`else
78
- ${rt(e.elseBody)}`),`${t.join(`
75
+ `||u&&E==="}",y=a?"*?[]\\".includes(E):"*?[]\\(){}.^+".includes(E);S?E!==`
76
+ `&&(p+=E):y?(h(),f.push(T.escaped(E))):p+=`\\${E}`,d+=2;continue}if(m==="'"&&!a&&!i){h();let E=t.indexOf("'",d+1);if(E===-1){p+=t.slice(d);break}f.push(T.singleQuoted(t.slice(d+1,E))),d=E+1;continue}if(m==='"'&&!i){h();let{part:E,endIndex:S}=Nd(e,t,d+1);f.push(E),d=S+1;continue}if(m==="$"&&t[d+1]==="'"){h();let{part:E,endIndex:S}=ol(e,t,d+2);f.push(E),d=S;continue}if(m==="$"){h();let{part:E,endIndex:S}=wi(e,t,d);E&&f.push(E),d=S;continue}if(m==="`"){h();let{part:E,endIndex:S}=e.parseBacktickSubstitution(t,d);f.push(E),d=S;continue}if((m==="<"||m===">")&&t[d+1]==="("&&!i&&!a){h();let{part:E,endIndex:S}=e.parseProcessSubstitutionFromString(t,d);f.push(E),d=S;continue}if(m==="~"){let E=d>0?t[d-1]:"";if(d===0&&c||E==="="||s&&E===":"){let y=sl(e,t,d),g=t[y];if(g===void 0||g==="/"||g===":"){h();let b=t.slice(d+1,y)||null;f.push({type:"TildeExpansion",user:b}),d=y;continue}}}if("@*+?!".includes(m)&&d+1<t.length&&t[d+1]==="("){let E=kd(t,d+1);if(E!==-1){h();let S=t.slice(d,E+1);f.push({type:"Glob",pattern:S}),d=E+1;continue}}if(m==="*"||m==="?"||m==="["){h();let{pattern:E,endIndex:S}=al(e,t,d);f.push({type:"Glob",pattern:l?xd(E):E}),d=S;continue}if(m==="{"&&!s&&!o&&!i){let E=ll(e,t,d,Ut);if(E){h(),f.push(E.part),d=E.endIndex;continue}}p+=m,d++}return h(),f}var j=class e{tokens=[];pos=0;pendingHeredocs=[];parseBudget;ownsParseBudget;_input="";processLineState;constructor(t){this.parseBudget=t??new Lr,this.ownsParseBudget=t===void 0}getInput(){return this._input}checkIterationLimit(){let t=this.current();this.parseBudget.chargeIteration(t?.line??1,t?.column??1)}enterDepth(){let t=this.current();return this.parseBudget.enter(t?.line??1,t?.column??1)}withDepth(t){let n=this.enterDepth();try{return t()}finally{n()}}parse(t,n){this.ownsParseBudget&&this.parseBudget.reset();let r=this.ownsParseBudget?void 0:this.enterDepth();try{if(t.length>ei)throw new $e(`Input too large: ${t.length} bytes exceeds limit of ${ei}`,1,1);this._input=t,this.processLineState=void 0;let s=new _r(t,n);if(this.tokens=s.tokenize(),this.tokens.length>nr)throw new $e(`Too many tokens: ${this.tokens.length} exceeds limit of ${nr}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseBudget.chargeTokens(this.tokens.length),this.parseScript()}finally{r?.()}}parseTokens(t){this.ownsParseBudget&&this.parseBudget.reset();let n=this.ownsParseBudget?void 0:this.enterDepth();try{return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.processLineState=void 0,this.parseBudget.chargeTokens(t.length),this.parseScript()}finally{n?.()}}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}getSourceLine(t=this.current()){let n=this.processLineState;return n?(n.currentPhysicalLine===void 0?n.currentPhysicalLine=t.line:t.line>n.currentPhysicalLine&&(n.currentPhysicalLine=t.line,n.currentLogicalLine+=1),n.currentLogicalLine):t.line}check(t,n,r,s,...i){let 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 $e(n||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let n=this.current();throw new $e(t,n.line,n.column,n)}skipNewlines(){for(;this.check(w.NEWLINE,w.COMMENT);)this.check(w.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(w.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(w.SEMICOLON,w.COMMENT)){this.advance();continue}if(t&&this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,n,r,s){this.pendingHeredocs.push({redirect:t,delimiter:n,stripTabs:r,quoted:s})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(w.HEREDOC_CONTENT)){let n=this.advance(),r;t.quoted?r=T.word([T.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),t.redirect.target=T.hereDoc(t.delimiter,r,t.stripTabs,t.quoted,n.heredocTerminated??!1)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(w.EOF,w.NEWLINE,w.SEMICOLON,w.AMP,w.AND_AND,w.OR_OR,w.RPAREN,w.RBRACE,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return this.isWord()||t===w.ASSIGNMENT_WORD||t===w.FD_VARIABLE||t===w.LPAREN||t===w.LBRACE||t===w.DPAREN_START||t===w.DBRACK_START||ir(this)}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(w.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)");let s=this.checkUnexpectedToken();if(s){t.push(s),this.skipSeparators(!1);continue}let i=this.pos,a=this.parseStatement();a&&t.push(a),this.check(w.HEREDOC_CONTENT)&&this.processHeredocs(),this.skipSeparators(!1),this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(w.EOF)&&this.error(`syntax error near unexpected token \`${this.current().value}'`)}return T.script(t)}checkUnexpectedToken(){let t=this.current().type,n=this.current().value;if(this.currentTokenJoinsProcessSubstitution())return null;if((t===w.DO||t===w.DONE||t===w.THEN||t===w.ELSE||t===w.ELIF||t===w.FI||t===w.ESAC)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.RBRACE||t===w.RPAREN){let r=`syntax error near unexpected token \`${n}'`;return this.advance(),T.statement([T.pipeline([T.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:n})}return(t===w.DSEMI||t===w.SEMI_AND||t===w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`),(t===w.AMP||t===w.AND_AND||t===w.OR_OR||t===w.PIPE||t===w.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${n}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,n=[],r=[],s=!1,i=this.parsePipeline();for(n.push(i);this.check(w.AND_AND,w.OR_OR);){let l=this.advance();r.push(l.type===w.AND_AND?"&&":"||"),this.skipNewlines();let u=this.parsePipeline();n.push(u)}this.check(w.AMP)&&(this.advance(),s=!0);let a=this.pos>0?this.tokens[this.pos-1].end:t,o=this._input.slice(t,a);return T.statement(n,r,s,void 0,o)}parseTimePrefix(){if(!this.check(w.TIME)||this.currentTokenJoinsProcessSubstitution())return;this.advance();let t=!1;return this.check(w.WORD,w.NAME)&&this.current().value==="-p"&&(this.advance(),t=!0),t}parsePipeline(){let t=!1,n=!1,r=0;for(;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++;if(r===0){let l=this.parseTimePrefix();if(l!==void 0)for(t=!0,n=l;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++}let s=r%2===1,i=[],a=[],o=this.parseCommand();for(i.push(o);this.check(w.PIPE,w.PIPE_AMP);){let l=this.advance();this.skipNewlines(),a.push(l.type===w.PIPE_AMP);let u=this.parseCommand();i.push(u)}return T.pipeline(i,s,t,n,a.length>0?a:void 0)}parseCommand(){if(this.currentTokenJoinsProcessSubstitution())return oi(this);let t=this.current();switch(t.type){case w.IF:return li(this);case w.FOR:return ui(this);case w.WHILE:return ci(this);case w.UNTIL:return fi(this);case w.CASE:return di(this);case w.LPAREN:return pi(this);case w.LBRACE:return hi(this);case w.DPAREN_START:return this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand();case w.DBRACK_START:return this.parseConditionalCommand();case w.FUNCTION:return this.parseFunctionDef();case w.TIME:break;case w.BANG:this.error(`syntax error near unexpected token \`${t.value}'`);break;default:Js(t.type)&&this.error(`syntax error near unexpected token \`${t.value}'`)}return this.check(w.NAME,w.WORD)&&this.peek(1).type===w.LPAREN&&this.peek(2).type===w.RPAREN?this.parseFunctionDef():oi(this)}dparenClosesWithSpacedParens(){let t=1,n=1;for(;n<this.tokens.length-this.pos;){let r=this.peek(n);if(r.type===w.EOF)return!1;if(r.type===w.DPAREN_START||r.type===w.LPAREN)t++;else if(r.type===w.DPAREN_END){if(t-=2,t<=0)return!1}else if(r.type===w.RPAREN&&(t--,t===0&&this.peek(n+1).type===w.RPAREN))return!0;n++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(w.RPAREN),this.expect(w.RPAREN);let n=this.parseOptionalRedirections(),r=T.subshell(t,[]);return T.subshell([T.statement([T.pipeline([r],!1,!1,!1)])],n)}isWord(){return this.isWordToken(Ce.Default)||this.isProcessSubstitutionStart()||this.currentTokenJoinsProcessSubstitution()}isWordToken(t){let n=this.current().type;return n===w.WORD||n===w.NAME||n===w.NUMBER||Js(n)||n===w.BANG||n===w.ASSIGNMENT_WORD&&(t&Ce.Regex)!==0}isProcessSubstitutionStart(t=0){let n=this.peek(t),r=this.peek(t+1);return(n.type===w.LESS||n.type===w.GREAT)&&r.type===w.LPAREN&&n.end===r.start}currentTokenJoinsProcessSubstitution(){return this.current().type===w.COMMENT||!this.isAdjacentWordToken(Ce.Default)?!1:this.current().end===this.peek(1).start&&this.isProcessSubstitutionStart(1)}isAdjacentWordToken(t){let n=this.current().type;return this.isWordToken(t)||n===w.ASSIGNMENT_WORD||n===w.COMMENT||n===w.LBRACE||n===w.RBRACE||n===w.DBRACK_START||n===w.DBRACK_END||n===w.FD_VARIABLE}parseWord(t=Ce.Default){if(this.isProcessSubstitutionStart())return this.parseAdjacentWordParts([],this.current().start,t);let n=this.advance(),r=this.parseWordToken(n,t);return this.parseAdjacentWordParts(r.parts,n.end,t)}parseAdjacentWordParts(t,n,r=Ce.Default){for(;n===this.current().start;){if(this.isProcessSubstitutionStart()){t.push(this.parseProcessSubstitution()),n=this.tokens[this.pos-1].end;continue}if(!this.isAdjacentWordToken(r))break;let s=this.advance();t.push(...this.parseWordToken(s,r,t.length===0).parts),n=s.end}return T.word(t)}parseWordNoBraceExpansion(){return this.parseWord(Ce.NoBraceExpansion)}parseWordForRegex(){return this.parseWord(Ce.NoBraceExpansion|Ce.Regex)}parseWordToken(t,n,r=!0){return t.type===w.LBRACE||t.type===w.RBRACE||t.type===w.DBRACK_START||t.type===w.DBRACK_END||t.type===w.FD_VARIABLE?T.word([T.literal(t.type===w.FD_VARIABLE?`{${t.value}}`:t.value)]):this.parseWordFromString(t.value,t.quoted,t.singleQuoted,(n&Ce.Assignment)!==0,!1,(n&Ce.NoBraceExpansion)!==0,(n&Ce.Regex)!==0,r)}parseWordFromString(t,n=!1,r=!1,s=!1,i=!1,a=!1,o=!1,l=!0){let u=Ut(this,t,n,r,s,i,!1,a,o,!1,l);return T.word(u)}parseCommandSubstitution(t,n){return _o(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitutionFromString(t,n){return Lo(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitution(){let t=this.advance();this.expect(w.LPAREN);let n=this.processLineState,r=this.getSourceLine(t);this.processLineState={currentLogicalLine:r};let s;try{s=T.script(this.parseCompoundList())}finally{this.processLineState=n}return this.check(w.EOF)&&this.error("unexpected EOF while looking for matching `)'"),this.expect(w.RPAREN),T.processSubstitution(s,t.type===w.LESS?"input":"output")}parseBacktickSubstitution(t,n,r=!1){return To(t,n,r,()=>new e(this.parseBudget),s=>this.error(s))}isDollarDparenSubshell(t,n){return Io(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:T.arithmeticExpansion(l),endIndex:a+2}}parseArithmeticCommand(){let t=this.expect(w.DPAREN_START),n="",r=1,s=0,i=!1,a=!1;for(;r>0&&!this.check(w.EOF);){if(i){if(i=!1,s>0){s--,n+=")";continue}if(this.check(w.RPAREN)){r--,a=!0,this.advance();continue}if(this.check(w.DPAREN_END)){r--,a=!0;continue}n+=")";continue}if(this.check(w.DPAREN_START))r++,n+="((",this.advance();else if(this.check(w.DPAREN_END))s>=2?(s-=2,n+="))",this.advance()):s===1?(s--,n+=")",i=!0,this.advance()):(r--,a=!0,r>0&&(n+="))"),this.advance());else if(this.check(w.LPAREN))s++,n+="(",this.advance();else if(this.check(w.RPAREN))s>0&&s--,n+=")",this.advance();else{let u=this.current().value,c=n.length>0?n[n.length-1]:"";n.length>0&&!n.endsWith(" ")&&!(u==="="&&/[|&^+\-*/%<>]$/.test(n))&&!(u==="<"&&c==="<")&&!(u===">"&&c===">")&&(n+=" "),n+=u,this.advance()}}a||this.expect(w.DPAREN_END);let o=this.parseArithmeticExpression(n.trim()),l=this.parseOptionalRedirections();return T.arithmeticCommand(o,l,this.getSourceLine(t))}parseConditionalCommand(){let t=this.expect(w.DBRACK_START),n=yi(this);this.expect(w.DBRACK_END);let r=this.parseOptionalRedirections();return T.conditionalCommand(n,r,this.getSourceLine(t))}parseFunctionDef(){let t;if(this.check(w.FUNCTION)){if(this.advance(),this.check(w.NAME)||this.check(w.WORD))t=this.advance().value;else{let s=this.current();throw new $e("Expected function name",s.line,s.column,s)}this.check(w.LPAREN)&&(this.advance(),this.expect(w.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(w.LPAREN),this.expect(w.RPAREN);this.skipNewlines();let n=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return T.functionDef(t,n,r)}parseCompoundCommandBody(t){let n=t?.forFunctionBody;if(this.check(w.LBRACE))return hi(this,{skipRedirections:n});if(this.check(w.LPAREN))return pi(this,{skipRedirections:n});if(this.check(w.IF))return li(this,{skipRedirections:n});if(this.check(w.FOR))return ui(this,{skipRedirections:n});if(this.check(w.WHILE))return ci(this,{skipRedirections:n});if(this.check(w.UNTIL))return fi(this,{skipRedirections:n});if(this.check(w.CASE))return di(this,{skipRedirections:n});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth();try{let n=[];for(this.skipNewlines();(this.currentTokenJoinsProcessSubstitution()||!this.check(w.EOF,w.FI,w.ELSE,w.ELIF,w.THEN,w.DO,w.DONE,w.ESAC,w.RPAREN,w.RBRACE,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND))&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,s=this.parseStatement();if(s&&n.push(s),this.skipSeparators(),this.pos===r&&!s)break}return n}finally{t()}}parseOptionalRedirections(){let t=[];for(;ir(this);){this.checkIterationLimit();let n=this.pos;if(t.push(Br(this)),this.pos===n)break}return t}parseArithmeticExpression(t){return te(this,t)}};function pt(e,t){return new j().parse(e,t)}function ml(e){return wn(e)}function wn(e){return e.statements.map(yl).join(`
77
+ `)}function yl(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(Dd(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let n=t.join(" ");return e.background&&(n+=" &"),n}function Dd(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(gl(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 gl(e){switch(e.type){case"SimpleCommand":return Id(e);case"If":return Vd(e);case"For":return zd(e);case"CStyleFor":return qd(e);case"While":return Ud(e);case"Until":return jd(e);case"Case":return Gd(e);case"Subshell":return Zd(e);case"Group":return Qd(e);case"ArithmeticCommand":return Kd(e);case"ConditionalCommand":return Xd(e);case"FunctionDef":return Yd(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function Id(e){let t=[];for(let n of e.assignments)t.push(Od(n));e.name&&t.push(Se(e.name));for(let n of e.args)t.push(Se(n));for(let n of e.redirections)t.push(bl(n));return t.join(" ")}function Od(e){let t=e.append?"+=":"=";if(e.array){let n=e.array.map(Se).join(" ");return`${e.name}${t}(${n})`}return e.value?`${e.name}${t}${Se(e.value)}`:`${e.name}${t}`}function Se(e){return e.parts.map(t=>Wr(t,!1)).join("")}function jt(e){return e.parts.map(t=>Wr(t,!0)).join("")}function Wr(e,t){switch(e.type){case"Literal":return t?Ld(e.value):_d(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(n=>Wr(n,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return wl(e);case"CommandSubstitution":return e.legacy?`\`${wn(e.body)}\``:`$(${wn(e.body)})`;case"ArithmeticExpansion":return`$((${fe(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${wn(e.body)})`:`>(${wn(e.body)})`;case"BraceExpansion":return Bd(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 _d(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function Ld(e){return e.replace(/[$`"\\]/g,"\\$&")}function Td(e,t){return e.parts.map(n=>Md(n,t)).join("")}function Md(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return wl(e);case"CommandSubstitution":return e.legacy?`\`${wn(e.body)}\``:`$(${wn(e.body)})`;case"ArithmeticExpansion":return`$((${fe(e.expression.expression)}))`;default:return Wr(e,!1)}}function wl(e){return e.operation?`\${${El(e.parameter,e.operation)}}`:Fd(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function Fd(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function El(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?`!${El(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 Bd(e){return`{${e.items.map(Wd).join(",")}}`}function Wd(e){if(e.type==="Word")return Se(e.word);let t=e.startStr??String(e.start),n=e.endStr??String(e.end);return e.step!==void 0?`${t}..${n}..${e.step}`:`${t}..${n}`}function bl(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let n=e.target;if(n.terminated===!1)throw new Error("Cannot serialize an unterminated here-document");let r=n.quoted?`'${n.delimiter}'`:n.delimiter,s=Td(n.content,n.quoted);return`${t}${e.operator}${r}
78
+ ${s}${n.delimiter}`}return e.operator==="<<<"?`${t}<<< ${Se(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${Se(e.target)}`:`${t}${e.operator} ${Se(e.target)}`}function ht(e){return e.length===0?"":` ${e.map(bl).join(" ")}`}function it(e){return e.map(yl).join(`
79
+ `)}function Vd(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} ${it(r.condition)}; then
80
+ ${it(r.body)}`)}return e.elseBody&&t.push(`else
81
+ ${it(e.elseBody)}`),`${t.join(`
79
82
  `)}
80
- fi${ut(e.redirections)}`}function Od(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let n=e.words.map(Se).join(" ");t=`for ${e.variable} in ${n}`}return`${t}; do
81
- ${rt(e.body)}
82
- done${ut(e.redirections)}`}function _d(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
83
- ${rt(e.body)}
84
- done${ut(e.redirections)}`}function Ld(e){return`while ${rt(e.condition)}; do
85
- ${rt(e.body)}
86
- done${ut(e.redirections)}`}function Td(e){return`until ${rt(e.condition)}; do
87
- ${rt(e.body)}
88
- done${ut(e.redirections)}`}function Md(e){let t=e.items.map(Fd).join(`
83
+ fi${ht(e.redirections)}`}function zd(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let n=e.words.map(Se).join(" ");t=`for ${e.variable} in ${n}`}return`${t}; do
84
+ ${it(e.body)}
85
+ done${ht(e.redirections)}`}function qd(e){let t=e.init?fe(e.init.expression):"",n=e.condition?fe(e.condition.expression):"",r=e.update?fe(e.update.expression):"";return`for ((${t}; ${n}; ${r})); do
86
+ ${it(e.body)}
87
+ done${ht(e.redirections)}`}function Ud(e){return`while ${it(e.condition)}; do
88
+ ${it(e.body)}
89
+ done${ht(e.redirections)}`}function jd(e){return`until ${it(e.condition)}; do
90
+ ${it(e.body)}
91
+ done${ht(e.redirections)}`}function Gd(e){let t=e.items.map(Hd).join(`
89
92
  `);return`case ${Se(e.word)} in
90
93
  ${t}
91
- esac${ut(e.redirections)}`}function Fd(e){let t=e.patterns.map(Se).join(" | "),n=rt(e.body);return n?`${t})
94
+ esac${ht(e.redirections)}`}function Hd(e){let t=e.patterns.map(Se).join(" | "),n=it(e.body);return n?`${t})
92
95
  ${n}
93
96
  ${e.terminator}`:`${t})
94
- ${e.terminator}`}function Bd(e){return`(${rt(e.body)})${ut(e.redirections)}`}function Wd(e){return`{ ${rt(e.body)}; }${ut(e.redirections)}`}function Vd(e){return`((${fe(e.expression.expression)}))${ut(e.redirections)}`}function zd(e){return`[[ ${ln(e.expression)} ]]${ut(e.redirections)}`}function qd(e){let t=il(e.body);return`${e.name}() ${t}${ut(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 ln(e){switch(e.type){case"CondBinary":return`${Se(e.left)} ${e.operator} ${Se(e.right)}`;case"CondUnary":return`${e.operator} ${Se(e.operand)}`;case"CondNot":return`! ${ln(e.operand)}`;case"CondAnd":return`${ln(e.left)} && ${ln(e.right)}`;case"CondOr":return`${ln(e.left)} || ${ln(e.right)}`;case"CondGroup":return`( ${ln(e.expression)} )`;case"CondWord":return Se(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var Ud="BASH_ALIAS_";function _r(e,t,n,r){let s=F(t);if(s>n-r.value)throw new k(`alias expansion exceeds string length limit (${n} bytes)`,"string_length");return r.value+=s,e+t}function ul(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function cl(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function fl(e,t){return e.env.get(`${Ud}${t}`)}function pl(e,t,n){return hl(e,t,n)}function hl(e,t,n,r=!0){if(!t.name||!ul(t.name))return t;let s=cl(t.name);if(!s)return t;let i=fl(e,s);if(!i||n.has(s))return t;try{n.add(s);let a=new G,o={value:0},l=_r("",i,e.limits.maxStringLength,o),u=i.endsWith(" ");if(!u)for(let p of t.args){let h=Se(p);l=_r(l,` ${h}`,e.limits.maxStringLength,o)}let c;try{c=a.parse(l)}catch(p){if(p instanceof $e)throw p;return t}if(c.statements.length!==1||c.statements[0].pipelines.length!==1||c.statements[0].pipelines[0].commands.length!==1)return dl(e,t,i);let f=c.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return dl(e,t,i);let d={...f,assignments:[...t.assignments,...f.assignments],redirections:[...f.redirections,...t.redirections],line:t.line};if(u&&t.args.length>0){d={...d,args:[...d.args,...t.args]};let p=1;for(;r&&d.args.length>0;){let h=d.args[0];if(!ul(h))break;let m=cl(h),E=m?fl(e,m):null;if(!E)break;if(p>=e.limits.maxCallDepth)throw new k(`alias expansion depth limit exceeded (${e.limits.maxCallDepth})`,"recursion");p++;let b={type:"SimpleCommand",name:h,args:d.args.slice(1),assignments:[],redirections:[]},g=hl(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 dl(e,t,n){let r={value:0},s=_r("",n,e.limits.maxStringLength,r);for(let u of t.args){let c=Se(u);s=_r(s,` ${c}`,e.limits.maxStringLength,r)}let i=new G,a=i.parseWordFromString("eval",!1,!1),o=0;for(let u of s)u==="'"&&o++;if(r.value+2+o*3>e.limits.maxStringLength)throw new k(`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}}var jd=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 di(e){return jd.get(e)??""}function ml(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 yl(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 u=e.slice(s+2,l),c=di(u);i+=c,s=l+2;continue}}if(e[s]==="\\"&&s+1<e.length){i+=`\\${e[s+1]}`,s+=2;continue}if(e[s]==="-"){let l=s===o,u=s+1===a;l||u?i+="\\-":i+="-"}else i+=e[s];s++}i+="]",t+=i,n=s}else if(r==="\\"&&n+1<e.length){let s=e[n+1];/[.+^${}()|\\*?[\]]/.test(s)?t+=`\\${s}`:t+=s,n++}else/[.+^${}()|]/.test(r)?t+=`\\${r}`:t+=r}return t+="$",me(t)}function pi(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 hi(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 gl=5,Bt=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=ml(i))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new k(`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 yl(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>gl))throw new k(`Glob pattern has too many ** segments (max ${gl})`,"glob_operations")}let n;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))n=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");n=await this.expandSimple(r)}return this.filterGlobignore(n)}isGlobstarValid(t){let n=t.split("/");for(let r of n)if(r.includes("**")&&r!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let n=t.startsWith("/"),r=t.split("/").filter(u=>u!==""),s=-1;for(let u=0;u<r.length;u++)if(this.hasGlobChars(r[u])){s=u;break}if(s===-1)return[t];let i,a;if(s===0)n?(i="/",a="/"):(i=this.cwd,a="");else{let u=r.slice(0,s);n?(i=`/${u.join("/")}`,a=`/${u.join("/")}`):(i=this.fs.resolvePath(this.cwd,u.join("/")),a=u.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=[],u=[...o],c=this.dotglob||this.hasGlobignore;if(s.startsWith(".")||this.dotglob){let d=o.some(h=>h.name==="."),p=o.some(h=>h.name==="..");d||u.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),p||u.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of u)if(!(d.name.startsWith(".")&&!s.startsWith(".")&&!c)&&this.matchPattern(d.name,s)){let p=t==="/"?`/${d.name}`:`${t}/${d.name}`,h;n===""?h=d.name:n==="/"?h=`/${d.name}`:h=`${n}/${d.name}`,i.length===0?l.push(Promise.resolve([h])):d.isDirectory&&l.push(this.expandSegments(p,h,i))}let f=await Promise.all(l);for(let d of f)a.push(...d)}else{this.checkOpsLimit();let o=await this.fs.readdir(t),l=[],u=[...o],c=this.dotglob||this.hasGlobignore;(s.startsWith(".")||this.dotglob)&&(o.includes(".")||u.push("."),o.includes("..")||u.push(".."));for(let d of u)if(!(d.startsWith(".")&&!s.startsWith(".")&&!c)&&this.matchPattern(d,s)){let p=t==="/"?`/${d}`:`${t}/${d}`,h;n===""?h=d:n==="/"?h=`/${d}`:h=`${n}/${d}`,i.length===0?l.push(Promise.resolve([h])):l.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(p)).isDirectory)return this.expandSegments(p,h,i)}catch(m){if(m instanceof k)throw m}return[]})())}let f=await Promise.all(l);for(let d of f)a.push(...d)}}catch(o){if(o instanceof k)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 u of i){let c=t==="."?u.name:`${t}/${u.name}`;u.isDirectory&&a.push(c)}let o=t==="."?n:`${t}/${n}`,l=await this.expandRecursive(o);r.push(...l);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,n,r)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(s),o=[];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&&o.push(f)}catch(p){if(p instanceof k)throw p}}let l=t==="."?n:`${t}/${n}`,u=await this.expandRecursive(l);r.push(...u);for(let c=0;c<o.length;c+=100){let f=o.slice(c,c+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,n,r)))}}}catch(i){if(i instanceof k)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 u=t==="."?l.name:`${t}/${l.name}`;l.isDirectory?o.push(u):n&&this.matchPattern(l.name,n)&&a.push(u)}r.push(...a);for(let l=0;l<o.length;l+=100){let u=o.slice(l,l+100);await Promise.all(u.map(c=>this.walkDirectory(c,n,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(s),a=[];for(let l=0;l<i.length;l+=100){let u=i.slice(l,l+100),c=await Promise.all(u.map(async f=>{let d=t==="."?f:`${t}/${f}`,p=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let h=await this.fs.stat(p);return{name:f,path:d,isDirectory:h.isDirectory}}catch(h){if(h instanceof k)throw h;return null}}));a.push(...c.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 u=o.slice(l,l+100);await Promise.all(u.map(c=>this.walkDirectory(c.path,n,r)))}}}catch(i){if(i instanceof k)throw i}}matchPattern(t,n){return this.patternToRegex(n).test(t)}patternToRegex(t){let n=this.patternToRegexStr(t);return me(`^${n}$`)}patternToRegexStr(t){let n="",r=!1;for(let s=0;s<t.length;s++){if(t.slice(s,s+13)==="\0QUOTE_START\0"){r=!0,s+=12;continue}if(t.slice(s,s+11)==="\0QUOTE_END\0"){r=!1,s+=10;continue}let i=t[s];if(r){/[.+^${}()|\\*?[\]]/.test(i)?n+=`\\${i}`:n+=i;continue}if(this.extglob&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&s+1<t.length&&t[s+1]==="("){let a=pi(t,s+1);if(a!==-1){let o=t.slice(s+2,a),l=hi(o),u=l.map(f=>this.patternToRegexStr(f)),c=u.length>0?u.join("|"):"(?:)";if(i==="@")n+=`(?:${c})`;else if(i==="*")n+=`(?:${c})*`;else if(i==="+")n+=`(?:${c})+`;else if(i==="?")n+=`(?:${c})?`;else if(i==="!")if(a<t.length-1){let d=l.map(h=>this.computePatternLength(h));if(d.every(h=>h!==null)&&d.every(h=>h===d[0])&&d[0]!==null){let h=d[0];if(h===0)n+="(?:.+)";else{let m=[];h>0&&m.push(`.{0,${h-1}}`),m.push(`.{${h+1},}`),m.push(`(?!(?:${c})).{${h}}`),n+=`(?:${m.join("|")})`}}else n+=`(?:(?!(?:${c})).)*?`}else n+=`(?!(?:${c})$).*`;s=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 c=t.indexOf(":]",l+2);if(c!==-1){l=c+2;continue}}if(t[l]==="]")break;l++}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=di(f);o+=d,a=c+2;continue}}if(t[a]==="\\"&&a+1<t.length){o+=`\\${t[a+1]}`,a+=2;continue}if(t[a]==="-"){let c=a===u,f=a+1===l;c||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=pi(t,r+1);if(a!==-1){if(i==="@"){let o=t.slice(r+2,a),u=hi(o).map(c=>this.computePatternLength(c));if(u.every(c=>c!==null)&&u.every(c=>c===u[0])){n+=u[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 mi(e){for(let t=0;t<e.length;t++){if(e[t]==="\\"){t++;continue}if(e[t]==="$"){let n=e[t+1];if(n==="{"||n&&/[a-zA-Z_]/.test(n))return!0}}return!1}function Gd(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 wl(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 Jn(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 u of l.parts)u.type==="ParameterExpansion"&&(u.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!u.operation||u.operation.type==="PatternRemoval"||u.operation.type==="PatternReplacement")&&(s=!0),(u.operation?.type==="VarNamePrefix"||u.operation?.type==="ArrayKeys")&&(a=!0),u.operation?.type==="Indirection"&&(o=!0));l.type==="CommandSubstitution"&&(n=!0),l.type==="ParameterExpansion"&&(i=!0,(l.parameter==="@"||l.parameter==="*")&&(r=!0),Gd(l)&&(t=!0),(l.operation?.type==="VarNamePrefix"||l.operation?.type==="ArrayKeys")&&(a=!0),l.operation?.type==="Indirection"&&(o=!0)),l.type==="Glob"&&mi(l.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i,hasVarNamePrefixExpansion:a,hasIndirection:o}}var Zd=`
95
- `;function cn(e,t){if(e>=t)throw new k(`array element limit exceeded (${t})`,"array_elements")}function yi(e,t,n,r,s){cn(e.length,s),cn(t.length,s),e.push(n),t.push(r)}function Ae(e){return e.get("IFS")??Zd}function Ne(e){return e.get("IFS")===""}function Lr(e){let t=Ae(e);if(t==="")return!0;for(let n of t)if(n!==" "&&n!==" "&&n!==`
96
- `)return!1;return!0}function El(e){let t=!1,n=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?n.push(`\\${r}`):r===" "?n.push("\\t"):r===`
97
- `?n.push("\\n"):n.push(r);return t&&n.push("\\-"),n.join("")}function H(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var Hd=`
98
- `;function Qd(e){return Hd.includes(e)}function gi(e){let t=new Set,n=new Set;for(let r of e)Qd(r)?t.add(r):n.add(r);return{whitespace:t,nonWhitespace:n}}function wi(e,t,n,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:(cn(0,n),{words:[e],wordStarts:[0]});let{whitespace:i,nonWhitespace:a}=gi(t),o=[],l=[],u=0;for(;u<e.length&&i.has(e[u]);)u++;if(u>=e.length)return{words:[],wordStarts:[]};if(a.has(e[u]))for(yi(o,l,"",u,n),u++;u<e.length&&i.has(e[u]);)u++;for(;u<e.length&&!(r!==void 0&&o.length>=r);){let c=u;for(;u<e.length;){let f=e[u];if(!s&&f==="\\"){u++,u<e.length&&u++;continue}if(i.has(f)||a.has(f))break;u++}if(yi(o,l,e.substring(c,u),c,n),u>=e.length)break;for(;u<e.length&&i.has(e[u]);)u++;if(u<e.length&&a.has(e[u])){for(u++;u<e.length&&i.has(e[u]);)u++;for(;u<e.length&&a.has(e[u])&&!(r!==void 0&&o.length>=r);)for(yi(o,l,"",u,n),u++;u<e.length&&i.has(e[u]);)u++}}return{words:o,wordStarts:l}}function Tr(e,t,n){if(t==="")return e&&cn(0,n),{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=gi(t),i=[],a=0,o=!1,l=!1,u=a;for(;a<e.length&&r.has(e[a]);)a++;if(a>u&&(o=!0),a>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[a]))for(cn(i.length,n),i.push(""),a++;a<e.length&&r.has(e[a]);)a++;for(;a<e.length;){let c=a;for(;a<e.length;){let d=e[a];if(r.has(d)||s.has(d))break;a++}if(cn(i.length,n),i.push(e.substring(c,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(cn(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 ce(e,t,n){return Tr(e,t,n).words}function Kd(e,t){for(let n of e)if(t.has(n))return!0;return!1}function bl(e,t,n){if(t==="")return e;let{whitespace:r,nonWhitespace:s}=gi(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,u=a.length-2;for(;u>=0&&a[u]==="\\";)l++,u--;if(l%2===1)return a}let o=a.substring(0,a.length-1);if(!Kd(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 Sl(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Al(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function vl(e,t){return e.state.invalidNamerefs?.has(t)??!1}function Ei(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function Mr(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let s=n[1],i=Pe(e,s),a=e.state.associativeArrays?.has(s)??!1;return i||a}return Pe(e,t)?!0:e.state.env.has(t)}function Te(e,t,n=100){if(!le(e,t)||vl(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 fn(e,t){if(le(e,t))return e.state.env.get(t)}function Fr(e,t,n,r=100){if(!le(e,t)||vl(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)&&Mr(e,n)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(a))return i;i=a}}function $l(e,t){let n=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(r,s)=>e.state.env.get(s)??"");return n=n.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(r,s)=>e.state.env.get(s)??""),n}function Z(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)?gt(e,t).map(i=>[i,ae(e,t,i)??""]):be(e,t).map(s=>[s,ae(e,t,s)??""])}function ct(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)?Pe(e,t):Pe(e,t)}async function re(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(H(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 go;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 Ze(`\${${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=Z(e,a);if(f.length>0)return f.map(([,p])=>p).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=xr(o);f=$l(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 u;if(/^-?\d+$/.test(o))u=Number.parseInt(o,10);else try{let f=new G,d=te(f,o);u=await K(e,d.expression)}catch{let f=e.state.env.get(o);u=f?Number.parseInt(f,10):0,Number.isNaN(u)&&(u=0)}if(u<0){let f=Z(e,a),d=e.state.currentLine;if(f.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${a}: bad array subscript
99
- `,"";let h=Math.max(...f.map(([E])=>typeof E=="number"?E:0))+1+u;return h<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${a}: bad array subscript
100
- `,""):ae(e,a,h)||""}let c=ae(e,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(n&&e.state.options.nounset)throw new Be(`${a}[${u}]`);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 re(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(ct(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 Et(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 Z(e,s).length>0?!0:e.state.env.has(s);if(e.state.associativeArrays?.has(s)){let l=$l(e,xr(i));return Tt(e,s,l)}let o;if(/^-?\d+$/.test(i))o=Number.parseInt(i,10);else try{let l=new G,u=te(l,i);o=await K(e,u.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=Z(e,s);if(l.length===0)return!1;let c=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+o;return c<0?!1:Tt(e,s,c)}return Tt(e,s,o)}if(le(e,t)){let s=Te(e,t);return s===void 0||s===t?e.state.env.has(t):Et(e,s)}return e.state.env.has(t)?!0:ct(e,t)?Tt(e,t,0):!1}async function xl(e,t){let n="",r=0;for(;r<t.length;){if(t[r]==="$"){if(t[r+1]==="{"){let s=1,i=r+2;for(;i<t.length&&s>0;)t[i]==="{"?s++:t[i]==="}"&&s--,i++;n+=t.slice(r,i),r=i;continue}if(t[r+1]==="("){let s=1,i=r+2;for(;i<t.length&&s>0;)t[i]==="("?s++:t[i]===")"&&s--,i++;n+=t.slice(r,i),r=i;continue}if(/[a-zA-Z_]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)s++;let i=t.slice(r+1,s),a=await re(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 re(e,i);n+=a,r=s;continue}if(/[*@#?\-!$]/.test(t[r+1]||"")){let s=t[r+1],i=await re(e,s);n+=i,r+=2;continue}}if(t[r]==='"'){for(n+='"',r++;r<t.length&&t[r]!=='"';)if(t[r]==="$"&&/[a-zA-Z_]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)s++;let i=t.slice(r+1,s),a=await re(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 bi(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 u=n.slice(a+2,l-1);if(e.execFn){let c=await e.execFn(u,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}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 u=n.slice(a+2,l-1),c=await re(e,u);i+=c,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),u=await re(e,l);i+=u,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 u=await e.execFn(l,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}a=o+1}else i+=n[a],a++;return i}var er=1e4,Si={maxResults:er,maxStringBytes:10*1024*1024};function Br(e,t,n,r){if(e.length>=n.maxResults)return!1;let s=F(t);if(s>n.maxStringBytes-r.value)throw new k(`brace expansion string limit exceeded (${n.maxStringBytes} bytes)`,"string_length");return e.push(t),r.value+=s,!0}function Xd(e,t,n,r,s,i=Si){let a=n??1;a===0&&(a=1);let o=Math.abs(a),l=[],u=0;if(r?.match(/^-?0\d/)&&(u=Math.max(u,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(u=Math.max(u,s.replace(/^-/,"").length)),u>i.maxStringBytes)throw new k(`brace expansion padding limit exceeded (${i.maxStringBytes} bytes)`,"string_length");let c={value:0},f=d=>{if(u>0){let p=d<0,h=String(Math.abs(d)).padStart(u,"0");return p?`-${h}`:h}return String(d)};if(e<=t)for(let d=e,p=0;d<=t&&p<er&&Br(l,f(d),i,c);d+=o,p++);else for(let d=e,p=0;d>=t&&p<er&&Br(l,f(d),i,c);d-=o,p++);return l}function Yd(e,t,n,r=Si){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",u=e>="a"&&e<="z",c=t>="A"&&t<="Z",f=t>="a"&&t<="z";if(l&&f||u&&c){let h=n!==void 0?`..${n}`:"";throw new br(`{${e}..${t}${h}}: invalid sequence`)}let d=[],p={value:0};if(i<=a)for(let h=i,m=0;h<=a&&m<er&&Br(d,String.fromCharCode(h),r,p);h+=o,m++);else for(let h=i,m=0;h>=a&&m<er&&Br(d,String.fromCharCode(h),r,p);h-=o,m++);return d}function Ai(e,t,n,r,s,i=Si){let a=n!==void 0?`..${n}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:Xd(e,t,n,r,s,i),literal:`{${e}..${t}${a}}`}:typeof e=="string"&&typeof t=="string"?{expanded:Yd(e,t,n,i),literal:`{${e}..${t}${a}}`}:{expanded:null,literal:`{${e}..${t}${a}}`}}function kl(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 bt(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function vi(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 Ke(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function Cn(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function J(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=Jd(e,s+1);if(a!==-1){let o=e.slice(s+2,a),u=ep(o).map(f=>X(f,t,n)),c=u.length>0?u.join("|"):"(?:)";i==="@"?r+=`(?:${c})`:i==="*"?r+=`(?:${c})*`:i==="+"?r+=`(?:${c})+`:i==="?"?r+=`(?:${c})?`:i==="!"&&(r+=`(?!(?:${c})$).*`),s=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=tp(e,s);if(a===-1)r+="\\[",s++;else{let o=e.slice(s+1,a);r+=np(o),s=a+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,s++):(r+=i,s++)}return r}function Jd(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 ep(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 tp(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 np(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+=sp(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 rp=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]);function sp(e){return rp.get(e)??""}function ft(e,t,n,r,s){if(r==="prefix")return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),me(`^${n}`,"s").replace(t,"");let i=me(`${n}$`,"s");if(s)return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),i.replace(t,"");e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal");let a=me(`^(?:.*)(${n})$`,"s").exec(t);if(!a)return t;let o=a[1]??"";return t.slice(0,t.length-o.length)}function Nn(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 gn(e.limits.maxStringLength,"pattern replacement",()=>new k(`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 Pl(e){let t=[],n=0;return{append(r){let s=F(r);if(s>e-n)throw new k(`prompt expansion exceeds string length limit (${e} bytes)`,"string_length");r&&t.push(r),n+=s},build:()=>t.join("")}}function ip(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=Pl(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 tr(e,t){let n=Pl(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")||"/",u=o.startsWith(l)?`~${o.slice(l.length)}`:o,c=o.split("/").pop()||o,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],p=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],h=e.state.env.get("__COMMAND_NUMBER")||"1";for(;r<t.length;){let m=t[r];if(m==="\\"){if(r+1>=t.length){n.append("\\"),r++;continue}let E=t[r+1];if(E>="0"&&E<="7"){let b="",g=r+1;for(;g<t.length&&g<r+4&&t[g]>="0"&&t[g]<="7";)b+=t[g],g++;let y=Number.parseInt(b,8)%256;n.append(String.fromCharCode(y)),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(`
101
- `),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(u),r+=2;break;case"W":n.append(c),r+=2;break;case"d":{let b=String(f.getDate()).padStart(2," ");n.append(`${d[f.getDay()]} ${p[f.getMonth()]} ${b}`),r+=2;break}case"t":{let b=String(f.getHours()).padStart(2,"0"),g=String(f.getMinutes()).padStart(2,"0"),y=String(f.getSeconds()).padStart(2,"0");n.append(`${b}:${g}:${y}`),r+=2;break}case"T":{let b=f.getHours()%12;b===0&&(b=12);let g=String(b).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),S=String(f.getSeconds()).padStart(2,"0");n.append(`${g}:${y}:${S}`),r+=2;break}case"@":{let b=f.getHours()%12;b===0&&(b=12);let g=String(b).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),S=f.getHours()<12?"AM":"PM";n.append(`${g}:${y} ${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(ip(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(h),r+=2;break;case"!":n.append(h),r+=2;break;case"x":n.append("\\x"),r+=2;break;default:n.append(`\\${E}`),r+=2}}else n.append(m),r++}return n.build()}function Wt(e){if(e==="")return"''";if(/[\n\r\t\x00-\x1f\x7f']/.test(e)){let n="$'";for(let r of e)switch(r){case"'":n+="\\'";break;case"\\":n+="\\\\";break;case`
102
- `: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 Me(e,t){return e.state.readonlyVars?.has(t)??!1}function ue(e,t,n="bash"){if(Me(e,t)){let r=`${n}: ${t}: readonly variable
103
- `;throw new U(1,"",r)}return null}function dt(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 Vr(e,t){e.state.exportedVars?.delete(t)}function Vt(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let n="",r=ve(e,t)?.kind==="indexed",s=e.state.associativeArrays?.has(t)??!1;return r&&!s&&(n+="a"),s&&(n+="A"),e.state.integerVars?.has(t)&&(n+="i"),le(e,t)&&(n+="n"),Me(e,t)&&(n+="r"),e.state.exportedVars?.has(t)&&(n+="x"),n}async function Cl(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 Nl(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,u]=o,c;if(/^\d+$/.test(u))c=Number.parseInt(u,10);else{try{let f=new G,d=te(f,u);c=await K(e,d.expression)}catch{let f=e.state.env.get(u);c=f?Number.parseInt(f,10):0}Number.isNaN(c)&&(c=0)}j(e,l,c,a)}else e.state.env.set(t,a);return a}return r.effectiveValue}async function Rl(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 U(1,"",`bash: ${a}
104
- `)}return r.effectiveValue}async function Dl(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 Il(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+=J(o.value);else if(o.type==="DoubleQuoted"){let l=await r(e,o.parts);i+=J(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+=J(l)}return ft(e,t,i,n.side,n.greedy)}async function Ol(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",a=e.state.shoptOptions.extglob;if(n.pattern)for(let u of n.pattern.parts)if(u.type==="Glob")i+=X(u.pattern,!0,a);else if(u.type==="Literal")i+=X(u.value,!0,a);else if(u.type==="SingleQuoted"||u.type==="Escaped")i+=J(u.value);else if(u.type==="DoubleQuoted"){let c=await r(e,u.parts);i+=J(c)}else if(u.type==="ParameterExpansion"){let c=await s(e,u);i+=X(c,!0,a)}else{let c=await s(e,u);i+=J(c)}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 u=me(i,l);return Wr(e,t,u,o,n.all)}catch(u){if(u instanceof k)throw u;return t}}function _l(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=Z(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)&&ct(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 Ll(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 u=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let h=1;h<=u;h++)c.push(e.state.env.get(String(h))||"");let f=e.state.env.get("0")||"bash",d,p;if(s<=0)if(d=[f,...c],s<0){if(p=d.length+s,p<0)return""}else p=0;else d=c,p=s-1;if(p<0||p>=d.length)return"";if(i!==void 0){let h=i<0?d.length+i:p+i;return d.slice(p,Math.max(p,h)).join(" ")}return d.slice(p).join(" ")}let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(a){let u=a[1];if(e.state.associativeArrays?.has(u))throw new U(1,"",`bash: \${${u}[@]: 0: 3}: bad substitution
105
- `);let c=Z(e,u),f=0;if(s<0){if(c.length>0){let d=c[c.length-1][0],h=(typeof d=="number"?d:0)+1+s;if(h<0||(f=c.findIndex(([m])=>typeof m=="number"&&m>=h),f<0))return""}}else if(f=c.findIndex(([d])=>typeof d=="number"&&d>=s),f<0)return"";if(i!==void 0){if(i<0)throw new oe(`${a[1]}[@]: substring expression < 0`);return c.slice(f,f+i).map(([,d])=>d).join(" ")}return c.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 u=o.length+i;return o.slice(l,Math.max(l,u)).join("")}return o.slice(l,l+i).join("")}return o.slice(l).join("")}async function Tl(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+=J(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);a+=J(d)}else if(f.type==="ParameterExpansion"){let d=await s(e,f);a+=X(d,!0,i)}let o=me(`^(?:${a})$`),l=n.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),u="",c=!1;for(let f of t)!n.all&&c?u+=f:o.test(f)?(u+=l(f),c=!0):u+=f;return u}return n.direction==="upper"?n.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):n.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function Ml(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 Z(e,i[1]).map(([,u])=>Wt(u)).join(" ");if(i&&s.operator==="a")return Vt(e,i[1]);let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(a&&s.operator==="a")return Vt(e,a[1]);switch(s.operator){case"Q":return r?"":Wt(n);case"P":return tr(e,n);case"a":return Vt(e,t);case"A":return r?"":`${t}=${Wt(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`
106
- `;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?"":Wt(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 Fl(e,t,n,r,s,i,a=!1){if(e.coverage?.hit("bash:expansion:indirection"),le(e,t))return fn(e,t)||"";let o=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(s.innerOp?.type==="UseAlternative")return"";throw new Ze(`\${!${t}}`)}let l=n;if(o&&(l===""||l.includes(" ")))throw new Ze(`\${!${t}}`);let u=l.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new Ze(`\${!${t}}`);if(s.innerOp){let c={type:"ParameterExpansion",parameter:l,operation:s.innerOp};return i(e,c,a)}return await re(e,l)}function Bl(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=Z(e,t.array).map(([s])=>String(s));return t.star?r.join(H(e.state.env)):r.join(" ")}function Wl(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let n=Nn(e,t.prefix);return t.star?n.join(H(e.state.env)):n.join(" ")}function Vl(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=Z(e,a);if(l.length===0)return{isEmpty:!0,effectiveValue:""};if(o==="*"){let u=H(e.state.env),c=l.map(([,f])=>f).join(u);return{isEmpty:r?c==="":!1,effectiveValue:c}}return{isEmpty:l.length===1&&l.every(([,u])=>u===""),effectiveValue:l.map(([,u])=>u).join(" ")}}return{isEmpty:n==="",effectiveValue:n}}function zl(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 ql(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 zr(e,t){let n=new G,r;try{r=n.parse(t)}catch{return""}let s=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let i=new Map(e.state.env),a=nt(e.state.arrays),o=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let u=await e.executeScript(r),c=u.exitCode;return e.state.env=i,e.state.arrays=a,e.state.cwd=o,e.state.suppressVerbose=l,e.state.lastExitCode=c,e.state.env.set("?",String(c)),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr),e.state.bashPid=s,u.stdout.replace(/\n+$/,"")}catch(u){if(e.state.env=i,e.state.arrays=a,e.state.cwd=o,e.state.bashPid=s,e.state.suppressVerbose=l,u instanceof k)throw u;return u instanceof U?(e.state.lastExitCode=u.exitCode,e.state.env.set("?",String(u.exitCode)),u.stdout?.replace(/\n+$/,"")??""):""}}function $i(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let a=t.slice(r+1,i);n+=Ke(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=ap(e,o);n+=Ke(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 ap(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 Ul(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+=Ke(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 op(e,o);n+=Ke(l),r=i+1;continue}}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=ql(t,r+2);if(i!==-1){let a=t.slice(r+2,i),o=await zr(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 zr(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 op(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=ql(t,r+2);if(i!==-1){let a=t.slice(r+2,i),o=await zr(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 zr(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 xi(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 zt(e,t){return t.split(":").map(n=>xi(e,n)).join(":")}function Re(e,t,n,r){if(e.length>n-t.length)throw new k(`${r} element limit exceeded (${n})`,"array_elements");for(let s of t)e.push(s)}async function lp(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+=J(i.value);else if(i.type==="DoubleQuoted"){let a=await n(e,i.parts);s+=J(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+=J(a)}return s}async function jl(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]==="*",u=i.operation,c=Z(e,o),f=c.map(([,E])=>E);if(c.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="";u.pattern&&(d=await lp(e,u.pattern,n,r));let p=u.replacement?await n(e,u.replacement.parts):"",h=d;u.anchor==="start"?h=`^${d}`:u.anchor==="end"&&(h=`${d}$`);let m=[];try{let E=me(h,u.all?"g":"");for(let b of f)m.push(E.replace(b,p))}catch{m.push(...f)}if(l){let E=H(e.state.env);return{values:[m.join(E)],quoted:!0}}return{values:m,quoted:!0}}async function Gl(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]==="*",u=i.operation,c=Z(e,o),f=c.map(([,m])=>m);if(c.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="",p=e.state.shoptOptions.extglob;if(u.pattern)for(let m of u.pattern.parts)if(m.type==="Glob")d+=X(m.pattern,u.greedy,p);else if(m.type==="Literal")d+=X(m.value,u.greedy,p);else if(m.type==="SingleQuoted"||m.type==="Escaped")d+=J(m.value);else if(m.type==="DoubleQuoted"){let E=await n(e,m.parts);d+=J(E)}else if(m.type==="ParameterExpansion"){let E=await r(e,m);d+=X(E,u.greedy,p)}else{let E=await r(e,m);d+=J(E)}let h=[];for(let m of f)h.push(ft(e,m,d,u.side,u.greedy));if(l){let m=H(e.state.env);return{values:[h.join(m)],quoted:!0}}return{values:h,quoted:!0}}async function Zl(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 u=Z(e,l),c=u.length>0||e.state.env.has(l),f=u.length===0||u.length===1&&u.every(([,p])=>p===""),d=s.checkEmpty??!1;if(s.type==="UseAlternative"?a=c&&!(d&&f):a=!c||d&&f,!a){if(u.length>0){let h=u.map(([,m])=>m);if(o){let m=H(e.state.env);return{values:[h.join(m)],quoted:!0}}return{values:h,quoted:!0}}let p=e.state.env.get(l);return p!==void 0?{values:[p],quoted:!0}:{values:[],quoted:!0}}}else{let l=r.parameter,u=await Et(e,l),c=await re(e,l),f=c==="",d=s.checkEmpty??!1;if(s.type==="UseAlternative"?a=u&&!(d&&f):a=!u||d&&f,!a)return{values:[c],quoted:!0}}if(a&&s.word){let l=s.word.parts,u=null,c=!1;for(let f of l)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){u=d[1],c=d[2]==="*";break}}if(u){let f=Z(e,u);if(f.length>0){let p=f.map(([,h])=>h);if(c||o){let h=H(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}let d=e.state.env.get(u);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}return null}async function Hl(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,u=null;for(let m=0;m<i.parts.length;m++){let E=i.parts[m];if(E.type==="ParameterExpansion"&&(E.operation?.type==="PatternRemoval"||E.operation?.type==="PatternReplacement")){let b=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){a=m,o=b[1],l=b[2]==="*",u=E.operation;break}}}if(a===-1||a===0&&a===i.parts.length-1)return null;let c="";for(let m=0;m<a;m++)c+=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=Z(e,o),p=d.map(([,m])=>m);if(d.length===0){let m=e.state.env.get(o);if(m!==void 0)p=[m];else{if(l)return{values:[c+f],quoted:!0};let E=c+f;return{values:E?[E]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let m=u,E="",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+=J(g.value);else if(g.type==="DoubleQuoted"){let y=await s(e,g.parts);E+=J(y)}else if(g.type==="ParameterExpansion"){let y=await r(e,g);E+=X(y,m.greedy,b)}else{let y=await r(e,g);E+=J(y)}p=p.map(g=>ft(e,g,E,m.side,m.greedy))}else if(u?.type==="PatternReplacement"){let m=u,E="";if(m.pattern)for(let y of m.pattern.parts)if(y.type==="Glob")E+=X(y.pattern,!0,e.state.shoptOptions.extglob);else if(y.type==="Literal")E+=X(y.value,!0,e.state.shoptOptions.extglob);else if(y.type==="SingleQuoted"||y.type==="Escaped")E+=J(y.value);else if(y.type==="DoubleQuoted"){let S=await s(e,y.parts);E+=J(S)}else if(y.type==="ParameterExpansion"){let S=await r(e,y);E+=X(S,!0,e.state.shoptOptions.extglob)}else{let S=await r(e,y);E+=J(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 y=me(g,m.all?"g":"");p=p.map(S=>y.replace(S,b))}catch{}}if(l){let m=H(e.state.env);return{values:[c+p.join(m)+f],quoted:!0}}return p.length===1?{values:[c+p[0]+f],quoted:!0}:{values:[c+p[0],...p.slice(1,-1),p[p.length-1]+f],quoted:!0}}async function Ql(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 p=0;p<s.parts.length;p++){let h=s.parts[p];if(h.type==="ParameterExpansion"&&!h.operation){let m=h.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(m){i=p,a=m[1],o=m[2]==="*";break}}}if(i===-1)return null;let l="";for(let p=0;p<i;p++)l+=await r(e,s.parts[p]);let u="";for(let p=i+1;p<s.parts.length;p++)u+=await r(e,s.parts[p]);let c=Z(e,a),f=c.map(([,p])=>p);if(c.length===0){let p=e.state.env.get(a);if(p!==void 0)return{values:[l+p+u],quoted:!0};if(o)return{values:[l+u],quoted:!0};let h=l+u;return{values:h?[h]:[],quoted:!0}}if(o){let p=H(e.state.env);return{values:[l+f.join(p)+u],quoted:!0}}return f.length===1?{values:[l+f[0]+u],quoted:!0}:{values:[l+f[0],...f.slice(1,-1),f[f.length-1]+u],quoted:!0}}async function Kl(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 U(1,"",`bash: \${${a}[@]: 0: 3}: bad substitution
107
- `);let u=l.offset?await n(e,l.offset.expression):0,c=l.length?await n(e,l.length.expression):void 0,f=Z(e,a);if(f.length>e.limits.maxArrayElements)throw new k(`array transform element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let d=0;if(u<0){if(f.length>0){let h=f[f.length-1][0],E=(typeof h=="number"?h:0)+1+u;if(E<0)return{values:[],quoted:!0};d=f.findIndex(([b])=>typeof b=="number"&&b>=E),d<0&&(d=f.length)}}else d=f.findIndex(([h])=>typeof h=="number"&&h>=u),d<0&&(d=f.length);let p;if(c!==void 0){if(c<0)throw new oe(`${a}[@]: substring expression < 0`);p=f.slice(d,d+c).map(([,h])=>h)}else p=f.slice(d).map(([,h])=>h);if(p.length===0)return{values:[],quoted:!0};if(o){let h=H(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}function Xl(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=Z(e,i);if(l.length===0){let d=e.state.env.get(i);if(d!==void 0){let p;switch(o.operator){case"a":p="";break;case"P":p=tr(e,d);break;case"Q":p=Wt(d);break;default:p=d}if(F(p)>e.limits.maxStringLength)throw new k(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[p],quoted:!0}}return a?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=Vt(e,i),c=[],f=0;for(let[,d]of l){let p;switch(o.operator){case"a":p=u;break;case"P":p=tr(e,d);break;case"Q":p=Wt(d);break;case"u":p=d.charAt(0).toUpperCase()+d.slice(1);break;case"U":p=d.toUpperCase();break;case"L":p=d.toLowerCase();break;default:p=d}let h=F(p);if(h>e.limits.maxStringLength-f)throw new k(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");c.push(p),f+=h}if(a){let d=H(e.state.env);if(Math.max(0,c.length-1)*F(d)>e.limits.maxStringLength-f)throw new k(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[c.join(d)],quoted:!0}}return{values:c,quoted:!0}}function Yl(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=fn(e,i);if(l?.endsWith("[@]")||l?.endsWith("[*]"))return{values:[],quoted:!0}}let a=Z(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 Jl(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=fn(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=Z(e,o);if(l.length>0)return{values:l.map(([,c])=>c),quoted:!0};let u=e.state.env.get(o);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function eu(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 re(e,a.parameter),u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!o.innerOp&&(l==="@"||l==="*")){let h=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let E=1;E<=h;E++)m.push(e.state.env.get(String(E))||"");return l==="*"?{values:[m.join(H(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let c=u[1],f=u[2]==="*",d=Z(e,c);if(o.innerOp){if(o.innerOp.type==="Substring")return up(e,d,c,f,o.innerOp);if(o.innerOp.type==="DefaultValue"||o.innerOp.type==="UseAlternative"||o.innerOp.type==="AssignDefault"||o.innerOp.type==="ErrorIfUnset")return cp(e,d,c,f,o.innerOp,s);if(o.innerOp.type==="Transform"&&o.innerOp.operator==="a"){let m=Vt(e,c),E=d.map(()=>m);return f?{values:[E.join(H(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let h=[];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);h.push(g)}finally{b!==void 0?e.state.env.set("_indirect_elem_",b):e.state.env.delete("_indirect_elem_")}}return f?{values:[h.join(H(e.state.env))],quoted:!0}:{values:h,quoted:!0}}if(d.length>0){let h=d.map(([,m])=>m);return f?{values:[h.join(H(e.state.env))],quoted:!0}:{values:h,quoted:!0}}let p=e.state.env.get(c);return p!==void 0?{values:[p],quoted:!0}:{values:[],quoted:!0}}async function up(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 c=t[t.length-1][0],d=(typeof c=="number"?c:0)+1+i;if(d<0)return{values:[],quoted:!0};if(o=t.findIndex(([p])=>typeof p=="number"&&p>=d),o<0)return{values:[],quoted:!0}}}else if(o=t.findIndex(([c])=>typeof c=="number"&&c>=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 u=l.map(([,c])=>c);return r?{values:[u.join(H(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function cp(e,t,n,r,s,i){let a=s.checkEmpty??!1,o=t.map(([,c])=>c),l=t.length===0,u=t.length===0;if(s.type==="UseAlternative")return!u&&!(a&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(s.type==="DefaultValue")return(u||a&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:r?{values:[o.join(H(e.state.env))],quoted:!0}:{values:o,quoted:!0};if(s.type==="AssignDefault"){if((u||a&&l)&&s.word){let f=await i(e,s.word.parts,!0);return j(e,n,0,f),{values:[f],quoted:!0}}return r?{values:[o.join(H(e.state.env))],quoted:!0}:{values:o,quoted:!0}}return r?{values:[o.join(H(e.state.env))],quoted:!0}:{values:o,quoted:!0}}async function tu(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 re(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!l)return null;let u=await Et(e,n.parameter),c=await re(e,n.parameter)==="",f=r.checkEmpty??!1,d;if(r.type==="UseAlternative"?d=u&&!(f&&c):d=!u||f&&c,d){let p=l[1],h=l[2]==="*",m=Z(e,p);if(m.length>0){let b=m.map(([,g])=>g);return h?{values:[b.join(H(e.state.env))],quoted:!0}:{values:b,quoted:!0}}let E=e.state.env.get(p);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function nu(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],u=(await re(e,o.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await re(e,n.parameter),f=await Et(e,n.parameter),d=c==="",p=s.checkEmpty??!1,h;if(s.type==="UseAlternative"?h=f&&!(p&&d):h=!f||p&&d,h){let m=u[1],E=u[2]==="*",b=Z(e,m);if(b.length>0){let y=b.map(([,S])=>S);return E?{values:[y.join(H(e.state.env))],quoted:!0}:{values:y,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 ru(e){let t=Number.parseInt(e.state.env.get("#")||"0",10);if(t>e.limits.maxArrayElements)throw new k(`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=F(i);if(a>e.limits.maxStringLength-r)throw new k(`positional parameter string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n.push(i),r+=a}return n}function qr(e,t,n){if(F(t)>n-F(e))throw new k(`positional expansion string limit exceeded (${n} bytes)`,"string_length");return e+t}function ki(e,t,n,r){if(e.length>=r.limits.maxArrayElements)throw new k(`positional expansion element limit exceeded (${r.limits.maxArrayElements})`,"array_elements");let s=F(t);if(s>r.limits.maxStringLength-n.value)throw new k(`positional expansion string limit exceeded (${r.limits.maxStringLength} bytes)`,"string_length");e.push(t),n.value+=s}async function su(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 y=s.parts[g];if(y.type==="ParameterExpansion"&&(y.parameter==="@"||y.parameter==="*")&&y.operation?.type==="Substring"){i=g,a=y.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,u=l.offset?await n(e,l.offset.expression):0,c=l.length?await n(e,l.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),d=[];for(let g=1;g<=f;g++)d.push(e.state.env.get(String(g))||"");let p=e.state.env.get("0")||"bash",h;if(u<=0){let g=[p,...d],y=g.length+u;if(y<0)h=[];else{let S=u<0?y:0;if(c!==void 0){let v=c<0?g.length+c:S+c;h=g.slice(S,Math.max(S,v))}else h=g.slice(S)}}else{let g=u-1;if(g>=d.length)h=[];else if(c!==void 0){let y=c<0?d.length+c:g+c;h=d.slice(g,Math.max(g,y))}else h=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(h.length===0){let g=m+E;return{values:g?[g]:[],quoted:!0}}if(a){let g=H(e.state.env);return{values:[m+h.join(g)+E],quoted:!0}}return h.length===1?{values:[m+h[0]+E],quoted:!0}:{values:[m+h[0],...h.slice(1,-1),h[h.length-1]+E],quoted:!0}}async function iu(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 y=s.parts[g];if(y.type==="ParameterExpansion"&&(y.parameter==="@"||y.parameter==="*")&&y.operation?.type==="PatternReplacement"){i=g,a=y.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,u=ru(e),c="";for(let g=0;g<i;g++)c=qr(c,await n(e,s.parts[g]),e.limits.maxStringLength);let f="";for(let g=i+1;g<s.parts.length;g++)f=qr(f,await n(e,s.parts[g]),e.limits.maxStringLength);if(u.length===0){let g=c+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+=J(g.value);else if(g.type==="DoubleQuoted"){let y=await r(e,g.parts);d+=J(y)}else if(g.type==="ParameterExpansion"){let y=await n(e,g);d+=X(y,!0,e.state.shoptOptions.extglob)}else{let y=await n(e,g);d+=J(y)}let p=l.replacement?await r(e,l.replacement.parts):"",h=d;l.anchor==="start"?h=`^${d}`:l.anchor==="end"&&(h=`${d}$`);let m=[],E={value:0};try{let g=me(h,l.all?"g":"");for(let y of u){let S=0;g.lastIndex=0;for(let x=g.exec(y);x&&(S++,!!l.all);x=g.exec(y))x[0].length===0&&g.lastIndex++;let v=F(y),$=F(p),A=0,C=/\$(?:\$|&|\d+|<[^>]+>|`|')/g;for(;C.exec(p)!==null;)A++;if(v+S*$+S*A*v>e.limits.maxStringLength-E.value)throw new k(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");ki(m,g.replace(y,p),E,e)}}catch(g){if(g instanceof k)throw g;for(let y of u)ki(m,y,E,e)}if(a){let g=H(e.state.env);if(E.value+Math.max(0,m.length-1)*F(g)+F(c)+F(f)>e.limits.maxStringLength)throw new k(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[c+m.join(g)+f],quoted:!0}}if(F(c)+E.value+F(f)>e.limits.maxStringLength)throw new k(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return m.length===1?{values:[c+m[0]+f],quoted:!0}:{values:[c+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function au(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,u=ru(e),c="";for(let b=0;b<i;b++)c=qr(c,await n(e,s.parts[b]),e.limits.maxStringLength);let f="";for(let b=i+1;b<s.parts.length;b++)f=qr(f,await n(e,s.parts[b]),e.limits.maxStringLength);if(u.length===0){let b=c+f;return{values:b?[b]:[],quoted:!0}}let d="",p=e.state.shoptOptions.extglob;if(l.pattern)for(let b of l.pattern.parts)if(b.type==="Glob")d+=X(b.pattern,l.greedy,p);else if(b.type==="Literal")d+=X(b.value,l.greedy,p);else if(b.type==="SingleQuoted"||b.type==="Escaped")d+=J(b.value);else if(b.type==="DoubleQuoted"){let g=await r(e,b.parts);d+=J(g)}else if(b.type==="ParameterExpansion"){let g=await n(e,b);d+=X(g,l.greedy,p)}else{let g=await n(e,b);d+=J(g)}let h=[],m={value:0};for(let b of u)ki(h,ft(e,b,d,l.side,l.greedy),m,e);if(a){let b=H(e.state.env);if(m.value+Math.max(0,h.length-1)*F(b)+F(c)+F(f)>e.limits.maxStringLength)throw new k(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[c+h.join(b)+f],quoted:!0}}if(F(c)+m.value+F(f)>e.limits.maxStringLength)throw new k(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return h.length===1?{values:[c+h[0]+f],quoted:!0}:{values:[c+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function ou(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0],s=-1,i=!1;for(let d=0;d<r.parts.length;d++){let p=r.parts[d];if(p.type==="ParameterExpansion"&&(p.parameter==="@"||p.parameter==="*")){s=d,i=p.parameter==="*";break}}if(s===-1)return null;let 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 u="";for(let d=s+1;d<r.parts.length;d++)u+=await n(e,r.parts[d]);if(o===0){if(i)return{values:[l+u],quoted:!0};let d=l+u;return{values:d?[d]:[],quoted:!0}}let c=[];for(let d=1;d<=o;d++)c.push(e.state.env.get(String(d))||"");if(i){let d=H(e.state.env);return{values:[l+c.join(d)+u],quoted:!0}}return c.length===1?{values:[l+c[0]+u],quoted:!0}:{values:[l+c[0],...c.slice(1,-1),c[c.length-1]+u],quoted:!0}}function St(e,t,n,r){if(t.length>=e.limits.maxArrayElements)throw new k(`unquoted expansion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let s=F(n);if(s>e.limits.maxStringLength-r.value)throw new k(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");t.push(n),r.value+=s}function Pi(e,t,n,r){let s=F(n),i=Math.max(0,t.length-1);if(s>0&&i>Math.floor((e.limits.maxStringLength-r)/s))throw new k(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return t.join(n)}function fp(e){return new Bt(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 Ur(e,t){if(e.state.options.noglob)return t;let n=fp(e),r=[];for(let s of t)if(bt(s,e.state.shoptOptions.extglob)){let i=await n.expand(s);if(i.length>0)Re(r,i,e.limits.maxArrayElements,"unquoted glob expansion");else{if(n.hasFailglob())throw new Nt(s);n.hasNullglob()||r.push(s)}}else r.push(s);return r}async function lu(e,t,n,r){let s=-1,i="",a=!1;for(let S=0;S<t.length;S++){let v=t[S];if(v.type==="ParameterExpansion"&&v.operation?.type==="PatternReplacement"){let $=v.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if($){s=S,i=$[1],a=$[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,u=Z(e,i),c=u.map(([,S])=>S);if(u.length===0){let S=e.state.env.get(i);S!==void 0&&(c=[S])}if(c.length===0)return{values:[],quoted:!1};let f="";if(l.pattern)for(let S of l.pattern.parts)if(S.type==="Glob")f+=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+=J(S.value);else if(S.type==="DoubleQuoted"){let v=await n(e,S.parts);f+=J(v)}else if(S.type==="ParameterExpansion"){let v=await r(e,S);f+=X(v,!0,e.state.shoptOptions.extglob)}else{let v=await r(e,S);f+=J(v)}let d=l.replacement?await n(e,l.replacement.parts):"",p=f;l.anchor==="start"?p=`^${f}`:l.anchor==="end"&&(p=`${f}$`);let h=[],m={value:0};try{let S=me(p,l.all?"g":"");for(let v of c)St(e,h,Wr(e,v,S,d,l.all),m)}catch(S){if(S instanceof k)throw S;for(let v of c)St(e,h,v,m)}let E=Ae(e.state.env),b=Ne(e.state.env);if(a){let S=H(e.state.env),v=Pi(e,h,S,m.value);return b?{values:v?[v]:[],quoted:!1}:{values:ce(v,E,e.limits.maxArrayElements),quoted:!1}}if(b)return{values:h,quoted:!1};let g=[],y={value:0};for(let S of h)if(S==="")St(e,g,"",y);else for(let v of ce(S,E,e.limits.maxArrayElements))St(e,g,v,y);return{values:g,quoted:!1}}async function uu(e,t,n,r){let s=-1,i="",a=!1;for(let y=0;y<t.length;y++){let S=t[y];if(S.type==="ParameterExpansion"&&S.operation?.type==="PatternRemoval"){let v=S.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(v){s=y,i=v[1],a=v[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,u=Z(e,i),c=u.map(([,y])=>y);if(u.length===0){let y=e.state.env.get(i);y!==void 0&&(c=[y])}if(c.length===0)return{values:[],quoted:!1};let f="",d=e.state.shoptOptions.extglob;if(l.pattern)for(let y of l.pattern.parts)if(y.type==="Glob")f+=X(y.pattern,l.greedy,d);else if(y.type==="Literal")f+=X(y.value,l.greedy,d);else if(y.type==="SingleQuoted"||y.type==="Escaped")f+=J(y.value);else if(y.type==="DoubleQuoted"){let S=await n(e,y.parts);f+=J(S)}else if(y.type==="ParameterExpansion"){let S=await r(e,y);f+=X(S,l.greedy,d)}else{let S=await r(e,y);f+=J(S)}let p=[],h={value:0};for(let y of c)St(e,p,ft(e,y,f,l.side,l.greedy),h);let m=Ae(e.state.env),E=Ne(e.state.env);if(a){let y=H(e.state.env),S=Pi(e,p,y,h.value);return E?{values:S?[S]:[],quoted:!1}:{values:ce(S,m,e.limits.maxArrayElements),quoted:!1}}if(E)return{values:p,quoted:!1};let b=[],g={value:0};for(let y of p)if(y==="")St(e,b,"",g);else for(let S of ce(y,m,e.limits.maxArrayElements))St(e,b,S,g);return{values:b,quoted:!1}}async function cu(e,t,n,r){let s=-1,i=!1;for(let g=0;g<t.length;g++){let y=t[g];if(y.type==="ParameterExpansion"&&(y.parameter==="@"||y.parameter==="*")&&y.operation?.type==="PatternRemoval"){s=g,i=y.parameter==="*";break}}if(s===-1)return null;let o=t[s].operation,l=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let g=1;g<=l;g++)u.push(e.state.env.get(String(g))||"");if(u.length===0)return{values:[],quoted:!1};let c="",f=e.state.shoptOptions.extglob;if(o.pattern)for(let g of o.pattern.parts)if(g.type==="Glob")c+=X(g.pattern,o.greedy,f);else if(g.type==="Literal")c+=X(g.value,o.greedy,f);else if(g.type==="SingleQuoted"||g.type==="Escaped")c+=J(g.value);else if(g.type==="DoubleQuoted"){let y=await n(e,g.parts);c+=J(y)}else if(g.type==="ParameterExpansion"){let y=await r(e,g);c+=X(y,o.greedy,f)}else{let y=await r(e,g);c+=J(y)}let d=[],p={value:0};for(let g of u)St(e,d,ft(e,g,c,o.side,o.greedy),p);let h=Ae(e.state.env),m=Ne(e.state.env);if(i){let g=H(e.state.env),y=Pi(e,d,g,p.value);return m?{values:y?[y]:[],quoted:!1}:{values:ce(y,h,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[],b={value:0};for(let g of d)if(g==="")St(e,E,"",b);else for(let y of ce(g,h,e.limits.maxArrayElements))St(e,E,y,b);return{values:E,quoted:!1}}async function fu(e,t,n,r){let s=-1,i=!1;for(let y=0;y<t.length;y++){let S=t[y];if(S.type==="ParameterExpansion"&&(S.parameter==="@"||S.parameter==="*")&&S.operation?.type==="Substring"){s=y,i=S.parameter==="*";break}}if(s===-1)return null;let o=t[s].operation,l=o.offset?await n(e,o.offset.expression):0,u=o.length?await n(e,o.length.expression):void 0,c=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let y=1;y<=c;y++)f.push(e.state.env.get(String(y))||"");let d=e.state.env.get("0")||"bash",p;if(l<=0){let y=[d,...f],S=y.length+l;if(S<0)p=[];else{let v=l<0?S:0;if(u!==void 0){let $=u<0?y.length+u:v+u;p=y.slice(v,Math.max(v,$))}else p=y.slice(v)}}else{let y=l-1;if(y>=f.length)p=[];else if(u!==void 0){let S=u<0?f.length+u:y+u;p=f.slice(y,Math.max(y,S))}else p=f.slice(y)}let h="";for(let y=0;y<s;y++)h+=await r(e,t[y]);let m="";for(let y=s+1;y<t.length;y++)m+=await r(e,t[y]);let E=Ae(e.state.env),b=Ne(e.state.env);if(p.length===0){let y=h+m;return y?b?{values:[y],quoted:!1}:{values:ce(y,E,e.limits.maxArrayElements),quoted:!1}:{values:[],quoted:!1}}let g;if(i){let y=H(e.state.env),S=h+p.join(y)+m;b?g=S?[S]:[]:g=ce(S,E,e.limits.maxArrayElements)}else if(b)p.length===1?g=[h+p[0]+m]:g=[h+p[0],...p.slice(1,-1),p[p.length-1]+m];else{g=[];for(let y=0;y<p.length;y++){let S=p[y];if(y===0&&(S=h+S),y===p.length-1&&(S=S+m),S==="")g.push("");else{let v=ce(S,E,e.limits.maxArrayElements);Re(g,v,e.limits.maxArrayElements,"unquoted expansion")}}}return{values:await Ur(e,g),quoted:!1}}async function du(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let n=t[0].parameter==="*",r=Number.parseInt(e.state.env.get("#")||"0",10);if(r===0)return{values:[],quoted:!1};let s=[];for(let u=1;u<=r;u++)s.push(e.state.env.get(String(u))||"");let i=Ae(e.state.env),a=Ne(e.state.env),o=Lr(e.state.env),l;if(n)if(a)l=s.filter(u=>u!=="");else{let u=H(e.state.env),c=s.join(u);l=ce(c,i,e.limits.maxArrayElements)}else if(a)l=s.filter(u=>u!=="");else if(o){l=[];for(let u of s){if(u==="")continue;let c=ce(u,i,e.limits.maxArrayElements);Re(l,c,e.limits.maxArrayElements,"unquoted expansion")}}else{l=[];for(let u of s)if(u==="")l.push("");else{let c=ce(u,i,e.limits.maxArrayElements);Re(l,c,e.limits.maxArrayElements,"unquoted expansion")}for(;l.length>0&&l[l.length-1]==="";)l.pop()}return{values:await Ur(e,l),quoted:!1}}async function pu(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=Z(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=Ae(e.state.env),l=Ne(e.state.env),u=Lr(e.state.env),c;if(s)if(l)c=a.filter(f=>f!=="");else{let f=H(e.state.env),d=a.join(f);c=ce(d,o,e.limits.maxArrayElements)}else if(l)c=a.filter(f=>f!=="");else if(u){c=[];for(let f of a){if(f==="")continue;let d=ce(f,o,e.limits.maxArrayElements);Re(c,d,e.limits.maxArrayElements,"unquoted expansion")}}else{c=[];for(let f of a)if(f==="")c.push("");else{let d=ce(f,o,e.limits.maxArrayElements);Re(c,d,e.limits.maxArrayElements,"unquoted expansion")}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Ur(e,c),quoted:!1}}function hu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let n=t[0].operation,r=Nn(e,n.prefix);if(r.length===0)return{values:[],quoted:!1};let s=Ae(e.state.env),i=Ne(e.state.env),a;if(n.star)if(i)a=r;else{let o=H(e.state.env),l=r.join(o);a=ce(l,s,e.limits.maxArrayElements)}else if(i)a=r;else{a=[];for(let o of r){let l=ce(o,s,e.limits.maxArrayElements);Re(a,l,e.limits.maxArrayElements,"unquoted expansion")}}return{values:a,quoted:!1}}function mu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let n=t[0].operation,s=Z(e,n.array).map(([l])=>String(l));if(s.length===0)return{values:[],quoted:!1};let i=Ae(e.state.env),a=Ne(e.state.env),o;if(n.star)if(a)o=s;else{let l=H(e.state.env),u=s.join(l);o=ce(u,i,e.limits.maxArrayElements)}else if(a)o=s;else{o=[];for(let l of s){let u=ce(l,i,e.limits.maxArrayElements);Re(o,u,e.limits.maxArrayElements,"unquoted expansion")}}return{values:o,quoted:!1}}async function yu(e,t,n){let r=-1;for(let d=0;d<t.length;d++){let p=t[d];if(p.type==="ParameterExpansion"&&(p.parameter==="@"||p.parameter==="*")&&!p.operation){r=d;break}}if(r===-1||t.length<=1)return null;let s=Number.parseInt(e.state.env.get("#")||"0",10),i=[];for(let d=1;d<=s;d++)i.push(e.state.env.get(String(d))||"");let 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=Ae(e.state.env),u=Ne(e.state.env),c=Lr(e.state.env);if(s===0){let d=a+o;return{values:d?[d]:[],quoted:!1}}let f;{let d=[];for(let p=0;p<i.length;p++){let h=i[p];p===0&&(h=a+h),p===i.length-1&&(h=h+o),d.push(h)}if(u)f=d.filter(p=>p!=="");else if(c){f=[];for(let p of d){if(p==="")continue;let h=ce(p,l,e.limits.maxArrayElements);Re(f,h,e.limits.maxArrayElements,"unquoted expansion")}}else{f=[];for(let p of d)if(p==="")f.push("");else{let h=ce(p,l,e.limits.maxArrayElements);Re(f,h,e.limits.maxArrayElements,"unquoted expansion")}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Ur(e,f),quoted:!1}}async function Eu(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:u,hasIndirection:c}=Jn(r),d=n.hasBraceExpansion(r)?await n.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return dp(e,d,s);let p=await pp(e,r,o,u,c,n);if(p!==null)return p;let h=await mp(e,r,n);if(h!==null)return h;let m=await yp(e,r,n);if(m!==null)return m;let E=await wp(e,r,n.expandPart);if(E!==null)return wu(e,E);if((i||a||l)&&!Ne(e.state.env)){let g=Ae(e.state.env),y=n.buildIfsCharClassPattern(g),S=await n.smartWordSplit(e,r,g,y,n.expandPart);return wu(e,S)}let b=await n.expandWordAsync(e,t);return Ep(e,t,r,b,s,n.expandWordForGlobbing)}async function dp(e,t,n){let r=[];for(let s of t)if(!(!n&&s===""))if(!n&&!e.state.options.noglob&&bt(s,e.state.shoptOptions.extglob)){let i=await jr(e,s);Re(r,i,e.limits.maxArrayElements,"brace/glob expansion")}else r.push(s);return{values:r,quoted:!1}}async function pp(e,t,n,r,s,i){if(n){let a=Yl(e,t);if(a!==null)return a}{let a=Jl(e,t);if(a!==null)return a}{let a=await Zl(e,t);if(a!==null)return a}{let a=await Hl(e,t,n,i.expandPart,i.expandWordPartsAsync);if(a!==null)return a}{let a=await Ql(e,t,n,i.expandPart);if(a!==null)return a}{let a=await Kl(e,t,i.evaluateArithmetic);if(a!==null)return a}{let a=Xl(e,t);if(a!==null)return a}{let a=await jl(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}{let a=await Gl(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let a=hp(e,t);if(a!==null)return a}{let a=await eu(e,t,s,i.expandParameterAsync,i.expandWordPartsAsync);if(a!==null)return a}{let a=await tu(e,t);if(a!==null)return a}{let a=await nu(e,t);if(a!==null)return a}return null}function hp(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=Nn(e,r.prefix);return r.star?{values:[s.join(H(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=Z(e,r.array).map(([a])=>String(a));return r.star?{values:[i.join(H(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function mp(e,t,n){{let r=await su(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await iu(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await au(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await ou(e,t,n.expandPart);if(r!==null)return r}return null}async function yp(e,t,n){{let r=await lu(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await uu(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await cu(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await fu(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await du(e,t);if(r!==null)return r}{let r=await pu(e,t);if(r!==null)return r}{let r=hu(e,t);if(r!==null)return r}{let r=mu(e,t);if(r!==null)return r}{let r=await yu(e,t,n.expandPart);if(r!==null)return r}return null}function gu(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 gp(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=Z(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=H(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 wp(e,t,n){if(t.length<2)return null;let r=!1;for(let l of t)if(gu(l)){r=!0;break}if(!r)return null;let s=Ae(e.state.env),i=Ne(e.state.env),a=[];for(let l of t){let u=gu(l);if(u&&l.type==="DoubleQuoted"){let c=await gp(e,l,u,n);a.push(c)}else if(l.type==="DoubleQuoted"||l.type==="SingleQuoted"){let c=await n(e,l);a.push([c])}else if(l.type==="Literal")a.push([l.value]);else if(l.type==="ParameterExpansion"){let c=await n(e,l);if(i)a.push(c?[c]:[]);else{let f=ce(c,s,e.limits.maxArrayElements);a.push(f)}}else{let c=await n(e,l);if(i)a.push(c?[c]:[]);else{let f=ce(c,s,e.limits.maxArrayElements);a.push(f)}}}let o=[];for(let l of a)if(l.length!==0)if(o.length===0)Re(o,l,e.limits.maxArrayElements,"word expansion");else{let u=o.length-1;o[u]=o[u]+l[0];for(let c=1;c<l.length;c++)o.push(l[c])}return o}async function wu(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let n=[];for(let r of t)if(bt(r,e.state.shoptOptions.extglob)){let s=await jr(e,r);Re(n,s,e.limits.maxArrayElements,"glob expansion")}else n.push(r);return{values:n,quoted:!1}}async function jr(e,t){let n=new Bt(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 Nt(t);return n.hasNullglob()?[]:[t]}async function Ep(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(bt(o,e.state.shoptOptions.extglob)){let u=await jr(e,o);if(u.length>0&&u[0]!==o)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let l=vi(r);if(!Ne(e.state.env)){let u=Ae(e.state.env);return{values:ce(l,u,e.limits.maxArrayElements),quoted:!1}}return{values:[l],quoted:!1}}if(!s&&!e.state.options.noglob&&bt(r,e.state.shoptOptions.extglob)){let o=await i(e,t);if(bt(o,e.state.shoptOptions.extglob)){let l=await jr(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=vi(r);if(!Ne(e.state.env)){let l=Ae(e.state.env);return{values:ce(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 k(`word splitting element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");t.push(n)}async function Su(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 Et(e,t.parameter),a=await re(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 bp(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(n=>n.type==="Literal"):!1}async function Sp(e,t){if(t.type!=="ParameterExpansion")return null;let n=await Su(e,t);if(!n||n.length<=1)return null;let r=n.some(i=>bp(i)),s=n.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&s?n:null}function Ap(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?mi(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&wl(e))}async function Au(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let d=t[0],p=await Su(e,d);if(p&&p.length>0&&p.length>1&&p.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&p.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return bu(e,p,n,r,s)}let i=[],a=!1;for(let d of t){let p=Ap(d),h=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=p?await Sp(e,d):null,E=await s(e,d);i.push({value:E,isSplittable:p,isQuoted:h,mixedDefaultParts:m??void 0}),p&&(a=!0)}if(!a){let d=i.map(p=>p.value).join("");return d?[d]:[]}let o=[],l="",u=!1,c=!1,f=!1;for(let d of i)if(!d.isSplittable)c?d.isQuoted&&d.value===""?(l!==""&&Oe(e,o,l),Oe(e,o,""),u=!0,l="",c=!1,f=!0):d.value!==""?(l!==""&&Oe(e,o,l),l=d.value,c=!1,f=!1):(l+=d.value,f=!1):(l+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let p=await bu(e,d.mixedDefaultParts,n,r,s);if(p.length!==0)if(p.length===1)l+=p[0],u=!0;else{l+=p[0],Oe(e,o,l),u=!0;for(let h=1;h<p.length-1;h++)Oe(e,o,p[h]);l=p[p.length-1]}c=!1,f=!1}else{let{words:p,hadLeadingDelimiter:h,hadTrailingDelimiter:m}=Tr(d.value,n,e.limits.maxArrayElements);if(f&&h&&l===""&&(Oe(e,o,""),u=!0),p.length===0)m&&(c=!0);else if(p.length===1)l+=p[0],u=!0,c=m;else{l+=p[0],Oe(e,o,l),u=!0;for(let E=1;E<p.length-1;E++)Oe(e,o,p[E]);l=p[p.length-1],c=m}f=!1}return l!==""?Oe(e,o,l):o.length===0&&u&&Oe(e,o,""),o}function vp(e,t){return e.length>0&&t.includes(e[0])}async function bu(e,t,n,r,s){let i=[];for(let c of t){let d=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),p=await s(e,c);i.push({value:p,isSplittable:d})}let a=[],o="",l=!1,u=!1;for(let c of i)if(!c.isSplittable)u&&c.value!==""?(o!==""&&Oe(e,a,o),o=c.value,u=!1):o+=c.value;else{vp(c.value,n)&&o!==""&&(Oe(e,a,o),o="",l=!0);let{words:d,hadTrailingDelimiter:p}=Tr(c.value,n,e.limits.maxArrayElements);if(d.length===0)p&&(u=!0);else if(d.length===1)o+=d[0],l=!0,u=p;else{o+=d[0],Oe(e,a,o),l=!0;for(let h=1;h<d.length-1;h++)Oe(e,a,d[h]);o=d[d.length-1],u=p}}return o!==""?Oe(e,a,o):a.length===0&&l&&Oe(e,a,""),a}function vu(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function $u(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}var nr=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new yt,t?.mounts)for(let{mountPoint:n,filesystem:r}of t.mounts)this.mount(n,r)}mount(t,n){this.validateMountPath(t);let r=z(t);this.validateMount(r),this.mounts.set(r,{mountPoint:r,filesystem:n})}unmount(t){let n=z(t);if(!this.mounts.has(n))throw new Error(`No filesystem mounted at '${t}'`);this.mounts.delete(n)}getMounts(){return Array.from(this.mounts.values()).map(t=>({mountPoint:t.mountPoint,filesystem:t.filesystem}))}isMountPoint(t){let n=z(t);return this.mounts.has(n)}validateMountPath(t){let n=t.split("/");for(let r of n)if(r==="."||r==="..")throw new Error(`Invalid mount point '${t}': contains '.' or '..' segments`)}validateMount(t){if(t==="/")throw new Error("Cannot mount at root '/'");for(let n of this.mounts.keys())if(n!==t){if(t.startsWith(`${n}/`))throw new Error(`Cannot mount at '${t}': inside existing mount '${n}'`);if(n.startsWith(`${t}/`))throw new Error(`Cannot mount at '${t}': would contain existing mount '${n}'`)}}routePath(t){Q(t,"access");let n=z(t),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=z(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 mn(n,r)}async readFileBuffer(t){let{fs:n,relativePath:r}=this.routePath(t);return n.readFileBuffer(r)}async writeFile(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.writeFile(i,n,r)}async appendFile(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.appendFile(i,n,r)}async exists(t){let n=z(t);if(this.mounts.has(n)||this.getChildMountPoints(n).length>0)return!0;let{fs:s,relativePath:i}=this.routePath(t);return s.exists(i)}async stat(t){let n=z(t),r=this.mounts.get(n);if(r)try{return await r.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=z(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=z(t);if(this.mounts.has(r)){if(n?.recursive)return;throw new Error(`EEXIST: directory already exists, mkdir '${t}'`)}if(this.getChildMountPoints(r).length>0&&n?.recursive)return;let{fs:i,relativePath:a}=this.routePath(t);return i.mkdir(a,n)}async readdir(t){let n=z(t),r=new Set,s=null,{fs:i,relativePath:a}=this.routePath(t);try{let l=await i.readdir(a);for(let u of l)r.add(u)}catch(l){let u=l.code,c=l.message||"";if(u!=="ENOENT"&&!c.includes("ENOENT"))throw l;s=l}let 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=z(t);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot remove '${t}'`);if(this.getChildMountPoints(r).length>0)throw new Error(`EBUSY: contains mount points, cannot remove '${t}'`);let{fs:i,relativePath:a}=this.routePath(t);return i.rm(a,n)}async cp(t,n,r){if((await this.stat(t)).isDirectory&&$t(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=z(t);if((await this.stat(t)).isDirectory&&$t(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 En(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=z(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=z(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=xt(t,a),l=xt(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)}};var Gr="/dev/fd",ku=63,$p=10,xu=ku-$p+1,Ci=class extends yt{isLiveDescriptor;constructor(t){super(),this.isLiveDescriptor=t}assertLiveDescriptor(t,n){this.isLiveDescriptor(t)||this.refuse(t,n)}refuse(t,n){throw new Error(`EROFS: read-only file system, ${n} '${Gr}${t}'`)}async writeFile(t,n,r){return this.assertLiveDescriptor(t,"write"),super.writeFile(t,n,r)}async appendFile(t,n,r){return this.assertLiveDescriptor(t,"append"),super.appendFile(t,n,r)}async rm(t,n){return this.assertLiveDescriptor(t,"rm"),super.rm(t,n)}async mkdir(t,n){this.refuse(t,"mkdir")}async cp(t,n){this.refuse(n,"cp")}async mv(t,n){this.refuse(n,"mv")}async symlink(t,n){this.refuse(n,"symlink")}async link(t,n){this.refuse(n,"link")}async chmod(t,n){this.refuse(t,"chmod")}async utimes(t,n,r){this.refuse(t,"utimes")}};function xp(e){let t=new Ci(n=>Pu(e).some(r=>r.path===`${Gr}${n}`));e.fs=new nr({base:e.fs,mounts:[{mountPoint:Gr,filesystem:t}]}),e.state.processSubstitutionFsMounted=!0}async function kp(e,t,n){try{await e.fs.writeFile(t,n,"binary");return}catch(r){if(e.state.processSubstitutionFsMounted)throw r;xp(e)}await e.fs.writeFile(t,n,"binary")}async function Pp(e,t){try{await e.fs.rm(t,{force:!0})}catch{}}function Pu(e){let t=e.state.processSubstitutions;if(t)return t;let n=[];return e.state.processSubstitutions=n,n}async function Cu(e,t,n){let r=e.substitutionDepth??0,s=e.limits.maxSubstitutionDepth;if(r>=s)throw new k(`Process substitution nesting limit exceeded (${s})`,"substitution_depth");let i=e.substitutionDepth,a=new Map(e.state.env),o=nt(e.state.arrays),l=e.state.cwd,u=e.state.bashPid,c=e.state.suppressVerbose,f=e.state.groupStdin,d=e.state.lastExitCode,p=e.state.env.get("?");e.substitutionDepth=r+1,e.state.bashPid=e.state.nextVirtualPid++,e.state.suppressVerbose=!0,n!==void 0&&(e.state.groupStdin=n);let h;try{h=await e.executeScript(t)}catch(m){if(m instanceof k)throw m;if(m instanceof U)return{stdout:m.stdout,stderr:m.stderr,exitCode:m.exitCode};throw m}finally{e.substitutionDepth=i,e.state.env=a,e.state.arrays=o,e.state.cwd=l,e.state.bashPid=u,e.state.suppressVerbose=c,e.state.groupStdin=f,e.state.lastExitCode=d,p!==void 0?e.state.env.set("?",p):e.state.env.delete("?")}return h}async function Nu(e,t){let n=Pu(e);if(n.length>=xu)throw new k(`Process substitution limit exceeded (${xu} concurrent)`,"file_descriptors");let r="";if(t.direction==="input"){let a=await Cu(e,t.body,void 0);if(a.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+a.stderr),r=Ct(a),r.length>e.limits.maxStringLength)throw new k(`process substitution: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")}let s=ku-n.length,i=`${Gr}/${s}`;n.push({fd:s,path:i,direction:t.direction,body:t.body});try{await kp(e,i,r)}catch(a){throw n.pop(),a}return i}function Ru(e){return e.state.processSubstitutions?.length??0}var Cp={stdout:"",stderr:""};async function Ni(e,t){let n=e.state.processSubstitutions;if(!n||n.length<=t)return Cp;let r="",s="";for(;n.length>t;){let i=n[n.length-1],a="";if(i.direction==="output")try{a=await mn(e.fs,i.path)}catch{}if(await Pp(e,i.path),n.pop(),i.direction==="output"){let o=await Cu(e,i.body,a);r+=Ct(o),s+=o.stderr}}return{stdout:r,stderr:s}}function qt(e,t,n){if(e.length>t)throw new k(`${n}: string length limit exceeded (${t} bytes)`,"string_length")}async function pt(e,t,n=!1){let r=[];for(let s of t)r.push(await Xe(e,s,n));return r.join("")}function Np(e){return $u(e)}function Iu(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!Np(t))return!1;return!0}function Rp(e,t,n=!1){let r=vu(t);if(r!==null)return r;switch(t.type){case"TildeExpansion":return n?t.user===null?"~":`~${t.user}`:(e.coverage?.hit("bash:expansion:tilde"),t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`);case"Glob":return $i(e,t.pattern);default:return null}}async function ne(e,t){return Di(e,t)}async function Ou(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped")n.push(Cn(r.value));else if(r.type==="SingleQuoted")n.push(r.value);else if(r.type==="DoubleQuoted"){let s=await pt(e,r.parts);n.push(s)}else if(r.type==="TildeExpansion"){let s=await Xe(e,r);n.push(Cn(s))}else n.push(await Xe(e,r));return n.join("")}async function _u(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(Ke(r.value));else if(r.type==="DoubleQuoted"){let s=await pt(e,r.parts);n.push(Ke(s))}else n.push(await Xe(e,r));return n.join("")}async function Lu(e,t){let n=[];for(let r of t.parts)if(r.type==="SingleQuoted")n.push(Ke(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 pt(e,r.parts);n.push(Ke(s))}else r.type==="Glob"?zl(r.pattern)?n.push(await Ul(e,r.pattern)):n.push($i(e,r.pattern)):r.type==="Literal"?n.push(r.value):n.push(await Xe(e,r));return n.join("")}function Hr(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&Hr(t.parts))return!0;return!1}var Du=1e5;async function Tu(e,t,n={count:0}){let r=()=>{n.count++,e.executionScope.consumeLimited("brace_operations",1,Math.min(Du,e.limits.maxBraceExpansionResults),"brace expansion")},s=(a,o)=>{if(a.length>=e.limits.maxBraceExpansionResults)throw new k(`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,u="";for(let d of a.items)if(d.type==="Range"){let p=Ai(d.start,d.end,d.step,d.startStr,d.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(p.expanded)for(let h of p.expanded)s(o,h);else{l=!0,u=p.literal;break}}else{let p=await Tu(e,d.word.parts,n);for(let h of p){let m=[];for(let E of h)typeof E=="string"?m.push(E):m.push(await Xe(e,E));s(o,m.join(""))}}if(l){for(let d of i)r(),d.push(u);continue}if(i.length*o.length>e.limits.maxBraceExpansionResults||n.count>Du)throw new k(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");let f=[];for(let d of i)for(let p of o){if(f.length>=e.limits.maxBraceExpansionResults)throw new k(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),f.push([...d,p])}i=f}else for(let o of i)r(),o.push(a);return i}async function Mu(e,t){let n=t.parts;if(!Hr(n))return[await ne(e,t)];let r=await Tu(e,n),s=[];for(let i of r){let a=[];for(let o of i)typeof o=="string"?a.push(o):a.push(await Xe(e,o));s.push(xi(e,a.join("")))}return s}function Dp(){return{expandWordAsync:Di,expandWordForGlobbing:Lu,expandWordWithBracesAsync:Mu,expandWordPartsAsync:pt,expandPart:Xe,expandParameterAsync:Zr,hasBraceExpansion:Hr,evaluateArithmetic:K,buildIfsCharClassPattern:El,smartWordSplit:Au}}async function ht(e,t){return Eu(e,t,Dp())}function Ip(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Ri(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 Fu(e,t){if(Ri(e,t))return{error:`bash: $@: ambiguous redirect
108
- `};let n=t.parts,{hasQuoted:r}=Jn(n);if(Hr(n)&&(await Mu(e,t)).length>1)return{error:`bash: ${n.map(p=>p.type==="Literal"?p.value:p.type==="BraceExpansion"?`{${p.items.map(m=>{if(m.type==="Range"){let E=m.step?`..${m.step}`:"";return`${m.startStr??m.start}..${m.endStr??m.end}${E}`}return m.word.parts.map(E=>E.type==="Literal"?E.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect
109
- `};let s=await Di(e,t),{hasParamExpansion:i,hasCommandSub:a}=Jn(n);if((i||a)&&!r&&!Ne(e.state.env)){let f=Ae(e.state.env);if(ce(s,f,e.limits.maxArrayElements).length>1)return{error:`bash: $${Ip(n)}: ambiguous redirect
110
- `}}if(r||e.state.options.noglob||n.some(f=>f.type==="ProcessSubstitution"))return{target:s};let l=await Lu(e,t);if(!bt(l,e.state.shoptOptions.extglob))return{target:s};let u=new Bt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")}),c=await u.expand(l);return c.length===0?u.hasFailglob()?{error:`bash: no match: ${s}
97
+ ${e.terminator}`}function Zd(e){return`(${it(e.body)})${ht(e.redirections)}`}function Qd(e){return`{ ${it(e.body)}; }${ht(e.redirections)}`}function Kd(e){return`((${fe(e.expression.expression)}))${ht(e.redirections)}`}function Xd(e){return`[[ ${gn(e.expression)} ]]${ht(e.redirections)}`}function Yd(e){let t=gl(e.body);return`${e.name}() ${t}${ht(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 gn(e){switch(e.type){case"CondBinary":return`${Se(e.left)} ${e.operator} ${Se(e.right)}`;case"CondUnary":return`${e.operator} ${Se(e.operand)}`;case"CondNot":return`! ${gn(e.operand)}`;case"CondAnd":return`${gn(e.left)} && ${gn(e.right)}`;case"CondOr":return`${gn(e.left)} || ${gn(e.right)}`;case"CondGroup":return`( ${gn(e.expression)} )`;case"CondWord":return Se(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var Jd="BASH_ALIAS_";function Vr(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 Sl(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function Al(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function vl(e,t){return e.env.get(`${Jd}${t}`)}function xl(e,t,n){return kl(e,t,n)}function kl(e,t,n,r=!0){if(!t.name||!Sl(t.name))return t;let s=Al(t.name);if(!s)return t;let i=vl(e,s);if(!i||n.has(s))return t;try{n.add(s);let a=new j,o={value:0},l=Vr("",i,e.limits.maxStringLength,o),u=i.endsWith(" ");if(!u)for(let p of t.args){let h=Se(p);l=Vr(l,` ${h}`,e.limits.maxStringLength,o)}let c;try{c=a.parse(l)}catch(p){if(p instanceof $e)throw p;return t}if(c.statements.length!==1||c.statements[0].pipelines.length!==1||c.statements[0].pipelines[0].commands.length!==1)return $l(e,t,i);let f=c.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return $l(e,t,i);let d={...f,assignments:[...t.assignments,...f.assignments],redirections:[...f.redirections,...t.redirections],line:t.line};if(u&&t.args.length>0){d={...d,args:[...d.args,...t.args]};let p=1;for(;r&&d.args.length>0;){let h=d.args[0];if(!Sl(h))break;let m=Al(h),E=m?vl(e,m):null;if(!E)break;if(p>=e.limits.maxCallDepth)throw new P(`alias expansion depth limit exceeded (${e.limits.maxCallDepth})`,"recursion");p++;let S={type:"SimpleCommand",name:h,args:d.args.slice(1),assignments:[],redirections:[]},y=kl(e,S,n,!1);if(y===S||(d={...d,name:y.name,args:[...y.args]},!E.endsWith(" ")))break}}return d}catch(a){throw n.delete(s),a}}function $l(e,t,n){let r={value:0},s=Vr("",n,e.limits.maxStringLength,r);for(let u of t.args){let c=Se(u);s=Vr(s,` ${c}`,e.limits.maxStringLength,r)}let i=new j,a=i.parseWordFromString("eval",!1,!1),o=0;for(let u of s)u==="'"&&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}}var ep=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 Ei(e){return ep.get(e)??""}function Pl(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 Cl(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 u=e.slice(s+2,l),c=Ei(u);i+=c,s=l+2;continue}}if(e[s]==="\\"&&s+1<e.length){i+=`\\${e[s+1]}`,s+=2;continue}if(e[s]==="-"){let l=s===o,u=s+1===a;l||u?i+="\\-":i+="-"}else i+=e[s];s++}i+="]",t+=i,n=s}else if(r==="\\"&&n+1<e.length){let s=e[n+1];/[.+^${}()|\\*?[\]]/.test(s)?t+=`\\${s}`:t+=s,n++}else/[.+^${}()|]/.test(r)?t+=`\\${r}`:t+=r}return t+="$",me(t)}function bi(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 Si(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 Nl=5,Gt=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=Pl(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 Cl(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>Nl))throw new P(`Glob pattern has too many ** segments (max ${Nl})`,"glob_operations")}let n;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))n=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");n=await this.expandSimple(r)}return this.filterGlobignore(n)}isGlobstarValid(t){let n=t.split("/");for(let r of n)if(r.includes("**")&&r!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let n=t.startsWith("/"),r=t.split("/").filter(u=>u!==""),s=-1;for(let u=0;u<r.length;u++)if(this.hasGlobChars(r[u])){s=u;break}if(s===-1)return[t];let i,a;if(s===0)n?(i="/",a="/"):(i=this.cwd,a="");else{let u=r.slice(0,s);n?(i=`/${u.join("/")}`,a=`/${u.join("/")}`):(i=this.fs.resolvePath(this.cwd,u.join("/")),a=u.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=[],u=[...o],c=this.dotglob||this.hasGlobignore;if(s.startsWith(".")||this.dotglob){let d=o.some(h=>h.name==="."),p=o.some(h=>h.name==="..");d||u.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),p||u.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of u)if(!(d.name.startsWith(".")&&!s.startsWith(".")&&!c)&&this.matchPattern(d.name,s)){let p=t==="/"?`/${d.name}`:`${t}/${d.name}`,h;n===""?h=d.name:n==="/"?h=`/${d.name}`:h=`${n}/${d.name}`,i.length===0?l.push(Promise.resolve([h])):d.isDirectory&&l.push(this.expandSegments(p,h,i))}let f=await Promise.all(l);for(let d of f)a.push(...d)}else{this.checkOpsLimit();let o=await this.fs.readdir(t),l=[],u=[...o],c=this.dotglob||this.hasGlobignore;(s.startsWith(".")||this.dotglob)&&(o.includes(".")||u.push("."),o.includes("..")||u.push(".."));for(let d of u)if(!(d.startsWith(".")&&!s.startsWith(".")&&!c)&&this.matchPattern(d,s)){let p=t==="/"?`/${d}`:`${t}/${d}`,h;n===""?h=d:n==="/"?h=`/${d}`:h=`${n}/${d}`,i.length===0?l.push(Promise.resolve([h])):l.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(p)).isDirectory)return this.expandSegments(p,h,i)}catch(m){if(m instanceof P)throw m}return[]})())}let f=await Promise.all(l);for(let d of f)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 u of i){let c=t==="."?u.name:`${t}/${u.name}`;u.isDirectory&&a.push(c)}let o=t==="."?n:`${t}/${n}`,l=await this.expandRecursive(o);r.push(...l);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,n,r)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(s),o=[];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&&o.push(f)}catch(p){if(p instanceof P)throw p}}let l=t==="."?n:`${t}/${n}`,u=await this.expandRecursive(l);r.push(...u);for(let c=0;c<o.length;c+=100){let f=o.slice(c,c+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,n,r)))}}}catch(i){if(i instanceof P)throw i}}async walkDirectory(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let i=await this.fs.readdirWithFileTypes(s),a=[],o=[];for(let l of i){let u=t==="."?l.name:`${t}/${l.name}`;l.isDirectory?o.push(u):n&&this.matchPattern(l.name,n)&&a.push(u)}r.push(...a);for(let l=0;l<o.length;l+=100){let u=o.slice(l,l+100);await Promise.all(u.map(c=>this.walkDirectory(c,n,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(s),a=[];for(let l=0;l<i.length;l+=100){let u=i.slice(l,l+100),c=await Promise.all(u.map(async f=>{let d=t==="."?f:`${t}/${f}`,p=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let h=await this.fs.stat(p);return{name:f,path:d,isDirectory:h.isDirectory}}catch(h){if(h instanceof P)throw h;return null}}));a.push(...c.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 u=o.slice(l,l+100);await Promise.all(u.map(c=>this.walkDirectory(c.path,n,r)))}}}catch(i){if(i instanceof P)throw i}}matchPattern(t,n){return this.patternToRegex(n).test(t)}patternToRegex(t){let n=this.patternToRegexStr(t);return me(`^${n}$`)}patternToRegexStr(t){let n="",r=!1;for(let s=0;s<t.length;s++){if(t.slice(s,s+13)==="\0QUOTE_START\0"){r=!0,s+=12;continue}if(t.slice(s,s+11)==="\0QUOTE_END\0"){r=!1,s+=10;continue}let i=t[s];if(r){/[.+^${}()|\\*?[\]]/.test(i)?n+=`\\${i}`:n+=i;continue}if(this.extglob&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&s+1<t.length&&t[s+1]==="("){let a=bi(t,s+1);if(a!==-1){let o=t.slice(s+2,a),l=Si(o),u=l.map(f=>this.patternToRegexStr(f)),c=u.length>0?u.join("|"):"(?:)";if(i==="@")n+=`(?:${c})`;else if(i==="*")n+=`(?:${c})*`;else if(i==="+")n+=`(?:${c})+`;else if(i==="?")n+=`(?:${c})?`;else if(i==="!")if(a<t.length-1){let d=l.map(h=>this.computePatternLength(h));if(d.every(h=>h!==null)&&d.every(h=>h===d[0])&&d[0]!==null){let h=d[0];if(h===0)n+="(?:.+)";else{let m=[];h>0&&m.push(`.{0,${h-1}}`),m.push(`.{${h+1},}`),m.push(`(?!(?:${c})).{${h}}`),n+=`(?:${m.join("|")})`}}else n+=`(?:(?!(?:${c})).)*?`}else n+=`(?!(?:${c})$).*`;s=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 c=t.indexOf(":]",l+2);if(c!==-1){l=c+2;continue}}if(t[l]==="]")break;l++}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=Ei(f);o+=d,a=c+2;continue}}if(t[a]==="\\"&&a+1<t.length){o+=`\\${t[a+1]}`,a+=2;continue}if(t[a]==="-"){let c=a===u,f=a+1===l;c||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=bi(t,r+1);if(a!==-1){if(i==="@"){let o=t.slice(r+2,a),u=Si(o).map(c=>this.computePatternLength(c));if(u.every(c=>c!==null)&&u.every(c=>c===u[0])){n+=u[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 Ai(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 tp(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 Rl(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 or(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 u of l.parts)u.type==="ParameterExpansion"&&(u.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!u.operation||u.operation.type==="PatternRemoval"||u.operation.type==="PatternReplacement")&&(s=!0),(u.operation?.type==="VarNamePrefix"||u.operation?.type==="ArrayKeys")&&(a=!0),u.operation?.type==="Indirection"&&(o=!0));l.type==="CommandSubstitution"&&(n=!0),l.type==="ParameterExpansion"&&(i=!0,(l.parameter==="@"||l.parameter==="*")&&(r=!0),tp(l)&&(t=!0),(l.operation?.type==="VarNamePrefix"||l.operation?.type==="ArrayKeys")&&(a=!0),l.operation?.type==="Indirection"&&(o=!0)),l.type==="Glob"&&Ai(l.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i,hasVarNamePrefixExpansion:a,hasIndirection:o}}var np=`
98
+ `;function En(e,t){if(e>=t)throw new P(`array element limit exceeded (${t})`,"array_elements")}function vi(e,t,n,r,s){En(e.length,s),En(t.length,s),e.push(n),t.push(r)}function Ae(e){return e.get("IFS")??np}function Ne(e){return e.get("IFS")===""}function zr(e){let t=Ae(e);if(t==="")return!0;for(let n of t)if(n!==" "&&n!==" "&&n!==`
99
+ `)return!1;return!0}function Dl(e){let t=!1,n=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?n.push(`\\${r}`):r===" "?n.push("\\t"):r===`
100
+ `?n.push("\\n"):n.push(r);return t&&n.push("\\-"),n.join("")}function Z(e){let t=e.get("IFS");if(t===void 0)return" ";let n=t.codePointAt(0);return n===void 0?"":String.fromCodePoint(n)}var rp=`
101
+ `;function sp(e){return rp.includes(e)}function $i(e){let t=new Set,n=new Set;for(let r of e)sp(r)?t.add(r):n.add(r);return{whitespace:t,nonWhitespace:n}}function xi(e,t,n,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:(En(0,n),{words:[e],wordStarts:[0]});let{whitespace:i,nonWhitespace:a}=$i(t),o=[],l=[],u=0;for(;u<e.length&&i.has(e[u]);)u++;if(u>=e.length)return{words:[],wordStarts:[]};if(a.has(e[u]))for(vi(o,l,"",u,n),u++;u<e.length&&i.has(e[u]);)u++;for(;u<e.length&&!(r!==void 0&&o.length>=r);){let c=u;for(;u<e.length;){let f=e[u];if(!s&&f==="\\"){u++,u<e.length&&u++;continue}if(i.has(f)||a.has(f))break;u++}if(vi(o,l,e.substring(c,u),c,n),u>=e.length)break;for(;u<e.length&&i.has(e[u]);)u++;if(u<e.length&&a.has(e[u])){for(u++;u<e.length&&i.has(e[u]);)u++;for(;u<e.length&&a.has(e[u])&&!(r!==void 0&&o.length>=r);)for(vi(o,l,"",u,n),u++;u<e.length&&i.has(e[u]);)u++}}return{words:o,wordStarts:l}}function qr(e,t,n){if(t==="")return e&&En(0,n),{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=$i(t),i=[],a=0,o=!1,l=!1,u=a;for(;a<e.length&&r.has(e[a]);)a++;if(a>u&&(o=!0),a>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[a]))for(En(i.length,n),i.push(""),a++;a<e.length&&r.has(e[a]);)a++;for(;a<e.length;){let c=a;for(;a<e.length;){let d=e[a];if(r.has(d)||s.has(d))break;a++}if(En(i.length,n),i.push(e.substring(c,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(En(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 ce(e,t,n){return qr(e,t,n).words}function ip(e,t){for(let n of e)if(t.has(n))return!0;return!1}function Il(e,t,n){if(t==="")return e;let{whitespace:r,nonWhitespace:s}=$i(t),i=e.length;for(;i>0&&r.has(e[i-1]);){if(!n&&i>=2){let 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,u=a.length-2;for(;u>=0&&a[u]==="\\";)l++,u--;if(l%2===1)return a}let o=a.substring(0,a.length-1);if(!ip(o,s))return o}return a}function le(e,t){return e.state.namerefs?.has(t)??!1}function Ot(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function Ol(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function _l(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function Ll(e,t){return e.state.invalidNamerefs?.has(t)??!1}function ki(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function Ur(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let s=n[1],i=Pe(e,s),a=e.state.associativeArrays?.has(s)??!1;return i||a}return Pe(e,t)?!0:e.state.env.has(t)}function Me(e,t,n=100){if(!le(e,t)||Ll(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 bn(e,t){if(le(e,t))return e.state.env.get(t)}function jr(e,t,n,r=100){if(!le(e,t)||Ll(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)&&Ur(e,n)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(a))return i;i=a}}function Tl(e,t){let n=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(r,s)=>e.state.env.get(s)??"");return n=n.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(r,s)=>e.state.env.get(s)??""),n}function G(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((i,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)?vt(e,t).map(i=>[i,ie(e,t,i)??""]):be(e,t).map(s=>[s,ie(e,t,s)??""])}function mt(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)?Pe(e,t):Pe(e,t)}async function re(e,t,n=!0){switch(t){case"?":return String(e.state.lastExitCode);case"$":return String(e.state.virtualPid);case"#":return e.state.env.get("#")||"0";case"@":return e.state.env.get("@")||"";case"_":return e.state.lastArg;case"-":{let i="";return i+="h",e.state.options.errexit&&(i+="e"),e.state.options.noglob&&(i+="f"),e.state.options.nounset&&(i+="u"),e.state.options.verbose&&(i+="v"),e.state.options.xtrace&&(i+="x"),i+="B",e.state.options.noclobber&&(i+="C"),i+="s",i}case"*":{let i=Number.parseInt(e.state.env.get("#")||"0",10);if(i===0)return"";let a=[];for(let o=1;o<=i;o++)a.push(e.state.env.get(String(o))||"");return a.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 No;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let i=e.state.funcNameStack?.[0];if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new We("FUNCNAME");return""}case"BASH_LINENO":{let i=e.state.callLineStack?.[0];if(i!==void 0)return String(i);if(n&&e.state.options.nounset)throw new We("BASH_LINENO");return""}case"BASH_SOURCE":{let i=e.state.sourceStack?.[0];if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new We("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new Ze(`\${${t}}`);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let i=r[1],a=r[2];if(le(e,i)){let c=Me(e,i);if(c&&c!==i){if(c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";i=c}}if(a==="@"||a==="*"){let c=G(e,i);if(c.length>0){let d=a==="*"?Z(e.state.env):" ",p=M(d)*(c.length-1);for(let[,h]of c)if(p+=M(h),p>e.limits.maxStringLength)throw new P(`array expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return c.map(([,h])=>h).join(d)}let f=e.state.env.get(i);return f!==void 0?f:""}if(i==="FUNCNAME"){let c=Number.parseInt(a,10);return!Number.isNaN(c)&&c>=0?e.state.funcNameStack?.[c]??"":""}if(i==="BASH_LINENO"){let c=Number.parseInt(a,10);if(!Number.isNaN(c)&&c>=0){let f=e.state.callLineStack?.[c];return f!==void 0?String(f):""}return""}if(i==="BASH_SOURCE"){let c=Number.parseInt(a,10);return!Number.isNaN(c)&&c>=0?e.state.sourceStack?.[c]??"":""}if(e.state.associativeArrays?.has(i)){let c=Ir(a);c=Tl(e,c);let f=ie(e,i,c);if(f===void 0&&n&&e.state.options.nounset)throw new We(`${i}[${a}]`);return f||""}let l;if(/^-?\d+$/.test(a))l=Number.parseInt(a,10);else try{let c=new j,f=te(c,a);l=await X(e,f.expression)}catch{let c=e.state.env.get(a);l=c?Number.parseInt(c,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let c=G(e,i),f=e.state.currentLine;if(c.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${i}: bad array subscript
102
+ `,"";let p=Math.max(...c.map(([m])=>typeof m=="number"?m:0))+1+l;return p<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${i}: bad array subscript
103
+ `,""):ie(e,i,p)||""}let u=ie(e,i,l);if(u!==void 0)return u;if(l===0){let c=e.state.env.get(i);if(c!==void 0)return c}if(n&&e.state.options.nounset)throw new We(`${i}[${l}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let i=e.state.env.get(t);if(i===void 0&&n&&e.state.options.nounset)throw new We(t);return i||""}if(le(e,t)){let i=Me(e,t);if(i===void 0)return"";if(i!==t)return await re(e,i,n);let a=e.state.env.get(t);if((a===void 0||a==="")&&n&&e.state.options.nounset)throw new We(t);return a||""}let s=e.state.env.get(t);if(s!==void 0)return e.state.tempEnvBindings?.some(i=>i.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),s;if(mt(e,t)){let i=ie(e,t,0);if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new We(t);return""}if(n&&e.state.options.nounset)throw new We(t);return""}async function xt(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=Me(e,s);if(l&&l!==s){if(l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;s=l}}if(i==="@"||i==="*")return G(e,s).length>0?!0:e.state.env.has(s);if(e.state.associativeArrays?.has(s)){let l=Tl(e,Ir(i));return qt(e,s,l)}let o;if(/^-?\d+$/.test(i))o=Number.parseInt(i,10);else try{let l=new j,u=te(l,i);o=await X(e,u.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=G(e,s);if(l.length===0)return!1;let c=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+o;return c<0?!1:qt(e,s,c)}return qt(e,s,o)}if(le(e,t)){let s=Me(e,t);return s===void 0||s===t?e.state.env.has(t):xt(e,s)}return e.state.env.has(t)?!0:mt(e,t)?qt(e,t,0):!1}async function Ml(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 re(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 re(e,i);n+=a,r=s;continue}if(/[*@#?\-!$]/.test(t[r+1]||"")){let s=t[r+1],i=await re(e,s);n+=i,r+=2;continue}}if(t[r]==='"'){for(n+='"',r++;r<t.length&&t[r]!=='"';)if(t[r]==="$"&&/[a-zA-Z_]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)s++;let i=t.slice(r+1,s),a=await re(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 Pi(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 u=n.slice(a+2,l-1);if(e.execFn){let c=await e.execFn(u,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}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 u=n.slice(a+2,l-1),c=await re(e,u);i+=c,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),u=await re(e,l);i+=u,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 u=await e.execFn(l,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}a=o+1}else i+=n[a],a++;return i}var lr=1e4,Ci={maxResults:lr,maxStringBytes:10*1024*1024};function Gr(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 ap(e,t,n,r,s,i=Ci){let a=n??1;a===0&&(a=1);let o=Math.abs(a),l=[],u=0;if(r?.match(/^-?0\d/)&&(u=Math.max(u,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(u=Math.max(u,s.replace(/^-/,"").length)),u>i.maxStringBytes)throw new P(`brace expansion padding limit exceeded (${i.maxStringBytes} bytes)`,"string_length");let c={value:0},f=d=>{if(u>0){let p=d<0,h=String(Math.abs(d)).padStart(u,"0");return p?`-${h}`:h}return String(d)};if(e<=t)for(let d=e,p=0;d<=t&&p<lr&&Gr(l,f(d),i,c);d+=o,p++);else for(let d=e,p=0;d>=t&&p<lr&&Gr(l,f(d),i,c);d-=o,p++);return l}function op(e,t,n,r=Ci){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",u=e>="a"&&e<="z",c=t>="A"&&t<="Z",f=t>="a"&&t<="z";if(l&&f||u&&c){let h=n!==void 0?`..${n}`:"";throw new kr(`{${e}..${t}${h}}: invalid sequence`)}let d=[],p={value:0};if(i<=a)for(let h=i,m=0;h<=a&&m<lr&&Gr(d,String.fromCharCode(h),r,p);h+=o,m++);else for(let h=i,m=0;h>=a&&m<lr&&Gr(d,String.fromCharCode(h),r,p);h-=o,m++);return d}function Ni(e,t,n,r,s,i=Ci){let a=n!==void 0?`..${n}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:ap(e,t,n,r,s,i),literal:`{${e}..${t}${a}}`}:typeof e=="string"&&typeof t=="string"?{expanded:op(e,t,n,i),literal:`{${e}..${t}${a}}`}:{expanded:null,literal:`{${e}..${t}${a}}`}}function Fl(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 kt(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function Ri(e){let t="",n=0;for(;n<e.length;)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);return t}function Xe(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function Tn(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function oe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function se(e,t,n=!1){let r="",s=0;for(;s<e.length;){let i=e[s];if(n&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&s+1<e.length&&e[s+1]==="("){let a=lp(e,s+1);if(a!==-1){let o=e.slice(s+2,a),u=up(o).map(f=>se(f,t,n)),c=u.length>0?u.join("|"):"(?:)";i==="@"?r+=`(?:${c})`:i==="*"?r+=`(?:${c})*`:i==="+"?r+=`(?:${c})+`:i==="?"?r+=`(?:${c})?`:i==="!"&&(r+=`(?!(?:${c})$).*`),s=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=cp(e,s);if(a===-1)r+="\\[",s++;else{let o=e.slice(s+1,a);r+=fp(o),s=a+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,s++):(r+=i,s++)}return r}function lp(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 up(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 cp(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 fp(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+=pp(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 dp=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 pp(e){return dp.get(e)??""}async function Ht(e,t,n,r,s){let i="",a=e.state.shoptOptions.extglob;for(let o of t.parts)if(o.type==="Glob")i+=se(o.pattern,n,a);else if(o.type==="Literal")i+=se(o.value,n,a);else if(o.type==="SingleQuoted"||o.type==="Escaped")i+=oe(o.value);else if(o.type==="DoubleQuoted"){let l=await r(e,o.parts);i+=oe(l)}else if(o.type==="ParameterExpansion"){let l=await s(e,o);i+=se(l,n,a)}else{let l=await s(e,o);i+=oe(l)}return i}function yt(e,t,n,r,s){if(r==="prefix")return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),me(`^${n}`,"s").replace(t,"");let i=me(`${n}$`,"s");if(s)return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),i.replace(t,"");e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal");let a=me(`^(?:.*)(${n})$`,"s").exec(t);if(!a)return t;let o=a[1]??"";return t.slice(0,t.length-o.length)}function Mn(e,t){let n=new Set;for(let r of e.state.env.keys())r.startsWith(t)&&n.add(r);for(let r of e.state.arrays?.keys()??[])r.startsWith(t)&&n.add(r);return[...n].sort()}function Hr(e,t,n,r,s){let i=new kn(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 Bl(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 hp(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=Bl(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 ur(e,t){let n=Bl(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")||"/",u=o.startsWith(l)?`~${o.slice(l.length)}`:o,c=o.split("/").pop()||o,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],p=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],h=e.state.env.get("__COMMAND_NUMBER")||"1";for(;r<t.length;){let m=t[r];if(m==="\\"){if(r+1>=t.length){n.append("\\"),r++;continue}let E=t[r+1];if(E>="0"&&E<="7"){let S="",y=r+1;for(;y<t.length&&y<r+4&&t[y]>="0"&&t[y]<="7";)S+=t[y],y++;let g=Number.parseInt(S,8)%256;n.append(String.fromCharCode(g)),r=y;continue}switch(E){case"\\":n.append("\\"),r+=2;break;case"a":n.append("\x07"),r+=2;break;case"e":n.append("\x1B"),r+=2;break;case"n":n.append(`
104
+ `),r+=2;break;case"r":n.append("\r"),r+=2;break;case"$":n.append("$"),r+=2;break;case"[":case"]":r+=2;break;case"u":n.append(s),r+=2;break;case"h":n.append(a),r+=2;break;case"H":n.append(i),r+=2;break;case"w":n.append(u),r+=2;break;case"W":n.append(c),r+=2;break;case"d":{let S=String(f.getDate()).padStart(2," ");n.append(`${d[f.getDay()]} ${p[f.getMonth()]} ${S}`),r+=2;break}case"t":{let S=String(f.getHours()).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),g=String(f.getSeconds()).padStart(2,"0");n.append(`${S}:${y}:${g}`),r+=2;break}case"T":{let S=f.getHours()%12;S===0&&(S=12);let y=String(S).padStart(2,"0"),g=String(f.getMinutes()).padStart(2,"0"),b=String(f.getSeconds()).padStart(2,"0");n.append(`${y}:${g}:${b}`),r+=2;break}case"@":{let S=f.getHours()%12;S===0&&(S=12);let y=String(S).padStart(2,"0"),g=String(f.getMinutes()).padStart(2,"0"),b=f.getHours()<12?"AM":"PM";n.append(`${y}:${g} ${b}`),r+=2;break}case"A":{let S=String(f.getHours()).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0");n.append(`${S}:${y}`),r+=2;break}case"D":if(r+2<t.length&&t[r+2]==="{"){let S=t.indexOf("}",r+3);if(S!==-1){let y=t.slice(r+3,S);n.append(hp(y,f,e.limits.maxStringLength)),r=S+1}else n.append("\\D"),r+=2}else n.append("\\D"),r+=2;break;case"s":n.append("bash"),r+=2;break;case"v":n.append("5.0"),r+=2;break;case"V":n.append("5.0.0"),r+=2;break;case"j":n.append("0"),r+=2;break;case"l":n.append("tty"),r+=2;break;case"#":n.append(h),r+=2;break;case"!":n.append(h),r+=2;break;case"x":n.append("\\x"),r+=2;break;default:n.append(`\\${E}`),r+=2}}else n.append(m),r++}return n.build()}function 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`
105
+ `:n+="\\n";break;case"\r":n+="\\r";break;case" ":n+="\\t";break;default:{let s=r.charCodeAt(0);s<32||s===127?n+=`\\${s.toString(8).padStart(3,"0")}`:n+=r}}return`${n}'`}return`'${e}'`}function je(e,t){e.state.readonlyVars=e.state.readonlyVars||new Set,e.state.readonlyVars.add(t)}function Fe(e,t){return e.state.readonlyVars?.has(t)??!1}function ue(e,t,n="bash"){if(Fe(e,t)){let r=`${n}: ${t}: readonly variable
106
+ `;throw new q(1,"",r)}return null}function gt(e,t){let n=e.state.exportedVars?.has(t)??!1;if(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(t),e.state.localScopes.length>0&&e.state.localScopes[e.state.localScopes.length-1].has(t)&&!n){for(e.state.localExportedVars||(e.state.localExportedVars=[]);e.state.localExportedVars.length<e.state.localScopes.length;)e.state.localExportedVars.push(new Set);e.state.localExportedVars[e.state.localExportedVars.length-1].add(t)}}function Zr(e,t){e.state.exportedVars?.delete(t)}function Qt(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let n="",r=ve(e,t)?.kind==="indexed",s=e.state.associativeArrays?.has(t)??!1;return r&&!s&&(n+="a"),s&&(n+="A"),e.state.integerVars?.has(t)&&(n+="i"),le(e,t)&&(n+="n"),Fe(e,t)&&(n+="r"),e.state.exportedVars?.has(t)&&(n+="x"),n}async function Wl(e,t,n,r){return e.coverage?.hit("bash:expansion:default_value"),(n.isUnset||t.checkEmpty&&n.isEmpty)&&t.word?r(e,t.word.parts,n.inDoubleQuotes):n.effectiveValue}function Di(e){if(/^(?:\d+|[@*#?$!-])$/.test(e))throw new q(1,"",`bash: $${e}: cannot assign in this way
107
+ `)}async function Vl(e,t,n,r,s){e.coverage?.hit("bash:expansion:assign_default");let i=r.isUnset||n.checkEmpty&&r.isEmpty;if(i&&Di(t),i&&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,u]=o;if(u==="@"||u==="*")throw new q(1,"",`${e.state.expansionStderr||""}bash: ${t}: bad array subscript
108
+ `);let c;if(/^\d+$/.test(u))c=Number.parseInt(u,10);else{try{let f=new j,d=te(f,u);c=await X(e,d.expression)}catch{let f=e.state.env.get(u);c=f?Number.parseInt(f,10):0}Number.isNaN(c)&&(c=0)}U(e,l,c,a)}else e.state.env.set(t,a);return a}return r.effectiveValue}async function zl(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 q(1,"",`bash: ${a}
109
+ `)}return r.effectiveValue}async function ql(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 Ul(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_removal");let i=n.pattern?await Ht(e,n.pattern,n.greedy,r,s):"";return yt(e,t,i,n.side,n.greedy)}async function jl(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",a=e.state.shoptOptions.extglob;if(n.pattern)for(let u of n.pattern.parts)if(u.type==="Glob")i+=se(u.pattern,!0,a);else if(u.type==="Literal")i+=se(u.value,!0,a);else if(u.type==="SingleQuoted"||u.type==="Escaped")i+=oe(u.value);else if(u.type==="DoubleQuoted"){let c=await r(e,u.parts);i+=oe(c)}else if(u.type==="ParameterExpansion"){let c=await s(e,u);i+=se(c,!0,a)}else{let c=await s(e,u);i+=oe(c)}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 u=me(i,l);return Hr(e,t,u,o,n.all)}catch(u){if(u instanceof P)throw u;return t}}function Ii(e,t,n){e.coverage?.hit("bash:expansion:length");let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(r){let s=r[1],i=G(e,s);return i.length>0?String(i.length):e.state.env.get(s)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&mt(e,t)){if(t==="FUNCNAME"){let i=e.state.funcNameStack?.[0]||"";return String([...i].length)}if(t==="BASH_LINENO"){let i=e.state.callLineStack?.[0];return String(i!==void 0?[...String(i)].length:0)}let s=ie(e,t,0)||"";return String([...s].length)}return String([...n].length)}async function Gl(e,t,n,r){e.coverage?.hit("bash:expansion:substring");let s=await X(e,r.offset.expression),i=r.length?await X(e,r.length.expression):void 0;if(t==="@"||t==="*"){let u=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let h=1;h<=u;h++)c.push(e.state.env.get(String(h))||"");let f=e.state.env.get("0")||"bash",d,p;if(s<=0)if(d=[f,...c],s<0){if(p=d.length+s,p<0)return""}else p=0;else d=c,p=s-1;if(p<0||p>=d.length)return"";if(i!==void 0){let h=i<0?d.length+i:p+i;return d.slice(p,Math.max(p,h)).join(" ")}return d.slice(p).join(" ")}let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(a){let u=a[1];if(e.state.associativeArrays?.has(u))throw new q(1,"",`bash: \${${u}[@]: 0: 3}: bad substitution
110
+ `);let c=G(e,u),f=0;if(s<0){if(c.length>0){let d=c[c.length-1][0],h=(typeof d=="number"?d:0)+1+s;if(h<0||(f=c.findIndex(([m])=>typeof m=="number"&&m>=h),f<0))return""}}else if(f=c.findIndex(([d])=>typeof d=="number"&&d>=s),f<0)return"";if(i!==void 0){if(i<0)throw new ae(`${a[1]}[@]: substring expression < 0`);return c.slice(f,f+i).map(([,d])=>d).join(" ")}return c.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 u=o.length+i;return o.slice(l,Math.max(l,u)).join("")}return o.slice(l,l+i).join("")}return o.slice(l).join("")}async function Hl(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+=se(f.pattern,!0,i);else if(f.type==="Literal")a+=se(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")a+=oe(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);a+=oe(d)}else if(f.type==="ParameterExpansion"){let d=await s(e,f);a+=se(d,!0,i)}let o=me(`^(?:${a})$`),l=n.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),u="",c=!1;for(let f of t)!n.all&&c?u+=f:o.test(f)?(u+=l(f),c=!0):u+=f;return u}return n.direction==="upper"?n.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):n.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function Zl(e,t,n,r,s){e.coverage?.hit("bash:expansion:transform");let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i&&s.operator==="Q")return G(e,i[1]).map(([,u])=>Zt(u)).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 ur(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`
111
+ `;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return l}});case"K":case"k":return r?"":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 Ql(e,t,n,r,s,i,a=!1){if(e.coverage?.hit("bash:expansion:indirection"),le(e,t))return bn(e,t)||"";let o=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(s.innerOp?.type==="UseAlternative")return"";throw new Ze(`\${!${t}}`)}let l=n;if(o&&(l===""||l.includes(" ")))throw new Ze(`\${!${t}}`);let u=l.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new Ze(`\${!${t}}`);if(s.innerOp){let c={type:"ParameterExpansion",parameter:l,operation:s.innerOp};return i(e,c,a)}return await re(e,l)}function Kl(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=G(e,t.array).map(([s])=>String(s));return t.star?r.join(Z(e.state.env)):r.join(" ")}function Xl(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let n=Mn(e,t.prefix);return t.star?n.join(Z(e.state.env)):n.join(" ")}function Yl(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=G(e,a);return l.length===0?{isEmpty:!0,effectiveValue:""}:o==="*"?{isEmpty:r?n==="":!1,effectiveValue:n}:{isEmpty:l.length===1&&l.every(([,u])=>u===""),effectiveValue:n}}return{isEmpty:n==="",effectiveValue:n}}function Kt(e,t){e.lastExitCode=t,e.env.set("?",String(t)),e.lastSubstitutionExitCode=t}function mp(e){switch(e.operator){case"<":case"<&":case"<<":case"<<-":case"<<<":case"<>":return e.fd===null||e.fd===0;default:return!1}}function Qr(e,t){return t.some(mp)?0:e.lastSubstitutionExitCode??0}function Jl(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 eu(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 Kr(e,t){let n=new j,r;try{r=n.parse(t)}catch{return""}let s=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let i=new Map(e.state.env),a=st(e.state.arrays),o=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let u=await e.executeScript(r),c=u.exitCode;return e.state.env=i,e.state.arrays=a,e.state.cwd=o,e.state.suppressVerbose=l,Kt(e.state,c),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr),e.state.bashPid=s,u.stdout.replace(/\n+$/,"")}catch(u){if(e.state.env=i,e.state.arrays=a,e.state.cwd=o,e.state.bashPid=s,e.state.suppressVerbose=l,u instanceof P)throw u;return u instanceof q?(Kt(e.state,u.exitCode),u.stdout?.replace(/\n+$/,"")??""):""}}function Oi(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=yp(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 yp(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 tu(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 gp(e,o);n+=Xe(l),r=i+1;continue}}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=eu(t,r+2);if(i!==-1){let a=t.slice(r+2,i),o=await Kr(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 Kr(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 gp(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=eu(t,r+2);if(i!==-1){let a=t.slice(r+2,i),o=await Kr(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 Kr(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 _i(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 Xt(e,t){return t.split(":").map(n=>_i(e,n)).join(":")}function Re(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 wp(e,t,n,r){let s="";for(let i of t.parts)if(i.type==="Glob")s+=se(i.pattern,!0,e.state.shoptOptions.extglob);else if(i.type==="Literal")s+=se(i.value,!0,e.state.shoptOptions.extglob);else if(i.type==="SingleQuoted"||i.type==="Escaped")s+=oe(i.value);else if(i.type==="DoubleQuoted"){let a=await n(e,i.parts);s+=oe(a)}else if(i.type==="ParameterExpansion"){let a=await r(e,i);s+=se(a,!0,e.state.shoptOptions.extglob)}else{let a=await r(e,i);s+=oe(a)}return s}async function nu(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]==="*",u=i.operation,c=G(e,o),f=c.map(([,E])=>E);if(c.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="";u.pattern&&(d=await wp(e,u.pattern,n,r));let p=u.replacement?await n(e,u.replacement.parts):"",h=d;u.anchor==="start"?h=`^${d}`:u.anchor==="end"&&(h=`${d}$`);let m=[];try{let E=me(h,u.all?"g":"");for(let S of f)m.push(E.replace(S,p))}catch{m.push(...f)}if(l){let E=Z(e.state.env);return{values:[m.join(E)],quoted:!0}}return{values:m,quoted:!0}}async function ru(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]==="*",u=i.operation,c=G(e,o),f=c.map(([,h])=>h);if(c.length===0){let h=e.state.env.get(o);h!==void 0&&f.push(h)}if(f.length===0)return{values:[],quoted:!0};let d=u.pattern?await Ht(e,u.pattern,u.greedy,n,r):"",p=[];for(let h of f)p.push(yt(e,h,d,u.side,u.greedy));if(l){let h=Z(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}async function su(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="DefaultValue"&&n.parts[0].operation?.type!=="UseAlternative"&&n.parts[0].operation?.type!=="AssignDefault")return null;let r=n.parts[0];if(r.operation?.type==="AssignDefault"&&/^(?:\d+|[@*#?$!-])$/.test(r.parameter))return null;let s=r.operation,i=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(s.type==="AssignDefault"&&(!i||i[2]==="*"))return null;let a,o=!1;if(i){let l=i[1];o=i[2]==="*";let u=G(e,l),c=u.length>0||e.state.env.has(l),f=u.length===0||u.length===1&&u.every(([,p])=>p===""),d=s.checkEmpty??!1;if(s.type==="UseAlternative"?a=c&&!(d&&f):a=!c||d&&f,!a){if(u.length>0){let h=u.map(([,m])=>m);if(o){let m=Z(e.state.env);return{values:[h.join(m)],quoted:!0}}return{values:h,quoted:!0}}let p=e.state.env.get(l);return p!==void 0?{values:[p],quoted:!0}:{values:[],quoted:!0}}}else{let l=r.parameter,u=await xt(e,l),c=await re(e,l,!1),f=c==="",d=s.checkEmpty??!1;if(s.type==="UseAlternative"?a=u&&!(d&&f):a=!u||d&&f,!a)return{values:[c],quoted:!0}}if(s.type==="AssignDefault")return null;if(a&&s.word){let l=s.word.parts,u=null,c=!1;for(let f of l)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){u=d[1],c=d[2]==="*";break}}if(u){let f=G(e,u);if(f.length>0){let p=f.map(([,h])=>h);if(c||o){let h=Z(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}let d=e.state.env.get(u);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}return null}async function iu(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,u=null;for(let m=0;m<i.parts.length;m++){let E=i.parts[m];if(E.type==="ParameterExpansion"&&(E.operation?.type==="PatternRemoval"||E.operation?.type==="PatternReplacement")){let S=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(S){a=m,o=S[1],l=S[2]==="*",u=E.operation;break}}}if(a===-1||a===0&&a===i.parts.length-1)return null;let c="";for(let m=0;m<a;m++)c+=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=G(e,o),p=d.map(([,m])=>m);if(d.length===0){let m=e.state.env.get(o);if(m!==void 0)p=[m];else{if(l)return{values:[c+f],quoted:!0};let E=c+f;return{values:E?[E]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let m=u,E=m.pattern?await Ht(e,m.pattern,m.greedy,s,r):"";p=p.map(S=>yt(e,S,E,m.side,m.greedy))}else if(u?.type==="PatternReplacement"){let m=u,E="";if(m.pattern)for(let g of m.pattern.parts)if(g.type==="Glob")E+=se(g.pattern,!0,e.state.shoptOptions.extglob);else if(g.type==="Literal")E+=se(g.value,!0,e.state.shoptOptions.extglob);else if(g.type==="SingleQuoted"||g.type==="Escaped")E+=oe(g.value);else if(g.type==="DoubleQuoted"){let b=await s(e,g.parts);E+=oe(b)}else if(g.type==="ParameterExpansion"){let b=await r(e,g);E+=se(b,!0,e.state.shoptOptions.extglob)}else{let b=await r(e,g);E+=oe(b)}let S=m.replacement?await s(e,m.replacement.parts):"",y=E;m.anchor==="start"?y=`^${E}`:m.anchor==="end"&&(y=`${E}$`);try{let g=me(y,m.all?"g":"");p=p.map(b=>g.replace(b,S))}catch{}}if(l){let m=Z(e.state.env);return{values:[c+p.join(m)+f],quoted:!0}}return p.length===1?{values:[c+p[0]+f],quoted:!0}:{values:[c+p[0],...p.slice(1,-1),p[p.length-1]+f],quoted:!0}}async function au(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 p=0;p<s.parts.length;p++){let h=s.parts[p];if(h.type==="ParameterExpansion"&&!h.operation){let m=h.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(m){i=p,a=m[1],o=m[2]==="*";break}}}if(i===-1)return null;let l="";for(let p=0;p<i;p++)l+=await r(e,s.parts[p]);let u="";for(let p=i+1;p<s.parts.length;p++)u+=await r(e,s.parts[p]);let c=G(e,a),f=c.map(([,p])=>p);if(c.length===0){let p=e.state.env.get(a);if(p!==void 0)return{values:[l+p+u],quoted:!0};if(o)return{values:[l+u],quoted:!0};let h=l+u;return{values:h?[h]:[],quoted:!0}}if(o){let p=Z(e.state.env);return{values:[l+f.join(p)+u],quoted:!0}}return f.length===1?{values:[l+f[0]+u],quoted:!0}:{values:[l+f[0],...f.slice(1,-1),f[f.length-1]+u],quoted:!0}}async function ou(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 q(1,"",`bash: \${${a}[@]: 0: 3}: bad substitution
112
+ `);let u=l.offset?await n(e,l.offset.expression):0,c=l.length?await n(e,l.length.expression):void 0,f=G(e,a);if(f.length>e.limits.maxArrayElements)throw new P(`array transform element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let d=0;if(u<0){if(f.length>0){let h=f[f.length-1][0],E=(typeof h=="number"?h:0)+1+u;if(E<0)return{values:[],quoted:!0};d=f.findIndex(([S])=>typeof S=="number"&&S>=E),d<0&&(d=f.length)}}else d=f.findIndex(([h])=>typeof h=="number"&&h>=u),d<0&&(d=f.length);let p;if(c!==void 0){if(c<0)throw new ae(`${a}[@]: substring expression < 0`);p=f.slice(d,d+c).map(([,h])=>h)}else p=f.slice(d).map(([,h])=>h);if(p.length===0)return{values:[],quoted:!0};if(o){let h=Z(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}function lu(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.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=G(e,i);if(l.length===0){let d=e.state.env.get(i);if(d!==void 0){let p;switch(o.operator){case"a":p="";break;case"P":p=ur(e,d);break;case"Q":p=Zt(d);break;default:p=d}if(M(p)>e.limits.maxStringLength)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[p],quoted:!0}}return a?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=Qt(e,i),c=[],f=0;for(let[,d]of l){let p;switch(o.operator){case"a":p=u;break;case"P":p=ur(e,d);break;case"Q":p=Zt(d);break;case"u":p=d.charAt(0).toUpperCase()+d.slice(1);break;case"U":p=d.toUpperCase();break;case"L":p=d.toLowerCase();break;default:p=d}let h=M(p);if(h>e.limits.maxStringLength-f)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");c.push(p),f+=h}if(a){let d=Z(e.state.env);if(Math.max(0,c.length-1)*M(d)>e.limits.maxStringLength-f)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[c.join(d)],quoted:!0}}return{values:c,quoted:!0}}function uu(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=bn(e,i);if(l?.endsWith("[@]")||l?.endsWith("[*]"))return{values:[],quoted:!0}}let a=G(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 cu(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation)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=bn(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=G(e,o);if(l.length>0)return{values:l.map(([,c])=>c),quoted:!0};let u=e.state.env.get(o);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function fu(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 re(e,a.parameter),u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!o.innerOp&&(l==="@"||l==="*")){let h=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let E=1;E<=h;E++)m.push(e.state.env.get(String(E))||"");return l==="*"?{values:[m.join(Z(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let c=u[1],f=u[2]==="*",d=G(e,c);if(o.innerOp){if(o.innerOp.type==="Substring")return Ep(e,d,c,f,o.innerOp);if(o.innerOp.type==="DefaultValue"||o.innerOp.type==="UseAlternative"||o.innerOp.type==="AssignDefault"||o.innerOp.type==="ErrorIfUnset")return bp(e,d,c,f,o.innerOp,s);if(o.innerOp.type==="Transform"&&o.innerOp.operator==="a"){let m=Qt(e,c),E=d.map(()=>m);return f?{values:[E.join(Z(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let h=[];for(let[,m]of d){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:o.innerOp},S=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",m);try{let y=await r(e,E,!0);h.push(y)}finally{S!==void 0?e.state.env.set("_indirect_elem_",S):e.state.env.delete("_indirect_elem_")}}return f?{values:[h.join(Z(e.state.env))],quoted:!0}:{values:h,quoted:!0}}if(d.length>0){let h=d.map(([,m])=>m);return f?{values:[h.join(Z(e.state.env))],quoted:!0}:{values:h,quoted:!0}}let p=e.state.env.get(c);return p!==void 0?{values:[p],quoted:!0}:{values:[],quoted:!0}}async function Ep(e,t,n,r,s){let i=s.offset?await X(e,s.offset.expression):0,a=s.length?await X(e,s.length.expression):void 0,o=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(o=t.findIndex(([p])=>typeof p=="number"&&p>=d),o<0)return{values:[],quoted:!0}}}else if(o=t.findIndex(([c])=>typeof c=="number"&&c>=i),o<0)return{values:[],quoted:!0};let l;if(a!==void 0){if(a<0)throw new ae(`${n}[@]: substring expression < 0`);l=t.slice(o,o+a)}else l=t.slice(o);let u=l.map(([,c])=>c);return r?{values:[u.join(Z(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function bp(e,t,n,r,s,i){let a=s.checkEmpty??!1,o=t.map(([,c])=>c),l=t.length===0,u=t.length===0;if(s.type==="UseAlternative")return!u&&!(a&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(s.type==="DefaultValue")return(u||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((u||a&&l)&&s.word){let f=await i(e,s.word.parts,!0);return U(e,n,0,f),{values:[f],quoted:!0}}return r?{values:[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 du(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 re(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!l)return null;let u=await xt(e,n.parameter),c=await re(e,n.parameter)==="",f=r.checkEmpty??!1,d;if(r.type==="UseAlternative"?d=u&&!(f&&c):d=!u||f&&c,d){let p=l[1],h=l[2]==="*",m=G(e,p);if(m.length>0){let S=m.map(([,y])=>y);return h?{values:[S.join(Z(e.state.env))],quoted:!0}:{values:S,quoted:!0}}let E=e.state.env.get(p);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function pu(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],u=(await re(e,o.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await re(e,n.parameter),f=await xt(e,n.parameter),d=c==="",p=s.checkEmpty??!1,h;if(s.type==="UseAlternative"?h=f&&!(p&&d):h=!f||p&&d,h){let m=u[1],E=u[2]==="*",S=G(e,m);if(S.length>0){let g=S.map(([,b])=>b);return E?{values:[g.join(Z(e.state.env))],quoted:!0}:{values:g,quoted:!0}}let y=e.state.env.get(m);return y!==void 0?{values:[y],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function hu(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 Xr(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 Li(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 mu(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,a=!1;for(let y=0;y<s.parts.length;y++){let g=s.parts[y];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="Substring"){i=y,a=g.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,u=l.offset?await n(e,l.offset.expression):0,c=l.length?await n(e,l.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),d=[];for(let y=1;y<=f;y++)d.push(e.state.env.get(String(y))||"");let p=e.state.env.get("0")||"bash",h;if(u<=0){let y=[p,...d],g=y.length+u;if(g<0)h=[];else{let b=u<0?g:0;if(c!==void 0){let v=c<0?y.length+c:b+c;h=y.slice(b,Math.max(b,v))}else h=y.slice(b)}}else{let y=u-1;if(y>=d.length)h=[];else if(c!==void 0){let g=c<0?d.length+c:y+c;h=d.slice(y,Math.max(y,g))}else h=d.slice(y)}let m="";for(let y=0;y<i;y++)m+=await r(e,s.parts[y]);let E="";for(let y=i+1;y<s.parts.length;y++)E+=await r(e,s.parts[y]);if(h.length===0){let y=m+E;return{values:y?[y]:[],quoted:!0}}if(a){let y=Z(e.state.env);return{values:[m+h.join(y)+E],quoted:!0}}return h.length===1?{values:[m+h[0]+E],quoted:!0}:{values:[m+h[0],...h.slice(1,-1),h[h.length-1]+E],quoted:!0}}async function yu(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,a=!1;for(let y=0;y<s.parts.length;y++){let g=s.parts[y];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="PatternReplacement"){i=y,a=g.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,u=hu(e),c="";for(let y=0;y<i;y++)c=Xr(c,await n(e,s.parts[y]),e.limits.maxStringLength);let f="";for(let y=i+1;y<s.parts.length;y++)f=Xr(f,await n(e,s.parts[y]),e.limits.maxStringLength);if(u.length===0){let y=c+f;return{values:y?[y]:[],quoted:!0}}let d="";if(l.pattern)for(let y of l.pattern.parts)if(y.type==="Glob")d+=se(y.pattern,!0,e.state.shoptOptions.extglob);else if(y.type==="Literal")d+=se(y.value,!0,e.state.shoptOptions.extglob);else if(y.type==="SingleQuoted"||y.type==="Escaped")d+=oe(y.value);else if(y.type==="DoubleQuoted"){let g=await r(e,y.parts);d+=oe(g)}else if(y.type==="ParameterExpansion"){let g=await n(e,y);d+=se(g,!0,e.state.shoptOptions.extglob)}else{let g=await n(e,y);d+=oe(g)}let p=l.replacement?await r(e,l.replacement.parts):"",h=d;l.anchor==="start"?h=`^${d}`:l.anchor==="end"&&(h=`${d}$`);let m=[],E={value:0};try{let y=me(h,l.all?"g":"");for(let g of u){let b=0;y.lastIndex=0;for(let x=y.exec(g);x&&(b++,!!l.all);x=y.exec(g))x[0].length===0&&y.lastIndex++;let v=M(g),$=M(p),A=0,k=/\$(?:\$|&|\d+|<[^>]+>|`|')/g;for(;k.exec(p)!==null;)A++;if(v+b*$+b*A*v>e.limits.maxStringLength-E.value)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");Li(m,y.replace(g,p),E,e)}}catch(y){if(y instanceof P)throw y;for(let g of u)Li(m,g,E,e)}if(a){let y=Z(e.state.env);if(E.value+Math.max(0,m.length-1)*M(y)+M(c)+M(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[c+m.join(y)+f],quoted:!0}}if(M(c)+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:[c+m[0]+f],quoted:!0}:{values:[c+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function gu(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,a=!1;for(let S=0;S<s.parts.length;S++){let y=s.parts[S];if(y.type==="ParameterExpansion"&&(y.parameter==="@"||y.parameter==="*")&&y.operation?.type==="PatternRemoval"){i=S,a=y.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,u=hu(e),c="";for(let S=0;S<i;S++)c=Xr(c,await n(e,s.parts[S]),e.limits.maxStringLength);let f="";for(let S=i+1;S<s.parts.length;S++)f=Xr(f,await n(e,s.parts[S]),e.limits.maxStringLength);if(u.length===0){let S=c+f;return{values:S?[S]:[],quoted:!0}}let d="",p=e.state.shoptOptions.extglob;if(l.pattern)for(let S of l.pattern.parts)if(S.type==="Glob")d+=se(S.pattern,l.greedy,p);else if(S.type==="Literal")d+=se(S.value,l.greedy,p);else if(S.type==="SingleQuoted"||S.type==="Escaped")d+=oe(S.value);else if(S.type==="DoubleQuoted"){let y=await r(e,S.parts);d+=oe(y)}else if(S.type==="ParameterExpansion"){let y=await n(e,S);d+=se(y,l.greedy,p)}else{let y=await n(e,S);d+=oe(y)}let h=[],m={value:0};for(let S of u)Li(h,yt(e,S,d,l.side,l.greedy),m,e);if(a){let S=Z(e.state.env);if(m.value+Math.max(0,h.length-1)*M(S)+M(c)+M(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[c+h.join(S)+f],quoted:!0}}if(M(c)+m.value+M(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return h.length===1?{values:[c+h[0]+f],quoted:!0}:{values:[c+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function wu(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0],s=-1,i=!1;for(let d=0;d<r.parts.length;d++){let p=r.parts[d];if(p.type==="ParameterExpansion"&&(p.parameter==="@"||p.parameter==="*")){s=d,i=p.parameter==="*";break}}if(s===-1)return null;let 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 u="";for(let d=s+1;d<r.parts.length;d++)u+=await n(e,r.parts[d]);if(o===0){if(i)return{values:[l+u],quoted:!0};let d=l+u;return{values:d?[d]:[],quoted:!0}}let c=[];for(let d=1;d<=o;d++)c.push(e.state.env.get(String(d))||"");if(i){let d=Z(e.state.env);return{values:[l+c.join(d)+u],quoted:!0}}return c.length===1?{values:[l+c[0]+u],quoted:!0}:{values:[l+c[0],...c.slice(1,-1),c[c.length-1]+u],quoted:!0}}function Pt(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 Ti(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 Sp(e){return new Gt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")})}async function Yr(e,t){if(e.state.options.noglob)return t;let n=Sp(e),r=[];for(let s of t)if(kt(s,e.state.shoptOptions.extglob)){let i=await n.expand(s);if(i.length>0)Re(r,i,e.limits.maxArrayElements,"unquoted glob expansion");else{if(n.hasFailglob())throw new Tt(s);n.hasNullglob()||r.push(s)}}else r.push(s);return r}async function Eu(e,t,n,r){let s=-1,i="",a=!1;for(let b=0;b<t.length;b++){let v=t[b];if(v.type==="ParameterExpansion"&&v.operation?.type==="PatternReplacement"){let $=v.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if($){s=b,i=$[1],a=$[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,u=G(e,i),c=u.map(([,b])=>b);if(u.length===0){let b=e.state.env.get(i);b!==void 0&&(c=[b])}if(c.length===0)return{values:[],quoted:!1};let f="";if(l.pattern)for(let b of l.pattern.parts)if(b.type==="Glob")f+=se(b.pattern,!0,e.state.shoptOptions.extglob);else if(b.type==="Literal")f+=se(b.value,!0,e.state.shoptOptions.extglob);else if(b.type==="SingleQuoted"||b.type==="Escaped")f+=oe(b.value);else if(b.type==="DoubleQuoted"){let v=await n(e,b.parts);f+=oe(v)}else if(b.type==="ParameterExpansion"){let v=await r(e,b);f+=se(v,!0,e.state.shoptOptions.extglob)}else{let v=await r(e,b);f+=oe(v)}let d=l.replacement?await n(e,l.replacement.parts):"",p=f;l.anchor==="start"?p=`^${f}`:l.anchor==="end"&&(p=`${f}$`);let h=[],m={value:0};try{let b=me(p,l.all?"g":"");for(let v of c)Pt(e,h,Hr(e,v,b,d,l.all),m)}catch(b){if(b instanceof P)throw b;for(let v of c)Pt(e,h,v,m)}let E=Ae(e.state.env),S=Ne(e.state.env);if(a){let b=Z(e.state.env),v=Ti(e,h,b,m.value);return S?{values:v?[v]:[],quoted:!1}:{values:ce(v,E,e.limits.maxArrayElements),quoted:!1}}if(S)return{values:h,quoted:!1};let y=[],g={value:0};for(let b of h)if(b==="")Pt(e,y,"",g);else for(let v of ce(b,E,e.limits.maxArrayElements))Pt(e,y,v,g);return{values:y,quoted:!1}}async function bu(e,t,n,r){let s=-1,i="",a=!1;for(let y=0;y<t.length;y++){let g=t[y];if(g.type==="ParameterExpansion"&&g.operation?.type==="PatternRemoval"){let b=g.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){s=y,i=b[1],a=b[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,u=G(e,i),c=u.map(([,y])=>y);if(u.length===0){let y=e.state.env.get(i);y!==void 0&&(c=[y])}if(c.length===0)return{values:[],quoted:!1};let f=l.pattern?await Ht(e,l.pattern,l.greedy,n,r):"",d=[],p={value:0};for(let y of c)Pt(e,d,yt(e,y,f,l.side,l.greedy),p);let h=Ae(e.state.env),m=Ne(e.state.env);if(a){let y=Z(e.state.env),g=Ti(e,d,y,p.value);return m?{values:g?[g]:[],quoted:!1}:{values:ce(g,h,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[],S={value:0};for(let y of d)if(y==="")Pt(e,E,"",S);else for(let g of ce(y,h,e.limits.maxArrayElements))Pt(e,E,g,S);return{values:E,quoted:!1}}async function Su(e,t,n,r){let s=-1,i=!1;for(let y=0;y<t.length;y++){let g=t[y];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="PatternRemoval"){s=y,i=g.parameter==="*";break}}if(s===-1)return null;let o=t[s].operation,l=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let y=1;y<=l;y++)u.push(e.state.env.get(String(y))||"");if(u.length===0)return{values:[],quoted:!1};let c="",f=e.state.shoptOptions.extglob;if(o.pattern)for(let y of o.pattern.parts)if(y.type==="Glob")c+=se(y.pattern,o.greedy,f);else if(y.type==="Literal")c+=se(y.value,o.greedy,f);else if(y.type==="SingleQuoted"||y.type==="Escaped")c+=oe(y.value);else if(y.type==="DoubleQuoted"){let g=await n(e,y.parts);c+=oe(g)}else if(y.type==="ParameterExpansion"){let g=await r(e,y);c+=se(g,o.greedy,f)}else{let g=await r(e,y);c+=oe(g)}let d=[],p={value:0};for(let y of u)Pt(e,d,yt(e,y,c,o.side,o.greedy),p);let h=Ae(e.state.env),m=Ne(e.state.env);if(i){let y=Z(e.state.env),g=Ti(e,d,y,p.value);return m?{values:g?[g]:[],quoted:!1}:{values:ce(g,h,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[],S={value:0};for(let y of d)if(y==="")Pt(e,E,"",S);else for(let g of ce(y,h,e.limits.maxArrayElements))Pt(e,E,g,S);return{values:E,quoted:!1}}async function Au(e,t,n,r){let s=-1,i=!1;for(let g=0;g<t.length;g++){let b=t[g];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="Substring"){s=g,i=b.parameter==="*";break}}if(s===-1)return null;let o=t[s].operation,l=o.offset?await n(e,o.offset.expression):0,u=o.length?await n(e,o.length.expression):void 0,c=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let g=1;g<=c;g++)f.push(e.state.env.get(String(g))||"");let d=e.state.env.get("0")||"bash",p;if(l<=0){let g=[d,...f],b=g.length+l;if(b<0)p=[];else{let v=l<0?b:0;if(u!==void 0){let $=u<0?g.length+u:v+u;p=g.slice(v,Math.max(v,$))}else p=g.slice(v)}}else{let g=l-1;if(g>=f.length)p=[];else if(u!==void 0){let b=u<0?f.length+u:g+u;p=f.slice(g,Math.max(g,b))}else p=f.slice(g)}let h="";for(let g=0;g<s;g++)h+=await r(e,t[g]);let m="";for(let g=s+1;g<t.length;g++)m+=await r(e,t[g]);let E=Ae(e.state.env),S=Ne(e.state.env);if(p.length===0){let g=h+m;return g?S?{values:[g],quoted:!1}:{values:ce(g,E,e.limits.maxArrayElements),quoted:!1}:{values:[],quoted:!1}}let y;if(i){let g=Z(e.state.env),b=h+p.join(g)+m;S?y=b?[b]:[]:y=ce(b,E,e.limits.maxArrayElements)}else if(S)p.length===1?y=[h+p[0]+m]:y=[h+p[0],...p.slice(1,-1),p[p.length-1]+m];else{y=[];for(let g=0;g<p.length;g++){let b=p[g];if(g===0&&(b=h+b),g===p.length-1&&(b=b+m),b==="")y.push("");else{let v=ce(b,E,e.limits.maxArrayElements);Re(y,v,e.limits.maxArrayElements,"unquoted expansion")}}}return{values:await Yr(e,y),quoted:!1}}async function vu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let n=t[0].parameter==="*",r=Number.parseInt(e.state.env.get("#")||"0",10);if(r===0)return{values:[],quoted:!1};let s=[];for(let u=1;u<=r;u++)s.push(e.state.env.get(String(u))||"");let i=Ae(e.state.env),a=Ne(e.state.env),o=zr(e.state.env),l;if(n)if(a)l=s.filter(u=>u!=="");else{let u=Z(e.state.env),c=s.join(u);l=ce(c,i,e.limits.maxArrayElements)}else if(a)l=s.filter(u=>u!=="");else if(o){l=[];for(let u of s){if(u==="")continue;let c=ce(u,i,e.limits.maxArrayElements);Re(l,c,e.limits.maxArrayElements,"unquoted expansion")}}else{l=[];for(let u of s)if(u==="")l.push("");else{let c=ce(u,i,e.limits.maxArrayElements);Re(l,c,e.limits.maxArrayElements,"unquoted expansion")}for(;l.length>0&&l[l.length-1]==="";)l.pop()}return{values:await Yr(e,l),quoted:!1}}async function $u(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let n=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let r=n[1],s=n[2]==="*",i=G(e,r),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=Ae(e.state.env),l=Ne(e.state.env),u=zr(e.state.env),c;if(s)if(l)c=a.filter(f=>f!=="");else{let f=Z(e.state.env),d=a.join(f);c=ce(d,o,e.limits.maxArrayElements)}else if(l)c=a.filter(f=>f!=="");else if(u){c=[];for(let f of a){if(f==="")continue;let d=ce(f,o,e.limits.maxArrayElements);Re(c,d,e.limits.maxArrayElements,"unquoted expansion")}}else{c=[];for(let f of a)if(f==="")c.push("");else{let d=ce(f,o,e.limits.maxArrayElements);Re(c,d,e.limits.maxArrayElements,"unquoted expansion")}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Yr(e,c),quoted:!1}}function xu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let n=t[0].operation,r=Mn(e,n.prefix);if(r.length===0)return{values:[],quoted:!1};let s=Ae(e.state.env),i=Ne(e.state.env),a;if(n.star)if(i)a=r;else{let o=Z(e.state.env),l=r.join(o);a=ce(l,s,e.limits.maxArrayElements)}else if(i)a=r;else{a=[];for(let o of r){let l=ce(o,s,e.limits.maxArrayElements);Re(a,l,e.limits.maxArrayElements,"unquoted expansion")}}return{values:a,quoted:!1}}function ku(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let n=t[0].operation,s=G(e,n.array).map(([l])=>String(l));if(s.length===0)return{values:[],quoted:!1};let i=Ae(e.state.env),a=Ne(e.state.env),o;if(n.star)if(a)o=s;else{let l=Z(e.state.env),u=s.join(l);o=ce(u,i,e.limits.maxArrayElements)}else if(a)o=s;else{o=[];for(let l of s){let u=ce(l,i,e.limits.maxArrayElements);Re(o,u,e.limits.maxArrayElements,"unquoted expansion")}}return{values:o,quoted:!1}}async function Pu(e,t,n){let r=-1;for(let d=0;d<t.length;d++){let p=t[d];if(p.type==="ParameterExpansion"&&(p.parameter==="@"||p.parameter==="*")&&!p.operation){r=d;break}}if(r===-1||t.length<=1)return null;let s=Number.parseInt(e.state.env.get("#")||"0",10),i=[];for(let d=1;d<=s;d++)i.push(e.state.env.get(String(d))||"");let 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=Ae(e.state.env),u=Ne(e.state.env),c=zr(e.state.env);if(s===0){let d=a+o;return{values:d?[d]:[],quoted:!1}}let f;{let d=[];for(let p=0;p<i.length;p++){let h=i[p];p===0&&(h=a+h),p===i.length-1&&(h=h+o),d.push(h)}if(u)f=d.filter(p=>p!=="");else if(c){f=[];for(let p of d){if(p==="")continue;let h=ce(p,l,e.limits.maxArrayElements);Re(f,h,e.limits.maxArrayElements,"unquoted expansion")}}else{f=[];for(let p of d)if(p==="")f.push("");else{let h=ce(p,l,e.limits.maxArrayElements);Re(f,h,e.limits.maxArrayElements,"unquoted expansion")}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Yr(e,f),quoted:!1}}async function Ru(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:u,hasIndirection:c}=or(r),d=n.hasBraceExpansion(r)?await n.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return Ap(e,d,s);let p=await vp(e,r,o,u,c,n);if(p!==null)return p;let h=await xp(e,r,n);if(h!==null)return h;let m=await kp(e,r,n);if(m!==null)return m;let E=await Cp(e,r,n.expandPart);if(E!==null)return Nu(e,E);if((i||a||l)&&!Ne(e.state.env)){let y=Ae(e.state.env),g=n.buildIfsCharClassPattern(y),b=await n.smartWordSplit(e,r,y,g,n.expandPart);return Nu(e,b)}let S=await n.expandWordAsync(e,t);return Np(e,t,r,S,s,n.expandWordForGlobbing)}async function Ap(e,t,n){let r=[];for(let s of t)if(!(!n&&s===""))if(!n&&!e.state.options.noglob&&kt(s,e.state.shoptOptions.extglob)){let i=await Jr(e,s);Re(r,i,e.limits.maxArrayElements,"brace/glob expansion")}else r.push(s);return{values:r,quoted:!1}}async function vp(e,t,n,r,s,i){if(n){let a=uu(e,t);if(a!==null)return a}{let a=cu(e,t);if(a!==null)return a}{let a=await su(e,t);if(a!==null)return a}{let a=await iu(e,t,n,i.expandPart,i.expandWordPartsAsync);if(a!==null)return a}{let a=await au(e,t,n,i.expandPart);if(a!==null)return a}{let a=await ou(e,t,i.evaluateArithmetic);if(a!==null)return a}{let a=lu(e,t);if(a!==null)return a}{let a=await nu(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}{let a=await ru(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let a=$p(e,t);if(a!==null)return a}{let a=await fu(e,t,s,i.expandParameterAsync,i.expandWordPartsAsync);if(a!==null)return a}{let a=await du(e,t);if(a!==null)return a}{let a=await pu(e,t);if(a!==null)return a}return null}function $p(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=Mn(e,r.prefix);return r.star?{values:[s.join(Z(e.state.env))],quoted:!0}:{values:s,quoted:!0}}if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="ArrayKeys"){let r=n.parts[0].operation,i=G(e,r.array).map(([a])=>String(a));return r.star?{values:[i.join(Z(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function xp(e,t,n){{let r=await mu(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await yu(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await gu(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await wu(e,t,n.expandPart);if(r!==null)return r}return null}async function kp(e,t,n){{let r=await Eu(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await bu(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Su(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Au(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await vu(e,t);if(r!==null)return r}{let r=await $u(e,t);if(r!==null)return r}{let r=xu(e,t);if(r!==null)return r}{let r=ku(e,t);if(r!==null)return r}{let r=await Pu(e,t,n.expandPart);if(r!==null)return r}return null}function Cu(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 Pp(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=G(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 Cp(e,t,n){if(t.length<2)return null;let r=!1;for(let l of t)if(Cu(l)){r=!0;break}if(!r)return null;let s=Ae(e.state.env),i=Ne(e.state.env),a=[];for(let l of t){let u=Cu(l);if(u&&l.type==="DoubleQuoted"){let c=await Pp(e,l,u,n);a.push(c)}else if(l.type==="DoubleQuoted"||l.type==="SingleQuoted"){let c=await n(e,l);a.push([c])}else if(l.type==="Literal")a.push([l.value]);else if(l.type==="ParameterExpansion"){let c=await n(e,l);if(i)a.push(c?[c]:[]);else{let f=ce(c,s,e.limits.maxArrayElements);a.push(f)}}else{let c=await n(e,l);if(i)a.push(c?[c]:[]);else{let f=ce(c,s,e.limits.maxArrayElements);a.push(f)}}}let o=[];for(let l of a)if(l.length!==0)if(o.length===0)Re(o,l,e.limits.maxArrayElements,"word expansion");else{let u=o.length-1;o[u]=o[u]+l[0];for(let c=1;c<l.length;c++)o.push(l[c])}return o}async function Nu(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let n=[];for(let r of t)if(kt(r,e.state.shoptOptions.extglob)){let s=await Jr(e,r);Re(n,s,e.limits.maxArrayElements,"glob expansion")}else n.push(r);return{values:n,quoted:!1}}async function Jr(e,t){let n=new Gt(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 Tt(t);return n.hasNullglob()?[]:[t]}async function Np(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(kt(o,e.state.shoptOptions.extglob)){let u=await Jr(e,o);if(u.length>0&&u[0]!==o)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let l=Ri(r);if(!Ne(e.state.env)){let u=Ae(e.state.env);return{values:ce(l,u,e.limits.maxArrayElements),quoted:!1}}return{values:[l],quoted:!1}}if(!s&&!e.state.options.noglob&&kt(r,e.state.shoptOptions.extglob)){let o=await i(e,t);if(kt(o,e.state.shoptOptions.extglob)){let l=await Jr(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=Ri(r);if(!Ne(e.state.env)){let l=Ae(e.state.env);return{values:ce(o,l,e.limits.maxArrayElements),quoted:!1}}return{values:[o],quoted:!1}}return{values:[r],quoted:s}}function _e(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 Iu(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 xt(e,t.parameter),a=await re(e,t.parameter,!1)==="",o=n.checkEmpty??!1,l;return n.type==="UseAlternative"?l=s&&!(o&&a):l=!s||o&&a,l?(n.type==="AssignDefault"&&Di(t.parameter),r.parts):null}function Rp(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(n=>n.type==="Literal"):!1}async function Dp(e,t){if(t.type!=="ParameterExpansion")return null;let n=await Iu(e,t);if(!n||n.length<=1)return null;let r=n.some(i=>Rp(i)),s=n.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&s?n:null}function Ip(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?Ai(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&Rl(e))}async function Ou(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let d=t[0],p=await Iu(e,d);if(p&&p.length>0&&p.length>1&&p.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&p.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return Du(e,p,n,r,s)}let i=[],a=!1;for(let d of t){let p=Ip(d),h=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=p?await Dp(e,d):null,E=await s(e,d);i.push({value:E,isSplittable:p,isQuoted:h,mixedDefaultParts:m??void 0}),p&&(a=!0)}if(!a){let d=i.map(p=>p.value).join("");return d?[d]:[]}let o=[],l="",u=!1,c=!1,f=!1;for(let d of i)if(!d.isSplittable)c?d.isQuoted&&d.value===""?(l!==""&&_e(e,o,l),_e(e,o,""),u=!0,l="",c=!1,f=!0):d.value!==""?(l!==""&&_e(e,o,l),l=d.value,c=!1,f=!1):(l+=d.value,f=!1):(l+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let p=await Du(e,d.mixedDefaultParts,n,r,s);if(p.length!==0)if(p.length===1)l+=p[0],u=!0;else{l+=p[0],_e(e,o,l),u=!0;for(let h=1;h<p.length-1;h++)_e(e,o,p[h]);l=p[p.length-1]}c=!1,f=!1}else{let{words:p,hadLeadingDelimiter:h,hadTrailingDelimiter:m}=qr(d.value,n,e.limits.maxArrayElements);if(f&&h&&l===""&&(_e(e,o,""),u=!0),p.length===0)m&&(c=!0);else if(p.length===1)l+=p[0],u=!0,c=m;else{l+=p[0],_e(e,o,l),u=!0;for(let E=1;E<p.length-1;E++)_e(e,o,p[E]);l=p[p.length-1],c=m}f=!1}return l!==""?_e(e,o,l):o.length===0&&u&&_e(e,o,""),o}function Op(e,t){return e.length>0&&t.includes(e[0])}async function Du(e,t,n,r,s){let i=[];for(let c of t){let d=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),p=await s(e,c);i.push({value:p,isSplittable:d})}let a=[],o="",l=!1,u=!1;for(let c of i)if(!c.isSplittable)u&&c.value!==""?(o!==""&&_e(e,a,o),o=c.value,u=!1):o+=c.value;else{Op(c.value,n)&&o!==""&&(_e(e,a,o),o="",l=!0);let{words:d,hadTrailingDelimiter:p}=qr(c.value,n,e.limits.maxArrayElements);if(d.length===0)p&&(u=!0);else if(d.length===1)o+=d[0],l=!0,u=p;else{o+=d[0],_e(e,a,o),l=!0;for(let h=1;h<d.length-1;h++)_e(e,a,d[h]);o=d[d.length-1],u=p}}return o!==""?_e(e,a,o):a.length===0&&l&&_e(e,a,""),a}function _u(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Lu(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}var es="/dev/fd",Mu=63,_p=10,Tu=Mu-_p+1,Mi=class extends At{isLiveDescriptor;constructor(t){super(),this.isLiveDescriptor=t}assertLiveDescriptor(t,n){this.isLiveDescriptor(t)||this.refuse(t,n)}refuse(t,n){throw new Error(`EROFS: read-only file system, ${n} '${es}${t}'`)}async writeFile(t,n,r){return this.assertLiveDescriptor(t,"write"),super.writeFile(t,n,r)}async appendFile(t,n,r){return this.assertLiveDescriptor(t,"append"),super.appendFile(t,n,r)}async rm(t,n){return this.assertLiveDescriptor(t,"rm"),super.rm(t,n)}async mkdir(t,n){this.refuse(t,"mkdir")}async cp(t,n){this.refuse(n,"cp")}async mv(t,n){this.refuse(n,"mv")}async symlink(t,n){this.refuse(n,"symlink")}async link(t,n){this.refuse(n,"link")}async chmod(t,n){this.refuse(t,"chmod")}async utimes(t,n,r){this.refuse(t,"utimes")}};function Lp(e){let t=new Mi(n=>Fu(e).some(r=>r.path===`${es}${n}`));e.fs=new dn({base:e.fs,mounts:[{mountPoint:es,filesystem:t}]}),e.state.processSubstitutionFsMounted=!0}async function Tp(e,t,n){try{await e.fs.writeFile(t,n,"binary");return}catch(r){if(e.state.processSubstitutionFsMounted)throw r;Lp(e)}await e.fs.writeFile(t,n,"binary")}async function Mp(e,t){try{await e.fs.rm(t,{force:!0})}catch{}}function Fu(e){let t=e.state.processSubstitutions;if(t)return t;let n=[];return e.state.processSubstitutions=n,n}async function Bu(e,t,n){let r=e.substitutionDepth??0,s=e.limits.maxSubstitutionDepth;if(r>=s)throw new P(`Process substitution nesting limit exceeded (${s})`,"substitution_depth");let i=e.substitutionDepth,a=new Map(e.state.env),o=st(e.state.arrays),l=e.state.cwd,u=e.state.bashPid,c=e.state.suppressVerbose,f=e.state.groupStdin,d=e.state.lastExitCode,p=e.state.env.get("?"),h=e.state.lastSubstitutionExitCode;e.substitutionDepth=r+1,e.state.bashPid=e.state.nextVirtualPid++,e.state.suppressVerbose=!0,n!==void 0&&(e.state.groupStdin=n);let m;try{m=await e.executeScript(t)}catch(E){if(E instanceof P)throw E;if(E instanceof q)return{stdout:E.stdout,stderr:E.stderr,exitCode:E.exitCode};throw E}finally{e.substitutionDepth=i,e.state.env=a,e.state.arrays=o,e.state.cwd=l,e.state.bashPid=u,e.state.suppressVerbose=c,e.state.groupStdin=f,e.state.lastExitCode=d,e.state.lastSubstitutionExitCode=h,p!==void 0?e.state.env.set("?",p):e.state.env.delete("?")}return m}async function Wu(e,t){let n=Fu(e);if(n.length>=Tu)throw new P(`Process substitution limit exceeded (${Tu} concurrent)`,"file_descriptors");let r="";if(t.direction==="input"){let a=await Bu(e,t.body,void 0);if(a.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+a.stderr),r=Lt(a),r.length>e.limits.maxStringLength)throw new P(`process substitution: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")}let s=Mu-n.length,i=`${es}/${s}`;n.push({fd:s,path:i,direction:t.direction,body:t.body});try{await Tp(e,i,r)}catch(a){throw n.pop(),a}return i}function Vu(e){return e.state.processSubstitutions?.length??0}var Fp={stdout:"",stderr:""};async function Fi(e,t){let n=e.state.processSubstitutions;if(!n||n.length<=t)return Fp;let r="",s="";for(;n.length>t;){let i=n[n.length-1],a="";if(i.direction==="output")try{a=await $n(e.fs,i.path)}catch{}if(await Mp(e,i.path),n.pop(),i.direction==="output"){let o=await Bu(e,i.body,a);r+=Lt(o),s+=o.stderr}}return{stdout:r,stderr:s}}function Yt(e,t,n){if(e.length>t)throw new P(`${n}: string length limit exceeded (${t} bytes)`,"string_length")}async function wt(e,t,n=!1){let r=[],s=0;for(let i of t){let a=await Ye(e,i,n);if(s+=M(a),s>e.limits.maxStringLength)throw new P(`parameter word string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");r.push(a)}return r.join("")}function Bp(e){return Lu(e)}function qu(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!Bp(t))return!1;return!0}function Wp(e,t,n=!1){let r=_u(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 Oi(e,t.pattern);default:return null}}async function ne(e,t){return Wi(e,t)}async function Uu(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped")n.push(Tn(r.value));else if(r.type==="SingleQuoted")n.push(r.value);else if(r.type==="DoubleQuoted"){let s=await wt(e,r.parts);n.push(s)}else if(r.type==="TildeExpansion"){let s=await Ye(e,r);n.push(Tn(s))}else n.push(await Ye(e,r));return n.join("")}async function ju(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 wt(e,r.parts);n.push(Xe(s))}else n.push(await Ye(e,r));return n.join("")}async function Gu(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 wt(e,r.parts);n.push(Xe(s))}else r.type==="Glob"?Jl(r.pattern)?n.push(await tu(e,r.pattern)):n.push(Oi(e,r.pattern)):r.type==="Literal"?n.push(r.value):n.push(await Ye(e,r));return n.join("")}function ns(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&ns(t.parts))return!0;return!1}var zu=1e5;async function Hu(e,t,n={count:0}){let r=()=>{n.count++,e.executionScope.consumeLimited("brace_operations",1,Math.min(zu,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,u="";for(let d of a.items)if(d.type==="Range"){let p=Ni(d.start,d.end,d.step,d.startStr,d.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(p.expanded)for(let h of p.expanded)s(o,h);else{l=!0,u=p.literal;break}}else{let p=await Hu(e,d.word.parts,n);for(let h of p){let m=[];for(let E of h)typeof E=="string"?m.push(E):m.push(await Ye(e,E));s(o,m.join(""))}}if(l){for(let d of i)r(),d.push(u);continue}if(i.length*o.length>e.limits.maxBraceExpansionResults||n.count>zu)throw new P(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");let f=[];for(let d of i)for(let p 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,p])}i=f}else for(let o of i)r(),o.push(a);return i}async function Zu(e,t){let n=t.parts;if(!ns(n))return[await ne(e,t)];let r=await Hu(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(_i(e,a.join("")))}return s}function Vp(){return{expandWordAsync:Wi,expandWordForGlobbing:Gu,expandWordWithBracesAsync:Zu,expandWordPartsAsync:wt,expandPart:Ye,expandParameterAsync:ts,hasBraceExpansion:ns,evaluateArithmetic:X,buildIfsCharClassPattern:Dl,smartWordSplit:Ou}}async function Et(e,t){return Ru(e,t,Vp())}function zp(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Bi(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 Qu(e,t){if(Bi(e,t))return{error:`bash: $@: ambiguous redirect
113
+ `};let n=t.parts,{hasQuoted:r}=or(n);if(ns(n)&&(await Zu(e,t)).length>1)return{error:`bash: ${n.map(p=>p.type==="Literal"?p.value:p.type==="BraceExpansion"?`{${p.items.map(m=>{if(m.type==="Range"){let E=m.step?`..${m.step}`:"";return`${m.startStr??m.start}..${m.endStr??m.end}${E}`}return m.word.parts.map(E=>E.type==="Literal"?E.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect
114
+ `};let s=await Wi(e,t),{hasParamExpansion:i,hasCommandSub:a}=or(n);if((i||a)&&!r&&!Ne(e.state.env)){let f=Ae(e.state.env);if(ce(s,f,e.limits.maxArrayElements).length>1)return{error:`bash: $${zp(n)}: ambiguous redirect
115
+ `}}if(r||e.state.options.noglob||n.some(f=>f.type==="ProcessSubstitution"))return{target:s};let l=await Gu(e,t);if(!kt(l,e.state.shoptOptions.extglob))return{target:s};let u=new Gt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")}),c=await u.expand(l);return c.length===0?u.hasFailglob()?{error:`bash: no match: ${s}
111
116
  `}:{target:s}:c.length===1?{target:c[0]}:{error:`bash: ${s}: ambiguous redirect
112
- `}}async function Di(e,t){let n=t.parts,r=n.length;if(r===1){let a=await Xe(e,n[0]);return qt(a,e.limits.maxStringLength,"word expansion"),a}let s=[];for(let a=0;a<r;a++)s.push(await Xe(e,n[a]));let i=s.join("");return qt(i,e.limits.maxStringLength,"word expansion"),i}async function Xe(e,t,n=!1){if(t.type==="ParameterExpansion")return Zr(e,t,n);let r=Rp(e,t,n);if(r!==null)return r;switch(t.type){case"DoubleQuoted":{let s=[];for(let i of t.parts)s.push(await Xe(e,i,!0));return s.join("")}case"CommandSubstitution":{let s=kl(t.body);if(s)try{let p=await ne(e,s.target),h=p.startsWith("/")?p:`${e.state.cwd}/${p}`,m=await e.fs.readFile(h);e.state.lastExitCode=0,e.state.env.set("?","0");let E=m.replace(/\n+$/,"");return qt(E,e.limits.maxStringLength,"command substitution"),E}catch(p){if(p instanceof k)throw p;return e.state.lastExitCode=1,e.state.env.set("?","1"),""}let i=e.substitutionDepth??0,a=e.limits.maxSubstitutionDepth;if(i>=a)throw new k(`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 u=new Map(e.state.env),c=nt(e.state.arrays),f=e.state.cwd,d=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let p=await e.executeScript(t.body),h=p.exitCode;e.state.env=u,e.state.arrays=c,e.state.cwd=f,e.state.suppressVerbose=d,e.state.lastExitCode=h,e.state.env.set("?",String(h)),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr),e.state.bashPid=l,e.substitutionDepth=o;let m=p.stdout.replace(/\n+$/,"");return qt(m,e.limits.maxStringLength,"command substitution"),m}catch(p){if(e.state.env=u,e.state.arrays=c,e.state.cwd=f,e.state.bashPid=l,e.substitutionDepth=o,e.state.suppressVerbose=d,p instanceof k)throw p;if(p instanceof U){e.state.lastExitCode=p.exitCode,e.state.env.set("?",String(p.exitCode)),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr);let h=p.stdout.replace(/\n+$/,"");return qt(h,e.limits.maxStringLength,"command substitution"),h}throw p}}case"ProcessSubstitution":return Nu(e,t);case"ArithmeticExpansion":{let s=t.expression.originalText;if(s&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(s)){let a=await xl(e,s),o=new G,l=te(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=Ai(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 ne(e,i.word));return s.join(" ")}default:return""}}async function Zr(e,t,n=!1){let{parameter:r}=t,{operation:s}=t,i=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(i){let[,d,p]=i;if(e.state.associativeArrays?.has(d)||p.includes("$(")||p.includes("`")||p.includes("${")){let m=await bi(e,p);r=`${d}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&le(e,r)){let d=Te(e,r);if(d&&d!==r){let p=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(p){let[,h,m]=p;if(e.state.associativeArrays?.has(h)||m.includes("$(")||m.includes("`")||m.includes("${")){let b=await bi(e,m);r=`${h}[${b}]`}}}}let a=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),o=await re(e,r,!a);if(!s)return o;let l=!await Et(e,r),{isEmpty:u,effectiveValue:c}=Vl(e,r,o,n),f={value:o,isUnset:l,isEmpty:u,effectiveValue:c,inDoubleQuotes:n};switch(s.type){case"DefaultValue":return Cl(e,s,f,pt);case"AssignDefault":return Nl(e,r,s,f,pt);case"ErrorIfUnset":return Rl(e,r,s,f,pt);case"UseAlternative":return Dl(e,s,f,pt);case"PatternRemoval":{let d=await Il(e,o,s,pt,Xe);return qt(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await Ol(e,o,s,pt,Xe);return qt(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return _l(e,r,o);case"LengthSliceError":throw new Ze(r);case"BadSubstitution":throw new Ze(s.text);case"Substring":return Ll(e,r,o,s);case"CaseModification":{let d=await Tl(e,o,s,pt,Zr);return qt(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return Ml(e,r,o,l,s);case"Indirection":return Fl(e,r,o,l,s,Zr,n);case"ArrayKeys":return Bl(e,s);case"VarNamePrefix":return Wl(e,s);default:return o}}function Wu(){return{visited:new Set,depth:0}}function Op(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 Bu(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 _p(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function Lp(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 re(e,t)}async function Tp(e,t,n){if(!t)return 0;let r=Number.parseInt(t,10);if(!Number.isNaN(r)&&/^-?\d+$/.test(t.trim()))return r;let s=t.trim();if(!s)return 0;let i=new G,{expr:a,pos:o}=Pn(i,s,0);if(o<s.length){let l=s.slice(o).trim(),u=l.split(/\s+/)[0]||l;throw new oe(`syntax error in expression (error token is "${u}")`,"","")}return await Dn(e,a,!1,n)}async function Qr(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 Tp(e,n,r)}finally{r.depth--,r.visited.delete(t)}}async function Ii(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 Lp(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 Ii(e,i,n);let a=new G,{expr:o,pos:l}=Pn(a,i,0);if(l<i.length){let u=i.slice(l).trim(),c=u.split(/\s+/)[0]||u;throw new oe(`${i}: syntax error in expression (error token is "${c}")`)}return await Dn(e,o,!1,n)}finally{n.depth--,n.visited.delete(t)}}async function Kr(e,t){if(t.startsWith("#")){let f=t.slice(1),d=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(d){let h=d[1],m=Z(e,h);return String(m.length)}let p=e.state.env.get(f)||"";return String(p.length)}if(t.startsWith("!")){let f=t.slice(1),d=e.state.env.get(f)||"";return e.state.env.get(d)||""}let n=[":-",":=",":?",":+","-","=","?","+"],r=-1,s="";for(let f of n){let d=t.indexOf(f);d>0&&(r===-1||d<r)&&(r=d,s=f)}if(r===-1)return await re(e,t);let i=t.slice(0,r),a=t.slice(r+s.length),o=e.state.env.get(i),l=o===void 0,u=o==="",c=s.startsWith(":");switch(s){case":-":case"-":return l||c&&u?a:o||"";case":=":case"=":return l||c&&u?(e.state.env.set(i,a),a):o||"";case":+":case"+":return!(l||c&&u)?a:"";case":?":case"?":{if(l||c&&u)throw new Error(a||`${i}: parameter null or not set`);return o||""}default:return o||""}}async function K(e,t,n=!1){return Dn(e,t,n,Wu())}async function Dn(e,t,n,r){let s=(i,a=n)=>Dn(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 Ii(e,t.name,r);case"ArithSpecialVar":{let a=(await re(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 G,{expr:u}=Pn(l,a,0);return await s(u)}case"ArithNested":return await s(t.expression);case"ArithCommandSubst":{if(e.execFn){let i=await e.execFn(t.command,{signal:e.state.signal});i.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+i.stderr);let a=i.stdout.trim();return Number.parseInt(a,10)||0}return 0}case"ArithBracedExpansion":{let i=await Kr(e,t.content);return Number.parseInt(i,10)||0}case"ArithDynamicBase":{let i=await Kr(e,t.baseExpr),a=Number.parseInt(i,10);if(a<2||a>64)return 0;let o=`${a}#${t.value}`;return Qn(o)}case"ArithDynamicNumber":{let a=await Kr(e,t.prefix)+t.suffix;return Qn(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 Qr(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 re(e,t.index.name);return await a(o)}if(t.index){let o=await s(t.index);if(o<0){let c=Z(e,t.array),f=e.state.currentLine;if(c.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
117
+ `}}async function Wi(e,t){let n=t.parts,r=n.length;if(r===1){let a=await Ye(e,n[0]);return Yt(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 Yt(i,e.limits.maxStringLength,"word expansion"),i}async function Ye(e,t,n=!1){if(t.type==="ParameterExpansion")return ts(e,t,n);let r=Wp(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=Fl(t.body);if(s)try{let p=await ne(e,s.target),h=p.startsWith("/")?p:`${e.state.cwd}/${p}`,m=await e.fs.readFile(h);Kt(e.state,0);let E=m.replace(/\n+$/,"");return Yt(E,e.limits.maxStringLength,"command substitution"),E}catch(p){if(p instanceof P)throw p;return Kt(e.state,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 u=new Map(e.state.env),c=st(e.state.arrays),f=e.state.cwd,d=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let p=await e.executeScript(t.body),h=p.exitCode;e.state.env=u,e.state.arrays=c,e.state.cwd=f,e.state.suppressVerbose=d,Kt(e.state,h),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr),e.state.bashPid=l,e.substitutionDepth=o;let m=p.stdout.replace(/\n+$/,"");return Yt(m,e.limits.maxStringLength,"command substitution"),m}catch(p){if(e.state.env=u,e.state.arrays=c,e.state.cwd=f,e.state.bashPid=l,e.substitutionDepth=o,e.state.suppressVerbose=d,p instanceof P)throw p;if(p instanceof q){Kt(e.state,p.exitCode),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr);let h=p.stdout.replace(/\n+$/,"");return Yt(h,e.limits.maxStringLength,"command substitution"),h}throw p}}case"ProcessSubstitution":return Wu(e,t);case"ArithmeticExpansion":{let s=t.expression.originalText;if(s&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(s)){let a=await Ml(e,s),o=new j,l=te(o,a);return String(await X(e,l.expression,!0))}return String(await X(e,t.expression.expression,!0))}case"BraceExpansion":{let s=[];for(let i of t.items)if(i.type==="Range"){let a=Ni(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 ne(e,i.word));return s.join(" ")}default:return""}}async function ts(e,t,n=!1){let{parameter:r}=t,{operation:s}=t,i=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(i){let[,d,p]=i;if(e.state.associativeArrays?.has(d)||p.includes("$(")||p.includes("`")||p.includes("${")){let m=await Pi(e,p);r=`${d}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&le(e,r)){let d=Me(e,r);if(d&&d!==r){let p=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(p){let[,h,m]=p;if(e.state.associativeArrays?.has(h)||m.includes("$(")||m.includes("`")||m.includes("${")){let S=await Pi(e,m);r=`${h}[${S}]`}}}}if(s?.type==="Length"&&/^[a-zA-Z_][a-zA-Z0-9_]*\[[@*]\]$/.test(r))return Ii(e,r,"");let a=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),o=await re(e,r,!a);if(!s)return o;let l=!await xt(e,r),{isEmpty:u,effectiveValue:c}=Yl(e,r,o,n),f={value:o,isUnset:l,isEmpty:u,effectiveValue:c,inDoubleQuotes:n};switch(s.type){case"DefaultValue":return Wl(e,s,f,wt);case"AssignDefault":return Vl(e,r,s,f,wt);case"ErrorIfUnset":return zl(e,r,s,f,wt);case"UseAlternative":return ql(e,s,f,wt);case"PatternRemoval":{let d=await Ul(e,o,s,wt,Ye);return Yt(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await jl(e,o,s,wt,Ye);return Yt(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return Ii(e,r,o);case"LengthSliceError":throw new Ze(r);case"BadSubstitution":throw new Ze(s.text);case"Substring":return Gl(e,r,o,s);case"CaseModification":{let d=await Hl(e,o,s,wt,ts);return Yt(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return Zl(e,r,o,l,s);case"Indirection":return Ql(e,r,o,l,s,ts,n);case"ArrayKeys":return Kl(e,s);case"VarNamePrefix":return Xl(e,s);default:return o}}function Xu(){return{visited:new Set,depth:0}}function qp(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new ae("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new ae("division by 0");return e%t;case"**":if(t<0)throw new ae("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 Ku(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 Up(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function jp(e,t){let n=e.state.env.get(t);if(n!==void 0)return n;let r=ie(e,t,0);return r!==void 0?r:await re(e,t)}async function Gp(e,t,n){if(!t)return 0;let r=Number.parseInt(t,10);if(!Number.isNaN(r)&&/^-?\d+$/.test(t.trim()))return r;let s=t.trim();if(!s)return 0;let i=new j,{expr:a,pos:o}=Ln(i,s,0);if(o<s.length){let l=s.slice(o).trim(),u=l.split(/\s+/)[0]||l;throw new ae(`syntax error in expression (error token is "${u}")`,"","")}return await Bn(e,a,!1,n)}async function rs(e,t,n,r){if(r.depth>100)throw new ae("maximum variable indirection depth exceeded");if(r.visited.has(t))throw new ae(`arithmetic variable cycle detected at ${t}`);r.visited.add(t),r.depth++;try{return await Gp(e,n,r)}finally{r.depth--,r.visited.delete(t)}}async function Vi(e,t,n){if(n.depth>100)throw new ae("maximum variable indirection depth exceeded");if(n.visited.has(t))throw new ae(`arithmetic variable cycle detected at ${t}`);n.visited.add(t),n.depth++;try{let r=await jp(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 Vi(e,i,n);let a=new j,{expr:o,pos:l}=Ln(a,i,0);if(l<i.length){let u=i.slice(l).trim(),c=u.split(/\s+/)[0]||u;throw new ae(`${i}: syntax error in expression (error token is "${c}")`)}return await Bn(e,o,!1,n)}finally{n.depth--,n.visited.delete(t)}}async function ss(e,t){if(t.startsWith("#")){let f=t.slice(1),d=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(d){let h=d[1],m=G(e,h);return String(m.length)}let p=e.state.env.get(f)||"";return String(p.length)}if(t.startsWith("!")){let f=t.slice(1),d=e.state.env.get(f)||"";return e.state.env.get(d)||""}let n=[":-",":=",":?",":+","-","=","?","+"],r=-1,s="";for(let f of n){let d=t.indexOf(f);d>0&&(r===-1||d<r)&&(r=d,s=f)}if(r===-1)return await re(e,t);let i=t.slice(0,r),a=t.slice(r+s.length),o=e.state.env.get(i),l=o===void 0,u=o==="",c=s.startsWith(":");switch(s){case":-":case"-":return l||c&&u?a:o||"";case":=":case"=":return l||c&&u?(e.state.env.set(i,a),a):o||"";case":+":case"+":return!(l||c&&u)?a:"";case":?":case"?":{if(l||c&&u)throw new Error(a||`${i}: parameter null or not set`);return o||""}default:return o||""}}async function X(e,t,n=!1){return Bn(e,t,n,Xu())}async function Bn(e,t,n,r){let s=(i,a=n)=>Bn(e,i,a,r);switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new ae("value too great for base");return t.value;case"ArithVariable":return await Vi(e,t.name,r);case"ArithSpecialVar":{let a=(await re(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 j,{expr:u}=Ln(l,a,0);return await s(u)}case"ArithNested":return await s(t.expression);case"ArithCommandSubst":{if(e.execFn){let i=await e.execFn(t.command,{signal:e.state.signal});i.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+i.stderr);let a=i.stdout.trim();return Number.parseInt(a,10)||0}return 0}case"ArithBracedExpansion":{let i=await ss(e,t.content);return Number.parseInt(i,10)||0}case"ArithDynamicBase":{let i=await ss(e,t.baseExpr),a=Number.parseInt(i,10);if(a<2||a>64)return 0;let o=`${a}#${t.value}`;return rr(o)}case"ArithDynamicNumber":{let a=await ss(e,t.prefix)+t.suffix;return rr(a)}case"ArithArrayElement":{let i=e.state.associativeArrays?.has(t.array),a=async o=>{let l=ie(e,t.array,o);return l!==void 0?await rs(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 re(e,t.index.name);return await a(o)}if(t.index){let o=await s(t.index);if(o<0){let c=G(e,t.array),f=e.state.currentLine;if(c.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
113
118
  `,0;let p=Math.max(...c.map(([h])=>typeof h=="number"?h:0))+1+o;if(p<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
114
- `,0;o=p}let l=`${t.array}[${o}]`,u=ae(e,t.array,o);if(u!==void 0)return Qr(e,l,u,r);if(o===0){let c=e.state.env.get(t.array);if(c!==void 0)return Qr(e,t.array,c,r)}if(e.state.options.nounset&&!(e.state.env.has(t.array)||Pe(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 Op(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 re(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 re(e,t.operand.index.name);else if(t.operand.index){let f=await s(t.operand.index);l=String(f)}else return i;let u=Number.parseInt(ae(e,a,l)||"0",10)||0,c=t.operator==="++"?u+1:u-1;return j(e,a,l,String(c),o?"associative":"indexed"),t.prefix?c:u}if(t.operand.type==="ArithConcat"){let a="";for(let o of t.operand.parts)a+=await Rn(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 Rn(e,o,n,r);else t.operand.nameExpr.type==="ArithVariable"&&(a=t.operand.nameExpr.hasDollarPrefix?await re(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,u=t.operator==="++"?l+1:l-1;return j(e,a,o,String(u)),t.prefix?u:l}}return i}return _p(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 re(e,t.subscript.name)||"\\";else if(d){let p=await s(t.subscript);o=String(p)}else{let p=await s(t.subscript);if(p<0){let h=Z(e,i);h.length>0&&(p=Math.max(...h.map(([E])=>typeof E=="number"?E:0))+1+p)}o=String(p)}}let l=o===void 0?e.state.env.get(a):ae(e,i,o),u=Number.parseInt(l||"0",10)||0,c=await s(t.value),f=Bu(u,c,t.operator);return o===void 0?e.state.env.set(a,String(f)):j(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 Rn(e,a,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)?await Ii(e,i,r):Number.parseInt(i,10)||0}case"ArithDynamicAssignment":{let i="";if(t.target.type==="ArithConcat")for(let c of t.target.parts)i+=await Rn(e,c,n,r);else t.target.type==="ArithVariable"&&(i=t.target.hasDollarPrefix?await re(e,t.target.name):t.target.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let a=i;if(t.subscript){let c=await s(t.subscript);a=`${i}_${c}`}let o=Number.parseInt(e.state.env.get(a)||"0",10)||0,l=await s(t.value),u=Bu(o,l,t.operator);return e.state.env.set(a,String(u)),u}case"ArithDynamicElement":{let i="";if(t.nameExpr.type==="ArithConcat")for(let u of t.nameExpr.parts)i+=await Rn(e,u,n,r);else t.nameExpr.type==="ArithVariable"&&(i=t.nameExpr.hasDollarPrefix?await re(e,t.nameExpr.name):t.nameExpr.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let a=await s(t.subscript),o=`${i}_${a}`,l=e.state.env.get(o);return l!==void 0?Qr(e,o,l,r):0}default:return 0}}async function Rn(e,t,n=!1,r=Wu()){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await Dn(e,t,n,r));case"ArithVariable":return t.hasDollarPrefix?await re(e,t.name):t.name;case"ArithSpecialVar":return await re(e,t.name);case"ArithBracedExpansion":return await Kr(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 Rn(e,i,n,r);return s}default:return String(await Dn(e,t,n,r))}}async function Vu(e,t){let n="",r=0;for(let v of t.parts){let $=v.type==="Literal"?v.value:"\0",A=F($);if(A>e.limits.maxStringLength-r)throw new k(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n+=$,r+=A}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,u="",c=0,f=0,d=!1,p=!0,h=v=>{let $=F(v);if($>e.limits.maxStringLength-f-c)throw new k(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u+=v,c+=$},m=(v,$=!1)=>{if(a.length>=e.limits.maxArrayElements)throw new k(`array assignment element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let A=F(v);if(A>e.limits.maxStringLength-f)throw new k(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");a.push(v),o.push($),f+=A},E=()=>{m(u,p),u="",c=0,d=!1,p=!0};for(let v of t.parts)if(v.type==="Literal"){let $=v.value;if(!l){let A=$.indexOf("=(");A!==-1&&(l=!0,$=$.slice(A+2))}if(l){$.endsWith(")")&&($=$.slice(0,-1));for(let A of $)/\s/.test(A)?(u||d)&&E():h(A)}}else if(l)if(v.type==="BraceExpansion")if(/^\[.+\]=/.test(u))h(xn({type:"Word",parts:[v]}));else{(u||d)&&E();let A=await ht(e,{type:"Word",parts:[v]});for(let C of A.values)m(C)}else{(v.type==="SingleQuoted"||v.type==="DoubleQuoted"||v.type==="Escaped")&&(d=!0),p=!1;let $=await ne(e,{type:"Word",parts:[v]});h($)}(u||d)&&E();let b=a.splice(0),g=o.splice(0);f=0;for(let v=0;v<b.length;v++){let $=b[v];if(!g[v]){m($);continue}let A=$.match(/^(\[[^\]]+\]=)(.*)$/s);if(A){let C=zt(e,A[2]);$=A[1]+C}if($.includes("{")&&$.includes("}")){let C=new G().parseWordFromString($,!1,!1);if(C.parts.some(N=>N.type==="BraceExpansion")){let N=await ht(e,C);for(let x of N.values)m(x);continue}}m($)}let y=[`${i}=(`],S=F(y[0]);for(let v=0;v<a.length;v++){let $=a[v],A;/^\[.+\]=/.test($)?A=$:$===""?A="''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test($)&&!$.startsWith("'")&&!$.startsWith('"')?A=`'${$.replace(/'/g,"'\\''")}'`:A=$;let C=`${v>0?" ":""}${A}`,N=F(C);if(N+1>e.limits.maxStringLength-S)throw new k(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");y.push(C),S+=N}return y.push(")"),y.join("")}async function zu(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 y=E.value.slice(0,b);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(y)){n=m,r=b,s=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(y)){n=m,r=b,s=!0;break}}let g=E.value.indexOf("=");if(g!==-1&&(g===0||E.value[g-1]!=="+")){let y=E.value.slice(0,g);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(y)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(y)){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),u=a.value.slice(r+o),c=t.parts.slice(n+1),f="";for(let m of i)f+=await ne(e,{type:"Word",parts:[m]});f+=l;let d={type:"Word",parts:u!==""?[{type:"Literal",value:u},...c]:c},p=d.parts.length>0?await ne(e,d):"";return`${f}${s?"+=":"="}${p}`}var Mp=["tar","yq","xan","sqlite3","python3","python"];function qu(e){return Mp.includes(e)}var ee=Object.freeze({stdout:"",stderr:"",exitCode:0,internalStdinConsumed:0});function Y(e=""){return{stdout:e,stderr:"",exitCode:0}}function I(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function L(e,t,n){return{stdout:e,stderr:t,exitCode:n}}function ge(e){return{stdout:"",stderr:"",exitCode:e?0:1,internalStdinConsumed:0}}function Ut(e,t,n="",r=""){throw new k(e,t,n,r)}function Uu(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new k(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function Oi(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Rt;return ee}if(t.length>1)throw new U(1,"",`bash: break: too many arguments
115
- `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new U(128,"",`bash: break: ${t[0]}: numeric argument required
116
- `);n=r}throw new je(n)}async function _i(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(p=>p);for(let p of d){let h=p.startsWith("/")?`${p}/${n}`:`${e.state.cwd}/${p}/${n}`;try{if((await e.fs.stat(h)).isDirectory){n=h,r=!0;break}}catch{}}}}let l=(n.startsWith("/")?n:`${e.state.cwd}/${n}`).split("/").filter(f=>f&&f!=="."),u="";for(let f of l)if(f==="..")u=u.split("/").slice(0,-1).join("/")||"/";else{u=u?`${u}/${f}`:`/${f}`;try{if(!(await e.fs.stat(u)).isDirectory)return I(`bash: cd: ${n}: Not a directory
117
- `)}catch{return I(`bash: cd: ${n}: No such file or directory
119
+ `,0;o=p}let l=`${t.array}[${o}]`,u=ie(e,t.array,o);if(u!==void 0)return rs(e,l,u,r);if(o===0){let c=e.state.env.get(t.array);if(c!==void 0)return rs(e,t.array,c,r)}if(e.state.options.nounset&&!(e.state.env.has(t.array)||Pe(e,t.array)))throw new We(`${t.array}[${o}]`);return 0}return 0}case"ArithDoubleSubscript":throw new ae("double subscript","","");case"ArithNumberSubscript":throw new ae(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new ae(t.message,"","",!0);case"ArithSingleQuote":{if(n)throw new ae(`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 qp(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 re(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 re(e,t.operand.index.name);else if(t.operand.index){let f=await s(t.operand.index);l=String(f)}else return i;let u=Number.parseInt(ie(e,a,l)||"0",10)||0,c=t.operator==="++"?u+1:u-1;return U(e,a,l,String(c),o?"associative":"indexed"),t.prefix?c:u}if(t.operand.type==="ArithConcat"){let a="";for(let o of t.operand.parts)a+=await Fn(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 Fn(e,o,n,r);else t.operand.nameExpr.type==="ArithVariable"&&(a=t.operand.nameExpr.hasDollarPrefix?await re(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(ie(e,a,o)||"0",10)||0,u=t.operator==="++"?l+1:l-1;return U(e,a,o,String(u)),t.prefix?u:l}}return i}return Up(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 re(e,t.subscript.name)||"\\";else if(d){let p=await s(t.subscript);o=String(p)}else{let p=await s(t.subscript);if(p<0){let h=G(e,i);h.length>0&&(p=Math.max(...h.map(([E])=>typeof E=="number"?E:0))+1+p)}o=String(p)}}let l=o===void 0?e.state.env.get(a):ie(e,i,o),u=Number.parseInt(l||"0",10)||0,c=await s(t.value),f=Ku(u,c,t.operator);return o===void 0?e.state.env.set(a,String(f)):U(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 Fn(e,a,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)?await Vi(e,i,r):Number.parseInt(i,10)||0}case"ArithDynamicAssignment":{let i="";if(t.target.type==="ArithConcat")for(let c of t.target.parts)i+=await Fn(e,c,n,r);else t.target.type==="ArithVariable"&&(i=t.target.hasDollarPrefix?await re(e,t.target.name):t.target.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let a=i;if(t.subscript){let c=await s(t.subscript);a=`${i}_${c}`}let o=Number.parseInt(e.state.env.get(a)||"0",10)||0,l=await s(t.value),u=Ku(o,l,t.operator);return e.state.env.set(a,String(u)),u}case"ArithDynamicElement":{let i="";if(t.nameExpr.type==="ArithConcat")for(let u of t.nameExpr.parts)i+=await Fn(e,u,n,r);else t.nameExpr.type==="ArithVariable"&&(i=t.nameExpr.hasDollarPrefix?await re(e,t.nameExpr.name):t.nameExpr.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let a=await s(t.subscript),o=`${i}_${a}`,l=e.state.env.get(o);return l!==void 0?rs(e,o,l,r):0}default:return 0}}async function Fn(e,t,n=!1,r=Xu()){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await Bn(e,t,n,r));case"ArithVariable":return t.hasDollarPrefix?await re(e,t.name):t.name;case"ArithSpecialVar":return await re(e,t.name);case"ArithBracedExpansion":return await ss(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command,{signal:e.state.signal})).stdout.trim():"0";case"ArithConcat":{let s="";for(let i of t.parts)s+=await Fn(e,i,n,r);return s}default:return String(await Bn(e,t,n,r))}}async function Yu(e,t){let n="",r=0;for(let $ of t.parts){let A=$.type==="Literal"?$.value:"\0",k=M(A);if(k>e.limits.maxStringLength-r)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n+=A,r+=k}let s=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(\+?=)\(/);if(!s||!n.endsWith(")"))return null;let i=s[1],a=s[2],o=[],l=[],u=!1,c="",f=0,d=0,p=!1,h=!0,m=$=>{let A=M($);if(A>e.limits.maxStringLength-d-f)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");c+=$,f+=A},E=($,A=!1)=>{if(o.length>=e.limits.maxArrayElements)throw new P(`array assignment element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let k=M($);if(k>e.limits.maxStringLength-d)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");o.push($),l.push(A),d+=k},S=()=>{E(c,h),c="",f=0,p=!1,h=!0};for(let $ of t.parts)if($.type==="Literal"){let A=$.value;if(!u){let k=A.indexOf("=(");k!==-1&&(u=!0,A=A.slice(k+2))}if(u){A.endsWith(")")&&(A=A.slice(0,-1));for(let k of A)/\s/.test(k)?(c||p)&&S():m(k)}}else if(u)if($.type==="BraceExpansion")if(/^\[.+\]=/.test(c))m(On({type:"Word",parts:[$]}));else{(c||p)&&S();let k=await Et(e,{type:"Word",parts:[$]});for(let N of k.values)E(N)}else{($.type==="SingleQuoted"||$.type==="DoubleQuoted"||$.type==="Escaped")&&(p=!0),h=!1;let A=await ne(e,{type:"Word",parts:[$]});m(A)}(c||p)&&S();let y=o.splice(0),g=l.splice(0);d=0;for(let $=0;$<y.length;$++){let A=y[$];if(!g[$]){E(A);continue}let k=A.match(/^(\[[^\]]+\]=)(.*)$/s);if(k){let N=Xt(e,k[2]);A=k[1]+N}if(A.includes("{")&&A.includes("}")){let N=new j().parseWordFromString(A,!1,!1);if(N.parts.some(x=>x.type==="BraceExpansion")){let x=await Et(e,N);for(let C of x.values)E(C);continue}}E(A)}let b=[`${i}${a}(`],v=M(b[0]);for(let $=0;$<o.length;$++){let A=o[$],k,N=A.match(/^(\[[^\]]+\]=)(.*)$/s);if(N){let D=N[2].replace(/\\/g,"\\\\").replace(/"/g,'\\"');k=`${N[1]}"${D}"`}else A===""?k="''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(A)&&!A.startsWith("'")&&!A.startsWith('"')?k=`'${A.replace(/'/g,"'\\''")}'`:k=A;let x=`${$>0?" ":""}${k}`,C=M(x);if(C+1>e.limits.maxStringLength-v)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");b.push(x),v+=C}return b.push(")"),b.join("")}async function Ju(e,t){let n=-1,r=-1,s=!1;for(let m=0;m<t.parts.length;m++){let E=t.parts[m];if(E.type==="Literal"){let S=E.value.indexOf("+=");if(S!==-1){let g=E.value.slice(0,S);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(g)){n=m,r=S,s=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(g)){n=m,r=S,s=!0;break}}let y=E.value.indexOf("=");if(y!==-1&&(y===0||E.value[y-1]!=="+")){let g=E.value.slice(0,y);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(g)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(g)){n=m,r=y;break}}}}if(n===-1)return null;let i=t.parts.slice(0,n),a=t.parts[n];if(a.type!=="Literal")return null;let o=s?2:1,l=a.value.slice(0,r),u=a.value.slice(r+o),c=t.parts.slice(n+1),f="";for(let m of i)f+=await ne(e,{type:"Word",parts:[m]});f+=l;let d={type:"Word",parts:u!==""?[{type:"Literal",value:u},...c]:c},p=d.parts.length>0?await ne(e,d):"";return`${f}${s?"+=":"="}${p}`}var Hp=["tar","yq","xan","sqlite3","python3","python"];function ec(e){return Hp.includes(e)}var J=Object.freeze({stdout:"",stderr:"",exitCode:0,internalStdinConsumed:0});function Y(e=""){return{stdout:e,stderr:"",exitCode:0}}function _(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function L(e,t,n){return{stdout:e,stderr:t,exitCode:n}}function ge(e){return{stdout:"",stderr:"",exitCode:e?0:1,internalStdinConsumed:0}}function Jt(e,t,n="",r=""){throw new P(e,t,n,r)}function tc(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 zi(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Mt;return J}if(t.length>1)throw new q(1,"",`bash: break: too many arguments
120
+ `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new q(128,"",`bash: break: ${t[0]}: numeric argument required
121
+ `);n=r}throw new Ge(n)}async function qi(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(p=>p);for(let p of d){let h=p.startsWith("/")?`${p}/${n}`:`${e.state.cwd}/${p}/${n}`;try{if((await e.fs.stat(h)).isDirectory){n=h,r=!0;break}}catch{}}}}let l=(n.startsWith("/")?n:`${e.state.cwd}/${n}`).split("/").filter(f=>f&&f!=="."),u="";for(let f of l)if(f==="..")u=u.split("/").slice(0,-1).join("/")||"/";else{u=u?`${u}/${f}`:`/${f}`;try{if(!(await e.fs.stat(u)).isDirectory)return _(`bash: cd: ${n}: Not a directory
122
+ `)}catch{return _(`bash: cd: ${n}: No such file or directory
118
123
  `)}}let c=u||"/";if(s)try{c=await e.fs.realpath(c)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=c,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),Y(r?`${c}
119
- `:"")}function Li(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Fp=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function Xr(e){return Fp.includes(e)}async function Yr(e,t,n){let r=Li(e,n);switch(t){case"-e":case"-a":return e.fs.exists(r);case"-f":return await e.fs.exists(r)?(await e.fs.stat(r)).isFile:!1;case"-d":return await e.fs.exists(r)?(await e.fs.stat(r)).isDirectory:!1;case"-r":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&256)!==0:!1;case"-w":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&128)!==0:!1;case"-x":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&64)!==0:!1;case"-s":return await e.fs.exists(r)?(await e.fs.stat(r)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(r)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&512)!==0:!1;case"-g":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(r);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].includes(r);case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(r);default:return!1}}var Bp=["-nt","-ot","-ef"];function Jr(e){return Bp.includes(e)}async function es(e,t,n,r){let s=Li(e,n),i=Li(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,u]=await Promise.all([e.fs.stat(s),e.fs.stat(i)]);return l.dev!==void 0&&l.ino!==void 0&&u.dev!==void 0&&u.ino!==void 0?l.dev===u.dev&&l.ino===u.ino:l.identity&&u.identity?l.identity===u.identity:!1}catch{return!1}default:return!1}}var Wp=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function ts(e){return Wp.has(e)}function ns(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 sr(e){return e==="="||e==="=="||e==="!="}function rs(e,t,n,r=!1,s=!1,i=!1,a=256){if(r){let l=In(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 Vp=new Set(["-z","-n"]);function ss(e){return Vp.has(e)}function is(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function as(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,u)=>e.state.env.get(u)||""),Tt(e,r,o)}let a;try{let o=new G,l=te(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=be(e,r),l=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
124
+ `:"")}function Ui(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Zp=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function is(e){return Zp.includes(e)}async function as(e,t,n){let r=Ui(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 Qp=["-nt","-ot","-ef"];function os(e){return Qp.includes(e)}async function ls(e,t,n,r){let s=Ui(e,n),i=Ui(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,u]=await Promise.all([e.fs.stat(s),e.fs.stat(i)]);return l.dev!==void 0&&l.ino!==void 0&&u.dev!==void 0&&u.ino!==void 0?l.dev===u.dev&&l.ino===u.ino:l.identity&&u.identity?l.identity===u.identity:!1}catch{return!1}default:return!1}}var Kp=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function us(e){return Kp.has(e)}function cs(e,t,n){switch(e){case"-eq":return t===n;case"-ne":return t!==n;case"-lt":return t<n;case"-le":return t<=n;case"-gt":return t>n;case"-ge":return t>=n}}function fr(e){return e==="="||e==="=="||e==="!="}function fs(e,t,n,r=!1,s=!1,i=!1,a=256){if(r){let l=Wn(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 Xp=new Set(["-z","-n"]);function ds(e){return Xp.has(e)}function ps(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function hs(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let r=n[1],s=n[2];if(e.state.associativeArrays?.has(r)){let 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,u)=>e.state.env.get(u)||""),qt(e,r,o)}let a;try{let o=new j,l=te(o,s);a=await X(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=be(e,r),l=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
120
125
  `,!1;if(a=Math.max(...o)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
121
- `,!1}return Tt(e,r,a)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?gt(e,t).length>0:be(e,t).length>0}async function jt(e,t){switch(t.type){case"CondBinary":{let n=await ne(e,t.left),r=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),s;if(t.operator==="=~")if(r){let i=await ne(e,t.right);s=Cn(i)}else s=await Ou(e,t.right);else sr(t.operator)&&!r?s=await _u(e,t.right):s=await ne(e,t.right);if(sr(t.operator)){let i=e.state.shoptOptions.nocasematch;return rs(t.operator,n,s,!r,i,!0,e.limits.maxCallDepth)}if(ts(t.operator))return ns(t.operator,await Gu(e,n),await Gu(e,s));if(Jr(t.operator))return es(e,t.operator,n,s);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=Gp(s),l=me(a,i?"i":"").match(n);if(ye(e,"BASH_REMATCH"),l)for(let u=0;u<l.length;u++)j(e,"BASH_REMATCH",u,l[u]||"");return l!==null}catch{throw new Error("syntax error in regular expression")}case"<":return n<s;case">":return n>s;default:return!1}}case"CondUnary":{let n=await ne(e,t.operand);return Xr(t.operator)?Yr(e,t.operator,n):ss(t.operator)?is(t.operator,n):t.operator==="-v"?await as(e,n):t.operator==="-o"?Mi(e,n):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await ne(e,t.operand.expression.word)})`!=="":!await jt(e,t.operand);case"CondAnd":return await jt(e,t.left)?await jt(e,t.right):!1;case"CondOr":return await jt(e,t.left)?!0:await jt(e,t.right);case"CondGroup":return await jt(e,t.expression);case"CondWord":return await ne(e,t.word)!=="";default:return!1}}async function ir(e,t){if(t.length===0)return L("","",1);if(t.length===1)return ge(!!t[0]);if(t.length===2){let r=t[0],s=t[1];return r==="("?I(`test: '(' without matching ')'
122
- `,2):Xr(r)?ge(await Yr(e,r,s)):ss(r)?ge(is(r,s)):r==="!"?ge(!s):r==="-v"?ge(await as(e,s)):r==="-o"?ge(Mi(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"?I(`test: ${r}: unary operator expected
123
- `,2):L("","",1)}if(t.length===3){let r=t[0],s=t[1],i=t[2];if(sr(s))return ge(rs(s,r,i));if(ts(s)){let a=os(r),o=os(i);return!a.valid||!o.valid?L("","",2):ge(ns(s,a.value,o.value))}if(Jr(s))return ge(await es(e,s,r,i));switch(s){case"-a":return ge(r!==""&&i!=="");case"-o":return ge(r!==""||i!=="");case">":return ge(r>i);case"<":return ge(r<i)}if(r==="!"){let a=await ir(e,[s,i]);return L("",a.stderr,a.exitCode===0?1:a.exitCode===1?0:a.exitCode)}if(r==="("&&i===")")return ge(s!=="")}if(t.length===4){if(t[0]==="!"){let r=await ir(e,t.slice(1));return L("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(t[0]==="("&&t[3]===")")return ir(e,[t[1],t[2]])}let n=await Hu(e,t,0);return n.pos<t.length?I(`test: too many arguments
124
- `,2):ge(n.value)}async function Hu(e,t,n){return zp(e,t,n)}async function zp(e,t,n){let{value:r,pos:s}=await ju(e,t,n);for(;t[s]==="-o";){let i=await ju(e,t,s+1);r=r||i.value,s=i.pos}return{value:r,pos:s}}async function ju(e,t,n){let{value:r,pos:s}=await Ti(e,t,n);for(;t[s]==="-a";){let i=await Ti(e,t,s+1);r=r&&i.value,s=i.pos}return{value:r,pos:s}}async function Ti(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 Ti(e,t,n+1);return{value:!s,pos:i}}return qp(e,t,n)}finally{r.release()}}async function qp(e,t,n){let r=t[n];if(r==="("){let{value:i,pos:a}=await Hu(e,t,n+1);return{value:i,pos:t[a]===")"?a+1:a}}let s=t[n+1];if(sr(s)){let i=r,a=t[n+2]??"";return{value:rs(s,i,a),pos:n+3}}if(ts(s)){let i=os(r),a=os(t[n+2]??"0");return!i.valid||!a.valid?{value:!1,pos:n+3}:{value:ns(s,i.value,a.value),pos:n+3}}if(Jr(s)){let i=r,a=t[n+2]??"";return{value:await es(e,s,i,a),pos:n+3}}if(Xr(r)){let i=t[n+1]??"";return{value:await Yr(e,r,i),pos:n+2}}if(ss(r)){let i=t[n+1]??"";return{value:is(r,i),pos:n+2}}if(r==="-v"){let i=t[n+1]??"";return{value:await as(e,i),pos:n+2}}if(r==="-o"){let i=t[n+1]??"";return{value:Mi(e,i),pos:n+2}}return{value:r!==void 0&&r!=="",pos:n+1}}function In(e,t,n=!1,r=!1,s=256){r&&Up(t,s);let i=`^${Qu(t,r)}$`;return me(i,n?"is":"s").test(e)}function Up(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 k(`extglob maximum depth (${t}) exceeded`,"recursion")}else e[s]===")"&&r.length>0&&r.pop()&&n--}}function Qu(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=Ku(e,r+1);if(i!==-1){let a=e.slice(r+2,i),o=Xu(a),l=o.map(c=>Qu(c,t)),u=l.length>0?l.join("|"):"(?:)";if(s==="@")n+=`(?:${u})`;else if(s==="*")n+=`(?:${u})*`;else if(s==="+")n+=`(?:${u})+`;else if(s==="?")n+=`(?:${u})?`;else if(s==="!")if(i<e.length-1){let f=o.map(p=>Yu(p,t));if(f.every(p=>p!==null)&&f.every(p=>p===f[0])&&f[0]!==null){let p=f[0];if(p===0)n+="(?:.+)";else{let h=[];p>0&&h.push(`.{0,${p-1}}`),h.push(`.{${p+1},}`),h.push(`(?!(?:${u})).{${p}}`),n+=`(?:${h.join("|")})`}}else n+=`(?:(?!(?:${u})).)*?`}else n+=`(?!(?:${u})$).*`;r=i;continue}}if(s==="\\")if(r+1<e.length){let i=e[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?n+=`\\${i}`:n+=i,r++}else n+="\\\\";else if(s==="*")n+=".*";else if(s==="?")n+=".";else if(s==="["){let i=e.indexOf("]",r+1);i!==-1?(n+=e.slice(r,i+1),r=i):n+="\\["}else/[\\^$.|+(){}]/.test(s)?n+=`\\${s}`:n+=s}return n}function Ku(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 Xu(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 Yu(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=Ku(e,r+1);if(i!==-1){if(s==="@"){let a=e.slice(r+2,i),l=Xu(a).map(u=>Yu(u,t));if(l.every(u=>u!==null)&&l.every(u=>u===l[0])){n+=l[0],r=i+1;continue}return null}return null}}if(s==="*")return null;if(s==="?"){n+=1,r++;continue}if(s==="["){let i=e.indexOf("]",r+1);if(i!==-1){n+=1,r=i+1;continue}n+=1,r++;continue}if(s==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}function Mi(e,t){let r=new Map([["errexit",()=>e.state.options.errexit===!0],["nounset",()=>e.state.options.nounset===!0],["pipefail",()=>e.state.options.pipefail===!0],["xtrace",()=>e.state.options.xtrace===!0],["e",()=>e.state.options.errexit===!0],["u",()=>e.state.options.nounset===!0],["x",()=>e.state.options.xtrace===!0]]).get(t);return r?r():!1}async function Gu(e,t){if(t=t.trim(),t==="")return 0;if(/^[+-]?(\d+#[a-zA-Z0-9@_]+|0[xX][0-9a-fA-F]+|0[0-7]+|\d+)$/.test(t))return Zu(t);try{let n=new G,r=te(n,t);return await K(e,r.expression)}catch{return Zu(t)}}function jp(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 Zu(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=jp(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 os(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 Gp(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=Zp(e,n);t+=r.converted,n=r.endIndex}else t+=e[n],n++;return t}function Zp(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 u=e.indexOf(":]",n+2);if(u!==-1){let c=e.slice(n+2,u);a+=Hp(c),n=u+2;continue}}if(l==="["&&n+1<e.length){let u=e[n+1];if(u==="."||u==="="){let c=`${u}]`,f=e.indexOf(c,n+2);if(f!==-1){let d=e.slice(n+2,f);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 Hp(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 Fi(e,t,n){if(n&&e.length>=n.maxElements)throw new k(`array element limit exceeded (${n.maxElements})`,"array_elements");e.push(t)}function Pt(e,t){if(t&&F(e)>t.maxStringBytes)throw new k(`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===`
125
- `)&&!s&&!i){o&&(Fi(n,r,t),r="",o=!1);continue}r+=l,o=!0}return o&&Fi(n,r,t),n}function ls(e,t){if(t&&F(e)>t.maxStringBytes)throw new k(`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++;Fi(n,[s,i],t)}return n}function Ju(e,t){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(n)return{name:n[1],isArray:!0,arrayElements:Pt(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 Qp(e,t){try{let n=new G,r=te(n,t);return await K(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}async function ec(e,t,n={}){let{name:r,isArray:s,arrayElements:i,value:a,arrayIndex:o}=t,{makeReadonly:l=!1,checkReadonly:u=!0}=n;if(u){let c=ue(e,r);if(c)return c}if(s&&i){e.executionScope.consumeWork(i.length,"array assignment");let c=ve(e,r),f=c?Le(c):void 0,d=e.state.env.get(r);try{ye(e,r);for(let p=0;p<i.length;p++)j(e,r,p,i[p]);e.state.env.delete(r)}catch(p){throw e.state.arrays??=new Map,f?e.state.arrays.set(r,f):e.state.arrays.delete(r),d===void 0?e.state.env.delete(r):e.state.env.set(r,d),p}}else if(o!==void 0&&a!==void 0){let c=await Qp(e,o);j(e,r,c,a)}else a!==void 0&&e.state.env.set(r,a);return l&&Ue(e,r),null}function Gt(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function Bi(e,t){return e.state.localVarDepth?.get(t)}function us(e,t){e.state.localVarDepth?.delete(t)}function tc(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 nc(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 Wi=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function rc(e){return Wi.has(e)}var Vi=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),On=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 zi="__file__:",qi="__file_append__:",Gi="__rw__:",Ui="__dupout__:",ji="__dupin__:",we=3;function Kp(e){let t=e.slice(Gi.length),n=t.indexOf(":");if(n===-1)return null;let r=Number.parseInt(t.slice(0,n),10);if(Number.isNaN(r)||r<0)return null;let s=n+1,i=t.slice(s,s+r),a=t.slice(s+r+1),o=a.indexOf(":");if(o===-1)return null;let l=Number.parseInt(a.slice(0,o),10);return Number.isNaN(l)||l<0?null:{path:i,position:l,content:a.slice(o+1)}}function sc(e,t){let n=Number.parseInt(e.slice(t.length),10);return Number.isNaN(n)?null:n}function Xp(e){if(e.startsWith(zi))return{kind:"output",path:e.slice(zi.length),append:!1};if(e.startsWith(qi))return{kind:"output",path:e.slice(qi.length),append:!0};if(e.startsWith(Gi)){let t=Kp(e);if(t)return{kind:"readwrite",...t}}if(e.startsWith(Ui)){let t=sc(e,Ui);if(t!==null)return{kind:"dup-out",sourceFd:t}}if(e.startsWith(ji)){let t=sc(e,ji);if(t!==null)return{kind:"dup-in",sourceFd:t}}return{kind:"input",content:e}}function Zi(e){switch(e.kind){case"input":return e.content;case"output":return`${e.append?qi:zi}${e.path}`;case"readwrite":return`${Gi}${e.path.length}:${e.path}:${e.position}:${e.content}`;case"dup-out":return`${Ui}${e.sourceFd}`;case"dup-in":return`${ji}${e.sourceFd}`;case"closed":throw new Error("Closed descriptors have no table encoding")}}function Yp(e){return e.state.fileDescriptors??=new Map,e.state.fileDescriptors}function Jp(e,t,n){n?(e.state.inputFds??=new Set,e.state.inputFds.add(t)):e.state.inputFds?.delete(t)}function _n(e,t){return e.state.fdAliases?.get(t)}function Zt(e,t){return[..._n(e,t)??[t]]}function ic(e,t){let n=_n(e,t);if(n&&(n.delete(t),e.state.fdAliases?.delete(t),n.size<2))for(let r of n)e.state.fdAliases?.delete(r)}function Hi(e,t,n){if(t===n)return;e.state.fdAliases??=new Map;let r=_n(e,n)??new Set([n]);r.add(t);for(let s of r)e.state.fdAliases.set(s,r)}function fs(e,t){return e.state.fileDescriptors?.get(t)}function Ye(e,t){let n=fs(e,t);if(n!==void 0)return e.state.inputFds?.has(t)?{kind:"input",content:n}:Xp(n)}function dn(e,t){return e.state.fileDescriptors?.has(t)===!0}function Qi(e,t,n,r){let s=Yp(e);s.has(t)||Uu(e),s.set(t,n),Jp(e,t,r)}function ds(e,t,n,r=!1){ic(e,t),Qi(e,t,n,r)}function st(e,t,n){ds(e,t,Zi(n),n.kind==="input")}function At(e,t){e.state.fileDescriptors?.delete(t),e.state.inputFds?.delete(t),ic(e,t)}function ps(e,t,n){let r=fs(e,n);return r===void 0?!1:(ds(e,t,r,e.state.inputFds?.has(n)===!0),Hi(e,t,n),!0)}function Ki(e,t,n){let r=fs(e,n);if(r===void 0)return!1;if(t===n)return!0;let s=e.state.inputFds?.has(n)===!0,i=[..._n(e,n)??[]].filter(o=>o!==n);At(e,n),ds(e,t,r,s);let a=i.find(o=>dn(e,o));return a!==void 0&&Hi(e,t,a),!0}function hs(e,t){let n=Ye(e,t);if(n===void 0)return{error:"not-open"};switch(n.kind){case"input":return{content:n.content};case"readwrite":return{content:n.content.slice(n.position)};case"output":case"dup-out":return{error:"write-only"};case"dup-in":return{error:"not-open"};case"closed":return{error:"not-open"}}}function Ht(e,t,n){let r=Ye(e,t);if(r===void 0)return;let s;if(r.kind==="input")s={kind:"input",content:r.content.slice(n)};else if(r.kind==="readwrite")s={...r,position:r.position+n};else return;let i=Zi(s),a=s.kind==="input";for(let o of _n(e,t)??[t])Qi(e,o,i,a)}async function Xi(e,t,n,r,s){if(t.kind==="output")return await e.fs.appendFile(t.path,r,s),!0;let a=n.map(c=>Ye(e,c)).find(c=>c?.kind==="readwrite")??t;if(a.kind!=="readwrite")return!1;let o=a.content.slice(0,a.position)+r+a.content.slice(a.position+r.length),l={...a,position:a.position+r.length,content:o};await e.fs.writeFile(a.path,o,s);let u=Zi(l);for(let c of n)dn(e,c)&&Qi(e,c,u,!1);return!0}function Qt(e,t,n){if(t.has(n))return;let r=_n(e,n);t.set(n,{raw:fs(e,n),isInput:e.state.inputFds?.has(n)===!0,aliases:r?[...r].filter(s=>s!==n):[]})}function ms(e,t){let n=e.state.fileDescriptors;if(n)for(let[r,{raw:s,isInput:i,aliases:a}]of t){if(s===void 0){At(e,r);continue}ds(e,r,s,i);let o=a.find(l=>n.has(l));o!==void 0&&Hi(e,r,o)}}function Yi(e){switch(e.operator){case"<":case"<>":case"<<":case"<<-":case"<<<":case"<&":return e.fd??0;case">":case">>":case">|":case">&":return e.fd??1;default:return null}}function ac(e){if(e.fdVariable)return!1;let t=Yi(e);return t!==null&&t>=we}async function eh(e,t,n,r){try{if(!await e.fs.exists(t))return null;if((await e.fs.stat(t)).isDirectory)return`bash: ${n}: Is a directory
126
+ `,!1}return qt(e,r,a)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?vt(e,t).length>0:be(e,t).length>0}async function en(e,t){switch(t.type){case"CondBinary":{let n=await ne(e,t.left),r=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),s;if(t.operator==="=~")if(r){let i=await ne(e,t.right);s=Tn(i)}else s=await Uu(e,t.right);else fr(t.operator)&&!r?s=await ju(e,t.right):s=await ne(e,t.right);if(fr(t.operator)){let i=e.state.shoptOptions.nocasematch;return fs(t.operator,n,s,!r,i,!0,e.limits.maxCallDepth)}if(us(t.operator))return cs(t.operator,await rc(e,n),await rc(e,s));if(os(t.operator))return ls(e,t.operator,n,s);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=nh(s),l=me(a,i?"i":"").match(n);if(ye(e,"BASH_REMATCH"),l)for(let u=0;u<l.length;u++)U(e,"BASH_REMATCH",u,l[u]||"");return l!==null}catch{throw new Error("syntax error in regular expression")}case"<":return n<s;case">":return n>s;default:return!1}}case"CondUnary":{let n=await ne(e,t.operand);return is(t.operator)?as(e,t.operator,n):ds(t.operator)?ps(t.operator,n):t.operator==="-v"?await hs(e,n):t.operator==="-o"?Gi(e,n):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await ne(e,t.operand.expression.word)})`!=="":!await en(e,t.operand);case"CondAnd":return await en(e,t.left)?await en(e,t.right):!1;case"CondOr":return await en(e,t.left)?!0:await en(e,t.right);case"CondGroup":return await en(e,t.expression);case"CondWord":return await ne(e,t.word)!=="";default:return!1}}async function dr(e,t){if(t.length===0)return L("","",1);if(t.length===1)return ge(!!t[0]);if(t.length===2){let r=t[0],s=t[1];return r==="("?_(`test: '(' without matching ')'
127
+ `,2):is(r)?ge(await as(e,r,s)):ds(r)?ge(ps(r,s)):r==="!"?ge(!s):r==="-v"?ge(await hs(e,s)):r==="-o"?ge(Gi(e,s)):r==="="||r==="=="||r==="!="||r==="<"||r===">"||r==="-eq"||r==="-ne"||r==="-lt"||r==="-le"||r==="-gt"||r==="-ge"||r==="-nt"||r==="-ot"||r==="-ef"?_(`test: ${r}: unary operator expected
128
+ `,2):L("","",1)}if(t.length===3){let r=t[0],s=t[1],i=t[2];if(fr(s))return ge(fs(s,r,i));if(us(s)){let a=ms(r),o=ms(i);return!a.valid||!o.valid?L("","",2):ge(cs(s,a.value,o.value))}if(os(s))return ge(await ls(e,s,r,i));switch(s){case"-a":return ge(r!==""&&i!=="");case"-o":return ge(r!==""||i!=="");case">":return ge(r>i);case"<":return ge(r<i)}if(r==="!"){let a=await dr(e,[s,i]);return L("",a.stderr,a.exitCode===0?1:a.exitCode===1?0:a.exitCode)}if(r==="("&&i===")")return ge(s!=="")}if(t.length===4){if(t[0]==="!"){let r=await dr(e,t.slice(1));return L("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(t[0]==="("&&t[3]===")")return dr(e,[t[1],t[2]])}let n=await ic(e,t,0);return n.pos<t.length?_(`test: too many arguments
129
+ `,2):ge(n.value)}async function ic(e,t,n){return Yp(e,t,n)}async function Yp(e,t,n){let{value:r,pos:s}=await nc(e,t,n);for(;t[s]==="-o";){let i=await nc(e,t,s+1);r=r||i.value,s=i.pos}return{value:r,pos:s}}async function nc(e,t,n){let{value:r,pos:s}=await ji(e,t,n);for(;t[s]==="-a";){let i=await ji(e,t,s+1);r=r&&i.value,s=i.pos}return{value:r,pos:s}}async function ji(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 ji(e,t,n+1);return{value:!s,pos:i}}return Jp(e,t,n)}finally{r.release()}}async function Jp(e,t,n){let r=t[n];if(r==="("){let{value:i,pos:a}=await ic(e,t,n+1);return{value:i,pos:t[a]===")"?a+1:a}}let s=t[n+1];if(fr(s)){let i=r,a=t[n+2]??"";return{value:fs(s,i,a),pos:n+3}}if(us(s)){let i=ms(r),a=ms(t[n+2]??"0");return!i.valid||!a.valid?{value:!1,pos:n+3}:{value:cs(s,i.value,a.value),pos:n+3}}if(os(s)){let i=r,a=t[n+2]??"";return{value:await ls(e,s,i,a),pos:n+3}}if(is(r)){let i=t[n+1]??"";return{value:await as(e,r,i),pos:n+2}}if(ds(r)){let i=t[n+1]??"";return{value:ps(r,i),pos:n+2}}if(r==="-v"){let i=t[n+1]??"";return{value:await hs(e,i),pos:n+2}}if(r==="-o"){let i=t[n+1]??"";return{value:Gi(e,i),pos:n+2}}return{value:r!==void 0&&r!=="",pos:n+1}}function Wn(e,t,n=!1,r=!1,s=256){r&&eh(t,s);let i=`^${ac(t,r)}$`;return me(i,n?"is":"s").test(e)}function eh(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 ac(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=oc(e,r+1);if(i!==-1){let a=e.slice(r+2,i),o=lc(a),l=o.map(c=>ac(c,t)),u=l.length>0?l.join("|"):"(?:)";if(s==="@")n+=`(?:${u})`;else if(s==="*")n+=`(?:${u})*`;else if(s==="+")n+=`(?:${u})+`;else if(s==="?")n+=`(?:${u})?`;else if(s==="!")if(i<e.length-1){let f=o.map(p=>uc(p,t));if(f.every(p=>p!==null)&&f.every(p=>p===f[0])&&f[0]!==null){let p=f[0];if(p===0)n+="(?:.+)";else{let h=[];p>0&&h.push(`.{0,${p-1}}`),h.push(`.{${p+1},}`),h.push(`(?!(?:${u})).{${p}}`),n+=`(?:${h.join("|")})`}}else n+=`(?:(?!(?:${u})).)*?`}else n+=`(?!(?:${u})$).*`;r=i;continue}}if(s==="\\")if(r+1<e.length){let i=e[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?n+=`\\${i}`:n+=i,r++}else n+="\\\\";else if(s==="*")n+=".*";else if(s==="?")n+=".";else if(s==="["){let i=e.indexOf("]",r+1);i!==-1?(n+=e.slice(r,i+1),r=i):n+="\\["}else/[\\^$.|+(){}]/.test(s)?n+=`\\${s}`:n+=s}return n}function oc(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 lc(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 uc(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=oc(e,r+1);if(i!==-1){if(s==="@"){let a=e.slice(r+2,i),l=lc(a).map(u=>uc(u,t));if(l.every(u=>u!==null)&&l.every(u=>u===l[0])){n+=l[0],r=i+1;continue}return null}return null}}if(s==="*")return null;if(s==="?"){n+=1,r++;continue}if(s==="["){let i=e.indexOf("]",r+1);if(i!==-1){n+=1,r=i+1;continue}n+=1,r++;continue}if(s==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}function Gi(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 rc(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 sc(t);try{let n=new j,r=te(n,t);return await X(e,r.expression)}catch{return sc(t)}}function th(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 sc(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=th(r[2],s):n=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?n=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?n=Number.parseInt(e,8):n=Number.parseInt(e,10);return Number.isNaN(n)&&(n=0),t?-n:n}function ms(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let n=Number.parseInt(e,10);return Number.isNaN(n)?{value:0,valid:!1}:{value:t?-n:n,valid:!0}}function nh(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=rh(e,n);t+=r.converted,n=r.endIndex}else t+=e[n],n++;return t}function rh(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 u=e.indexOf(":]",n+2);if(u!==-1){let c=e.slice(n+2,u);a+=sh(c),n=u+2;continue}}if(l==="["&&n+1<e.length){let u=e[n+1];if(u==="."||u==="="){let c=`${u}]`,f=e.indexOf(c,n+2);if(f!==-1){let d=e.slice(n+2,f);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 sh(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 Hi(e,t,n){if(n&&e.length>=n.maxElements)throw new P(`array element limit exceeded (${n.maxElements})`,"array_elements");e.push(t)}function _t(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===`
130
+ `)&&!s&&!i){o&&(Hi(n,r,t),r="",o=!1);continue}r+=l,o=!0}return o&&Hi(n,r,t),n}function ys(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++;Hi(n,[s,i],t)}return n}function cc(e,t){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(n)return{name:n[1],isArray:!0,arrayElements:_t(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 ih(e,t){try{let n=new j,r=te(n,t);return await X(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}async function fc(e,t,n={}){let{name:r,isArray:s,arrayElements:i,value:a,arrayIndex:o}=t,{makeReadonly:l=!1,checkReadonly:u=!0}=n;if(u){let c=ue(e,r);if(c)return c}if(s&&i){e.executionScope.consumeWork(i.length,"array assignment");let c=ve(e,r),f=c?Te(c):void 0,d=e.state.env.get(r);try{ye(e,r);for(let p=0;p<i.length;p++)U(e,r,p,i[p]);e.state.env.delete(r)}catch(p){throw e.state.arrays??=new Map,f?e.state.arrays.set(r,f):e.state.arrays.delete(r),d===void 0?e.state.env.delete(r):e.state.env.set(r,d),p}}else if(o!==void 0&&a!==void 0){let c=await ih(e,o);U(e,r,c,a)}else a!==void 0&&e.state.env.set(r,a);return l&&je(e,r),null}function tn(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function Zi(e,t){return e.state.localVarDepth?.get(t)}function gs(e,t){e.state.localVarDepth?.delete(t)}function dc(e,t,n){e.state.localVarStack=e.state.localVarStack||new Map;let r=e.state.localVarStack.get(t)||[];r.push({value:n,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,r)}function ws(e,t){let n=e.state.localVarStack?.get(t);if(!(!n||n.length===0))return n.pop()}function pc(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 Qi=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function hc(e){return Qi.has(e)}var Ki=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Vn=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);var Xi="__file__:",Yi="__file_append__:",ta="__rw__:",Ji="__dupout__:",ea="__dupin__:",we=3;function ah(e){let t=e.slice(ta.length),n=t.indexOf(":");if(n===-1)return null;let r=Number.parseInt(t.slice(0,n),10);if(Number.isNaN(r)||r<0)return null;let s=n+1,i=t.slice(s,s+r),a=t.slice(s+r+1),o=a.indexOf(":");if(o===-1)return null;let l=Number.parseInt(a.slice(0,o),10);return Number.isNaN(l)||l<0?null:{path:i,position:l,content:a.slice(o+1)}}function mc(e,t){let n=Number.parseInt(e.slice(t.length),10);return Number.isNaN(n)?null:n}function oh(e){if(e.startsWith(Xi))return{kind:"output",path:e.slice(Xi.length),append:!1};if(e.startsWith(Yi))return{kind:"output",path:e.slice(Yi.length),append:!0};if(e.startsWith(ta)){let t=ah(e);if(t)return{kind:"readwrite",...t}}if(e.startsWith(Ji)){let t=mc(e,Ji);if(t!==null)return{kind:"dup-out",sourceFd:t}}if(e.startsWith(ea)){let t=mc(e,ea);if(t!==null)return{kind:"dup-in",sourceFd:t}}return{kind:"input",content:e}}function na(e){switch(e.kind){case"input":return e.content;case"output":return`${e.append?Yi:Xi}${e.path}`;case"readwrite":return`${ta}${e.path.length}:${e.path}:${e.position}:${e.content}`;case"dup-out":return`${Ji}${e.sourceFd}`;case"dup-in":return`${ea}${e.sourceFd}`;case"closed":throw new Error("Closed descriptors have no table encoding")}}function lh(e){return e.state.fileDescriptors??=new Map,e.state.fileDescriptors}function uh(e,t,n){n?(e.state.inputFds??=new Set,e.state.inputFds.add(t)):e.state.inputFds?.delete(t)}function zn(e,t){return e.state.fdAliases?.get(t)}function nn(e,t){return[...zn(e,t)??[t]]}function yc(e,t){let n=zn(e,t);if(n&&(n.delete(t),e.state.fdAliases?.delete(t),n.size<2))for(let r of n)e.state.fdAliases?.delete(r)}function ra(e,t,n){if(t===n)return;e.state.fdAliases??=new Map;let r=zn(e,n)??new Set([n]);r.add(t);for(let s of r)e.state.fdAliases.set(s,r)}function Es(e,t){return e.state.fileDescriptors?.get(t)}function Je(e,t){let n=Es(e,t);if(n!==void 0)return e.state.inputFds?.has(t)?{kind:"input",content:n}:oh(n)}function Sn(e,t){return e.state.fileDescriptors?.has(t)===!0}function sa(e,t,n,r){let s=lh(e);s.has(t)||tc(e),s.set(t,n),uh(e,t,r)}function bs(e,t,n,r=!1){yc(e,t),sa(e,t,n,r)}function at(e,t,n){bs(e,t,na(n),n.kind==="input")}function Ct(e,t){e.state.fileDescriptors?.delete(t),e.state.inputFds?.delete(t),yc(e,t)}function Ss(e,t,n){let r=Es(e,n);return r===void 0?!1:(bs(e,t,r,e.state.inputFds?.has(n)===!0),ra(e,t,n),!0)}function ia(e,t,n){let r=Es(e,n);if(r===void 0)return!1;if(t===n)return!0;let s=e.state.inputFds?.has(n)===!0,i=[...zn(e,n)??[]].filter(o=>o!==n);Ct(e,n),bs(e,t,r,s);let a=i.find(o=>Sn(e,o));return a!==void 0&&ra(e,t,a),!0}function As(e,t){let n=Je(e,t);if(n===void 0)return{error:"not-open"};switch(n.kind){case"input":return{content:n.content};case"readwrite":return{content:n.content.slice(n.position)};case"output":case"dup-out":return{error:"write-only"};case"dup-in":return{error:"not-open"};case"closed":return{error:"not-open"}}}function rn(e,t,n){let r=Je(e,t);if(r===void 0)return;let s;if(r.kind==="input")s={kind:"input",content:r.content.slice(n)};else if(r.kind==="readwrite")s={...r,position:r.position+n};else return;let i=na(s),a=s.kind==="input";for(let o of zn(e,t)??[t])sa(e,o,i,a)}async function aa(e,t,n,r,s){if(t.kind==="output")return await e.fs.appendFile(t.path,r,s),!0;let a=n.map(c=>Je(e,c)).find(c=>c?.kind==="readwrite")??t;if(a.kind!=="readwrite")return!1;let o=a.content.slice(0,a.position)+r+a.content.slice(a.position+r.length),l={...a,position:a.position+r.length,content:o};await e.fs.writeFile(a.path,o,s);let u=na(l);for(let c of n)Sn(e,c)&&sa(e,c,u,!1);return!0}function sn(e,t,n){if(t.has(n))return;let r=zn(e,n);t.set(n,{raw:Es(e,n),isInput:e.state.inputFds?.has(n)===!0,aliases:r?[...r].filter(s=>s!==n):[]})}function vs(e,t){let n=e.state.fileDescriptors;if(n)for(let[r,{raw:s,isInput:i,aliases:a}]of t){if(s===void 0){Ct(e,r);continue}bs(e,r,s,i);let o=a.find(l=>n.has(l));o!==void 0&&ra(e,r,o)}}function oa(e){switch(e.operator){case"<":case"<>":case"<<":case"<<-":case"<<<":case"<&":return e.fd??0;case">":case">>":case">|":case">&":return e.fd??1;default:return null}}function gc(e){if(e.fdVariable)return!1;let t=oa(e);return t!==null&&t>=we}async function ch(e,t,n,r){try{if(!await e.fs.exists(t))return null;if((await e.fs.stat(t)).isDirectory)return`bash: ${n}: Is a directory
126
131
  `;if(r.checkNoclobber&&e.state.options.noclobber&&!r.isClobber&&n!=="/dev/null")return`bash: ${n}: cannot overwrite existing file
127
132
  `}catch{return`bash: ${n}: cannot open redirect target
128
- `}return null}function oc(e){let n=Math.min(e.length,8192);for(let r=0;r<n;r++)if(e.charCodeAt(r)>127)return"utf8";return"binary"}var ar="scoped",uc="bare",cc="persistent",th=e=>new k(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors"),nh=(e,t)=>dn(e,t)||(e.state.fileDescriptors?.size??0)<e.limits.maxFileDescriptors,lc=e=>{let t=Math.max(e.state.nextFd??10,10);for(;dn(e,t);)t+=1;return t},ys=e=>{let t=e.endsWith("-"),n=t?e.slice(0,-1):e;return/^\d+$/.test(n)?{sourceFd:Number.parseInt(n,10),move:t}:null},rh=(e,t,n)=>{let r=Ye(e,t);return t<we?r?{kind:"entry",entry:r,descriptors:Zt(e,t)}:{kind:"standard",fd:t}:r?n?r.kind==="input"||r.kind==="readwrite"||r.kind==="dup-in"?{kind:"entry",entry:r,descriptors:Zt(e,t)}:null:r.kind==="output"||r.kind==="readwrite"||r.kind==="dup-out"?{kind:"entry",entry:r,descriptors:Zt(e,t)}:null:null};async function Ln(e,t,n,r,s=!0){let i=e.fs.resolvePath(e.state.cwd,t),a=await eh(e,i,t,{checkNoclobber:!n,isClobber:r});if(a)return{error:L("",a,1)};if(t==="/dev/full")return{error:L("",`bash: /dev/full: No space left on device
133
+ `}return null}function wc(e){let n=Math.min(e.length,8192);for(let r=0;r<n;r++)if(e.charCodeAt(r)>127)return"utf8";return"binary"}var pr="scoped",bc="bare",Sc="persistent",fh=e=>new P(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors"),dh=(e,t)=>Sn(e,t)||(e.state.fileDescriptors?.size??0)<e.limits.maxFileDescriptors,Ec=e=>{let t=Math.max(e.state.nextFd??10,10);for(;Sn(e,t);)t+=1;return t},$s=e=>{let t=e.endsWith("-"),n=t?e.slice(0,-1):e;return/^\d+$/.test(n)?{sourceFd:Number.parseInt(n,10),move:t}:null},ph=(e,t,n)=>{let r=Je(e,t);return t<we?r?{kind:"entry",entry:r,descriptors:nn(e,t)}:{kind:"standard",fd:t}:r?n?r.kind==="input"||r.kind==="readwrite"||r.kind==="dup-in"?{kind:"entry",entry:r,descriptors:nn(e,t)}:null:r.kind==="output"||r.kind==="readwrite"||r.kind==="dup-out"?{kind:"entry",entry:r,descriptors:nn(e,t)}:null:null};async function qn(e,t,n,r,s=!0){let i=e.fs.resolvePath(e.state.cwd,t),a=await ch(e,i,t,{checkNoclobber:!n,isClobber:r});if(a)return{error:L("",a,1)};if(t==="/dev/full")return{error:L("",`bash: /dev/full: No space left on device
129
134
  `,1)};if(t==="/dev/stdout")return{entry:{kind:"dup-out",sourceFd:1}};if(t==="/dev/stderr")return{entry:{kind:"dup-out",sourceFd:2}};try{n?await e.fs.appendFile(i,"","binary"):await e.fs.writeFile(i,"","binary")}catch(o){if(!s)throw o;return{error:L("",`bash: ${t}: cannot open redirect target
130
- `,1)}}return{entry:{kind:"output",path:i,append:n}}}async function Ji(e,t,n){let r=e.fs.resolvePath(e.state.cwd,t);try{let s=await e.fs.readFile(r);return n?{entry:{kind:"readwrite",path:r,position:0,content:s}}:{entry:{kind:"input",content:s}}}catch{if(!n)return{error:L("",`bash: ${t}: No such file or directory
135
+ `,1)}}return{entry:{kind:"output",path:i,append:n}}}async function la(e,t,n){let r=e.fs.resolvePath(e.state.cwd,t);try{let s=await e.fs.readFile(r);return n?{entry:{kind:"readwrite",path:r,position:0,content:s}}:{entry:{kind:"input",content:s}}}catch{if(!n)return{error:L("",`bash: ${t}: No such file or directory
131
136
  `,1)};try{return await e.fs.writeFile(r,"","binary"),{entry:{kind:"readwrite",path:r,position:0,content:""}}}catch{return{error:L("",`bash: ${t}: No such file or directory
132
- `,1)}}}}var sh=async(e,t)=>{let n=await ne(e,t.content);return t.stripTabs?n.split(`
137
+ `,1)}}}}var hh=async(e,t)=>{let n=await ne(e,t.content);return t.stripTabs?n.split(`
133
138
  `).map(r=>r.replace(/^\t+/,"")).join(`
134
- `):n};async function ih(e,t,n,r){let s=new Map,i=new Map,a=(g,y)=>e.state.closedStandardFds?.has(g)?{kind:"closed"}:Ye(e,g)??y,o=new Map([[0,a(0,{kind:"dup-in",sourceFd:0})],[1,a(1,{kind:"dup-out",sourceFd:1})],[2,a(2,{kind:"dup-out",sourceFd:2})]]),l=r.numericSnapshot,u,c=-1,f=o.get(0);f?.kind==="input"?(u=f.content,c=0):f?.kind==="readwrite"&&(u=f.content.slice(f.position),c=0);let d=()=>({targets:s,dupSources:i,standardRoutes:o,stdin:u,stdinSourceFd:c,error:null}),p=async(g,y,S)=>{let v={...d(),error:await Kt(e,g,t.slice(0,y),s,i,o)};return S?{...v,errorCause:S}:v},h=async(g,y)=>{if(nh(e,g))return null;let S=th(e);return p(L("",S.stderr,k.EXIT_CODE),y,S)},m=(g,y)=>{g!==null&&g<we&&o.set(g,y),r.policy==="persistent"&&g!==null&&g<we&&(e.state.closedStandardFds?.delete(g),st(e,g,y))},E=(g,y)=>{o.set(g,y),Qt(e,r.standardSnapshot,g),r.standardClosedSnapshot.has(g)||r.standardClosedSnapshot.set(g,e.state.closedStandardFds?.has(g)===!0),e.state.closedStandardFds?.delete(g),st(e,g,y)},b=(g,y)=>{if(g<we){let S=o.get(g);return S?.kind==="closed"?null:S?{kind:"entry",entry:S,descriptors:Zt(e,g)}:{kind:"standard",fd:g}}return rh(e,g,y)};for(let g=0;g<t.length;g++){let y=t[g],S=Yi(y);if(y.target.type==="HereDoc"){let A=await sh(e,y.target);if(y.fdVariable){try{ue(e,y.fdVariable)}catch(x){if(!(x instanceof U))throw x;return p(L(x.stdout,x.stderr,x.exitCode),g,x)}let C=lc(e),N=await h(C,g);if(N)return N;Qt(e,r.fdVariableSnapshot,C),r.fdVariableEnv.has(y.fdVariable)||r.fdVariableEnv.set(y.fdVariable,e.state.env.get(y.fdVariable)),st(e,C,{kind:"input",content:A}),e.state.env.set(y.fdVariable,String(C)),e.state.nextFd=C+1}else if(S!==null&&S>=we){let C=await h(S,g);if(C)return C;Qt(e,l,S),st(e,S,{kind:"input",content:A})}else if(S===0||S===null)u=tn(A),c=-1,m(S,{kind:"input",content:u});else{let C={kind:"input",content:A};r.policy==="persistent"?m(S,C):E(S,C)}continue}let v,$=y.operator===">&"||y.operator==="<&";if($){if(Ri(e,y.target))return p(L("",`bash: $@: ambiguous redirect
135
- `,1),g);v=await ne(e,y.target)}else if(y.operator==="<<<")v=await ne(e,y.target);else{let A=await Fu(e,y.target);if("error"in A)return p(L("",A.error,1),g);v=A.target}if(s.set(g,v),v.includes("\0"))return p(L("",`bash: ${v.replace(/\0/g,"")}: No such file or directory
136
- `,1),g);if(y.fdVariable){try{ue(e,y.fdVariable)}catch(R){if(!(R instanceof U))throw R;return p(L(R.stdout,R.stderr,R.exitCode),g,R)}if($&&v==="-"){let R=Number.parseInt(e.state.env.get(y.fdVariable)??"",10);Number.isNaN(R)||(Qt(e,r.fdVariableSnapshot,R),At(e,R));continue}let A=lc(e),C=$?ys(v):null;if(C&&!b(C.sourceFd,y.operator==="<&"))return p(L("",`bash: ${C.sourceFd}: Bad file descriptor
137
- `,1),g);if(!(C?.move===!0&&C.sourceFd>=we)){let R=await h(A,g);if(R)return R}Qt(e,r.fdVariableSnapshot,A),r.fdVariableEnv.has(y.fdVariable)||r.fdVariableEnv.set(y.fdVariable,e.state.env.get(y.fdVariable));let x,P;if($){let R=C;if(R){let B=b(R.sourceFd,y.operator==="<&");if(!B)return p(L("",`bash: ${R.sourceFd}: Bad file descriptor
138
- `,1),g);P=R,B.kind==="standard"?x={kind:y.operator==="<&"?"dup-in":"dup-out",sourceFd:B.fd}:R.sourceFd<we&&(x=B.entry)}else{if(y.operator==="<&")return p(L("",`bash: ${v}: ambiguous redirect
139
- `,1),g);let B=await Ln(e,v,!1,!1);if(B.error)return p(B.error,g);x=B.entry}}else if(y.operator===">"||y.operator===">|"||y.operator===">>"||y.operator==="&>"||y.operator==="&>>"){let R=y.operator===">>"||y.operator==="&>>",B=await Ln(e,v,R,y.operator===">|");if(B.error)return p(B.error,g);x=B.entry}else if(y.operator==="<<<")x={kind:"input",content:`${v}
140
- `};else if(y.operator==="<"||y.operator==="<>"){let R=await Ji(e,v,y.operator==="<>");if(R.error)return p(R.error,g);x=R.entry}if(P&&P.sourceFd>=we){if(!(P.move?Ki(e,A,P.sourceFd):ps(e,A,P.sourceFd)))return p(L("",`bash: ${P.sourceFd}: Bad file descriptor
141
- `,1),g)}else x&&st(e,A,x);P?.move&&P.sourceFd!==A&&P.sourceFd<we&&At(e,P.sourceFd),e.state.env.set(y.fdVariable,String(A)),e.state.nextFd=A+1;continue}if(ac(y)){let A=S;if($&&v==="-"){Qt(e,l,A),At(e,A);continue}let C=$?ys(v):null;if(C&&!b(C.sourceFd,y.operator==="<&"))return p(L("",`bash: ${C.sourceFd}: Bad file descriptor
142
- `,1),g);if(!(C?.move===!0&&C.sourceFd>=we)){let x=await h(A,g);if(x)return x}if(Qt(e,l,A),$){let x=C;if(!x){if(y.operator==="<&")return p(L("",`bash: ${v}: ambiguous redirect
143
- `,1),g);let R=await Ln(e,v,!1,!1);if(R.error)return p(R.error,g);st(e,A,R.entry);continue}let P=b(x.sourceFd,y.operator==="<&");if(!P)return p(L("",`bash: ${x.sourceFd}: Bad file descriptor
144
- `,1),g);if(P.kind==="standard")st(e,A,{kind:y.operator==="<&"?"dup-in":"dup-out",sourceFd:P.fd});else if(x.sourceFd<we)st(e,A,P.entry);else if(!(x.move?Ki(e,A,x.sourceFd):ps(e,A,x.sourceFd)))return p(L("",`bash: ${x.sourceFd}: Bad file descriptor
145
- `,1),g);x.move&&x.sourceFd!==A&&x.sourceFd<we&&At(e,x.sourceFd);continue}if(y.operator===">"||y.operator===">|"||y.operator===">>"){let x=await Ln(e,v,y.operator===">>",y.operator===">|");if(x.error)return p(x.error,g);st(e,A,x.entry)}else if(y.operator==="<<<")st(e,A,{kind:"input",content:`${v}
146
- `});else if(y.operator==="<"||y.operator==="<>"){let x=await Ji(e,v,y.operator==="<>");if(x.error)return p(x.error,g);st(e,A,x.entry)}continue}if($){if(v==="-"){S===0&&(u="",c=-1),S!==null&&S<we&&(o.set(S,{kind:"closed"}),r.policy==="persistent"&&(At(e,S),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(S)));continue}let A=ys(v);if(!A){if(y.operator==="<&")return p(L("",`bash: ${v}: ambiguous redirect
147
- `,1),g);let N=await Ln(e,v,!1,!1,!1);if(N.error)return p(N.error,g);let x=N.entry;i.set(g,{kind:"entry",entry:x,descriptors:[]}),y.fd==null?(m(1,x),m(2,x)):m(S,x);continue}let C=b(A.sourceFd,y.operator==="<&");if(!C)return p(L("",`bash: ${A.sourceFd}: Bad file descriptor
148
- `,1),g);if(i.set(g,C),C.kind==="entry"&&r.policy==="persistent"&&S!==null&&S<we&&A.sourceFd>=we){if(!ps(e,S,A.sourceFd))return p(L("",`bash: ${A.sourceFd}: Bad file descriptor
149
- `,1),g);o.set(S,Ye(e,S)),e.state.closedStandardFds?.delete(S)}else C.kind==="standard"?m(S,{kind:y.operator==="<&"?"dup-in":"dup-out",sourceFd:C.fd}):m(S,C.entry);if(y.operator==="<&"&&S===0)if(C.kind==="standard")u=C.fd===0?n:"",c=-1;else if(C.entry.kind==="input"||C.entry.kind==="readwrite"){let N=A.sourceFd<we&&!dn(e,A.sourceFd)?{content:C.entry.kind==="input"?C.entry.content:C.entry.content.slice(C.entry.position)}:hs(e,A.sourceFd);if("error"in N)return p(L("",`bash: ${A.sourceFd}: Bad file descriptor
150
- `,1),g);u=N.content,c=dn(e,A.sourceFd)?A.sourceFd:-1}else u=n,c=-1;A.move&&(A.sourceFd>=we?At(e,A.sourceFd):(o.set(A.sourceFd,{kind:"closed"}),r.policy==="persistent"&&(At(e,A.sourceFd),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(A.sourceFd))));continue}if(y.operator===">"||y.operator===">|"||y.operator===">>"||y.operator==="&>"||y.operator==="&>>"){let A=await Ln(e,v,y.operator===">>"||y.operator==="&>>",y.operator===">|",!1);if(A.error)return p(A.error,g);let C=A.entry;y.operator==="&>"||y.operator==="&>>"?(m(1,C),m(2,C)):m(S,C);continue}if(y.operator==="<<<")u=tn(`${v}
151
- `),c=-1,m(S,{kind:"input",content:u});else if(y.operator==="<"){let A=e.fs.resolvePath(e.state.cwd,v);try{u=await mn(e.fs,A),c=-1,m(S,{kind:"input",content:u})}catch{return p(L("",`bash: ${v}: No such file or directory
152
- `,1),g)}}else if(y.operator==="<>"){let A=await Ji(e,v,!0);if(A.error)return p(A.error,g);let C=A.entry;m(S,C),S===0&&C.kind==="readwrite"&&(u=C.content,c=-1)}}return d()}function Tn(e,t,n){let r={numericSnapshot:new Map,fdVariableSnapshot:new Map,standardSnapshot:new Map,standardClosedSnapshot:new Map,fdVariableEnv:new Map,nextFd:e.state.nextFd,policy:n},s=!1;return{prepare:(i="")=>ih(e,t,i,r),finish:()=>{if(!s){if(s=!0,n!=="persistent"&&ms(e,r.numericSnapshot),n!=="persistent"){ms(e,r.standardSnapshot);for(let[i,a]of r.standardClosedSnapshot)a?(e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(i)):e.state.closedStandardFds?.delete(i)}if(n==="bare"){ms(e,r.fdVariableSnapshot);for(let[i,a]of r.fdVariableEnv)a===void 0?e.state.env.delete(i):e.state.env.set(i,a);e.state.nextFd=r.nextFd}}}}}function Mn(e){if(!e.error)throw new Error("Expected a redirection error");if(e.errorCause)throw e.errorCause.stdout=e.error.stdout,e.errorCause.stderr=e.error.stderr,e.errorCause;return e.error}async function ea(e,t,n,r){let s=t instanceof U||t instanceof Ie||t instanceof Fe?t.exitCode:t instanceof k?k.EXIT_CODE:0,i=await Kt(e,L(t.stdout,t.stderr,s),n,r.targets,r.dupSources,r.standardRoutes);t.stdout=i.stdout,t.stderr=i.stderr,t.internalOutputAccounting=i.internalOutputAccounting??{stdout:F(i.stdout),stderr:F(i.stderr)}}async function Je(e,t,n,r){let s=Tn(e,t,ar),i;try{if(i=await s.prepare(n),i.error)return Mn(i);let a=e.state.groupStdin,o=e.state.groupStdinSourceFd;i.stdin!==void 0&&(e.state.groupStdin=i.stdin,e.state.groupStdinSourceFd=i.stdinSourceFd);try{let l=await r(i);return await Kt(e,l,t,i.targets,i.dupSources,i.standardRoutes)}finally{i.stdin!==void 0&&(e.state.groupStdin=a,e.state.groupStdinSourceFd=o)}}catch(a){throw!(a instanceof yn)||!i||await ea(e,a,t,i),a}finally{s.finish()}}async function Kt(e,t,n,r,s=new Map,i=new Map,a="bash",o=!1){n.length>0&&(t=e.executionScope.accountResult(t,"redirection"));let{stdout:l,stderr:u,exitCode:c}=t,d=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",p=S=>d,h={kind:"live-stdout"},m={kind:"live-stderr"},E=S=>{if(!S)return null;if(S.kind==="entry"){if(S.entry.kind==="dup-out"){if(S.entry.sourceFd===1)return{kind:"live-stdout"};if(S.entry.sourceFd===2)return{kind:"live-stderr"}}return S.entry.kind==="output"||S.entry.kind==="readwrite"?{kind:"descriptor",source:S}:null}return S.fd===1?h:S.fd===2?m:null},b=S=>{let v=i.get(S)??Ye(e,S);return v?v.kind==="closed"?{kind:"invalid-output",fd:S}:v.kind==="input"||v.kind==="dup-in"?{kind:"invalid-output",fd:S}:v.kind==="dup-out"?v.sourceFd===1?{kind:"live-stdout"}:v.sourceFd===2?{kind:"live-stderr"}:null:v.kind==="output"||v.kind==="readwrite"?{kind:"descriptor",source:{kind:"entry",entry:v,descriptors:Zt(e,S)}}:null:null};h=b(1)??h,m=b(2)??m;for(let S=0;S<n.length;S++){let v=n[S];if(v.target.type==="HereDoc"||v.fdVariable)continue;let $=r.get(S);if($!==void 0)switch(v.operator){case">":case">|":case">>":{let A=v.fd??1;if(A!==1&&A!==2)break;let C=v.operator===">>";if($==="/dev/stdout"){A===2&&(m=h);break}if($==="/dev/stderr"){A===1&&(h=m);break}if($==="/dev/full"){u+=`bash: echo: write error: No space left on device
153
- `,c=1,A===1&&(l="");break}if($==="/dev/null"&&A===2){m={kind:"discard"};break}let N=e.fs.resolvePath(e.state.cwd,$);A===1?h={kind:"file",path:N,append:C}:m={kind:"file",path:N,append:C};break}case">&":case"<&":{let A=v.fd??(v.operator==="<&"?0:1);if(A>=we||A===0)break;if($==="-"){A===1?h={kind:"discard"}:m={kind:"discard"};break}let C=E(s.get(S));if(!C)break;v.fd==null&&ys($)===null?(h=C,m=C):A===1?h=C:A===2&&(m=C);break}case"&>":{h={kind:"file",path:e.fs.resolvePath(e.state.cwd,$),append:!1},m=h;break}case"&>>":{h={kind:"file",path:e.fs.resolvePath(e.state.cwd,$),append:!0},m=h;break}}}if(l!==""||u!==""){let S=l,v=u;l="",u="",h.kind==="invalid-output"&&S!==""&&(S="",v+=`${o?"":"bash: "}${a}: write error: Bad file descriptor
154
- `,c=1),m.kind==="invalid-output"&&(v="");let $=async(A,C,N)=>{A.append?await e.fs.appendFile(A.path,C,N):await e.fs.writeFile(A.path,C,N)};if(h===m&&(h.kind==="file"||h.kind==="descriptor")){let A=S+v;A!==""&&(h.kind==="file"?await $(h,A,p(A)):await Xi(e,h.source.entry,h.source.descriptors,A,p(A)))}else for(let[A,C,N]of[[S,h,!0],[v,m,!1]])if(A!=="")switch(C.kind){case"live-stdout":l+=A;break;case"live-stderr":u+=A;break;case"file":await $(C,A,N?p(A):oc(A));break;case"descriptor":await Xi(e,C.source.entry,C.source.descriptors,A,N?p(A):oc(A));break;case"invalid-output":break;case"discard":break}}let g=L(l,u,c);if(t.stdoutKind&&(g.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(g.stdoutEncoding="binary"),t.internalPipeStatusOverride&&(g.internalPipeStatusOverride=t.internalPipeStatusOverride),n.length>0||e.state.fileDescriptors?.has(1)===!0||e.state.fileDescriptors?.has(2)===!0){let S=(t.internalOutputAccounting?.stdout??0)+(t.internalOutputAccounting?.stderr??0),v=F(g.stdout),$=F(g.stderr),A=Math.min(v,S);g.internalOutputAccounting={stdout:A,stderr:Math.min($,S-A)},e.executionScope.accountResult(g,"redirection")}else t.internalOutputAccounting&&(g.internalOutputAccounting=t.internalOutputAccounting);return g}function fc(e,t){if(e.state.options.posix&&Wi.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
155
- `;throw new U(2,"",r)}let n={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,n),ee}async function gs(e,t,n,r="",s,i=!1){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,Ut(`${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 a=new Map,o=Number.parseInt(e.state.env.get("#")??"0",10),l=Math.max(n.length,o);for(let p=0;p<l;p++){let h=String(p+1);a.set(h,e.state.env.get(h)),p<n.length?e.state.env.set(h,n[p]):e.state.env.delete(h)}a.set("@",e.state.env.get("@")),a.set("#",e.state.env.get("#")),e.state.env.set("@",n.join(" ")),e.state.env.set("#",String(n.length));let u=!1,c=()=>{if(u)return;u=!0;let p=e.state.localScopes.length-1,h=e.state.localScopes.pop(),m=e.state.localArrayScopes?.pop();if(h)for(let[E,b]of h)b===void 0?e.state.env.delete(E):e.state.env.set(E,b);if(m){e.state.arrays??=new Map;for(let[E,b]of m)b===void 0?(e.state.arrays.delete(E),e.state.associativeArrays?.delete(E)):(e.state.arrays.set(E,Le(b)),e.state.associativeArrays??=new Set,b.kind==="associative"?e.state.associativeArrays.add(E):e.state.associativeArrays.delete(E))}if(nc(e,p),e.state.fullyUnsetLocals)for(let[E,b]of e.state.fullyUnsetLocals.entries())b===p&&e.state.fullyUnsetLocals.delete(E);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let E=e.state.localExportedVars.pop();if(E)for(let b of E)e.state.exportedVars?.delete(b)}for(let[E,b]of a)b===void 0?e.state.env.delete(E):e.state.env.set(E,b);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},f=null,d=Tn(e,t.redirections,ar);try{if(f=await d.prepare(r),f.error)return Mn(f);let p=f.stdin??r,h=i||f.stdin!==void 0||r!=="",m=await e.executeCommand(t.body,p,h);return Kt(e,m,t.redirections,f.targets,f.dupSources,f.standardRoutes)}catch(p){if(p instanceof yn&&f&&(await ea(e,p,t.redirections,f),p instanceof Ie))return L(p.stdout,p.stderr,p.exitCode);throw p}finally{d.finish(),c()}}var pc=e=>e.type==="Escaped"?T.literal(`\\${e.value}`):e.type==="DoubleQuoted"?{...e,parts:e.parts.map(pc)}:e,hc=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],ra=[".",":","[","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"],ah=["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"],oh=ra;async function sa(e,t){let n=[],r=null,s="",i="",a=null,o=!1,l=!1,u=!1,c=null,f=null,d=null,p=[],h=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let $=0;$<t.length;$++){let A=t[$];if(A==="-v")n.push("variable");else if(A==="-e")n.push("export");else if(A==="-f")n.push("file");else if(A==="-d")n.push("directory");else if(A==="-k")n.push("keyword");else if(A==="-A"){if($++,$>=t.length)return I(`compgen: -A: option requires an argument
156
- `,2);let C=t[$];if(!h.includes(C))return I(`compgen: ${C}: invalid action name
157
- `,2);n.push(C)}else if(A==="-W"){if($++,$>=t.length)return I(`compgen: -W: option requires an argument
158
- `,2);r=t[$]}else if(A==="-P"){if($++,$>=t.length)return I(`compgen: -P: option requires an argument
159
- `,2);s=t[$]}else if(A==="-S"){if($++,$>=t.length)return I(`compgen: -S: option requires an argument
160
- `,2);i=t[$]}else if(A==="-o"){if($++,$>=t.length)return I(`compgen: -o: option requires an argument
161
- `,2);let C=t[$];if(C==="plusdirs")o=!0;else if(C==="dirnames")l=!0;else if(C==="default")u=!0;else if(!(C==="filenames"||C==="nospace"||C==="bashdefault"||C==="noquote"))return I(`compgen: ${C}: invalid option name
162
- `,2)}else if(A==="-F"){if($++,$>=t.length)return I(`compgen: -F: option requires an argument
163
- `,2);f=t[$]}else if(A==="-C"){if($++,$>=t.length)return I(`compgen: -C: option requires an argument
164
- `,2);d=t[$]}else if(A==="-X"){if($++,$>=t.length)return I(`compgen: -X: option requires an argument
165
- `,2);c=t[$]}else if(A==="-G"){if($++,$>=t.length)return I(`compgen: -G: option requires an argument
166
- `,2)}else if(A==="--"){p.push(...t.slice($+1));break}else A.startsWith("-")||p.push(A)}a=p[0]??null;let m=[],E=new Set,b=()=>e.limits.maxArrayElements-m.length,g=$=>{for(let A of $){if(m.length>=e.limits.maxArrayElements)throw new k(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(F(A)>e.limits.maxStringLength)throw new k(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");e.executionScope.consumeWork(1,"compgen completion"),m.push(A),E.add(A)}};if(l){let $=await ta(e,a,b());g($)}if(u){let $=await dc(e,a,b());g($)}for(let $ of n)if($==="variable"){let A=lh(e,a,b());g(A)}else if($==="export"){let A=uh(e,a,b());g(A)}else if($==="function"){let A=ch(e,a,b());g(A)}else if($==="builtin"){let A=fh(e,a,b());g(A)}else if($==="keyword"){let A=dh(e,a,b());g(A)}else if($==="alias"){let A=ph(e,a,b());g(A)}else if($==="shopt"){let A=hh(e,a,b());g(A)}else if($==="helptopic"){let A=mh(e,a,b());g(A)}else if($==="directory"){let A=await ta(e,a,b());g(A)}else if($==="file"){let A=await dc(e,a,b());g(A)}else if($==="user"){let A=yh(e,a,b());g(A)}else if($==="command"){let A=await gh(e,a,b());g(A)}if(r!==null)try{let $=await wh(e,r),A=Eh(e,$,b(),a);for(let C of A)g([C])}catch($){if($ instanceof k)throw $;return L("","",1)}if(o){let $=await ta(e,a,b(),E);for(let A of $)E.has(A)||g([A])}let y="";if(f!==null){let $=e.state.functions.get(f);if($){let A=new Map,C=ve(e,"COMP_WORDS"),N=C?Le(C):void 0;ye(e,"COMP_WORDS"),Gn(e,"COMP_WORDS"),A.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),A.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),A.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let x=ve(e,"COMPREPLY"),P=x?Le(x):void 0,R=e.state.env.get("COMPREPLY");ye(e,"COMPREPLY"),e.state.env.delete("COMPREPLY");let B=["compgen",p[0]??"",""];try{let q=await gs(e,$,B,"");if(q.exitCode!==0)return na(e,A),Fn(e,"COMP_WORDS",N),Fn(e,"COMPREPLY",P),R!==void 0&&e.state.env.set("COMPREPLY",R),L("",q.stderr,1);y=q.stdout;let D=bh(e,b());g(D)}catch(q){if(q instanceof k)throw q;return na(e,A),Fn(e,"COMP_WORDS",N),Fn(e,"COMPREPLY",P),R!==void 0&&e.state.env.set("COMPREPLY",R),L("","",1)}na(e,A),Fn(e,"COMP_WORDS",N),Fn(e,"COMPREPLY",P),R!==void 0&&e.state.env.set("COMPREPLY",R)}}if(d!==null)try{let $=lt(d),A=await e.executeScript($);if(A.exitCode!==0)return L("",A.stderr,A.exitCode);if(A.stdout)for(let C of Sh(A.stdout))C.length>0&&g([C])}catch($){if($.name==="ParseException")return I(`compgen: -C: ${$.message}
167
- `,2);throw $}let S=m;if(c!==null){let $=c.startsWith("!"),A=$?c.slice(1):c;S=m.filter(C=>{let N=In(C,A,!1,!0,e.limits.maxCallDepth);return $?N:!N})}if(S.length===0&&a!==null)return L(y,"",1);let v=new gn(e.limits.maxOutputSize,"compgen");v.append(y);for(let $ of S)v.append(s).append($).append(i).append(`
168
- `);return Y(v.build())}function lh(e,t,n){let r=it(e,t,n);for(let s of e.state.env.keys())/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&r.add(s);for(let s of e.state.arrays?.keys()??[])r.add(s);return r.build()}function uh(e,t,n){let r=it(e,t,n),s=e.state.exportedVars??new Set;for(let i of s)e.state.env.has(i)&&r.add(i);return r.build()}function ch(e,t,n){let r=it(e,t,n);for(let s of e.state.functions.keys())r.add(s);return r.build()}function fh(e,t,n){let r=it(e,t,n);for(let s of ra)r.add(s);return r.build()}function dh(e,t,n){let r=it(e,t,n);for(let s of hc)r.add(s);return r.build()}function ph(e,t,n){let r=it(e,t,n);for(let s of e.state.env.keys())if(s.startsWith("BASH_ALIAS_")){let i=s.slice(11);r.add(i)}return r.build()}function hh(e,t,n){let r=it(e,t,n);for(let s of ah)r.add(s);return r.build()}function mh(e,t,n){let r=it(e,t,n);for(let s of oh)r.add(s);return r.build()}async function ta(e,t,n=e.limits.maxArrayElements,r){let s=it(e,null,n,r);try{let i=e.state.cwd,a=t??"";if(t){let l=t.lastIndexOf("/");if(l!==-1){let u=t.slice(0,l)||"/";a=t.slice(l+1),u.startsWith("/")?i=u:i=`${e.state.cwd}/${u}`}}let o=await e.fs.readdir(i);for(let l of o){e.executionScope.consumeWork(1,"compgen directory scan");let u=`${i}/${l}`;try{if((await e.fs.stat(u)).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(c){if(c instanceof k)throw c}}}catch(i){if(i instanceof k)throw i}return s.build()}async function dc(e,t,n=e.limits.maxArrayElements){let r=it(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("/"),u=t.slice(0,l+1);r.add(u+o)}else r.add(o)}catch(s){if(s instanceof k)throw s}return r.build()}function yh(e,t,n){let r=it(e,t,n);return r.add("root"),r.add("nobody"),r.build()}async function gh(e,t,n){let r=it(e,t,n);for(let i of ra)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 hc)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 k)throw a}return r.build()}function it(e,t,n,r){let s=new Set;return{add(i){if(e.executionScope.consumeWork(1,"compgen candidate collection"),!(t!==null&&!i.startsWith(t))&&!r?.has(i)&&!s.has(i)){if(s.size>=n)throw new k(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(F(i)>e.limits.maxStringLength)throw new k(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");s.add(i)}},build(){return Array.from(s).sort()}}}async function wh(e,t){let r=new G().parseWordFromString(t,!1,!1);return await ne(e,T.word(r.parts.map(pc)))}function Eh(e,t,n,r){let s=e.state.env.get("IFS")??`
169
- `;if(s.length===0){if(r!==null&&!t.startsWith(r))return[];if(n===0)throw new k(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");return[t]}let i=new Set(s.split("")),a=[],o=c=>{if(!(r!==null&&!c.startsWith(r))){if(a.length>=n)throw new k(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");a.push(c)}},l="",u=0;for(;u<t.length;){let c=t[u];if(c==="\\"&&u+1<t.length){let f=t[u+1];l+=f,u+=2}else i.has(c)?(l.length>0&&(o(l),l=""),u++):(l+=c,u++)}return l.length>0&&o(l),a}function na(e,t){for(let[n,r]of t)r===void 0?e.state.env.delete(n):e.state.env.set(n,r)}function Fn(e,t,n){e.state.arrays??=new Map,n?e.state.arrays.set(t,Le(n)):e.state.arrays.delete(t)}function bh(e,t){let n=[],r=s=>{if(n.length>=t)throw new k(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");n.push(s)};if(Pe(e,"COMPREPLY")){let s=Z(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*Sh(e){let t=0;for(;t<=e.length;){let n=e.indexOf(`
170
- `,t),r=n===-1?e.length:n;if(r>t&&(yield e.slice(t,r)),n===-1)return;t=n+1}}function or(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n===127)return!0}return!1}function ia(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 mc(e){if(or(e))return yc(e);if(e==="")return 2;if(/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e))return F(e);let t=F(e)+2;for(let n of e)n==="'"&&(t+=3);return t}function Ee(e){return or(e)?ia(e):e===""?"''":/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function ws(e){if(or(e))return yc(e);let t=F(e)+2;for(let n of e)(n==="\\"||n==='"'||n==="$"||n==="`")&&t++;return t}function Xt(e){return or(e)?ia(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}function yc(e){let t=3;for(let n of e){let r=n.codePointAt(0)??0;r===7||r===8||r===9||r===10||r===11||r===12||r===13||r===27||r===39||r===92?t+=2:r<32||r===127?t+=4:t+=F(n)}return t}function lr(e){return or(e)?ia(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}var Ah=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function oa(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=!1,i,a,o,l=[],u=[],c=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-p")n=!0;else if(d==="-r")r=!0;else if(d==="-D")s=!0;else if(d==="-W"){if(f++,f>=t.length)return I(`complete: -W: option requires an argument
171
- `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return I(`complete: -F: option requires an argument
172
- `,2);a=t[f]}else if(d==="-o"){if(f++,f>=t.length)return I(`complete: -o: option requires an argument
173
- `,2);let p=t[f];if(!Ah.includes(p))return I(`complete: ${p}: invalid option name
174
- `,2);l.push(p)}else if(d==="-A"){if(f++,f>=t.length)return I(`complete: -A: option requires an argument
175
- `,2);u.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return I(`complete: -C: option requires an argument
176
- `,2);o=t[f]}else if(d==="-G"){if(f++,f>=t.length)return I(`complete: -G: option requires an argument
177
- `,2)}else if(d==="-P"){if(f++,f>=t.length)return I(`complete: -P: option requires an argument
178
- `,2)}else if(d==="-S"){if(f++,f>=t.length)return I(`complete: -S: option requires an argument
179
- `,2)}else if(d==="-X"){if(f++,f>=t.length)return I(`complete: -X: option requires an argument
180
- `,2)}else if(d==="--"){c.push(...t.slice(f+1));break}else d.startsWith("-")||c.push(d)}if(r){if(c.length===0)return e.state.completionSpecs.clear(),e.state.defaultCompletionSpec=void 0,e.state.emptyCompletionSpec=void 0,Y("");for(let f of c)e.state.completionSpecs.delete(f);return Y("")}if(n)return c.length===0?aa(e):aa(e,c);if(t.length===0||c.length===0&&!i&&!a&&!o&&l.length===0&&u.length===0&&!s)return aa(e);if(a&&c.length===0&&!s)return I(`complete: -F: option requires a command name
181
- `,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),u.length>0&&(f.actions=u),e.state.defaultCompletionSpec=f,Y("")}for(let f of c){let d=Object.create(null);i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),o!==void 0&&(d.command=o),l.length>0&&(d.options=l),u.length>0&&(d.actions=u),e.state.completionSpecs.set(f,d)}return Y("")}function aa(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
139
+ `):n};async function mh(e,t,n,r){let s=new Map,i=new Map,a=(y,g)=>e.state.closedStandardFds?.has(y)?{kind:"closed"}:Je(e,y)??g,o=new Map([[0,a(0,{kind:"dup-in",sourceFd:0})],[1,a(1,{kind:"dup-out",sourceFd:1})],[2,a(2,{kind:"dup-out",sourceFd:2})]]),l=r.numericSnapshot,u,c=-1,f=o.get(0);f?.kind==="input"?(u=f.content,c=0):f?.kind==="readwrite"&&(u=f.content.slice(f.position),c=0);let d=()=>({targets:s,dupSources:i,standardRoutes:o,stdin:u,stdinSourceFd:c,error:null}),p=async(y,g,b)=>{let v={...d(),error:await an(e,y,t.slice(0,g),s,i,o)};return b?{...v,errorCause:b}:v},h=async(y,g)=>{if(dh(e,y))return null;let b=fh(e);return p(L("",b.stderr,P.EXIT_CODE),g,b)},m=(y,g)=>{y!==null&&y<we&&o.set(y,g),r.policy==="persistent"&&y!==null&&y<we&&(e.state.closedStandardFds?.delete(y),at(e,y,g))},E=(y,g)=>{o.set(y,g),sn(e,r.standardSnapshot,y),r.standardClosedSnapshot.has(y)||r.standardClosedSnapshot.set(y,e.state.closedStandardFds?.has(y)===!0),e.state.closedStandardFds?.delete(y),at(e,y,g)},S=(y,g)=>{if(y<we){let b=o.get(y);return b?.kind==="closed"?null:b?{kind:"entry",entry:b,descriptors:nn(e,y)}:{kind:"standard",fd:y}}return ph(e,y,g)};for(let y=0;y<t.length;y++){let g=t[y],b=oa(g);if(g.target.type==="HereDoc"){let A=await hh(e,g.target);if(g.fdVariable){try{ue(e,g.fdVariable)}catch(x){if(!(x instanceof q))throw x;return p(L(x.stdout,x.stderr,x.exitCode),y,x)}let k=Ec(e),N=await h(k,y);if(N)return N;sn(e,r.fdVariableSnapshot,k),r.fdVariableEnv.has(g.fdVariable)||r.fdVariableEnv.set(g.fdVariable,e.state.env.get(g.fdVariable)),at(e,k,{kind:"input",content:A}),e.state.env.set(g.fdVariable,String(k)),e.state.nextFd=k+1}else if(b!==null&&b>=we){let k=await h(b,y);if(k)return k;sn(e,l,b),at(e,b,{kind:"input",content:A})}else if(b===0||b===null)u=cn(A),c=-1,m(b,{kind:"input",content:u});else{let k={kind:"input",content:A};r.policy==="persistent"?m(b,k):E(b,k)}continue}let v,$=g.operator===">&"||g.operator==="<&";if($){if(Bi(e,g.target))return p(L("",`bash: $@: ambiguous redirect
140
+ `,1),y);v=await ne(e,g.target)}else if(g.operator==="<<<")v=await ne(e,g.target);else{let A=await Qu(e,g.target);if("error"in A)return p(L("",A.error,1),y);v=A.target}if(s.set(y,v),v.includes("\0"))return p(L("",`bash: ${v.replace(/\0/g,"")}: No such file or directory
141
+ `,1),y);if(g.fdVariable){try{ue(e,g.fdVariable)}catch(D){if(!(D instanceof q))throw D;return p(L(D.stdout,D.stderr,D.exitCode),y,D)}if($&&v==="-"){let D=Number.parseInt(e.state.env.get(g.fdVariable)??"",10);Number.isNaN(D)||(sn(e,r.fdVariableSnapshot,D),Ct(e,D));continue}let A=Ec(e),k=$?$s(v):null;if(k&&!S(k.sourceFd,g.operator==="<&"))return p(L("",`bash: ${k.sourceFd}: Bad file descriptor
142
+ `,1),y);if(!(k?.move===!0&&k.sourceFd>=we)){let D=await h(A,y);if(D)return D}sn(e,r.fdVariableSnapshot,A),r.fdVariableEnv.has(g.fdVariable)||r.fdVariableEnv.set(g.fdVariable,e.state.env.get(g.fdVariable));let x,C;if($){let D=k;if(D){let B=S(D.sourceFd,g.operator==="<&");if(!B)return p(L("",`bash: ${D.sourceFd}: Bad file descriptor
143
+ `,1),y);C=D,B.kind==="standard"?x={kind:g.operator==="<&"?"dup-in":"dup-out",sourceFd:B.fd}:D.sourceFd<we&&(x=B.entry)}else{if(g.operator==="<&")return p(L("",`bash: ${v}: ambiguous redirect
144
+ `,1),y);let B=await qn(e,v,!1,!1);if(B.error)return p(B.error,y);x=B.entry}}else if(g.operator===">"||g.operator===">|"||g.operator===">>"||g.operator==="&>"||g.operator==="&>>"){let D=g.operator===">>"||g.operator==="&>>",B=await qn(e,v,D,g.operator===">|");if(B.error)return p(B.error,y);x=B.entry}else if(g.operator==="<<<")x={kind:"input",content:`${v}
145
+ `};else if(g.operator==="<"||g.operator==="<>"){let D=await la(e,v,g.operator==="<>");if(D.error)return p(D.error,y);x=D.entry}if(C&&C.sourceFd>=we){if(!(C.move?ia(e,A,C.sourceFd):Ss(e,A,C.sourceFd)))return p(L("",`bash: ${C.sourceFd}: Bad file descriptor
146
+ `,1),y)}else x&&at(e,A,x);C?.move&&C.sourceFd!==A&&C.sourceFd<we&&Ct(e,C.sourceFd),e.state.env.set(g.fdVariable,String(A)),e.state.nextFd=A+1;continue}if(gc(g)){let A=b;if($&&v==="-"){sn(e,l,A),Ct(e,A);continue}let k=$?$s(v):null;if(k&&!S(k.sourceFd,g.operator==="<&"))return p(L("",`bash: ${k.sourceFd}: Bad file descriptor
147
+ `,1),y);if(!(k?.move===!0&&k.sourceFd>=we)){let x=await h(A,y);if(x)return x}if(sn(e,l,A),$){let x=k;if(!x){if(g.operator==="<&")return p(L("",`bash: ${v}: ambiguous redirect
148
+ `,1),y);let D=await qn(e,v,!1,!1);if(D.error)return p(D.error,y);at(e,A,D.entry);continue}let C=S(x.sourceFd,g.operator==="<&");if(!C)return p(L("",`bash: ${x.sourceFd}: Bad file descriptor
149
+ `,1),y);if(C.kind==="standard")at(e,A,{kind:g.operator==="<&"?"dup-in":"dup-out",sourceFd:C.fd});else if(x.sourceFd<we)at(e,A,C.entry);else if(!(x.move?ia(e,A,x.sourceFd):Ss(e,A,x.sourceFd)))return p(L("",`bash: ${x.sourceFd}: Bad file descriptor
150
+ `,1),y);x.move&&x.sourceFd!==A&&x.sourceFd<we&&Ct(e,x.sourceFd);continue}if(g.operator===">"||g.operator===">|"||g.operator===">>"){let x=await qn(e,v,g.operator===">>",g.operator===">|");if(x.error)return p(x.error,y);at(e,A,x.entry)}else if(g.operator==="<<<")at(e,A,{kind:"input",content:`${v}
151
+ `});else if(g.operator==="<"||g.operator==="<>"){let x=await la(e,v,g.operator==="<>");if(x.error)return p(x.error,y);at(e,A,x.entry)}continue}if($){if(v==="-"){b===0&&(u="",c=-1),b!==null&&b<we&&(o.set(b,{kind:"closed"}),r.policy==="persistent"&&(Ct(e,b),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(b)));continue}let A=$s(v);if(!A){if(g.operator==="<&")return p(L("",`bash: ${v}: ambiguous redirect
152
+ `,1),y);let N=await qn(e,v,!1,!1,!1);if(N.error)return p(N.error,y);let x=N.entry;i.set(y,{kind:"entry",entry:x,descriptors:[]}),g.fd==null?(m(1,x),m(2,x)):m(b,x);continue}let k=S(A.sourceFd,g.operator==="<&");if(!k)return p(L("",`bash: ${A.sourceFd}: Bad file descriptor
153
+ `,1),y);if(i.set(y,k),k.kind==="entry"&&r.policy==="persistent"&&b!==null&&b<we&&A.sourceFd>=we){if(!Ss(e,b,A.sourceFd))return p(L("",`bash: ${A.sourceFd}: Bad file descriptor
154
+ `,1),y);o.set(b,Je(e,b)),e.state.closedStandardFds?.delete(b)}else k.kind==="standard"?m(b,{kind:g.operator==="<&"?"dup-in":"dup-out",sourceFd:k.fd}):m(b,k.entry);if(g.operator==="<&"&&b===0)if(k.kind==="standard")u=k.fd===0?n:"",c=-1;else if(k.entry.kind==="input"||k.entry.kind==="readwrite"){let N=A.sourceFd<we&&!Sn(e,A.sourceFd)?{content:k.entry.kind==="input"?k.entry.content:k.entry.content.slice(k.entry.position)}:As(e,A.sourceFd);if("error"in N)return p(L("",`bash: ${A.sourceFd}: Bad file descriptor
155
+ `,1),y);u=N.content,c=Sn(e,A.sourceFd)?A.sourceFd:-1}else u=n,c=-1;A.move&&(A.sourceFd>=we?Ct(e,A.sourceFd):(o.set(A.sourceFd,{kind:"closed"}),r.policy==="persistent"&&(Ct(e,A.sourceFd),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(A.sourceFd))));continue}if(g.operator===">"||g.operator===">|"||g.operator===">>"||g.operator==="&>"||g.operator==="&>>"){let A=await qn(e,v,g.operator===">>"||g.operator==="&>>",g.operator===">|",!1);if(A.error)return p(A.error,y);let k=A.entry;g.operator==="&>"||g.operator==="&>>"?(m(1,k),m(2,k)):m(b,k);continue}if(g.operator==="<<<")u=cn(`${v}
156
+ `),c=-1,m(b,{kind:"input",content:u});else if(g.operator==="<"){let A=e.fs.resolvePath(e.state.cwd,v);try{u=await $n(e.fs,A),c=-1,m(b,{kind:"input",content:u})}catch{return p(L("",`bash: ${v}: No such file or directory
157
+ `,1),y)}}else if(g.operator==="<>"){let A=await la(e,v,!0);if(A.error)return p(A.error,y);let k=A.entry;m(b,k),b===0&&k.kind==="readwrite"&&(u=k.content,c=-1)}}return d()}function Un(e,t,n){let r={numericSnapshot:new Map,fdVariableSnapshot:new Map,standardSnapshot:new Map,standardClosedSnapshot:new Map,fdVariableEnv:new Map,nextFd:e.state.nextFd,policy:n},s=!1;return{prepare:(i="")=>mh(e,t,i,r),finish:()=>{if(!s){if(s=!0,n!=="persistent"&&vs(e,r.numericSnapshot),n!=="persistent"){vs(e,r.standardSnapshot);for(let[i,a]of r.standardClosedSnapshot)a?(e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(i)):e.state.closedStandardFds?.delete(i)}if(n==="bare"){vs(e,r.fdVariableSnapshot);for(let[i,a]of r.fdVariableEnv)a===void 0?e.state.env.delete(i):e.state.env.set(i,a);e.state.nextFd=r.nextFd}}}}}function jn(e){if(!e.error)throw new Error("Expected a redirection error");if(e.errorCause)throw e.errorCause.stdout=e.error.stdout,e.errorCause.stderr=e.error.stderr,e.errorCause;return e.error}async function ua(e,t,n,r){let s=t instanceof q||t instanceof Oe||t instanceof Be?t.exitCode:t instanceof P?P.EXIT_CODE:0,i=await an(e,L(t.stdout,t.stderr,s),n,r.targets,r.dupSources,r.standardRoutes);t.stdout=i.stdout,t.stderr=i.stderr,t.internalOutputAccounting=i.internalOutputAccounting??{stdout:M(i.stdout),stderr:M(i.stderr)}}async function et(e,t,n,r){let s=Un(e,t,pr),i;try{if(i=await s.prepare(n),i.error)return jn(i);let a=e.state.groupStdin,o=e.state.groupStdinSourceFd;i.stdin!==void 0&&(e.state.groupStdin=i.stdin,e.state.groupStdinSourceFd=i.stdinSourceFd);try{let l=await r(i);return await an(e,l,t,i.targets,i.dupSources,i.standardRoutes)}finally{i.stdin!==void 0&&(e.state.groupStdin=a,e.state.groupStdinSourceFd=o)}}catch(a){throw!(a instanceof xn)||!i||await ua(e,a,t,i),a}finally{s.finish()}}async function an(e,t,n,r,s=new Map,i=new Map,a="bash",o=!1){n.length>0&&(t=e.executionScope.accountResult(t,"redirection"));let{stdout:l,stderr:u,exitCode:c}=t,d=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",p=b=>d,h={kind:"live-stdout"},m={kind:"live-stderr"},E=b=>{if(!b)return null;if(b.kind==="entry"){if(b.entry.kind==="dup-out"){if(b.entry.sourceFd===1)return{kind:"live-stdout"};if(b.entry.sourceFd===2)return{kind:"live-stderr"}}return b.entry.kind==="output"||b.entry.kind==="readwrite"?{kind:"descriptor",source:b}:null}return b.fd===1?h:b.fd===2?m:null},S=b=>{let v=i.get(b)??Je(e,b);return v?v.kind==="closed"?{kind:"invalid-output",fd:b}:v.kind==="input"||v.kind==="dup-in"?{kind:"invalid-output",fd:b}:v.kind==="dup-out"?v.sourceFd===1?{kind:"live-stdout"}:v.sourceFd===2?{kind:"live-stderr"}:null:v.kind==="output"||v.kind==="readwrite"?{kind:"descriptor",source:{kind:"entry",entry:v,descriptors:nn(e,b)}}:null:null};h=S(1)??h,m=S(2)??m;for(let b=0;b<n.length;b++){let v=n[b];if(v.target.type==="HereDoc"||v.fdVariable)continue;let $=r.get(b);if($!==void 0)switch(v.operator){case">":case">|":case">>":{let A=v.fd??1;if(A!==1&&A!==2)break;let k=v.operator===">>";if($==="/dev/stdout"){A===2&&(m=h);break}if($==="/dev/stderr"){A===1&&(h=m);break}if($==="/dev/full"){u+=`bash: echo: write error: No space left on device
158
+ `,c=1,A===1&&(l="");break}if($==="/dev/null"&&A===2){m={kind:"discard"};break}let N=e.fs.resolvePath(e.state.cwd,$);A===1?h={kind:"file",path:N,append:k}:m={kind:"file",path:N,append:k};break}case">&":case"<&":{let A=v.fd??(v.operator==="<&"?0:1);if(A>=we||A===0)break;if($==="-"){A===1?h={kind:"discard"}:m={kind:"discard"};break}let k=E(s.get(b));if(!k)break;v.fd==null&&$s($)===null?(h=k,m=k):A===1?h=k:A===2&&(m=k);break}case"&>":{h={kind:"file",path:e.fs.resolvePath(e.state.cwd,$),append:!1},m=h;break}case"&>>":{h={kind:"file",path:e.fs.resolvePath(e.state.cwd,$),append:!0},m=h;break}}}if(l!==""||u!==""){let b=l,v=u;l="",u="",h.kind==="invalid-output"&&b!==""&&(b="",v+=`${o?"":"bash: "}${a}: write error: Bad file descriptor
159
+ `,c=1),m.kind==="invalid-output"&&(v="");let $=async(A,k,N)=>{A.append?await e.fs.appendFile(A.path,k,N):await e.fs.writeFile(A.path,k,N)};if(h===m&&(h.kind==="file"||h.kind==="descriptor")){let A=b+v;A!==""&&(h.kind==="file"?await $(h,A,p(A)):await aa(e,h.source.entry,h.source.descriptors,A,p(A)))}else for(let[A,k,N]of[[b,h,!0],[v,m,!1]])if(A!=="")switch(k.kind){case"live-stdout":l+=A;break;case"live-stderr":u+=A;break;case"file":await $(k,A,N?p(A):wc(A));break;case"descriptor":await aa(e,k.source.entry,k.source.descriptors,A,N?p(A):wc(A));break;case"invalid-output":break;case"discard":break}}let y=L(l,u,c);if(t.stdoutKind&&(y.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(y.stdoutEncoding="binary"),t.internalPipeStatusOverride&&(y.internalPipeStatusOverride=t.internalPipeStatusOverride),n.length>0||e.state.fileDescriptors?.has(1)===!0||e.state.fileDescriptors?.has(2)===!0){let b=(t.internalOutputAccounting?.stdout??0)+(t.internalOutputAccounting?.stderr??0),v=M(y.stdout),$=M(y.stderr),A=Math.min(v,b);y.internalOutputAccounting={stdout:A,stderr:Math.min($,b-A)},e.executionScope.accountResult(y,"redirection")}else t.internalOutputAccounting&&(y.internalOutputAccounting=t.internalOutputAccounting);return y}function Ac(e,t){if(e.state.options.posix&&Qi.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
160
+ `;throw new q(2,"",r)}let n={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,n),J}async function xs(e,t,n,r="",s,i=!1){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,Jt(`${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 a=new Map,o=Number.parseInt(e.state.env.get("#")??"0",10),l=Math.max(n.length,o);for(let p=0;p<l;p++){let h=String(p+1);a.set(h,e.state.env.get(h)),p<n.length?e.state.env.set(h,n[p]):e.state.env.delete(h)}a.set("@",e.state.env.get("@")),a.set("#",e.state.env.get("#")),e.state.env.set("@",n.join(" ")),e.state.env.set("#",String(n.length));let u=!1,c=()=>{if(u)return;u=!0;let p=e.state.localScopes.length-1,h=e.state.localScopes.pop(),m=e.state.localArrayScopes?.pop();if(h)for(let[E,S]of h)S===void 0?e.state.env.delete(E):e.state.env.set(E,S);if(m){e.state.arrays??=new Map;for(let[E,S]of m)S===void 0?(e.state.arrays.delete(E),e.state.associativeArrays?.delete(E)):(e.state.arrays.set(E,Te(S)),e.state.associativeArrays??=new Set,S.kind==="associative"?e.state.associativeArrays.add(E):e.state.associativeArrays.delete(E))}if(pc(e,p),e.state.fullyUnsetLocals)for(let[E,S]of e.state.fullyUnsetLocals.entries())S===p&&e.state.fullyUnsetLocals.delete(E);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let E=e.state.localExportedVars.pop();if(E)for(let S of E)e.state.exportedVars?.delete(S)}for(let[E,S]of a)S===void 0?e.state.env.delete(E):e.state.env.set(E,S);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},f=null,d=Un(e,t.redirections,pr);try{if(f=await d.prepare(r),f.error)return jn(f);let p=f.stdin??r,h=i||f.stdin!==void 0||r!=="",m=await e.executeCommand(t.body,p,h);return an(e,m,t.redirections,f.targets,f.dupSources,f.standardRoutes)}catch(p){if(p instanceof xn&&f&&(await ua(e,p,t.redirections,f),p instanceof Oe))return L(p.stdout,p.stderr,p.exitCode);throw p}finally{d.finish(),c()}}var $c=e=>e.type==="Escaped"?T.literal(`\\${e.value}`):e.type==="DoubleQuoted"?{...e,parts:e.parts.map($c)}:e,xc=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],da=[".",":","[","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"],yh=["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"],gh=da;async function pa(e,t){let n=[],r=null,s="",i="",a=null,o=!1,l=!1,u=!1,c=null,f=null,d=null,p=[],h=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let $=0;$<t.length;$++){let A=t[$];if(A==="-v")n.push("variable");else if(A==="-e")n.push("export");else if(A==="-f")n.push("file");else if(A==="-d")n.push("directory");else if(A==="-k")n.push("keyword");else if(A==="-A"){if($++,$>=t.length)return _(`compgen: -A: option requires an argument
161
+ `,2);let k=t[$];if(!h.includes(k))return _(`compgen: ${k}: invalid action name
162
+ `,2);n.push(k)}else if(A==="-W"){if($++,$>=t.length)return _(`compgen: -W: option requires an argument
163
+ `,2);r=t[$]}else if(A==="-P"){if($++,$>=t.length)return _(`compgen: -P: option requires an argument
164
+ `,2);s=t[$]}else if(A==="-S"){if($++,$>=t.length)return _(`compgen: -S: option requires an argument
165
+ `,2);i=t[$]}else if(A==="-o"){if($++,$>=t.length)return _(`compgen: -o: option requires an argument
166
+ `,2);let k=t[$];if(k==="plusdirs")o=!0;else if(k==="dirnames")l=!0;else if(k==="default")u=!0;else if(!(k==="filenames"||k==="nospace"||k==="bashdefault"||k==="noquote"))return _(`compgen: ${k}: invalid option name
167
+ `,2)}else if(A==="-F"){if($++,$>=t.length)return _(`compgen: -F: option requires an argument
168
+ `,2);f=t[$]}else if(A==="-C"){if($++,$>=t.length)return _(`compgen: -C: option requires an argument
169
+ `,2);d=t[$]}else if(A==="-X"){if($++,$>=t.length)return _(`compgen: -X: option requires an argument
170
+ `,2);c=t[$]}else if(A==="-G"){if($++,$>=t.length)return _(`compgen: -G: option requires an argument
171
+ `,2)}else if(A==="--"){p.push(...t.slice($+1));break}else A.startsWith("-")||p.push(A)}a=p[0]??null;let m=[],E=new Set,S=()=>e.limits.maxArrayElements-m.length,y=$=>{for(let A of $){if(m.length>=e.limits.maxArrayElements)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(M(A)>e.limits.maxStringLength)throw new P(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");e.executionScope.consumeWork(1,"compgen completion"),m.push(A),E.add(A)}};if(l){let $=await ca(e,a,S());y($)}if(u){let $=await vc(e,a,S());y($)}for(let $ of n)if($==="variable"){let A=wh(e,a,S());y(A)}else if($==="export"){let A=Eh(e,a,S());y(A)}else if($==="function"){let A=bh(e,a,S());y(A)}else if($==="builtin"){let A=Sh(e,a,S());y(A)}else if($==="keyword"){let A=Ah(e,a,S());y(A)}else if($==="alias"){let A=vh(e,a,S());y(A)}else if($==="shopt"){let A=$h(e,a,S());y(A)}else if($==="helptopic"){let A=xh(e,a,S());y(A)}else if($==="directory"){let A=await ca(e,a,S());y(A)}else if($==="file"){let A=await vc(e,a,S());y(A)}else if($==="user"){let A=kh(e,a,S());y(A)}else if($==="command"){let A=await Ph(e,a,S());y(A)}if(r!==null)try{let $=await Ch(e,r),A=Nh(e,$,S(),a);for(let k of A)y([k])}catch($){if($ instanceof P)throw $;return L("","",1)}if(o){let $=await ca(e,a,S(),E);for(let A of $)E.has(A)||y([A])}let g="";if(f!==null){let $=e.state.functions.get(f);if($){let A=new Map,k=ve(e,"COMP_WORDS"),N=k?Te(k):void 0;ye(e,"COMP_WORDS"),er(e,"COMP_WORDS"),A.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),A.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),A.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let x=ve(e,"COMPREPLY"),C=x?Te(x):void 0,D=e.state.env.get("COMPREPLY");ye(e,"COMPREPLY"),e.state.env.delete("COMPREPLY");let B=["compgen",p[0]??"",""];try{let H=await xs(e,$,B,"");if(H.exitCode!==0)return fa(e,A),Gn(e,"COMP_WORDS",N),Gn(e,"COMPREPLY",C),D!==void 0&&e.state.env.set("COMPREPLY",D),L("",H.stderr,1);g=H.stdout;let R=Rh(e,S());y(R)}catch(H){if(H instanceof P)throw H;return fa(e,A),Gn(e,"COMP_WORDS",N),Gn(e,"COMPREPLY",C),D!==void 0&&e.state.env.set("COMPREPLY",D),L("","",1)}fa(e,A),Gn(e,"COMP_WORDS",N),Gn(e,"COMPREPLY",C),D!==void 0&&e.state.env.set("COMPREPLY",D)}}if(d!==null)try{let $=pt(d),A=await e.executeScript($);if(A.exitCode!==0)return L("",A.stderr,A.exitCode);if(A.stdout)for(let k of Dh(A.stdout))k.length>0&&y([k])}catch($){if($.name==="ParseException")return _(`compgen: -C: ${$.message}
172
+ `,2);throw $}let b=m;if(c!==null){let $=c.startsWith("!"),A=$?c.slice(1):c;b=m.filter(k=>{let N=Wn(k,A,!1,!0,e.limits.maxCallDepth);return $?N:!N})}if(b.length===0&&a!==null)return L(g,"",1);let v=new kn(e.limits.maxOutputSize,"compgen");v.append(g);for(let $ of b)v.append(s).append($).append(i).append(`
173
+ `);return Y(v.build())}function wh(e,t,n){let r=ot(e,t,n);for(let s of e.state.env.keys())/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&r.add(s);for(let s of e.state.arrays?.keys()??[])r.add(s);return r.build()}function Eh(e,t,n){let r=ot(e,t,n),s=e.state.exportedVars??new Set;for(let i of s)e.state.env.has(i)&&r.add(i);return r.build()}function bh(e,t,n){let r=ot(e,t,n);for(let s of e.state.functions.keys())r.add(s);return r.build()}function Sh(e,t,n){let r=ot(e,t,n);for(let s of da)r.add(s);return r.build()}function Ah(e,t,n){let r=ot(e,t,n);for(let s of xc)r.add(s);return r.build()}function vh(e,t,n){let r=ot(e,t,n);for(let s of e.state.env.keys())if(s.startsWith("BASH_ALIAS_")){let i=s.slice(11);r.add(i)}return r.build()}function $h(e,t,n){let r=ot(e,t,n);for(let s of yh)r.add(s);return r.build()}function xh(e,t,n){let r=ot(e,t,n);for(let s of gh)r.add(s);return r.build()}async function ca(e,t,n=e.limits.maxArrayElements,r){let s=ot(e,null,n,r);try{let i=e.state.cwd,a=t??"";if(t){let l=t.lastIndexOf("/");if(l!==-1){let u=t.slice(0,l)||"/";a=t.slice(l+1),u.startsWith("/")?i=u:i=`${e.state.cwd}/${u}`}}let o=await e.fs.readdir(i);for(let l of o){e.executionScope.consumeWork(1,"compgen directory scan");let u=`${i}/${l}`;try{if((await e.fs.stat(u)).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(c){if(c instanceof P)throw c}}}catch(i){if(i instanceof P)throw i}return s.build()}async function vc(e,t,n=e.limits.maxArrayElements){let r=ot(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("/"),u=t.slice(0,l+1);r.add(u+o)}else r.add(o)}catch(s){if(s instanceof P)throw s}return r.build()}function kh(e,t,n){let r=ot(e,t,n);return r.add("root"),r.add("nobody"),r.build()}async function Ph(e,t,n){let r=ot(e,t,n);for(let i of da)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 xc)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 ot(e,t,n,r){let s=new Set;return{add(i){if(e.executionScope.consumeWork(1,"compgen candidate collection"),!(t!==null&&!i.startsWith(t))&&!r?.has(i)&&!s.has(i)){if(s.size>=n)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(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 Ch(e,t){let r=new j().parseWordFromString(t,!1,!1);return await ne(e,T.word(r.parts.map($c)))}function Nh(e,t,n,r){let s=e.state.env.get("IFS")??`
174
+ `;if(s.length===0){if(r!==null&&!t.startsWith(r))return[];if(n===0)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");return[t]}let i=new Set(s.split("")),a=[],o=c=>{if(!(r!==null&&!c.startsWith(r))){if(a.length>=n)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");a.push(c)}},l="",u=0;for(;u<t.length;){let c=t[u];if(c==="\\"&&u+1<t.length){let f=t[u+1];l+=f,u+=2}else i.has(c)?(l.length>0&&(o(l),l=""),u++):(l+=c,u++)}return l.length>0&&o(l),a}function fa(e,t){for(let[n,r]of t)r===void 0?e.state.env.delete(n):e.state.env.set(n,r)}function Gn(e,t,n){e.state.arrays??=new Map,n?e.state.arrays.set(t,Te(n)):e.state.arrays.delete(t)}function Rh(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(Pe(e,"COMPREPLY")){let s=G(e,"COMPREPLY");for(let[,i]of s)r(i)}else{let s=e.state.env.get("COMPREPLY");s!==void 0&&r(s)}return n}function*Dh(e){let t=0;for(;t<=e.length;){let n=e.indexOf(`
175
+ `,t),r=n===-1?e.length:n;if(r>t&&(yield e.slice(t,r)),n===-1)return;t=n+1}}function hr(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n===127)return!0}return!1}function ha(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 kc(e){if(hr(e))return Pc(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 hr(e)?ha(e):e===""?"''":/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function ks(e){if(hr(e))return Pc(e);let t=M(e)+2;for(let n of e)(n==="\\"||n==='"'||n==="$"||n==="`")&&t++;return t}function on(e){return hr(e)?ha(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}function Pc(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 mr(e){return hr(e)?ha(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}var Ih=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function ya(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=!1,i,a,o,l=[],u=[],c=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-p")n=!0;else if(d==="-r")r=!0;else if(d==="-D")s=!0;else if(d==="-W"){if(f++,f>=t.length)return _(`complete: -W: option requires an argument
176
+ `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return _(`complete: -F: option requires an argument
177
+ `,2);a=t[f]}else if(d==="-o"){if(f++,f>=t.length)return _(`complete: -o: option requires an argument
178
+ `,2);let p=t[f];if(!Ih.includes(p))return _(`complete: ${p}: invalid option name
179
+ `,2);l.push(p)}else if(d==="-A"){if(f++,f>=t.length)return _(`complete: -A: option requires an argument
180
+ `,2);u.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return _(`complete: -C: option requires an argument
181
+ `,2);o=t[f]}else if(d==="-G"){if(f++,f>=t.length)return _(`complete: -G: option requires an argument
182
+ `,2)}else if(d==="-P"){if(f++,f>=t.length)return _(`complete: -P: option requires an argument
183
+ `,2)}else if(d==="-S"){if(f++,f>=t.length)return _(`complete: -S: option requires an argument
184
+ `,2)}else if(d==="-X"){if(f++,f>=t.length)return _(`complete: -X: option requires an argument
185
+ `,2)}else if(d==="--"){c.push(...t.slice(f+1));break}else d.startsWith("-")||c.push(d)}if(r){if(c.length===0)return e.state.completionSpecs.clear(),e.state.defaultCompletionSpec=void 0,e.state.emptyCompletionSpec=void 0,Y("");for(let f of c)e.state.completionSpecs.delete(f);return Y("")}if(n)return c.length===0?ma(e):ma(e,c);if(t.length===0||c.length===0&&!i&&!a&&!o&&l.length===0&&u.length===0&&!s)return ma(e);if(a&&c.length===0&&!s)return _(`complete: -F: option requires a command name
186
+ `,2);if(s){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),a!==void 0&&(f.function=a),o!==void 0&&(f.command=o),l.length>0&&(f.options=l),u.length>0&&(f.actions=u),e.state.defaultCompletionSpec=f,Y("")}for(let f of c){let d=Object.create(null);i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),o!==void 0&&(d.command=o),l.length>0&&(d.options=l),u.length>0&&(d.actions=u),e.state.completionSpecs.set(f,d)}return Y("")}function ma(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
182
187
  `;return L("",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 L(r.join(`
183
188
  `)+(r.length>0?`
184
189
  `:""),`complete: ${i}: no completion specification
185
190
  `,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(`
186
191
  `)}
187
- `)}var gc=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function la(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 I(`compopt: -o: option requires an argument
188
- `,2);let u=t[o];if(!gc.includes(u))return I(`compopt: ${u}: invalid option name
189
- `,2);s.push(u)}else if(l==="+o"){if(o++,o>=t.length)return I(`compopt: +o: option requires an argument
190
- `,2);let u=t[o];if(!gc.includes(u))return I(`compopt: ${u}: invalid option name
191
- `,2);i.push(u)}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 u of s)l.add(u);for(let u of i)l.delete(u);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 u of s)l.add(u);for(let u of i)l.delete(u);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)??{},u=new Set(l.options??[]);for(let c of s)u.add(c);for(let c of i)u.delete(c);l.options=u.size>0?Array.from(u):void 0,e.state.completionSpecs.set(o,l)}return Y("")}return I(`compopt: not currently executing completion function
192
- `,1)}function ua(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Rt;return ee}if(t.length>1)throw new U(1,"",`bash: continue: too many arguments
193
- `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new U(1,"",`bash: continue: ${t[0]}: numeric argument required
194
- `);n=r}throw new Ge(n)}function wc(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 ca(e){return Ee(e)}function fa(e){return`'${e.replace(/'/g,"'\\''")}'`}function Ec(e,t){let n="",r="",s=!1;for(let i of t){let a=wc(e,i);if(e.state.associativeArrays?.has(i)){let c=gt(e,i);if(c.length===0)n+=`declare -A ${i}=()
195
- `;else{let f=c.map(d=>{let p=ae(e,i,d)??"",h=ca(p);return`[${fa(d)}]=${h}`});n+=`declare -A ${i}=(${f.join(" ")})
196
- `}continue}let l=be(e,i);if(l.length>0){let c=l.map(f=>{let d=ae(e,i,f)??"";return`[${f}]=${Xt(d)}`});n+=`declare -a ${i}=(${c.join(" ")})
192
+ `)}var Cc=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function ga(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 _(`compopt: -o: option requires an argument
193
+ `,2);let u=t[o];if(!Cc.includes(u))return _(`compopt: ${u}: invalid option name
194
+ `,2);s.push(u)}else if(l==="+o"){if(o++,o>=t.length)return _(`compopt: +o: option requires an argument
195
+ `,2);let u=t[o];if(!Cc.includes(u))return _(`compopt: ${u}: invalid option name
196
+ `,2);i.push(u)}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 u of s)l.add(u);for(let u of i)l.delete(u);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 u of s)l.add(u);for(let u of i)l.delete(u);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)??{},u=new Set(l.options??[]);for(let c of s)u.add(c);for(let c of i)u.delete(c);l.options=u.size>0?Array.from(u):void 0,e.state.completionSpecs.set(o,l)}return Y("")}return _(`compopt: not currently executing completion function
197
+ `,1)}function wa(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Mt;return J}if(t.length>1)throw new q(1,"",`bash: continue: too many arguments
198
+ `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new q(1,"",`bash: continue: ${t[0]}: numeric argument required
199
+ `);n=r}throw new He(n)}function Nc(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 Ea(e){return Ee(e)}function ba(e){return`'${e.replace(/'/g,"'\\''")}'`}function Rc(e,t){let n="",r="",s=!1;for(let i of t){let a=Nc(e,i);if(e.state.associativeArrays?.has(i)){let c=vt(e,i);if(c.length===0)n+=`declare -A ${i}=()
200
+ `;else{let f=c.map(d=>{let p=ie(e,i,d)??"",h=Ea(p);return`[${ba(d)}]=${h}`});n+=`declare -A ${i}=(${f.join(" ")})
201
+ `}continue}let l=be(e,i);if(l.length>0){let c=l.map(f=>{let d=ie(e,i,f)??"";return`[${f}]=${on(d)}`});n+=`declare -a ${i}=(${c.join(" ")})
197
202
  `;continue}if(Pe(e,i)){n+=`declare -a ${i}=()
198
- `;continue}let u=e.state.env.get(i);if(u!==void 0)n+=`declare ${a} ${i}=${lr(u)}
203
+ `;continue}let u=e.state.env.get(i);if(u!==void 0)n+=`declare ${a} ${i}=${mr(u)}
199
204
  `;else{let c=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);c||f?n+=`declare ${a} ${i}
200
205
  `:(r+=`bash: declare: ${i}: not found
201
- `,s=!0)}}return L(n,r,s?1:0)}function bc(e,t){let{filterExport:n,filterReadonly:r,filterNameref:s,filterIndexedArray:i,filterAssocArray:a}=t,o=n||r||s||i||a,l="",u=new Set;for(let f of e.state.env.keys())f.startsWith("BASH_")||u.add(f);for(let f of e.state.arrays?.keys()??[])u.add(f);if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())u.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)u.add(f);let c=Array.from(u).sort();for(let f of c){let d=wc(e,f),p=e.state.associativeArrays?.has(f),h=be(e,f),m=!p&&Pe(e,f);if(o&&(a&&!p||i&&!m||n&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||s&&!le(e,f)))continue;if(p){let b=gt(e,f);if(b.length===0)l+=`declare -A ${f}=()
202
- `;else{let g=b.map(y=>{let S=ae(e,f,y)??"",v=ca(S);return`[${fa(y)}]=${v}`});l+=`declare -A ${f}=(${g.join(" ")})
203
- `}continue}if(h.length>0){let b=h.map(g=>{let y=ae(e,f,g)??"";return`[${g}]=${Xt(y)}`});l+=`declare -a ${f}=(${b.join(" ")})
206
+ `,s=!0)}}return L(n,r,s?1:0)}function Dc(e,t){let{filterExport:n,filterReadonly:r,filterNameref:s,filterIndexedArray:i,filterAssocArray:a}=t,o=n||r||s||i||a,l="",u=new Set;for(let f of e.state.env.keys())f.startsWith("BASH_")||u.add(f);for(let f of e.state.arrays?.keys()??[])u.add(f);if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())u.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)u.add(f);let c=Array.from(u).sort();for(let f of c){let d=Nc(e,f),p=e.state.associativeArrays?.has(f),h=be(e,f),m=!p&&Pe(e,f);if(o&&(a&&!p||i&&!m||n&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||s&&!le(e,f)))continue;if(p){let S=vt(e,f);if(S.length===0)l+=`declare -A ${f}=()
207
+ `;else{let y=S.map(g=>{let b=ie(e,f,g)??"",v=Ea(b);return`[${ba(g)}]=${v}`});l+=`declare -A ${f}=(${y.join(" ")})
208
+ `}continue}if(h.length>0){let S=h.map(y=>{let g=ie(e,f,y)??"";return`[${y}]=${on(g)}`});l+=`declare -a ${f}=(${S.join(" ")})
204
209
  `;continue}if(Pe(e,f)){l+=`declare -a ${f}=()
205
- `;continue}let E=e.state.env.get(f);E!==void 0&&(l+=`declare ${d} ${f}=${lr(E)}
206
- `)}return Y(l)}function Sc(e){let t="",n=Array.from(e.state.associativeArrays??[]).sort();for(let r of n){let s=gt(e,r);if(s.length===0)t+=`declare -A ${r}=()
207
- `;else{let i=s.map(a=>{let o=ae(e,r,a)??"",l=ca(o);return`[${fa(a)}]=${l}`});t+=`declare -A ${r}=(${i.join(" ")})
208
- `}}return Y(t)}function Ac(e){let t="",n=new Set(Array.from(e.state.arrays??[]).filter(([,s])=>s.kind==="indexed").map(([s])=>s)),r=Array.from(n).sort();for(let s of r){let i=be(e,s);if(i.length===0)t+=`declare -a ${s}=()
209
- `;else{let a=i.map(o=>{let l=ae(e,s,o)??"";return`[${o}]=${Xt(l)}`});t+=`declare -a ${s}=(${a.join(" ")})
210
- `}}return Y(t)}function vc(e){let t="",n=new Set;for(let s of e.state.env.keys())s.startsWith("BASH_")||n.add(s);let r=Array.from(n).sort();for(let s of r){if(e.state.associativeArrays?.has(s)||be(e,s).length>0||Pe(e,s))continue;let o=e.state.env.get(s);o!==void 0&&(t+=`${s}=${Ee(o)}
211
- `)}return Y(t)}function da(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function ur(e,t){return e.state.integerVars?.has(t)??!1}function pa(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function vh(e,t){return e.state.lowercaseVars?.has(t)??!1}function ha(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function $h(e,t){return e.state.uppercaseVars?.has(t)??!1}function Bn(e,t,n){return vh(e,t)?n.toLowerCase():$h(e,t)?n.toUpperCase():n}async function $c(e,t){try{let n=new G,r=te(n,t),s=await K(e,r.expression);return String(s)}catch{return"0"}}function xh(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 ma(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,a=!1,o=!1,l=!1,u=!1,c=!1,f=!1,d=!1,p=!1,h=!1,m=!1,E=!1,b=!1,g=[];for(let x=0;x<t.length;x++){let P=t[x];if(P==="-a")r=!0;else if(P==="-A")s=!0;else if(P==="-r")i=!0;else if(P==="-x")a=!0;else if(P==="-p")o=!0;else if(P==="-n")l=!0;else if(P==="+n")u=!0;else if(P==="+a")c=!0;else if(P==="+x")f=!0;else if(P==="--"){g.push(...t.slice(x+1));break}else if(P.startsWith("+")){for(let R of P.slice(1))if(R==="n")u=!0;else if(R==="a")c=!0;else if(R==="x")f=!0;else if(R!=="r"){if(R!=="i"){if(!(R==="f"||R==="F"))return L("",`bash: typeset: +${R}: invalid option
212
- `,2)}}}else if(P==="-i")d=!0;else if(P==="-l")p=!0;else if(P==="-u")h=!0;else if(P==="-f")m=!0;else if(P==="-F")E=!0;else if(P==="-g")b=!0;else if(P.startsWith("-"))for(let R of P.slice(1))if(R==="a")r=!0;else if(R==="A")s=!0;else if(R==="r")i=!0;else if(R==="x")a=!0;else if(R==="p")o=!0;else if(R==="n")l=!0;else if(R==="i")d=!0;else if(R==="l")p=!0;else if(R==="u")h=!0;else if(R==="f")m=!0;else if(R==="F")E=!0;else if(R==="g")b=!0;else return L("",`bash: typeset: -${R}: invalid option
213
- `,2);else g.push(P)}let S=e.state.localScopes.length>0&&!b,v=x=>{if(!S)return;let P=e.state.localScopes[e.state.localScopes.length-1];P.has(x)||P.set(x,e.state.env.get(x))},$=x=>{if(!S)return;let P=e.state.localScopes[e.state.localScopes.length-1];for(P.has(x)||P.set(x,e.state.env.get(x)),e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let R=e.state.localArrayScopes.at(-1);if(R&&!R.has(x)){let B=ve(e,x);R.set(x,B?Le(B):void 0)}},A=x=>{S&&Gt(e,x)};if(E){if(g.length===0){let R=Array.from(e.state.functions.keys()).sort(),B="";for(let q of R)B+=`declare -f ${q}
214
- `;return Y(B)}let x=!0,P="";for(let R of g)e.state.functions.has(R)?P+=`${R}
215
- `:x=!1;return L(P,"",x?0:1)}if(m){if(g.length===0){let P="",R=Array.from(e.state.functions.keys()).sort();for(let B of R)P+=`${B} ()
210
+ `;continue}let E=e.state.env.get(f);E!==void 0&&(l+=`declare ${d} ${f}=${mr(E)}
211
+ `)}return Y(l)}function Ic(e){let t="",n=Array.from(e.state.associativeArrays??[]).sort();for(let r of n){let s=vt(e,r);if(s.length===0)t+=`declare -A ${r}=()
212
+ `;else{let i=s.map(a=>{let o=ie(e,r,a)??"",l=Ea(o);return`[${ba(a)}]=${l}`});t+=`declare -A ${r}=(${i.join(" ")})
213
+ `}}return Y(t)}function Oc(e){let t="",n=new Set(Array.from(e.state.arrays??[]).filter(([,s])=>s.kind==="indexed").map(([s])=>s)),r=Array.from(n).sort();for(let s of r){let i=be(e,s);if(i.length===0)t+=`declare -a ${s}=()
214
+ `;else{let a=i.map(o=>{let l=ie(e,s,o)??"";return`[${o}]=${on(l)}`});t+=`declare -a ${s}=(${a.join(" ")})
215
+ `}}return Y(t)}function _c(e){let t="",n=new Set;for(let s of e.state.env.keys())s.startsWith("BASH_")||n.add(s);let r=Array.from(n).sort();for(let s of r){if(e.state.associativeArrays?.has(s)||be(e,s).length>0||Pe(e,s))continue;let o=e.state.env.get(s);o!==void 0&&(t+=`${s}=${Ee(o)}
216
+ `)}return Y(t)}function Sa(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function yr(e,t){return e.state.integerVars?.has(t)??!1}function Aa(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Oh(e,t){return e.state.lowercaseVars?.has(t)??!1}function va(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function _h(e,t){return e.state.uppercaseVars?.has(t)??!1}function Hn(e,t,n){return Oh(e,t)?n.toLowerCase():_h(e,t)?n.toUpperCase():n}async function Lc(e,t){try{let n=new j,r=te(n,t),s=await X(e,r.expression);return String(s)}catch{return"0"}}function Lh(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 $a(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,a=!1,o=!1,l=!1,u=!1,c=!1,f=!1,d=!1,p=!1,h=!1,m=!1,E=!1,S=!1,y=[];for(let x=0;x<t.length;x++){let C=t[x];if(C==="-a")r=!0;else if(C==="-A")s=!0;else if(C==="-r")i=!0;else if(C==="-x")a=!0;else if(C==="-p")o=!0;else if(C==="-n")l=!0;else if(C==="+n")u=!0;else if(C==="+a")c=!0;else if(C==="+x")f=!0;else if(C==="--"){y.push(...t.slice(x+1));break}else if(C.startsWith("+")){for(let D of C.slice(1))if(D==="n")u=!0;else if(D==="a")c=!0;else if(D==="x")f=!0;else if(D!=="r"){if(D!=="i"){if(!(D==="f"||D==="F"))return L("",`bash: typeset: +${D}: invalid option
217
+ `,2)}}}else if(C==="-i")d=!0;else if(C==="-l")p=!0;else if(C==="-u")h=!0;else if(C==="-f")m=!0;else if(C==="-F")E=!0;else if(C==="-g")S=!0;else if(C.startsWith("-"))for(let D of C.slice(1))if(D==="a")r=!0;else if(D==="A")s=!0;else if(D==="r")i=!0;else if(D==="x")a=!0;else if(D==="p")o=!0;else if(D==="n")l=!0;else if(D==="i")d=!0;else if(D==="l")p=!0;else if(D==="u")h=!0;else if(D==="f")m=!0;else if(D==="F")E=!0;else if(D==="g")S=!0;else return L("",`bash: typeset: -${D}: invalid option
218
+ `,2);else y.push(C)}let b=e.state.localScopes.length>0&&!S,v=x=>{if(!b)return;let C=e.state.localScopes[e.state.localScopes.length-1];C.has(x)||C.set(x,e.state.env.get(x))},$=x=>{if(!b)return;let C=e.state.localScopes[e.state.localScopes.length-1];for(C.has(x)||C.set(x,e.state.env.get(x)),e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let D=e.state.localArrayScopes.at(-1);if(D&&!D.has(x)){let B=ve(e,x);D.set(x,B?Te(B):void 0)}},A=x=>{b&&tn(e,x)};if(E){if(y.length===0){let D=Array.from(e.state.functions.keys()).sort(),B="";for(let H of D)B+=`declare -f ${H}
219
+ `;return Y(B)}let x=!0,C="";for(let D of y)e.state.functions.has(D)?C+=`${D}
220
+ `:x=!1;return L(C,"",x?0:1)}if(m){if(y.length===0){let C="",D=Array.from(e.state.functions.keys()).sort();for(let B of D)C+=`${B} ()
216
221
  {
217
222
  # function body
218
223
  }
219
- `;return Y(P)}let x=!0;for(let P of g)e.state.functions.has(P)||(x=!1);return L("","",x?0:1)}if(o&&g.length>0)return Ec(e,g);if(o&&g.length===0)return bc(e,{filterExport:a,filterReadonly:i,filterNameref:l,filterIndexedArray:r,filterAssocArray:s});if(g.length===0&&s&&!o)return Sc(e);if(g.length===0&&r&&!o)return Ac(e);if(g.length===0&&!o)return vc(e);let C="",N=0;for(let x of g){let P=x.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(P&&!c){let D=P[1],W=P[2],V=ue(e,D);if(V)return V;if(s&&be(e,D).length>0){C+=`bash: declare: ${D}: cannot convert indexed to associative array
220
- `,N=1;continue}if((r||!s&&!r)&&e.state.associativeArrays?.has(D)){C+=`bash: declare: ${D}: cannot convert associative to indexed array
221
- `,N=1;continue}let O=s&&W.includes("[")?ls(W,n):void 0,_=O===void 0?Pt(W,{...n,maxElements:s?n.maxElements*2:n.maxElements}):void 0;if(e.executionScope.consumeWork(O?.length??_?.length??0,"declare array assignment"),$(D),s?(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(D),Lt(e,D,"associative")):Lt(e,D,"indexed"),ye(e,D),e.state.env.delete(D),s&&W.includes("["))for(let[M,se]of O??[])j(e,D,M,zt(e,se),"associative");else if(s){let M=_??[];for(let se=0;se<M.length;se+=2){let ie=M[se],pn=se+1<M.length?M[se+1]:"";j(e,D,ie,pn,"associative")}}else{let M=_??[];if(M.some(ie=>/^\[[^\]]+\]=/.test(ie))){let ie=0;for(let pn of M){let Rs=pn.match(/^\[([^\]]+)\]=(.*)$/);if(Rs){let Ds=Rs[1],Cf=Rs[2],zn;if(/^-?\d+$/.test(Ds))zn=Number.parseInt(Ds,10);else try{let Nf=new G,Rf=te(Nf,Ds);zn=await K(e,Rf.expression)}catch{zn=0}j(e,D,zn,zt(e,Cf)),ie=zn+1}else j(e,D,ie,pn),ie++}}else for(let ie=0;ie<M.length;ie++)j(e,D,ie,M[ie])}A(D),i&&Ue(e,D),a&&dt(e,D);continue}if(u){let D=x.includes("=")?x.slice(0,x.indexOf("=")):x;if(Sl(e,D),!x.includes("="))continue}if(f){let D=x.includes("=")?x.slice(0,x.indexOf("=")):x;if(Vr(e,D),!x.includes("="))continue}let R=xh(x);if(R){let{name:D,indexExpr:W,value:V}=R,O=ue(e,D);if(O)return O;$(D);let _;try{let M=new G,se=te(M,W);_=await K(e,se.expression)}catch{let M=parseInt(W,10);_=Number.isNaN(M)?0:M}j(e,D,_,V),A(D),i&&Ue(e,D),a&&dt(e,D);continue}let B=x.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(B&&!c){let D=B[1],W=B[2],V=ue(e,D);if(V)return V;$(D);let O=Pt(W,n);if(e.state.associativeArrays?.has(D)){let _=ls(W,n);e.executionScope.consumeWork(_.length,"declare array append"),rn(e,D,_.map(([M])=>M));for(let[M,se]of _)j(e,D,M,se,"associative")}else{e.executionScope.consumeWork(O.length,"declare array append");let _=be(e,D),M=0,se=e.state.env.get(D);_.length===0&&se!==void 0?(j(e,D,0,se),e.state.env.delete(D),M=1):_.length>0&&(M=Math.max(..._)+1),rn(e,D,Array.from({length:O.length},(ie,pn)=>M+pn));for(let ie=0;ie<O.length;ie++)j(e,D,M+ie,O[ie])}A(D),i&&Ue(e,D),a&&dt(e,D);continue}let q=x.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(q){let D=q[1],W=q[2],V=ue(e,D);if(V)return V;v(D),d&&da(e,D),p&&pa(e,D),h&&ha(e,D);let _=be(e,D).length>0||e.state.associativeArrays?.has(D);if(ur(e,D)){let M=e.state.env.get(D)??"0",se=parseInt(M,10)||0,ie=parseInt(await $c(e,W),10)||0;W=String(se+ie),e.state.env.set(D,W)}else if(_){W=Bn(e,D,W);let M=ae(e,D,0)??"";j(e,D,0,Dt([M,W],"",e.limits.maxStringLength,"declare append"))}else{W=Bn(e,D,W);let M=e.state.env.get(D)??"";e.state.env.set(D,Dt([M,W],"",e.limits.maxStringLength,"declare append"))}A(D),i&&Ue(e,D),a&&dt(e,D),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(D));continue}if(x.includes("=")){let D=x.indexOf("="),W=x.slice(0,D),V=x.slice(D+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(W)){C+=`bash: typeset: \`${W}': not a valid identifier
222
- `,N=1;continue}let O=ue(e,W);if(O)return O;if(v(W),l){if(V!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(V)){C+=`bash: declare: \`${V}': invalid variable name for name reference
223
- `,N=1;continue}e.state.env.set(W,V),kt(e,W),V!==""&&Mr(e,V)&&Ei(e,W),A(W),i&&Ue(e,W),a&&dt(e,W);continue}if(d&&da(e,W),p&&pa(e,W),h&&ha(e,W),ur(e,W)&&(V=await $c(e,V)),V=Bn(e,W,V),le(e,W)){let _=Te(e,W);_&&_!==W?e.state.env.set(_,V):e.state.env.set(W,V)}else e.state.env.set(W,V);A(W),i&&Ue(e,W),a&&dt(e,W),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(W))}else{let D=x;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(D)){C+=`bash: typeset: \`${D}': not a valid identifier
224
- `,N=1;continue}if(r||s?$(D):v(D),l){kt(e,D);let V=e.state.env.get(D);V!==void 0&&V!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(V)?Al(e,D):V&&Mr(e,V)&&Ei(e,D),A(D),i&&Ue(e,D),a&&dt(e,D);continue}if(d&&da(e,D),p&&pa(e,D),h&&ha(e,D),s){if(be(e,D).length>0){C+=`bash: declare: ${D}: cannot convert indexed to associative array
225
- `,N=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(D),Lt(e,D,"associative")}let W=Pe(e,D);!e.state.env.has(D)&&!W&&(r||s?Lt(e,D,s?"associative":"indexed"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(D))),A(D),i&&Ue(e,D),a&&dt(e,D)}}return L("",C,N)}async function ya(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 u of l){let c=e.state.env.get(u);if(c!==void 0){let f=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');o+=`declare -r ${u}="${f}"
226
- `}}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],p=l[2],h=ue(e,d);if(h)return h;let m=Pt(p,n);if(e.state.associativeArrays?.has(d)){let E=ls(p,n);e.executionScope.consumeWork(E.length,"readonly array append"),rn(e,d,E.map(([b])=>b));for(let[b,g]of E)j(e,d,b,g,"associative")}else{e.executionScope.consumeWork(m.length,"readonly array append");let E=be(e,d),b=0,g=e.state.env.get(d);E.length===0&&g!==void 0?(j(e,d,0,g),e.state.env.delete(d),b=1):E.length>0&&(b=Math.max(...E)+1),rn(e,d,Array.from({length:m.length},(y,S)=>b+S));for(let y=0;y<m.length;y++)j(e,d,b+y,m[y])}Ue(e,d);continue}let u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(u){let d=u[1],p=u[2],h=ue(e,d);if(h)return h;let m=e.state.env.get(d)??"";e.state.env.set(d,Dt([m,p],"",e.limits.maxStringLength,"readonly append")),Ue(e,d);continue}let c=Ju(o,n);if(c.value===void 0&&!c.isArray){Ue(e,c.name);continue}let f=await ec(e,c,{makeReadonly:!0});if(f)return f}return ee}function ga(e){return e.state.directoryStack??=[],e.state.directoryStack}function cr(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function kh(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 wa(e,t){let n=ga(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 I(`bash: pushd: too many arguments
227
- `,2);r=t[o+1],o++}}else{if(l.startsWith("-")&&l!=="-")return I(`bash: pushd: ${l}: invalid option
228
- `,2);if(r!==void 0)return I(`bash: pushd: too many arguments
229
- `,2);r=l}}if(r===void 0){if(n.length<2)return I(`bash: pushd: no other directory
230
- `,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=kh(s);try{if(!(await e.fs.stat(s)).isDirectory)return I(`bash: pushd: ${r}: Not a directory
231
- `,1)}catch{return I(`bash: pushd: ${r}: No such file or directory
232
- `,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=>cr(o,i)).join(" ")}
233
- `;return Y(a)}function Ea(e,t){let n=ga(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?I(`bash: popd: ${a}: invalid option
234
- `,2):I(`bash: popd: too many arguments
235
- `,2);if(n.length===0)return I(`bash: popd: directory stack empty
236
- `,1);let r=n.shift();if(!r)return I(`bash: popd: directory stack empty
237
- `,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=>cr(a,s)).join(" ")}
238
- `;return Y(i)}function ba(e,t){let n=ga(e),r=!1,s=!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")s=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,a=!0;else return I(`bash: dirs: -${f}: invalid option
239
- `,2);else return I(`bash: dirs: too many arguments
240
- `,1);if(r)return e.state.directoryStack=[],ee;let o=[e.state.cwd,...n],l=e.state.env.get("HOME")||"",u;return a?(u=o.map((c,f)=>{let d=s?c:cr(c,l);return` ${f} ${d}`}).join(`
224
+ `;return Y(C)}let x=!0;for(let C of y)e.state.functions.has(C)||(x=!1);return L("","",x?0:1)}if(o&&y.length>0)return Rc(e,y);if(o&&y.length===0)return Dc(e,{filterExport:a,filterReadonly:i,filterNameref:l,filterIndexedArray:r,filterAssocArray:s});if(y.length===0&&s&&!o)return Ic(e);if(y.length===0&&r&&!o)return Oc(e);if(y.length===0&&!o)return _c(e);let k="",N=0;for(let x of y){let C=x.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(C&&!c){let R=C[1],W=C[2],V=ue(e,R);if(V)return V;if(s&&be(e,R).length>0){k+=`bash: declare: ${R}: cannot convert indexed to associative array
225
+ `,N=1;continue}if((r||!s&&!r)&&e.state.associativeArrays?.has(R)){k+=`bash: declare: ${R}: cannot convert associative to indexed array
226
+ `,N=1;continue}let I=s&&W.includes("[")?ys(W,n):void 0,O=I===void 0?_t(W,{...n,maxElements:s?n.maxElements*2:n.maxElements}):void 0;if(e.executionScope.consumeWork(I?.length??O?.length??0,"declare array assignment"),$(R),s?(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(R),zt(e,R,"associative")):zt(e,R,"indexed"),ye(e,R),e.state.env.delete(R),s&&W.includes("["))for(let[F,ee]of I??[])U(e,R,F,Xt(e,ee),"associative");else if(s){let F=O??[];for(let ee=0;ee<F.length;ee+=2){let K=F[ee],Ie=ee+1<F.length?F[ee+1]:"";U(e,R,K,Ie,"associative")}}else{let F=O??[];if(F.some(K=>/^\[[^\]]+\]=/.test(K))){let K=0;for(let Ie of F){let ut=Ie.match(/^\[([^\]]+)\]=(.*)$/);if(ut){let Rt=ut[1],ct=ut[2],ft;if(/^-?\d+$/.test(Rt))ft=Number.parseInt(Rt,10);else try{let Dt=new j,Ff=te(Dt,Rt);ft=await X(e,Ff.expression)}catch{ft=0}U(e,R,ft,Xt(e,ct)),K=ft+1}else U(e,R,K,Ie),K++}}else for(let K=0;K<F.length;K++)U(e,R,K,F[K])}A(R),i&&je(e,R),a&&gt(e,R);continue}if(u){let R=x.includes("=")?x.slice(0,x.indexOf("=")):x;if(Ol(e,R),!x.includes("="))continue}if(f){let R=x.includes("=")?x.slice(0,x.indexOf("=")):x;if(Zr(e,R),!x.includes("="))continue}let D=Lh(x);if(D){let{name:R,indexExpr:W,value:V}=D,I=ue(e,R);if(I)return I;$(R);let O;try{let F=new j,ee=te(F,W);O=await X(e,ee.expression)}catch{let F=parseInt(W,10);O=Number.isNaN(F)?0:F}U(e,R,O,V),A(R),i&&je(e,R),a&&gt(e,R);continue}let B=x.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(B&&!c){let R=B[1],W=B[2],V=ue(e,R);if(V)return V;$(R);let I=_t(W,n);if(e.state.associativeArrays?.has(R)){let O=ys(W,n);e.executionScope.consumeWork(O.length,"declare array append"),pn(e,R,O.map(([F])=>F));for(let[F,ee]of O)U(e,R,F,ee,"associative")}else{e.executionScope.consumeWork(I.length,"declare array append");let O=be(e,R),F=0,ee=e.state.env.get(R);O.length===0&&ee!==void 0?(U(e,R,0,ee),e.state.env.delete(R),F=1):O.length>0&&(F=Math.max(...O)+1),pn(e,R,Array.from({length:I.length},(K,Ie)=>F+Ie));for(let K=0;K<I.length;K++)U(e,R,F+K,I[K])}A(R),i&&je(e,R),a&&gt(e,R);continue}let H=x.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(H){let R=H[1],W=H[2],V=ue(e,R);if(V)return V;v(R),d&&Sa(e,R),p&&Aa(e,R),h&&va(e,R);let O=be(e,R).length>0||e.state.associativeArrays?.has(R);if(yr(e,R)){let F=e.state.env.get(R)??"0",ee=parseInt(F,10)||0,K=parseInt(await Lc(e,W),10)||0;W=String(ee+K),e.state.env.set(R,W)}else if(O){W=Hn(e,R,W);let F=ie(e,R,0)??"";U(e,R,0,Ft([F,W],"",e.limits.maxStringLength,"declare append"))}else{W=Hn(e,R,W);let F=e.state.env.get(R)??"";e.state.env.set(R,Ft([F,W],"",e.limits.maxStringLength,"declare append"))}A(R),i&&je(e,R),a&&gt(e,R),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(R));continue}if(x.includes("=")){let R=x.indexOf("="),W=x.slice(0,R),V=x.slice(R+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(W)){k+=`bash: typeset: \`${W}': not a valid identifier
227
+ `,N=1;continue}let I=ue(e,W);if(I)return I;if(v(W),l){if(V!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(V)){k+=`bash: declare: \`${V}': invalid variable name for name reference
228
+ `,N=1;continue}e.state.env.set(W,V),Ot(e,W),V!==""&&Ur(e,V)&&ki(e,W),A(W),i&&je(e,W),a&&gt(e,W);continue}if(d&&Sa(e,W),p&&Aa(e,W),h&&va(e,W),yr(e,W)&&(V=await Lc(e,V)),V=Hn(e,W,V),le(e,W)){let O=Me(e,W);O&&O!==W?e.state.env.set(O,V):e.state.env.set(W,V)}else e.state.env.set(W,V);A(W),i&&je(e,W),a&&gt(e,W),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(W))}else{let R=x;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(R)){k+=`bash: typeset: \`${R}': not a valid identifier
229
+ `,N=1;continue}if(r||s?$(R):v(R),l){Ot(e,R);let V=e.state.env.get(R);V!==void 0&&V!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(V)?_l(e,R):V&&Ur(e,V)&&ki(e,R),A(R),i&&je(e,R),a&&gt(e,R);continue}if(d&&Sa(e,R),p&&Aa(e,R),h&&va(e,R),s){if(be(e,R).length>0){k+=`bash: declare: ${R}: cannot convert indexed to associative array
230
+ `,N=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(R),zt(e,R,"associative")}let W=Pe(e,R);!e.state.env.has(R)&&!W&&(r||s?zt(e,R,s?"associative":"indexed"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(R))),A(R),i&&je(e,R),a&&gt(e,R)}}return L("",k,N)}async function xa(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 u of l){let c=e.state.env.get(u);if(c!==void 0){let f=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');o+=`declare -r ${u}="${f}"
231
+ `}}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],p=l[2],h=ue(e,d);if(h)return h;let m=_t(p,n);if(e.state.associativeArrays?.has(d)){let E=ys(p,n);e.executionScope.consumeWork(E.length,"readonly array append"),pn(e,d,E.map(([S])=>S));for(let[S,y]of E)U(e,d,S,y,"associative")}else{e.executionScope.consumeWork(m.length,"readonly array append");let E=be(e,d),S=0,y=e.state.env.get(d);E.length===0&&y!==void 0?(U(e,d,0,y),e.state.env.delete(d),S=1):E.length>0&&(S=Math.max(...E)+1),pn(e,d,Array.from({length:m.length},(g,b)=>S+b));for(let g=0;g<m.length;g++)U(e,d,S+g,m[g])}je(e,d);continue}let u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(u){let d=u[1],p=u[2],h=ue(e,d);if(h)return h;let m=e.state.env.get(d)??"";e.state.env.set(d,Ft([m,p],"",e.limits.maxStringLength,"readonly append")),je(e,d);continue}let c=cc(o,n);if(c.value===void 0&&!c.isArray){je(e,c.name);continue}let f=await fc(e,c,{makeReadonly:!0});if(f)return f}return J}function ka(e){return e.state.directoryStack??=[],e.state.directoryStack}function gr(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function Th(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 Pa(e,t){let n=ka(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 _(`bash: pushd: too many arguments
232
+ `,2);r=t[o+1],o++}}else{if(l.startsWith("-")&&l!=="-")return _(`bash: pushd: ${l}: invalid option
233
+ `,2);if(r!==void 0)return _(`bash: pushd: too many arguments
234
+ `,2);r=l}}if(r===void 0){if(n.length<2)return _(`bash: pushd: no other directory
235
+ `,1);let 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=Th(s);try{if(!(await e.fs.stat(s)).isDirectory)return _(`bash: pushd: ${r}: Not a directory
236
+ `,1)}catch{return _(`bash: pushd: ${r}: No such file or directory
237
+ `,1)}n.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=s,e.state.env.set("PWD",s),e.state.env.set("OLDPWD",e.state.previousDir);let i=e.state.env.get("HOME")||"",a=`${[s,...n].map(o=>gr(o,i)).join(" ")}
238
+ `;return Y(a)}function Ca(e,t){let n=ka(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?_(`bash: popd: ${a}: invalid option
239
+ `,2):_(`bash: popd: too many arguments
240
+ `,2);if(n.length===0)return _(`bash: popd: directory stack empty
241
+ `,1);let r=n.shift();if(!r)return _(`bash: popd: directory stack empty
242
+ `,1);e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.set("PWD",r),e.state.env.set("OLDPWD",e.state.previousDir);let s=e.state.env.get("HOME")||"",i=`${[r,...n].map(a=>gr(a,s)).join(" ")}
243
+ `;return Y(i)}function Na(e,t){let n=ka(e),r=!1,s=!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")s=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,a=!0;else return _(`bash: dirs: -${f}: invalid option
244
+ `,2);else return _(`bash: dirs: too many arguments
245
+ `,1);if(r)return e.state.directoryStack=[],J;let o=[e.state.cwd,...n],l=e.state.env.get("HOME")||"",u;return a?(u=o.map((c,f)=>{let d=s?c:gr(c,l);return` ${f} ${d}`}).join(`
241
246
  `),u+=`
242
- `):i?u=o.map(c=>s?c:cr(c,l)).join(`
247
+ `):i?u=o.map(c=>s?c:gr(c,l)).join(`
243
248
  `)+`
244
- `:u=o.map(c=>s?c:cr(c,l)).join(" ")+`
245
- `,Y(u)}async function Es(e,t,n,r=!1){let s=t;if(s.length>0){let l=s[0];if(l==="--")s=s.slice(1);else if(l.startsWith("-")&&l!=="-"&&l.length>1)return I(`bash: eval: ${l}: invalid option
249
+ `:u=o.map(c=>s?c:gr(c,l)).join(" ")+`
250
+ `,Y(u)}async function Ps(e,t,n,r=!1){let s=t;if(s.length>0){let l=s[0];if(l==="--")s=s.slice(1);else if(l.startsWith("-")&&l!=="-"&&l.length>1)return _(`bash: eval: ${l}: invalid option
246
251
  eval: usage: eval [arg ...]
247
- `,2)}if(s.length===0)return ee;let i=s.join(" ");if(i.trim()==="")return ee;let a=e.state.groupStdin,o=r||n!==void 0&&n!=="";o&&(e.state.groupStdin=n??"");try{let l=lt(i);return await e.executeScript(l)}catch(l){if(l instanceof je||l instanceof Ge||l instanceof Ie||l instanceof U)throw l;if(l.name==="ParseException")return I(`bash: eval: ${l.message}
248
- `);throw l}finally{(o||a!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=a)}}function Sa(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
249
- `,n=2;else{let i=BigInt(s);n=Number((i%256n+256n)%256n)}}throw new U(n,"",r)}function Aa(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 u of l){let c=e.state.env.get(u);c!==void 0&&(a+=`declare -x ${u}=${lr(c)}
252
+ `,2)}if(s.length===0)return J;let i=s.join(" ");if(i.trim()==="")return J;let a=e.state.groupStdin,o=r||n!==void 0&&n!=="";o&&(e.state.groupStdin=n??"");try{let l=pt(i);return await e.executeScript(l)}catch(l){if(l instanceof Ge||l instanceof He||l instanceof Oe||l instanceof q)throw l;if(l.name==="ParseException")return _(`bash: eval: ${l.message}
253
+ `);throw l}finally{(o||a!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=a)}}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
254
+ `,n=2;else{let i=BigInt(s);n=Number((i%256n+256n)%256n)}}throw new q(n,"",r)}function Da(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 u of l){let c=e.state.env.get(u);c!==void 0&&(a+=`declare -x ${u}=${mr(c)}
250
255
  `)}return Y(a)}if(n){for(let a of r){let o,l;if(a.includes("=")){let u=a.indexOf("=");o=a.slice(0,u),l=a.slice(u+1)}else o=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o))return L("",`bash: export: \`${a}': not a valid identifier
251
- `,1);l!==void 0&&(ue(e,o),e.state.env.set(o,l)),Vr(e,o)}return ee}let s="",i=0;for(let a of r){let o,l,u=!1,c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c)o=c[1],l=c[2],u=!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
252
- `,i=1;continue}if(l!==void 0)if(ue(e,o),u){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,"");dt(e,o)}return L("",s,i)}function bs(e,t){if(t.length<2)return I(`bash: getopts: usage: getopts optstring name [arg ...]
253
- `);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 u=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 c=o[l-1];if(!c||c==="-"||!c.startsWith("-"))return s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};if(c==="--")return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};let f=u===0?1:u,d=c[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),bs(e,t);let p=a.indexOf(d);if(p===-1){let m="";return i?e.state.env.set("OPTARG",d):m=`bash: illegal option -- ${d}
256
+ `,1);l!==void 0&&(ue(e,o),e.state.env.set(o,l)),Zr(e,o)}return J}let s="",i=0;for(let a of r){let o,l,u=!1,c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c)o=c[1],l=c[2],u=!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
257
+ `,i=1;continue}if(l!==void 0)if(ue(e,o),u){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,"");gt(e,o)}return L("",s,i)}function Cs(e,t){if(t.length<2)return _(`bash: getopts: usage: getopts optstring name [arg ...]
258
+ `);let n=t[0],r=t[1],s=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r),i=n.startsWith(":"),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 u=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 c=o[l-1];if(!c||c==="-"||!c.startsWith("-"))return s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};if(c==="--")return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};let f=u===0?1:u,d=c[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),Cs(e,t);let p=a.indexOf(d);if(p===-1){let m="";return i?e.state.env.set("OPTARG",d):m=`bash: illegal option -- ${d}
254
259
  `,s||e.state.env.set(r,"?"),f+1<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0")),{exitCode:s?2:0,stdout:"",stderr:m}}if(p+1<a.length&&a[p+1]===":")if(f+1<c.length)e.state.env.set("OPTARG",c.slice(f+1)),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0");else{if(l>=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}
255
- `,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<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return s||e.state.env.set(r,d),{exitCode:s?2:0,stdout:"",stderr:""}}async function va(e,t){e.state.hashTable||(e.state.hashTable=new Map);let n=!1,r=!1,s=!1,i=!1,a=!1,o="",l=[],u=0;for(;u<t.length;){let h=t[u];if(h==="--"){u++,l.push(...t.slice(u));break}if(h==="-r")n=!0,u++;else if(h==="-d")r=!0,u++;else if(h==="-l")s=!0,u++;else if(h==="-t")a=!0,u++;else if(h==="-p"){if(i=!0,u++,u>=t.length)return I(`bash: hash: -p: option requires an argument
256
- `,1);o=t[u],u++}else if(h.startsWith("-")&&h.length>1){for(let m of h.slice(1))if(m==="r")n=!0;else if(m==="d")r=!0;else if(m==="l")s=!0;else if(m==="t")a=!0;else return m==="p"?I(`bash: hash: -p: option requires an argument
257
- `,1):I(`bash: hash: -${m}: invalid option
258
- `,1);u++}else l.push(h),u++}if(n)return e.state.hashTable.clear(),ee;if(r){if(l.length===0)return I(`bash: hash: -d: option requires an argument
260
+ `,s||e.state.env.set(r,"?")),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:0,stdout:"",stderr:m}}e.state.env.set("OPTARG",o[l]),e.state.env.set("OPTIND",String(l+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return s||e.state.env.set(r,d),{exitCode:s?2:0,stdout:"",stderr:""}}async function Ia(e,t){e.state.hashTable||(e.state.hashTable=new Map);let n=!1,r=!1,s=!1,i=!1,a=!1,o="",l=[],u=0;for(;u<t.length;){let h=t[u];if(h==="--"){u++,l.push(...t.slice(u));break}if(h==="-r")n=!0,u++;else if(h==="-d")r=!0,u++;else if(h==="-l")s=!0,u++;else if(h==="-t")a=!0,u++;else if(h==="-p"){if(i=!0,u++,u>=t.length)return _(`bash: hash: -p: option requires an argument
261
+ `,1);o=t[u],u++}else if(h.startsWith("-")&&h.length>1){for(let m of h.slice(1))if(m==="r")n=!0;else if(m==="d")r=!0;else if(m==="l")s=!0;else if(m==="t")a=!0;else return m==="p"?_(`bash: hash: -p: option requires an argument
262
+ `,1):_(`bash: hash: -${m}: invalid option
263
+ `,1);u++}else l.push(h),u++}if(n)return e.state.hashTable.clear(),J;if(r){if(l.length===0)return _(`bash: hash: -d: option requires an argument
259
264
  `,1);let h=!1,m="";for(let E of l)e.state.hashTable.has(E)?e.state.hashTable.delete(E):(m+=`bash: hash: ${E}: not found
260
- `,h=!0);return h?I(m,1):ee}if(a){if(l.length===0)return I(`bash: hash: -t: option requires an argument
261
- `,1);let h="",m=!1,E="";for(let b of l){let g=e.state.hashTable.get(b);g?l.length>1?h+=`${b} ${g}
262
- `:h+=`${g}
263
- `:(E+=`bash: hash: ${b}: not found
264
- `,m=!0)}return m?{exitCode:1,stdout:h,stderr:E}:Y(h)}if(i){if(l.length===0)return I(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
265
- `,1);let h=l[0];return e.state.hashTable.set(h,o),ee}if(l.length===0){if(e.state.hashTable.size===0)return Y(`hash: hash table empty
266
- `);let h="";if(s)for(let[m,E]of e.state.hashTable){let b=m.startsWith("-")?" --":"";h+=`builtin hash -p ${Ee(E)}${b} ${Ee(m)}
265
+ `,h=!0);return h?_(m,1):J}if(a){if(l.length===0)return _(`bash: hash: -t: option requires an argument
266
+ `,1);let h="",m=!1,E="";for(let S of l){let y=e.state.hashTable.get(S);y?l.length>1?h+=`${S} ${y}
267
+ `:h+=`${y}
268
+ `:(E+=`bash: hash: ${S}: not found
269
+ `,m=!0)}return m?{exitCode:1,stdout:h,stderr:E}:Y(h)}if(i){if(l.length===0)return _(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
270
+ `,1);let h=l[0];return e.state.hashTable.set(h,o),J}if(l.length===0){if(e.state.hashTable.size===0)return Y(`hash: hash table empty
271
+ `);let h="";if(s)for(let[m,E]of e.state.hashTable){let S=m.startsWith("-")?" --":"";h+=`builtin hash -p ${Ee(E)}${S} ${Ee(m)}
267
272
  `}else{h=`hits command
268
273
  `;for(let[,m]of e.state.hashTable)h+=` 1 ${m}
269
274
  `}return Y(h)}let c=!1,f="",p=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let h of l){if(h.includes("/")){f+=`bash: hash: ${h}: cannot use / in name
270
- `,c=!0;continue}let m=!1;for(let E of p){if(!E)continue;let b=`${E}/${h}`;if(await e.fs.exists(b)){e.state.hashTable.set(h,b),m=!0;break}}m||(f+=`bash: hash: ${h}: not found
271
- `,c=!0)}return c?I(f,1):ee}var xc=new Map([[":",[": [arguments]",`Null command.
275
+ `,c=!0;continue}let m=!1;for(let E of p){if(!E)continue;let S=`${E}/${h}`;if(await e.fs.exists(S)){e.state.hashTable.set(h,S),m=!0;break}}m||(f+=`bash: hash: ${h}: not found
276
+ `,c=!0)}return c?_(f,1):J}var Tc=new Map([[":",[": [arguments]",`Null command.
272
277
  No effect; the command does nothing.
273
278
  Exit Status:
274
279
  Always succeeds.`]],[".",[". filename [arguments]",`Execute commands from a file in the current shell.
@@ -613,37 +618,37 @@ eval: usage: eval [arg ...]
613
618
  job specification, and reports its termination status.
614
619
  Exit Status:
615
620
  Returns the status of the last ID; fails if ID is invalid or an invalid
616
- option is given.`]]]),kc=[...xc.keys()].sort();function $a(e,t){let n=!1,r=[],s=0;for(;s<t.length;){let l=t[s];if(l==="--"){for(s++;s<t.length;)r.push(t[s]),s++;break}if(l.startsWith("-")&&l.length>1){for(let u=1;u<l.length;u++){let c=l[u];if(c==="s")n=!0;else return I(`bash: help: -${c}: invalid option
617
- `,2)}s++}else r.push(l),s++}if(r.length===0)return Ch();let i="",a=!1,o="";for(let l of r){let u=Ph(l);if(u.length===0){o+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
618
- `,a=!0;continue}for(let c of u){let f=xc.get(c);if(!f)continue;let[d,p]=f;n?i+=`${c}: ${d}
621
+ option is given.`]]]),Mc=[...Tc.keys()].sort();function Oa(e,t){let n=!1,r=[],s=0;for(;s<t.length;){let l=t[s];if(l==="--"){for(s++;s<t.length;)r.push(t[s]),s++;break}if(l.startsWith("-")&&l.length>1){for(let u=1;u<l.length;u++){let c=l[u];if(c==="s")n=!0;else return _(`bash: help: -${c}: invalid option
622
+ `,2)}s++}else r.push(l),s++}if(r.length===0)return Fh();let i="",a=!1,o="";for(let l of r){let u=Mh(l);if(u.length===0){o+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
623
+ `,a=!0;continue}for(let c of u){let f=Tc.get(c);if(!f)continue;let[d,p]=f;n?i+=`${c}: ${d}
619
624
  `:i+=`${c}: ${d}
620
625
  ${p}
621
- `}}return{exitCode:a?1:0,stdout:i,stderr:o}}function Ph(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),n=me(`^${t}$`);return kc.filter(r=>n.test(r))}function Ch(){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=kc.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(`
626
+ `}}return{exitCode:a?1:0,stdout:i,stderr:o}}function Mh(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),n=me(`^${t}$`);return Mc.filter(r=>n.test(r))}function Fh(){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=Mc.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(`
622
627
  `)}
623
- `)}function Nh(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 xa(e,t){if(t.length===0)return I(`bash: let: expression expected
624
- `);let n=Nh(t),r=0;for(let s of n)try{let a=lt(`(( ${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 I(`bash: let: ${s}: ${i.message}
625
- `)}return L("","",r===0?1:0)}async function ka(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength};if(e.state.localScopes.length===0)return I(`bash: local: can only be used in a function
626
- `);let r=e.state.localScopes[e.state.localScopes.length-1];for(e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let s=e.state.localArrayScopes.at(-1),i=d=>{if(r.has(d)||r.set(d,e.state.env.get(d)),s&&!s.has(d)){let p=ve(e,d);s.set(d,p?Le(p):void 0)}},a="",o=0,l=!1,u=!1,c=!1,f=[];for(let d of t)if(d==="-n")l=!0;else if(d==="-a")u=!0;else if(d==="-p")c=!0;else if(d.startsWith("-")&&!d.includes("="))for(let p of d.slice(1))p==="n"?l=!0:p==="a"?u=!0:p==="p"&&(c=!0);else f.push(d);if(f.length===0){let d="",p=Array.from(r.keys()).sort();for(let h of p){let m=e.state.env.get(h);m!==void 0&&(d+=`${h}=${m}
627
- `)}return L(d,"",0)}for(let d of f){let p,h,m=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(m){p=m[1];let S=m[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(p)){a+=`bash: local: \`${d}': not a valid identifier
628
- `,o=1;continue}ue(e,p,"bash");let v=Pt(S,n);e.executionScope.consumeWork(v.length,"local array assignment"),i(p),ye(e,p),Lt(e,p,"indexed");for(let $=0;$<v.length;$++)j(e,p,$,v[$]);Gt(e,p),l&&kt(e,p);continue}let E=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(E){p=E[1];let S=E[2];ue(e,p,"bash"),i(p);let v=Pt(S,n);e.executionScope.consumeWork(v.length,"local array append");let $=be(e,p),A=0,C=e.state.env.get(p);$.length===0&&C!==void 0?(j(e,p,0,C),e.state.env.delete(p),A=1):$.length>0&&(A=Math.max(...$)+1),rn(e,p,Array.from({length:v.length},(N,x)=>A+x));for(let N=0;N<v.length;N++)j(e,p,A+N,v[N]);Gt(e,p),l&&kt(e,p);continue}let b=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(b){p=b[1];let S=b[2];ue(e,p,"bash"),r.has(p)||r.set(p,e.state.env.get(p));let v=e.state.env.get(p)??"";e.state.env.set(p,Dt([v,S],"",e.limits.maxStringLength,"local append")),Gt(e,p),l&&kt(e,p);continue}let g=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(g){p=g[1];let S=g[2],v=g[3];ue(e,p,"bash"),i(p);let $;try{let A=new G,C=te(A,S);$=await K(e,C.expression)}catch{let A=parseInt(S,10);$=Number.isNaN(A)?0:A}j(e,p,$,v),Gt(e,p),l&&kt(e,p);continue}if(d.includes("=")){let S=d.indexOf("=");p=d.slice(0,S),h=d.slice(S+1)}else p=d;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(p)){a+=`bash: local: \`${d}': not a valid identifier
629
- `,o=1;continue}let y=r.has(p);if(h!==void 0){let S=e.state.env.get(p);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(p),$=e.state.mutatedTempEnvVars?.has(p);if(!v&&!$)for(let A=e.state.tempEnvBindings.length-1;A>=0;A--){let C=e.state.tempEnvBindings[A];if(C.has(p)){S=C.get(p);break}}}tc(e,p,S)}if(!y){let S=e.state.env.get(p);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let $=e.state.tempEnvBindings[v];if($.has(p)){S=$.get(p);break}}r.set(p,S),u&&i(p)}if(u&&h===void 0)ye(e,p),Lt(e,p,"indexed");else if(h!==void 0){if(ue(e,p,"bash"),l&&h!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(h)){a+=`bash: local: \`${h}': invalid variable name for name reference
630
- `,o=1;continue}e.state.env.set(p,h),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(p))}else{let S=e.state.tempEnvBindings?.some(v=>v.has(p));!y&&!S&&e.state.env.delete(p)}Gt(e,p),l&&kt(e,p)}return L("",a,o)}function Pa(e,t,n){let r=`
631
- `,s=0,i=0,a=0,o=!1,l="MAPFILE",u=0;for(;u<t.length;){let g=t[u];g==="-d"&&u+1<t.length?(r=t[u+1]===""?"\0":t[u+1]||`
632
- `,u+=2):g==="-n"&&u+1<t.length?(s=Number.parseInt(t[u+1],10)||0,u+=2):g==="-O"&&u+1<t.length?(i=Number.parseInt(t[u+1],10)||0,u+=2):g==="-s"&&u+1<t.length?(a=Number.parseInt(t[u+1],10)||0,u+=2):g==="-t"?(o=!0,u++):g==="-u"||g==="-C"||g==="-c"?u+=2:(g.startsWith("-")||(l=g),u++)}if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l))return L("",`mapfile: ${l}: not a valid identifier
628
+ `)}function Bh(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 _a(e,t){if(t.length===0)return _(`bash: let: expression expected
629
+ `);let n=Bh(t),r=0;for(let s of n)try{let a=pt(`(( ${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 X(e,o.expression.expression))}}catch(i){return _(`bash: let: ${s}: ${i.message}
630
+ `)}return L("","",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 _(`bash: local: can only be used in a function
631
+ `);let r=e.state.localScopes[e.state.localScopes.length-1];for(e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let s=e.state.localArrayScopes.at(-1),i=d=>{if(r.has(d)||r.set(d,e.state.env.get(d)),s&&!s.has(d)){let p=ve(e,d);s.set(d,p?Te(p):void 0)}},a="",o=0,l=!1,u=!1,c=!1,f=[];for(let d of t)if(d==="-n")l=!0;else if(d==="-a")u=!0;else if(d==="-p")c=!0;else if(d.startsWith("-")&&!d.includes("="))for(let p of d.slice(1))p==="n"?l=!0:p==="a"?u=!0:p==="p"&&(c=!0);else f.push(d);if(f.length===0){let d="",p=Array.from(r.keys()).sort();for(let h of p){let m=e.state.env.get(h);m!==void 0&&(d+=`${h}=${m}
632
+ `)}return L(d,"",0)}for(let d of f){let p,h,m=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(m){p=m[1];let b=m[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(p)){a+=`bash: local: \`${d}': not a valid identifier
633
+ `,o=1;continue}ue(e,p,"bash");let v=_t(b,n);e.executionScope.consumeWork(v.length,"local array assignment"),i(p),ye(e,p),zt(e,p,"indexed");for(let $=0;$<v.length;$++)U(e,p,$,v[$]);tn(e,p),l&&Ot(e,p);continue}let E=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(E){p=E[1];let b=E[2];ue(e,p,"bash"),i(p);let v=_t(b,n);e.executionScope.consumeWork(v.length,"local array append");let $=be(e,p),A=0,k=e.state.env.get(p);$.length===0&&k!==void 0?(U(e,p,0,k),e.state.env.delete(p),A=1):$.length>0&&(A=Math.max(...$)+1),pn(e,p,Array.from({length:v.length},(N,x)=>A+x));for(let N=0;N<v.length;N++)U(e,p,A+N,v[N]);tn(e,p),l&&Ot(e,p);continue}let S=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(S){p=S[1];let b=S[2];ue(e,p,"bash"),r.has(p)||r.set(p,e.state.env.get(p));let v=e.state.env.get(p)??"";e.state.env.set(p,Ft([v,b],"",e.limits.maxStringLength,"local append")),tn(e,p),l&&Ot(e,p);continue}let y=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(y){p=y[1];let b=y[2],v=y[3];ue(e,p,"bash"),i(p);let $;try{let A=new j,k=te(A,b);$=await X(e,k.expression)}catch{let A=parseInt(b,10);$=Number.isNaN(A)?0:A}U(e,p,$,v),tn(e,p),l&&Ot(e,p);continue}if(d.includes("=")){let b=d.indexOf("=");p=d.slice(0,b),h=d.slice(b+1)}else p=d;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(p)){a+=`bash: local: \`${d}': not a valid identifier
634
+ `,o=1;continue}let g=r.has(p);if(h!==void 0){let b=e.state.env.get(p);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(p),$=e.state.mutatedTempEnvVars?.has(p);if(!v&&!$)for(let A=e.state.tempEnvBindings.length-1;A>=0;A--){let k=e.state.tempEnvBindings[A];if(k.has(p)){b=k.get(p);break}}}dc(e,p,b)}if(!g){let b=e.state.env.get(p);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let $=e.state.tempEnvBindings[v];if($.has(p)){b=$.get(p);break}}r.set(p,b),u&&i(p)}if(u&&h===void 0)ye(e,p),zt(e,p,"indexed");else if(h!==void 0){if(ue(e,p,"bash"),l&&h!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(h)){a+=`bash: local: \`${h}': invalid variable name for name reference
635
+ `,o=1;continue}e.state.env.set(p,h),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(p))}else{let b=e.state.tempEnvBindings?.some(v=>v.has(p));!g&&!b&&e.state.env.delete(p)}tn(e,p),l&&Ot(e,p)}return L("",a,o)}function Ta(e,t,n){let r=`
636
+ `,s=0,i=0,a=0,o=!1,l="MAPFILE",u=0;for(;u<t.length;){let y=t[u];y==="-d"&&u+1<t.length?(r=t[u+1]===""?"\0":t[u+1]||`
637
+ `,u+=2):y==="-n"&&u+1<t.length?(s=Number.parseInt(t[u+1],10)||0,u+=2):y==="-O"&&u+1<t.length?(i=Number.parseInt(t[u+1],10)||0,u+=2):y==="-s"&&u+1<t.length?(a=Number.parseInt(t[u+1],10)||0,u+=2):y==="-t"?(o=!0,u++):y==="-u"||y==="-C"||y==="-c"?u+=2:(y.startsWith("-")||(l=y),u++)}if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l))return L("",`mapfile: ${l}: not a valid identifier
633
638
  `,1);if(!Number.isSafeInteger(i)||i<0)return L("",`mapfile: invalid array origin
634
- `,1);ue(e,l,"mapfile");let c=n;!c&&e.state.groupStdin!==void 0&&(c=e.state.groupStdin);let f=[],d=0,p=0,h=0,m=e.limits.maxArrayElements,E=g=>{if(F(g)>e.limits.maxStringLength)throw new k(`mapfile: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");f.push(g)};for(;d<c.length;){e.executionScope.consumeWork(1,"mapfile input");let g=c.indexOf(r,d);if(g===-1){if(d<c.length){if(h<a)h++;else if(s===0||p<s){let v=c.slice(d),$=v.indexOf("\0");if($!==-1&&(v=v.substring(0,$)),f.length>=m)return L("",`mapfile: array element limit exceeded (${m})
635
- `,1);E(v),p++}}break}let y=c.slice(d,g),S=y.indexOf("\0");if(S!==-1&&(y=y.substring(0,S)),!o&&r!=="\0"&&(y+=r),d=g+r.length,h<a){h++;continue}if(s>0&&p>=s)break;if(f.length>=m)return L("",`mapfile: array element limit exceeded (${m})
636
- `,1);E(y),p++}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 L("",`mapfile: array element limit exceeded (${m})
637
- `,1);i===0&&ye(e,l);for(let g=0;g<f.length;g++)j(e,l,i+g,f[g]);return e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=""),{...L("","",0),internalStdinConsumed:c.length}}function Ca(e,t,n,r=-1){let s=!1,i=`
638
- `,a="",o=-1,l=-1,u=null,c=-1,f=-1,d=[],p=0,h=!1,m=(O,_)=>{let M=1;for(;M<O.length;){let se=O[M];if(se==="r")s=!0,M++;else if(se==="s")M++;else{if(se==="d")return M+1<O.length?(i=O.substring(M+1),{nextArgIndex:_+1}):_+1<t.length?(i=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(se==="n"){if(M+1<O.length){let ie=O.substring(M+1);return o=Number.parseInt(ie,10),(Number.isNaN(o)||o<0)&&(h=!0,o=0),{nextArgIndex:_+1}}else if(_+1<t.length)return o=Number.parseInt(t[_+1],10),(Number.isNaN(o)||o<0)&&(h=!0,o=0),{nextArgIndex:_+2};return{nextArgIndex:_+1}}else if(se==="N"){if(M+1<O.length){let ie=O.substring(M+1);return l=Number.parseInt(ie,10),(Number.isNaN(l)||l<0)&&(h=!0,l=0),{nextArgIndex:_+1}}else if(_+1<t.length)return l=Number.parseInt(t[_+1],10),(Number.isNaN(l)||l<0)&&(h=!0,l=0),{nextArgIndex:_+2};return{nextArgIndex:_+1}}else{if(se==="a")return M+1<O.length?(u=O.substring(M+1),{nextArgIndex:_+1}):_+1<t.length?(u=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(se==="p")return M+1<O.length?(a=O.substring(M+1),{nextArgIndex:_+1}):_+1<t.length?(a=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(se==="u"){if(M+1<O.length){let ie=O.substring(M+1);return c=Number.parseInt(ie,10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:_+1}}else if(_+1<t.length)return c=Number.parseInt(t[_+1],10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:_+2};return{nextArgIndex:_+1}}else if(se==="t"){if(M+1<O.length){let ie=O.substring(M+1);return f=Number.parseFloat(ie),Number.isNaN(f)&&(f=0),{nextArgIndex:_+1}}else if(_+1<t.length)return f=Number.parseFloat(t[_+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:_+2};return{nextArgIndex:_+1}}else if(se==="e"||se==="i"||se==="P"){if(se==="i"&&_+1<t.length)return{nextArgIndex:_+2};M++}else M++}}}return{nextArgIndex:_+1}};for(;p<t.length;){let O=t[p];if(O.startsWith("-")&&O.length>1&&O!=="--"){let _=m(O,p);if(_.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(_.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};p=_.nextArgIndex}else if(O==="--")for(p++;p<t.length;)d.push(t[p]),p++;else d.push(O),p++}if(h)return L("","",1);d.length===0&&u===null&&d.push("REPLY");let E=new Set;u&&E.add(u);for(let O of d)E.add(O);l>=0&&d.length===0&&E.add("REPLY");for(let O of E){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(O))return L("",`bash: read: \`${O}': not a valid identifier
639
- `,1);ue(e,O,"bash")}if(f===0){if(u)ye(e,u);else{for(let O of d)e.state.env.set(O,"");d.length===0&&e.state.env.set("REPLY","")}return L("","",0)}if(f<0&&f!==-1)return L("","",1);let b=n,g=Ye(e,c),y=c>0&&!(g?.kind==="dup-in"&&g.sourceFd===0);if(y){let O=hs(e,c);if("error"in O){let M=O.error==="write-only"||c===1||c===2?`bash: read: read error: ${c}: Bad file descriptor
639
+ `,1);ue(e,l,"mapfile");let c=n;!c&&e.state.groupStdin!==void 0&&(c=e.state.groupStdin);let f=[],d=0,p=0,h=0,m=e.limits.maxArrayElements,E=y=>{if(M(y)>e.limits.maxStringLength)throw new P(`mapfile: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");f.push(y)};for(;d<c.length;){e.executionScope.consumeWork(1,"mapfile input");let y=c.indexOf(r,d);if(y===-1){if(d<c.length){if(h<a)h++;else if(s===0||p<s){let v=c.slice(d),$=v.indexOf("\0");if($!==-1&&(v=v.substring(0,$)),f.length>=m)return L("",`mapfile: array element limit exceeded (${m})
640
+ `,1);E(v),p++}}break}let g=c.slice(d,y),b=g.indexOf("\0");if(b!==-1&&(g=g.substring(0,b)),!o&&r!=="\0"&&(g+=r),d=y+r.length,h<a){h++;continue}if(s>0&&p>=s)break;if(f.length>=m)return L("",`mapfile: array element limit exceeded (${m})
641
+ `,1);E(g),p++}let S=new Set(i===0?[]:e.state.arrays?.get(l)?.elements.keys()??[]);for(let y=0;y<f.length;y++)if(S.add(String(i+y)),S.size>m)return L("",`mapfile: array element limit exceeded (${m})
642
+ `,1);i===0&&ye(e,l);for(let y=0;y<f.length;y++)U(e,l,i+y,f[y]);return e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=""),{...L("","",0),internalStdinConsumed:c.length}}function Ma(e,t,n,r=-1){let s=!1,i=`
643
+ `,a="",o=-1,l=-1,u=null,c=-1,f=-1,d=[],p=0,h=!1,m=(I,O)=>{let F=1;for(;F<I.length;){let ee=I[F];if(ee==="r")s=!0,F++;else if(ee==="s")F++;else{if(ee==="d")return F+1<I.length?(i=I.substring(F+1),{nextArgIndex:O+1}):O+1<t.length?(i=t[O+1],{nextArgIndex:O+2}):{nextArgIndex:O+1};if(ee==="n"){if(F+1<I.length){let K=I.substring(F+1);return o=Number.parseInt(K,10),(Number.isNaN(o)||o<0)&&(h=!0,o=0),{nextArgIndex:O+1}}else if(O+1<t.length)return o=Number.parseInt(t[O+1],10),(Number.isNaN(o)||o<0)&&(h=!0,o=0),{nextArgIndex:O+2};return{nextArgIndex:O+1}}else if(ee==="N"){if(F+1<I.length){let K=I.substring(F+1);return l=Number.parseInt(K,10),(Number.isNaN(l)||l<0)&&(h=!0,l=0),{nextArgIndex:O+1}}else if(O+1<t.length)return l=Number.parseInt(t[O+1],10),(Number.isNaN(l)||l<0)&&(h=!0,l=0),{nextArgIndex:O+2};return{nextArgIndex:O+1}}else{if(ee==="a")return F+1<I.length?(u=I.substring(F+1),{nextArgIndex:O+1}):O+1<t.length?(u=t[O+1],{nextArgIndex:O+2}):{nextArgIndex:O+1};if(ee==="p")return F+1<I.length?(a=I.substring(F+1),{nextArgIndex:O+1}):O+1<t.length?(a=t[O+1],{nextArgIndex:O+2}):{nextArgIndex:O+1};if(ee==="u"){if(F+1<I.length){let K=I.substring(F+1);return c=Number.parseInt(K,10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:O+1}}else if(O+1<t.length)return c=Number.parseInt(t[O+1],10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:O+2};return{nextArgIndex:O+1}}else if(ee==="t"){if(F+1<I.length){let K=I.substring(F+1);return f=Number.parseFloat(K),Number.isNaN(f)&&(f=0),{nextArgIndex:O+1}}else if(O+1<t.length)return f=Number.parseFloat(t[O+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:O+2};return{nextArgIndex:O+1}}else if(ee==="e"||ee==="i"||ee==="P"){if(ee==="i"&&O+1<t.length)return{nextArgIndex:O+2};F++}else F++}}}return{nextArgIndex:O+1}};for(;p<t.length;){let I=t[p];if(I.startsWith("-")&&I.length>1&&I!=="--"){let O=m(I,p);if(O.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(O.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};p=O.nextArgIndex}else if(I==="--")for(p++;p<t.length;)d.push(t[p]),p++;else d.push(I),p++}if(h)return L("","",1);d.length===0&&u===null&&d.push("REPLY");let E=new Set;u&&E.add(u);for(let I of d)E.add(I);l>=0&&d.length===0&&E.add("REPLY");for(let I of E){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(I))return L("",`bash: read: \`${I}': not a valid identifier
644
+ `,1);ue(e,I,"bash")}if(f===0){if(u)ye(e,u);else{for(let I of d)e.state.env.set(I,"");d.length===0&&e.state.env.set("REPLY","")}return L("","",0)}if(f<0&&f!==-1)return L("","",1);let S=n,y=Je(e,c),g=c>0&&!(y?.kind==="dup-in"&&y.sourceFd===0);if(g){let I=As(e,c);if("error"in I){let F=I.error==="write-only"||c===1||c===2?`bash: read: read error: ${c}: Bad file descriptor
640
645
  `:`bash: read: ${c}: invalid file descriptor: Bad file descriptor
641
- `;return L("",M,1)}b=O.content}else!b&&e.state.groupStdin!==void 0&&(b=e.state.groupStdin);let S=i===""?"\0":i,v="",$=0,A=O=>{let _=F(O);if(_>e.limits.maxStringLength-$)throw new k(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");v+=O,$+=_},C=O=>{if(F(O)>e.limits.maxStringLength)throw new k(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")},N=0,x=!0,P=O=>{y?Ht(e,c,O):r>=0?Ht(e,r,O):e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=b.substring(O),e.state.groupStdinSourceFd!==void 0&&Ht(e,e.state.groupStdinSourceFd,O))};if(l>=0){let O=Math.min(l,b.length);v=b.substring(0,O),C(v),N=O,x=O>=l,P(N);let _=d[0]||"REPLY";e.state.env.set(_,v);for(let M=1;M<d.length;M++)e.state.env.set(d[M],"");return L("","",x?0:1)}else if(o>=0){let O=0,_=0,M=!1;for(;_<b.length&&O<o;){let se=b[_];if(se===S){N=_+1,M=!0;break}if(!s&&se==="\\"&&_+1<b.length){let ie=b[_+1];if(ie===S&&S===`
642
- `){_+=2,N=_;continue}if(ie===S){_+=2,O++,A(ie),N=_;continue}A(ie),_+=2,O++,N=_}else A(se),_++,O++,N=_}x=O>=o||M,P(N)}else{N=0;let O=0;for(;O<b.length;){let _=b[O];if(_===S){N=O+S.length,x=!0;break}if(!s&&_==="\\"&&O+1<b.length){let M=b[O+1];if(M===`
643
- `){O+=2;continue}if(M===S){A(M),O+=2;continue}A(_),A(M),O+=2;continue}A(_),O++}if(O>=b.length&&(x=!1,N=O,v.length===0&&b.length===0)){for(let _ of d)e.state.env.set(_,"");return u&&ye(e,u),L("","",1)}P(N)}S===`
646
+ `;return L("",F,1)}S=I.content}else!S&&e.state.groupStdin!==void 0&&(S=e.state.groupStdin);let b=i===""?"\0":i,v="",$=0,A=I=>{let O=M(I);if(O>e.limits.maxStringLength-$)throw new P(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");v+=I,$+=O},k=I=>{if(M(I)>e.limits.maxStringLength)throw new P(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")},N=0,x=!0,C=I=>{g?rn(e,c,I):r>=0?rn(e,r,I):e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=S.substring(I),e.state.groupStdinSourceFd!==void 0&&rn(e,e.state.groupStdinSourceFd,I))};if(l>=0){let I=Math.min(l,S.length);v=S.substring(0,I),k(v),N=I,x=I>=l,C(N);let O=d[0]||"REPLY";e.state.env.set(O,v);for(let F=1;F<d.length;F++)e.state.env.set(d[F],"");return L("","",x?0:1)}else if(o>=0){let I=0,O=0,F=!1;for(;O<S.length&&I<o;){let ee=S[O];if(ee===b){N=O+1,F=!0;break}if(!s&&ee==="\\"&&O+1<S.length){let K=S[O+1];if(K===b&&b===`
647
+ `){O+=2,N=O;continue}if(K===b){O+=2,I++,A(K),N=O;continue}A(K),O+=2,I++,N=O}else A(ee),O++,I++,N=O}x=I>=o||F,C(N)}else{N=0;let I=0;for(;I<S.length;){let O=S[I];if(O===b){N=I+b.length,x=!0;break}if(!s&&O==="\\"&&I+1<S.length){let F=S[I+1];if(F===`
648
+ `){I+=2;continue}if(F===b){A(F),I+=2;continue}A(O),A(F),I+=2;continue}A(O),I++}if(I>=S.length&&(x=!1,N=I,v.length===0&&S.length===0)){for(let O of d)e.state.env.set(O,"");return u&&ye(e,u),L("","",1)}C(N)}b===`
644
649
  `&&v.endsWith(`
645
- `)&&(v=v.slice(0,-1));let R=O=>s?O:O.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",R(v)),L("","",x?0:1);let B=Ae(e.state.env),q=e.limits.maxArrayElements;if(u){let{words:O}=wi(v,B,q,void 0,s);ye(e,u);for(let _=0;_<O.length;_++)j(e,u,_,R(O[_]));return L("","",x?0:1)}let D=d.length,{words:W,wordStarts:V}=wi(v,B,q,D,s);for(let O=0;O<d.length;O++){let _=d[O];if(O<d.length-1)e.state.env.set(_,R(W[O]??""));else if(O<V.length){let M=v.substring(V[O]);M=bl(M,B,s),M=R(M),e.state.env.set(_,M)}else e.state.env.set(_,"")}return L("","",x?0:1)}function Na(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return I("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 I(`bash: return: ${r}: numeric argument required
646
- `,2);n=(s%256+256)%256}throw new Ie(n)}var fr=`set: usage: set [-eux] [+eux] [-o option] [+o option]
650
+ `)&&(v=v.slice(0,-1));let D=I=>s?I:I.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",D(v)),L("","",x?0:1);let B=Ae(e.state.env),H=e.limits.maxArrayElements;if(u){let{words:I}=xi(v,B,H,void 0,s);ye(e,u);for(let O=0;O<I.length;O++)U(e,u,O,D(I[O]));return L("","",x?0:1)}let R=d.length,{words:W,wordStarts:V}=xi(v,B,H,R,s);for(let I=0;I<d.length;I++){let O=d[I];if(I<d.length-1)e.state.env.set(O,D(W[I]??""));else if(I<V.length){let F=v.substring(V[I]);F=Il(F,B,s),F=D(F),e.state.env.set(O,F)}else e.state.env.set(O,"")}return L("","",x?0:1)}function Fa(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return _("bash: return: can only `return' from a function or sourced script\n");let n=e.state.lastExitCode;if(t.length>0){let r=t[0],s=Number.parseInt(r,10);if(r===""||Number.isNaN(s)||!/^-?\d+$/.test(r))return _(`bash: return: ${r}: numeric argument required
651
+ `,2);n=(s%256+256)%256}throw new Oe(n)}var wr=`set: usage: set [-eux] [+eux] [-o option] [+o option]
647
652
  Options:
648
653
  -e Exit immediately if a command exits with non-zero status
649
654
  +e Disable -e
@@ -659,78 +664,78 @@ Options:
659
664
  +o pipefail Disable pipefail
660
665
  -o xtrace Same as -x
661
666
  +o xtrace Disable xtrace
662
- `,Pc=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]]),Ss=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]]),Rc=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],Dc=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Ra(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,kn(e))}function Rh(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Dh(e,t,n){let r=be(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],a=ae(e,n,i)??"";s>0&&t.append(" "),t.append(`[${i}]=`),t.reserve(ws(a)),t.append(Xt(a))}t.append(")")}function Ih(e,t){if(/^[a-zA-Z0-9_]+$/.test(t)){e.append(t);return}e.reserve(ws(t)),e.append(Xt(t))}function Oh(e,t,n){let r=gt(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("["),Ih(t,i),t.append("]="),t.reserve(ws(a)),t.append(Xt(a))}t.append(" )")}function _h(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 Lh(e){return e.state.associativeArrays??new Set}function Cc(e){let t=Rc.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),n=Dc.map(r=>`${r.padEnd(16)}off`);return`${[...t,...n].sort().join(`
667
+ `,Fc=new Map([["e","errexit"],["u","nounset"],["x","xtrace"],["v","verbose"],["f","noglob"],["C","noclobber"],["a","allexport"],["n","noexec"],["h",null],["b",null],["m",null],["B",null],["H",null],["P",null],["T",null],["E",null],["p",null]]),Ns=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["noclobber","noclobber"],["noglob","noglob"],["allexport","allexport"],["noexec","noexec"],["posix","posix"],["vi","vi"],["emacs","emacs"],["notify",null],["monitor",null],["braceexpand",null],["histexpand",null],["physical",null],["functrace",null],["errtrace",null],["privileged",null],["hashall",null],["ignoreeof",null],["interactive-comments",null],["keyword",null],["onecmd",null]]),Vc=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],zc=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Ba(e,t,n){t!==null&&(n&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=n,_n(e))}function Wh(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Vh(e,t,n){let r=be(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],a=ie(e,n,i)??"";s>0&&t.append(" "),t.append(`[${i}]=`),t.reserve(ks(a)),t.append(on(a))}t.append(")")}function zh(e,t){if(/^[a-zA-Z0-9_]+$/.test(t)){e.append(t);return}e.reserve(ks(t)),e.append(on(t))}function qh(e,t,n){let r=vt(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=ie(e,n,i)??"";s>0&&t.append(" "),t.append("["),zh(t,i),t.append("]="),t.reserve(ks(a)),t.append(on(a))}t.append(" )")}function Uh(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 jh(e){return e.state.associativeArrays??new Set}function Bc(e){let t=Vc.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),n=zc.map(r=>`${r.padEnd(16)}off`);return`${[...t,...n].sort().join(`
663
668
  `)}
664
- `}function Nc(e){let t=Rc.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),n=Dc.map(r=>`set +o ${r}`);return`${[...t,...n].sort().join(`
669
+ `}function Wc(e){let t=Vc.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),n=zc.map(r=>`set +o ${r}`);return`${[...t,...n].sort().join(`
665
670
  `)}
666
- `}function Ia(e,t){if(t.includes("--help"))return Y(fr);if(t.length===0){let i=_h(e),a=Lh(e),o=[];for(let[c,f]of e.state.env)/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)&&(i.has(c)||a.has(c)||o.push([c,f]));let l=[...o.map(([c,f])=>({kind:"scalar",name:c,value:f})),...Array.from(i,c=>({kind:"indexed",name:c})),...Array.from(a,c=>({kind:"associative",name:c}))];l.sort((c,f)=>c.name<f.name?-1:c.name>f.name?1:0);let u=new gn(e.limits.maxOutputSize,"set");for(let c of l)e.executionScope.consumeWork(1,"set variable listing"),c.kind==="scalar"?(u.append(c.name).append("="),u.reserve(mc(c.value)),u.append(Ee(c.value))):c.kind==="indexed"?Dh(e,u,c.name):Oh(e,u,c.name),u.append(`
667
- `);return Y(u.build())}let n=[],r=()=>n.length>0?Y(n.join("")):ee,s=0;for(;s<t.length;){let i=t[s];if((i==="-o"||i==="+o")&&Rh(t,s)){let a=t[s+1];if(!Ss.has(a)){let o=`bash: set: ${a}: invalid option name
668
- ${fr}`;if(e.state.options.posix)throw new et(1,"",o);return I(o)}Ra(e,Ss.get(a)??null,i==="-o"),s+=2;continue}if(i==="-o"){n.push(Cc(e)),s++;continue}if(i==="+o"){n.push(Nc(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 u=i[l];if(u==="o"){let c=s+1+o;if(c<t.length&&!t[c].startsWith("-")&&!t[c].startsWith("+")){let d=t[c];if(!Ss.has(d)){let p=`bash: set: ${d}: invalid option name
669
- ${fr}`;if(e.state.options.posix)throw new et(1,"",p);return I(p)}Ra(e,Ss.get(d)??null,a),o++;continue}n.push(a?Cc(e):Nc(e));continue}if(!Pc.has(u)){let c=`bash: set: ${i[0]}${u}: invalid option
670
- ${fr}`;if(e.state.options.posix)throw new et(1,"",c);return I(c)}Ra(e,Pc.get(u)??null,a)}s+=1+o;continue}if(i==="--")return Da(e,t.slice(s+1)),r();if(i==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,kn(e),s+1<t.length)return Da(e,t.slice(s+1)),r();s++;continue}if(i==="+"){s++;continue}if(i.startsWith("-")||i.startsWith("+")){let a=`bash: set: ${i}: invalid option
671
- ${fr}`;if(e.state.options.posix)throw new et(1,"",a);return I(a)}return Da(e,t.slice(s)),r()}return r()}function Da(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 Oa(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
672
- `;if(e.state.options.posix)throw new et(1,"",o);return I(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
673
- `;if(e.state.options.posix)throw new et(1,"",a);return I(a)}if(n===0)return ee;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(" ")),ee}async function _a(e,t){let n=t;if(n.length>0&&n[0]==="--"&&(n=n.slice(1)),n.length===0)return L("",`bash: source: filename argument required
674
- `,2);let r=n[0],s=null,i=null;if(r.includes("/")){let u=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(u),s=u}catch{}}else{let c=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of c){let d=e.fs.resolvePath(e.state.cwd,`${f}/${r}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),s=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(f),s=f}catch{}}}if(i===null)return I(`bash: ${r}: No such file or directory
675
- `);let a=new Map;if(n.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=n.slice(1);e.state.env.set("#",String(u.length)),e.state.env.set("@",u.join(" "));for(let c=0;c<u.length&&c<9;c++)e.state.env.set(String(c+1),u[c]);for(let c=u.length+1;c<=9;c++)e.state.env.delete(String(c))}let o=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=o,n.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 k(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let u=lt(i),c=await e.executeScript(u);return l(),c}catch(u){if(l(),u instanceof U)throw u;if(u instanceof Ie)return L(u.stdout,u.stderr,u.exitCode);if(u.name==="ParseException")return I(`bash: ${r}: ${u.message}
676
- `);throw u}}function Ic(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Th(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function Oc(e,t){if(Th(t))return null;try{let n=new G,r=te(n,t);return await K(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}function _c(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)us(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),La(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),us(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||us(e,t),!0}}return!1}function La(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 Lc(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let n=t.slice(1,-1),s=new G().parseWordFromString(n,!0,!1);return ne(e,s)}if(t.includes("$")){let r=new G().parseWordFromString(t,!1,!1);return ne(e,r)}return t}async function Ta(e,t){let n="both",r="",s=0;for(let i of t){if(i==="-v"){n="variable";continue}if(i==="-f"){n="function";continue}if(n==="function"){e.state.functions.delete(i);continue}if(n==="variable"){let u=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(u){let d=u[1],p=u[2];if(Me(e,d)){r+=`bash: unset: ${d}: cannot unset: readonly variable
677
- `,s=1;continue}if(p==="@"||p==="*"){Zn(e,d),e.state.env.delete(d);continue}let h=e.state.associativeArrays?.has(d);if(h){let y=await Lc(e,p);sn(e,d,y);continue}let m=ct(e,d),E=e.state.declaredVars?.has(d);if((e.state.env.has(d)||E)&&!m&&!h){r+=`bash: unset: ${d}: not an array variable
678
- `,s=1;continue}let g=await Oc(e,p);if(g===null&&m){r+=`bash: unset: ${p}: not a valid identifier
679
- `,s=1;continue}if(g===null)continue;if(g<0){let y=Z(e,d),S=y.length,v=e.state.currentLine;if(S===0){r+=`bash: line ${v}: unset: [${g}]: bad array subscript
680
- `,s=1;continue}let $=S+g;if($<0){r+=`bash: line ${v}: unset: [${g}]: bad array subscript
681
- `,s=1;continue}let A=y[$][0];sn(e,d,A);continue}sn(e,d,g);continue}if(!Ic(i)){r+=`bash: unset: \`${i}': not a valid identifier
682
- `,s=1;continue}let c=i;if(le(e,i)){let d=Te(e,i);d&&d!==i&&(c=d)}if(Me(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable
683
- `,s=1;continue}Zn(e,c);let f=Bi(e,c);if(f!==void 0&&f!==e.state.callDepth)_c(e,c);else if(e.state.fullyUnsetLocals?.has(c))e.state.env.delete(c);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(c),p=e.state.mutatedTempEnvVars?.has(c);if((d||p)&&e.state.localVarStack?.has(c)){let h=cs(e,c);h?h.value===void 0?e.state.env.delete(c):e.state.env.set(c,h.value):e.state.env.delete(c)}else e.state.env.delete(c)}else La(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(Me(e,u)){r+=`bash: unset: ${u}: cannot unset: readonly variable
684
- `,s=1;continue}if(c==="@"||c==="*"){Zn(e,u),e.state.env.delete(u);continue}let f=e.state.associativeArrays?.has(u);if(f){let m=await Lc(e,c);sn(e,u,m);continue}let d=ct(e,u);if(e.state.env.has(u)&&!d&&!f){r+=`bash: unset: ${u}: not an array variable
685
- `,s=1;continue}let h=await Oc(e,c);if(h===null&&d){r+=`bash: unset: ${c}: not a valid identifier
686
- `,s=1;continue}if(h===null)continue;if(h<0){let m=Z(e,u),E=m.length,b=e.state.currentLine;if(E===0){r+=`bash: line ${b}: unset: [${h}]: bad array subscript
687
- `,s=1;continue}let g=E+h;if(g<0){r+=`bash: line ${b}: unset: [${h}]: bad array subscript
688
- `,s=1;continue}let y=m[g][0];sn(e,u,y);continue}sn(e,u,h);continue}if(!Ic(i)){r+=`bash: unset: \`${i}': not a valid identifier
689
- `,s=1;continue}let o=i;if(le(e,i)){let u=Te(e,i);u&&u!==i&&(o=u)}if(Me(e,o)){r+=`bash: unset: ${o}: cannot unset: readonly variable
690
- `,s=1;continue}Zn(e,o);let l=Bi(e,o);if(l!==void 0&&l!==e.state.callDepth)_c(e,o);else if(e.state.fullyUnsetLocals?.has(o))e.state.env.delete(o);else if(l!==void 0){let u=e.state.accessedTempEnvVars?.has(o),c=e.state.mutatedTempEnvVars?.has(o);if((u||c)&&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 La(e,o)||e.state.env.delete(o);e.state.exportedVars?.delete(o),e.state.functions.delete(i)}return L("",r,s)}function vt(e,t,n,r){let s=n+F(t)+1;if(s>r)throw new k(`shopt: output size limit exceeded (${r} bytes)`,"output_size");return e.push(t),s}var Ma=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],Mh=["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 As(e){return Ma.includes(e)}function Fh(e){return Mh.includes(e)}function Tc(e,t){let n=e.limits.maxArrayElements;if(t.length>n)throw new k(`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,u=[],c=0;for(;c<t.length;){let E=t[c];if(E==="--"){c++;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
691
- `}}}c++}else break}for(;c<t.length;)u.push(t[c]),c++;if(l)return Bh(e,u,s,i,a,o);if(s&&i)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
692
- `};if(u.length===0){if(s||i){let b=[];for(let g of Ma){let y=e.state.shoptOptions[g];s&&y?b.push(a?`shopt -s ${g}`:`${g} on`):i&&!y&&b.push(a?`shopt -u ${g}`:`${g} off`)}return{exitCode:0,stdout:b.length>0?`${b.join(`
671
+ `}function Va(e,t){if(t.includes("--help"))return Y(wr);if(t.length===0){let i=Uh(e),a=jh(e),o=[];for(let[c,f]of e.state.env)/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)&&(i.has(c)||a.has(c)||o.push([c,f]));let l=[...o.map(([c,f])=>({kind:"scalar",name:c,value:f})),...Array.from(i,c=>({kind:"indexed",name:c})),...Array.from(a,c=>({kind:"associative",name:c}))];l.sort((c,f)=>c.name<f.name?-1:c.name>f.name?1:0);let u=new kn(e.limits.maxOutputSize,"set");for(let c of l)e.executionScope.consumeWork(1,"set variable listing"),c.kind==="scalar"?(u.append(c.name).append("="),u.reserve(kc(c.value)),u.append(Ee(c.value))):c.kind==="indexed"?Vh(e,u,c.name):qh(e,u,c.name),u.append(`
672
+ `);return Y(u.build())}let n=[],r=()=>n.length>0?Y(n.join("")):J,s=0;for(;s<t.length;){let i=t[s];if((i==="-o"||i==="+o")&&Wh(t,s)){let a=t[s+1];if(!Ns.has(a)){let o=`bash: set: ${a}: invalid option name
673
+ ${wr}`;if(e.state.options.posix)throw new tt(1,"",o);return _(o)}Ba(e,Ns.get(a)??null,i==="-o"),s+=2;continue}if(i==="-o"){n.push(Bc(e)),s++;continue}if(i==="+o"){n.push(Wc(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 u=i[l];if(u==="o"){let c=s+1+o;if(c<t.length&&!t[c].startsWith("-")&&!t[c].startsWith("+")){let d=t[c];if(!Ns.has(d)){let p=`bash: set: ${d}: invalid option name
674
+ ${wr}`;if(e.state.options.posix)throw new tt(1,"",p);return _(p)}Ba(e,Ns.get(d)??null,a),o++;continue}n.push(a?Bc(e):Wc(e));continue}if(!Fc.has(u)){let c=`bash: set: ${i[0]}${u}: invalid option
675
+ ${wr}`;if(e.state.options.posix)throw new tt(1,"",c);return _(c)}Ba(e,Fc.get(u)??null,a)}s+=1+o;continue}if(i==="--")return Wa(e,t.slice(s+1)),r();if(i==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,_n(e),s+1<t.length)return Wa(e,t.slice(s+1)),r();s++;continue}if(i==="+"){s++;continue}if(i.startsWith("-")||i.startsWith("+")){let a=`bash: set: ${i}: invalid option
676
+ ${wr}`;if(e.state.options.posix)throw new tt(1,"",a);return _(a)}return Wa(e,t.slice(s)),r()}return r()}function Wa(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 za(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
677
+ `;if(e.state.options.posix)throw new tt(1,"",o);return _(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
678
+ `;if(e.state.options.posix)throw new tt(1,"",a);return _(a)}if(n===0)return J;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(" ")),J}async function qa(e,t){let n=t;if(n.length>0&&n[0]==="--"&&(n=n.slice(1)),n.length===0)return L("",`bash: source: filename argument required
679
+ `,2);let r=n[0],s=null,i=null;if(r.includes("/")){let u=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(u),s=u}catch{}}else{let c=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of c){let d=e.fs.resolvePath(e.state.cwd,`${f}/${r}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),s=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(f),s=f}catch{}}}if(i===null)return _(`bash: ${r}: No such file or directory
680
+ `);let a=new Map;if(n.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=n.slice(1);e.state.env.set("#",String(u.length)),e.state.env.set("@",u.join(" "));for(let c=0;c<u.length&&c<9;c++)e.state.env.set(String(c+1),u[c]);for(let c=u.length+1;c<=9;c++)e.state.env.delete(String(c))}let o=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=o,n.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 P(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let u=pt(i),c=await e.executeScript(u);return l(),c}catch(u){if(l(),u instanceof q)throw u;if(u instanceof Oe)return L(u.stdout,u.stderr,u.exitCode);if(u.name==="ParseException")return _(`bash: ${r}: ${u.message}
681
+ `);throw u}}function qc(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Gh(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function Uc(e,t){if(Gh(t))return null;try{let n=new j,r=te(n,t);return await X(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}function jc(e,t){if(e.state.localVarStack?.has(t)){let r=ws(e,t);if(r){r.value===void 0?e.state.env.delete(t):e.state.env.set(t,r.value);let s=e.state.localVarStack?.get(t);if(!s||s.length===0)gs(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),Ua(e,t);else{let i=s[s.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return e.state.env.delete(t),gs(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let r=e.state.localScopes.length-1;r>=0;r--){let s=e.state.localScopes[r];if(s.has(t)){let i=s.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),s.delete(t);let 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||gs(e,t),!0}}return!1}function Ua(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let n=e.state.tempEnvBindings.length-1;n>=0;n--){let r=e.state.tempEnvBindings[n];if(r.has(t)){let s=r.get(t);return s===void 0?e.state.env.delete(t):e.state.env.set(t,s),r.delete(t),!0}}return!1}async function Gc(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let n=t.slice(1,-1),s=new j().parseWordFromString(n,!0,!1);return ne(e,s)}if(t.includes("$")){let r=new j().parseWordFromString(t,!1,!1);return ne(e,r)}return t}async function ja(e,t){let n="both",r="",s=0;for(let i of t){if(i==="-v"){n="variable";continue}if(i==="-f"){n="function";continue}if(n==="function"){e.state.functions.delete(i);continue}if(n==="variable"){let u=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(u){let d=u[1],p=u[2];if(Fe(e,d)){r+=`bash: unset: ${d}: cannot unset: readonly variable
682
+ `,s=1;continue}if(p==="@"||p==="*"){tr(e,d),e.state.env.delete(d);continue}let h=e.state.associativeArrays?.has(d);if(h){let g=await Gc(e,p);hn(e,d,g);continue}let m=mt(e,d),E=e.state.declaredVars?.has(d);if((e.state.env.has(d)||E)&&!m&&!h){r+=`bash: unset: ${d}: not an array variable
683
+ `,s=1;continue}let y=await Uc(e,p);if(y===null&&m){r+=`bash: unset: ${p}: not a valid identifier
684
+ `,s=1;continue}if(y===null)continue;if(y<0){let g=G(e,d),b=g.length,v=e.state.currentLine;if(b===0){r+=`bash: line ${v}: unset: [${y}]: bad array subscript
685
+ `,s=1;continue}let $=b+y;if($<0){r+=`bash: line ${v}: unset: [${y}]: bad array subscript
686
+ `,s=1;continue}let A=g[$][0];hn(e,d,A);continue}hn(e,d,y);continue}if(!qc(i)){r+=`bash: unset: \`${i}': not a valid identifier
687
+ `,s=1;continue}let c=i;if(le(e,i)){let d=Me(e,i);d&&d!==i&&(c=d)}if(Fe(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable
688
+ `,s=1;continue}tr(e,c);let f=Zi(e,c);if(f!==void 0&&f!==e.state.callDepth)jc(e,c);else if(e.state.fullyUnsetLocals?.has(c))e.state.env.delete(c);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(c),p=e.state.mutatedTempEnvVars?.has(c);if((d||p)&&e.state.localVarStack?.has(c)){let h=ws(e,c);h?h.value===void 0?e.state.env.delete(c):e.state.env.set(c,h.value):e.state.env.delete(c)}else e.state.env.delete(c)}else Ua(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(Fe(e,u)){r+=`bash: unset: ${u}: cannot unset: readonly variable
689
+ `,s=1;continue}if(c==="@"||c==="*"){tr(e,u),e.state.env.delete(u);continue}let f=e.state.associativeArrays?.has(u);if(f){let m=await Gc(e,c);hn(e,u,m);continue}let d=mt(e,u);if(e.state.env.has(u)&&!d&&!f){r+=`bash: unset: ${u}: not an array variable
690
+ `,s=1;continue}let h=await Uc(e,c);if(h===null&&d){r+=`bash: unset: ${c}: not a valid identifier
691
+ `,s=1;continue}if(h===null)continue;if(h<0){let m=G(e,u),E=m.length,S=e.state.currentLine;if(E===0){r+=`bash: line ${S}: unset: [${h}]: bad array subscript
692
+ `,s=1;continue}let y=E+h;if(y<0){r+=`bash: line ${S}: unset: [${h}]: bad array subscript
693
+ `,s=1;continue}let g=m[y][0];hn(e,u,g);continue}hn(e,u,h);continue}if(!qc(i)){r+=`bash: unset: \`${i}': not a valid identifier
694
+ `,s=1;continue}let o=i;if(le(e,i)){let u=Me(e,i);u&&u!==i&&(o=u)}if(Fe(e,o)){r+=`bash: unset: ${o}: cannot unset: readonly variable
695
+ `,s=1;continue}tr(e,o);let l=Zi(e,o);if(l!==void 0&&l!==e.state.callDepth)jc(e,o);else if(e.state.fullyUnsetLocals?.has(o))e.state.env.delete(o);else if(l!==void 0){let u=e.state.accessedTempEnvVars?.has(o),c=e.state.mutatedTempEnvVars?.has(o);if((u||c)&&e.state.localVarStack?.has(o)){let f=ws(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 Ua(e,o)||e.state.env.delete(o);e.state.exportedVars?.delete(o),e.state.functions.delete(i)}return L("",r,s)}function Nt(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 Ga=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],Hh=["autocd","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","execfail","extdebug","extquote","force_fignore","globasciiranges","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath"];function Rs(e){return Ga.includes(e)}function Zh(e){return Hh.includes(e)}function Hc(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,u=[],c=0;for(;c<t.length;){let E=t[c];if(E==="--"){c++;break}if(E.startsWith("-")&&E.length>1){for(let S=1;S<E.length;S++){let y=E[S];switch(y){case"s":s=!0;break;case"u":i=!0;break;case"p":a=!0;break;case"q":o=!0;break;case"o":l=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${y}: invalid option
696
+ `}}}c++}else break}for(;c<t.length;)u.push(t[c]),c++;if(l)return Qh(e,u,s,i,a,o);if(s&&i)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
697
+ `};if(u.length===0){if(s||i){let S=[];for(let y of Ga){let g=e.state.shoptOptions[y];s&&g?S.push(a?`shopt -s ${y}`:`${y} on`):i&&!g&&S.push(a?`shopt -u ${y}`:`${y} off`)}return{exitCode:0,stdout:S.length>0?`${S.join(`
693
698
  `)}
694
- `:"",stderr:""}}let E=[];for(let b of Ma){let g=e.state.shoptOptions[b];E.push(a?`shopt ${g?"-s":"-u"} ${b}`:`${b} ${g?"on":"off"}`)}return{exitCode:0,stdout:`${E.join(`
699
+ `:"",stderr:""}}let E=[];for(let S of Ga){let y=e.state.shoptOptions[S];E.push(a?`shopt ${y?"-s":"-u"} ${S}`:`${S} ${y?"on":"off"}`)}return{exitCode:0,stdout:`${E.join(`
695
700
  `)}
696
- `,stderr:""}}let f=!1,d=[],p=0,h=[],m=0;for(let E of u){if(!As(E)&&!Fh(E)){p=vt(d,`shopt: ${E}: invalid shell option name`,p,r),f=!0;continue}if(s)As(E)&&(e.state.shoptOptions[E]=!0,Us(e));else if(i)As(E)&&(e.state.shoptOptions[E]=!1,Us(e));else if(As(E)){let b=e.state.shoptOptions[E];o?b||(f=!0):a?(m=vt(h,`shopt ${b?"-s":"-u"} ${E}`,m,r),b||(f=!0)):(m=vt(h,`${E} ${b?"on":"off"}`,m,r),b||(f=!0))}else o?f=!0:a?(m=vt(h,`shopt -u ${E}`,m,r),f=!0):(m=vt(h,`${E} off`,m,r),f=!0)}return{exitCode:f?1:0,stdout:h.length>0?`${h.join(`
701
+ `,stderr:""}}let f=!1,d=[],p=0,h=[],m=0;for(let E of u){if(!Rs(E)&&!Zh(E)){p=Nt(d,`shopt: ${E}: invalid shell option name`,p,r),f=!0;continue}if(s)Rs(E)&&(e.state.shoptOptions[E]=!0,Xs(e));else if(i)Rs(E)&&(e.state.shoptOptions[E]=!1,Xs(e));else if(Rs(E)){let S=e.state.shoptOptions[E];o?S||(f=!0):a?(m=Nt(h,`shopt ${S?"-s":"-u"} ${E}`,m,r),S||(f=!0)):(m=Nt(h,`${E} ${S?"on":"off"}`,m,r),S||(f=!0))}else o?f=!0:a?(m=Nt(h,`shopt -u ${E}`,m,r),f=!0):(m=Nt(h,`${E} off`,m,r),f=!0)}return{exitCode:f?1:0,stdout:h.length>0?`${h.join(`
697
702
  `)}
698
703
  `:"",stderr:d.length>0?`${d.join(`
699
704
  `)}
700
- `:""}}function Bh(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"],u=[...o.keys(),...l].sort();if(t.length===0){let m=[];for(let E of u){let b=l.includes(E),g=o.get(E),y=b||!g?!1:e.state.options[g];n&&!y||r&&y||m.push(s?`set ${y?"-o":"+o"} ${E}`:`${E} ${y?"on":"off"}`)}return{exitCode:0,stdout:m.length>0?`${m.join(`
705
+ `:""}}function Qh(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"],u=[...o.keys(),...l].sort();if(t.length===0){let m=[];for(let E of u){let S=l.includes(E),y=o.get(E),g=S||!y?!1:e.state.options[y];n&&!g||r&&g||m.push(s?`set ${g?"-o":"+o"} ${E}`:`${E} ${g?"on":"off"}`)}return{exitCode:0,stdout:m.length>0?`${m.join(`
701
706
  `)}
702
- `:"",stderr:""}}let c=!1,f=[],d=0,p=[],h=0;for(let m of t){let E=o.has(m),b=l.includes(m);if(!E&&!b){d=vt(f,`shopt: ${m}: invalid option name`,d,a),c=!0;continue}if(b){n||r||(i?c=!0:s?(h=vt(p,`set +o ${m}`,h,a),c=!0):(h=vt(p,`${m} off`,h,a),c=!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,kn(e);else if(r)e.state.options[g]=!1,kn(e);else{let y=e.state.options[g];i?y||(c=!0):s?(h=vt(p,`set ${y?"-o":"+o"} ${m}`,h,a),y||(c=!0)):(h=vt(p,`${m} ${y?"on":"off"}`,h,a),y||(c=!0))}}return{exitCode:c?1:0,stdout:p.length>0?`${p.join(`
707
+ `:"",stderr:""}}let c=!1,f=[],d=0,p=[],h=0;for(let m of t){let E=o.has(m),S=l.includes(m);if(!E&&!S){d=Nt(f,`shopt: ${m}: invalid option name`,d,a),c=!0;continue}if(S){n||r||(i?c=!0:s?(h=Nt(p,`set +o ${m}`,h,a),c=!0):(h=Nt(p,`${m} off`,h,a),c=!0));continue}let y=o.get(m);if(y)if(n)y==="vi"?e.state.options.emacs=!1:y==="emacs"&&(e.state.options.vi=!1),e.state.options[y]=!0,_n(e);else if(r)e.state.options[y]=!1,_n(e);else{let g=e.state.options[y];i?g||(c=!0):s?(h=Nt(p,`set ${g?"-o":"+o"} ${m}`,h,a),g||(c=!0)):(h=Nt(p,`${m} ${g?"on":"off"}`,h,a),g||(c=!0))}}return{exitCode:c?1:0,stdout:p.length>0?`${p.join(`
703
708
  `)}
704
709
  `:"",stderr:f.length>0?`${f.join(`
705
710
  `)}
706
- `:""}}function vs(e,t){return e===`/bin/${t}`||e===`/usr/bin/${t}`}async function Mc(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,u=e.commands.get(l);return u&&vs(a,l)?{cmd:u,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&&vs(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 u=await e.fs.stat(l);if(u.isDirectory)continue;let c=(u.mode&73)!==0,f=e.commands.get(t),d=vs(l,t);if(f&&d)return{cmd:f,path:l};if(c){if(f&&!d)return{script:!0,path:l};if(!f)return{script:!0,path:l}}}catch{}}if(!await e.fs.exists("/usr/bin")){let a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function $s(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(vs(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 Wh(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function pe(e,t,n,r){return((...s)=>{jn(t,n,`${r} call`);let i=e(...s);return Wh(i)?i.then(a=>(jn(t,n,`${r} post-await`),a),a=>{throw jn(t,n,`${r} post-await`),a}):(jn(t,n,`${r} return`),i)})}function Vh(e,t,n){let r={readFile:pe(e.readFile.bind(e),t,n,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:pe(e.readFileBytes.bind(e),t,n,"fs.readFileBytes")}:Object.create(null),readFileBuffer:pe(e.readFileBuffer.bind(e),t,n,"fs.readFileBuffer"),writeFile:pe(e.writeFile.bind(e),t,n,"fs.writeFile"),appendFile:pe(e.appendFile.bind(e),t,n,"fs.appendFile"),exists:pe(e.exists.bind(e),t,n,"fs.exists"),stat:pe(e.stat.bind(e),t,n,"fs.stat"),mkdir:pe(e.mkdir.bind(e),t,n,"fs.mkdir"),readdir:pe(e.readdir.bind(e),t,n,"fs.readdir"),rm:pe(e.rm.bind(e),t,n,"fs.rm"),cp:pe(e.cp.bind(e),t,n,"fs.cp"),mv:pe(e.mv.bind(e),t,n,"fs.mv"),resolvePath:pe(e.resolvePath.bind(e),t,n,"fs.resolvePath"),getAllPaths:pe(e.getAllPaths.bind(e),t,n,"fs.getAllPaths"),chmod:pe(e.chmod.bind(e),t,n,"fs.chmod"),symlink:pe(e.symlink.bind(e),t,n,"fs.symlink"),link:pe(e.link.bind(e),t,n,"fs.link"),readlink:pe(e.readlink.bind(e),t,n,"fs.readlink"),lstat:pe(e.lstat.bind(e),t,n,"fs.lstat"),realpath:pe(e.realpath.bind(e),t,n,"fs.realpath"),utimes:pe(e.utimes.bind(e),t,n,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=pe(e.readdirWithFileTypes.bind(e),t,n,"fs.readdirWithFileTypes")),r}function Fa(e,t){if(!e.requireDefenseContext)return e;let n=`command:${t}`,r=Object.getOwnPropertyDescriptors(e);r.fs={value:Vh(e.fs,e.requireDefenseContext,n),enumerable:!0,configurable:!0,writable:!0};let s=Object.defineProperties(Object.create(Object.getPrototypeOf(e)),r);return e.exec&&(s.exec=pe(e.exec,e.requireDefenseContext,n,"exec")),e.origCommand&&(s.origCommand=pe(e.origCommand,e.requireDefenseContext,n,"origCommand")),e.fetch&&(s.fetch=pe(e.fetch,e.requireDefenseContext,n,"fetch")),e.sleep&&(s.sleep=pe(e.sleep,e.requireDefenseContext,n,"sleep")),e.getRegisteredCommands&&(s.getRegisteredCommands=pe(e.getRegisteredCommands,e.requireDefenseContext,n,"getRegisteredCommands")),s}var Fc="+ ";async function Bc(e){let t=e.state.env.get("PS4");if(t===void 0)return Fc;if(t==="")return"";let n=e.state.options.xtrace;e.state.options.xtrace=!1;try{let s=new G().parseWordFromString(t,!1,!1);return await ne(e,s)}catch(r){if(r instanceof oe&&!r.fatal)return t;if(r instanceof yn||r instanceof Error&&r.name==="AbortError")throw r;return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
707
- `,t||Fc}finally{e.state.options.xtrace=n}}function zh(e){return e.map(t=>qh(t)).join(" ")}function qh(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let n=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
711
+ `:""}}function Ds(e,t){return e===`/bin/${t}`||e===`/usr/bin/${t}`}async function Zc(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,u=e.commands.get(l);return u&&Ds(a,l)?{cmd:u,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&&Ds(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 u=await e.fs.stat(l);if(u.isDirectory)continue;let c=(u.mode&73)!==0,f=e.commands.get(t),d=Ds(l,t);if(f&&d)return{cmd:f,path:l};if(c){if(f&&!d)return{script:!0,path:l};if(!f)return{script:!0,path:l}}}catch{}}if(!await e.fs.exists("/usr/bin")){let a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function Is(e,t){let n=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let 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(Ds(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 Kh(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function de(e,t,n,r){return((...s)=>{Jn(t,n,`${r} call`);let i=e(...s);return Kh(i)?i.then(a=>(Jn(t,n,`${r} post-await`),a),a=>{throw Jn(t,n,`${r} post-await`),a}):(Jn(t,n,`${r} return`),i)})}function Xh(e,t,n){let r={readFile:de(e.readFile.bind(e),t,n,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:de(e.readFileBytes.bind(e),t,n,"fs.readFileBytes")}:Object.create(null),readFileBuffer:de(e.readFileBuffer.bind(e),t,n,"fs.readFileBuffer"),writeFile:de(e.writeFile.bind(e),t,n,"fs.writeFile"),appendFile:de(e.appendFile.bind(e),t,n,"fs.appendFile"),exists:de(e.exists.bind(e),t,n,"fs.exists"),stat:de(e.stat.bind(e),t,n,"fs.stat"),mkdir:de(e.mkdir.bind(e),t,n,"fs.mkdir"),readdir:de(e.readdir.bind(e),t,n,"fs.readdir"),rm:de(e.rm.bind(e),t,n,"fs.rm"),cp:de(e.cp.bind(e),t,n,"fs.cp"),mv:de(e.mv.bind(e),t,n,"fs.mv"),resolvePath:de(e.resolvePath.bind(e),t,n,"fs.resolvePath"),getAllPaths:de(e.getAllPaths.bind(e),t,n,"fs.getAllPaths"),chmod:de(e.chmod.bind(e),t,n,"fs.chmod"),symlink:de(e.symlink.bind(e),t,n,"fs.symlink"),link:de(e.link.bind(e),t,n,"fs.link"),readlink:de(e.readlink.bind(e),t,n,"fs.readlink"),lstat:de(e.lstat.bind(e),t,n,"fs.lstat"),realpath:de(e.realpath.bind(e),t,n,"fs.realpath"),utimes:de(e.utimes.bind(e),t,n,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=de(e.readdirWithFileTypes.bind(e),t,n,"fs.readdirWithFileTypes")),e.createExclusive&&(r.createExclusive=de(e.createExclusive.bind(e),t,n,"fs.createExclusive")),r}function Ha(e,t){if(!e.requireDefenseContext)return e;let n=`command:${t}`,r=Object.getOwnPropertyDescriptors(e);r.fs={value:Xh(e.fs,e.requireDefenseContext,n),enumerable:!0,configurable:!0,writable:!0};let s=Object.defineProperties(Object.create(Object.getPrototypeOf(e)),r);return e.exec&&(s.exec=de(e.exec,e.requireDefenseContext,n,"exec")),e.origCommand&&(s.origCommand=de(e.origCommand,e.requireDefenseContext,n,"origCommand")),e.fetch&&(s.fetch=de(e.fetch,e.requireDefenseContext,n,"fetch")),e.sleep&&(s.sleep=de(e.sleep,e.requireDefenseContext,n,"sleep")),e.getRegisteredCommands&&(s.getRegisteredCommands=de(e.getRegisteredCommands,e.requireDefenseContext,n,"getRegisteredCommands")),s}var Qc="+ ";async function Kc(e){let t=e.state.env.get("PS4");if(t===void 0)return Qc;if(t==="")return"";let n=e.state.options.xtrace;e.state.options.xtrace=!1;let r=e.state.lastExitCode,s=e.state.env.get("?"),i=e.state.lastSubstitutionExitCode;try{let o=new j().parseWordFromString(t,!1,!1);return await ne(e,o)}catch(a){if(a instanceof ae&&!a.fatal)return t;if(a instanceof xn||a instanceof Error&&a.name==="AbortError")throw a;return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
712
+ `,t||Qc}finally{e.state.options.xtrace=n,e.state.lastExitCode=r,e.state.lastSubstitutionExitCode=i,s===void 0?e.state.env.delete("?"):e.state.env.set("?",s)}}function Yh(e){return e.map(t=>Jh(t)).join(" ")}function Jh(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let n=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
708
713
  `),s=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(n||r||s||i){let l="";for(let u of e){let c=u.charCodeAt(0);u===`
709
- `?l+="\\n":u===" "?l+="\\t":u==="\\"?l+="\\\\":u==="'"?l+="'":u==='"'?l+='"':c<32||c===127?c<256?l+=`\\x${c.toString(16).padStart(2,"0")}`:l+=`\\u${c.toString(16).padStart(4,"0")}`:l+=u}return`$'${l}'`}return a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function Wc(e,t,n){if(!e.state.options.xtrace)return"";let r=await Bc(e),s=[t,...n],i=zh(s);return`${r}${i}
710
- `}async function Vc(e,t,n){return e.state.options.xtrace?`${await Bc(e)}${t}=${n}
711
- `:""}function xs(e,t,n){return Dt([t,n],"",e.limits.maxStringLength,"array assignment")}async function zc(e,t){let n=new Map,r="";for(let s of t.assignments){let i=s.name;if(s.array){let c=await Uh(e,t,i,s.array,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};if(r+=c.xtraceOutput,c.continueToNext)continue}let a=s.value?await ne(e,s.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:L("",`bash: ${i}: bad array subscript
712
- `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let c=await Qh(e,t,l[1],l[2],a,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};if(c.continueToNext)continue}let u=await Kh(e,t,i,a,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};r+=u.xtraceOutput,u.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:n}}async function Uh(e,t,n,r,s,i){let a="";if(/\[.+\]$/.test(n))return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: ${n}: cannot assign list to array member
713
- `,1)};if(le(e,n)){let h=fn(e,n);if(h===void 0||h==="")throw new U(1,"","");let m=Te(e,n);if(m&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(m))return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: ${n}: cannot assign list to array member
714
- `,1)}}if(Me(e,n)){if(t.name)return a+=`bash: ${n}: readonly variable
715
- `,{continueToNext:!0,xtraceOutput:a};let h=ue(e,n);if(h)return{continueToNext:!1,xtraceOutput:"",error:h}}let o=e.state.associativeArrays?.has(n),l=ve(e,n),u=l?Le(l):void 0,c=e.state.env.get(n),f=()=>{e.state.arrays??=new Map,u?e.state.arrays.set(n,u):e.state.arrays.delete(n),c===void 0?e.state.env.delete(n):e.state.env.set(n,c)},d=jh(r),p=()=>{ye(e,n),e.state.env.delete(n)};try{o&&d?await Gh(e,t,n,r,s,p,h=>{a+=h}):d?await Zh(e,n,r,s,p):await Hh(e,n,r,s,p)}catch(h){throw f(),h}if(t.name){i.set(n,e.state.env.get(n));let m=`(${r.map(E=>xn(E)).join(" ")})`;e.state.env.set(n,m)}return{continueToNext:!0,xtraceOutput:a}}function jh(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 Gh(e,t,n,r,s,i,a){let o=[];for(let l of r){if(o.length>=e.limits.maxArrayElements)throw new k(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let u=Vs(l);if(u){let{key:c,valueParts:f,append:d}=u,p;f.length>0?(p=await ne(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(p=zt(e,p))):p="",o.push({type:"keyed",key:c,value:p,append:d})}else{let c=await ne(e,l);o.push({type:"invalid",expandedValue:c})}}e.executionScope.consumeWork(o.length,"associative array assignment"),s||i();for(let l of o)if(l.type==="keyed")if(l.append){let u=ae(e,n,l.key)??"";j(e,n,l.key,xs(e,u,l.value),"associative")}else j(e,n,l.key,l.value,"associative");else{let u=t.line??e.state.currentLine??1;a(`bash: line ${u}: ${n}: ${l.expandedValue}: must use subscript when assigning associative array
716
- `)}}async function Zh(e,t,n,r,s){let i=[],a=0;for(let l of n){let u=Vs(l);if(u){if(a>=e.limits.maxArrayElements)throw new k(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let{key:c,valueParts:f,append:d}=u,p;f.length>0?(p=await ne(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(p=zt(e,p))):p="",i.push({type:"keyed",indexExpr:c,value:p,append:d}),a++}else{let c=await ht(e,l);if(c.values.length>e.limits.maxArrayElements-a)throw new k(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push({type:"non-keyed",values:c.values}),a+=c.values.length}}e.executionScope.consumeWork(a,"indexed array assignment"),r||s();let o=0;for(let l of i)if(l.type==="keyed"){let u;try{let c=new G,f=te(c,l.indexExpr);u=await K(e,f.expression,!1)}catch{if(/^-?\d+$/.test(l.indexExpr))u=Number.parseInt(l.indexExpr,10);else{let c=e.state.env.get(l.indexExpr);u=c?Number.parseInt(c,10):0,Number.isNaN(u)&&(u=0)}}if(l.append){let c=ae(e,t,u)??"";j(e,t,u,xs(e,c,l.value))}else j(e,t,u,l.value);o=u+1}else for(let u of l.values)j(e,t,o++,u)}async function Hh(e,t,n,r,s){let i=[];for(let o of n){let l=await ht(e,o);for(let u of l.values){if(i.length>=e.limits.maxArrayElements)throw new k(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push(u)}}let a=0;if(e.executionScope.consumeWork(i.length,"indexed array assignment"),r){let o=Z(e,t);if(o.length>0)a=Math.max(...o.map(([u])=>typeof u=="number"?u:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(j(e,t,0,l),e.state.env.delete(t),a=1)}}else s();for(let o=0;o<i.length;o++)j(e,t,a+o,i[o])}async function Qh(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:L("",`bash: \`${f}': not a valid identifier
717
- `,1)};o=f}}if(Me(e,o)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=ue(e,o);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l=e.state.associativeArrays?.has(o),u;if(l)u=await qc(e,r);else{let f=await Ba(e,o,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};u=String(f.index)}let c=i?xs(e,ae(e,o,u)||"",s):s;return t.name||j(e,o,u,c,l?"associative":"indexed"),{continueToNext:!0,xtraceOutput:""}}async function qc(e,t){let n;if(t.startsWith("'")&&t.endsWith("'"))n=t.slice(1,-1);else if(t.startsWith('"')&&t.endsWith('"')){let r=t.slice(1,-1),i=new G().parseWordFromString(r,!0,!1);n=await ne(e,i)}else if(t.includes("$")){let s=new G().parseWordFromString(t,!1,!1);n=await ne(e,s)}else n=t;return n}async function 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 G,a=te(i,r);s=await K(e,a.expression,!1)}catch(i){if(i instanceof U)throw i;if(i instanceof oe){let l=`bash: line ${e.state.currentLine}: ${n}: ${i.message}
718
- `;if(i.fatal)throw new U(1,"",l);return{index:0,error:L("",l,1)}}let a=e.state.currentLine;return{index:0,error:L("",`bash: line ${a}: ${t}[${n}]: bad array subscript
719
- `,1)}}Number.isNaN(s)&&(s=0)}if(s<0){let i=Z(e,t);if(i.length===0){let o=e.state.currentLine;return{index:0,error:L("",`bash: line ${o}: ${t}[${n}]: bad array subscript
714
+ `?l+="\\n":u===" "?l+="\\t":u==="\\"?l+="\\\\":u==="'"?l+="'":u==='"'?l+='"':c<32||c===127?c<256?l+=`\\x${c.toString(16).padStart(2,"0")}`:l+=`\\u${c.toString(16).padStart(4,"0")}`:l+=u}return`$'${l}'`}return a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function Xc(e,t,n){if(!e.state.options.xtrace)return"";let r=await Kc(e),s=[t,...n],i=Yh(s);return`${r}${i}
715
+ `}async function Yc(e,t,n){return e.state.options.xtrace?`${await Kc(e)}${t}=${n}
716
+ `:""}function Os(e,t,n){return Ft([t,n],"",e.limits.maxStringLength,"array assignment")}async function Jc(e,t){let n=new Map,r="";for(let s of t.assignments){let i=s.name;if(s.array){let c=await em(e,t,i,s.array,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};if(r+=c.xtraceOutput,c.continueToNext)continue}let a=s.value?await ne(e,s.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:L("",`bash: ${i}: bad array subscript
717
+ `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let c=await im(e,t,l[1],l[2],a,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};if(c.continueToNext)continue}let u=await am(e,t,i,a,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};r+=u.xtraceOutput,u.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:n}}async function em(e,t,n,r,s,i){let a="";if(/\[.+\]$/.test(n))return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: ${n}: cannot assign list to array member
718
+ `,1)};if(le(e,n)){let h=bn(e,n);if(h===void 0||h==="")throw new q(1,"","");let m=Me(e,n);if(m&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(m))return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: ${n}: cannot assign list to array member
719
+ `,1)}}if(Fe(e,n)){if(t.name)return a+=`bash: ${n}: readonly variable
720
+ `,{continueToNext:!0,xtraceOutput:a};let h=ue(e,n);if(h)return{continueToNext:!1,xtraceOutput:"",error:h}}let o=e.state.associativeArrays?.has(n),l=ve(e,n),u=l?Te(l):void 0,c=e.state.env.get(n),f=()=>{e.state.arrays??=new Map,u?e.state.arrays.set(n,u):e.state.arrays.delete(n),c===void 0?e.state.env.delete(n):e.state.env.set(n,c)},d=tm(r),p=()=>{ye(e,n),e.state.env.delete(n)};try{o&&d?await nm(e,t,n,r,s,p,h=>{a+=h}):d?await rm(e,n,r,s,p):await sm(e,n,r,s,p)}catch(h){throw f(),h}if(t.name){i.set(n,e.state.env.get(n));let m=`(${r.map(E=>On(E)).join(" ")})`;e.state.env.set(n,m)}return{continueToNext:!0,xtraceOutput:a}}function tm(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 nm(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 u=Zs(l);if(u){let{key:c,valueParts:f,append:d}=u,p;f.length>0?(p=await ne(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(p=Xt(e,p))):p="",o.push({type:"keyed",key:c,value:p,append:d})}else{let c=await ne(e,l);o.push({type:"invalid",expandedValue:c})}}e.executionScope.consumeWork(o.length,"associative array assignment"),s||i();for(let l of o)if(l.type==="keyed")if(l.append){let u=ie(e,n,l.key)??"";U(e,n,l.key,Os(e,u,l.value),"associative")}else U(e,n,l.key,l.value,"associative");else{let u=t.line??e.state.currentLine??1;a(`bash: line ${u}: ${n}: ${l.expandedValue}: must use subscript when assigning associative array
721
+ `)}}async function rm(e,t,n,r,s){let i=[],a=0;for(let l of n){let u=Zs(l);if(u){if(a>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let{key:c,valueParts:f,append:d}=u,p;f.length>0?(p=await ne(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(p=Xt(e,p))):p="",i.push({type:"keyed",indexExpr:c,value:p,append:d}),a++}else{let c=await Et(e,l);if(c.values.length>e.limits.maxArrayElements-a)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push({type:"non-keyed",values:c.values}),a+=c.values.length}}e.executionScope.consumeWork(a,"indexed array assignment"),r||s();let o=0;for(let l of i)if(l.type==="keyed"){let u;try{let c=new j,f=te(c,l.indexExpr);u=await X(e,f.expression,!1)}catch{if(/^-?\d+$/.test(l.indexExpr))u=Number.parseInt(l.indexExpr,10);else{let c=e.state.env.get(l.indexExpr);u=c?Number.parseInt(c,10):0,Number.isNaN(u)&&(u=0)}}if(l.append){let c=ie(e,t,u)??"";U(e,t,u,Os(e,c,l.value))}else U(e,t,u,l.value);o=u+1}else for(let u of l.values)U(e,t,o++,u)}async function sm(e,t,n,r,s){let i=[];for(let o of n){let l=await Et(e,o);for(let u of l.values){if(i.length>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push(u)}}let a=0;if(e.executionScope.consumeWork(i.length,"indexed array assignment"),r){let o=G(e,t);if(o.length>0)a=Math.max(...o.map(([u])=>typeof u=="number"?u:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(U(e,t,0,l),e.state.env.delete(t),a=1)}}else s();for(let o=0;o<i.length;o++)U(e,t,a+o,i[o])}async function im(e,t,n,r,s,i,a){let o=n;if(le(e,n)){let f=Me(e,n);if(f&&f!==n){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: \`${f}': not a valid identifier
722
+ `,1)};o=f}}if(Fe(e,o)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=ue(e,o);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l=e.state.associativeArrays?.has(o),u;if(l)u=await ef(e,r);else{let f=await Za(e,o,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};u=String(f.index)}let c=i?Os(e,ie(e,o,u)||"",s):s;return t.name||U(e,o,u,c,l?"associative":"indexed"),{continueToNext:!0,xtraceOutput:""}}async function ef(e,t){let n;if(t.startsWith("'")&&t.endsWith("'"))n=t.slice(1,-1);else if(t.startsWith('"')&&t.endsWith('"')){let r=t.slice(1,-1),i=new j().parseWordFromString(r,!0,!1);n=await ne(e,i)}else if(t.includes("$")){let s=new j().parseWordFromString(t,!1,!1);n=await ne(e,s)}else n=t;return n}async function Za(e,t,n){let r=n;n.startsWith('"')&&n.endsWith('"')&&n.length>=2&&(r=n.slice(1,-1));let s;if(/^-?\d+$/.test(r))s=Number.parseInt(r,10);else{try{let i=new j,a=te(i,r);s=await X(e,a.expression,!1)}catch(i){if(i instanceof q)throw i;if(i instanceof ae){let l=`bash: line ${e.state.currentLine}: ${n}: ${i.message}
723
+ `;if(i.fatal)throw new q(1,"",l);return{index:0,error:L("",l,1)}}let a=e.state.currentLine;return{index:0,error:L("",`bash: line ${a}: ${t}[${n}]: bad array subscript
724
+ `,1)}}Number.isNaN(s)&&(s=0)}if(s<0){let i=G(e,t);if(i.length===0){let o=e.state.currentLine;return{index:0,error:L("",`bash: line ${o}: ${t}[${n}]: bad array subscript
720
725
  `,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:L("",`bash: line ${o}: ${t}[${n}]: bad array subscript
721
- `,1)}}}return{index:s}}async function Kh(e,t,n,r,s,i){let a="",o=n,l=null;if(le(e,n)){let f=Fr(e,n,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: ${n}: circular name reference
722
- `,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(Me(e,o)){if(t.name)return a+=`bash: ${o}: readonly variable
723
- `,{continueToNext:!0,xtraceOutput:a};let f=ue(e,o);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let u;if(ur(e,o))try{let f=new G;if(s){let p=`(${e.state.env.get(o)||"0"}) + (${r})`,h=te(f,p);u=String(await K(e,h.expression))}else{let d=te(f,r);u=String(await K(e,d.expression))}}catch{u="0"}else{let f=ct(e,o)?ae(e,o,0):e.state.env.get(o);u=s?xs(e,f||"",r):r}u=Bn(e,o,u),a+=await Vc(e,o,u);let c;return l?c=await Xh(e,l):ct(e,o)&&(c="0"),t.name?c===void 0&&(i.set(o,e.state.env.get(o)),e.state.env.set(o,u)):(c===void 0?e.state.env.set(o,u):j(e,o,c,u),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 Xh(e,t){let{arrayName:n,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(n))return qc(e,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let a=new G,o=te(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=Z(e,n);a.length>0&&(i=Math.max(...a.map(l=>l[0]))+1+i)}return String(i)}async function Gc(e,t,n,r){let s=!1,i=!1,a=!1,o=!1,l=!1,u=[];for(let m of t)if(m.startsWith("-")&&m.length>1)for(let E of m.slice(1))E==="t"?s=!0:E==="p"?i=!0:E==="P"?a=!0:E==="a"?o=!0:E==="f"&&(l=!0);else u.push(m);let c="",f="",d=0,p=!1,h=!1;for(let m of u){let E=!1;if(a){if(o){let $=await r(m);if($.length>0){for(let A of $)c+=`${A}
726
+ `,1)}}}return{index:s}}async function am(e,t,n,r,s,i){let a="",o=n,l=null;if(le(e,n)){let f=jr(e,n,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: ${n}: circular name reference
727
+ `,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(Fe(e,o)){if(t.name)return a+=`bash: ${o}: readonly variable
728
+ `,{continueToNext:!0,xtraceOutput:a};let f=ue(e,o);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let u;if(yr(e,o))try{let f=new j;if(s){let p=`(${e.state.env.get(o)||"0"}) + (${r})`,h=te(f,p);u=String(await X(e,h.expression))}else{let d=te(f,r);u=String(await X(e,d.expression))}}catch{u="0"}else{let f=mt(e,o)?ie(e,o,0):e.state.env.get(o);u=s?Os(e,f||"",r):r}u=Hn(e,o,u),a+=await Yc(e,o,u);let c;return l?c=await om(e,l):mt(e,o)&&(c="0"),t.name?c===void 0&&(i.set(o,e.state.env.get(o)),e.state.env.set(o,u)):(c===void 0?e.state.env.set(o,u):U(e,o,c,u),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 om(e,t){let{arrayName:n,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(n))return ef(e,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let a=new j,o=te(a,r);i=await X(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=G(e,n);a.length>0&&(i=Math.max(...a.map(l=>l[0]))+1+i)}return String(i)}async function rf(e,t,n,r){let s=!1,i=!1,a=!1,o=!1,l=!1,u=[];for(let m of t)if(m.startsWith("-")&&m.length>1)for(let E of m.slice(1))E==="t"?s=!0:E==="p"?i=!0:E==="P"?a=!0:E==="a"?o=!0:E==="f"&&(l=!0);else u.push(m);let c="",f="",d=0,p=!1,h=!1;for(let m of u){let E=!1;if(a){if(o){let $=await r(m);if($.length>0){for(let A of $)c+=`${A}
724
729
  `;p=!0,E=!0}}else{let $=await n(m);$&&(c+=`${$}
725
- `,p=!0,E=!0)}E||(h=!0);continue}let b=!l&&e.state.functions.has(m);if(o&&b){if(!i)if(s)c+=`function
726
- `;else{let $=e.state.functions.get(m),A=$?Uc(m,$):`${m} is a function
727
- `;c+=A}E=!0}let g=e.state.env.get(`BASH_ALIAS_${m}`);if(g!==void 0&&(o||!E)&&(i||(s?c+=`alias
728
- `:c+=`${m} is aliased to \`${g}'
729
- `),E=!0,!o)||Vi.has(m)&&(o||!E)&&(i||(s?c+=`keyword
730
+ `,p=!0,E=!0)}E||(h=!0);continue}let S=!l&&e.state.functions.has(m);if(o&&S){if(!i)if(s)c+=`function
731
+ `;else{let $=e.state.functions.get(m),A=$?tf(m,$):`${m} is a function
732
+ `;c+=A}E=!0}let y=e.state.env.get(`BASH_ALIAS_${m}`);if(y!==void 0&&(o||!E)&&(i||(s?c+=`alias
733
+ `:c+=`${m} is aliased to \`${y}'
734
+ `),E=!0,!o)||Ki.has(m)&&(o||!E)&&(i||(s?c+=`keyword
730
735
  `:c+=`${m} is a shell keyword
731
- `),E=!0,!o))continue;if(!o&&b&&!E){if(!i)if(s)c+=`function
732
- `;else{let $=e.state.functions.get(m),A=$?Uc(m,$):`${m} is a function
733
- `;c+=A}E=!0;continue}if(!(On.has(m)&&(o||!E)&&(i||(s?c+=`builtin
736
+ `),E=!0,!o))continue;if(!o&&S&&!E){if(!i)if(s)c+=`function
737
+ `;else{let $=e.state.functions.get(m),A=$?tf(m,$):`${m} is a function
738
+ `;c+=A}E=!0;continue}if(!(Vn.has(m)&&(o||!E)&&(i||(s?c+=`builtin
734
739
  `:c+=`${m} is a shell builtin
735
740
  `),E=!0,!o))){if(o){let $=await r(m);for(let A of $)i?c+=`${A}
736
741
  `:s?c+=`file
@@ -739,16 +744,16 @@ ${fr}`;if(e.state.options.posix)throw new et(1,"",a);return I(a)}return Da(e,t.s
739
744
  `:s?c+=`file
740
745
  `:c+=`${m} is ${$}
741
746
  `,p=!0,E=!0)}if(!E&&(h=!0,!s&&!i)){let $=!0;if(m.includes("/")){let A=e.fs.resolvePath(e.state.cwd,m);await e.fs.exists(A)&&($=!1)}$&&(f+=`bash: type: ${m}: not found
742
- `)}}}return i?d=h&&!p?1:0:d=h?1:0,L(c,f,d)}function Uc(e,t){let n;return t.body.type==="Group"?n=t.body.body.map(s=>dr(s)).join("; "):n=dr(t.body),`${e} is a function
747
+ `)}}}return i?d=h&&!p?1:0:d=h?1:0,L(c,f,d)}function tf(e,t){let n;return t.body.type==="Group"?n=t.body.body.map(s=>Er(s)).join("; "):n=Er(t.body),`${e} is a function
743
748
  ${e} ()
744
749
  {
745
750
  ${n}
746
751
  }
747
- `}function dr(e){if(Array.isArray(e))return e.map(t=>dr(t)).join("; ");if(e.type==="Statement"){let t=[];for(let n=0;n<e.pipelines.length;n++){let r=e.pipelines[n];t.push(Yh(r)),e.operators[n]&&t.push(e.operators[n])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,n=[];t.name&&n.push(jc(t.name));for(let r of t.args)n.push(jc(r));return n.join(" ")}return e.type==="Group"?`{ ${e.body.map(r=>dr(r)).join("; ")}; }`:"..."}function jc(e){return e.parts.map(Zc).join("")}function Zc(e){switch(e.type){case"Literal":return e.value;case"Escaped":return`\\${e.value}`;case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(Zc).join("")}"`;default:return Se(T.word([e]))}}function Yh(e){let t=e.commands.map(n=>dr(n));return(e.negated?"! ":"")+t.join(" | ")}async function Hc(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}"
752
+ `}function Er(e){if(Array.isArray(e))return e.map(t=>Er(t)).join("; ");if(e.type==="Statement"){let t=[];for(let n=0;n<e.pipelines.length;n++){let r=e.pipelines[n];t.push(lm(r)),e.operators[n]&&t.push(e.operators[n])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,n=[];t.name&&n.push(nf(t.name));for(let r of t.args)n.push(nf(r));return n.join(" ")}return e.type==="Group"?`{ ${e.body.map(r=>Er(r)).join("; ")}; }`:"..."}function nf(e){return e.parts.map(sf).join("")}function sf(e){switch(e.type){case"Literal":return e.value;case"Escaped":return`\\${e.value}`;case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(sf).join("")}"`;default:return Se(T.word([e]))}}function lm(e){let t=e.commands.map(n=>Er(n));return(e.negated?"! ":"")+t.join(" | ")}async function af(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}"
748
753
  `:s+=`alias ${o}='${l}'
749
- `;else if(Vi.has(o))r?s+=`${o} is a shell keyword
754
+ `;else if(Ki.has(o))r?s+=`${o} is a shell keyword
750
755
  `:s+=`${o}
751
- `;else if(On.has(o))r?s+=`${o} is a shell builtin
756
+ `;else if(Vn.has(o))r?s+=`${o} is a shell builtin
752
757
  `:s+=`${o}
753
758
  `;else if(e.state.functions.has(o))r?s+=`${o} is a function
754
759
  `:s+=`${o}
@@ -758,53 +763,53 @@ ${e} ()
758
763
  `),a=1)}else if(e.commands.has(o)){let c=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of c){if(!d)continue;let p=`${d}/${o}`;try{let h=await e.fs.stat(p);if(!h.isDirectory&&(h.mode&73)!==0){f=p;break}}catch{}}f||(f=`/usr/bin/${o}`),r?s+=`${o} is ${f}
759
764
  `:s+=`${f}
760
765
  `}else r&&(i+=`${o}: not found
761
- `),a=1}return L(s,i,a)}async function Qc(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 Kc(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
762
- `)},a=f=>{if(f===null||typeof f!="object"&&typeof f!="function")return f;let d=s.get(f);if(d!==void 0)return d;if(typeof f=="object"&&lo(f))return f;if(f instanceof Uint8Array){let E=new Uint8Array(f);return s.set(f,E),E}if(f instanceof ArrayBuffer){let E=f.slice(0);return s.set(f,E),E}if(f instanceof Promise){let E=f.then(b=>(i(),a(b)));return s.set(f,E),E}if(typeof f=="function"){let E=function(...b){return i(),a(Reflect.apply(f,this,b))};return s.set(f,E),E}let p=Object.getPrototypeOf(f);if(Array.isArray(f)||p===Object.prototype||p===null){let E=Array.isArray(f)?[]:Object.create(p);s.set(f,E);let b=Object.getOwnPropertyDescriptors(f);for(let g of Object.values(b)){if("value"in g){let y=g.value;g.value=typeof y=="function"?(...S)=>(i(),a(Reflect.apply(y,f,S))):a(y)}if(g.get){let y=g.get;g.get=()=>(i(),a(Reflect.apply(y,f,[])))}if(g.set){let y=g.set;g.set=S=>{i(),Reflect.apply(y,f,[S])}}}return Object.defineProperties(E,b),E}let h=new Map,m=new eo(f,{get(E,b){if(i(),b==="constructor"||b==="prototype"||b==="__proto__")throw new Error(`${t}: unsafe context property access`);let g=Reflect.get(E,b,E);if(typeof g!="function")return a(g);if(h.has(b))return h.get(b);let y=(...S)=>(i(),a(Reflect.apply(g,E,S)));return h.set(b,y),y},set(E,b,g){if(i(),b==="constructor"||b==="prototype"||b==="__proto__")throw new Error(`${t}: unsafe context property access`);return Reflect.set(E,b,g,E)}});return s.set(f,m),m},o=f=>a(f),l=f=>f&&((...d)=>(i(),a(f(...d)))),u=f=>({value:f,enumerable:!0,configurable:!0,writable:!0}),c=Object.getOwnPropertyDescriptors(e);return Object.assign(c,{fs:u(o(e.fs)),env:u(o(e.env)),limits:u(Object.freeze({...e.limits})),exportedEnv:u(e.exportedEnv?Object.freeze({...e.exportedEnv}):void 0),executionScope:u(e.executionScope?o(e.executionScope):void 0),fileDescriptors:u(e.fileDescriptors?o(e.fileDescriptors):void 0),coverage:u(e.coverage?o(e.coverage):void 0),assignShellVariable:u(l(e.assignShellVariable)),exec:u(l(e.exec)),origCommand:u(l(e.origCommand)),execWithInheritedStdin:u(l(e.execWithInheritedStdin)),fetch:u(l(e.fetch)),getRegisteredCommands:u(l(e.getRegisteredCommands)),sleep:u(l(e.sleep)),trace:u(l(e.trace)),invokeTool:u(l(e.invokeTool)),signal:u(r?.signal)}),{context:Object.defineProperties(Object.create(Object.getPrototypeOf(e)),c),revoke(){n=!1,r?.signal.aborted||r?.abort(new We("",`bash: ${t} context revoked
763
- `))}}}async function Jh(e,t,n,r,s,i){let a=s.remainingTimeMs()??t.limits.maxExecutionTimeMs,o=t.limits.maxExtensionCleanupTimeMs,l,u,c,d=Promise.resolve().then(e).then(h=>({kind:"result",result:h}),h=>({kind:"error",error:h})),p=new Promise(h=>{let m=()=>{n(),h({kind:"abort"})};u=m,i?.addEventListener("abort",m,{once:!0}),i?.aborted&&m(),l=qn(()=>{n(),h({kind:"deadline"})},a)});try{let h=await Promise.race([d,p]);if(h.kind==="result")return h.result;if(h.kind==="error")throw h.error;n();let m=await Promise.race([d.then(()=>!0),new Promise(b=>{c=qn(()=>b(!1),o)})]),E=h.kind==="deadline"?new We("",`bash: ${r} exceeded its execution deadline
764
- `):new We("",`bash: execution aborted
765
- `);throw m||s.poisonAfterAbort(E),E}finally{n(),Un(l),Un(c),u&&i?.removeEventListener("abort",u)}}async function Xc(e,t,n,r,s,i,a,o,l=!1){let{ctx:u,runCommand:c}=e;if(u.coverage&&On.has(t)&&u.coverage.hit(`bash:builtin:${t}`),t==="export")return Aa(u,n);if(t==="unset")return Ta(u,n);if(t==="exit")return Sa(u,n);if(t==="local")return ka(u,n);if(t==="set")return Ia(u,n);if(t==="break")return Oi(u,n);if(t==="continue")return ua(u,n);if(t==="return")return Na(u,n);if(t==="eval"&&u.state.options.posix)return Es(u,n,s,l);if(t==="shift")return Oa(u,n);if(t==="getopts")return bs(u,n);if(t==="compgen")return sa(u,n);if(t==="complete")return oa(u,n);if(t==="compopt")return la(u,n);if(t==="pushd")return await wa(u,n);if(t==="popd")return Ea(u,n);if(t==="dirs")return ba(u,n);if(t==="source"||t===".")return _a(u,n);if(t==="read")return Ca(u,n,s,o);if(t==="mapfile"||t==="readarray")return Pa(u,n,s);if(t==="declare"||t==="typeset")return ma(u,n);if(t==="readonly")return ya(u,n);if(!i){let f=u.state.functions.get(t);if(f)return gs(u,f,n,s,void 0,l)}if(t==="__just_bash_tee_restore"){if(n.length===0||n.length>u.limits.maxArrayElements)return I(`bash: invalid internal pipeline status restore
766
- `,2);let f=[];for(let h of n){if(!/^(?:0|[1-9][0-9]{0,2})$/.test(h))return I(`bash: invalid internal pipeline status restore
767
- `,2);let m=Number(h);if(!Number.isSafeInteger(m)||m>255)return I(`bash: invalid internal pipeline status restore
768
- `,2);f.push(m)}let d=f[f.length-1]??0,p=[...f].reverse().find(h=>h!==0);return{stdout:"",stderr:"",exitCode:u.state.options.pipefail&&p!==void 0?p:d,internalPipeStatusOverride:f}}if(t==="eval")return Es(u,n,s,l);if(t==="cd")return await _i(u,n);if(t===":"||t==="true")return ee;if(t==="false")return ge(!1);if(t==="let")return xa(u,n);if(t==="command")return em(e,n,s,l);if(t==="builtin")return tm(e,n,s,l);if(t==="shopt")return Tc(u,n);if(t==="exec"){if(n.length===0)return ee;let[f,...d]=n;return{...await c(f,d,[],s,!1,!1,-1,l),internalProducerOmitsShellPrefix:!0}}if(t==="wait")return ee;if(t==="type")return await Gc(u,n,f=>Qc(u,f),f=>$s(u,f));if(t==="hash")return va(u,n);if(t==="help")return $a(u,n);if(t==="["||t==="test"){let f=n;if(t==="["){if(n[n.length-1]!=="]")return I("[: missing `]'\n",2);f=n.slice(0,-1)}return ir(u,f)}return null}async function em(e,t,n,r=!1){let{ctx:s,runCommand:i}=e;if(t.length===0)return ee;let a=!1,o=!1,l=!1,u=t;for(;u.length>0&&u[0].startsWith("-");){let d=u[0];if(d==="--"){u=u.slice(1);break}for(let p of d.slice(1))p==="p"?a=!0:p==="V"?o=!0:p==="v"&&(l=!0);u=u.slice(1)}if(u.length===0)return ee;if(l||o)return await Hc(s,u,l,o);let[c,...f]=u;return i(c,f,[],n,!0,a,-1,r)}async function tm(e,t,n,r=!1){let{runCommand:s}=e;if(t.length===0)return ee;let i=t;if(i[0]==="--"&&(i=i.slice(1),i.length===0))return ee;let a=i[0];if(a!=="__just_bash_tee_restore"&&!On.has(a))return I(`bash: builtin: ${a}: not a shell builtin
769
- `);let[,...o]=i;return s(a,o,[],n,!0,!1,-1,r)}async function Yc(e,t,n,r,s){let{ctx:i,buildExportedEnv:a,executeUserScript:o}=e,u=await Mc(i,t,s?"/usr/bin:/bin":void 0);if(!u)return qu(t)?I(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
770
- `,127):I(`bash: ${t}: command not found
771
- `,127);if("error"in u)return u.error==="permission_denied"?I(`bash: ${t}: Permission denied
772
- `,126):I(`bash: ${t}: No such file or directory
773
- `,127);if("script"in u)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u.path)),await o(u.path,n,r);let{cmd:c,path:f}=u;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",p=!1,h=a();i.state.fileDescriptors??=new Map;let m={fs:i.fs,fsIdentity:Ms(i.fs),cwd:i.state.cwd,env:i.state.env,assignShellVariable:async(v,$,A)=>{if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v))throw new Error(`${v}: not a valid identifier`);let C=A===void 0?v:`${v}[${A}]`,N=Fr(i,v,$);if(N===void 0)throw new Error(`${v}: circular name reference`);if(N===null)return;let x=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(?:\[(.*)\])?$/);if(!x)throw new Error(`${C}: not a valid identifier`);let P=x[1],R=x[2]??A;if(Me(i,v)||Me(i,P))throw new Error(`${P}: readonly variable`);if(R===void 0)i.state.env.set(P,$);else{let B=i.state.associativeArrays?.has(P)?"associative":"indexed";if(B==="associative"){j(i,P,R,$,B);return}let q=await Ba(i,P,R);if(q.error)throw new U(q.error.exitCode,q.error.stdout,q.error.stderr);j(i,P,q.index,$,B)}},exportedEnv:h,get stdin(){return p=!0,d},limits:i.limits,executionScope:c.internalIsExtension?ho(i.executionScope):i.executionScope,exec:(v,$)=>i.execFn(v,$,!1),execWithInheritedStdin:(v,$)=>i.execFn(v,{...$,stdin:d,stdinKind:"bytes"},!0),fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo,coverage:i.coverage,signal:i.state.signal,requireDefenseContext:i.requireDefenseContext,jsBootstrapCode:i.jsBootstrapCode,invokeTool:i.invokeTool},E=c.internalOriginalCommand,b=()=>{};if(E){let v=Object.getOwnPropertyDescriptors(m);v.executionScope={value:i.executionScope,enumerable:!0,configurable:!0,writable:!0};let $=Object.defineProperties(Object.create(Object.getPrototypeOf(m)),v),A=Kc($,E.name),C=Fa(A.context,E.name);b=A.revoke,m.origCommand=N=>{let x=()=>E.execute(N,C);return E.trusted?_e.runTrustedAsync(x):_e.runUntrustedAsync(x)}}let g=Kc(m,t),y=Fa(g.context,t),S=()=>{g.revoke(),b()};try{let v=()=>Ja(i.requireDefenseContext,"command",`${t} execution`,()=>c.execute(n,y)),$=()=>Jh(v,y,S,t,i.executionScope,i.state.signal),A=c.trusted?await _e.runTrustedAsync($):await $();return{...A,internalStdinConsumed:A.internalStdinConsumed??(p?r.length:0)}}catch(v){if(v instanceof k||v instanceof We||v instanceof hn)throw v;return I(`${t}: ${mt(tt(v))}
774
- `)}}async function Wa(e,t){let n=e.state.inCondition;e.state.inCondition=!0;let r=new Ot(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 pr(e,t,n,r){if(e instanceof je)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 Ge)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"continue",stdout:t,stderr:n};if(e instanceof Ie||e instanceof Fe||e instanceof U||e instanceof k)return e.prependOutput(t,n),{action:"rethrow",stdout:t,stderr:n,error:e};let s=tt(e);return{action:"error",stdout:t,stderr:`${n}${s}
775
- `,exitCode:1}}function Jc(e,t){return e!==void 0?{owns:!0,stdin:e}:t!==""?{owns:!0,stdin:t}:{owns:!1}}var Yt=class{ctx;stdoutChunks=[];stderrChunks=[];totalBytes=0;constructor(t){this.ctx=t}append(t,n){let r=F(t)+F(n);r>this.ctx.limits.maxOutputSize-this.totalBytes&&Ut(`total output size exceeded (>${this.ctx.limits.maxOutputSize} bytes), increase executionLimits.maxOutputSize`,"output_size"),t&&this.stdoutChunks.push(t),n&&this.stderrChunks.push(n),this.totalBytes+=r}appendUnaccounted(t,n){this.ctx.executionScope.appendOutput("stdout",t,"control-flow"),this.ctx.executionScope.appendOutput("stderr",n,"control-flow"),this.append(t,n)}replace(t,n){this.stdoutChunks=[],this.stderrChunks=[],this.totalBytes=0,this.append(t,n)}get stdout(){return this.stdoutChunks.join("")}get stderr(){return this.stderrChunks.join("")}build(t){let n=this.stdout,r=this.stderr;return{stdout:n,stderr:r,exitCode:t,internalOutputAccounting:{stdout:F(n),stderr:F(r)}}}};async function 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(Sr(s)||s instanceof Fe||s instanceof U||s instanceof k||s instanceof Rt)throw s.prependOutput(n.stdout,n.stderr),s;return n.appendUnaccounted("",`${tt(s)}
776
- `),n.build(1)}return n.build(r)}async function ef(e,t){return Je(e,t.redirections,"",()=>nm(e,t))}async function nm(e,t){let n=new Yt(e);for(let r of t.clauses){let s=await Wa(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 tf(e,t){return Je(e,t.redirections,"",()=>rm(e,t))}async function rm(e,t){let n=new Yt(e),r=0,s=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return I(`bash: \`${t.variable}': not a valid identifier
777
- `);let i=[];if(t.words===null)i=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)i=[];else try{for(let a of t.words){let o=await ht(e,a);Re(i,o.values,e.limits.maxArrayElements,"for-loop expansion")}}catch(a){if(a instanceof Nt)return{stdout:"",stderr:a.stderr,exitCode:1};throw a}e.state.loopDepth++;try{for(let a of i){s++,s>e.limits.maxLoopIterations&&Ut(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n.stdout,n.stderr),e.state.env.set(t.variable,a);try{for(let o of t.body){let l=await e.executeStatement(o);n.append(l.stdout,l.stderr),r=l.exitCode}}catch(o){let l=pr(o,n.stdout,n.stderr,e.state.loopDepth);if(n.replace(l.stdout,l.stderr),l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return n.build(l.exitCode??1);throw l.error}}}finally{e.state.loopDepth--}return n.build(r)}async function nf(e,t){return Je(e,t.redirections,"",()=>sm(e,t))}async function sm(e,t){let n=t.line;n!==void 0&&(e.state.currentLine=n);let r=new Yt(e),s=0,i=0;t.init&&await K(e,t.init.expression),e.state.loopDepth++;try{for(;i++,i>e.limits.maxLoopIterations&&Ut(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r.stdout,r.stderr),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await K(e,t.condition.expression)===0));){try{for(let a of t.body){let o=await e.executeStatement(a);r.append(o.stdout,o.stderr),s=o.exitCode}}catch(a){let o=pr(a,r.stdout,r.stderr,e.state.loopDepth);if(r.replace(o.stdout,o.stderr),o.action==="break")break;if(o.action==="continue"){t.update&&await K(e,t.update.expression);continue}if(o.action==="error")return r.build(o.exitCode??1);throw o.error}t.update&&await K(e,t.update.expression)}}finally{e.state.loopDepth--}return r.build(s)}async function rf(e,t,n=""){return Je(e,t.redirections,n,r=>im(e,t,n,r))}async function im(e,t,n,r){let s=new Yt(e),i=0,a=0,o=Jc(r.stdin,n),l=e.state.groupStdin;o.owns&&(e.state.groupStdin=o.stdin),e.state.loopDepth++;try{for(;;){a++,a>e.limits.maxLoopIterations&&Ut(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let u=0,c=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let p of t.condition){let h=await e.executeStatement(p);s.append(h.stdout,h.stderr),u=h.exitCode}}catch(p){if(p instanceof je){if(s.append(p.stdout,p.stderr),p.levels>1&&e.state.loopDepth>1)throw p.levels--,p.stdout=s.stdout,p.stderr=s.stderr,e.state.inCondition=d,p;c=!0}else if(p instanceof Ge){if(s.append(p.stdout,p.stderr),p.levels>1&&e.state.loopDepth>1)throw p.levels--,p.stdout=s.stdout,p.stderr=s.stderr,e.state.inCondition=d,p;f=!0}else throw e.state.inCondition=d,p}finally{e.state.inCondition=d}if(c)break;if(!f){if(u!==0)break;try{for(let p of t.body){let h=await e.executeStatement(p);s.append(h.stdout,h.stderr),i=h.exitCode}}catch(p){let h=pr(p,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(h.stdout,h.stderr),h.action==="break")break;if(h.action==="continue")continue;if(h.action==="error")return s.build(h.exitCode??1);throw h.error}}}}finally{e.state.loopDepth--,o.owns&&(e.state.groupStdin=l)}return s.build(i)}async function sf(e,t,n=""){return Je(e,t.redirections,n,r=>am(e,t,n,r))}async function am(e,t,n,r){let s=new Yt(e),i=0,a=0,o=Jc(r.stdin,n),l=e.state.groupStdin;o.owns&&(e.state.groupStdin=o.stdin),e.state.loopDepth++;try{for(;;){a++,a>e.limits.maxLoopIterations&&Ut(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let u=await Wa(e,t.condition);if(s.append(u.stdout,u.stderr),u.exitCode===0)break;try{for(let c of t.body){let f=await e.executeStatement(c);s.append(f.stdout,f.stderr),i=f.exitCode}}catch(c){let f=pr(c,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(f.stdout,f.stderr),f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error")return s.build(f.exitCode??1);throw f.error}}}finally{e.state.loopDepth--,o.owns&&(e.state.groupStdin=l)}return s.build(i)}async function af(e,t){return Je(e,t.redirections,"",()=>om(e,t))}async function om(e,t){let n=new Yt(e),r=0,s=await ne(e,t.word),i=!1;for(let a=0;a<t.items.length;a++){let o=t.items[a],l=i;if(!i)for(let u of o.patterns){let c=await ne(e,u);Iu(u)&&(c=Ke(c));let f=e.state.shoptOptions.nocasematch,d=e.state.shoptOptions.extglob;if(In(s,c,f,d,e.limits.maxCallDepth)){l=!0;break}}if(l){let u=await Va(e,o.body,n);if(n.replace(u.stdout,u.stderr),r=u.exitCode,o.terminator===";;")break;o.terminator===";&"?i=!0:i=!1}else i=!1}return n.build(r)}function za(e,t){if(e.parts.length!==1)return!1;let n=e.parts[0];return n.type!=="Literal"?!1:t.includes(n.value)}async function of(e,t,n){let r=t.timed?_s():0,s="",i=ee,a=0,o=[],l="",u=0,c=t.commands.length>1,f=e.state.lastArg,d=e.state.groupStdin,p=e.state.groupStdinSourceFd;for(let g=0;g<t.commands.length;g++){let y=t.commands[g],S=g===t.commands.length-1,v=g===0;c&&(e.state.lastArg="",e.state.groupStdin=v?d:void 0,e.state.groupStdinSourceFd=v?p:void 0);let $=c&&(!S||!e.state.shoptOptions.lastpipe),A=$?new Map(e.state.env):null,C=$?nt(e.state.arrays):null,N,x=e.executionScope.outputBytesUsed;try{e.state.commandCount=e.executionScope.chargeCommand(),N=await n(y,s)}catch(P){if(P instanceof Ze)N={stdout:P.stdout,stderr:P.stderr,exitCode:1};else if(P instanceof U&&t.commands.length>1)N={stdout:P.stdout,stderr:P.stderr,exitCode:P.exitCode};else if(P instanceof Fe&&t.commands.length>1)N={stdout:P.stdout,stderr:P.stderr,exitCode:P.exitCode};else throw A&&(e.state.env=A,e.state.arrays=C??new Map),P}finally{c&&(v&&(d=e.state.groupStdin,p=e.state.groupStdinSourceFd),e.state.groupStdin=d,e.state.groupStdinSourceFd=p)}if(A&&(e.state.env=A,e.state.arrays=C??new Map),N=e.executionScope.accountResult(N,"pipeline",e.executionScope.outputBytesUsed-x),!S){let P=t.pipeStderr?.[g]??!1,R=N.internalOutputAccounting?.stdout??0,B=P?N.internalOutputAccounting?.stderr??0:0;mo(e.executionScope,R+B,"pipeline"),N={...N,internalOutputAccounting:{stdout:0,stderr:P?0:N.internalOutputAccounting?.stderr??0}}}o.push(N.exitCode),N.exitCode!==0&&(a=N.exitCode),S?i=N:(t.pipeStderr?.[g]??!1?s=tn(N.stderr)+Ct(N):(s=Ct(N),l+=N.stderr,u+=N.internalOutputAccounting?.stderr??0),i={stdout:"",stderr:"",exitCode:N.exitCode})}l&&(i={...i,stderr:l+i.stderr,internalOutputAccounting:{stdout:i.internalOutputAccounting?.stdout??0,stderr:u+(i.internalOutputAccounting?.stderr??0)}});let h=t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand",m=i.internalPipeStatusOverride??o;if(h){ye(e,"PIPESTATUS");for(let g=0;g<m.length;g++)j(e,"PIPESTATUS",g,String(m[g]))}if(e.state.options.pipefail&&a!==0&&(i={...i,exitCode:a}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let y=(_s()-r)/1e3,S=Math.floor(y/60),v=y%60,$;t.timePosix?$=`real ${y.toFixed(2)}
766
+ `),a=1}return L(s,i,a)}async function of(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 lf(e,t){let n=!0,r=e.signal?new AbortController:void 0,s=new WeakMap,i=()=>{if(!n)throw new Ve("",`bash: ${t} used its context after cancellation
767
+ `)},a=f=>{if(f===null||typeof f!="object"&&typeof f!="function")return f;let d=s.get(f);if(d!==void 0)return d;if(typeof f=="object"&&So(f))return f;if(f instanceof Uint8Array){let E=new Uint8Array(f);return s.set(f,E),E}if(f instanceof ArrayBuffer){let E=f.slice(0);return s.set(f,E),E}if(f instanceof Promise){let E=f.then(S=>(i(),a(S)));return s.set(f,E),E}if(typeof f=="function"){let E=function(...S){return i(),a(Reflect.apply(f,this,S))};return s.set(f,E),E}let p=Object.getPrototypeOf(f);if(Array.isArray(f)||p===Object.prototype||p===null){let E=Array.isArray(f)?[]:Object.create(p);s.set(f,E);let S=Object.getOwnPropertyDescriptors(f);for(let y of Object.values(S)){if("value"in y){let g=y.value;y.value=typeof g=="function"?(...b)=>(i(),a(Reflect.apply(g,f,b))):a(g)}if(y.get){let g=y.get;y.get=()=>(i(),a(Reflect.apply(g,f,[])))}if(y.set){let g=y.set;y.set=b=>{i(),Reflect.apply(g,f,[b])}}}return Object.defineProperties(E,S),E}let h=new Map,m=new fo(f,{get(E,S){if(i(),S==="constructor"||S==="prototype"||S==="__proto__")throw new Error(`${t}: unsafe context property access`);let y=Reflect.get(E,S,E);if(typeof y!="function")return a(y);if(h.has(S))return h.get(S);let g=(...b)=>(i(),a(Reflect.apply(y,E,b)));return h.set(S,g),g},set(E,S,y){if(i(),S==="constructor"||S==="prototype"||S==="__proto__")throw new Error(`${t}: unsafe context property access`);return Reflect.set(E,S,y,E)}});return s.set(f,m),m},o=f=>a(f),l=f=>f&&((...d)=>(i(),a(f(...d)))),u=f=>({value:f,enumerable:!0,configurable:!0,writable:!0}),c=Object.getOwnPropertyDescriptors(e);return Object.assign(c,{fs:u(o(e.fs)),env:u(o(e.env)),limits:u(Object.freeze({...e.limits})),exportedEnv:u(e.exportedEnv?Object.freeze({...e.exportedEnv}):void 0),executionScope:u(e.executionScope?o(e.executionScope):void 0),fileDescriptors:u(e.fileDescriptors?o(e.fileDescriptors):void 0),coverage:u(e.coverage?o(e.coverage):void 0),assignShellVariable:u(l(e.assignShellVariable)),exec:u(l(e.exec)),origCommand:u(l(e.origCommand)),execWithInheritedStdin:u(l(e.execWithInheritedStdin)),fetch:u(l(e.fetch)),getRegisteredCommands:u(l(e.getRegisteredCommands)),sleep:u(l(e.sleep)),trace:u(l(e.trace)),invokeTool:u(l(e.invokeTool)),signal:u(r?.signal)}),{context:Object.defineProperties(Object.create(Object.getPrototypeOf(e)),c),revoke(){n=!1,r?.signal.aborted||r?.abort(new Ve("",`bash: ${t} context revoked
768
+ `))}}}async function um(e,t,n,r,s,i){let a=s.remainingTimeMs()??t.limits.maxExecutionTimeMs,o=t.limits.maxExtensionCleanupTimeMs,l,u,c,d=Promise.resolve().then(e).then(h=>({kind:"result",result:h}),h=>({kind:"error",error:h})),p=new Promise(h=>{let m=()=>{n(),h({kind:"abort"})};u=m,i?.addEventListener("abort",m,{once:!0}),i?.aborted&&m(),l=Kn(()=>{n(),h({kind:"deadline"})},a)});try{let h=await Promise.race([d,p]);if(h.kind==="result")return h.result;if(h.kind==="error")throw h.error;n();let m=await Promise.race([d.then(()=>!0),new Promise(S=>{c=Kn(()=>S(!1),o)})]),E=h.kind==="deadline"?new Ve("",`bash: ${r} exceeded its execution deadline
769
+ `):new Ve("",`bash: execution aborted
770
+ `);throw m||s.poisonAfterAbort(E),E}finally{n(),Xn(l),Xn(c),u&&i?.removeEventListener("abort",u)}}async function uf(e,t,n,r,s,i,a,o,l=!1){let{ctx:u,runCommand:c}=e;if(u.coverage&&Vn.has(t)&&u.coverage.hit(`bash:builtin:${t}`),t==="export")return Da(u,n);if(t==="unset")return ja(u,n);if(t==="exit")return Ra(u,n);if(t==="local")return La(u,n);if(t==="set")return Va(u,n);if(t==="break")return zi(u,n);if(t==="continue")return wa(u,n);if(t==="return")return Fa(u,n);if(t==="eval"&&u.state.options.posix)return Ps(u,n,s,l);if(t==="shift")return za(u,n);if(t==="getopts")return Cs(u,n);if(t==="compgen")return pa(u,n);if(t==="complete")return ya(u,n);if(t==="compopt")return ga(u,n);if(t==="pushd")return await Pa(u,n);if(t==="popd")return Ca(u,n);if(t==="dirs")return Na(u,n);if(t==="source"||t===".")return qa(u,n);if(t==="read")return Ma(u,n,s,o);if(t==="mapfile"||t==="readarray")return Ta(u,n,s);if(t==="declare"||t==="typeset")return $a(u,n);if(t==="readonly")return xa(u,n);if(!i){let f=u.state.functions.get(t);if(f)return xs(u,f,n,s,void 0,l)}if(t==="__just_bash_tee_restore"){if(n.length===0||n.length>u.limits.maxArrayElements)return _(`bash: invalid internal pipeline status restore
771
+ `,2);let f=[];for(let h of n){if(!/^(?:0|[1-9][0-9]{0,2})$/.test(h))return _(`bash: invalid internal pipeline status restore
772
+ `,2);let m=Number(h);if(!Number.isSafeInteger(m)||m>255)return _(`bash: invalid internal pipeline status restore
773
+ `,2);f.push(m)}let d=f[f.length-1]??0,p=[...f].reverse().find(h=>h!==0);return{stdout:"",stderr:"",exitCode:u.state.options.pipefail&&p!==void 0?p:d,internalPipeStatusOverride:f}}if(t==="eval")return Ps(u,n,s,l);if(t==="cd")return await qi(u,n);if(t===":"||t==="true")return J;if(t==="false")return ge(!1);if(t==="let")return _a(u,n);if(t==="command")return cm(e,n,s,l);if(t==="builtin")return fm(e,n,s,l);if(t==="shopt")return Hc(u,n);if(t==="exec"){if(n.length===0)return J;let[f,...d]=n;return{...await c(f,d,[],s,!1,!1,-1,l),internalProducerOmitsShellPrefix:!0}}if(t==="wait")return J;if(t==="type")return await rf(u,n,f=>of(u,f),f=>Is(u,f));if(t==="hash")return Ia(u,n);if(t==="help")return Oa(u,n);if(t==="["||t==="test"){let f=n;if(t==="["){if(n[n.length-1]!=="]")return _("[: missing `]'\n",2);f=n.slice(0,-1)}return dr(u,f)}return null}async function cm(e,t,n,r=!1){let{ctx:s,runCommand:i}=e;if(t.length===0)return J;let a=!1,o=!1,l=!1,u=t;for(;u.length>0&&u[0].startsWith("-");){let d=u[0];if(d==="--"){u=u.slice(1);break}for(let p of d.slice(1))p==="p"?a=!0:p==="V"?o=!0:p==="v"&&(l=!0);u=u.slice(1)}if(u.length===0)return J;if(l||o)return await af(s,u,l,o);let[c,...f]=u;return i(c,f,[],n,!0,a,-1,r)}async function fm(e,t,n,r=!1){let{runCommand:s}=e;if(t.length===0)return J;let i=t;if(i[0]==="--"&&(i=i.slice(1),i.length===0))return J;let a=i[0];if(a!=="__just_bash_tee_restore"&&!Vn.has(a))return _(`bash: builtin: ${a}: not a shell builtin
774
+ `);let[,...o]=i;return s(a,o,[],n,!0,!1,-1,r)}async function cf(e,t,n,r,s){let{ctx:i,buildExportedEnv:a,executeUserScript:o}=e,u=await Zc(i,t,s?"/usr/bin:/bin":void 0);if(!u)return ec(t)?_(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
775
+ `,127):_(`bash: ${t}: command not found
776
+ `,127);if("error"in u)return u.error==="permission_denied"?_(`bash: ${t}: Permission denied
777
+ `,126):_(`bash: ${t}: No such file or directory
778
+ `,127);if("script"in u)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u.path)),await o(u.path,n,r);let{cmd:c,path:f}=u;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",p=!1,h=a();i.state.fileDescriptors??=new Map;let m={fs:i.fs,fsIdentity:Us(i.fs),cwd:i.state.cwd,env:i.state.env,assignShellVariable:async(v,$,A)=>{if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v))throw new Error(`${v}: not a valid identifier`);let k=A===void 0?v:`${v}[${A}]`,N=jr(i,v,$);if(N===void 0)throw new Error(`${v}: circular name reference`);if(N===null)return;let x=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(?:\[(.*)\])?$/);if(!x)throw new Error(`${k}: not a valid identifier`);let C=x[1],D=x[2]??A;if(Fe(i,v)||Fe(i,C))throw new Error(`${C}: readonly variable`);if(D===void 0)i.state.env.set(C,$);else{let B=i.state.associativeArrays?.has(C)?"associative":"indexed";if(B==="associative"){U(i,C,D,$,B);return}let H=await Za(i,C,D);if(H.error)throw new q(H.error.exitCode,H.error.stdout,H.error.stderr);U(i,C,H.index,$,B)}},exportedEnv:h,get stdin(){return p=!0,d},limits:i.limits,executionScope:c.internalIsExtension?ko(i.executionScope):i.executionScope,exec:(v,$)=>i.execFn(v,$,!1),execWithInheritedStdin:(v,$)=>i.execFn(v,{...$,stdin:d,stdinKind:"bytes"},!0),fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo,coverage:i.coverage,signal:i.state.signal,requireDefenseContext:i.requireDefenseContext,jsBootstrapCode:i.jsBootstrapCode,invokeTool:i.invokeTool},E=c.internalOriginalCommand,S=()=>{};if(E){let v=Object.getOwnPropertyDescriptors(m);v.executionScope={value:i.executionScope,enumerable:!0,configurable:!0,writable:!0};let $=Object.defineProperties(Object.create(Object.getPrototypeOf(m)),v),A=lf($,E.name),k=Ha(A.context,E.name);S=A.revoke,m.origCommand=N=>{let x=()=>E.execute(N,k);return E.trusted?Le.runTrustedAsync(x):Le.runUntrustedAsync(x)}}let y=lf(m,t),g=Ha(y.context,t),b=()=>{y.revoke(),S()};try{let v=()=>co(i.requireDefenseContext,"command",`${t} execution`,()=>c.execute(n,g)),$=()=>um(v,g,b,t,i.executionScope,i.state.signal),A=c.trusted?await Le.runTrustedAsync($):await $();return{...A,internalStdinConsumed:A.internalStdinConsumed??(p?r.length:0)}}catch(v){if(v instanceof P||v instanceof Ve||v instanceof vn)throw v;return _(`${t}: ${St(nt(v))}
779
+ `)}}async function Qa(e,t){let n=e.state.inCondition;e.state.inCondition=!0;let r=new Wt(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)}var _s=0;function Zn(e,t){return e.state.lastExitCode=t,e.state.env.set("?",String(t)),t}function br(e,t,n,r){if(e instanceof Ge)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"break",stdout:t,stderr:n,exitCode:_s};if(e instanceof He)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"continue",stdout:t,stderr:n,exitCode:_s};if(e instanceof Oe||e instanceof Be||e instanceof q||e instanceof P)return e.prependOutput(t,n),{action:"rethrow",stdout:t,stderr:n,error:e};let s=nt(e);return{action:"error",stdout:t,stderr:`${n}${s}
780
+ `,exitCode:1}}function ff(e,t){return e!==void 0?{owns:!0,stdin:e}:t!==""?{owns:!0,stdin:t}:{owns:!1}}var ln=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&&Jt(`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 Ka(e,t,n){let r=0;try{for(let s of t){let i=await e.executeStatement(s);n.append(i.stdout,i.stderr),r=i.exitCode}}catch(s){if(Pr(s)||s instanceof Be||s instanceof q||s instanceof P||s instanceof Mt)throw s.prependOutput(n.stdout,n.stderr),s;return n.appendUnaccounted("",`${nt(s)}
781
+ `),n.build(1)}return n.build(r)}async function df(e,t){return et(e,t.redirections,"",()=>dm(e,t))}async function dm(e,t){let n=new ln(e);for(let r of t.clauses){let s=await Qa(e,r.condition);if(n.append(s.stdout,s.stderr),s.exitCode===0)return Ka(e,r.body,n)}return t.elseBody?Ka(e,t.elseBody,n):n.build(0)}async function pf(e,t){return et(e,t.redirections,"",()=>pm(e,t))}async function pm(e,t){let n=new ln(e),r=0,s=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return _(`bash: \`${t.variable}': not a valid identifier
782
+ `);let i=[];if(t.words===null)i=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)i=[];else try{for(let a of t.words){let o=await Et(e,a);Re(i,o.values,e.limits.maxArrayElements,"for-loop expansion")}}catch(a){if(a instanceof Tt)return{stdout:"",stderr:a.stderr,exitCode:1};throw a}e.state.loopDepth++;try{for(let a of i){s++,s>e.limits.maxLoopIterations&&Jt(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n.stdout,n.stderr),e.state.env.set(t.variable,a);try{for(let o of t.body){let l=await e.executeStatement(o);n.append(l.stdout,l.stderr),r=l.exitCode}}catch(o){let l=br(o,n.stdout,n.stderr,e.state.loopDepth);if(n.replace(l.stdout,l.stderr),l.exitCode!==void 0&&(r=Zn(e,l.exitCode)),l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return n.build(l.exitCode??1);throw l.error}}}finally{e.state.loopDepth--}return n.build(r)}async function hf(e,t){return et(e,t.redirections,"",()=>hm(e,t))}async function hm(e,t){let n=t.line;n!==void 0&&(e.state.currentLine=n);let r=new ln(e),s=0,i=0;t.init&&await X(e,t.init.expression),e.state.loopDepth++;try{for(;i++,i>e.limits.maxLoopIterations&&Jt(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r.stdout,r.stderr),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await X(e,t.condition.expression)===0));){try{for(let a of t.body){let o=await e.executeStatement(a);r.append(o.stdout,o.stderr),s=o.exitCode}}catch(a){let o=br(a,r.stdout,r.stderr,e.state.loopDepth);if(r.replace(o.stdout,o.stderr),o.exitCode!==void 0&&(s=Zn(e,o.exitCode)),o.action==="break")break;if(o.action==="continue"){t.update&&await X(e,t.update.expression);continue}if(o.action==="error")return r.build(o.exitCode??1);throw o.error}t.update&&await X(e,t.update.expression)}}finally{e.state.loopDepth--}return r.build(s)}async function mf(e,t,n=""){return et(e,t.redirections,n,r=>mm(e,t,n,r))}async function mm(e,t,n,r){let s=new ln(e),i=0,a=0,o=ff(r.stdin,n),l=e.state.groupStdin;o.owns&&(e.state.groupStdin=o.stdin),e.state.loopDepth++;try{for(;;){a++,a>e.limits.maxLoopIterations&&Jt(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let u=0,c=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let p of t.condition){let h=await e.executeStatement(p);s.append(h.stdout,h.stderr),u=h.exitCode}}catch(p){if(p instanceof Ge){if(s.append(p.stdout,p.stderr),p.levels>1&&e.state.loopDepth>1)throw p.levels--,p.stdout=s.stdout,p.stderr=s.stderr,e.state.inCondition=d,p;c=!0}else if(p instanceof He){if(s.append(p.stdout,p.stderr),p.levels>1&&e.state.loopDepth>1)throw p.levels--,p.stdout=s.stdout,p.stderr=s.stderr,e.state.inCondition=d,p;f=!0}else throw e.state.inCondition=d,p}finally{e.state.inCondition=d}if((c||f)&&(i=Zn(e,_s)),c)break;if(!f){if(u!==0)break;try{for(let p of t.body){let h=await e.executeStatement(p);s.append(h.stdout,h.stderr),i=h.exitCode}}catch(p){let h=br(p,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(h.stdout,h.stderr),h.exitCode!==void 0&&(i=Zn(e,h.exitCode)),h.action==="break")break;if(h.action==="continue")continue;if(h.action==="error")return s.build(h.exitCode??1);throw h.error}}}}finally{e.state.loopDepth--,o.owns&&(e.state.groupStdin=l)}return s.build(i)}async function yf(e,t,n=""){return et(e,t.redirections,n,r=>ym(e,t,n,r))}async function ym(e,t,n,r){let s=new ln(e),i=0,a=0,o=ff(r.stdin,n),l=e.state.groupStdin;o.owns&&(e.state.groupStdin=o.stdin),e.state.loopDepth++;try{for(;;){a++,a>e.limits.maxLoopIterations&&Jt(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let u=await Qa(e,t.condition);if(s.append(u.stdout,u.stderr),u.exitCode===0)break;try{for(let c of t.body){let f=await e.executeStatement(c);s.append(f.stdout,f.stderr),i=f.exitCode}}catch(c){let f=br(c,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(f.stdout,f.stderr),f.exitCode!==void 0&&(i=Zn(e,f.exitCode)),f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error")return s.build(f.exitCode??1);throw f.error}}}finally{e.state.loopDepth--,o.owns&&(e.state.groupStdin=l)}return s.build(i)}async function gf(e,t){return et(e,t.redirections,"",()=>gm(e,t))}async function gm(e,t){let n=new ln(e),r=0,s=await ne(e,t.word),i=!1;for(let a=0;a<t.items.length;a++){let o=t.items[a],l=i;if(!i)for(let u of o.patterns){let c=await ne(e,u);qu(u)&&(c=Xe(c));let f=e.state.shoptOptions.nocasematch,d=e.state.shoptOptions.extglob;if(Wn(s,c,f,d,e.limits.maxCallDepth)){l=!0;break}}if(l){let u=await Ka(e,o.body,n);if(n.replace(u.stdout,u.stderr),r=u.exitCode,o.terminator===";;")break;o.terminator===";&"?i=!0:i=!1}else i=!1}return n.build(r)}function Xa(e,t){if(e.parts.length!==1)return!1;let n=e.parts[0];return n.type!=="Literal"?!1:t.includes(n.value)}async function wf(e,t,n){let r=t.timed?Vs():0,s="",i=J,a=0,o=[],l="",u=0,c=t.commands.length>1,f=e.state.lastArg,d=e.state.groupStdin,p=e.state.groupStdinSourceFd;for(let y=0;y<t.commands.length;y++){let g=t.commands[y],b=y===t.commands.length-1,v=y===0;c&&(e.state.lastArg="",e.state.groupStdin=v?d:void 0,e.state.groupStdinSourceFd=v?p:void 0);let $=c&&(!b||!e.state.shoptOptions.lastpipe),A=$?new Map(e.state.env):null,k=$?st(e.state.arrays):null,N,x=e.executionScope.outputBytesUsed;try{e.state.commandCount=e.executionScope.chargeCommand(),N=await n(g,s)}catch(C){if(C instanceof Ze)N={stdout:C.stdout,stderr:C.stderr,exitCode:1};else if(C instanceof q&&t.commands.length>1)N={stdout:C.stdout,stderr:C.stderr,exitCode:C.exitCode};else if(C instanceof Be&&t.commands.length>1)N={stdout:C.stdout,stderr:C.stderr,exitCode:C.exitCode};else throw A&&(e.state.env=A,e.state.arrays=k??new Map),C}finally{c&&(v&&(d=e.state.groupStdin,p=e.state.groupStdinSourceFd),e.state.groupStdin=d,e.state.groupStdinSourceFd=p)}if(A&&(e.state.env=A,e.state.arrays=k??new Map),N=e.executionScope.accountResult(N,"pipeline",e.executionScope.outputBytesUsed-x),!b){let C=t.pipeStderr?.[y]??!1,D=N.internalOutputAccounting?.stdout??0,B=C?N.internalOutputAccounting?.stderr??0:0;Po(e.executionScope,D+B,"pipeline"),N={...N,internalOutputAccounting:{stdout:0,stderr:C?0:N.internalOutputAccounting?.stderr??0}}}o.push(N.exitCode),N.exitCode!==0&&(a=N.exitCode),b?i=N:(t.pipeStderr?.[y]??!1?s=cn(N.stderr)+Lt(N):(s=Lt(N),l+=N.stderr,u+=N.internalOutputAccounting?.stderr??0),i={stdout:"",stderr:"",exitCode:N.exitCode})}l&&(i={...i,stderr:l+i.stderr,internalOutputAccounting:{stdout:i.internalOutputAccounting?.stdout??0,stderr:u+(i.internalOutputAccounting?.stderr??0)}});let h=t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand",m=i.internalPipeStatusOverride??o;if(h){ye(e,"PIPESTATUS");for(let y=0;y<m.length;y++)U(e,"PIPESTATUS",y,String(m[y]))}if(e.state.options.pipefail&&a!==0&&(i={...i,exitCode:a}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let g=(Vs()-r)/1e3,b=Math.floor(g/60),v=g%60,$;t.timePosix?$=`real ${g.toFixed(2)}
778
783
  user 0.00
779
784
  sys 0.00
780
785
  `:$=`
781
- real ${`${S}m${v.toFixed(3)}s`}
786
+ real ${`${b}m${v.toFixed(3)}s`}
782
787
  user 0m0.000s
783
788
  sys 0m0.000s
784
- `,i={...i,stderr:i.stderr+$}}c&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=f),i=e.executionScope.accountResult(i,"pipeline");let{internalPipeStatusOverride:E,...b}=i;return b}function qa(e){return e?{...e,options:e.options?[...e.options]:void 0,actions:e.actions?[...e.actions]:void 0}:void 0}function lm(e){return e?new Map(Array.from(e,([t,n])=>[t,qa(n)])):void 0}function um(e){if(!e)return;let t=new Map,n=new Map;for(let[r,s]of e){let i=t.get(s);i||(i=new Set(s),t.set(s,i)),n.set(r,i)}return n}function cm(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 fm(e){return e?new Map(Array.from(e,([t,n])=>[t,n.map(r=>({...r}))])):void 0}function Ua(e){let t={env:e.env,arrays:e.arrays,cwd:e.cwd,previousDir:e.previousDir,lastExitCode:e.lastExitCode,lastArg:e.lastArg,currentLine:e.currentLine,options:e.options,shoptOptions:e.shoptOptions,fileDescriptors:e.fileDescriptors,inputFds:e.inputFds,fdAliases:e.fdAliases,closedStandardFds:e.closedStandardFds,nextFd:e.nextFd,readonlyVars:e.readonlyVars,associativeArrays:e.associativeArrays,namerefs:e.namerefs,boundNamerefs:e.boundNamerefs,invalidNamerefs:e.invalidNamerefs,integerVars:e.integerVars,lowercaseVars:e.lowercaseVars,uppercaseVars:e.uppercaseVars,exportedVars:e.exportedVars,tempExportedVars:e.tempExportedVars,localExportedVars:e.localExportedVars,declaredVars:e.declaredVars,localScopes:e.localScopes,localArrayScopes:e.localArrayScopes,localVarDepth:e.localVarDepth,localVarStack:e.localVarStack,fullyUnsetLocals:e.fullyUnsetLocals,tempEnvBindings:e.tempEnvBindings,mutatedTempEnvVars:e.mutatedTempEnvVars,accessedTempEnvVars:e.accessedTempEnvVars,functions:e.functions,callDepth:e.callDepth,sourceDepth:e.sourceDepth,callLineStack:e.callLineStack,funcNameStack:e.funcNameStack,sourceStack:e.sourceStack,currentSource:e.currentSource,inCondition:e.inCondition,loopDepth:e.loopDepth,parentHasLoopContext:e.parentHasLoopContext,errexitSafe:e.errexitSafe,directoryStack:e.directoryStack,hashTable:e.hashTable,completionSpecs:e.completionSpecs,defaultCompletionSpec:e.defaultCompletionSpec,emptyCompletionSpec:e.emptyCompletionSpec,groupStdin:e.groupStdin,groupStdinSourceFd:e.groupStdinSourceFd,bashPid:e.bashPid,expansionExitCode:e.expansionExitCode,expansionStderr:e.expansionStderr};e.env=new Map(e.env),e.arrays=nt(e.arrays),e.options={...e.options},e.shoptOptions={...e.shoptOptions},e.fileDescriptors=e.fileDescriptors?new Map(e.fileDescriptors):void 0,e.inputFds=e.inputFds?new Set(e.inputFds):void 0,e.fdAliases=um(e.fdAliases),e.closedStandardFds=e.closedStandardFds?new Set(e.closedStandardFds):void 0,e.readonlyVars=new Set(e.readonlyVars),e.associativeArrays=new Set(e.associativeArrays),e.namerefs=new Set(e.namerefs),e.boundNamerefs=new Set(e.boundNamerefs),e.invalidNamerefs=new Set(e.invalidNamerefs),e.integerVars=new Set(e.integerVars),e.lowercaseVars=new Set(e.lowercaseVars),e.uppercaseVars=new Set(e.uppercaseVars),e.exportedVars=new Set(e.exportedVars),e.tempExportedVars=new Set(e.tempExportedVars),e.localExportedVars=e.localExportedVars?.map(r=>new Set(r)),e.declaredVars=new Set(e.declaredVars),e.localScopes=e.localScopes.map(r=>new Map(r)),e.localArrayScopes=cm(e.localArrayScopes),e.localVarDepth=e.localVarDepth?new Map(e.localVarDepth):void 0,e.localVarStack=fm(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=lm(e.completionSpecs),e.defaultCompletionSpec=qa(e.defaultCompletionSpec),e.emptyCompletionSpec=qa(e.emptyCompletionSpec);let n=!1;return()=>{n||(n=!0,Object.assign(e,t))}}async function lf(e,t,n,r,s=!1){let i=e.state.loopDepth,a=new Map;for(let l of e.state.fileDescriptors?.keys()??[]){let u=Ye(e,l);u&&a.set(l,u)}let o=Ua(e.state);e.state.parentHasLoopContext=i>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++;try{return await Je(e,t.redirections,n,l=>dm(e,t,l.stdin??n,r,s||l.stdin!==void 0))}finally{let l=new Map;for(let[u,c]of a){let f=Ye(e,u),d=c.kind==="input"&&f?.kind==="input"?c.content.length-f.content.length:c.kind==="readwrite"&&f?.kind==="readwrite"&&c.path===f.path?f.position-c.position:0;if(d<=0)continue;let p=Math.min(...Zt(e,u));l.set(p,Math.max(l.get(p)??0,d))}o();for(let[u,c]of l)Ht(e,u,c)}}async function dm(e,t,n,r,s){(s||n)&&(e.state.groupStdin=n);let i=new Ot(e.executionScope,"subshell"),a=0;try{for(let o of t.body){let l=await r(o);i.appendResult(l),a=l.exitCode}}catch(o){if(o instanceof k)throw i.prependTo(o),o;return o instanceof Rt||o instanceof je||o instanceof Ge?(i.append("stdout",o.stdout,o.internalOutputAccounting.stdout),i.append("stderr",o.stderr,o.internalOutputAccounting.stderr),i.build(0)):o instanceof U||o instanceof Ie||o instanceof Fe?(i.append("stdout",o.stdout,o.internalOutputAccounting.stdout),i.append("stderr",o.stderr,o.internalOutputAccounting.stderr),i.build(o.exitCode)):(i.append("stderr",`${tt(o)}
785
- `),i.build(1))}return i.build(a)}async function uf(e,t,n,r,s=!1){return Je(e,t.redirections,n,i=>pm(e,t,n,r,s,i))}async function pm(e,t,n,r,s,i){let a=new Ot(e.executionScope,"group"),o=0,l=i.stdin??n,u=s||n!==""||i.stdin!==void 0,c=e.state.groupStdin;u&&(e.state.groupStdin=l);let f=()=>{(u||c!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=c)};try{for(let d of t.body){let p=await r(d);a.appendResult(p),o=p.exitCode}}catch(d){if(f(),d instanceof k)throw a.prependTo(d),d;if(Sr(d)||d instanceof Fe||d instanceof U)throw d.prependOutput(a.stdout,a.stderr),d;return a.append("stderr",`${tt(d)}
786
- `),a.build(1)}return f(),a.build(o)}async function cf(e,t,n,r,s){let i;try{i=await e.fs.readFile(t)}catch{return I(`bash: ${t}: No such file or directory
789
+ `,i={...i,stderr:i.stderr+$}}c&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=f),i=e.executionScope.accountResult(i,"pipeline");let{internalPipeStatusOverride:E,...S}=i;return S}function Ya(e){return e?{...e,options:e.options?[...e.options]:void 0,actions:e.actions?[...e.actions]:void 0}:void 0}function wm(e){return e?new Map(Array.from(e,([t,n])=>[t,Ya(n)])):void 0}function Em(e){if(!e)return;let t=new Map,n=new Map;for(let[r,s]of e){let i=t.get(s);i||(i=new Set(s),t.set(s,i)),n.set(r,i)}return n}function bm(e){return e?.map(t=>new Map(Array.from(t,([n,r])=>[n,r?{kind:r.kind,elements:new Map(r.elements)}:void 0])))}function Sm(e){return e?new Map(Array.from(e,([t,n])=>[t,n.map(r=>({...r}))])):void 0}function Ja(e){let t={env:e.env,arrays:e.arrays,cwd:e.cwd,previousDir:e.previousDir,lastExitCode:e.lastExitCode,lastArg:e.lastArg,currentLine:e.currentLine,options:e.options,shoptOptions:e.shoptOptions,fileDescriptors:e.fileDescriptors,inputFds:e.inputFds,fdAliases:e.fdAliases,closedStandardFds:e.closedStandardFds,nextFd:e.nextFd,readonlyVars:e.readonlyVars,associativeArrays:e.associativeArrays,namerefs:e.namerefs,boundNamerefs:e.boundNamerefs,invalidNamerefs:e.invalidNamerefs,integerVars:e.integerVars,lowercaseVars:e.lowercaseVars,uppercaseVars:e.uppercaseVars,exportedVars:e.exportedVars,tempExportedVars:e.tempExportedVars,localExportedVars:e.localExportedVars,declaredVars:e.declaredVars,localScopes:e.localScopes,localArrayScopes:e.localArrayScopes,localVarDepth:e.localVarDepth,localVarStack:e.localVarStack,fullyUnsetLocals:e.fullyUnsetLocals,tempEnvBindings:e.tempEnvBindings,mutatedTempEnvVars:e.mutatedTempEnvVars,accessedTempEnvVars:e.accessedTempEnvVars,functions:e.functions,callDepth:e.callDepth,sourceDepth:e.sourceDepth,callLineStack:e.callLineStack,funcNameStack:e.funcNameStack,sourceStack:e.sourceStack,currentSource:e.currentSource,inCondition:e.inCondition,loopDepth:e.loopDepth,parentHasLoopContext:e.parentHasLoopContext,errexitSafe:e.errexitSafe,directoryStack:e.directoryStack,hashTable:e.hashTable,completionSpecs:e.completionSpecs,defaultCompletionSpec:e.defaultCompletionSpec,emptyCompletionSpec:e.emptyCompletionSpec,groupStdin:e.groupStdin,groupStdinSourceFd:e.groupStdinSourceFd,bashPid:e.bashPid,expansionExitCode:e.expansionExitCode,expansionStderr:e.expansionStderr};e.env=new Map(e.env),e.arrays=st(e.arrays),e.options={...e.options},e.shoptOptions={...e.shoptOptions},e.fileDescriptors=e.fileDescriptors?new Map(e.fileDescriptors):void 0,e.inputFds=e.inputFds?new Set(e.inputFds):void 0,e.fdAliases=Em(e.fdAliases),e.closedStandardFds=e.closedStandardFds?new Set(e.closedStandardFds):void 0,e.readonlyVars=new Set(e.readonlyVars),e.associativeArrays=new Set(e.associativeArrays),e.namerefs=new Set(e.namerefs),e.boundNamerefs=new Set(e.boundNamerefs),e.invalidNamerefs=new Set(e.invalidNamerefs),e.integerVars=new Set(e.integerVars),e.lowercaseVars=new Set(e.lowercaseVars),e.uppercaseVars=new Set(e.uppercaseVars),e.exportedVars=new Set(e.exportedVars),e.tempExportedVars=new Set(e.tempExportedVars),e.localExportedVars=e.localExportedVars?.map(r=>new Set(r)),e.declaredVars=new Set(e.declaredVars),e.localScopes=e.localScopes.map(r=>new Map(r)),e.localArrayScopes=bm(e.localArrayScopes),e.localVarDepth=e.localVarDepth?new Map(e.localVarDepth):void 0,e.localVarStack=Sm(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=wm(e.completionSpecs),e.defaultCompletionSpec=Ya(e.defaultCompletionSpec),e.emptyCompletionSpec=Ya(e.emptyCompletionSpec);let n=!1;return()=>{n||(n=!0,Object.assign(e,t))}}async function Ef(e,t,n,r,s=!1){let i=e.state.loopDepth,a=new Map;for(let l of e.state.fileDescriptors?.keys()??[]){let u=Je(e,l);u&&a.set(l,u)}let o=Ja(e.state);e.state.parentHasLoopContext=i>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++;try{return await et(e,t.redirections,n,l=>Am(e,t,l.stdin??n,r,s||l.stdin!==void 0))}finally{let l=new Map;for(let[u,c]of a){let f=Je(e,u),d=c.kind==="input"&&f?.kind==="input"?c.content.length-f.content.length:c.kind==="readwrite"&&f?.kind==="readwrite"&&c.path===f.path?f.position-c.position:0;if(d<=0)continue;let p=Math.min(...nn(e,u));l.set(p,Math.max(l.get(p)??0,d))}o();for(let[u,c]of l)rn(e,u,c)}}async function Am(e,t,n,r,s){(s||n)&&(e.state.groupStdin=n);let i=new Wt(e.executionScope,"subshell"),a=0;try{for(let o of t.body){let l=await r(o);i.appendResult(l),a=l.exitCode}}catch(o){if(o instanceof P)throw i.prependTo(o),o;return o instanceof Mt||o instanceof Ge||o instanceof He?(i.append("stdout",o.stdout,o.internalOutputAccounting.stdout),i.append("stderr",o.stderr,o.internalOutputAccounting.stderr),i.build(0)):o instanceof q||o instanceof Oe||o instanceof Be?(i.append("stdout",o.stdout,o.internalOutputAccounting.stdout),i.append("stderr",o.stderr,o.internalOutputAccounting.stderr),i.build(o.exitCode)):(i.append("stderr",`${nt(o)}
790
+ `),i.build(1))}return i.build(a)}async function bf(e,t,n,r,s=!1){return et(e,t.redirections,n,i=>vm(e,t,n,r,s,i))}async function vm(e,t,n,r,s,i){let a=new Wt(e.executionScope,"group"),o=0,l=i.stdin??n,u=s||n!==""||i.stdin!==void 0,c=e.state.groupStdin;u&&(e.state.groupStdin=l);let f=()=>{(u||c!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=c)};try{for(let d of t.body){let p=await r(d);a.appendResult(p),o=p.exitCode}}catch(d){if(f(),d instanceof P)throw a.prependTo(d),d;if(Pr(d)||d instanceof Be||d instanceof q)throw d.prependOutput(a.stdout,a.stderr),d;return a.append("stderr",`${nt(d)}
791
+ `),a.build(1)}return f(),a.build(o)}async function Sf(e,t,n,r,s){let i;try{i=await e.fs.readFile(t)}catch{return _(`bash: ${t}: No such file or directory
787
792
  `,127)}if(i.startsWith("#!")){let l=i.indexOf(`
788
- `);l!==-1&&(i=i.slice(l+1))}let a=e.state.loopDepth,o=Ua(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 u=new G().parse(i),c=await s(u);return o(),c}catch(l){if(o(),l instanceof U)return L(l.stdout,l.stderr,l.exitCode);if(l instanceof k)throw l;if(l.name==="ParseException")return I(`bash: ${t}: ${l.message}
789
- `);throw l}}function hm(e){throw new TypeError(`Unsupported command node: ${JSON.stringify(e)}`)}var hr=class{ctx;constructor(t,n){this.ctx={state:n,fs:t.fs,commands:t.commands,limits:t.limits,executionScope:t.executionScope,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode,invokeTool:t.invokeTool}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||_e.isInSandboxedContext())return;let n=`interpreter ${t} attempted outside defense context`;throw new hn(n,{timestamp:Date.now(),type:"missing_defense_context",message:n,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:_e.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,n=this.ctx.state.tempExportedVars,r=new Set;if(t)for(let i of t)r.add(i);if(n)for(let i of n)r.add(i);if(r.size===0)return Object.create(null);let s=Object.create(null);for(let i of r){let 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 Ot(this.ctx.executionScope,"script");for(let s of t.statements)try{let i=await this.executeStatement(s);r.appendResult(i,Is(i)),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(i){if(i instanceof U)throw i.prependOutput(r.stdout,r.stderr),i;if(i instanceof et)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:It(this.ctx.state.env)};if(i instanceof k)throw r.prependTo(i),i;if(i instanceof Fe)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:It(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:It(this.ctx.state.env)};if(i instanceof Ze)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:It(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 br){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 je||i instanceof Ge){if(this.ctx.state.loopDepth>0)throw i.prependOutput(r.stdout,r.stderr),i;r.append("stdout",i.stdout),r.append("stderr",i.stderr);continue}throw i instanceof Ie&&i.prependOutput(r.stdout,r.stderr),i}return{...r.build(n),env:It(this.ctx.state.env)}}async executeUserScript(t,n,r=""){return cf(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 $e(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return ee;this.ctx.state.errexitSafe=!1;let n=new Ot(this.ctx.executionScope,"statement");this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&n.append("stderr",`${t.sourceText}
790
- `);let r=0,s=-1,i=!1;try{for(let l=0;l<t.pipelines.length;l++){let u=t.pipelines[l],c=l>0?t.operators[l-1]:null;if(c==="&&"&&r!==0||c==="||"&&r===0)continue;let f=await this.executePipeline(u);n.appendResult(f,Is(f)),r=f.exitCode,s=l,i=u.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}}catch(l){throw n.prependTo(l),l}let 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 Fe(r);throw l.prependOutput(n.stdout,n.stderr),l}return n.build(r)}async executePipeline(t){return of(this.ctx,t,(n,r)=>this.executeCommand(n,r))}async executeCommand(t,n,r=!1){let s=Ru(this.ctx),i;try{i=await this.executeCommandInner(t,n,r)}catch(o){throw await Ni(this.ctx,s).catch(()=>{}),o}let a=await Ni(this.ctx,s);return!a.stdout&&!a.stderr?i:{...i,stdout:a.stdout?Ct(i)+a.stdout:i.stdout,stdoutKind:a.stdout?"bytes":i.stdoutKind,stderr:i.stderr+a.stderr}}async executeCommandInner(t,n,r){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,n);case"If":return ef(this.ctx,t);case"For":return tf(this.ctx,t);case"CStyleFor":return nf(this.ctx,t);case"While":return rf(this.ctx,t,n);case"Until":return sf(this.ctx,t,n);case"Case":return af(this.ctx,t);case"Subshell":return this.executeSubshell(t,n,r);case"Group":return this.executeGroup(t,n,r);case"FunctionDef":return fc(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return hm(t)}}async executeSimpleCommand(t,n){let r;try{return await this.executeSimpleCommandInner(t,n,s=>{r=s})}catch(s){if(r?.finish(),s instanceof Nt)return I(s.stderr);throw s}}async executeSimpleCommandInner(t,n,r){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let x=t,P=0;for(;;){let R=this.expandAlias(x);if(R===x)break;if(P>=this.ctx.limits.maxCallDepth)throw new k(`alias expansion depth limit exceeded (${this.ctx.limits.maxCallDepth})`,"recursion");P++,x=R}this.aliasExpansionStack.clear(),x!==t&&(t=x)}this.ctx.state.expansionStderr="";let s=await zc(this.ctx,t);if(s.error)return s.error;let i=s.tempAssignments,a=s.xtraceOutput,o=()=>{for(let[x,P]of i)P===void 0?this.ctx.state.env.delete(x):this.ctx.state.env.set(x,P)};if(!t.name){if(t.redirections.length>0){let P=Tn(this.ctx,t.redirections,uc);r(P);let R=await P.prepare(n);if(R.error){if(o(),!R.errorCause)return P.finish(),R.error;try{return Mn(R)}finally{P.finish()}}let B=L("",a,0),q=await Kt(this.ctx,B,t.redirections,R.targets,R.dupSources,R.standardRoutes);return P.finish(),q}this.ctx.state.lastArg="";let x=(this.ctx.state.expansionStderr||"")+a;return this.ctx.state.expansionStderr="",L("",x,this.ctx.state.lastExitCode)}let l=t.name&&za(t.name,["local","declare","typeset","export","readonly"]),u=Array.from(i.keys());if(u.length>0&&!l){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let x of u)this.ctx.state.tempExportedVars.add(x)}let c=await ne(this.ctx,t.name),f=[],d=[],p=(x,P)=>{if(f.length>=this.ctx.limits.maxArrayElements)throw new k(`expanded argument element limit exceeded (${this.ctx.limits.maxArrayElements})`,"array_elements");f.push(x),d.push(P)};if(za(t.name,["local","declare","typeset","export","readonly"])&&(c==="local"||c==="declare"||c==="typeset"||c==="export"||c==="readonly"))for(let x of t.args){let P=await Vu(this.ctx,x);if(P)p(P,!0);else{let R=await zu(this.ctx,x);if(R!==null)p(R,!0);else{let B=await ht(this.ctx,x);for(let q of B.values)p(q,B.quoted)}}}else for(let x of t.args){let P=await ht(this.ctx,x);for(let R of P.values)p(R,P.quoted)}let m=t.name.parts.every(x=>x.type==="CommandSubstitution"||x.type==="ParameterExpansion"||x.type==="ArithmeticExpansion");!c&&m&&f.length>0&&(c=f.shift(),d.shift());let E=Tn(this.ctx,t.redirections,c==="exec"?cc:ar);r(E);let b=await E.prepare(n);if(b.error)return o(),b.errorCause?Mn(b):(E.finish(),b.error);let g=b.stdinSourceFd,y=b.stdin!==void 0;if(b.stdin!==void 0&&(n=b.stdin),!c)return m?(E.finish(),L("","",this.ctx.state.lastExitCode)):(E.finish(),I(`bash: : command not found
791
- `,127));if(c==="exec"&&(f.length===0||f[0]==="--")){for(let[x,P]of i)P===void 0?this.ctx.state.env.delete(x):this.ctx.state.env.set(x,P);if(this.ctx.state.tempExportedVars)for(let x of i.keys())this.ctx.state.tempExportedVars.delete(x);return E.finish(),ee}if(this.ctx.state.extraArgs){let x=this.ctx.state.extraArgs;this.ctx.state.extraArgs=void 0;for(let P of x)p(P,!0)}let S=await Wc(this.ctx,c,f);i.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(i)));let v,$=null;try{v=await this.runCommand(c,f,d,n,!1,!1,g,y)}catch(x){if(x instanceof je||x instanceof Ge)$=x,v=ee;else throw x}g>=0&&c!=="read"&&Ht(this.ctx,g,v.internalStdinConsumed??0);let A=a+S;if(A&&(v={...v,stderr:A+v.stderr}),v=await Kt(this.ctx,v,t.redirections,b.targets,b.dupSources,b.standardRoutes,v.internalProducerCommand??c,v.internalProducerOmitsShellPrefix),E.finish(),$)throw $;if(f.length>0){let x=f[f.length-1];if((c==="declare"||c==="local"||c==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(x)){let P=x.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);P&&(x=P[1])}this.ctx.state.lastArg=x}else this.ctx.state.lastArg=c;let C=rc(c)&&c!=="unset"&&c!=="eval";if(!this.ctx.state.options.posix||!C)for(let[x,P]of i)this.ctx.state.fullyUnsetLocals?.has(x)||(P===void 0?this.ctx.state.env.delete(x):this.ctx.state.env.set(x,P));if(this.ctx.state.tempExportedVars)for(let x of i.keys())this.ctx.state.tempExportedVars.delete(x);return i.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(v={...v,stderr:this.ctx.state.expansionStderr+v.stderr},this.ctx.state.expansionStderr=""),v}async runCommand(t,n,r,s,i=!1,a=!1,o=-1,l=!1){let u={ctx:this.ctx,runCommand:(d,p,h,m,E,b,g,y)=>this.runCommand(d,p,h,m,E,b,g,y),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(d,p,h)=>this.executeUserScript(d,p,h)},c=await Xc(u,t,n,r,s,i,a,o,l);return c!==null?c.internalProducerCommand===void 0?{...c,internalProducerCommand:t}:c:{...await Yc(u,t,n,s,a),internalProducerCommand:t}}aliasExpansionStack=new Set;expandAlias(t){return pl({env:this.ctx.state.env,limits:this.ctx.limits},t,this.aliasExpansionStack)}async findCommandInPath(t){return $s(this.ctx,t)}async executeSubshell(t,n="",r=!1){return lf(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeGroup(t,n="",r=!1){return uf(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeArithmeticCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),Je(this.ctx,t.redirections,"",async()=>{try{let n=await K(this.ctx,t.expression.expression),r=ge(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){return I(`bash: arithmetic expression: ${n.message}
792
- `)}})}async executeConditionalCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),Je(this.ctx,t.redirections,"",async()=>{try{let n=await jt(this.ctx,t.expression),r=ge(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){let r=n instanceof oe?1:2;return I(`bash: conditional expression: ${n.message}
793
- `,r)}})}};import{lookup as km}from"node:dns";function ja(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function mm(e){let t=ja(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var ym=3;function ff(e){let t=e;for(let n=0;n<ym;n++){if(t.includes("\\")||t.includes(";")||/%(?![0-9a-f]{2})/i.test(t))return!0;let r=t.toLowerCase();if(r.includes("%2f")||r.includes("%2e")||r.includes("%5c")||r.includes("%3b"))return!0;let s;try{s=decodeURIComponent(t)}catch{return!0}if(s===t)return!1;t=s}return t.includes("%")}function gm(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function Ga(e,t){let n=ja(e);if(!n)return!1;let r=mm(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&ff(n.pathname)?!1:gm(n.pathname,r.pathPrefix)}function df(e){return typeof e=="string"?e:e.url}function pf(e,t){return!t||t.length===0?!1:t.some(n=>Ga(e,df(n)))}function Za(e){let t=wm(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=hf(t);if(n)return ks(n);let r=bm(t);return r?Sm(r):!1}function wm(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function Em(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 hf(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>Em(l));if(n.some(l=>l===null))return null;let r=n;if(t.length===1){let l=r[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,u]=r;return l>255||u>16777215?null:[l,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[l,u,c]=r;return l>255||u>255||c>65535?null:[l,u,c>>>8&255,c&255]}let[s,i,a,o]=r;return s>255||i>255||a>255||o>255?null:[s,i,a,o]}function bm(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=hf(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,u=a.map(l),c=o.map(l);if(u.some(m=>m===null)||c.some(m=>m===null))return null;let f=n?2:0,d=u.length+c.length+f,p=0;if(r===1){if(p=8-d,p<0)return null}else if(d!==8)return null;let h=[...u,...new Array(p).fill(0),...c];return n&&(h.push(n[0]<<8|n[1]),h.push(n[2]<<8|n[3])),h.length===8?h:null}function ks(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 Sm(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 ks(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 ks(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 ks(s)}return!1}function mf(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=df(n);if(!ja(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!==""&&ff(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 Am=typeof __BROWSER__<"u"&&__BROWSER__,Jt=class extends Error{constructor(){super("DNS pinning is unavailable in this runtime"),this.name="DnsPinningUnavailableError"}};function vm(e){return"Agent"in e?e:e.default}function $m(e){let t=new Error(`ENOTFOUND ${e}`);return t.code="ENOTFOUND",t.errno=-3008,t.syscall="getaddrinfo",t.hostname=e,t}function xm(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($m(t),"");return}n.all?r(null,[{address:e.address,family:e.family}]):r(null,e.address,e.family)}}var yf=async e=>{if(Am)throw new Jt;try{let{Agent:t,fetch:n}=vm(await import("./chunks/undici-CKF2L2IP.js")),r=new t({connections:1,pipelining:0,connect:{lookup:xm(e)}}),s=!1;return{async fetch(i,a){if(s)throw new Jt;return await n(i,{...a,dispatcher:r})},async close(){s||(s=!0,await r.destroy())}}}catch(t){throw t instanceof Jt?t:new Jt}};var at=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},mr=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},yr=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Ps=class extends Error{constructor(t,n){super(`HTTP method '${t}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}},Wn=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};function Pm(e){return new Promise((t,n)=>{km(e,{all:!0},(r,s)=>{r?n(r):t(s)})})}var Cm=20,Nm=3e4,Rm=10485760,Dm=["GET","HEAD"],Im=new Set(["GET","HEAD","OPTIONS"]),Om=new Set([301,302,303,307,308]);function Vn(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function gf(e){if(e?.aborted)throw Vn(e)}async function en(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),Vn(t);let n,r=new Promise((s,i)=>{n=()=>i(Vn(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function _m(e,t){try{return await en(e,t)}catch(n){throw t?.aborted&&e.then(r=>_e.runTrustedAsync(()=>r.close())).catch(()=>{}),n}}async function Lm(e){e.body&&!e.body.locked&&await e.body.cancel()}function Ha(e){let t=e.allowedUrlPrefixes??[];if(!e.dangerouslyAllowFullInternetAccess){let E=mf(t);if(E.length>0)throw new Error(`Invalid network allow-list:
794
- ${E.join(`
795
- `)}`)}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(Ga(E,g.url)&&g.transform){b||(b=new Headers);for(let y of g.transform)for(let[S,v]of Object.entries(y.headers))b.set(S,v)}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??Cm,i=e.timeoutMs??Nm,a=e.maxResponseSize??Rm,o=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Dm,l=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),u=e._dnsResolve??Pm,c=e._createConnectionOwner??yf;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(y=>Number(y)<=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:y,family:S}=g;if(f(y)!==S)throw new at(E,"DNS returned an invalid address for private IP check");return{hostname:b,address:y,family:S}}async function p(E,b){if(gf(b),!e.dangerouslyAllowFullInternetAccess&&!pf(E,t))throw new at(E);if(!l)return null;let g;try{g=new URL(E)}catch{throw new at(E,"invalid URL")}if(Za(g.hostname))throw new at(E,"private/loopback IP address blocked");let y=g.hostname;if(f(y)!==null)return null;let S;try{S=await en(u(y),b)}catch{throw b?.aborted?Vn(b):new at(E,"DNS resolution failed for private IP check")}if(!Array.isArray(S)||S.length===0)throw new at(E,"DNS resolution returned no addresses for private IP check");let v=S.map($=>d(E,y,$));for(let{address:$}of v)if(Za($))throw new at(E,"hostname resolves to private/loopback IP address");return v[0]}function h(E){if(e.dangerouslyAllowFullInternetAccess)return;let b=E.toUpperCase();if(!o.includes(b))throw new Ps(b,o)}async function m(E,b={}){let g=b.method?.toUpperCase()??"GET",y=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,v=Math.min(s,S),$=b.timeoutMs!==void 0?Math.min(b.timeoutMs,i):i,A=new AbortController,C=Xa(()=>A.abort(new DOMException("The operation was aborted","AbortError")),$),N=Er(b.signal,A.signal);try{let x=await p(E,N.signal);h(g);let P=E,R=0;for(;;){gf(N.signal);let B;try{let q=await _e.runTrustedAsync(async()=>{let D=r(P),W=Tm(b.headers,D),V={method:g,headers:W,signal:N.signal,redirect:"manual"};if(b.body&&!Im.has(g)&&(V.body=b.body),!x)return await en(fetch(P,V),N.signal);try{return B=await _m(c(x),N.signal),await en(B.fetch(P,V),N.signal)}catch(O){throw O instanceof Jt?new at(P,"DNS pinning unavailable for private IP enforcement"):O}});if(Om.has(q.status)&&y){let D=q.headers.get("location");if(!D)return await wf(q,P,a,N.signal);let W=new URL(D,P).href;await en(Lm(q),N.signal);try{x=await p(W,N.signal)}catch{throw N.signal?.aborted?Vn(N.signal):new yr(W)}if(R++,R>v)throw new mr(v);P=W;continue}return await wf(q,P,a,N.signal)}finally{if(B){let q=B,D=_e.runTrustedAsync(()=>q.close());await en(D,N.signal)}}}}finally{Ya(C),N.cleanup()}}return m}function Tm(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 wf(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 Wn(n)}}let i;if(n>0&&e.body){let a=e.body.getReader(),o=[],l=0;try{for(;;){let{done:c,value:f}=await en(a.read(),r);if(c)break;if(f){if(l+=f.byteLength,l>n)throw await a.cancel(),new Wn(n);o.push(f)}}}catch(c){throw r?.aborted&&await a.cancel(Vn(r)).catch(()=>{}),c}i=new Uint8Array(l);let u=0;for(let c of o)i.set(c,u),u+=c.byteLength}else{let a=await en(e.arrayBuffer(),r);if(n>0&&a.byteLength>n)throw new Wn(n);i=new Uint8Array(a)}return{status:e.status,statusText:e.statusText,headers:s,body:i,url:t}}function Qa(e,t){if(e.length>t||F(e)>t)throw new k(`script input size limit exceeded (${t} bytes)`,"string_length")}var Cs=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;invokeToolFn;transformPlugins=[];state;constructor(t={}){this.limits=Fs({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}},t.executionLimitProfile);let n=t.fs??new yt(t.files,{maxTotalBytes:this.limits.maxFileSystemBytes});this.fs=n,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),s=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
796
- `],["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=Ha(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",zs(this.state.options)),this.state.env.set("BASHOPTS",qs(this.state.shoptOptions)),Eo(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&n instanceof yt)try{n.mkdirSync(r,{recursive:!0})}catch{}for(let a of no(t.commands))this.registerBundledCommand(a);if(t.fetch||t.network)for(let a of ro())this.registerBundledCommand(a);if(t.python)for(let a of so())this.registerBundledCommand(a);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let a of io())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(co(a)){let o=fo(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){let s=this.commands.get(t.name),i=n?s?.internalOriginalCommand??(s&&!s.internalIsExtension?s:void 0):void 0,a={name:t.name,trusted:r,internalIsExtension:n,internalOriginalCommand:i,execute:(l,u)=>t.execute(l,u)};this.commands.set(t.name,a);let o=this.fs;if(typeof o.writeFileSync=="function"){let l=`#!/bin/bash
793
+ `);l!==-1&&(i=i.slice(l+1))}let a=e.state.loopDepth,o=Ja(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 u=new j().parse(i),c=await s(u);return o(),c}catch(l){if(o(),l instanceof q)return L(l.stdout,l.stderr,l.exitCode);if(l instanceof P)throw l;if(l.name==="ParseException")return _(`bash: ${t}: ${l.message}
794
+ `);throw l}}function $m(e){throw new TypeError(`Unsupported command node: ${JSON.stringify(e)}`)}var Sr=class{ctx;constructor(t,n){this.ctx={state:n,fs:t.fs,commands:t.commands,limits:t.limits,executionScope:t.executionScope,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode,invokeTool:t.invokeTool}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||Le.isInSandboxedContext())return;let n=`interpreter ${t} attempted outside defense context`;throw new vn(n,{timestamp:Date.now(),type:"missing_defense_context",message:n,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:Le.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 Wt(this.ctx.executionScope,"script");for(let s of t.statements)try{let i=await this.executeStatement(s);r.appendResult(i,Bs(i)),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(i){if(i instanceof q)throw i.prependOutput(r.stdout,r.stderr),i;if(i instanceof tt)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Bt(this.ctx.state.env)};if(i instanceof P)throw r.prependTo(i),i;if(i instanceof Be)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:Bt(this.ctx.state.env)};if(i instanceof We)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:Bt(this.ctx.state.env)};if(i instanceof Ze)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Bt(this.ctx.state.env)};if(i instanceof ae){r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(i instanceof kr){r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(i instanceof Ge||i instanceof He){if(this.ctx.state.loopDepth>0)throw i.prependOutput(r.stdout,r.stderr),i;r.append("stdout",i.stdout),r.append("stderr",i.stderr);continue}throw i instanceof Oe&&i.prependOutput(r.stdout,r.stderr),i}return{...r.build(n),env:Bt(this.ctx.state.env)}}async executeUserScript(t,n,r=""){return Sf(this.ctx,t,n,r,s=>this.executeScript(s))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Ve;if(t.deferredError)throw new $e(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return J;this.ctx.state.errexitSafe=!1;let n=new Wt(this.ctx.executionScope,"statement");this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&n.append("stderr",`${t.sourceText}
795
+ `);let r=0,s=-1,i=!1;try{for(let l=0;l<t.pipelines.length;l++){let u=t.pipelines[l],c=l>0?t.operators[l-1]:null;if(c==="&&"&&r!==0||c==="||"&&r===0)continue;let f=await this.executePipeline(u);n.appendResult(f,Bs(f)),r=f.exitCode,s=l,i=u.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}}catch(l){throw n.prependTo(l),l}let 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 Be(r);throw l.prependOutput(n.stdout,n.stderr),l}return n.build(r)}async executePipeline(t){return wf(this.ctx,t,(n,r)=>this.executeCommand(n,r))}async executeCommand(t,n,r=!1){let s=Vu(this.ctx),i;try{i=await this.executeCommandInner(t,n,r)}catch(o){throw await Fi(this.ctx,s).catch(()=>{}),o}let a=await Fi(this.ctx,s);return!a.stdout&&!a.stderr?i:{...i,stdout:a.stdout?Lt(i)+a.stdout:i.stdout,stdoutKind:a.stdout?"bytes":i.stdoutKind,stderr:i.stderr+a.stderr}}async executeCommandInner(t,n,r){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,n);case"If":return df(this.ctx,t);case"For":return pf(this.ctx,t);case"CStyleFor":return hf(this.ctx,t);case"While":return mf(this.ctx,t,n);case"Until":return yf(this.ctx,t,n);case"Case":return gf(this.ctx,t);case"Subshell":return this.executeSubshell(t,n,r);case"Group":return this.executeGroup(t,n,r);case"FunctionDef":return Ac(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return $m(t)}}async executeSimpleCommand(t,n){let r;try{return await this.executeSimpleCommandInner(t,n,s=>{r=s})}catch(s){if(r?.finish(),s instanceof Tt)return _(s.stderr);throw s}}async executeSimpleCommandInner(t,n,r){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let x=t,C=0;for(;;){let D=this.expandAlias(x);if(D===x)break;if(C>=this.ctx.limits.maxCallDepth)throw new P(`alias expansion depth limit exceeded (${this.ctx.limits.maxCallDepth})`,"recursion");C++,x=D}this.aliasExpansionStack.clear(),x!==t&&(t=x)}this.ctx.state.expansionStderr="",this.ctx.state.lastSubstitutionExitCode=null;let s=await Jc(this.ctx,t);if(s.error)return s.error;let i=s.tempAssignments,a=s.xtraceOutput,o=()=>{for(let[x,C]of i)C===void 0?this.ctx.state.env.delete(x):this.ctx.state.env.set(x,C)};if(!t.name){if(t.redirections.length>0){let C=Un(this.ctx,t.redirections,bc);r(C);let D=await C.prepare(n);if(D.error){if(o(),!D.errorCause)return C.finish(),D.error;try{return jn(D)}finally{C.finish()}}let B=L("",a,Qr(this.ctx.state,t.redirections)),H=await an(this.ctx,B,t.redirections,D.targets,D.dupSources,D.standardRoutes);return C.finish(),H}this.ctx.state.lastArg="";let x=(this.ctx.state.expansionStderr||"")+a;return this.ctx.state.expansionStderr="",L("",x,Qr(this.ctx.state,[]))}let l=t.name&&Xa(t.name,["local","declare","typeset","export","readonly"]),u=Array.from(i.keys());if(u.length>0&&!l){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let x of u)this.ctx.state.tempExportedVars.add(x)}let c=await ne(this.ctx,t.name),f=[],d=[],p=(x,C)=>{if(f.length>=this.ctx.limits.maxArrayElements)throw new P(`expanded argument element limit exceeded (${this.ctx.limits.maxArrayElements})`,"array_elements");f.push(x),d.push(C)};if(Xa(t.name,["local","declare","typeset","export","readonly"])&&(c==="local"||c==="declare"||c==="typeset"||c==="export"||c==="readonly"))for(let x of t.args){let C=await Yu(this.ctx,x);if(C)p(C,!0);else{let D=await Ju(this.ctx,x);if(D!==null)p(D,!0);else{let B=await Et(this.ctx,x);for(let H of B.values)p(H,B.quoted)}}}else for(let x of t.args){let C=await Et(this.ctx,x);for(let D of C.values)p(D,C.quoted)}let m=t.name.parts.every(x=>x.type==="CommandSubstitution"||x.type==="ParameterExpansion"||x.type==="ArithmeticExpansion");!c&&m&&f.length>0&&(c=f.shift(),d.shift());let E=Un(this.ctx,t.redirections,c==="exec"?Sc:pr);r(E);let S=await E.prepare(n);if(S.error)return o(),S.errorCause?jn(S):(E.finish(),S.error);let y=S.stdinSourceFd,g=S.stdin!==void 0;if(S.stdin!==void 0&&(n=S.stdin),!c)return m?(E.finish(),L("","",Qr(this.ctx.state,t.redirections))):(E.finish(),_(`bash: : command not found
796
+ `,127));if(c==="exec"&&(f.length===0||f[0]==="--")){for(let[x,C]of i)C===void 0?this.ctx.state.env.delete(x):this.ctx.state.env.set(x,C);if(this.ctx.state.tempExportedVars)for(let x of i.keys())this.ctx.state.tempExportedVars.delete(x);return E.finish(),J}if(this.ctx.state.extraArgs){let x=this.ctx.state.extraArgs;this.ctx.state.extraArgs=void 0;for(let C of x)p(C,!0)}let b=await Xc(this.ctx,c,f);i.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(i)));let v,$=null;try{v=await this.runCommand(c,f,d,n,!1,!1,y,g)}catch(x){if(x instanceof Ge||x instanceof He)$=x,v=J;else throw x}y>=0&&c!=="read"&&rn(this.ctx,y,v.internalStdinConsumed??0);let A=a+b;if(A&&(v={...v,stderr:A+v.stderr}),v=await an(this.ctx,v,t.redirections,S.targets,S.dupSources,S.standardRoutes,v.internalProducerCommand??c,v.internalProducerOmitsShellPrefix),E.finish(),$)throw $;if(f.length>0){let x=f[f.length-1];if((c==="declare"||c==="local"||c==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(x)){let C=x.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);C&&(x=C[1])}this.ctx.state.lastArg=x}else this.ctx.state.lastArg=c;let k=hc(c)&&c!=="unset"&&c!=="eval";if(!this.ctx.state.options.posix||!k)for(let[x,C]of i)this.ctx.state.fullyUnsetLocals?.has(x)||(C===void 0?this.ctx.state.env.delete(x):this.ctx.state.env.set(x,C));if(this.ctx.state.tempExportedVars)for(let x of i.keys())this.ctx.state.tempExportedVars.delete(x);return i.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(v={...v,stderr:this.ctx.state.expansionStderr+v.stderr},this.ctx.state.expansionStderr=""),v}async runCommand(t,n,r,s,i=!1,a=!1,o=-1,l=!1){let u={ctx:this.ctx,runCommand:(d,p,h,m,E,S,y,g)=>this.runCommand(d,p,h,m,E,S,y,g),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(d,p,h)=>this.executeUserScript(d,p,h)},c=await uf(u,t,n,r,s,i,a,o,l);return c!==null?c.internalProducerCommand===void 0?{...c,internalProducerCommand:t}:c:{...await cf(u,t,n,s,a),internalProducerCommand:t}}aliasExpansionStack=new Set;expandAlias(t){return xl({env:this.ctx.state.env,limits:this.ctx.limits},t,this.aliasExpansionStack)}async findCommandInPath(t){return Is(this.ctx,t)}async executeSubshell(t,n="",r=!1){return Ef(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeGroup(t,n="",r=!1){return bf(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeArithmeticCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),et(this.ctx,t.redirections,"",async()=>{try{let n=await X(this.ctx,t.expression.expression),r=ge(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){return _(`bash: arithmetic expression: ${n.message}
797
+ `)}})}async executeConditionalCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),et(this.ctx,t.redirections,"",async()=>{try{let n=await en(this.ctx,t.expression),r=ge(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){let r=n instanceof ae?1:2;return _(`bash: conditional expression: ${n.message}
798
+ `,r)}})}};function eo(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function xm(e){let t=eo(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var km=3;function Af(e){let t=e;for(let n=0;n<km;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 Pm(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function to(e,t){let n=eo(e);if(!n)return!1;let r=xm(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&Af(n.pathname)?!1:Pm(n.pathname,r.pathPrefix)}function vf(e){return typeof e=="string"?e:e.url}function $f(e,t){return!t||t.length===0?!1:t.some(n=>to(e,vf(n)))}function no(e){let t=Cm(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=xf(t);if(n)return Ls(n);let r=Rm(t);return r?Dm(r):!1}function Cm(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function Nm(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 xf(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>Nm(l));if(n.some(l=>l===null))return null;let r=n;if(t.length===1){let l=r[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,u]=r;return l>255||u>16777215?null:[l,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[l,u,c]=r;return l>255||u>255||c>65535?null:[l,u,c>>>8&255,c&255]}let[s,i,a,o]=r;return s>255||i>255||a>255||o>255?null:[s,i,a,o]}function Rm(e){let t=e,n=null;if(t.includes(".")){let m=t.lastIndexOf(":");if(m<0)return null;let E=t.slice(m+1),S=xf(E);if(!S)return null;n=S,t=t.slice(0,m)}let r=t.includes("::")?t.split("::").length-1:0;if(r>1)return null;let[s,i]=t.split("::"),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,u=a.map(l),c=o.map(l);if(u.some(m=>m===null)||c.some(m=>m===null))return null;let f=n?2:0,d=u.length+c.length+f,p=0;if(r===1){if(p=8-d,p<0)return null}else if(d!==8)return null;let h=[...u,...new Array(p).fill(0),...c];return n&&(h.push(n[0]<<8|n[1]),h.push(n[2]<<8|n[3])),h.length===8?h:null}function Ls(e){let[t,n]=e;return t===127||t===10||t===172&&n>=16&&n<=31||t===192&&n===168||t===169&&n===254||t===0||t===100&&n>=64&&n<=127||t===198&&(n===18||n===19)||t===192&&n===0&&e[2]===0||t===192&&n===0&&e[2]===2||t===198&&n===51&&e[2]===100||t===203&&n===0&&e[2]===113||t>=240}function Dm(e){if(e.every(s=>s===0)||e.slice(0,7).every(s=>s===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Ls(s)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Ls(s)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let s=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return Ls(s)}return!1}function kf(e){let t=[];for(let n of e){if(typeof n!="string"&&(n===null||typeof n!="object"||!("url"in n)||typeof n.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let r=vf(n);if(!eo(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!==""&&Af(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 bt=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},Qn=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},un=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Ts=class extends Error{constructor(t,n){super(`HTTP method '${t}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}},An=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var Im=20,Om=3e4,_m=10485760,Lm=["GET","HEAD"],Ar;typeof __BROWSER__<"u"&&__BROWSER__?Ar=null:(Ar=import("./chunks/dist-4NZ74CRE.js"),Ar.catch(()=>{}));var Tm=new Set(["GET","HEAD","OPTIONS"]),Mm=new Set([301,302,303,307,308]);function vr(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function Fm(e){if(e?.aborted)throw vr(e)}function so(e){let t=e.allowedUrlPrefixes??[];if(e._dnsResolve)throw new Error("NetworkConfig._dnsResolve is no longer supported: DNS resolution is performed by guarded-fetch and cannot be overridden");if(e._createConnectionOwner)throw new Error("NetworkConfig._createConnectionOwner is no longer supported: connect-time IP pinning is performed by guarded-fetch and cannot be overridden");let n=e._fetch;if(!e.dangerouslyAllowFullInternetAccess){let b=kf(t);if(b.length>0)throw new Error(`Invalid network allow-list:
799
+ ${b.join(`
800
+ `)}`)}let r=[];for(let b of t)typeof b=="object"&&b.transform&&b.transform.length>0&&r.push(b);function s(b){if(r.length===0)return null;let v=null;for(let $ of r)if(to(b,$.url)&&$.transform){v||(v=new Headers);for(let A of $.transform)for(let[k,N]of Object.entries(A.headers))v.set(k,N)}return v}if(e.maxRedirects!==void 0&&(!Number.isSafeInteger(e.maxRedirects)||e.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let i=e.maxRedirects??Im,a=e.timeoutMs??Om,o=e.maxResponseSize??_m,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Lm,u=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),c=[];for(let b of t){let v=typeof b=="string"?b:b.url;try{c.push(new URL(v).hostname)}catch{}}function f(b){try{return new URL(b).hostname||"localhost.invalid"}catch{return"localhost.invalid"}}function d(b){return e.dangerouslyAllowFullInternetAccess?u?{allowedHosts:void 0,skipSsrfCheckForAllowedHosts:void 0}:{allowedHosts:[f(b)],skipSsrfCheckForAllowedHosts:!0}:{allowedHosts:c,skipSsrfCheckForAllowedHosts:!u}}function p(b){try{return no(new URL(b).hostname)}catch{return!1}}async function h(b,v){let $={method:v.method,headers:v.headers,signal:v.signal,redirect:"manual"};return v.body!==void 0&&($.body=v.body),await(n??globalThis.fetch)(b,$)}function m(b){if(!e.dangerouslyAllowFullInternetAccess&&!$f(b,t))throw new bt(b)}function E(b){if(!u)return;let v;try{v=new URL(b)}catch{throw new bt(b,"invalid URL")}if(no(v.hostname))throw new bt(b,"private/loopback IP address blocked")}function S(b){if(e.dangerouslyAllowFullInternetAccess)return;let v=b.toUpperCase();if(!l.includes(v))throw new Ts(v,l)}function y(b,v,$,A){if(!$.isGuardedFetchError(b))return b;let k=b,{onRedirectHop:N,subReason:x}=A;switch(k.code){case"host_not_allowed":case"protocol_not_allowed":return N?new un(v):new bt(v);case"hostname_unsafe":return N?new un(v):new bt(v,x==="dns_resolution_failed"?"DNS resolution failed for private IP check":"hostname resolves to private/loopback IP address");case"redirect_to_unsafe_host":return new un(v);case"too_many_redirects":return new Qn(i);case"response_too_large":return new An(o);default:return b}}async function g(b,v={}){let $=v.method?.toUpperCase()??"GET",A=v.followRedirects??!0;if(v.maxRedirects!==void 0&&(!Number.isSafeInteger(v.maxRedirects)||v.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let k=v.maxRedirects??i,N=Math.min(i,k),x=v.timeoutMs!==void 0?Math.min(v.timeoutMs,a):a,C=new AbortController,D=oo(()=>C.abort(new DOMException("The operation was aborted","AbortError")),x),B=Cr(v.signal,C.signal);try{m(b),E(b),S($);let H=Ar?await Ar:null,R=b,W=0,V=[],I=$,O=v.body,F=v.headers,ee=!1;for(;;){Fm(B.signal);let K=await Le.runTrustedAsync(async()=>{let Ie=F;if(ee&&Ie){let Dt=Ie instanceof Headers?new Headers(Ie):new Headers(Ie);Dt.delete("authorization"),Dt.delete("cookie"),Ie=Dt}let ut=s(R),Rt=Wm(Ie,ut),ct={method:I,headers:Rt,signal:B.signal,followRedirects:!1,timeoutMs:x,sanitizeHeaders:!1};if(O&&!Tm.has(I)&&(ct.body=O),Object.assign(ct,d(R)),!H||p(R)){if(u)throw new bt(R,"DNS pinning unavailable for private IP enforcement");return await h(R,ct)}u?n&&(ct.fetch=n):(ct.fetch=n??globalThis.fetch,ct.dispatcher=null);let ft;ct.onUrlBlocked=Dt=>{ft=Dt.subReason};try{return await H.guardedFetch(R,ct)}catch(Dt){throw y(Dt,R,H,{onRedirectHop:W>0,subReason:ft})}});if(Mm.has(K.status)&&A){let Ie=K.headers.get("location");if(!Ie)return await Pf(K,R,o,B.signal,V);V.push({status:K.status,statusText:K.statusText,headers:Cf(K.headers)});let ut=new URL(Ie,R).href;await ro(Bm(K),B.signal);try{m(ut),E(ut)}catch(ft){throw B.signal?.aborted?vr(B.signal):ft instanceof bt?new un(ut):ft}let Rt=K.status;if(((Rt===301||Rt===302)&&I==="POST"||Rt===303&&I!=="GET"&&I!=="HEAD")&&(I="GET",O=void 0,S(I)),new URL(ut).origin!==new URL(R).origin&&(ee=!0),W++,W>N)throw new Qn(N);R=ut;continue}return await Pf(K,R,o,B.signal,V)}}finally{lo(D),B.cleanup()}}return g}async function ro(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),vr(t);let n,r=new Promise((s,i)=>{n=()=>i(vr(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function Bm(e){e.body&&!e.body.locked&&await e.body.cancel()}function Wm(e,t){if(!e&&!t)return;if(!t)return e;let n=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,s]of t)n.set(r,s);return n}function Cf(e){let t=Object.create(null);return e.forEach((n,r)=>{t[r.toLowerCase()]=n}),t}async function Pf(e,t,n,r,s){let i=Cf(e.headers);if(n>0){let l=e.headers.get("content-length");if(l){let u=parseInt(l,10);if(!Number.isNaN(u)&&u>n)throw new An(n)}}let a;if(n>0&&e.body){let l=e.body.getReader(),u=[],c=0;try{for(;;){let{done:d,value:p}=await ro(l.read(),r);if(d)break;if(p){if(c+=p.byteLength,c>n)throw await l.cancel(),new An(n);u.push(p)}}}catch(d){throw r?.aborted&&await l.cancel(vr(r)).catch(()=>{}),d}a=new Uint8Array(c);let f=0;for(let d of u)a.set(d,f),f+=d.byteLength}else{let l=await ro(e.arrayBuffer(),r);if(n>0&&l.byteLength>n)throw new An(n);a=new Uint8Array(l)}let o={status:e.status,statusText:e.statusText,headers:i,body:a,url:t};return s&&s.length>0&&(o.redirectChain=s),o}function io(e,t){if(e.length>t||M(e)>t)throw new P(`script input size limit exceeded (${t} bytes)`,"string_length")}var Ms=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;invokeToolFn;transformPlugins=[];state;constructor(t={}){this.limits=js({...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 At(t.files,{maxTotalBytes:this.limits.maxFileSystemBytes});this.fs=n,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),s=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
801
+ `],["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"],["PWD",r],["OLDPWD",r],["OPTIND","1"],...Object.entries(t.env??{})]);if(t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=so(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.coverageWriter=t.coverage,this.state={env:s,arrays:new Map,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastSubstitutionExitCode:null,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,virtualPid:t.processInfo?.pid??1,virtualPpid:t.processInfo?.ppid??0,virtualUid:t.processInfo?.uid??1e3,virtualGid:t.processInfo?.gid??1e3,bashPid:t.processInfo?.pid??1,nextVirtualPid:(t.processInfo?.pid??1)+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",Qs(this.state.options)),this.state.env.set("BASHOPTS",Ks(this.state.shoptOptions)),Do(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&(n instanceof At||n instanceof dn))try{n.mkdirSync(r,{recursive:!0})}catch{}for(let a of mo(t.commands))this.registerBundledCommand(a);if(t.fetch||t.network)for(let a of yo())this.registerBundledCommand(a);if(t.python)for(let a of go())this.registerBundledCommand(a);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let a of wo())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(vo(a)){let o=$o(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){let s=this.commands.get(t.name),i=n?s?.internalOriginalCommand??(s&&!s.internalIsExtension?s:void 0):void 0,a={name:t.name,trusted:r,internalIsExtension:n,internalOriginalCommand:i,execute:(l,u)=>t.execute(l,u)};this.commands.set(t.name,a);let o=this.fs;if(typeof o.writeFileSync=="function"){let l=`#!/bin/bash
797
802
  # Built-in command: ${t.name}
798
- `;try{o.writeFileSync(`/bin/${t.name}`,l)}catch{}try{o.writeFileSync(`/usr/bin/${t.name}`,l)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=bf(t.stdout),t.stderr=bf(t.stderr),t}async exec(t,n){let r=new vr(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
799
- `,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,u=Er(i,n?.signal),c=n?{...n,signal:u.signal}:{signal:u.signal};try{if(r.assertExecDepth(s),Qa(t,this.limits.maxSourceBytes),!t.trim())return{stdout:"",stderr:"",exitCode:0,env:He(this.state.env,c.env)};this.logger?.info("exec",{command:t});let f=c.cwd??this.state.cwd,d,p=f;if(c.cwd)if(c.env&&"PWD"in c.env)d=c.env.PWD;else if(c.env&&!("PWD"in c.env))try{d=await this.fs.realpath(f),p=d}catch{d=f}else d=f;let h=c.replaceEnv?new Map:new Map(this.state.env);if(c.env)for(let[y,S]of Object.entries(c.env))h.set(y,S);d!==void 0&&h.set("PWD",d);let m={...this.state,env:h,arrays:c.replaceEnv?new Map:nt(this.state.arrays),cwd:p,previousDir:c.env?.OLDPWD??this.state.previousDir,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:Bm(c.stdin,c.stdinKind,this.limits.maxInputBytes,this.limits.maxStringLength,r,a),signal:c.signal,extraArgs:c.args},E=t;c.rawScript||(E=Ef(t));let b=this.defenseInDepthConfig?_e.getInstance(this.defenseInDepthConfig):null,g=b?.activate();try{let y=async()=>{let S=lt(E,{maxHeredocSize:this.limits.maxHeredocSize}),v;if(this.transformPlugins.length>0){let x=Object.create(null);for(let P of this.transformPlugins){let R=P.transform({ast:S,metadata:x});S=R.ast,R.metadata&&(x=Os(x,R.metadata))}v=x}let $={fs:this.fs,commands:this.commands,limits:this.limits,executionScope:r,exec:(x,P,R=!1)=>this.execInScope(x,P,r,s+1,c.signal,R),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:b?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},N=await new hr($,m).executeScript(S);return v&&(N.metadata=v),l(N)};return g?await g.run(y):await y()}catch(y){if(y instanceof U)return l({stdout:y.stdout,stderr:y.stderr,exitCode:y.exitCode,internalOutputAccounting:y.internalOutputAccounting,env:He(this.state.env,c.env)});if(y instanceof et)return l({stdout:y.stdout,stderr:y.stderr,exitCode:y.exitCode,env:He(this.state.env,c.env)});if(y instanceof oe)return l({stdout:y.stdout,stderr:y.stderr,exitCode:1,env:He(this.state.env,c.env)});if(y instanceof We)return l({stdout:y.stdout,stderr:y.stderr,exitCode:124,env:He(this.state.env,c.env)});if(y instanceof k)return l({stdout:y.stdout,stderr:mt(y.stderr),exitCode:k.EXIT_CODE,internalOutputAccounting:y.internalOutputAccounting,env:He(this.state.env,c.env)});if(y instanceof hn)return l({stdout:"",stderr:`bash: security violation: ${mt(y.message)}
800
- `,exitCode:1,env:He(this.state.env,c.env)});if(y.name==="ParseException")return l({stdout:"",stderr:`bash: syntax error: ${mt(y.message)}
801
- `,exitCode:2,env:He(this.state.env,c.env)});if(y instanceof Qe)return l({stdout:"",stderr:`bash: ${mt(y.message)}
802
- `,exitCode:2,env:He(this.state.env,c.env)});if(y instanceof RangeError)return l({stdout:"",stderr:`bash: ${mt(y.message)}
803
- `,exitCode:1,env:He(this.state.env,c.env)});throw y}finally{g?.deactivate()}}catch(f){if(f instanceof We)return l({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:He(this.state.env,c.env)});if(f instanceof k)return l({stdout:f.stdout,stderr:mt(f.stderr),exitCode:k.EXIT_CODE,internalOutputAccounting:f.internalOutputAccounting,env:He(this.state.env,c.env)});throw f}finally{u.cleanup()}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,n){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),n)}getCwd(){return this.state.cwd}getEnv(){return It(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){Qa(t,this.limits.maxSourceBytes);let n=Ef(t),r=lt(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=Os(s,a.metadata))}return{script:rl(r),ast:r,metadata:s}}};function Mm(e,t){let n=t;for(let r=0;r<e.length;r++){let s=e[r];if(n==="single")s==="'"&&(n="none");else if(n==="double")s==="\\"?r++:s==='"'&&(n="none");else if(s==="'")n="single";else if(s==='"')n="double";else if(s==="\\")r++;else if(s==="#"&&(r===0||/\s/.test(e[r-1])))break}return n}function Ef(e){let t=e.split(`
804
- `),n=[],r=[],s="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){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=Mm(a,o),o!=="none")continue;let u=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let c of l.matchAll(u)){let f=c[1]==="-",d=c[3];r.push({delimiter:d,stripTabs:f})}}return n.join(`
805
- `)}var Fm=new TextDecoder("utf-8",{fatal:!0});function bf(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 Fm.decode(n)}catch{return e}}function Bm(e,t,n,r,s,i){if(e===void 0)return;let a=t==="bytes"?e.length:F(e);if(a>n||a>r)throw new k(`stdin size limit exceeded (${Math.min(n,r)} bytes)`,"string_length");return i||s.consumeInput(a,"stdin"),t==="bytes"?e:tn(e)}import*as de from"node:fs";import*as De from"node:path";import*as ot from"node:fs";import*as xe from"node:path";function wr(e,t){let n=/^[A-Za-z]:[\\/]/.test(t)?xe.win32:xe.posix,r=n.relative(t,e);return r===""||r!==".."&&!r.startsWith(`..${n.sep}`)&&!n.isAbsolute(r)}function gr(e,t){try{let n=ot.realpathSync(e);return wr(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=xe.dirname(e);if(r===e)return null;let s=gr(r,t);if(s===null)return null;try{if(ot.lstatSync(e).isSymbolicLink()){let a=ot.readlinkSync(e),o=xe.isAbsolute(a)?a:xe.resolve(xe.dirname(e),a),l=gr(o,t);return l===null?null:l}}catch{}return xe.join(s,xe.basename(e))}return null}}function Sf(e,t,n){let r=gr(e,n);if(r===null)return null;let s=xe.resolve(e),i=s.slice(t.length),a=r.slice(n.length);if(i!==a)return null;try{if(ot.lstatSync(s).isSymbolicLink())return null}catch{}return r}function Af(e,t){if(!ot.existsSync(e))throw new Error(`${t} root does not exist`);if(!ot.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function vf(e,t){if(!xe.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=ot.realpathSync(e)}catch{n=xe.resolve(e)}return wr(n,t)?{withinRoot:!0,relativePath:n.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:xe.basename(e)}}function $f(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 Wm=["ELOOP","EFBIG","EPERM"],Vm="/home/user/project",Ns=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=De.resolve(t.root);let n=t.mountPoint??Vm;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,Af(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=z(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=z(t),s=this.getDirname(r);s!=="/"&&this.mkdirSync(s);let i=n instanceof Uint8Array?n:new TextEncoder().encode(n);this.setMemoryEntry(r,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let n=t.lastIndexOf("/");return n===0?"/":t.slice(0,n)}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let n=z(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=De.join(this.root,r),i=De.resolve(s);return wr(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?gr(t,this.canonicalRoot):Sf(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=De.dirname(t),r=this.resolveRealPath_(n);return r===null?null:De.join(r,De.basename(t))}sanitizeError(t,n,r){$f(t,n,r,Wm)}ensureParentDirs(t){let n=wn(t);n!=="/"&&(this.memory.has(n)||(this.ensureParentDirs(n),this.setMemoryEntry(n,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(n))}async existsInOverlay(t){let n=z(t);if(this.deleted.has(n))return!1;if(this.memory.has(n))return!0;let r=this.resolveRealPathParent_(this.toRealPath(n));if(!r)return!1;try{return await de.promises.lstat(r),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=_t(n);return An(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return An(n,"binary")}async readFileBuffer(t,n=new Set){Q(t,"open");let r=z(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let u=this.resolveSymlink(r,s.target);return this.readFileBuffer(u,n)}if(s.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(!s.appendChunks||s.appendChunks.length===0)return s.content;let a=s.appendChunks.reduce((u,c)=>u+c.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 u of s.appendChunks)o.set(u,l),l+=u.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 u=await de.promises.readlink(i),c=this.realTargetToVirtual(r,u),f=this.resolveSymlink(r,c);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 u=await l.readFile();return new Uint8Array(u)}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){Q(t,"write"),this.assertWritable(`write '${t}'`);let s=z(t);this.ensureParentDirs(s);let i=_t(r),a=Sn(n,i);this.setMemoryEntry(s,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(s)}async appendFile(t,n,r){Q(t,"append"),this.assertWritable(`append '${t}'`);let s=z(t),i=_t(r),a=Sn(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){Q(t,"stat");let r=z(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let 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),u=this.resolveSymlink(r,l);return this.stat(u,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){Q(t,"lstat");let n=z(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let i=0;return r.type==="file"&&(i=r.content.length+(r.appendChunks?.reduce((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 bn(t,n)}realTargetToVirtual(t,n){let r=vf(n,this.canonicalRoot);if(r.withinRoot){if(!De.isAbsolute(n))return n;let s=r.relativePath;return this.mountPoint==="/"?s:`${this.mountPoint}${s}`}return r.safeName}async mkdir(t,n){Q(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=z(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=wn(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),u=l.split("/")[0];u&&!l.includes("/",u.length)&&s.add(u)}for(let[o,l]of this.memory)if(o!==n&&o.startsWith(i)){let u=o.slice(i.length),c=u.split("/")[0];c&&!s.has(c)&&!u.includes("/",1)&&r.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let 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=z(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 c=await de.promises.readlink(l),f=this.realTargetToVirtual(r,c),d=this.resolveSymlink(r,f);return this.resolveForReaddir(d,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async readdir(t){Q(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.keys()).sort((i,a)=>i<a?-1:i>a?1:0)}async readdirWithFileTypes(t){Q(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.values()).sort((i,a)=>i.name<a.name?-1:i.name>a.name?1:0)}async rm(t,n){Q(t,"rm"),this.assertWritable(`rm '${t}'`);let r=z(t);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(r)).isDirectory){let 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){Q(t,"cp"),Q(n,"cp"),this.assertWritable(`cp '${n}'`);let s=z(t),i=z(n);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let 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($t(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(s);for(let u of l){let c=s==="/"?`/${u}`:`${s}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(c,f,r)}}}async mv(t,n){this.assertWritable(`mv '${n}'`),await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return En(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=De.join(r,i);de.lstatSync(o).isDirectory()&&this.scanRealFs(a,n)}}catch{}}async chmod(t,n){Q(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=z(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(r);if(i){i.mode=n;return}let 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}'`);Q(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=z(n);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.setMemoryEntry(r,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(t,n){Q(t,"link"),Q(n,"link"),this.assertWritable(`link '${n}'`);let r=z(t),s=z(n);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let 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){Q(t,"readlink");let n=z(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let r=this.memory.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await de.promises.readlink(s);if(!De.isAbsolute(i)){let a=De.resolve(De.dirname(s),i),o;try{o=de.realpathSync(a)}catch{o=a}if(!wr(o,this.canonicalRoot))return De.basename(i)}return this.realTargetToVirtual(n,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){Q(t,"realpath");let n=z(t),r=new Set,s=async o=>{let l=o==="/"?[]:o.slice(1).split("/"),u="";for(let c of l){if(u=`${u}/${c}`,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(u),d=0,p=40;for(;f&&f.type==="symlink"&&d<p;){if(r.add(u),u=this.resolveSymlink(u,f.target),d++,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(u)}if(d>=p)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let h=this.toRealPath(u),m=this.resolveRealPath_(h);if(m)try{if((await 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(u,b);return r.add(u),u=this.resolveSymlink(u,g),s(u)}}catch(E){if(E.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(E,t,"realpath")}else if(!this.allowSymlinks){let E=this.resolveRealPathParent_(h);if(E)try{if((await 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 u||"/"},i=await s(n);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,n,r){Q(t,"utimes"),this.assertWritable(`utimes '${t}'`);let s=z(t);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let 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})}};var ke={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"},Ka=class{env;rl;running=!0;history=[];initialization;isInteractive;constructor(t={}){let n=process.cwd(),r=new Ns({root:n,mountPoint:"/"});this.env=new Cs({fs:r,cwd:t.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...t.env},network:t.network===!0?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.initialization=this.seedFiles(r,t.files),this.isInteractive=process.stdin.isTTY===!0,this.rl=Pf.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C
803
+ `;try{o.writeFileSync(`/bin/${t.name}`,l)}catch{}try{o.writeFileSync(`/usr/bin/${t.name}`,l)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=Rf(t.stdout),t.stderr=Rf(t.stderr),t}async exec(t,n){let r=new Rr(this.limits,n?.signal),s;try{s=await this.execInScope(t,n,r,0,n?.signal,!1,!1)}catch(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
804
+ `,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,u=Cr(i,n?.signal),c=n?{...n,signal:u.signal}:{signal:u.signal};try{if(r.assertExecDepth(s),io(t,this.limits.maxSourceBytes),!t.trim())return{stdout:"",stderr:"",exitCode:0,env:Qe(this.state.env,c.env)};this.logger?.info("exec",{command:t});let f=c.cwd??this.state.cwd,d,p=f;if(c.cwd)if(c.env&&"PWD"in c.env)d=c.env.PWD;else if(c.env&&!("PWD"in c.env))try{d=await this.fs.realpath(f),p=d}catch{d=f}else d=f;let h=c.replaceEnv?new Map:new Map(this.state.env);if(c.env)for(let[g,b]of Object.entries(c.env))h.set(g,b);d!==void 0&&h.set("PWD",d);let m={...this.state,env:h,arrays:c.replaceEnv?new Map:st(this.state.arrays),cwd:p,previousDir:c.env?.OLDPWD??this.state.previousDir,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:qm(c.stdin,c.stdinKind,this.limits.maxInputBytes,this.limits.maxStringLength,r,a),signal:c.signal,extraArgs:c.args},E=t;c.rawScript||(E=Nf(t));let S=this.defenseInDepthConfig?Le.getInstance(this.defenseInDepthConfig):null,y=S?.activate();try{let g=async()=>{let b=pt(E,{maxHeredocSize:this.limits.maxHeredocSize}),v;if(this.transformPlugins.length>0){let x=Object.create(null);for(let C of this.transformPlugins){let D=C.transform({ast:b,metadata:x});b=D.ast,D.metadata&&(x=Ws(x,D.metadata))}v=x}let $={fs:this.fs,commands:this.commands,limits:this.limits,executionScope:r,exec:(x,C,D=!1)=>this.execInScope(x,C,r,s+1,c.signal,D),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:S?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},N=await new Sr($,m).executeScript(b);return v&&(N.metadata=v),l(N)};return y?await y.run(g):await g()}catch(g){if(g instanceof q)return l({stdout:g.stdout,stderr:g.stderr,exitCode:g.exitCode,internalOutputAccounting:g.internalOutputAccounting,env:Qe(this.state.env,c.env)});if(g instanceof tt)return l({stdout:g.stdout,stderr:g.stderr,exitCode:g.exitCode,env:Qe(this.state.env,c.env)});if(g instanceof ae)return l({stdout:g.stdout,stderr:g.stderr,exitCode:1,env:Qe(this.state.env,c.env)});if(g instanceof Ve)return l({stdout:g.stdout,stderr:g.stderr,exitCode:124,env:Qe(this.state.env,c.env)});if(g instanceof P)return l({stdout:g.stdout,stderr:St(g.stderr),exitCode:P.EXIT_CODE,internalOutputAccounting:g.internalOutputAccounting,env:Qe(this.state.env,c.env)});if(g instanceof vn)return l({stdout:"",stderr:`bash: security violation: ${St(g.message)}
805
+ `,exitCode:1,env:Qe(this.state.env,c.env)});if(g.name==="ParseException")return l({stdout:"",stderr:`bash: syntax error: ${St(g.message)}
806
+ `,exitCode:2,env:Qe(this.state.env,c.env)});if(g instanceof Ke)return l({stdout:"",stderr:`bash: ${St(g.message)}
807
+ `,exitCode:2,env:Qe(this.state.env,c.env)});if(g instanceof RangeError)return l({stdout:"",stderr:`bash: ${St(g.message)}
808
+ `,exitCode:1,env:Qe(this.state.env,c.env)});throw g}finally{y?.deactivate()}}catch(f){if(f instanceof Ve)return l({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:Qe(this.state.env,c.env)});if(f instanceof P)return l({stdout:f.stdout,stderr:St(f.stderr),exitCode:P.EXIT_CODE,internalOutputAccounting:f.internalOutputAccounting,env:Qe(this.state.env,c.env)});throw f}finally{u.cleanup()}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,n){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),n)}getCwd(){return this.state.cwd}getEnv(){return Bt(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){io(t,this.limits.maxSourceBytes);let n=Nf(t),r=pt(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=Ws(s,a.metadata))}return{script:ml(r),ast:r,metadata:s}}};function Vm(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 Nf(e){let t=e.split(`
809
+ `),n=[],r=[],s="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){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=Vm(a,o),o!=="none")continue;let u=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let c of l.matchAll(u)){let f=c[1]==="-",d=c[3];r.push({delimiter:d,stripTabs:f})}}return n.join(`
810
+ `)}var zm=new TextDecoder("utf-8",{fatal:!0});function Rf(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 zm.decode(n)}catch{return e}}function qm(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:cn(e)}import*as pe from"node:fs";import*as De from"node:path";import*as lt from"node:fs";import*as xe from"node:path";function xr(e,t){let n=/^[A-Za-z]:[\\/]/.test(t)?xe.win32:xe.posix,r=n.relative(t,e);return r===""||r!==".."&&!r.startsWith(`..${n.sep}`)&&!n.isAbsolute(r)}function $r(e,t){try{let n=lt.realpathSync(e);return xr(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=xe.dirname(e);if(r===e)return null;let s=$r(r,t);if(s===null)return null;try{if(lt.lstatSync(e).isSymbolicLink()){let a=lt.readlinkSync(e),o=xe.isAbsolute(a)?a:xe.resolve(xe.dirname(e),a),l=$r(o,t);return l===null?null:l}}catch{}return xe.join(s,xe.basename(e))}return null}}function Df(e,t,n){let r=$r(e,n);if(r===null)return null;let s=xe.resolve(e),i=s.slice(t.length),a=r.slice(n.length);if(i!==a)return null;try{if(lt.lstatSync(s).isSymbolicLink())return null}catch{}return r}function If(e,t){if(!lt.existsSync(e))throw new Error(`${t} root does not exist`);if(!lt.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function Of(e,t){if(!xe.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=lt.realpathSync(e)}catch{n=xe.resolve(e)}return xr(n,t)?{withinRoot:!0,relativePath:n.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:xe.basename(e)}}function _f(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 Um=["ELOOP","EFBIG","EPERM"],jm="/home/user/project",Fs=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=De.resolve(t.root);let n=t.mountPoint??jm;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,If(this.root,"OverlayFs"),this.canonicalRoot=pe.realpathSync(this.root),this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){let t=this.mountPoint.split("/").filter(Boolean),n="";for(let r of t)n+=`/${r}`,this.memory.has(n)||this.setMemoryEntry(n,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.setMemoryEntry("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}mkdirSync(t,n){let s=z(t).split("/").filter(Boolean),i="";for(let a of s)i+=`/${a}`,this.memory.has(i)||this.setMemoryEntry(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,n){let r=z(t),s=this.getDirname(r);s!=="/"&&this.mkdirSync(s);let i=n instanceof Uint8Array?n:new TextEncoder().encode(n);this.setMemoryEntry(r,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let n=t.lastIndexOf("/");return n===0?"/":t.slice(0,n)}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let n=z(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=De.join(this.root,r),i=De.resolve(s);return xr(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?$r(t,this.canonicalRoot):Df(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=De.dirname(t),r=this.resolveRealPath_(n);return r===null?null:De.join(r,De.basename(t))}sanitizeError(t,n,r){_f(t,n,r,Um)}ensureParentDirs(t){let n=dt(t);n!=="/"&&(this.memory.has(n)||(this.ensureParentDirs(n),this.setMemoryEntry(n,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(n))}async existsInOverlay(t){let n=z(t);if(this.deleted.has(n))return!1;if(this.memory.has(n))return!0;let r=this.resolveRealPathParent_(this.toRealPath(n));if(!r)return!1;try{return await pe.promises.lstat(r),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=Vt(n);return Rn(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Rn(n,"binary")}async readFileBuffer(t,n=new Set){Q(t,"open");let r=z(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let u=this.resolveSymlink(r,s.target);return this.readFileBuffer(u,n)}if(s.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(!s.appendChunks||s.appendChunks.length===0)return s.content;let a=s.appendChunks.reduce((u,c)=>u+c.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 u of s.appendChunks)o.set(u,l),l+=u.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 pe.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${t}'`);let u=await pe.promises.readlink(i),c=this.realTargetToVirtual(r,u),f=this.resolveSymlink(r,c);return this.readFileBuffer(f,n)}if(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?pe.constants.O_RDONLY:pe.constants.O_RDONLY|pe.constants.O_NOFOLLOW,l=await pe.promises.open(i,o);try{let u=await l.readFile();return new Uint8Array(u)}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){Q(t,"write"),this.assertWritable(`write '${t}'`);let s=z(t);this.ensureParentDirs(s);let i=Vt(r),a=Nn(n,i);this.setMemoryEntry(s,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(s)}async appendFile(t,n,r){Q(t,"append"),this.assertWritable(`append '${t}'`);let s=z(t),i=Vt(r),a=Nn(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){Q(t,"stat");let r=z(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let 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 pe.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let o=await pe.promises.readlink(i),l=this.realTargetToVirtual(r,o),u=this.resolveSymlink(r,l);return this.stat(u,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){Q(t,"lstat");let n=z(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let i=0;return r.type==="file"&&(i=r.content.length+(r.appendChunks?.reduce((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 pe.promises.lstat(s);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime,dev:i.dev,ino:i.ino}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}resolveSymlink(t,n){return Cn(t,n)}realTargetToVirtual(t,n){let r=Of(n,this.canonicalRoot);if(r.withinRoot){if(!De.isAbsolute(n))return n;let s=r.relativePath;return this.mountPoint==="/"?s:`${this.mountPoint}${s}`}return r.safeName}async mkdir(t,n){Q(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=z(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=dt(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),u=l.split("/")[0];u&&!l.includes("/",u.length)&&s.add(u)}for(let[o,l]of this.memory)if(o!==n&&o.startsWith(i)){let u=o.slice(i.length),c=u.split("/")[0];c&&!s.has(c)&&!u.includes("/",1)&&r.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let a=this.resolveRealPath_(this.toRealPath(n));if(a)try{if(!this.allowSymlinks&&(await pe.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 pe.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=z(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 pe.promises.lstat(l)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let c=await pe.promises.readlink(l),f=this.realTargetToVirtual(r,c),d=this.resolveSymlink(r,f);return this.resolveForReaddir(d,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async createExclusive(t,n){let r=n.directory?"mkdir":"open";Q(t,r),this.assertWritable(`${r} '${t}'`);let s=z(t);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);let i=dt(s),a=s;if(i!=="/"){let o;try{o=await this.realpath(i)}catch{throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`)}let l=await this.stat(o).catch(()=>null);if(!l)throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);if(!l.isDirectory)throw new Error(`ENOTDIR: not a directory, ${r} '${t}'`);if(a=rt(o,s.slice(s.lastIndexOf("/")+1)),a!==s&&await this.existsInOverlay(a))throw new Error(`EEXIST: file already exists, ${r} '${t}'`)}if(this.memory.has(a))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);this.setMemoryEntry(a,n.directory?{type:"directory",mode:n.mode,mtime:new Date}:{type:"file",content:new Uint8Array(0),mode:n.mode,mtime:new Date}),this.deleted.delete(a)}async readdir(t){Q(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.keys()).sort((i,a)=>i<a?-1:i>a?1:0)}async readdirWithFileTypes(t){Q(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.values()).sort((i,a)=>i.name<a.name?-1:i.name>a.name?1:0)}async rm(t,n){Q(t,"rm"),this.assertWritable(`rm '${t}'`);let r=z(t);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(r)).isDirectory){let 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 pe.lstatSync(r),!0}catch{return!1}}async cp(t,n,r){Q(t,"cp"),Q(n,"cp"),this.assertWritable(`cp '${n}'`);let s=z(t),i=z(n);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let 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(It(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(s);for(let u of l){let c=s==="/"?`/${u}`:`${s}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(c,f,r)}}}async mv(t,n){this.assertWritable(`mv '${n}'`),await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return Pn(t,n)}getAllPaths(){let t=new Set(this.memory.keys());for(let n of this.deleted)t.delete(n);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,n){if(this.deleted.has(t))return;let r=this.resolveRealPath_(this.toRealPath(t));if(r)try{let s=pe.readdirSync(r);for(let i of s){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;n.add(a);let o=De.join(r,i);pe.lstatSync(o).isDirectory()&&this.scanRealFs(a,n)}}catch{}}async chmod(t,n){Q(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=z(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(r);if(i){i.mode=n;return}let 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}'`);Q(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=z(n);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.setMemoryEntry(r,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(t,n){Q(t,"link"),Q(n,"link"),this.assertWritable(`link '${n}'`);let r=z(t),s=z(n);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let 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){Q(t,"readlink");let n=z(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let r=this.memory.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await pe.promises.readlink(s);if(!De.isAbsolute(i)){let a=De.resolve(De.dirname(s),i),o;try{o=pe.realpathSync(a)}catch{o=a}if(!xr(o,this.canonicalRoot))return De.basename(i)}return this.realTargetToVirtual(n,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){Q(t,"realpath");let n=z(t),r=new Set,s=async o=>{let l=o==="/"?[]:o.slice(1).split("/"),u="";for(let c of l){if(u=`${u}/${c}`,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(u),d=0,p=40;for(;f&&f.type==="symlink"&&d<p;){if(r.add(u),u=this.resolveSymlink(u,f.target),d++,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(u)}if(d>=p)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let h=this.toRealPath(u),m=this.resolveRealPath_(h);if(m)try{if((await pe.promises.lstat(m)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let S=await pe.promises.readlink(m),y=this.realTargetToVirtual(u,S);return r.add(u),u=this.resolveSymlink(u,y),s(u)}}catch(E){if(E.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(E,t,"realpath")}else if(!this.allowSymlinks){let E=this.resolveRealPathParent_(h);if(E)try{if((await pe.promises.lstat(E)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch(S){if(S.message?.includes("ENOENT")||S.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(S,t,"realpath")}}}}return u||"/"},i=await s(n);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,n,r){Q(t,"utimes"),this.assertWritable(`utimes '${t}'`);let s=z(t);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let 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})}};var ke={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"},ao=class{env;rl;running=!0;history=[];initialization;isInteractive;constructor(t={}){let n=process.cwd(),r=new Fs({root:n,mountPoint:"/"});this.env=new Ms({fs:r,cwd:t.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...t.env},network:t.network===!0?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.initialization=this.seedFiles(r,t.files),this.isInteractive=process.stdin.isTTY===!0,this.rl=Mf.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C
806
811
  `),this.prompt()}),process.stdin.isTTY&&this.rl.on("close",()=>{this.running=!1,console.log(`
807
- Goodbye!`),process.exit(0)})}async seedFiles(t,n){if(n)for(let[r,s]of Object.entries(n)){if(typeof s!="string")throw new TypeError(`Invalid --files content for ${r}`);let i=t.resolvePath("/",r);await t.mkdir(kf.posix.dirname(i),{recursive:!0}),await t.writeFile(i,s)}}syncHistory(){let t=this.env.getEnv();t.BASH_HISTORY=JSON.stringify(this.history)}getPrompt(){let t=this.env.getCwd(),n=this.env.getEnv().HOME||"/home/user",r=t;return t===n?r="~":t.startsWith(`${n}/`)&&(r=`~${t.slice(n.length)}`),`${ke.green}${ke.bold}user@virtual${ke.reset}:${ke.blue}${ke.bold}${r}${ke.reset}$ `}async executeCommand(t){let n=t.trim();if(n){if(this.history.push(n),n==="exit"||n.startsWith("exit ")){let r=n.split(/\s+/),s=r[1]?parseInt(r[1],10):0;console.log("exit"),process.exit(s)}this.syncHistory();try{let r=await this.env.exec(n);r.stdout&&process.stdout.write(r.stdout),r.stderr&&process.stderr.write(`${ke.red}${r.stderr}${ke.reset}`)}catch(r){console.error(`${ke.red}Error: ${tt(r)}${ke.reset}`)}}}printWelcome(){console.log(`
812
+ Goodbye!`),process.exit(0)})}async seedFiles(t,n){if(n)for(let[r,s]of Object.entries(n)){if(typeof s!="string")throw new TypeError(`Invalid --files content for ${r}`);let i=t.resolvePath("/",r);await t.mkdir(Tf.posix.dirname(i),{recursive:!0}),await t.writeFile(i,s)}}syncHistory(){let t=this.env.getEnv();t.BASH_HISTORY=JSON.stringify(this.history)}getPrompt(){let t=this.env.getCwd(),n=this.env.getEnv().HOME||"/home/user",r=t;return t===n?r="~":t.startsWith(`${n}/`)&&(r=`~${t.slice(n.length)}`),`${ke.green}${ke.bold}user@virtual${ke.reset}:${ke.blue}${ke.bold}${r}${ke.reset}$ `}async executeCommand(t){let n=t.trim();if(n){if(this.history.push(n),n==="exit"||n.startsWith("exit ")){let r=n.split(/\s+/),s=r[1]?parseInt(r[1],10):0;console.log("exit"),process.exit(s)}this.syncHistory();try{let r=await this.env.exec(n);r.stdout&&process.stdout.write(r.stdout),r.stderr&&process.stderr.write(`${ke.red}${r.stderr}${ke.reset}`)}catch(r){console.error(`${ke.red}Error: ${nt(r)}${ke.reset}`)}}}printWelcome(){console.log(`
808
813
  ${ke.cyan}${ke.bold}\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
809
814
  \u2551 Virtual Shell v1.0 \u2551
810
815
  \u2551 A simulated bash environment in TypeScript \u2551
@@ -814,7 +819,7 @@ ${ke.dim}Exploring: ${process.cwd()}${ke.reset}
814
819
 
815
820
  Type ${ke.green}help${ke.reset} for available commands, ${ke.green}exit${ke.reset} to quit.
816
821
  Reads from real filesystem, writes stay in memory (OverlayFs).
817
- `)}prompt(){this.rl.question(this.getPrompt(),async t=>{this.running&&(await this.executeCommand(t),this.prompt())})}async run(){if(await this.initialization,this.isInteractive)this.printWelcome(),this.prompt();else{let t=[];this.rl.on("line",n=>{t.push(n)}),await new Promise(n=>{this.rl.on("close",n)});for(let n of t)await this.executeCommand(n)}}};function zm(){let e=process.argv.slice(2),t={};for(let n=0;n<e.length;n++)if(e[n]==="--cwd"&&e[n+1])t.cwd=e[++n];else if(e[n]==="--files"&&e[n+1]){let r=e[++n];try{let s=xf.readFileSync(r,"utf-8");t.files=JSON.parse(s)}catch(s){console.error(`Error reading files from ${r}:`,s),process.exit(1)}}else e[n]==="--network"?t.network=!0:e[n]==="--no-network"?t.network=!1:(e[n]==="--help"||e[n]==="-h")&&(console.log(`
822
+ `)}prompt(){this.rl.question(this.getPrompt(),async t=>{this.running&&(await this.executeCommand(t),this.prompt())})}async run(){if(await this.initialization,this.isInteractive)this.printWelcome(),this.prompt();else{let t=[];this.rl.on("line",n=>{t.push(n)}),await new Promise(n=>{this.rl.on("close",n)});for(let n of t)await this.executeCommand(n)}}};function Gm(){let e=process.argv.slice(2),t={};for(let n=0;n<e.length;n++)if(e[n]==="--cwd"&&e[n+1])t.cwd=e[++n];else if(e[n]==="--files"&&e[n+1]){let r=e[++n];try{let s=Lf.readFileSync(r,"utf-8");t.files=JSON.parse(s)}catch(s){console.error(`Error reading files from ${r}:`,s),process.exit(1)}}else e[n]==="--network"?t.network=!0:e[n]==="--no-network"?t.network=!1:(e[n]==="--help"||e[n]==="-h")&&(console.log(`
818
823
  Usage: pnpm shell [options]
819
824
 
820
825
  Interactive shell using OverlayFs - reads from the current directory,
@@ -830,4 +835,4 @@ Options:
830
835
  Example:
831
836
  pnpm shell
832
837
  pnpm shell --network
833
- `),process.exit(0));return t}var qm=zm(),Um=new Ka(qm);Um.run().catch(e=>{console.error(`Error initializing virtual shell: ${tt(e)}`),process.exitCode=1});
838
+ `),process.exit(0));return t}var Hm=Gm(),Zm=new ao(Hm);Zm.run().catch(e=>{console.error(`Error initializing virtual shell: ${nt(e)}`),process.exitCode=1});