just-bash 3.2.0 → 3.4.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 (288) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +47 -0
  3. package/dist/ast/types.d.ts +4 -1
  4. package/dist/bin/chunks/{awk2-7UZLEPVX.js → awk2-DZN2ZRSE.js} +1 -1
  5. package/dist/bin/{shell/chunks/base64-W6FVFNXJ.js → chunks/base64-TP4NUOEB.js} +1 -1
  6. package/dist/bin/chunks/{cat-5YECZSFQ.js → cat-A3REFE6L.js} +1 -1
  7. package/dist/bin/{shell/chunks/chmod-45TMYSW2.js → chunks/chmod-PHPDPTZD.js} +1 -1
  8. package/dist/bin/{shell/chunks/chunk-DSZQ22OX.js → chunks/chunk-35BSNGJK.js} +1 -1
  9. package/dist/bin/{shell/chunks/chunk-BWRQ5HYX.js → chunks/chunk-3DCUOX7D.js} +1 -1
  10. package/dist/bin/{shell/chunks/chunk-OKU677H3.js → chunks/chunk-57BWX3A3.js} +1 -1
  11. package/dist/bin/chunks/{chunk-QF7PPON7.js → chunk-5SR55TXB.js} +10 -10
  12. package/dist/bin/{shell/chunks/chunk-XAAXPEOP.js → chunks/chunk-62NF3462.js} +1 -1
  13. package/dist/bin/{shell/chunks/chunk-3OYRDLJJ.js → chunks/chunk-6KTOOQK6.js} +1 -1
  14. package/dist/bin/chunks/chunk-6WNZWDBA.js +12 -0
  15. package/dist/bin/chunks/{chunk-QK6BXSHU.js → chunk-7NMBLWZ5.js} +1 -1
  16. package/dist/bin/chunks/{chunk-W4U4QOZF.js → chunk-BPMGKB5E.js} +1 -1
  17. package/dist/bin/{shell/chunks/chunk-NGD6G5ZG.js → chunks/chunk-BXDEO6VY.js} +1 -1
  18. package/dist/bin/chunks/{chunk-XBB73LFB.js → chunk-CMTQFWZK.js} +2 -2
  19. package/dist/bin/chunks/{chunk-ZXIW4JPL.js → chunk-DX5LO7JF.js} +1 -1
  20. package/dist/bin/chunks/{chunk-SSK3N7FN.js → chunk-EJIZDPMG.js} +1 -1
  21. package/dist/bin/chunks/{chunk-PQPFDJFF.js → chunk-FC5CC5UP.js} +1 -1
  22. package/dist/bin/chunks/chunk-FE6GSISP.js +22 -0
  23. package/dist/bin/chunks/{chunk-VTAIIBJT.js → chunk-GE5ERIO2.js} +1 -1
  24. package/dist/bin/{shell/chunks/chunk-NQQ3X7MZ.js → chunks/chunk-GGPUS2B4.js} +1 -1
  25. package/dist/bin/chunks/{chunk-WWOUFMMY.js → chunk-IHS3YLRI.js} +1 -1
  26. package/dist/bin/chunks/{chunk-3HUI54BW.js → chunk-KHS7PCAP.js} +2 -2
  27. package/dist/bin/chunks/chunk-KP2UH5CJ.js +22 -0
  28. package/dist/bin/chunks/{chunk-B7RRNV3A.js → chunk-MLJZPRDV.js} +1 -1
  29. package/dist/bin/chunks/chunk-MOCKUJD6.js +21 -0
  30. package/dist/bin/{shell/chunks/chunk-TPU3OX2A.js → chunks/chunk-NFYXRUSI.js} +1 -1
  31. package/dist/bin/{shell/chunks/chunk-IAAPXDHN.js → chunks/chunk-NWBQ75GZ.js} +1 -1
  32. package/dist/bin/chunks/{chunk-YMELOXDK.js → chunk-O5R7J45W.js} +8 -8
  33. package/dist/bin/chunks/{chunk-7I6MNC5I.js → chunk-OD2SHTFL.js} +1 -1
  34. package/dist/bin/chunks/{chunk-BNYIXXC2.js → chunk-ODCVIRIN.js} +1 -1
  35. package/dist/bin/{shell/chunks/chunk-NJ67YJRE.js → chunks/chunk-ODPB5AH7.js} +1 -1
  36. package/dist/bin/chunks/chunk-QUWWWM4E.js +276 -0
  37. package/dist/bin/chunks/{chunk-JQER3HUP.js → chunk-ROFYAVPF.js} +2 -2
  38. package/dist/bin/chunks/chunk-SHAOH2UJ.js +5 -0
  39. package/dist/bin/chunks/{chunk-PKWK3LQM.js → chunk-SOKKZSUV.js} +1 -1
  40. package/dist/bin/{shell/chunks/chunk-WSLBBXPJ.js → chunks/chunk-TIYIKCEZ.js} +1 -1
  41. package/dist/bin/chunks/{chunk-4SQKKW2M.js → chunk-TKBTWIXO.js} +1 -1
  42. package/dist/bin/{shell/chunks/chunk-VY2K25J4.js → chunks/chunk-TOTKK2XI.js} +1 -1
  43. package/dist/bin/{shell/chunks/chunk-X63MJBLH.js → chunks/chunk-TY77F4UM.js} +1 -1
  44. package/dist/bin/chunks/{chunk-CB4SODHK.js → chunk-XBX7KFWK.js} +19 -19
  45. package/dist/bin/{shell/chunks/chunk-GEUCQ4AB.js → chunks/chunk-XG7YUZ3R.js} +1 -1
  46. package/dist/bin/chunks/chunk-YABXNPH6.js +65 -0
  47. package/dist/bin/{shell/chunks/chunk-TL4JI2SL.js → chunks/chunk-YB3A42T5.js} +17 -18
  48. package/dist/bin/chunks/{chunk-MZM7RVYU.js → chunk-YBTJPT3R.js} +1 -1
  49. package/dist/bin/chunks/{chunk-X5VUGFUL.js → chunk-Z7QCL4IA.js} +1 -1
  50. package/dist/bin/chunks/{echo-4OUEL7QB.js → echo-NYDCCFWB.js} +1 -1
  51. package/dist/bin/{shell/chunks/expr-56X7LYOS.js → chunks/expr-FAB3XEIB.js} +1 -1
  52. package/dist/bin/{shell/chunks/file-SQSOBJLR.js → chunks/file-ZHL2YACR.js} +1 -1
  53. package/dist/bin/chunks/{find-XY2NTAT5.js → find-6DH6TRDN.js} +1 -1
  54. package/dist/bin/chunks/{flag-coverage-WGSE667D.js → flag-coverage-SPPGTKG3.js} +1 -1
  55. package/dist/bin/{shell/chunks/grep-CMT2H2S7.js → chunks/grep-FBVRTH4M.js} +1 -1
  56. package/dist/bin/chunks/{gzip-DJSFJOY6.js → gzip-AWQGRTSF.js} +1 -1
  57. package/dist/bin/{shell/chunks/head-KPRH4HKC.js → chunks/head-A7CPWX7R.js} +1 -1
  58. package/dist/bin/{shell/chunks/html-to-markdown-WUBAMB4O.js → chunks/html-to-markdown-EMODJ24M.js} +1 -1
  59. package/dist/bin/chunks/{jq-ACCMBTSD.js → jq-DXL4NMI5.js} +1 -1
  60. package/dist/bin/{shell/chunks/js-exec-4KNUPGHA.js → chunks/js-exec-BFLXGNPQ.js} +1 -1
  61. package/dist/bin/chunks/js-exec-worker.js +56 -20
  62. package/dist/bin/chunks/{ls-FTHYNINH.js → ls-R6DAGGBH.js} +1 -1
  63. package/dist/bin/chunks/{od-A7CW5RMS.js → od-ZPR6FUOW.js} +1 -1
  64. package/dist/bin/{shell/chunks/paste-YJLYVJMP.js → chunks/paste-RQKXCKQO.js} +1 -1
  65. package/dist/bin/chunks/{printf-F2KOCULO.js → printf-CNXNRQ3I.js} +1 -1
  66. package/dist/bin/chunks/python3-WKVKCO33.js +14 -0
  67. package/dist/bin/{shell/chunks/rg-JRKJ6I4X.js → chunks/rg-34TWIR7N.js} +1 -1
  68. package/dist/bin/{shell/chunks/sed-QJ2LNV2N.js → chunks/sed-SW74NKGU.js} +1 -1
  69. package/dist/bin/{shell/chunks/sleep-FUDWGDCE.js → chunks/sleep-J2AVORMB.js} +1 -1
  70. package/dist/bin/{shell/chunks/split-7IYQYKOW.js → chunks/split-EDDYGW4A.js} +1 -1
  71. package/dist/bin/chunks/{sqlite3-ZXF6BGDW.js → sqlite3-AZ27WWV7.js} +1 -1
  72. package/dist/bin/{shell/chunks/stat-Y5D3VPLG.js → chunks/stat-XNGV2W6W.js} +1 -1
  73. package/dist/bin/{shell/chunks/tail-QISQLA3I.js → chunks/tail-H2WOZSEI.js} +1 -1
  74. package/dist/bin/chunks/{tar-TB2XWXF6.js → tar-MZP7QXR4.js} +1 -1
  75. package/dist/bin/{shell/chunks/timeout-TDOV6JDA.js → chunks/timeout-GH6S72QX.js} +1 -1
  76. package/dist/bin/chunks/{tr-AR6EK7JH.js → tr-RVCBERJ4.js} +1 -1
  77. package/dist/bin/chunks/undici-CKF2L2IP.js +141 -0
  78. package/dist/bin/chunks/worker.js +17 -1
  79. package/dist/bin/chunks/{xan-D6US4ZGL.js → xan-BSNJF6SH.js} +1 -1
  80. package/dist/bin/chunks/{xan-view-QGKWT354.js → xan-view-H3LNQ72O.js} +1 -1
  81. package/dist/bin/chunks/{yq-EYV7HLKK.js → yq-GNMXK6OP.js} +1 -1
  82. package/dist/bin/just-bash.js +396 -394
  83. package/dist/bin/shell/chunks/{awk2-7UZLEPVX.js → awk2-DZN2ZRSE.js} +1 -1
  84. package/dist/bin/{chunks/base64-W6FVFNXJ.js → shell/chunks/base64-TP4NUOEB.js} +1 -1
  85. package/dist/bin/shell/chunks/{cat-5YECZSFQ.js → cat-A3REFE6L.js} +1 -1
  86. package/dist/bin/{chunks/chmod-45TMYSW2.js → shell/chunks/chmod-PHPDPTZD.js} +1 -1
  87. package/dist/bin/{chunks/chunk-DSZQ22OX.js → shell/chunks/chunk-35BSNGJK.js} +1 -1
  88. package/dist/bin/{chunks/chunk-BWRQ5HYX.js → shell/chunks/chunk-3DCUOX7D.js} +1 -1
  89. package/dist/bin/{chunks/chunk-OKU677H3.js → shell/chunks/chunk-57BWX3A3.js} +1 -1
  90. package/dist/bin/shell/chunks/{chunk-QF7PPON7.js → chunk-5SR55TXB.js} +10 -10
  91. package/dist/bin/{chunks/chunk-XAAXPEOP.js → shell/chunks/chunk-62NF3462.js} +1 -1
  92. package/dist/bin/{chunks/chunk-3OYRDLJJ.js → shell/chunks/chunk-6KTOOQK6.js} +1 -1
  93. package/dist/bin/shell/chunks/chunk-6WNZWDBA.js +12 -0
  94. package/dist/bin/shell/chunks/{chunk-QK6BXSHU.js → chunk-7NMBLWZ5.js} +1 -1
  95. package/dist/bin/shell/chunks/{chunk-W4U4QOZF.js → chunk-BPMGKB5E.js} +1 -1
  96. package/dist/bin/{chunks/chunk-NGD6G5ZG.js → shell/chunks/chunk-BXDEO6VY.js} +1 -1
  97. package/dist/bin/shell/chunks/{chunk-XBB73LFB.js → chunk-CMTQFWZK.js} +2 -2
  98. package/dist/bin/shell/chunks/{chunk-ZXIW4JPL.js → chunk-DX5LO7JF.js} +1 -1
  99. package/dist/bin/shell/chunks/{chunk-SSK3N7FN.js → chunk-EJIZDPMG.js} +1 -1
  100. package/dist/bin/shell/chunks/{chunk-PQPFDJFF.js → chunk-FC5CC5UP.js} +1 -1
  101. package/dist/bin/shell/chunks/chunk-FE6GSISP.js +22 -0
  102. package/dist/bin/shell/chunks/{chunk-VTAIIBJT.js → chunk-GE5ERIO2.js} +1 -1
  103. package/dist/bin/{chunks/chunk-NQQ3X7MZ.js → shell/chunks/chunk-GGPUS2B4.js} +1 -1
  104. package/dist/bin/shell/chunks/{chunk-WWOUFMMY.js → chunk-IHS3YLRI.js} +1 -1
  105. package/dist/bin/shell/chunks/{chunk-3HUI54BW.js → chunk-KHS7PCAP.js} +2 -2
  106. package/dist/bin/shell/chunks/chunk-KP2UH5CJ.js +22 -0
  107. package/dist/bin/shell/chunks/{chunk-B7RRNV3A.js → chunk-MLJZPRDV.js} +1 -1
  108. package/dist/bin/shell/chunks/chunk-MOCKUJD6.js +21 -0
  109. package/dist/bin/{chunks/chunk-TPU3OX2A.js → shell/chunks/chunk-NFYXRUSI.js} +1 -1
  110. package/dist/bin/{chunks/chunk-IAAPXDHN.js → shell/chunks/chunk-NWBQ75GZ.js} +1 -1
  111. package/dist/bin/shell/chunks/{chunk-YMELOXDK.js → chunk-O5R7J45W.js} +8 -8
  112. package/dist/bin/shell/chunks/{chunk-7I6MNC5I.js → chunk-OD2SHTFL.js} +1 -1
  113. package/dist/bin/shell/chunks/{chunk-BNYIXXC2.js → chunk-ODCVIRIN.js} +1 -1
  114. package/dist/bin/{chunks/chunk-NJ67YJRE.js → shell/chunks/chunk-ODPB5AH7.js} +1 -1
  115. package/dist/bin/shell/chunks/chunk-QUWWWM4E.js +276 -0
  116. package/dist/bin/shell/chunks/{chunk-JQER3HUP.js → chunk-ROFYAVPF.js} +2 -2
  117. package/dist/bin/shell/chunks/chunk-SHAOH2UJ.js +5 -0
  118. package/dist/bin/shell/chunks/{chunk-PKWK3LQM.js → chunk-SOKKZSUV.js} +1 -1
  119. package/dist/bin/{chunks/chunk-WSLBBXPJ.js → shell/chunks/chunk-TIYIKCEZ.js} +1 -1
  120. package/dist/bin/shell/chunks/{chunk-4SQKKW2M.js → chunk-TKBTWIXO.js} +1 -1
  121. package/dist/bin/{chunks/chunk-VY2K25J4.js → shell/chunks/chunk-TOTKK2XI.js} +1 -1
  122. package/dist/bin/{chunks/chunk-X63MJBLH.js → shell/chunks/chunk-TY77F4UM.js} +1 -1
  123. package/dist/bin/shell/chunks/{chunk-CB4SODHK.js → chunk-XBX7KFWK.js} +19 -19
  124. package/dist/bin/{chunks/chunk-GEUCQ4AB.js → shell/chunks/chunk-XG7YUZ3R.js} +1 -1
  125. package/dist/bin/shell/chunks/chunk-YABXNPH6.js +65 -0
  126. package/dist/bin/{chunks/chunk-TL4JI2SL.js → shell/chunks/chunk-YB3A42T5.js} +17 -18
  127. package/dist/bin/shell/chunks/{chunk-MZM7RVYU.js → chunk-YBTJPT3R.js} +1 -1
  128. package/dist/bin/shell/chunks/{chunk-X5VUGFUL.js → chunk-Z7QCL4IA.js} +1 -1
  129. package/dist/bin/shell/chunks/{echo-4OUEL7QB.js → echo-NYDCCFWB.js} +1 -1
  130. package/dist/bin/{chunks/expr-56X7LYOS.js → shell/chunks/expr-FAB3XEIB.js} +1 -1
  131. package/dist/bin/{chunks/file-SQSOBJLR.js → shell/chunks/file-ZHL2YACR.js} +1 -1
  132. package/dist/bin/shell/chunks/{find-XY2NTAT5.js → find-6DH6TRDN.js} +1 -1
  133. package/dist/bin/shell/chunks/{flag-coverage-WGSE667D.js → flag-coverage-SPPGTKG3.js} +1 -1
  134. package/dist/bin/{chunks/grep-CMT2H2S7.js → shell/chunks/grep-FBVRTH4M.js} +1 -1
  135. package/dist/bin/shell/chunks/{gzip-DJSFJOY6.js → gzip-AWQGRTSF.js} +1 -1
  136. package/dist/bin/{chunks/head-KPRH4HKC.js → shell/chunks/head-A7CPWX7R.js} +1 -1
  137. package/dist/bin/{chunks/html-to-markdown-WUBAMB4O.js → shell/chunks/html-to-markdown-EMODJ24M.js} +1 -1
  138. package/dist/bin/shell/chunks/{jq-ACCMBTSD.js → jq-DXL4NMI5.js} +1 -1
  139. package/dist/bin/{chunks/js-exec-4KNUPGHA.js → shell/chunks/js-exec-BFLXGNPQ.js} +1 -1
  140. package/dist/bin/shell/chunks/{ls-FTHYNINH.js → ls-R6DAGGBH.js} +1 -1
  141. package/dist/bin/shell/chunks/{od-A7CW5RMS.js → od-ZPR6FUOW.js} +1 -1
  142. package/dist/bin/{chunks/paste-YJLYVJMP.js → shell/chunks/paste-RQKXCKQO.js} +1 -1
  143. package/dist/bin/shell/chunks/{printf-F2KOCULO.js → printf-CNXNRQ3I.js} +1 -1
  144. package/dist/bin/shell/chunks/python3-WKVKCO33.js +14 -0
  145. package/dist/bin/{chunks/rg-JRKJ6I4X.js → shell/chunks/rg-34TWIR7N.js} +1 -1
  146. package/dist/bin/{chunks/sed-QJ2LNV2N.js → shell/chunks/sed-SW74NKGU.js} +1 -1
  147. package/dist/bin/{chunks/sleep-FUDWGDCE.js → shell/chunks/sleep-J2AVORMB.js} +1 -1
  148. package/dist/bin/{chunks/split-7IYQYKOW.js → shell/chunks/split-EDDYGW4A.js} +1 -1
  149. package/dist/bin/shell/chunks/{sqlite3-ZXF6BGDW.js → sqlite3-AZ27WWV7.js} +1 -1
  150. package/dist/bin/{chunks/stat-Y5D3VPLG.js → shell/chunks/stat-XNGV2W6W.js} +1 -1
  151. package/dist/bin/{chunks/tail-QISQLA3I.js → shell/chunks/tail-H2WOZSEI.js} +1 -1
  152. package/dist/bin/shell/chunks/{tar-TB2XWXF6.js → tar-MZP7QXR4.js} +1 -1
  153. package/dist/bin/{chunks/timeout-TDOV6JDA.js → shell/chunks/timeout-GH6S72QX.js} +1 -1
  154. package/dist/bin/shell/chunks/{tr-AR6EK7JH.js → tr-RVCBERJ4.js} +1 -1
  155. package/dist/bin/shell/chunks/undici-CKF2L2IP.js +141 -0
  156. package/dist/bin/shell/chunks/{xan-D6US4ZGL.js → xan-BSNJF6SH.js} +1 -1
  157. package/dist/bin/shell/chunks/{xan-view-QGKWT354.js → xan-view-H3LNQ72O.js} +1 -1
  158. package/dist/bin/shell/chunks/{yq-EYV7HLKK.js → yq-GNMXK6OP.js} +1 -1
  159. package/dist/bin/shell/shell.js +391 -389
  160. package/dist/bundle/browser.js +837 -824
  161. package/dist/bundle/chunks/{awk2-IPNBFNH2.js → awk2-IDCJYLV2.js} +1 -1
  162. package/dist/bundle/chunks/{base64-OXGTKKDA.js → base64-3XQZ3ADB.js} +1 -1
  163. package/dist/bundle/chunks/{cat-636HYSH4.js → cat-XWS72C47.js} +1 -1
  164. package/dist/bundle/chunks/{chmod-4CIOYX5Q.js → chmod-6FVWFWKL.js} +1 -1
  165. package/dist/bundle/chunks/{chunk-6IUGGJ2Y.js → chunk-264HW33U.js} +1 -1
  166. package/dist/bundle/chunks/{chunk-LGLR6TFP.js → chunk-2TLWENMK.js} +1 -1
  167. package/dist/bundle/chunks/{chunk-AMLHAS2N.js → chunk-4AKAIZPW.js} +9 -9
  168. package/dist/bundle/chunks/{chunk-FBXMKFE2.js → chunk-4HMWZAP7.js} +1 -1
  169. package/dist/bundle/chunks/{chunk-EAQUR2NP.js → chunk-4MPKG4PJ.js} +1 -1
  170. package/dist/bundle/chunks/{chunk-LJRVJXUI.js → chunk-4X2R47I5.js} +1 -1
  171. package/dist/bundle/chunks/{chunk-65Z4QURM.js → chunk-5GI2HJYO.js} +8 -8
  172. package/dist/bundle/chunks/{chunk-PJWSSENQ.js → chunk-6D2ZCRTO.js} +1 -1
  173. package/dist/bundle/chunks/chunk-6RK4AAB7.js +21 -0
  174. package/dist/bundle/chunks/chunk-73DVPW3C.js +20 -0
  175. package/dist/bundle/chunks/{chunk-6SHYIICL.js → chunk-AGH5UJJI.js} +2 -2
  176. package/dist/bundle/chunks/{chunk-RAHPENCM.js → chunk-CA7HMEGG.js} +1 -1
  177. package/dist/bundle/chunks/{chunk-SELXJ5KQ.js → chunk-CVMQI27W.js} +1 -1
  178. package/dist/bundle/chunks/{chunk-ORDZCFFT.js → chunk-CYCUGNN7.js} +1 -1
  179. package/dist/bundle/chunks/{chunk-UB6T3UHL.js → chunk-ENMIHC6G.js} +1 -1
  180. package/dist/bundle/chunks/{chunk-5KGKXQF6.js → chunk-EVJMYTCY.js} +2 -2
  181. package/dist/bundle/chunks/{chunk-JYQ6MII2.js → chunk-EZFSCUSP.js} +1 -1
  182. package/dist/bundle/chunks/{chunk-E3D4WVAH.js → chunk-FFNWVPYL.js} +1 -1
  183. package/dist/bundle/chunks/{chunk-MF4F4ZPP.js → chunk-GP3D65AC.js} +1 -1
  184. package/dist/bundle/chunks/{chunk-EWWPEE2G.js → chunk-HZYCWAEC.js} +17 -18
  185. package/dist/bundle/chunks/{chunk-QTLI5LUD.js → chunk-JQL34RLH.js} +1 -1
  186. package/dist/bundle/chunks/{chunk-JCPCQREJ.js → chunk-KBXRZGTY.js} +1 -1
  187. package/dist/bundle/chunks/{chunk-CN3HTJTZ.js → chunk-KESUKNUF.js} +1 -1
  188. package/dist/bundle/chunks/{chunk-XVL654YD.js → chunk-KVG5FR5F.js} +19 -19
  189. package/dist/bundle/chunks/{chunk-KKVPMNSS.js → chunk-LDCENVG4.js} +1 -1
  190. package/dist/bundle/chunks/chunk-M7DIEMEN.js +275 -0
  191. package/dist/bundle/chunks/{chunk-MAWVZWRK.js → chunk-MMSRUX6V.js} +1 -1
  192. package/dist/bundle/chunks/{chunk-INHMNORI.js → chunk-MP3NNO6W.js} +1 -1
  193. package/dist/bundle/chunks/{chunk-AI5LSBJC.js → chunk-QKQP2SCP.js} +1 -1
  194. package/dist/bundle/chunks/{chunk-OTYP7VVT.js → chunk-QNXJ5FEA.js} +1 -1
  195. package/dist/bundle/chunks/{chunk-K3XJ2WT4.js → chunk-QXYDKHGI.js} +1 -1
  196. package/dist/bundle/chunks/chunk-RT7ROXPF.js +4 -0
  197. package/dist/bundle/chunks/{chunk-WENIVVEE.js → chunk-TUNYNC46.js} +2 -2
  198. package/dist/bundle/chunks/chunk-UGU4ZDZA.js +11 -0
  199. package/dist/bundle/chunks/{chunk-D3W7DTI6.js → chunk-VPJHPG6G.js} +1 -1
  200. package/dist/bundle/chunks/{chunk-5HXWWNWH.js → chunk-VQCA62JK.js} +1 -1
  201. package/dist/bundle/chunks/{chunk-NNH4ERNJ.js → chunk-W4IV5QW4.js} +1 -1
  202. package/dist/bundle/chunks/{chunk-3DHFIWMM.js → chunk-XJWBSZIU.js} +1 -1
  203. package/dist/bundle/chunks/{chunk-VOSNSQE2.js → chunk-XOBSBDA5.js} +1 -1
  204. package/dist/bundle/chunks/chunk-XW6UBSKO.js +64 -0
  205. package/dist/bundle/chunks/{chunk-UK4BO5W3.js → chunk-XZZSXYTK.js} +1 -1
  206. package/dist/bundle/chunks/{echo-HZOVZAPR.js → echo-PLLZYM2L.js} +1 -1
  207. package/dist/bundle/chunks/{expr-SHRJJ4PX.js → expr-VKQHAJNO.js} +1 -1
  208. package/dist/bundle/chunks/{file-YC4YEI4P.js → file-WGI2QYXG.js} +1 -1
  209. package/dist/bundle/chunks/{find-DWWMZFO5.js → find-PM3TD7V4.js} +1 -1
  210. package/dist/bundle/chunks/{flag-coverage-THYQHOT3.js → flag-coverage-6LWPOTGE.js} +1 -1
  211. package/dist/bundle/chunks/{grep-S6SNTIHZ.js → grep-SAEHL7UZ.js} +1 -1
  212. package/dist/bundle/chunks/{gzip-BTI6CWY4.js → gzip-2SHFSHNB.js} +1 -1
  213. package/dist/bundle/chunks/{head-UCOA3VQC.js → head-RMKV5HCV.js} +1 -1
  214. package/dist/bundle/chunks/{html-to-markdown-NUF6QEX4.js → html-to-markdown-GEKF6U7Z.js} +1 -1
  215. package/dist/bundle/chunks/{jq-D6N4QCAJ.js → jq-MW2VEOCW.js} +1 -1
  216. package/dist/bundle/chunks/{js-exec-PNUEDFT5.js → js-exec-J4DLDAWY.js} +1 -1
  217. package/dist/bundle/chunks/js-exec-worker.js +56 -20
  218. package/dist/bundle/chunks/{od-YXD2NNIU.js → od-26HTHXXM.js} +1 -1
  219. package/dist/bundle/chunks/{paste-ZU3EODNI.js → paste-WIDT5N6N.js} +1 -1
  220. package/dist/bundle/chunks/{printf-QHD2JRWQ.js → printf-V42QCPHL.js} +1 -1
  221. package/dist/bundle/chunks/python3-4Q7M5CDT.js +13 -0
  222. package/dist/bundle/chunks/{rg-OUJZ5DH6.js → rg-IA4UE2UF.js} +1 -1
  223. package/dist/bundle/chunks/{sed-TZIPJOGL.js → sed-LSWWSQ6J.js} +1 -1
  224. package/dist/bundle/chunks/{sleep-VPYWSKDR.js → sleep-YMKR4HFQ.js} +1 -1
  225. package/dist/bundle/chunks/{split-KNDNAFPT.js → split-EATPU6Q7.js} +1 -1
  226. package/dist/bundle/chunks/{sqlite3-WWZJZW37.js → sqlite3-XXXHFJGP.js} +1 -1
  227. package/dist/bundle/chunks/{stat-MLNSW25G.js → stat-AKB6X3TV.js} +1 -1
  228. package/dist/bundle/chunks/{tail-G3W6PNG3.js → tail-OEM7DTYC.js} +1 -1
  229. package/dist/bundle/chunks/{tar-GLX6QUHW.js → tar-26DH77YN.js} +1 -1
  230. package/dist/bundle/chunks/{timeout-SYQCWBMZ.js → timeout-FOKHN3GQ.js} +1 -1
  231. package/dist/bundle/chunks/{tr-3KPFH3J4.js → tr-VUNRKFC3.js} +1 -1
  232. package/dist/bundle/chunks/undici-PSPBDOYF.js +140 -0
  233. package/dist/bundle/chunks/worker.js +17 -1
  234. package/dist/bundle/chunks/{xan-KKPV2TJ3.js → xan-LUEGYXLV.js} +1 -1
  235. package/dist/bundle/chunks/{xan-view-47P277LZ.js → xan-view-MDMZTFFI.js} +1 -1
  236. package/dist/bundle/chunks/{yq-ZGB3W46S.js → yq-B7E6UX7Y.js} +1 -1
  237. package/dist/bundle/index.cjs +1029 -1032
  238. package/dist/bundle/index.js +391 -389
  239. package/dist/commands/python3/worker.d.ts +1 -0
  240. package/dist/commands/query-engine/evaluator.d.ts +8 -0
  241. package/dist/fs/read-write-fs/read-write-fs.d.ts +42 -1
  242. package/dist/interpreter/builtin-dispatch.d.ts +9 -2
  243. package/dist/interpreter/builtins/eval.d.ts +7 -1
  244. package/dist/interpreter/control-flow.d.ts +1 -1
  245. package/dist/interpreter/fd-table.d.ts +130 -0
  246. package/dist/interpreter/functions.d.ts +3 -1
  247. package/dist/interpreter/helpers/word-matching.d.ts +0 -10
  248. package/dist/interpreter/interpreter.d.ts +7 -0
  249. package/dist/interpreter/numeric-fd-redirects.d.ts +8 -0
  250. package/dist/interpreter/process-substitution.d.ts +62 -0
  251. package/dist/interpreter/redirections.d.ts +33 -37
  252. package/dist/interpreter/subshell-group.d.ts +10 -2
  253. package/dist/interpreter/types.d.ts +38 -1
  254. package/dist/network/dns-pin.d.ts +11 -0
  255. package/dist/parser/expansion-parser.d.ts +3 -1
  256. package/dist/parser/lexer.d.ts +7 -9
  257. package/dist/parser/parser-substitution.d.ts +13 -4
  258. package/dist/parser/parser.d.ts +18 -4
  259. package/dist/parser/types.d.ts +6 -0
  260. package/dist/parser/word-parser.d.ts +2 -0
  261. package/dist/types.d.ts +13 -0
  262. package/package.json +21 -21
  263. package/dist/bin/chunks/chunk-46CDVHZ3.js +0 -5
  264. package/dist/bin/chunks/chunk-D3MUBZ4P.js +0 -65
  265. package/dist/bin/chunks/chunk-LGERQ5TD.js +0 -22
  266. package/dist/bin/chunks/chunk-LNFTLSWJ.js +0 -22
  267. package/dist/bin/chunks/chunk-P6NPCASY.js +0 -11
  268. package/dist/bin/chunks/chunk-PRKSLEHG.js +0 -291
  269. package/dist/bin/chunks/chunk-WYTPLN2M.js +0 -11
  270. package/dist/bin/chunks/python3-AYUQQRCR.js +0 -14
  271. package/dist/bin/chunks/undici-JES22UVU.js +0 -141
  272. package/dist/bin/shell/chunks/chunk-46CDVHZ3.js +0 -5
  273. package/dist/bin/shell/chunks/chunk-D3MUBZ4P.js +0 -65
  274. package/dist/bin/shell/chunks/chunk-LGERQ5TD.js +0 -22
  275. package/dist/bin/shell/chunks/chunk-LNFTLSWJ.js +0 -22
  276. package/dist/bin/shell/chunks/chunk-P6NPCASY.js +0 -11
  277. package/dist/bin/shell/chunks/chunk-PRKSLEHG.js +0 -291
  278. package/dist/bin/shell/chunks/chunk-WYTPLN2M.js +0 -11
  279. package/dist/bin/shell/chunks/python3-AYUQQRCR.js +0 -14
  280. package/dist/bin/shell/chunks/undici-JES22UVU.js +0 -141
  281. package/dist/bundle/chunks/chunk-NOPXHH6G.js +0 -290
  282. package/dist/bundle/chunks/chunk-T2RHALUC.js +0 -64
  283. package/dist/bundle/chunks/chunk-UBTKJ6MG.js +0 -4
  284. package/dist/bundle/chunks/chunk-VECGTAPW.js +0 -10
  285. package/dist/bundle/chunks/chunk-Y3DGIAIG.js +0 -21
  286. package/dist/bundle/chunks/chunk-YOUUMJLJ.js +0 -10
  287. package/dist/bundle/chunks/python3-QDNG2UXX.js +0 -13
  288. package/dist/bundle/chunks/undici-HCLAUJT3.js +0 -140
@@ -1,240 +1,274 @@
1
1
  #!/usr/bin/env node
2
2
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{a as on,b as ln,c as $t}from"./chunks/chunk-O2BCKSMK.js";import{a as nr}from"./chunks/chunk-3PCPQIUD.js";import{c as ps,e as ga}from"./chunks/chunk-TW2IJRUF.js";import{a as da,b as pa,c as kn,d as Nn}from"./chunks/chunk-SSK3N7FN.js";import{a as xt}from"./chunks/chunk-6D75E4LV.js";import{a as vt,b as Ge,c as ds}from"./chunks/chunk-MROECM42.js";import{a as Pn,b as ya}from"./chunks/chunk-4SQKKW2M.js";import{a as he}from"./chunks/chunk-CB4SODHK.js";import{a as en,b as ze}from"./chunks/chunk-46CDVHZ3.js";import"./chunks/chunk-VLWZ6L7C.js";import{c as At,d as tn}from"./chunks/chunk-CPTQXTBJ.js";import"./chunks/chunk-7JZKVC3F.js";import{a as H,b as nn,c as K,d as rn,e as ir,f as sn,g as an}from"./chunks/chunk-43E7AR6A.js";import{a as ma,b as qe,c as Ue,d as Oe,e as Qe,f as Le,g as j,h as ie,i as je,j as bt,k as rr,l as $,m as Te,n as St,o as sr,p as Ke}from"./chunks/chunk-LCP3IKI7.js";import{a as T,c as qt,e as ha,f as us,g as fs}from"./chunks/chunk-CPKBPQ2C.js";import{a as Me}from"./chunks/chunk-PBOVSFTJ.js";import{a as yt}from"./chunks/chunk-I4IRHQDW.js";import"./chunks/chunk-DN2YCFOR.js";import{resolve as ku}from"node:path";var cn=[{name:"echo",load:async()=>(await import("./chunks/echo-4OUEL7QB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-5YECZSFQ.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-F2KOCULO.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-FTHYNINH.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-45TMYSW2.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-KPRH4HKC.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-QISQLA3I.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-VSQBRD6B.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-Y5D3VPLG.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-CMT2H2S7.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-CMT2H2S7.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-CMT2H2S7.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-JRKJ6I4X.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-QJ2LNV2N.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-7UZLEPVX.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-YJLYVJMP.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-AR6EK7JH.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-7IYQYKOW.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-XY2NTAT5.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-ACCMBTSD.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-W6FVFNXJ.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-FUDWGDCE.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-TDOV6JDA.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-56X7LYOS.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-SQSOBJLR.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-WUBAMB4O.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-A7CW5RMS.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-DJSFJOY6.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-DJSFJOY6.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-DJSFJOY6.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(cn.push({name:"tar",load:async()=>(await import("./chunks/tar-TB2XWXF6.js")).tarCommand}),cn.push({name:"yq",load:async()=>(await import("./chunks/yq-EYV7HLKK.js")).yqCommand}),cn.push({name:"xan",load:async()=>(await import("./chunks/xan-D6US4ZGL.js")).xanCommand}),cn.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-ZXF6BGDW.js")).sqlite3Command}));var hs=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(hs.push({name:"python3",load:async()=>(await import("./chunks/python3-AYUQQRCR.js")).python3Command}),hs.push({name:"python",load:async()=>(await import("./chunks/python3-AYUQQRCR.js")).pythonCommand}));var ms=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(ms.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-4KNUPGHA.js")).jsExecCommand}),ms.push({name:"node",load:async()=>(await import("./chunks/js-exec-4KNUPGHA.js")).nodeStubCommand}));var Ru=[{name:"curl",load:async()=>(await import("./chunks/curl-FS5LAEYI.js")).curlCommand}],wa=new Map;function ar(e){return{name:e.name,async execute(t,n){let r=wa.get(e.name);if(r||(r=await ze.runTrustedAsync(()=>e.load()),wa.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await import("./chunks/flag-coverage-WGSE667D.js");s(n.coverage,e.name,t)}return r.execute(t,n)}}}function Ea(e){return(e?cn.filter(n=>e.includes(n.name)):cn).map(ar)}function ba(){return Ru.map(ar)}function Sa(){return hs.map(ar)}function Aa(){return ms.map(ar)}var va=new WeakMap,xa=new WeakSet;function ys(e){let t=va.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),va.set(e,t),xa.add(t)),t}function $a(e){return xa.has(e)}var ka={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},Iu={...ka,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 gs(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?Iu:ka;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 Na(e){return"load"in e&&typeof e.load=="function"}function Pa(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 Ca=Object.freeze(Object.create(null)),or=class{limits;signal;commandCount=0;workUnits=0;liveBytes=0;inputBytes=0;outputBytes=0;countersByKind=new Map;bytesByKind=new Map;depthByKind=new Map;cleanupCallbacks=[];poisoned;closed=!1;startedAt=Date.now();get remainingLiveBytes(){return Math.max(0,this.limits.maxLiveBytes-this.liveBytes)}get outputBytesUsed(){return this.outputBytes}constructor(t,n=void 0){this.limits=t,this.signal=n}fail(t){throw this.poisoned??=t,this.poisoned}poisonAfterAbort(t){this.poisoned??=t}assertUsable(){if(this.poisoned)throw this.poisoned;if(this.closed)throw new Error("execution budget is already closed");this.throwIfAborted()}chargeCommand(){return this.consume("commands",1,"execution")}consumeWork(t=1,n="execution"){return this.consume("work",t,n)}consumeLimited(t,n,r,s=t){this.assertUsable();let i=this.countersByKind.get(t)??0;return(!Number.isSafeInteger(n)||n<0||!Number.isSafeInteger(r)||r<0||n>r-i)&&this.fail(new $(`${s}: ${t} work limit exceeded (${r})`,"iterations")),n>this.limits.maxWorkUnits-this.workUnits&&this.fail(new $(`${s}: aggregate work limit exceeded (${this.limits.maxWorkUnits})`,"iterations")),this.countersByKind.set(t,i+n),this.workUnits+=n,i+n}consumeInput(t,n="execution"){return this.assertUsable(),(!Number.isSafeInteger(t)||t<0||t>this.limits.maxInputBytes-this.inputBytes)&&this.fail(new $(`${n}: aggregate input size limit exceeded (${this.limits.maxInputBytes} bytes)`,"string_length")),this.inputBytes+=t,this.inputBytes}consume(t,n=1,r=t){this.assertUsable();let s=this.countersByKind.get(t)??0,i=t==="commands"?this.commandCount:this.workUnits,a=t==="commands"?this.limits.maxCommandCount:this.limits.maxWorkUnits;(!Number.isSafeInteger(n)||n<0||n>a-i)&&this.fail(new $(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 $(`${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:T(n);(!Number.isSafeInteger(s)||s<0||s>a)&&this.fail(new $(`${r}: invalid ${t} accounting`,"output_size"));let o=a-s;return o>this.limits.maxOutputSize-this.outputBytes&&this.fail(new $(`${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!==Ca&&this.fail(new $(`${n}: unauthorized output accounting release`,"output_size")),(!Number.isSafeInteger(t)||t<0||t>this.outputBytes)&&this.fail(new $(`${n}: invalid output accounting release`,"output_size")),this.outputBytes-=t}enterDepth(t,n=this.limits.maxCallDepth,r){this.assertUsable();let s=typeof n=="number"?n:this.limits.maxCallDepth,i=typeof n=="string"?n:r??t,a=this.depthByKind.get(t)??0;a>=s&&this.fail(new $(`${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 Te("",`bash: ${t} aborted
4
- `)),Date.now()-this.startedAt>this.limits.maxExecutionTimeMs&&this.fail(new Te("",`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=kn(()=>o({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(Nn(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 $(`maximum nested execution depth (${this.limits.maxExecDepth}) exceeded`,"recursion"))}};function Da(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 Ra(e,t,n="pipeline"){e.relinquishOutput(t,n,Ca)}var Ut=new TextEncoder;function _u(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Cn=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:T(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:T(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):_u(s)?this.writeFileSync(r,s.content,void 0,{mode:s.mode,mtime:s.mtime}):this.writeFileSync(r,s)}ensureParentDirs(t){let n=rn(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){K(t,"write");let i=H(t);this.ensureParentDirs(i);let a=$t(r);this.assertCanAllocate(i,this.contentByteLength(n,a));let o=on(n,a);this.setEntry(i,{type:"file",content:o,mode:s?.mode??420,mtime:s?.mtime??new Date})}writeFileLazy(t,n,r){K(t,"write");let s=H(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"?Ut.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 ln(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return ln(n,"binary")}async readFileBuffer(t){K(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:Ut.encode(s.content)}return r.content instanceof Uint8Array?r.content:Ut.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){K(t,"append");let s=H(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 c="content"in l&&l.content instanceof Uint8Array?l.content:Ut.encode("content"in l?l.content:"");this.assertCanAllocate(s,c.byteLength+o);let u=on(n,a),f=new Uint8Array(c.length+u.length);f.set(c),f.set(u,c.length),this.setEntry(s,{type:"file",content:f,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,n,r)}async exists(t){if(t.includes("\0"))return!1;try{let n=this.resolvePathWithSymlinks(t);return this.data.has(n)}catch{return!1}}async stat(t){K(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=Ut.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){K(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=Ut.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=H(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",i=new Set;for(let a=0;a<r.length-1;a++){let o=r[a];s=`${s}/${o}`;let l=this.data.get(s),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(s),s=an(s,l.target),l=this.data.get(s),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let n=H(t);if(n==="/")return"/";let r=n.slice(1).split("/"),s="",i=new Set;for(let a of r){s=`${s}/${a}`;let o=this.data.get(s),l=0,c=40;for(;o&&o.type==="symlink"&&l<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(s),s=an(s,o.target),o=this.data.get(s),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return s}async mkdir(t,n){this.mkdirSync(t,n)}mkdirSync(t,n){K(t,"mkdir");let r=H(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=rn(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){K(t,"scandir");let n=H(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=an(n,r.target),r=this.data.get(n)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=n==="/"?"/":`${n}/`,a=new Map;for(let[o,l]of this.data.entries())if(o!==n&&o.startsWith(i)){let c=o.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!a.has(u)&&a.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(a.values()).sort((o,l)=>o.name<l.name?-1:o.name>l.name?1:0)}async rm(t,n){K(t,"rm");let r=H(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=sn(r,a);await this.rm(o,n)}}}this.deleteEntry(r)}async cp(t,n,r){K(t,"cp"),K(n,"cp");let s=H(t),i=H(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:Ut.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(nn(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(s);for(let l of o){let c=sn(s,l),u=sn(i,l);await this.cp(c,u,r)}}}async mv(t,n){K(t,"mv"),K(n,"mv");let r=H(t),s=H(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"&&nn(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(sn(r,o),sn(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 ir(t,n)}async chmod(t,n){K(t,"chmod");let r=H(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){K(n,"symlink");let r=H(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){K(t,"link"),K(n,"link");let r=H(t),s=H(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){K(t,"readlink");let n=H(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){K(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){K(t,"utimes");let s=H(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 _a="5.1.0(1)-release",Oa="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function Es(e){let{pid:t,ppid:n,uid:r,gid:s}=e;return`Name: bash
3
+ import{a as bn,b as Sn,c as Ot}from"./chunks/chunk-O2BCKSMK.js";import{a as Er}from"./chunks/chunk-3PCPQIUD.js";import{c as Os,e as Jo}from"./chunks/chunk-TW2IJRUF.js";import{a as Ko,b as Xo,c as qn,d as Un}from"./chunks/chunk-EJIZDPMG.js";import{a as It}from"./chunks/chunk-6D75E4LV.js";import{a as Dt,b as He,c as Is}from"./chunks/chunk-MROECM42.js";import{a as jn,b as Yo}from"./chunks/chunk-TKBTWIXO.js";import{a as me}from"./chunks/chunk-XBX7KFWK.js";import{a as pn,b as Oe}from"./chunks/chunk-SHAOH2UJ.js";import"./chunks/chunk-VLWZ6L7C.js";import{c as Rt,d as yn}from"./chunks/chunk-CPTQXTBJ.js";import"./chunks/chunk-7JZKVC3F.js";import{a as z,b as vt,c as Q,d as gn,e as wn,f as xt,g as En}from"./chunks/chunk-43E7AR6A.js";import{a as mn,b as je,c as Ge,d as De,e as Me,f as Fe,g as U,h as ae,i as Ze,j as Ct,k as br,l as k,m as Be,n as Nt,o as Sr,p as et}from"./chunks/chunk-LCP3IKI7.js";import{a as F,c as en,e as hn,f as Pt,g as Ds}from"./chunks/chunk-CPKBPQ2C.js";import{a as We}from"./chunks/chunk-PBOVSFTJ.js";import{a as At}from"./chunks/chunk-I4IRHQDW.js";import"./chunks/chunk-DN2YCFOR.js";import{resolve as vf}from"node:path";var An=[{name:"echo",load:async()=>(await import("./chunks/echo-NYDCCFWB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-A3REFE6L.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-PHPDPTZD.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-A7CPWX7R.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-H2WOZSEI.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-VSQBRD6B.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-XNGV2W6W.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-FBVRTH4M.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-FBVRTH4M.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-FBVRTH4M.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-34TWIR7N.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-SW74NKGU.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-DZN2ZRSE.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-RQKXCKQO.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-RVCBERJ4.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-EDDYGW4A.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-DXL4NMI5.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-TP4NUOEB.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-J2AVORMB.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-GH6S72QX.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-FAB3XEIB.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-ZHL2YACR.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-EMODJ24M.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-ZPR6FUOW.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-AWQGRTSF.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-AWQGRTSF.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-AWQGRTSF.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(An.push({name:"tar",load:async()=>(await import("./chunks/tar-MZP7QXR4.js")).tarCommand}),An.push({name:"yq",load:async()=>(await import("./chunks/yq-GNMXK6OP.js")).yqCommand}),An.push({name:"xan",load:async()=>(await import("./chunks/xan-BSNJF6SH.js")).xanCommand}),An.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-AZ27WWV7.js")).sqlite3Command}));var _s=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(_s.push({name:"python3",load:async()=>(await import("./chunks/python3-WKVKCO33.js")).python3Command}),_s.push({name:"python",load:async()=>(await import("./chunks/python3-WKVKCO33.js")).pythonCommand}));var Ls=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ls.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-BFLXGNPQ.js")).jsExecCommand}),Ls.push({name:"node",load:async()=>(await import("./chunks/js-exec-BFLXGNPQ.js")).nodeStubCommand}));var Cf=[{name:"curl",load:async()=>(await import("./chunks/curl-FS5LAEYI.js")).curlCommand}],ea=new Map;function Ar(e){return{name:e.name,async execute(t,n){let r=ea.get(e.name);if(r||(r=await Oe.runTrustedAsync(()=>e.load()),ea.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await import("./chunks/flag-coverage-SPPGTKG3.js");s(n.coverage,e.name,t)}return r.execute(t,n)}}}function ta(e){return(e?An.filter(n=>e.includes(n.name)):An).map(Ar)}function na(){return Cf.map(Ar)}function ra(){return _s.map(Ar)}function sa(){return Ls.map(Ar)}var ia=new WeakMap,oa=new WeakSet;function Ts(e){let t=ia.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),ia.set(e,t),oa.add(t)),t}function aa(e){return oa.has(e)}var la={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},Nf={...la,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 Ms(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?Nf:la;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 ua(e){return"load"in e&&typeof e.load=="function"}function ca(e){let t=null,n=null;return{name:e.name,trusted:e.trusted!==!1,async execute(r,s){if(!t){let o=n;o||(o=e.load().then(a=>(t=a,a)),n=o);try{t=await o}catch(a){throw n===o&&(n=null),a}}let i=t;if(!i)throw new Error(`Failed to load command: ${e.name}`);return i.execute(r,s)}}}var fa=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,o=t==="commands"?this.limits.maxCommandCount:this.limits.maxWorkUnits;(!Number.isSafeInteger(n)||n<0||n>o-i)&&this.fail(new k(t==="commands"?`too many commands executed (>${o}), increase executionLimits.maxCommandCount`:`${r}: ${t} work limit exceeded (${o})`,t==="commands"?"commands":"iterations"));let a=i+n;return t==="commands"?this.commandCount=a:this.workUnits=a,this.countersByKind.set(t,s+n),a}reserveBytes(t,n,r){this.assertUsable();let s=typeof t=="string"?t:"live",i=typeof t=="string"?n:t,o=typeof t=="string"?r??s:n??"execution";(!Number.isSafeInteger(i)||i<0||i>this.limits.maxLiveBytes-this.liveBytes)&&this.fail(new k(`${o}: live byte limit exceeded (${this.limits.maxLiveBytes} bytes)`,"string_length")),this.liveBytes+=i,this.bytesByKind.set(s,(this.bytesByKind.get(s)??0)+i);let a=!1;return{release:()=>{if(a)return;a=!0,this.liveBytes-=i;let l=(this.bytesByKind.get(s)??i)-i;l<=0?this.bytesByKind.delete(s):this.bytesByKind.set(s,l)}}}appendOutput(t,n,r="execution",s=0,i="text"){this.assertUsable();let o=i==="bytes"?n.length:F(n);(!Number.isSafeInteger(s)||s<0||s>o)&&this.fail(new k(`${r}: invalid ${t} accounting`,"output_size"));let a=o-s;return a>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+=a,o}accountResult(t,n="execution",r=Number.POSITIVE_INFINITY){let s=t.internalOutputAccounting,i=Math.min(s?.stdout??0,r),o=Math.min(s?.stderr??0,Math.max(0,r-i)),a=this.appendOutput("stdout",t.stdout,n,i,t.stdoutKind==="bytes"||t.stdoutEncoding==="binary"?"bytes":"text"),l=this.appendOutput("stderr",t.stderr,n,o);return Object.isExtensible(t)?(t.internalOutputAccounting={stdout:a,stderr:l},t):a===0&&l===0?t:{...t,internalOutputAccounting:{stdout:a,stderr:l}}}relinquishOutput(t,n,r){this.assertUsable(),r!==fa&&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,o=this.depthByKind.get(t)??0;o>=s&&this.fail(new k(`${i}: maximum depth (${s}) exceeded`,"recursion")),this.depthByKind.set(t,o+1);let a=!1;return{release:()=>{if(a)return;a=!0;let l=(this.depthByKind.get(t)??1)-1;l<=0?this.depthByKind.delete(t):this.depthByKind.set(t,l)}}}throwIfAborted(t="execution"){this.signal?.aborted&&this.fail(new Be("",`bash: ${t} aborted
4
+ `)),Date.now()-this.startedAt>this.limits.maxExecutionTimeMs&&this.fail(new Be("",`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,o=await Promise.race([Promise.resolve().then(this.cleanupCallbacks[r]).then(()=>({ok:!0}),a=>({ok:!1,error:a})),new Promise(a=>{i=qn(()=>a({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(Un(i),!o.ok&&(t.push(o.error),Date.now()>=n))break}catch(s){t.push(s)}if(this.cleanupCallbacks.length=0,this.depthByKind.clear(),this.bytesByKind.clear(),this.liveBytes=0,t.length>0)throw new AggregateError(t,"execution cleanup failed")}assertExecDepth(t){this.assertUsable(),t>this.limits.maxExecDepth&&this.fail(new k(`maximum nested execution depth (${this.limits.maxExecDepth}) exceeded`,"recursion"))}};function da(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 pa(e,t,n="pipeline"){e.relinquishOutput(t,n,fa)}var tn=new TextEncoder;function Rf(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var ht=class{data=new Map;entryIdentities=new WeakMap;nextEntryIdentity=1;maxTotalBytes;retainedBytes=0;contentReferences=new WeakMap;materializedContent(t){return t?.type==="file"&&"content"in t?t.content:null}storedByteLength(t){return t===null?0:t instanceof Uint8Array?t.byteLength:F(t)}wouldReleaseBytes(t){let n=this.materializedContent(t);return n===null?0:n instanceof Uint8Array?this.contentReferences.get(n)===1?n.byteLength:0:this.storedByteLength(n)}assertCanAllocate(t,n){let r=this.wouldReleaseBytes(this.data.get(t));if(!Number.isSafeInteger(n)||n<0||n>this.maxTotalBytes-this.retainedBytes+r)throw new Error(`ENOSPC: in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`)}setEntry(t,n){let r=this.data.get(t),s=this.materializedContent(r),i=this.materializedContent(n);if(s===i){this.data.set(t,n);return}let o=this.wouldReleaseBytes(r),a=i instanceof Uint8Array?this.contentReferences.has(i)?0:i.byteLength:this.storedByteLength(i);if(a>this.maxTotalBytes-this.retainedBytes+o)throw new Error(`ENOSPC: in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`);if(s instanceof Uint8Array){let l=this.contentReferences.get(s)??0;l<=1?this.contentReferences.delete(s):this.contentReferences.set(s,l-1)}i instanceof Uint8Array&&this.contentReferences.set(i,(this.contentReferences.get(i)??0)+1),this.retainedBytes+=a-o,this.data.set(t,n)}deleteEntry(t){let n=this.data.get(t);if(!n)return!1;let r=this.materializedContent(n),s=this.wouldReleaseBytes(n);if(r instanceof Uint8Array){let i=this.contentReferences.get(r)??0;i<=1?this.contentReferences.delete(r):this.contentReferences.set(r,i-1)}return this.retainedBytes-=s,this.data.delete(t)}contentByteLength(t,n){if(t instanceof Uint8Array)return t.byteLength;if(n==="hex")return Math.floor(t.length/2);if(n==="base64"){let r=t.endsWith("==")?2:t.endsWith("=")?1:0;return Math.max(0,Math.floor(t.length*3/4)-r)}return n==="binary"||n==="latin1"?t.length:F(t)}identityFor(t){let n=this.entryIdentities.get(t);return n||(n=`memfs:${this.nextEntryIdentity++}`,this.entryIdentities.set(t,n)),n}constructor(t,n={}){if(this.maxTotalBytes=n.maxTotalBytes??1024*1024*1024,!Number.isSafeInteger(this.maxTotalBytes)||this.maxTotalBytes<0)throw new Error("InMemoryFs: invalid maxTotalBytes");if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[r,s]of Object.entries(t))typeof s=="function"?this.writeFileLazy(r,s):Rf(s)?this.writeFileSync(r,s.content,void 0,{mode:s.mode,mtime:s.mtime}):this.writeFileSync(r,s)}ensureParentDirs(t){let n=gn(t);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,n,r,s){Q(t,"write");let i=z(t);this.ensureParentDirs(i);let o=Ot(r);this.assertCanAllocate(i,this.contentByteLength(n,o));let a=bn(n,o);this.setEntry(i,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}writeFileLazy(t,n,r){Q(t,"write");let s=z(t);this.ensureParentDirs(s),this.setEntry(s,{type:"file",lazy:n,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,n){let r=await n.lazy(),s=typeof r=="string"?tn.encode(r):r,i={type:"file",content:s,mode:n.mode,mtime:n.mtime};return this.assertCanAllocate(t,s.byteLength),this.setEntry(t,i),i}async readFile(t,n){let r=await this.readFileBuffer(t),s=Ot(n);return Sn(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Sn(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:tn.encode(s.content)}return r.content instanceof Uint8Array?r.content:tn.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){Q(t,"append");let s=z(t),i=this.data.get(s);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=Ot(r),a=this.contentByteLength(n,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(s,l));let u="content"in l&&l.content instanceof Uint8Array?l.content:tn.encode("content"in l?l.content:"");this.assertCanAllocate(s,u.byteLength+a);let c=bn(n,o),f=new Uint8Array(u.length+c.length);f.set(u),f.set(c,u.length),this.setEntry(s,{type:"file",content:f,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,n,r)}async exists(t){if(t.includes("\0"))return!1;try{let n=this.resolvePathWithSymlinks(t);return this.data.has(n)}catch{return!1}}async stat(t){Q(t,"stat");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=tn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}async lstat(t){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=tn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}resolveIntermediateSymlinks(t){let n=z(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];s=`${s}/${a}`;let l=this.data.get(s),u=0,c=40;for(;l&&l.type==="symlink"&&u<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(s),s=En(s,l.target),l=this.data.get(s),u++}if(u>=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let n=z(t);if(n==="/")return"/";let r=n.slice(1).split("/"),s="",i=new Set;for(let o of r){s=`${s}/${o}`;let a=this.data.get(s),l=0,u=40;for(;a&&a.type==="symlink"&&l<u;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(s),s=En(s,a.target),a=this.data.get(s),l++}if(l>=u)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return s}async mkdir(t,n){this.mkdirSync(t,n)}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=gn(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=En(n,r.target),r=this.data.get(n)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=n==="/"?"/":`${n}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==n&&a.startsWith(i)){let u=a.slice(i.length),c=u.split("/")[0];c&&!u.includes("/",c.length)&&!o.has(c)&&o.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,n){Q(t,"rm");let r=z(t),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(s.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=xt(r,o);await this.rm(a,n)}}}this.deleteEntry(r)}async cp(t,n,r){Q(t,"cp"),Q(n,"cp");let s=z(t),i=z(n),o=this.data.get(s);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")if(this.ensureParentDirs(i),"content"in o){let a=o.content instanceof Uint8Array?o.content.byteLength:tn.encode(o.content).byteLength;this.assertCanAllocate(i,a);let l=o.content instanceof Uint8Array?new Uint8Array(o.content):o.content;this.setEntry(i,{...o,content:l})}else this.setEntry(i,{...o});else if(o.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(vt(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(s);for(let l of a){let u=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"&&vt(r,s))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);if(i.type==="directory"){await this.mkdir(s,{recursive:!0});let o=await this.readdir(r);for(let a of o)await this.mv(xt(r,a),xt(s,a));this.deleteEntry(r);return}this.ensureParentDirs(s),this.setEntry(s,i),this.deleteEntry(r)}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,n){return wn(t,n)}async chmod(t,n){Q(t,"chmod");let r=z(t),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);s.mode=n}async symlink(t,n){Q(n,"symlink");let r=z(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,n){Q(t,"link"),Q(n,"link");let r=z(t),s=z(n),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let o=i;"lazy"in o&&(o=await this.materializeLazy(r,o)),this.ensureParentDirs(s);let a={type:"file",content:o.content,mode:o.mode,mtime:o.mtime};this.entryIdentities.set(a,this.identityFor(o)),this.setEntry(s,a)}async readlink(t){Q(t,"readlink");let n=z(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){Q(t,"realpath");let n=this.resolvePathWithSymlinks(t);if(!this.data.has(n))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return n}async utimes(t,n,r){Q(t,"utimes");let s=z(t),i=this.resolvePathWithSymlinks(s),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=r}};var ma="5.1.0(1)-release",ya="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function Bs(e){let{pid:t,ppid:n,uid:r,gid:s}=e;return`Name: bash
6
6
  State: R (running)
7
7
  Pid: ${t}
8
8
  PPid: ${n}
9
9
  Uid: ${r} ${r} ${r} ${r}
10
10
  Gid: ${s} ${s} ${s} ${s}
11
- `}function Ou(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Lu(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 Tu(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function Mu(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Oa}
11
+ `}function Df(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function If(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 Of(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 _f(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${ya}
12
12
  `),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",()=>Es(t)):e.writeFileSync("/proc/self/status",Es(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 La(e,t,n={pid:1,ppid:0,uid:1e3,gid:1e3}){Ou(e)&&(Lu(e,t),Tu(e),Mu(e,n))}function De(e){return{kind:e.kind,elements:new Map(e.elements)}}function ct(e){return new Map(Array.from(e??[],([t,n])=>[t,De(n)]))}function Se(e,t){return e.state.arrays?.get(t)}function Dn(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 kt(e,t,n){let r=Dn(e,t,n);return r.kind=n,r}function $e(e,t){return e.state.arrays?.has(t)??!1}function se(e,t,n){return Se(e,t)?.elements.get(String(n))}function Nt(e,t,n){return Se(e,t)?.elements.has(String(n))??!1}function F(e,t,n,r,s){let i=Dn(e,t,s),a=String(n);if(!i.elements.has(a)&&i.elements.size>=e.limits.maxArrayElements)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(T(r)>e.limits.maxStringLength)throw new $(`array value string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");i.elements.set(a,r)}function jt(e,t,n,r=!1){let s=new Set(r?[]:Se(e,t)?.elements.keys()??[]);for(let i of n)if(s.add(String(i)),s.size>e.limits.maxArrayElements)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements")}function Gt(e,t,n){return Se(e,t)?.elements.delete(String(n))??!1}function Rn(e,t){e.state.arrays?.delete(t),e.state.associativeArrays?.delete(t)}function Ee(e,t){return Array.from(Se(e,t)?.elements.keys()??[]).filter(r=>/^(0|[1-9]\d*)$/.test(r)).map(Number).sort((r,s)=>r-s)}function me(e,t){Dn(e,t,e.state.associativeArrays?.has(t)?"associative":"indexed").elements.clear()}function ut(e,t){return Array.from(Se(e,t)?.elements.keys()??[]).sort()}function cr(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function bs(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=cr(r);let a;if(s.type!=="Literal")return null;s.value.startsWith("]=")||s.value.startsWith("]+=")?a=s.value.slice(1):a=s.value;let o=a.startsWith("+=");if(!o&&!a.startsWith("="))return null;let l=[],c=o?2:1,u=a.slice(c);u&&l.push({type:"Literal",value:u});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?l.push({type:"Literal",value:Bu(d)}):l.push(d)}return{key:r,valueParts:l,append:o}}function Bu(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 fn(n.word)}).join(",")}}`}function fn(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}`:""}`:fn(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",n.user&&(t+=n.user);break}return t}var Wu=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],Fu=["braceexpand","hashall","interactive-comments"];function Ss(e){let t=[],n=[...Fu.map(r=>({name:r,enabled:!0})),...Wu.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 dn(e){e.state.env.set("SHELLOPTS",Ss(e.state.options))}var Vu=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function As(e){let t=[];for(let n of Vu)e[n]&&t.push(n);return t.join(":")}function vs(e){e.state.env.set("BASHOPTS",As(e.state.shoptOptions))}var L={script(e){return{type:"Script",statements:e}},statement(e,t=[],n=!1,r,s){let i={type:"Statement",pipelines:e,operators:t,background:n};return r&&(i.deferredError=r),s!==void 0&&(i.sourceText=s),i},pipeline(e,t=!1,n=!1,r=!1,s){return{type:"Pipeline",commands:e,negated:t,timed:n,timePosix:r,pipeStderr:s}},simpleCommand(e,t=[],n=[],r=[]){return{type:"SimpleCommand",name:e,args:t,assignments:n,redirections:r}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},assignment(e,t,n=!1,r=null){return{type:"Assignment",name:e,value:t,append:n,array:r}},redirection(e,t,n=null,r){let s={type:"Redirection",fd:n,operator:e,target:t};return r&&(s.fdVariable=r),s},hereDoc(e,t,n=!1,r=!1){return{type:"HereDoc",delimiter:e,content:t,stripTabs:n,quoted:r}},ifNode(e,t=null,n=[]){return{type:"If",clauses:e,elseBody:t,redirections:n}},forNode(e,t,n,r=[]){return{type:"For",variable:e,words:t,body:n,redirections:r}},whileNode(e,t,n=[]){return{type:"While",condition:e,body:t,redirections:n}},untilNode(e,t,n=[]){return{type:"Until",condition:e,body:t,redirections:n}},caseNode(e,t,n=[]){return{type:"Case",word:e,items:t,redirections:n}},caseItem(e,t,n=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:n}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,n=[],r){return{type:"FunctionDef",name:e,body:t,redirections:n,sourceFile:r}},conditionalCommand(e,t=[],n){return{type:"ConditionalCommand",expression:e,redirections:t,line:n}},arithmeticCommand(e,t=[],n){return{type:"ArithmeticCommand",expression:e,redirections:t,line:n}}};function Ta(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 xs(e,t){let n="",r=t,s=i=>i===" "||i===" "||i===`
14
- `||i===";"||i==="&"||i==="|"||i==="<"||i===">"||i==="("||i===")";for(;r<e.length;){let i=e[r];if(i==="'"){for(r++;r<e.length&&e[r]!=="'";)n+=e[r],r++;r<e.length&&r++;continue}if(i==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length&&r++,n+=e[r],r++;r<e.length&&r++;continue}if(i==="\\"&&r+1<e.length){n+=e[r+1],r+=2;continue}if(s(i))break;n+=i,r++}return{delim:n,endPos:r}}function zu(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(`
15
- `,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 Ma(e,t,n,r){let s=t+2,i=1,a=s,o=!1,l=!1,c=0,u=!1,f="",d=[],p=0;for(;a<e.length&&i>0;){let b=e[a];if(o)b==="'"&&(o=!1);else if(l)b==="\\"&&a+1<e.length?a++:b==='"'&&(l=!1);else{if(b==="("&&e[a+1]==="("?p++:b===")"&&e[a+1]===")"&&p>0&&p--,p===0&&b==="<"&&e[a+1]==="<"&&e[a+2]!=="<"){let g=a+2,w=!1;for(e[g]==="-"&&(w=!0,g++);e[g]===" "||e[g]===" ";)g++;let{delim:S,endPos:v}=xs(e,g);if(S.length>0){d.push({delim:S,stripTabs:w}),f="",a=v;continue}}if(b===`
16
- `&&d.length>0){let g=zu(e,a,d);d.length=0,f="",a=g;continue}b==="'"?(o=!0,f=""):b==='"'?(l=!0,f=""):b==="\\"&&a+1<e.length?(a++,f=""):/[a-zA-Z_]/.test(b)?f+=b:(f==="case"?(c++,u=!1):f==="in"&&c>0?u=!0:f==="esac"&&c>0&&(c--,u=!1),f="",b==="("?a>0&&e[a-1]==="$"?i++:u||i++:b===")"?u?u=!1:i--:b===";"&&c>0&&a+1<e.length&&e[a+1]===";"&&(u=!0))}i>0&&a++}i>0&&r("unexpected EOF while looking for matching `)'");let h=e.slice(s,a),E=n().parse(h);return{part:L.commandSubstitution(E,!1),endIndex:a+1}}function Ba(e,t,n,r,s){let a=t+1,o="";for(;a<e.length&&e[a]!=="`";)if(e[a]==="\\"){let u=e[a+1];u==="$"||u==="`"||u==="\\"||u===`
17
- `||n&&u==='"'?(u!==`
18
- `&&(o+=u),a+=2):(o+=e[a],a++)}else o+=e[a],a++;a>=e.length&&s("unexpected EOF while looking for matching ``'");let c=r().parse(o);return{part:L.commandSubstitution(c,!0),endIndex:a+1}}var qu=10485760,y;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(y||(y={}));var Pt=class extends Error{line;column;constructor(t,n,r){super(`line ${n}: ${t}`),this.line=n,this.column=r,this.name="LexerError"}},Wa=new Map([["if",y.IF],["then",y.THEN],["else",y.ELSE],["elif",y.ELIF],["fi",y.FI],["for",y.FOR],["while",y.WHILE],["until",y.UNTIL],["do",y.DO],["done",y.DONE],["case",y.CASE],["esac",y.ESAC],["in",y.IN],["function",y.FUNCTION],["select",y.SELECT],["time",y.TIME],["coproc",y.COPROC]]);function Fa(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 Va(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 Uu=[[";",";","&",y.SEMI_SEMI_AND],["<","<","<",y.TLESS],["&",">",">",y.AND_DGREAT]],ju=[["[","[",y.DBRACK_START],["]","]",y.DBRACK_END],["(","(",y.DPAREN_START],[")",")",y.DPAREN_END],["&","&",y.AND_AND],["|","|",y.OR_OR],[";",";",y.DSEMI],[";","&",y.SEMI_AND],["|","&",y.PIPE_AMP],[">",">",y.DGREAT],["<","&",y.LESSAND],[">","&",y.GREATAND],["<",">",y.LESSGREAT],[">","|",y.CLOBBER],["&",">",y.AND_GREAT]],Gu=new Map([["|",y.PIPE],["&",y.AMP],[";",y.SEMICOLON],["(",y.LPAREN],[")",y.RPAREN],["<",y.LESS],[">",y.GREAT]]);function Zu(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function za(e){return e===" "||e===" "||e===`
19
- `||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var ur=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];dparenDepth=0;maxHeredocSize;constructor(t,n){this.input=t,this.maxHeredocSize=n?.maxHeredocSize??qu}tokenize(){let n=this.input.length,r=this.tokens,s=this.pendingHeredocs;for(;this.pos<n;){if(s.length>0&&r.length>0&&r[r.length-1].type===y.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=n)break;let i=this.nextToken();i&&r.push(i)}return r.push({type:y.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let t=this.input,n=t.length,r=this.pos,s=this.column,i=this.line;for(;r<n;){let a=t[r];if(a===" "||a===" ")r++,s++;else if(a==="\\"&&t[r+1]===`
20
- `)r+=2,i++,s=1;else break}this.pos=r,this.column=s,this.line=i}nextToken(){let t=this.input,n=this.pos,r=this.line,s=this.column,i=t[n],a=t[n+1],o=t[n+2];if(i==="#"&&this.dparenDepth===0)return this.readComment(n,r,s);if(i===`
21
- `)return this.pos=n+1,this.line++,this.column=1,{type:y.NEWLINE,value:`
22
- `,start:n,end:n+1,line:r,column:s};if(i==="<"&&a==="<"&&o==="-")return this.pos=n+3,this.column=s+3,this.registerHeredocFromLookahead(!0),this.makeToken(y.DLESSDASH,"<<-",n,r,s);for(let[c,u,f,d]of Uu)if(i===c&&a===u&&o===f)return this.pos=n+3,this.column=s+3,this.makeToken(d,c+u+f,n,r,s);if(i==="<"&&a==="<")return this.pos=n+2,this.column=s+2,this.registerHeredocFromLookahead(!1),this.makeToken(y.DLESS,"<<",n,r,s);if(i==="("&&a==="(")return this.dparenDepth>0?(this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(y.LPAREN,"(",n,r,s)):this.looksLikeNestedSubshells(n+2)||this.dparenClosesWithSpacedParens(n+2)?(this.pos=n+1,this.column=s+1,this.makeToken(y.LPAREN,"(",n,r,s)):(this.pos=n+2,this.column=s+2,this.dparenDepth=1,this.makeToken(y.DPAREN_START,"((",n,r,s));if(i===")"&&a===")")return this.dparenDepth===1?(this.pos=n+2,this.column=s+2,this.dparenDepth=0,this.makeToken(y.DPAREN_END,"))",n,r,s)):this.dparenDepth>1?(this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(y.RPAREN,")",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(y.RPAREN,")",n,r,s));for(let[c,u,f]of ju)if(!(c==="("&&u==="("||c===")"&&u===")")&&!(this.dparenDepth>0&&c===";"&&(f===y.DSEMI||f===y.SEMI_AND||f===y.SEMI_SEMI_AND))&&i===c&&a===u){if(f===y.DBRACK_START||f===y.DBRACK_END){let d=t[n+2];if(d!==void 0&&d!==" "&&d!==" "&&d!==`
23
- `&&d!==";"&&d!=="&"&&d!=="|"&&d!=="("&&d!==")"&&d!=="<"&&d!==">")break}return this.pos=n+2,this.column=s+2,this.makeToken(f,c+u,n,r,s)}if(i==="("&&this.dparenDepth>0)return this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(y.LPAREN,"(",n,r,s);if(i===")"&&this.dparenDepth>1)return this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(y.RPAREN,")",n,r,s);let l=Gu.get(i);if(l!==void 0)return this.pos=n+1,this.column=s+1,this.makeToken(l,i,n,r,s);if(i==="{"){let c=this.scanFdVariable(n);return c!==null?(this.pos=c.end,this.column=s+(c.end-n),{type:y.FD_VARIABLE,value:c.varname,start:n,end:c.end,line:r,column:s}):a==="}"?(this.pos=n+2,this.column=s+2,{type:y.WORD,value:"{}",start:n,end:n+2,line:r,column:s,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(n)!==null?this.readWordWithBraceExpansion(n,r,s):this.scanLiteralBraceWord(n)!==null?this.readWordWithBraceExpansion(n,r,s):a!==void 0&&a!==" "&&a!==" "&&a!==`
24
- `?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(y.LBRACE,"{",n,r,s))}return i==="}"?this.isWordCharFollowing(n+1)?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(y.RBRACE,"}",n,r,s)):i==="!"?a==="="?(this.pos=n+2,this.column=s+2,this.makeToken(y.WORD,"!=",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(y.BANG,"!",n,r,s)):this.readWord(n,r,s)}looksLikeNestedSubshells(t){let n=this.input,r=n.length,s=t;for(;s<r&&(n[s]===" "||n[s]===" ");)s++;if(s>=r)return!1;let i=n[s];if(i==="(")return this.looksLikeNestedSubshells(s+1);let a=/[a-zA-Z_]/.test(i),o=i==="!"||i==="[";if(!a&&!o)return!1;let l=s;for(;l<r&&/[a-zA-Z0-9_\-.]/.test(n[l]);)l++;if(l===s)return o;let c=l;for(;c<r&&(n[c]===" "||n[c]===" ");)c++;if(c>=r)return!1;let u=n[c];if(u==="="&&n[c+1]!=="="||u===`
25
- `||l===c&&/[+\-*/%<>&|^!~?:]/.test(u)&&u!=="-"||u===")"&&n[c+1]===")")return!1;if(c>l&&(u==="-"||u==='"'||u==="'"||u==="$"||/[a-zA-Z_/.]/.test(u))){let f=c;for(;f<r&&n[f]!==`
26
- `;){if(n[f]===")")return!0;f++}return!1}if(u===")"){let f=c+1;for(;f<r&&(n[f]===" "||n[f]===" ");)f++;if(n[f]==="|"&&n[f+1]==="|"||n[f]==="&"&&n[f+1]==="&"||n[f]===";"||n[f]==="|"&&n[f+1]!=="|")return!0}return!1}makeToken(t,n,r,s,i){return{type:t,value:n,start:r,end:this.pos,line:s,column:i}}readComment(t,n,r){let s=this.input,i=s.length,a=this.pos;for(;a<i&&s[a]!==`
27
- `;)a++;let o=s.slice(t,a);return this.pos=a,this.column=r+(a-t),{type:y.COMMENT,value:o,start:t,end:a,line:n,column:r}}readWord(t,n,r){let s=this.input,i=s.length,a=this.pos,o=a;for(;a<i;){let w=s[a];if(w===" "||w===" "||w===`
28
- `||w===";"||w==="&"||w==="|"||w==="("||w===")"||w==="<"||w===">"||w==="'"||w==='"'||w==="\\"||w==="$"||w==="`"||w==="{"||w==="}"||w==="~"||w==="*"||w==="?"||w==="[")break;a++}if(a>o){let w=s[a];if(!(w==="("&&a>o&&"@*+?!".includes(s[a-1]))){if(a>=i||w===" "||w===" "||w===`
29
- `||w===";"||w==="&"||w==="|"||w==="("||w===")"||w==="<"||w===">"){let S=s.slice(o,a);this.pos=a,this.column=r+(a-o);let v=Wa.get(S);if(v!==void 0)return{type:v,value:S,start:t,end:a,line:n,column:r};let A=Va(S);return A>0&&Fa(S.slice(0,A))?{type:y.ASSIGNMENT_WORD,value:S,start:t,end:a,line:n,column:r}:/^[0-9]+$/.test(S)?{type:y.NUMBER,value:S,start:t,end:a,line:n,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(S)?{type:y.NAME,value:S,start:t,end:a,line:n,column:r,quoted:!1,singleQuoted:!1}:{type:y.WORD,value:S,start:t,end:a,line:n,column:r,quoted:!1,singleQuoted:!1}}}}a=this.pos;let l=this.column,c=this.line,u="",f=!1,d=!1,p=!1,h=!1,m=s[a]==='"'||s[a]==="'",E=!1,b=0;for(;a<i;){let w=s[a];if(!p&&!h){if(w==="("&&u.length>0&&"@*+?!".includes(u[u.length-1])){let S=this.scanExtglobPattern(a);if(S!==null){u+=S.content,a=S.end,l+=S.content.length;continue}}if(w==="["&&b===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){let S=a+1<i?s[a+1]:"";if(S==="^"||S==="!"){u+=w,a++,l++;continue}b=1,u+=w,a++,l++;continue}}else if(w==="["&&b>0){u.length>0&&u[u.length-1]!=="\\"&&b++,u+=w,a++,l++;continue}else if(w==="]"&&b>0){u.length>0&&u[u.length-1]!=="\\"&&b--,u+=w,a++,l++;continue}if(b>0){if(w===`
30
- `)break;u+=w,a++,l++;continue}if(w===" "||w===" "||w===`
31
- `||w===";"||w==="&"||w==="|"||w==="("||w===")"||w==="<"||w===">")break}if(w==="$"&&a+1<i&&s[a+1]==="'"&&!p&&!h){for(u+="$'",a+=2,l+=2;a<i&&s[a]!=="'";)s[a]==="\\"&&a+1<i?(u+=s[a]+s[a+1],a+=2,l+=2):(u+=s[a],a++,l++);a<i&&(u+="'",a++,l++);continue}if(w==="$"&&a+1<i&&s[a+1]==='"'&&!p&&!h){a++,l++,h=!0,f=!0,u===""&&(m=!0),a++,l++;continue}if(w==="'"&&!h){if(p)if(p=!1,!m||E)u+=w;else{let S=a+1<i?s[a+1]:"";S&&!za(S)&&S!=="'"&&(S==='"'?(E=!0,u+=w,d=!1,f=!1):(E=!0,u+=w))}else p=!0,m&&!E?(d=!0,f=!0):u+=w;a++,l++;continue}if(w==='"'&&!p){if(h)if(h=!1,!m||E)u+=w;else{let S=a+1<i?s[a+1]:"";S&&!za(S)&&S!=='"'&&(S==="'"?(E=!0,u+=w,d=!1,f=!1):(E=!0,u+=w))}else h=!0,m&&!E?f=!0:u+=w;a++,l++;continue}if(w==="\\"&&!p&&a+1<i){let S=s[a+1];if(S===`
32
- `){a+=2,c++,l=1;continue}if(h){if(S==='"'||S==="\\"||S==="$"||S==="`"||S===`
13
+ `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>Bs(t)):e.writeFileSync("/proc/self/status",Bs(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function ga(e,t,n={pid:1,ppid:0,uid:1e3,gid:1e3}){Df(e)&&(If(e,t),Of(e),_f(e,n))}function _e(e){return{kind:e.kind,elements:new Map(e.elements)}}function tt(e){return new Map(Array.from(e??[],([t,n])=>[t,_e(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 _t(e,t,n){let r=Gn(e,t,n);return r.kind=n,r}function ke(e,t){return e.state.arrays?.has(t)??!1}function oe(e,t,n){return ve(e,t)?.elements.get(String(n))}function Lt(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),o=String(n);if(!i.elements.has(o)&&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(o,r)}function nn(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 rn(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 mt(e,t){return Array.from(ve(e,t)?.elements.keys()??[]).sort()}function $r(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function Ws(e){if(e.parts.length<2)return null;let t=e.parts[0],n=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let r,s=n,i=1;if(n.type==="Literal"&&n.value.startsWith("]")){let f=n.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))r=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let d=e.parts[2];if(d.type!=="Literal"||!d.value.startsWith("=")&&!d.value.startsWith("+="))return null;r=t.pattern.slice(1),s=d,i=2}else return null}else if(t.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(n.type==="SingleQuoted")r=n.value;else{r="";for(let d of n.parts)(d.type==="Literal"||d.type==="Escaped")&&(r+=d.value)}s=f,i=2}else if(t.pattern.endsWith("]")){if(n.type!=="Literal"||!n.value.startsWith("=")&&!n.value.startsWith("+="))return null;r=t.pattern.slice(1,-1)}else return null;r=$r(r);let o;if(s.type!=="Literal")return null;s.value.startsWith("]=")||s.value.startsWith("]+=")?o=s.value.slice(1):o=s.value;let a=o.startsWith("+=");if(!a&&!o.startsWith("="))return null;let l=[],u=a?2:1,c=o.slice(u);c&&l.push({type:"Literal",value:c});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?l.push({type:"Literal",value:Lf(d)}):l.push(d)}return{key:r,valueParts:l,append:a}}function Lf(e){return`{${e.items.map(n=>{if(n.type==="Range"){let r=n.startStr??String(n.start),s=n.endStr??String(n.end),i=`${r}..${s}`;return n.step&&(i+=`..${n.step}`),i}return 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 Tf=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],Mf=["braceexpand","hashall","interactive-comments"];function Vs(e){let t=[],n=[...Mf.map(r=>({name:r,enabled:!0})),...Tf.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",Vs(e.state.options))}var Ff=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function zs(e){let t=[];for(let n of Ff)e[n]&&t.push(n);return t.join(":")}function qs(e){e.state.env.set("BASHOPTS",zs(e.state.shoptOptions))}var 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 wa(e,t){let n=e.length,r=t+3,s=2,i=!1,o=!1;for(;r<n&&s>0;){let a=e[r];if(i){a==="'"&&(i=!1),r++;continue}if(o){if(a==="\\"){r+=2;continue}a==='"'&&(o=!1),r++;continue}if(a==="'"){i=!0,r++;continue}if(a==='"'){o=!0,r++;continue}if(a==="\\"){r+=2;continue}if(a==="("){s++,r++;continue}if(a===")"){if(s--,s===1){let l=r+1;return!(l<n&&e[l]===")")}if(s===0)return!1;r++;continue}if(s===1&&(a==="|"&&r+1<n&&e[r+1]==="|"||a==="&"&&r+1<n&&e[r+1]==="&"||a==="|"&&r+1<n&&e[r+1]!=="|"))return!0;r++}return!1}function kr(e,t){let n="",r=t,s=0,i=!1,o,a=l=>l===" "||l===" "||l===`
14
+ `||l===";"||l==="&"||l==="|"||l==="<"||l===">"||l==="("||l===")";for(;r<e.length;){let l=e[r];if(l==="'"){let u=s>0;for(u||(i=!0),u&&(n+=l),r++;r<e.length&&e[r]!=="'";)n+=e[r],r++;r<e.length?(u&&(n+=e[r]),r++):o=l;continue}if(l==='"'){let u=s>0;for(u||(i=!0),u&&(n+=l),r++;r<e.length&&e[r]!=='"';){if(e[r]==="\\"&&r+1<e.length){if(u){n+=e.slice(r,r+2),r+=2;continue}let c=e[r+1];if(c==="$"||c==="`"||c==='"'||c==="\\"||c===`
15
+ `){r+=2,c!==`
16
+ `&&(n+=c);continue}}n+=e[r],r++}r<e.length?(u&&(n+=e[r]),r++):o=l;continue}if(l==="\\"&&r+1<e.length){if(s>0){n+=e.slice(r,r+2),r+=2;continue}i=!0;let u=e[r+1];u!==`
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&&a(l))break;s>0&&(l==="("?s++:l===")"&&s--),n+=l,r++}return{delim:n,endPos:r,quoted:i,unclosedQuote:o,unclosedSubstitution:s>0}}function Bf(e,t,n){let r=t+1;for(let{delim:s,stripTabs:i}of n)for(;;){if(r>=e.length)return e.length;let o=e.indexOf(`
18
+ `,r);o===-1&&(o=e.length);let a=e.slice(r,o);if(i&&(a=a.replace(/^\t+/,"")),a===s){r=o+1;break}if(o>=e.length)return e.length;r=o+1}return Math.min(r,e.length)}function Ea(e,t,n){let r=1,s=t,i=!1,o=!1,a=0,l=!1,u="",c=[],f=0;for(;s<e.length&&r>0;){let d=e[s];if(i)d==="'"&&(i=!1);else if(o)d==="\\"&&s+1<e.length?s++:d==='"'&&(o=!1);else{if(d==="("&&e[s+1]==="("?f++:d===")"&&e[s+1]===")"&&f>0&&f--,f===0&&d==="<"&&e[s+1]==="<"&&e[s+2]!=="<"){let p=s+2,h=!1;for(e[p]==="-"&&(h=!0,p++);e[p]===" "||e[p]===" ";)p++;let{delim:m,endPos:E,unclosedQuote: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=Bf(e,s,c);c.length=0,u="",s=p;continue}d==="'"?(i=!0,u=""):d==='"'?(o=!0,u=""):d==="\\"&&s+1<e.length?(s++,u=""):/[a-zA-Z_]/.test(d)?u+=d:(u==="case"?(a++,l=!1):u==="in"&&a>0?l=!0:u==="esac"&&a>0&&(a--,l=!1),u="",d==="("?s>0&&e[s-1]==="$"?r++:l||r++:d===")"?l?l=!1:r--:d===";"&&a>0&&s+1<e.length&&e[s+1]===";"&&(l=!0))}r>0&&s++}return r>0&&n("unexpected EOF while looking for matching `)'"),s}function ba(e,t,n,r){let s=t+2,i=Ea(e,s,r),o=e.slice(s,i),l=n().parse(o);return{part:T.commandSubstitution(l,!1),endIndex:i+1}}function Sa(e,t,n,r){let s=e[t]==="<"?"input":"output",i=t+2,o=Ea(e,i,r),a=n().parse(e.slice(i,o));return{part:T.processSubstitution(a,s),endIndex:o+1}}function Aa(e,t,n,r,s){let o=t+1,a="";for(;o<e.length&&e[o]!=="`";)if(e[o]==="\\"){let c=e[o+1];c==="$"||c==="`"||c==="\\"||c===`
20
+ `||n&&c==='"'?(c!==`
21
+ `&&(a+=c),o+=2):(a+=e[o],o++)}else a+=e[o],o++;o>=e.length&&s("unexpected EOF while looking for matching ``'");let u=r().parse(a);return{part:T.commandSubstitution(u,!0),endIndex:o+1}}var Wf=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"}},Us=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]]),Vf=new Set(Us.values());function js(e){return Vf.has(e)}function va(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 xa(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 zf=[[";",";","&",w.SEMI_SEMI_AND],["<","<","<",w.TLESS],["&",">",">",w.AND_DGREAT]],qf=[["[","[",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]],Uf=new Map([["|",w.PIPE],["&",w.AMP],[";",w.SEMICOLON],["(",w.LPAREN],[")",w.RPAREN],["<",w.LESS],[">",w.GREAT]]);function jf(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function $a(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??Wf}tokenize(){let n=this.input.length,r=this.tokens,s=this.pendingHeredocs;for(;this.pos<n;){if(s.length>0&&r.length>0&&r[r.length-1].type===w.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=n)break;let i=this.nextToken();i&&r.push(i)}return s.length>0&&this.readHeredocContent(),r.push({type:w.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let t=this.input,n=t.length,r=this.pos,s=this.column,i=this.line;for(;r<n;){let o=t[r];if(o===" "||o===" ")r++,s++;else if(o==="\\"&&t[r+1]===`
23
+ `)r+=2,i++,s=1;else break}this.pos=r,this.column=s,this.line=i}nextToken(){let t=this.input,n=this.pos,r=this.line,s=this.column,i=t[n],o=t[n+1],a=t[n+2],l=this.pendingHeredocDelimiterMode;if(this.pendingHeredocDelimiterMode=void 0,l!==void 0&&i!==`
24
+ `&&!(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
+ `)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==="<"&&o==="<"&&a==="-")return this.pos=n+3,this.column=s+3,this.pendingHeredocDelimiterMode=!0,this.makeToken(w.DLESSDASH,"<<-",n,r,s);for(let[c,f,d,p]of zf)if(i===c&&o===f&&a===d)return this.pos=n+3,this.column=s+3,this.makeToken(p,c+f+d,n,r,s);if(i==="<"&&o==="<")return this.pos=n+2,this.column=s+2,this.pendingHeredocDelimiterMode=!1,this.makeToken(w.DLESS,"<<",n,r,s);if(i==="("&&o==="("){let c=this.tokens[this.tokens.length-1];return this.dparenDepth===0&&c?.end===n&&(c.type===w.LESS||c.type===w.GREAT)?(this.pos=n+1,this.column=s+1,this.makeToken(w.LPAREN,"(",n,r,s)):this.dparenDepth>0?(this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(w.LPAREN,"(",n,r,s)):this.looksLikeNestedSubshells(n+2)||this.dparenClosesWithSpacedParens(n+2)?(this.pos=n+1,this.column=s+1,this.makeToken(w.LPAREN,"(",n,r,s)):(this.pos=n+2,this.column=s+2,this.dparenDepth=1,this.makeToken(w.DPAREN_START,"((",n,r,s))}if(i===")"&&o===")")return this.dparenDepth===1?(this.pos=n+2,this.column=s+2,this.dparenDepth=0,this.makeToken(w.DPAREN_END,"))",n,r,s)):this.dparenDepth>1?(this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(w.RPAREN,")",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(w.RPAREN,")",n,r,s));for(let[c,f,d]of qf)if(!(c==="("&&f==="("||c===")"&&f===")")&&!(this.dparenDepth>0&&c===";"&&(d===w.DSEMI||d===w.SEMI_AND||d===w.SEMI_SEMI_AND))&&i===c&&o===f){if(d===w.DBRACK_START||d===w.DBRACK_END){let p=t[n+2];if(p!==void 0&&p!==" "&&p!==" "&&p!==`
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=Uf.get(i);if(u!==void 0)return this.pos=n+1,this.column=s+1,this.makeToken(u,i,n,r,s);if(i==="{"){let c=this.scanFdVariable(n);return c!==null?(this.pos=c.end,this.column=s+(c.end-n),{type:w.FD_VARIABLE,value:c.varname,start:n,end:c.end,line:r,column:s}):o==="}"?(this.pos=n+2,this.column=s+2,{type:w.WORD,value:"{}",start:n,end:n+2,line:r,column:s,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(n)!==null?this.readWordWithBraceExpansion(n,r,s):this.scanLiteralBraceWord(n)!==null?this.readWordWithBraceExpansion(n,r,s):o!==void 0&&o!==" "&&o!==" "&&o!==`
28
+ `?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(w.LBRACE,"{",n,r,s))}return i==="}"?this.isWordCharFollowing(n+1)?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(w.RBRACE,"}",n,r,s)):i==="!"?o==="="?(this.pos=n+2,this.column=s+2,this.makeToken(w.WORD,"!=",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(w.BANG,"!",n,r,s)):this.readWord(n,r,s)}looksLikeNestedSubshells(t){let n=this.input,r=n.length,s=t;for(;s<r&&(n[s]===" "||n[s]===" ");)s++;if(s>=r)return!1;let i=n[s];if(i==="(")return this.looksLikeNestedSubshells(s+1);let o=/[a-zA-Z_]/.test(i),a=i==="!"||i==="[";if(!o&&!a)return!1;let l=s;for(;l<r&&/[a-zA-Z0-9_\-.]/.test(n[l]);)l++;if(l===s)return a;let u=l;for(;u<r&&(n[u]===" "||n[u]===" ");)u++;if(u>=r)return!1;let c=n[u];if(c==="="&&n[u+1]!=="="||c===`
29
+ `||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
+ `;){if(n[f]===")")return!0;f++}return!1}if(c===")"){let f=u+1;for(;f<r&&(n[f]===" "||n[f]===" ");)f++;if(n[f]==="|"&&n[f+1]==="|"||n[f]==="&"&&n[f+1]==="&"||n[f]===";"||n[f]==="|"&&n[f+1]!=="|")return!0}return!1}makeToken(t,n,r,s,i){return{type:t,value:n,start:r,end:this.pos,line:s,column:i}}readComment(t,n,r){let s=this.input,i=s.length,o=this.pos;for(;o<i&&s[o]!==`
31
+ `;)o++;let a=s.slice(t,o);return this.pos=o,this.column=r+(o-t),{type:w.COMMENT,value:a,start:t,end:o,line:n,column:r}}readWord(t,n,r){let s=this.input,i=s.length,o=this.pos,a=o;for(;o<i;){let y=s[o];if(y===" "||y===" "||y===`
32
+ `||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"||y==="'"||y==='"'||y==="\\"||y==="$"||y==="`"||y==="{"||y==="}"||y==="~"||y==="*"||y==="?"||y==="[")break;o++}if(o>a){let y=s[o];if(!(y==="("&&o>a&&"@*+?!".includes(s[o-1]))){if(o>=i||y===" "||y===" "||y===`
33
+ `||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"){let S=s.slice(a,o);this.pos=o,this.column=r+(o-a);let v=Us.get(S);if(v!==void 0)return{type:v,value:S,start:t,end:o,line:n,column:r};let x=xa(S);return x>0&&va(S.slice(0,x))?{type:w.ASSIGNMENT_WORD,value:S,start:t,end:o,line:n,column:r}:/^[0-9]+$/.test(S)?{type:w.NUMBER,value:S,start:t,end:o,line:n,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(S)?{type:w.NAME,value:S,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}:{type:w.WORD,value:S,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}}}}o=this.pos;let l=this.column,u=this.line,c="",f=!1,d=!1,p=!1,h=!1,m=s[o]==='"'||s[o]==="'",E=!1,b=0;for(;o<i;){let y=s[o];if(!p&&!h){if(y==="("&&c.length>0&&"@*+?!".includes(c[c.length-1])){let S=this.scanExtglobPattern(o);if(S!==null){c+=S.content,o=S.end,l+=S.content.length;continue}}if(y==="["&&b===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){let S=o+1<i?s[o+1]:"";if(S==="^"||S==="!"){c+=y,o++,l++;continue}b=1,c+=y,o++,l++;continue}}else if(y==="["&&b>0){c.length>0&&c[c.length-1]!=="\\"&&b++,c+=y,o++,l++;continue}else if(y==="]"&&b>0){c.length>0&&c[c.length-1]!=="\\"&&b--,c+=y,o++,l++;continue}if(b>0){if(y===`
34
+ `)break;c+=y,o++,l++;continue}if(y===" "||y===" "||y===`
35
+ `||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">")break}if(y==="$"&&o+1<i&&s[o+1]==="'"&&!p&&!h){for(c+="$'",o+=2,l+=2;o<i&&s[o]!=="'";)s[o]==="\\"&&o+1<i?(c+=s[o]+s[o+1],o+=2,l+=2):(c+=s[o],o++,l++);o<i&&(c+="'",o++,l++);continue}if(y==="$"&&o+1<i&&s[o+1]==='"'&&!p&&!h){o++,l++,h=!0,f=!0,c===""&&(m=!0),o++,l++;continue}if(y==="'"&&!h){if(p)if(p=!1,!m||E)c+=y;else{let S=o+1<i?s[o+1]:"";S&&!$a(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;o++,l++;continue}if(y==='"'&&!p){if(h)if(h=!1,!m||E)c+=y;else{let S=o+1<i?s[o+1]:"";S&&!$a(S)&&S!=='"'&&(S==="'"?(E=!0,c+=y,d=!1,f=!1):(E=!0,c+=y))}else h=!0,m&&!E?f=!0:c+=y;o++,l++;continue}if(y==="\\"&&!p&&o+1<i){let S=s[o+1];if(S===`
36
+ `){o+=2,u++,l=1;continue}if(h){if(S==='"'||S==="\\"||S==="$"||S==="`"||S===`
33
37
  `){if(S===`
34
- `){a+=2,l=1,c++;continue}u+=w+S,a+=2,l+=2;continue}}else{S==="\\"||S==='"'||S==="'"||S==="`"||S==="*"||S==="?"||S==="["||S==="]"||S==="("||S===")"||S==="$"||S==="-"||S==="."||S==="^"||S==="+"||S==="{"||S==="}"?u+=w+S:u+=S,a+=2,l+=2;continue}}if(w==="$"&&a+1<i&&s[a+1]==="("&&!p){u+=w,a++,l++,u+=s[a],a++,l++;let S=1,v=!1,A=!1,x=0,P=!1,D="",I=[],O=s[a]==="("&&!this.dollarDparenIsSubshell(a),B=O?1:0;for(;S>0&&a<i;){let Y=s[a];if(u+=Y,v)Y==="'"&&(v=!1);else if(A)Y==="\\"&&a+1<i?(u+=s[a+1],a++,l++):Y==='"'&&(A=!1);else{if(Y==="("&&s[a+1]==="("?B++:Y===")"&&s[a+1]===")"&&B>0&&B--,B===0&&Y==="<"&&s[a+1]==="<"&&s[a+2]!=="<"){let J=a+2,C=!1;for(s[J]==="-"&&(C=!0,J++);s[J]===" "||s[J]===" ";)J++;let{delim:k,endPos:N}=xs(s,J);if(k.length>0){u+=s.slice(a+1,N),l+=N-a,I.push({delim:k,stripTabs:C}),a=N;continue}}if(Y===`
35
- `&&I.length>0){c++,l=0;let J=a+1;for(let{delim:C,stripTabs:k}of I)for(;!(J>=i);){let N=s.indexOf(`
36
- `,J);N===-1&&(N=i);let M=s.slice(J,N),G=k?M.replace(/^\t+/,""):M;u+=s.slice(J,Math.min(N+1,i)),N<i&&c++;let q=N>=i;if(J=N+1,G===C||q)break}I.length=0,l=0,a=Math.min(J,i);continue}if(Y==="'")v=!0,D="";else if(Y==='"')A=!0,D="";else if(Y==="\\"&&a+1<i)u+=s[a+1],a++,l++,D="";else if(Y==="$"&&a+1<i&&s[a+1]==="{"){a++,l++,u+=s[a],a++,l++;let J=1,C=!1,k=!1;for(;J>0&&a<i;){let N=s[a];if(N==="\\"&&a+1<i&&!C){u+=N,a++,l++,u+=s[a],a++,l++;continue}u+=N,C?N==="'"&&(C=!1):k?N==='"'&&(k=!1):N==="'"?C=!0:N==='"'?k=!0:N==="{"?J++:N==="}"&&J--,N===`
37
- `?(c++,l=0):l++,a++}D="";continue}else if(Y==="#"&&!O&&(D===""||/\s/.test(s[a-1]||""))){for(;a+1<i&&s[a+1]!==`
38
- `;)a++,l++,u+=s[a];D=""}else/[a-zA-Z_]/.test(Y)?D+=Y:(D==="case"?(x++,P=!1):D==="in"&&x>0?P=!0:D==="esac"&&x>0&&(x--,P=!1),D="",Y==="("?a>0&&s[a-1]==="$"?S++:P||S++:Y===")"?P?P=!1:S--:Y===";"&&x>0&&(a+1<i&&s[a+1]===";"||a+1<i&&s[a+1]==="&")&&(P=!0))}Y===`
39
- `&&(c++,l=0,D=""),a++,l++}continue}if(w==="$"&&a+1<i&&s[a+1]==="["&&!p){u+=w,a++,l++,u+=s[a],a++,l++;let S=1;for(;S>0&&a<i;){let v=s[a];u+=v,v==="["?S++:v==="]"?S--:v===`
40
- `&&(c++,l=0),a++,l++}continue}if(w==="$"&&a+1<i&&s[a+1]==="{"&&!p){u+=w,a++,l++,u+=s[a],a++,l++;let S=1,v=!1,A=!1,x=c,P=l,D=c,I=l;for(;S>0&&a<i;){let O=s[a];if(O==="\\"&&a+1<i&&s[a+1]===`
41
- `){a+=2,c++,l=1;continue}if(O==="\\"&&a+1<i&&!v){u+=O,a++,l++,u+=s[a],a++,l++;continue}u+=O,v?O==="'"&&(v=!1):A?O==='"'&&(A=!1):O==="'"?(v=!0,x=c,P=l):O==='"'?(A=!0,D=c,I=l):O==="{"?S++:O==="}"&&S--,O===`
42
- `&&(c++,l=0),a++,l++}if(v)throw new Pt("unexpected EOF while looking for matching `''",x,P);if(A)throw new Pt("unexpected EOF while looking for matching `\"'",D,I);continue}if(w==="$"&&a+1<i&&!p){let S=s[a+1];if(S==="#"||S==="?"||S==="$"||S==="!"||S==="@"||S==="*"||S==="-"||S>="0"&&S<="9"){u+=w+S,a+=2,l+=2;continue}}if(w==="`"&&!p){for(u+=w,a++,l++;a<i&&s[a]!=="`";){let S=s[a];u+=S,S==="\\"&&a+1<i&&(u+=s[a+1],a++,l++),S===`
43
- `&&(c++,l=0),a++,l++}a<i&&(u+=s[a],a++,l++);continue}u+=w,a++,w===`
44
- `?(c++,l=1):l++}if(this.pos=a,this.column=l,this.line=c,E&&m&&(u=s[t]+u,f=!1,d=!1),p||h){let w=p?"'":'"';throw new Pt(`unexpected EOF while looking for matching \`${w}'`,n,r)}if(!m&&u.length>=2){if(u[0]==="'"&&u[u.length-1]==="'"){let w=u.slice(1,-1);!w.includes("'")&&!w.includes('"')&&(u=w,f=!0,d=!0)}else if(u[0]==='"'&&u[u.length-1]==='"'){let w=u.slice(1,-1),S=!1;for(let v=0;v<w.length;v++){if(w[v]==='"'){S=!0;break}w[v]==="\\"&&v+1<w.length&&v++}S||(u=w,f=!0,d=!1)}}if(u==="")return{type:y.WORD,value:"",start:t,end:a,line:n,column:r,quoted:f,singleQuoted:d};let g=Wa.get(u);if(!f&&g!==void 0)return{type:g,value:u,start:t,end:a,line:n,column:r};if(!m){let w=Va(u);if(w>0&&Fa(u.slice(0,w)))return{type:y.ASSIGNMENT_WORD,value:u,start:t,end:a,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(u)?{type:y.NUMBER,value:u,start:t,end:a,line:n,column:r}:Zu(u)?{type:y.NAME,value:u,start:t,end:a,line:n,column:r,quoted:f,singleQuoted:d}:{type:y.WORD,value:u,start:t,end:a,line:n,column:r,quoted:f,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let n=this.pos,r=this.line,s=this.column,i="";for(;this.pos<this.input.length;){let a="";for(;this.pos<this.input.length&&this.input[this.pos]!==`
45
- `;)a+=this.input[this.pos],this.pos++,this.column++;if((t.stripTabs?a.replace(/^\t+/,""):a)===t.delimiter){this.pos<this.input.length&&this.input[this.pos]===`
46
- `&&(this.pos++,this.line++,this.column=1);break}if(i+=a,i.length>this.maxHeredocSize)throw new Pt(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,s);this.pos<this.input.length&&this.input[this.pos]===`
47
- `&&(i+=`
48
- `,this.pos++,this.line++,this.column=1)}this.tokens.push({type:y.HEREDOC_CONTENT,value:i,start:n,end:this.pos,line:r,column:s})}}addPendingHeredoc(t,n,r){this.pendingHeredocs.push({delimiter:t,stripTabs:n,quoted:r})}registerHeredocFromLookahead(t){let n=this.pos,r=this.column;for(;this.pos<this.input.length&&(this.input[this.pos]===" "||this.input[this.pos]===" ");)this.pos++,this.column++;let s="",i=!1;for(;this.pos<this.input.length;){let a=this.input[this.pos];if(/[\s;<>&|()]/.test(a))break;if(a==="'"||a==='"'){i=!0;let o=a;for(this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]!==o;)s+=this.input[this.pos],this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]===o&&(this.pos++,this.column++)}else a==="\\"?(i=!0,this.pos++,this.column++,this.pos<this.input.length&&(s+=this.input[this.pos],this.pos++,this.column++)):(s+=a,this.pos++,this.column++)}this.pos=n,this.column=r,s&&this.pendingHeredocs.push({delimiter:s,stripTabs:t,quoted:i})}isWordCharFollowing(t){if(t>=this.input.length)return!1;let n=this.input[t];return!(n===" "||n===" "||n===`
49
- `||n===";"||n==="&"||n==="|"||n==="("||n===")"||n==="<"||n===">")}readWordWithBraceExpansion(t,n,r){let s=this.input,i=s.length,a=t,o=r;for(;a<i;){let c=s[a];if(c===" "||c===" "||c===`
50
- `||c===";"||c==="&"||c==="|"||c==="("||c===")"||c==="<"||c===">")break;if(c==="{"){if(this.scanBraceExpansion(a)!==null){let f=1;for(a++,o++;a<i&&f>0;)s[a]==="{"?f++:s[a]==="}"&&f--,a++,o++;continue}a++,o++;continue}if(c==="}"){a++,o++;continue}if(c==="$"&&a+1<i&&s[a+1]==="("){a++,o++,a++,o++;let u=1;for(;u>0&&a<i;)s[a]==="("?u++:s[a]===")"&&u--,a++,o++;continue}if(c==="$"&&a+1<i&&s[a+1]==="{"){a++,o++,a++,o++;let u=1;for(;u>0&&a<i;)s[a]==="{"?u++:s[a]==="}"&&u--,a++,o++;continue}if(c==="`"){for(a++,o++;a<i&&s[a]!=="`";)s[a]==="\\"&&a+1<i?(a+=2,o+=2):(a++,o++);a<i&&(a++,o++);continue}a++,o++}let l=s.slice(t,a);return this.pos=a,this.column=o,{type:y.WORD,value:l,start:t,end:a,line:n,column:r,quoted:!1,singleQuoted:!1}}scanBraceExpansion(t){let n=this.input,r=n.length,s=t+1,i=1,a=!1,o=!1;for(;s<r&&i>0;){let l=n[s];if(l==="{")i++,s++;else if(l==="}")i--,s++;else if(l===","&&i===1)a=!0,s++;else if(l==="."&&s+1<r&&n[s+1]===".")o=!0,s+=2;else{if(l===" "||l===" "||l===`
51
- `||l===";"||l==="&"||l==="|")return null;s++}}return i===0&&(a||o)?n.slice(t,s):null}scanLiteralBraceWord(t){let n=this.input,r=n.length,s=t+1,i=1;for(;s<r&&i>0;){let a=n[s];if(a==="{")i++,s++;else if(a==="}"){if(i--,i===0)return n.slice(t,s+1);s++}else{if(a===" "||a===" "||a===`
52
- `||a===";"||a==="&"||a==="|")return null;s++}}return null}scanExtglobPattern(t){let n=this.input,r=n.length,s=t+1,i=1;for(;s<r&&i>0;){let a=n[s];if(a==="\\"&&s+1<r){s+=2;continue}if("@*+?!".includes(a)&&s+1<r&&n[s+1]==="("){s++,i++,s++;continue}if(a==="(")i++,s++;else if(a===")")i--,s++;else{if(a===`
53
- `)return null;s++}}return i===0?{content:n.slice(t,s),end:s}:null}scanFdVariable(t){let n=this.input,r=n.length,s=t+1,i=s;for(;s<r;){let u=n[s];if(s===i){if(!(u>="a"&&u<="z"||u>="A"&&u<="Z"||u==="_"))return null}else if(!(u>="a"&&u<="z"||u>="A"&&u<="Z"||u>="0"&&u<="9"||u==="_"))break;s++}if(s===i)return null;let a=n.slice(i,s);if(s>=r||n[s]!=="}"||(s++,s>=r))return null;let o=n[s],l=s+1<r?n[s+1]:"";return o===">"||o==="<"||o==="&"&&(l===">"||l==="<")?{varname:a,end:s}:null}dollarDparenIsSubshell(t){let n=this.input,r=n.length,s=t+1,i=2,a=!1,o=!1,l=!1;for(;s<r&&i>0;){let c=n[s];if(a){c==="'"&&(a=!1),c===`
54
- `&&(l=!0),s++;continue}if(o){if(c==="\\"){s+=2;continue}c==='"'&&(o=!1),c===`
55
- `&&(l=!0),s++;continue}if(c==="'"){a=!0,s++;continue}if(c==='"'){o=!0,s++;continue}if(c==="\\"){s+=2;continue}if(c===`
56
- `&&(l=!0),c==="("){i++,s++;continue}if(c===")"){if(i--,i===1){let u=s+1;if(u<r&&n[u]===")")return!1;let f=u,d=!1;for(;f<r&&(n[f]===" "||n[f]===" "||n[f]===`
57
- `);)d=!0,f++;if(d&&f<r&&n[f]===")"||l)return!0}if(i===0)return!1;s++;continue}s++}return!1}dparenClosesWithSpacedParens(t){let n=this.input,r=n.length,s=t,i=2,a=!1,o=!1;for(;s<r&&i>0;){let l=n[s];if(a){l==="'"&&(a=!1),s++;continue}if(o){if(l==="\\"){s+=2;continue}l==='"'&&(o=!1),s++;continue}if(l==="'"){a=!0,s++;continue}if(l==='"'){o=!0,s++;continue}if(l==="\\"){s+=2;continue}if(l==="("){i++,s++;continue}if(l===")"){if(i--,i===1){let c=s+1;if(c<r&&n[c]===")")return!1;let u=c,f=!1;for(;u<r&&(n[u]===" "||n[u]===" "||n[u]===`
58
- `);)f=!0,u++;if(f&&u<r&&n[u]===")")return!0}if(i===0)return!1;s++;continue}if(i===1&&(l==="|"&&s+1<r&&n[s+1]==="|"||l==="&"&&s+1<r&&n[s+1]==="&"||l==="|"&&s+1<r&&n[s+1]!=="|"))return!0;s++}return!1}};var $s=1e6,In=1e5,Hu=1e6,qa=200,Ua=new Set([y.LESS,y.GREAT,y.DLESS,y.DGREAT,y.LESSAND,y.GREATAND,y.LESSGREAT,y.DLESSDASH,y.CLOBBER,y.TLESS,y.AND_GREAT,y.AND_DGREAT]),ja=new Set([y.LESS,y.GREAT,y.DLESS,y.DGREAT,y.LESSAND,y.GREATAND,y.LESSGREAT,y.DLESSDASH,y.CLOBBER,y.TLESS]),Ga=new Set([y.LESS,y.GREAT,y.DLESS,y.DGREAT,y.LESSAND,y.GREATAND,y.LESSGREAT,y.DLESSDASH,y.CLOBBER,y.TLESS,y.AND_GREAT,y.AND_DGREAT]),Ae=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"}},fr=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>Hu)throw new Ae("Maximum parse iterations exceeded (possible infinite loop)",t,n)}chargeTokens(t,n=1,r=1){if(this.tokens+=t,this.tokens>In)throw new Ae(`Too many tokens: cumulative count exceeds limit of ${In}`,n,r)}enter(t,n){if(this.depth++,this.depth>qa)throw this.depth--,new Ae(`Maximum parser nesting depth exceeded (${qa})`,t,n);let r=!0;return()=>{r&&(r=!1,this.depth--)}}};function de(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
59
- `){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var dr=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function _n(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 Za(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 Ha(e,t){if(e.slice(t,t+2)!=="$'")return null;let n=t+2,r="";for(;n<e.length&&e[n]!=="'";)if(e[n]==="\\"&&n+1<e.length){let i=e[n+1];switch(i){case"n":r+=`
60
- `;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 Qa(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 Qu(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 ne(e,t){let n=Qu(t),{expr:r,pos:s}=pn(e,n,0),i=de(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 Be(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function We(e,t){return de(e,t)>=e.length}function pn(e,t,n){return Ku(e,t,n)}function Zt(e,t,n){return e.withDepth(()=>pn(e,t,n))}function Ku(e,t,n){let{expr:r,pos:s}=On(e,t,n);for(s=de(t,s);t[s]===",";){if(s++,We(t,s))return Be(",",s);let{expr:a,pos:o}=On(e,t,s);r={type:"ArithBinary",operator:",",left:r,right:a},s=de(t,o)}return{expr:r,pos:s}}function On(e,t,n){let{expr:r,pos:s}=Xu(e,t,n);if(s=de(t,s),t[s]==="?"){s++;let{expr:i,pos:a}=Zt(e,t,s);if(s=de(t,a),t[s]===":"){s++;let{expr:o,pos:l}=Zt(e,t,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:o},pos:l}}}return{expr:r,pos:s}}function Xu(e,t,n){let{expr:r,pos:s}=Ka(e,t,n);for(;s=de(t,s),t.slice(s,s+2)==="||";){if(s+=2,We(t,s))return Be("||",s);let{expr:a,pos:o}=Ka(e,t,s);r={type:"ArithBinary",operator:"||",left:r,right:a},s=o}return{expr:r,pos:s}}function Ka(e,t,n){let{expr:r,pos:s}=Xa(e,t,n);for(;s=de(t,s),t.slice(s,s+2)==="&&";){if(s+=2,We(t,s))return Be("&&",s);let{expr:a,pos:o}=Xa(e,t,s);r={type:"ArithBinary",operator:"&&",left:r,right:a},s=o}return{expr:r,pos:s}}function Xa(e,t,n){let{expr:r,pos:s}=Ya(e,t,n);for(;s=de(t,s),t[s]==="|"&&t[s+1]!=="|";){if(s++,We(t,s))return Be("|",s);let{expr:a,pos:o}=Ya(e,t,s);r={type:"ArithBinary",operator:"|",left:r,right:a},s=o}return{expr:r,pos:s}}function Ya(e,t,n){let{expr:r,pos:s}=Ja(e,t,n);for(;s=de(t,s),t[s]==="^";){if(s++,We(t,s))return Be("^",s);let{expr:a,pos:o}=Ja(e,t,s);r={type:"ArithBinary",operator:"^",left:r,right:a},s=o}return{expr:r,pos:s}}function Ja(e,t,n){let{expr:r,pos:s}=eo(e,t,n);for(;s=de(t,s),t[s]==="&"&&t[s+1]!=="&";){if(s++,We(t,s))return Be("&",s);let{expr:a,pos:o}=eo(e,t,s);r={type:"ArithBinary",operator:"&",left:r,right:a},s=o}return{expr:r,pos:s}}function eo(e,t,n){let{expr:r,pos:s}=to(e,t,n);for(;s=de(t,s),t.slice(s,s+2)==="=="||t.slice(s,s+2)==="!=";){let i=t.slice(s,s+2);if(s+=2,We(t,s))return Be(i,s);let{expr:a,pos:o}=to(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}return{expr:r,pos:s}}function to(e,t,n){let{expr:r,pos:s}=ks(e,t,n);for(;;)if(s=de(t,s),t.slice(s,s+2)==="<="||t.slice(s,s+2)===">="){let i=t.slice(s,s+2);if(s+=2,We(t,s))return Be(i,s);let{expr:a,pos:o}=ks(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++,We(t,s))return Be(i,s);let{expr:a,pos:o}=ks(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}else break;return{expr:r,pos:s}}function ks(e,t,n){let{expr:r,pos:s}=no(e,t,n);for(;s=de(t,s),t.slice(s,s+2)==="<<"||t.slice(s,s+2)===">>";){let i=t.slice(s,s+2);if(s+=2,We(t,s))return Be(i,s);let{expr:a,pos:o}=no(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}return{expr:r,pos:s}}function no(e,t,n){let{expr:r,pos:s}=ro(e,t,n);for(;s=de(t,s),(t[s]==="+"||t[s]==="-")&&t[s+1]!==t[s];){let i=t[s];if(s++,We(t,s))return Be(i,s);let{expr:a,pos:o}=ro(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}return{expr:r,pos:s}}function ro(e,t,n){let{expr:r,pos:s}=pr(e,t,n);for(;;)if(s=de(t,s),t[s]==="*"&&t[s+1]!=="*"){if(s++,We(t,s))return Be("*",s);let{expr:a,pos:o}=pr(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++,We(t,s))return Be(i,s);let{expr:a,pos:o}=pr(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:a},s=o}else break;return{expr:r,pos:s}}function pr(e,t,n){let{expr:r,pos:s}=Ns(e,t,n),i=de(t,s);if(t.slice(i,i+2)==="**"){if(i+=2,We(t,i))return Be("**",i);let{expr:o,pos:l}=e.withDepth(()=>pr(e,t,i));return{expr:{type:"ArithBinary",operator:"**",left:r,right:o},pos:l}}return{expr:r,pos:s}}function Ns(e,t,n){let r=de(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(()=>Ns(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(()=>Ns(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:a}}return Ju(e,t,r)}function Yu(e,t){let n=e[t];return n==="$"||n==="`"}function Ju(e,t,n){let{expr:r,pos:s}=so(e,t,n,!1),i=[r];for(;Yu(t,s);){let{expr:o,pos:l}=so(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}=Zt(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=de(t,s),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let o of dr)if(t.slice(s,s+o.length)===o&&t.slice(s,s+o.length+1)!=="=="){s+=o.length;let{expr:l,pos:c}=e.withDepth(()=>On(e,t,s));return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:o,target:r.nameExpr,subscript:r.subscript,value:l},pos:c}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:o,target:r,value:l},pos:c}:{expr:{type:"ArithAssignment",operator:o,variable:r.name,value:l},pos:c}}}if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let o=t.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:o,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function so(e,t,n,r=!1){let s=de(t,n),i=Za(Zt,e,t,s);if(i)return i;let a=Ha(t,s);if(a)return a;let o=Qa(t,s);if(o)return o;if(t.slice(s,s+2)==="$("&&t[s+2]!=="("){s+=2;let c=1,u=s;for(;s<t.length&&c>0;)t[s]==="("?c++:t[s]===")"&&c--,c>0&&s++;let f=t.slice(u,s);return s++,{expr:{type:"ArithCommandSubst",command:f},pos:s}}if(t[s]==="`"){s++;let c=s;for(;s<t.length&&t[s]!=="`";)s++;let u=t.slice(c,s);return t[s]==="`"&&s++,{expr:{type:"ArithCommandSubst",command:u},pos:s}}if(t[s]==="("){s++;let{expr:c,pos:u}=Zt(e,t,s);return s=de(t,u),t[s]===")"&&s++,{expr:{type:"ArithGroup",expression:c},pos:s}}if(t[s]==="'"){s++;let c="";for(;s<t.length&&t[s]!=="'";)c+=t[s],s++;t[s]==="'"&&s++;let u=Number.parseInt(c,10);return{expr:{type:"ArithSingleQuote",content:c,value:Number.isNaN(u)?0:u},pos:s}}if(t[s]==='"'){s++;let c="";for(;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?(c+=t[s+1],s+=2):(c+=t[s],s++);t[s]==='"'&&s++;let u=c.trim();if(!u)return{expr:{type:"ArithNumber",value:0},pos:s};let{expr:f}=Zt(e,u,0);return{expr:f,pos:s}}if(/[0-9]/.test(t[s])){let c="",u=!1,f=!1;for(;s<t.length;){let p=t[s];if(u)if(/[0-9a-zA-Z@_]/.test(p))c+=p,s++;else break;else if(p==="#")u=!0,c+=p,s++;else if(c==="0"&&(p==="x"||p==="X")&&s+1<t.length&&/[0-9a-fA-F]/.test(t[s+1]))f=!0,c+=p,s++;else if(f&&/[0-9a-fA-F]/.test(p))c+=p,s++;else if(!f&&/[0-9]/.test(p))c+=p,s++;else break}if(s<t.length&&/[a-zA-Z_]/.test(t[s])){let p=c;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 ie(`${c}.${t[s+1]}...: syntax error: invalid arithmetic operator`);if(t[s]==="["){let p=t.slice(s).trim();return{expr:{type:"ArithNumberSubscript",number:c,errorToken:p},pos:t.length}}return{expr:{type:"ArithNumber",value:_n(c)},pos:s}}if(t[s]==="$"&&t[s+1]==="{"){let c=s+2,u=1,f=c;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;let d=t.slice(c,f),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 c="";for(;s<t.length&&/[0-9]/.test(t[s]);)c+=t[s],s++;return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:!0},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[*@#?\-!$]/.test(t[s+1])){let c=t[s+1];return s+=2,{expr:{type:"ArithSpecialVar",name:c},pos:s}}let l=!1;if(t[s]==="$"&&s+1<t.length&&/[a-zA-Z_]/.test(t[s+1])&&(l=!0,s++),s<t.length&&/[a-zA-Z_]/.test(t[s])){let c="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)c+=t[s],s++;if(t[s]==="["&&!r){s++;let u;if(t[s]==="'"||t[s]==='"'){let d=t[s];for(s++,u="";s<t.length&&t[s]!==d;)u+=t[s],s++;t[s]===d&&s++,s=de(t,s),t[s]==="]"&&s++}let f;if(u===void 0){let{expr:d,pos:p}=Zt(e,t,s);f=d,s=p,t[s]==="]"&&s++}if(s=de(t,s),t[s]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:c,index:f},pos:s};if(!r){for(let d of dr)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(()=>On(e,t,s));return{expr:{type:"ArithAssignment",operator:d,variable:c,subscript:f,stringKey:u,value:p},pos:h}}}return{expr:{type:"ArithArrayElement",array:c,index:f,stringKey:u},pos:s}}if(s=de(t,s),!r){for(let u of dr)if(t.slice(s,s+u.length)===u&&t.slice(s,s+u.length+1)!=="=="){s+=u.length;let{expr:f,pos:d}=e.withDepth(()=>On(e,t,s));return{expr:{type:"ArithAssignment",operator:u,variable:c,value:f},pos:d}}}return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:l},pos:s}}if(t[s]==="#"){let c=s+1;for(;c<t.length&&t[c]!==`
61
- `;)c++;let u=t.slice(s,c).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:u,message:`${u}: syntax error: invalid arithmetic operator (error token is "${u}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:s}}function ef(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 oo(e,t,n){let r=n+1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;return r}function Ps(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 Ht(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 lo(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 co(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=tf(t,r);a===-1?(s+=i,r++):(s+=t.slice(r,a+1),r=a+1)}else break}return{pattern:s,endIndex:r}}function tf(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 uo(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+=`
62
- `,s+=2;break;case"t":r+=" ",s+=2;break;case"r":r+="\r",s+=2;break;case"\\":r+="\\",s+=2;break;case"'":r+="'",s+=2;break;case'"':r+='"',s+=2;break;case"a":r+="\x07",s+=2;break;case"b":r+="\b",s+=2;break;case"e":case"E":r+="\x1B",s+=2;break;case"f":r+="\f",s+=2;break;case"v":r+="\v",s+=2;break;case"x":{let o=[],l=s;for(;l+1<t.length&&t[l]==="\\"&&t[l+1]==="x";){let c=t.slice(l+2,l+4),u=parseInt(c,16);if(!Number.isNaN(u)&&c.length>0)o.push(u),l+=2+c.length;else break}o.length>0?(r+=ef(o),s=l):(r+="\\x",s+=2);break}case"u":{let o=t.slice(s+2,s+6),l=parseInt(o,16);Number.isNaN(l)?(r+="\\u",s+=2):(r+=String.fromCharCode(l),s+=6);break}case"c":{if(s+2<t.length){let l=t[s+2].charCodeAt(0)&31;r+=String.fromCharCode(l),s+=3}else r+="\\c",s+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let o="",l=s+1;for(;l<t.length&&l<s+4&&/[0-7]/.test(t[l]);)o+=t[l],l++;let c=parseInt(o,8);r+=String.fromCharCode(c),s=l;break}default:r+=i,s++}else r+=i,s++}return s<t.length&&t[s]==="'"&&s++,{part:L.literal(r),endIndex:s}}function Cs(e,t){let n=t.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:ne(e,n)}function ao(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 fo(e,t,n,r){let s=Ps(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:ao(i).map(u=>e.withDepth(()=>({type:"Word",word:L.word(r(e,u,!1,!1,!1))})))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:ao(i).map(u=>({type:"Word",word:L.word([L.literal(u)])}))},endIndex:s+1}:null}function Ds(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(Ds(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 po(e,t){return{[y.LESS]:"<",[y.GREAT]:">",[y.DGREAT]:">>",[y.LESSAND]:"<&",[y.GREATAND]:">&",[y.LESSGREAT]:"<>",[y.CLOBBER]:">|",[y.TLESS]:"<<<",[y.AND_GREAT]:"&>",[y.AND_DGREAT]:"&>>",[y.DLESS]:"<",[y.DLESSDASH]:"<"}[t]||">"}function hr(e){let t=e.current(),n=t.type;if(n===y.NUMBER){let r=e.peek(1);return t.end!==r.start?!1:ja.has(r.type)}if(n===y.FD_VARIABLE){let r=e.peek(1);return Ga.has(r.type)}return Ua.has(n)}function mr(e){let t=null,n;e.check(y.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(y.FD_VARIABLE)&&(n=e.advance().value);let r=e.advance(),s=po(e,r.type);if(r.type===y.DLESS||r.type===y.DLESSDASH)return nf(e,s,t,r.type===y.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return L.redirection(s,i,t,n)}function nf(e,t,n,r){e.isWord()||e.error("Expected here-document delimiter");let s=e.advance(),i=s.value,a=s.quoted||!1;(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1));let o=L.redirection(r?"<<-":"<<",L.hereDoc(i,L.word([]),r,a),n);return e.addPendingHeredoc(o,i,r,a),o}function mo(e){let t=e.current().line,n=[],r=null,s=[],i=[];for(;e.check(y.ASSIGNMENT_WORD)||hr(e);)e.checkIterationLimit(),e.check(y.ASSIGNMENT_WORD)?n.push(rf(e)):i.push(mr(e));if(e.isWord())r=e.parseWord();else if(n.length>0&&(e.check(y.DBRACK_START)||e.check(y.DPAREN_START))){let o=e.advance();r=L.word([L.literal(o.value)])}for(;(!e.isStatementEnd()||e.check(y.RBRACE))&&!e.check(y.PIPE,y.PIPE_AMP);)if(e.checkIterationLimit(),hr(e))i.push(mr(e));else if(e.check(y.RBRACE)){let o=e.advance();s.push(e.parseWordFromString(o.value,!1,!1))}else if(e.check(y.LBRACE)){let o=e.advance();s.push(e.parseWordFromString(o.value,!1,!1))}else if(e.check(y.DBRACK_END)){let o=e.advance();s.push(e.parseWordFromString(o.value,!1,!1))}else if(e.isWord())s.push(e.parseWord());else if(e.check(y.ASSIGNMENT_WORD)){let o=e.advance(),l=o.value,c=l.endsWith("="),u=l.endsWith("=(");if((c||u)&&(u||e.check(y.LPAREN))){let f=u?l.slice(0,-2):l.slice(0,-1);u||e.expect(y.LPAREN);let d=Rs(e);e.expect(y.RPAREN);let p=d.map(m=>Ds(e,m)),h=`${f}=(${p.join(" ")})`;s.push(e.parseWordFromString(h,!1,!1,!0))}else s.push(e.parseWordFromString(l,o.quoted,o.singleQuoted,!0))}else if(e.check(y.LPAREN))e.error("syntax error near unexpected token `('");else break;let a=L.simpleCommand(r,s,n,i);return a.line=t,a}function rf(e){let t=e.expect(y.ASSIGNMENT_WORD),n=t.value,r=n.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||e.error(`Invalid assignment: ${n}`);let s=r[0],i,a=s.length;if(n[a]==="["){let f=0,d=a+1;for(;a<n.length;a++)if(n[a]==="[")f++;else if(n[a]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${n}`),i=n.slice(d,a),a++}let o=n[a]==="+";o&&a++,n[a]!=="="&&e.error(`Invalid assignment: ${n}`),a++;let l=n.slice(a);if(l==="("){let f=Rs(e);e.expect(y.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return L.assignment(d,null,o,f)}if(l===""&&e.check(y.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=Rs(e);e.expect(y.RPAREN);let p=i!==void 0?`${s}[${i}]`:s;return L.assignment(p,null,o,d)}}let c=l?e.parseWordFromString(l,t.quoted,t.singleQuoted,!0):null,u=i!==void 0?`${s}[${i}]`:s;return L.assignment(u,c,o,null)}var sf=new Set([y.AMP,y.PIPE,y.PIPE_AMP,y.SEMICOLON,y.AND_AND,y.OR_OR,y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND]);function Rs(e){let t=[];for(e.skipNewlines();!e.check(y.RPAREN,y.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):sf.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function Is(e,t){e.expect(y.IF);let n=[],r=e.parseCompoundList();e.expect(y.THEN);let s=e.parseCompoundList();if(s.length===0){let o=e.check(y.FI)?"fi":e.check(y.ELSE)?"else":e.check(y.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${o}'`)}for(n.push({condition:r,body:s});e.check(y.ELIF);){e.advance();let o=e.parseCompoundList();e.expect(y.THEN);let l=e.parseCompoundList();if(l.length===0){let c=e.check(y.FI)?"fi":e.check(y.ELSE)?"else":e.check(y.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${c}'`)}n.push({condition:o,body:l})}let i=null;e.check(y.ELSE)&&(e.advance(),i=e.parseCompoundList(),i.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(y.FI);let a=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.ifNode(n,i,a)}function _s(e,t){let n=e.expect(y.FOR);if(e.check(y.DPAREN_START))return of(e,t,n.line);e.isWord()||e.error("Expected variable name in for loop");let s=e.advance().value,i=null;if(e.skipNewlines(),e.check(y.IN))for(e.advance(),i=[];!e.check(y.SEMICOLON,y.NEWLINE,y.DO,y.EOF)&&e.isWord();)i.push(e.parseWord());e.check(y.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(y.DO);let a=e.parseCompoundList();e.expect(y.DONE);let o=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.forNode(s,i,a,o)}function of(e,t,n){e.expect(y.DPAREN_START);let r=null,s=null,i=null,a=["","",""],o=0,l=0;for(;!e.check(y.DPAREN_END,y.EOF);){let f=e.advance();if(f.type===y.SEMICOLON&&l===0){if(o++,o>2)break}else f.value==="("&&l++,f.value===")"&&l--,a[o]+=f.value}e.expect(y.DPAREN_END),a[0].trim()&&(r=ne(e,a[0].trim())),a[1].trim()&&(s=ne(e,a[1].trim())),a[2].trim()&&(i=ne(e,a[2].trim())),e.skipNewlines(),e.check(y.SEMICOLON)&&e.advance(),e.skipNewlines();let c;e.check(y.LBRACE)?(e.advance(),c=e.parseCompoundList(),e.expect(y.RBRACE)):(e.expect(y.DO),c=e.parseCompoundList(),e.expect(y.DONE));let u=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:s,update:i,body:c,redirections:u,line:n}}function Os(e,t){e.expect(y.WHILE);let n=e.parseCompoundList();e.expect(y.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(y.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.whileNode(n,r,s)}function Ls(e,t){e.expect(y.UNTIL);let n=e.parseCompoundList();e.expect(y.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(y.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.untilNode(n,r,s)}function Ts(e,t){e.expect(y.CASE),e.isWord()||e.error("Expected word after 'case'");let n=e.parseWord();e.skipNewlines(),e.expect(y.IN),e.skipNewlines();let r=[];for(;!e.check(y.ESAC,y.EOF);){e.checkIterationLimit();let i=e.getPos(),a=lf(e);if(a&&r.push(a),e.skipNewlines(),e.getPos()===i&&!a)break}e.expect(y.ESAC);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.caseNode(n,r,s)}function lf(e){e.check(y.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(y.PIPE));)e.advance();if(t.length===0)return null;e.expect(y.RPAREN),e.skipNewlines();let n=[];for(;!e.check(y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND,y.ESAC,y.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===y.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(y.LPAREN)&&e.peek(1).type===y.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let s=e.getPos(),i=e.parseStatement();if(i&&n.push(i),e.skipSeparators(!1),e.getPos()===s&&!i)break}let r=";;";return e.check(y.DSEMI)?(e.advance(),r=";;"):e.check(y.SEMI_AND)?(e.advance(),r=";&"):e.check(y.SEMI_SEMI_AND)&&(e.advance(),r=";;&"),L.caseItem(t,n,r)}function Ms(e,t){e.expect(y.LPAREN);let n=e.parseCompoundList();e.expect(y.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.subshell(n,r)}function Bs(e,t){e.expect(y.LBRACE);let n=e.parseCompoundList();e.expect(y.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return L.group(n,r)}var uf=["-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"],ff=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function yo(e){return e.isWord()||e.check(y.LBRACE)||e.check(y.RBRACE)||e.check(y.ASSIGNMENT_WORD)}function go(e){if(e.check(y.BANG)&&e.peek(1).type===y.LPAREN){e.advance(),e.advance();let t=1,n="!(";for(;t>0&&!e.check(y.EOF);)if(e.check(y.LPAREN))t++,n+="(",e.advance();else if(e.check(y.RPAREN))t--,t>0&&(n+=")"),e.advance();else if(e.isWord())n+=e.advance().value;else if(e.check(y.PIPE))n+="|",e.advance();else break;return n+=")",e.parseWordFromString(n,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function Fs(e){return e.skipNewlines(),df(e)}function df(e){let t=wo(e);for(e.skipNewlines();e.check(y.OR_OR);){e.advance(),e.skipNewlines();let n=wo(e);t={type:"CondOr",left:t,right:n},e.skipNewlines()}return t}function wo(e){let t=Ws(e);for(e.skipNewlines();e.check(y.AND_AND);){e.advance(),e.skipNewlines();let n=Ws(e);t={type:"CondAnd",left:t,right:n},e.skipNewlines()}return t}function Ws(e){return e.skipNewlines(),e.check(y.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:e.withDepth(()=>Ws(e))}):pf(e)}function pf(e){if(e.check(y.LPAREN)){e.advance();let t=e.withDepth(()=>Fs(e));return e.expect(y.RPAREN),{type:"CondGroup",expression:t}}if(yo(e)){let t=e.current(),n=t.value;if(uf.includes(n)&&!t.quoted){if(e.advance(),e.check(y.DBRACK_END)&&e.error(`Expected operand after ${n}`),yo(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()&&ff.includes(e.current().value)){let s=e.advance().value,i;return s==="=~"?i=hf(e):s==="=="||s==="!="?i=go(e):i=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:s,left:r,right:i}}if(e.check(y.LESS)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:r,right:s}}if(e.check(y.GREAT)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:r,right:s}}if(e.isWord()&&e.current().value==="="){e.advance();let s=go(e);return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function hf(e){let t=[],n=0,r=-1,s=e.getInput(),i=()=>e.check(y.DBRACK_END)||e.check(y.AND_AND)||e.check(y.OR_OR)||e.check(y.NEWLINE)||e.check(y.EOF);for(;!i();){let a=e.current(),o=r>=0&&a.start>r;if(n===0&&o)break;if(n>0&&o){let l=s.slice(r,a.start);t.push({type:"Literal",value:l})}if(e.isWord()||e.check(y.ASSIGNMENT_WORD)){let l=e.parseWordForRegex();t.push(...l.parts),r=e.peek(-1).end}else if(e.check(y.LPAREN)){let l=e.advance();t.push({type:"Literal",value:"("}),n++,r=l.end}else if(e.check(y.DPAREN_START)){let l=e.advance();t.push({type:"Literal",value:"(("}),n+=2,r=l.end}else if(e.check(y.DPAREN_END))if(n>=2){let l=e.advance();t.push({type:"Literal",value:"))"}),n-=2,r=l.end}else{if(n===1)break;break}else if(e.check(y.RPAREN))if(n>0){let l=e.advance();t.push({type:"Literal",value:")"}),n--,r=l.end}else break;else if(e.check(y.PIPE)){let l=e.advance();t.push({type:"Literal",value:"|"}),r=l.end}else if(e.check(y.SEMICOLON))if(n>0){let l=e.advance();t.push({type:"Literal",value:";"}),r=l.end}else break;else if(n>0&&e.check(y.LESS)){let l=e.advance();t.push({type:"Literal",value:"<"}),r=l.end}else if(n>0&&e.check(y.GREAT)){let l=e.advance();t.push({type:"Literal",value:">"}),r=l.end}else if(n>0&&e.check(y.DGREAT)){let l=e.advance();t.push({type:"Literal",value:">>"}),r=l.end}else if(n>0&&e.check(y.DLESS)){let l=e.advance();t.push({type:"Literal",value:"<<"}),r=l.end}else if(n>0&&e.check(y.LESSAND)){let l=e.advance();t.push({type:"Literal",value:"<&"}),r=l.end}else if(n>0&&e.check(y.GREATAND)){let l=e.advance();t.push({type:"Literal",value:">&"}),r=l.end}else if(n>0&&e.check(y.LESSGREAT)){let l=e.advance();t.push({type:"Literal",value:"<>"}),r=l.end}else if(n>0&&e.check(y.CLOBBER)){let l=e.advance();t.push({type:"Literal",value:">|"}),r=l.end}else if(n>0&&e.check(y.TLESS)){let l=e.advance();t.push({type:"Literal",value:"<<<"}),r=l.end}else if(n>0&&e.check(y.AMP)){let l=e.advance();t.push({type:"Literal",value:"&"}),r=l.end}else if(n>0&&e.check(y.LBRACE)){let l=e.advance();t.push({type:"Literal",value:"{"}),r=l.end}else if(n>0&&e.check(y.RBRACE)){let l=e.advance();t.push({type:"Literal",value:"}"}),r=l.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function Ln(e){return e.length>0?e:[L.literal("")]}function yf(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 gf(e,t,n){let r=n+1,s=t[r];if("@*#?$!-0123456789".includes(s))return{part:L.parameterExpansion(s),endIndex:r+1};let i="";for(;r<t.length&&/[a-zA-Z0-9_]/.test(t[r]);)i+=t[r],r++;return{part:L.parameterExpansion(i),endIndex:r}}function wf(e,t,n,r=!1){let s=n+2,i=!1;t[s]==="!"&&(i=!0,s++);let a=!1;t[s]==="#"&&!/[}:#%/^,]/.test(t[s+1]||"}")&&(a=!0,s++);let o="",l=t[s];if(/[@*#?$!-]/.test(l)&&!/[a-zA-Z0-9_]/.test(t[s+1]||""))o=l,s++;else for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)o+=t[s],s++;if(t[s]==="["){let u=Ps(e,t,s,"[","]");if(o+=t.slice(s,u+1),s=u+1,t[s]==="["){let f=1,d=s;for(;d<t.length&&f>0;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let p=t.slice(n+2,d);return{part:L.parameterExpansion("",{type:"BadSubstitution",text:p}),endIndex:d+1}}}if(o===""&&!i&&!a&&t[s]!=="}"){let u=1,f=s;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;if(u>0)throw new Ae("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(n+2,f);return{part:L.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let c=null;if(i){let u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Vs(e,t,s,o,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):(c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},o="")}else c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},o="";else if(t[s]==="*"||t[s]==="@"&&!/[QPaAEKkuUL]/.test(t[s+1]||"")){let f=t[s];s++,c={type:"VarNamePrefix",prefix:o,star:f==="*"},o=""}else if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Vs(e,t,s,o,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):c={type:"Indirection"}}else c={type:"Indirection"}}else if(a)if(t[s]===":")for(c={type:"LengthSliceError"};s<t.length&&t[s]!=="}";)s++;else t[s]!=="}"&&/[-+=?]/.test(t[s])?e.error(`\${#${o}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):t[s]==="/"?e.error(`\${#${o}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):c={type:"Length"};if(!c&&s<t.length&&t[s]!=="}"){let u=Vs(e,t,s,o,r);c=u.operation,s=u.endIndex}if(s<t.length&&t[s]!=="}"){let u=t[s];if(!/[:\-+=?#%/^,@[]/.test(u)){let f=s;for(;f<t.length&&t[f]!=="}";)f++;let d=t.slice(n,f+1);e.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<t.length&&t[s]!=="}";)s++;if(s>=t.length)throw new Ae("unexpected EOF while looking for matching '}'",0,0);return{part:L.parameterExpansion(o,c),endIndex:s+1}}function Vs(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=Ht(e,t,i),g=t.slice(i,b),w=e.withDepth(()=>Ct(e,g,!1,!1,!0,!1,s,!1,!1,!0)),S=L.word(Ln(w));if(l==="-")return{operation:{type:"DefaultValue",word:S,checkEmpty:!0},endIndex:b};if(l==="=")return{operation:{type:"AssignDefault",word:S,checkEmpty:!0},endIndex:b};if(l==="?")return{operation:{type:"ErrorIfUnset",word:S,checkEmpty:!0},endIndex:b};if(l==="+")return{operation:{type:"UseAlternative",word:S,checkEmpty:!0},endIndex:b}}i++;let c=Ht(e,t,i),u=t.slice(i,c),f=-1,d=0,p=0;for(let E=0;E<u.length;E++){let b=u[E];if(b==="("||b==="[")d++;else if(b===")"||b==="]")d--;else if(b==="?"&&d===0)p++;else if(b===":"&&d===0)if(p>0)p--;else{f=E;break}}let h=f>=0?u.slice(0,f):u,m=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:Cs(e,h),length:m!==null?Cs(e,m):null},endIndex:c}}if("-=?+".includes(a)){i++;let l=Ht(e,t,i),c=t.slice(i,l),u=e.withDepth(()=>Ct(e,c,!1,!1,!0,!1,s,!1,!1,!0)),f=L.word(Ln(u));if(a==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:l};if(a==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:l};if(a==="?")return{operation:{type:"ErrorIfUnset",word:c?f:null,checkEmpty:!1},endIndex:l};if(a==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:l}}if(a==="#"||a==="%"){let l=o===a,c=a==="#"?"prefix":"suffix";i+=l?2:1;let u=Ht(e,t,i),f=t.slice(i,u),d=e.withDepth(()=>Ct(e,f,!1,!1,!1));return{operation:{type:"PatternRemoval",pattern:L.word(Ln(d)),side:c,greedy:l},endIndex:u}}if(a==="/"){let l=o==="/";i+=l?2:1;let c=null;t[i]==="#"?(c="start",i++):t[i]==="%"&&(c="end",i++);let u;c!==null&&(t[i]==="/"||t[i]==="}")?u=i:u=lo(e,t,i);let f=t.slice(i,u),d=e.withDepth(()=>Ct(e,f,!1,!1,!1)),p=L.word(Ln(d)),h=null,m=u;if(t[u]==="/"){let E=u+1,b=Ht(e,t,E),g=t.slice(E,b),w=e.withDepth(()=>Ct(e,g,!1,!1,!1));h=L.word(Ln(w)),m=b}return{operation:{type:"PatternReplacement",pattern:p,replacement:h,all:l,anchor:c},endIndex:m}}if(a==="^"||a===","){let l=o===a,c=a==="^"?"upper":"lower";i+=l?2:1;let u=Ht(e,t,i),f=t.slice(i,u),d=f?L.word([L.literal(f)]):null;return{operation:{type:"CaseModification",direction:c,all:l,pattern:d},endIndex:u}}return a==="@"&&/[QPaAEKkuUL]/.test(o)?{operation:{type:"Transform",operator:o},endIndex:i+2}:{operation:null,endIndex:i}}function zs(e,t,n,r=!1){let s=n+1;if(s>=t.length)return{part:L.literal("$"),endIndex:s};let i=t[s];if(i==="("&&t[s+1]==="(")return e.isDollarDparenSubshell(t,n)?e.parseCommandSubstitution(t,n):e.parseArithmeticExpansion(t,n);if(i==="["){let a=1,o=s+1;for(;o<t.length&&a>0;)t[o]==="["?a++:t[o]==="]"&&a--,a>0&&o++;if(a===0){let l=t.slice(s+1,o),c=ne(e,l);return{part:L.arithmeticExpansion(c),endIndex:o+1}}}return i==="("?e.parseCommandSubstitution(t,n):i==="{"?wf(e,t,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?gf(e,t,n):{part:L.literal("$"),endIndex:s}}function Eo(e,t){let n=[],r=0,s="",i=()=>{s&&(n.push(L.literal(s)),s="")};for(;r<t.length;){let a=t[r];if(a==="\\"&&r+1<t.length){let o=t[r+1];if(o==="$"||o==="`"||o==='"'||o==="\\"){s+=o,r+=2;continue}s+=a,r++;continue}if(a==="$"){i();let{part:o,endIndex:l}=zs(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 Ef(e,t,n){let r=[],s=n,i="",a=()=>{i&&(r.push(L.literal(i)),i="")};for(;s<t.length&&t[s]!=='"';){let o=t[s];if(o==="\\"&&s+1<t.length){let l=t[s+1];if('"\\$`\n'.includes(l)){i+=l,s+=2;continue}i+=o,s++;continue}if(o==="$"){a();let{part:l,endIndex:c}=zs(e,t,s,!0);l&&r.push(l),s=c;continue}if(o==="`"){a();let{part:l,endIndex:c}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=c;continue}i+=o,s++}return a(),{part:L.doubleQuoted(r),endIndex:s}}function Ct(e,t,n=!1,r=!1,s=!1,i=!1,a=!1,o=!1,l=!1,c=!1){if(r)return[L.singleQuoted(t)];if(n){let h=Eo(e,t);return[L.doubleQuoted(h)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let h=t.slice(1,-1),m=!1;for(let E=0;E<h.length;E++){if(h[E]==='"'){m=!0;break}h[E]==="\\"&&E+1<h.length&&E++}if(!m){let E=Eo(e,h);return[L.doubleQuoted(E)]}}let u=[],f=0,d="",p=()=>{d&&(u.push(L.literal(d)),d="")};for(;f<t.length;){let h=t[f];if(h==="\\"&&f+1<t.length){let m=t[f+1];if(l){p(),u.push(L.escaped(m)),f+=2;continue}let E=i?m==="$"||m==="`"||m===`
63
- `:m==="$"||m==="`"||m==='"'||m==="'"||m===`
64
- `||c&&m==="}",b=a?"*?[]\\".includes(m):"*?[]\\(){}.^+".includes(m);E?d+=m:b?(p(),u.push(L.escaped(m))):d+=`\\${m}`,f+=2;continue}if(h==="'"&&!a&&!i){p();let m=t.indexOf("'",f+1);if(m===-1){d+=t.slice(f);break}u.push(L.singleQuoted(t.slice(f+1,m))),f=m+1;continue}if(h==='"'&&!i){p();let{part:m,endIndex:E}=Ef(e,t,f+1);u.push(m),f=E+1;continue}if(h==="$"&&t[f+1]==="'"){p();let{part:m,endIndex:E}=uo(e,t,f+2);u.push(m),f=E;continue}if(h==="$"){p();let{part:m,endIndex:E}=zs(e,t,f);m&&u.push(m),f=E;continue}if(h==="`"){p();let{part:m,endIndex:E}=e.parseBacktickSubstitution(t,f);u.push(m),f=E;continue}if(h==="~"){let m=f>0?t[f-1]:"";if(f===0||m==="="||s&&m===":"){let b=oo(e,t,f),g=t[b];if(g===void 0||g==="/"||g===":"){p();let w=t.slice(f+1,b)||null;u.push({type:"TildeExpansion",user:w}),f=b;continue}}}if("@*+?!".includes(h)&&f+1<t.length&&t[f+1]==="("){let m=yf(t,f+1);if(m!==-1){p();let E=t.slice(f,m+1);u.push({type:"Glob",pattern:E}),f=m+1;continue}}if(h==="*"||h==="?"||h==="["){p();let{pattern:m,endIndex:E}=co(e,t,f);u.push({type:"Glob",pattern:m}),f=E;continue}if(h==="{"&&!s&&!o&&!i){let m=fo(e,t,f,Ct);if(m){p(),u.push(m.part),f=m.endIndex;continue}}d+=h,f++}return p(),u}var V=class e{tokens=[];pos=0;pendingHeredocs=[];parseBudget;ownsParseBudget;_input="";constructor(t){this.parseBudget=t??new fr,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>$s)throw new Ae(`Input too large: ${t.length} bytes exceeds limit of ${$s}`,1,1);this._input=t;let s=new ur(t,n);if(this.tokens=s.tokenize(),this.tokens.length>In)throw new Ae(`Too many tokens: ${this.tokens.length} exceeds limit of ${In}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseBudget.chargeTokens(this.tokens.length),this.parseScript()}finally{r?.()}}parseTokens(t){this.ownsParseBudget&&this.parseBudget.reset();let n=this.ownsParseBudget?void 0:this.enterDepth();try{return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.parseBudget.chargeTokens(t.length),this.parseScript()}finally{n?.()}}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}check(t,n,r,s,...i){let a=this.tokens[this.pos]?.type;return a===t||n!==void 0&&a===n||r!==void 0&&a===r||s!==void 0&&a===s?!0:i.length>0?i.includes(a):!1}expect(t,n){if(this.check(t))return this.advance();let r=this.current();throw new Ae(n||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let n=this.current();throw new Ae(t,n.line,n.column,n)}skipNewlines(){for(;this.check(y.NEWLINE,y.COMMENT);)this.check(y.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(y.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(y.SEMICOLON,y.COMMENT)){this.advance();continue}if(t&&this.check(y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,n,r,s){this.pendingHeredocs.push({redirect:t,delimiter:n,stripTabs:r,quoted:s})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(y.HEREDOC_CONTENT)){let n=this.advance(),r;t.quoted?r=L.word([L.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),t.redirect.target=L.hereDoc(t.delimiter,r,t.stripTabs,t.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(y.EOF,y.NEWLINE,y.SEMICOLON,y.AMP,y.AND_AND,y.OR_OR,y.RPAREN,y.RBRACE,y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return t===y.WORD||t===y.NAME||t===y.NUMBER||t===y.ASSIGNMENT_WORD||t===y.IF||t===y.FOR||t===y.WHILE||t===y.UNTIL||t===y.CASE||t===y.LPAREN||t===y.LBRACE||t===y.DPAREN_START||t===y.DBRACK_START||t===y.FUNCTION||t===y.BANG||t===y.TIME||t===y.IN||t===y.LESS||t===y.GREAT||t===y.DLESS||t===y.DGREAT||t===y.LESSAND||t===y.GREATAND||t===y.LESSGREAT||t===y.DLESSDASH||t===y.CLOBBER||t===y.TLESS||t===y.AND_GREAT||t===y.AND_DGREAT}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(y.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)");let s=this.checkUnexpectedToken();if(s){t.push(s),this.skipSeparators(!1);continue}let i=this.pos,a=this.parseStatement();a&&t.push(a),this.skipSeparators(!1),this.check(y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(y.EOF)&&this.advance()}return L.script(t)}checkUnexpectedToken(){let t=this.current().type,n=this.current().value;if((t===y.DO||t===y.DONE||t===y.THEN||t===y.ELSE||t===y.ELIF||t===y.FI||t===y.ESAC)&&this.error(`syntax error near unexpected token \`${n}'`),t===y.RBRACE||t===y.RPAREN){let r=`syntax error near unexpected token \`${n}'`;return this.advance(),L.statement([L.pipeline([L.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:n})}return(t===y.DSEMI||t===y.SEMI_AND||t===y.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),t===y.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`),(t===y.PIPE||t===y.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${n}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,n=[],r=[],s=!1,i=this.parsePipeline();for(n.push(i);this.check(y.AND_AND,y.OR_OR);){let l=this.advance();r.push(l.type===y.AND_AND?"&&":"||"),this.skipNewlines();let c=this.parsePipeline();n.push(c)}this.check(y.AMP)&&(this.advance(),s=!0);let a=this.pos>0?this.tokens[this.pos-1].end:t,o=this._input.slice(t,a);return L.statement(n,r,s,void 0,o)}parsePipeline(){let t=!1,n=!1;this.check(y.TIME)&&(this.advance(),t=!0,this.check(y.WORD,y.NAME)&&this.current().value==="-p"&&(this.advance(),n=!0));let r=0;for(;this.check(y.BANG);)this.advance(),r++;let s=r%2===1,i=[],a=[],o=this.parseCommand();for(i.push(o);this.check(y.PIPE,y.PIPE_AMP);){let l=this.advance();this.skipNewlines(),a.push(l.type===y.PIPE_AMP);let c=this.parseCommand();i.push(c)}return L.pipeline(i,s,t,n,a.length>0?a:void 0)}parseCommand(){return this.check(y.IF)?Is(this):this.check(y.FOR)?_s(this):this.check(y.WHILE)?Os(this):this.check(y.UNTIL)?Ls(this):this.check(y.CASE)?Ts(this):this.check(y.LPAREN)?Ms(this):this.check(y.LBRACE)?Bs(this):this.check(y.DPAREN_START)?this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand():this.check(y.DBRACK_START)?this.parseConditionalCommand():this.check(y.FUNCTION)?this.parseFunctionDef():this.check(y.NAME,y.WORD)&&this.peek(1).type===y.LPAREN&&this.peek(2).type===y.RPAREN?this.parseFunctionDef():mo(this)}dparenClosesWithSpacedParens(){let t=1,n=1;for(;n<this.tokens.length-this.pos;){let r=this.peek(n);if(r.type===y.EOF)return!1;if(r.type===y.DPAREN_START||r.type===y.LPAREN)t++;else if(r.type===y.DPAREN_END){if(t-=2,t<=0)return!1}else if(r.type===y.RPAREN&&(t--,t===0&&this.peek(n+1).type===y.RPAREN))return!0;n++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(y.RPAREN),this.expect(y.RPAREN);let n=this.parseOptionalRedirections(),r=L.subshell(t,[]);return L.subshell([L.statement([L.pipeline([r],!1,!1,!1)])],n)}isWord(){let t=this.current().type;return t===y.WORD||t===y.NAME||t===y.NUMBER||t===y.IF||t===y.FOR||t===y.WHILE||t===y.UNTIL||t===y.CASE||t===y.FUNCTION||t===y.ELSE||t===y.ELIF||t===y.FI||t===y.THEN||t===y.DO||t===y.DONE||t===y.ESAC||t===y.IN||t===y.SELECT||t===y.TIME||t===y.COPROC||t===y.BANG}parseWord(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted)}parseWordNoBraceExpansion(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0)}parseWordForRegex(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0,!0)}parseWordFromString(t,n=!1,r=!1,s=!1,i=!1,a=!1,o=!1){let l=Ct(this,t,n,r,s,i,!1,a,o);return L.word(l)}parseCommandSubstitution(t,n){return Ma(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseBacktickSubstitution(t,n,r=!1){return Ba(t,n,r,()=>new e(this.parseBudget),s=>this.error(s))}isDollarDparenSubshell(t,n){return Ta(t,n)}parseArithmeticExpansion(t,n){let r=n+3,s=1,i=0,a=r;for(;a<t.length-1&&s>0;)t[a]==="$"&&t[a+1]==="("?t[a+2]==="("?(s++,a+=3):(i++,a+=2):t[a]==="("&&t[a+1]==="("?(s++,a+=2):t[a]===")"&&t[a+1]===")"?i>0?(i--,a++):(s--,s>0&&(a+=2)):t[a]==="("?(i++,a++):(t[a]===")"&&i>0&&i--,a++);let o=t.slice(r,a),l=this.parseArithmeticExpression(o);return{part:L.arithmeticExpansion(l),endIndex:a+2}}parseArithmeticCommand(){let t=this.expect(y.DPAREN_START),n="",r=1,s=0,i=!1,a=!1;for(;r>0&&!this.check(y.EOF);){if(i){if(i=!1,s>0){s--,n+=")";continue}if(this.check(y.RPAREN)){r--,a=!0,this.advance();continue}if(this.check(y.DPAREN_END)){r--,a=!0;continue}n+=")";continue}if(this.check(y.DPAREN_START))r++,n+="((",this.advance();else if(this.check(y.DPAREN_END))s>=2?(s-=2,n+="))",this.advance()):s===1?(s--,n+=")",i=!0,this.advance()):(r--,a=!0,r>0&&(n+="))"),this.advance());else if(this.check(y.LPAREN))s++,n+="(",this.advance();else if(this.check(y.RPAREN))s>0&&s--,n+=")",this.advance();else{let c=this.current().value,u=n.length>0?n[n.length-1]:"";n.length>0&&!n.endsWith(" ")&&!(c==="="&&/[|&^+\-*/%<>]$/.test(n))&&!(c==="<"&&u==="<")&&!(c===">"&&u===">")&&(n+=" "),n+=c,this.advance()}}a||this.expect(y.DPAREN_END);let o=this.parseArithmeticExpression(n.trim()),l=this.parseOptionalRedirections();return L.arithmeticCommand(o,l,t.line)}parseConditionalCommand(){let t=this.expect(y.DBRACK_START),n=Fs(this);this.expect(y.DBRACK_END);let r=this.parseOptionalRedirections();return L.conditionalCommand(n,r,t.line)}parseFunctionDef(){let t;if(this.check(y.FUNCTION)){if(this.advance(),this.check(y.NAME)||this.check(y.WORD))t=this.advance().value;else{let s=this.current();throw new Ae("Expected function name",s.line,s.column,s)}this.check(y.LPAREN)&&(this.advance(),this.expect(y.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(y.LPAREN),this.expect(y.RPAREN);this.skipNewlines();let n=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return L.functionDef(t,n,r)}parseCompoundCommandBody(t){let n=t?.forFunctionBody;if(this.check(y.LBRACE))return Bs(this,{skipRedirections:n});if(this.check(y.LPAREN))return Ms(this,{skipRedirections:n});if(this.check(y.IF))return Is(this,{skipRedirections:n});if(this.check(y.FOR))return _s(this,{skipRedirections:n});if(this.check(y.WHILE))return Os(this,{skipRedirections:n});if(this.check(y.UNTIL))return Ls(this,{skipRedirections:n});if(this.check(y.CASE))return Ts(this,{skipRedirections:n});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth();try{let n=[];for(this.skipNewlines();!this.check(y.EOF,y.FI,y.ELSE,y.ELIF,y.THEN,y.DO,y.DONE,y.ESAC,y.RPAREN,y.RBRACE,y.DSEMI,y.SEMI_AND,y.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,s=this.parseStatement();if(s&&n.push(s),this.skipSeparators(),this.pos===r&&!s)break}return n}finally{t()}}parseOptionalRedirections(){let t=[];for(;hr(this);){this.checkIterationLimit();let n=this.pos;if(t.push(mr(this)),this.pos===n)break}return t}parseArithmeticExpression(t){return ne(this,t)}};function tt(e,t){return new V().parse(e,t)}var Sf="BASH_ALIAS_";function yr(e,t,n,r){let s=T(t);if(s>n-r.value)throw new $(`alias expansion exceeds string length limit (${n} bytes)`,"string_length");return r.value+=s,e+t}function bo(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function So(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function Ao(e,t){return e.env.get(`${Sf}${t}`)}function xo(e,t,n){return $o(e,t,n)}function $o(e,t,n,r=!0){if(!t.name||!bo(t.name))return t;let s=So(t.name);if(!s)return t;let i=Ao(e,s);if(!i||n.has(s))return t;try{n.add(s);let a=new V,o={value:0},l=yr("",i,e.limits.maxStringLength,o),c=i.endsWith(" ");if(!c)for(let p of t.args){let h=ko(p);l=yr(l,` ${h}`,e.limits.maxStringLength,o)}let u;try{u=a.parse(l)}catch(p){if(p instanceof Ae)throw p;return t}if(u.statements.length!==1||u.statements[0].pipelines.length!==1||u.statements[0].pipelines[0].commands.length!==1)return vo(e,t,i);let f=u.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return vo(e,t,i);let d={...f,assignments:[...t.assignments,...f.assignments],redirections:[...f.redirections,...t.redirections],line:t.line};if(c&&t.args.length>0){d={...d,args:[...d.args,...t.args]};let p=1;for(;r&&d.args.length>0;){let h=d.args[0];if(!bo(h))break;let m=So(h),E=m?Ao(e,m):null;if(!E)break;if(p>=e.limits.maxCallDepth)throw new $(`alias expansion depth limit exceeded (${e.limits.maxCallDepth})`,"recursion");p++;let b={type:"SimpleCommand",name:h,args:d.args.slice(1),assignments:[],redirections:[]},g=$o(e,b,n,!1);if(g===b||(d={...d,name:g.name,args:[...g.args]},!E.endsWith(" ")))break}}return d}catch(a){throw n.delete(s),a}}function vo(e,t,n){let r={value:0},s=yr("",n,e.limits.maxStringLength,r);for(let c of t.args){let u=ko(c);s=yr(s,` ${u}`,e.limits.maxStringLength,r)}let i=new V,a=i.parseWordFromString("eval",!1,!1),o=0;for(let c of s)c==="'"&&o++;if(r.value+2+o*3>e.limits.maxStringLength)throw new $(`alias expansion exceeds string length limit (${e.limits.maxStringLength} bytes)`,"string_length");let l=i.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:a,args:[l],assignments:t.assignments,redirections:t.redirections,line:t.line}}function ko(e){let t="";for(let n of e.parts)switch(n.type){case"Literal":t+=n.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${n.value}'`;break;case"DoubleQuoted":t+=`"${n.parts.map(r=>r.type==="Literal"?r.value:`$${r.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${n.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${n.expression}))`;break;case"Glob":t+=n.pattern;break;default:break}return t}var Af=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 qs(e){return Af.get(e)??""}function No(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 Po(e){let t="^";for(let n=0;n<e.length;n++){let r=e[n];if(r==="*")t+="[^/]*";else if(r==="?")t+="[^/]";else if(r==="["){let s=n+1,i="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(i+="^",s++),s<e.length&&e[s]==="]"&&(i+="\\]",s++);let a=s;for(;a<e.length;){if(e[a]==="\\"&&a+1<e.length){a+=2;continue}if(e[a]==="["&&a+1<e.length&&e[a+1]===":"){let l=e.indexOf(":]",a+2);if(l!==-1){a=l+2;continue}}if(e[a]==="]")break;a++}let o=s;for(;s<e.length&&e[s]!=="]";){if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let l=e.indexOf(":]",s+2);if(l!==-1){let c=e.slice(s+2,l),u=qs(c);i+=u,s=l+2;continue}}if(e[s]==="\\"&&s+1<e.length){i+=`\\${e[s+1]}`,s+=2;continue}if(e[s]==="-"){let l=s===o,c=s+1===a;l||c?i+="\\-":i+="-"}else i+=e[s];s++}i+="]",t+=i,n=s}else if(r==="\\"&&n+1<e.length){let s=e[n+1];/[.+^${}()|\\*?[\]]/.test(s)?t+=`\\${s}`:t+=s,n++}else/[.+^${}()|]/.test(r)?t+=`\\${r}`:t+=r}return t+="$",he(t)}function Us(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 js(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 Co=5,Dt=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=No(i))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new $(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations");this.consumeOperation?.()}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(n=>{let r=n.split("/").pop()||n;if((this.hasGlobignore||this.globskipdots)&&(r==="."||r===".."))return!1;if(this.hasGlobignore){for(let s of this.globignorePatterns)if(this.matchGlobignorePattern(n,s))return!1}return!0})}matchGlobignorePattern(t,n){return Po(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>Co))throw new $(`Glob pattern has too many ** segments (max ${Co})`,"glob_operations")}let n;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))n=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");n=await this.expandSimple(r)}return this.filterGlobignore(n)}isGlobstarValid(t){let n=t.split("/");for(let r of n)if(r.includes("**")&&r!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let n=t.startsWith("/"),r=t.split("/").filter(c=>c!==""),s=-1;for(let c=0;c<r.length;c++)if(this.hasGlobChars(r[c])){s=c;break}if(s===-1)return[t];let i,a;if(s===0)n?(i="/",a="/"):(i=this.cwd,a="");else{let c=r.slice(0,s);n?(i=`/${c.join("/")}`,a=`/${c.join("/")}`):(i=this.fs.resolvePath(this.cwd,c.join("/")),a=c.join("/"))}let o=r.slice(s);return(await this.expandSegments(i,a,o)).sort()}async expandSegments(t,n,r){if(this.checkOpsLimit(),r.length===0)return[n];let[s,...i]=r,a=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let o=await this.fs.readdirWithFileTypes(t),l=[],c=[...o],u=this.dotglob||this.hasGlobignore;if(s.startsWith(".")||this.dotglob){let d=o.some(h=>h.name==="."),p=o.some(h=>h.name==="..");d||c.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),p||c.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of c)if(!(d.name.startsWith(".")&&!s.startsWith(".")&&!u)&&this.matchPattern(d.name,s)){let 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=[],c=[...o],u=this.dotglob||this.hasGlobignore;(s.startsWith(".")||this.dotglob)&&(o.includes(".")||c.push("."),o.includes("..")||c.push(".."));for(let d of c)if(!(d.startsWith(".")&&!s.startsWith(".")&&!u)&&this.matchPattern(d,s)){let 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 $)throw m}return[]})())}let f=await Promise.all(l);for(let d of f)a.push(...d)}}catch(o){if(o instanceof $)throw o}return a}async expandRecursive(t){let n=[],r=t.indexOf("**"),s=t.slice(0,r).replace(/\/$/,"")||".",a=t.slice(r+2).replace(/^\//,"");return a.includes("**")&&this.isGlobstarValid(a)?(await this.walkDirectoryMultiGlobstar(s,a,n),[...new Set(n)].sort()):(await this.walkDirectory(s,a,n),n.sort())}async walkDirectoryMultiGlobstar(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let i=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(s):null;if(i){let a=[];for(let c of i){let u=t==="."?c.name:`${t}/${c.name}`;c.isDirectory&&a.push(u)}let o=t==="."?n:`${t}/${n}`,l=await this.expandRecursive(o);r.push(...l);for(let c=0;c<a.length;c+=100){let u=a.slice(c,c+100);await Promise.all(u.map(f=>this.walkDirectoryMultiGlobstar(f,n,r)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(s),o=[];for(let u of a){let f=t==="."?u:`${t}/${u}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&o.push(f)}catch(p){if(p instanceof $)throw p}}let l=t==="."?n:`${t}/${n}`,c=await this.expandRecursive(l);r.push(...c);for(let u=0;u<o.length;u+=100){let f=o.slice(u,u+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,n,r)))}}}catch(i){if(i instanceof $)throw i}}async walkDirectory(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let i=await this.fs.readdirWithFileTypes(s),a=[],o=[];for(let l of i){let c=t==="."?l.name:`${t}/${l.name}`;l.isDirectory?o.push(c):n&&this.matchPattern(l.name,n)&&a.push(c)}r.push(...a);for(let l=0;l<o.length;l+=100){let c=o.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u,n,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(s),a=[];for(let l=0;l<i.length;l+=100){let c=i.slice(l,l+100),u=await Promise.all(c.map(async f=>{let d=t==="."?f:`${t}/${f}`,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 $)throw h;return null}}));a.push(...u.filter(f=>f!==null))}for(let l of a)!l.isDirectory&&n&&this.matchPattern(l.name,n)&&r.push(l.path);let o=a.filter(l=>l.isDirectory);for(let l=0;l<o.length;l+=100){let c=o.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,n,r)))}}}catch(i){if(i instanceof $)throw i}}matchPattern(t,n){return this.patternToRegex(n).test(t)}patternToRegex(t){let n=this.patternToRegexStr(t);return he(`^${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=Us(t,s+1);if(a!==-1){let o=t.slice(s+2,a),l=js(o),c=l.map(f=>this.patternToRegexStr(f)),u=c.length>0?c.join("|"):"(?:)";if(i==="@")n+=`(?:${u})`;else if(i==="*")n+=`(?:${u})*`;else if(i==="+")n+=`(?:${u})+`;else if(i==="?")n+=`(?:${u})?`;else if(i==="!")if(a<t.length-1){let d=l.map(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(`(?!(?:${u})).{${h}}`),n+=`(?:${m.join("|")})`}}else n+=`(?:(?!(?:${u})).)*?`}else n+=`(?!(?:${u})$).*`;s=a;continue}}if(i==="*")n+=".*";else if(i==="?")n+=".";else if(i==="["){let a=s+1,o="[";a<t.length&&(t[a]==="^"||t[a]==="!")&&(o+="^",a++),a<t.length&&t[a]==="]"&&(o+="\\]",a++);let l=a;for(;l<t.length;){if(t[l]==="\\"&&l+1<t.length){l+=2;continue}if(t[l]==="["&&l+1<t.length&&t[l+1]===":"){let u=t.indexOf(":]",l+2);if(u!==-1){l=u+2;continue}}if(t[l]==="]")break;l++}let c=a;for(;a<t.length&&t[a]!=="]";){if(t[a]==="["&&a+1<t.length&&t[a+1]===":"){let u=t.indexOf(":]",a+2);if(u!==-1){let f=t.slice(a+2,u),d=qs(f);o+=d,a=u+2;continue}}if(t[a]==="\\"&&a+1<t.length){o+=`\\${t[a+1]}`,a+=2;continue}if(t[a]==="-"){let u=a===c,f=a+1===l;u||f?o+="\\-":o+="-"}else o+=t[a];a++}o+="]",n+=o,s=a}else if(i==="\\"&&s+1<t.length){let a=t[s+1];/[.+^${}()|\\*?[\]]/.test(a)?n+=`\\${a}`:n+=a,s++}else/[.+^${}()|]/.test(i)?n+=`\\${i}`:n+=i}return n}computePatternLength(t){let n=0,r=0,s=!1;for(;r<t.length;){if(t.slice(r,r+13)==="\0QUOTE_START\0"){s=!0,r+=13;continue}if(t.slice(r,r+11)==="\0QUOTE_END\0"){s=!1,r+=11;continue}let i=t[r];if(s){n+=1,r++;continue}if((i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&r+1<t.length&&t[r+1]==="("){let a=Us(t,r+1);if(a!==-1){if(i==="@"){let o=t.slice(r+2,a),c=js(o).map(u=>this.computePatternLength(u));if(c.every(u=>u!==null)&&c.every(u=>u===c[0])){n+=c[0],r=a+1;continue}return null}return null}}if(i==="*")return null;if(i==="?"){n+=1,r++;continue}if(i==="["){let a=t.indexOf("]",r+1);if(a!==-1){n+=1,r=a+1;continue}n+=1,r++;continue}if(i==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}};function Gs(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 vf(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 Do(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 Tn(e){let t=!1,n=!1,r=!1,s=!1,i=!1,a=!1,o=!1;for(let l of e){if((l.type==="SingleQuoted"||l.type==="DoubleQuoted")&&(t=!0,l.type==="DoubleQuoted"))for(let c of l.parts)c.type==="ParameterExpansion"&&(c.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!c.operation||c.operation.type==="PatternRemoval"||c.operation.type==="PatternReplacement")&&(s=!0),(c.operation?.type==="VarNamePrefix"||c.operation?.type==="ArrayKeys")&&(a=!0),c.operation?.type==="Indirection"&&(o=!0));l.type==="CommandSubstitution"&&(n=!0),l.type==="ParameterExpansion"&&(i=!0,(l.parameter==="@"||l.parameter==="*")&&(r=!0),vf(l)&&(t=!0),(l.operation?.type==="VarNamePrefix"||l.operation?.type==="ArrayKeys")&&(a=!0),l.operation?.type==="Indirection"&&(o=!0)),l.type==="Glob"&&Gs(l.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i,hasVarNamePrefixExpansion:a,hasIndirection:o}}var xf=`
65
- `;function Qt(e,t){if(e>=t)throw new $(`array element limit exceeded (${t})`,"array_elements")}function Zs(e,t,n,r,s){Qt(e.length,s),Qt(t.length,s),e.push(n),t.push(r)}function be(e){return e.get("IFS")??xf}function ke(e){return e.get("IFS")===""}function gr(e){let t=be(e);if(t==="")return!0;for(let n of t)if(n!==" "&&n!==" "&&n!==`
66
- `)return!1;return!0}function Ro(e){let t=!1,n=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?n.push(`\\${r}`):r===" "?n.push("\\t"):r===`
67
- `?n.push("\\n"):n.push(r);return t&&n.push("\\-"),n.join("")}function U(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var $f=`
68
- `;function kf(e){return $f.includes(e)}function Hs(e){let t=new Set,n=new Set;for(let r of e)kf(r)?t.add(r):n.add(r);return{whitespace:t,nonWhitespace:n}}function Qs(e,t,n,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:(Qt(0,n),{words:[e],wordStarts:[0]});let{whitespace:i,nonWhitespace:a}=Hs(t),o=[],l=[],c=0;for(;c<e.length&&i.has(e[c]);)c++;if(c>=e.length)return{words:[],wordStarts:[]};if(a.has(e[c]))for(Zs(o,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&!(r!==void 0&&o.length>=r);){let u=c;for(;c<e.length;){let f=e[c];if(!s&&f==="\\"){c++,c<e.length&&c++;continue}if(i.has(f)||a.has(f))break;c++}if(Zs(o,l,e.substring(u,c),u,n),c>=e.length)break;for(;c<e.length&&i.has(e[c]);)c++;if(c<e.length&&a.has(e[c])){for(c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&a.has(e[c])&&!(r!==void 0&&o.length>=r);)for(Zs(o,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++}}return{words:o,wordStarts:l}}function wr(e,t,n){if(t==="")return e&&Qt(0,n),{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=Hs(t),i=[],a=0,o=!1,l=!1,c=a;for(;a<e.length&&r.has(e[a]);)a++;if(a>c&&(o=!0),a>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[a]))for(Qt(i.length,n),i.push(""),a++;a<e.length&&r.has(e[a]);)a++;for(;a<e.length;){let u=a;for(;a<e.length;){let d=e[a];if(r.has(d)||s.has(d))break;a++}if(Qt(i.length,n),i.push(e.substring(u,a)),a>=e.length){l=!1;break}let f=a;for(;a<e.length&&r.has(e[a]);)a++;if(a<e.length&&s.has(e[a])){for(a++;a<e.length&&r.has(e[a]);)a++;for(;a<e.length&&s.has(e[a]);)for(Qt(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 le(e,t,n){return wr(e,t,n).words}function Nf(e,t){for(let n of e)if(t.has(n))return!0;return!1}function Io(e,t,n){if(t==="")return e;let{whitespace:r,nonWhitespace:s}=Hs(t),i=e.length;for(;i>0&&r.has(e[i-1]);){if(!n&&i>=2){let o=0,l=i-2;for(;l>=0&&e[l]==="\\";)o++,l--;if(o%2===1)break}i--}let a=e.substring(0,i);if(a.length>=1&&s.has(a[a.length-1])){if(!n&&a.length>=2){let l=0,c=a.length-2;for(;c>=0&&a[c]==="\\";)l++,c--;if(l%2===1)return a}let o=a.substring(0,a.length-1);if(!Nf(o,s))return o}return a}function ae(e,t){return e.state.namerefs?.has(t)??!1}function wt(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function _o(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Oo(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function Lo(e,t){return e.state.invalidNamerefs?.has(t)??!1}function Ks(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function Er(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let s=n[1],i=$e(e,s),a=e.state.associativeArrays?.has(s)??!1;return i||a}return $e(e,t)?!0:e.state.env.has(t)}function Re(e,t,n=100){if(!ae(e,t)||Lo(e,t))return t;let r=new Set,s=t;for(;n-- >0;){if(r.has(s))return;if(r.add(s),!ae(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 Kt(e,t){if(ae(e,t))return e.state.env.get(t)}function br(e,t,n,r=100){if(!ae(e,t)||Lo(e,t))return t;let s=new Set,i=t;for(;r-- >0;){if(s.has(i))return;if(s.add(i),!ae(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)&&Er(e,n)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(a))return i;i=a}}function To(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)?ut(e,t).map(i=>[i,se(e,t,i)??""]):Ee(e,t).map(s=>[s,se(e,t,s)??""])}function nt(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)?$e(e,t):$e(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(U(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 _a;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 Le("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 Le("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 Le("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new je(`\${${t}}`);let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let a=s[1],o=s[2];if(ae(e,a)){let f=Re(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=cr(o);f=To(e,f);let d=se(e,a,f);if(d===void 0&&n&&e.state.options.nounset)throw new Le(`${a}[${o}]`);return d||""}let c;if(/^-?\d+$/.test(o))c=Number.parseInt(o,10);else try{let f=new V,d=ne(f,o);c=await Z(e,d.expression)}catch{let f=e.state.env.get(o);c=f?Number.parseInt(f,10):0,Number.isNaN(c)&&(c=0)}if(c<0){let f=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
69
- `,"";let h=Math.max(...f.map(([E])=>typeof E=="number"?E:0))+1+c;return h<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${a}: bad array subscript
70
- `,""):se(e,a,h)||""}let u=se(e,a,c);if(u!==void 0)return u;if(c===0){let f=e.state.env.get(a);if(f!==void 0)return f}if(n&&e.state.options.nounset)throw new Le(`${a}[${c}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let a=e.state.env.get(t);if(a===void 0&&n&&e.state.options.nounset)throw new Le(t);return a||""}if(ae(e,t)){let a=Re(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 Le(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(nt(e,t)){let a=se(e,t,0);if(a!==void 0)return a;if(n&&e.state.options.nounset)throw new Le(t);return""}if(n&&e.state.options.nounset)throw new Le(t);return""}async function dt(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(ae(e,s)){let l=Re(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=To(e,cr(i));return Nt(e,s,l)}let o;if(/^-?\d+$/.test(i))o=Number.parseInt(i,10);else try{let l=new V,c=ne(l,i);o=await Z(e,c.expression)}catch{let l=e.state.env.get(i);o=l?Number.parseInt(l,10):0,Number.isNaN(o)&&(o=0)}if(o<0){let l=z(e,s);if(l.length===0)return!1;let u=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+o;return u<0?!1:Nt(e,s,u)}return Nt(e,s,o)}if(ae(e,t)){let s=Re(e,t);return s===void 0||s===t?e.state.env.has(t):dt(e,s)}return e.state.env.has(t)?!0:nt(e,t)?Nt(e,t,0):!1}async function Mo(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 Xs(e,t){let n=t,r=t.startsWith('"')&&t.endsWith('"'),s=t.startsWith("'")&&t.endsWith("'");if((r||s)&&(n=t.slice(1,-1)),s)return n;let i="",a=0;for(;a<n.length;)if(n[a]==="$")if(n[a+1]==="("){let o=1,l=a+2;for(;l<n.length&&o>0;)n[l]==="("&&n[l-1]==="$"||n[l]==="("?o++:n[l]===")"&&o--,l++;let c=n.slice(a+2,l-1);if(e.execFn){let u=await e.execFn(c,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}a=l}else if(n[a+1]==="{"){let o=1,l=a+2;for(;l<n.length&&o>0;)n[l]==="{"?o++:n[l]==="}"&&o--,l++;let c=n.slice(a+2,l-1),u=await re(e,c);i+=u,a=l}else if(/[a-zA-Z_]/.test(n[a+1]||"")){let o=a+1;for(;o<n.length&&/[a-zA-Z0-9_]/.test(n[o]);)o++;let l=n.slice(a+1,o),c=await re(e,l);i+=c,a=o}else i+=n[a],a++;else if(n[a]==="`"){let o=a+1;for(;o<n.length&&n[o]!=="`";)o++;let l=n.slice(a+1,o);if(e.execFn){let c=await e.execFn(l,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}a=o+1}else i+=n[a],a++;return i}var Mn=1e4,Ys={maxResults:Mn,maxStringBytes:10*1024*1024};function Sr(e,t,n,r){if(e.length>=n.maxResults)return!1;let s=T(t);if(s>n.maxStringBytes-r.value)throw new $(`brace expansion string limit exceeded (${n.maxStringBytes} bytes)`,"string_length");return e.push(t),r.value+=s,!0}function Pf(e,t,n,r,s,i=Ys){let a=n??1;a===0&&(a=1);let o=Math.abs(a),l=[],c=0;if(r?.match(/^-?0\d/)&&(c=Math.max(c,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(c=Math.max(c,s.replace(/^-/,"").length)),c>i.maxStringBytes)throw new $(`brace expansion padding limit exceeded (${i.maxStringBytes} bytes)`,"string_length");let u={value:0},f=d=>{if(c>0){let p=d<0,h=String(Math.abs(d)).padStart(c,"0");return p?`-${h}`:h}return String(d)};if(e<=t)for(let d=e,p=0;d<=t&&p<Mn&&Sr(l,f(d),i,u);d+=o,p++);else for(let d=e,p=0;d>=t&&p<Mn&&Sr(l,f(d),i,u);d-=o,p++);return l}function Cf(e,t,n,r=Ys){let s=n??1;s===0&&(s=1);let i=e.charCodeAt(0),a=t.charCodeAt(0),o=Math.abs(s),l=e>="A"&&e<="Z",c=e>="a"&&e<="z",u=t>="A"&&t<="Z",f=t>="a"&&t<="z";if(l&&f||c&&u){let h=n!==void 0?`..${n}`:"";throw new rr(`{${e}..${t}${h}}: invalid sequence`)}let d=[],p={value:0};if(i<=a)for(let h=i,m=0;h<=a&&m<Mn&&Sr(d,String.fromCharCode(h),r,p);h+=o,m++);else for(let h=i,m=0;h>=a&&m<Mn&&Sr(d,String.fromCharCode(h),r,p);h-=o,m++);return d}function Js(e,t,n,r,s,i=Ys){let a=n!==void 0?`..${n}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:Pf(e,t,n,r,s,i),literal:`{${e}..${t}${a}}`}:typeof e=="string"&&typeof t=="string"?{expanded:Cf(e,t,n,i),literal:`{${e}..${t}${a}}`}:{expanded:null,literal:`{${e}..${t}${a}}`}}function Bo(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 pt(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function ei(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 Ze(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function Bn(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function ee(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Q(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=Df(e,s+1);if(a!==-1){let o=e.slice(s+2,a),c=Rf(o).map(f=>Q(f,t,n)),u=c.length>0?c.join("|"):"(?:)";i==="@"?r+=`(?:${u})`:i==="*"?r+=`(?:${u})*`:i==="+"?r+=`(?:${u})+`:i==="?"?r+=`(?:${u})?`:i==="!"&&(r+=`(?!(?:${u})$).*`),s=a+1;continue}}if(i==="\\")if(s+1<e.length){let a=e[s+1];/[\\^$.|+(){}[\]*?]/.test(a)?r+=`\\${a}`:r+=a,s+=2}else r+="\\\\",s++;else if(i==="*")r+=t?".*":".*?",s++;else if(i==="?")r+=".",s++;else if(i==="["){let a=If(e,s);if(a===-1)r+="\\[",s++;else{let o=e.slice(s+1,a);r+=_f(o),s=a+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,s++):(r+=i,s++)}return r}function Df(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 Rf(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 If(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 _f(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+=Lf(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 Of=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 Lf(e){return Of.get(e)??""}function rt(e,t,n,r,s){if(r==="prefix")return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),he(`^${n}`,"s").replace(t,"");let i=he(`${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=he(`^(?:.*)(${n})$`,"s").exec(t);if(!a)return t;let o=a[1]??"";return t.slice(0,t.length-o.length)}function hn(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 Ar(e,t,n,r,s){let i=new tn(e.limits.maxStringLength,"pattern replacement",()=>new $(`pattern replacement: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length"));n.lastIndex=0;let 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 Wo(e){let t=[],n=0;return{append(r){let s=T(r);if(s>e-n)throw new $(`prompt expansion exceeds string length limit (${e} bytes)`,"string_length");r&&t.push(r),n+=s},build:()=>t.join("")}}function Tf(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=Wo(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 Wn(e,t){let n=Wo(e.limits.maxStringLength),r=0,s=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",i=e.state.env.get("HOSTNAME")||"localhost",a=i.split(".")[0],o=e.state.env.get("PWD")||"/",l=e.state.env.get("HOME")||"/",c=o.startsWith(l)?`~${o.slice(l.length)}`:o,u=o.split("/").pop()||o,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],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 w=Number.parseInt(b,8)%256;n.append(String.fromCharCode(w)),r=g;continue}switch(E){case"\\":n.append("\\"),r+=2;break;case"a":n.append("\x07"),r+=2;break;case"e":n.append("\x1B"),r+=2;break;case"n":n.append(`
71
- `),r+=2;break;case"r":n.append("\r"),r+=2;break;case"$":n.append("$"),r+=2;break;case"[":case"]":r+=2;break;case"u":n.append(s),r+=2;break;case"h":n.append(a),r+=2;break;case"H":n.append(i),r+=2;break;case"w":n.append(c),r+=2;break;case"W":n.append(u),r+=2;break;case"d":{let b=String(f.getDate()).padStart(2," ");n.append(`${d[f.getDay()]} ${p[f.getMonth()]} ${b}`),r+=2;break}case"t":{let b=String(f.getHours()).padStart(2,"0"),g=String(f.getMinutes()).padStart(2,"0"),w=String(f.getSeconds()).padStart(2,"0");n.append(`${b}:${g}:${w}`),r+=2;break}case"T":{let b=f.getHours()%12;b===0&&(b=12);let g=String(b).padStart(2,"0"),w=String(f.getMinutes()).padStart(2,"0"),S=String(f.getSeconds()).padStart(2,"0");n.append(`${g}:${w}:${S}`),r+=2;break}case"@":{let b=f.getHours()%12;b===0&&(b=12);let g=String(b).padStart(2,"0"),w=String(f.getMinutes()).padStart(2,"0"),S=f.getHours()<12?"AM":"PM";n.append(`${g}:${w} ${S}`),r+=2;break}case"A":{let b=String(f.getHours()).padStart(2,"0"),g=String(f.getMinutes()).padStart(2,"0");n.append(`${b}:${g}`),r+=2;break}case"D":if(r+2<t.length&&t[r+2]==="{"){let b=t.indexOf("}",r+3);if(b!==-1){let g=t.slice(r+3,b);n.append(Tf(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 Rt(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`
72
- `: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 Fe(e,t){e.state.readonlyVars=e.state.readonlyVars||new Set,e.state.readonlyVars.add(t)}function Ie(e,t){return e.state.readonlyVars?.has(t)??!1}function oe(e,t,n="bash"){if(Ie(e,t)){let r=`${n}: ${t}: readonly variable
73
- `;throw new j(1,"",r)}return null}function st(e,t){let n=e.state.exportedVars?.has(t)??!1;if(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(t),e.state.localScopes.length>0&&e.state.localScopes[e.state.localScopes.length-1].has(t)&&!n){for(e.state.localExportedVars||(e.state.localExportedVars=[]);e.state.localExportedVars.length<e.state.localScopes.length;)e.state.localExportedVars.push(new Set);e.state.localExportedVars[e.state.localExportedVars.length-1].add(t)}}function vr(e,t){e.state.exportedVars?.delete(t)}function It(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let n="",r=Se(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"),ae(e,t)&&(n+="n"),Ie(e,t)&&(n+="r"),e.state.exportedVars?.has(t)&&(n+="x"),n}async function Fo(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 Vo(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:assign_default"),(r.isUnset||n.checkEmpty&&r.isEmpty)&&n.word){let a=await s(e,n.word.parts,r.inDoubleQuotes),o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let[,l,c]=o,u;if(/^\d+$/.test(c))u=Number.parseInt(c,10);else{try{let f=new V,d=ne(f,c);u=await Z(e,d.expression)}catch{let f=e.state.env.get(c);u=f?Number.parseInt(f,10):0}Number.isNaN(u)&&(u=0)}F(e,l,u,a)}else e.state.env.set(t,a);return a}return r.effectiveValue}async function zo(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 j(1,"",`bash: ${a}
74
- `)}return r.effectiveValue}async function qo(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 Uo(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+=Q(o.pattern,n.greedy,a);else if(o.type==="Literal")i+=Q(o.value,n.greedy,a);else if(o.type==="SingleQuoted"||o.type==="Escaped")i+=ee(o.value);else if(o.type==="DoubleQuoted"){let l=await r(e,o.parts);i+=ee(l)}else if(o.type==="ParameterExpansion"){let l=await s(e,o);i+=Q(l,n.greedy,a)}else{let l=await s(e,o);i+=ee(l)}return rt(e,t,i,n.side,n.greedy)}async function jo(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",a=e.state.shoptOptions.extglob;if(n.pattern)for(let c of n.pattern.parts)if(c.type==="Glob")i+=Q(c.pattern,!0,a);else if(c.type==="Literal")i+=Q(c.value,!0,a);else if(c.type==="SingleQuoted"||c.type==="Escaped")i+=ee(c.value);else if(c.type==="DoubleQuoted"){let u=await r(e,c.parts);i+=ee(u)}else if(c.type==="ParameterExpansion"){let u=await s(e,c);i+=Q(u,!0,a)}else{let u=await s(e,c);i+=ee(u)}let o=n.replacement?await r(e,n.replacement.parts):"";if(n.anchor==="start"?i=`^${i}`:n.anchor==="end"&&(i=`${i}$`),i==="")return t;let l=n.all?"gs":"s";try{let c=he(i,l);return Ar(e,t,c,o,n.all)}catch(c){if(c instanceof $)throw c;return t}}function Go(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)&&nt(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=se(e,t,0)||"";return String([...s].length)}return String([...n].length)}async function Zo(e,t,n,r){e.coverage?.hit("bash:expansion:substring");let s=await Z(e,r.offset.expression),i=r.length?await Z(e,r.length.expression):void 0;if(t==="@"||t==="*"){let c=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let h=1;h<=c;h++)u.push(e.state.env.get(String(h))||"");let f=e.state.env.get("0")||"bash",d,p;if(s<=0)if(d=[f,...u],s<0){if(p=d.length+s,p<0)return""}else p=0;else d=u,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 c=a[1];if(e.state.associativeArrays?.has(c))throw new j(1,"",`bash: \${${c}[@]: 0: 3}: bad substitution
75
- `);let u=z(e,c),f=0;if(s<0){if(u.length>0){let d=u[u.length-1][0],h=(typeof d=="number"?d:0)+1+s;if(h<0||(f=u.findIndex(([m])=>typeof m=="number"&&m>=h),f<0))return""}}else if(f=u.findIndex(([d])=>typeof d=="number"&&d>=s),f<0)return"";if(i!==void 0){if(i<0)throw new ie(`${a[1]}[@]: substring expression < 0`);return u.slice(f,f+i).map(([,d])=>d).join(" ")}return u.slice(f).map(([,d])=>d).join(" ")}let o=[...n],l=s;if(l<0&&(l=Math.max(0,o.length+l)),i!==void 0){if(i<0){let c=o.length+i;return o.slice(l,Math.max(l,c)).join("")}return o.slice(l,l+i).join("")}return o.slice(l).join("")}async function Ho(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+=Q(f.pattern,!0,i);else if(f.type==="Literal")a+=Q(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")a+=ee(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);a+=ee(d)}else if(f.type==="ParameterExpansion"){let d=await s(e,f);a+=Q(d,!0,i)}let o=he(`^(?:${a})$`),l=n.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),c="",u=!1;for(let f of t)!n.all&&u?c+=f:o.test(f)?(c+=l(f),u=!0):c+=f;return c}return n.direction==="upper"?n.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):n.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function Qo(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(([,c])=>Rt(c)).join(" ");if(i&&s.operator==="a")return It(e,i[1]);let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(a&&s.operator==="a")return It(e,a[1]);switch(s.operator){case"Q":return r?"":Rt(n);case"P":return Wn(e,n);case"a":return It(e,t);case"A":return r?"":`${t}=${Rt(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`
76
- `;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?"":Rt(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 Ko(e,t,n,r,s,i,a=!1){if(e.coverage?.hit("bash:expansion:indirection"),ae(e,t))return Kt(e,t)||"";let o=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(s.innerOp?.type==="UseAlternative")return"";throw new je(`\${!${t}}`)}let l=n;if(o&&(l===""||l.includes(" ")))throw new je(`\${!${t}}`);let c=l.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(c&&c[1].includes("~"))throw new je(`\${!${t}}`);if(s.innerOp){let u={type:"ParameterExpansion",parameter:l,operation:s.innerOp};return i(e,u,a)}return await re(e,l)}function Xo(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=z(e,t.array).map(([s])=>String(s));return t.star?r.join(U(e.state.env)):r.join(" ")}function Yo(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let n=hn(e,t.prefix);return t.star?n.join(U(e.state.env)):n.join(" ")}function Jo(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 c=U(e.state.env),u=l.map(([,f])=>f).join(c);return{isEmpty:r?u==="":!1,effectiveValue:u}}return{isEmpty:l.length===1&&l.every(([,c])=>c===""),effectiveValue:l.map(([,c])=>c).join(" ")}}return{isEmpty:n==="",effectiveValue:n}}function el(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 tl(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 xr(e,t){let n=new V,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=ct(e.state.arrays),o=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let c=await e.executeScript(r),u=c.exitCode;return e.state.env=i,e.state.arrays=a,e.state.cwd=o,e.state.suppressVerbose=l,e.state.lastExitCode=u,e.state.env.set("?",String(u)),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr),e.state.bashPid=s,c.stdout.replace(/\n+$/,"")}catch(c){if(e.state.env=i,e.state.arrays=a,e.state.cwd=o,e.state.bashPid=s,e.state.suppressVerbose=l,c instanceof $)throw c;return c instanceof j?(e.state.lastExitCode=c.exitCode,e.state.env.set("?",String(c.exitCode)),c.stdout?.replace(/\n+$/,"")??""):""}}function ti(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+=Ze(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=Mf(e,o);n+=Ze(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 Mf(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 nl(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+=Ze(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 Bf(e,o);n+=Ze(l),r=i+1;continue}}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=tl(t,r+2);if(i!==-1){let a=t.slice(r+2,i),o=await xr(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 xr(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 Bf(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=tl(t,r+2);if(i!==-1){let a=t.slice(r+2,i),o=await xr(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 xr(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 ni(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 _t(e,t){return t.split(":").map(n=>ni(e,n)).join(":")}function Ne(e,t,n,r){if(e.length>n-t.length)throw new $(`${r} element limit exceeded (${n})`,"array_elements");for(let s of t)e.push(s)}async function Wf(e,t,n,r){let s="";for(let i of t.parts)if(i.type==="Glob")s+=Q(i.pattern,!0,e.state.shoptOptions.extglob);else if(i.type==="Literal")s+=Q(i.value,!0,e.state.shoptOptions.extglob);else if(i.type==="SingleQuoted"||i.type==="Escaped")s+=ee(i.value);else if(i.type==="DoubleQuoted"){let a=await n(e,i.parts);s+=ee(a)}else if(i.type==="ParameterExpansion"){let a=await r(e,i);s+=Q(a,!0,e.state.shoptOptions.extglob)}else{let a=await r(e,i);s+=ee(a)}return s}async function rl(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternReplacement")return null;let i=s.parts[0],a=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let o=a[1],l=a[2]==="*",c=i.operation,u=z(e,o),f=u.map(([,E])=>E);if(u.length===0){let E=e.state.env.get(o);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let d="";c.pattern&&(d=await Wf(e,c.pattern,n,r));let p=c.replacement?await n(e,c.replacement.parts):"",h=d;c.anchor==="start"?h=`^${d}`:c.anchor==="end"&&(h=`${d}$`);let m=[];try{let E=he(h,c.all?"g":"");for(let b of f)m.push(E.replace(b,p))}catch{m.push(...f)}if(l){let E=U(e.state.env);return{values:[m.join(E)],quoted:!0}}return{values:m,quoted:!0}}async function sl(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternRemoval")return null;let i=s.parts[0],a=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let o=a[1],l=a[2]==="*",c=i.operation,u=z(e,o),f=u.map(([,m])=>m);if(u.length===0){let m=e.state.env.get(o);m!==void 0&&f.push(m)}if(f.length===0)return{values:[],quoted:!0};let d="",p=e.state.shoptOptions.extglob;if(c.pattern)for(let m of c.pattern.parts)if(m.type==="Glob")d+=Q(m.pattern,c.greedy,p);else if(m.type==="Literal")d+=Q(m.value,c.greedy,p);else if(m.type==="SingleQuoted"||m.type==="Escaped")d+=ee(m.value);else if(m.type==="DoubleQuoted"){let E=await n(e,m.parts);d+=ee(E)}else if(m.type==="ParameterExpansion"){let E=await r(e,m);d+=Q(E,c.greedy,p)}else{let E=await r(e,m);d+=ee(E)}let h=[];for(let m of f)h.push(rt(e,m,d,c.side,c.greedy));if(l){let m=U(e.state.env);return{values:[h.join(m)],quoted:!0}}return{values:h,quoted:!0}}async function il(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="DefaultValue"&&n.parts[0].operation?.type!=="UseAlternative"&&n.parts[0].operation?.type!=="AssignDefault")return null;let r=n.parts[0],s=r.operation,i=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/),a,o=!1;if(i){let l=i[1];o=i[2]==="*";let c=z(e,l),u=c.length>0||e.state.env.has(l),f=c.length===0||c.length===1&&c.every(([,p])=>p===""),d=s.checkEmpty??!1;if(s.type==="UseAlternative"?a=u&&!(d&&f):a=!u||d&&f,!a){if(c.length>0){let h=c.map(([,m])=>m);if(o){let m=U(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,c=await dt(e,l),u=await re(e,l),f=u==="",d=s.checkEmpty??!1;if(s.type==="UseAlternative"?a=c&&!(d&&f):a=!c||d&&f,!a)return{values:[u],quoted:!0}}if(a&&s.word){let l=s.word.parts,c=null,u=!1;for(let f of l)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){c=d[1],u=d[2]==="*";break}}if(c){let f=z(e,c);if(f.length>0){let p=f.map(([,h])=>h);if(u||o){let h=U(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}let d=e.state.env.get(c);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}return null}async function al(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0],a=-1,o="",l=!1,c=null;for(let m=0;m<i.parts.length;m++){let E=i.parts[m];if(E.type==="ParameterExpansion"&&(E.operation?.type==="PatternRemoval"||E.operation?.type==="PatternReplacement")){let b=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){a=m,o=b[1],l=b[2]==="*",c=E.operation;break}}}if(a===-1||a===0&&a===i.parts.length-1)return null;let u="";for(let m=0;m<a;m++)u+=await r(e,i.parts[m]);let f="";for(let m=a+1;m<i.parts.length;m++)f+=await r(e,i.parts[m]);let d=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:[u+f],quoted:!0};let E=u+f;return{values:E?[E]:[],quoted:!0}}}if(c?.type==="PatternRemoval"){let m=c,E="",b=e.state.shoptOptions.extglob;if(m.pattern)for(let g of m.pattern.parts)if(g.type==="Glob")E+=Q(g.pattern,m.greedy,b);else if(g.type==="Literal")E+=Q(g.value,m.greedy,b);else if(g.type==="SingleQuoted"||g.type==="Escaped")E+=ee(g.value);else if(g.type==="DoubleQuoted"){let w=await s(e,g.parts);E+=ee(w)}else if(g.type==="ParameterExpansion"){let w=await r(e,g);E+=Q(w,m.greedy,b)}else{let w=await r(e,g);E+=ee(w)}p=p.map(g=>rt(e,g,E,m.side,m.greedy))}else if(c?.type==="PatternReplacement"){let m=c,E="";if(m.pattern)for(let w of m.pattern.parts)if(w.type==="Glob")E+=Q(w.pattern,!0,e.state.shoptOptions.extglob);else if(w.type==="Literal")E+=Q(w.value,!0,e.state.shoptOptions.extglob);else if(w.type==="SingleQuoted"||w.type==="Escaped")E+=ee(w.value);else if(w.type==="DoubleQuoted"){let S=await s(e,w.parts);E+=ee(S)}else if(w.type==="ParameterExpansion"){let S=await r(e,w);E+=Q(S,!0,e.state.shoptOptions.extglob)}else{let S=await r(e,w);E+=ee(S)}let b=m.replacement?await s(e,m.replacement.parts):"",g=E;m.anchor==="start"?g=`^${E}`:m.anchor==="end"&&(g=`${E}$`);try{let w=he(g,m.all?"g":"");p=p.map(S=>w.replace(S,b))}catch{}}if(l){let m=U(e.state.env);return{values:[u+p.join(m)+f],quoted:!0}}return p.length===1?{values:[u+p[0]+f],quoted:!0}:{values:[u+p[0],...p.slice(1,-1),p[p.length-1]+f],quoted:!0}}async function ol(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 c="";for(let p=i+1;p<s.parts.length;p++)c+=await r(e,s.parts[p]);let u=z(e,a),f=u.map(([,p])=>p);if(u.length===0){let p=e.state.env.get(a);if(p!==void 0)return{values:[l+p+c],quoted:!0};if(o)return{values:[l+c],quoted:!0};let h=l+c;return{values:h?[h]:[],quoted:!0}}if(o){let p=U(e.state.env);return{values:[l+f.join(p)+c],quoted:!0}}return f.length===1?{values:[l+f[0]+c],quoted:!0}:{values:[l+f[0],...f.slice(1,-1),f[f.length-1]+c],quoted:!0}}async function ll(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 j(1,"",`bash: \${${a}[@]: 0: 3}: bad substitution
77
- `);let c=l.offset?await n(e,l.offset.expression):0,u=l.length?await n(e,l.length.expression):void 0,f=z(e,a);if(f.length>e.limits.maxArrayElements)throw new $(`array transform element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let d=0;if(c<0){if(f.length>0){let h=f[f.length-1][0],E=(typeof h=="number"?h:0)+1+c;if(E<0)return{values:[],quoted:!0};d=f.findIndex(([b])=>typeof b=="number"&&b>=E),d<0&&(d=f.length)}}else d=f.findIndex(([h])=>typeof h=="number"&&h>=c),d<0&&(d=f.length);let p;if(u!==void 0){if(u<0)throw new ie(`${a}[@]: substring expression < 0`);p=f.slice(d,d+u).map(([,h])=>h)}else p=f.slice(d).map(([,h])=>h);if(p.length===0)return{values:[],quoted:!0};if(o){let h=U(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}function cl(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.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=Wn(e,d);break;case"Q":p=Rt(d);break;default:p=d}if(T(p)>e.limits.maxStringLength)throw new $(`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 c=It(e,i),u=[],f=0;for(let[,d]of l){let p;switch(o.operator){case"a":p=c;break;case"P":p=Wn(e,d);break;case"Q":p=Rt(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=T(p);if(h>e.limits.maxStringLength-f)throw new $(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u.push(p),f+=h}if(a){let d=U(e.state.env);if(Math.max(0,u.length-1)*T(d)>e.limits.maxStringLength-f)throw new $(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u.join(d)],quoted:!0}}return{values:u,quoted:!0}}function ul(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(ae(e,i)){let l=Kt(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 fl(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)||!ae(e,s))return null;let i=Kt(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(([,u])=>u),quoted:!0};let c=e.state.env.get(o);return c!==void 0?{values:[c],quoted:!0}:{values:[],quoted:!0}}async function dl(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let a=i.parts[0],o=a.operation,l=await re(e,a.parameter),c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c){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(U(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let u=c[1],f=c[2]==="*",d=z(e,u);if(o.innerOp){if(o.innerOp.type==="Substring")return Ff(e,d,u,f,o.innerOp);if(o.innerOp.type==="DefaultValue"||o.innerOp.type==="UseAlternative"||o.innerOp.type==="AssignDefault"||o.innerOp.type==="ErrorIfUnset")return Vf(e,d,u,f,o.innerOp,s);if(o.innerOp.type==="Transform"&&o.innerOp.operator==="a"){let m=It(e,u),E=d.map(()=>m);return f?{values:[E.join(U(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(U(e.state.env))],quoted:!0}:{values:h,quoted:!0}}if(d.length>0){let h=d.map(([,m])=>m);return f?{values:[h.join(U(e.state.env))],quoted:!0}:{values:h,quoted:!0}}let p=e.state.env.get(u);return p!==void 0?{values:[p],quoted:!0}:{values:[],quoted:!0}}async function Ff(e,t,n,r,s){let i=s.offset?await Z(e,s.offset.expression):0,a=s.length?await Z(e,s.length.expression):void 0,o=0;if(i<0){if(t.length>0){let u=t[t.length-1][0],d=(typeof u=="number"?u:0)+1+i;if(d<0)return{values:[],quoted:!0};if(o=t.findIndex(([p])=>typeof p=="number"&&p>=d),o<0)return{values:[],quoted:!0}}}else if(o=t.findIndex(([u])=>typeof u=="number"&&u>=i),o<0)return{values:[],quoted:!0};let l;if(a!==void 0){if(a<0)throw new ie(`${n}[@]: substring expression < 0`);l=t.slice(o,o+a)}else l=t.slice(o);let c=l.map(([,u])=>u);return r?{values:[c.join(U(e.state.env))],quoted:!0}:{values:c,quoted:!0}}async function Vf(e,t,n,r,s,i){let a=s.checkEmpty??!1,o=t.map(([,u])=>u),l=t.length===0,c=t.length===0;if(s.type==="UseAlternative")return!c&&!(a&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(s.type==="DefaultValue")return(c||a&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:r?{values:[o.join(U(e.state.env))],quoted:!0}:{values:o,quoted:!0};if(s.type==="AssignDefault"){if((c||a&&l)&&s.word){let f=await i(e,s.word.parts,!0);return F(e,n,0,f),{values:[f],quoted:!0}}return r?{values:[o.join(U(e.state.env))],quoted:!0}:{values:o,quoted:!0}}return r?{values:[o.join(U(e.state.env))],quoted:!0}:{values:o,quoted:!0}}async function pl(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 c=await dt(e,n.parameter),u=await re(e,n.parameter)==="",f=r.checkEmpty??!1,d;if(r.type==="UseAlternative"?d=c&&!(f&&u):d=!c||f&&u,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(U(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 hl(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let n=t[0],s=n.operation.innerOp;if(!s||s.type!=="UseAlternative"&&s.type!=="DefaultValue")return null;let i=s.word;if(!i||i.parts.length!==1||i.parts[0].type!=="DoubleQuoted")return null;let a=i.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let o=a.parts[0],c=(await re(e,o.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c)return null;let u=await re(e,n.parameter),f=await dt(e,n.parameter),d=u==="",p=s.checkEmpty??!1,h;if(s.type==="UseAlternative"?h=f&&!(p&&d):h=!f||p&&d,h){let m=c[1],E=c[2]==="*",b=z(e,m);if(b.length>0){let w=b.map(([,S])=>S);return E?{values:[w.join(U(e.state.env))],quoted:!0}:{values:w,quoted:!0}}let g=e.state.env.get(m);return g!==void 0?{values:[g],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function ml(e){let t=Number.parseInt(e.state.env.get("#")||"0",10);if(t>e.limits.maxArrayElements)throw new $(`positional parameter element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let n=[],r=0;for(let s=1;s<=t;s++){let i=e.state.env.get(String(s))||"",a=T(i);if(a>e.limits.maxStringLength-r)throw new $(`positional parameter string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n.push(i),r+=a}return n}function $r(e,t,n){if(T(t)>n-T(e))throw new $(`positional expansion string limit exceeded (${n} bytes)`,"string_length");return e+t}function ri(e,t,n,r){if(e.length>=r.limits.maxArrayElements)throw new $(`positional expansion element limit exceeded (${r.limits.maxArrayElements})`,"array_elements");let s=T(t);if(s>r.limits.maxStringLength-n.value)throw new $(`positional expansion string limit exceeded (${r.limits.maxStringLength} bytes)`,"string_length");e.push(t),n.value+=s}async function yl(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,a=!1;for(let g=0;g<s.parts.length;g++){let w=s.parts[g];if(w.type==="ParameterExpansion"&&(w.parameter==="@"||w.parameter==="*")&&w.operation?.type==="Substring"){i=g,a=w.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=l.offset?await n(e,l.offset.expression):0,u=l.length?await n(e,l.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),d=[];for(let g=1;g<=f;g++)d.push(e.state.env.get(String(g))||"");let p=e.state.env.get("0")||"bash",h;if(c<=0){let g=[p,...d],w=g.length+c;if(w<0)h=[];else{let S=c<0?w:0;if(u!==void 0){let v=u<0?g.length+u:S+u;h=g.slice(S,Math.max(S,v))}else h=g.slice(S)}}else{let g=c-1;if(g>=d.length)h=[];else if(u!==void 0){let w=u<0?d.length+u:g+u;h=d.slice(g,Math.max(g,w))}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=U(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 gl(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,a=!1;for(let g=0;g<s.parts.length;g++){let w=s.parts[g];if(w.type==="ParameterExpansion"&&(w.parameter==="@"||w.parameter==="*")&&w.operation?.type==="PatternReplacement"){i=g,a=w.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=ml(e),u="";for(let g=0;g<i;g++)u=$r(u,await n(e,s.parts[g]),e.limits.maxStringLength);let f="";for(let g=i+1;g<s.parts.length;g++)f=$r(f,await n(e,s.parts[g]),e.limits.maxStringLength);if(c.length===0){let g=u+f;return{values:g?[g]:[],quoted:!0}}let d="";if(l.pattern)for(let g of l.pattern.parts)if(g.type==="Glob")d+=Q(g.pattern,!0,e.state.shoptOptions.extglob);else if(g.type==="Literal")d+=Q(g.value,!0,e.state.shoptOptions.extglob);else if(g.type==="SingleQuoted"||g.type==="Escaped")d+=ee(g.value);else if(g.type==="DoubleQuoted"){let w=await r(e,g.parts);d+=ee(w)}else if(g.type==="ParameterExpansion"){let w=await n(e,g);d+=Q(w,!0,e.state.shoptOptions.extglob)}else{let w=await n(e,g);d+=ee(w)}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=he(h,l.all?"g":"");for(let w of c){let S=0;g.lastIndex=0;for(let I=g.exec(w);I&&(S++,!!l.all);I=g.exec(w))I[0].length===0&&g.lastIndex++;let v=T(w),A=T(p),x=0,P=/\$(?:\$|&|\d+|<[^>]+>|`|')/g;for(;P.exec(p)!==null;)x++;if(v+S*A+S*x*v>e.limits.maxStringLength-E.value)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");ri(m,g.replace(w,p),E,e)}}catch(g){if(g instanceof $)throw g;for(let w of c)ri(m,w,E,e)}if(a){let g=U(e.state.env);if(E.value+Math.max(0,m.length-1)*T(g)+T(u)+T(f)>e.limits.maxStringLength)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+m.join(g)+f],quoted:!0}}if(T(u)+E.value+T(f)>e.limits.maxStringLength)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return m.length===1?{values:[u+m[0]+f],quoted:!0}:{values:[u+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function wl(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,a=!1;for(let b=0;b<s.parts.length;b++){let g=s.parts[b];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="PatternRemoval"){i=b,a=g.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=ml(e),u="";for(let b=0;b<i;b++)u=$r(u,await n(e,s.parts[b]),e.limits.maxStringLength);let f="";for(let b=i+1;b<s.parts.length;b++)f=$r(f,await n(e,s.parts[b]),e.limits.maxStringLength);if(c.length===0){let b=u+f;return{values:b?[b]:[],quoted:!0}}let d="",p=e.state.shoptOptions.extglob;if(l.pattern)for(let b of l.pattern.parts)if(b.type==="Glob")d+=Q(b.pattern,l.greedy,p);else if(b.type==="Literal")d+=Q(b.value,l.greedy,p);else if(b.type==="SingleQuoted"||b.type==="Escaped")d+=ee(b.value);else if(b.type==="DoubleQuoted"){let g=await r(e,b.parts);d+=ee(g)}else if(b.type==="ParameterExpansion"){let g=await n(e,b);d+=Q(g,l.greedy,p)}else{let g=await n(e,b);d+=ee(g)}let h=[],m={value:0};for(let b of c)ri(h,rt(e,b,d,l.side,l.greedy),m,e);if(a){let b=U(e.state.env);if(m.value+Math.max(0,h.length-1)*T(b)+T(u)+T(f)>e.limits.maxStringLength)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+h.join(b)+f],quoted:!0}}if(T(u)+m.value+T(f)>e.limits.maxStringLength)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return h.length===1?{values:[u+h[0]+f],quoted:!0}:{values:[u+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function El(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 c="";for(let d=s+1;d<r.parts.length;d++)c+=await n(e,r.parts[d]);if(o===0){if(i)return{values:[l+c],quoted:!0};let d=l+c;return{values:d?[d]:[],quoted:!0}}let u=[];for(let d=1;d<=o;d++)u.push(e.state.env.get(String(d))||"");if(i){let d=U(e.state.env);return{values:[l+u.join(d)+c],quoted:!0}}return u.length===1?{values:[l+u[0]+c],quoted:!0}:{values:[l+u[0],...u.slice(1,-1),u[u.length-1]+c],quoted:!0}}function ht(e,t,n,r){if(t.length>=e.limits.maxArrayElements)throw new $(`unquoted expansion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let s=T(n);if(s>e.limits.maxStringLength-r.value)throw new $(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");t.push(n),r.value+=s}function si(e,t,n,r){let s=T(n),i=Math.max(0,t.length-1);if(s>0&&i>Math.floor((e.limits.maxStringLength-r)/s))throw new $(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return t.join(n)}function zf(e){return new Dt(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 kr(e,t){if(e.state.options.noglob)return t;let n=zf(e),r=[];for(let s of t)if(pt(s,e.state.shoptOptions.extglob)){let i=await n.expand(s);if(i.length>0)Ne(r,i,e.limits.maxArrayElements,"unquoted glob expansion");else{if(n.hasFailglob())throw new bt(s);n.hasNullglob()||r.push(s)}}else r.push(s);return r}async function bl(e,t,n,r){let s=-1,i="",a=!1;for(let S=0;S<t.length;S++){let v=t[S];if(v.type==="ParameterExpansion"&&v.operation?.type==="PatternReplacement"){let A=v.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(A){s=S,i=A[1],a=A[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,c=z(e,i),u=c.map(([,S])=>S);if(c.length===0){let S=e.state.env.get(i);S!==void 0&&(u=[S])}if(u.length===0)return{values:[],quoted:!1};let f="";if(l.pattern)for(let S of l.pattern.parts)if(S.type==="Glob")f+=Q(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")f+=Q(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=ee(S.value);else if(S.type==="DoubleQuoted"){let v=await n(e,S.parts);f+=ee(v)}else if(S.type==="ParameterExpansion"){let v=await r(e,S);f+=Q(v,!0,e.state.shoptOptions.extglob)}else{let v=await r(e,S);f+=ee(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=he(p,l.all?"g":"");for(let v of u)ht(e,h,Ar(e,v,S,d,l.all),m)}catch(S){if(S instanceof $)throw S;for(let v of u)ht(e,h,v,m)}let E=be(e.state.env),b=ke(e.state.env);if(a){let S=U(e.state.env),v=si(e,h,S,m.value);return b?{values:v?[v]:[],quoted:!1}:{values:le(v,E,e.limits.maxArrayElements),quoted:!1}}if(b)return{values:h,quoted:!1};let g=[],w={value:0};for(let S of h)if(S==="")ht(e,g,"",w);else for(let v of le(S,E,e.limits.maxArrayElements))ht(e,g,v,w);return{values:g,quoted:!1}}async function Sl(e,t,n,r){let s=-1,i="",a=!1;for(let w=0;w<t.length;w++){let S=t[w];if(S.type==="ParameterExpansion"&&S.operation?.type==="PatternRemoval"){let v=S.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(v){s=w,i=v[1],a=v[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,c=z(e,i),u=c.map(([,w])=>w);if(c.length===0){let w=e.state.env.get(i);w!==void 0&&(u=[w])}if(u.length===0)return{values:[],quoted:!1};let f="",d=e.state.shoptOptions.extglob;if(l.pattern)for(let w of l.pattern.parts)if(w.type==="Glob")f+=Q(w.pattern,l.greedy,d);else if(w.type==="Literal")f+=Q(w.value,l.greedy,d);else if(w.type==="SingleQuoted"||w.type==="Escaped")f+=ee(w.value);else if(w.type==="DoubleQuoted"){let S=await n(e,w.parts);f+=ee(S)}else if(w.type==="ParameterExpansion"){let S=await r(e,w);f+=Q(S,l.greedy,d)}else{let S=await r(e,w);f+=ee(S)}let p=[],h={value:0};for(let w of u)ht(e,p,rt(e,w,f,l.side,l.greedy),h);let m=be(e.state.env),E=ke(e.state.env);if(a){let w=U(e.state.env),S=si(e,p,w,h.value);return E?{values:S?[S]:[],quoted:!1}:{values:le(S,m,e.limits.maxArrayElements),quoted:!1}}if(E)return{values:p,quoted:!1};let b=[],g={value:0};for(let w of p)if(w==="")ht(e,b,"",g);else for(let S of le(w,m,e.limits.maxArrayElements))ht(e,b,S,g);return{values:b,quoted:!1}}async function Al(e,t,n,r){let s=-1,i=!1;for(let g=0;g<t.length;g++){let w=t[g];if(w.type==="ParameterExpansion"&&(w.parameter==="@"||w.parameter==="*")&&w.operation?.type==="PatternRemoval"){s=g,i=w.parameter==="*";break}}if(s===-1)return null;let o=t[s].operation,l=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let g=1;g<=l;g++)c.push(e.state.env.get(String(g))||"");if(c.length===0)return{values:[],quoted:!1};let u="",f=e.state.shoptOptions.extglob;if(o.pattern)for(let g of o.pattern.parts)if(g.type==="Glob")u+=Q(g.pattern,o.greedy,f);else if(g.type==="Literal")u+=Q(g.value,o.greedy,f);else if(g.type==="SingleQuoted"||g.type==="Escaped")u+=ee(g.value);else if(g.type==="DoubleQuoted"){let w=await n(e,g.parts);u+=ee(w)}else if(g.type==="ParameterExpansion"){let w=await r(e,g);u+=Q(w,o.greedy,f)}else{let w=await r(e,g);u+=ee(w)}let d=[],p={value:0};for(let g of c)ht(e,d,rt(e,g,u,o.side,o.greedy),p);let h=be(e.state.env),m=ke(e.state.env);if(i){let g=U(e.state.env),w=si(e,d,g,p.value);return m?{values:w?[w]:[],quoted:!1}:{values:le(w,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==="")ht(e,E,"",b);else for(let w of le(g,h,e.limits.maxArrayElements))ht(e,E,w,b);return{values:E,quoted:!1}}async function vl(e,t,n,r){let s=-1,i=!1;for(let w=0;w<t.length;w++){let S=t[w];if(S.type==="ParameterExpansion"&&(S.parameter==="@"||S.parameter==="*")&&S.operation?.type==="Substring"){s=w,i=S.parameter==="*";break}}if(s===-1)return null;let o=t[s].operation,l=o.offset?await n(e,o.offset.expression):0,c=o.length?await n(e,o.length.expression):void 0,u=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let w=1;w<=u;w++)f.push(e.state.env.get(String(w))||"");let d=e.state.env.get("0")||"bash",p;if(l<=0){let w=[d,...f],S=w.length+l;if(S<0)p=[];else{let v=l<0?S:0;if(c!==void 0){let A=c<0?w.length+c:v+c;p=w.slice(v,Math.max(v,A))}else p=w.slice(v)}}else{let w=l-1;if(w>=f.length)p=[];else if(c!==void 0){let S=c<0?f.length+c:w+c;p=f.slice(w,Math.max(w,S))}else p=f.slice(w)}let h="";for(let w=0;w<s;w++)h+=await r(e,t[w]);let m="";for(let w=s+1;w<t.length;w++)m+=await r(e,t[w]);let E=be(e.state.env),b=ke(e.state.env);if(p.length===0){let w=h+m;return w?b?{values:[w],quoted:!1}:{values:le(w,E,e.limits.maxArrayElements),quoted:!1}:{values:[],quoted:!1}}let g;if(i){let w=U(e.state.env),S=h+p.join(w)+m;b?g=S?[S]:[]:g=le(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 w=0;w<p.length;w++){let S=p[w];if(w===0&&(S=h+S),w===p.length-1&&(S=S+m),S==="")g.push("");else{let v=le(S,E,e.limits.maxArrayElements);Ne(g,v,e.limits.maxArrayElements,"unquoted expansion")}}}return{values:await kr(e,g),quoted:!1}}async function xl(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let n=t[0].parameter==="*",r=Number.parseInt(e.state.env.get("#")||"0",10);if(r===0)return{values:[],quoted:!1};let s=[];for(let c=1;c<=r;c++)s.push(e.state.env.get(String(c))||"");let i=be(e.state.env),a=ke(e.state.env),o=gr(e.state.env),l;if(n)if(a)l=s.filter(c=>c!=="");else{let c=U(e.state.env),u=s.join(c);l=le(u,i,e.limits.maxArrayElements)}else if(a)l=s.filter(c=>c!=="");else if(o){l=[];for(let c of s){if(c==="")continue;let u=le(c,i,e.limits.maxArrayElements);Ne(l,u,e.limits.maxArrayElements,"unquoted expansion")}}else{l=[];for(let c of s)if(c==="")l.push("");else{let u=le(c,i,e.limits.maxArrayElements);Ne(l,u,e.limits.maxArrayElements,"unquoted expansion")}for(;l.length>0&&l[l.length-1]==="";)l.pop()}return{values:await kr(e,l),quoted:!1}}async function $l(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=be(e.state.env),l=ke(e.state.env),c=gr(e.state.env),u;if(s)if(l)u=a.filter(f=>f!=="");else{let f=U(e.state.env),d=a.join(f);u=le(d,o,e.limits.maxArrayElements)}else if(l)u=a.filter(f=>f!=="");else if(c){u=[];for(let f of a){if(f==="")continue;let d=le(f,o,e.limits.maxArrayElements);Ne(u,d,e.limits.maxArrayElements,"unquoted expansion")}}else{u=[];for(let f of a)if(f==="")u.push("");else{let d=le(f,o,e.limits.maxArrayElements);Ne(u,d,e.limits.maxArrayElements,"unquoted expansion")}for(;u.length>0&&u[u.length-1]==="";)u.pop()}return{values:await kr(e,u),quoted:!1}}function kl(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let n=t[0].operation,r=hn(e,n.prefix);if(r.length===0)return{values:[],quoted:!1};let s=be(e.state.env),i=ke(e.state.env),a;if(n.star)if(i)a=r;else{let o=U(e.state.env),l=r.join(o);a=le(l,s,e.limits.maxArrayElements)}else if(i)a=r;else{a=[];for(let o of r){let l=le(o,s,e.limits.maxArrayElements);Ne(a,l,e.limits.maxArrayElements,"unquoted expansion")}}return{values:a,quoted:!1}}function Nl(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=be(e.state.env),a=ke(e.state.env),o;if(n.star)if(a)o=s;else{let l=U(e.state.env),c=s.join(l);o=le(c,i,e.limits.maxArrayElements)}else if(a)o=s;else{o=[];for(let l of s){let c=le(l,i,e.limits.maxArrayElements);Ne(o,c,e.limits.maxArrayElements,"unquoted expansion")}}return{values:o,quoted:!1}}async function Pl(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=be(e.state.env),c=ke(e.state.env),u=gr(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(c)f=d.filter(p=>p!=="");else if(u){f=[];for(let p of d){if(p==="")continue;let h=le(p,l,e.limits.maxArrayElements);Ne(f,h,e.limits.maxArrayElements,"unquoted expansion")}}else{f=[];for(let p of d)if(p==="")f.push("");else{let h=le(p,l,e.limits.maxArrayElements);Ne(f,h,e.limits.maxArrayElements,"unquoted expansion")}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await kr(e,f),quoted:!1}}async function Rl(e,t,n){e.coverage?.hit("bash:expansion:word_glob");let r=t.parts,{hasQuoted:s,hasCommandSub:i,hasArrayVar:a,hasArrayAtExpansion:o,hasParamExpansion:l,hasVarNamePrefixExpansion:c,hasIndirection:u}=Tn(r),d=n.hasBraceExpansion(r)?await n.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return qf(e,d,s);let p=await Uf(e,r,o,c,u,n);if(p!==null)return p;let h=await Gf(e,r,n);if(h!==null)return h;let m=await Zf(e,r,n);if(m!==null)return m;let E=await Qf(e,r,n.expandPart);if(E!==null)return Dl(e,E);if((i||a||l)&&!ke(e.state.env)){let g=be(e.state.env),w=n.buildIfsCharClassPattern(g),S=await n.smartWordSplit(e,r,g,w,n.expandPart);return Dl(e,S)}let b=await n.expandWordAsync(e,t);return Kf(e,t,r,b,s,n.expandWordForGlobbing)}async function qf(e,t,n){let r=[];for(let s of t)if(!(!n&&s===""))if(!n&&!e.state.options.noglob&&pt(s,e.state.shoptOptions.extglob)){let i=await Nr(e,s);Ne(r,i,e.limits.maxArrayElements,"brace/glob expansion")}else r.push(s);return{values:r,quoted:!1}}async function Uf(e,t,n,r,s,i){if(n){let a=ul(e,t);if(a!==null)return a}{let a=fl(e,t);if(a!==null)return a}{let a=await il(e,t);if(a!==null)return a}{let a=await al(e,t,n,i.expandPart,i.expandWordPartsAsync);if(a!==null)return a}{let a=await ol(e,t,n,i.expandPart);if(a!==null)return a}{let a=await ll(e,t,i.evaluateArithmetic);if(a!==null)return a}{let a=cl(e,t);if(a!==null)return a}{let a=await rl(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}{let a=await sl(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let a=jf(e,t);if(a!==null)return a}{let a=await dl(e,t,s,i.expandParameterAsync,i.expandWordPartsAsync);if(a!==null)return a}{let a=await pl(e,t);if(a!==null)return a}{let a=await hl(e,t);if(a!==null)return a}return null}function jf(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=hn(e,r.prefix);return r.star?{values:[s.join(U(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(U(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function Gf(e,t,n){{let r=await yl(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await gl(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await wl(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await El(e,t,n.expandPart);if(r!==null)return r}return null}async function Zf(e,t,n){{let r=await bl(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Sl(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Al(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await vl(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await xl(e,t);if(r!==null)return r}{let r=await $l(e,t);if(r!==null)return r}{let r=kl(e,t);if(r!==null)return r}{let r=Nl(e,t);if(r!==null)return r}{let r=await Pl(e,t,n.expandPart);if(r!==null)return r}return null}function Cl(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 Hf(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=U(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 Qf(e,t,n){if(t.length<2)return null;let r=!1;for(let l of t)if(Cl(l)){r=!0;break}if(!r)return null;let s=be(e.state.env),i=ke(e.state.env),a=[];for(let l of t){let c=Cl(l);if(c&&l.type==="DoubleQuoted"){let u=await Hf(e,l,c,n);a.push(u)}else if(l.type==="DoubleQuoted"||l.type==="SingleQuoted"){let u=await n(e,l);a.push([u])}else if(l.type==="Literal")a.push([l.value]);else if(l.type==="ParameterExpansion"){let u=await n(e,l);if(i)a.push(u?[u]:[]);else{let f=le(u,s,e.limits.maxArrayElements);a.push(f)}}else{let u=await n(e,l);if(i)a.push(u?[u]:[]);else{let f=le(u,s,e.limits.maxArrayElements);a.push(f)}}}let o=[];for(let l of a)if(l.length!==0)if(o.length===0)Ne(o,l,e.limits.maxArrayElements,"word expansion");else{let c=o.length-1;o[c]=o[c]+l[0];for(let u=1;u<l.length;u++)o.push(l[u])}return o}async function Dl(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let n=[];for(let r of t)if(pt(r,e.state.shoptOptions.extglob)){let s=await Nr(e,r);Ne(n,s,e.limits.maxArrayElements,"glob expansion")}else n.push(r);return{values:n,quoted:!1}}async function Nr(e,t){let n=new Dt(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 bt(t);return n.hasNullglob()?[]:[t]}async function Kf(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(pt(o,e.state.shoptOptions.extglob)){let c=await Nr(e,o);if(c.length>0&&c[0]!==o)return{values:c,quoted:!1};if(c.length===0)return{values:[],quoted:!1}}let l=ei(r);if(!ke(e.state.env)){let c=be(e.state.env);return{values:le(l,c,e.limits.maxArrayElements),quoted:!1}}return{values:[l],quoted:!1}}if(!s&&!e.state.options.noglob&&pt(r,e.state.shoptOptions.extglob)){let o=await i(e,t);if(pt(o,e.state.shoptOptions.extglob)){let l=await Nr(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=ei(r);if(!ke(e.state.env)){let l=be(e.state.env);return{values:le(o,l,e.limits.maxArrayElements),quoted:!1}}return{values:[o],quoted:!1}}return{values:[r],quoted:s}}function Ce(e,t,n){if(t.length>=e.limits.maxArrayElements)throw new $(`word splitting element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");t.push(n)}async function _l(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 dt(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 Xf(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(n=>n.type==="Literal"):!1}async function Yf(e,t){if(t.type!=="ParameterExpansion")return null;let n=await _l(e,t);if(!n||n.length<=1)return null;let r=n.some(i=>Xf(i)),s=n.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&s?n:null}function Jf(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?Gs(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&Do(e))}async function Ol(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 _l(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 Il(e,p,n,r,s)}let i=[],a=!1;for(let d of t){let p=Jf(d),h=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=p?await Yf(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="",c=!1,u=!1,f=!1;for(let d of i)if(!d.isSplittable)u?d.isQuoted&&d.value===""?(l!==""&&Ce(e,o,l),Ce(e,o,""),c=!0,l="",u=!1,f=!0):d.value!==""?(l!==""&&Ce(e,o,l),l=d.value,u=!1,f=!1):(l+=d.value,f=!1):(l+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let p=await Il(e,d.mixedDefaultParts,n,r,s);if(p.length!==0)if(p.length===1)l+=p[0],c=!0;else{l+=p[0],Ce(e,o,l),c=!0;for(let h=1;h<p.length-1;h++)Ce(e,o,p[h]);l=p[p.length-1]}u=!1,f=!1}else{let{words:p,hadLeadingDelimiter:h,hadTrailingDelimiter:m}=wr(d.value,n,e.limits.maxArrayElements);if(f&&h&&l===""&&(Ce(e,o,""),c=!0),p.length===0)m&&(u=!0);else if(p.length===1)l+=p[0],c=!0,u=m;else{l+=p[0],Ce(e,o,l),c=!0;for(let E=1;E<p.length-1;E++)Ce(e,o,p[E]);l=p[p.length-1],u=m}f=!1}return l!==""?Ce(e,o,l):o.length===0&&c&&Ce(e,o,""),o}function ed(e,t){return e.length>0&&t.includes(e[0])}async function Il(e,t,n,r,s){let i=[];for(let u of t){let d=!(u.type==="DoubleQuoted"||u.type==="SingleQuoted"),p=await s(e,u);i.push({value:p,isSplittable:d})}let a=[],o="",l=!1,c=!1;for(let u of i)if(!u.isSplittable)c&&u.value!==""?(o!==""&&Ce(e,a,o),o=u.value,c=!1):o+=u.value;else{ed(u.value,n)&&o!==""&&(Ce(e,a,o),o="",l=!0);let{words:d,hadTrailingDelimiter:p}=wr(u.value,n,e.limits.maxArrayElements);if(d.length===0)p&&(c=!0);else if(d.length===1)o+=d[0],l=!0,c=p;else{o+=d[0],Ce(e,a,o),l=!0;for(let h=1;h<d.length-1;h++)Ce(e,a,d[h]);o=d[d.length-1],c=p}}return o!==""?Ce(e,a,o):a.length===0&&l&&Ce(e,a,""),a}function Ll(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Tl(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}function Ot(e,t,n){if(e.length>t)throw new $(`${n}: string length limit exceeded (${t} bytes)`,"string_length")}async function it(e,t,n=!1){let r=[];for(let s of t)r.push(await He(e,s,n));return r.join("")}function td(e){return Tl(e)}function Bl(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!td(t))return!1;return!0}function nd(e,t,n=!1){let r=Ll(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 ti(e,t.pattern);default:return null}}async function W(e,t){return ii(e,t)}async function Wl(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped")n.push(`\\${r.value}`);else if(r.type==="SingleQuoted")n.push(r.value);else if(r.type==="DoubleQuoted"){let s=await it(e,r.parts);n.push(s)}else if(r.type==="TildeExpansion"){let s=await He(e,r);n.push(Bn(s))}else n.push(await He(e,r));return n.join("")}async function Fl(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(Ze(r.value));else if(r.type==="DoubleQuoted"){let s=await it(e,r.parts);n.push(Ze(s))}else n.push(await He(e,r));return n.join("")}async function Vl(e,t){let n=[];for(let r of t.parts)if(r.type==="SingleQuoted")n.push(Ze(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 it(e,r.parts);n.push(Ze(s))}else r.type==="Glob"?el(r.pattern)?n.push(await nl(e,r.pattern)):n.push(ti(e,r.pattern)):r.type==="Literal"?n.push(r.value):n.push(await He(e,r));return n.join("")}function Cr(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&Cr(t.parts))return!0;return!1}var Ml=1e5;async function zl(e,t,n={count:0}){let r=()=>{n.count++,e.executionScope.consumeLimited("brace_operations",1,Math.min(Ml,e.limits.maxBraceExpansionResults),"brace expansion")},s=(a,o)=>{if(a.length>=e.limits.maxBraceExpansionResults)throw new $(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),a.push(o)},i=[[]];for(let a of t)if(a.type==="BraceExpansion"){let o=[],l=!1,c="";for(let d of a.items)if(d.type==="Range"){let p=Js(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,c=p.literal;break}}else{let p=await zl(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 He(e,E));s(o,m.join(""))}}if(l){for(let d of i)r(),d.push(c);continue}if(i.length*o.length>e.limits.maxBraceExpansionResults||n.count>Ml)throw new $(`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 $(`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 ql(e,t){let n=t.parts;if(!Cr(n))return[await W(e,t)];let r=await zl(e,n),s=[];for(let i of r){let a=[];for(let o of i)typeof o=="string"?a.push(o):a.push(await He(e,o));s.push(ni(e,a.join("")))}return s}function rd(){return{expandWordAsync:ii,expandWordForGlobbing:Vl,expandWordWithBracesAsync:ql,expandWordPartsAsync:it,expandPart:He,expandParameterAsync:Pr,hasBraceExpansion:Cr,evaluateArithmetic:Z,buildIfsCharClassPattern:Ro,smartWordSplit:Ol}}async function at(e,t){return Rl(e,t,rd())}function sd(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Fn(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 Dr(e,t){if(Fn(e,t))return{error:`bash: $@: ambiguous redirect
78
- `};let n=t.parts,{hasQuoted:r}=Tn(n);if(Cr(n)&&(await ql(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
79
- `};let s=await ii(e,t),{hasParamExpansion:i,hasCommandSub:a}=Tn(n);if((i||a)&&!r&&!ke(e.state.env)){let f=be(e.state.env);if(le(s,f,e.limits.maxArrayElements).length>1)return{error:`bash: $${sd(n)}: ambiguous redirect
80
- `}}if(r||e.state.options.noglob)return{target:s};let l=await Vl(e,t);if(!pt(l,e.state.shoptOptions.extglob))return{target:s};let c=new Dt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")}),u=await c.expand(l);return u.length===0?c.hasFailglob()?{error:`bash: no match: ${s}
81
- `}:{target:s}:u.length===1?{target:u[0]}:{error:`bash: ${s}: ambiguous redirect
82
- `}}async function ii(e,t){let n=t.parts,r=n.length;if(r===1){let a=await He(e,n[0]);return Ot(a,e.limits.maxStringLength,"word expansion"),a}let s=[];for(let a=0;a<r;a++)s.push(await He(e,n[a]));let i=s.join("");return Ot(i,e.limits.maxStringLength,"word expansion"),i}async function He(e,t,n=!1){if(t.type==="ParameterExpansion")return Pr(e,t,n);let r=nd(e,t,n);if(r!==null)return r;switch(t.type){case"DoubleQuoted":{let s=[];for(let i of t.parts)s.push(await He(e,i,!0));return s.join("")}case"CommandSubstitution":{let s=Bo(t.body);if(s)try{let p=await W(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 Ot(E,e.limits.maxStringLength,"command substitution"),E}catch(p){if(p instanceof $)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 $(`Command substitution nesting limit exceeded (${a})`,"substitution_depth");let o=e.substitutionDepth;e.substitutionDepth=i+1;let l=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let c=new Map(e.state.env),u=ct(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=c,e.state.arrays=u,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 Ot(m,e.limits.maxStringLength,"command substitution"),m}catch(p){if(e.state.env=c,e.state.arrays=u,e.state.cwd=f,e.state.bashPid=l,e.substitutionDepth=o,e.state.suppressVerbose=d,p instanceof $)throw p;if(p instanceof j){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 Ot(h,e.limits.maxStringLength,"command substitution"),h}throw p}}case"ArithmeticExpansion":{let s=t.expression.originalText;if(s&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(s)){let a=await Mo(e,s),o=new V,l=ne(o,a);return String(await Z(e,l.expression,!0))}return String(await Z(e,t.expression.expression,!0))}case"BraceExpansion":{let s=[];for(let i of t.items)if(i.type==="Range"){let a=Js(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 W(e,i.word));return s.join(" ")}default:return""}}async function Pr(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 Xs(e,p);r=`${d}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ae(e,r)){let d=Re(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 Xs(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 dt(e,r),{isEmpty:c,effectiveValue:u}=Jo(e,r,o,n),f={value:o,isUnset:l,isEmpty:c,effectiveValue:u,inDoubleQuotes:n};switch(s.type){case"DefaultValue":return Fo(e,s,f,it);case"AssignDefault":return Vo(e,r,s,f,it);case"ErrorIfUnset":return zo(e,r,s,f,it);case"UseAlternative":return qo(e,s,f,it);case"PatternRemoval":{let d=await Uo(e,o,s,it,He);return Ot(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await jo(e,o,s,it,He);return Ot(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return Go(e,r,o);case"LengthSliceError":throw new je(r);case"BadSubstitution":throw new je(s.text);case"Substring":return Zo(e,r,o,s);case"CaseModification":{let d=await Ho(e,o,s,it,Pr);return Ot(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return Qo(e,r,o,l,s);case"Indirection":return Ko(e,r,o,l,s,Pr,n);case"ArrayKeys":return Xo(e,s);case"VarNamePrefix":return Yo(e,s);default:return o}}function jl(){return{visited:new Set,depth:0}}function id(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new ie("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new ie("division by 0");return e%t;case"**":if(t<0)throw new ie("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 Ul(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 ad(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function od(e,t){let n=e.state.env.get(t);if(n!==void 0)return n;let r=se(e,t,0);return r!==void 0?r:await re(e,t)}async function ld(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 V,{expr:a,pos:o}=pn(i,s,0);if(o<s.length){let l=s.slice(o).trim(),c=l.split(/\s+/)[0]||l;throw new ie(`syntax error in expression (error token is "${c}")`,"","")}return await yn(e,a,!1,n)}async function Rr(e,t,n,r){if(r.depth>100)throw new ie("maximum variable indirection depth exceeded");if(r.visited.has(t))throw new ie(`arithmetic variable cycle detected at ${t}`);r.visited.add(t),r.depth++;try{return await ld(e,n,r)}finally{r.depth--,r.visited.delete(t)}}async function ai(e,t,n){if(n.depth>100)throw new ie("maximum variable indirection depth exceeded");if(n.visited.has(t))throw new ie(`arithmetic variable cycle detected at ${t}`);n.visited.add(t),n.depth++;try{let r=await od(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 ai(e,i,n);let a=new V,{expr:o,pos:l}=pn(a,i,0);if(l<i.length){let c=i.slice(l).trim(),u=c.split(/\s+/)[0]||c;throw new ie(`${i}: syntax error in expression (error token is "${u}")`)}return await yn(e,o,!1,n)}finally{n.depth--,n.visited.delete(t)}}async function Ir(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,c=o==="",u=s.startsWith(":");switch(s){case":-":case"-":return l||u&&c?a:o||"";case":=":case"=":return l||u&&c?(e.state.env.set(i,a),a):o||"";case":+":case"+":return!(l||u&&c)?a:"";case":?":case"?":{if(l||u&&c)throw new Error(a||`${i}: parameter null or not set`);return o||""}default:return o||""}}async function Z(e,t,n=!1){return yn(e,t,n,jl())}async function yn(e,t,n,r){let s=(i,a=n)=>yn(e,i,a,r);switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new ie("value too great for base");return t.value;case"ArithVariable":return await ai(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 V,{expr:c}=pn(l,a,0);return await s(c)}case"ArithNested":return await s(t.expression);case"ArithCommandSubst":{if(e.execFn){let i=await e.execFn(t.command,{signal:e.state.signal});i.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+i.stderr);let a=i.stdout.trim();return Number.parseInt(a,10)||0}return 0}case"ArithBracedExpansion":{let i=await Ir(e,t.content);return Number.parseInt(i,10)||0}case"ArithDynamicBase":{let i=await Ir(e,t.baseExpr),a=Number.parseInt(i,10);if(a<2||a>64)return 0;let o=`${a}#${t.value}`;return _n(o)}case"ArithDynamicNumber":{let a=await Ir(e,t.prefix)+t.suffix;return _n(a)}case"ArithArrayElement":{let i=e.state.associativeArrays?.has(t.array),a=async o=>{let l=se(e,t.array,o);return l!==void 0?await Rr(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 u=z(e,t.array),f=e.state.currentLine;if(u.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
83
- `,0;let p=Math.max(...u.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
84
- `,0;o=p}let l=`${t.array}[${o}]`,c=se(e,t.array,o);if(c!==void 0)return Rr(e,l,c,r);if(o===0){let u=e.state.env.get(t.array);if(u!==void 0)return Rr(e,t.array,u,r)}if(e.state.options.nounset&&!(e.state.env.has(t.array)||$e(e,t.array)))throw new Le(`${t.array}[${o}]`);return 0}return 0}case"ArithDoubleSubscript":throw new ie("double subscript","","");case"ArithNumberSubscript":throw new ie(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new ie(t.message,"","",!0);case"ArithSingleQuote":{if(n)throw new ie(`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 id(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 c=Number.parseInt(se(e,a,l)||"0",10)||0,u=t.operator==="++"?c+1:c-1;return F(e,a,l,String(u),o?"associative":"indexed"),t.prefix?u:c}if(t.operand.type==="ArithConcat"){let a="";for(let o of t.operand.parts)a+=await mn(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 mn(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(se(e,a,o)||"0",10)||0,c=t.operator==="++"?l+1:l-1;return F(e,a,o,String(c)),t.prefix?c:l}}return i}return ad(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):se(e,i,o),c=Number.parseInt(l||"0",10)||0,u=await s(t.value),f=Ul(c,u,t.operator);return o===void 0?e.state.env.set(a,String(f)):F(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 mn(e,a,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)?await ai(e,i,r):Number.parseInt(i,10)||0}case"ArithDynamicAssignment":{let i="";if(t.target.type==="ArithConcat")for(let u of t.target.parts)i+=await mn(e,u,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 u=await s(t.subscript);a=`${i}_${u}`}let o=Number.parseInt(e.state.env.get(a)||"0",10)||0,l=await s(t.value),c=Ul(o,l,t.operator);return e.state.env.set(a,String(c)),c}case"ArithDynamicElement":{let i="";if(t.nameExpr.type==="ArithConcat")for(let c of t.nameExpr.parts)i+=await mn(e,c,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?Rr(e,o,l,r):0}default:return 0}}async function mn(e,t,n=!1,r=jl()){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await yn(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 Ir(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command,{signal:e.state.signal})).stdout.trim():"0";case"ArithConcat":{let s="";for(let i of t.parts)s+=await mn(e,i,n,r);return s}default:return String(await yn(e,t,n,r))}}async function Gl(e,t){let n="",r=0;for(let v of t.parts){let A=v.type==="Literal"?v.value:"\0",x=T(A);if(x>e.limits.maxStringLength-r)throw new $(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n+=A,r+=x}let s=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!s||!n.endsWith(")"))return null;let i=s[1],a=[],o=[],l=!1,c="",u=0,f=0,d=!1,p=!0,h=v=>{let A=T(v);if(A>e.limits.maxStringLength-f-u)throw new $(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");c+=v,u+=A},m=(v,A=!1)=>{if(a.length>=e.limits.maxArrayElements)throw new $(`array assignment element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let x=T(v);if(x>e.limits.maxStringLength-f)throw new $(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");a.push(v),o.push(A),f+=x},E=()=>{m(c,p),c="",u=0,d=!1,p=!0};for(let v of t.parts)if(v.type==="Literal"){let A=v.value;if(!l){let x=A.indexOf("=(");x!==-1&&(l=!0,A=A.slice(x+2))}if(l){A.endsWith(")")&&(A=A.slice(0,-1));for(let x of A)/\s/.test(x)?(c||d)&&E():h(x)}}else if(l)if(v.type==="BraceExpansion")if(/^\[.+\]=/.test(c))h(fn({type:"Word",parts:[v]}));else{(c||d)&&E();let x=await at(e,{type:"Word",parts:[v]});for(let P of x.values)m(P)}else{(v.type==="SingleQuoted"||v.type==="DoubleQuoted"||v.type==="Escaped")&&(d=!0),p=!1;let A=await W(e,{type:"Word",parts:[v]});h(A)}(c||d)&&E();let b=a.splice(0),g=o.splice(0);f=0;for(let v=0;v<b.length;v++){let A=b[v];if(!g[v]){m(A);continue}let x=A.match(/^(\[[^\]]+\]=)(.*)$/s);if(x){let P=_t(e,x[2]);A=x[1]+P}if(A.includes("{")&&A.includes("}")){let P=new V().parseWordFromString(A,!1,!1);if(P.parts.some(D=>D.type==="BraceExpansion")){let D=await at(e,P);for(let I of D.values)m(I);continue}}m(A)}let w=[`${i}=(`],S=T(w[0]);for(let v=0;v<a.length;v++){let A=a[v],x;/^\[.+\]=/.test(A)?x=A:A===""?x="''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(A)&&!A.startsWith("'")&&!A.startsWith('"')?x=`'${A.replace(/'/g,"'\\''")}'`:x=A;let P=`${v>0?" ":""}${x}`,D=T(P);if(D+1>e.limits.maxStringLength-S)throw new $(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");w.push(P),S+=D}return w.push(")"),w.join("")}async function Zl(e,t){let n=-1,r=-1,s=!1;for(let m=0;m<t.parts.length;m++){let E=t.parts[m];if(E.type==="Literal"){let b=E.value.indexOf("+=");if(b!==-1){let w=E.value.slice(0,b);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(w)){n=m,r=b,s=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(w)){n=m,r=b,s=!0;break}}let g=E.value.indexOf("=");if(g!==-1&&(g===0||E.value[g-1]!=="+")){let w=E.value.slice(0,g);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(w)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(w)){n=m,r=g;break}}}}if(n===-1)return null;let i=t.parts.slice(0,n),a=t.parts[n];if(a.type!=="Literal")return null;let o=s?2:1,l=a.value.slice(0,r),c=a.value.slice(r+o),u=t.parts.slice(n+1),f="";for(let m of i)f+=await W(e,{type:"Word",parts:[m]});f+=l;let d={type:"Word",parts:c!==""?[{type:"Literal",value:c},...u]:u},p=d.parts.length>0?await W(e,d):"";return`${f}${s?"+=":"="}${p}`}var cd=["tar","yq","xan","sqlite3","python3","python"];function Hl(e){return cd.includes(e)}var te=Object.freeze({stdout:"",stderr:"",exitCode:0});function X(e=""){return{stdout:e,stderr:"",exitCode:0}}function R(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function _(e,t,n){return{stdout:e,stderr:t,exitCode:n}}function ye(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function Lt(e,t,n="",r=""){throw new $(e,t,n,r)}function Ve(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new $(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function oi(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new St;return te}if(t.length>1)throw new j(1,"",`bash: break: too many arguments
85
- `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new j(128,"",`bash: break: ${t[0]}: numeric argument required
86
- `);n=r}throw new qe(n)}async function li(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!=="."),c="";for(let f of l)if(f==="..")c=c.split("/").slice(0,-1).join("/")||"/";else{c=c?`${c}/${f}`:`/${f}`;try{if(!(await e.fs.stat(c)).isDirectory)return R(`bash: cd: ${n}: Not a directory
87
- `)}catch{return R(`bash: cd: ${n}: No such file or directory
88
- `)}}let u=c||"/";if(s)try{u=await e.fs.realpath(u)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=u,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),X(r?`${u}
89
- `:"")}function ci(e,t){return e.fs.resolvePath(e.state.cwd,t)}var ud=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function _r(e){return ud.includes(e)}async function Or(e,t,n){let r=ci(e,n);switch(t){case"-e":case"-a":return e.fs.exists(r);case"-f":return await e.fs.exists(r)?(await e.fs.stat(r)).isFile:!1;case"-d":return await e.fs.exists(r)?(await e.fs.stat(r)).isDirectory:!1;case"-r":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&256)!==0:!1;case"-w":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&128)!==0:!1;case"-x":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&64)!==0:!1;case"-s":return await e.fs.exists(r)?(await e.fs.stat(r)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(r)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&512)!==0:!1;case"-g":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(r);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].includes(r);case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(r);default:return!1}}var fd=["-nt","-ot","-ef"];function Lr(e){return fd.includes(e)}async function Tr(e,t,n,r){let s=ci(e,n),i=ci(e,r);switch(t){case"-nt":{let[a,o]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return a!==null&&(o===null||a.mtime>o.mtime)}case"-ot":{let[a,o]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return o!==null&&(a===null||a.mtime<o.mtime)}case"-ef":try{let[a,o]=await Promise.all([e.fs.realpath(s),e.fs.realpath(i)]);if(a===o)return!0;let[l,c]=await Promise.all([e.fs.stat(s),e.fs.stat(i)]);return l.dev!==void 0&&l.ino!==void 0&&c.dev!==void 0&&c.ino!==void 0?l.dev===c.dev&&l.ino===c.ino:l.identity&&c.identity?l.identity===c.identity:!1}catch{return!1}default:return!1}}var dd=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function Mr(e){return dd.has(e)}function Br(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 Vn(e){return e==="="||e==="=="||e==="!="}function Wr(e,t,n,r=!1,s=!1,i=!1,a=256){if(r){let l=gn(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 pd=new Set(["-z","-n"]);function Fr(e){return pd.has(e)}function Vr(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function zr(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let r=n[1],s=n[2];if(e.state.associativeArrays?.has(r)){let o=s;return(o.startsWith("'")&&o.endsWith("'")||o.startsWith('"')&&o.endsWith('"'))&&(o=o.slice(1,-1)),o=o.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(l,c)=>e.state.env.get(c)||""),Nt(e,r,o)}let a;try{let o=new V,l=ne(o,s);a=await Z(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=Ee(e,r),l=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
90
- `,!1;if(a=Math.max(...o)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
91
- `,!1}return Nt(e,r,a)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?ut(e,t).length>0:Ee(e,t).length>0}async function Tt(e,t){switch(t.type){case"CondBinary":{let n=await W(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 W(e,t.right);s=Bn(i)}else s=await Wl(e,t.right);else Vn(t.operator)&&!r?s=await Fl(e,t.right):s=await W(e,t.right);if(Vn(t.operator)){let i=e.state.shoptOptions.nocasematch;return Wr(t.operator,n,s,!r,i,!0,e.limits.maxCallDepth)}if(Mr(t.operator))return Br(t.operator,await Kl(e,n),await Kl(e,s));if(Lr(t.operator))return Tr(e,t.operator,n,s);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=wd(s),l=he(a,i?"i":"").match(n);if(me(e,"BASH_REMATCH"),l)for(let c=0;c<l.length;c++)F(e,"BASH_REMATCH",c,l[c]||"");return l!==null}catch{throw new Error("syntax error in regular expression")}case"<":return n<s;case">":return n>s;default:return!1}}case"CondUnary":{let n=await W(e,t.operand);return _r(t.operator)?Or(e,t.operator,n):Fr(t.operator)?Vr(t.operator,n):t.operator==="-v"?await zr(e,n):t.operator==="-o"?fi(e,n):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await W(e,t.operand.expression.word)})`!=="":!await Tt(e,t.operand);case"CondAnd":return await Tt(e,t.left)?await Tt(e,t.right):!1;case"CondOr":return await Tt(e,t.left)?!0:await Tt(e,t.right);case"CondGroup":return await Tt(e,t.expression);case"CondWord":return await W(e,t.word)!=="";default:return!1}}async function zn(e,t){if(t.length===0)return _("","",1);if(t.length===1)return ye(!!t[0]);if(t.length===2){let r=t[0],s=t[1];return r==="("?R(`test: '(' without matching ')'
92
- `,2):_r(r)?ye(await Or(e,r,s)):Fr(r)?ye(Vr(r,s)):r==="!"?ye(!s):r==="-v"?ye(await zr(e,s)):r==="-o"?ye(fi(e,s)):r==="="||r==="=="||r==="!="||r==="<"||r===">"||r==="-eq"||r==="-ne"||r==="-lt"||r==="-le"||r==="-gt"||r==="-ge"||r==="-nt"||r==="-ot"||r==="-ef"?R(`test: ${r}: unary operator expected
93
- `,2):_("","",1)}if(t.length===3){let r=t[0],s=t[1],i=t[2];if(Vn(s))return ye(Wr(s,r,i));if(Mr(s)){let a=qr(r),o=qr(i);return!a.valid||!o.valid?_("","",2):ye(Br(s,a.value,o.value))}if(Lr(s))return ye(await Tr(e,s,r,i));switch(s){case"-a":return ye(r!==""&&i!=="");case"-o":return ye(r!==""||i!=="");case">":return ye(r>i);case"<":return ye(r<i)}if(r==="!"){let a=await zn(e,[s,i]);return _("",a.stderr,a.exitCode===0?1:a.exitCode===1?0:a.exitCode)}if(r==="("&&i===")")return ye(s!=="")}if(t.length===4){if(t[0]==="!"){let r=await zn(e,t.slice(1));return _("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(t[0]==="("&&t[3]===")")return zn(e,[t[1],t[2]])}let n=await Yl(e,t,0);return n.pos<t.length?R(`test: too many arguments
94
- `,2):ye(n.value)}async function Yl(e,t,n){return hd(e,t,n)}async function hd(e,t,n){let{value:r,pos:s}=await Ql(e,t,n);for(;t[s]==="-o";){let i=await Ql(e,t,s+1);r=r||i.value,s=i.pos}return{value:r,pos:s}}async function Ql(e,t,n){let{value:r,pos:s}=await ui(e,t,n);for(;t[s]==="-a";){let i=await ui(e,t,s+1);r=r&&i.value,s=i.pos}return{value:r,pos:s}}async function ui(e,t,n){let r=e.executionScope.enterDepth("test_expression",e.limits.maxCallDepth,"test expression");try{if(t[n]==="!"){let{value:s,pos:i}=await ui(e,t,n+1);return{value:!s,pos:i}}return md(e,t,n)}finally{r.release()}}async function md(e,t,n){let r=t[n];if(r==="("){let{value:i,pos:a}=await Yl(e,t,n+1);return{value:i,pos:t[a]===")"?a+1:a}}let s=t[n+1];if(Vn(s)){let i=r,a=t[n+2]??"";return{value:Wr(s,i,a),pos:n+3}}if(Mr(s)){let i=qr(r),a=qr(t[n+2]??"0");return!i.valid||!a.valid?{value:!1,pos:n+3}:{value:Br(s,i.value,a.value),pos:n+3}}if(Lr(s)){let i=r,a=t[n+2]??"";return{value:await Tr(e,s,i,a),pos:n+3}}if(_r(r)){let i=t[n+1]??"";return{value:await Or(e,r,i),pos:n+2}}if(Fr(r)){let i=t[n+1]??"";return{value:Vr(r,i),pos:n+2}}if(r==="-v"){let i=t[n+1]??"";return{value:await zr(e,i),pos:n+2}}if(r==="-o"){let i=t[n+1]??"";return{value:fi(e,i),pos:n+2}}return{value:r!==void 0&&r!=="",pos:n+1}}function gn(e,t,n=!1,r=!1,s=256){r&&yd(t,s);let i=`^${Jl(t,r)}$`;return he(i,n?"is":"s").test(e)}function yd(e,t){let n=0,r=[];for(let s=0;s<e.length;s++){if(e[s]==="\\"){s++;continue}if(e[s]==="("){let i=s>0&&"@*+?!".includes(e[s-1]);if(r.push(i),i&&n++,n>t)throw new $(`extglob maximum depth (${t}) exceeded`,"recursion")}else e[s]===")"&&r.length>0&&r.pop()&&n--}}function Jl(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=ec(e,r+1);if(i!==-1){let a=e.slice(r+2,i),o=tc(a),l=o.map(u=>Jl(u,t)),c=l.length>0?l.join("|"):"(?:)";if(s==="@")n+=`(?:${c})`;else if(s==="*")n+=`(?:${c})*`;else if(s==="+")n+=`(?:${c})+`;else if(s==="?")n+=`(?:${c})?`;else if(s==="!")if(i<e.length-1){let f=o.map(p=>nc(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(`(?!(?:${c})).{${p}}`),n+=`(?:${h.join("|")})`}}else n+=`(?:(?!(?:${c})).)*?`}else n+=`(?!(?:${c})$).*`;r=i;continue}}if(s==="\\")if(r+1<e.length){let i=e[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?n+=`\\${i}`:n+=i,r++}else n+="\\\\";else if(s==="*")n+=".*";else if(s==="?")n+=".";else if(s==="["){let i=e.indexOf("]",r+1);i!==-1?(n+=e.slice(r,i+1),r=i):n+="\\["}else/[\\^$.|+(){}]/.test(s)?n+=`\\${s}`:n+=s}return n}function ec(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 tc(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 nc(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=ec(e,r+1);if(i!==-1){if(s==="@"){let a=e.slice(r+2,i),l=tc(a).map(c=>nc(c,t));if(l.every(c=>c!==null)&&l.every(c=>c===l[0])){n+=l[0],r=i+1;continue}return null}return null}}if(s==="*")return null;if(s==="?"){n+=1,r++;continue}if(s==="["){let i=e.indexOf("]",r+1);if(i!==-1){n+=1,r=i+1;continue}n+=1,r++;continue}if(s==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}function fi(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 Kl(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 Xl(t);try{let n=new V,r=ne(n,t);return await Z(e,r.expression)}catch{return Xl(t)}}function gd(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 Xl(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=gd(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 qr(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 wd(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=Ed(e,n);t+=r.converted,n=r.endIndex}else t+=e[n],n++;return t}function Ed(e,t){let n=t+1,r="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(r+="^",n++);let s=!1;n<e.length&&e[n]==="]"&&(s=!0,n++);let i=!1;n<e.length&&e[n]==="["&&n+1<e.length&&e[n+1]!==":"&&(i=!0,n++);let a="",o=!1;for(;n<e.length;){let l=e[n];if(l==="]"){o=!0,n++;break}if(l==="["&&n+1<e.length&&e[n+1]===":"){let c=e.indexOf(":]",n+2);if(c!==-1){let u=e.slice(n+2,c);a+=bd(u),n=c+2;continue}}if(l==="["&&n+1<e.length){let c=e[n+1];if(c==="."||c==="="){let u=`${c}]`,f=e.indexOf(u,n+2);if(f!==-1){let d=e.slice(n+2,f);a+=d,n=f+2;continue}}}if(l==="\\"&&n+1<e.length){a+=l+e[n+1],n+=2;continue}a+=l,n++}return o?(s&&(r+="\\]"),i&&(r+="\\["),r+=a,r+="]",{converted:r,endIndex:n}):{converted:"\\[",endIndex:t+1}}function bd(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 di(e,t,n){if(n&&e.length>=n.maxElements)throw new $(`array element limit exceeded (${n.maxElements})`,"array_elements");e.push(t)}function Et(e,t){if(t&&T(e)>t.maxStringBytes)throw new $(`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===`
95
- `)&&!s&&!i){o&&(di(n,r,t),r="",o=!1);continue}r+=l,o=!0}return o&&di(n,r,t),n}function Ur(e,t){if(t&&T(e)>t.maxStringBytes)throw new $(`array assignment string limit exceeded (${t.maxStringBytes} bytes)`,"string_length");let n=[],r=0;for(;r<e.length;){for(;r<e.length&&/\s/.test(e[r]);)r++;if(r>=e.length)break;if(e[r]!=="["){r++;continue}r++;let s="";if(e[r]==="'"||e[r]==='"'){let 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++;di(n,[s,i],t)}return n}function rc(e,t){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(n)return{name:n[1],isArray:!0,arrayElements:Et(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 Sd(e,t){try{let n=new V,r=ne(n,t);return await Z(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}async function sc(e,t,n={}){let{name:r,isArray:s,arrayElements:i,value:a,arrayIndex:o}=t,{makeReadonly:l=!1,checkReadonly:c=!0}=n;if(c){let u=oe(e,r);if(u)return u}if(s&&i){e.executionScope.consumeWork(i.length,"array assignment");let u=Se(e,r),f=u?De(u):void 0,d=e.state.env.get(r);try{me(e,r);for(let p=0;p<i.length;p++)F(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 u=await Sd(e,o);F(e,r,u,a)}else a!==void 0&&e.state.env.set(r,a);return l&&Fe(e,r),null}function Mt(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function pi(e,t){return e.state.localVarDepth?.get(t)}function jr(e,t){e.state.localVarDepth?.delete(t)}function ic(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 Gr(e,t){let n=e.state.localVarStack?.get(t);if(!(!n||n.length===0))return n.pop()}function ac(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 hi=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function oc(e){return hi.has(e)}var mi=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),wn=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);var Zr=class extends Error{};async function qn(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
38
+ `){o+=2,l=1,u++;continue}c+=y+S,o+=2,l+=2;continue}}else{c+=y+S,o+=2,l+=2;continue}}if(y==="$"&&o+1<i&&s[o+1]==="("&&!p){c+=y,o++,l++,c+=s[o],o++,l++;let S=1,v=!1,x=!1,A=0,C=!1,N="",$=[],P=s[o]==="("&&!this.dollarDparenIsSubshell(o),R=P?1:0;for(;S>0&&o<i;){let B=s[o];if(c+=B,v)B==="'"&&(v=!1);else if(x)B==="\\"&&o+1<i?(c+=s[o+1],o++,l++):B==='"'&&(x=!1);else{if(B==="("&&s[o+1]==="("?R++:B===")"&&s[o+1]===")"&&R>0&&R--,R===0&&B==="<"&&s[o+1]==="<"&&s[o+2]!=="<"){let q=o+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(o+1,V),l+=V-o,$.push({delim:W,stripTabs:D}),o=V;continue}}if(B===`
39
+ `&&$.length>0){u++,l=0;let q=o+1;for(let{delim:D,stripTabs:W}of $)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}$.length=0,l=0,o=Math.min(q,i);continue}if(B==="'")v=!0,N="";else if(B==='"')x=!0,N="";else if(B==="\\"&&o+1<i)c+=s[o+1],o++,l++,N="";else if(B==="$"&&o+1<i&&s[o+1]==="{"){o++,l++,c+=s[o],o++,l++;let q=1,D=!1,W=!1;for(;q>0&&o<i;){let V=s[o];if(V==="\\"&&o+1<i&&!D){c+=V,o++,l++,c+=s[o],o++,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++,o++}N="";continue}else if(B==="#"&&!P&&(N===""||/\s/.test(s[o-1]||""))){for(;o+1<i&&s[o+1]!==`
42
+ `;)o++,l++,c+=s[o];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==="("?o>0&&s[o-1]==="$"?S++:C||S++:B===")"?C?C=!1:S--:B===";"&&A>0&&(o+1<i&&s[o+1]===";"||o+1<i&&s[o+1]==="&")&&(C=!0))}B===`
43
+ `&&(u++,l=0,N=""),o++,l++}continue}if(y==="$"&&o+1<i&&s[o+1]==="["&&!p){c+=y,o++,l++,c+=s[o],o++,l++;let S=1;for(;S>0&&o<i;){let v=s[o];c+=v,v==="["?S++:v==="]"?S--:v===`
44
+ `&&(u++,l=0),o++,l++}continue}if(y==="$"&&o+1<i&&s[o+1]==="{"&&!p){c+=y,o++,l++,c+=s[o],o++,l++;let S=1,v=!1,x=!1,A=u,C=l,N=u,$=l;for(;S>0&&o<i;){let P=s[o];if(P==="\\"&&o+1<i&&s[o+1]===`
45
+ `){o+=2,u++,l=1;continue}if(P==="\\"&&o+1<i&&!v){c+=P,o++,l++,c+=s[o],o++,l++;continue}c+=P,v?P==="'"&&(v=!1):x?P==='"'&&(x=!1):P==="'"?(v=!0,A=u,C=l):P==='"'?(x=!0,N=u,$=l):P==="{"?S++:P==="}"&&S--,P===`
46
+ `&&(u++,l=0),o++,l++}if(v)throw new Qe("unexpected EOF while looking for matching `''",A,C);if(x)throw new Qe("unexpected EOF while looking for matching `\"'",N,$);continue}if(y==="$"&&o+1<i&&!p){let S=s[o+1];if(S==="#"||S==="?"||S==="$"||S==="!"||S==="@"||S==="*"||S==="-"||S>="0"&&S<="9"){c+=y+S,o+=2,l+=2;continue}}if(y==="`"&&!p){for(c+=y,o++,l++;o<i&&s[o]!=="`";){let S=s[o];c+=S,S==="\\"&&o+1<i&&(c+=s[o+1],o++,l++),S===`
47
+ `&&(u++,l=0),o++,l++}o<i&&(c+=s[o],o++,l++);continue}c+=y,o++,y===`
48
+ `?(u++,l=1):l++}if(this.pos=o,this.column=l,this.line=u,E&&m&&(c=s[t]+c,f=!1,d=!1),p||h){let 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:o,line:n,column:r,quoted:f,singleQuoted:d};let g=Us.get(c);if(!f&&g!==void 0)return{type:g,value:c,start:t,end:o,line:n,column:r};if(!m){let y=xa(c);if(y>0&&va(c.slice(0,y)))return{type:w.ASSIGNMENT_WORD,value:c,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(c)?{type:w.NUMBER,value:c,start:t,end:o,line:n,column:r}:jf(c)?{type:w.NAME,value:c,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}:{type:w.WORD,value:c,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let n=this.pos,r=this.line,s=this.column,i="",o=!1;for(;this.pos<this.input.length;){let a="",l="",u="";for(;;){for(a="";this.pos<this.input.length&&this.input[this.pos]!==`
49
+ `;)a+=this.input[this.pos],this.pos++,this.column++;let f=0;for(let d=a.length-1;a[d]==="\\";d-=1)f+=1;if(u+=a,t.quoted||f%2===0||this.pos+1>=this.input.length)break;u=u.slice(0,-1),l+=`${a}
50
+ `,this.pos++,this.line++,this.column=1}if((t.stripTabs?u.replace(/^\t+/,""):u)===t.delimiter){o=!0,this.pos<this.input.length&&this.input[this.pos]===`
51
+ `&&(this.pos++,this.line++,this.column=1);break}if(i+=l,i+=a,this.pos<this.input.length&&this.input[this.pos]===`
52
+ `?(i+=`
53
+ `,this.pos++,this.line++,this.column=1):a.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:o})}}readHeredocDelimiterToken(t,n,r,s){let i=this.input,{delim:o,endPos:a,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(a===t)throw new Qe("Expected here-document delimiter",n,r);let f=n,d=r;for(let p=t;p<a;p++)i[p]===`
55
+ `?(f+=1,d=1):d+=1;return this.pos=a,this.line=f,this.column=d,this.pendingHeredocs.push({delimiter:o,stripTabs:s,quoted:l}),{type:w.WORD,value:i.slice(t,a),start:t,end:a,line:n,column:r,quoted:l,heredocDelimiter:o}}isWordCharFollowing(t){if(t>=this.input.length)return!1;let n=this.input[t];return!(n===" "||n===" "||n===`
56
+ `||n===";"||n==="&"||n==="|"||n==="("||n===")"||n==="<"||n===">")}readWordWithBraceExpansion(t,n,r){let s=this.input,i=s.length,o=t,a=r;for(;o<i;){let u=s[o];if(u===" "||u===" "||u===`
57
+ `||u===";"||u==="&"||u==="|"||u==="("||u===")"||u==="<"||u===">")break;if(u==="{"){if(this.scanBraceExpansion(o)!==null){let f=1;for(o++,a++;o<i&&f>0;)s[o]==="{"?f++:s[o]==="}"&&f--,o++,a++;continue}o++,a++;continue}if(u==="}"){o++,a++;continue}if(u==="$"&&o+1<i&&s[o+1]==="("){o++,a++,o++,a++;let c=1;for(;c>0&&o<i;)s[o]==="("?c++:s[o]===")"&&c--,o++,a++;continue}if(u==="$"&&o+1<i&&s[o+1]==="{"){o++,a++,o++,a++;let c=1;for(;c>0&&o<i;)s[o]==="{"?c++:s[o]==="}"&&c--,o++,a++;continue}if(u==="`"){for(o++,a++;o<i&&s[o]!=="`";)s[o]==="\\"&&o+1<i?(o+=2,a+=2):(o++,a++);o<i&&(o++,a++);continue}o++,a++}let l=s.slice(t,o);return this.pos=o,this.column=a,{type:w.WORD,value:l,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}}scanBraceExpansion(t){let n=this.input,r=n.length,s=t+1,i=1,o=!1,a=!1;for(;s<r&&i>0;){let l=n[s];if(l==="{")i++,s++;else if(l==="}")i--,s++;else if(l===","&&i===1)o=!0,s++;else if(l==="."&&s+1<r&&n[s+1]===".")a=!0,s+=2;else{if(l===" "||l===" "||l===`
58
+ `||l===";"||l==="&"||l==="|")return null;s++}}return i===0&&(o||a)?n.slice(t,s):null}scanLiteralBraceWord(t){let n=this.input,r=n.length,s=t+1,i=1;for(;s<r&&i>0;){let o=n[s];if(o==="{")i++,s++;else if(o==="}"){if(i--,i===0)return n.slice(t,s+1);s++}else{if(o===" "||o===" "||o===`
59
+ `||o===";"||o==="&"||o==="|")return null;s++}}return null}scanExtglobPattern(t){let n=this.input,r=n.length,s=t+1,i=1;for(;s<r&&i>0;){let o=n[s];if(o==="\\"&&s+1<r){s+=2;continue}if("@*+?!".includes(o)&&s+1<r&&n[s+1]==="("){s++,i++,s++;continue}if(o==="(")i++,s++;else if(o===")")i--,s++;else{if(o===`
60
+ `)return null;s++}}return i===0?{content:n.slice(t,s),end:s}:null}scanFdVariable(t){let n=this.input,r=n.length,s=t+1,i=s;for(;s<r;){let c=n[s];if(s===i){if(!(c>="a"&&c<="z"||c>="A"&&c<="Z"||c==="_"))return null}else if(!(c>="a"&&c<="z"||c>="A"&&c<="Z"||c>="0"&&c<="9"||c==="_"))break;s++}if(s===i)return null;let o=n.slice(i,s);if(s>=r||n[s]!=="}"||(s++,s>=r))return null;let a=n[s],l=s+1<r?n[s+1]:"";return a===">"||a==="<"||a==="&"&&(l===">"||l==="<")?{varname:o,end:s}:null}dollarDparenIsSubshell(t){let n=this.input,r=n.length,s=t+1,i=2,o=!1,a=!1,l=!1;for(;s<r&&i>0;){let u=n[s];if(o){u==="'"&&(o=!1),u===`
61
+ `&&(l=!0),s++;continue}if(a){if(u==="\\"){s+=2;continue}u==='"'&&(a=!1),u===`
62
+ `&&(l=!0),s++;continue}if(u==="'"){o=!0,s++;continue}if(u==='"'){a=!0,s++;continue}if(u==="\\"){s+=2;continue}if(u===`
63
+ `&&(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
+ `);)d=!0,f++;if(d&&f<r&&n[f]===")"||l)return!0}if(i===0)return!1;s++;continue}s++}return!1}dparenClosesWithSpacedParens(t){let n=this.input,r=n.length,s=t,i=2,o=!1,a=!1;for(;s<r&&i>0;){let l=n[s];if(o){l==="'"&&(o=!1),s++;continue}if(a){if(l==="\\"){s+=2;continue}l==='"'&&(a=!1),s++;continue}if(l==="'"){o=!0,s++;continue}if(l==='"'){a=!0,s++;continue}if(l==="\\"){s+=2;continue}if(l==="("){i++,s++;continue}if(l===")"){if(i--,i===1){let u=s+1;if(u<r&&n[u]===")")return!1;let c=u,f=!1;for(;c<r&&(n[c]===" "||n[c]===" "||n[c]===`
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 Gs=1e6,Hn=1e5,Gf=1e6,ka=200,Pe;(function(e){e[e.Default=0]="Default",e[e.Assignment=1]="Assignment",e[e.NoBraceExpansion=2]="NoBraceExpansion",e[e.Regex=4]="Regex"})(Pe||(Pe={}));var Pa=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]),Ca=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS]),Na=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS,w.AND_GREAT,w.AND_DGREAT]),xe=class extends Error{line;column;token;constructor(t,n,r,s=void 0){super(`Parse error at ${n}:${r}: ${t}`),this.line=n,this.column=r,this.token=s,this.name="ParseException"}},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>Gf)throw new xe("Maximum parse iterations exceeded (possible infinite loop)",t,n)}chargeTokens(t,n=1,r=1){if(this.tokens+=t,this.tokens>Hn)throw new xe(`Too many tokens: cumulative count exceeds limit of ${Hn}`,n,r)}enter(t,n){if(this.depth++,this.depth>ka)throw this.depth--,new xe(`Maximum parser nesting depth exceeded (${ka})`,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 o=0;for(let a of s){let l;if(/[0-9]/.test(a))l=a.charCodeAt(0)-48;else if(/[a-z]/.test(a))l=a.charCodeAt(0)-97+10;else if(/[A-Z]/.test(a))l=a.charCodeAt(0)-65+(i<=36?10:36);else if(a==="@")l=62;else if(a==="_")l=63;else return Number.NaN;if(l>=i)return Number.NaN;if(o=o*i+l,o>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return o}if(e.startsWith("0x")||e.startsWith("0X")){let n=Number.parseInt(e.slice(2),16);return n>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:n}if(e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)){if(/[89]/.test(e))return Number.NaN;let n=Number.parseInt(e,8);return n>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:n}let t=Number.parseInt(e,10);return t>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t}function Ra(e,t,n,r){if(n.slice(r,r+3)!=="$((")return null;let s=r+3,i=1,o=s;for(;s<n.length-1&&i>0;)n[s]==="("&&n[s+1]==="("?(i++,s+=2):n[s]===")"&&n[s+1]===")"?(i--,i>0&&(s+=2)):s++;let a=n.slice(o,s),{expr:l}=e(t,a,0);return s+=2,{expr:{type:"ArithNested",expression:l},pos:s}}function Da(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 Ia(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 Zf(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=Zf(t),{expr:r,pos:s}=kn(e,n,0),i=he(n,s);if(i<n.length){let o=t.slice(i).trim();if(o)return{type:"ArithmeticExpression",originalText:t,expression:{type:"ArithSyntaxError",errorToken:o,message:`${o}: syntax error: invalid arithmetic operator (error token is "${o}")`}}}return{type:"ArithmeticExpression",expression:r,originalText:t}}function 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 kn(e,t,n){return Hf(e,t,n)}function sn(e,t,n){return e.withDepth(()=>kn(e,t,n))}function Hf(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:o,pos:a}=Kn(e,t,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=he(t,a)}return{expr:r,pos:s}}function Kn(e,t,n){let{expr:r,pos:s}=Qf(e,t,n);if(s=he(t,s),t[s]==="?"){s++;let{expr:i,pos:o}=sn(e,t,s);if(s=he(t,o),t[s]===":"){s++;let{expr:a,pos:l}=sn(e,t,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:a},pos:l}}}return{expr:r,pos:s}}function Qf(e,t,n){let{expr:r,pos:s}=Oa(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="||";){if(s+=2,qe(t,s))return ze("||",s);let{expr:o,pos:a}=Oa(e,t,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=a}return{expr:r,pos:s}}function Oa(e,t,n){let{expr:r,pos:s}=_a(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="&&";){if(s+=2,qe(t,s))return ze("&&",s);let{expr:o,pos:a}=_a(e,t,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=a}return{expr:r,pos:s}}function _a(e,t,n){let{expr:r,pos:s}=La(e,t,n);for(;s=he(t,s),t[s]==="|"&&t[s+1]!=="|";){if(s++,qe(t,s))return ze("|",s);let{expr:o,pos:a}=La(e,t,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=a}return{expr:r,pos:s}}function La(e,t,n){let{expr:r,pos:s}=Ta(e,t,n);for(;s=he(t,s),t[s]==="^";){if(s++,qe(t,s))return ze("^",s);let{expr:o,pos:a}=Ta(e,t,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=a}return{expr:r,pos:s}}function Ta(e,t,n){let{expr:r,pos:s}=Ma(e,t,n);for(;s=he(t,s),t[s]==="&"&&t[s+1]!=="&";){if(s++,qe(t,s))return ze("&",s);let{expr:o,pos:a}=Ma(e,t,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=a}return{expr:r,pos:s}}function Ma(e,t,n){let{expr:r,pos:s}=Fa(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:o,pos:a}=Fa(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function Fa(e,t,n){let{expr:r,pos:s}=Zs(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:o,pos:a}=Zs(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else if(t[s]==="<"||t[s]===">"){let i=t[s];if(s++,qe(t,s))return ze(i,s);let{expr:o,pos:a}=Zs(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function Zs(e,t,n){let{expr:r,pos:s}=Ba(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:o,pos:a}=Ba(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function Ba(e,t,n){let{expr:r,pos:s}=Wa(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:o,pos:a}=Wa(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function Wa(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:o,pos:a}=Rr(e,t,s);r={type:"ArithBinary",operator:"*",left:r,right:o},s=a}else if(t[s]==="/"||t[s]==="%"){let i=t[s];if(s++,qe(t,s))return ze(i,s);let{expr:o,pos:a}=Rr(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function Rr(e,t,n){let{expr:r,pos:s}=Hs(e,t,n),i=he(t,s);if(t.slice(i,i+2)==="**"){if(i+=2,qe(t,i))return ze("**",i);let{expr:a,pos:l}=e.withDepth(()=>Rr(e,t,i));return{expr:{type:"ArithBinary",operator:"**",left:r,right:a},pos:l}}return{expr:r,pos:s}}function Hs(e,t,n){let r=he(t,n);if(t.slice(r,r+2)==="++"||t.slice(r,r+2)==="--"){let s=t.slice(r,r+2);r+=2;let{expr:i,pos:o}=e.withDepth(()=>Hs(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}if(t[r]==="+"||t[r]==="-"||t[r]==="!"||t[r]==="~"){let s=t[r];r++;let{expr:i,pos:o}=e.withDepth(()=>Hs(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}return Xf(e,t,r)}function Kf(e,t){let n=e[t];return n==="$"||n==="`"}function Xf(e,t,n){let{expr:r,pos:s}=Va(e,t,n,!1),i=[r];for(;Kf(t,s);){let{expr:a,pos:l}=Va(e,t,s,!0);i.push(a),s=l}i.length>1&&(r={type:"ArithConcat",parts:i});let o;if(t[s]==="["&&r.type==="ArithConcat"){s++;let{expr:a,pos:l}=sn(e,t,s);o=a,s=l,t[s]==="]"&&s++}if(o&&r.type==="ArithConcat"&&(r={type:"ArithDynamicElement",nameExpr:r,subscript:o},o=void 0),s=he(t,s),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let a of Nr)if(t.slice(s,s+a.length)===a&&t.slice(s,s+a.length+1)!=="=="){s+=a.length;let{expr:l,pos:u}=e.withDepth(()=>Kn(e,t,s));return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r.nameExpr,subscript:r.subscript,value:l},pos:u}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r,value:l},pos:u}:{expr:{type:"ArithAssignment",operator:a,variable:r.name,value:l},pos:u}}}if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let a=t.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:a,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function Va(e,t,n,r=!1){let s=he(t,n),i=Ra(sn,e,t,s);if(i)return i;let o=Da(t,s);if(o)return o;let a=Ia(t,s);if(a)return a;if(t.slice(s,s+2)==="$("&&t[s+2]!=="("){s+=2;let u=1,c=s;for(;s<t.length&&u>0;)t[s]==="("?u++:t[s]===")"&&u--,u>0&&s++;let f=t.slice(c,s);return s++,{expr:{type:"ArithCommandSubst",command:f},pos:s}}if(t[s]==="`"){s++;let u=s;for(;s<t.length&&t[s]!=="`";)s++;let c=t.slice(u,s);return t[s]==="`"&&s++,{expr:{type:"ArithCommandSubst",command:c},pos:s}}if(t[s]==="("){s++;let{expr:u,pos:c}=sn(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}=sn(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: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}=sn(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 Yf(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 Ua(e,t,n){let r=n+1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;return r}function Qs(e,t,n,r,s){let i=1,o=n+1;for(;o<t.length&&i>0;)t[o]===r?i++:t[o]===s&&i--,i>0&&o++;return i===0?o:-1}function 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 o=t.indexOf("'",r+1);if(o!==-1){r=o+1;continue}}if(i==='"'){for(r++;r<t.length&&t[r]!=='"';)t[r]==="\\"&&r+1<t.length?r+=2:r++;r<t.length&&r++;continue}i==="{"?s++:i==="}"&&s--,s>0&&r++}return r}function ja(e,t,n){let r=n,s=!1;for(;r<t.length;){let i=t[r];if(i==="/"&&s||i==="}")break;if(i==="'"){let o=t.indexOf("'",r+1);if(o!==-1){r=o+1,s=!0;continue}}if(i==='"'){for(r++;r<t.length&&t[r]!=='"';)t[r]==="\\"&&r+1<t.length?r+=2:r++;r<t.length&&r++,s=!0;continue}i==="\\"?(r+=2,s=!0):(r++,s=!0)}return r}function Ga(e,t,n){let r=n,s="";for(;r<t.length;){let i=t[r];if(i==="*"||i==="?")s+=i,r++;else if(i==="["){let o=Jf(t,r);o===-1?(s+=i,r++):(s+=t.slice(r,o+1),r=o+1)}else break}return{pattern:s,endIndex:r}}function Jf(e,t){let n=t+1;for(n<e.length&&e[n]==="^"&&n++,n<e.length&&e[n]==="]"&&n++;n<e.length;){let r=e[n];if(r==="\\"&&n+1<e.length){let s=e[n+1];if(s==='"'||s==="'")return-1;n+=2;continue}if(r==="]")return n;if(r==='"'||r==="$"||r==="`")return-1;if(r==="'"){let s=e.indexOf("'",n+1);if(s!==-1){n=s+1;continue}}if(r==="["&&n+1<e.length&&e[n+1]===":"){let s=e.indexOf(":]",n+2);if(s!==-1){n=s+2;continue}}if(r==="["&&n+1<e.length&&(e[n+1]==="."||e[n+1]==="=")){let i=`${e[n+1]}]`,o=e.indexOf(i,n+2);if(o!==-1){n=o+2;continue}}n++}return-1}function Za(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 a=[],l=s;for(;l+1<t.length&&t[l]==="\\"&&t[l+1]==="x";){let u=t.slice(l+2,l+4),c=parseInt(u,16);if(!Number.isNaN(c)&&u.length>0)a.push(c),l+=2+u.length;else break}a.length>0?(r+=Yf(a),s=l):(r+="\\x",s+=2);break}case"u":{let a=t.slice(s+2,s+6),l=parseInt(a,16);Number.isNaN(l)?(r+="\\u",s+=2):(r+=String.fromCharCode(l),s+=6);break}case"c":{if(s+2<t.length){let l=t[s+2].charCodeAt(0)&31;r+=String.fromCharCode(l),s+=3}else r+="\\c",s+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let a="",l=s+1;for(;l<t.length&&l<s+4&&/[0-7]/.test(t[l]);)a+=t[l],l++;let u=parseInt(a,8);r+=String.fromCharCode(u),s=l;break}default:r+=i,s++}else r+=i,s++}return s<t.length&&t[s]==="'"&&s++,{part:T.literal(r),endIndex:s}}function Ks(e,t){let n=t.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:te(e,n)}function qa(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 Ha(e,t,n,r){let s=Qs(e,t,n,"{","}");if(s===-1)return null;let i=t.slice(n+1,s),o=i.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(o)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(o[1],10),end:Number.parseInt(o[2],10),step:o[3]?Number.parseInt(o[3],10):void 0,startStr:o[1],endStr:o[2]}]},endIndex:s+1};let a=i.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return a?{part:{type:"BraceExpansion",items:[{type:"Range",start:a[1],end:a[2],step:a[3]?Number.parseInt(a[3],10):void 0}]},endIndex:s+1}:i.includes(",")&&r?{part:{type:"BraceExpansion",items:qa(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:qa(i).map(c=>({type:"Word",word:T.word([T.literal(c)])}))},endIndex:s+1}:null}function Xs(e,t){let n="";for(let r of t.parts)switch(r.type){case"Literal":n+=r.value;break;case"SingleQuoted":n+=`'${r.value}'`;break;case"Escaped":n+=r.value;break;case"DoubleQuoted":n+='"';for(let s of r.parts)s.type==="Literal"||s.type==="Escaped"?n+=s.value:s.type==="ParameterExpansion"&&(n+=`\${${s.parameter}}`);n+='"';break;case"ParameterExpansion":n+=`\${${r.parameter}}`;break;case"Glob":n+=r.pattern;break;case"TildeExpansion":n+="~",r.user&&(n+=r.user);break;case"BraceExpansion":{n+="{";let s=[];for(let i of r.items)if(i.type==="Range"){let o=i.startStr??String(i.start),a=i.endStr??String(i.end);i.step!==void 0?s.push(`${o}..${a}..${i.step}`):s.push(`${o}..${a}`)}else s.push(Xs(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 Qa(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:Ca.has(r.type)}if(n===w.FD_VARIABLE){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:Na.has(r.type)}return!e.isProcessSubstitutionStart()&&Pa.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=Qa(e,r.type);if(r.type===w.DLESS||r.type===w.DLESSDASH)return ed(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 ed(e,t,n,r){e.isWord()||e.error("Expected here-document delimiter");let s=e.advance(),i=s.heredocDelimiter??s.value,o=s.quoted||!1,a=T.redirection(r?"<<-":"<<",T.hereDoc(i,T.word([]),r,o),t,n);return e.addPendingHeredoc(a,i,r,o),a}function Js(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(td(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 a=e.advance();r=T.word([T.literal(a.value)])}for(;(!e.isStatementEnd()||e.check(w.RBRACE))&&!e.check(w.PIPE,w.PIPE_AMP);)if(e.checkIterationLimit(),Xn(e))i.push(Ir(e));else if(e.check(w.ASSIGNMENT_WORD)){let a=e.advance(),l=a.value,u=l.endsWith("="),c=l.endsWith("=(");if((u||c)&&(c||e.check(w.LPAREN))){let f=c?l.slice(0,-2):l.slice(0,-1);c||e.expect(w.LPAREN);let d=Ys(e);e.expect(w.RPAREN);let p=d.map(m=>Xs(e,m)),h=`${f}=(${p.join(" ")})`;s.push(e.parseWordFromString(h,!1,!1,!0))}else{let f=e.parseWordFromString(l,a.quoted,a.singleQuoted,!0);s.push(e.parseAdjacentWordParts(f.parts,a.end,Pe.Assignment))}}else if(e.isWord())s.push(e.parseWord());else if(e.check(w.RBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.LBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.DBRACK_END)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.LPAREN))e.error("syntax error near unexpected token `('");else break;let o=T.simpleCommand(r,s,n,i);return o.line=t,o}function td(e){let t=e.expect(w.ASSIGNMENT_WORD),n=t.value,r=n.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||e.error(`Invalid assignment: ${n}`);let s=r[0],i,o=s.length;if(n[o]==="["){let f=0,d=o+1;for(;o<n.length;o++)if(n[o]==="[")f++;else if(n[o]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${n}`),i=Dr(n.slice(d,o)),o++}let a=n[o]==="+";a&&o++,n[o]!=="="&&e.error(`Invalid assignment: ${n}`),o++;let l=n.slice(o);if(l==="("){let f=Ys(e);e.expect(w.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return T.assignment(d,null,a,f)}if(l===""&&e.check(w.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=Ys(e);e.expect(w.RPAREN);let p=i!==void 0?`${s}[${i}]`:s;return T.assignment(p,null,a,d)}}let u=l?e.parseWordFromString(l,t.quoted,t.singleQuoted,!0):null;t.end===e.current().start&&e.isProcessSubstitutionStart()&&(u=e.parseAdjacentWordParts(u?.parts??[],t.end,Pe.Assignment));let c=i!==void 0?`${s}[${i}]`:s;return T.assignment(c,u,a,null)}var nd=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 Ys(e){let t=[];for(e.skipNewlines();!e.check(w.RPAREN,w.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):nd.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function ei(e,t){e.expect(w.IF);let n=[],r=e.parseCompoundList();e.expect(w.THEN);let s=e.parseCompoundList();if(s.length===0){let a=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${a}'`)}for(n.push({condition:r,body:s});e.check(w.ELIF);){e.advance();let a=e.parseCompoundList();e.expect(w.THEN);let l=e.parseCompoundList();if(l.length===0){let u=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${u}'`)}n.push({condition:a,body:l})}let i=null;e.check(w.ELSE)&&(e.advance(),i=e.parseCompoundList(),i.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(w.FI);let o=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.ifNode(n,i,o)}function ti(e,t){let n=e.expect(w.FOR);if(e.check(w.DPAREN_START))return sd(e,t,e.getSourceLine(n));e.isWord()||e.error("Expected variable name in for loop");let s=e.advance().value,i=null;if(e.skipNewlines(),e.check(w.IN))for(e.advance(),i=[];!e.check(w.SEMICOLON,w.NEWLINE,w.DO,w.EOF)&&e.isWord();)i.push(e.parseWord());e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(w.DO);let o=e.parseCompoundList();e.expect(w.DONE);let a=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.forNode(s,i,o,a)}function sd(e,t,n){e.expect(w.DPAREN_START);let r=null,s=null,i=null,o=["","",""],a=0,l=0;for(;!e.check(w.DPAREN_END,w.EOF);){let f=e.advance();if(f.type===w.SEMICOLON&&l===0){if(a++,a>2)break}else f.value==="("&&l++,f.value===")"&&l--,o[a]+=f.value}e.expect(w.DPAREN_END),o[0].trim()&&(r=te(e,o[0].trim())),o[1].trim()&&(s=te(e,o[1].trim())),o[2].trim()&&(i=te(e,o[2].trim())),e.skipNewlines(),e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines();let u;e.check(w.LBRACE)?(e.advance(),u=e.parseCompoundList(),e.expect(w.RBRACE)):(e.expect(w.DO),u=e.parseCompoundList(),e.expect(w.DONE));let c=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:s,update:i,body:u,redirections:c,line:n}}function ni(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 ri(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 si(e,t){e.expect(w.CASE),e.isWord()||e.error("Expected word after 'case'");let n=e.parseWord();e.skipNewlines(),e.expect(w.IN),e.skipNewlines();let r=[];for(;!e.check(w.ESAC,w.EOF);){e.checkIterationLimit();let i=e.getPos(),o=id(e);if(o&&r.push(o),e.skipNewlines(),e.getPos()===i&&!o)break}e.expect(w.ESAC);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.caseNode(n,r,s)}function id(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 ii(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 ad=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],ld=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function Xa(e){return e.isWord()||e.check(w.LBRACE)||e.check(w.RBRACE)||e.check(w.ASSIGNMENT_WORD)}function Ya(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 li(e){return e.skipNewlines(),ud(e)}function ud(e){let t=Ja(e);for(e.skipNewlines();e.check(w.OR_OR);){e.advance(),e.skipNewlines();let n=Ja(e);t={type:"CondOr",left:t,right:n},e.skipNewlines()}return t}function Ja(e){let t=ai(e);for(e.skipNewlines();e.check(w.AND_AND);){e.advance(),e.skipNewlines();let n=ai(e);t={type:"CondAnd",left:t,right:n},e.skipNewlines()}return t}function ai(e){return e.skipNewlines(),e.check(w.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:e.withDepth(()=>ai(e))}):cd(e)}function cd(e){if(e.check(w.LPAREN)){e.advance();let t=e.withDepth(()=>li(e));return e.expect(w.RPAREN),{type:"CondGroup",expression:t}}if(Xa(e)){let t=e.current(),n=t.value;if(ad.includes(n)&&!t.quoted){if(e.advance(),e.check(w.DBRACK_END)&&e.error(`Expected operand after ${n}`),Xa(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()&&ld.includes(e.current().value)){let s=e.advance().value,i;return s==="=~"?i=fd(e):s==="=="||s==="!="?i=Ya(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=Ya(e);return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function fd(e){let t=[],n=0,r=-1,s=e.getInput(),i=()=>e.check(w.DBRACK_END)||e.check(w.AND_AND)||e.check(w.OR_OR)||e.check(w.NEWLINE)||e.check(w.EOF);for(;!i();){let o=e.current(),a=r>=0&&o.start>r;if(n===0&&a)break;if(n>0&&a){let l=s.slice(r,o.start);t.push({type:"Literal",value:l})}if(e.isWord()||e.check(w.ASSIGNMENT_WORD)){let l=e.parseWordForRegex();t.push(...l.parts),r=e.peek(-1).end}else if(e.check(w.LPAREN)){let l=e.advance();t.push({type:"Literal",value:"("}),n++,r=l.end}else if(e.check(w.DPAREN_START)){let l=e.advance();t.push({type:"Literal",value:"(("}),n+=2,r=l.end}else if(e.check(w.DPAREN_END))if(n>=2){let l=e.advance();t.push({type:"Literal",value:"))"}),n-=2,r=l.end}else{if(n===1)break;break}else if(e.check(w.RPAREN))if(n>0){let l=e.advance();t.push({type:"Literal",value:")"}),n--,r=l.end}else break;else if(e.check(w.PIPE)){let l=e.advance();t.push({type:"Literal",value:"|"}),r=l.end}else if(e.check(w.SEMICOLON))if(n>0){let l=e.advance();t.push({type:"Literal",value:";"}),r=l.end}else break;else if(n>0&&e.check(w.LESS)){let l=e.advance();t.push({type:"Literal",value:"<"}),r=l.end}else if(n>0&&e.check(w.GREAT)){let l=e.advance();t.push({type:"Literal",value:">"}),r=l.end}else if(n>0&&e.check(w.DGREAT)){let l=e.advance();t.push({type:"Literal",value:">>"}),r=l.end}else if(n>0&&e.check(w.DLESS)){let l=e.advance();t.push({type:"Literal",value:"<<"}),r=l.end}else if(n>0&&e.check(w.LESSAND)){let l=e.advance();t.push({type:"Literal",value:"<&"}),r=l.end}else if(n>0&&e.check(w.GREATAND)){let l=e.advance();t.push({type:"Literal",value:">&"}),r=l.end}else if(n>0&&e.check(w.LESSGREAT)){let l=e.advance();t.push({type:"Literal",value:"<>"}),r=l.end}else if(n>0&&e.check(w.CLOBBER)){let l=e.advance();t.push({type:"Literal",value:">|"}),r=l.end}else if(n>0&&e.check(w.TLESS)){let l=e.advance();t.push({type:"Literal",value:"<<<"}),r=l.end}else if(n>0&&e.check(w.AMP)){let l=e.advance();t.push({type:"Literal",value:"&"}),r=l.end}else if(n>0&&e.check(w.LBRACE)){let l=e.advance();t.push({type:"Literal",value:"{"}),r=l.end}else if(n>0&&e.check(w.RBRACE)){let l=e.advance();t.push({type:"Literal",value:"}"}),r=l.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function pd(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 hd(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 md(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 yd(e,t,n,r=!1){let s=n+2,i=!1;t[s]==="!"&&(i=!0,s++);let o=!1;t[s]==="#"&&!/[}:#%/^,]/.test(t[s+1]||"}")&&(o=!0,s++);let a="",l=t[s];if(/[@*#?$!-]/.test(l)&&!/[a-zA-Z0-9_]/.test(t[s+1]||""))a=l,s++;else for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)a+=t[s],s++;if(t[s]==="["){let c=Qs(e,t,s,"[","]");if(a+=`[${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(a===""&&!i&&!o&&t[s]!=="}"){let c=1,f=s;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;if(c>0)throw new xe("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(n+2,f);return{part:T.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let u=null;if(i){let c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(c)if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=ui(e,t,s,a,r);f.operation?(u={type:"Indirection",innerOp:f.operation},s=f.endIndex):(u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},a="")}else u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},a="";else if(t[s]==="*"||t[s]==="@"&&!/[QPaAEKkuUL]/.test(t[s+1]||"")){let f=t[s];s++,u={type:"VarNamePrefix",prefix:a,star:f==="*"},a=""}else if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=ui(e,t,s,a,r);f.operation?(u={type:"Indirection",innerOp:f.operation},s=f.endIndex):u={type:"Indirection"}}else u={type:"Indirection"}}else if(o)if(t[s]===":")for(u={type:"LengthSliceError"};s<t.length&&t[s]!=="}";)s++;else t[s]!=="}"&&/[-+=?]/.test(t[s])?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):t[s]==="/"?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):u={type:"Length"};if(!u&&s<t.length&&t[s]!=="}"){let c=ui(e,t,s,a,r);u=c.operation,s=c.endIndex}if(s<t.length&&t[s]!=="}"){let c=t[s];if(!/[:\-+=?#%/^,@[]/.test(c)){let f=s;for(;f<t.length&&t[f]!=="}";)f++;let d=t.slice(n,f+1);e.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<t.length&&t[s]!=="}";)s++;if(s>=t.length)throw new xe("unexpected EOF while looking for matching '}'",0,0);return{part:T.parameterExpansion(a,u),endIndex:s+1}}function ui(e,t,n,r,s=!1){let i=n,o=t[i],a=t[i+1]||"";if(o===":"){let l=a;if("-=?+".includes(l)){i+=2;let b=on(e,t,i),g=t.slice(i,b),y=e.withDepth(()=>Tt(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:Ks(e,h),length:m!==null?Ks(e,m):null},endIndex:u}}if("-=?+".includes(o)){i++;let l=on(e,t,i),u=t.slice(i,l),c=e.withDepth(()=>Tt(e,u,!1,!1,!0,!1,s,!1,!1,!0)),f=T.word(Yn(c));if(o==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:l};if(o==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:l};if(o==="?")return{operation:{type:"ErrorIfUnset",word:u?f:null,checkEmpty:!1},endIndex:l};if(o==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:l}}if(o==="#"||o==="%"){let l=a===o,u=o==="#"?"prefix":"suffix";i+=l?2:1;let c=on(e,t,i),f=t.slice(i,c),d=e.withDepth(()=>Tt(e,f,!1,!1,!1));return{operation:{type:"PatternRemoval",pattern:T.word(Yn(d)),side:u,greedy:l},endIndex:c}}if(o==="/"){let l=a==="/";i+=l?2:1;let u=null;t[i]==="#"?(u="start",i++):t[i]==="%"&&(u="end",i++);let c;u!==null&&(t[i]==="/"||t[i]==="}")?c=i:c=ja(e,t,i);let f=t.slice(i,c),d=e.withDepth(()=>Tt(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(()=>Tt(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(o==="^"||o===","){let l=a===o,u=o==="^"?"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 o==="@"&&/[QPaAEKkuUL]/.test(a)?{operation:{type:"Transform",operator:a},endIndex:i+2}:{operation:null,endIndex:i}}function ci(e,t,n,r=!1){let s=n+1;if(s>=t.length)return{part:T.literal("$"),endIndex:s};let i=t[s];if(i==="("&&t[s+1]==="(")return e.isDollarDparenSubshell(t,n)?e.parseCommandSubstitution(t,n):e.parseArithmeticExpansion(t,n);if(i==="["){let o=1,a=s+1;for(;a<t.length&&o>0;)t[a]==="["?o++:t[a]==="]"&&o--,o>0&&a++;if(o===0){let l=t.slice(s+1,a),u=te(e,l);return{part:T.arithmeticExpansion(u),endIndex:a+1}}}return i==="("?e.parseCommandSubstitution(t,n):i==="{"?yd(e,t,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?md(e,t,n):{part:T.literal("$"),endIndex:s}}function el(e,t){let n=[],r=0,s="",i=()=>{s&&(n.push(T.literal(s)),s="")};for(;r<t.length;){let o=t[r];if(o==="\\"&&r+1<t.length){let a=t[r+1];if(a==="$"||a==="`"||a==='"'||a==="\\"){s+=a,r+=2;continue}s+=o,r++;continue}if(o==="$"){i();let{part:a,endIndex:l}=ci(e,t,r,!0);a&&n.push(a),r=l;continue}if(o==="`"){i();let{part:a,endIndex:l}=e.parseBacktickSubstitution(t,r,!0);n.push(a),r=l;continue}s+=o,r++}return i(),n}function gd(e,t,n){let r=[],s=n,i="",o=()=>{i&&(r.push(T.literal(i)),i="")};for(;s<t.length&&t[s]!=='"';){let a=t[s];if(a==="\\"&&s+1<t.length){let l=t[s+1];if('"\\$`\n'.includes(l)){i+=l,s+=2;continue}i+=a,s++;continue}if(a==="$"){o();let{part:l,endIndex:u}=ci(e,t,s,!0);l&&r.push(l),s=u;continue}if(a==="`"){o();let{part:l,endIndex:u}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=u;continue}i+=a,s++}return o(),{part:T.doubleQuoted(r),endIndex:s}}function Tt(e,t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,u=!1,c=!0){if(r)return[T.singleQuoted(t)];if(n){let m=el(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=el(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&&!o){E!==`
70
+ `&&(h(),f.push(T.escaped(E))),d+=2;continue}let b=i?E==="$"||E==="`"||E===`
71
+ `:E==="$"||E==="`"||E==='"'||E==="'"||E===`
72
+ `||u&&E==="}",g=o?"*?[]\\".includes(E):"*?[]\\(){}.^+".includes(E);b?E!==`
73
+ `&&(p+=E):g?(h(),f.push(T.escaped(E))):p+=`\\${E}`,d+=2;continue}if(m==="'"&&!o&&!i){h();let E=t.indexOf("'",d+1);if(E===-1){p+=t.slice(d);break}f.push(T.singleQuoted(t.slice(d+1,E))),d=E+1;continue}if(m==='"'&&!i){h();let{part:E,endIndex:b}=gd(e,t,d+1);f.push(E),d=b+1;continue}if(m==="$"&&t[d+1]==="'"){h();let{part:E,endIndex:b}=Za(e,t,d+2);f.push(E),d=b;continue}if(m==="$"){h();let{part:E,endIndex:b}=ci(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&&!o){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=Ua(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=hd(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}=Ga(e,t,d);f.push({type:"Glob",pattern:l?pd(E):E}),d=b;continue}if(m==="{"&&!s&&!a&&!i){let E=Ha(e,t,d,Tt);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>Gs)throw new xe(`Input too large: ${t.length} bytes exceeds limit of ${Gs}`,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 xe(`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 o=this.tokens[this.pos]?.type;return o===t||n!==void 0&&o===n||r!==void 0&&o===r||s!==void 0&&o===s?!0:i.length>0?i.includes(o):!1}expect(t,n){if(this.check(t))return this.advance();let r=this.current();throw new xe(n||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let n=this.current();throw new xe(t,n.line,n.column,n)}skipNewlines(){for(;this.check(w.NEWLINE,w.COMMENT);)this.check(w.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(w.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(w.SEMICOLON,w.COMMENT)){this.advance();continue}if(t&&this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,n,r,s){this.pendingHeredocs.push({redirect:t,delimiter:n,stripTabs:r,quoted:s})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(w.HEREDOC_CONTENT)){let n=this.advance(),r;t.quoted?r=T.word([T.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),t.redirect.target=T.hereDoc(t.delimiter,r,t.stripTabs,t.quoted,n.heredocTerminated??!1)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(w.EOF,w.NEWLINE,w.SEMICOLON,w.AMP,w.AND_AND,w.OR_OR,w.RPAREN,w.RBRACE,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return this.isWord()||t===w.ASSIGNMENT_WORD||t===w.FD_VARIABLE||t===w.LPAREN||t===w.LBRACE||t===w.DPAREN_START||t===w.DBRACK_START||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,o=this.parseStatement();o&&t.push(o),this.check(w.HEREDOC_CONTENT)&&this.processHeredocs(),this.skipSeparators(!1),this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(w.EOF)&&this.error(`syntax error near unexpected token \`${this.current().value}'`)}return T.script(t)}checkUnexpectedToken(){let t=this.current().type,n=this.current().value;if(this.currentTokenJoinsProcessSubstitution())return null;if((t===w.DO||t===w.DONE||t===w.THEN||t===w.ELSE||t===w.ELIF||t===w.FI||t===w.ESAC)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.RBRACE||t===w.RPAREN){let r=`syntax error near unexpected token \`${n}'`;return this.advance(),T.statement([T.pipeline([T.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:n})}return(t===w.DSEMI||t===w.SEMI_AND||t===w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`),(t===w.AMP||t===w.AND_AND||t===w.OR_OR||t===w.PIPE||t===w.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${n}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,n=[],r=[],s=!1,i=this.parsePipeline();for(n.push(i);this.check(w.AND_AND,w.OR_OR);){let l=this.advance();r.push(l.type===w.AND_AND?"&&":"||"),this.skipNewlines();let u=this.parsePipeline();n.push(u)}this.check(w.AMP)&&(this.advance(),s=!0);let o=this.pos>0?this.tokens[this.pos-1].end:t,a=this._input.slice(t,o);return T.statement(n,r,s,void 0,a)}parseTimePrefix(){if(!this.check(w.TIME)||this.currentTokenJoinsProcessSubstitution())return;this.advance();let t=!1;return this.check(w.WORD,w.NAME)&&this.current().value==="-p"&&(this.advance(),t=!0),t}parsePipeline(){let t=!1,n=!1,r=0;for(;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++;if(r===0){let l=this.parseTimePrefix();if(l!==void 0)for(t=!0,n=l;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++}let s=r%2===1,i=[],o=[],a=this.parseCommand();for(i.push(a);this.check(w.PIPE,w.PIPE_AMP);){let l=this.advance();this.skipNewlines(),o.push(l.type===w.PIPE_AMP);let u=this.parseCommand();i.push(u)}return T.pipeline(i,s,t,n,o.length>0?o:void 0)}parseCommand(){if(this.currentTokenJoinsProcessSubstitution())return Js(this);let t=this.current();switch(t.type){case w.IF:return ei(this);case w.FOR:return ti(this);case w.WHILE:return ni(this);case w.UNTIL:return ri(this);case w.CASE:return si(this);case w.LPAREN:return ii(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: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():Js(this)}dparenClosesWithSpacedParens(){let t=1,n=1;for(;n<this.tokens.length-this.pos;){let r=this.peek(n);if(r.type===w.EOF)return!1;if(r.type===w.DPAREN_START||r.type===w.LPAREN)t++;else if(r.type===w.DPAREN_END){if(t-=2,t<=0)return!1}else if(r.type===w.RPAREN&&(t--,t===0&&this.peek(n+1).type===w.RPAREN))return!0;n++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(w.RPAREN),this.expect(w.RPAREN);let n=this.parseOptionalRedirections(),r=T.subshell(t,[]);return T.subshell([T.statement([T.pipeline([r],!1,!1,!1)])],n)}isWord(){return this.isWordToken(Pe.Default)||this.isProcessSubstitutionStart()||this.currentTokenJoinsProcessSubstitution()}isWordToken(t){let n=this.current().type;return n===w.WORD||n===w.NAME||n===w.NUMBER||js(n)||n===w.BANG||n===w.ASSIGNMENT_WORD&&(t&Pe.Regex)!==0}isProcessSubstitutionStart(t=0){let n=this.peek(t),r=this.peek(t+1);return(n.type===w.LESS||n.type===w.GREAT)&&r.type===w.LPAREN&&n.end===r.start}currentTokenJoinsProcessSubstitution(){return this.current().type===w.COMMENT||!this.isAdjacentWordToken(Pe.Default)?!1:this.current().end===this.peek(1).start&&this.isProcessSubstitutionStart(1)}isAdjacentWordToken(t){let n=this.current().type;return this.isWordToken(t)||n===w.ASSIGNMENT_WORD||n===w.COMMENT||n===w.LBRACE||n===w.RBRACE||n===w.DBRACK_START||n===w.DBRACK_END||n===w.FD_VARIABLE}parseWord(t=Pe.Default){if(this.isProcessSubstitutionStart())return this.parseAdjacentWordParts([],this.current().start,t);let n=this.advance(),r=this.parseWordToken(n,t);return this.parseAdjacentWordParts(r.parts,n.end,t)}parseAdjacentWordParts(t,n,r=Pe.Default){for(;n===this.current().start;){if(this.isProcessSubstitutionStart()){t.push(this.parseProcessSubstitution()),n=this.tokens[this.pos-1].end;continue}if(!this.isAdjacentWordToken(r))break;let s=this.advance();t.push(...this.parseWordToken(s,r,t.length===0).parts),n=s.end}return T.word(t)}parseWordNoBraceExpansion(){return this.parseWord(Pe.NoBraceExpansion)}parseWordForRegex(){return this.parseWord(Pe.NoBraceExpansion|Pe.Regex)}parseWordToken(t,n,r=!0){return t.type===w.LBRACE||t.type===w.RBRACE||t.type===w.DBRACK_START||t.type===w.DBRACK_END||t.type===w.FD_VARIABLE?T.word([T.literal(t.type===w.FD_VARIABLE?`{${t.value}}`:t.value)]):this.parseWordFromString(t.value,t.quoted,t.singleQuoted,(n&Pe.Assignment)!==0,!1,(n&Pe.NoBraceExpansion)!==0,(n&Pe.Regex)!==0,r)}parseWordFromString(t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!0){let u=Tt(this,t,n,r,s,i,!1,o,a,!1,l);return T.word(u)}parseCommandSubstitution(t,n){return ba(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitutionFromString(t,n){return Sa(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 Aa(t,n,r,()=>new e(this.parseBudget),s=>this.error(s))}isDollarDparenSubshell(t,n){return wa(t,n)}parseArithmeticExpansion(t,n){let r=n+3,s=1,i=0,o=r;for(;o<t.length-1&&s>0;)t[o]==="$"&&t[o+1]==="("?t[o+2]==="("?(s++,o+=3):(i++,o+=2):t[o]==="("&&t[o+1]==="("?(s++,o+=2):t[o]===")"&&t[o+1]===")"?i>0?(i--,o++):(s--,s>0&&(o+=2)):t[o]==="("?(i++,o++):(t[o]===")"&&i>0&&i--,o++);let a=t.slice(r,o),l=this.parseArithmeticExpression(a);return{part:T.arithmeticExpansion(l),endIndex:o+2}}parseArithmeticCommand(){let t=this.expect(w.DPAREN_START),n="",r=1,s=0,i=!1,o=!1;for(;r>0&&!this.check(w.EOF);){if(i){if(i=!1,s>0){s--,n+=")";continue}if(this.check(w.RPAREN)){r--,o=!0,this.advance();continue}if(this.check(w.DPAREN_END)){r--,o=!0;continue}n+=")";continue}if(this.check(w.DPAREN_START))r++,n+="((",this.advance();else if(this.check(w.DPAREN_END))s>=2?(s-=2,n+="))",this.advance()):s===1?(s--,n+=")",i=!0,this.advance()):(r--,o=!0,r>0&&(n+="))"),this.advance());else if(this.check(w.LPAREN))s++,n+="(",this.advance();else if(this.check(w.RPAREN))s>0&&s--,n+=")",this.advance();else{let u=this.current().value,c=n.length>0?n[n.length-1]:"";n.length>0&&!n.endsWith(" ")&&!(u==="="&&/[|&^+\-*/%<>]$/.test(n))&&!(u==="<"&&c==="<")&&!(u===">"&&c===">")&&(n+=" "),n+=u,this.advance()}}o||this.expect(w.DPAREN_END);let a=this.parseArithmeticExpression(n.trim()),l=this.parseOptionalRedirections();return T.arithmeticCommand(a,l,this.getSourceLine(t))}parseConditionalCommand(){let t=this.expect(w.DBRACK_START),n=li(this);this.expect(w.DBRACK_END);let r=this.parseOptionalRedirections();return T.conditionalCommand(n,r,this.getSourceLine(t))}parseFunctionDef(){let t;if(this.check(w.FUNCTION)){if(this.advance(),this.check(w.NAME)||this.check(w.WORD))t=this.advance().value;else{let s=this.current();throw new xe("Expected function name",s.line,s.column,s)}this.check(w.LPAREN)&&(this.advance(),this.expect(w.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(w.LPAREN),this.expect(w.RPAREN);this.skipNewlines();let n=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return T.functionDef(t,n,r)}parseCompoundCommandBody(t){let n=t?.forFunctionBody;if(this.check(w.LBRACE))return oi(this,{skipRedirections:n});if(this.check(w.LPAREN))return ii(this,{skipRedirections:n});if(this.check(w.IF))return ei(this,{skipRedirections:n});if(this.check(w.FOR))return ti(this,{skipRedirections:n});if(this.check(w.WHILE))return ni(this,{skipRedirections:n});if(this.check(w.UNTIL))return ri(this,{skipRedirections:n});if(this.check(w.CASE))return si(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 at(e,t){return new G().parse(e,t)}function tl(e){return ln(e)}function ln(e){return e.statements.map(nl).join(`
74
+ `)}function nl(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(Ed(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let n=t.join(" ");return e.background&&(n+=" &"),n}function Ed(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(rl(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 rl(e){switch(e.type){case"SimpleCommand":return bd(e);case"If":return Nd(e);case"For":return Rd(e);case"CStyleFor":return Dd(e);case"While":return Id(e);case"Until":return Od(e);case"Case":return _d(e);case"Subshell":return Td(e);case"Group":return Md(e);case"ArithmeticCommand":return Fd(e);case"ConditionalCommand":return Bd(e);case"FunctionDef":return Wd(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function bd(e){let t=[];for(let n of e.assignments)t.push(Sd(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(ol(n));return t.join(" ")}function Sd(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 Mt(e){return e.parts.map(t=>Or(t,!0)).join("")}function Or(e,t){switch(e.type){case"Literal":return t?vd(e.value):Ad(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 sl(e);case"CommandSubstitution":return e.legacy?`\`${ln(e.body)}\``:`$(${ln(e.body)})`;case"ArithmeticExpansion":return`$((${fe(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${ln(e.body)})`:`>(${ln(e.body)})`;case"BraceExpansion":return Pd(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 Ad(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function vd(e){return e.replace(/[$`"\\]/g,"\\$&")}function xd(e,t){return e.parts.map(n=>$d(n,t)).join("")}function $d(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return sl(e);case"CommandSubstitution":return e.legacy?`\`${ln(e.body)}\``:`$(${ln(e.body)})`;case"ArithmeticExpansion":return`$((${fe(e.expression.expression)}))`;default:return Or(e,!1)}}function sl(e){return e.operation?`\${${il(e.parameter,e.operation)}}`:kd(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function kd(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function il(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${Mt(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${Mt(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?Mt(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${Mt(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}${Mt(t.pattern)}`}case"PatternReplacement":{let n="/";t.all?n="//":t.anchor==="start"?n="/#":t.anchor==="end"&&(n="/%");let r=t.replacement?`/${Mt(t.replacement)}`:"";return`${e}${n}${Mt(t.pattern)}${r}`}case"CaseModification":{let n=t.direction==="upper"?"^":",",r=t.all?`${n}${n}`:n,s=t.pattern?Mt(t.pattern):"";return`${e}${r}${s}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${il(e,t.innerOp)}`:`!${e}`;case"ArrayKeys":return`!${t.array}[${t.star?"*":"@"}]`;case"VarNamePrefix":return`!${t.prefix}${t.star?"*":"@"}`;default:{let n=t;throw new Error(`Unsupported parameter operation type: ${n.type}`)}}}function Pd(e){return`{${e.items.map(Cd).join(",")}}`}function Cd(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 ol(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=xd(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 lt(e){return e.length===0?"":` ${e.map(ol).join(" ")}`}function nt(e){return e.map(nl).join(`
76
+ `)}function Nd(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} ${nt(r.condition)}; then
77
+ ${nt(r.body)}`)}return e.elseBody&&t.push(`else
78
+ ${nt(e.elseBody)}`),`${t.join(`
79
+ `)}
80
+ fi${lt(e.redirections)}`}function Rd(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
+ ${nt(e.body)}
82
+ done${lt(e.redirections)}`}function Dd(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
+ ${nt(e.body)}
84
+ done${lt(e.redirections)}`}function Id(e){return`while ${nt(e.condition)}; do
85
+ ${nt(e.body)}
86
+ done${lt(e.redirections)}`}function Od(e){return`until ${nt(e.condition)}; do
87
+ ${nt(e.body)}
88
+ done${lt(e.redirections)}`}function _d(e){let t=e.items.map(Ld).join(`
89
+ `);return`case ${Se(e.word)} in
90
+ ${t}
91
+ esac${lt(e.redirections)}`}function Ld(e){let t=e.patterns.map(Se).join(" | "),n=nt(e.body);return n?`${t})
92
+ ${n}
93
+ ${e.terminator}`:`${t})
94
+ ${e.terminator}`}function Td(e){return`(${nt(e.body)})${lt(e.redirections)}`}function Md(e){return`{ ${nt(e.body)}; }${lt(e.redirections)}`}function Fd(e){return`((${fe(e.expression.expression)}))${lt(e.redirections)}`}function Bd(e){return`[[ ${an(e.expression)} ]]${lt(e.redirections)}`}function Wd(e){let t=rl(e.body);return`${e.name}() ${t}${lt(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 an(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`! ${an(e.operand)}`;case"CondAnd":return`${an(e.left)} && ${an(e.right)}`;case"CondOr":return`${an(e.left)} || ${an(e.right)}`;case"CondGroup":return`( ${an(e.expression)} )`;case"CondWord":return Se(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var Vd="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 al(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function ll(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function ul(e,t){return e.env.get(`${Vd}${t}`)}function fl(e,t,n){return dl(e,t,n)}function dl(e,t,n,r=!0){if(!t.name||!al(t.name))return t;let s=ll(t.name);if(!s)return t;let i=ul(e,s);if(!i||n.has(s))return t;try{n.add(s);let o=new G,a={value:0},l=_r("",i,e.limits.maxStringLength,a),u=i.endsWith(" ");if(!u)for(let p of t.args){let h=Se(p);l=_r(l,` ${h}`,e.limits.maxStringLength,a)}let c;try{c=o.parse(l)}catch(p){if(p instanceof xe)throw p;return t}if(c.statements.length!==1||c.statements[0].pipelines.length!==1||c.statements[0].pipelines[0].commands.length!==1)return cl(e,t,i);let f=c.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return cl(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(!al(h))break;let m=ll(h),E=m?ul(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=dl(e,b,n,!1);if(g===b||(d={...d,name:g.name,args:[...g.args]},!E.endsWith(" ")))break}}return d}catch(o){throw n.delete(s),o}}function cl(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,o=i.parseWordFromString("eval",!1,!1),a=0;for(let u of s)u==="'"&&a++;if(r.value+2+a*3>e.limits.maxStringLength)throw new 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:o,args:[l],assignments:t.assignments,redirections:t.redirections,line:t.line}}var zd=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function fi(e){return zd.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 hl(e){let t="^";for(let n=0;n<e.length;n++){let r=e[n];if(r==="*")t+="[^/]*";else if(r==="?")t+="[^/]";else if(r==="["){let s=n+1,i="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(i+="^",s++),s<e.length&&e[s]==="]"&&(i+="\\]",s++);let o=s;for(;o<e.length;){if(e[o]==="\\"&&o+1<e.length){o+=2;continue}if(e[o]==="["&&o+1<e.length&&e[o+1]===":"){let l=e.indexOf(":]",o+2);if(l!==-1){o=l+2;continue}}if(e[o]==="]")break;o++}let a=s;for(;s<e.length&&e[s]!=="]";){if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let l=e.indexOf(":]",s+2);if(l!==-1){let u=e.slice(s+2,l),c=fi(u);i+=c,s=l+2;continue}}if(e[s]==="\\"&&s+1<e.length){i+=`\\${e[s+1]}`,s+=2;continue}if(e[s]==="-"){let l=s===a,u=s+1===o;l||u?i+="\\-":i+="-"}else i+=e[s];s++}i+="]",t+=i,n=s}else if(r==="\\"&&n+1<e.length){let s=e[n+1];/[.+^${}()|\\*?[\]]/.test(s)?t+=`\\${s}`:t+=s,n++}else/[.+^${}()|]/.test(r)?t+=`\\${r}`:t+=r}return t+="$",me(t)}function di(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 pi(e){let t=[],n="",r=0,s=!1,i=0;for(;i<e.length;){let o=e[i];if(o==="'"&&!s){s=!0,n+="\0QUOTE_START\0",i++;continue}if(o==="'"&&s){s=!1,n+="\0QUOTE_END\0",i++;continue}if(s){n+=o,i++;continue}if(o==="\\"){n+=o,i+1<e.length?(n+=e[i+1],i+=2):i++;continue}o==="("?(r++,n+=o):o===")"?(r--,n+=o):o==="|"&&r===0?(t.push(n),n=""):n+=o,i++}return t.push(n),t}var ml=5,Ft=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 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 hl(n).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,n){let r=t.map((o,a)=>(n?.[a]??!1)||!this.isGlobPattern(o)?null:this.expand(o)),s=await Promise.all(r.map(o=>o||Promise.resolve(null))),i=[];for(let o=0;o<t.length;o++){let a=s[o];a===null?i.push(t[o]):a.length>0?i.push(...a):i.push(t[o])}return i}async expand(t){if(this.globstar){let r=t.split("/"),s=0;for(let i of r)if(i==="**"&&(s++,s>ml))throw new k(`Glob pattern has too many ** segments (max ${ml})`,"glob_operations")}let n;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))n=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");n=await this.expandSimple(r)}return this.filterGlobignore(n)}isGlobstarValid(t){let n=t.split("/");for(let r of n)if(r.includes("**")&&r!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let n=t.startsWith("/"),r=t.split("/").filter(u=>u!==""),s=-1;for(let u=0;u<r.length;u++)if(this.hasGlobChars(r[u])){s=u;break}if(s===-1)return[t];let i,o;if(s===0)n?(i="/",o="/"):(i=this.cwd,o="");else{let u=r.slice(0,s);n?(i=`/${u.join("/")}`,o=`/${u.join("/")}`):(i=this.fs.resolvePath(this.cwd,u.join("/")),o=u.join("/"))}let a=r.slice(s);return(await this.expandSegments(i,o,a)).sort()}async expandSegments(t,n,r){if(this.checkOpsLimit(),r.length===0)return[n];let[s,...i]=r,o=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(t),l=[],u=[...a],c=this.dotglob||this.hasGlobignore;if(s.startsWith(".")||this.dotglob){let d=a.some(h=>h.name==="."),p=a.some(h=>h.name==="..");d||u.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),p||u.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of u)if(!(d.name.startsWith(".")&&!s.startsWith(".")&&!c)&&this.matchPattern(d.name,s)){let p=t==="/"?`/${d.name}`:`${t}/${d.name}`,h;n===""?h=d.name:n==="/"?h=`/${d.name}`:h=`${n}/${d.name}`,i.length===0?l.push(Promise.resolve([h])):d.isDirectory&&l.push(this.expandSegments(p,h,i))}let f=await Promise.all(l);for(let d of f)o.push(...d)}else{this.checkOpsLimit();let a=await this.fs.readdir(t),l=[],u=[...a],c=this.dotglob||this.hasGlobignore;(s.startsWith(".")||this.dotglob)&&(a.includes(".")||u.push("."),a.includes("..")||u.push(".."));for(let d of u)if(!(d.startsWith(".")&&!s.startsWith(".")&&!c)&&this.matchPattern(d,s)){let p=t==="/"?`/${d}`:`${t}/${d}`,h;n===""?h=d:n==="/"?h=`/${d}`:h=`${n}/${d}`,i.length===0?l.push(Promise.resolve([h])):l.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(p)).isDirectory)return this.expandSegments(p,h,i)}catch(m){if(m instanceof k)throw m}return[]})())}let f=await Promise.all(l);for(let d of f)o.push(...d)}}catch(a){if(a instanceof k)throw a}return o}async expandRecursive(t){let n=[],r=t.indexOf("**"),s=t.slice(0,r).replace(/\/$/,"")||".",o=t.slice(r+2).replace(/^\//,"");return o.includes("**")&&this.isGlobstarValid(o)?(await this.walkDirectoryMultiGlobstar(s,o,n),[...new Set(n)].sort()):(await this.walkDirectory(s,o,n),n.sort())}async walkDirectoryMultiGlobstar(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let i=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(s):null;if(i){let o=[];for(let u of i){let c=t==="."?u.name:`${t}/${u.name}`;u.isDirectory&&o.push(c)}let a=t==="."?n:`${t}/${n}`,l=await this.expandRecursive(a);r.push(...l);for(let u=0;u<o.length;u+=100){let c=o.slice(u,u+100);await Promise.all(c.map(f=>this.walkDirectoryMultiGlobstar(f,n,r)))}}else{this.checkOpsLimit();let o=await this.fs.readdir(s),a=[];for(let c of o){let f=t==="."?c:`${t}/${c}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&a.push(f)}catch(p){if(p instanceof k)throw p}}let l=t==="."?n:`${t}/${n}`,u=await this.expandRecursive(l);r.push(...u);for(let c=0;c<a.length;c+=100){let f=a.slice(c,c+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,n,r)))}}}catch(i){if(i instanceof 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),o=[],a=[];for(let l of i){let u=t==="."?l.name:`${t}/${l.name}`;l.isDirectory?a.push(u):n&&this.matchPattern(l.name,n)&&o.push(u)}r.push(...o);for(let l=0;l<a.length;l+=100){let u=a.slice(l,l+100);await Promise.all(u.map(c=>this.walkDirectory(c,n,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(s),o=[];for(let l=0;l<i.length;l+=100){let u=i.slice(l,l+100),c=await Promise.all(u.map(async f=>{let d=t==="."?f:`${t}/${f}`,p=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let h=await this.fs.stat(p);return{name:f,path:d,isDirectory:h.isDirectory}}catch(h){if(h instanceof k)throw h;return null}}));o.push(...c.filter(f=>f!==null))}for(let l of o)!l.isDirectory&&n&&this.matchPattern(l.name,n)&&r.push(l.path);let a=o.filter(l=>l.isDirectory);for(let l=0;l<a.length;l+=100){let u=a.slice(l,l+100);await Promise.all(u.map(c=>this.walkDirectory(c.path,n,r)))}}}catch(i){if(i instanceof 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 o=di(t,s+1);if(o!==-1){let a=t.slice(s+2,o),l=pi(a),u=l.map(f=>this.patternToRegexStr(f)),c=u.length>0?u.join("|"):"(?:)";if(i==="@")n+=`(?:${c})`;else if(i==="*")n+=`(?:${c})*`;else if(i==="+")n+=`(?:${c})+`;else if(i==="?")n+=`(?:${c})?`;else if(i==="!")if(o<t.length-1){let d=l.map(h=>this.computePatternLength(h));if(d.every(h=>h!==null)&&d.every(h=>h===d[0])&&d[0]!==null){let h=d[0];if(h===0)n+="(?:.+)";else{let m=[];h>0&&m.push(`.{0,${h-1}}`),m.push(`.{${h+1},}`),m.push(`(?!(?:${c})).{${h}}`),n+=`(?:${m.join("|")})`}}else n+=`(?:(?!(?:${c})).)*?`}else n+=`(?!(?:${c})$).*`;s=o;continue}}if(i==="*")n+=".*";else if(i==="?")n+=".";else if(i==="["){let o=s+1,a="[";o<t.length&&(t[o]==="^"||t[o]==="!")&&(a+="^",o++),o<t.length&&t[o]==="]"&&(a+="\\]",o++);let l=o;for(;l<t.length;){if(t[l]==="\\"&&l+1<t.length){l+=2;continue}if(t[l]==="["&&l+1<t.length&&t[l+1]===":"){let c=t.indexOf(":]",l+2);if(c!==-1){l=c+2;continue}}if(t[l]==="]")break;l++}let u=o;for(;o<t.length&&t[o]!=="]";){if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let c=t.indexOf(":]",o+2);if(c!==-1){let f=t.slice(o+2,c),d=fi(f);a+=d,o=c+2;continue}}if(t[o]==="\\"&&o+1<t.length){a+=`\\${t[o+1]}`,o+=2;continue}if(t[o]==="-"){let c=o===u,f=o+1===l;c||f?a+="\\-":a+="-"}else a+=t[o];o++}a+="]",n+=a,s=o}else if(i==="\\"&&s+1<t.length){let o=t[s+1];/[.+^${}()|\\*?[\]]/.test(o)?n+=`\\${o}`:n+=o,s++}else/[.+^${}()|]/.test(i)?n+=`\\${i}`:n+=i}return n}computePatternLength(t){let n=0,r=0,s=!1;for(;r<t.length;){if(t.slice(r,r+13)==="\0QUOTE_START\0"){s=!0,r+=13;continue}if(t.slice(r,r+11)==="\0QUOTE_END\0"){s=!1,r+=11;continue}let i=t[r];if(s){n+=1,r++;continue}if((i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&r+1<t.length&&t[r+1]==="("){let o=di(t,r+1);if(o!==-1){if(i==="@"){let a=t.slice(r+2,o),u=pi(a).map(c=>this.computePatternLength(c));if(u.every(c=>c!==null)&&u.every(c=>c===u[0])){n+=u[0],r=o+1;continue}return null}return null}}if(i==="*")return null;if(i==="?"){n+=1,r++;continue}if(i==="["){let o=t.indexOf("]",r+1);if(o!==-1){n+=1,r=o+1;continue}n+=1,r++;continue}if(i==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}};function hi(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 qd(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 yl(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,o=!1,a=!1;for(let l of e){if((l.type==="SingleQuoted"||l.type==="DoubleQuoted")&&(t=!0,l.type==="DoubleQuoted"))for(let u of l.parts)u.type==="ParameterExpansion"&&(u.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!u.operation||u.operation.type==="PatternRemoval"||u.operation.type==="PatternReplacement")&&(s=!0),(u.operation?.type==="VarNamePrefix"||u.operation?.type==="ArrayKeys")&&(o=!0),u.operation?.type==="Indirection"&&(a=!0));l.type==="CommandSubstitution"&&(n=!0),l.type==="ParameterExpansion"&&(i=!0,(l.parameter==="@"||l.parameter==="*")&&(r=!0),qd(l)&&(t=!0),(l.operation?.type==="VarNamePrefix"||l.operation?.type==="ArrayKeys")&&(o=!0),l.operation?.type==="Indirection"&&(a=!0)),l.type==="Glob"&&hi(l.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i,hasVarNamePrefixExpansion:o,hasIndirection:a}}var Ud=`
95
+ `;function un(e,t){if(e>=t)throw new k(`array element limit exceeded (${t})`,"array_elements")}function mi(e,t,n,r,s){un(e.length,s),un(t.length,s),e.push(n),t.push(r)}function Ae(e){return e.get("IFS")??Ud}function Ce(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 gl(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 jd=`
98
+ `;function Gd(e){return jd.includes(e)}function yi(e){let t=new Set,n=new Set;for(let r of e)Gd(r)?t.add(r):n.add(r);return{whitespace:t,nonWhitespace:n}}function gi(e,t,n,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:(un(0,n),{words:[e],wordStarts:[0]});let{whitespace:i,nonWhitespace:o}=yi(t),a=[],l=[],u=0;for(;u<e.length&&i.has(e[u]);)u++;if(u>=e.length)return{words:[],wordStarts:[]};if(o.has(e[u]))for(mi(a,l,"",u,n),u++;u<e.length&&i.has(e[u]);)u++;for(;u<e.length&&!(r!==void 0&&a.length>=r);){let c=u;for(;u<e.length;){let f=e[u];if(!s&&f==="\\"){u++,u<e.length&&u++;continue}if(i.has(f)||o.has(f))break;u++}if(mi(a,l,e.substring(c,u),c,n),u>=e.length)break;for(;u<e.length&&i.has(e[u]);)u++;if(u<e.length&&o.has(e[u])){for(u++;u<e.length&&i.has(e[u]);)u++;for(;u<e.length&&o.has(e[u])&&!(r!==void 0&&a.length>=r);)for(mi(a,l,"",u,n),u++;u<e.length&&i.has(e[u]);)u++}}return{words:a,wordStarts:l}}function Tr(e,t,n){if(t==="")return e&&un(0,n),{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=yi(t),i=[],o=0,a=!1,l=!1,u=o;for(;o<e.length&&r.has(e[o]);)o++;if(o>u&&(a=!0),o>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[o]))for(un(i.length,n),i.push(""),o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length;){let c=o;for(;o<e.length;){let d=e[o];if(r.has(d)||s.has(d))break;o++}if(un(i.length,n),i.push(e.substring(c,o)),o>=e.length){l=!1;break}let f=o;for(;o<e.length&&r.has(e[o]);)o++;if(o<e.length&&s.has(e[o])){for(o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length&&s.has(e[o]);)for(un(i.length,n),i.push(""),o++;o<e.length&&r.has(e[o]);)o++}o>=e.length&&o>f&&(l=!0)}return{words:i,hadLeadingDelimiter:a,hadTrailingDelimiter:l}}function ce(e,t,n){return Tr(e,t,n).words}function Zd(e,t){for(let n of e)if(t.has(n))return!0;return!1}function wl(e,t,n){if(t==="")return e;let{whitespace:r,nonWhitespace:s}=yi(t),i=e.length;for(;i>0&&r.has(e[i-1]);){if(!n&&i>=2){let a=0,l=i-2;for(;l>=0&&e[l]==="\\";)a++,l--;if(a%2===1)break}i--}let o=e.substring(0,i);if(o.length>=1&&s.has(o[o.length-1])){if(!n&&o.length>=2){let l=0,u=o.length-2;for(;u>=0&&o[u]==="\\";)l++,u--;if(l%2===1)return o}let a=o.substring(0,o.length-1);if(!Zd(a,s))return a}return o}function le(e,t){return e.state.namerefs?.has(t)??!1}function $t(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function El(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function bl(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function Sl(e,t){return e.state.invalidNamerefs?.has(t)??!1}function wi(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=ke(e,s),o=e.state.associativeArrays?.has(s)??!1;return i||o}return ke(e,t)?!0:e.state.env.has(t)}function Le(e,t,n=100){if(!le(e,t)||Sl(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 cn(e,t){if(le(e,t))return e.state.env.get(t)}function Fr(e,t,n,r=100){if(!le(e,t)||Sl(e,t))return t;let s=new Set,i=t;for(;r-- >0;){if(s.has(i))return;if(s.add(i),!le(e,i))return i;let o=e.state.env.get(i);if(o===void 0||o==="")return n!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)&&Mr(e,n)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(o))return i;i=o}}function Al(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,o)=>[o,i]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((i,o)=>[o,String(i)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((i,o)=>[o,i]):e.state.associativeArrays?.has(t)?mt(e,t).map(i=>[i,oe(e,t,i)??""]):be(e,t).map(s=>[s,oe(e,t,s)??""])}function ut(e,t){return t==="FUNCNAME"?(e.state.funcNameStack?.length??0)>0:t==="BASH_LINENO"?(e.state.callLineStack?.length??0)>0:t==="BASH_SOURCE"?(e.state.sourceStack?.length??0)>0:e.state.associativeArrays?.has(t)?ke(e,t):ke(e,t)}async function re(e,t,n=!0,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 o="";return o+="h",e.state.options.errexit&&(o+="e"),e.state.options.noglob&&(o+="f"),e.state.options.nounset&&(o+="u"),e.state.options.verbose&&(o+="v"),e.state.options.xtrace&&(o+="x"),o+="B",e.state.options.noclobber&&(o+="C"),o+="s",o}case"*":{let o=Number.parseInt(e.state.env.get("#")||"0",10);if(o===0)return"";let a=[];for(let l=1;l<=o;l++)a.push(e.state.env.get(String(l))||"");return a.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 ma;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let o=e.state.funcNameStack?.[0];if(o!==void 0)return o;if(n&&e.state.options.nounset)throw new Fe("FUNCNAME");return""}case"BASH_LINENO":{let o=e.state.callLineStack?.[0];if(o!==void 0)return String(o);if(n&&e.state.options.nounset)throw new Fe("BASH_LINENO");return""}case"BASH_SOURCE":{let o=e.state.sourceStack?.[0];if(o!==void 0)return o;if(n&&e.state.options.nounset)throw new Fe("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 o=s[1],a=s[2];if(le(e,o)){let f=Le(e,o);if(f&&f!==o){if(f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";o=f}}if(a==="@"||a==="*"){let f=Z(e,o);if(f.length>0)return f.map(([,p])=>p).join(" ");let d=e.state.env.get(o);return d!==void 0?d:""}if(o==="FUNCNAME"){let f=Number.parseInt(a,10);return!Number.isNaN(f)&&f>=0?e.state.funcNameStack?.[f]??"":""}if(o==="BASH_LINENO"){let f=Number.parseInt(a,10);if(!Number.isNaN(f)&&f>=0){let d=e.state.callLineStack?.[f];return d!==void 0?String(d):""}return""}if(o==="BASH_SOURCE"){let f=Number.parseInt(a,10);return!Number.isNaN(f)&&f>=0?e.state.sourceStack?.[f]??"":""}if(e.state.associativeArrays?.has(o)){let f=$r(a);f=Al(e,f);let d=oe(e,o,f);if(d===void 0&&n&&e.state.options.nounset)throw new Fe(`${o}[${a}]`);return d||""}let u;if(/^-?\d+$/.test(a))u=Number.parseInt(a,10);else try{let f=new G,d=te(f,a);u=await K(e,d.expression)}catch{let f=e.state.env.get(a);u=f?Number.parseInt(f,10):0,Number.isNaN(u)&&(u=0)}if(u<0){let f=Z(e,o),d=e.state.currentLine;if(f.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${o}: 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}: ${o}: bad array subscript
100
+ `,""):oe(e,o,h)||""}let c=oe(e,o,u);if(c!==void 0)return c;if(u===0){let f=e.state.env.get(o);if(f!==void 0)return f}if(n&&e.state.options.nounset)throw new Fe(`${o}[${u}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let o=e.state.env.get(t);if(o===void 0&&n&&e.state.options.nounset)throw new Fe(t);return o||""}if(le(e,t)){let o=Le(e,t);if(o===void 0)return"";if(o!==t)return await re(e,o,n,r);let a=e.state.env.get(t);if((a===void 0||a==="")&&n&&e.state.options.nounset)throw new Fe(t);return a||""}let i=e.state.env.get(t);if(i!==void 0)return e.state.tempEnvBindings?.some(o=>o.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),i;if(ut(e,t)){let o=oe(e,t,0);if(o!==void 0)return o;if(n&&e.state.options.nounset)throw new Fe(t);return""}if(n&&e.state.options.nounset)throw new Fe(t);return""}async function gt(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let s=r[1],i=r[2];if(le(e,s)){let l=Le(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=Al(e,$r(i));return Lt(e,s,l)}let a;if(/^-?\d+$/.test(i))a=Number.parseInt(i,10);else try{let l=new G,u=te(l,i);a=await K(e,u.expression)}catch{let l=e.state.env.get(i);a=l?Number.parseInt(l,10):0,Number.isNaN(a)&&(a=0)}if(a<0){let l=Z(e,s);if(l.length===0)return!1;let c=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+a;return c<0?!1:Lt(e,s,c)}return Lt(e,s,a)}if(le(e,t)){let s=Le(e,t);return s===void 0||s===t?e.state.env.has(t):gt(e,s)}return e.state.env.has(t)?!0:ut(e,t)?Lt(e,t,0):!1}async function vl(e,t){let n="",r=0;for(;r<t.length;){if(t[r]==="$"){if(t[r+1]==="{"){let s=1,i=r+2;for(;i<t.length&&s>0;)t[i]==="{"?s++:t[i]==="}"&&s--,i++;n+=t.slice(r,i),r=i;continue}if(t[r+1]==="("){let s=1,i=r+2;for(;i<t.length&&s>0;)t[i]==="("?s++:t[i]===")"&&s--,i++;n+=t.slice(r,i),r=i;continue}if(/[a-zA-Z_]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await re(e,i);n+=o,r=s;continue}if(/[0-9]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[0-9]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await re(e,i);n+=o,r=s;continue}if(/[*@#?\-!$]/.test(t[r+1]||"")){let s=t[r+1],i=await re(e,s);n+=i,r+=2;continue}}if(t[r]==='"'){for(n+='"',r++;r<t.length&&t[r]!=='"';)if(t[r]==="$"&&/[a-zA-Z_]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await re(e,i);n+=o,r=s}else t[r]==="\\"?(n+=t[r],r++,r<t.length&&(n+=t[r],r++)):(n+=t[r],r++);r<t.length&&(n+='"',r++);continue}n+=t[r],r++}return n}async function Ei(e,t){let n=t,r=t.startsWith('"')&&t.endsWith('"'),s=t.startsWith("'")&&t.endsWith("'");if((r||s)&&(n=t.slice(1,-1)),s)return n;let i="",o=0;for(;o<n.length;)if(n[o]==="$")if(n[o+1]==="("){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="("&&n[l-1]==="$"||n[l]==="("?a++:n[l]===")"&&a--,l++;let u=n.slice(o+2,l-1);if(e.execFn){let c=await e.execFn(u,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}o=l}else if(n[o+1]==="{"){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="{"?a++:n[l]==="}"&&a--,l++;let u=n.slice(o+2,l-1),c=await re(e,u);i+=c,o=l}else if(/[a-zA-Z_]/.test(n[o+1]||"")){let a=o+1;for(;a<n.length&&/[a-zA-Z0-9_]/.test(n[a]);)a++;let l=n.slice(o+1,a),u=await re(e,l);i+=u,o=a}else i+=n[o],o++;else if(n[o]==="`"){let a=o+1;for(;a<n.length&&n[a]!=="`";)a++;let l=n.slice(o+1,a);if(e.execFn){let u=await e.execFn(l,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}o=a+1}else i+=n[o],o++;return i}var er=1e4,bi={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 Hd(e,t,n,r,s,i=bi){let o=n??1;o===0&&(o=1);let a=Math.abs(o),l=[],u=0;if(r?.match(/^-?0\d/)&&(u=Math.max(u,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(u=Math.max(u,s.replace(/^-/,"").length)),u>i.maxStringBytes)throw new 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+=a,p++);else for(let d=e,p=0;d>=t&&p<er&&Br(l,f(d),i,c);d-=a,p++);return l}function Qd(e,t,n,r=bi){let s=n??1;s===0&&(s=1);let i=e.charCodeAt(0),o=t.charCodeAt(0),a=Math.abs(s),l=e>="A"&&e<="Z",u=e>="a"&&e<="z",c=t>="A"&&t<="Z",f=t>="a"&&t<="z";if(l&&f||u&&c){let h=n!==void 0?`..${n}`:"";throw new br(`{${e}..${t}${h}}: invalid sequence`)}let d=[],p={value:0};if(i<=o)for(let h=i,m=0;h<=o&&m<er&&Br(d,String.fromCharCode(h),r,p);h+=a,m++);else for(let h=i,m=0;h>=o&&m<er&&Br(d,String.fromCharCode(h),r,p);h-=a,m++);return d}function Si(e,t,n,r,s,i=bi){let o=n!==void 0?`..${n}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:Hd(e,t,n,r,s,i),literal:`{${e}..${t}${o}}`}:typeof e=="string"&&typeof t=="string"?{expanded:Qd(e,t,n,i),literal:`{${e}..${t}${o}}`}:{expanded:null,literal:`{${e}..${t}${o}}`}}function xl(e){if(e.statements.length!==1)return null;let t=e.statements[0];if(t.operators.length!==0||t.pipelines.length!==1)return null;let n=t.pipelines[0];if(n.negated||n.commands.length!==1)return null;let r=n.commands[0];if(r.type!=="SimpleCommand")return null;let s=r;if(s.name!==null||s.args.length!==0||s.assignments.length!==0||s.redirections.length!==1)return null;let i=s.redirections[0];return i.operator!=="<"||i.target.type!=="Word"?null:{target:i.target}}function wt(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function Ai(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 Pn(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 o=Kd(e,s+1);if(o!==-1){let a=e.slice(s+2,o),u=Xd(a).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=o+1;continue}}if(i==="\\")if(s+1<e.length){let o=e[s+1];/[\\^$.|+(){}[\]*?]/.test(o)?r+=`\\${o}`:r+=o,s+=2}else r+="\\\\",s++;else if(i==="*")r+=t?".*":".*?",s++;else if(i==="?")r+=".",s++;else if(i==="["){let o=Yd(e,s);if(o===-1)r+="\\[",s++;else{let a=e.slice(s+1,o);r+=Jd(a),s=o+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,s++):(r+=i,s++)}return r}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(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function Xd(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 Yd(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 Jd(e){let t="[",n=0;for((e[0]==="^"||e[0]==="!")&&(t+="^",n++);n<e.length;){if(e[n]==="'"){let s=e.indexOf("'",n+1);if(s!==-1){let i=e.slice(n+1,s);for(let o of i)o==="\\"?t+="\\\\":o==="]"?t+="\\]":o==="^"&&t==="["?t+="\\^":t+=o;n=s+1;continue}}if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let s=e.indexOf(":]",n+2);if(s!==-1){let i=e.slice(n+2,s);t+=tp(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 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 tp(e){return ep.get(e)??""}function ct(e,t,n,r,s){if(r==="prefix")return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),me(`^${n}`,"s").replace(t,"");let i=me(`${n}$`,"s");if(s)return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),i.replace(t,"");e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal");let o=me(`^(?:.*)(${n})$`,"s").exec(t);if(!o)return t;let a=o[1]??"";return t.slice(0,t.length-a.length)}function Cn(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 yn(e.limits.maxStringLength,"pattern replacement",()=>new k(`pattern replacement: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length"));n.lastIndex=0;let o=0,a=n.exec(t);for(;a!==null&&(e.executionScope.consumeLimited("pattern_operations",1,e.limits.maxGlobOperations,"pattern replacement"),!(s&&a[0].length===0&&a.index===t.length||(i.append(t.slice(o,a.index)),i.append(r),o=a.index+a[0].length,!s)));)a[0].length===0&&(o++,n.lastIndex<=a.index&&(n.lastIndex=a.index+1)),a=n.exec(t);return i.append(t.slice(o)),n.lastIndex=0,i.build()}function $l(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 np(e,t,n){let r=(o,a=2)=>String(o).padStart(a,"0");if(e===""){let o=r(t.getHours()),a=r(t.getMinutes()),l=r(t.getSeconds());return`${o}:${a}:${l}`}let s=$l(n),i=0;for(;i<e.length;)if(e[i]==="%"){if(i+1>=e.length){s.append("%"),i++;continue}let o=e[i+1];switch(o){case"H":s.append(r(t.getHours()));break;case"M":s.append(r(t.getMinutes()));break;case"S":s.append(r(t.getSeconds()));break;case"d":s.append(r(t.getDate()));break;case"m":s.append(r(t.getMonth()+1));break;case"Y":s.append(String(t.getFullYear()));break;case"y":s.append(r(t.getFullYear()%100));break;case"I":{let a=t.getHours()%12;a===0&&(a=12),s.append(r(a));break}case"p":s.append(t.getHours()<12?"AM":"PM");break;case"P":s.append(t.getHours()<12?"am":"pm");break;case"%":s.append("%");break;case"a":{let a=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];s.append(a[t.getDay()]);break}case"b":{let a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];s.append(a[t.getMonth()]);break}default:s.append(`%${o}`)}i+=2}else s.append(e[i]),i++;return s.build()}function tr(e,t){let n=$l(e.limits.maxStringLength),r=0,s=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",i=e.state.env.get("HOSTNAME")||"localhost",o=i.split(".")[0],a=e.state.env.get("PWD")||"/",l=e.state.env.get("HOME")||"/",u=a.startsWith(l)?`~${a.slice(l.length)}`:a,c=a.split("/").pop()||a,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],p=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],h=e.state.env.get("__COMMAND_NUMBER")||"1";for(;r<t.length;){let m=t[r];if(m==="\\"){if(r+1>=t.length){n.append("\\"),r++;continue}let E=t[r+1];if(E>="0"&&E<="7"){let 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(o),r+=2;break;case"H":n.append(i),r+=2;break;case"w":n.append(u),r+=2;break;case"W":n.append(c),r+=2;break;case"d":{let b=String(f.getDate()).padStart(2," ");n.append(`${d[f.getDay()]} ${p[f.getMonth()]} ${b}`),r+=2;break}case"t":{let b=String(f.getHours()).padStart(2,"0"),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(np(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 Bt(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 Te(e,t){return e.state.readonlyVars?.has(t)??!1}function ue(e,t,n="bash"){if(Te(e,t)){let r=`${n}: ${t}: readonly variable
103
+ `;throw new U(1,"",r)}return null}function ft(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 Wt(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"),Te(e,t)&&(n+="r"),e.state.exportedVars?.has(t)&&(n+="x"),n}async function kl(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 Pl(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:assign_default"),(r.isUnset||n.checkEmpty&&r.isEmpty)&&n.word){let o=await s(e,n.word.parts,r.inDoubleQuotes),a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let[,l,u]=a,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,o)}else e.state.env.set(t,o);return o}return r.effectiveValue}async function Cl(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:error_if_unset"),r.isUnset||n.checkEmpty&&r.isEmpty){let o=n.word?await s(e,n.word.parts,r.inDoubleQuotes):`${t}: parameter null or not set`;throw new U(1,"",`bash: ${o}
104
+ `)}return r.effectiveValue}async function Nl(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 Rl(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_removal");let i="",o=e.state.shoptOptions.extglob;if(n.pattern)for(let a of n.pattern.parts)if(a.type==="Glob")i+=X(a.pattern,n.greedy,o);else if(a.type==="Literal")i+=X(a.value,n.greedy,o);else if(a.type==="SingleQuoted"||a.type==="Escaped")i+=J(a.value);else if(a.type==="DoubleQuoted"){let l=await r(e,a.parts);i+=J(l)}else if(a.type==="ParameterExpansion"){let l=await s(e,a);i+=X(l,n.greedy,o)}else{let l=await s(e,a);i+=J(l)}return ct(e,t,i,n.side,n.greedy)}async function Dl(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",o=e.state.shoptOptions.extglob;if(n.pattern)for(let u of n.pattern.parts)if(u.type==="Glob")i+=X(u.pattern,!0,o);else if(u.type==="Literal")i+=X(u.value,!0,o);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,o)}else{let c=await s(e,u);i+=J(c)}let a=n.replacement?await r(e,n.replacement.parts):"";if(n.anchor==="start"?i=`^${i}`:n.anchor==="end"&&(i=`${i}$`),i==="")return t;let l=n.all?"gs":"s";try{let u=me(i,l);return Wr(e,t,u,a,n.all)}catch(u){if(u instanceof k)throw u;return t}}function Il(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)&&ut(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=oe(e,t,0)||"";return String([...s].length)}return String([...n].length)}async function Ol(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 o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(o){let u=o[1];if(e.state.associativeArrays?.has(u))throw new U(1,"",`bash: \${${u}[@]: 0: 3}: bad substitution
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 ae(`${o[1]}[@]: substring expression < 0`);return c.slice(f,f+i).map(([,d])=>d).join(" ")}return c.slice(f).map(([,d])=>d).join(" ")}let a=[...n],l=s;if(l<0&&(l=Math.max(0,a.length+l)),i!==void 0){if(i<0){let u=a.length+i;return a.slice(l,Math.max(l,u)).join("")}return a.slice(l,l+i).join("")}return a.slice(l).join("")}async function _l(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:case_modification"),n.pattern){let i=e.state.shoptOptions.extglob,o="";for(let f of n.pattern.parts)if(f.type==="Glob")o+=X(f.pattern,!0,i);else if(f.type==="Literal")o+=X(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")o+=J(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);o+=J(d)}else if(f.type==="ParameterExpansion"){let d=await s(e,f);o+=X(d,!0,i)}let a=me(`^(?:${o})$`),l=n.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),u="",c=!1;for(let f of t)!n.all&&c?u+=f:a.test(f)?(u+=l(f),c=!0):u+=f;return u}return n.direction==="upper"?n.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):n.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function Ll(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])=>Bt(u)).join(" ");if(i&&s.operator==="a")return Wt(e,i[1]);let o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(o&&s.operator==="a")return Wt(e,o[1]);switch(s.operator){case"Q":return r?"":Bt(n);case"P":return tr(e,n);case"a":return Wt(e,t);case"A":return r?"":`${t}=${Bt(n)}`;case"E":return n.replace(/\\([\\abefnrtv'"?])/g,(a,l)=>{switch(l){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
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?"":Bt(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 Tl(e,t,n,r,s,i,o=!1){if(e.coverage?.hit("bash:expansion:indirection"),le(e,t))return cn(e,t)||"";let a=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(s.innerOp?.type==="UseAlternative")return"";throw new Ze(`\${!${t}}`)}let l=n;if(a&&(l===""||l.includes(" ")))throw new Ze(`\${!${t}}`);let u=l.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new Ze(`\${!${t}}`);if(s.innerOp){let c={type:"ParameterExpansion",parameter:l,operation:s.innerOp};return i(e,c,o)}return await re(e,l)}function Ml(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 Fl(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let n=Cn(e,t.prefix);return t.star?n.join(H(e.state.env)):n.join(" ")}function Bl(e,t,n,r){let s=Number.parseInt(e.state.env.get("#")||"0",10),i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:s===0,effectiveValue:n};if(t==="@")return{isEmpty:s===0||s===1&&e.state.env.get("1")==="",effectiveValue:n};if(i){let[,o,a]=i,l=Z(e,o);if(l.length===0)return{isEmpty:!0,effectiveValue:""};if(a==="*"){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 Wl(e){let t=0;for(;t<e.length;){let n=e[t];if(n==="\\"&&t+1<e.length){t+=2;continue}if(n==="'"){let r=e.indexOf("'",t+1);if(r!==-1){t=r+1;continue}}if(n==="$"&&t+1<e.length&&e[t+1]==="("||n==="`")return!0;t++}return!1}function Vl(e,t){let n=1,r=t,s=!1,i=!1;for(;r<e.length&&n>0;){let o=e[r];if(o==="\\"&&!s&&r+1<e.length){r+=2;continue}if(o==="'"&&!i){s=!s,r++;continue}if(o==='"'&&!s){i=!i,r++;continue}if(!s&&!i){if(o==="(")n++;else if(o===")"&&(n--,n===0))return r}r++}return-1}async function 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),o=tt(e.state.arrays),a=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let u=await e.executeScript(r),c=u.exitCode;return e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.suppressVerbose=l,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=o,e.state.cwd=a,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 vi(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=Ke(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=rp(e,a);n+=Ke(l),r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}function rp(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){n+=i,r+=2;continue}n+=s,r++;continue}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}n+=s,r++}return n}async function zl(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=Ke(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=await sp(e,a);n+=Ke(l),r=i+1;continue}}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=Vl(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await zr(e,o);n+=a,r=i+1;continue}}if(s==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let o=t.slice(r+1,i),a=await zr(e,o);n+=a,r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}async function sp(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=Vl(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await zr(e,o);n+=a,r=i+1;continue}}if(s==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let o=t.slice(r+1,i),a=await zr(e,o);n+=a,r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}n+=s,r++}return n}function 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 Vt(e,t){return t.split(":").map(n=>xi(e,n)).join(":")}function Ne(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 ip(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 o=await n(e,i.parts);s+=J(o)}else if(i.type==="ParameterExpansion"){let o=await r(e,i);s+=X(o,!0,e.state.shoptOptions.extglob)}else{let o=await r(e,i);s+=J(o)}return s}async function ql(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternReplacement")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",u=i.operation,c=Z(e,a),f=c.map(([,E])=>E);if(c.length===0){let E=e.state.env.get(a);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let d="";u.pattern&&(d=await ip(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 Ul(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternRemoval")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",u=i.operation,c=Z(e,a),f=c.map(([,m])=>m);if(c.length===0){let m=e.state.env.get(a);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(ct(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 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?.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_]*)\[([@*])\]$/),o,a=!1;if(i){let l=i[1];a=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"?o=c&&!(d&&f):o=!c||d&&f,!o){if(u.length>0){let h=u.map(([,m])=>m);if(a){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 gt(e,l),c=await re(e,l),f=c==="",d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=u&&!(d&&f):o=!u||d&&f,!o)return{values:[c],quoted:!0}}if(o&&s.word){let l=s.word.parts,u=null,c=!1;for(let f of l)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){u=d[1],c=d[2]==="*";break}}if(u){let f=Z(e,u);if(f.length>0){let p=f.map(([,h])=>h);if(c||a){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 Gl(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0],o=-1,a="",l=!1,u=null;for(let m=0;m<i.parts.length;m++){let E=i.parts[m];if(E.type==="ParameterExpansion"&&(E.operation?.type==="PatternRemoval"||E.operation?.type==="PatternReplacement")){let b=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){o=m,a=b[1],l=b[2]==="*",u=E.operation;break}}}if(o===-1||o===0&&o===i.parts.length-1)return null;let c="";for(let m=0;m<o;m++)c+=await r(e,i.parts[m]);let f="";for(let m=o+1;m<i.parts.length;m++)f+=await r(e,i.parts[m]);let d=Z(e,a),p=d.map(([,m])=>m);if(d.length===0){let m=e.state.env.get(a);if(m!==void 0)p=[m];else{if(l)return{values:[c+f],quoted:!0};let E=c+f;return{values:E?[E]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let m=u,E="",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=>ct(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 Zl(e,t,n,r){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o="",a=!1;for(let p=0;p<s.parts.length;p++){let h=s.parts[p];if(h.type==="ParameterExpansion"&&!h.operation){let m=h.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(m){i=p,o=m[1],a=m[2]==="*";break}}}if(i===-1)return null;let l="";for(let p=0;p<i;p++)l+=await r(e,s.parts[p]);let u="";for(let p=i+1;p<s.parts.length;p++)u+=await r(e,s.parts[p]);let c=Z(e,o),f=c.map(([,p])=>p);if(c.length===0){let p=e.state.env.get(o);if(p!==void 0)return{values:[l+p+u],quoted:!0};if(a)return{values:[l+u],quoted:!0};let h=l+u;return{values:h?[h]:[],quoted:!0}}if(a){let p=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 Hl(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Substring")return null;let s=r.parts[0],i=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let o=i[1],a=i[2]==="*",l=s.operation;if(e.state.associativeArrays?.has(o))throw new U(1,"",`bash: \${${o}[@]: 0: 3}: bad substitution
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,o);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 ae(`${o}[@]: substring expression < 0`);p=f.slice(d,d+c).map(([,h])=>h)}else p=f.slice(d).map(([,h])=>h);if(p.length===0)return{values:[],quoted:!0};if(a){let h=H(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}function Ql(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="Transform")return null;let r=n.parts[0],s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!s)return null;let i=s[1],o=s[2]==="*",a=r.operation,l=Z(e,i);if(l.length===0){let d=e.state.env.get(i);if(d!==void 0){let p;switch(a.operator){case"a":p="";break;case"P":p=tr(e,d);break;case"Q":p=Bt(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 o?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=Wt(e,i),c=[],f=0;for(let[,d]of l){let p;switch(a.operator){case"a":p=u;break;case"P":p=tr(e,d);break;case"Q":p=Bt(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(o){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 Kl(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion")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=cn(e,i);if(l?.endsWith("[@]")||l?.endsWith("[*]"))return{values:[],quoted:!0}}let o=Z(e,i);if(o.length>0)return{values:o.map(([,l])=>l),quoted:!0};let a=e.state.env.get(i);return a!==void 0?{values:[a],quoted:!0}:{values:[],quoted:!0}}function 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)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=cn(e,s);if(!i)return null;let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!o)return null;let a=o[1],l=Z(e,a);if(l.length>0)return{values:l.map(([,c])=>c),quoted:!0};let u=e.state.env.get(a);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function Yl(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let o=i.parts[0],a=o.operation,l=await re(e,o.parameter),u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!a.innerOp&&(l==="@"||l==="*")){let h=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let E=1;E<=h;E++)m.push(e.state.env.get(String(E))||"");return l==="*"?{values:[m.join(H(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let c=u[1],f=u[2]==="*",d=Z(e,c);if(a.innerOp){if(a.innerOp.type==="Substring")return op(e,d,c,f,a.innerOp);if(a.innerOp.type==="DefaultValue"||a.innerOp.type==="UseAlternative"||a.innerOp.type==="AssignDefault"||a.innerOp.type==="ErrorIfUnset")return ap(e,d,c,f,a.innerOp,s);if(a.innerOp.type==="Transform"&&a.innerOp.operator==="a"){let m=Wt(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:a.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 op(e,t,n,r,s){let i=s.offset?await K(e,s.offset.expression):0,o=s.length?await K(e,s.length.expression):void 0,a=0;if(i<0){if(t.length>0){let c=t[t.length-1][0],d=(typeof c=="number"?c:0)+1+i;if(d<0)return{values:[],quoted:!0};if(a=t.findIndex(([p])=>typeof p=="number"&&p>=d),a<0)return{values:[],quoted:!0}}}else if(a=t.findIndex(([c])=>typeof c=="number"&&c>=i),a<0)return{values:[],quoted:!0};let l;if(o!==void 0){if(o<0)throw new ae(`${n}[@]: substring expression < 0`);l=t.slice(a,a+o)}else l=t.slice(a);let u=l.map(([,c])=>c);return r?{values:[u.join(H(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function ap(e,t,n,r,s,i){let o=s.checkEmpty??!1,a=t.map(([,c])=>c),l=t.length===0,u=t.length===0;if(s.type==="UseAlternative")return!u&&!(o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(s.type==="DefaultValue")return(u||o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:r?{values:[a.join(H(e.state.env))],quoted:!0}:{values:a,quoted:!0};if(s.type==="AssignDefault"){if((u||o&&l)&&s.word){let f=await i(e,s.word.parts,!0);return j(e,n,0,f),{values:[f],quoted:!0}}return r?{values:[a.join(H(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return r?{values:[a.join(H(e.state.env))],quoted:!0}:{values:a,quoted:!0}}async function Jl(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let n=t[0],r=n.operation,s=r?.word;if(!s||s.parts.length!==1||s.parts[0].type!=="DoubleQuoted")return null;let i=s.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let o=i.parts[0],l=(await re(e,o.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!l)return null;let u=await gt(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 eu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let n=t[0],s=n.operation.innerOp;if(!s||s.type!=="UseAlternative"&&s.type!=="DefaultValue")return null;let i=s.word;if(!i||i.parts.length!==1||i.parts[0].type!=="DoubleQuoted")return null;let o=i.parts[0];if(o.parts.length!==1||o.parts[0].type!=="ParameterExpansion"||o.parts[0].operation?.type!=="Indirection")return null;let a=o.parts[0],u=(await re(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await re(e,n.parameter),f=await gt(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 tu(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))||"",o=F(i);if(o>e.limits.maxStringLength-r)throw new k(`positional parameter string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n.push(i),r+=o}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 $i(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 nu(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!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,o=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(o){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 ru(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!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,o=y.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,u=tu(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 $=g.exec(y);$&&(S++,!!l.all);$=g.exec(y))$[0].length===0&&g.lastIndex++;let v=F(y),x=F(p),A=0,C=/\$(?:\$|&|\d+|<[^>]+>|`|')/g;for(;C.exec(p)!==null;)A++;if(v+S*x+S*A*v>e.limits.maxStringLength-E.value)throw new k(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");$i(m,g.replace(y,p),E,e)}}catch(g){if(g instanceof k)throw g;for(let y of u)$i(m,y,E,e)}if(o){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 su(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let b=0;b<s.parts.length;b++){let g=s.parts[b];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="PatternRemoval"){i=b,o=g.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,u=tu(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)$i(h,ct(e,b,d,l.side,l.greedy),m,e);if(o){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 iu(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0],s=-1,i=!1;for(let d=0;d<r.parts.length;d++){let p=r.parts[d];if(p.type==="ParameterExpansion"&&(p.parameter==="@"||p.parameter==="*")){s=d,i=p.parameter==="*";break}}if(s===-1)return null;let o=r.parts[s];if(o.type==="ParameterExpansion"&&o.operation)return null;let a=Number.parseInt(e.state.env.get("#")||"0",10),l="";for(let d=0;d<s;d++)l+=await n(e,r.parts[d]);let u="";for(let d=s+1;d<r.parts.length;d++)u+=await n(e,r.parts[d]);if(a===0){if(i)return{values:[l+u],quoted:!0};let d=l+u;return{values:d?[d]:[],quoted:!0}}let c=[];for(let d=1;d<=a;d++)c.push(e.state.env.get(String(d))||"");if(i){let d=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 Et(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 ki(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 lp(e){return new Ft(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=lp(e),r=[];for(let s of t)if(wt(s,e.state.shoptOptions.extglob)){let i=await n.expand(s);if(i.length>0)Ne(r,i,e.limits.maxArrayElements,"unquoted glob expansion");else{if(n.hasFailglob())throw new Ct(s);n.hasNullglob()||r.push(s)}}else r.push(s);return r}async function ou(e,t,n,r){let s=-1,i="",o=!1;for(let S=0;S<t.length;S++){let v=t[S];if(v.type==="ParameterExpansion"&&v.operation?.type==="PatternReplacement"){let x=v.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(x){s=S,i=x[1],o=x[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)Et(e,h,Wr(e,v,S,d,l.all),m)}catch(S){if(S instanceof k)throw S;for(let v of c)Et(e,h,v,m)}let E=Ae(e.state.env),b=Ce(e.state.env);if(o){let S=H(e.state.env),v=ki(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==="")Et(e,g,"",y);else for(let v of ce(S,E,e.limits.maxArrayElements))Et(e,g,v,y);return{values:g,quoted:!1}}async function au(e,t,n,r){let s=-1,i="",o=!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],o=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)Et(e,p,ct(e,y,f,l.side,l.greedy),h);let m=Ae(e.state.env),E=Ce(e.state.env);if(o){let y=H(e.state.env),S=ki(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==="")Et(e,b,"",g);else for(let S of ce(y,m,e.limits.maxArrayElements))Et(e,b,S,g);return{values:b,quoted:!1}}async function lu(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 a=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(a.pattern)for(let g of a.pattern.parts)if(g.type==="Glob")c+=X(g.pattern,a.greedy,f);else if(g.type==="Literal")c+=X(g.value,a.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,a.greedy,f)}else{let y=await r(e,g);c+=J(y)}let d=[],p={value:0};for(let g of u)Et(e,d,ct(e,g,c,a.side,a.greedy),p);let h=Ae(e.state.env),m=Ce(e.state.env);if(i){let g=H(e.state.env),y=ki(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==="")Et(e,E,"",b);else for(let y of ce(g,h,e.limits.maxArrayElements))Et(e,E,y,b);return{values:E,quoted:!1}}async function uu(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 a=t[s].operation,l=a.offset?await n(e,a.offset.expression):0,u=a.length?await n(e,a.length.expression):void 0,c=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let 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 x=u<0?y.length+u:v+u;p=y.slice(v,Math.max(v,x))}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=Ce(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);Ne(g,v,e.limits.maxArrayElements,"unquoted expansion")}}}return{values:await Ur(e,g),quoted:!1}}async function cu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let n=t[0].parameter==="*",r=Number.parseInt(e.state.env.get("#")||"0",10);if(r===0)return{values:[],quoted:!1};let s=[];for(let u=1;u<=r;u++)s.push(e.state.env.get(String(u))||"");let i=Ae(e.state.env),o=Ce(e.state.env),a=Lr(e.state.env),l;if(n)if(o)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(o)l=s.filter(u=>u!=="");else if(a){l=[];for(let u of s){if(u==="")continue;let c=ce(u,i,e.limits.maxArrayElements);Ne(l,c,e.limits.maxArrayElements,"unquoted expansion")}}else{l=[];for(let u of s)if(u==="")l.push("");else{let c=ce(u,i,e.limits.maxArrayElements);Ne(l,c,e.limits.maxArrayElements,"unquoted expansion")}for(;l.length>0&&l[l.length-1]==="";)l.pop()}return{values:await Ur(e,l),quoted:!1}}async function fu(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),o;if(i.length===0){let f=e.state.env.get(r);if(f!==void 0)o=[f];else return{values:[],quoted:!1}}else o=i.map(([,f])=>f);let a=Ae(e.state.env),l=Ce(e.state.env),u=Lr(e.state.env),c;if(s)if(l)c=o.filter(f=>f!=="");else{let f=H(e.state.env),d=o.join(f);c=ce(d,a,e.limits.maxArrayElements)}else if(l)c=o.filter(f=>f!=="");else if(u){c=[];for(let f of o){if(f==="")continue;let d=ce(f,a,e.limits.maxArrayElements);Ne(c,d,e.limits.maxArrayElements,"unquoted expansion")}}else{c=[];for(let f of o)if(f==="")c.push("");else{let d=ce(f,a,e.limits.maxArrayElements);Ne(c,d,e.limits.maxArrayElements,"unquoted expansion")}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Ur(e,c),quoted:!1}}function du(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let n=t[0].operation,r=Cn(e,n.prefix);if(r.length===0)return{values:[],quoted:!1};let s=Ae(e.state.env),i=Ce(e.state.env),o;if(n.star)if(i)o=r;else{let a=H(e.state.env),l=r.join(a);o=ce(l,s,e.limits.maxArrayElements)}else if(i)o=r;else{o=[];for(let a of r){let l=ce(a,s,e.limits.maxArrayElements);Ne(o,l,e.limits.maxArrayElements,"unquoted expansion")}}return{values:o,quoted:!1}}function pu(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),o=Ce(e.state.env),a;if(n.star)if(o)a=s;else{let l=H(e.state.env),u=s.join(l);a=ce(u,i,e.limits.maxArrayElements)}else if(o)a=s;else{a=[];for(let l of s){let u=ce(l,i,e.limits.maxArrayElements);Ne(a,u,e.limits.maxArrayElements,"unquoted expansion")}}return{values:a,quoted:!1}}async function hu(e,t,n){let r=-1;for(let d=0;d<t.length;d++){let p=t[d];if(p.type==="ParameterExpansion"&&(p.parameter==="@"||p.parameter==="*")&&!p.operation){r=d;break}}if(r===-1||t.length<=1)return null;let s=Number.parseInt(e.state.env.get("#")||"0",10),i=[];for(let d=1;d<=s;d++)i.push(e.state.env.get(String(d))||"");let o="";for(let d=0;d<r;d++)o+=await n(e,t[d]);let a="";for(let d=r+1;d<t.length;d++)a+=await n(e,t[d]);let l=Ae(e.state.env),u=Ce(e.state.env),c=Lr(e.state.env);if(s===0){let d=o+a;return{values:d?[d]:[],quoted:!1}}let f;{let d=[];for(let p=0;p<i.length;p++){let h=i[p];p===0&&(h=o+h),p===i.length-1&&(h=h+a),d.push(h)}if(u)f=d.filter(p=>p!=="");else if(c){f=[];for(let p of d){if(p==="")continue;let h=ce(p,l,e.limits.maxArrayElements);Ne(f,h,e.limits.maxArrayElements,"unquoted expansion")}}else{f=[];for(let p of d)if(p==="")f.push("");else{let h=ce(p,l,e.limits.maxArrayElements);Ne(f,h,e.limits.maxArrayElements,"unquoted expansion")}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Ur(e,f),quoted:!1}}async function gu(e,t,n){e.coverage?.hit("bash:expansion:word_glob");let r=t.parts,{hasQuoted:s,hasCommandSub:i,hasArrayVar:o,hasArrayAtExpansion:a,hasParamExpansion:l,hasVarNamePrefixExpansion:u,hasIndirection:c}=Jn(r),d=n.hasBraceExpansion(r)?await n.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return up(e,d,s);let p=await cp(e,r,a,u,c,n);if(p!==null)return p;let h=await dp(e,r,n);if(h!==null)return h;let m=await pp(e,r,n);if(m!==null)return m;let E=await mp(e,r,n.expandPart);if(E!==null)return yu(e,E);if((i||o||l)&&!Ce(e.state.env)){let g=Ae(e.state.env),y=n.buildIfsCharClassPattern(g),S=await n.smartWordSplit(e,r,g,y,n.expandPart);return yu(e,S)}let b=await n.expandWordAsync(e,t);return yp(e,t,r,b,s,n.expandWordForGlobbing)}async function up(e,t,n){let r=[];for(let s of t)if(!(!n&&s===""))if(!n&&!e.state.options.noglob&&wt(s,e.state.shoptOptions.extglob)){let i=await jr(e,s);Ne(r,i,e.limits.maxArrayElements,"brace/glob expansion")}else r.push(s);return{values:r,quoted:!1}}async function cp(e,t,n,r,s,i){if(n){let o=Kl(e,t);if(o!==null)return o}{let o=Xl(e,t);if(o!==null)return o}{let o=await jl(e,t);if(o!==null)return o}{let o=await Gl(e,t,n,i.expandPart,i.expandWordPartsAsync);if(o!==null)return o}{let o=await Zl(e,t,n,i.expandPart);if(o!==null)return o}{let o=await Hl(e,t,i.evaluateArithmetic);if(o!==null)return o}{let o=Ql(e,t);if(o!==null)return o}{let o=await ql(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}{let o=await Ul(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let o=fp(e,t);if(o!==null)return o}{let o=await Yl(e,t,s,i.expandParameterAsync,i.expandWordPartsAsync);if(o!==null)return o}{let o=await Jl(e,t);if(o!==null)return o}{let o=await eu(e,t);if(o!==null)return o}return null}function fp(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=Cn(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(([o])=>String(o));return r.star?{values:[i.join(H(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function dp(e,t,n){{let r=await nu(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await ru(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await su(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await iu(e,t,n.expandPart);if(r!==null)return r}return null}async function pp(e,t,n){{let r=await ou(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await au(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await lu(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await uu(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await cu(e,t);if(r!==null)return r}{let r=await fu(e,t);if(r!==null)return r}{let r=du(e,t);if(r!==null)return r}{let r=pu(e,t);if(r!==null)return r}{let r=await hu(e,t,n.expandPart);if(r!==null)return r}return null}function mu(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 hp(e,t,n,r){let s="";for(let a=0;a<n.atIndex;a++)s+=await r(e,t.parts[a]);let i="";for(let a=n.atIndex+1;a<t.parts.length;a++)i+=await r(e,t.parts[a]);let o;if(n.type==="array"){if(o=Z(e,n.name).map(([,l])=>l),o.length===0){let l=e.state.env.get(n.name);l!==void 0&&(o=[l])}}else{let a=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let l=1;l<=a;l++)o.push(e.state.env.get(String(l))||"")}if(n.isStar){let a=H(e.state.env),l=o.join(a);return[s+l+i]}if(o.length===0){let a=s+i;return a?[a]:[]}return o.length===1?[s+o[0]+i]:[s+o[0],...o.slice(1,-1),o[o.length-1]+i]}async function mp(e,t,n){if(t.length<2)return null;let r=!1;for(let l of t)if(mu(l)){r=!0;break}if(!r)return null;let s=Ae(e.state.env),i=Ce(e.state.env),o=[];for(let l of t){let u=mu(l);if(u&&l.type==="DoubleQuoted"){let c=await hp(e,l,u,n);o.push(c)}else if(l.type==="DoubleQuoted"||l.type==="SingleQuoted"){let c=await n(e,l);o.push([c])}else if(l.type==="Literal")o.push([l.value]);else if(l.type==="ParameterExpansion"){let c=await n(e,l);if(i)o.push(c?[c]:[]);else{let f=ce(c,s,e.limits.maxArrayElements);o.push(f)}}else{let c=await n(e,l);if(i)o.push(c?[c]:[]);else{let f=ce(c,s,e.limits.maxArrayElements);o.push(f)}}}let a=[];for(let l of o)if(l.length!==0)if(a.length===0)Ne(a,l,e.limits.maxArrayElements,"word expansion");else{let u=a.length-1;a[u]=a[u]+l[0];for(let c=1;c<l.length;c++)a.push(l[c])}return a}async function yu(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let n=[];for(let r of t)if(wt(r,e.state.shoptOptions.extglob)){let s=await jr(e,r);Ne(n,s,e.limits.maxArrayElements,"glob expansion")}else n.push(r);return{values:n,quoted:!1}}async function jr(e,t){let n=new Ft(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 Ct(t);return n.hasNullglob()?[]:[t]}async function yp(e,t,n,r,s,i){let o=n.some(a=>a.type==="Glob");if(!e.state.options.noglob&&o){let a=await i(e,t);if(wt(a,e.state.shoptOptions.extglob)){let u=await jr(e,a);if(u.length>0&&u[0]!==a)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let l=Ai(r);if(!Ce(e.state.env)){let u=Ae(e.state.env);return{values:ce(l,u,e.limits.maxArrayElements),quoted:!1}}return{values:[l],quoted:!1}}if(!s&&!e.state.options.noglob&&wt(r,e.state.shoptOptions.extglob)){let a=await i(e,t);if(wt(a,e.state.shoptOptions.extglob)){let l=await jr(e,a);if(l.length>0&&l[0]!==a)return{values:l,quoted:!1}}}if(r===""&&!s)return{values:[],quoted:!1};if(o&&!s){let a=Ai(r);if(!Ce(e.state.env)){let l=Ae(e.state.env);return{values:ce(a,l,e.limits.maxArrayElements),quoted:!1}}return{values:[a],quoted:!1}}return{values:[r],quoted:s}}function Ie(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 Eu(e,t){let n=t.operation;if(!n||n.type!=="DefaultValue"&&n.type!=="AssignDefault"&&n.type!=="UseAlternative")return null;let r=n.word;if(!r||r.parts.length===0)return null;let s=await gt(e,t.parameter),o=await re(e,t.parameter,!1)==="",a=n.checkEmpty??!1,l;return n.type==="UseAlternative"?l=s&&!(a&&o):l=!s||a&&o,l?r.parts:null}function gp(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(n=>n.type==="Literal"):!1}async function wp(e,t){if(t.type!=="ParameterExpansion")return null;let n=await Eu(e,t);if(!n||n.length<=1)return null;let r=n.some(i=>gp(i)),s=n.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&s?n:null}function Ep(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?hi(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&yl(e))}async function bu(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 Eu(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 wu(e,p,n,r,s)}let i=[],o=!1;for(let d of t){let p=Ep(d),h=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=p?await wp(e,d):null,E=await s(e,d);i.push({value:E,isSplittable:p,isQuoted:h,mixedDefaultParts:m??void 0}),p&&(o=!0)}if(!o){let d=i.map(p=>p.value).join("");return d?[d]:[]}let a=[],l="",u=!1,c=!1,f=!1;for(let d of i)if(!d.isSplittable)c?d.isQuoted&&d.value===""?(l!==""&&Ie(e,a,l),Ie(e,a,""),u=!0,l="",c=!1,f=!0):d.value!==""?(l!==""&&Ie(e,a,l),l=d.value,c=!1,f=!1):(l+=d.value,f=!1):(l+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let p=await wu(e,d.mixedDefaultParts,n,r,s);if(p.length!==0)if(p.length===1)l+=p[0],u=!0;else{l+=p[0],Ie(e,a,l),u=!0;for(let h=1;h<p.length-1;h++)Ie(e,a,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===""&&(Ie(e,a,""),u=!0),p.length===0)m&&(c=!0);else if(p.length===1)l+=p[0],u=!0,c=m;else{l+=p[0],Ie(e,a,l),u=!0;for(let E=1;E<p.length-1;E++)Ie(e,a,p[E]);l=p[p.length-1],c=m}f=!1}return l!==""?Ie(e,a,l):a.length===0&&u&&Ie(e,a,""),a}function bp(e,t){return e.length>0&&t.includes(e[0])}async function wu(e,t,n,r,s){let i=[];for(let c of t){let d=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),p=await s(e,c);i.push({value:p,isSplittable:d})}let o=[],a="",l=!1,u=!1;for(let c of i)if(!c.isSplittable)u&&c.value!==""?(a!==""&&Ie(e,o,a),a=c.value,u=!1):a+=c.value;else{bp(c.value,n)&&a!==""&&(Ie(e,o,a),a="",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)a+=d[0],l=!0,u=p;else{a+=d[0],Ie(e,o,a),l=!0;for(let h=1;h<d.length-1;h++)Ie(e,o,d[h]);a=d[d.length-1],u=p}}return a!==""?Ie(e,o,a):o.length===0&&l&&Ie(e,o,""),o}function Su(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Au(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 ht,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 o=i.mountPoint;if(n===o)return{fs:i.filesystem,relativePath:"/"};n.startsWith(`${o}/`)&&o.length>s&&(r=i,s=o.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 a=i.slice(r.length).split("/")[0];a&&!s.includes(a)&&s.push(a)}return s}async readFile(t,n){let{fs:r,relativePath:s}=this.routePath(t);return r.readFile(s,n)}async readFileBytes(t){let{fs:n,relativePath:r}=this.routePath(t);return hn(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:o}=this.routePath(t);return i.stat(o)}async lstat(t){let n=z(t),r=this.mounts.get(n);if(r)try{return await r.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:o}=this.routePath(t);return i.lstat(o)}async mkdir(t,n){let r=z(t);if(this.mounts.has(r)){if(n?.recursive)return;throw new Error(`EEXIST: directory already exists, mkdir '${t}'`)}if(this.getChildMountPoints(r).length>0&&n?.recursive)return;let{fs:i,relativePath:o}=this.routePath(t);return i.mkdir(o,n)}async readdir(t){let n=z(t),r=new Set,s=null,{fs:i,relativePath:o}=this.routePath(t);try{let l=await i.readdir(o);for(let u of l)r.add(u)}catch(l){let u=l.code,c=l.message||"";if(u!=="ENOENT"&&!c.includes("ENOENT"))throw l;s=l}let a=this.getChildMountPoints(n);for(let l of a)r.add(l);if(r.size===0&&s&&!this.mounts.has(n))throw s;return Array.from(r).sort()}async rm(t,n){let r=z(t);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot remove '${t}'`);if(this.getChildMountPoints(r).length>0)throw new Error(`EBUSY: contains mount points, cannot remove '${t}'`);let{fs:i,relativePath:o}=this.routePath(t);return i.rm(o,n)}async cp(t,n,r){if((await this.stat(t)).isDirectory&&vt(t,n))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);let i=this.routePath(t),o=this.routePath(n);return i.fs===o.fs?i.fs.cp(i.relativePath,o.relativePath,r):this.crossMountCopy(t,n,r)}async mv(t,n){let r=z(t);if((await this.stat(t)).isDirectory&&vt(t,n))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot move '${t}'`);let i=this.routePath(t),o=this.routePath(n);if(i.fs===o.fs)return i.fs.mv(i.relativePath,o.relativePath);await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return wn(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 o of r)s=`${s}/${o}`,t.add(s);let i=this.mounts.get(n);if(i)for(let o of i.filesystem.getAllPaths())o==="/"?t.add(n):t.add(`${n}${o}`)}return Array.from(t).sort()}async chmod(t,n){let r=z(t),s=this.mounts.get(r);if(s)return s.filesystem.chmod("/",n);let{fs:i,relativePath:o}=this.routePath(t);return i.chmod(o,n)}async symlink(t,n){let{fs:r,relativePath:s}=this.routePath(n);return r.symlink(t,s)}async link(t,n){let r=this.routePath(t),s=this.routePath(n);if(r.fs!==s.fs)throw new Error(`EXDEV: cross-device link not permitted, link '${t}' -> '${n}'`);return r.fs.link(r.relativePath,s.relativePath)}async readlink(t){let{fs:n,relativePath:r}=this.routePath(t);return n.readlink(r)}async realpath(t){let n=z(t);if(this.mounts.get(n))return n;let{fs:s,relativePath:i}=this.routePath(t),o=await s.realpath(i);for(let[a,l]of this.mounts)if(n===a||n.startsWith(`${a}/`))return o==="/"?a:`${a}${o}`;return o}async crossMountCopy(t,n,r){let s=await this.lstat(t);if(s.isFile){let i=await this.readFileBuffer(t);await this.writeFile(n,i),await this.chmod(n,s.mode)}else if(s.isDirectory){if(!r?.recursive)throw new Error(`cp: ${t} is a directory (not copied)`);await this.mkdir(n,{recursive:!0});let i=await this.readdir(t);for(let o of i){let a=xt(t,o),l=xt(n,o);await this.crossMountCopy(a,l,r)}}else if(s.isSymbolicLink){let i=await this.readlink(t);await this.symlink(i,n)}}async utimes(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.utimes(i,n,r)}};var Gr="/dev/fd",xu=63,Sp=10,vu=xu-Sp+1,Pi=class extends ht{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 Ap(e){let t=new Pi(n=>$u(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 vp(e,t,n){try{await e.fs.writeFile(t,n,"binary");return}catch(r){if(e.state.processSubstitutionFsMounted)throw r;Ap(e)}await e.fs.writeFile(t,n,"binary")}async function xp(e,t){try{await e.fs.rm(t,{force:!0})}catch{}}function $u(e){let t=e.state.processSubstitutions;if(t)return t;let n=[];return e.state.processSubstitutions=n,n}async function ku(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,o=new Map(e.state.env),a=tt(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=o,e.state.arrays=a,e.state.cwd=l,e.state.bashPid=u,e.state.suppressVerbose=c,e.state.groupStdin=f,e.state.lastExitCode=d,p!==void 0?e.state.env.set("?",p):e.state.env.delete("?")}return h}async function Pu(e,t){let n=$u(e);if(n.length>=vu)throw new k(`Process substitution limit exceeded (${vu} concurrent)`,"file_descriptors");let r="";if(t.direction==="input"){let o=await ku(e,t.body,void 0);if(o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),r=Pt(o),r.length>e.limits.maxStringLength)throw new k(`process substitution: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")}let s=xu-n.length,i=`${Gr}/${s}`;n.push({fd:s,path:i,direction:t.direction,body:t.body});try{await vp(e,i,r)}catch(o){throw n.pop(),o}return i}function Cu(e){return e.state.processSubstitutions?.length??0}var $p={stdout:"",stderr:""};async function Ci(e,t){let n=e.state.processSubstitutions;if(!n||n.length<=t)return $p;let r="",s="";for(;n.length>t;){let i=n[n.length-1],o="";if(i.direction==="output")try{o=await hn(e.fs,i.path)}catch{}if(await xp(e,i.path),n.pop(),i.direction==="output"){let a=await ku(e,i.body,o);r+=Pt(a),s+=a.stderr}}return{stdout:r,stderr:s}}function zt(e,t,n){if(e.length>t)throw new k(`${n}: string length limit exceeded (${t} bytes)`,"string_length")}async function dt(e,t,n=!1){let r=[];for(let s of t)r.push(await Xe(e,s,n));return r.join("")}function kp(e){return Au(e)}function Ru(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!kp(t))return!1;return!0}function Pp(e,t,n=!1){let r=Su(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 vi(e,t.pattern);default:return null}}async function ne(e,t){return Ri(e,t)}async function Du(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped")n.push(Pn(r.value));else if(r.type==="SingleQuoted")n.push(r.value);else if(r.type==="DoubleQuoted"){let s=await dt(e,r.parts);n.push(s)}else if(r.type==="TildeExpansion"){let s=await Xe(e,r);n.push(Pn(s))}else n.push(await Xe(e,r));return n.join("")}async function Iu(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped"){let s=r.value;"()|*?[]".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="SingleQuoted")n.push(Ke(r.value));else if(r.type==="DoubleQuoted"){let s=await dt(e,r.parts);n.push(Ke(s))}else n.push(await Xe(e,r));return n.join("")}async function Ou(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 dt(e,r.parts);n.push(Ke(s))}else r.type==="Glob"?Wl(r.pattern)?n.push(await zl(e,r.pattern)):n.push(vi(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 Nu=1e5;async function _u(e,t,n={count:0}){let r=()=>{n.count++,e.executionScope.consumeLimited("brace_operations",1,Math.min(Nu,e.limits.maxBraceExpansionResults),"brace expansion")},s=(o,a)=>{if(o.length>=e.limits.maxBraceExpansionResults)throw new k(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),o.push(a)},i=[[]];for(let o of t)if(o.type==="BraceExpansion"){let a=[],l=!1,u="";for(let d of o.items)if(d.type==="Range"){let p=Si(d.start,d.end,d.step,d.startStr,d.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(p.expanded)for(let h of p.expanded)s(a,h);else{l=!0,u=p.literal;break}}else{let p=await _u(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(a,m.join(""))}}if(l){for(let d of i)r(),d.push(u);continue}if(i.length*a.length>e.limits.maxBraceExpansionResults||n.count>Nu)throw new k(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");let f=[];for(let d of i)for(let p of a){if(f.length>=e.limits.maxBraceExpansionResults)throw new k(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),f.push([...d,p])}i=f}else for(let a of i)r(),a.push(o);return i}async function Lu(e,t){let n=t.parts;if(!Hr(n))return[await ne(e,t)];let r=await _u(e,n),s=[];for(let i of r){let o=[];for(let a of i)typeof a=="string"?o.push(a):o.push(await Xe(e,a));s.push(xi(e,o.join("")))}return s}function Cp(){return{expandWordAsync:Ri,expandWordForGlobbing:Ou,expandWordWithBracesAsync:Lu,expandWordPartsAsync:dt,expandPart:Xe,expandParameterAsync:Zr,hasBraceExpansion:Hr,evaluateArithmetic:K,buildIfsCharClassPattern:gl,smartWordSplit:bu}}async function pt(e,t){return gu(e,t,Cp())}function Np(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Ni(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function r(s){for(let i of s)if(i.type==="DoubleQuoted"){for(let o of i.parts)if(o.type==="ParameterExpansion"&&o.parameter==="@"&&!o.operation)return!0}return!1}return r(t.parts)}async function Tu(e,t){if(Ni(e,t))return{error:`bash: $@: ambiguous redirect
108
+ `};let n=t.parts,{hasQuoted:r}=Jn(n);if(Hr(n)&&(await Lu(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 Ri(e,t),{hasParamExpansion:i,hasCommandSub:o}=Jn(n);if((i||o)&&!r&&!Ce(e.state.env)){let f=Ae(e.state.env);if(ce(s,f,e.limits.maxArrayElements).length>1)return{error:`bash: $${Np(n)}: ambiguous redirect
110
+ `}}if(r||e.state.options.noglob||n.some(f=>f.type==="ProcessSubstitution"))return{target:s};let l=await Ou(e,t);if(!wt(l,e.state.shoptOptions.extglob))return{target:s};let u=new Ft(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
+ `}:{target:s}:c.length===1?{target:c[0]}:{error:`bash: ${s}: ambiguous redirect
112
+ `}}async function Ri(e,t){let n=t.parts,r=n.length;if(r===1){let o=await Xe(e,n[0]);return zt(o,e.limits.maxStringLength,"word expansion"),o}let s=[];for(let o=0;o<r;o++)s.push(await Xe(e,n[o]));let i=s.join("");return zt(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=Pp(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=xl(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 zt(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,o=e.limits.maxSubstitutionDepth;if(i>=o)throw new k(`Command substitution nesting limit exceeded (${o})`,"substitution_depth");let a=e.substitutionDepth;e.substitutionDepth=i+1;let l=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let u=new Map(e.state.env),c=tt(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=a;let m=p.stdout.replace(/\n+$/,"");return zt(m,e.limits.maxStringLength,"command substitution"),m}catch(p){if(e.state.env=u,e.state.arrays=c,e.state.cwd=f,e.state.bashPid=l,e.substitutionDepth=a,e.state.suppressVerbose=d,p instanceof 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 zt(h,e.limits.maxStringLength,"command substitution"),h}throw p}}case"ProcessSubstitution":return Pu(e,t);case"ArithmeticExpansion":{let s=t.expression.originalText;if(s&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(s)){let o=await vl(e,s),a=new G,l=te(a,o);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 o=Si(i.start,i.end,i.step,i.startStr,i.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(o.expanded)s.push(...o.expanded);else return o.literal}else s.push(await ne(e,i.word));return s.join(" ")}default:return""}}async function 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 Ei(e,p);r=`${d}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&le(e,r)){let d=Le(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 Ei(e,m);r=`${h}[${b}]`}}}}let o=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),a=await re(e,r,!o);if(!s)return a;let l=!await gt(e,r),{isEmpty:u,effectiveValue:c}=Bl(e,r,a,n),f={value:a,isUnset:l,isEmpty:u,effectiveValue:c,inDoubleQuotes:n};switch(s.type){case"DefaultValue":return kl(e,s,f,dt);case"AssignDefault":return Pl(e,r,s,f,dt);case"ErrorIfUnset":return Cl(e,r,s,f,dt);case"UseAlternative":return Nl(e,s,f,dt);case"PatternRemoval":{let d=await Rl(e,a,s,dt,Xe);return zt(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await Dl(e,a,s,dt,Xe);return zt(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return Il(e,r,a);case"LengthSliceError":throw new Ze(r);case"BadSubstitution":throw new Ze(s.text);case"Substring":return Ol(e,r,a,s);case"CaseModification":{let d=await _l(e,a,s,dt,Zr);return zt(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return Ll(e,r,a,l,s);case"Indirection":return Tl(e,r,a,l,s,Zr,n);case"ArrayKeys":return Ml(e,s);case"VarNamePrefix":return Fl(e,s);default:return a}}function Fu(){return{visited:new Set,depth:0}}function Rp(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 Mu(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 Dp(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function Ip(e,t){let n=e.state.env.get(t);if(n!==void 0)return n;let r=oe(e,t,0);return r!==void 0?r:await re(e,t)}async function Op(e,t,n){if(!t)return 0;let r=Number.parseInt(t,10);if(!Number.isNaN(r)&&/^-?\d+$/.test(t.trim()))return r;let s=t.trim();if(!s)return 0;let i=new G,{expr:o,pos:a}=kn(i,s,0);if(a<s.length){let l=s.slice(a).trim(),u=l.split(/\s+/)[0]||l;throw new ae(`syntax error in expression (error token is "${u}")`,"","")}return await Rn(e,o,!1,n)}async function Qr(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 Op(e,n,r)}finally{r.depth--,r.visited.delete(t)}}async function Di(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 Ip(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 Di(e,i,n);let o=new G,{expr:a,pos:l}=kn(o,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 Rn(e,a,!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),o=t.slice(r+s.length),a=e.state.env.get(i),l=a===void 0,u=a==="",c=s.startsWith(":");switch(s){case":-":case"-":return l||c&&u?o:a||"";case":=":case"=":return l||c&&u?(e.state.env.set(i,o),o):a||"";case":+":case"+":return!(l||c&&u)?o:"";case":?":case"?":{if(l||c&&u)throw new Error(o||`${i}: parameter null or not set`);return a||""}default:return a||""}}async function K(e,t,n=!1){return Rn(e,t,n,Fu())}async function Rn(e,t,n,r){let s=(i,o=n)=>Rn(e,i,o,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 Di(e,t.name,r);case"ArithSpecialVar":{let o=(await re(e,t.name)).trim();if(!o)return 0;let a=Number.parseInt(o,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(o))return a;let l=new G,{expr:u}=kn(l,o,0);return await s(u)}case"ArithNested":return await s(t.expression);case"ArithCommandSubst":{if(e.execFn){let i=await e.execFn(t.command,{signal:e.state.signal});i.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+i.stderr);let o=i.stdout.trim();return Number.parseInt(o,10)||0}return 0}case"ArithBracedExpansion":{let i=await Kr(e,t.content);return Number.parseInt(i,10)||0}case"ArithDynamicBase":{let i=await Kr(e,t.baseExpr),o=Number.parseInt(i,10);if(o<2||o>64)return 0;let a=`${o}#${t.value}`;return Qn(a)}case"ArithDynamicNumber":{let o=await Kr(e,t.prefix)+t.suffix;return Qn(o)}case"ArithArrayElement":{let i=e.state.associativeArrays?.has(t.array),o=async a=>{let l=oe(e,t.array,a);return l!==void 0?await Qr(e,`${t.array}[${a}]`,l,r):0};if(t.stringKey!==void 0)return await o(t.stringKey);if(i&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await o(t.index.name);if(i&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let a=await re(e,t.index.name);return await o(a)}if(t.index){let a=await s(t.index);if(a<0){let c=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
113
+ `,0;let p=Math.max(...c.map(([h])=>typeof h=="number"?h:0))+1+a;if(p<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
114
+ `,0;a=p}let l=`${t.array}[${a}]`,u=oe(e,t.array,a);if(u!==void 0)return Qr(e,l,u,r);if(a===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)||ke(e,t.array)))throw new Fe(`${t.array}[${a}]`);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),o=await s(t.right);return Rp(i,o,t.operator)}case"ArithUnary":{let i=await s(t.operand);if(t.operator==="++"||t.operator==="--"){if(t.operand.type==="ArithVariable"){let o=t.operand.name,a=Number.parseInt(await re(e,o),10)||0,l=t.operator==="++"?a+1:a-1;return e.state.env.set(o,String(l)),t.prefix?l:a}if(t.operand.type==="ArithArrayElement"){let o=t.operand.array,a=e.state.associativeArrays?.has(o),l;if(t.operand.stringKey!==void 0)l=t.operand.stringKey;else if(a&&t.operand.index?.type==="ArithVariable"&&!t.operand.index.hasDollarPrefix)l=t.operand.index.name;else if(a&&t.operand.index?.type==="ArithVariable"&&t.operand.index.hasDollarPrefix)l=await re(e,t.operand.index.name);else if(t.operand.index){let f=await s(t.operand.index);l=String(f)}else return i;let u=Number.parseInt(oe(e,o,l)||"0",10)||0,c=t.operator==="++"?u+1:u-1;return j(e,o,l,String(c),a?"associative":"indexed"),t.prefix?c:u}if(t.operand.type==="ArithConcat"){let o="";for(let a of t.operand.parts)o+=await Nn(e,a,n,r);if(o&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){let a=Number.parseInt(e.state.env.get(o)||"0",10)||0,l=t.operator==="++"?a+1:a-1;return e.state.env.set(o,String(l)),t.prefix?l:a}}if(t.operand.type==="ArithDynamicElement"){let o="";if(t.operand.nameExpr.type==="ArithConcat")for(let a of t.operand.nameExpr.parts)o+=await Nn(e,a,n,r);else t.operand.nameExpr.type==="ArithVariable"&&(o=t.operand.nameExpr.hasDollarPrefix?await re(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(o&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){let a=await s(t.operand.subscript),l=Number.parseInt(oe(e,o,a)||"0",10)||0,u=t.operator==="++"?l+1:l-1;return j(e,o,a,String(u)),t.prefix?u:l}}return i}return Dp(i,t.operator)}case"ArithTernary":return await s(t.condition)?await s(t.consequent):await s(t.alternate);case"ArithAssignment":{let i=t.variable,o=i,a;if(t.stringKey!==void 0)a=t.stringKey;else if(t.subscript){let d=e.state.associativeArrays?.has(i);if(d&&t.subscript.type==="ArithVariable"&&!t.subscript.hasDollarPrefix)a=t.subscript.name;else if(d&&t.subscript.type==="ArithVariable"&&t.subscript.hasDollarPrefix)a=await re(e,t.subscript.name)||"\\";else if(d){let p=await s(t.subscript);a=String(p)}else{let p=await s(t.subscript);if(p<0){let h=Z(e,i);h.length>0&&(p=Math.max(...h.map(([E])=>typeof E=="number"?E:0))+1+p)}a=String(p)}}let l=a===void 0?e.state.env.get(o):oe(e,i,a),u=Number.parseInt(l||"0",10)||0,c=await s(t.value),f=Mu(u,c,t.operator);return a===void 0?e.state.env.set(o,String(f)):j(e,i,a,String(f),e.state.associativeArrays?.has(i)?"associative":"indexed"),f}case"ArithGroup":return await s(t.expression);case"ArithConcat":{let i="";for(let o of t.parts)i+=await Nn(e,o,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)?await Di(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 Nn(e,c,n,r);else t.target.type==="ArithVariable"&&(i=t.target.hasDollarPrefix?await re(e,t.target.name):t.target.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let o=i;if(t.subscript){let c=await s(t.subscript);o=`${i}_${c}`}let a=Number.parseInt(e.state.env.get(o)||"0",10)||0,l=await s(t.value),u=Mu(a,l,t.operator);return e.state.env.set(o,String(u)),u}case"ArithDynamicElement":{let i="";if(t.nameExpr.type==="ArithConcat")for(let u of t.nameExpr.parts)i+=await Nn(e,u,n,r);else t.nameExpr.type==="ArithVariable"&&(i=t.nameExpr.hasDollarPrefix?await re(e,t.nameExpr.name):t.nameExpr.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let o=await s(t.subscript),a=`${i}_${o}`,l=e.state.env.get(a);return l!==void 0?Qr(e,a,l,r):0}default:return 0}}async function Nn(e,t,n=!1,r=Fu()){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await Rn(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 Nn(e,i,n,r);return s}default:return String(await Rn(e,t,n,r))}}async function Bu(e,t){let n="",r=0;for(let v of t.parts){let x=v.type==="Literal"?v.value:"\0",A=F(x);if(A>e.limits.maxStringLength-r)throw new k(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n+=x,r+=A}let s=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!s||!n.endsWith(")"))return null;let i=s[1],o=[],a=[],l=!1,u="",c=0,f=0,d=!1,p=!0,h=v=>{let x=F(v);if(x>e.limits.maxStringLength-f-c)throw new k(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u+=v,c+=x},m=(v,x=!1)=>{if(o.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");o.push(v),a.push(x),f+=A},E=()=>{m(u,p),u="",c=0,d=!1,p=!0};for(let v of t.parts)if(v.type==="Literal"){let x=v.value;if(!l){let A=x.indexOf("=(");A!==-1&&(l=!0,x=x.slice(A+2))}if(l){x.endsWith(")")&&(x=x.slice(0,-1));for(let A of x)/\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 pt(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 x=await ne(e,{type:"Word",parts:[v]});h(x)}(u||d)&&E();let b=o.splice(0),g=a.splice(0);f=0;for(let v=0;v<b.length;v++){let x=b[v];if(!g[v]){m(x);continue}let A=x.match(/^(\[[^\]]+\]=)(.*)$/s);if(A){let C=Vt(e,A[2]);x=A[1]+C}if(x.includes("{")&&x.includes("}")){let C=new G().parseWordFromString(x,!1,!1);if(C.parts.some(N=>N.type==="BraceExpansion")){let N=await pt(e,C);for(let $ of N.values)m($);continue}}m(x)}let y=[`${i}=(`],S=F(y[0]);for(let v=0;v<o.length;v++){let x=o[v],A;/^\[.+\]=/.test(x)?A=x:x===""?A="''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(x)&&!x.startsWith("'")&&!x.startsWith('"')?A=`'${x.replace(/'/g,"'\\''")}'`:A=x;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 Wu(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),o=t.parts[n];if(o.type!=="Literal")return null;let a=s?2:1,l=o.value.slice(0,r),u=o.value.slice(r+a),c=t.parts.slice(n+1),f="";for(let m of i)f+=await ne(e,{type:"Word",parts:[m]});f+=l;let d={type:"Word",parts:u!==""?[{type:"Literal",value:u},...c]:c},p=d.parts.length>0?await ne(e,d):"";return`${f}${s?"+=":"="}${p}`}var _p=["tar","yq","xan","sqlite3","python3","python"];function Vu(e){return _p.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 qt(e,t,n="",r=""){throw new k(e,t,n,r)}function zu(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 Ii(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Nt;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 Oi(e,t){let n,r=!1,s=!1,i=0;for(;i<t.length;)if(t[i]==="--"){i++;break}else if(t[i]==="-L")s=!1,i++;else if(t[i]==="-P")s=!0,i++;else if(t[i].startsWith("-")&&t[i]!=="-")i++;else break;let o=t.slice(i);if(o.length===0||o[0]==="~"?n=e.state.env.get("HOME")||"/":o[0]==="-"?(n=e.state.previousDir,r=!0):n=o[0],!n.startsWith("/")&&!n.startsWith("./")&&!n.startsWith("../")&&n!=="."&&n!==".."){let f=e.state.env.get("CDPATH");if(f){let d=f.split(":").filter(p=>p);for(let p of d){let h=p.startsWith("/")?`${p}/${n}`:`${e.state.cwd}/${p}/${n}`;try{if((await e.fs.stat(h)).isDirectory){n=h,r=!0;break}}catch{}}}}let l=(n.startsWith("/")?n:`${e.state.cwd}/${n}`).split("/").filter(f=>f&&f!=="."),u="";for(let f of l)if(f==="..")u=u.split("/").slice(0,-1).join("/")||"/";else{u=u?`${u}/${f}`:`/${f}`;try{if(!(await e.fs.stat(u)).isDirectory)return I(`bash: cd: ${n}: Not a directory
117
+ `)}catch{return I(`bash: cd: ${n}: No such file or directory
118
+ `)}}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 _i(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Lp=["-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 Lp.includes(e)}async function Yr(e,t,n){let r=_i(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 Tp=["-nt","-ot","-ef"];function Jr(e){return Tp.includes(e)}async function es(e,t,n,r){let s=_i(e,n),i=_i(e,r);switch(t){case"-nt":{let[o,a]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return o!==null&&(a===null||o.mtime>a.mtime)}case"-ot":{let[o,a]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return a!==null&&(o===null||o.mtime<a.mtime)}case"-ef":try{let[o,a]=await Promise.all([e.fs.realpath(s),e.fs.realpath(i)]);if(o===a)return!0;let[l,u]=await Promise.all([e.fs.stat(s),e.fs.stat(i)]);return l.dev!==void 0&&l.ino!==void 0&&u.dev!==void 0&&u.ino!==void 0?l.dev===u.dev&&l.ino===u.ino:l.identity&&u.identity?l.identity===u.identity:!1}catch{return!1}default:return!1}}var Mp=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function ts(e){return Mp.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,o=256){if(r){let l=Dn(t,n,s,i,o);return e==="!="?!l:l}if(s){let l=t.toLowerCase()===n.toLowerCase();return e==="!="?!l:l}let a=t===n;return e==="!="?!a:a}var Fp=new Set(["-z","-n"]);function ss(e){return Fp.has(e)}function is(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function os(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let r=n[1],s=n[2];if(e.state.associativeArrays?.has(r)){let a=s;return(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1)),a=a.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(l,u)=>e.state.env.get(u)||""),Lt(e,r,a)}let o;try{let a=new G,l=te(a,s);o=await K(e,l.expression)}catch{if(/^-?\d+$/.test(s))o=Number.parseInt(s,10);else{let a=e.state.env.get(s);o=a?Number.parseInt(a,10):0}}if(o<0){let a=be(e,r),l=e.state.currentLine;if(a.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
120
+ `,!1;if(o=Math.max(...a)+1+o,o<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
121
+ `,!1}return Lt(e,r,o)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?mt(e,t).length>0:be(e,t).length>0}async function Ut(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=Pn(i)}else s=await Du(e,t.right);else sr(t.operator)&&!r?s=await Iu(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 Uu(e,n),await Uu(e,s));if(Jr(t.operator))return es(e,t.operator,n,s);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=qp(s),l=me(o,i?"i":"").match(n);if(ye(e,"BASH_REMATCH"),l)for(let u=0;u<l.length;u++)j(e,"BASH_REMATCH",u,l[u]||"");return l!==null}catch{throw new Error("syntax error in regular expression")}case"<":return n<s;case">":return n>s;default:return!1}}case"CondUnary":{let n=await ne(e,t.operand);return Xr(t.operator)?Yr(e,t.operator,n):ss(t.operator)?is(t.operator,n):t.operator==="-v"?await os(e,n):t.operator==="-o"?Ti(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 Ut(e,t.operand);case"CondAnd":return await Ut(e,t.left)?await Ut(e,t.right):!1;case"CondOr":return await Ut(e,t.left)?!0:await Ut(e,t.right);case"CondGroup":return await Ut(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 os(e,s)):r==="-o"?ge(Ti(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 o=as(r),a=as(i);return!o.valid||!a.valid?L("","",2):ge(ns(s,o.value,a.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 o=await ir(e,[s,i]);return L("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(r==="("&&i===")")return ge(s!=="")}if(t.length===4){if(t[0]==="!"){let r=await 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 Gu(e,t,0);return n.pos<t.length?I(`test: too many arguments
124
+ `,2):ge(n.value)}async function Gu(e,t,n){return Bp(e,t,n)}async function Bp(e,t,n){let{value:r,pos:s}=await qu(e,t,n);for(;t[s]==="-o";){let i=await qu(e,t,s+1);r=r||i.value,s=i.pos}return{value:r,pos:s}}async function qu(e,t,n){let{value:r,pos:s}=await Li(e,t,n);for(;t[s]==="-a";){let i=await Li(e,t,s+1);r=r&&i.value,s=i.pos}return{value:r,pos:s}}async function Li(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 Li(e,t,n+1);return{value:!s,pos:i}}return Wp(e,t,n)}finally{r.release()}}async function Wp(e,t,n){let r=t[n];if(r==="("){let{value:i,pos:o}=await Gu(e,t,n+1);return{value:i,pos:t[o]===")"?o+1:o}}let s=t[n+1];if(sr(s)){let i=r,o=t[n+2]??"";return{value:rs(s,i,o),pos:n+3}}if(ts(s)){let i=as(r),o=as(t[n+2]??"0");return!i.valid||!o.valid?{value:!1,pos:n+3}:{value:ns(s,i.value,o.value),pos:n+3}}if(Jr(s)){let i=r,o=t[n+2]??"";return{value:await es(e,s,i,o),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 os(e,i),pos:n+2}}if(r==="-o"){let i=t[n+1]??"";return{value:Ti(e,i),pos:n+2}}return{value:r!==void 0&&r!=="",pos:n+1}}function Dn(e,t,n=!1,r=!1,s=256){r&&Vp(t,s);let i=`^${Zu(t,r)}$`;return me(i,n?"is":"s").test(e)}function Vp(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 Zu(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=Hu(e,r+1);if(i!==-1){let o=e.slice(r+2,i),a=Qu(o),l=a.map(c=>Zu(c,t)),u=l.length>0?l.join("|"):"(?:)";if(s==="@")n+=`(?:${u})`;else if(s==="*")n+=`(?:${u})*`;else if(s==="+")n+=`(?:${u})+`;else if(s==="?")n+=`(?:${u})?`;else if(s==="!")if(i<e.length-1){let f=a.map(p=>Ku(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 Hu(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 Qu(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 Ku(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=Hu(e,r+1);if(i!==-1){if(s==="@"){let o=e.slice(r+2,i),l=Qu(o).map(u=>Ku(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 Ti(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 Uu(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 ju(t);try{let n=new G,r=te(n,t);return await K(e,r.expression)}catch{return ju(t)}}function zp(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 ju(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=zp(r[2],s):n=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?n=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?n=Number.parseInt(e,8):n=Number.parseInt(e,10);return Number.isNaN(n)&&(n=0),t?-n:n}function as(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let n=Number.parseInt(e,10);return Number.isNaN(n)?{value:0,valid:!1}:{value:t?-n:n,valid:!0}}function qp(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=Up(e,n);t+=r.converted,n=r.endIndex}else t+=e[n],n++;return t}function Up(e,t){let n=t+1,r="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(r+="^",n++);let s=!1;n<e.length&&e[n]==="]"&&(s=!0,n++);let i=!1;n<e.length&&e[n]==="["&&n+1<e.length&&e[n+1]!==":"&&(i=!0,n++);let o="",a=!1;for(;n<e.length;){let l=e[n];if(l==="]"){a=!0,n++;break}if(l==="["&&n+1<e.length&&e[n+1]===":"){let u=e.indexOf(":]",n+2);if(u!==-1){let c=e.slice(n+2,u);o+=jp(c),n=u+2;continue}}if(l==="["&&n+1<e.length){let u=e[n+1];if(u==="."||u==="="){let c=`${u}]`,f=e.indexOf(c,n+2);if(f!==-1){let d=e.slice(n+2,f);o+=d,n=f+2;continue}}}if(l==="\\"&&n+1<e.length){o+=l+e[n+1],n+=2;continue}o+=l,n++}return a?(s&&(r+="\\]"),i&&(r+="\\["),r+=o,r+="]",{converted:r,endIndex:n}):{converted:"\\[",endIndex:t+1}}function jp(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 Mi(e,t,n){if(n&&e.length>=n.maxElements)throw new k(`array element limit exceeded (${n.maxElements})`,"array_elements");e.push(t)}function kt(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,o=!1,a=!1;for(let l of e){if(o){r+=l,o=!1,a=!0;continue}if(l==="\\"){o=!0;continue}if(l==="'"&&!i){s||(a=!0),s=!s;continue}if(l==='"'&&!s){i||(a=!0),i=!i;continue}if((l===" "||l===" "||l===`
125
+ `)&&!s&&!i){a&&(Mi(n,r,t),r="",a=!1);continue}r+=l,a=!0}return a&&Mi(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 o=e[r];for(r++;r<e.length&&e[r]!==o;)s+=e[r],r++;e[r]===o&&r++}else for(;r<e.length&&e[r]!=="]"&&e[r]!=="=";)s+=e[r],r++;for(;r<e.length&&e[r]!=="]";)r++;if(e[r]==="]"&&r++,e[r]!=="=")continue;r++;let i="";if(e[r]==="'"||e[r]==='"'){let o=e[r];for(r++;r<e.length&&e[r]!==o;)e[r]==="\\"&&r+1<e.length&&r++,i+=e[r],r++;e[r]===o&&r++}else for(;r<e.length&&!/\s/.test(e[r]);)i+=e[r],r++;Mi(n,[s,i],t)}return n}function Xu(e,t){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(n)return{name:n[1],isArray:!0,arrayElements:kt(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 Gp(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 Yu(e,t,n={}){let{name:r,isArray:s,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:l=!1,checkReadonly:u=!0}=n;if(u){let c=ue(e,r);if(c)return c}if(s&&i){e.executionScope.consumeWork(i.length,"array assignment");let c=ve(e,r),f=c?_e(c):void 0,d=e.state.env.get(r);try{ye(e,r);for(let p=0;p<i.length;p++)j(e,r,p,i[p]);e.state.env.delete(r)}catch(p){throw e.state.arrays??=new Map,f?e.state.arrays.set(r,f):e.state.arrays.delete(r),d===void 0?e.state.env.delete(r):e.state.env.set(r,d),p}}else if(a!==void 0&&o!==void 0){let c=await Gp(e,a);j(e,r,c,o)}else o!==void 0&&e.state.env.set(r,o);return l&&Ue(e,r),null}function jt(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function Fi(e,t){return e.state.localVarDepth?.get(t)}function us(e,t){e.state.localVarDepth?.delete(t)}function Ju(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 ec(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 Bi=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function tc(e){return Bi.has(e)}var Wi=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),In=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 Vi="__file__:",zi="__file_append__:",ji="__rw__:",qi="__dupout__:",Ui="__dupin__:",we=3;function Zp(e){let t=e.slice(ji.length),n=t.indexOf(":");if(n===-1)return null;let r=Number.parseInt(t.slice(0,n),10);if(Number.isNaN(r)||r<0)return null;let s=n+1,i=t.slice(s,s+r),o=t.slice(s+r+1),a=o.indexOf(":");if(a===-1)return null;let l=Number.parseInt(o.slice(0,a),10);return Number.isNaN(l)||l<0?null:{path:i,position:l,content:o.slice(a+1)}}function nc(e,t){let n=Number.parseInt(e.slice(t.length),10);return Number.isNaN(n)?null:n}function Hp(e){if(e.startsWith(Vi))return{kind:"output",path:e.slice(Vi.length),append:!1};if(e.startsWith(zi))return{kind:"output",path:e.slice(zi.length),append:!0};if(e.startsWith(ji)){let t=Zp(e);if(t)return{kind:"readwrite",...t}}if(e.startsWith(qi)){let t=nc(e,qi);if(t!==null)return{kind:"dup-out",sourceFd:t}}if(e.startsWith(Ui)){let t=nc(e,Ui);if(t!==null)return{kind:"dup-in",sourceFd:t}}return{kind:"input",content:e}}function Gi(e){switch(e.kind){case"input":return e.content;case"output":return`${e.append?zi:Vi}${e.path}`;case"readwrite":return`${ji}${e.path.length}:${e.path}:${e.position}:${e.content}`;case"dup-out":return`${qi}${e.sourceFd}`;case"dup-in":return`${Ui}${e.sourceFd}`;case"closed":throw new Error("Closed descriptors have no table encoding")}}function Qp(e){return e.state.fileDescriptors??=new Map,e.state.fileDescriptors}function Kp(e,t,n){n?(e.state.inputFds??=new Set,e.state.inputFds.add(t)):e.state.inputFds?.delete(t)}function On(e,t){return e.state.fdAliases?.get(t)}function Gt(e,t){return[...On(e,t)??[t]]}function rc(e,t){let n=On(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 Zi(e,t,n){if(t===n)return;e.state.fdAliases??=new Map;let r=On(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}:Hp(n)}function fn(e,t){return e.state.fileDescriptors?.has(t)===!0}function Hi(e,t,n,r){let s=Qp(e);s.has(t)||zu(e),s.set(t,n),Kp(e,t,r)}function ds(e,t,n,r=!1){rc(e,t),Hi(e,t,n,r)}function rt(e,t,n){ds(e,t,Gi(n),n.kind==="input")}function bt(e,t){e.state.fileDescriptors?.delete(t),e.state.inputFds?.delete(t),rc(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),Zi(e,t,n),!0)}function Qi(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=[...On(e,n)??[]].filter(a=>a!==n);bt(e,n),ds(e,t,r,s);let o=i.find(a=>fn(e,a));return o!==void 0&&Zi(e,t,o),!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 Zt(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=Gi(s),o=s.kind==="input";for(let a of On(e,t)??[t])Hi(e,a,i,o)}async function Ki(e,t,n,r,s){if(t.kind==="output")return await e.fs.appendFile(t.path,r,s),!0;let o=n.map(c=>Ye(e,c)).find(c=>c?.kind==="readwrite")??t;if(o.kind!=="readwrite")return!1;let a=o.content.slice(0,o.position)+r+o.content.slice(o.position+r.length),l={...o,position:o.position+r.length,content:a};await e.fs.writeFile(o.path,a,s);let u=Gi(l);for(let c of n)fn(e,c)&&Hi(e,c,u,!1);return!0}function Ht(e,t,n){if(t.has(n))return;let r=On(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:o}]of t){if(s===void 0){bt(e,r);continue}ds(e,r,s,i);let a=o.find(l=>n.has(l));a!==void 0&&Zi(e,r,a)}}function Xi(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 sc(e){if(e.fdVariable)return!1;let t=Xi(e);return t!==null&&t>=we}async function Xp(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
96
126
  `;if(r.checkNoclobber&&e.state.options.noclobber&&!r.isClobber&&n!=="/dev/null")return`bash: ${n}: cannot overwrite existing file
97
127
  `}catch{return`bash: ${n}: cannot open redirect target
98
- `}return null}function En(e){let n=Math.min(e.length,8192);for(let r=0;r<n;r++)if(e.charCodeAt(r)>127)return"utf8";return"binary"}function Ad(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),n=t.indexOf(":");if(n===-1)return null;let r=Number.parseInt(t.slice(0,n),10);if(Number.isNaN(r)||r<0)return null;let s=n+1,i=t.slice(s,s+r),a=s+r+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let c=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let u=o.slice(l+1);return{path:i,position:c,content:u}}async function yi(e,t){let n=new Map;for(let r=0;r<t.length;r++){let s=t[r];if(s.target.type==="HereDoc")continue;if(s.operator===">&"||s.operator==="<&"){if(Fn(e,s.target))return{targets:n,error:`bash: $@: ambiguous redirect
99
- `};n.set(r,await W(e,s.target))}else{let a=await Dr(e,s.target);if("error"in a)return{targets:n,error:a.error};n.set(r,a.target)}}return{targets:n}}function vd(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd,n=e.limits.maxFileDescriptors;if(t>=n)throw new Error(`bash: cannot allocate file descriptor: too many open files (max ${n})`);return e.state.nextFd++,t}async function Hr(e,t,n){for(let r=0;r<t.length;r++){let s=t[r];if(!s.fdVariable||s.target.type!=="Word")continue;oe(e,s.fdVariable);let i=s.operator===">&"||s.operator==="<&",a=n?.get(r);if(a===void 0)if(i){if(Fn(e,s.target))return _("",`bash: $@: ambiguous redirect
100
- `,1);a=await W(e,s.target)}else{let c=await Dr(e,s.target);if("error"in c)return _("",c.error,1);a=c.target}if(a.includes("\0"))return _("",`bash: ${a.replace(/\0/g,"")}: No such file or directory
101
- `,1);if(e.state.fileDescriptors??=new Map,i&&a==="-"){let c=e.state.env.get(s.fdVariable);if(c!==void 0){let u=Number.parseInt(c,10);Number.isNaN(u)||e.state.fileDescriptors.delete(u)}continue}let o;if(i){let c=Number.parseInt(a,10);Number.isNaN(c)||(o=e.state.fileDescriptors.get(c))}else if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let c=e.fs.resolvePath(e.state.cwd,a),u=s.operator===">>"||s.operator==="&>>",f=u?{checkNoclobber:!1}:{checkNoclobber:!0,isClobber:s.operator===">|"},d=await qn(e,c,a,f);if(d)return _("",d,1);Ve(e),u?await e.fs.appendFile(c,"","binary"):await e.fs.writeFile(c,"","binary"),o=`__file__:${c}`}else if(s.operator==="<<<")o=`${a}
102
- `;else if(s.operator==="<"||s.operator==="<>")try{let c=e.fs.resolvePath(e.state.cwd,a);o=await e.fs.readFile(c)}catch{return _("",`bash: ${a}: No such file or directory
103
- `,1)}Ve(e);let l=vd(e);e.state.env.set(s.fdVariable,String(l)),o!==void 0&&e.state.fileDescriptors.set(l,o)}return null}async function ot(e,t){for(let s of t)s.fdVariable&&oe(e,s.fdVariable);let n=await yi(e,t);if(n.error)return{targets:n.targets,error:_("",n.error,1)};let r=[];for(let s=0;s<t.length;s++){let i=t[s];if(i.target.type==="HereDoc")continue;let a=i.operator===">&";if(i.operator!==">"&&i.operator!==">|"&&i.operator!=="&>"&&!a)continue;let o=n.targets.get(s);if(o===void 0||a&&(o==="-"||!Number.isNaN(Number.parseInt(o,10))||i.fd!=null))continue;let l=e.fs.resolvePath(e.state.cwd,o),c=i.operator===">|";if(l.includes("\0"))return{targets:n.targets,error:_("",`bash: ${o}: No such file or directory
104
- `,1)};try{if(!await e.fs.exists(l))throw new Zr;let f=await e.fs.stat(l);if(f.isDirectory)return{targets:n.targets,error:_("",`bash: ${o}: Is a directory
105
- `,1)};if(e.state.options.noclobber&&!c&&!f.isDirectory&&o!=="/dev/null")return{targets:n.targets,error:_("",`bash: ${o}: cannot overwrite existing file
106
- `,1)}}catch(u){if(!(u instanceof Zr))return{targets:n.targets,error:_("",`bash: ${o}: cannot open redirect target
107
- `,1)}}if(o==="/dev/full")return{targets:n.targets,error:_("",`bash: /dev/full: No space left on device
108
- `,1)};o!=="/dev/null"&&o!=="/dev/stdout"&&o!=="/dev/stderr"&&r.push({filePath:l,target:o})}for(let{filePath:s,target:i}of r)try{await e.fs.writeFile(s,"","binary")}catch{return{targets:n.targets,error:_("",`bash: ${i}: cannot open redirect target
109
- `,1)}}return{targets:n.targets,error:null}}async function pe(e,t,n,r){n.length>0&&(t=e.executionScope.accountResult(t,"redirection"));let{stdout:s,stderr:i,exitCode:a}=t,l=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",c=E=>l,u={kind:"live-stdout"},f={kind:"live-stderr"};for(let E=0;E<n.length;E++){let b=n[E];if(b.target.type==="HereDoc")continue;let g,w=r?.get(E);if(w!==void 0)g=w;else if(b.operator===">&"||b.operator==="<&"){if(Fn(e,b.target)){i+=`bash: $@: ambiguous redirect
110
- `,a=1,s="";continue}g=await W(e,b.target)}else{let v=await Dr(e,b.target);if("error"in v){i+=v.error,a=1,s="";continue}g=v.target}if(!b.fdVariable){if(g.includes("\0")){i+=`bash: ${g.replace(/\0/g,"")}: No such file or directory
111
- `,a=1,s="";continue}switch(b.operator){case">":case">|":case">>":{let S=b.fd??1;if(S!==1&&S!==2)break;let v=b.operator===">>",A=b.operator===">|";if(g==="/dev/stdout"){S===2&&(f=u);break}if(g==="/dev/stderr"){S===1&&(u=f);break}if(g==="/dev/full"){i+=`bash: echo: write error: No space left on device
112
- `,a=1,S===1&&(s="");break}if(g==="/dev/null"&&S===2){f={kind:"discard"};break}let x=e.fs.resolvePath(e.state.cwd,g),P=await qn(e,x,g,{...v?{}:{checkNoclobber:!0,isClobber:A}});if(P){i+=P,a=1,S===1&&(s="");break}v?await e.fs.appendFile(x,"","binary"):await e.fs.writeFile(x,"","binary"),S===1?u={kind:"file",path:x,append:v}:f={kind:"file",path:x,append:v};break}case">&":case"<&":{let S=b.fd??1;if(g==="-")break;if(g.endsWith("-")){let v=g.slice(0,-1),A=Number.parseInt(v,10);if(!Number.isNaN(A)){let x=e.state.fileDescriptors?.get(A);x!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(S,x),A>=3&&e.state.fileDescriptors?.delete(A)):A===1||A===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(S,`__dupout__:${A}`)):A===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(S,`__dupin__:${A}`)):A>=3&&(i+=`bash: ${A}: Bad file descriptor
113
- `,a=1)}break}if(g==="2"||g==="&2")S===1&&(u=f);else if(g==="1"||g==="&1")S===2?f=u:(s+=i,i="");else{let v=Number.parseInt(g,10);if(Number.isNaN(v)){if(b.operator===">&"){let A=e.fs.resolvePath(e.state.cwd,g),x=await qn(e,A,g,{checkNoclobber:!0});if(x){i=x,a=1,s="";break}await e.fs.writeFile(A,"","binary"),b.fd==null?(u={kind:"file",path:A,append:!1},f=u):S===1?u={kind:"file",path:A,append:!1}:S===2&&(f={kind:"file",path:A,append:!1})}}else{let A=e.state.fileDescriptors?.get(v);if(A?.startsWith("__file__:")){let x=A.slice(9);S===1?(await e.fs.appendFile(x,s,c(s)),s=""):S===2&&(await e.fs.appendFile(x,i,En(i)),i="")}else if(A?.startsWith("__rw__:")){let x=Ad(A);x&&(S===1?(await e.fs.appendFile(x.path,s,c(s)),s=""):S===2&&(await e.fs.appendFile(x.path,i,En(i)),i=""))}else if(A?.startsWith("__dupout__:")){let x=Number.parseInt(A.slice(11),10);if(x!==1)if(x===2)S===1&&(i+=s,s="");else{let P=e.state.fileDescriptors?.get(x);if(P?.startsWith("__file__:")){let D=P.slice(9);S===1?(await e.fs.appendFile(D,s,c(s)),s=""):S===2&&(await e.fs.appendFile(D,i,En(i)),i="")}}}else A?.startsWith("__dupin__:")?(i+=`bash: ${v}: Bad file descriptor
114
- `,a=1,s=""):v>=3&&(i+=`bash: ${v}: Bad file descriptor
115
- `,a=1,s="")}}break}case"&>":{if(g==="/dev/full"){i=`bash: echo: write error: No space left on device
116
- `,a=1,s="";break}let S=e.fs.resolvePath(e.state.cwd,g),v=await qn(e,S,g,{checkNoclobber:!0});if(v){i=v,a=1,s="";break}await e.fs.writeFile(S,"","binary"),u={kind:"file",path:S,append:!1},f=u;break}case"&>>":{if(g==="/dev/full"){i=`bash: echo: write error: No space left on device
117
- `,a=1,s="";break}let S=e.fs.resolvePath(e.state.cwd,g),v=await qn(e,S,g,{});if(v){i=v,a=1,s="";break}await e.fs.appendFile(S,"","binary"),u={kind:"file",path:S,append:!0},f=u;break}}}}if(s!==""||i!==""){let E=s,b=i;s="",i="";let g=async(w,S,v)=>{w.append?await e.fs.appendFile(w.path,S,v):await e.fs.writeFile(w.path,S,v)};if(u===f&&u.kind==="file"){let w=E+b;w!==""&&await g(u,w,c(w))}else for(let[w,S,v]of[[E,u,!0],[b,f,!1]])if(w!=="")switch(S.kind){case"live-stdout":s+=w;break;case"live-stderr":i+=w;break;case"file":await g(S,w,v?c(w):En(w));break;case"discard":break}}let d=e.state.fileDescriptors?.get(1);if(d){if(d==="__dupout__:2")i+=s,s="";else if(d.startsWith("__file__:")){let E=d.slice(9);await e.fs.appendFile(E,s,c(s)),s=""}else if(d.startsWith("__file_append__:")){let E=d.slice(16);await e.fs.appendFile(E,s,c(s)),s=""}}let p=e.state.fileDescriptors?.get(2);if(p){if(p==="__dupout__:1")s+=i,i="";else if(p.startsWith("__file__:")){let E=p.slice(9);await e.fs.appendFile(E,i,En(i)),i=""}else if(p.startsWith("__file_append__:")){let E=p.slice(16);await e.fs.appendFile(E,i,En(i)),i=""}}let h=_(s,i,a);if(t.stdoutKind&&(h.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(h.stdoutEncoding="binary"),t.internalPipeStatusOverride&&(h.internalPipeStatusOverride=t.internalPipeStatusOverride),n.length>0||e.state.fileDescriptors?.has(1)===!0||e.state.fileDescriptors?.has(2)===!0){let E=(t.internalOutputAccounting?.stdout??0)+(t.internalOutputAccounting?.stderr??0),b=T(h.stdout),g=T(h.stderr),w=Math.min(b,E);h.internalOutputAccounting={stdout:w,stderr:Math.min(g,E-w)},e.executionScope.accountResult(h,"redirection")}else t.internalOutputAccounting&&(h.internalOutputAccounting=t.internalOutputAccounting);return h}function lc(e,t){if(e.state.options.posix&&hi.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
118
- `;throw new j(2,"",r)}let n={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,n),te}async function xd(e,t){let n="";for(let r of t)if((r.operator==="<<"||r.operator==="<<-")&&r.target.type==="HereDoc"){let s=r.target,i=await W(e,s.content);s.stripTabs&&(i=i.split(`
119
- `).map(o=>o.replace(/^\t+/,"")).join(`
120
- `)),(r.fd??0)===0&&(n=i)}else if(r.operator==="<<<"&&r.target.type==="Word")n=`${await W(e,r.target)}
121
- `;else if(r.operator==="<"&&r.target.type==="Word"){let s=await W(e,r.target),i=e.fs.resolvePath(e.state.cwd,s);try{n=await e.fs.readFile(i)}catch{}}return n}async function Qr(e,t,n,r="",s){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,Lt(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(s??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localArrayScopes??=[],e.state.localArrayScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i=new Map,a=Number.parseInt(e.state.env.get("#")??"0",10),o=Math.max(n.length,a);for(let f=0;f<o;f++){let d=String(f+1);i.set(d,e.state.env.get(d)),f<n.length?e.state.env.set(d,n[f]):e.state.env.delete(d)}i.set("@",e.state.env.get("@")),i.set("#",e.state.env.get("#")),e.state.env.set("@",n.join(" ")),e.state.env.set("#",String(n.length));let l=!1,c=()=>{if(l)return;l=!0;let f=e.state.localScopes.length-1,d=e.state.localScopes.pop(),p=e.state.localArrayScopes?.pop();if(d)for(let[h,m]of d)m===void 0?e.state.env.delete(h):e.state.env.set(h,m);if(p){e.state.arrays??=new Map;for(let[h,m]of p)m===void 0?(e.state.arrays.delete(h),e.state.associativeArrays?.delete(h)):(e.state.arrays.set(h,De(m)),e.state.associativeArrays??=new Set,m.kind==="associative"?e.state.associativeArrays.add(h):e.state.associativeArrays.delete(h))}if(ac(e,f),e.state.fullyUnsetLocals)for(let[h,m]of e.state.fullyUnsetLocals.entries())m===f&&e.state.fullyUnsetLocals.delete(h);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let h=e.state.localExportedVars.pop();if(h)for(let m of h)e.state.exportedVars?.delete(m)}for(let[h,m]of i)m===void 0?e.state.env.delete(h):e.state.env.set(h,m);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},u=new Map;try{let{targets:f,error:d}=await yi(e,t.redirections);if(u=f,d)return _("",d,1);let p=await xd(e,t.redirections),h=r||p,m=await e.executeCommand(t.body,h);return pe(e,m,t.redirections,u)}catch(f){if(f instanceof Oe){let d=_(f.stdout,f.stderr,f.exitCode);return pe(e,d,t.redirections,u)}throw f}finally{c()}}var uc=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],Ei=[".",":","[","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"],$d=["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"],kd=Ei;async function bi(e,t){let n=[],r=null,s="",i="",a=null,o=!1,l=!1,c=!1,u=null,f=null,d=null,p=[],h=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let A=0;A<t.length;A++){let x=t[A];if(x==="-v")n.push("variable");else if(x==="-e")n.push("export");else if(x==="-f")n.push("file");else if(x==="-d")n.push("directory");else if(x==="-k")n.push("keyword");else if(x==="-A"){if(A++,A>=t.length)return R(`compgen: -A: option requires an argument
122
- `,2);let P=t[A];if(!h.includes(P))return R(`compgen: ${P}: invalid action name
123
- `,2);n.push(P)}else if(x==="-W"){if(A++,A>=t.length)return R(`compgen: -W: option requires an argument
124
- `,2);r=t[A]}else if(x==="-P"){if(A++,A>=t.length)return R(`compgen: -P: option requires an argument
125
- `,2);s=t[A]}else if(x==="-S"){if(A++,A>=t.length)return R(`compgen: -S: option requires an argument
126
- `,2);i=t[A]}else if(x==="-o"){if(A++,A>=t.length)return R(`compgen: -o: option requires an argument
127
- `,2);let P=t[A];if(P==="plusdirs")o=!0;else if(P==="dirnames")l=!0;else if(P==="default")c=!0;else if(!(P==="filenames"||P==="nospace"||P==="bashdefault"||P==="noquote"))return R(`compgen: ${P}: invalid option name
128
- `,2)}else if(x==="-F"){if(A++,A>=t.length)return R(`compgen: -F: option requires an argument
129
- `,2);f=t[A]}else if(x==="-C"){if(A++,A>=t.length)return R(`compgen: -C: option requires an argument
130
- `,2);d=t[A]}else if(x==="-X"){if(A++,A>=t.length)return R(`compgen: -X: option requires an argument
131
- `,2);u=t[A]}else if(x==="-G"){if(A++,A>=t.length)return R(`compgen: -G: option requires an argument
132
- `,2)}else if(x==="--"){p.push(...t.slice(A+1));break}else x.startsWith("-")||p.push(x)}a=p[0]??null;let m=[],E=new Set,b=()=>e.limits.maxArrayElements-m.length,g=A=>{for(let x of A){if(m.length>=e.limits.maxArrayElements)throw new $(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(T(x)>e.limits.maxStringLength)throw new $(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");e.executionScope.consumeWork(1,"compgen completion"),m.push(x),E.add(x)}};if(l){let A=await gi(e,a,b());g(A)}if(c){let A=await cc(e,a,b());g(A)}for(let A of n)if(A==="variable"){let x=Nd(e,a,b());g(x)}else if(A==="export"){let x=Pd(e,a,b());g(x)}else if(A==="function"){let x=Cd(e,a,b());g(x)}else if(A==="builtin"){let x=Dd(e,a,b());g(x)}else if(A==="keyword"){let x=Rd(e,a,b());g(x)}else if(A==="alias"){let x=Id(e,a,b());g(x)}else if(A==="shopt"){let x=_d(e,a,b());g(x)}else if(A==="helptopic"){let x=Od(e,a,b());g(x)}else if(A==="directory"){let x=await gi(e,a,b());g(x)}else if(A==="file"){let x=await cc(e,a,b());g(x)}else if(A==="user"){let x=Ld(e,a,b());g(x)}else if(A==="command"){let x=await Td(e,a,b());g(x)}if(r!==null)try{let A=await Md(e,r),x=Bd(e,A,b(),a);for(let P of x)g([P])}catch(A){if(A instanceof $)throw A;return _("","",1)}if(o){let A=await gi(e,a,b(),E);for(let x of A)E.has(x)||g([x])}let w="";if(f!==null){let A=e.state.functions.get(f);if(A){let x=new Map,P=Se(e,"COMP_WORDS"),D=P?De(P):void 0;me(e,"COMP_WORDS"),Dn(e,"COMP_WORDS"),x.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),x.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),x.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let I=Se(e,"COMPREPLY"),O=I?De(I):void 0,B=e.state.env.get("COMPREPLY");me(e,"COMPREPLY"),e.state.env.delete("COMPREPLY");let Y=["compgen",p[0]??"",""];try{let J=await Qr(e,A,Y,"");if(J.exitCode!==0)return wi(e,x),bn(e,"COMP_WORDS",D),bn(e,"COMPREPLY",O),B!==void 0&&e.state.env.set("COMPREPLY",B),_("",J.stderr,1);w=J.stdout;let C=Wd(e,b());g(C)}catch(J){if(J instanceof $)throw J;return wi(e,x),bn(e,"COMP_WORDS",D),bn(e,"COMPREPLY",O),B!==void 0&&e.state.env.set("COMPREPLY",B),_("","",1)}wi(e,x),bn(e,"COMP_WORDS",D),bn(e,"COMPREPLY",O),B!==void 0&&e.state.env.set("COMPREPLY",B)}}if(d!==null)try{let A=tt(d),x=await e.executeScript(A);if(x.exitCode!==0)return _("",x.stderr,x.exitCode);if(x.stdout)for(let P of Fd(x.stdout))P.length>0&&g([P])}catch(A){if(A.name==="ParseException")return R(`compgen: -C: ${A.message}
133
- `,2);throw A}let S=m;if(u!==null){let A=u.startsWith("!"),x=A?u.slice(1):u;S=m.filter(P=>{let D=gn(P,x,!1,!0,e.limits.maxCallDepth);return A?D:!D})}if(S.length===0&&a!==null)return _(w,"",1);let v=new tn(e.limits.maxOutputSize,"compgen");v.append(w);for(let A of S)v.append(s).append(A).append(i).append(`
134
- `);return X(v.build())}function Nd(e,t,n){let r=Xe(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 Pd(e,t,n){let r=Xe(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 Cd(e,t,n){let r=Xe(e,t,n);for(let s of e.state.functions.keys())r.add(s);return r.build()}function Dd(e,t,n){let r=Xe(e,t,n);for(let s of Ei)r.add(s);return r.build()}function Rd(e,t,n){let r=Xe(e,t,n);for(let s of uc)r.add(s);return r.build()}function Id(e,t,n){let r=Xe(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 _d(e,t,n){let r=Xe(e,t,n);for(let s of $d)r.add(s);return r.build()}function Od(e,t,n){let r=Xe(e,t,n);for(let s of kd)r.add(s);return r.build()}async function gi(e,t,n=e.limits.maxArrayElements,r){let s=Xe(e,null,n,r);try{let i=e.state.cwd,a=t??"";if(t){let l=t.lastIndexOf("/");if(l!==-1){let c=t.slice(0,l)||"/";a=t.slice(l+1),c.startsWith("/")?i=c:i=`${e.state.cwd}/${c}`}}let o=await e.fs.readdir(i);for(let l of o){e.executionScope.consumeWork(1,"compgen directory scan");let c=`${i}/${l}`;try{if((await e.fs.stat(c)).isDirectory&&(!a||l.startsWith(a)))if(t?.includes("/")){let f=t.lastIndexOf("/"),d=t.slice(0,f+1);s.add(d+l)}else s.add(l)}catch(u){if(u instanceof $)throw u}}}catch(i){if(i instanceof $)throw i}return s.build()}async function cc(e,t,n=e.limits.maxArrayElements){let r=Xe(e,null,n);try{let s=e.state.cwd,i=t??"";if(t){let o=t.lastIndexOf("/");if(o!==-1){let l=t.slice(0,o)||"/";i=t.slice(o+1),l.startsWith("/")?s=l:s=`${e.state.cwd}/${l}`}}let a=await e.fs.readdir(s);for(let o of a)if(e.executionScope.consumeWork(1,"compgen file scan"),!i||o.startsWith(i))if(t?.includes("/")){let l=t.lastIndexOf("/"),c=t.slice(0,l+1);r.add(c+o)}else r.add(o)}catch(s){if(s instanceof $)throw s}return r.build()}function Ld(e,t,n){let r=Xe(e,t,n);return r.add("root"),r.add("nobody"),r.build()}async function Td(e,t,n){let r=Xe(e,t,n);for(let i of Ei)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 uc)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 $)throw a}return r.build()}function Xe(e,t,n,r){let s=new Set;return{add(i){if(e.executionScope.consumeWork(1,"compgen candidate collection"),!(t!==null&&!i.startsWith(t))&&!r?.has(i)&&!s.has(i)){if(s.size>=n)throw new $(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(T(i)>e.limits.maxStringLength)throw new $(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");s.add(i)}},build(){return Array.from(s).sort()}}}async function Md(e,t){let r=new V().parseWordFromString(t,!1,!1);return await W(e,r)}function Bd(e,t,n,r){let s=e.state.env.get("IFS")??`
135
- `;if(s.length===0){if(r!==null&&!t.startsWith(r))return[];if(n===0)throw new $(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");return[t]}let i=new Set(s.split("")),a=[],o=u=>{if(!(r!==null&&!u.startsWith(r))){if(a.length>=n)throw new $(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");a.push(u)}},l="",c=0;for(;c<t.length;){let u=t[c];if(u==="\\"&&c+1<t.length){let f=t[c+1];l+=f,c+=2}else i.has(u)?(l.length>0&&(o(l),l=""),c++):(l+=u,c++)}return l.length>0&&o(l),a}function wi(e,t){for(let[n,r]of t)r===void 0?e.state.env.delete(n):e.state.env.set(n,r)}function bn(e,t,n){e.state.arrays??=new Map,n?e.state.arrays.set(t,De(n)):e.state.arrays.delete(t)}function Wd(e,t){let n=[],r=s=>{if(n.length>=t)throw new $(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");n.push(s)};if($e(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*Fd(e){let t=0;for(;t<=e.length;){let n=e.indexOf(`
136
- `,t),r=n===-1?e.length:n;if(r>t&&(yield e.slice(t,r)),n===-1)return;t=n+1}}function Un(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n===127)return!0}return!1}function Si(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 fc(e){if(Un(e))return dc(e);if(e==="")return 2;if(/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e))return T(e);let t=T(e)+2;for(let n of e)n==="'"&&(t+=3);return t}function ge(e){return Un(e)?Si(e):e===""?"''":/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Kr(e){if(Un(e))return dc(e);let t=T(e)+2;for(let n of e)(n==="\\"||n==='"'||n==="$"||n==="`")&&t++;return t}function Bt(e){return Un(e)?Si(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}function dc(e){let t=3;for(let n of e){let r=n.codePointAt(0)??0;r===7||r===8||r===9||r===10||r===11||r===12||r===13||r===27||r===39||r===92?t+=2:r<32||r===127?t+=4:t+=T(n)}return t}function jn(e){return Un(e)?Si(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}var Vd=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function vi(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=!1,i,a,o,l=[],c=[],u=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-p")n=!0;else if(d==="-r")r=!0;else if(d==="-D")s=!0;else if(d==="-W"){if(f++,f>=t.length)return R(`complete: -W: option requires an argument
137
- `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return R(`complete: -F: option requires an argument
138
- `,2);a=t[f]}else if(d==="-o"){if(f++,f>=t.length)return R(`complete: -o: option requires an argument
139
- `,2);let p=t[f];if(!Vd.includes(p))return R(`complete: ${p}: invalid option name
140
- `,2);l.push(p)}else if(d==="-A"){if(f++,f>=t.length)return R(`complete: -A: option requires an argument
141
- `,2);c.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return R(`complete: -C: option requires an argument
142
- `,2);o=t[f]}else if(d==="-G"){if(f++,f>=t.length)return R(`complete: -G: option requires an argument
143
- `,2)}else if(d==="-P"){if(f++,f>=t.length)return R(`complete: -P: option requires an argument
144
- `,2)}else if(d==="-S"){if(f++,f>=t.length)return R(`complete: -S: option requires an argument
145
- `,2)}else if(d==="-X"){if(f++,f>=t.length)return R(`complete: -X: option requires an argument
146
- `,2)}else if(d==="--"){u.push(...t.slice(f+1));break}else d.startsWith("-")||u.push(d)}if(r){if(u.length===0)return e.state.completionSpecs.clear(),e.state.defaultCompletionSpec=void 0,e.state.emptyCompletionSpec=void 0,X("");for(let f of u)e.state.completionSpecs.delete(f);return X("")}if(n)return u.length===0?Ai(e):Ai(e,u);if(t.length===0||u.length===0&&!i&&!a&&!o&&l.length===0&&c.length===0&&!s)return Ai(e);if(a&&u.length===0&&!s)return R(`complete: -F: option requires a command name
147
- `,2);if(s){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),a!==void 0&&(f.function=a),o!==void 0&&(f.command=o),l.length>0&&(f.options=l),c.length>0&&(f.actions=c),e.state.defaultCompletionSpec=f,X("")}for(let f of u){let d=Object.create(null);i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),o!==void 0&&(d.command=o),l.length>0&&(d.options=l),c.length>0&&(d.actions=c),e.state.completionSpecs.set(f,d)}return X("")}function Ai(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
148
- `;return _("",i,1)}return X("")}let r=[],s=t||Array.from(n.keys());for(let i of s){let a=n.get(i);if(!a){if(t)return _(r.join(`
128
+ `}return null}function ic(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 or="scoped",ac="bare",lc="persistent",Yp=e=>new k(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors"),Jp=(e,t)=>fn(e,t)||(e.state.fileDescriptors?.size??0)<e.limits.maxFileDescriptors,oc=e=>{let t=Math.max(e.state.nextFd??10,10);for(;fn(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},eh=(e,t,n)=>{let r=Ye(e,t);return t<we?r?{kind:"entry",entry:r,descriptors:Gt(e,t)}:{kind:"standard",fd:t}:r?n?r.kind==="input"||r.kind==="readwrite"||r.kind==="dup-in"?{kind:"entry",entry:r,descriptors:Gt(e,t)}:null:r.kind==="output"||r.kind==="readwrite"||r.kind==="dup-out"?{kind:"entry",entry:r,descriptors:Gt(e,t)}:null:null};async function _n(e,t,n,r,s=!0){let i=e.fs.resolvePath(e.state.cwd,t),o=await Xp(e,i,t,{checkNoclobber:!n,isClobber:r});if(o)return{error:L("",o,1)};if(t==="/dev/full")return{error:L("",`bash: /dev/full: No space left on device
129
+ `,1)};if(t==="/dev/stdout")return{entry:{kind:"dup-out",sourceFd:1}};if(t==="/dev/stderr")return{entry:{kind:"dup-out",sourceFd:2}};try{n?await e.fs.appendFile(i,"","binary"):await e.fs.writeFile(i,"","binary")}catch(a){if(!s)throw a;return{error:L("",`bash: ${t}: cannot open redirect target
130
+ `,1)}}return{entry:{kind:"output",path:i,append:n}}}async function Yi(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
+ `,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 th=async(e,t)=>{let n=await ne(e,t.content);return t.stripTabs?n.split(`
133
+ `).map(r=>r.replace(/^\t+/,"")).join(`
134
+ `):n};async function nh(e,t,n,r){let s=new Map,i=new Map,o=(g,y)=>e.state.closedStandardFds?.has(g)?{kind:"closed"}:Ye(e,g)??y,a=new Map([[0,o(0,{kind:"dup-in",sourceFd:0})],[1,o(1,{kind:"dup-out",sourceFd:1})],[2,o(2,{kind:"dup-out",sourceFd:2})]]),l=r.numericSnapshot,u,c=-1,f=a.get(0);f?.kind==="input"?(u=f.content,c=0):f?.kind==="readwrite"&&(u=f.content.slice(f.position),c=0);let d=()=>({targets:s,dupSources:i,standardRoutes:a,stdin:u,stdinSourceFd:c,error:null}),p=async(g,y,S)=>{let v={...d(),error:await Qt(e,g,t.slice(0,y),s,i,a)};return S?{...v,errorCause:S}:v},h=async(g,y)=>{if(Jp(e,g))return null;let S=Yp(e);return p(L("",S.stderr,k.EXIT_CODE),y,S)},m=(g,y)=>{g!==null&&g<we&&a.set(g,y),r.policy==="persistent"&&g!==null&&g<we&&(e.state.closedStandardFds?.delete(g),rt(e,g,y))},E=(g,y)=>{a.set(g,y),Ht(e,r.standardSnapshot,g),r.standardClosedSnapshot.has(g)||r.standardClosedSnapshot.set(g,e.state.closedStandardFds?.has(g)===!0),e.state.closedStandardFds?.delete(g),rt(e,g,y)},b=(g,y)=>{if(g<we){let S=a.get(g);return S?.kind==="closed"?null:S?{kind:"entry",entry:S,descriptors:Gt(e,g)}:{kind:"standard",fd:g}}return eh(e,g,y)};for(let g=0;g<t.length;g++){let y=t[g],S=Xi(y);if(y.target.type==="HereDoc"){let A=await th(e,y.target);if(y.fdVariable){try{ue(e,y.fdVariable)}catch($){if(!($ instanceof U))throw $;return p(L($.stdout,$.stderr,$.exitCode),g,$)}let C=oc(e),N=await h(C,g);if(N)return N;Ht(e,r.fdVariableSnapshot,C),r.fdVariableEnv.has(y.fdVariable)||r.fdVariableEnv.set(y.fdVariable,e.state.env.get(y.fdVariable)),rt(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;Ht(e,l,S),rt(e,S,{kind:"input",content:A})}else if(S===0||S===null)u=en(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,x=y.operator===">&"||y.operator==="<&";if(x){if(Ni(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 Tu(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(x&&v==="-"){let R=Number.parseInt(e.state.env.get(y.fdVariable)??"",10);Number.isNaN(R)||(Ht(e,r.fdVariableSnapshot,R),bt(e,R));continue}let A=oc(e),C=x?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}Ht(e,r.fdVariableSnapshot,A),r.fdVariableEnv.has(y.fdVariable)||r.fdVariableEnv.set(y.fdVariable,e.state.env.get(y.fdVariable));let $,P;if(x){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"?$={kind:y.operator==="<&"?"dup-in":"dup-out",sourceFd:B.fd}:R.sourceFd<we&&($=B.entry)}else{if(y.operator==="<&")return p(L("",`bash: ${v}: ambiguous redirect
139
+ `,1),g);let B=await _n(e,v,!1,!1);if(B.error)return p(B.error,g);$=B.entry}}else if(y.operator===">"||y.operator===">|"||y.operator===">>"||y.operator==="&>"||y.operator==="&>>"){let R=y.operator===">>"||y.operator==="&>>",B=await _n(e,v,R,y.operator===">|");if(B.error)return p(B.error,g);$=B.entry}else if(y.operator==="<<<")$={kind:"input",content:`${v}
140
+ `};else if(y.operator==="<"||y.operator==="<>"){let R=await Yi(e,v,y.operator==="<>");if(R.error)return p(R.error,g);$=R.entry}if(P&&P.sourceFd>=we){if(!(P.move?Qi(e,A,P.sourceFd):ps(e,A,P.sourceFd)))return p(L("",`bash: ${P.sourceFd}: Bad file descriptor
141
+ `,1),g)}else $&&rt(e,A,$);P?.move&&P.sourceFd!==A&&P.sourceFd<we&&bt(e,P.sourceFd),e.state.env.set(y.fdVariable,String(A)),e.state.nextFd=A+1;continue}if(sc(y)){let A=S;if(x&&v==="-"){Ht(e,l,A),bt(e,A);continue}let C=x?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 $=await h(A,g);if($)return $}if(Ht(e,l,A),x){let $=C;if(!$){if(y.operator==="<&")return p(L("",`bash: ${v}: ambiguous redirect
143
+ `,1),g);let R=await _n(e,v,!1,!1);if(R.error)return p(R.error,g);rt(e,A,R.entry);continue}let P=b($.sourceFd,y.operator==="<&");if(!P)return p(L("",`bash: ${$.sourceFd}: Bad file descriptor
144
+ `,1),g);if(P.kind==="standard")rt(e,A,{kind:y.operator==="<&"?"dup-in":"dup-out",sourceFd:P.fd});else if($.sourceFd<we)rt(e,A,P.entry);else if(!($.move?Qi(e,A,$.sourceFd):ps(e,A,$.sourceFd)))return p(L("",`bash: ${$.sourceFd}: Bad file descriptor
145
+ `,1),g);$.move&&$.sourceFd!==A&&$.sourceFd<we&&bt(e,$.sourceFd);continue}if(y.operator===">"||y.operator===">|"||y.operator===">>"){let $=await _n(e,v,y.operator===">>",y.operator===">|");if($.error)return p($.error,g);rt(e,A,$.entry)}else if(y.operator==="<<<")rt(e,A,{kind:"input",content:`${v}
146
+ `});else if(y.operator==="<"||y.operator==="<>"){let $=await Yi(e,v,y.operator==="<>");if($.error)return p($.error,g);rt(e,A,$.entry)}continue}if(x){if(v==="-"){S===0&&(u="",c=-1),S!==null&&S<we&&(a.set(S,{kind:"closed"}),r.policy==="persistent"&&(bt(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 _n(e,v,!1,!1,!1);if(N.error)return p(N.error,g);let $=N.entry;i.set(g,{kind:"entry",entry:$,descriptors:[]}),y.fd==null?(m(1,$),m(2,$)):m(S,$);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);a.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&&!fn(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=fn(e,A.sourceFd)?A.sourceFd:-1}else u=n,c=-1;A.move&&(A.sourceFd>=we?bt(e,A.sourceFd):(a.set(A.sourceFd,{kind:"closed"}),r.policy==="persistent"&&(bt(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 _n(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=en(`${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 hn(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 Yi(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 Ln(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="")=>nh(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,o]of r.standardClosedSnapshot)o?(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,o]of r.fdVariableEnv)o===void 0?e.state.env.delete(i):e.state.env.set(i,o);e.state.nextFd=r.nextFd}}}}}function Tn(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 Ji(e,t,n,r){let s=t instanceof U||t instanceof De||t instanceof Me?t.exitCode:t instanceof k?k.EXIT_CODE:0,i=await Qt(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=Ln(e,t,or),i;try{if(i=await s.prepare(n),i.error)return Tn(i);let o=e.state.groupStdin,a=e.state.groupStdinSourceFd;i.stdin!==void 0&&(e.state.groupStdin=i.stdin,e.state.groupStdinSourceFd=i.stdinSourceFd);try{let l=await r(i);return await Qt(e,l,t,i.targets,i.dupSources,i.standardRoutes)}finally{i.stdin!==void 0&&(e.state.groupStdin=o,e.state.groupStdinSourceFd=a)}}catch(o){throw!(o instanceof mn)||!i||await Ji(e,o,t,i),o}finally{s.finish()}}async function Qt(e,t,n,r,s=new Map,i=new Map,o="bash",a=!1){n.length>0&&(t=e.executionScope.accountResult(t,"redirection"));let{stdout:l,stderr:u,exitCode:c}=t,d=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",p=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:Gt(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 x=r.get(S);if(x!==void 0)switch(v.operator){case">":case">|":case">>":{let A=v.fd??1;if(A!==1&&A!==2)break;let C=v.operator===">>";if(x==="/dev/stdout"){A===2&&(m=h);break}if(x==="/dev/stderr"){A===1&&(h=m);break}if(x==="/dev/full"){u+=`bash: echo: write error: No space left on device
153
+ `,c=1,A===1&&(l="");break}if(x==="/dev/null"&&A===2){m={kind:"discard"};break}let N=e.fs.resolvePath(e.state.cwd,x);A===1?h={kind:"file",path:N,append: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(x==="-"){A===1?h={kind:"discard"}:m={kind:"discard"};break}let C=E(s.get(S));if(!C)break;v.fd==null&&ys(x)===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,x),append:!1},m=h;break}case"&>>":{h={kind:"file",path:e.fs.resolvePath(e.state.cwd,x),append:!0},m=h;break}}}if(l!==""||u!==""){let S=l,v=u;l="",u="",h.kind==="invalid-output"&&S!==""&&(S="",v+=`${a?"":"bash: "}${o}: write error: Bad file descriptor
154
+ `,c=1),m.kind==="invalid-output"&&(v="");let x=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 x(h,A,p(A)):await Ki(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 x(C,A,N?p(A):ic(A));break;case"descriptor":await Ki(e,C.source.entry,C.source.descriptors,A,N?p(A):ic(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),x=F(g.stderr),A=Math.min(v,S);g.internalOutputAccounting={stdout:A,stderr:Math.min(x,S-A)},e.executionScope.accountResult(g,"redirection")}else t.internalOutputAccounting&&(g.internalOutputAccounting=t.internalOutputAccounting);return g}function uc(e,t){if(e.state.options.posix&&Bi.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--,qt(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(s??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localArrayScopes??=[],e.state.localArrayScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let o=new Map,a=Number.parseInt(e.state.env.get("#")??"0",10),l=Math.max(n.length,a);for(let p=0;p<l;p++){let h=String(p+1);o.set(h,e.state.env.get(h)),p<n.length?e.state.env.set(h,n[p]):e.state.env.delete(h)}o.set("@",e.state.env.get("@")),o.set("#",e.state.env.get("#")),e.state.env.set("@",n.join(" ")),e.state.env.set("#",String(n.length));let u=!1,c=()=>{if(u)return;u=!0;let p=e.state.localScopes.length-1,h=e.state.localScopes.pop(),m=e.state.localArrayScopes?.pop();if(h)for(let[E,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,_e(b)),e.state.associativeArrays??=new Set,b.kind==="associative"?e.state.associativeArrays.add(E):e.state.associativeArrays.delete(E))}if(ec(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 o)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=Ln(e,t.redirections,or);try{if(f=await d.prepare(r),f.error)return Tn(f);let p=f.stdin??r,h=i||f.stdin!==void 0||r!=="",m=await e.executeCommand(t.body,p,h);return Qt(e,m,t.redirections,f.targets,f.dupSources,f.standardRoutes)}catch(p){if(p instanceof mn&&f&&(await Ji(e,p,t.redirections,f),p instanceof De))return L(p.stdout,p.stderr,p.exitCode);throw p}finally{d.finish(),c()}}var fc=e=>e.type==="Escaped"?T.literal(`\\${e.value}`):e.type==="DoubleQuoted"?{...e,parts:e.parts.map(fc)}:e,dc=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],no=[".",":","[","alias","bg","bind","break","builtin","caller","cd","command","compgen","complete","compopt","continue","declare","dirs","disown","echo","enable","eval","exec","exit","export","false","fc","fg","getopts","hash","help","history","jobs","kill","let","local","logout","mapfile","popd","printf","pushd","pwd","read","readarray","readonly","return","set","shift","shopt","source","suspend","test","times","trap","true","type","typeset","ulimit","umask","unalias","unset","wait"],rh=["autocd","assoc_expand_once","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","dotglob","execfail","expand_aliases","extdebug","extglob","extquote","failglob","force_fignore","globasciiranges","globstar","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lastpipe","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","nocaseglob","nocasematch","nullglob","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath","xpg_echo"],sh=no;async function ro(e,t){let n=[],r=null,s="",i="",o=null,a=!1,l=!1,u=!1,c=null,f=null,d=null,p=[],h=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let x=0;x<t.length;x++){let A=t[x];if(A==="-v")n.push("variable");else if(A==="-e")n.push("export");else if(A==="-f")n.push("file");else if(A==="-d")n.push("directory");else if(A==="-k")n.push("keyword");else if(A==="-A"){if(x++,x>=t.length)return I(`compgen: -A: option requires an argument
156
+ `,2);let C=t[x];if(!h.includes(C))return I(`compgen: ${C}: invalid action name
157
+ `,2);n.push(C)}else if(A==="-W"){if(x++,x>=t.length)return I(`compgen: -W: option requires an argument
158
+ `,2);r=t[x]}else if(A==="-P"){if(x++,x>=t.length)return I(`compgen: -P: option requires an argument
159
+ `,2);s=t[x]}else if(A==="-S"){if(x++,x>=t.length)return I(`compgen: -S: option requires an argument
160
+ `,2);i=t[x]}else if(A==="-o"){if(x++,x>=t.length)return I(`compgen: -o: option requires an argument
161
+ `,2);let C=t[x];if(C==="plusdirs")a=!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(x++,x>=t.length)return I(`compgen: -F: option requires an argument
163
+ `,2);f=t[x]}else if(A==="-C"){if(x++,x>=t.length)return I(`compgen: -C: option requires an argument
164
+ `,2);d=t[x]}else if(A==="-X"){if(x++,x>=t.length)return I(`compgen: -X: option requires an argument
165
+ `,2);c=t[x]}else if(A==="-G"){if(x++,x>=t.length)return I(`compgen: -G: option requires an argument
166
+ `,2)}else if(A==="--"){p.push(...t.slice(x+1));break}else A.startsWith("-")||p.push(A)}o=p[0]??null;let m=[],E=new Set,b=()=>e.limits.maxArrayElements-m.length,g=x=>{for(let A of x){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 x=await eo(e,o,b());g(x)}if(u){let x=await cc(e,o,b());g(x)}for(let x of n)if(x==="variable"){let A=ih(e,o,b());g(A)}else if(x==="export"){let A=oh(e,o,b());g(A)}else if(x==="function"){let A=ah(e,o,b());g(A)}else if(x==="builtin"){let A=lh(e,o,b());g(A)}else if(x==="keyword"){let A=uh(e,o,b());g(A)}else if(x==="alias"){let A=ch(e,o,b());g(A)}else if(x==="shopt"){let A=fh(e,o,b());g(A)}else if(x==="helptopic"){let A=dh(e,o,b());g(A)}else if(x==="directory"){let A=await eo(e,o,b());g(A)}else if(x==="file"){let A=await cc(e,o,b());g(A)}else if(x==="user"){let A=ph(e,o,b());g(A)}else if(x==="command"){let A=await hh(e,o,b());g(A)}if(r!==null)try{let x=await mh(e,r),A=yh(e,x,b(),o);for(let C of A)g([C])}catch(x){if(x instanceof k)throw x;return L("","",1)}if(a){let x=await eo(e,o,b(),E);for(let A of x)E.has(A)||g([A])}let y="";if(f!==null){let x=e.state.functions.get(f);if(x){let A=new Map,C=ve(e,"COMP_WORDS"),N=C?_e(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 $=ve(e,"COMPREPLY"),P=$?_e($):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,x,B,"");if(q.exitCode!==0)return to(e,A),Mn(e,"COMP_WORDS",N),Mn(e,"COMPREPLY",P),R!==void 0&&e.state.env.set("COMPREPLY",R),L("",q.stderr,1);y=q.stdout;let D=gh(e,b());g(D)}catch(q){if(q instanceof k)throw q;return to(e,A),Mn(e,"COMP_WORDS",N),Mn(e,"COMPREPLY",P),R!==void 0&&e.state.env.set("COMPREPLY",R),L("","",1)}to(e,A),Mn(e,"COMP_WORDS",N),Mn(e,"COMPREPLY",P),R!==void 0&&e.state.env.set("COMPREPLY",R)}}if(d!==null)try{let x=at(d),A=await e.executeScript(x);if(A.exitCode!==0)return L("",A.stderr,A.exitCode);if(A.stdout)for(let C of wh(A.stdout))C.length>0&&g([C])}catch(x){if(x.name==="ParseException")return I(`compgen: -C: ${x.message}
167
+ `,2);throw x}let S=m;if(c!==null){let x=c.startsWith("!"),A=x?c.slice(1):c;S=m.filter(C=>{let N=Dn(C,A,!1,!0,e.limits.maxCallDepth);return x?N:!N})}if(S.length===0&&o!==null)return L(y,"",1);let v=new yn(e.limits.maxOutputSize,"compgen");v.append(y);for(let x of S)v.append(s).append(x).append(i).append(`
168
+ `);return Y(v.build())}function ih(e,t,n){let r=st(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 oh(e,t,n){let r=st(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 ah(e,t,n){let r=st(e,t,n);for(let s of e.state.functions.keys())r.add(s);return r.build()}function lh(e,t,n){let r=st(e,t,n);for(let s of no)r.add(s);return r.build()}function uh(e,t,n){let r=st(e,t,n);for(let s of dc)r.add(s);return r.build()}function ch(e,t,n){let r=st(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 fh(e,t,n){let r=st(e,t,n);for(let s of rh)r.add(s);return r.build()}function dh(e,t,n){let r=st(e,t,n);for(let s of sh)r.add(s);return r.build()}async function eo(e,t,n=e.limits.maxArrayElements,r){let s=st(e,null,n,r);try{let i=e.state.cwd,o=t??"";if(t){let l=t.lastIndexOf("/");if(l!==-1){let u=t.slice(0,l)||"/";o=t.slice(l+1),u.startsWith("/")?i=u:i=`${e.state.cwd}/${u}`}}let a=await e.fs.readdir(i);for(let l of a){e.executionScope.consumeWork(1,"compgen directory scan");let u=`${i}/${l}`;try{if((await e.fs.stat(u)).isDirectory&&(!o||l.startsWith(o)))if(t?.includes("/")){let f=t.lastIndexOf("/"),d=t.slice(0,f+1);s.add(d+l)}else s.add(l)}catch(c){if(c instanceof k)throw c}}}catch(i){if(i instanceof k)throw i}return s.build()}async function cc(e,t,n=e.limits.maxArrayElements){let r=st(e,null,n);try{let s=e.state.cwd,i=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";i=t.slice(a+1),l.startsWith("/")?s=l:s=`${e.state.cwd}/${l}`}}let o=await e.fs.readdir(s);for(let a of o)if(e.executionScope.consumeWork(1,"compgen file scan"),!i||a.startsWith(i))if(t?.includes("/")){let l=t.lastIndexOf("/"),u=t.slice(0,l+1);r.add(u+a)}else r.add(a)}catch(s){if(s instanceof k)throw s}return r.build()}function ph(e,t,n){let r=st(e,t,n);return r.add("root"),r.add("nobody"),r.build()}async function hh(e,t,n){let r=st(e,t,n);for(let i of no)r.add(i);for(let i of e.state.functions.keys())r.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&r.add(i.slice(11));for(let i of dc)r.add(i);let s=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of s.split(":"))if(i)try{let o=await e.fs.readdir(i);for(let a of o)r.add(a)}catch(o){if(o instanceof k)throw o}return r.build()}function st(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 mh(e,t){let r=new G().parseWordFromString(t,!1,!1);return await ne(e,T.word(r.parts.map(fc)))}function yh(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("")),o=[],a=c=>{if(!(r!==null&&!c.startsWith(r))){if(o.length>=n)throw new k(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");o.push(c)}},l="",u=0;for(;u<t.length;){let c=t[u];if(c==="\\"&&u+1<t.length){let f=t[u+1];l+=f,u+=2}else i.has(c)?(l.length>0&&(a(l),l=""),u++):(l+=c,u++)}return l.length>0&&a(l),o}function to(e,t){for(let[n,r]of t)r===void 0?e.state.env.delete(n):e.state.env.set(n,r)}function Mn(e,t,n){e.state.arrays??=new Map,n?e.state.arrays.set(t,_e(n)):e.state.arrays.delete(t)}function gh(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(ke(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*wh(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 ar(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n===127)return!0}return!1}function so(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 pc(e){if(ar(e))return hc(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 ar(e)?so(e):e===""?"''":/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function ws(e){if(ar(e))return hc(e);let t=F(e)+2;for(let n of e)(n==="\\"||n==='"'||n==="$"||n==="`")&&t++;return t}function Kt(e){return ar(e)?so(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}function hc(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 ar(e)?so(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}var Eh=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function oo(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=!1,i,o,a,l=[],u=[],c=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-p")n=!0;else if(d==="-r")r=!0;else if(d==="-D")s=!0;else if(d==="-W"){if(f++,f>=t.length)return 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);o=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(!Eh.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);a=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?io(e):io(e,c);if(t.length===0||c.length===0&&!i&&!o&&!a&&l.length===0&&u.length===0&&!s)return io(e);if(o&&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),o!==void 0&&(f.function=o),a!==void 0&&(f.command=a),l.length>0&&(f.options=l),u.length>0&&(f.actions=u),e.state.defaultCompletionSpec=f,Y("")}for(let f of c){let d=Object.create(null);i!==void 0&&(d.wordlist=i),o!==void 0&&(d.function=o),a!==void 0&&(d.command=a),l.length>0&&(d.options=l),u.length>0&&(d.actions=u),e.state.completionSpecs.set(f,d)}return Y("")}function io(e,t){let n=e.state.completionSpecs??new Map;if(n.size===0&&!e.state.defaultCompletionSpec){if(t&&t.length>0){let i="";for(let o of t)i+=`complete: ${o}: no completion specification
182
+ `;return L("",i,1)}return Y("")}let r=[],s=t||Array.from(n.keys());for(let i of s){let o=n.get(i);if(!o){if(t)return L(r.join(`
149
183
  `)+(r.length>0?`
150
184
  `:""),`complete: ${i}: no completion specification
151
- `,1);continue}let o="complete";if(a.options)for(let l of a.options)o+=` -o ${ge(l)}`;if(a.actions)for(let l of a.actions)o+=` -A ${ge(l)}`;a.wordlist!==void 0&&(a.wordlist.includes(" ")||a.wordlist.includes("'")?o+=` -W ${ge(a.wordlist)}`:o+=` -W ${ge(a.wordlist)}`),a.function!==void 0&&(o+=` -F ${ge(a.function)}`),a.command!==void 0&&(o+=` -C ${ge(a.command)}`),a.isDefault&&(o+=" -D"),o+=`${i.startsWith("-")?" -- ":" "}${ge(i)}`,r.push(o)}if(!t&&e.state.defaultCompletionSpec){let i=e.state.defaultCompletionSpec,a="complete";for(let o of i.options??[])a+=` -o ${ge(o)}`;for(let o of i.actions??[])a+=` -A ${ge(o)}`;i.wordlist!==void 0&&(a+=` -W ${ge(i.wordlist)}`),i.function!==void 0&&(a+=` -F ${ge(i.function)}`),i.command!==void 0&&(a+=` -C ${ge(i.command)}`),a+=" -D",r.push(a)}return r.length===0?X(""):X(`${r.join(`
185
+ `,1);continue}let a="complete";if(o.options)for(let l of o.options)a+=` -o ${Ee(l)}`;if(o.actions)for(let l of o.actions)a+=` -A ${Ee(l)}`;o.wordlist!==void 0&&(o.wordlist.includes(" ")||o.wordlist.includes("'")?a+=` -W ${Ee(o.wordlist)}`:a+=` -W ${Ee(o.wordlist)}`),o.function!==void 0&&(a+=` -F ${Ee(o.function)}`),o.command!==void 0&&(a+=` -C ${Ee(o.command)}`),o.isDefault&&(a+=" -D"),a+=`${i.startsWith("-")?" -- ":" "}${Ee(i)}`,r.push(a)}if(!t&&e.state.defaultCompletionSpec){let i=e.state.defaultCompletionSpec,o="complete";for(let a of i.options??[])o+=` -o ${Ee(a)}`;for(let a of i.actions??[])o+=` -A ${Ee(a)}`;i.wordlist!==void 0&&(o+=` -W ${Ee(i.wordlist)}`),i.function!==void 0&&(o+=` -F ${Ee(i.function)}`),i.command!==void 0&&(o+=` -C ${Ee(i.command)}`),o+=" -D",r.push(o)}return r.length===0?Y(""):Y(`${r.join(`
152
186
  `)}
153
- `)}var pc=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function xi(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=[],i=[],a=[];for(let o=0;o<t.length;o++){let l=t[o];if(l==="-D")n=!0;else if(l==="-E")r=!0;else if(l==="-o"){if(o++,o>=t.length)return R(`compopt: -o: option requires an argument
154
- `,2);let c=t[o];if(!pc.includes(c))return R(`compopt: ${c}: invalid option name
155
- `,2);s.push(c)}else if(l==="+o"){if(o++,o>=t.length)return R(`compopt: +o: option requires an argument
156
- `,2);let c=t[o];if(!pc.includes(c))return R(`compopt: ${c}: invalid option name
157
- `,2);i.push(c)}else if(l==="--"){a.push(...t.slice(o+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&a.push(l)}if(n){let o=e.state.defaultCompletionSpec??{isDefault:!0},l=new Set(o.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return o.options=l.size>0?Array.from(l):void 0,e.state.defaultCompletionSpec=o,X("")}if(r){let o=e.state.emptyCompletionSpec??Object.create(null),l=new Set(o.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return o.options=l.size>0?Array.from(l):void 0,e.state.emptyCompletionSpec=o,X("")}if(a.length>0){for(let o of a){let l=e.state.completionSpecs.get(o)??{},c=new Set(l.options??[]);for(let u of s)c.add(u);for(let u of i)c.delete(u);l.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set(o,l)}return X("")}return R(`compopt: not currently executing completion function
158
- `,1)}function $i(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new St;return te}if(t.length>1)throw new j(1,"",`bash: continue: too many arguments
159
- `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new j(1,"",`bash: continue: ${t[0]}: numeric argument required
160
- `);n=r}throw new Ue(n)}function hc(e,t){let n="";return e.state.integerVars?.has(t)&&(n+="i"),e.state.lowercaseVars?.has(t)&&(n+="l"),ae(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 ki(e){return ge(e)}function Ni(e){return`'${e.replace(/'/g,"'\\''")}'`}function mc(e,t){let n="",r="",s=!1;for(let i of t){let a=hc(e,i);if(e.state.associativeArrays?.has(i)){let u=ut(e,i);if(u.length===0)n+=`declare -A ${i}=()
161
- `;else{let f=u.map(d=>{let p=se(e,i,d)??"",h=ki(p);return`[${Ni(d)}]=${h}`});n+=`declare -A ${i}=(${f.join(" ")})
162
- `}continue}let l=Ee(e,i);if(l.length>0){let u=l.map(f=>{let d=se(e,i,f)??"";return`[${f}]=${Bt(d)}`});n+=`declare -a ${i}=(${u.join(" ")})
163
- `;continue}if($e(e,i)){n+=`declare -a ${i}=()
164
- `;continue}let c=e.state.env.get(i);if(c!==void 0)n+=`declare ${a} ${i}=${jn(c)}
165
- `;else{let u=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);u||f?n+=`declare ${a} ${i}
187
+ `)}var mc=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function ao(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=[],i=[],o=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-D")n=!0;else if(l==="-E")r=!0;else if(l==="-o"){if(a++,a>=t.length)return I(`compopt: -o: option requires an argument
188
+ `,2);let u=t[a];if(!mc.includes(u))return I(`compopt: ${u}: invalid option name
189
+ `,2);s.push(u)}else if(l==="+o"){if(a++,a>=t.length)return I(`compopt: +o: option requires an argument
190
+ `,2);let u=t[a];if(!mc.includes(u))return I(`compopt: ${u}: invalid option name
191
+ `,2);i.push(u)}else if(l==="--"){o.push(...t.slice(a+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&o.push(l)}if(n){let a=e.state.defaultCompletionSpec??{isDefault:!0},l=new Set(a.options??[]);for(let u of s)l.add(u);for(let u of i)l.delete(u);return a.options=l.size>0?Array.from(l):void 0,e.state.defaultCompletionSpec=a,Y("")}if(r){let a=e.state.emptyCompletionSpec??Object.create(null),l=new Set(a.options??[]);for(let u of s)l.add(u);for(let u of i)l.delete(u);return a.options=l.size>0?Array.from(l):void 0,e.state.emptyCompletionSpec=a,Y("")}if(o.length>0){for(let a of o){let l=e.state.completionSpecs.get(a)??{},u=new Set(l.options??[]);for(let c of s)u.add(c);for(let c of i)u.delete(c);l.options=u.size>0?Array.from(u):void 0,e.state.completionSpecs.set(a,l)}return Y("")}return I(`compopt: not currently executing completion function
192
+ `,1)}function lo(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Nt;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 yc(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 uo(e){return Ee(e)}function co(e){return`'${e.replace(/'/g,"'\\''")}'`}function gc(e,t){let n="",r="",s=!1;for(let i of t){let o=yc(e,i);if(e.state.associativeArrays?.has(i)){let c=mt(e,i);if(c.length===0)n+=`declare -A ${i}=()
195
+ `;else{let f=c.map(d=>{let p=oe(e,i,d)??"",h=uo(p);return`[${co(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=oe(e,i,f)??"";return`[${f}]=${Kt(d)}`});n+=`declare -a ${i}=(${c.join(" ")})
197
+ `;continue}if(ke(e,i)){n+=`declare -a ${i}=()
198
+ `;continue}let u=e.state.env.get(i);if(u!==void 0)n+=`declare ${o} ${i}=${lr(u)}
199
+ `;else{let c=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);c||f?n+=`declare ${o} ${i}
166
200
  `:(r+=`bash: declare: ${i}: not found
167
- `,s=!0)}}return _(n,r,s?1:0)}function yc(e,t){let{filterExport:n,filterReadonly:r,filterNameref:s,filterIndexedArray:i,filterAssocArray:a}=t,o=n||r||s||i||a,l="",c=new Set;for(let f of e.state.env.keys())f.startsWith("BASH_")||c.add(f);for(let f of e.state.arrays?.keys()??[])c.add(f);if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())c.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)c.add(f);let u=Array.from(c).sort();for(let f of u){let d=hc(e,f),p=e.state.associativeArrays?.has(f),h=Ee(e,f),m=!p&&$e(e,f);if(o&&(a&&!p||i&&!m||n&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||s&&!ae(e,f)))continue;if(p){let b=ut(e,f);if(b.length===0)l+=`declare -A ${f}=()
168
- `;else{let g=b.map(w=>{let S=se(e,f,w)??"",v=ki(S);return`[${Ni(w)}]=${v}`});l+=`declare -A ${f}=(${g.join(" ")})
169
- `}continue}if(h.length>0){let b=h.map(g=>{let w=se(e,f,g)??"";return`[${g}]=${Bt(w)}`});l+=`declare -a ${f}=(${b.join(" ")})
170
- `;continue}if($e(e,f)){l+=`declare -a ${f}=()
171
- `;continue}let E=e.state.env.get(f);E!==void 0&&(l+=`declare ${d} ${f}=${jn(E)}
172
- `)}return X(l)}function gc(e){let t="",n=Array.from(e.state.associativeArrays??[]).sort();for(let r of n){let s=ut(e,r);if(s.length===0)t+=`declare -A ${r}=()
173
- `;else{let i=s.map(a=>{let o=se(e,r,a)??"",l=ki(o);return`[${Ni(a)}]=${l}`});t+=`declare -A ${r}=(${i.join(" ")})
174
- `}}return X(t)}function wc(e){let t="",n=new Set(Array.from(e.state.arrays??[]).filter(([,s])=>s.kind==="indexed").map(([s])=>s)),r=Array.from(n).sort();for(let s of r){let i=Ee(e,s);if(i.length===0)t+=`declare -a ${s}=()
175
- `;else{let a=i.map(o=>{let l=se(e,s,o)??"";return`[${o}]=${Bt(l)}`});t+=`declare -a ${s}=(${a.join(" ")})
176
- `}}return X(t)}function Ec(e){let t="",n=new Set;for(let s of e.state.env.keys())s.startsWith("BASH_")||n.add(s);let r=Array.from(n).sort();for(let s of r){if(e.state.associativeArrays?.has(s)||Ee(e,s).length>0||$e(e,s))continue;let o=e.state.env.get(s);o!==void 0&&(t+=`${s}=${ge(o)}
177
- `)}return X(t)}function Pi(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function Gn(e,t){return e.state.integerVars?.has(t)??!1}function Ci(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function zd(e,t){return e.state.lowercaseVars?.has(t)??!1}function Di(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function qd(e,t){return e.state.uppercaseVars?.has(t)??!1}function Sn(e,t,n){return zd(e,t)?n.toLowerCase():qd(e,t)?n.toUpperCase():n}async function bc(e,t){try{let n=new V,r=ne(n,t),s=await Z(e,r.expression);return String(s)}catch{return"0"}}function Ud(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 Ri(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,a=!1,o=!1,l=!1,c=!1,u=!1,f=!1,d=!1,p=!1,h=!1,m=!1,E=!1,b=!1,g=[];for(let I=0;I<t.length;I++){let O=t[I];if(O==="-a")r=!0;else if(O==="-A")s=!0;else if(O==="-r")i=!0;else if(O==="-x")a=!0;else if(O==="-p")o=!0;else if(O==="-n")l=!0;else if(O==="+n")c=!0;else if(O==="+a")u=!0;else if(O==="+x")f=!0;else if(O==="--"){g.push(...t.slice(I+1));break}else if(O.startsWith("+")){for(let B of O.slice(1))if(B==="n")c=!0;else if(B==="a")u=!0;else if(B==="x")f=!0;else if(B!=="r"){if(B!=="i"){if(!(B==="f"||B==="F"))return _("",`bash: typeset: +${B}: invalid option
178
- `,2)}}}else if(O==="-i")d=!0;else if(O==="-l")p=!0;else if(O==="-u")h=!0;else if(O==="-f")m=!0;else if(O==="-F")E=!0;else if(O==="-g")b=!0;else if(O.startsWith("-"))for(let B of O.slice(1))if(B==="a")r=!0;else if(B==="A")s=!0;else if(B==="r")i=!0;else if(B==="x")a=!0;else if(B==="p")o=!0;else if(B==="n")l=!0;else if(B==="i")d=!0;else if(B==="l")p=!0;else if(B==="u")h=!0;else if(B==="f")m=!0;else if(B==="F")E=!0;else if(B==="g")b=!0;else return _("",`bash: typeset: -${B}: invalid option
179
- `,2);else g.push(O)}let S=e.state.localScopes.length>0&&!b,v=I=>{if(!S)return;let O=e.state.localScopes[e.state.localScopes.length-1];O.has(I)||O.set(I,e.state.env.get(I))},A=I=>{if(!S)return;let O=e.state.localScopes[e.state.localScopes.length-1];for(O.has(I)||O.set(I,e.state.env.get(I)),e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let B=e.state.localArrayScopes.at(-1);if(B&&!B.has(I)){let Y=Se(e,I);B.set(I,Y?De(Y):void 0)}},x=I=>{S&&Mt(e,I)};if(E){if(g.length===0){let B=Array.from(e.state.functions.keys()).sort(),Y="";for(let J of B)Y+=`declare -f ${J}
180
- `;return X(Y)}let I=!0,O="";for(let B of g)e.state.functions.has(B)?O+=`${B}
181
- `:I=!1;return _(O,"",I?0:1)}if(m){if(g.length===0){let O="",B=Array.from(e.state.functions.keys()).sort();for(let Y of B)O+=`${Y} ()
201
+ `,s=!0)}}return L(n,r,s?1:0)}function wc(e,t){let{filterExport:n,filterReadonly:r,filterNameref:s,filterIndexedArray:i,filterAssocArray:o}=t,a=n||r||s||i||o,l="",u=new Set;for(let f of e.state.env.keys())f.startsWith("BASH_")||u.add(f);for(let f of e.state.arrays?.keys()??[])u.add(f);if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())u.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)u.add(f);let c=Array.from(u).sort();for(let f of c){let d=yc(e,f),p=e.state.associativeArrays?.has(f),h=be(e,f),m=!p&&ke(e,f);if(a&&(o&&!p||i&&!m||n&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||s&&!le(e,f)))continue;if(p){let b=mt(e,f);if(b.length===0)l+=`declare -A ${f}=()
202
+ `;else{let g=b.map(y=>{let S=oe(e,f,y)??"",v=uo(S);return`[${co(y)}]=${v}`});l+=`declare -A ${f}=(${g.join(" ")})
203
+ `}continue}if(h.length>0){let b=h.map(g=>{let y=oe(e,f,g)??"";return`[${g}]=${Kt(y)}`});l+=`declare -a ${f}=(${b.join(" ")})
204
+ `;continue}if(ke(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 Ec(e){let t="",n=Array.from(e.state.associativeArrays??[]).sort();for(let r of n){let s=mt(e,r);if(s.length===0)t+=`declare -A ${r}=()
207
+ `;else{let i=s.map(o=>{let a=oe(e,r,o)??"",l=uo(a);return`[${co(o)}]=${l}`});t+=`declare -A ${r}=(${i.join(" ")})
208
+ `}}return Y(t)}function bc(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 o=i.map(a=>{let l=oe(e,s,a)??"";return`[${a}]=${Kt(l)}`});t+=`declare -a ${s}=(${o.join(" ")})
210
+ `}}return Y(t)}function Sc(e){let t="",n=new Set;for(let s of e.state.env.keys())s.startsWith("BASH_")||n.add(s);let r=Array.from(n).sort();for(let s of r){if(e.state.associativeArrays?.has(s)||be(e,s).length>0||ke(e,s))continue;let a=e.state.env.get(s);a!==void 0&&(t+=`${s}=${Ee(a)}
211
+ `)}return Y(t)}function fo(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function ur(e,t){return e.state.integerVars?.has(t)??!1}function po(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function bh(e,t){return e.state.lowercaseVars?.has(t)??!1}function ho(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Sh(e,t){return e.state.uppercaseVars?.has(t)??!1}function Fn(e,t,n){return bh(e,t)?n.toLowerCase():Sh(e,t)?n.toUpperCase():n}async function Ac(e,t){try{let n=new G,r=te(n,t),s=await K(e,r.expression);return String(s)}catch{return"0"}}function Ah(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let n=t[0],r=n.length;if(e[r]!=="[")return null;let s=0,i=r+1;for(;r<e.length;r++)if(e[r]==="[")s++;else if(e[r]==="]"&&(s--,s===0))break;if(s!==0)return null;let o=e.slice(i,r);if(r++,e[r]!=="=")return null;r++;let a=e.slice(r);return{name:n,indexExpr:o,value:a}}async function mo(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,u=!1,c=!1,f=!1,d=!1,p=!1,h=!1,m=!1,E=!1,b=!1,g=[];for(let $=0;$<t.length;$++){let P=t[$];if(P==="-a")r=!0;else if(P==="-A")s=!0;else if(P==="-r")i=!0;else if(P==="-x")o=!0;else if(P==="-p")a=!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($+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")o=!0;else if(R==="p")a=!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=$=>{if(!S)return;let P=e.state.localScopes[e.state.localScopes.length-1];P.has($)||P.set($,e.state.env.get($))},x=$=>{if(!S)return;let P=e.state.localScopes[e.state.localScopes.length-1];for(P.has($)||P.set($,e.state.env.get($)),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($)){let B=ve(e,$);R.set($,B?_e(B):void 0)}},A=$=>{S&&jt(e,$)};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 $=!0,P="";for(let R of g)e.state.functions.has(R)?P+=`${R}
215
+ `:$=!1;return L(P,"",$?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} ()
182
216
  {
183
217
  # function body
184
218
  }
185
- `;return X(O)}let I=!0;for(let O of g)e.state.functions.has(O)||(I=!1);return _("","",I?0:1)}if(o&&g.length>0)return mc(e,g);if(o&&g.length===0)return yc(e,{filterExport:a,filterReadonly:i,filterNameref:l,filterIndexedArray:r,filterAssocArray:s});if(g.length===0&&s&&!o)return gc(e);if(g.length===0&&r&&!o)return wc(e);if(g.length===0&&!o)return Ec(e);let P="",D=0;for(let I of g){let O=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(O&&!u){let C=O[1],k=O[2],N=oe(e,C);if(N)return N;if(s&&Ee(e,C).length>0){P+=`bash: declare: ${C}: cannot convert indexed to associative array
186
- `,D=1;continue}if((r||!s&&!r)&&e.state.associativeArrays?.has(C)){P+=`bash: declare: ${C}: cannot convert associative to indexed array
187
- `,D=1;continue}let M=s&&k.includes("[")?Ur(k,n):void 0,G=M===void 0?Et(k,{...n,maxElements:s?n.maxElements*2:n.maxElements}):void 0;if(e.executionScope.consumeWork(M?.length??G?.length??0,"declare array assignment"),A(C),s?(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(C),kt(e,C,"associative")):kt(e,C,"indexed"),me(e,C),e.state.env.delete(C),s&&k.includes("["))for(let[q,xe]of M??[])F(e,C,q,_t(e,xe),"associative");else if(s){let q=G??[];for(let xe=0;xe<q.length;xe+=2){let we=q[xe],Jt=xe+1<q.length?q[xe+1]:"";F(e,C,we,Jt,"associative")}}else{let q=G??[];if(q.some(we=>/^\[[^\]]+\]=/.test(we))){let we=0;for(let Jt of q){let ls=Jt.match(/^\[([^\]]+)\]=(.*)$/);if(ls){let cs=ls[1],Pu=ls[2],$n;if(/^-?\d+$/.test(cs))$n=Number.parseInt(cs,10);else try{let Cu=new V,Du=ne(Cu,cs);$n=await Z(e,Du.expression)}catch{$n=0}F(e,C,$n,_t(e,Pu)),we=$n+1}else F(e,C,we,Jt),we++}}else for(let we=0;we<q.length;we++)F(e,C,we,q[we])}x(C),i&&Fe(e,C),a&&st(e,C);continue}if(c){let C=I.includes("=")?I.slice(0,I.indexOf("=")):I;if(_o(e,C),!I.includes("="))continue}if(f){let C=I.includes("=")?I.slice(0,I.indexOf("=")):I;if(vr(e,C),!I.includes("="))continue}let B=Ud(I);if(B){let{name:C,indexExpr:k,value:N}=B,M=oe(e,C);if(M)return M;A(C);let G;try{let q=new V,xe=ne(q,k);G=await Z(e,xe.expression)}catch{let q=parseInt(k,10);G=Number.isNaN(q)?0:q}F(e,C,G,N),x(C),i&&Fe(e,C),a&&st(e,C);continue}let Y=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(Y&&!u){let C=Y[1],k=Y[2],N=oe(e,C);if(N)return N;A(C);let M=Et(k,n);if(e.state.associativeArrays?.has(C)){let G=Ur(k,n);e.executionScope.consumeWork(G.length,"declare array append"),jt(e,C,G.map(([q])=>q));for(let[q,xe]of G)F(e,C,q,xe,"associative")}else{e.executionScope.consumeWork(M.length,"declare array append");let G=Ee(e,C),q=0,xe=e.state.env.get(C);G.length===0&&xe!==void 0?(F(e,C,0,xe),e.state.env.delete(C),q=1):G.length>0&&(q=Math.max(...G)+1),jt(e,C,Array.from({length:M.length},(we,Jt)=>q+Jt));for(let we=0;we<M.length;we++)F(e,C,q+we,M[we])}x(C),i&&Fe(e,C),a&&st(e,C);continue}let J=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(J){let C=J[1],k=J[2],N=oe(e,C);if(N)return N;v(C),d&&Pi(e,C),p&&Ci(e,C),h&&Di(e,C);let G=Ee(e,C).length>0||e.state.associativeArrays?.has(C);if(Gn(e,C)){let q=e.state.env.get(C)??"0",xe=parseInt(q,10)||0,we=parseInt(await bc(e,k),10)||0;k=String(xe+we),e.state.env.set(C,k)}else if(G){k=Sn(e,C,k);let q=se(e,C,0)??"";F(e,C,0,At([q,k],"",e.limits.maxStringLength,"declare append"))}else{k=Sn(e,C,k);let q=e.state.env.get(C)??"";e.state.env.set(C,At([q,k],"",e.limits.maxStringLength,"declare append"))}x(C),i&&Fe(e,C),a&&st(e,C),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(C));continue}if(I.includes("=")){let C=I.indexOf("="),k=I.slice(0,C),N=I.slice(C+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(k)){P+=`bash: typeset: \`${k}': not a valid identifier
188
- `,D=1;continue}let M=oe(e,k);if(M)return M;if(v(k),l){if(N!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(N)){P+=`bash: declare: \`${N}': invalid variable name for name reference
189
- `,D=1;continue}e.state.env.set(k,N),wt(e,k),N!==""&&Er(e,N)&&Ks(e,k),x(k),i&&Fe(e,k),a&&st(e,k);continue}if(d&&Pi(e,k),p&&Ci(e,k),h&&Di(e,k),Gn(e,k)&&(N=await bc(e,N)),N=Sn(e,k,N),ae(e,k)){let G=Re(e,k);G&&G!==k?e.state.env.set(G,N):e.state.env.set(k,N)}else e.state.env.set(k,N);x(k),i&&Fe(e,k),a&&st(e,k),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(k))}else{let C=I;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(C)){P+=`bash: typeset: \`${C}': not a valid identifier
190
- `,D=1;continue}if(r||s?A(C):v(C),l){wt(e,C);let N=e.state.env.get(C);N!==void 0&&N!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(N)?Oo(e,C):N&&Er(e,N)&&Ks(e,C),x(C),i&&Fe(e,C),a&&st(e,C);continue}if(d&&Pi(e,C),p&&Ci(e,C),h&&Di(e,C),s){if(Ee(e,C).length>0){P+=`bash: declare: ${C}: cannot convert indexed to associative array
191
- `,D=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(C),kt(e,C,"associative")}let k=$e(e,C);!e.state.env.has(C)&&!k&&(r||s?kt(e,C,s?"associative":"indexed"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(C))),x(C),i&&Fe(e,C),a&&st(e,C)}}return _("",P,D)}async function Ii(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,a=[];for(let o=0;o<t.length;o++){let l=t[o];if(l==="-a")r=!0;else if(l==="-A")s=!0;else if(l==="-p")i=!0;else if(l==="--"){a.push(...t.slice(o+1));break}else l.startsWith("-")||a.push(l)}if(a.length===0){let o="",l=Array.from(e.state.readonlyVars||[]).sort();for(let c of l){let u=e.state.env.get(c);if(u!==void 0){let f=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');o+=`declare -r ${c}="${f}"
192
- `}}return X(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=oe(e,d);if(h)return h;let m=Et(p,n);if(e.state.associativeArrays?.has(d)){let E=Ur(p,n);e.executionScope.consumeWork(E.length,"readonly array append"),jt(e,d,E.map(([b])=>b));for(let[b,g]of E)F(e,d,b,g,"associative")}else{e.executionScope.consumeWork(m.length,"readonly array append");let E=Ee(e,d),b=0,g=e.state.env.get(d);E.length===0&&g!==void 0?(F(e,d,0,g),e.state.env.delete(d),b=1):E.length>0&&(b=Math.max(...E)+1),jt(e,d,Array.from({length:m.length},(w,S)=>b+S));for(let w=0;w<m.length;w++)F(e,d,b+w,m[w])}Fe(e,d);continue}let c=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c){let d=c[1],p=c[2],h=oe(e,d);if(h)return h;let m=e.state.env.get(d)??"";e.state.env.set(d,At([m,p],"",e.limits.maxStringLength,"readonly append")),Fe(e,d);continue}let u=rc(o,n);if(u.value===void 0&&!u.isArray){Fe(e,u.name);continue}let f=await sc(e,u,{makeReadonly:!0});if(f)return f}return te}function _i(e){return e.state.directoryStack??=[],e.state.directoryStack}function Zn(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function jd(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 Oi(e,t){let n=_i(e),r;for(let o=0;o<t.length;o++){let l=t[o];if(l==="--"){if(o+1<t.length){if(r!==void 0)return R(`bash: pushd: too many arguments
193
- `,2);r=t[o+1],o++}}else{if(l.startsWith("-")&&l!=="-")return R(`bash: pushd: ${l}: invalid option
194
- `,2);if(r!==void 0)return R(`bash: pushd: too many arguments
195
- `,2);r=l}}if(r===void 0){if(n.length<2)return R(`bash: pushd: no other directory
196
- `,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=jd(s);try{if(!(await e.fs.stat(s)).isDirectory)return R(`bash: pushd: ${r}: Not a directory
197
- `,1)}catch{return R(`bash: pushd: ${r}: No such file or directory
198
- `,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=>Zn(o,i)).join(" ")}
199
- `;return X(a)}function Li(e,t){let n=_i(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?R(`bash: popd: ${a}: invalid option
200
- `,2):R(`bash: popd: too many arguments
201
- `,2);if(n.length===0)return R(`bash: popd: directory stack empty
202
- `,1);let r=n.shift();if(!r)return R(`bash: popd: directory stack empty
203
- `,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=>Zn(a,s)).join(" ")}
204
- `;return X(i)}function Ti(e,t){let n=_i(e),r=!1,s=!1,i=!1,a=!1;for(let u of t)if(u!=="--")if(u.startsWith("-"))for(let f of u.slice(1))if(f==="c")r=!0;else if(f==="l")s=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,a=!0;else return R(`bash: dirs: -${f}: invalid option
205
- `,2);else return R(`bash: dirs: too many arguments
206
- `,1);if(r)return e.state.directoryStack=[],te;let o=[e.state.cwd,...n],l=e.state.env.get("HOME")||"",c;return a?(c=o.map((u,f)=>{let d=s?u:Zn(u,l);return` ${f} ${d}`}).join(`
207
- `),c+=`
208
- `):i?c=o.map(u=>s?u:Zn(u,l)).join(`
219
+ `;return Y(P)}let $=!0;for(let P of g)e.state.functions.has(P)||($=!1);return L("","",$?0:1)}if(a&&g.length>0)return gc(e,g);if(a&&g.length===0)return wc(e,{filterExport:o,filterReadonly:i,filterNameref:l,filterIndexedArray:r,filterAssocArray:s});if(g.length===0&&s&&!a)return Ec(e);if(g.length===0&&r&&!a)return bc(e);if(g.length===0&&!a)return Sc(e);let C="",N=0;for(let $ of g){let P=$.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?kt(W,{...n,maxElements:s?n.maxElements*2:n.maxElements}):void 0;if(e.executionScope.consumeWork(O?.length??_?.length??0,"declare array assignment"),x(D),s?(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(D),_t(e,D,"associative")):_t(e,D,"indexed"),ye(e,D),e.state.env.delete(D),s&&W.includes("["))for(let[M,se]of O??[])j(e,D,M,Vt(e,se),"associative");else if(s){let M=_??[];for(let se=0;se<M.length;se+=2){let ie=M[se],dn=se+1<M.length?M[se+1]:"";j(e,D,ie,dn,"associative")}}else{let M=_??[];if(M.some(ie=>/^\[[^\]]+\]=/.test(ie))){let ie=0;for(let dn of M){let Ns=dn.match(/^\[([^\]]+)\]=(.*)$/);if(Ns){let Rs=Ns[1],$f=Ns[2],zn;if(/^-?\d+$/.test(Rs))zn=Number.parseInt(Rs,10);else try{let kf=new G,Pf=te(kf,Rs);zn=await K(e,Pf.expression)}catch{zn=0}j(e,D,zn,Vt(e,$f)),ie=zn+1}else j(e,D,ie,dn),ie++}}else for(let ie=0;ie<M.length;ie++)j(e,D,ie,M[ie])}A(D),i&&Ue(e,D),o&&ft(e,D);continue}if(u){let D=$.includes("=")?$.slice(0,$.indexOf("=")):$;if(El(e,D),!$.includes("="))continue}if(f){let D=$.includes("=")?$.slice(0,$.indexOf("=")):$;if(Vr(e,D),!$.includes("="))continue}let R=Ah($);if(R){let{name:D,indexExpr:W,value:V}=R,O=ue(e,D);if(O)return O;x(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),o&&ft(e,D);continue}let B=$.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;x(D);let O=kt(W,n);if(e.state.associativeArrays?.has(D)){let _=ls(W,n);e.executionScope.consumeWork(_.length,"declare array append"),nn(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),nn(e,D,Array.from({length:O.length},(ie,dn)=>M+dn));for(let ie=0;ie<O.length;ie++)j(e,D,M+ie,O[ie])}A(D),i&&Ue(e,D),o&&ft(e,D);continue}let q=$.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&&fo(e,D),p&&po(e,D),h&&ho(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 Ac(e,W),10)||0;W=String(se+ie),e.state.env.set(D,W)}else if(_){W=Fn(e,D,W);let M=oe(e,D,0)??"";j(e,D,0,Rt([M,W],"",e.limits.maxStringLength,"declare append"))}else{W=Fn(e,D,W);let M=e.state.env.get(D)??"";e.state.env.set(D,Rt([M,W],"",e.limits.maxStringLength,"declare append"))}A(D),i&&Ue(e,D),o&&ft(e,D),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(D));continue}if($.includes("=")){let D=$.indexOf("="),W=$.slice(0,D),V=$.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),$t(e,W),V!==""&&Mr(e,V)&&wi(e,W),A(W),i&&Ue(e,W),o&&ft(e,W);continue}if(d&&fo(e,W),p&&po(e,W),h&&ho(e,W),ur(e,W)&&(V=await Ac(e,V)),V=Fn(e,W,V),le(e,W)){let _=Le(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),o&&ft(e,W),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(W))}else{let D=$;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?x(D):v(D),l){$t(e,D);let V=e.state.env.get(D);V!==void 0&&V!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(V)?bl(e,D):V&&Mr(e,V)&&wi(e,D),A(D),i&&Ue(e,D),o&&ft(e,D);continue}if(d&&fo(e,D),p&&po(e,D),h&&ho(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),_t(e,D,"associative")}let W=ke(e,D);!e.state.env.has(D)&&!W&&(r||s?_t(e,D,s?"associative":"indexed"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(D))),A(D),i&&Ue(e,D),o&&ft(e,D)}}return L("",C,N)}async function yo(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-a")r=!0;else if(l==="-A")s=!0;else if(l==="-p")i=!0;else if(l==="--"){o.push(...t.slice(a+1));break}else l.startsWith("-")||o.push(l)}if(o.length===0){let a="",l=Array.from(e.state.readonlyVars||[]).sort();for(let u of l){let c=e.state.env.get(u);if(c!==void 0){let f=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${u}="${f}"
226
+ `}}return Y(a)}for(let a of o){let l=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(l){let d=l[1],p=l[2],h=ue(e,d);if(h)return h;let m=kt(p,n);if(e.state.associativeArrays?.has(d)){let E=ls(p,n);e.executionScope.consumeWork(E.length,"readonly array append"),nn(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),nn(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=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(u){let d=u[1],p=u[2],h=ue(e,d);if(h)return h;let m=e.state.env.get(d)??"";e.state.env.set(d,Rt([m,p],"",e.limits.maxStringLength,"readonly append")),Ue(e,d);continue}let c=Xu(a,n);if(c.value===void 0&&!c.isArray){Ue(e,c.name);continue}let f=await Yu(e,c,{makeReadonly:!0});if(f)return f}return ee}function go(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 vh(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 wo(e,t){let n=go(e),r;for(let a=0;a<t.length;a++){let l=t[a];if(l==="--"){if(a+1<t.length){if(r!==void 0)return I(`bash: pushd: too many arguments
227
+ `,2);r=t[a+1],a++}}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 a=n[0];n[0]=n[1],n[1]=a,r=n[0]}let s;if(r.startsWith("/"))s=r;else if(r===".."){let a=e.state.cwd.split("/").filter(l=>l);a.pop(),s=`/${a.join("/")}`}else r==="."?s=e.state.cwd:r.startsWith("~")?s=(e.state.env.get("HOME")||"/")+r.slice(1):s=`${e.state.cwd}/${r}`;s=vh(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")||"",o=`${[s,...n].map(a=>cr(a,i)).join(" ")}
233
+ `;return Y(o)}function Eo(e,t){let n=go(e);for(let o of t)if(o!=="--")return o.startsWith("-")&&o!=="-"?I(`bash: popd: ${o}: 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(o=>cr(o,s)).join(" ")}
238
+ `;return Y(i)}function bo(e,t){let n=go(e),r=!1,s=!1,i=!1,o=!1;for(let c of t)if(c!=="--")if(c.startsWith("-"))for(let f of c.slice(1))if(f==="c")r=!0;else if(f==="l")s=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,o=!0;else return 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 a=[e.state.cwd,...n],l=e.state.env.get("HOME")||"",u;return o?(u=a.map((c,f)=>{let d=s?c:cr(c,l);return` ${f} ${d}`}).join(`
241
+ `),u+=`
242
+ `):i?u=a.map(c=>s?c:cr(c,l)).join(`
209
243
  `)+`
210
- `:c=o.map(u=>s?u:Zn(u,l)).join(" ")+`
211
- `,X(c)}async function Xr(e,t,n){let r=t;if(r.length>0){let o=r[0];if(o==="--")r=r.slice(1);else if(o.startsWith("-")&&o!=="-"&&o.length>1)return R(`bash: eval: ${o}: invalid option
244
+ `:u=a.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
212
246
  eval: usage: eval [arg ...]
213
- `,2)}if(r.length===0)return te;let s=r.join(" ");if(s.trim()==="")return te;let i=e.state.groupStdin,a=n??e.state.groupStdin;a!==void 0&&(e.state.groupStdin=a);try{let o=tt(s);return await e.executeScript(o)}catch(o){if(o instanceof qe||o instanceof Ue||o instanceof Oe||o instanceof j)throw o;if(o.name==="ParseException")return R(`bash: eval: ${o.message}
214
- `);throw o}finally{e.state.groupStdin=i}}function Mi(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
215
- `,n=2;else{let i=BigInt(s);n=Number((i%256n+256n)%256n)}}throw new j(n,"",r)}function Bi(e,t){let n=!1,r=[];for(let a of t)a==="-n"?n=!0:a==="-p"||a==="--"||r.push(a);if(r.length===0&&!n){let a="",o=e.state.exportedVars??new Set,l=Array.from(o).sort();for(let c of l){let u=e.state.env.get(c);u!==void 0&&(a+=`declare -x ${c}=${jn(u)}
216
- `)}return X(a)}if(n){for(let a of r){let o,l;if(a.includes("=")){let c=a.indexOf("=");o=a.slice(0,c),l=a.slice(c+1)}else o=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o))return _("",`bash: export: \`${a}': not a valid identifier
217
- `,1);l!==void 0&&(oe(e,o),e.state.env.set(o,l)),vr(e,o)}return te}let s="",i=0;for(let a of r){let o,l,c=!1,u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(u)o=u[1],l=u[2],c=!0;else if(a.includes("=")){let f=a.indexOf("=");o=a.slice(0,f),l=a.slice(f+1)}else o=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){s+=`bash: export: \`${a}': not a valid identifier
218
- `,i=1;continue}if(l!==void 0)if(oe(e,o),c){let f=e.state.env.get(o)??"";e.state.env.set(o,f+l)}else e.state.env.set(o,l);else e.state.env.has(o)||e.state.env.set(o,"");st(e,o)}return _("",s,i)}function Yr(e,t){if(t.length<2)return R(`bash: getopts: usage: getopts optstring name [arg ...]
219
- `);let n=t[0],r=t[1],s=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r),i=n.startsWith(":"),a=i?n.slice(1):n,o;if(t.length>2)o=t.slice(2);else{let m=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let E=1;E<=m;E++)o.push(e.state.env.get(String(E))||"")}let l=Number.parseInt(e.state.env.get("OPTIND")||"1",10);l<1&&(l=1);let c=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),l>o.length)return s||e.state.env.set(r,"?"),e.state.env.set("OPTIND",String(o.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:1,stdout:"",stderr:""};let u=o[l-1];if(!u||u==="-"||!u.startsWith("-"))return s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};if(u==="--")return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};let f=c===0?1:c,d=u[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),Yr(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}
220
- `,s||e.state.env.set(r,"?"),f+1<u.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0")),{exitCode:s?2:0,stdout:"",stderr:m}}if(p+1<a.length&&a[p+1]===":")if(f+1<u.length)e.state.env.set("OPTARG",u.slice(f+1)),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0");else{if(l>=o.length){let m="";return i?(e.state.env.set("OPTARG",d),s||e.state.env.set(r,":")):(m=`bash: option requires an argument -- ${d}
221
- `,s||e.state.env.set(r,"?")),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:0,stdout:"",stderr:m}}e.state.env.set("OPTARG",o[l]),e.state.env.set("OPTIND",String(l+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1<u.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return s||e.state.env.set(r,d),{exitCode:s?2:0,stdout:"",stderr:""}}async function Wi(e,t){e.state.hashTable||(e.state.hashTable=new Map);let n=!1,r=!1,s=!1,i=!1,a=!1,o="",l=[],c=0;for(;c<t.length;){let h=t[c];if(h==="--"){c++,l.push(...t.slice(c));break}if(h==="-r")n=!0,c++;else if(h==="-d")r=!0,c++;else if(h==="-l")s=!0,c++;else if(h==="-t")a=!0,c++;else if(h==="-p"){if(i=!0,c++,c>=t.length)return R(`bash: hash: -p: option requires an argument
222
- `,1);o=t[c],c++}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"?R(`bash: hash: -p: option requires an argument
223
- `,1):R(`bash: hash: -${m}: invalid option
224
- `,1);c++}else l.push(h),c++}if(n)return e.state.hashTable.clear(),te;if(r){if(l.length===0)return R(`bash: hash: -d: option requires an argument
247
+ `,2)}if(s.length===0)return ee;let i=s.join(" ");if(i.trim()==="")return ee;let o=e.state.groupStdin,a=r||n!==void 0&&n!=="";a&&(e.state.groupStdin=n??"");try{let l=at(i);return await e.executeScript(l)}catch(l){if(l instanceof je||l instanceof Ge||l instanceof De||l instanceof U)throw l;if(l.name==="ParseException")return I(`bash: eval: ${l.message}
248
+ `);throw l}finally{(a||o!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=o)}}function So(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 Ao(e,t){let n=!1,r=[];for(let o of t)o==="-n"?n=!0:o==="-p"||o==="--"||r.push(o);if(r.length===0&&!n){let o="",a=e.state.exportedVars??new Set,l=Array.from(a).sort();for(let u of l){let c=e.state.env.get(u);c!==void 0&&(o+=`declare -x ${u}=${lr(c)}
250
+ `)}return Y(o)}if(n){for(let o of r){let a,l;if(o.includes("=")){let u=o.indexOf("=");a=o.slice(0,u),l=o.slice(u+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return L("",`bash: export: \`${o}': not a valid identifier
251
+ `,1);l!==void 0&&(ue(e,a),e.state.env.set(a,l)),Vr(e,a)}return ee}let s="",i=0;for(let o of r){let a,l,u=!1,c=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c)a=c[1],l=c[2],u=!0;else if(o.includes("=")){let f=o.indexOf("=");a=o.slice(0,f),l=o.slice(f+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){s+=`bash: export: \`${o}': not a valid identifier
252
+ `,i=1;continue}if(l!==void 0)if(ue(e,a),u){let f=e.state.env.get(a)??"";e.state.env.set(a,f+l)}else e.state.env.set(a,l);else e.state.env.has(a)||e.state.env.set(a,"");ft(e,a)}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(":"),o=i?n.slice(1):n,a;if(t.length>2)a=t.slice(2);else{let m=Number.parseInt(e.state.env.get("#")||"0",10);a=[];for(let E=1;E<=m;E++)a.push(e.state.env.get(String(E))||"")}let l=Number.parseInt(e.state.env.get("OPTIND")||"1",10);l<1&&(l=1);let u=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),l>a.length)return s||e.state.env.set(r,"?"),e.state.env.set("OPTIND",String(a.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:1,stdout:"",stderr:""};let c=a[l-1];if(!c||c==="-"||!c.startsWith("-"))return s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};if(c==="--")return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};let f=u===0?1:u,d=c[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),bs(e,t);let p=o.indexOf(d);if(p===-1){let m="";return i?e.state.env.set("OPTARG",d):m=`bash: illegal option -- ${d}
254
+ `,s||e.state.env.set(r,"?"),f+1<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0")),{exitCode:s?2:0,stdout:"",stderr:m}}if(p+1<o.length&&o[p+1]===":")if(f+1<c.length)e.state.env.set("OPTARG",c.slice(f+1)),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0");else{if(l>=a.length){let m="";return i?(e.state.env.set("OPTARG",d),s||e.state.env.set(r,":")):(m=`bash: option requires an argument -- ${d}
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",a[l]),e.state.env.set("OPTIND",String(l+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return s||e.state.env.set(r,d),{exitCode:s?2:0,stdout:"",stderr:""}}async function vo(e,t){e.state.hashTable||(e.state.hashTable=new Map);let n=!1,r=!1,s=!1,i=!1,o=!1,a="",l=[],u=0;for(;u<t.length;){let h=t[u];if(h==="--"){u++,l.push(...t.slice(u));break}if(h==="-r")n=!0,u++;else if(h==="-d")r=!0,u++;else if(h==="-l")s=!0,u++;else if(h==="-t")o=!0,u++;else if(h==="-p"){if(i=!0,u++,u>=t.length)return I(`bash: hash: -p: option requires an argument
256
+ `,1);a=t[u],u++}else if(h.startsWith("-")&&h.length>1){for(let m of h.slice(1))if(m==="r")n=!0;else if(m==="d")r=!0;else if(m==="l")s=!0;else if(m==="t")o=!0;else return m==="p"?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
225
259
  `,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
226
- `,h=!0);return h?R(m,1):te}if(a){if(l.length===0)return R(`bash: hash: -t: option requires an argument
260
+ `,h=!0);return h?I(m,1):ee}if(o){if(l.length===0)return I(`bash: hash: -t: option requires an argument
227
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}
228
262
  `:h+=`${g}
229
263
  `:(E+=`bash: hash: ${b}: not found
230
- `,m=!0)}return m?{exitCode:1,stdout:h,stderr:E}:X(h)}if(i){if(l.length===0)return R(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
231
- `,1);let h=l[0];return e.state.hashTable.set(h,o),te}if(l.length===0){if(e.state.hashTable.size===0)return X(`hash: hash table empty
232
- `);let h="";if(s)for(let[m,E]of e.state.hashTable){let b=m.startsWith("-")?" --":"";h+=`builtin hash -p ${ge(E)}${b} ${ge(m)}
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,a),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)}
233
267
  `}else{h=`hits command
234
268
  `;for(let[,m]of e.state.hashTable)h+=` 1 ${m}
235
- `}return X(h)}let u=!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
236
- `,u=!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
237
- `,u=!0)}return u?R(f,1):te}var Sc=new Map([[":",[": [arguments]",`Null command.
269
+ `}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 vc=new Map([[":",[": [arguments]",`Null command.
238
272
  No effect; the command does nothing.
239
273
  Exit Status:
240
274
  Always succeeds.`]],[".",[". filename [arguments]",`Execute commands from a file in the current shell.
@@ -579,35 +613,37 @@ eval: usage: eval [arg ...]
579
613
  job specification, and reports its termination status.
580
614
  Exit Status:
581
615
  Returns the status of the last ID; fails if ID is invalid or an invalid
582
- option is given.`]]]),Ac=[...Sc.keys()].sort();function Fi(e,t){let n=!1,r=[],s=0;for(;s<t.length;){let l=t[s];if(l==="--"){for(s++;s<t.length;)r.push(t[s]),s++;break}if(l.startsWith("-")&&l.length>1){for(let c=1;c<l.length;c++){let u=l[c];if(u==="s")n=!0;else return R(`bash: help: -${u}: invalid option
583
- `,2)}s++}else r.push(l),s++}if(r.length===0)return Zd();let i="",a=!1,o="";for(let l of r){let c=Gd(l);if(c.length===0){o+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
584
- `,a=!0;continue}for(let u of c){let f=Sc.get(u);if(!f)continue;let[d,p]=f;n?i+=`${u}: ${d}
585
- `:i+=`${u}: ${d}
616
+ option is given.`]]]),xc=[...vc.keys()].sort();function xo(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 $h();let i="",o=!1,a="";for(let l of r){let u=xh(l);if(u.length===0){a+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
618
+ `,o=!0;continue}for(let c of u){let f=vc.get(c);if(!f)continue;let[d,p]=f;n?i+=`${c}: ${d}
619
+ `:i+=`${c}: ${d}
586
620
  ${p}
587
- `}}return{exitCode:a?1:0,stdout:i,stderr:o}}function Gd(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),n=he(`^${t}$`);return Ac.filter(r=>n.test(r))}function Zd(){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=Ac.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 X(`${e.join(`
621
+ `}}return{exitCode:o?1:0,stdout:i,stderr:a}}function xh(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),n=me(`^${t}$`);return xc.filter(r=>n.test(r))}function $h(){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=xc.slice(),r=Math.ceil(n.length/2);for(let s=0;s<r;s++){let i=n[s]||"",o=n[s+r]||"",a=i.padEnd(t);e.push(o?`${a}${o}`:i)}return Y(`${e.join(`
588
622
  `)}
589
- `)}function Hd(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 Vi(e,t){if(t.length===0)return R(`bash: let: expression expected
590
- `);let n=Hd(t),r=0;for(let s of n)try{let a=tt(`(( ${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 Z(e,o.expression.expression))}}catch(i){return R(`bash: let: ${s}: ${i.message}
591
- `)}return _("","",r===0?1:0)}async function zi(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength};if(e.state.localScopes.length===0)return R(`bash: local: can only be used in a function
592
- `);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=Se(e,d);s.set(d,p?De(p):void 0)}},a="",o=0,l=!1,c=!1,u=!1,f=[];for(let d of t)if(d==="-n")l=!0;else if(d==="-a")c=!0;else if(d==="-p")u=!0;else if(d.startsWith("-")&&!d.includes("="))for(let p of d.slice(1))p==="n"?l=!0:p==="a"?c=!0:p==="p"&&(u=!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}
593
- `)}return _(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
594
- `,o=1;continue}oe(e,p,"bash");let v=Et(S,n);e.executionScope.consumeWork(v.length,"local array assignment"),i(p),me(e,p),kt(e,p,"indexed");for(let A=0;A<v.length;A++)F(e,p,A,v[A]);Mt(e,p),l&&wt(e,p);continue}let E=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(E){p=E[1];let S=E[2];oe(e,p,"bash"),i(p);let v=Et(S,n);e.executionScope.consumeWork(v.length,"local array append");let A=Ee(e,p),x=0,P=e.state.env.get(p);A.length===0&&P!==void 0?(F(e,p,0,P),e.state.env.delete(p),x=1):A.length>0&&(x=Math.max(...A)+1),jt(e,p,Array.from({length:v.length},(D,I)=>x+I));for(let D=0;D<v.length;D++)F(e,p,x+D,v[D]);Mt(e,p),l&&wt(e,p);continue}let b=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(b){p=b[1];let S=b[2];oe(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,At([v,S],"",e.limits.maxStringLength,"local append")),Mt(e,p),l&&wt(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];oe(e,p,"bash"),i(p);let A;try{let x=new V,P=ne(x,S);A=await Z(e,P.expression)}catch{let x=parseInt(S,10);A=Number.isNaN(x)?0:x}F(e,p,A,v),Mt(e,p),l&&wt(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
595
- `,o=1;continue}let w=r.has(p);if(h!==void 0){let S=e.state.env.get(p);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(p),A=e.state.mutatedTempEnvVars?.has(p);if(!v&&!A)for(let x=e.state.tempEnvBindings.length-1;x>=0;x--){let P=e.state.tempEnvBindings[x];if(P.has(p)){S=P.get(p);break}}}ic(e,p,S)}if(!w){let S=e.state.env.get(p);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let A=e.state.tempEnvBindings[v];if(A.has(p)){S=A.get(p);break}}r.set(p,S),c&&i(p)}if(c&&h===void 0)me(e,p),kt(e,p,"indexed");else if(h!==void 0){if(oe(e,p,"bash"),l&&h!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(h)){a+=`bash: local: \`${h}': invalid variable name for name reference
596
- `,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));!w&&!S&&e.state.env.delete(p)}Mt(e,p),l&&wt(e,p)}return _("",a,o)}function qi(e,t,n){let r=`
597
- `,s=0,i=0,a=0,o=!1,l="MAPFILE",c=0;for(;c<t.length;){let g=t[c];g==="-d"&&c+1<t.length?(r=t[c+1]===""?"\0":t[c+1]||`
598
- `,c+=2):g==="-n"&&c+1<t.length?(s=Number.parseInt(t[c+1],10)||0,c+=2):g==="-O"&&c+1<t.length?(i=Number.parseInt(t[c+1],10)||0,c+=2):g==="-s"&&c+1<t.length?(a=Number.parseInt(t[c+1],10)||0,c+=2):g==="-t"?(o=!0,c++):g==="-u"||g==="-C"||g==="-c"?c+=2:(g.startsWith("-")||(l=g),c++)}if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l))return _("",`mapfile: ${l}: not a valid identifier
599
- `,1);if(!Number.isSafeInteger(i)||i<0)return _("",`mapfile: invalid array origin
600
- `,1);oe(e,l,"mapfile");let u=n;!u&&e.state.groupStdin!==void 0&&(u=e.state.groupStdin);let f=[],d=0,p=0,h=0,m=e.limits.maxArrayElements,E=g=>{if(T(g)>e.limits.maxStringLength)throw new $(`mapfile: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");f.push(g)};for(;d<u.length;){e.executionScope.consumeWork(1,"mapfile input");let g=u.indexOf(r,d);if(g===-1){if(d<u.length){if(h<a)h++;else if(s===0||p<s){let v=u.slice(d),A=v.indexOf("\0");if(A!==-1&&(v=v.substring(0,A)),f.length>=m)return _("",`mapfile: array element limit exceeded (${m})
601
- `,1);E(v),p++}}break}let w=u.slice(d,g),S=w.indexOf("\0");if(S!==-1&&(w=w.substring(0,S)),!o&&r!=="\0"&&(w+=r),d=g+r.length,h<a){h++;continue}if(s>0&&p>=s)break;if(f.length>=m)return _("",`mapfile: array element limit exceeded (${m})
602
- `,1);E(w),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 _("",`mapfile: array element limit exceeded (${m})
603
- `,1);i===0&&me(e,l);for(let g=0;g<f.length;g++)F(e,l,i+g,f[g]);return e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=""),_("","",0)}function Qd(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),n=t.indexOf(":");if(n===-1)return null;let r=Number.parseInt(t.slice(0,n),10);if(Number.isNaN(r)||r<0)return null;let s=n+1,i=t.slice(s,s+r),a=s+r+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let c=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let u=o.slice(l+1);return{path:i,position:c,content:u}}function Kd(e,t,n){return`__rw__:${e.length}:${e}:${t}:${n}`}function Ui(e,t,n,r=-1){let s=!1,i=`
604
- `,a="",o=-1,l=-1,c=null,u=-1,f=-1,d=[],p=0,h=!1,m=(k,N)=>{let M=1;for(;M<k.length;){let G=k[M];if(G==="r")s=!0,M++;else if(G==="s")M++;else{if(G==="d")return M+1<k.length?(i=k.substring(M+1),{nextArgIndex:N+1}):N+1<t.length?(i=t[N+1],{nextArgIndex:N+2}):{nextArgIndex:N+1};if(G==="n"){if(M+1<k.length){let q=k.substring(M+1);return o=Number.parseInt(q,10),(Number.isNaN(o)||o<0)&&(h=!0,o=0),{nextArgIndex:N+1}}else if(N+1<t.length)return o=Number.parseInt(t[N+1],10),(Number.isNaN(o)||o<0)&&(h=!0,o=0),{nextArgIndex:N+2};return{nextArgIndex:N+1}}else if(G==="N"){if(M+1<k.length){let q=k.substring(M+1);return l=Number.parseInt(q,10),(Number.isNaN(l)||l<0)&&(h=!0,l=0),{nextArgIndex:N+1}}else if(N+1<t.length)return l=Number.parseInt(t[N+1],10),(Number.isNaN(l)||l<0)&&(h=!0,l=0),{nextArgIndex:N+2};return{nextArgIndex:N+1}}else{if(G==="a")return M+1<k.length?(c=k.substring(M+1),{nextArgIndex:N+1}):N+1<t.length?(c=t[N+1],{nextArgIndex:N+2}):{nextArgIndex:N+1};if(G==="p")return M+1<k.length?(a=k.substring(M+1),{nextArgIndex:N+1}):N+1<t.length?(a=t[N+1],{nextArgIndex:N+2}):{nextArgIndex:N+1};if(G==="u"){if(M+1<k.length){let q=k.substring(M+1);return u=Number.parseInt(q,10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:N+1}}else if(N+1<t.length)return u=Number.parseInt(t[N+1],10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:N+2};return{nextArgIndex:N+1}}else if(G==="t"){if(M+1<k.length){let q=k.substring(M+1);return f=Number.parseFloat(q),Number.isNaN(f)&&(f=0),{nextArgIndex:N+1}}else if(N+1<t.length)return f=Number.parseFloat(t[N+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:N+2};return{nextArgIndex:N+1}}else if(G==="e"||G==="i"||G==="P"){if(G==="i"&&N+1<t.length)return{nextArgIndex:N+2};M++}else M++}}}return{nextArgIndex:N+1}};for(;p<t.length;){let k=t[p];if(k.startsWith("-")&&k.length>1&&k!=="--"){let N=m(k,p);if(N.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(N.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};p=N.nextArgIndex}else if(k==="--")for(p++;p<t.length;)d.push(t[p]),p++;else d.push(k),p++}if(h)return _("","",1);d.length===0&&c===null&&d.push("REPLY");let E=new Set;c&&E.add(c);for(let k of d)E.add(k);l>=0&&d.length===0&&E.add("REPLY");for(let k of E){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(k))return _("",`bash: read: \`${k}': not a valid identifier
605
- `,1);oe(e,k,"bash")}if(f===0){if(c)me(e,c);else{for(let k of d)e.state.env.set(k,"");d.length===0&&e.state.env.set("REPLY","")}return _("","",0)}if(f<0&&f!==-1)return _("","",1);let b=n;u>=0?e.state.fileDescriptors?b=e.state.fileDescriptors.get(u)||"":b="":!b&&e.state.groupStdin!==void 0&&(b=e.state.groupStdin);let g=i===""?"\0":i,w="",S=0,v=k=>{let N=T(k);if(N>e.limits.maxStringLength-S)throw new $(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");w+=k,S+=N},A=k=>{if(T(k)>e.limits.maxStringLength)throw new $(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")},x=0,P=!0,D=k=>{if(u>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(u,b.substring(k));else if(r>=0&&e.state.fileDescriptors){let N=e.state.fileDescriptors.get(r);if(N?.startsWith("__rw__:")){let M=Qd(N);if(M){let G=M.position+k;e.state.fileDescriptors.set(r,Kd(M.path,G,M.content))}}}else e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=b.substring(k))};if(l>=0){let k=Math.min(l,b.length);w=b.substring(0,k),A(w),x=k,P=k>=l,D(x);let N=d[0]||"REPLY";e.state.env.set(N,w);for(let M=1;M<d.length;M++)e.state.env.set(d[M],"");return _("","",P?0:1)}else if(o>=0){let k=0,N=0,M=!1;for(;N<b.length&&k<o;){let G=b[N];if(G===g){x=N+1,M=!0;break}if(!s&&G==="\\"&&N+1<b.length){let q=b[N+1];if(q===g&&g===`
606
- `){N+=2,x=N;continue}if(q===g){N+=2,k++,v(q),x=N;continue}v(q),N+=2,k++,x=N}else v(G),N++,k++,x=N}P=k>=o||M,D(x)}else{x=0;let k=0;for(;k<b.length;){let N=b[k];if(N===g){x=k+g.length,P=!0;break}if(!s&&N==="\\"&&k+1<b.length){let M=b[k+1];if(M===`
607
- `){k+=2;continue}if(M===g){v(M),k+=2;continue}v(N),v(M),k+=2;continue}v(N),k++}if(k>=b.length&&(P=!1,x=k,w.length===0&&b.length===0)){for(let N of d)e.state.env.set(N,"");return c&&me(e,c),_("","",1)}D(x)}g===`
608
- `&&w.endsWith(`
609
- `)&&(w=w.slice(0,-1));let I=k=>s?k:k.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",I(w)),_("","",P?0:1);let O=be(e.state.env),B=e.limits.maxArrayElements;if(c){let{words:k}=Qs(w,O,B,void 0,s);me(e,c);for(let N=0;N<k.length;N++)F(e,c,N,I(k[N]));return _("","",P?0:1)}let Y=d.length,{words:J,wordStarts:C}=Qs(w,O,B,Y,s);for(let k=0;k<d.length;k++){let N=d[k];if(k<d.length-1)e.state.env.set(N,I(J[k]??""));else if(k<C.length){let M=w.substring(C[k]);M=Io(M,O,s),M=I(M),e.state.env.set(N,M)}else e.state.env.set(N,"")}return _("","",P?0:1)}function ji(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return R("bash: return: can only `return' from a function or sourced script\n");let n=e.state.lastExitCode;if(t.length>0){let r=t[0],s=Number.parseInt(r,10);if(r===""||Number.isNaN(s)||!/^-?\d+$/.test(r))return R(`bash: return: ${r}: numeric argument required
610
- `,2);n=(s%256+256)%256}throw new Oe(n)}var Hn=`set: usage: set [-eux] [+eux] [-o option] [+o option]
623
+ `)}function kh(e){let t=[],n="",r=0;for(let s of e){for(let i of s)i==="("?r++:i===")"&&r--;n?n+=` ${s}`:n=s,r===0&&(t.push(n),n="")}return n&&t.push(n),t}async function $o(e,t){if(t.length===0)return I(`bash: let: expression expected
624
+ `);let n=kh(t),r=0;for(let s of n)try{let o=at(`(( ${s} ))`).statements[0];if(o&&o.pipelines.length>0&&o.pipelines[0].commands.length>0){let a=o.pipelines[0].commands[0];a.type==="ArithmeticCommand"&&(r=await K(e,a.expression.expression))}}catch(i){return I(`bash: let: ${s}: ${i.message}
625
+ `)}return L("","",r===0?1:0)}async function ko(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?_e(p):void 0)}},o="",a=0,l=!1,u=!1,c=!1,f=[];for(let d of t)if(d==="-n")l=!0;else if(d==="-a")u=!0;else if(d==="-p")c=!0;else if(d.startsWith("-")&&!d.includes("="))for(let p of d.slice(1))p==="n"?l=!0:p==="a"?u=!0:p==="p"&&(c=!0);else f.push(d);if(f.length===0){let d="",p=Array.from(r.keys()).sort();for(let h of p){let m=e.state.env.get(h);m!==void 0&&(d+=`${h}=${m}
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)){o+=`bash: local: \`${d}': not a valid identifier
628
+ `,a=1;continue}ue(e,p,"bash");let v=kt(S,n);e.executionScope.consumeWork(v.length,"local array assignment"),i(p),ye(e,p),_t(e,p,"indexed");for(let x=0;x<v.length;x++)j(e,p,x,v[x]);jt(e,p),l&&$t(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=kt(S,n);e.executionScope.consumeWork(v.length,"local array append");let x=be(e,p),A=0,C=e.state.env.get(p);x.length===0&&C!==void 0?(j(e,p,0,C),e.state.env.delete(p),A=1):x.length>0&&(A=Math.max(...x)+1),nn(e,p,Array.from({length:v.length},(N,$)=>A+$));for(let N=0;N<v.length;N++)j(e,p,A+N,v[N]);jt(e,p),l&&$t(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,Rt([v,S],"",e.limits.maxStringLength,"local append")),jt(e,p),l&&$t(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 x;try{let A=new G,C=te(A,S);x=await K(e,C.expression)}catch{let A=parseInt(S,10);x=Number.isNaN(A)?0:A}j(e,p,x,v),jt(e,p),l&&$t(e,p);continue}if(d.includes("=")){let S=d.indexOf("=");p=d.slice(0,S),h=d.slice(S+1)}else p=d;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(p)){o+=`bash: local: \`${d}': not a valid identifier
629
+ `,a=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),x=e.state.mutatedTempEnvVars?.has(p);if(!v&&!x)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}}}Ju(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 x=e.state.tempEnvBindings[v];if(x.has(p)){S=x.get(p);break}}r.set(p,S),u&&i(p)}if(u&&h===void 0)ye(e,p),_t(e,p,"indexed");else if(h!==void 0){if(ue(e,p,"bash"),l&&h!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(h)){o+=`bash: local: \`${h}': invalid variable name for name reference
630
+ `,a=1;continue}e.state.env.set(p,h),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(p))}else{let S=e.state.tempEnvBindings?.some(v=>v.has(p));!y&&!S&&e.state.env.delete(p)}jt(e,p),l&&$t(e,p)}return L("",o,a)}function Po(e,t,n){let r=`
631
+ `,s=0,i=0,o=0,a=!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?(o=Number.parseInt(t[u+1],10)||0,u+=2):g==="-t"?(a=!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
633
+ `,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<o)h++;else if(s===0||p<s){let v=c.slice(d),x=v.indexOf("\0");if(x!==-1&&(v=v.substring(0,x)),f.length>=m)return L("",`mapfile: array element limit exceeded (${m})
635
+ `,1);E(v),p++}}break}let y=c.slice(d,g),S=y.indexOf("\0");if(S!==-1&&(y=y.substring(0,S)),!a&&r!=="\0"&&(y+=r),d=g+r.length,h<o){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 Co(e,t,n,r=-1){let s=!1,i=`
638
+ `,o="",a=-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 a=Number.parseInt(ie,10),(Number.isNaN(a)||a<0)&&(h=!0,a=0),{nextArgIndex:_+1}}else if(_+1<t.length)return a=Number.parseInt(t[_+1],10),(Number.isNaN(a)||a<0)&&(h=!0,a=0),{nextArgIndex:_+2};return{nextArgIndex:_+1}}else if(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?(o=O.substring(M+1),{nextArgIndex:_+1}):_+1<t.length?(o=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
640
+ `:`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="",x=0,A=O=>{let _=F(O);if(_>e.limits.maxStringLength-x)throw new k(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");v+=O,x+=_},C=O=>{if(F(O)>e.limits.maxStringLength)throw new k(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")},N=0,$=!0,P=O=>{y?Zt(e,c,O):r>=0?Zt(e,r,O):e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=b.substring(O),e.state.groupStdinSourceFd!==void 0&&Zt(e,e.state.groupStdinSourceFd,O))};if(l>=0){let O=Math.min(l,b.length);v=b.substring(0,O),C(v),N=O,$=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("","",$?0:1)}else if(a>=0){let O=0,_=0,M=!1;for(;_<b.length&&O<a;){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=_}$=O>=a||M,P(N)}else{N=0;let O=0;for(;O<b.length;){let _=b[O];if(_===S){N=O+S.length,$=!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&&($=!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===`
644
+ `&&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("","",$?0:1);let B=Ae(e.state.env),q=e.limits.maxArrayElements;if(u){let{words:O}=gi(v,B,q,void 0,s);ye(e,u);for(let _=0;_<O.length;_++)j(e,u,_,R(O[_]));return L("","",$?0:1)}let D=d.length,{words:W,wordStarts:V}=gi(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=wl(M,B,s),M=R(M),e.state.env.set(_,M)}else e.state.env.set(_,"")}return L("","",$?0:1)}function No(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 De(n)}var fr=`set: usage: set [-eux] [+eux] [-o option] [+o option]
611
647
  Options:
612
648
  -e Exit immediately if a command exits with non-zero status
613
649
  +e Disable -e
@@ -623,184 +659,150 @@ Options:
623
659
  +o pipefail Disable pipefail
624
660
  -o xtrace Same as -x
625
661
  +o xtrace Disable xtrace
626
- `,vc=new Map([["e","errexit"],["u","nounset"],["x","xtrace"],["v","verbose"],["f","noglob"],["C","noclobber"],["a","allexport"],["n","noexec"],["h",null],["b",null],["m",null],["B",null],["H",null],["P",null],["T",null],["E",null],["p",null]]),Jr=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]]),kc=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],Nc=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Gi(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,dn(e))}function Xd(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Yd(e,t,n){let r=Ee(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],a=se(e,n,i)??"";s>0&&t.append(" "),t.append(`[${i}]=`),t.reserve(Kr(a)),t.append(Bt(a))}t.append(")")}function Jd(e,t){if(/^[a-zA-Z0-9_]+$/.test(t)){e.append(t);return}e.reserve(Kr(t)),e.append(Bt(t))}function ep(e,t,n){let r=ut(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=se(e,n,i)??"";s>0&&t.append(" "),t.append("["),Jd(t,i),t.append("]="),t.reserve(Kr(a)),t.append(Bt(a))}t.append(" )")}function tp(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 np(e){return e.state.associativeArrays??new Set}function xc(e){let t=kc.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),n=Nc.map(r=>`${r.padEnd(16)}off`);return`${[...t,...n].sort().join(`
662
+ `,$c=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]]),Cc=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],Nc=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Ro(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 Ph(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Ch(e,t,n){let r=be(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],o=oe(e,n,i)??"";s>0&&t.append(" "),t.append(`[${i}]=`),t.reserve(ws(o)),t.append(Kt(o))}t.append(")")}function Nh(e,t){if(/^[a-zA-Z0-9_]+$/.test(t)){e.append(t);return}e.reserve(ws(t)),e.append(Kt(t))}function Rh(e,t,n){let r=mt(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],o=oe(e,n,i)??"";s>0&&t.append(" "),t.append("["),Nh(t,i),t.append("]="),t.reserve(ws(o)),t.append(Kt(o))}t.append(" )")}function Dh(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 Ih(e){return e.state.associativeArrays??new Set}function kc(e){let t=Cc.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),n=Nc.map(r=>`${r.padEnd(16)}off`);return`${[...t,...n].sort().join(`
627
663
  `)}
628
- `}function $c(e){let t=kc.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),n=Nc.map(r=>`set +o ${r}`);return`${[...t,...n].sort().join(`
664
+ `}function Pc(e){let t=Cc.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),n=Nc.map(r=>`set +o ${r}`);return`${[...t,...n].sort().join(`
629
665
  `)}
630
- `}function Hi(e,t){if(t.includes("--help"))return X(Hn);if(t.length===0){let i=tp(e),a=np(e),o=[];for(let[u,f]of e.state.env)/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)&&(i.has(u)||a.has(u)||o.push([u,f]));let l=[...o.map(([u,f])=>({kind:"scalar",name:u,value:f})),...Array.from(i,u=>({kind:"indexed",name:u})),...Array.from(a,u=>({kind:"associative",name:u}))];l.sort((u,f)=>u.name<f.name?-1:u.name>f.name?1:0);let c=new tn(e.limits.maxOutputSize,"set");for(let u of l)e.executionScope.consumeWork(1,"set variable listing"),u.kind==="scalar"?(c.append(u.name).append("="),c.reserve(fc(u.value)),c.append(ge(u.value))):u.kind==="indexed"?Yd(e,c,u.name):ep(e,c,u.name),c.append(`
631
- `);return X(c.build())}let n=[],r=()=>n.length>0?X(n.join("")):te,s=0;for(;s<t.length;){let i=t[s];if((i==="-o"||i==="+o")&&Xd(t,s)){let a=t[s+1];if(!Jr.has(a)){let o=`bash: set: ${a}: invalid option name
632
- ${Hn}`;if(e.state.options.posix)throw new Ke(1,"",o);return R(o)}Gi(e,Jr.get(a)??null,i==="-o"),s+=2;continue}if(i==="-o"){n.push(xc(e)),s++;continue}if(i==="+o"){n.push($c(e)),s++;continue}if(i.length>1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let a=i[0]==="-",o=0;for(let l=1;l<i.length;l++){let c=i[l];if(c==="o"){let u=s+1+o;if(u<t.length&&!t[u].startsWith("-")&&!t[u].startsWith("+")){let d=t[u];if(!Jr.has(d)){let p=`bash: set: ${d}: invalid option name
633
- ${Hn}`;if(e.state.options.posix)throw new Ke(1,"",p);return R(p)}Gi(e,Jr.get(d)??null,a),o++;continue}n.push(a?xc(e):$c(e));continue}if(!vc.has(c)){let u=`bash: set: ${i[0]}${c}: invalid option
634
- ${Hn}`;if(e.state.options.posix)throw new Ke(1,"",u);return R(u)}Gi(e,vc.get(c)??null,a)}s+=1+o;continue}if(i==="--")return Zi(e,t.slice(s+1)),r();if(i==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,dn(e),s+1<t.length)return Zi(e,t.slice(s+1)),r();s++;continue}if(i==="+"){s++;continue}if(i.startsWith("-")||i.startsWith("+")){let a=`bash: set: ${i}: invalid option
635
- ${Hn}`;if(e.state.options.posix)throw new Ke(1,"",a);return R(a)}return Zi(e,t.slice(s)),r()}return r()}function Zi(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 Qi(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
636
- `;if(e.state.options.posix)throw new Ke(1,"",o);return R(o)}n=a}let r=Number.parseInt(e.state.env.get("#")||"0",10);if(n>r){let a=`bash: shift: shift count out of range
637
- `;if(e.state.options.posix)throw new Ke(1,"",a);return R(a)}if(n===0)return te;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(" ")),te}async function Ki(e,t){let n=t;if(n.length>0&&n[0]==="--"&&(n=n.slice(1)),n.length===0)return _("",`bash: source: filename argument required
638
- `,2);let r=n[0],s=null,i=null;if(r.includes("/")){let c=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(c),s=c}catch{}}else{let u=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of u){let d=e.fs.resolvePath(e.state.cwd,`${f}/${r}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),s=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(f),s=f}catch{}}}if(i===null)return R(`bash: ${r}: No such file or directory
639
- `);let a=new Map;if(n.length>1){for(let u=1;u<=9;u++)a.set(String(u),e.state.env.get(String(u)));a.set("#",e.state.env.get("#")),a.set("@",e.state.env.get("@"));let c=n.slice(1);e.state.env.set("#",String(c.length)),e.state.env.set("@",c.join(" "));for(let u=0;u<c.length&&u<9;u++)e.state.env.set(String(u+1),c[u]);for(let u=c.length+1;u<=9;u++)e.state.env.delete(String(u))}let o=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=o,n.length>1)for(let[c,u]of a)u===void 0?e.state.env.delete(c):e.state.env.set(c,u)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new $(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let c=tt(i),u=await e.executeScript(c);return l(),u}catch(c){if(l(),c instanceof j)throw c;if(c instanceof Oe)return _(c.stdout,c.stderr,c.exitCode);if(c.name==="ParseException")return R(`bash: ${r}: ${c.message}
640
- `);throw c}}function Pc(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function rp(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function Cc(e,t){if(rp(t))return null;try{let n=new V,r=ne(n,t);return await Z(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}function Dc(e,t){if(e.state.localVarStack?.has(t)){let r=Gr(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)jr(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),Xi(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),jr(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||jr(e,t),!0}}return!1}function Xi(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 Rc(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 V().parseWordFromString(n,!0,!1);return W(e,s)}if(t.includes("$")){let r=new V().parseWordFromString(t,!1,!1);return W(e,r)}return t}async function Yi(e,t){let n="both",r="",s=0;for(let i of t){if(i==="-v"){n="variable";continue}if(i==="-f"){n="function";continue}if(n==="function"){e.state.functions.delete(i);continue}if(n==="variable"){let c=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(c){let d=c[1],p=c[2];if(Ie(e,d)){r+=`bash: unset: ${d}: cannot unset: readonly variable
641
- `,s=1;continue}if(p==="@"||p==="*"){Rn(e,d),e.state.env.delete(d);continue}let h=e.state.associativeArrays?.has(d);if(h){let w=await Rc(e,p);Gt(e,d,w);continue}let m=nt(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
642
- `,s=1;continue}let g=await Cc(e,p);if(g===null&&m){r+=`bash: unset: ${p}: not a valid identifier
643
- `,s=1;continue}if(g===null)continue;if(g<0){let w=z(e,d),S=w.length,v=e.state.currentLine;if(S===0){r+=`bash: line ${v}: unset: [${g}]: bad array subscript
644
- `,s=1;continue}let A=S+g;if(A<0){r+=`bash: line ${v}: unset: [${g}]: bad array subscript
645
- `,s=1;continue}let x=w[A][0];Gt(e,d,x);continue}Gt(e,d,g);continue}if(!Pc(i)){r+=`bash: unset: \`${i}': not a valid identifier
646
- `,s=1;continue}let u=i;if(ae(e,i)){let d=Re(e,i);d&&d!==i&&(u=d)}if(Ie(e,u)){r+=`bash: unset: ${u}: cannot unset: readonly variable
647
- `,s=1;continue}Rn(e,u);let f=pi(e,u);if(f!==void 0&&f!==e.state.callDepth)Dc(e,u);else if(e.state.fullyUnsetLocals?.has(u))e.state.env.delete(u);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(u),p=e.state.mutatedTempEnvVars?.has(u);if((d||p)&&e.state.localVarStack?.has(u)){let h=Gr(e,u);h?h.value===void 0?e.state.env.delete(u):e.state.env.set(u,h.value):e.state.env.delete(u)}else e.state.env.delete(u)}else Xi(e,u)||e.state.env.delete(u);e.state.exportedVars?.delete(u);continue}let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let c=a[1],u=a[2];if(Ie(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable
648
- `,s=1;continue}if(u==="@"||u==="*"){Rn(e,c),e.state.env.delete(c);continue}let f=e.state.associativeArrays?.has(c);if(f){let m=await Rc(e,u);Gt(e,c,m);continue}let d=nt(e,c);if(e.state.env.has(c)&&!d&&!f){r+=`bash: unset: ${c}: not an array variable
649
- `,s=1;continue}let h=await Cc(e,u);if(h===null&&d){r+=`bash: unset: ${u}: not a valid identifier
650
- `,s=1;continue}if(h===null)continue;if(h<0){let m=z(e,c),E=m.length,b=e.state.currentLine;if(E===0){r+=`bash: line ${b}: unset: [${h}]: bad array subscript
666
+ `}function Io(e,t){if(t.includes("--help"))return Y(fr);if(t.length===0){let i=Dh(e),o=Ih(e),a=[];for(let[c,f]of e.state.env)/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)&&(i.has(c)||o.has(c)||a.push([c,f]));let l=[...a.map(([c,f])=>({kind:"scalar",name:c,value:f})),...Array.from(i,c=>({kind:"indexed",name:c})),...Array.from(o,c=>({kind:"associative",name:c}))];l.sort((c,f)=>c.name<f.name?-1:c.name>f.name?1:0);let u=new yn(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(pc(c.value)),u.append(Ee(c.value))):c.kind==="indexed"?Ch(e,u,c.name):Rh(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")&&Ph(t,s)){let o=t[s+1];if(!Ss.has(o)){let a=`bash: set: ${o}: invalid option name
668
+ ${fr}`;if(e.state.options.posix)throw new et(1,"",a);return I(a)}Ro(e,Ss.get(o)??null,i==="-o"),s+=2;continue}if(i==="-o"){n.push(kc(e)),s++;continue}if(i==="+o"){n.push(Pc(e)),s++;continue}if(i.length>1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let o=i[0]==="-",a=0;for(let l=1;l<i.length;l++){let u=i[l];if(u==="o"){let c=s+1+a;if(c<t.length&&!t[c].startsWith("-")&&!t[c].startsWith("+")){let d=t[c];if(!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)}Ro(e,Ss.get(d)??null,o),a++;continue}n.push(o?kc(e):Pc(e));continue}if(!$c.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)}Ro(e,$c.get(u)??null,o)}s+=1+a;continue}if(i==="--")return Do(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 Do(e,t.slice(s+1)),r();s++;continue}if(i==="+"){s++;continue}if(i.startsWith("-")||i.startsWith("+")){let o=`bash: set: ${i}: invalid option
671
+ ${fr}`;if(e.state.options.posix)throw new et(1,"",o);return I(o)}return Do(e,t.slice(s)),r()}return r()}function Do(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 Oo(e,t){let n=1;if(t.length>0){let o=Number.parseInt(t[0],10);if(Number.isNaN(o)||o<0){let a=`bash: shift: ${t[0]}: numeric argument required
672
+ `;if(e.state.options.posix)throw new et(1,"",a);return I(a)}n=o}let r=Number.parseInt(e.state.env.get("#")||"0",10);if(n>r){let o=`bash: shift: shift count out of range
673
+ `;if(e.state.options.posix)throw new et(1,"",o);return I(o)}if(n===0)return ee;let s=[];for(let o=1;o<=r;o++)s.push(e.state.env.get(String(o))||"");let i=s.slice(n);for(let o=1;o<=r;o++)e.state.env.delete(String(o));for(let o=0;o<i.length;o++)e.state.env.set(String(o+1),i[o]);return e.state.env.set("#",String(i.length)),e.state.env.set("@",i.join(" ")),ee}async function _o(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 o=new Map;if(n.length>1){for(let c=1;c<=9;c++)o.set(String(c),e.state.env.get(String(c)));o.set("#",e.state.env.get("#")),o.set("@",e.state.env.get("@"));let u=n.slice(1);e.state.env.set("#",String(u.length)),e.state.env.set("@",u.join(" "));for(let c=0;c<u.length&&c<9;c++)e.state.env.set(String(c+1),u[c]);for(let c=u.length+1;c<=9;c++)e.state.env.delete(String(c))}let a=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=a,n.length>1)for(let[u,c]of o)c===void 0?e.state.env.delete(u):e.state.env.set(u,c)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new k(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let u=at(i),c=await e.executeScript(u);return l(),c}catch(u){if(l(),u instanceof U)throw u;if(u instanceof De)return L(u.stdout,u.stderr,u.exitCode);if(u.name==="ParseException")return I(`bash: ${r}: ${u.message}
676
+ `);throw u}}function Rc(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Oh(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function Dc(e,t){if(Oh(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 Ic(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),Lo(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 o=!1;for(let a=r-1;a>=0;a--)if(e.state.localScopes[a].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,a+1),o=!0;break}return o||us(e,t),!0}}return!1}function Lo(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 Oc(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 To(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(Te(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 Oc(e,p);rn(e,d,y);continue}let m=ut(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 Dc(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 x=S+g;if(x<0){r+=`bash: line ${v}: unset: [${g}]: bad array subscript
681
+ `,s=1;continue}let A=y[x][0];rn(e,d,A);continue}rn(e,d,g);continue}if(!Rc(i)){r+=`bash: unset: \`${i}': not a valid identifier
682
+ `,s=1;continue}let c=i;if(le(e,i)){let d=Le(e,i);d&&d!==i&&(c=d)}if(Te(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable
683
+ `,s=1;continue}Zn(e,c);let f=Fi(e,c);if(f!==void 0&&f!==e.state.callDepth)Ic(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 Lo(e,c)||e.state.env.delete(c);e.state.exportedVars?.delete(c);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let u=o[1],c=o[2];if(Te(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 Oc(e,c);rn(e,u,m);continue}let d=ut(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 Dc(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
651
687
  `,s=1;continue}let g=E+h;if(g<0){r+=`bash: line ${b}: unset: [${h}]: bad array subscript
652
- `,s=1;continue}let w=m[g][0];Gt(e,c,w);continue}Gt(e,c,h);continue}if(!Pc(i)){r+=`bash: unset: \`${i}': not a valid identifier
653
- `,s=1;continue}let o=i;if(ae(e,i)){let c=Re(e,i);c&&c!==i&&(o=c)}if(Ie(e,o)){r+=`bash: unset: ${o}: cannot unset: readonly variable
654
- `,s=1;continue}Rn(e,o);let l=pi(e,o);if(l!==void 0&&l!==e.state.callDepth)Dc(e,o);else if(e.state.fullyUnsetLocals?.has(o))e.state.env.delete(o);else if(l!==void 0){let c=e.state.accessedTempEnvVars?.has(o),u=e.state.mutatedTempEnvVars?.has(o);if((c||u)&&e.state.localVarStack?.has(o)){let f=Gr(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 Xi(e,o)||e.state.env.delete(o);e.state.exportedVars?.delete(o),e.state.functions.delete(i)}return _("",r,s)}function mt(e,t,n,r){let s=n+T(t)+1;if(s>r)throw new $(`shopt: output size limit exceeded (${r} bytes)`,"output_size");return e.push(t),s}var Ji=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],sp=["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 es(e){return Ji.includes(e)}function ip(e){return sp.includes(e)}function Ic(e,t){let n=e.limits.maxArrayElements;if(t.length>n)throw new $(`shopt: argument limit exceeded (${n})`,"array_elements");let r=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),s=!1,i=!1,a=!1,o=!1,l=!1,c=[],u=0;for(;u<t.length;){let E=t[u];if(E==="--"){u++;break}if(E.startsWith("-")&&E.length>1){for(let b=1;b<E.length;b++){let g=E[b];switch(g){case"s":s=!0;break;case"u":i=!0;break;case"p":a=!0;break;case"q":o=!0;break;case"o":l=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${g}: invalid option
655
- `}}}u++}else break}for(;u<t.length;)c.push(t[u]),u++;if(l)return ap(e,c,s,i,a,o);if(s&&i)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
656
- `};if(c.length===0){if(s||i){let b=[];for(let g of Ji){let w=e.state.shoptOptions[g];s&&w?b.push(a?`shopt -s ${g}`:`${g} on`):i&&!w&&b.push(a?`shopt -u ${g}`:`${g} off`)}return{exitCode:0,stdout:b.length>0?`${b.join(`
688
+ `,s=1;continue}let y=m[g][0];rn(e,u,y);continue}rn(e,u,h);continue}if(!Rc(i)){r+=`bash: unset: \`${i}': not a valid identifier
689
+ `,s=1;continue}let a=i;if(le(e,i)){let u=Le(e,i);u&&u!==i&&(a=u)}if(Te(e,a)){r+=`bash: unset: ${a}: cannot unset: readonly variable
690
+ `,s=1;continue}Zn(e,a);let l=Fi(e,a);if(l!==void 0&&l!==e.state.callDepth)Ic(e,a);else if(e.state.fullyUnsetLocals?.has(a))e.state.env.delete(a);else if(l!==void 0){let u=e.state.accessedTempEnvVars?.has(a),c=e.state.mutatedTempEnvVars?.has(a);if((u||c)&&e.state.localVarStack?.has(a)){let f=cs(e,a);f?f.value===void 0?e.state.env.delete(a):e.state.env.set(a,f.value):e.state.env.delete(a)}else e.state.env.delete(a)}else Lo(e,a)||e.state.env.delete(a);e.state.exportedVars?.delete(a),e.state.functions.delete(i)}return L("",r,s)}function St(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 Mo=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],_h=["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 Mo.includes(e)}function Lh(e){return _h.includes(e)}function _c(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,o=!1,a=!1,l=!1,u=[],c=0;for(;c<t.length;){let E=t[c];if(E==="--"){c++;break}if(E.startsWith("-")&&E.length>1){for(let b=1;b<E.length;b++){let g=E[b];switch(g){case"s":s=!0;break;case"u":i=!0;break;case"p":o=!0;break;case"q":a=!0;break;case"o":l=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${g}: invalid option
691
+ `}}}c++}else break}for(;c<t.length;)u.push(t[c]),c++;if(l)return Th(e,u,s,i,o,a);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 Mo){let y=e.state.shoptOptions[g];s&&y?b.push(o?`shopt -s ${g}`:`${g} on`):i&&!y&&b.push(o?`shopt -u ${g}`:`${g} off`)}return{exitCode:0,stdout:b.length>0?`${b.join(`
657
693
  `)}
658
- `:"",stderr:""}}let E=[];for(let b of Ji){let g=e.state.shoptOptions[b];E.push(a?`shopt ${g?"-s":"-u"} ${b}`:`${b} ${g?"on":"off"}`)}return{exitCode:0,stdout:`${E.join(`
694
+ `:"",stderr:""}}let E=[];for(let b of Mo){let g=e.state.shoptOptions[b];E.push(o?`shopt ${g?"-s":"-u"} ${b}`:`${b} ${g?"on":"off"}`)}return{exitCode:0,stdout:`${E.join(`
659
695
  `)}
660
- `,stderr:""}}let f=!1,d=[],p=0,h=[],m=0;for(let E of c){if(!es(E)&&!ip(E)){p=mt(d,`shopt: ${E}: invalid shell option name`,p,r),f=!0;continue}if(s)es(E)&&(e.state.shoptOptions[E]=!0,vs(e));else if(i)es(E)&&(e.state.shoptOptions[E]=!1,vs(e));else if(es(E)){let b=e.state.shoptOptions[E];o?b||(f=!0):a?(m=mt(h,`shopt ${b?"-s":"-u"} ${E}`,m,r),b||(f=!0)):(m=mt(h,`${E} ${b?"on":"off"}`,m,r),b||(f=!0))}else o?f=!0:a?(m=mt(h,`shopt -u ${E}`,m,r),f=!0):(m=mt(h,`${E} off`,m,r),f=!0)}return{exitCode:f?1:0,stdout:h.length>0?`${h.join(`
696
+ `,stderr:""}}let f=!1,d=[],p=0,h=[],m=0;for(let E of u){if(!As(E)&&!Lh(E)){p=St(d,`shopt: ${E}: invalid shell option name`,p,r),f=!0;continue}if(s)As(E)&&(e.state.shoptOptions[E]=!0,qs(e));else if(i)As(E)&&(e.state.shoptOptions[E]=!1,qs(e));else if(As(E)){let b=e.state.shoptOptions[E];a?b||(f=!0):o?(m=St(h,`shopt ${b?"-s":"-u"} ${E}`,m,r),b||(f=!0)):(m=St(h,`${E} ${b?"on":"off"}`,m,r),b||(f=!0))}else a?f=!0:o?(m=St(h,`shopt -u ${E}`,m,r),f=!0):(m=St(h,`${E} off`,m,r),f=!0)}return{exitCode:f?1:0,stdout:h.length>0?`${h.join(`
661
697
  `)}
662
698
  `:"",stderr:d.length>0?`${d.join(`
663
699
  `)}
664
- `:""}}function ap(e,t,n,r,s,i){let a=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),o=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),l=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],c=[...o.keys(),...l].sort();if(t.length===0){let m=[];for(let E of c){let b=l.includes(E),g=o.get(E),w=b||!g?!1:e.state.options[g];n&&!w||r&&w||m.push(s?`set ${w?"-o":"+o"} ${E}`:`${E} ${w?"on":"off"}`)}return{exitCode:0,stdout:m.length>0?`${m.join(`
700
+ `:""}}function Th(e,t,n,r,s,i){let o=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),a=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),l=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],u=[...a.keys(),...l].sort();if(t.length===0){let m=[];for(let E of u){let b=l.includes(E),g=a.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(`
665
701
  `)}
666
- `:"",stderr:""}}let u=!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=mt(f,`shopt: ${m}: invalid option name`,d,a),u=!0;continue}if(b){n||r||(i?u=!0:s?(h=mt(p,`set +o ${m}`,h,a),u=!0):(h=mt(p,`${m} off`,h,a),u=!0));continue}let g=o.get(m);if(g)if(n)g==="vi"?e.state.options.emacs=!1:g==="emacs"&&(e.state.options.vi=!1),e.state.options[g]=!0,dn(e);else if(r)e.state.options[g]=!1,dn(e);else{let w=e.state.options[g];i?w||(u=!0):s?(h=mt(p,`set ${w?"-o":"+o"} ${m}`,h,a),w||(u=!0)):(h=mt(p,`${m} ${w?"on":"off"}`,h,a),w||(u=!0))}}return{exitCode:u?1:0,stdout:p.length>0?`${p.join(`
702
+ `:"",stderr:""}}let c=!1,f=[],d=0,p=[],h=0;for(let m of t){let E=a.has(m),b=l.includes(m);if(!E&&!b){d=St(f,`shopt: ${m}: invalid option name`,d,o),c=!0;continue}if(b){n||r||(i?c=!0:s?(h=St(p,`set +o ${m}`,h,o),c=!0):(h=St(p,`${m} off`,h,o),c=!0));continue}let g=a.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,$n(e);else if(r)e.state.options[g]=!1,$n(e);else{let y=e.state.options[g];i?y||(c=!0):s?(h=St(p,`set ${y?"-o":"+o"} ${m}`,h,o),y||(c=!0)):(h=St(p,`${m} ${y?"on":"off"}`,h,o),y||(c=!0))}}return{exitCode:c?1:0,stdout:p.length>0?`${p.join(`
667
703
  `)}
668
704
  `:"",stderr:f.length>0?`${f.join(`
669
705
  `)}
670
- `:""}}function ts(e,t){return e===`/bin/${t}`||e===`/usr/bin/${t}`}async function _c(e,t,n){if(t.includes("/")){let a=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(a))return{error:"not_found",path:a};try{let o=await e.fs.stat(a);if(o.isDirectory)return{error:"permission_denied",path:a};let l=a.split("/").pop()||t,c=e.commands.get(l);return c&&ts(a,l)?{cmd:c,path:a}:(o.mode&73)!==0?{script:!0,path:a}:{error:"permission_denied",path:a}}catch{return{error:"not_found",path:a}}}if(!n&&e.state.hashTable){let a=e.state.hashTable.get(t);if(a){try{let o=await e.fs.stat(a);if(!o.isDirectory){let l=e.commands.get(t);if(l&&ts(a,t))return{cmd:l,path:a};if((o.mode&73)!==0)return{script:!0,path:a}}}catch{}e.state.hashTable.delete(t)}}let s=(n??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let a of s){if(!a)continue;let l=`${a.startsWith("/")?a:e.fs.resolvePath(e.state.cwd,a)}/${t}`;if(await e.fs.exists(l))try{let c=await e.fs.stat(l);if(c.isDirectory)continue;let u=(c.mode&73)!==0,f=e.commands.get(t),d=ts(l,t);if(f&&d)return{cmd:f,path:l};if(u){if(f&&!d)return{script:!0,path:l};if(!f)return{script:!0,path:l}}}catch{}}if(!await e.fs.exists("/usr/bin")){let a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function ns(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(ts(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 op(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function fe(e,t,n,r){return((...s)=>{Pn(t,n,`${r} call`);let i=e(...s);return op(i)?i.then(a=>(Pn(t,n,`${r} post-await`),a),a=>{throw Pn(t,n,`${r} post-await`),a}):(Pn(t,n,`${r} return`),i)})}function lp(e,t,n){let r={readFile:fe(e.readFile.bind(e),t,n,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:fe(e.readFileBytes.bind(e),t,n,"fs.readFileBytes")}:Object.create(null),readFileBuffer:fe(e.readFileBuffer.bind(e),t,n,"fs.readFileBuffer"),writeFile:fe(e.writeFile.bind(e),t,n,"fs.writeFile"),appendFile:fe(e.appendFile.bind(e),t,n,"fs.appendFile"),exists:fe(e.exists.bind(e),t,n,"fs.exists"),stat:fe(e.stat.bind(e),t,n,"fs.stat"),mkdir:fe(e.mkdir.bind(e),t,n,"fs.mkdir"),readdir:fe(e.readdir.bind(e),t,n,"fs.readdir"),rm:fe(e.rm.bind(e),t,n,"fs.rm"),cp:fe(e.cp.bind(e),t,n,"fs.cp"),mv:fe(e.mv.bind(e),t,n,"fs.mv"),resolvePath:fe(e.resolvePath.bind(e),t,n,"fs.resolvePath"),getAllPaths:fe(e.getAllPaths.bind(e),t,n,"fs.getAllPaths"),chmod:fe(e.chmod.bind(e),t,n,"fs.chmod"),symlink:fe(e.symlink.bind(e),t,n,"fs.symlink"),link:fe(e.link.bind(e),t,n,"fs.link"),readlink:fe(e.readlink.bind(e),t,n,"fs.readlink"),lstat:fe(e.lstat.bind(e),t,n,"fs.lstat"),realpath:fe(e.realpath.bind(e),t,n,"fs.realpath"),utimes:fe(e.utimes.bind(e),t,n,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=fe(e.readdirWithFileTypes.bind(e),t,n,"fs.readdirWithFileTypes")),r}function Oc(e,t){if(!e.requireDefenseContext)return e;let n=`command:${t}`,r={...e,fs:lp(e.fs,e.requireDefenseContext,n)};return e.exec&&(r.exec=fe(e.exec,e.requireDefenseContext,n,"exec")),e.fetch&&(r.fetch=fe(e.fetch,e.requireDefenseContext,n,"fetch")),e.sleep&&(r.sleep=fe(e.sleep,e.requireDefenseContext,n,"sleep")),e.getRegisteredCommands&&(r.getRegisteredCommands=fe(e.getRegisteredCommands,e.requireDefenseContext,n,"getRegisteredCommands")),r}var Lc="+ ";async function Tc(e){let t=e.state.env.get("PS4");if(t===void 0)return Lc;if(t==="")return"";let n=e.state.options.xtrace;e.state.options.xtrace=!1;try{let s=new V().parseWordFromString(t,!1,!1);return await W(e,s)}catch(r){if(r instanceof ie&&!r.fatal)return t;if(r instanceof ma||r instanceof Error&&r.name==="AbortError")throw r;return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
671
- `,t||Lc}finally{e.state.options.xtrace=n}}function cp(e){return e.map(t=>up(t)).join(" ")}function up(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let n=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
672
- `),s=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(n||r||s||i){let l="";for(let c of e){let u=c.charCodeAt(0);c===`
673
- `?l+="\\n":c===" "?l+="\\t":c==="\\"?l+="\\\\":c==="'"?l+="'":c==='"'?l+='"':u<32||u===127?u<256?l+=`\\x${u.toString(16).padStart(2,"0")}`:l+=`\\u${u.toString(16).padStart(4,"0")}`:l+=c}return`$'${l}'`}return a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function Mc(e,t,n){if(!e.state.options.xtrace)return"";let r=await Tc(e),s=[t,...n],i=cp(s);return`${r}${i}
674
- `}async function Bc(e,t,n){return e.state.options.xtrace?`${await Tc(e)}${t}=${n}
675
- `:""}function rs(e,t,n){return At([t,n],"",e.limits.maxStringLength,"array assignment")}async function Wc(e,t){let n=new Map,r="";for(let s of t.assignments){let i=s.name;if(s.array){let u=await fp(e,t,i,s.array,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};if(r+=u.xtraceOutput,u.continueToNext)continue}let a=s.value?await W(e,s.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:_("",`bash: ${i}: bad array subscript
676
- `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let u=await yp(e,t,l[1],l[2],a,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};if(u.continueToNext)continue}let c=await gp(e,t,i,a,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};r+=c.xtraceOutput,c.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:n}}async function fp(e,t,n,r,s,i){let a="";if(/\[.+\]$/.test(n))return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: ${n}: cannot assign list to array member
677
- `,1)};if(ae(e,n)){let h=Kt(e,n);if(h===void 0||h==="")throw new j(1,"","");let m=Re(e,n);if(m&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(m))return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: ${n}: cannot assign list to array member
678
- `,1)}}if(Ie(e,n)){if(t.name)return a+=`bash: ${n}: readonly variable
679
- `,{continueToNext:!0,xtraceOutput:a};let h=oe(e,n);if(h)return{continueToNext:!1,xtraceOutput:"",error:h}}let o=e.state.associativeArrays?.has(n),l=Se(e,n),c=l?De(l):void 0,u=e.state.env.get(n),f=()=>{e.state.arrays??=new Map,c?e.state.arrays.set(n,c):e.state.arrays.delete(n),u===void 0?e.state.env.delete(n):e.state.env.set(n,u)},d=dp(r),p=()=>{me(e,n),e.state.env.delete(n)};try{o&&d?await pp(e,t,n,r,s,p,h=>{a+=h}):d?await hp(e,n,r,s,p):await mp(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=>fn(E)).join(" ")})`;e.state.env.set(n,m)}return{continueToNext:!0,xtraceOutput:a}}function dp(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 pp(e,t,n,r,s,i,a){let o=[];for(let l of r){if(o.length>=e.limits.maxArrayElements)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let c=bs(l);if(c){let{key:u,valueParts:f,append:d}=c,p;f.length>0?(p=await W(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(p=_t(e,p))):p="",o.push({type:"keyed",key:u,value:p,append:d})}else{let u=await W(e,l);o.push({type:"invalid",expandedValue:u})}}e.executionScope.consumeWork(o.length,"associative array assignment"),s||i();for(let l of o)if(l.type==="keyed")if(l.append){let c=se(e,n,l.key)??"";F(e,n,l.key,rs(e,c,l.value),"associative")}else F(e,n,l.key,l.value,"associative");else{let c=t.line??e.state.currentLine??1;a(`bash: line ${c}: ${n}: ${l.expandedValue}: must use subscript when assigning associative array
680
- `)}}async function hp(e,t,n,r,s){let i=[],a=0;for(let l of n){let c=bs(l);if(c){if(a>=e.limits.maxArrayElements)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let{key:u,valueParts:f,append:d}=c,p;f.length>0?(p=await W(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(p=_t(e,p))):p="",i.push({type:"keyed",indexExpr:u,value:p,append:d}),a++}else{let u=await at(e,l);if(u.values.length>e.limits.maxArrayElements-a)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push({type:"non-keyed",values:u.values}),a+=u.values.length}}e.executionScope.consumeWork(a,"indexed array assignment"),r||s();let o=0;for(let l of i)if(l.type==="keyed"){let c;try{let u=new V,f=ne(u,l.indexExpr);c=await Z(e,f.expression,!1)}catch{if(/^-?\d+$/.test(l.indexExpr))c=Number.parseInt(l.indexExpr,10);else{let u=e.state.env.get(l.indexExpr);c=u?Number.parseInt(u,10):0,Number.isNaN(c)&&(c=0)}}if(l.append){let u=se(e,t,c)??"";F(e,t,c,rs(e,u,l.value))}else F(e,t,c,l.value);o=c+1}else for(let c of l.values)F(e,t,o++,c)}async function mp(e,t,n,r,s){let i=[];for(let o of n){let l=await at(e,o);for(let c of l.values){if(i.length>=e.limits.maxArrayElements)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push(c)}}let 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(([c])=>typeof c=="number"?c:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(F(e,t,0,l),e.state.env.delete(t),a=1)}}else s();for(let o=0;o<i.length;o++)F(e,t,a+o,i[o])}async function yp(e,t,n,r,s,i,a){let o=n;if(ae(e,n)){let f=Re(e,n);if(f&&f!==n){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: \`${f}': not a valid identifier
681
- `,1)};o=f}}if(Ie(e,o)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=oe(e,o);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l=e.state.associativeArrays?.has(o),c;if(l)c=await Fc(e,r);else{let f=await ea(e,o,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};c=String(f.index)}let u=i?rs(e,se(e,o,c)||"",s):s;return t.name||F(e,o,c,u,l?"associative":"indexed"),{continueToNext:!0,xtraceOutput:""}}async function Fc(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 V().parseWordFromString(r,!0,!1);n=await W(e,i)}else if(t.includes("$")){let s=new V().parseWordFromString(t,!1,!1);n=await W(e,s)}else n=t;return n}async function ea(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 V,a=ne(i,r);s=await Z(e,a.expression,!1)}catch(i){if(i instanceof j)throw i;if(i instanceof ie){let l=`bash: line ${e.state.currentLine}: ${n}: ${i.message}
682
- `;if(i.fatal)throw new j(1,"",l);return{index:0,error:_("",l,1)}}let a=e.state.currentLine;return{index:0,error:_("",`bash: line ${a}: ${t}[${n}]: bad array subscript
683
- `,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:_("",`bash: line ${o}: ${t}[${n}]: bad array subscript
684
- `,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:_("",`bash: line ${o}: ${t}[${n}]: bad array subscript
685
- `,1)}}}return{index:s}}async function gp(e,t,n,r,s,i){let a="",o=n,l=null;if(ae(e,n)){let f=br(e,n,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: ${n}: circular name reference
686
- `,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(Ie(e,o)){if(t.name)return a+=`bash: ${o}: readonly variable
687
- `,{continueToNext:!0,xtraceOutput:a};let f=oe(e,o);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let c;if(Gn(e,o))try{let f=new V;if(s){let p=`(${e.state.env.get(o)||"0"}) + (${r})`,h=ne(f,p);c=String(await Z(e,h.expression))}else{let d=ne(f,r);c=String(await Z(e,d.expression))}}catch{c="0"}else{let f=nt(e,o)?se(e,o,0):e.state.env.get(o);c=s?rs(e,f||"",r):r}c=Sn(e,o,c),a+=await Bc(e,o,c);let u;return l?u=await wp(e,l):nt(e,o)&&(u="0"),t.name?u===void 0&&(i.set(o,e.state.env.get(o)),e.state.env.set(o,c)):(u===void 0?e.state.env.set(o,c):F(e,o,u,c),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(o)),e.state.tempEnvBindings?.some(f=>f.has(o))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(o))),{continueToNext:!1,xtraceOutput:a}}async function wp(e,t){let{arrayName:n,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(n))return Fc(e,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let a=new V,o=ne(a,r);i=await Z(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 Uc(e,t,n,r){let s=!1,i=!1,a=!1,o=!1,l=!1,c=[];for(let m of t)if(m.startsWith("-")&&m.length>1)for(let E of m.slice(1))E==="t"?s=!0:E==="p"?i=!0:E==="P"?a=!0:E==="a"?o=!0:E==="f"&&(l=!0);else c.push(m);let u="",f="",d=0,p=!1,h=!1;for(let m of c){let E=!1;if(a){if(o){let A=await r(m);if(A.length>0){for(let x of A)u+=`${x}
688
- `;p=!0,E=!0}}else{let A=await n(m);A&&(u+=`${A}
689
- `,p=!0,E=!0)}E||(h=!0);continue}let b=!l&&e.state.functions.has(m);if(o&&b){if(!i)if(s)u+=`function
690
- `;else{let A=e.state.functions.get(m),x=A?Vc(m,A):`${m} is a function
691
- `;u+=x}E=!0}let g=e.state.env.get(`BASH_ALIAS_${m}`);if(g!==void 0&&(o||!E)&&(i||(s?u+=`alias
692
- `:u+=`${m} is aliased to \`${g}'
693
- `),E=!0,!o)||mi.has(m)&&(o||!E)&&(i||(s?u+=`keyword
694
- `:u+=`${m} is a shell keyword
695
- `),E=!0,!o))continue;if(!o&&b&&!E){if(!i)if(s)u+=`function
696
- `;else{let A=e.state.functions.get(m),x=A?Vc(m,A):`${m} is a function
697
- `;u+=x}E=!0;continue}if(!(wn.has(m)&&(o||!E)&&(i||(s?u+=`builtin
698
- `:u+=`${m} is a shell builtin
699
- `),E=!0,!o))){if(o){let A=await r(m);for(let x of A)i?u+=`${x}
700
- `:s?u+=`file
701
- `:u+=`${m} is ${x}
702
- `,p=!0,E=!0}else if(!E){let A=await n(m);A&&(i?u+=`${A}
703
- `:s?u+=`file
704
- `:u+=`${m} is ${A}
705
- `,p=!0,E=!0)}if(!E&&(h=!0,!s&&!i)){let A=!0;if(m.includes("/")){let x=e.fs.resolvePath(e.state.cwd,m);await e.fs.exists(x)&&(A=!1)}A&&(f+=`bash: type: ${m}: not found
706
- `)}}}return i?d=h&&!p?1:0:d=h?1:0,_(u,f,d)}function Vc(e,t){let n;return t.body.type==="Group"?n=t.body.body.map(s=>Qn(s)).join("; "):n=Qn(t.body),`${e} is a function
706
+ `:""}}function vs(e,t){return e===`/bin/${t}`||e===`/usr/bin/${t}`}async function Lc(e,t,n){if(t.includes("/")){let o=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(o))return{error:"not_found",path:o};try{let a=await e.fs.stat(o);if(a.isDirectory)return{error:"permission_denied",path:o};let l=o.split("/").pop()||t,u=e.commands.get(l);return u&&vs(o,l)?{cmd:u,path:o}:(a.mode&73)!==0?{script:!0,path:o}:{error:"permission_denied",path:o}}catch{return{error:"not_found",path:o}}}if(!n&&e.state.hashTable){let o=e.state.hashTable.get(t);if(o){try{let a=await e.fs.stat(o);if(!a.isDirectory){let l=e.commands.get(t);if(l&&vs(o,t))return{cmd:l,path:o};if((a.mode&73)!==0)return{script:!0,path:o}}}catch{}e.state.hashTable.delete(t)}}let s=(n??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let o of s){if(!o)continue;let l=`${o.startsWith("/")?o:e.fs.resolvePath(e.state.cwd,o)}/${t}`;if(await e.fs.exists(l))try{let u=await e.fs.stat(l);if(u.isDirectory)continue;let c=(u.mode&73)!==0,f=e.commands.get(t),d=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 o=e.commands.get(t);if(o)return{cmd:o,path:`/usr/bin/${t}`}}return null}async function xs(e,t){let n=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let o=await e.fs.stat(i);o.isDirectory||(o.mode&73)!==0&&n.push(t)}catch{}return n}let s=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of s){if(!i)continue;let a=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(vs(a,t)&&e.commands.has(t)){n.push(a);continue}if(await e.fs.exists(a)){try{let l=await e.fs.stat(a);if(l.isDirectory||(l.mode&73)===0)continue}catch{continue}n.push(i.startsWith("/")?a:`${i}/${t}`)}}return n}function Mh(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 Mh(i)?i.then(o=>(jn(t,n,`${r} post-await`),o),o=>{throw jn(t,n,`${r} post-await`),o}):(jn(t,n,`${r} return`),i)})}function Fh(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 Fo(e,t){if(!e.requireDefenseContext)return e;let n=`command:${t}`,r=Object.getOwnPropertyDescriptors(e);r.fs={value:Fh(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 Tc="+ ";async function Mc(e){let t=e.state.env.get("PS4");if(t===void 0)return Tc;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 ae&&!r.fatal)return t;if(r instanceof mn||r instanceof Error&&r.name==="AbortError")throw r;return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
707
+ `,t||Tc}finally{e.state.options.xtrace=n}}function Bh(e){return e.map(t=>Wh(t)).join(" ")}function Wh(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let n=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
708
+ `),s=e.includes(" "),i=e.includes("\\"),o=e.includes("'");if(n||r||s||i){let l="";for(let u of e){let c=u.charCodeAt(0);u===`
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 o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function Fc(e,t,n){if(!e.state.options.xtrace)return"";let r=await Mc(e),s=[t,...n],i=Bh(s);return`${r}${i}
710
+ `}async function Bc(e,t,n){return e.state.options.xtrace?`${await Mc(e)}${t}=${n}
711
+ `:""}function $s(e,t,n){return Rt([t,n],"",e.limits.maxStringLength,"array assignment")}async function Wc(e,t){let n=new Map,r="";for(let s of t.assignments){let i=s.name;if(s.array){let c=await Vh(e,t,i,s.array,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};if(r+=c.xtraceOutput,c.continueToNext)continue}let o=s.value?await ne(e,s.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:L("",`bash: ${i}: bad array subscript
712
+ `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let c=await Gh(e,t,l[1],l[2],o,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};if(c.continueToNext)continue}let u=await Zh(e,t,i,o,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};r+=u.xtraceOutput,u.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:n}}async function Vh(e,t,n,r,s,i){let o="";if(/\[.+\]$/.test(n))return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: ${n}: cannot assign list to array member
713
+ `,1)};if(le(e,n)){let h=cn(e,n);if(h===void 0||h==="")throw new U(1,"","");let m=Le(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(Te(e,n)){if(t.name)return o+=`bash: ${n}: readonly variable
715
+ `,{continueToNext:!0,xtraceOutput:o};let h=ue(e,n);if(h)return{continueToNext:!1,xtraceOutput:"",error:h}}let a=e.state.associativeArrays?.has(n),l=ve(e,n),u=l?_e(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=zh(r),p=()=>{ye(e,n),e.state.env.delete(n)};try{a&&d?await qh(e,t,n,r,s,p,h=>{o+=h}):d?await Uh(e,n,r,s,p):await jh(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:o}}function zh(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 qh(e,t,n,r,s,i,o){let a=[];for(let l of r){if(a.length>=e.limits.maxArrayElements)throw new k(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let u=Ws(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=Vt(e,p))):p="",a.push({type:"keyed",key:c,value:p,append:d})}else{let c=await ne(e,l);a.push({type:"invalid",expandedValue:c})}}e.executionScope.consumeWork(a.length,"associative array assignment"),s||i();for(let l of a)if(l.type==="keyed")if(l.append){let u=oe(e,n,l.key)??"";j(e,n,l.key,$s(e,u,l.value),"associative")}else j(e,n,l.key,l.value,"associative");else{let u=t.line??e.state.currentLine??1;o(`bash: line ${u}: ${n}: ${l.expandedValue}: must use subscript when assigning associative array
716
+ `)}}async function Uh(e,t,n,r,s){let i=[],o=0;for(let l of n){let u=Ws(l);if(u){if(o>=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=Vt(e,p))):p="",i.push({type:"keyed",indexExpr:c,value:p,append:d}),o++}else{let c=await pt(e,l);if(c.values.length>e.limits.maxArrayElements-o)throw new k(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push({type:"non-keyed",values:c.values}),o+=c.values.length}}e.executionScope.consumeWork(o,"indexed array assignment"),r||s();let a=0;for(let l of i)if(l.type==="keyed"){let u;try{let c=new G,f=te(c,l.indexExpr);u=await 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=oe(e,t,u)??"";j(e,t,u,$s(e,c,l.value))}else j(e,t,u,l.value);a=u+1}else for(let u of l.values)j(e,t,a++,u)}async function jh(e,t,n,r,s){let i=[];for(let a of n){let l=await pt(e,a);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 o=0;if(e.executionScope.consumeWork(i.length,"indexed array assignment"),r){let a=Z(e,t);if(a.length>0)o=Math.max(...a.map(([u])=>typeof u=="number"?u:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(j(e,t,0,l),e.state.env.delete(t),o=1)}}else s();for(let a=0;a<i.length;a++)j(e,t,o+a,i[a])}async function Gh(e,t,n,r,s,i,o){let a=n;if(le(e,n)){let f=Le(e,n);if(f&&f!==n){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: \`${f}': not a valid identifier
717
+ `,1)};a=f}}if(Te(e,a)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=ue(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l=e.state.associativeArrays?.has(a),u;if(l)u=await Vc(e,r);else{let f=await Bo(e,a,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};u=String(f.index)}let c=i?$s(e,oe(e,a,u)||"",s):s;return t.name||j(e,a,u,c,l?"associative":"indexed"),{continueToNext:!0,xtraceOutput:""}}async function Vc(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 Bo(e,t,n){let r=n;n.startsWith('"')&&n.endsWith('"')&&n.length>=2&&(r=n.slice(1,-1));let s;if(/^-?\d+$/.test(r))s=Number.parseInt(r,10);else{try{let i=new G,o=te(i,r);s=await K(e,o.expression,!1)}catch(i){if(i instanceof U)throw i;if(i instanceof ae){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 o=e.state.currentLine;return{index:0,error:L("",`bash: line ${o}: ${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 a=e.state.currentLine;return{index:0,error:L("",`bash: line ${a}: ${t}[${n}]: bad array subscript
720
+ `,1)}}if(s=Math.max(...i.map(([a])=>typeof a=="number"?a:0))+1+s,s<0){let a=e.state.currentLine;return{index:0,error:L("",`bash: line ${a}: ${t}[${n}]: bad array subscript
721
+ `,1)}}}return{index:s}}async function Zh(e,t,n,r,s,i){let o="",a=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:""};a=f;let d=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(l={arrayName:d[1],subscriptExpr:d[2]},a=d[1])}if(Te(e,a)){if(t.name)return o+=`bash: ${a}: readonly variable
723
+ `,{continueToNext:!0,xtraceOutput:o};let f=ue(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let u;if(ur(e,a))try{let f=new G;if(s){let p=`(${e.state.env.get(a)||"0"}) + (${r})`,h=te(f,p);u=String(await K(e,h.expression))}else{let d=te(f,r);u=String(await K(e,d.expression))}}catch{u="0"}else{let f=ut(e,a)?oe(e,a,0):e.state.env.get(a);u=s?$s(e,f||"",r):r}u=Fn(e,a,u),o+=await Bc(e,a,u);let c;return l?c=await Hh(e,l):ut(e,a)&&(c="0"),t.name?c===void 0&&(i.set(a,e.state.env.get(a)),e.state.env.set(a,u)):(c===void 0?e.state.env.set(a,u):j(e,a,c,u),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(a)),e.state.tempEnvBindings?.some(f=>f.has(a))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(a))),{continueToNext:!1,xtraceOutput:o}}async function Hh(e,t){let{arrayName:n,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(n))return Vc(e,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let o=new G,a=te(o,r);i=await K(e,a.expression,!1)}catch{let o=e.state.env.get(r);i=o?Number.parseInt(o,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let o=Z(e,n);o.length>0&&(i=Math.max(...o.map(l=>l[0]))+1+i)}return String(i)}async function Uc(e,t,n,r){let s=!1,i=!1,o=!1,a=!1,l=!1,u=[];for(let m of t)if(m.startsWith("-")&&m.length>1)for(let E of m.slice(1))E==="t"?s=!0:E==="p"?i=!0:E==="P"?o=!0:E==="a"?a=!0:E==="f"&&(l=!0);else u.push(m);let c="",f="",d=0,p=!1,h=!1;for(let m of u){let E=!1;if(o){if(a){let x=await r(m);if(x.length>0){for(let A of x)c+=`${A}
724
+ `;p=!0,E=!0}}else{let x=await n(m);x&&(c+=`${x}
725
+ `,p=!0,E=!0)}E||(h=!0);continue}let b=!l&&e.state.functions.has(m);if(a&&b){if(!i)if(s)c+=`function
726
+ `;else{let x=e.state.functions.get(m),A=x?zc(m,x):`${m} is a function
727
+ `;c+=A}E=!0}let g=e.state.env.get(`BASH_ALIAS_${m}`);if(g!==void 0&&(a||!E)&&(i||(s?c+=`alias
728
+ `:c+=`${m} is aliased to \`${g}'
729
+ `),E=!0,!a)||Wi.has(m)&&(a||!E)&&(i||(s?c+=`keyword
730
+ `:c+=`${m} is a shell keyword
731
+ `),E=!0,!a))continue;if(!a&&b&&!E){if(!i)if(s)c+=`function
732
+ `;else{let x=e.state.functions.get(m),A=x?zc(m,x):`${m} is a function
733
+ `;c+=A}E=!0;continue}if(!(In.has(m)&&(a||!E)&&(i||(s?c+=`builtin
734
+ `:c+=`${m} is a shell builtin
735
+ `),E=!0,!a))){if(a){let x=await r(m);for(let A of x)i?c+=`${A}
736
+ `:s?c+=`file
737
+ `:c+=`${m} is ${A}
738
+ `,p=!0,E=!0}else if(!E){let x=await n(m);x&&(i?c+=`${x}
739
+ `:s?c+=`file
740
+ `:c+=`${m} is ${x}
741
+ `,p=!0,E=!0)}if(!E&&(h=!0,!s&&!i)){let x=!0;if(m.includes("/")){let A=e.fs.resolvePath(e.state.cwd,m);await e.fs.exists(A)&&(x=!1)}x&&(f+=`bash: type: ${m}: not found
742
+ `)}}}return i?d=h&&!p?1:0:d=h?1:0,L(c,f,d)}function zc(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
707
743
  ${e} ()
708
744
  {
709
745
  ${n}
710
746
  }
711
- `}function Qn(e){if(Array.isArray(e))return e.map(t=>Qn(t)).join("; ");if(e.type==="Statement"){let t=[];for(let n=0;n<e.pipelines.length;n++){let r=e.pipelines[n];t.push(Ep(r)),e.operators[n]&&t.push(e.operators[n])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,n=[];t.name&&n.push(zc(t.name));for(let r of t.args)n.push(zc(r));return n.join(" ")}return e.type==="Group"?`{ ${e.body.map(r=>Qn(r)).join("; ")}; }`:"..."}function Ep(e){let t=e.commands.map(n=>Qn(n));return(e.negated?"! ":"")+t.join(" | ")}function zc(e){let t="";for(let n of e.parts)n.type==="Literal"?t+=n.value:n.type==="DoubleQuoted"?t+=`"${n.parts.map(r=>qc(r)).join("")}"`:n.type==="SingleQuoted"?t+=`'${n.value}'`:t+=qc(n);return t}function qc(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function jc(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}"
712
- `:s+=`alias ${o}='${l}'
713
- `;else if(mi.has(o))r?s+=`${o} is a shell keyword
714
- `:s+=`${o}
715
- `;else if(wn.has(o))r?s+=`${o} is a shell builtin
716
- `:s+=`${o}
717
- `;else if(e.state.functions.has(o))r?s+=`${o} is a function
718
- `:s+=`${o}
719
- `;else if(o.includes("/")){let c=e.fs.resolvePath(e.state.cwd,o),u=!1;if(await e.fs.exists(c))try{let f=await e.fs.stat(c);f.isDirectory||(f.mode&73)!==0&&(r?s+=`${o} is ${o}
720
- `:s+=`${o}
721
- `,u=!0)}catch{}u||(r&&(i+=`${o}: not found
722
- `),a=1)}else if(e.commands.has(o)){let u=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of u){if(!d)continue;let 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}
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(Qh(r)),e.operators[n]&&t.push(e.operators[n])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,n=[];t.name&&n.push(qc(t.name));for(let r of t.args)n.push(qc(r));return n.join(" ")}return e.type==="Group"?`{ ${e.body.map(r=>dr(r)).join("; ")}; }`:"..."}function qc(e){return e.parts.map(jc).join("")}function jc(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(jc).join("")}"`;default:return Se(T.word([e]))}}function Qh(e){let t=e.commands.map(n=>dr(n));return(e.negated?"! ":"")+t.join(" | ")}async function Gc(e,t,n,r){let s="",i="",o=0;for(let a of t){if(!a){o=1;continue}let l=e.state.env.get(`BASH_ALIAS_${a}`);if(l!==void 0)r?s+=`${a} is an alias for "${l}"
748
+ `:s+=`alias ${a}='${l}'
749
+ `;else if(Wi.has(a))r?s+=`${a} is a shell keyword
750
+ `:s+=`${a}
751
+ `;else if(In.has(a))r?s+=`${a} is a shell builtin
752
+ `:s+=`${a}
753
+ `;else if(e.state.functions.has(a))r?s+=`${a} is a function
754
+ `:s+=`${a}
755
+ `;else if(a.includes("/")){let u=e.fs.resolvePath(e.state.cwd,a),c=!1;if(await e.fs.exists(u))try{let f=await e.fs.stat(u);f.isDirectory||(f.mode&73)!==0&&(r?s+=`${a} is ${a}
756
+ `:s+=`${a}
757
+ `,c=!0)}catch{}c||(r&&(i+=`${a}: not found
758
+ `),o=1)}else if(e.commands.has(a)){let c=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of c){if(!d)continue;let p=`${d}/${a}`;try{let h=await e.fs.stat(p);if(!h.isDirectory&&(h.mode&73)!==0){f=p;break}}catch{}}f||(f=`/usr/bin/${a}`),r?s+=`${a} is ${f}
723
759
  `:s+=`${f}
724
- `}else r&&(i+=`${o}: not found
725
- `),a=1}return _(s,i,a)}async function Gc(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 bp(e,t){let n=!0,r=e.signal?new AbortController:void 0,s=new WeakMap,i=()=>{if(!n)throw new Te("",`bash: ${t} used its context after cancellation
726
- `)},a=c=>{if(c===null||typeof c!="object"&&typeof c!="function")return c;let u=s.get(c);if(u!==void 0)return u;if(typeof c=="object"&&$a(c))return c;if(c instanceof Uint8Array){let h=new Uint8Array(c);return s.set(c,h),h}if(c instanceof ArrayBuffer){let h=c.slice(0);return s.set(c,h),h}if(c instanceof Promise){let h=c.then(m=>(i(),a(m)));return s.set(c,h),h}if(typeof c=="function"){let h=function(...m){return i(),a(Reflect.apply(c,this,m))};return s.set(c,h),h}let f=Object.getPrototypeOf(c);if(Array.isArray(c)||f===Object.prototype||f===null){let h=Array.isArray(c)?[]:Object.create(f);s.set(c,h);let m=Object.getOwnPropertyDescriptors(c);for(let E of Object.values(m)){if("value"in E){let b=E.value;E.value=typeof b=="function"?(...g)=>(i(),a(Reflect.apply(b,c,g))):a(b)}if(E.get){let b=E.get;E.get=()=>(i(),a(Reflect.apply(b,c,[])))}if(E.set){let b=E.set;E.set=g=>{i(),Reflect.apply(b,c,[g])}}}return Object.defineProperties(h,m),h}let d=new Map,p=new ga(c,{get(h,m){if(i(),m==="constructor"||m==="prototype"||m==="__proto__")throw new Error(`${t}: unsafe context property access`);let E=Reflect.get(h,m,h);if(typeof E!="function")return a(E);if(d.has(m))return d.get(m);let b=(...g)=>(i(),a(Reflect.apply(E,h,g)));return d.set(m,b),b},set(h,m,E){if(i(),m==="constructor"||m==="prototype"||m==="__proto__")throw new Error(`${t}: unsafe context property access`);return Reflect.set(h,m,E,h)}});return s.set(c,p),p},o=c=>a(c),l=c=>c&&((...u)=>(i(),a(c(...u))));return{context:{...e,fs:o(e.fs),env:o(e.env),limits:Object.freeze({...e.limits}),exportedEnv:e.exportedEnv?Object.freeze({...e.exportedEnv}):void 0,executionScope:e.executionScope?o(e.executionScope):void 0,fileDescriptors:e.fileDescriptors?o(e.fileDescriptors):void 0,coverage:e.coverage?o(e.coverage):void 0,assignShellVariable:l(e.assignShellVariable),exec:l(e.exec),execWithInheritedStdin:l(e.execWithInheritedStdin),fetch:l(e.fetch),getRegisteredCommands:l(e.getRegisteredCommands),sleep:l(e.sleep),trace:l(e.trace),invokeTool:l(e.invokeTool),signal:r?.signal},revoke(){n=!1,r?.signal.aborted||r?.abort(new Te("",`bash: ${t} context revoked
727
- `))}}}async function Sp(e,t,n,r,s,i){let a=s.remainingTimeMs()??t.limits.maxExecutionTimeMs,o=t.limits.maxExtensionCleanupTimeMs,l,c,u,d=Promise.resolve().then(e).then(h=>({kind:"result",result:h}),h=>({kind:"error",error:h})),p=new Promise(h=>{let m=()=>{n(),h({kind:"abort"})};c=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(b=>{u=kn(()=>b(!1),o)})]),E=h.kind==="deadline"?new Te("",`bash: ${r} exceeded its execution deadline
728
- `):new Te("",`bash: execution aborted
729
- `);throw m||s.poisonAfterAbort(E),E}finally{n(),Nn(l),Nn(u),c&&i?.removeEventListener("abort",c)}}async function Zc(e,t,n,r,s,i,a,o){let{ctx:l,runCommand:c}=e;if(l.coverage&&wn.has(t)&&l.coverage.hit(`bash:builtin:${t}`),t==="export")return Bi(l,n);if(t==="unset")return Yi(l,n);if(t==="exit")return Mi(l,n);if(t==="local")return zi(l,n);if(t==="set")return Hi(l,n);if(t==="break")return oi(l,n);if(t==="continue")return $i(l,n);if(t==="return")return ji(l,n);if(t==="eval"&&l.state.options.posix)return Xr(l,n,s);if(t==="shift")return Qi(l,n);if(t==="getopts")return Yr(l,n);if(t==="compgen")return bi(l,n);if(t==="complete")return vi(l,n);if(t==="compopt")return xi(l,n);if(t==="pushd")return await Oi(l,n);if(t==="popd")return Li(l,n);if(t==="dirs")return Ti(l,n);if(t==="source"||t===".")return Ki(l,n);if(t==="read")return Ui(l,n,s,o);if(t==="mapfile"||t==="readarray")return qi(l,n,s);if(t==="declare"||t==="typeset")return Ri(l,n);if(t==="readonly")return Ii(l,n);if(!i){let u=l.state.functions.get(t);if(u)return Qr(l,u,n,s)}if(t==="__just_bash_tee_restore"){if(n.length===0||n.length>l.limits.maxArrayElements)return R(`bash: invalid internal pipeline status restore
730
- `,2);let u=[];for(let p of n){if(!/^(?:0|[1-9][0-9]{0,2})$/.test(p))return R(`bash: invalid internal pipeline status restore
731
- `,2);let h=Number(p);if(!Number.isSafeInteger(h)||h>255)return R(`bash: invalid internal pipeline status restore
732
- `,2);u.push(h)}let f=u[u.length-1]??0,d=[...u].reverse().find(p=>p!==0);return{stdout:"",stderr:"",exitCode:l.state.options.pipefail&&d!==void 0?d:f,internalPipeStatusOverride:u}}if(t==="eval")return Xr(l,n,s);if(t==="cd")return await li(l,n);if(t===":"||t==="true")return te;if(t==="false")return ye(!1);if(t==="let")return Vi(l,n);if(t==="command")return Ap(e,n,s);if(t==="builtin")return vp(e,n,s);if(t==="shopt")return Ic(l,n);if(t==="exec"){if(n.length===0)return te;let[u,...f]=n;return c(u,f,[],s,!1,!1,-1)}if(t==="wait")return te;if(t==="type")return await Uc(l,n,u=>Gc(l,u),u=>ns(l,u));if(t==="hash")return Wi(l,n);if(t==="help")return Fi(l,n);if(t==="["||t==="test"){let u=n;if(t==="["){if(n[n.length-1]!=="]")return R("[: missing `]'\n",2);u=n.slice(0,-1)}return zn(l,u)}return null}async function Ap(e,t,n){let{ctx:r,runCommand:s}=e;if(t.length===0)return te;let i=!1,a=!1,o=!1,l=t;for(;l.length>0&&l[0].startsWith("-");){let f=l[0];if(f==="--"){l=l.slice(1);break}for(let d of f.slice(1))d==="p"?i=!0:d==="V"?a=!0:d==="v"&&(o=!0);l=l.slice(1)}if(l.length===0)return te;if(o||a)return await jc(r,l,o,a);let[c,...u]=l;return s(c,u,[],n,!0,i,-1)}async function vp(e,t,n){let{runCommand:r}=e;if(t.length===0)return te;let s=t;if(s[0]==="--"&&(s=s.slice(1),s.length===0))return te;let i=s[0];if(i!=="__just_bash_tee_restore"&&!wn.has(i))return R(`bash: builtin: ${i}: not a shell builtin
733
- `);let[,...a]=s;return r(i,a,[],n,!0,!1,-1)}async function Hc(e,t,n,r,s){let{ctx:i,buildExportedEnv:a,executeUserScript:o}=e,c=await _c(i,t,s?"/usr/bin:/bin":void 0);if(!c)return Hl(t)?R(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
734
- `,127):R(`bash: ${t}: command not found
735
- `,127);if("error"in c)return c.error==="permission_denied"?R(`bash: ${t}: Permission denied
736
- `,126):R(`bash: ${t}: No such file or directory
737
- `,127);if("script"in c)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,c.path)),await o(c.path,n,r);let{cmd:u,path:f}=c;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",p=a();i.state.fileDescriptors??=new Map;let h={fs:i.fs,fsIdentity:ys(i.fs),cwd:i.state.cwd,env:i.state.env,assignShellVariable:async(b,g,w)=>{if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(b))throw new Error(`${b}: not a valid identifier`);let S=w===void 0?b:`${b}[${w}]`,v=br(i,b,g);if(v===void 0)throw new Error(`${b}: circular name reference`);if(v===null)return;let A=v.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(?:\[(.*)\])?$/);if(!A)throw new Error(`${S}: not a valid identifier`);let x=A[1],P=A[2]??w;if(Ie(i,b)||Ie(i,x))throw new Error(`${x}: readonly variable`);if(P===void 0)i.state.env.set(x,g);else{let D=i.state.associativeArrays?.has(x)?"associative":"indexed";if(D==="associative"){F(i,x,P,g,D);return}let I=await ea(i,x,P);if(I.error)throw new j(I.error.exitCode,I.error.stdout,I.error.stderr);F(i,x,I.index,g,D)}},exportedEnv:p,stdin:d,limits:i.limits,executionScope:u.internalIsExtension?Da(i.executionScope):i.executionScope,exec:(b,g)=>i.execFn(b,g,!1),execWithInheritedStdin:(b,g)=>i.execFn(b,{...g,stdin:d,stdinKind:"bytes"},!0),fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo,coverage:i.coverage,signal:i.state.signal,requireDefenseContext:i.requireDefenseContext,jsBootstrapCode:i.jsBootstrapCode,invokeTool:i.invokeTool},m=bp(h,t),E=Oc(m.context,t);try{let b=()=>ya(i.requireDefenseContext,"command",`${t} execution`,()=>u.execute(n,E)),g=()=>Sp(b,E,m.revoke,t,i.executionScope,i.state.signal);return u.trusted?await ze.runTrustedAsync(g):await g()}catch(b){if(b instanceof $||b instanceof Te||b instanceof en)throw b;return R(`${t}: ${Me(yt(b))}
738
- `)}}async function na(e,t){let n=e.state.inCondition;e.state.inCondition=!0;let r=new xt(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 Kn(e,t,n,r){if(e instanceof qe)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"break",stdout:t,stderr:n};if(e instanceof Ue)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 Oe||e instanceof Qe||e instanceof j||e instanceof $)return e.prependOutput(t,n),{action:"rethrow",stdout:t,stderr:n,error:e};let s=yt(e);return{action:"error",stdout:t,stderr:`${n}${s}
739
- `,exitCode:1}}var Wt=class{ctx;stdoutChunks=[];stderrChunks=[];totalBytes=0;constructor(t){this.ctx=t}append(t,n){let r=T(t)+T(n);r>this.ctx.limits.maxOutputSize-this.totalBytes&&Lt(`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:T(n),stderr:T(r)}}}};async function ra(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 Qe||s instanceof j||s instanceof $||s instanceof St)throw s.prependOutput(n.stdout,n.stderr),s;return n.appendUnaccounted("",`${yt(s)}
740
- `),n.build(1)}return n.build(r)}async function Qc(e,t){let n=new Wt(e);for(let r of t.clauses){let s=await na(e,r.condition);if(n.append(s.stdout,s.stderr),s.exitCode===0)return ra(e,r.body,n)}return t.elseBody?ra(e,t.elseBody,n):n.build(0)}async function Kc(e,t){let n=await ot(e,t.redirections);if(n.error)return n.error;let r=new Wt(e),s=0,i=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return R(`bash: \`${t.variable}': not a valid identifier
741
- `);let a=[];if(t.words===null)a=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)a=[];else try{for(let l of t.words){let c=await at(e,l);Ne(a,c.values,e.limits.maxArrayElements,"for-loop expansion")}}catch(l){if(l instanceof bt)return{stdout:"",stderr:l.stderr,exitCode:1};throw l}e.state.loopDepth++;try{for(let l of a){i++,i>e.limits.maxLoopIterations&&Lt(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r.stdout,r.stderr),e.state.env.set(t.variable,l);try{for(let c of t.body){let u=await e.executeStatement(c);r.append(u.stdout,u.stderr),s=u.exitCode}}catch(c){let u=Kn(c,r.stdout,r.stderr,e.state.loopDepth);if(r.replace(u.stdout,u.stderr),u.action==="break")break;if(u.action==="continue")continue;if(u.action==="error"){let f=r.build(u.exitCode??1);return pe(e,f,t.redirections,n.targets)}throw u.error}}}finally{e.state.loopDepth--}let o=r.build(s);return pe(e,o,t.redirections,n.targets)}async function Xc(e,t){let n=await ot(e,t.redirections);if(n.error)return n.error;let r=t.line;r!==void 0&&(e.state.currentLine=r);let s=new Wt(e),i=0,a=0;t.init&&await Z(e,t.init.expression),e.state.loopDepth++;try{for(;a++,a>e.limits.maxLoopIterations&&Lt(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr),!(t.condition&&(r!==void 0&&(e.state.currentLine=r),await Z(e,t.condition.expression)===0));){try{for(let l of t.body){let c=await e.executeStatement(l);s.append(c.stdout,c.stderr),i=c.exitCode}}catch(l){let c=Kn(l,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(c.stdout,c.stderr),c.action==="break")break;if(c.action==="continue"){t.update&&await Z(e,t.update.expression);continue}if(c.action==="error"){let u=s.build(c.exitCode??1);return pe(e,u,t.redirections,n.targets)}throw c.error}t.update&&await Z(e,t.update.expression)}}finally{e.state.loopDepth--}let o=s.build(i);return pe(e,o,t.redirections,n.targets)}async function Yc(e,t,n=""){let r=new Wt(e),s=0,i=0,a=n;for(let l of t.redirections)if((l.operator==="<<"||l.operator==="<<-")&&l.target.type==="HereDoc"){let c=l.target,u=await W(e,c.content);c.stripTabs&&(u=u.split(`
742
- `).map(f=>f.replace(/^\t+/,"")).join(`
743
- `)),a=u}else if(l.operator==="<<<"&&l.target.type==="Word")a=`${await W(e,l.target)}
744
- `;else if(l.operator==="<"&&l.target.type==="Word")try{let c=await W(e,l.target),u=e.fs.resolvePath(e.state.cwd,c);a=await e.fs.readFile(u)}catch{let c=await W(e,l.target);return R(`bash: ${c}: No such file or directory
745
- `)}let o=e.state.groupStdin;a&&(e.state.groupStdin=a),e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&Lt(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r.stdout,r.stderr);let l=0,c=!1,u=!1,f=e.state.inCondition;e.state.inCondition=!0;try{for(let d of t.condition){let p=await e.executeStatement(d);r.append(p.stdout,p.stderr),l=p.exitCode}}catch(d){if(d instanceof qe){if(r.append(d.stdout,d.stderr),d.levels>1&&e.state.loopDepth>1)throw d.levels--,d.stdout=r.stdout,d.stderr=r.stderr,e.state.inCondition=f,d;c=!0}else if(d instanceof Ue){if(r.append(d.stdout,d.stderr),d.levels>1&&e.state.loopDepth>1)throw d.levels--,d.stdout=r.stdout,d.stderr=r.stderr,e.state.inCondition=f,d;u=!0}else throw e.state.inCondition=f,d}finally{e.state.inCondition=f}if(c)break;if(!u){if(l!==0)break;try{for(let d of t.body){let p=await e.executeStatement(d);r.append(p.stdout,p.stderr),s=p.exitCode}}catch(d){let p=Kn(d,r.stdout,r.stderr,e.state.loopDepth);if(r.replace(p.stdout,p.stderr),p.action==="break")break;if(p.action==="continue")continue;if(p.action==="error")return r.build(p.exitCode??1);throw p.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=o}return r.build(s)}async function Jc(e,t){let n=new Wt(e),r=0,s=0;e.state.loopDepth++;try{for(;;){s++,s>e.limits.maxLoopIterations&&Lt(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n.stdout,n.stderr);let i=await na(e,t.condition);if(n.append(i.stdout,i.stderr),i.exitCode===0)break;try{for(let a of t.body){let o=await e.executeStatement(a);n.append(o.stdout,o.stderr),r=o.exitCode}}catch(a){let o=Kn(a,n.stdout,n.stderr,e.state.loopDepth);if(n.replace(o.stdout,o.stderr),o.action==="break")break;if(o.action==="continue")continue;if(o.action==="error")return n.build(o.exitCode??1);throw o.error}}}finally{e.state.loopDepth--}return n.build(r)}async function eu(e,t){let n=await ot(e,t.redirections);if(n.error)return n.error;let r=new Wt(e),s=0,i=await W(e,t.word),a=!1;for(let l=0;l<t.items.length;l++){let c=t.items[l],u=a;if(!a)for(let f of c.patterns){let d=await W(e,f);Bl(f)&&(d=Ze(d));let p=e.state.shoptOptions.nocasematch,h=e.state.shoptOptions.extglob;if(gn(i,d,p,h,e.limits.maxCallDepth)){u=!0;break}}if(u){let f=await ra(e,c.body,r);if(r.replace(f.stdout,f.stderr),s=f.exitCode,c.terminator===";;")break;c.terminator===";&"?a=!0:a=!1}else a=!1}let o=r.build(s);return pe(e,o,t.redirections,n.targets)}function sa(e,t){if(e.parts.length!==1)return!1;let n=e.parts[0];return n.type!=="Literal"?!1:t.includes(n.value)}function tu(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),n=t.indexOf(":");if(n===-1)return null;let r=Number.parseInt(t.slice(0,n),10);if(Number.isNaN(r)||r<0)return null;let s=n+1,i=t.slice(s,s+r),a=s+r+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let c=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let u=o.slice(l+1);return{path:i,position:c,content:u}}async function nu(e,t,n){let r=t.timed?ps():0,s="",i=te,a=0,o=[],l="",c=0,u=t.commands.length>1,f=e.state.lastArg;for(let E=0;E<t.commands.length;E++){let b=t.commands[E],g=E===t.commands.length-1,w=E===0;u&&(e.state.lastArg="",w||(e.state.groupStdin=void 0));let S=u&&(!g||!e.state.shoptOptions.lastpipe),v=S?new Map(e.state.env):null,A=S?ct(e.state.arrays):null,x,P=e.executionScope.outputBytesUsed;try{e.state.commandCount=e.executionScope.chargeCommand(),x=await n(b,s)}catch(D){if(D instanceof je)x={stdout:D.stdout,stderr:D.stderr,exitCode:1};else if(D instanceof j&&t.commands.length>1)x={stdout:D.stdout,stderr:D.stderr,exitCode:D.exitCode};else if(D instanceof Qe&&t.commands.length>1)x={stdout:D.stdout,stderr:D.stderr,exitCode:D.exitCode};else throw v&&(e.state.env=v,e.state.arrays=A??new Map),D}if(v&&(e.state.env=v,e.state.arrays=A??new Map),x=e.executionScope.accountResult(x,"pipeline",e.executionScope.outputBytesUsed-P),!g){let D=t.pipeStderr?.[E]??!1,I=x.internalOutputAccounting?.stdout??0,O=D?x.internalOutputAccounting?.stderr??0:0;Ra(e.executionScope,I+O,"pipeline"),x={...x,internalOutputAccounting:{stdout:0,stderr:D?0:x.internalOutputAccounting?.stderr??0}}}o.push(x.exitCode),x.exitCode!==0&&(a=x.exitCode),g?i=x:(t.pipeStderr?.[E]??!1?s=qt(x.stderr)+us(x):(s=us(x),l+=x.stderr,c+=x.internalOutputAccounting?.stderr??0),i={stdout:"",stderr:"",exitCode:x.exitCode})}l&&(i={...i,stderr:l+i.stderr,internalOutputAccounting:{stdout:i.internalOutputAccounting?.stdout??0,stderr:c+(i.internalOutputAccounting?.stderr??0)}});let d=t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand",p=i.internalPipeStatusOverride??o;if(d){me(e,"PIPESTATUS");for(let E=0;E<p.length;E++)F(e,"PIPESTATUS",E,String(p[E]))}if(e.state.options.pipefail&&a!==0&&(i={...i,exitCode:a}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let b=(ps()-r)/1e3,g=Math.floor(b/60),w=b%60,S;t.timePosix?S=`real ${b.toFixed(2)}
760
+ `}else r&&(i+=`${a}: not found
761
+ `),o=1}return L(s,i,o)}async function Zc(e,t){if(t.includes("/")){let s=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(s)){try{let i=await e.fs.stat(s);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let r=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let s of r){if(!s)continue;let o=`${s.startsWith("/")?s:e.fs.resolvePath(e.state.cwd,s)}/${t}`;if(await e.fs.exists(o)){try{let a=await e.fs.stat(o);if(a.isDirectory||(a.mode&73)===0)continue}catch{continue}return`${s}/${t}`}}if(e.commands.has(t)){for(let s of r)if(s==="/usr/bin"||s==="/bin")return`${s}/${t}`;return`/usr/bin/${t}`}return null}function Hc(e,t){let n=!0,r=e.signal?new AbortController:void 0,s=new WeakMap,i=()=>{if(!n)throw new Be("",`bash: ${t} used its context after cancellation
762
+ `)},o=f=>{if(f===null||typeof f!="object"&&typeof f!="function")return f;let d=s.get(f);if(d!==void 0)return d;if(typeof f=="object"&&aa(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(),o(b)));return s.set(f,E),E}if(typeof f=="function"){let E=function(...b){return i(),o(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(),o(Reflect.apply(y,f,S))):o(y)}if(g.get){let y=g.get;g.get=()=>(i(),o(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 Jo(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 o(g);if(h.has(b))return h.get(b);let y=(...S)=>(i(),o(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},a=f=>o(f),l=f=>f&&((...d)=>(i(),o(f(...d)))),u=f=>({value:f,enumerable:!0,configurable:!0,writable:!0}),c=Object.getOwnPropertyDescriptors(e);return Object.assign(c,{fs:u(a(e.fs)),env:u(a(e.env)),limits:u(Object.freeze({...e.limits})),exportedEnv:u(e.exportedEnv?Object.freeze({...e.exportedEnv}):void 0),executionScope:u(e.executionScope?a(e.executionScope):void 0),fileDescriptors:u(e.fileDescriptors?a(e.fileDescriptors):void 0),coverage:u(e.coverage?a(e.coverage):void 0),assignShellVariable:u(l(e.assignShellVariable)),exec:u(l(e.exec)),origCommand:u(l(e.origCommand)),execWithInheritedStdin:u(l(e.execWithInheritedStdin)),fetch:u(l(e.fetch)),getRegisteredCommands:u(l(e.getRegisteredCommands)),sleep:u(l(e.sleep)),trace:u(l(e.trace)),invokeTool:u(l(e.invokeTool)),signal:u(r?.signal)}),{context:Object.defineProperties(Object.create(Object.getPrototypeOf(e)),c),revoke(){n=!1,r?.signal.aborted||r?.abort(new Be("",`bash: ${t} context revoked
763
+ `))}}}async function Kh(e,t,n,r,s,i){let o=s.remainingTimeMs()??t.limits.maxExecutionTimeMs,a=t.limits.maxExtensionCleanupTimeMs,l,u,c,d=Promise.resolve().then(e).then(h=>({kind:"result",result:h}),h=>({kind:"error",error:h})),p=new Promise(h=>{let m=()=>{n(),h({kind:"abort"})};u=m,i?.addEventListener("abort",m,{once:!0}),i?.aborted&&m(),l=qn(()=>{n(),h({kind:"deadline"})},o)});try{let h=await Promise.race([d,p]);if(h.kind==="result")return h.result;if(h.kind==="error")throw h.error;n();let m=await Promise.race([d.then(()=>!0),new Promise(b=>{c=qn(()=>b(!1),a)})]),E=h.kind==="deadline"?new Be("",`bash: ${r} exceeded its execution deadline
764
+ `):new Be("",`bash: execution aborted
765
+ `);throw m||s.poisonAfterAbort(E),E}finally{n(),Un(l),Un(c),u&&i?.removeEventListener("abort",u)}}async function Qc(e,t,n,r,s,i,o,a,l=!1){let{ctx:u,runCommand:c}=e;if(u.coverage&&In.has(t)&&u.coverage.hit(`bash:builtin:${t}`),t==="export")return Ao(u,n);if(t==="unset")return To(u,n);if(t==="exit")return So(u,n);if(t==="local")return ko(u,n);if(t==="set")return Io(u,n);if(t==="break")return Ii(u,n);if(t==="continue")return lo(u,n);if(t==="return")return No(u,n);if(t==="eval"&&u.state.options.posix)return Es(u,n,s,l);if(t==="shift")return Oo(u,n);if(t==="getopts")return bs(u,n);if(t==="compgen")return ro(u,n);if(t==="complete")return oo(u,n);if(t==="compopt")return ao(u,n);if(t==="pushd")return await wo(u,n);if(t==="popd")return Eo(u,n);if(t==="dirs")return bo(u,n);if(t==="source"||t===".")return _o(u,n);if(t==="read")return Co(u,n,s,a);if(t==="mapfile"||t==="readarray")return Po(u,n,s);if(t==="declare"||t==="typeset")return mo(u,n);if(t==="readonly")return yo(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 Oi(u,n);if(t===":"||t==="true")return ee;if(t==="false")return ge(!1);if(t==="let")return $o(u,n);if(t==="command")return Xh(e,n,s,l);if(t==="builtin")return Yh(e,n,s,l);if(t==="shopt")return _c(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 Uc(u,n,f=>Zc(u,f),f=>xs(u,f));if(t==="hash")return vo(u,n);if(t==="help")return xo(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 Xh(e,t,n,r=!1){let{ctx:s,runCommand:i}=e;if(t.length===0)return ee;let o=!1,a=!1,l=!1,u=t;for(;u.length>0&&u[0].startsWith("-");){let d=u[0];if(d==="--"){u=u.slice(1);break}for(let p of d.slice(1))p==="p"?o=!0:p==="V"?a=!0:p==="v"&&(l=!0);u=u.slice(1)}if(u.length===0)return ee;if(l||a)return await Gc(s,u,l,a);let[c,...f]=u;return i(c,f,[],n,!0,o,-1,r)}async function Yh(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 o=i[0];if(o!=="__just_bash_tee_restore"&&!In.has(o))return I(`bash: builtin: ${o}: not a shell builtin
769
+ `);let[,...a]=i;return s(o,a,[],n,!0,!1,-1,r)}async function Kc(e,t,n,r,s){let{ctx:i,buildExportedEnv:o,executeUserScript:a}=e,u=await Lc(i,t,s?"/usr/bin:/bin":void 0);if(!u)return Vu(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 a(u.path,n,r);let{cmd:c,path:f}=u;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",p=!1,h=o();i.state.fileDescriptors??=new Map;let m={fs:i.fs,fsIdentity:Ts(i.fs),cwd:i.state.cwd,env:i.state.env,assignShellVariable:async(v,x,A)=>{if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v))throw new Error(`${v}: not a valid identifier`);let C=A===void 0?v:`${v}[${A}]`,N=Fr(i,v,x);if(N===void 0)throw new Error(`${v}: circular name reference`);if(N===null)return;let $=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(?:\[(.*)\])?$/);if(!$)throw new Error(`${C}: not a valid identifier`);let P=$[1],R=$[2]??A;if(Te(i,v)||Te(i,P))throw new Error(`${P}: readonly variable`);if(R===void 0)i.state.env.set(P,x);else{let B=i.state.associativeArrays?.has(P)?"associative":"indexed";if(B==="associative"){j(i,P,R,x,B);return}let q=await Bo(i,P,R);if(q.error)throw new U(q.error.exitCode,q.error.stdout,q.error.stderr);j(i,P,q.index,x,B)}},exportedEnv:h,get stdin(){return p=!0,d},limits:i.limits,executionScope:c.internalIsExtension?da(i.executionScope):i.executionScope,exec:(v,x)=>i.execFn(v,x,!1),execWithInheritedStdin:(v,x)=>i.execFn(v,{...x,stdin:d,stdinKind:"bytes"},!0),fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo,coverage:i.coverage,signal:i.state.signal,requireDefenseContext:i.requireDefenseContext,jsBootstrapCode:i.jsBootstrapCode,invokeTool:i.invokeTool},E=c.internalOriginalCommand,b=()=>{};if(E){let v=Object.getOwnPropertyDescriptors(m);v.executionScope={value:i.executionScope,enumerable:!0,configurable:!0,writable:!0};let x=Object.defineProperties(Object.create(Object.getPrototypeOf(m)),v),A=Hc(x,E.name),C=Fo(A.context,E.name);b=A.revoke,m.origCommand=N=>{let $=()=>E.execute(N,C);return E.trusted?Oe.runTrustedAsync($):Oe.runUntrustedAsync($)}}let g=Hc(m,t),y=Fo(g.context,t),S=()=>{g.revoke(),b()};try{let v=()=>Yo(i.requireDefenseContext,"command",`${t} execution`,()=>c.execute(n,y)),x=()=>Kh(v,y,S,t,i.executionScope,i.state.signal),A=c.trusted?await Oe.runTrustedAsync(x):await x();return{...A,internalStdinConsumed:A.internalStdinConsumed??(p?r.length:0)}}catch(v){if(v instanceof k||v instanceof Be||v instanceof pn)throw v;return I(`${t}: ${We(At(v))}
774
+ `)}}async function Wo(e,t){let n=e.state.inCondition;e.state.inCondition=!0;let r=new It(e.executionScope,"condition"),s=0;try{for(let i of t){let o=await e.executeStatement(i);r.appendResult(o),s=o.exitCode}}catch(i){throw r.prependTo(i),i}finally{e.state.inCondition=n}return r.build(s)}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 De||e instanceof Me||e instanceof U||e instanceof k)return e.prependOutput(t,n),{action:"rethrow",stdout:t,stderr:n,error:e};let s=At(e);return{action:"error",stdout:t,stderr:`${n}${s}
775
+ `,exitCode:1}}function Xc(e,t){return e!==void 0?{owns:!0,stdin:e}:t!==""?{owns:!0,stdin:t}:{owns:!1}}var Xt=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&&qt(`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 Vo(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 Me||s instanceof U||s instanceof k||s instanceof Nt)throw s.prependOutput(n.stdout,n.stderr),s;return n.appendUnaccounted("",`${At(s)}
776
+ `),n.build(1)}return n.build(r)}async function Yc(e,t){return Je(e,t.redirections,"",()=>Jh(e,t))}async function Jh(e,t){let n=new Xt(e);for(let r of t.clauses){let s=await Wo(e,r.condition);if(n.append(s.stdout,s.stderr),s.exitCode===0)return Vo(e,r.body,n)}return t.elseBody?Vo(e,t.elseBody,n):n.build(0)}async function Jc(e,t){return Je(e,t.redirections,"",()=>em(e,t))}async function em(e,t){let n=new Xt(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 o of t.words){let a=await pt(e,o);Ne(i,a.values,e.limits.maxArrayElements,"for-loop expansion")}}catch(o){if(o instanceof Ct)return{stdout:"",stderr:o.stderr,exitCode:1};throw o}e.state.loopDepth++;try{for(let o of i){s++,s>e.limits.maxLoopIterations&&qt(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n.stdout,n.stderr),e.state.env.set(t.variable,o);try{for(let a of t.body){let l=await e.executeStatement(a);n.append(l.stdout,l.stderr),r=l.exitCode}}catch(a){let l=pr(a,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 ef(e,t){return Je(e,t.redirections,"",()=>tm(e,t))}async function tm(e,t){let n=t.line;n!==void 0&&(e.state.currentLine=n);let r=new Xt(e),s=0,i=0;t.init&&await K(e,t.init.expression),e.state.loopDepth++;try{for(;i++,i>e.limits.maxLoopIterations&&qt(`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 o of t.body){let a=await e.executeStatement(o);r.append(a.stdout,a.stderr),s=a.exitCode}}catch(o){let a=pr(o,r.stdout,r.stderr,e.state.loopDepth);if(r.replace(a.stdout,a.stderr),a.action==="break")break;if(a.action==="continue"){t.update&&await K(e,t.update.expression);continue}if(a.action==="error")return r.build(a.exitCode??1);throw a.error}t.update&&await K(e,t.update.expression)}}finally{e.state.loopDepth--}return r.build(s)}async function tf(e,t,n=""){return Je(e,t.redirections,n,r=>nm(e,t,n,r))}async function nm(e,t,n,r){let s=new Xt(e),i=0,o=0,a=Xc(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&qt(`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--,a.owns&&(e.state.groupStdin=l)}return s.build(i)}async function nf(e,t,n=""){return Je(e,t.redirections,n,r=>rm(e,t,n,r))}async function rm(e,t,n,r){let s=new Xt(e),i=0,o=0,a=Xc(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&qt(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let u=await Wo(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--,a.owns&&(e.state.groupStdin=l)}return s.build(i)}async function rf(e,t){return Je(e,t.redirections,"",()=>sm(e,t))}async function sm(e,t){let n=new Xt(e),r=0,s=await ne(e,t.word),i=!1;for(let o=0;o<t.items.length;o++){let a=t.items[o],l=i;if(!i)for(let u of a.patterns){let c=await ne(e,u);Ru(u)&&(c=Ke(c));let f=e.state.shoptOptions.nocasematch,d=e.state.shoptOptions.extglob;if(Dn(s,c,f,d,e.limits.maxCallDepth)){l=!0;break}}if(l){let u=await Vo(e,a.body,n);if(n.replace(u.stdout,u.stderr),r=u.exitCode,a.terminator===";;")break;a.terminator===";&"?i=!0:i=!1}else i=!1}return n.build(r)}function zo(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 sf(e,t,n){let r=t.timed?Os():0,s="",i=ee,o=0,a=[],l="",u=0,c=t.commands.length>1,f=e.state.lastArg,d=e.state.groupStdin,p=e.state.groupStdinSourceFd;for(let 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 x=c&&(!S||!e.state.shoptOptions.lastpipe),A=x?new Map(e.state.env):null,C=x?tt(e.state.arrays):null,N,$=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 Me&&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-$),!S){let P=t.pipeStderr?.[g]??!1,R=N.internalOutputAccounting?.stdout??0,B=P?N.internalOutputAccounting?.stderr??0:0;pa(e.executionScope,R+B,"pipeline"),N={...N,internalOutputAccounting:{stdout:0,stderr:P?0:N.internalOutputAccounting?.stderr??0}}}a.push(N.exitCode),N.exitCode!==0&&(o=N.exitCode),S?i=N:(t.pipeStderr?.[g]??!1?s=en(N.stderr)+Pt(N):(s=Pt(N),l+=N.stderr,u+=N.internalOutputAccounting?.stderr??0),i={stdout:"",stderr:"",exitCode:N.exitCode})}l&&(i={...i,stderr:l+i.stderr,internalOutputAccounting:{stdout:i.internalOutputAccounting?.stdout??0,stderr:u+(i.internalOutputAccounting?.stderr??0)}});let h=t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand",m=i.internalPipeStatusOverride??a;if(h){ye(e,"PIPESTATUS");for(let g=0;g<m.length;g++)j(e,"PIPESTATUS",g,String(m[g]))}if(e.state.options.pipefail&&o!==0&&(i={...i,exitCode:o}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let y=(Os()-r)/1e3,S=Math.floor(y/60),v=y%60,x;t.timePosix?x=`real ${y.toFixed(2)}
746
778
  user 0.00
747
779
  sys 0.00
748
- `:S=`
749
- real ${`${g}m${w.toFixed(3)}s`}
780
+ `:x=`
781
+ real ${`${S}m${v.toFixed(3)}s`}
750
782
  user 0m0.000s
751
783
  sys 0m0.000s
752
- `,i={...i,stderr:i.stderr+S}}u&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=f),i=e.executionScope.accountResult(i,"pipeline");let{internalPipeStatusOverride:h,...m}=i;return m}function ia(e){return e?{...e,options:e.options?[...e.options]:void 0,actions:e.actions?[...e.actions]:void 0}:void 0}function xp(e){return e?new Map(Array.from(e,([t,n])=>[t,ia(n)])):void 0}function $p(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 kp(e){return e?new Map(Array.from(e,([t,n])=>[t,n.map(r=>({...r}))])):void 0}function aa(e){let t={env:e.env,arrays:e.arrays,cwd:e.cwd,previousDir:e.previousDir,lastExitCode:e.lastExitCode,lastArg:e.lastArg,currentLine:e.currentLine,options:e.options,shoptOptions:e.shoptOptions,fileDescriptors:e.fileDescriptors,nextFd:e.nextFd,readonlyVars:e.readonlyVars,associativeArrays:e.associativeArrays,namerefs:e.namerefs,boundNamerefs:e.boundNamerefs,invalidNamerefs:e.invalidNamerefs,integerVars:e.integerVars,lowercaseVars:e.lowercaseVars,uppercaseVars:e.uppercaseVars,exportedVars:e.exportedVars,tempExportedVars:e.tempExportedVars,localExportedVars:e.localExportedVars,declaredVars:e.declaredVars,localScopes:e.localScopes,localArrayScopes:e.localArrayScopes,localVarDepth:e.localVarDepth,localVarStack:e.localVarStack,fullyUnsetLocals:e.fullyUnsetLocals,tempEnvBindings:e.tempEnvBindings,mutatedTempEnvVars:e.mutatedTempEnvVars,accessedTempEnvVars:e.accessedTempEnvVars,functions:e.functions,callDepth:e.callDepth,sourceDepth:e.sourceDepth,callLineStack:e.callLineStack,funcNameStack:e.funcNameStack,sourceStack:e.sourceStack,currentSource:e.currentSource,inCondition:e.inCondition,loopDepth:e.loopDepth,parentHasLoopContext:e.parentHasLoopContext,errexitSafe:e.errexitSafe,directoryStack:e.directoryStack,hashTable:e.hashTable,completionSpecs:e.completionSpecs,defaultCompletionSpec:e.defaultCompletionSpec,emptyCompletionSpec:e.emptyCompletionSpec,groupStdin:e.groupStdin,bashPid:e.bashPid,expansionExitCode:e.expansionExitCode,expansionStderr:e.expansionStderr};e.env=new Map(e.env),e.arrays=ct(e.arrays),e.options={...e.options},e.shoptOptions={...e.shoptOptions},e.fileDescriptors=e.fileDescriptors?new Map(e.fileDescriptors):void 0,e.readonlyVars=new Set(e.readonlyVars),e.associativeArrays=new Set(e.associativeArrays),e.namerefs=new Set(e.namerefs),e.boundNamerefs=new Set(e.boundNamerefs),e.invalidNamerefs=new Set(e.invalidNamerefs),e.integerVars=new Set(e.integerVars),e.lowercaseVars=new Set(e.lowercaseVars),e.uppercaseVars=new Set(e.uppercaseVars),e.exportedVars=new Set(e.exportedVars),e.tempExportedVars=new Set(e.tempExportedVars),e.localExportedVars=e.localExportedVars?.map(r=>new Set(r)),e.declaredVars=new Set(e.declaredVars),e.localScopes=e.localScopes.map(r=>new Map(r)),e.localArrayScopes=$p(e.localArrayScopes),e.localVarDepth=e.localVarDepth?new Map(e.localVarDepth):void 0,e.localVarStack=kp(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=xp(e.completionSpecs),e.defaultCompletionSpec=ia(e.defaultCompletionSpec),e.emptyCompletionSpec=ia(e.emptyCompletionSpec);let n=!1;return()=>{n||(n=!0,Object.assign(e,t))}}async function ru(e,t,n,r){let s=await ot(e,t.redirections);if(s.error)return s.error;let i=e.state.loopDepth,a=aa(e.state);e.state.parentHasLoopContext=i>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,n&&(e.state.groupStdin=n);let o=new xt(e.executionScope,"subshell"),l=0;try{for(let u of t.body){let f=await r(u);o.appendResult(f),l=f.exitCode}}catch(u){if(a(),u instanceof $)throw o.prependTo(u),u;if(u instanceof St){o.append("stdout",u.stdout,u.internalOutputAccounting.stdout),o.append("stderr",u.stderr,u.internalOutputAccounting.stderr);let d=o.build(0);return pe(e,d,t.redirections,s.targets)}if(u instanceof qe||u instanceof Ue){o.append("stdout",u.stdout,u.internalOutputAccounting.stdout),o.append("stderr",u.stderr,u.internalOutputAccounting.stderr);let d=o.build(0);return pe(e,d,t.redirections,s.targets)}if(u instanceof j){o.append("stdout",u.stdout,u.internalOutputAccounting.stdout),o.append("stderr",u.stderr,u.internalOutputAccounting.stderr);let d=o.build(u.exitCode);return pe(e,d,t.redirections,s.targets)}if(u instanceof Oe){o.append("stdout",u.stdout,u.internalOutputAccounting.stdout),o.append("stderr",u.stderr,u.internalOutputAccounting.stderr);let d=o.build(u.exitCode);return pe(e,d,t.redirections,s.targets)}if(u instanceof Qe){o.append("stdout",u.stdout,u.internalOutputAccounting.stdout),o.append("stderr",u.stderr,u.internalOutputAccounting.stderr);let d=o.build(u.exitCode);return pe(e,d,t.redirections,s.targets)}o.append("stderr",`${yt(u)}
753
- `);let f=o.build(1);return pe(e,f,t.redirections,s.targets)}a();let c=o.build(l);return pe(e,c,t.redirections,s.targets)}async function su(e,t,n,r){let s=new xt(e.executionScope,"group"),i=0,a=await ot(e,t.redirections);if(a.error)return a.error;let o=await Hr(e,t.redirections,a.targets);if(o)return o;let l=n;for(let f of t.redirections)if((f.operator==="<<"||f.operator==="<<-")&&f.target.type==="HereDoc"){let d=f.target,p=await W(e,d.content);d.stripTabs&&(p=p.split(`
754
- `).map(m=>m.replace(/^\t+/,"")).join(`
755
- `));let h=f.fd??0;h!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),Ve(e),e.state.fileDescriptors.set(h,p)):l=p}else if(f.operator==="<<<"&&f.target.type==="Word")l=`${a.targets.get(t.redirections.indexOf(f))??""}
756
- `;else if(f.operator==="<"&&f.target.type==="Word")try{let d=a.targets.get(t.redirections.indexOf(f))??"",p=e.fs.resolvePath(e.state.cwd,d);l=await e.fs.readFile(p)}catch{let d=a.targets.get(t.redirections.indexOf(f))??"";return _("",`bash: ${d}: No such file or directory
757
- `,1)}let c=e.state.groupStdin;l&&(e.state.groupStdin=l);try{for(let f of t.body){let d=await r(f);s.appendResult(d),i=d.exitCode}}catch(f){if(e.state.groupStdin=c,f instanceof $)throw s.prependTo(f),f;if(sr(f)||f instanceof Qe||f instanceof j)throw f.prependOutput(s.stdout,s.stderr),f;return s.append("stderr",`${yt(f)}
758
- `),s.build(1)}e.state.groupStdin=c;let u=s.build(i);return pe(e,u,t.redirections,a.targets)}async function iu(e,t,n,r,s){let i;try{i=await e.fs.readFile(t)}catch{return R(`bash: ${t}: No such file or directory
784
+ `,i={...i,stderr:i.stderr+x}}c&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=f),i=e.executionScope.accountResult(i,"pipeline");let{internalPipeStatusOverride:E,...b}=i;return b}function qo(e){return e?{...e,options:e.options?[...e.options]:void 0,actions:e.actions?[...e.actions]:void 0}:void 0}function im(e){return e?new Map(Array.from(e,([t,n])=>[t,qo(n)])):void 0}function om(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 am(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 lm(e){return e?new Map(Array.from(e,([t,n])=>[t,n.map(r=>({...r}))])):void 0}function Uo(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=tt(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=om(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=am(e.localArrayScopes),e.localVarDepth=e.localVarDepth?new Map(e.localVarDepth):void 0,e.localVarStack=lm(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=im(e.completionSpecs),e.defaultCompletionSpec=qo(e.defaultCompletionSpec),e.emptyCompletionSpec=qo(e.emptyCompletionSpec);let n=!1;return()=>{n||(n=!0,Object.assign(e,t))}}async function of(e,t,n,r,s=!1){let i=e.state.loopDepth,o=new Map;for(let l of e.state.fileDescriptors?.keys()??[]){let u=Ye(e,l);u&&o.set(l,u)}let a=Uo(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=>um(e,t,l.stdin??n,r,s||l.stdin!==void 0))}finally{let l=new Map;for(let[u,c]of o){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(...Gt(e,u));l.set(p,Math.max(l.get(p)??0,d))}a();for(let[u,c]of l)Zt(e,u,c)}}async function um(e,t,n,r,s){(s||n)&&(e.state.groupStdin=n);let i=new It(e.executionScope,"subshell"),o=0;try{for(let a of t.body){let l=await r(a);i.appendResult(l),o=l.exitCode}}catch(a){if(a instanceof k)throw i.prependTo(a),a;return a instanceof Nt||a instanceof je||a instanceof Ge?(i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(0)):a instanceof U||a instanceof De||a instanceof Me?(i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(a.exitCode)):(i.append("stderr",`${At(a)}
785
+ `),i.build(1))}return i.build(o)}async function af(e,t,n,r,s=!1){return Je(e,t.redirections,n,i=>cm(e,t,n,r,s,i))}async function cm(e,t,n,r,s,i){let o=new It(e.executionScope,"group"),a=0,l=i.stdin??n,u=s||n!==""||i.stdin!==void 0,c=e.state.groupStdin;u&&(e.state.groupStdin=l);let f=()=>{(u||c!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=c)};try{for(let d of t.body){let p=await r(d);o.appendResult(p),a=p.exitCode}}catch(d){if(f(),d instanceof k)throw o.prependTo(d),d;if(Sr(d)||d instanceof Me||d instanceof U)throw d.prependOutput(o.stdout,o.stderr),d;return o.append("stderr",`${At(d)}
786
+ `),o.build(1)}return f(),o.build(a)}async function lf(e,t,n,r,s){let i;try{i=await e.fs.readFile(t)}catch{return I(`bash: ${t}: No such file or directory
759
787
  `,127)}if(i.startsWith("#!")){let l=i.indexOf(`
760
- `);l!==-1&&(i=i.slice(l+1))}let a=e.state.loopDepth,o=aa(e.state);e.state.parentHasLoopContext=a>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,r&&(e.state.groupStdin=r),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(n.length)),e.state.env.set("@",n.join(" ")),e.state.env.set("*",n.join(" "));for(let l=0;l<n.length&&l<9;l++)e.state.env.set(String(l+1),n[l]);for(let l=n.length+1;l<=9;l++)e.state.env.delete(String(l));try{let c=new V().parse(i),u=await s(c);return o(),u}catch(l){if(o(),l instanceof j)return _(l.stdout,l.stderr,l.exitCode);if(l instanceof $)throw l;if(l.name==="ParseException")return R(`bash: ${t}: ${l.message}
761
- `);throw l}}var Xn=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||ze.isInSandboxedContext())return;let n=`interpreter ${t} attempted outside defense context`;throw new en(n,{timestamp:Date.now(),type:"missing_defense_context",message:n,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:ze.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 xt(this.ctx.executionScope,"script");for(let s of t.statements)try{let i=await this.executeStatement(s);r.appendResult(i,fs(i)),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(i){if(i instanceof j)throw i.prependOutput(r.stdout,r.stderr),i;if(i instanceof Ke)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:vt(this.ctx.state.env)};if(i instanceof $)throw r.prependTo(i),i;if(i instanceof Qe)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:vt(this.ctx.state.env)};if(i instanceof Le)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:vt(this.ctx.state.env)};if(i instanceof je)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:vt(this.ctx.state.env)};if(i instanceof ie){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 rr){r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(i instanceof qe||i instanceof Ue){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:vt(this.ctx.state.env)}}async executeUserScript(t,n,r=""){return iu(this.ctx,t,n,r,s=>this.executeScript(s))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Te;if(t.deferredError)throw new Ae(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return te;this.ctx.state.errexitSafe=!1;let n=new xt(this.ctx.executionScope,"statement");this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&n.append("stderr",`${t.sourceText}
762
- `);let r=0,s=-1,i=!1;try{for(let l=0;l<t.pipelines.length;l++){let c=t.pipelines[l],u=l>0?t.operators[l-1]:null;if(u==="&&"&&r!==0||u==="||"&&r===0)continue;let f=await this.executePipeline(c);n.appendResult(f,fs(f)),r=f.exitCode,s=l,i=c.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}}catch(l){throw n.prependTo(l),l}let a=s<t.pipelines.length-1,o=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=a||i||o,this.ctx.state.options.errexit&&r!==0&&s===t.pipelines.length-1&&!i&&!this.ctx.state.inCondition&&!o){let l=new Qe(r);throw l.prependOutput(n.stdout,n.stderr),l}return n.build(r)}async executePipeline(t){return nu(this.ctx,t,(n,r)=>this.executeCommand(n,r))}async executeCommand(t,n){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,n);case"If":return Qc(this.ctx,t);case"For":return Kc(this.ctx,t);case"CStyleFor":return Xc(this.ctx,t);case"While":return Yc(this.ctx,t,n);case"Until":return Jc(this.ctx,t);case"Case":return eu(this.ctx,t);case"Subshell":return this.executeSubshell(t,n);case"Group":return this.executeGroup(t,n);case"FunctionDef":return lc(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return te}}async executeSimpleCommand(t,n){try{return await this.executeSimpleCommandInner(t,n)}catch(r){if(r instanceof bt)return R(r.stderr);throw r}}async executeSimpleCommandInner(t,n){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let v=t,A=0;for(;;){let x=this.expandAlias(v);if(x===v)break;if(A>=this.ctx.limits.maxCallDepth)throw new $(`alias expansion depth limit exceeded (${this.ctx.limits.maxCallDepth})`,"recursion");A++,v=x}this.aliasExpansionStack.clear(),v!==t&&(t=v)}this.ctx.state.expansionStderr="";let r=await Wc(this.ctx,t);if(r.error)return r.error;let s=r.tempAssignments,i=r.xtraceOutput;if(!t.name){if(t.redirections.length>0){let A=await ot(this.ctx,t.redirections);if(A.error)return A.error;let x=_("",i,0);return pe(this.ctx,x,t.redirections,A.targets)}this.ctx.state.lastArg="";let v=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",_("",v,this.ctx.state.lastExitCode)}let a=t.name&&sa(t.name,["local","declare","typeset","export","readonly"]),o=Array.from(s.keys());if(o.length>0&&!a){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let v of o)this.ctx.state.tempExportedVars.add(v)}let l=await Hr(this.ctx,t.redirections);if(l){for(let[v,A]of s)A===void 0?this.ctx.state.env.delete(v):this.ctx.state.env.set(v,A);return l}let c=-1;for(let v of t.redirections){if((v.operator==="<<"||v.operator==="<<-")&&v.target.type==="HereDoc"){let A=v.target,x=await W(this.ctx,A.content);A.stripTabs&&(x=x.split(`
763
- `).map(D=>D.replace(/^\t+/,"")).join(`
764
- `)),x=qt(x);let P=v.fd??0;P!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),Ve(this.ctx),this.ctx.state.fileDescriptors.set(P,x)):n=x;continue}if(v.operator==="<<<"&&v.target.type==="Word"){n=qt(`${await W(this.ctx,v.target)}
765
- `);continue}if(v.operator==="<"&&v.target.type==="Word")try{let A=await W(this.ctx,v.target),x=this.ctx.fs.resolvePath(this.ctx.state.cwd,A);n=await ha(this.ctx.fs,x)}catch{let A=await W(this.ctx,v.target);for(let[x,P]of s)P===void 0?this.ctx.state.env.delete(x):this.ctx.state.env.set(x,P);return R(`bash: ${A}: No such file or directory
766
- `)}if(v.operator==="<&"&&v.target.type==="Word"){let A=await W(this.ctx,v.target),x=Number.parseInt(A,10);if(!Number.isNaN(x)&&this.ctx.state.fileDescriptors){let P=this.ctx.state.fileDescriptors.get(x);if(P!==void 0)if(P.startsWith("__rw__:")){let D=tu(P);D&&(n=D.content.slice(D.position),c=x)}else P.startsWith("__file__:")||P.startsWith("__file_append__:")||(n=P)}}}let u=await W(this.ctx,t.name),f=[],d=[],p=(v,A)=>{if(f.length>=this.ctx.limits.maxArrayElements)throw new $(`expanded argument element limit exceeded (${this.ctx.limits.maxArrayElements})`,"array_elements");f.push(v),d.push(A)};if(sa(t.name,["local","declare","typeset","export","readonly"])&&(u==="local"||u==="declare"||u==="typeset"||u==="export"||u==="readonly"))for(let v of t.args){let A=await Gl(this.ctx,v);if(A)p(A,!0);else{let x=await Zl(this.ctx,v);if(x!==null)p(x,!0);else{let P=await at(this.ctx,v);for(let D of P.values)p(D,P.quoted)}}}else for(let v of t.args){let A=await at(this.ctx,v);for(let x of A.values)p(x,A.quoted)}if(!u){if(t.name.parts.every(A=>A.type==="CommandSubstitution"||A.type==="ParameterExpansion"||A.type==="ArithmeticExpansion")){if(f.length>0){let A=f.shift();return d.shift(),await this.runCommand(A,f,d,n,!1,!1,c)}return _("","",this.ctx.state.lastExitCode)}return R(`bash: : command not found
767
- `,127)}if(u==="exec"&&(f.length===0||f[0]==="--")){for(let v of t.redirections){if(v.target.type==="HereDoc"||v.fdVariable)continue;let A=await W(this.ctx,v.target),x=v.fd??(v.operator==="<"||v.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),v.operator){case">":case">|":{let P=this.ctx.fs.resolvePath(this.ctx.state.cwd,A);await this.ctx.fs.writeFile(P,"","utf8"),Ve(this.ctx),this.ctx.state.fileDescriptors.set(x,`__file__:${P}`);break}case">>":{let P=this.ctx.fs.resolvePath(this.ctx.state.cwd,A);Ve(this.ctx),this.ctx.state.fileDescriptors.set(x,`__file_append__:${P}`);break}case"<":{let P=this.ctx.fs.resolvePath(this.ctx.state.cwd,A);try{let D=await this.ctx.fs.readFile(P);Ve(this.ctx),this.ctx.state.fileDescriptors.set(x,D)}catch{return R(`bash: ${A}: No such file or directory
768
- `)}break}case"<>":{let P=this.ctx.fs.resolvePath(this.ctx.state.cwd,A);try{let D=await this.ctx.fs.readFile(P);Ve(this.ctx),this.ctx.state.fileDescriptors.set(x,`__rw__:${P.length}:${P}:0:${D}`)}catch{await this.ctx.fs.writeFile(P,"","utf8"),Ve(this.ctx),this.ctx.state.fileDescriptors.set(x,`__rw__:${P.length}:${P}:0:`)}break}case">&":{if(A==="-")this.ctx.state.fileDescriptors.delete(x);else if(A.endsWith("-")){let P=A.slice(0,-1),D=Number.parseInt(P,10);if(!Number.isNaN(D)){let I=this.ctx.state.fileDescriptors.get(D);I!==void 0?this.ctx.state.fileDescriptors.set(x,I):this.ctx.state.fileDescriptors.set(x,`__dupout__:${D}`),this.ctx.state.fileDescriptors.delete(D)}}else{let P=Number.parseInt(A,10);Number.isNaN(P)||(Ve(this.ctx),this.ctx.state.fileDescriptors.set(x,`__dupout__:${P}`))}break}case"<&":{if(A==="-")this.ctx.state.fileDescriptors.delete(x);else if(A.endsWith("-")){let P=A.slice(0,-1),D=Number.parseInt(P,10);if(!Number.isNaN(D)){let I=this.ctx.state.fileDescriptors.get(D);I!==void 0?this.ctx.state.fileDescriptors.set(x,I):this.ctx.state.fileDescriptors.set(x,`__dupin__:${D}`),this.ctx.state.fileDescriptors.delete(D)}}else{let P=Number.parseInt(A,10);Number.isNaN(P)||(Ve(this.ctx),this.ctx.state.fileDescriptors.set(x,`__dupin__:${P}`))}break}}}for(let[v,A]of s)A===void 0?this.ctx.state.env.delete(v):this.ctx.state.env.set(v,A);if(this.ctx.state.tempExportedVars)for(let v of s.keys())this.ctx.state.tempExportedVars.delete(v);return te}if(this.ctx.state.extraArgs){let v=this.ctx.state.extraArgs;this.ctx.state.extraArgs=void 0;for(let A of v)p(A,!0)}let m=await Mc(this.ctx,u,f);s.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(s)));let E,b=null;try{E=await this.runCommand(u,f,d,n,!1,!1,c)}catch(v){if(v instanceof qe||v instanceof Ue)b=v,E=te;else throw v}let g=i+m;if(g&&(E={...E,stderr:g+E.stderr}),E=await pe(this.ctx,E,t.redirections),b)throw b;if(f.length>0){let v=f[f.length-1];if((u==="declare"||u==="local"||u==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(v)){let A=v.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);A&&(v=A[1])}this.ctx.state.lastArg=v}else this.ctx.state.lastArg=u;let w=oc(u)&&u!=="unset"&&u!=="eval";if(!this.ctx.state.options.posix||!w)for(let[v,A]of s)this.ctx.state.fullyUnsetLocals?.has(v)||(A===void 0?this.ctx.state.env.delete(v):this.ctx.state.env.set(v,A));if(this.ctx.state.tempExportedVars)for(let v of s.keys())this.ctx.state.tempExportedVars.delete(v);return s.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(E={...E,stderr:this.ctx.state.expansionStderr+E.stderr},this.ctx.state.expansionStderr=""),E}async runCommand(t,n,r,s,i=!1,a=!1,o=-1){let l={ctx:this.ctx,runCommand:(u,f,d,p,h,m,E)=>this.runCommand(u,f,d,p,h,m,E),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(u,f,d)=>this.executeUserScript(u,f,d)},c=await Zc(l,t,n,r,s,i,a,o);return c!==null?c:Hc(l,t,n,s,a)}aliasExpansionStack=new Set;expandAlias(t){return xo({env:this.ctx.state.env,limits:this.ctx.limits},t,this.aliasExpansionStack)}async findCommandInPath(t){return ns(this.ctx,t)}async executeSubshell(t,n=""){return ru(this.ctx,t,n,r=>this.executeStatement(r))}async executeGroup(t,n=""){return su(this.ctx,t,n,r=>this.executeStatement(r))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let n=await ot(this.ctx,t.redirections);if(n.error)return n.error;try{let r=await Z(this.ctx,t.expression.expression),s=ye(r!==0);return this.ctx.state.expansionStderr&&(s={...s,stderr:this.ctx.state.expansionStderr+s.stderr},this.ctx.state.expansionStderr=""),pe(this.ctx,s,t.redirections,n.targets)}catch(r){let s=R(`bash: arithmetic expression: ${r.message}
769
- `);return pe(this.ctx,s,t.redirections,n.targets)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let n=await ot(this.ctx,t.redirections);if(n.error)return n.error;try{let r=await Tt(this.ctx,t.expression),s=ye(r);return this.ctx.state.expansionStderr&&(s={...s,stderr:this.ctx.state.expansionStderr+s.stderr},this.ctx.state.expansionStderr=""),pe(this.ctx,s,t.redirections,n.targets)}catch(r){let s=r instanceof ie?1:2,i=R(`bash: conditional expression: ${r.message}
770
- `,s);return pe(this.ctx,i,t.redirections,n.targets)}}};import{lookup as Mp}from"node:dns";function oa(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function Np(e){let t=oa(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var Pp=3;function au(e){let t=e;for(let n=0;n<Pp;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 Cp(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function la(e,t){let n=oa(e);if(!n)return!1;let r=Np(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&au(n.pathname)?!1:Cp(n.pathname,r.pathPrefix)}function ou(e){return typeof e=="string"?e:e.url}function lu(e,t){return!t||t.length===0?!1:t.some(n=>la(e,ou(n)))}function ca(e){let t=Dp(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=cu(t);if(n)return ss(n);let r=Ip(t);return r?_p(r):!1}function Dp(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function Rp(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 cu(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>Rp(l));if(n.some(l=>l===null))return null;let r=n;if(t.length===1){let l=r[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,c]=r;return l>255||c>16777215?null:[l,c>>>16&255,c>>>8&255,c&255]}if(t.length===3){let[l,c,u]=r;return l>255||c>255||u>65535?null:[l,c,u>>>8&255,u&255]}let[s,i,a,o]=r;return s>255||i>255||a>255||o>255?null:[s,i,a,o]}function Ip(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=cu(E);if(!b)return null;n=b,t=t.slice(0,m)}let r=t.includes("::")?t.split("::").length-1:0;if(r>1)return null;let[s,i]=t.split("::"),a=s?s.split(":").filter(Boolean):[],o=i?i.split(":").filter(Boolean):[],l=m=>/^[0-9a-f]{1,4}$/i.test(m)?Number.parseInt(m,16):null,c=a.map(l),u=o.map(l);if(c.some(m=>m===null)||u.some(m=>m===null))return null;let f=n?2:0,d=c.length+u.length+f,p=0;if(r===1){if(p=8-d,p<0)return null}else if(d!==8)return null;let h=[...c,...new Array(p).fill(0),...u];return n&&(h.push(n[0]<<8|n[1]),h.push(n[2]<<8|n[3])),h.length===8?h:null}function ss(e){let[t,n]=e;return t===127||t===10||t===172&&n>=16&&n<=31||t===192&&n===168||t===169&&n===254||t===0||t===100&&n>=64&&n<=127||t===198&&(n===18||n===19)||t===192&&n===0&&e[2]===0||t===192&&n===0&&e[2]===2||t===198&&n===51&&e[2]===100||t===203&&n===0&&e[2]===113||t>=240}function _p(e){if(e.every(s=>s===0)||e.slice(0,7).every(s=>s===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return ss(s)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return ss(s)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let s=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return ss(s)}return!1}function uu(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=ou(n);if(!oa(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!==""&&au(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 Op=typeof __BROWSER__<"u"&&__BROWSER__,Ft=class extends Error{constructor(){super("DNS pinning is unavailable in this runtime"),this.name="DnsPinningUnavailableError"}};function Lp(e){let t=new Error(`ENOTFOUND ${e}`);return t.code="ENOTFOUND",t.errno=-3008,t.syscall="getaddrinfo",t.hostname=e,t}function Tp(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(Lp(t),"");return}n.all?r(null,[{address:e.address,family:e.family}]):r(null,e.address,e.family)}}var fu=async e=>{if(Op)throw new Ft;try{let t=await import("./chunks/undici-JES22UVU.js"),n=new t.Agent({connections:1,pipelining:0,connect:{lookup:Tp(e)}}),r=!1;return{async fetch(s,i){if(r)throw new Ft;let a=t.fetch;return await a(s,{...i,dispatcher:n})},async close(){r||(r=!0,await n.destroy())}}}catch(t){throw t instanceof Ft?t:new Ft}};var Ye=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},Yn=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},Jn=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},is=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"}};function Bp(e){return new Promise((t,n)=>{Mp(e,{all:!0},(r,s)=>{r?n(r):t(s)})})}var Wp=20,Fp=3e4,Vp=10485760,zp=["GET","HEAD"],qp=new Set(["GET","HEAD","OPTIONS"]),Up=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 du(e){if(e?.aborted)throw vn(e)}async function Vt(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 jp(e,t){try{return await Vt(e,t)}catch(n){throw t?.aborted&&e.then(r=>ze.runTrustedAsync(()=>r.close())).catch(()=>{}),n}}async function Gp(e){e.body&&!e.body.locked&&await e.body.cancel()}function ua(e){let t=e.allowedUrlPrefixes??[];if(!e.dangerouslyAllowFullInternetAccess){let E=uu(t);if(E.length>0)throw new Error(`Invalid network allow-list:
788
+ `);l!==-1&&(i=i.slice(l+1))}let o=e.state.loopDepth,a=Uo(e.state);e.state.parentHasLoopContext=o>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,r&&(e.state.groupStdin=r),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(n.length)),e.state.env.set("@",n.join(" ")),e.state.env.set("*",n.join(" "));for(let l=0;l<n.length&&l<9;l++)e.state.env.set(String(l+1),n[l]);for(let l=n.length+1;l<=9;l++)e.state.env.delete(String(l));try{let u=new G().parse(i),c=await s(u);return a(),c}catch(l){if(a(),l instanceof U)return 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 fm(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||Oe.isInSandboxedContext())return;let n=`interpreter ${t} attempted outside defense context`;throw new pn(n,{timestamp:Date.now(),type:"missing_defense_context",message:n,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:Oe.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,n=this.ctx.state.tempExportedVars,r=new Set;if(t)for(let i of t)r.add(i);if(n)for(let i of n)r.add(i);if(r.size===0)return Object.create(null);let s=Object.create(null);for(let i of r){let o=this.ctx.state.env.get(i);o!==void 0&&(s[i]=o)}return s}async executeScript(t){this.assertDefenseContext("execution");let n=0,r=new It(this.ctx.executionScope,"script");for(let s of t.statements)try{let i=await this.executeStatement(s);r.appendResult(i,Ds(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:Dt(this.ctx.state.env)};if(i instanceof k)throw r.prependTo(i),i;if(i instanceof Me)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Dt(this.ctx.state.env)};if(i instanceof Fe)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:Dt(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:Dt(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 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 De&&i.prependOutput(r.stdout,r.stderr),i}return{...r.build(n),env:Dt(this.ctx.state.env)}}async executeUserScript(t,n,r=""){return lf(this.ctx,t,n,r,s=>this.executeScript(s))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Be;if(t.deferredError)throw new xe(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return ee;this.ctx.state.errexitSafe=!1;let n=new It(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,Ds(f)),r=f.exitCode,s=l,i=u.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}}catch(l){throw n.prependTo(l),l}let o=s<t.pipelines.length-1,a=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=o||i||a,this.ctx.state.options.errexit&&r!==0&&s===t.pipelines.length-1&&!i&&!this.ctx.state.inCondition&&!a){let l=new Me(r);throw l.prependOutput(n.stdout,n.stderr),l}return n.build(r)}async executePipeline(t){return sf(this.ctx,t,(n,r)=>this.executeCommand(n,r))}async executeCommand(t,n,r=!1){let s=Cu(this.ctx),i;try{i=await this.executeCommandInner(t,n,r)}catch(a){throw await Ci(this.ctx,s).catch(()=>{}),a}let o=await Ci(this.ctx,s);return!o.stdout&&!o.stderr?i:{...i,stdout:o.stdout?Pt(i)+o.stdout:i.stdout,stdoutKind:o.stdout?"bytes":i.stdoutKind,stderr:i.stderr+o.stderr}}async executeCommandInner(t,n,r){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,n);case"If":return Yc(this.ctx,t);case"For":return Jc(this.ctx,t);case"CStyleFor":return ef(this.ctx,t);case"While":return tf(this.ctx,t,n);case"Until":return nf(this.ctx,t,n);case"Case":return rf(this.ctx,t);case"Subshell":return this.executeSubshell(t,n,r);case"Group":return this.executeGroup(t,n,r);case"FunctionDef":return uc(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return fm(t)}}async executeSimpleCommand(t,n){let r;try{return await this.executeSimpleCommandInner(t,n,s=>{r=s})}catch(s){if(r?.finish(),s instanceof Ct)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 $=t,P=0;for(;;){let R=this.expandAlias($);if(R===$)break;if(P>=this.ctx.limits.maxCallDepth)throw new k(`alias expansion depth limit exceeded (${this.ctx.limits.maxCallDepth})`,"recursion");P++,$=R}this.aliasExpansionStack.clear(),$!==t&&(t=$)}this.ctx.state.expansionStderr="";let s=await Wc(this.ctx,t);if(s.error)return s.error;let i=s.tempAssignments,o=s.xtraceOutput,a=()=>{for(let[$,P]of i)P===void 0?this.ctx.state.env.delete($):this.ctx.state.env.set($,P)};if(!t.name){if(t.redirections.length>0){let P=Ln(this.ctx,t.redirections,ac);r(P);let R=await P.prepare(n);if(R.error){if(a(),!R.errorCause)return P.finish(),R.error;try{return Tn(R)}finally{P.finish()}}let B=L("",o,0),q=await Qt(this.ctx,B,t.redirections,R.targets,R.dupSources,R.standardRoutes);return P.finish(),q}this.ctx.state.lastArg="";let $=(this.ctx.state.expansionStderr||"")+o;return this.ctx.state.expansionStderr="",L("",$,this.ctx.state.lastExitCode)}let l=t.name&&zo(t.name,["local","declare","typeset","export","readonly"]),u=Array.from(i.keys());if(u.length>0&&!l){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let $ of u)this.ctx.state.tempExportedVars.add($)}let c=await ne(this.ctx,t.name),f=[],d=[],p=($,P)=>{if(f.length>=this.ctx.limits.maxArrayElements)throw new k(`expanded argument element limit exceeded (${this.ctx.limits.maxArrayElements})`,"array_elements");f.push($),d.push(P)};if(zo(t.name,["local","declare","typeset","export","readonly"])&&(c==="local"||c==="declare"||c==="typeset"||c==="export"||c==="readonly"))for(let $ of t.args){let P=await Bu(this.ctx,$);if(P)p(P,!0);else{let R=await Wu(this.ctx,$);if(R!==null)p(R,!0);else{let B=await pt(this.ctx,$);for(let q of B.values)p(q,B.quoted)}}}else for(let $ of t.args){let P=await pt(this.ctx,$);for(let R of P.values)p(R,P.quoted)}let m=t.name.parts.every($=>$.type==="CommandSubstitution"||$.type==="ParameterExpansion"||$.type==="ArithmeticExpansion");!c&&m&&f.length>0&&(c=f.shift(),d.shift());let E=Ln(this.ctx,t.redirections,c==="exec"?lc:or);r(E);let b=await E.prepare(n);if(b.error)return a(),b.errorCause?Tn(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[$,P]of i)P===void 0?this.ctx.state.env.delete($):this.ctx.state.env.set($,P);if(this.ctx.state.tempExportedVars)for(let $ of i.keys())this.ctx.state.tempExportedVars.delete($);return E.finish(),ee}if(this.ctx.state.extraArgs){let $=this.ctx.state.extraArgs;this.ctx.state.extraArgs=void 0;for(let P of $)p(P,!0)}let S=await Fc(this.ctx,c,f);i.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(i)));let v,x=null;try{v=await this.runCommand(c,f,d,n,!1,!1,g,y)}catch($){if($ instanceof je||$ instanceof Ge)x=$,v=ee;else throw $}g>=0&&c!=="read"&&Zt(this.ctx,g,v.internalStdinConsumed??0);let A=o+S;if(A&&(v={...v,stderr:A+v.stderr}),v=await Qt(this.ctx,v,t.redirections,b.targets,b.dupSources,b.standardRoutes,v.internalProducerCommand??c,v.internalProducerOmitsShellPrefix),E.finish(),x)throw x;if(f.length>0){let $=f[f.length-1];if((c==="declare"||c==="local"||c==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test($)){let P=$.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);P&&($=P[1])}this.ctx.state.lastArg=$}else this.ctx.state.lastArg=c;let C=tc(c)&&c!=="unset"&&c!=="eval";if(!this.ctx.state.options.posix||!C)for(let[$,P]of i)this.ctx.state.fullyUnsetLocals?.has($)||(P===void 0?this.ctx.state.env.delete($):this.ctx.state.env.set($,P));if(this.ctx.state.tempExportedVars)for(let $ of i.keys())this.ctx.state.tempExportedVars.delete($);return i.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(v={...v,stderr:this.ctx.state.expansionStderr+v.stderr},this.ctx.state.expansionStderr=""),v}async runCommand(t,n,r,s,i=!1,o=!1,a=-1,l=!1){let u={ctx:this.ctx,runCommand:(d,p,h,m,E,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 Qc(u,t,n,r,s,i,o,a,l);return c!==null?c.internalProducerCommand===void 0?{...c,internalProducerCommand:t}:c:{...await Kc(u,t,n,s,o),internalProducerCommand:t}}aliasExpansionStack=new Set;expandAlias(t){return fl({env:this.ctx.state.env,limits:this.ctx.limits},t,this.aliasExpansionStack)}async findCommandInPath(t){return xs(this.ctx,t)}async executeSubshell(t,n="",r=!1){return of(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeGroup(t,n="",r=!1){return af(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeArithmeticCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),Je(this.ctx,t.redirections,"",async()=>{try{let n=await 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 Ut(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 I(`bash: conditional expression: ${n.message}
793
+ `,r)}})}};import{lookup as vm}from"node:dns";function jo(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function dm(e){let t=jo(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var pm=3;function uf(e){let t=e;for(let n=0;n<pm;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 hm(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function Go(e,t){let n=jo(e);if(!n)return!1;let r=dm(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&uf(n.pathname)?!1:hm(n.pathname,r.pathPrefix)}function cf(e){return typeof e=="string"?e:e.url}function ff(e,t){return!t||t.length===0?!1:t.some(n=>Go(e,cf(n)))}function Zo(e){let t=mm(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=df(t);if(n)return ks(n);let r=gm(t);return r?wm(r):!1}function mm(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function ym(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 df(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>ym(l));if(n.some(l=>l===null))return null;let r=n;if(t.length===1){let l=r[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,u]=r;return l>255||u>16777215?null:[l,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[l,u,c]=r;return l>255||u>255||c>65535?null:[l,u,c>>>8&255,c&255]}let[s,i,o,a]=r;return s>255||i>255||o>255||a>255?null:[s,i,o,a]}function gm(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=df(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("::"),o=s?s.split(":").filter(Boolean):[],a=i?i.split(":").filter(Boolean):[],l=m=>/^[0-9a-f]{1,4}$/i.test(m)?Number.parseInt(m,16):null,u=o.map(l),c=a.map(l);if(u.some(m=>m===null)||c.some(m=>m===null))return null;let f=n?2:0,d=u.length+c.length+f,p=0;if(r===1){if(p=8-d,p<0)return null}else if(d!==8)return null;let h=[...u,...new Array(p).fill(0),...c];return n&&(h.push(n[0]<<8|n[1]),h.push(n[2]<<8|n[3])),h.length===8?h:null}function 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 wm(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 pf(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=cf(n);if(!jo(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!==""&&uf(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 Em=typeof __BROWSER__<"u"&&__BROWSER__,Yt=class extends Error{constructor(){super("DNS pinning is unavailable in this runtime"),this.name="DnsPinningUnavailableError"}};function bm(e){return"Agent"in e?e:e.default}function Sm(e){let t=new Error(`ENOTFOUND ${e}`);return t.code="ENOTFOUND",t.errno=-3008,t.syscall="getaddrinfo",t.hostname=e,t}function Am(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(Sm(t),"");return}n.all?r(null,[{address:e.address,family:e.family}]):r(null,e.address,e.family)}}var hf=async e=>{if(Em)throw new Yt;try{let{Agent:t,fetch:n}=bm(await import("./chunks/undici-CKF2L2IP.js")),r=new t({connections:1,pipelining:0,connect:{lookup:Am(e)}}),s=!1;return{async fetch(i,o){if(s)throw new Yt;return await n(i,{...o,dispatcher:r})},async close(){s||(s=!0,await r.destroy())}}}catch(t){throw t instanceof Yt?t:new Yt}};var it=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"}},Bn=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};function xm(e){return new Promise((t,n)=>{vm(e,{all:!0},(r,s)=>{r?n(r):t(s)})})}var $m=20,km=3e4,Pm=10485760,Cm=["GET","HEAD"],Nm=new Set(["GET","HEAD","OPTIONS"]),Rm=new Set([301,302,303,307,308]);function Wn(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function mf(e){if(e?.aborted)throw Wn(e)}async function Jt(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),Wn(t);let n,r=new Promise((s,i)=>{n=()=>i(Wn(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function Dm(e,t){try{return await Jt(e,t)}catch(n){throw t?.aborted&&e.then(r=>Oe.runTrustedAsync(()=>r.close())).catch(()=>{}),n}}async function Im(e){e.body&&!e.body.locked&&await e.body.cancel()}function Ho(e){let t=e.allowedUrlPrefixes??[];if(!e.dangerouslyAllowFullInternetAccess){let E=pf(t);if(E.length>0)throw new Error(`Invalid network allow-list:
771
794
  ${E.join(`
772
- `)}`)}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(la(E,g.url)&&g.transform){b||(b=new Headers);for(let w of g.transform)for(let[S,v]of Object.entries(w.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??Wp,i=e.timeoutMs??Fp,a=e.maxResponseSize??Vp,o=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??zp,l=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),c=e._dnsResolve??Bp,u=e._createConnectionOwner??fu;function f(E){let b=E.startsWith("[")&&E.endsWith("]")?E.slice(1,-1):E;if(/^(?:0|[1-9]\d{0,2})(?:\.(?:0|[1-9]\d{0,2})){3}$/.test(b)&&b.split(".").every(w=>Number(w)<=255))return 4;if(b.includes(":")&&!b.includes("%"))try{if(new URL(`http://[${b}]/`).hostname.length>2)return 6}catch{}return null}function d(E,b,g){let{address:w,family:S}=g;if(f(w)!==S)throw new Ye(E,"DNS returned an invalid address for private IP check");return{hostname:b,address:w,family:S}}async function p(E,b){if(du(b),!e.dangerouslyAllowFullInternetAccess&&!lu(E,t))throw new Ye(E);if(!l)return null;let g;try{g=new URL(E)}catch{throw new Ye(E,"invalid URL")}if(ca(g.hostname))throw new Ye(E,"private/loopback IP address blocked");let w=g.hostname;if(f(w)!==null)return null;let S;try{S=await Vt(c(w),b)}catch{throw b?.aborted?vn(b):new Ye(E,"DNS resolution failed for private IP check")}if(!Array.isArray(S)||S.length===0)throw new Ye(E,"DNS resolution returned no addresses for private IP check");let v=S.map(A=>d(E,w,A));for(let{address:A}of v)if(ca(A))throw new Ye(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 is(b,o)}async function m(E,b={}){let g=b.method?.toUpperCase()??"GET",w=b.followRedirects??!0;if(b.maxRedirects!==void 0&&(!Number.isSafeInteger(b.maxRedirects)||b.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let S=b.maxRedirects??s,v=Math.min(s,S),A=b.timeoutMs!==void 0?Math.min(b.timeoutMs,i):i,x=new AbortController,P=da(()=>x.abort(new DOMException("The operation was aborted","AbortError")),A),D=nr(b.signal,x.signal);try{let I=await p(E,D.signal);h(g);let O=E,B=0;for(;;){du(D.signal);let Y;try{let J=await ze.runTrustedAsync(async()=>{let C=r(O),k=Zp(b.headers,C),N={method:g,headers:k,signal:D.signal,redirect:"manual"};if(b.body&&!qp.has(g)&&(N.body=b.body),!I)return await Vt(fetch(O,N),D.signal);try{return Y=await jp(u(I),D.signal),await Vt(Y.fetch(O,N),D.signal)}catch(M){throw M instanceof Ft?new Ye(O,"DNS pinning unavailable for private IP enforcement"):M}});if(Up.has(J.status)&&w){let C=J.headers.get("location");if(!C)return await pu(J,O,a,D.signal);let k=new URL(C,O).href;await Vt(Gp(J),D.signal);try{I=await p(k,D.signal)}catch{throw D.signal?.aborted?vn(D.signal):new Jn(k)}if(B++,B>v)throw new Yn(v);O=k;continue}return await pu(J,O,a,D.signal)}finally{if(Y){let J=Y,C=ze.runTrustedAsync(()=>J.close());await Vt(C,D.signal)}}}}finally{pa(P),D.cleanup()}}return m}function Zp(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 pu(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 An(n)}}let i;if(n>0&&e.body){let a=e.body.getReader(),o=[],l=0;try{for(;;){let{done:u,value:f}=await Vt(a.read(),r);if(u)break;if(f){if(l+=f.byteLength,l>n)throw await a.cancel(),new An(n);o.push(f)}}}catch(u){throw r?.aborted&&await a.cancel(vn(r)).catch(()=>{}),u}i=new Uint8Array(l);let c=0;for(let u of o)i.set(u,c),c+=u.byteLength}else{let a=await Vt(e.arrayBuffer(),r);if(n>0&&a.byteLength>n)throw new An(n);i=new Uint8Array(a)}return{status:e.status,statusText:e.statusText,headers:s,body:i,url:t}}function fa(e,t){if(e.length>t||T(e)>t)throw new $(`script input size limit exceeded (${t} bytes)`,"string_length")}function hu(e){return Yt(e)}function Yt(e){return e.statements.map(mu).join(`
773
- `)}function mu(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(Hp(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let n=t.join(" ");return e.background&&(n+=" &"),n}function Hp(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(yu(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 yu(e){switch(e.type){case"SimpleCommand":return Qp(e);case"If":return sh(e);case"For":return ih(e);case"CStyleFor":return ah(e);case"While":return oh(e);case"Until":return lh(e);case"Case":return ch(e);case"Subshell":return fh(e);case"Group":return dh(e);case"ArithmeticCommand":return ph(e);case"ConditionalCommand":return hh(e);case"FunctionDef":return mh(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function Qp(e){let t=[];for(let n of e.assignments)t.push(Kp(n));e.name&&t.push(_e(e.name));for(let n of e.args)t.push(_e(n));for(let n of e.redirections)t.push(Eu(n));return t.join(" ")}function Kp(e){let t=e.append?"+=":"=";if(e.array){let n=e.array.map(_e).join(" ");return`${e.name}${t}(${n})`}return e.value?`${e.name}${t}${_e(e.value)}`:`${e.name}${t}`}function _e(e){return e.parts.map(t=>as(t,!1)).join("")}function zt(e){return e.parts.map(t=>as(t,!0)).join("")}function as(e,t){switch(e.type){case"Literal":return t?Yp(e.value):Xp(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(n=>as(n,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return gu(e);case"CommandSubstitution":return e.legacy?`\`${Yt(e.body)}\``:`$(${Yt(e.body)})`;case"ArithmeticExpansion":return`$((${ce(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${Yt(e.body)})`:`>(${Yt(e.body)})`;case"BraceExpansion":return nh(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 Xp(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function Yp(e){return e.replace(/[$`"\\]/g,"\\$&")}function Jp(e,t){return e.parts.map(n=>eh(n,t)).join("")}function eh(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return gu(e);case"CommandSubstitution":return e.legacy?`\`${Yt(e.body)}\``:`$(${Yt(e.body)})`;case"ArithmeticExpansion":return`$((${ce(e.expression.expression)}))`;default:return as(e,!1)}}function gu(e){return e.operation?`\${${wu(e.parameter,e.operation)}}`:th(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function th(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function wu(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${zt(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${zt(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?zt(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${zt(t.word)}`;case"Substring":{let n=ce(t.offset.expression);return t.length?`${e}:${n}:${ce(t.length.expression)}`:`${e}:${n}`}case"PatternRemoval":{let n=t.side==="prefix"?"#":"%",r=t.greedy?`${n}${n}`:n;return`${e}${r}${zt(t.pattern)}`}case"PatternReplacement":{let n="/";t.all?n="//":t.anchor==="start"?n="/#":t.anchor==="end"&&(n="/%");let r=t.replacement?`/${zt(t.replacement)}`:"";return`${e}${n}${zt(t.pattern)}${r}`}case"CaseModification":{let n=t.direction==="upper"?"^":",",r=t.all?`${n}${n}`:n,s=t.pattern?zt(t.pattern):"";return`${e}${r}${s}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${wu(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 nh(e){return`{${e.items.map(rh).join(",")}}`}function rh(e){if(e.type==="Word")return _e(e.word);let t=e.startStr??String(e.start),n=e.endStr??String(e.end);return e.step!==void 0?`${t}..${n}..${e.step}`:`${t}..${n}`}function Eu(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let n=e.target,r=n.quoted?`'${n.delimiter}'`:n.delimiter,s=Jp(n.content,n.quoted);return`${t}${e.operator}${r}
774
- ${s}${n.delimiter}`}return e.operator==="<<<"?`${t}<<< ${_e(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${_e(e.target)}`:`${t}${e.operator} ${_e(e.target)}`}function lt(e){return e.length===0?"":` ${e.map(Eu).join(" ")}`}function Je(e){return e.map(mu).join(`
775
- `)}function sh(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} ${Je(r.condition)}; then
776
- ${Je(r.body)}`)}return e.elseBody&&t.push(`else
777
- ${Je(e.elseBody)}`),`${t.join(`
778
- `)}
779
- fi${lt(e.redirections)}`}function ih(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let n=e.words.map(_e).join(" ");t=`for ${e.variable} in ${n}`}return`${t}; do
780
- ${Je(e.body)}
781
- done${lt(e.redirections)}`}function ah(e){let t=e.init?ce(e.init.expression):"",n=e.condition?ce(e.condition.expression):"",r=e.update?ce(e.update.expression):"";return`for ((${t}; ${n}; ${r})); do
782
- ${Je(e.body)}
783
- done${lt(e.redirections)}`}function oh(e){return`while ${Je(e.condition)}; do
784
- ${Je(e.body)}
785
- done${lt(e.redirections)}`}function lh(e){return`until ${Je(e.condition)}; do
786
- ${Je(e.body)}
787
- done${lt(e.redirections)}`}function ch(e){let t=e.items.map(uh).join(`
788
- `);return`case ${_e(e.word)} in
789
- ${t}
790
- esac${lt(e.redirections)}`}function uh(e){let t=e.patterns.map(_e).join(" | "),n=Je(e.body);return n?`${t})
791
- ${n}
792
- ${e.terminator}`:`${t})
793
- ${e.terminator}`}function fh(e){return`(${Je(e.body)})${lt(e.redirections)}`}function dh(e){return`{ ${Je(e.body)}; }${lt(e.redirections)}`}function ph(e){return`((${ce(e.expression.expression)}))${lt(e.redirections)}`}function hh(e){return`[[ ${Xt(e.expression)} ]]${lt(e.redirections)}`}function mh(e){let t=yu(e.body);return`${e.name}() ${t}${lt(e.redirections)}`}function ce(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`${ce(e.left)} ${e.operator} ${ce(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${ce(e.operand)}`:`${ce(e.operand)}${e.operator}`;case"ArithTernary":return`${ce(e.condition)} ? ${ce(e.consequent)} : ${ce(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${ce(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${ce(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${ce(e.target)}[${ce(e.subscript)}]`:ce(e.target)} ${e.operator} ${ce(e.value)}`;case"ArithDynamicElement":return`${ce(e.nameExpr)}[${ce(e.subscript)}]`;case"ArithGroup":return`(${ce(e.expression)})`;case"ArithNested":return`$((${ce(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}[${ce(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(ce).join("");case"ArithDoubleSubscript":return`${e.array}[${ce(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 Xt(e){switch(e.type){case"CondBinary":return`${_e(e.left)} ${e.operator} ${_e(e.right)}`;case"CondUnary":return`${e.operator} ${_e(e.operand)}`;case"CondNot":return`! ${Xt(e.operand)}`;case"CondAnd":return`${Xt(e.left)} && ${Xt(e.right)}`;case"CondOr":return`${Xt(e.left)} || ${Xt(e.right)}`;case"CondGroup":return`( ${Xt(e.expression)} )`;case"CondWord":return _e(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var os=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;invokeToolFn;transformPlugins=[];state;constructor(t={}){this.limits=gs({...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 Cn(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",`
794
- `],["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=ua(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",Ss(this.state.options)),this.state.env.set("BASHOPTS",As(this.state.shoptOptions)),La(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&n instanceof Cn)try{n.mkdirSync(r,{recursive:!0})}catch{}for(let a of Ea(t.commands))this.registerBundledCommand(a);if(t.fetch||t.network)for(let a of ba())this.registerBundledCommand(a);if(t.python)for(let a of Sa())this.registerBundledCommand(a);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let a of Aa())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(Na(a)){let o=Pa(a);this.registerCommandInternal(o,!0)}else this.registerCommandInternal(a,!0)}registerCommand(t){this.registerCommandInternal(t,!0)}registerBundledCommand(t){this.registerCommandInternal(t,!1)}registerCommandInternal(t,n,r=n?t.trusted??!0:t.trusted){this.commands.set(t.name,{name:t.name,trusted:r,internalIsExtension:n,execute:(i,a)=>t.execute(i,a)});let s=this.fs;if(typeof s.writeFileSync=="function"){let i=`#!/bin/bash
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(Go(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??$m,i=e.timeoutMs??km,o=e.maxResponseSize??Pm,a=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Cm,l=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),u=e._dnsResolve??xm,c=e._createConnectionOwner??hf;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 it(E,"DNS returned an invalid address for private IP check");return{hostname:b,address:y,family:S}}async function p(E,b){if(mf(b),!e.dangerouslyAllowFullInternetAccess&&!ff(E,t))throw new it(E);if(!l)return null;let g;try{g=new URL(E)}catch{throw new it(E,"invalid URL")}if(Zo(g.hostname))throw new it(E,"private/loopback IP address blocked");let y=g.hostname;if(f(y)!==null)return null;let S;try{S=await Jt(u(y),b)}catch{throw b?.aborted?Wn(b):new it(E,"DNS resolution failed for private IP check")}if(!Array.isArray(S)||S.length===0)throw new it(E,"DNS resolution returned no addresses for private IP check");let v=S.map(x=>d(E,y,x));for(let{address:x}of v)if(Zo(x))throw new it(E,"hostname resolves to private/loopback IP address");return v[0]}function h(E){if(e.dangerouslyAllowFullInternetAccess)return;let b=E.toUpperCase();if(!a.includes(b))throw new Ps(b,a)}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),x=b.timeoutMs!==void 0?Math.min(b.timeoutMs,i):i,A=new AbortController,C=Ko(()=>A.abort(new DOMException("The operation was aborted","AbortError")),x),N=Er(b.signal,A.signal);try{let $=await p(E,N.signal);h(g);let P=E,R=0;for(;;){mf(N.signal);let B;try{let q=await Oe.runTrustedAsync(async()=>{let D=r(P),W=Om(b.headers,D),V={method:g,headers:W,signal:N.signal,redirect:"manual"};if(b.body&&!Nm.has(g)&&(V.body=b.body),!$)return await Jt(fetch(P,V),N.signal);try{return B=await Dm(c($),N.signal),await Jt(B.fetch(P,V),N.signal)}catch(O){throw O instanceof Yt?new it(P,"DNS pinning unavailable for private IP enforcement"):O}});if(Rm.has(q.status)&&y){let D=q.headers.get("location");if(!D)return await yf(q,P,o,N.signal);let W=new URL(D,P).href;await Jt(Im(q),N.signal);try{$=await p(W,N.signal)}catch{throw N.signal?.aborted?Wn(N.signal):new yr(W)}if(R++,R>v)throw new mr(v);P=W;continue}return await yf(q,P,o,N.signal)}finally{if(B){let q=B,D=Oe.runTrustedAsync(()=>q.close());await Jt(D,N.signal)}}}}finally{Xo(C),N.cleanup()}}return m}function Om(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 yf(e,t,n,r){let s=Object.create(null);if(e.headers.forEach((o,a)=>{s[a.toLowerCase()]=o}),n>0){let o=e.headers.get("content-length");if(o){let a=parseInt(o,10);if(!Number.isNaN(a)&&a>n)throw new Bn(n)}}let i;if(n>0&&e.body){let o=e.body.getReader(),a=[],l=0;try{for(;;){let{done:c,value:f}=await Jt(o.read(),r);if(c)break;if(f){if(l+=f.byteLength,l>n)throw await o.cancel(),new Bn(n);a.push(f)}}}catch(c){throw r?.aborted&&await o.cancel(Wn(r)).catch(()=>{}),c}i=new Uint8Array(l);let u=0;for(let c of a)i.set(c,u),u+=c.byteLength}else{let o=await Jt(e.arrayBuffer(),r);if(n>0&&o.byteLength>n)throw new Bn(n);i=new Uint8Array(o)}return{status:e.status,statusText:e.statusText,headers:s,body:i,url:t}}function Qo(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=Ms({...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 ht(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=Ho(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.coverageWriter=t.coverage,this.state={env:s,arrays:new Map,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,virtualPid:t.processInfo?.pid??1,virtualPpid:t.processInfo?.ppid??0,virtualUid:t.processInfo?.uid??1e3,virtualGid:t.processInfo?.gid??1e3,bashPid:t.processInfo?.pid??1,nextVirtualPid:(t.processInfo?.pid??1)+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",Vs(this.state.options)),this.state.env.set("BASHOPTS",zs(this.state.shoptOptions)),ga(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&n instanceof ht)try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of ta(t.commands))this.registerBundledCommand(o);if(t.fetch||t.network)for(let o of na())this.registerBundledCommand(o);if(t.python)for(let o of ra())this.registerBundledCommand(o);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let o of sa())this.registerBundledCommand(o);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap),i.invokeTool&&(this.invokeToolFn=i.invokeTool)}if(t.customCommands)for(let o of t.customCommands)if(ua(o)){let a=ca(o);this.registerCommandInternal(a,!0)}else this.registerCommandInternal(o,!0)}registerCommand(t){this.registerCommandInternal(t,!0)}registerBundledCommand(t){this.registerCommandInternal(t,!1)}registerCommandInternal(t,n,r=n?t.trusted??!0:t.trusted){let s=this.commands.get(t.name),i=n?s?.internalOriginalCommand??(s&&!s.internalIsExtension?s:void 0):void 0,o={name:t.name,trusted:r,internalIsExtension:n,internalOriginalCommand:i,execute:(l,u)=>t.execute(l,u)};this.commands.set(t.name,o);let a=this.fs;if(typeof a.writeFileSync=="function"){let l=`#!/bin/bash
795
797
  # Built-in command: ${t.name}
796
- `;try{s.writeFileSync(`/bin/${t.name}`,i)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,i)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=Su(t.stdout),t.stderr=Su(t.stderr),t}async exec(t,n){let r=new or(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
797
- `,exitCode:126}}return t.trim()?this.logResult(i):i}async execInScope(t,n,r,s,i,a=!1,o=!0){let l=f=>o?this.logResult(f):f,c=nr(i,n?.signal),u=n?{...n,signal:c.signal}:{signal:c.signal};try{if(r.assertExecDepth(s),fa(t,this.limits.maxSourceBytes),!t.trim())return{stdout:"",stderr:"",exitCode:0,env:Ge(this.state.env,u.env)};this.logger?.info("exec",{command:t});let f=u.cwd??this.state.cwd,d,p=f;if(u.cwd)if(u.env&&"PWD"in u.env)d=u.env.PWD;else if(u.env&&!("PWD"in u.env))try{d=await this.fs.realpath(f),p=d}catch{d=f}else d=f;let h=u.replaceEnv?new Map:new Map(this.state.env);if(u.env)for(let[w,S]of Object.entries(u.env))h.set(w,S);d!==void 0&&h.set("PWD",d);let m={...this.state,env:h,arrays:u.replaceEnv?new Map:ct(this.state.arrays),cwd:p,previousDir:u.env?.OLDPWD??this.state.previousDir,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:wh(u.stdin,u.stdinKind,this.limits.maxInputBytes,this.limits.maxStringLength,r,a),signal:u.signal,extraArgs:u.args},E=t;u.rawScript||(E=bu(t));let b=this.defenseInDepthConfig?ze.getInstance(this.defenseInDepthConfig):null,g=b?.activate();try{let w=async()=>{let S=tt(E,{maxHeredocSize:this.limits.maxHeredocSize}),v;if(this.transformPlugins.length>0){let I=Object.create(null);for(let O of this.transformPlugins){let B=O.transform({ast:S,metadata:I});S=B.ast,B.metadata&&(I=ds(I,B.metadata))}v=I}let A={fs:this.fs,commands:this.commands,limits:this.limits,executionScope:r,exec:(I,O,B=!1)=>this.execInScope(I,O,r,s+1,u.signal,B),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:b?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},D=await new Xn(A,m).executeScript(S);return v&&(D.metadata=v),l(D)};return g?await g.run(w):await w()}catch(w){if(w instanceof j)return l({stdout:w.stdout,stderr:w.stderr,exitCode:w.exitCode,env:Ge(this.state.env,u.env)});if(w instanceof Ke)return l({stdout:w.stdout,stderr:w.stderr,exitCode:w.exitCode,env:Ge(this.state.env,u.env)});if(w instanceof ie)return l({stdout:w.stdout,stderr:w.stderr,exitCode:1,env:Ge(this.state.env,u.env)});if(w instanceof Te)return l({stdout:w.stdout,stderr:w.stderr,exitCode:124,env:Ge(this.state.env,u.env)});if(w instanceof $)return l({stdout:w.stdout,stderr:Me(w.stderr),exitCode:$.EXIT_CODE,env:Ge(this.state.env,u.env)});if(w instanceof en)return l({stdout:"",stderr:`bash: security violation: ${Me(w.message)}
798
- `,exitCode:1,env:Ge(this.state.env,u.env)});if(w.name==="ParseException")return l({stdout:"",stderr:`bash: syntax error: ${Me(w.message)}
799
- `,exitCode:2,env:Ge(this.state.env,u.env)});if(w instanceof Pt)return l({stdout:"",stderr:`bash: ${Me(w.message)}
800
- `,exitCode:2,env:Ge(this.state.env,u.env)});if(w instanceof RangeError)return l({stdout:"",stderr:`bash: ${Me(w.message)}
801
- `,exitCode:1,env:Ge(this.state.env,u.env)});throw w}finally{g?.deactivate()}}catch(f){if(f instanceof Te)return l({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:Ge(this.state.env,u.env)});if(f instanceof $)return l({stdout:f.stdout,stderr:Me(f.stderr),exitCode:$.EXIT_CODE,env:Ge(this.state.env,u.env)});throw f}finally{c.cleanup()}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,n){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),n)}getCwd(){return this.state.cwd}getEnv(){return vt(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){fa(t,this.limits.maxSourceBytes);let n=bu(t),r=tt(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=ds(s,a.metadata))}return{script:hu(r),ast:r,metadata:s}}};function yh(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 bu(e){let t=e.split(`
802
- `),n=[],r=[],s="none";for(let i=0;i<t.length;i++){let a=t[i];if(r.length>0){let u=r[r.length-1];if((u.stripTabs?a.replace(/^\t+/,""):a)===u.delimiter){n.push(a.trimStart()),r.pop();continue}n.push(a);continue}let o=s,l=o==="none"?a.trimStart():a;if(n.push(l),s=yh(a,o),o!=="none")continue;let c=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let u of l.matchAll(c)){let f=u[1]==="-",d=u[3];r.push({delimiter:d,stripTabs:f})}}return n.join(`
803
- `)}var gh=new TextDecoder("utf-8",{fatal:!0});function Su(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 gh.decode(n)}catch{return e}}function wh(e,t,n,r,s,i){if(e===void 0)return;let a=t==="bytes"?e.length:T(e);if(a>n||a>r)throw new $(`stdin size limit exceeded (${Math.min(n,r)} bytes)`,"string_length");return i||s.consumeInput(a,"stdin"),t==="bytes"?e:qt(e)}import*as ue from"node:fs";import*as Pe from"node:path";import*as et from"node:fs";import*as ve from"node:path";function tr(e,t){let n=/^[A-Za-z]:[\\/]/.test(t)?ve.win32:ve.posix,r=n.relative(t,e);return r===""||r!==".."&&!r.startsWith(`..${n.sep}`)&&!n.isAbsolute(r)}function er(e,t){try{let n=et.realpathSync(e);return tr(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=ve.dirname(e);if(r===e)return null;let s=er(r,t);if(s===null)return null;try{if(et.lstatSync(e).isSymbolicLink()){let a=et.readlinkSync(e),o=ve.isAbsolute(a)?a:ve.resolve(ve.dirname(e),a);if(er(o,t)===null)return null}}catch{}return ve.join(s,ve.basename(e))}return null}}function Au(e,t,n){let r=er(e,n);if(r===null)return null;let s=ve.resolve(e),i=s.slice(t.length),a=r.slice(n.length);if(i!==a)return null;try{if(et.lstatSync(s).isSymbolicLink())return null}catch{}return r}function vu(e,t){if(!et.existsSync(e))throw new Error(`${t} root does not exist`);if(!et.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function xu(e,t){if(!ve.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=et.realpathSync(e)}catch{n=ve.resolve(e)}return tr(n,t)?{withinRoot:!0,relativePath:n.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:ve.basename(e)}}function $u(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 Eh=["ELOOP","EFBIG","EPERM"],bh="/home/user/project",xn=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=Pe.resolve(t.root);let n=t.mountPoint??bh;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,vu(this.root,"OverlayFs"),this.canonicalRoot=ue.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=H(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=H(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=H(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=Pe.join(this.root,r),i=Pe.resolve(s);return tr(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?er(t,this.canonicalRoot):Au(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=Pe.dirname(t),r=this.resolveRealPath_(n);return r===null?null:Pe.join(r,Pe.basename(t))}sanitizeError(t,n,r){$u(t,n,r,Eh)}ensureParentDirs(t){let n=rn(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=H(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 ue.promises.lstat(r),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=$t(n);return ln(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return ln(n,"binary")}async readFileBuffer(t,n=new Set){K(t,"open");let r=H(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let c=this.resolveSymlink(r,s.target);return this.readFileBuffer(c,n)}if(s.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(!s.appendChunks||s.appendChunks.length===0)return s.content;let a=s.appendChunks.reduce((c,u)=>c+u.byteLength,s.content.byteLength);if(!Number.isSafeInteger(a))throw new Error(`EFBIG: file too large, read '${t}'`);let o=new Uint8Array(a);o.set(s.content);let l=s.content.byteLength;for(let c of s.appendChunks)o.set(c,l),l+=c.byteLength;return s.content=o,s.appendChunks=void 0,o}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let a=await ue.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${t}'`);let c=await ue.promises.readlink(i),u=this.realTargetToVirtual(r,c),f=this.resolveSymlink(r,u);return this.readFileBuffer(f,n)}if(a.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(this.maxFileReadSize>0&&a.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${a.size} bytes, max ${this.maxFileReadSize})`);let o=this.allowSymlinks?ue.constants.O_RDONLY:ue.constants.O_RDONLY|ue.constants.O_NOFOLLOW,l=await ue.promises.open(i,o);try{let c=await l.readFile();return new Uint8Array(c)}finally{await l.close()}}catch(a){let o=a.code;if(o==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(o==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(a,t,"open")}}async writeFile(t,n,r){K(t,"write"),this.assertWritable(`write '${t}'`);let s=H(t);this.ensureParentDirs(s);let i=$t(r),a=on(n,i);this.setMemoryEntry(s,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(s)}async appendFile(t,n,r){K(t,"append"),this.assertWritable(`append '${t}'`);let s=H(t),i=$t(r),a=on(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){K(t,"stat");let r=H(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 ue.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let o=await ue.promises.readlink(i),l=this.realTargetToVirtual(r,o),c=this.resolveSymlink(r,l);return this.stat(c,n)}return{isFile:a.isFile(),isDirectory:a.isDirectory(),isSymbolicLink:!1,mode:a.mode,size:a.size,mtime:a.mtime,dev:a.dev,ino:a.ino}}catch(a){if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(a,t,"stat")}}async lstat(t){K(t,"lstat");let n=H(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 ue.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 an(t,n)}realTargetToVirtual(t,n){let r=xu(n,this.canonicalRoot);if(r.withinRoot){if(!Pe.isAbsolute(n))return n;let s=r.relativePath;return this.mountPoint==="/"?s:`${this.mountPoint}${s}`}return r.safeName}async mkdir(t,n){K(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=H(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=rn(r);if(i!=="/"&&!await this.existsInOverlay(i))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.setMemoryEntry(r,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(r)}async readdirCore(t,n){if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Map,s=new Set,i=n==="/"?"/":`${n}/`;for(let o of this.deleted)if(o.startsWith(i)){let l=o.slice(i.length),c=l.split("/")[0];c&&!l.includes("/",c.length)&&s.add(c)}for(let[o,l]of this.memory)if(o!==n&&o.startsWith(i)){let c=o.slice(i.length),u=c.split("/")[0];u&&!s.has(u)&&!c.includes("/",1)&&r.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let a=this.resolveRealPath_(this.toRealPath(n));if(a)try{if(!this.allowSymlinks&&(await ue.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 ue.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=H(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 ue.promises.lstat(l)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let u=await ue.promises.readlink(l),f=this.realTargetToVirtual(r,u),d=this.resolveSymlink(r,f);return this.resolveForReaddir(d,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async readdir(t){K(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){K(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){K(t,"rm"),this.assertWritable(`rm '${t}'`);let r=H(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 ue.lstatSync(r),!0}catch{return!1}}async cp(t,n,r){K(t,"cp"),K(n,"cp"),this.assertWritable(`cp '${n}'`);let s=H(t),i=H(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(nn(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(s);for(let c of l){let u=s==="/"?`/${c}`:`${s}/${c}`,f=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(u,f,r)}}}async mv(t,n){this.assertWritable(`mv '${n}'`),await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return ir(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=ue.readdirSync(r);for(let i of s){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;n.add(a);let o=Pe.join(r,i);ue.lstatSync(o).isDirectory()&&this.scanRealFs(a,n)}}catch{}}async chmod(t,n){K(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=H(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}'`);K(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=H(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){K(t,"link"),K(n,"link"),this.assertWritable(`link '${n}'`);let r=H(t),s=H(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){K(t,"readlink");let n=H(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 ue.promises.readlink(s);if(!Pe.isAbsolute(i)){let a=Pe.resolve(Pe.dirname(s),i),o;try{o=ue.realpathSync(a)}catch{o=a}if(!tr(o,this.canonicalRoot))return Pe.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){K(t,"realpath");let n=H(t),r=new Set,s=async o=>{let l=o==="/"?[]:o.slice(1).split("/"),c="";for(let u of l){if(c=`${c}/${u}`,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(c),d=0,p=40;for(;f&&f.type==="symlink"&&d<p;){if(r.add(c),c=this.resolveSymlink(c,f.target),d++,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(c)}if(d>=p)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let h=this.toRealPath(c),m=this.resolveRealPath_(h);if(m)try{if((await ue.promises.lstat(m)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let b=await ue.promises.readlink(m),g=this.realTargetToVirtual(c,b);return r.add(c),c=this.resolveSymlink(c,g),s(c)}}catch(E){if(E.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(E,t,"realpath")}else if(!this.allowSymlinks){let E=this.resolveRealPathParent_(h);if(E)try{if((await ue.promises.lstat(E)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch(b){if(b.message?.includes("ENOENT")||b.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(b,t,"realpath")}}}}return c||"/"},i=await s(n);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,n,r){K(t,"utimes"),this.assertWritable(`utimes '${t}'`);let s=H(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})}};function Nu(){console.log(`just-bash - A secure bash environment for AI agents
798
+ `;try{a.writeFileSync(`/bin/${t.name}`,l)}catch{}try{a.writeFileSync(`/usr/bin/${t.name}`,l)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=wf(t.stdout),t.stderr=wf(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(o){try{await r.close()}catch{}throw o}let i=s;try{await r.close()}catch{i={...s,stderr:`${s.stderr}bash: execution cleanup failed
799
+ `,exitCode:126}}return t.trim()?this.logResult(i):i}async execInScope(t,n,r,s,i,o=!1,a=!0){let l=f=>a?this.logResult(f):f,u=Er(i,n?.signal),c=n?{...n,signal:u.signal}:{signal:u.signal};try{if(r.assertExecDepth(s),Qo(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:tt(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:Tm(c.stdin,c.stdinKind,this.limits.maxInputBytes,this.limits.maxStringLength,r,o),signal:c.signal,extraArgs:c.args},E=t;c.rawScript||(E=gf(t));let b=this.defenseInDepthConfig?Oe.getInstance(this.defenseInDepthConfig):null,g=b?.activate();try{let y=async()=>{let S=at(E,{maxHeredocSize:this.limits.maxHeredocSize}),v;if(this.transformPlugins.length>0){let $=Object.create(null);for(let P of this.transformPlugins){let R=P.transform({ast:S,metadata:$});S=R.ast,R.metadata&&($=Is($,R.metadata))}v=$}let x={fs:this.fs,commands:this.commands,limits:this.limits,executionScope:r,exec:($,P,R=!1)=>this.execInScope($,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(x,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 ae)return l({stdout:y.stdout,stderr:y.stderr,exitCode:1,env:He(this.state.env,c.env)});if(y instanceof Be)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:We(y.stderr),exitCode:k.EXIT_CODE,internalOutputAccounting:y.internalOutputAccounting,env:He(this.state.env,c.env)});if(y instanceof pn)return l({stdout:"",stderr:`bash: security violation: ${We(y.message)}
800
+ `,exitCode:1,env:He(this.state.env,c.env)});if(y.name==="ParseException")return l({stdout:"",stderr:`bash: syntax error: ${We(y.message)}
801
+ `,exitCode:2,env:He(this.state.env,c.env)});if(y instanceof Qe)return l({stdout:"",stderr:`bash: ${We(y.message)}
802
+ `,exitCode:2,env:He(this.state.env,c.env)});if(y instanceof RangeError)return l({stdout:"",stderr:`bash: ${We(y.message)}
803
+ `,exitCode:1,env:He(this.state.env,c.env)});throw y}finally{g?.deactivate()}}catch(f){if(f instanceof Be)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:We(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 Dt(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){Qo(t,this.limits.maxSourceBytes);let n=gf(t),r=at(n,{maxHeredocSize:this.limits.maxHeredocSize}),s=Object.create(null);for(let i of this.transformPlugins){let o=i.transform({ast:r,metadata:s});r=o.ast,o.metadata&&(s=Is(s,o.metadata))}return{script:tl(r),ast:r,metadata:s}}};function _m(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 gf(e){let t=e.split(`
804
+ `),n=[],r=[],s="none";for(let i=0;i<t.length;i++){let o=t[i];if(r.length>0){let c=r[r.length-1];if((c.stripTabs?o.replace(/^\t+/,""):o)===c.delimiter){n.push(o.trimStart()),r.pop();continue}n.push(o);continue}let a=s,l=a==="none"?o.trimStart():o;if(n.push(l),s=_m(o,a),a!=="none")continue;let u=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let c of l.matchAll(u)){let f=c[1]==="-",d=c[3];r.push({delimiter:d,stripTabs:f})}}return n.join(`
805
+ `)}var Lm=new TextDecoder("utf-8",{fatal:!0});function wf(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 Lm.decode(n)}catch{return e}}function Tm(e,t,n,r,s,i){if(e===void 0)return;let o=t==="bytes"?e.length:F(e);if(o>n||o>r)throw new k(`stdin size limit exceeded (${Math.min(n,r)} bytes)`,"string_length");return i||s.consumeInput(o,"stdin"),t==="bytes"?e:en(e)}import*as de from"node:fs";import*as Re from"node:path";import*as ot from"node:fs";import*as $e from"node:path";function wr(e,t){let n=/^[A-Za-z]:[\\/]/.test(t)?$e.win32:$e.posix,r=n.relative(t,e);return r===""||r!==".."&&!r.startsWith(`..${n.sep}`)&&!n.isAbsolute(r)}function gr(e,t){try{let n=ot.realpathSync(e);return wr(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=$e.dirname(e);if(r===e)return null;let s=gr(r,t);if(s===null)return null;try{if(ot.lstatSync(e).isSymbolicLink()){let o=ot.readlinkSync(e),a=$e.isAbsolute(o)?o:$e.resolve($e.dirname(e),o),l=gr(a,t);return l===null?null:l}}catch{}return $e.join(s,$e.basename(e))}return null}}function Ef(e,t,n){let r=gr(e,n);if(r===null)return null;let s=$e.resolve(e),i=s.slice(t.length),o=r.slice(n.length);if(i!==o)return null;try{if(ot.lstatSync(s).isSymbolicLink())return null}catch{}return r}function bf(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 Sf(e,t){if(!$e.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=ot.realpathSync(e)}catch{n=$e.resolve(e)}return wr(n,t)?{withinRoot:!0,relativePath:n.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:$e.basename(e)}}function Af(e,t,n,r){let s=e;if(s.path===void 0){for(let o of r)if(s.message?.includes(o))throw e}let i=s.code||"EIO";throw new Error(`${i}: ${n} '${t}'`)}var Mm=["ELOOP","EFBIG","EPERM"],Fm="/home/user/project",Vn=class{root;canonicalRoot;mountPoint;readOnly;maxFileReadSize;maxMemoryBytes;allowSymlinks;memory=new Map;deleted=new Set;nextMemoryIdentity=1;retainedMemoryBytes=0;memoryEntryBytes(t){if(!t||t.type!=="file")return 0;let n=t.content.byteLength;for(let r of t.appendChunks??[])n+=r.byteLength;return n}assertMemoryCapacity(t,n=0){if(!Number.isSafeInteger(t)||t<0||t>this.maxMemoryBytes-this.retainedMemoryBytes+n)throw new Error(`ENOSPC: overlay memory byte limit exceeded (${this.maxMemoryBytes} bytes)`)}setMemoryEntry(t,n){let r=this.memoryEntryBytes(this.memory.get(t)),s=this.memoryEntryBytes(n);this.assertMemoryCapacity(s,r),this.memory.set(t,n),this.retainedMemoryBytes+=s-r}deleteMemoryEntry(t){let n=this.memory.get(t);n&&(this.retainedMemoryBytes-=this.memoryEntryBytes(n),this.memory.delete(t))}identityFor(t){return t.type==="symlink"?"":(t.identity||(t.identity=`overlay:${this.nextMemoryIdentity++}`),t.identity)}constructor(t){this.root=Re.resolve(t.root);let n=t.mountPoint??Fm;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,bf(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 o of s)i+=`/${o}`,this.memory.has(i)||this.setMemoryEntry(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,n){let r=z(t),s=this.getDirname(r);s!=="/"&&this.mkdirSync(s);let i=n instanceof Uint8Array?n:new TextEncoder().encode(n);this.setMemoryEntry(r,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let n=t.lastIndexOf("/");return n===0?"/":t.slice(0,n)}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let n=z(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=Re.join(this.root,r),i=Re.resolve(s);return wr(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?gr(t,this.canonicalRoot):Ef(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=Re.dirname(t),r=this.resolveRealPath_(n);return r===null?null:Re.join(r,Re.basename(t))}sanitizeError(t,n,r){Af(t,n,r,Mm)}ensureParentDirs(t){let n=gn(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=Ot(n);return Sn(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Sn(n,"binary")}async readFileBuffer(t,n=new Set){Q(t,"open");let r=z(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let u=this.resolveSymlink(r,s.target);return this.readFileBuffer(u,n)}if(s.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(!s.appendChunks||s.appendChunks.length===0)return s.content;let o=s.appendChunks.reduce((u,c)=>u+c.byteLength,s.content.byteLength);if(!Number.isSafeInteger(o))throw new Error(`EFBIG: file too large, read '${t}'`);let a=new Uint8Array(o);a.set(s.content);let l=s.content.byteLength;for(let u of s.appendChunks)a.set(u,l),l+=u.byteLength;return s.content=a,s.appendChunks=void 0,a}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let o=await de.promises.lstat(i);if(o.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(o.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(this.maxFileReadSize>0&&o.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${o.size} bytes, max ${this.maxFileReadSize})`);let a=this.allowSymlinks?de.constants.O_RDONLY:de.constants.O_RDONLY|de.constants.O_NOFOLLOW,l=await de.promises.open(i,a);try{let u=await l.readFile();return new Uint8Array(u)}finally{await l.close()}}catch(o){let a=o.code;if(a==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(a==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(o,t,"open")}}async writeFile(t,n,r){Q(t,"write"),this.assertWritable(`write '${t}'`);let s=z(t);this.ensureParentDirs(s);let i=Ot(r),o=bn(n,i);this.setMemoryEntry(s,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(s)}async appendFile(t,n,r){Q(t,"append"),this.assertWritable(`append '${t}'`);let s=z(t),i=Ot(r),o=bn(n,i),a=this.memory.get(s);if(a?.type==="file"){this.assertMemoryCapacity(o.byteLength),a.appendChunks||(a.appendChunks=[]),a.appendChunks.push(o),this.retainedMemoryBytes+=o.byteLength,a.mtime=new Date,this.deleted.delete(s);return}let l;try{l=await this.readFileBuffer(s)}catch{l=new Uint8Array(0)}this.ensureParentDirs(s),this.setMemoryEntry(s,{type:"file",content:l,appendChunks:[o],mode:420,mtime:new Date}),this.deleted.delete(s)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,n=new Set){Q(t,"stat");let r=z(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let a=this.resolveSymlink(r,s.target);return this.stat(a,n)}let o=0;return s.type==="file"&&(o=s.content.length+(s.appendChunks?.reduce((a,l)=>a+l.byteLength,0)??0)),{isFile:s.type==="file",isDirectory:s.type==="directory",isSymbolicLink:!1,mode:s.mode,size:o,mtime:s.mtime,identity:this.identityFor(s)}}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let o=await de.promises.lstat(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let a=await de.promises.readlink(i),l=this.realTargetToVirtual(r,a),u=this.resolveSymlink(r,l);return this.stat(u,n)}return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:!1,mode:o.mode,size:o.size,mtime:o.mtime,dev:o.dev,ino:o.ino}}catch(o){if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(o,t,"stat")}}async lstat(t){Q(t,"lstat");let n=z(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let i=0;return r.type==="file"&&(i=r.content.length+(r.appendChunks?.reduce((o,a)=>o+a.byteLength,0)??0)),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:i,mtime:r.mtime,identity:this.identityFor(r)}}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await 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 En(t,n)}realTargetToVirtual(t,n){let r=Sf(n,this.canonicalRoot);if(r.withinRoot){if(!Re.isAbsolute(n))return n;let s=r.relativePath;return this.mountPoint==="/"?s:`${this.mountPoint}${s}`}return r.safeName}async mkdir(t,n){Q(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=z(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=gn(r);if(i!=="/"&&!await this.existsInOverlay(i))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.setMemoryEntry(r,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(r)}async readdirCore(t,n){if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Map,s=new Set,i=n==="/"?"/":`${n}/`;for(let a of this.deleted)if(a.startsWith(i)){let l=a.slice(i.length),u=l.split("/")[0];u&&!l.includes("/",u.length)&&s.add(u)}for(let[a,l]of this.memory)if(a!==n&&a.startsWith(i)){let u=a.slice(i.length),c=u.split("/")[0];c&&!s.has(c)&&!u.includes("/",1)&&r.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let o=this.resolveRealPath_(this.toRealPath(n));if(o)try{if(!this.allowSymlinks&&(await de.promises.lstat(o)).isSymbolicLink()){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);return r}let a=await de.promises.readdir(o,{withFileTypes:!0});for(let l of a)!s.has(l.name)&&!r.has(l.name)&&r.set(l.name,{name:l.name,isFile:l.isFile(),isDirectory:l.isDirectory(),isSymbolicLink:l.isSymbolicLink()})}catch(a){if(a.code==="ENOENT"){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else a.code!=="ENOTDIR"&&this.sanitizeError(a,t,"scandir")}return r}async resolveForReaddir(t,n=!1){let r=z(t),s=new Set,i=n,o=this.memory.get(r);for(;o&&o.type==="symlink";){if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(r),i=!0,r=this.resolveSymlink(r,o.target),o=this.memory.get(r)}if(o)return{normalized:r,outsideOverlay:!1};if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let l=this.resolveRealPath_(this.toRealPath(r));if(!l)return{normalized:r,outsideOverlay:!0};try{if((await 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,o)=>i<o?-1:i>o?1:0)}async readdirWithFileTypes(t){Q(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.values()).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async rm(t,n){Q(t,"rm"),this.assertWritable(`rm '${t}'`);let r=z(t);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(r)).isDirectory){let o=await this.readdir(r);if(o.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of o){let l=r==="/"?`/${a}`:`${r}/${a}`;await this.rm(l,n)}}}}catch(i){if(i instanceof Error&&(i.message.includes("ENOTEMPTY")||i.message.includes("EISDIR")))throw i}this.deleteMemoryEntry(r),this.existsOnRealFs(r)&&this.deleted.add(r)}existsOnRealFs(t){let n=this.toRealPath(t),r=this.resolveRealPathParent_(n);if(!r)return!1;try{return 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 a=await this.stat(s);if(a.isFile){let l=await this.readFileBuffer(s);await this.writeFile(i,l)}else if(a.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(vt(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(s);for(let 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 wn(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 o=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(o))continue;n.add(o);let a=Re.join(r,i);de.lstatSync(a).isDirectory()&&this.scanRealFs(o,n)}}catch{}}async chmod(t,n){Q(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=z(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(r);if(i){i.mode=n;return}let o=await this.stat(r);if(o.isFile){let a=await this.readFileBuffer(r);this.setMemoryEntry(r,{type:"file",content:a,mode:n,mtime:new Date})}else o.isDirectory&&this.setMemoryEntry(r,{type:"directory",mode:n,mtime:new Date})}async symlink(t,n){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${n}'`);Q(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=z(n);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.setMemoryEntry(r,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(t,n){Q(t,"link"),Q(n,"link"),this.assertWritable(`link '${n}'`);let r=z(t),s=z(n);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let o=await this.stat(r);if(!o.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let l=await this.readFileBuffer(r);this.ensureParentDirs(s),this.setMemoryEntry(s,{type:"file",content:l,mode:o.mode,mtime:new Date,identity:o.identity??`overlay:${this.nextMemoryIdentity++}`}),this.deleted.delete(s)}async readlink(t){Q(t,"readlink");let n=z(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let r=this.memory.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await de.promises.readlink(s);if(!Re.isAbsolute(i)){let o=Re.resolve(Re.dirname(s),i),a;try{a=de.realpathSync(o)}catch{a=o}if(!wr(a,this.canonicalRoot))return Re.basename(i)}return this.realTargetToVirtual(n,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){Q(t,"realpath");let n=z(t),r=new Set,s=async a=>{let l=a==="/"?[]:a.slice(1).split("/"),u="";for(let c of l){if(u=`${u}/${c}`,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(u),d=0,p=40;for(;f&&f.type==="symlink"&&d<p;){if(r.add(u),u=this.resolveSymlink(u,f.target),d++,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(u)}if(d>=p)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let h=this.toRealPath(u),m=this.resolveRealPath_(h);if(m)try{if((await 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 o=this.memory.get(s);if(o){o.mtime=r;return}let a=await this.stat(s);if(a.isFile){let l=await this.readFileBuffer(s);this.setMemoryEntry(s,{type:"file",content:l,mode:a.mode,mtime:r})}else a.isDirectory&&this.setMemoryEntry(s,{type:"directory",mode:a.mode,mtime:r})}};function xf(){console.log(`just-bash - A secure bash environment for AI agents
804
806
 
805
807
  Usage:
806
808
  just-bash [options] [script-file] [root]
@@ -851,5 +853,5 @@ Examples:
851
853
 
852
854
  # Allow write operations (writes stay in memory)
853
855
  just-bash -c 'echo test > /tmp/file.txt && cat /tmp/file.txt' --allow-write
854
- `)}function Sh(){console.log("just-bash 1.0.0")}function Ah(e){let t={root:process.cwd(),cwd:"/",cwdOverridden:!1,errexit:!1,allowWrite:!1,python:!1,javascript:!1,json:!1,help:!1,version:!1},n=0,r=[],s=!1;for(;n<e.length;){let a=e[n];if(a==="--"){r.push(...e.slice(n+1));break}else if(a==="-h"||a==="--help")t.help=!0,n++;else if(a==="-v"||a==="--version")t.version=!0,n++;else if(a==="-c")n+1>=e.length&&(console.error("Error: -c requires a script argument"),process.exit(1)),t.script=e[n+1],n+=2;else if(a==="-e"||a==="--errexit")t.errexit=!0,n++;else if(a==="--root")n+1>=e.length&&(console.error("Error: --root requires a path argument"),process.exit(1)),t.root=ku(e[n+1]),s=!0,n+=2;else if(a==="--cwd")n+1>=e.length&&(console.error("Error: --cwd requires a path argument"),process.exit(1)),t.cwd=e[n+1],t.cwdOverridden=!0,n+=2;else if(a==="--json")t.json=!0,n++;else if(a==="--allow-write")t.allowWrite=!0,n++;else if(a==="--python")t.python=!0,n++;else if(a==="--javascript")t.javascript=!0,n++;else if(a.startsWith("-"))if(a.length>2&&!a.startsWith("--")){let o=a.slice(1);for(let l of o)if(l==="e")t.errexit=!0;else if(l==="h")t.help=!0;else if(l==="v")t.version=!0;else if(l==="c"){n+1>=e.length&&(console.error("Error: -c requires a script argument"),process.exit(1)),t.script=e[n+1],n++;break}else console.error(`Error: Unknown option: -${l}`),process.exit(1);n++}else console.error(`Error: Unknown option: ${a}`),process.exit(1);else r.push(a),n++}let i=a=>{console.error(`Error: ${a}`),process.exit(1)};if(t.script&&r.length>0&&i("script file cannot be combined with -c"),r.length>2&&i("unexpected extra positional argument"),r.length>=1&&(t.scriptFile=r[0]),r.length===2){let a=ku(r[1]);s&&a!==t.root&&i("conflicting positional root and --root"),t.root=a}return t}function vh(e){if(!e||e==="/")return"/";let t=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;t.startsWith("/")||(t=`/${t}`);let n=t.split("/").filter(s=>s&&s!=="."),r=[];for(let s of n)s===".."?r.pop():r.push(s);return`/${r.join("/")}`||"/"}async function xh(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString("utf-8")}async function $h(){let e=process.argv.slice(2),t=Ah(e);t.help&&(Nu(),process.exit(0)),t.version&&(Sh(),process.exit(0));let n;if(t.script)n=t.script;else if(t.scriptFile){let o=new xn({root:t.root}),l=o.getMountPoint();try{let c=t.scriptFile.startsWith("/")?t.scriptFile:`${l}/${t.scriptFile}`;n=await o.readFile(c,"utf-8")}catch(c){console.error(`Error: Cannot read script file: ${t.scriptFile}`),console.error(Me(c instanceof Error?c.message:String(c))),process.exit(1)}}else process.stdin.isTTY?(Nu(),process.exit(1)):n=await xh();n.trim()||(t.json&&console.log(JSON.stringify({stdout:"",stderr:"",exitCode:0})),process.exit(0));let r=new xn({root:t.root,readOnly:!t.allowWrite}),s=r.getMountPoint(),i=t.cwdOverridden?vh(t.cwd):s,a=new os({fs:r,cwd:i,python:t.python,javascript:t.javascript});t.errexit&&(n=`set -e
855
- ${n}`);try{let o=await a.exec(n);t.json?console.log(JSON.stringify({stdout:o.stdout,stderr:o.stderr,exitCode:o.exitCode})):(o.stdout&&process.stdout.write(o.stdout),o.stderr&&process.stderr.write(o.stderr)),process.exit(o.exitCode)}catch(o){let l=Me(o instanceof Error?o.message:String(o));t.json?console.log(JSON.stringify({stdout:"",stderr:l,exitCode:1})):console.error(l),process.exit(1)}}$h().catch(e=>{console.error("Fatal error:",Me(e instanceof Error?e.message:String(e))),process.exit(1)});
856
+ `)}function Bm(){console.log("just-bash 1.0.0")}function Wm(e){let t={root:process.cwd(),cwd:"/",cwdOverridden:!1,errexit:!1,allowWrite:!1,python:!1,javascript:!1,json:!1,help:!1,version:!1},n=0,r=[],s=!1;for(;n<e.length;){let o=e[n];if(o==="--"){r.push(...e.slice(n+1));break}else if(o==="-h"||o==="--help")t.help=!0,n++;else if(o==="-v"||o==="--version")t.version=!0,n++;else if(o==="-c")n+1>=e.length&&(console.error("Error: -c requires a script argument"),process.exit(1)),t.script=e[n+1],n+=2;else if(o==="-e"||o==="--errexit")t.errexit=!0,n++;else if(o==="--root")n+1>=e.length&&(console.error("Error: --root requires a path argument"),process.exit(1)),t.root=vf(e[n+1]),s=!0,n+=2;else if(o==="--cwd")n+1>=e.length&&(console.error("Error: --cwd requires a path argument"),process.exit(1)),t.cwd=e[n+1],t.cwdOverridden=!0,n+=2;else if(o==="--json")t.json=!0,n++;else if(o==="--allow-write")t.allowWrite=!0,n++;else if(o==="--python")t.python=!0,n++;else if(o==="--javascript")t.javascript=!0,n++;else if(o.startsWith("-"))if(o.length>2&&!o.startsWith("--")){let a=o.slice(1);for(let l of a)if(l==="e")t.errexit=!0;else if(l==="h")t.help=!0;else if(l==="v")t.version=!0;else if(l==="c"){n+1>=e.length&&(console.error("Error: -c requires a script argument"),process.exit(1)),t.script=e[n+1],n++;break}else console.error(`Error: Unknown option: -${l}`),process.exit(1);n++}else console.error(`Error: Unknown option: ${o}`),process.exit(1);else r.push(o),n++}let i=o=>{console.error(`Error: ${o}`),process.exit(1)};if(t.script&&r.length>0&&i("script file cannot be combined with -c"),r.length>2&&i("unexpected extra positional argument"),r.length>=1&&(t.scriptFile=r[0]),r.length===2){let o=vf(r[1]);s&&o!==t.root&&i("conflicting positional root and --root"),t.root=o}return t}function Vm(e){if(!e||e==="/")return"/";let t=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;t.startsWith("/")||(t=`/${t}`);let n=t.split("/").filter(s=>s&&s!=="."),r=[];for(let s of n)s===".."?r.pop():r.push(s);return`/${r.join("/")}`||"/"}async function zm(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString("utf-8")}async function qm(){let e=process.argv.slice(2),t=Wm(e);t.help&&(xf(),process.exit(0)),t.version&&(Bm(),process.exit(0));let n;if(t.script)n=t.script;else if(t.scriptFile){let a=new Vn({root:t.root}),l=a.getMountPoint();try{let u=t.scriptFile.startsWith("/")?t.scriptFile:`${l}/${t.scriptFile}`;n=await a.readFile(u,"utf-8")}catch(u){console.error(`Error: Cannot read script file: ${t.scriptFile}`),console.error(We(u instanceof Error?u.message:String(u))),process.exit(1)}}else process.stdin.isTTY?(xf(),process.exit(1)):n=await zm();n.trim()||(t.json&&console.log(JSON.stringify({stdout:"",stderr:"",exitCode:0})),process.exit(0));let r=new Vn({root:t.root,readOnly:!t.allowWrite}),s=r.getMountPoint(),i=t.cwdOverridden?Vm(t.cwd):s,o=new Cs({fs:r,cwd:i,python:t.python,javascript:t.javascript});t.errexit&&(n=`set -e
857
+ ${n}`);try{let a=await o.exec(n);t.json?console.log(JSON.stringify({stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode})):(a.stdout&&process.stdout.write(a.stdout),a.stderr&&process.stderr.write(a.stderr)),process.exit(a.exitCode)}catch(a){let l=We(a instanceof Error?a.message:String(a));t.json?console.log(JSON.stringify({stdout:"",stderr:l,exitCode:1})):console.error(l),process.exit(1)}}qm().catch(e=>{console.error("Fatal error:",We(e instanceof Error?e.message:String(e))),process.exit(1)});