@jerryan/just-bash 3.10.0 → 3.11.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 (382) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +2 -2
  3. package/dist/AGENTS.md +2 -2
  4. package/dist/abort-signals.d.ts +10 -0
  5. package/dist/bin/chunks/awk2-LCV2AUIX.js +3 -0
  6. package/dist/bin/{shell/chunks/base64-TQ5KOCNW.js → chunks/base64-OLYCF2PC.js} +1 -1
  7. package/dist/bin/chunks/{cat-BQ7FQTN5.js → cat-UJLF2DU2.js} +1 -1
  8. package/dist/bin/{shell/chunks/chmod-S4ARARR4.js → chunks/chmod-V5F4BXZ2.js} +1 -1
  9. package/dist/bin/chunks/{chunk-V4S4A7M6.js → chunk-2TEF4USR.js} +1 -1
  10. package/dist/bin/chunks/{chunk-N26Y42L6.js → chunk-3M5OMKFS.js} +1 -1
  11. package/dist/bin/chunks/chunk-4NYJ4ZTO.js +17 -0
  12. package/dist/bin/{shell/chunks/chunk-M3Z5NZXT.js → chunks/chunk-572NXISH.js} +1 -1
  13. package/dist/bin/chunks/chunk-5NWK7A4R.js +13 -0
  14. package/dist/bin/{shell/chunks/chunk-YXPSX3SI.js → chunks/chunk-623Q77WZ.js} +1 -1
  15. package/dist/bin/chunks/chunk-6NG4ULJM.js +7 -0
  16. package/dist/bin/chunks/{chunk-QFOXSCOD.js → chunk-726WDFMQ.js} +1 -1
  17. package/dist/bin/chunks/{chunk-4JPWP5WS.js → chunk-AJ3CSZ34.js} +1 -1
  18. package/dist/bin/{shell/chunks/chunk-VTAMGD42.js → chunks/chunk-APEQNYAO.js} +1 -1
  19. package/dist/bin/chunks/chunk-BFLKIASG.js +7 -0
  20. package/dist/bin/chunks/{chunk-IOKQFPM6.js → chunk-BRB5PJ3E.js} +1 -1
  21. package/dist/bin/chunks/{chunk-ZVG47PYA.js → chunk-BVBYPYA5.js} +1 -1
  22. package/dist/bin/chunks/{chunk-K65FCSAT.js → chunk-BZJ77YQD.js} +1 -1
  23. package/dist/bin/{shell/chunks/chunk-GR4ZHKXI.js → chunks/chunk-C2BLJ3AE.js} +1 -1
  24. package/dist/bin/{shell/chunks/chunk-R7THHH4J.js → chunks/chunk-C45GTJTD.js} +1 -1
  25. package/dist/bin/chunks/{chunk-GOWX7VPU.js → chunk-CTS7QXCJ.js} +1 -1
  26. package/dist/bin/chunks/{chunk-42AMF6EE.js → chunk-DTNGYQCJ.js} +1 -1
  27. package/dist/bin/chunks/{chunk-TW2IJRUF.js → chunk-ENEHPI32.js} +1 -1
  28. package/dist/bin/chunks/{chunk-E54Z6VIE.js → chunk-ERYPQAZE.js} +5 -5
  29. package/dist/bin/chunks/{chunk-PQ2INDRF.js → chunk-GB3KUAFV.js} +1 -1
  30. package/dist/bin/{shell/chunks/chunk-E2O6S35K.js → chunks/chunk-HFVQCXYX.js} +1 -1
  31. package/dist/bin/chunks/{chunk-IRCAXXH6.js → chunk-HSWCKN2X.js} +1 -1
  32. package/dist/bin/chunks/{chunk-B6WWC6K3.js → chunk-I6MS5ZWE.js} +1 -1
  33. package/dist/bin/chunks/{chunk-V4U26ZWL.js → chunk-IOFXLMNJ.js} +1 -1
  34. package/dist/bin/chunks/chunk-IX6QY5JW.js +5 -0
  35. package/dist/bin/chunks/{chunk-QKJAAJ7J.js → chunk-IXTPVJ6W.js} +1 -1
  36. package/dist/bin/chunks/{chunk-OUQKFRVR.js → chunk-JBYLHCKP.js} +1 -1
  37. package/dist/bin/chunks/{chunk-NXUXZWS5.js → chunk-JLRB7DV3.js} +1 -1
  38. package/dist/bin/{shell/chunks/chunk-GKJD4ULC.js → chunks/chunk-KH6YLKPE.js} +1 -1
  39. package/dist/bin/{shell/chunks/chunk-Z3TCELKN.js → chunks/chunk-KXSDVBJA.js} +1 -1
  40. package/dist/bin/chunks/{chunk-DYIBFLS3.js → chunk-LOU52GPJ.js} +2 -2
  41. package/dist/bin/{shell/chunks/chunk-L345YZ6R.js → chunks/chunk-LVT5R45K.js} +1 -1
  42. package/dist/bin/{shell/chunks/chunk-PTUQEN6I.js → chunks/chunk-M345X45Z.js} +7 -7
  43. package/dist/bin/chunks/{chunk-MWQMHODV.js → chunk-NDS7PYKD.js} +1 -1
  44. package/dist/bin/chunks/chunk-O3PNT72D.js +3 -0
  45. package/dist/bin/chunks/chunk-OGOISDGZ.js +3 -0
  46. package/dist/bin/chunks/chunk-OSW4MDDH.js +21 -0
  47. package/dist/bin/chunks/{chunk-FPWHWWXO.js → chunk-OXV2B2YS.js} +1 -1
  48. package/dist/bin/chunks/{chunk-QMPZXXEK.js → chunk-OY25E3ZN.js} +1 -1
  49. package/dist/bin/{shell/chunks/chunk-O2BCKSMK.js → chunks/chunk-PEJXCXSY.js} +1 -1
  50. package/dist/bin/{shell/chunks/chunk-6KHZX4HU.js → chunks/chunk-PLLMJHMV.js} +1 -1
  51. package/dist/bin/{shell/chunks/chunk-6TUILMPB.js → chunks/chunk-QELDDRV5.js} +1 -1
  52. package/dist/bin/chunks/{chunk-3FQBUEB6.js → chunk-RC4UXNHA.js} +1 -1
  53. package/dist/bin/{shell/chunks/chunk-H7PD6FLC.js → chunks/chunk-RE7Z53A3.js} +1 -1
  54. package/dist/bin/chunks/chunk-SCQRBEQW.js +275 -0
  55. package/dist/bin/chunks/{chunk-3DWQCLNP.js → chunk-SS2OPV62.js} +1 -1
  56. package/dist/bin/{shell/chunks/chunk-CC2AQ6B7.js → chunks/chunk-U6JTVQU6.js} +1 -1
  57. package/dist/bin/{shell/chunks/chunk-UNCYBFWT.js → chunks/chunk-UFAYH3WW.js} +1 -1
  58. package/dist/bin/chunks/chunk-UPUFWGHR.js +3 -0
  59. package/dist/bin/{shell/chunks/chunk-HARVZWUX.js → chunks/chunk-UU42WPB7.js} +1 -1
  60. package/dist/bin/chunks/{chunk-CNVNOT67.js → chunk-UW4E5XU5.js} +1 -1
  61. package/dist/bin/{shell/chunks/chunk-F4ACJZIY.js → chunks/chunk-WLQ2KWS3.js} +1 -1
  62. package/dist/bin/chunks/{chunk-MVBK66TR.js → chunk-WPJ5CECR.js} +1 -1
  63. package/dist/bin/chunks/{chunk-ANX7U57Q.js → chunk-XBOBVLRL.js} +2 -2
  64. package/dist/bin/chunks/{chunk-HZGHQZSY.js → chunk-Z3MXFCN7.js} +1 -1
  65. package/dist/bin/chunks/{column-AJFK3TWF.js → column-AL4LR5PO.js} +1 -1
  66. package/dist/bin/chunks/{cp-WRBRHVVD.js → cp-XJWV46T5.js} +1 -1
  67. package/dist/bin/chunks/{curl-NHNZ46BU.js → curl-HZ5SBTVY.js} +11 -11
  68. package/dist/bin/chunks/{cut-42X6363P.js → cut-LNJEMWBJ.js} +1 -1
  69. package/dist/bin/chunks/dist-4NZ74CRE.js +141 -0
  70. package/dist/bin/chunks/{expr-PQEPO5TE.js → expr-GLGO2VEZ.js} +1 -1
  71. package/dist/bin/chunks/{file-JA7QI2YT.js → file-7M5LLZJY.js} +1 -1
  72. package/dist/bin/chunks/{find-T3JZPTUX.js → find-3QDGII35.js} +1 -1
  73. package/dist/bin/chunks/flag-coverage-AGEO3F6X.js +3 -0
  74. package/dist/bin/chunks/{grep-VXWNMIDD.js → grep-AZJ2CMYE.js} +1 -1
  75. package/dist/bin/chunks/{gzip-EXJSFNCU.js → gzip-W5CL2E2W.js} +1 -1
  76. package/dist/bin/{shell/chunks/head-QKVY3SIO.js → chunks/head-ABLEKDMV.js} +1 -1
  77. package/dist/bin/{shell/chunks/help-HVIDHJ6M.js → chunks/help-EXVKU23F.js} +1 -1
  78. package/dist/bin/chunks/{html-to-markdown-XUMA42ZC.js → html-to-markdown-FDNPIEKZ.js} +1 -1
  79. package/dist/bin/{shell/chunks/jq-YS4PR46D.js → chunks/jq-5SOTL7D7.js} +1 -1
  80. package/dist/bin/chunks/{js-exec-PLUMFEX6.js → js-exec-LISDW7YC.js} +1 -1
  81. package/dist/bin/chunks/js-exec-worker.js +1 -0
  82. package/dist/bin/{shell/chunks/ls-LOCOWLZ3.js → chunks/ls-EEX3YIOF.js} +1 -1
  83. package/dist/bin/chunks/mkdir-KDEZTR53.js +3 -0
  84. package/dist/bin/chunks/mktemp-OYQYUB5H.js +3 -0
  85. package/dist/bin/chunks/{mv-NAMOL2HF.js → mv-35V6IA5V.js} +1 -1
  86. package/dist/bin/chunks/{od-2GXD4D5K.js → od-TD5LZDUM.js} +1 -1
  87. package/dist/bin/{shell/chunks/paste-DWWA3JTW.js → chunks/paste-QJG6BYAP.js} +1 -1
  88. package/dist/bin/chunks/{python3-J5GXF27H.js → python3-P6MZ44HK.js} +1 -1
  89. package/dist/bin/{shell/chunks/rg-XF5U7GS2.js → chunks/rg-B2DVJQVY.js} +1 -1
  90. package/dist/bin/chunks/rm-HCMKNRM2.js +3 -0
  91. package/dist/bin/{shell/chunks/rmdir-W73C4GEA.js → chunks/rmdir-WGVUYGPF.js} +1 -1
  92. package/dist/bin/{shell/chunks/sed-SY63U2YX.js → chunks/sed-66XZQ75T.js} +1 -1
  93. package/dist/bin/chunks/{seq-X2EAOGV5.js → seq-KBVCQ4WT.js} +1 -1
  94. package/dist/bin/{shell/chunks/sleep-MOJQBZMY.js → chunks/sleep-4O22Z4DI.js} +1 -1
  95. package/dist/bin/chunks/{split-2VXPZJJ4.js → split-OK6JHDWZ.js} +1 -1
  96. package/dist/bin/chunks/sqlite3-57ACN7ES.js +3 -0
  97. package/dist/bin/chunks/{stat-LROLDXHH.js → stat-VNNI7JDZ.js} +1 -1
  98. package/dist/bin/chunks/{tail-UOTUV25D.js → tail-PAHZX3MA.js} +1 -1
  99. package/dist/bin/chunks/{tar-7XOP7VOX.js → tar-RPVTXGFJ.js} +1 -1
  100. package/dist/bin/chunks/{time-LF7BTSK5.js → time-J2DAZUIN.js} +1 -1
  101. package/dist/bin/chunks/timeout-XMTXHNFF.js +3 -0
  102. package/dist/bin/{shell/chunks/tr-PVFO6FRY.js → chunks/tr-ETPC3LHV.js} +1 -1
  103. package/dist/bin/chunks/worker.js +5 -0
  104. package/dist/bin/chunks/{xan-RMH6JEXM.js → xan-XZHKEPJ4.js} +1 -1
  105. package/dist/bin/chunks/{xan-view-PD26QEFN.js → xan-view-CNGKCABE.js} +1 -1
  106. package/dist/bin/chunks/yes-2EQTNSIB.js +3 -0
  107. package/dist/bin/chunks/yq-T6S3IDKY.js +3 -0
  108. package/dist/bin/just-bash.js +291 -286
  109. package/dist/bin/shell/chunks/awk2-LCV2AUIX.js +3 -0
  110. package/dist/bin/{chunks/base64-TQ5KOCNW.js → shell/chunks/base64-OLYCF2PC.js} +1 -1
  111. package/dist/bin/shell/chunks/{cat-BQ7FQTN5.js → cat-UJLF2DU2.js} +1 -1
  112. package/dist/bin/{chunks/chmod-S4ARARR4.js → shell/chunks/chmod-V5F4BXZ2.js} +1 -1
  113. package/dist/bin/shell/chunks/{chunk-V4S4A7M6.js → chunk-2TEF4USR.js} +1 -1
  114. package/dist/bin/shell/chunks/{chunk-N26Y42L6.js → chunk-3M5OMKFS.js} +1 -1
  115. package/dist/bin/shell/chunks/chunk-4NYJ4ZTO.js +17 -0
  116. package/dist/bin/{chunks/chunk-M3Z5NZXT.js → shell/chunks/chunk-572NXISH.js} +1 -1
  117. package/dist/bin/shell/chunks/chunk-5NWK7A4R.js +13 -0
  118. package/dist/bin/{chunks/chunk-YXPSX3SI.js → shell/chunks/chunk-623Q77WZ.js} +1 -1
  119. package/dist/bin/shell/chunks/chunk-6NG4ULJM.js +7 -0
  120. package/dist/bin/shell/chunks/{chunk-QFOXSCOD.js → chunk-726WDFMQ.js} +1 -1
  121. package/dist/bin/shell/chunks/{chunk-4JPWP5WS.js → chunk-AJ3CSZ34.js} +1 -1
  122. package/dist/bin/{chunks/chunk-VTAMGD42.js → shell/chunks/chunk-APEQNYAO.js} +1 -1
  123. package/dist/bin/shell/chunks/chunk-BFLKIASG.js +7 -0
  124. package/dist/bin/shell/chunks/{chunk-IOKQFPM6.js → chunk-BRB5PJ3E.js} +1 -1
  125. package/dist/bin/shell/chunks/{chunk-ZVG47PYA.js → chunk-BVBYPYA5.js} +1 -1
  126. package/dist/bin/shell/chunks/{chunk-K65FCSAT.js → chunk-BZJ77YQD.js} +1 -1
  127. package/dist/bin/{chunks/chunk-GR4ZHKXI.js → shell/chunks/chunk-C2BLJ3AE.js} +1 -1
  128. package/dist/bin/{chunks/chunk-R7THHH4J.js → shell/chunks/chunk-C45GTJTD.js} +1 -1
  129. package/dist/bin/shell/chunks/{chunk-GOWX7VPU.js → chunk-CTS7QXCJ.js} +1 -1
  130. package/dist/bin/shell/chunks/{chunk-42AMF6EE.js → chunk-DTNGYQCJ.js} +1 -1
  131. package/dist/bin/shell/chunks/{chunk-TW2IJRUF.js → chunk-ENEHPI32.js} +1 -1
  132. package/dist/bin/shell/chunks/{chunk-E54Z6VIE.js → chunk-ERYPQAZE.js} +5 -5
  133. package/dist/bin/shell/chunks/{chunk-PQ2INDRF.js → chunk-GB3KUAFV.js} +1 -1
  134. package/dist/bin/{chunks/chunk-E2O6S35K.js → shell/chunks/chunk-HFVQCXYX.js} +1 -1
  135. package/dist/bin/shell/chunks/{chunk-IRCAXXH6.js → chunk-HSWCKN2X.js} +1 -1
  136. package/dist/bin/shell/chunks/{chunk-B6WWC6K3.js → chunk-I6MS5ZWE.js} +1 -1
  137. package/dist/bin/shell/chunks/{chunk-V4U26ZWL.js → chunk-IOFXLMNJ.js} +1 -1
  138. package/dist/bin/shell/chunks/chunk-IX6QY5JW.js +5 -0
  139. package/dist/bin/shell/chunks/{chunk-QKJAAJ7J.js → chunk-IXTPVJ6W.js} +1 -1
  140. package/dist/bin/shell/chunks/{chunk-OUQKFRVR.js → chunk-JBYLHCKP.js} +1 -1
  141. package/dist/bin/shell/chunks/{chunk-NXUXZWS5.js → chunk-JLRB7DV3.js} +1 -1
  142. package/dist/bin/{chunks/chunk-GKJD4ULC.js → shell/chunks/chunk-KH6YLKPE.js} +1 -1
  143. package/dist/bin/{chunks/chunk-Z3TCELKN.js → shell/chunks/chunk-KXSDVBJA.js} +1 -1
  144. package/dist/bin/shell/chunks/{chunk-DYIBFLS3.js → chunk-LOU52GPJ.js} +2 -2
  145. package/dist/bin/{chunks/chunk-L345YZ6R.js → shell/chunks/chunk-LVT5R45K.js} +1 -1
  146. package/dist/bin/{chunks/chunk-PTUQEN6I.js → shell/chunks/chunk-M345X45Z.js} +7 -7
  147. package/dist/bin/shell/chunks/{chunk-MWQMHODV.js → chunk-NDS7PYKD.js} +1 -1
  148. package/dist/bin/shell/chunks/chunk-O3PNT72D.js +3 -0
  149. package/dist/bin/shell/chunks/chunk-OGOISDGZ.js +3 -0
  150. package/dist/bin/shell/chunks/chunk-OSW4MDDH.js +21 -0
  151. package/dist/bin/shell/chunks/{chunk-FPWHWWXO.js → chunk-OXV2B2YS.js} +1 -1
  152. package/dist/bin/shell/chunks/{chunk-QMPZXXEK.js → chunk-OY25E3ZN.js} +1 -1
  153. package/dist/bin/{chunks/chunk-O2BCKSMK.js → shell/chunks/chunk-PEJXCXSY.js} +1 -1
  154. package/dist/bin/{chunks/chunk-6KHZX4HU.js → shell/chunks/chunk-PLLMJHMV.js} +1 -1
  155. package/dist/bin/{chunks/chunk-6TUILMPB.js → shell/chunks/chunk-QELDDRV5.js} +1 -1
  156. package/dist/bin/shell/chunks/{chunk-3FQBUEB6.js → chunk-RC4UXNHA.js} +1 -1
  157. package/dist/bin/{chunks/chunk-H7PD6FLC.js → shell/chunks/chunk-RE7Z53A3.js} +1 -1
  158. package/dist/bin/shell/chunks/chunk-SCQRBEQW.js +275 -0
  159. package/dist/bin/shell/chunks/{chunk-3DWQCLNP.js → chunk-SS2OPV62.js} +1 -1
  160. package/dist/bin/{chunks/chunk-CC2AQ6B7.js → shell/chunks/chunk-U6JTVQU6.js} +1 -1
  161. package/dist/bin/{chunks/chunk-UNCYBFWT.js → shell/chunks/chunk-UFAYH3WW.js} +1 -1
  162. package/dist/bin/shell/chunks/chunk-UPUFWGHR.js +3 -0
  163. package/dist/bin/{chunks/chunk-HARVZWUX.js → shell/chunks/chunk-UU42WPB7.js} +1 -1
  164. package/dist/bin/shell/chunks/{chunk-CNVNOT67.js → chunk-UW4E5XU5.js} +1 -1
  165. package/dist/bin/{chunks/chunk-F4ACJZIY.js → shell/chunks/chunk-WLQ2KWS3.js} +1 -1
  166. package/dist/bin/shell/chunks/{chunk-MVBK66TR.js → chunk-WPJ5CECR.js} +1 -1
  167. package/dist/bin/shell/chunks/{chunk-ANX7U57Q.js → chunk-XBOBVLRL.js} +2 -2
  168. package/dist/bin/shell/chunks/{chunk-HZGHQZSY.js → chunk-Z3MXFCN7.js} +1 -1
  169. package/dist/bin/shell/chunks/{column-AJFK3TWF.js → column-AL4LR5PO.js} +1 -1
  170. package/dist/bin/shell/chunks/{cp-WRBRHVVD.js → cp-XJWV46T5.js} +1 -1
  171. package/dist/bin/shell/chunks/{curl-NHNZ46BU.js → curl-HZ5SBTVY.js} +11 -11
  172. package/dist/bin/shell/chunks/{cut-42X6363P.js → cut-LNJEMWBJ.js} +1 -1
  173. package/dist/bin/shell/chunks/dist-4NZ74CRE.js +141 -0
  174. package/dist/bin/shell/chunks/{expr-PQEPO5TE.js → expr-GLGO2VEZ.js} +1 -1
  175. package/dist/bin/shell/chunks/{file-JA7QI2YT.js → file-7M5LLZJY.js} +1 -1
  176. package/dist/bin/shell/chunks/{find-T3JZPTUX.js → find-3QDGII35.js} +1 -1
  177. package/dist/bin/shell/chunks/flag-coverage-AGEO3F6X.js +3 -0
  178. package/dist/bin/shell/chunks/{grep-VXWNMIDD.js → grep-AZJ2CMYE.js} +1 -1
  179. package/dist/bin/shell/chunks/{gzip-EXJSFNCU.js → gzip-W5CL2E2W.js} +1 -1
  180. package/dist/bin/{chunks/head-QKVY3SIO.js → shell/chunks/head-ABLEKDMV.js} +1 -1
  181. package/dist/bin/{chunks/help-HVIDHJ6M.js → shell/chunks/help-EXVKU23F.js} +1 -1
  182. package/dist/bin/shell/chunks/{html-to-markdown-XUMA42ZC.js → html-to-markdown-FDNPIEKZ.js} +1 -1
  183. package/dist/bin/{chunks/jq-YS4PR46D.js → shell/chunks/jq-5SOTL7D7.js} +1 -1
  184. package/dist/bin/shell/chunks/{js-exec-PLUMFEX6.js → js-exec-LISDW7YC.js} +1 -1
  185. package/dist/bin/{chunks/ls-LOCOWLZ3.js → shell/chunks/ls-EEX3YIOF.js} +1 -1
  186. package/dist/bin/shell/chunks/mkdir-KDEZTR53.js +3 -0
  187. package/dist/bin/shell/chunks/mktemp-OYQYUB5H.js +3 -0
  188. package/dist/bin/shell/chunks/{mv-NAMOL2HF.js → mv-35V6IA5V.js} +1 -1
  189. package/dist/bin/shell/chunks/{od-2GXD4D5K.js → od-TD5LZDUM.js} +1 -1
  190. package/dist/bin/{chunks/paste-DWWA3JTW.js → shell/chunks/paste-QJG6BYAP.js} +1 -1
  191. package/dist/bin/shell/chunks/{python3-J5GXF27H.js → python3-P6MZ44HK.js} +1 -1
  192. package/dist/bin/{chunks/rg-XF5U7GS2.js → shell/chunks/rg-B2DVJQVY.js} +1 -1
  193. package/dist/bin/shell/chunks/rm-HCMKNRM2.js +3 -0
  194. package/dist/bin/{chunks/rmdir-W73C4GEA.js → shell/chunks/rmdir-WGVUYGPF.js} +1 -1
  195. package/dist/bin/{chunks/sed-SY63U2YX.js → shell/chunks/sed-66XZQ75T.js} +1 -1
  196. package/dist/bin/shell/chunks/{seq-X2EAOGV5.js → seq-KBVCQ4WT.js} +1 -1
  197. package/dist/bin/{chunks/sleep-MOJQBZMY.js → shell/chunks/sleep-4O22Z4DI.js} +1 -1
  198. package/dist/bin/shell/chunks/{split-2VXPZJJ4.js → split-OK6JHDWZ.js} +1 -1
  199. package/dist/bin/shell/chunks/sqlite3-57ACN7ES.js +3 -0
  200. package/dist/bin/shell/chunks/{stat-LROLDXHH.js → stat-VNNI7JDZ.js} +1 -1
  201. package/dist/bin/shell/chunks/{tail-UOTUV25D.js → tail-PAHZX3MA.js} +1 -1
  202. package/dist/bin/shell/chunks/{tar-7XOP7VOX.js → tar-RPVTXGFJ.js} +1 -1
  203. package/dist/bin/shell/chunks/{time-LF7BTSK5.js → time-J2DAZUIN.js} +1 -1
  204. package/dist/bin/shell/chunks/timeout-XMTXHNFF.js +3 -0
  205. package/dist/bin/{chunks/tr-PVFO6FRY.js → shell/chunks/tr-ETPC3LHV.js} +1 -1
  206. package/dist/bin/shell/chunks/{xan-RMH6JEXM.js → xan-XZHKEPJ4.js} +1 -1
  207. package/dist/bin/shell/chunks/{xan-view-PD26QEFN.js → xan-view-CNGKCABE.js} +1 -1
  208. package/dist/bin/shell/chunks/yes-2EQTNSIB.js +3 -0
  209. package/dist/bin/shell/chunks/yq-T6S3IDKY.js +3 -0
  210. package/dist/bin/shell/shell.js +337 -332
  211. package/dist/browser.d.ts +1 -1
  212. package/dist/bundle/browser.js +741 -730
  213. package/dist/bundle/chunks/awk2-TLK6FCHV.js +2 -0
  214. package/dist/bundle/chunks/{base64-MHVQ5XHI.js → base64-GUZMZ645.js} +1 -1
  215. package/dist/bundle/chunks/{cat-VZBWBIJB.js → cat-LG4YGKUE.js} +1 -1
  216. package/dist/bundle/chunks/{chmod-KMFNCMRX.js → chmod-XUKPG2M4.js} +1 -1
  217. package/dist/bundle/chunks/{chunk-WNH3HOQA.js → chunk-353VO5TF.js} +1 -1
  218. package/dist/bundle/chunks/{chunk-O5OYOY3C.js → chunk-37UJACD6.js} +1 -1
  219. package/dist/bundle/chunks/{chunk-MMXJJCAE.js → chunk-3LGQ6XEC.js} +1 -1
  220. package/dist/bundle/chunks/{chunk-P57S6Z6R.js → chunk-3ZY5QX3G.js} +1 -1
  221. package/dist/bundle/chunks/{chunk-5KOWUQOZ.js → chunk-4VU4IF3W.js} +1 -1
  222. package/dist/bundle/chunks/{chunk-SIOONII3.js → chunk-52W2IWA7.js} +1 -1
  223. package/dist/bundle/chunks/chunk-5IB57TIJ.js +274 -0
  224. package/dist/bundle/chunks/chunk-5J4S2LP5.js +2 -0
  225. package/dist/bundle/chunks/{chunk-PCPW54JH.js → chunk-5LDRJ22P.js} +1 -1
  226. package/dist/bundle/chunks/{chunk-BKUWXPEM.js → chunk-654CJKE3.js} +1 -1
  227. package/dist/bundle/chunks/{chunk-EZNS4GF7.js → chunk-67ODVGSB.js} +1 -1
  228. package/dist/bundle/chunks/{chunk-6QF3PCMO.js → chunk-6HQQON3N.js} +1 -1
  229. package/dist/bundle/chunks/{chunk-U57DSHID.js → chunk-6P2DITXT.js} +1 -1
  230. package/dist/bundle/chunks/{chunk-THDUQVY3.js → chunk-74IR77AZ.js} +1 -1
  231. package/dist/bundle/chunks/{chunk-S3ENGQML.js → chunk-7DVD6YCI.js} +1 -1
  232. package/dist/bundle/chunks/{chunk-HXWB4Z5X.js → chunk-7II7XIVI.js} +1 -1
  233. package/dist/bundle/chunks/{chunk-AYSZ5MAE.js → chunk-A3C4Z3Q3.js} +1 -1
  234. package/dist/bundle/chunks/chunk-A6SU3BZX.js +6 -0
  235. package/dist/bundle/chunks/{chunk-5NUTFEEG.js → chunk-AMXNXHXK.js} +1 -1
  236. package/dist/bundle/chunks/{chunk-QJ7OXJAZ.js → chunk-BLG7RWH4.js} +1 -1
  237. package/dist/bundle/chunks/{chunk-XQ2ZZFO6.js → chunk-BQTWRHZR.js} +2 -2
  238. package/dist/bundle/chunks/{chunk-6IFH67ZB.js → chunk-BZ2OMW2T.js} +1 -1
  239. package/dist/bundle/chunks/{chunk-CH7SUFFO.js → chunk-CORCIYJD.js} +1 -1
  240. package/dist/bundle/chunks/{chunk-LGIJSCWH.js → chunk-EQDVNHQS.js} +1 -1
  241. package/dist/bundle/chunks/{chunk-U4K5ZDWK.js → chunk-EZEO6MFE.js} +1 -1
  242. package/dist/bundle/chunks/{chunk-4CDTAUYP.js → chunk-EZT6M2HG.js} +1 -1
  243. package/dist/bundle/chunks/{chunk-4MJ7VJG4.js → chunk-H7UVJSZR.js} +1 -1
  244. package/dist/bundle/chunks/{chunk-5EI7WSRV.js → chunk-HYQGYXGZ.js} +1 -1
  245. package/dist/bundle/chunks/{chunk-6IA4DXG2.js → chunk-IPKSYZ3R.js} +1 -1
  246. package/dist/bundle/chunks/{chunk-TLPMB3FO.js → chunk-KJBPGFZD.js} +1 -1
  247. package/dist/bundle/chunks/chunk-L7NEGEOJ.js +16 -0
  248. package/dist/bundle/chunks/{chunk-YFFU74KY.js → chunk-MJEJ7QEY.js} +1 -1
  249. package/dist/bundle/chunks/{chunk-QJFYYEFV.js → chunk-N36I27VM.js} +1 -1
  250. package/dist/bundle/chunks/chunk-N5L7E4EL.js +6 -0
  251. package/dist/bundle/chunks/{chunk-IXFQXNL4.js → chunk-NFW4YKDO.js} +1 -1
  252. package/dist/bundle/chunks/{chunk-PASYAXFP.js → chunk-NOX3PCUH.js} +1 -1
  253. package/dist/bundle/chunks/{chunk-MQKGGNPS.js → chunk-NXBUT5V2.js} +2 -2
  254. package/dist/bundle/chunks/{chunk-4KZT23KR.js → chunk-O5BHWBYH.js} +1 -1
  255. package/dist/bundle/chunks/{chunk-DVSA72LH.js → chunk-QTL2XC4B.js} +1 -1
  256. package/dist/bundle/chunks/chunk-RK2WBVP4.js +2 -0
  257. package/dist/bundle/chunks/{chunk-BLPYR4TN.js → chunk-RVBBGZ22.js} +1 -1
  258. package/dist/bundle/chunks/{chunk-PS2RJNZZ.js → chunk-SXQJYLP7.js} +1 -1
  259. package/dist/bundle/chunks/{chunk-FXAKF2QS.js → chunk-T7OAZEXT.js} +1 -1
  260. package/dist/bundle/chunks/{chunk-O452S4KX.js → chunk-URIKBXSE.js} +1 -1
  261. package/dist/bundle/chunks/{chunk-6BSOPPZH.js → chunk-UVQC75LS.js} +7 -7
  262. package/dist/bundle/chunks/chunk-VCREDMWH.js +4 -0
  263. package/dist/bundle/chunks/{chunk-DDPD7SIB.js → chunk-VQ6EUBJ3.js} +1 -1
  264. package/dist/bundle/chunks/{chunk-4OKRFRMS.js → chunk-VQEB6E2M.js} +1 -1
  265. package/dist/bundle/chunks/{chunk-R2FBRMDU.js → chunk-VWUMR4IC.js} +1 -1
  266. package/dist/bundle/chunks/{chunk-XXBIOG4R.js → chunk-WDY2TNMK.js} +1 -1
  267. package/dist/bundle/chunks/{chunk-H4AFUSSQ.js → chunk-XT7EK6BR.js} +1 -1
  268. package/dist/bundle/chunks/{chunk-BS6EJR2R.js → chunk-XUTEQMTL.js} +5 -5
  269. package/dist/bundle/chunks/{chunk-KIGPB52X.js → chunk-XZ34OGNM.js} +1 -1
  270. package/dist/bundle/chunks/chunk-YUITEK6N.js +12 -0
  271. package/dist/bundle/chunks/chunk-YZCPEJRE.js +20 -0
  272. package/dist/bundle/chunks/chunk-ZUEPJPYA.js +2 -0
  273. package/dist/bundle/chunks/{column-QJI65SH2.js → column-T4LGMRJG.js} +1 -1
  274. package/dist/bundle/chunks/{cp-P2D2L6PC.js → cp-ZDDVNITX.js} +1 -1
  275. package/dist/bundle/chunks/{curl-K4WT7UPN.js → curl-RCRD36LD.js} +11 -11
  276. package/dist/bundle/chunks/{cut-FMDNVWQN.js → cut-35WER2E2.js} +1 -1
  277. package/dist/bundle/chunks/{expr-A5XITHQD.js → expr-KSNRNE7V.js} +1 -1
  278. package/dist/bundle/chunks/{file-6AYYTULJ.js → file-XH37HMGV.js} +1 -1
  279. package/dist/bundle/chunks/{find-IUWEB4XQ.js → find-3AONTPPM.js} +1 -1
  280. package/dist/bundle/chunks/flag-coverage-6YGO7STE.js +2 -0
  281. package/dist/bundle/chunks/{grep-Q2O5EIXQ.js → grep-WW5KJPUG.js} +1 -1
  282. package/dist/bundle/chunks/{gzip-VUJBDHZ5.js → gzip-ISZXQNJJ.js} +1 -1
  283. package/dist/bundle/chunks/{head-6UIPFWVJ.js → head-VYXZQLPZ.js} +1 -1
  284. package/dist/bundle/chunks/{help-QDDMBDU7.js → help-62M75TSG.js} +1 -1
  285. package/dist/bundle/chunks/{html-to-markdown-PE6BPRPA.js → html-to-markdown-4LXS3A44.js} +1 -1
  286. package/dist/bundle/chunks/{jq-UKAA3QWU.js → jq-3IVOWP3G.js} +1 -1
  287. package/dist/bundle/chunks/{js-exec-6RW7WZCG.js → js-exec-T2WEE4KG.js} +1 -1
  288. package/dist/bundle/chunks/js-exec-worker.js +1 -0
  289. package/dist/bundle/chunks/{ls-ECKG2XHZ.js → ls-FC3CSHKE.js} +1 -1
  290. package/dist/bundle/chunks/mkdir-DPFWDY25.js +2 -0
  291. package/dist/bundle/chunks/mktemp-SW2AHXZW.js +2 -0
  292. package/dist/bundle/chunks/{mv-IF55A2UD.js → mv-PWCFXEF2.js} +1 -1
  293. package/dist/bundle/chunks/{od-Z4AIL3P4.js → od-VJ6PBBEI.js} +1 -1
  294. package/dist/bundle/chunks/{paste-ZNHNSRBW.js → paste-TIQETHSO.js} +1 -1
  295. package/dist/bundle/chunks/{python3-XHTOW7VA.js → python3-6JEP7ZZK.js} +1 -1
  296. package/dist/bundle/chunks/{rg-E6H2HACA.js → rg-2OPJ5V3D.js} +1 -1
  297. package/dist/bundle/chunks/rm-AZZM5DCE.js +2 -0
  298. package/dist/bundle/chunks/{rmdir-WKKBLZ54.js → rmdir-YXYSZD4X.js} +1 -1
  299. package/dist/bundle/chunks/{sed-6G32B25J.js → sed-HYSBLGO5.js} +1 -1
  300. package/dist/bundle/chunks/{seq-B6KDLMYQ.js → seq-M2S4FRN4.js} +1 -1
  301. package/dist/bundle/chunks/{sleep-25QUPVDK.js → sleep-YC4HFEGC.js} +1 -1
  302. package/dist/bundle/chunks/{split-NEU2K2YN.js → split-UOPIWKKE.js} +1 -1
  303. package/dist/bundle/chunks/sqlite3-XCROTL6G.js +2 -0
  304. package/dist/bundle/chunks/{stat-LXFZND2P.js → stat-I3FPUTR7.js} +1 -1
  305. package/dist/bundle/chunks/{tail-UBGSN4JF.js → tail-WK3WACZK.js} +1 -1
  306. package/dist/bundle/chunks/{tar-LE7LAAIX.js → tar-VZYMNZV2.js} +1 -1
  307. package/dist/bundle/chunks/{time-NERE2JJ2.js → time-N6J6DC6C.js} +1 -1
  308. package/dist/bundle/chunks/timeout-UDR5J2MP.js +2 -0
  309. package/dist/bundle/chunks/{tr-UI2LA3GA.js → tr-VI5PIA4A.js} +1 -1
  310. package/dist/bundle/chunks/worker.js +5 -0
  311. package/dist/bundle/chunks/{xan-UIL24CGT.js → xan-DL576EIT.js} +1 -1
  312. package/dist/bundle/chunks/xan-view-GJVN6IHX.js +2 -0
  313. package/dist/bundle/chunks/yes-OVJMX6NM.js +2 -0
  314. package/dist/bundle/chunks/yq-KYPU4LQP.js +2 -0
  315. package/dist/bundle/index.cjs +1079 -1068
  316. package/dist/bundle/index.js +336 -331
  317. package/dist/commands/mktemp/mktemp.d.ts +4 -0
  318. package/dist/commands/registry.d.ts +1 -1
  319. package/dist/commands/yes/yes.d.ts +4 -0
  320. package/dist/custom-commands.d.ts +7 -0
  321. package/dist/fs/create-exclusive.d.ts +30 -0
  322. package/dist/fs/in-memory-fs/in-memory-fs.d.ts +8 -1
  323. package/dist/fs/interface.d.ts +37 -0
  324. package/dist/fs/mountable-fs/mountable-fs.d.ts +18 -1
  325. package/dist/fs/overlay-fs/overlay-fs.d.ts +19 -1
  326. package/dist/fs/read-write-fs/read-write-fs.d.ts +22 -1
  327. package/dist/index.d.cts +1 -1
  328. package/dist/index.d.ts +1 -1
  329. package/dist/interpreter/expansion/array-prefix-suffix.d.ts +2 -1
  330. package/dist/interpreter/expansion/parameter-ops.d.ts +1 -0
  331. package/dist/interpreter/expansion/pattern-removal.d.ts +3 -0
  332. package/dist/interpreter/expansion/variable.d.ts +1 -1
  333. package/dist/interpreter/helpers/loop.d.ts +32 -0
  334. package/dist/network/dns-pin.d.ts +1 -32
  335. package/dist/network/fetch.d.ts +1 -1
  336. package/dist/security/trusted-globals.d.ts +8 -0
  337. package/package.json +3 -4
  338. package/dist/bin/chunks/awk2-NTRVFXRA.js +0 -3
  339. package/dist/bin/chunks/chunk-3PCPQIUD.js +0 -3
  340. package/dist/bin/chunks/chunk-HWI42GQO.js +0 -7
  341. package/dist/bin/chunks/chunk-I57EACSL.js +0 -3
  342. package/dist/bin/chunks/chunk-NSI6LMDS.js +0 -16
  343. package/dist/bin/chunks/chunk-ONF4KUYV.js +0 -13
  344. package/dist/bin/chunks/chunk-PRVPFKTC.js +0 -276
  345. package/dist/bin/chunks/chunk-U5JLGI56.js +0 -21
  346. package/dist/bin/chunks/dist-5MWO25Y4.js +0 -141
  347. package/dist/bin/chunks/flag-coverage-LVKHEUTL.js +0 -3
  348. package/dist/bin/chunks/mkdir-VHLJ3E65.js +0 -3
  349. package/dist/bin/chunks/rm-L4RHENMV.js +0 -3
  350. package/dist/bin/chunks/sqlite3-3S5HIA5W.js +0 -3
  351. package/dist/bin/chunks/timeout-RQOWSWYG.js +0 -3
  352. package/dist/bin/chunks/yq-CWBZMGUV.js +0 -3
  353. package/dist/bin/shell/chunks/awk2-NTRVFXRA.js +0 -3
  354. package/dist/bin/shell/chunks/chunk-3PCPQIUD.js +0 -3
  355. package/dist/bin/shell/chunks/chunk-HWI42GQO.js +0 -7
  356. package/dist/bin/shell/chunks/chunk-I57EACSL.js +0 -3
  357. package/dist/bin/shell/chunks/chunk-NSI6LMDS.js +0 -16
  358. package/dist/bin/shell/chunks/chunk-ONF4KUYV.js +0 -13
  359. package/dist/bin/shell/chunks/chunk-PRVPFKTC.js +0 -276
  360. package/dist/bin/shell/chunks/chunk-U5JLGI56.js +0 -21
  361. package/dist/bin/shell/chunks/dist-5MWO25Y4.js +0 -141
  362. package/dist/bin/shell/chunks/flag-coverage-LVKHEUTL.js +0 -3
  363. package/dist/bin/shell/chunks/mkdir-VHLJ3E65.js +0 -3
  364. package/dist/bin/shell/chunks/rm-L4RHENMV.js +0 -3
  365. package/dist/bin/shell/chunks/sqlite3-3S5HIA5W.js +0 -3
  366. package/dist/bin/shell/chunks/timeout-RQOWSWYG.js +0 -3
  367. package/dist/bin/shell/chunks/yq-CWBZMGUV.js +0 -3
  368. package/dist/bundle/chunks/awk2-VS5QVYHU.js +0 -2
  369. package/dist/bundle/chunks/chunk-35MBA3VY.js +0 -12
  370. package/dist/bundle/chunks/chunk-4WRO2G22.js +0 -15
  371. package/dist/bundle/chunks/chunk-BRJERIF4.js +0 -2
  372. package/dist/bundle/chunks/chunk-FTET43KM.js +0 -2
  373. package/dist/bundle/chunks/chunk-GRUZ4SBY.js +0 -275
  374. package/dist/bundle/chunks/chunk-Y6JBSHCM.js +0 -20
  375. package/dist/bundle/chunks/chunk-ZBUZKIPX.js +0 -6
  376. package/dist/bundle/chunks/flag-coverage-SZ4AUPRQ.js +0 -2
  377. package/dist/bundle/chunks/mkdir-YL7XGMD7.js +0 -2
  378. package/dist/bundle/chunks/rm-CWLMERIO.js +0 -2
  379. package/dist/bundle/chunks/sqlite3-KJ5NMKBM.js +0 -2
  380. package/dist/bundle/chunks/timeout-37GM7IIL.js +0 -2
  381. package/dist/bundle/chunks/xan-view-FOCYCKZQ.js +0 -2
  382. package/dist/bundle/chunks/yq-ZRNZKDLE.js +0 -2
@@ -1,57 +1,60 @@
1
1
  #!/usr/bin/env node
2
2
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{a as On,b as _n,c as Zt}from"./chunks/chunk-O2BCKSMK.js";import{b as vt,c as Aa,d as va,e as xa}from"./chunks/chunk-AQKIHX3Q.js";import{a as _r}from"./chunks/chunk-3PCPQIUD.js";import{c as ri,e as Sa}from"./chunks/chunk-TW2IJRUF.js";import{a as ga,b as wa,d as Jn,e as er}from"./chunks/chunk-QKJAAJ7J.js";import{a as Gt}from"./chunks/chunk-K27FY3ES.js";import{a as Ht,b as je,c as ni}from"./chunks/chunk-MROECM42.js";import{a as nr,b as ba}from"./chunks/chunk-42AMF6EE.js";import{a as me}from"./chunks/chunk-YXPSX3SI.js";import{a as Fr,b as Mr}from"./chunks/chunk-GR4ZHKXI.js";import{a as Or,b as Te}from"./chunks/chunk-HWI42GQO.js";import"./chunks/chunk-YERKK5B3.js";import{c as qt,d as Nn}from"./chunks/chunk-I57EACSL.js";import"./chunks/chunk-7JZKVC3F.js";import{a as tr,b as ht,c as jt,d as Br,e as U,f as Tt,g as X,h as Rn,i as Dn,j as Ea,k as Ft,l as In}from"./chunks/chunk-UBA7DOWE.js";import{a as Vt,b as Qe,c as Ke,d as _e,e as ze,f as Ue,g as q,h as le,i as Xe,j as zt,k as Lr,l as P,m as Ye,n as Pe,o as Ut,p as Tr,q as st}from"./chunks/chunk-FUT3X2GJ.js";import{a as B,c as yn,e as Cn,f as Wt,g as ti}from"./chunks/chunk-CPKBPQ2C.js";import{a as N,c as it}from"./chunks/chunk-OHFB3M3X.js";import{a as qe}from"./chunks/chunk-PBOVSFTJ.js";import{a as Lt}from"./chunks/chunk-I4IRHQDW.js";import"./chunks/chunk-DN2YCFOR.js";import{resolve as td}from"node:path";var Ln=[{name:"echo",load:async()=>(await import("./chunks/echo-NYDCCFWB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-BQ7FQTN5.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-YXCSED2H.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-LOCOWLZ3.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-VHLJ3E65.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-W73C4GEA.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-TVQAUQOG.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-L4RHENMV.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-WRBRHVVD.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-NAMOL2HF.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-XVC53673.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-S4ARARR4.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-YKLNXWZI.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-BF435HNQ.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-QKVY3SIO.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-UOTUV25D.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-3KLVOCI2.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-LROLDXHH.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-VXWNMIDD.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-VXWNMIDD.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-VXWNMIDD.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-XF5U7GS2.js")).rgCommand,handlesOwnVersion:!0},{name:"sed",load:async()=>(await import("./chunks/sed-SY63U2YX.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-NTRVFXRA.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-HBOCBBJQ.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-JMHDIJXT.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-URDMZCXL.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-42X6363P.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-DWWA3JTW.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-PVFO6FRY.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-CZTQCNOZ.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-4IZRRT7U.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-YEY7X54W.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-IQRKKT7D.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-JPOQORZF.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-CNUK76JL.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-2VXPZJJ4.js")).split},{name:"column",load:async()=>(await import("./chunks/column-AJFK3TWF.js")).column},{name:"join",load:async()=>(await import("./chunks/join-34DX7YK5.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-L4HKV5PD.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-T3JZPTUX.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-YNAJTGCR.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-4AMMXFXL.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-YS4PR46D.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-TQ5KOCNW.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-YLVT27CZ.js")).diffCommand,handlesOwnVersion:!0},{name:"date",load:async()=>(await import("./chunks/date-6MQGVWDY.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-MOJQBZMY.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-RQOWSWYG.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-LF7BTSK5.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-X2EAOGV5.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-PQEPO5TE.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-JA7QI2YT.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-XUMA42ZC.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-HVIDHJ6M.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-G7X54RZL.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-2GXD4D5K.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-EXJSFNCU.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-EXJSFNCU.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-EXJSFNCU.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ln.push({name:"tar",load:async()=>(await import("./chunks/tar-7XOP7VOX.js")).tarCommand}),Ln.push({name:"yq",load:async()=>(await import("./chunks/yq-CWBZMGUV.js")).yqCommand}),Ln.push({name:"xan",load:async()=>(await import("./chunks/xan-RMH6JEXM.js")).xanCommand}),Ln.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-3S5HIA5W.js")).sqlite3Command}));var si=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(si.push({name:"python3",load:async()=>(await import("./chunks/python3-J5GXF27H.js")).python3Command,handlesOwnVersion:!0}),si.push({name:"python",load:async()=>(await import("./chunks/python3-J5GXF27H.js")).pythonCommand,handlesOwnVersion:!0}));var ii=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(ii.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-PLUMFEX6.js")).jsExecCommand,handlesOwnVersion:!0}),ii.push({name:"node",load:async()=>(await import("./chunks/js-exec-PLUMFEX6.js")).nodeStubCommand}));var sd=[{name:"curl",load:async()=>(await import("./chunks/curl-NHNZ46BU.js")).curlCommand}],ka=new Map;function Wr(e){return{name:e.name,handlesOwnVersion:e.handlesOwnVersion,async execute(t,n){let r=ka.get(e.name);if(r||(r=await Te.runTrustedAsync(()=>e.load()),ka.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await import("./chunks/flag-coverage-LVKHEUTL.js");s(n.coverage,e.name,t)}return r.execute(t,n)}}}function $a(e){return(e?Ln.filter(n=>e.includes(n.name)):Ln).map(Wr)}function Pa(){return sd.map(Wr)}function Ca(){return si.map(Wr)}function Na(){return ii.map(Wr)}var Ra=new WeakMap,Da=new WeakSet;function oi(e){let t=Ra.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),Ra.set(e,t),Da.add(t)),t}function Ia(e){return Da.has(e)}var Oa={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,maxJsMemoryBytes:67108864,maxGlobOperations:1e6,maxStringLength:67108864,maxArrayElements:1e6,maxHeredocSize:67108864,maxSubstitutionDepth:50,maxBraceExpansionResults:1e5,maxOutputSize:268435456,maxFileDescriptors:4096,maxSourceDepth:100},id={...Oa,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 od(e){return Number.isFinite(e)?Math.min(Math.max(0,Math.floor(e)),4294967295):4294967295}function ai(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?id:Oa;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,maxJsMemoryBytes:od(e.maxJsMemoryBytes??n.maxJsMemoryBytes),maxGlobOperations:e.maxGlobOperations??n.maxGlobOperations,maxStringLength:e.maxStringLength??n.maxStringLength,maxArrayElements:e.maxArrayElements??n.maxArrayElements,maxHeredocSize:e.maxHeredocSize??n.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??n.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??n.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??n.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??n.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??n.maxSourceDepth};for(let s of Object.keys(r)){let i=r[s];if(i!==Number.POSITIVE_INFINITY&&(!Number.isSafeInteger(i)||i<0))throw new RangeError(`${s} must be a non-negative safe integer or positive Infinity`)}return r}function _a(e){return"load"in e&&typeof e.load=="function"}function La(e){let t=null,n=null;return{name:e.name,trusted:e.trusted!==!1,handlesOwnVersion:e.handlesOwnVersion,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 Ta=Object.freeze(Object.create(null)),Vr=class{limits;signal;abortOnUnresolvedCommands;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();unresolvedCommands=new Set;get remainingLiveBytes(){return Math.max(0,this.limits.maxLiveBytes-this.liveBytes)}get outputBytesUsed(){return this.outputBytes}constructor(t,n=void 0,r=!1){this.limits=t,this.signal=n,this.abortOnUnresolvedCommands=r}recordUnresolvedCommand(t){this.unresolvedCommands.add(t)}get unresolvedCommandNames(){return[...this.unresolvedCommands]}fail(t){throw this.poisoned??=t,this.poisoned}poisonAfterAbort(t){this.poisoned??=t}assertUsable(){if(this.poisoned)throw this.poisoned;if(this.closed)throw new Error("execution budget is already closed");this.throwIfAborted()}chargeCommand(){return this.consume("commands",1,"execution")}consumeWork(t=1,n="execution"){return this.consume("work",t,n)}consumeLimited(t,n,r,s=t){this.assertUsable();let i=this.countersByKind.get(t)??0;return(!Number.isSafeInteger(n)||n<0||!Number.isSafeInteger(r)||r<0||n>r-i)&&this.fail(new P(`${s}: ${t} work limit exceeded (${r})`,"iterations")),n>this.limits.maxWorkUnits-this.workUnits&&this.fail(new P(`${s}: aggregate work limit exceeded (${this.limits.maxWorkUnits})`,"iterations")),this.countersByKind.set(t,i+n),this.workUnits+=n,i+n}consumeInput(t,n="execution"){return this.assertUsable(),(!Number.isSafeInteger(t)||t<0||t>this.limits.maxInputBytes-this.inputBytes)&&this.fail(new P(`${n}: aggregate input size limit exceeded (${this.limits.maxInputBytes} bytes)`,"string_length")),this.inputBytes+=t,this.inputBytes}consume(t,n=1,r=t){this.assertUsable();let s=this.countersByKind.get(t)??0,i=t==="commands"?this.commandCount:this.workUnits,o=t==="commands"?this.limits.maxCommandCount:this.limits.maxWorkUnits;(!Number.isSafeInteger(n)||n<0||n>o-i)&&this.fail(new P(t==="commands"?`too many commands executed (>${o}), increase executionLimits.maxCommandCount`:`${r}: ${t} work limit exceeded (${o})`,t==="commands"?"commands":"iterations"));let a=i+n;return t==="commands"?this.commandCount=a:this.workUnits=a,this.countersByKind.set(t,s+n),a}reserveBytes(t,n,r){this.assertUsable();let s=typeof t=="string"?t:"live",i=typeof t=="string"?n:t,o=typeof t=="string"?r??s:n??"execution";(!Number.isSafeInteger(i)||i<0||i>this.limits.maxLiveBytes-this.liveBytes)&&this.fail(new P(`${o}: live byte limit exceeded (${this.limits.maxLiveBytes} bytes)`,"string_length")),this.liveBytes+=i,this.bytesByKind.set(s,(this.bytesByKind.get(s)??0)+i);let a=!1;return{release:()=>{if(a)return;a=!0,this.liveBytes-=i;let l=(this.bytesByKind.get(s)??i)-i;l<=0?this.bytesByKind.delete(s):this.bytesByKind.set(s,l)}}}appendOutput(t,n,r="execution",s=0,i="text"){this.assertUsable();let o=i==="bytes"?n.length:B(n);(!Number.isSafeInteger(s)||s<0||s>o)&&this.fail(new P(`${r}: invalid ${t} accounting`,"output_size"));let a=o-s;return a>this.limits.maxOutputSize-this.outputBytes&&this.fail(new P(`${r}: total output size exceeded (>${this.limits.maxOutputSize} bytes), increase executionLimits.maxOutputSize`,"output_size")),this.outputBytes+=a,o}accountResult(t,n="execution",r=Number.POSITIVE_INFINITY){let s=t.internalOutputAccounting,i=Math.min(s?.stdout??0,r),o=Math.min(s?.stderr??0,Math.max(0,r-i)),a=this.appendOutput("stdout",t.stdout,n,i,t.stdoutKind==="bytes"||t.stdoutEncoding==="binary"?"bytes":"text"),l=this.appendOutput("stderr",t.stderr,n,o);return Object.isExtensible(t)?(t.internalOutputAccounting={stdout:a,stderr:l},t):a===0&&l===0?t:{...t,internalOutputAccounting:{stdout:a,stderr:l}}}relinquishOutput(t,n,r){this.assertUsable(),r!==Ta&&this.fail(new P(`${n}: unauthorized output accounting release`,"output_size")),(!Number.isSafeInteger(t)||t<0||t>this.outputBytes)&&this.fail(new P(`${n}: invalid output accounting release`,"output_size")),this.outputBytes-=t}enterDepth(t,n=this.limits.maxCallDepth,r){this.assertUsable();let s=typeof n=="number"?n:this.limits.maxCallDepth,i=typeof n=="string"?n:r??t,o=this.depthByKind.get(t)??0;o>=s&&this.fail(new P(`${i}: maximum depth (${s}) exceeded`,"recursion")),this.depthByKind.set(t,o+1);let a=!1;return{release:()=>{if(a)return;a=!0;let l=(this.depthByKind.get(t)??1)-1;l<=0?this.depthByKind.delete(t):this.depthByKind.set(t,l)}}}throwIfAborted(t="execution"){this.signal?.aborted&&this.fail(new Ye("",`bash: ${t} aborted
3
+ import{a as Ln,b as Tn,c as Qt}from"./chunks/chunk-PEJXCXSY.js";import{b as kt,c as Ra,d as Da,e as Ia}from"./chunks/chunk-AQKIHX3Q.js";import{a as Br,b as sr}from"./chunks/chunk-OGOISDGZ.js";import{a as va,b as xa,d as nr,e as rr}from"./chunks/chunk-IXTPVJ6W.js";import{c as ai,e as Ca,f as Na}from"./chunks/chunk-ENEHPI32.js";import{a as Zt}from"./chunks/chunk-K27FY3ES.js";import{a as Gt,b as je,c as oi}from"./chunks/chunk-MROECM42.js";import{a as or,b as Pa}from"./chunks/chunk-DTNGYQCJ.js";import{a as me}from"./chunks/chunk-623Q77WZ.js";import{a as Wr,b as Vr}from"./chunks/chunk-C2BLJ3AE.js";import{a as Tr,b as Te}from"./chunks/chunk-BFLKIASG.js";import"./chunks/chunk-YERKK5B3.js";import{d as jt,e as In}from"./chunks/chunk-O3PNT72D.js";import"./chunks/chunk-7JZKVC3F.js";import{a as $a}from"./chunks/chunk-UPUFWGHR.js";import{a as ir,b as mt,c as Ht,d as zr,e as z,f as Mt,g as K,h as yt,i as On,j as ka,k as ot,l as _n}from"./chunks/chunk-UBA7DOWE.js";import{a as zt,b as Qe,c as Ke,d as _e,e as ze,f as Ue,g as q,h as ae,i as Xe,j as Ut,k as Fr,l as P,m as Ye,n as Pe,o as qt,p as Mr,q as st}from"./chunks/chunk-FUT3X2GJ.js";import{a as M,c as wn,e as Dn,f as Vt,g as ii}from"./chunks/chunk-CPKBPQ2C.js";import{a as N,c as it}from"./chunks/chunk-OHFB3M3X.js";import{a as Ft}from"./chunks/chunk-I4IRHQDW.js";import{a as qe}from"./chunks/chunk-PBOVSFTJ.js";import"./chunks/chunk-DN2YCFOR.js";import{resolve as ld}from"node:path";var Fn=[{name:"echo",load:async()=>(await import("./chunks/echo-NYDCCFWB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-UJLF2DU2.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-YXCSED2H.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-EEX3YIOF.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-KDEZTR53.js")).mkdirCommand},{name:"mktemp",load:async()=>(await import("./chunks/mktemp-OYQYUB5H.js")).mktempCommand,handlesOwnVersion:!0},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-WGVUYGPF.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-TVQAUQOG.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-HCMKNRM2.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-XJWV46T5.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-35V6IA5V.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-XVC53673.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-V5F4BXZ2.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-YKLNXWZI.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-BF435HNQ.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-ABLEKDMV.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-PAHZX3MA.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-3KLVOCI2.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-VNNI7JDZ.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-AZJ2CMYE.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-AZJ2CMYE.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-AZJ2CMYE.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-B2DVJQVY.js")).rgCommand,handlesOwnVersion:!0},{name:"sed",load:async()=>(await import("./chunks/sed-66XZQ75T.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-LCV2AUIX.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-HBOCBBJQ.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-JMHDIJXT.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-URDMZCXL.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-LNJEMWBJ.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-QJG6BYAP.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-ETPC3LHV.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-CZTQCNOZ.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-4IZRRT7U.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-YEY7X54W.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-IQRKKT7D.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-JPOQORZF.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-CNUK76JL.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-OK6JHDWZ.js")).split},{name:"column",load:async()=>(await import("./chunks/column-AL4LR5PO.js")).column},{name:"join",load:async()=>(await import("./chunks/join-34DX7YK5.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-L4HKV5PD.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-3QDGII35.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-YNAJTGCR.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-4AMMXFXL.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).falseCommand},{name:"yes",load:async()=>(await import("./chunks/yes-2EQTNSIB.js")).yesCommand},{name:"clear",load:async()=>(await import("./chunks/clear-OE52K3TM.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-CFCBBWVH.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-CFCBBWVH.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-5SOTL7D7.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-OLYCF2PC.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-YLVT27CZ.js")).diffCommand,handlesOwnVersion:!0},{name:"date",load:async()=>(await import("./chunks/date-6MQGVWDY.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-4O22Z4DI.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-XMTXHNFF.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-J2DAZUIN.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-KBVCQ4WT.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-GLGO2VEZ.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-7M5LLZJY.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-FDNPIEKZ.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-EXVKU23F.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-G7X54RZL.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-TD5LZDUM.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-W5CL2E2W.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-W5CL2E2W.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-W5CL2E2W.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Fn.push({name:"tar",load:async()=>(await import("./chunks/tar-RPVTXGFJ.js")).tarCommand}),Fn.push({name:"yq",load:async()=>(await import("./chunks/yq-T6S3IDKY.js")).yqCommand}),Fn.push({name:"xan",load:async()=>(await import("./chunks/xan-XZHKEPJ4.js")).xanCommand}),Fn.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-57ACN7ES.js")).sqlite3Command}));var li=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(li.push({name:"python3",load:async()=>(await import("./chunks/python3-P6MZ44HK.js")).python3Command,handlesOwnVersion:!0}),li.push({name:"python",load:async()=>(await import("./chunks/python3-P6MZ44HK.js")).pythonCommand,handlesOwnVersion:!0}));var ci=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(ci.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-LISDW7YC.js")).jsExecCommand,handlesOwnVersion:!0}),ci.push({name:"node",load:async()=>(await import("./chunks/js-exec-LISDW7YC.js")).nodeStubCommand}));var fd=[{name:"curl",load:async()=>(await import("./chunks/curl-HZ5SBTVY.js")).curlCommand}],Oa=new Map;function Ur(e){return{name:e.name,handlesOwnVersion:e.handlesOwnVersion,async execute(t,n){let r=Oa.get(e.name);if(r||(r=await Te.runTrustedAsync(()=>sr(e.load(),n.signal,`bash: ${e.name} was cancelled before it started
4
+ `)),Oa.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await sr(import("./chunks/flag-coverage-AGEO3F6X.js"),n.signal,`bash: ${e.name} was cancelled before it started
5
+ `);s(n.coverage,e.name,t)}return r.execute(t,n)}}}function _a(e){return(e?Fn.filter(n=>e.includes(n.name)):Fn).map(Ur)}function La(){return fd.map(Ur)}function Ta(){return li.map(Ur)}function Fa(){return ci.map(Ur)}var Ma=new WeakMap,Ba=new WeakSet;function ui(e){let t=Ma.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),Ma.set(e,t),Ba.add(t)),t}function Wa(e){return Ba.has(e)}var Va={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,maxJsMemoryBytes:67108864,maxGlobOperations:1e6,maxStringLength:67108864,maxArrayElements:1e6,maxHeredocSize:67108864,maxSubstitutionDepth:50,maxBraceExpansionResults:1e5,maxOutputSize:268435456,maxFileDescriptors:4096,maxSourceDepth:100},dd={...Va,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 pd(e){return Number.isFinite(e)?Math.min(Math.max(0,Math.floor(e)),4294967295):4294967295}function fi(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?dd:Va;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,maxJsMemoryBytes:pd(e.maxJsMemoryBytes??n.maxJsMemoryBytes),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 za(e){return"load"in e&&typeof e.load=="function"}function Ua(e){let t=null,n=!1,r=new Set,s=a=>{t=a;for(let l of r)l.resolve(a);r.clear()},i=a=>{n=!1;for(let l of r)l.reject(a);r.clear()},o=()=>{n=!0;let a;try{a=Promise.resolve(e.load())}catch(l){i(l);return}Na.call(a,s,i)};return{name:e.name,trusted:e.trusted!==!1,handlesOwnVersion:e.handlesOwnVersion,async execute(a,l){if(!t){let u,f=new Promise((d,p)=>{u={resolve:d,reject:p},r.add(u)});n||o();try{t=await sr(f,l.signal,`bash: ${e.name} was cancelled before it started
6
+ `)}finally{u&&r.delete(u)}}let c=t;if(!c)throw new Error(`Failed to load command: ${e.name}`);return c.execute(a,l)}}}var qa=Object.freeze(Object.create(null)),qr=class{limits;signal;abortOnUnresolvedCommands;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();unresolvedCommands=new Set;get remainingLiveBytes(){return Math.max(0,this.limits.maxLiveBytes-this.liveBytes)}get outputBytesUsed(){return this.outputBytes}constructor(t,n=void 0,r=!1){this.limits=t,this.signal=n,this.abortOnUnresolvedCommands=r}recordUnresolvedCommand(t){this.unresolvedCommands.add(t)}get unresolvedCommandNames(){return[...this.unresolvedCommands]}fail(t){throw this.poisoned??=t,this.poisoned}poisonAfterAbort(t){this.poisoned??=t}assertUsable(){if(this.poisoned)throw this.poisoned;if(this.closed)throw new Error("execution budget is already closed");this.throwIfAborted()}chargeCommand(){return this.consume("commands",1,"execution")}consumeWork(t=1,n="execution"){return this.consume("work",t,n)}consumeLimited(t,n,r,s=t){this.assertUsable();let i=this.countersByKind.get(t)??0;return(!Number.isSafeInteger(n)||n<0||!Number.isSafeInteger(r)||r<0||n>r-i)&&this.fail(new P(`${s}: ${t} work limit exceeded (${r})`,"iterations")),n>this.limits.maxWorkUnits-this.workUnits&&this.fail(new P(`${s}: aggregate work limit exceeded (${this.limits.maxWorkUnits})`,"iterations")),this.countersByKind.set(t,i+n),this.workUnits+=n,i+n}consumeInput(t,n="execution"){return this.assertUsable(),(!Number.isSafeInteger(t)||t<0||t>this.limits.maxInputBytes-this.inputBytes)&&this.fail(new P(`${n}: aggregate input size limit exceeded (${this.limits.maxInputBytes} bytes)`,"string_length")),this.inputBytes+=t,this.inputBytes}consume(t,n=1,r=t){this.assertUsable();let s=this.countersByKind.get(t)??0,i=t==="commands"?this.commandCount:this.workUnits,o=t==="commands"?this.limits.maxCommandCount:this.limits.maxWorkUnits;(!Number.isSafeInteger(n)||n<0||n>o-i)&&this.fail(new P(t==="commands"?`too many commands executed (>${o}), increase executionLimits.maxCommandCount`:`${r}: ${t} work limit exceeded (${o})`,t==="commands"?"commands":"iterations"));let a=i+n;return t==="commands"?this.commandCount=a:this.workUnits=a,this.countersByKind.set(t,s+n),a}reserveBytes(t,n,r){this.assertUsable();let s=typeof t=="string"?t:"live",i=typeof t=="string"?n:t,o=typeof t=="string"?r??s:n??"execution";(!Number.isSafeInteger(i)||i<0||i>this.limits.maxLiveBytes-this.liveBytes)&&this.fail(new P(`${o}: live byte limit exceeded (${this.limits.maxLiveBytes} bytes)`,"string_length")),this.liveBytes+=i,this.bytesByKind.set(s,(this.bytesByKind.get(s)??0)+i);let a=!1;return{release:()=>{if(a)return;a=!0,this.liveBytes-=i;let l=(this.bytesByKind.get(s)??i)-i;l<=0?this.bytesByKind.delete(s):this.bytesByKind.set(s,l)}}}appendOutput(t,n,r="execution",s=0,i="text"){this.assertUsable();let o=i==="bytes"?n.length:M(n);(!Number.isSafeInteger(s)||s<0||s>o)&&this.fail(new P(`${r}: invalid ${t} accounting`,"output_size"));let a=o-s;return a>this.limits.maxOutputSize-this.outputBytes&&this.fail(new P(`${r}: total output size exceeded (>${this.limits.maxOutputSize} bytes), increase executionLimits.maxOutputSize`,"output_size")),this.outputBytes+=a,o}accountResult(t,n="execution",r=Number.POSITIVE_INFINITY){let s=t.internalOutputAccounting,i=Math.min(s?.stdout??0,r),o=Math.min(s?.stderr??0,Math.max(0,r-i)),a=this.appendOutput("stdout",t.stdout,n,i,t.stdoutKind==="bytes"||t.stdoutEncoding==="binary"?"bytes":"text"),l=this.appendOutput("stderr",t.stderr,n,o);return Object.isExtensible(t)?(t.internalOutputAccounting={stdout:a,stderr:l},t):a===0&&l===0?t:{...t,internalOutputAccounting:{stdout:a,stderr:l}}}relinquishOutput(t,n,r){this.assertUsable(),r!==qa&&this.fail(new P(`${n}: unauthorized output accounting release`,"output_size")),(!Number.isSafeInteger(t)||t<0||t>this.outputBytes)&&this.fail(new P(`${n}: invalid output accounting release`,"output_size")),this.outputBytes-=t}enterDepth(t,n=this.limits.maxCallDepth,r){this.assertUsable();let s=typeof n=="number"?n:this.limits.maxCallDepth,i=typeof n=="string"?n:r??t,o=this.depthByKind.get(t)??0;o>=s&&this.fail(new P(`${i}: maximum depth (${s}) exceeded`,"recursion")),this.depthByKind.set(t,o+1);let a=!1;return{release:()=>{if(a)return;a=!0;let l=(this.depthByKind.get(t)??1)-1;l<=0?this.depthByKind.delete(t):this.depthByKind.set(t,l)}}}throwIfAborted(t="execution"){this.signal?.aborted&&this.fail(new Ye("",`bash: ${t} aborted
4
7
  `)),Date.now()-this.startedAt>this.limits.maxExecutionTimeMs&&this.fail(new Ye("",`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=Jn(()=>a({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(er(i),!o.ok&&(t.push(o.error),Date.now()>=n))break}catch(s){t.push(s)}if(this.cleanupCallbacks.length=0,this.depthByKind.clear(),this.bytesByKind.clear(),this.liveBytes=0,t.length>0)throw new AggregateError(t,"execution cleanup failed")}assertExecDepth(t){this.assertUsable(),t>this.limits.maxExecDepth&&this.fail(new P(`maximum nested execution depth (${this.limits.maxExecDepth}) exceeded`,"recursion"))}};function Fa(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 Ma(e,t,n="pipeline"){e.relinquishOutput(t,n,Ta)}var gn=new TextEncoder;function ad(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var xt=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:B(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 N("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 N("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:B(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:ht,mtime:new Date}),t)for(let[r,s]of Object.entries(t))typeof s=="function"?this.writeFileLazy(r,s):ad(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:ht,mtime:new Date})))}writeFileSync(t,n,r,s){X(t,"write");let i=U(t);this.ensureParentDirs(i);let o=Zt(r);this.assertCanAllocate(i,this.contentByteLength(n,o));let a=On(n,o);this.setEntry(i,{type:"file",content:a,mode:s?.mode??jt,mtime:s?.mtime??new Date})}writeFileLazy(t,n,r){X(t,"write");let s=U(t);this.ensureParentDirs(s),this.setEntry(s,{type:"file",lazy:n,mode:r?.mode??jt,mtime:r?.mtime??new Date})}async materializeLazy(t,n){let r=await Te.runTrustedAsync(async()=>n.lazy()),s=typeof r=="string"?gn.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=Zt(n);return _n(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return _n(n,"binary")}async readFileBuffer(t){X(t,"open");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new N("ENOENT",`no such file or directory, open '${t}'`);if(r.type!=="file")throw new N("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:gn.encode(s.content)}return r.content instanceof Uint8Array?r.content:gn.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){X(t,"append");let s=U(t),i=this.data.get(s);if(i&&i.type==="directory")throw new N("EISDIR",`illegal operation on a directory, write '${t}'`);let o=Zt(r),a=this.contentByteLength(n,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(s,l));let c="content"in l&&l.content instanceof Uint8Array?l.content:gn.encode("content"in l?l.content:"");this.assertCanAllocate(s,c.byteLength+a);let u=On(n,o),f=new Uint8Array(c.length+u.length);f.set(c),f.set(u,c.length),this.setEntry(s,{type:"file",content:f,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,n,r)}async exists(t){if(t.includes("\0"))return!1;try{let n=this.resolvePathWithSymlinks(t);return this.data.has(n)}catch{return!1}}async stat(t){X(t,"stat");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new N("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=gn.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){X(t,"lstat");let n=this.resolveIntermediateSymlinks(t),r=this.data.get(n);if(!r)throw new N("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=gn.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=U(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];s=`${s}/${a}`;let l=this.data.get(s),c=0,u=tr;for(;l&&l.type==="symlink"&&c<u;){if(i.has(s))throw new N("ELOOP",`too many levels of symbolic links, lstat '${t}'`);i.add(s),s=In(s,l.target),l=this.data.get(s),c++}if(c>=u)throw new N("ELOOP",`too many levels of symbolic links, lstat '${t}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let n=U(t);if(n==="/")return"/";let r=n.slice(1).split("/"),s="",i=new Set;for(let o of r){s=`${s}/${o}`;let a=this.data.get(s),l=0,c=tr;for(;a&&a.type==="symlink"&&l<c;){if(i.has(s))throw new N("ELOOP",`too many levels of symbolic links, open '${t}'`);i.add(s),s=In(s,a.target),a=this.data.get(s),l++}if(l>=c)throw new N("ELOOP",`too many levels of symbolic links, open '${t}'`)}return s}async mkdir(t,n){this.mkdirSync(t,n)}mkdirSync(t,n){X(t,"mkdir");let r=U(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new N("EEXIST",`file already exists, mkdir '${t}'`);if(!n?.recursive)throw new N("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 N("ENOENT",`no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:ht,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){X(t,"scandir");let n=U(t),r=this.data.get(n);if(!r)throw new N("ENOENT",`no such file or directory, scandir '${t}'`);let s=new Set;for(;r&&r.type==="symlink";){if(s.has(n))throw new N("ELOOP",`too many levels of symbolic links, scandir '${t}'`);s.add(n),n=In(n,r.target),r=this.data.get(n)}if(!r)throw new N("ENOENT",`no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new N("ENOTDIR",`not a directory, scandir '${t}'`);let i=n==="/"?"/":`${n}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==n&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,n){X(t,"rm");let r=U(t),s=this.data.get(r);if(!s){if(n?.force)return;throw new N("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 N("ENOTEMPTY",`directory not empty, rm '${t}'`);for(let o of i){let a=Ft(r,o);await this.rm(a,n)}}}this.deleteEntry(r)}async cp(t,n,r){X(t,"cp"),X(n,"cp");let s=U(t),i=U(n),o=this.data.get(s);if(!o)throw new N("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:gn.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 N("EISDIR",`is a directory, cp '${t}'`);if(Tt(s,i))throw new N("EINVAL",`cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(s);for(let l of a){let c=Ft(s,l),u=Ft(i,l);await this.cp(c,u,r)}}}async mv(t,n){X(t,"mv"),X(n,"mv");let r=U(t),s=U(n);if(r===s)return;let i=this.data.get(r);if(!i)throw new N("ENOENT",`no such file or directory, mv '${t}'`);if(i.type==="directory"&&Tt(r,s))throw new N("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(Ft(r,a),Ft(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 Dn(t,n)}async chmod(t,n){X(t,"chmod");let r=U(t),s=this.data.get(r);if(!s)throw new N("ENOENT",`no such file or directory, chmod '${t}'`);s.mode=n}async symlink(t,n){X(n,"symlink");let r=U(n);if(this.data.has(r))throw new N("EEXIST",`file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:Br,mtime:new Date})}async link(t,n){X(t,"link"),X(n,"link");let r=U(t),s=U(n),i=this.data.get(r);if(!i)throw new N("ENOENT",`no such file or directory, link '${t}'`);if(i.type!=="file")throw new N("EPERM",`operation not permitted, link '${t}'`);if(this.data.has(s))throw new N("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){X(t,"readlink");let n=U(t),r=this.data.get(n);if(!r)throw new N("ENOENT",`no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new N("EINVAL",`invalid argument, readlink '${t}'`);return r.target}async realpath(t){X(t,"realpath");let n=this.resolvePathWithSymlinks(t);if(!this.data.has(n))throw new N("ENOENT",`no such file or directory, realpath '${t}'`);return n}async utimes(t,n,r){X(t,"utimes");let s=U(t),i=this.resolvePathWithSymlinks(s),o=this.data.get(i);if(!o)throw new N("ENOENT",`no such file or directory, utimes '${t}'`);o.mtime=r}};var Wa="5.1.0(1)-release",Va="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function li(e){let{pid:t,ppid:n,uid:r,gid:s}=e;return`Name: bash
8
+ `))}remainingTimeMs(){return Math.max(0,this.limits.maxExecutionTimeMs-(Date.now()-this.startedAt))}registerCleanup(t){this.assertUsable(),this.cleanupCallbacks.push(t);let n=!0;return()=>{if(!n)return;n=!1;let r=this.cleanupCallbacks.indexOf(t);r>=0&&this.cleanupCallbacks.splice(r,1)}}async close(){if(this.closed)return;this.closed=!0;let t=[],n=Date.now()+this.limits.maxExtensionCleanupTimeMs;for(let r=this.cleanupCallbacks.length-1;r>=0;r--)try{let s=n-Date.now();if(s<=0){t.push(new Error("execution cleanup grace period exceeded"));break}let i,o=await Promise.race([Promise.resolve().then(this.cleanupCallbacks[r]).then(()=>({ok:!0}),a=>({ok:!1,error:a})),new Promise(a=>{i=nr(()=>a({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(rr(i),!o.ok&&(t.push(o.error),Date.now()>=n))break}catch(s){t.push(s)}if(this.cleanupCallbacks.length=0,this.depthByKind.clear(),this.bytesByKind.clear(),this.liveBytes=0,t.length>0)throw new AggregateError(t,"execution cleanup failed")}assertExecDepth(t){this.assertUsable(),t>this.limits.maxExecDepth&&this.fail(new P(`maximum nested execution depth (${this.limits.maxExecDepth}) exceeded`,"recursion"))}};function ja(e){let t=Object.create(null);return Object.defineProperties(t,{remainingLiveBytes:{enumerable:!0,get:()=>e.remainingLiveBytes},consumeWork:{enumerable:!0,value:e.consumeWork.bind(e)},consumeLimited:{enumerable:!0,value:e.consumeLimited.bind(e)},consumeInput:{enumerable:!0,value:e.consumeInput.bind(e)},reserveBytes:{enumerable:!0,value:e.reserveBytes.bind(e)},enterDepth:{enumerable:!0,value:e.enterDepth.bind(e)},throwIfAborted:{enumerable:!0,value:e.throwIfAborted.bind(e)},remainingTimeMs:{enumerable:!0,value:e.remainingTimeMs.bind(e)},registerCleanup:{enumerable:!0,value:e.registerCleanup.bind(e)}}),Object.freeze(t)}function Ha(e,t,n="pipeline"){e.relinquishOutput(t,n,qa)}var En=new TextEncoder;function hd(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var $t=class{data=new Map;entryIdentities=new WeakMap;nextEntryIdentity=1;maxTotalBytes;retainedBytes=0;contentReferences=new WeakMap;materializedContent(t){return t?.type==="file"&&"content"in t?t.content:null}storedByteLength(t){return t===null?0:t instanceof Uint8Array?t.byteLength:M(t)}wouldReleaseBytes(t){let n=this.materializedContent(t);return n===null?0:n instanceof Uint8Array?this.contentReferences.get(n)===1?n.byteLength:0:this.storedByteLength(n)}assertCanAllocate(t,n){let r=this.wouldReleaseBytes(this.data.get(t));if(!Number.isSafeInteger(n)||n<0||n>this.maxTotalBytes-this.retainedBytes+r)throw new N("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 N("ENOSPC",`in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`);if(s instanceof Uint8Array){let l=this.contentReferences.get(s)??0;l<=1?this.contentReferences.delete(s):this.contentReferences.set(s,l-1)}i instanceof Uint8Array&&this.contentReferences.set(i,(this.contentReferences.get(i)??0)+1),this.retainedBytes+=a-o,this.data.set(t,n)}deleteEntry(t){let n=this.data.get(t);if(!n)return!1;let r=this.materializedContent(n),s=this.wouldReleaseBytes(n);if(r instanceof Uint8Array){let i=this.contentReferences.get(r)??0;i<=1?this.contentReferences.delete(r):this.contentReferences.set(r,i-1)}return this.retainedBytes-=s,this.data.delete(t)}contentByteLength(t,n){if(t instanceof Uint8Array)return t.byteLength;if(n==="hex")return Math.floor(t.length/2);if(n==="base64"){let r=t.endsWith("==")?2:t.endsWith("=")?1:0;return Math.max(0,Math.floor(t.length*3/4)-r)}return n==="binary"||n==="latin1"?t.length:M(t)}identityFor(t){let n=this.entryIdentities.get(t);return n||(n=`memfs:${this.nextEntryIdentity++}`,this.entryIdentities.set(t,n)),n}constructor(t,n={}){if(this.maxTotalBytes=n.maxTotalBytes??1024*1024*1024,!Number.isSafeInteger(this.maxTotalBytes)||this.maxTotalBytes<0)throw new Error("InMemoryFs: invalid maxTotalBytes");if(this.data.set("/",{type:"directory",mode:mt,mtime:new Date}),t)for(let[r,s]of Object.entries(t))typeof s=="function"?this.writeFileLazy(r,s):hd(s)?this.writeFileSync(r,s.content,void 0,{mode:s.mode,mtime:s.mtime}):this.writeFileSync(r,s)}ensureParentDirs(t){let n=yt(t);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:mt,mtime:new Date})))}writeFileSync(t,n,r,s){K(t,"write");let i=z(t);this.ensureParentDirs(i);let o=Qt(r);this.assertCanAllocate(i,this.contentByteLength(n,o));let a=Ln(n,o);this.setEntry(i,{type:"file",content:a,mode:s?.mode??Ht,mtime:s?.mtime??new Date})}writeFileLazy(t,n,r){K(t,"write");let s=z(t);this.ensureParentDirs(s),this.setEntry(s,{type:"file",lazy:n,mode:r?.mode??Ht,mtime:r?.mtime??new Date})}async materializeLazy(t,n){let r=await Te.runTrustedAsync(async()=>n.lazy()),s=typeof r=="string"?En.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=Qt(n);return Tn(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Tn(n,"binary")}async readFileBuffer(t){K(t,"open");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new N("ENOENT",`no such file or directory, open '${t}'`);if(r.type!=="file")throw new N("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:En.encode(s.content)}return r.content instanceof Uint8Array?r.content:En.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){K(t,"append");let s=z(t),i=this.data.get(s);if(i&&i.type==="directory")throw new N("EISDIR",`illegal operation on a directory, write '${t}'`);let o=Qt(r),a=this.contentByteLength(n,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(s,l));let c="content"in l&&l.content instanceof Uint8Array?l.content:En.encode("content"in l?l.content:"");this.assertCanAllocate(s,c.byteLength+a);let u=Ln(n,o),f=new Uint8Array(c.length+u.length);f.set(c),f.set(u,c.length),this.setEntry(s,{type:"file",content:f,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,n,r)}async exists(t){if(t.includes("\0"))return!1;try{let n=this.resolvePathWithSymlinks(t);return this.data.has(n)}catch{return!1}}async stat(t){K(t,"stat");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new N("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=En.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 N("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=En.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),c=0,u=ir;for(;l&&l.type==="symlink"&&c<u;){if(i.has(s))throw new N("ELOOP",`too many levels of symbolic links, lstat '${t}'`);i.add(s),s=_n(s,l.target),l=this.data.get(s),c++}if(c>=u)throw new N("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,c=ir;for(;a&&a.type==="symlink"&&l<c;){if(i.has(s))throw new N("ELOOP",`too many levels of symbolic links, open '${t}'`);i.add(s),s=_n(s,a.target),a=this.data.get(s),l++}if(l>=c)throw new N("ELOOP",`too many levels of symbolic links, open '${t}'`)}return s}async mkdir(t,n){this.mkdirSync(t,n)}async createExclusive(t,n){let r=n.directory?"mkdir":"open";K(t,n.directory?"mkdir":"write");let s=z(t),i=yt(s),o=i==="/"?"/":this.resolvePathWithSymlinks(i),a=ot(o,s.slice(s.lastIndexOf("/")+1));if(this.data.has(a))throw new N("EEXIST",`file already exists, ${r} '${t}'`);if(o!=="/"){let l=this.data.get(o);if(!l)throw new N("ENOENT",`no such file or directory, ${r} '${t}'`);if(l.type!=="directory")throw new N("ENOTDIR",`not a directory, ${r} '${t}'`)}if(n.directory){this.setEntry(a,{type:"directory",mode:n.mode,mtime:new Date});return}this.assertCanAllocate(a,0),this.setEntry(a,{type:"file",content:new Uint8Array(0),mode:n.mode,mtime:new Date})}mkdirSync(t,n){K(t,"mkdir");let r=z(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new N("EEXIST",`file already exists, mkdir '${t}'`);if(!n?.recursive)throw new N("EEXIST",`directory already exists, mkdir '${t}'`);return}let s=yt(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new N("ENOENT",`no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:mt,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){K(t,"scandir");let n=z(t),r=this.data.get(n);if(!r)throw new N("ENOENT",`no such file or directory, scandir '${t}'`);let s=new Set;for(;r&&r.type==="symlink";){if(s.has(n))throw new N("ELOOP",`too many levels of symbolic links, scandir '${t}'`);s.add(n),n=_n(n,r.target),r=this.data.get(n)}if(!r)throw new N("ENOENT",`no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new N("ENOTDIR",`not a directory, scandir '${t}'`);let i=n==="/"?"/":`${n}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==n&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,n){K(t,"rm");let r=z(t),s=this.data.get(r);if(!s){if(n?.force)return;throw new N("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 N("ENOTEMPTY",`directory not empty, rm '${t}'`);for(let o of i){let a=ot(r,o);await this.rm(a,n)}}}this.deleteEntry(r)}async cp(t,n,r){K(t,"cp"),K(n,"cp");let s=z(t),i=z(n),o=this.data.get(s);if(!o)throw new N("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:En.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 N("EISDIR",`is a directory, cp '${t}'`);if(Mt(s,i))throw new N("EINVAL",`cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(s);for(let l of a){let c=ot(s,l),u=ot(i,l);await this.cp(c,u,r)}}}async mv(t,n){K(t,"mv"),K(n,"mv");let r=z(t),s=z(n);if(r===s)return;let i=this.data.get(r);if(!i)throw new N("ENOENT",`no such file or directory, mv '${t}'`);if(i.type==="directory"&&Mt(r,s))throw new N("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(ot(r,a),ot(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 On(t,n)}async chmod(t,n){K(t,"chmod");let r=z(t),s=this.data.get(r);if(!s)throw new N("ENOENT",`no such file or directory, chmod '${t}'`);s.mode=n}async symlink(t,n){K(n,"symlink");let r=z(n);if(this.data.has(r))throw new N("EEXIST",`file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:zr,mtime:new Date})}async link(t,n){K(t,"link"),K(n,"link");let r=z(t),s=z(n),i=this.data.get(r);if(!i)throw new N("ENOENT",`no such file or directory, link '${t}'`);if(i.type!=="file")throw new N("EPERM",`operation not permitted, link '${t}'`);if(this.data.has(s))throw new N("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){K(t,"readlink");let n=z(t),r=this.data.get(n);if(!r)throw new N("ENOENT",`no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new N("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 N("ENOENT",`no such file or directory, realpath '${t}'`);return n}async utimes(t,n,r){K(t,"utimes");let s=z(t),i=this.resolvePathWithSymlinks(s),o=this.data.get(i);if(!o)throw new N("ENOENT",`no such file or directory, utimes '${t}'`);o.mtime=r}};var Za="5.1.0(1)-release",Qa="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function di(e){let{pid:t,ppid:n,uid:r,gid:s}=e;return`Name: bash
6
9
  State: R (running)
7
10
  Pid: ${t}
8
11
  PPid: ${n}
9
12
  Uid: ${r} ${r} ${r} ${r}
10
13
  Gid: ${s} ${s} ${s} ${s}
11
- `}function ld(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function cd(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 ud(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 fd(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Va}
14
+ `}function md(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function yd(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 gd(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 wd(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Qa}
12
15
  `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
13
- `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>li(t)):e.writeFileSync("/proc/self/status",li(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 za(e,t,n={pid:1,ppid:0,uid:1e3,gid:1e3}){ld(e)&&(cd(e,t),ud(e),fd(e,n))}function Ua(e){let t={commands:new Set,definedFunctions:new Set,definedAliases:new Set};return ci(e,t),{commands:[...t.commands],definedFunctions:t.definedFunctions,definedAliases:t.definedAliases}}function dd(e){return e.parts.length===1&&e.parts[0].type==="Literal"?e.parts[0].value:null}function pd(e,t){for(let n of e){let r=n.parts[0];if(r?.type!=="Literal")continue;let s=/^([A-Za-z_][A-Za-z0-9_]*)=/.exec(r.value);s&&t.definedAliases.add(s[1])}}function ci(e,t){for(let n of e.statements)kt(n,t)}function kt(e,t){for(let n of e.pipelines)hd(n,t)}function hd(e,t){for(let n of e.commands)qa(n,t)}function qa(e,t){switch(e.type){case"SimpleCommand":if(e.name){let n=dd(e.name);n&&(t.commands.add(n),n==="alias"&&pd(e.args,t)),Fe(e.name.parts,t)}for(let n of e.args)Fe(n.parts,t);for(let n of e.assignments)if(n.value&&Fe(n.value.parts,t),n.array)for(let r of n.array)Fe(r.parts,t);for(let n of e.redirections)n.target.type==="Word"?Fe(n.target.parts,t):n.target.type==="HereDoc"&&!n.target.quoted&&Fe(n.target.content.parts,t);break;case"If":for(let n of e.clauses){for(let r of n.condition)kt(r,t);for(let r of n.body)kt(r,t)}if(e.elseBody)for(let n of e.elseBody)kt(n,t);break;case"For":if(e.words)for(let n of e.words)Fe(n.parts,t);for(let n of e.body)kt(n,t);break;case"CStyleFor":for(let n of e.body)kt(n,t);break;case"While":case"Until":for(let n of e.condition)kt(n,t);for(let n of e.body)kt(n,t);break;case"Case":Fe(e.word.parts,t);for(let n of e.items)for(let r of n.body)kt(r,t);break;case"Subshell":case"Group":for(let n of e.body)kt(n,t);break;case"ArithmeticCommand":case"ConditionalCommand":break;case"FunctionDef":t.definedFunctions.add(e.name),qa(e.body,t);break}}function Fe(e,t){for(let n of e)switch(n.type){case"CommandSubstitution":ci(n.body,t);break;case"ProcessSubstitution":ci(n.body,t);break;case"DoubleQuoted":Fe(n.parts,t);break;case"ParameterExpansion":n.operation&&ja(n.operation,t);break}}function ja(e,t){switch(e.type){case"DefaultValue":case"AssignDefault":case"UseAlternative":Fe(e.word.parts,t);break;case"ErrorIfUnset":e.word&&Fe(e.word.parts,t);break;case"PatternRemoval":Fe(e.pattern.parts,t);break;case"PatternReplacement":Fe(e.pattern.parts,t),e.replacement&&Fe(e.replacement.parts,t);break;case"CaseModification":e.pattern&&Fe(e.pattern.parts,t);break;case"Indirection":e.innerOp&&ja(e.innerOp,t);break}}function zr(e,t){return e===`/bin/${t}`||e===`/usr/bin/${t}`}async function Ur(e,t,n){if(t.includes("/")){let o=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(o))return{error:"not_found",path:o};try{let a=await e.fs.stat(o);if(a.isDirectory)return{error:"permission_denied",path:o};let l=o.split("/").pop()||t,c=e.commands.get(l);return c&&zr(o,l)?{cmd:c,path:o}:(a.mode&73)!==0?{script:!0,path:o}:{error:"permission_denied",path:o}}catch{return{error:"not_found",path:o}}}if(!n&&e.state.hashTable){let o=e.state.hashTable.get(t);if(o){try{let a=await e.fs.stat(o);if(!a.isDirectory){let l=e.commands.get(t);if(l&&zr(o,t))return{cmd:l,path:o};if((a.mode&73)!==0)return{script:!0,path:o}}}catch{}e.state.hashTable.delete(t)}}let s=(n??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let o of s){if(!o)continue;let l=`${o.startsWith("/")?o:e.fs.resolvePath(e.state.cwd,o)}/${t}`;if(await e.fs.exists(l))try{let c=await e.fs.stat(l);if(c.isDirectory)continue;let u=(c.mode&73)!==0,f=e.commands.get(t),d=zr(l,t);if(f&&d)return{cmd:f,path:l};if(u){if(f&&!d)return{script:!0,path:l};if(!f)return{script:!0,path:l}}}catch{}}if(!await e.fs.exists("/usr/bin")){let o=e.commands.get(t);if(o)return{cmd:o,path:`/usr/bin/${t}`}}return null}async function qr(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(zr(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 Me(e){return{kind:e.kind,elements:new Map(e.elements)}}function ot(e){return new Map(Array.from(e??[],([t,n])=>[t,Me(n)]))}function xe(e,t){return e.state.arrays?.get(t)}function rr(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 Qt(e,t,n){let r=rr(e,t,n);return r.kind=n,r}function Ce(e,t){return e.state.arrays?.has(t)??!1}function ae(e,t,n){return xe(e,t)?.elements.get(String(n))}function Kt(e,t,n){return xe(e,t)?.elements.has(String(n))??!1}function j(e,t,n,r,s){let i=rr(e,t,s),o=String(n);if(!i.elements.has(o)&&i.elements.size>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(B(r)>e.limits.maxStringLength)throw new P(`array value string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");i.elements.set(o,r)}function wn(e,t,n,r=!1){let s=new Set(r?[]:xe(e,t)?.elements.keys()??[]);for(let i of n)if(s.add(String(i)),s.size>e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements")}function En(e,t,n){return xe(e,t)?.elements.delete(String(n))??!1}function sr(e,t){e.state.arrays?.delete(t),e.state.associativeArrays?.delete(t)}function Se(e,t){return Array.from(xe(e,t)?.elements.keys()??[]).filter(r=>/^(0|[1-9]\d*)$/.test(r)).map(Number).sort((r,s)=>r-s)}function ge(e,t){rr(e,t,e.state.associativeArrays?.has(t)?"associative":"indexed").elements.clear()}function $t(e,t){return Array.from(xe(e,t)?.elements.keys()??[]).sort()}function jr(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function ui(e){if(e.parts.length<2)return null;let t=e.parts[0],n=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let r,s=n,i=1;if(n.type==="Literal"&&n.value.startsWith("]")){let f=n.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))r=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let d=e.parts[2];if(d.type!=="Literal"||!d.value.startsWith("=")&&!d.value.startsWith("+="))return null;r=t.pattern.slice(1),s=d,i=2}else return null}else if(t.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(n.type==="SingleQuoted")r=n.value;else{r="";for(let d of n.parts)(d.type==="Literal"||d.type==="Escaped")&&(r+=d.value)}s=f,i=2}else if(t.pattern.endsWith("]")){if(n.type!=="Literal"||!n.value.startsWith("=")&&!n.value.startsWith("+="))return null;r=t.pattern.slice(1,-1)}else return null;r=jr(r);let o;if(s.type!=="Literal")return null;s.value.startsWith("]=")||s.value.startsWith("]+=")?o=s.value.slice(1):o=s.value;let a=o.startsWith("+=");if(!a&&!o.startsWith("="))return null;let l=[],c=a?2:1,u=o.slice(c);u&&l.push({type:"Literal",value:u});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?l.push({type:"Literal",value:md(d)}):l.push(d)}return{key:r,valueParts:l,append:a}}function md(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 Tn(n.word)}).join(",")}}`}function Tn(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}`:""}`:Tn(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",n.user&&(t+=n.user);break}return t}var ir=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Ha(e){return ir.has(e)}var or=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]);var yd=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],gd=["braceexpand","hashall","interactive-comments"];function fi(e){let t=[],n=[...gd.map(r=>({name:r,enabled:!0})),...yd.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 Fn(e){e.state.env.set("SHELLOPTS",fi(e.state.options))}var wd=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function di(e){let t=[];for(let n of wd)e[n]&&t.push(n);return t.join(":")}function pi(e){e.state.env.set("BASHOPTS",di(e.state.shoptOptions))}var F={script(e){return{type:"Script",statements:e}},statement(e,t=[],n=!1,r,s){let i={type:"Statement",pipelines:e,operators:t,background:n};return r&&(i.deferredError=r),s!==void 0&&(i.sourceText=s),i},pipeline(e,t=!1,n=!1,r=!1,s){return{type:"Pipeline",commands:e,negated:t,timed:n,timePosix:r,pipeStderr:s}},simpleCommand(e,t=[],n=[],r=[]){return{type:"SimpleCommand",name:e,args:t,assignments:n,redirections:r}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},processSubstitution(e,t){return{type:"ProcessSubstitution",body:e,direction:t}},assignment(e,t,n=!1,r=null){return{type:"Assignment",name:e,value:t,append:n,array:r}},redirection(e,t,n=null,r){let s={type:"Redirection",fd:n,operator:e,target:t};return r&&(s.fdVariable=r),s},hereDoc(e,t,n=!1,r=!1,s){let i={type:"HereDoc",delimiter:e,content:t,stripTabs:n,quoted:r};return s!==void 0&&(i.terminated=s),i},ifNode(e,t=null,n=[]){return{type:"If",clauses:e,elseBody:t,redirections:n}},forNode(e,t,n,r=[]){return{type:"For",variable:e,words:t,body:n,redirections:r}},whileNode(e,t,n=[]){return{type:"While",condition:e,body:t,redirections:n}},untilNode(e,t,n=[]){return{type:"Until",condition:e,body:t,redirections:n}},caseNode(e,t,n=[]){return{type:"Case",word:e,items:t,redirections:n}},caseItem(e,t,n=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:n}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,n=[],r){return{type:"FunctionDef",name:e,body:t,redirections:n,sourceFile:r}},conditionalCommand(e,t=[],n){return{type:"ConditionalCommand",expression:e,redirections:t,line:n}},arithmeticCommand(e,t=[],n){return{type:"ArithmeticCommand",expression:e,redirections:t,line:n}}};function Ga(e,t){let n=e.length,r=t+3,s=2,i=!1,o=!1;for(;r<n&&s>0;){let a=e[r];if(i){a==="'"&&(i=!1),r++;continue}if(o){if(a==="\\"){r+=2;continue}a==='"'&&(o=!1),r++;continue}if(a==="'"){i=!0,r++;continue}if(a==='"'){o=!0,r++;continue}if(a==="\\"){r+=2;continue}if(a==="("){s++,r++;continue}if(a===")"){if(s--,s===1){let l=r+1;return!(l<n&&e[l]===")")}if(s===0)return!1;r++;continue}if(s===1&&(a==="|"&&r+1<n&&e[r+1]==="|"||a==="&"&&r+1<n&&e[r+1]==="&"||a==="|"&&r+1<n&&e[r+1]!=="|"))return!0;r++}return!1}function Hr(e,t){let n="",r=t,s=0,i=!1,o,a=l=>l===" "||l===" "||l===`
16
+ `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>di(t)):e.writeFileSync("/proc/self/status",di(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function Ka(e,t,n={pid:1,ppid:0,uid:1e3,gid:1e3}){if(md(e)){let r=Ed(e);yd(r,t),gd(r),wd(r,n)}}function Ed(e){let t=r=>{try{r()}catch(s){if(s?.code!=="ENOSYS")throw s}},n={mkdirSync:(r,s)=>t(()=>e.mkdirSync(r,s)),writeFileSync:(r,s)=>t(()=>e.writeFileSync(r,s))};return e.writeFileLazy&&(n.writeFileLazy=(r,s)=>t(()=>e.writeFileLazy?.(r,s))),n}var bn=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new $t,t?.mounts)for(let{mountPoint:n,filesystem:r}of t.mounts)this.mount(n,r)}mount(t,n){this.validateMountPath(t);let r=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}))}diff(t){let n=t?.space??"vfs",r=[],s=[],i=[];for(let o of this.mounts.values()){let a=o.filesystem;if(typeof a.diff!="function")throw new N("EINVAL",`mounted filesystem at '${o.mountPoint}' does not support diff()`);let l=a.diff(),c=u=>{if(n==="vfs")return o.mountPoint==="/"?u:`${o.mountPoint}${u}`;if(typeof a.rootDir!="string")throw new N("EINVAL",`cannot produce a host-space diff: mount at '${o.mountPoint}' has no real root`);return`${a.rootDir}${u}`};for(let u of l.writes)r.push({...u,path:c(u.path)});for(let u=0;u<l.deletions.length;u++)s.push(c(l.deletions[u])),i.push(l.deletionChangedAt?.[u]??0)}return{writes:r,deletions:s,...i.length>0&&{deletionChangedAt:i}}}restamp(t,n,r="full"){let{fs:s,relativePath:i}=this.routePath(t),o=s.restamp;typeof o=="function"&&o.call(s,i,n,r)}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){K(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 Dn(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:mt,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:mt,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:mt,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:mt,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 N("EEXIST",`directory already exists, mkdir '${t}'`)}if(this.getChildMountPoints(r).length>0&&n?.recursive)return;let{fs:i,relativePath:o}=this.routePath(t);return i.mkdir(o,n)}async createExclusive(t,n){let r=z(t),s=n.directory?"mkdir":"open";if(this.mounts.has(r))throw new N("EEXIST",`file already exists, ${s} '${t}'`);let{fs:i,relativePath:o}=this.routePath(t);if(!i.createExclusive)throw new $a(t,s);let a=yt(o);return a!=="/"&&this.getChildMountPoints(yt(r)).length>0&&!await i.exists(a)&&await i.mkdir(a,{recursive:!0}),i.createExclusive(o,n)}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 c of l)r.add(c)}catch(l){if(!it(l,"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 N("EBUSY",`mount point, cannot remove '${t}'`);if(this.getChildMountPoints(r).length>0)throw new N("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&&Mt(t,n))throw new N("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&&Mt(t,n))throw new N("EINVAL",`cannot move '${t}' into itself, '${n}'`);if(this.mounts.has(r))throw new N("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 On(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 N("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=ot(t,o),l=ot(n,o);await this.crossMountCopy(a,l,r)}}else if(s.isSymbolicLink){let i=await this.readlink(t);await this.symlink(i,n)}}mkdirSync(t,n){let{fs:r,relativePath:s}=this.routePath(t),i=r;if(!i.mkdirSync)throw new N("ENOSYS",`function not implemented, mkdir '${t}'`);i.mkdirSync(s,n)}writeFileSync(t,n){let{fs:r,relativePath:s}=this.routePath(t),i=r;if(!i.writeFileSync)throw new N("ENOSYS",`function not implemented, write '${t}'`);i.writeFileSync(s,n)}async utimes(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.utimes(i,n,r)}};function Xa(e){let t={commands:new Set,definedFunctions:new Set,definedAliases:new Set};return pi(e,t),{commands:[...t.commands],definedFunctions:t.definedFunctions,definedAliases:t.definedAliases}}function bd(e){return e.parts.length===1&&e.parts[0].type==="Literal"?e.parts[0].value:null}function Sd(e,t){for(let n of e){let r=n.parts[0];if(r?.type!=="Literal")continue;let s=/^([A-Za-z_][A-Za-z0-9_]*)=/.exec(r.value);s&&t.definedAliases.add(s[1])}}function pi(e,t){for(let n of e.statements)Pt(n,t)}function Pt(e,t){for(let n of e.pipelines)Ad(n,t)}function Ad(e,t){for(let n of e.commands)Ya(n,t)}function Ya(e,t){switch(e.type){case"SimpleCommand":if(e.name){let n=bd(e.name);n&&(t.commands.add(n),n==="alias"&&Sd(e.args,t)),Fe(e.name.parts,t)}for(let n of e.args)Fe(n.parts,t);for(let n of e.assignments)if(n.value&&Fe(n.value.parts,t),n.array)for(let r of n.array)Fe(r.parts,t);for(let n of e.redirections)n.target.type==="Word"?Fe(n.target.parts,t):n.target.type==="HereDoc"&&!n.target.quoted&&Fe(n.target.content.parts,t);break;case"If":for(let n of e.clauses){for(let r of n.condition)Pt(r,t);for(let r of n.body)Pt(r,t)}if(e.elseBody)for(let n of e.elseBody)Pt(n,t);break;case"For":if(e.words)for(let n of e.words)Fe(n.parts,t);for(let n of e.body)Pt(n,t);break;case"CStyleFor":for(let n of e.body)Pt(n,t);break;case"While":case"Until":for(let n of e.condition)Pt(n,t);for(let n of e.body)Pt(n,t);break;case"Case":Fe(e.word.parts,t);for(let n of e.items)for(let r of n.body)Pt(r,t);break;case"Subshell":case"Group":for(let n of e.body)Pt(n,t);break;case"ArithmeticCommand":case"ConditionalCommand":break;case"FunctionDef":t.definedFunctions.add(e.name),Ya(e.body,t);break}}function Fe(e,t){for(let n of e)switch(n.type){case"CommandSubstitution":pi(n.body,t);break;case"ProcessSubstitution":pi(n.body,t);break;case"DoubleQuoted":Fe(n.parts,t);break;case"ParameterExpansion":n.operation&&Ja(n.operation,t);break}}function Ja(e,t){switch(e.type){case"DefaultValue":case"AssignDefault":case"UseAlternative":Fe(e.word.parts,t);break;case"ErrorIfUnset":e.word&&Fe(e.word.parts,t);break;case"PatternRemoval":Fe(e.pattern.parts,t);break;case"PatternReplacement":Fe(e.pattern.parts,t),e.replacement&&Fe(e.replacement.parts,t);break;case"CaseModification":e.pattern&&Fe(e.pattern.parts,t);break;case"Indirection":e.innerOp&&Ja(e.innerOp,t);break}}function jr(e,t){return e===`/bin/${t}`||e===`/usr/bin/${t}`}async function Hr(e,t,n){if(t.includes("/")){let o=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(o))return{error:"not_found",path:o};try{let a=await e.fs.stat(o);if(a.isDirectory)return{error:"permission_denied",path:o};let l=o.split("/").pop()||t,c=e.commands.get(l);return c&&jr(o,l)?{cmd:c,path:o}:(a.mode&73)!==0?{script:!0,path:o}:{error:"permission_denied",path:o}}catch{return{error:"not_found",path:o}}}if(!n&&e.state.hashTable){let o=e.state.hashTable.get(t);if(o){try{let a=await e.fs.stat(o);if(!a.isDirectory){let l=e.commands.get(t);if(l&&jr(o,t))return{cmd:l,path:o};if((a.mode&73)!==0)return{script:!0,path:o}}}catch{}e.state.hashTable.delete(t)}}let s=(n??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let o of s){if(!o)continue;let l=`${o.startsWith("/")?o:e.fs.resolvePath(e.state.cwd,o)}/${t}`;if(await e.fs.exists(l))try{let c=await e.fs.stat(l);if(c.isDirectory)continue;let u=(c.mode&73)!==0,f=e.commands.get(t),d=jr(l,t);if(f&&d)return{cmd:f,path:l};if(u){if(f&&!d)return{script:!0,path:l};if(!f)return{script:!0,path:l}}}catch{}}if(!await e.fs.exists("/usr/bin")){let o=e.commands.get(t);if(o)return{cmd:o,path:`/usr/bin/${t}`}}return null}async function Gr(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(jr(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 Me(e){return{kind:e.kind,elements:new Map(e.elements)}}function at(e){return new Map(Array.from(e??[],([t,n])=>[t,Me(n)]))}function xe(e,t){return e.state.arrays?.get(t)}function ar(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=ar(e,t,n);return r.kind=n,r}function Ce(e,t){return e.state.arrays?.has(t)??!1}function oe(e,t,n){return xe(e,t)?.elements.get(String(n))}function Xt(e,t,n){return xe(e,t)?.elements.has(String(n))??!1}function j(e,t,n,r,s){let i=ar(e,t,s),o=String(n);if(!i.elements.has(o)&&i.elements.size>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(M(r)>e.limits.maxStringLength)throw new P(`array value string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");i.elements.set(o,r)}function Sn(e,t,n,r=!1){let s=new Set(r?[]:xe(e,t)?.elements.keys()??[]);for(let i of n)if(s.add(String(i)),s.size>e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements")}function An(e,t,n){return xe(e,t)?.elements.delete(String(n))??!1}function lr(e,t){e.state.arrays?.delete(t),e.state.associativeArrays?.delete(t)}function Se(e,t){return Array.from(xe(e,t)?.elements.keys()??[]).filter(r=>/^(0|[1-9]\d*)$/.test(r)).map(Number).sort((r,s)=>r-s)}function ge(e,t){ar(e,t,e.state.associativeArrays?.has(t)?"associative":"indexed").elements.clear()}function Ct(e,t){return Array.from(xe(e,t)?.elements.keys()??[]).sort()}function Zr(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function hi(e){if(e.parts.length<2)return null;let t=e.parts[0],n=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let r,s=n,i=1;if(n.type==="Literal"&&n.value.startsWith("]")){let f=n.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))r=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let d=e.parts[2];if(d.type!=="Literal"||!d.value.startsWith("=")&&!d.value.startsWith("+="))return null;r=t.pattern.slice(1),s=d,i=2}else return null}else if(t.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(n.type==="SingleQuoted")r=n.value;else{r="";for(let d of n.parts)(d.type==="Literal"||d.type==="Escaped")&&(r+=d.value)}s=f,i=2}else if(t.pattern.endsWith("]")){if(n.type!=="Literal"||!n.value.startsWith("=")&&!n.value.startsWith("+="))return null;r=t.pattern.slice(1,-1)}else return null;r=Zr(r);let o;if(s.type!=="Literal")return null;s.value.startsWith("]=")||s.value.startsWith("]+=")?o=s.value.slice(1):o=s.value;let a=o.startsWith("+=");if(!a&&!o.startsWith("="))return null;let l=[],c=a?2:1,u=o.slice(c);u&&l.push({type:"Literal",value:u});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?l.push({type:"Literal",value:vd(d)}):l.push(d)}return{key:r,valueParts:l,append:a}}function vd(e){return`{${e.items.map(n=>{if(n.type==="Range"){let r=n.startStr??String(n.start),s=n.endStr??String(n.end),i=`${r}..${s}`;return n.step&&(i+=`..${n.step}`),i}return Mn(n.word)}).join(",")}}`}function Mn(e){let t="";for(let n of e.parts)switch(n.type){case"Literal":t+=n.value;break;case"Glob":t+=n.pattern;break;case"SingleQuoted":t+=n.value;break;case"DoubleQuoted":for(let r of n.parts)(r.type==="Literal"||r.type==="Escaped")&&(t+=r.value);break;case"Escaped":t+=n.value;break;case"BraceExpansion":t+="{",t+=n.items.map(r=>r.type==="Range"?`${r.startStr}..${r.endStr}${r.step?`..${r.step}`:""}`:Mn(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",n.user&&(t+=n.user);break}return t}var cr=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function el(e){return cr.has(e)}var ur=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]);var xd=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],kd=["braceexpand","hashall","interactive-comments"];function mi(e){let t=[],n=[...kd.map(r=>({name:r,enabled:!0})),...xd.map(r=>({name:r,enabled:e[r]}))].sort((r,s)=>r.name.localeCompare(s.name));for(let r of n)r.enabled&&t.push(r.name);return t.join(":")}function Bn(e){e.state.env.set("SHELLOPTS",mi(e.state.options))}var $d=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function yi(e){let t=[];for(let n of $d)e[n]&&t.push(n);return t.join(":")}function gi(e){e.state.env.set("BASHOPTS",yi(e.state.shoptOptions))}var F={script(e){return{type:"Script",statements:e}},statement(e,t=[],n=!1,r,s){let i={type:"Statement",pipelines:e,operators:t,background:n};return r&&(i.deferredError=r),s!==void 0&&(i.sourceText=s),i},pipeline(e,t=!1,n=!1,r=!1,s){return{type:"Pipeline",commands:e,negated:t,timed:n,timePosix:r,pipeStderr:s}},simpleCommand(e,t=[],n=[],r=[]){return{type:"SimpleCommand",name:e,args:t,assignments:n,redirections:r}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},processSubstitution(e,t){return{type:"ProcessSubstitution",body:e,direction:t}},assignment(e,t,n=!1,r=null){return{type:"Assignment",name:e,value:t,append:n,array:r}},redirection(e,t,n=null,r){let s={type:"Redirection",fd:n,operator:e,target:t};return r&&(s.fdVariable=r),s},hereDoc(e,t,n=!1,r=!1,s){let i={type:"HereDoc",delimiter:e,content:t,stripTabs:n,quoted:r};return s!==void 0&&(i.terminated=s),i},ifNode(e,t=null,n=[]){return{type:"If",clauses:e,elseBody:t,redirections:n}},forNode(e,t,n,r=[]){return{type:"For",variable:e,words:t,body:n,redirections:r}},whileNode(e,t,n=[]){return{type:"While",condition:e,body:t,redirections:n}},untilNode(e,t,n=[]){return{type:"Until",condition:e,body:t,redirections:n}},caseNode(e,t,n=[]){return{type:"Case",word:e,items:t,redirections:n}},caseItem(e,t,n=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:n}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,n=[],r){return{type:"FunctionDef",name:e,body:t,redirections:n,sourceFile:r}},conditionalCommand(e,t=[],n){return{type:"ConditionalCommand",expression:e,redirections:t,line:n}},arithmeticCommand(e,t=[],n){return{type:"ArithmeticCommand",expression:e,redirections:t,line:n}}};function tl(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 Qr(e,t){let n="",r=t,s=0,i=!1,o,a=l=>l===" "||l===" "||l===`
14
17
  `||l===";"||l==="&"||l==="|"||l==="<"||l===">"||l==="("||l===")";for(;r<e.length;){let l=e[r];if(l==="'"){let c=s>0;for(c||(i=!0),c&&(n+=l),r++;r<e.length&&e[r]!=="'";)n+=e[r],r++;r<e.length?(c&&(n+=e[r]),r++):o=l;continue}if(l==='"'){let c=s>0;for(c||(i=!0),c&&(n+=l),r++;r<e.length&&e[r]!=='"';){if(e[r]==="\\"&&r+1<e.length){if(c){n+=e.slice(r,r+2),r+=2;continue}let u=e[r+1];if(u==="$"||u==="`"||u==='"'||u==="\\"||u===`
15
18
  `){r+=2,u!==`
16
19
  `&&(n+=u);continue}}n+=e[r],r++}r<e.length?(c&&(n+=e[r]),r++):o=l;continue}if(l==="\\"&&r+1<e.length){if(s>0){n+=e.slice(r,r+2),r+=2;continue}i=!0;let c=e[r+1];c!==`
17
- `&&(n+=c),r+=2;continue}if(s===0&&(l==="$"||l==="<"||l===">")&&e[r+1]==="("){n+=`${l}(`,s=1,r+=2;continue}if(s===0&&a(l))break;s>0&&(l==="("?s++:l===")"&&s--),n+=l,r++}return{delim:n,endPos:r,quoted:i,unclosedQuote:o,unclosedSubstitution:s>0}}function Ed(e,t,n){let r=t+1;for(let{delim:s,stripTabs:i}of n)for(;;){if(r>=e.length)return e.length;let o=e.indexOf(`
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 Za(e,t,n){let r=1,s=t,i=!1,o=!1,a=0,l=!1,c="",u=[],f=0;for(;s<e.length&&r>0;){let d=e[s];if(i)d==="'"&&(i=!1);else if(o)d==="\\"&&s+1<e.length?s++:d==='"'&&(o=!1);else{if(d==="("&&e[s+1]==="("?f++:d===")"&&e[s+1]===")"&&f>0&&f--,f===0&&d==="<"&&e[s+1]==="<"&&e[s+2]!=="<"){let p=s+2,h=!1;for(e[p]==="-"&&(h=!0,p++);e[p]===" "||e[p]===" ";)p++;let{delim:y,endPos:E,unclosedQuote:S,unclosedSubstitution:g}=Hr(e,p);if(S&&n(`unexpected EOF while looking for matching \`${S}'`),g&&n("unexpected EOF while looking for matching `)'"),y.length>0){u.push({delim:y,stripTabs:h}),c="",s=E;continue}}if(d===`
19
- `&&u.length>0){let p=Ed(e,s,u);u.length=0,c="",s=p;continue}d==="'"?(i=!0,c=""):d==='"'?(o=!0,c=""):d==="\\"&&s+1<e.length?(s++,c=""):/[a-zA-Z_]/.test(d)?c+=d:(c==="case"?(a++,l=!1):c==="in"&&a>0?l=!0:c==="esac"&&a>0&&(a--,l=!1),c="",d==="("?s>0&&e[s-1]==="$"?r++:l||r++:d===")"?l?l=!1:r--:d===";"&&a>0&&s+1<e.length&&e[s+1]===";"&&(l=!0))}r>0&&s++}return r>0&&n("unexpected EOF while looking for matching `)'"),s}function Qa(e,t,n,r){let s=t+2,i=Za(e,s,r),o=e.slice(s,i),l=n().parse(o);return{part:F.commandSubstitution(l,!1),endIndex:i+1}}function Ka(e,t,n,r){let s=e[t]==="<"?"input":"output",i=t+2,o=Za(e,i,r),a=n().parse(e.slice(i,o));return{part:F.processSubstitution(a,s),endIndex:o+1}}function Xa(e,t,n,r,s){let o=t+1,a="";for(;o<e.length&&e[o]!=="`";)if(e[o]==="\\"){let u=e[o+1];u==="$"||u==="`"||u==="\\"||u===`
20
+ `&&(n+=c),r+=2;continue}if(s===0&&(l==="$"||l==="<"||l===">")&&e[r+1]==="("){n+=`${l}(`,s=1,r+=2;continue}if(s===0&&a(l))break;s>0&&(l==="("?s++:l===")"&&s--),n+=l,r++}return{delim:n,endPos:r,quoted:i,unclosedQuote:o,unclosedSubstitution:s>0}}function Pd(e,t,n){let r=t+1;for(let{delim:s,stripTabs:i}of n)for(;;){if(r>=e.length)return e.length;let o=e.indexOf(`
21
+ `,r);o===-1&&(o=e.length);let a=e.slice(r,o);if(i&&(a=a.replace(/^\t+/,"")),a===s){r=o+1;break}if(o>=e.length)return e.length;r=o+1}return Math.min(r,e.length)}function nl(e,t,n){let r=1,s=t,i=!1,o=!1,a=0,l=!1,c="",u=[],f=0;for(;s<e.length&&r>0;){let d=e[s];if(i)d==="'"&&(i=!1);else if(o)d==="\\"&&s+1<e.length?s++:d==='"'&&(o=!1);else{if(d==="("&&e[s+1]==="("?f++:d===")"&&e[s+1]===")"&&f>0&&f--,f===0&&d==="<"&&e[s+1]==="<"&&e[s+2]!=="<"){let p=s+2,h=!1;for(e[p]==="-"&&(h=!0,p++);e[p]===" "||e[p]===" ";)p++;let{delim:y,endPos:E,unclosedQuote:S,unclosedSubstitution:m}=Qr(e,p);if(S&&n(`unexpected EOF while looking for matching \`${S}'`),m&&n("unexpected EOF while looking for matching `)'"),y.length>0){u.push({delim:y,stripTabs:h}),c="",s=E;continue}}if(d===`
22
+ `&&u.length>0){let p=Pd(e,s,u);u.length=0,c="",s=p;continue}d==="'"?(i=!0,c=""):d==='"'?(o=!0,c=""):d==="\\"&&s+1<e.length?(s++,c=""):/[a-zA-Z_]/.test(d)?c+=d:(c==="case"?(a++,l=!1):c==="in"&&a>0?l=!0:c==="esac"&&a>0&&(a--,l=!1),c="",d==="("?s>0&&e[s-1]==="$"?r++:l||r++:d===")"?l?l=!1:r--:d===";"&&a>0&&s+1<e.length&&e[s+1]===";"&&(l=!0))}r>0&&s++}return r>0&&n("unexpected EOF while looking for matching `)'"),s}function rl(e,t,n,r){let s=t+2,i=nl(e,s,r),o=e.slice(s,i),l=n().parse(o);return{part:F.commandSubstitution(l,!1),endIndex:i+1}}function sl(e,t,n,r){let s=e[t]==="<"?"input":"output",i=t+2,o=nl(e,i,r),a=n().parse(e.slice(i,o));return{part:F.processSubstitution(a,s),endIndex:o+1}}function il(e,t,n,r,s){let o=t+1,a="";for(;o<e.length&&e[o]!=="`";)if(e[o]==="\\"){let u=e[o+1];u==="$"||u==="`"||u==="\\"||u===`
20
23
  `||n&&u==='"'?(u!==`
21
- `&&(a+=u),o+=2):(a+=e[o],o++)}else a+=e[o],o++;o>=e.length&&s("unexpected EOF while looking for matching ``'");let c=r().parse(a);return{part:F.commandSubstitution(c,!0),endIndex:o+1}}var bd=10485760,w;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(w||(w={}));var Je=class extends Error{line;column;constructor(t,n,r){super(`line ${n}: ${t}`),this.line=n,this.column=r,this.name="LexerError"}},hi=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]]),Sd=new Set(hi.values());function mi(e){return Sd.has(e)}function Ya(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return!1;let n=e.slice(t[0].length);if(n===""||n==="+")return!0;if(n[0]==="["){let r=0,s=0;for(;s<n.length;s++)if(n[s]==="[")r++;else if(n[s]==="]"&&(r--,r===0))break;if(r!==0||s>=n.length)return!1;let i=n.slice(s+1);return i===""||i==="+"}return!1}function Ja(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];if(r==="[")t++;else if(r==="]")t--;else{if(t===0&&r==="=")return n;if(t===0&&r==="+"&&e[n+1]==="=")return n+1}}return-1}var Ad=[[";",";","&",w.SEMI_SEMI_AND],["<","<","<",w.TLESS],["&",">",">",w.AND_DGREAT]],vd=[["[","[",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]],xd=new Map([["|",w.PIPE],["&",w.AMP],[";",w.SEMICOLON],["(",w.LPAREN],[")",w.RPAREN],["<",w.LESS],[">",w.GREAT]]);function kd(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function el(e){return e===" "||e===" "||e===`
22
- `||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var Gr=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];pendingHeredocDelimiterMode;dparenDepth=0;maxHeredocSize;constructor(t,n){this.input=t,this.maxHeredocSize=n?.maxHeredocSize??bd}tokenize(){let n=this.input.length,r=this.tokens,s=this.pendingHeredocs;for(;this.pos<n;){if(s.length>0&&r.length>0&&r[r.length-1].type===w.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=n)break;let i=this.nextToken();i&&r.push(i)}return s.length>0&&this.readHeredocContent(),r.push({type:w.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let t=this.input,n=t.length,r=this.pos,s=this.column,i=this.line;for(;r<n;){let o=t[r];if(o===" "||o===" ")r++,s++;else if(o==="\\"&&t[r+1]===`
24
+ `&&(a+=u),o+=2):(a+=e[o],o++)}else a+=e[o],o++;o>=e.length&&s("unexpected EOF while looking for matching ``'");let c=r().parse(a);return{part:F.commandSubstitution(c,!0),endIndex:o+1}}var Cd=10485760,w;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(w||(w={}));var Je=class extends Error{line;column;constructor(t,n,r){super(`line ${n}: ${t}`),this.line=n,this.column=r,this.name="LexerError"}},wi=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]]),Nd=new Set(wi.values());function Ei(e){return Nd.has(e)}function ol(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 al(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];if(r==="[")t++;else if(r==="]")t--;else{if(t===0&&r==="=")return n;if(t===0&&r==="+"&&e[n+1]==="=")return n+1}}return-1}var Rd=[[";",";","&",w.SEMI_SEMI_AND],["<","<","<",w.TLESS],["&",">",">",w.AND_DGREAT]],Dd=[["[","[",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]],Id=new Map([["|",w.PIPE],["&",w.AMP],[";",w.SEMICOLON],["(",w.LPAREN],[")",w.RPAREN],["<",w.LESS],[">",w.GREAT]]);function Od(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function ll(e){return e===" "||e===" "||e===`
25
+ `||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var Kr=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];pendingHeredocDelimiterMode;dparenDepth=0;maxHeredocSize;constructor(t,n){this.input=t,this.maxHeredocSize=n?.maxHeredocSize??Cd}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
26
  `)r+=2,i++,s=1;else break}this.pos=r,this.column=s,this.line=i}nextToken(){let t=this.input,n=this.pos,r=this.line,s=this.column,i=t[n],o=t[n+1],a=t[n+2],l=this.pendingHeredocDelimiterMode;if(this.pendingHeredocDelimiterMode=void 0,l!==void 0&&i!==`
24
27
  `&&!(i==="#"&&this.dparenDepth===0))return this.readHeredocDelimiterToken(n,r,s,l);if(i==="#"&&this.dparenDepth===0)return this.readComment(n,r,s);if(i===`
25
28
  `)return this.pos=n+1,this.line++,this.column=1,{type:w.NEWLINE,value:`
26
- `,start:n,end:n+1,line:r,column:s};if(i==="<"&&o==="<"&&a==="-")return this.pos=n+3,this.column=s+3,this.pendingHeredocDelimiterMode=!0,this.makeToken(w.DLESSDASH,"<<-",n,r,s);for(let[u,f,d,p]of Ad)if(i===u&&o===f&&a===d)return this.pos=n+3,this.column=s+3,this.makeToken(p,u+f+d,n,r,s);if(i==="<"&&o==="<")return this.pos=n+2,this.column=s+2,this.pendingHeredocDelimiterMode=!1,this.makeToken(w.DLESS,"<<",n,r,s);if(i==="("&&o==="("){let u=this.tokens[this.tokens.length-1];return this.dparenDepth===0&&u?.end===n&&(u.type===w.LESS||u.type===w.GREAT)?(this.pos=n+1,this.column=s+1,this.makeToken(w.LPAREN,"(",n,r,s)):this.dparenDepth>0?(this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(w.LPAREN,"(",n,r,s)):this.looksLikeNestedSubshells(n+2)||this.dparenClosesWithSpacedParens(n+2)?(this.pos=n+1,this.column=s+1,this.makeToken(w.LPAREN,"(",n,r,s)):(this.pos=n+2,this.column=s+2,this.dparenDepth=1,this.makeToken(w.DPAREN_START,"((",n,r,s))}if(i===")"&&o===")")return this.dparenDepth===1?(this.pos=n+2,this.column=s+2,this.dparenDepth=0,this.makeToken(w.DPAREN_END,"))",n,r,s)):this.dparenDepth>1?(this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(w.RPAREN,")",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(w.RPAREN,")",n,r,s));for(let[u,f,d]of vd)if(!(u==="("&&f==="("||u===")"&&f===")")&&!(this.dparenDepth>0&&u===";"&&(d===w.DSEMI||d===w.SEMI_AND||d===w.SEMI_SEMI_AND))&&i===u&&o===f){if(d===w.DBRACK_START||d===w.DBRACK_END){let 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,u+f,n,r,s)}if(i==="("&&this.dparenDepth>0)return this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(w.LPAREN,"(",n,r,s);if(i===")"&&this.dparenDepth>1)return this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(w.RPAREN,")",n,r,s);let c=xd.get(i);if(c!==void 0)return this.pos=n+1,this.column=s+1,this.makeToken(c,i,n,r,s);if(i==="{"){let u=this.scanFdVariable(n);return u!==null?(this.pos=u.end,this.column=s+(u.end-n),{type:w.FD_VARIABLE,value:u.varname,start:n,end:u.end,line:r,column:s}):o==="}"?(this.pos=n+2,this.column=s+2,{type:w.WORD,value:"{}",start:n,end:n+2,line:r,column:s,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(n)!==null?this.readWordWithBraceExpansion(n,r,s):this.scanLiteralBraceWord(n)!==null?this.readWordWithBraceExpansion(n,r,s):o!==void 0&&o!==" "&&o!==" "&&o!==`
29
+ `,start:n,end:n+1,line:r,column:s};if(i==="<"&&o==="<"&&a==="-")return this.pos=n+3,this.column=s+3,this.pendingHeredocDelimiterMode=!0,this.makeToken(w.DLESSDASH,"<<-",n,r,s);for(let[u,f,d,p]of Rd)if(i===u&&o===f&&a===d)return this.pos=n+3,this.column=s+3,this.makeToken(p,u+f+d,n,r,s);if(i==="<"&&o==="<")return this.pos=n+2,this.column=s+2,this.pendingHeredocDelimiterMode=!1,this.makeToken(w.DLESS,"<<",n,r,s);if(i==="("&&o==="("){let u=this.tokens[this.tokens.length-1];return this.dparenDepth===0&&u?.end===n&&(u.type===w.LESS||u.type===w.GREAT)?(this.pos=n+1,this.column=s+1,this.makeToken(w.LPAREN,"(",n,r,s)):this.dparenDepth>0?(this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(w.LPAREN,"(",n,r,s)):this.looksLikeNestedSubshells(n+2)||this.dparenClosesWithSpacedParens(n+2)?(this.pos=n+1,this.column=s+1,this.makeToken(w.LPAREN,"(",n,r,s)):(this.pos=n+2,this.column=s+2,this.dparenDepth=1,this.makeToken(w.DPAREN_START,"((",n,r,s))}if(i===")"&&o===")")return this.dparenDepth===1?(this.pos=n+2,this.column=s+2,this.dparenDepth=0,this.makeToken(w.DPAREN_END,"))",n,r,s)):this.dparenDepth>1?(this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(w.RPAREN,")",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(w.RPAREN,")",n,r,s));for(let[u,f,d]of Dd)if(!(u==="("&&f==="("||u===")"&&f===")")&&!(this.dparenDepth>0&&u===";"&&(d===w.DSEMI||d===w.SEMI_AND||d===w.SEMI_SEMI_AND))&&i===u&&o===f){if(d===w.DBRACK_START||d===w.DBRACK_END){let p=t[n+2];if(p!==void 0&&p!==" "&&p!==" "&&p!==`
30
+ `&&p!==";"&&p!=="&"&&p!=="|"&&p!=="("&&p!==")"&&p!=="<"&&p!==">")break}return this.pos=n+2,this.column=s+2,this.makeToken(d,u+f,n,r,s)}if(i==="("&&this.dparenDepth>0)return this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(w.LPAREN,"(",n,r,s);if(i===")"&&this.dparenDepth>1)return this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(w.RPAREN,")",n,r,s);let c=Id.get(i);if(c!==void 0)return this.pos=n+1,this.column=s+1,this.makeToken(c,i,n,r,s);if(i==="{"){let u=this.scanFdVariable(n);return u!==null?(this.pos=u.end,this.column=s+(u.end-n),{type:w.FD_VARIABLE,value:u.varname,start:n,end:u.end,line:r,column:s}):o==="}"?(this.pos=n+2,this.column=s+2,{type:w.WORD,value:"{}",start:n,end:n+2,line:r,column:s,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(n)!==null?this.readWordWithBraceExpansion(n,r,s):this.scanLiteralBraceWord(n)!==null?this.readWordWithBraceExpansion(n,r,s):o!==void 0&&o!==" "&&o!==" "&&o!==`
28
31
  `?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(w.LBRACE,"{",n,r,s))}return i==="}"?this.isWordCharFollowing(n+1)?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(w.RBRACE,"}",n,r,s)):i==="!"?o==="="?(this.pos=n+2,this.column=s+2,this.makeToken(w.WORD,"!=",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(w.BANG,"!",n,r,s)):this.readWord(n,r,s)}looksLikeNestedSubshells(t){let n=this.input,r=n.length,s=t;for(;s<r&&(n[s]===" "||n[s]===" ");)s++;if(s>=r)return!1;let i=n[s];if(i==="(")return this.looksLikeNestedSubshells(s+1);let o=/[a-zA-Z_]/.test(i),a=i==="!"||i==="[";if(!o&&!a)return!1;let l=s;for(;l<r&&/[a-zA-Z0-9_\-.]/.test(n[l]);)l++;if(l===s)return a;let c=l;for(;c<r&&(n[c]===" "||n[c]===" ");)c++;if(c>=r)return!1;let u=n[c];if(u==="="&&n[c+1]!=="="||u===`
29
32
  `||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]!==`
30
33
  `;){if(n[f]===")")return!0;f++}return!1}if(u===")"){let f=c+1;for(;f<r&&(n[f]===" "||n[f]===" ");)f++;if(n[f]==="|"&&n[f+1]==="|"||n[f]==="&"&&n[f+1]==="&"||n[f]===";"||n[f]==="|"&&n[f+1]!=="|")return!0}return!1}makeToken(t,n,r,s,i){return{type:t,value:n,start:r,end:this.pos,line:s,column:i}}readComment(t,n,r){let s=this.input,i=s.length,o=this.pos;for(;o<i&&s[o]!==`
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 m=s[o];if(m===" "||m===" "||m===`
32
- `||m===";"||m==="&"||m==="|"||m==="("||m===")"||m==="<"||m===">"||m==="'"||m==='"'||m==="\\"||m==="$"||m==="`"||m==="{"||m==="}"||m==="~"||m==="*"||m==="?"||m==="[")break;o++}if(o>a){let m=s[o];if(!(m==="("&&o>a&&"@*+?!".includes(s[o-1]))){if(o>=i||m===" "||m===" "||m===`
33
- `||m===";"||m==="&"||m==="|"||m==="("||m===")"||m==="<"||m===">"){let b=s.slice(a,o);this.pos=o,this.column=r+(o-a);let A=hi.get(b);if(A!==void 0)return{type:A,value:b,start:t,end:o,line:n,column:r};let x=Ja(b);return x>0&&Ya(b.slice(0,x))?{type:w.ASSIGNMENT_WORD,value:b,start:t,end:o,line:n,column:r}:/^[0-9]+$/.test(b)?{type:w.NUMBER,value:b,start:t,end:o,line:n,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(b)?{type:w.NAME,value:b,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}:{type:w.WORD,value:b,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}}}}o=this.pos;let l=this.column,c=this.line,u="",f=!1,d=!1,p=!1,h=!1,y=s[o]==='"'||s[o]==="'",E=!1,S=0;for(;o<i;){let m=s[o];if(!p&&!h){if(m==="("&&u.length>0&&"@*+?!".includes(u[u.length-1])){let b=this.scanExtglobPattern(o);if(b!==null){u+=b.content,o=b.end,l+=b.content.length;continue}}if(m==="["&&S===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){let b=o+1<i?s[o+1]:"";if(b==="^"||b==="!"){u+=m,o++,l++;continue}S=1,u+=m,o++,l++;continue}}else if(m==="["&&S>0){u.length>0&&u[u.length-1]!=="\\"&&S++,u+=m,o++,l++;continue}else if(m==="]"&&S>0){u.length>0&&u[u.length-1]!=="\\"&&S--,u+=m,o++,l++;continue}if(S>0){if(m===`
34
- `)break;u+=m,o++,l++;continue}if(m===" "||m===" "||m===`
35
- `||m===";"||m==="&"||m==="|"||m==="("||m===")"||m==="<"||m===">")break}if(m==="$"&&o+1<i&&s[o+1]==="'"&&!p&&!h){for(u+="$'",o+=2,l+=2;o<i&&s[o]!=="'";)s[o]==="\\"&&o+1<i?(u+=s[o]+s[o+1],o+=2,l+=2):(u+=s[o],o++,l++);o<i&&(u+="'",o++,l++);continue}if(m==="$"&&o+1<i&&s[o+1]==='"'&&!p&&!h){o++,l++,h=!0,f=!0,u===""&&(y=!0),o++,l++;continue}if(m==="'"&&!h){if(p)if(p=!1,!y||E)u+=m;else{let b=o+1<i?s[o+1]:"";b&&!el(b)&&b!=="'"&&(b==='"'?(E=!0,u+=m,d=!1,f=!1):(E=!0,u+=m))}else p=!0,y&&!E?(d=!0,f=!0):u+=m;o++,l++;continue}if(m==='"'&&!p){if(h)if(h=!1,!y||E)u+=m;else{let b=o+1<i?s[o+1]:"";b&&!el(b)&&b!=='"'&&(b==="'"?(E=!0,u+=m,d=!1,f=!1):(E=!0,u+=m))}else h=!0,y&&!E?f=!0:u+=m;o++,l++;continue}if(m==="\\"&&!p&&o+1<i){let b=s[o+1];if(b===`
34
+ `;)o++;let a=s.slice(t,o);return this.pos=o,this.column=r+(o-t),{type:w.COMMENT,value:a,start:t,end:o,line:n,column:r}}readWord(t,n,r){let s=this.input,i=s.length,o=this.pos,a=o;for(;o<i;){let g=s[o];if(g===" "||g===" "||g===`
35
+ `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">"||g==="'"||g==='"'||g==="\\"||g==="$"||g==="`"||g==="{"||g==="}"||g==="~"||g==="*"||g==="?"||g==="[")break;o++}if(o>a){let g=s[o];if(!(g==="("&&o>a&&"@*+?!".includes(s[o-1]))){if(o>=i||g===" "||g===" "||g===`
36
+ `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">"){let b=s.slice(a,o);this.pos=o,this.column=r+(o-a);let v=wi.get(b);if(v!==void 0)return{type:v,value:b,start:t,end:o,line:n,column:r};let x=al(b);return x>0&&ol(b.slice(0,x))?{type:w.ASSIGNMENT_WORD,value:b,start:t,end:o,line:n,column:r}:/^[0-9]+$/.test(b)?{type:w.NUMBER,value:b,start:t,end:o,line:n,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(b)?{type:w.NAME,value:b,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}:{type:w.WORD,value:b,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}}}}o=this.pos;let l=this.column,c=this.line,u="",f=!1,d=!1,p=!1,h=!1,y=s[o]==='"'||s[o]==="'",E=!1,S=0;for(;o<i;){let g=s[o];if(!p&&!h){if(g==="("&&u.length>0&&"@*+?!".includes(u[u.length-1])){let b=this.scanExtglobPattern(o);if(b!==null){u+=b.content,o=b.end,l+=b.content.length;continue}}if(g==="["&&S===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){let b=o+1<i?s[o+1]:"";if(b==="^"||b==="!"){u+=g,o++,l++;continue}S=1,u+=g,o++,l++;continue}}else if(g==="["&&S>0){u.length>0&&u[u.length-1]!=="\\"&&S++,u+=g,o++,l++;continue}else if(g==="]"&&S>0){u.length>0&&u[u.length-1]!=="\\"&&S--,u+=g,o++,l++;continue}if(S>0){if(g===`
37
+ `)break;u+=g,o++,l++;continue}if(g===" "||g===" "||g===`
38
+ `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">")break}if(g==="$"&&o+1<i&&s[o+1]==="'"&&!p&&!h){for(u+="$'",o+=2,l+=2;o<i&&s[o]!=="'";)s[o]==="\\"&&o+1<i?(u+=s[o]+s[o+1],o+=2,l+=2):(u+=s[o],o++,l++);o<i&&(u+="'",o++,l++);continue}if(g==="$"&&o+1<i&&s[o+1]==='"'&&!p&&!h){o++,l++,h=!0,f=!0,u===""&&(y=!0),o++,l++;continue}if(g==="'"&&!h){if(p)if(p=!1,!y||E)u+=g;else{let b=o+1<i?s[o+1]:"";b&&!ll(b)&&b!=="'"&&(b==='"'?(E=!0,u+=g,d=!1,f=!1):(E=!0,u+=g))}else p=!0,y&&!E?(d=!0,f=!0):u+=g;o++,l++;continue}if(g==='"'&&!p){if(h)if(h=!1,!y||E)u+=g;else{let b=o+1<i?s[o+1]:"";b&&!ll(b)&&b!=='"'&&(b==="'"?(E=!0,u+=g,d=!1,f=!1):(E=!0,u+=g))}else h=!0,y&&!E?f=!0:u+=g;o++,l++;continue}if(g==="\\"&&!p&&o+1<i){let b=s[o+1];if(b===`
36
39
  `){o+=2,c++,l=1;continue}if(h){if(b==='"'||b==="\\"||b==="$"||b==="`"||b===`
37
40
  `){if(b===`
38
- `){o+=2,l=1,c++;continue}u+=m+b,o+=2,l+=2;continue}}else{u+=m+b,o+=2,l+=2;continue}}if(m==="$"&&o+1<i&&s[o+1]==="("&&!p){u+=m,o++,l++,u+=s[o],o++,l++;let b=1,A=!1,x=!1,v=0,$=!1,D="",k=[],C=s[o]==="("&&!this.dollarDparenIsSubshell(o),I=C?1:0;for(;b>0&&o<i;){let W=s[o];if(u+=W,A)W==="'"&&(A=!1);else if(x)W==="\\"&&o+1<i?(u+=s[o+1],o++,l++):W==='"'&&(x=!1);else{if(W==="("&&s[o+1]==="("?I++:W===")"&&s[o+1]===")"&&I>0&&I--,I===0&&W==="<"&&s[o+1]==="<"&&s[o+2]!=="<"){let Z=o+2,R=!1;for(s[Z]==="-"&&(R=!0,Z++);s[Z]===" "||s[Z]===" ";)Z++;let{delim:V,endPos:z,unclosedQuote:O,unclosedSubstitution:_}=Hr(s,Z);if(O)throw new Je(`unexpected EOF while looking for matching \`${O}'`,c,l);if(_)throw new Je("unexpected EOF while looking for matching `)'",c,l);if(V.length>0){u+=s.slice(o+1,z),l+=z-o,k.push({delim:V,stripTabs:R}),o=z;continue}}if(W===`
39
- `&&k.length>0){c++,l=0;let Z=o+1;for(let{delim:R,stripTabs:V}of k)for(;!(Z>=i);){let z=s.indexOf(`
40
- `,Z);z===-1&&(z=i);let O=s.slice(Z,z),_=V?O.replace(/^\t+/,""):O;u+=s.slice(Z,Math.min(z+1,i)),z<i&&c++;let M=z>=i;if(Z=z+1,_===R||M)break}k.length=0,l=0,o=Math.min(Z,i);continue}if(W==="'")A=!0,D="";else if(W==='"')x=!0,D="";else if(W==="\\"&&o+1<i)u+=s[o+1],o++,l++,D="";else if(W==="$"&&o+1<i&&s[o+1]==="{"){o++,l++,u+=s[o],o++,l++;let Z=1,R=!1,V=!1;for(;Z>0&&o<i;){let z=s[o];if(z==="\\"&&o+1<i&&!R){u+=z,o++,l++,u+=s[o],o++,l++;continue}u+=z,R?z==="'"&&(R=!1):V?z==='"'&&(V=!1):z==="'"?R=!0:z==='"'?V=!0:z==="{"?Z++:z==="}"&&Z--,z===`
41
- `?(c++,l=0):l++,o++}D="";continue}else if(W==="#"&&!C&&(D===""||/\s/.test(s[o-1]||""))){for(;o+1<i&&s[o+1]!==`
42
- `;)o++,l++,u+=s[o];D=""}else/[a-zA-Z_]/.test(W)?D+=W:(D==="case"?(v++,$=!1):D==="in"&&v>0?$=!0:D==="esac"&&v>0&&(v--,$=!1),D="",W==="("?o>0&&s[o-1]==="$"?b++:$||b++:W===")"?$?$=!1:b--:W===";"&&v>0&&(o+1<i&&s[o+1]===";"||o+1<i&&s[o+1]==="&")&&($=!0))}W===`
43
- `&&(c++,l=0,D=""),o++,l++}continue}if(m==="$"&&o+1<i&&s[o+1]==="["&&!p){u+=m,o++,l++,u+=s[o],o++,l++;let b=1;for(;b>0&&o<i;){let A=s[o];u+=A,A==="["?b++:A==="]"?b--:A===`
44
- `&&(c++,l=0),o++,l++}continue}if(m==="$"&&o+1<i&&s[o+1]==="{"&&!p){u+=m,o++,l++,u+=s[o],o++,l++;let b=1,A=!1,x=!1,v=c,$=l,D=c,k=l;for(;b>0&&o<i;){let C=s[o];if(C==="\\"&&o+1<i&&s[o+1]===`
45
- `){o+=2,c++,l=1;continue}if(C==="\\"&&o+1<i&&!A){u+=C,o++,l++,u+=s[o],o++,l++;continue}u+=C,A?C==="'"&&(A=!1):x?C==='"'&&(x=!1):C==="'"?(A=!0,v=c,$=l):C==='"'?(x=!0,D=c,k=l):C==="{"?b++:C==="}"&&b--,C===`
46
- `&&(c++,l=0),o++,l++}if(A)throw new Je("unexpected EOF while looking for matching `''",v,$);if(x)throw new Je("unexpected EOF while looking for matching `\"'",D,k);continue}if(m==="$"&&o+1<i&&!p){let b=s[o+1];if(b==="#"||b==="?"||b==="$"||b==="!"||b==="@"||b==="*"||b==="-"||b>="0"&&b<="9"){u+=m+b,o+=2,l+=2;continue}}if(m==="`"&&!p){for(u+=m,o++,l++;o<i&&s[o]!=="`";){let b=s[o];u+=b,b==="\\"&&o+1<i&&(u+=s[o+1],o++,l++),b===`
47
- `&&(c++,l=0),o++,l++}o<i&&(u+=s[o],o++,l++);continue}u+=m,o++,m===`
48
- `?(c++,l=1):l++}if(this.pos=o,this.column=l,this.line=c,E&&y&&(u=s[t]+u,f=!1,d=!1),p||h){let m=p?"'":'"';throw new Je(`unexpected EOF while looking for matching \`${m}'`,n,r)}if(!y&&u.length>=2){if(u[0]==="'"&&u[u.length-1]==="'"){let m=u.slice(1,-1);!m.includes("'")&&!m.includes('"')&&(u=m,f=!0,d=!0)}else if(u[0]==='"'&&u[u.length-1]==='"'){let m=u.slice(1,-1),b=!1;for(let A=0;A<m.length;A++){if(m[A]==='"'){b=!0;break}m[A]==="\\"&&A+1<m.length&&A++}b||(u=m,f=!0,d=!1)}}if(u==="")return{type:w.WORD,value:"",start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d};let g=hi.get(u);if(!f&&g!==void 0)return{type:g,value:u,start:t,end:o,line:n,column:r};if(!y){let m=Ja(u);if(m>0&&Ya(u.slice(0,m)))return{type:w.ASSIGNMENT_WORD,value:u,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(u)?{type:w.NUMBER,value:u,start:t,end:o,line:n,column:r}:kd(u)?{type:w.NAME,value:u,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}:{type:w.WORD,value:u,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let n=this.pos,r=this.line,s=this.column,i="",o=!1;for(;this.pos<this.input.length;){let a="",l="",c="";for(;;){for(a="";this.pos<this.input.length&&this.input[this.pos]!==`
41
+ `){o+=2,l=1,c++;continue}u+=g+b,o+=2,l+=2;continue}}else{u+=g+b,o+=2,l+=2;continue}}if(g==="$"&&o+1<i&&s[o+1]==="("&&!p){u+=g,o++,l++,u+=s[o],o++,l++;let b=1,v=!1,x=!1,A=0,$=!1,R="",k=[],C=s[o]==="("&&!this.dollarDparenIsSubshell(o),I=C?1:0;for(;b>0&&o<i;){let W=s[o];if(u+=W,v)W==="'"&&(v=!1);else if(x)W==="\\"&&o+1<i?(u+=s[o+1],o++,l++):W==='"'&&(x=!1);else{if(W==="("&&s[o+1]==="("?I++:W===")"&&s[o+1]===")"&&I>0&&I--,I===0&&W==="<"&&s[o+1]==="<"&&s[o+2]!=="<"){let Z=o+2,D=!1;for(s[Z]==="-"&&(D=!0,Z++);s[Z]===" "||s[Z]===" ";)Z++;let{delim:V,endPos:U,unclosedQuote:O,unclosedSubstitution:_}=Qr(s,Z);if(O)throw new Je(`unexpected EOF while looking for matching \`${O}'`,c,l);if(_)throw new Je("unexpected EOF while looking for matching `)'",c,l);if(V.length>0){u+=s.slice(o+1,U),l+=U-o,k.push({delim:V,stripTabs:D}),o=U;continue}}if(W===`
42
+ `&&k.length>0){c++,l=0;let Z=o+1;for(let{delim:D,stripTabs:V}of k)for(;!(Z>=i);){let U=s.indexOf(`
43
+ `,Z);U===-1&&(U=i);let O=s.slice(Z,U),_=V?O.replace(/^\t+/,""):O;u+=s.slice(Z,Math.min(U+1,i)),U<i&&c++;let B=U>=i;if(Z=U+1,_===D||B)break}k.length=0,l=0,o=Math.min(Z,i);continue}if(W==="'")v=!0,R="";else if(W==='"')x=!0,R="";else if(W==="\\"&&o+1<i)u+=s[o+1],o++,l++,R="";else if(W==="$"&&o+1<i&&s[o+1]==="{"){o++,l++,u+=s[o],o++,l++;let Z=1,D=!1,V=!1;for(;Z>0&&o<i;){let U=s[o];if(U==="\\"&&o+1<i&&!D){u+=U,o++,l++,u+=s[o],o++,l++;continue}u+=U,D?U==="'"&&(D=!1):V?U==='"'&&(V=!1):U==="'"?D=!0:U==='"'?V=!0:U==="{"?Z++:U==="}"&&Z--,U===`
44
+ `?(c++,l=0):l++,o++}R="";continue}else if(W==="#"&&!C&&(R===""||/\s/.test(s[o-1]||""))){for(;o+1<i&&s[o+1]!==`
45
+ `;)o++,l++,u+=s[o];R=""}else/[a-zA-Z_]/.test(W)?R+=W:(R==="case"?(A++,$=!1):R==="in"&&A>0?$=!0:R==="esac"&&A>0&&(A--,$=!1),R="",W==="("?o>0&&s[o-1]==="$"?b++:$||b++:W===")"?$?$=!1:b--:W===";"&&A>0&&(o+1<i&&s[o+1]===";"||o+1<i&&s[o+1]==="&")&&($=!0))}W===`
46
+ `&&(c++,l=0,R=""),o++,l++}continue}if(g==="$"&&o+1<i&&s[o+1]==="["&&!p){u+=g,o++,l++,u+=s[o],o++,l++;let b=1;for(;b>0&&o<i;){let v=s[o];u+=v,v==="["?b++:v==="]"?b--:v===`
47
+ `&&(c++,l=0),o++,l++}continue}if(g==="$"&&o+1<i&&s[o+1]==="{"&&!p){u+=g,o++,l++,u+=s[o],o++,l++;let b=1,v=!1,x=!1,A=c,$=l,R=c,k=l;for(;b>0&&o<i;){let C=s[o];if(C==="\\"&&o+1<i&&s[o+1]===`
48
+ `){o+=2,c++,l=1;continue}if(C==="\\"&&o+1<i&&!v){u+=C,o++,l++,u+=s[o],o++,l++;continue}u+=C,v?C==="'"&&(v=!1):x?C==='"'&&(x=!1):C==="'"?(v=!0,A=c,$=l):C==='"'?(x=!0,R=c,k=l):C==="{"?b++:C==="}"&&b--,C===`
49
+ `&&(c++,l=0),o++,l++}if(v)throw new Je("unexpected EOF while looking for matching `''",A,$);if(x)throw new Je("unexpected EOF while looking for matching `\"'",R,k);continue}if(g==="$"&&o+1<i&&!p){let b=s[o+1];if(b==="#"||b==="?"||b==="$"||b==="!"||b==="@"||b==="*"||b==="-"||b>="0"&&b<="9"){u+=g+b,o+=2,l+=2;continue}}if(g==="`"&&!p){for(u+=g,o++,l++;o<i&&s[o]!=="`";){let b=s[o];u+=b,b==="\\"&&o+1<i&&(u+=s[o+1],o++,l++),b===`
50
+ `&&(c++,l=0),o++,l++}o<i&&(u+=s[o],o++,l++);continue}u+=g,o++,g===`
51
+ `?(c++,l=1):l++}if(this.pos=o,this.column=l,this.line=c,E&&y&&(u=s[t]+u,f=!1,d=!1),p||h){let g=p?"'":'"';throw new Je(`unexpected EOF while looking for matching \`${g}'`,n,r)}if(!y&&u.length>=2){if(u[0]==="'"&&u[u.length-1]==="'"){let g=u.slice(1,-1);!g.includes("'")&&!g.includes('"')&&(u=g,f=!0,d=!0)}else if(u[0]==='"'&&u[u.length-1]==='"'){let g=u.slice(1,-1),b=!1;for(let v=0;v<g.length;v++){if(g[v]==='"'){b=!0;break}g[v]==="\\"&&v+1<g.length&&v++}b||(u=g,f=!0,d=!1)}}if(u==="")return{type:w.WORD,value:"",start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d};let m=wi.get(u);if(!f&&m!==void 0)return{type:m,value:u,start:t,end:o,line:n,column:r};if(!y){let g=al(u);if(g>0&&ol(u.slice(0,g)))return{type:w.ASSIGNMENT_WORD,value:u,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(u)?{type:w.NUMBER,value:u,start:t,end:o,line:n,column:r}:Od(u)?{type:w.NAME,value:u,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}:{type:w.WORD,value:u,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let n=this.pos,r=this.line,s=this.column,i="",o=!1;for(;this.pos<this.input.length;){let a="",l="",c="";for(;;){for(a="";this.pos<this.input.length&&this.input[this.pos]!==`
49
52
  `;)a+=this.input[this.pos],this.pos++,this.column++;let f=0;for(let d=a.length-1;a[d]==="\\";d-=1)f+=1;if(c+=a,t.quoted||f%2===0||this.pos+1>=this.input.length)break;c=c.slice(0,-1),l+=`${a}
50
53
  `,this.pos++,this.line++,this.column=1}if((t.stripTabs?c.replace(/^\t+/,""):c)===t.delimiter){o=!0,this.pos<this.input.length&&this.input[this.pos]===`
51
54
  `&&(this.pos++,this.line++,this.column=1);break}if(i+=l,i+=a,this.pos<this.input.length&&this.input[this.pos]===`
52
55
  `?(i+=`
53
56
  `,this.pos++,this.line++,this.column=1):a.length>0&&(i+=`
54
- `),i.length>this.maxHeredocSize)throw new Je(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,s)}this.tokens.push({type:w.HEREDOC_CONTENT,value:i,start:n,end:this.pos,line:r,column:s,heredocTerminated:o})}}readHeredocDelimiterToken(t,n,r,s){let i=this.input,{delim:o,endPos:a,quoted:l,unclosedQuote:c,unclosedSubstitution:u}=Hr(i,t);if(c)throw new Je(`unexpected EOF while looking for matching \`${c}'`,n,r);if(u)throw new Je("unexpected EOF while looking for matching `)'",n,r);if(a===t)throw new Je("Expected here-document delimiter",n,r);let f=n,d=r;for(let p=t;p<a;p++)i[p]===`
57
+ `),i.length>this.maxHeredocSize)throw new Je(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,s)}this.tokens.push({type:w.HEREDOC_CONTENT,value:i,start:n,end:this.pos,line:r,column:s,heredocTerminated:o})}}readHeredocDelimiterToken(t,n,r,s){let i=this.input,{delim:o,endPos:a,quoted:l,unclosedQuote:c,unclosedSubstitution:u}=Qr(i,t);if(c)throw new Je(`unexpected EOF while looking for matching \`${c}'`,n,r);if(u)throw new Je("unexpected EOF while looking for matching `)'",n,r);if(a===t)throw new Je("Expected here-document delimiter",n,r);let f=n,d=r;for(let p=t;p<a;p++)i[p]===`
55
58
  `?(f+=1,d=1):d+=1;return this.pos=a,this.line=f,this.column=d,this.pendingHeredocs.push({delimiter:o,stripTabs:s,quoted:l}),{type:w.WORD,value:i.slice(t,a),start:t,end:a,line:n,column:r,quoted:l,heredocDelimiter:o}}isWordCharFollowing(t){if(t>=this.input.length)return!1;let n=this.input[t];return!(n===" "||n===" "||n===`
56
59
  `||n===";"||n==="&"||n==="|"||n==="("||n===")"||n==="<"||n===">")}readWordWithBraceExpansion(t,n,r){let s=this.input,i=s.length,o=t,a=r;for(;o<i;){let c=s[o];if(c===" "||c===" "||c===`
57
60
  `||c===";"||c==="&"||c==="|"||c==="("||c===")"||c==="<"||c===">")break;if(c==="{"){if(this.scanBraceExpansion(o)!==null){let f=1;for(o++,a++;o<i&&f>0;)s[o]==="{"?f++:s[o]==="}"&&f--,o++,a++;continue}o++,a++;continue}if(c==="}"){o++,a++;continue}if(c==="$"&&o+1<i&&s[o+1]==="("){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="("?u++:s[o]===")"&&u--,o++,a++;continue}if(c==="$"&&o+1<i&&s[o+1]==="{"){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="{"?u++:s[o]==="}"&&u--,o++,a++;continue}if(c==="`"){for(o++,a++;o<i&&s[o]!=="`";)s[o]==="\\"&&o+1<i?(o+=2,a+=2):(o++,a++);o<i&&(o++,a++);continue}o++,a++}let l=s.slice(t,o);return this.pos=o,this.column=a,{type:w.WORD,value:l,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}}scanBraceExpansion(t){let n=this.input,r=n.length,s=t+1,i=1,o=!1,a=!1;for(;s<r&&i>0;){let l=n[s];if(l==="{")i++,s++;else if(l==="}")i--,s++;else if(l===","&&i===1)o=!0,s++;else if(l==="."&&s+1<r&&n[s+1]===".")a=!0,s+=2;else{if(l===" "||l===" "||l===`
@@ -62,229 +65,231 @@ Gid: ${s} ${s} ${s} ${s}
62
65
  `&&(l=!0),s++;continue}if(c==="'"){o=!0,s++;continue}if(c==='"'){a=!0,s++;continue}if(c==="\\"){s+=2;continue}if(c===`
63
66
  `&&(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]===`
64
67
  `);)d=!0,f++;if(d&&f<r&&n[f]===")"||l)return!0}if(i===0)return!1;s++;continue}s++}return!1}dparenClosesWithSpacedParens(t){let n=this.input,r=n.length,s=t,i=2,o=!1,a=!1;for(;s<r&&i>0;){let l=n[s];if(o){l==="'"&&(o=!1),s++;continue}if(a){if(l==="\\"){s+=2;continue}l==='"'&&(a=!1),s++;continue}if(l==="'"){o=!0,s++;continue}if(l==='"'){a=!0,s++;continue}if(l==="\\"){s+=2;continue}if(l==="("){i++,s++;continue}if(l===")"){if(i--,i===1){let c=s+1;if(c<r&&n[c]===")")return!1;let u=c,f=!1;for(;u<r&&(n[u]===" "||n[u]===" "||n[u]===`
65
- `);)f=!0,u++;if(f&&u<r&&n[u]===")")return!0}if(i===0)return!1;s++;continue}if(i===1&&(l==="|"&&s+1<r&&n[s+1]==="|"||l==="&"&&s+1<r&&n[s+1]==="&"||l==="|"&&s+1<r&&n[s+1]!=="|"))return!0;s++}return!1}};var yi=1e6,ar=1e5,$d=1e6,tl=200,Ne;(function(e){e[e.Default=0]="Default",e[e.Assignment=1]="Assignment",e[e.NoBraceExpansion=2]="NoBraceExpansion",e[e.Regex=4]="Regex"})(Ne||(Ne={}));var nl=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS,w.AND_GREAT,w.AND_DGREAT]),rl=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS]),sl=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS,w.AND_GREAT,w.AND_DGREAT]),ke=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"}},Zr=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>$d)throw new ke("Maximum parse iterations exceeded (possible infinite loop)",t,n)}chargeTokens(t,n=1,r=1){if(this.tokens+=t,this.tokens>ar)throw new ke(`Too many tokens: cumulative count exceeds limit of ${ar}`,n,r)}enter(t,n){if(this.depth++,this.depth>tl)throw this.depth--,new ke(`Maximum parser nesting depth exceeded (${tl})`,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 Qr=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function lr(e){if(e.includes("#")){let n=e.split("#");if(n.length!==2)return Number.NaN;let[r,s]=n;if(!/^\d+$/.test(r)||s.length===0)return Number.NaN;let i=Number.parseInt(r,10);if(i<2||i>64)return Number.NaN;let o=0;for(let a of s){let l;if(/[0-9]/.test(a))l=a.charCodeAt(0)-48;else if(/[a-z]/.test(a))l=a.charCodeAt(0)-97+10;else if(/[A-Z]/.test(a))l=a.charCodeAt(0)-65+(i<=36?10:36);else if(a==="@")l=62;else if(a==="_")l=63;else return Number.NaN;if(l>=i)return Number.NaN;if(o=o*i+l,o>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return o}if(e.startsWith("0x")||e.startsWith("0X")){let n=Number.parseInt(e.slice(2),16);return n>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:n}if(e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)){if(/[89]/.test(e))return Number.NaN;let n=Number.parseInt(e,8);return n>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:n}let t=Number.parseInt(e,10);return t>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t}function il(e,t,n,r){if(n.slice(r,r+3)!=="$((")return null;let s=r+3,i=1,o=s;for(;s<n.length-1&&i>0;)n[s]==="("&&n[s+1]==="("?(i++,s+=2):n[s]===")"&&n[s+1]===")"?(i--,i>0&&(s+=2)):s++;let a=n.slice(o,s),{expr:l}=e(t,a,0);return s+=2,{expr:{type:"ArithNested",expression:l},pos:s}}function ol(e,t){if(e.slice(t,t+2)!=="$'")return null;let n=t+2,r="";for(;n<e.length&&e[n]!=="'";)if(e[n]==="\\"&&n+1<e.length){let i=e[n+1];switch(i){case"n":r+=`
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 al(e,t){if(e.slice(t,t+2)!=='$"')return null;let n=t+2,r="";for(;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?(r+=e[n+1],n+=2):(r+=e[n],n++);e[n]==='"'&&n++;let s=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(s)?0:s},pos:n}}function Pd(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 se(e,t){let n=Pd(t),{expr:r,pos:s}=Mn(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 He(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function Ge(e,t){return he(e,t)>=e.length}function Mn(e,t,n){return Cd(e,t,n)}function bn(e,t,n){return e.withDepth(()=>Mn(e,t,n))}function Cd(e,t,n){let{expr:r,pos:s}=cr(e,t,n);for(s=he(t,s);t[s]===",";){if(s++,Ge(t,s))return He(",",s);let{expr:o,pos:a}=cr(e,t,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=he(t,a)}return{expr:r,pos:s}}function cr(e,t,n){let{expr:r,pos:s}=Nd(e,t,n);if(s=he(t,s),t[s]==="?"){s++;let{expr:i,pos:o}=bn(e,t,s);if(s=he(t,o),t[s]===":"){s++;let{expr:a,pos:l}=bn(e,t,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:a},pos:l}}}return{expr:r,pos:s}}function Nd(e,t,n){let{expr:r,pos:s}=ll(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="||";){if(s+=2,Ge(t,s))return He("||",s);let{expr:o,pos:a}=ll(e,t,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=a}return{expr:r,pos:s}}function ll(e,t,n){let{expr:r,pos:s}=cl(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="&&";){if(s+=2,Ge(t,s))return He("&&",s);let{expr:o,pos:a}=cl(e,t,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=a}return{expr:r,pos:s}}function cl(e,t,n){let{expr:r,pos:s}=ul(e,t,n);for(;s=he(t,s),t[s]==="|"&&t[s+1]!=="|";){if(s++,Ge(t,s))return He("|",s);let{expr:o,pos:a}=ul(e,t,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=a}return{expr:r,pos:s}}function ul(e,t,n){let{expr:r,pos:s}=fl(e,t,n);for(;s=he(t,s),t[s]==="^";){if(s++,Ge(t,s))return He("^",s);let{expr:o,pos:a}=fl(e,t,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=a}return{expr:r,pos:s}}function fl(e,t,n){let{expr:r,pos:s}=dl(e,t,n);for(;s=he(t,s),t[s]==="&"&&t[s+1]!=="&";){if(s++,Ge(t,s))return He("&",s);let{expr:o,pos:a}=dl(e,t,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=a}return{expr:r,pos:s}}function dl(e,t,n){let{expr:r,pos:s}=pl(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,Ge(t,s))return He(i,s);let{expr:o,pos:a}=pl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function pl(e,t,n){let{expr:r,pos:s}=gi(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,Ge(t,s))return He(i,s);let{expr:o,pos:a}=gi(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else if(t[s]==="<"||t[s]===">"){let i=t[s];if(s++,Ge(t,s))return He(i,s);let{expr:o,pos:a}=gi(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function gi(e,t,n){let{expr:r,pos:s}=hl(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,Ge(t,s))return He(i,s);let{expr:o,pos:a}=hl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function hl(e,t,n){let{expr:r,pos:s}=ml(e,t,n);for(;s=he(t,s),(t[s]==="+"||t[s]==="-")&&t[s+1]!==t[s];){let i=t[s];if(s++,Ge(t,s))return He(i,s);let{expr:o,pos:a}=ml(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function ml(e,t,n){let{expr:r,pos:s}=Kr(e,t,n);for(;;)if(s=he(t,s),t[s]==="*"&&t[s+1]!=="*"){if(s++,Ge(t,s))return He("*",s);let{expr:o,pos:a}=Kr(e,t,s);r={type:"ArithBinary",operator:"*",left:r,right:o},s=a}else if(t[s]==="/"||t[s]==="%"){let i=t[s];if(s++,Ge(t,s))return He(i,s);let{expr:o,pos:a}=Kr(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function Kr(e,t,n){let{expr:r,pos:s}=wi(e,t,n),i=he(t,s);if(t.slice(i,i+2)==="**"){if(i+=2,Ge(t,i))return He("**",i);let{expr:a,pos:l}=e.withDepth(()=>Kr(e,t,i));return{expr:{type:"ArithBinary",operator:"**",left:r,right:a},pos:l}}return{expr:r,pos:s}}function wi(e,t,n){let r=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(()=>wi(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}if(t[r]==="+"||t[r]==="-"||t[r]==="!"||t[r]==="~"){let s=t[r];r++;let{expr:i,pos:o}=e.withDepth(()=>wi(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}return Dd(e,t,r)}function Rd(e,t){let n=e[t];return n==="$"||n==="`"}function Dd(e,t,n){let{expr:r,pos:s}=yl(e,t,n,!1),i=[r];for(;Rd(t,s);){let{expr:a,pos:l}=yl(e,t,s,!0);i.push(a),s=l}i.length>1&&(r={type:"ArithConcat",parts:i});let o;if(t[s]==="["&&r.type==="ArithConcat"){s++;let{expr:a,pos:l}=bn(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 Qr)if(t.slice(s,s+a.length)===a&&t.slice(s,s+a.length+1)!=="=="){s+=a.length;let{expr:l,pos:c}=e.withDepth(()=>cr(e,t,s));return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r.nameExpr,subscript:r.subscript,value:l},pos:c}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r,value:l},pos:c}:{expr:{type:"ArithAssignment",operator:a,variable:r.name,value:l},pos:c}}}if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let a=t.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:a,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function yl(e,t,n,r=!1){let s=he(t,n),i=il(bn,e,t,s);if(i)return i;let o=ol(t,s);if(o)return o;let a=al(t,s);if(a)return a;if(t.slice(s,s+2)==="$("&&t[s+2]!=="("){s+=2;let c=1,u=s;for(;s<t.length&&c>0;)t[s]==="("?c++:t[s]===")"&&c--,c>0&&s++;let f=t.slice(u,s);return s++,{expr:{type:"ArithCommandSubst",command:f},pos:s}}if(t[s]==="`"){s++;let c=s;for(;s<t.length&&t[s]!=="`";)s++;let u=t.slice(c,s);return t[s]==="`"&&s++,{expr:{type:"ArithCommandSubst",command:u},pos:s}}if(t[s]==="("){s++;let{expr:c,pos:u}=bn(e,t,s);return s=he(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}=bn(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 le(`${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:lr(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 y=t.slice(p+1,h);return{expr:{type:"ArithDynamicBase",baseExpr:d,value:y},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 y=t.slice(p,h);return{expr:{type:"ArithDynamicNumber",prefix:d,suffix:y},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=he(t,s),t[s]==="]"&&s++}let f;if(u===void 0){let{expr:d,pos:p}=bn(e,t,s);f=d,s=p,t[s]==="]"&&s++}if(s=he(t,s),t[s]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:c,index:f},pos:s};if(!r){for(let d of Qr)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(()=>cr(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=he(t,s),!r){for(let u of Qr)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(()=>cr(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]!==`
68
- `;)c++;let u=t.slice(s,c).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:u,message:`${u}: syntax error: invalid arithmetic operator (error token is "${u}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:s}}var Xr=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 Id(e){let t="",n=0;for(;n<e.length;){let r=e[n];if(r<128){t+=String.fromCharCode(r),n++;continue}if((r&224)===192){if(n+1<e.length&&(e[n+1]&192)===128&&r>=194){let s=(r&31)<<6|e[n+1]&63;t+=String.fromCharCode(s),n+=2;continue}t+=String.fromCharCode(r),n++;continue}if((r&240)===224){if(n+2<e.length&&(e[n+1]&192)===128&&(e[n+2]&192)===128){if(r===224&&e[n+1]<160){t+=String.fromCharCode(r),n++;continue}let s=(r&15)<<12|(e[n+1]&63)<<6|e[n+2]&63;if(s>=55296&&s<=57343){t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(s),n+=3;continue}t+=String.fromCharCode(r),n++;continue}if((r&248)===240&&r<=244){if(n+3<e.length&&(e[n+1]&192)===128&&(e[n+2]&192)===128&&(e[n+3]&192)===128){if(r===240&&e[n+1]<144){t+=String.fromCharCode(r),n++;continue}let s=(r&7)<<18|(e[n+1]&63)<<12|(e[n+2]&63)<<6|e[n+3]&63;if(s>1114111){t+=String.fromCharCode(r),n++;continue}t+=String.fromCodePoint(s),n+=4;continue}t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(r),n++}return t}function El(e,t,n){let r=n+1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;return r}function Ei(e,t,n,r,s){let i=1,o=n+1;for(;o<t.length&&i>0;)t[o]===r?i++:t[o]===s&&i--,i>0&&o++;return i===0?o:-1}function Sn(e,t,n){let r=n,s=1;for(;r<t.length&&s>0;){let i=t[r];if(i==="\\"&&r+1<t.length){r+=2;continue}if(i==="'"){let o=t.indexOf("'",r+1);if(o!==-1){r=o+1;continue}}if(i==='"'){for(r++;r<t.length&&t[r]!=='"';)t[r]==="\\"&&r+1<t.length?r+=2:r++;r<t.length&&r++;continue}i==="{"?s++:i==="}"&&s--,s>0&&r++}return r}function bl(e,t,n){let r=n,s=!1;for(;r<t.length;){let i=t[r];if(i==="/"&&s||i==="}")break;if(i==="'"){let o=t.indexOf("'",r+1);if(o!==-1){r=o+1,s=!0;continue}}if(i==='"'){for(r++;r<t.length&&t[r]!=='"';)t[r]==="\\"&&r+1<t.length?r+=2:r++;r<t.length&&r++,s=!0;continue}i==="\\"?(r+=2,s=!0):(r++,s=!0)}return r}function Sl(e,t,n){let r=n,s="";for(;r<t.length;){let i=t[r];if(i==="*"||i==="?")s+=i,r++;else if(i==="["){let o=Od(t,r);o===-1?(s+=i,r++):(s+=t.slice(r,o+1),r=o+1)}else break}return{pattern:s,endIndex:r}}function Od(e,t){let n=t+1;for(n<e.length&&e[n]==="^"&&n++,n<e.length&&e[n]==="]"&&n++;n<e.length;){let r=e[n];if(r==="\\"&&n+1<e.length){let s=e[n+1];if(s==='"'||s==="'")return-1;n+=2;continue}if(r==="]")return n;if(r==='"'||r==="$"||r==="`")return-1;if(r==="'"){let s=e.indexOf("'",n+1);if(s!==-1){n=s+1;continue}}if(r==="["&&n+1<e.length&&e[n+1]===":"){let s=e.indexOf(":]",n+2);if(s!==-1){n=s+2;continue}}if(r==="["&&n+1<e.length&&(e[n+1]==="."||e[n+1]==="=")){let i=`${e[n+1]}]`,o=e.indexOf(i,n+2);if(o!==-1){n=o+2;continue}}n++}return-1}function Al(e,t,n){let r="",s=n;for(;s<t.length&&t[s]!=="'";){let i=t[s];if(i==="\\"&&s+1<t.length)switch(t[s+1]){case"n":r+=`
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 c=t.slice(l+2,l+4),u=parseInt(c,16);if(!Number.isNaN(u)&&c.length>0)a.push(u),l+=2+c.length;else break}a.length>0?(r+=Id(a),s=l):(r+="\\x",s+=2);break}case"u":{let a=t.slice(s+2,s+6),l=parseInt(a,16);Number.isNaN(l)?(r+="\\u",s+=2):(r+=String.fromCharCode(l),s+=6);break}case"c":{if(s+2<t.length){let l=t[s+2].charCodeAt(0)&31;r+=String.fromCharCode(l),s+=3}else r+="\\c",s+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let a="",l=s+1;for(;l<t.length&&l<s+4&&/[0-7]/.test(t[l]);)a+=t[l],l++;let c=parseInt(a,8);r+=String.fromCharCode(c),s=l;break}default:r+=i,s++}else r+=i,s++}return s<t.length&&t[s]==="'"&&s++,{part:F.literal(r),endIndex:s}}function bi(e,t){let n=t.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:se(e,n)}function wl(e){let t=[],n="",r=0;for(let s=0;s<e.length;s++){let i=e[s];i==="{"?(r++,n+=i):i==="}"?(r--,n+=i):i===","&&r===0?(t.push(n),n=""):n+=i}return t.push(n),t}function vl(e,t,n,r){let s=Ei(e,t,n,"{","}");if(s===-1)return null;let i=t.slice(n+1,s),o=i.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(o)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(o[1],10),end:Number.parseInt(o[2],10),step:o[3]?Number.parseInt(o[3],10):void 0,startStr:o[1],endStr:o[2]}]},endIndex:s+1};let a=i.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return a?{part:{type:"BraceExpansion",items:[{type:"Range",start:a[1],end:a[2],step:a[3]?Number.parseInt(a[3],10):void 0}]},endIndex:s+1}:i.includes(",")&&r?{part:{type:"BraceExpansion",items:wl(i).map(u=>e.withDepth(()=>({type:"Word",word:F.word(r(e,u,!1,!1,!1))})))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:wl(i).map(u=>({type:"Word",word:F.word([F.literal(u)])}))},endIndex:s+1}:null}function Si(e,t){let n="";for(let r of t.parts)switch(r.type){case"Literal":n+=r.value;break;case"SingleQuoted":n+=`'${r.value}'`;break;case"Escaped":n+=r.value;break;case"DoubleQuoted":n+='"';for(let s of r.parts)s.type==="Literal"||s.type==="Escaped"?n+=s.value:s.type==="ParameterExpansion"&&(n+=`\${${s.parameter}}`);n+='"';break;case"ParameterExpansion":n+=`\${${r.parameter}}`;break;case"Glob":n+=r.pattern;break;case"TildeExpansion":n+="~",r.user&&(n+=r.user);break;case"BraceExpansion":{n+="{";let s=[];for(let i of r.items)if(i.type==="Range"){let o=i.startStr??String(i.start),a=i.endStr??String(i.end);i.step!==void 0?s.push(`${o}..${a}..${i.step}`):s.push(`${o}..${a}`)}else s.push(Si(e,i.word));s.length===1&&r.items[0].type==="Range"?n+=s[0]:n+=s.join(","),n+="}";break}default:n+=r.type}return n}function xl(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 ur(e){let t=e.current(),n=t.type;if(n===w.NUMBER){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:rl.has(r.type)}if(n===w.FD_VARIABLE){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:sl.has(r.type)}return!e.isProcessSubstitutionStart()&&nl.has(n)}function Yr(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=xl(e,r.type);if(r.type===w.DLESS||r.type===w.DLESSDASH)return _d(e,t,n,r.type===w.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return F.redirection(s,i,t,n)}function _d(e,t,n,r){e.isWord()||e.error("Expected here-document delimiter");let s=e.advance(),i=s.heredocDelimiter??s.value,o=s.quoted||!1,a=F.redirection(r?"<<-":"<<",F.hereDoc(i,F.word([]),r,o),t,n);return e.addPendingHeredoc(a,i,r,o),a}function vi(e){let t=e.getSourceLine(),n=[],r=null,s=[],i=[];for(;e.check(w.ASSIGNMENT_WORD)||ur(e);)e.checkIterationLimit(),e.check(w.ASSIGNMENT_WORD)?n.push(Ld(e)):i.push(Yr(e));if(e.isWord())r=e.parseWord();else if(n.length>0&&(e.check(w.DBRACK_START)||e.check(w.DPAREN_START))){let a=e.advance();r=F.word([F.literal(a.value)])}for(;(!e.isStatementEnd()||e.check(w.RBRACE))&&!e.check(w.PIPE,w.PIPE_AMP);)if(e.checkIterationLimit(),ur(e))i.push(Yr(e));else if(e.check(w.ASSIGNMENT_WORD)){let a=e.advance(),l=a.value,c=l.endsWith("="),u=l.endsWith("=(");if((c||u)&&(u||e.check(w.LPAREN))){let f=u?l.slice(0,-2):l.slice(0,-1);u||e.expect(w.LPAREN);let d=Ai(e);e.expect(w.RPAREN);let p=d.map(y=>Si(e,y)),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,Ne.Assignment))}}else if(e.isWord())s.push(e.parseWord());else if(e.check(w.RBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.LBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.DBRACK_END)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.LPAREN))e.error("syntax error near unexpected token `('");else break;let o=F.simpleCommand(r,s,n,i);return o.line=t,o}function Ld(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=Xr(n.slice(d,o)),o++}let a=n[o]==="+";a&&o++,n[o]!=="="&&e.error(`Invalid assignment: ${n}`),o++;let l=n.slice(o);if(l==="("){let f=Ai(e);e.expect(w.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return F.assignment(d,null,a,f)}if(l===""&&e.check(w.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=Ai(e);e.expect(w.RPAREN);let p=i!==void 0?`${s}[${i}]`:s;return F.assignment(p,null,a,d)}}let c=l?e.parseWordFromString(l,t.quoted,t.singleQuoted,!0):null;t.end===e.current().start&&e.isProcessSubstitutionStart()&&(c=e.parseAdjacentWordParts(c?.parts??[],t.end,Ne.Assignment));let u=i!==void 0?`${s}[${i}]`:s;return F.assignment(u,c,a,null)}var Td=new Set([w.AMP,w.PIPE,w.PIPE_AMP,w.SEMICOLON,w.AND_AND,w.OR_OR,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND]);function Ai(e){let t=[];for(e.skipNewlines();!e.check(w.RPAREN,w.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):Td.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function xi(e,t){e.expect(w.IF);let n=[],r=e.parseCompoundList();e.expect(w.THEN);let s=e.parseCompoundList();if(s.length===0){let a=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${a}'`)}for(n.push({condition:r,body:s});e.check(w.ELIF);){e.advance();let a=e.parseCompoundList();e.expect(w.THEN);let l=e.parseCompoundList();if(l.length===0){let c=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${c}'`)}n.push({condition:a,body:l})}let i=null;e.check(w.ELSE)&&(e.advance(),i=e.parseCompoundList(),i.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(w.FI);let o=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.ifNode(n,i,o)}function ki(e,t){let n=e.expect(w.FOR);if(e.check(w.DPAREN_START))return Md(e,t,e.getSourceLine(n));e.isWord()||e.error("Expected variable name in for loop");let s=e.advance().value,i=null;if(e.skipNewlines(),e.check(w.IN))for(e.advance(),i=[];!e.check(w.SEMICOLON,w.NEWLINE,w.DO,w.EOF)&&e.isWord();)i.push(e.parseWord());e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(w.DO);let o=e.parseCompoundList();e.expect(w.DONE);let a=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.forNode(s,i,o,a)}function Md(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=se(e,o[0].trim())),o[1].trim()&&(s=se(e,o[1].trim())),o[2].trim()&&(i=se(e,o[2].trim())),e.skipNewlines(),e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines();let c;e.check(w.LBRACE)?(e.advance(),c=e.parseCompoundList(),e.expect(w.RBRACE)):(e.expect(w.DO),c=e.parseCompoundList(),e.expect(w.DONE));let u=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:s,update:i,body:c,redirections:u,line:n}}function $i(e,t){e.expect(w.WHILE);let n=e.parseCompoundList();e.expect(w.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(w.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.whileNode(n,r,s)}function Pi(e,t){e.expect(w.UNTIL);let n=e.parseCompoundList();e.expect(w.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(w.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.untilNode(n,r,s)}function Ci(e,t){e.expect(w.CASE),e.isWord()||e.error("Expected word after 'case'");let n=e.parseWord();e.skipNewlines(),e.expect(w.IN),e.skipNewlines();let r=[];for(;!e.check(w.ESAC,w.EOF);){e.checkIterationLimit();let i=e.getPos(),o=Bd(e);if(o&&r.push(o),e.skipNewlines(),e.getPos()===i&&!o)break}e.expect(w.ESAC);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.caseNode(n,r,s)}function Bd(e){e.check(w.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(w.PIPE));)e.advance();if(t.length===0)return null;e.expect(w.RPAREN),e.skipNewlines();let n=[];for(;!e.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND,w.ESAC,w.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===w.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(w.LPAREN)&&e.peek(1).type===w.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let s=e.getPos(),i=e.parseStatement();if(i&&n.push(i),e.skipSeparators(!1),e.getPos()===s&&!i)break}let r=";;";return e.check(w.DSEMI)?(e.advance(),r=";;"):e.check(w.SEMI_AND)?(e.advance(),r=";&"):e.check(w.SEMI_SEMI_AND)&&(e.advance(),r=";;&"),F.caseItem(t,n,r)}function Ni(e,t){e.expect(w.LPAREN);let n=e.parseCompoundList();e.expect(w.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.subshell(n,r)}function Ri(e,t){e.expect(w.LBRACE);let n=e.parseCompoundList();e.expect(w.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.group(n,r)}var Vd=["-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"],zd=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function $l(e){return e.isWord()||e.check(w.LBRACE)||e.check(w.RBRACE)||e.check(w.ASSIGNMENT_WORD)}function Pl(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 Ii(e){return e.skipNewlines(),Ud(e)}function Ud(e){let t=Cl(e);for(e.skipNewlines();e.check(w.OR_OR);){e.advance(),e.skipNewlines();let n=Cl(e);t={type:"CondOr",left:t,right:n},e.skipNewlines()}return t}function Cl(e){let t=Di(e);for(e.skipNewlines();e.check(w.AND_AND);){e.advance(),e.skipNewlines();let n=Di(e);t={type:"CondAnd",left:t,right:n},e.skipNewlines()}return t}function Di(e){return e.skipNewlines(),e.check(w.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:e.withDepth(()=>Di(e))}):qd(e)}function qd(e){if(e.check(w.LPAREN)){e.advance();let t=e.withDepth(()=>Ii(e));return e.expect(w.RPAREN),{type:"CondGroup",expression:t}}if($l(e)){let t=e.current(),n=t.value;if(Vd.includes(n)&&!t.quoted){if(e.advance(),e.check(w.DBRACK_END)&&e.error(`Expected operand after ${n}`),$l(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()&&zd.includes(e.current().value)){let s=e.advance().value,i;return s==="=~"?i=jd(e):s==="=="||s==="!="?i=Pl(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=Pl(e);return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function jd(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 Gd(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 fr(e){return e.length>0?e:[F.literal("")]}function Zd(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 Qd(e,t,n){let r=n+1,s=t[r];if("@*#?$!-0123456789".includes(s))return{part:F.parameterExpansion(s),endIndex:r+1};let i="";for(;r<t.length&&/[a-zA-Z0-9_]/.test(t[r]);)i+=t[r],r++;return{part:F.parameterExpansion(i),endIndex:r}}function Kd(e,t,n,r=!1){let s=n+2,i=!1;t[s]==="!"&&(i=!0,s++);let o=!1;t[s]==="#"&&!/[}:#%/^,]/.test(t[s+1]||"}")&&(o=!0,s++);let a="",l=t[s];if(/[@*#?$!-]/.test(l)&&!/[a-zA-Z0-9_]/.test(t[s+1]||""))a=l,s++;else for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)a+=t[s],s++;if(t[s]==="["){let u=Ei(e,t,s,"[","]");if(a+=`[${Xr(t.slice(s+1,u))}]`,s=u+1,t[s]==="["){let f=1,d=s;for(;d<t.length&&f>0;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let p=t.slice(n+2,d);return{part:F.parameterExpansion("",{type:"BadSubstitution",text:p}),endIndex:d+1}}}if(a===""&&!i&&!o&&t[s]!=="}"){let u=1,f=s;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;if(u>0)throw new ke("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(n+2,f);return{part:F.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let c=null;if(i){let u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Oi(e,t,s,a,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):(c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="")}else c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="";else if(t[s]==="*"||t[s]==="@"&&!/[QPaAEKkuUL]/.test(t[s+1]||"")){let f=t[s];s++,c={type:"VarNamePrefix",prefix:a,star:f==="*"},a=""}else if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Oi(e,t,s,a,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):c={type:"Indirection"}}else c={type:"Indirection"}}else if(o)if(t[s]===":")for(c={type:"LengthSliceError"};s<t.length&&t[s]!=="}";)s++;else t[s]!=="}"&&/[-+=?]/.test(t[s])?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):t[s]==="/"?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):c={type:"Length"};if(!c&&s<t.length&&t[s]!=="}"){let u=Oi(e,t,s,a,r);c=u.operation,s=u.endIndex}if(s<t.length&&t[s]!=="}"){let u=t[s];if(!/[:\-+=?#%/^,@[]/.test(u)){let f=s;for(;f<t.length&&t[f]!=="}";)f++;let d=t.slice(n,f+1);e.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<t.length&&t[s]!=="}";)s++;if(s>=t.length)throw new ke("unexpected EOF while looking for matching '}'",0,0);return{part:F.parameterExpansion(a,c),endIndex:s+1}}function Oi(e,t,n,r,s=!1){let i=n,o=t[i],a=t[i+1]||"";if(o===":"){let l=a;if("-=?+".includes(l)){i+=2;let S=Sn(e,t,i),g=t.slice(i,S),m=e.withDepth(()=>Xt(e,g,!1,!1,!0,!1,s,!1,!1,!0)),b=F.word(fr(m));if(l==="-")return{operation:{type:"DefaultValue",word:b,checkEmpty:!0},endIndex:S};if(l==="=")return{operation:{type:"AssignDefault",word:b,checkEmpty:!0},endIndex:S};if(l==="?")return{operation:{type:"ErrorIfUnset",word:b,checkEmpty:!0},endIndex:S};if(l==="+")return{operation:{type:"UseAlternative",word:b,checkEmpty:!0},endIndex:S}}i++;let c=Sn(e,t,i),u=t.slice(i,c),f=-1,d=0,p=0;for(let E=0;E<u.length;E++){let S=u[E];if(S==="("||S==="[")d++;else if(S===")"||S==="]")d--;else if(S==="?"&&d===0)p++;else if(S===":"&&d===0)if(p>0)p--;else{f=E;break}}let h=f>=0?u.slice(0,f):u,y=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:bi(e,h),length:y!==null?bi(e,y):null},endIndex:c}}if("-=?+".includes(o)){i++;let l=Sn(e,t,i),c=t.slice(i,l),u=e.withDepth(()=>Xt(e,c,!1,!1,!0,!1,s,!1,!1,!0)),f=F.word(fr(u));if(o==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:l};if(o==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:l};if(o==="?")return{operation:{type:"ErrorIfUnset",word:c?f:null,checkEmpty:!1},endIndex:l};if(o==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:l}}if(o==="#"||o==="%"){let l=a===o,c=o==="#"?"prefix":"suffix";i+=l?2:1;let u=Sn(e,t,i),f=t.slice(i,u),d=e.withDepth(()=>Xt(e,f,!1,!1,!1));return{operation:{type:"PatternRemoval",pattern:F.word(fr(d)),side:c,greedy:l},endIndex:u}}if(o==="/"){let l=a==="/";i+=l?2:1;let c=null;t[i]==="#"?(c="start",i++):t[i]==="%"&&(c="end",i++);let u;c!==null&&(t[i]==="/"||t[i]==="}")?u=i:u=bl(e,t,i);let f=t.slice(i,u),d=e.withDepth(()=>Xt(e,f,!1,!1,!1)),p=F.word(fr(d)),h=null,y=u;if(t[u]==="/"){let E=u+1,S=Sn(e,t,E),g=t.slice(E,S),m=e.withDepth(()=>Xt(e,g,!1,!1,!1));h=F.word(fr(m)),y=S}return{operation:{type:"PatternReplacement",pattern:p,replacement:h,all:l,anchor:c},endIndex:y}}if(o==="^"||o===","){let l=a===o,c=o==="^"?"upper":"lower";i+=l?2:1;let u=Sn(e,t,i),f=t.slice(i,u),d=f?F.word([F.literal(f)]):null;return{operation:{type:"CaseModification",direction:c,all:l,pattern:d},endIndex:u}}return o==="@"&&/[QPaAEKkuUL]/.test(a)?{operation:{type:"Transform",operator:a},endIndex:i+2}:{operation:null,endIndex:i}}function _i(e,t,n,r=!1){let s=n+1;if(s>=t.length)return{part:F.literal("$"),endIndex:s};let i=t[s];if(i==="("&&t[s+1]==="(")return e.isDollarDparenSubshell(t,n)?e.parseCommandSubstitution(t,n):e.parseArithmeticExpansion(t,n);if(i==="["){let o=1,a=s+1;for(;a<t.length&&o>0;)t[a]==="["?o++:t[a]==="]"&&o--,o>0&&a++;if(o===0){let l=t.slice(s+1,a),c=se(e,l);return{part:F.arithmeticExpansion(c),endIndex:a+1}}}return i==="("?e.parseCommandSubstitution(t,n):i==="{"?Kd(e,t,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?Qd(e,t,n):{part:F.literal("$"),endIndex:s}}function Nl(e,t){let n=[],r=0,s="",i=()=>{s&&(n.push(F.literal(s)),s="")};for(;r<t.length;){let o=t[r];if(o==="\\"&&r+1<t.length){let a=t[r+1];if(a==="$"||a==="`"||a==='"'||a==="\\"){s+=a,r+=2;continue}s+=o,r++;continue}if(o==="$"){i();let{part:a,endIndex:l}=_i(e,t,r,!0);a&&n.push(a),r=l;continue}if(o==="`"){i();let{part:a,endIndex:l}=e.parseBacktickSubstitution(t,r,!0);n.push(a),r=l;continue}s+=o,r++}return i(),n}function Xd(e,t,n){let r=[],s=n,i="",o=()=>{i&&(r.push(F.literal(i)),i="")};for(;s<t.length&&t[s]!=='"';){let a=t[s];if(a==="\\"&&s+1<t.length){let l=t[s+1];if('"\\$`\n'.includes(l)){i+=l,s+=2;continue}i+=a,s++;continue}if(a==="$"){o();let{part:l,endIndex:c}=_i(e,t,s,!0);l&&r.push(l),s=c;continue}if(a==="`"){o();let{part:l,endIndex:c}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=c;continue}i+=a,s++}return o(),{part:F.doubleQuoted(r),endIndex:s}}function Xt(e,t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!0){if(r)return[F.singleQuoted(t)];if(n){let y=Nl(e,t);return[F.doubleQuoted(y)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let y=t.slice(1,-1),E=!1;for(let S=0;S<y.length;S++){if(y[S]==='"'){E=!0;break}y[S]==="\\"&&S+1<y.length&&S++}if(!E){let S=Nl(e,y);return[F.doubleQuoted(S)]}}let f=[],d=0,p="",h=()=>{p&&(f.push(F.literal(p)),p="")};for(;d<t.length;){let y=t[d];if(y==="\\"&&d+1<t.length){let E=t[d+1];if(l){h(),f.push(F.escaped(E)),d+=2;continue}if(!i&&!o){E!==`
68
+ `);)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 bi=1e6,fr=1e5,_d=1e6,cl=200,Ne;(function(e){e[e.Default=0]="Default",e[e.Assignment=1]="Assignment",e[e.NoBraceExpansion=2]="NoBraceExpansion",e[e.Regex=4]="Regex"})(Ne||(Ne={}));var ul=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]),fl=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS]),dl=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]),ke=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"}},Xr=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>_d)throw new ke("Maximum parse iterations exceeded (possible infinite loop)",t,n)}chargeTokens(t,n=1,r=1){if(this.tokens+=t,this.tokens>fr)throw new ke(`Too many tokens: cumulative count exceeds limit of ${fr}`,n,r)}enter(t,n){if(this.depth++,this.depth>cl)throw this.depth--,new ke(`Maximum parser nesting depth exceeded (${cl})`,t,n);let r=!0;return()=>{r&&(r=!1,this.depth--)}}};function he(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
69
+ `){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var Yr=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function dr(e){if(e.includes("#")){let n=e.split("#");if(n.length!==2)return Number.NaN;let[r,s]=n;if(!/^\d+$/.test(r)||s.length===0)return Number.NaN;let i=Number.parseInt(r,10);if(i<2||i>64)return Number.NaN;let o=0;for(let a of s){let l;if(/[0-9]/.test(a))l=a.charCodeAt(0)-48;else if(/[a-z]/.test(a))l=a.charCodeAt(0)-97+10;else if(/[A-Z]/.test(a))l=a.charCodeAt(0)-65+(i<=36?10:36);else if(a==="@")l=62;else if(a==="_")l=63;else return Number.NaN;if(l>=i)return Number.NaN;if(o=o*i+l,o>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return o}if(e.startsWith("0x")||e.startsWith("0X")){let n=Number.parseInt(e.slice(2),16);return n>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:n}if(e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)){if(/[89]/.test(e))return Number.NaN;let n=Number.parseInt(e,8);return n>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:n}let t=Number.parseInt(e,10);return t>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t}function pl(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 hl(e,t){if(e.slice(t,t+2)!=="$'")return null;let n=t+2,r="";for(;n<e.length&&e[n]!=="'";)if(e[n]==="\\"&&n+1<e.length){let i=e[n+1];switch(i){case"n":r+=`
70
+ `;break;case"t":r+=" ";break;case"r":r+="\r";break;case"\\":r+="\\";break;case"'":r+="'";break;default:r+=i}n+=2}else r+=e[n],n++;e[n]==="'"&&n++;let s=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(s)?0:s},pos:n}}function ml(e,t){if(e.slice(t,t+2)!=='$"')return null;let n=t+2,r="";for(;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?(r+=e[n+1],n+=2):(r+=e[n],n++);e[n]==='"'&&n++;let s=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(s)?0:s},pos:n}}function Ld(e){let t="",n=0;for(;n<e.length;)if(e[n]==='"'){for(n++;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);n<e.length&&n++}else t+=e[n],n++;return t}function ne(e,t){let n=Ld(t),{expr:r,pos:s}=Wn(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 He(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function Ge(e,t){return he(e,t)>=e.length}function Wn(e,t,n){return Td(e,t,n)}function vn(e,t,n){return e.withDepth(()=>Wn(e,t,n))}function Td(e,t,n){let{expr:r,pos:s}=pr(e,t,n);for(s=he(t,s);t[s]===",";){if(s++,Ge(t,s))return He(",",s);let{expr:o,pos:a}=pr(e,t,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=he(t,a)}return{expr:r,pos:s}}function pr(e,t,n){let{expr:r,pos:s}=Fd(e,t,n);if(s=he(t,s),t[s]==="?"){s++;let{expr:i,pos:o}=vn(e,t,s);if(s=he(t,o),t[s]===":"){s++;let{expr:a,pos:l}=vn(e,t,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:a},pos:l}}}return{expr:r,pos:s}}function Fd(e,t,n){let{expr:r,pos:s}=yl(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="||";){if(s+=2,Ge(t,s))return He("||",s);let{expr:o,pos:a}=yl(e,t,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=a}return{expr:r,pos:s}}function yl(e,t,n){let{expr:r,pos:s}=gl(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="&&";){if(s+=2,Ge(t,s))return He("&&",s);let{expr:o,pos:a}=gl(e,t,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=a}return{expr:r,pos:s}}function gl(e,t,n){let{expr:r,pos:s}=wl(e,t,n);for(;s=he(t,s),t[s]==="|"&&t[s+1]!=="|";){if(s++,Ge(t,s))return He("|",s);let{expr:o,pos:a}=wl(e,t,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=a}return{expr:r,pos:s}}function wl(e,t,n){let{expr:r,pos:s}=El(e,t,n);for(;s=he(t,s),t[s]==="^";){if(s++,Ge(t,s))return He("^",s);let{expr:o,pos:a}=El(e,t,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=a}return{expr:r,pos:s}}function El(e,t,n){let{expr:r,pos:s}=bl(e,t,n);for(;s=he(t,s),t[s]==="&"&&t[s+1]!=="&";){if(s++,Ge(t,s))return He("&",s);let{expr:o,pos:a}=bl(e,t,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=a}return{expr:r,pos:s}}function bl(e,t,n){let{expr:r,pos:s}=Sl(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,Ge(t,s))return He(i,s);let{expr:o,pos:a}=Sl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function Sl(e,t,n){let{expr:r,pos:s}=Si(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,Ge(t,s))return He(i,s);let{expr:o,pos:a}=Si(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else if(t[s]==="<"||t[s]===">"){let i=t[s];if(s++,Ge(t,s))return He(i,s);let{expr:o,pos:a}=Si(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function Si(e,t,n){let{expr:r,pos:s}=Al(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,Ge(t,s))return He(i,s);let{expr:o,pos:a}=Al(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function Al(e,t,n){let{expr:r,pos:s}=vl(e,t,n);for(;s=he(t,s),(t[s]==="+"||t[s]==="-")&&t[s+1]!==t[s];){let i=t[s];if(s++,Ge(t,s))return He(i,s);let{expr:o,pos:a}=vl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function vl(e,t,n){let{expr:r,pos:s}=Jr(e,t,n);for(;;)if(s=he(t,s),t[s]==="*"&&t[s+1]!=="*"){if(s++,Ge(t,s))return He("*",s);let{expr:o,pos:a}=Jr(e,t,s);r={type:"ArithBinary",operator:"*",left:r,right:o},s=a}else if(t[s]==="/"||t[s]==="%"){let i=t[s];if(s++,Ge(t,s))return He(i,s);let{expr:o,pos:a}=Jr(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function Jr(e,t,n){let{expr:r,pos:s}=Ai(e,t,n),i=he(t,s);if(t.slice(i,i+2)==="**"){if(i+=2,Ge(t,i))return He("**",i);let{expr:a,pos:l}=e.withDepth(()=>Jr(e,t,i));return{expr:{type:"ArithBinary",operator:"**",left:r,right:a},pos:l}}return{expr:r,pos:s}}function Ai(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(()=>Ai(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(()=>Ai(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}return Bd(e,t,r)}function Md(e,t){let n=e[t];return n==="$"||n==="`"}function Bd(e,t,n){let{expr:r,pos:s}=xl(e,t,n,!1),i=[r];for(;Md(t,s);){let{expr:a,pos:l}=xl(e,t,s,!0);i.push(a),s=l}i.length>1&&(r={type:"ArithConcat",parts:i});let o;if(t[s]==="["&&r.type==="ArithConcat"){s++;let{expr:a,pos:l}=vn(e,t,s);o=a,s=l,t[s]==="]"&&s++}if(o&&r.type==="ArithConcat"&&(r={type:"ArithDynamicElement",nameExpr:r,subscript:o},o=void 0),s=he(t,s),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let a of Yr)if(t.slice(s,s+a.length)===a&&t.slice(s,s+a.length+1)!=="=="){s+=a.length;let{expr:l,pos:c}=e.withDepth(()=>pr(e,t,s));return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r.nameExpr,subscript:r.subscript,value:l},pos:c}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r,value:l},pos:c}:{expr:{type:"ArithAssignment",operator:a,variable:r.name,value:l},pos:c}}}if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let a=t.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:a,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function xl(e,t,n,r=!1){let s=he(t,n),i=pl(vn,e,t,s);if(i)return i;let o=hl(t,s);if(o)return o;let a=ml(t,s);if(a)return a;if(t.slice(s,s+2)==="$("&&t[s+2]!=="("){s+=2;let c=1,u=s;for(;s<t.length&&c>0;)t[s]==="("?c++:t[s]===")"&&c--,c>0&&s++;let f=t.slice(u,s);return s++,{expr:{type:"ArithCommandSubst",command:f},pos:s}}if(t[s]==="`"){s++;let c=s;for(;s<t.length&&t[s]!=="`";)s++;let u=t.slice(c,s);return t[s]==="`"&&s++,{expr:{type:"ArithCommandSubst",command:u},pos:s}}if(t[s]==="("){s++;let{expr:c,pos:u}=vn(e,t,s);return s=he(t,u),t[s]===")"&&s++,{expr:{type:"ArithGroup",expression:c},pos:s}}if(t[s]==="'"){s++;let c="";for(;s<t.length&&t[s]!=="'";)c+=t[s],s++;t[s]==="'"&&s++;let u=Number.parseInt(c,10);return{expr:{type:"ArithSingleQuote",content:c,value:Number.isNaN(u)?0:u},pos:s}}if(t[s]==='"'){s++;let c="";for(;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?(c+=t[s+1],s+=2):(c+=t[s],s++);t[s]==='"'&&s++;let u=c.trim();if(!u)return{expr:{type:"ArithNumber",value:0},pos:s};let{expr:f}=vn(e,u,0);return{expr:f,pos:s}}if(/[0-9]/.test(t[s])){let c="",u=!1,f=!1;for(;s<t.length;){let 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 ae(`${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:dr(c)},pos:s}}if(t[s]==="$"&&t[s+1]==="{"){let c=s+2,u=1,f=c;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;let d=t.slice(c,f),p=f+1;if(t[p]==="#"){let h=p+1;for(;h<t.length&&/[0-9a-zA-Z@_]/.test(t[h]);)h++;let y=t.slice(p+1,h);return{expr:{type:"ArithDynamicBase",baseExpr:d,value:y},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 y=t.slice(p,h);return{expr:{type:"ArithDynamicNumber",prefix:d,suffix:y},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=he(t,s),t[s]==="]"&&s++}let f;if(u===void 0){let{expr:d,pos:p}=vn(e,t,s);f=d,s=p,t[s]==="]"&&s++}if(s=he(t,s),t[s]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:c,index:f},pos:s};if(!r){for(let d of Yr)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(()=>pr(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=he(t,s),!r){for(let u of Yr)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(()=>pr(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]!==`
71
+ `;)c++;let u=t.slice(s,c).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:u,message:`${u}: syntax error: invalid arithmetic operator (error token is "${u}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:s}}var es=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 Wd(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 Pl(e,t,n){let r=n+1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;return r}function vi(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 xn(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 Cl(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 Nl(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=Vd(t,r);o===-1?(s+=i,r++):(s+=t.slice(r,o+1),r=o+1)}else break}return{pattern:s,endIndex:r}}function Vd(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 Rl(e,t,n){let r="",s=n;for(;s<t.length&&t[s]!=="'";){let i=t[s];if(i==="\\"&&s+1<t.length)switch(t[s+1]){case"n":r+=`
72
+ `,s+=2;break;case"t":r+=" ",s+=2;break;case"r":r+="\r",s+=2;break;case"\\":r+="\\",s+=2;break;case"'":r+="'",s+=2;break;case'"':r+='"',s+=2;break;case"a":r+="\x07",s+=2;break;case"b":r+="\b",s+=2;break;case"e":case"E":r+="\x1B",s+=2;break;case"f":r+="\f",s+=2;break;case"v":r+="\v",s+=2;break;case"x":{let a=[],l=s;for(;l+1<t.length&&t[l]==="\\"&&t[l+1]==="x";){let c=t.slice(l+2,l+4),u=parseInt(c,16);if(!Number.isNaN(u)&&c.length>0)a.push(u),l+=2+c.length;else break}a.length>0?(r+=Wd(a),s=l):(r+="\\x",s+=2);break}case"u":{let a=t.slice(s+2,s+6),l=parseInt(a,16);Number.isNaN(l)?(r+="\\u",s+=2):(r+=String.fromCharCode(l),s+=6);break}case"c":{if(s+2<t.length){let l=t[s+2].charCodeAt(0)&31;r+=String.fromCharCode(l),s+=3}else r+="\\c",s+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let a="",l=s+1;for(;l<t.length&&l<s+4&&/[0-7]/.test(t[l]);)a+=t[l],l++;let c=parseInt(a,8);r+=String.fromCharCode(c),s=l;break}default:r+=i,s++}else r+=i,s++}return s<t.length&&t[s]==="'"&&s++,{part:F.literal(r),endIndex:s}}function xi(e,t){let n=t.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:ne(e,n)}function $l(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 Dl(e,t,n,r){let s=vi(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:$l(i).map(u=>e.withDepth(()=>({type:"Word",word:F.word(r(e,u,!1,!1,!1))})))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:$l(i).map(u=>({type:"Word",word:F.word([F.literal(u)])}))},endIndex:s+1}:null}function ki(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(ki(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 Il(e,t){return{[w.LESS]:"<",[w.GREAT]:">",[w.DGREAT]:">>",[w.LESSAND]:"<&",[w.GREATAND]:">&",[w.LESSGREAT]:"<>",[w.CLOBBER]:">|",[w.TLESS]:"<<<",[w.AND_GREAT]:"&>",[w.AND_DGREAT]:"&>>",[w.DLESS]:"<",[w.DLESSDASH]:"<"}[t]||">"}function hr(e){let t=e.current(),n=t.type;if(n===w.NUMBER){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:fl.has(r.type)}if(n===w.FD_VARIABLE){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:dl.has(r.type)}return!e.isProcessSubstitutionStart()&&ul.has(n)}function ts(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=Il(e,r.type);if(r.type===w.DLESS||r.type===w.DLESSDASH)return zd(e,t,n,r.type===w.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return F.redirection(s,i,t,n)}function zd(e,t,n,r){e.isWord()||e.error("Expected here-document delimiter");let s=e.advance(),i=s.heredocDelimiter??s.value,o=s.quoted||!1,a=F.redirection(r?"<<-":"<<",F.hereDoc(i,F.word([]),r,o),t,n);return e.addPendingHeredoc(a,i,r,o),a}function Pi(e){let t=e.getSourceLine(),n=[],r=null,s=[],i=[];for(;e.check(w.ASSIGNMENT_WORD)||hr(e);)e.checkIterationLimit(),e.check(w.ASSIGNMENT_WORD)?n.push(Ud(e)):i.push(ts(e));if(e.isWord())r=e.parseWord();else if(n.length>0&&(e.check(w.DBRACK_START)||e.check(w.DPAREN_START))){let a=e.advance();r=F.word([F.literal(a.value)])}for(;(!e.isStatementEnd()||e.check(w.RBRACE))&&!e.check(w.PIPE,w.PIPE_AMP);)if(e.checkIterationLimit(),hr(e))i.push(ts(e));else if(e.check(w.ASSIGNMENT_WORD)){let a=e.advance(),l=a.value,c=l.endsWith("="),u=l.endsWith("=(");if((c||u)&&(u||e.check(w.LPAREN))){let f=u?l.slice(0,-2):l.slice(0,-1);u||e.expect(w.LPAREN);let d=$i(e);e.expect(w.RPAREN);let p=d.map(y=>ki(e,y)),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,Ne.Assignment))}}else if(e.isWord())s.push(e.parseWord());else if(e.check(w.RBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.LBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.DBRACK_END)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.LPAREN))e.error("syntax error near unexpected token `('");else break;let o=F.simpleCommand(r,s,n,i);return o.line=t,o}function Ud(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=es(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=$i(e);e.expect(w.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return F.assignment(d,null,a,f)}if(l===""&&e.check(w.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=$i(e);e.expect(w.RPAREN);let p=i!==void 0?`${s}[${i}]`:s;return F.assignment(p,null,a,d)}}let c=l?e.parseWordFromString(l,t.quoted,t.singleQuoted,!0):null;t.end===e.current().start&&e.isProcessSubstitutionStart()&&(c=e.parseAdjacentWordParts(c?.parts??[],t.end,Ne.Assignment));let u=i!==void 0?`${s}[${i}]`:s;return F.assignment(u,c,a,null)}var qd=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 $i(e){let t=[];for(e.skipNewlines();!e.check(w.RPAREN,w.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):qd.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function Ci(e,t){e.expect(w.IF);let n=[],r=e.parseCompoundList();e.expect(w.THEN);let s=e.parseCompoundList();if(s.length===0){let a=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${a}'`)}for(n.push({condition:r,body:s});e.check(w.ELIF);){e.advance();let a=e.parseCompoundList();e.expect(w.THEN);let l=e.parseCompoundList();if(l.length===0){let c=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${c}'`)}n.push({condition:a,body:l})}let i=null;e.check(w.ELSE)&&(e.advance(),i=e.parseCompoundList(),i.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(w.FI);let o=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.ifNode(n,i,o)}function Ni(e,t){let n=e.expect(w.FOR);if(e.check(w.DPAREN_START))return Hd(e,t,e.getSourceLine(n));e.isWord()||e.error("Expected variable name in for loop");let s=e.advance().value,i=null;if(e.skipNewlines(),e.check(w.IN))for(e.advance(),i=[];!e.check(w.SEMICOLON,w.NEWLINE,w.DO,w.EOF)&&e.isWord();)i.push(e.parseWord());e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(w.DO);let o=e.parseCompoundList();e.expect(w.DONE);let a=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.forNode(s,i,o,a)}function Hd(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=ne(e,o[0].trim())),o[1].trim()&&(s=ne(e,o[1].trim())),o[2].trim()&&(i=ne(e,o[2].trim())),e.skipNewlines(),e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines();let c;e.check(w.LBRACE)?(e.advance(),c=e.parseCompoundList(),e.expect(w.RBRACE)):(e.expect(w.DO),c=e.parseCompoundList(),e.expect(w.DONE));let u=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:s,update:i,body:c,redirections:u,line:n}}function Ri(e,t){e.expect(w.WHILE);let n=e.parseCompoundList();e.expect(w.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(w.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.whileNode(n,r,s)}function Di(e,t){e.expect(w.UNTIL);let n=e.parseCompoundList();e.expect(w.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(w.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.untilNode(n,r,s)}function Ii(e,t){e.expect(w.CASE),e.isWord()||e.error("Expected word after 'case'");let n=e.parseWord();e.skipNewlines(),e.expect(w.IN),e.skipNewlines();let r=[];for(;!e.check(w.ESAC,w.EOF);){e.checkIterationLimit();let i=e.getPos(),o=Gd(e);if(o&&r.push(o),e.skipNewlines(),e.getPos()===i&&!o)break}e.expect(w.ESAC);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.caseNode(n,r,s)}function Gd(e){e.check(w.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(w.PIPE));)e.advance();if(t.length===0)return null;e.expect(w.RPAREN),e.skipNewlines();let n=[];for(;!e.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND,w.ESAC,w.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===w.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(w.LPAREN)&&e.peek(1).type===w.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let s=e.getPos(),i=e.parseStatement();if(i&&n.push(i),e.skipSeparators(!1),e.getPos()===s&&!i)break}let r=";;";return e.check(w.DSEMI)?(e.advance(),r=";;"):e.check(w.SEMI_AND)?(e.advance(),r=";&"):e.check(w.SEMI_SEMI_AND)&&(e.advance(),r=";;&"),F.caseItem(t,n,r)}function Oi(e,t){e.expect(w.LPAREN);let n=e.parseCompoundList();e.expect(w.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.subshell(n,r)}function _i(e,t){e.expect(w.LBRACE);let n=e.parseCompoundList();e.expect(w.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.group(n,r)}var Qd=["-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"],Kd=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function _l(e){return e.isWord()||e.check(w.LBRACE)||e.check(w.RBRACE)||e.check(w.ASSIGNMENT_WORD)}function Ll(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 Ti(e){return e.skipNewlines(),Xd(e)}function Xd(e){let t=Tl(e);for(e.skipNewlines();e.check(w.OR_OR);){e.advance(),e.skipNewlines();let n=Tl(e);t={type:"CondOr",left:t,right:n},e.skipNewlines()}return t}function Tl(e){let t=Li(e);for(e.skipNewlines();e.check(w.AND_AND);){e.advance(),e.skipNewlines();let n=Li(e);t={type:"CondAnd",left:t,right:n},e.skipNewlines()}return t}function Li(e){return e.skipNewlines(),e.check(w.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:e.withDepth(()=>Li(e))}):Yd(e)}function Yd(e){if(e.check(w.LPAREN)){e.advance();let t=e.withDepth(()=>Ti(e));return e.expect(w.RPAREN),{type:"CondGroup",expression:t}}if(_l(e)){let t=e.current(),n=t.value;if(Qd.includes(n)&&!t.quoted){if(e.advance(),e.check(w.DBRACK_END)&&e.error(`Expected operand after ${n}`),_l(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()&&Kd.includes(e.current().value)){let s=e.advance().value,i;return s==="=~"?i=Jd(e):s==="=="||s==="!="?i=Ll(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=Ll(e);return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function Jd(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 tp(e){let t="";for(let n=0;n<e.length;n++){let r=e[n],s=e[n+1];if(r!=="\\"||s===void 0){t+=r;continue}"\\[]^-".includes(s)&&(t+="\\"),t+=s,n++}return t}function mr(e){return e.length>0?e:[F.literal("")]}function np(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 rp(e,t,n){let r=n+1,s=t[r];if("@*#?$!-0123456789".includes(s))return{part:F.parameterExpansion(s),endIndex:r+1};let i="";for(;r<t.length&&/[a-zA-Z0-9_]/.test(t[r]);)i+=t[r],r++;return{part:F.parameterExpansion(i),endIndex:r}}function sp(e,t,n,r=!1){let s=n+2,i=!1;t[s]==="!"&&(i=!0,s++);let o=!1;t[s]==="#"&&!/[}:#%/^,]/.test(t[s+1]||"}")&&(o=!0,s++);let a="",l=t[s];if(/[@*#?$!-]/.test(l)&&!/[a-zA-Z0-9_]/.test(t[s+1]||""))a=l,s++;else for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)a+=t[s],s++;if(t[s]==="["){let u=vi(e,t,s,"[","]");if(a+=`[${es(t.slice(s+1,u))}]`,s=u+1,t[s]==="["){let f=1,d=s;for(;d<t.length&&f>0;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let p=t.slice(n+2,d);return{part:F.parameterExpansion("",{type:"BadSubstitution",text:p}),endIndex:d+1}}}if(a===""&&!i&&!o&&t[s]!=="}"){let u=1,f=s;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;if(u>0)throw new ke("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(n+2,f);return{part:F.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let c=null;if(i){let u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Fi(e,t,s,a,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):(c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="")}else c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="";else if(t[s]==="*"||t[s]==="@"&&!/[QPaAEKkuUL]/.test(t[s+1]||"")){let f=t[s];s++,c={type:"VarNamePrefix",prefix:a,star:f==="*"},a=""}else if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Fi(e,t,s,a,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):c={type:"Indirection"}}else c={type:"Indirection"}}else if(o)if(t[s]===":")for(c={type:"LengthSliceError"};s<t.length&&t[s]!=="}";)s++;else t[s]!=="}"&&/[-+=?]/.test(t[s])?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):t[s]==="/"?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):c={type:"Length"};if(!c&&s<t.length&&t[s]!=="}"){let u=Fi(e,t,s,a,r);c=u.operation,s=u.endIndex}if(s<t.length&&t[s]!=="}"){let u=t[s];if(!/[:\-+=?#%/^,@[]/.test(u)){let f=s;for(;f<t.length&&t[f]!=="}";)f++;let d=t.slice(n,f+1);e.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<t.length&&t[s]!=="}";)s++;if(s>=t.length)throw new ke("unexpected EOF while looking for matching '}'",0,0);return{part:F.parameterExpansion(a,c),endIndex:s+1}}function Fi(e,t,n,r,s=!1){let i=n,o=t[i],a=t[i+1]||"";if(o===":"){let l=a;if("-=?+".includes(l)){i+=2;let S=xn(e,t,i),m=t.slice(i,S),g=e.withDepth(()=>Yt(e,m,!1,!1,!0,!1,s,!1,!1,!0)),b=F.word(mr(g));if(l==="-")return{operation:{type:"DefaultValue",word:b,checkEmpty:!0},endIndex:S};if(l==="=")return{operation:{type:"AssignDefault",word:b,checkEmpty:!0},endIndex:S};if(l==="?")return{operation:{type:"ErrorIfUnset",word:b,checkEmpty:!0},endIndex:S};if(l==="+")return{operation:{type:"UseAlternative",word:b,checkEmpty:!0},endIndex:S}}i++;let c=xn(e,t,i),u=t.slice(i,c),f=-1,d=0,p=0;for(let E=0;E<u.length;E++){let S=u[E];if(S==="("||S==="[")d++;else if(S===")"||S==="]")d--;else if(S==="?"&&d===0)p++;else if(S===":"&&d===0)if(p>0)p--;else{f=E;break}}let h=f>=0?u.slice(0,f):u,y=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:xi(e,h),length:y!==null?xi(e,y):null},endIndex:c}}if("-=?+".includes(o)){i++;let l=xn(e,t,i),c=t.slice(i,l),u=e.withDepth(()=>Yt(e,c,!1,!1,!0,!1,s,!1,!1,!0)),f=F.word(mr(u));if(o==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:l};if(o==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:l};if(o==="?")return{operation:{type:"ErrorIfUnset",word:c?f:null,checkEmpty:!1},endIndex:l};if(o==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:l}}if(o==="#"||o==="%"){let l=a===o,c=o==="#"?"prefix":"suffix";i+=l?2:1;let u=xn(e,t,i),f=t.slice(i,u),d=e.withDepth(()=>Yt(e,f,!1,!1,!1));return{operation:{type:"PatternRemoval",pattern:F.word(mr(d)),side:c,greedy:l},endIndex:u}}if(o==="/"){let l=a==="/";i+=l?2:1;let c=null;t[i]==="#"?(c="start",i++):t[i]==="%"&&(c="end",i++);let u;c!==null&&(t[i]==="/"||t[i]==="}")?u=i:u=Cl(e,t,i);let f=t.slice(i,u),d=e.withDepth(()=>Yt(e,f,!1,!1,!1)),p=F.word(mr(d)),h=null,y=u;if(t[u]==="/"){let E=u+1,S=xn(e,t,E),m=t.slice(E,S),g=e.withDepth(()=>Yt(e,m,!1,!1,!1));h=F.word(mr(g)),y=S}return{operation:{type:"PatternReplacement",pattern:p,replacement:h,all:l,anchor:c},endIndex:y}}if(o==="^"||o===","){let l=a===o,c=o==="^"?"upper":"lower";i+=l?2:1;let u=xn(e,t,i),f=t.slice(i,u),d=f?F.word([F.literal(f)]):null;return{operation:{type:"CaseModification",direction:c,all:l,pattern:d},endIndex:u}}return o==="@"&&/[QPaAEKkuUL]/.test(a)?{operation:{type:"Transform",operator:a},endIndex:i+2}:{operation:null,endIndex:i}}function Mi(e,t,n,r=!1){let s=n+1;if(s>=t.length)return{part:F.literal("$"),endIndex:s};let i=t[s];if(i==="("&&t[s+1]==="(")return e.isDollarDparenSubshell(t,n)?e.parseCommandSubstitution(t,n):e.parseArithmeticExpansion(t,n);if(i==="["){let o=1,a=s+1;for(;a<t.length&&o>0;)t[a]==="["?o++:t[a]==="]"&&o--,o>0&&a++;if(o===0){let l=t.slice(s+1,a),c=ne(e,l);return{part:F.arithmeticExpansion(c),endIndex:a+1}}}return i==="("?e.parseCommandSubstitution(t,n):i==="{"?sp(e,t,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?rp(e,t,n):{part:F.literal("$"),endIndex:s}}function Fl(e,t){let n=[],r=0,s="",i=()=>{s&&(n.push(F.literal(s)),s="")};for(;r<t.length;){let o=t[r];if(o==="\\"&&r+1<t.length){let a=t[r+1];if(a==="$"||a==="`"||a==='"'||a==="\\"){s+=a,r+=2;continue}s+=o,r++;continue}if(o==="$"){i();let{part:a,endIndex:l}=Mi(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 ip(e,t,n){let r=[],s=n,i="",o=()=>{i&&(r.push(F.literal(i)),i="")};for(;s<t.length&&t[s]!=='"';){let a=t[s];if(a==="\\"&&s+1<t.length){let l=t[s+1];if('"\\$`\n'.includes(l)){i+=l,s+=2;continue}i+=a,s++;continue}if(a==="$"){o();let{part:l,endIndex:c}=Mi(e,t,s,!0);l&&r.push(l),s=c;continue}if(a==="`"){o();let{part:l,endIndex:c}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=c;continue}i+=a,s++}return o(),{part:F.doubleQuoted(r),endIndex:s}}function Yt(e,t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!0){if(r)return[F.singleQuoted(t)];if(n){let y=Fl(e,t);return[F.doubleQuoted(y)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let y=t.slice(1,-1),E=!1;for(let S=0;S<y.length;S++){if(y[S]==='"'){E=!0;break}y[S]==="\\"&&S+1<y.length&&S++}if(!E){let S=Fl(e,y);return[F.doubleQuoted(S)]}}let f=[],d=0,p="",h=()=>{p&&(f.push(F.literal(p)),p="")};for(;d<t.length;){let y=t[d];if(y==="\\"&&d+1<t.length){let E=t[d+1];if(l){h(),f.push(F.escaped(E)),d+=2;continue}if(!i&&!o){E!==`
70
73
  `&&(h(),f.push(F.escaped(E))),d+=2;continue}let S=i?E==="$"||E==="`"||E===`
71
74
  `:E==="$"||E==="`"||E==='"'||E==="'"||E===`
72
- `||c&&E==="}",g=o?"*?[]\\".includes(E):"*?[]\\(){}.^+".includes(E);S?E!==`
73
- `&&(p+=E):g?(h(),f.push(F.escaped(E))):p+=`\\${E}`,d+=2;continue}if(y==="'"&&!o&&!i){h();let E=t.indexOf("'",d+1);if(E===-1){p+=t.slice(d);break}f.push(F.singleQuoted(t.slice(d+1,E))),d=E+1;continue}if(y==='"'&&!i){h();let{part:E,endIndex:S}=Xd(e,t,d+1);f.push(E),d=S+1;continue}if(y==="$"&&t[d+1]==="'"){h();let{part:E,endIndex:S}=Al(e,t,d+2);f.push(E),d=S;continue}if(y==="$"){h();let{part:E,endIndex:S}=_i(e,t,d);E&&f.push(E),d=S;continue}if(y==="`"){h();let{part:E,endIndex:S}=e.parseBacktickSubstitution(t,d);f.push(E),d=S;continue}if((y==="<"||y===">")&&t[d+1]==="("&&!i&&!o){h();let{part:E,endIndex:S}=e.parseProcessSubstitutionFromString(t,d);f.push(E),d=S;continue}if(y==="~"){let E=d>0?t[d-1]:"";if(d===0&&u||E==="="||s&&E===":"){let g=El(e,t,d),m=t[g];if(m===void 0||m==="/"||m===":"){h();let b=t.slice(d+1,g)||null;f.push({type:"TildeExpansion",user:b}),d=g;continue}}}if("@*+?!".includes(y)&&d+1<t.length&&t[d+1]==="("){let E=Zd(t,d+1);if(E!==-1){h();let S=t.slice(d,E+1);f.push({type:"Glob",pattern:S}),d=E+1;continue}}if(y==="*"||y==="?"||y==="["){h();let{pattern:E,endIndex:S}=Sl(e,t,d);f.push({type:"Glob",pattern:l?Gd(E):E}),d=S;continue}if(y==="{"&&!s&&!a&&!i){let E=vl(e,t,d,Xt);if(E){h(),f.push(E.part),d=E.endIndex;continue}}p+=y,d++}return h(),f}var H=class e{tokens=[];pos=0;pendingHeredocs=[];parseBudget;ownsParseBudget;_input="";processLineState;constructor(t){this.parseBudget=t??new Zr,this.ownsParseBudget=t===void 0}getInput(){return this._input}checkIterationLimit(){let t=this.current();this.parseBudget.chargeIteration(t?.line??1,t?.column??1)}enterDepth(){let t=this.current();return this.parseBudget.enter(t?.line??1,t?.column??1)}withDepth(t){let n=this.enterDepth();try{return t()}finally{n()}}parse(t,n){this.ownsParseBudget&&this.parseBudget.reset();let r=this.ownsParseBudget?void 0:this.enterDepth();try{if(t.length>yi)throw new ke(`Input too large: ${t.length} bytes exceeds limit of ${yi}`,1,1);this._input=t,this.processLineState=void 0;let s=new Gr(t,n);if(this.tokens=s.tokenize(),this.tokens.length>ar)throw new ke(`Too many tokens: ${this.tokens.length} exceeds limit of ${ar}`,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 ke(n||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let n=this.current();throw new ke(t,n.line,n.column,n)}skipNewlines(){for(;this.check(w.NEWLINE,w.COMMENT);)this.check(w.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(w.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(w.SEMICOLON,w.COMMENT)){this.advance();continue}if(t&&this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,n,r,s){this.pendingHeredocs.push({redirect:t,delimiter:n,stripTabs:r,quoted:s})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(w.HEREDOC_CONTENT)){let n=this.advance(),r;t.quoted?r=F.word([F.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),t.redirect.target=F.hereDoc(t.delimiter,r,t.stripTabs,t.quoted,n.heredocTerminated??!1)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(w.EOF,w.NEWLINE,w.SEMICOLON,w.AMP,w.AND_AND,w.OR_OR,w.RPAREN,w.RBRACE,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return this.isWord()||t===w.ASSIGNMENT_WORD||t===w.FD_VARIABLE||t===w.LPAREN||t===w.LBRACE||t===w.DPAREN_START||t===w.DBRACK_START||ur(this)}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(w.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)");let s=this.checkUnexpectedToken();if(s){t.push(s),this.skipSeparators(!1);continue}let i=this.pos,o=this.parseStatement();o&&t.push(o),this.check(w.HEREDOC_CONTENT)&&this.processHeredocs(),this.skipSeparators(!1),this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(w.EOF)&&this.error(`syntax error near unexpected token \`${this.current().value}'`)}return F.script(t)}checkUnexpectedToken(){let t=this.current().type,n=this.current().value;if(this.currentTokenJoinsProcessSubstitution())return null;if((t===w.DO||t===w.DONE||t===w.THEN||t===w.ELSE||t===w.ELIF||t===w.FI||t===w.ESAC)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.RBRACE||t===w.RPAREN){let r=`syntax error near unexpected token \`${n}'`;return this.advance(),F.statement([F.pipeline([F.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:n})}return(t===w.DSEMI||t===w.SEMI_AND||t===w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`),(t===w.AMP||t===w.AND_AND||t===w.OR_OR||t===w.PIPE||t===w.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${n}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,n=[],r=[],s=!1,i=this.parsePipeline();for(n.push(i);this.check(w.AND_AND,w.OR_OR);){let l=this.advance();r.push(l.type===w.AND_AND?"&&":"||"),this.skipNewlines();let c=this.parsePipeline();n.push(c)}this.check(w.AMP)&&(this.advance(),s=!0);let o=this.pos>0?this.tokens[this.pos-1].end:t,a=this._input.slice(t,o);return F.statement(n,r,s,void 0,a)}parseTimePrefix(){if(!this.check(w.TIME)||this.currentTokenJoinsProcessSubstitution())return;this.advance();let t=!1;return this.check(w.WORD,w.NAME)&&this.current().value==="-p"&&(this.advance(),t=!0),t}parsePipeline(){let t=!1,n=!1,r=0;for(;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++;if(r===0){let l=this.parseTimePrefix();if(l!==void 0)for(t=!0,n=l;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++}let s=r%2===1,i=[],o=[],a=this.parseCommand();for(i.push(a);this.check(w.PIPE,w.PIPE_AMP);){let l=this.advance();this.skipNewlines(),o.push(l.type===w.PIPE_AMP);let c=this.parseCommand();i.push(c)}return F.pipeline(i,s,t,n,o.length>0?o:void 0)}parseCommand(){if(this.currentTokenJoinsProcessSubstitution())return vi(this);let t=this.current();switch(t.type){case w.IF:return xi(this);case w.FOR:return ki(this);case w.WHILE:return $i(this);case w.UNTIL:return Pi(this);case w.CASE:return Ci(this);case w.LPAREN:return Ni(this);case w.LBRACE:return Ri(this);case w.DPAREN_START:return this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand();case w.DBRACK_START:return this.parseConditionalCommand();case w.FUNCTION:return this.parseFunctionDef();case w.TIME:break;case w.BANG:this.error(`syntax error near unexpected token \`${t.value}'`);break;default:mi(t.type)&&this.error(`syntax error near unexpected token \`${t.value}'`)}return this.check(w.NAME,w.WORD)&&this.peek(1).type===w.LPAREN&&this.peek(2).type===w.RPAREN?this.parseFunctionDef():vi(this)}dparenClosesWithSpacedParens(){let t=1,n=1;for(;n<this.tokens.length-this.pos;){let r=this.peek(n);if(r.type===w.EOF)return!1;if(r.type===w.DPAREN_START||r.type===w.LPAREN)t++;else if(r.type===w.DPAREN_END){if(t-=2,t<=0)return!1}else if(r.type===w.RPAREN&&(t--,t===0&&this.peek(n+1).type===w.RPAREN))return!0;n++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(w.RPAREN),this.expect(w.RPAREN);let n=this.parseOptionalRedirections(),r=F.subshell(t,[]);return F.subshell([F.statement([F.pipeline([r],!1,!1,!1)])],n)}isWord(){return this.isWordToken(Ne.Default)||this.isProcessSubstitutionStart()||this.currentTokenJoinsProcessSubstitution()}isWordToken(t){let n=this.current().type;return n===w.WORD||n===w.NAME||n===w.NUMBER||mi(n)||n===w.BANG||n===w.ASSIGNMENT_WORD&&(t&Ne.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(Ne.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=Ne.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=Ne.Default){for(;n===this.current().start;){if(this.isProcessSubstitutionStart()){t.push(this.parseProcessSubstitution()),n=this.tokens[this.pos-1].end;continue}if(!this.isAdjacentWordToken(r))break;let s=this.advance();t.push(...this.parseWordToken(s,r,t.length===0).parts),n=s.end}return F.word(t)}parseWordNoBraceExpansion(){return this.parseWord(Ne.NoBraceExpansion)}parseWordForRegex(){return this.parseWord(Ne.NoBraceExpansion|Ne.Regex)}parseWordToken(t,n,r=!0){return t.type===w.LBRACE||t.type===w.RBRACE||t.type===w.DBRACK_START||t.type===w.DBRACK_END||t.type===w.FD_VARIABLE?F.word([F.literal(t.type===w.FD_VARIABLE?`{${t.value}}`:t.value)]):this.parseWordFromString(t.value,t.quoted,t.singleQuoted,(n&Ne.Assignment)!==0,!1,(n&Ne.NoBraceExpansion)!==0,(n&Ne.Regex)!==0,r)}parseWordFromString(t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!0){let c=Xt(this,t,n,r,s,i,!1,o,a,!1,l);return F.word(c)}parseCommandSubstitution(t,n){return Qa(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitutionFromString(t,n){return Ka(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitution(){let t=this.advance();this.expect(w.LPAREN);let n=this.processLineState,r=this.getSourceLine(t);this.processLineState={currentLogicalLine:r};let s;try{s=F.script(this.parseCompoundList())}finally{this.processLineState=n}return this.check(w.EOF)&&this.error("unexpected EOF while looking for matching `)'"),this.expect(w.RPAREN),F.processSubstitution(s,t.type===w.LESS?"input":"output")}parseBacktickSubstitution(t,n,r=!1){return Xa(t,n,r,()=>new e(this.parseBudget),s=>this.error(s))}isDollarDparenSubshell(t,n){return Ga(t,n)}parseArithmeticExpansion(t,n){let r=n+3,s=1,i=0,o=r;for(;o<t.length-1&&s>0;)t[o]==="$"&&t[o+1]==="("?t[o+2]==="("?(s++,o+=3):(i++,o+=2):t[o]==="("&&t[o+1]==="("?(s++,o+=2):t[o]===")"&&t[o+1]===")"?i>0?(i--,o++):(s--,s>0&&(o+=2)):t[o]==="("?(i++,o++):(t[o]===")"&&i>0&&i--,o++);let a=t.slice(r,o),l=this.parseArithmeticExpression(a);return{part:F.arithmeticExpansion(l),endIndex:o+2}}parseArithmeticCommand(){let t=this.expect(w.DPAREN_START),n="",r=1,s=0,i=!1,o=!1;for(;r>0&&!this.check(w.EOF);){if(i){if(i=!1,s>0){s--,n+=")";continue}if(this.check(w.RPAREN)){r--,o=!0,this.advance();continue}if(this.check(w.DPAREN_END)){r--,o=!0;continue}n+=")";continue}if(this.check(w.DPAREN_START))r++,n+="((",this.advance();else if(this.check(w.DPAREN_END))s>=2?(s-=2,n+="))",this.advance()):s===1?(s--,n+=")",i=!0,this.advance()):(r--,o=!0,r>0&&(n+="))"),this.advance());else if(this.check(w.LPAREN))s++,n+="(",this.advance();else if(this.check(w.RPAREN))s>0&&s--,n+=")",this.advance();else{let c=this.current().value,u=n.length>0?n[n.length-1]:"";n.length>0&&!n.endsWith(" ")&&!(c==="="&&/[|&^+\-*/%<>]$/.test(n))&&!(c==="<"&&u==="<")&&!(c===">"&&u===">")&&(n+=" "),n+=c,this.advance()}}o||this.expect(w.DPAREN_END);let a=this.parseArithmeticExpression(n.trim()),l=this.parseOptionalRedirections();return F.arithmeticCommand(a,l,this.getSourceLine(t))}parseConditionalCommand(){let t=this.expect(w.DBRACK_START),n=Ii(this);this.expect(w.DBRACK_END);let r=this.parseOptionalRedirections();return F.conditionalCommand(n,r,this.getSourceLine(t))}parseFunctionDef(){let t;if(this.check(w.FUNCTION)){if(this.advance(),this.check(w.NAME)||this.check(w.WORD))t=this.advance().value;else{let s=this.current();throw new ke("Expected function name",s.line,s.column,s)}this.check(w.LPAREN)&&(this.advance(),this.expect(w.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(w.LPAREN),this.expect(w.RPAREN);this.skipNewlines();let n=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return F.functionDef(t,n,r)}parseCompoundCommandBody(t){let n=t?.forFunctionBody;if(this.check(w.LBRACE))return Ri(this,{skipRedirections:n});if(this.check(w.LPAREN))return Ni(this,{skipRedirections:n});if(this.check(w.IF))return xi(this,{skipRedirections:n});if(this.check(w.FOR))return ki(this,{skipRedirections:n});if(this.check(w.WHILE))return $i(this,{skipRedirections:n});if(this.check(w.UNTIL))return Pi(this,{skipRedirections:n});if(this.check(w.CASE))return Ci(this,{skipRedirections:n});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth();try{let n=[];for(this.skipNewlines();(this.currentTokenJoinsProcessSubstitution()||!this.check(w.EOF,w.FI,w.ELSE,w.ELIF,w.THEN,w.DO,w.DONE,w.ESAC,w.RPAREN,w.RBRACE,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND))&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,s=this.parseStatement();if(s&&n.push(s),this.skipSeparators(),this.pos===r&&!s)break}return n}finally{t()}}parseOptionalRedirections(){let t=[];for(;ur(this);){this.checkIterationLimit();let n=this.pos;if(t.push(Yr(this)),this.pos===n)break}return t}parseArithmeticExpression(t){return se(this,t)}};function at(e,t){return new H().parse(e,t)}function Rl(e){return vn(e)}function vn(e){return e.statements.map(Dl).join(`
74
- `)}function Dl(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(Jd(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let n=t.join(" ");return e.background&&(n+=" &"),n}function Jd(e){let t=[];e.timed&&t.push(e.timePosix?"time -p":"time"),e.negated&&t.push("!");let n=[];for(let s=0;s<e.commands.length;s++)if(n.push(Il(e.commands[s])),s<e.commands.length-1){let i=e.pipeStderr?.[s];n.push(i?"|&":"|")}return(t.length>0?`${t.join(" ")} `:"")+n.join(" ")}function Il(e){switch(e.type){case"SimpleCommand":return ep(e);case"If":return cp(e);case"For":return up(e);case"CStyleFor":return fp(e);case"While":return dp(e);case"Until":return pp(e);case"Case":return hp(e);case"Subshell":return yp(e);case"Group":return gp(e);case"ArithmeticCommand":return wp(e);case"ConditionalCommand":return Ep(e);case"FunctionDef":return bp(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function ep(e){let t=[];for(let n of e.assignments)t.push(tp(n));e.name&&t.push(Ae(e.name));for(let n of e.args)t.push(Ae(n));for(let n of e.redirections)t.push(Ll(n));return t.join(" ")}function tp(e){let t=e.append?"+=":"=";if(e.array){let n=e.array.map(Ae).join(" ");return`${e.name}${t}(${n})`}return e.value?`${e.name}${t}${Ae(e.value)}`:`${e.name}${t}`}function Ae(e){return e.parts.map(t=>Jr(t,!1)).join("")}function Yt(e){return e.parts.map(t=>Jr(t,!0)).join("")}function Jr(e,t){switch(e.type){case"Literal":return t?rp(e.value):np(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(n=>Jr(n,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Ol(e);case"CommandSubstitution":return e.legacy?`\`${vn(e.body)}\``:`$(${vn(e.body)})`;case"ArithmeticExpansion":return`$((${de(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${vn(e.body)})`:`>(${vn(e.body)})`;case"BraceExpansion":return ap(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 np(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function rp(e){return e.replace(/[$`"\\]/g,"\\$&")}function sp(e,t){return e.parts.map(n=>ip(n,t)).join("")}function ip(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Ol(e);case"CommandSubstitution":return e.legacy?`\`${vn(e.body)}\``:`$(${vn(e.body)})`;case"ArithmeticExpansion":return`$((${de(e.expression.expression)}))`;default:return Jr(e,!1)}}function Ol(e){return e.operation?`\${${_l(e.parameter,e.operation)}}`:op(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function op(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function _l(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${Yt(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${Yt(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?Yt(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${Yt(t.word)}`;case"Substring":{let n=de(t.offset.expression);return t.length?`${e}:${n}:${de(t.length.expression)}`:`${e}:${n}`}case"PatternRemoval":{let n=t.side==="prefix"?"#":"%",r=t.greedy?`${n}${n}`:n;return`${e}${r}${Yt(t.pattern)}`}case"PatternReplacement":{let n="/";t.all?n="//":t.anchor==="start"?n="/#":t.anchor==="end"&&(n="/%");let r=t.replacement?`/${Yt(t.replacement)}`:"";return`${e}${n}${Yt(t.pattern)}${r}`}case"CaseModification":{let n=t.direction==="upper"?"^":",",r=t.all?`${n}${n}`:n,s=t.pattern?Yt(t.pattern):"";return`${e}${r}${s}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${_l(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 ap(e){return`{${e.items.map(lp).join(",")}}`}function lp(e){if(e.type==="Word")return Ae(e.word);let t=e.startStr??String(e.start),n=e.endStr??String(e.end);return e.step!==void 0?`${t}..${n}..${e.step}`:`${t}..${n}`}function Ll(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let n=e.target;if(n.terminated===!1)throw new Error("Cannot serialize an unterminated here-document");let r=n.quoted?`'${n.delimiter}'`:n.delimiter,s=sp(n.content,n.quoted);return`${t}${e.operator}${r}
75
- ${s}${n.delimiter}`}return e.operator==="<<<"?`${t}<<< ${Ae(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${Ae(e.target)}`:`${t}${e.operator} ${Ae(e.target)}`}function mt(e){return e.length===0?"":` ${e.map(Ll).join(" ")}`}function lt(e){return e.map(Dl).join(`
76
- `)}function cp(e){let t=[];for(let n=0;n<e.clauses.length;n++){let r=e.clauses[n],s=n===0?"if":"elif";t.push(`${s} ${lt(r.condition)}; then
77
- ${lt(r.body)}`)}return e.elseBody&&t.push(`else
78
- ${lt(e.elseBody)}`),`${t.join(`
75
+ `||c&&E==="}",m=o?"*?[]\\".includes(E):"*?[]\\(){}.^+".includes(E);S?E!==`
76
+ `&&(p+=E):m?(h(),f.push(F.escaped(E))):p+=`\\${E}`,d+=2;continue}if(y==="'"&&!o&&!i){h();let E=t.indexOf("'",d+1);if(E===-1){p+=t.slice(d);break}f.push(F.singleQuoted(t.slice(d+1,E))),d=E+1;continue}if(y==='"'&&!i){h();let{part:E,endIndex:S}=ip(e,t,d+1);f.push(E),d=S+1;continue}if(y==="$"&&t[d+1]==="'"){h();let{part:E,endIndex:S}=Rl(e,t,d+2);f.push(E),d=S;continue}if(y==="$"){h();let{part:E,endIndex:S}=Mi(e,t,d);E&&f.push(E),d=S;continue}if(y==="`"){h();let{part:E,endIndex:S}=e.parseBacktickSubstitution(t,d);f.push(E),d=S;continue}if((y==="<"||y===">")&&t[d+1]==="("&&!i&&!o){h();let{part:E,endIndex:S}=e.parseProcessSubstitutionFromString(t,d);f.push(E),d=S;continue}if(y==="~"){let E=d>0?t[d-1]:"";if(d===0&&u||E==="="||s&&E===":"){let m=Pl(e,t,d),g=t[m];if(g===void 0||g==="/"||g===":"){h();let b=t.slice(d+1,m)||null;f.push({type:"TildeExpansion",user:b}),d=m;continue}}}if("@*+?!".includes(y)&&d+1<t.length&&t[d+1]==="("){let E=np(t,d+1);if(E!==-1){h();let S=t.slice(d,E+1);f.push({type:"Glob",pattern:S}),d=E+1;continue}}if(y==="*"||y==="?"||y==="["){h();let{pattern:E,endIndex:S}=Nl(e,t,d);f.push({type:"Glob",pattern:l?tp(E):E}),d=S;continue}if(y==="{"&&!s&&!a&&!i){let E=Dl(e,t,d,Yt);if(E){h(),f.push(E.part),d=E.endIndex;continue}}p+=y,d++}return h(),f}var H=class e{tokens=[];pos=0;pendingHeredocs=[];parseBudget;ownsParseBudget;_input="";processLineState;constructor(t){this.parseBudget=t??new Xr,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>bi)throw new ke(`Input too large: ${t.length} bytes exceeds limit of ${bi}`,1,1);this._input=t,this.processLineState=void 0;let s=new Kr(t,n);if(this.tokens=s.tokenize(),this.tokens.length>fr)throw new ke(`Too many tokens: ${this.tokens.length} exceeds limit of ${fr}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseBudget.chargeTokens(this.tokens.length),this.parseScript()}finally{r?.()}}parseTokens(t){this.ownsParseBudget&&this.parseBudget.reset();let n=this.ownsParseBudget?void 0:this.enterDepth();try{return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.processLineState=void 0,this.parseBudget.chargeTokens(t.length),this.parseScript()}finally{n?.()}}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}getSourceLine(t=this.current()){let n=this.processLineState;return n?(n.currentPhysicalLine===void 0?n.currentPhysicalLine=t.line:t.line>n.currentPhysicalLine&&(n.currentPhysicalLine=t.line,n.currentLogicalLine+=1),n.currentLogicalLine):t.line}check(t,n,r,s,...i){let o=this.tokens[this.pos]?.type;return o===t||n!==void 0&&o===n||r!==void 0&&o===r||s!==void 0&&o===s?!0:i.length>0?i.includes(o):!1}expect(t,n){if(this.check(t))return this.advance();let r=this.current();throw new ke(n||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let n=this.current();throw new ke(t,n.line,n.column,n)}skipNewlines(){for(;this.check(w.NEWLINE,w.COMMENT);)this.check(w.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(w.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(w.SEMICOLON,w.COMMENT)){this.advance();continue}if(t&&this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,n,r,s){this.pendingHeredocs.push({redirect:t,delimiter:n,stripTabs:r,quoted:s})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(w.HEREDOC_CONTENT)){let n=this.advance(),r;t.quoted?r=F.word([F.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),t.redirect.target=F.hereDoc(t.delimiter,r,t.stripTabs,t.quoted,n.heredocTerminated??!1)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(w.EOF,w.NEWLINE,w.SEMICOLON,w.AMP,w.AND_AND,w.OR_OR,w.RPAREN,w.RBRACE,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return this.isWord()||t===w.ASSIGNMENT_WORD||t===w.FD_VARIABLE||t===w.LPAREN||t===w.LBRACE||t===w.DPAREN_START||t===w.DBRACK_START||hr(this)}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(w.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)");let s=this.checkUnexpectedToken();if(s){t.push(s),this.skipSeparators(!1);continue}let i=this.pos,o=this.parseStatement();o&&t.push(o),this.check(w.HEREDOC_CONTENT)&&this.processHeredocs(),this.skipSeparators(!1),this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(w.EOF)&&this.error(`syntax error near unexpected token \`${this.current().value}'`)}return F.script(t)}checkUnexpectedToken(){let t=this.current().type,n=this.current().value;if(this.currentTokenJoinsProcessSubstitution())return null;if((t===w.DO||t===w.DONE||t===w.THEN||t===w.ELSE||t===w.ELIF||t===w.FI||t===w.ESAC)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.RBRACE||t===w.RPAREN){let r=`syntax error near unexpected token \`${n}'`;return this.advance(),F.statement([F.pipeline([F.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:n})}return(t===w.DSEMI||t===w.SEMI_AND||t===w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`),(t===w.AMP||t===w.AND_AND||t===w.OR_OR||t===w.PIPE||t===w.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${n}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,n=[],r=[],s=!1,i=this.parsePipeline();for(n.push(i);this.check(w.AND_AND,w.OR_OR);){let l=this.advance();r.push(l.type===w.AND_AND?"&&":"||"),this.skipNewlines();let c=this.parsePipeline();n.push(c)}this.check(w.AMP)&&(this.advance(),s=!0);let o=this.pos>0?this.tokens[this.pos-1].end:t,a=this._input.slice(t,o);return F.statement(n,r,s,void 0,a)}parseTimePrefix(){if(!this.check(w.TIME)||this.currentTokenJoinsProcessSubstitution())return;this.advance();let t=!1;return this.check(w.WORD,w.NAME)&&this.current().value==="-p"&&(this.advance(),t=!0),t}parsePipeline(){let t=!1,n=!1,r=0;for(;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++;if(r===0){let l=this.parseTimePrefix();if(l!==void 0)for(t=!0,n=l;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++}let s=r%2===1,i=[],o=[],a=this.parseCommand();for(i.push(a);this.check(w.PIPE,w.PIPE_AMP);){let l=this.advance();this.skipNewlines(),o.push(l.type===w.PIPE_AMP);let c=this.parseCommand();i.push(c)}return F.pipeline(i,s,t,n,o.length>0?o:void 0)}parseCommand(){if(this.currentTokenJoinsProcessSubstitution())return Pi(this);let t=this.current();switch(t.type){case w.IF:return Ci(this);case w.FOR:return Ni(this);case w.WHILE:return Ri(this);case w.UNTIL:return Di(this);case w.CASE:return Ii(this);case w.LPAREN:return Oi(this);case w.LBRACE:return _i(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:Ei(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():Pi(this)}dparenClosesWithSpacedParens(){let t=1,n=1;for(;n<this.tokens.length-this.pos;){let r=this.peek(n);if(r.type===w.EOF)return!1;if(r.type===w.DPAREN_START||r.type===w.LPAREN)t++;else if(r.type===w.DPAREN_END){if(t-=2,t<=0)return!1}else if(r.type===w.RPAREN&&(t--,t===0&&this.peek(n+1).type===w.RPAREN))return!0;n++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(w.RPAREN),this.expect(w.RPAREN);let n=this.parseOptionalRedirections(),r=F.subshell(t,[]);return F.subshell([F.statement([F.pipeline([r],!1,!1,!1)])],n)}isWord(){return this.isWordToken(Ne.Default)||this.isProcessSubstitutionStart()||this.currentTokenJoinsProcessSubstitution()}isWordToken(t){let n=this.current().type;return n===w.WORD||n===w.NAME||n===w.NUMBER||Ei(n)||n===w.BANG||n===w.ASSIGNMENT_WORD&&(t&Ne.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(Ne.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=Ne.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=Ne.Default){for(;n===this.current().start;){if(this.isProcessSubstitutionStart()){t.push(this.parseProcessSubstitution()),n=this.tokens[this.pos-1].end;continue}if(!this.isAdjacentWordToken(r))break;let s=this.advance();t.push(...this.parseWordToken(s,r,t.length===0).parts),n=s.end}return F.word(t)}parseWordNoBraceExpansion(){return this.parseWord(Ne.NoBraceExpansion)}parseWordForRegex(){return this.parseWord(Ne.NoBraceExpansion|Ne.Regex)}parseWordToken(t,n,r=!0){return t.type===w.LBRACE||t.type===w.RBRACE||t.type===w.DBRACK_START||t.type===w.DBRACK_END||t.type===w.FD_VARIABLE?F.word([F.literal(t.type===w.FD_VARIABLE?`{${t.value}}`:t.value)]):this.parseWordFromString(t.value,t.quoted,t.singleQuoted,(n&Ne.Assignment)!==0,!1,(n&Ne.NoBraceExpansion)!==0,(n&Ne.Regex)!==0,r)}parseWordFromString(t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!0){let c=Yt(this,t,n,r,s,i,!1,o,a,!1,l);return F.word(c)}parseCommandSubstitution(t,n){return rl(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitutionFromString(t,n){return sl(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitution(){let t=this.advance();this.expect(w.LPAREN);let n=this.processLineState,r=this.getSourceLine(t);this.processLineState={currentLogicalLine:r};let s;try{s=F.script(this.parseCompoundList())}finally{this.processLineState=n}return this.check(w.EOF)&&this.error("unexpected EOF while looking for matching `)'"),this.expect(w.RPAREN),F.processSubstitution(s,t.type===w.LESS?"input":"output")}parseBacktickSubstitution(t,n,r=!1){return il(t,n,r,()=>new e(this.parseBudget),s=>this.error(s))}isDollarDparenSubshell(t,n){return tl(t,n)}parseArithmeticExpansion(t,n){let r=n+3,s=1,i=0,o=r;for(;o<t.length-1&&s>0;)t[o]==="$"&&t[o+1]==="("?t[o+2]==="("?(s++,o+=3):(i++,o+=2):t[o]==="("&&t[o+1]==="("?(s++,o+=2):t[o]===")"&&t[o+1]===")"?i>0?(i--,o++):(s--,s>0&&(o+=2)):t[o]==="("?(i++,o++):(t[o]===")"&&i>0&&i--,o++);let a=t.slice(r,o),l=this.parseArithmeticExpression(a);return{part:F.arithmeticExpansion(l),endIndex:o+2}}parseArithmeticCommand(){let t=this.expect(w.DPAREN_START),n="",r=1,s=0,i=!1,o=!1;for(;r>0&&!this.check(w.EOF);){if(i){if(i=!1,s>0){s--,n+=")";continue}if(this.check(w.RPAREN)){r--,o=!0,this.advance();continue}if(this.check(w.DPAREN_END)){r--,o=!0;continue}n+=")";continue}if(this.check(w.DPAREN_START))r++,n+="((",this.advance();else if(this.check(w.DPAREN_END))s>=2?(s-=2,n+="))",this.advance()):s===1?(s--,n+=")",i=!0,this.advance()):(r--,o=!0,r>0&&(n+="))"),this.advance());else if(this.check(w.LPAREN))s++,n+="(",this.advance();else if(this.check(w.RPAREN))s>0&&s--,n+=")",this.advance();else{let c=this.current().value,u=n.length>0?n[n.length-1]:"";n.length>0&&!n.endsWith(" ")&&!(c==="="&&/[|&^+\-*/%<>]$/.test(n))&&!(c==="<"&&u==="<")&&!(c===">"&&u===">")&&(n+=" "),n+=c,this.advance()}}o||this.expect(w.DPAREN_END);let a=this.parseArithmeticExpression(n.trim()),l=this.parseOptionalRedirections();return F.arithmeticCommand(a,l,this.getSourceLine(t))}parseConditionalCommand(){let t=this.expect(w.DBRACK_START),n=Ti(this);this.expect(w.DBRACK_END);let r=this.parseOptionalRedirections();return F.conditionalCommand(n,r,this.getSourceLine(t))}parseFunctionDef(){let t;if(this.check(w.FUNCTION)){if(this.advance(),this.check(w.NAME)||this.check(w.WORD))t=this.advance().value;else{let s=this.current();throw new ke("Expected function name",s.line,s.column,s)}this.check(w.LPAREN)&&(this.advance(),this.expect(w.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(w.LPAREN),this.expect(w.RPAREN);this.skipNewlines();let n=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return F.functionDef(t,n,r)}parseCompoundCommandBody(t){let n=t?.forFunctionBody;if(this.check(w.LBRACE))return _i(this,{skipRedirections:n});if(this.check(w.LPAREN))return Oi(this,{skipRedirections:n});if(this.check(w.IF))return Ci(this,{skipRedirections:n});if(this.check(w.FOR))return Ni(this,{skipRedirections:n});if(this.check(w.WHILE))return Ri(this,{skipRedirections:n});if(this.check(w.UNTIL))return Di(this,{skipRedirections:n});if(this.check(w.CASE))return Ii(this,{skipRedirections:n});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth();try{let n=[];for(this.skipNewlines();(this.currentTokenJoinsProcessSubstitution()||!this.check(w.EOF,w.FI,w.ELSE,w.ELIF,w.THEN,w.DO,w.DONE,w.ESAC,w.RPAREN,w.RBRACE,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND))&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,s=this.parseStatement();if(s&&n.push(s),this.skipSeparators(),this.pos===r&&!s)break}return n}finally{t()}}parseOptionalRedirections(){let t=[];for(;hr(this);){this.checkIterationLimit();let n=this.pos;if(t.push(ts(this)),this.pos===n)break}return t}parseArithmeticExpression(t){return ne(this,t)}};function lt(e,t){return new H().parse(e,t)}function Ml(e){return $n(e)}function $n(e){return e.statements.map(Bl).join(`
77
+ `)}function Bl(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(ap(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let n=t.join(" ");return e.background&&(n+=" &"),n}function ap(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(Wl(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 Wl(e){switch(e.type){case"SimpleCommand":return lp(e);case"If":return gp(e);case"For":return wp(e);case"CStyleFor":return Ep(e);case"While":return bp(e);case"Until":return Sp(e);case"Case":return Ap(e);case"Subshell":return xp(e);case"Group":return kp(e);case"ArithmeticCommand":return $p(e);case"ConditionalCommand":return Pp(e);case"FunctionDef":return Cp(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function lp(e){let t=[];for(let n of e.assignments)t.push(cp(n));e.name&&t.push(Ae(e.name));for(let n of e.args)t.push(Ae(n));for(let n of e.redirections)t.push(Ul(n));return t.join(" ")}function cp(e){let t=e.append?"+=":"=";if(e.array){let n=e.array.map(Ae).join(" ");return`${e.name}${t}(${n})`}return e.value?`${e.name}${t}${Ae(e.value)}`:`${e.name}${t}`}function Ae(e){return e.parts.map(t=>ns(t,!1)).join("")}function Jt(e){return e.parts.map(t=>ns(t,!0)).join("")}function ns(e,t){switch(e.type){case"Literal":return t?fp(e.value):up(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(n=>ns(n,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Vl(e);case"CommandSubstitution":return e.legacy?`\`${$n(e.body)}\``:`$(${$n(e.body)})`;case"ArithmeticExpansion":return`$((${de(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${$n(e.body)})`:`>(${$n(e.body)})`;case"BraceExpansion":return mp(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 up(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function fp(e){return e.replace(/[$`"\\]/g,"\\$&")}function dp(e,t){return e.parts.map(n=>pp(n,t)).join("")}function pp(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Vl(e);case"CommandSubstitution":return e.legacy?`\`${$n(e.body)}\``:`$(${$n(e.body)})`;case"ArithmeticExpansion":return`$((${de(e.expression.expression)}))`;default:return ns(e,!1)}}function Vl(e){return e.operation?`\${${zl(e.parameter,e.operation)}}`:hp(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function hp(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function zl(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${Jt(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${Jt(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?Jt(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${Jt(t.word)}`;case"Substring":{let n=de(t.offset.expression);return t.length?`${e}:${n}:${de(t.length.expression)}`:`${e}:${n}`}case"PatternRemoval":{let n=t.side==="prefix"?"#":"%",r=t.greedy?`${n}${n}`:n;return`${e}${r}${Jt(t.pattern)}`}case"PatternReplacement":{let n="/";t.all?n="//":t.anchor==="start"?n="/#":t.anchor==="end"&&(n="/%");let r=t.replacement?`/${Jt(t.replacement)}`:"";return`${e}${n}${Jt(t.pattern)}${r}`}case"CaseModification":{let n=t.direction==="upper"?"^":",",r=t.all?`${n}${n}`:n,s=t.pattern?Jt(t.pattern):"";return`${e}${r}${s}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${zl(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 mp(e){return`{${e.items.map(yp).join(",")}}`}function yp(e){if(e.type==="Word")return Ae(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 Ul(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=dp(n.content,n.quoted);return`${t}${e.operator}${r}
78
+ ${s}${n.delimiter}`}return e.operator==="<<<"?`${t}<<< ${Ae(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${Ae(e.target)}`:`${t}${e.operator} ${Ae(e.target)}`}function gt(e){return e.length===0?"":` ${e.map(Ul).join(" ")}`}function ct(e){return e.map(Bl).join(`
79
+ `)}function gp(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} ${ct(r.condition)}; then
80
+ ${ct(r.body)}`)}return e.elseBody&&t.push(`else
81
+ ${ct(e.elseBody)}`),`${t.join(`
79
82
  `)}
80
- fi${mt(e.redirections)}`}function up(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let n=e.words.map(Ae).join(" ");t=`for ${e.variable} in ${n}`}return`${t}; do
81
- ${lt(e.body)}
82
- done${mt(e.redirections)}`}function fp(e){let t=e.init?de(e.init.expression):"",n=e.condition?de(e.condition.expression):"",r=e.update?de(e.update.expression):"";return`for ((${t}; ${n}; ${r})); do
83
- ${lt(e.body)}
84
- done${mt(e.redirections)}`}function dp(e){return`while ${lt(e.condition)}; do
85
- ${lt(e.body)}
86
- done${mt(e.redirections)}`}function pp(e){return`until ${lt(e.condition)}; do
87
- ${lt(e.body)}
88
- done${mt(e.redirections)}`}function hp(e){let t=e.items.map(mp).join(`
83
+ fi${gt(e.redirections)}`}function wp(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let n=e.words.map(Ae).join(" ");t=`for ${e.variable} in ${n}`}return`${t}; do
84
+ ${ct(e.body)}
85
+ done${gt(e.redirections)}`}function Ep(e){let t=e.init?de(e.init.expression):"",n=e.condition?de(e.condition.expression):"",r=e.update?de(e.update.expression):"";return`for ((${t}; ${n}; ${r})); do
86
+ ${ct(e.body)}
87
+ done${gt(e.redirections)}`}function bp(e){return`while ${ct(e.condition)}; do
88
+ ${ct(e.body)}
89
+ done${gt(e.redirections)}`}function Sp(e){return`until ${ct(e.condition)}; do
90
+ ${ct(e.body)}
91
+ done${gt(e.redirections)}`}function Ap(e){let t=e.items.map(vp).join(`
89
92
  `);return`case ${Ae(e.word)} in
90
93
  ${t}
91
- esac${mt(e.redirections)}`}function mp(e){let t=e.patterns.map(Ae).join(" | "),n=lt(e.body);return n?`${t})
94
+ esac${gt(e.redirections)}`}function vp(e){let t=e.patterns.map(Ae).join(" | "),n=ct(e.body);return n?`${t})
92
95
  ${n}
93
96
  ${e.terminator}`:`${t})
94
- ${e.terminator}`}function yp(e){return`(${lt(e.body)})${mt(e.redirections)}`}function gp(e){return`{ ${lt(e.body)}; }${mt(e.redirections)}`}function wp(e){return`((${de(e.expression.expression)}))${mt(e.redirections)}`}function Ep(e){return`[[ ${An(e.expression)} ]]${mt(e.redirections)}`}function bp(e){let t=Il(e.body);return`${e.name}() ${t}${mt(e.redirections)}`}function de(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`${de(e.left)} ${e.operator} ${de(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${de(e.operand)}`:`${de(e.operand)}${e.operator}`;case"ArithTernary":return`${de(e.condition)} ? ${de(e.consequent)} : ${de(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${de(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${de(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${de(e.target)}[${de(e.subscript)}]`:de(e.target)} ${e.operator} ${de(e.value)}`;case"ArithDynamicElement":return`${de(e.nameExpr)}[${de(e.subscript)}]`;case"ArithGroup":return`(${de(e.expression)})`;case"ArithNested":return`$((${de(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}[${de(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(de).join("");case"ArithDoubleSubscript":return`${e.array}[${de(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`${Ae(e.left)} ${e.operator} ${Ae(e.right)}`;case"CondUnary":return`${e.operator} ${Ae(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 Ae(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var Sp="BASH_ALIAS_";function es(e,t,n,r){let s=B(t);if(s>n-r.value)throw new P(`alias expansion exceeds string length limit (${n} bytes)`,"string_length");return r.value+=s,e+t}function Tl(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function Fl(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function Ml(e,t){return e.env.get(`${Sp}${t}`)}function Wl(e,t,n){return Vl(e,t,n)}function Vl(e,t,n,r=!0){if(!t.name||!Tl(t.name))return t;let s=Fl(t.name);if(!s)return t;let i=Ml(e,s);if(!i||n.has(s))return t;try{n.add(s);let o=new H,a={value:0},l=es("",i,e.limits.maxStringLength,a),c=i.endsWith(" ");if(!c)for(let p of t.args){let h=Ae(p);l=es(l,` ${h}`,e.limits.maxStringLength,a)}let u;try{u=o.parse(l)}catch(p){if(p instanceof ke)throw p;return t}if(u.statements.length!==1||u.statements[0].pipelines.length!==1||u.statements[0].pipelines[0].commands.length!==1)return Bl(e,t,i);let f=u.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return Bl(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(!Tl(h))break;let y=Fl(h),E=y?Ml(e,y):null;if(!E)break;if(p>=e.limits.maxCallDepth)throw new P(`alias expansion depth limit exceeded (${e.limits.maxCallDepth})`,"recursion");p++;let S={type:"SimpleCommand",name:h,args:d.args.slice(1),assignments:[],redirections:[]},g=Vl(e,S,n,!1);if(g===S||(d={...d,name:g.name,args:[...g.args]},!E.endsWith(" ")))break}}return d}catch(o){throw n.delete(s),o}}function Bl(e,t,n){let r={value:0},s=es("",n,e.limits.maxStringLength,r);for(let c of t.args){let u=Ae(c);s=es(s,` ${u}`,e.limits.maxStringLength,r)}let i=new H,o=i.parseWordFromString("eval",!1,!1),a=0;for(let c of s)c==="'"&&a++;if(r.value+2+a*3>e.limits.maxStringLength)throw new P(`alias expansion exceeds string length limit (${e.limits.maxStringLength} bytes)`,"string_length");let l=i.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:o,args:[l],assignments:t.assignments,redirections:t.redirections,line:t.line}}var Ap=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 Li(e){return Ap.get(e)??""}function zl(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 Ul(e){let t="^";for(let n=0;n<e.length;n++){let r=e[n];if(r==="*")t+="[^/]*";else if(r==="?")t+="[^/]";else if(r==="["){let s=n+1,i="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(i+="^",s++),s<e.length&&e[s]==="]"&&(i+="\\]",s++);let o=s;for(;o<e.length;){if(e[o]==="\\"&&o+1<e.length){o+=2;continue}if(e[o]==="["&&o+1<e.length&&e[o+1]===":"){let l=e.indexOf(":]",o+2);if(l!==-1){o=l+2;continue}}if(e[o]==="]")break;o++}let a=s;for(;s<e.length&&e[s]!=="]";){if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let l=e.indexOf(":]",s+2);if(l!==-1){let c=e.slice(s+2,l),u=Li(c);i+=u,s=l+2;continue}}if(e[s]==="\\"&&s+1<e.length){i+=`\\${e[s+1]}`,s+=2;continue}if(e[s]==="-"){let l=s===a,c=s+1===o;l||c?i+="\\-":i+="-"}else i+=e[s];s++}i+="]",t+=i,n=s}else if(r==="\\"&&n+1<e.length){let s=e[n+1];/[.+^${}()|\\*?[\]]/.test(s)?t+=`\\${s}`:t+=s,n++}else/[.+^${}()|]/.test(r)?t+=`\\${r}`:t+=r}return t+="$",me(t)}function Ti(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function Fi(e){let t=[],n="",r=0,s=!1,i=0;for(;i<e.length;){let o=e[i];if(o==="'"&&!s){s=!0,n+="\0QUOTE_START\0",i++;continue}if(o==="'"&&s){s=!1,n+="\0QUOTE_END\0",i++;continue}if(s){n+=o,i++;continue}if(o==="\\"){n+=o,i+1<e.length?(n+=e[i+1],i+=2):i++;continue}o==="("?(r++,n+=o):o===")"?(r--,n+=o):o==="|"&&r===0?(t.push(n),n=""):n+=o,i++}return t.push(n),t}var ql=5,Jt=class{fs;cwd;globignorePatterns=[];hasGlobignore=!1;globstar=!1;nullglob=!1;failglob=!1;dotglob=!1;extglob=!1;globskipdots=!0;ops={count:0};maxOps;consumeOperation;constructor(t,n,r,s){this.fs=t,this.cwd=n,typeof s=="boolean"?(this.globstar=s,this.maxOps=1e5):s?(this.globstar=s.globstar??!1,this.nullglob=s.nullglob??!1,this.failglob=s.failglob??!1,this.dotglob=s.dotglob??!1,this.extglob=s.extglob??!1,this.globskipdots=s.globskipdots??!0,this.maxOps=s.maxGlobOperations??1e5,this.consumeOperation=s.consumeOperation):this.maxOps=1e5;let i=r?.get("GLOBIGNORE");i!==void 0&&i!==""&&(this.hasGlobignore=!0,this.globignorePatterns=zl(i))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new P(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations");this.consumeOperation?.()}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(n=>{let r=n.split("/").pop()||n;if((this.hasGlobignore||this.globskipdots)&&(r==="."||r===".."))return!1;if(this.hasGlobignore){for(let s of this.globignorePatterns)if(this.matchGlobignorePattern(n,s))return!1}return!0})}matchGlobignorePattern(t,n){return Ul(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>ql))throw new P(`Glob pattern has too many ** segments (max ${ql})`,"glob_operations")}let n;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))n=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");n=await this.expandSimple(r)}return this.filterGlobignore(n)}isGlobstarValid(t){let n=t.split("/");for(let r of n)if(r.includes("**")&&r!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let n=t.startsWith("/"),r=t.split("/").filter(c=>c!==""),s=-1;for(let c=0;c<r.length;c++)if(this.hasGlobChars(r[c])){s=c;break}if(s===-1)return[t];let i,o;if(s===0)n?(i="/",o="/"):(i=this.cwd,o="");else{let c=r.slice(0,s);n?(i=`/${c.join("/")}`,o=`/${c.join("/")}`):(i=this.fs.resolvePath(this.cwd,c.join("/")),o=c.join("/"))}let a=r.slice(s);return(await this.expandSegments(i,o,a)).sort()}async expandSegments(t,n,r){if(this.checkOpsLimit(),r.length===0)return[n];let[s,...i]=r,o=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(t),l=[],c=[...a],u=this.dotglob||this.hasGlobignore;if(s.startsWith(".")||this.dotglob){let d=a.some(h=>h.name==="."),p=a.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)o.push(...d)}else{this.checkOpsLimit();let a=await this.fs.readdir(t),l=[],c=[...a],u=this.dotglob||this.hasGlobignore;(s.startsWith(".")||this.dotglob)&&(a.includes(".")||c.push("."),a.includes("..")||c.push(".."));for(let d of c)if(!(d.startsWith(".")&&!s.startsWith(".")&&!u)&&this.matchPattern(d,s)){let 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(y){if(y instanceof P)throw y}return[]})())}let f=await Promise.all(l);for(let d of f)o.push(...d)}}catch(a){if(a instanceof P)throw a}return o}async expandRecursive(t){let n=[],r=t.indexOf("**"),s=t.slice(0,r).replace(/\/$/,"")||".",o=t.slice(r+2).replace(/^\//,"");return o.includes("**")&&this.isGlobstarValid(o)?(await this.walkDirectoryMultiGlobstar(s,o,n),[...new Set(n)].sort()):(await this.walkDirectory(s,o,n),n.sort())}async walkDirectoryMultiGlobstar(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let i=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(s):null;if(i){let o=[];for(let c of i){let u=t==="."?c.name:`${t}/${c.name}`;c.isDirectory&&o.push(u)}let a=t==="."?n:`${t}/${n}`,l=await this.expandRecursive(a);r.push(...l);for(let c=0;c<o.length;c+=100){let u=o.slice(c,c+100);await Promise.all(u.map(f=>this.walkDirectoryMultiGlobstar(f,n,r)))}}else{this.checkOpsLimit();let o=await this.fs.readdir(s),a=[];for(let u of o){let f=t==="."?u:`${t}/${u}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&a.push(f)}catch(p){if(p instanceof P)throw p}}let l=t==="."?n:`${t}/${n}`,c=await this.expandRecursive(l);r.push(...c);for(let u=0;u<a.length;u+=100){let f=a.slice(u,u+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,n,r)))}}}catch(i){if(i instanceof P)throw i}}async walkDirectory(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let i=await this.fs.readdirWithFileTypes(s),o=[],a=[];for(let l of i){let c=t==="."?l.name:`${t}/${l.name}`;l.isDirectory?a.push(c):n&&this.matchPattern(l.name,n)&&o.push(c)}r.push(...o);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u,n,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(s),o=[];for(let l=0;l<i.length;l+=100){let c=i.slice(l,l+100),u=await Promise.all(c.map(async f=>{let d=t==="."?f:`${t}/${f}`,p=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let h=await this.fs.stat(p);return{name:f,path:d,isDirectory:h.isDirectory}}catch(h){if(h instanceof P)throw h;return null}}));o.push(...u.filter(f=>f!==null))}for(let l of o)!l.isDirectory&&n&&this.matchPattern(l.name,n)&&r.push(l.path);let a=o.filter(l=>l.isDirectory);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,n,r)))}}}catch(i){if(i instanceof P)throw i}}matchPattern(t,n){return this.patternToRegex(n).test(t)}patternToRegex(t){let n=this.patternToRegexStr(t);return me(`^${n}$`)}patternToRegexStr(t){let n="",r=!1;for(let s=0;s<t.length;s++){if(t.slice(s,s+13)==="\0QUOTE_START\0"){r=!0,s+=12;continue}if(t.slice(s,s+11)==="\0QUOTE_END\0"){r=!1,s+=10;continue}let i=t[s];if(r){/[.+^${}()|\\*?[\]]/.test(i)?n+=`\\${i}`:n+=i;continue}if(this.extglob&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&s+1<t.length&&t[s+1]==="("){let o=Ti(t,s+1);if(o!==-1){let a=t.slice(s+2,o),l=Fi(a),c=l.map(f=>this.patternToRegexStr(f)),u=c.length>0?c.join("|"):"(?:)";if(i==="@")n+=`(?:${u})`;else if(i==="*")n+=`(?:${u})*`;else if(i==="+")n+=`(?:${u})+`;else if(i==="?")n+=`(?:${u})?`;else if(i==="!")if(o<t.length-1){let d=l.map(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 y=[];h>0&&y.push(`.{0,${h-1}}`),y.push(`.{${h+1},}`),y.push(`(?!(?:${u})).{${h}}`),n+=`(?:${y.join("|")})`}}else n+=`(?:(?!(?:${u})).)*?`}else n+=`(?!(?:${u})$).*`;s=o;continue}}if(i==="*")n+=".*";else if(i==="?")n+=".";else if(i==="["){let o=s+1,a="[";o<t.length&&(t[o]==="^"||t[o]==="!")&&(a+="^",o++),o<t.length&&t[o]==="]"&&(a+="\\]",o++);let l=o;for(;l<t.length;){if(t[l]==="\\"&&l+1<t.length){l+=2;continue}if(t[l]==="["&&l+1<t.length&&t[l+1]===":"){let u=t.indexOf(":]",l+2);if(u!==-1){l=u+2;continue}}if(t[l]==="]")break;l++}let c=o;for(;o<t.length&&t[o]!=="]";){if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let u=t.indexOf(":]",o+2);if(u!==-1){let f=t.slice(o+2,u),d=Li(f);a+=d,o=u+2;continue}}if(t[o]==="\\"&&o+1<t.length){a+=`\\${t[o+1]}`,o+=2;continue}if(t[o]==="-"){let u=o===c,f=o+1===l;u||f?a+="\\-":a+="-"}else a+=t[o];o++}a+="]",n+=a,s=o}else if(i==="\\"&&s+1<t.length){let o=t[s+1];/[.+^${}()|\\*?[\]]/.test(o)?n+=`\\${o}`:n+=o,s++}else/[.+^${}()|]/.test(i)?n+=`\\${i}`:n+=i}return n}computePatternLength(t){let n=0,r=0,s=!1;for(;r<t.length;){if(t.slice(r,r+13)==="\0QUOTE_START\0"){s=!0,r+=13;continue}if(t.slice(r,r+11)==="\0QUOTE_END\0"){s=!1,r+=11;continue}let i=t[r];if(s){n+=1,r++;continue}if((i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&r+1<t.length&&t[r+1]==="("){let o=Ti(t,r+1);if(o!==-1){if(i==="@"){let a=t.slice(r+2,o),c=Fi(a).map(u=>this.computePatternLength(u));if(c.every(u=>u!==null)&&c.every(u=>u===c[0])){n+=c[0],r=o+1;continue}return null}return null}}if(i==="*")return null;if(i==="?"){n+=1,r++;continue}if(i==="["){let o=t.indexOf("]",r+1);if(o!==-1){n+=1,r=o+1;continue}n+=1,r++;continue}if(i==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}};function Mi(e){for(let t=0;t<e.length;t++){if(e[t]==="\\"){t++;continue}if(e[t]==="$"){let n=e[t+1];if(n==="{"||n&&/[a-zA-Z_]/.test(n))return!0}}return!1}function vp(e){if(!e.operation)return!1;let t=e.operation,n;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(n=t.word?.parts),!n)return!1;for(let r of n)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function jl(e){if(!e.operation)return!1;let t=e.operation,n;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(n=t.word?.parts),!n||n.length===0)return!1;for(let r of n)if(r.type!=="DoubleQuoted"&&r.type!=="SingleQuoted")return!1;return!0}function dr(e){let t=!1,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1;for(let l of e){if((l.type==="SingleQuoted"||l.type==="DoubleQuoted")&&(t=!0,l.type==="DoubleQuoted"))for(let c of l.parts)c.type==="ParameterExpansion"&&(c.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!c.operation||c.operation.type==="PatternRemoval"||c.operation.type==="PatternReplacement")&&(s=!0),(c.operation?.type==="VarNamePrefix"||c.operation?.type==="ArrayKeys")&&(o=!0),c.operation?.type==="Indirection"&&(a=!0));l.type==="CommandSubstitution"&&(n=!0),l.type==="ParameterExpansion"&&(i=!0,(l.parameter==="@"||l.parameter==="*")&&(r=!0),vp(l)&&(t=!0),(l.operation?.type==="VarNamePrefix"||l.operation?.type==="ArrayKeys")&&(o=!0),l.operation?.type==="Indirection"&&(a=!0)),l.type==="Glob"&&Mi(l.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i,hasVarNamePrefixExpansion:o,hasIndirection:a}}var xp=`
95
- `;function xn(e,t){if(e>=t)throw new P(`array element limit exceeded (${t})`,"array_elements")}function Bi(e,t,n,r,s){xn(e.length,s),xn(t.length,s),e.push(n),t.push(r)}function ve(e){return e.get("IFS")??xp}function Re(e){return e.get("IFS")===""}function ts(e){let t=ve(e);if(t==="")return!0;for(let n of t)if(n!==" "&&n!==" "&&n!==`
96
- `)return!1;return!0}function Hl(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 Q(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var kp=`
98
- `;function $p(e){return kp.includes(e)}function Wi(e){let t=new Set,n=new Set;for(let r of e)$p(r)?t.add(r):n.add(r);return{whitespace:t,nonWhitespace:n}}function Vi(e,t,n,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:(xn(0,n),{words:[e],wordStarts:[0]});let{whitespace:i,nonWhitespace:o}=Wi(t),a=[],l=[],c=0;for(;c<e.length&&i.has(e[c]);)c++;if(c>=e.length)return{words:[],wordStarts:[]};if(o.has(e[c]))for(Bi(a,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&!(r!==void 0&&a.length>=r);){let u=c;for(;c<e.length;){let f=e[c];if(!s&&f==="\\"){c++,c<e.length&&c++;continue}if(i.has(f)||o.has(f))break;c++}if(Bi(a,l,e.substring(u,c),u,n),c>=e.length)break;for(;c<e.length&&i.has(e[c]);)c++;if(c<e.length&&o.has(e[c])){for(c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&o.has(e[c])&&!(r!==void 0&&a.length>=r);)for(Bi(a,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++}}return{words:a,wordStarts:l}}function ns(e,t,n){if(t==="")return e&&xn(0,n),{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=Wi(t),i=[],o=0,a=!1,l=!1,c=o;for(;o<e.length&&r.has(e[o]);)o++;if(o>c&&(a=!0),o>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[o]))for(xn(i.length,n),i.push(""),o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length;){let u=o;for(;o<e.length;){let d=e[o];if(r.has(d)||s.has(d))break;o++}if(xn(i.length,n),i.push(e.substring(u,o)),o>=e.length){l=!1;break}let f=o;for(;o<e.length&&r.has(e[o]);)o++;if(o<e.length&&s.has(e[o])){for(o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length&&s.has(e[o]);)for(xn(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 fe(e,t,n){return ns(e,t,n).words}function Pp(e,t){for(let n of e)if(t.has(n))return!0;return!1}function Gl(e,t,n){if(t==="")return e;let{whitespace:r,nonWhitespace:s}=Wi(t),i=e.length;for(;i>0&&r.has(e[i-1]);){if(!n&&i>=2){let a=0,l=i-2;for(;l>=0&&e[l]==="\\";)a++,l--;if(a%2===1)break}i--}let o=e.substring(0,i);if(o.length>=1&&s.has(o[o.length-1])){if(!n&&o.length>=2){let l=0,c=o.length-2;for(;c>=0&&o[c]==="\\";)l++,c--;if(l%2===1)return o}let a=o.substring(0,o.length-1);if(!Pp(a,s))return a}return o}function ce(e,t){return e.state.namerefs?.has(t)??!1}function Mt(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function Zl(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Ql(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function Kl(e,t){return e.state.invalidNamerefs?.has(t)??!1}function zi(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function rs(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let s=n[1],i=Ce(e,s),o=e.state.associativeArrays?.has(s)??!1;return i||o}return Ce(e,t)?!0:e.state.env.has(t)}function Be(e,t,n=100){if(!ce(e,t)||Kl(e,t))return t;let r=new Set,s=t;for(;n-- >0;){if(r.has(s))return;if(r.add(s),!ce(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 kn(e,t){if(ce(e,t))return e.state.env.get(t)}function ss(e,t,n,r=100){if(!ce(e,t)||Kl(e,t))return t;let s=new Set,i=t;for(;r-- >0;){if(s.has(i))return;if(s.add(i),!ce(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)&&rs(e,n)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(o))return i;i=o}}function Xl(e,t){let n=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(r,s)=>e.state.env.get(s)??"");return n=n.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(r,s)=>e.state.env.get(s)??""),n}function G(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((i,o)=>[o,i]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((i,o)=>[o,String(i)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((i,o)=>[o,i]):e.state.associativeArrays?.has(t)?$t(e,t).map(i=>[i,ae(e,t,i)??""]):Se(e,t).map(s=>[s,ae(e,t,s)??""])}function yt(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)?Ce(e,t):Ce(e,t)}async function oe(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(Q(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 Wa;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 Ue("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 Ue("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 Ue("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new Xe(`\${${t}}`);let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let o=s[1],a=s[2];if(ce(e,o)){let f=Be(e,o);if(f&&f!==o){if(f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";o=f}}if(a==="@"||a==="*"){let f=G(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=jr(a);f=Xl(e,f);let d=ae(e,o,f);if(d===void 0&&n&&e.state.options.nounset)throw new Ue(`${o}[${a}]`);return d||""}let c;if(/^-?\d+$/.test(a))c=Number.parseInt(a,10);else try{let f=new H,d=se(f,a);c=await Y(e,d.expression)}catch{let f=e.state.env.get(a);c=f?Number.parseInt(f,10):0,Number.isNaN(c)&&(c=0)}if(c<0){let f=G(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+c;return h<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${o}: bad array subscript
100
- `,""):ae(e,o,h)||""}let u=ae(e,o,c);if(u!==void 0)return u;if(c===0){let f=e.state.env.get(o);if(f!==void 0)return f}if(n&&e.state.options.nounset)throw new Ue(`${o}[${c}]`);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 Ue(t);return o||""}if(ce(e,t)){let o=Be(e,t);if(o===void 0)return"";if(o!==t)return await oe(e,o,n,r);let a=e.state.env.get(t);if((a===void 0||a==="")&&n&&e.state.options.nounset)throw new Ue(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(yt(e,t)){let o=ae(e,t,0);if(o!==void 0)return o;if(n&&e.state.options.nounset)throw new Ue(t);return""}if(n&&e.state.options.nounset)throw new Ue(t);return""}async function Ct(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(ce(e,s)){let l=Be(e,s);if(l&&l!==s){if(l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;s=l}}if(i==="@"||i==="*")return G(e,s).length>0?!0:e.state.env.has(s);if(e.state.associativeArrays?.has(s)){let l=Xl(e,jr(i));return Kt(e,s,l)}let a;if(/^-?\d+$/.test(i))a=Number.parseInt(i,10);else try{let l=new H,c=se(l,i);a=await Y(e,c.expression)}catch{let l=e.state.env.get(i);a=l?Number.parseInt(l,10):0,Number.isNaN(a)&&(a=0)}if(a<0){let l=G(e,s);if(l.length===0)return!1;let u=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+a;return u<0?!1:Kt(e,s,u)}return Kt(e,s,a)}if(ce(e,t)){let s=Be(e,t);return s===void 0||s===t?e.state.env.has(t):Ct(e,s)}return e.state.env.has(t)?!0:yt(e,t)?Kt(e,t,0):!1}async function Yl(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 oe(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 oe(e,i);n+=o,r=s;continue}if(/[*@#?\-!$]/.test(t[r+1]||"")){let s=t[r+1],i=await oe(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 oe(e,i);n+=o,r=s}else t[r]==="\\"?(n+=t[r],r++,r<t.length&&(n+=t[r],r++)):(n+=t[r],r++);r<t.length&&(n+='"',r++);continue}n+=t[r],r++}return n}async function Ui(e,t){let n=t,r=t.startsWith('"')&&t.endsWith('"'),s=t.startsWith("'")&&t.endsWith("'");if((r||s)&&(n=t.slice(1,-1)),s)return n;let i="",o=0;for(;o<n.length;)if(n[o]==="$")if(n[o+1]==="("){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="("&&n[l-1]==="$"||n[l]==="("?a++:n[l]===")"&&a--,l++;let c=n.slice(o+2,l-1);if(e.execFn){let u=await e.execFn(c,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}o=l}else if(n[o+1]==="{"){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="{"?a++:n[l]==="}"&&a--,l++;let c=n.slice(o+2,l-1),u=await oe(e,c);i+=u,o=l}else if(/[a-zA-Z_]/.test(n[o+1]||"")){let a=o+1;for(;a<n.length&&/[a-zA-Z0-9_]/.test(n[a]);)a++;let l=n.slice(o+1,a),c=await oe(e,l);i+=c,o=a}else i+=n[o],o++;else if(n[o]==="`"){let a=o+1;for(;a<n.length&&n[a]!=="`";)a++;let l=n.slice(o+1,a);if(e.execFn){let c=await e.execFn(l,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}o=a+1}else i+=n[o],o++;return i}var pr=1e4,qi={maxResults:pr,maxStringBytes:10*1024*1024};function is(e,t,n,r){if(e.length>=n.maxResults)return!1;let s=B(t);if(s>n.maxStringBytes-r.value)throw new P(`brace expansion string limit exceeded (${n.maxStringBytes} bytes)`,"string_length");return e.push(t),r.value+=s,!0}function Cp(e,t,n,r,s,i=qi){let o=n??1;o===0&&(o=1);let a=Math.abs(o),l=[],c=0;if(r?.match(/^-?0\d/)&&(c=Math.max(c,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(c=Math.max(c,s.replace(/^-/,"").length)),c>i.maxStringBytes)throw new P(`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<pr&&is(l,f(d),i,u);d+=a,p++);else for(let d=e,p=0;d>=t&&p<pr&&is(l,f(d),i,u);d-=a,p++);return l}function Np(e,t,n,r=qi){let s=n??1;s===0&&(s=1);let i=e.charCodeAt(0),o=t.charCodeAt(0),a=Math.abs(s),l=e>="A"&&e<="Z",c=e>="a"&&e<="z",u=t>="A"&&t<="Z",f=t>="a"&&t<="z";if(l&&f||c&&u){let h=n!==void 0?`..${n}`:"";throw new Lr(`{${e}..${t}${h}}: invalid sequence`)}let d=[],p={value:0};if(i<=o)for(let h=i,y=0;h<=o&&y<pr&&is(d,String.fromCharCode(h),r,p);h+=a,y++);else for(let h=i,y=0;h>=o&&y<pr&&is(d,String.fromCharCode(h),r,p);h-=a,y++);return d}function ji(e,t,n,r,s,i=qi){let o=n!==void 0?`..${n}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:Cp(e,t,n,r,s,i),literal:`{${e}..${t}${o}}`}:typeof e=="string"&&typeof t=="string"?{expanded:Np(e,t,n,i),literal:`{${e}..${t}${o}}`}:{expanded:null,literal:`{${e}..${t}${o}}`}}function Jl(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 Nt(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function Hi(e){let t="",n=0;for(;n<e.length;)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);return t}function et(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function Bn(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function te(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function J(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=Rp(e,s+1);if(o!==-1){let a=e.slice(s+2,o),c=Dp(a).map(f=>J(f,t,n)),u=c.length>0?c.join("|"):"(?:)";i==="@"?r+=`(?:${u})`:i==="*"?r+=`(?:${u})*`:i==="+"?r+=`(?:${u})+`:i==="?"?r+=`(?:${u})?`:i==="!"&&(r+=`(?!(?:${u})$).*`),s=o+1;continue}}if(i==="\\")if(s+1<e.length){let o=e[s+1];/[\\^$.|+(){}[\]*?]/.test(o)?r+=`\\${o}`:r+=o,s+=2}else r+="\\\\",s++;else if(i==="*")r+=t?".*":".*?",s++;else if(i==="?")r+=".",s++;else if(i==="["){let o=Ip(e,s);if(o===-1)r+="\\[",s++;else{let a=e.slice(s+1,o);r+=Op(a),s=o+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,s++):(r+=i,s++)}return r}function Rp(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function Dp(e){let t=[],n="",r=0,s=0;for(;s<e.length;){let i=e[s];if(i==="\\"){n+=i,s+1<e.length?(n+=e[s+1],s+=2):s++;continue}i==="("?(r++,n+=i):i===")"?(r--,n+=i):i==="|"&&r===0?(t.push(n),n=""):n+=i,s++}return t.push(n),t}function Ip(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 Op(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+=Lp(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 _p=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 Lp(e){return _p.get(e)??""}function gt(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 Wn(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 os(e,t,n,r,s){let i=new Nn(e.limits.maxStringLength,"pattern replacement",()=>new P(`pattern replacement: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length"));n.lastIndex=0;let o=0,a=n.exec(t);for(;a!==null&&(e.executionScope.consumeLimited("pattern_operations",1,e.limits.maxGlobOperations,"pattern replacement"),!(s&&a[0].length===0&&a.index===t.length||(i.append(t.slice(o,a.index)),i.append(r),o=a.index+a[0].length,!s)));)a[0].length===0&&(o++,n.lastIndex<=a.index&&(n.lastIndex=a.index+1)),a=n.exec(t);return i.append(t.slice(o)),n.lastIndex=0,i.build()}function ec(e){let t=[],n=0;return{append(r){let s=B(r);if(s>e-n)throw new P(`prompt expansion exceeds string length limit (${e} bytes)`,"string_length");r&&t.push(r),n+=s},build:()=>t.join("")}}function Tp(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=ec(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 hr(e,t){let n=ec(e.limits.maxStringLength),r=0,s=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",i=e.state.env.get("HOSTNAME")||"localhost",o=i.split(".")[0],a=e.state.env.get("PWD")||"/",l=e.state.env.get("HOME")||"/",c=a.startsWith(l)?`~${a.slice(l.length)}`:a,u=a.split("/").pop()||a,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],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 y=t[r];if(y==="\\"){if(r+1>=t.length){n.append("\\"),r++;continue}let E=t[r+1];if(E>="0"&&E<="7"){let S="",g=r+1;for(;g<t.length&&g<r+4&&t[g]>="0"&&t[g]<="7";)S+=t[g],g++;let m=Number.parseInt(S,8)%256;n.append(String.fromCharCode(m)),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(c),r+=2;break;case"W":n.append(u),r+=2;break;case"d":{let S=String(f.getDate()).padStart(2," ");n.append(`${d[f.getDay()]} ${p[f.getMonth()]} ${S}`),r+=2;break}case"t":{let S=String(f.getHours()).padStart(2,"0"),g=String(f.getMinutes()).padStart(2,"0"),m=String(f.getSeconds()).padStart(2,"0");n.append(`${S}:${g}:${m}`),r+=2;break}case"T":{let S=f.getHours()%12;S===0&&(S=12);let g=String(S).padStart(2,"0"),m=String(f.getMinutes()).padStart(2,"0"),b=String(f.getSeconds()).padStart(2,"0");n.append(`${g}:${m}:${b}`),r+=2;break}case"@":{let S=f.getHours()%12;S===0&&(S=12);let g=String(S).padStart(2,"0"),m=String(f.getMinutes()).padStart(2,"0"),b=f.getHours()<12?"AM":"PM";n.append(`${g}:${m} ${b}`),r+=2;break}case"A":{let S=String(f.getHours()).padStart(2,"0"),g=String(f.getMinutes()).padStart(2,"0");n.append(`${S}:${g}`),r+=2;break}case"D":if(r+2<t.length&&t[r+2]==="{"){let S=t.indexOf("}",r+3);if(S!==-1){let g=t.slice(r+3,S);n.append(Tp(g,f,e.limits.maxStringLength)),r=S+1}else n.append("\\D"),r+=2}else n.append("\\D"),r+=2;break;case"s":n.append("bash"),r+=2;break;case"v":n.append("5.0"),r+=2;break;case"V":n.append("5.0.0"),r+=2;break;case"j":n.append("0"),r+=2;break;case"l":n.append("tty"),r+=2;break;case"#":n.append(h),r+=2;break;case"!":n.append(h),r+=2;break;case"x":n.append("\\x"),r+=2;break;default:n.append(`\\${E}`),r+=2}}else n.append(y),r++}return n.build()}function en(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`
97
+ ${e.terminator}`}function xp(e){return`(${ct(e.body)})${gt(e.redirections)}`}function kp(e){return`{ ${ct(e.body)}; }${gt(e.redirections)}`}function $p(e){return`((${de(e.expression.expression)}))${gt(e.redirections)}`}function Pp(e){return`[[ ${kn(e.expression)} ]]${gt(e.redirections)}`}function Cp(e){let t=Wl(e.body);return`${e.name}() ${t}${gt(e.redirections)}`}function de(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`${de(e.left)} ${e.operator} ${de(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${de(e.operand)}`:`${de(e.operand)}${e.operator}`;case"ArithTernary":return`${de(e.condition)} ? ${de(e.consequent)} : ${de(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${de(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${de(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${de(e.target)}[${de(e.subscript)}]`:de(e.target)} ${e.operator} ${de(e.value)}`;case"ArithDynamicElement":return`${de(e.nameExpr)}[${de(e.subscript)}]`;case"ArithGroup":return`(${de(e.expression)})`;case"ArithNested":return`$((${de(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}[${de(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(de).join("");case"ArithDoubleSubscript":return`${e.array}[${de(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 kn(e){switch(e.type){case"CondBinary":return`${Ae(e.left)} ${e.operator} ${Ae(e.right)}`;case"CondUnary":return`${e.operator} ${Ae(e.operand)}`;case"CondNot":return`! ${kn(e.operand)}`;case"CondAnd":return`${kn(e.left)} && ${kn(e.right)}`;case"CondOr":return`${kn(e.left)} || ${kn(e.right)}`;case"CondGroup":return`( ${kn(e.expression)} )`;case"CondWord":return Ae(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var Np="BASH_ALIAS_";function rs(e,t,n,r){let s=M(t);if(s>n-r.value)throw new P(`alias expansion exceeds string length limit (${n} bytes)`,"string_length");return r.value+=s,e+t}function ql(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function jl(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function Hl(e,t){return e.env.get(`${Np}${t}`)}function Zl(e,t,n){return Ql(e,t,n)}function Ql(e,t,n,r=!0){if(!t.name||!ql(t.name))return t;let s=jl(t.name);if(!s)return t;let i=Hl(e,s);if(!i||n.has(s))return t;try{n.add(s);let o=new H,a={value:0},l=rs("",i,e.limits.maxStringLength,a),c=i.endsWith(" ");if(!c)for(let p of t.args){let h=Ae(p);l=rs(l,` ${h}`,e.limits.maxStringLength,a)}let u;try{u=o.parse(l)}catch(p){if(p instanceof ke)throw p;return t}if(u.statements.length!==1||u.statements[0].pipelines.length!==1||u.statements[0].pipelines[0].commands.length!==1)return Gl(e,t,i);let f=u.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return Gl(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(!ql(h))break;let y=jl(h),E=y?Hl(e,y):null;if(!E)break;if(p>=e.limits.maxCallDepth)throw new P(`alias expansion depth limit exceeded (${e.limits.maxCallDepth})`,"recursion");p++;let S={type:"SimpleCommand",name:h,args:d.args.slice(1),assignments:[],redirections:[]},m=Ql(e,S,n,!1);if(m===S||(d={...d,name:m.name,args:[...m.args]},!E.endsWith(" ")))break}}return d}catch(o){throw n.delete(s),o}}function Gl(e,t,n){let r={value:0},s=rs("",n,e.limits.maxStringLength,r);for(let c of t.args){let u=Ae(c);s=rs(s,` ${u}`,e.limits.maxStringLength,r)}let i=new H,o=i.parseWordFromString("eval",!1,!1),a=0;for(let c of s)c==="'"&&a++;if(r.value+2+a*3>e.limits.maxStringLength)throw new P(`alias expansion exceeds string length limit (${e.limits.maxStringLength} bytes)`,"string_length");let l=i.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:o,args:[l],assignments:t.assignments,redirections:t.redirections,line:t.line}}var Rp=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function Bi(e){return Rp.get(e)??""}function Kl(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 Xl(e){let t="^";for(let n=0;n<e.length;n++){let r=e[n];if(r==="*")t+="[^/]*";else if(r==="?")t+="[^/]";else if(r==="["){let s=n+1,i="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(i+="^",s++),s<e.length&&e[s]==="]"&&(i+="\\]",s++);let o=s;for(;o<e.length;){if(e[o]==="\\"&&o+1<e.length){o+=2;continue}if(e[o]==="["&&o+1<e.length&&e[o+1]===":"){let l=e.indexOf(":]",o+2);if(l!==-1){o=l+2;continue}}if(e[o]==="]")break;o++}let a=s;for(;s<e.length&&e[s]!=="]";){if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let l=e.indexOf(":]",s+2);if(l!==-1){let c=e.slice(s+2,l),u=Bi(c);i+=u,s=l+2;continue}}if(e[s]==="\\"&&s+1<e.length){i+=`\\${e[s+1]}`,s+=2;continue}if(e[s]==="-"){let l=s===a,c=s+1===o;l||c?i+="\\-":i+="-"}else i+=e[s];s++}i+="]",t+=i,n=s}else if(r==="\\"&&n+1<e.length){let s=e[n+1];/[.+^${}()|\\*?[\]]/.test(s)?t+=`\\${s}`:t+=s,n++}else/[.+^${}()|]/.test(r)?t+=`\\${r}`:t+=r}return t+="$",me(t)}function Wi(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 Vi(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 Yl=5,en=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=Kl(i))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new P(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations");this.consumeOperation?.()}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(n=>{let r=n.split("/").pop()||n;if((this.hasGlobignore||this.globskipdots)&&(r==="."||r===".."))return!1;if(this.hasGlobignore){for(let s of this.globignorePatterns)if(this.matchGlobignorePattern(n,s))return!1}return!0})}matchGlobignorePattern(t,n){return Xl(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>Yl))throw new P(`Glob pattern has too many ** segments (max ${Yl})`,"glob_operations")}let n;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))n=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");n=await this.expandSimple(r)}return this.filterGlobignore(n)}isGlobstarValid(t){let n=t.split("/");for(let r of n)if(r.includes("**")&&r!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let n=t.startsWith("/"),r=t.split("/").filter(c=>c!==""),s=-1;for(let c=0;c<r.length;c++)if(this.hasGlobChars(r[c])){s=c;break}if(s===-1)return[t];let i,o;if(s===0)n?(i="/",o="/"):(i=this.cwd,o="");else{let c=r.slice(0,s);n?(i=`/${c.join("/")}`,o=`/${c.join("/")}`):(i=this.fs.resolvePath(this.cwd,c.join("/")),o=c.join("/"))}let a=r.slice(s);return(await this.expandSegments(i,o,a)).sort()}async expandSegments(t,n,r){if(this.checkOpsLimit(),r.length===0)return[n];let[s,...i]=r,o=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(t),l=[],c=[...a],u=this.dotglob||this.hasGlobignore;if(s.startsWith(".")||this.dotglob){let d=a.some(h=>h.name==="."),p=a.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)o.push(...d)}else{this.checkOpsLimit();let a=await this.fs.readdir(t),l=[],c=[...a],u=this.dotglob||this.hasGlobignore;(s.startsWith(".")||this.dotglob)&&(a.includes(".")||c.push("."),a.includes("..")||c.push(".."));for(let d of c)if(!(d.startsWith(".")&&!s.startsWith(".")&&!u)&&this.matchPattern(d,s)){let 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(y){if(y instanceof P)throw y}return[]})())}let f=await Promise.all(l);for(let d of f)o.push(...d)}}catch(a){if(a instanceof P)throw a}return o}async expandRecursive(t){let n=[],r=t.indexOf("**"),s=t.slice(0,r).replace(/\/$/,"")||".",o=t.slice(r+2).replace(/^\//,"");return o.includes("**")&&this.isGlobstarValid(o)?(await this.walkDirectoryMultiGlobstar(s,o,n),[...new Set(n)].sort()):(await this.walkDirectory(s,o,n),n.sort())}async walkDirectoryMultiGlobstar(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let i=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(s):null;if(i){let o=[];for(let c of i){let u=t==="."?c.name:`${t}/${c.name}`;c.isDirectory&&o.push(u)}let a=t==="."?n:`${t}/${n}`,l=await this.expandRecursive(a);r.push(...l);for(let c=0;c<o.length;c+=100){let u=o.slice(c,c+100);await Promise.all(u.map(f=>this.walkDirectoryMultiGlobstar(f,n,r)))}}else{this.checkOpsLimit();let o=await this.fs.readdir(s),a=[];for(let u of o){let f=t==="."?u:`${t}/${u}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&a.push(f)}catch(p){if(p instanceof P)throw p}}let l=t==="."?n:`${t}/${n}`,c=await this.expandRecursive(l);r.push(...c);for(let u=0;u<a.length;u+=100){let f=a.slice(u,u+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,n,r)))}}}catch(i){if(i instanceof P)throw i}}async walkDirectory(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let i=await this.fs.readdirWithFileTypes(s),o=[],a=[];for(let l of i){let c=t==="."?l.name:`${t}/${l.name}`;l.isDirectory?a.push(c):n&&this.matchPattern(l.name,n)&&o.push(c)}r.push(...o);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u,n,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(s),o=[];for(let l=0;l<i.length;l+=100){let c=i.slice(l,l+100),u=await Promise.all(c.map(async f=>{let d=t==="."?f:`${t}/${f}`,p=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let h=await this.fs.stat(p);return{name:f,path:d,isDirectory:h.isDirectory}}catch(h){if(h instanceof P)throw h;return null}}));o.push(...u.filter(f=>f!==null))}for(let l of o)!l.isDirectory&&n&&this.matchPattern(l.name,n)&&r.push(l.path);let a=o.filter(l=>l.isDirectory);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,n,r)))}}}catch(i){if(i instanceof P)throw i}}matchPattern(t,n){return this.patternToRegex(n).test(t)}patternToRegex(t){let n=this.patternToRegexStr(t);return me(`^${n}$`)}patternToRegexStr(t){let n="",r=!1;for(let s=0;s<t.length;s++){if(t.slice(s,s+13)==="\0QUOTE_START\0"){r=!0,s+=12;continue}if(t.slice(s,s+11)==="\0QUOTE_END\0"){r=!1,s+=10;continue}let i=t[s];if(r){/[.+^${}()|\\*?[\]]/.test(i)?n+=`\\${i}`:n+=i;continue}if(this.extglob&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&s+1<t.length&&t[s+1]==="("){let o=Wi(t,s+1);if(o!==-1){let a=t.slice(s+2,o),l=Vi(a),c=l.map(f=>this.patternToRegexStr(f)),u=c.length>0?c.join("|"):"(?:)";if(i==="@")n+=`(?:${u})`;else if(i==="*")n+=`(?:${u})*`;else if(i==="+")n+=`(?:${u})+`;else if(i==="?")n+=`(?:${u})?`;else if(i==="!")if(o<t.length-1){let d=l.map(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 y=[];h>0&&y.push(`.{0,${h-1}}`),y.push(`.{${h+1},}`),y.push(`(?!(?:${u})).{${h}}`),n+=`(?:${y.join("|")})`}}else n+=`(?:(?!(?:${u})).)*?`}else n+=`(?!(?:${u})$).*`;s=o;continue}}if(i==="*")n+=".*";else if(i==="?")n+=".";else if(i==="["){let o=s+1,a="[";o<t.length&&(t[o]==="^"||t[o]==="!")&&(a+="^",o++),o<t.length&&t[o]==="]"&&(a+="\\]",o++);let l=o;for(;l<t.length;){if(t[l]==="\\"&&l+1<t.length){l+=2;continue}if(t[l]==="["&&l+1<t.length&&t[l+1]===":"){let u=t.indexOf(":]",l+2);if(u!==-1){l=u+2;continue}}if(t[l]==="]")break;l++}let c=o;for(;o<t.length&&t[o]!=="]";){if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let u=t.indexOf(":]",o+2);if(u!==-1){let f=t.slice(o+2,u),d=Bi(f);a+=d,o=u+2;continue}}if(t[o]==="\\"&&o+1<t.length){a+=`\\${t[o+1]}`,o+=2;continue}if(t[o]==="-"){let u=o===c,f=o+1===l;u||f?a+="\\-":a+="-"}else a+=t[o];o++}a+="]",n+=a,s=o}else if(i==="\\"&&s+1<t.length){let o=t[s+1];/[.+^${}()|\\*?[\]]/.test(o)?n+=`\\${o}`:n+=o,s++}else/[.+^${}()|]/.test(i)?n+=`\\${i}`:n+=i}return n}computePatternLength(t){let n=0,r=0,s=!1;for(;r<t.length;){if(t.slice(r,r+13)==="\0QUOTE_START\0"){s=!0,r+=13;continue}if(t.slice(r,r+11)==="\0QUOTE_END\0"){s=!1,r+=11;continue}let i=t[r];if(s){n+=1,r++;continue}if((i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&r+1<t.length&&t[r+1]==="("){let o=Wi(t,r+1);if(o!==-1){if(i==="@"){let a=t.slice(r+2,o),c=Vi(a).map(u=>this.computePatternLength(u));if(c.every(u=>u!==null)&&c.every(u=>u===c[0])){n+=c[0],r=o+1;continue}return null}return null}}if(i==="*")return null;if(i==="?"){n+=1,r++;continue}if(i==="["){let o=t.indexOf("]",r+1);if(o!==-1){n+=1,r=o+1;continue}n+=1,r++;continue}if(i==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}};function zi(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 Dp(e){if(!e.operation)return!1;let t=e.operation,n;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(n=t.word?.parts),!n)return!1;for(let r of n)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function Jl(e){if(!e.operation)return!1;let t=e.operation,n;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(n=t.word?.parts),!n||n.length===0)return!1;for(let r of n)if(r.type!=="DoubleQuoted"&&r.type!=="SingleQuoted")return!1;return!0}function yr(e){let t=!1,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1;for(let l of e){if((l.type==="SingleQuoted"||l.type==="DoubleQuoted")&&(t=!0,l.type==="DoubleQuoted"))for(let c of l.parts)c.type==="ParameterExpansion"&&(c.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!c.operation||c.operation.type==="PatternRemoval"||c.operation.type==="PatternReplacement")&&(s=!0),(c.operation?.type==="VarNamePrefix"||c.operation?.type==="ArrayKeys")&&(o=!0),c.operation?.type==="Indirection"&&(a=!0));l.type==="CommandSubstitution"&&(n=!0),l.type==="ParameterExpansion"&&(i=!0,(l.parameter==="@"||l.parameter==="*")&&(r=!0),Dp(l)&&(t=!0),(l.operation?.type==="VarNamePrefix"||l.operation?.type==="ArrayKeys")&&(o=!0),l.operation?.type==="Indirection"&&(a=!0)),l.type==="Glob"&&zi(l.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i,hasVarNamePrefixExpansion:o,hasIndirection:a}}var Ip=`
98
+ `;function Pn(e,t){if(e>=t)throw new P(`array element limit exceeded (${t})`,"array_elements")}function Ui(e,t,n,r,s){Pn(e.length,s),Pn(t.length,s),e.push(n),t.push(r)}function ve(e){return e.get("IFS")??Ip}function Re(e){return e.get("IFS")===""}function ss(e){let t=ve(e);if(t==="")return!0;for(let n of t)if(n!==" "&&n!==" "&&n!==`
99
+ `)return!1;return!0}function ec(e){let t=!1,n=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?n.push(`\\${r}`):r===" "?n.push("\\t"):r===`
100
+ `?n.push("\\n"):n.push(r);return t&&n.push("\\-"),n.join("")}function Q(e){let t=e.get("IFS");if(t===void 0)return" ";let n=t.codePointAt(0);return n===void 0?"":String.fromCodePoint(n)}var Op=`
101
+ `;function _p(e){return Op.includes(e)}function qi(e){let t=new Set,n=new Set;for(let r of e)_p(r)?t.add(r):n.add(r);return{whitespace:t,nonWhitespace:n}}function ji(e,t,n,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:(Pn(0,n),{words:[e],wordStarts:[0]});let{whitespace:i,nonWhitespace:o}=qi(t),a=[],l=[],c=0;for(;c<e.length&&i.has(e[c]);)c++;if(c>=e.length)return{words:[],wordStarts:[]};if(o.has(e[c]))for(Ui(a,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&!(r!==void 0&&a.length>=r);){let u=c;for(;c<e.length;){let f=e[c];if(!s&&f==="\\"){c++,c<e.length&&c++;continue}if(i.has(f)||o.has(f))break;c++}if(Ui(a,l,e.substring(u,c),u,n),c>=e.length)break;for(;c<e.length&&i.has(e[c]);)c++;if(c<e.length&&o.has(e[c])){for(c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&o.has(e[c])&&!(r!==void 0&&a.length>=r);)for(Ui(a,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++}}return{words:a,wordStarts:l}}function is(e,t,n){if(t==="")return e&&Pn(0,n),{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=qi(t),i=[],o=0,a=!1,l=!1,c=o;for(;o<e.length&&r.has(e[o]);)o++;if(o>c&&(a=!0),o>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[o]))for(Pn(i.length,n),i.push(""),o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length;){let u=o;for(;o<e.length;){let d=e[o];if(r.has(d)||s.has(d))break;o++}if(Pn(i.length,n),i.push(e.substring(u,o)),o>=e.length){l=!1;break}let f=o;for(;o<e.length&&r.has(e[o]);)o++;if(o<e.length&&s.has(e[o])){for(o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length&&s.has(e[o]);)for(Pn(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 fe(e,t,n){return is(e,t,n).words}function Lp(e,t){for(let n of e)if(t.has(n))return!0;return!1}function tc(e,t,n){if(t==="")return e;let{whitespace:r,nonWhitespace:s}=qi(t),i=e.length;for(;i>0&&r.has(e[i-1]);){if(!n&&i>=2){let a=0,l=i-2;for(;l>=0&&e[l]==="\\";)a++,l--;if(a%2===1)break}i--}let o=e.substring(0,i);if(o.length>=1&&s.has(o[o.length-1])){if(!n&&o.length>=2){let l=0,c=o.length-2;for(;c>=0&&o[c]==="\\";)l++,c--;if(l%2===1)return o}let a=o.substring(0,o.length-1);if(!Lp(a,s))return a}return o}function ce(e,t){return e.state.namerefs?.has(t)??!1}function Bt(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function nc(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function rc(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function sc(e,t){return e.state.invalidNamerefs?.has(t)??!1}function Hi(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function os(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let s=n[1],i=Ce(e,s),o=e.state.associativeArrays?.has(s)??!1;return i||o}return Ce(e,t)?!0:e.state.env.has(t)}function Be(e,t,n=100){if(!ce(e,t)||sc(e,t))return t;let r=new Set,s=t;for(;n-- >0;){if(r.has(s))return;if(r.add(s),!ce(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(ce(e,t))return e.state.env.get(t)}function as(e,t,n,r=100){if(!ce(e,t)||sc(e,t))return t;let s=new Set,i=t;for(;r-- >0;){if(s.has(i))return;if(s.add(i),!ce(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)&&os(e,n)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(o))return i;i=o}}function ic(e,t){let n=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(r,s)=>e.state.env.get(s)??"");return n=n.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(r,s)=>e.state.env.get(s)??""),n}function G(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((i,o)=>[o,i]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((i,o)=>[o,String(i)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((i,o)=>[o,i]):e.state.associativeArrays?.has(t)?Ct(e,t).map(i=>[i,oe(e,t,i)??""]):Se(e,t).map(s=>[s,oe(e,t,s)??""])}function wt(e,t){return t==="FUNCNAME"?(e.state.funcNameStack?.length??0)>0:t==="BASH_LINENO"?(e.state.callLineStack?.length??0)>0:t==="BASH_SOURCE"?(e.state.sourceStack?.length??0)>0:e.state.associativeArrays?.has(t)?Ce(e,t):Ce(e,t)}async function se(e,t,n=!0){switch(t){case"?":return String(e.state.lastExitCode);case"$":return String(e.state.virtualPid);case"#":return e.state.env.get("#")||"0";case"@":return e.state.env.get("@")||"";case"_":return e.state.lastArg;case"-":{let i="";return i+="h",e.state.options.errexit&&(i+="e"),e.state.options.noglob&&(i+="f"),e.state.options.nounset&&(i+="u"),e.state.options.verbose&&(i+="v"),e.state.options.xtrace&&(i+="x"),i+="B",e.state.options.noclobber&&(i+="C"),i+="s",i}case"*":{let i=Number.parseInt(e.state.env.get("#")||"0",10);if(i===0)return"";let o=[];for(let a=1;a<=i;a++)o.push(e.state.env.get(String(a))||"");return o.join(Q(e.state.env))}case"0":return e.state.env.get("0")||"bash";case"PWD":return e.state.env.get("PWD")??"";case"OLDPWD":return e.state.env.get("OLDPWD")??"";case"PPID":return String(e.state.virtualPpid);case"UID":return String(e.state.virtualUid);case"EUID":return String(e.state.virtualUid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-e.state.startTime)/1e3));case"BASH_VERSION":return Za;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let i=e.state.funcNameStack?.[0];if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new Ue("FUNCNAME");return""}case"BASH_LINENO":{let i=e.state.callLineStack?.[0];if(i!==void 0)return String(i);if(n&&e.state.options.nounset)throw new Ue("BASH_LINENO");return""}case"BASH_SOURCE":{let i=e.state.sourceStack?.[0];if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new Ue("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new Xe(`\${${t}}`);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let i=r[1],o=r[2];if(ce(e,i)){let u=Be(e,i);if(u&&u!==i){if(u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";i=u}}if(o==="@"||o==="*"){let u=G(e,i);if(u.length>0){let d=o==="*"?Q(e.state.env):" ",p=M(d)*(u.length-1);for(let[,h]of u)if(p+=M(h),p>e.limits.maxStringLength)throw new P(`array expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return u.map(([,h])=>h).join(d)}let f=e.state.env.get(i);return f!==void 0?f:""}if(i==="FUNCNAME"){let u=Number.parseInt(o,10);return!Number.isNaN(u)&&u>=0?e.state.funcNameStack?.[u]??"":""}if(i==="BASH_LINENO"){let u=Number.parseInt(o,10);if(!Number.isNaN(u)&&u>=0){let f=e.state.callLineStack?.[u];return f!==void 0?String(f):""}return""}if(i==="BASH_SOURCE"){let u=Number.parseInt(o,10);return!Number.isNaN(u)&&u>=0?e.state.sourceStack?.[u]??"":""}if(e.state.associativeArrays?.has(i)){let u=Zr(o);u=ic(e,u);let f=oe(e,i,u);if(f===void 0&&n&&e.state.options.nounset)throw new Ue(`${i}[${o}]`);return f||""}let l;if(/^-?\d+$/.test(o))l=Number.parseInt(o,10);else try{let u=new H,f=ne(u,o);l=await Y(e,f.expression)}catch{let u=e.state.env.get(o);l=u?Number.parseInt(u,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let u=G(e,i),f=e.state.currentLine;if(u.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${i}: bad array subscript
102
+ `,"";let p=Math.max(...u.map(([y])=>typeof y=="number"?y:0))+1+l;return p<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${i}: bad array subscript
103
+ `,""):oe(e,i,p)||""}let c=oe(e,i,l);if(c!==void 0)return c;if(l===0){let u=e.state.env.get(i);if(u!==void 0)return u}if(n&&e.state.options.nounset)throw new Ue(`${i}[${l}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let i=e.state.env.get(t);if(i===void 0&&n&&e.state.options.nounset)throw new Ue(t);return i||""}if(ce(e,t)){let i=Be(e,t);if(i===void 0)return"";if(i!==t)return await se(e,i,n);let o=e.state.env.get(t);if((o===void 0||o==="")&&n&&e.state.options.nounset)throw new Ue(t);return o||""}let s=e.state.env.get(t);if(s!==void 0)return e.state.tempEnvBindings?.some(i=>i.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),s;if(wt(e,t)){let i=oe(e,t,0);if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new Ue(t);return""}if(n&&e.state.options.nounset)throw new Ue(t);return""}async function Rt(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(ce(e,s)){let l=Be(e,s);if(l&&l!==s){if(l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;s=l}}if(i==="@"||i==="*")return G(e,s).length>0?!0:e.state.env.has(s);if(e.state.associativeArrays?.has(s)){let l=ic(e,Zr(i));return Xt(e,s,l)}let a;if(/^-?\d+$/.test(i))a=Number.parseInt(i,10);else try{let l=new H,c=ne(l,i);a=await Y(e,c.expression)}catch{let l=e.state.env.get(i);a=l?Number.parseInt(l,10):0,Number.isNaN(a)&&(a=0)}if(a<0){let l=G(e,s);if(l.length===0)return!1;let u=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+a;return u<0?!1:Xt(e,s,u)}return Xt(e,s,a)}if(ce(e,t)){let s=Be(e,t);return s===void 0||s===t?e.state.env.has(t):Rt(e,s)}return e.state.env.has(t)?!0:wt(e,t)?Xt(e,t,0):!1}async function oc(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 se(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 se(e,i);n+=o,r=s;continue}if(/[*@#?\-!$]/.test(t[r+1]||"")){let s=t[r+1],i=await se(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 se(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 Gi(e,t){let n=t,r=t.startsWith('"')&&t.endsWith('"'),s=t.startsWith("'")&&t.endsWith("'");if((r||s)&&(n=t.slice(1,-1)),s)return n;let i="",o=0;for(;o<n.length;)if(n[o]==="$")if(n[o+1]==="("){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="("&&n[l-1]==="$"||n[l]==="("?a++:n[l]===")"&&a--,l++;let c=n.slice(o+2,l-1);if(e.execFn){let u=await e.execFn(c,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}o=l}else if(n[o+1]==="{"){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="{"?a++:n[l]==="}"&&a--,l++;let c=n.slice(o+2,l-1),u=await se(e,c);i+=u,o=l}else if(/[a-zA-Z_]/.test(n[o+1]||"")){let a=o+1;for(;a<n.length&&/[a-zA-Z0-9_]/.test(n[a]);)a++;let l=n.slice(o+1,a),c=await se(e,l);i+=c,o=a}else i+=n[o],o++;else if(n[o]==="`"){let a=o+1;for(;a<n.length&&n[a]!=="`";)a++;let l=n.slice(o+1,a);if(e.execFn){let c=await e.execFn(l,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}o=a+1}else i+=n[o],o++;return i}var gr=1e4,Zi={maxResults:gr,maxStringBytes:10*1024*1024};function ls(e,t,n,r){if(e.length>=n.maxResults)return!1;let s=M(t);if(s>n.maxStringBytes-r.value)throw new P(`brace expansion string limit exceeded (${n.maxStringBytes} bytes)`,"string_length");return e.push(t),r.value+=s,!0}function Tp(e,t,n,r,s,i=Zi){let o=n??1;o===0&&(o=1);let a=Math.abs(o),l=[],c=0;if(r?.match(/^-?0\d/)&&(c=Math.max(c,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(c=Math.max(c,s.replace(/^-/,"").length)),c>i.maxStringBytes)throw new P(`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<gr&&ls(l,f(d),i,u);d+=a,p++);else for(let d=e,p=0;d>=t&&p<gr&&ls(l,f(d),i,u);d-=a,p++);return l}function Fp(e,t,n,r=Zi){let s=n??1;s===0&&(s=1);let i=e.charCodeAt(0),o=t.charCodeAt(0),a=Math.abs(s),l=e>="A"&&e<="Z",c=e>="a"&&e<="z",u=t>="A"&&t<="Z",f=t>="a"&&t<="z";if(l&&f||c&&u){let h=n!==void 0?`..${n}`:"";throw new Fr(`{${e}..${t}${h}}: invalid sequence`)}let d=[],p={value:0};if(i<=o)for(let h=i,y=0;h<=o&&y<gr&&ls(d,String.fromCharCode(h),r,p);h+=a,y++);else for(let h=i,y=0;h>=o&&y<gr&&ls(d,String.fromCharCode(h),r,p);h-=a,y++);return d}function Qi(e,t,n,r,s,i=Zi){let o=n!==void 0?`..${n}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:Tp(e,t,n,r,s,i),literal:`{${e}..${t}${o}}`}:typeof e=="string"&&typeof t=="string"?{expanded:Fp(e,t,n,i),literal:`{${e}..${t}${o}}`}:{expanded:null,literal:`{${e}..${t}${o}}`}}function ac(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 Dt(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function Ki(e){let t="",n=0;for(;n<e.length;)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);return t}function et(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function Vn(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function le(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ie(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=Mp(e,s+1);if(o!==-1){let a=e.slice(s+2,o),c=Bp(a).map(f=>ie(f,t,n)),u=c.length>0?c.join("|"):"(?:)";i==="@"?r+=`(?:${u})`:i==="*"?r+=`(?:${u})*`:i==="+"?r+=`(?:${u})+`:i==="?"?r+=`(?:${u})?`:i==="!"&&(r+=`(?!(?:${u})$).*`),s=o+1;continue}}if(i==="\\")if(s+1<e.length){let o=e[s+1];/[\\^$.|+(){}[\]*?]/.test(o)?r+=`\\${o}`:r+=o,s+=2}else r+="\\\\",s++;else if(i==="*")r+=t?".*":".*?",s++;else if(i==="?")r+=".",s++;else if(i==="["){let o=Wp(e,s);if(o===-1)r+="\\[",s++;else{let a=e.slice(s+1,o);r+=Vp(a),s=o+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,s++):(r+=i,s++)}return r}function Mp(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 Bp(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 Wp(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 Vp(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+=Up(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 zp=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 Up(e){return zp.get(e)??""}async function tn(e,t,n,r,s){let i="",o=e.state.shoptOptions.extglob;for(let a of t.parts)if(a.type==="Glob")i+=ie(a.pattern,n,o);else if(a.type==="Literal")i+=ie(a.value,n,o);else if(a.type==="SingleQuoted"||a.type==="Escaped")i+=le(a.value);else if(a.type==="DoubleQuoted"){let l=await r(e,a.parts);i+=le(l)}else if(a.type==="ParameterExpansion"){let l=await s(e,a);i+=ie(l,n,o)}else{let l=await s(e,a);i+=le(l)}return i}function Et(e,t,n,r,s){if(r==="prefix")return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),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 zn(e,t){let n=new Set;for(let r of e.state.env.keys())r.startsWith(t)&&n.add(r);for(let r of e.state.arrays?.keys()??[])r.startsWith(t)&&n.add(r);return[...n].sort()}function cs(e,t,n,r,s){let i=new In(e.limits.maxStringLength,"pattern replacement",()=>new P(`pattern replacement: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length"));n.lastIndex=0;let o=0,a=n.exec(t);for(;a!==null&&(e.executionScope.consumeLimited("pattern_operations",1,e.limits.maxGlobOperations,"pattern replacement"),!(s&&a[0].length===0&&a.index===t.length||(i.append(t.slice(o,a.index)),i.append(r),o=a.index+a[0].length,!s)));)a[0].length===0&&(o++,n.lastIndex<=a.index&&(n.lastIndex=a.index+1)),a=n.exec(t);return i.append(t.slice(o)),n.lastIndex=0,i.build()}function lc(e){let t=[],n=0;return{append(r){let s=M(r);if(s>e-n)throw new P(`prompt expansion exceeds string length limit (${e} bytes)`,"string_length");r&&t.push(r),n+=s},build:()=>t.join("")}}function qp(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=lc(n),i=0;for(;i<e.length;)if(e[i]==="%"){if(i+1>=e.length){s.append("%"),i++;continue}let o=e[i+1];switch(o){case"H":s.append(r(t.getHours()));break;case"M":s.append(r(t.getMinutes()));break;case"S":s.append(r(t.getSeconds()));break;case"d":s.append(r(t.getDate()));break;case"m":s.append(r(t.getMonth()+1));break;case"Y":s.append(String(t.getFullYear()));break;case"y":s.append(r(t.getFullYear()%100));break;case"I":{let a=t.getHours()%12;a===0&&(a=12),s.append(r(a));break}case"p":s.append(t.getHours()<12?"AM":"PM");break;case"P":s.append(t.getHours()<12?"am":"pm");break;case"%":s.append("%");break;case"a":{let a=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];s.append(a[t.getDay()]);break}case"b":{let a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];s.append(a[t.getMonth()]);break}default:s.append(`%${o}`)}i+=2}else s.append(e[i]),i++;return s.build()}function wr(e,t){let n=lc(e.limits.maxStringLength),r=0,s=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",i=e.state.env.get("HOSTNAME")||"localhost",o=i.split(".")[0],a=e.state.env.get("PWD")||"/",l=e.state.env.get("HOME")||"/",c=a.startsWith(l)?`~${a.slice(l.length)}`:a,u=a.split("/").pop()||a,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],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 y=t[r];if(y==="\\"){if(r+1>=t.length){n.append("\\"),r++;continue}let E=t[r+1];if(E>="0"&&E<="7"){let S="",m=r+1;for(;m<t.length&&m<r+4&&t[m]>="0"&&t[m]<="7";)S+=t[m],m++;let g=Number.parseInt(S,8)%256;n.append(String.fromCharCode(g)),r=m;continue}switch(E){case"\\":n.append("\\"),r+=2;break;case"a":n.append("\x07"),r+=2;break;case"e":n.append("\x1B"),r+=2;break;case"n":n.append(`
104
+ `),r+=2;break;case"r":n.append("\r"),r+=2;break;case"$":n.append("$"),r+=2;break;case"[":case"]":r+=2;break;case"u":n.append(s),r+=2;break;case"h":n.append(o),r+=2;break;case"H":n.append(i),r+=2;break;case"w":n.append(c),r+=2;break;case"W":n.append(u),r+=2;break;case"d":{let S=String(f.getDate()).padStart(2," ");n.append(`${d[f.getDay()]} ${p[f.getMonth()]} ${S}`),r+=2;break}case"t":{let S=String(f.getHours()).padStart(2,"0"),m=String(f.getMinutes()).padStart(2,"0"),g=String(f.getSeconds()).padStart(2,"0");n.append(`${S}:${m}:${g}`),r+=2;break}case"T":{let S=f.getHours()%12;S===0&&(S=12);let m=String(S).padStart(2,"0"),g=String(f.getMinutes()).padStart(2,"0"),b=String(f.getSeconds()).padStart(2,"0");n.append(`${m}:${g}:${b}`),r+=2;break}case"@":{let S=f.getHours()%12;S===0&&(S=12);let m=String(S).padStart(2,"0"),g=String(f.getMinutes()).padStart(2,"0"),b=f.getHours()<12?"AM":"PM";n.append(`${m}:${g} ${b}`),r+=2;break}case"A":{let S=String(f.getHours()).padStart(2,"0"),m=String(f.getMinutes()).padStart(2,"0");n.append(`${S}:${m}`),r+=2;break}case"D":if(r+2<t.length&&t[r+2]==="{"){let S=t.indexOf("}",r+3);if(S!==-1){let m=t.slice(r+3,S);n.append(qp(m,f,e.limits.maxStringLength)),r=S+1}else n.append("\\D"),r+=2}else n.append("\\D"),r+=2;break;case"s":n.append("bash"),r+=2;break;case"v":n.append("5.0"),r+=2;break;case"V":n.append("5.0.0"),r+=2;break;case"j":n.append("0"),r+=2;break;case"l":n.append("tty"),r+=2;break;case"#":n.append(h),r+=2;break;case"!":n.append(h),r+=2;break;case"x":n.append("\\x"),r+=2;break;default:n.append(`\\${E}`),r+=2}}else n.append(y),r++}return n.build()}function nn(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
105
  `:n+="\\n";break;case"\r":n+="\\r";break;case" ":n+="\\t";break;default:{let s=r.charCodeAt(0);s<32||s===127?n+=`\\${s.toString(8).padStart(3,"0")}`:n+=r}}return`${n}'`}return`'${e}'`}function Ze(e,t){e.state.readonlyVars=e.state.readonlyVars||new Set,e.state.readonlyVars.add(t)}function We(e,t){return e.state.readonlyVars?.has(t)??!1}function ue(e,t,n="bash"){if(We(e,t)){let r=`${n}: ${t}: readonly variable
103
- `;throw new q(1,"",r)}return null}function wt(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 as(e,t){e.state.exportedVars?.delete(t)}function tn(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let n="",r=xe(e,t)?.kind==="indexed",s=e.state.associativeArrays?.has(t)??!1;return r&&!s&&(n+="a"),s&&(n+="A"),e.state.integerVars?.has(t)&&(n+="i"),ce(e,t)&&(n+="n"),We(e,t)&&(n+="r"),e.state.exportedVars?.has(t)&&(n+="x"),n}async function tc(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 nc(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,c]=a,u;if(/^\d+$/.test(c))u=Number.parseInt(c,10);else{try{let f=new H,d=se(f,c);u=await Y(e,d.expression)}catch{let f=e.state.env.get(c);u=f?Number.parseInt(f,10):0}Number.isNaN(u)&&(u=0)}j(e,l,u,o)}else e.state.env.set(t,o);return o}return r.effectiveValue}async function rc(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:error_if_unset"),r.isUnset||n.checkEmpty&&r.isEmpty){let o=n.word?await s(e,n.word.parts,r.inDoubleQuotes):`${t}: parameter null or not set`;throw new q(1,"",`bash: ${o}
104
- `)}return r.effectiveValue}async function sc(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 ic(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+=J(a.pattern,n.greedy,o);else if(a.type==="Literal")i+=J(a.value,n.greedy,o);else if(a.type==="SingleQuoted"||a.type==="Escaped")i+=te(a.value);else if(a.type==="DoubleQuoted"){let l=await r(e,a.parts);i+=te(l)}else if(a.type==="ParameterExpansion"){let l=await s(e,a);i+=J(l,n.greedy,o)}else{let l=await s(e,a);i+=te(l)}return gt(e,t,i,n.side,n.greedy)}async function oc(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",o=e.state.shoptOptions.extglob;if(n.pattern)for(let c of n.pattern.parts)if(c.type==="Glob")i+=J(c.pattern,!0,o);else if(c.type==="Literal")i+=J(c.value,!0,o);else if(c.type==="SingleQuoted"||c.type==="Escaped")i+=te(c.value);else if(c.type==="DoubleQuoted"){let u=await r(e,c.parts);i+=te(u)}else if(c.type==="ParameterExpansion"){let u=await s(e,c);i+=J(u,!0,o)}else{let u=await s(e,c);i+=te(u)}let a=n.replacement?await r(e,n.replacement.parts):"";if(n.anchor==="start"?i=`^${i}`:n.anchor==="end"&&(i=`${i}$`),i==="")return t;let l=n.all?"gs":"s";try{let c=me(i,l);return os(e,t,c,a,n.all)}catch(c){if(c instanceof P)throw c;return t}}function ac(e,t,n){e.coverage?.hit("bash:expansion:length");let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(r){let s=r[1],i=G(e,s);return i.length>0?String(i.length):e.state.env.get(s)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&yt(e,t)){if(t==="FUNCNAME"){let i=e.state.funcNameStack?.[0]||"";return String([...i].length)}if(t==="BASH_LINENO"){let i=e.state.callLineStack?.[0];return String(i!==void 0?[...String(i)].length:0)}let s=ae(e,t,0)||"";return String([...s].length)}return String([...n].length)}async function lc(e,t,n,r){e.coverage?.hit("bash:expansion:substring");let s=await Y(e,r.offset.expression),i=r.length?await Y(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 o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(o){let c=o[1];if(e.state.associativeArrays?.has(c))throw new q(1,"",`bash: \${${c}[@]: 0: 3}: bad substitution
105
- `);let u=G(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(([y])=>typeof y=="number"&&y>=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 le(`${o[1]}[@]: substring expression < 0`);return u.slice(f,f+i).map(([,d])=>d).join(" ")}return u.slice(f).map(([,d])=>d).join(" ")}let a=[...n],l=s;if(l<0&&(l=Math.max(0,a.length+l)),i!==void 0){if(i<0){let c=a.length+i;return a.slice(l,Math.max(l,c)).join("")}return a.slice(l,l+i).join("")}return a.slice(l).join("")}async function cc(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+=J(f.pattern,!0,i);else if(f.type==="Literal")o+=J(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")o+=te(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);o+=te(d)}else if(f.type==="ParameterExpansion"){let d=await s(e,f);o+=J(d,!0,i)}let a=me(`^(?:${o})$`),l=n.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),c="",u=!1;for(let f of t)!n.all&&u?c+=f:a.test(f)?(c+=l(f),u=!0):c+=f;return c}return n.direction==="upper"?n.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):n.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function uc(e,t,n,r,s){e.coverage?.hit("bash:expansion:transform");let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i&&s.operator==="Q")return G(e,i[1]).map(([,c])=>en(c)).join(" ");if(i&&s.operator==="a")return tn(e,i[1]);let o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(o&&s.operator==="a")return tn(e,o[1]);switch(s.operator){case"Q":return r?"":en(n);case"P":return hr(e,n);case"a":return tn(e,t);case"A":return r?"":`${t}=${en(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?"":en(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 fc(e,t,n,r,s,i,o=!1){if(e.coverage?.hit("bash:expansion:indirection"),ce(e,t))return kn(e,t)||"";let a=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(s.innerOp?.type==="UseAlternative")return"";throw new Xe(`\${!${t}}`)}let l=n;if(a&&(l===""||l.includes(" ")))throw new Xe(`\${!${t}}`);let c=l.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(c&&c[1].includes("~"))throw new Xe(`\${!${t}}`);if(s.innerOp){let u={type:"ParameterExpansion",parameter:l,operation:s.innerOp};return i(e,u,o)}return await oe(e,l)}function dc(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=G(e,t.array).map(([s])=>String(s));return t.star?r.join(Q(e.state.env)):r.join(" ")}function pc(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let n=Wn(e,t.prefix);return t.star?n.join(Q(e.state.env)):n.join(" ")}function hc(e,t,n,r){let s=Number.parseInt(e.state.env.get("#")||"0",10),i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:s===0,effectiveValue:n};if(t==="@")return{isEmpty:s===0||s===1&&e.state.env.get("1")==="",effectiveValue:n};if(i){let[,o,a]=i,l=G(e,o);if(l.length===0)return{isEmpty:!0,effectiveValue:""};if(a==="*"){let c=Q(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 nn(e,t){e.lastExitCode=t,e.env.set("?",String(t)),e.lastSubstitutionExitCode=t}function Fp(e){switch(e.operator){case"<":case"<&":case"<<":case"<<-":case"<<<":case"<>":return e.fd===null||e.fd===0;default:return!1}}function ls(e,t){return t.some(Fp)?0:e.lastSubstitutionExitCode??0}function mc(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 yc(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 cs(e,t){let n=new H,r;try{r=n.parse(t)}catch{return""}let s=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let i=new Map(e.state.env),o=ot(e.state.arrays),a=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let c=await e.executeScript(r),u=c.exitCode;return e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.suppressVerbose=l,nn(e.state,u),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr),e.state.bashPid=s,c.stdout.replace(/\n+$/,"")}catch(c){return e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.bashPid=s,e.state.suppressVerbose=l,Mr(c),c instanceof q?(nn(e.state,c.exitCode),c.stdout?.replace(/\n+$/,"")??""):""}}function Gi(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=et(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=Mp(e,a);n+=et(l),r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}function Mp(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 gc(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=et(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=await Bp(e,a);n+=et(l),r=i+1;continue}}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=yc(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await cs(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 cs(e,o);n+=a,r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}async function Bp(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){n+=i,r+=2;continue}n+=s,r++;continue}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=yc(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await cs(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 cs(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 Zi(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 rn(e,t){return t.split(":").map(n=>Zi(e,n)).join(":")}function De(e,t,n,r){if(e.length>n-t.length)throw new P(`${r} element limit exceeded (${n})`,"array_elements");for(let s of t)e.push(s)}async function Wp(e,t,n,r){let s="";for(let i of t.parts)if(i.type==="Glob")s+=J(i.pattern,!0,e.state.shoptOptions.extglob);else if(i.type==="Literal")s+=J(i.value,!0,e.state.shoptOptions.extglob);else if(i.type==="SingleQuoted"||i.type==="Escaped")s+=te(i.value);else if(i.type==="DoubleQuoted"){let o=await n(e,i.parts);s+=te(o)}else if(i.type==="ParameterExpansion"){let o=await r(e,i);s+=J(o,!0,e.state.shoptOptions.extglob)}else{let o=await r(e,i);s+=te(o)}return s}async function wc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternReplacement")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",c=i.operation,u=G(e,a),f=u.map(([,E])=>E);if(u.length===0){let E=e.state.env.get(a);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let d="";c.pattern&&(d=await Wp(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 y=[];try{let E=me(h,c.all?"g":"");for(let S of f)y.push(E.replace(S,p))}catch{y.push(...f)}if(l){let E=Q(e.state.env);return{values:[y.join(E)],quoted:!0}}return{values:y,quoted:!0}}async function Ec(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternRemoval")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",c=i.operation,u=G(e,a),f=u.map(([,y])=>y);if(u.length===0){let y=e.state.env.get(a);y!==void 0&&f.push(y)}if(f.length===0)return{values:[],quoted:!0};let d="",p=e.state.shoptOptions.extglob;if(c.pattern)for(let y of c.pattern.parts)if(y.type==="Glob")d+=J(y.pattern,c.greedy,p);else if(y.type==="Literal")d+=J(y.value,c.greedy,p);else if(y.type==="SingleQuoted"||y.type==="Escaped")d+=te(y.value);else if(y.type==="DoubleQuoted"){let E=await n(e,y.parts);d+=te(E)}else if(y.type==="ParameterExpansion"){let E=await r(e,y);d+=J(E,c.greedy,p)}else{let E=await r(e,y);d+=te(E)}let h=[];for(let y of f)h.push(gt(e,y,d,c.side,c.greedy));if(l){let y=Q(e.state.env);return{values:[h.join(y)],quoted:!0}}return{values:h,quoted:!0}}async function bc(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 c=G(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"?o=u&&!(d&&f):o=!u||d&&f,!o){if(c.length>0){let h=c.map(([,y])=>y);if(a){let y=Q(e.state.env);return{values:[h.join(y)],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 Ct(e,l),u=await oe(e,l),f=u==="",d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=c&&!(d&&f):o=!c||d&&f,!o)return{values:[u],quoted:!0}}if(o&&s.word){let l=s.word.parts,c=null,u=!1;for(let f of l)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){c=d[1],u=d[2]==="*";break}}if(c){let f=G(e,c);if(f.length>0){let p=f.map(([,h])=>h);if(u||a){let h=Q(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 Sc(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0],o=-1,a="",l=!1,c=null;for(let y=0;y<i.parts.length;y++){let E=i.parts[y];if(E.type==="ParameterExpansion"&&(E.operation?.type==="PatternRemoval"||E.operation?.type==="PatternReplacement")){let S=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(S){o=y,a=S[1],l=S[2]==="*",c=E.operation;break}}}if(o===-1||o===0&&o===i.parts.length-1)return null;let u="";for(let y=0;y<o;y++)u+=await r(e,i.parts[y]);let f="";for(let y=o+1;y<i.parts.length;y++)f+=await r(e,i.parts[y]);let d=G(e,a),p=d.map(([,y])=>y);if(d.length===0){let y=e.state.env.get(a);if(y!==void 0)p=[y];else{if(l)return{values:[u+f],quoted:!0};let E=u+f;return{values:E?[E]:[],quoted:!0}}}if(c?.type==="PatternRemoval"){let y=c,E="",S=e.state.shoptOptions.extglob;if(y.pattern)for(let g of y.pattern.parts)if(g.type==="Glob")E+=J(g.pattern,y.greedy,S);else if(g.type==="Literal")E+=J(g.value,y.greedy,S);else if(g.type==="SingleQuoted"||g.type==="Escaped")E+=te(g.value);else if(g.type==="DoubleQuoted"){let m=await s(e,g.parts);E+=te(m)}else if(g.type==="ParameterExpansion"){let m=await r(e,g);E+=J(m,y.greedy,S)}else{let m=await r(e,g);E+=te(m)}p=p.map(g=>gt(e,g,E,y.side,y.greedy))}else if(c?.type==="PatternReplacement"){let y=c,E="";if(y.pattern)for(let m of y.pattern.parts)if(m.type==="Glob")E+=J(m.pattern,!0,e.state.shoptOptions.extglob);else if(m.type==="Literal")E+=J(m.value,!0,e.state.shoptOptions.extglob);else if(m.type==="SingleQuoted"||m.type==="Escaped")E+=te(m.value);else if(m.type==="DoubleQuoted"){let b=await s(e,m.parts);E+=te(b)}else if(m.type==="ParameterExpansion"){let b=await r(e,m);E+=J(b,!0,e.state.shoptOptions.extglob)}else{let b=await r(e,m);E+=te(b)}let S=y.replacement?await s(e,y.replacement.parts):"",g=E;y.anchor==="start"?g=`^${E}`:y.anchor==="end"&&(g=`${E}$`);try{let m=me(g,y.all?"g":"");p=p.map(b=>m.replace(b,S))}catch{}}if(l){let y=Q(e.state.env);return{values:[u+p.join(y)+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 Ac(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 y=h.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(y){i=p,o=y[1],a=y[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=G(e,o),f=u.map(([,p])=>p);if(u.length===0){let p=e.state.env.get(o);if(p!==void 0)return{values:[l+p+c],quoted:!0};if(a)return{values:[l+c],quoted:!0};let h=l+c;return{values:h?[h]:[],quoted:!0}}if(a){let p=Q(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 vc(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Substring")return null;let s=r.parts[0],i=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let o=i[1],a=i[2]==="*",l=s.operation;if(e.state.associativeArrays?.has(o))throw new q(1,"",`bash: \${${o}[@]: 0: 3}: bad substitution
107
- `);let c=l.offset?await n(e,l.offset.expression):0,u=l.length?await n(e,l.length.expression):void 0,f=G(e,o);if(f.length>e.limits.maxArrayElements)throw new P(`array transform element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let d=0;if(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(([S])=>typeof S=="number"&&S>=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 le(`${o}[@]: 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(a){let h=Q(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}function xc(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="Transform")return null;let r=n.parts[0],s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!s)return null;let i=s[1],o=s[2]==="*",a=r.operation,l=G(e,i);if(l.length===0){let d=e.state.env.get(i);if(d!==void 0){let p;switch(a.operator){case"a":p="";break;case"P":p=hr(e,d);break;case"Q":p=en(d);break;default:p=d}if(B(p)>e.limits.maxStringLength)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[p],quoted:!0}}return o?{values:[""],quoted:!0}:{values:[],quoted:!0}}let c=tn(e,i),u=[],f=0;for(let[,d]of l){let p;switch(a.operator){case"a":p=c;break;case"P":p=hr(e,d);break;case"Q":p=en(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=B(p);if(h>e.limits.maxStringLength-f)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u.push(p),f+=h}if(o){let d=Q(e.state.env);if(Math.max(0,u.length-1)*B(d)>e.limits.maxStringLength-f)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u.join(d)],quoted:!0}}return{values:u,quoted:!0}}function kc(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion")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(ce(e,i)){let l=kn(e,i);if(l?.endsWith("[@]")||l?.endsWith("[*]"))return{values:[],quoted:!0}}let o=G(e,i);if(o.length>0)return{values:o.map(([,l])=>l),quoted:!0};let a=e.state.env.get(i);return a!==void 0?{values:[a],quoted:!0}:{values:[],quoted:!0}}function $c(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation)return null;let s=n.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)||!ce(e,s))return null;let i=kn(e,s);if(!i)return null;let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!o)return null;let a=o[1],l=G(e,a);if(l.length>0)return{values:l.map(([,u])=>u),quoted:!0};let c=e.state.env.get(a);return c!==void 0?{values:[c],quoted:!0}:{values:[],quoted:!0}}async function Pc(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 oe(e,o.parameter),c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c){if(!a.innerOp&&(l==="@"||l==="*")){let h=Number.parseInt(e.state.env.get("#")||"0",10),y=[];for(let E=1;E<=h;E++)y.push(e.state.env.get(String(E))||"");return l==="*"?{values:[y.join(Q(e.state.env))],quoted:!0}:{values:y,quoted:!0}}return null}let u=c[1],f=c[2]==="*",d=G(e,u);if(a.innerOp){if(a.innerOp.type==="Substring")return Vp(e,d,u,f,a.innerOp);if(a.innerOp.type==="DefaultValue"||a.innerOp.type==="UseAlternative"||a.innerOp.type==="AssignDefault"||a.innerOp.type==="ErrorIfUnset")return zp(e,d,u,f,a.innerOp,s);if(a.innerOp.type==="Transform"&&a.innerOp.operator==="a"){let y=tn(e,u),E=d.map(()=>y);return f?{values:[E.join(Q(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let h=[];for(let[,y]of d){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:a.innerOp},S=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",y);try{let g=await r(e,E,!0);h.push(g)}finally{S!==void 0?e.state.env.set("_indirect_elem_",S):e.state.env.delete("_indirect_elem_")}}return f?{values:[h.join(Q(e.state.env))],quoted:!0}:{values:h,quoted:!0}}if(d.length>0){let h=d.map(([,y])=>y);return f?{values:[h.join(Q(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 Vp(e,t,n,r,s){let i=s.offset?await Y(e,s.offset.expression):0,o=s.length?await Y(e,s.length.expression):void 0,a=0;if(i<0){if(t.length>0){let u=t[t.length-1][0],d=(typeof u=="number"?u:0)+1+i;if(d<0)return{values:[],quoted:!0};if(a=t.findIndex(([p])=>typeof p=="number"&&p>=d),a<0)return{values:[],quoted:!0}}}else if(a=t.findIndex(([u])=>typeof u=="number"&&u>=i),a<0)return{values:[],quoted:!0};let l;if(o!==void 0){if(o<0)throw new le(`${n}[@]: substring expression < 0`);l=t.slice(a,a+o)}else l=t.slice(a);let c=l.map(([,u])=>u);return r?{values:[c.join(Q(e.state.env))],quoted:!0}:{values:c,quoted:!0}}async function zp(e,t,n,r,s,i){let o=s.checkEmpty??!1,a=t.map(([,u])=>u),l=t.length===0,c=t.length===0;if(s.type==="UseAlternative")return!c&&!(o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(s.type==="DefaultValue")return(c||o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:r?{values:[a.join(Q(e.state.env))],quoted:!0}:{values:a,quoted:!0};if(s.type==="AssignDefault"){if((c||o&&l)&&s.word){let f=await i(e,s.word.parts,!0);return j(e,n,0,f),{values:[f],quoted:!0}}return r?{values:[a.join(Q(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return r?{values:[a.join(Q(e.state.env))],quoted:!0}:{values:a,quoted:!0}}async function Cc(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 oe(e,o.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!l)return null;let c=await Ct(e,n.parameter),u=await oe(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]==="*",y=G(e,p);if(y.length>0){let S=y.map(([,g])=>g);return h?{values:[S.join(Q(e.state.env))],quoted:!0}:{values:S,quoted:!0}}let E=e.state.env.get(p);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function Nc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let n=t[0],s=n.operation.innerOp;if(!s||s.type!=="UseAlternative"&&s.type!=="DefaultValue")return null;let i=s.word;if(!i||i.parts.length!==1||i.parts[0].type!=="DoubleQuoted")return null;let o=i.parts[0];if(o.parts.length!==1||o.parts[0].type!=="ParameterExpansion"||o.parts[0].operation?.type!=="Indirection")return null;let a=o.parts[0],c=(await oe(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c)return null;let u=await oe(e,n.parameter),f=await Ct(e,n.parameter),d=u==="",p=s.checkEmpty??!1,h;if(s.type==="UseAlternative"?h=f&&!(p&&d):h=!f||p&&d,h){let y=c[1],E=c[2]==="*",S=G(e,y);if(S.length>0){let m=S.map(([,b])=>b);return E?{values:[m.join(Q(e.state.env))],quoted:!0}:{values:m,quoted:!0}}let g=e.state.env.get(y);return g!==void 0?{values:[g],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function Rc(e){let t=Number.parseInt(e.state.env.get("#")||"0",10);if(t>e.limits.maxArrayElements)throw new P(`positional parameter element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let n=[],r=0;for(let s=1;s<=t;s++){let i=e.state.env.get(String(s))||"",o=B(i);if(o>e.limits.maxStringLength-r)throw new P(`positional parameter string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n.push(i),r+=o}return n}function us(e,t,n){if(B(t)>n-B(e))throw new P(`positional expansion string limit exceeded (${n} bytes)`,"string_length");return e+t}function Qi(e,t,n,r){if(e.length>=r.limits.maxArrayElements)throw new P(`positional expansion element limit exceeded (${r.limits.maxArrayElements})`,"array_elements");let s=B(t);if(s>r.limits.maxStringLength-n.value)throw new P(`positional expansion string limit exceeded (${r.limits.maxStringLength} bytes)`,"string_length");e.push(t),n.value+=s}async function Dc(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 m=s.parts[g];if(m.type==="ParameterExpansion"&&(m.parameter==="@"||m.parameter==="*")&&m.operation?.type==="Substring"){i=g,o=m.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],m=g.length+c;if(m<0)h=[];else{let b=c<0?m:0;if(u!==void 0){let A=u<0?g.length+u:b+u;h=g.slice(b,Math.max(b,A))}else h=g.slice(b)}}else{let g=c-1;if(g>=d.length)h=[];else if(u!==void 0){let m=u<0?d.length+u:g+u;h=d.slice(g,Math.max(g,m))}else h=d.slice(g)}let y="";for(let g=0;g<i;g++)y+=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=y+E;return{values:g?[g]:[],quoted:!0}}if(o){let g=Q(e.state.env);return{values:[y+h.join(g)+E],quoted:!0}}return h.length===1?{values:[y+h[0]+E],quoted:!0}:{values:[y+h[0],...h.slice(1,-1),h[h.length-1]+E],quoted:!0}}async function Ic(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let g=0;g<s.parts.length;g++){let m=s.parts[g];if(m.type==="ParameterExpansion"&&(m.parameter==="@"||m.parameter==="*")&&m.operation?.type==="PatternReplacement"){i=g,o=m.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=Rc(e),u="";for(let g=0;g<i;g++)u=us(u,await n(e,s.parts[g]),e.limits.maxStringLength);let f="";for(let g=i+1;g<s.parts.length;g++)f=us(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+=J(g.pattern,!0,e.state.shoptOptions.extglob);else if(g.type==="Literal")d+=J(g.value,!0,e.state.shoptOptions.extglob);else if(g.type==="SingleQuoted"||g.type==="Escaped")d+=te(g.value);else if(g.type==="DoubleQuoted"){let m=await r(e,g.parts);d+=te(m)}else if(g.type==="ParameterExpansion"){let m=await n(e,g);d+=J(m,!0,e.state.shoptOptions.extglob)}else{let m=await n(e,g);d+=te(m)}let p=l.replacement?await r(e,l.replacement.parts):"",h=d;l.anchor==="start"?h=`^${d}`:l.anchor==="end"&&(h=`${d}$`);let y=[],E={value:0};try{let g=me(h,l.all?"g":"");for(let m of c){let b=0;g.lastIndex=0;for(let k=g.exec(m);k&&(b++,!!l.all);k=g.exec(m))k[0].length===0&&g.lastIndex++;let A=B(m),x=B(p),v=0,$=/\$(?:\$|&|\d+|<[^>]+>|`|')/g;for(;$.exec(p)!==null;)v++;if(A+b*x+b*v*A>e.limits.maxStringLength-E.value)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");Qi(y,g.replace(m,p),E,e)}}catch(g){if(g instanceof P)throw g;for(let m of c)Qi(y,m,E,e)}if(o){let g=Q(e.state.env);if(E.value+Math.max(0,y.length-1)*B(g)+B(u)+B(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+y.join(g)+f],quoted:!0}}if(B(u)+E.value+B(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return y.length===1?{values:[u+y[0]+f],quoted:!0}:{values:[u+y[0],...y.slice(1,-1),y[y.length-1]+f],quoted:!0}}async function Oc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let S=0;S<s.parts.length;S++){let g=s.parts[S];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="PatternRemoval"){i=S,o=g.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=Rc(e),u="";for(let S=0;S<i;S++)u=us(u,await n(e,s.parts[S]),e.limits.maxStringLength);let f="";for(let S=i+1;S<s.parts.length;S++)f=us(f,await n(e,s.parts[S]),e.limits.maxStringLength);if(c.length===0){let S=u+f;return{values:S?[S]:[],quoted:!0}}let d="",p=e.state.shoptOptions.extglob;if(l.pattern)for(let S of l.pattern.parts)if(S.type==="Glob")d+=J(S.pattern,l.greedy,p);else if(S.type==="Literal")d+=J(S.value,l.greedy,p);else if(S.type==="SingleQuoted"||S.type==="Escaped")d+=te(S.value);else if(S.type==="DoubleQuoted"){let g=await r(e,S.parts);d+=te(g)}else if(S.type==="ParameterExpansion"){let g=await n(e,S);d+=J(g,l.greedy,p)}else{let g=await n(e,S);d+=te(g)}let h=[],y={value:0};for(let S of c)Qi(h,gt(e,S,d,l.side,l.greedy),y,e);if(o){let S=Q(e.state.env);if(y.value+Math.max(0,h.length-1)*B(S)+B(u)+B(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+h.join(S)+f],quoted:!0}}if(B(u)+y.value+B(f)>e.limits.maxStringLength)throw new P(`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 _c(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 c="";for(let d=s+1;d<r.parts.length;d++)c+=await n(e,r.parts[d]);if(a===0){if(i)return{values:[l+c],quoted:!0};let d=l+c;return{values:d?[d]:[],quoted:!0}}let u=[];for(let d=1;d<=a;d++)u.push(e.state.env.get(String(d))||"");if(i){let d=Q(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 Rt(e,t,n,r){if(t.length>=e.limits.maxArrayElements)throw new P(`unquoted expansion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let s=B(n);if(s>e.limits.maxStringLength-r.value)throw new P(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");t.push(n),r.value+=s}function Ki(e,t,n,r){let s=B(n),i=Math.max(0,t.length-1);if(s>0&&i>Math.floor((e.limits.maxStringLength-r)/s))throw new P(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return t.join(n)}function Up(e){return new Jt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")})}async function fs(e,t){if(e.state.options.noglob)return t;let n=Up(e),r=[];for(let s of t)if(Nt(s,e.state.shoptOptions.extglob)){let i=await n.expand(s);if(i.length>0)De(r,i,e.limits.maxArrayElements,"unquoted glob expansion");else{if(n.hasFailglob())throw new zt(s);n.hasNullglob()||r.push(s)}}else r.push(s);return r}async function Lc(e,t,n,r){let s=-1,i="",o=!1;for(let b=0;b<t.length;b++){let A=t[b];if(A.type==="ParameterExpansion"&&A.operation?.type==="PatternReplacement"){let x=A.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(x){s=b,i=x[1],o=x[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,c=G(e,i),u=c.map(([,b])=>b);if(c.length===0){let b=e.state.env.get(i);b!==void 0&&(u=[b])}if(u.length===0)return{values:[],quoted:!1};let f="";if(l.pattern)for(let b of l.pattern.parts)if(b.type==="Glob")f+=J(b.pattern,!0,e.state.shoptOptions.extglob);else if(b.type==="Literal")f+=J(b.value,!0,e.state.shoptOptions.extglob);else if(b.type==="SingleQuoted"||b.type==="Escaped")f+=te(b.value);else if(b.type==="DoubleQuoted"){let A=await n(e,b.parts);f+=te(A)}else if(b.type==="ParameterExpansion"){let A=await r(e,b);f+=J(A,!0,e.state.shoptOptions.extglob)}else{let A=await r(e,b);f+=te(A)}let d=l.replacement?await n(e,l.replacement.parts):"",p=f;l.anchor==="start"?p=`^${f}`:l.anchor==="end"&&(p=`${f}$`);let h=[],y={value:0};try{let b=me(p,l.all?"g":"");for(let A of u)Rt(e,h,os(e,A,b,d,l.all),y)}catch(b){if(b instanceof P)throw b;for(let A of u)Rt(e,h,A,y)}let E=ve(e.state.env),S=Re(e.state.env);if(o){let b=Q(e.state.env),A=Ki(e,h,b,y.value);return S?{values:A?[A]:[],quoted:!1}:{values:fe(A,E,e.limits.maxArrayElements),quoted:!1}}if(S)return{values:h,quoted:!1};let g=[],m={value:0};for(let b of h)if(b==="")Rt(e,g,"",m);else for(let A of fe(b,E,e.limits.maxArrayElements))Rt(e,g,A,m);return{values:g,quoted:!1}}async function Tc(e,t,n,r){let s=-1,i="",o=!1;for(let m=0;m<t.length;m++){let b=t[m];if(b.type==="ParameterExpansion"&&b.operation?.type==="PatternRemoval"){let A=b.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(A){s=m,i=A[1],o=A[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,c=G(e,i),u=c.map(([,m])=>m);if(c.length===0){let m=e.state.env.get(i);m!==void 0&&(u=[m])}if(u.length===0)return{values:[],quoted:!1};let f="",d=e.state.shoptOptions.extglob;if(l.pattern)for(let m of l.pattern.parts)if(m.type==="Glob")f+=J(m.pattern,l.greedy,d);else if(m.type==="Literal")f+=J(m.value,l.greedy,d);else if(m.type==="SingleQuoted"||m.type==="Escaped")f+=te(m.value);else if(m.type==="DoubleQuoted"){let b=await n(e,m.parts);f+=te(b)}else if(m.type==="ParameterExpansion"){let b=await r(e,m);f+=J(b,l.greedy,d)}else{let b=await r(e,m);f+=te(b)}let p=[],h={value:0};for(let m of u)Rt(e,p,gt(e,m,f,l.side,l.greedy),h);let y=ve(e.state.env),E=Re(e.state.env);if(o){let m=Q(e.state.env),b=Ki(e,p,m,h.value);return E?{values:b?[b]:[],quoted:!1}:{values:fe(b,y,e.limits.maxArrayElements),quoted:!1}}if(E)return{values:p,quoted:!1};let S=[],g={value:0};for(let m of p)if(m==="")Rt(e,S,"",g);else for(let b of fe(m,y,e.limits.maxArrayElements))Rt(e,S,b,g);return{values:S,quoted:!1}}async function Fc(e,t,n,r){let s=-1,i=!1;for(let g=0;g<t.length;g++){let m=t[g];if(m.type==="ParameterExpansion"&&(m.parameter==="@"||m.parameter==="*")&&m.operation?.type==="PatternRemoval"){s=g,i=m.parameter==="*";break}}if(s===-1)return null;let a=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(a.pattern)for(let g of a.pattern.parts)if(g.type==="Glob")u+=J(g.pattern,a.greedy,f);else if(g.type==="Literal")u+=J(g.value,a.greedy,f);else if(g.type==="SingleQuoted"||g.type==="Escaped")u+=te(g.value);else if(g.type==="DoubleQuoted"){let m=await n(e,g.parts);u+=te(m)}else if(g.type==="ParameterExpansion"){let m=await r(e,g);u+=J(m,a.greedy,f)}else{let m=await r(e,g);u+=te(m)}let d=[],p={value:0};for(let g of c)Rt(e,d,gt(e,g,u,a.side,a.greedy),p);let h=ve(e.state.env),y=Re(e.state.env);if(i){let g=Q(e.state.env),m=Ki(e,d,g,p.value);return y?{values:m?[m]:[],quoted:!1}:{values:fe(m,h,e.limits.maxArrayElements),quoted:!1}}if(y)return{values:d,quoted:!1};let E=[],S={value:0};for(let g of d)if(g==="")Rt(e,E,"",S);else for(let m of fe(g,h,e.limits.maxArrayElements))Rt(e,E,m,S);return{values:E,quoted:!1}}async function Mc(e,t,n,r){let s=-1,i=!1;for(let m=0;m<t.length;m++){let b=t[m];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="Substring"){s=m,i=b.parameter==="*";break}}if(s===-1)return null;let a=t[s].operation,l=a.offset?await n(e,a.offset.expression):0,c=a.length?await n(e,a.length.expression):void 0,u=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let m=1;m<=u;m++)f.push(e.state.env.get(String(m))||"");let d=e.state.env.get("0")||"bash",p;if(l<=0){let m=[d,...f],b=m.length+l;if(b<0)p=[];else{let A=l<0?b:0;if(c!==void 0){let x=c<0?m.length+c:A+c;p=m.slice(A,Math.max(A,x))}else p=m.slice(A)}}else{let m=l-1;if(m>=f.length)p=[];else if(c!==void 0){let b=c<0?f.length+c:m+c;p=f.slice(m,Math.max(m,b))}else p=f.slice(m)}let h="";for(let m=0;m<s;m++)h+=await r(e,t[m]);let y="";for(let m=s+1;m<t.length;m++)y+=await r(e,t[m]);let E=ve(e.state.env),S=Re(e.state.env);if(p.length===0){let m=h+y;return m?S?{values:[m],quoted:!1}:{values:fe(m,E,e.limits.maxArrayElements),quoted:!1}:{values:[],quoted:!1}}let g;if(i){let m=Q(e.state.env),b=h+p.join(m)+y;S?g=b?[b]:[]:g=fe(b,E,e.limits.maxArrayElements)}else if(S)p.length===1?g=[h+p[0]+y]:g=[h+p[0],...p.slice(1,-1),p[p.length-1]+y];else{g=[];for(let m=0;m<p.length;m++){let b=p[m];if(m===0&&(b=h+b),m===p.length-1&&(b=b+y),b==="")g.push("");else{let A=fe(b,E,e.limits.maxArrayElements);De(g,A,e.limits.maxArrayElements,"unquoted expansion")}}}return{values:await fs(e,g),quoted:!1}}async function Bc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let n=t[0].parameter==="*",r=Number.parseInt(e.state.env.get("#")||"0",10);if(r===0)return{values:[],quoted:!1};let s=[];for(let c=1;c<=r;c++)s.push(e.state.env.get(String(c))||"");let i=ve(e.state.env),o=Re(e.state.env),a=ts(e.state.env),l;if(n)if(o)l=s.filter(c=>c!=="");else{let c=Q(e.state.env),u=s.join(c);l=fe(u,i,e.limits.maxArrayElements)}else if(o)l=s.filter(c=>c!=="");else if(a){l=[];for(let c of s){if(c==="")continue;let u=fe(c,i,e.limits.maxArrayElements);De(l,u,e.limits.maxArrayElements,"unquoted expansion")}}else{l=[];for(let c of s)if(c==="")l.push("");else{let u=fe(c,i,e.limits.maxArrayElements);De(l,u,e.limits.maxArrayElements,"unquoted expansion")}for(;l.length>0&&l[l.length-1]==="";)l.pop()}return{values:await fs(e,l),quoted:!1}}async function Wc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let n=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let r=n[1],s=n[2]==="*",i=G(e,r),o;if(i.length===0){let f=e.state.env.get(r);if(f!==void 0)o=[f];else return{values:[],quoted:!1}}else o=i.map(([,f])=>f);let a=ve(e.state.env),l=Re(e.state.env),c=ts(e.state.env),u;if(s)if(l)u=o.filter(f=>f!=="");else{let f=Q(e.state.env),d=o.join(f);u=fe(d,a,e.limits.maxArrayElements)}else if(l)u=o.filter(f=>f!=="");else if(c){u=[];for(let f of o){if(f==="")continue;let d=fe(f,a,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}}else{u=[];for(let f of o)if(f==="")u.push("");else{let d=fe(f,a,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}for(;u.length>0&&u[u.length-1]==="";)u.pop()}return{values:await fs(e,u),quoted:!1}}function Vc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let n=t[0].operation,r=Wn(e,n.prefix);if(r.length===0)return{values:[],quoted:!1};let s=ve(e.state.env),i=Re(e.state.env),o;if(n.star)if(i)o=r;else{let a=Q(e.state.env),l=r.join(a);o=fe(l,s,e.limits.maxArrayElements)}else if(i)o=r;else{o=[];for(let a of r){let l=fe(a,s,e.limits.maxArrayElements);De(o,l,e.limits.maxArrayElements,"unquoted expansion")}}return{values:o,quoted:!1}}function zc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let n=t[0].operation,s=G(e,n.array).map(([l])=>String(l));if(s.length===0)return{values:[],quoted:!1};let i=ve(e.state.env),o=Re(e.state.env),a;if(n.star)if(o)a=s;else{let l=Q(e.state.env),c=s.join(l);a=fe(c,i,e.limits.maxArrayElements)}else if(o)a=s;else{a=[];for(let l of s){let c=fe(l,i,e.limits.maxArrayElements);De(a,c,e.limits.maxArrayElements,"unquoted expansion")}}return{values:a,quoted:!1}}async function Uc(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=ve(e.state.env),c=Re(e.state.env),u=ts(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(c)f=d.filter(p=>p!=="");else if(u){f=[];for(let p of d){if(p==="")continue;let h=fe(p,l,e.limits.maxArrayElements);De(f,h,e.limits.maxArrayElements,"unquoted expansion")}}else{f=[];for(let p of d)if(p==="")f.push("");else{let h=fe(p,l,e.limits.maxArrayElements);De(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 fs(e,f),quoted:!1}}async function Hc(e,t,n){e.coverage?.hit("bash:expansion:word_glob");let r=t.parts,{hasQuoted:s,hasCommandSub:i,hasArrayVar:o,hasArrayAtExpansion:a,hasParamExpansion:l,hasVarNamePrefixExpansion:c,hasIndirection:u}=dr(r),d=n.hasBraceExpansion(r)?await n.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return qp(e,d,s);let p=await jp(e,r,a,c,u,n);if(p!==null)return p;let h=await Gp(e,r,n);if(h!==null)return h;let y=await Zp(e,r,n);if(y!==null)return y;let E=await Kp(e,r,n.expandPart);if(E!==null)return jc(e,E);if((i||o||l)&&!Re(e.state.env)){let g=ve(e.state.env),m=n.buildIfsCharClassPattern(g),b=await n.smartWordSplit(e,r,g,m,n.expandPart);return jc(e,b)}let S=await n.expandWordAsync(e,t);return Xp(e,t,r,S,s,n.expandWordForGlobbing)}async function qp(e,t,n){let r=[];for(let s of t)if(!(!n&&s===""))if(!n&&!e.state.options.noglob&&Nt(s,e.state.shoptOptions.extglob)){let i=await ds(e,s);De(r,i,e.limits.maxArrayElements,"brace/glob expansion")}else r.push(s);return{values:r,quoted:!1}}async function jp(e,t,n,r,s,i){if(n){let o=kc(e,t);if(o!==null)return o}{let o=$c(e,t);if(o!==null)return o}{let o=await bc(e,t);if(o!==null)return o}{let o=await Sc(e,t,n,i.expandPart,i.expandWordPartsAsync);if(o!==null)return o}{let o=await Ac(e,t,n,i.expandPart);if(o!==null)return o}{let o=await vc(e,t,i.evaluateArithmetic);if(o!==null)return o}{let o=xc(e,t);if(o!==null)return o}{let o=await wc(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}{let o=await Ec(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let o=Hp(e,t);if(o!==null)return o}{let o=await Pc(e,t,s,i.expandParameterAsync,i.expandWordPartsAsync);if(o!==null)return o}{let o=await Cc(e,t);if(o!==null)return o}{let o=await Nc(e,t);if(o!==null)return o}return null}function Hp(e,t){let n=t[0];if(n.type!=="DoubleQuoted")return null;if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="VarNamePrefix"){let r=n.parts[0].operation,s=Wn(e,r.prefix);return r.star?{values:[s.join(Q(e.state.env))],quoted:!0}:{values:s,quoted:!0}}if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="ArrayKeys"){let r=n.parts[0].operation,i=G(e,r.array).map(([o])=>String(o));return r.star?{values:[i.join(Q(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function Gp(e,t,n){{let r=await Dc(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await Ic(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Oc(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await _c(e,t,n.expandPart);if(r!==null)return r}return null}async function Zp(e,t,n){{let r=await Lc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Tc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Fc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Mc(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await Bc(e,t);if(r!==null)return r}{let r=await Wc(e,t);if(r!==null)return r}{let r=Vc(e,t);if(r!==null)return r}{let r=zc(e,t);if(r!==null)return r}{let r=await Uc(e,t,n.expandPart);if(r!==null)return r}return null}function qc(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 Qp(e,t,n,r){let s="";for(let a=0;a<n.atIndex;a++)s+=await r(e,t.parts[a]);let i="";for(let a=n.atIndex+1;a<t.parts.length;a++)i+=await r(e,t.parts[a]);let o;if(n.type==="array"){if(o=G(e,n.name).map(([,l])=>l),o.length===0){let l=e.state.env.get(n.name);l!==void 0&&(o=[l])}}else{let a=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let l=1;l<=a;l++)o.push(e.state.env.get(String(l))||"")}if(n.isStar){let a=Q(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 Kp(e,t,n){if(t.length<2)return null;let r=!1;for(let l of t)if(qc(l)){r=!0;break}if(!r)return null;let s=ve(e.state.env),i=Re(e.state.env),o=[];for(let l of t){let c=qc(l);if(c&&l.type==="DoubleQuoted"){let u=await Qp(e,l,c,n);o.push(u)}else if(l.type==="DoubleQuoted"||l.type==="SingleQuoted"){let u=await n(e,l);o.push([u])}else if(l.type==="Literal")o.push([l.value]);else if(l.type==="ParameterExpansion"){let u=await n(e,l);if(i)o.push(u?[u]:[]);else{let f=fe(u,s,e.limits.maxArrayElements);o.push(f)}}else{let u=await n(e,l);if(i)o.push(u?[u]:[]);else{let f=fe(u,s,e.limits.maxArrayElements);o.push(f)}}}let a=[];for(let l of o)if(l.length!==0)if(a.length===0)De(a,l,e.limits.maxArrayElements,"word expansion");else{let c=a.length-1;a[c]=a[c]+l[0];for(let u=1;u<l.length;u++)a.push(l[u])}return a}async function jc(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let n=[];for(let r of t)if(Nt(r,e.state.shoptOptions.extglob)){let s=await ds(e,r);De(n,s,e.limits.maxArrayElements,"glob expansion")}else n.push(r);return{values:n,quoted:!1}}async function ds(e,t){let n=new Jt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")}),r=await n.expand(t);if(r.length>0)return r;if(n.hasFailglob())throw new zt(t);return n.hasNullglob()?[]:[t]}async function Xp(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(Nt(a,e.state.shoptOptions.extglob)){let c=await ds(e,a);if(c.length>0&&c[0]!==a)return{values:c,quoted:!1};if(c.length===0)return{values:[],quoted:!1}}let l=Hi(r);if(!Re(e.state.env)){let c=ve(e.state.env);return{values:fe(l,c,e.limits.maxArrayElements),quoted:!1}}return{values:[l],quoted:!1}}if(!s&&!e.state.options.noglob&&Nt(r,e.state.shoptOptions.extglob)){let a=await i(e,t);if(Nt(a,e.state.shoptOptions.extglob)){let l=await ds(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=Hi(r);if(!Re(e.state.env)){let l=ve(e.state.env);return{values:fe(a,l,e.limits.maxArrayElements),quoted:!1}}return{values:[a],quoted:!1}}return{values:[r],quoted:s}}function Le(e,t,n){if(t.length>=e.limits.maxArrayElements)throw new P(`word splitting element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");t.push(n)}async function Zc(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 Ct(e,t.parameter),o=await oe(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 Yp(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(n=>n.type==="Literal"):!1}async function Jp(e,t){if(t.type!=="ParameterExpansion")return null;let n=await Zc(e,t);if(!n||n.length<=1)return null;let r=n.some(i=>Yp(i)),s=n.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&s?n:null}function eh(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?Mi(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&jl(e))}async function Qc(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 Zc(e,d);if(p&&p.length>0&&p.length>1&&p.some(y=>y.type==="DoubleQuoted"||y.type==="SingleQuoted")&&p.some(y=>y.type==="Literal"||y.type==="ParameterExpansion"||y.type==="CommandSubstitution"||y.type==="ArithmeticExpansion"))return Gc(e,p,n,r,s)}let i=[],o=!1;for(let d of t){let p=eh(d),h=d.type==="DoubleQuoted"||d.type==="SingleQuoted",y=p?await Jp(e,d):null,E=await s(e,d);i.push({value:E,isSplittable:p,isQuoted:h,mixedDefaultParts:y??void 0}),p&&(o=!0)}if(!o){let d=i.map(p=>p.value).join("");return d?[d]:[]}let a=[],l="",c=!1,u=!1,f=!1;for(let d of i)if(!d.isSplittable)u?d.isQuoted&&d.value===""?(l!==""&&Le(e,a,l),Le(e,a,""),c=!0,l="",u=!1,f=!0):d.value!==""?(l!==""&&Le(e,a,l),l=d.value,u=!1,f=!1):(l+=d.value,f=!1):(l+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let p=await Gc(e,d.mixedDefaultParts,n,r,s);if(p.length!==0)if(p.length===1)l+=p[0],c=!0;else{l+=p[0],Le(e,a,l),c=!0;for(let h=1;h<p.length-1;h++)Le(e,a,p[h]);l=p[p.length-1]}u=!1,f=!1}else{let{words:p,hadLeadingDelimiter:h,hadTrailingDelimiter:y}=ns(d.value,n,e.limits.maxArrayElements);if(f&&h&&l===""&&(Le(e,a,""),c=!0),p.length===0)y&&(u=!0);else if(p.length===1)l+=p[0],c=!0,u=y;else{l+=p[0],Le(e,a,l),c=!0;for(let E=1;E<p.length-1;E++)Le(e,a,p[E]);l=p[p.length-1],u=y}f=!1}return l!==""?Le(e,a,l):a.length===0&&c&&Le(e,a,""),a}function th(e,t){return e.length>0&&t.includes(e[0])}async function Gc(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 o=[],a="",l=!1,c=!1;for(let u of i)if(!u.isSplittable)c&&u.value!==""?(a!==""&&Le(e,o,a),a=u.value,c=!1):a+=u.value;else{th(u.value,n)&&a!==""&&(Le(e,o,a),a="",l=!0);let{words:d,hadTrailingDelimiter:p}=ns(u.value,n,e.limits.maxArrayElements);if(d.length===0)p&&(c=!0);else if(d.length===1)a+=d[0],l=!0,c=p;else{a+=d[0],Le(e,o,a),l=!0;for(let h=1;h<d.length-1;h++)Le(e,o,d[h]);a=d[d.length-1],c=p}}return a!==""?Le(e,o,a):o.length===0&&l&&Le(e,o,""),o}function Kc(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Xc(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}var mr=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new xt,t?.mounts)for(let{mountPoint:n,filesystem:r}of t.mounts)this.mount(n,r)}mount(t,n){this.validateMountPath(t);let r=U(t);this.validateMount(r),this.mounts.set(r,{mountPoint:r,filesystem:n})}unmount(t){let n=U(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}))}diff(t){let n=t?.space??"vfs",r=[],s=[],i=[];for(let o of this.mounts.values()){let a=o.filesystem;if(typeof a.diff!="function")throw new N("EINVAL",`mounted filesystem at '${o.mountPoint}' does not support diff()`);let l=a.diff(),c=u=>{if(n==="vfs")return o.mountPoint==="/"?u:`${o.mountPoint}${u}`;if(typeof a.rootDir!="string")throw new N("EINVAL",`cannot produce a host-space diff: mount at '${o.mountPoint}' has no real root`);return`${a.rootDir}${u}`};for(let u of l.writes)r.push({...u,path:c(u.path)});for(let u=0;u<l.deletions.length;u++)s.push(c(l.deletions[u])),i.push(l.deletionChangedAt?.[u]??0)}return{writes:r,deletions:s,...i.length>0&&{deletionChangedAt:i}}}restamp(t,n,r="full"){let{fs:s,relativePath:i}=this.routePath(t),o=s.restamp;typeof o=="function"&&o.call(s,i,n,r)}isMountPoint(t){let n=U(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){X(t,"access");let n=U(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=U(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 Cn(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=U(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=U(t),r=this.mounts.get(n);if(r)try{return await r.filesystem.stat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:ht,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:ht,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.stat(o)}async lstat(t){let n=U(t),r=this.mounts.get(n);if(r)try{return await r.filesystem.lstat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:ht,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:ht,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.lstat(o)}async mkdir(t,n){let r=U(t);if(this.mounts.has(r)){if(n?.recursive)return;throw new N("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=U(t),r=new Set,s=null,{fs:i,relativePath:o}=this.routePath(t);try{let l=await i.readdir(o);for(let c of l)r.add(c)}catch(l){if(!it(l,"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=U(t);if(this.mounts.has(r))throw new N("EBUSY",`mount point, cannot remove '${t}'`);if(this.getChildMountPoints(r).length>0)throw new N("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&&Tt(t,n))throw new N("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=U(t);if((await this.stat(t)).isDirectory&&Tt(t,n))throw new N("EINVAL",`cannot move '${t}' into itself, '${n}'`);if(this.mounts.has(r))throw new N("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 Dn(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=U(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 N("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=U(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=Ft(t,o),l=Ft(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 ps="/dev/fd",Jc=63,nh=10,Yc=Jc-nh+1,Xi=class extends xt{isLiveDescriptor;constructor(t){super(),this.isLiveDescriptor=t}assertLiveDescriptor(t,n){this.isLiveDescriptor(t)||this.refuse(t,n)}refuse(t,n){throw new N("EROFS",`read-only file system, ${n} '${ps}${t}'`)}async writeFile(t,n,r){return this.assertLiveDescriptor(t,"write"),super.writeFile(t,n,r)}async appendFile(t,n,r){return this.assertLiveDescriptor(t,"append"),super.appendFile(t,n,r)}async rm(t,n){return this.assertLiveDescriptor(t,"rm"),super.rm(t,n)}async mkdir(t,n){this.refuse(t,"mkdir")}async cp(t,n){this.refuse(n,"cp")}async mv(t,n){this.refuse(n,"mv")}async symlink(t,n){this.refuse(n,"symlink")}async link(t,n){this.refuse(n,"link")}async chmod(t,n){this.refuse(t,"chmod")}async utimes(t,n,r){this.refuse(t,"utimes")}};function rh(e){let t=new Xi(n=>eu(e).some(r=>r.path===`${ps}${n}`));e.fs=new mr({base:e.fs,mounts:[{mountPoint:ps,filesystem:t}]}),e.state.processSubstitutionFsMounted=!0}async function sh(e,t,n){try{await e.fs.writeFile(t,n,"binary");return}catch(r){if(e.state.processSubstitutionFsMounted)throw r;rh(e)}await e.fs.writeFile(t,n,"binary")}async function ih(e,t){try{await e.fs.rm(t,{force:!0})}catch{}}function eu(e){let t=e.state.processSubstitutions;if(t)return t;let n=[];return e.state.processSubstitutions=n,n}async function tu(e,t,n){let r=e.substitutionDepth??0,s=e.limits.maxSubstitutionDepth;if(r>=s)throw new P(`Process substitution nesting limit exceeded (${s})`,"substitution_depth");let i=e.substitutionDepth,o=new Map(e.state.env),a=ot(e.state.arrays),l=e.state.cwd,c=e.state.bashPid,u=e.state.suppressVerbose,f=e.state.groupStdin,d=e.state.lastExitCode,p=e.state.env.get("?"),h=e.state.lastSubstitutionExitCode;e.substitutionDepth=r+1,e.state.bashPid=e.state.nextVirtualPid++,e.state.suppressVerbose=!0,n!==void 0&&(e.state.groupStdin=n);let y;try{y=await e.executeScript(t)}catch(E){if(E instanceof P)throw E;if(E instanceof q)return{stdout:E.stdout,stderr:E.stderr,exitCode:E.exitCode};throw E}finally{e.substitutionDepth=i,e.state.env=o,e.state.arrays=a,e.state.cwd=l,e.state.bashPid=c,e.state.suppressVerbose=u,e.state.groupStdin=f,e.state.lastExitCode=d,e.state.lastSubstitutionExitCode=h,p!==void 0?e.state.env.set("?",p):e.state.env.delete("?")}return y}async function nu(e,t){let n=eu(e);if(n.length>=Yc)throw new P(`Process substitution limit exceeded (${Yc} concurrent)`,"file_descriptors");let r="";if(t.direction==="input"){let o=await tu(e,t.body,void 0);if(o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),r=Wt(o),r.length>e.limits.maxStringLength)throw new P(`process substitution: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")}let s=Jc-n.length,i=`${ps}/${s}`;n.push({fd:s,path:i,direction:t.direction,body:t.body});try{await sh(e,i,r)}catch(o){throw n.pop(),o}return i}function ru(e){return e.state.processSubstitutions?.length??0}var oh={stdout:"",stderr:""};async function Yi(e,t){let n=e.state.processSubstitutions;if(!n||n.length<=t)return oh;let r="",s="";for(;n.length>t;){let i=n[n.length-1],o="";if(i.direction==="output")try{o=await Cn(e.fs,i.path)}catch{}if(await ih(e,i.path),n.pop(),i.direction==="output"){let a=await tu(e,i.body,o);r+=Wt(a),s+=a.stderr}}return{stdout:r,stderr:s}}function sn(e,t,n){if(e.length>t)throw new P(`${n}: string length limit exceeded (${t} bytes)`,"string_length")}async function Et(e,t,n=!1){let r=[];for(let s of t)r.push(await tt(e,s,n));return r.join("")}function ah(e){return Xc(e)}function iu(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!ah(t))return!1;return!0}function lh(e,t,n=!1){let r=Kc(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 Gi(e,t.pattern);default:return null}}async function ie(e,t){return eo(e,t)}async function ou(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped")n.push(Bn(r.value));else if(r.type==="SingleQuoted")n.push(r.value);else if(r.type==="DoubleQuoted"){let s=await Et(e,r.parts);n.push(s)}else if(r.type==="TildeExpansion"){let s=await tt(e,r);n.push(Bn(s))}else n.push(await tt(e,r));return n.join("")}async function au(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped"){let s=r.value;"()|*?[]".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="SingleQuoted")n.push(et(r.value));else if(r.type==="DoubleQuoted"){let s=await Et(e,r.parts);n.push(et(s))}else n.push(await tt(e,r));return n.join("")}async function lu(e,t){let n=[];for(let r of t.parts)if(r.type==="SingleQuoted")n.push(et(r.value));else if(r.type==="Escaped"){let s=r.value;"*?[]\\()|".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="DoubleQuoted"){let s=await Et(e,r.parts);n.push(et(s))}else r.type==="Glob"?mc(r.pattern)?n.push(await gc(e,r.pattern)):n.push(Gi(e,r.pattern)):r.type==="Literal"?n.push(r.value):n.push(await tt(e,r));return n.join("")}function ms(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&ms(t.parts))return!0;return!1}var su=1e5;async function cu(e,t,n={count:0}){let r=()=>{n.count++,e.executionScope.consumeLimited("brace_operations",1,Math.min(su,e.limits.maxBraceExpansionResults),"brace expansion")},s=(o,a)=>{if(o.length>=e.limits.maxBraceExpansionResults)throw new P(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),o.push(a)},i=[[]];for(let o of t)if(o.type==="BraceExpansion"){let a=[],l=!1,c="";for(let d of o.items)if(d.type==="Range"){let p=ji(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,c=p.literal;break}}else{let p=await cu(e,d.word.parts,n);for(let h of p){let y=[];for(let E of h)typeof E=="string"?y.push(E):y.push(await tt(e,E));s(a,y.join(""))}}if(l){for(let d of i)r(),d.push(c);continue}if(i.length*a.length>e.limits.maxBraceExpansionResults||n.count>su)throw new P(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");let f=[];for(let d of i)for(let p of a){if(f.length>=e.limits.maxBraceExpansionResults)throw new P(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),f.push([...d,p])}i=f}else for(let a of i)r(),a.push(o);return i}async function uu(e,t){let n=t.parts;if(!ms(n))return[await ie(e,t)];let r=await cu(e,n),s=[];for(let i of r){let o=[];for(let a of i)typeof a=="string"?o.push(a):o.push(await tt(e,a));s.push(Zi(e,o.join("")))}return s}function ch(){return{expandWordAsync:eo,expandWordForGlobbing:lu,expandWordWithBracesAsync:uu,expandWordPartsAsync:Et,expandPart:tt,expandParameterAsync:hs,hasBraceExpansion:ms,evaluateArithmetic:Y,buildIfsCharClassPattern:Hl,smartWordSplit:Qc}}async function bt(e,t){return Hc(e,t,ch())}function uh(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Ji(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 fu(e,t){if(Ji(e,t))return{error:`bash: $@: ambiguous redirect
108
- `};let n=t.parts,{hasQuoted:r}=dr(n);if(ms(n)&&(await uu(e,t)).length>1)return{error:`bash: ${n.map(p=>p.type==="Literal"?p.value:p.type==="BraceExpansion"?`{${p.items.map(y=>{if(y.type==="Range"){let E=y.step?`..${y.step}`:"";return`${y.startStr??y.start}..${y.endStr??y.end}${E}`}return y.word.parts.map(E=>E.type==="Literal"?E.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect
109
- `};let s=await eo(e,t),{hasParamExpansion:i,hasCommandSub:o}=dr(n);if((i||o)&&!r&&!Re(e.state.env)){let f=ve(e.state.env);if(fe(s,f,e.limits.maxArrayElements).length>1)return{error:`bash: $${uh(n)}: ambiguous redirect
110
- `}}if(r||e.state.options.noglob||n.some(f=>f.type==="ProcessSubstitution"))return{target:s};let l=await lu(e,t);if(!Nt(l,e.state.shoptOptions.extglob))return{target:s};let c=new Jt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")}),u=await c.expand(l);return u.length===0?c.hasFailglob()?{error:`bash: no match: ${s}
106
+ `;throw new q(1,"",r)}return null}function bt(e,t){let n=e.state.exportedVars?.has(t)??!1;if(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(t),e.state.localScopes.length>0&&e.state.localScopes[e.state.localScopes.length-1].has(t)&&!n){for(e.state.localExportedVars||(e.state.localExportedVars=[]);e.state.localExportedVars.length<e.state.localScopes.length;)e.state.localExportedVars.push(new Set);e.state.localExportedVars[e.state.localExportedVars.length-1].add(t)}}function us(e,t){e.state.exportedVars?.delete(t)}function rn(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let n="",r=xe(e,t)?.kind==="indexed",s=e.state.associativeArrays?.has(t)??!1;return r&&!s&&(n+="a"),s&&(n+="A"),e.state.integerVars?.has(t)&&(n+="i"),ce(e,t)&&(n+="n"),We(e,t)&&(n+="r"),e.state.exportedVars?.has(t)&&(n+="x"),n}async function cc(e,t,n,r){return e.coverage?.hit("bash:expansion:default_value"),(n.isUnset||t.checkEmpty&&n.isEmpty)&&t.word?r(e,t.word.parts,n.inDoubleQuotes):n.effectiveValue}function Xi(e){if(/^(?:\d+|[@*#?$!-])$/.test(e))throw new q(1,"",`bash: $${e}: cannot assign in this way
107
+ `)}async function uc(e,t,n,r,s){e.coverage?.hit("bash:expansion:assign_default");let i=r.isUnset||n.checkEmpty&&r.isEmpty;if(i&&Xi(t),i&&n.word){let o=await s(e,n.word.parts,r.inDoubleQuotes),a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let[,l,c]=a;if(c==="@"||c==="*")throw new q(1,"",`${e.state.expansionStderr||""}bash: ${t}: bad array subscript
108
+ `);let u;if(/^\d+$/.test(c))u=Number.parseInt(c,10);else{try{let f=new H,d=ne(f,c);u=await Y(e,d.expression)}catch{let f=e.state.env.get(c);u=f?Number.parseInt(f,10):0}Number.isNaN(u)&&(u=0)}j(e,l,u,o)}else e.state.env.set(t,o);return o}return r.effectiveValue}async function fc(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:error_if_unset"),r.isUnset||n.checkEmpty&&r.isEmpty){let o=n.word?await s(e,n.word.parts,r.inDoubleQuotes):`${t}: parameter null or not set`;throw new q(1,"",`bash: ${o}
109
+ `)}return r.effectiveValue}async function dc(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 pc(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_removal");let i=n.pattern?await tn(e,n.pattern,n.greedy,r,s):"";return Et(e,t,i,n.side,n.greedy)}async function hc(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",o=e.state.shoptOptions.extglob;if(n.pattern)for(let c of n.pattern.parts)if(c.type==="Glob")i+=ie(c.pattern,!0,o);else if(c.type==="Literal")i+=ie(c.value,!0,o);else if(c.type==="SingleQuoted"||c.type==="Escaped")i+=le(c.value);else if(c.type==="DoubleQuoted"){let u=await r(e,c.parts);i+=le(u)}else if(c.type==="ParameterExpansion"){let u=await s(e,c);i+=ie(u,!0,o)}else{let u=await s(e,c);i+=le(u)}let a=n.replacement?await r(e,n.replacement.parts):"";if(n.anchor==="start"?i=`^${i}`:n.anchor==="end"&&(i=`${i}$`),i==="")return t;let l=n.all?"gs":"s";try{let c=me(i,l);return cs(e,t,c,a,n.all)}catch(c){if(c instanceof P)throw c;return t}}function Yi(e,t,n){e.coverage?.hit("bash:expansion:length");let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(r){let s=r[1],i=G(e,s);return i.length>0?String(i.length):e.state.env.get(s)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&wt(e,t)){if(t==="FUNCNAME"){let i=e.state.funcNameStack?.[0]||"";return String([...i].length)}if(t==="BASH_LINENO"){let i=e.state.callLineStack?.[0];return String(i!==void 0?[...String(i)].length:0)}let s=oe(e,t,0)||"";return String([...s].length)}return String([...n].length)}async function mc(e,t,n,r){e.coverage?.hit("bash:expansion:substring");let s=await Y(e,r.offset.expression),i=r.length?await Y(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 o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(o){let c=o[1];if(e.state.associativeArrays?.has(c))throw new q(1,"",`bash: \${${c}[@]: 0: 3}: bad substitution
110
+ `);let u=G(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(([y])=>typeof y=="number"&&y>=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 ae(`${o[1]}[@]: substring expression < 0`);return u.slice(f,f+i).map(([,d])=>d).join(" ")}return u.slice(f).map(([,d])=>d).join(" ")}let a=[...n],l=s;if(l<0&&(l=Math.max(0,a.length+l)),i!==void 0){if(i<0){let c=a.length+i;return a.slice(l,Math.max(l,c)).join("")}return a.slice(l,l+i).join("")}return a.slice(l).join("")}async function yc(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+=ie(f.pattern,!0,i);else if(f.type==="Literal")o+=ie(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")o+=le(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);o+=le(d)}else if(f.type==="ParameterExpansion"){let d=await s(e,f);o+=ie(d,!0,i)}let a=me(`^(?:${o})$`),l=n.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),c="",u=!1;for(let f of t)!n.all&&u?c+=f:a.test(f)?(c+=l(f),u=!0):c+=f;return c}return n.direction==="upper"?n.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):n.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function gc(e,t,n,r,s){e.coverage?.hit("bash:expansion:transform");let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i&&s.operator==="Q")return G(e,i[1]).map(([,c])=>nn(c)).join(" ");if(i&&s.operator==="a")return rn(e,i[1]);let o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(o&&s.operator==="a")return rn(e,o[1]);switch(s.operator){case"Q":return r?"":nn(n);case"P":return wr(e,n);case"a":return rn(e,t);case"A":return r?"":`${t}=${nn(n)}`;case"E":return n.replace(/\\([\\abefnrtv'"?])/g,(a,l)=>{switch(l){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
111
+ `;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return l}});case"K":case"k":return r?"":nn(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 wc(e,t,n,r,s,i,o=!1){if(e.coverage?.hit("bash:expansion:indirection"),ce(e,t))return Cn(e,t)||"";let a=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(s.innerOp?.type==="UseAlternative")return"";throw new Xe(`\${!${t}}`)}let l=n;if(a&&(l===""||l.includes(" ")))throw new Xe(`\${!${t}}`);let c=l.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(c&&c[1].includes("~"))throw new Xe(`\${!${t}}`);if(s.innerOp){let u={type:"ParameterExpansion",parameter:l,operation:s.innerOp};return i(e,u,o)}return await se(e,l)}function Ec(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=G(e,t.array).map(([s])=>String(s));return t.star?r.join(Q(e.state.env)):r.join(" ")}function bc(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let n=zn(e,t.prefix);return t.star?n.join(Q(e.state.env)):n.join(" ")}function Sc(e,t,n,r){let s=Number.parseInt(e.state.env.get("#")||"0",10),i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:s===0,effectiveValue:n};if(t==="@")return{isEmpty:s===0||s===1&&e.state.env.get("1")==="",effectiveValue:n};if(i){let[,o,a]=i,l=G(e,o);return l.length===0?{isEmpty:!0,effectiveValue:""}:a==="*"?{isEmpty:r?n==="":!1,effectiveValue:n}:{isEmpty:l.length===1&&l.every(([,c])=>c===""),effectiveValue:n}}return{isEmpty:n==="",effectiveValue:n}}function sn(e,t){e.lastExitCode=t,e.env.set("?",String(t)),e.lastSubstitutionExitCode=t}function jp(e){switch(e.operator){case"<":case"<&":case"<<":case"<<-":case"<<<":case"<>":return e.fd===null||e.fd===0;default:return!1}}function fs(e,t){return t.some(jp)?0:e.lastSubstitutionExitCode??0}function Ac(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 vc(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 ds(e,t){let n=new H,r;try{r=n.parse(t)}catch{return""}let s=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let i=new Map(e.state.env),o=at(e.state.arrays),a=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let c=await e.executeScript(r),u=c.exitCode;return e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.suppressVerbose=l,sn(e.state,u),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr),e.state.bashPid=s,c.stdout.replace(/\n+$/,"")}catch(c){return e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.bashPid=s,e.state.suppressVerbose=l,Vr(c),c instanceof q?(sn(e.state,c.exitCode),c.stdout?.replace(/\n+$/,"")??""):""}}function Ji(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=et(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=Hp(e,a);n+=et(l),r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}function Hp(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){n+=i,r+=2;continue}n+=s,r++;continue}if(s==="$"&&r+1<t.length){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 xc(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=et(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=await Gp(e,a);n+=et(l),r=i+1;continue}}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=vc(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await ds(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 ds(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 Gp(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){n+=i,r+=2;continue}n+=s,r++;continue}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=vc(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await ds(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 ds(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 eo(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 on(e,t){return t.split(":").map(n=>eo(e,n)).join(":")}function De(e,t,n,r){if(e.length>n-t.length)throw new P(`${r} element limit exceeded (${n})`,"array_elements");for(let s of t)e.push(s)}async function Zp(e,t,n,r){let s="";for(let i of t.parts)if(i.type==="Glob")s+=ie(i.pattern,!0,e.state.shoptOptions.extglob);else if(i.type==="Literal")s+=ie(i.value,!0,e.state.shoptOptions.extglob);else if(i.type==="SingleQuoted"||i.type==="Escaped")s+=le(i.value);else if(i.type==="DoubleQuoted"){let o=await n(e,i.parts);s+=le(o)}else if(i.type==="ParameterExpansion"){let o=await r(e,i);s+=ie(o,!0,e.state.shoptOptions.extglob)}else{let o=await r(e,i);s+=le(o)}return s}async function kc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternReplacement")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",c=i.operation,u=G(e,a),f=u.map(([,E])=>E);if(u.length===0){let E=e.state.env.get(a);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let d="";c.pattern&&(d=await Zp(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 y=[];try{let E=me(h,c.all?"g":"");for(let S of f)y.push(E.replace(S,p))}catch{y.push(...f)}if(l){let E=Q(e.state.env);return{values:[y.join(E)],quoted:!0}}return{values:y,quoted:!0}}async function $c(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternRemoval")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",c=i.operation,u=G(e,a),f=u.map(([,h])=>h);if(u.length===0){let h=e.state.env.get(a);h!==void 0&&f.push(h)}if(f.length===0)return{values:[],quoted:!0};let d=c.pattern?await tn(e,c.pattern,c.greedy,n,r):"",p=[];for(let h of f)p.push(Et(e,h,d,c.side,c.greedy));if(l){let h=Q(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}async function Pc(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="DefaultValue"&&n.parts[0].operation?.type!=="UseAlternative"&&n.parts[0].operation?.type!=="AssignDefault")return null;let r=n.parts[0];if(r.operation?.type==="AssignDefault"&&/^(?:\d+|[@*#?$!-])$/.test(r.parameter))return null;let s=r.operation,i=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(s.type==="AssignDefault"&&(!i||i[2]==="*"))return null;let o,a=!1;if(i){let l=i[1];a=i[2]==="*";let c=G(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"?o=u&&!(d&&f):o=!u||d&&f,!o){if(c.length>0){let h=c.map(([,y])=>y);if(a){let y=Q(e.state.env);return{values:[h.join(y)],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 Rt(e,l),u=await se(e,l,!1),f=u==="",d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=c&&!(d&&f):o=!c||d&&f,!o)return{values:[u],quoted:!0}}if(s.type==="AssignDefault")return null;if(o&&s.word){let l=s.word.parts,c=null,u=!1;for(let f of l)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){c=d[1],u=d[2]==="*";break}}if(c){let f=G(e,c);if(f.length>0){let p=f.map(([,h])=>h);if(u||a){let h=Q(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 Cc(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0],o=-1,a="",l=!1,c=null;for(let y=0;y<i.parts.length;y++){let E=i.parts[y];if(E.type==="ParameterExpansion"&&(E.operation?.type==="PatternRemoval"||E.operation?.type==="PatternReplacement")){let S=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(S){o=y,a=S[1],l=S[2]==="*",c=E.operation;break}}}if(o===-1||o===0&&o===i.parts.length-1)return null;let u="";for(let y=0;y<o;y++)u+=await r(e,i.parts[y]);let f="";for(let y=o+1;y<i.parts.length;y++)f+=await r(e,i.parts[y]);let d=G(e,a),p=d.map(([,y])=>y);if(d.length===0){let y=e.state.env.get(a);if(y!==void 0)p=[y];else{if(l)return{values:[u+f],quoted:!0};let E=u+f;return{values:E?[E]:[],quoted:!0}}}if(c?.type==="PatternRemoval"){let y=c,E=y.pattern?await tn(e,y.pattern,y.greedy,s,r):"";p=p.map(S=>Et(e,S,E,y.side,y.greedy))}else if(c?.type==="PatternReplacement"){let y=c,E="";if(y.pattern)for(let g of y.pattern.parts)if(g.type==="Glob")E+=ie(g.pattern,!0,e.state.shoptOptions.extglob);else if(g.type==="Literal")E+=ie(g.value,!0,e.state.shoptOptions.extglob);else if(g.type==="SingleQuoted"||g.type==="Escaped")E+=le(g.value);else if(g.type==="DoubleQuoted"){let b=await s(e,g.parts);E+=le(b)}else if(g.type==="ParameterExpansion"){let b=await r(e,g);E+=ie(b,!0,e.state.shoptOptions.extglob)}else{let b=await r(e,g);E+=le(b)}let S=y.replacement?await s(e,y.replacement.parts):"",m=E;y.anchor==="start"?m=`^${E}`:y.anchor==="end"&&(m=`${E}$`);try{let g=me(m,y.all?"g":"");p=p.map(b=>g.replace(b,S))}catch{}}if(l){let y=Q(e.state.env);return{values:[u+p.join(y)+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 Nc(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 y=h.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(y){i=p,o=y[1],a=y[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=G(e,o),f=u.map(([,p])=>p);if(u.length===0){let p=e.state.env.get(o);if(p!==void 0)return{values:[l+p+c],quoted:!0};if(a)return{values:[l+c],quoted:!0};let h=l+c;return{values:h?[h]:[],quoted:!0}}if(a){let p=Q(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 Rc(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Substring")return null;let s=r.parts[0],i=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let o=i[1],a=i[2]==="*",l=s.operation;if(e.state.associativeArrays?.has(o))throw new q(1,"",`bash: \${${o}[@]: 0: 3}: bad substitution
112
+ `);let c=l.offset?await n(e,l.offset.expression):0,u=l.length?await n(e,l.length.expression):void 0,f=G(e,o);if(f.length>e.limits.maxArrayElements)throw new P(`array transform element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let d=0;if(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(([S])=>typeof S=="number"&&S>=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 ae(`${o}[@]: 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(a){let h=Q(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}function Dc(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="Transform")return null;let r=n.parts[0],s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!s)return null;let i=s[1],o=s[2]==="*",a=r.operation,l=G(e,i);if(l.length===0){let d=e.state.env.get(i);if(d!==void 0){let p;switch(a.operator){case"a":p="";break;case"P":p=wr(e,d);break;case"Q":p=nn(d);break;default:p=d}if(M(p)>e.limits.maxStringLength)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[p],quoted:!0}}return o?{values:[""],quoted:!0}:{values:[],quoted:!0}}let c=rn(e,i),u=[],f=0;for(let[,d]of l){let p;switch(a.operator){case"a":p=c;break;case"P":p=wr(e,d);break;case"Q":p=nn(d);break;case"u":p=d.charAt(0).toUpperCase()+d.slice(1);break;case"U":p=d.toUpperCase();break;case"L":p=d.toLowerCase();break;default:p=d}let h=M(p);if(h>e.limits.maxStringLength-f)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u.push(p),f+=h}if(o){let d=Q(e.state.env);if(Math.max(0,u.length-1)*M(d)>e.limits.maxStringLength-f)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u.join(d)],quoted:!0}}return{values:u,quoted:!0}}function Ic(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(ce(e,i)){let l=Cn(e,i);if(l?.endsWith("[@]")||l?.endsWith("[*]"))return{values:[],quoted:!0}}let o=G(e,i);if(o.length>0)return{values:o.map(([,l])=>l),quoted:!0};let a=e.state.env.get(i);return a!==void 0?{values:[a],quoted:!0}:{values:[],quoted:!0}}function Oc(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)||!ce(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=G(e,a);if(l.length>0)return{values:l.map(([,u])=>u),quoted:!0};let c=e.state.env.get(a);return c!==void 0?{values:[c],quoted:!0}:{values:[],quoted:!0}}async function _c(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 se(e,o.parameter),c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c){if(!a.innerOp&&(l==="@"||l==="*")){let h=Number.parseInt(e.state.env.get("#")||"0",10),y=[];for(let E=1;E<=h;E++)y.push(e.state.env.get(String(E))||"");return l==="*"?{values:[y.join(Q(e.state.env))],quoted:!0}:{values:y,quoted:!0}}return null}let u=c[1],f=c[2]==="*",d=G(e,u);if(a.innerOp){if(a.innerOp.type==="Substring")return Qp(e,d,u,f,a.innerOp);if(a.innerOp.type==="DefaultValue"||a.innerOp.type==="UseAlternative"||a.innerOp.type==="AssignDefault"||a.innerOp.type==="ErrorIfUnset")return Kp(e,d,u,f,a.innerOp,s);if(a.innerOp.type==="Transform"&&a.innerOp.operator==="a"){let y=rn(e,u),E=d.map(()=>y);return f?{values:[E.join(Q(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let h=[];for(let[,y]of d){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:a.innerOp},S=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",y);try{let m=await r(e,E,!0);h.push(m)}finally{S!==void 0?e.state.env.set("_indirect_elem_",S):e.state.env.delete("_indirect_elem_")}}return f?{values:[h.join(Q(e.state.env))],quoted:!0}:{values:h,quoted:!0}}if(d.length>0){let h=d.map(([,y])=>y);return f?{values:[h.join(Q(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 Qp(e,t,n,r,s){let i=s.offset?await Y(e,s.offset.expression):0,o=s.length?await Y(e,s.length.expression):void 0,a=0;if(i<0){if(t.length>0){let u=t[t.length-1][0],d=(typeof u=="number"?u:0)+1+i;if(d<0)return{values:[],quoted:!0};if(a=t.findIndex(([p])=>typeof p=="number"&&p>=d),a<0)return{values:[],quoted:!0}}}else if(a=t.findIndex(([u])=>typeof u=="number"&&u>=i),a<0)return{values:[],quoted:!0};let l;if(o!==void 0){if(o<0)throw new ae(`${n}[@]: substring expression < 0`);l=t.slice(a,a+o)}else l=t.slice(a);let c=l.map(([,u])=>u);return r?{values:[c.join(Q(e.state.env))],quoted:!0}:{values:c,quoted:!0}}async function Kp(e,t,n,r,s,i){let o=s.checkEmpty??!1,a=t.map(([,u])=>u),l=t.length===0,c=t.length===0;if(s.type==="UseAlternative")return!c&&!(o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(s.type==="DefaultValue")return(c||o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:r?{values:[a.join(Q(e.state.env))],quoted:!0}:{values:a,quoted:!0};if(s.type==="AssignDefault"){if((c||o&&l)&&s.word){let f=await i(e,s.word.parts,!0);return j(e,n,0,f),{values:[f],quoted:!0}}return r?{values:[a.join(Q(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return r?{values:[a.join(Q(e.state.env))],quoted:!0}:{values:a,quoted:!0}}async function Lc(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 se(e,o.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!l)return null;let c=await Rt(e,n.parameter),u=await se(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]==="*",y=G(e,p);if(y.length>0){let S=y.map(([,m])=>m);return h?{values:[S.join(Q(e.state.env))],quoted:!0}:{values:S,quoted:!0}}let E=e.state.env.get(p);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function Tc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let n=t[0],s=n.operation.innerOp;if(!s||s.type!=="UseAlternative"&&s.type!=="DefaultValue")return null;let i=s.word;if(!i||i.parts.length!==1||i.parts[0].type!=="DoubleQuoted")return null;let o=i.parts[0];if(o.parts.length!==1||o.parts[0].type!=="ParameterExpansion"||o.parts[0].operation?.type!=="Indirection")return null;let a=o.parts[0],c=(await se(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c)return null;let u=await se(e,n.parameter),f=await Rt(e,n.parameter),d=u==="",p=s.checkEmpty??!1,h;if(s.type==="UseAlternative"?h=f&&!(p&&d):h=!f||p&&d,h){let y=c[1],E=c[2]==="*",S=G(e,y);if(S.length>0){let g=S.map(([,b])=>b);return E?{values:[g.join(Q(e.state.env))],quoted:!0}:{values:g,quoted:!0}}let m=e.state.env.get(y);return m!==void 0?{values:[m],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function Fc(e){let t=Number.parseInt(e.state.env.get("#")||"0",10);if(t>e.limits.maxArrayElements)throw new P(`positional parameter element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let n=[],r=0;for(let s=1;s<=t;s++){let i=e.state.env.get(String(s))||"",o=M(i);if(o>e.limits.maxStringLength-r)throw new P(`positional parameter string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n.push(i),r+=o}return n}function ps(e,t,n){if(M(t)>n-M(e))throw new P(`positional expansion string limit exceeded (${n} bytes)`,"string_length");return e+t}function to(e,t,n,r){if(e.length>=r.limits.maxArrayElements)throw new P(`positional expansion element limit exceeded (${r.limits.maxArrayElements})`,"array_elements");let s=M(t);if(s>r.limits.maxStringLength-n.value)throw new P(`positional expansion string limit exceeded (${r.limits.maxStringLength} bytes)`,"string_length");e.push(t),n.value+=s}async function Mc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let m=0;m<s.parts.length;m++){let g=s.parts[m];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="Substring"){i=m,o=g.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=l.offset?await n(e,l.offset.expression):0,u=l.length?await n(e,l.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),d=[];for(let m=1;m<=f;m++)d.push(e.state.env.get(String(m))||"");let p=e.state.env.get("0")||"bash",h;if(c<=0){let m=[p,...d],g=m.length+c;if(g<0)h=[];else{let b=c<0?g:0;if(u!==void 0){let v=u<0?m.length+u:b+u;h=m.slice(b,Math.max(b,v))}else h=m.slice(b)}}else{let m=c-1;if(m>=d.length)h=[];else if(u!==void 0){let g=u<0?d.length+u:m+u;h=d.slice(m,Math.max(m,g))}else h=d.slice(m)}let y="";for(let m=0;m<i;m++)y+=await r(e,s.parts[m]);let E="";for(let m=i+1;m<s.parts.length;m++)E+=await r(e,s.parts[m]);if(h.length===0){let m=y+E;return{values:m?[m]:[],quoted:!0}}if(o){let m=Q(e.state.env);return{values:[y+h.join(m)+E],quoted:!0}}return h.length===1?{values:[y+h[0]+E],quoted:!0}:{values:[y+h[0],...h.slice(1,-1),h[h.length-1]+E],quoted:!0}}async function Bc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let m=0;m<s.parts.length;m++){let g=s.parts[m];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="PatternReplacement"){i=m,o=g.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=Fc(e),u="";for(let m=0;m<i;m++)u=ps(u,await n(e,s.parts[m]),e.limits.maxStringLength);let f="";for(let m=i+1;m<s.parts.length;m++)f=ps(f,await n(e,s.parts[m]),e.limits.maxStringLength);if(c.length===0){let m=u+f;return{values:m?[m]:[],quoted:!0}}let d="";if(l.pattern)for(let m of l.pattern.parts)if(m.type==="Glob")d+=ie(m.pattern,!0,e.state.shoptOptions.extglob);else if(m.type==="Literal")d+=ie(m.value,!0,e.state.shoptOptions.extglob);else if(m.type==="SingleQuoted"||m.type==="Escaped")d+=le(m.value);else if(m.type==="DoubleQuoted"){let g=await r(e,m.parts);d+=le(g)}else if(m.type==="ParameterExpansion"){let g=await n(e,m);d+=ie(g,!0,e.state.shoptOptions.extglob)}else{let g=await n(e,m);d+=le(g)}let p=l.replacement?await r(e,l.replacement.parts):"",h=d;l.anchor==="start"?h=`^${d}`:l.anchor==="end"&&(h=`${d}$`);let y=[],E={value:0};try{let m=me(h,l.all?"g":"");for(let g of c){let b=0;m.lastIndex=0;for(let k=m.exec(g);k&&(b++,!!l.all);k=m.exec(g))k[0].length===0&&m.lastIndex++;let v=M(g),x=M(p),A=0,$=/\$(?:\$|&|\d+|<[^>]+>|`|')/g;for(;$.exec(p)!==null;)A++;if(v+b*x+b*A*v>e.limits.maxStringLength-E.value)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");to(y,m.replace(g,p),E,e)}}catch(m){if(m instanceof P)throw m;for(let g of c)to(y,g,E,e)}if(o){let m=Q(e.state.env);if(E.value+Math.max(0,y.length-1)*M(m)+M(u)+M(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+y.join(m)+f],quoted:!0}}if(M(u)+E.value+M(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return y.length===1?{values:[u+y[0]+f],quoted:!0}:{values:[u+y[0],...y.slice(1,-1),y[y.length-1]+f],quoted:!0}}async function Wc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let S=0;S<s.parts.length;S++){let m=s.parts[S];if(m.type==="ParameterExpansion"&&(m.parameter==="@"||m.parameter==="*")&&m.operation?.type==="PatternRemoval"){i=S,o=m.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=Fc(e),u="";for(let S=0;S<i;S++)u=ps(u,await n(e,s.parts[S]),e.limits.maxStringLength);let f="";for(let S=i+1;S<s.parts.length;S++)f=ps(f,await n(e,s.parts[S]),e.limits.maxStringLength);if(c.length===0){let S=u+f;return{values:S?[S]:[],quoted:!0}}let d="",p=e.state.shoptOptions.extglob;if(l.pattern)for(let S of l.pattern.parts)if(S.type==="Glob")d+=ie(S.pattern,l.greedy,p);else if(S.type==="Literal")d+=ie(S.value,l.greedy,p);else if(S.type==="SingleQuoted"||S.type==="Escaped")d+=le(S.value);else if(S.type==="DoubleQuoted"){let m=await r(e,S.parts);d+=le(m)}else if(S.type==="ParameterExpansion"){let m=await n(e,S);d+=ie(m,l.greedy,p)}else{let m=await n(e,S);d+=le(m)}let h=[],y={value:0};for(let S of c)to(h,Et(e,S,d,l.side,l.greedy),y,e);if(o){let S=Q(e.state.env);if(y.value+Math.max(0,h.length-1)*M(S)+M(u)+M(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+h.join(S)+f],quoted:!0}}if(M(u)+y.value+M(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return h.length===1?{values:[u+h[0]+f],quoted:!0}:{values:[u+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function Vc(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 c="";for(let d=s+1;d<r.parts.length;d++)c+=await n(e,r.parts[d]);if(a===0){if(i)return{values:[l+c],quoted:!0};let d=l+c;return{values:d?[d]:[],quoted:!0}}let u=[];for(let d=1;d<=a;d++)u.push(e.state.env.get(String(d))||"");if(i){let d=Q(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 It(e,t,n,r){if(t.length>=e.limits.maxArrayElements)throw new P(`unquoted expansion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let s=M(n);if(s>e.limits.maxStringLength-r.value)throw new P(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");t.push(n),r.value+=s}function no(e,t,n,r){let s=M(n),i=Math.max(0,t.length-1);if(s>0&&i>Math.floor((e.limits.maxStringLength-r)/s))throw new P(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return t.join(n)}function Xp(e){return new en(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 hs(e,t){if(e.state.options.noglob)return t;let n=Xp(e),r=[];for(let s of t)if(Dt(s,e.state.shoptOptions.extglob)){let i=await n.expand(s);if(i.length>0)De(r,i,e.limits.maxArrayElements,"unquoted glob expansion");else{if(n.hasFailglob())throw new Ut(s);n.hasNullglob()||r.push(s)}}else r.push(s);return r}async function zc(e,t,n,r){let s=-1,i="",o=!1;for(let b=0;b<t.length;b++){let v=t[b];if(v.type==="ParameterExpansion"&&v.operation?.type==="PatternReplacement"){let x=v.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(x){s=b,i=x[1],o=x[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,c=G(e,i),u=c.map(([,b])=>b);if(c.length===0){let b=e.state.env.get(i);b!==void 0&&(u=[b])}if(u.length===0)return{values:[],quoted:!1};let f="";if(l.pattern)for(let b of l.pattern.parts)if(b.type==="Glob")f+=ie(b.pattern,!0,e.state.shoptOptions.extglob);else if(b.type==="Literal")f+=ie(b.value,!0,e.state.shoptOptions.extglob);else if(b.type==="SingleQuoted"||b.type==="Escaped")f+=le(b.value);else if(b.type==="DoubleQuoted"){let v=await n(e,b.parts);f+=le(v)}else if(b.type==="ParameterExpansion"){let v=await r(e,b);f+=ie(v,!0,e.state.shoptOptions.extglob)}else{let v=await r(e,b);f+=le(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=[],y={value:0};try{let b=me(p,l.all?"g":"");for(let v of u)It(e,h,cs(e,v,b,d,l.all),y)}catch(b){if(b instanceof P)throw b;for(let v of u)It(e,h,v,y)}let E=ve(e.state.env),S=Re(e.state.env);if(o){let b=Q(e.state.env),v=no(e,h,b,y.value);return S?{values:v?[v]:[],quoted:!1}:{values:fe(v,E,e.limits.maxArrayElements),quoted:!1}}if(S)return{values:h,quoted:!1};let m=[],g={value:0};for(let b of h)if(b==="")It(e,m,"",g);else for(let v of fe(b,E,e.limits.maxArrayElements))It(e,m,v,g);return{values:m,quoted:!1}}async function Uc(e,t,n,r){let s=-1,i="",o=!1;for(let m=0;m<t.length;m++){let g=t[m];if(g.type==="ParameterExpansion"&&g.operation?.type==="PatternRemoval"){let b=g.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){s=m,i=b[1],o=b[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,c=G(e,i),u=c.map(([,m])=>m);if(c.length===0){let m=e.state.env.get(i);m!==void 0&&(u=[m])}if(u.length===0)return{values:[],quoted:!1};let f=l.pattern?await tn(e,l.pattern,l.greedy,n,r):"",d=[],p={value:0};for(let m of u)It(e,d,Et(e,m,f,l.side,l.greedy),p);let h=ve(e.state.env),y=Re(e.state.env);if(o){let m=Q(e.state.env),g=no(e,d,m,p.value);return y?{values:g?[g]:[],quoted:!1}:{values:fe(g,h,e.limits.maxArrayElements),quoted:!1}}if(y)return{values:d,quoted:!1};let E=[],S={value:0};for(let m of d)if(m==="")It(e,E,"",S);else for(let g of fe(m,h,e.limits.maxArrayElements))It(e,E,g,S);return{values:E,quoted:!1}}async function qc(e,t,n,r){let s=-1,i=!1;for(let m=0;m<t.length;m++){let g=t[m];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="PatternRemoval"){s=m,i=g.parameter==="*";break}}if(s===-1)return null;let a=t[s].operation,l=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let m=1;m<=l;m++)c.push(e.state.env.get(String(m))||"");if(c.length===0)return{values:[],quoted:!1};let u="",f=e.state.shoptOptions.extglob;if(a.pattern)for(let m of a.pattern.parts)if(m.type==="Glob")u+=ie(m.pattern,a.greedy,f);else if(m.type==="Literal")u+=ie(m.value,a.greedy,f);else if(m.type==="SingleQuoted"||m.type==="Escaped")u+=le(m.value);else if(m.type==="DoubleQuoted"){let g=await n(e,m.parts);u+=le(g)}else if(m.type==="ParameterExpansion"){let g=await r(e,m);u+=ie(g,a.greedy,f)}else{let g=await r(e,m);u+=le(g)}let d=[],p={value:0};for(let m of c)It(e,d,Et(e,m,u,a.side,a.greedy),p);let h=ve(e.state.env),y=Re(e.state.env);if(i){let m=Q(e.state.env),g=no(e,d,m,p.value);return y?{values:g?[g]:[],quoted:!1}:{values:fe(g,h,e.limits.maxArrayElements),quoted:!1}}if(y)return{values:d,quoted:!1};let E=[],S={value:0};for(let m of d)if(m==="")It(e,E,"",S);else for(let g of fe(m,h,e.limits.maxArrayElements))It(e,E,g,S);return{values:E,quoted:!1}}async function jc(e,t,n,r){let s=-1,i=!1;for(let g=0;g<t.length;g++){let b=t[g];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="Substring"){s=g,i=b.parameter==="*";break}}if(s===-1)return null;let a=t[s].operation,l=a.offset?await n(e,a.offset.expression):0,c=a.length?await n(e,a.length.expression):void 0,u=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let g=1;g<=u;g++)f.push(e.state.env.get(String(g))||"");let d=e.state.env.get("0")||"bash",p;if(l<=0){let g=[d,...f],b=g.length+l;if(b<0)p=[];else{let v=l<0?b:0;if(c!==void 0){let x=c<0?g.length+c:v+c;p=g.slice(v,Math.max(v,x))}else p=g.slice(v)}}else{let g=l-1;if(g>=f.length)p=[];else if(c!==void 0){let b=c<0?f.length+c:g+c;p=f.slice(g,Math.max(g,b))}else p=f.slice(g)}let h="";for(let g=0;g<s;g++)h+=await r(e,t[g]);let y="";for(let g=s+1;g<t.length;g++)y+=await r(e,t[g]);let E=ve(e.state.env),S=Re(e.state.env);if(p.length===0){let g=h+y;return g?S?{values:[g],quoted:!1}:{values:fe(g,E,e.limits.maxArrayElements),quoted:!1}:{values:[],quoted:!1}}let m;if(i){let g=Q(e.state.env),b=h+p.join(g)+y;S?m=b?[b]:[]:m=fe(b,E,e.limits.maxArrayElements)}else if(S)p.length===1?m=[h+p[0]+y]:m=[h+p[0],...p.slice(1,-1),p[p.length-1]+y];else{m=[];for(let g=0;g<p.length;g++){let b=p[g];if(g===0&&(b=h+b),g===p.length-1&&(b=b+y),b==="")m.push("");else{let v=fe(b,E,e.limits.maxArrayElements);De(m,v,e.limits.maxArrayElements,"unquoted expansion")}}}return{values:await hs(e,m),quoted:!1}}async function Hc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let n=t[0].parameter==="*",r=Number.parseInt(e.state.env.get("#")||"0",10);if(r===0)return{values:[],quoted:!1};let s=[];for(let c=1;c<=r;c++)s.push(e.state.env.get(String(c))||"");let i=ve(e.state.env),o=Re(e.state.env),a=ss(e.state.env),l;if(n)if(o)l=s.filter(c=>c!=="");else{let c=Q(e.state.env),u=s.join(c);l=fe(u,i,e.limits.maxArrayElements)}else if(o)l=s.filter(c=>c!=="");else if(a){l=[];for(let c of s){if(c==="")continue;let u=fe(c,i,e.limits.maxArrayElements);De(l,u,e.limits.maxArrayElements,"unquoted expansion")}}else{l=[];for(let c of s)if(c==="")l.push("");else{let u=fe(c,i,e.limits.maxArrayElements);De(l,u,e.limits.maxArrayElements,"unquoted expansion")}for(;l.length>0&&l[l.length-1]==="";)l.pop()}return{values:await hs(e,l),quoted:!1}}async function Gc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let n=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let r=n[1],s=n[2]==="*",i=G(e,r),o;if(i.length===0){let f=e.state.env.get(r);if(f!==void 0)o=[f];else return{values:[],quoted:!1}}else o=i.map(([,f])=>f);let a=ve(e.state.env),l=Re(e.state.env),c=ss(e.state.env),u;if(s)if(l)u=o.filter(f=>f!=="");else{let f=Q(e.state.env),d=o.join(f);u=fe(d,a,e.limits.maxArrayElements)}else if(l)u=o.filter(f=>f!=="");else if(c){u=[];for(let f of o){if(f==="")continue;let d=fe(f,a,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}}else{u=[];for(let f of o)if(f==="")u.push("");else{let d=fe(f,a,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}for(;u.length>0&&u[u.length-1]==="";)u.pop()}return{values:await hs(e,u),quoted:!1}}function Zc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let n=t[0].operation,r=zn(e,n.prefix);if(r.length===0)return{values:[],quoted:!1};let s=ve(e.state.env),i=Re(e.state.env),o;if(n.star)if(i)o=r;else{let a=Q(e.state.env),l=r.join(a);o=fe(l,s,e.limits.maxArrayElements)}else if(i)o=r;else{o=[];for(let a of r){let l=fe(a,s,e.limits.maxArrayElements);De(o,l,e.limits.maxArrayElements,"unquoted expansion")}}return{values:o,quoted:!1}}function Qc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let n=t[0].operation,s=G(e,n.array).map(([l])=>String(l));if(s.length===0)return{values:[],quoted:!1};let i=ve(e.state.env),o=Re(e.state.env),a;if(n.star)if(o)a=s;else{let l=Q(e.state.env),c=s.join(l);a=fe(c,i,e.limits.maxArrayElements)}else if(o)a=s;else{a=[];for(let l of s){let c=fe(l,i,e.limits.maxArrayElements);De(a,c,e.limits.maxArrayElements,"unquoted expansion")}}return{values:a,quoted:!1}}async function Kc(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=ve(e.state.env),c=Re(e.state.env),u=ss(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(c)f=d.filter(p=>p!=="");else if(u){f=[];for(let p of d){if(p==="")continue;let h=fe(p,l,e.limits.maxArrayElements);De(f,h,e.limits.maxArrayElements,"unquoted expansion")}}else{f=[];for(let p of d)if(p==="")f.push("");else{let h=fe(p,l,e.limits.maxArrayElements);De(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 hs(e,f),quoted:!1}}async function Jc(e,t,n){e.coverage?.hit("bash:expansion:word_glob");let r=t.parts,{hasQuoted:s,hasCommandSub:i,hasArrayVar:o,hasArrayAtExpansion:a,hasParamExpansion:l,hasVarNamePrefixExpansion:c,hasIndirection:u}=yr(r),d=n.hasBraceExpansion(r)?await n.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return Yp(e,d,s);let p=await Jp(e,r,a,c,u,n);if(p!==null)return p;let h=await th(e,r,n);if(h!==null)return h;let y=await nh(e,r,n);if(y!==null)return y;let E=await sh(e,r,n.expandPart);if(E!==null)return Yc(e,E);if((i||o||l)&&!Re(e.state.env)){let m=ve(e.state.env),g=n.buildIfsCharClassPattern(m),b=await n.smartWordSplit(e,r,m,g,n.expandPart);return Yc(e,b)}let S=await n.expandWordAsync(e,t);return ih(e,t,r,S,s,n.expandWordForGlobbing)}async function Yp(e,t,n){let r=[];for(let s of t)if(!(!n&&s===""))if(!n&&!e.state.options.noglob&&Dt(s,e.state.shoptOptions.extglob)){let i=await ms(e,s);De(r,i,e.limits.maxArrayElements,"brace/glob expansion")}else r.push(s);return{values:r,quoted:!1}}async function Jp(e,t,n,r,s,i){if(n){let o=Ic(e,t);if(o!==null)return o}{let o=Oc(e,t);if(o!==null)return o}{let o=await Pc(e,t);if(o!==null)return o}{let o=await Cc(e,t,n,i.expandPart,i.expandWordPartsAsync);if(o!==null)return o}{let o=await Nc(e,t,n,i.expandPart);if(o!==null)return o}{let o=await Rc(e,t,i.evaluateArithmetic);if(o!==null)return o}{let o=Dc(e,t);if(o!==null)return o}{let o=await kc(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}{let o=await $c(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let o=eh(e,t);if(o!==null)return o}{let o=await _c(e,t,s,i.expandParameterAsync,i.expandWordPartsAsync);if(o!==null)return o}{let o=await Lc(e,t);if(o!==null)return o}{let o=await Tc(e,t);if(o!==null)return o}return null}function eh(e,t){let n=t[0];if(n.type!=="DoubleQuoted")return null;if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="VarNamePrefix"){let r=n.parts[0].operation,s=zn(e,r.prefix);return r.star?{values:[s.join(Q(e.state.env))],quoted:!0}:{values:s,quoted:!0}}if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="ArrayKeys"){let r=n.parts[0].operation,i=G(e,r.array).map(([o])=>String(o));return r.star?{values:[i.join(Q(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function th(e,t,n){{let r=await Mc(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await Bc(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Wc(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Vc(e,t,n.expandPart);if(r!==null)return r}return null}async function nh(e,t,n){{let r=await zc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Uc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await qc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await jc(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await Hc(e,t);if(r!==null)return r}{let r=await Gc(e,t);if(r!==null)return r}{let r=Zc(e,t);if(r!==null)return r}{let r=Qc(e,t);if(r!==null)return r}{let r=await Kc(e,t,n.expandPart);if(r!==null)return r}return null}function Xc(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 rh(e,t,n,r){let s="";for(let a=0;a<n.atIndex;a++)s+=await r(e,t.parts[a]);let i="";for(let a=n.atIndex+1;a<t.parts.length;a++)i+=await r(e,t.parts[a]);let o;if(n.type==="array"){if(o=G(e,n.name).map(([,l])=>l),o.length===0){let l=e.state.env.get(n.name);l!==void 0&&(o=[l])}}else{let a=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let l=1;l<=a;l++)o.push(e.state.env.get(String(l))||"")}if(n.isStar){let a=Q(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 sh(e,t,n){if(t.length<2)return null;let r=!1;for(let l of t)if(Xc(l)){r=!0;break}if(!r)return null;let s=ve(e.state.env),i=Re(e.state.env),o=[];for(let l of t){let c=Xc(l);if(c&&l.type==="DoubleQuoted"){let u=await rh(e,l,c,n);o.push(u)}else if(l.type==="DoubleQuoted"||l.type==="SingleQuoted"){let u=await n(e,l);o.push([u])}else if(l.type==="Literal")o.push([l.value]);else if(l.type==="ParameterExpansion"){let u=await n(e,l);if(i)o.push(u?[u]:[]);else{let f=fe(u,s,e.limits.maxArrayElements);o.push(f)}}else{let u=await n(e,l);if(i)o.push(u?[u]:[]);else{let f=fe(u,s,e.limits.maxArrayElements);o.push(f)}}}let a=[];for(let l of o)if(l.length!==0)if(a.length===0)De(a,l,e.limits.maxArrayElements,"word expansion");else{let c=a.length-1;a[c]=a[c]+l[0];for(let u=1;u<l.length;u++)a.push(l[u])}return a}async function Yc(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let n=[];for(let r of t)if(Dt(r,e.state.shoptOptions.extglob)){let s=await ms(e,r);De(n,s,e.limits.maxArrayElements,"glob expansion")}else n.push(r);return{values:n,quoted:!1}}async function ms(e,t){let n=new en(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 Ut(t);return n.hasNullglob()?[]:[t]}async function ih(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(Dt(a,e.state.shoptOptions.extglob)){let c=await ms(e,a);if(c.length>0&&c[0]!==a)return{values:c,quoted:!1};if(c.length===0)return{values:[],quoted:!1}}let l=Ki(r);if(!Re(e.state.env)){let c=ve(e.state.env);return{values:fe(l,c,e.limits.maxArrayElements),quoted:!1}}return{values:[l],quoted:!1}}if(!s&&!e.state.options.noglob&&Dt(r,e.state.shoptOptions.extglob)){let a=await i(e,t);if(Dt(a,e.state.shoptOptions.extglob)){let l=await ms(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=Ki(r);if(!Re(e.state.env)){let l=ve(e.state.env);return{values:fe(a,l,e.limits.maxArrayElements),quoted:!1}}return{values:[a],quoted:!1}}return{values:[r],quoted:s}}function Le(e,t,n){if(t.length>=e.limits.maxArrayElements)throw new P(`word splitting element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");t.push(n)}async function tu(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 Rt(e,t.parameter),o=await se(e,t.parameter,!1)==="",a=n.checkEmpty??!1,l;return n.type==="UseAlternative"?l=s&&!(a&&o):l=!s||a&&o,l?(n.type==="AssignDefault"&&Xi(t.parameter),r.parts):null}function oh(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(n=>n.type==="Literal"):!1}async function ah(e,t){if(t.type!=="ParameterExpansion")return null;let n=await tu(e,t);if(!n||n.length<=1)return null;let r=n.some(i=>oh(i)),s=n.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&s?n:null}function lh(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?zi(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&Jl(e))}async function nu(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 tu(e,d);if(p&&p.length>0&&p.length>1&&p.some(y=>y.type==="DoubleQuoted"||y.type==="SingleQuoted")&&p.some(y=>y.type==="Literal"||y.type==="ParameterExpansion"||y.type==="CommandSubstitution"||y.type==="ArithmeticExpansion"))return eu(e,p,n,r,s)}let i=[],o=!1;for(let d of t){let p=lh(d),h=d.type==="DoubleQuoted"||d.type==="SingleQuoted",y=p?await ah(e,d):null,E=await s(e,d);i.push({value:E,isSplittable:p,isQuoted:h,mixedDefaultParts:y??void 0}),p&&(o=!0)}if(!o){let d=i.map(p=>p.value).join("");return d?[d]:[]}let a=[],l="",c=!1,u=!1,f=!1;for(let d of i)if(!d.isSplittable)u?d.isQuoted&&d.value===""?(l!==""&&Le(e,a,l),Le(e,a,""),c=!0,l="",u=!1,f=!0):d.value!==""?(l!==""&&Le(e,a,l),l=d.value,u=!1,f=!1):(l+=d.value,f=!1):(l+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let p=await eu(e,d.mixedDefaultParts,n,r,s);if(p.length!==0)if(p.length===1)l+=p[0],c=!0;else{l+=p[0],Le(e,a,l),c=!0;for(let h=1;h<p.length-1;h++)Le(e,a,p[h]);l=p[p.length-1]}u=!1,f=!1}else{let{words:p,hadLeadingDelimiter:h,hadTrailingDelimiter:y}=is(d.value,n,e.limits.maxArrayElements);if(f&&h&&l===""&&(Le(e,a,""),c=!0),p.length===0)y&&(u=!0);else if(p.length===1)l+=p[0],c=!0,u=y;else{l+=p[0],Le(e,a,l),c=!0;for(let E=1;E<p.length-1;E++)Le(e,a,p[E]);l=p[p.length-1],u=y}f=!1}return l!==""?Le(e,a,l):a.length===0&&c&&Le(e,a,""),a}function ch(e,t){return e.length>0&&t.includes(e[0])}async function eu(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 o=[],a="",l=!1,c=!1;for(let u of i)if(!u.isSplittable)c&&u.value!==""?(a!==""&&Le(e,o,a),a=u.value,c=!1):a+=u.value;else{ch(u.value,n)&&a!==""&&(Le(e,o,a),a="",l=!0);let{words:d,hadTrailingDelimiter:p}=is(u.value,n,e.limits.maxArrayElements);if(d.length===0)p&&(c=!0);else if(d.length===1)a+=d[0],l=!0,c=p;else{a+=d[0],Le(e,o,a),l=!0;for(let h=1;h<d.length-1;h++)Le(e,o,d[h]);a=d[d.length-1],c=p}}return a!==""?Le(e,o,a):o.length===0&&l&&Le(e,o,""),o}function ru(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function su(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}var ys="/dev/fd",ou=63,uh=10,iu=ou-uh+1,ro=class extends $t{isLiveDescriptor;constructor(t){super(),this.isLiveDescriptor=t}assertLiveDescriptor(t,n){this.isLiveDescriptor(t)||this.refuse(t,n)}refuse(t,n){throw new N("EROFS",`read-only file system, ${n} '${ys}${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 fh(e){let t=new ro(n=>au(e).some(r=>r.path===`${ys}${n}`));e.fs=new bn({base:e.fs,mounts:[{mountPoint:ys,filesystem:t}]}),e.state.processSubstitutionFsMounted=!0}async function dh(e,t,n){try{await e.fs.writeFile(t,n,"binary");return}catch(r){if(e.state.processSubstitutionFsMounted)throw r;fh(e)}await e.fs.writeFile(t,n,"binary")}async function ph(e,t){try{await e.fs.rm(t,{force:!0})}catch{}}function au(e){let t=e.state.processSubstitutions;if(t)return t;let n=[];return e.state.processSubstitutions=n,n}async function lu(e,t,n){let r=e.substitutionDepth??0,s=e.limits.maxSubstitutionDepth;if(r>=s)throw new P(`Process substitution nesting limit exceeded (${s})`,"substitution_depth");let i=e.substitutionDepth,o=new Map(e.state.env),a=at(e.state.arrays),l=e.state.cwd,c=e.state.bashPid,u=e.state.suppressVerbose,f=e.state.groupStdin,d=e.state.lastExitCode,p=e.state.env.get("?"),h=e.state.lastSubstitutionExitCode;e.substitutionDepth=r+1,e.state.bashPid=e.state.nextVirtualPid++,e.state.suppressVerbose=!0,n!==void 0&&(e.state.groupStdin=n);let y;try{y=await e.executeScript(t)}catch(E){if(E instanceof P)throw E;if(E instanceof q)return{stdout:E.stdout,stderr:E.stderr,exitCode:E.exitCode};throw E}finally{e.substitutionDepth=i,e.state.env=o,e.state.arrays=a,e.state.cwd=l,e.state.bashPid=c,e.state.suppressVerbose=u,e.state.groupStdin=f,e.state.lastExitCode=d,e.state.lastSubstitutionExitCode=h,p!==void 0?e.state.env.set("?",p):e.state.env.delete("?")}return y}async function cu(e,t){let n=au(e);if(n.length>=iu)throw new P(`Process substitution limit exceeded (${iu} concurrent)`,"file_descriptors");let r="";if(t.direction==="input"){let o=await lu(e,t.body,void 0);if(o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),r=Vt(o),r.length>e.limits.maxStringLength)throw new P(`process substitution: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")}let s=ou-n.length,i=`${ys}/${s}`;n.push({fd:s,path:i,direction:t.direction,body:t.body});try{await dh(e,i,r)}catch(o){throw n.pop(),o}return i}function uu(e){return e.state.processSubstitutions?.length??0}var hh={stdout:"",stderr:""};async function so(e,t){let n=e.state.processSubstitutions;if(!n||n.length<=t)return hh;let r="",s="";for(;n.length>t;){let i=n[n.length-1],o="";if(i.direction==="output")try{o=await Dn(e.fs,i.path)}catch{}if(await ph(e,i.path),n.pop(),i.direction==="output"){let a=await lu(e,i.body,o);r+=Vt(a),s+=a.stderr}}return{stdout:r,stderr:s}}function an(e,t,n){if(e.length>t)throw new P(`${n}: string length limit exceeded (${t} bytes)`,"string_length")}async function St(e,t,n=!1){let r=[],s=0;for(let i of t){let o=await tt(e,i,n);if(s+=M(o),s>e.limits.maxStringLength)throw new P(`parameter word string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");r.push(o)}return r.join("")}function mh(e){return su(e)}function du(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!mh(t))return!1;return!0}function yh(e,t,n=!1){let r=ru(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 Ji(e,t.pattern);default:return null}}async function re(e,t){return oo(e,t)}async function pu(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped")n.push(Vn(r.value));else if(r.type==="SingleQuoted")n.push(r.value);else if(r.type==="DoubleQuoted"){let s=await St(e,r.parts);n.push(s)}else if(r.type==="TildeExpansion"){let s=await tt(e,r);n.push(Vn(s))}else n.push(await tt(e,r));return n.join("")}async function hu(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped"){let s=r.value;"()|*?[]".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="SingleQuoted")n.push(et(r.value));else if(r.type==="DoubleQuoted"){let s=await St(e,r.parts);n.push(et(s))}else n.push(await tt(e,r));return n.join("")}async function mu(e,t){let n=[];for(let r of t.parts)if(r.type==="SingleQuoted")n.push(et(r.value));else if(r.type==="Escaped"){let s=r.value;"*?[]\\()|".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="DoubleQuoted"){let s=await St(e,r.parts);n.push(et(s))}else r.type==="Glob"?Ac(r.pattern)?n.push(await xc(e,r.pattern)):n.push(Ji(e,r.pattern)):r.type==="Literal"?n.push(r.value):n.push(await tt(e,r));return n.join("")}function ws(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&ws(t.parts))return!0;return!1}var fu=1e5;async function yu(e,t,n={count:0}){let r=()=>{n.count++,e.executionScope.consumeLimited("brace_operations",1,Math.min(fu,e.limits.maxBraceExpansionResults),"brace expansion")},s=(o,a)=>{if(o.length>=e.limits.maxBraceExpansionResults)throw new P(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),o.push(a)},i=[[]];for(let o of t)if(o.type==="BraceExpansion"){let a=[],l=!1,c="";for(let d of o.items)if(d.type==="Range"){let p=Qi(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,c=p.literal;break}}else{let p=await yu(e,d.word.parts,n);for(let h of p){let y=[];for(let E of h)typeof E=="string"?y.push(E):y.push(await tt(e,E));s(a,y.join(""))}}if(l){for(let d of i)r(),d.push(c);continue}if(i.length*a.length>e.limits.maxBraceExpansionResults||n.count>fu)throw new P(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");let f=[];for(let d of i)for(let p of a){if(f.length>=e.limits.maxBraceExpansionResults)throw new P(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),f.push([...d,p])}i=f}else for(let a of i)r(),a.push(o);return i}async function gu(e,t){let n=t.parts;if(!ws(n))return[await re(e,t)];let r=await yu(e,n),s=[];for(let i of r){let o=[];for(let a of i)typeof a=="string"?o.push(a):o.push(await tt(e,a));s.push(eo(e,o.join("")))}return s}function gh(){return{expandWordAsync:oo,expandWordForGlobbing:mu,expandWordWithBracesAsync:gu,expandWordPartsAsync:St,expandPart:tt,expandParameterAsync:gs,hasBraceExpansion:ws,evaluateArithmetic:Y,buildIfsCharClassPattern:ec,smartWordSplit:nu}}async function At(e,t){return Jc(e,t,gh())}function wh(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function io(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 wu(e,t){if(io(e,t))return{error:`bash: $@: ambiguous redirect
113
+ `};let n=t.parts,{hasQuoted:r}=yr(n);if(ws(n)&&(await gu(e,t)).length>1)return{error:`bash: ${n.map(p=>p.type==="Literal"?p.value:p.type==="BraceExpansion"?`{${p.items.map(y=>{if(y.type==="Range"){let E=y.step?`..${y.step}`:"";return`${y.startStr??y.start}..${y.endStr??y.end}${E}`}return y.word.parts.map(E=>E.type==="Literal"?E.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect
114
+ `};let s=await oo(e,t),{hasParamExpansion:i,hasCommandSub:o}=yr(n);if((i||o)&&!r&&!Re(e.state.env)){let f=ve(e.state.env);if(fe(s,f,e.limits.maxArrayElements).length>1)return{error:`bash: $${wh(n)}: ambiguous redirect
115
+ `}}if(r||e.state.options.noglob||n.some(f=>f.type==="ProcessSubstitution"))return{target:s};let l=await mu(e,t);if(!Dt(l,e.state.shoptOptions.extglob))return{target:s};let c=new en(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}
111
116
  `}:{target:s}:u.length===1?{target:u[0]}:{error:`bash: ${s}: ambiguous redirect
112
- `}}async function eo(e,t){let n=t.parts,r=n.length;if(r===1){let o=await tt(e,n[0]);return sn(o,e.limits.maxStringLength,"word expansion"),o}let s=[];for(let o=0;o<r;o++)s.push(await tt(e,n[o]));let i=s.join("");return sn(i,e.limits.maxStringLength,"word expansion"),i}async function tt(e,t,n=!1){if(t.type==="ParameterExpansion")return hs(e,t,n);let r=lh(e,t,n);if(r!==null)return r;switch(t.type){case"DoubleQuoted":{let s=[];for(let i of t.parts)s.push(await tt(e,i,!0));return s.join("")}case"CommandSubstitution":{let s=Jl(t.body);if(s)try{let p=await ie(e,s.target),h=p.startsWith("/")?p:`${e.state.cwd}/${p}`,y=await e.fs.readFile(h);nn(e.state,0);let E=y.replace(/\n+$/,"");return sn(E,e.limits.maxStringLength,"command substitution"),E}catch(p){if(p instanceof P)throw p;return nn(e.state,1),""}let i=e.substitutionDepth??0,o=e.limits.maxSubstitutionDepth;if(i>=o)throw new P(`Command substitution nesting limit exceeded (${o})`,"substitution_depth");let a=e.substitutionDepth;e.substitutionDepth=i+1;let l=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let c=new Map(e.state.env),u=ot(e.state.arrays),f=e.state.cwd,d=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let 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,nn(e.state,h),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr),e.state.bashPid=l,e.substitutionDepth=a;let y=p.stdout.replace(/\n+$/,"");return sn(y,e.limits.maxStringLength,"command substitution"),y}catch(p){if(e.state.env=c,e.state.arrays=u,e.state.cwd=f,e.state.bashPid=l,e.substitutionDepth=a,e.state.suppressVerbose=d,p instanceof P)throw p;if(p instanceof q){nn(e.state,p.exitCode),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr);let h=p.stdout.replace(/\n+$/,"");return sn(h,e.limits.maxStringLength,"command substitution"),h}throw p}}case"ProcessSubstitution":return nu(e,t);case"ArithmeticExpansion":{let s=t.expression.originalText;if(s&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(s)){let o=await Yl(e,s),a=new H,l=se(a,o);return String(await Y(e,l.expression,!0))}return String(await Y(e,t.expression.expression,!0))}case"BraceExpansion":{let s=[];for(let i of t.items)if(i.type==="Range"){let o=ji(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 ie(e,i.word));return s.join(" ")}default:return""}}async function hs(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 y=await Ui(e,p);r=`${d}[${y}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ce(e,r)){let d=Be(e,r);if(d&&d!==r){let p=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(p){let[,h,y]=p;if(e.state.associativeArrays?.has(h)||y.includes("$(")||y.includes("`")||y.includes("${")){let S=await Ui(e,y);r=`${h}[${S}]`}}}}let o=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),a=await oe(e,r,!o);if(!s)return a;let l=!await Ct(e,r),{isEmpty:c,effectiveValue:u}=hc(e,r,a,n),f={value:a,isUnset:l,isEmpty:c,effectiveValue:u,inDoubleQuotes:n};switch(s.type){case"DefaultValue":return tc(e,s,f,Et);case"AssignDefault":return nc(e,r,s,f,Et);case"ErrorIfUnset":return rc(e,r,s,f,Et);case"UseAlternative":return sc(e,s,f,Et);case"PatternRemoval":{let d=await ic(e,a,s,Et,tt);return sn(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await oc(e,a,s,Et,tt);return sn(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return ac(e,r,a);case"LengthSliceError":throw new Xe(r);case"BadSubstitution":throw new Xe(s.text);case"Substring":return lc(e,r,a,s);case"CaseModification":{let d=await cc(e,a,s,Et,hs);return sn(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return uc(e,r,a,l,s);case"Indirection":return fc(e,r,a,l,s,hs,n);case"ArrayKeys":return dc(e,s);case"VarNamePrefix":return pc(e,s);default:return a}}function pu(){return{visited:new Set,depth:0}}function fh(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new le("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new le("division by 0");return e%t;case"**":if(t<0)throw new le("exponent less than 0");return e**t;case"<<":return e<<t;case">>":return e>>t;case"<":return e<t?1:0;case"<=":return e<=t?1:0;case">":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function du(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 dh(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function ph(e,t){let n=e.state.env.get(t);if(n!==void 0)return n;let r=ae(e,t,0);return r!==void 0?r:await oe(e,t)}async function hh(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 H,{expr:o,pos:a}=Mn(i,s,0);if(a<s.length){let l=s.slice(a).trim(),c=l.split(/\s+/)[0]||l;throw new le(`syntax error in expression (error token is "${c}")`,"","")}return await zn(e,o,!1,n)}async function ys(e,t,n,r){if(r.depth>100)throw new le("maximum variable indirection depth exceeded");if(r.visited.has(t))throw new le(`arithmetic variable cycle detected at ${t}`);r.visited.add(t),r.depth++;try{return await hh(e,n,r)}finally{r.depth--,r.visited.delete(t)}}async function to(e,t,n){if(n.depth>100)throw new le("maximum variable indirection depth exceeded");if(n.visited.has(t))throw new le(`arithmetic variable cycle detected at ${t}`);n.visited.add(t),n.depth++;try{let r=await ph(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 to(e,i,n);let o=new H,{expr:a,pos:l}=Mn(o,i,0);if(l<i.length){let c=i.slice(l).trim(),u=c.split(/\s+/)[0]||c;throw new le(`${i}: syntax error in expression (error token is "${u}")`)}return await zn(e,a,!1,n)}finally{n.depth--,n.visited.delete(t)}}async function gs(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],y=G(e,h);return String(y.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 oe(e,t);let i=t.slice(0,r),o=t.slice(r+s.length),a=e.state.env.get(i),l=a===void 0,c=a==="",u=s.startsWith(":");switch(s){case":-":case"-":return l||u&&c?o:a||"";case":=":case"=":return l||u&&c?(e.state.env.set(i,o),o):a||"";case":+":case"+":return!(l||u&&c)?o:"";case":?":case"?":{if(l||u&&c)throw new Error(o||`${i}: parameter null or not set`);return a||""}default:return a||""}}async function Y(e,t,n=!1){return zn(e,t,n,pu())}async function zn(e,t,n,r){let s=(i,o=n)=>zn(e,i,o,r);switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new le("value too great for base");return t.value;case"ArithVariable":return await to(e,t.name,r);case"ArithSpecialVar":{let o=(await oe(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 H,{expr:c}=Mn(l,o,0);return await s(c)}case"ArithNested":return await s(t.expression);case"ArithCommandSubst":{if(e.execFn){let i=await e.execFn(t.command,{signal:e.state.signal});i.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+i.stderr);let o=i.stdout.trim();return Number.parseInt(o,10)||0}return 0}case"ArithBracedExpansion":{let i=await gs(e,t.content);return Number.parseInt(i,10)||0}case"ArithDynamicBase":{let i=await gs(e,t.baseExpr),o=Number.parseInt(i,10);if(o<2||o>64)return 0;let a=`${o}#${t.value}`;return lr(a)}case"ArithDynamicNumber":{let o=await gs(e,t.prefix)+t.suffix;return lr(o)}case"ArithArrayElement":{let i=e.state.associativeArrays?.has(t.array),o=async a=>{let l=ae(e,t.array,a);return l!==void 0?await ys(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 oe(e,t.index.name);return await o(a)}if(t.index){let a=await s(t.index);if(a<0){let u=G(e,t.array),f=e.state.currentLine;if(u.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
117
+ `}}async function oo(e,t){let n=t.parts,r=n.length;if(r===1){let o=await tt(e,n[0]);return an(o,e.limits.maxStringLength,"word expansion"),o}let s=[];for(let o=0;o<r;o++)s.push(await tt(e,n[o]));let i=s.join("");return an(i,e.limits.maxStringLength,"word expansion"),i}async function tt(e,t,n=!1){if(t.type==="ParameterExpansion")return gs(e,t,n);let r=yh(e,t,n);if(r!==null)return r;switch(t.type){case"DoubleQuoted":{let s=[];for(let i of t.parts)s.push(await tt(e,i,!0));return s.join("")}case"CommandSubstitution":{let s=ac(t.body);if(s)try{let p=await re(e,s.target),h=p.startsWith("/")?p:`${e.state.cwd}/${p}`,y=await e.fs.readFile(h);sn(e.state,0);let E=y.replace(/\n+$/,"");return an(E,e.limits.maxStringLength,"command substitution"),E}catch(p){if(p instanceof P)throw p;return sn(e.state,1),""}let i=e.substitutionDepth??0,o=e.limits.maxSubstitutionDepth;if(i>=o)throw new P(`Command substitution nesting limit exceeded (${o})`,"substitution_depth");let a=e.substitutionDepth;e.substitutionDepth=i+1;let l=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let c=new Map(e.state.env),u=at(e.state.arrays),f=e.state.cwd,d=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let 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,sn(e.state,h),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr),e.state.bashPid=l,e.substitutionDepth=a;let y=p.stdout.replace(/\n+$/,"");return an(y,e.limits.maxStringLength,"command substitution"),y}catch(p){if(e.state.env=c,e.state.arrays=u,e.state.cwd=f,e.state.bashPid=l,e.substitutionDepth=a,e.state.suppressVerbose=d,p instanceof P)throw p;if(p instanceof q){sn(e.state,p.exitCode),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr);let h=p.stdout.replace(/\n+$/,"");return an(h,e.limits.maxStringLength,"command substitution"),h}throw p}}case"ProcessSubstitution":return cu(e,t);case"ArithmeticExpansion":{let s=t.expression.originalText;if(s&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(s)){let o=await oc(e,s),a=new H,l=ne(a,o);return String(await Y(e,l.expression,!0))}return String(await Y(e,t.expression.expression,!0))}case"BraceExpansion":{let s=[];for(let i of t.items)if(i.type==="Range"){let o=Qi(i.start,i.end,i.step,i.startStr,i.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(o.expanded)s.push(...o.expanded);else return o.literal}else s.push(await re(e,i.word));return s.join(" ")}default:return""}}async function gs(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 y=await Gi(e,p);r=`${d}[${y}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ce(e,r)){let d=Be(e,r);if(d&&d!==r){let p=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(p){let[,h,y]=p;if(e.state.associativeArrays?.has(h)||y.includes("$(")||y.includes("`")||y.includes("${")){let S=await Gi(e,y);r=`${h}[${S}]`}}}}if(s?.type==="Length"&&/^[a-zA-Z_][a-zA-Z0-9_]*\[[@*]\]$/.test(r))return Yi(e,r,"");let o=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),a=await se(e,r,!o);if(!s)return a;let l=!await Rt(e,r),{isEmpty:c,effectiveValue:u}=Sc(e,r,a,n),f={value:a,isUnset:l,isEmpty:c,effectiveValue:u,inDoubleQuotes:n};switch(s.type){case"DefaultValue":return cc(e,s,f,St);case"AssignDefault":return uc(e,r,s,f,St);case"ErrorIfUnset":return fc(e,r,s,f,St);case"UseAlternative":return dc(e,s,f,St);case"PatternRemoval":{let d=await pc(e,a,s,St,tt);return an(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await hc(e,a,s,St,tt);return an(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return Yi(e,r,a);case"LengthSliceError":throw new Xe(r);case"BadSubstitution":throw new Xe(s.text);case"Substring":return mc(e,r,a,s);case"CaseModification":{let d=await yc(e,a,s,St,gs);return an(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return gc(e,r,a,l,s);case"Indirection":return wc(e,r,a,l,s,gs,n);case"ArrayKeys":return Ec(e,s);case"VarNamePrefix":return bc(e,s);default:return a}}function bu(){return{visited:new Set,depth:0}}function Eh(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 Eu(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 bh(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function Sh(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 se(e,t)}async function Ah(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 H,{expr:o,pos:a}=Wn(i,s,0);if(a<s.length){let l=s.slice(a).trim(),c=l.split(/\s+/)[0]||l;throw new ae(`syntax error in expression (error token is "${c}")`,"","")}return await qn(e,o,!1,n)}async function Es(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 Ah(e,n,r)}finally{r.depth--,r.visited.delete(t)}}async function ao(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 Sh(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 ao(e,i,n);let o=new H,{expr:a,pos:l}=Wn(o,i,0);if(l<i.length){let c=i.slice(l).trim(),u=c.split(/\s+/)[0]||c;throw new ae(`${i}: syntax error in expression (error token is "${u}")`)}return await qn(e,a,!1,n)}finally{n.depth--,n.visited.delete(t)}}async function bs(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],y=G(e,h);return String(y.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 se(e,t);let i=t.slice(0,r),o=t.slice(r+s.length),a=e.state.env.get(i),l=a===void 0,c=a==="",u=s.startsWith(":");switch(s){case":-":case"-":return l||u&&c?o:a||"";case":=":case"=":return l||u&&c?(e.state.env.set(i,o),o):a||"";case":+":case"+":return!(l||u&&c)?o:"";case":?":case"?":{if(l||u&&c)throw new Error(o||`${i}: parameter null or not set`);return a||""}default:return a||""}}async function Y(e,t,n=!1){return qn(e,t,n,bu())}async function qn(e,t,n,r){let s=(i,o=n)=>qn(e,i,o,r);switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new ae("value too great for base");return t.value;case"ArithVariable":return await ao(e,t.name,r);case"ArithSpecialVar":{let o=(await se(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 H,{expr:c}=Wn(l,o,0);return await s(c)}case"ArithNested":return await s(t.expression);case"ArithCommandSubst":{if(e.execFn){let i=await e.execFn(t.command,{signal:e.state.signal});i.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+i.stderr);let o=i.stdout.trim();return Number.parseInt(o,10)||0}return 0}case"ArithBracedExpansion":{let i=await bs(e,t.content);return Number.parseInt(i,10)||0}case"ArithDynamicBase":{let i=await bs(e,t.baseExpr),o=Number.parseInt(i,10);if(o<2||o>64)return 0;let a=`${o}#${t.value}`;return dr(a)}case"ArithDynamicNumber":{let o=await bs(e,t.prefix)+t.suffix;return dr(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 Es(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 se(e,t.index.name);return await o(a)}if(t.index){let a=await s(t.index);if(a<0){let u=G(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
113
118
  `,0;let p=Math.max(...u.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}]`,c=ae(e,t.array,a);if(c!==void 0)return ys(e,l,c,r);if(a===0){let u=e.state.env.get(t.array);if(u!==void 0)return ys(e,t.array,u,r)}if(e.state.options.nounset&&!(e.state.env.has(t.array)||Ce(e,t.array)))throw new Ue(`${t.array}[${a}]`);return 0}return 0}case"ArithDoubleSubscript":throw new le("double subscript","","");case"ArithNumberSubscript":throw new le(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new le(t.message,"","",!0);case"ArithSingleQuote":{if(n)throw new le(`syntax error: operand expected (error token is "'${t.content}'")`);return t.value}case"ArithBinary":{if(t.operator==="||")return await s(t.left)||await s(t.right)?1:0;if(t.operator==="&&")return await s(t.left)&&await s(t.right)?1:0;let i=await s(t.left),o=await s(t.right);return fh(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 oe(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 oe(e,t.operand.index.name);else if(t.operand.index){let f=await s(t.operand.index);l=String(f)}else return i;let c=Number.parseInt(ae(e,o,l)||"0",10)||0,u=t.operator==="++"?c+1:c-1;return j(e,o,l,String(u),a?"associative":"indexed"),t.prefix?u:c}if(t.operand.type==="ArithConcat"){let o="";for(let a of t.operand.parts)o+=await Vn(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 Vn(e,a,n,r);else t.operand.nameExpr.type==="ArithVariable"&&(o=t.operand.nameExpr.hasDollarPrefix?await oe(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(o&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){let a=await s(t.operand.subscript),l=Number.parseInt(ae(e,o,a)||"0",10)||0,c=t.operator==="++"?l+1:l-1;return j(e,o,a,String(c)),t.prefix?c:l}}return i}return dh(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 oe(e,t.subscript.name)||"\\";else if(d){let p=await s(t.subscript);a=String(p)}else{let p=await s(t.subscript);if(p<0){let h=G(e,i);h.length>0&&(p=Math.max(...h.map(([E])=>typeof E=="number"?E:0))+1+p)}a=String(p)}}let l=a===void 0?e.state.env.get(o):ae(e,i,a),c=Number.parseInt(l||"0",10)||0,u=await s(t.value),f=du(c,u,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 Vn(e,o,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)?await to(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 Vn(e,u,n,r);else t.target.type==="ArithVariable"&&(i=t.target.hasDollarPrefix?await oe(e,t.target.name):t.target.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let o=i;if(t.subscript){let u=await s(t.subscript);o=`${i}_${u}`}let a=Number.parseInt(e.state.env.get(o)||"0",10)||0,l=await s(t.value),c=du(a,l,t.operator);return e.state.env.set(o,String(c)),c}case"ArithDynamicElement":{let i="";if(t.nameExpr.type==="ArithConcat")for(let c of t.nameExpr.parts)i+=await Vn(e,c,n,r);else t.nameExpr.type==="ArithVariable"&&(i=t.nameExpr.hasDollarPrefix?await oe(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?ys(e,a,l,r):0}default:return 0}}async function Vn(e,t,n=!1,r=pu()){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await zn(e,t,n,r));case"ArithVariable":return t.hasDollarPrefix?await oe(e,t.name):t.name;case"ArithSpecialVar":return await oe(e,t.name);case"ArithBracedExpansion":return await gs(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 Vn(e,i,n,r);return s}default:return String(await zn(e,t,n,r))}}async function hu(e,t){let n="",r=0;for(let A of t.parts){let x=A.type==="Literal"?A.value:"\0",v=B(x);if(v>e.limits.maxStringLength-r)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n+=x,r+=v}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,c="",u=0,f=0,d=!1,p=!0,h=A=>{let x=B(A);if(x>e.limits.maxStringLength-f-u)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");c+=A,u+=x},y=(A,x=!1)=>{if(o.length>=e.limits.maxArrayElements)throw new P(`array assignment element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let v=B(A);if(v>e.limits.maxStringLength-f)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");o.push(A),a.push(x),f+=v},E=()=>{y(c,p),c="",u=0,d=!1,p=!0};for(let A of t.parts)if(A.type==="Literal"){let x=A.value;if(!l){let v=x.indexOf("=(");v!==-1&&(l=!0,x=x.slice(v+2))}if(l){x.endsWith(")")&&(x=x.slice(0,-1));for(let v of x)/\s/.test(v)?(c||d)&&E():h(v)}}else if(l)if(A.type==="BraceExpansion")if(/^\[.+\]=/.test(c))h(Tn({type:"Word",parts:[A]}));else{(c||d)&&E();let v=await bt(e,{type:"Word",parts:[A]});for(let $ of v.values)y($)}else{(A.type==="SingleQuoted"||A.type==="DoubleQuoted"||A.type==="Escaped")&&(d=!0),p=!1;let x=await ie(e,{type:"Word",parts:[A]});h(x)}(c||d)&&E();let S=o.splice(0),g=a.splice(0);f=0;for(let A=0;A<S.length;A++){let x=S[A];if(!g[A]){y(x);continue}let v=x.match(/^(\[[^\]]+\]=)(.*)$/s);if(v){let $=rn(e,v[2]);x=v[1]+$}if(x.includes("{")&&x.includes("}")){let $=new H().parseWordFromString(x,!1,!1);if($.parts.some(D=>D.type==="BraceExpansion")){let D=await bt(e,$);for(let k of D.values)y(k);continue}}y(x)}let m=[`${i}=(`],b=B(m[0]);for(let A=0;A<o.length;A++){let x=o[A],v;/^\[.+\]=/.test(x)?v=x:x===""?v="''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(x)&&!x.startsWith("'")&&!x.startsWith('"')?v=`'${x.replace(/'/g,"'\\''")}'`:v=x;let $=`${A>0?" ":""}${v}`,D=B($);if(D+1>e.limits.maxStringLength-b)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");m.push($),b+=D}return m.push(")"),m.join("")}async function mu(e,t){let n=-1,r=-1,s=!1;for(let y=0;y<t.parts.length;y++){let E=t.parts[y];if(E.type==="Literal"){let S=E.value.indexOf("+=");if(S!==-1){let m=E.value.slice(0,S);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(m)){n=y,r=S,s=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(m)){n=y,r=S,s=!0;break}}let g=E.value.indexOf("=");if(g!==-1&&(g===0||E.value[g-1]!=="+")){let m=E.value.slice(0,g);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(m)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(m)){n=y,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),c=o.value.slice(r+a),u=t.parts.slice(n+1),f="";for(let y of i)f+=await ie(e,{type:"Word",parts:[y]});f+=l;let d={type:"Word",parts:c!==""?[{type:"Literal",value:c},...u]:u},p=d.parts.length>0?await ie(e,d):"";return`${f}${s?"+=":"="}${p}`}var mh=["tar","yq","xan","sqlite3","python3","python"];function yu(e){return mh.includes(e)}var ne=Object.freeze({stdout:"",stderr:"",exitCode:0,internalStdinConsumed:0});function ee(e=""){return{stdout:e,stderr:"",exitCode:0}}function L(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function T(e,t,n){return{stdout:e,stderr:t,exitCode:n}}function we(e){return{stdout:"",stderr:"",exitCode:e?0:1,internalStdinConsumed:0}}function on(e,t,n="",r=""){throw new P(e,t,n,r)}function gu(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new P(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function no(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Ut;return ne}if(t.length>1)throw new q(1,"",`bash: break: too many arguments
119
+ `,0;a=p}let l=`${t.array}[${a}]`,c=oe(e,t.array,a);if(c!==void 0)return Es(e,l,c,r);if(a===0){let u=e.state.env.get(t.array);if(u!==void 0)return Es(e,t.array,u,r)}if(e.state.options.nounset&&!(e.state.env.has(t.array)||Ce(e,t.array)))throw new Ue(`${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 Eh(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 se(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 se(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(oe(e,o,l)||"0",10)||0,u=t.operator==="++"?c+1:c-1;return j(e,o,l,String(u),a?"associative":"indexed"),t.prefix?u:c}if(t.operand.type==="ArithConcat"){let o="";for(let a of t.operand.parts)o+=await Un(e,a,n,r);if(o&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){let a=Number.parseInt(e.state.env.get(o)||"0",10)||0,l=t.operator==="++"?a+1:a-1;return e.state.env.set(o,String(l)),t.prefix?l:a}}if(t.operand.type==="ArithDynamicElement"){let o="";if(t.operand.nameExpr.type==="ArithConcat")for(let a of t.operand.nameExpr.parts)o+=await Un(e,a,n,r);else t.operand.nameExpr.type==="ArithVariable"&&(o=t.operand.nameExpr.hasDollarPrefix?await se(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,c=t.operator==="++"?l+1:l-1;return j(e,o,a,String(c)),t.prefix?c:l}}return i}return bh(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 se(e,t.subscript.name)||"\\";else if(d){let p=await s(t.subscript);a=String(p)}else{let p=await s(t.subscript);if(p<0){let h=G(e,i);h.length>0&&(p=Math.max(...h.map(([E])=>typeof E=="number"?E:0))+1+p)}a=String(p)}}let l=a===void 0?e.state.env.get(o):oe(e,i,a),c=Number.parseInt(l||"0",10)||0,u=await s(t.value),f=Eu(c,u,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 Un(e,o,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)?await ao(e,i,r):Number.parseInt(i,10)||0}case"ArithDynamicAssignment":{let i="";if(t.target.type==="ArithConcat")for(let u of t.target.parts)i+=await Un(e,u,n,r);else t.target.type==="ArithVariable"&&(i=t.target.hasDollarPrefix?await se(e,t.target.name):t.target.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let o=i;if(t.subscript){let u=await s(t.subscript);o=`${i}_${u}`}let a=Number.parseInt(e.state.env.get(o)||"0",10)||0,l=await s(t.value),c=Eu(a,l,t.operator);return e.state.env.set(o,String(c)),c}case"ArithDynamicElement":{let i="";if(t.nameExpr.type==="ArithConcat")for(let c of t.nameExpr.parts)i+=await Un(e,c,n,r);else t.nameExpr.type==="ArithVariable"&&(i=t.nameExpr.hasDollarPrefix?await se(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?Es(e,a,l,r):0}default:return 0}}async function Un(e,t,n=!1,r=bu()){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await qn(e,t,n,r));case"ArithVariable":return t.hasDollarPrefix?await se(e,t.name):t.name;case"ArithSpecialVar":return await se(e,t.name);case"ArithBracedExpansion":return await bs(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command,{signal:e.state.signal})).stdout.trim():"0";case"ArithConcat":{let s="";for(let i of t.parts)s+=await Un(e,i,n,r);return s}default:return String(await qn(e,t,n,r))}}async function Su(e,t){let n="",r=0;for(let x of t.parts){let A=x.type==="Literal"?x.value:"\0",$=M(A);if($>e.limits.maxStringLength-r)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n+=A,r+=$}let s=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(\+?=)\(/);if(!s||!n.endsWith(")"))return null;let i=s[1],o=s[2],a=[],l=[],c=!1,u="",f=0,d=0,p=!1,h=!0,y=x=>{let A=M(x);if(A>e.limits.maxStringLength-d-f)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u+=x,f+=A},E=(x,A=!1)=>{if(a.length>=e.limits.maxArrayElements)throw new P(`array assignment element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let $=M(x);if($>e.limits.maxStringLength-d)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");a.push(x),l.push(A),d+=$},S=()=>{E(u,h),u="",f=0,p=!1,h=!0};for(let x of t.parts)if(x.type==="Literal"){let A=x.value;if(!c){let $=A.indexOf("=(");$!==-1&&(c=!0,A=A.slice($+2))}if(c){A.endsWith(")")&&(A=A.slice(0,-1));for(let $ of A)/\s/.test($)?(u||p)&&S():y($)}}else if(c)if(x.type==="BraceExpansion")if(/^\[.+\]=/.test(u))y(Mn({type:"Word",parts:[x]}));else{(u||p)&&S();let $=await At(e,{type:"Word",parts:[x]});for(let R of $.values)E(R)}else{(x.type==="SingleQuoted"||x.type==="DoubleQuoted"||x.type==="Escaped")&&(p=!0),h=!1;let A=await re(e,{type:"Word",parts:[x]});y(A)}(u||p)&&S();let m=a.splice(0),g=l.splice(0);d=0;for(let x=0;x<m.length;x++){let A=m[x];if(!g[x]){E(A);continue}let $=A.match(/^(\[[^\]]+\]=)(.*)$/s);if($){let R=on(e,$[2]);A=$[1]+R}if(A.includes("{")&&A.includes("}")){let R=new H().parseWordFromString(A,!1,!1);if(R.parts.some(k=>k.type==="BraceExpansion")){let k=await At(e,R);for(let C of k.values)E(C);continue}}E(A)}let b=[`${i}${o}(`],v=M(b[0]);for(let x=0;x<a.length;x++){let A=a[x],$,R=A.match(/^(\[[^\]]+\]=)(.*)$/s);if(R){let I=R[2].replace(/\\/g,"\\\\").replace(/"/g,'\\"');$=`${R[1]}"${I}"`}else A===""?$="''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(A)&&!A.startsWith("'")&&!A.startsWith('"')?$=`'${A.replace(/'/g,"'\\''")}'`:$=A;let k=`${x>0?" ":""}${$}`,C=M(k);if(C+1>e.limits.maxStringLength-v)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");b.push(k),v+=C}return b.push(")"),b.join("")}async function Au(e,t){let n=-1,r=-1,s=!1;for(let y=0;y<t.parts.length;y++){let E=t.parts[y];if(E.type==="Literal"){let S=E.value.indexOf("+=");if(S!==-1){let g=E.value.slice(0,S);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(g)){n=y,r=S,s=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(g)){n=y,r=S,s=!0;break}}let m=E.value.indexOf("=");if(m!==-1&&(m===0||E.value[m-1]!=="+")){let g=E.value.slice(0,m);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(g)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(g)){n=y,r=m;break}}}}if(n===-1)return null;let i=t.parts.slice(0,n),o=t.parts[n];if(o.type!=="Literal")return null;let a=s?2:1,l=o.value.slice(0,r),c=o.value.slice(r+a),u=t.parts.slice(n+1),f="";for(let y of i)f+=await re(e,{type:"Word",parts:[y]});f+=l;let d={type:"Word",parts:c!==""?[{type:"Literal",value:c},...u]:u},p=d.parts.length>0?await re(e,d):"";return`${f}${s?"+=":"="}${p}`}var vh=["tar","yq","xan","sqlite3","python3","python"];function vu(e){return vh.includes(e)}var ee=Object.freeze({stdout:"",stderr:"",exitCode:0,internalStdinConsumed:0});function J(e=""){return{stdout:e,stderr:"",exitCode:0}}function L(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function T(e,t,n){return{stdout:e,stderr:t,exitCode:n}}function we(e){return{stdout:"",stderr:"",exitCode:e?0:1,internalStdinConsumed:0}}function ln(e,t,n="",r=""){throw new P(e,t,n,r)}function xu(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new P(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function lo(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new qt;return ee}if(t.length>1)throw new q(1,"",`bash: break: too many arguments
115
120
  `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new q(128,"",`bash: break: ${t[0]}: numeric argument required
116
- `);n=r}throw new Qe(n)}async function ro(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!=="."),c="";for(let f of l)if(f==="..")c=c.split("/").slice(0,-1).join("/")||"/";else{c=c?`${c}/${f}`:`/${f}`;try{if(!(await e.fs.stat(c)).isDirectory)return L(`bash: cd: ${n}: Not a directory
121
+ `);n=r}throw new Qe(n)}async function co(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!=="."),c="";for(let f of l)if(f==="..")c=c.split("/").slice(0,-1).join("/")||"/";else{c=c?`${c}/${f}`:`/${f}`;try{if(!(await e.fs.stat(c)).isDirectory)return L(`bash: cd: ${n}: Not a directory
117
122
  `)}catch{return L(`bash: cd: ${n}: No such file or directory
118
- `)}}let u=c||"/";if(s)try{u=await e.fs.realpath(u)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=u,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),ee(r?`${u}
119
- `:"")}function so(e,t){return e.fs.resolvePath(e.state.cwd,t)}var yh=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function ws(e){return yh.includes(e)}async function Es(e,t,n){let r=so(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 gh=["-nt","-ot","-ef"];function bs(e){return gh.includes(e)}async function Ss(e,t,n,r){let s=so(e,n),i=so(e,r);switch(t){case"-nt":{let[o,a]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return o!==null&&(a===null||o.mtime>a.mtime)}case"-ot":{let[o,a]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return a!==null&&(o===null||o.mtime<a.mtime)}case"-ef":try{let[o,a]=await Promise.all([e.fs.realpath(s),e.fs.realpath(i)]);if(o===a)return!0;let[l,c]=await Promise.all([e.fs.stat(s),e.fs.stat(i)]);return l.dev!==void 0&&l.ino!==void 0&&c.dev!==void 0&&c.ino!==void 0?l.dev===c.dev&&l.ino===c.ino:l.identity&&c.identity?l.identity===c.identity:!1}catch{return!1}default:return!1}}var wh=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function As(e){return wh.has(e)}function vs(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 gr(e){return e==="="||e==="=="||e==="!="}function xs(e,t,n,r=!1,s=!1,i=!1,o=256){if(r){let l=Un(t,n,s,i,o);return e==="!="?!l:l}if(s){let l=t.toLowerCase()===n.toLowerCase();return e==="!="?!l:l}let a=t===n;return e==="!="?!a:a}var Eh=new Set(["-z","-n"]);function ks(e){return Eh.has(e)}function $s(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Ps(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let r=n[1],s=n[2];if(e.state.associativeArrays?.has(r)){let a=s;return(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1)),a=a.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(l,c)=>e.state.env.get(c)||""),Kt(e,r,a)}let o;try{let a=new H,l=se(a,s);o=await Y(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=Se(e,r),l=e.state.currentLine;if(a.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
123
+ `)}}let u=c||"/";if(s)try{u=await e.fs.realpath(u)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=u,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),J(r?`${u}
124
+ `:"")}function uo(e,t){return e.fs.resolvePath(e.state.cwd,t)}var xh=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function Ss(e){return xh.includes(e)}async function As(e,t,n){let r=uo(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 kh=["-nt","-ot","-ef"];function vs(e){return kh.includes(e)}async function xs(e,t,n,r){let s=uo(e,n),i=uo(e,r);switch(t){case"-nt":{let[o,a]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return o!==null&&(a===null||o.mtime>a.mtime)}case"-ot":{let[o,a]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return a!==null&&(o===null||o.mtime<a.mtime)}case"-ef":try{let[o,a]=await Promise.all([e.fs.realpath(s),e.fs.realpath(i)]);if(o===a)return!0;let[l,c]=await Promise.all([e.fs.stat(s),e.fs.stat(i)]);return l.dev!==void 0&&l.ino!==void 0&&c.dev!==void 0&&c.ino!==void 0?l.dev===c.dev&&l.ino===c.ino:l.identity&&c.identity?l.identity===c.identity:!1}catch{return!1}default:return!1}}var $h=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function ks(e){return $h.has(e)}function $s(e,t,n){switch(e){case"-eq":return t===n;case"-ne":return t!==n;case"-lt":return t<n;case"-le":return t<=n;case"-gt":return t>n;case"-ge":return t>=n}}function br(e){return e==="="||e==="=="||e==="!="}function Ps(e,t,n,r=!1,s=!1,i=!1,o=256){if(r){let l=jn(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 Ph=new Set(["-z","-n"]);function Cs(e){return Ph.has(e)}function Ns(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Rs(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let r=n[1],s=n[2];if(e.state.associativeArrays?.has(r)){let a=s;return(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1)),a=a.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(l,c)=>e.state.env.get(c)||""),Xt(e,r,a)}let o;try{let a=new H,l=ne(a,s);o=await Y(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=Se(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
125
  `,!1;if(o=Math.max(...a)+1+o,o<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
121
- `,!1}return Kt(e,r,o)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?$t(e,t).length>0:Se(e,t).length>0}async function an(e,t){switch(t.type){case"CondBinary":{let n=await ie(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 ie(e,t.right);s=Bn(i)}else s=await ou(e,t.right);else gr(t.operator)&&!r?s=await au(e,t.right):s=await ie(e,t.right);if(gr(t.operator)){let i=e.state.shoptOptions.nocasematch;return xs(t.operator,n,s,!r,i,!0,e.limits.maxCallDepth)}if(As(t.operator))return vs(t.operator,await Eu(e,n),await Eu(e,s));if(bs(t.operator))return Ss(e,t.operator,n,s);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=xh(s),l=me(o,i?"i":"").match(n);if(ge(e,"BASH_REMATCH"),l)for(let c=0;c<l.length;c++)j(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 ie(e,t.operand);return ws(t.operator)?Es(e,t.operator,n):ks(t.operator)?$s(t.operator,n):t.operator==="-v"?await Ps(e,n):t.operator==="-o"?oo(e,n):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await ie(e,t.operand.expression.word)})`!=="":!await an(e,t.operand);case"CondAnd":return await an(e,t.left)?await an(e,t.right):!1;case"CondOr":return await an(e,t.left)?!0:await an(e,t.right);case"CondGroup":return await an(e,t.expression);case"CondWord":return await ie(e,t.word)!=="";default:return!1}}async function qn(e,t){if(t.length===0)return T("","",1);if(t.length===1)return we(!!t[0]);if(t.length===2){let r=t[0],s=t[1];return r==="("?L(`test: '(' without matching ')'
122
- `,2):ws(r)?we(await Es(e,r,s)):ks(r)?we($s(r,s)):r==="!"?we(!s):r==="-v"?we(await Ps(e,s)):r==="-o"?we(oo(e,s)):r==="="||r==="=="||r==="!="||r==="<"||r===">"||r==="-eq"||r==="-ne"||r==="-lt"||r==="-le"||r==="-gt"||r==="-ge"||r==="-nt"||r==="-ot"||r==="-ef"?L(`test: ${r}: unary operator expected
123
- `,2):T("","",1)}if(t.length===3){let r=t[0],s=t[1],i=t[2];if(gr(s))return we(xs(s,r,i));if(As(s)){let o=Cs(r),a=Cs(i);return!o.valid||!a.valid?T("","",2):we(vs(s,o.value,a.value))}if(bs(s))return we(await Ss(e,s,r,i));switch(s){case"-a":return we(r!==""&&i!=="");case"-o":return we(r!==""||i!=="");case">":return we(r>i);case"<":return we(r<i)}if(r==="!"){let o=await qn(e,[s,i]);return T("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(r==="("&&i===")")return we(s!=="")}if(t.length===4){if(t[0]==="!"){let r=await qn(e,t.slice(1));return T("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(t[0]==="("&&t[3]===")")return qn(e,[t[1],t[2]])}let n=await Su(e,t,0);return n.pos<t.length?L(`test: too many arguments
124
- `,2):we(n.value)}async function Su(e,t,n){return bh(e,t,n)}async function bh(e,t,n){let{value:r,pos:s}=await wu(e,t,n);for(;t[s]==="-o";){let i=await wu(e,t,s+1);r=r||i.value,s=i.pos}return{value:r,pos:s}}async function wu(e,t,n){let{value:r,pos:s}=await io(e,t,n);for(;t[s]==="-a";){let i=await io(e,t,s+1);r=r&&i.value,s=i.pos}return{value:r,pos:s}}async function io(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 io(e,t,n+1);return{value:!s,pos:i}}return Sh(e,t,n)}finally{r.release()}}async function Sh(e,t,n){let r=t[n];if(r==="("){let{value:i,pos:o}=await Su(e,t,n+1);return{value:i,pos:t[o]===")"?o+1:o}}let s=t[n+1];if(gr(s)){let i=r,o=t[n+2]??"";return{value:xs(s,i,o),pos:n+3}}if(As(s)){let i=Cs(r),o=Cs(t[n+2]??"0");return!i.valid||!o.valid?{value:!1,pos:n+3}:{value:vs(s,i.value,o.value),pos:n+3}}if(bs(s)){let i=r,o=t[n+2]??"";return{value:await Ss(e,s,i,o),pos:n+3}}if(ws(r)){let i=t[n+1]??"";return{value:await Es(e,r,i),pos:n+2}}if(ks(r)){let i=t[n+1]??"";return{value:$s(r,i),pos:n+2}}if(r==="-v"){let i=t[n+1]??"";return{value:await Ps(e,i),pos:n+2}}if(r==="-o"){let i=t[n+1]??"";return{value:oo(e,i),pos:n+2}}return{value:r!==void 0&&r!=="",pos:n+1}}function Un(e,t,n=!1,r=!1,s=256){r&&Ah(t,s);let i=`^${Au(t,r)}$`;return me(i,n?"is":"s").test(e)}function Ah(e,t){let n=0,r=[];for(let s=0;s<e.length;s++){if(e[s]==="\\"){s++;continue}if(e[s]==="("){let i=s>0&&"@*+?!".includes(e[s-1]);if(r.push(i),i&&n++,n>t)throw new P(`extglob maximum depth (${t}) exceeded`,"recursion")}else e[s]===")"&&r.length>0&&r.pop()&&n--}}function Au(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=vu(e,r+1);if(i!==-1){let o=e.slice(r+2,i),a=xu(o),l=a.map(u=>Au(u,t)),c=l.length>0?l.join("|"):"(?:)";if(s==="@")n+=`(?:${c})`;else if(s==="*")n+=`(?:${c})*`;else if(s==="+")n+=`(?:${c})+`;else if(s==="?")n+=`(?:${c})?`;else if(s==="!")if(i<e.length-1){let f=a.map(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(`(?!(?:${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 vu(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function xu(e){let t=[],n="",r=0,s=0;for(;s<e.length;){let i=e[s];if(i==="\\"){n+=i,s+1<e.length?(n+=e[s+1],s+=2):s++;continue}i==="("?(r++,n+=i):i===")"?(r--,n+=i):i==="|"&&r===0?(t.push(n),n=""):n+=i,s++}return t.push(n),t}function 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=vu(e,r+1);if(i!==-1){if(s==="@"){let o=e.slice(r+2,i),l=xu(o).map(c=>ku(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 oo(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 Eu(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 bu(t);try{let n=new H,r=se(n,t);return await Y(e,r.expression)}catch{return bu(t)}}function vh(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 bu(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=vh(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 Cs(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 xh(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=kh(e,n);t+=r.converted,n=r.endIndex}else t+=e[n],n++;return t}function kh(e,t){let n=t+1,r="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(r+="^",n++);let s=!1;n<e.length&&e[n]==="]"&&(s=!0,n++);let i=!1;n<e.length&&e[n]==="["&&n+1<e.length&&e[n+1]!==":"&&(i=!0,n++);let o="",a=!1;for(;n<e.length;){let l=e[n];if(l==="]"){a=!0,n++;break}if(l==="["&&n+1<e.length&&e[n+1]===":"){let c=e.indexOf(":]",n+2);if(c!==-1){let u=e.slice(n+2,c);o+=$h(u),n=c+2;continue}}if(l==="["&&n+1<e.length){let c=e[n+1];if(c==="."||c==="="){let u=`${c}]`,f=e.indexOf(u,n+2);if(f!==-1){let d=e.slice(n+2,f);o+=d,n=f+2;continue}}}if(l==="\\"&&n+1<e.length){o+=l+e[n+1],n+=2;continue}o+=l,n++}return a?(s&&(r+="\\]"),i&&(r+="\\["),r+=o,r+="]",{converted:r,endIndex:n}):{converted:"\\[",endIndex:t+1}}function $h(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 ao(e,t,n){if(n&&e.length>=n.maxElements)throw new P(`array element limit exceeded (${n.maxElements})`,"array_elements");e.push(t)}function Bt(e,t){if(t&&B(e)>t.maxStringBytes)throw new P(`array assignment string limit exceeded (${t.maxStringBytes} bytes)`,"string_length");let n=[],r="",s=!1,i=!1,o=!1,a=!1;for(let l of e){if(o){r+=l,o=!1,a=!0;continue}if(l==="\\"){o=!0;continue}if(l==="'"&&!i){s||(a=!0),s=!s;continue}if(l==='"'&&!s){i||(a=!0),i=!i;continue}if((l===" "||l===" "||l===`
125
- `)&&!s&&!i){a&&(ao(n,r,t),r="",a=!1);continue}r+=l,a=!0}return a&&ao(n,r,t),n}function Ns(e,t){if(t&&B(e)>t.maxStringBytes)throw new P(`array assignment string limit exceeded (${t.maxStringBytes} bytes)`,"string_length");let n=[],r=0;for(;r<e.length;){for(;r<e.length&&/\s/.test(e[r]);)r++;if(r>=e.length)break;if(e[r]!=="["){r++;continue}r++;let s="";if(e[r]==="'"||e[r]==='"'){let o=e[r];for(r++;r<e.length&&e[r]!==o;)s+=e[r],r++;e[r]===o&&r++}else for(;r<e.length&&e[r]!=="]"&&e[r]!=="=";)s+=e[r],r++;for(;r<e.length&&e[r]!=="]";)r++;if(e[r]==="]"&&r++,e[r]!=="=")continue;r++;let i="";if(e[r]==="'"||e[r]==='"'){let o=e[r];for(r++;r<e.length&&e[r]!==o;)e[r]==="\\"&&r+1<e.length&&r++,i+=e[r],r++;e[r]===o&&r++}else for(;r<e.length&&!/\s/.test(e[r]);)i+=e[r],r++;ao(n,[s,i],t)}return n}function $u(e,t){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(n)return{name:n[1],isArray:!0,arrayElements:Bt(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 Ph(e,t){try{let n=new H,r=se(n,t);return await Y(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}async function Pu(e,t,n={}){let{name:r,isArray:s,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:l=!1,checkReadonly:c=!0}=n;if(c){let u=ue(e,r);if(u)return u}if(s&&i){e.executionScope.consumeWork(i.length,"array assignment");let u=xe(e,r),f=u?Me(u):void 0,d=e.state.env.get(r);try{ge(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 u=await Ph(e,a);j(e,r,u,o)}else o!==void 0&&e.state.env.set(r,o);return l&&Ze(e,r),null}function ln(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function lo(e,t){return e.state.localVarDepth?.get(t)}function Rs(e,t){e.state.localVarDepth?.delete(t)}function Cu(e,t,n){e.state.localVarStack=e.state.localVarStack||new Map;let r=e.state.localVarStack.get(t)||[];r.push({value:n,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,r)}function Ds(e,t){let n=e.state.localVarStack?.get(t);if(!(!n||n.length===0))return n.pop()}function Nu(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 co="__file__:",uo="__file_append__:",ho="__rw__:",fo="__dupout__:",po="__dupin__:",Ee=3;function Ch(e){let t=e.slice(ho.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 Ru(e,t){let n=Number.parseInt(e.slice(t.length),10);return Number.isNaN(n)?null:n}function Nh(e){if(e.startsWith(co))return{kind:"output",path:e.slice(co.length),append:!1};if(e.startsWith(uo))return{kind:"output",path:e.slice(uo.length),append:!0};if(e.startsWith(ho)){let t=Ch(e);if(t)return{kind:"readwrite",...t}}if(e.startsWith(fo)){let t=Ru(e,fo);if(t!==null)return{kind:"dup-out",sourceFd:t}}if(e.startsWith(po)){let t=Ru(e,po);if(t!==null)return{kind:"dup-in",sourceFd:t}}return{kind:"input",content:e}}function mo(e){switch(e.kind){case"input":return e.content;case"output":return`${e.append?uo:co}${e.path}`;case"readwrite":return`${ho}${e.path.length}:${e.path}:${e.position}:${e.content}`;case"dup-out":return`${fo}${e.sourceFd}`;case"dup-in":return`${po}${e.sourceFd}`;case"closed":throw new Error("Closed descriptors have no table encoding")}}function Rh(e){return e.state.fileDescriptors??=new Map,e.state.fileDescriptors}function Dh(e,t,n){n?(e.state.inputFds??=new Set,e.state.inputFds.add(t)):e.state.inputFds?.delete(t)}function jn(e,t){return e.state.fdAliases?.get(t)}function cn(e,t){return[...jn(e,t)??[t]]}function Du(e,t){let n=jn(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 yo(e,t,n){if(t===n)return;e.state.fdAliases??=new Map;let r=jn(e,n)??new Set([n]);r.add(t);for(let s of r)e.state.fdAliases.set(s,r)}function Is(e,t){return e.state.fileDescriptors?.get(t)}function nt(e,t){let n=Is(e,t);if(n!==void 0)return e.state.inputFds?.has(t)?{kind:"input",content:n}:Nh(n)}function $n(e,t){return e.state.fileDescriptors?.has(t)===!0}function go(e,t,n,r){let s=Rh(e);s.has(t)||gu(e),s.set(t,n),Dh(e,t,r)}function Os(e,t,n,r=!1){Du(e,t),go(e,t,n,r)}function ct(e,t,n){Os(e,t,mo(n),n.kind==="input")}function Dt(e,t){e.state.fileDescriptors?.delete(t),e.state.inputFds?.delete(t),Du(e,t)}function _s(e,t,n){let r=Is(e,n);return r===void 0?!1:(Os(e,t,r,e.state.inputFds?.has(n)===!0),yo(e,t,n),!0)}function wo(e,t,n){let r=Is(e,n);if(r===void 0)return!1;if(t===n)return!0;let s=e.state.inputFds?.has(n)===!0,i=[...jn(e,n)??[]].filter(a=>a!==n);Dt(e,n),Os(e,t,r,s);let o=i.find(a=>$n(e,a));return o!==void 0&&yo(e,t,o),!0}function Ls(e,t){let n=nt(e,t);if(n===void 0)return{error:"not-open"};switch(n.kind){case"input":return{content:n.content};case"readwrite":return{content:n.content.slice(n.position)};case"output":case"dup-out":return{error:"write-only"};case"dup-in":return{error:"not-open"};case"closed":return{error:"not-open"}}}function un(e,t,n){let r=nt(e,t);if(r===void 0)return;let s;if(r.kind==="input")s={kind:"input",content:r.content.slice(n)};else if(r.kind==="readwrite")s={...r,position:r.position+n};else return;let i=mo(s),o=s.kind==="input";for(let a of jn(e,t)??[t])go(e,a,i,o)}async function Eo(e,t,n,r,s){if(t.kind==="output")return await e.fs.appendFile(t.path,r,s),!0;let o=n.map(u=>nt(e,u)).find(u=>u?.kind==="readwrite")??t;if(o.kind!=="readwrite")return!1;let a=o.content.slice(0,o.position)+r+o.content.slice(o.position+r.length),l={...o,position:o.position+r.length,content:a};await e.fs.writeFile(o.path,a,s);let c=mo(l);for(let u of n)$n(e,u)&&go(e,u,c,!1);return!0}function fn(e,t,n){if(t.has(n))return;let r=jn(e,n);t.set(n,{raw:Is(e,n),isInput:e.state.inputFds?.has(n)===!0,aliases:r?[...r].filter(s=>s!==n):[]})}function Ts(e,t){let n=e.state.fileDescriptors;if(n)for(let[r,{raw:s,isInput:i,aliases:o}]of t){if(s===void 0){Dt(e,r);continue}Os(e,r,s,i);let a=o.find(l=>n.has(l));a!==void 0&&yo(e,r,a)}}function bo(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 Iu(e){if(e.fdVariable)return!1;let t=bo(e);return t!==null&&t>=Ee}async function Ih(e,t,n,r){try{if(!await e.fs.exists(t))return null;if((await e.fs.stat(t)).isDirectory)return`bash: ${n}: Is a directory
126
+ `,!1}return Xt(e,r,o)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?Ct(e,t).length>0:Se(e,t).length>0}async function cn(e,t){switch(t.type){case"CondBinary":{let n=await re(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 re(e,t.right);s=Vn(i)}else s=await pu(e,t.right);else br(t.operator)&&!r?s=await hu(e,t.right):s=await re(e,t.right);if(br(t.operator)){let i=e.state.shoptOptions.nocasematch;return Ps(t.operator,n,s,!r,i,!0,e.limits.maxCallDepth)}if(ks(t.operator))return $s(t.operator,await $u(e,n),await $u(e,s));if(vs(t.operator))return xs(e,t.operator,n,s);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=Ih(s),l=me(o,i?"i":"").match(n);if(ge(e,"BASH_REMATCH"),l)for(let c=0;c<l.length;c++)j(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 re(e,t.operand);return Ss(t.operator)?As(e,t.operator,n):Cs(t.operator)?Ns(t.operator,n):t.operator==="-v"?await Rs(e,n):t.operator==="-o"?po(e,n):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await re(e,t.operand.expression.word)})`!=="":!await cn(e,t.operand);case"CondAnd":return await cn(e,t.left)?await cn(e,t.right):!1;case"CondOr":return await cn(e,t.left)?!0:await cn(e,t.right);case"CondGroup":return await cn(e,t.expression);case"CondWord":return await re(e,t.word)!=="";default:return!1}}async function Hn(e,t){if(t.length===0)return T("","",1);if(t.length===1)return we(!!t[0]);if(t.length===2){let r=t[0],s=t[1];return r==="("?L(`test: '(' without matching ')'
127
+ `,2):Ss(r)?we(await As(e,r,s)):Cs(r)?we(Ns(r,s)):r==="!"?we(!s):r==="-v"?we(await Rs(e,s)):r==="-o"?we(po(e,s)):r==="="||r==="=="||r==="!="||r==="<"||r===">"||r==="-eq"||r==="-ne"||r==="-lt"||r==="-le"||r==="-gt"||r==="-ge"||r==="-nt"||r==="-ot"||r==="-ef"?L(`test: ${r}: unary operator expected
128
+ `,2):T("","",1)}if(t.length===3){let r=t[0],s=t[1],i=t[2];if(br(s))return we(Ps(s,r,i));if(ks(s)){let o=Ds(r),a=Ds(i);return!o.valid||!a.valid?T("","",2):we($s(s,o.value,a.value))}if(vs(s))return we(await xs(e,s,r,i));switch(s){case"-a":return we(r!==""&&i!=="");case"-o":return we(r!==""||i!=="");case">":return we(r>i);case"<":return we(r<i)}if(r==="!"){let o=await Hn(e,[s,i]);return T("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(r==="("&&i===")")return we(s!=="")}if(t.length===4){if(t[0]==="!"){let r=await Hn(e,t.slice(1));return T("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(t[0]==="("&&t[3]===")")return Hn(e,[t[1],t[2]])}let n=await Cu(e,t,0);return n.pos<t.length?L(`test: too many arguments
129
+ `,2):we(n.value)}async function Cu(e,t,n){return Ch(e,t,n)}async function Ch(e,t,n){let{value:r,pos:s}=await ku(e,t,n);for(;t[s]==="-o";){let i=await ku(e,t,s+1);r=r||i.value,s=i.pos}return{value:r,pos:s}}async function ku(e,t,n){let{value:r,pos:s}=await fo(e,t,n);for(;t[s]==="-a";){let i=await fo(e,t,s+1);r=r&&i.value,s=i.pos}return{value:r,pos:s}}async function fo(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 fo(e,t,n+1);return{value:!s,pos:i}}return Nh(e,t,n)}finally{r.release()}}async function Nh(e,t,n){let r=t[n];if(r==="("){let{value:i,pos:o}=await Cu(e,t,n+1);return{value:i,pos:t[o]===")"?o+1:o}}let s=t[n+1];if(br(s)){let i=r,o=t[n+2]??"";return{value:Ps(s,i,o),pos:n+3}}if(ks(s)){let i=Ds(r),o=Ds(t[n+2]??"0");return!i.valid||!o.valid?{value:!1,pos:n+3}:{value:$s(s,i.value,o.value),pos:n+3}}if(vs(s)){let i=r,o=t[n+2]??"";return{value:await xs(e,s,i,o),pos:n+3}}if(Ss(r)){let i=t[n+1]??"";return{value:await As(e,r,i),pos:n+2}}if(Cs(r)){let i=t[n+1]??"";return{value:Ns(r,i),pos:n+2}}if(r==="-v"){let i=t[n+1]??"";return{value:await Rs(e,i),pos:n+2}}if(r==="-o"){let i=t[n+1]??"";return{value:po(e,i),pos:n+2}}return{value:r!==void 0&&r!=="",pos:n+1}}function jn(e,t,n=!1,r=!1,s=256){r&&Rh(t,s);let i=`^${Nu(t,r)}$`;return me(i,n?"is":"s").test(e)}function Rh(e,t){let n=0,r=[];for(let s=0;s<e.length;s++){if(e[s]==="\\"){s++;continue}if(e[s]==="("){let i=s>0&&"@*+?!".includes(e[s-1]);if(r.push(i),i&&n++,n>t)throw new P(`extglob maximum depth (${t}) exceeded`,"recursion")}else e[s]===")"&&r.length>0&&r.pop()&&n--}}function Nu(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=Ru(e,r+1);if(i!==-1){let o=e.slice(r+2,i),a=Du(o),l=a.map(u=>Nu(u,t)),c=l.length>0?l.join("|"):"(?:)";if(s==="@")n+=`(?:${c})`;else if(s==="*")n+=`(?:${c})*`;else if(s==="+")n+=`(?:${c})+`;else if(s==="?")n+=`(?:${c})?`;else if(s==="!")if(i<e.length-1){let f=a.map(p=>Iu(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 Ru(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 Du(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 Iu(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=Ru(e,r+1);if(i!==-1){if(s==="@"){let o=e.slice(r+2,i),l=Du(o).map(c=>Iu(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 po(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 $u(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 Pu(t);try{let n=new H,r=ne(n,t);return await Y(e,r.expression)}catch{return Pu(t)}}function Dh(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 Pu(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=Dh(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 Ds(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let n=Number.parseInt(e,10);return Number.isNaN(n)?{value:0,valid:!1}:{value:t?-n:n,valid:!0}}function Ih(e){let t="",n=0;for(;n<e.length;)if(e[n]==="\\"&&n+1<e.length)t+=e[n]+e[n+1],n+=2;else if(e[n]==="["){let r=Oh(e,n);t+=r.converted,n=r.endIndex}else t+=e[n],n++;return t}function Oh(e,t){let n=t+1,r="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(r+="^",n++);let s=!1;n<e.length&&e[n]==="]"&&(s=!0,n++);let i=!1;n<e.length&&e[n]==="["&&n+1<e.length&&e[n+1]!==":"&&(i=!0,n++);let o="",a=!1;for(;n<e.length;){let l=e[n];if(l==="]"){a=!0,n++;break}if(l==="["&&n+1<e.length&&e[n+1]===":"){let c=e.indexOf(":]",n+2);if(c!==-1){let u=e.slice(n+2,c);o+=_h(u),n=c+2;continue}}if(l==="["&&n+1<e.length){let c=e[n+1];if(c==="."||c==="="){let u=`${c}]`,f=e.indexOf(u,n+2);if(f!==-1){let d=e.slice(n+2,f);o+=d,n=f+2;continue}}}if(l==="\\"&&n+1<e.length){o+=l+e[n+1],n+=2;continue}o+=l,n++}return a?(s&&(r+="\\]"),i&&(r+="\\["),r+=o,r+="]",{converted:r,endIndex:n}):{converted:"\\[",endIndex:t+1}}function _h(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 ho(e,t,n){if(n&&e.length>=n.maxElements)throw new P(`array element limit exceeded (${n.maxElements})`,"array_elements");e.push(t)}function Wt(e,t){if(t&&M(e)>t.maxStringBytes)throw new P(`array assignment string limit exceeded (${t.maxStringBytes} bytes)`,"string_length");let n=[],r="",s=!1,i=!1,o=!1,a=!1;for(let l of e){if(o){r+=l,o=!1,a=!0;continue}if(l==="\\"){o=!0;continue}if(l==="'"&&!i){s||(a=!0),s=!s;continue}if(l==='"'&&!s){i||(a=!0),i=!i;continue}if((l===" "||l===" "||l===`
130
+ `)&&!s&&!i){a&&(ho(n,r,t),r="",a=!1);continue}r+=l,a=!0}return a&&ho(n,r,t),n}function Is(e,t){if(t&&M(e)>t.maxStringBytes)throw new P(`array assignment string limit exceeded (${t.maxStringBytes} bytes)`,"string_length");let n=[],r=0;for(;r<e.length;){for(;r<e.length&&/\s/.test(e[r]);)r++;if(r>=e.length)break;if(e[r]!=="["){r++;continue}r++;let s="";if(e[r]==="'"||e[r]==='"'){let 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++;ho(n,[s,i],t)}return n}function Ou(e,t){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(n)return{name:n[1],isArray:!0,arrayElements:Wt(n[2],t)};let r=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(r)return{name:r[1],isArray:!1,arrayIndex:r[2],value:r[3]};if(e.includes("=")){let s=e.indexOf("=");return{name:e.slice(0,s),isArray:!1,value:e.slice(s+1)}}return{name:e,isArray:!1}}async function Lh(e,t){try{let n=new H,r=ne(n,t);return await Y(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}async function _u(e,t,n={}){let{name:r,isArray:s,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:l=!1,checkReadonly:c=!0}=n;if(c){let u=ue(e,r);if(u)return u}if(s&&i){e.executionScope.consumeWork(i.length,"array assignment");let u=xe(e,r),f=u?Me(u):void 0,d=e.state.env.get(r);try{ge(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 u=await Lh(e,a);j(e,r,u,o)}else o!==void 0&&e.state.env.set(r,o);return l&&Ze(e,r),null}function un(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function mo(e,t){return e.state.localVarDepth?.get(t)}function Os(e,t){e.state.localVarDepth?.delete(t)}function Lu(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 _s(e,t){let n=e.state.localVarStack?.get(t);if(!(!n||n.length===0))return n.pop()}function Tu(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 yo="__file__:",go="__file_append__:",bo="__rw__:",wo="__dupout__:",Eo="__dupin__:",Ee=3;function Th(e){let t=e.slice(bo.length),n=t.indexOf(":");if(n===-1)return null;let r=Number.parseInt(t.slice(0,n),10);if(Number.isNaN(r)||r<0)return null;let s=n+1,i=t.slice(s,s+r),o=t.slice(s+r+1),a=o.indexOf(":");if(a===-1)return null;let l=Number.parseInt(o.slice(0,a),10);return Number.isNaN(l)||l<0?null:{path:i,position:l,content:o.slice(a+1)}}function Fu(e,t){let n=Number.parseInt(e.slice(t.length),10);return Number.isNaN(n)?null:n}function Fh(e){if(e.startsWith(yo))return{kind:"output",path:e.slice(yo.length),append:!1};if(e.startsWith(go))return{kind:"output",path:e.slice(go.length),append:!0};if(e.startsWith(bo)){let t=Th(e);if(t)return{kind:"readwrite",...t}}if(e.startsWith(wo)){let t=Fu(e,wo);if(t!==null)return{kind:"dup-out",sourceFd:t}}if(e.startsWith(Eo)){let t=Fu(e,Eo);if(t!==null)return{kind:"dup-in",sourceFd:t}}return{kind:"input",content:e}}function So(e){switch(e.kind){case"input":return e.content;case"output":return`${e.append?go:yo}${e.path}`;case"readwrite":return`${bo}${e.path.length}:${e.path}:${e.position}:${e.content}`;case"dup-out":return`${wo}${e.sourceFd}`;case"dup-in":return`${Eo}${e.sourceFd}`;case"closed":throw new Error("Closed descriptors have no table encoding")}}function Mh(e){return e.state.fileDescriptors??=new Map,e.state.fileDescriptors}function Bh(e,t,n){n?(e.state.inputFds??=new Set,e.state.inputFds.add(t)):e.state.inputFds?.delete(t)}function Gn(e,t){return e.state.fdAliases?.get(t)}function fn(e,t){return[...Gn(e,t)??[t]]}function Mu(e,t){let n=Gn(e,t);if(n&&(n.delete(t),e.state.fdAliases?.delete(t),n.size<2))for(let r of n)e.state.fdAliases?.delete(r)}function Ao(e,t,n){if(t===n)return;e.state.fdAliases??=new Map;let r=Gn(e,n)??new Set([n]);r.add(t);for(let s of r)e.state.fdAliases.set(s,r)}function Ls(e,t){return e.state.fileDescriptors?.get(t)}function nt(e,t){let n=Ls(e,t);if(n!==void 0)return e.state.inputFds?.has(t)?{kind:"input",content:n}:Fh(n)}function Nn(e,t){return e.state.fileDescriptors?.has(t)===!0}function vo(e,t,n,r){let s=Mh(e);s.has(t)||xu(e),s.set(t,n),Bh(e,t,r)}function Ts(e,t,n,r=!1){Mu(e,t),vo(e,t,n,r)}function ut(e,t,n){Ts(e,t,So(n),n.kind==="input")}function Ot(e,t){e.state.fileDescriptors?.delete(t),e.state.inputFds?.delete(t),Mu(e,t)}function Fs(e,t,n){let r=Ls(e,n);return r===void 0?!1:(Ts(e,t,r,e.state.inputFds?.has(n)===!0),Ao(e,t,n),!0)}function xo(e,t,n){let r=Ls(e,n);if(r===void 0)return!1;if(t===n)return!0;let s=e.state.inputFds?.has(n)===!0,i=[...Gn(e,n)??[]].filter(a=>a!==n);Ot(e,n),Ts(e,t,r,s);let o=i.find(a=>Nn(e,a));return o!==void 0&&Ao(e,t,o),!0}function Ms(e,t){let n=nt(e,t);if(n===void 0)return{error:"not-open"};switch(n.kind){case"input":return{content:n.content};case"readwrite":return{content:n.content.slice(n.position)};case"output":case"dup-out":return{error:"write-only"};case"dup-in":return{error:"not-open"};case"closed":return{error:"not-open"}}}function dn(e,t,n){let r=nt(e,t);if(r===void 0)return;let s;if(r.kind==="input")s={kind:"input",content:r.content.slice(n)};else if(r.kind==="readwrite")s={...r,position:r.position+n};else return;let i=So(s),o=s.kind==="input";for(let a of Gn(e,t)??[t])vo(e,a,i,o)}async function ko(e,t,n,r,s){if(t.kind==="output")return await e.fs.appendFile(t.path,r,s),!0;let o=n.map(u=>nt(e,u)).find(u=>u?.kind==="readwrite")??t;if(o.kind!=="readwrite")return!1;let a=o.content.slice(0,o.position)+r+o.content.slice(o.position+r.length),l={...o,position:o.position+r.length,content:a};await e.fs.writeFile(o.path,a,s);let c=So(l);for(let u of n)Nn(e,u)&&vo(e,u,c,!1);return!0}function pn(e,t,n){if(t.has(n))return;let r=Gn(e,n);t.set(n,{raw:Ls(e,n),isInput:e.state.inputFds?.has(n)===!0,aliases:r?[...r].filter(s=>s!==n):[]})}function Bs(e,t){let n=e.state.fileDescriptors;if(n)for(let[r,{raw:s,isInput:i,aliases:o}]of t){if(s===void 0){Ot(e,r);continue}Ts(e,r,s,i);let a=o.find(l=>n.has(l));a!==void 0&&Ao(e,r,a)}}function $o(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 Bu(e){if(e.fdVariable)return!1;let t=$o(e);return t!==null&&t>=Ee}async function Wh(e,t,n,r){try{if(!await e.fs.exists(t))return null;if((await e.fs.stat(t)).isDirectory)return`bash: ${n}: Is a directory
126
131
  `;if(r.checkNoclobber&&e.state.options.noclobber&&!r.isClobber&&n!=="/dev/null")return`bash: ${n}: cannot overwrite existing file
127
132
  `}catch{return`bash: ${n}: cannot open redirect target
128
- `}return null}function Ou(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 wr="scoped",Lu="bare",Tu="persistent",Oh=e=>new P(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors"),_h=(e,t)=>$n(e,t)||(e.state.fileDescriptors?.size??0)<e.limits.maxFileDescriptors,_u=e=>{let t=Math.max(e.state.nextFd??10,10);for(;$n(e,t);)t+=1;return t},Fs=e=>{let t=e.endsWith("-"),n=t?e.slice(0,-1):e;return/^\d+$/.test(n)?{sourceFd:Number.parseInt(n,10),move:t}:null},Lh=(e,t,n)=>{let r=nt(e,t);return t<Ee?r?{kind:"entry",entry:r,descriptors:cn(e,t)}:{kind:"standard",fd:t}:r?n?r.kind==="input"||r.kind==="readwrite"||r.kind==="dup-in"?{kind:"entry",entry:r,descriptors:cn(e,t)}:null:r.kind==="output"||r.kind==="readwrite"||r.kind==="dup-out"?{kind:"entry",entry:r,descriptors:cn(e,t)}:null:null};async function Hn(e,t,n,r){let s=e.fs.resolvePath(e.state.cwd,t),i=await Ih(e,s,t,{checkNoclobber:!n,isClobber:r});if(i)return{error:T("",i,1)};if(t==="/dev/full")return{error:T("",`bash: /dev/full: No space left on device
133
+ `}return null}function Wu(e){let n=Math.min(e.length,8192);for(let r=0;r<n;r++)if(e.charCodeAt(r)>127)return"utf8";return"binary"}var Sr="scoped",zu="bare",Uu="persistent",Vh=e=>new P(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors"),zh=(e,t)=>Nn(e,t)||(e.state.fileDescriptors?.size??0)<e.limits.maxFileDescriptors,Vu=e=>{let t=Math.max(e.state.nextFd??10,10);for(;Nn(e,t);)t+=1;return t},Ws=e=>{let t=e.endsWith("-"),n=t?e.slice(0,-1):e;return/^\d+$/.test(n)?{sourceFd:Number.parseInt(n,10),move:t}:null},Uh=(e,t,n)=>{let r=nt(e,t);return t<Ee?r?{kind:"entry",entry:r,descriptors:fn(e,t)}:{kind:"standard",fd:t}:r?n?r.kind==="input"||r.kind==="readwrite"||r.kind==="dup-in"?{kind:"entry",entry:r,descriptors:fn(e,t)}:null:r.kind==="output"||r.kind==="readwrite"||r.kind==="dup-out"?{kind:"entry",entry:r,descriptors:fn(e,t)}:null:null};async function Zn(e,t,n,r){let s=e.fs.resolvePath(e.state.cwd,t),i=await Wh(e,s,t,{checkNoclobber:!n,isClobber:r});if(i)return{error:T("",i,1)};if(t==="/dev/full")return{error:T("",`bash: /dev/full: No space left on device
129
134
  `,1)};if(t==="/dev/stdout")return{entry:{kind:"dup-out",sourceFd:1}};if(t==="/dev/stderr")return{entry:{kind:"dup-out",sourceFd:2}};try{n?await e.fs.appendFile(s,"","binary"):await e.fs.writeFile(s,"","binary")}catch(o){let a="cannot open redirect target";return it(o,"EROFS")?a="Read-only file system":it(o,"EACCES")?a="Permission denied":it(o,"ENOENT")?a="No such file or directory":it(o,"EISDIR")&&(a="Is a directory"),{error:T("",`bash: ${t}: ${a}
130
- `,1)}}return{entry:{kind:"output",path:s,append:n}}}async function So(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:T("",`bash: ${t}: No such file or directory
135
+ `,1)}}return{entry:{kind:"output",path:s,append:n}}}async function Po(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:T("",`bash: ${t}: No such file or directory
131
136
  `,1)};try{return await e.fs.writeFile(r,"","binary"),{entry:{kind:"readwrite",path:r,position:0,content:""}}}catch{return{error:T("",`bash: ${t}: No such file or directory
132
- `,1)}}}}var Th=async(e,t)=>{let n=await ie(e,t.content);return t.stripTabs?n.split(`
137
+ `,1)}}}}var qh=async(e,t)=>{let n=await re(e,t.content);return t.stripTabs?n.split(`
133
138
  `).map(r=>r.replace(/^\t+/,"")).join(`
134
- `):n};async function Fh(e,t,n,r){let s=new Map,i=new Map,o=(g,m)=>e.state.closedStandardFds?.has(g)?{kind:"closed"}:nt(e,g)??m,a=new Map([[0,o(0,{kind:"dup-in",sourceFd:0})],[1,o(1,{kind:"dup-out",sourceFd:1})],[2,o(2,{kind:"dup-out",sourceFd:2})]]),l=r.numericSnapshot,c,u=-1,f=a.get(0);f?.kind==="input"?(c=f.content,u=0):f?.kind==="readwrite"&&(c=f.content.slice(f.position),u=0);let d=()=>({targets:s,dupSources:i,standardRoutes:a,stdin:c,stdinSourceFd:u,error:null}),p=async(g,m,b)=>{let A={...d(),error:await dn(e,g,t.slice(0,m),s,i,a)};return b?{...A,errorCause:b}:A},h=async(g,m)=>{if(_h(e,g))return null;let b=Oh(e);return p(T("",b.stderr,P.EXIT_CODE),m,b)},y=(g,m)=>{g!==null&&g<Ee&&a.set(g,m),r.policy==="persistent"&&g!==null&&g<Ee&&(e.state.closedStandardFds?.delete(g),ct(e,g,m))},E=(g,m)=>{a.set(g,m),fn(e,r.standardSnapshot,g),r.standardClosedSnapshot.has(g)||r.standardClosedSnapshot.set(g,e.state.closedStandardFds?.has(g)===!0),e.state.closedStandardFds?.delete(g),ct(e,g,m)},S=(g,m)=>{if(g<Ee){let b=a.get(g);return b?.kind==="closed"?null:b?{kind:"entry",entry:b,descriptors:cn(e,g)}:{kind:"standard",fd:g}}return Lh(e,g,m)};for(let g=0;g<t.length;g++){let m=t[g],b=bo(m);if(m.target.type==="HereDoc"){let v=await Th(e,m.target);if(m.fdVariable){try{ue(e,m.fdVariable)}catch(k){if(!(k instanceof q))throw k;return p(T(k.stdout,k.stderr,k.exitCode),g,k)}let $=_u(e),D=await h($,g);if(D)return D;fn(e,r.fdVariableSnapshot,$),r.fdVariableEnv.has(m.fdVariable)||r.fdVariableEnv.set(m.fdVariable,e.state.env.get(m.fdVariable)),ct(e,$,{kind:"input",content:v}),e.state.env.set(m.fdVariable,String($)),e.state.nextFd=$+1}else if(b!==null&&b>=Ee){let $=await h(b,g);if($)return $;fn(e,l,b),ct(e,b,{kind:"input",content:v})}else if(b===0||b===null)c=yn(v),u=-1,y(b,{kind:"input",content:c});else{let $={kind:"input",content:v};r.policy==="persistent"?y(b,$):E(b,$)}continue}let A,x=m.operator===">&"||m.operator==="<&";if(x){if(Ji(e,m.target))return p(T("",`bash: $@: ambiguous redirect
135
- `,1),g);A=await ie(e,m.target)}else if(m.operator==="<<<")A=await ie(e,m.target);else{let v=await fu(e,m.target);if("error"in v)return p(T("",v.error,1),g);A=v.target}if(s.set(g,A),A.includes("\0"))return p(T("",`bash: ${A.replace(/\0/g,"")}: No such file or directory
136
- `,1),g);if(m.fdVariable){try{ue(e,m.fdVariable)}catch(I){if(!(I instanceof q))throw I;return p(T(I.stdout,I.stderr,I.exitCode),g,I)}if(x&&A==="-"){let I=Number.parseInt(e.state.env.get(m.fdVariable)??"",10);Number.isNaN(I)||(fn(e,r.fdVariableSnapshot,I),Dt(e,I));continue}let v=_u(e),$=x?Fs(A):null;if($&&!S($.sourceFd,m.operator==="<&"))return p(T("",`bash: ${$.sourceFd}: Bad file descriptor
137
- `,1),g);if(!($?.move===!0&&$.sourceFd>=Ee)){let I=await h(v,g);if(I)return I}fn(e,r.fdVariableSnapshot,v),r.fdVariableEnv.has(m.fdVariable)||r.fdVariableEnv.set(m.fdVariable,e.state.env.get(m.fdVariable));let k,C;if(x){let I=$;if(I){let W=S(I.sourceFd,m.operator==="<&");if(!W)return p(T("",`bash: ${I.sourceFd}: Bad file descriptor
138
- `,1),g);C=I,W.kind==="standard"?k={kind:m.operator==="<&"?"dup-in":"dup-out",sourceFd:W.fd}:I.sourceFd<Ee&&(k=W.entry)}else{if(m.operator==="<&")return p(T("",`bash: ${A}: ambiguous redirect
139
- `,1),g);let W=await Hn(e,A,!1,!1);if(W.error)return p(W.error,g);k=W.entry}}else if(m.operator===">"||m.operator===">|"||m.operator===">>"||m.operator==="&>"||m.operator==="&>>"){let I=m.operator===">>"||m.operator==="&>>",W=await Hn(e,A,I,m.operator===">|");if(W.error)return p(W.error,g);k=W.entry}else if(m.operator==="<<<")k={kind:"input",content:`${A}
140
- `};else if(m.operator==="<"||m.operator==="<>"){let I=await So(e,A,m.operator==="<>");if(I.error)return p(I.error,g);k=I.entry}if(C&&C.sourceFd>=Ee){if(!(C.move?wo(e,v,C.sourceFd):_s(e,v,C.sourceFd)))return p(T("",`bash: ${C.sourceFd}: Bad file descriptor
141
- `,1),g)}else k&&ct(e,v,k);C?.move&&C.sourceFd!==v&&C.sourceFd<Ee&&Dt(e,C.sourceFd),e.state.env.set(m.fdVariable,String(v)),e.state.nextFd=v+1;continue}if(Iu(m)){let v=b;if(x&&A==="-"){fn(e,l,v),Dt(e,v);continue}let $=x?Fs(A):null;if($&&!S($.sourceFd,m.operator==="<&"))return p(T("",`bash: ${$.sourceFd}: Bad file descriptor
142
- `,1),g);if(!($?.move===!0&&$.sourceFd>=Ee)){let k=await h(v,g);if(k)return k}if(fn(e,l,v),x){let k=$;if(!k){if(m.operator==="<&")return p(T("",`bash: ${A}: ambiguous redirect
143
- `,1),g);let I=await Hn(e,A,!1,!1);if(I.error)return p(I.error,g);ct(e,v,I.entry);continue}let C=S(k.sourceFd,m.operator==="<&");if(!C)return p(T("",`bash: ${k.sourceFd}: Bad file descriptor
144
- `,1),g);if(C.kind==="standard")ct(e,v,{kind:m.operator==="<&"?"dup-in":"dup-out",sourceFd:C.fd});else if(k.sourceFd<Ee)ct(e,v,C.entry);else if(!(k.move?wo(e,v,k.sourceFd):_s(e,v,k.sourceFd)))return p(T("",`bash: ${k.sourceFd}: Bad file descriptor
145
- `,1),g);k.move&&k.sourceFd!==v&&k.sourceFd<Ee&&Dt(e,k.sourceFd);continue}if(m.operator===">"||m.operator===">|"||m.operator===">>"){let k=await Hn(e,A,m.operator===">>",m.operator===">|");if(k.error)return p(k.error,g);ct(e,v,k.entry)}else if(m.operator==="<<<")ct(e,v,{kind:"input",content:`${A}
146
- `});else if(m.operator==="<"||m.operator==="<>"){let k=await So(e,A,m.operator==="<>");if(k.error)return p(k.error,g);ct(e,v,k.entry)}continue}if(x){if(A==="-"){b===0&&(c="",u=-1),b!==null&&b<Ee&&(a.set(b,{kind:"closed"}),r.policy==="persistent"&&(Dt(e,b),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(b)));continue}let v=Fs(A);if(!v){if(m.operator==="<&")return p(T("",`bash: ${A}: ambiguous redirect
147
- `,1),g);let D=await Hn(e,A,!1,!1);if(D.error)return p(D.error,g);let k=D.entry;i.set(g,{kind:"entry",entry:k,descriptors:[]}),m.fd==null?(y(1,k),y(2,k)):y(b,k);continue}let $=S(v.sourceFd,m.operator==="<&");if(!$)return p(T("",`bash: ${v.sourceFd}: Bad file descriptor
148
- `,1),g);if(i.set(g,$),$.kind==="entry"&&r.policy==="persistent"&&b!==null&&b<Ee&&v.sourceFd>=Ee){if(!_s(e,b,v.sourceFd))return p(T("",`bash: ${v.sourceFd}: Bad file descriptor
149
- `,1),g);a.set(b,nt(e,b)),e.state.closedStandardFds?.delete(b)}else $.kind==="standard"?y(b,{kind:m.operator==="<&"?"dup-in":"dup-out",sourceFd:$.fd}):y(b,$.entry);if(m.operator==="<&"&&b===0)if($.kind==="standard")c=$.fd===0?n:"",u=-1;else if($.entry.kind==="input"||$.entry.kind==="readwrite"){let D=v.sourceFd<Ee&&!$n(e,v.sourceFd)?{content:$.entry.kind==="input"?$.entry.content:$.entry.content.slice($.entry.position)}:Ls(e,v.sourceFd);if("error"in D)return p(T("",`bash: ${v.sourceFd}: Bad file descriptor
150
- `,1),g);c=D.content,u=$n(e,v.sourceFd)?v.sourceFd:-1}else c=n,u=-1;v.move&&(v.sourceFd>=Ee?Dt(e,v.sourceFd):(a.set(v.sourceFd,{kind:"closed"}),r.policy==="persistent"&&(Dt(e,v.sourceFd),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(v.sourceFd))));continue}if(m.operator===">"||m.operator===">|"||m.operator===">>"||m.operator==="&>"||m.operator==="&>>"){let v=await Hn(e,A,m.operator===">>"||m.operator==="&>>",m.operator===">|");if(v.error)return p(v.error,g);let $=v.entry;m.operator==="&>"||m.operator==="&>>"?(y(1,$),y(2,$)):y(b,$);continue}if(m.operator==="<<<")c=yn(`${A}
151
- `),u=-1,y(b,{kind:"input",content:c});else if(m.operator==="<"){let v=e.fs.resolvePath(e.state.cwd,A);try{c=await Cn(e.fs,v),u=-1,y(b,{kind:"input",content:c})}catch{return p(T("",`bash: ${A}: No such file or directory
152
- `,1),g)}}else if(m.operator==="<>"){let v=await So(e,A,!0);if(v.error)return p(v.error,g);let $=v.entry;y(b,$),b===0&&$.kind==="readwrite"&&(c=$.content,u=-1)}}return d()}function Gn(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="")=>Fh(e,t,i,r),finish:()=>{if(!s){if(s=!0,n!=="persistent"&&Ts(e,r.numericSnapshot),n!=="persistent"){Ts(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"){Ts(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 Zn(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 Ao(e,t,n,r){let s=t instanceof q||t instanceof _e||t instanceof ze?t.exitCode:t instanceof P?P.EXIT_CODE:0,i=await dn(e,T(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:B(i.stdout),stderr:B(i.stderr)}}async function rt(e,t,n,r){let s=Gn(e,t,wr),i;try{if(i=await s.prepare(n),i.error)return Zn(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 dn(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 Vt)||!i||await Ao(e,o,t,i),o}finally{s.finish()}}async function dn(e,t,n,r,s=new Map,i=new Map,o="bash",a=!1){n.length>0&&(t=e.executionScope.accountResult(t,"redirection"));let{stdout:l,stderr:c,exitCode:u}=t,d=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",p=b=>d,h={kind:"live-stdout"},y={kind:"live-stderr"},E=b=>{if(!b)return null;if(b.kind==="entry"){if(b.entry.kind==="dup-out"){if(b.entry.sourceFd===1)return{kind:"live-stdout"};if(b.entry.sourceFd===2)return{kind:"live-stderr"}}return b.entry.kind==="output"||b.entry.kind==="readwrite"?{kind:"descriptor",source:b}:null}return b.fd===1?h:b.fd===2?y:null},S=b=>{let A=i.get(b)??nt(e,b);return A?A.kind==="closed"?{kind:"invalid-output",fd:b}:A.kind==="input"||A.kind==="dup-in"?{kind:"invalid-output",fd:b}:A.kind==="dup-out"?A.sourceFd===1?{kind:"live-stdout"}:A.sourceFd===2?{kind:"live-stderr"}:null:A.kind==="output"||A.kind==="readwrite"?{kind:"descriptor",source:{kind:"entry",entry:A,descriptors:cn(e,b)}}:null:null};h=S(1)??h,y=S(2)??y;for(let b=0;b<n.length;b++){let A=n[b];if(A.target.type==="HereDoc"||A.fdVariable)continue;let x=r.get(b);if(x!==void 0)switch(A.operator){case">":case">|":case">>":{let v=A.fd??1;if(v!==1&&v!==2)break;let $=A.operator===">>";if(x==="/dev/stdout"){v===2&&(y=h);break}if(x==="/dev/stderr"){v===1&&(h=y);break}if(x==="/dev/full"){c+=`bash: echo: write error: No space left on device
153
- `,u=1,v===1&&(l="");break}if(x==="/dev/null"&&v===2){y={kind:"discard"};break}let D=e.fs.resolvePath(e.state.cwd,x);v===1?h={kind:"file",path:D,append:$}:y={kind:"file",path:D,append:$};break}case">&":case"<&":{let v=A.fd??(A.operator==="<&"?0:1);if(v>=Ee||v===0)break;if(x==="-"){v===1?h={kind:"discard"}:y={kind:"discard"};break}let $=E(s.get(b));if(!$)break;A.fd==null&&Fs(x)===null?(h=$,y=$):v===1?h=$:v===2&&(y=$);break}case"&>":{h={kind:"file",path:e.fs.resolvePath(e.state.cwd,x),append:!1},y=h;break}case"&>>":{h={kind:"file",path:e.fs.resolvePath(e.state.cwd,x),append:!0},y=h;break}}}if(l!==""||c!==""){let b=l,A=c;l="",c="",h.kind==="invalid-output"&&b!==""&&(b="",A+=`${a?"":"bash: "}${o}: write error: Bad file descriptor
154
- `,u=1),y.kind==="invalid-output"&&(A="");let x=async(v,$,D)=>{v.append?await e.fs.appendFile(v.path,$,D):await e.fs.writeFile(v.path,$,D)};if(h===y&&(h.kind==="file"||h.kind==="descriptor")){let v=b+A;v!==""&&(h.kind==="file"?await x(h,v,p(v)):await Eo(e,h.source.entry,h.source.descriptors,v,p(v)))}else for(let[v,$,D]of[[b,h,!0],[A,y,!1]])if(v!=="")switch($.kind){case"live-stdout":l+=v;break;case"live-stderr":c+=v;break;case"file":await x($,v,D?p(v):Ou(v));break;case"descriptor":await Eo(e,$.source.entry,$.source.descriptors,v,D?p(v):Ou(v));break;case"invalid-output":break;case"discard":break}}let g=T(l,c,u);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 b=(t.internalOutputAccounting?.stdout??0)+(t.internalOutputAccounting?.stderr??0),A=B(g.stdout),x=B(g.stderr),v=Math.min(A,b);g.internalOutputAccounting={stdout:v,stderr:Math.min(x,b-v)},e.executionScope.accountResult(g,"redirection")}else t.internalOutputAccounting&&(g.internalOutputAccounting=t.internalOutputAccounting);return g}function Fu(e,t){if(e.state.options.posix&&ir.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
155
- `;throw new q(2,"",r)}let n={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,n),ne}async function Ms(e,t,n,r="",s,i=!1){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,on(`${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 c=!1,u=()=>{if(c)return;c=!0;let p=e.state.localScopes.length-1,h=e.state.localScopes.pop(),y=e.state.localArrayScopes?.pop();if(h)for(let[E,S]of h)S===void 0?e.state.env.delete(E):e.state.env.set(E,S);if(y){e.state.arrays??=new Map;for(let[E,S]of y)S===void 0?(e.state.arrays.delete(E),e.state.associativeArrays?.delete(E)):(e.state.arrays.set(E,Me(S)),e.state.associativeArrays??=new Set,S.kind==="associative"?e.state.associativeArrays.add(E):e.state.associativeArrays.delete(E))}if(Nu(e,p),e.state.fullyUnsetLocals)for(let[E,S]of e.state.fullyUnsetLocals.entries())S===p&&e.state.fullyUnsetLocals.delete(E);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let E=e.state.localExportedVars.pop();if(E)for(let S of E)e.state.exportedVars?.delete(S)}for(let[E,S]of o)S===void 0?e.state.env.delete(E):e.state.env.set(E,S);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},f=null,d=Gn(e,t.redirections,wr);try{if(f=await d.prepare(r),f.error)return Zn(f);let p=f.stdin??r,h=i||f.stdin!==void 0||r!=="",y=await e.executeCommand(t.body,p,h);return dn(e,y,t.redirections,f.targets,f.dupSources,f.standardRoutes)}catch(p){if(p instanceof Vt&&f&&(await Ao(e,p,t.redirections,f),p instanceof _e))return T(p.stdout,p.stderr,p.exitCode);throw p}finally{d.finish(),u()}}function It(e,t,n,r){let s=n+B(t)+1;if(s>r)throw new P(`shopt: output size limit exceeded (${r} bytes)`,"output_size");return e.push(t),s}var Ws=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],Mu=["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"],Bu=[...Ws,...Mu];function Bs(e){return Ws.includes(e)}function Mh(e){return Mu.includes(e)}function Wu(e,t){let n=e.limits.maxArrayElements;if(t.length>n)throw new P(`shopt: argument limit exceeded (${n})`,"array_elements");let r=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),s=!1,i=!1,o=!1,a=!1,l=!1,c=[],u=0;for(;u<t.length;){let E=t[u];if(E==="--"){u++;break}if(E.startsWith("-")&&E.length>1){for(let S=1;S<E.length;S++){let g=E[S];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
156
- `}}}u++}else break}for(;u<t.length;)c.push(t[u]),u++;if(l)return Bh(e,c,s,i,o,a);if(s&&i)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
157
- `};if(c.length===0){if(s||i){let S=[];for(let g of Ws){let m=e.state.shoptOptions[g];s&&m?S.push(o?`shopt -s ${g}`:`${g} on`):i&&!m&&S.push(o?`shopt -u ${g}`:`${g} off`)}return{exitCode:0,stdout:S.length>0?`${S.join(`
139
+ `):n};async function jh(e,t,n,r){let s=new Map,i=new Map,o=(m,g)=>e.state.closedStandardFds?.has(m)?{kind:"closed"}:nt(e,m)??g,a=new Map([[0,o(0,{kind:"dup-in",sourceFd:0})],[1,o(1,{kind:"dup-out",sourceFd:1})],[2,o(2,{kind:"dup-out",sourceFd:2})]]),l=r.numericSnapshot,c,u=-1,f=a.get(0);f?.kind==="input"?(c=f.content,u=0):f?.kind==="readwrite"&&(c=f.content.slice(f.position),u=0);let d=()=>({targets:s,dupSources:i,standardRoutes:a,stdin:c,stdinSourceFd:u,error:null}),p=async(m,g,b)=>{let v={...d(),error:await hn(e,m,t.slice(0,g),s,i,a)};return b?{...v,errorCause:b}:v},h=async(m,g)=>{if(zh(e,m))return null;let b=Vh(e);return p(T("",b.stderr,P.EXIT_CODE),g,b)},y=(m,g)=>{m!==null&&m<Ee&&a.set(m,g),r.policy==="persistent"&&m!==null&&m<Ee&&(e.state.closedStandardFds?.delete(m),ut(e,m,g))},E=(m,g)=>{a.set(m,g),pn(e,r.standardSnapshot,m),r.standardClosedSnapshot.has(m)||r.standardClosedSnapshot.set(m,e.state.closedStandardFds?.has(m)===!0),e.state.closedStandardFds?.delete(m),ut(e,m,g)},S=(m,g)=>{if(m<Ee){let b=a.get(m);return b?.kind==="closed"?null:b?{kind:"entry",entry:b,descriptors:fn(e,m)}:{kind:"standard",fd:m}}return Uh(e,m,g)};for(let m=0;m<t.length;m++){let g=t[m],b=$o(g);if(g.target.type==="HereDoc"){let A=await qh(e,g.target);if(g.fdVariable){try{ue(e,g.fdVariable)}catch(k){if(!(k instanceof q))throw k;return p(T(k.stdout,k.stderr,k.exitCode),m,k)}let $=Vu(e),R=await h($,m);if(R)return R;pn(e,r.fdVariableSnapshot,$),r.fdVariableEnv.has(g.fdVariable)||r.fdVariableEnv.set(g.fdVariable,e.state.env.get(g.fdVariable)),ut(e,$,{kind:"input",content:A}),e.state.env.set(g.fdVariable,String($)),e.state.nextFd=$+1}else if(b!==null&&b>=Ee){let $=await h(b,m);if($)return $;pn(e,l,b),ut(e,b,{kind:"input",content:A})}else if(b===0||b===null)c=wn(A),u=-1,y(b,{kind:"input",content:c});else{let $={kind:"input",content:A};r.policy==="persistent"?y(b,$):E(b,$)}continue}let v,x=g.operator===">&"||g.operator==="<&";if(x){if(io(e,g.target))return p(T("",`bash: $@: ambiguous redirect
140
+ `,1),m);v=await re(e,g.target)}else if(g.operator==="<<<")v=await re(e,g.target);else{let A=await wu(e,g.target);if("error"in A)return p(T("",A.error,1),m);v=A.target}if(s.set(m,v),v.includes("\0"))return p(T("",`bash: ${v.replace(/\0/g,"")}: No such file or directory
141
+ `,1),m);if(g.fdVariable){try{ue(e,g.fdVariable)}catch(I){if(!(I instanceof q))throw I;return p(T(I.stdout,I.stderr,I.exitCode),m,I)}if(x&&v==="-"){let I=Number.parseInt(e.state.env.get(g.fdVariable)??"",10);Number.isNaN(I)||(pn(e,r.fdVariableSnapshot,I),Ot(e,I));continue}let A=Vu(e),$=x?Ws(v):null;if($&&!S($.sourceFd,g.operator==="<&"))return p(T("",`bash: ${$.sourceFd}: Bad file descriptor
142
+ `,1),m);if(!($?.move===!0&&$.sourceFd>=Ee)){let I=await h(A,m);if(I)return I}pn(e,r.fdVariableSnapshot,A),r.fdVariableEnv.has(g.fdVariable)||r.fdVariableEnv.set(g.fdVariable,e.state.env.get(g.fdVariable));let k,C;if(x){let I=$;if(I){let W=S(I.sourceFd,g.operator==="<&");if(!W)return p(T("",`bash: ${I.sourceFd}: Bad file descriptor
143
+ `,1),m);C=I,W.kind==="standard"?k={kind:g.operator==="<&"?"dup-in":"dup-out",sourceFd:W.fd}:I.sourceFd<Ee&&(k=W.entry)}else{if(g.operator==="<&")return p(T("",`bash: ${v}: ambiguous redirect
144
+ `,1),m);let W=await Zn(e,v,!1,!1);if(W.error)return p(W.error,m);k=W.entry}}else if(g.operator===">"||g.operator===">|"||g.operator===">>"||g.operator==="&>"||g.operator==="&>>"){let I=g.operator===">>"||g.operator==="&>>",W=await Zn(e,v,I,g.operator===">|");if(W.error)return p(W.error,m);k=W.entry}else if(g.operator==="<<<")k={kind:"input",content:`${v}
145
+ `};else if(g.operator==="<"||g.operator==="<>"){let I=await Po(e,v,g.operator==="<>");if(I.error)return p(I.error,m);k=I.entry}if(C&&C.sourceFd>=Ee){if(!(C.move?xo(e,A,C.sourceFd):Fs(e,A,C.sourceFd)))return p(T("",`bash: ${C.sourceFd}: Bad file descriptor
146
+ `,1),m)}else k&&ut(e,A,k);C?.move&&C.sourceFd!==A&&C.sourceFd<Ee&&Ot(e,C.sourceFd),e.state.env.set(g.fdVariable,String(A)),e.state.nextFd=A+1;continue}if(Bu(g)){let A=b;if(x&&v==="-"){pn(e,l,A),Ot(e,A);continue}let $=x?Ws(v):null;if($&&!S($.sourceFd,g.operator==="<&"))return p(T("",`bash: ${$.sourceFd}: Bad file descriptor
147
+ `,1),m);if(!($?.move===!0&&$.sourceFd>=Ee)){let k=await h(A,m);if(k)return k}if(pn(e,l,A),x){let k=$;if(!k){if(g.operator==="<&")return p(T("",`bash: ${v}: ambiguous redirect
148
+ `,1),m);let I=await Zn(e,v,!1,!1);if(I.error)return p(I.error,m);ut(e,A,I.entry);continue}let C=S(k.sourceFd,g.operator==="<&");if(!C)return p(T("",`bash: ${k.sourceFd}: Bad file descriptor
149
+ `,1),m);if(C.kind==="standard")ut(e,A,{kind:g.operator==="<&"?"dup-in":"dup-out",sourceFd:C.fd});else if(k.sourceFd<Ee)ut(e,A,C.entry);else if(!(k.move?xo(e,A,k.sourceFd):Fs(e,A,k.sourceFd)))return p(T("",`bash: ${k.sourceFd}: Bad file descriptor
150
+ `,1),m);k.move&&k.sourceFd!==A&&k.sourceFd<Ee&&Ot(e,k.sourceFd);continue}if(g.operator===">"||g.operator===">|"||g.operator===">>"){let k=await Zn(e,v,g.operator===">>",g.operator===">|");if(k.error)return p(k.error,m);ut(e,A,k.entry)}else if(g.operator==="<<<")ut(e,A,{kind:"input",content:`${v}
151
+ `});else if(g.operator==="<"||g.operator==="<>"){let k=await Po(e,v,g.operator==="<>");if(k.error)return p(k.error,m);ut(e,A,k.entry)}continue}if(x){if(v==="-"){b===0&&(c="",u=-1),b!==null&&b<Ee&&(a.set(b,{kind:"closed"}),r.policy==="persistent"&&(Ot(e,b),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(b)));continue}let A=Ws(v);if(!A){if(g.operator==="<&")return p(T("",`bash: ${v}: ambiguous redirect
152
+ `,1),m);let R=await Zn(e,v,!1,!1);if(R.error)return p(R.error,m);let k=R.entry;i.set(m,{kind:"entry",entry:k,descriptors:[]}),g.fd==null?(y(1,k),y(2,k)):y(b,k);continue}let $=S(A.sourceFd,g.operator==="<&");if(!$)return p(T("",`bash: ${A.sourceFd}: Bad file descriptor
153
+ `,1),m);if(i.set(m,$),$.kind==="entry"&&r.policy==="persistent"&&b!==null&&b<Ee&&A.sourceFd>=Ee){if(!Fs(e,b,A.sourceFd))return p(T("",`bash: ${A.sourceFd}: Bad file descriptor
154
+ `,1),m);a.set(b,nt(e,b)),e.state.closedStandardFds?.delete(b)}else $.kind==="standard"?y(b,{kind:g.operator==="<&"?"dup-in":"dup-out",sourceFd:$.fd}):y(b,$.entry);if(g.operator==="<&"&&b===0)if($.kind==="standard")c=$.fd===0?n:"",u=-1;else if($.entry.kind==="input"||$.entry.kind==="readwrite"){let R=A.sourceFd<Ee&&!Nn(e,A.sourceFd)?{content:$.entry.kind==="input"?$.entry.content:$.entry.content.slice($.entry.position)}:Ms(e,A.sourceFd);if("error"in R)return p(T("",`bash: ${A.sourceFd}: Bad file descriptor
155
+ `,1),m);c=R.content,u=Nn(e,A.sourceFd)?A.sourceFd:-1}else c=n,u=-1;A.move&&(A.sourceFd>=Ee?Ot(e,A.sourceFd):(a.set(A.sourceFd,{kind:"closed"}),r.policy==="persistent"&&(Ot(e,A.sourceFd),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(A.sourceFd))));continue}if(g.operator===">"||g.operator===">|"||g.operator===">>"||g.operator==="&>"||g.operator==="&>>"){let A=await Zn(e,v,g.operator===">>"||g.operator==="&>>",g.operator===">|");if(A.error)return p(A.error,m);let $=A.entry;g.operator==="&>"||g.operator==="&>>"?(y(1,$),y(2,$)):y(b,$);continue}if(g.operator==="<<<")c=wn(`${v}
156
+ `),u=-1,y(b,{kind:"input",content:c});else if(g.operator==="<"){let A=e.fs.resolvePath(e.state.cwd,v);try{c=await Dn(e.fs,A),u=-1,y(b,{kind:"input",content:c})}catch{return p(T("",`bash: ${v}: No such file or directory
157
+ `,1),m)}}else if(g.operator==="<>"){let A=await Po(e,v,!0);if(A.error)return p(A.error,m);let $=A.entry;y(b,$),b===0&&$.kind==="readwrite"&&(c=$.content,u=-1)}}return d()}function Qn(e,t,n){let r={numericSnapshot:new Map,fdVariableSnapshot:new Map,standardSnapshot:new Map,standardClosedSnapshot:new Map,fdVariableEnv:new Map,nextFd:e.state.nextFd,policy:n},s=!1;return{prepare:(i="")=>jh(e,t,i,r),finish:()=>{if(!s){if(s=!0,n!=="persistent"&&Bs(e,r.numericSnapshot),n!=="persistent"){Bs(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"){Bs(e,r.fdVariableSnapshot);for(let[i,o]of r.fdVariableEnv)o===void 0?e.state.env.delete(i):e.state.env.set(i,o);e.state.nextFd=r.nextFd}}}}}function Kn(e){if(!e.error)throw new Error("Expected a redirection error");if(e.errorCause)throw e.errorCause.stdout=e.error.stdout,e.errorCause.stderr=e.error.stderr,e.errorCause;return e.error}async function Co(e,t,n,r){let s=t instanceof q||t instanceof _e||t instanceof ze?t.exitCode:t instanceof P?P.EXIT_CODE:0,i=await hn(e,T(t.stdout,t.stderr,s),n,r.targets,r.dupSources,r.standardRoutes);t.stdout=i.stdout,t.stderr=i.stderr,t.internalOutputAccounting=i.internalOutputAccounting??{stdout:M(i.stdout),stderr:M(i.stderr)}}async function rt(e,t,n,r){let s=Qn(e,t,Sr),i;try{if(i=await s.prepare(n),i.error)return Kn(i);let o=e.state.groupStdin,a=e.state.groupStdinSourceFd;i.stdin!==void 0&&(e.state.groupStdin=i.stdin,e.state.groupStdinSourceFd=i.stdinSourceFd);try{let l=await r(i);return await hn(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 zt)||!i||await Co(e,o,t,i),o}finally{s.finish()}}async function hn(e,t,n,r,s=new Map,i=new Map,o="bash",a=!1){n.length>0&&(t=e.executionScope.accountResult(t,"redirection"));let{stdout:l,stderr:c,exitCode:u}=t,d=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",p=b=>d,h={kind:"live-stdout"},y={kind:"live-stderr"},E=b=>{if(!b)return null;if(b.kind==="entry"){if(b.entry.kind==="dup-out"){if(b.entry.sourceFd===1)return{kind:"live-stdout"};if(b.entry.sourceFd===2)return{kind:"live-stderr"}}return b.entry.kind==="output"||b.entry.kind==="readwrite"?{kind:"descriptor",source:b}:null}return b.fd===1?h:b.fd===2?y:null},S=b=>{let v=i.get(b)??nt(e,b);return v?v.kind==="closed"?{kind:"invalid-output",fd:b}:v.kind==="input"||v.kind==="dup-in"?{kind:"invalid-output",fd:b}:v.kind==="dup-out"?v.sourceFd===1?{kind:"live-stdout"}:v.sourceFd===2?{kind:"live-stderr"}:null:v.kind==="output"||v.kind==="readwrite"?{kind:"descriptor",source:{kind:"entry",entry:v,descriptors:fn(e,b)}}:null:null};h=S(1)??h,y=S(2)??y;for(let b=0;b<n.length;b++){let v=n[b];if(v.target.type==="HereDoc"||v.fdVariable)continue;let x=r.get(b);if(x!==void 0)switch(v.operator){case">":case">|":case">>":{let A=v.fd??1;if(A!==1&&A!==2)break;let $=v.operator===">>";if(x==="/dev/stdout"){A===2&&(y=h);break}if(x==="/dev/stderr"){A===1&&(h=y);break}if(x==="/dev/full"){c+=`bash: echo: write error: No space left on device
158
+ `,u=1,A===1&&(l="");break}if(x==="/dev/null"&&A===2){y={kind:"discard"};break}let R=e.fs.resolvePath(e.state.cwd,x);A===1?h={kind:"file",path:R,append:$}:y={kind:"file",path:R,append:$};break}case">&":case"<&":{let A=v.fd??(v.operator==="<&"?0:1);if(A>=Ee||A===0)break;if(x==="-"){A===1?h={kind:"discard"}:y={kind:"discard"};break}let $=E(s.get(b));if(!$)break;v.fd==null&&Ws(x)===null?(h=$,y=$):A===1?h=$:A===2&&(y=$);break}case"&>":{h={kind:"file",path:e.fs.resolvePath(e.state.cwd,x),append:!1},y=h;break}case"&>>":{h={kind:"file",path:e.fs.resolvePath(e.state.cwd,x),append:!0},y=h;break}}}if(l!==""||c!==""){let b=l,v=c;l="",c="",h.kind==="invalid-output"&&b!==""&&(b="",v+=`${a?"":"bash: "}${o}: write error: Bad file descriptor
159
+ `,u=1),y.kind==="invalid-output"&&(v="");let x=async(A,$,R)=>{A.append?await e.fs.appendFile(A.path,$,R):await e.fs.writeFile(A.path,$,R)};if(h===y&&(h.kind==="file"||h.kind==="descriptor")){let A=b+v;A!==""&&(h.kind==="file"?await x(h,A,p(A)):await ko(e,h.source.entry,h.source.descriptors,A,p(A)))}else for(let[A,$,R]of[[b,h,!0],[v,y,!1]])if(A!=="")switch($.kind){case"live-stdout":l+=A;break;case"live-stderr":c+=A;break;case"file":await x($,A,R?p(A):Wu(A));break;case"descriptor":await ko(e,$.source.entry,$.source.descriptors,A,R?p(A):Wu(A));break;case"invalid-output":break;case"discard":break}}let m=T(l,c,u);if(t.stdoutKind&&(m.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(m.stdoutEncoding="binary"),t.internalPipeStatusOverride&&(m.internalPipeStatusOverride=t.internalPipeStatusOverride),n.length>0||e.state.fileDescriptors?.has(1)===!0||e.state.fileDescriptors?.has(2)===!0){let b=(t.internalOutputAccounting?.stdout??0)+(t.internalOutputAccounting?.stderr??0),v=M(m.stdout),x=M(m.stderr),A=Math.min(v,b);m.internalOutputAccounting={stdout:A,stderr:Math.min(x,b-A)},e.executionScope.accountResult(m,"redirection")}else t.internalOutputAccounting&&(m.internalOutputAccounting=t.internalOutputAccounting);return m}function qu(e,t){if(e.state.options.posix&&cr.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
160
+ `;throw new q(2,"",r)}let n={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,n),ee}async function Vs(e,t,n,r="",s,i=!1){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,ln(`${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 c=!1,u=()=>{if(c)return;c=!0;let p=e.state.localScopes.length-1,h=e.state.localScopes.pop(),y=e.state.localArrayScopes?.pop();if(h)for(let[E,S]of h)S===void 0?e.state.env.delete(E):e.state.env.set(E,S);if(y){e.state.arrays??=new Map;for(let[E,S]of y)S===void 0?(e.state.arrays.delete(E),e.state.associativeArrays?.delete(E)):(e.state.arrays.set(E,Me(S)),e.state.associativeArrays??=new Set,S.kind==="associative"?e.state.associativeArrays.add(E):e.state.associativeArrays.delete(E))}if(Tu(e,p),e.state.fullyUnsetLocals)for(let[E,S]of e.state.fullyUnsetLocals.entries())S===p&&e.state.fullyUnsetLocals.delete(E);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let E=e.state.localExportedVars.pop();if(E)for(let S of E)e.state.exportedVars?.delete(S)}for(let[E,S]of o)S===void 0?e.state.env.delete(E):e.state.env.set(E,S);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},f=null,d=Qn(e,t.redirections,Sr);try{if(f=await d.prepare(r),f.error)return Kn(f);let p=f.stdin??r,h=i||f.stdin!==void 0||r!=="",y=await e.executeCommand(t.body,p,h);return hn(e,y,t.redirections,f.targets,f.dupSources,f.standardRoutes)}catch(p){if(p instanceof zt&&f&&(await Co(e,p,t.redirections,f),p instanceof _e))return T(p.stdout,p.stderr,p.exitCode);throw p}finally{d.finish(),u()}}function _t(e,t,n,r){let s=n+M(t)+1;if(s>r)throw new P(`shopt: output size limit exceeded (${r} bytes)`,"output_size");return e.push(t),s}var Us=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],ju=["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"],Hu=[...Us,...ju];function zs(e){return Us.includes(e)}function Hh(e){return ju.includes(e)}function Gu(e,t){let n=e.limits.maxArrayElements;if(t.length>n)throw new P(`shopt: argument limit exceeded (${n})`,"array_elements");let r=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),s=!1,i=!1,o=!1,a=!1,l=!1,c=[],u=0;for(;u<t.length;){let E=t[u];if(E==="--"){u++;break}if(E.startsWith("-")&&E.length>1){for(let S=1;S<E.length;S++){let m=E[S];switch(m){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: -${m}: invalid option
161
+ `}}}u++}else break}for(;u<t.length;)c.push(t[u]),u++;if(l)return Gh(e,c,s,i,o,a);if(s&&i)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
162
+ `};if(c.length===0){if(s||i){let S=[];for(let m of Us){let g=e.state.shoptOptions[m];s&&g?S.push(o?`shopt -s ${m}`:`${m} on`):i&&!g&&S.push(o?`shopt -u ${m}`:`${m} off`)}return{exitCode:0,stdout:S.length>0?`${S.join(`
158
163
  `)}
159
- `:"",stderr:""}}let E=[];for(let S of Ws){let g=e.state.shoptOptions[S];E.push(o?`shopt ${g?"-s":"-u"} ${S}`:`${S} ${g?"on":"off"}`)}return{exitCode:0,stdout:`${E.join(`
164
+ `:"",stderr:""}}let E=[];for(let S of Us){let m=e.state.shoptOptions[S];E.push(o?`shopt ${m?"-s":"-u"} ${S}`:`${S} ${m?"on":"off"}`)}return{exitCode:0,stdout:`${E.join(`
160
165
  `)}
161
- `,stderr:""}}let f=!1,d=[],p=0,h=[],y=0;for(let E of c){if(!Bs(E)&&!Mh(E)){p=It(d,`shopt: ${E}: invalid shell option name`,p,r),f=!0;continue}if(s)Bs(E)&&(e.state.shoptOptions[E]=!0,pi(e));else if(i)Bs(E)&&(e.state.shoptOptions[E]=!1,pi(e));else if(Bs(E)){let S=e.state.shoptOptions[E];a?S||(f=!0):o?(y=It(h,`shopt ${S?"-s":"-u"} ${E}`,y,r),S||(f=!0)):(y=It(h,`${E} ${S?"on":"off"}`,y,r),S||(f=!0))}else a?f=!0:o?(y=It(h,`shopt -u ${E}`,y,r),f=!0):(y=It(h,`${E} off`,y,r),f=!0)}return{exitCode:f?1:0,stdout:h.length>0?`${h.join(`
166
+ `,stderr:""}}let f=!1,d=[],p=0,h=[],y=0;for(let E of c){if(!zs(E)&&!Hh(E)){p=_t(d,`shopt: ${E}: invalid shell option name`,p,r),f=!0;continue}if(s)zs(E)&&(e.state.shoptOptions[E]=!0,gi(e));else if(i)zs(E)&&(e.state.shoptOptions[E]=!1,gi(e));else if(zs(E)){let S=e.state.shoptOptions[E];a?S||(f=!0):o?(y=_t(h,`shopt ${S?"-s":"-u"} ${E}`,y,r),S||(f=!0)):(y=_t(h,`${E} ${S?"on":"off"}`,y,r),S||(f=!0))}else a?f=!0:o?(y=_t(h,`shopt -u ${E}`,y,r),f=!0):(y=_t(h,`${E} off`,y,r),f=!0)}return{exitCode:f?1:0,stdout:h.length>0?`${h.join(`
162
167
  `)}
163
168
  `:"",stderr:d.length>0?`${d.join(`
164
169
  `)}
165
- `:""}}function Bh(e,t,n,r,s,i){let o=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),a=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),l=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],c=[...a.keys(),...l].sort();if(t.length===0){let y=[];for(let E of c){let S=l.includes(E),g=a.get(E),m=S||!g?!1:e.state.options[g];n&&!m||r&&m||y.push(s?`set ${m?"-o":"+o"} ${E}`:`${E} ${m?"on":"off"}`)}return{exitCode:0,stdout:y.length>0?`${y.join(`
170
+ `:""}}function Gh(e,t,n,r,s,i){let o=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),a=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),l=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],c=[...a.keys(),...l].sort();if(t.length===0){let y=[];for(let E of c){let S=l.includes(E),m=a.get(E),g=S||!m?!1:e.state.options[m];n&&!g||r&&g||y.push(s?`set ${g?"-o":"+o"} ${E}`:`${E} ${g?"on":"off"}`)}return{exitCode:0,stdout:y.length>0?`${y.join(`
166
171
  `)}
167
- `:"",stderr:""}}let u=!1,f=[],d=0,p=[],h=0;for(let y of t){let E=a.has(y),S=l.includes(y);if(!E&&!S){d=It(f,`shopt: ${y}: invalid option name`,d,o),u=!0;continue}if(S){n||r||(i?u=!0:s?(h=It(p,`set +o ${y}`,h,o),u=!0):(h=It(p,`${y} off`,h,o),u=!0));continue}let g=a.get(y);if(g)if(n)g==="vi"?e.state.options.emacs=!1:g==="emacs"&&(e.state.options.vi=!1),e.state.options[g]=!0,Fn(e);else if(r)e.state.options[g]=!1,Fn(e);else{let m=e.state.options[g];i?m||(u=!0):s?(h=It(p,`set ${m?"-o":"+o"} ${y}`,h,o),m||(u=!0)):(h=It(p,`${y} ${m?"on":"off"}`,h,o),m||(u=!0))}}return{exitCode:u?1:0,stdout:p.length>0?`${p.join(`
172
+ `:"",stderr:""}}let u=!1,f=[],d=0,p=[],h=0;for(let y of t){let E=a.has(y),S=l.includes(y);if(!E&&!S){d=_t(f,`shopt: ${y}: invalid option name`,d,o),u=!0;continue}if(S){n||r||(i?u=!0:s?(h=_t(p,`set +o ${y}`,h,o),u=!0):(h=_t(p,`${y} off`,h,o),u=!0));continue}let m=a.get(y);if(m)if(n)m==="vi"?e.state.options.emacs=!1:m==="emacs"&&(e.state.options.vi=!1),e.state.options[m]=!0,Bn(e);else if(r)e.state.options[m]=!1,Bn(e);else{let g=e.state.options[m];i?g||(u=!0):s?(h=_t(p,`set ${g?"-o":"+o"} ${y}`,h,o),g||(u=!0)):(h=_t(p,`${y} ${g?"on":"off"}`,h,o),g||(u=!0))}}return{exitCode:u?1:0,stdout:p.length>0?`${p.join(`
168
173
  `)}
169
174
  `:"",stderr:f.length>0?`${f.join(`
170
175
  `)}
171
- `:""}}var zu=e=>e.type==="Escaped"?F.literal(`\\${e.value}`):e.type==="DoubleQuoted"?{...e,parts:e.parts.map(zu)}:e,Uu=or,ko=vt,Wh=Bu,Vh=ko;async function $o(e,t){let n=[],r=null,s="",i="",o=null,a=!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 x=0;x<t.length;x++){let v=t[x];if(v==="-v")n.push("variable");else if(v==="-e")n.push("export");else if(v==="-f")n.push("file");else if(v==="-d")n.push("directory");else if(v==="-k")n.push("keyword");else if(v==="-A"){if(x++,x>=t.length)return L(`compgen: -A: option requires an argument
176
+ `:""}}var Qu=e=>e.type==="Escaped"?F.literal(`\\${e.value}`):e.type==="DoubleQuoted"?{...e,parts:e.parts.map(Qu)}:e,Ku=ur,Do=kt,Zh=Hu,Qh=Do;async function Io(e,t){let n=[],r=null,s="",i="",o=null,a=!1,l=!1,c=!1,u=null,f=null,d=null,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 L(`compgen: -A: option requires an argument
172
177
  `,2);let $=t[x];if(!h.includes($))return L(`compgen: ${$}: invalid action name
173
- `,2);n.push($)}else if(v==="-W"){if(x++,x>=t.length)return L(`compgen: -W: option requires an argument
174
- `,2);r=t[x]}else if(v==="-P"){if(x++,x>=t.length)return L(`compgen: -P: option requires an argument
175
- `,2);s=t[x]}else if(v==="-S"){if(x++,x>=t.length)return L(`compgen: -S: option requires an argument
176
- `,2);i=t[x]}else if(v==="-o"){if(x++,x>=t.length)return L(`compgen: -o: option requires an argument
178
+ `,2);n.push($)}else if(A==="-W"){if(x++,x>=t.length)return L(`compgen: -W: option requires an argument
179
+ `,2);r=t[x]}else if(A==="-P"){if(x++,x>=t.length)return L(`compgen: -P: option requires an argument
180
+ `,2);s=t[x]}else if(A==="-S"){if(x++,x>=t.length)return L(`compgen: -S: option requires an argument
181
+ `,2);i=t[x]}else if(A==="-o"){if(x++,x>=t.length)return L(`compgen: -o: option requires an argument
177
182
  `,2);let $=t[x];if($==="plusdirs")a=!0;else if($==="dirnames")l=!0;else if($==="default")c=!0;else if(!($==="filenames"||$==="nospace"||$==="bashdefault"||$==="noquote"))return L(`compgen: ${$}: invalid option name
178
- `,2)}else if(v==="-F"){if(x++,x>=t.length)return L(`compgen: -F: option requires an argument
179
- `,2);f=t[x]}else if(v==="-C"){if(x++,x>=t.length)return L(`compgen: -C: option requires an argument
180
- `,2);d=t[x]}else if(v==="-X"){if(x++,x>=t.length)return L(`compgen: -X: option requires an argument
181
- `,2);u=t[x]}else if(v==="-G"){if(x++,x>=t.length)return L(`compgen: -G: option requires an argument
182
- `,2)}else if(v==="--"){p.push(...t.slice(x+1));break}else v.startsWith("-")||p.push(v)}o=p[0]??null;let y=[],E=new Set,S=()=>e.limits.maxArrayElements-y.length,g=x=>{for(let v of x){if(y.length>=e.limits.maxArrayElements)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(B(v)>e.limits.maxStringLength)throw new P(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");e.executionScope.consumeWork(1,"compgen completion"),y.push(v),E.add(v)}};if(l){let x=await vo(e,o,S());g(x)}if(c){let x=await Vu(e,o,S());g(x)}for(let x of n)if(x==="variable"){let v=zh(e,o,S());g(v)}else if(x==="export"){let v=Uh(e,o,S());g(v)}else if(x==="function"){let v=qh(e,o,S());g(v)}else if(x==="builtin"){let v=jh(e,o,S());g(v)}else if(x==="keyword"){let v=Hh(e,o,S());g(v)}else if(x==="alias"){let v=Gh(e,o,S());g(v)}else if(x==="shopt"){let v=Zh(e,o,S());g(v)}else if(x==="helptopic"){let v=Qh(e,o,S());g(v)}else if(x==="directory"){let v=await vo(e,o,S());g(v)}else if(x==="file"){let v=await Vu(e,o,S());g(v)}else if(x==="user"){let v=Kh(e,o,S());g(v)}else if(x==="command"){let v=await Xh(e,o,S());g(v)}if(r!==null)try{let x=await Yh(e,r),v=Jh(e,x,S(),o);for(let $ of v)g([$])}catch(x){if(x instanceof P)throw x;return T("","",1)}if(a){let x=await vo(e,o,S(),E);for(let v of x)E.has(v)||g([v])}let m="";if(f!==null){let x=e.state.functions.get(f);if(x){let v=new Map,$=xe(e,"COMP_WORDS"),D=$?Me($):void 0;ge(e,"COMP_WORDS"),rr(e,"COMP_WORDS"),v.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),v.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),v.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let k=xe(e,"COMPREPLY"),C=k?Me(k):void 0,I=e.state.env.get("COMPREPLY");ge(e,"COMPREPLY"),e.state.env.delete("COMPREPLY");let W=["compgen",p[0]??"",""];try{let Z=await Ms(e,x,W,"");if(Z.exitCode!==0)return xo(e,v),Qn(e,"COMP_WORDS",D),Qn(e,"COMPREPLY",C),I!==void 0&&e.state.env.set("COMPREPLY",I),T("",Z.stderr,1);m=Z.stdout;let R=em(e,S());g(R)}catch(Z){if(Z instanceof P)throw Z;return xo(e,v),Qn(e,"COMP_WORDS",D),Qn(e,"COMPREPLY",C),I!==void 0&&e.state.env.set("COMPREPLY",I),T("","",1)}xo(e,v),Qn(e,"COMP_WORDS",D),Qn(e,"COMPREPLY",C),I!==void 0&&e.state.env.set("COMPREPLY",I)}}if(d!==null)try{let x=at(d),v=await e.executeScript(x);if(v.exitCode!==0)return T("",v.stderr,v.exitCode);if(v.stdout)for(let $ of tm(v.stdout))$.length>0&&g([$])}catch(x){if(x.name==="ParseException")return L(`compgen: -C: ${x.message}
183
- `,2);throw x}let b=y;if(u!==null){let x=u.startsWith("!"),v=x?u.slice(1):u;b=y.filter($=>{let D=Un($,v,!1,!0,e.limits.maxCallDepth);return x?D:!D})}if(b.length===0&&o!==null)return T(m,"",1);let A=new Nn(e.limits.maxOutputSize,"compgen");A.append(m);for(let x of b)A.append(s).append(x).append(i).append(`
184
- `);return ee(A.build())}function zh(e,t,n){let r=ut(e,t,n);for(let s of e.state.env.keys())/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&r.add(s);for(let s of e.state.arrays?.keys()??[])r.add(s);return r.build()}function Uh(e,t,n){let r=ut(e,t,n),s=e.state.exportedVars??new Set;for(let i of s)e.state.env.has(i)&&r.add(i);return r.build()}function qh(e,t,n){let r=ut(e,t,n);for(let s of e.state.functions.keys())r.add(s);return r.build()}function jh(e,t,n){let r=ut(e,t,n);for(let s of ko)r.add(s);return r.build()}function Hh(e,t,n){let r=ut(e,t,n);for(let s of Uu)r.add(s);return r.build()}function Gh(e,t,n){let r=ut(e,t,n);for(let s of e.state.env.keys())if(s.startsWith("BASH_ALIAS_")){let i=s.slice(11);r.add(i)}return r.build()}function Zh(e,t,n){let r=ut(e,t,n);for(let s of Wh)r.add(s);return r.build()}function Qh(e,t,n){let r=ut(e,t,n);for(let s of Vh)r.add(s);return r.build()}async function vo(e,t,n=e.limits.maxArrayElements,r){let s=ut(e,null,n,r);try{let i=e.state.cwd,o=t??"";if(t){let l=t.lastIndexOf("/");if(l!==-1){let c=t.slice(0,l)||"/";o=t.slice(l+1),c.startsWith("/")?i=c:i=`${e.state.cwd}/${c}`}}let a=await e.fs.readdir(i);for(let l of a){e.executionScope.consumeWork(1,"compgen directory scan");let c=`${i}/${l}`;try{if((await e.fs.stat(c)).isDirectory&&(!o||l.startsWith(o)))if(t?.includes("/")){let f=t.lastIndexOf("/"),d=t.slice(0,f+1);s.add(d+l)}else s.add(l)}catch(u){if(u instanceof P)throw u}}}catch(i){if(i instanceof P)throw i}return s.build()}async function Vu(e,t,n=e.limits.maxArrayElements){let r=ut(e,null,n);try{let s=e.state.cwd,i=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";i=t.slice(a+1),l.startsWith("/")?s=l:s=`${e.state.cwd}/${l}`}}let o=await e.fs.readdir(s);for(let a of o)if(e.executionScope.consumeWork(1,"compgen file scan"),!i||a.startsWith(i))if(t?.includes("/")){let l=t.lastIndexOf("/"),c=t.slice(0,l+1);r.add(c+a)}else r.add(a)}catch(s){if(s instanceof P)throw s}return r.build()}function Kh(e,t,n){let r=ut(e,t,n);return r.add("root"),r.add("nobody"),r.build()}async function Xh(e,t,n){let r=ut(e,t,n);for(let i of ko)r.add(i);for(let i of e.state.functions.keys())r.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&r.add(i.slice(11));for(let i of Uu)r.add(i);let s=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of s.split(":"))if(i)try{let o=await e.fs.readdir(i);for(let a of o)r.add(a)}catch(o){if(o instanceof P)throw o}return r.build()}function ut(e,t,n,r){let s=new Set;return{add(i){if(e.executionScope.consumeWork(1,"compgen candidate collection"),!(t!==null&&!i.startsWith(t))&&!r?.has(i)&&!s.has(i)){if(s.size>=n)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(B(i)>e.limits.maxStringLength)throw new P(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");s.add(i)}},build(){return Array.from(s).sort()}}}async function Yh(e,t){let r=new H().parseWordFromString(t,!1,!1);return await ie(e,F.word(r.parts.map(zu)))}function Jh(e,t,n,r){let s=e.state.env.get("IFS")??`
185
- `;if(s.length===0){if(r!==null&&!t.startsWith(r))return[];if(n===0)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");return[t]}let i=new Set(s.split("")),o=[],a=u=>{if(!(r!==null&&!u.startsWith(r))){if(o.length>=n)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");o.push(u)}},l="",c=0;for(;c<t.length;){let u=t[c];if(u==="\\"&&c+1<t.length){let f=t[c+1];l+=f,c+=2}else i.has(u)?(l.length>0&&(a(l),l=""),c++):(l+=u,c++)}return l.length>0&&a(l),o}function xo(e,t){for(let[n,r]of t)r===void 0?e.state.env.delete(n):e.state.env.set(n,r)}function Qn(e,t,n){e.state.arrays??=new Map,n?e.state.arrays.set(t,Me(n)):e.state.arrays.delete(t)}function em(e,t){let n=[],r=s=>{if(n.length>=t)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");n.push(s)};if(Ce(e,"COMPREPLY")){let s=G(e,"COMPREPLY");for(let[,i]of s)r(i)}else{let s=e.state.env.get("COMPREPLY");s!==void 0&&r(s)}return n}function*tm(e){let t=0;for(;t<=e.length;){let n=e.indexOf(`
186
- `,t),r=n===-1?e.length:n;if(r>t&&(yield e.slice(t,r)),n===-1)return;t=n+1}}function Er(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n===127)return!0}return!1}function Po(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 qu(e){if(Er(e))return ju(e);if(e==="")return 2;if(/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e))return B(e);let t=B(e)+2;for(let n of e)n==="'"&&(t+=3);return t}function be(e){return Er(e)?Po(e):e===""?"''":/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Vs(e){if(Er(e))return ju(e);let t=B(e)+2;for(let n of e)(n==="\\"||n==='"'||n==="$"||n==="`")&&t++;return t}function pn(e){return Er(e)?Po(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}function ju(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+=B(n)}return t}function br(e){return Er(e)?Po(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}var nm=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function No(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=!1,i,o,a,l=[],c=[],u=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-p")n=!0;else if(d==="-r")r=!0;else if(d==="-D")s=!0;else if(d==="-W"){if(f++,f>=t.length)return L(`complete: -W: option requires an argument
183
+ `,2)}else if(A==="-F"){if(x++,x>=t.length)return L(`compgen: -F: option requires an argument
184
+ `,2);f=t[x]}else if(A==="-C"){if(x++,x>=t.length)return L(`compgen: -C: option requires an argument
185
+ `,2);d=t[x]}else if(A==="-X"){if(x++,x>=t.length)return L(`compgen: -X: option requires an argument
186
+ `,2);u=t[x]}else if(A==="-G"){if(x++,x>=t.length)return L(`compgen: -G: option requires an argument
187
+ `,2)}else if(A==="--"){p.push(...t.slice(x+1));break}else A.startsWith("-")||p.push(A)}o=p[0]??null;let y=[],E=new Set,S=()=>e.limits.maxArrayElements-y.length,m=x=>{for(let A of x){if(y.length>=e.limits.maxArrayElements)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(M(A)>e.limits.maxStringLength)throw new P(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");e.executionScope.consumeWork(1,"compgen completion"),y.push(A),E.add(A)}};if(l){let x=await No(e,o,S());m(x)}if(c){let x=await Zu(e,o,S());m(x)}for(let x of n)if(x==="variable"){let A=Kh(e,o,S());m(A)}else if(x==="export"){let A=Xh(e,o,S());m(A)}else if(x==="function"){let A=Yh(e,o,S());m(A)}else if(x==="builtin"){let A=Jh(e,o,S());m(A)}else if(x==="keyword"){let A=em(e,o,S());m(A)}else if(x==="alias"){let A=tm(e,o,S());m(A)}else if(x==="shopt"){let A=nm(e,o,S());m(A)}else if(x==="helptopic"){let A=rm(e,o,S());m(A)}else if(x==="directory"){let A=await No(e,o,S());m(A)}else if(x==="file"){let A=await Zu(e,o,S());m(A)}else if(x==="user"){let A=sm(e,o,S());m(A)}else if(x==="command"){let A=await im(e,o,S());m(A)}if(r!==null)try{let x=await om(e,r),A=am(e,x,S(),o);for(let $ of A)m([$])}catch(x){if(x instanceof P)throw x;return T("","",1)}if(a){let x=await No(e,o,S(),E);for(let A of x)E.has(A)||m([A])}let g="";if(f!==null){let x=e.state.functions.get(f);if(x){let A=new Map,$=xe(e,"COMP_WORDS"),R=$?Me($):void 0;ge(e,"COMP_WORDS"),ar(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 k=xe(e,"COMPREPLY"),C=k?Me(k):void 0,I=e.state.env.get("COMPREPLY");ge(e,"COMPREPLY"),e.state.env.delete("COMPREPLY");let W=["compgen",p[0]??"",""];try{let Z=await Vs(e,x,W,"");if(Z.exitCode!==0)return Ro(e,A),Xn(e,"COMP_WORDS",R),Xn(e,"COMPREPLY",C),I!==void 0&&e.state.env.set("COMPREPLY",I),T("",Z.stderr,1);g=Z.stdout;let D=lm(e,S());m(D)}catch(Z){if(Z instanceof P)throw Z;return Ro(e,A),Xn(e,"COMP_WORDS",R),Xn(e,"COMPREPLY",C),I!==void 0&&e.state.env.set("COMPREPLY",I),T("","",1)}Ro(e,A),Xn(e,"COMP_WORDS",R),Xn(e,"COMPREPLY",C),I!==void 0&&e.state.env.set("COMPREPLY",I)}}if(d!==null)try{let x=lt(d),A=await e.executeScript(x);if(A.exitCode!==0)return T("",A.stderr,A.exitCode);if(A.stdout)for(let $ of cm(A.stdout))$.length>0&&m([$])}catch(x){if(x.name==="ParseException")return L(`compgen: -C: ${x.message}
188
+ `,2);throw x}let b=y;if(u!==null){let x=u.startsWith("!"),A=x?u.slice(1):u;b=y.filter($=>{let R=jn($,A,!1,!0,e.limits.maxCallDepth);return x?R:!R})}if(b.length===0&&o!==null)return T(g,"",1);let v=new In(e.limits.maxOutputSize,"compgen");v.append(g);for(let x of b)v.append(s).append(x).append(i).append(`
189
+ `);return J(v.build())}function Kh(e,t,n){let r=ft(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 Xh(e,t,n){let r=ft(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 Yh(e,t,n){let r=ft(e,t,n);for(let s of e.state.functions.keys())r.add(s);return r.build()}function Jh(e,t,n){let r=ft(e,t,n);for(let s of Do)r.add(s);return r.build()}function em(e,t,n){let r=ft(e,t,n);for(let s of Ku)r.add(s);return r.build()}function tm(e,t,n){let r=ft(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 nm(e,t,n){let r=ft(e,t,n);for(let s of Zh)r.add(s);return r.build()}function rm(e,t,n){let r=ft(e,t,n);for(let s of Qh)r.add(s);return r.build()}async function No(e,t,n=e.limits.maxArrayElements,r){let s=ft(e,null,n,r);try{let i=e.state.cwd,o=t??"";if(t){let l=t.lastIndexOf("/");if(l!==-1){let c=t.slice(0,l)||"/";o=t.slice(l+1),c.startsWith("/")?i=c:i=`${e.state.cwd}/${c}`}}let a=await e.fs.readdir(i);for(let l of a){e.executionScope.consumeWork(1,"compgen directory scan");let c=`${i}/${l}`;try{if((await e.fs.stat(c)).isDirectory&&(!o||l.startsWith(o)))if(t?.includes("/")){let f=t.lastIndexOf("/"),d=t.slice(0,f+1);s.add(d+l)}else s.add(l)}catch(u){if(u instanceof P)throw u}}}catch(i){if(i instanceof P)throw i}return s.build()}async function Zu(e,t,n=e.limits.maxArrayElements){let r=ft(e,null,n);try{let s=e.state.cwd,i=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";i=t.slice(a+1),l.startsWith("/")?s=l:s=`${e.state.cwd}/${l}`}}let o=await e.fs.readdir(s);for(let a of o)if(e.executionScope.consumeWork(1,"compgen file scan"),!i||a.startsWith(i))if(t?.includes("/")){let l=t.lastIndexOf("/"),c=t.slice(0,l+1);r.add(c+a)}else r.add(a)}catch(s){if(s instanceof P)throw s}return r.build()}function sm(e,t,n){let r=ft(e,t,n);return r.add("root"),r.add("nobody"),r.build()}async function im(e,t,n){let r=ft(e,t,n);for(let i of Do)r.add(i);for(let i of e.state.functions.keys())r.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&r.add(i.slice(11));for(let i of Ku)r.add(i);let s=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of s.split(":"))if(i)try{let o=await e.fs.readdir(i);for(let a of o)r.add(a)}catch(o){if(o instanceof P)throw o}return r.build()}function ft(e,t,n,r){let s=new Set;return{add(i){if(e.executionScope.consumeWork(1,"compgen candidate collection"),!(t!==null&&!i.startsWith(t))&&!r?.has(i)&&!s.has(i)){if(s.size>=n)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(M(i)>e.limits.maxStringLength)throw new P(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");s.add(i)}},build(){return Array.from(s).sort()}}}async function om(e,t){let r=new H().parseWordFromString(t,!1,!1);return await re(e,F.word(r.parts.map(Qu)))}function am(e,t,n,r){let s=e.state.env.get("IFS")??`
190
+ `;if(s.length===0){if(r!==null&&!t.startsWith(r))return[];if(n===0)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");return[t]}let i=new Set(s.split("")),o=[],a=u=>{if(!(r!==null&&!u.startsWith(r))){if(o.length>=n)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");o.push(u)}},l="",c=0;for(;c<t.length;){let u=t[c];if(u==="\\"&&c+1<t.length){let f=t[c+1];l+=f,c+=2}else i.has(u)?(l.length>0&&(a(l),l=""),c++):(l+=u,c++)}return l.length>0&&a(l),o}function Ro(e,t){for(let[n,r]of t)r===void 0?e.state.env.delete(n):e.state.env.set(n,r)}function Xn(e,t,n){e.state.arrays??=new Map,n?e.state.arrays.set(t,Me(n)):e.state.arrays.delete(t)}function lm(e,t){let n=[],r=s=>{if(n.length>=t)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");n.push(s)};if(Ce(e,"COMPREPLY")){let s=G(e,"COMPREPLY");for(let[,i]of s)r(i)}else{let s=e.state.env.get("COMPREPLY");s!==void 0&&r(s)}return n}function*cm(e){let t=0;for(;t<=e.length;){let n=e.indexOf(`
191
+ `,t),r=n===-1?e.length:n;if(r>t&&(yield e.slice(t,r)),n===-1)return;t=n+1}}function Ar(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n===127)return!0}return!1}function Oo(e){let t="$'";for(let n=0;n<e.length;n++){let r=e[n],s=e.charCodeAt(n);s===7?t+="\\a":s===8?t+="\\b":s===9?t+="\\t":s===10?t+="\\n":s===11?t+="\\v":s===12?t+="\\f":s===13?t+="\\r":s===27?t+="\\e":s===39?t+="\\'":s===92?t+="\\\\":s<32||s===127?t+=`\\${s.toString(8).padStart(3,"0")}`:t+=r}return t+="'",t}function Xu(e){if(Ar(e))return Yu(e);if(e==="")return 2;if(/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e))return M(e);let t=M(e)+2;for(let n of e)n==="'"&&(t+=3);return t}function be(e){return Ar(e)?Oo(e):e===""?"''":/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function qs(e){if(Ar(e))return Yu(e);let t=M(e)+2;for(let n of e)(n==="\\"||n==='"'||n==="$"||n==="`")&&t++;return t}function mn(e){return Ar(e)?Oo(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}function Yu(e){let t=3;for(let n of e){let r=n.codePointAt(0)??0;r===7||r===8||r===9||r===10||r===11||r===12||r===13||r===27||r===39||r===92?t+=2:r<32||r===127?t+=4:t+=M(n)}return t}function vr(e){return Ar(e)?Oo(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}var um=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Lo(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=!1,i,o,a,l=[],c=[],u=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-p")n=!0;else if(d==="-r")r=!0;else if(d==="-D")s=!0;else if(d==="-W"){if(f++,f>=t.length)return L(`complete: -W: option requires an argument
187
192
  `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return L(`complete: -F: option requires an argument
188
193
  `,2);o=t[f]}else if(d==="-o"){if(f++,f>=t.length)return L(`complete: -o: option requires an argument
189
- `,2);let p=t[f];if(!nm.includes(p))return L(`complete: ${p}: invalid option name
194
+ `,2);let p=t[f];if(!um.includes(p))return L(`complete: ${p}: invalid option name
190
195
  `,2);l.push(p)}else if(d==="-A"){if(f++,f>=t.length)return L(`complete: -A: option requires an argument
191
196
  `,2);c.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return L(`complete: -C: option requires an argument
192
197
  `,2);a=t[f]}else if(d==="-G"){if(f++,f>=t.length)return L(`complete: -G: option requires an argument
193
198
  `,2)}else if(d==="-P"){if(f++,f>=t.length)return L(`complete: -P: option requires an argument
194
199
  `,2)}else if(d==="-S"){if(f++,f>=t.length)return L(`complete: -S: option requires an argument
195
200
  `,2)}else if(d==="-X"){if(f++,f>=t.length)return L(`complete: -X: option requires an argument
196
- `,2)}else if(d==="--"){u.push(...t.slice(f+1));break}else d.startsWith("-")||u.push(d)}if(r){if(u.length===0)return e.state.completionSpecs.clear(),e.state.defaultCompletionSpec=void 0,e.state.emptyCompletionSpec=void 0,ee("");for(let f of u)e.state.completionSpecs.delete(f);return ee("")}if(n)return u.length===0?Co(e):Co(e,u);if(t.length===0||u.length===0&&!i&&!o&&!a&&l.length===0&&c.length===0&&!s)return Co(e);if(o&&u.length===0&&!s)return L(`complete: -F: option requires a command name
197
- `,2);if(s){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),o!==void 0&&(f.function=o),a!==void 0&&(f.command=a),l.length>0&&(f.options=l),c.length>0&&(f.actions=c),e.state.defaultCompletionSpec=f,ee("")}for(let f of u){let d=Object.create(null);i!==void 0&&(d.wordlist=i),o!==void 0&&(d.function=o),a!==void 0&&(d.command=a),l.length>0&&(d.options=l),c.length>0&&(d.actions=c),e.state.completionSpecs.set(f,d)}return ee("")}function Co(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
198
- `;return T("",i,1)}return ee("")}let r=[],s=t||Array.from(n.keys());for(let i of s){let o=n.get(i);if(!o){if(t)return T(r.join(`
201
+ `,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,J("");for(let f of u)e.state.completionSpecs.delete(f);return J("")}if(n)return u.length===0?_o(e):_o(e,u);if(t.length===0||u.length===0&&!i&&!o&&!a&&l.length===0&&c.length===0&&!s)return _o(e);if(o&&u.length===0&&!s)return L(`complete: -F: option requires a command name
202
+ `,2);if(s){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),o!==void 0&&(f.function=o),a!==void 0&&(f.command=a),l.length>0&&(f.options=l),c.length>0&&(f.actions=c),e.state.defaultCompletionSpec=f,J("")}for(let f of u){let d=Object.create(null);i!==void 0&&(d.wordlist=i),o!==void 0&&(d.function=o),a!==void 0&&(d.command=a),l.length>0&&(d.options=l),c.length>0&&(d.actions=c),e.state.completionSpecs.set(f,d)}return J("")}function _o(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
203
+ `;return T("",i,1)}return J("")}let r=[],s=t||Array.from(n.keys());for(let i of s){let o=n.get(i);if(!o){if(t)return T(r.join(`
199
204
  `)+(r.length>0?`
200
205
  `:""),`complete: ${i}: no completion specification
201
- `,1);continue}let a="complete";if(o.options)for(let l of o.options)a+=` -o ${be(l)}`;if(o.actions)for(let l of o.actions)a+=` -A ${be(l)}`;o.wordlist!==void 0&&(o.wordlist.includes(" ")||o.wordlist.includes("'")?a+=` -W ${be(o.wordlist)}`:a+=` -W ${be(o.wordlist)}`),o.function!==void 0&&(a+=` -F ${be(o.function)}`),o.command!==void 0&&(a+=` -C ${be(o.command)}`),o.isDefault&&(a+=" -D"),a+=`${i.startsWith("-")?" -- ":" "}${be(i)}`,r.push(a)}if(!t&&e.state.defaultCompletionSpec){let i=e.state.defaultCompletionSpec,o="complete";for(let a of i.options??[])o+=` -o ${be(a)}`;for(let a of i.actions??[])o+=` -A ${be(a)}`;i.wordlist!==void 0&&(o+=` -W ${be(i.wordlist)}`),i.function!==void 0&&(o+=` -F ${be(i.function)}`),i.command!==void 0&&(o+=` -C ${be(i.command)}`),o+=" -D",r.push(o)}return r.length===0?ee(""):ee(`${r.join(`
206
+ `,1);continue}let a="complete";if(o.options)for(let l of o.options)a+=` -o ${be(l)}`;if(o.actions)for(let l of o.actions)a+=` -A ${be(l)}`;o.wordlist!==void 0&&(o.wordlist.includes(" ")||o.wordlist.includes("'")?a+=` -W ${be(o.wordlist)}`:a+=` -W ${be(o.wordlist)}`),o.function!==void 0&&(a+=` -F ${be(o.function)}`),o.command!==void 0&&(a+=` -C ${be(o.command)}`),o.isDefault&&(a+=" -D"),a+=`${i.startsWith("-")?" -- ":" "}${be(i)}`,r.push(a)}if(!t&&e.state.defaultCompletionSpec){let i=e.state.defaultCompletionSpec,o="complete";for(let a of i.options??[])o+=` -o ${be(a)}`;for(let a of i.actions??[])o+=` -A ${be(a)}`;i.wordlist!==void 0&&(o+=` -W ${be(i.wordlist)}`),i.function!==void 0&&(o+=` -F ${be(i.function)}`),i.command!==void 0&&(o+=` -C ${be(i.command)}`),o+=" -D",r.push(o)}return r.length===0?J(""):J(`${r.join(`
202
207
  `)}
203
- `)}var Hu=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Ro(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=[],i=[],o=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-D")n=!0;else if(l==="-E")r=!0;else if(l==="-o"){if(a++,a>=t.length)return L(`compopt: -o: option requires an argument
204
- `,2);let c=t[a];if(!Hu.includes(c))return L(`compopt: ${c}: invalid option name
208
+ `)}var Ju=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function To(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=[],i=[],o=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-D")n=!0;else if(l==="-E")r=!0;else if(l==="-o"){if(a++,a>=t.length)return L(`compopt: -o: option requires an argument
209
+ `,2);let c=t[a];if(!Ju.includes(c))return L(`compopt: ${c}: invalid option name
205
210
  `,2);s.push(c)}else if(l==="+o"){if(a++,a>=t.length)return L(`compopt: +o: option requires an argument
206
- `,2);let c=t[a];if(!Hu.includes(c))return L(`compopt: ${c}: invalid option name
207
- `,2);i.push(c)}else if(l==="--"){o.push(...t.slice(a+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&o.push(l)}if(n){let a=e.state.defaultCompletionSpec??{isDefault:!0},l=new Set(a.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.defaultCompletionSpec=a,ee("")}if(r){let a=e.state.emptyCompletionSpec??Object.create(null),l=new Set(a.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.emptyCompletionSpec=a,ee("")}if(o.length>0){for(let a of o){let l=e.state.completionSpecs.get(a)??{},c=new Set(l.options??[]);for(let u of s)c.add(u);for(let u of i)c.delete(u);l.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set(a,l)}return ee("")}return L(`compopt: not currently executing completion function
208
- `,1)}function Do(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Ut;return ne}if(t.length>1)throw new q(1,"",`bash: continue: too many arguments
211
+ `,2);let c=t[a];if(!Ju.includes(c))return L(`compopt: ${c}: invalid option name
212
+ `,2);i.push(c)}else if(l==="--"){o.push(...t.slice(a+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&o.push(l)}if(n){let a=e.state.defaultCompletionSpec??{isDefault:!0},l=new Set(a.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.defaultCompletionSpec=a,J("")}if(r){let a=e.state.emptyCompletionSpec??Object.create(null),l=new Set(a.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.emptyCompletionSpec=a,J("")}if(o.length>0){for(let a of o){let l=e.state.completionSpecs.get(a)??{},c=new Set(l.options??[]);for(let u of s)c.add(u);for(let u of i)c.delete(u);l.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set(a,l)}return J("")}return L(`compopt: not currently executing completion function
213
+ `,1)}function Fo(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new qt;return ee}if(t.length>1)throw new q(1,"",`bash: continue: too many arguments
209
214
  `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new q(1,"",`bash: continue: ${t[0]}: numeric argument required
210
- `);n=r}throw new Ke(n)}function Gu(e,t){let n="";return e.state.integerVars?.has(t)&&(n+="i"),e.state.lowercaseVars?.has(t)&&(n+="l"),ce(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 Io(e){return be(e)}function Oo(e){return`'${e.replace(/'/g,"'\\''")}'`}function Zu(e,t){let n="",r="",s=!1;for(let i of t){let o=Gu(e,i);if(e.state.associativeArrays?.has(i)){let u=$t(e,i);if(u.length===0)n+=`declare -A ${i}=()
211
- `;else{let f=u.map(d=>{let p=ae(e,i,d)??"",h=Io(p);return`[${Oo(d)}]=${h}`});n+=`declare -A ${i}=(${f.join(" ")})
212
- `}continue}let l=Se(e,i);if(l.length>0){let u=l.map(f=>{let d=ae(e,i,f)??"";return`[${f}]=${pn(d)}`});n+=`declare -a ${i}=(${u.join(" ")})
215
+ `);n=r}throw new Ke(n)}function ef(e,t){let n="";return e.state.integerVars?.has(t)&&(n+="i"),e.state.lowercaseVars?.has(t)&&(n+="l"),ce(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 Mo(e){return be(e)}function Bo(e){return`'${e.replace(/'/g,"'\\''")}'`}function tf(e,t){let n="",r="",s=!1;for(let i of t){let o=ef(e,i);if(e.state.associativeArrays?.has(i)){let u=Ct(e,i);if(u.length===0)n+=`declare -A ${i}=()
216
+ `;else{let f=u.map(d=>{let p=oe(e,i,d)??"",h=Mo(p);return`[${Bo(d)}]=${h}`});n+=`declare -A ${i}=(${f.join(" ")})
217
+ `}continue}let l=Se(e,i);if(l.length>0){let u=l.map(f=>{let d=oe(e,i,f)??"";return`[${f}]=${mn(d)}`});n+=`declare -a ${i}=(${u.join(" ")})
213
218
  `;continue}if(Ce(e,i)){n+=`declare -a ${i}=()
214
- `;continue}let c=e.state.env.get(i);if(c!==void 0)n+=`declare ${o} ${i}=${br(c)}
219
+ `;continue}let c=e.state.env.get(i);if(c!==void 0)n+=`declare ${o} ${i}=${vr(c)}
215
220
  `;else{let u=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);u||f?n+=`declare ${o} ${i}
216
221
  `:(r+=`bash: declare: ${i}: not found
217
- `,s=!0)}}return T(n,r,s?1:0)}function Qu(e,t){let{filterExport:n,filterReadonly:r,filterNameref:s,filterIndexedArray:i,filterAssocArray:o}=t,a=n||r||s||i||o,l="",c=new Set;for(let f of e.state.env.keys())f.startsWith("BASH_")||c.add(f);for(let f of e.state.arrays?.keys()??[])c.add(f);if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())c.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)c.add(f);let u=Array.from(c).sort();for(let f of u){let d=Gu(e,f),p=e.state.associativeArrays?.has(f),h=Se(e,f),y=!p&&Ce(e,f);if(a&&(o&&!p||i&&!y||n&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||s&&!ce(e,f)))continue;if(p){let S=$t(e,f);if(S.length===0)l+=`declare -A ${f}=()
218
- `;else{let g=S.map(m=>{let b=ae(e,f,m)??"",A=Io(b);return`[${Oo(m)}]=${A}`});l+=`declare -A ${f}=(${g.join(" ")})
219
- `}continue}if(h.length>0){let S=h.map(g=>{let m=ae(e,f,g)??"";return`[${g}]=${pn(m)}`});l+=`declare -a ${f}=(${S.join(" ")})
222
+ `,s=!0)}}return T(n,r,s?1:0)}function nf(e,t){let{filterExport:n,filterReadonly:r,filterNameref:s,filterIndexedArray:i,filterAssocArray:o}=t,a=n||r||s||i||o,l="",c=new Set;for(let f of e.state.env.keys())f.startsWith("BASH_")||c.add(f);for(let f of e.state.arrays?.keys()??[])c.add(f);if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())c.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)c.add(f);let u=Array.from(c).sort();for(let f of u){let d=ef(e,f),p=e.state.associativeArrays?.has(f),h=Se(e,f),y=!p&&Ce(e,f);if(a&&(o&&!p||i&&!y||n&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||s&&!ce(e,f)))continue;if(p){let S=Ct(e,f);if(S.length===0)l+=`declare -A ${f}=()
223
+ `;else{let m=S.map(g=>{let b=oe(e,f,g)??"",v=Mo(b);return`[${Bo(g)}]=${v}`});l+=`declare -A ${f}=(${m.join(" ")})
224
+ `}continue}if(h.length>0){let S=h.map(m=>{let g=oe(e,f,m)??"";return`[${m}]=${mn(g)}`});l+=`declare -a ${f}=(${S.join(" ")})
220
225
  `;continue}if(Ce(e,f)){l+=`declare -a ${f}=()
221
- `;continue}let E=e.state.env.get(f);E!==void 0&&(l+=`declare ${d} ${f}=${br(E)}
222
- `)}return ee(l)}function Ku(e){let t="",n=Array.from(e.state.associativeArrays??[]).sort();for(let r of n){let s=$t(e,r);if(s.length===0)t+=`declare -A ${r}=()
223
- `;else{let i=s.map(o=>{let a=ae(e,r,o)??"",l=Io(a);return`[${Oo(o)}]=${l}`});t+=`declare -A ${r}=(${i.join(" ")})
224
- `}}return ee(t)}function Xu(e){let t="",n=new Set(Array.from(e.state.arrays??[]).filter(([,s])=>s.kind==="indexed").map(([s])=>s)),r=Array.from(n).sort();for(let s of r){let i=Se(e,s);if(i.length===0)t+=`declare -a ${s}=()
225
- `;else{let o=i.map(a=>{let l=ae(e,s,a)??"";return`[${a}]=${pn(l)}`});t+=`declare -a ${s}=(${o.join(" ")})
226
- `}}return ee(t)}function Yu(e){let t="",n=new Set;for(let s of e.state.env.keys())s.startsWith("BASH_")||n.add(s);let r=Array.from(n).sort();for(let s of r){if(e.state.associativeArrays?.has(s)||Se(e,s).length>0||Ce(e,s))continue;let a=e.state.env.get(s);a!==void 0&&(t+=`${s}=${be(a)}
227
- `)}return ee(t)}function _o(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function Sr(e,t){return e.state.integerVars?.has(t)??!1}function Lo(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function rm(e,t){return e.state.lowercaseVars?.has(t)??!1}function To(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function sm(e,t){return e.state.uppercaseVars?.has(t)??!1}function Kn(e,t,n){return rm(e,t)?n.toLowerCase():sm(e,t)?n.toUpperCase():n}async function Ju(e,t){try{let n=new H,r=se(n,t),s=await Y(e,r.expression);return String(s)}catch{return"0"}}function im(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 zs(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!1,f=!1,d=!1,p=!1,h=!1,y=!1,E=!1,S=!1,g=[];for(let k=0;k<t.length;k++){let C=t[k];if(C==="-a")r=!0;else if(C==="-A")s=!0;else if(C==="-r")i=!0;else if(C==="-x")o=!0;else if(C==="-p")a=!0;else if(C==="-n")l=!0;else if(C==="+n")c=!0;else if(C==="+a")u=!0;else if(C==="+x")f=!0;else if(C==="--"){g.push(...t.slice(k+1));break}else if(C.startsWith("+")){for(let I of C.slice(1))if(I==="n")c=!0;else if(I==="a")u=!0;else if(I==="x")f=!0;else if(I!=="r"){if(I!=="i"){if(!(I==="f"||I==="F"))return T("",`bash: typeset: +${I}: invalid option
226
+ `;continue}let E=e.state.env.get(f);E!==void 0&&(l+=`declare ${d} ${f}=${vr(E)}
227
+ `)}return J(l)}function rf(e){let t="",n=Array.from(e.state.associativeArrays??[]).sort();for(let r of n){let s=Ct(e,r);if(s.length===0)t+=`declare -A ${r}=()
228
+ `;else{let i=s.map(o=>{let a=oe(e,r,o)??"",l=Mo(a);return`[${Bo(o)}]=${l}`});t+=`declare -A ${r}=(${i.join(" ")})
229
+ `}}return J(t)}function sf(e){let t="",n=new Set(Array.from(e.state.arrays??[]).filter(([,s])=>s.kind==="indexed").map(([s])=>s)),r=Array.from(n).sort();for(let s of r){let i=Se(e,s);if(i.length===0)t+=`declare -a ${s}=()
230
+ `;else{let o=i.map(a=>{let l=oe(e,s,a)??"";return`[${a}]=${mn(l)}`});t+=`declare -a ${s}=(${o.join(" ")})
231
+ `}}return J(t)}function of(e){let t="",n=new Set;for(let s of e.state.env.keys())s.startsWith("BASH_")||n.add(s);let r=Array.from(n).sort();for(let s of r){if(e.state.associativeArrays?.has(s)||Se(e,s).length>0||Ce(e,s))continue;let a=e.state.env.get(s);a!==void 0&&(t+=`${s}=${be(a)}
232
+ `)}return J(t)}function Wo(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function xr(e,t){return e.state.integerVars?.has(t)??!1}function Vo(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function fm(e,t){return e.state.lowercaseVars?.has(t)??!1}function zo(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function dm(e,t){return e.state.uppercaseVars?.has(t)??!1}function Yn(e,t,n){return fm(e,t)?n.toLowerCase():dm(e,t)?n.toUpperCase():n}async function af(e,t){try{let n=new H,r=ne(n,t),s=await Y(e,r.expression);return String(s)}catch{return"0"}}function pm(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 js(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!1,f=!1,d=!1,p=!1,h=!1,y=!1,E=!1,S=!1,m=[];for(let k=0;k<t.length;k++){let C=t[k];if(C==="-a")r=!0;else if(C==="-A")s=!0;else if(C==="-r")i=!0;else if(C==="-x")o=!0;else if(C==="-p")a=!0;else if(C==="-n")l=!0;else if(C==="+n")c=!0;else if(C==="+a")u=!0;else if(C==="+x")f=!0;else if(C==="--"){m.push(...t.slice(k+1));break}else if(C.startsWith("+")){for(let I of C.slice(1))if(I==="n")c=!0;else if(I==="a")u=!0;else if(I==="x")f=!0;else if(I!=="r"){if(I!=="i"){if(!(I==="f"||I==="F"))return T("",`bash: typeset: +${I}: invalid option
228
233
  `,2)}}}else if(C==="-i")d=!0;else if(C==="-l")p=!0;else if(C==="-u")h=!0;else if(C==="-f")y=!0;else if(C==="-F")E=!0;else if(C==="-g")S=!0;else if(C.startsWith("-"))for(let I of C.slice(1))if(I==="a")r=!0;else if(I==="A")s=!0;else if(I==="r")i=!0;else if(I==="x")o=!0;else if(I==="p")a=!0;else if(I==="n")l=!0;else if(I==="i")d=!0;else if(I==="l")p=!0;else if(I==="u")h=!0;else if(I==="f")y=!0;else if(I==="F")E=!0;else if(I==="g")S=!0;else return T("",`bash: typeset: -${I}: invalid option
229
- `,2);else g.push(C)}let b=e.state.localScopes.length>0&&!S,A=k=>{if(!b)return;let C=e.state.localScopes[e.state.localScopes.length-1];C.has(k)||C.set(k,e.state.env.get(k))},x=k=>{if(!b)return;let C=e.state.localScopes[e.state.localScopes.length-1];for(C.has(k)||C.set(k,e.state.env.get(k)),e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let I=e.state.localArrayScopes.at(-1);if(I&&!I.has(k)){let W=xe(e,k);I.set(k,W?Me(W):void 0)}},v=k=>{b&&ln(e,k)};if(E){if(g.length===0){let I=Array.from(e.state.functions.keys()).sort(),W="";for(let Z of I)W+=`declare -f ${Z}
230
- `;return ee(W)}let k=!0,C="";for(let I of g)e.state.functions.has(I)?C+=`${I}
231
- `:k=!1;return T(C,"",k?0:1)}if(y){if(g.length===0){let C="",I=Array.from(e.state.functions.keys()).sort();for(let W of I)C+=`${W} ()
234
+ `,2);else m.push(C)}let b=e.state.localScopes.length>0&&!S,v=k=>{if(!b)return;let C=e.state.localScopes[e.state.localScopes.length-1];C.has(k)||C.set(k,e.state.env.get(k))},x=k=>{if(!b)return;let C=e.state.localScopes[e.state.localScopes.length-1];for(C.has(k)||C.set(k,e.state.env.get(k)),e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let I=e.state.localArrayScopes.at(-1);if(I&&!I.has(k)){let W=xe(e,k);I.set(k,W?Me(W):void 0)}},A=k=>{b&&un(e,k)};if(E){if(m.length===0){let I=Array.from(e.state.functions.keys()).sort(),W="";for(let Z of I)W+=`declare -f ${Z}
235
+ `;return J(W)}let k=!0,C="";for(let I of m)e.state.functions.has(I)?C+=`${I}
236
+ `:k=!1;return T(C,"",k?0:1)}if(y){if(m.length===0){let C="",I=Array.from(e.state.functions.keys()).sort();for(let W of I)C+=`${W} ()
232
237
  {
233
238
  # function body
234
239
  }
235
- `;return ee(C)}let k=!0;for(let C of g)e.state.functions.has(C)||(k=!1);return T("","",k?0:1)}if(a&&g.length>0)return Zu(e,g);if(a&&g.length===0)return Qu(e,{filterExport:o,filterReadonly:i,filterNameref:l,filterIndexedArray:r,filterAssocArray:s});if(g.length===0&&s&&!a)return Ku(e);if(g.length===0&&r&&!a)return Xu(e);if(g.length===0&&!a)return Yu(e);let $="",D=0;for(let k of g){let C=k.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(C&&!u){let R=C[1],V=C[2],z=ue(e,R);if(z)return z;if(s&&Se(e,R).length>0){$+=`bash: declare: ${R}: cannot convert indexed to associative array
236
- `,D=1;continue}if((r||!s&&!r)&&e.state.associativeArrays?.has(R)){$+=`bash: declare: ${R}: cannot convert associative to indexed array
237
- `,D=1;continue}let O=s&&V.includes("[")?Ns(V,n):void 0,_=O===void 0?Bt(V,{...n,maxElements:s?n.maxElements*2:n.maxElements}):void 0;if(e.executionScope.consumeWork(O?.length??_?.length??0,"declare array assignment"),x(R),s?(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(R),Qt(e,R,"associative")):Qt(e,R,"indexed"),ge(e,R),e.state.env.delete(R),s&&V.includes("["))for(let[M,re]of O??[])j(e,R,M,rn(e,re),"associative");else if(s){let M=_??[];for(let re=0;re<M.length;re+=2){let K=M[re],Oe=re+1<M.length?M[re+1]:"";j(e,R,K,Oe,"associative")}}else{let M=_??[];if(M.some(K=>/^\[[^\]]+\]=/.test(K))){let K=0;for(let Oe of M){let ft=Oe.match(/^\[([^\]]+)\]=(.*)$/);if(ft){let Ot=ft[1],dt=ft[2],pt;if(/^-?\d+$/.test(Ot))pt=Number.parseInt(Ot,10);else try{let _t=new H,rd=se(_t,Ot);pt=await Y(e,rd.expression)}catch{pt=0}j(e,R,pt,rn(e,dt)),K=pt+1}else j(e,R,K,Oe),K++}}else for(let K=0;K<M.length;K++)j(e,R,K,M[K])}v(R),i&&Ze(e,R),o&&wt(e,R);continue}if(c){let R=k.includes("=")?k.slice(0,k.indexOf("=")):k;if(Zl(e,R),!k.includes("="))continue}if(f){let R=k.includes("=")?k.slice(0,k.indexOf("=")):k;if(as(e,R),!k.includes("="))continue}let I=im(k);if(I){let{name:R,indexExpr:V,value:z}=I,O=ue(e,R);if(O)return O;x(R);let _;try{let M=new H,re=se(M,V);_=await Y(e,re.expression)}catch{let M=parseInt(V,10);_=Number.isNaN(M)?0:M}j(e,R,_,z),v(R),i&&Ze(e,R),o&&wt(e,R);continue}let W=k.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(W&&!u){let R=W[1],V=W[2],z=ue(e,R);if(z)return z;x(R);let O=Bt(V,n);if(e.state.associativeArrays?.has(R)){let _=Ns(V,n);e.executionScope.consumeWork(_.length,"declare array append"),wn(e,R,_.map(([M])=>M));for(let[M,re]of _)j(e,R,M,re,"associative")}else{e.executionScope.consumeWork(O.length,"declare array append");let _=Se(e,R),M=0,re=e.state.env.get(R);_.length===0&&re!==void 0?(j(e,R,0,re),e.state.env.delete(R),M=1):_.length>0&&(M=Math.max(..._)+1),wn(e,R,Array.from({length:O.length},(K,Oe)=>M+Oe));for(let K=0;K<O.length;K++)j(e,R,M+K,O[K])}v(R),i&&Ze(e,R),o&&wt(e,R);continue}let Z=k.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(Z){let R=Z[1],V=Z[2],z=ue(e,R);if(z)return z;A(R),d&&_o(e,R),p&&Lo(e,R),h&&To(e,R);let _=Se(e,R).length>0||e.state.associativeArrays?.has(R);if(Sr(e,R)){let M=e.state.env.get(R)??"0",re=parseInt(M,10)||0,K=parseInt(await Ju(e,V),10)||0;V=String(re+K),e.state.env.set(R,V)}else if(_){V=Kn(e,R,V);let M=ae(e,R,0)??"";j(e,R,0,qt([M,V],"",e.limits.maxStringLength,"declare append"))}else{V=Kn(e,R,V);let M=e.state.env.get(R)??"";e.state.env.set(R,qt([M,V],"",e.limits.maxStringLength,"declare append"))}v(R),i&&Ze(e,R),o&&wt(e,R),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(R));continue}if(k.includes("=")){let R=k.indexOf("="),V=k.slice(0,R),z=k.slice(R+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(V)){$+=`bash: typeset: \`${V}': not a valid identifier
238
- `,D=1;continue}let O=ue(e,V);if(O)return O;if(A(V),l){if(z!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(z)){$+=`bash: declare: \`${z}': invalid variable name for name reference
239
- `,D=1;continue}e.state.env.set(V,z),Mt(e,V),z!==""&&rs(e,z)&&zi(e,V),v(V),i&&Ze(e,V),o&&wt(e,V);continue}if(d&&_o(e,V),p&&Lo(e,V),h&&To(e,V),Sr(e,V)&&(z=await Ju(e,z)),z=Kn(e,V,z),ce(e,V)){let _=Be(e,V);_&&_!==V?e.state.env.set(_,z):e.state.env.set(V,z)}else e.state.env.set(V,z);v(V),i&&Ze(e,V),o&&wt(e,V),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(V))}else{let R=k;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(R)){$+=`bash: typeset: \`${R}': not a valid identifier
240
- `,D=1;continue}if(r||s?x(R):A(R),l){Mt(e,R);let z=e.state.env.get(R);z!==void 0&&z!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(z)?Ql(e,R):z&&rs(e,z)&&zi(e,R),v(R),i&&Ze(e,R),o&&wt(e,R);continue}if(d&&_o(e,R),p&&Lo(e,R),h&&To(e,R),s){if(Se(e,R).length>0){$+=`bash: declare: ${R}: cannot convert indexed to associative array
241
- `,D=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(R),Qt(e,R,"associative")}let V=Ce(e,R);!e.state.env.has(R)&&!V&&(r||s?Qt(e,R,s?"associative":"indexed"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(R))),v(R),i&&Ze(e,R),o&&wt(e,R)}}return T("",$,D)}async function Fo(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-a")r=!0;else if(l==="-A")s=!0;else if(l==="-p")i=!0;else if(l==="--"){o.push(...t.slice(a+1));break}else l.startsWith("-")||o.push(l)}if(o.length===0){let a="",l=Array.from(e.state.readonlyVars||[]).sort();for(let c of l){let u=e.state.env.get(c);if(u!==void 0){let f=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${c}="${f}"
242
- `}}return ee(a)}for(let a of o){let l=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(l){let d=l[1],p=l[2],h=ue(e,d);if(h)return h;let y=Bt(p,n);if(e.state.associativeArrays?.has(d)){let E=Ns(p,n);e.executionScope.consumeWork(E.length,"readonly array append"),wn(e,d,E.map(([S])=>S));for(let[S,g]of E)j(e,d,S,g,"associative")}else{e.executionScope.consumeWork(y.length,"readonly array append");let E=Se(e,d),S=0,g=e.state.env.get(d);E.length===0&&g!==void 0?(j(e,d,0,g),e.state.env.delete(d),S=1):E.length>0&&(S=Math.max(...E)+1),wn(e,d,Array.from({length:y.length},(m,b)=>S+b));for(let m=0;m<y.length;m++)j(e,d,S+m,y[m])}Ze(e,d);continue}let c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c){let d=c[1],p=c[2],h=ue(e,d);if(h)return h;let y=e.state.env.get(d)??"";e.state.env.set(d,qt([y,p],"",e.limits.maxStringLength,"readonly append")),Ze(e,d);continue}let u=$u(a,n);if(u.value===void 0&&!u.isArray){Ze(e,u.name);continue}let f=await Pu(e,u,{makeReadonly:!0});if(f)return f}return ne}function Mo(e){return e.state.directoryStack??=[],e.state.directoryStack}function Ar(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function om(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 Bo(e,t){let n=Mo(e),r;for(let a=0;a<t.length;a++){let l=t[a];if(l==="--"){if(a+1<t.length){if(r!==void 0)return L(`bash: pushd: too many arguments
240
+ `;return J(C)}let k=!0;for(let C of m)e.state.functions.has(C)||(k=!1);return T("","",k?0:1)}if(a&&m.length>0)return tf(e,m);if(a&&m.length===0)return nf(e,{filterExport:o,filterReadonly:i,filterNameref:l,filterIndexedArray:r,filterAssocArray:s});if(m.length===0&&s&&!a)return rf(e);if(m.length===0&&r&&!a)return sf(e);if(m.length===0&&!a)return of(e);let $="",R=0;for(let k of m){let C=k.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(C&&!u){let D=C[1],V=C[2],U=ue(e,D);if(U)return U;if(s&&Se(e,D).length>0){$+=`bash: declare: ${D}: cannot convert indexed to associative array
241
+ `,R=1;continue}if((r||!s&&!r)&&e.state.associativeArrays?.has(D)){$+=`bash: declare: ${D}: cannot convert associative to indexed array
242
+ `,R=1;continue}let O=s&&V.includes("[")?Is(V,n):void 0,_=O===void 0?Wt(V,{...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),Kt(e,D,"associative")):Kt(e,D,"indexed"),ge(e,D),e.state.env.delete(D),s&&V.includes("["))for(let[B,te]of O??[])j(e,D,B,on(e,te),"associative");else if(s){let B=_??[];for(let te=0;te<B.length;te+=2){let X=B[te],Oe=te+1<B.length?B[te+1]:"";j(e,D,X,Oe,"associative")}}else{let B=_??[];if(B.some(X=>/^\[[^\]]+\]=/.test(X))){let X=0;for(let Oe of B){let dt=Oe.match(/^\[([^\]]+)\]=(.*)$/);if(dt){let Lt=dt[1],pt=dt[2],ht;if(/^-?\d+$/.test(Lt))ht=Number.parseInt(Lt,10);else try{let Tt=new H,ud=ne(Tt,Lt);ht=await Y(e,ud.expression)}catch{ht=0}j(e,D,ht,on(e,pt)),X=ht+1}else j(e,D,X,Oe),X++}}else for(let X=0;X<B.length;X++)j(e,D,X,B[X])}A(D),i&&Ze(e,D),o&&bt(e,D);continue}if(c){let D=k.includes("=")?k.slice(0,k.indexOf("=")):k;if(nc(e,D),!k.includes("="))continue}if(f){let D=k.includes("=")?k.slice(0,k.indexOf("=")):k;if(us(e,D),!k.includes("="))continue}let I=pm(k);if(I){let{name:D,indexExpr:V,value:U}=I,O=ue(e,D);if(O)return O;x(D);let _;try{let B=new H,te=ne(B,V);_=await Y(e,te.expression)}catch{let B=parseInt(V,10);_=Number.isNaN(B)?0:B}j(e,D,_,U),A(D),i&&Ze(e,D),o&&bt(e,D);continue}let W=k.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(W&&!u){let D=W[1],V=W[2],U=ue(e,D);if(U)return U;x(D);let O=Wt(V,n);if(e.state.associativeArrays?.has(D)){let _=Is(V,n);e.executionScope.consumeWork(_.length,"declare array append"),Sn(e,D,_.map(([B])=>B));for(let[B,te]of _)j(e,D,B,te,"associative")}else{e.executionScope.consumeWork(O.length,"declare array append");let _=Se(e,D),B=0,te=e.state.env.get(D);_.length===0&&te!==void 0?(j(e,D,0,te),e.state.env.delete(D),B=1):_.length>0&&(B=Math.max(..._)+1),Sn(e,D,Array.from({length:O.length},(X,Oe)=>B+Oe));for(let X=0;X<O.length;X++)j(e,D,B+X,O[X])}A(D),i&&Ze(e,D),o&&bt(e,D);continue}let Z=k.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(Z){let D=Z[1],V=Z[2],U=ue(e,D);if(U)return U;v(D),d&&Wo(e,D),p&&Vo(e,D),h&&zo(e,D);let _=Se(e,D).length>0||e.state.associativeArrays?.has(D);if(xr(e,D)){let B=e.state.env.get(D)??"0",te=parseInt(B,10)||0,X=parseInt(await af(e,V),10)||0;V=String(te+X),e.state.env.set(D,V)}else if(_){V=Yn(e,D,V);let B=oe(e,D,0)??"";j(e,D,0,jt([B,V],"",e.limits.maxStringLength,"declare append"))}else{V=Yn(e,D,V);let B=e.state.env.get(D)??"";e.state.env.set(D,jt([B,V],"",e.limits.maxStringLength,"declare append"))}A(D),i&&Ze(e,D),o&&bt(e,D),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(D));continue}if(k.includes("=")){let D=k.indexOf("="),V=k.slice(0,D),U=k.slice(D+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(V)){$+=`bash: typeset: \`${V}': not a valid identifier
243
+ `,R=1;continue}let O=ue(e,V);if(O)return O;if(v(V),l){if(U!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(U)){$+=`bash: declare: \`${U}': invalid variable name for name reference
244
+ `,R=1;continue}e.state.env.set(V,U),Bt(e,V),U!==""&&os(e,U)&&Hi(e,V),A(V),i&&Ze(e,V),o&&bt(e,V);continue}if(d&&Wo(e,V),p&&Vo(e,V),h&&zo(e,V),xr(e,V)&&(U=await af(e,U)),U=Yn(e,V,U),ce(e,V)){let _=Be(e,V);_&&_!==V?e.state.env.set(_,U):e.state.env.set(V,U)}else e.state.env.set(V,U);A(V),i&&Ze(e,V),o&&bt(e,V),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(V))}else{let D=k;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(D)){$+=`bash: typeset: \`${D}': not a valid identifier
245
+ `,R=1;continue}if(r||s?x(D):v(D),l){Bt(e,D);let U=e.state.env.get(D);U!==void 0&&U!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(U)?rc(e,D):U&&os(e,U)&&Hi(e,D),A(D),i&&Ze(e,D),o&&bt(e,D);continue}if(d&&Wo(e,D),p&&Vo(e,D),h&&zo(e,D),s){if(Se(e,D).length>0){$+=`bash: declare: ${D}: cannot convert indexed to associative array
246
+ `,R=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(D),Kt(e,D,"associative")}let V=Ce(e,D);!e.state.env.has(D)&&!V&&(r||s?Kt(e,D,s?"associative":"indexed"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(D))),A(D),i&&Ze(e,D),o&&bt(e,D)}}return T("",$,R)}async function Uo(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-a")r=!0;else if(l==="-A")s=!0;else if(l==="-p")i=!0;else if(l==="--"){o.push(...t.slice(a+1));break}else l.startsWith("-")||o.push(l)}if(o.length===0){let a="",l=Array.from(e.state.readonlyVars||[]).sort();for(let c of l){let u=e.state.env.get(c);if(u!==void 0){let f=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${c}="${f}"
247
+ `}}return J(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 y=Wt(p,n);if(e.state.associativeArrays?.has(d)){let E=Is(p,n);e.executionScope.consumeWork(E.length,"readonly array append"),Sn(e,d,E.map(([S])=>S));for(let[S,m]of E)j(e,d,S,m,"associative")}else{e.executionScope.consumeWork(y.length,"readonly array append");let E=Se(e,d),S=0,m=e.state.env.get(d);E.length===0&&m!==void 0?(j(e,d,0,m),e.state.env.delete(d),S=1):E.length>0&&(S=Math.max(...E)+1),Sn(e,d,Array.from({length:y.length},(g,b)=>S+b));for(let g=0;g<y.length;g++)j(e,d,S+g,y[g])}Ze(e,d);continue}let c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c){let d=c[1],p=c[2],h=ue(e,d);if(h)return h;let y=e.state.env.get(d)??"";e.state.env.set(d,jt([y,p],"",e.limits.maxStringLength,"readonly append")),Ze(e,d);continue}let u=Ou(a,n);if(u.value===void 0&&!u.isArray){Ze(e,u.name);continue}let f=await _u(e,u,{makeReadonly:!0});if(f)return f}return ee}function qo(e){return e.state.directoryStack??=[],e.state.directoryStack}function kr(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function hm(e){let t=e.split("/").filter(r=>r&&r!=="."),n=[];for(let r of t)r===".."?n.pop():n.push(r);return`/${n.join("/")}`}async function jo(e,t){let n=qo(e),r;for(let a=0;a<t.length;a++){let l=t[a];if(l==="--"){if(a+1<t.length){if(r!==void 0)return L(`bash: pushd: too many arguments
243
248
  `,2);r=t[a+1],a++}}else{if(l.startsWith("-")&&l!=="-")return L(`bash: pushd: ${l}: invalid option
244
249
  `,2);if(r!==void 0)return L(`bash: pushd: too many arguments
245
250
  `,2);r=l}}if(r===void 0){if(n.length<2)return L(`bash: pushd: no other directory
246
- `,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=om(s);try{if(!(await e.fs.stat(s)).isDirectory)return L(`bash: pushd: ${r}: Not a directory
251
+ `,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=hm(s);try{if(!(await e.fs.stat(s)).isDirectory)return L(`bash: pushd: ${r}: Not a directory
247
252
  `,1)}catch{return L(`bash: pushd: ${r}: No such file or directory
248
- `,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=>Ar(a,i)).join(" ")}
249
- `;return ee(o)}function Wo(e,t){let n=Mo(e);for(let o of t)if(o!=="--")return o.startsWith("-")&&o!=="-"?L(`bash: popd: ${o}: invalid option
253
+ `,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=>kr(a,i)).join(" ")}
254
+ `;return J(o)}function Ho(e,t){let n=qo(e);for(let o of t)if(o!=="--")return o.startsWith("-")&&o!=="-"?L(`bash: popd: ${o}: invalid option
250
255
  `,2):L(`bash: popd: too many arguments
251
256
  `,2);if(n.length===0)return L(`bash: popd: directory stack empty
252
257
  `,1);let r=n.shift();if(!r)return L(`bash: popd: directory stack empty
253
- `,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=>Ar(o,s)).join(" ")}
254
- `;return ee(i)}function Vo(e,t){let n=Mo(e),r=!1,s=!1,i=!1,o=!1;for(let u of t)if(u!=="--")if(u.startsWith("-"))for(let f of u.slice(1))if(f==="c")r=!0;else if(f==="l")s=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,o=!0;else return L(`bash: dirs: -${f}: invalid option
258
+ `,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=>kr(o,s)).join(" ")}
259
+ `;return J(i)}function Go(e,t){let n=qo(e),r=!1,s=!1,i=!1,o=!1;for(let u of t)if(u!=="--")if(u.startsWith("-"))for(let f of u.slice(1))if(f==="c")r=!0;else if(f==="l")s=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,o=!0;else return L(`bash: dirs: -${f}: invalid option
255
260
  `,2);else return L(`bash: dirs: too many arguments
256
- `,1);if(r)return e.state.directoryStack=[],ne;let a=[e.state.cwd,...n],l=e.state.env.get("HOME")||"",c;return o?(c=a.map((u,f)=>{let d=s?u:Ar(u,l);return` ${f} ${d}`}).join(`
261
+ `,1);if(r)return e.state.directoryStack=[],ee;let a=[e.state.cwd,...n],l=e.state.env.get("HOME")||"",c;return o?(c=a.map((u,f)=>{let d=s?u:kr(u,l);return` ${f} ${d}`}).join(`
257
262
  `),c+=`
258
- `):i?c=a.map(u=>s?u:Ar(u,l)).join(`
263
+ `):i?c=a.map(u=>s?u:kr(u,l)).join(`
259
264
  `)+`
260
- `:c=a.map(u=>s?u:Ar(u,l)).join(" ")+`
261
- `,ee(c)}async function zo(e,t,n,r=!1){let s=t;if(s.length>0){let l=s[0];if(l==="--")s=s.slice(1);else if(l.startsWith("-")&&l!=="-"&&l.length>1)return L(`bash: eval: ${l}: invalid option
265
+ `:c=a.map(u=>s?u:kr(u,l)).join(" ")+`
266
+ `,J(c)}async function Zo(e,t,n,r=!1){let s=t;if(s.length>0){let l=s[0];if(l==="--")s=s.slice(1);else if(l.startsWith("-")&&l!=="-"&&l.length>1)return L(`bash: eval: ${l}: invalid option
262
267
  eval: usage: eval [arg ...]
263
- `,2)}if(s.length===0)return ne;let i=s.join(" ");if(i.trim()==="")return ne;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 Qe||l instanceof Ke||l instanceof _e||l instanceof q||l instanceof Pe)throw l;if(l.name==="ParseException")return L(`bash: eval: ${l.message}
264
- `);throw l}finally{(a||o!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=o)}}function Uo(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
265
- `,n=2;else{let i=BigInt(s);n=Number((i%256n+256n)%256n)}}throw new q(n,"",r)}function qo(e,t){let n=!1,r=[];for(let o of t)o==="-n"?n=!0:o==="-p"||o==="--"||r.push(o);if(r.length===0&&!n){let o="",a=e.state.exportedVars??new Set,l=Array.from(a).sort();for(let c of l){let u=e.state.env.get(c);u!==void 0&&(o+=`declare -x ${c}=${br(u)}
266
- `)}return ee(o)}if(n){for(let o of r){let a,l;if(o.includes("=")){let c=o.indexOf("=");a=o.slice(0,c),l=o.slice(c+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return T("",`bash: export: \`${o}': not a valid identifier
267
- `,1);l!==void 0&&(ue(e,a),e.state.env.set(a,l)),as(e,a)}return ne}let s="",i=0;for(let o of r){let a,l,c=!1,u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(u)a=u[1],l=u[2],c=!0;else if(o.includes("=")){let f=o.indexOf("=");a=o.slice(0,f),l=o.slice(f+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){s+=`bash: export: \`${o}': not a valid identifier
268
- `,i=1;continue}if(l!==void 0)if(ue(e,a),c){let f=e.state.env.get(a)??"";e.state.env.set(a,f+l)}else e.state.env.set(a,l);else e.state.env.has(a)||e.state.env.set(a,"");wt(e,a)}return T("",s,i)}function Us(e,t){if(t.length<2)return L(`bash: getopts: usage: getopts optstring name [arg ...]
269
- `);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 y=Number.parseInt(e.state.env.get("#")||"0",10);a=[];for(let E=1;E<=y;E++)a.push(e.state.env.get(String(E))||"")}let l=Number.parseInt(e.state.env.get("OPTIND")||"1",10);l<1&&(l=1);let c=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),l>a.length)return s||e.state.env.set(r,"?"),e.state.env.set("OPTIND",String(a.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:1,stdout:"",stderr:""};let u=a[l-1];if(!u||u==="-"||!u.startsWith("-"))return s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};if(u==="--")return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};let f=c===0?1:c,d=u[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),Us(e,t);let p=o.indexOf(d);if(p===-1){let y="";return i?e.state.env.set("OPTARG",d):y=`bash: illegal option -- ${d}
268
+ `,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=lt(i);return await e.executeScript(l)}catch(l){if(l instanceof Qe||l instanceof Ke||l instanceof _e||l instanceof q||l instanceof Pe)throw l;if(l.name==="ParseException")return L(`bash: eval: ${l.message}
269
+ `);throw l}finally{(a||o!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=o)}}function Qo(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
270
+ `,n=2;else{let i=BigInt(s);n=Number((i%256n+256n)%256n)}}throw new q(n,"",r)}function Ko(e,t){let n=!1,r=[];for(let o of t)o==="-n"?n=!0:o==="-p"||o==="--"||r.push(o);if(r.length===0&&!n){let o="",a=e.state.exportedVars??new Set,l=Array.from(a).sort();for(let c of l){let u=e.state.env.get(c);u!==void 0&&(o+=`declare -x ${c}=${vr(u)}
271
+ `)}return J(o)}if(n){for(let o of r){let a,l;if(o.includes("=")){let c=o.indexOf("=");a=o.slice(0,c),l=o.slice(c+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return T("",`bash: export: \`${o}': not a valid identifier
272
+ `,1);l!==void 0&&(ue(e,a),e.state.env.set(a,l)),us(e,a)}return ee}let s="",i=0;for(let o of r){let a,l,c=!1,u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(u)a=u[1],l=u[2],c=!0;else if(o.includes("=")){let f=o.indexOf("=");a=o.slice(0,f),l=o.slice(f+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){s+=`bash: export: \`${o}': not a valid identifier
273
+ `,i=1;continue}if(l!==void 0)if(ue(e,a),c){let f=e.state.env.get(a)??"";e.state.env.set(a,f+l)}else e.state.env.set(a,l);else e.state.env.has(a)||e.state.env.set(a,"");bt(e,a)}return T("",s,i)}function Hs(e,t){if(t.length<2)return L(`bash: getopts: usage: getopts optstring name [arg ...]
274
+ `);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 y=Number.parseInt(e.state.env.get("#")||"0",10);a=[];for(let E=1;E<=y;E++)a.push(e.state.env.get(String(E))||"")}let l=Number.parseInt(e.state.env.get("OPTIND")||"1",10);l<1&&(l=1);let c=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),l>a.length)return s||e.state.env.set(r,"?"),e.state.env.set("OPTIND",String(a.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:1,stdout:"",stderr:""};let u=a[l-1];if(!u||u==="-"||!u.startsWith("-"))return s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};if(u==="--")return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};let f=c===0?1:c,d=u[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),Hs(e,t);let p=o.indexOf(d);if(p===-1){let y="";return i?e.state.env.set("OPTARG",d):y=`bash: illegal option -- ${d}
270
275
  `,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:y}}if(p+1<o.length&&o[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>=a.length){let y="";return i?(e.state.env.set("OPTARG",d),s||e.state.env.set(r,":")):(y=`bash: option requires an argument -- ${d}
271
- `,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:y}}e.state.env.set("OPTARG",a[l]),e.state.env.set("OPTIND",String(l+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1<u.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return s||e.state.env.set(r,d),{exitCode:s?2:0,stdout:"",stderr:""}}async function jo(e,t){e.state.hashTable||(e.state.hashTable=new Map);let n=!1,r=!1,s=!1,i=!1,o=!1,a="",l=[],c=0;for(;c<t.length;){let 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")o=!0,c++;else if(h==="-p"){if(i=!0,c++,c>=t.length)return L(`bash: hash: -p: option requires an argument
276
+ `,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:y}}e.state.env.set("OPTARG",a[l]),e.state.env.set("OPTIND",String(l+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1<u.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return s||e.state.env.set(r,d),{exitCode:s?2:0,stdout:"",stderr:""}}async function Xo(e,t){e.state.hashTable||(e.state.hashTable=new Map);let n=!1,r=!1,s=!1,i=!1,o=!1,a="",l=[],c=0;for(;c<t.length;){let 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")o=!0,c++;else if(h==="-p"){if(i=!0,c++,c>=t.length)return L(`bash: hash: -p: option requires an argument
272
277
  `,1);a=t[c],c++}else if(h.startsWith("-")&&h.length>1){for(let y of h.slice(1))if(y==="r")n=!0;else if(y==="d")r=!0;else if(y==="l")s=!0;else if(y==="t")o=!0;else return y==="p"?L(`bash: hash: -p: option requires an argument
273
278
  `,1):L(`bash: hash: -${y}: invalid option
274
- `,1);c++}else l.push(h),c++}if(n)return e.state.hashTable.clear(),ne;if(r){if(l.length===0)return L(`bash: hash: -d: option requires an argument
279
+ `,1);c++}else l.push(h),c++}if(n)return e.state.hashTable.clear(),ee;if(r){if(l.length===0)return L(`bash: hash: -d: option requires an argument
275
280
  `,1);let h=!1,y="";for(let E of l)e.state.hashTable.has(E)?e.state.hashTable.delete(E):(y+=`bash: hash: ${E}: not found
276
- `,h=!0);return h?L(y,1):ne}if(o){if(l.length===0)return L(`bash: hash: -t: option requires an argument
277
- `,1);let h="",y=!1,E="";for(let S of l){let g=e.state.hashTable.get(S);g?l.length>1?h+=`${S} ${g}
278
- `:h+=`${g}
281
+ `,h=!0);return h?L(y,1):ee}if(o){if(l.length===0)return L(`bash: hash: -t: option requires an argument
282
+ `,1);let h="",y=!1,E="";for(let S of l){let m=e.state.hashTable.get(S);m?l.length>1?h+=`${S} ${m}
283
+ `:h+=`${m}
279
284
  `:(E+=`bash: hash: ${S}: not found
280
- `,y=!0)}return y?{exitCode:1,stdout:h,stderr:E}:ee(h)}if(i){if(l.length===0)return L(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
281
- `,1);let h=l[0];return e.state.hashTable.set(h,a),ne}if(l.length===0){if(e.state.hashTable.size===0)return ee(`hash: hash table empty
285
+ `,y=!0)}return y?{exitCode:1,stdout:h,stderr:E}:J(h)}if(i){if(l.length===0)return L(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
286
+ `,1);let h=l[0];return e.state.hashTable.set(h,a),ee}if(l.length===0){if(e.state.hashTable.size===0)return J(`hash: hash table empty
282
287
  `);let h="";if(s)for(let[y,E]of e.state.hashTable){let S=y.startsWith("-")?" --":"";h+=`builtin hash -p ${be(E)}${S} ${be(y)}
283
288
  `}else{h=`hits command
284
289
  `;for(let[,y]of e.state.hashTable)h+=` 1 ${y}
285
- `}return ee(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
290
+ `}return J(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
286
291
  `,u=!0;continue}let y=!1;for(let E of p){if(!E)continue;let S=`${E}/${h}`;if(await e.fs.exists(S)){e.state.hashTable.set(h,S),y=!0;break}}y||(f+=`bash: hash: ${h}: not found
287
- `,u=!0)}return u?L(f,1):ne}var ef=new Map([[":",[": [arguments]",`Null command.
292
+ `,u=!0)}return u?L(f,1):ee}var lf=new Map([[":",[": [arguments]",`Null command.
288
293
  No effect; the command does nothing.
289
294
  Exit Status:
290
295
  Always succeeds.`]],[".",[". filename [arguments]",`Execute commands from a file in the current shell.
@@ -634,37 +639,37 @@ eval: usage: eval [arg ...]
634
639
  job specification, and reports its termination status.
635
640
  Exit Status:
636
641
  Returns the status of the last ID; fails if ID is invalid or an invalid
637
- option is given.`]]]),tf=[...ef.keys()].sort();function Ho(e,t){let n=!1,r=[],s=0;for(;s<t.length;){let l=t[s];if(l==="--"){for(s++;s<t.length;)r.push(t[s]),s++;break}if(l.startsWith("-")&&l.length>1){for(let c=1;c<l.length;c++){let u=l[c];if(u==="s")n=!0;else return L(`bash: help: -${u}: invalid option
638
- `,2)}s++}else r.push(l),s++}if(r.length===0)return lm();let i="",o=!1,a="";for(let l of r){let c=am(l);if(c.length===0){a+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
639
- `,o=!0;continue}for(let u of c){let f=ef.get(u);if(!f)continue;let[d,p]=f;n?i+=`${u}: ${d}
642
+ option is given.`]]]),cf=[...lf.keys()].sort();function Yo(e,t){let n=!1,r=[],s=0;for(;s<t.length;){let l=t[s];if(l==="--"){for(s++;s<t.length;)r.push(t[s]),s++;break}if(l.startsWith("-")&&l.length>1){for(let c=1;c<l.length;c++){let u=l[c];if(u==="s")n=!0;else return L(`bash: help: -${u}: invalid option
643
+ `,2)}s++}else r.push(l),s++}if(r.length===0)return ym();let i="",o=!1,a="";for(let l of r){let c=mm(l);if(c.length===0){a+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
644
+ `,o=!0;continue}for(let u of c){let f=lf.get(u);if(!f)continue;let[d,p]=f;n?i+=`${u}: ${d}
640
645
  `:i+=`${u}: ${d}
641
646
  ${p}
642
- `}}return{exitCode:o?1:0,stdout:i,stderr:a}}function am(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),n=me(`^${t}$`);return tf.filter(r=>n.test(r))}function lm(){let e=[];e.push("just-bash shell builtins"),e.push("These shell commands are defined internally. Type `help' to see this list."),e.push("Type `help name' to find out more about the function `name'."),e.push("");let t=36,n=tf.slice(),r=Math.ceil(n.length/2);for(let s=0;s<r;s++){let i=n[s]||"",o=n[s+r]||"",a=i.padEnd(t);e.push(o?`${a}${o}`:i)}return ee(`${e.join(`
647
+ `}}return{exitCode:o?1:0,stdout:i,stderr:a}}function mm(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),n=me(`^${t}$`);return cf.filter(r=>n.test(r))}function ym(){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=cf.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 J(`${e.join(`
643
648
  `)}
644
- `)}function cm(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 Go(e,t){if(t.length===0)return L(`bash: let: expression expected
645
- `);let n=cm(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 Y(e,a.expression.expression))}}catch(i){return L(`bash: let: ${s}: ${i.message}
646
- `)}return T("","",r===0?1:0)}async function Zo(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength};if(e.state.localScopes.length===0)return L(`bash: local: can only be used in a function
649
+ `)}function gm(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 Jo(e,t){if(t.length===0)return L(`bash: let: expression expected
650
+ `);let n=gm(t),r=0;for(let s of n)try{let o=lt(`(( ${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 Y(e,a.expression.expression))}}catch(i){return L(`bash: let: ${s}: ${i.message}
651
+ `)}return T("","",r===0?1:0)}async function ea(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength};if(e.state.localScopes.length===0)return L(`bash: local: can only be used in a function
647
652
  `);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=xe(e,d);s.set(d,p?Me(p):void 0)}},o="",a=0,l=!1,c=!1,u=!1,f=[];for(let d of t)if(d==="-n")l=!0;else if(d==="-a")c=!0;else if(d==="-p")u=!0;else if(d.startsWith("-")&&!d.includes("="))for(let 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 y=e.state.env.get(h);y!==void 0&&(d+=`${h}=${y}
648
653
  `)}return T(d,"",0)}for(let d of f){let p,h,y=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(y){p=y[1];let b=y[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(p)){o+=`bash: local: \`${d}': not a valid identifier
649
- `,a=1;continue}ue(e,p,"bash");let A=Bt(b,n);e.executionScope.consumeWork(A.length,"local array assignment"),i(p),ge(e,p),Qt(e,p,"indexed");for(let x=0;x<A.length;x++)j(e,p,x,A[x]);ln(e,p),l&&Mt(e,p);continue}let E=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(E){p=E[1];let b=E[2];ue(e,p,"bash"),i(p);let A=Bt(b,n);e.executionScope.consumeWork(A.length,"local array append");let x=Se(e,p),v=0,$=e.state.env.get(p);x.length===0&&$!==void 0?(j(e,p,0,$),e.state.env.delete(p),v=1):x.length>0&&(v=Math.max(...x)+1),wn(e,p,Array.from({length:A.length},(D,k)=>v+k));for(let D=0;D<A.length;D++)j(e,p,v+D,A[D]);ln(e,p),l&&Mt(e,p);continue}let S=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(S){p=S[1];let b=S[2];ue(e,p,"bash"),r.has(p)||r.set(p,e.state.env.get(p));let A=e.state.env.get(p)??"";e.state.env.set(p,qt([A,b],"",e.limits.maxStringLength,"local append")),ln(e,p),l&&Mt(e,p);continue}let g=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(g){p=g[1];let b=g[2],A=g[3];ue(e,p,"bash"),i(p);let x;try{let v=new H,$=se(v,b);x=await Y(e,$.expression)}catch{let v=parseInt(b,10);x=Number.isNaN(v)?0:v}j(e,p,x,A),ln(e,p),l&&Mt(e,p);continue}if(d.includes("=")){let b=d.indexOf("=");p=d.slice(0,b),h=d.slice(b+1)}else p=d;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(p)){o+=`bash: local: \`${d}': not a valid identifier
650
- `,a=1;continue}let m=r.has(p);if(h!==void 0){let b=e.state.env.get(p);if(e.state.tempEnvBindings){let A=e.state.accessedTempEnvVars?.has(p),x=e.state.mutatedTempEnvVars?.has(p);if(!A&&!x)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let $=e.state.tempEnvBindings[v];if($.has(p)){b=$.get(p);break}}}Cu(e,p,b)}if(!m){let b=e.state.env.get(p);if(e.state.tempEnvBindings)for(let A=e.state.tempEnvBindings.length-1;A>=0;A--){let x=e.state.tempEnvBindings[A];if(x.has(p)){b=x.get(p);break}}r.set(p,b),c&&i(p)}if(c&&h===void 0)ge(e,p),Qt(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
651
- `,a=1;continue}e.state.env.set(p,h),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(p))}else{let b=e.state.tempEnvBindings?.some(A=>A.has(p));!m&&!b&&e.state.env.delete(p)}ln(e,p),l&&Mt(e,p)}return T("",o,a)}function qs(e,t,n){let r=`
652
- `,s=0,i=0,o=0,a=!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]||`
653
- `,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?(o=Number.parseInt(t[c+1],10)||0,c+=2):g==="-t"?(a=!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 T("",`mapfile: ${l}: not a valid identifier
654
+ `,a=1;continue}ue(e,p,"bash");let v=Wt(b,n);e.executionScope.consumeWork(v.length,"local array assignment"),i(p),ge(e,p),Kt(e,p,"indexed");for(let x=0;x<v.length;x++)j(e,p,x,v[x]);un(e,p),l&&Bt(e,p);continue}let E=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(E){p=E[1];let b=E[2];ue(e,p,"bash"),i(p);let v=Wt(b,n);e.executionScope.consumeWork(v.length,"local array append");let x=Se(e,p),A=0,$=e.state.env.get(p);x.length===0&&$!==void 0?(j(e,p,0,$),e.state.env.delete(p),A=1):x.length>0&&(A=Math.max(...x)+1),Sn(e,p,Array.from({length:v.length},(R,k)=>A+k));for(let R=0;R<v.length;R++)j(e,p,A+R,v[R]);un(e,p),l&&Bt(e,p);continue}let S=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(S){p=S[1];let b=S[2];ue(e,p,"bash"),r.has(p)||r.set(p,e.state.env.get(p));let v=e.state.env.get(p)??"";e.state.env.set(p,jt([v,b],"",e.limits.maxStringLength,"local append")),un(e,p),l&&Bt(e,p);continue}let m=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(m){p=m[1];let b=m[2],v=m[3];ue(e,p,"bash"),i(p);let x;try{let A=new H,$=ne(A,b);x=await Y(e,$.expression)}catch{let A=parseInt(b,10);x=Number.isNaN(A)?0:A}j(e,p,x,v),un(e,p),l&&Bt(e,p);continue}if(d.includes("=")){let b=d.indexOf("=");p=d.slice(0,b),h=d.slice(b+1)}else p=d;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(p)){o+=`bash: local: \`${d}': not a valid identifier
655
+ `,a=1;continue}let g=r.has(p);if(h!==void 0){let b=e.state.env.get(p);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(p),x=e.state.mutatedTempEnvVars?.has(p);if(!v&&!x)for(let A=e.state.tempEnvBindings.length-1;A>=0;A--){let $=e.state.tempEnvBindings[A];if($.has(p)){b=$.get(p);break}}}Lu(e,p,b)}if(!g){let b=e.state.env.get(p);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let x=e.state.tempEnvBindings[v];if(x.has(p)){b=x.get(p);break}}r.set(p,b),c&&i(p)}if(c&&h===void 0)ge(e,p),Kt(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
656
+ `,a=1;continue}e.state.env.set(p,h),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(p))}else{let b=e.state.tempEnvBindings?.some(v=>v.has(p));!g&&!b&&e.state.env.delete(p)}un(e,p),l&&Bt(e,p)}return T("",o,a)}function Gs(e,t,n){let r=`
657
+ `,s=0,i=0,o=0,a=!1,l="MAPFILE",c=0;for(;c<t.length;){let m=t[c];m==="-d"&&c+1<t.length?(r=t[c+1]===""?"\0":t[c+1]||`
658
+ `,c+=2):m==="-n"&&c+1<t.length?(s=Number.parseInt(t[c+1],10)||0,c+=2):m==="-O"&&c+1<t.length?(i=Number.parseInt(t[c+1],10)||0,c+=2):m==="-s"&&c+1<t.length?(o=Number.parseInt(t[c+1],10)||0,c+=2):m==="-t"?(a=!0,c++):m==="-u"||m==="-C"||m==="-c"?c+=2:(m.startsWith("-")||(l=m),c++)}if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l))return T("",`mapfile: ${l}: not a valid identifier
654
659
  `,1);if(!Number.isSafeInteger(i)||i<0)return T("",`mapfile: invalid array origin
655
- `,1);ue(e,l,"mapfile");let u=n;!u&&e.state.groupStdin!==void 0&&(u=e.state.groupStdin);let f=[],d=0,p=0,h=0,y=e.limits.maxArrayElements,E=g=>{if(B(g)>e.limits.maxStringLength)throw new P(`mapfile: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");f.push(g)};for(;d<u.length;){e.executionScope.consumeWork(1,"mapfile input");let g=u.indexOf(r,d);if(g===-1){if(d<u.length){if(h<o)h++;else if(s===0||p<s){let A=u.slice(d),x=A.indexOf("\0");if(x!==-1&&(A=A.substring(0,x)),f.length>=y)return T("",`mapfile: array element limit exceeded (${y})
656
- `,1);E(A),p++}}break}let m=u.slice(d,g),b=m.indexOf("\0");if(b!==-1&&(m=m.substring(0,b)),!a&&r!=="\0"&&(m+=r),d=g+r.length,h<o){h++;continue}if(s>0&&p>=s)break;if(f.length>=y)return T("",`mapfile: array element limit exceeded (${y})
657
- `,1);E(m),p++}let S=new Set(i===0?[]:e.state.arrays?.get(l)?.elements.keys()??[]);for(let g=0;g<f.length;g++)if(S.add(String(i+g)),S.size>y)return T("",`mapfile: array element limit exceeded (${y})
658
- `,1);i===0&&ge(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=""),{...T("","",0),internalStdinConsumed:u.length}}function Qo(e,t,n,r=-1){let s=!1,i=`
659
- `,o="",a=-1,l=-1,c=null,u=-1,f=-1,d=[],p=0,h=!1,y=(O,_)=>{let M=1;for(;M<O.length;){let re=O[M];if(re==="r")s=!0,M++;else if(re==="s")M++;else{if(re==="d")return M+1<O.length?(i=O.substring(M+1),{nextArgIndex:_+1}):_+1<t.length?(i=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(re==="n"){if(M+1<O.length){let K=O.substring(M+1);return a=Number.parseInt(K,10),(Number.isNaN(a)||a<0)&&(h=!0,a=0),{nextArgIndex:_+1}}else if(_+1<t.length)return a=Number.parseInt(t[_+1],10),(Number.isNaN(a)||a<0)&&(h=!0,a=0),{nextArgIndex:_+2};return{nextArgIndex:_+1}}else if(re==="N"){if(M+1<O.length){let K=O.substring(M+1);return l=Number.parseInt(K,10),(Number.isNaN(l)||l<0)&&(h=!0,l=0),{nextArgIndex:_+1}}else if(_+1<t.length)return l=Number.parseInt(t[_+1],10),(Number.isNaN(l)||l<0)&&(h=!0,l=0),{nextArgIndex:_+2};return{nextArgIndex:_+1}}else{if(re==="a")return M+1<O.length?(c=O.substring(M+1),{nextArgIndex:_+1}):_+1<t.length?(c=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(re==="p")return M+1<O.length?(o=O.substring(M+1),{nextArgIndex:_+1}):_+1<t.length?(o=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(re==="u"){if(M+1<O.length){let K=O.substring(M+1);return u=Number.parseInt(K,10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:_+1}}else if(_+1<t.length)return u=Number.parseInt(t[_+1],10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:_+2};return{nextArgIndex:_+1}}else if(re==="t"){if(M+1<O.length){let K=O.substring(M+1);return f=Number.parseFloat(K),Number.isNaN(f)&&(f=0),{nextArgIndex:_+1}}else if(_+1<t.length)return f=Number.parseFloat(t[_+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:_+2};return{nextArgIndex:_+1}}else if(re==="e"||re==="i"||re==="P"){if(re==="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 _=y(O,p);if(_.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(_.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};p=_.nextArgIndex}else if(O==="--")for(p++;p<t.length;)d.push(t[p]),p++;else d.push(O),p++}if(h)return T("","",1);d.length===0&&c===null&&d.push("REPLY");let E=new Set;c&&E.add(c);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 T("",`bash: read: \`${O}': not a valid identifier
660
- `,1);ue(e,O,"bash")}if(f===0){if(c)ge(e,c);else{for(let O of d)e.state.env.set(O,"");d.length===0&&e.state.env.set("REPLY","")}return T("","",0)}if(f<0&&f!==-1)return T("","",1);let S=n,g=nt(e,u),m=u>0&&!(g?.kind==="dup-in"&&g.sourceFd===0);if(m){let O=Ls(e,u);if("error"in O){let M=O.error==="write-only"||u===1||u===2?`bash: read: read error: ${u}: Bad file descriptor
660
+ `,1);ue(e,l,"mapfile");let u=n;!u&&e.state.groupStdin!==void 0&&(u=e.state.groupStdin);let f=[],d=0,p=0,h=0,y=e.limits.maxArrayElements,E=m=>{if(M(m)>e.limits.maxStringLength)throw new P(`mapfile: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");f.push(m)};for(;d<u.length;){e.executionScope.consumeWork(1,"mapfile input");let m=u.indexOf(r,d);if(m===-1){if(d<u.length){if(h<o)h++;else if(s===0||p<s){let v=u.slice(d),x=v.indexOf("\0");if(x!==-1&&(v=v.substring(0,x)),f.length>=y)return T("",`mapfile: array element limit exceeded (${y})
661
+ `,1);E(v),p++}}break}let g=u.slice(d,m),b=g.indexOf("\0");if(b!==-1&&(g=g.substring(0,b)),!a&&r!=="\0"&&(g+=r),d=m+r.length,h<o){h++;continue}if(s>0&&p>=s)break;if(f.length>=y)return T("",`mapfile: array element limit exceeded (${y})
662
+ `,1);E(g),p++}let S=new Set(i===0?[]:e.state.arrays?.get(l)?.elements.keys()??[]);for(let m=0;m<f.length;m++)if(S.add(String(i+m)),S.size>y)return T("",`mapfile: array element limit exceeded (${y})
663
+ `,1);i===0&&ge(e,l);for(let m=0;m<f.length;m++)j(e,l,i+m,f[m]);return e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=""),{...T("","",0),internalStdinConsumed:u.length}}function ta(e,t,n,r=-1){let s=!1,i=`
664
+ `,o="",a=-1,l=-1,c=null,u=-1,f=-1,d=[],p=0,h=!1,y=(O,_)=>{let B=1;for(;B<O.length;){let te=O[B];if(te==="r")s=!0,B++;else if(te==="s")B++;else{if(te==="d")return B+1<O.length?(i=O.substring(B+1),{nextArgIndex:_+1}):_+1<t.length?(i=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(te==="n"){if(B+1<O.length){let X=O.substring(B+1);return a=Number.parseInt(X,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(te==="N"){if(B+1<O.length){let X=O.substring(B+1);return l=Number.parseInt(X,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(te==="a")return B+1<O.length?(c=O.substring(B+1),{nextArgIndex:_+1}):_+1<t.length?(c=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(te==="p")return B+1<O.length?(o=O.substring(B+1),{nextArgIndex:_+1}):_+1<t.length?(o=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(te==="u"){if(B+1<O.length){let X=O.substring(B+1);return u=Number.parseInt(X,10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:_+1}}else if(_+1<t.length)return u=Number.parseInt(t[_+1],10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:_+2};return{nextArgIndex:_+1}}else if(te==="t"){if(B+1<O.length){let X=O.substring(B+1);return f=Number.parseFloat(X),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(te==="e"||te==="i"||te==="P"){if(te==="i"&&_+1<t.length)return{nextArgIndex:_+2};B++}else B++}}}return{nextArgIndex:_+1}};for(;p<t.length;){let O=t[p];if(O.startsWith("-")&&O.length>1&&O!=="--"){let _=y(O,p);if(_.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(_.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};p=_.nextArgIndex}else if(O==="--")for(p++;p<t.length;)d.push(t[p]),p++;else d.push(O),p++}if(h)return T("","",1);d.length===0&&c===null&&d.push("REPLY");let E=new Set;c&&E.add(c);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 T("",`bash: read: \`${O}': not a valid identifier
665
+ `,1);ue(e,O,"bash")}if(f===0){if(c)ge(e,c);else{for(let O of d)e.state.env.set(O,"");d.length===0&&e.state.env.set("REPLY","")}return T("","",0)}if(f<0&&f!==-1)return T("","",1);let S=n,m=nt(e,u),g=u>0&&!(m?.kind==="dup-in"&&m.sourceFd===0);if(g){let O=Ms(e,u);if("error"in O){let B=O.error==="write-only"||u===1||u===2?`bash: read: read error: ${u}: Bad file descriptor
661
666
  `:`bash: read: ${u}: invalid file descriptor: Bad file descriptor
662
- `;return T("",M,1)}S=O.content}else!S&&e.state.groupStdin!==void 0&&(S=e.state.groupStdin);let b=i===""?"\0":i,A="",x=0,v=O=>{let _=B(O);if(_>e.limits.maxStringLength-x)throw new P(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");A+=O,x+=_},$=O=>{if(B(O)>e.limits.maxStringLength)throw new P(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")},D=0,k=!0,C=O=>{m?un(e,u,O):r>=0?un(e,r,O):e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=S.substring(O),e.state.groupStdinSourceFd!==void 0&&un(e,e.state.groupStdinSourceFd,O))};if(l>=0){let O=Math.min(l,S.length);A=S.substring(0,O),$(A),D=O,k=O>=l,C(D);let _=d[0]||"REPLY";e.state.env.set(_,A);for(let M=1;M<d.length;M++)e.state.env.set(d[M],"");return T("","",k?0:1)}else if(a>=0){let O=0,_=0,M=!1;for(;_<S.length&&O<a;){let re=S[_];if(re===b){D=_+1,M=!0;break}if(!s&&re==="\\"&&_+1<S.length){let K=S[_+1];if(K===b&&b===`
663
- `){_+=2,D=_;continue}if(K===b){_+=2,O++,v(K),D=_;continue}v(K),_+=2,O++,D=_}else v(re),_++,O++,D=_}k=O>=a||M,C(D)}else{D=0;let O=0;for(;O<S.length;){let _=S[O];if(_===b){D=O+b.length,k=!0;break}if(!s&&_==="\\"&&O+1<S.length){let M=S[O+1];if(M===`
664
- `){O+=2;continue}if(M===b){v(M),O+=2;continue}v(_),v(M),O+=2;continue}v(_),O++}if(O>=S.length&&(k=!1,D=O,A.length===0&&S.length===0)){for(let _ of d)e.state.env.set(_,"");return c&&ge(e,c),T("","",1)}C(D)}b===`
665
- `&&A.endsWith(`
666
- `)&&(A=A.slice(0,-1));let I=O=>s?O:O.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",I(A)),T("","",k?0:1);let W=ve(e.state.env),Z=e.limits.maxArrayElements;if(c){let{words:O}=Vi(A,W,Z,void 0,s);ge(e,c);for(let _=0;_<O.length;_++)j(e,c,_,I(O[_]));return T("","",k?0:1)}let R=d.length,{words:V,wordStarts:z}=Vi(A,W,Z,R,s);for(let O=0;O<d.length;O++){let _=d[O];if(O<d.length-1)e.state.env.set(_,I(V[O]??""));else if(O<z.length){let M=A.substring(z[O]);M=Gl(M,W,s),M=I(M),e.state.env.set(_,M)}else e.state.env.set(_,"")}return T("","",k?0:1)}function Ko(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return L("bash: return: can only `return' from a function or sourced script\n");let n=e.state.lastExitCode;if(t.length>0){let r=t[0],s=Number.parseInt(r,10);if(r===""||Number.isNaN(s)||!/^-?\d+$/.test(r))return L(`bash: return: ${r}: numeric argument required
667
- `,2);n=(s%256+256)%256}throw new _e(n)}var vr=`set: usage: set [-eux] [+eux] [-o option] [+o option]
667
+ `;return T("",B,1)}S=O.content}else!S&&e.state.groupStdin!==void 0&&(S=e.state.groupStdin);let b=i===""?"\0":i,v="",x=0,A=O=>{let _=M(O);if(_>e.limits.maxStringLength-x)throw new P(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");v+=O,x+=_},$=O=>{if(M(O)>e.limits.maxStringLength)throw new P(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")},R=0,k=!0,C=O=>{g?dn(e,u,O):r>=0?dn(e,r,O):e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=S.substring(O),e.state.groupStdinSourceFd!==void 0&&dn(e,e.state.groupStdinSourceFd,O))};if(l>=0){let O=Math.min(l,S.length);v=S.substring(0,O),$(v),R=O,k=O>=l,C(R);let _=d[0]||"REPLY";e.state.env.set(_,v);for(let B=1;B<d.length;B++)e.state.env.set(d[B],"");return T("","",k?0:1)}else if(a>=0){let O=0,_=0,B=!1;for(;_<S.length&&O<a;){let te=S[_];if(te===b){R=_+1,B=!0;break}if(!s&&te==="\\"&&_+1<S.length){let X=S[_+1];if(X===b&&b===`
668
+ `){_+=2,R=_;continue}if(X===b){_+=2,O++,A(X),R=_;continue}A(X),_+=2,O++,R=_}else A(te),_++,O++,R=_}k=O>=a||B,C(R)}else{R=0;let O=0;for(;O<S.length;){let _=S[O];if(_===b){R=O+b.length,k=!0;break}if(!s&&_==="\\"&&O+1<S.length){let B=S[O+1];if(B===`
669
+ `){O+=2;continue}if(B===b){A(B),O+=2;continue}A(_),A(B),O+=2;continue}A(_),O++}if(O>=S.length&&(k=!1,R=O,v.length===0&&S.length===0)){for(let _ of d)e.state.env.set(_,"");return c&&ge(e,c),T("","",1)}C(R)}b===`
670
+ `&&v.endsWith(`
671
+ `)&&(v=v.slice(0,-1));let I=O=>s?O:O.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",I(v)),T("","",k?0:1);let W=ve(e.state.env),Z=e.limits.maxArrayElements;if(c){let{words:O}=ji(v,W,Z,void 0,s);ge(e,c);for(let _=0;_<O.length;_++)j(e,c,_,I(O[_]));return T("","",k?0:1)}let D=d.length,{words:V,wordStarts:U}=ji(v,W,Z,D,s);for(let O=0;O<d.length;O++){let _=d[O];if(O<d.length-1)e.state.env.set(_,I(V[O]??""));else if(O<U.length){let B=v.substring(U[O]);B=tc(B,W,s),B=I(B),e.state.env.set(_,B)}else e.state.env.set(_,"")}return T("","",k?0:1)}function na(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return L("bash: return: can only `return' from a function or sourced script\n");let n=e.state.lastExitCode;if(t.length>0){let r=t[0],s=Number.parseInt(r,10);if(r===""||Number.isNaN(s)||!/^-?\d+$/.test(r))return L(`bash: return: ${r}: numeric argument required
672
+ `,2);n=(s%256+256)%256}throw new _e(n)}var $r=`set: usage: set [-eux] [+eux] [-o option] [+o option]
668
673
  Options:
669
674
  -e Exit immediately if a command exits with non-zero status
670
675
  +e Disable -e
@@ -680,80 +685,80 @@ Options:
680
685
  +o pipefail Disable pipefail
681
686
  -o xtrace Same as -x
682
687
  +o xtrace Disable xtrace
683
- `,nf=new Map([["e","errexit"],["u","nounset"],["x","xtrace"],["v","verbose"],["f","noglob"],["C","noclobber"],["a","allexport"],["n","noexec"],["h",null],["b",null],["m",null],["B",null],["H",null],["P",null],["T",null],["E",null],["p",null]]),js=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["noclobber","noclobber"],["noglob","noglob"],["allexport","allexport"],["noexec","noexec"],["posix","posix"],["vi","vi"],["emacs","emacs"],["notify",null],["monitor",null],["braceexpand",null],["histexpand",null],["physical",null],["functrace",null],["errtrace",null],["privileged",null],["hashall",null],["ignoreeof",null],["interactive-comments",null],["keyword",null],["onecmd",null]]),of=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],af=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Xo(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,Fn(e))}function um(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function fm(e,t,n){let r=Se(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],o=ae(e,n,i)??"";s>0&&t.append(" "),t.append(`[${i}]=`),t.reserve(Vs(o)),t.append(pn(o))}t.append(")")}function dm(e,t){if(/^[a-zA-Z0-9_]+$/.test(t)){e.append(t);return}e.reserve(Vs(t)),e.append(pn(t))}function pm(e,t,n){let r=$t(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],o=ae(e,n,i)??"";s>0&&t.append(" "),t.append("["),dm(t,i),t.append("]="),t.reserve(Vs(o)),t.append(pn(o))}t.append(" )")}function hm(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 mm(e){return e.state.associativeArrays??new Set}function rf(e){let t=of.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),n=af.map(r=>`${r.padEnd(16)}off`);return`${[...t,...n].sort().join(`
688
+ `,uf=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]]),Zs=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]]),pf=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],hf=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function ra(e,t,n){t!==null&&(n&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=n,Bn(e))}function wm(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Em(e,t,n){let r=Se(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],o=oe(e,n,i)??"";s>0&&t.append(" "),t.append(`[${i}]=`),t.reserve(qs(o)),t.append(mn(o))}t.append(")")}function bm(e,t){if(/^[a-zA-Z0-9_]+$/.test(t)){e.append(t);return}e.reserve(qs(t)),e.append(mn(t))}function Sm(e,t,n){let r=Ct(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("["),bm(t,i),t.append("]="),t.reserve(qs(o)),t.append(mn(o))}t.append(" )")}function Am(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 vm(e){return e.state.associativeArrays??new Set}function ff(e){let t=pf.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),n=hf.map(r=>`${r.padEnd(16)}off`);return`${[...t,...n].sort().join(`
684
689
  `)}
685
- `}function sf(e){let t=of.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),n=af.map(r=>`set +o ${r}`);return`${[...t,...n].sort().join(`
690
+ `}function df(e){let t=pf.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),n=hf.map(r=>`set +o ${r}`);return`${[...t,...n].sort().join(`
686
691
  `)}
687
- `}function Jo(e,t){if(t.includes("--help"))return ee(vr);if(t.length===0){let i=hm(e),o=mm(e),a=[];for(let[u,f]of e.state.env)/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)&&(i.has(u)||o.has(u)||a.push([u,f]));let l=[...a.map(([u,f])=>({kind:"scalar",name:u,value:f})),...Array.from(i,u=>({kind:"indexed",name:u})),...Array.from(o,u=>({kind:"associative",name:u}))];l.sort((u,f)=>u.name<f.name?-1:u.name>f.name?1:0);let c=new Nn(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(qu(u.value)),c.append(be(u.value))):u.kind==="indexed"?fm(e,c,u.name):pm(e,c,u.name),c.append(`
688
- `);return ee(c.build())}let n=[],r=()=>n.length>0?ee(n.join("")):ne,s=0;for(;s<t.length;){let i=t[s];if((i==="-o"||i==="+o")&&um(t,s)){let o=t[s+1];if(!js.has(o)){let a=`bash: set: ${o}: invalid option name
689
- ${vr}`;if(e.state.options.posix)throw new st(1,"",a);return L(a)}Xo(e,js.get(o)??null,i==="-o"),s+=2;continue}if(i==="-o"){n.push(rf(e)),s++;continue}if(i==="+o"){n.push(sf(e)),s++;continue}if(i.length>1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let o=i[0]==="-",a=0;for(let l=1;l<i.length;l++){let c=i[l];if(c==="o"){let u=s+1+a;if(u<t.length&&!t[u].startsWith("-")&&!t[u].startsWith("+")){let d=t[u];if(!js.has(d)){let p=`bash: set: ${d}: invalid option name
690
- ${vr}`;if(e.state.options.posix)throw new st(1,"",p);return L(p)}Xo(e,js.get(d)??null,o),a++;continue}n.push(o?rf(e):sf(e));continue}if(!nf.has(c)){let u=`bash: set: ${i[0]}${c}: invalid option
691
- ${vr}`;if(e.state.options.posix)throw new st(1,"",u);return L(u)}Xo(e,nf.get(c)??null,o)}s+=1+a;continue}if(i==="--")return Yo(e,t.slice(s+1)),r();if(i==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,Fn(e),s+1<t.length)return Yo(e,t.slice(s+1)),r();s++;continue}if(i==="+"){s++;continue}if(i.startsWith("-")||i.startsWith("+")){let o=`bash: set: ${i}: invalid option
692
- ${vr}`;if(e.state.options.posix)throw new st(1,"",o);return L(o)}return Yo(e,t.slice(s)),r()}return r()}function Yo(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 ea(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
692
+ `}function ia(e,t){if(t.includes("--help"))return J($r);if(t.length===0){let i=Am(e),o=vm(e),a=[];for(let[u,f]of e.state.env)/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)&&(i.has(u)||o.has(u)||a.push([u,f]));let l=[...a.map(([u,f])=>({kind:"scalar",name:u,value:f})),...Array.from(i,u=>({kind:"indexed",name:u})),...Array.from(o,u=>({kind:"associative",name:u}))];l.sort((u,f)=>u.name<f.name?-1:u.name>f.name?1:0);let c=new In(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(Xu(u.value)),c.append(be(u.value))):u.kind==="indexed"?Em(e,c,u.name):Sm(e,c,u.name),c.append(`
693
+ `);return J(c.build())}let n=[],r=()=>n.length>0?J(n.join("")):ee,s=0;for(;s<t.length;){let i=t[s];if((i==="-o"||i==="+o")&&wm(t,s)){let o=t[s+1];if(!Zs.has(o)){let a=`bash: set: ${o}: invalid option name
694
+ ${$r}`;if(e.state.options.posix)throw new st(1,"",a);return L(a)}ra(e,Zs.get(o)??null,i==="-o"),s+=2;continue}if(i==="-o"){n.push(ff(e)),s++;continue}if(i==="+o"){n.push(df(e)),s++;continue}if(i.length>1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let o=i[0]==="-",a=0;for(let l=1;l<i.length;l++){let c=i[l];if(c==="o"){let u=s+1+a;if(u<t.length&&!t[u].startsWith("-")&&!t[u].startsWith("+")){let d=t[u];if(!Zs.has(d)){let p=`bash: set: ${d}: invalid option name
695
+ ${$r}`;if(e.state.options.posix)throw new st(1,"",p);return L(p)}ra(e,Zs.get(d)??null,o),a++;continue}n.push(o?ff(e):df(e));continue}if(!uf.has(c)){let u=`bash: set: ${i[0]}${c}: invalid option
696
+ ${$r}`;if(e.state.options.posix)throw new st(1,"",u);return L(u)}ra(e,uf.get(c)??null,o)}s+=1+a;continue}if(i==="--")return sa(e,t.slice(s+1)),r();if(i==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,Bn(e),s+1<t.length)return sa(e,t.slice(s+1)),r();s++;continue}if(i==="+"){s++;continue}if(i.startsWith("-")||i.startsWith("+")){let o=`bash: set: ${i}: invalid option
697
+ ${$r}`;if(e.state.options.posix)throw new st(1,"",o);return L(o)}return sa(e,t.slice(s)),r()}return r()}function sa(e,t){let n=1;for(;e.state.env.has(String(n));)e.state.env.delete(String(n)),n++;for(let r=0;r<t.length;r++)e.state.env.set(String(r+1),t[r]);e.state.env.set("#",String(t.length)),e.state.env.set("@",t.join(" ")),e.state.env.set("*",t.join(" "))}function oa(e,t){let n=1;if(t.length>0){let o=Number.parseInt(t[0],10);if(Number.isNaN(o)||o<0){let a=`bash: shift: ${t[0]}: numeric argument required
693
698
  `;if(e.state.options.posix)throw new st(1,"",a);return L(a)}n=o}let r=Number.parseInt(e.state.env.get("#")||"0",10);if(n>r){let o=`bash: shift: shift count out of range
694
- `;if(e.state.options.posix)throw new st(1,"",o);return L(o)}if(n===0)return ne;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(" ")),ne}async function Hs(e,t){let n=t;if(n.length>0&&n[0]==="--"&&(n=n.slice(1)),n.length===0)return T("",`bash: source: filename argument required
699
+ `;if(e.state.options.posix)throw new st(1,"",o);return L(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 Qs(e,t){let n=t;if(n.length>0&&n[0]==="--"&&(n=n.slice(1)),n.length===0)return T("",`bash: source: filename argument required
695
700
  `,2);let r=n[0],s=null,i=null;if(r.includes("/")){let c=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(c),s=c}catch{}}else{let u=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of u){let d=e.fs.resolvePath(e.state.cwd,`${f}/${r}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),s=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(f),s=f}catch{}}}if(i===null)return L(`bash: ${r}: No such file or directory
696
- `);let o=new Map;if(n.length>1){for(let u=1;u<=9;u++)o.set(String(u),e.state.env.get(String(u)));o.set("#",e.state.env.get("#")),o.set("@",e.state.env.get("@"));let c=n.slice(1);e.state.env.set("#",String(c.length)),e.state.env.set("@",c.join(" "));for(let u=0;u<c.length&&u<9;u++)e.state.env.set(String(u+1),c[u]);for(let u=c.length+1;u<=9;u++)e.state.env.delete(String(u))}let a=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=a,n.length>1)for(let[c,u]of o)u===void 0?e.state.env.delete(c):e.state.env.set(c,u)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new P(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let c=at(i),u=await e.executeScript(c);return l(),u}catch(c){if(l(),c instanceof q)throw c;if(c instanceof _e)return T(c.stdout,c.stderr,c.exitCode);if(c.name==="ParseException")return L(`bash: ${r}: ${c.message}
697
- `);throw c}}function lf(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function ym(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function cf(e,t){if(ym(t))return null;try{let n=new H,r=se(n,t);return await Y(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}function uf(e,t){if(e.state.localVarStack?.has(t)){let r=Ds(e,t);if(r){r.value===void 0?e.state.env.delete(t):e.state.env.set(t,r.value);let s=e.state.localVarStack?.get(t);if(!s||s.length===0)Rs(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),ta(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),Rs(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||Rs(e,t),!0}}return!1}function ta(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let n=e.state.tempEnvBindings.length-1;n>=0;n--){let r=e.state.tempEnvBindings[n];if(r.has(t)){let s=r.get(t);return s===void 0?e.state.env.delete(t):e.state.env.set(t,s),r.delete(t),!0}}return!1}async function ff(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let n=t.slice(1,-1),s=new H().parseWordFromString(n,!0,!1);return ie(e,s)}if(t.includes("$")){let r=new H().parseWordFromString(t,!1,!1);return ie(e,r)}return t}async function na(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(We(e,d)){r+=`bash: unset: ${d}: cannot unset: readonly variable
698
- `,s=1;continue}if(p==="@"||p==="*"){sr(e,d),e.state.env.delete(d);continue}let h=e.state.associativeArrays?.has(d);if(h){let m=await ff(e,p);En(e,d,m);continue}let y=yt(e,d),E=e.state.declaredVars?.has(d);if((e.state.env.has(d)||E)&&!y&&!h){r+=`bash: unset: ${d}: not an array variable
699
- `,s=1;continue}let g=await cf(e,p);if(g===null&&y){r+=`bash: unset: ${p}: not a valid identifier
700
- `,s=1;continue}if(g===null)continue;if(g<0){let m=G(e,d),b=m.length,A=e.state.currentLine;if(b===0){r+=`bash: line ${A}: unset: [${g}]: bad array subscript
701
- `,s=1;continue}let x=b+g;if(x<0){r+=`bash: line ${A}: unset: [${g}]: bad array subscript
702
- `,s=1;continue}let v=m[x][0];En(e,d,v);continue}En(e,d,g);continue}if(!lf(i)){r+=`bash: unset: \`${i}': not a valid identifier
701
+ `);let o=new Map;if(n.length>1){for(let u=1;u<=9;u++)o.set(String(u),e.state.env.get(String(u)));o.set("#",e.state.env.get("#")),o.set("@",e.state.env.get("@"));let c=n.slice(1);e.state.env.set("#",String(c.length)),e.state.env.set("@",c.join(" "));for(let u=0;u<c.length&&u<9;u++)e.state.env.set(String(u+1),c[u]);for(let u=c.length+1;u<=9;u++)e.state.env.delete(String(u))}let a=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=a,n.length>1)for(let[c,u]of o)u===void 0?e.state.env.delete(c):e.state.env.set(c,u)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new P(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let c=lt(i),u=await e.executeScript(c);return l(),u}catch(c){if(l(),c instanceof q)throw c;if(c instanceof _e)return T(c.stdout,c.stderr,c.exitCode);if(c.name==="ParseException")return L(`bash: ${r}: ${c.message}
702
+ `);throw c}}function mf(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function xm(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function yf(e,t){if(xm(t))return null;try{let n=new H,r=ne(n,t);return await Y(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}function gf(e,t){if(e.state.localVarStack?.has(t)){let r=_s(e,t);if(r){r.value===void 0?e.state.env.delete(t):e.state.env.set(t,r.value);let s=e.state.localVarStack?.get(t);if(!s||s.length===0)Os(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),aa(e,t);else{let i=s[s.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return e.state.env.delete(t),Os(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let r=e.state.localScopes.length-1;r>=0;r--){let s=e.state.localScopes[r];if(s.has(t)){let i=s.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),s.delete(t);let o=!1;for(let a=r-1;a>=0;a--)if(e.state.localScopes[a].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,a+1),o=!0;break}return o||Os(e,t),!0}}return!1}function aa(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let n=e.state.tempEnvBindings.length-1;n>=0;n--){let r=e.state.tempEnvBindings[n];if(r.has(t)){let s=r.get(t);return s===void 0?e.state.env.delete(t):e.state.env.set(t,s),r.delete(t),!0}}return!1}async function wf(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 H().parseWordFromString(n,!0,!1);return re(e,s)}if(t.includes("$")){let r=new H().parseWordFromString(t,!1,!1);return re(e,r)}return t}async function la(e,t){let n="both",r="",s=0;for(let i of t){if(i==="-v"){n="variable";continue}if(i==="-f"){n="function";continue}if(n==="function"){e.state.functions.delete(i);continue}if(n==="variable"){let c=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(c){let d=c[1],p=c[2];if(We(e,d)){r+=`bash: unset: ${d}: cannot unset: readonly variable
703
+ `,s=1;continue}if(p==="@"||p==="*"){lr(e,d),e.state.env.delete(d);continue}let h=e.state.associativeArrays?.has(d);if(h){let g=await wf(e,p);An(e,d,g);continue}let y=wt(e,d),E=e.state.declaredVars?.has(d);if((e.state.env.has(d)||E)&&!y&&!h){r+=`bash: unset: ${d}: not an array variable
704
+ `,s=1;continue}let m=await yf(e,p);if(m===null&&y){r+=`bash: unset: ${p}: not a valid identifier
705
+ `,s=1;continue}if(m===null)continue;if(m<0){let g=G(e,d),b=g.length,v=e.state.currentLine;if(b===0){r+=`bash: line ${v}: unset: [${m}]: bad array subscript
706
+ `,s=1;continue}let x=b+m;if(x<0){r+=`bash: line ${v}: unset: [${m}]: bad array subscript
707
+ `,s=1;continue}let A=g[x][0];An(e,d,A);continue}An(e,d,m);continue}if(!mf(i)){r+=`bash: unset: \`${i}': not a valid identifier
703
708
  `,s=1;continue}let u=i;if(ce(e,i)){let d=Be(e,i);d&&d!==i&&(u=d)}if(We(e,u)){r+=`bash: unset: ${u}: cannot unset: readonly variable
704
- `,s=1;continue}sr(e,u);let f=lo(e,u);if(f!==void 0&&f!==e.state.callDepth)uf(e,u);else if(e.state.fullyUnsetLocals?.has(u))e.state.env.delete(u);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(u),p=e.state.mutatedTempEnvVars?.has(u);if((d||p)&&e.state.localVarStack?.has(u)){let h=Ds(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 ta(e,u)||e.state.env.delete(u);e.state.exportedVars?.delete(u);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let c=o[1],u=o[2];if(We(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable
705
- `,s=1;continue}if(u==="@"||u==="*"){sr(e,c),e.state.env.delete(c);continue}let f=e.state.associativeArrays?.has(c);if(f){let y=await ff(e,u);En(e,c,y);continue}let d=yt(e,c);if(e.state.env.has(c)&&!d&&!f){r+=`bash: unset: ${c}: not an array variable
706
- `,s=1;continue}let h=await cf(e,u);if(h===null&&d){r+=`bash: unset: ${u}: not a valid identifier
709
+ `,s=1;continue}lr(e,u);let f=mo(e,u);if(f!==void 0&&f!==e.state.callDepth)gf(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=_s(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 aa(e,u)||e.state.env.delete(u);e.state.exportedVars?.delete(u);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let c=o[1],u=o[2];if(We(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable
710
+ `,s=1;continue}if(u==="@"||u==="*"){lr(e,c),e.state.env.delete(c);continue}let f=e.state.associativeArrays?.has(c);if(f){let y=await wf(e,u);An(e,c,y);continue}let d=wt(e,c);if(e.state.env.has(c)&&!d&&!f){r+=`bash: unset: ${c}: not an array variable
711
+ `,s=1;continue}let h=await yf(e,u);if(h===null&&d){r+=`bash: unset: ${u}: not a valid identifier
707
712
  `,s=1;continue}if(h===null)continue;if(h<0){let y=G(e,c),E=y.length,S=e.state.currentLine;if(E===0){r+=`bash: line ${S}: unset: [${h}]: bad array subscript
708
- `,s=1;continue}let g=E+h;if(g<0){r+=`bash: line ${S}: unset: [${h}]: bad array subscript
709
- `,s=1;continue}let m=y[g][0];En(e,c,m);continue}En(e,c,h);continue}if(!lf(i)){r+=`bash: unset: \`${i}': not a valid identifier
713
+ `,s=1;continue}let m=E+h;if(m<0){r+=`bash: line ${S}: unset: [${h}]: bad array subscript
714
+ `,s=1;continue}let g=y[m][0];An(e,c,g);continue}An(e,c,h);continue}if(!mf(i)){r+=`bash: unset: \`${i}': not a valid identifier
710
715
  `,s=1;continue}let a=i;if(ce(e,i)){let c=Be(e,i);c&&c!==i&&(a=c)}if(We(e,a)){r+=`bash: unset: ${a}: cannot unset: readonly variable
711
- `,s=1;continue}sr(e,a);let l=lo(e,a);if(l!==void 0&&l!==e.state.callDepth)uf(e,a);else if(e.state.fullyUnsetLocals?.has(a))e.state.env.delete(a);else if(l!==void 0){let c=e.state.accessedTempEnvVars?.has(a),u=e.state.mutatedTempEnvVars?.has(a);if((c||u)&&e.state.localVarStack?.has(a)){let f=Ds(e,a);f?f.value===void 0?e.state.env.delete(a):e.state.env.set(a,f.value):e.state.env.delete(a)}else e.state.env.delete(a)}else ta(e,a)||e.state.env.delete(a);e.state.exportedVars?.delete(a),e.state.functions.delete(i)}return T("",r,s)}function gm(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function pe(e,t,n,r){return((...s)=>{nr(t,n,`${r} call`);let i=e(...s);return gm(i)?i.then(o=>(nr(t,n,`${r} post-await`),o),o=>{throw nr(t,n,`${r} post-await`),o}):(nr(t,n,`${r} return`),i)})}function wm(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 ra(e,t){if(!e.requireDefenseContext)return e;let n=`command:${t}`,r=Object.getOwnPropertyDescriptors(e);r.fs={value:wm(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 df="+ ";async function pf(e){let t=e.state.env.get("PS4");if(t===void 0)return df;if(t==="")return"";let n=e.state.options.xtrace;e.state.options.xtrace=!1;let r=e.state.lastExitCode,s=e.state.env.get("?"),i=e.state.lastSubstitutionExitCode;try{let a=new H().parseWordFromString(t,!1,!1);return await ie(e,a)}catch(o){if(o instanceof le&&!o.fatal)return t;if(o instanceof Vt||o instanceof Error&&o.name==="AbortError")throw o;return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
712
- `,t||df}finally{e.state.options.xtrace=n,e.state.lastExitCode=r,e.state.lastSubstitutionExitCode=i,s===void 0?e.state.env.delete("?"):e.state.env.set("?",s)}}function Em(e){return e.map(t=>bm(t)).join(" ")}function bm(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let n=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
716
+ `,s=1;continue}lr(e,a);let l=mo(e,a);if(l!==void 0&&l!==e.state.callDepth)gf(e,a);else if(e.state.fullyUnsetLocals?.has(a))e.state.env.delete(a);else if(l!==void 0){let c=e.state.accessedTempEnvVars?.has(a),u=e.state.mutatedTempEnvVars?.has(a);if((c||u)&&e.state.localVarStack?.has(a)){let f=_s(e,a);f?f.value===void 0?e.state.env.delete(a):e.state.env.set(a,f.value):e.state.env.delete(a)}else e.state.env.delete(a)}else aa(e,a)||e.state.env.delete(a);e.state.exportedVars?.delete(a),e.state.functions.delete(i)}return T("",r,s)}function km(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function pe(e,t,n,r){return((...s)=>{or(t,n,`${r} call`);let i=e(...s);return km(i)?i.then(o=>(or(t,n,`${r} post-await`),o),o=>{throw or(t,n,`${r} post-await`),o}):(or(t,n,`${r} return`),i)})}function $m(e,t,n){let r={readFile:pe(e.readFile.bind(e),t,n,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:pe(e.readFileBytes.bind(e),t,n,"fs.readFileBytes")}:Object.create(null),readFileBuffer:pe(e.readFileBuffer.bind(e),t,n,"fs.readFileBuffer"),writeFile:pe(e.writeFile.bind(e),t,n,"fs.writeFile"),appendFile:pe(e.appendFile.bind(e),t,n,"fs.appendFile"),exists:pe(e.exists.bind(e),t,n,"fs.exists"),stat:pe(e.stat.bind(e),t,n,"fs.stat"),mkdir:pe(e.mkdir.bind(e),t,n,"fs.mkdir"),readdir:pe(e.readdir.bind(e),t,n,"fs.readdir"),rm:pe(e.rm.bind(e),t,n,"fs.rm"),cp:pe(e.cp.bind(e),t,n,"fs.cp"),mv:pe(e.mv.bind(e),t,n,"fs.mv"),resolvePath:pe(e.resolvePath.bind(e),t,n,"fs.resolvePath"),getAllPaths:pe(e.getAllPaths.bind(e),t,n,"fs.getAllPaths"),chmod:pe(e.chmod.bind(e),t,n,"fs.chmod"),symlink:pe(e.symlink.bind(e),t,n,"fs.symlink"),link:pe(e.link.bind(e),t,n,"fs.link"),readlink:pe(e.readlink.bind(e),t,n,"fs.readlink"),lstat:pe(e.lstat.bind(e),t,n,"fs.lstat"),realpath:pe(e.realpath.bind(e),t,n,"fs.realpath"),utimes:pe(e.utimes.bind(e),t,n,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=pe(e.readdirWithFileTypes.bind(e),t,n,"fs.readdirWithFileTypes")),e.createExclusive&&(r.createExclusive=pe(e.createExclusive.bind(e),t,n,"fs.createExclusive")),r}function ca(e,t){if(!e.requireDefenseContext)return e;let n=`command:${t}`,r=Object.getOwnPropertyDescriptors(e);r.fs={value:$m(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 Ef="+ ";async function bf(e){let t=e.state.env.get("PS4");if(t===void 0)return Ef;if(t==="")return"";let n=e.state.options.xtrace;e.state.options.xtrace=!1;let r=e.state.lastExitCode,s=e.state.env.get("?"),i=e.state.lastSubstitutionExitCode;try{let a=new H().parseWordFromString(t,!1,!1);return await re(e,a)}catch(o){if(o instanceof ae&&!o.fatal)return t;if(o instanceof zt||o instanceof Error&&o.name==="AbortError")throw o;return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
717
+ `,t||Ef}finally{e.state.options.xtrace=n,e.state.lastExitCode=r,e.state.lastSubstitutionExitCode=i,s===void 0?e.state.env.delete("?"):e.state.env.set("?",s)}}function Pm(e){return e.map(t=>Cm(t)).join(" ")}function Cm(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let n=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
713
718
  `),s=e.includes(" "),i=e.includes("\\"),o=e.includes("'");if(n||r||s||i){let l="";for(let c of e){let u=c.charCodeAt(0);c===`
714
- `?l+="\\n":c===" "?l+="\\t":c==="\\"?l+="\\\\":c==="'"?l+="'":c==='"'?l+='"':u<32||u===127?u<256?l+=`\\x${u.toString(16).padStart(2,"0")}`:l+=`\\u${u.toString(16).padStart(4,"0")}`:l+=c}return`$'${l}'`}return o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function hf(e,t,n){if(!e.state.options.xtrace)return"";let r=await pf(e),s=[t,...n],i=Em(s);return`${r}${i}
715
- `}async function mf(e,t,n){return e.state.options.xtrace?`${await pf(e)}${t}=${n}
716
- `:""}function Gs(e,t,n){return qt([t,n],"",e.limits.maxStringLength,"array assignment")}async function yf(e,t){let n=new Map,r="";for(let s of t.assignments){let i=s.name;if(s.array){let u=await Sm(e,t,i,s.array,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};if(r+=u.xtraceOutput,u.continueToNext)continue}let o=s.value?await ie(e,s.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:T("",`bash: ${i}: bad array subscript
717
- `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let u=await $m(e,t,l[1],l[2],o,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};if(u.continueToNext)continue}let c=await Pm(e,t,i,o,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};r+=c.xtraceOutput,c.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:n}}async function Sm(e,t,n,r,s,i){let o="";if(/\[.+\]$/.test(n))return{continueToNext:!1,xtraceOutput:"",error:T("",`bash: ${n}: cannot assign list to array member
718
- `,1)};if(ce(e,n)){let h=kn(e,n);if(h===void 0||h==="")throw new q(1,"","");let y=Be(e,n);if(y&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(y))return{continueToNext:!1,xtraceOutput:"",error:T("",`bash: ${n}: cannot assign list to array member
719
+ `?l+="\\n":c===" "?l+="\\t":c==="\\"?l+="\\\\":c==="'"?l+="'":c==='"'?l+='"':u<32||u===127?u<256?l+=`\\x${u.toString(16).padStart(2,"0")}`:l+=`\\u${u.toString(16).padStart(4,"0")}`:l+=c}return`$'${l}'`}return o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function Sf(e,t,n){if(!e.state.options.xtrace)return"";let r=await bf(e),s=[t,...n],i=Pm(s);return`${r}${i}
720
+ `}async function Af(e,t,n){return e.state.options.xtrace?`${await bf(e)}${t}=${n}
721
+ `:""}function Ks(e,t,n){return jt([t,n],"",e.limits.maxStringLength,"array assignment")}async function vf(e,t){let n=new Map,r="";for(let s of t.assignments){let i=s.name;if(s.array){let u=await Nm(e,t,i,s.array,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};if(r+=u.xtraceOutput,u.continueToNext)continue}let o=s.value?await re(e,s.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:T("",`bash: ${i}: bad array subscript
722
+ `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let u=await _m(e,t,l[1],l[2],o,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};if(u.continueToNext)continue}let c=await Lm(e,t,i,o,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};r+=c.xtraceOutput,c.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:n}}async function Nm(e,t,n,r,s,i){let o="";if(/\[.+\]$/.test(n))return{continueToNext:!1,xtraceOutput:"",error:T("",`bash: ${n}: cannot assign list to array member
723
+ `,1)};if(ce(e,n)){let h=Cn(e,n);if(h===void 0||h==="")throw new q(1,"","");let y=Be(e,n);if(y&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(y))return{continueToNext:!1,xtraceOutput:"",error:T("",`bash: ${n}: cannot assign list to array member
719
724
  `,1)}}if(We(e,n)){if(t.name)return o+=`bash: ${n}: readonly variable
720
- `,{continueToNext:!0,xtraceOutput:o};let h=ue(e,n);if(h)return{continueToNext:!1,xtraceOutput:"",error:h}}let a=e.state.associativeArrays?.has(n),l=xe(e,n),c=l?Me(l):void 0,u=e.state.env.get(n),f=()=>{e.state.arrays??=new Map,c?e.state.arrays.set(n,c):e.state.arrays.delete(n),u===void 0?e.state.env.delete(n):e.state.env.set(n,u)},d=Am(r),p=()=>{ge(e,n),e.state.env.delete(n)};try{a&&d?await vm(e,t,n,r,s,p,h=>{o+=h}):d?await xm(e,n,r,s,p):await km(e,n,r,s,p)}catch(h){throw f(),h}if(t.name){i.set(n,e.state.env.get(n));let y=`(${r.map(E=>Tn(E)).join(" ")})`;e.state.env.set(n,y)}return{continueToNext:!0,xtraceOutput:o}}function Am(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 vm(e,t,n,r,s,i,o){let a=[];for(let l of r){if(a.length>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let c=ui(l);if(c){let{key:u,valueParts:f,append:d}=c,p;f.length>0?(p=await ie(e,{type:"Word",parts:f}),f.every(y=>y.type==="Literal"||y.type==="TildeExpansion")&&(p=rn(e,p))):p="",a.push({type:"keyed",key:u,value:p,append:d})}else{let u=await ie(e,l);a.push({type:"invalid",expandedValue:u})}}e.executionScope.consumeWork(a.length,"associative array assignment"),s||i();for(let l of a)if(l.type==="keyed")if(l.append){let c=ae(e,n,l.key)??"";j(e,n,l.key,Gs(e,c,l.value),"associative")}else j(e,n,l.key,l.value,"associative");else{let c=t.line??e.state.currentLine??1;o(`bash: line ${c}: ${n}: ${l.expandedValue}: must use subscript when assigning associative array
721
- `)}}async function xm(e,t,n,r,s){let i=[],o=0;for(let l of n){let c=ui(l);if(c){if(o>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let{key:u,valueParts:f,append:d}=c,p;f.length>0?(p=await ie(e,{type:"Word",parts:f}),f.every(y=>y.type==="Literal"||y.type==="TildeExpansion")&&(p=rn(e,p))):p="",i.push({type:"keyed",indexExpr:u,value:p,append:d}),o++}else{let u=await bt(e,l);if(u.values.length>e.limits.maxArrayElements-o)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push({type:"non-keyed",values:u.values}),o+=u.values.length}}e.executionScope.consumeWork(o,"indexed array assignment"),r||s();let a=0;for(let l of i)if(l.type==="keyed"){let c;try{let u=new H,f=se(u,l.indexExpr);c=await Y(e,f.expression,!1)}catch{if(/^-?\d+$/.test(l.indexExpr))c=Number.parseInt(l.indexExpr,10);else{let u=e.state.env.get(l.indexExpr);c=u?Number.parseInt(u,10):0,Number.isNaN(c)&&(c=0)}}if(l.append){let u=ae(e,t,c)??"";j(e,t,c,Gs(e,u,l.value))}else j(e,t,c,l.value);a=c+1}else for(let c of l.values)j(e,t,a++,c)}async function km(e,t,n,r,s){let i=[];for(let a of n){let l=await bt(e,a);for(let c of l.values){if(i.length>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push(c)}}let o=0;if(e.executionScope.consumeWork(i.length,"indexed array assignment"),r){let a=G(e,t);if(a.length>0)o=Math.max(...a.map(([c])=>typeof c=="number"?c: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 $m(e,t,n,r,s,i,o){let a=n;if(ce(e,n)){let f=Be(e,n);if(f&&f!==n){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:T("",`bash: \`${f}': not a valid identifier
722
- `,1)};a=f}}if(We(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),c;if(l)c=await gf(e,r);else{let f=await sa(e,a,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};c=String(f.index)}let u=i?Gs(e,ae(e,a,c)||"",s):s;return t.name||j(e,a,c,u,l?"associative":"indexed"),{continueToNext:!0,xtraceOutput:""}}async function gf(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 H().parseWordFromString(r,!0,!1);n=await ie(e,i)}else if(t.includes("$")){let s=new H().parseWordFromString(t,!1,!1);n=await ie(e,s)}else n=t;return n}async function sa(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 H,o=se(i,r);s=await Y(e,o.expression,!1)}catch(i){if(i instanceof q||i instanceof Pe)throw i;if(i instanceof le){let l=`bash: line ${e.state.currentLine}: ${n}: ${i.message}
725
+ `,{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=xe(e,n),c=l?Me(l):void 0,u=e.state.env.get(n),f=()=>{e.state.arrays??=new Map,c?e.state.arrays.set(n,c):e.state.arrays.delete(n),u===void 0?e.state.env.delete(n):e.state.env.set(n,u)},d=Rm(r),p=()=>{ge(e,n),e.state.env.delete(n)};try{a&&d?await Dm(e,t,n,r,s,p,h=>{o+=h}):d?await Im(e,n,r,s,p):await Om(e,n,r,s,p)}catch(h){throw f(),h}if(t.name){i.set(n,e.state.env.get(n));let y=`(${r.map(E=>Mn(E)).join(" ")})`;e.state.env.set(n,y)}return{continueToNext:!0,xtraceOutput:o}}function Rm(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 Dm(e,t,n,r,s,i,o){let a=[];for(let l of r){if(a.length>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let c=hi(l);if(c){let{key:u,valueParts:f,append:d}=c,p;f.length>0?(p=await re(e,{type:"Word",parts:f}),f.every(y=>y.type==="Literal"||y.type==="TildeExpansion")&&(p=on(e,p))):p="",a.push({type:"keyed",key:u,value:p,append:d})}else{let u=await re(e,l);a.push({type:"invalid",expandedValue:u})}}e.executionScope.consumeWork(a.length,"associative array assignment"),s||i();for(let l of a)if(l.type==="keyed")if(l.append){let c=oe(e,n,l.key)??"";j(e,n,l.key,Ks(e,c,l.value),"associative")}else j(e,n,l.key,l.value,"associative");else{let c=t.line??e.state.currentLine??1;o(`bash: line ${c}: ${n}: ${l.expandedValue}: must use subscript when assigning associative array
726
+ `)}}async function Im(e,t,n,r,s){let i=[],o=0;for(let l of n){let c=hi(l);if(c){if(o>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let{key:u,valueParts:f,append:d}=c,p;f.length>0?(p=await re(e,{type:"Word",parts:f}),f.every(y=>y.type==="Literal"||y.type==="TildeExpansion")&&(p=on(e,p))):p="",i.push({type:"keyed",indexExpr:u,value:p,append:d}),o++}else{let u=await At(e,l);if(u.values.length>e.limits.maxArrayElements-o)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push({type:"non-keyed",values:u.values}),o+=u.values.length}}e.executionScope.consumeWork(o,"indexed array assignment"),r||s();let a=0;for(let l of i)if(l.type==="keyed"){let c;try{let u=new H,f=ne(u,l.indexExpr);c=await Y(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=oe(e,t,c)??"";j(e,t,c,Ks(e,u,l.value))}else j(e,t,c,l.value);a=c+1}else for(let c of l.values)j(e,t,a++,c)}async function Om(e,t,n,r,s){let i=[];for(let a of n){let l=await At(e,a);for(let c of l.values){if(i.length>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push(c)}}let o=0;if(e.executionScope.consumeWork(i.length,"indexed array assignment"),r){let a=G(e,t);if(a.length>0)o=Math.max(...a.map(([c])=>typeof c=="number"?c:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(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 _m(e,t,n,r,s,i,o){let a=n;if(ce(e,n)){let f=Be(e,n);if(f&&f!==n){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:T("",`bash: \`${f}': not a valid identifier
727
+ `,1)};a=f}}if(We(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),c;if(l)c=await xf(e,r);else{let f=await ua(e,a,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};c=String(f.index)}let u=i?Ks(e,oe(e,a,c)||"",s):s;return t.name||j(e,a,c,u,l?"associative":"indexed"),{continueToNext:!0,xtraceOutput:""}}async function xf(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 H().parseWordFromString(r,!0,!1);n=await re(e,i)}else if(t.includes("$")){let s=new H().parseWordFromString(t,!1,!1);n=await re(e,s)}else n=t;return n}async function ua(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 H,o=ne(i,r);s=await Y(e,o.expression,!1)}catch(i){if(i instanceof q||i instanceof Pe)throw i;if(i instanceof ae){let l=`bash: line ${e.state.currentLine}: ${n}: ${i.message}
723
728
  `;if(i.fatal)throw new q(1,"",l);return{index:0,error:T("",l,1)}}let o=e.state.currentLine;return{index:0,error:T("",`bash: line ${o}: ${t}[${n}]: bad array subscript
724
729
  `,1)}}Number.isNaN(s)&&(s=0)}if(s<0){let i=G(e,t);if(i.length===0){let a=e.state.currentLine;return{index:0,error:T("",`bash: line ${a}: ${t}[${n}]: bad array subscript
725
730
  `,1)}}if(s=Math.max(...i.map(([a])=>typeof a=="number"?a:0))+1+s,s<0){let a=e.state.currentLine;return{index:0,error:T("",`bash: line ${a}: ${t}[${n}]: bad array subscript
726
- `,1)}}}return{index:s}}async function Pm(e,t,n,r,s,i){let o="",a=n,l=null;if(ce(e,n)){let f=ss(e,n,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:T("",`bash: ${n}: circular name reference
731
+ `,1)}}}return{index:s}}async function Lm(e,t,n,r,s,i){let o="",a=n,l=null;if(ce(e,n)){let f=as(e,n,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:T("",`bash: ${n}: circular name reference
727
732
  `,1)};if(f===null)return{continueToNext:!0,xtraceOutput:""};a=f;let d=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(l={arrayName:d[1],subscriptExpr:d[2]},a=d[1])}if(We(e,a)){if(t.name)return o+=`bash: ${a}: readonly variable
728
- `,{continueToNext:!0,xtraceOutput:o};let f=ue(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let c;if(Sr(e,a))try{let f=new H;if(s){let p=`(${e.state.env.get(a)||"0"}) + (${r})`,h=se(f,p);c=String(await Y(e,h.expression))}else{let d=se(f,r);c=String(await Y(e,d.expression))}}catch{c="0"}else{let f=yt(e,a)?ae(e,a,0):e.state.env.get(a);c=s?Gs(e,f||"",r):r}c=Kn(e,a,c),o+=await mf(e,a,c);let u;return l?u=await Cm(e,l):yt(e,a)&&(u="0"),t.name?u===void 0&&(i.set(a,e.state.env.get(a)),e.state.env.set(a,c)):(u===void 0?e.state.env.set(a,c):j(e,a,u,c),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(a)),e.state.tempEnvBindings?.some(f=>f.has(a))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(a))),{continueToNext:!1,xtraceOutput:o}}async function Cm(e,t){let{arrayName:n,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(n))return gf(e,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let o=new H,a=se(o,r);i=await Y(e,a.expression,!1)}catch{let o=e.state.env.get(r);i=o?Number.parseInt(o,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let o=G(e,n);o.length>0&&(i=Math.max(...o.map(l=>l[0]))+1+i)}return String(i)}async function bf(e,t,n,r){let s=!1,i=!1,o=!1,a=!1,l=!1,c=[];for(let y of t)if(y.startsWith("-")&&y.length>1)for(let E of y.slice(1))E==="t"?s=!0:E==="p"?i=!0:E==="P"?o=!0:E==="a"?a=!0:E==="f"&&(l=!0);else c.push(y);let u="",f="",d=0,p=!1,h=!1;for(let y of c){let E=!1;if(o){if(a){let x=await r(y);if(x.length>0){for(let v of x)u+=`${v}
733
+ `,{continueToNext:!0,xtraceOutput:o};let f=ue(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let c;if(xr(e,a))try{let f=new H;if(s){let p=`(${e.state.env.get(a)||"0"}) + (${r})`,h=ne(f,p);c=String(await Y(e,h.expression))}else{let d=ne(f,r);c=String(await Y(e,d.expression))}}catch{c="0"}else{let f=wt(e,a)?oe(e,a,0):e.state.env.get(a);c=s?Ks(e,f||"",r):r}c=Yn(e,a,c),o+=await Af(e,a,c);let u;return l?u=await Tm(e,l):wt(e,a)&&(u="0"),t.name?u===void 0&&(i.set(a,e.state.env.get(a)),e.state.env.set(a,c)):(u===void 0?e.state.env.set(a,c):j(e,a,u,c),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(a)),e.state.tempEnvBindings?.some(f=>f.has(a))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(a))),{continueToNext:!1,xtraceOutput:o}}async function Tm(e,t){let{arrayName:n,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(n))return xf(e,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let o=new H,a=ne(o,r);i=await Y(e,a.expression,!1)}catch{let o=e.state.env.get(r);i=o?Number.parseInt(o,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let o=G(e,n);o.length>0&&(i=Math.max(...o.map(l=>l[0]))+1+i)}return String(i)}async function Pf(e,t,n,r){let s=!1,i=!1,o=!1,a=!1,l=!1,c=[];for(let y of t)if(y.startsWith("-")&&y.length>1)for(let E of y.slice(1))E==="t"?s=!0:E==="p"?i=!0:E==="P"?o=!0:E==="a"?a=!0:E==="f"&&(l=!0);else c.push(y);let u="",f="",d=0,p=!1,h=!1;for(let y of c){let E=!1;if(o){if(a){let x=await r(y);if(x.length>0){for(let A of x)u+=`${A}
729
734
  `;p=!0,E=!0}}else{let x=await n(y);x&&(u+=`${x}
730
735
  `,p=!0,E=!0)}E||(h=!0);continue}let S=!l&&e.state.functions.has(y);if(a&&S){if(!i)if(s)u+=`function
731
- `;else{let x=e.state.functions.get(y),v=x?wf(y,x):`${y} is a function
732
- `;u+=v}E=!0}let g=e.state.env.get(`BASH_ALIAS_${y}`);if(g!==void 0&&(a||!E)&&(i||(s?u+=`alias
733
- `:u+=`${y} is aliased to \`${g}'
734
- `),E=!0,!a)||or.has(y)&&(a||!E)&&(i||(s?u+=`keyword
736
+ `;else{let x=e.state.functions.get(y),A=x?kf(y,x):`${y} is a function
737
+ `;u+=A}E=!0}let m=e.state.env.get(`BASH_ALIAS_${y}`);if(m!==void 0&&(a||!E)&&(i||(s?u+=`alias
738
+ `:u+=`${y} is aliased to \`${m}'
739
+ `),E=!0,!a)||ur.has(y)&&(a||!E)&&(i||(s?u+=`keyword
735
740
  `:u+=`${y} is a shell keyword
736
741
  `),E=!0,!a))continue;if(!a&&S&&!E){if(!i)if(s)u+=`function
737
- `;else{let x=e.state.functions.get(y),v=x?wf(y,x):`${y} is a function
738
- `;u+=v}E=!0;continue}if(!(vt.has(y)&&(a||!E)&&(i||(s?u+=`builtin
742
+ `;else{let x=e.state.functions.get(y),A=x?kf(y,x):`${y} is a function
743
+ `;u+=A}E=!0;continue}if(!(kt.has(y)&&(a||!E)&&(i||(s?u+=`builtin
739
744
  `:u+=`${y} is a shell builtin
740
- `),E=!0,!a))){if(a){let x=await r(y);for(let v of x)i?u+=`${v}
745
+ `),E=!0,!a))){if(a){let x=await r(y);for(let A of x)i?u+=`${A}
741
746
  `:s?u+=`file
742
- `:u+=`${y} is ${v}
747
+ `:u+=`${y} is ${A}
743
748
  `,p=!0,E=!0}else if(!E){let x=await n(y);x&&(i?u+=`${x}
744
749
  `:s?u+=`file
745
750
  `:u+=`${y} is ${x}
746
- `,p=!0,E=!0)}if(!E&&(h=!0,!s&&!i)){let x=!0;if(y.includes("/")){let v=e.fs.resolvePath(e.state.cwd,y);await e.fs.exists(v)&&(x=!1)}x&&(f+=`bash: type: ${y}: not found
747
- `)}}}return i?d=h&&!p?1:0:d=h?1:0,T(u,f,d)}function wf(e,t){let n;return t.body.type==="Group"?n=t.body.body.map(s=>xr(s)).join("; "):n=xr(t.body),`${e} is a function
751
+ `,p=!0,E=!0)}if(!E&&(h=!0,!s&&!i)){let x=!0;if(y.includes("/")){let A=e.fs.resolvePath(e.state.cwd,y);await e.fs.exists(A)&&(x=!1)}x&&(f+=`bash: type: ${y}: not found
752
+ `)}}}return i?d=h&&!p?1:0:d=h?1:0,T(u,f,d)}function kf(e,t){let n;return t.body.type==="Group"?n=t.body.body.map(s=>Pr(s)).join("; "):n=Pr(t.body),`${e} is a function
748
753
  ${e} ()
749
754
  {
750
755
  ${n}
751
756
  }
752
- `}function xr(e){if(Array.isArray(e))return e.map(t=>xr(t)).join("; ");if(e.type==="Statement"){let t=[];for(let n=0;n<e.pipelines.length;n++){let r=e.pipelines[n];t.push(Nm(r)),e.operators[n]&&t.push(e.operators[n])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,n=[];t.name&&n.push(Ef(t.name));for(let r of t.args)n.push(Ef(r));return n.join(" ")}return e.type==="Group"?`{ ${e.body.map(r=>xr(r)).join("; ")}; }`:"..."}function Ef(e){return e.parts.map(Sf).join("")}function Sf(e){switch(e.type){case"Literal":return e.value;case"Escaped":return`\\${e.value}`;case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(Sf).join("")}"`;default:return Ae(F.word([e]))}}function Nm(e){let t=e.commands.map(n=>xr(n));return(e.negated?"! ":"")+t.join(" | ")}async function Af(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}"
757
+ `}function Pr(e){if(Array.isArray(e))return e.map(t=>Pr(t)).join("; ");if(e.type==="Statement"){let t=[];for(let n=0;n<e.pipelines.length;n++){let r=e.pipelines[n];t.push(Fm(r)),e.operators[n]&&t.push(e.operators[n])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,n=[];t.name&&n.push($f(t.name));for(let r of t.args)n.push($f(r));return n.join(" ")}return e.type==="Group"?`{ ${e.body.map(r=>Pr(r)).join("; ")}; }`:"..."}function $f(e){return e.parts.map(Cf).join("")}function Cf(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(Cf).join("")}"`;default:return Ae(F.word([e]))}}function Fm(e){let t=e.commands.map(n=>Pr(n));return(e.negated?"! ":"")+t.join(" | ")}async function Nf(e,t,n,r){let s="",i="",o=0;for(let a of t){if(!a){o=1;continue}let l=e.state.env.get(`BASH_ALIAS_${a}`);if(l!==void 0)r?s+=`${a} is an alias for "${l}"
753
758
  `:s+=`alias ${a}='${l}'
754
- `;else if(or.has(a))r?s+=`${a} is a shell keyword
759
+ `;else if(ur.has(a))r?s+=`${a} is a shell keyword
755
760
  `:s+=`${a}
756
- `;else if(vt.has(a))r?s+=`${a} is a shell builtin
761
+ `;else if(kt.has(a))r?s+=`${a} is a shell builtin
757
762
  `:s+=`${a}
758
763
  `;else if(e.state.functions.has(a))r?s+=`${a} is a function
759
764
  `:s+=`${a}
@@ -763,53 +768,53 @@ ${e} ()
763
768
  `),o=1)}else if(e.commands.has(a)){let u=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of u){if(!d)continue;let p=`${d}/${a}`;try{let h=await e.fs.stat(p);if(!h.isDirectory&&(h.mode&73)!==0){f=p;break}}catch{}}f||(f=`/usr/bin/${a}`),r?s+=`${a} is ${f}
764
769
  `:s+=`${f}
765
770
  `}else r&&(i+=`${a}: not found
766
- `),o=1}return T(s,i,o)}async function vf(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 xf(e,t){let n=!0,r=e.signal?new AbortController:void 0,s=new WeakMap,i=()=>{if(!n)throw new Ye("",`bash: ${t} used its context after cancellation
767
- `)},o=f=>{if(f===null||typeof f!="object"&&typeof f!="function")return f;let d=s.get(f);if(d!==void 0)return d;if(typeof f=="object"&&Ia(f))return f;if(f instanceof Uint8Array){let E=new Uint8Array(f);return s.set(f,E),E}if(f instanceof ArrayBuffer){let E=f.slice(0);return s.set(f,E),E}if(f instanceof Promise){let E=f.then(S=>(i(),o(S)));return s.set(f,E),E}if(typeof f=="function"){let E=function(...S){return i(),o(Reflect.apply(f,this,S))};return s.set(f,E),E}let p=Object.getPrototypeOf(f);if(Array.isArray(f)||p===Object.prototype||p===null){let E=Array.isArray(f)?[]:Object.create(p);s.set(f,E);let S=Object.getOwnPropertyDescriptors(f);for(let g of Object.values(S)){if("value"in g){let m=g.value;g.value=typeof m=="function"?(...b)=>(i(),o(Reflect.apply(m,f,b))):o(m)}if(g.get){let m=g.get;g.get=()=>(i(),o(Reflect.apply(m,f,[])))}if(g.set){let m=g.set;g.set=b=>{i(),Reflect.apply(m,f,[b])}}}return Object.defineProperties(E,S),E}let h=new Map,y=new Sa(f,{get(E,S){if(i(),S==="constructor"||S==="prototype"||S==="__proto__")throw new Error(`${t}: unsafe context property access`);let g=Reflect.get(E,S,E);if(typeof g!="function")return o(g);if(h.has(S))return h.get(S);let m=(...b)=>(i(),o(Reflect.apply(g,E,b)));return h.set(S,m),m},set(E,S,g){if(i(),S==="constructor"||S==="prototype"||S==="__proto__")throw new Error(`${t}: unsafe context property access`);return Reflect.set(E,S,g,E)}});return s.set(f,y),y},a=f=>o(f),l=f=>f&&((...d)=>(i(),o(f(...d)))),c=f=>({value:f,enumerable:!0,configurable:!0,writable:!0}),u=Object.getOwnPropertyDescriptors(e);return Object.assign(u,{fs:c(a(e.fs)),env:c(a(e.env)),limits:c(Object.freeze({...e.limits})),exportedEnv:c(e.exportedEnv?Object.freeze({...e.exportedEnv}):void 0),executionScope:c(e.executionScope?a(e.executionScope):void 0),fileDescriptors:c(e.fileDescriptors?a(e.fileDescriptors):void 0),coverage:c(e.coverage?a(e.coverage):void 0),assignShellVariable:c(l(e.assignShellVariable)),exec:c(l(e.exec)),origCommand:c(l(e.origCommand)),execWithInheritedStdin:c(l(e.execWithInheritedStdin)),fetch:c(l(e.fetch)),getRegisteredCommands:c(l(e.getRegisteredCommands)),sleep:c(l(e.sleep)),trace:c(l(e.trace)),invokeTool:c(l(e.invokeTool)),signal:c(r?.signal)}),{context:Object.defineProperties(Object.create(Object.getPrototypeOf(e)),u),revoke(){n=!1,r?.signal.aborted||r?.abort(new Ye("",`bash: ${t} context revoked
768
- `))}}}async function Rm(e,t,n,r,s,i){let o=s.remainingTimeMs()??t.limits.maxExecutionTimeMs,a=t.limits.maxExtensionCleanupTimeMs,l,c,u,d=Promise.resolve().then(e).then(h=>({kind:"result",result:h}),h=>({kind:"error",error:h})),p=new Promise(h=>{let y=()=>{n(),h({kind:"abort"})};c=y,i?.addEventListener("abort",y,{once:!0}),i?.aborted&&y(),l=Jn(()=>{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 y=await Promise.race([d.then(()=>!0),new Promise(S=>{u=Jn(()=>S(!1),a)})]),E=h.kind==="deadline"?new Ye("",`bash: ${r} exceeded its execution deadline
771
+ `),o=1}return T(s,i,o)}async function Rf(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 Df(e,t){let n=!0,r=e.signal?new AbortController:void 0,s=new WeakMap,i=()=>{if(!n)throw new Ye("",`bash: ${t} used its context after cancellation
772
+ `)},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"&&Wa(f))return f;if(f instanceof Uint8Array){let E=new Uint8Array(f);return s.set(f,E),E}if(f instanceof ArrayBuffer){let E=f.slice(0);return s.set(f,E),E}if(f instanceof Promise){let E=f.then(S=>(i(),o(S)));return s.set(f,E),E}if(typeof f=="function"){let E=function(...S){return i(),o(Reflect.apply(f,this,S))};return s.set(f,E),E}let p=Object.getPrototypeOf(f);if(Array.isArray(f)||p===Object.prototype||p===null){let E=Array.isArray(f)?[]:Object.create(p);s.set(f,E);let S=Object.getOwnPropertyDescriptors(f);for(let m of Object.values(S)){if("value"in m){let g=m.value;m.value=typeof g=="function"?(...b)=>(i(),o(Reflect.apply(g,f,b))):o(g)}if(m.get){let g=m.get;m.get=()=>(i(),o(Reflect.apply(g,f,[])))}if(m.set){let g=m.set;m.set=b=>{i(),Reflect.apply(g,f,[b])}}}return Object.defineProperties(E,S),E}let h=new Map,y=new Ca(f,{get(E,S){if(i(),S==="constructor"||S==="prototype"||S==="__proto__")throw new Error(`${t}: unsafe context property access`);let m=Reflect.get(E,S,E);if(typeof m!="function")return o(m);if(h.has(S))return h.get(S);let g=(...b)=>(i(),o(Reflect.apply(m,E,b)));return h.set(S,g),g},set(E,S,m){if(i(),S==="constructor"||S==="prototype"||S==="__proto__")throw new Error(`${t}: unsafe context property access`);return Reflect.set(E,S,m,E)}});return s.set(f,y),y},a=f=>o(f),l=f=>f&&((...d)=>(i(),o(f(...d)))),c=f=>({value:f,enumerable:!0,configurable:!0,writable:!0}),u=Object.getOwnPropertyDescriptors(e);return Object.assign(u,{fs:c(a(e.fs)),env:c(a(e.env)),limits:c(Object.freeze({...e.limits})),exportedEnv:c(e.exportedEnv?Object.freeze({...e.exportedEnv}):void 0),executionScope:c(e.executionScope?a(e.executionScope):void 0),fileDescriptors:c(e.fileDescriptors?a(e.fileDescriptors):void 0),coverage:c(e.coverage?a(e.coverage):void 0),assignShellVariable:c(l(e.assignShellVariable)),exec:c(l(e.exec)),origCommand:c(l(e.origCommand)),execWithInheritedStdin:c(l(e.execWithInheritedStdin)),fetch:c(l(e.fetch)),getRegisteredCommands:c(l(e.getRegisteredCommands)),sleep:c(l(e.sleep)),trace:c(l(e.trace)),invokeTool:c(l(e.invokeTool)),signal:c(r?.signal)}),{context:Object.defineProperties(Object.create(Object.getPrototypeOf(e)),u),revoke(){n=!1,r?.signal.aborted||r?.abort(new Ye("",`bash: ${t} context revoked
773
+ `))}}}async function Mm(e,t,n,r,s,i){let o=s.remainingTimeMs()??t.limits.maxExecutionTimeMs,a=t.limits.maxExtensionCleanupTimeMs,l,c,u,d=Promise.resolve().then(e).then(h=>({kind:"result",result:h}),h=>({kind:"error",error:h})),p=new Promise(h=>{let y=()=>{n(),h({kind:"abort"})};c=y,i?.addEventListener("abort",y,{once:!0}),i?.aborted&&y(),l=nr(()=>{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 y=await Promise.race([d.then(()=>!0),new Promise(S=>{u=nr(()=>S(!1),a)})]),E=h.kind==="deadline"?new Ye("",`bash: ${r} exceeded its execution deadline
769
774
  `):new Ye("",`bash: execution aborted
770
- `);throw y||s.poisonAfterAbort(E),E}finally{n(),er(l),er(u),c&&i?.removeEventListener("abort",c)}}var kf={export:(e,t)=>qo(e.ctx,t),unset:(e,t)=>na(e.ctx,t),exit:(e,t)=>Uo(e.ctx,t),local:(e,t)=>Zo(e.ctx,t),set:(e,t)=>Jo(e.ctx,t),break:(e,t)=>no(e.ctx,t),continue:(e,t)=>Do(e.ctx,t),return:(e,t)=>Ko(e.ctx,t),shift:(e,t)=>ea(e.ctx,t),getopts:(e,t)=>Us(e.ctx,t),compgen:(e,t)=>$o(e.ctx,t),complete:(e,t)=>No(e.ctx,t),compopt:(e,t)=>Ro(e.ctx,t),pushd:(e,t)=>Bo(e.ctx,t),popd:(e,t)=>Wo(e.ctx,t),dirs:(e,t)=>Vo(e.ctx,t),source:(e,t)=>Hs(e.ctx,t),".":(e,t)=>Hs(e.ctx,t),read:(e,t,n)=>Qo(e.ctx,t,n.stdin,n.stdinSourceFd),mapfile:(e,t,n)=>qs(e.ctx,t,n.stdin),readarray:(e,t,n)=>qs(e.ctx,t,n.stdin),declare:(e,t)=>zs(e.ctx,t),typeset:(e,t)=>zs(e.ctx,t),readonly:(e,t)=>Fo(e.ctx,t),eval:(e,t,n)=>zo(e.ctx,t,n.stdin,n.stdinRedirected),cd:(e,t)=>ro(e.ctx,t),":":()=>ne,true:()=>ne,false:()=>we(!1),let:(e,t)=>Go(e.ctx,t),command:(e,t,n)=>Dm(e,t,n.stdin,n.stdinRedirected),builtin:(e,t,n)=>Im(e,t,n.stdin,n.stdinRedirected),shopt:(e,t)=>Wu(e.ctx,t),exec:async(e,t,n)=>{if(t.length===0)return ne;let[r,...s]=t;return{...await e.runCommand(r,s,[],n.stdin,!1,!1,-1,n.stdinRedirected),internalProducerOmitsShellPrefix:!0}},wait:()=>ne,type:(e,t)=>bf(e.ctx,t,n=>vf(e.ctx,n),n=>qr(e.ctx,n)),hash:(e,t)=>jo(e.ctx,t),help:(e,t)=>Ho(e.ctx,t),"[":(e,t)=>t[t.length-1]!=="]"?L("[: missing `]'\n",2):qn(e.ctx,t.slice(0,-1)),test:(e,t)=>qn(e.ctx,t)};async function $f(e,t,n,r,s,i,o,a,l=!1){let{ctx:c}=e;c.coverage&&vt.has(t)&&c.coverage.hit(`bash:builtin:${t}`);let u={stdin:s,stdinRedirected:l,stdinSourceFd:a},f=va(t),d=(f==="early"||f==="late")&&Object.hasOwn(kf,t)?kf[t]:void 0;if(d&&(f==="early"||c.state.options.posix&&xa(t)))return d(e,n,u);if(!i){let p=c.state.functions.get(t);if(p)return Ms(c,p,n,s,void 0,l)}if(t==="__just_bash_tee_restore"){if(n.length===0||n.length>c.limits.maxArrayElements)return L(`bash: invalid internal pipeline status restore
775
+ `);throw y||s.poisonAfterAbort(E),E}finally{n(),rr(l),rr(u),c&&i?.removeEventListener("abort",c)}}var If={export:(e,t)=>Ko(e.ctx,t),unset:(e,t)=>la(e.ctx,t),exit:(e,t)=>Qo(e.ctx,t),local:(e,t)=>ea(e.ctx,t),set:(e,t)=>ia(e.ctx,t),break:(e,t)=>lo(e.ctx,t),continue:(e,t)=>Fo(e.ctx,t),return:(e,t)=>na(e.ctx,t),shift:(e,t)=>oa(e.ctx,t),getopts:(e,t)=>Hs(e.ctx,t),compgen:(e,t)=>Io(e.ctx,t),complete:(e,t)=>Lo(e.ctx,t),compopt:(e,t)=>To(e.ctx,t),pushd:(e,t)=>jo(e.ctx,t),popd:(e,t)=>Ho(e.ctx,t),dirs:(e,t)=>Go(e.ctx,t),source:(e,t)=>Qs(e.ctx,t),".":(e,t)=>Qs(e.ctx,t),read:(e,t,n)=>ta(e.ctx,t,n.stdin,n.stdinSourceFd),mapfile:(e,t,n)=>Gs(e.ctx,t,n.stdin),readarray:(e,t,n)=>Gs(e.ctx,t,n.stdin),declare:(e,t)=>js(e.ctx,t),typeset:(e,t)=>js(e.ctx,t),readonly:(e,t)=>Uo(e.ctx,t),eval:(e,t,n)=>Zo(e.ctx,t,n.stdin,n.stdinRedirected),cd:(e,t)=>co(e.ctx,t),":":()=>ee,true:()=>ee,false:()=>we(!1),let:(e,t)=>Jo(e.ctx,t),command:(e,t,n)=>Bm(e,t,n.stdin,n.stdinRedirected),builtin:(e,t,n)=>Wm(e,t,n.stdin,n.stdinRedirected),shopt:(e,t)=>Gu(e.ctx,t),exec:async(e,t,n)=>{if(t.length===0)return ee;let[r,...s]=t;return{...await e.runCommand(r,s,[],n.stdin,!1,!1,-1,n.stdinRedirected),internalProducerOmitsShellPrefix:!0}},wait:()=>ee,type:(e,t)=>Pf(e.ctx,t,n=>Rf(e.ctx,n),n=>Gr(e.ctx,n)),hash:(e,t)=>Xo(e.ctx,t),help:(e,t)=>Yo(e.ctx,t),"[":(e,t)=>t[t.length-1]!=="]"?L("[: missing `]'\n",2):Hn(e.ctx,t.slice(0,-1)),test:(e,t)=>Hn(e.ctx,t)};async function Of(e,t,n,r,s,i,o,a,l=!1){let{ctx:c}=e;c.coverage&&kt.has(t)&&c.coverage.hit(`bash:builtin:${t}`);let u={stdin:s,stdinRedirected:l,stdinSourceFd:a},f=Da(t),d=(f==="early"||f==="late")&&Object.hasOwn(If,t)?If[t]:void 0;if(d&&(f==="early"||c.state.options.posix&&Ia(t)))return d(e,n,u);if(!i){let p=c.state.functions.get(t);if(p)return Vs(c,p,n,s,void 0,l)}if(t==="__just_bash_tee_restore"){if(n.length===0||n.length>c.limits.maxArrayElements)return L(`bash: invalid internal pipeline status restore
771
776
  `,2);let p=[];for(let E of n){if(!/^(?:0|[1-9][0-9]{0,2})$/.test(E))return L(`bash: invalid internal pipeline status restore
772
777
  `,2);let S=Number(E);if(!Number.isSafeInteger(S)||S>255)return L(`bash: invalid internal pipeline status restore
773
- `,2);p.push(S)}let h=p[p.length-1]??0,y=[...p].reverse().find(E=>E!==0);return{stdout:"",stderr:"",exitCode:c.state.options.pipefail&&y!==void 0?y:h,internalPipeStatusOverride:p}}return d&&f==="late"?d(e,n,u):null}async function Dm(e,t,n,r=!1){let{ctx:s,runCommand:i}=e;if(t.length===0)return ne;let o=!1,a=!1,l=!1,c=t;for(;c.length>0&&c[0].startsWith("-");){let d=c[0];if(d==="--"){c=c.slice(1);break}for(let p of d.slice(1))p==="p"?o=!0:p==="V"?a=!0:p==="v"&&(l=!0);c=c.slice(1)}if(c.length===0)return ne;if(l||a)return await Af(s,c,l,a);let[u,...f]=c;return i(u,f,[],n,!0,o,-1,r)}async function Im(e,t,n,r=!1){let{runCommand:s}=e;if(t.length===0)return ne;let i=t;if(i[0]==="--"&&(i=i.slice(1),i.length===0))return ne;let o=i[0];if(o!=="__just_bash_tee_restore"&&!vt.has(o))return L(`bash: builtin: ${o}: not a shell builtin
774
- `);let[,...a]=i;return s(o,a,[],n,!0,!1,-1,r)}async function Pf(e,t,n,r,s){let{ctx:i,buildExportedEnv:o,executeUserScript:a}=e,c=await Ur(i,t,s?"/usr/bin:/bin":void 0);if(!c){i.executionScope.recordUnresolvedCommand(t);let A=i.executionScope.abortOnUnresolvedCommands;if(yu(t)){let x=`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
775
- `;if(A)throw new Pe(t,"",x);return L(x,127)}if(A)throw new Pe(t,"",`bash: ${t}: command not found
778
+ `,2);p.push(S)}let h=p[p.length-1]??0,y=[...p].reverse().find(E=>E!==0);return{stdout:"",stderr:"",exitCode:c.state.options.pipefail&&y!==void 0?y:h,internalPipeStatusOverride:p}}return d&&f==="late"?d(e,n,u):null}async function Bm(e,t,n,r=!1){let{ctx:s,runCommand:i}=e;if(t.length===0)return ee;let o=!1,a=!1,l=!1,c=t;for(;c.length>0&&c[0].startsWith("-");){let d=c[0];if(d==="--"){c=c.slice(1);break}for(let p of d.slice(1))p==="p"?o=!0:p==="V"?a=!0:p==="v"&&(l=!0);c=c.slice(1)}if(c.length===0)return ee;if(l||a)return await Nf(s,c,l,a);let[u,...f]=c;return i(u,f,[],n,!0,o,-1,r)}async function Wm(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"&&!kt.has(o))return L(`bash: builtin: ${o}: not a shell builtin
779
+ `);let[,...a]=i;return s(o,a,[],n,!0,!1,-1,r)}async function _f(e,t,n,r,s){let{ctx:i,buildExportedEnv:o,executeUserScript:a}=e,c=await Hr(i,t,s?"/usr/bin:/bin":void 0);if(!c){i.executionScope.recordUnresolvedCommand(t);let v=i.executionScope.abortOnUnresolvedCommands;if(vu(t)){let x=`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
780
+ `;if(v)throw new Pe(t,"",x);return L(x,127)}if(v)throw new Pe(t,"",`bash: ${t}: command not found
776
781
  `);return L(`bash: ${t}: command not found
777
782
  `,127)}if("error"in c)return c.error==="permission_denied"?L(`bash: ${t}: Permission denied
778
783
  `,126):L(`bash: ${t}: No such file or directory
779
- `,127);if("script"in c)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,c.path)),await a(c.path,n,r);let{cmd:u,path:f}=c;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",p=!1,h=o();i.state.fileDescriptors??=new Map;let y={fs:i.fs,fsIdentity:oi(i.fs),cwd:i.state.cwd,env:i.state.env,assignShellVariable:async(A,x,v)=>{if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(A))throw new Error(`${A}: not a valid identifier`);let $=v===void 0?A:`${A}[${v}]`,D=ss(i,A,x);if(D===void 0)throw new Error(`${A}: circular name reference`);if(D===null)return;let k=D.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(?:\[(.*)\])?$/);if(!k)throw new Error(`${$}: not a valid identifier`);let C=k[1],I=k[2]??v;if(We(i,A)||We(i,C))throw new Error(`${C}: readonly variable`);if(I===void 0)i.state.env.set(C,x);else{let W=i.state.associativeArrays?.has(C)?"associative":"indexed";if(W==="associative"){j(i,C,I,x,W);return}let Z=await sa(i,C,I);if(Z.error)throw new q(Z.error.exitCode,Z.error.stdout,Z.error.stderr);j(i,C,Z.index,x,W)}},exportedEnv:h,get stdin(){return p=!0,d},limits:i.limits,executionScope:u.internalIsExtension?Fa(i.executionScope):i.executionScope,exec:(A,x)=>i.execFn(A,x,!1),execWithInheritedStdin:(A,x)=>i.execFn(A,{...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=u.internalOriginalCommand,S=()=>{};if(E){let A=Object.getOwnPropertyDescriptors(y);A.executionScope={value:i.executionScope,enumerable:!0,configurable:!0,writable:!0};let x=Object.defineProperties(Object.create(Object.getPrototypeOf(y)),A),v=xf(x,E.name),$=ra(v.context,E.name);S=v.revoke,y.origCommand=D=>{let k=()=>E.execute(D,$);return E.trusted?Te.runTrustedAsync(k):Te.runUntrustedAsync(k)}}let g=xf(y,t),m=ra(g.context,t),b=()=>{g.revoke(),S()};try{if(!u.handlesOwnVersion&&n.slice(0,n.indexOf("--")===-1?void 0:n.indexOf("--")).includes("--version"))return{stdout:`${t} (just-bash)
780
- `,stderr:"",exitCode:0};let A=()=>ba(i.requireDefenseContext,"command",`${t} execution`,()=>u.execute(n,m)),x=()=>Rm(A,m,b,t,i.executionScope,i.state.signal),v=u.trusted?await Te.runTrustedAsync(x):await x();return{...v,internalStdinConsumed:v.internalStdinConsumed??(p?r.length:0)}}catch(A){return Mr(A),L(`${t}: ${qe(Lt(A))}
781
- `)}}async function ia(e,t){let n=e.state.inCondition;e.state.inCondition=!0;let r=new Gt(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 kr(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 Ke)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"continue",stdout:t,stderr:n};if(Fr(e)||e instanceof _e||e instanceof ze||e instanceof q)return e instanceof Vt&&e.prependOutput(t,n),{action:"rethrow",stdout:t,stderr:n,error:e};let s=Lt(e);return{action:"error",stdout:t,stderr:`${n}${s}
782
- `,exitCode:1}}function Cf(e,t){return e!==void 0?{owns:!0,stdin:e}:t!==""?{owns:!0,stdin:t}:{owns:!1}}var hn=class{ctx;stdoutChunks=[];stderrChunks=[];totalBytes=0;constructor(t){this.ctx=t}append(t,n){let r=B(t)+B(n);r>this.ctx.limits.maxOutputSize-this.totalBytes&&on(`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:B(n),stderr:B(r)}}}};async function oa(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(Tr(s)||s instanceof ze||s instanceof q||s instanceof Pe||s instanceof P||s instanceof Ut)throw s.prependOutput(n.stdout,n.stderr),s;return n.appendUnaccounted("",`${Lt(s)}
783
- `),n.build(1)}return n.build(r)}async function Nf(e,t){return rt(e,t.redirections,"",()=>Om(e,t))}async function Om(e,t){let n=new hn(e);for(let r of t.clauses){let s=await ia(e,r.condition);if(n.append(s.stdout,s.stderr),s.exitCode===0)return oa(e,r.body,n)}return t.elseBody?oa(e,t.elseBody,n):n.build(0)}async function Rf(e,t){return rt(e,t.redirections,"",()=>_m(e,t))}async function _m(e,t){let n=new hn(e),r=0,s=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return L(`bash: \`${t.variable}': not a valid identifier
784
- `);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 bt(e,o);De(i,a.values,e.limits.maxArrayElements,"for-loop expansion")}}catch(o){if(o instanceof zt)return{stdout:"",stderr:o.stderr,exitCode:1};throw o}e.state.loopDepth++;try{for(let o of i){s++,s>e.limits.maxLoopIterations&&on(`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=kr(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 Df(e,t){return rt(e,t.redirections,"",()=>Lm(e,t))}async function Lm(e,t){let n=t.line;n!==void 0&&(e.state.currentLine=n);let r=new hn(e),s=0,i=0;t.init&&await Y(e,t.init.expression),e.state.loopDepth++;try{for(;i++,i>e.limits.maxLoopIterations&&on(`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 Y(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=kr(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 Y(e,t.update.expression);continue}if(a.action==="error")return r.build(a.exitCode??1);throw a.error}t.update&&await Y(e,t.update.expression)}}finally{e.state.loopDepth--}return r.build(s)}async function If(e,t,n=""){return rt(e,t.redirections,n,r=>Tm(e,t,n,r))}async function Tm(e,t,n,r){let s=new hn(e),i=0,o=0,a=Cf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&on(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let c=0,u=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let p of t.condition){let h=await e.executeStatement(p);s.append(h.stdout,h.stderr),c=h.exitCode}}catch(p){if(p instanceof Qe){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;u=!0}else if(p instanceof Ke){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(u)break;if(!f){if(c!==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=kr(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 Of(e,t,n=""){return rt(e,t.redirections,n,r=>Fm(e,t,n,r))}async function Fm(e,t,n,r){let s=new hn(e),i=0,o=0,a=Cf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&on(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let c=await ia(e,t.condition);if(s.append(c.stdout,c.stderr),c.exitCode===0)break;try{for(let u of t.body){let f=await e.executeStatement(u);s.append(f.stdout,f.stderr),i=f.exitCode}}catch(u){let f=kr(u,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 _f(e,t){return rt(e,t.redirections,"",()=>Mm(e,t))}async function Mm(e,t){let n=new hn(e),r=0,s=await ie(e,t.word),i=!1;for(let o=0;o<t.items.length;o++){let a=t.items[o],l=i;if(!i)for(let c of a.patterns){let u=await ie(e,c);iu(c)&&(u=et(u));let f=e.state.shoptOptions.nocasematch,d=e.state.shoptOptions.extglob;if(Un(s,u,f,d,e.limits.maxCallDepth)){l=!0;break}}if(l){let c=await oa(e,a.body,n);if(n.replace(c.stdout,c.stderr),r=c.exitCode,a.terminator===";;")break;a.terminator===";&"?i=!0:i=!1}else i=!1}return n.build(r)}function aa(e,t){if(e.parts.length!==1)return!1;let n=e.parts[0];return n.type!=="Literal"?!1:t.includes(n.value)}async function Lf(e,t,n){let r=t.timed?ri():0,s="",i=ne,o=0,a=[],l="",c=0,u=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 m=t.commands[g],b=g===t.commands.length-1,A=g===0;u&&(e.state.lastArg="",e.state.groupStdin=A?d:void 0,e.state.groupStdinSourceFd=A?p:void 0);let x=u&&(!b||!e.state.shoptOptions.lastpipe),v=x?new Map(e.state.env):null,$=x?ot(e.state.arrays):null,D,k=e.executionScope.outputBytesUsed;try{e.state.commandCount=e.executionScope.chargeCommand(),D=await n(m,s)}catch(C){if(C instanceof Xe)D={stdout:C.stdout,stderr:C.stderr,exitCode:1};else if(C instanceof q&&t.commands.length>1)D={stdout:C.stdout,stderr:C.stderr,exitCode:C.exitCode};else if(C instanceof ze&&t.commands.length>1)D={stdout:C.stdout,stderr:C.stderr,exitCode:C.exitCode};else throw v&&(e.state.env=v,e.state.arrays=$??new Map),C}finally{u&&(A&&(d=e.state.groupStdin,p=e.state.groupStdinSourceFd),e.state.groupStdin=d,e.state.groupStdinSourceFd=p)}if(v&&(e.state.env=v,e.state.arrays=$??new Map),D=e.executionScope.accountResult(D,"pipeline",e.executionScope.outputBytesUsed-k),!b){let C=t.pipeStderr?.[g]??!1,I=D.internalOutputAccounting?.stdout??0,W=C?D.internalOutputAccounting?.stderr??0:0;Ma(e.executionScope,I+W,"pipeline"),D={...D,internalOutputAccounting:{stdout:0,stderr:C?0:D.internalOutputAccounting?.stderr??0}}}a.push(D.exitCode),D.exitCode!==0&&(o=D.exitCode),b?i=D:(t.pipeStderr?.[g]??!1?s=yn(D.stderr)+Wt(D):(s=Wt(D),l+=D.stderr,c+=D.internalOutputAccounting?.stderr??0),i={stdout:"",stderr:"",exitCode:D.exitCode})}l&&(i={...i,stderr:l+i.stderr,internalOutputAccounting:{stdout:i.internalOutputAccounting?.stdout??0,stderr:c+(i.internalOutputAccounting?.stderr??0)}});let h=t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand",y=i.internalPipeStatusOverride??a;if(h){ge(e,"PIPESTATUS");for(let g=0;g<y.length;g++)j(e,"PIPESTATUS",g,String(y[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 m=(ri()-r)/1e3,b=Math.floor(m/60),A=m%60,x;t.timePosix?x=`real ${m.toFixed(2)}
784
+ `,127);if("script"in c)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,c.path)),await a(c.path,n,r);let{cmd:u,path:f}=c;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",p=!1,h=o();i.state.fileDescriptors??=new Map;let y={fs:i.fs,fsIdentity:ui(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 $=A===void 0?v:`${v}[${A}]`,R=as(i,v,x);if(R===void 0)throw new Error(`${v}: circular name reference`);if(R===null)return;let k=R.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(?:\[(.*)\])?$/);if(!k)throw new Error(`${$}: not a valid identifier`);let C=k[1],I=k[2]??A;if(We(i,v)||We(i,C))throw new Error(`${C}: readonly variable`);if(I===void 0)i.state.env.set(C,x);else{let W=i.state.associativeArrays?.has(C)?"associative":"indexed";if(W==="associative"){j(i,C,I,x,W);return}let Z=await ua(i,C,I);if(Z.error)throw new q(Z.error.exitCode,Z.error.stdout,Z.error.stderr);j(i,C,Z.index,x,W)}},exportedEnv:h,get stdin(){return p=!0,d},limits:i.limits,executionScope:u.internalIsExtension?ja(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=u.internalOriginalCommand,S=()=>{};if(E){let v=Object.getOwnPropertyDescriptors(y);v.executionScope={value:i.executionScope,enumerable:!0,configurable:!0,writable:!0};let x=Object.defineProperties(Object.create(Object.getPrototypeOf(y)),v),A=Df(x,E.name),$=ca(A.context,E.name);S=A.revoke,y.origCommand=R=>{let k=()=>E.execute(R,$);return E.trusted?Te.runTrustedAsync(k):Te.runUntrustedAsync(k)}}let m=Df(y,t),g=ca(m.context,t),b=()=>{m.revoke(),S()};try{if(!u.handlesOwnVersion&&n.slice(0,n.indexOf("--")===-1?void 0:n.indexOf("--")).includes("--version"))return{stdout:`${t} (just-bash)
785
+ `,stderr:"",exitCode:0};let v=()=>Pa(i.requireDefenseContext,"command",`${t} execution`,()=>u.execute(n,g)),x=()=>Mm(v,g,b,t,i.executionScope,i.state.signal),A=u.trusted?await Te.runTrustedAsync(x):await x();return{...A,internalStdinConsumed:A.internalStdinConsumed??(p?r.length:0)}}catch(v){return Vr(v),L(`${t}: ${qe(Ft(v))}
786
+ `)}}async function fa(e,t){let n=e.state.inCondition;e.state.inCondition=!0;let r=new Zt(e.executionScope,"condition"),s=0;try{for(let i of t){let o=await e.executeStatement(i);r.appendResult(o),s=o.exitCode}}catch(i){throw r.prependTo(i),i}finally{e.state.inCondition=n}return r.build(s)}var Xs=0;function Jn(e,t){return e.state.lastExitCode=t,e.state.env.set("?",String(t)),t}function Cr(e,t,n,r){if(e instanceof Qe)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"break",stdout:t,stderr:n,exitCode:Xs};if(e instanceof Ke)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"continue",stdout:t,stderr:n,exitCode:Xs};if(Wr(e)||e instanceof _e||e instanceof ze||e instanceof q)return e instanceof zt&&e.prependOutput(t,n),{action:"rethrow",stdout:t,stderr:n,error:e};let s=Ft(e);return{action:"error",stdout:t,stderr:`${n}${s}
787
+ `,exitCode:1}}function Lf(e,t){return e!==void 0?{owns:!0,stdin:e}:t!==""?{owns:!0,stdin:t}:{owns:!1}}var yn=class{ctx;stdoutChunks=[];stderrChunks=[];totalBytes=0;constructor(t){this.ctx=t}append(t,n){let r=M(t)+M(n);r>this.ctx.limits.maxOutputSize-this.totalBytes&&ln(`total output size exceeded (>${this.ctx.limits.maxOutputSize} bytes), increase executionLimits.maxOutputSize`,"output_size"),t&&this.stdoutChunks.push(t),n&&this.stderrChunks.push(n),this.totalBytes+=r}appendUnaccounted(t,n){this.ctx.executionScope.appendOutput("stdout",t,"control-flow"),this.ctx.executionScope.appendOutput("stderr",n,"control-flow"),this.append(t,n)}replace(t,n){this.stdoutChunks=[],this.stderrChunks=[],this.totalBytes=0,this.append(t,n)}get stdout(){return this.stdoutChunks.join("")}get stderr(){return this.stderrChunks.join("")}build(t){let n=this.stdout,r=this.stderr;return{stdout:n,stderr:r,exitCode:t,internalOutputAccounting:{stdout:M(n),stderr:M(r)}}}};async function da(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(Mr(s)||s instanceof ze||s instanceof q||s instanceof Pe||s instanceof P||s instanceof qt)throw s.prependOutput(n.stdout,n.stderr),s;return n.appendUnaccounted("",`${Ft(s)}
788
+ `),n.build(1)}return n.build(r)}async function Tf(e,t){return rt(e,t.redirections,"",()=>Vm(e,t))}async function Vm(e,t){let n=new yn(e);for(let r of t.clauses){let s=await fa(e,r.condition);if(n.append(s.stdout,s.stderr),s.exitCode===0)return da(e,r.body,n)}return t.elseBody?da(e,t.elseBody,n):n.build(0)}async function Ff(e,t){return rt(e,t.redirections,"",()=>zm(e,t))}async function zm(e,t){let n=new yn(e),r=0,s=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return L(`bash: \`${t.variable}': not a valid identifier
789
+ `);let i=[];if(t.words===null)i=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)i=[];else try{for(let o of t.words){let a=await At(e,o);De(i,a.values,e.limits.maxArrayElements,"for-loop expansion")}}catch(o){if(o instanceof Ut)return{stdout:"",stderr:o.stderr,exitCode:1};throw o}e.state.loopDepth++;try{for(let o of i){s++,s>e.limits.maxLoopIterations&&ln(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n.stdout,n.stderr),e.state.env.set(t.variable,o);try{for(let a of t.body){let l=await e.executeStatement(a);n.append(l.stdout,l.stderr),r=l.exitCode}}catch(a){let l=Cr(a,n.stdout,n.stderr,e.state.loopDepth);if(n.replace(l.stdout,l.stderr),l.exitCode!==void 0&&(r=Jn(e,l.exitCode)),l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return n.build(l.exitCode??1);throw l.error}}}finally{e.state.loopDepth--}return n.build(r)}async function Mf(e,t){return rt(e,t.redirections,"",()=>Um(e,t))}async function Um(e,t){let n=t.line;n!==void 0&&(e.state.currentLine=n);let r=new yn(e),s=0,i=0;t.init&&await Y(e,t.init.expression),e.state.loopDepth++;try{for(;i++,i>e.limits.maxLoopIterations&&ln(`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 Y(e,t.condition.expression)===0));){try{for(let o of t.body){let a=await e.executeStatement(o);r.append(a.stdout,a.stderr),s=a.exitCode}}catch(o){let a=Cr(o,r.stdout,r.stderr,e.state.loopDepth);if(r.replace(a.stdout,a.stderr),a.exitCode!==void 0&&(s=Jn(e,a.exitCode)),a.action==="break")break;if(a.action==="continue"){t.update&&await Y(e,t.update.expression);continue}if(a.action==="error")return r.build(a.exitCode??1);throw a.error}t.update&&await Y(e,t.update.expression)}}finally{e.state.loopDepth--}return r.build(s)}async function Bf(e,t,n=""){return rt(e,t.redirections,n,r=>qm(e,t,n,r))}async function qm(e,t,n,r){let s=new yn(e),i=0,o=0,a=Lf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&ln(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let c=0,u=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let p of t.condition){let h=await e.executeStatement(p);s.append(h.stdout,h.stderr),c=h.exitCode}}catch(p){if(p instanceof Qe){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;u=!0}else if(p instanceof Ke){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((u||f)&&(i=Jn(e,Xs)),u)break;if(!f){if(c!==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=Cr(p,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(h.stdout,h.stderr),h.exitCode!==void 0&&(i=Jn(e,h.exitCode)),h.action==="break")break;if(h.action==="continue")continue;if(h.action==="error")return s.build(h.exitCode??1);throw h.error}}}}finally{e.state.loopDepth--,a.owns&&(e.state.groupStdin=l)}return s.build(i)}async function Wf(e,t,n=""){return rt(e,t.redirections,n,r=>jm(e,t,n,r))}async function jm(e,t,n,r){let s=new yn(e),i=0,o=0,a=Lf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&ln(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let c=await fa(e,t.condition);if(s.append(c.stdout,c.stderr),c.exitCode===0)break;try{for(let u of t.body){let f=await e.executeStatement(u);s.append(f.stdout,f.stderr),i=f.exitCode}}catch(u){let f=Cr(u,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(f.stdout,f.stderr),f.exitCode!==void 0&&(i=Jn(e,f.exitCode)),f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error")return s.build(f.exitCode??1);throw f.error}}}finally{e.state.loopDepth--,a.owns&&(e.state.groupStdin=l)}return s.build(i)}async function Vf(e,t){return rt(e,t.redirections,"",()=>Hm(e,t))}async function Hm(e,t){let n=new yn(e),r=0,s=await re(e,t.word),i=!1;for(let o=0;o<t.items.length;o++){let a=t.items[o],l=i;if(!i)for(let c of a.patterns){let u=await re(e,c);du(c)&&(u=et(u));let f=e.state.shoptOptions.nocasematch,d=e.state.shoptOptions.extglob;if(jn(s,u,f,d,e.limits.maxCallDepth)){l=!0;break}}if(l){let c=await da(e,a.body,n);if(n.replace(c.stdout,c.stderr),r=c.exitCode,a.terminator===";;")break;a.terminator===";&"?i=!0:i=!1}else i=!1}return n.build(r)}function pa(e,t){if(e.parts.length!==1)return!1;let n=e.parts[0];return n.type!=="Literal"?!1:t.includes(n.value)}async function zf(e,t,n){let r=t.timed?ai():0,s="",i=ee,o=0,a=[],l="",c=0,u=t.commands.length>1,f=e.state.lastArg,d=e.state.groupStdin,p=e.state.groupStdinSourceFd;for(let m=0;m<t.commands.length;m++){let g=t.commands[m],b=m===t.commands.length-1,v=m===0;u&&(e.state.lastArg="",e.state.groupStdin=v?d:void 0,e.state.groupStdinSourceFd=v?p:void 0);let x=u&&(!b||!e.state.shoptOptions.lastpipe),A=x?new Map(e.state.env):null,$=x?at(e.state.arrays):null,R,k=e.executionScope.outputBytesUsed;try{e.state.commandCount=e.executionScope.chargeCommand(),R=await n(g,s)}catch(C){if(C instanceof Xe)R={stdout:C.stdout,stderr:C.stderr,exitCode:1};else if(C instanceof q&&t.commands.length>1)R={stdout:C.stdout,stderr:C.stderr,exitCode:C.exitCode};else if(C instanceof ze&&t.commands.length>1)R={stdout:C.stdout,stderr:C.stderr,exitCode:C.exitCode};else throw A&&(e.state.env=A,e.state.arrays=$??new Map),C}finally{u&&(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=$??new Map),R=e.executionScope.accountResult(R,"pipeline",e.executionScope.outputBytesUsed-k),!b){let C=t.pipeStderr?.[m]??!1,I=R.internalOutputAccounting?.stdout??0,W=C?R.internalOutputAccounting?.stderr??0:0;Ha(e.executionScope,I+W,"pipeline"),R={...R,internalOutputAccounting:{stdout:0,stderr:C?0:R.internalOutputAccounting?.stderr??0}}}a.push(R.exitCode),R.exitCode!==0&&(o=R.exitCode),b?i=R:(t.pipeStderr?.[m]??!1?s=wn(R.stderr)+Vt(R):(s=Vt(R),l+=R.stderr,c+=R.internalOutputAccounting?.stderr??0),i={stdout:"",stderr:"",exitCode:R.exitCode})}l&&(i={...i,stderr:l+i.stderr,internalOutputAccounting:{stdout:i.internalOutputAccounting?.stdout??0,stderr:c+(i.internalOutputAccounting?.stderr??0)}});let h=t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand",y=i.internalPipeStatusOverride??a;if(h){ge(e,"PIPESTATUS");for(let m=0;m<y.length;m++)j(e,"PIPESTATUS",m,String(y[m]))}if(e.state.options.pipefail&&o!==0&&(i={...i,exitCode:o}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let g=(ai()-r)/1e3,b=Math.floor(g/60),v=g%60,x;t.timePosix?x=`real ${g.toFixed(2)}
785
790
  user 0.00
786
791
  sys 0.00
787
792
  `:x=`
788
- real ${`${b}m${A.toFixed(3)}s`}
793
+ real ${`${b}m${v.toFixed(3)}s`}
789
794
  user 0m0.000s
790
795
  sys 0m0.000s
791
- `,i={...i,stderr:i.stderr+x}}u&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=f),i=e.executionScope.accountResult(i,"pipeline");let{internalPipeStatusOverride:E,...S}=i;return S}function la(e){return e?{...e,options:e.options?[...e.options]:void 0,actions:e.actions?[...e.actions]:void 0}:void 0}function Bm(e){return e?new Map(Array.from(e,([t,n])=>[t,la(n)])):void 0}function Wm(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 Vm(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 zm(e){return e?new Map(Array.from(e,([t,n])=>[t,n.map(r=>({...r}))])):void 0}function ca(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=ot(e.arrays),e.options={...e.options},e.shoptOptions={...e.shoptOptions},e.fileDescriptors=e.fileDescriptors?new Map(e.fileDescriptors):void 0,e.inputFds=e.inputFds?new Set(e.inputFds):void 0,e.fdAliases=Wm(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=Vm(e.localArrayScopes),e.localVarDepth=e.localVarDepth?new Map(e.localVarDepth):void 0,e.localVarStack=zm(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=Bm(e.completionSpecs),e.defaultCompletionSpec=la(e.defaultCompletionSpec),e.emptyCompletionSpec=la(e.emptyCompletionSpec);let n=!1;return()=>{n||(n=!0,Object.assign(e,t))}}async function Tf(e,t,n,r,s=!1){let i=e.state.loopDepth,o=new Map;for(let l of e.state.fileDescriptors?.keys()??[]){let c=nt(e,l);c&&o.set(l,c)}let a=ca(e.state);e.state.parentHasLoopContext=i>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++;try{return await rt(e,t.redirections,n,l=>Um(e,t,l.stdin??n,r,s||l.stdin!==void 0))}finally{let l=new Map;for(let[c,u]of o){let f=nt(e,c),d=u.kind==="input"&&f?.kind==="input"?u.content.length-f.content.length:u.kind==="readwrite"&&f?.kind==="readwrite"&&u.path===f.path?f.position-u.position:0;if(d<=0)continue;let p=Math.min(...cn(e,c));l.set(p,Math.max(l.get(p)??0,d))}a();for(let[c,u]of l)un(e,c,u)}}async function Um(e,t,n,r,s){(s||n)&&(e.state.groupStdin=n);let i=new Gt(e.executionScope,"subshell"),o=0;try{for(let a of t.body){let l=await r(a);i.appendResult(l),o=l.exitCode}}catch(a){if(a instanceof P)throw i.prependTo(a),a;if(a instanceof Ut||a instanceof Qe||a instanceof Ke)return i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(0);if(a instanceof q||a instanceof _e||a instanceof ze)return i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(a.exitCode);if(a instanceof Pe)throw a.prependOutput(i.stdout,i.stderr),a;return i.append("stderr",`${Lt(a)}
792
- `),i.build(1)}return i.build(o)}async function Ff(e,t,n,r,s=!1){return rt(e,t.redirections,n,i=>qm(e,t,n,r,s,i))}async function qm(e,t,n,r,s,i){let o=new Gt(e.executionScope,"group"),a=0,l=i.stdin??n,c=s||n!==""||i.stdin!==void 0,u=e.state.groupStdin;c&&(e.state.groupStdin=l);let f=()=>{(c||u!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=u)};try{for(let d of t.body){let p=await r(d);o.appendResult(p),a=p.exitCode}}catch(d){if(f(),d instanceof P)throw o.prependTo(d),d;if(Tr(d)||d instanceof ze||d instanceof q||d instanceof Pe)throw d.prependOutput(o.stdout,o.stderr),d;return o.append("stderr",`${Lt(d)}
793
- `),o.build(1)}return f(),o.build(a)}async function Mf(e,t,n,r,s){let i;try{i=await e.fs.readFile(t)}catch{return L(`bash: ${t}: No such file or directory
796
+ `,i={...i,stderr:i.stderr+x}}u&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=f),i=e.executionScope.accountResult(i,"pipeline");let{internalPipeStatusOverride:E,...S}=i;return S}function ha(e){return e?{...e,options:e.options?[...e.options]:void 0,actions:e.actions?[...e.actions]:void 0}:void 0}function Gm(e){return e?new Map(Array.from(e,([t,n])=>[t,ha(n)])):void 0}function Zm(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 Qm(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 Km(e){return e?new Map(Array.from(e,([t,n])=>[t,n.map(r=>({...r}))])):void 0}function ma(e){let t={env:e.env,arrays:e.arrays,cwd:e.cwd,previousDir:e.previousDir,lastExitCode:e.lastExitCode,lastArg:e.lastArg,currentLine:e.currentLine,options:e.options,shoptOptions:e.shoptOptions,fileDescriptors:e.fileDescriptors,inputFds:e.inputFds,fdAliases:e.fdAliases,closedStandardFds:e.closedStandardFds,nextFd:e.nextFd,readonlyVars:e.readonlyVars,associativeArrays:e.associativeArrays,namerefs:e.namerefs,boundNamerefs:e.boundNamerefs,invalidNamerefs:e.invalidNamerefs,integerVars:e.integerVars,lowercaseVars:e.lowercaseVars,uppercaseVars:e.uppercaseVars,exportedVars:e.exportedVars,tempExportedVars:e.tempExportedVars,localExportedVars:e.localExportedVars,declaredVars:e.declaredVars,localScopes:e.localScopes,localArrayScopes:e.localArrayScopes,localVarDepth:e.localVarDepth,localVarStack:e.localVarStack,fullyUnsetLocals:e.fullyUnsetLocals,tempEnvBindings:e.tempEnvBindings,mutatedTempEnvVars:e.mutatedTempEnvVars,accessedTempEnvVars:e.accessedTempEnvVars,functions:e.functions,callDepth:e.callDepth,sourceDepth:e.sourceDepth,callLineStack:e.callLineStack,funcNameStack:e.funcNameStack,sourceStack:e.sourceStack,currentSource:e.currentSource,inCondition:e.inCondition,loopDepth:e.loopDepth,parentHasLoopContext:e.parentHasLoopContext,errexitSafe:e.errexitSafe,directoryStack:e.directoryStack,hashTable:e.hashTable,completionSpecs:e.completionSpecs,defaultCompletionSpec:e.defaultCompletionSpec,emptyCompletionSpec:e.emptyCompletionSpec,groupStdin:e.groupStdin,groupStdinSourceFd:e.groupStdinSourceFd,bashPid:e.bashPid,expansionExitCode:e.expansionExitCode,expansionStderr:e.expansionStderr};e.env=new Map(e.env),e.arrays=at(e.arrays),e.options={...e.options},e.shoptOptions={...e.shoptOptions},e.fileDescriptors=e.fileDescriptors?new Map(e.fileDescriptors):void 0,e.inputFds=e.inputFds?new Set(e.inputFds):void 0,e.fdAliases=Zm(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=Qm(e.localArrayScopes),e.localVarDepth=e.localVarDepth?new Map(e.localVarDepth):void 0,e.localVarStack=Km(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=Gm(e.completionSpecs),e.defaultCompletionSpec=ha(e.defaultCompletionSpec),e.emptyCompletionSpec=ha(e.emptyCompletionSpec);let n=!1;return()=>{n||(n=!0,Object.assign(e,t))}}async function Uf(e,t,n,r,s=!1){let i=e.state.loopDepth,o=new Map;for(let l of e.state.fileDescriptors?.keys()??[]){let c=nt(e,l);c&&o.set(l,c)}let a=ma(e.state);e.state.parentHasLoopContext=i>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++;try{return await rt(e,t.redirections,n,l=>Xm(e,t,l.stdin??n,r,s||l.stdin!==void 0))}finally{let l=new Map;for(let[c,u]of o){let f=nt(e,c),d=u.kind==="input"&&f?.kind==="input"?u.content.length-f.content.length:u.kind==="readwrite"&&f?.kind==="readwrite"&&u.path===f.path?f.position-u.position:0;if(d<=0)continue;let p=Math.min(...fn(e,c));l.set(p,Math.max(l.get(p)??0,d))}a();for(let[c,u]of l)dn(e,c,u)}}async function Xm(e,t,n,r,s){(s||n)&&(e.state.groupStdin=n);let i=new Zt(e.executionScope,"subshell"),o=0;try{for(let a of t.body){let l=await r(a);i.appendResult(l),o=l.exitCode}}catch(a){if(a instanceof P)throw i.prependTo(a),a;if(a instanceof qt||a instanceof Qe||a instanceof Ke)return i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(0);if(a instanceof q||a instanceof _e||a instanceof ze)return i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(a.exitCode);if(a instanceof Pe)throw a.prependOutput(i.stdout,i.stderr),a;return i.append("stderr",`${Ft(a)}
797
+ `),i.build(1)}return i.build(o)}async function qf(e,t,n,r,s=!1){return rt(e,t.redirections,n,i=>Ym(e,t,n,r,s,i))}async function Ym(e,t,n,r,s,i){let o=new Zt(e.executionScope,"group"),a=0,l=i.stdin??n,c=s||n!==""||i.stdin!==void 0,u=e.state.groupStdin;c&&(e.state.groupStdin=l);let f=()=>{(c||u!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=u)};try{for(let d of t.body){let p=await r(d);o.appendResult(p),a=p.exitCode}}catch(d){if(f(),d instanceof P)throw o.prependTo(d),d;if(Mr(d)||d instanceof ze||d instanceof q||d instanceof Pe)throw d.prependOutput(o.stdout,o.stderr),d;return o.append("stderr",`${Ft(d)}
798
+ `),o.build(1)}return f(),o.build(a)}async function jf(e,t,n,r,s){let i;try{i=await e.fs.readFile(t)}catch{return L(`bash: ${t}: No such file or directory
794
799
  `,127)}if(i.startsWith("#!")){let l=i.indexOf(`
795
- `);l!==-1&&(i=i.slice(l+1))}let o=e.state.loopDepth,a=ca(e.state);e.state.parentHasLoopContext=o>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,r&&(e.state.groupStdin=r),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(n.length)),e.state.env.set("@",n.join(" ")),e.state.env.set("*",n.join(" "));for(let l=0;l<n.length&&l<9;l++)e.state.env.set(String(l+1),n[l]);for(let l=n.length+1;l<=9;l++)e.state.env.delete(String(l));try{let c=new H().parse(i),u=await s(c);return a(),u}catch(l){if(a(),l instanceof q)return T(l.stdout,l.stderr,l.exitCode);if(l instanceof Pe||l instanceof P)throw l;if(l.name==="ParseException")return L(`bash: ${t}: ${l.message}
796
- `);throw l}}function jm(e){throw new TypeError(`Unsupported command node: ${JSON.stringify(e)}`)}var $r=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||Te.isInSandboxedContext())return;let n=`interpreter ${t} attempted outside defense context`;throw new Or(n,{timestamp:Date.now(),type:"missing_defense_context",message:n,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:Te.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 Gt(this.ctx.executionScope,"script");for(let s of t.statements)try{let i=await this.executeStatement(s);r.appendResult(i,ti(i)),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(i){if(i instanceof q||i instanceof Pe)throw i.prependOutput(r.stdout,r.stderr),i;if(i instanceof st)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Ht(this.ctx.state.env)};if(Fr(i))throw r.prependTo(i),i;if(i instanceof ze)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:Ht(this.ctx.state.env)};if(i instanceof Ue)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:Ht(this.ctx.state.env)};if(i instanceof Xe)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Ht(this.ctx.state.env)};if(i instanceof le){r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(i instanceof Lr){r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(i instanceof Qe||i instanceof Ke){if(this.ctx.state.loopDepth>0)throw i.prependOutput(r.stdout,r.stderr),i;r.append("stdout",i.stdout),r.append("stderr",i.stderr);continue}throw i instanceof _e&&i.prependOutput(r.stdout,r.stderr),i}return{...r.build(n),env:Ht(this.ctx.state.env)}}async executeUserScript(t,n,r=""){return Mf(this.ctx,t,n,r,s=>this.executeScript(s))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Ye;if(t.deferredError)throw new ke(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return ne;this.ctx.state.errexitSafe=!1;let n=new Gt(this.ctx.executionScope,"statement");this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&n.append("stderr",`${t.sourceText}
797
- `);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,ti(f)),r=f.exitCode,s=l,i=c.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}}catch(l){throw n.prependTo(l),l}let o=s<t.pipelines.length-1,a=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=o||i||a,this.ctx.state.options.errexit&&r!==0&&s===t.pipelines.length-1&&!i&&!this.ctx.state.inCondition&&!a){let l=new ze(r);throw l.prependOutput(n.stdout,n.stderr),l}return n.build(r)}async executePipeline(t){return Lf(this.ctx,t,(n,r)=>this.executeCommand(n,r))}async executeCommand(t,n,r=!1){let s=ru(this.ctx),i;try{i=await this.executeCommandInner(t,n,r)}catch(a){throw await Yi(this.ctx,s).catch(()=>{}),a}let o=await Yi(this.ctx,s);return!o.stdout&&!o.stderr?i:{...i,stdout:o.stdout?Wt(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 Nf(this.ctx,t);case"For":return Rf(this.ctx,t);case"CStyleFor":return Df(this.ctx,t);case"While":return If(this.ctx,t,n);case"Until":return Of(this.ctx,t,n);case"Case":return _f(this.ctx,t);case"Subshell":return this.executeSubshell(t,n,r);case"Group":return this.executeGroup(t,n,r);case"FunctionDef":return Fu(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return jm(t)}}async executeSimpleCommand(t,n){let r;try{return await this.executeSimpleCommandInner(t,n,s=>{r=s})}catch(s){if(r?.finish(),s instanceof zt)return L(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 k=t,C=0;for(;;){let I=this.expandAlias(k);if(I===k)break;if(C>=this.ctx.limits.maxCallDepth)throw new P(`alias expansion depth limit exceeded (${this.ctx.limits.maxCallDepth})`,"recursion");C++,k=I}this.aliasExpansionStack.clear(),k!==t&&(t=k)}this.ctx.state.expansionStderr="",this.ctx.state.lastSubstitutionExitCode=null;let s=await yf(this.ctx,t);if(s.error)return s.error;let i=s.tempAssignments,o=s.xtraceOutput,a=()=>{for(let[k,C]of i)C===void 0?this.ctx.state.env.delete(k):this.ctx.state.env.set(k,C)};if(!t.name){if(t.redirections.length>0){let C=Gn(this.ctx,t.redirections,Lu);r(C);let I=await C.prepare(n);if(I.error){if(a(),!I.errorCause)return C.finish(),I.error;try{return Zn(I)}finally{C.finish()}}let W=T("",o,ls(this.ctx.state,t.redirections)),Z=await dn(this.ctx,W,t.redirections,I.targets,I.dupSources,I.standardRoutes);return C.finish(),Z}this.ctx.state.lastArg="";let k=(this.ctx.state.expansionStderr||"")+o;return this.ctx.state.expansionStderr="",T("",k,ls(this.ctx.state,[]))}let l=t.name&&aa(t.name,["local","declare","typeset","export","readonly"]),c=Array.from(i.keys());if(c.length>0&&!l){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let k of c)this.ctx.state.tempExportedVars.add(k)}let u=await ie(this.ctx,t.name),f=[],d=[],p=(k,C)=>{if(f.length>=this.ctx.limits.maxArrayElements)throw new P(`expanded argument element limit exceeded (${this.ctx.limits.maxArrayElements})`,"array_elements");f.push(k),d.push(C)};if(aa(t.name,["local","declare","typeset","export","readonly"])&&(u==="local"||u==="declare"||u==="typeset"||u==="export"||u==="readonly"))for(let k of t.args){let C=await hu(this.ctx,k);if(C)p(C,!0);else{let I=await mu(this.ctx,k);if(I!==null)p(I,!0);else{let W=await bt(this.ctx,k);for(let Z of W.values)p(Z,W.quoted)}}}else for(let k of t.args){let C=await bt(this.ctx,k);for(let I of C.values)p(I,C.quoted)}let y=t.name.parts.every(k=>k.type==="CommandSubstitution"||k.type==="ParameterExpansion"||k.type==="ArithmeticExpansion");!u&&y&&f.length>0&&(u=f.shift(),d.shift());let E=Gn(this.ctx,t.redirections,u==="exec"?Tu:wr);r(E);let S=await E.prepare(n);if(S.error)return a(),S.errorCause?Zn(S):(E.finish(),S.error);let g=S.stdinSourceFd,m=S.stdin!==void 0;if(S.stdin!==void 0&&(n=S.stdin),!u)return y?(E.finish(),T("","",ls(this.ctx.state,t.redirections))):(E.finish(),L(`bash: : command not found
798
- `,127));if(u==="exec"&&(f.length===0||f[0]==="--")){for(let[k,C]of i)C===void 0?this.ctx.state.env.delete(k):this.ctx.state.env.set(k,C);if(this.ctx.state.tempExportedVars)for(let k of i.keys())this.ctx.state.tempExportedVars.delete(k);return E.finish(),ne}if(this.ctx.state.extraArgs){let k=this.ctx.state.extraArgs;this.ctx.state.extraArgs=void 0;for(let C of k)p(C,!0)}let b=await hf(this.ctx,u,f);i.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(i)));let A,x=null;try{A=await this.runCommand(u,f,d,n,!1,!1,g,m)}catch(k){if(k instanceof Qe||k instanceof Ke)x=k,A=ne;else throw k}g>=0&&u!=="read"&&un(this.ctx,g,A.internalStdinConsumed??0);let v=o+b;if(v&&(A={...A,stderr:v+A.stderr}),A=await dn(this.ctx,A,t.redirections,S.targets,S.dupSources,S.standardRoutes,A.internalProducerCommand??u,A.internalProducerOmitsShellPrefix),E.finish(),x)throw x;if(f.length>0){let k=f[f.length-1];if((u==="declare"||u==="local"||u==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(k)){let C=k.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);C&&(k=C[1])}this.ctx.state.lastArg=k}else this.ctx.state.lastArg=u;let $=Ha(u)&&u!=="unset"&&u!=="eval";if(!this.ctx.state.options.posix||!$)for(let[k,C]of i)this.ctx.state.fullyUnsetLocals?.has(k)||(C===void 0?this.ctx.state.env.delete(k):this.ctx.state.env.set(k,C));if(this.ctx.state.tempExportedVars)for(let k of i.keys())this.ctx.state.tempExportedVars.delete(k);return i.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(A={...A,stderr:this.ctx.state.expansionStderr+A.stderr},this.ctx.state.expansionStderr=""),A}async runCommand(t,n,r,s,i=!1,o=!1,a=-1,l=!1){let c={ctx:this.ctx,runCommand:(d,p,h,y,E,S,g,m)=>this.runCommand(d,p,h,y,E,S,g,m),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(d,p,h)=>this.executeUserScript(d,p,h)},u=await $f(c,t,n,r,s,i,o,a,l);return u!==null?u.internalProducerCommand===void 0?{...u,internalProducerCommand:t}:u:{...await Pf(c,t,n,s,o),internalProducerCommand:t}}aliasExpansionStack=new Set;expandAlias(t){return Wl({env:this.ctx.state.env,limits:this.ctx.limits},t,this.aliasExpansionStack)}async findCommandInPath(t){return qr(this.ctx,t)}async executeSubshell(t,n="",r=!1){return Tf(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeGroup(t,n="",r=!1){return Ff(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeArithmeticCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),rt(this.ctx,t.redirections,"",async()=>{try{let n=await Y(this.ctx,t.expression.expression),r=we(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){return L(`bash: arithmetic expression: ${n.message}
799
- `)}})}async executeConditionalCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),rt(this.ctx,t.redirections,"",async()=>{try{let n=await an(this.ctx,t.expression),r=we(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){let r=n instanceof le?1:2;return L(`bash: conditional expression: ${n.message}
800
- `,r)}})}};function ua(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function Hm(e){let t=ua(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var Gm=3;function Bf(e){let t=e;for(let n=0;n<Gm;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 Zm(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function fa(e,t){let n=ua(e);if(!n)return!1;let r=Hm(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&Bf(n.pathname)?!1:Zm(n.pathname,r.pathPrefix)}function Wf(e){return typeof e=="string"?e:e.url}function Vf(e,t){return!t||t.length===0?!1:t.some(n=>fa(e,Wf(n)))}function da(e){let t=Qm(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=zf(t);if(n)return Zs(n);let r=Xm(t);return r?Ym(r):!1}function Qm(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function Km(e){if(!e)return null;let t=10,n=e;if(n.startsWith("0x")||n.startsWith("0X")?(t=16,n=n.slice(2)):n.length>1&&n.startsWith("0")&&(t=8),!n||t===16&&!/^[0-9a-fA-F]+$/.test(n)||t===10&&!/^\d+$/.test(n)||t===8&&!/^[0-7]+$/.test(n))return null;let r=Number.parseInt(n,t);return!Number.isFinite(r)||r<0?null:r}function zf(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>Km(l));if(n.some(l=>l===null))return null;let r=n;if(t.length===1){let l=r[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,c]=r;return l>255||c>16777215?null:[l,c>>>16&255,c>>>8&255,c&255]}if(t.length===3){let[l,c,u]=r;return l>255||c>255||u>65535?null:[l,c,u>>>8&255,u&255]}let[s,i,o,a]=r;return s>255||i>255||o>255||a>255?null:[s,i,o,a]}function Xm(e){let t=e,n=null;if(t.includes(".")){let y=t.lastIndexOf(":");if(y<0)return null;let E=t.slice(y+1),S=zf(E);if(!S)return null;n=S,t=t.slice(0,y)}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=y=>/^[0-9a-f]{1,4}$/i.test(y)?Number.parseInt(y,16):null,c=o.map(l),u=a.map(l);if(c.some(y=>y===null)||u.some(y=>y===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 Zs(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 Ym(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 Zs(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 Zs(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 Zs(s)}return!1}function Uf(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=Wf(n);if(!ua(r)){t.push(`Invalid URL in allow-list: "${r}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(r);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${r}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${r}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&Bf(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${r}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${r}"`)}return t}var St=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},Xn=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},mn=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Qs=class extends Error{constructor(t,n){super(`HTTP method '${t}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}},Pn=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var Jm=20,ey=3e4,ty=10485760,ny=["GET","HEAD"],Pr;typeof __BROWSER__<"u"&&__BROWSER__?Pr=null:(Pr=import("./chunks/dist-5MWO25Y4.js"),Pr.catch(()=>{}));var ry=new Set(["GET","HEAD","OPTIONS"]),sy=new Set([301,302,303,307,308]);function Cr(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function iy(e){if(e?.aborted)throw Cr(e)}function ha(e){let t=e.allowedUrlPrefixes??[];if(e._dnsResolve)throw new Error("NetworkConfig._dnsResolve is no longer supported: DNS resolution is performed by guarded-fetch and cannot be overridden");if(e._createConnectionOwner)throw new Error("NetworkConfig._createConnectionOwner is no longer supported: connect-time IP pinning is performed by guarded-fetch and cannot be overridden");let n=e._fetch;if(!e.dangerouslyAllowFullInternetAccess){let b=Uf(t);if(b.length>0)throw new Error(`Invalid network allow-list:
800
+ `);l!==-1&&(i=i.slice(l+1))}let o=e.state.loopDepth,a=ma(e.state);e.state.parentHasLoopContext=o>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,r&&(e.state.groupStdin=r),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(n.length)),e.state.env.set("@",n.join(" ")),e.state.env.set("*",n.join(" "));for(let l=0;l<n.length&&l<9;l++)e.state.env.set(String(l+1),n[l]);for(let l=n.length+1;l<=9;l++)e.state.env.delete(String(l));try{let c=new H().parse(i),u=await s(c);return a(),u}catch(l){if(a(),l instanceof q)return T(l.stdout,l.stderr,l.exitCode);if(l instanceof Pe||l instanceof P)throw l;if(l.name==="ParseException")return L(`bash: ${t}: ${l.message}
801
+ `);throw l}}function Jm(e){throw new TypeError(`Unsupported command node: ${JSON.stringify(e)}`)}var Nr=class{ctx;constructor(t,n){this.ctx={state:n,fs:t.fs,commands:t.commands,limits:t.limits,executionScope:t.executionScope,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode,invokeTool:t.invokeTool}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||Te.isInSandboxedContext())return;let n=`interpreter ${t} attempted outside defense context`;throw new Tr(n,{timestamp:Date.now(),type:"missing_defense_context",message:n,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:Te.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 Zt(this.ctx.executionScope,"script");for(let s of t.statements)try{let i=await this.executeStatement(s);r.appendResult(i,ii(i)),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(i){if(i instanceof q||i instanceof Pe)throw i.prependOutput(r.stdout,r.stderr),i;if(i instanceof st)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Gt(this.ctx.state.env)};if(Wr(i))throw r.prependTo(i),i;if(i instanceof ze)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:Gt(this.ctx.state.env)};if(i instanceof Ue)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:Gt(this.ctx.state.env)};if(i instanceof Xe)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Gt(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 Fr){r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(i instanceof Qe||i instanceof Ke){if(this.ctx.state.loopDepth>0)throw i.prependOutput(r.stdout,r.stderr),i;r.append("stdout",i.stdout),r.append("stderr",i.stderr);continue}throw i instanceof _e&&i.prependOutput(r.stdout,r.stderr),i}return{...r.build(n),env:Gt(this.ctx.state.env)}}async executeUserScript(t,n,r=""){return jf(this.ctx,t,n,r,s=>this.executeScript(s))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Ye;if(t.deferredError)throw new ke(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return ee;this.ctx.state.errexitSafe=!1;let n=new Zt(this.ctx.executionScope,"statement");this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&n.append("stderr",`${t.sourceText}
802
+ `);let r=0,s=-1,i=!1;try{for(let l=0;l<t.pipelines.length;l++){let c=t.pipelines[l],u=l>0?t.operators[l-1]:null;if(u==="&&"&&r!==0||u==="||"&&r===0)continue;let f=await this.executePipeline(c);n.appendResult(f,ii(f)),r=f.exitCode,s=l,i=c.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}}catch(l){throw n.prependTo(l),l}let o=s<t.pipelines.length-1,a=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=o||i||a,this.ctx.state.options.errexit&&r!==0&&s===t.pipelines.length-1&&!i&&!this.ctx.state.inCondition&&!a){let l=new ze(r);throw l.prependOutput(n.stdout,n.stderr),l}return n.build(r)}async executePipeline(t){return zf(this.ctx,t,(n,r)=>this.executeCommand(n,r))}async executeCommand(t,n,r=!1){let s=uu(this.ctx),i;try{i=await this.executeCommandInner(t,n,r)}catch(a){throw await so(this.ctx,s).catch(()=>{}),a}let o=await so(this.ctx,s);return!o.stdout&&!o.stderr?i:{...i,stdout:o.stdout?Vt(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 Tf(this.ctx,t);case"For":return Ff(this.ctx,t);case"CStyleFor":return Mf(this.ctx,t);case"While":return Bf(this.ctx,t,n);case"Until":return Wf(this.ctx,t,n);case"Case":return Vf(this.ctx,t);case"Subshell":return this.executeSubshell(t,n,r);case"Group":return this.executeGroup(t,n,r);case"FunctionDef":return qu(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return Jm(t)}}async executeSimpleCommand(t,n){let r;try{return await this.executeSimpleCommandInner(t,n,s=>{r=s})}catch(s){if(r?.finish(),s instanceof Ut)return L(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 k=t,C=0;for(;;){let I=this.expandAlias(k);if(I===k)break;if(C>=this.ctx.limits.maxCallDepth)throw new P(`alias expansion depth limit exceeded (${this.ctx.limits.maxCallDepth})`,"recursion");C++,k=I}this.aliasExpansionStack.clear(),k!==t&&(t=k)}this.ctx.state.expansionStderr="",this.ctx.state.lastSubstitutionExitCode=null;let s=await vf(this.ctx,t);if(s.error)return s.error;let i=s.tempAssignments,o=s.xtraceOutput,a=()=>{for(let[k,C]of i)C===void 0?this.ctx.state.env.delete(k):this.ctx.state.env.set(k,C)};if(!t.name){if(t.redirections.length>0){let C=Qn(this.ctx,t.redirections,zu);r(C);let I=await C.prepare(n);if(I.error){if(a(),!I.errorCause)return C.finish(),I.error;try{return Kn(I)}finally{C.finish()}}let W=T("",o,fs(this.ctx.state,t.redirections)),Z=await hn(this.ctx,W,t.redirections,I.targets,I.dupSources,I.standardRoutes);return C.finish(),Z}this.ctx.state.lastArg="";let k=(this.ctx.state.expansionStderr||"")+o;return this.ctx.state.expansionStderr="",T("",k,fs(this.ctx.state,[]))}let l=t.name&&pa(t.name,["local","declare","typeset","export","readonly"]),c=Array.from(i.keys());if(c.length>0&&!l){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let k of c)this.ctx.state.tempExportedVars.add(k)}let u=await re(this.ctx,t.name),f=[],d=[],p=(k,C)=>{if(f.length>=this.ctx.limits.maxArrayElements)throw new P(`expanded argument element limit exceeded (${this.ctx.limits.maxArrayElements})`,"array_elements");f.push(k),d.push(C)};if(pa(t.name,["local","declare","typeset","export","readonly"])&&(u==="local"||u==="declare"||u==="typeset"||u==="export"||u==="readonly"))for(let k of t.args){let C=await Su(this.ctx,k);if(C)p(C,!0);else{let I=await Au(this.ctx,k);if(I!==null)p(I,!0);else{let W=await At(this.ctx,k);for(let Z of W.values)p(Z,W.quoted)}}}else for(let k of t.args){let C=await At(this.ctx,k);for(let I of C.values)p(I,C.quoted)}let y=t.name.parts.every(k=>k.type==="CommandSubstitution"||k.type==="ParameterExpansion"||k.type==="ArithmeticExpansion");!u&&y&&f.length>0&&(u=f.shift(),d.shift());let E=Qn(this.ctx,t.redirections,u==="exec"?Uu:Sr);r(E);let S=await E.prepare(n);if(S.error)return a(),S.errorCause?Kn(S):(E.finish(),S.error);let m=S.stdinSourceFd,g=S.stdin!==void 0;if(S.stdin!==void 0&&(n=S.stdin),!u)return y?(E.finish(),T("","",fs(this.ctx.state,t.redirections))):(E.finish(),L(`bash: : command not found
803
+ `,127));if(u==="exec"&&(f.length===0||f[0]==="--")){for(let[k,C]of i)C===void 0?this.ctx.state.env.delete(k):this.ctx.state.env.set(k,C);if(this.ctx.state.tempExportedVars)for(let k of i.keys())this.ctx.state.tempExportedVars.delete(k);return E.finish(),ee}if(this.ctx.state.extraArgs){let k=this.ctx.state.extraArgs;this.ctx.state.extraArgs=void 0;for(let C of k)p(C,!0)}let b=await Sf(this.ctx,u,f);i.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(i)));let v,x=null;try{v=await this.runCommand(u,f,d,n,!1,!1,m,g)}catch(k){if(k instanceof Qe||k instanceof Ke)x=k,v=ee;else throw k}m>=0&&u!=="read"&&dn(this.ctx,m,v.internalStdinConsumed??0);let A=o+b;if(A&&(v={...v,stderr:A+v.stderr}),v=await hn(this.ctx,v,t.redirections,S.targets,S.dupSources,S.standardRoutes,v.internalProducerCommand??u,v.internalProducerOmitsShellPrefix),E.finish(),x)throw x;if(f.length>0){let k=f[f.length-1];if((u==="declare"||u==="local"||u==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(k)){let C=k.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);C&&(k=C[1])}this.ctx.state.lastArg=k}else this.ctx.state.lastArg=u;let $=el(u)&&u!=="unset"&&u!=="eval";if(!this.ctx.state.options.posix||!$)for(let[k,C]of i)this.ctx.state.fullyUnsetLocals?.has(k)||(C===void 0?this.ctx.state.env.delete(k):this.ctx.state.env.set(k,C));if(this.ctx.state.tempExportedVars)for(let k of i.keys())this.ctx.state.tempExportedVars.delete(k);return i.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(v={...v,stderr:this.ctx.state.expansionStderr+v.stderr},this.ctx.state.expansionStderr=""),v}async runCommand(t,n,r,s,i=!1,o=!1,a=-1,l=!1){let c={ctx:this.ctx,runCommand:(d,p,h,y,E,S,m,g)=>this.runCommand(d,p,h,y,E,S,m,g),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(d,p,h)=>this.executeUserScript(d,p,h)},u=await Of(c,t,n,r,s,i,o,a,l);return u!==null?u.internalProducerCommand===void 0?{...u,internalProducerCommand:t}:u:{...await _f(c,t,n,s,o),internalProducerCommand:t}}aliasExpansionStack=new Set;expandAlias(t){return Zl({env:this.ctx.state.env,limits:this.ctx.limits},t,this.aliasExpansionStack)}async findCommandInPath(t){return Gr(this.ctx,t)}async executeSubshell(t,n="",r=!1){return Uf(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeGroup(t,n="",r=!1){return qf(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeArithmeticCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),rt(this.ctx,t.redirections,"",async()=>{try{let n=await Y(this.ctx,t.expression.expression),r=we(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){return L(`bash: arithmetic expression: ${n.message}
804
+ `)}})}async executeConditionalCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),rt(this.ctx,t.redirections,"",async()=>{try{let n=await cn(this.ctx,t.expression),r=we(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 L(`bash: conditional expression: ${n.message}
805
+ `,r)}})}};function ya(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function ey(e){let t=ya(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var ty=3;function Hf(e){let t=e;for(let n=0;n<ty;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 ny(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function ga(e,t){let n=ya(e);if(!n)return!1;let r=ey(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&Hf(n.pathname)?!1:ny(n.pathname,r.pathPrefix)}function Gf(e){return typeof e=="string"?e:e.url}function Zf(e,t){return!t||t.length===0?!1:t.some(n=>ga(e,Gf(n)))}function wa(e){let t=ry(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=Qf(t);if(n)return Ys(n);let r=iy(t);return r?oy(r):!1}function ry(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function sy(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 Qf(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>sy(l));if(n.some(l=>l===null))return null;let r=n;if(t.length===1){let l=r[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,c]=r;return l>255||c>16777215?null:[l,c>>>16&255,c>>>8&255,c&255]}if(t.length===3){let[l,c,u]=r;return l>255||c>255||u>65535?null:[l,c,u>>>8&255,u&255]}let[s,i,o,a]=r;return s>255||i>255||o>255||a>255?null:[s,i,o,a]}function iy(e){let t=e,n=null;if(t.includes(".")){let y=t.lastIndexOf(":");if(y<0)return null;let E=t.slice(y+1),S=Qf(E);if(!S)return null;n=S,t=t.slice(0,y)}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=y=>/^[0-9a-f]{1,4}$/i.test(y)?Number.parseInt(y,16):null,c=o.map(l),u=a.map(l);if(c.some(y=>y===null)||u.some(y=>y===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 Ys(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 oy(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 Ys(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 Ys(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 Ys(s)}return!1}function Kf(e){let t=[];for(let n of e){if(typeof n!="string"&&(n===null||typeof n!="object"||!("url"in n)||typeof n.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let r=Gf(n);if(!ya(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!==""&&Hf(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 vt=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},er=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},gn=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Js=class extends Error{constructor(t,n){super(`HTTP method '${t}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}},Rn=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var ay=20,ly=3e4,cy=10485760,uy=["GET","HEAD"],Rr;typeof __BROWSER__<"u"&&__BROWSER__?Rr=null:(Rr=import("./chunks/dist-4NZ74CRE.js"),Rr.catch(()=>{}));var fy=new Set(["GET","HEAD","OPTIONS"]),dy=new Set([301,302,303,307,308]);function Dr(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function py(e){if(e?.aborted)throw Dr(e)}function ba(e){let t=e.allowedUrlPrefixes??[];if(e._dnsResolve)throw new Error("NetworkConfig._dnsResolve is no longer supported: DNS resolution is performed by guarded-fetch and cannot be overridden");if(e._createConnectionOwner)throw new Error("NetworkConfig._createConnectionOwner is no longer supported: connect-time IP pinning is performed by guarded-fetch and cannot be overridden");let n=e._fetch;if(!e.dangerouslyAllowFullInternetAccess){let b=Kf(t);if(b.length>0)throw new Error(`Invalid network allow-list:
801
806
  ${b.join(`
802
- `)}`)}let r=[];for(let b of t)typeof b=="object"&&b.transform&&b.transform.length>0&&r.push(b);function s(b){if(r.length===0)return null;let A=null;for(let x of r)if(fa(b,x.url)&&x.transform){A||(A=new Headers);for(let v of x.transform)for(let[$,D]of Object.entries(v.headers))A.set($,D)}return A}if(e.maxRedirects!==void 0&&(!Number.isSafeInteger(e.maxRedirects)||e.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let i=e.maxRedirects??Jm,o=e.timeoutMs??ey,a=e.maxResponseSize??ty,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??ny,c=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),u=[];for(let b of t){let A=typeof b=="string"?b:b.url;try{u.push(new URL(A).hostname)}catch{}}function f(b){try{return new URL(b).hostname||"localhost.invalid"}catch{return"localhost.invalid"}}function d(b){return e.dangerouslyAllowFullInternetAccess?c?{allowedHosts:void 0,skipSsrfCheckForAllowedHosts:void 0}:{allowedHosts:[f(b)],skipSsrfCheckForAllowedHosts:!0}:{allowedHosts:u,skipSsrfCheckForAllowedHosts:!c}}function p(b){try{return da(new URL(b).hostname)}catch{return!1}}async function h(b,A){let x={method:A.method,headers:A.headers,signal:A.signal,redirect:"manual"};return A.body!==void 0&&(x.body=A.body),await(n??globalThis.fetch)(b,x)}function y(b){if(!e.dangerouslyAllowFullInternetAccess&&!Vf(b,t))throw new St(b)}function E(b){if(!c)return;let A;try{A=new URL(b)}catch{throw new St(b,"invalid URL")}if(da(A.hostname))throw new St(b,"private/loopback IP address blocked")}function S(b){if(e.dangerouslyAllowFullInternetAccess)return;let A=b.toUpperCase();if(!l.includes(A))throw new Qs(A,l)}function g(b,A,x,v){if(!x.isGuardedFetchError(b))return b;let $=b,{onRedirectHop:D,subReason:k}=v;switch($.code){case"host_not_allowed":case"protocol_not_allowed":return D?new mn(A):new St(A);case"hostname_unsafe":return D?new mn(A):new St(A,k==="dns_resolution_failed"?"DNS resolution failed for private IP check":"hostname resolves to private/loopback IP address");case"redirect_to_unsafe_host":return new mn(A);case"too_many_redirects":return new Xn(i);case"response_too_large":return new Pn(a);default:return b}}async function m(b,A={}){let x=A.method?.toUpperCase()??"GET",v=A.followRedirects??!0;if(A.maxRedirects!==void 0&&(!Number.isSafeInteger(A.maxRedirects)||A.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let $=A.maxRedirects??i,D=Math.min(i,$),k=A.timeoutMs!==void 0?Math.min(A.timeoutMs,o):o,C=new AbortController,I=ga(()=>C.abort(new DOMException("The operation was aborted","AbortError")),k),W=_r(A.signal,C.signal);try{y(b),E(b),S(x);let Z=Pr?await Pr:null,R=b,V=0,z=[],O=x,_=A.body,M=A.headers,re=!1;for(;;){iy(W.signal);let K=await Te.runTrustedAsync(async()=>{let Oe=M;if(re&&Oe){let _t=Oe instanceof Headers?new Headers(Oe):new Headers(Oe);_t.delete("authorization"),_t.delete("cookie"),Oe=_t}let ft=s(R),Ot=ay(Oe,ft),dt={method:O,headers:Ot,signal:W.signal,followRedirects:!1,timeoutMs:k,sanitizeHeaders:!1};if(_&&!ry.has(O)&&(dt.body=_),Object.assign(dt,d(R)),!Z||p(R)){if(c)throw new St(R,"DNS pinning unavailable for private IP enforcement");return await h(R,dt)}c?n&&(dt.fetch=n):(dt.fetch=n??globalThis.fetch,dt.dispatcher=null);let pt;dt.onUrlBlocked=_t=>{pt=_t.subReason};try{return await Z.guardedFetch(R,dt)}catch(_t){throw g(_t,R,Z,{onRedirectHop:V>0,subReason:pt})}});if(sy.has(K.status)&&v){let Oe=K.headers.get("location");if(!Oe)return await qf(K,R,a,W.signal,z);z.push({status:K.status,statusText:K.statusText,headers:jf(K.headers)});let ft=new URL(Oe,R).href;await pa(oy(K),W.signal);try{y(ft),E(ft)}catch(pt){throw W.signal?.aborted?Cr(W.signal):pt instanceof St?new mn(ft):pt}let Ot=K.status;if(((Ot===301||Ot===302)&&O==="POST"||Ot===303&&O!=="GET"&&O!=="HEAD")&&(O="GET",_=void 0,S(O)),new URL(ft).origin!==new URL(R).origin&&(re=!0),V++,V>D)throw new Xn(D);R=ft;continue}return await qf(K,R,a,W.signal,z)}}finally{wa(I),W.cleanup()}}return m}async function pa(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),Cr(t);let n,r=new Promise((s,i)=>{n=()=>i(Cr(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function oy(e){e.body&&!e.body.locked&&await e.body.cancel()}function ay(e,t){if(!e&&!t)return;if(!t)return e;let n=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,s]of t)n.set(r,s);return n}function jf(e){let t=Object.create(null);return e.forEach((n,r)=>{t[r.toLowerCase()]=n}),t}async function qf(e,t,n,r,s){let i=jf(e.headers);if(n>0){let l=e.headers.get("content-length");if(l){let c=parseInt(l,10);if(!Number.isNaN(c)&&c>n)throw new Pn(n)}}let o;if(n>0&&e.body){let l=e.body.getReader(),c=[],u=0;try{for(;;){let{done:d,value:p}=await pa(l.read(),r);if(d)break;if(p){if(u+=p.byteLength,u>n)throw await l.cancel(),new Pn(n);c.push(p)}}}catch(d){throw r?.aborted&&await l.cancel(Cr(r)).catch(()=>{}),d}o=new Uint8Array(u);let f=0;for(let d of c)o.set(d,f),f+=d.byteLength}else{let l=await pa(e.arrayBuffer(),r);if(n>0&&l.byteLength>n)throw new Pn(n);o=new Uint8Array(l)}let a={status:e.status,statusText:e.statusText,headers:i,body:o,url:t};return s&&s.length>0&&(a.redirectChain=s),a}function Ks(e,t){if(e.length>t||B(e)>t)throw new P(`script input size limit exceeded (${t} bytes)`,"string_length")}var Xs=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;abortOnUnresolvedCommands=!1;invokeToolFn;transformPlugins=[];state;constructor(t={}){if(this.limits=ai({...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),t.fs&&t.files)throw new Error("Bash: options.files is ignored when options.fs is provided; write the files into your filesystem directly or drop options.fs");let n=t.fs??new xt(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",`
803
- `],["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"],["PWD",r],["OLDPWD",r],["OPTIND","1"],...Object.entries(t.env??{})]);if(t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=ha(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.abortOnUnresolvedCommands=t.abortOnUnresolvedCommands??!1,this.coverageWriter=t.coverage,this.state={env:s,arrays:new Map,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastSubstitutionExitCode:null,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,virtualPid:t.processInfo?.pid??1,virtualPpid:t.processInfo?.ppid??0,virtualUid:t.processInfo?.uid??1e3,virtualGid:t.processInfo?.gid??1e3,bashPid:t.processInfo?.pid??1,nextVirtualPid:(t.processInfo?.pid??1)+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",fi(this.state.options)),this.state.env.set("BASHOPTS",di(this.state.shoptOptions)),za(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&n instanceof xt)try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of $a(t.commands))this.registerBundledCommand(o);if(t.fetch||t.network)for(let o of Pa())this.registerBundledCommand(o);if(t.python)for(let o of Ca())this.registerBundledCommand(o);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let o of Na())this.registerBundledCommand(o);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap),i.invokeTool&&(this.invokeToolFn=i.invokeTool)}if(t.customCommands)for(let o of t.customCommands)if(_a(o)){let a=La(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,handlesOwnVersion:t.handlesOwnVersion,execute:(l,c)=>t.execute(l,c)};this.commands.set(t.name,o);let a=this.fs;if(typeof a.writeFileSync=="function"){let l=`#!/bin/bash
807
+ `)}`)}let r=[];for(let b of t)typeof b=="object"&&b.transform&&b.transform.length>0&&r.push(b);function s(b){if(r.length===0)return null;let v=null;for(let x of r)if(ga(b,x.url)&&x.transform){v||(v=new Headers);for(let A of x.transform)for(let[$,R]of Object.entries(A.headers))v.set($,R)}return v}if(e.maxRedirects!==void 0&&(!Number.isSafeInteger(e.maxRedirects)||e.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let i=e.maxRedirects??ay,o=e.timeoutMs??ly,a=e.maxResponseSize??cy,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??uy,c=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),u=[];for(let b of t){let v=typeof b=="string"?b:b.url;try{u.push(new URL(v).hostname)}catch{}}function f(b){try{return new URL(b).hostname||"localhost.invalid"}catch{return"localhost.invalid"}}function d(b){return e.dangerouslyAllowFullInternetAccess?c?{allowedHosts:void 0,skipSsrfCheckForAllowedHosts:void 0}:{allowedHosts:[f(b)],skipSsrfCheckForAllowedHosts:!0}:{allowedHosts:u,skipSsrfCheckForAllowedHosts:!c}}function p(b){try{return wa(new URL(b).hostname)}catch{return!1}}async function h(b,v){let x={method:v.method,headers:v.headers,signal:v.signal,redirect:"manual"};return v.body!==void 0&&(x.body=v.body),await(n??globalThis.fetch)(b,x)}function y(b){if(!e.dangerouslyAllowFullInternetAccess&&!Zf(b,t))throw new vt(b)}function E(b){if(!c)return;let v;try{v=new URL(b)}catch{throw new vt(b,"invalid URL")}if(wa(v.hostname))throw new vt(b,"private/loopback IP address blocked")}function S(b){if(e.dangerouslyAllowFullInternetAccess)return;let v=b.toUpperCase();if(!l.includes(v))throw new Js(v,l)}function m(b,v,x,A){if(!x.isGuardedFetchError(b))return b;let $=b,{onRedirectHop:R,subReason:k}=A;switch($.code){case"host_not_allowed":case"protocol_not_allowed":return R?new gn(v):new vt(v);case"hostname_unsafe":return R?new gn(v):new vt(v,k==="dns_resolution_failed"?"DNS resolution failed for private IP check":"hostname resolves to private/loopback IP address");case"redirect_to_unsafe_host":return new gn(v);case"too_many_redirects":return new er(i);case"response_too_large":return new Rn(a);default:return b}}async function g(b,v={}){let x=v.method?.toUpperCase()??"GET",A=v.followRedirects??!0;if(v.maxRedirects!==void 0&&(!Number.isSafeInteger(v.maxRedirects)||v.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let $=v.maxRedirects??i,R=Math.min(i,$),k=v.timeoutMs!==void 0?Math.min(v.timeoutMs,o):o,C=new AbortController,I=va(()=>C.abort(new DOMException("The operation was aborted","AbortError")),k),W=Br(v.signal,C.signal);try{y(b),E(b),S(x);let Z=Rr?await Rr:null,D=b,V=0,U=[],O=x,_=v.body,B=v.headers,te=!1;for(;;){py(W.signal);let X=await Te.runTrustedAsync(async()=>{let Oe=B;if(te&&Oe){let Tt=Oe instanceof Headers?new Headers(Oe):new Headers(Oe);Tt.delete("authorization"),Tt.delete("cookie"),Oe=Tt}let dt=s(D),Lt=my(Oe,dt),pt={method:O,headers:Lt,signal:W.signal,followRedirects:!1,timeoutMs:k,sanitizeHeaders:!1};if(_&&!fy.has(O)&&(pt.body=_),Object.assign(pt,d(D)),!Z||p(D)){if(c)throw new vt(D,"DNS pinning unavailable for private IP enforcement");return await h(D,pt)}c?n&&(pt.fetch=n):(pt.fetch=n??globalThis.fetch,pt.dispatcher=null);let ht;pt.onUrlBlocked=Tt=>{ht=Tt.subReason};try{return await Z.guardedFetch(D,pt)}catch(Tt){throw m(Tt,D,Z,{onRedirectHop:V>0,subReason:ht})}});if(dy.has(X.status)&&A){let Oe=X.headers.get("location");if(!Oe)return await Xf(X,D,a,W.signal,U);U.push({status:X.status,statusText:X.statusText,headers:Yf(X.headers)});let dt=new URL(Oe,D).href;await Ea(hy(X),W.signal);try{y(dt),E(dt)}catch(ht){throw W.signal?.aborted?Dr(W.signal):ht instanceof vt?new gn(dt):ht}let Lt=X.status;if(((Lt===301||Lt===302)&&O==="POST"||Lt===303&&O!=="GET"&&O!=="HEAD")&&(O="GET",_=void 0,S(O)),new URL(dt).origin!==new URL(D).origin&&(te=!0),V++,V>R)throw new er(R);D=dt;continue}return await Xf(X,D,a,W.signal,U)}}finally{xa(I),W.cleanup()}}return g}async function Ea(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),Dr(t);let n,r=new Promise((s,i)=>{n=()=>i(Dr(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function hy(e){e.body&&!e.body.locked&&await e.body.cancel()}function my(e,t){if(!e&&!t)return;if(!t)return e;let n=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,s]of t)n.set(r,s);return n}function Yf(e){let t=Object.create(null);return e.forEach((n,r)=>{t[r.toLowerCase()]=n}),t}async function Xf(e,t,n,r,s){let i=Yf(e.headers);if(n>0){let l=e.headers.get("content-length");if(l){let c=parseInt(l,10);if(!Number.isNaN(c)&&c>n)throw new Rn(n)}}let o;if(n>0&&e.body){let l=e.body.getReader(),c=[],u=0;try{for(;;){let{done:d,value:p}=await Ea(l.read(),r);if(d)break;if(p){if(u+=p.byteLength,u>n)throw await l.cancel(),new Rn(n);c.push(p)}}}catch(d){throw r?.aborted&&await l.cancel(Dr(r)).catch(()=>{}),d}o=new Uint8Array(u);let f=0;for(let d of c)o.set(d,f),f+=d.byteLength}else{let l=await Ea(e.arrayBuffer(),r);if(n>0&&l.byteLength>n)throw new Rn(n);o=new Uint8Array(l)}let a={status:e.status,statusText:e.statusText,headers:i,body:o,url:t};return s&&s.length>0&&(a.redirectChain=s),a}function ei(e,t){if(e.length>t||M(e)>t)throw new P(`script input size limit exceeded (${t} bytes)`,"string_length")}var ti=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;abortOnUnresolvedCommands=!1;invokeToolFn;transformPlugins=[];state;constructor(t={}){if(this.limits=fi({...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),t.fs&&t.files)throw new Error("Bash: options.files is ignored when options.fs is provided; write the files into your filesystem directly or drop options.fs");let n=t.fs??new $t(t.files,{maxTotalBytes:this.limits.maxFileSystemBytes});this.fs=n,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),s=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
808
+ `],["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=ba(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.abortOnUnresolvedCommands=t.abortOnUnresolvedCommands??!1,this.coverageWriter=t.coverage,this.state={env:s,arrays:new Map,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastSubstitutionExitCode:null,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,virtualPid:t.processInfo?.pid??1,virtualPpid:t.processInfo?.ppid??0,virtualUid:t.processInfo?.uid??1e3,virtualGid:t.processInfo?.gid??1e3,bashPid:t.processInfo?.pid??1,nextVirtualPid:(t.processInfo?.pid??1)+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",mi(this.state.options)),this.state.env.set("BASHOPTS",yi(this.state.shoptOptions)),Ka(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&(n instanceof $t||n instanceof bn))try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of _a(t.commands))this.registerBundledCommand(o);if(t.fetch||t.network)for(let o of La())this.registerBundledCommand(o);if(t.python)for(let o of Ta())this.registerBundledCommand(o);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let o of Fa())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(za(o)){let a=Ua(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,handlesOwnVersion:t.handlesOwnVersion,execute:(l,c)=>t.execute(l,c)};this.commands.set(t.name,o);let a=this.fs;if(typeof a.writeFileSync=="function"){let l=`#!/bin/bash
804
809
  # Built-in command: ${t.name}
805
- `;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=Hf(t.stdout),t.stderr=Hf(t.stderr),t}async exec(t,n){let r=new Vr(this.limits,n?.signal,this.abortOnUnresolvedCommands),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
806
- `,exitCode:126}}return i.unresolvedCommands=r.unresolvedCommandNames,t.trim()?this.logResult(i):i}async execInScope(t,n,r,s,i,o=!1,a=!0){let l=f=>a?this.logResult(f):f,c=_r(i,n?.signal),u=n?{...n,signal:c.signal}:{signal:c.signal};try{if(r.assertExecDepth(s),Ks(t,this.limits.maxSourceBytes),!t.trim())return{stdout:"",stderr:"",exitCode:0,env:je(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[m,b]of Object.entries(u.env))h.set(m,b);d!==void 0&&h.set("PWD",d);let y={...this.state,env:h,arrays:u.replaceEnv?new Map:ot(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:uy(u.stdin,u.stdinKind,this.limits.maxInputBytes,this.limits.maxStringLength,r,o),signal:u.signal,extraArgs:u.args},E=t;u.rawScript||(E=ma(t));let S=this.defenseInDepthConfig?Te.getInstance(this.defenseInDepthConfig):null,g=S?.activate();try{let m=async()=>{let b=at(E,{maxHeredocSize:this.limits.maxHeredocSize}),A;if(this.transformPlugins.length>0){let k=Object.create(null);for(let C of this.transformPlugins){let I=C.transform({ast:b,metadata:k});b=I.ast,I.metadata&&(k=ni(k,I.metadata))}A=k}let x={fs:this.fs,commands:this.commands,limits:this.limits,executionScope:r,exec:(k,C,I=!1)=>this.execInScope(k,C,r,s+1,u.signal,I),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:S?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},D=await new $r(x,y).executeScript(b);return A&&(D.metadata=A),l(D)};return g?await g.run(m):await m()}catch(m){if(m instanceof q)return l({stdout:m.stdout,stderr:m.stderr,exitCode:m.exitCode,internalOutputAccounting:m.internalOutputAccounting,env:je(this.state.env,u.env)});if(m instanceof Pe){if(s>0)throw m;return l({stdout:m.stdout,stderr:m.stderr,exitCode:m.exitCode,internalOutputAccounting:m.internalOutputAccounting,env:je(this.state.env,u.env)})}if(m instanceof st)return l({stdout:m.stdout,stderr:m.stderr,exitCode:m.exitCode,env:je(this.state.env,u.env)});if(m instanceof le)return l({stdout:m.stdout,stderr:m.stderr,exitCode:1,env:je(this.state.env,u.env)});if(m instanceof Ye)return l({stdout:m.stdout,stderr:m.stderr,exitCode:124,env:je(this.state.env,u.env)});if(m instanceof P)return l({stdout:m.stdout,stderr:qe(m.stderr),exitCode:P.EXIT_CODE,internalOutputAccounting:m.internalOutputAccounting,env:je(this.state.env,u.env)});if(m instanceof Or)return l({stdout:"",stderr:`bash: security violation: ${qe(m.message)}
807
- `,exitCode:1,env:je(this.state.env,u.env)});if(m.name==="ParseException")return l({stdout:"",stderr:`bash: syntax error: ${qe(m.message)}
808
- `,exitCode:2,env:je(this.state.env,u.env)});if(m instanceof Je)return l({stdout:"",stderr:`bash: ${qe(m.message)}
809
- `,exitCode:2,env:je(this.state.env,u.env)});if(m instanceof RangeError)return l({stdout:"",stderr:`bash: ${qe(m.message)}
810
- `,exitCode:1,env:je(this.state.env,u.env)});throw m}finally{g?.deactivate()}}catch(f){if(f instanceof Ye)return l({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:je(this.state.env,u.env)});if(f instanceof P)return l({stdout:f.stdout,stderr:qe(f.stderr),exitCode:P.EXIT_CODE,internalOutputAccounting:f.internalOutputAccounting,env:je(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 Ht(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){Ks(t,this.limits.maxSourceBytes);let n=ma(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=ni(s,o.metadata))}return{script:Rl(r),ast:r,metadata:s}}async analyzeCommands(t){Ks(t,this.limits.maxSourceBytes);let n=at(ma(t),{maxHeredocSize:this.limits.maxHeredocSize}),{commands:r,definedFunctions:s,definedAliases:i}=Ua(n),o=[];for(let a of r)s.has(a)||i.has(a)||await this.resolvesCommandForAnalysis(a)||o.push(a);return{commands:r,unresolved:o}}async resolvesCommandForAnalysis(t){if((ir.has(t)||vt.has(t))&&!Aa.has(t)||this.state.functions.has(t))return!0;let n=await Ur({fs:this.fs,state:{...this.state,hashTable:new Map},commands:this.commands},t);return n!==null&&!("error"in n)}};function ly(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 ma(e){let t=e.split(`
811
- `),n=[],r=[],s="none";for(let i=0;i<t.length;i++){let o=t[i];if(r.length>0){let u=r[r.length-1];if((u.stripTabs?o.replace(/^\t+/,""):o)===u.delimiter){n.push(o.trimStart()),r.pop();continue}n.push(o);continue}let a=s,l=a==="none"?o.trimStart():o;if(n.push(l),s=ly(o,a),a!=="none")continue;let c=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let u of l.matchAll(c)){let f=u[1]==="-",d=u[3];r.push({delimiter:d,stripTabs:f})}}return n.join(`
812
- `)}var cy=new TextDecoder("utf-8",{fatal:!0});function Hf(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 cy.decode(n)}catch{return e}}function uy(e,t,n,r,s,i){if(e===void 0)return;let o=t==="bytes"?e.length:B(e);if(o>n||o>r)throw new P(`stdin size limit exceeded (${Math.min(n,r)} bytes)`,"string_length");return i||s.consumeInput(o,"stdin"),t==="bytes"?e:yn(e)}import*as ye from"node:fs";import*as Ie from"node:path";import*as Ve from"node:fs";import*as $e from"node:path";function Rr(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 Nr(e,t){try{let n=Ve.realpathSync(e);return Rr(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=$e.dirname(e);if(r===e)return null;let s=Nr(r,t);if(s===null)return null;try{if(Ve.lstatSync(e).isSymbolicLink()){let o=Ve.readlinkSync(e),a=$e.isAbsolute(o)?o:$e.resolve($e.dirname(e),o),l=Nr(a,t);return l===null?null:l}}catch{}return $e.join(s,$e.basename(e))}return null}}function Gf(e,t,n){let r=Nr(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(Ve.lstatSync(s).isSymbolicLink())return null}catch{}return r}function Zf(e,t){if(!Ve.existsSync(e))throw new Error(`${t} root does not exist`);if(!Ve.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function Qf(e,t){if(!$e.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=Ve.realpathSync(e)}catch{n=$e.resolve(e)}return Rr(n,t)?{withinRoot:!0,relativePath:Ea(n.slice(t.length))||"/"}:{withinRoot:!1,safeName:$e.basename(e)}}function Kf(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 N(i,`${n} '${t}'`)}async function At(e){return Xf(await Ve.promises.lstat(e))}function ya(e){return Xf(Ve.lstatSync(e))}function Xf(e){return process.platform==="win32"&&e.isDirectory()&&(e.mode=e.mode&-512|493),e}function Ys(e){let t=e.content.byteLength;for(let n of e.appendChunks??[])t+=n.byteLength;return t}function ed(e){return Ys(e)}function ei(e,t){if(!e.appendChunks||e.appendChunks.length===0)return e.content;let n=e.appendChunks.reduce((i,o)=>i+o.byteLength,e.content.byteLength);if(!Number.isSafeInteger(n))throw new N("EFBIG",`file too large, read '${t}'`);let r=new Uint8Array(n);r.set(e.content);let s=e.content.byteLength;for(let i of e.appendChunks)r.set(i,s),s+=i.byteLength;return e.content=r,e.appendChunks=void 0,r}function Yf(e){return!e||e.type!=="file"?0:Ys(e)}function Dr(){return{type:"directory",children:new Map,changedAt:Date.now(),mode:ht,mtime:new Date}}function Ir(e){return e.split("/").filter(Boolean)}var Js=class e{maxMemoryBytes;rootNode=Dr();bytes=0;mutationSeq_=0;constructor(t){this.maxMemoryBytes=t}get root(){return this.rootNode}get retainedBytes(){return this.bytes}descend(t){let n=Ir(t),r=[this.rootNode],s=this.rootNode;for(let i=0;i<n.length;i++){let o=s.children.get(n[i]);if(o===void 0)return{kind:"missing",stack:r,missingAt:i};if(i===n.length-1)return{kind:"found",stack:r,node:o};if(o.type==="whiteout")return{kind:"blocked",stack:r,blockedAt:i};if(o.type!=="directory")return{kind:"notdir",stack:r,notdirAt:i};r.push(o),s=o}return{kind:"found",stack:[],node:this.rootNode}}ensureDirs(t,n){let r=this.rootNode,s="";for(let i of Ir(t)){s=`${s}/${i}`;let o=r.children.get(i);if(o===void 0)o=Dr(),r.children.set(i,o);else if(o.type==="whiteout")o=this.resurrectDir(r,i,s,o.changedAt??0,n);else if(o.type!=="directory")throw new N("ENOTDIR",`not a directory, mkdir '${t}'`);r=o}return r}resurrectDir(t,n,r,s,i){let o=Dr();t.children.set(n,o);let a=i?.(r);if(a)for(let l of a)o.children.has(l)||o.children.set(l,{type:"whiteout",changedAt:s});return o}attach(t,n){n.changedAt=Date.now();let r=Ir(t);if(r.length===0)throw new N("EINVAL",`cannot attach at root, attach '${t}'`);let s=this.parentDirOf(r,t),i=s.children.get(r[r.length-1]);if(i?.type==="directory"&&n.type!=="directory")throw new N("EISDIR",`cannot replace directory with ${n.type}, attach '${t}'`);if(i!==void 0&&n.type==="directory")throw new N("EEXIST",`cannot replace ${i.type} with directory, attach '${t}'`);let o=Yf(i),a=Yf(n);this.assertCapacity(a,o),s.children.set(r[r.length-1],n),this.bytes+=a-o}detach(t){let n=Ir(t);if(n.length===0)return;let r=this.descend(t);return r.kind!=="found"?void 0:(r.stack[r.stack.length-1].children.delete(n[n.length-1]),this.bytes-=e.subtreeBytes(r.node),r.node)}putWhiteout(t){let n=Ir(t);if(n.length===0)throw new N("EINVAL",`cannot whiteout the root, rm '${t}'`);let r=this.rootNode;for(let o=0;o<n.length-1;o++)r=this.ensureChildDir(r,n[o],t);let s=n[n.length-1],i=r.children.get(s);i?.type!=="whiteout"&&(this.bytes-=e.subtreeBytes(i),r.children.set(s,{type:"whiteout",changedAt:Date.now()}))}appendChunk(t,n){this.assertCapacity(n.byteLength),t.appendChunks||(t.appendChunks=[]),t.appendChunks.push(n),this.bytes+=n.byteLength,this.touch(t)}touch(t){t.seq=++this.mutationSeq_,t.changedAt=Date.now()}detachIfUnchanged(t,n,r){let s=this.descend(t);return s.kind!=="found"||s.node!==n||n.seq!==r||n.type==="directory"&&n.children.size>0?!1:(this.detach(t),!0)}*preOrder(){let t=[{path:"/",node:this.rootNode}];for(;t.length>0;){let n=t.pop();if(yield n,n.node.type==="directory"){let r=[...n.node.children.entries()];for(let s=r.length-1;s>=0;s--){let[i,o]=r[s];t.push({path:Jf(n.path,i),node:o})}}}}*postOrder(){let t=[],n=[{path:"/",node:this.rootNode}];for(;n.length>0;){let r=n.pop();if(t.push(r),r.node.type==="directory")for(let[s,i]of r.node.children)n.push({path:Jf(r.path,s),node:i})}for(let r=t.length-1;r>=0;r--)yield t[r]}clear(){this.rootNode=Dr(),this.bytes=0}static subtreeBytes(t){if(t===void 0)return 0;if(t.type==="file")return Ys(t);if(t.type!=="directory")return 0;let n=0,r=[t];for(;r.length>0;){let s=r.pop();for(let i of s.children.values())i.type==="file"?n+=Ys(i):i.type==="directory"&&r.push(i)}return n}parentDirOf(t,n){let r=this.rootNode;for(let s=0;s<t.length-1;s++){let i=r.children.get(t[s]);if(i?.type!=="directory")throw new N("ENOTDIR",`not a directory, attach '${n}'`);r=i}return r}ensureChildDir(t,n,r){let s=t.children.get(n);if(s===void 0||s.type==="whiteout")s=Dr(),t.children.set(n,s);else if(s.type!=="directory")throw new N("ENOTDIR",`not a directory, rm '${r}'`);return s}assertCapacity(t,n=0){if(!Number.isSafeInteger(t)||t<0||t>this.maxMemoryBytes-this.bytes+n)throw new N("ENOSPC",`overlay memory byte limit exceeded (${this.maxMemoryBytes} bytes)`)}};function Jf(e,t){return e==="/"?`/${t}`:`${e}/${t}`}var fy=["ELOOP","EFBIG","EPERM"],dy="/home/user/project",Yn=class{root;canonicalRoot;mountPoint;readOnly;maxFileReadSize;maxMemoryBytes;allowSymlinks;tree;nextMemoryIdentity=1;get rootDir(){return this.root}restamp(t,n,r="full"){let s=U(t),i=c=>{let u=this.tree.descend(c);u.kind==="found"&&(u.node.changedAt=n)},o=c=>{let u=this.tree.descend(c);if(u.kind==="found"){let f=u.node;(f.changedAt??0)>n&&(f.changedAt=n,f.mtime=new Date(n))}};r==="full"&&i(s);let a=s;for(;;){let c=a.lastIndexOf("/");if(c<=0)break;a=a.slice(0,c),o(a)}if(r==="ancestors")return;let l=[s];for(;l.length>0;){let c=l.pop(),u=this.tree.descend(c);if(!(u.kind!=="found"||u.node.type!=="directory"))for(let f of u.node.children.keys()){let d=`${c==="/"?"":c}/${f}`;o(d),l.push(d)}}}identityFor(t){return t.type==="symlink"?"":(t.identity||(t.identity=`overlay:${this.nextMemoryIdentity++}`),t.identity)}constructor(t){this.root=Ie.resolve(t.root);let n=t.mountPoint??dy;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,Zf(this.root,"OverlayFs"),this.canonicalRoot=ye.realpathSync(this.root),this.tree=new Js(this.maxMemoryBytes),this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new N("EROFS",`read-only file system, ${t}`)}createMountPointDirs(){this.tree.ensureDirs(this.mountPoint)}getMountPoint(){return this.mountPoint}diff(){let t=[],n=[],r=[];for(let{path:i,node:o}of this.tree.preOrder()){let a=this.getRelativeToMount(i);if(!(a===null||a==="/")){if(o.type==="whiteout"){this.existsOnRealFs(i)&&(n.push(a),r.push(o.changedAt??0));continue}if(o.type==="file")if(o.metacopy){if(!this.existsOnRealFs(i))continue;t.push({path:a,nodeType:"file",content:new Uint8Array(0),mode:o.mode,mtime:o.mtime,changedAt:o.changedAt??0,metadataOnly:!0})}else t.push({path:a,nodeType:"file",content:ei(o,i),mode:o.mode,mtime:o.mtime,changedAt:o.changedAt??0});else o.type==="directory"?t.push({path:a,nodeType:"directory",content:new Uint8Array(0),mode:o.mode,mtime:o.mtime,changedAt:o.changedAt??0}):t.push({path:a,nodeType:"symlink",content:new TextEncoder().encode(o.target),mode:o.mode,mtime:o.mtime,changedAt:o.changedAt??0})}}t.sort((i,o)=>i.path<o.path?-1:i.path>o.path?1:0);let s=n.map((i,o)=>({path:i,changedAt:r[o]}));return s.sort((i,o)=>i.path<o.path?-1:i.path>o.path?1:0),{writes:t,deletions:s.map(i=>i.path),...s.length>0&&{deletionChangedAt:s.map(i=>i.changedAt)}}}async sync(){for(let{path:t,node:n}of this.tree.postOrder()){let r=this.getRelativeToMount(t);if(r===null||r==="/")continue;if(n.type==="whiteout"){this.existsOnRealFs(t)||this.tree.detach(t);continue}if(n.type==="directory"&&n.children.size>0)continue;let s=n.seq;await this.nodeMatchesDisk(t,n)&&this.tree.detachIfUnchanged(t,n,s)}}reset(){this.tree.clear(),this.createMountPointDirs()}drop(t){let n=t.map(r=>{let s=U(r);if(s==="/")throw new N("EINVAL",`invalid argument, drop '${r}'`);return this.mountPoint==="/"?s:`${this.mountPoint}${s}`});n.sort((r,s)=>s.length-r.length);for(let r of n){let s=this.tree.descend(r);if(s.kind!=="found")continue;let i=s.node;i.type==="directory"&&i.children.size>0||this.tree.detach(r)}}async lstatLower(t){let n=this.resolveRealPathParent_(this.toRealPath(t));if(!n)return null;try{return{canonical:n,stat:await At(n)}}catch{return null}}async nodeMatchesDisk(t,n){if(n.type==="directory")return(await this.lstatLower(t))?.stat.isDirectory()??!1;if(n.type==="symlink"){if(!this.allowSymlinks)return!1;let s=await this.lstatLower(t);if(!s?.stat.isSymbolicLink())return!1;try{let i=await ye.promises.readlink(s.canonical);return this.realTargetToVirtual(i)===n.target}catch{return!1}}if(n.metacopy){let s=await this.lstatLower(t);if(!s?.stat.isFile())return!1;let{stat:i}=s;return!(i.mtime.getTime()!==n.mtime.getTime()||process.platform!=="win32"&&(i.mode&4095)!==(n.mode&4095))}let r=this.resolveRealPath_(this.toRealPath(t));if(!r)return!1;try{let s=await At(r);if(!s.isFile())return!1;let i=ei(n,t);if(s.size!==i.byteLength)return!1;let o=this.allowSymlinks?ye.constants.O_RDONLY:ye.constants.O_RDONLY|ye.constants.O_NOFOLLOW,a=await ye.promises.open(r,o),l;try{l=new Uint8Array(await a.readFile())}finally{await a.close()}for(let c=0;c<l.byteLength;c++)if(l[c]!==i[c])return!1;return!0}catch{return!1}}mkdirSync(t,n){this.tree.ensureDirs(U(t),r=>this.lowerChildren(r))}writeFileSync(t,n){let r=U(t);this.ensureParentDirs(r);let s=n instanceof Uint8Array?n:new TextEncoder().encode(n);this.tree.attach(r,{type:"file",content:s,mode:jt,mtime:new Date})}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let n=U(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=Ie.join(this.root,r),i=Ie.resolve(s);return Rr(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?Nr(t,this.canonicalRoot):Gf(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=Ie.dirname(t),r=this.resolveRealPath_(n);return r===null?null:Ie.join(r,Ie.basename(t))}sanitizeError(t,n,r){Kf(t,n,r,fy)}ensureParentDirs(t){let n=Rn(t);n!=="/"&&this.tree.ensureDirs(n,r=>this.lowerChildren(r))}lowerChildren(t){let n=this.resolveRealPath_(this.toRealPath(t));if(!n)return null;try{return ye.readdirSync(n)}catch{return null}}async existsInOverlay(t){let n=U(t),r=this.tree.descend(n);if(r.kind==="found")return r.node.type!=="whiteout";if(r.kind==="blocked"||r.kind==="notdir")return!1;let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)return!1;try{return await At(s),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=Zt(n);return _n(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return _n(n,"binary")}async readFileBuffer(t,n=new Set){X(t,"open");let r=U(t);if(n.has(r))throw new N("ELOOP",`too many levels of symbolic links, open '${t}'`);n.add(r);let s=this.tree.descend(r);if(s.kind==="blocked")throw new N("ENOENT",`no such file or directory, open '${t}'`);if(s.kind==="notdir")throw new N("ENOTDIR",`not a directory, open '${t}'`);if(s.kind==="found"){let i=s.node;if(i.type==="whiteout")throw new N("ENOENT",`no such file or directory, open '${t}'`);if(i.type==="symlink"){let a=this.resolveSymlink(r,i.target);return this.readFileBuffer(a,n)}if(i.type!=="file")throw new N("EISDIR",`illegal operation on a directory, read '${t}'`);if(!i.metacopy)return ei(i,t);let o=await this.readLowerFileBytes(r,t,n);if(process.platform==="win32")try{this.tree.attach(r,{type:"file",content:o,mode:i.mode,mtime:i.mtime})}catch(a){if(!it(a,"ENOSPC"))throw a}return o}return this.readLowerFileBytes(r,t,n)}async readLowerFileBytes(t,n,r){let s=this.resolveRealPath_(this.toRealPath(t));if(!s)throw new N("ENOENT",`no such file or directory, open '${n}'`);try{let i=await At(s);if(i.isSymbolicLink()){if(!this.allowSymlinks)throw new N("ENOENT",`no such file or directory, open '${n}'`);let l=await ye.promises.readlink(s),c=this.realTargetToVirtual(l),u=this.resolveSymlink(t,c);return this.readFileBuffer(u,r)}if(i.isDirectory())throw new N("EISDIR",`illegal operation on a directory, read '${n}'`);if(this.maxFileReadSize>0&&i.size>this.maxFileReadSize)throw new N("EFBIG",`file too large, read '${n}' (${i.size} bytes, max ${this.maxFileReadSize})`);let o=this.allowSymlinks?ye.constants.O_RDONLY:ye.constants.O_RDONLY|ye.constants.O_NOFOLLOW,a=await ye.promises.open(s,o);try{let l=await a.readFile();return new Uint8Array(l)}finally{await a.close()}}catch(i){let o=i.code;if(o==="ENOENT")throw new N("ENOENT",`no such file or directory, open '${n}'`);if(o==="ELOOP")throw new N("ENOENT",`no such file or directory, open '${n}'`);this.sanitizeError(i,n,"open")}}async writeFile(t,n,r){X(t,"write"),this.assertWritable(`write '${t}'`);let s=U(t);this.ensureParentDirs(s);let i=Zt(r),o=On(n,i);this.tree.attach(s,{type:"file",content:o,mode:await this.inheritedMode(s),mtime:new Date})}async inheritedMode(t){let n=this.entryAt(t);if(n?.type==="file")return n.mode;if(n?.type==="directory")return jt;if(process.platform==="win32")return jt;try{let r=await this.stat(t);if(r.isFile)return r.mode}catch{}return jt}async appendFile(t,n,r){X(t,"append"),this.assertWritable(`append '${t}'`);let s=U(t),i=Zt(r),o=On(n,i),a=this.tree.descend(s);if(a.kind==="found"&&a.node.type==="file"){await this.appendToExisting_(s,a.node,o,t);return}if(a.kind==="blocked")throw new N("ENOENT",`no such file or directory, append '${t}'`);if(a.kind==="notdir")throw new N("ENOTDIR",`not a directory, append '${t}'`);let l;try{l=await this.readFileBuffer(s)}catch(f){if(!it(f,"ENOENT"))throw f;l=new Uint8Array(0)}let c=await this.inheritedMode(s),u=this.tree.descend(s);if(u.kind==="found"&&u.node.type==="file"){await this.appendToExisting_(s,u.node,o,t);return}this.ensureParentDirs(s),this.tree.attach(s,{type:"file",content:l,appendChunks:[o],mode:c,mtime:new Date})}async appendToExisting_(t,n,r,s){if(n.metacopy){let i=await this.readLowerFileBytes(t,s,new Set),o=this.tree.descend(t);if(o.kind==="found"&&o.node.type==="file"&&!o.node.metacopy){this.tree.appendChunk(o.node,r),o.node.mtime=new Date;return}this.tree.attach(t,{type:"file",content:i,appendChunks:[r],mode:n.mode,mtime:new Date});return}this.tree.appendChunk(n,r),n.mtime=new Date}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,n=new Set){X(t,"stat");let r=U(t);if(n.has(r))throw new N("ELOOP",`too many levels of symbolic links, stat '${t}'`);n.add(r);let s=this.tree.descend(r);if(s.kind==="blocked")throw new N("ENOENT",`no such file or directory, stat '${t}'`);if(s.kind==="notdir")throw new N("ENOTDIR",`not a directory, stat '${t}'`);if(s.kind==="found"){let o=s.node;if(o.type==="whiteout")throw new N("ENOENT",`no such file or directory, stat '${t}'`);if(o.type==="symlink"){let a=this.resolveSymlink(r,o.target);return this.stat(a,n)}return this.memoryEntryStat(o)}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new N("ENOENT",`no such file or directory, stat '${t}'`);try{let o=await At(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new N("ENOENT",`no such file or directory, stat '${t}'`);let a=await ye.promises.readlink(i),l=this.realTargetToVirtual(a),c=this.resolveSymlink(r,l);return this.stat(c,n)}return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:!1,mode:o.mode,size:o.size,mtime:o.mtime,dev:o.dev,ino:o.ino}}catch(o){if(o.code==="ENOENT")throw new N("ENOENT",`no such file or directory, stat '${t}'`);this.sanitizeError(o,t,"stat")}}async lstat(t){X(t,"lstat");let n=U(t),r=this.tree.descend(n);if(r.kind==="blocked")throw new N("ENOENT",`no such file or directory, lstat '${t}'`);if(r.kind==="notdir")throw new N("ENOTDIR",`not a directory, lstat '${t}'`);if(r.kind==="found"){let i=r.node;if(i.type==="whiteout")throw new N("ENOENT",`no such file or directory, lstat '${t}'`);return this.memoryEntryStat(i)}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new N("ENOENT",`no such file or directory, lstat '${t}'`);try{let i=await At(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 N("ENOENT",`no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}memoryEntryStat(t){if(t.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:t.mode,size:t.target.length,mtime:t.mtime};let n=0;return t.type==="file"&&(n=t.metacopy?t.lowerSize??0:ed(t)),{isFile:t.type==="file",isDirectory:t.type==="directory",isSymbolicLink:!1,mode:t.mode,size:n,mtime:t.mtime,identity:this.identityFor(t)}}resolveSymlink(t,n){return In(t,n)}realTargetToVirtual(t){let n=Qf(t,this.canonicalRoot);if(n.withinRoot){if(!Ie.isAbsolute(t))return t;let r=n.relativePath;return this.mountPoint==="/"?r:`${this.mountPoint}${r}`}return n.safeName}async mkdir(t,n){X(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=U(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new N("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 N("ENOENT",`no such file or directory, mkdir '${t}'`);this.tree.ensureDirs(r,o=>this.lowerChildren(o))}async readdirCore(t,n){let r=new Map,s=new Set,i=this.tree.descend(n);if(i.kind==="blocked")throw new N("ENOENT",`no such file or directory, scandir '${t}'`);if(i.kind==="notdir")throw new N("ENOTDIR",`not a directory, scandir '${t}'`);let o;if(i.kind==="found"){let l=i.node;if(l.type==="whiteout")throw new N("ENOENT",`no such file or directory, scandir '${t}'`);if(l.type!=="directory")throw new N("ENOTDIR",`not a directory, scandir '${t}'`);o=l;for(let[c,u]of l.children){if(u.type==="whiteout"){s.add(c);continue}r.set(c,{name:c,isFile:u.type==="file",isDirectory:u.type==="directory",isSymbolicLink:u.type==="symlink"})}}let a=this.resolveRealPath_(this.toRealPath(n));if(a)try{if(!this.allowSymlinks&&(await At(a)).isSymbolicLink()){if(!o)throw new N("ENOENT",`no such file or directory, scandir '${t}'`);return r}let l=await ye.promises.readdir(a,{withFileTypes:!0});for(let c of l)!s.has(c.name)&&!r.has(c.name)&&r.set(c.name,{name:c.name,isFile:c.isFile(),isDirectory:c.isDirectory(),isSymbolicLink:c.isSymbolicLink()})}catch(l){if(l.code==="ENOENT"){if(!o)throw new N("ENOENT",`no such file or directory, scandir '${t}'`)}else l.code!=="ENOTDIR"&&this.sanitizeError(l,t,"scandir")}return r}async resolveForReaddir(t,n=!1){let r=U(t),s=new Set,i=n;for(;;){let l=this.tree.descend(r);if(l.kind!=="found")break;let c=l.node;if(c.type!=="symlink")return{normalized:r,outsideOverlay:!1};if(s.has(r))throw new N("ELOOP",`too many levels of symbolic links, scandir '${t}'`);s.add(r),i=!0,r=this.resolveSymlink(r,c.target)}if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let a=this.resolveRealPath_(this.toRealPath(r));if(!a)return{normalized:r,outsideOverlay:!0};try{if((await At(a)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let c=await ye.promises.readlink(a),u=this.realTargetToVirtual(c),f=this.resolveSymlink(r,u);return this.resolveForReaddir(f,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async readdir(t){X(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){X(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){X(t,"rm"),this.assertWritable(`rm '${t}'`);let r=U(t);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new N("ENOENT",`no such file or directory, rm '${t}'`)}let i=!1;try{(await this.stat(r)).isDirectory&&(i=(await this.readdir(r)).length>0)}catch{}if(i&&!n?.recursive)throw new N("ENOTEMPTY",`directory not empty, rm '${t}'`);this.existsOnRealFs(r)?this.tree.putWhiteout(r):this.tree.detach(r)}existsOnRealFs(t){let n=this.toRealPath(t),r=this.resolveRealPathParent_(n);if(!r)return!1;try{return ya(r),!0}catch{return!1}}async cp(t,n,r){X(t,"cp"),X(n,"cp"),this.assertWritable(`cp '${n}'`);let s=U(t),i=U(n);if(!await this.existsInOverlay(s))throw new N("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 N("EISDIR",`is a directory, cp '${t}'`);if(Tt(s,i))throw new N("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 Dn(t,n)}getAllPaths(){let t=new Set;for(let{path:n,node:r}of this.tree.preOrder())r.type!=="whiteout"&&t.add(n);return this.scanRealFs(this.mountPoint,t),Array.from(t)}scanRealFs(t,n){if(this.lowerHidden(t))return;let r=this.resolveRealPath_(this.toRealPath(t));if(r)try{let s=ye.readdirSync(r);for(let i of s){let o=t==="/"?`/${i}`:`${t}/${i}`;if(this.lowerHidden(o))continue;n.add(o);let a=Ie.join(r,i);ya(a).isDirectory()&&this.scanRealFs(o,n)}}catch{}}lowerHidden(t){let n=this.tree.descend(t);switch(n.kind){case"blocked":case"notdir":return!0;case"found":return n.node.type!=="directory";default:return!1}}entryAt(t){let n=this.tree.descend(t);if(n.kind==="found"&&n.node.type!=="whiteout")return n.node}async chmod(t,n){X(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=U(t);if(!await this.existsInOverlay(r))throw new N("ENOENT",`no such file or directory, chmod '${t}'`);let i=this.entryAt(r);if(i){i.mode=n,this.tree.touch(i);return}let o=await this.stat(r);this.attachMetacopyShadow(r,o,n,o.isFile?o.mtime:new Date)}attachMetacopyShadow(t,n,r,s){this.ensureParentDirs(t),n.isFile?this.tree.attach(t,{type:"file",content:new Uint8Array(0),metacopy:!0,lowerSize:n.size,mode:r,mtime:s}):n.isDirectory&&this.tree.attach(t,{type:"directory",children:new Map,mode:r,mtime:s})}async symlink(t,n){if(!this.allowSymlinks)throw new N("EPERM",`operation not permitted, symlink '${n}'`);X(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=U(n);if(await this.existsInOverlay(r))throw new N("EEXIST",`file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.tree.attach(r,{type:"symlink",target:t,mode:Br,mtime:new Date})}async link(t,n){X(t,"link"),X(n,"link"),this.assertWritable(`link '${n}'`);let r=U(t),s=U(n);if(!await this.existsInOverlay(r))throw new N("ENOENT",`no such file or directory, link '${t}'`);let o=await this.stat(r);if(!o.isFile)throw new N("EPERM",`operation not permitted, link '${t}'`);if(await this.existsInOverlay(s))throw new N("EEXIST",`file already exists, link '${n}'`);let l=await this.readFileBuffer(r);this.ensureParentDirs(s),this.tree.attach(s,{type:"file",content:l,mode:o.mode,mtime:new Date,identity:o.identity??`overlay:${this.nextMemoryIdentity++}`})}async readlink(t){X(t,"readlink");let n=U(t),r=this.tree.descend(n);if(r.kind==="blocked")throw new N("ENOENT",`no such file or directory, readlink '${t}'`);if(r.kind==="notdir")throw new N("ENOTDIR",`not a directory, readlink '${t}'`);if(r.kind==="found"){let i=r.node;if(i.type==="whiteout")throw new N("ENOENT",`no such file or directory, readlink '${t}'`);if(i.type!=="symlink")throw new N("EINVAL",`invalid argument, readlink '${t}'`);return i.target}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new N("ENOENT",`no such file or directory, readlink '${t}'`);try{let i=await ye.promises.readlink(s);if(!Ie.isAbsolute(i)){let o=Ie.resolve(Ie.dirname(s),i),a;try{a=ye.realpathSync(o)}catch{a=o}if(!Rr(a,this.canonicalRoot))return Ie.basename(i)}return this.realTargetToVirtual(i)}catch(i){if(i.code==="ENOENT")throw new N("ENOENT",`no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new N("EINVAL",`invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){X(t,"realpath");let n=U(t),r=new Set,s=l=>{let c=this.tree.descend(l);if(c.kind==="blocked"||c.kind==="found"&&c.node.type==="whiteout")throw new N("ENOENT",`no such file or directory, realpath '${t}'`);return c.kind==="found"?c.node:void 0},i=async l=>{let c=l==="/"?[]:l.slice(1).split("/"),u="";for(let f of c){if(u=`${u}/${f}`,r.has(u))throw new N("ELOOP",`too many levels of symbolic links, realpath '${t}'`);let d=s(u),p=0,h=tr;for(;d&&d.type==="symlink"&&p<h;){if(r.add(u),u=this.resolveSymlink(u,d.target),p++,r.has(u))throw new N("ELOOP",`too many levels of symbolic links, realpath '${t}'`);d=s(u)}if(p>=h)throw new N("ELOOP",`too many levels of symbolic links, realpath '${t}'`);if(!d){let y=this.toRealPath(u),E=this.resolveRealPath_(y);if(E)try{if((await At(E)).isSymbolicLink()){if(!this.allowSymlinks)throw new N("ENOENT",`no such file or directory, realpath '${t}'`);let g=await ye.promises.readlink(E),m=this.realTargetToVirtual(g);return r.add(u),u=this.resolveSymlink(u,m),i(u)}}catch(S){if(S.code==="ENOENT")throw new N("ENOENT",`no such file or directory, realpath '${t}'`);this.sanitizeError(S,t,"realpath")}else if(!this.allowSymlinks){let S=this.resolveRealPathParent_(y);if(S)try{if((await At(S)).isSymbolicLink())throw new N("ENOENT",`no such file or directory, realpath '${t}'`)}catch(g){if(it(g,"ENOENT")||it(g,"ELOOP"))throw new N("ENOENT",`no such file or directory, realpath '${t}'`);this.sanitizeError(g,t,"realpath")}}}}return u||"/"},o=await i(n);if(!await this.existsInOverlay(o))throw new N("ENOENT",`no such file or directory, realpath '${t}'`);return o}async utimes(t,n,r){X(t,"utimes"),this.assertWritable(`utimes '${t}'`);let s=U(t);if(!await this.existsInOverlay(s))throw new N("ENOENT",`no such file or directory, utimes '${t}'`);let o=this.entryAt(s);if(o){o.mtime=r,this.tree.touch(o);return}let a=await this.stat(s);this.attachMetacopyShadow(s,a,a.mode,r)}};function nd(){console.log(`just-bash - A secure bash environment for AI agents
810
+ `;try{a.writeFileSync(`/bin/${t.name}`,l)}catch{}try{a.writeFileSync(`/usr/bin/${t.name}`,l)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=Jf(t.stdout),t.stderr=Jf(t.stderr),t}async exec(t,n){let r=new qr(this.limits,n?.signal,this.abortOnUnresolvedCommands),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
811
+ `,exitCode:126}}return i.unresolvedCommands=r.unresolvedCommandNames,t.trim()?this.logResult(i):i}async execInScope(t,n,r,s,i,o=!1,a=!0){let l=f=>a?this.logResult(f):f,c=Br(i,n?.signal),u=n?{...n,signal:c.signal}:{signal:c.signal};try{if(r.assertExecDepth(s),ei(t,this.limits.maxSourceBytes),!t.trim())return{stdout:"",stderr:"",exitCode:0,env:je(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[g,b]of Object.entries(u.env))h.set(g,b);d!==void 0&&h.set("PWD",d);let y={...this.state,env:h,arrays:u.replaceEnv?new Map:at(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:wy(u.stdin,u.stdinKind,this.limits.maxInputBytes,this.limits.maxStringLength,r,o),signal:u.signal,extraArgs:u.args},E=t;u.rawScript||(E=Sa(t));let S=this.defenseInDepthConfig?Te.getInstance(this.defenseInDepthConfig):null,m=S?.activate();try{let g=async()=>{let b=lt(E,{maxHeredocSize:this.limits.maxHeredocSize}),v;if(this.transformPlugins.length>0){let k=Object.create(null);for(let C of this.transformPlugins){let I=C.transform({ast:b,metadata:k});b=I.ast,I.metadata&&(k=oi(k,I.metadata))}v=k}let x={fs:this.fs,commands:this.commands,limits:this.limits,executionScope:r,exec:(k,C,I=!1)=>this.execInScope(k,C,r,s+1,u.signal,I),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:S?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},R=await new Nr(x,y).executeScript(b);return v&&(R.metadata=v),l(R)};return m?await m.run(g):await g()}catch(g){if(g instanceof q)return l({stdout:g.stdout,stderr:g.stderr,exitCode:g.exitCode,internalOutputAccounting:g.internalOutputAccounting,env:je(this.state.env,u.env)});if(g instanceof Pe){if(s>0)throw g;return l({stdout:g.stdout,stderr:g.stderr,exitCode:g.exitCode,internalOutputAccounting:g.internalOutputAccounting,env:je(this.state.env,u.env)})}if(g instanceof st)return l({stdout:g.stdout,stderr:g.stderr,exitCode:g.exitCode,env:je(this.state.env,u.env)});if(g instanceof ae)return l({stdout:g.stdout,stderr:g.stderr,exitCode:1,env:je(this.state.env,u.env)});if(g instanceof Ye)return l({stdout:g.stdout,stderr:g.stderr,exitCode:124,env:je(this.state.env,u.env)});if(g instanceof P)return l({stdout:g.stdout,stderr:qe(g.stderr),exitCode:P.EXIT_CODE,internalOutputAccounting:g.internalOutputAccounting,env:je(this.state.env,u.env)});if(g instanceof Tr)return l({stdout:"",stderr:`bash: security violation: ${qe(g.message)}
812
+ `,exitCode:1,env:je(this.state.env,u.env)});if(g.name==="ParseException")return l({stdout:"",stderr:`bash: syntax error: ${qe(g.message)}
813
+ `,exitCode:2,env:je(this.state.env,u.env)});if(g instanceof Je)return l({stdout:"",stderr:`bash: ${qe(g.message)}
814
+ `,exitCode:2,env:je(this.state.env,u.env)});if(g instanceof RangeError)return l({stdout:"",stderr:`bash: ${qe(g.message)}
815
+ `,exitCode:1,env:je(this.state.env,u.env)});throw g}finally{m?.deactivate()}}catch(f){if(f instanceof Ye)return l({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:je(this.state.env,u.env)});if(f instanceof P)return l({stdout:f.stdout,stderr:qe(f.stderr),exitCode:P.EXIT_CODE,internalOutputAccounting:f.internalOutputAccounting,env:je(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 Gt(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){ei(t,this.limits.maxSourceBytes);let n=Sa(t),r=lt(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=oi(s,o.metadata))}return{script:Ml(r),ast:r,metadata:s}}async analyzeCommands(t){ei(t,this.limits.maxSourceBytes);let n=lt(Sa(t),{maxHeredocSize:this.limits.maxHeredocSize}),{commands:r,definedFunctions:s,definedAliases:i}=Xa(n),o=[];for(let a of r)s.has(a)||i.has(a)||await this.resolvesCommandForAnalysis(a)||o.push(a);return{commands:r,unresolved:o}}async resolvesCommandForAnalysis(t){if((cr.has(t)||kt.has(t))&&!Ra.has(t)||this.state.functions.has(t))return!0;let n=await Hr({fs:this.fs,state:{...this.state,hashTable:new Map},commands:this.commands},t);return n!==null&&!("error"in n)}};function yy(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 Sa(e){let t=e.split(`
816
+ `),n=[],r=[],s="none";for(let i=0;i<t.length;i++){let o=t[i];if(r.length>0){let u=r[r.length-1];if((u.stripTabs?o.replace(/^\t+/,""):o)===u.delimiter){n.push(o.trimStart()),r.pop();continue}n.push(o);continue}let a=s,l=a==="none"?o.trimStart():o;if(n.push(l),s=yy(o,a),a!=="none")continue;let c=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let u of l.matchAll(c)){let f=u[1]==="-",d=u[3];r.push({delimiter:d,stripTabs:f})}}return n.join(`
817
+ `)}var gy=new TextDecoder("utf-8",{fatal:!0});function Jf(e){if(!e)return e;let t=!1;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);if(s>255)return e;s>127&&(t=!0)}if(!t)return e;let n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);try{return gy.decode(n)}catch{return e}}function wy(e,t,n,r,s,i){if(e===void 0)return;let o=t==="bytes"?e.length:M(e);if(o>n||o>r)throw new P(`stdin size limit exceeded (${Math.min(n,r)} bytes)`,"string_length");return i||s.consumeInput(o,"stdin"),t==="bytes"?e:wn(e)}import*as ye from"node:fs";import*as Ie from"node:path";import*as Ve from"node:fs";import*as $e from"node:path";function Or(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 Ir(e,t){try{let n=Ve.realpathSync(e);return Or(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=$e.dirname(e);if(r===e)return null;let s=Ir(r,t);if(s===null)return null;try{if(Ve.lstatSync(e).isSymbolicLink()){let o=Ve.readlinkSync(e),a=$e.isAbsolute(o)?o:$e.resolve($e.dirname(e),o),l=Ir(a,t);return l===null?null:l}}catch{}return $e.join(s,$e.basename(e))}return null}}function ed(e,t,n){let r=Ir(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(Ve.lstatSync(s).isSymbolicLink())return null}catch{}return r}function td(e,t){if(!Ve.existsSync(e))throw new Error(`${t} root does not exist`);if(!Ve.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function nd(e,t){if(!$e.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=Ve.realpathSync(e)}catch{n=$e.resolve(e)}return Or(n,t)?{withinRoot:!0,relativePath:ka(n.slice(t.length))||"/"}:{withinRoot:!1,safeName:$e.basename(e)}}function rd(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 N(i,`${n} '${t}'`)}async function xt(e){return sd(await Ve.promises.lstat(e))}function Aa(e){return sd(Ve.lstatSync(e))}function sd(e){return process.platform==="win32"&&e.isDirectory()&&(e.mode=e.mode&-512|493),e}function ni(e){let t=e.content.byteLength;for(let n of e.appendChunks??[])t+=n.byteLength;return t}function ad(e){return ni(e)}function si(e,t){if(!e.appendChunks||e.appendChunks.length===0)return e.content;let n=e.appendChunks.reduce((i,o)=>i+o.byteLength,e.content.byteLength);if(!Number.isSafeInteger(n))throw new N("EFBIG",`file too large, read '${t}'`);let r=new Uint8Array(n);r.set(e.content);let s=e.content.byteLength;for(let i of e.appendChunks)r.set(i,s),s+=i.byteLength;return e.content=r,e.appendChunks=void 0,r}function id(e){return!e||e.type!=="file"?0:ni(e)}function _r(){return{type:"directory",children:new Map,changedAt:Date.now(),mode:mt,mtime:new Date}}function Lr(e){return e.split("/").filter(Boolean)}var ri=class e{maxMemoryBytes;rootNode=_r();bytes=0;mutationSeq_=0;constructor(t){this.maxMemoryBytes=t}get root(){return this.rootNode}get retainedBytes(){return this.bytes}descend(t){let n=Lr(t),r=[this.rootNode],s=this.rootNode;for(let i=0;i<n.length;i++){let o=s.children.get(n[i]);if(o===void 0)return{kind:"missing",stack:r,missingAt:i};if(i===n.length-1)return{kind:"found",stack:r,node:o};if(o.type==="whiteout")return{kind:"blocked",stack:r,blockedAt:i};if(o.type!=="directory")return{kind:"notdir",stack:r,notdirAt:i};r.push(o),s=o}return{kind:"found",stack:[],node:this.rootNode}}ensureDirs(t,n){let r=this.rootNode,s="";for(let i of Lr(t)){s=`${s}/${i}`;let o=r.children.get(i);if(o===void 0)o=_r(),r.children.set(i,o);else if(o.type==="whiteout")o=this.resurrectDir(r,i,s,o.changedAt??0,n);else if(o.type!=="directory")throw new N("ENOTDIR",`not a directory, mkdir '${t}'`);r=o}return r}resurrectDir(t,n,r,s,i){let o=_r();t.children.set(n,o);let a=i?.(r);if(a)for(let l of a)o.children.has(l)||o.children.set(l,{type:"whiteout",changedAt:s});return o}attach(t,n){n.changedAt=Date.now();let r=Lr(t);if(r.length===0)throw new N("EINVAL",`cannot attach at root, attach '${t}'`);let s=this.parentDirOf(r,t),i=s.children.get(r[r.length-1]);if(i?.type==="directory"&&n.type!=="directory")throw new N("EISDIR",`cannot replace directory with ${n.type}, attach '${t}'`);if(i!==void 0&&n.type==="directory")throw new N("EEXIST",`cannot replace ${i.type} with directory, attach '${t}'`);let o=id(i),a=id(n);this.assertCapacity(a,o),s.children.set(r[r.length-1],n),this.bytes+=a-o}detach(t){let n=Lr(t);if(n.length===0)return;let r=this.descend(t);return r.kind!=="found"?void 0:(r.stack[r.stack.length-1].children.delete(n[n.length-1]),this.bytes-=e.subtreeBytes(r.node),r.node)}putWhiteout(t){let n=Lr(t);if(n.length===0)throw new N("EINVAL",`cannot whiteout the root, rm '${t}'`);let r=this.rootNode;for(let o=0;o<n.length-1;o++)r=this.ensureChildDir(r,n[o],t);let s=n[n.length-1],i=r.children.get(s);i?.type!=="whiteout"&&(this.bytes-=e.subtreeBytes(i),r.children.set(s,{type:"whiteout",changedAt:Date.now()}))}appendChunk(t,n){this.assertCapacity(n.byteLength),t.appendChunks||(t.appendChunks=[]),t.appendChunks.push(n),this.bytes+=n.byteLength,this.touch(t)}touch(t){t.seq=++this.mutationSeq_,t.changedAt=Date.now()}detachIfUnchanged(t,n,r){let s=this.descend(t);return s.kind!=="found"||s.node!==n||n.seq!==r||n.type==="directory"&&n.children.size>0?!1:(this.detach(t),!0)}*preOrder(){let t=[{path:"/",node:this.rootNode}];for(;t.length>0;){let n=t.pop();if(yield n,n.node.type==="directory"){let r=[...n.node.children.entries()];for(let s=r.length-1;s>=0;s--){let[i,o]=r[s];t.push({path:od(n.path,i),node:o})}}}}*postOrder(){let t=[],n=[{path:"/",node:this.rootNode}];for(;n.length>0;){let r=n.pop();if(t.push(r),r.node.type==="directory")for(let[s,i]of r.node.children)n.push({path:od(r.path,s),node:i})}for(let r=t.length-1;r>=0;r--)yield t[r]}clear(){this.rootNode=_r(),this.bytes=0}static subtreeBytes(t){if(t===void 0)return 0;if(t.type==="file")return ni(t);if(t.type!=="directory")return 0;let n=0,r=[t];for(;r.length>0;){let s=r.pop();for(let i of s.children.values())i.type==="file"?n+=ni(i):i.type==="directory"&&r.push(i)}return n}parentDirOf(t,n){let r=this.rootNode;for(let s=0;s<t.length-1;s++){let i=r.children.get(t[s]);if(i?.type!=="directory")throw new N("ENOTDIR",`not a directory, attach '${n}'`);r=i}return r}ensureChildDir(t,n,r){let s=t.children.get(n);if(s===void 0||s.type==="whiteout")s=_r(),t.children.set(n,s);else if(s.type!=="directory")throw new N("ENOTDIR",`not a directory, rm '${r}'`);return s}assertCapacity(t,n=0){if(!Number.isSafeInteger(t)||t<0||t>this.maxMemoryBytes-this.bytes+n)throw new N("ENOSPC",`overlay memory byte limit exceeded (${this.maxMemoryBytes} bytes)`)}};function od(e,t){return e==="/"?`/${t}`:`${e}/${t}`}var Ey=["ELOOP","EFBIG","EPERM"],by="/home/user/project",tr=class{root;canonicalRoot;mountPoint;readOnly;maxFileReadSize;maxMemoryBytes;allowSymlinks;tree;nextMemoryIdentity=1;get rootDir(){return this.root}restamp(t,n,r="full"){let s=z(t),i=c=>{let u=this.tree.descend(c);u.kind==="found"&&(u.node.changedAt=n)},o=c=>{let u=this.tree.descend(c);if(u.kind==="found"){let f=u.node;(f.changedAt??0)>n&&(f.changedAt=n,f.mtime=new Date(n))}};r==="full"&&i(s);let a=s;for(;;){let c=a.lastIndexOf("/");if(c<=0)break;a=a.slice(0,c),o(a)}if(r==="ancestors")return;let l=[s];for(;l.length>0;){let c=l.pop(),u=this.tree.descend(c);if(!(u.kind!=="found"||u.node.type!=="directory"))for(let f of u.node.children.keys()){let d=`${c==="/"?"":c}/${f}`;o(d),l.push(d)}}}identityFor(t){return t.type==="symlink"?"":(t.identity||(t.identity=`overlay:${this.nextMemoryIdentity++}`),t.identity)}constructor(t){this.root=Ie.resolve(t.root);let n=t.mountPoint??by;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,td(this.root,"OverlayFs"),this.canonicalRoot=ye.realpathSync(this.root),this.tree=new ri(this.maxMemoryBytes),this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new N("EROFS",`read-only file system, ${t}`)}createMountPointDirs(){this.tree.ensureDirs(this.mountPoint)}getMountPoint(){return this.mountPoint}diff(){let t=[],n=[],r=[];for(let{path:i,node:o}of this.tree.preOrder()){let a=this.getRelativeToMount(i);if(!(a===null||a==="/")){if(o.type==="whiteout"){this.existsOnRealFs(i)&&(n.push(a),r.push(o.changedAt??0));continue}if(o.type==="file")if(o.metacopy){if(!this.existsOnRealFs(i))continue;t.push({path:a,nodeType:"file",content:new Uint8Array(0),mode:o.mode,mtime:o.mtime,changedAt:o.changedAt??0,metadataOnly:!0})}else t.push({path:a,nodeType:"file",content:si(o,i),mode:o.mode,mtime:o.mtime,changedAt:o.changedAt??0});else o.type==="directory"?t.push({path:a,nodeType:"directory",content:new Uint8Array(0),mode:o.mode,mtime:o.mtime,changedAt:o.changedAt??0}):t.push({path:a,nodeType:"symlink",content:new TextEncoder().encode(o.target),mode:o.mode,mtime:o.mtime,changedAt:o.changedAt??0})}}t.sort((i,o)=>i.path<o.path?-1:i.path>o.path?1:0);let s=n.map((i,o)=>({path:i,changedAt:r[o]}));return s.sort((i,o)=>i.path<o.path?-1:i.path>o.path?1:0),{writes:t,deletions:s.map(i=>i.path),...s.length>0&&{deletionChangedAt:s.map(i=>i.changedAt)}}}async sync(){for(let{path:t,node:n}of this.tree.postOrder()){let r=this.getRelativeToMount(t);if(r===null||r==="/")continue;if(n.type==="whiteout"){this.existsOnRealFs(t)||this.tree.detach(t);continue}if(n.type==="directory"&&n.children.size>0)continue;let s=n.seq;await this.nodeMatchesDisk(t,n)&&this.tree.detachIfUnchanged(t,n,s)}}reset(){this.tree.clear(),this.createMountPointDirs()}drop(t){let n=t.map(r=>{let s=z(r);if(s==="/")throw new N("EINVAL",`invalid argument, drop '${r}'`);return this.mountPoint==="/"?s:`${this.mountPoint}${s}`});n.sort((r,s)=>s.length-r.length);for(let r of n){let s=this.tree.descend(r);if(s.kind!=="found")continue;let i=s.node;i.type==="directory"&&i.children.size>0||this.tree.detach(r)}}async lstatLower(t){let n=this.resolveRealPathParent_(this.toRealPath(t));if(!n)return null;try{return{canonical:n,stat:await xt(n)}}catch{return null}}async nodeMatchesDisk(t,n){if(n.type==="directory")return(await this.lstatLower(t))?.stat.isDirectory()??!1;if(n.type==="symlink"){if(!this.allowSymlinks)return!1;let s=await this.lstatLower(t);if(!s?.stat.isSymbolicLink())return!1;try{let i=await ye.promises.readlink(s.canonical);return this.realTargetToVirtual(i)===n.target}catch{return!1}}if(n.metacopy){let s=await this.lstatLower(t);if(!s?.stat.isFile())return!1;let{stat:i}=s;return!(i.mtime.getTime()!==n.mtime.getTime()||process.platform!=="win32"&&(i.mode&4095)!==(n.mode&4095))}let r=this.resolveRealPath_(this.toRealPath(t));if(!r)return!1;try{let s=await xt(r);if(!s.isFile())return!1;let i=si(n,t);if(s.size!==i.byteLength)return!1;let o=this.allowSymlinks?ye.constants.O_RDONLY:ye.constants.O_RDONLY|ye.constants.O_NOFOLLOW,a=await ye.promises.open(r,o),l;try{l=new Uint8Array(await a.readFile())}finally{await a.close()}for(let c=0;c<l.byteLength;c++)if(l[c]!==i[c])return!1;return!0}catch{return!1}}mkdirSync(t,n){this.tree.ensureDirs(z(t),r=>this.lowerChildren(r))}writeFileSync(t,n){let r=z(t);this.ensureParentDirs(r);let s=n instanceof Uint8Array?n:new TextEncoder().encode(n);this.tree.attach(r,{type:"file",content:s,mode:Ht,mtime:new Date})}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=Ie.join(this.root,r),i=Ie.resolve(s);return Or(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?Ir(t,this.canonicalRoot):ed(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=Ie.dirname(t),r=this.resolveRealPath_(n);return r===null?null:Ie.join(r,Ie.basename(t))}sanitizeError(t,n,r){rd(t,n,r,Ey)}ensureParentDirs(t){let n=yt(t);n!=="/"&&this.tree.ensureDirs(n,r=>this.lowerChildren(r))}lowerChildren(t){let n=this.resolveRealPath_(this.toRealPath(t));if(!n)return null;try{return ye.readdirSync(n)}catch{return null}}async existsInOverlay(t){let n=z(t),r=this.tree.descend(n);if(r.kind==="found")return r.node.type!=="whiteout";if(r.kind==="blocked"||r.kind==="notdir")return!1;let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)return!1;try{return await xt(s),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=Qt(n);return Tn(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Tn(n,"binary")}async readFileBuffer(t,n=new Set){K(t,"open");let r=z(t);if(n.has(r))throw new N("ELOOP",`too many levels of symbolic links, open '${t}'`);n.add(r);let s=this.tree.descend(r);if(s.kind==="blocked")throw new N("ENOENT",`no such file or directory, open '${t}'`);if(s.kind==="notdir")throw new N("ENOTDIR",`not a directory, open '${t}'`);if(s.kind==="found"){let i=s.node;if(i.type==="whiteout")throw new N("ENOENT",`no such file or directory, open '${t}'`);if(i.type==="symlink"){let a=this.resolveSymlink(r,i.target);return this.readFileBuffer(a,n)}if(i.type!=="file")throw new N("EISDIR",`illegal operation on a directory, read '${t}'`);if(!i.metacopy)return si(i,t);let o=await this.readLowerFileBytes(r,t,n);if(process.platform==="win32")try{this.tree.attach(r,{type:"file",content:o,mode:i.mode,mtime:i.mtime})}catch(a){if(!it(a,"ENOSPC"))throw a}return o}return this.readLowerFileBytes(r,t,n)}async readLowerFileBytes(t,n,r){let s=this.resolveRealPath_(this.toRealPath(t));if(!s)throw new N("ENOENT",`no such file or directory, open '${n}'`);try{let i=await xt(s);if(i.isSymbolicLink()){if(!this.allowSymlinks)throw new N("ENOENT",`no such file or directory, open '${n}'`);let l=await ye.promises.readlink(s),c=this.realTargetToVirtual(l),u=this.resolveSymlink(t,c);return this.readFileBuffer(u,r)}if(i.isDirectory())throw new N("EISDIR",`illegal operation on a directory, read '${n}'`);if(this.maxFileReadSize>0&&i.size>this.maxFileReadSize)throw new N("EFBIG",`file too large, read '${n}' (${i.size} bytes, max ${this.maxFileReadSize})`);let o=this.allowSymlinks?ye.constants.O_RDONLY:ye.constants.O_RDONLY|ye.constants.O_NOFOLLOW,a=await ye.promises.open(s,o);try{let l=await a.readFile();return new Uint8Array(l)}finally{await a.close()}}catch(i){let o=i.code;if(o==="ENOENT")throw new N("ENOENT",`no such file or directory, open '${n}'`);if(o==="ELOOP")throw new N("ENOENT",`no such file or directory, open '${n}'`);this.sanitizeError(i,n,"open")}}async writeFile(t,n,r){K(t,"write"),this.assertWritable(`write '${t}'`);let s=z(t);this.ensureParentDirs(s);let i=Qt(r),o=Ln(n,i);this.tree.attach(s,{type:"file",content:o,mode:await this.inheritedMode(s),mtime:new Date})}async inheritedMode(t){let n=this.entryAt(t);if(n?.type==="file")return n.mode;if(n?.type==="directory")return Ht;if(process.platform==="win32")return Ht;try{let r=await this.stat(t);if(r.isFile)return r.mode}catch{}return Ht}async appendFile(t,n,r){K(t,"append"),this.assertWritable(`append '${t}'`);let s=z(t),i=Qt(r),o=Ln(n,i),a=this.tree.descend(s);if(a.kind==="found"&&a.node.type==="file"){await this.appendToExisting_(s,a.node,o,t);return}if(a.kind==="blocked")throw new N("ENOENT",`no such file or directory, append '${t}'`);if(a.kind==="notdir")throw new N("ENOTDIR",`not a directory, append '${t}'`);let l;try{l=await this.readFileBuffer(s)}catch(f){if(!it(f,"ENOENT"))throw f;l=new Uint8Array(0)}let c=await this.inheritedMode(s),u=this.tree.descend(s);if(u.kind==="found"&&u.node.type==="file"){await this.appendToExisting_(s,u.node,o,t);return}this.ensureParentDirs(s),this.tree.attach(s,{type:"file",content:l,appendChunks:[o],mode:c,mtime:new Date})}async appendToExisting_(t,n,r,s){if(n.metacopy){let i=await this.readLowerFileBytes(t,s,new Set),o=this.tree.descend(t);if(o.kind==="found"&&o.node.type==="file"&&!o.node.metacopy){this.tree.appendChunk(o.node,r),o.node.mtime=new Date;return}this.tree.attach(t,{type:"file",content:i,appendChunks:[r],mode:n.mode,mtime:new Date});return}this.tree.appendChunk(n,r),n.mtime=new Date}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,n=new Set){K(t,"stat");let r=z(t);if(n.has(r))throw new N("ELOOP",`too many levels of symbolic links, stat '${t}'`);n.add(r);let s=this.tree.descend(r);if(s.kind==="blocked")throw new N("ENOENT",`no such file or directory, stat '${t}'`);if(s.kind==="notdir")throw new N("ENOTDIR",`not a directory, stat '${t}'`);if(s.kind==="found"){let o=s.node;if(o.type==="whiteout")throw new N("ENOENT",`no such file or directory, stat '${t}'`);if(o.type==="symlink"){let a=this.resolveSymlink(r,o.target);return this.stat(a,n)}return this.memoryEntryStat(o)}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new N("ENOENT",`no such file or directory, stat '${t}'`);try{let o=await xt(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new N("ENOENT",`no such file or directory, stat '${t}'`);let a=await ye.promises.readlink(i),l=this.realTargetToVirtual(a),c=this.resolveSymlink(r,l);return this.stat(c,n)}return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:!1,mode:o.mode,size:o.size,mtime:o.mtime,dev:o.dev,ino:o.ino}}catch(o){if(o.code==="ENOENT")throw new N("ENOENT",`no such file or directory, stat '${t}'`);this.sanitizeError(o,t,"stat")}}async lstat(t){K(t,"lstat");let n=z(t),r=this.tree.descend(n);if(r.kind==="blocked")throw new N("ENOENT",`no such file or directory, lstat '${t}'`);if(r.kind==="notdir")throw new N("ENOTDIR",`not a directory, lstat '${t}'`);if(r.kind==="found"){let i=r.node;if(i.type==="whiteout")throw new N("ENOENT",`no such file or directory, lstat '${t}'`);return this.memoryEntryStat(i)}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new N("ENOENT",`no such file or directory, lstat '${t}'`);try{let i=await xt(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 N("ENOENT",`no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}memoryEntryStat(t){if(t.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:t.mode,size:t.target.length,mtime:t.mtime};let n=0;return t.type==="file"&&(n=t.metacopy?t.lowerSize??0:ad(t)),{isFile:t.type==="file",isDirectory:t.type==="directory",isSymbolicLink:!1,mode:t.mode,size:n,mtime:t.mtime,identity:this.identityFor(t)}}resolveSymlink(t,n){return _n(t,n)}realTargetToVirtual(t){let n=nd(t,this.canonicalRoot);if(n.withinRoot){if(!Ie.isAbsolute(t))return t;let r=n.relativePath;return this.mountPoint==="/"?r:`${this.mountPoint}${r}`}return n.safeName}async mkdir(t,n){K(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=z(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new N("EEXIST",`file already exists, mkdir '${t}'`);return}let i=yt(r);if(i!=="/"&&!await this.existsInOverlay(i))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new N("ENOENT",`no such file or directory, mkdir '${t}'`);this.tree.ensureDirs(r,o=>this.lowerChildren(o))}async createExclusive(t,n){let r=n.directory?"mkdir":"open";K(t,r),this.assertWritable(`${r} '${t}'`);let s=z(t);if(await this.existsInOverlay(s))throw new N("EEXIST",`file already exists, ${r} '${t}'`);let i=yt(s),o=s;if(i!=="/"){let l;try{l=await this.realpath(i)}catch{throw new N("ENOENT",`no such file or directory, ${r} '${t}'`)}let c=await this.stat(l).catch(()=>null);if(!c)throw new N("ENOENT",`no such file or directory, ${r} '${t}'`);if(!c.isDirectory)throw new N("ENOTDIR",`not a directory, ${r} '${t}'`);if(o=ot(l,s.slice(s.lastIndexOf("/")+1)),o!==s&&await this.existsInOverlay(o))throw new N("EEXIST",`file already exists, ${r} '${t}'`)}if(n.directory){let l=this.tree.descend(o);if(l.kind==="found"&&l.node.type!=="whiteout")throw new N("EEXIST",`file already exists, ${r} '${t}'`);let c=this.tree.ensureDirs(o,u=>this.lowerChildren(u));c.mode=n.mode;return}this.ensureParentDirs(o);let a=this.tree.descend(o);if(a.kind==="found"&&a.node.type!=="whiteout")throw new N("EEXIST",`file already exists, ${r} '${t}'`);this.tree.attach(o,{type:"file",content:new Uint8Array(0),mode:n.mode,mtime:new Date})}async readdirCore(t,n){let r=new Map,s=new Set,i=this.tree.descend(n);if(i.kind==="blocked")throw new N("ENOENT",`no such file or directory, scandir '${t}'`);if(i.kind==="notdir")throw new N("ENOTDIR",`not a directory, scandir '${t}'`);let o;if(i.kind==="found"){let l=i.node;if(l.type==="whiteout")throw new N("ENOENT",`no such file or directory, scandir '${t}'`);if(l.type!=="directory")throw new N("ENOTDIR",`not a directory, scandir '${t}'`);o=l;for(let[c,u]of l.children){if(u.type==="whiteout"){s.add(c);continue}r.set(c,{name:c,isFile:u.type==="file",isDirectory:u.type==="directory",isSymbolicLink:u.type==="symlink"})}}let a=this.resolveRealPath_(this.toRealPath(n));if(a)try{if(!this.allowSymlinks&&(await xt(a)).isSymbolicLink()){if(!o)throw new N("ENOENT",`no such file or directory, scandir '${t}'`);return r}let l=await ye.promises.readdir(a,{withFileTypes:!0});for(let c of l)!s.has(c.name)&&!r.has(c.name)&&r.set(c.name,{name:c.name,isFile:c.isFile(),isDirectory:c.isDirectory(),isSymbolicLink:c.isSymbolicLink()})}catch(l){if(l.code==="ENOENT"){if(!o)throw new N("ENOENT",`no such file or directory, scandir '${t}'`)}else l.code!=="ENOTDIR"&&this.sanitizeError(l,t,"scandir")}return r}async resolveForReaddir(t,n=!1){let r=z(t),s=new Set,i=n;for(;;){let l=this.tree.descend(r);if(l.kind!=="found")break;let c=l.node;if(c.type!=="symlink")return{normalized:r,outsideOverlay:!1};if(s.has(r))throw new N("ELOOP",`too many levels of symbolic links, scandir '${t}'`);s.add(r),i=!0,r=this.resolveSymlink(r,c.target)}if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let a=this.resolveRealPath_(this.toRealPath(r));if(!a)return{normalized:r,outsideOverlay:!0};try{if((await xt(a)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let c=await ye.promises.readlink(a),u=this.realTargetToVirtual(c),f=this.resolveSymlink(r,u);return this.resolveForReaddir(f,!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,o)=>i<o?-1:i>o?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,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async rm(t,n){K(t,"rm"),this.assertWritable(`rm '${t}'`);let r=z(t);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new N("ENOENT",`no such file or directory, rm '${t}'`)}let i=!1;try{(await this.stat(r)).isDirectory&&(i=(await this.readdir(r)).length>0)}catch{}if(i&&!n?.recursive)throw new N("ENOTEMPTY",`directory not empty, rm '${t}'`);this.existsOnRealFs(r)?this.tree.putWhiteout(r):this.tree.detach(r)}existsOnRealFs(t){let n=this.toRealPath(t),r=this.resolveRealPathParent_(n);if(!r)return!1;try{return Aa(r),!0}catch{return!1}}async cp(t,n,r){K(t,"cp"),K(n,"cp"),this.assertWritable(`cp '${n}'`);let s=z(t),i=z(n);if(!await this.existsInOverlay(s))throw new N("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 N("EISDIR",`is a directory, cp '${t}'`);if(Mt(s,i))throw new N("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 On(t,n)}getAllPaths(){let t=new Set;for(let{path:n,node:r}of this.tree.preOrder())r.type!=="whiteout"&&t.add(n);return this.scanRealFs(this.mountPoint,t),Array.from(t)}scanRealFs(t,n){if(this.lowerHidden(t))return;let r=this.resolveRealPath_(this.toRealPath(t));if(r)try{let s=ye.readdirSync(r);for(let i of s){let o=t==="/"?`/${i}`:`${t}/${i}`;if(this.lowerHidden(o))continue;n.add(o);let a=Ie.join(r,i);Aa(a).isDirectory()&&this.scanRealFs(o,n)}}catch{}}lowerHidden(t){let n=this.tree.descend(t);switch(n.kind){case"blocked":case"notdir":return!0;case"found":return n.node.type!=="directory";default:return!1}}entryAt(t){let n=this.tree.descend(t);if(n.kind==="found"&&n.node.type!=="whiteout")return n.node}async chmod(t,n){K(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=z(t);if(!await this.existsInOverlay(r))throw new N("ENOENT",`no such file or directory, chmod '${t}'`);let i=this.entryAt(r);if(i){i.mode=n,this.tree.touch(i);return}let o=await this.stat(r);this.attachMetacopyShadow(r,o,n,o.isFile?o.mtime:new Date)}attachMetacopyShadow(t,n,r,s){this.ensureParentDirs(t),n.isFile?this.tree.attach(t,{type:"file",content:new Uint8Array(0),metacopy:!0,lowerSize:n.size,mode:r,mtime:s}):n.isDirectory&&this.tree.attach(t,{type:"directory",children:new Map,mode:r,mtime:s})}async symlink(t,n){if(!this.allowSymlinks)throw new N("EPERM",`operation not permitted, symlink '${n}'`);K(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=z(n);if(await this.existsInOverlay(r))throw new N("EEXIST",`file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.tree.attach(r,{type:"symlink",target:t,mode:zr,mtime:new Date})}async link(t,n){K(t,"link"),K(n,"link"),this.assertWritable(`link '${n}'`);let r=z(t),s=z(n);if(!await this.existsInOverlay(r))throw new N("ENOENT",`no such file or directory, link '${t}'`);let o=await this.stat(r);if(!o.isFile)throw new N("EPERM",`operation not permitted, link '${t}'`);if(await this.existsInOverlay(s))throw new N("EEXIST",`file already exists, link '${n}'`);let l=await this.readFileBuffer(r);this.ensureParentDirs(s),this.tree.attach(s,{type:"file",content:l,mode:o.mode,mtime:new Date,identity:o.identity??`overlay:${this.nextMemoryIdentity++}`})}async readlink(t){K(t,"readlink");let n=z(t),r=this.tree.descend(n);if(r.kind==="blocked")throw new N("ENOENT",`no such file or directory, readlink '${t}'`);if(r.kind==="notdir")throw new N("ENOTDIR",`not a directory, readlink '${t}'`);if(r.kind==="found"){let i=r.node;if(i.type==="whiteout")throw new N("ENOENT",`no such file or directory, readlink '${t}'`);if(i.type!=="symlink")throw new N("EINVAL",`invalid argument, readlink '${t}'`);return i.target}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new N("ENOENT",`no such file or directory, readlink '${t}'`);try{let i=await ye.promises.readlink(s);if(!Ie.isAbsolute(i)){let o=Ie.resolve(Ie.dirname(s),i),a;try{a=ye.realpathSync(o)}catch{a=o}if(!Or(a,this.canonicalRoot))return Ie.basename(i)}return this.realTargetToVirtual(i)}catch(i){if(i.code==="ENOENT")throw new N("ENOENT",`no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new N("EINVAL",`invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){K(t,"realpath");let n=z(t),r=new Set,s=l=>{let c=this.tree.descend(l);if(c.kind==="blocked"||c.kind==="found"&&c.node.type==="whiteout")throw new N("ENOENT",`no such file or directory, realpath '${t}'`);return c.kind==="found"?c.node:void 0},i=async l=>{let c=l==="/"?[]:l.slice(1).split("/"),u="";for(let f of c){if(u=`${u}/${f}`,r.has(u))throw new N("ELOOP",`too many levels of symbolic links, realpath '${t}'`);let d=s(u),p=0,h=ir;for(;d&&d.type==="symlink"&&p<h;){if(r.add(u),u=this.resolveSymlink(u,d.target),p++,r.has(u))throw new N("ELOOP",`too many levels of symbolic links, realpath '${t}'`);d=s(u)}if(p>=h)throw new N("ELOOP",`too many levels of symbolic links, realpath '${t}'`);if(!d){let y=this.toRealPath(u),E=this.resolveRealPath_(y);if(E)try{if((await xt(E)).isSymbolicLink()){if(!this.allowSymlinks)throw new N("ENOENT",`no such file or directory, realpath '${t}'`);let m=await ye.promises.readlink(E),g=this.realTargetToVirtual(m);return r.add(u),u=this.resolveSymlink(u,g),i(u)}}catch(S){if(S.code==="ENOENT")throw new N("ENOENT",`no such file or directory, realpath '${t}'`);this.sanitizeError(S,t,"realpath")}else if(!this.allowSymlinks){let S=this.resolveRealPathParent_(y);if(S)try{if((await xt(S)).isSymbolicLink())throw new N("ENOENT",`no such file or directory, realpath '${t}'`)}catch(m){if(it(m,"ENOENT")||it(m,"ELOOP"))throw new N("ENOENT",`no such file or directory, realpath '${t}'`);this.sanitizeError(m,t,"realpath")}}}}return u||"/"},o=await i(n);if(!await this.existsInOverlay(o))throw new N("ENOENT",`no such file or directory, realpath '${t}'`);return o}async utimes(t,n,r){K(t,"utimes"),this.assertWritable(`utimes '${t}'`);let s=z(t);if(!await this.existsInOverlay(s))throw new N("ENOENT",`no such file or directory, utimes '${t}'`);let o=this.entryAt(s);if(o){o.mtime=r,this.tree.touch(o);return}let a=await this.stat(s);this.attachMetacopyShadow(s,a,a.mode,r)}};function cd(){console.log(`just-bash - A secure bash environment for AI agents
813
818
 
814
819
  Usage:
815
820
  just-bash [options] [script-file] [root]
@@ -860,5 +865,5 @@ Examples:
860
865
 
861
866
  # Allow write operations (writes stay in memory)
862
867
  just-bash -c 'echo test > /tmp/file.txt && cat /tmp/file.txt' --allow-write
863
- `)}function py(){console.log("just-bash 1.0.0")}function hy(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=td(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=td(r[1]);s&&o!==t.root&&i("conflicting positional root and --root"),t.root=o}return t}function my(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 yy(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString("utf-8")}async function gy(){let e=process.argv.slice(2),t=hy(e);t.help&&(nd(),process.exit(0)),t.version&&(py(),process.exit(0));let n;if(t.script)n=t.script;else if(t.scriptFile){let a=new Yn({root:t.root}),l=a.getMountPoint();try{let c=t.scriptFile.startsWith("/")?t.scriptFile:`${l}/${t.scriptFile}`;n=await a.readFile(c,"utf-8")}catch(c){console.error(`Error: Cannot read script file: ${t.scriptFile}`),console.error(qe(c instanceof Error?c.message:String(c))),process.exit(1)}}else process.stdin.isTTY?(nd(),process.exit(1)):n=await yy();n.trim()||(t.json&&console.log(JSON.stringify({stdout:"",stderr:"",exitCode:0})),process.exit(0));let r=new Yn({root:t.root,readOnly:!t.allowWrite}),s=r.getMountPoint(),i=t.cwdOverridden?my(t.cwd):s,o=new Xs({fs:r,cwd:i,python:t.python,javascript:t.javascript});t.errexit&&(n=`set -e
864
- ${n}`);try{let a=await o.exec(n);t.json?console.log(JSON.stringify({stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode})):(a.stdout&&process.stdout.write(a.stdout),a.stderr&&process.stderr.write(a.stderr)),process.exit(a.exitCode)}catch(a){let l=qe(a instanceof Error?a.message:String(a));t.json?console.log(JSON.stringify({stdout:"",stderr:l,exitCode:1})):console.error(l),process.exit(1)}}gy().catch(e=>{console.error("Fatal error:",qe(e instanceof Error?e.message:String(e))),process.exit(1)});
868
+ `)}function Sy(){console.log("just-bash 1.0.0")}function Ay(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=ld(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=ld(r[1]);s&&o!==t.root&&i("conflicting positional root and --root"),t.root=o}return t}function vy(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 xy(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString("utf-8")}async function ky(){let e=process.argv.slice(2),t=Ay(e);t.help&&(cd(),process.exit(0)),t.version&&(Sy(),process.exit(0));let n;if(t.script)n=t.script;else if(t.scriptFile){let a=new tr({root:t.root}),l=a.getMountPoint();try{let c=t.scriptFile.startsWith("/")?t.scriptFile:`${l}/${t.scriptFile}`;n=await a.readFile(c,"utf-8")}catch(c){console.error(`Error: Cannot read script file: ${t.scriptFile}`),console.error(qe(c instanceof Error?c.message:String(c))),process.exit(1)}}else process.stdin.isTTY?(cd(),process.exit(1)):n=await xy();n.trim()||(t.json&&console.log(JSON.stringify({stdout:"",stderr:"",exitCode:0})),process.exit(0));let r=new tr({root:t.root,readOnly:!t.allowWrite}),s=r.getMountPoint(),i=t.cwdOverridden?vy(t.cwd):s,o=new ti({fs:r,cwd:i,python:t.python,javascript:t.javascript});t.errexit&&(n=`set -e
869
+ ${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=qe(a instanceof Error?a.message:String(a));t.json?console.log(JSON.stringify({stdout:"",stderr:l,exitCode:1})):console.error(l),process.exit(1)}}ky().catch(e=>{console.error("Fatal error:",qe(e instanceof Error?e.message:String(e))),process.exit(1)});