just-bash 2.5.5 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/README.md +2 -2
  2. package/dist/AGENTS.md +2 -2
  3. package/dist/ast/types.d.ts +100 -11
  4. package/dist/bin/chunks/alias-EGIS5LUE.js +7 -0
  5. package/dist/bin/chunks/awk2-GFEJOWML.js +21 -0
  6. package/dist/bin/chunks/bash-PGDTHIM2.js +6 -0
  7. package/dist/bin/chunks/chmod-TYLTHXFR.js +9 -0
  8. package/dist/bin/chunks/chunk-D5WP4CKS.js +3 -0
  9. package/dist/bin/chunks/chunk-FSAGDARS.js +74 -0
  10. package/dist/bin/chunks/chunk-FSZWFMB4.js +16 -0
  11. package/dist/bin/chunks/chunk-IRUD2E3M.js +17 -0
  12. package/dist/bin/chunks/chunk-K5IXNHO5.js +8 -0
  13. package/dist/bin/chunks/chunk-KD3EODLB.js +6 -0
  14. package/dist/bin/{shell/chunks/echo-WSKTON6U.js → chunks/echo-7I42V66Q.js} +2 -2
  15. package/dist/bin/chunks/env-7A4MH7BJ.js +9 -0
  16. package/dist/bin/chunks/expansion-BOR3ELLC.js +2 -0
  17. package/dist/bin/{shell/chunks/find-CBEJ35BR.js → chunks/find-PHDZK64M.js} +1 -1
  18. package/dist/bin/{shell/chunks/grep-IIVQXFNI.js → chunks/grep-VX7MJMVN.js} +2 -2
  19. package/dist/bin/chunks/{head-DYK37Z24.js → head-TJHLLIMR.js} +1 -1
  20. package/dist/bin/{shell/chunks/jq-XXZPU5CA.js → chunks/jq-RGZHJNXC.js} +1 -1
  21. package/dist/bin/chunks/od-KRKGC2U3.js +5 -0
  22. package/dist/bin/chunks/printf-YPXD4CRE.js +15 -0
  23. package/dist/bin/chunks/pwd-L26WH2K4.js +3 -0
  24. package/dist/bin/{shell/chunks/rg-Q4OTJOEF.js → chunks/rg-RSDLLECO.js} +1 -1
  25. package/dist/bin/chunks/rmdir-GOODLY5W.js +14 -0
  26. package/dist/bin/chunks/sed-JPDTWF4W.js +100 -0
  27. package/dist/bin/{shell/chunks/tail-BES27CZT.js → chunks/tail-YAUIERGN.js} +1 -1
  28. package/dist/bin/{shell/chunks/tar-C27YYUAS.js → chunks/tar-LFENC54A.js} +7 -7
  29. package/dist/bin/chunks/time-37F5EBPK.js +14 -0
  30. package/dist/bin/chunks/touch-IBPHJBM3.js +7 -0
  31. package/dist/bin/chunks/wc-SAOHEZYP.js +6 -0
  32. package/dist/bin/chunks/{which-73KOOLC6.js → which-FCDFBOMN.js} +1 -1
  33. package/dist/bin/chunks/whoami-JVLUNKSG.js +3 -0
  34. package/dist/bin/{shell/chunks/xan-6K2NGTHM.js → chunks/xan-5HNHTFMB.js} +19 -19
  35. package/dist/bin/chunks/{yq-MF2SNFGL.js → yq-PFV4T2PV.js} +1 -1
  36. package/dist/bin/just-bash.js +659 -135
  37. package/dist/bin/shell/chunks/alias-EGIS5LUE.js +7 -0
  38. package/dist/bin/shell/chunks/awk2-GFEJOWML.js +21 -0
  39. package/dist/bin/shell/chunks/bash-PGDTHIM2.js +6 -0
  40. package/dist/bin/shell/chunks/chmod-TYLTHXFR.js +9 -0
  41. package/dist/bin/shell/chunks/chunk-D5WP4CKS.js +3 -0
  42. package/dist/bin/shell/chunks/chunk-FSAGDARS.js +74 -0
  43. package/dist/bin/shell/chunks/chunk-FSZWFMB4.js +16 -0
  44. package/dist/bin/shell/chunks/chunk-IRUD2E3M.js +17 -0
  45. package/dist/bin/shell/chunks/chunk-K5IXNHO5.js +8 -0
  46. package/dist/bin/shell/chunks/chunk-KD3EODLB.js +6 -0
  47. package/dist/bin/{chunks/echo-WSKTON6U.js → shell/chunks/echo-7I42V66Q.js} +2 -2
  48. package/dist/bin/shell/chunks/env-7A4MH7BJ.js +9 -0
  49. package/dist/bin/shell/chunks/expansion-BOR3ELLC.js +2 -0
  50. package/dist/bin/{chunks/find-CBEJ35BR.js → shell/chunks/find-PHDZK64M.js} +1 -1
  51. package/dist/bin/{chunks/grep-IIVQXFNI.js → shell/chunks/grep-VX7MJMVN.js} +2 -2
  52. package/dist/bin/shell/chunks/{head-DYK37Z24.js → head-TJHLLIMR.js} +1 -1
  53. package/dist/bin/{chunks/jq-XXZPU5CA.js → shell/chunks/jq-RGZHJNXC.js} +1 -1
  54. package/dist/bin/shell/chunks/od-KRKGC2U3.js +5 -0
  55. package/dist/bin/shell/chunks/printf-YPXD4CRE.js +15 -0
  56. package/dist/bin/shell/chunks/pwd-L26WH2K4.js +3 -0
  57. package/dist/bin/{chunks/rg-Q4OTJOEF.js → shell/chunks/rg-RSDLLECO.js} +1 -1
  58. package/dist/bin/shell/chunks/rmdir-GOODLY5W.js +14 -0
  59. package/dist/bin/shell/chunks/sed-JPDTWF4W.js +100 -0
  60. package/dist/bin/{chunks/tail-BES27CZT.js → shell/chunks/tail-YAUIERGN.js} +1 -1
  61. package/dist/bin/{chunks/tar-C27YYUAS.js → shell/chunks/tar-LFENC54A.js} +7 -7
  62. package/dist/bin/shell/chunks/time-37F5EBPK.js +14 -0
  63. package/dist/bin/shell/chunks/touch-IBPHJBM3.js +7 -0
  64. package/dist/bin/shell/chunks/wc-SAOHEZYP.js +6 -0
  65. package/dist/bin/shell/chunks/{which-73KOOLC6.js → which-FCDFBOMN.js} +1 -1
  66. package/dist/bin/shell/chunks/whoami-JVLUNKSG.js +3 -0
  67. package/dist/bin/{chunks/xan-6K2NGTHM.js → shell/chunks/xan-5HNHTFMB.js} +19 -19
  68. package/dist/bin/shell/chunks/{yq-MF2SNFGL.js → yq-PFV4T2PV.js} +1 -1
  69. package/dist/bin/shell/shell.js +664 -140
  70. package/dist/bundle/browser.js +1251 -606
  71. package/dist/bundle/chunks/alias-ATFBB6D2.js +6 -0
  72. package/dist/bundle/chunks/awk2-6FBZTP57.js +20 -0
  73. package/dist/bundle/chunks/bash-OLRNM52U.js +5 -0
  74. package/dist/bundle/chunks/chmod-ODWUR7E6.js +8 -0
  75. package/dist/bundle/chunks/chunk-3AWP5CWK.js +73 -0
  76. package/dist/bundle/chunks/chunk-CXEWLFNE.js +16 -0
  77. package/dist/bundle/chunks/chunk-CZPA5RBA.js +5 -0
  78. package/dist/bundle/chunks/chunk-EEXR5ZDP.js +2 -0
  79. package/dist/bundle/chunks/chunk-HDQ56CKY.js +15 -0
  80. package/dist/bundle/chunks/chunk-PSW6BMXW.js +7 -0
  81. package/dist/bundle/chunks/{echo-VUHWYV6L.js → echo-6S7WE7XB.js} +2 -2
  82. package/dist/bundle/chunks/env-2UI6XINU.js +8 -0
  83. package/dist/bundle/chunks/expansion-RIGCFEMA.js +1 -0
  84. package/dist/bundle/chunks/{find-ACOAWALE.js → find-YGMSVGUV.js} +1 -1
  85. package/dist/bundle/chunks/{grep-ACVE42JK.js → grep-NIC6JNLH.js} +2 -2
  86. package/dist/bundle/chunks/{head-FZ6IQHYW.js → head-SA7P5NJ7.js} +1 -1
  87. package/dist/bundle/chunks/{jq-3YU5HRKE.js → jq-RLRYRPOJ.js} +1 -1
  88. package/dist/bundle/chunks/od-3FPDPLWJ.js +4 -0
  89. package/dist/bundle/chunks/printf-66XGXFCD.js +14 -0
  90. package/dist/bundle/chunks/pwd-S4NVAMC4.js +2 -0
  91. package/dist/bundle/chunks/{rg-YLZJWCEJ.js → rg-SRMB7L6G.js} +1 -1
  92. package/dist/bundle/chunks/rmdir-XFQE4ZYV.js +13 -0
  93. package/dist/bundle/chunks/sed-IV6HLDXU.js +99 -0
  94. package/dist/bundle/chunks/{tail-PD4RZR6J.js → tail-52LRAWXT.js} +1 -1
  95. package/dist/bundle/chunks/{tar-QWBXMF7K.js → tar-LWIHPMT6.js} +7 -7
  96. package/dist/bundle/chunks/time-UWXBG6CS.js +13 -0
  97. package/dist/bundle/chunks/touch-TDTEBHHI.js +6 -0
  98. package/dist/bundle/chunks/wc-HE5XARI4.js +5 -0
  99. package/dist/bundle/chunks/{which-M5MQ6QXQ.js → which-UBLRBDHN.js} +1 -1
  100. package/dist/bundle/chunks/whoami-YUDAIS32.js +2 -0
  101. package/dist/bundle/chunks/{xan-2R2APJJ4.js → xan-A6VPI4HJ.js} +19 -19
  102. package/dist/bundle/chunks/{yq-KANM4MD2.js → yq-L665QPQU.js} +1 -1
  103. package/dist/bundle/index.js +657 -133
  104. package/dist/commands/awk/ast.d.ts +1 -0
  105. package/dist/commands/awk/interpreter/context.d.ts +14 -0
  106. package/dist/commands/awk/interpreter/interpreter.d.ts +2 -0
  107. package/dist/commands/awk/interpreter/{helpers.d.ts → type-coercion.d.ts} +4 -1
  108. package/dist/commands/awk/parser2-print.d.ts +35 -0
  109. package/dist/commands/awk/parser2.d.ts +42 -34
  110. package/dist/commands/printf/strftime.d.ts +9 -0
  111. package/dist/commands/query-engine/builtins/array-builtins.d.ts +20 -0
  112. package/dist/commands/query-engine/builtins/control-builtins.d.ts +18 -0
  113. package/dist/commands/query-engine/builtins/date-builtins.d.ts +15 -0
  114. package/dist/commands/query-engine/builtins/format-builtins.d.ts +11 -0
  115. package/dist/commands/query-engine/builtins/index-builtins.d.ts +16 -0
  116. package/dist/commands/query-engine/builtins/index.d.ts +17 -0
  117. package/dist/commands/query-engine/builtins/math-builtins.d.ts +15 -0
  118. package/dist/commands/query-engine/builtins/navigation-builtins.d.ts +18 -0
  119. package/dist/commands/query-engine/builtins/object-builtins.d.ts +15 -0
  120. package/dist/commands/query-engine/builtins/path-builtins.d.ts +20 -0
  121. package/dist/commands/query-engine/builtins/sql-builtins.d.ts +16 -0
  122. package/dist/commands/query-engine/builtins/string-builtins.d.ts +15 -0
  123. package/dist/commands/query-engine/builtins/type-builtins.d.ts +11 -0
  124. package/dist/commands/query-engine/evaluator.d.ts +10 -2
  125. package/dist/commands/query-engine/parser-types.d.ts +171 -0
  126. package/dist/commands/query-engine/parser.d.ts +2 -132
  127. package/dist/commands/query-engine/path-operations.d.ts +15 -0
  128. package/dist/commands/query-engine/value-operations.d.ts +39 -0
  129. package/dist/commands/registry.d.ts +1 -1
  130. package/dist/commands/rmdir/rmdir.d.ts +2 -0
  131. package/dist/commands/sed/lexer.d.ts +12 -0
  132. package/dist/commands/sed/parser.d.ts +9 -0
  133. package/dist/commands/sed/sed-regex.d.ts +23 -0
  134. package/dist/commands/sed/types.d.ts +13 -1
  135. package/dist/commands/tar/tar-options.d.ts +36 -0
  136. package/dist/commands/time/time.d.ts +25 -0
  137. package/dist/commands/whoami/whoami.d.ts +9 -0
  138. package/dist/commands/xan/moonblade-tokenizer.d.ts +25 -0
  139. package/dist/fs/in-memory-fs/in-memory-fs.d.ts +12 -0
  140. package/dist/fs/interface.d.ts +16 -0
  141. package/dist/fs/mountable-fs/mountable-fs.d.ts +12 -0
  142. package/dist/fs/overlay-fs/overlay-fs.d.ts +13 -1
  143. package/dist/fs/read-write-fs/read-write-fs.d.ts +13 -1
  144. package/dist/interpreter/alias-expansion.d.ts +23 -0
  145. package/dist/interpreter/arithmetic.d.ts +1 -6
  146. package/dist/interpreter/assignment-expansion.d.ts +24 -0
  147. package/dist/interpreter/builtin-dispatch.d.ts +39 -0
  148. package/dist/interpreter/builtins/compgen.d.ts +26 -0
  149. package/dist/interpreter/builtins/complete.d.ts +17 -0
  150. package/dist/interpreter/builtins/compopt.d.ts +28 -0
  151. package/dist/interpreter/builtins/declare-array-parsing.d.ts +14 -0
  152. package/dist/interpreter/builtins/declare-print.d.ts +39 -0
  153. package/dist/interpreter/builtins/declare.d.ts +10 -4
  154. package/dist/interpreter/builtins/dirs.d.ts +29 -0
  155. package/dist/interpreter/builtins/eval.d.ts +1 -1
  156. package/dist/interpreter/builtins/export.d.ts +1 -0
  157. package/dist/interpreter/builtins/getopts.d.ts +18 -0
  158. package/dist/interpreter/builtins/hash.d.ts +19 -0
  159. package/dist/interpreter/builtins/help.d.ts +12 -0
  160. package/dist/interpreter/builtins/index.d.ts +9 -1
  161. package/dist/interpreter/builtins/local.d.ts +1 -1
  162. package/dist/interpreter/builtins/read.d.ts +1 -1
  163. package/dist/interpreter/builtins/set.d.ts +3 -0
  164. package/dist/interpreter/builtins/shift.d.ts +3 -0
  165. package/dist/interpreter/builtins/shopt.d.ts +7 -0
  166. package/dist/interpreter/builtins/unset.d.ts +5 -1
  167. package/dist/interpreter/builtins/variable-assignment.d.ts +66 -0
  168. package/dist/interpreter/command-resolution.d.ts +43 -0
  169. package/dist/interpreter/conditionals.d.ts +1 -1
  170. package/dist/interpreter/errors.d.ts +36 -1
  171. package/dist/interpreter/expansion/analysis.d.ts +15 -17
  172. package/dist/interpreter/expansion/arith-text-expansion.d.ts +20 -0
  173. package/dist/interpreter/expansion/array-pattern-ops.d.ts +21 -0
  174. package/dist/interpreter/expansion/array-prefix-suffix.d.ts +46 -0
  175. package/dist/interpreter/expansion/array-slice-transform.d.ts +36 -0
  176. package/dist/interpreter/expansion/array-word-expansion.d.ts +39 -0
  177. package/dist/interpreter/expansion/command-substitution.d.ts +23 -0
  178. package/dist/interpreter/expansion/glob-escape.d.ts +32 -0
  179. package/dist/interpreter/expansion/indirect-expansion.d.ts +42 -0
  180. package/dist/interpreter/expansion/parameter-ops.d.ts +113 -0
  181. package/dist/interpreter/expansion/pattern-expansion.d.ts +23 -0
  182. package/dist/interpreter/expansion/pattern-removal.d.ts +18 -0
  183. package/dist/interpreter/expansion/pattern.d.ts +2 -1
  184. package/dist/interpreter/expansion/positional-params.d.ts +59 -0
  185. package/dist/interpreter/expansion/prompt.d.ts +39 -0
  186. package/dist/interpreter/expansion/quoting.d.ts +13 -0
  187. package/dist/interpreter/expansion/tilde.d.ts +12 -0
  188. package/dist/interpreter/expansion/unquoted-expansion.d.ts +76 -0
  189. package/dist/interpreter/expansion/variable-attrs.d.ts +19 -0
  190. package/dist/interpreter/expansion/variable.d.ts +10 -1
  191. package/dist/interpreter/expansion/word-glob-expansion.d.ts +33 -0
  192. package/dist/interpreter/expansion/word-split.d.ts +11 -6
  193. package/dist/interpreter/expansion.d.ts +30 -4
  194. package/dist/interpreter/functions.d.ts +1 -1
  195. package/dist/interpreter/helpers/array.d.ts +20 -0
  196. package/dist/interpreter/helpers/ifs.d.ts +66 -5
  197. package/dist/interpreter/helpers/nameref.d.ts +65 -0
  198. package/dist/interpreter/helpers/quoting.d.ts +24 -0
  199. package/dist/interpreter/helpers/readonly.d.ts +28 -4
  200. package/dist/interpreter/helpers/shell-constants.d.ts +25 -0
  201. package/dist/interpreter/helpers/shellopts.d.ts +28 -0
  202. package/dist/interpreter/helpers/string-compare.d.ts +3 -1
  203. package/dist/interpreter/helpers/tilde.d.ts +13 -0
  204. package/dist/interpreter/helpers/variable-tests.d.ts +1 -1
  205. package/dist/interpreter/helpers/word-matching.d.ts +26 -0
  206. package/dist/interpreter/helpers/xtrace.d.ts +18 -0
  207. package/dist/interpreter/interpreter.d.ts +13 -14
  208. package/dist/interpreter/pipeline-execution.d.ts +16 -0
  209. package/dist/interpreter/redirections.d.ts +38 -1
  210. package/dist/interpreter/simple-command-assignments.d.ts +29 -0
  211. package/dist/interpreter/subshell-group.d.ts +32 -0
  212. package/dist/interpreter/type-command.d.ts +37 -0
  213. package/dist/interpreter/types.d.ts +255 -21
  214. package/dist/parser/arithmetic-parser.d.ts +2 -4
  215. package/dist/parser/arithmetic-primaries.d.ts +45 -0
  216. package/dist/parser/compound-parser.d.ts +21 -7
  217. package/dist/parser/expansion-parser.d.ts +7 -1
  218. package/dist/parser/lexer.d.ts +57 -0
  219. package/dist/parser/parser-substitution.d.ts +62 -0
  220. package/dist/parser/parser.d.ts +39 -2
  221. package/dist/parser/types.d.ts +1 -0
  222. package/dist/types.d.ts +17 -0
  223. package/package.json +4 -1
  224. package/dist/bin/chunks/alias-PCMLRCRW.js +0 -7
  225. package/dist/bin/chunks/awk2-D2US2LMM.js +0 -20
  226. package/dist/bin/chunks/bash-UT3MT5UU.js +0 -7
  227. package/dist/bin/chunks/chmod-3DIKREF7.js +0 -9
  228. package/dist/bin/chunks/chunk-ACRTDIBO.js +0 -6
  229. package/dist/bin/chunks/chunk-DV5HL4K2.js +0 -17
  230. package/dist/bin/chunks/chunk-J7BCMQDI.js +0 -16
  231. package/dist/bin/chunks/chunk-NWWB2XRE.js +0 -6
  232. package/dist/bin/chunks/chunk-PM2DS2YW.js +0 -3
  233. package/dist/bin/chunks/env-YLLSNZZN.js +0 -9
  234. package/dist/bin/chunks/od-SLM7SRWU.js +0 -7
  235. package/dist/bin/chunks/printf-HWUQKYUM.js +0 -14
  236. package/dist/bin/chunks/pwd-53KG2MCJ.js +0 -3
  237. package/dist/bin/chunks/sed-5LQMJYRJ.js +0 -80
  238. package/dist/bin/chunks/touch-TSNAXMZ2.js +0 -4
  239. package/dist/bin/chunks/wc-QSBRKIF5.js +0 -6
  240. package/dist/bin/shell/chunks/alias-PCMLRCRW.js +0 -7
  241. package/dist/bin/shell/chunks/awk2-D2US2LMM.js +0 -20
  242. package/dist/bin/shell/chunks/bash-UT3MT5UU.js +0 -7
  243. package/dist/bin/shell/chunks/chmod-3DIKREF7.js +0 -9
  244. package/dist/bin/shell/chunks/chunk-ACRTDIBO.js +0 -6
  245. package/dist/bin/shell/chunks/chunk-DV5HL4K2.js +0 -17
  246. package/dist/bin/shell/chunks/chunk-J7BCMQDI.js +0 -16
  247. package/dist/bin/shell/chunks/chunk-NWWB2XRE.js +0 -6
  248. package/dist/bin/shell/chunks/chunk-PM2DS2YW.js +0 -3
  249. package/dist/bin/shell/chunks/env-YLLSNZZN.js +0 -9
  250. package/dist/bin/shell/chunks/od-SLM7SRWU.js +0 -7
  251. package/dist/bin/shell/chunks/printf-HWUQKYUM.js +0 -14
  252. package/dist/bin/shell/chunks/pwd-53KG2MCJ.js +0 -3
  253. package/dist/bin/shell/chunks/sed-5LQMJYRJ.js +0 -80
  254. package/dist/bin/shell/chunks/touch-TSNAXMZ2.js +0 -4
  255. package/dist/bin/shell/chunks/wc-QSBRKIF5.js +0 -6
  256. package/dist/bundle/chunks/alias-4UGRF4DM.js +0 -6
  257. package/dist/bundle/chunks/awk2-46RTIZKB.js +0 -19
  258. package/dist/bundle/chunks/bash-ZILV3VHA.js +0 -6
  259. package/dist/bundle/chunks/chmod-FBHLEIY6.js +0 -8
  260. package/dist/bundle/chunks/chunk-4JO5BKO4.js +0 -5
  261. package/dist/bundle/chunks/chunk-BOJ3OAZB.js +0 -16
  262. package/dist/bundle/chunks/chunk-CG2HXOFG.js +0 -5
  263. package/dist/bundle/chunks/chunk-NWEGHOXL.js +0 -2
  264. package/dist/bundle/chunks/chunk-W2EKKAIL.js +0 -15
  265. package/dist/bundle/chunks/env-EG5SQSAQ.js +0 -8
  266. package/dist/bundle/chunks/od-ECWXNUB4.js +0 -6
  267. package/dist/bundle/chunks/printf-VG2POOXB.js +0 -13
  268. package/dist/bundle/chunks/pwd-AC4P3JKI.js +0 -2
  269. package/dist/bundle/chunks/sed-ZKODWZ6F.js +0 -79
  270. package/dist/bundle/chunks/touch-MVQSKQKT.js +0 -3
  271. package/dist/bundle/chunks/wc-DFQKWSIZ.js +0 -5
  272. package/dist/interpreter/builtins/variable-helpers.d.ts +0 -30
  273. /package/dist/bin/chunks/{curl-LCMREE7R.js → curl-TH7YRBSA.js} +0 -0
  274. /package/dist/bin/chunks/{file-LNCFDPQZ.js → file-6PCTL3MH.js} +0 -0
  275. /package/dist/bin/shell/chunks/{curl-LCMREE7R.js → curl-TH7YRBSA.js} +0 -0
  276. /package/dist/bin/shell/chunks/{file-LNCFDPQZ.js → file-6PCTL3MH.js} +0 -0
  277. /package/dist/bundle/chunks/{curl-TVZH24MD.js → curl-XLP4VABU.js} +0 -0
  278. /package/dist/bundle/chunks/{file-XPA6O6H2.js → file-NQP3CKRV.js} +0 -0
  279. /package/dist/commands/curl/{utils.d.ts → response-formatting.d.ts} +0 -0
  280. /package/dist/commands/xan/{xan-utils.d.ts → column-selection.d.ts} +0 -0
  281. /package/dist/fs/{utils.d.ts → encoding.d.ts} +0 -0
@@ -1,78 +1,522 @@
1
- import{a as U,b as Y,c as G,d as te,e as J,f as R,g as W,h as Ee,i as B,j as ue,k as qe}from"./chunks/chunk-CG2HXOFG.js";import"./chunks/chunk-NUFRM6SI.js";import{a as le}from"./chunks/chunk-44UOCSGV.js";import"./chunks/chunk-DXB73IDG.js";var ge=[{name:"echo",load:async()=>(await import("./chunks/echo-VUHWYV6L.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-MV4K6AUA.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-VG2POOXB.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-5W3NU5OJ.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-7UKY4B3B.js")).mkdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-MVQSKQKT.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-I2SRVF7H.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-PBJT3GBF.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-FXHEKRTB.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-Y7YB677N.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-FBHLEIY6.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-AC4P3JKI.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-EM4O3U4P.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-FZ6IQHYW.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-PD4RZR6J.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-DFQKWSIZ.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-IVQBBOKN.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-ACVE42JK.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-ACVE42JK.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-ACVE42JK.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-YLZJWCEJ.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-ZKODWZ6F.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-46RTIZKB.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-EJUT5LXD.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-47QVBRNC.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-AXQM7FFF.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-NVKWEAZF.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-QTGVEPH5.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-EDGW5FG6.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-FKUV5GH5.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-KWQGFZH5.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-6CFXIPYZ.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-VSTNOVF5.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-I7A2VXFD.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-LRU5XCFP.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-YBTFW7MT.js")).split},{name:"column",load:async()=>(await import("./chunks/column-XPDNNO5Y.js")).column},{name:"join",load:async()=>(await import("./chunks/join-X3QYPZUA.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-2QU4NRSJ.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-ACOAWALE.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-CFA5ZIGT.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-YPJLCQYA.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-MEM64BW3.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-NQXEC3EF.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-EG5SQSAQ.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-EG5SQSAQ.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-4UGRF4DM.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-4UGRF4DM.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-MQDK2OPD.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-4FRA6OJ7.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-CNJ54NE6.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-CNJ54NE6.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-VT2LJIDX.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-ZILV3VHA.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-ZILV3VHA.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-3YU5HRKE.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-3BME25ON.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-ZLJYSBRK.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-PN3CMG7K.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-AK4QE4WR.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-X3X3N6IE.js")).timeoutCommand},{name:"seq",load:async()=>(await import("./chunks/seq-5VRIVQYP.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-DG4E7SIS.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-KLHZSRUA.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-WKWTIZGQ.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-IUVNMBTA.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-XPA6O6H2.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-ZK6GQVSL.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-75YOGKM4.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-M5MQ6QXQ.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-2X4JLF4W.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-NWR32CGF.js")).hostname},{name:"od",load:async()=>(await import("./chunks/od-ECWXNUB4.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-L3NDJG3F.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-L3NDJG3F.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-L3NDJG3F.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(ge.push({name:"tar",load:async()=>(await import("./chunks/tar-QWBXMF7K.js")).tarCommand}),ge.push({name:"yq",load:async()=>(await import("./chunks/yq-KANM4MD2.js")).yqCommand}),ge.push({name:"xan",load:async()=>(await import("./chunks/xan-2R2APJJ4.js")).xanCommand}),ge.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-5QVZOGER.js")).sqlite3Command}));var Ar=[{name:"curl",load:async()=>(await import("./chunks/curl-TVZH24MD.js")).curlCommand}],gr=new Map;function Sr(t){return{name:t.name,async execute(e,s){let r=gr.get(t.name);return r||(r=await t.load(),gr.set(t.name,r)),r.execute(e,s)}}}function Hs(){return ge.map(t=>t.name)}function js(){return Ar.map(t=>t.name)}function xr(t){return(t?ge.filter(s=>t.includes(s.name)):ge).map(Sr)}function br(){return Ar.map(Sr)}function Cr(t){return"load"in t&&typeof t.load=="function"}function qs(t,e){return{name:t,execute:e}}function Nr(t){let e=null;return{name:t.name,async execute(s,r){return e||(e=await t.load()),e.execute(s,r)}}}var Zs=new TextEncoder,Qs=new TextDecoder;function re(t,e){if(t instanceof Uint8Array)return t;if(e==="base64")return Uint8Array.from(atob(t),s=>s.charCodeAt(0));if(e==="hex"){let s=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)s[r/2]=parseInt(t.slice(r,r+2),16);return s}return e==="binary"||e==="latin1"?Uint8Array.from(t,s=>s.charCodeAt(0)):Zs.encode(t)}function Ce(t,e){return e==="base64"?btoa(String.fromCharCode(...t)):e==="hex"?Array.from(t).map(s=>s.toString(16).padStart(2,"0")).join(""):e==="binary"||e==="latin1"?String.fromCharCode(...t):Qs.decode(t)}function q(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var Ze=new TextEncoder;function Ks(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var se=class{data=new Map;constructor(e){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),e)for(let[s,r]of Object.entries(e))Ks(r)?this.writeFileSync(s,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(s,r)}normalizePath(e){if(!e||e==="/")return"/";let s=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;s.startsWith("/")||(s=`/${s}`);let r=s.split("/").filter(i=>i&&i!=="."),n=[];for(let i of r)i===".."?n.pop():n.push(i);return`/${n.join("/")}`||"/"}dirname(e){let s=this.normalizePath(e);if(s==="/")return"/";let r=s.lastIndexOf("/");return r===0?"/":s.slice(0,r)}ensureParentDirs(e){let s=this.dirname(e);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,s,r,n){let i=this.normalizePath(e);this.ensureParentDirs(i);let o=q(r),a=re(s,o);this.data.set(i,{type:"file",content:a,mode:n?.mode??420,mtime:n?.mtime??new Date})}async readFile(e,s){let r=await this.readFileBuffer(e),n=q(s);return Ce(r,n)}async readFileBuffer(e){let s=this.resolvePathWithSymlinks(e),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content instanceof Uint8Array?r.content:Ze.encode(r.content)}async writeFile(e,s,r){this.writeFileSync(e,s,r)}async appendFile(e,s,r){let n=this.normalizePath(e),i=this.data.get(n);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${e}'`);let o=q(r),a=re(s,o);if(i?.type==="file"){let c=i.content instanceof Uint8Array?i.content:Ze.encode(i.content),l=new Uint8Array(c.length+a.length);l.set(c),l.set(a,c.length),this.data.set(n,{type:"file",content:l,mode:i.mode,mtime:new Date})}else this.writeFileSync(e,s,r)}async exists(e){try{let s=this.resolvePathWithSymlinks(e);return this.data.has(s)}catch{return!1}}async stat(e){let s=this.resolvePathWithSymlinks(e),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let n=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Ze.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}async lstat(e){let s=this.resolveIntermediateSymlinks(e),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};let n=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Ze.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}resolveSymlink(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${s}`:`${r}/${s}`)}resolveIntermediateSymlinks(e){let s=this.normalizePath(e);if(s==="/")return"/";let r=s.slice(1).split("/");if(r.length<=1)return s;let n="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];n=`${n}/${a}`;let c=this.data.get(n),l=0,u=40;for(;c&&c.type==="symlink"&&l<u;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${e}'`);i.add(n),n=this.resolveSymlink(n,c.target),c=this.data.get(n),l++}if(l>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${e}'`)}return`${n}/${r[r.length-1]}`}resolvePathWithSymlinks(e){let s=this.normalizePath(e);if(s==="/")return"/";let r=s.slice(1).split("/"),n="",i=new Set;for(let o of r){n=`${n}/${o}`;let a=this.data.get(n),c=0,l=40;for(;a&&a.type==="symlink"&&c<l;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);i.add(n),n=this.resolveSymlink(n,a.target),a=this.data.get(n),c++}if(c>=l)throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`)}return n}async mkdir(e,s){this.mkdirSync(e,s)}mkdirSync(e,s){let r=this.normalizePath(e);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let n=this.dirname(r);if(n!=="/"&&!this.data.has(n))if(s?.recursive)this.mkdirSync(n,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(e){return(await this.readdirWithFileTypes(e)).map(r=>r.name)}async readdirWithFileTypes(e){let s=this.normalizePath(e),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let n=new Set;for(;r&&r.type==="symlink";){if(n.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${e}'`);n.add(s),s=this.resolveSymlink(s,r.target),r=this.data.get(s)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${e}'`);let i=s==="/"?"/":`${s}/`,o=new Map;for(let[a,c]of this.data.entries())if(a!==s&&a.startsWith(i)){let l=a.slice(i.length),u=l.split("/")[0];u&&!l.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}return Array.from(o.values()).sort((a,c)=>a.name<c.name?-1:a.name>c.name?1:0)}async rm(e,s){let r=this.normalizePath(e),n=this.data.get(r);if(!n){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(n.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let o of i){let a=r==="/"?`/${o}`:`${r}/${o}`;await this.rm(a,s)}}}this.data.delete(r)}async cp(e,s,r){let n=this.normalizePath(e),i=this.normalizePath(s),o=this.data.get(n);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${e}'`);if(o.type==="file")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(n);for(let c of a){let l=n==="/"?`/${c}`:`${n}/${c}`,u=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(l,u,r)}}}async mv(e,s){await this.cp(e,s,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=e==="/"?`/${s}`:`${e}/${s}`;return this.normalizePath(r)}async chmod(e,s){let r=this.normalizePath(e),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);n.mode=s}async symlink(e,s){let r=this.normalizePath(s);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,s){let r=this.normalizePath(e),n=this.normalizePath(s),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${e}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${e}'`);if(this.data.has(n))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(e){let s=this.normalizePath(e),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}};var Pr="5.1.0(1)-release",vr="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function We(){return{pid:process.pid,ppid:process.ppid,uid:process.getuid?.()??1e3,gid:process.getgid?.()??1e3}}function $r(){let{pid:t,ppid:e,uid:s,gid:r}=We();return`Name: bash
2
- State: R (running)
3
- Pid: ${t}
4
- PPid: ${e}
5
- Uid: ${s} ${s} ${s} ${s}
6
- Gid: ${r} ${r} ${r} ${r}
7
- `}function Xs(t){let e=t;return typeof e.mkdirSync=="function"&&typeof e.writeFileSync=="function"}function Ys(t,e){t.mkdirSync("/bin",{recursive:!0}),t.mkdirSync("/usr/bin",{recursive:!0}),e&&(t.mkdirSync("/home/user",{recursive:!0}),t.mkdirSync("/tmp",{recursive:!0}))}function Js(t){t.mkdirSync("/dev",{recursive:!0}),t.writeFileSync("/dev/null",""),t.writeFileSync("/dev/zero",new Uint8Array(0)),t.writeFileSync("/dev/stdin",""),t.writeFileSync("/dev/stdout",""),t.writeFileSync("/dev/stderr","")}function en(t){t.mkdirSync("/proc/self/fd",{recursive:!0}),t.writeFileSync("/proc/version",`${vr}
8
- `),t.writeFileSync("/proc/self/exe","/bin/bash"),t.writeFileSync("/proc/self/cmdline","bash\0"),t.writeFileSync("/proc/self/comm",`bash
9
- `),t.writeFileSync("/proc/self/status",$r()),t.writeFileSync("/proc/self/fd/0","/dev/stdin"),t.writeFileSync("/proc/self/fd/1","/dev/stdout"),t.writeFileSync("/proc/self/fd/2","/dev/stderr")}function kr(t,e){Xs(t)&&(Ys(t,e),Js(t),en(t))}var tn=["tar","yq","xan","sqlite3"];function Ir(t){return tn.includes(t)}function T(t,e){return{type:"ArithmeticExpression",expression:ne(t,e,0).expr}}function ne(t,e,s){return rn(t,e,s)}function rn(t,e,s){let{expr:r,pos:n}=Ke(t,e,s);for(n=O(e,n);e[n]===",";){n++;let{expr:i,pos:o}=Ke(t,e,n);r={type:"ArithBinary",operator:",",left:r,right:i},n=O(e,o)}return{expr:r,pos:n}}function Ke(t,e,s){let{expr:r,pos:n}=sn(t,e,s);if(n=O(e,n),e[n]==="?"){n++;let{expr:i,pos:o}=ne(t,e,n);if(n=O(e,o),e[n]===":"){n++;let{expr:a,pos:c}=ne(t,e,n);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:a},pos:c}}}return{expr:r,pos:n}}function sn(t,e,s){let{expr:r,pos:n}=Rr(t,e,s);for(;n=O(e,n),e.slice(n,n+2)==="||";){n+=2;let{expr:i,pos:o}=Rr(t,e,n);r={type:"ArithBinary",operator:"||",left:r,right:i},n=o}return{expr:r,pos:n}}function Rr(t,e,s){let{expr:r,pos:n}=Dr(t,e,s);for(;n=O(e,n),e.slice(n,n+2)==="&&";){n+=2;let{expr:i,pos:o}=Dr(t,e,n);r={type:"ArithBinary",operator:"&&",left:r,right:i},n=o}return{expr:r,pos:n}}function Dr(t,e,s){let{expr:r,pos:n}=Or(t,e,s);for(;n=O(e,n),e[n]==="|"&&e[n+1]!=="|";){n++;let{expr:i,pos:o}=Or(t,e,n);r={type:"ArithBinary",operator:"|",left:r,right:i},n=o}return{expr:r,pos:n}}function Or(t,e,s){let{expr:r,pos:n}=_r(t,e,s);for(;n=O(e,n),e[n]==="^";){n++;let{expr:i,pos:o}=_r(t,e,n);r={type:"ArithBinary",operator:"^",left:r,right:i},n=o}return{expr:r,pos:n}}function _r(t,e,s){let{expr:r,pos:n}=Lr(t,e,s);for(;n=O(e,n),e[n]==="&"&&e[n+1]!=="&";){n++;let{expr:i,pos:o}=Lr(t,e,n);r={type:"ArithBinary",operator:"&",left:r,right:i},n=o}return{expr:r,pos:n}}function Lr(t,e,s){let{expr:r,pos:n}=Tr(t,e,s);for(;n=O(e,n),e.slice(n,n+2)==="=="||e.slice(n,n+2)==="!=";){let i=e.slice(n,n+2);n+=2;let{expr:o,pos:a}=Tr(t,e,n);r={type:"ArithBinary",operator:i,left:r,right:o},n=a}return{expr:r,pos:n}}function Tr(t,e,s){let{expr:r,pos:n}=Nt(t,e,s);for(;;)if(n=O(e,n),e.slice(n,n+2)==="<="||e.slice(n,n+2)===">="){let i=e.slice(n,n+2);n+=2;let{expr:o,pos:a}=Nt(t,e,n);r={type:"ArithBinary",operator:i,left:r,right:o},n=a}else if(e[n]==="<"||e[n]===">"){let i=e[n];n++;let{expr:o,pos:a}=Nt(t,e,n);r={type:"ArithBinary",operator:i,left:r,right:o},n=a}else break;return{expr:r,pos:n}}function Nt(t,e,s){let{expr:r,pos:n}=Fr(t,e,s);for(;n=O(e,n),e.slice(n,n+2)==="<<"||e.slice(n,n+2)===">>";){let i=e.slice(n,n+2);n+=2;let{expr:o,pos:a}=Fr(t,e,n);r={type:"ArithBinary",operator:i,left:r,right:o},n=a}return{expr:r,pos:n}}function Fr(t,e,s){let{expr:r,pos:n}=Wr(t,e,s);for(;n=O(e,n),(e[n]==="+"||e[n]==="-")&&e[n+1]!==e[n];){let i=e[n];n++;let{expr:o,pos:a}=Wr(t,e,n);r={type:"ArithBinary",operator:i,left:r,right:o},n=a}return{expr:r,pos:n}}function Wr(t,e,s){let{expr:r,pos:n}=Qe(t,e,s);for(;;)if(n=O(e,n),e[n]==="*"&&e[n+1]!=="*"){n++;let{expr:i,pos:o}=Qe(t,e,n);r={type:"ArithBinary",operator:"*",left:r,right:i},n=o}else if(e[n]==="/"||e[n]==="%"){let i=e[n];n++;let{expr:o,pos:a}=Qe(t,e,n);r={type:"ArithBinary",operator:i,left:r,right:o},n=a}else break;return{expr:r,pos:n}}function Qe(t,e,s){let{expr:r,pos:n}=Pt(t,e,s),i=O(e,n);if(e.slice(i,i+2)==="**"){i+=2;let{expr:o,pos:a}=Qe(t,e,i);return{expr:{type:"ArithBinary",operator:"**",left:r,right:o},pos:a}}return{expr:r,pos:n}}function Pt(t,e,s){let r=O(e,s);if(e.slice(r,r+2)==="++"||e.slice(r,r+2)==="--"){let n=e.slice(r,r+2);r+=2;let{expr:i,pos:o}=Pt(t,e,r);return{expr:{type:"ArithUnary",operator:n,operand:i,prefix:!0},pos:o}}if(e[r]==="+"||e[r]==="-"||e[r]==="!"||e[r]==="~"){let n=e[r];r++;let{expr:i,pos:o}=Pt(t,e,r);return{expr:{type:"ArithUnary",operator:n,operand:i,prefix:!0},pos:o}}return on(t,e,r)}function nn(t,e){let s=t[e];return s==="$"||s==="`"}function on(t,e,s){let{expr:r,pos:n}=Mr(t,e,s),i=[r];for(;nn(e,n);){let{expr:o,pos:a}=Mr(t,e,n);i.push(o),n=a}if(i.length>1&&(r={type:"ArithConcat",parts:i}),n=O(e,n),e.slice(n,n+2)==="++"||e.slice(n,n+2)==="--"){let o=e.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:o,operand:r,prefix:!1},pos:n}}return{expr:r,pos:n}}function Mr(t,e,s){let r=O(e,s);if(e.slice(r,r+3)==="$(("){r+=3;let n=1,i=r;for(;r<e.length-1&&n>0;)e[r]==="("&&e[r+1]==="("?(n++,r+=2):e[r]===")"&&e[r+1]===")"?(n--,n>0&&(r+=2)):r++;let o=e.slice(i,r),{expr:a}=ne(t,o,0);return r+=2,{expr:{type:"ArithNested",expression:a},pos:r}}if(e.slice(r,r+2)==="$("&&e[r+2]!=="("){r+=2;let n=1,i=r;for(;r<e.length&&n>0;)e[r]==="("?n++:e[r]===")"&&n--,n>0&&r++;let o=e.slice(i,r);return r++,{expr:{type:"ArithCommandSubst",command:o},pos:r}}if(e[r]==="`"){r++;let n=r;for(;r<e.length&&e[r]!=="`";)r++;let i=e.slice(n,r);return e[r]==="`"&&r++,{expr:{type:"ArithCommandSubst",command:i},pos:r}}if(e[r]==="("){r++;let{expr:n,pos:i}=ne(t,e,r);return r=O(e,i),e[r]===")"&&r++,{expr:{type:"ArithGroup",expression:n},pos:r}}if(/[0-9]/.test(e[r])){let n="",i=!1;for(;r<e.length;){let a=e[r];if(i)if(/[0-9a-zA-Z@_]/.test(a))n+=a,r++;else break;else if(a==="#")i=!0,n+=a,r++;else if(/[0-9a-fA-FxX]/.test(a))n+=a,r++;else break}if(e[r]==="."&&/[0-9]/.test(e[r+1]))throw new W(`${n}.${e[r+1]}...: syntax error: invalid arithmetic operator`);if(e[r]==="["){let a=e.slice(r).trim();return{expr:{type:"ArithNumberSubscript",number:n,errorToken:a},pos:e.length}}return{expr:{type:"ArithNumber",value:Ne(n)},pos:r}}if(e[r]==="$"&&e[r+1]==="{"){let n=r+2,i=1,o=n;for(;o<e.length&&i>0;)e[o]==="{"?i++:e[o]==="}"&&i--,i>0&&o++;let a=e.slice(n,o),c=o+1;if(e[c]==="#"){let l=c+1;for(;l<e.length&&/[0-9a-zA-Z@_]/.test(e[l]);)l++;let u=e.slice(c+1,l);return{expr:{type:"ArithDynamicBase",baseExpr:a,value:u},pos:l}}if(/[0-9]/.test(e[c])||e[c]==="x"||e[c]==="X"){let l=c;if(e[c]==="x"||e[c]==="X")for(l++;l<e.length&&/[0-9a-fA-F]/.test(e[l]);)l++;else for(;l<e.length&&/[0-9]/.test(e[l]);)l++;let u=e.slice(c,l);return{expr:{type:"ArithDynamicNumber",prefix:a,suffix:u},pos:l}}return r=c,{expr:{type:"ArithBracedExpansion",content:a},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[0-9]/.test(e[r+1])){r++;let n="";for(;r<e.length&&/[0-9]/.test(e[r]);)n+=e[r],r++;return{expr:{type:"ArithVariable",name:n},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[a-zA-Z_]/.test(e[r+1])&&r++,/[a-zA-Z_]/.test(e[r])){let n="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)n+=e[r],r++;if(e[r]==="["){r++;let o;if(e[r]==="'"||e[r]==='"'){let l=e[r];for(r++,o="";r<e.length&&e[r]!==l;)o+=e[r],r++;e[r]===l&&r++,r=O(e,r),e[r]==="]"&&r++}let a;if(o===void 0){let{expr:l,pos:u}=ne(t,e,r);a=l,r=u,e[r]==="]"&&r++}if(r=O(e,r),e[r]==="["&&a)return{expr:{type:"ArithDoubleSubscript",array:n,index:a},pos:r};let c=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let l of c)if(e.slice(r,r+l.length)===l&&e.slice(r,r+l.length+1)!=="=="){r+=l.length;let{expr:u,pos:h}=Ke(t,e,r);return{expr:{type:"ArithAssignment",operator:l,variable:n,subscript:a,stringKey:o,value:u},pos:h}}return{expr:{type:"ArithArrayElement",array:n,index:a,stringKey:o},pos:r}}r=O(e,r);let i=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let o of i)if(e.slice(r,r+o.length)===o&&e.slice(r,r+o.length+1)!=="=="){r+=o.length;let{expr:a,pos:c}=Ke(t,e,r);return{expr:{type:"ArithAssignment",operator:o,variable:n,value:a},pos:c}}return{expr:{type:"ArithVariable",name:n},pos:r}}return{expr:{type:"ArithNumber",value:0},pos:r}}function Ne(t){if(t.includes("#")){let[e,s]=t.split("#"),r=Number.parseInt(e,10);if(r<2||r>64)return Number.NaN;if(r<=36)return Number.parseInt(s,r);let n=0;for(let i of s){let o;if(i>="0"&&i<="9")o=i.charCodeAt(0)-48;else if(i>="a"&&i<="z")o=i.charCodeAt(0)-97+10;else if(i>="A"&&i<="Z")o=i.charCodeAt(0)-65+36;else if(i==="@")o=62;else if(i==="_")o=63;else return Number.NaN;if(o>=r)return Number.NaN;n=n*r+o}return n}return t.startsWith("0x")||t.startsWith("0X")?Number.parseInt(t.slice(2),16):t.startsWith("0")&&t.length>1&&/^[0-9]+$/.test(t)?/[89]/.test(t)?Number.NaN:Number.parseInt(t,8):Number.parseInt(t,10)}function O(t,e){for(;e<t.length;){if(t[e]==="\\"&&t[e+1]===`
10
- `){e+=2;continue}if(/\s/.test(t[e])){e++;continue}break}return e}var A={script(t){return{type:"Script",statements:t}},statement(t,e=[],s=!1){return{type:"Statement",pipelines:t,operators:e,background:s}},pipeline(t,e=!1){return{type:"Pipeline",commands:t,negated:e}},simpleCommand(t,e=[],s=[],r=[]){return{type:"SimpleCommand",name:t,args:e,assignments:s,redirections:r}},word(t){return{type:"Word",parts:t}},literal(t){return{type:"Literal",value:t}},singleQuoted(t){return{type:"SingleQuoted",value:t}},doubleQuoted(t){return{type:"DoubleQuoted",parts:t}},escaped(t){return{type:"Escaped",value:t}},parameterExpansion(t,e=null){return{type:"ParameterExpansion",parameter:t,operation:e}},commandSubstitution(t,e=!1){return{type:"CommandSubstitution",body:t,legacy:e}},arithmeticExpansion(t){return{type:"ArithmeticExpansion",expression:t}},assignment(t,e,s=!1,r=null){return{type:"Assignment",name:t,value:e,append:s,array:r}},redirection(t,e,s=null){return{type:"Redirection",fd:s,operator:t,target:e}},hereDoc(t,e,s=!1,r=!1){return{type:"HereDoc",delimiter:t,content:e,stripTabs:s,quoted:r}},ifNode(t,e=null,s=[]){return{type:"If",clauses:t,elseBody:e,redirections:s}},forNode(t,e,s,r=[]){return{type:"For",variable:t,words:e,body:s,redirections:r}},whileNode(t,e,s=[]){return{type:"While",condition:t,body:e,redirections:s}},untilNode(t,e,s=[]){return{type:"Until",condition:t,body:e,redirections:s}},caseNode(t,e,s=[]){return{type:"Case",word:t,items:e,redirections:s}},caseItem(t,e,s=";;"){return{type:"CaseItem",patterns:t,body:e,terminator:s}},subshell(t,e=[]){return{type:"Subshell",body:t,redirections:e}},group(t,e=[]){return{type:"Group",body:t,redirections:e}},functionDef(t,e,s=[]){return{type:"FunctionDef",name:t,body:e,redirections:s}},conditionalCommand(t,e=[]){return{type:"ConditionalCommand",expression:t,redirections:e}},arithmeticCommand(t,e=[]){return{type:"ArithmeticCommand",expression:t,redirections:e}}};var f;(function(t){t.EOF="EOF",t.NEWLINE="NEWLINE",t.SEMICOLON="SEMICOLON",t.AMP="AMP",t.PIPE="PIPE",t.PIPE_AMP="PIPE_AMP",t.AND_AND="AND_AND",t.OR_OR="OR_OR",t.BANG="BANG",t.LESS="LESS",t.GREAT="GREAT",t.DLESS="DLESS",t.DGREAT="DGREAT",t.LESSAND="LESSAND",t.GREATAND="GREATAND",t.LESSGREAT="LESSGREAT",t.DLESSDASH="DLESSDASH",t.CLOBBER="CLOBBER",t.TLESS="TLESS",t.AND_GREAT="AND_GREAT",t.AND_DGREAT="AND_DGREAT",t.LPAREN="LPAREN",t.RPAREN="RPAREN",t.LBRACE="LBRACE",t.RBRACE="RBRACE",t.DSEMI="DSEMI",t.SEMI_AND="SEMI_AND",t.SEMI_SEMI_AND="SEMI_SEMI_AND",t.DBRACK_START="DBRACK_START",t.DBRACK_END="DBRACK_END",t.DPAREN_START="DPAREN_START",t.DPAREN_END="DPAREN_END",t.IF="IF",t.THEN="THEN",t.ELSE="ELSE",t.ELIF="ELIF",t.FI="FI",t.FOR="FOR",t.WHILE="WHILE",t.UNTIL="UNTIL",t.DO="DO",t.DONE="DONE",t.CASE="CASE",t.ESAC="ESAC",t.IN="IN",t.FUNCTION="FUNCTION",t.SELECT="SELECT",t.TIME="TIME",t.COPROC="COPROC",t.WORD="WORD",t.NAME="NAME",t.NUMBER="NUMBER",t.ASSIGNMENT_WORD="ASSIGNMENT_WORD",t.COMMENT="COMMENT",t.HEREDOC_CONTENT="HEREDOC_CONTENT"})(f||(f={}));var Xe={if:f.IF,then:f.THEN,else:f.ELSE,elif:f.ELIF,fi:f.FI,for:f.FOR,while:f.WHILE,until:f.UNTIL,do:f.DO,done:f.DONE,case:f.CASE,esac:f.ESAC,in:f.IN,function:f.FUNCTION,select:f.SELECT,time:f.TIME,coproc:f.COPROC};function Br(t){let e=t.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!e)return!1;let s=t.slice(e[0].length);if(s===""||s==="+")return!0;if(s[0]==="["){let r=0,n=0;for(;n<s.length;n++)if(s[n]==="[")r++;else if(s[n]==="]"&&(r--,r===0))break;if(r!==0||n>=s.length)return!1;let i=s.slice(n+1);return i===""||i==="+"}return!1}var an=[[";",";","&",f.SEMI_SEMI_AND],["<","<","<",f.TLESS],["&",">",">",f.AND_DGREAT]],cn=[["[","[",f.DBRACK_START],["]","]",f.DBRACK_END],["(","(",f.DPAREN_START],[")",")",f.DPAREN_END],["&","&",f.AND_AND],["|","|",f.OR_OR],[";",";",f.DSEMI],[";","&",f.SEMI_AND],["|","&",f.PIPE_AMP],[">",">",f.DGREAT],["<","&",f.LESSAND],[">","&",f.GREATAND],["<",">",f.LESSGREAT],[">","|",f.CLOBBER],["&",">",f.AND_GREAT]],ln={"|":f.PIPE,"&":f.AMP,";":f.SEMICOLON,"(":f.LPAREN,")":f.RPAREN,"<":f.LESS,">":f.GREAT};function un(t){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)}var Ye=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];constructor(e){this.input=e}tokenize(){let s=this.input.length,r=this.tokens,n=this.pendingHeredocs;for(;this.pos<s;){if(n.length>0&&r.length>0&&r[r.length-1].type===f.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=s)break;let i=this.nextToken();i&&r.push(i)}return r.push({type:f.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let e=this.input,s=e.length,r=this.pos,n=this.column,i=this.line;for(;r<s;){let o=e[r];if(o===" "||o===" ")r++,n++;else if(o==="\\"&&e[r+1]===`
11
- `)r+=2,i++,n=1;else break}this.pos=r,this.column=n,this.line=i}nextToken(){let e=this.input,s=this.pos,r=this.line,n=this.column,i=e[s],o=e[s+1],a=e[s+2];if(i==="#")return this.readComment(s,r,n);if(i===`
12
- `)return this.pos=s+1,this.line++,this.column=1,{type:f.NEWLINE,value:`
13
- `,start:s,end:s+1,line:r,column:n};if(i==="<"&&o==="<"&&a==="-")return this.pos=s+3,this.column=n+3,this.registerHeredocFromLookahead(!0),this.makeToken(f.DLESSDASH,"<<-",s,r,n);for(let[l,u,h,d]of an)if(i===l&&o===u&&a===h)return this.pos=s+3,this.column=n+3,this.makeToken(d,l+u+h,s,r,n);if(i==="<"&&o==="<")return this.pos=s+2,this.column=n+2,this.registerHeredocFromLookahead(!1),this.makeToken(f.DLESS,"<<",s,r,n);for(let[l,u,h]of cn)if(i===l&&o===u)return this.pos=s+2,this.column=n+2,this.makeToken(h,l+u,s,r,n);let c=ln[i];return c?(this.pos=s+1,this.column=n+1,this.makeToken(c,i,s,r,n)):i==="{"?o==="}"?(this.pos=s+2,this.column=n+2,{type:f.WORD,value:"{}",start:s,end:s+2,line:r,column:n,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(s)!==null?this.readWordWithBraceExpansion(s,r,n):this.scanLiteralBraceWord(s)!==null?this.readWordWithBraceExpansion(s,r,n):o!==void 0&&o!==" "&&o!==" "&&o!==`
14
- `?this.readWord(s,r,n):(this.pos=s+1,this.column=n+1,this.makeToken(f.LBRACE,"{",s,r,n)):i==="}"?this.isWordCharFollowing(s+1)?this.readWord(s,r,n):(this.pos=s+1,this.column=n+1,this.makeToken(f.RBRACE,"}",s,r,n)):i==="!"?o==="="?(this.pos=s+2,this.column=n+2,this.makeToken(f.WORD,"!=",s,r,n)):(this.pos=s+1,this.column=n+1,this.makeToken(f.BANG,"!",s,r,n)):this.readWord(s,r,n)}makeToken(e,s,r,n,i){return{type:e,value:s,start:r,end:this.pos,line:n,column:i}}readComment(e,s,r){let n=this.input,i=n.length,o=this.pos;for(;o<i&&n[o]!==`
15
- `;)o++;let a=n.slice(e,o);return this.pos=o,this.column=r+(o-e),{type:f.COMMENT,value:a,start:e,end:o,line:s,column:r}}readWord(e,s,r){let n=this.input,i=n.length,o=this.pos,a=o;for(;o<i;){let p=n[o];if(p===" "||p===" "||p===`
16
- `||p===";"||p==="&"||p==="|"||p==="("||p===")"||p==="<"||p===">"||p==="'"||p==='"'||p==="\\"||p==="$"||p==="`"||p==="{"||p==="}"||p==="~"||p==="*"||p==="?"||p==="[")break;o++}if(o>a){let p=n[o];if(o>=i||p===" "||p===" "||p===`
17
- `||p===";"||p==="&"||p==="|"||p==="("||p===")"||p==="<"||p===">"){let w=n.slice(a,o);if(this.pos=o,this.column=r+(o-a),Xe[w])return{type:Xe[w],value:w,start:e,end:o,line:s,column:r};let g=w.indexOf("=");return g>0&&Br(w.slice(0,g))?{type:f.ASSIGNMENT_WORD,value:w,start:e,end:o,line:s,column:r}:/^[0-9]+$/.test(w)?{type:f.NUMBER,value:w,start:e,end:o,line:s,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(w)?{type:f.NAME,value:w,start:e,end:o,line:s,column:r,quoted:!1,singleQuoted:!1}:{type:f.WORD,value:w,start:e,end:o,line:s,column:r,quoted:!1,singleQuoted:!1}}}o=this.pos;let c=this.column,l=this.line,u="",h=!1,d=!1,m=!1,y=!1,E=n[o]==='"'||n[o]==="'";for(;o<i;){let p=n[o];if(!m&&!y&&(p===" "||p===" "||p===`
18
- `||p===";"||p==="&"||p==="|"||p==="("||p===")"||p==="<"||p===">"))break;if(p==="$"&&o+1<i&&n[o+1]==="'"&&!m&&!y){for(u+="$'",o+=2,c+=2;o<i&&n[o]!=="'";)n[o]==="\\"&&o+1<i?(u+=n[o]+n[o+1],o+=2,c+=2):(u+=n[o],o++,c++);o<i&&(u+="'",o++,c++);continue}if(p==="$"&&o+1<i&&n[o+1]==='"'&&!m&&!y){o++,c++,y=!0,h=!0,u===""&&(E=!0),o++,c++;continue}if(p==="'"&&!y){m?(m=!1,E||(u+=p)):(m=!0,E?(d=!0,h=!0):u+=p),o++,c++;continue}if(p==='"'&&!m){y?(y=!1,E||(u+=p)):(y=!0,E?h=!0:u+=p),o++,c++;continue}if(p==="\\"&&!m&&o+1<i){let w=n[o+1];if(w===`
19
- `){o+=2,l++,c=1;continue}if(y){if(w==='"'||w==="\\"||w==="$"||w==="`"||w===`
20
- `){w==="$"||w==="`"?u+=p+w:u+=w,o+=2,c+=2;continue}}else{w==='"'||w==="'"?u+=p+w:u+=w,o+=2,c+=2;continue}}if(p==="$"&&o+1<i&&n[o+1]==="("){u+=p,o++,c++,u+=n[o],o++,c++;let w=1,g=!1,b=!1,C=0,I=!1,D="",we=n[o]==="(";for(;w>0&&o<i;){let L=n[o];if(u+=L,g)L==="'"&&(g=!1);else if(b)L==="\\"&&o+1<i?(u+=n[o+1],o++,c++):L==='"'&&(b=!1);else if(L==="'")g=!0,D="";else if(L==='"')b=!0,D="";else if(L==="\\"&&o+1<i)u+=n[o+1],o++,c++,D="";else if(L==="#"&&!we&&(D===""||/\s/.test(n[o-1]||""))){for(;o+1<i&&n[o+1]!==`
21
- `;)o++,c++,u+=n[o];D=""}else/[a-zA-Z_]/.test(L)?D+=L:(D==="case"?(C++,I=!1):D==="in"&&C>0?I=!0:D==="esac"&&C>0&&(C--,I=!1),D="",L==="("?o>0&&n[o-1]==="$"?w++:I||w++:L===")"?I?I=!1:w--:L===";"&&C>0&&o+1<i&&n[o+1]===";"&&(I=!0));L===`
22
- `&&(l++,c=0,D=""),o++,c++}continue}if(p==="$"&&o+1<i&&n[o+1]==="["){u+=p,o++,c++,u+=n[o],o++,c++;let w=1;for(;w>0&&o<i;){let g=n[o];u+=g,g==="["?w++:g==="]"?w--:g===`
23
- `&&(l++,c=0),o++,c++}continue}if(p==="$"&&o+1<i&&n[o+1]==="{"){u+=p,o++,c++,u+=n[o],o++,c++;let w=1;for(;w>0&&o<i;){let g=n[o];u+=g,g==="{"?w++:g==="}"?w--:g===`
24
- `&&(l++,c=0),o++,c++}continue}if(p==="$"&&o+1<i){let w=n[o+1];if(w==="#"||w==="?"||w==="$"||w==="!"||w==="@"||w==="*"||w==="-"||w>="0"&&w<="9"){u+=p+w,o+=2,c+=2;continue}}if(p==="`"){for(u+=p,o++,c++;o<i&&n[o]!=="`";){let w=n[o];u+=w,w==="\\"&&o+1<i&&(u+=n[o+1],o++,c++),w===`
25
- `&&(l++,c=0),o++,c++}o<i&&(u+=n[o],o++,c++);continue}u+=p,o++,p===`
26
- `?(l++,c=1):c++}if(this.pos=o,this.column=c,this.line=l,u==="")return{type:f.WORD,value:"",start:e,end:o,line:s,column:r,quoted:h,singleQuoted:d};if(!h&&Xe[u])return{type:Xe[u],value:u,start:e,end:o,line:s,column:r};if(!E){let p=u.indexOf("=");if(p>0&&Br(u.slice(0,p)))return{type:f.ASSIGNMENT_WORD,value:u,start:e,end:o,line:s,column:r,quoted:h,singleQuoted:d}}return/^[0-9]+$/.test(u)?{type:f.NUMBER,value:u,start:e,end:o,line:s,column:r}:un(u)?{type:f.NAME,value:u,start:e,end:o,line:s,column:r,quoted:h,singleQuoted:d}:{type:f.WORD,value:u,start:e,end:o,line:s,column:r,quoted:h,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let e=this.pendingHeredocs.shift();if(!e)break;let s=this.pos,r=this.line,n=this.column,i="";for(;this.pos<this.input.length;){let o=this.pos,a="";for(;this.pos<this.input.length&&this.input[this.pos]!==`
27
- `;)a+=this.input[this.pos],this.pos++,this.column++;if((e.stripTabs?a.replace(/^\t+/,""):a)===e.delimiter){this.pos<this.input.length&&this.input[this.pos]===`
28
- `&&(this.pos++,this.line++,this.column=1);break}i+=a,this.pos<this.input.length&&this.input[this.pos]===`
29
- `&&(i+=`
30
- `,this.pos++,this.line++,this.column=1)}this.tokens.push({type:f.HEREDOC_CONTENT,value:i,start:s,end:this.pos,line:r,column:n})}}addPendingHeredoc(e,s,r){this.pendingHeredocs.push({delimiter:e,stripTabs:s,quoted:r})}registerHeredocFromLookahead(e){let s=this.pos,r=this.column;for(;this.pos<this.input.length&&(this.input[this.pos]===" "||this.input[this.pos]===" ");)this.pos++,this.column++;let n="",i=!1,o=this.input[this.pos];if(o==="'"||o==='"'){i=!0;let a=o;for(this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]!==a;)n+=this.input[this.pos],this.pos++,this.column++}else for(;this.pos<this.input.length&&!/[\s;<>&|()]/.test(this.input[this.pos]);)n+=this.input[this.pos],this.pos++,this.column++;this.pos=s,this.column=r,n&&this.pendingHeredocs.push({delimiter:n,stripTabs:e,quoted:i})}isWordCharFollowing(e){if(e>=this.input.length)return!1;let s=this.input[e];return!(s===" "||s===" "||s===`
31
- `||s===";"||s==="&"||s==="|"||s==="("||s===")"||s==="<"||s===">")}readWordWithBraceExpansion(e,s,r){let n=this.input,i=n.length,o=e,a=r;for(;o<i;){let l=n[o];if(l===" "||l===" "||l===`
32
- `||l===";"||l==="&"||l==="|"||l==="("||l===")"||l==="<"||l===">")break;if(l==="{"){if(this.scanBraceExpansion(o)!==null){let h=1;for(o++,a++;o<i&&h>0;)n[o]==="{"?h++:n[o]==="}"&&h--,o++,a++;continue}o++,a++;continue}if(l==="}"){o++,a++;continue}if(l==="$"&&o+1<i&&n[o+1]==="("){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)n[o]==="("?u++:n[o]===")"&&u--,o++,a++;continue}if(l==="$"&&o+1<i&&n[o+1]==="{"){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)n[o]==="{"?u++:n[o]==="}"&&u--,o++,a++;continue}if(l==="`"){for(o++,a++;o<i&&n[o]!=="`";)n[o]==="\\"&&o+1<i?(o+=2,a+=2):(o++,a++);o<i&&(o++,a++);continue}o++,a++}let c=n.slice(e,o);return this.pos=o,this.column=a,{type:f.WORD,value:c,start:e,end:o,line:s,column:r,quoted:!1,singleQuoted:!1}}scanBraceExpansion(e){let s=this.input,r=s.length,n=e+1,i=1,o=!1,a=!1;for(;n<r&&i>0;){let c=s[n];if(c==="{")i++,n++;else if(c==="}")i--,n++;else if(c===","&&i===1)o=!0,n++;else if(c==="."&&n+1<r&&s[n+1]===".")a=!0,n+=2;else{if(c===" "||c===" "||c===`
33
- `||c===";"||c==="&"||c==="|")return null;n++}}return i===0&&(o||a)?s.slice(e,n):null}scanLiteralBraceWord(e){let s=this.input,r=s.length,n=e+1,i=1;for(;n<r&&i>0;){let o=s[n];if(o==="{")i++,n++;else if(o==="}"){if(i--,i===0)return s.slice(e,n+1);n++}else{if(o===" "||o===" "||o===`
34
- `||o===";"||o==="&"||o==="|")return null;n++}}return null}};var vt=1e6,$t=1e5,Ur=1e6,Gr=new Set([f.LESS,f.GREAT,f.DLESS,f.DGREAT,f.LESSAND,f.GREATAND,f.LESSGREAT,f.DLESSDASH,f.CLOBBER,f.TLESS,f.AND_GREAT,f.AND_DGREAT]),Vr=new Set([f.LESS,f.GREAT,f.DLESS,f.DGREAT,f.LESSAND,f.GREATAND,f.LESSGREAT,f.DLESSDASH,f.CLOBBER,f.TLESS]),ie=class extends Error{line;column;token;constructor(e,s,r,n=void 0){super(`Parse error at ${s}:${r}: ${e}`),this.line=s,this.column=r,this.token=n,this.name="ParseException"}};function jr(t,e,s){let r=s+1;for(;r<e.length&&/[a-zA-Z0-9_-]/.test(e[r]);)r++;return r}function kt(t,e,s,r,n){let i=1,o=s+1;for(;o<e.length&&i>0;)e[o]===r?i++:e[o]===n&&i--,i>0&&o++;return i===0?o:-1}function Ae(t,e,s){let r=s,n=1;for(;r<e.length&&n>0;){let i=e[r];if(i==="\\"&&r+1<e.length){r+=2;continue}if(i==="'"){let o=e.indexOf("'",r+1);if(o!==-1){r=o+1;continue}}if(i==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?r+=2:r++;r<e.length&&r++;continue}i==="{"?n++:i==="}"&&n--,n>0&&r++}return r}function qr(t,e,s){let r=s,n=!1;for(;r<e.length;){let i=e[r];if(i==="/"&&n||i==="}")break;if(i==="'"){let o=e.indexOf("'",r+1);if(o!==-1){r=o+1,n=!0;continue}}if(i==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?r+=2:r++;r<e.length&&r++,n=!0;continue}i==="\\"?(r+=2,n=!0):(r++,n=!0)}return r}function Zr(t,e,s){let r=s,n="";for(;r<e.length;){let i=e[r];if(i==="*"||i==="?")n+=i,r++;else if(i==="["){let o=fn(e,r);o===-1?(n+=i,r++):(n+=e.slice(r,o+1),r=o+1)}else break}return{pattern:n,endIndex:r}}function fn(t,e){let s=e+1;for(s<t.length&&t[s]==="^"&&s++,s<t.length&&t[s]==="]"&&s++;s<t.length;){let r=t[s];if(r==="\\"&&s+1<t.length){s+=2;continue}if(r==="]")return s;if(r==='"'||r==="$"||r==="`")return-1;if(r==="'"){let n=t.indexOf("'",s+1);if(n!==-1){s=n+1;continue}}if(r==="["&&s+1<t.length&&t[s+1]===":"){let n=t.indexOf(":]",s+2);if(n!==-1){s=n+2;continue}}if(r==="["&&s+1<t.length&&(t[s+1]==="."||t[s+1]==="=")){let i=`${t[s+1]}]`,o=t.indexOf(i,s+2);if(o!==-1){s=o+2;continue}}s++}return-1}function Qr(t,e,s){let r="",n=s;for(;n<e.length&&e[n]!=="'";){let i=e[n];if(i==="\\"&&n+1<e.length)switch(e[n+1]){case"n":r+=`
35
- `,n+=2;break;case"t":r+=" ",n+=2;break;case"r":r+="\r",n+=2;break;case"\\":r+="\\",n+=2;break;case"'":r+="'",n+=2;break;case'"':r+='"',n+=2;break;case"a":r+="\x07",n+=2;break;case"b":r+="\b",n+=2;break;case"e":case"E":r+="\x1B",n+=2;break;case"f":r+="\f",n+=2;break;case"v":r+="\v",n+=2;break;case"x":{let a=e.slice(n+2,n+4),c=parseInt(a,16);Number.isNaN(c)?(r+="\\x",n+=2):(r+=String.fromCharCode(c),n+=4);break}case"u":{let a=e.slice(n+2,n+6),c=parseInt(a,16);Number.isNaN(c)?(r+="\\u",n+=2):(r+=String.fromCharCode(c),n+=6);break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let a="",c=n+1;for(;c<e.length&&c<n+4&&/[0-7]/.test(e[c]);)a+=e[c],c++;let l=parseInt(a,8);r+=String.fromCharCode(l),n=c;break}default:r+=i,n++}else r+=i,n++}return n<e.length&&e[n]==="'"&&n++,{part:A.literal(r),endIndex:n}}function It(t,e){let s=e.trim();return s===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:T(t,s)}function Hr(t){let e=[],s="",r=0;for(let n=0;n<t.length;n++){let i=t[n];i==="{"?(r++,s+=i):i==="}"?(r--,s+=i):i===","&&r===0?(e.push(s),s=""):s+=i}return e.push(s),e}function Kr(t,e,s,r){let n=kt(t,e,s,"{","}");if(n===-1)return null;let i=e.slice(s+1,n),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:n+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:n+1}:i.includes(",")&&r?{part:{type:"BraceExpansion",items:Hr(i).map(u=>({type:"Word",word:A.word(r(t,u,!1,!1,!1))}))},endIndex:n+1}:i.includes(",")?{part:{type:"BraceExpansion",items:Hr(i).map(u=>({type:"Word",word:A.word([A.literal(u)])}))},endIndex:n+1}:null}function Xr(t,e){let s="";for(let r of e.parts)switch(r.type){case"Literal":case"SingleQuoted":case"Escaped":s+=r.value;break;case"DoubleQuoted":s+='"';for(let n of r.parts)n.type==="Literal"||n.type==="Escaped"?s+=n.value:n.type==="ParameterExpansion"&&(s+=`\${${n.parameter}}`);s+='"';break;case"ParameterExpansion":s+=`\${${r.parameter}}`;break;case"Glob":s+=r.pattern;break;default:s+=r.type}return s}function Yr(t,e){return{[f.LESS]:"<",[f.GREAT]:">",[f.DGREAT]:">>",[f.LESSAND]:"<&",[f.GREATAND]:">&",[f.LESSGREAT]:"<>",[f.CLOBBER]:">|",[f.TLESS]:"<<<",[f.AND_GREAT]:"&>",[f.AND_DGREAT]:"&>>",[f.DLESS]:"<",[f.DLESSDASH]:"<"}[e]||">"}function Je(t){let e=t.current(),s=e.type;if(s===f.NUMBER){let r=t.peek(1);return e.end!==r.start?!1:Vr.has(r.type)}return Gr.has(s)}function et(t){let e=null;t.check(f.NUMBER)&&(e=Number.parseInt(t.advance().value,10));let s=t.advance(),r=Yr(t,s.type);if(s.type===f.DLESS||s.type===f.DLESSDASH)return hn(t,r,e,s.type===f.DLESSDASH);t.isWord()||t.error("Expected redirection target");let n=t.parseWord();return A.redirection(r,n,e)}function hn(t,e,s,r){t.isWord()||t.error("Expected here-document delimiter");let n=t.advance(),i=n.value,o=n.quoted||!1;(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1));let a=A.redirection(r?"<<-":"<<",A.hereDoc(i,A.word([]),r,o),s);return t.addPendingHeredoc(a,i,r,o),a}function es(t){let e=t.current().line,s=[],r=null,n=[],i=[];for(;t.check(f.ASSIGNMENT_WORD);)t.checkIterationLimit(),s.push(dn(t));for(;Je(t);)t.checkIterationLimit(),i.push(et(t));for(t.isWord()&&(r=t.parseWord());(!t.isStatementEnd()||t.check(f.RBRACE))&&!t.check(f.PIPE,f.PIPE_AMP);)if(t.checkIterationLimit(),Je(t))i.push(et(t));else if(t.check(f.RBRACE)){let a=t.advance();n.push(t.parseWordFromString(a.value,!1,!1))}else if(t.isWord())n.push(t.parseWord());else if(t.check(f.ASSIGNMENT_WORD)){let a=t.advance(),c=a.value,l=c.endsWith("="),u=c.endsWith("=(");if((l||u)&&(u||t.check(f.LPAREN))){let h=u?c.slice(0,-2):c.slice(0,-1);u||t.expect(f.LPAREN);let d=Rt(t);t.expect(f.RPAREN);let m=d.map(E=>Xr(t,E)),y=`${h}=(${m.join(" ")})`;n.push(t.parseWordFromString(y,!1,!1))}else n.push(t.parseWordFromString(c,a.quoted,a.singleQuoted))}else if(t.check(f.LPAREN))t.error("syntax error near unexpected token `('");else break;let o=A.simpleCommand(r,n,s,i);return o.line=e,o}function dn(t){let e=t.expect(f.ASSIGNMENT_WORD),s=e.value,r=s.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||t.error(`Invalid assignment: ${s}`);let n=r[0],i,o=n.length;if(s[o]==="["){let h=0,d=o+1;for(;o<s.length;o++)if(s[o]==="[")h++;else if(s[o]==="]"&&(h--,h===0))break;h!==0&&t.error(`Invalid assignment: ${s}`),i=s.slice(d,o),o++}let a=s[o]==="+";a&&o++,s[o]!=="="&&t.error(`Invalid assignment: ${s}`),o++;let c=s.slice(o);if(c==="("){let h=Rt(t);t.expect(f.RPAREN);let d=i!==void 0?`${n}[${i}]`:n;return A.assignment(d,null,a,h)}if(c===""&&t.check(f.LPAREN)){let h=t.current();if(e.end===h.start){t.advance();let d=Rt(t);t.expect(f.RPAREN);let m=i!==void 0?`${n}[${i}]`:n;return A.assignment(m,null,a,d)}}let l=c?t.parseWordFromString(c,e.quoted,e.singleQuoted,!0):null,u=i!==void 0?`${n}[${i}]`:n;return A.assignment(u,l,a,null)}function Rt(t){let e=[];for(t.skipNewlines();!t.check(f.RPAREN,f.EOF);)t.checkIterationLimit(),t.isWord()?e.push(t.parseWord()):t.advance(),t.skipNewlines();return e}function Dt(t){t.expect(f.IF);let e=[],s=t.parseCompoundList();t.expect(f.THEN);let r=t.parseCompoundList();if(r.length===0){let o=t.check(f.FI)?"fi":t.check(f.ELSE)?"else":t.check(f.ELIF)?"elif":"fi";t.error(`syntax error near unexpected token \`${o}'`)}for(e.push({condition:s,body:r});t.check(f.ELIF);){t.advance();let o=t.parseCompoundList();t.expect(f.THEN);let a=t.parseCompoundList();if(a.length===0){let c=t.check(f.FI)?"fi":t.check(f.ELSE)?"else":t.check(f.ELIF)?"elif":"fi";t.error(`syntax error near unexpected token \`${c}'`)}e.push({condition:o,body:a})}let n=null;t.check(f.ELSE)&&(t.advance(),n=t.parseCompoundList(),n.length===0&&t.error("syntax error near unexpected token `fi'")),t.expect(f.FI);let i=t.parseOptionalRedirections();return A.ifNode(e,n,i)}function Ot(t){if(t.expect(f.FOR),t.check(f.DPAREN_START))return pn(t);t.isWord()||t.error("Expected variable name in for loop");let s=t.advance().value,r=null;if(t.skipNewlines(),t.check(f.IN))for(t.advance(),r=[];!t.check(f.SEMICOLON,f.NEWLINE,f.DO,f.EOF)&&t.isWord();)r.push(t.parseWord());t.check(f.SEMICOLON)&&t.advance(),t.skipNewlines(),t.expect(f.DO);let n=t.parseCompoundList();t.expect(f.DONE);let i=t.parseOptionalRedirections();return A.forNode(s,r,n,i)}function pn(t){t.expect(f.DPAREN_START);let e=null,s=null,r=null,n=["","",""],i=0,o=0;for(;!t.check(f.DPAREN_END,f.EOF);){let l=t.advance();if(l.type===f.SEMICOLON&&o===0){if(i++,i>2)break}else l.value==="("&&o++,l.value===")"&&o--,n[i]+=l.value}t.expect(f.DPAREN_END),n[0].trim()&&(e=T(t,n[0].trim())),n[1].trim()&&(s=T(t,n[1].trim())),n[2].trim()&&(r=T(t,n[2].trim())),t.skipNewlines(),t.check(f.SEMICOLON)&&t.advance(),t.skipNewlines(),t.expect(f.DO);let a=t.parseCompoundList();t.expect(f.DONE);let c=t.parseOptionalRedirections();return{type:"CStyleFor",init:e,condition:s,update:r,body:a,redirections:c}}function _t(t){t.expect(f.WHILE);let e=t.parseCompoundList();t.expect(f.DO);let s=t.parseCompoundList();s.length===0&&t.error("syntax error near unexpected token `done'"),t.expect(f.DONE);let r=t.parseOptionalRedirections();return A.whileNode(e,s,r)}function Lt(t){t.expect(f.UNTIL);let e=t.parseCompoundList();t.expect(f.DO);let s=t.parseCompoundList();s.length===0&&t.error("syntax error near unexpected token `done'"),t.expect(f.DONE);let r=t.parseOptionalRedirections();return A.untilNode(e,s,r)}function Tt(t){t.expect(f.CASE),t.isWord()||t.error("Expected word after 'case'");let e=t.parseWord();t.skipNewlines(),t.expect(f.IN),t.skipNewlines();let s=[];for(;!t.check(f.ESAC,f.EOF);){t.checkIterationLimit();let n=t.getPos(),i=yn(t);if(i&&s.push(i),t.skipNewlines(),t.getPos()===n&&!i)break}t.expect(f.ESAC);let r=t.parseOptionalRedirections();return A.caseNode(e,s,r)}function yn(t){t.check(f.LPAREN)&&t.advance();let e=[];for(;t.isWord()&&(e.push(t.parseWord()),t.check(f.PIPE));)t.advance();if(e.length===0)return null;t.expect(f.RPAREN),t.skipNewlines();let s=[];for(;!t.check(f.DSEMI,f.SEMI_AND,f.SEMI_SEMI_AND,f.ESAC,f.EOF);){t.checkIterationLimit(),t.isWord()&&t.peek(1).type===f.RPAREN&&t.error("syntax error near unexpected token `)'"),t.check(f.LPAREN)&&t.peek(1).type===f.WORD&&t.error(`syntax error near unexpected token \`${t.peek(1).value}'`);let n=t.getPos(),i=t.parseStatement();if(i&&s.push(i),t.skipSeparators(!1),t.getPos()===n&&!i)break}let r=";;";return t.check(f.DSEMI)?(t.advance(),r=";;"):t.check(f.SEMI_AND)?(t.advance(),r=";&"):t.check(f.SEMI_SEMI_AND)&&(t.advance(),r=";;&"),A.caseItem(e,s,r)}function Ft(t){t.peek(1).type,f.LPAREN,t.expect(f.LPAREN),t.check(f.LPAREN)&&t.advance();let e=t.parseCompoundList();t.expect(f.RPAREN);let s=t.parseOptionalRedirections();return A.subshell(e,s)}function Wt(t){t.expect(f.LBRACE);let e=t.parseCompoundList();t.expect(f.RBRACE);let s=t.parseOptionalRedirections();return A.group(e,s)}var En=["-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"],gn=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function zt(t){return t.skipNewlines(),An(t)}function An(t){let e=ts(t);for(t.skipNewlines();t.check(f.OR_OR);){t.advance(),t.skipNewlines();let s=ts(t);e={type:"CondOr",left:e,right:s},t.skipNewlines()}return e}function ts(t){let e=Mt(t);for(t.skipNewlines();t.check(f.AND_AND);){t.advance(),t.skipNewlines();let s=Mt(t);e={type:"CondAnd",left:e,right:s},t.skipNewlines()}return e}function Mt(t){return t.skipNewlines(),t.check(f.BANG)?(t.advance(),t.skipNewlines(),{type:"CondNot",operand:Mt(t)}):Sn(t)}function Sn(t){if(t.check(f.LPAREN)){t.advance();let e=zt(t);return t.expect(f.RPAREN),{type:"CondGroup",expression:e}}if(t.isWord()){let e=t.current(),s=e.value;if(En.includes(s)&&!e.quoted&&(t.advance(),t.check(f.DBRACK_END)&&t.error(`Expected operand after ${s}`),t.isWord())){let n=t.parseWord();return{type:"CondUnary",operator:s,operand:n}}let r=t.parseWord();if(t.isWord()&&gn.includes(t.current().value)){let n=t.advance().value,i=t.parseWord();return{type:"CondBinary",operator:n,left:r,right:i}}if(t.check(f.LESS)){t.advance();let n=t.parseWord();return{type:"CondBinary",operator:"<",left:r,right:n}}if(t.check(f.GREAT)){t.advance();let n=t.parseWord();return{type:"CondBinary",operator:">",left:r,right:n}}if(t.isWord()&&t.current().value==="="){t.advance();let n=t.parseWord();return{type:"CondBinary",operator:"==",left:r,right:n}}return{type:"CondWord",word:r}}t.error("Expected conditional expression")}function bn(t,e,s){let r=s+1,n=e[r];if("@*#?$!-0123456789".includes(n))return{part:A.parameterExpansion(n),endIndex:r+1};let i="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)i+=e[r],r++;return{part:A.parameterExpansion(i),endIndex:r}}function Cn(t,e,s,r=!1){let n=s+2,i=!1;e[n]==="!"&&(i=!0,n++);let o=!1;e[n]==="#"&&!/[}:#%/^,]/.test(e[n+1]||"}")&&(o=!0,n++);let a="",c=e[n];if(/[@*#?$!-]/.test(c)&&!/[a-zA-Z0-9_]/.test(e[n+1]||""))a=c,n++;else for(;n<e.length&&/[a-zA-Z0-9_]/.test(e[n]);)a+=e[n],n++;if(e[n]==="["){let u=kt(t,e,n,"[","]");a+=e.slice(n,u+1),n=u+1}a===""&&!i&&!o&&e[n]!=="}"&&t.error(`\${${e[n]}}: bad substitution`);let l=null;if(i){let u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)l={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="";else if(e[n]==="*"||e[n]==="@"){let h=e[n];n++,l={type:"VarNamePrefix",prefix:a,star:h==="*"},a=""}else l={type:"Indirection"}}else if(o)if(e[n]===":")for(l={type:"LengthSliceError"};n<e.length&&e[n]!=="}";)n++;else e[n]!=="}"&&/[-+=?]/.test(e[n])?t.error(`\${#${a}${e.slice(n,e.indexOf("}",n))}}: bad substitution`):l={type:"Length"};if(!l&&n<e.length&&e[n]!=="}"){let u=Nn(t,e,n,a,r);l=u.operation,n=u.endIndex}if(n<e.length&&e[n]!=="}"){let u=e[n];if(!/[:\-+=?#%/^,@[]/.test(u)){let h=n;for(;h<e.length&&e[h]!=="}";)h++;let d=e.slice(s,h+1);t.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;n<e.length&&e[n]!=="}";)n++;return{part:A.parameterExpansion(a,l),endIndex:n+1}}function Nn(t,e,s,r,n=!1){let i=s,o=e[i],a=e[i+1]||"";if(o===":"){let c=a;if("-=?+".includes(c)){i+=2;let w=Ae(t,e,i),g=e.slice(i,w),b=fe(t,g,!1,!1,!0,!1,n),C=A.word(b.length>0?b:[A.literal("")]);if(c==="-")return{operation:{type:"DefaultValue",word:C,checkEmpty:!0},endIndex:w};if(c==="=")return{operation:{type:"AssignDefault",word:C,checkEmpty:!0},endIndex:w};if(c==="?")return{operation:{type:"ErrorIfUnset",word:C,checkEmpty:!0},endIndex:w};if(c==="+")return{operation:{type:"UseAlternative",word:C,checkEmpty:!0},endIndex:w}}i++;let l=Ae(t,e,i),u=e.slice(i,l),h=-1,d=0,m=0;for(let p=0;p<u.length;p++){let w=u[p];if(w==="("||w==="[")d++;else if(w===")"||w==="]")d--;else if(w==="?"&&d===0)m++;else if(w===":"&&d===0)if(m>0)m--;else{h=p;break}}let y=h>=0?u.slice(0,h):u,E=h>=0?u.slice(h+1):null;return{operation:{type:"Substring",offset:It(t,y),length:E?It(t,E):null},endIndex:l}}if("-=?+".includes(o)){i++;let c=Ae(t,e,i),l=e.slice(i,c),u=fe(t,l,!1,!1,!0,!1,n),h=A.word(u.length>0?u:[A.literal("")]);if(o==="-")return{operation:{type:"DefaultValue",word:h,checkEmpty:!1},endIndex:c};if(o==="=")return{operation:{type:"AssignDefault",word:h,checkEmpty:!1},endIndex:c};if(o==="?")return{operation:{type:"ErrorIfUnset",word:l?h:null,checkEmpty:!1},endIndex:c};if(o==="+")return{operation:{type:"UseAlternative",word:h,checkEmpty:!1},endIndex:c}}if(o==="#"||o==="%"){let c=a===o,l=o==="#"?"prefix":"suffix";i+=c?2:1;let u=Ae(t,e,i),h=e.slice(i,u),d=fe(t,h,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:A.word(d.length>0?d:[A.literal("")]),side:l,greedy:c},endIndex:u}}if(o==="/"){let c=a==="/";i+=c?2:1;let l=null;e[i]==="#"?(l="start",i++):e[i]==="%"&&(l="end",i++);let u=qr(t,e,i),h=e.slice(i,u),d=fe(t,h,!1,!1,!1),m=A.word(d.length>0?d:[A.literal("")]),y=null,E=u;if(e[u]==="/"){let p=u+1,w=Ae(t,e,p),g=e.slice(p,w),b=fe(t,g,!1,!1,!1);y=A.word(b.length>0?b:[A.literal("")]),E=w}return{operation:{type:"PatternReplacement",pattern:m,replacement:y,all:c,anchor:l},endIndex:E}}if(o==="^"||o===","){let c=a===o,l=o==="^"?"upper":"lower";i+=c?2:1;let u=Ae(t,e,i),h=e.slice(i,u),d=h?A.word([A.literal(h)]):null;return{operation:{type:"CaseModification",direction:l,all:c,pattern:d},endIndex:u}}return o==="@"&&/[QPaAEK]/.test(a)?{operation:{type:"Transform",operator:a},endIndex:i+2}:{operation:null,endIndex:i}}function Bt(t,e,s,r=!1){let n=s+1;if(n>=e.length)return{part:A.literal("$"),endIndex:n};let i=e[n];if(i==="("&&e[n+1]==="(")return t.parseArithmeticExpansion(e,s);if(i==="["){let o=1,a=n+1;for(;a<e.length&&o>0;)e[a]==="["?o++:e[a]==="]"&&o--,o>0&&a++;if(o===0){let c=e.slice(n+1,a),l=T(t,c);return{part:A.arithmeticExpansion(l),endIndex:a+1}}}return i==="("?t.parseCommandSubstitution(e,s):i==="{"?Cn(t,e,s,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?bn(t,e,s):{part:A.literal("$"),endIndex:n}}function Pn(t,e){let s=[],r=0,n="",i=()=>{n&&(s.push(A.literal(n)),n="")};for(;r<e.length;){let o=e[r];if(o==="\\"&&r+1<e.length){let a=e[r+1];if(a==="$"||a==="`"){n+=a,r+=2;continue}n+=o,r++;continue}if(o==="$"){i();let{part:a,endIndex:c}=Bt(t,e,r,!0);a&&s.push(a),r=c;continue}if(o==="`"){i();let{part:a,endIndex:c}=t.parseBacktickSubstitution(e,r,!0);s.push(a),r=c;continue}n+=o,r++}return i(),s}function vn(t,e,s){let r=[],n=s,i="",o=()=>{i&&(r.push(A.literal(i)),i="")};for(;n<e.length&&e[n]!=='"';){let a=e[n];if(a==="\\"&&n+1<e.length){let c=e[n+1];if('"\\$`\n'.includes(c)){i+=c,n+=2;continue}i+=a,n++;continue}if(a==="$"){o();let{part:c,endIndex:l}=Bt(t,e,n,!0);c&&r.push(c),n=l;continue}if(a==="`"){o();let{part:c,endIndex:l}=t.parseBacktickSubstitution(e,n,!0);r.push(c),n=l;continue}i+=a,n++}return o(),{part:A.doubleQuoted(r),endIndex:n}}function fe(t,e,s=!1,r=!1,n=!1,i=!1,o=!1){if(r)return[A.singleQuoted(e)];if(s){let h=Pn(t,e);return[A.doubleQuoted(h)]}let a=[],c=0,l="",u=()=>{l&&(a.push(A.literal(l)),l="")};for(;c<e.length;){let h=e[c];if(h==="\\"&&c+1<e.length){let d=e[c+1];(i?d==="$"||d==="`"||d==="\\"||d===`
36
- `:d==="$"||d==="`"||d==="\\"||d==='"'||d===`
37
- `)?l+=d:l+=`\\${d}`,c+=2;continue}if(h==="'"&&!o&&!i){u();let d=e.indexOf("'",c+1);if(d===-1){l+=e.slice(c);break}a.push(A.singleQuoted(e.slice(c+1,d))),c=d+1;continue}if(h==='"'&&!i){u();let{part:d,endIndex:m}=vn(t,e,c+1);a.push(d),c=m+1;continue}if(h==="$"&&e[c+1]==="'"){u();let{part:d,endIndex:m}=Qr(t,e,c+2);a.push(d),c=m;continue}if(h==="$"){u();let{part:d,endIndex:m}=Bt(t,e,c);d&&a.push(d),c=m;continue}if(h==="`"){u();let{part:d,endIndex:m}=t.parseBacktickSubstitution(e,c);a.push(d),c=m;continue}if(h==="~"){let d=c>0?e[c-1]:"";if(c===0||d==="="||n&&d===":"){let y=jr(t,e,c),E=e[y];if(E===void 0||E==="/"||E===":"){u();let p=e.slice(c+1,y)||null;a.push({type:"TildeExpansion",user:p}),c=y;continue}}}if(h==="*"||h==="?"||h==="["){u();let{pattern:d,endIndex:m}=Zr(t,e,c);a.push({type:"Glob",pattern:d}),c=m;continue}if(h==="{"&&!n){let d=Kr(t,e,c,fe);if(d){u(),a.push(d.part),c=d.endIndex;continue}}l+=h,c++}return u(),a}var z=class t{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;checkIterationLimit(){if(this.parseIterations++,this.parseIterations>Ur)throw new ie("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}parse(e){if(e.length>vt)throw new ie(`Input too large: ${e.length} bytes exceeds limit of ${vt}`,1,1);let s=new Ye(e);if(this.tokens=s.tokenize(),this.tokens.length>$t)throw new ie(`Too many tokens: ${this.tokens.length} exceeds limit of ${$t}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseScript()}parseTokens(e){return this.tokens=e,this.pos=0,this.pendingHeredocs=[],this.parseScript()}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(e=0){return this.tokens[this.pos+e]||this.tokens[this.tokens.length-1]}advance(){let e=this.current();return this.pos<this.tokens.length-1&&this.pos++,e}getPos(){return this.pos}check(e,s,r,n,...i){let o=this.tokens[this.pos]?.type;return o===e||s!==void 0&&o===s||r!==void 0&&o===r||n!==void 0&&o===n?!0:i.length>0?i.includes(o):!1}expect(e,s){if(this.check(e))return this.advance();let r=this.current();throw new ie(s||`Expected ${e}, got ${r.type}`,r.line,r.column,r)}error(e){let s=this.current();throw new ie(e,s.line,s.column,s)}skipNewlines(){for(;this.check(f.NEWLINE,f.COMMENT);)this.check(f.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(e=!0){for(;;){if(this.check(f.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(f.SEMICOLON,f.COMMENT)){this.advance();continue}if(e&&this.check(f.DSEMI,f.SEMI_AND,f.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(e,s,r,n){this.pendingHeredocs.push({redirect:e,delimiter:s,stripTabs:r,quoted:n})}processHeredocs(){for(let e of this.pendingHeredocs)if(this.check(f.HEREDOC_CONTENT)){let s=this.advance(),r;e.quoted?r=A.word([A.literal(s.value)]):r=this.parseWordFromString(s.value,!1,!1,!1,!0),e.redirect.target=A.hereDoc(e.delimiter,r,e.stripTabs,e.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(f.EOF,f.NEWLINE,f.SEMICOLON,f.AMP,f.AND_AND,f.OR_OR,f.RPAREN,f.RBRACE,f.DSEMI,f.SEMI_AND,f.SEMI_SEMI_AND)}isCommandStart(){let e=this.current().type;return e===f.WORD||e===f.NAME||e===f.NUMBER||e===f.ASSIGNMENT_WORD||e===f.IF||e===f.FOR||e===f.WHILE||e===f.UNTIL||e===f.CASE||e===f.LPAREN||e===f.LBRACE||e===f.DPAREN_START||e===f.DBRACK_START||e===f.FUNCTION||e===f.BANG||e===f.IN||e===f.LESS||e===f.GREAT||e===f.DLESS||e===f.DGREAT||e===f.LESSAND||e===f.GREATAND||e===f.LESSGREAT||e===f.DLESSDASH||e===f.CLOBBER||e===f.TLESS||e===f.AND_GREAT||e===f.AND_DGREAT}parseScript(){let e=[],r=0;for(this.skipNewlines();!this.check(f.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)"),this.checkUnexpectedToken();let n=this.pos,i=this.parseStatement();i&&e.push(i),this.skipSeparators(!1),this.check(f.DSEMI,f.SEMI_AND,f.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===n&&!this.check(f.EOF)&&this.advance()}return A.script(e)}checkUnexpectedToken(){let e=this.current().type,s=this.current().value;(e===f.DO||e===f.DONE||e===f.THEN||e===f.ELSE||e===f.ELIF||e===f.FI||e===f.ESAC)&&this.error(`syntax error near unexpected token \`${s}'`),(e===f.RBRACE||e===f.RPAREN)&&this.error(`syntax error near unexpected token \`${s}'`),(e===f.DSEMI||e===f.SEMI_AND||e===f.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${s}'`),e===f.SEMICOLON&&this.error(`syntax error near unexpected token \`${s}'`)}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let e=[],s=[],r=!1,n=this.parsePipeline();for(e.push(n);this.check(f.AND_AND,f.OR_OR);){let i=this.advance();s.push(i.type===f.AND_AND?"&&":"||"),this.skipNewlines();let o=this.parsePipeline();e.push(o)}return this.check(f.AMP)&&(this.advance(),r=!0),A.statement(e,s,r)}parsePipeline(){let e=0;for(;this.check(f.BANG);)this.advance(),e++;let s=e%2===1,r=[],n=this.parseCommand();for(r.push(n);this.check(f.PIPE,f.PIPE_AMP);){let i=this.advance();this.skipNewlines();let o=this.parseCommand();i.type===f.PIPE_AMP&&o.type==="SimpleCommand"&&o.redirections.unshift(A.redirection(">&",A.word([A.literal("1")]),2)),r.push(o)}return A.pipeline(r,s)}parseCommand(){return this.check(f.IF)?Dt(this):this.check(f.FOR)?Ot(this):this.check(f.WHILE)?_t(this):this.check(f.UNTIL)?Lt(this):this.check(f.CASE)?Tt(this):this.check(f.LPAREN)?Ft(this):this.check(f.LBRACE)?Wt(this):this.check(f.DPAREN_START)?this.parseArithmeticCommand():this.check(f.DBRACK_START)?this.parseConditionalCommand():this.check(f.FUNCTION)?this.parseFunctionDef():this.check(f.NAME,f.WORD)&&this.peek(1).type===f.LPAREN&&this.peek(2).type===f.RPAREN?this.parseFunctionDef():es(this)}isWord(){let e=this.current().type;return e===f.WORD||e===f.NAME||e===f.NUMBER||e===f.IF||e===f.FOR||e===f.WHILE||e===f.UNTIL||e===f.CASE||e===f.FUNCTION||e===f.ELSE||e===f.ELIF||e===f.FI||e===f.THEN||e===f.DO||e===f.DONE||e===f.ESAC||e===f.IN||e===f.SELECT||e===f.TIME||e===f.COPROC||e===f.BANG}parseWord(){let e=this.advance();return this.parseWordFromString(e.value,e.quoted,e.singleQuoted)}parseWordFromString(e,s=!1,r=!1,n=!1,i=!1){let o=fe(this,e,s,r,n,i);return A.word(o)}parseCommandSubstitution(e,s){let r=s+2,n=1,i=r,o=!1,a=!1,c=0,l=!1,u="";for(;i<e.length&&n>0;){let y=e[i];o?y==="'"&&(o=!1):a?y==="\\"&&i+1<e.length?i++:y==='"'&&(a=!1):y==="'"?(o=!0,u=""):y==='"'?(a=!0,u=""):y==="\\"&&i+1<e.length?(i++,u=""):/[a-zA-Z_]/.test(y)?u+=y:(u==="case"?(c++,l=!1):u==="in"&&c>0?l=!0:u==="esac"&&c>0&&(c--,l=!1),u="",y==="("?i>0&&e[i-1]==="$"?n++:l||n++:y===")"?l?l=!1:n--:y===";"&&c>0&&i+1<e.length&&e[i+1]===";"&&(l=!0)),n>0&&i++}n>0&&this.error("unexpected EOF while looking for matching `)'");let h=e.slice(r,i),m=new t().parse(h);return{part:A.commandSubstitution(m,!1),endIndex:i+1}}parseBacktickSubstitution(e,s,r=!1){let i=s+1,o="";for(;i<e.length&&e[i]!=="`";)if(e[i]==="\\"){let l=e[i+1];l==="$"||l==="`"||l==="\\"||l===`
38
- `||r&&l==='"'?(l!==`
39
- `&&(o+=l),i+=2):(o+=e[i],i++)}else o+=e[i],i++;i>=e.length&&this.error("unexpected EOF while looking for matching ``'");let c=new t().parse(o);return{part:A.commandSubstitution(c,!0),endIndex:i+1}}parseArithmeticExpansion(e,s){let r=s+3,n=1,i=0,o=r;for(;o<e.length-1&&n>0;)e[o]==="$"&&e[o+1]==="("?e[o+2]==="("?(n++,o+=3):(i++,o+=2):e[o]==="("&&e[o+1]==="("?(n++,o+=2):e[o]===")"&&e[o+1]===")"?i>0?(i--,o++):(n--,n>0&&(o+=2)):e[o]==="("?(i++,o++):(e[o]===")"&&i>0&&i--,o++);let a=e.slice(r,o),c=this.parseArithmeticExpression(a);return{part:A.arithmeticExpansion(c),endIndex:o+2}}parseArithmeticCommand(){this.expect(f.DPAREN_START);let e="",s=1,r=0,n=!1,i=!1;for(;s>0&&!this.check(f.EOF);){if(n){if(n=!1,r>0){r--,e+=")";continue}if(this.check(f.RPAREN)){s--,i=!0,this.advance();continue}if(this.check(f.DPAREN_END)){s--,i=!0;continue}e+=")";continue}this.check(f.DPAREN_START)?(s++,e+="((",this.advance()):this.check(f.DPAREN_END)?r>=2?(r-=2,e+="))",this.advance()):r===1?(r--,e+=")",n=!0,this.advance()):(s--,i=!0,s>0&&(e+="))"),this.advance()):this.check(f.LPAREN)?(r++,e+="(",this.advance()):this.check(f.RPAREN)?(r>0&&r--,e+=")",this.advance()):(e+=this.current().value,this.advance())}i||this.expect(f.DPAREN_END);let o=this.parseArithmeticExpression(e.trim()),a=this.parseOptionalRedirections();return A.arithmeticCommand(o,a)}parseConditionalCommand(){this.expect(f.DBRACK_START);let e=zt(this);this.expect(f.DBRACK_END);let s=this.parseOptionalRedirections();return A.conditionalCommand(e,s)}parseFunctionDef(){let e;this.check(f.FUNCTION)?(this.advance(),e=this.expect(f.NAME,"Expected function name").value,this.check(f.LPAREN)&&(this.advance(),this.expect(f.RPAREN))):(e=this.advance().value,this.expect(f.LPAREN),this.expect(f.RPAREN)),this.skipNewlines();let s=this.parseCompoundCommandBody(),r=this.parseOptionalRedirections();return A.functionDef(e,s,r)}parseCompoundCommandBody(){if(this.check(f.LBRACE))return Wt(this);if(this.check(f.LPAREN))return Ft(this);if(this.check(f.IF))return Dt(this);if(this.check(f.FOR))return Ot(this);if(this.check(f.WHILE))return _t(this);if(this.check(f.UNTIL))return Lt(this);if(this.check(f.CASE))return Tt(this);this.error("Expected compound command for function body")}parseCompoundList(){let e=[];for(this.skipNewlines();!this.check(f.EOF,f.FI,f.ELSE,f.ELIF,f.THEN,f.DO,f.DONE,f.ESAC,f.RPAREN,f.RBRACE,f.DSEMI,f.SEMI_AND,f.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let s=this.pos,r=this.parseStatement();if(r&&e.push(r),this.skipSeparators(),this.pos===s&&!r)break}return e}parseOptionalRedirections(){let e=[];for(;Je(this);){this.checkIterationLimit();let s=this.pos;if(e.push(et(this)),this.pos===s)break}return e}parseArithmeticExpression(e){return T(this,e)}};function he(t){return new z().parse(t)}var ve=class{fs;cwd;constructor(e,s){this.fs=e,this.cwd=s}isGlobPattern(e){return e.includes("*")||e.includes("?")||/\[.*\]/.test(e)}async expandArgs(e,s){let r=e.map((o,a)=>(s?.[a]??!1)||!this.isGlobPattern(o)?null:this.expand(o)),n=await Promise.all(r.map(o=>o||Promise.resolve(null))),i=[];for(let o=0;o<e.length;o++){let a=n[o];a===null?i.push(e[o]):a.length>0?i.push(...a):i.push(e[o])}return i}async expand(e){return e.includes("**")?this.expandRecursive(e):this.expandSimple(e)}hasGlobChars(e){return e.includes("*")||e.includes("?")||/\[.*\]/.test(e)}async expandSimple(e){let s=e.startsWith("/"),r=e.split("/").filter(l=>l!==""),n=-1;for(let l=0;l<r.length;l++)if(this.hasGlobChars(r[l])){n=l;break}if(n===-1)return[e];let i,o;if(n===0)s?(i="/",o="/"):(i=this.cwd,o="");else{let l=r.slice(0,n);s?(i=`/${l.join("/")}`,o=`/${l.join("/")}`):(i=this.fs.resolvePath(this.cwd,l.join("/")),o=l.join("/"))}let a=r.slice(n);return(await this.expandSegments(i,o,a)).sort()}async expandSegments(e,s,r){if(r.length===0)return[s];let[n,...i]=r,o=[];try{if(this.fs.readdirWithFileTypes){let a=await this.fs.readdirWithFileTypes(e),c=[];for(let u of a)if(!(u.name.startsWith(".")&&!n.startsWith("."))&&this.matchPattern(u.name,n)){let h=e==="/"?`/${u.name}`:`${e}/${u.name}`,d;s===""?d=u.name:s==="/"?d=`/${u.name}`:d=`${s}/${u.name}`,i.length===0?c.push(Promise.resolve([d])):u.isDirectory&&c.push(this.expandSegments(h,d,i))}let l=await Promise.all(c);for(let u of l)o.push(...u)}else{let a=await this.fs.readdir(e),c=[];for(let u of a)if(!(u.startsWith(".")&&!n.startsWith("."))&&this.matchPattern(u,n)){let h=e==="/"?`/${u}`:`${e}/${u}`,d;s===""?d=u:s==="/"?d=`/${u}`:d=`${s}/${u}`,i.length===0?c.push(Promise.resolve([d])):c.push((async()=>{try{if((await this.fs.stat(h)).isDirectory)return this.expandSegments(h,d,i)}catch{}return[]})())}let l=await Promise.all(c);for(let u of l)o.push(...u)}}catch{}return o}async expandRecursive(e){let s=[],r=e.indexOf("**"),n=e.slice(0,r).replace(/\/$/,"")||".",o=e.slice(r+2).replace(/^\//,"");return await this.walkDirectory(n,o,s),s.sort()}async walkDirectory(e,s,r){let n=this.fs.resolvePath(this.cwd,e);try{if(this.fs.readdirWithFileTypes){let i=await this.fs.readdirWithFileTypes(n),o=[],a=[];for(let c of i){let l=e==="."?c.name:`${e}/${c.name}`;c.isDirectory?a.push(l):s&&this.matchPattern(c.name,s)&&o.push(l)}r.push(...o);for(let c=0;c<a.length;c+=100){let l=a.slice(c,c+100);await Promise.all(l.map(u=>this.walkDirectory(u,s,r)))}}else{let i=await this.fs.readdir(n),o=[];for(let c=0;c<i.length;c+=100){let l=i.slice(c,c+100),u=await Promise.all(l.map(async h=>{let d=e==="."?h:`${e}/${h}`,m=this.fs.resolvePath(this.cwd,d);try{let y=await this.fs.stat(m);return{name:h,path:d,isDirectory:y.isDirectory}}catch{return null}}));o.push(...u.filter(h=>h!==null))}for(let c of o)!c.isDirectory&&s&&this.matchPattern(c.name,s)&&r.push(c.path);let a=o.filter(c=>c.isDirectory);for(let c=0;c<a.length;c+=100){let l=a.slice(c,c+100);await Promise.all(l.map(u=>this.walkDirectory(u.path,s,r)))}}}catch{}}matchPattern(e,s){return this.patternToRegex(s).test(e)}patternToRegex(e){let s="^";for(let r=0;r<e.length;r++){let n=e[r];if(n==="*")s+=".*";else if(n==="?")s+=".";else if(n==="["){let i=r+1,o="[";for(i<e.length&&(e[i]==="^"||e[i]==="!")&&(o+="^",i++),i<e.length&&e[i]==="]"&&(o+="\\]",i++);i<e.length&&e[i]!=="]";){if(e[i]==="["&&i+1<e.length&&e[i+1]===":"){let a=e.indexOf(":]",i+2);if(a!==-1){let c=e.slice(i+2,a),l=this.posixClassToRegex(c);o+=l,i=a+2;continue}}if(e[i]==="\\"&&i+1<e.length){o+=`\\${e[i+1]}`,i+=2;continue}e[i]==="-"?o+="\\-":o+=e[i],i++}o+="]",s+=o,r=i}else if(n==="\\"&&r+1<e.length){let i=e[r+1];/[.+^${}()|\\*?[\]]/.test(i)?s+=`\\${i}`:s+=i,r++}else/[.+^${}()|]/.test(n)?s+=`\\${n}`:s+=n}return s+="$",new RegExp(s)}posixClassToRegex(e){return{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"}[e]||""}};function Z(t){switch(t.type){case"ArithCommandSubst":return!0;case"ArithNested":return Z(t.expression);case"ArithBinary":return Z(t.left)||Z(t.right);case"ArithUnary":return Z(t.operand);case"ArithTernary":return Z(t.condition)||Z(t.consequent)||Z(t.alternate);case"ArithAssignment":return Z(t.value);case"ArithGroup":return Z(t.expression);case"ArithArrayElement":return t.index?Z(t.index):!1;case"ArithConcat":return t.parts.some(Z);default:return!1}}function Ut(t){let e=t.operation;return e?!!("word"in e&&e.word&&oe(e.word)||e.type==="PatternReplacement"&&(e.pattern&&oe(e.pattern)||e.replacement&&oe(e.replacement))||e.type==="PatternRemoval"&&e.pattern&&oe(e.pattern)):!1}function tt(t){switch(t.type){case"CommandSubstitution":return!0;case"ArithmeticExpansion":return Z(t.expression.expression);case"DoubleQuoted":return t.parts.some(tt);case"BraceExpansion":return t.items.some(e=>e.type==="Word"&&oe(e.word));case"ParameterExpansion":return Ut(t);default:return!1}}function oe(t){return t.parts.some(tt)}function Gt(t){if(!t.operation)return!1;let e=t.operation,s;if((e.type==="DefaultValue"||e.type==="AssignDefault"||e.type==="UseAlternative"||e.type==="ErrorIfUnset")&&(s=e.word?.parts),!s)return!1;for(let r of s)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function rs(t){let e=!1,s=!1,r=!1,n=!1,i=!1;for(let o of t){if((o.type==="SingleQuoted"||o.type==="DoubleQuoted")&&(e=!0,o.type==="DoubleQuoted"))for(let a of o.parts)a.type==="ParameterExpansion"&&a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&!a.operation&&(n=!0);o.type==="CommandSubstitution"&&(s=!0),o.type==="ParameterExpansion"&&(i=!0,(o.parameter==="@"||o.parameter==="*")&&(r=!0),Gt(o)&&(e=!0))}return{hasQuoted:e,hasCommandSub:s,hasArrayVar:r,hasArrayAtExpansion:n,hasParamExpansion:i}}function kn(t,e,s,r,n){let i=s??1;i===0&&(i=1);let o=Math.abs(i),a=[],c=0;r?.match(/^-?0\d/)&&(c=Math.max(c,r.replace(/^-/,"").length)),n?.match(/^-?0\d/)&&(c=Math.max(c,n.replace(/^-/,"").length));let l=u=>{if(c>0){let h=u<0,d=String(Math.abs(u)).padStart(c,"0");return h?`-${d}`:d}return String(u)};if(t<=e)for(let u=t,h=0;u<=e&&h<1e4;u+=o,h++)a.push(l(u));else for(let u=t,h=0;u>=e&&h<1e4;u-=o,h++)a.push(l(u));return a}function In(t,e,s){let r=s??1;r===0&&(r=1);let n=t.charCodeAt(0),i=e.charCodeAt(0),o=Math.abs(r),a=t>="A"&&t<="Z",c=t>="a"&&t<="z",l=e>="A"&&e<="Z",u=e>="a"&&e<="z";if(a&&u||c&&l)return null;let h=[];if(n<=i)for(let d=n,m=0;d<=i&&m<1e4;d+=o,m++)h.push(String.fromCharCode(d));else for(let d=n,m=0;d>=i&&m<1e4;d-=o,m++)h.push(String.fromCharCode(d));return h}function Me(t,e,s,r,n){let i=s!==void 0?`..${s}`:"";return typeof t=="number"&&typeof e=="number"?{expanded:kn(t,e,s,r,n),literal:`{${t}..${e}${i}}`}:typeof t=="string"&&typeof e=="string"?{expanded:In(t,e,s),literal:`{${t}..${e}${i}}`}:{expanded:null,literal:`{${t}..${e}${i}}`}}function V(t,e){let s="",r=0;for(;r<t.length;){let n=t[r];if(n==="\\")if(r+1<t.length){let i=t[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,r+=2}else s+="\\\\",r++;else if(n==="*")s+=e?".*":".*?",r++;else if(n==="?")s+=".",r++;else if(n==="["){let i=Rn(t,r);if(i===-1)s+="\\[",r++;else{let o=t.slice(r+1,i);s+=Dn(o),r=i+1}}else/[\^$.|+(){}]/.test(n)?(s+=`\\${n}`,r++):(s+=n,r++)}return s}function Rn(t,e){let s=e+1;for(s<t.length&&t[s]==="^"&&s++,s<t.length&&t[s]==="]"&&s++;s<t.length;){if(t[s]==="\\"&&s+1<t.length){s+=2;continue}if(t[s]==="]")return s;if(t[s]==="'"){let r=t.indexOf("'",s+1);if(r!==-1){s=r+1;continue}}if(t[s]==="["&&s+1<t.length&&t[s+1]===":"){let r=t.indexOf(":]",s+2);if(r!==-1){s=r+2;continue}}s++}return-1}function Dn(t){let e="[",s=0;for((t[0]==="^"||t[0]==="!")&&(e+="^",s++);s<t.length;){if(t[s]==="'"){let n=t.indexOf("'",s+1);if(n!==-1){let i=t.slice(s+1,n);for(let o of i)o==="\\"?e+="\\\\":o==="]"?e+="\\]":o==="^"&&e==="["?e+="\\^":e+=o;s=n+1;continue}}if(t[s]==="["&&s+1<t.length&&t[s+1]===":"){let n=t.indexOf(":]",s+2);if(n!==-1){let i=t.slice(s+2,n);e+=_n(i),s=n+2;continue}}let r=t[s];r==="\\"?s+1<t.length?(e+=`\\${t[s+1]}`,s+=2):(e+="\\\\",s++):r==="-"&&s>0&&s<t.length-1?(e+="-",s++):r==="^"&&s===0?(e+="^",s++):(r==="]"&&s===0?e+="\\]":e+=r,s++)}return e+="]",e}var On={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 _n(t){return On[t]??""}function ze(t,e){let s=`${e}_`,r=[];for(let n of Object.keys(t.state.env))if(n.startsWith(s)){let i=n.slice(s.length),o=Number.parseInt(i,10);!Number.isNaN(o)&&String(o)===i&&r.push(o)}return r.sort((n,i)=>n-i)}function Be(t,e){let s=`${e}_`;for(let r of Object.keys(t.state.env))r.startsWith(s)&&delete t.state.env[r]}function Vt(t,e){let s=`${e}_`,r=[];for(let n of Object.keys(t.state.env))if(n.startsWith(s)&&!n.includes("__")){let i=n.slice(s.length);r.push(i)}return r.sort()}function ss(t){return t.startsWith("'")&&t.endsWith("'")||t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function rt(t){return t.IFS??`
40
- `}function ns(t){return t.IFS===""}function Ue(t){return t.split("").map(e=>/[\\^$.*+?()[\]{}|-]/.test(e)?`\\${e}`:e===" "?"\\t":e===`
41
- `?"\\n":e).join("")}function Ln(t,e){let s=Ue(t);return new RegExp(`[${s}]+`,e)}function Tn(t){let e=Ue(t);return new RegExp(`^[${e}]+`)}function Fn(t){let e=Ue(t);return new RegExp(`[${e}]+$`)}function $e(t){let e=t.IFS;return e===void 0?" ":e[0]||""}function is(t,e){if(e==="")return{words:[t],wordStarts:[0]};let s=[],r=[],n=Ln(e,"g"),i=0,o=t.match(Tn(e));o&&(i=o[0].length),n.lastIndex=i;let a=n.exec(t);for(;a!==null;)a.index>i&&(r.push(i),s.push(t.substring(i,a.index))),i=n.lastIndex,a=n.exec(t);return i<t.length&&(r.push(i),s.push(t.substring(i))),{words:s,wordStarts:r}}function os(t,e){return e===""?t:t.replace(Fn(e),"")}function F(t,e){return t.state.associativeArrays?.has(e)?Vt(t,e).map(i=>[i,t.state.env[`${e}_${i}`]]):ze(t,e).map(n=>[n,t.state.env[`${e}_${n}`]])}function as(t,e){return t.state.associativeArrays?.has(e)?Vt(t,e).length>0:ze(t,e).length>0}function Q(t,e,s=!0,r=!1){switch(e){case"?":return String(t.state.lastExitCode);case"$":return String(process.pid);case"#":return t.state.env["#"]||"0";case"@":return t.state.env["@"]||"";case"_":return t.state.lastArg;case"-":{let o="";return t.state.options.errexit&&(o+="e"),t.state.options.nounset&&(o+="u"),t.state.options.verbose&&(o+="v"),t.state.options.xtrace&&(o+="x"),t.state.options.pipefail&&(o+="p"),o}case"*":{let o=Number.parseInt(t.state.env["#"]||"0",10);if(o===0)return"";let a=[];for(let c=1;c<=o;c++)a.push(t.state.env[String(c)]||"");return a.join($e(t.state.env))}case"0":return t.state.env[0]||"bash";case"PWD":return t.state.env.PWD!==void 0?t.state.env.PWD:"";case"OLDPWD":return t.state.env.OLDPWD!==void 0?t.state.env.OLDPWD:"";case"PPID":{let{ppid:o}=We();return String(o)}case"UID":{let{uid:o}=We();return String(o)}case"EUID":return String(process.geteuid?.()??We().uid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-t.state.startTime)/1e3));case"BASH_VERSION":return Pr;case"!":return String(t.state.lastBackgroundPid);case"LINENO":return String(t.state.currentLine)}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(e))throw new Ee(`\${${e}}`);let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let o=n[1],a=n[2];if(a==="@"||a==="*"){let h=F(t,o);if(h.length>0)return h.map(([,m])=>m).join(" ");let d=t.state.env[o];return d!==void 0?d:""}if(t.state.associativeArrays?.has(o)){let h=ss(a),d=t.state.env[`${o}_${h}`];if(d===void 0&&s&&t.state.options.nounset)throw new J(`${o}[${a}]`);return d||""}let l;if(/^-?\d+$/.test(a))l=Number.parseInt(a,10);else try{let h=new z,d=T(h,a);l=P(t,d.expression)}catch{let h=t.state.env[a];l=h?Number.parseInt(h,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let h=F(t,o);if(h.length===0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${o}: bad array subscript
42
- `,"";let m=Math.max(...h.map(([E])=>typeof E=="number"?E:0))+1+l;return m<0?(t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${o}: bad array subscript
43
- `,""):t.state.env[`${o}_${m}`]||""}let u=t.state.env[`${o}_${l}`];if(u===void 0&&s&&t.state.options.nounset)throw new J(`${o}[${l}]`);return u||""}if(/^[1-9][0-9]*$/.test(e)){let o=t.state.env[e];if(o===void 0&&s&&t.state.options.nounset)throw new J(e);return o||""}let i=t.state.env[e];if(i===void 0&&s&&t.state.options.nounset)throw new J(e);return i||""}async function cs(t,e,s,r,n){let i=[];for(let u of e){let h=u.type==="ParameterExpansion"||u.type==="CommandSubstitution"||u.type==="ArithmeticExpansion";if(u.type==="ParameterExpansion"&&Gt(u)){let d=await n(t,u);i.push({value:d,splittable:!1})}else{let d=await n(t,u);i.push({value:d,splittable:h})}}if(!i.some(u=>u.splittable&&new RegExp(`[${r}]`).test(u.value))){let u=i.map(h=>h.value).join("");return u?[u]:[]}let a=new RegExp(`[${r}]+`),c=[],l="";for(let u=0;u<i.length;u++){let h=i[u];if(!h.splittable)l+=h.value;else{let d=h.value.split(a);for(let m=0;m<d.length;m++)m===0?l+=d[m]:(l!==""&&c.push(l),l=d[m])}}return l!==""&&c.push(l),c}function H(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ls(t){switch(t.type){case"Literal":return t.value;case"SingleQuoted":return t.value;case"Escaped":return t.value;default:return null}}function us(t){switch(t.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return t.value==="";default:return!1}}function Ht(t){if(t==="")return"''";if(!/['\\\n\r\t\x00-\x1f\x7f]/.test(t))return`'${t}'`;let e="$'";for(let s of t)switch(s){case"'":e+="\\'";break;case"\\":e+="\\\\";break;case`
44
- `:e+="\\n";break;case"\r":e+="\\r";break;case" ":e+="\\t";break;default:{let r=s.charCodeAt(0);r<32||r===127?e+=`\\x${r.toString(16).padStart(2,"0")}`:e+=s}}return`${e}'`}function Se(t,e,s=!1){return e.map(r=>ae(t,r,s)).join("")}async function xe(t,e,s=!1){let r=[];for(let n of e)r.push(await K(t,n));return r.join("")}function Wn(t){return us(t)}function fs(t){if(t.parts.length===0)return!0;for(let e of t.parts)if(!Wn(e))return!1;return!0}function hs(t){return t.replace(/([*?[\]\\])/g,"\\$1")}function ds(t,e,s=!1){let r=ls(e);if(r!==null)return r;switch(e.type){case"ParameterExpansion":return Es(t,e,s);case"TildeExpansion":return s?e.user===null?"~":`~${e.user}`:e.user===null?t.state.env.HOME||"/home/user":e.user==="root"?"/root":`~${e.user}`;case"Glob":return e.pattern;default:return null}}function ae(t,e,s=!1){let r=ds(t,e,s);if(r!==null)return r;switch(e.type){case"DoubleQuoted":{let n=[];for(let i of e.parts)n.push(ae(t,i,!0));return n.join("")}case"ArithmeticExpansion":return String(P(t,e.expression.expression));case"BraceExpansion":{let n=[];for(let i of e.items)if(i.type==="Range"){let o=Me(i.start,i.end,i.step,i.startStr,i.endStr);if(o.expanded)n.push(...o.expanded);else return o.literal}else n.push(st(t,i.word));return n.join(" ")}default:return""}}function st(t,e){let s=e.parts,r=s.length;if(r===1)return ae(t,s[0]);let n=[];for(let i=0;i<r;i++)n.push(ae(t,s[i]));return n.join("")}async function k(t,e){return oe(e)?ws(t,e):st(t,e)}function nt(t){for(let e of t)if(e.type==="BraceExpansion"||e.type==="DoubleQuoted"&&nt(e.parts))return!0;return!1}function Mn(t){for(let e of t){if(e.type==="BraceExpansion"){for(let s of e.items)if(s.type==="Word"&&oe(s.word))return!0}if(tt(e))return!0}return!1}var ms=1e4,ke=1e5;function ps(t,e,s={count:0}){if(s.count>ke)return[[]];let r=[[]];for(let n of e)if(n.type==="BraceExpansion"){let i=[],o=!1,a="";for(let u of n.items)if(u.type==="Range"){let h=Me(u.start,u.end,u.step,u.startStr,u.endStr);if(h.expanded)for(let d of h.expanded)s.count++,i.push(d);else{o=!0,a=h.literal;break}}else{let h=ps(t,u.word.parts,s);for(let d of h)s.count++,i.push(d.join(""))}if(o){for(let u of r)s.count++,u.push(a);continue}if(r.length*i.length>ms||s.count>ke)return r;let l=[];for(let u of r)for(let h of i){if(s.count++,s.count>ke)return l.length>0?l:r;l.push([...u,h])}r=l}else{let i=ae(t,n);for(let o of r)s.count++,o.push(i)}return r}function zn(t,e){let s=e.parts;return nt(s)?ps(t,s).map(n=>n.join("")):[st(t,e)]}async function ys(t,e,s={count:0}){if(s.count>ke)return[[]];let r=[[]];for(let n of e)if(n.type==="BraceExpansion"){let i=[],o=!1,a="";for(let u of n.items)if(u.type==="Range"){let h=Me(u.start,u.end,u.step,u.startStr,u.endStr);if(h.expanded)for(let d of h.expanded)s.count++,i.push(d);else{o=!0,a=h.literal;break}}else{let h=await ys(t,u.word.parts,s);for(let d of h)s.count++,i.push(d.join(""))}if(o){for(let u of r)s.count++,u.push(a);continue}if(r.length*i.length>ms||s.count>ke)return r;let l=[];for(let u of r)for(let h of i){if(s.count++,s.count>ke)return l.length>0?l:r;l.push([...u,h])}r=l}else{let i=await K(t,n);for(let o of r)s.count++,o.push(i)}return r}async function Bn(t,e){let s=e.parts;return nt(s)?(await ys(t,s)).map(n=>n.join("")):[await k(t,e)]}async function Ge(t,e){let s=e.parts,{hasQuoted:r,hasCommandSub:n,hasArrayVar:i,hasArrayAtExpansion:o,hasParamExpansion:a}=rs(s),l=nt(s)?Mn(s)?await Bn(t,e):zn(t,e):null;if(l&&l.length>1){let d=[];for(let m of l)if(!r&&/[*?[]/.test(m)){let E=await new ve(t.fs,t.state.cwd).expand(m);E.length>0?d.push(...E):d.push(m)}else d.push(m);return{values:d,quoted:!1}}if(o&&s.length===1&&s[0].type==="DoubleQuoted"){let d=s[0];if(d.parts.length===1&&d.parts[0].type==="ParameterExpansion"){let y=d.parts[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@]\]$/);if(y){let E=y[1],p=F(t,E);if(p.length>0)return{values:p.map(([,g])=>g),quoted:!0};let w=t.state.env[E];return w!==void 0?{values:[w],quoted:!0}:{values:[],quoted:!0}}}}if(s.length===1&&s[0].type==="DoubleQuoted"){let d=s[0],m=-1,y=!1;for(let E=0;E<d.parts.length;E++){let p=d.parts[E];if(p.type==="ParameterExpansion"&&(p.parameter==="@"||p.parameter==="*")){m=E,y=p.parameter==="*";break}}if(m!==-1){let E=d.parts[m];E.type==="ParameterExpansion"&&E.operation&&(m=-1)}if(m!==-1){let E=Number.parseInt(t.state.env["#"]||"0",10),p="";for(let C=0;C<m;C++)p+=await K(t,d.parts[C]);let w="";for(let C=m+1;C<d.parts.length;C++)w+=await K(t,d.parts[C]);if(E===0){if(y)return{values:[p+w],quoted:!0};let C=p+w;return{values:C?[C]:[],quoted:!0}}let g=[];for(let C=1;C<=E;C++)g.push(t.state.env[String(C)]||"");if(y){let C=$e(t.state.env);return{values:[p+g.join(C)+w],quoted:!0}}return g.length===1?{values:[p+g[0]+w],quoted:!0}:{values:[p+g[0],...g.slice(1,-1),g[g.length-1]+w],quoted:!0}}}if((n||i||a)&&!ns(t.state.env)){let d=rt(t.state.env),m=Ue(d),y=await cs(t,s,d,m,K),E=[],p=new ve(t.fs,t.state.cwd);for(let w of y)if(/[*?[]/.test(w)){let g=await p.expand(w);g.length>0?E.push(...g):E.push(w)}else E.push(w);return{values:E,quoted:!1}}let h=oe(e)?await ws(t,e):st(t,e);if(!r&&/[*?[]/.test(h)){let m=await new ve(t.fs,t.state.cwd).expand(h);if(m.length>0)return{values:m,quoted:!1}}return h===""&&!r?{values:[],quoted:!1}:{values:[h],quoted:r}}async function ws(t,e){let s=e.parts,r=s.length;if(r===1)return K(t,s[0]);let n=[];for(let i=0;i<r;i++)n.push(await K(t,s[i]));return n.join("")}async function K(t,e){if(e.type==="ParameterExpansion"&&Ut(e))return Un(t,e);let s=ds(t,e);if(s!==null)return s;switch(e.type){case"DoubleQuoted":{let r=[];for(let n of e.parts)r.push(await K(t,n));return r.join("")}case"CommandSubstitution":try{let r=await t.executeScript(e.body);return t.state.lastExitCode=r.exitCode,t.state.env["?"]=String(r.exitCode),r.stdout.replace(/\n+$/,"")}catch(r){if(r instanceof B)throw r;if(r instanceof R)return t.state.lastExitCode=r.exitCode,t.state.env["?"]=String(r.exitCode),r.stdout.replace(/\n+$/,"");throw r}case"ArithmeticExpansion":return String(await v(t,e.expression.expression));case"BraceExpansion":{let r=[];for(let n of e.items)if(n.type==="Range"){let i=Me(n.start,n.end,n.step,n.startStr,n.endStr);if(i.expanded)r.push(...i.expanded);else return i.literal}else r.push(await k(t,n.word));return r.join(" ")}default:return""}}function Es(t,e,s=!1){let{parameter:r,operation:n}=e,i=n&&(n.type==="DefaultValue"||n.type==="AssignDefault"||n.type==="UseAlternative"||n.type==="ErrorIfUnset"),o=Q(t,r,!i);if(!n)return o;let a=!(r in t.state.env),c=o==="";switch(n.type){case"DefaultValue":return(a||n.checkEmpty&&c)&&n.word?Se(t,n.word.parts,s):o;case"AssignDefault":{if((a||n.checkEmpty&&c)&&n.word){let u=Se(t,n.word.parts,s),h=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(h){let[,d,m]=h,y;if(/^\d+$/.test(m))y=Number.parseInt(m,10);else{try{let p=new z,w=T(p,m);y=P(t,w.expression)}catch{let p=t.state.env[m];y=p?Number.parseInt(p,10):0}Number.isNaN(y)&&(y=0)}t.state.env[`${d}_${y}`]=u;let E=Number.parseInt(t.state.env[`${d}__length`]||"0",10);y>=E&&(t.state.env[`${d}__length`]=String(y+1))}else t.state.env[r]=u;return u}return o}case"ErrorIfUnset":{if(a||n.checkEmpty&&c){let u=n.word?Se(t,n.word.parts,s):`${r}: parameter null or not set`;throw new R(1,"",`bash: ${u}
45
- `)}return o}case"UseAlternative":return!(a||n.checkEmpty&&c)&&n.word?Se(t,n.word.parts,s):"";case"Length":{let l=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(l){let u=F(t,l[1]);return String(u.length)}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&as(t,r)){let u=t.state.env[`${r}_0`]||"";return String(u.length)}return String(o.length)}case"LengthSliceError":throw new Ee(r);case"Substring":{let l=n.offset?P(t,n.offset.expression):0,u=n.length?P(t,n.length.expression):void 0;if(r==="@"||r==="*"){let y=(t.state.env["@"]||"").split(" ").filter(g=>g),E=t.state.env[0]||"bash",p=l===0?[E,...y]:y,w=l===0?0:l-1;if(w<0||w>=p.length)return"";if(u!==void 0){let g=u<0?p.length+u:w+u;return p.slice(w,Math.max(w,g)).join(" ")}return p.slice(w).join(" ")}let h=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(h){let E=F(t,h[1]).map(([,w])=>w),p=l;if(p<0&&(p=E.length+p,p<0))return"";if(u!==void 0){if(u<0){let w=E.length+u;return E.slice(p,Math.max(p,w)).join(" ")}return E.slice(p,p+u).join(" ")}return E.slice(p).join(" ")}let d=[...o],m=l;if(m<0&&(m=Math.max(0,d.length+m)),u!==void 0){if(u<0){let y=d.length+u;return d.slice(m,Math.max(m,y)).join("")}return d.slice(m,m+u).join("")}return d.slice(m).join("")}case"PatternRemoval":{let l="";if(n.pattern)for(let h of n.pattern.parts)if(h.type==="Glob")l+=V(h.pattern,n.greedy);else if(h.type==="Literal")l+=V(h.value,n.greedy);else if(h.type==="SingleQuoted"||h.type==="Escaped")l+=H(h.value);else if(h.type==="DoubleQuoted"){let d=Se(t,h.parts);l+=H(d)}else if(h.type==="ParameterExpansion"){let d=ae(t,h);l+=V(d,n.greedy)}else{let d=ae(t,h);l+=H(d)}if(n.side==="prefix")return o.replace(new RegExp(`^${l}`),"");let u=new RegExp(`${l}$`);if(n.greedy)return o.replace(u,"");for(let h=o.length;h>=0;h--){let d=o.slice(h);if(u.test(d))return o.slice(0,h)}return o}case"PatternReplacement":{let l="";if(n.pattern)for(let d of n.pattern.parts)if(d.type==="Glob")l+=V(d.pattern,!0);else if(d.type==="Literal")l+=V(d.value,!0);else if(d.type==="SingleQuoted"||d.type==="Escaped")l+=H(d.value);else if(d.type==="DoubleQuoted"){let m=Se(t,d.parts);l+=H(m)}else if(d.type==="ParameterExpansion"){let m=ae(t,d);l+=V(m,!0)}else{let m=ae(t,d);l+=H(m)}let u=n.replacement?Se(t,n.replacement.parts):"";if(l==="")return o;n.anchor==="start"?l=`^${l}`:n.anchor==="end"&&(l=`${l}$`);let h=n.all?"g":"";try{let d=new RegExp(l,h);if(n.all){let m="",y=0,E=d.exec(o);for(;E!==null&&!(E[0].length===0&&E.index===o.length);)m+=o.slice(y,E.index)+u,y=E.index+E[0].length,E[0].length===0&&y++,E=d.exec(o);return m+=o.slice(y),m}return o.replace(d,u)}catch{return o}}case"CaseModification":return n.direction==="upper"?n.all?o.toUpperCase():o.charAt(0).toUpperCase()+o.slice(1):n.all?o.toLowerCase():o.charAt(0).toLowerCase()+o.slice(1);case"Transform":{let l=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(l&&n.operator==="Q")return F(t,l[1]).map(([,d])=>Ht(d)).join(" ");switch(n.operator){case"Q":return Ht(o);case"P":return o;case"a":return"";case"A":return`${r}=${Ht(o)}`;case"E":return o.replace(/\\([\\abefnrtv'"?])/g,(u,h)=>{switch(h){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
46
- `;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return h}});case"K":return"";default:return o}}case"Indirection":return Q(t,o);case"ArrayKeys":{let u=F(t,n.array).map(([h])=>String(h));return n.star?u.join($e(t.state.env)):u.join(" ")}case"VarNamePrefix":{let l=Object.keys(t.state.env).filter(u=>u.startsWith(n.prefix)&&!u.includes("__")).sort();return n.star?l.join($e(t.state.env)):l.join(" ")}default:return o}}async function Un(t,e,s=!1){let{parameter:r,operation:n}=e,i=n&&(n.type==="DefaultValue"||n.type==="AssignDefault"||n.type==="UseAlternative"||n.type==="ErrorIfUnset"),o=Q(t,r,!i);if(!n)return o;let a=!(r in t.state.env),c=o==="";switch(n.type){case"DefaultValue":return(a||n.checkEmpty&&c)&&n.word?xe(t,n.word.parts,s):o;case"AssignDefault":{if((a||n.checkEmpty&&c)&&n.word){let u=await xe(t,n.word.parts,s),h=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(h){let[,d,m]=h,y;if(/^\d+$/.test(m))y=Number.parseInt(m,10);else{try{let p=new z,w=T(p,m);y=await v(t,w.expression)}catch{let p=t.state.env[m];y=p?Number.parseInt(p,10):0}Number.isNaN(y)&&(y=0)}t.state.env[`${d}_${y}`]=u;let E=Number.parseInt(t.state.env[`${d}__length`]||"0",10);y>=E&&(t.state.env[`${d}__length`]=String(y+1))}else t.state.env[r]=u;return u}return o}case"ErrorIfUnset":{if(a||n.checkEmpty&&c){let u=n.word?await xe(t,n.word.parts,s):`${r}: parameter null or not set`;throw new R(1,"",`bash: ${u}
47
- `)}return o}case"UseAlternative":return!(a||n.checkEmpty&&c)&&n.word?xe(t,n.word.parts,s):"";case"PatternRemoval":{let l="";if(n.pattern)for(let h of n.pattern.parts)if(h.type==="Glob")l+=V(h.pattern,n.greedy);else if(h.type==="Literal")l+=V(h.value,n.greedy);else if(h.type==="SingleQuoted"||h.type==="Escaped")l+=H(h.value);else if(h.type==="DoubleQuoted"){let d=await xe(t,h.parts);l+=H(d)}else if(h.type==="ParameterExpansion"){let d=await K(t,h);l+=V(d,n.greedy)}else{let d=await K(t,h);l+=H(d)}if(n.side==="prefix")return o.replace(new RegExp(`^${l}`),"");let u=new RegExp(`${l}$`);if(n.greedy)return o.replace(u,"");for(let h=o.length;h>=0;h--){let d=o.slice(h);if(u.test(d))return o.slice(0,h)}return o}case"PatternReplacement":{let l="";if(n.pattern)for(let d of n.pattern.parts)if(d.type==="Glob")l+=V(d.pattern,!0);else if(d.type==="Literal")l+=V(d.value,!0);else if(d.type==="SingleQuoted"||d.type==="Escaped")l+=H(d.value);else if(d.type==="DoubleQuoted"){let m=await xe(t,d.parts);l+=H(m)}else if(d.type==="ParameterExpansion"){let m=await K(t,d);l+=V(m,!0)}else{let m=await K(t,d);l+=H(m)}let u=n.replacement?await xe(t,n.replacement.parts):"";if(l==="")return o;n.anchor==="start"?l=`^${l}`:n.anchor==="end"&&(l=`${l}$`);let h=n.all?"g":"";try{let d=new RegExp(l,h);if(n.all){let m="",y=0,E=d.exec(o);for(;E!==null&&!(E[0].length===0&&E.index===o.length);)m+=o.slice(y,E.index)+u,y=E.index+E[0].length,E[0].length===0&&y++,E=d.exec(o);return m+=o.slice(y),m}return o.replace(d,u)}catch{return o}}default:return Es(t,e,s)}}function jt(t,e,s){switch(s){case"+":return t+e;case"-":return t-e;case"*":return t*e;case"/":return e!==0?Math.trunc(t/e):0;case"%":return e!==0?t%e:0;case"**":if(e<0)throw new W("exponent less than 0");return t**e;case"<<":return t<<e;case">>":return t>>e;case"<":return t<e?1:0;case"<=":return t<=e?1:0;case">":return t>e?1:0;case">=":return t>=e?1:0;case"==":return t===e?1:0;case"!=":return t!==e?1:0;case"&":return t&e;case"|":return t|e;case"^":return t^e;case",":return e;default:return 0}}function gs(t,e,s){switch(s){case"=":return e;case"+=":return t+e;case"-=":return t-e;case"*=":return t*e;case"/=":return e!==0?Math.trunc(t/e):0;case"%=":return e!==0?t%e:0;case"<<=":return t<<e;case">>=":return t>>e;case"&=":return t&e;case"|=":return t|e;case"^=":return t^e;default:return e}}function qt(t,e){switch(e){case"-":return-t;case"+":return+t;case"!":return t===0?1:0;case"~":return~t;default:return t}}function Gn(t,e){let s=t.state.env[e];if(s!==void 0)return s;let r=t.state.env[`${e}_0`];return r!==void 0?r:Q(t,e)}function Ie(t){if(!t)return 0;let e=Number.parseInt(t,10);if(!Number.isNaN(e)&&/^-?\d+$/.test(t.trim()))return e;let s=t.trim();if(!s)return 0;try{let r=new z,{expr:n,pos:i}=ne(r,s,0);if(i<s.length){let o=s.slice(i).trim().split(/\s+/)[0];throw new W(`${s}: syntax error in expression (error token is "${o}")`)}return n.type==="ArithNumber"?n.value:e||0}catch(r){if(r instanceof W)throw r;let n=s.split(/\s+/).slice(1)[0]||s;throw new W(`${s}: syntax error in expression (error token is "${n}")`)}}function it(t,e,s=new Set){if(s.has(e))return 0;s.add(e);let r=Gn(t,e);if(!r)return 0;let n=Number.parseInt(r,10);if(!Number.isNaN(n)&&/^-?\d+$/.test(r.trim()))return n;let i=r.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return it(t,i,s);try{let o=new z,{expr:a}=ne(o,i,0);return X(t,a,s)}catch{return 0}}function X(t,e,s){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new W("value too great for base");return e.value;case"ArithVariable":return it(t,e.name,s);case"ArithBinary":{if(e.operator==="||")return X(t,e.left,s)||X(t,e.right,s)?1:0;if(e.operator==="&&")return X(t,e.left,s)&&X(t,e.right,s)?1:0;let r=X(t,e.left,s),n=X(t,e.right,s);return jt(r,n,e.operator)}case"ArithUnary":{let r=X(t,e.operand,s);return qt(r,e.operator)}case"ArithTernary":return X(t,e.condition,s)?X(t,e.consequent,s):X(t,e.alternate,s);case"ArithGroup":return X(t,e.expression,s);default:return P(t,e)}}function de(t,e){if(e.startsWith("#")){let h=e.slice(1),d=t.state.env[h]||"";return String(d.length)}if(e.startsWith("!")){let h=e.slice(1),d=t.state.env[h]||"";return t.state.env[d]||""}let s=[":-",":=",":?",":+","-","=","?","+"],r=-1,n="";for(let h of s){let d=e.indexOf(h);d>0&&(r===-1||d<r)&&(r=d,n=h)}if(r===-1)return Q(t,e);let i=e.slice(0,r),o=e.slice(r+n.length),a=t.state.env[i],c=a===void 0,l=a==="",u=n.startsWith(":");switch(n){case":-":case"-":return c||u&&l?o:a||"";case":=":case"=":return c||u&&l?(t.state.env[i]=o,o):a||"";case":+":case"+":return!(c||u&&l)?o:"";case":?":case"?":{if(c||u&&l)throw new Error(o||`${i}: parameter null or not set`);return a||""}default:return a||""}}function P(t,e){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new W("value too great for base");return e.value;case"ArithVariable":return it(t,e.name);case"ArithNested":return P(t,e.expression);case"ArithCommandSubst":return 0;case"ArithBracedExpansion":{let s=de(t,e.content);return Number.parseInt(s,10)||0}case"ArithDynamicBase":{let s=de(t,e.baseExpr),r=Number.parseInt(s,10);if(r<2||r>64)return 0;let n=`${r}#${e.value}`;return Ne(n)}case"ArithDynamicNumber":{let r=de(t,e.prefix)+e.suffix;return Ne(r)}case"ArithArrayElement":{let s=t.state.associativeArrays?.has(e.array),r;if(e.stringKey!==void 0)r=`${e.array}_${e.stringKey}`;else if(s&&e.index?.type==="ArithVariable")r=`${e.array}_${e.index.name}`;else if(e.index){let i=P(t,e.index);if(i<0){let a=F(t,e.array);if(a.length===0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${e.array}: bad array subscript
48
- `,0;let l=Math.max(...a.map(([u])=>typeof u=="number"?u:0))+1+i;if(l<0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${e.array}: bad array subscript
49
- `,0;i=l}r=`${e.array}_${i}`;let o=t.state.env[r];if(o!==void 0)return Ie(o);if(i===0){let a=t.state.env[e.array];if(a!==void 0)return Ie(a)}if(t.state.options.nounset&&!Object.keys(t.state.env).some(c=>c===e.array||c.startsWith(`${e.array}_`)))throw new J(`${e.array}[${i}]`);return 0}else return 0;let n=t.state.env[r];return n!==void 0?Ie(n):0}case"ArithDoubleSubscript":throw new W("double subscript","","");case"ArithNumberSubscript":throw new W(`${e.number}${e.errorToken}: syntax error: invalid arithmetic operator (error token is "${e.errorToken}")`);case"ArithBinary":{if(e.operator==="||")return P(t,e.left)||P(t,e.right)?1:0;if(e.operator==="&&")return P(t,e.left)&&P(t,e.right)?1:0;let s=P(t,e.left),r=P(t,e.right);return jt(s,r,e.operator)}case"ArithUnary":{let s=P(t,e.operand);if(e.operator==="++"||e.operator==="--"){if(e.operand.type==="ArithVariable"){let r=e.operand.name,n=Number.parseInt(Q(t,r),10)||0,i=e.operator==="++"?n+1:n-1;return t.state.env[r]=String(i),e.prefix?i:n}if(e.operand.type==="ArithArrayElement"){let r=e.operand.array,n=t.state.associativeArrays?.has(r),i;if(e.operand.stringKey!==void 0)i=`${r}_${e.operand.stringKey}`;else if(n&&e.operand.index?.type==="ArithVariable")i=`${r}_${e.operand.index.name}`;else if(e.operand.index){let c=P(t,e.operand.index);i=`${r}_${c}`}else return s;let o=Number.parseInt(t.state.env[i]||"0",10)||0,a=e.operator==="++"?o+1:o-1;return t.state.env[i]=String(a),e.prefix?a:o}return s}return qt(s,e.operator)}case"ArithTernary":return P(t,e.condition)?P(t,e.consequent):P(t,e.alternate);case"ArithAssignment":{let s=e.variable,r=s;if(e.stringKey!==void 0)r=`${s}_${e.stringKey}`;else if(e.subscript){let a=t.state.associativeArrays?.has(s);if(a&&e.subscript.type==="ArithVariable")r=`${s}_${e.subscript.name}`;else if(a){let c=P(t,e.subscript);r=`${s}_${c}`}else{let c=P(t,e.subscript);if(c<0){let l=F(t,s);l.length>0&&(c=Math.max(...l.map(([h])=>typeof h=="number"?h:0))+1+c)}r=`${s}_${c}`}}let n=Number.parseInt(t.state.env[r]||"0",10)||0,i=P(t,e.value),o=gs(n,i,e.operator);return t.state.env[r]=String(o),o}case"ArithGroup":return P(t,e.expression);case"ArithConcat":{let s="";for(let r of e.parts)s+=As(t,r);return Number.parseInt(s,10)||0}default:return 0}}function As(t,e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return Q(t,e.name);case"ArithBracedExpansion":return de(t,e.content);case"ArithCommandSubst":return"0";case"ArithConcat":{let s="";for(let r of e.parts)s+=As(t,r);return s}default:return String(P(t,e))}}async function v(t,e){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new W("value too great for base");return e.value;case"ArithVariable":return it(t,e.name);case"ArithNested":return v(t,e.expression);case"ArithCommandSubst":{if(t.execFn){let r=(await t.execFn(e.command)).stdout.trim();return Number.parseInt(r,10)||0}return 0}case"ArithBracedExpansion":{let s=de(t,e.content);return Number.parseInt(s,10)||0}case"ArithDynamicBase":{let s=de(t,e.baseExpr),r=Number.parseInt(s,10);if(r<2||r>64)return 0;let n=`${r}#${e.value}`;return Ne(n)}case"ArithDynamicNumber":{let r=de(t,e.prefix)+e.suffix;return Ne(r)}case"ArithArrayElement":{let s=t.state.associativeArrays?.has(e.array),r;if(e.stringKey!==void 0)r=`${e.array}_${e.stringKey}`;else if(s&&e.index?.type==="ArithVariable")r=`${e.array}_${e.index.name}`;else if(e.index){let i=await v(t,e.index);r=`${e.array}_${i}`;let o=t.state.env[r];if(o!==void 0)return Ie(o);if(i===0){let a=t.state.env[e.array];if(a!==void 0)return Ie(a)}if(t.state.options.nounset&&!Object.keys(t.state.env).some(c=>c===e.array||c.startsWith(`${e.array}_`)))throw new J(`${e.array}[${i}]`);return 0}else return 0;let n=t.state.env[r];return n!==void 0?Ie(n):0}case"ArithDoubleSubscript":throw new W("double subscript","","");case"ArithNumberSubscript":throw new W(`${e.number}${e.errorToken}: syntax error: invalid arithmetic operator (error token is "${e.errorToken}")`);case"ArithBinary":{if(e.operator==="||")return await v(t,e.left)||await v(t,e.right)?1:0;if(e.operator==="&&")return await v(t,e.left)&&await v(t,e.right)?1:0;let s=await v(t,e.left),r=await v(t,e.right);return jt(s,r,e.operator)}case"ArithUnary":{let s=await v(t,e.operand);if(e.operator==="++"||e.operator==="--"){if(e.operand.type==="ArithVariable"){let r=e.operand.name,n=Number.parseInt(Q(t,r),10)||0,i=e.operator==="++"?n+1:n-1;return t.state.env[r]=String(i),e.prefix?i:n}if(e.operand.type==="ArithArrayElement"){let r=e.operand.array,n=t.state.associativeArrays?.has(r),i;if(e.operand.stringKey!==void 0)i=`${r}_${e.operand.stringKey}`;else if(n&&e.operand.index?.type==="ArithVariable")i=`${r}_${e.operand.index.name}`;else if(e.operand.index){let c=await v(t,e.operand.index);i=`${r}_${c}`}else return s;let o=Number.parseInt(t.state.env[i]||"0",10)||0,a=e.operator==="++"?o+1:o-1;return t.state.env[i]=String(a),e.prefix?a:o}return s}return qt(s,e.operator)}case"ArithTernary":return await v(t,e.condition)?await v(t,e.consequent):await v(t,e.alternate);case"ArithAssignment":{let s=e.variable,r=s;if(e.stringKey!==void 0)r=`${s}_${e.stringKey}`;else if(e.subscript){let a=t.state.associativeArrays?.has(s);if(a&&e.subscript.type==="ArithVariable")r=`${s}_${e.subscript.name}`;else if(a){let c=await v(t,e.subscript);r=`${s}_${c}`}else{let c=await v(t,e.subscript);if(c<0){let l=F(t,s);l.length>0&&(c=Math.max(...l.map(([h])=>typeof h=="number"?h:0))+1+c)}r=`${s}_${c}`}}let n=Number.parseInt(t.state.env[r]||"0",10)||0,i=await v(t,e.value),o=gs(n,i,e.operator);return t.state.env[r]=String(o),o}case"ArithGroup":return await v(t,e.expression);case"ArithConcat":{let s="";for(let r of e.parts)s+=await Ss(t,r);return Number.parseInt(s,10)||0}default:return 0}}async function Ss(t,e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return Q(t,e.name);case"ArithBracedExpansion":return de(t,e.content);case"ArithCommandSubst":return t.execFn?(await t.execFn(e.command)).stdout.trim():"0";case"ArithConcat":{let s="";for(let r of e.parts)s+=await Ss(t,r);return s}default:return String(await v(t,e))}}var N=Object.freeze({stdout:"",stderr:"",exitCode:0});function j(t=""){return{stdout:t,stderr:"",exitCode:0}}function x(t,e=1){return{stdout:"",stderr:t,exitCode:e}}function S(t,e,s){return{stdout:t,stderr:e,exitCode:s}}function _(t){return{stdout:"",stderr:"",exitCode:t?0:1}}function ce(t,e,s="",r=""){throw new B(t,e,s,r)}function Zt(t,e){if(t.state.loopDepth===0){if(t.state.parentHasLoopContext)throw new ue;return N}let s=1;if(e.length>0){let r=Number.parseInt(e[0],10);if(Number.isNaN(r)||r<1)throw new R(128,"",`bash: break: ${e[0]}: numeric argument required
50
- `);s=r}throw new U(s)}async function Qt(t,e){let s,r=!1,n=!1,i=0;for(;i<e.length;)if(e[i]==="--"){i++;break}else if(e[i]==="-L")n=!1,i++;else if(e[i]==="-P")n=!0,i++;else if(e[i].startsWith("-")&&e[i]!=="-")i++;else break;let o=e.slice(i);if(o.length===0||o[0]==="~"?s=t.state.env.HOME||"/":o[0]==="-"?(s=t.state.previousDir,r=!0):s=o[0],!s.startsWith("/")&&!s.startsWith("./")&&!s.startsWith("../")&&s!=="."&&s!==".."){let h=t.state.env.CDPATH;if(h){let d=h.split(":").filter(m=>m);for(let m of d){let y=m.startsWith("/")?`${m}/${s}`:`${t.state.cwd}/${m}/${s}`;try{if((await t.fs.stat(y)).isDirectory){s=y,r=!0;break}}catch{}}}}let c=(s.startsWith("/")?s:`${t.state.cwd}/${s}`).split("/").filter(h=>h&&h!=="."),l="";for(let h of c)if(h==="..")l=l.split("/").slice(0,-1).join("/")||"/";else{l=l?`${l}/${h}`:`/${h}`;try{if(!(await t.fs.stat(l)).isDirectory)return x(`bash: cd: ${s}: Not a directory
51
- `)}catch{return x(`bash: cd: ${s}: No such file or directory
52
- `)}}let u=l||"/";return t.state.previousDir=t.state.cwd,t.state.cwd=u,t.state.env.PWD=t.state.cwd,t.state.env.OLDPWD=t.state.previousDir,j(r?`${u}
53
- `:"")}function Kt(t,e){if(t.state.loopDepth===0){if(t.state.parentHasLoopContext)throw new ue;return N}if(e.length>1)throw new U(1);let s=1;if(e.length>0){let r=Number.parseInt(e[0],10);if(Number.isNaN(r)||r<1)return x(`bash: continue: ${e[0]}: numeric argument required
54
- `);s=r}throw new Y(s)}function be(t,e){t.state.readonlyVars=t.state.readonlyVars||new Set,t.state.readonlyVars.add(e)}function Vn(t,e){return t.state.readonlyVars?.has(e)??!1}function me(t,e,s="bash"){return Vn(t,e)?x(`${s}: ${e}: readonly variable
55
- `):null}function xs(t){let e=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(e)return{name:e[1],isArray:!0,arrayElements:Xt(e[2])};if(t.includes("=")){let s=t.indexOf("=");return{name:t.slice(0,s),isArray:!1,value:t.slice(s+1)}}return{name:t,isArray:!1}}function bs(t,e,s={}){let{name:r,isArray:n,arrayElements:i,value:o}=e,{makeReadonly:a=!1,checkReadonly:c=!0}=s;if(c){let l=me(t,r);if(l)return l}if(n&&i){for(let l=0;l<i.length;l++)t.state.env[`${r}_${l}`]=i[l];t.state.env[`${r}__length`]=String(i.length)}else o!==void 0&&(t.state.env[r]=o);return a&&be(t,r),null}function Yt(t,e){let s=!1,r=!1,n=!1,i=!1,o=!1,a=[];for(let c=0;c<e.length;c++){let l=e[c];if(l==="-a")s=!0;else if(l==="-A")r=!0;else if(l==="-r")n=!0;else if(l==="-x")i=!0;else if(l==="-p")o=!0;else if(l==="--"){a.push(...e.slice(c+1));break}else if(l.startsWith("-"))for(let u of l.slice(1))u==="a"?s=!0:u==="A"?r=!0:u==="r"?n=!0:u==="x"?i=!0:u==="p"&&(o=!0);else a.push(l)}if(o&&a.length>0){let c="";for(let l of a){let u=t.state.env[l];if(u!==void 0){let h=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');c+=`declare -- ${l}="${h}"
56
- `}}return j(c)}if(a.length===0&&!o){let c="",l=Object.entries(t.state.env).filter(([u])=>!u.startsWith("BASH_")).sort(([u],[h])=>u.localeCompare(h));for(let[u,h]of l){let d=h.replace(/'/g,"'\\''");c+=`declare -- ${u}='${d}'
57
- `}return j(c)}for(let c of a){let l=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(l){let u=l[1],h=l[2];if(r&&(t.state.associativeArrays??=new Set,t.state.associativeArrays.add(u)),r&&h.includes("[")){let d=Hn(h);for(let[m,y]of d)t.state.env[`${u}_${m}`]=y}else{let d=Xt(h);for(let m=0;m<d.length;m++)t.state.env[`${u}_${m}`]=d[m];t.state.env[`${u}__length`]=String(d.length)}n&&be(t,u);continue}if(c.includes("=")){let u=c.indexOf("="),h=c.slice(0,u),d=c.slice(u+1),m=me(t,h);if(m)return m;t.state.env[h]=d,n&&be(t,h)}else{let u=c;r&&(t.state.associativeArrays??=new Set,t.state.associativeArrays.add(u));let h=Object.keys(t.state.env).some(d=>d.startsWith(`${u}_`)&&!d.startsWith(`${u}__length`));!(u in t.state.env)&&!h&&(s||r?t.state.env[`${u}__length`]="0":t.state.env[u]=""),n&&be(t,u)}}return N}function Xt(t){let e=[],s="",r=!1,n=!1,i=!1;for(let o of t){if(i){s+=o,i=!1;continue}if(o==="\\"){i=!0;continue}if(o==="'"&&!n){r=!r;continue}if(o==='"'&&!r){n=!n;continue}if((o===" "||o===" "||o===`
58
- `)&&!r&&!n){s&&(e.push(s),s="");continue}s+=o}return s&&e.push(s),e}function Hn(t){let e=[],s=0;for(;s<t.length;){for(;s<t.length&&/\s/.test(t[s]);)s++;if(s>=t.length)break;if(t[s]!=="["){s++;continue}s++;let r="";if(t[s]==="'"||t[s]==='"'){let i=t[s];for(s++;s<t.length&&t[s]!==i;)r+=t[s],s++;t[s]===i&&s++}else for(;s<t.length&&t[s]!=="]"&&t[s]!=="=";)r+=t[s],s++;for(;s<t.length&&t[s]!=="]";)s++;if(t[s]==="]"&&s++,t[s]!=="=")continue;s++;let n="";if(t[s]==="'"||t[s]==='"'){let i=t[s];for(s++;s<t.length&&t[s]!==i;)t[s]==="\\"&&s+1<t.length&&s++,n+=t[s],s++;t[s]===i&&s++}else for(;s<t.length&&!/\s/.test(t[s]);)n+=t[s],s++;e.push([r,n])}return e}function Jt(t,e){let s=!1,r=!1,n=[];for(let i=0;i<e.length;i++){let o=e[i];if(o==="-a")s=!0;else if(o==="-A")r=!0;else if(o==="-p"){if(e.length===1){let a="";for(let c of t.state.readonlyVars||[]){let l=t.state.env[c];l!==void 0&&(a+=`declare -r ${c}="${l}"
59
- `)}return j(a)}}else if(o==="--"){n.push(...e.slice(i+1));break}else o.startsWith("-")||n.push(o)}for(let i of n){let o=xs(i);if(o.value===void 0&&!o.isArray){be(t,o.name);continue}let a=bs(t,o,{makeReadonly:!0});if(a)return a}return N}async function er(t,e){let s=e;if(s.length>0){let n=s[0];if(n==="--")s=s.slice(1);else if(n.startsWith("-")&&n!=="-"&&n.length>1)return x(`bash: eval: ${n}: invalid option
1
+ import{B as Ys,C as Qs,D as ne,E as Oe,F as K,G as ue,H as at,I as Js,J as T,K as en,L as tn,M as pe,N as Bt,O as lt,P as V,a as Bs,b as js,c as Hs,d as it,e as Z,f as W,g as de,h as J,i as he,j as Ae,k as Ft,l as ot,m as Us,n as Mt,o as qs,p as ae,q as ve,r as Zs,s as Gs,t as Wt,u as zt,v as Pe,w as Xs,x as Ks,y as fe,z as Vt}from"./chunks/chunk-3AWP5CWK.js";import{a as re,b as ie,c as se,d as oe,e as zs,f as z,g as ke,h as st,i as nt,j as Vs,k as te,l as Se,m as rt,n as ce}from"./chunks/chunk-PSW6BMXW.js";import"./chunks/chunk-NUFRM6SI.js";import{a as ge}from"./chunks/chunk-44UOCSGV.js";import"./chunks/chunk-DXB73IDG.js";var De=[{name:"echo",load:async()=>(await import("./chunks/echo-6S7WE7XB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-MV4K6AUA.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-66XGXFCD.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-5W3NU5OJ.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-7UKY4B3B.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-XFQE4ZYV.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-TDTEBHHI.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-I2SRVF7H.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-PBJT3GBF.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-FXHEKRTB.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-Y7YB677N.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-ODWUR7E6.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-S4NVAMC4.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-EM4O3U4P.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-SA7P5NJ7.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-52LRAWXT.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-HE5XARI4.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-IVQBBOKN.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-NIC6JNLH.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-NIC6JNLH.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-NIC6JNLH.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-SRMB7L6G.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-IV6HLDXU.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-6FBZTP57.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-EJUT5LXD.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-47QVBRNC.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-AXQM7FFF.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-NVKWEAZF.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-QTGVEPH5.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-EDGW5FG6.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-FKUV5GH5.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-KWQGFZH5.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-6CFXIPYZ.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-VSTNOVF5.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-I7A2VXFD.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-LRU5XCFP.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-YBTFW7MT.js")).split},{name:"column",load:async()=>(await import("./chunks/column-XPDNNO5Y.js")).column},{name:"join",load:async()=>(await import("./chunks/join-X3QYPZUA.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-2QU4NRSJ.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-YGMSVGUV.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-CFA5ZIGT.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-YPJLCQYA.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-MEM64BW3.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-NQXEC3EF.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-2UI6XINU.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-2UI6XINU.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-ATFBB6D2.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-ATFBB6D2.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-MQDK2OPD.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-4FRA6OJ7.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-CNJ54NE6.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-CNJ54NE6.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-VT2LJIDX.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-OLRNM52U.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-OLRNM52U.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-RLRYRPOJ.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-3BME25ON.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-ZLJYSBRK.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-PN3CMG7K.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-AK4QE4WR.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-X3X3N6IE.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-UWXBG6CS.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-5VRIVQYP.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-DG4E7SIS.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-KLHZSRUA.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-WKWTIZGQ.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-IUVNMBTA.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-NQP3CKRV.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-ZK6GQVSL.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-75YOGKM4.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-UBLRBDHN.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-2X4JLF4W.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-NWR32CGF.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-YUDAIS32.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-3FPDPLWJ.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-L3NDJG3F.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-L3NDJG3F.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-L3NDJG3F.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(De.push({name:"tar",load:async()=>(await import("./chunks/tar-LWIHPMT6.js")).tarCommand}),De.push({name:"yq",load:async()=>(await import("./chunks/yq-L665QPQU.js")).yqCommand}),De.push({name:"xan",load:async()=>(await import("./chunks/xan-A6VPI4HJ.js")).xanCommand}),De.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-5QVZOGER.js")).sqlite3Command}));var nn=[{name:"curl",load:async()=>(await import("./chunks/curl-XLP4VABU.js")).curlCommand}],sn=new Map;function rn(e){return{name:e.name,async execute(t,s){let n=sn.get(e.name);return n||(n=await e.load(),sn.set(e.name,n)),n.execute(t,s)}}}function xr(){return De.map(e=>e.name)}function Lr(){return nn.map(e=>e.name)}function on(e){return(e?De.filter(s=>e.includes(s.name)):De).map(rn)}function an(){return nn.map(rn)}function ln(e){return"load"in e&&typeof e.load=="function"}function Fr(e,t){return{name:e,execute:t}}function cn(e){let t=null;return{name:e.name,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}var Mr=new TextEncoder,Wr=new TextDecoder;function be(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)s[n/2]=parseInt(e.slice(n,n+2),16);return s}return t==="binary"||t==="latin1"?Uint8Array.from(e,s=>s.charCodeAt(0)):Mr.encode(e)}function Re(e,t){return t==="base64"?btoa(String.fromCharCode(...e)):t==="hex"?Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join(""):t==="binary"||t==="latin1"?String.fromCharCode(...e):Wr.decode(e)}function le(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var ct=new TextEncoder;function zr(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Ee=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,n]of Object.entries(t))zr(n)?this.writeFileSync(s,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(s,n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,n,r){let i=this.normalizePath(t);this.ensureParentDirs(i);let o=le(n),a=be(s,o);this.data.set(i,{type:"file",content:a,mode:r?.mode??420,mtime:r?.mtime??new Date})}async readFile(t,s){let n=await this.readFileBuffer(t),r=le(s);return Re(n,r)}async readFileBuffer(t){let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content instanceof Uint8Array?n.content:ct.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){let r=this.normalizePath(t),i=this.data.get(r);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=le(n),a=be(s,o);if(i?.type==="file"){let l=i.content instanceof Uint8Array?i.content:ct.encode(i.content),c=new Uint8Array(l.length+a.length);c.set(l),c.set(a,l.length),this.data.set(r,{type:"file",content:c,mode:i.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=ct.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}async lstat(t){let s=this.resolveIntermediateSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=ct.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}resolveIntermediateSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/");if(n.length<=1)return s;let r="",i=new Set;for(let o=0;o<n.length-1;o++){let a=n[o];r=`${r}/${a}`;let l=this.data.get(r),c=0,f=40;for(;l&&l.type==="symlink"&&c<f;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(r),r=this.resolveSymlink(r,l.target),l=this.data.get(r),c++}if(c>=f)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${r}/${n[n.length-1]}`}resolvePathWithSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/"),r="",i=new Set;for(let o of n){r=`${r}/${o}`;let a=this.data.get(r),l=0,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(r),r=this.resolveSymlink(r,a.target),a=this.data.get(r),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return r}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){let n=this.normalizePath(t);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let r=this.dirname(n);if(r!=="/"&&!this.data.has(r))if(s?.recursive)this.mkdirSync(r,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Set;for(;n&&n.type==="symlink";){if(r.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(s),s=this.resolveSymlink(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==s&&a.startsWith(i)){let c=a.slice(i.length),f=c.split("/")[0];f&&!c.includes("/",f.length)&&!o.has(f)&&o.set(f,{name:f,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,s){let n=this.normalizePath(t),r=this.data.get(n);if(!r){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(r.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(a,s)}}}this.data.delete(n)}async cp(t,s,n){let r=this.normalizePath(t),i=this.normalizePath(s),o=this.data.get(r);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(r);for(let l of a){let c=r==="/"?`/${l}`:`${r}/${l}`,f=i==="/"?`/${l}`:`${i}/${l}`;await this.cp(c,f,n)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}async chmod(t,s){let n=this.normalizePath(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);r.mode=s}async symlink(t,s){let n=this.normalizePath(s);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){let n=this.normalizePath(t),r=this.normalizePath(s),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(r))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(t){let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}async realpath(t){let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,n){let r=this.normalizePath(t),i=this.resolvePathWithSymlinks(r),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=n}};function Vr(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Br(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 jr(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function Hr(e){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Bs}
2
+ `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
3
+ `),e.writeFileSync("/proc/self/status",js()),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 fn(e,t){Vr(e)&&(Br(e,t),jr(e),Hr(e))}var Ur=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],qr=["braceexpand","hashall","interactive-comments"];function jt(e){let t=[],s=[...qr.map(n=>({name:n,enabled:!0})),...Ur.map(n=>({name:n,enabled:e[n]}))].sort((n,r)=>n.name.localeCompare(r.name));for(let n of s)n.enabled&&t.push(n.name);return t.join(":")}function xe(e){e.state.env.SHELLOPTS=jt(e.state.options)}var Zr=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Ht(e){let t=[];for(let s of Zr)e[s]&&t.push(s);return t.join(":")}function Ut(e){e.state.env.BASHOPTS=Ht(e.state.shoptOptions)}var Gr="BASH_ALIAS_";function un(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function dn(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function hn(e,t){return e.env[`${Gr}${t}`]}function qt(e,t,s){if(!t.name||!un(t.name))return t;let n=dn(t.name);if(!n)return t;let r=hn(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new W,o=r,a=r.endsWith(" ");if(!a)for(let u of t.args){let d=mn(u);o+=` ${d}`}let l;try{l=i.parse(o)}catch(u){if(u instanceof it)throw u;return t}if(l.statements.length!==1||l.statements[0].pipelines.length!==1||l.statements[0].pipelines[0].commands.length!==1)return pn(t,r);let c=l.statements[0].pipelines[0].commands[0];if(c.type!=="SimpleCommand")return pn(t,r);let f={...c,assignments:[...t.assignments,...c.assignments],redirections:[...c.redirections,...t.redirections],line:t.line};if(a&&t.args.length>0&&(f={...f,args:[...f.args,...t.args]},f.args.length>0)){let u=f.args[0];if(un(u)){let d=dn(u);if(d&&hn(e,d)){let h={type:"SimpleCommand",name:u,args:f.args.slice(1),assignments:[],redirections:[]},m=qt(e,h,s);m!==h&&(f={...f,name:m.name,args:[...m.args]})}}}return f}catch(i){throw s.delete(n),i}}function pn(e,t){let s=t;for(let o of e.args){let a=mn(o);s+=` ${a}`}let n=new W,r=n.parseWordFromString("eval",!1,!1),i=n.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:r,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function mn(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${s.value}'`;break;case"DoubleQuoted":t+=`"${s.parts.map(n=>n.type==="Literal"?n.value:`$${n.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${s.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${s.expression}))`;break;case"Glob":t+=s.pattern;break;default:break}return t}async function yn(e,t){let s=t.parts.map(f=>f.type==="Literal"?f.value:"\0").join(""),n=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!n||!s.endsWith(")"))return null;let r=n[1],i=[],o=!1,a="",l=!1;for(let f of t.parts)if(f.type==="Literal"){let u=f.value;if(!o){let d=u.indexOf("=(");d!==-1&&(o=!0,u=u.slice(d+2))}if(o){u.endsWith(")")&&(u=u.slice(0,-1));let d=u.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(a||l)&&(i.push(a),a="",l=!1):h&&(a+=h)}}else if(o)if(f.type==="BraceExpansion")if(/^\[.+\]=/.test(a))a+=ot({type:"Word",parts:[f]});else{(a||l)&&(i.push(a),a="",l=!1);let d=await pe(e,{type:"Word",parts:[f]});i.push(...d.values)}else{(f.type==="SingleQuoted"||f.type==="DoubleQuoted"||f.type==="Escaped")&&(l=!0);let u=await T(e,{type:"Word",parts:[f]});a+=u}(a||l)&&i.push(a);let c=i.map(f=>/^\[.+\]=/.test(f)?f:f===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(f)&&!f.startsWith("'")&&!f.startsWith('"')?`'${f.replace(/'/g,"'\\''")}'`:f);return`${r}=(${c.join(" ")})`}async function wn(e,t){let s=-1,n=-1,r=!1;for(let p=0;p<t.parts.length;p++){let w=t.parts[p];if(w.type==="Literal"){let b=w.value.indexOf("+=");if(b!==-1){let C=w.value.slice(0,b);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(C)){s=p,n=b,r=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(C)){s=p,n=b,r=!0;break}}let $=w.value.indexOf("=");if($!==-1&&($===0||w.value[$-1]!=="+")){let C=w.value.slice(0,$);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(C)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(C)){s=p,n=$;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),o=t.parts[s];if(o.type!=="Literal")return null;let a=r?2:1,l=o.value.slice(0,n),c=o.value.slice(n+a),f=t.parts.slice(s+1),u="";for(let p of i)u+=await T(e,{type:"Word",parts:[p]});u+=l;let d={type:"Word",parts:c!==""?[{type:"Literal",value:c},...f]:f},h=d.parts.length>0?await T(e,d):"";return`${u}${r?"+=":"="}${h}`}var Xr=["tar","yq","xan","sqlite3"];function gn(e){return Xr.includes(e)}var L=Object.freeze({stdout:"",stderr:"",exitCode:0});function F(e=""){return{stdout:e,stderr:"",exitCode:0}}function S(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function P(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function q(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function $e(e,t,s="",n=""){throw new te(e,t,s,n)}function Zt(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Se;return L}if(t.length>1)throw new z(1,"",`bash: break: too many arguments
4
+ `);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new z(128,"",`bash: break: ${t[0]}: numeric argument required
5
+ `);s=n}throw new re(s)}async function Gt(e,t){let s,n=!1,r=!1,i=0;for(;i<t.length;)if(t[i]==="--"){i++;break}else if(t[i]==="-L")r=!1,i++;else if(t[i]==="-P")r=!0,i++;else if(t[i].startsWith("-")&&t[i]!=="-")i++;else break;let o=t.slice(i);if(o.length===0||o[0]==="~"?s=e.state.env.HOME||"/":o[0]==="-"?(s=e.state.previousDir,n=!0):s=o[0],!s.startsWith("/")&&!s.startsWith("./")&&!s.startsWith("../")&&s!=="."&&s!==".."){let u=e.state.env.CDPATH;if(u){let d=u.split(":").filter(h=>h);for(let h of d){let m=h.startsWith("/")?`${h}/${s}`:`${e.state.cwd}/${h}/${s}`;try{if((await e.fs.stat(m)).isDirectory){s=m,n=!0;break}}catch{}}}}let l=(s.startsWith("/")?s:`${e.state.cwd}/${s}`).split("/").filter(u=>u&&u!=="."),c="";for(let u of l)if(u==="..")c=c.split("/").slice(0,-1).join("/")||"/";else{c=c?`${c}/${u}`:`/${u}`;try{if(!(await e.fs.stat(c)).isDirectory)return S(`bash: cd: ${s}: Not a directory
6
+ `)}catch{return S(`bash: cd: ${s}: No such file or directory
7
+ `)}}let f=c||"/";if(r)try{f=await e.fs.realpath(f)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=f,e.state.env.PWD=e.state.cwd,e.state.env.OLDPWD=e.state.previousDir,F(n?`${f}
8
+ `:"")}function Xt(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Kr=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function ft(e){return Kr.includes(e)}async function ut(e,t,s){let n=Xt(e,s);switch(t){case"-e":case"-a":return e.fs.exists(n);case"-f":return await e.fs.exists(n)?(await e.fs.stat(n)).isFile:!1;case"-d":return await e.fs.exists(n)?(await e.fs.stat(n)).isDirectory:!1;case"-r":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&256)!==0:!1;case"-w":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&128)!==0:!1;case"-x":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&64)!==0:!1;case"-s":return await e.fs.exists(n)?(await e.fs.stat(n)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(n)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&512)!==0:!1;case"-g":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(n);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].some(i=>n===i||n.endsWith(i));case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(n);default:return!1}}var Yr=["-nt","-ot","-ef"];function dt(e){return Yr.includes(e)}async function ht(e,t,s,n){let r=Xt(e,s),i=Xt(e,n);switch(t){case"-nt":try{let o=await e.fs.stat(r),a=await e.fs.stat(i);return o.mtime>a.mtime}catch{return!1}case"-ot":try{let o=await e.fs.stat(r),a=await e.fs.stat(i);return o.mtime<a.mtime}catch{return!1}case"-ef":try{if(!await e.fs.exists(r)||!await e.fs.exists(i))return!1;let o=e.fs.resolvePath(e.state.cwd,r),a=e.fs.resolvePath(e.state.cwd,i);return o===a}catch{return!1}default:return!1}}var Qr=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function pt(e){return Qr.has(e)}function mt(e,t,s){switch(e){case"-eq":return t===s;case"-ne":return t!==s;case"-lt":return t<s;case"-le":return t<=s;case"-gt":return t>s;case"-ge":return t>=s}}function Ze(e){return e==="="||e==="=="||e==="!="}function yt(e,t,s,n=!1,r=!1,i=!1){if(n){let a=Le(t,s,r,i);return e==="!="?!a:a}if(r){let a=t.toLowerCase()===s.toLowerCase();return e==="!="?!a:a}let o=t===s;return e==="!="?!o:o}var Jr=new Set(["-z","-n"]);function wt(e){return Jr.has(e)}function gt(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function vt(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],r=s[2];if(e.state.associativeArrays?.has(n)){let a=r;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[c]||""),`${n}_${a}`in e.state.env}let o;try{let a=new W,l=Z(a,r);o=await V(e,l.expression)}catch{if(/^-?\d+$/.test(r))o=Number.parseInt(r,10);else{let a=e.state.env[r];o=a?Number.parseInt(a,10):0}}if(o<0){let a=J(e,n),l=e.state.currentLine;if(a.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${n}: bad array subscript
9
+ `,!1;if(o=Math.max(...a)+1+o,o<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${n}: bad array subscript
10
+ `,!1}return`${n}_${o}`in e.state.env}return t in e.state.env?!0:e.state.associativeArrays?.has(t)?Ae(e,t).length>0:J(e,t).length>0}async function _e(e,t){switch(t.type){case"CondBinary":{let s=await T(e,t.left),n=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),r;if(t.operator==="=~")if(n){let i=await T(e,t.right);r=Qs(i)}else r=await en(e,t.right);else Ze(t.operator)&&!n?r=await tn(e,t.right):r=await T(e,t.right);if(Ze(t.operator)){let i=e.state.shoptOptions.nocasematch;return yt(t.operator,s,r,!n,i,!0)}if(pt(t.operator))return mt(t.operator,await bn(e,s),await bn(e,r));if(dt(t.operator))return ht(e,t.operator,s,r);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=ni(r),a=new RegExp(o,i?"i":""),l=s.match(a);if(he(e,"BASH_REMATCH"),l)for(let c=0;c<l.length;c++)e.state.env[`BASH_REMATCH_${c}`]=l[c]||"";return l!==null}catch{throw new Error("syntax error in regular expression")}case"<":return s<r;case">":return s>r;default:return!1}}case"CondUnary":{let s=await T(e,t.operand);return ft(t.operator)?ut(e,t.operator,s):wt(t.operator)?gt(t.operator,s):t.operator==="-v"?await vt(e,s):t.operator==="-o"?Yt(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await T(e,t.operand.expression.word)})`!=="":!await _e(e,t.operand);case"CondAnd":return await _e(e,t.left)?await _e(e,t.right):!1;case"CondOr":return await _e(e,t.left)?!0:await _e(e,t.right);case"CondGroup":return await _e(e,t.expression);case"CondWord":return await T(e,t.word)!=="";default:return!1}}async function Ge(e,t){if(t.length===0)return P("","",1);if(t.length===1)return q(!!t[0]);if(t.length===2){let n=t[0],r=t[1];return n==="("?S(`test: '(' without matching ')'
11
+ `,2):ft(n)?q(await ut(e,n,r)):wt(n)?q(gt(n,r)):n==="!"?q(!r):n==="-v"?q(await vt(e,r)):n==="-o"?q(Yt(e,r)):n==="="||n==="=="||n==="!="||n==="<"||n===">"||n==="-eq"||n==="-ne"||n==="-lt"||n==="-le"||n==="-gt"||n==="-ge"||n==="-nt"||n==="-ot"||n==="-ef"?S(`test: ${n}: unary operator expected
12
+ `,2):P("","",1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(Ze(r))return q(yt(r,n,i));if(pt(r)){let o=bt(n),a=bt(i);return!o.valid||!a.valid?P("","",2):q(mt(r,o.value,a.value))}if(dt(r))return q(await ht(e,r,n,i));switch(r){case"-a":return q(n!==""&&i!=="");case"-o":return q(n!==""||i!=="");case">":return q(n>i);case"<":return q(n<i)}if(n==="!"){let o=await Ge(e,[r,i]);return P("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(n==="("&&i===")")return q(r!=="")}if(t.length===4){if(t[0]==="!"){let n=await Ge(e,t.slice(1));return P("",n.stderr,n.exitCode===0?1:n.exitCode===1?0:n.exitCode)}if(t[0]==="("&&t[3]===")")return Ge(e,[t[1],t[2]])}let s=await $n(e,t,0);return s.pos<t.length?S(`test: too many arguments
13
+ `,2):q(s.value)}async function $n(e,t,s){return ei(e,t,s)}async function ei(e,t,s){let{value:n,pos:r}=await vn(e,t,s);for(;t[r]==="-o";){let i=await vn(e,t,r+1);n=n||i.value,r=i.pos}return{value:n,pos:r}}async function vn(e,t,s){let{value:n,pos:r}=await Kt(e,t,s);for(;t[r]==="-a";){let i=await Kt(e,t,r+1);n=n&&i.value,r=i.pos}return{value:n,pos:r}}async function Kt(e,t,s){if(t[s]==="!"){let{value:n,pos:r}=await Kt(e,t,s+1);return{value:!n,pos:r}}return ti(e,t,s)}async function ti(e,t,s){let n=t[s];if(n==="("){let{value:i,pos:o}=await $n(e,t,s+1);return{value:i,pos:t[o]===")"?o+1:o}}let r=t[s+1];if(Ze(r)){let i=n,o=t[s+2]??"";return{value:yt(r,i,o),pos:s+3}}if(pt(r)){let i=bt(n),o=bt(t[s+2]??"0");return!i.valid||!o.valid?{value:!1,pos:s+3}:{value:mt(r,i.value,o.value),pos:s+3}}if(dt(r)){let i=n,o=t[s+2]??"";return{value:await ht(e,r,i,o),pos:s+3}}if(ft(n)){let i=t[s+1]??"";return{value:await ut(e,n,i),pos:s+2}}if(wt(n)){let i=t[s+1]??"";return{value:gt(n,i),pos:s+2}}if(n==="-v"){let i=t[s+1]??"";return{value:await vt(e,i),pos:s+2}}if(n==="-o"){let i=t[s+1]??"";return{value:Yt(e,i),pos:s+2}}return{value:n!==void 0&&n!=="",pos:s+1}}function Le(e,t,s=!1,n=!1){let r=`^${Sn(t,n)}$`,i=s?"is":"s";return new RegExp(r,i).test(e)}function Sn(e,t){let s="";for(let n=0;n<e.length;n++){let r=e[n];if(t&&(r==="@"||r==="*"||r==="+"||r==="?"||r==="!")&&n+1<e.length&&e[n+1]==="("){let i=An(e,n+1);if(i!==-1){let o=e.slice(n+2,i),a=Pn(o),l=a.map(f=>Sn(f,t)),c=l.length>0?l.join("|"):"(?:)";if(r==="@")s+=`(?:${c})`;else if(r==="*")s+=`(?:${c})*`;else if(r==="+")s+=`(?:${c})+`;else if(r==="?")s+=`(?:${c})?`;else if(r==="!")if(i<e.length-1){let u=a.map(h=>_n(h,t));if(u.every(h=>h!==null)&&u.every(h=>h===u[0])&&u[0]!==null){let h=u[0];if(h===0)s+="(?:.+)";else{let m=[];h>0&&m.push(`.{0,${h-1}}`),m.push(`.{${h+1},}`),m.push(`(?!(?:${c})).{${h}}`),s+=`(?:${m.join("|")})`}}else s+=`(?:(?!(?:${c})).)*?`}else s+=`(?!(?:${c})$).*`;n=i;continue}}if(r==="\\")if(n+1<e.length){let i=e[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,n++}else s+="\\\\";else if(r==="*")s+=".*";else if(r==="?")s+=".";else if(r==="["){let i=e.indexOf("]",n+1);i!==-1?(s+=e.slice(n,i+1),n=i):s+="\\["}else/[\\^$.|+(){}]/.test(r)?s+=`\\${r}`:s+=r}return s}function An(e,t){let s=1,n=t+1;for(;n<e.length&&s>0;){let r=e[n];if(r==="\\"){n+=2;continue}if(r==="(")s++;else if(r===")"&&(s--,s===0))return n;n++}return-1}function Pn(e){let t=[],s="",n=0,r=0;for(;r<e.length;){let i=e[r];if(i==="\\"){s+=i,r+1<e.length?(s+=e[r+1],r+=2):r++;continue}i==="("?(n++,s+=i):i===")"?(n--,s+=i):i==="|"&&n===0?(t.push(s),s=""):s+=i,r++}return t.push(s),t}function _n(e,t){let s=0,n=0;for(;n<e.length;){let r=e[n];if(t&&(r==="@"||r==="*"||r==="+"||r==="?"||r==="!")&&n+1<e.length&&e[n+1]==="("){let i=An(e,n+1);if(i!==-1){if(r==="@"){let o=e.slice(n+2,i),l=Pn(o).map(c=>_n(c,t));if(l.every(c=>c!==null)&&l.every(c=>c===l[0])){s+=l[0],n=i+1;continue}return null}return null}}if(r==="*")return null;if(r==="?"){s+=1,n++;continue}if(r==="["){let i=e.indexOf("]",n+1);if(i!==-1){s+=1,n=i+1;continue}s+=1,n++;continue}if(r==="\\"){s+=1,n+=2;continue}s+=1,n++}return s}function Yt(e,t){let n={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}[t];return n?n():!1}async function bn(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 En(t);try{let s=new W,n=Z(s,t);return await V(e,n.expression)}catch{return En(t)}}function si(e,t){let s=0;for(let n of e){let r;if(n>="0"&&n<="9")r=n.charCodeAt(0)-48;else if(n>="a"&&n<="z")r=n.charCodeAt(0)-97+10;else if(n>="A"&&n<="Z")r=n.charCodeAt(0)-65+36;else if(n==="@")r=62;else if(n==="_")r=63;else return Number.NaN;if(r>=t)return Number.NaN;s=s*t+r}return s}function En(e){if(e=e.trim(),e==="")return 0;let t=!1;e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1));let s,n=e.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(n){let r=Number.parseInt(n[1],10);r>=2&&r<=64?s=si(n[2],r):s=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?s=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?s=Number.parseInt(e,8):s=Number.parseInt(e,10);return Number.isNaN(s)&&(s=0),t?-s:s}function bt(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let s=Number.parseInt(e,10);return Number.isNaN(s)?{value:0,valid:!1}:{value:t?-s:s,valid:!0}}function ni(e){let t="",s=0;for(;s<e.length;)if(e[s]==="\\"&&s+1<e.length)t+=e[s]+e[s+1],s+=2;else if(e[s]==="["){let n=ri(e,s);t+=n.converted,s=n.endIndex}else t+=e[s],s++;return t}function ri(e,t){let s=t+1,n="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(n+="^",s++);let r=!1;s<e.length&&e[s]==="]"&&(r=!0,s++);let i=!1;s<e.length&&e[s]==="["&&s+1<e.length&&e[s+1]!==":"&&(i=!0,s++);let o="",a=!1;for(;s<e.length;){let l=e[s];if(l==="]"){a=!0,s++;break}if(l==="["&&s+1<e.length&&e[s+1]===":"){let c=e.indexOf(":]",s+2);if(c!==-1){let f=e.slice(s+2,c);o+=ii(f),s=c+2;continue}}if(l==="["&&s+1<e.length){let c=e[s+1];if(c==="."||c==="="){let f=`${c}]`,u=e.indexOf(f,s+2);if(u!==-1){let d=e.slice(s+2,u);o+=d,s=u+2;continue}}}if(l==="\\"&&s+1<e.length){o+=l+e[s+1],s+=2;continue}o+=l,s++}return a?(r&&(n+="\\]"),i&&(n+="\\["),n+=o,n+="]",{converted:n,endIndex:s}):{converted:"\\[",endIndex:t+1}}function ii(e){return{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"}[e]??""}function me(e){let t=[],s="",n=!1,r=!1,i=!1,o=!1;for(let a of e){if(i){s+=a,i=!1,o=!0;continue}if(a==="\\"){i=!0;continue}if(a==="'"&&!r){n||(o=!0),n=!n;continue}if(a==='"'&&!n){r||(o=!0),r=!r;continue}if((a===" "||a===" "||a===`
14
+ `)&&!n&&!r){o&&(t.push(s),s="",o=!1);continue}s+=a,o=!0}return o&&t.push(s),t}function Et(e){let t=[],s=0;for(;s<e.length;){for(;s<e.length&&/\s/.test(e[s]);)s++;if(s>=e.length)break;if(e[s]!=="["){s++;continue}s++;let n="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)n+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&e[s]!=="]"&&e[s]!=="=";)n+=e[s],s++;for(;s<e.length&&e[s]!=="]";)s++;if(e[s]==="]"&&s++,e[s]!=="=")continue;s++;let r="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)e[s]==="\\"&&s+1<e.length&&s++,r+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&!/\s/.test(e[s]);)r+=e[s],s++;t.push([n,r])}return t}function Nn(e){let t=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(t)return{name:t[1],isArray:!0,arrayElements:me(t[2])};let s=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(s)return{name:s[1],isArray:!1,arrayIndex:s[2],value:s[3]};if(e.includes("=")){let n=e.indexOf("=");return{name:e.slice(0,n),isArray:!1,value:e.slice(n+1)}}return{name:e,isArray:!1}}async function oi(e,t){try{let s=new W,n=Z(s,t);return await V(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}async function Cn(e,t,s={}){let{name:n,isArray:r,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:l=!1,checkReadonly:c=!0}=s;if(c){let f=K(e,n);if(f)return f}if(r&&i){for(let f=0;f<i.length;f++)e.state.env[`${n}_${f}`]=i[f];e.state.env[`${n}__length`]=String(i.length)}else if(a!==void 0&&o!==void 0){let f=await oi(e,a);e.state.env[`${n}_${f}`]=o;let u=parseInt(e.state.env[`${n}__length`]??"0",10);f>=u&&(e.state.env[`${n}__length`]=String(f+1))}else o!==void 0&&(e.state.env[n]=o);return l&&ne(e,n),null}function Ne(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function Fe(e,t){return e.state.localVarDepth?.get(t)}function $t(e,t){e.state.localVarDepth?.delete(t)}function kn(e,t,s){e.state.localVarStack=e.state.localVarStack||new Map;let n=e.state.localVarStack.get(t)||[];n.push({value:s,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,n)}function St(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function On(e,t){if(e.state.localVarStack)for(let[s,n]of e.state.localVarStack.entries()){for(;n.length>0&&n[n.length-1].scopeIndex===t;)n.pop();n.length===0&&e.state.localVarStack.delete(s)}}var Qt=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Dn(e){return Qt.has(e)}var Jt=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Xe=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);async function Te(e,t,s,n){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory
15
+ `;if(n.checkNoclobber&&e.state.options.noclobber&&!n.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file
16
+ `}catch{}return null}function Y(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return"utf8";return"binary"}function ai(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),o=r+n+1,a=t.slice(o),l=a.indexOf(":");if(l===-1)return null;let c=Number.parseInt(a.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let f=a.slice(l+1);return{path:i,position:c,content:f}}async function Tn(e,t){let s=new Map;for(let n=0;n<t.length;n++){let r=t[n];if(r.target.type==="HereDoc")continue;if(r.operator===">&"||r.operator==="<&"){if(Bt(e,r.target))return{targets:s,error:`bash: $@: ambiguous redirect
17
+ `};s.set(n,await T(e,r.target))}else{let o=await lt(e,r.target);if("error"in o)return{targets:s,error:o.error};s.set(n,o.target)}}return{targets:s}}function li(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd;return e.state.nextFd++,t}async function At(e,t){for(let s of t){if(!s.fdVariable)continue;if(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),(s.operator===">&"||s.operator==="<&")&&s.target.type==="Word"&&await T(e,s.target)==="-"){let i=e.state.env[s.fdVariable];if(i!==void 0){let o=Number.parseInt(i,10);Number.isNaN(o)||e.state.fileDescriptors.delete(o)}continue}let n=li(e);if(e.state.env[s.fdVariable]=String(n),s.target.type==="Word"){let r=await T(e,s.target);if(s.operator===">&"||s.operator==="<&"){let i=Number.parseInt(r,10);if(!Number.isNaN(i)){let o=e.state.fileDescriptors.get(i);o!==void 0&&e.state.fileDescriptors.set(n,o);continue}}if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let i=e.fs.resolvePath(e.state.cwd,r);(s.operator===">"||s.operator===">|"||s.operator==="&>")&&await e.fs.writeFile(i,"","binary"),e.state.fileDescriptors.set(n,`__file__:${i}`)}else if(s.operator==="<<<")e.state.fileDescriptors.set(n,`${r}
18
+ `);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,r),o=await e.fs.readFile(i);e.state.fileDescriptors.set(n,o)}catch{return P("",`bash: ${r}: No such file or directory
19
+ `,1)}}}return null}async function ye(e,t){for(let s of t){if(s.target.type==="HereDoc")continue;let n=s.operator===">&";if(s.operator!==">"&&s.operator!==">|"&&s.operator!=="&>"&&!n)continue;let r;if(n){if(r=await T(e,s.target),r==="-"||!Number.isNaN(Number.parseInt(r,10))||s.fd!=null)continue}else{let a=await lt(e,s.target);if("error"in a)return P("",a.error,1);r=a.target}let i=e.fs.resolvePath(e.state.cwd,r),o=s.operator===">|";try{let a=await e.fs.stat(i);if(a.isDirectory)return P("",`bash: ${r}: Is a directory
20
+ `,1);if(e.state.options.noclobber&&!o&&!a.isDirectory&&r!=="/dev/null")return P("",`bash: ${r}: cannot overwrite existing file
21
+ `,1)}catch{}if(r!=="/dev/null"&&r!=="/dev/stdout"&&r!=="/dev/stderr"&&r!=="/dev/full"&&await e.fs.writeFile(i,"","binary"),r==="/dev/full")return P("",`bash: /dev/full: No space left on device
22
+ `,1)}return null}async function j(e,t,s,n){let{stdout:r,stderr:i,exitCode:o}=t;for(let c=0;c<s.length;c++){let f=s[c];if(f.target.type==="HereDoc")continue;let u,d=n?.get(c);if(d!==void 0)u=d;else if(f.operator===">&"||f.operator==="<&"){if(Bt(e,f.target)){i+=`bash: $@: ambiguous redirect
23
+ `,o=1,r="";continue}u=await T(e,f.target)}else{let m=await lt(e,f.target);if("error"in m){i+=m.error,o=1,r="";continue}u=m.target}if(!f.fdVariable)switch(f.operator){case">":case">|":{let h=f.fd??1,m=f.operator===">|";if(h===1){if(u==="/dev/stdout")break;if(u==="/dev/stderr"){i+=r,r="";break}if(u==="/dev/full"){i+=`bash: echo: write error: No space left on device
24
+ `,o=1,r="";break}let p=e.fs.resolvePath(e.state.cwd,u),w=await Te(e,p,u,{checkNoclobber:!0,isClobber:m});if(w){i+=w,o=1,r="";break}await e.fs.writeFile(p,r,Y(r)),r=""}else if(h===2){if(u==="/dev/stderr")break;if(u==="/dev/stdout"){r+=i,i="";break}if(u==="/dev/full"){i+=`bash: echo: write error: No space left on device
25
+ `,o=1;break}if(u==="/dev/null")i="";else{let p=e.fs.resolvePath(e.state.cwd,u),w=await Te(e,p,u,{checkNoclobber:!0,isClobber:m});if(w){i+=w,o=1;break}await e.fs.writeFile(p,i,Y(i)),i=""}}break}case">>":{let h=f.fd??1;if(h===1){if(u==="/dev/stdout")break;if(u==="/dev/stderr"){i+=r,r="";break}if(u==="/dev/full"){i+=`bash: echo: write error: No space left on device
26
+ `,o=1,r="";break}let m=e.fs.resolvePath(e.state.cwd,u),p=await Te(e,m,u,{});if(p){i+=p,o=1,r="";break}await e.fs.appendFile(m,r,Y(r)),r=""}else if(h===2){if(u==="/dev/stderr")break;if(u==="/dev/stdout"){r+=i,i="";break}if(u==="/dev/full"){i+=`bash: echo: write error: No space left on device
27
+ `,o=1;break}let m=e.fs.resolvePath(e.state.cwd,u),p=await Te(e,m,u,{});if(p){i+=p,o=1;break}await e.fs.appendFile(m,i,Y(i)),i=""}break}case">&":case"<&":{let h=f.fd??1;if(u==="-")break;if(u.endsWith("-")){let m=u.slice(0,-1),p=Number.parseInt(m,10);if(!Number.isNaN(p)){let w=e.state.fileDescriptors?.get(p);w!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,w),p>=3&&e.state.fileDescriptors?.delete(p)):p===1||p===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,`__dupout__:${p}`)):p===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,`__dupin__:${p}`)):p>=3&&(i+=`bash: ${p}: Bad file descriptor
28
+ `,o=1)}break}if(u==="2"||u==="&2")h===1&&(i+=r,r="");else if(u==="1"||u==="&1")r+=i,i="";else{let m=Number.parseInt(u,10);if(Number.isNaN(m)){if(f.operator===">&"){let p=e.fs.resolvePath(e.state.cwd,u),w=await Te(e,p,u,{checkNoclobber:!0});if(w){i=w,o=1,r="";break}if(f.fd==null){let b=r+i;await e.fs.writeFile(p,b,Y(b)),r="",i=""}else h===1?(await e.fs.writeFile(p,r,Y(r)),r=""):h===2&&(await e.fs.writeFile(p,i,Y(i)),i="")}}else{let p=e.state.fileDescriptors?.get(m);if(p?.startsWith("__file__:")){let w=p.slice(9);h===1?(await e.fs.appendFile(w,r,Y(r)),r=""):h===2&&(await e.fs.appendFile(w,i,Y(i)),i="")}else if(p?.startsWith("__rw__:")){let w=ai(p);w&&(h===1?(await e.fs.appendFile(w.path,r,Y(r)),r=""):h===2&&(await e.fs.appendFile(w.path,i,Y(i)),i=""))}else if(p?.startsWith("__dupout__:")){let w=Number.parseInt(p.slice(11),10);if(w!==1)if(w===2)h===1&&(i+=r,r="");else{let b=e.state.fileDescriptors?.get(w);if(b?.startsWith("__file__:")){let $=b.slice(9);h===1?(await e.fs.appendFile($,r,Y(r)),r=""):h===2&&(await e.fs.appendFile($,i,Y(i)),i="")}}}else p?.startsWith("__dupin__:")?(i+=`bash: ${m}: Bad file descriptor
29
+ `,o=1,r=""):m>=3&&(i+=`bash: ${m}: Bad file descriptor
30
+ `,o=1,r="")}}break}case"&>":{if(u==="/dev/full"){i=`bash: echo: write error: No space left on device
31
+ `,o=1,r="";break}let h=e.fs.resolvePath(e.state.cwd,u),m=await Te(e,h,u,{checkNoclobber:!0});if(m){i=m,o=1,r="";break}let p=r+i;await e.fs.writeFile(h,p,Y(p)),r="",i="";break}case"&>>":{if(u==="/dev/full"){i=`bash: echo: write error: No space left on device
32
+ `,o=1,r="";break}let h=e.fs.resolvePath(e.state.cwd,u),m=await Te(e,h,u,{});if(m){i=m,o=1,r="";break}let p=r+i;await e.fs.appendFile(h,p,Y(p)),r="",i="";break}}}let a=e.state.fileDescriptors?.get(1);if(a){if(a==="__dupout__:2")i+=r,r="";else if(a.startsWith("__file__:")){let c=a.slice(9);await e.fs.appendFile(c,r,Y(r)),r=""}else if(a.startsWith("__file_append__:")){let c=a.slice(16);await e.fs.appendFile(c,r,Y(r)),r=""}}let l=e.state.fileDescriptors?.get(2);if(l){if(l==="__dupout__:1")r+=i,i="";else if(l.startsWith("__file__:")){let c=l.slice(9);await e.fs.appendFile(c,i,Y(i)),i=""}else if(l.startsWith("__file_append__:")){let c=l.slice(16);await e.fs.appendFile(c,i,Y(i)),i=""}}return P(r,i,o)}function In(e,t){if(e.state.options.posix&&Qt.has(t.name)){let n=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
33
+ `;throw new z(2,"",n)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),L}async function ci(e,t){let s="";for(let n of t)if((n.operator==="<<"||n.operator==="<<-")&&n.target.type==="HereDoc"){let r=n.target,i=await T(e,r.content);r.stripTabs&&(i=i.split(`
34
+ `).map(a=>a.replace(/^\t+/,"")).join(`
35
+ `)),(n.fd??0)===0&&(s=i)}else if(n.operator==="<<<"&&n.target.type==="Word")s=`${await T(e,n.target)}
36
+ `;else if(n.operator==="<"&&n.target.type==="Word"){let r=await T(e,n.target),i=e.fs.resolvePath(e.state.cwd,r);try{s=await e.fs.readFile(i)}catch{}}return s}async function Pt(e,t,s,n="",r){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,$e(`${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(r??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i={};for(let c=0;c<s.length;c++)i[String(c+1)]=e.state.env[String(c+1)],e.state.env[String(c+1)]=s[c];i["@"]=e.state.env["@"],i["#"]=e.state.env["#"],e.state.env["@"]=s.join(" "),e.state.env["#"]=String(s.length);let o=()=>{let c=e.state.localScopes.length-1,f=e.state.localScopes.pop();if(f)for(let[u,d]of f)d===void 0?delete e.state.env[u]:e.state.env[u]=d;if(On(e,c),e.state.fullyUnsetLocals)for(let[u,d]of e.state.fullyUnsetLocals.entries())d===c&&e.state.fullyUnsetLocals.delete(u);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let u=e.state.localExportedVars.pop();if(u)for(let d of u)e.state.exportedVars?.delete(d)}for(let[u,d]of Object.entries(i))d===void 0?delete e.state.env[u]:e.state.env[u]=d;e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},{targets:a,error:l}=await Tn(e,t.redirections);if(l)return o(),P("",l,1);try{let c=await ci(e,t.redirections),f=n||c,u=await e.executeCommand(t.body,f);return o(),j(e,u,t.redirections,a)}catch(c){if(o(),c instanceof se){let f=P(c.stdout,c.stderr,c.exitCode);return j(e,f,t.redirections,a)}throw c}}var xn=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],ts=[".",":","[","alias","bg","bind","break","builtin","caller","cd","command","compgen","complete","compopt","continue","declare","dirs","disown","echo","enable","eval","exec","exit","export","false","fc","fg","getopts","hash","help","history","jobs","kill","let","local","logout","mapfile","popd","printf","pushd","pwd","read","readarray","readonly","return","set","shift","shopt","source","suspend","test","times","trap","true","type","typeset","ulimit","umask","unalias","unset","wait"],fi=["autocd","assoc_expand_once","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","dotglob","execfail","expand_aliases","extdebug","extglob","extquote","failglob","force_fignore","globasciiranges","globstar","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lastpipe","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","nocaseglob","nocasematch","nullglob","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath","xpg_echo"],ui=ts;async function ss(e,t){let s=[],n=null,r="",i="",o=null,a=!1,l=!1,c=!1,f=null,u=null,d=null,h=[],m=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let y=0;y<t.length;y++){let g=t[y];if(g==="-v")s.push("variable");else if(g==="-e")s.push("export");else if(g==="-f")s.push("file");else if(g==="-d")s.push("directory");else if(g==="-k")s.push("keyword");else if(g==="-A"){if(y++,y>=t.length)return S(`compgen: -A: option requires an argument
37
+ `,2);let v=t[y];if(!m.includes(v))return S(`compgen: ${v}: invalid action name
38
+ `,2);s.push(v)}else if(g==="-W"){if(y++,y>=t.length)return S(`compgen: -W: option requires an argument
39
+ `,2);n=t[y]}else if(g==="-P"){if(y++,y>=t.length)return S(`compgen: -P: option requires an argument
40
+ `,2);r=t[y]}else if(g==="-S"){if(y++,y>=t.length)return S(`compgen: -S: option requires an argument
41
+ `,2);i=t[y]}else if(g==="-o"){if(y++,y>=t.length)return S(`compgen: -o: option requires an argument
42
+ `,2);let v=t[y];if(v==="plusdirs")a=!0;else if(v==="dirnames")l=!0;else if(v==="default")c=!0;else if(!(v==="filenames"||v==="nospace"||v==="bashdefault"||v==="noquote"))return S(`compgen: ${v}: invalid option name
43
+ `,2)}else if(g==="-F"){if(y++,y>=t.length)return S(`compgen: -F: option requires an argument
44
+ `,2);u=t[y]}else if(g==="-C"){if(y++,y>=t.length)return S(`compgen: -C: option requires an argument
45
+ `,2);d=t[y]}else if(g==="-X"){if(y++,y>=t.length)return S(`compgen: -X: option requires an argument
46
+ `,2);f=t[y]}else if(g==="-G"){if(y++,y>=t.length)return S(`compgen: -G: option requires an argument
47
+ `,2)}else if(g==="--"){h.push(...t.slice(y+1));break}else g.startsWith("-")||h.push(g)}o=h[0]??null;let p=[];if(l){let y=await es(e,o);p.push(...y)}if(c){let y=await Rn(e,o);p.push(...y)}for(let y of s)if(y==="variable"){let g=di(e,o);p.push(...g)}else if(y==="export"){let g=hi(e,o);p.push(...g)}else if(y==="function"){let g=pi(e,o);p.push(...g)}else if(y==="builtin"){let g=mi(o);p.push(...g)}else if(y==="keyword"){let g=yi(o);p.push(...g)}else if(y==="alias"){let g=wi(e,o);p.push(...g)}else if(y==="shopt"){let g=gi(o);p.push(...g)}else if(y==="helptopic"){let g=vi(o);p.push(...g)}else if(y==="directory"){let g=await es(e,o);p.push(...g)}else if(y==="file"){let g=await Rn(e,o);p.push(...g)}else if(y==="user"){let g=bi(o);p.push(...g)}else if(y==="command"){let g=await Ei(e,o);p.push(...g)}if(n!==null)try{let y=await $i(e,n),g=Si(e,y);for(let v of g)(o===null||v.startsWith(o))&&p.push(v)}catch{return P("","",1)}if(a){let y=await es(e,o);for(let g of y)p.includes(g)||p.push(g)}let w="";if(u!==null){let y=e.state.functions.get(u);if(y){let g={};g.COMP_WORDS__length=e.state.env.COMP_WORDS__length,e.state.env.COMP_WORDS__length="0",g.COMP_CWORD=e.state.env.COMP_CWORD,e.state.env.COMP_CWORD="-1",g.COMP_LINE=e.state.env.COMP_LINE,e.state.env.COMP_LINE="",g.COMP_POINT=e.state.env.COMP_POINT,e.state.env.COMP_POINT="0";let v={};for(let k of Object.keys(e.state.env))(k==="COMPREPLY"||k.startsWith("COMPREPLY_")||k==="COMPREPLY__length")&&(v[k]=e.state.env[k],delete e.state.env[k]);let _=["compgen",h[0]??"",""];try{let k=await Pt(e,y,_,"");if(k.exitCode!==0)return Me(e,g),Me(e,v),P("",k.stderr,1);w=k.stdout;let I=Ai(e);p.push(...I)}catch{return Me(e,g),Me(e,v),P("","",1)}Me(e,g),Me(e,v)}}if(d!==null)try{let y=de(d),g=await e.executeScript(y);if(g.exitCode!==0)return P("",g.stderr,g.exitCode);if(g.stdout){let v=g.stdout.split(`
48
+ `);for(let _ of v)_.length>0&&p.push(_)}}catch(y){if(y.name==="ParseException")return S(`compgen: -C: ${y.message}
49
+ `,2);throw y}let b=p;if(f!==null){let y=f.startsWith("!"),g=y?f.slice(1):f;b=p.filter(v=>{let _=Le(v,g,!1,!0);return y?_:!_})}if(b.length===0&&o!==null)return P(w,"",1);let $=b.map(y=>`${r}${y}${i}`).join(`
50
+ `),C=w+($?`${$}
51
+ `:"");return F(C)}function di(e,t){let s=new Set;for(let r of Object.keys(e.state.env)){if(r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length"))continue;let i=r.split("_")[0];/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)?s.add(r):i&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)&&e.state.env[`${i}__length`]!==void 0&&s.add(i)}let n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function hi(e,t){let s=e.state.exportedVars??new Set,n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n=n.filter(r=>r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length")?!1:e.state.env[r]!==void 0),n.sort()}function pi(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(n=>n.startsWith(t))),s.sort()}function mi(e){let t=[...ts];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function yi(e){let t=[...xn];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function wi(e,t){let s=[];for(let r of Object.keys(e.state.env))if(r.startsWith("BASH_ALIAS_")){let i=r.slice(11);s.push(i)}let n=s;return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function gi(e){let t=[...fi];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function vi(e){let t=[...ui];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function es(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let o=t.lastIndexOf("/");if(o!==-1){let a=t.slice(0,o)||"/";r=t.slice(o+1),a.startsWith("/")?n=a:n=`${e.state.cwd}/${a}`}}let i=await e.fs.readdir(n);for(let o of i){let a=`${n}/${o}`;try{if((await e.fs.stat(a)).isDirectory&&(!r||o.startsWith(r)))if(t?.includes("/")){let c=t.lastIndexOf("/"),f=t.slice(0,c+1);s.push(f+o)}else s.push(o)}catch{}}}catch{}return s.sort()}async function Rn(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let o=t.lastIndexOf("/");if(o!==-1){let a=t.slice(0,o)||"/";r=t.slice(o+1),a.startsWith("/")?n=a:n=`${e.state.cwd}/${a}`}}let i=await e.fs.readdir(n);for(let o of i)if(!r||o.startsWith(r))if(t?.includes("/")){let a=t.lastIndexOf("/"),l=t.slice(0,a+1);s.push(l+o)}else s.push(o)}catch{}return s.sort()}function bi(e){return["root","nobody"]}async function Ei(e,t){let s=new Set;for(let i of ts)s.add(i);for(let i of e.state.functions.keys())s.add(i);for(let i of Object.keys(e.state.env))i.startsWith("BASH_ALIAS_")&&s.add(i.slice(11));for(let i of xn)s.add(i);let n=e.state.env.PATH??"/usr/bin:/bin";for(let i of n.split(":"))if(i)try{let o=await e.fs.readdir(i);for(let a of o)s.add(a)}catch{}let r=Array.from(s);return t!==null&&(r=r.filter(i=>i.startsWith(t))),r.sort()}async function $i(e,t){let n=new W().parseWordFromString(t,!1,!1);return await T(e,n)}function Si(e,t){let s=e.state.env.IFS??`
52
+ `;if(s.length===0)return[t];let n=new Set(s.split("")),r=[],i="",o=0;for(;o<t.length;){let a=t[o];if(a==="\\"&&o+1<t.length){let l=t[o+1];i+=l,o+=2}else n.has(a)?(i.length>0&&(r.push(i),i=""),o++):(i+=a,o++)}return i.length>0&&r.push(i),r}function Me(e,t){for(let[s,n]of Object.entries(t))n===void 0?delete e.state.env[s]:e.state.env[s]=n}function Ai(e){let t=[];if(e.state.env["COMPREPLY__length"]!==void 0){let r=fe(e,"COMPREPLY");for(let[,i]of r)t.push(i)}else e.state.env.COMPREPLY!==void 0&&t.push(e.state.env.COMPREPLY);return t}var Pi=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function rs(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=!1,i,o,a,l=[],c=[],f=[];for(let u=0;u<t.length;u++){let d=t[u];if(d==="-p")s=!0;else if(d==="-r")n=!0;else if(d==="-D")r=!0;else if(d==="-W"){if(u++,u>=t.length)return S(`complete: -W: option requires an argument
53
+ `,2);i=t[u]}else if(d==="-F"){if(u++,u>=t.length)return S(`complete: -F: option requires an argument
54
+ `,2);o=t[u]}else if(d==="-o"){if(u++,u>=t.length)return S(`complete: -o: option requires an argument
55
+ `,2);let h=t[u];if(!Pi.includes(h))return S(`complete: ${h}: invalid option name
56
+ `,2);l.push(h)}else if(d==="-A"){if(u++,u>=t.length)return S(`complete: -A: option requires an argument
57
+ `,2);c.push(t[u])}else if(d==="-C"){if(u++,u>=t.length)return S(`complete: -C: option requires an argument
58
+ `,2);a=t[u]}else if(d==="-G"){if(u++,u>=t.length)return S(`complete: -G: option requires an argument
59
+ `,2)}else if(d==="-P"){if(u++,u>=t.length)return S(`complete: -P: option requires an argument
60
+ `,2)}else if(d==="-S"){if(u++,u>=t.length)return S(`complete: -S: option requires an argument
61
+ `,2)}else if(d==="-X"){if(u++,u>=t.length)return S(`complete: -X: option requires an argument
62
+ `,2)}else if(d==="--"){f.push(...t.slice(u+1));break}else d.startsWith("-")||f.push(d)}if(n){if(f.length===0)return e.state.completionSpecs.clear(),F("");for(let u of f)e.state.completionSpecs.delete(u);return F("")}if(s)return f.length===0?ns(e):ns(e,f);if(t.length===0||f.length===0&&!i&&!o&&!a&&l.length===0&&c.length===0&&!r)return ns(e);if(o&&f.length===0&&!r)return S(`complete: -F: option requires a command name
63
+ `,2);if(r){let u={isDefault:!0};return i!==void 0&&(u.wordlist=i),o!==void 0&&(u.function=o),a!==void 0&&(u.command=a),l.length>0&&(u.options=l),c.length>0&&(u.actions=c),e.state.completionSpecs.set("__default__",u),F("")}for(let u of f){let d={};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(u,d)}return F("")}function ns(e,t){let s=e.state.completionSpecs;if(!s||s.size===0){if(t&&t.length>0){let i="";for(let o of t)i+=`complete: ${o}: no completion specification
64
+ `;return P("",i,1)}return F("")}let n=[],r=t||Array.from(s.keys());for(let i of r){if(i==="__default__")continue;let o=s.get(i);if(!o){if(t)return P(n.join(`
65
+ `)+(n.length>0?`
66
+ `:""),`complete: ${i}: no completion specification
67
+ `,1);continue}let a="complete";if(o.options)for(let l of o.options)a+=` -o ${l}`;if(o.actions)for(let l of o.actions)a+=` -A ${l}`;o.wordlist!==void 0&&(o.wordlist.includes(" ")||o.wordlist.includes("'")?a+=` -W '${o.wordlist}'`:a+=` -W ${o.wordlist}`),o.function!==void 0&&(a+=` -F ${o.function}`),o.isDefault&&(a+=" -D"),a+=` ${i}`,n.push(a)}return n.length===0?F(""):F(`${n.join(`
68
+ `)}
69
+ `)}var Ln=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function is(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=[],i=[],o=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-D")s=!0;else if(l==="-E")n=!0;else if(l==="-o"){if(a++,a>=t.length)return S(`compopt: -o: option requires an argument
70
+ `,2);let c=t[a];if(!Ln.includes(c))return S(`compopt: ${c}: invalid option name
71
+ `,2);r.push(c)}else if(l==="+o"){if(a++,a>=t.length)return S(`compopt: +o: option requires an argument
72
+ `,2);let c=t[a];if(!Ln.includes(c))return S(`compopt: ${c}: invalid option name
73
+ `,2);i.push(c)}else if(l==="--"){o.push(...t.slice(a+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&o.push(l)}if(s){let a=e.state.completionSpecs.get("__default__")??{isDefault:!0},l=new Set(a.options??[]);for(let c of r)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set("__default__",a),F("")}if(n){let a=e.state.completionSpecs.get("__empty__")??{},l=new Set(a.options??[]);for(let c of r)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set("__empty__",a),F("")}if(o.length>0){for(let a of o){let l=e.state.completionSpecs.get(a)??{},c=new Set(l.options??[]);for(let f of r)c.add(f);for(let f of i)c.delete(f);l.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set(a,l)}return F("")}return S(`compopt: not currently executing completion function
74
+ `,1)}function os(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Se;return L}if(t.length>1)throw new z(1,"",`bash: continue: too many arguments
75
+ `);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new z(1,"",`bash: continue: ${t[0]}: numeric argument required
76
+ `);s=n}throw new ie(s)}function H(e,t){let s=e.state.env.HOME||"/home/user";return t.split(":").map(i=>i==="~"?s:i==="~root"?"/root":i.startsWith("~/")?s+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function as(e){for(let t=0;t<e.length;t++){let s=e.charCodeAt(t);if(s<32||s===127)return!0}return!1}function ls(e){let t="$'";for(let s=0;s<e.length;s++){let n=e[s],r=e.charCodeAt(s);r===7?t+="\\a":r===8?t+="\\b":r===9?t+="\\t":r===10?t+="\\n":r===11?t+="\\v":r===12?t+="\\f":r===13?t+="\\r":r===27?t+="\\e":r===39?t+="\\'":r===92?t+="\\\\":r<32||r===127?t+=`\\${r.toString(8).padStart(3,"0")}`:t+=n}return t+="'",t}function _t(e){return as(e)?ls(e):/^[a-zA-Z0-9_/.:\-@%+,=]*$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Ie(e){return as(e)?ls(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function cs(e){return as(e)?ls(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Fn(e,t){let s="";return e.state.integerVars?.has(t)&&(s+="i"),e.state.lowercaseVars?.has(t)&&(s+="l"),ae(e,t)&&(s+="n"),e.state.readonlyVars?.has(t)&&(s+="r"),e.state.uppercaseVars?.has(t)&&(s+="u"),e.state.exportedVars?.has(t)&&(s+="x"),s===""?"--":`-${s}`}function fs(e){return e===""?"''":/[\s'\\]/.test(e)?`'${e.replace(/'/g,"'\\''")}'`:e}function Mn(e,t){let s="",n="",r=!1;for(let i of t){let o=Fn(e,i);if(e.state.associativeArrays?.has(i)){let f=Ae(e,i);if(f.length===0)s+=`declare -A ${i}=()
77
+ `;else{let u=f.map(d=>{let h=e.state.env[`${i}_${d}`]??"",m=fs(h);return`['${d}']=${m}`});s+=`declare -A ${i}=(${u.join(" ")})
78
+ `}continue}let l=J(e,i);if(l.length>0){let f=l.map(u=>{let d=e.state.env[`${i}_${u}`]??"";return`[${u}]=${Ie(d)}`});s+=`declare -a ${i}=(${f.join(" ")})
79
+ `;continue}if(e.state.env[`${i}__length`]!==void 0){s+=`declare -a ${i}=()
80
+ `;continue}let c=e.state.env[i];if(c!==void 0)s+=`declare ${o} ${i}=${cs(c)}
81
+ `;else{let f=e.state.declaredVars?.has(i),u=e.state.localVarDepth?.has(i);f||u?s+=`declare ${o} ${i}
82
+ `:(n+=`bash: declare: ${i}: not found
83
+ `,r=!0)}}return P(s,n,r?1:0)}function Wn(e,t){let{filterExport:s,filterReadonly:n,filterNameref:r,filterIndexedArray:i,filterAssocArray:o}=t,a=s||n||r||i||o,l="",c=new Set;for(let u of Object.keys(e.state.env)){if(u.startsWith("BASH_"))continue;if(u.endsWith("__length")){let h=u.slice(0,-8);c.add(h);continue}let d=u.lastIndexOf("_");if(d>0){let h=u.slice(0,d),m=u.slice(d+1);if(/^\d+$/.test(m)||e.state.associativeArrays?.has(h)){c.add(h);continue}}c.add(u)}if(e.state.localVarDepth)for(let u of e.state.localVarDepth.keys())c.add(u);if(e.state.associativeArrays)for(let u of e.state.associativeArrays)c.add(u);let f=Array.from(c).sort();for(let u of f){let d=Fn(e,u),h=e.state.associativeArrays?.has(u),m=J(e,u),p=!h&&(m.length>0||e.state.env[`${u}__length`]!==void 0);if(a&&(o&&!h||i&&!p||s&&!e.state.exportedVars?.has(u)||n&&!e.state.readonlyVars?.has(u)||r&&!ae(e,u)))continue;if(h){let b=Ae(e,u);if(b.length===0)l+=`declare -A ${u}=()
84
+ `;else{let $=b.map(C=>{let y=e.state.env[`${u}_${C}`]??"",g=fs(y);return`['${C}']=${g}`});l+=`declare -A ${u}=(${$.join(" ")})
85
+ `}continue}if(m.length>0){let b=m.map($=>{let C=e.state.env[`${u}_${$}`]??"";return`[${$}]=${Ie(C)}`});l+=`declare -a ${u}=(${b.join(" ")})
86
+ `;continue}if(e.state.env[`${u}__length`]!==void 0){l+=`declare -a ${u}=()
87
+ `;continue}let w=e.state.env[u];w!==void 0&&(l+=`declare ${d} ${u}=${cs(w)}
88
+ `)}return F(l)}function zn(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let n of s){let r=Ae(e,n);if(r.length===0)t+=`declare -A ${n}=()
89
+ `;else{let i=r.map(o=>{let a=e.state.env[`${n}_${o}`]??"",l=fs(a);return`['${o}']=${l}`});t+=`declare -A ${n}=(${i.join(" ")})
90
+ `}}return F(t)}function Vn(e){let t="",s=new Set;for(let r of Object.keys(e.state.env)){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let o=r.slice(0,-8);e.state.associativeArrays?.has(o)||s.add(o);continue}let i=r.lastIndexOf("_");if(i>0){let o=r.slice(0,i),a=r.slice(i+1);/^\d+$/.test(a)&&(e.state.associativeArrays?.has(o)||s.add(o))}}let n=Array.from(s).sort();for(let r of n){let i=J(e,r);if(i.length===0)t+=`declare -a ${r}=()
91
+ `;else{let o=i.map(a=>{let l=e.state.env[`${r}_${a}`]??"";return`[${a}]=${Ie(l)}`});t+=`declare -a ${r}=(${o.join(" ")})
92
+ `}}return F(t)}function Bn(e){let t="",s=new Set;for(let r of Object.keys(e.state.env)){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let o=r.slice(0,-8);s.add(o);continue}let i=r.lastIndexOf("_");if(i>0){let o=r.slice(0,i),a=r.slice(i+1);if(/^\d+$/.test(a)||e.state.associativeArrays?.has(o)){s.add(o);continue}}s.add(r)}let n=Array.from(s).sort();for(let r of n){if(e.state.associativeArrays?.has(r)||J(e,r).length>0||e.state.env[`${r}__length`]!==void 0)continue;let a=e.state.env[r];a!==void 0&&(t+=`${r}=${_t(a)}
93
+ `)}return F(t)}function us(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function Ke(e,t){return e.state.integerVars?.has(t)??!1}function ds(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function _i(e,t){return e.state.lowercaseVars?.has(t)??!1}function hs(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Ni(e,t){return e.state.uppercaseVars?.has(t)??!1}function We(e,t,s){return _i(e,t)?s.toLowerCase():Ni(e,t)?s.toUpperCase():s}async function jn(e,t){try{let s=new W,n=Z(s,t),r=await V(e,n.expression);return String(r)}catch{return"0"}}function Ci(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let s=t[0],n=s.length;if(e[n]!=="[")return null;let r=0,i=n+1;for(;n<e.length;n++)if(e[n]==="[")r++;else if(e[n]==="]"&&(r--,r===0))break;if(r!==0)return null;let o=e.slice(i,n);if(n++,e[n]!=="=")return null;n++;let a=e.slice(n);return{name:s,indexExpr:o,value:a}}async function ps(e,t){let s=!1,n=!1,r=!1,i=!1,o=!1,a=!1,l=!1,c=!1,f=!1,u=!1,d=!1,h=!1,m=!1,p=!1,w=!1,b=[];for(let I=0;I<t.length;I++){let R=t[I];if(R==="-a")s=!0;else if(R==="-A")n=!0;else if(R==="-r")r=!0;else if(R==="-x")i=!0;else if(R==="-p")o=!0;else if(R==="-n")a=!0;else if(R==="+n")l=!0;else if(R==="+a")c=!0;else if(R==="+x")f=!0;else if(R==="--"){b.push(...t.slice(I+1));break}else if(R.startsWith("+")){for(let A of R.slice(1))if(A==="n")l=!0;else if(A==="a")c=!0;else if(A==="x")f=!0;else if(A!=="r"){if(A!=="i"){if(!(A==="f"||A==="F"))return P("",`bash: typeset: +${A}: invalid option
94
+ `,2)}}}else if(R==="-i")u=!0;else if(R==="-l")d=!0;else if(R==="-u")h=!0;else if(R==="-f")m=!0;else if(R==="-F")p=!0;else if(R==="-g")w=!0;else if(R.startsWith("-"))for(let A of R.slice(1))if(A==="a")s=!0;else if(A==="A")n=!0;else if(A==="r")r=!0;else if(A==="x")i=!0;else if(A==="p")o=!0;else if(A==="n")a=!0;else if(A==="i")u=!0;else if(A==="l")d=!0;else if(A==="u")h=!0;else if(A==="f")m=!0;else if(A==="F")p=!0;else if(A==="g")w=!0;else return P("",`bash: typeset: -${A}: invalid option
95
+ `,2);else b.push(R)}let C=e.state.localScopes.length>0&&!w,y=I=>{if(!C)return;let R=e.state.localScopes[e.state.localScopes.length-1];R.has(I)||R.set(I,e.state.env[I])},g=I=>{if(!C)return;let R=e.state.localScopes[e.state.localScopes.length-1];R.has(I)||R.set(I,e.state.env[I]);let A=`${I}_`;for(let D of Object.keys(e.state.env))D.startsWith(A)&&!D.includes("__")&&(R.has(D)||R.set(D,e.state.env[D]));let N=`${I}__length`;e.state.env[N]!==void 0&&!R.has(N)&&R.set(N,e.state.env[N])},v=I=>{C&&Ne(e,I)};if(p){if(b.length===0){let A=Array.from(e.state.functions.keys()).sort(),N="";for(let D of A)N+=`declare -f ${D}
96
+ `;return F(N)}let I=!0,R="";for(let A of b)e.state.functions.has(A)?R+=`${A}
97
+ `:I=!1;return P(R,"",I?0:1)}if(m){if(b.length===0){let R="",A=Array.from(e.state.functions.keys()).sort();for(let N of A)R+=`${N} ()
98
+ {
99
+ # function body
100
+ }
101
+ `;return F(R)}let I=!0;for(let R of b)e.state.functions.has(R)||(I=!1);return P("","",I?0:1)}if(o&&b.length>0)return Mn(e,b);if(o&&b.length===0)return Wn(e,{filterExport:i,filterReadonly:r,filterNameref:a,filterIndexedArray:s,filterAssocArray:n});if(b.length===0&&n&&!o)return zn(e);if(b.length===0&&s&&!o)return Vn(e);if(b.length===0&&!o)return Bn(e);let _="",k=0;for(let I of b){let R=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(R&&!c){let E=R[1],O=R[2];if(n&&J(e,E).length>0){_+=`bash: declare: ${E}: cannot convert indexed to associative array
102
+ `,k=1;continue}if((s||!n&&!s)&&e.state.associativeArrays?.has(E)){_+=`bash: declare: ${E}: cannot convert associative to indexed array
103
+ `,k=1;continue}if(g(E),n&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(E)),he(e,E),delete e.state.env[E],delete e.state.env[`${E}__length`],n&&O.includes("[")){let x=Et(O);for(let[X,M]of x){let U=H(e,M);e.state.env[`${E}_${X}`]=U}}else if(n){let x=me(O);for(let X=0;X<x.length;X+=2){let M=x[X],U=X+1<x.length?H(e,x[X+1]):"";e.state.env[`${E}_${M}`]=U}}else{let x=me(O);if(x.some(M=>/^\[[^\]]+\]=/.test(M))){let M=0;for(let U of x){let ee=U.match(/^\[([^\]]+)\]=(.*)$/);if(ee){let Q=ee[1],Dr=ee[2],Tr=H(e,Dr),qe;if(/^-?\d+$/.test(Q))qe=Number.parseInt(Q,10);else try{let Ir=new W,Rr=Z(Ir,Q);qe=await V(e,Rr.expression)}catch{qe=0}e.state.env[`${E}_${qe}`]=Tr,M=qe+1}else{let Q=H(e,U);e.state.env[`${E}_${M}`]=Q,M++}}}else{for(let M=0;M<x.length;M++)e.state.env[`${E}_${M}`]=x[M];e.state.env[`${E}__length`]=String(x.length)}}v(E),r&&ne(e,E),i&&ue(e,E);continue}if(l){let E=I.includes("=")?I.slice(0,I.indexOf("=")):I;if(Zs(e,E),!I.includes("="))continue}if(f){let E=I.includes("=")?I.slice(0,I.indexOf("=")):I;if(at(e,E),!I.includes("="))continue}let A=Ci(I);if(A){let{name:E,indexExpr:O,value:x}=A,X=K(e,E);if(X)return X;g(E);let M;try{let ee=new W,Q=Z(ee,O);M=await V(e,Q.expression)}catch{let ee=parseInt(O,10);M=Number.isNaN(ee)?0:ee}e.state.env[`${E}_${M}`]=x;let U=parseInt(e.state.env[`${E}__length`]??"0",10);M>=U&&(e.state.env[`${E}__length`]=String(M+1)),v(E),r&&ne(e,E),i&&ue(e,E);continue}let N=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(N&&!c){let E=N[1],O=N[2],x=K(e,E);if(x)return x;g(E);let X=me(O);if(e.state.associativeArrays?.has(E)){let M=Et(O);for(let[U,ee]of M){let Q=H(e,ee);e.state.env[`${E}_${U}`]=Q}}else{let M=J(e,E),U=0;if(M.length===0&&e.state.env[E]!==void 0){let Q=e.state.env[E];e.state.env[`${E}_0`]=Q,delete e.state.env[E],U=1}else M.length>0&&(U=Math.max(...M)+1);for(let Q=0;Q<X.length;Q++)e.state.env[`${E}_${U+Q}`]=H(e,X[Q]);let ee=U+X.length;e.state.env[`${E}__length`]=String(ee)}v(E),r&&ne(e,E),i&&ue(e,E);continue}let D=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(D){let E=D[1],O=H(e,D[2]),x=K(e,E);if(x)return x;y(E),u&&us(e,E),d&&ds(e,E),h&&hs(e,E);let M=J(e,E).length>0||e.state.associativeArrays?.has(E);if(Ke(e,E)){let U=e.state.env[E]??"0",ee=parseInt(U,10)||0,Q=parseInt(await jn(e,O),10)||0;O=String(ee+Q),e.state.env[E]=O}else if(M){O=We(e,E,O);let U=`${E}_0`,ee=e.state.env[U]??"";e.state.env[U]=ee+O}else{O=We(e,E,O);let U=e.state.env[E]??"";e.state.env[E]=U+O}v(E),r&&ne(e,E),i&&ue(e,E),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(E));continue}if(I.includes("=")){let E=I.indexOf("="),O=I.slice(0,E),x=I.slice(E+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(O)){_+=`bash: typeset: \`${O}': not a valid identifier
104
+ `,k=1;continue}let X=K(e,O);if(X)return X;if(y(O),a){if(x!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(x)){_+=`bash: declare: \`${x}': invalid variable name for name reference
105
+ `,k=1;continue}e.state.env[O]=x,ve(e,O),x!==""&&zt(e,x)&&Wt(e,O),v(O),r&&ne(e,O),i&&ue(e,O);continue}if(u&&us(e,O),d&&ds(e,O),h&&hs(e,O),Ke(e,O)&&(x=await jn(e,x)),x=We(e,O,x),ae(e,O)){let M=Pe(e,O);M&&M!==O?e.state.env[M]=x:e.state.env[O]=x}else e.state.env[O]=x;v(O),r&&ne(e,O),i&&ue(e,O),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(O))}else{let E=I;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(E)){_+=`bash: typeset: \`${E}': not a valid identifier
106
+ `,k=1;continue}if(s||n?g(E):y(E),a){ve(e,E);let x=e.state.env[E];x!==void 0&&x!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(x)?Gs(e,E):x&&zt(e,x)&&Wt(e,E),v(E),r&&ne(e,E),i&&ue(e,E);continue}if(u&&us(e,E),d&&ds(e,E),h&&hs(e,E),n){if(J(e,E).length>0){_+=`bash: declare: ${E}: cannot convert indexed to associative array
107
+ `,k=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(E)}let O=Object.keys(e.state.env).some(x=>x.startsWith(`${E}_`)&&!x.startsWith(`${E}__length`));!(E in e.state.env)&&!O&&(s||n?e.state.env[`${E}__length`]="0":(e.state.declaredVars??=new Set,e.state.declaredVars.add(E))),v(E),r&&ne(e,E),i&&ue(e,E)}}return P("",_,k)}async function ms(e,t){let s=!1,n=!1,r=!1,i=[];for(let o=0;o<t.length;o++){let a=t[o];if(a==="-a")s=!0;else if(a==="-A")n=!0;else if(a==="-p")r=!0;else if(a==="--"){i.push(...t.slice(o+1));break}else a.startsWith("-")||i.push(a)}if(i.length===0){let o="",a=Array.from(e.state.readonlyVars||[]).sort();for(let l of a){let c=e.state.env[l];if(c!==void 0){let f=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');o+=`declare -r ${l}="${f}"
108
+ `}}return F(o)}for(let o of i){let a=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(a){let u=a[1],d=a[2],h=K(e,u);if(h)return h;let m=me(d);if(e.state.associativeArrays?.has(u)){let p=Et(d);for(let[w,b]of p){let $=H(e,b);e.state.env[`${u}_${w}`]=$}}else{let p=J(e,u),w=0;if(p.length===0&&e.state.env[u]!==void 0){let $=e.state.env[u];e.state.env[`${u}_0`]=$,delete e.state.env[u],w=1}else p.length>0&&(w=Math.max(...p)+1);for(let $=0;$<m.length;$++)e.state.env[`${u}_${w+$}`]=H(e,m[$]);let b=w+m.length;e.state.env[`${u}__length`]=String(b)}ne(e,u);continue}let l=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(l){let u=l[1],d=H(e,l[2]),h=K(e,u);if(h)return h;let m=e.state.env[u]??"";e.state.env[u]=m+d,ne(e,u);continue}let c=Nn(o);if(c.value===void 0&&!c.isArray){ne(e,c.name);continue}let f=await Cn(e,c,{makeReadonly:!0});if(f)return f}return L}function ys(e){return e.state.directoryStack??=[],e.state.directoryStack}function Ye(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function ki(e){let t=e.split("/").filter(n=>n&&n!=="."),s=[];for(let n of t)n===".."?s.pop():s.push(n);return`/${s.join("/")}`}async function ws(e,t){let s=ys(e),n;for(let a=0;a<t.length;a++){let l=t[a];if(l==="--"){if(a+1<t.length){if(n!==void 0)return S(`bash: pushd: too many arguments
109
+ `,2);n=t[a+1],a++}}else{if(l.startsWith("-")&&l!=="-")return S(`bash: pushd: ${l}: invalid option
110
+ `,2);if(n!==void 0)return S(`bash: pushd: too many arguments
111
+ `,2);n=l}}if(n===void 0){if(s.length<2)return S(`bash: pushd: no other directory
112
+ `,1);let a=s[0];s[0]=s[1],s[1]=a,n=s[0]}let r;if(n.startsWith("/"))r=n;else if(n===".."){let a=e.state.cwd.split("/").filter(l=>l);a.pop(),r=`/${a.join("/")}`}else n==="."?r=e.state.cwd:n.startsWith("~")?r=(e.state.env.HOME||"/")+n.slice(1):r=`${e.state.cwd}/${n}`;r=ki(r);try{if(!(await e.fs.stat(r)).isDirectory)return S(`bash: pushd: ${n}: Not a directory
113
+ `,1)}catch{return S(`bash: pushd: ${n}: No such file or directory
114
+ `,1)}s.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.PWD=r,e.state.env.OLDPWD=e.state.previousDir;let i=e.state.env.HOME||"",o=`${[r,...s].map(a=>Ye(a,i)).join(" ")}
115
+ `;return F(o)}function gs(e,t){let s=ys(e);for(let o of t)if(o!=="--")return o.startsWith("-")&&o!=="-"?S(`bash: popd: ${o}: invalid option
116
+ `,2):S(`bash: popd: too many arguments
117
+ `,2);if(s.length===0)return S(`bash: popd: directory stack empty
118
+ `,1);let n=s.shift();if(!n)return S(`bash: popd: directory stack empty
119
+ `,1);e.state.previousDir=e.state.cwd,e.state.cwd=n,e.state.env.PWD=n,e.state.env.OLDPWD=e.state.previousDir;let r=e.state.env.HOME||"",i=`${[n,...s].map(o=>Ye(o,r)).join(" ")}
120
+ `;return F(i)}function vs(e,t){let s=ys(e),n=!1,r=!1,i=!1,o=!1;for(let f of t)if(f!=="--")if(f.startsWith("-"))for(let u of f.slice(1))if(u==="c")n=!0;else if(u==="l")r=!0;else if(u==="p")i=!0;else if(u==="v")i=!0,o=!0;else return S(`bash: dirs: -${u}: invalid option
121
+ `,2);else return S(`bash: dirs: too many arguments
122
+ `,1);if(n)return e.state.directoryStack=[],L;let a=[e.state.cwd,...s],l=e.state.env.HOME||"",c;return o?(c=a.map((f,u)=>{let d=r?f:Ye(f,l);return` ${u} ${d}`}).join(`
123
+ `),c+=`
124
+ `):i?c=a.map(f=>r?f:Ye(f,l)).join(`
125
+ `)+`
126
+ `:c=a.map(f=>r?f:Ye(f,l)).join(" ")+`
127
+ `,F(c)}async function Nt(e,t,s){let n=t;if(n.length>0){let a=n[0];if(a==="--")n=n.slice(1);else if(a.startsWith("-")&&a!=="-"&&a.length>1)return S(`bash: eval: ${a}: invalid option
60
128
  eval: usage: eval [arg ...]
61
- `,2)}if(s.length===0)return N;let r=s.join(" ");if(r.trim()==="")return N;try{let n=he(r);return t.executeScript(n)}catch(n){if(n instanceof U||n instanceof Y||n instanceof G||n instanceof R)throw n;if(n.name==="ParseException")return x(`bash: eval: ${n.message}
62
- `);throw n}}function tr(t,e){let s,r="";if(e.length===0)s=t.state.lastExitCode;else{let n=e[0],i=Number.parseInt(n,10);n===""||Number.isNaN(i)||!/^-?\d+$/.test(n)?(r=`bash: exit: ${n}: numeric argument required
63
- `,s=2):s=(i%256+256)%256}throw new R(s,"",r)}function rr(t,e){let s=!1,r=[];for(let o of e)o==="-n"?s=!0:o==="-p"||o==="--"||r.push(o);if(r.length===0&&!s){let o="",a=Object.entries(t.state.env).filter(([c])=>!c.startsWith("BASH_ALIAS_")).sort(([c],[l])=>c.localeCompare(l));for(let[c,l]of a){let u=l.replace(/'/g,"'\\''");o+=`declare -x ${c}='${u}'
64
- `}return j(o)}if(s){for(let o of r){let a=o.split("=")[0];delete t.state.env[a]}return N}let n="",i=0;for(let o of r){let a,c;if(o.includes("=")){let l=o.indexOf("=");a=o.slice(0,l),c=o.slice(l+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){n+=`bash: export: \`${o}': not a valid identifier
65
- `,i=1;continue}c!==void 0?t.state.env[a]=c:a in t.state.env||(t.state.env[a]="")}return S("",n,i)}function jn(t){let e=[],s="",r=0;for(let n of t){for(let i of n)i==="("?r++:i===")"&&r--;s?s+=` ${n}`:s=n,r===0&&(e.push(s),s="")}return s&&e.push(s),e}async function sr(t,e){if(e.length===0)return x(`bash: let: expression expected
66
- `);let s=jn(e),r=0;for(let n of s)try{let o=he(`(( ${n} ))`).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 v(t,a.expression.expression))}}catch(i){return x(`bash: let: ${n}: ${i.message}
67
- `)}return S("","",r===0?1:0)}function qn(t,e){let s=t.state.env.HOME||"/home/user";return e.split(":").map(i=>i==="~"?s:i==="~root"?"/root":i.startsWith("~/")?s+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function nr(t,e){if(t.state.localScopes.length===0)return x(`bash: local: can only be used in a function
68
- `);let s=t.state.localScopes[t.state.localScopes.length-1],r="",n=0;for(let i of e){let o,a;if(i.includes("=")){let c=i.indexOf("=");o=i.slice(0,c),a=qn(t,i.slice(c+1))}else o=i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){r+=`bash: local: \`${i}': not a valid identifier
69
- `,n=1;continue}s.has(o)||s.set(o,t.state.env[o]),a!==void 0&&(t.state.env[o]=a)}return S("",r,n)}function ir(t,e,s){let r=`
70
- `,n=0,i=0,o=0,a=!1,c="MAPFILE",l=0;for(;l<e.length;){let E=e[l];E==="-d"&&l+1<e.length?(r=e[l+1]||`
71
- `,l+=2):E==="-n"&&l+1<e.length?(n=Number.parseInt(e[l+1],10)||0,l+=2):E==="-O"&&l+1<e.length?(i=Number.parseInt(e[l+1],10)||0,l+=2):E==="-s"&&l+1<e.length?(o=Number.parseInt(e[l+1],10)||0,l+=2):E==="-t"?(a=!0,l++):E==="-u"||E==="-C"||E==="-c"?l+=2:(E.startsWith("-")||(c=E),l++)}let u=s;!u&&t.state.groupStdin!==void 0&&(u=t.state.groupStdin);let h=[],d=u,m=0,y=0;for(;d.length>0;){let E=d.indexOf(r);if(E===-1){d.length>0&&(y<o?y++:(n===0||m<n)&&(h.push(d),m++));break}let p=d.substring(0,E);if(a||(p+=r),d=d.substring(E+r.length),y<o){y++;continue}if(n>0&&m>=n)break;h.push(p),m++}Be(t,c);for(let E=0;E<h.length;E++)t.state.env[`${c}_${i+E}`]=h[E];return h.length>0&&(t.state.env[`${c}__length`]=String(i+h.length)),t.state.groupStdin!==void 0&&!s&&(t.state.groupStdin=""),S("","",0)}function or(t,e,s){let r=!1,n=`
72
- `,i="",o=-1,a=null,c=[],l=0,u=!1;for(;l<e.length;){let g=e[l];g==="-r"?r=!0:g==="-d"&&l+1<e.length?(n=e[l+1],l++):g==="-p"&&l+1<e.length?(i=e[l+1],l++):g==="-n"&&l+1<e.length?(o=Number.parseInt(e[l+1],10),(Number.isNaN(o)||o<0)&&(u=!0,o=0),l++):g==="-a"&&l+1<e.length?(a=e[l+1],l++):g==="-t"?l+1<e.length&&!e[l+1].startsWith("-")&&l++:g==="-s"||g.startsWith("-")||c.push(g),l++}if(u)return S("","",1);c.length===0&&a===null&&c.push("REPLY");let h=s;!h&&t.state.groupStdin!==void 0&&(h=t.state.groupStdin);let d="",m=0,y=!0;if(o>=0){for(let g=0;g<h.length&&g<o;g++){let b=h[g];if(b===n){m=g+1;break}d+=b,m=g+1}t.state.groupStdin!==void 0&&!s&&(t.state.groupStdin=h.substring(m))}else{let g=h;for(m=0;;){let b=g.indexOf(n);if(b!==-1){let C=g.substring(0,b);if(m+=b+n.length,g=g.substring(b+n.length),!r&&C.endsWith("\\")){d+=C.slice(0,-1);continue}d+=C,y=!0;break}else if(g.length>0){d+=g,m+=g.length,y=!1,g="";break}else{if(d.length===0){for(let C of c)t.state.env[C]="";return a&&Be(t,a),S("","",1)}y=!1;break}}t.state.groupStdin!==void 0&&!s&&(t.state.groupStdin=h.substring(m))}if(n===`
73
- `&&d.endsWith(`
74
- `)&&(d=d.slice(0,-1)),r||(d=d.replace(/\\(.)/g,"$1")),c.length===1&&c[0]==="REPLY")return t.state.env.REPLY=d,S("","",y?0:1);let E=rt(t.state.env),{words:p,wordStarts:w}=is(d,E);if(a){Be(t,a);for(let g=0;g<p.length;g++)t.state.env[`${a}_${g}`]=p[g];return S("","",y?0:1)}for(let g=0;g<c.length;g++){let b=c[g];if(g<c.length-1)t.state.env[b]=p[g]??"";else if(g<w.length){let C=os(d.substring(w[g]),E);t.state.env[b]=C}else t.state.env[b]=""}return S("","",y?0:1)}function ar(t,e){if(t.state.callDepth===0&&t.state.sourceDepth===0)return x("bash: return: can only `return' from a function or sourced script\n");let s=t.state.lastExitCode;if(e.length>0){let r=e[0],n=Number.parseInt(r,10);if(r===""||Number.isNaN(n)||!/^-?\d+$/.test(r))return x(`bash: return: ${r}: numeric argument required
75
- `,2);s=(n%256+256)%256}throw new G(s)}function Zn(t){return/^[a-zA-Z0-9_/.:-]*$/.test(t)?t:`'${t.replace(/'/g,"'\\''")}'`}var ot=`set: usage: set [-eux] [+eux] [-o option] [+o option]
129
+ `,2)}if(n.length===0)return L;let r=n.join(" ");if(r.trim()==="")return L;let i=e.state.groupStdin,o=s??e.state.groupStdin;o!==void 0&&(e.state.groupStdin=o);try{let a=de(r);return await e.executeScript(a)}catch(a){if(a instanceof re||a instanceof ie||a instanceof se||a instanceof z)throw a;if(a.name==="ParseException")return S(`bash: eval: ${a.message}
130
+ `);throw a}finally{e.state.groupStdin=i}}function bs(e,t){let s,n="";if(t.length===0)s=e.state.lastExitCode;else{let r=t[0],i=Number.parseInt(r,10);r===""||Number.isNaN(i)||!/^-?\d+$/.test(r)?(n=`bash: exit: ${r}: numeric argument required
131
+ `,s=2):s=(i%256+256)%256}throw new z(s,"",n)}function Es(e,t){let s=!1,n=[];for(let o of t)o==="-n"?s=!0:o==="-p"||o==="--"||n.push(o);if(n.length===0&&!s){let o="",a=e.state.exportedVars??new Set,l=Array.from(a).sort();for(let c of l){let f=e.state.env[c];if(f!==void 0){let u=f.replace(/\\/g,"\\\\").replace(/"/g,'\\"');o+=`declare -x ${c}="${u}"
132
+ `}}return F(o)}if(s){for(let o of n){let a,l;if(o.includes("=")){let c=o.indexOf("=");a=o.slice(0,c),l=H(e,o.slice(c+1)),e.state.env[a]=l}else a=o;at(e,a)}return L}let r="",i=0;for(let o of n){let a,l,c=!1,f=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(f)a=f[1],l=H(e,f[2]),c=!0;else if(o.includes("=")){let u=o.indexOf("=");a=o.slice(0,u),l=H(e,o.slice(u+1))}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){r+=`bash: export: \`${o}': not a valid identifier
133
+ `,i=1;continue}if(l!==void 0)if(c){let u=e.state.env[a]??"";e.state.env[a]=u+l}else e.state.env[a]=l;else a in e.state.env||(e.state.env[a]="");ue(e,a)}return P("",r,i)}function Ct(e,t){if(t.length<2)return S(`bash: getopts: usage: getopts optstring name [arg ...]
134
+ `);let s=t[0],n=t[1],r=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n),i=s.startsWith(":"),o=i?s.slice(1):s,a;if(t.length>2)a=t.slice(2);else{let p=Number.parseInt(e.state.env["#"]||"0",10);a=[];for(let w=1;w<=p;w++)a.push(e.state.env[String(w)]||"")}let l=Number.parseInt(e.state.env.OPTIND||"1",10);l<1&&(l=1);let c=Number.parseInt(e.state.env.__GETOPTS_CHARINDEX||"0",10);if(e.state.env.OPTARG="",l>a.length)return r||(e.state.env[n]="?"),e.state.env.OPTIND=String(a.length+1),e.state.env.__GETOPTS_CHARINDEX="0",{exitCode:r?2:1,stdout:"",stderr:""};let f=a[l-1];if(!f||f==="-"||!f.startsWith("-"))return r||(e.state.env[n]="?"),{exitCode:r?2:1,stdout:"",stderr:""};if(f==="--")return e.state.env.OPTIND=String(l+1),e.state.env.__GETOPTS_CHARINDEX="0",r||(e.state.env[n]="?"),{exitCode:r?2:1,stdout:"",stderr:""};let u=c===0?1:c,d=f[u];if(!d)return e.state.env.OPTIND=String(l+1),e.state.env.__GETOPTS_CHARINDEX="0",Ct(e,t);let h=o.indexOf(d);if(h===-1){let p="";return i?e.state.env.OPTARG=d:p=`bash: illegal option -- ${d}
135
+ `,r||(e.state.env[n]="?"),u+1<f.length?(e.state.env.__GETOPTS_CHARINDEX=String(u+1),e.state.env.OPTIND=String(l)):(e.state.env.OPTIND=String(l+1),e.state.env.__GETOPTS_CHARINDEX="0"),{exitCode:r?2:0,stdout:"",stderr:p}}if(h+1<o.length&&o[h+1]===":")if(u+1<f.length)e.state.env.OPTARG=f.slice(u+1),e.state.env.OPTIND=String(l+1),e.state.env.__GETOPTS_CHARINDEX="0";else{if(l>=a.length){let p="";return i?(e.state.env.OPTARG=d,r||(e.state.env[n]=":")):(p=`bash: option requires an argument -- ${d}
136
+ `,r||(e.state.env[n]="?")),e.state.env.OPTIND=String(l+1),e.state.env.__GETOPTS_CHARINDEX="0",{exitCode:r?2:0,stdout:"",stderr:p}}e.state.env.OPTARG=a[l],e.state.env.OPTIND=String(l+2),e.state.env.__GETOPTS_CHARINDEX="0"}else u+1<f.length?(e.state.env.__GETOPTS_CHARINDEX=String(u+1),e.state.env.OPTIND=String(l)):(e.state.env.OPTIND=String(l+1),e.state.env.__GETOPTS_CHARINDEX="0");return r||(e.state.env[n]=d),{exitCode:r?2:0,stdout:"",stderr:""}}async function $s(e,t){e.state.hashTable||(e.state.hashTable=new Map);let s=!1,n=!1,r=!1,i=!1,o=!1,a="",l=[],c=0;for(;c<t.length;){let m=t[c];if(m==="--"){c++,l.push(...t.slice(c));break}if(m==="-r")s=!0,c++;else if(m==="-d")n=!0,c++;else if(m==="-l")r=!0,c++;else if(m==="-t")o=!0,c++;else if(m==="-p"){if(i=!0,c++,c>=t.length)return S(`bash: hash: -p: option requires an argument
137
+ `,1);a=t[c],c++}else if(m.startsWith("-")&&m.length>1){for(let p of m.slice(1))if(p==="r")s=!0;else if(p==="d")n=!0;else if(p==="l")r=!0;else if(p==="t")o=!0;else return p==="p"?S(`bash: hash: -p: option requires an argument
138
+ `,1):S(`bash: hash: -${p}: invalid option
139
+ `,1);c++}else l.push(m),c++}if(s)return e.state.hashTable.clear(),L;if(n){if(l.length===0)return S(`bash: hash: -d: option requires an argument
140
+ `,1);let m=!1,p="";for(let w of l)e.state.hashTable.has(w)?e.state.hashTable.delete(w):(p+=`bash: hash: ${w}: not found
141
+ `,m=!0);return m?S(p,1):L}if(o){if(l.length===0)return S(`bash: hash: -t: option requires an argument
142
+ `,1);let m="",p=!1,w="";for(let b of l){let $=e.state.hashTable.get(b);$?l.length>1?m+=`${b} ${$}
143
+ `:m+=`${$}
144
+ `:(w+=`bash: hash: ${b}: not found
145
+ `,p=!0)}return p?{exitCode:1,stdout:m,stderr:w}:F(m)}if(i){if(l.length===0)return S(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
146
+ `,1);let m=l[0];return e.state.hashTable.set(m,a),L}if(l.length===0){if(e.state.hashTable.size===0)return F(`hash: hash table empty
147
+ `);let m="";if(r)for(let[p,w]of e.state.hashTable)m+=`builtin hash -p ${w} ${p}
148
+ `;else{m=`hits command
149
+ `;for(let[,p]of e.state.hashTable)m+=` 1 ${p}
150
+ `}return F(m)}let f=!1,u="",h=(e.state.env.PATH||"/usr/bin:/bin").split(":");for(let m of l){if(m.includes("/")){u+=`bash: hash: ${m}: cannot use / in name
151
+ `,f=!0;continue}let p=!1;for(let w of h){if(!w)continue;let b=`${w}/${m}`;if(await e.fs.exists(b)){e.state.hashTable.set(m,b),p=!0;break}}p||(u+=`bash: hash: ${m}: not found
152
+ `,f=!0)}return f?S(u,1):L}var Hn={":":[": [arguments]",`Null command.
153
+ No effect; the command does nothing.
154
+ Exit Status:
155
+ Always succeeds.`],".":[". filename [arguments]",`Execute commands from a file in the current shell.
156
+ Read and execute commands from FILENAME in the current shell.
157
+ The entries in $PATH are used to find the directory containing FILENAME.
158
+ Exit Status:
159
+ Returns the status of the last command executed in FILENAME.`],"[":["[ arg... ]",`Evaluate conditional expression.
160
+ This is a synonym for the "test" builtin, but the last argument must
161
+ be a literal \`]', to match the opening \`['.`],alias:["alias [-p] [name[=value] ... ]",`Define or display aliases.
162
+ Without arguments, \`alias' prints the list of aliases in the reusable
163
+ form \`alias NAME=VALUE' on standard output.
164
+ Exit Status:
165
+ alias returns true unless a NAME is supplied for which no alias has been
166
+ defined.`],bg:["bg [job_spec ...]",`Move jobs to the background.
167
+ Place the jobs identified by each JOB_SPEC in the background, as if they
168
+ had been started with \`&'.`],break:["break [n]",`Exit for, while, or until loops.
169
+ Exit a FOR, WHILE or UNTIL loop. If N is specified, break N enclosing
170
+ loops.
171
+ Exit Status:
172
+ The exit status is 0 unless N is not greater than or equal to 1.`],builtin:["builtin [shell-builtin [arg ...]]",`Execute shell builtins.
173
+ Execute SHELL-BUILTIN with arguments ARGs without performing command
174
+ lookup. This is useful when you wish to reimplement a shell builtin
175
+ as a shell function, but need to execute the builtin within the function.
176
+ Exit Status:
177
+ Returns the exit status of SHELL-BUILTIN, or false if SHELL-BUILTIN is
178
+ not a shell builtin.`],caller:["caller [expr]",`Return the context of the current subroutine call.
179
+ Without EXPR, returns "$line $filename". With EXPR, returns
180
+ "$line $subroutine $filename"; this extra information can be used to
181
+ provide a stack trace.
182
+ Exit Status:
183
+ Returns 0 unless the shell is not executing a subroutine call or
184
+ EXPR is invalid.`],cd:["cd [-L|-P] [dir]",`Change the shell working directory.
185
+ Change the current directory to DIR. The default DIR is the value of the
186
+ HOME shell variable.
187
+
188
+ The variable CDPATH defines the search path for the directory containing
189
+ DIR. Alternative directory names in CDPATH are separated by a colon (:).
190
+ A null directory name is the same as the current directory. If DIR begins
191
+ with a slash (/), then CDPATH is not used.
192
+
193
+ If the directory is not found, and the shell option \`cdable_vars' is set,
194
+ the word is assumed to be a variable name. If that variable has a value,
195
+ its value is used for DIR.
196
+
197
+ Options:
198
+ -L force symbolic links to be followed
199
+ -P use the physical directory structure without following symbolic
200
+ links
201
+
202
+ The default is to follow symbolic links, as if \`-L' were specified.
203
+
204
+ Exit Status:
205
+ Returns 0 if the directory is changed; non-zero otherwise.`],command:["command [-pVv] command [arg ...]",`Execute a simple command or display information about commands.
206
+ Runs COMMAND with ARGS suppressing shell function lookup, or display
207
+ information about the specified COMMANDs.
208
+
209
+ Options:
210
+ -p use a default value for PATH that is guaranteed to find all of
211
+ the standard utilities
212
+ -v print a description of COMMAND similar to the \`type' builtin
213
+ -V print a more verbose description of each COMMAND
214
+
215
+ Exit Status:
216
+ Returns exit status of COMMAND, or failure if COMMAND is not found.`],compgen:["compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word]",`Display possible completions depending on the options.
217
+ Intended to be used from within a shell function generating possible
218
+ completions. If the optional WORD argument is supplied, matches against
219
+ WORD are generated.
220
+ Exit Status:
221
+ Returns success unless an invalid option is supplied or an error occurs.`],complete:["complete [-abcdefgjksuv] [-pr] [-DEI] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]",`Specify how arguments are to be completed.
222
+ For each NAME, specify how arguments are to be completed.
223
+ Exit Status:
224
+ Returns success unless an invalid option is supplied or an error occurs.`],continue:["continue [n]",`Resume for, while, or until loops.
225
+ Resumes the next iteration of the enclosing FOR, WHILE or UNTIL loop.
226
+ If N is specified, resumes the Nth enclosing loop.
227
+ Exit Status:
228
+ The exit status is 0 unless N is not greater than or equal to 1.`],declare:["declare [-aAfFgilnrtux] [-p] [name[=value] ...]",`Set variable values and attributes.
229
+ Declare variables and give them attributes. If no NAMEs are given,
230
+ display the attributes and values of all variables.
231
+
232
+ Options:
233
+ -a to make NAMEs indexed arrays (if supported)
234
+ -A to make NAMEs associative arrays (if supported)
235
+ -i to make NAMEs have the \`integer' attribute
236
+ -l to convert the value of each NAME to lower case on assignment
237
+ -n make NAME a reference to the variable named by its value
238
+ -r to make NAMEs readonly
239
+ -t to make NAMEs have the \`trace' attribute
240
+ -u to convert the value of each NAME to upper case on assignment
241
+ -x to make NAMEs export
242
+
243
+ Exit Status:
244
+ Returns success unless an invalid option is supplied or a variable
245
+ assignment error occurs.`],dirs:["dirs [-clpv] [+N] [-N]",`Display directory stack.
246
+ Display the list of currently remembered directories. Directories
247
+ find their way onto the list with the \`pushd' command; you can get
248
+ back up through the list with the \`popd' command.
249
+ Exit Status:
250
+ Returns success unless an invalid option is supplied or an error occurs.`],disown:["disown [-h] [-ar] [jobspec ...]",`Remove jobs from current shell.
251
+ Without any JOBSPECs, remove the current job.`],echo:["echo [-neE] [arg ...]",`Write arguments to the standard output.
252
+ Display the ARGs, separated by a single space character and followed by a
253
+ newline, on the standard output.
254
+
255
+ Options:
256
+ -n do not append a newline
257
+ -e enable interpretation of the following backslash escapes
258
+ -E explicitly suppress interpretation of backslash escapes
259
+
260
+ Exit Status:
261
+ Returns success unless a write error occurs.`],enable:["enable [-a] [-dnps] [-f filename] [name ...]",`Enable and disable shell builtins.
262
+ Enables and disables builtin shell commands.
263
+ Exit Status:
264
+ Returns success unless NAME is not a shell builtin or an error occurs.`],eval:["eval [arg ...]",`Execute arguments as a shell command.
265
+ Combine ARGs into a single string, use the result as input to the shell,
266
+ and execute the resulting commands.
267
+ Exit Status:
268
+ Returns exit status of command or success if command is null.`],exec:["exec [-cl] [-a name] [command [arguments ...]] [redirection ...]",`Replace the shell with the given command.
269
+ Execute COMMAND, replacing this shell with the specified program.
270
+ ARGUMENTS become the arguments to COMMAND. If COMMAND is not specified,
271
+ any redirections take effect in the current shell.
272
+ Exit Status:
273
+ Returns success unless COMMAND is not found or a redirection error occurs.`],exit:["exit [n]",`Exit the shell.
274
+ Exits the shell with a status of N. If N is omitted, the exit status
275
+ is that of the last command executed.`],export:["export [-fn] [name[=value] ...] or export -p",`Set export attribute for shell variables.
276
+ Marks each NAME for automatic export to the environment of subsequently
277
+ executed commands. If VALUE is supplied, assign VALUE before exporting.
278
+
279
+ Options:
280
+ -f refer to shell functions
281
+ -n remove the export property from each NAME
282
+ -p display a list of all exported variables and functions
283
+
284
+ Exit Status:
285
+ Returns success unless an invalid option is given or NAME is invalid.`],false:["false",`Return an unsuccessful result.
286
+ Exit Status:
287
+ Always fails.`],fc:["fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]",`Display or execute commands from the history list.
288
+ Exit Status:
289
+ Returns success or status of executed command.`],fg:["fg [job_spec]",`Move job to the foreground.
290
+ Place the job identified by JOB_SPEC in the foreground, making it the
291
+ current job.`],getopts:["getopts optstring name [arg]",`Parse option arguments.
292
+ Getopts is used by shell procedures to parse positional parameters
293
+ as options.
294
+
295
+ OPTSTRING contains the option letters to be recognized; if a letter
296
+ is followed by a colon, the option is expected to have an argument,
297
+ which should be separated from it by white space.
298
+ Exit Status:
299
+ Returns success if an option is found; fails if the end of options is
300
+ encountered or an error occurs.`],hash:["hash [-lr] [-p pathname] [-dt] [name ...]",`Remember or display program locations.
301
+ Determine and remember the full pathname of each command NAME.
302
+ Exit Status:
303
+ Returns success unless NAME is not found or an invalid option is given.`],help:["help [-s] [pattern ...]",`Display information about builtin commands.
304
+ Displays brief summaries of builtin commands. If PATTERN is
305
+ specified, gives detailed help on all commands matching PATTERN,
306
+ otherwise the list of help topics is printed.
307
+
308
+ Options:
309
+ -s output only a short usage synopsis for each topic matching
310
+ PATTERN
311
+
312
+ Exit Status:
313
+ Returns success unless PATTERN is not found.`],history:["history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]",`Display or manipulate the history list.
314
+ Display the history list with line numbers, prefixing each modified
315
+ entry with a \`*'.
316
+ Exit Status:
317
+ Returns success unless an invalid option is given or an error occurs.`],jobs:["jobs [-lnprs] [jobspec ...] or jobs -x command [args]",`Display status of jobs.
318
+ Lists the active jobs.
319
+ Exit Status:
320
+ Returns success unless an invalid option is given or an error occurs.`],kill:["kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]",`Send a signal to a job.
321
+ Send the processes identified by PID or JOBSPEC the signal named by
322
+ SIGSPEC or SIGNUM.
323
+ Exit Status:
324
+ Returns success unless an invalid option is given or an error occurs.`],let:["let arg [arg ...]",`Evaluate arithmetic expressions.
325
+ Evaluate each ARG as an arithmetic expression. Evaluation is done in
326
+ fixed-width integers with no check for overflow, though division by 0
327
+ is trapped and flagged as an error.
328
+ Exit Status:
329
+ If the last ARG evaluates to 0, let returns 1; 0 is returned otherwise.`],local:["local [option] name[=value] ...",`Define local variables.
330
+ Create a local variable called NAME, and give it VALUE. OPTION can
331
+ be any option accepted by \`declare'.
332
+
333
+ Local can only be used within a function; it makes the variable NAME
334
+ have a visible scope restricted to that function and its children.
335
+ Exit Status:
336
+ Returns success unless an invalid option is supplied, a variable
337
+ assignment error occurs, or the shell is not executing a function.`],logout:["logout [n]",`Exit a login shell.
338
+ Exits a login shell with exit status N. Returns an error if not executed
339
+ in a login shell.`],mapfile:["mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]",`Read lines from the standard input into an indexed array variable.
340
+ Read lines from the standard input into the indexed array variable ARRAY,
341
+ or from file descriptor FD if the -u option is supplied.
342
+
343
+ Options:
344
+ -d delim Use DELIM to terminate lines, instead of newline
345
+ -n count Copy at most COUNT lines
346
+ -O origin Begin assigning to ARRAY at index ORIGIN
347
+ -s count Discard the first COUNT lines read
348
+ -t Remove a trailing DELIM from each line read (default newline)
349
+ -u fd Read lines from file descriptor FD instead of standard input
350
+
351
+ Exit Status:
352
+ Returns success unless an invalid option is given or ARRAY is readonly.`],popd:["popd [-n] [+N | -N]",`Remove directories from stack.
353
+ Removes entries from the directory stack.
354
+ Exit Status:
355
+ Returns success unless an invalid argument is supplied or the directory
356
+ change fails.`],printf:["printf [-v var] format [arguments]",`Formats and prints ARGUMENTS under control of the FORMAT.
357
+
358
+ Options:
359
+ -v var assign the output to shell variable VAR rather than
360
+ display it on the standard output
361
+
362
+ FORMAT is a character string which contains three types of objects: plain
363
+ characters, which are simply copied to standard output; character escape
364
+ sequences, which are converted and copied to the standard output; and
365
+ format specifications, each of which causes printing of the next successive
366
+ argument.
367
+ Exit Status:
368
+ Returns success unless an invalid option is given or a write or assignment
369
+ error occurs.`],pushd:["pushd [-n] [+N | -N | dir]",`Add directories to stack.
370
+ Adds a directory to the top of the directory stack, or rotates
371
+ the stack, making the new top of the stack the current working
372
+ directory.
373
+ Exit Status:
374
+ Returns success unless an invalid argument is supplied or the directory
375
+ change fails.`],pwd:["pwd [-LP]",`Print the name of the current working directory.
376
+
377
+ Options:
378
+ -L print the value of $PWD if it names the current working
379
+ directory
380
+ -P print the physical directory, without any symbolic links
381
+
382
+ By default, \`pwd' behaves as if \`-L' were specified.
383
+ Exit Status:
384
+ Returns 0 unless an invalid option is given or the current directory
385
+ cannot be read.`],read:["read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]",`Read a line from the standard input and split it into fields.
386
+ Reads a single line from the standard input, or from file descriptor FD
387
+ if the -u option is supplied. The line is split into fields as with word
388
+ splitting, and the first word is assigned to the first NAME, the second
389
+ word to the second NAME, and so on, with any leftover words assigned to
390
+ the last NAME.
391
+ Exit Status:
392
+ The return code is zero, unless end-of-file is encountered, read times out,
393
+ or an invalid file descriptor is supplied as the argument to -u.`],readarray:["readarray [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]","Read lines from a file into an array variable.\n A synonym for `mapfile'."],readonly:["readonly [-aAf] [name[=value] ...] or readonly -p",`Mark shell variables as unchangeable.
394
+ Mark each NAME as read-only; the values of these NAMEs may not be
395
+ changed by subsequent assignment.
396
+ Exit Status:
397
+ Returns success unless an invalid option is given or NAME is invalid.`],return:["return [n]",`Return from a shell function.
398
+ Causes a function or sourced script to exit with the return value
399
+ specified by N. If N is omitted, the return status is that of the
400
+ last command executed within the function or script.
401
+ Exit Status:
402
+ Returns N, or failure if the shell is not executing a function or script.`],set:["set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]",`Set or unset values of shell options and positional parameters.
403
+ Change the value of shell attributes and positional parameters, or
404
+ display the names and values of shell variables.
405
+
406
+ Options:
407
+ -e Exit immediately if a command exits with a non-zero status.
408
+ -u Treat unset variables as an error when substituting.
409
+ -x Print commands and their arguments as they are executed.
410
+ -o option-name
411
+ Set the variable corresponding to option-name
412
+
413
+ Exit Status:
414
+ Returns success unless an invalid option is given.`],shift:["shift [n]",`Shift positional parameters.
415
+ Rename the positional parameters $N+1,$N+2 ... to $1,$2 ... If N is
416
+ not given, it is assumed to be 1.
417
+ Exit Status:
418
+ Returns success unless N is negative or greater than $#.`],shopt:["shopt [-pqsu] [-o] [optname ...]",`Set and unset shell options.
419
+ Change the setting of each shell option OPTNAME. Without any option
420
+ arguments, list each supplied OPTNAME, or all shell options if no
421
+ OPTNAMEs are given, with an indication of whether or not each is set.
422
+
423
+ Options:
424
+ -o restrict OPTNAMEs to those defined for use with \`set -o'
425
+ -p print each shell option with an indication of its status
426
+ -q suppress output
427
+ -s enable (set) each OPTNAME
428
+ -u disable (unset) each OPTNAME
429
+
430
+ Exit Status:
431
+ Returns success if OPTNAME is enabled; fails if an invalid option is
432
+ given or OPTNAME is disabled.`],source:["source filename [arguments]",`Execute commands from a file in the current shell.
433
+ Read and execute commands from FILENAME in the current shell.
434
+ The entries in $PATH are used to find the directory containing FILENAME.
435
+ Exit Status:
436
+ Returns the status of the last command executed in FILENAME.`],suspend:["suspend [-f]",`Suspend shell execution.
437
+ Suspend the execution of this shell until it receives a SIGCONT signal.`],test:["test [expr]",`Evaluate conditional expression.
438
+ Exits with a status of 0 (true) or 1 (false) depending on
439
+ the evaluation of EXPR. Expressions may be unary or binary.
440
+ Exit Status:
441
+ Returns success if EXPR evaluates to true; fails if EXPR evaluates to
442
+ false or an invalid argument is given.`],times:["times",`Display process times.
443
+ Prints the accumulated user and system times for the shell and all of its
444
+ child processes.
445
+ Exit Status:
446
+ Always succeeds.`],trap:["trap [-lp] [[arg] signal_spec ...]",`Trap signals and other events.
447
+ Defines and activates handlers to be run when the shell receives signals
448
+ or other conditions.
449
+ Exit Status:
450
+ Returns success unless a SIGSPEC is invalid or an invalid option is given.`],true:["true",`Return a successful result.
451
+ Exit Status:
452
+ Always succeeds.`],type:["type [-afptP] name [name ...]",`Display information about command type.
453
+ For each NAME, indicate how it would be interpreted if used as a
454
+ command name.
455
+
456
+ Options:
457
+ -a display all locations containing an executable named NAME
458
+ -f suppress shell function lookup
459
+ -P force a PATH search for each NAME, even if it is an alias,
460
+ builtin, or function, and returns the name of the disk file
461
+ that would be executed
462
+ -p returns either the name of the disk file that would be executed,
463
+ or nothing if \`type -t NAME' would not return \`file'
464
+ -t output a single word which is one of \`alias', \`keyword',
465
+ \`function', \`builtin', \`file' or \`', if NAME is an alias,
466
+ shell reserved word, shell function, shell builtin, disk file,
467
+ or not found, respectively
468
+
469
+ Exit Status:
470
+ Returns success if all of the NAMEs are found; fails if any are not found.`],typeset:["typeset [-aAfFgilnrtux] [-p] name[=value] ...","Set variable values and attributes.\n A synonym for `declare'."],ulimit:["ulimit [-SHabcdefiklmnpqrstuvxPT] [limit]",`Modify shell resource limits.
471
+ Provides control over the resources available to the shell and processes
472
+ it creates, on systems that allow such control.
473
+ Exit Status:
474
+ Returns success unless an invalid option is supplied or an error occurs.`],umask:["umask [-p] [-S] [mode]",`Display or set file mode mask.
475
+ Sets the user file-creation mask to MODE. If MODE is omitted, prints
476
+ the current value of the mask.
477
+ Exit Status:
478
+ Returns success unless MODE is invalid or an invalid option is given.`],unalias:["unalias [-a] name [name ...]",`Remove each NAME from the list of defined aliases.
479
+ Exit Status:
480
+ Returns success unless a NAME is not an existing alias.`],unset:["unset [-f] [-v] [-n] [name ...]",`Unset values and attributes of shell variables and functions.
481
+ For each NAME, remove the corresponding variable or function.
482
+
483
+ Options:
484
+ -f treat each NAME as a shell function
485
+ -v treat each NAME as a shell variable
486
+ -n treat each NAME as a name reference and unset the variable itself
487
+ rather than the variable it references
488
+
489
+ Without options, unset first tries to unset a variable, and if that fails,
490
+ tries to unset a function.
491
+ Exit Status:
492
+ Returns success unless an invalid option is given or a NAME is read-only.`],wait:["wait [-fn] [id ...]",`Wait for job completion and return exit status.
493
+ Waits for each process identified by an ID, which may be a process ID or a
494
+ job specification, and reports its termination status.
495
+ Exit Status:
496
+ Returns the status of the last ID; fails if ID is invalid or an invalid
497
+ option is given.`]},Un=Object.keys(Hn).sort();function Ss(e,t){let s=!1,n=[],r=0;for(;r<t.length;){let l=t[r];if(l==="--"){for(r++;r<t.length;)n.push(t[r]),r++;break}if(l.startsWith("-")&&l.length>1){for(let c=1;c<l.length;c++){let f=l[c];if(f==="s")s=!0;else return S(`bash: help: -${f}: invalid option
498
+ `,2)}r++}else n.push(l),r++}if(n.length===0)return Di();let i="",o=!1,a="";for(let l of n){let c=Oi(l);if(c.length===0){a+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
499
+ `,o=!0;continue}for(let f of c){let[u,d]=Hn[f];s?i+=`${f}: ${u}
500
+ `:i+=`${f}: ${u}
501
+ ${d}
502
+ `}}return{exitCode:o?1:0,stdout:i,stderr:a}}function Oi(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),s=new RegExp(`^${t}$`);return Un.filter(n=>s.test(n))}function Di(){let e=[];e.push("just-bash shell builtins"),e.push("These shell commands are defined internally. Type `help' to see this list."),e.push("Type `help name' to find out more about the function `name'."),e.push("");let t=36,s=Un.slice(),n=Math.ceil(s.length/2);for(let r=0;r<n;r++){let i=s[r]||"",o=s[r+n]||"",a=i.padEnd(t);e.push(o?`${a}${o}`:i)}return F(`${e.join(`
503
+ `)}
504
+ `)}function Ti(e){let t=[],s="",n=0;for(let r of e){for(let i of r)i==="("?n++:i===")"&&n--;s?s+=` ${r}`:s=r,n===0&&(t.push(s),s="")}return s&&t.push(s),t}async function As(e,t){if(t.length===0)return S(`bash: let: expression expected
505
+ `);let s=Ti(t),n=0;for(let r of s)try{let o=de(`(( ${r} ))`).statements[0];if(o&&o.pipelines.length>0&&o.pipelines[0].commands.length>0){let a=o.pipelines[0].commands[0];a.type==="ArithmeticCommand"&&(n=await V(e,a.expression.expression))}}catch(i){return S(`bash: let: ${r}: ${i.message}
506
+ `)}return P("","",n===0?1:0)}async function Ps(e,t){if(e.state.localScopes.length===0)return S(`bash: local: can only be used in a function
507
+ `);let s=e.state.localScopes[e.state.localScopes.length-1],n="",r=0,i=!1,o=!1,a=!1,l=[];for(let c of t)if(c==="-n")i=!0;else if(c==="-a")o=!0;else if(c==="-p")a=!0;else if(c.startsWith("-")&&!c.includes("="))for(let f of c.slice(1))f==="n"?i=!0:f==="a"?o=!0:f==="p"&&(a=!0);else l.push(c);if(l.length===0){let c="",f=Array.from(s.keys()).filter(u=>!u.includes("_")||!u.match(/_\d+$/)).filter(u=>!u.includes("__length")).sort();for(let u of f){let d=e.state.env[u];d!==void 0&&(c+=`${u}=${d}
508
+ `)}return P(c,"",0)}for(let c of l){let f,u,d=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){f=d[1];let b=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(f)){n+=`bash: local: \`${c}': not a valid identifier
509
+ `,r=1;continue}if(K(e,f,"bash"),!s.has(f)){s.set(f,e.state.env[f]);let y=`${f}_`;for(let g of Object.keys(e.state.env))g.startsWith(y)&&!g.includes("__")&&(s.has(g)||s.set(g,e.state.env[g]))}let $=`${f}_`;for(let y of Object.keys(e.state.env))y.startsWith($)&&!y.includes("__")&&delete e.state.env[y];let C=me(b);for(let y=0;y<C.length;y++)e.state.env[`${f}_${y}`]=C[y];e.state.env[`${f}__length`]=String(C.length),Ne(e,f),i&&ve(e,f);continue}let h=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(h){f=h[1];let b=h[2];if(K(e,f,"bash"),!s.has(f)){s.set(f,e.state.env[f]);let v=`${f}_`;for(let k of Object.keys(e.state.env))k.startsWith(v)&&!k.includes("__")&&(s.has(k)||s.set(k,e.state.env[k]));let _=`${f}__length`;e.state.env[_]!==void 0&&!s.has(_)&&s.set(_,e.state.env[_])}let $=me(b),C=J(e,f),y=0;if(C.length===0&&e.state.env[f]!==void 0){let v=e.state.env[f];e.state.env[`${f}_0`]=v,delete e.state.env[f],y=1}else C.length>0&&(y=Math.max(...C)+1);for(let v=0;v<$.length;v++)e.state.env[`${f}_${y+v}`]=H(e,$[v]);let g=y+$.length;e.state.env[`${f}__length`]=String(g),Ne(e,f),i&&ve(e,f);continue}let m=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(m){f=m[1];let b=H(e,m[2]);K(e,f,"bash"),s.has(f)||s.set(f,e.state.env[f]);let $=e.state.env[f]??"";e.state.env[f]=$+b,Ne(e,f),i&&ve(e,f);continue}let p=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(p){f=p[1];let b=p[2],$=H(e,p[3]);if(K(e,f,"bash"),!s.has(f)){s.set(f,e.state.env[f]);let g=`${f}_`;for(let _ of Object.keys(e.state.env))_.startsWith(g)&&!_.includes("__")&&(s.has(_)||s.set(_,e.state.env[_]));let v=`${f}__length`;e.state.env[v]!==void 0&&!s.has(v)&&s.set(v,e.state.env[v])}let C;try{let g=new W,v=Z(g,b);C=await V(e,v.expression)}catch{let g=parseInt(b,10);C=Number.isNaN(g)?0:g}e.state.env[`${f}_${C}`]=$;let y=parseInt(e.state.env[`${f}__length`]??"0",10);C>=y&&(e.state.env[`${f}__length`]=String(C+1)),Ne(e,f),i&&ve(e,f);continue}if(c.includes("=")){let b=c.indexOf("=");f=c.slice(0,b),u=H(e,c.slice(b+1))}else f=c;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(f)){n+=`bash: local: \`${c}': not a valid identifier
510
+ `,r=1;continue}let w=s.has(f);if(u!==void 0){let b=e.state.env[f];if(e.state.tempEnvBindings){let $=e.state.accessedTempEnvVars?.has(f),C=e.state.mutatedTempEnvVars?.has(f);if(!$&&!C)for(let y=e.state.tempEnvBindings.length-1;y>=0;y--){let g=e.state.tempEnvBindings[y];if(g.has(f)){b=g.get(f);break}}}kn(e,f,b)}if(!w){let b=e.state.env[f];if(e.state.tempEnvBindings)for(let $=e.state.tempEnvBindings.length-1;$>=0;$--){let C=e.state.tempEnvBindings[$];if(C.has(f)){b=C.get(f);break}}if(s.set(f,b),o){let $=`${f}_`;for(let y of Object.keys(e.state.env))y.startsWith($)&&!y.includes("__")&&(s.has(y)||s.set(y,e.state.env[y]));let C=`${f}__length`;e.state.env[C]!==void 0&&!s.has(C)&&s.set(C,e.state.env[C])}}if(o&&u===void 0){let b=`${f}_`;for(let $ of Object.keys(e.state.env))$.startsWith(b)&&!$.includes("__")&&delete e.state.env[$];e.state.env[`${f}__length`]="0"}else if(u!==void 0){if(K(e,f,"bash"),i&&u!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(u)){n+=`bash: local: \`${u}': invalid variable name for name reference
511
+ `,r=1;continue}e.state.env[f]=u,e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(f))}else{let b=e.state.tempEnvBindings?.some($=>$.has(f));!w&&!b&&delete e.state.env[f]}Ne(e,f),i&&ve(e,f)}return P("",n,r)}function _s(e,t,s){let n=`
512
+ `,r=0,i=0,o=0,a=!1,l="MAPFILE",c=0;for(;c<t.length;){let b=t[c];b==="-d"&&c+1<t.length?(n=t[c+1]===""?"\0":t[c+1]||`
513
+ `,c+=2):b==="-n"&&c+1<t.length?(r=Number.parseInt(t[c+1],10)||0,c+=2):b==="-O"&&c+1<t.length?(i=Number.parseInt(t[c+1],10)||0,c+=2):b==="-s"&&c+1<t.length?(o=Number.parseInt(t[c+1],10)||0,c+=2):b==="-t"?(a=!0,c++):b==="-u"||b==="-C"||b==="-c"?c+=2:(b.startsWith("-")||(l=b),c++)}let f=s;!f&&e.state.groupStdin!==void 0&&(f=e.state.groupStdin);let u=[],d=f,h=0,m=0;for(;d.length>0;){let b=d.indexOf(n);if(b===-1){if(d.length>0){if(m<o)m++;else if(r===0||h<r){let y=d,g=y.indexOf("\0");g!==-1&&(y=y.substring(0,g)),u.push(y),h++}}break}let $=d.substring(0,b),C=$.indexOf("\0");if(C!==-1&&($=$.substring(0,C)),!a&&n!=="\0"&&($+=n),d=d.substring(b+n.length),m<o){m++;continue}if(r>0&&h>=r)break;u.push($),h++}i===0&&he(e,l);for(let b=0;b<u.length;b++)e.state.env[`${l}_${i+b}`]=u[b];let p=parseInt(e.state.env[`${l}__length`]||"0",10),w=i+u.length;return e.state.env[`${l}__length`]=String(Math.max(p,w)),e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=""),P("","",0)}function Ii(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),o=r+n+1,a=t.slice(o),l=a.indexOf(":");if(l===-1)return null;let c=Number.parseInt(a.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let f=a.slice(l+1);return{path:i,position:c,content:f}}function Ri(e,t,s){return`__rw__:${e.length}:${e}:${t}:${s}`}function Ns(e,t,s,n=-1){let r=!1,i=`
514
+ `,o="",a=-1,l=-1,c=null,f=-1,u=-1,d=[],h=0,m=!1,p=(A,N)=>{let D=1;for(;D<A.length;){let E=A[D];if(E==="r")r=!0,D++;else if(E==="s")D++;else{if(E==="d")return D+1<A.length?(i=A.substring(D+1),{nextArgIndex:N+1}):N+1<t.length?(i=t[N+1],{nextArgIndex:N+2}):{nextArgIndex:N+1};if(E==="n"){if(D+1<A.length){let O=A.substring(D+1);return a=Number.parseInt(O,10),(Number.isNaN(a)||a<0)&&(m=!0,a=0),{nextArgIndex:N+1}}else if(N+1<t.length)return a=Number.parseInt(t[N+1],10),(Number.isNaN(a)||a<0)&&(m=!0,a=0),{nextArgIndex:N+2};return{nextArgIndex:N+1}}else if(E==="N"){if(D+1<A.length){let O=A.substring(D+1);return l=Number.parseInt(O,10),(Number.isNaN(l)||l<0)&&(m=!0,l=0),{nextArgIndex:N+1}}else if(N+1<t.length)return l=Number.parseInt(t[N+1],10),(Number.isNaN(l)||l<0)&&(m=!0,l=0),{nextArgIndex:N+2};return{nextArgIndex:N+1}}else{if(E==="a")return D+1<A.length?(c=A.substring(D+1),{nextArgIndex:N+1}):N+1<t.length?(c=t[N+1],{nextArgIndex:N+2}):{nextArgIndex:N+1};if(E==="p")return D+1<A.length?(o=A.substring(D+1),{nextArgIndex:N+1}):N+1<t.length?(o=t[N+1],{nextArgIndex:N+2}):{nextArgIndex:N+1};if(E==="u"){if(D+1<A.length){let O=A.substring(D+1);return f=Number.parseInt(O,10),Number.isNaN(f)||f<0?{nextArgIndex:-2}:{nextArgIndex:N+1}}else if(N+1<t.length)return f=Number.parseInt(t[N+1],10),Number.isNaN(f)||f<0?{nextArgIndex:-2}:{nextArgIndex:N+2};return{nextArgIndex:N+1}}else if(E==="t"){if(D+1<A.length){let O=A.substring(D+1);return u=Number.parseFloat(O),Number.isNaN(u)&&(u=0),{nextArgIndex:N+1}}else if(N+1<t.length)return u=Number.parseFloat(t[N+1]),Number.isNaN(u)&&(u=0),{nextArgIndex:N+2};return{nextArgIndex:N+1}}else if(E==="e"||E==="i"||E==="P"){if(E==="i"&&N+1<t.length)return{nextArgIndex:N+2};D++}else D++}}}return{nextArgIndex:N+1}};for(;h<t.length;){let A=t[h];if(A.startsWith("-")&&A.length>1&&A!=="--"){let N=p(A,h);if(N.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(N.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=N.nextArgIndex}else if(A==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push(A),h++}if(m)return P("","",1);if(d.length===0&&c===null&&d.push("REPLY"),u===0){if(c)he(e,c);else{for(let A of d)e.state.env[A]="";d.length===0&&(e.state.env.REPLY="")}return P("","",0)}if(u<0&&u!==-1)return P("","",1);let w=s;f>=0?e.state.fileDescriptors?w=e.state.fileDescriptors.get(f)||"":w="":!w&&e.state.groupStdin!==void 0&&(w=e.state.groupStdin);let b=i===""?"\0":i,$="",C=0,y=!0,g=A=>{if(f>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(f,w.substring(A));else if(n>=0&&e.state.fileDescriptors){let N=e.state.fileDescriptors.get(n);if(N?.startsWith("__rw__:")){let D=Ii(N);if(D){let E=D.position+A;e.state.fileDescriptors.set(n,Ri(D.path,E,D.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=w.substring(A))};if(l>=0){let A=Math.min(l,w.length);$=w.substring(0,A),C=A,y=A>=l,g(C);let N=d[0]||"REPLY";e.state.env[N]=$;for(let D=1;D<d.length;D++)e.state.env[d[D]]="";return P("","",y?0:1)}else if(a>=0){let A=0,N=0,D=!1;for(;N<w.length&&A<a;){let E=w[N];if(E===b){C=N+1,D=!0;break}if(!r&&E==="\\"&&N+1<w.length){let O=w[N+1];if(O===b&&b===`
515
+ `){N+=2,C=N;continue}if(O===b){N+=2,A++,$+=O,C=N;continue}$+=O,N+=2,A++,C=N}else $+=E,N++,A++,C=N}y=A>=a||D,g(C)}else{C=0;let A=0;for(;A<w.length;){let N=w[A];if(N===b){C=A+b.length,y=!0;break}if(!r&&N==="\\"&&A+1<w.length){let D=w[A+1];if(D===`
516
+ `){A+=2;continue}if(D===b){$+=D,A+=2;continue}$+=N,$+=D,A+=2;continue}$+=N,A++}if(A>=w.length&&(y=!1,C=A,$.length===0&&w.length===0)){for(let N of d)e.state.env[N]="";return c&&he(e,c),P("","",1)}g(C)}b===`
517
+ `&&$.endsWith(`
518
+ `)&&($=$.slice(0,-1));let v=A=>r?A:A.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.REPLY=v($),P("","",y?0:1);let _=Us(e.state.env);if(c){let{words:A}=Mt($,_,void 0,r);he(e,c);for(let N=0;N<A.length;N++)e.state.env[`${c}_${N}`]=v(A[N]);return P("","",y?0:1)}let k=d.length,{words:I,wordStarts:R}=Mt($,_,k,r);for(let A=0;A<d.length;A++){let N=d[A];if(A<d.length-1)e.state.env[N]=v(I[A]??"");else if(A<R.length){let D=$.substring(R[A]);D=qs(D,_,r),D=v(D),e.state.env[N]=D}else e.state.env[N]=""}return P("","",y?0:1)}function Cs(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return S("bash: return: can only `return' from a function or sourced script\n");let s=e.state.lastExitCode;if(t.length>0){let n=t[0],r=Number.parseInt(n,10);if(n===""||Number.isNaN(r)||!/^-?\d+$/.test(n))return S(`bash: return: ${n}: numeric argument required
519
+ `,2);s=(r%256+256)%256}throw new se(s)}var kt=`set: usage: set [-eux] [+eux] [-o option] [+o option]
76
520
  Options:
77
521
  -e Exit immediately if a command exits with non-zero status
78
522
  +e Disable -e
@@ -88,65 +532,145 @@ Options:
88
532
  +o pipefail Disable pipefail
89
533
  -o xtrace Same as -x
90
534
  +o xtrace Disable xtrace
91
- `,Cs={e:"errexit",u:"nounset",x:"xtrace",v:"verbose",f:null,h:null,C:null,n:null,a:null,b:null,m:null,B:null,H:null,P:null,T:null,E:null,p:null},Ns={errexit:"errexit",pipefail:"pipefail",nounset:"nounset",xtrace:"xtrace",verbose:"verbose",noclobber:null,noglob:null,noexec:null,allexport:null,notify:null,monitor:null,braceexpand:null,histexpand:null,physical:null,functrace:null,errtrace:null,privileged:null,hashall:null,posix:null,vi:null,emacs:null,ignoreeof:null,"interactive-comments":null,keyword:null,onecmd:null},Ps=["errexit","nounset","pipefail","verbose","xtrace"],vs=["allexport","braceexpand","emacs","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","noclobber","noexec","noglob","nolog","notify","onecmd","physical","posix","privileged","vi"];function $s(t,e,s){e!==null&&(t.state.options[e]=s)}function Qn(t,e){return e+1<t.length&&!t[e+1].startsWith("-")&&!t[e+1].startsWith("+")}function lr(t,e){if(e.includes("--help"))return j(ot);if(e.length===0){let r=Object.entries(t.state.env).filter(([n])=>/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)).sort(([n],[i])=>n.localeCompare(i)).map(([n,i])=>`${n}=${Zn(i)}`).join(`
92
- `);return j(r?`${r}
93
- `:"")}let s=0;for(;s<e.length;){let r=e[s];if((r==="-o"||r==="+o")&&Qn(e,s)){let n=e[s+1];if(!(n in Ns))return x(`bash: set: ${n}: invalid option name
94
- ${ot}`);$s(t,Ns[n],r==="-o"),s+=2;continue}if(r==="-o"){let n=Ps.map(a=>`${a.padEnd(16)}${t.state.options[a]?"on":"off"}`),i=vs.map(a=>`${a.padEnd(16)}off`),o=[...n,...i].sort();return j(`${o.join(`
535
+ `,qn={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},Zn={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},Gn=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],Xn=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Kn(e,t,s){t!==null&&(s&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=s,xe(e))}function xi(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Li(e,t){let s=J(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env[`${t}_${r}`]??"";return`[${r}]=${Ie(i)}`});return`${t}=(${n.join(" ")})`}function Fi(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Mi(e,t){let s=Ae(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env[`${t}_${r}`]??"";return`[${Fi(r)}]=${Ie(i)}`});return`${t}=(${n.join(" ")} )`}function Wi(e){let t=new Set,s=e.state.associativeArrays??new Set;for(let n of Object.keys(e.state.env)){let r=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(r){let i=r[1];s.has(i)||t.add(i)}}return t}function zi(e){return e.state.associativeArrays??new Set}function Os(e,t){if(t.includes("--help"))return F(kt);if(t.length===0){let n=Wi(e),r=zi(e),i=l=>{for(let c of r){let f=`${c}_`,u=`${c}__length`;if(l!==u&&l.startsWith(f)){if(l.slice(f.length).startsWith("_length"))continue;return!0}}return!1},o=[];for(let[l,c]of Object.entries(e.state.env)){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l)||n.has(l)||r.has(l))continue;let f=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(f&&n.has(f[1]))continue;let u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);u&&n.has(u[1])||i(l)||u&&r.has(u[1])||o.push([l,c])}let a=[];for(let[l,c]of o.sort(([f],[u])=>f<u?-1:f>u?1:0))a.push(`${l}=${_t(c)}`);for(let l of[...n].sort((c,f)=>c<f?-1:c>f?1:0))a.push(Li(e,l));for(let l of[...r].sort((c,f)=>c<f?-1:c>f?1:0))a.push(Mi(e,l));return a.sort((l,c)=>{let f=l.split("=")[0],u=c.split("=")[0];return f<u?-1:f>u?1:0}),F(a.length>0?`${a.join(`
536
+ `)}
537
+ `:"")}let s=0;for(;s<t.length;){let n=t[s];if((n==="-o"||n==="+o")&&xi(t,s)){let r=t[s+1];if(!(r in Zn)){let i=`bash: set: ${r}: invalid option name
538
+ ${kt}`;if(e.state.options.posix)throw new ce(1,"",i);return S(i)}Kn(e,Zn[r],n==="-o"),s+=2;continue}if(n==="-o"){let r=Gn.map(a=>`${a.padEnd(16)}${e.state.options[a]?"on":"off"}`),i=Xn.map(a=>`${a.padEnd(16)}off`),o=[...r,...i].sort();return F(`${o.join(`
539
+ `)}
540
+ `)}if(n==="+o"){let r=Gn.map(a=>`set ${e.state.options[a]?"-o":"+o"} ${a}`),i=Xn.map(a=>`set +o ${a}`),o=[...r,...i].sort();return F(`${o.join(`
541
+ `)}
542
+ `)}if(n.length>1&&(n[0]==="-"||n[0]==="+")&&n[1]!=="-"){let r=n[0]==="-";for(let i=1;i<n.length;i++){let o=n[i];if(!(o in qn)){let a=`bash: set: ${n[0]}${o}: invalid option
543
+ ${kt}`;if(e.state.options.posix)throw new ce(1,"",a);return S(a)}Kn(e,qn[o],r)}s++;continue}if(n==="--")return ks(e,t.slice(s+1)),L;if(n==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,xe(e),s+1<t.length)return ks(e,t.slice(s+1)),L;s++;continue}if(n==="+"){s++;continue}if(n.startsWith("-")||n.startsWith("+")){let r=`bash: set: ${n}: invalid option
544
+ ${kt}`;if(e.state.options.posix)throw new ce(1,"",r);return S(r)}return ks(e,t.slice(s)),L}return L}function ks(e,t){let s=1;for(;e.state.env[String(s)]!==void 0;)delete e.state.env[String(s)],s++;for(let n=0;n<t.length;n++)e.state.env[String(n+1)]=t[n];e.state.env["#"]=String(t.length),e.state.env["@"]=t.join(" "),e.state.env["*"]=t.join(" ")}function Ds(e,t){let s=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
545
+ `;if(e.state.options.posix)throw new ce(1,"",a);return S(a)}s=o}let n=Number.parseInt(e.state.env["#"]||"0",10);if(s>n){let o=`bash: shift: shift count out of range
546
+ `;if(e.state.options.posix)throw new ce(1,"",o);return S(o)}if(s===0)return L;let r=[];for(let o=1;o<=n;o++)r.push(e.state.env[String(o)]||"");let i=r.slice(s);for(let o=1;o<=n;o++)delete e.state.env[String(o)];for(let o=0;o<i.length;o++)e.state.env[String(o+1)]=i[o];return e.state.env["#"]=String(i.length),e.state.env["@"]=i.join(" "),L}async function Ts(e,t){let s=t;if(s.length>0&&s[0]==="--"&&(s=s.slice(1)),s.length===0)return P("",`bash: source: filename argument required
547
+ `,2);let n=s[0],r=null,i=null;if(n.includes("/")){let c=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(c),r=c}catch{}}else{let f=(e.state.env.PATH||"").split(":").filter(u=>u);for(let u of f){let d=e.fs.resolvePath(e.state.cwd,`${u}/${n}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),r=d;break}catch{}}if(i===null){let u=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(u),r=u}catch{}}}if(i===null)return S(`bash: ${n}: No such file or directory
548
+ `);let o={};if(s.length>1){for(let f=1;f<=9;f++)o[String(f)]=e.state.env[String(f)];o["#"]=e.state.env["#"],o["@"]=e.state.env["@"];let c=s.slice(1);e.state.env["#"]=String(c.length),e.state.env["@"]=c.join(" ");for(let f=0;f<c.length&&f<9;f++)e.state.env[String(f+1)]=c[f];for(let f=c.length+1;f<=9;f++)delete e.state.env[String(f)]}let a=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=a,s.length>1)for(let[c,f]of Object.entries(o))f===void 0?delete e.state.env[c]:e.state.env[c]=f};e.state.sourceDepth++,e.state.currentSource=n;try{let c=de(i),f=await e.executeScript(c);return l(),f}catch(c){if(l(),c instanceof z)throw c;if(c instanceof se)return P(c.stdout,c.stderr,c.exitCode);if(c.name==="ParseException")return S(`bash: ${n}: ${c.message}
549
+ `);throw c}}function Yn(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Vi(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function Qn(e,t){if(Vi(t))return null;try{let s=new W,n=Z(s,t);return await V(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}function Jn(e,t){if(e.state.localVarStack?.has(t)){let n=St(e,t);if(n){n.value===void 0?delete e.state.env[t]:e.state.env[t]=n.value;let r=e.state.localVarStack?.get(t);if(!r||r.length===0)$t(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,n.scopeIndex),Is(e,t);else{let i=r[r.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return delete e.state.env[t],$t(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let n=e.state.localScopes.length-1;n>=0;n--){let r=e.state.localScopes[n];if(r.has(t)){let i=r.get(t);i===void 0?delete e.state.env[t]:e.state.env[t]=i,r.delete(t);let o=!1;for(let a=n-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||$t(e,t),!0}}return!1}function Is(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let s=e.state.tempEnvBindings.length-1;s>=0;s--){let n=e.state.tempEnvBindings[s];if(n.has(t)){let r=n.get(t);return r===void 0?delete e.state.env[t]:e.state.env[t]=r,n.delete(t),!0}}return!1}async function er(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let s=t.slice(1,-1),r=new W().parseWordFromString(s,!0,!1);return T(e,r)}if(t.includes("$")){let n=new W().parseWordFromString(t,!1,!1);return T(e,n)}return t}async function Rs(e,t){let s="both",n="",r=0;for(let i of t){if(i==="-v"){s="variable";continue}if(i==="-f"){s="function";continue}if(s==="function"){e.state.functions.delete(i);continue}if(s==="variable"){let c=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(c){let d=c[1],h=c[2];if(h==="@"||h==="*"){let C=fe(e,d);for(let[y]of C)delete e.state.env[`${d}_${y}`];delete e.state.env[d];continue}let m=e.state.associativeArrays?.has(d);if(m){let C=await er(e,h);delete e.state.env[`${d}_${C}`];continue}let p=Vt(e,d),w=e.state.declaredVars?.has(d);if((d in e.state.env||w)&&!p&&!m){n+=`bash: unset: ${d}: not an array variable
550
+ `,r=1;continue}let $=await Qn(e,h);if($===null&&p){n+=`bash: unset: ${h}: not a valid identifier
551
+ `,r=1;continue}if($===null)continue;if($<0){let C=fe(e,d),y=C.length,g=e.state.currentLine;if(y===0){n+=`bash: line ${g}: unset: [${$}]: bad array subscript
552
+ `,r=1;continue}let v=y+$;if(v<0){n+=`bash: line ${g}: unset: [${$}]: bad array subscript
553
+ `,r=1;continue}let _=C[v][0];delete e.state.env[`${d}_${_}`];continue}delete e.state.env[`${d}_${$}`];continue}if(!Yn(i)){n+=`bash: unset: \`${i}': not a valid identifier
554
+ `,r=1;continue}let f=i;if(ae(e,i)){let d=Pe(e,i);d&&d!==i&&(f=d)}if(Oe(e,f)){n+=`bash: unset: ${f}: cannot unset: readonly variable
555
+ `,r=1;continue}let u=Fe(e,f);if(u!==void 0&&u!==e.state.callDepth)Jn(e,f);else if(e.state.fullyUnsetLocals?.has(f))delete e.state.env[f];else if(u!==void 0){let d=e.state.accessedTempEnvVars?.has(f),h=e.state.mutatedTempEnvVars?.has(f);if((d||h)&&e.state.localVarStack?.has(f)){let m=St(e,f);m?m.value===void 0?delete e.state.env[f]:e.state.env[f]=m.value:delete e.state.env[f]}else delete e.state.env[f]}else Is(e,f)||delete e.state.env[f];e.state.exportedVars?.delete(f);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let c=o[1],f=o[2];if(f==="@"||f==="*"){let p=fe(e,c);for(let[w]of p)delete e.state.env[`${c}_${w}`];delete e.state.env[c];continue}let u=e.state.associativeArrays?.has(c);if(u){let p=await er(e,f);delete e.state.env[`${c}_${p}`];continue}let d=Vt(e,c);if(c in e.state.env&&!d&&!u){n+=`bash: unset: ${c}: not an array variable
556
+ `,r=1;continue}let m=await Qn(e,f);if(m===null&&d){n+=`bash: unset: ${f}: not a valid identifier
557
+ `,r=1;continue}if(m===null)continue;if(m<0){let p=fe(e,c),w=p.length,b=e.state.currentLine;if(w===0){n+=`bash: line ${b}: unset: [${m}]: bad array subscript
558
+ `,r=1;continue}let $=w+m;if($<0){n+=`bash: line ${b}: unset: [${m}]: bad array subscript
559
+ `,r=1;continue}let C=p[$][0];delete e.state.env[`${c}_${C}`];continue}delete e.state.env[`${c}_${m}`];continue}if(!Yn(i)){n+=`bash: unset: \`${i}': not a valid identifier
560
+ `,r=1;continue}let a=i;if(ae(e,i)){let c=Pe(e,i);c&&c!==i&&(a=c)}if(Oe(e,a)){n+=`bash: unset: ${a}: cannot unset: readonly variable
561
+ `,r=1;continue}let l=Fe(e,a);if(l!==void 0&&l!==e.state.callDepth)Jn(e,a);else if(e.state.fullyUnsetLocals?.has(a))delete e.state.env[a];else if(l!==void 0){let c=e.state.accessedTempEnvVars?.has(a),f=e.state.mutatedTempEnvVars?.has(a);if((c||f)&&e.state.localVarStack?.has(a)){let u=St(e,a);u?u.value===void 0?delete e.state.env[a]:e.state.env[a]=u.value:delete e.state.env[a]}else delete e.state.env[a]}else Is(e,a)||delete e.state.env[a];e.state.exportedVars?.delete(a),e.state.functions.delete(i)}return P("",n,r)}var xs=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],Bi=["autocd","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","execfail","extdebug","extquote","force_fignore","globasciiranges","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath"];function Ot(e){return xs.includes(e)}function ji(e){return Bi.includes(e)}function tr(e,t){let s=!1,n=!1,r=!1,i=!1,o=!1,a=[],l=0;for(;l<t.length;){let d=t[l];if(d==="--"){l++;break}if(d.startsWith("-")&&d.length>1){for(let h=1;h<d.length;h++){let m=d[h];switch(m){case"s":s=!0;break;case"u":n=!0;break;case"p":r=!0;break;case"q":i=!0;break;case"o":o=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${m}: invalid option
562
+ `}}}l++}else break}for(;l<t.length;)a.push(t[l]),l++;if(o)return Hi(e,a,s,n,r,i);if(s&&n)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
563
+ `};if(a.length===0){if(s||n){let h=[];for(let m of xs){let p=e.state.shoptOptions[m];s&&p?h.push(r?`shopt -s ${m}`:`${m} on`):n&&!p&&h.push(r?`shopt -u ${m}`:`${m} off`)}return{exitCode:0,stdout:h.length>0?`${h.join(`
564
+ `)}
565
+ `:"",stderr:""}}let d=[];for(let h of xs){let m=e.state.shoptOptions[h];d.push(r?`shopt ${m?"-s":"-u"} ${h}`:`${h} ${m?"on":"off"}`)}return{exitCode:0,stdout:`${d.join(`
566
+ `)}
567
+ `,stderr:""}}let c=!1,f="",u=[];for(let d of a){if(!Ot(d)&&!ji(d)){f+=`shopt: ${d}: invalid shell option name
568
+ `,c=!0;continue}if(s)Ot(d)&&(e.state.shoptOptions[d]=!0,Ut(e));else if(n)Ot(d)&&(e.state.shoptOptions[d]=!1,Ut(e));else if(Ot(d)){let h=e.state.shoptOptions[d];i?h||(c=!0):r?(u.push(`shopt ${h?"-s":"-u"} ${d}`),h||(c=!0)):(u.push(`${d} ${h?"on":"off"}`),h||(c=!0))}else i?c=!0:r?(u.push(`shopt -u ${d}`),c=!0):(u.push(`${d} off`),c=!0)}return{exitCode:c?1:0,stdout:u.length>0?`${u.join(`
569
+ `)}
570
+ `:"",stderr:f}}function Hi(e,t,s,n,r,i){let o={errexit:"errexit",pipefail:"pipefail",nounset:"nounset",xtrace:"xtrace",verbose:"verbose",posix:"posix",allexport:"allexport",noclobber:"noclobber",noglob:"noglob",noexec:"noexec",vi:"vi",emacs:"emacs"},a=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],l=[...Object.keys(o),...a].sort();if(t.length===0){let d=[];for(let h of l){let p=a.includes(h)?!1:e.state.options[o[h]];s&&!p||n&&p||d.push(r?`set ${p?"-o":"+o"} ${h}`:`${h} ${p?"on":"off"}`)}return{exitCode:0,stdout:d.length>0?`${d.join(`
95
571
  `)}
96
- `)}if(r==="+o"){let n=Ps.map(a=>`set ${t.state.options[a]?"-o":"+o"} ${a}`),i=vs.map(a=>`set +o ${a}`),o=[...n,...i].sort();return j(`${o.join(`
572
+ `:"",stderr:""}}let c=!1,f="",u=[];for(let d of t){let h=d in o,m=a.includes(d);if(!h&&!m){f+=`shopt: ${d}: invalid option name
573
+ `,c=!0;continue}if(m){s||n||(i?c=!0:r?(u.push(`set +o ${d}`),c=!0):(u.push(`${d} off`),c=!0));continue}let p=o[d];if(s)p==="vi"?e.state.options.emacs=!1:p==="emacs"&&(e.state.options.vi=!1),e.state.options[p]=!0,xe(e);else if(n)e.state.options[p]=!1,xe(e);else{let w=e.state.options[p];i?w||(c=!0):r?(u.push(`set ${w?"-o":"+o"} ${d}`),w||(c=!0)):(u.push(`${d} ${w?"on":"off"}`),w||(c=!0))}}return{exitCode:c?1:0,stdout:u.length>0?`${u.join(`
97
574
  `)}
98
- `)}if(r.length>1&&(r[0]==="-"||r[0]==="+")&&r[1]!=="-"){let n=r[0]==="-";for(let i=1;i<r.length;i++){let o=r[i];if(!(o in Cs))return x(`bash: set: ${r[0]}${o}: invalid option
99
- ${ot}`);$s(t,Cs[o],n)}s++;continue}if(r==="--")return cr(t,e.slice(s+1)),N;if(r==="-"){if(t.state.options.xtrace=!1,t.state.options.verbose=!1,s+1<e.length)return cr(t,e.slice(s+1)),N;s++;continue}if(r==="+"){s++;continue}return r.startsWith("-")||r.startsWith("+")?x(`bash: set: ${r}: invalid option
100
- ${ot}`):(cr(t,e.slice(s)),N)}return N}function cr(t,e){let s=1;for(;t.state.env[String(s)]!==void 0;)delete t.state.env[String(s)],s++;for(let r=0;r<e.length;r++)t.state.env[String(r+1)]=e[r];t.state.env["#"]=String(e.length),t.state.env["@"]=e.join(" "),t.state.env["*"]=e.join(" ")}function ur(t,e){let s=1;if(e.length>0){let o=Number.parseInt(e[0],10);if(Number.isNaN(o)||o<0)return x(`bash: shift: ${e[0]}: numeric argument required
101
- `);s=o}let r=Number.parseInt(t.state.env["#"]||"0",10);if(s>r)return x(`bash: shift: shift count out of range
102
- `);if(s===0)return N;let n=[];for(let o=1;o<=r;o++)n.push(t.state.env[String(o)]||"");let i=n.slice(s);for(let o=1;o<=r;o++)delete t.state.env[String(o)];for(let o=0;o<i.length;o++)t.state.env[String(o+1)]=i[o];return t.state.env["#"]=String(i.length),t.state.env["@"]=i.join(" "),N}async function fr(t,e){let s=e;if(s.length>0&&s[0]==="--"&&(s=s.slice(1)),s.length===0)return S("",`bash: source: filename argument required
103
- `,2);let r=s[0],n=null,i=null;if(r.includes("/")){let c=t.fs.resolvePath(t.state.cwd,r);try{i=await t.fs.readFile(c),n=c}catch{}}else{let l=(t.state.env.PATH||"").split(":").filter(u=>u);for(let u of l){let h=t.fs.resolvePath(t.state.cwd,`${u}/${r}`);try{if((await t.fs.stat(h)).isDirectory)continue;i=await t.fs.readFile(h),n=h;break}catch{}}if(i===null){let u=t.fs.resolvePath(t.state.cwd,r);try{i=await t.fs.readFile(u),n=u}catch{}}}if(i===null)return x(`bash: ${r}: No such file or directory
104
- `);let o={};if(s.length>1){for(let l=1;l<=9;l++)o[String(l)]=t.state.env[String(l)];o["#"]=t.state.env["#"],o["@"]=t.state.env["@"];let c=s.slice(1);t.state.env["#"]=String(c.length),t.state.env["@"]=c.join(" ");for(let l=0;l<c.length&&l<9;l++)t.state.env[String(l+1)]=c[l];for(let l=c.length+1;l<=9;l++)delete t.state.env[String(l)]}let a=()=>{if(t.state.sourceDepth--,s.length>1)for(let[c,l]of Object.entries(o))l===void 0?delete t.state.env[c]:t.state.env[c]=l};t.state.sourceDepth++;try{let c=he(i),l=await t.executeScript(c);return a(),l}catch(c){if(a(),c instanceof R)throw c;if(c instanceof G)return S(c.stdout,c.stderr,c.exitCode);if(c.name==="ParseException")return x(`bash: ${r}: ${c.message}
105
- `);throw c}}function hr(t,e){let s="variable",r="",n=0;for(let i of e){if(i==="-v"){s="variable";continue}if(i==="-f"){s="function";continue}if(s==="function"){t.state.functions.delete(i);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let a=o[1],c=o[2];if(c==="@"||c==="*"){let u=F(t,a);for(let[h]of u)delete t.state.env[`${a}_${h}`];delete t.state.env[a];continue}let l;if(/^-?\d+$/.test(c))l=Number.parseInt(c,10);else{let u=t.state.env[c];l=u?Number.parseInt(u,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let u=F(t,a),h=u.length;if(h===0){r+=`bash: unset: [${l}]: bad array subscript
106
- `,n=1;continue}let d=h+l;if(d<0){r+=`bash: unset: [${l}]: bad array subscript
107
- `,n=1;continue}let m=u[d][0];delete t.state.env[`${a}_${m}`];continue}delete t.state.env[`${a}_${l}`];continue}delete t.state.env[i],t.state.functions.delete(i)}return S("",r,n)}function dr(t,e){return t.fs.resolvePath(t.state.cwd,e)}var Kn=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function at(t){return Kn.includes(t)}async function ct(t,e,s){let r=dr(t,s);switch(e){case"-e":case"-a":return t.fs.exists(r);case"-f":return await t.fs.exists(r)?(await t.fs.stat(r)).isFile:!1;case"-d":return await t.fs.exists(r)?(await t.fs.stat(r)).isDirectory:!1;case"-r":case"-w":case"-x":return t.fs.exists(r);case"-s":return await t.fs.exists(r)?(await t.fs.stat(r)).size>0:!1;case"-L":case"-h":try{return(await t.fs.lstat(r)).isSymbolicLink}catch{return!1}case"-k":return await t.fs.exists(r)?((await t.fs.stat(r)).mode&512)!==0:!1;case"-g":return await t.fs.exists(r)?((await t.fs.stat(r)).mode&1024)!==0:!1;case"-u":return await t.fs.exists(r)?((await t.fs.stat(r)).mode&2048)!==0:!1;case"-G":case"-O":return t.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"].some(i=>r===i||r.endsWith(i));case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return t.fs.exists(r);default:return!1}}var Xn=["-nt","-ot","-ef"];function lt(t){return Xn.includes(t)}async function ut(t,e,s,r){let n=dr(t,s),i=dr(t,r);switch(e){case"-nt":try{let o=await t.fs.stat(n),a=await t.fs.stat(i);return o.mtime>a.mtime}catch{return!1}case"-ot":try{let o=await t.fs.stat(n),a=await t.fs.stat(i);return o.mtime<a.mtime}catch{return!1}case"-ef":try{if(!await t.fs.exists(n)||!await t.fs.exists(i))return!1;let o=t.fs.resolvePath(t.state.cwd,n),a=t.fs.resolvePath(t.state.cwd,i);return o===a}catch{return!1}default:return!1}}var Yn=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function ft(t){return Yn.has(t)}function ht(t,e,s){switch(t){case"-eq":return e===s;case"-ne":return e!==s;case"-lt":return e<s;case"-le":return e<=s;case"-gt":return e>s;case"-ge":return e>=s}}function dt(t){return t==="="||t==="=="||t==="!="}function mt(t,e,s,r=!1){let n=r?pt(e,s):e===s;return t==="!="?!n:n}var Jn=new Set(["-z","-n"]);function yt(t){return Jn.has(t)}function wt(t,e){switch(t){case"-z":return e==="";case"-n":return e!==""}}function Et(t,e){let s=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let r=s[1],n=s[2];n=n.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(o,a)=>t.state.env[a]||"");let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else try{let o=Function(`"use strict"; return (${n})`)();i=typeof o=="number"?Math.floor(o):0}catch{let o=t.state.env[n];i=o?Number.parseInt(o,10):0}if(i<0){let o=ze(t,r);if(o.length===0||(i=Math.max(...o)+1+i,i<0))return!1}return`${r}_${i}`in t.state.env}return e in t.state.env}async function pe(t,e){switch(e.type){case"CondBinary":{let s=await k(t,e.left),r=await k(t,e.right),n=e.right.parts.length>0&&e.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped");if(dt(e.operator))return mt(e.operator,s,r,!n);if(ft(e.operator))return ht(e.operator,Is(t,s),Is(t,r));if(lt(e.operator))return ut(t,e.operator,s,r);switch(e.operator){case"=~":try{let i=new RegExp(r),o=s.match(i);if(o){t.state.env.BASH_REMATCH=o[0];for(let a=1;a<o.length;a++)t.state.env[`BASH_REMATCH_${a}`]=o[a]||""}return o!==null}catch{throw new Error("syntax error in regular expression")}case"<":return s<r;case">":return s>r;default:return!1}}case"CondUnary":{let s=await k(t,e.operand);return at(e.operator)?ct(t,e.operator,s):yt(e.operator)?wt(e.operator,s):e.operator==="-v"?Et(t,s):e.operator==="-o"?pr(t,s):!1}case"CondNot":return!await pe(t,e.operand);case"CondAnd":return await pe(t,e.left)?await pe(t,e.right):!1;case"CondOr":return await pe(t,e.left)?!0:await pe(t,e.right);case"CondGroup":return await pe(t,e.expression);case"CondWord":return await k(t,e.word)!=="";default:return!1}}async function Re(t,e){if(e.length===0)return S("","",1);if(e.length===1)return _(!!e[0]);if(e.length===2){let r=e[0],n=e[1];return r==="("?x(`test: '(' without matching ')'
108
- `,2):at(r)?_(await ct(t,r,n)):yt(r)?_(wt(r,n)):r==="!"?_(!n):r==="-v"?_(Et(t,n)):r==="-o"?_(pr(t,n)):r==="="||r==="=="||r==="!="||r==="<"||r===">"||r==="-eq"||r==="-ne"||r==="-lt"||r==="-le"||r==="-gt"||r==="-ge"||r==="-nt"||r==="-ot"||r==="-ef"?x(`test: ${r}: unary operator expected
109
- `,2):S("","",1)}if(e.length===3){let r=e[0],n=e[1],i=e[2];if(dt(n))return _(mt(n,r,i));if(ft(n)){let o=gt(r),a=gt(i);return!o.valid||!a.valid?S("","",2):_(ht(n,o.value,a.value))}if(lt(n))return _(await ut(t,n,r,i));switch(n){case"-a":return _(r!==""&&i!=="");case"-o":return _(r!==""||i!=="");case">":return _(r>i);case"<":return _(r<i)}if(r==="!"){let o=await Re(t,[n,i]);return S("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(r==="("&&i===")")return _(n!=="")}if(e.length===4){if(e[0]==="!"){let r=await Re(t,e.slice(1));return S("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(e[0]==="("&&e[3]===")")return Re(t,[e[1],e[2]])}let s=await Ds(t,e,0);return s.pos<e.length?x(`test: too many arguments
110
- `,2):_(s.value)}async function Ds(t,e,s){return ei(t,e,s)}async function ei(t,e,s){let{value:r,pos:n}=await ks(t,e,s);for(;e[n]==="-o";){let i=await ks(t,e,n+1);r=r||i.value,n=i.pos}return{value:r,pos:n}}async function ks(t,e,s){let{value:r,pos:n}=await mr(t,e,s);for(;e[n]==="-a";){let i=await mr(t,e,n+1);r=r&&i.value,n=i.pos}return{value:r,pos:n}}async function mr(t,e,s){if(e[s]==="!"){let{value:r,pos:n}=await mr(t,e,s+1);return{value:!r,pos:n}}return ti(t,e,s)}async function ti(t,e,s){let r=e[s];if(r==="("){let{value:i,pos:o}=await Ds(t,e,s+1);return{value:i,pos:e[o]===")"?o+1:o}}if(at(r)){let i=e[s+1]??"";return{value:await ct(t,r,i),pos:s+2}}if(yt(r)){let i=e[s+1]??"";return{value:wt(r,i),pos:s+2}}if(r==="-v"){let i=e[s+1]??"";return{value:Et(t,i),pos:s+2}}if(r==="-o"){let i=e[s+1]??"";return{value:pr(t,i),pos:s+2}}let n=e[s+1];if(dt(n)){let i=r,o=e[s+2]??"";return{value:mt(n,i,o),pos:s+3}}if(ft(n)){let i=gt(r),o=gt(e[s+2]??"0");return!i.valid||!o.valid?{value:!1,pos:s+3}:{value:ht(n,i.value,o.value),pos:s+3}}if(lt(n)){let i=r,o=e[s+2]??"";return{value:await ut(t,n,i,o),pos:s+3}}return{value:r!==void 0&&r!=="",pos:s+1}}function pt(t,e){let s="^";for(let r=0;r<e.length;r++){let n=e[r];if(n==="\\")if(r+1<e.length){let i=e[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,r++}else s+="\\\\";else if(n==="*")s+=".*";else if(n==="?")s+=".";else if(n==="["){let i=e.indexOf("]",r+1);i!==-1?(s+=e.slice(r,i+1),r=i):s+="\\["}else/[\\^$.|+(){}]/.test(n)?s+=`\\${n}`:s+=n}return s+="$",new RegExp(s).test(t)}function pr(t,e){let r={errexit:()=>t.state.options.errexit===!0,nounset:()=>t.state.options.nounset===!0,pipefail:()=>t.state.options.pipefail===!0,xtrace:()=>t.state.options.xtrace===!0,e:()=>t.state.options.errexit===!0,u:()=>t.state.options.nounset===!0,x:()=>t.state.options.xtrace===!0}[e];return r?r():!1}function Is(t,e){if(e=e.trim(),e==="")return 0;if(/^[+-]?(\d+#[a-zA-Z0-9@_]+|0[xX][0-9a-fA-F]+|0[0-7]+|\d+)$/.test(e))return Rs(e);try{let s=new z,r=T(s,e);return P(t,r.expression)}catch{return Rs(e)}}function ri(t,e){let s=0;for(let r of t){let n;if(r>="0"&&r<="9")n=r.charCodeAt(0)-48;else if(r>="a"&&r<="z")n=r.charCodeAt(0)-97+10;else if(r>="A"&&r<="Z")n=r.charCodeAt(0)-65+36;else if(r==="@")n=62;else if(r==="_")n=63;else return Number.NaN;if(n>=e)return Number.NaN;s=s*e+n}return s}function Rs(t){if(t=t.trim(),t==="")return 0;let e=!1;t.startsWith("-")?(e=!0,t=t.slice(1)):t.startsWith("+")&&(t=t.slice(1));let s,r=t.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(r){let n=Number.parseInt(r[1],10);n>=2&&n<=64?s=ri(r[2],n):s=0}else/^0[xX][0-9a-fA-F]+$/.test(t)?s=Number.parseInt(t,16):/^0[0-7]+$/.test(t)?s=Number.parseInt(t,8):s=Number.parseInt(t,10);return Number.isNaN(s)&&(s=0),e?-s:s}function gt(t){if(t=t.trim(),t==="")return{value:0,valid:!0};let e=!1;if(t.startsWith("-")?(e=!0,t=t.slice(1)):t.startsWith("+")&&(t=t.slice(1)),!/^\d+$/.test(t))return{value:0,valid:!1};let s=Number.parseInt(t,10);return Number.isNaN(s)?{value:0,valid:!1}:{value:e?-s:s,valid:!0}}async function yr(t,e){let s=t.state.inCondition;t.state.inCondition=!0;let r="",n="",i=0;try{for(let o of e){let a=await t.executeStatement(o);r+=a.stdout,n+=a.stderr,i=a.exitCode}}finally{t.state.inCondition=s}return{stdout:r,stderr:n,exitCode:i}}function Ve(t,e,s,r){if(t instanceof U)return e+=t.stdout,s+=t.stderr,t.levels>1&&r>1?(t.levels--,t.stdout=e,t.stderr=s,{action:"rethrow",stdout:e,stderr:s,error:t}):{action:"break",stdout:e,stderr:s};if(t instanceof Y)return e+=t.stdout,s+=t.stderr,t.levels>1&&r>1?(t.levels--,t.stdout=e,t.stderr=s,{action:"rethrow",stdout:e,stderr:s,error:t}):{action:"continue",stdout:e,stderr:s};if(t instanceof G||t instanceof te||t instanceof R||t instanceof B)return t.prependOutput(e,s),{action:"rethrow",stdout:e,stderr:s,error:t};let n=le(t);return{action:"error",stdout:e,stderr:`${s}${n}
111
- `,exitCode:1}}async function At(t,e,s="",r=""){let n=s,i=r,o=0;try{for(let a of e){let c=await t.executeStatement(a);n+=c.stdout,i+=c.stderr,o=c.exitCode}}catch(a){if(qe(a)||a instanceof te||a instanceof R||a instanceof B||a instanceof ue)throw a.prependOutput(n,i),a;return{stdout:n,stderr:`${i}${le(a)}
112
- `,exitCode:1}}return{stdout:n,stderr:i,exitCode:o}}async function Os(t,e){let s="",r="";for(let n of e.clauses){let i=await yr(t,n.condition);if(s+=i.stdout,r+=i.stderr,i.exitCode===0)return At(t,n.body,s,r)}return e.elseBody?At(t,e.elseBody,s,r):S(s,r,0)}async function _s(t,e){let s="",r="",n=0,i=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e.variable))return x(`bash: \`${e.variable}': not a valid identifier
113
- `);let o=[];if(e.words===null)o=(t.state.env["@"]||"").split(" ").filter(Boolean);else if(e.words.length===0)o=[];else for(let a of e.words){let c=await Ge(t,a);o.push(...c.values)}t.state.loopDepth++;try{for(let a of o){i++,i>t.limits.maxLoopIterations&&ce(`for loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,r),t.state.env[e.variable]=a;try{for(let c of e.body){let l=await t.executeStatement(c);s+=l.stdout,r+=l.stderr,n=l.exitCode}}catch(c){let l=Ve(c,s,r,t.state.loopDepth);if(s=l.stdout,r=l.stderr,l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return S(s,r,l.exitCode??1);throw l.error}}}finally{t.state.loopDepth--}return S(s,r,n)}async function Ls(t,e){let s="",r="",n=0,i=0;e.init&&await v(t,e.init.expression),t.state.loopDepth++;try{for(;i++,i>t.limits.maxLoopIterations&&ce(`for loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,r),!(e.condition&&await v(t,e.condition.expression)===0);){try{for(let o of e.body){let a=await t.executeStatement(o);s+=a.stdout,r+=a.stderr,n=a.exitCode}}catch(o){let a=Ve(o,s,r,t.state.loopDepth);if(s=a.stdout,r=a.stderr,a.action==="break")break;if(a.action==="continue"){e.update&&await v(t,e.update.expression);continue}if(a.action==="error")return S(s,r,a.exitCode??1);throw a.error}e.update&&await v(t,e.update.expression)}}finally{t.state.loopDepth--}return S(s,r,n)}async function Ts(t,e,s=""){let r="",n="",i=0,o=0,a=s;for(let l of e.redirections)if((l.operator==="<<"||l.operator==="<<-")&&l.target.type==="HereDoc"){let u=l.target,h=await k(t,u.content);u.stripTabs&&(h=h.split(`
575
+ `:"",stderr:f}}async function sr(e,t,s){if(t.includes("/")){let o=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(o))return{error:"not_found",path:o};let a=o.split("/").pop()||t,l=e.commands.get(a);try{let c=await e.fs.stat(o);return c.isDirectory?{error:"permission_denied",path:o}:l?{cmd:l,path:o}:(c.mode&73)!==0?{script:!0,path:o}:{error:"permission_denied",path:o}}catch{return{error:"not_found",path:o}}}if(!s&&e.state.hashTable){let o=e.state.hashTable.get(t);if(o)if(await e.fs.exists(o)){let a=e.commands.get(t);if(a)return{cmd:a,path:o};try{let l=await e.fs.stat(o);if(!l.isDirectory&&(l.mode&73)!==0)return{script:!0,path:o}}catch{}}else e.state.hashTable.delete(t)}let r=(s??e.state.env.PATH??"/usr/bin:/bin").split(":");for(let o of r){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 f=(c.mode&73)!==0,u=e.commands.get(t),d=o==="/bin"||o==="/usr/bin";if(u&&d)return{cmd:u,path:l};if(f){if(u&&!d)return{script:!0,path:l};if(!u)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 Dt(e,t){let s=[];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&&s.push(t)}catch{}return s}let r=(e.state.env.PATH||"/usr/bin:/bin").split(":");for(let i of r){if(!i)continue;let a=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?a:`${i}/${t}`)}}return s}async function or(e,t,s,n){let r=!1,i=!1,o=!1,a=!1,l=!1,c=[];for(let p of t)if(p.startsWith("-")&&p.length>1)for(let w of p.slice(1))w==="t"?r=!0:w==="p"?i=!0:w==="P"?o=!0:w==="a"?a=!0:w==="f"&&(l=!0);else c.push(p);let f="",u="",d=0,h=!1,m=!1;for(let p of c){let w=!1;if(o){if(a){let v=await n(p);if(v.length>0){for(let _ of v)f+=`${_}
576
+ `;h=!0,w=!0}}else{let v=await s(p);v&&(f+=`${v}
577
+ `,h=!0,w=!0)}w||(m=!0);continue}let b=!l&&e.state.functions.has(p);if(a&&b){if(!i)if(r)f+=`function
578
+ `;else{let v=e.state.functions.get(p),_=v?nr(p,v):`${p} is a function
579
+ `;f+=_}w=!0}let $=e.state.env[`BASH_ALIAS_${p}`];if($!==void 0&&(a||!w)&&(i||(r?f+=`alias
580
+ `:f+=`${p} is aliased to \`${$}'
581
+ `),w=!0,!a)||Jt.has(p)&&(a||!w)&&(i||(r?f+=`keyword
582
+ `:f+=`${p} is a shell keyword
583
+ `),w=!0,!a))continue;if(!a&&b&&!w){if(!i)if(r)f+=`function
584
+ `;else{let v=e.state.functions.get(p),_=v?nr(p,v):`${p} is a function
585
+ `;f+=_}w=!0;continue}if(!(Xe.has(p)&&(a||!w)&&(i||(r?f+=`builtin
586
+ `:f+=`${p} is a shell builtin
587
+ `),w=!0,!a))){if(a){let v=await n(p);for(let _ of v)i?f+=`${_}
588
+ `:r?f+=`file
589
+ `:f+=`${p} is ${_}
590
+ `,h=!0,w=!0}else if(!w){let v=await s(p);v&&(i?f+=`${v}
591
+ `:r?f+=`file
592
+ `:f+=`${p} is ${v}
593
+ `,h=!0,w=!0)}if(!w&&(m=!0,!r&&!i)){let v=!0;if(p.includes("/")){let _=e.fs.resolvePath(e.state.cwd,p);await e.fs.exists(_)&&(v=!1)}v&&(u+=`bash: type: ${p}: not found
594
+ `)}}}return i?d=m&&!h?1:0:d=m?1:0,P(f,u,d)}function nr(e,t){let s;return t.body.type==="Group"?s=t.body.body.map(r=>Qe(r)).join("; "):s=Qe(t.body),`${e} is a function
595
+ ${e} ()
596
+ {
597
+ ${s}
598
+ }
599
+ `}function Qe(e){if(Array.isArray(e))return e.map(t=>Qe(t)).join("; ");if(e.type==="Statement"){let t=[];for(let s=0;s<e.pipelines.length;s++){let n=e.pipelines[s];t.push(Ui(n)),e.operators[s]&&t.push(e.operators[s])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,s=[];t.name&&s.push(rr(t.name));for(let n of t.args)s.push(rr(n));return s.join(" ")}return e.type==="Group"?`{ ${e.body.map(n=>Qe(n)).join("; ")}; }`:"..."}function Ui(e){let t=e.commands.map(s=>Qe(s));return(e.negated?"! ":"")+t.join(" | ")}function rr(e){let t="";for(let s of e.parts)s.type==="Literal"?t+=s.value:s.type==="DoubleQuoted"?t+=`"${s.parts.map(n=>ir(n)).join("")}"`:s.type==="SingleQuoted"?t+=`'${s.value}'`:t+=ir(s);return t}function ir(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function ar(e,t,s,n){let r="",i="",o=0;for(let a of t){if(!a){o=1;continue}let l=e.state.env[`BASH_ALIAS_${a}`];if(l!==void 0)n?r+=`${a} is an alias for "${l}"
600
+ `:r+=`alias ${a}='${l}'
601
+ `;else if(Jt.has(a))n?r+=`${a} is a shell keyword
602
+ `:r+=`${a}
603
+ `;else if(Xe.has(a))n?r+=`${a} is a shell builtin
604
+ `:r+=`${a}
605
+ `;else if(e.state.functions.has(a))n?r+=`${a} is a function
606
+ `:r+=`${a}
607
+ `;else if(a.includes("/")){let c=e.fs.resolvePath(e.state.cwd,a),f=!1;if(await e.fs.exists(c))try{let u=await e.fs.stat(c);u.isDirectory||(u.mode&73)!==0&&(n?r+=`${a} is ${a}
608
+ `:r+=`${a}
609
+ `,f=!0)}catch{}f||(n&&(i+=`${a}: not found
610
+ `),o=1)}else if(e.commands.has(a)){let f=(e.state.env.PATH??"/usr/bin:/bin").split(":"),u=null;for(let d of f){if(!d)continue;let h=`${d}/${a}`;try{let m=await e.fs.stat(h);if(!m.isDirectory&&(m.mode&73)!==0){u=h;break}}catch{}}u||(u=`/usr/bin/${a}`),n?r+=`${a} is ${u}
611
+ `:r+=`${u}
612
+ `}else n&&(i+=`${a}: not found
613
+ `),o=1}return P(r,i,o)}async function lr(e,t){if(t.includes("/")){let r=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(r)){try{let i=await e.fs.stat(r);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let n=(e.state.env.PATH??"/usr/bin:/bin").split(":");for(let r of n){if(!r)continue;let o=`${r.startsWith("/")?r:e.fs.resolvePath(e.state.cwd,r)}/${t}`;if(await e.fs.exists(o)){try{if((await e.fs.stat(o)).isDirectory)continue}catch{continue}return`${r}/${t}`}}if(e.commands.has(t)){for(let r of n)if(r==="/usr/bin"||r==="/bin")return`${r}/${t}`;return`/usr/bin/${t}`}return null}async function cr(e,t,s,n,r,i,o,a){let{ctx:l,runCommand:c}=e;if(t==="export")return Es(l,s);if(t==="unset")return Rs(l,s);if(t==="exit")return bs(l,s);if(t==="local")return Ps(l,s);if(t==="set")return Os(l,s);if(t==="break")return Zt(l,s);if(t==="continue")return os(l,s);if(t==="return")return Cs(l,s);if(t==="eval"&&l.state.options.posix)return Nt(l,s,r);if(t==="shift")return Ds(l,s);if(t==="getopts")return Ct(l,s);if(t==="compgen")return ss(l,s);if(t==="complete")return rs(l,s);if(t==="compopt")return is(l,s);if(t==="pushd")return await ws(l,s);if(t==="popd")return gs(l,s);if(t==="dirs")return vs(l,s);if(t==="source"||t===".")return Ts(l,s);if(t==="read")return Ns(l,s,r,a);if(t==="mapfile"||t==="readarray")return _s(l,s,r);if(t==="declare"||t==="typeset")return ps(l,s);if(t==="readonly")return ms(l,s);if(!i){let f=l.state.functions.get(t);if(f)return Pt(l,f,s,r)}if(t==="eval")return Nt(l,s,r);if(t==="cd")return await Gt(l,s);if(t===":"||t==="true")return L;if(t==="false")return q(!1);if(t==="let")return As(l,s);if(t==="command")return qi(e,s,r);if(t==="builtin")return Zi(e,s,r);if(t==="shopt")return tr(l,s);if(t==="exec"){if(s.length===0)return L;let[f,...u]=s;return c(f,u,[],r,!1,!1,-1)}if(t==="wait")return L;if(t==="type")return await or(l,s,f=>lr(l,f),f=>Dt(l,f));if(t==="hash")return $s(l,s);if(t==="help")return Ss(l,s);if(t==="["||t==="test"){let f=s;if(t==="["){if(s[s.length-1]!=="]")return S("[: missing `]'\n",2);f=s.slice(0,-1)}return Ge(l,f)}return null}async function qi(e,t,s){let{ctx:n,runCommand:r}=e;if(t.length===0)return L;let i=!1,o=!1,a=!1,l=t;for(;l.length>0&&l[0].startsWith("-");){let u=l[0];if(u==="--"){l=l.slice(1);break}for(let d of u.slice(1))d==="p"?i=!0:d==="V"?o=!0:d==="v"&&(a=!0);l=l.slice(1)}if(l.length===0)return L;if(a||o)return await ar(n,l,a,o);let[c,...f]=l;return r(c,f,[],s,!0,i,-1)}async function Zi(e,t,s){let{runCommand:n}=e;if(t.length===0)return L;let r=t;if(r[0]==="--"&&(r=r.slice(1),r.length===0))return L;let i=r[0];if(!Xe.has(i))return S(`bash: builtin: ${i}: not a shell builtin
614
+ `);let[,...o]=r;return n(i,o,[],s,!0,!1,-1)}async function fr(e,t,s,n,r){let{ctx:i,buildExportedEnv:o,executeUserScript:a}=e,c=await sr(i,t,r?"/usr/bin:/bin":void 0);if(!c)return gn(t)?S(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
615
+ `,127):S(`bash: ${t}: command not found
616
+ `,127);if("error"in c)return c.error==="permission_denied"?S(`bash: ${t}: Permission denied
617
+ `,126):S(`bash: ${t}: No such file or directory
618
+ `,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,s,n);let{cmd:f,path:u}=c;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u));let d=n||i.state.groupStdin||"",h=o(),m={fs:i.fs,cwd:i.state.cwd,env:i.state.env,exportedEnv:h,stdin:d,limits:i.limits,exec:i.execFn,fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo};try{return await f.execute(s,m)}catch(p){return S(`${t}: ${ge(p)}
619
+ `)}}async function Ls(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let n="",r="",i=0;try{for(let o of t){let a=await e.executeStatement(o);n+=a.stdout,r+=a.stderr,i=a.exitCode}}finally{e.state.inCondition=s}return{stdout:n,stderr:r,exitCode:i}}function Je(e,t,s,n){if(e instanceof re)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"break",stdout:t,stderr:s};if(e instanceof ie)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"continue",stdout:t,stderr:s};if(e instanceof se||e instanceof oe||e instanceof z||e instanceof te)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let r=ge(e);return{action:"error",stdout:t,stderr:`${s}${r}
620
+ `,exitCode:1}}async function Tt(e,t,s="",n=""){let r=s,i=n,o=0;try{for(let a of t){let l=await e.executeStatement(a);r+=l.stdout,i+=l.stderr,o=l.exitCode}}catch(a){if(rt(a)||a instanceof oe||a instanceof z||a instanceof te||a instanceof Se)throw a.prependOutput(r,i),a;return{stdout:r,stderr:`${i}${ge(a)}
621
+ `,exitCode:1}}return{stdout:r,stderr:i,exitCode:o}}async function ur(e,t){let s="",n="";for(let r of t.clauses){let i=await Ls(e,r.condition);if(s+=i.stdout,n+=i.stderr,i.exitCode===0)return Tt(e,r.body,s,n)}return t.elseBody?Tt(e,t.elseBody,s,n):P(s,n,0)}async function dr(e,t){let s=await ye(e,t.redirections);if(s)return s;let n="",r="",i=0,o=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return S(`bash: \`${t.variable}': not a valid identifier
622
+ `);let a=[];if(t.words===null)a=(e.state.env["@"]||"").split(" ").filter(Boolean);else if(t.words.length===0)a=[];else try{for(let c of t.words){let f=await pe(e,c);a.push(...f.values)}}catch(c){if(c instanceof nt)return{stdout:"",stderr:c.stderr,exitCode:1};throw c}e.state.loopDepth++;try{for(let c of a){o++,o>e.limits.maxLoopIterations&&$e(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),e.state.env[t.variable]=c;try{for(let f of t.body){let u=await e.executeStatement(f);n+=u.stdout,r+=u.stderr,i=u.exitCode}}catch(f){let u=Je(f,n,r,e.state.loopDepth);if(n=u.stdout,r=u.stderr,u.action==="break")break;if(u.action==="continue")continue;if(u.action==="error"){let d=P(n,r,u.exitCode??1);return j(e,d,t.redirections)}throw u.error}}}finally{e.state.loopDepth--}let l=P(n,r,i);return j(e,l,t.redirections)}async function hr(e,t){let s=await ye(e,t.redirections);if(s)return s;let n=t.line;n!==void 0&&(e.state.currentLine=n);let r="",i="",o=0,a=0;t.init&&await V(e,t.init.expression),e.state.loopDepth++;try{for(;a++,a>e.limits.maxLoopIterations&&$e(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,i),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await V(e,t.condition.expression)===0));){try{for(let c of t.body){let f=await e.executeStatement(c);r+=f.stdout,i+=f.stderr,o=f.exitCode}}catch(c){let f=Je(c,r,i,e.state.loopDepth);if(r=f.stdout,i=f.stderr,f.action==="break")break;if(f.action==="continue"){t.update&&await V(e,t.update.expression);continue}if(f.action==="error"){let u=P(r,i,f.exitCode??1);return j(e,u,t.redirections)}throw f.error}t.update&&await V(e,t.update.expression)}}finally{e.state.loopDepth--}let l=P(r,i,o);return j(e,l,t.redirections)}async function pr(e,t,s=""){let n="",r="",i=0,o=0,a=s;for(let c of t.redirections)if((c.operator==="<<"||c.operator==="<<-")&&c.target.type==="HereDoc"){let f=c.target,u=await T(e,f.content);f.stripTabs&&(u=u.split(`
114
623
  `).map(d=>d.replace(/^\t+/,"")).join(`
115
- `)),a=h}else if(l.operator==="<<<"&&l.target.type==="Word")a=`${await k(t,l.target)}
116
- `;else if(l.operator==="<"&&l.target.type==="Word")try{let u=await k(t,l.target),h=t.fs.resolvePath(t.state.cwd,u);a=await t.fs.readFile(h)}catch{let u=await k(t,l.target);return x(`bash: ${u}: No such file or directory
117
- `)}let c=t.state.groupStdin;a&&(t.state.groupStdin=a),t.state.loopDepth++;try{for(;;){o++,o>t.limits.maxLoopIterations&&ce(`while loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n);let l=0,u=!1,h=!1,d=t.state.inCondition;t.state.inCondition=!0;try{for(let m of e.condition){let y=await t.executeStatement(m);r+=y.stdout,n+=y.stderr,l=y.exitCode}}catch(m){if(m instanceof U){if(r+=m.stdout,n+=m.stderr,m.levels>1&&t.state.loopDepth>1)throw m.levels--,m.stdout=r,m.stderr=n,t.state.inCondition=d,m;u=!0}else if(m instanceof Y){if(r+=m.stdout,n+=m.stderr,m.levels>1&&t.state.loopDepth>1)throw m.levels--,m.stdout=r,m.stderr=n,t.state.inCondition=d,m;h=!0}else throw t.state.inCondition=d,m}finally{t.state.inCondition=d}if(u)break;if(!h){if(l!==0)break;try{for(let m of e.body){let y=await t.executeStatement(m);r+=y.stdout,n+=y.stderr,i=y.exitCode}}catch(m){let y=Ve(m,r,n,t.state.loopDepth);if(r=y.stdout,n=y.stderr,y.action==="break")break;if(y.action==="continue")continue;if(y.action==="error")return S(r,n,y.exitCode??1);throw y.error}}}}finally{t.state.loopDepth--,t.state.groupStdin=c}return S(r,n,i)}async function Fs(t,e){let s="",r="",n=0,i=0;t.state.loopDepth++;try{for(;;){i++,i>t.limits.maxLoopIterations&&ce(`until loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,r);let o=await yr(t,e.condition);if(s+=o.stdout,r+=o.stderr,o.exitCode===0)break;try{for(let a of e.body){let c=await t.executeStatement(a);s+=c.stdout,r+=c.stderr,n=c.exitCode}}catch(a){let c=Ve(a,s,r,t.state.loopDepth);if(s=c.stdout,r=c.stderr,c.action==="break")break;if(c.action==="continue")continue;if(c.action==="error")return S(s,r,c.exitCode??1);throw c.error}}}finally{t.state.loopDepth--}return S(s,r,n)}async function Ws(t,e){let s="",r="",n=0,i=await k(t,e.word),o=!1;for(let a=0;a<e.items.length;a++){let c=e.items[a],l=o;if(!o)for(let u of c.patterns){let h=await k(t,u);if(fs(u)&&(h=hs(h)),pt(i,h)){l=!0;break}}if(l){let u=await At(t,c.body,s,r);if(s=u.stdout,r=u.stderr,n=u.exitCode,c.terminator===";;")break;c.terminator===";&"?o=!0:o=!1}else o=!1}return S(s,r,n)}function Ms(t,e){return t.state.functions.set(e.name,e),N}async function zs(t,e,s){t.state.callDepth++,t.state.callDepth>t.limits.maxCallDepth&&(t.state.callDepth--,ce(`${e.name}: maximum recursion depth (${t.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),t.state.localScopes.push(new Map);let r={};for(let i=0;i<s.length;i++)r[String(i+1)]=t.state.env[String(i+1)],t.state.env[String(i+1)]=s[i];r["@"]=t.state.env["@"],r["#"]=t.state.env["#"],t.state.env["@"]=s.join(" "),t.state.env["#"]=String(s.length);let n=()=>{let i=t.state.localScopes.pop();if(i)for(let[o,a]of i)a===void 0?delete t.state.env[o]:t.state.env[o]=a;for(let[o,a]of Object.entries(r))a===void 0?delete t.state.env[o]:t.state.env[o]=a;t.state.callDepth--};try{let i=await t.executeCommand(e.body,"");return n(),i}catch(i){if(n(),i instanceof G)return S(i.stdout,i.stderr,i.exitCode);throw i}}async function Bs(t,e,s){let{stdout:r,stderr:n,exitCode:i}=e;for(let o of s){if(o.target.type==="HereDoc")continue;let a=await k(t,o.target);switch(o.operator){case">":{let c=o.fd??1;if(c===1){let l=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(l)).isDirectory){n+=`bash: ${a}: Is a directory
118
- `,i=1,r="";break}}catch{}await t.fs.writeFile(l,r,"binary"),r=""}else if(c===2)if(a==="/dev/null")n="";else{let l=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(l)).isDirectory){n+=`bash: ${a}: Is a directory
119
- `,i=1;break}}catch{}await t.fs.writeFile(l,n,"binary"),n=""}break}case">>":{let c=o.fd??1;if(c===1){let l=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(l)).isDirectory){n+=`bash: ${a}: Is a directory
120
- `,i=1,r="";break}}catch{}await t.fs.appendFile(l,r,"binary"),r=""}else if(c===2){let l=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(l)).isDirectory){n+=`bash: ${a}: Is a directory
121
- `,i=1;break}}catch{}await t.fs.appendFile(l,n,"binary"),n=""}break}case">&":{let c=o.fd??1;a==="2"||a==="&2"?c===1&&(n+=r,r=""):(a==="1"||a==="&1")&&(r+=n,n="");break}case"&>":{let c=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(c)).isDirectory){n=`bash: ${a}: Is a directory
122
- `,i=1,r="";break}}catch{}await t.fs.writeFile(c,r+n,"binary"),r="",n="";break}case"&>>":{let c=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(c)).isDirectory){n=`bash: ${a}: Is a directory
123
- `,i=1,r="";break}}catch{}await t.fs.appendFile(c,r+n,"binary"),r="",n="";break}}}return S(r,n,i)}var He=class{ctx;constructor(e,s){this.ctx={state:s,fs:e.fs,commands:e.commands,limits:e.limits,execFn:e.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:e.fetch,sleep:e.sleep,trace:e.trace}}async executeScript(e){let s="",r="",n=0;for(let i of e.statements)try{let o=await this.executeStatement(i);s+=o.stdout,r+=o.stderr,n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env["?"]=String(n)}catch(o){if(o instanceof R)throw o.prependOutput(s,r),o;if(o instanceof B)throw o;if(o instanceof te)return s+=o.stdout,r+=o.stderr,n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env["?"]=String(n),{stdout:s,stderr:r,exitCode:n,env:{...this.ctx.state.env}};if(o instanceof J)return s+=o.stdout,r+=o.stderr,n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env["?"]=String(n),{stdout:s,stderr:r,exitCode:n,env:{...this.ctx.state.env}};if(o instanceof Ee)return s+=o.stdout,r+=o.stderr,n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env["?"]=String(n),{stdout:s,stderr:r,exitCode:n,env:{...this.ctx.state.env}};if(o instanceof U||o instanceof Y){if(this.ctx.state.loopDepth>0)throw o.prependOutput(s,r),o;s+=o.stdout,r+=o.stderr;continue}throw o instanceof G&&o.prependOutput(s,r),o}return{stdout:s,stderr:r,exitCode:n,env:{...this.ctx.state.env}}}async executeStatement(e){this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&ce(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands");let s="",r="",n=0,i=-1,o=!1;for(let a=0;a<e.pipelines.length;a++){let c=e.pipelines[a],l=a>0?e.operators[a-1]:null;if(l==="&&"&&n!==0||l==="||"&&n===0)continue;let u=await this.executePipeline(c);s+=u.stdout,r+=u.stderr,n=u.exitCode,i=a,o=c.negated,this.ctx.state.lastExitCode=n,this.ctx.state.env["?"]=String(n)}if(this.ctx.state.options.errexit&&n!==0&&i===e.pipelines.length-1&&!o&&!this.ctx.state.inCondition)throw new te(n,s,r);return S(s,r,n)}async executePipeline(e){let s="",r=N,n=0,i=[];for(let o=0;o<e.commands.length;o++){let a=e.commands[o],c=o===e.commands.length-1,l;try{l=await this.executeCommand(a,s)}catch(u){if(u instanceof Ee)l={stdout:u.stdout,stderr:u.stderr,exitCode:1};else if(u instanceof R&&e.commands.length>1)l={stdout:u.stdout,stderr:u.stderr,exitCode:u.exitCode};else throw u}i.push(l.exitCode),l.exitCode!==0&&(n=l.exitCode),c?r=l:(s=l.stdout,r={stdout:"",stderr:l.stderr,exitCode:l.exitCode})}for(let o of Object.keys(this.ctx.state.env))o.startsWith("PIPESTATUS_")&&delete this.ctx.state.env[o];for(let o=0;o<i.length;o++)this.ctx.state.env[`PIPESTATUS_${o}`]=String(i[o]);return this.ctx.state.env.PIPESTATUS__length=String(i.length),this.ctx.state.options.pipefail&&n!==0&&(r={...r,exitCode:n}),e.negated&&(r={...r,exitCode:r.exitCode===0?1:0}),r}async executeCommand(e,s){switch(e.type){case"SimpleCommand":return this.executeSimpleCommand(e,s);case"If":return Os(this.ctx,e);case"For":return _s(this.ctx,e);case"CStyleFor":return Ls(this.ctx,e);case"While":return Ts(this.ctx,e,s);case"Until":return Fs(this.ctx,e);case"Case":return Ws(this.ctx,e);case"Subshell":return this.executeSubshell(e,s);case"Group":return this.executeGroup(e,s);case"FunctionDef":return Ms(this.ctx,e);case"ArithmeticCommand":return this.executeArithmeticCommand(e);case"ConditionalCommand":return this.executeConditionalCommand(e);default:return N}}async executeSimpleCommand(e,s){try{return await this.executeSimpleCommandInner(e,s)}catch(r){if(r instanceof W)return x(r.stderr);throw r}}async executeSimpleCommandInner(e,s){e.line!==void 0&&(this.ctx.state.currentLine=e.line),this.ctx.state.expansionStderr="";let r={};for(let c of e.assignments){let l=c.name;if(c.array){if(/\[.+\]$/.test(l))return S("",`bash: ${l}: cannot assign list to array member
124
- `,1);let E=me(this.ctx,l);if(E)return E;let p=[];for(let g of c.array){let b=await Ge(this.ctx,g);p.push(...b.values)}let w=0;if(c.append){let g=F(this.ctx,l);g.length>0&&(w=Math.max(...g.map(([C])=>typeof C=="number"?C:0))+1)}else{let g=`${l}_`;for(let b of Object.keys(this.ctx.state.env))b.startsWith(g)&&!b.includes("__")&&delete this.ctx.state.env[b]}for(let g=0;g<p.length;g++)this.ctx.state.env[`${l}_${w+g}`]=p[g];c.append||(this.ctx.state.env[`${l}__length`]=String(p.length));continue}let u=c.value?await k(this.ctx,c.value):"";if(l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return S("",`bash: ${l}: bad array subscript
125
- `,1);let d=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(d){let E=d[1],p=d[2],w=me(this.ctx,E);if(w)return w;let g=this.ctx.state.associativeArrays?.has(E),b;if(g){let I;if(p.startsWith("'")&&p.endsWith("'"))I=p.slice(1,-1);else if(p.startsWith('"')&&p.endsWith('"')){let D=p.slice(1,-1),L=new z().parseWordFromString(D,!0,!1);I=await k(this.ctx,L)}else if(p.includes("$")){let we=new z().parseWordFromString(p,!1,!1);I=await k(this.ctx,we)}else I=p;b=`${E}_${I}`}else{let I;if(/^-?\d+$/.test(p))I=Number.parseInt(p,10);else{try{let D=new z,we=T(D,p);I=P(this.ctx,we.expression)}catch{let D=this.ctx.state.env[p];I=D?Number.parseInt(D,10):0}Number.isNaN(I)&&(I=0)}if(I<0){let D=F(this.ctx,E);if(D.length===0)return S("",`bash: ${E}[${p}]: bad array subscript
126
- `,1);if(I=Math.max(...D.map(([L])=>typeof L=="number"?L:0))+1+I,I<0)return S("",`bash: ${E}[${p}]: bad array subscript
127
- `,1)}b=`${E}_${I}`}let C=c.append?(this.ctx.state.env[b]||"")+u:u;e.name?(r[b]=this.ctx.state.env[b],this.ctx.state.env[b]=C):this.ctx.state.env[b]=C;continue}let m=me(this.ctx,l);if(m)return m;let y=c.append?(this.ctx.state.env[l]||"")+u:u;e.name?(r[l]=this.ctx.state.env[l],this.ctx.state.env[l]=y):this.ctx.state.env[l]=y}if(!e.name)return S("","",this.ctx.state.lastExitCode);for(let c of e.redirections){if((c.operator==="<<"||c.operator==="<<-")&&c.target.type==="HereDoc"){let l=c.target,u=await k(this.ctx,l.content);l.stripTabs&&(u=u.split(`
128
- `).map(h=>h.replace(/^\t+/,"")).join(`
129
- `)),s=u;continue}if(c.operator==="<<<"&&c.target.type==="Word"){s=`${await k(this.ctx,c.target)}
130
- `;continue}if(c.operator==="<"&&c.target.type==="Word")try{let l=await k(this.ctx,c.target),u=this.ctx.fs.resolvePath(this.ctx.state.cwd,l);s=await this.ctx.fs.readFile(u)}catch{let l=await k(this.ctx,c.target);for(let[u,h]of Object.entries(r))h===void 0?delete this.ctx.state.env[u]:this.ctx.state.env[u]=h;return x(`bash: ${l}: No such file or directory
131
- `)}}let n=await k(this.ctx,e.name),i=[],o=[];for(let c of e.args){let l=await Ge(this.ctx,c);for(let u of l.values)i.push(u),o.push(l.quoted)}if(!n){if(e.name.parts.every(l=>l.type==="CommandSubstitution"||l.type==="ParameterExpansion"||l.type==="ArithmeticExpansion")){if(i.length>0){let l=i.shift();return o.shift(),await this.runCommand(l,i,o,s)}return S("","",this.ctx.state.lastExitCode)}return x(`bash: : command not found
132
- `,127)}let a=await this.runCommand(n,i,o,s);a=await Bs(this.ctx,a,e.redirections),this.ctx.state.lastArg=i.length>0?i[i.length-1]:n;for(let[c,l]of Object.entries(r))l===void 0?delete this.ctx.state.env[c]:this.ctx.state.env[c]=l;return this.ctx.state.expansionStderr&&(a={...a,stderr:this.ctx.state.expansionStderr+a.stderr},this.ctx.state.expansionStderr=""),a}async runCommand(e,s,r,n,i=!1){if(e==="cd")return await Qt(this.ctx,s);if(e==="export")return rr(this.ctx,s);if(e==="unset")return hr(this.ctx,s);if(e==="exit")return tr(this.ctx,s);if(e==="local")return nr(this.ctx,s);if(e==="set")return lr(this.ctx,s);if(e==="break")return Zt(this.ctx,s);if(e==="continue")return Kt(this.ctx,s);if(e==="return")return ar(this.ctx,s);if(e==="eval")return er(this.ctx,s);if(e==="shift")return ur(this.ctx,s);if(e==="source"||e===".")return fr(this.ctx,s);if(e==="read")return or(this.ctx,s,n);if(e==="mapfile"||e==="readarray")return ir(this.ctx,s,n);if(e==="declare"||e==="typeset")return Yt(this.ctx,s);if(e==="readonly")return Jt(this.ctx,s);if(!i){let u=this.ctx.state.functions.get(e);if(u)return zs(this.ctx,u,s)}if(e===":"||e==="true")return N;if(e==="false")return _(!1);if(e==="let")return sr(this.ctx,s);if(e==="command"){if(s.length===0)return N;let u=s;for(;u.length>0&&u[0].startsWith("-");)u=u.slice(1);if(u.length===0)return N;let[h,...d]=u;return this.runCommand(h,d,[],n,!0)}if(e==="builtin"){if(s.length===0)return N;let[u,...h]=s;return this.runCommand(u,h,[],n)}if(e==="shopt")return N;if(e==="exec"){if(s.length===0)return N;let[u,...h]=s;return this.runCommand(u,h,[],n)}if(e==="wait")return N;if(e==="type")return this.handleType(s);if(e==="[["){let u=s.lastIndexOf("]]");if(u!==-1){let h=s.slice(0,u);return Re(this.ctx,h)}return x("bash: [[: missing `]]'\n",2)}if(e==="["||e==="test"){let u=s;if(e==="["){if(s[s.length-1]!=="]")return x("[: missing `]'\n",2);u=s.slice(0,-1)}return Re(this.ctx,u)}let o=await this.resolveCommand(e);if(!o)return Ir(e)?x(`bash: ${e}: command not available in browser environments. Exclude '${e}' from your commands or use the Node.js bundle.
133
- `,127):x(`bash: ${e}: command not found
134
- `,127);let{cmd:a,path:c}=o,l={fs:this.ctx.fs,cwd:this.ctx.state.cwd,env:this.ctx.state.env,stdin:n,limits:this.ctx.limits,exec:this.ctx.execFn,fetch:this.ctx.fetch,getRegisteredCommands:()=>Array.from(this.ctx.commands.keys()),sleep:this.ctx.sleep,trace:this.ctx.trace};try{return await a.execute(s,l)}catch(u){return x(`${e}: ${le(u)}
135
- `)}}async resolveCommand(e){if(e.includes("/")){let i=this.ctx.fs.resolvePath(this.ctx.state.cwd,e);if(!await this.ctx.fs.exists(i))return null;let o=i.split("/").pop()||e,a=this.ctx.commands.get(o);return a?{cmd:a,path:i}:null}let r=(this.ctx.state.env.PATH||"/bin:/usr/bin").split(":");for(let i of r){if(!i)continue;let o=`${i}/${e}`;if(await this.ctx.fs.exists(o)){let a=this.ctx.commands.get(e);if(a)return{cmd:a,path:o}}}if(!await this.ctx.fs.exists("/bin")){let i=this.ctx.commands.get(e);if(i)return{cmd:i,path:`/bin/${e}`}}return null}async findCommandInPath(e){let s=[],n=(this.ctx.state.env.PATH||"/bin:/usr/bin").split(":");for(let i of n){if(!i)continue;let o=`${i}/${e}`;await this.ctx.fs.exists(o)&&s.push(o)}return s}handleType(e){let s=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),r=new Set(["cd","export","unset","exit","local","set","break","continue","return","eval","shift","source",".","read","declare","typeset","readonly",":","true","false","let","command","builtin","shopt","exec","wait","type","[","test"]),n="",i="",o=0;for(let a of e)s.has(a)?n+=`${a} is a shell keyword
136
- `:r.has(a)?n+=`${a} is a shell builtin
137
- `:this.ctx.state.functions.has(a)?n+=`${a} is a function
138
- `:this.ctx.commands.has(a)?n+=`${a} is /bin/${a}
139
- `:(i+=`bash: type: ${a}: not found
140
- `,o=1);return S(n,i,o)}async executeSubshell(e,s=""){let r={...this.ctx.state.env},n=this.ctx.state.cwd,i=this.ctx.state.loopDepth,o=this.ctx.state.parentHasLoopContext;this.ctx.state.parentHasLoopContext=i>0,this.ctx.state.loopDepth=0;let a=this.ctx.state.groupStdin;s&&(this.ctx.state.groupStdin=s);let c="",l="",u=0;try{for(let h of e.body){let d=await this.executeStatement(h);c+=d.stdout,l+=d.stderr,u=d.exitCode}}catch(h){if(this.ctx.state.env=r,this.ctx.state.cwd=n,this.ctx.state.loopDepth=i,this.ctx.state.parentHasLoopContext=o,this.ctx.state.groupStdin=a,h instanceof B)throw h;if(h instanceof ue)return c+=h.stdout,l+=h.stderr,S(c,l,0);if(h instanceof U||h instanceof Y)return c+=h.stdout,l+=h.stderr,S(c,l,0);if(h instanceof R)return c+=h.stdout,l+=h.stderr,S(c,l,h.exitCode);if(h instanceof G)return c+=h.stdout,l+=h.stderr,S(c,l,h.exitCode);if(h instanceof te)throw h.stdout=c+h.stdout,h.stderr=l+h.stderr,h;return S(c,`${l}${le(h)}
141
- `,1)}return this.ctx.state.env=r,this.ctx.state.cwd=n,this.ctx.state.loopDepth=i,this.ctx.state.parentHasLoopContext=o,this.ctx.state.groupStdin=a,S(c,l,u)}async executeGroup(e,s=""){let r="",n="",i=0,o=this.ctx.state.groupStdin;s&&(this.ctx.state.groupStdin=s);try{for(let a of e.body){let c=await this.executeStatement(a);r+=c.stdout,n+=c.stderr,i=c.exitCode}}catch(a){if(this.ctx.state.groupStdin=o,a instanceof B)throw a;if(qe(a)||a instanceof te||a instanceof R)throw a.prependOutput(r,n),a;return S(r,`${n}${le(a)}
142
- `,1)}return this.ctx.state.groupStdin=o,S(r,n,i)}async executeArithmeticCommand(e){try{let s=await v(this.ctx,e.expression.expression);return _(s!==0)}catch(s){return x(`bash: arithmetic expression: ${s.message}
143
- `)}}async executeConditionalCommand(e){try{let s=await pe(this.ctx,e.expression);return _(s)}catch(s){return x(`bash: conditional expression: ${s.message}
144
- `,2)}}};var ye={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3};function Us(t){return t?{maxCallDepth:t.maxCallDepth??ye.maxCallDepth,maxCommandCount:t.maxCommandCount??ye.maxCommandCount,maxLoopIterations:t.maxLoopIterations??ye.maxLoopIterations,maxAwkIterations:t.maxAwkIterations??ye.maxAwkIterations,maxSedIterations:t.maxSedIterations??ye.maxSedIterations,maxJqIterations:t.maxJqIterations??ye.maxJqIterations,maxSqliteTimeoutMs:t.maxSqliteTimeoutMs??ye.maxSqliteTimeoutMs}:{...ye}}function Gs(t){try{let e=new URL(t);return{origin:e.origin,pathname:e.pathname,href:e.href}}catch{return null}}function si(t){let e=Gs(t);return e?{origin:e.origin,pathPrefix:e.pathname}:null}function ni(t,e){let s=Gs(t);if(!s)return!1;let r=si(e);return!r||s.origin!==r.origin?!1:r.pathPrefix==="/"||r.pathPrefix===""?!0:s.pathname.startsWith(r.pathPrefix)}function wr(t,e){return!e||e.length===0?!1:e.some(s=>ni(t,s))}var De=class extends Error{constructor(e){super(`Network access denied: URL not in allow-list: ${e}`),this.name="NetworkAccessDeniedError"}},Oe=class extends Error{constructor(e){super(`Too many redirects (max: ${e})`),this.name="TooManyRedirectsError"}},_e=class extends Error{constructor(e){super(`Redirect target not in allow-list: ${e}`),this.name="RedirectNotAllowedError"}},St=class extends Error{constructor(e,s){super(`HTTP method '${e}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}};var ii=20,oi=3e4,ai=["GET","HEAD"],ci=new Set(["GET","HEAD","OPTIONS"]),li=new Set([301,302,303,307,308]);function Er(t){let e=t.maxRedirects??ii,s=t.timeoutMs??oi,r=t.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:t.allowedMethods??ai;function n(a){if(!t.dangerouslyAllowFullInternetAccess&&!wr(a,t.allowedUrlPrefixes??[]))throw new De(a)}function i(a){if(t.dangerouslyAllowFullInternetAccess)return;let c=a.toUpperCase();if(!r.includes(c))throw new St(c,r)}async function o(a,c={}){let l=c.method?.toUpperCase()??"GET";n(a),i(l);let u=a,h=0,d=c.followRedirects??!0,m=c.timeoutMs!==void 0?Math.min(c.timeoutMs,s):s;for(;;){let y=new AbortController,E=setTimeout(()=>y.abort(),m);try{let p={method:l,headers:c.headers,signal:y.signal,redirect:"manual"};c.body&&!ci.has(l)&&(p.body=c.body);let w=await fetch(u,p);if(li.has(w.status)&&d){let g=w.headers.get("location");if(!g)return await Vs(w,u);let b=new URL(g,u).href;if(!t.dangerouslyAllowFullInternetAccess&&!wr(b,t.allowedUrlPrefixes??[]))throw new _e(b);if(h++,h>e)throw new Oe(e);u=b;continue}return await Vs(w,u)}finally{clearTimeout(E)}}}return o}async function Vs(t,e){let s={};return t.headers.forEach((r,n)=>{s[n.toLowerCase()]=r}),{status:t.status,statusText:t.statusText,headers:s,body:await t.text(),url:e}}var je=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;state;constructor(e={}){let s=e.fs??new se(e.files);this.fs=s,this.useDefaultLayout=!e.cwd&&!e.files;let r=e.cwd||(this.useDefaultLayout?"/home/user":"/"),n={HOME:this.useDefaultLayout?"/home/user":"/",PATH:"/bin:/usr/bin",IFS:`
145
- `,OSTYPE:"linux-gnu",MACHTYPE:"x86_64-pc-linux-gnu",HOSTTYPE:"x86_64",PWD:r,OLDPWD:r,...e.env};if(this.limits=Us({...e.executionLimits,...e.maxCallDepth!==void 0&&{maxCallDepth:e.maxCallDepth},...e.maxCommandCount!==void 0&&{maxCommandCount:e.maxCommandCount},...e.maxLoopIterations!==void 0&&{maxLoopIterations:e.maxLoopIterations}}),e.network&&(this.secureFetch=Er(e.network)),this.sleepFn=e.sleep,this.traceFn=e.trace,this.logger=e.logger,this.state={env:n,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1},inCondition:!1,loopDepth:0},kr(s,this.useDefaultLayout),r!=="/"&&s instanceof se)try{s.mkdirSync(r,{recursive:!0})}catch{}for(let i of xr(e.commands))this.registerCommand(i);if(e.network)for(let i of br())this.registerCommand(i);if(e.customCommands)for(let i of e.customCommands)Cr(i)?this.registerCommand(Nr(i)):this.registerCommand(i)}registerCommand(e){this.commands.set(e.name,e);let s=this.fs;if(typeof s.writeFileSync=="function")try{s.writeFileSync(`/bin/${e.name}`,`#!/bin/bash
146
- # Built-in command: ${e.name}
147
- `)}catch{}}logResult(e){return this.logger&&(e.stdout&&this.logger.debug("stdout",{output:e.stdout}),e.stderr&&this.logger.info("stderr",{output:e.stderr}),this.logger.info("exit",{exitCode:e.exitCode})),e}async exec(e,s){if(this.state.callDepth===0&&(this.state.commandCount=0),this.state.commandCount++,this.state.commandCount>this.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option.
148
- `,exitCode:1,env:{...this.state.env,...s?.env}};if(!e.trim())return{stdout:"",stderr:"",exitCode:0,env:{...this.state.env,...s?.env}};this.logger?.info("exec",{command:e});let r=s?.cwd??this.state.cwd,n={...this.state,env:{...this.state.env,...s?.env,...s?.cwd?{PWD:s.cwd}:{}},cwd:r,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options}},i=e;s?.rawScript||(i=ui(e));try{let o=he(i),a={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn},l=await new He(a,n).executeScript(o);return this.logResult(l)}catch(o){if(o instanceof R)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:o.exitCode,env:{...this.state.env,...s?.env}});if(o instanceof W)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:1,env:{...this.state.env,...s?.env}});if(o instanceof B)return this.logResult({stdout:o.stdout,stderr:o.stderr,exitCode:B.EXIT_CODE,env:{...this.state.env,...s?.env}});if(o.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${o.message}
149
- `,exitCode:2,env:{...this.state.env,...s?.env}});if(o instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${o.message}
150
- `,exitCode:1,env:{...this.state.env,...s?.env}});throw o}}async readFile(e){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,e))}async writeFile(e,s){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,e),s)}getCwd(){return this.state.cwd}getEnv(){return{...this.state.env}}};function ui(t){let e=t.split(`
151
- `),s=[],r=[];for(let n=0;n<e.length;n++){let i=e[n];if(r.length>0){let c=r[r.length-1];if((c.stripTabs?i.replace(/^\t+/,""):i)===c.delimiter){s.push(i.trimStart()),r.pop();continue}s.push(i);continue}let o=i.trimStart();s.push(o);let a=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let c of o.matchAll(a)){let l=c[1]==="-",u=c[3];r.push({delimiter:u,stripTabs:l})}}return s.join(`
152
- `)}var xt=class{baseFs;mounts=new Map;constructor(e){if(this.baseFs=e?.base??new se,e?.mounts)for(let{mountPoint:s,filesystem:r}of e.mounts)this.mount(s,r)}mount(e,s){this.validateMountPath(e);let r=this.normalizePath(e);this.validateMount(r),this.mounts.set(r,{mountPoint:r,filesystem:s})}unmount(e){let s=this.normalizePath(e);if(!this.mounts.has(s))throw new Error(`No filesystem mounted at '${e}'`);this.mounts.delete(s)}getMounts(){return Array.from(this.mounts.values()).map(e=>({mountPoint:e.mountPoint,filesystem:e.filesystem}))}isMountPoint(e){let s=this.normalizePath(e);return this.mounts.has(s)}validateMountPath(e){let s=e.split("/");for(let r of s)if(r==="."||r==="..")throw new Error(`Invalid mount point '${e}': contains '.' or '..' segments`)}validateMount(e){if(e==="/")throw new Error("Cannot mount at root '/'");for(let s of this.mounts.keys())if(s!==e){if(e.startsWith(`${s}/`))throw new Error(`Cannot mount at '${e}': inside existing mount '${s}'`);if(s.startsWith(`${e}/`))throw new Error(`Cannot mount at '${e}': would contain existing mount '${s}'`)}}normalizePath(e){if(!e||e==="/")return"/";let s=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;s.startsWith("/")||(s=`/${s}`);let r=s.split("/").filter(i=>i&&i!=="."),n=[];for(let i of r)i===".."?n.pop():n.push(i);return`/${n.join("/")}`}routePath(e){let s=this.normalizePath(e),r=null,n=0;for(let i of this.mounts.values()){let o=i.mountPoint;if(s===o)return{fs:i.filesystem,relativePath:"/"};s.startsWith(`${o}/`)&&o.length>n&&(r=i,n=o.length)}if(r){let i=s.slice(n);return{fs:r.filesystem,relativePath:i||"/"}}return{fs:this.baseFs,relativePath:s}}getChildMountPoints(e){let s=this.normalizePath(e),r=s==="/"?"/":`${s}/`,n=[];for(let i of this.mounts.keys())if(i.startsWith(r)){let a=i.slice(r.length).split("/")[0];a&&!n.includes(a)&&n.push(a)}return n}async readFile(e,s){let{fs:r,relativePath:n}=this.routePath(e);return r.readFile(n,s)}async readFileBuffer(e){let{fs:s,relativePath:r}=this.routePath(e);return s.readFileBuffer(r)}async writeFile(e,s,r){let{fs:n,relativePath:i}=this.routePath(e);return n.writeFile(i,s,r)}async appendFile(e,s,r){let{fs:n,relativePath:i}=this.routePath(e);return n.appendFile(i,s,r)}async exists(e){let s=this.normalizePath(e);if(this.mounts.has(s)||this.getChildMountPoints(s).length>0)return!0;let{fs:n,relativePath:i}=this.routePath(e);return n.exists(i)}async stat(e){let s=this.normalizePath(e),r=this.mounts.get(s);if(r)try{return await r.filesystem.stat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(s).length>0)try{return await this.baseFs.stat(s)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(e);return i.stat(o)}async lstat(e){let s=this.normalizePath(e),r=this.mounts.get(s);if(r)try{return await r.filesystem.lstat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(s).length>0)try{return await this.baseFs.lstat(s)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(e);return i.lstat(o)}async mkdir(e,s){let r=this.normalizePath(e);if(this.mounts.has(r)){if(s?.recursive)return;throw new Error(`EEXIST: directory already exists, mkdir '${e}'`)}if(this.getChildMountPoints(r).length>0&&s?.recursive)return;let{fs:i,relativePath:o}=this.routePath(e);return i.mkdir(o,s)}async readdir(e){let s=this.normalizePath(e),r=new Set,n=null,{fs:i,relativePath:o}=this.routePath(e);try{let c=await i.readdir(o);for(let l of c)r.add(l)}catch(c){let l=c.code,u=c.message||"";if(l!=="ENOENT"&&!u.includes("ENOENT"))throw c;n=c}let a=this.getChildMountPoints(s);for(let c of a)r.add(c);if(r.size===0&&n&&!this.mounts.has(s))throw n;return Array.from(r).sort()}async rm(e,s){let r=this.normalizePath(e);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot remove '${e}'`);if(this.getChildMountPoints(r).length>0)throw new Error(`EBUSY: contains mount points, cannot remove '${e}'`);let{fs:i,relativePath:o}=this.routePath(e);return i.rm(o,s)}async cp(e,s,r){let n=this.routePath(e),i=this.routePath(s);return n.fs===i.fs?n.fs.cp(n.relativePath,i.relativePath,r):this.crossMountCopy(e,s,r)}async mv(e,s){let r=this.normalizePath(e);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot move '${e}'`);let n=this.routePath(e),i=this.routePath(s);if(n.fs===i.fs)return n.fs.mv(n.relativePath,i.relativePath);await this.cp(e,s,{recursive:!0}),await this.rm(e,{recursive:!0})}resolvePath(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=e==="/"?`/${s}`:`${e}/${s}`;return this.normalizePath(r)}getAllPaths(){let e=new Set;for(let s of this.baseFs.getAllPaths())e.add(s);for(let s of this.mounts.keys()){let r=s.split("/").filter(Boolean),n="";for(let o of r)n=`${n}/${o}`,e.add(n);let i=this.mounts.get(s);if(i)for(let o of i.filesystem.getAllPaths())o==="/"?e.add(s):e.add(`${s}${o}`)}return Array.from(e).sort()}async chmod(e,s){let r=this.normalizePath(e),n=this.mounts.get(r);if(n)return n.filesystem.chmod("/",s);let{fs:i,relativePath:o}=this.routePath(e);return i.chmod(o,s)}async symlink(e,s){let{fs:r,relativePath:n}=this.routePath(s);return r.symlink(e,n)}async link(e,s){let r=this.routePath(e),n=this.routePath(s);if(r.fs!==n.fs)throw new Error(`EXDEV: cross-device link not permitted, link '${e}' -> '${s}'`);return r.fs.link(r.relativePath,n.relativePath)}async readlink(e){let{fs:s,relativePath:r}=this.routePath(e);return s.readlink(r)}async crossMountCopy(e,s,r){let n=await this.lstat(e);if(n.isFile){let i=await this.readFileBuffer(e);await this.writeFile(s,i),await this.chmod(s,n.mode)}else if(n.isDirectory){if(!r?.recursive)throw new Error(`cp: ${e} is a directory (not copied)`);await this.mkdir(s,{recursive:!0});let i=await this.readdir(e);for(let o of i){let a=e==="/"?`/${o}`:`${e}/${o}`,c=s==="/"?`/${o}`:`${s}/${o}`;await this.crossMountCopy(a,c,r)}}else if(n.isSymbolicLink){let i=await this.readlink(e);await this.symlink(i,s)}}};import*as M from"node:fs";import*as Le from"node:path";var fi="/home/user/project",Te=class{root;mountPoint;readOnly;memory=new Map;deleted=new Set;constructor(e){this.root=Le.resolve(e.root);let s=e.mountPoint??fi;if(this.mountPoint=s==="/"?"/":s.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${s}`);if(this.readOnly=e.readOnly??!1,!M.existsSync(this.root))throw new Error(`OverlayFs root does not exist: ${this.root}`);if(!M.statSync(this.root).isDirectory())throw new Error(`OverlayFs root is not a directory: ${this.root}`);this.createMountPointDirs()}assertWritable(e){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${e}`)}createMountPointDirs(){let e=this.mountPoint.split("/").filter(Boolean),s="";for(let r of e)s+=`/${r}`,this.memory.has(s)||this.memory.set(s,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.memory.set("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}mkdirSync(e,s){let n=this.normalizePath(e).split("/").filter(Boolean),i="";for(let o of n)i+=`/${o}`,this.memory.has(i)||this.memory.set(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(e,s){let r=this.normalizePath(e),n=this.getDirname(r);n!=="/"&&this.mkdirSync(n);let i=s instanceof Uint8Array?s:new TextEncoder().encode(s);this.memory.set(r,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(e){let s=e.lastIndexOf("/");return s===0?"/":e.slice(0,s)}normalizePath(e){if(!e||e==="/")return"/";let s=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;s.startsWith("/")||(s=`/${s}`);let r=s.split("/").filter(i=>i&&i!=="."),n=[];for(let i of r)i===".."?n.pop():n.push(i);return`/${n.join("/")}`||"/"}getRelativeToMount(e){return this.mountPoint==="/"?e:e===this.mountPoint?"/":e.startsWith(`${this.mountPoint}/`)?e.slice(this.mountPoint.length):null}toRealPath(e){let s=this.normalizePath(e),r=this.getRelativeToMount(s);if(r===null)return null;let n=Le.join(this.root,r),i=Le.resolve(n);return!i.startsWith(this.root)&&i!==this.root.replace(/\/$/,"")?null:i}dirname(e){let s=this.normalizePath(e);if(s==="/")return"/";let r=s.lastIndexOf("/");return r===0?"/":s.slice(0,r)}ensureParentDirs(e){let s=this.dirname(e);s!=="/"&&(this.memory.has(s)||(this.ensureParentDirs(s),this.memory.set(s,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(s))}async existsInOverlay(e){let s=this.normalizePath(e);if(this.deleted.has(s))return!1;if(this.memory.has(s))return!0;let r=this.toRealPath(s);if(!r)return!1;try{return await M.promises.access(r),!0}catch{return!1}}async readFile(e,s){let r=await this.readFileBuffer(e),n=q(s);return Ce(r,n)}async readFileBuffer(e,s=new Set){let r=this.normalizePath(e);if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);if(s.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${e}'`);let n=this.memory.get(r);if(n){if(n.type==="symlink"){let o=this.resolveSymlink(r,n.target);return this.readFileBuffer(o,s)}if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return n.content}let i=this.toRealPath(r);if(!i)throw new Error(`ENOENT: no such file or directory, open '${e}'`);try{let o=await M.promises.lstat(i);if(o.isSymbolicLink()){let c=await M.promises.readlink(i),l=this.resolveSymlink(r,c);return this.readFileBuffer(l,s)}if(o.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);let a=await M.promises.readFile(i);return new Uint8Array(a)}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${e}'`):o}}async writeFile(e,s,r){this.assertWritable(`write '${e}'`);let n=this.normalizePath(e);this.ensureParentDirs(n);let i=q(r),o=re(s,i);this.memory.set(n,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(n)}async appendFile(e,s,r){this.assertWritable(`append '${e}'`);let n=this.normalizePath(e),i=q(r),o=re(s,i),a;try{a=await this.readFileBuffer(n)}catch{a=new Uint8Array(0)}let c=new Uint8Array(a.length+o.length);c.set(a),c.set(o,a.length),this.ensureParentDirs(n),this.memory.set(n,{type:"file",content:c,mode:420,mtime:new Date}),this.deleted.delete(n)}async exists(e){return this.existsInOverlay(e)}async stat(e,s=new Set){let r=this.normalizePath(e);if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${e}'`);if(s.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let n=this.memory.get(r);if(n){if(n.type==="symlink"){let a=this.resolveSymlink(r,n.target);return this.stat(a,s)}let o=0;return n.type==="file"&&(o=n.content.length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:o,mtime:n.mtime}}let i=this.toRealPath(r);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);try{let o=await M.promises.stat(i);return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:!1,mode:o.mode,size:o.size,mtime:o.mtime}}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${e}'`):o}}async lstat(e){let s=this.normalizePath(e);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let r=this.memory.get(s);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let i=0;return r.type==="file"&&(i=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:i,mtime:r.mtime}}let n=this.toRealPath(s);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);try{let i=await M.promises.lstat(n);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${e}'`):i}}resolveSymlink(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${s}`:`${r}/${s}`)}async mkdir(e,s){this.assertWritable(`mkdir '${e}'`);let r=this.normalizePath(e);if(await this.existsInOverlay(r)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${e}'`);return}let i=this.dirname(r);if(i!=="/"&&!await this.existsInOverlay(i))if(s?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.memory.set(r,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(r)}async readdirCore(e,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let r=new Map,n=new Set,i=s==="/"?"/":`${s}/`;for(let a of this.deleted)if(a.startsWith(i)){let c=a.slice(i.length),l=c.split("/")[0];l&&!c.includes("/",l.length)&&n.add(l)}for(let[a,c]of this.memory)if(a!==s&&a.startsWith(i)){let l=a.slice(i.length),u=l.split("/")[0];u&&!n.has(u)&&!l.includes("/",1)&&r.set(u,{name:u,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}let o=this.toRealPath(s);if(o)try{let a=await M.promises.readdir(o,{withFileTypes:!0});for(let c of a)!n.has(c.name)&&!r.has(c.name)&&r.set(c.name,{name:c.name,isFile:c.isFile(),isDirectory:c.isDirectory(),isSymbolicLink:c.isSymbolicLink()})}catch(a){if(a.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`)}else if(a.code!=="ENOTDIR")throw a}return r}async resolveForReaddir(e,s=!1){let r=this.normalizePath(e),n=new Set,i=s,o=this.memory.get(r);for(;o&&o.type==="symlink";){if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${e}'`);n.add(r),i=!0,r=this.resolveSymlink(r,o.target),o=this.memory.get(r)}if(o)return{normalized:r,outsideOverlay:!1};if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let c=this.toRealPath(r);if(!c)return{normalized:r,outsideOverlay:!0};try{if((await M.promises.lstat(c)).isSymbolicLink()){let u=await M.promises.readlink(c),h=this.resolveSymlink(r,u);return this.resolveForReaddir(h,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async readdir(e){let{normalized:s,outsideOverlay:r}=await this.resolveForReaddir(e);if(r)return[];let n=await this.readdirCore(e,s);return Array.from(n.keys()).sort((i,o)=>i<o?-1:i>o?1:0)}async readdirWithFileTypes(e){let{normalized:s,outsideOverlay:r}=await this.resolveForReaddir(e);if(r)return[];let n=await this.readdirCore(e,s);return Array.from(n.values()).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async rm(e,s){this.assertWritable(`rm '${e}'`);let r=this.normalizePath(e);if(!await this.existsInOverlay(r)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}try{if((await this.stat(r)).isDirectory){let o=await this.readdir(r);if(o.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let a of o){let c=r==="/"?`/${a}`:`${r}/${a}`;await this.rm(c,s)}}}}catch{}this.deleted.add(r),this.memory.delete(r)}async cp(e,s,r){this.assertWritable(`cp '${s}'`);let n=this.normalizePath(e),i=this.normalizePath(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, cp '${e}'`);let a=await this.stat(n);if(a.isFile){let c=await this.readFileBuffer(n);await this.writeFile(i,c)}else if(a.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(i,{recursive:!0});let c=await this.readdir(n);for(let l of c){let u=n==="/"?`/${l}`:`${n}/${l}`,h=i==="/"?`/${l}`:`${i}/${l}`;await this.cp(u,h,r)}}}async mv(e,s){this.assertWritable(`mv '${s}'`),await this.cp(e,s,{recursive:!0}),await this.rm(e,{recursive:!0})}resolvePath(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=e==="/"?`/${s}`:`${e}/${s}`;return this.normalizePath(r)}getAllPaths(){let e=new Set(this.memory.keys());for(let s of this.deleted)e.delete(s);return this.scanRealFs("/",e),Array.from(e)}scanRealFs(e,s){if(this.deleted.has(e))return;let r=this.toRealPath(e);if(r)try{let n=M.readdirSync(r);for(let i of n){let o=e==="/"?`/${i}`:`${e}/${i}`;if(this.deleted.has(o))continue;s.add(o);let a=Le.join(r,i);M.statSync(a).isDirectory()&&this.scanRealFs(o,s)}}catch{}}async chmod(e,s){this.assertWritable(`chmod '${e}'`);let r=this.normalizePath(e);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);let i=this.memory.get(r);if(i){i.mode=s;return}let o=await this.stat(r);if(o.isFile){let a=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:a,mode:s,mtime:new Date})}else o.isDirectory&&this.memory.set(r,{type:"directory",mode:s,mtime:new Date})}async symlink(e,s){this.assertWritable(`symlink '${s}'`);let r=this.normalizePath(s);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.memory.set(r,{type:"symlink",target:e,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(e,s){this.assertWritable(`link '${s}'`);let r=this.normalizePath(e),n=this.normalizePath(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${e}'`);let o=await this.stat(r);if(!o.isFile)throw new Error(`EPERM: operation not permitted, link '${e}'`);if(await this.existsInOverlay(n))throw new Error(`EEXIST: file already exists, link '${s}'`);let c=await this.readFileBuffer(r);this.ensureParentDirs(n),this.memory.set(n,{type:"file",content:c,mode:o.mode,mtime:new Date}),this.deleted.delete(n)}async readlink(e){let s=this.normalizePath(e);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);let r=this.memory.get(s);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}let n=this.toRealPath(s);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);try{return await M.promises.readlink(n)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${e}'`):i.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${e}'`):i}}};import*as $ from"node:fs";import*as ee from"node:path";var bt=class{root;constructor(e){if(this.root=ee.resolve(e.root),!$.existsSync(this.root))throw new Error(`ReadWriteFs root does not exist: ${this.root}`);if(!$.statSync(this.root).isDirectory())throw new Error(`ReadWriteFs root is not a directory: ${this.root}`)}toRealPath(e){let s=this.normalizePath(e),r=ee.join(this.root,s);return ee.resolve(r)}normalizePath(e){if(!e||e==="/")return"/";let s=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;s.startsWith("/")||(s=`/${s}`);let r=s.split("/").filter(i=>i&&i!=="."),n=[];for(let i of r)i===".."?n.pop():n.push(i);return`/${n.join("/")}`||"/"}async readFile(e,s){let r=await this.readFileBuffer(e),n=q(s);return Ce(r,n)}async readFileBuffer(e){let s=this.toRealPath(e);try{let r=await $.promises.readFile(s);return new Uint8Array(r)}catch(r){let n=r;throw n.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${e}'`):n.code==="EISDIR"?new Error(`EISDIR: illegal operation on a directory, read '${e}'`):r}}async writeFile(e,s,r){let n=this.toRealPath(e),i=q(r),o=re(s,i),a=ee.dirname(n);await $.promises.mkdir(a,{recursive:!0}),await $.promises.writeFile(n,o)}async appendFile(e,s,r){let n=this.toRealPath(e),i=q(r),o=re(s,i),a=ee.dirname(n);await $.promises.mkdir(a,{recursive:!0}),await $.promises.appendFile(n,o)}async exists(e){let s=this.toRealPath(e);try{return await $.promises.access(s),!0}catch{return!1}}async stat(e){let s=this.toRealPath(e);try{let r=await $.promises.stat(s);return{isFile:r.isFile(),isDirectory:r.isDirectory(),isSymbolicLink:!1,mode:r.mode,size:r.size,mtime:r.mtime}}catch(r){throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${e}'`):r}}async lstat(e){let s=this.toRealPath(e);try{let r=await $.promises.lstat(s);return{isFile:r.isFile(),isDirectory:r.isDirectory(),isSymbolicLink:r.isSymbolicLink(),mode:r.mode,size:r.size,mtime:r.mtime}}catch(r){throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${e}'`):r}}async mkdir(e,s){let r=this.toRealPath(e);try{await $.promises.mkdir(r,{recursive:s?.recursive})}catch(n){let i=n;throw i.code==="EEXIST"?new Error(`EEXIST: file already exists, mkdir '${e}'`):i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, mkdir '${e}'`):n}}async readdir(e){return(await this.readdirWithFileTypes(e)).map(r=>r.name)}async readdirWithFileTypes(e){let s=this.toRealPath(e);try{return(await $.promises.readdir(s,{withFileTypes:!0})).map(n=>({name:n.name,isFile:n.isFile(),isDirectory:n.isDirectory(),isSymbolicLink:n.isSymbolicLink()})).sort((n,i)=>n.name<i.name?-1:n.name>i.name?1:0)}catch(r){let n=r;throw n.code==="ENOENT"?new Error(`ENOENT: no such file or directory, scandir '${e}'`):n.code==="ENOTDIR"?new Error(`ENOTDIR: not a directory, scandir '${e}'`):r}}async rm(e,s){let r=this.toRealPath(e);try{await $.promises.rm(r,{recursive:s?.recursive??!1,force:s?.force??!1})}catch(n){let i=n;throw i.code==="ENOENT"&&!s?.force?new Error(`ENOENT: no such file or directory, rm '${e}'`):i.code==="ENOTEMPTY"?new Error(`ENOTEMPTY: directory not empty, rm '${e}'`):n}}async cp(e,s,r){let n=this.toRealPath(e),i=this.toRealPath(s);try{await $.promises.cp(n,i,{recursive:r?.recursive??!1})}catch(o){let a=o;throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, cp '${e}'`):a.code==="EISDIR"?new Error(`EISDIR: is a directory, cp '${e}'`):o}}async mv(e,s){let r=this.toRealPath(e),n=this.toRealPath(s),i=ee.dirname(n);await $.promises.mkdir(i,{recursive:!0});try{await $.promises.rename(r,n)}catch(o){let a=o;if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${e}'`);if(a.code==="EXDEV"){await this.cp(e,s,{recursive:!0}),await this.rm(e,{recursive:!0});return}throw o}}resolvePath(e,s){if(s.startsWith("/"))return this.normalizePath(s);let r=e==="/"?`/${s}`:`${e}/${s}`;return this.normalizePath(r)}getAllPaths(){let e=[];return this.scanDir("/",e),e}scanDir(e,s){let r=this.toRealPath(e);try{let n=$.readdirSync(r);for(let i of n){let o=e==="/"?`/${i}`:`${e}/${i}`;s.push(o);let a=ee.join(r,i);$.statSync(a).isDirectory()&&this.scanDir(o,s)}}catch{}}async chmod(e,s){let r=this.toRealPath(e);try{await $.promises.chmod(r,s)}catch(n){throw n.code==="ENOENT"?new Error(`ENOENT: no such file or directory, chmod '${e}'`):n}}async symlink(e,s){let r=this.toRealPath(s);try{await $.promises.symlink(e,r)}catch(n){throw n.code==="EEXIST"?new Error(`EEXIST: file already exists, symlink '${s}'`):n}}async link(e,s){let r=this.toRealPath(e),n=this.toRealPath(s);try{await $.promises.link(r,n)}catch(i){let o=i;throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, link '${e}'`):o.code==="EEXIST"?new Error(`EEXIST: file already exists, link '${s}'`):o.code==="EPERM"?new Error(`EPERM: operation not permitted, link '${e}'`):i}}async readlink(e){let s=this.toRealPath(e);try{return await $.promises.readlink(s)}catch(r){let n=r;throw n.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${e}'`):n.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${e}'`):r}}};var Fe=class{cmdId;cwd;startedAt;exitCode;bashEnv;cmdLine;env;explicitCwd;resultPromise;constructor(e,s,r,n,i=!1){this.cmdId=crypto.randomUUID(),this.cwd=r,this.startedAt=new Date,this.bashEnv=e,this.cmdLine=s,this.env=n,this.explicitCwd=i,this.resultPromise=this.execute()}async execute(){let e=this.env||this.explicitCwd?{cwd:this.explicitCwd?this.cwd:void 0,env:this.env}:void 0,s=await this.bashEnv.exec(this.cmdLine,e);return this.exitCode=s.exitCode,s}async*logs(){let e=await this.resultPromise;e.stdout&&(yield{type:"stdout",data:e.stdout,timestamp:new Date}),e.stderr&&(yield{type:"stderr",data:e.stderr,timestamp:new Date})}async wait(){return await this.resultPromise,this}async output(){let e=await this.resultPromise;return e.stdout+e.stderr}async stdout(){return(await this.resultPromise).stdout}async stderr(){return(await this.resultPromise).stderr}async kill(){}};var Ct=class t{bashEnv;constructor(e){this.bashEnv=e}static async create(e){let s=e?.fs;if(e?.overlayRoot){if(e?.fs)throw new Error("Cannot specify both 'fs' and 'overlayRoot' options");s=new Te({root:e.overlayRoot})}let r=new je({env:e?.env,cwd:e?.cwd,fs:s,maxCallDepth:e?.maxCallDepth,maxCommandCount:e?.maxCommandCount,maxLoopIterations:e?.maxLoopIterations,network:e?.network});return new t(r)}async runCommand(e,s){let r=s?.cwd??this.bashEnv.getCwd(),n=s?.cwd!==void 0;return new Fe(this.bashEnv,e,r,s?.env,n)}async writeFiles(e){for(let[s,r]of Object.entries(e)){let n;typeof r=="string"?n=r:r.encoding==="base64"?n=Buffer.from(r.content,"base64").toString("utf-8"):n=r.content;let i=s.substring(0,s.lastIndexOf("/"))||"/";i!=="/"&&await this.bashEnv.exec(`mkdir -p ${i}`),await this.bashEnv.writeFile(s,n)}}async readFile(e,s){let r=await this.bashEnv.readFile(e);return s==="base64"?Buffer.from(r).toString("base64"):r}async mkDir(e,s){let r=s?.recursive?"-p":"";await this.bashEnv.exec(`mkdir ${r} ${e}`)}async stop(){}async extendTimeout(e){}get domain(){}get bashEnvInstance(){return this.bashEnv}};export{je as Bash,se as InMemoryFs,xt as MountableFs,De as NetworkAccessDeniedError,Te as OverlayFs,bt as ReadWriteFs,_e as RedirectNotAllowedError,Ct as Sandbox,Fe as SandboxCommand,Oe as TooManyRedirectsError,qs as defineCommand,Hs as getCommandNames,js as getNetworkCommandNames};
624
+ `)),a=u}else if(c.operator==="<<<"&&c.target.type==="Word")a=`${await T(e,c.target)}
625
+ `;else if(c.operator==="<"&&c.target.type==="Word")try{let f=await T(e,c.target),u=e.fs.resolvePath(e.state.cwd,f);a=await e.fs.readFile(u)}catch{let f=await T(e,c.target);return S(`bash: ${f}: No such file or directory
626
+ `)}let l=e.state.groupStdin;a&&(e.state.groupStdin=a),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&$e(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r);let c=0,f=!1,u=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let m=await e.executeStatement(h);n+=m.stdout,r+=m.stderr,c=m.exitCode}}catch(h){if(h instanceof re){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;f=!0}else if(h instanceof ie){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;u=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if(f)break;if(!u){if(c!==0)break;try{for(let h of t.body){let m=await e.executeStatement(h);n+=m.stdout,r+=m.stderr,i=m.exitCode}}catch(h){let m=Je(h,n,r,e.state.loopDepth);if(n=m.stdout,r=m.stderr,m.action==="break")break;if(m.action==="continue")continue;if(m.action==="error")return P(n,r,m.exitCode??1);throw m.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=l}return P(n,r,i)}async function mr(e,t){let s="",n="",r=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&$e(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,n);let o=await Ls(e,t.condition);if(s+=o.stdout,n+=o.stderr,o.exitCode===0)break;try{for(let a of t.body){let l=await e.executeStatement(a);s+=l.stdout,n+=l.stderr,r=l.exitCode}}catch(a){let l=Je(a,s,n,e.state.loopDepth);if(s=l.stdout,n=l.stderr,l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return P(s,n,l.exitCode??1);throw l.error}}}finally{e.state.loopDepth--}return P(s,n,r)}async function yr(e,t){let s=await ye(e,t.redirections);if(s)return s;let n="",r="",i=0,o=await T(e,t.word),a=!1;for(let c=0;c<t.items.length;c++){let f=t.items[c],u=a;if(!a)for(let d of f.patterns){let h=await T(e,d);Js(d)&&(h=Ys(h));let m=e.state.shoptOptions.nocasematch,p=e.state.shoptOptions.extglob;if(Le(o,h,m,p)){u=!0;break}}if(u){let d=await Tt(e,f.body,n,r);if(n=d.stdout,r=d.stderr,i=d.exitCode,f.terminator===";;")break;f.terminator===";&"?a=!0:a=!1}else a=!1}let l=P(n,r,i);return j(e,l,t.redirections)}function Fs(e,t){if(e.parts.length!==1)return!1;let s=e.parts[0];return s.type!=="Literal"?!1:t.includes(s.value)}function wr(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),o=r+n+1,a=t.slice(o),l=a.indexOf(":");if(l===-1)return null;let c=Number.parseInt(a.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let f=a.slice(l+1);return{path:i,position:c,content:f}}var gr="+ ";async function vr(e){let t=e.state.env.PS4;if(t===void 0)return gr;if(t==="")return"";try{let n=new W().parseWordFromString(t,!1,!1);return await T(e,n)}catch{return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
627
+ `,t||gr}}function Gi(e){return e.map(t=>Xi(t)).join(" ")}function Xi(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),n=e.includes(`
628
+ `),r=e.includes(" "),i=e.includes("\\"),o=e.includes("'");if(s||n||r||i){let l="";for(let c of e){let f=c.charCodeAt(0);c===`
629
+ `?l+="\\n":c===" "?l+="\\t":c==="\\"?l+="\\\\":c==="'"?l+="'":c==='"'?l+='"':f<32||f===127?f<256?l+=`\\x${f.toString(16).padStart(2,"0")}`:l+=`\\u${f.toString(16).padStart(4,"0")}`:l+=c}return`$'${l}'`}return o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function br(e,t,s){if(!e.state.options.xtrace)return"";let n=await vr(e),r=[t,...s],i=Gi(r);return`${n}${i}
630
+ `}async function Er(e,t,s){return e.state.options.xtrace?`${await vr(e)}${t}=${s}
631
+ `:""}async function $r(e,t,s){let n=t.timed?performance.now():0,r="",i=L,o=0,a=[],l=t.commands.length>1,c=e.state.lastArg;for(let u=0;u<t.commands.length;u++){let d=t.commands[u],h=u===t.commands.length-1;l&&(e.state.lastArg="");let p=l&&(!h||!e.state.shoptOptions.lastpipe)?{...e.state.env}:null,w;try{w=await s(d,r)}catch(b){if(b instanceof st)w={stdout:b.stdout,stderr:b.stderr,exitCode:1};else if(b instanceof z&&t.commands.length>1)w={stdout:b.stdout,stderr:b.stderr,exitCode:b.exitCode};else if(b instanceof oe&&t.commands.length>1)w={stdout:b.stdout,stderr:b.stderr,exitCode:b.exitCode};else throw p&&(e.state.env=p),b}p&&(e.state.env=p),a.push(w.exitCode),w.exitCode!==0&&(o=w.exitCode),h?i=w:t.pipeStderr?.[u]??!1?(r=w.stderr+w.stdout,i={stdout:"",stderr:"",exitCode:w.exitCode}):(r=w.stdout,i={stdout:"",stderr:w.stderr,exitCode:w.exitCode})}if(t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let u of Object.keys(e.state.env))u.startsWith("PIPESTATUS_")&&delete e.state.env[u];for(let u=0;u<a.length;u++)e.state.env[`PIPESTATUS_${u}`]=String(a[u]);e.state.env.PIPESTATUS__length=String(a.length)}if(e.state.options.pipefail&&o!==0&&(i={...i,exitCode:o}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let d=(performance.now()-n)/1e3,h=Math.floor(d/60),m=d%60,p;t.timePosix?p=`real ${d.toFixed(2)}
632
+ user 0.00
633
+ sys 0.00
634
+ `:p=`
635
+ real ${`${h}m${m.toFixed(3)}s`}
636
+ user 0m0.000s
637
+ sys 0m0.000s
638
+ `,i={...i,stderr:i.stderr+p}}return l&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=c),i}async function Sr(e,t){let s={},n="";for(let r of t.assignments){let i=r.name;if(r.array){let f=await Ki(e,t,i,r.array,r.append,s);if(f.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:f.error};if(n+=f.xtraceOutput,f.continueToNext)continue}let o=r.value?await T(e,r.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:P("",`bash: ${i}: bad array subscript
639
+ `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let f=await to(e,t,l[1],l[2],o,r.append,s);if(f.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:f.error};if(f.continueToNext)continue}let c=await no(e,t,i,o,r.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:c.error};n+=c.xtraceOutput,c.continueToNext}return{continueToNext:!1,xtraceOutput:n,tempAssignments:s}}async function Ki(e,t,s,n,r,i){let o="";if(/\[.+\]$/.test(s))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: cannot assign list to array member
640
+ `,1)};if(ae(e,s)){let f=Xs(e,s);if(f===void 0||f==="")throw new z(1,"","");let u=Pe(e,s);if(u&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(u))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: cannot assign list to array member
641
+ `,1)}}if(Oe(e,s)){if(t.name)return o+=`bash: ${s}: readonly variable
642
+ `,{continueToNext:!0,xtraceOutput:o};let f=K(e,s);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let a=e.state.associativeArrays?.has(s),l=Yi(n),c=()=>{let f=`${s}_`;for(let u of Object.keys(e.state.env))u.startsWith(f)&&!u.includes("__")&&delete e.state.env[u];delete e.state.env[s]};if(a&&l?await Qi(e,t,s,n,r,c,f=>{o+=f}):l?await Ji(e,s,n,r,c):await eo(e,s,n,r,c),t.name){i[s]=e.state.env[s];let u=`(${n.map(d=>ot(d)).join(" ")})`;e.state.env[s]=u}return{continueToNext:!0,xtraceOutput:o}}function Yi(e){return e.some(t=>{if(t.parts.length>=2){let s=t.parts[0],n=t.parts[1];if(s.type!=="Glob"||!s.pattern.startsWith("["))return!1;if(s.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(t.parts.length<3)return!1;let r=t.parts[2];return r.type!=="Literal"?!1:r.value.startsWith("]=")||r.value.startsWith("]+=")}return n.type!=="Literal"?!1:n.value.startsWith("]")?n.value.startsWith("]=")||n.value.startsWith("]+="):s.pattern.endsWith("]")?n.value.startsWith("=")||n.value.startsWith("+="):!1}return!1})}async function Qi(e,t,s,n,r,i,o){let a=[];for(let l of n){let c=Ft(l);if(c){let{key:f,valueParts:u,append:d}=c,h;u.length>0?h=await T(e,{type:"Word",parts:u}):h="",h=H(e,h),a.push({type:"keyed",key:f,value:h,append:d})}else{let f=await T(e,l);a.push({type:"invalid",expandedValue:f})}}r||i();for(let l of a)if(l.type==="keyed")if(l.append){let c=e.state.env[`${s}_${l.key}`]??"";e.state.env[`${s}_${l.key}`]=c+l.value}else e.state.env[`${s}_${l.key}`]=l.value;else{let c=t.line??e.state.currentLine??1;o(`bash: line ${c}: ${s}: ${l.expandedValue}: must use subscript when assigning associative array
643
+ `)}}async function Ji(e,t,s,n,r){let i=[];for(let a of s){let l=Ft(a);if(l){let{key:c,valueParts:f,append:u}=l,d;f.length>0?d=await T(e,{type:"Word",parts:f}):d="",d=H(e,d),i.push({type:"keyed",indexExpr:c,value:d,append:u})}else{let c=await pe(e,a);i.push({type:"non-keyed",values:c.values})}}n||r();let o=0;for(let a of i)if(a.type==="keyed"){let l;try{let c=new W,f=Z(c,a.indexExpr);l=await V(e,f.expression,!1)}catch{if(/^-?\d+$/.test(a.indexExpr))l=Number.parseInt(a.indexExpr,10);else{let c=e.state.env[a.indexExpr];l=c?Number.parseInt(c,10):0,Number.isNaN(l)&&(l=0)}}if(a.append){let c=e.state.env[`${t}_${l}`]??"";e.state.env[`${t}_${l}`]=c+a.value}else e.state.env[`${t}_${l}`]=a.value;o=l+1}else for(let l of a.values)e.state.env[`${t}_${o++}`]=l}async function eo(e,t,s,n,r){let i=[];for(let a of s){let l=await pe(e,a);i.push(...l.values)}let o=0;if(n){let a=fe(e,t);if(a.length>0)o=Math.max(...a.map(([c])=>typeof c=="number"?c:0))+1;else if(e.state.env[t]!==void 0){let l=e.state.env[t];e.state.env[`${t}_0`]=l,delete e.state.env[t],o=1}}else r();for(let a=0;a<i.length;a++)e.state.env[`${t}_${o+a}`]=i[a];n||(e.state.env[`${t}__length`]=String(i.length))}async function to(e,t,s,n,r,i,o){let a=s;if(ae(e,s)){let u=Pe(e,s);if(u&&u!==s){if(u.includes("["))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: \`${u}': not a valid identifier
644
+ `,1)};a=u}}if(Oe(e,a)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let u=K(e,a);if(u)return{continueToNext:!1,xtraceOutput:"",error:u}}let l=e.state.associativeArrays?.has(a),c;if(l)c=await Ar(e,a,n);else{let u=await so(e,a,n);if(u.error)return{continueToNext:!1,xtraceOutput:"",error:u.error};c=`${a}_${u.index}`}let f=i?(e.state.env[c]||"")+r:r;if(t.name)o[c]=e.state.env[c],e.state.env[c]=f;else{let u=Fe(e,a);if(u!==void 0&&u===e.state.callDepth&&e.state.localScopes.length>0){let d=e.state.localScopes[e.state.localScopes.length-1];d.has(c)||d.set(c,e.state.env[c])}e.state.env[c]=f}return{continueToNext:!0,xtraceOutput:""}}async function Ar(e,t,s){let n;if(s.startsWith("'")&&s.endsWith("'"))n=s.slice(1,-1);else if(s.startsWith('"')&&s.endsWith('"')){let r=s.slice(1,-1),o=new W().parseWordFromString(r,!0,!1);n=await T(e,o)}else if(s.includes("$")){let i=new W().parseWordFromString(s,!1,!1);n=await T(e,i)}else n=s;return`${t}_${n}`}async function so(e,t,s){let n=s;s.startsWith('"')&&s.endsWith('"')&&s.length>=2&&(n=s.slice(1,-1));let r;if(/^-?\d+$/.test(n))r=Number.parseInt(n,10);else{try{let i=new W,o=Z(i,n);r=await V(e,o.expression,!1)}catch(i){if(i instanceof ke){let l=`bash: line ${e.state.currentLine}: ${s}: ${i.message}
645
+ `;if(i.fatal)throw new z(1,"",l);return{index:0,error:P("",l,1)}}let o=e.state.env[s];r=o?Number.parseInt(o,10):0}Number.isNaN(r)&&(r=0)}if(r<0){let i=fe(e,t);if(i.length===0){let a=e.state.currentLine;return{index:0,error:P("",`bash: line ${a}: ${t}[${s}]: bad array subscript
646
+ `,1)}}if(r=Math.max(...i.map(([a])=>typeof a=="number"?a:0))+1+r,r<0){let a=e.state.currentLine;return{index:0,error:P("",`bash: line ${a}: ${t}[${s}]: bad array subscript
647
+ `,1)}}}return{index:r}}async function no(e,t,s,n,r,i){let o="",a=s,l=null;if(ae(e,s)){let u=Ks(e,s,n);if(u===void 0)return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: circular name reference
648
+ `,1)};if(u===null)return{continueToNext:!0,xtraceOutput:""};a=u;let d=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(l={arrayName:d[1],subscriptExpr:d[2]},a=d[1])}if(Oe(e,a)){if(t.name)return o+=`bash: ${a}: readonly variable
649
+ `,{continueToNext:!0,xtraceOutput:o};let u=K(e,a);if(u)return{continueToNext:!1,xtraceOutput:"",error:u}}let c;if(Ke(e,a))try{let u=new W;if(r){let h=`(${e.state.env[a]||"0"}) + (${n})`,m=Z(u,h);c=String(await V(e,m.expression))}else{let d=Z(u,n);c=String(await V(e,d.expression))}}catch{c="0"}else{let{isArray:u}=await import("./chunks/expansion-RIGCFEMA.js"),d=u(e,a)?`${a}_0`:a;c=r?(e.state.env[d]||"")+n:n}c=We(e,a,c),o+=await Er(e,a,c);let f=a;if(l)f=await ro(e,l);else{let{isArray:u}=await import("./chunks/expansion-RIGCFEMA.js");u(e,a)&&(f=`${a}_0`)}return t.name?(i[f]=e.state.env[f],e.state.env[f]=c):(e.state.env[f]=c,e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(a)),e.state.tempEnvBindings?.some(u=>u.has(a))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(a))),{continueToNext:!1,xtraceOutput:o}}async function ro(e,t){let{arrayName:s,subscriptExpr:n}=t;if(e.state.associativeArrays?.has(s))return Ar(e,s,n);let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else{try{let o=new W,a=Z(o,n);i=await V(e,a.expression,!1)}catch{let o=e.state.env[n];i=o?Number.parseInt(o,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let o=fe(e,s);o.length>0&&(i=Math.max(...o.map(l=>l[0]))+1+i)}return`${s}_${i}`}async function Pr(e,t,s,n){let r=await ye(e,t.redirections);if(r)return r;let i={...e.state.env},o=e.state.cwd,a={...e.state.options},l=e.state.localScopes,c=e.state.localVarStack,f=e.state.localVarDepth,u=e.state.fullyUnsetLocals;if(e.state.localScopes=l.map(v=>new Map(v)),c){e.state.localVarStack=new Map;for(let[v,_]of c.entries())e.state.localVarStack.set(v,_.map(k=>({...k})))}f&&(e.state.localVarDepth=new Map(f)),u&&(e.state.fullyUnsetLocals=new Map(u));let d=e.state.loopDepth,h=e.state.parentHasLoopContext;e.state.parentHasLoopContext=d>0,e.state.loopDepth=0;let m=e.state.lastArg,p=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let w=e.state.groupStdin;s&&(e.state.groupStdin=s);let b="",$="",C=0,y=()=>{e.state.env=i,e.state.cwd=o,e.state.options=a,e.state.localScopes=l,e.state.localVarStack=c,e.state.localVarDepth=f,e.state.fullyUnsetLocals=u,e.state.loopDepth=d,e.state.parentHasLoopContext=h,e.state.groupStdin=w,e.state.bashPid=p,e.state.lastArg=m};try{for(let v of t.body){let _=await n(v);b+=_.stdout,$+=_.stderr,C=_.exitCode}}catch(v){if(y(),v instanceof te)throw v;if(v instanceof Se){b+=v.stdout,$+=v.stderr;let k=P(b,$,0);return j(e,k,t.redirections)}if(v instanceof re||v instanceof ie){b+=v.stdout,$+=v.stderr;let k=P(b,$,0);return j(e,k,t.redirections)}if(v instanceof z){b+=v.stdout,$+=v.stderr;let k=P(b,$,v.exitCode);return j(e,k,t.redirections)}if(v instanceof se){b+=v.stdout,$+=v.stderr;let k=P(b,$,v.exitCode);return j(e,k,t.redirections)}if(v instanceof oe){let k=P(b+v.stdout,$+v.stderr,v.exitCode);return j(e,k,t.redirections)}let _=P(b,`${$}${ge(v)}
650
+ `,1);return j(e,_,t.redirections)}y();let g=P(b,$,C);return j(e,g,t.redirections)}async function _r(e,t,s,n){let r="",i="",o=0,a=await At(e,t.redirections);if(a)return a;let l=s;for(let u of t.redirections)if((u.operator==="<<"||u.operator==="<<-")&&u.target.type==="HereDoc"){let d=u.target,h=await T(e,d.content);d.stripTabs&&(h=h.split(`
651
+ `).map(p=>p.replace(/^\t+/,"")).join(`
652
+ `));let m=u.fd??0;m!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(m,h)):l=h}else if(u.operator==="<<<"&&u.target.type==="Word")l=`${await T(e,u.target)}
653
+ `;else if(u.operator==="<"&&u.target.type==="Word")try{let d=await T(e,u.target),h=e.fs.resolvePath(e.state.cwd,d);l=await e.fs.readFile(h)}catch{let d=await T(e,u.target);return P("",`bash: ${d}: No such file or directory
654
+ `,1)}let c=e.state.groupStdin;l&&(e.state.groupStdin=l);try{for(let u of t.body){let d=await n(u);r+=d.stdout,i+=d.stderr,o=d.exitCode}}catch(u){if(e.state.groupStdin=c,u instanceof te)throw u;if(rt(u)||u instanceof oe||u instanceof z)throw u.prependOutput(r,i),u;return P(r,`${i}${ge(u)}
655
+ `,1)}e.state.groupStdin=c;let f=P(r,i,o);return j(e,f,t.redirections)}async function Nr(e,t,s,n,r){let i;try{i=await e.fs.readFile(t)}catch{return S(`bash: ${t}: No such file or directory
656
+ `,127)}if(i.startsWith("#!")){let w=i.indexOf(`
657
+ `);w!==-1&&(i=i.slice(w+1))}let o={...e.state.env},a=e.state.cwd,l={...e.state.options},c=e.state.loopDepth,f=e.state.parentHasLoopContext,u=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,m=e.state.currentSource;e.state.parentHasLoopContext=c>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,n&&(e.state.groupStdin=n),e.state.currentSource=t,e.state.env[0]=t,e.state.env["#"]=String(s.length),e.state.env["@"]=s.join(" "),e.state.env["*"]=s.join(" ");for(let w=0;w<s.length&&w<9;w++)e.state.env[String(w+1)]=s[w];for(let w=s.length+1;w<=9;w++)delete e.state.env[String(w)];let p=()=>{e.state.env=o,e.state.cwd=a,e.state.options=l,e.state.loopDepth=c,e.state.parentHasLoopContext=f,e.state.lastArg=u,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=m};try{let b=new W().parse(i),$=await r(b);return p(),$}catch(w){if(p(),w instanceof z||w instanceof te)throw w;if(w.name==="ParseException")return S(`bash: ${t}: ${w.message}
658
+ `);throw w}}var et=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace}}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,n=new Set;if(t)for(let i of t)n.add(i);if(s)for(let i of s)n.add(i);if(n.size===0)return{};let r={};for(let i of n){let o=this.ctx.state.env[i];o!==void 0&&(r[i]=o)}return r}async executeScript(t){let s="",n="",r=0;for(let i of t.statements)try{let o=await this.executeStatement(i);s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r)}catch(o){if(o instanceof z)throw o.prependOutput(s,n),o;if(o instanceof ce)return s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(o instanceof te)throw o;if(o instanceof oe)return s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(o instanceof zs)return s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(o instanceof st)return s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(o instanceof ke){s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r);continue}if(o instanceof Vs){s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r);continue}if(o instanceof re||o instanceof ie){if(this.ctx.state.loopDepth>0)throw o.prependOutput(s,n),o;s+=o.stdout,n+=o.stderr;continue}throw o instanceof se&&o.prependOutput(s,n),o}return{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}}}async executeUserScript(t,s,n=""){return Nr(this.ctx,t,s,n,r=>this.executeScript(r))}async executeStatement(t){if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&$e(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new it(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return L;this.ctx.state.errexitSafe=!1;let s="",n="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(n+=`${t.sourceText}
659
+ `);let r=0,i=-1,o=!1;for(let c=0;c<t.pipelines.length;c++){let f=t.pipelines[c],u=c>0?t.operators[c-1]:null;if(u==="&&"&&r!==0||u==="||"&&r===0)continue;let d=await this.executePipeline(f);s+=d.stdout,n+=d.stderr,r=d.exitCode,i=c,o=f.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r)}let a=i<t.pipelines.length-1,l=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=a||o||l,this.ctx.state.options.errexit&&r!==0&&i===t.pipelines.length-1&&!o&&!this.ctx.state.inCondition&&!l)throw new oe(r,s,n);return P(s,n,r)}async executePipeline(t){return $r(this.ctx,t,(s,n)=>this.executeCommand(s,n))}async executeCommand(t,s){switch(t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return ur(this.ctx,t);case"For":return dr(this.ctx,t);case"CStyleFor":return hr(this.ctx,t);case"While":return pr(this.ctx,t,s);case"Until":return mr(this.ctx,t);case"Case":return yr(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return In(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return L}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(n){if(n instanceof nt)return S(n.stderr);throw n}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let y=t,g=100;for(;g>0;){let v=this.expandAlias(y);if(v===y)break;y=v,g--}this.aliasExpansionStack.clear(),y!==t&&(t=y)}this.ctx.state.expansionStderr="";let n=await Sr(this.ctx,t);if(n.error)return n.error;let r=n.tempAssignments,i=n.xtraceOutput;if(!t.name){if(t.redirections.length>0){let g=await ye(this.ctx,t.redirections);if(g)return g;let v=P("",i,0);return j(this.ctx,v,t.redirections)}this.ctx.state.lastArg="";let y=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",P("",y,this.ctx.state.lastExitCode)}let o=t.name&&Fs(t.name,["local","declare","typeset","export","readonly"]),a=Object.keys(r);if(a.length>0&&!o){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let y of a)this.ctx.state.tempExportedVars.add(y)}let l=await At(this.ctx,t.redirections);if(l){for(let[y,g]of Object.entries(r))g===void 0?delete this.ctx.state.env[y]:this.ctx.state.env[y]=g;return l}let c=-1;for(let y of t.redirections){if((y.operator==="<<"||y.operator==="<<-")&&y.target.type==="HereDoc"){let g=y.target,v=await T(this.ctx,g.content);g.stripTabs&&(v=v.split(`
660
+ `).map(k=>k.replace(/^\t+/,"")).join(`
661
+ `));let _=y.fd??0;_!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),this.ctx.state.fileDescriptors.set(_,v)):s=v;continue}if(y.operator==="<<<"&&y.target.type==="Word"){s=`${await T(this.ctx,y.target)}
662
+ `;continue}if(y.operator==="<"&&y.target.type==="Word")try{let g=await T(this.ctx,y.target),v=this.ctx.fs.resolvePath(this.ctx.state.cwd,g);s=await this.ctx.fs.readFile(v)}catch{let g=await T(this.ctx,y.target);for(let[v,_]of Object.entries(r))_===void 0?delete this.ctx.state.env[v]:this.ctx.state.env[v]=_;return S(`bash: ${g}: No such file or directory
663
+ `)}if(y.operator==="<&"&&y.target.type==="Word"){let g=await T(this.ctx,y.target),v=Number.parseInt(g,10);if(!Number.isNaN(v)&&this.ctx.state.fileDescriptors){let _=this.ctx.state.fileDescriptors.get(v);if(_!==void 0)if(_.startsWith("__rw__:")){let k=wr(_);k&&(s=k.content.slice(k.position),c=v)}else _.startsWith("__file__:")||_.startsWith("__file_append__:")||(s=_)}}}let f=await T(this.ctx,t.name),u=[],d=[];if(Fs(t.name,["local","declare","typeset","export","readonly"])&&(f==="local"||f==="declare"||f==="typeset"||f==="export"||f==="readonly"))for(let y of t.args){let g=await yn(this.ctx,y);if(g)u.push(g),d.push(!0);else{let v=await wn(this.ctx,y);if(v!==null)u.push(v),d.push(!0);else{let _=await pe(this.ctx,y);for(let k of _.values)u.push(k),d.push(_.quoted)}}}else for(let y of t.args){let g=await pe(this.ctx,y);for(let v of g.values)u.push(v),d.push(g.quoted)}if(!f){if(t.name.parts.every(g=>g.type==="CommandSubstitution"||g.type==="ParameterExpansion"||g.type==="ArithmeticExpansion")){if(u.length>0){let g=u.shift();return d.shift(),await this.runCommand(g,u,d,s,!1,!1,c)}return P("","",this.ctx.state.lastExitCode)}return S(`bash: : command not found
664
+ `,127)}if(f==="exec"&&(u.length===0||u[0]==="--")){for(let y of t.redirections){if(y.target.type==="HereDoc"||y.fdVariable)continue;let g=await T(this.ctx,y.target),v=y.fd??(y.operator==="<"||y.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),y.operator){case">":case">|":{let _=this.ctx.fs.resolvePath(this.ctx.state.cwd,g);await this.ctx.fs.writeFile(_,"","utf8"),this.ctx.state.fileDescriptors.set(v,`__file__:${_}`);break}case">>":{let _=this.ctx.fs.resolvePath(this.ctx.state.cwd,g);this.ctx.state.fileDescriptors.set(v,`__file_append__:${_}`);break}case"<":{let _=this.ctx.fs.resolvePath(this.ctx.state.cwd,g);try{let k=await this.ctx.fs.readFile(_);this.ctx.state.fileDescriptors.set(v,k)}catch{return S(`bash: ${g}: No such file or directory
665
+ `)}break}case"<>":{let _=this.ctx.fs.resolvePath(this.ctx.state.cwd,g);try{let k=await this.ctx.fs.readFile(_);this.ctx.state.fileDescriptors.set(v,`__rw__:${_.length}:${_}:0:${k}`)}catch{await this.ctx.fs.writeFile(_,"","utf8"),this.ctx.state.fileDescriptors.set(v,`__rw__:${_.length}:${_}:0:`)}break}case">&":{if(g==="-")this.ctx.state.fileDescriptors.delete(v);else if(g.endsWith("-")){let _=g.slice(0,-1),k=Number.parseInt(_,10);if(!Number.isNaN(k)){let I=this.ctx.state.fileDescriptors.get(k);I!==void 0?this.ctx.state.fileDescriptors.set(v,I):this.ctx.state.fileDescriptors.set(v,`__dupout__:${k}`),this.ctx.state.fileDescriptors.delete(k)}}else{let _=Number.parseInt(g,10);Number.isNaN(_)||this.ctx.state.fileDescriptors.set(v,`__dupout__:${_}`)}break}case"<&":{if(g==="-")this.ctx.state.fileDescriptors.delete(v);else if(g.endsWith("-")){let _=g.slice(0,-1),k=Number.parseInt(_,10);if(!Number.isNaN(k)){let I=this.ctx.state.fileDescriptors.get(k);I!==void 0?this.ctx.state.fileDescriptors.set(v,I):this.ctx.state.fileDescriptors.set(v,`__dupin__:${k}`),this.ctx.state.fileDescriptors.delete(k)}}else{let _=Number.parseInt(g,10);Number.isNaN(_)||this.ctx.state.fileDescriptors.set(v,`__dupin__:${_}`)}break}}}for(let[y,g]of Object.entries(r))g===void 0?delete this.ctx.state.env[y]:this.ctx.state.env[y]=g;if(this.ctx.state.tempExportedVars)for(let y of Object.keys(r))this.ctx.state.tempExportedVars.delete(y);return L}let m=await br(this.ctx,f,u);Object.keys(r).length>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(Object.entries(r))));let p,w=null;try{p=await this.runCommand(f,u,d,s,!1,!1,c)}catch(y){if(y instanceof re||y instanceof ie)w=y,p=L;else throw y}let b=i+m;if(b&&(p={...p,stderr:b+p.stderr}),p=await j(this.ctx,p,t.redirections),w)throw w;if(u.length>0){let y=u[u.length-1];if((f==="declare"||f==="local"||f==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(y)){let g=y.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);g&&(y=g[1])}this.ctx.state.lastArg=y}else this.ctx.state.lastArg=f;let $=Dn(f)&&f!=="unset"&&f!=="eval";if(!this.ctx.state.options.posix||!$)for(let[y,g]of Object.entries(r))this.ctx.state.fullyUnsetLocals?.has(y)||(g===void 0?delete this.ctx.state.env[y]:this.ctx.state.env[y]=g);if(this.ctx.state.tempExportedVars)for(let y of Object.keys(r))this.ctx.state.tempExportedVars.delete(y);return Object.keys(r).length>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(p={...p,stderr:this.ctx.state.expansionStderr+p.stderr},this.ctx.state.expansionStderr=""),p}async runCommand(t,s,n,r,i=!1,o=!1,a=-1){let l={ctx:this.ctx,runCommand:(f,u,d,h,m,p,w)=>this.runCommand(f,u,d,h,m,p,w),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(f,u,d)=>this.executeUserScript(f,u,d)},c=await cr(l,t,s,n,r,i,o,a);return c!==null?c:fr(l,t,s,r,o)}aliasExpansionStack=new Set;expandAlias(t){return qt(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return Dt(this.ctx,t)}async executeSubshell(t,s=""){return Pr(this.ctx,t,s,n=>this.executeStatement(n))}async executeGroup(t,s=""){return _r(this.ctx,t,s,n=>this.executeStatement(n))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await ye(this.ctx,t.redirections);if(s)return s;try{let n=await V(this.ctx,t.expression.expression),r=q(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),j(this.ctx,r,t.redirections)}catch(n){let r=S(`bash: arithmetic expression: ${n.message}
666
+ `);return j(this.ctx,r,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await ye(this.ctx,t.redirections);if(s)return s;try{let n=await _e(this.ctx,t.expression),r=q(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),j(this.ctx,r,t.redirections)}catch(n){let r=n instanceof ke?1:2,i=S(`bash: conditional expression: ${n.message}
667
+ `,r);return j(this.ctx,i,t.redirections)}}};var Ce={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3};function Cr(e){return e?{maxCallDepth:e.maxCallDepth??Ce.maxCallDepth,maxCommandCount:e.maxCommandCount??Ce.maxCommandCount,maxLoopIterations:e.maxLoopIterations??Ce.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??Ce.maxAwkIterations,maxSedIterations:e.maxSedIterations??Ce.maxSedIterations,maxJqIterations:e.maxJqIterations??Ce.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??Ce.maxSqliteTimeoutMs}:{...Ce}}function kr(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function io(e){let t=kr(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function oo(e,t){let s=kr(e);if(!s)return!1;let n=io(t);return!n||s.origin!==n.origin?!1:n.pathPrefix==="/"||n.pathPrefix===""?!0:s.pathname.startsWith(n.pathPrefix)}function Ms(e,t){return!t||t.length===0?!1:t.some(s=>oo(e,s))}var ze=class extends Error{constructor(t){super(`Network access denied: URL not in allow-list: ${t}`),this.name="NetworkAccessDeniedError"}},Ve=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},Be=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},It=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}};var ao=20,lo=3e4,co=["GET","HEAD"],fo=new Set(["GET","HEAD","OPTIONS"]),uo=new Set([301,302,303,307,308]);function Ws(e){let t=e.maxRedirects??ao,s=e.timeoutMs??lo,n=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??co;function r(a){if(!e.dangerouslyAllowFullInternetAccess&&!Ms(a,e.allowedUrlPrefixes??[]))throw new ze(a)}function i(a){if(e.dangerouslyAllowFullInternetAccess)return;let l=a.toUpperCase();if(!n.includes(l))throw new It(l,n)}async function o(a,l={}){let c=l.method?.toUpperCase()??"GET";r(a),i(c);let f=a,u=0,d=l.followRedirects??!0,h=l.timeoutMs!==void 0?Math.min(l.timeoutMs,s):s;for(;;){let m=new AbortController,p=setTimeout(()=>m.abort(),h);try{let w={method:c,headers:l.headers,signal:m.signal,redirect:"manual"};l.body&&!fo.has(c)&&(w.body=l.body);let b=await fetch(f,w);if(uo.has(b.status)&&d){let $=b.headers.get("location");if(!$)return await Or(b,f);let C=new URL($,f).href;if(!e.dangerouslyAllowFullInternetAccess&&!Ms(C,e.allowedUrlPrefixes??[]))throw new Be(C);if(u++,u>t)throw new Ve(t);f=C;continue}return await Or(b,f)}finally{clearTimeout(p)}}}return o}async function Or(e,t){let s={};return e.headers.forEach((n,r)=>{s[r.toLowerCase()]=n}),{status:e.status,statusText:e.statusText,headers:s,body:await e.text(),url:t}}var tt=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;state;constructor(t={}){let s=t.fs??new Ee(t.files);this.fs=s,this.useDefaultLayout=!t.cwd&&!t.files;let n=t.cwd||(this.useDefaultLayout?"/home/user":"/"),r={HOME:this.useDefaultLayout?"/home/user":"/",PATH:"/usr/bin:/bin",IFS:`
668
+ `,OSTYPE:"linux-gnu",MACHTYPE:"x86_64-pc-linux-gnu",HOSTTYPE:"x86_64",HOSTNAME:"localhost",PWD:n,OLDPWD:n,OPTIND:"1",...t.env};if(this.limits=Cr({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}}),t.network&&(this.secureFetch=Ws(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.state={env:r,cwd:n,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,bashPid:process.pid,nextVirtualPid:process.pid+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.SHELLOPTS=jt(this.state.options),this.state.env.BASHOPTS=Ht(this.state.shoptOptions),fn(s,this.useDefaultLayout),n!=="/"&&s instanceof Ee)try{s.mkdirSync(n,{recursive:!0})}catch{}for(let i of on(t.commands))this.registerCommand(i);if(t.network)for(let i of an())this.registerCommand(i);if(t.customCommands)for(let i of t.customCommands)ln(i)?this.registerCommand(cn(i)):this.registerCommand(i)}registerCommand(t){this.commands.set(t.name,t);let s=this.fs;if(typeof s.writeFileSync=="function"){let n=`#!/bin/bash
669
+ # Built-in command: ${t.name}
670
+ `;try{s.writeFileSync(`/bin/${t.name}`,n)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,n)}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}async exec(t,s){if(this.state.callDepth===0&&(this.state.commandCount=0),this.state.commandCount++,this.state.commandCount>this.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option.
671
+ `,exitCode:1,env:{...this.state.env,...s?.env}};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:{...this.state.env,...s?.env}};this.logger?.info("exec",{command:t});let n=s?.cwd??this.state.cwd,r,i=n;if(s?.cwd)if(s.env&&"PWD"in s.env)r=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{r=await this.fs.realpath(n),i=r}catch{r=n}else r=n;let o={...this.state,env:{...this.state.env,...s?.env,...r!==void 0?{PWD:r}:{}},cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable},a=t;s?.rawScript||(a=ho(t));try{let l=de(a),c={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn},u=await new et(c,o).executeScript(l);return this.logResult(u)}catch(l){if(l instanceof z)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode,env:{...this.state.env,...s?.env}});if(l instanceof ce)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode,env:{...this.state.env,...s?.env}});if(l instanceof ke)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:1,env:{...this.state.env,...s?.env}});if(l instanceof te)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:te.EXIT_CODE,env:{...this.state.env,...s?.env}});if(l.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${l.message}
672
+ `,exitCode:2,env:{...this.state.env,...s?.env}});if(l instanceof Hs)return this.logResult({stdout:"",stderr:`bash: ${l.message}
673
+ `,exitCode:2,env:{...this.state.env,...s?.env}});if(l instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${l.message}
674
+ `,exitCode:1,env:{...this.state.env,...s?.env}});throw l}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,s){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),s)}getCwd(){return this.state.cwd}getEnv(){return{...this.state.env}}};function ho(e){let t=e.split(`
675
+ `),s=[],n=[];for(let r=0;r<t.length;r++){let i=t[r];if(n.length>0){let l=n[n.length-1];if((l.stripTabs?i.replace(/^\t+/,""):i)===l.delimiter){s.push(i.trimStart()),n.pop();continue}s.push(i);continue}let o=i.trimStart();s.push(o);let a=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let l of o.matchAll(a)){let c=l[1]==="-",f=l[3];n.push({delimiter:f,stripTabs:c})}}return s.join(`
676
+ `)}var Rt=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new Ee,t?.mounts)for(let{mountPoint:s,filesystem:n}of t.mounts)this.mount(s,n)}mount(t,s){this.validateMountPath(t);let n=this.normalizePath(t);this.validateMount(n),this.mounts.set(n,{mountPoint:n,filesystem:s})}unmount(t){let s=this.normalizePath(t);if(!this.mounts.has(s))throw new Error(`No filesystem mounted at '${t}'`);this.mounts.delete(s)}getMounts(){return Array.from(this.mounts.values()).map(t=>({mountPoint:t.mountPoint,filesystem:t.filesystem}))}isMountPoint(t){let s=this.normalizePath(t);return this.mounts.has(s)}validateMountPath(t){let s=t.split("/");for(let n of s)if(n==="."||n==="..")throw new Error(`Invalid mount point '${t}': contains '.' or '..' segments`)}validateMount(t){if(t==="/")throw new Error("Cannot mount at root '/'");for(let s of this.mounts.keys())if(s!==t){if(t.startsWith(`${s}/`))throw new Error(`Cannot mount at '${t}': inside existing mount '${s}'`);if(s.startsWith(`${t}/`))throw new Error(`Cannot mount at '${t}': would contain existing mount '${s}'`)}}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`}routePath(t){let s=this.normalizePath(t),n=null,r=0;for(let i of this.mounts.values()){let o=i.mountPoint;if(s===o)return{fs:i.filesystem,relativePath:"/"};s.startsWith(`${o}/`)&&o.length>r&&(n=i,r=o.length)}if(n){let i=s.slice(r);return{fs:n.filesystem,relativePath:i||"/"}}return{fs:this.baseFs,relativePath:s}}getChildMountPoints(t){let s=this.normalizePath(t),n=s==="/"?"/":`${s}/`,r=[];for(let i of this.mounts.keys())if(i.startsWith(n)){let a=i.slice(n.length).split("/")[0];a&&!r.includes(a)&&r.push(a)}return r}async readFile(t,s){let{fs:n,relativePath:r}=this.routePath(t);return n.readFile(r,s)}async readFileBuffer(t){let{fs:s,relativePath:n}=this.routePath(t);return s.readFileBuffer(n)}async writeFile(t,s,n){let{fs:r,relativePath:i}=this.routePath(t);return r.writeFile(i,s,n)}async appendFile(t,s,n){let{fs:r,relativePath:i}=this.routePath(t);return r.appendFile(i,s,n)}async exists(t){let s=this.normalizePath(t);if(this.mounts.has(s)||this.getChildMountPoints(s).length>0)return!0;let{fs:r,relativePath:i}=this.routePath(t);return r.exists(i)}async stat(t){let s=this.normalizePath(t),n=this.mounts.get(s);if(n)try{return await n.filesystem.stat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(s).length>0)try{return await this.baseFs.stat(s)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.stat(o)}async lstat(t){let s=this.normalizePath(t),n=this.mounts.get(s);if(n)try{return await n.filesystem.lstat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(s).length>0)try{return await this.baseFs.lstat(s)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.lstat(o)}async mkdir(t,s){let n=this.normalizePath(t);if(this.mounts.has(n)){if(s?.recursive)return;throw new Error(`EEXIST: directory already exists, mkdir '${t}'`)}if(this.getChildMountPoints(n).length>0&&s?.recursive)return;let{fs:i,relativePath:o}=this.routePath(t);return i.mkdir(o,s)}async readdir(t){let s=this.normalizePath(t),n=new Set,r=null,{fs:i,relativePath:o}=this.routePath(t);try{let l=await i.readdir(o);for(let c of l)n.add(c)}catch(l){let c=l.code,f=l.message||"";if(c!=="ENOENT"&&!f.includes("ENOENT"))throw l;r=l}let a=this.getChildMountPoints(s);for(let l of a)n.add(l);if(n.size===0&&r&&!this.mounts.has(s))throw r;return Array.from(n).sort()}async rm(t,s){let n=this.normalizePath(t);if(this.mounts.has(n))throw new Error(`EBUSY: mount point, cannot remove '${t}'`);if(this.getChildMountPoints(n).length>0)throw new Error(`EBUSY: contains mount points, cannot remove '${t}'`);let{fs:i,relativePath:o}=this.routePath(t);return i.rm(o,s)}async cp(t,s,n){let r=this.routePath(t),i=this.routePath(s);return r.fs===i.fs?r.fs.cp(r.relativePath,i.relativePath,n):this.crossMountCopy(t,s,n)}async mv(t,s){let n=this.normalizePath(t);if(this.mounts.has(n))throw new Error(`EBUSY: mount point, cannot move '${t}'`);let r=this.routePath(t),i=this.routePath(s);if(r.fs===i.fs)return r.fs.mv(r.relativePath,i.relativePath);await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=new Set;for(let s of this.baseFs.getAllPaths())t.add(s);for(let s of this.mounts.keys()){let n=s.split("/").filter(Boolean),r="";for(let o of n)r=`${r}/${o}`,t.add(r);let i=this.mounts.get(s);if(i)for(let o of i.filesystem.getAllPaths())o==="/"?t.add(s):t.add(`${s}${o}`)}return Array.from(t).sort()}async chmod(t,s){let n=this.normalizePath(t),r=this.mounts.get(n);if(r)return r.filesystem.chmod("/",s);let{fs:i,relativePath:o}=this.routePath(t);return i.chmod(o,s)}async symlink(t,s){let{fs:n,relativePath:r}=this.routePath(s);return n.symlink(t,r)}async link(t,s){let n=this.routePath(t),r=this.routePath(s);if(n.fs!==r.fs)throw new Error(`EXDEV: cross-device link not permitted, link '${t}' -> '${s}'`);return n.fs.link(n.relativePath,r.relativePath)}async readlink(t){let{fs:s,relativePath:n}=this.routePath(t);return s.readlink(n)}async realpath(t){let s=this.normalizePath(t);if(this.mounts.get(s))return s;let{fs:r,relativePath:i}=this.routePath(t),o=await r.realpath(i);for(let[a,l]of this.mounts)if(s===a||s.startsWith(`${a}/`))return o==="/"?a:`${a}${o}`;return o}async crossMountCopy(t,s,n){let r=await this.lstat(t);if(r.isFile){let i=await this.readFileBuffer(t);await this.writeFile(s,i),await this.chmod(s,r.mode)}else if(r.isDirectory){if(!n?.recursive)throw new Error(`cp: ${t} is a directory (not copied)`);await this.mkdir(s,{recursive:!0});let i=await this.readdir(t);for(let o of i){let a=t==="/"?`/${o}`:`${t}/${o}`,l=s==="/"?`/${o}`:`${s}/${o}`;await this.crossMountCopy(a,l,n)}}else if(r.isSymbolicLink){let i=await this.readlink(t);await this.symlink(i,s)}}async utimes(t,s,n){let{fs:r,relativePath:i}=this.routePath(t);return r.utimes(i,s,n)}};import*as G from"node:fs";import*as je from"node:path";var po="/home/user/project",He=class{root;mountPoint;readOnly;memory=new Map;deleted=new Set;constructor(t){this.root=je.resolve(t.root);let s=t.mountPoint??po;if(this.mountPoint=s==="/"?"/":s.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${s}`);if(this.readOnly=t.readOnly??!1,!G.existsSync(this.root))throw new Error(`OverlayFs root does not exist: ${this.root}`);if(!G.statSync(this.root).isDirectory())throw new Error(`OverlayFs root is not a directory: ${this.root}`);this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){let t=this.mountPoint.split("/").filter(Boolean),s="";for(let n of t)s+=`/${n}`,this.memory.has(s)||this.memory.set(s,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.memory.set("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}mkdirSync(t,s){let r=this.normalizePath(t).split("/").filter(Boolean),i="";for(let o of r)i+=`/${o}`,this.memory.has(i)||this.memory.set(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,s){let n=this.normalizePath(t),r=this.getDirname(n);r!=="/"&&this.mkdirSync(r);let i=s instanceof Uint8Array?s:new TextEncoder().encode(s);this.memory.set(n,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let s=this.normalizePath(t),n=this.getRelativeToMount(s);if(n===null)return null;let r=je.join(this.root,n),i=je.resolve(r);return!i.startsWith(this.root)&&i!==this.root.replace(/\/$/,"")?null:i}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.memory.has(s)||(this.ensureParentDirs(s),this.memory.set(s,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(s))}async existsInOverlay(t){let s=this.normalizePath(t);if(this.deleted.has(s))return!1;if(this.memory.has(s))return!0;let n=this.toRealPath(s);if(!n)return!1;try{return await G.promises.access(n),!0}catch{return!1}}async readFile(t,s){let n=await this.readFileBuffer(t),r=le(s);return Re(n,r)}async readFileBuffer(t,s=new Set){let n=this.normalizePath(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let o=this.resolveSymlink(n,r.target);return this.readFileBuffer(o,s)}if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return r.content}let i=this.toRealPath(n);if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let o=await G.promises.lstat(i);if(o.isSymbolicLink()){let l=await G.promises.readlink(i),c=this.resolveSymlink(n,l);return this.readFileBuffer(c,s)}if(o.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);let a=await G.promises.readFile(i);return new Uint8Array(a)}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${t}'`):o}}async writeFile(t,s,n){this.assertWritable(`write '${t}'`);let r=this.normalizePath(t);this.ensureParentDirs(r);let i=le(n),o=be(s,i);this.memory.set(r,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(r)}async appendFile(t,s,n){this.assertWritable(`append '${t}'`);let r=this.normalizePath(t),i=le(n),o=be(s,i),a;try{a=await this.readFileBuffer(r)}catch{a=new Uint8Array(0)}let l=new Uint8Array(a.length+o.length);l.set(a),l.set(o,a.length),this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:420,mtime:new Date}),this.deleted.delete(r)}async exists(t){return this.existsInOverlay(t)}async stat(t,s=new Set){let n=this.normalizePath(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let a=this.resolveSymlink(n,r.target);return this.stat(a,s)}let o=0;return r.type==="file"&&(o=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:o,mtime:r.mtime}}let i=this.toRealPath(n);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let o=await G.promises.stat(i);return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:!1,mode:o.mode,size:o.size,mtime:o.mtime}}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${t}'`):o}}async lstat(t){let s=this.normalizePath(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let n=this.memory.get(s);if(n){if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime};let i=0;return n.type==="file"&&(i=n.content.length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:i,mtime:n.mtime}}let r=this.toRealPath(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await G.promises.lstat(r);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${t}'`):i}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}async mkdir(t,s){this.assertWritable(`mkdir '${t}'`);let n=this.normalizePath(t);if(await this.existsInOverlay(n)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=this.dirname(n);if(i!=="/"&&!await this.existsInOverlay(i))if(s?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.memory.set(n,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(n)}async readdirCore(t,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Map,r=new Set,i=s==="/"?"/":`${s}/`;for(let a of this.deleted)if(a.startsWith(i)){let l=a.slice(i.length),c=l.split("/")[0];c&&!l.includes("/",c.length)&&r.add(c)}for(let[a,l]of this.memory)if(a!==s&&a.startsWith(i)){let c=a.slice(i.length),f=c.split("/")[0];f&&!r.has(f)&&!c.includes("/",1)&&n.set(f,{name:f,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let o=this.toRealPath(s);if(o)try{let a=await G.promises.readdir(o,{withFileTypes:!0});for(let l of a)!r.has(l.name)&&!n.has(l.name)&&n.set(l.name,{name:l.name,isFile:l.isFile(),isDirectory:l.isDirectory(),isSymbolicLink:l.isSymbolicLink()})}catch(a){if(a.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else if(a.code!=="ENOTDIR")throw a}return n}async resolveForReaddir(t,s=!1){let n=this.normalizePath(t),r=new Set,i=s,o=this.memory.get(n);for(;o&&o.type==="symlink";){if(r.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(n),i=!0,n=this.resolveSymlink(n,o.target),o=this.memory.get(n)}if(o)return{normalized:n,outsideOverlay:!1};if(this.getRelativeToMount(n)===null)return{normalized:n,outsideOverlay:!0};let l=this.toRealPath(n);if(!l)return{normalized:n,outsideOverlay:!0};try{if((await G.promises.lstat(l)).isSymbolicLink()){let f=await G.promises.readlink(l),u=this.resolveSymlink(n,f);return this.resolveForReaddir(u,!0)}return{normalized:n,outsideOverlay:!1}}catch{return i?{normalized:n,outsideOverlay:!0}:{normalized:n,outsideOverlay:!1}}}async readdir(t){let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.keys()).sort((i,o)=>i<o?-1:i>o?1:0)}async readdirWithFileTypes(t){let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.values()).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async rm(t,s){this.assertWritable(`rm '${t}'`);let n=this.normalizePath(t);if(!await this.existsInOverlay(n)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(n)).isDirectory){let o=await this.readdir(n);if(o.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of o){let l=n==="/"?`/${a}`:`${n}/${a}`;await this.rm(l,s)}}}}catch{}this.deleted.add(n),this.memory.delete(n)}async cp(t,s,n){this.assertWritable(`cp '${s}'`);let r=this.normalizePath(t),i=this.normalizePath(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let a=await this.stat(r);if(a.isFile){let l=await this.readFileBuffer(r);await this.writeFile(i,l)}else if(a.isDirectory){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(r);for(let c of l){let f=r==="/"?`/${c}`:`${r}/${c}`,u=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(f,u,n)}}}async mv(t,s){this.assertWritable(`mv '${s}'`),await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=new Set(this.memory.keys());for(let s of this.deleted)t.delete(s);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,s){if(this.deleted.has(t))return;let n=this.toRealPath(t);if(n)try{let r=G.readdirSync(n);for(let i of r){let o=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(o))continue;s.add(o);let a=je.join(n,i);G.statSync(a).isDirectory()&&this.scanRealFs(o,s)}}catch{}}async chmod(t,s){this.assertWritable(`chmod '${t}'`);let n=this.normalizePath(t);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(n);if(i){i.mode=s;return}let o=await this.stat(n);if(o.isFile){let a=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:a,mode:s,mtime:new Date})}else o.isDirectory&&this.memory.set(n,{type:"directory",mode:s,mtime:new Date})}async symlink(t,s){this.assertWritable(`symlink '${s}'`);let n=this.normalizePath(s);if(await this.existsInOverlay(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.memory.set(n,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(n)}async link(t,s){this.assertWritable(`link '${s}'`);let n=this.normalizePath(t),r=this.normalizePath(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let o=await this.stat(n);if(!o.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, link '${s}'`);let l=await this.readFileBuffer(n);this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:o.mode,mtime:new Date}),this.deleted.delete(r)}async readlink(t){let s=this.normalizePath(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let n=this.memory.get(s);if(n){if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}let r=this.toRealPath(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{return await G.promises.readlink(r)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${t}'`):i.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${t}'`):i}}async realpath(t){let s=this.normalizePath(t),n=new Set,r=async a=>{let l=a==="/"?[]:a.slice(1).split("/"),c="";for(let f of l){if(c=`${c}/${f}`,n.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let u=this.memory.get(c),d=0,h=40;for(;u&&u.type==="symlink"&&d<h;){if(n.add(c),c=this.resolveSymlink(c,u.target),d++,n.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);u=this.memory.get(c)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!u){let m=this.toRealPath(c);if(m)try{if((await G.promises.lstat(m)).isSymbolicLink()){let w=await G.promises.readlink(m);return n.add(c),c=this.resolveSymlink(c,w),r(c)}}catch(p){throw p.code==="ENOENT"?new Error(`ENOENT: no such file or directory, realpath '${t}'`):p}}}return c||"/"},i=await r(s);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,s,n){this.assertWritable(`utimes '${t}'`);let r=this.normalizePath(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let o=this.memory.get(r);if(o){o.mtime=n;return}let a=await this.stat(r);if(a.isFile){let l=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:l,mode:a.mode,mtime:n})}else a.isDirectory&&this.memory.set(r,{type:"directory",mode:a.mode,mtime:n})}};import*as B from"node:fs";import*as we from"node:path";var xt=class{root;constructor(t){if(this.root=we.resolve(t.root),!B.existsSync(this.root))throw new Error(`ReadWriteFs root does not exist: ${this.root}`);if(!B.statSync(this.root).isDirectory())throw new Error(`ReadWriteFs root is not a directory: ${this.root}`)}toRealPath(t){let s=this.normalizePath(t),n=we.join(this.root,s);return we.resolve(n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}async readFile(t,s){let n=await this.readFileBuffer(t),r=le(s);return Re(n,r)}async readFileBuffer(t){let s=this.toRealPath(t);try{let n=await B.promises.readFile(s);return new Uint8Array(n)}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${t}'`):r.code==="EISDIR"?new Error(`EISDIR: illegal operation on a directory, read '${t}'`):n}}async writeFile(t,s,n){let r=this.toRealPath(t),i=le(n),o=be(s,i),a=we.dirname(r);await B.promises.mkdir(a,{recursive:!0}),await B.promises.writeFile(r,o)}async appendFile(t,s,n){let r=this.toRealPath(t),i=le(n),o=be(s,i),a=we.dirname(r);await B.promises.mkdir(a,{recursive:!0}),await B.promises.appendFile(r,o)}async exists(t){let s=this.toRealPath(t);try{return await B.promises.access(s),!0}catch{return!1}}async stat(t){let s=this.toRealPath(t);try{let n=await B.promises.stat(s);return{isFile:n.isFile(),isDirectory:n.isDirectory(),isSymbolicLink:!1,mode:n.mode,size:n.size,mtime:n.mtime}}catch(n){throw n.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${t}'`):n}}async lstat(t){let s=this.toRealPath(t);try{let n=await B.promises.lstat(s);return{isFile:n.isFile(),isDirectory:n.isDirectory(),isSymbolicLink:n.isSymbolicLink(),mode:n.mode,size:n.size,mtime:n.mtime}}catch(n){throw n.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${t}'`):n}}async mkdir(t,s){let n=this.toRealPath(t);try{await B.promises.mkdir(n,{recursive:s?.recursive})}catch(r){let i=r;throw i.code==="EEXIST"?new Error(`EEXIST: file already exists, mkdir '${t}'`):i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, mkdir '${t}'`):r}}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){let s=this.toRealPath(t);try{return(await B.promises.readdir(s,{withFileTypes:!0})).map(r=>({name:r.name,isFile:r.isFile(),isDirectory:r.isDirectory(),isSymbolicLink:r.isSymbolicLink()})).sort((r,i)=>r.name<i.name?-1:r.name>i.name?1:0)}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, scandir '${t}'`):r.code==="ENOTDIR"?new Error(`ENOTDIR: not a directory, scandir '${t}'`):n}}async rm(t,s){let n=this.toRealPath(t);try{await B.promises.rm(n,{recursive:s?.recursive??!1,force:s?.force??!1})}catch(r){let i=r;throw i.code==="ENOENT"&&!s?.force?new Error(`ENOENT: no such file or directory, rm '${t}'`):i.code==="ENOTEMPTY"?new Error(`ENOTEMPTY: directory not empty, rm '${t}'`):r}}async cp(t,s,n){let r=this.toRealPath(t),i=this.toRealPath(s);try{await B.promises.cp(r,i,{recursive:n?.recursive??!1})}catch(o){let a=o;throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, cp '${t}'`):a.code==="EISDIR"?new Error(`EISDIR: is a directory, cp '${t}'`):o}}async mv(t,s){let n=this.toRealPath(t),r=this.toRealPath(s),i=we.dirname(r);await B.promises.mkdir(i,{recursive:!0});try{await B.promises.rename(n,r)}catch(o){let a=o;if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(a.code==="EXDEV"){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0});return}throw o}}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=[];return this.scanDir("/",t),t}scanDir(t,s){let n=this.toRealPath(t);try{let r=B.readdirSync(n);for(let i of r){let o=t==="/"?`/${i}`:`${t}/${i}`;s.push(o);let a=we.join(n,i);B.statSync(a).isDirectory()&&this.scanDir(o,s)}}catch{}}async chmod(t,s){let n=this.toRealPath(t);try{await B.promises.chmod(n,s)}catch(r){throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, chmod '${t}'`):r}}async symlink(t,s){let n=this.toRealPath(s);try{await B.promises.symlink(t,n)}catch(r){throw r.code==="EEXIST"?new Error(`EEXIST: file already exists, symlink '${s}'`):r}}async link(t,s){let n=this.toRealPath(t),r=this.toRealPath(s);try{await B.promises.link(n,r)}catch(i){let o=i;throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, link '${t}'`):o.code==="EEXIST"?new Error(`EEXIST: file already exists, link '${s}'`):o.code==="EPERM"?new Error(`EPERM: operation not permitted, link '${t}'`):i}}async readlink(t){let s=this.toRealPath(t);try{return await B.promises.readlink(s)}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${t}'`):r.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${t}'`):n}}async realpath(t){let s=this.toRealPath(t);try{let n=await B.promises.realpath(s);return n.startsWith(this.root)?n.slice(this.root.length)||"/":n}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, realpath '${t}'`):r.code==="ELOOP"?new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`):n}}async utimes(t,s,n){let r=this.toRealPath(t);try{await B.promises.utimes(r,s,n)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, utimes '${t}'`):i}}};var Ue=class{cmdId;cwd;startedAt;exitCode;bashEnv;cmdLine;env;explicitCwd;resultPromise;constructor(t,s,n,r,i=!1){this.cmdId=crypto.randomUUID(),this.cwd=n,this.startedAt=new Date,this.bashEnv=t,this.cmdLine=s,this.env=r,this.explicitCwd=i,this.resultPromise=this.execute()}async execute(){let t=this.env||this.explicitCwd?{cwd:this.explicitCwd?this.cwd:void 0,env:this.env}:void 0,s=await this.bashEnv.exec(this.cmdLine,t);return this.exitCode=s.exitCode,s}async*logs(){let t=await this.resultPromise;t.stdout&&(yield{type:"stdout",data:t.stdout,timestamp:new Date}),t.stderr&&(yield{type:"stderr",data:t.stderr,timestamp:new Date})}async wait(){return await this.resultPromise,this}async output(){let t=await this.resultPromise;return t.stdout+t.stderr}async stdout(){return(await this.resultPromise).stdout}async stderr(){return(await this.resultPromise).stderr}async kill(){}};var Lt=class e{bashEnv;constructor(t){this.bashEnv=t}static async create(t){let s=t?.fs;if(t?.overlayRoot){if(t?.fs)throw new Error("Cannot specify both 'fs' and 'overlayRoot' options");s=new He({root:t.overlayRoot})}let n=new tt({env:t?.env,cwd:t?.cwd,fs:s,maxCallDepth:t?.maxCallDepth,maxCommandCount:t?.maxCommandCount,maxLoopIterations:t?.maxLoopIterations,network:t?.network});return new e(n)}async runCommand(t,s){let n=s?.cwd??this.bashEnv.getCwd(),r=s?.cwd!==void 0;return new Ue(this.bashEnv,t,n,s?.env,r)}async writeFiles(t){for(let[s,n]of Object.entries(t)){let r;typeof n=="string"?r=n:n.encoding==="base64"?r=Buffer.from(n.content,"base64").toString("utf-8"):r=n.content;let i=s.substring(0,s.lastIndexOf("/"))||"/";i!=="/"&&await this.bashEnv.exec(`mkdir -p ${i}`),await this.bashEnv.writeFile(s,r)}}async readFile(t,s){let n=await this.bashEnv.readFile(t);return s==="base64"?Buffer.from(n).toString("base64"):n}async mkDir(t,s){let n=s?.recursive?"-p":"";await this.bashEnv.exec(`mkdir ${n} ${t}`)}async stop(){}async extendTimeout(t){}get domain(){}get bashEnvInstance(){return this.bashEnv}};export{tt as Bash,Ee as InMemoryFs,Rt as MountableFs,ze as NetworkAccessDeniedError,He as OverlayFs,xt as ReadWriteFs,Be as RedirectNotAllowedError,Lt as Sandbox,Ue as SandboxCommand,Ve as TooManyRedirectsError,Fr as defineCommand,xr as getCommandNames,Lr as getNetworkCommandNames};