just-bash 2.5.4 → 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,79 +1,523 @@
1
1
  #!/usr/bin/env node
2
- import{a as U,b as X,c as G,d as ee,e as J,f as k,g as F,h as pe,i as z,j as oe,k as Ue}from"./chunks/chunk-NWWB2XRE.js";import"./chunks/chunk-OBH7XN5N.js";import{a as Y}from"./chunks/chunk-4VDEBYW7.js";import"./chunks/chunk-KGOUQS5A.js";import*as zn from"node:fs";import*as Un from"node:readline";var Ae=[{name:"echo",load:async()=>(await import("./chunks/echo-WSKTON6U.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-AJXZOSPN.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-HWUQKYUM.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-BEHQBUMC.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-XJABRAUN.js")).mkdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-TSNAXMZ2.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-2PKAWTSQ.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-XXWRVG2D.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-3ATZ2ABL.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-EFFNQ3RY.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-3DIKREF7.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-53KG2MCJ.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-VL3R4LAM.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-DYK37Z24.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-BES27CZT.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-QSBRKIF5.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-UEQ7KMY5.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-IIVQXFNI.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-IIVQXFNI.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-IIVQXFNI.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-Q4OTJOEF.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-5LQMJYRJ.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-D2US2LMM.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-KUHOCH5S.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-IXHB2FVS.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-CPIFQTKY.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-IHF6BEOO.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-FT6WBQZG.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-MBLEXZBI.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-VP42N2JN.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-DSM3NUGM.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-452R4I2C.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-77K5HH2M.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-BFVYAPOU.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-ZEKN6D4Q.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-JJFZRWRC.js")).split},{name:"column",load:async()=>(await import("./chunks/column-TSFEMTG6.js")).column},{name:"join",load:async()=>(await import("./chunks/join-3IXMEGNA.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-ZFIT2GTM.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-CBEJ35BR.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-SO5MVUEX.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-EES7TR26.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-DQBEJH47.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-XQPYLN3H.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-YLLSNZZN.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-YLLSNZZN.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-PCMLRCRW.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-PCMLRCRW.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-G5C2J2OY.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-IWT2HHEA.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-OVATH2SQ.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-OVATH2SQ.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-CI7A5IXQ.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-UT3MT5UU.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-UT3MT5UU.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-XXZPU5CA.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-O7TCK5TL.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-GI3QVUGD.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-IQLPMFYI.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-O5BOTJGJ.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-JED4EKFH.js")).timeoutCommand},{name:"seq",load:async()=>(await import("./chunks/seq-AVK43XM2.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-RMGXYNQJ.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-2VAAFCTS.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-67P4ME4N.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-MV3WQ4QF.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-LNCFDPQZ.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-EPEXKI4B.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-7C5JICNL.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-73KOOLC6.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-KNRFDAY7.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-WXDKRL2Z.js")).hostname},{name:"od",load:async()=>(await import("./chunks/od-SLM7SRWU.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-YXK3WZQL.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-YXK3WZQL.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-YXK3WZQL.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ae.push({name:"tar",load:async()=>(await import("./chunks/tar-C27YYUAS.js")).tarCommand}),Ae.push({name:"yq",load:async()=>(await import("./chunks/yq-MF2SNFGL.js")).yqCommand}),Ae.push({name:"xan",load:async()=>(await import("./chunks/xan-6K2NGTHM.js")).xanCommand}),Ae.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-THMDBIGF.js")).sqlite3Command}));var Gn=[{name:"curl",load:async()=>(await import("./chunks/curl-LCMREE7R.js")).curlCommand}],pr=new Map;function yr(t){return{name:t.name,async execute(e,n){let r=pr.get(t.name);return r||(r=await t.load(),pr.set(t.name,r)),r.execute(e,n)}}}function wr(t){return(t?Ae.filter(n=>t.includes(n.name)):Ae).map(yr)}function Er(){return Gn.map(yr)}function gr(t){return"load"in t&&typeof t.load=="function"}function Ar(t){let e=null;return{name:t.name,async execute(n,r){return e||(e=await t.load()),e.execute(n,r)}}}var Hn=new TextEncoder,Vn=new TextDecoder;function Se(t,e){if(t instanceof Uint8Array)return t;if(e==="base64")return Uint8Array.from(atob(t),n=>n.charCodeAt(0));if(e==="hex"){let n=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)n[r/2]=parseInt(t.slice(r,r+2),16);return n}return e==="binary"||e==="latin1"?Uint8Array.from(t,n=>n.charCodeAt(0)):Hn.encode(t)}function Ge(t,e){return e==="base64"?btoa(String.fromCharCode(...t)):e==="hex"?Array.from(t).map(n=>n.toString(16).padStart(2,"0")).join(""):e==="binary"||e==="latin1"?String.fromCharCode(...t):Vn.decode(t)}function ae(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var He=new TextEncoder;function jn(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var ke=class{data=new Map;constructor(e){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),e)for(let[n,r]of Object.entries(e))jn(r)?this.writeFileSync(n,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(n,r)}normalizePath(e){if(!e||e==="/")return"/";let n=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;n.startsWith("/")||(n=`/${n}`);let r=n.split("/").filter(o=>o&&o!=="."),s=[];for(let o of r)o===".."?s.pop():s.push(o);return`/${s.join("/")}`||"/"}dirname(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.lastIndexOf("/");return r===0?"/":n.slice(0,r)}ensureParentDirs(e){let n=this.dirname(e);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,n,r,s){let o=this.normalizePath(e);this.ensureParentDirs(o);let i=ae(r),a=Se(n,i);this.data.set(o,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}async readFile(e,n){let r=await this.readFileBuffer(e),s=ae(n);return Ge(r,s)}async readFileBuffer(e){let n=this.resolvePathWithSymlinks(e),r=this.data.get(n);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:He.encode(r.content)}async writeFile(e,n,r){this.writeFileSync(e,n,r)}async appendFile(e,n,r){let s=this.normalizePath(e),o=this.data.get(s);if(o&&o.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${e}'`);let i=ae(r),a=Se(n,i);if(o?.type==="file"){let c=o.content instanceof Uint8Array?o.content:He.encode(o.content),l=new Uint8Array(c.length+a.length);l.set(c),l.set(a,c.length),this.data.set(s,{type:"file",content:l,mode:o.mode,mtime:new Date})}else this.writeFileSync(e,n,r)}async exists(e){try{let n=this.resolvePathWithSymlinks(e);return this.data.has(n)}catch{return!1}}async stat(e){let n=this.resolvePathWithSymlinks(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=He.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}async lstat(e){let n=this.resolveIntermediateSymlinks(e),r=this.data.get(n);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 s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=He.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}resolveSymlink(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${n}`:`${r}/${n}`)}resolveIntermediateSymlinks(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",o=new Set;for(let i=0;i<r.length-1;i++){let a=r[i];s=`${s}/${a}`;let c=this.data.get(s),l=0,u=40;for(;c&&c.type==="symlink"&&l<u;){if(o.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${e}'`);o.add(s),s=this.resolveSymlink(s,c.target),c=this.data.get(s),l++}if(l>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${e}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.slice(1).split("/"),s="",o=new Set;for(let i of r){s=`${s}/${i}`;let a=this.data.get(s),c=0,l=40;for(;a&&a.type==="symlink"&&c<l;){if(o.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);o.add(s),s=this.resolveSymlink(s,a.target),a=this.data.get(s),c++}if(c>=l)throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`)}return s}async mkdir(e,n){this.mkdirSync(e,n)}mkdirSync(e,n){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(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.dirname(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${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 n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let s=new Set;for(;r&&r.type==="symlink";){if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${e}'`);s.add(n),n=this.resolveSymlink(n,r.target),r=this.data.get(n)}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 o=n==="/"?"/":`${n}/`,i=new Map;for(let[a,c]of this.data.entries())if(a!==n&&a.startsWith(o)){let l=a.slice(o.length),u=l.split("/")[0];u&&!l.includes("/",u.length)&&!i.has(u)&&i.set(u,{name:u,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}return Array.from(i.values()).sort((a,c)=>a.name<c.name?-1:a.name>c.name?1:0)}async rm(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(s.type==="directory"){let o=await this.readdir(r);if(o.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let i of o){let a=r==="/"?`/${i}`:`${r}/${i}`;await this.rm(a,n)}}}this.data.delete(r)}async cp(e,n,r){let s=this.normalizePath(e),o=this.normalizePath(n),i=this.data.get(s);if(!i)throw new Error(`ENOENT: no such file or directory, cp '${e}'`);if(i.type==="file")this.ensureParentDirs(o),this.data.set(o,{...i});else if(i.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(o,{recursive:!0});let a=await this.readdir(s);for(let c of a){let l=s==="/"?`/${c}`:`${s}/${c}`,u=o==="/"?`/${c}`:`${o}/${c}`;await this.cp(l,u,r)}}}async mv(e,n){await this.cp(e,n,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=e==="/"?`/${n}`:`${e}/${n}`;return this.normalizePath(r)}async chmod(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);s.mode=n}async symlink(e,n){let r=this.normalizePath(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,n){let r=this.normalizePath(e),s=this.normalizePath(n),o=this.data.get(r);if(!o)throw new Error(`ENOENT: no such file or directory, link '${e}'`);if(o.type!=="file")throw new Error(`EPERM: operation not permitted, link '${e}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${n}'`);this.ensureParentDirs(s),this.data.set(s,{type:"file",content:o.content,mode:o.mode,mtime:o.mtime})}async readlink(e){let n=this.normalizePath(e),r=this.data.get(n);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 Sr="5.1.0(1)-release",xr="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function Re(){return{pid:process.pid,ppid:process.ppid,uid:process.getuid?.()??1e3,gid:process.getgid?.()??1e3}}function br(){let{pid:t,ppid:e,uid:n,gid:r}=Re();return`Name: bash
3
- State: R (running)
4
- Pid: ${t}
5
- PPid: ${e}
6
- Uid: ${n} ${n} ${n} ${n}
7
- Gid: ${r} ${r} ${r} ${r}
8
- `}function qn(t){let e=t;return typeof e.mkdirSync=="function"&&typeof e.writeFileSync=="function"}function Zn(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 Qn(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 Kn(t){t.mkdirSync("/proc/self/fd",{recursive:!0}),t.writeFileSync("/proc/version",`${xr}
9
- `),t.writeFileSync("/proc/self/exe","/bin/bash"),t.writeFileSync("/proc/self/cmdline","bash\0"),t.writeFileSync("/proc/self/comm",`bash
10
- `),t.writeFileSync("/proc/self/status",br()),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 Cr(t,e){qn(t)&&(Zn(t,e),Qn(t),Kn(t))}var Xn=["tar","yq","xan","sqlite3"];function $r(t){return Xn.includes(t)}function L(t,e){return{type:"ArithmeticExpression",expression:te(t,e,0).expr}}function te(t,e,n){return Yn(t,e,n)}function Yn(t,e,n){let{expr:r,pos:s}=je(t,e,n);for(s=D(e,s);e[s]===",";){s++;let{expr:o,pos:i}=je(t,e,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=D(e,i)}return{expr:r,pos:s}}function je(t,e,n){let{expr:r,pos:s}=Jn(t,e,n);if(s=D(e,s),e[s]==="?"){s++;let{expr:o,pos:i}=te(t,e,s);if(s=D(e,i),e[s]===":"){s++;let{expr:a,pos:c}=te(t,e,s);return{expr:{type:"ArithTernary",condition:r,consequent:o,alternate:a},pos:c}}}return{expr:r,pos:s}}function Jn(t,e,n){let{expr:r,pos:s}=Nr(t,e,n);for(;s=D(e,s),e.slice(s,s+2)==="||";){s+=2;let{expr:o,pos:i}=Nr(t,e,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=i}return{expr:r,pos:s}}function Nr(t,e,n){let{expr:r,pos:s}=vr(t,e,n);for(;s=D(e,s),e.slice(s,s+2)==="&&";){s+=2;let{expr:o,pos:i}=vr(t,e,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=i}return{expr:r,pos:s}}function vr(t,e,n){let{expr:r,pos:s}=Pr(t,e,n);for(;s=D(e,s),e[s]==="|"&&e[s+1]!=="|";){s++;let{expr:o,pos:i}=Pr(t,e,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=i}return{expr:r,pos:s}}function Pr(t,e,n){let{expr:r,pos:s}=Ir(t,e,n);for(;s=D(e,s),e[s]==="^";){s++;let{expr:o,pos:i}=Ir(t,e,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=i}return{expr:r,pos:s}}function Ir(t,e,n){let{expr:r,pos:s}=kr(t,e,n);for(;s=D(e,s),e[s]==="&"&&e[s+1]!=="&";){s++;let{expr:o,pos:i}=kr(t,e,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=i}return{expr:r,pos:s}}function kr(t,e,n){let{expr:r,pos:s}=Rr(t,e,n);for(;s=D(e,s),e.slice(s,s+2)==="=="||e.slice(s,s+2)==="!=";){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=Rr(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function Rr(t,e,n){let{expr:r,pos:s}=At(t,e,n);for(;;)if(s=D(e,s),e.slice(s,s+2)==="<="||e.slice(s,s+2)===">="){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=At(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else if(e[s]==="<"||e[s]===">"){let o=e[s];s++;let{expr:i,pos:a}=At(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else break;return{expr:r,pos:s}}function At(t,e,n){let{expr:r,pos:s}=Dr(t,e,n);for(;s=D(e,s),e.slice(s,s+2)==="<<"||e.slice(s,s+2)===">>";){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=Dr(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function Dr(t,e,n){let{expr:r,pos:s}=Or(t,e,n);for(;s=D(e,s),(e[s]==="+"||e[s]==="-")&&e[s+1]!==e[s];){let o=e[s];s++;let{expr:i,pos:a}=Or(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function Or(t,e,n){let{expr:r,pos:s}=Ve(t,e,n);for(;;)if(s=D(e,s),e[s]==="*"&&e[s+1]!=="*"){s++;let{expr:o,pos:i}=Ve(t,e,s);r={type:"ArithBinary",operator:"*",left:r,right:o},s=i}else if(e[s]==="/"||e[s]==="%"){let o=e[s];s++;let{expr:i,pos:a}=Ve(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else break;return{expr:r,pos:s}}function Ve(t,e,n){let{expr:r,pos:s}=St(t,e,n),o=D(e,s);if(e.slice(o,o+2)==="**"){o+=2;let{expr:i,pos:a}=Ve(t,e,o);return{expr:{type:"ArithBinary",operator:"**",left:r,right:i},pos:a}}return{expr:r,pos:s}}function St(t,e,n){let r=D(e,n);if(e.slice(r,r+2)==="++"||e.slice(r,r+2)==="--"){let s=e.slice(r,r+2);r+=2;let{expr:o,pos:i}=St(t,e,r);return{expr:{type:"ArithUnary",operator:s,operand:o,prefix:!0},pos:i}}if(e[r]==="+"||e[r]==="-"||e[r]==="!"||e[r]==="~"){let s=e[r];r++;let{expr:o,pos:i}=St(t,e,r);return{expr:{type:"ArithUnary",operator:s,operand:o,prefix:!0},pos:i}}return ts(t,e,r)}function es(t,e){let n=t[e];return n==="$"||n==="`"}function ts(t,e,n){let{expr:r,pos:s}=_r(t,e,n),o=[r];for(;es(e,s);){let{expr:i,pos:a}=_r(t,e,s);o.push(i),s=a}if(o.length>1&&(r={type:"ArithConcat",parts:o}),s=D(e,s),e.slice(s,s+2)==="++"||e.slice(s,s+2)==="--"){let i=e.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:i,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function _r(t,e,n){let r=D(e,n);if(e.slice(r,r+3)==="$(("){r+=3;let s=1,o=r;for(;r<e.length-1&&s>0;)e[r]==="("&&e[r+1]==="("?(s++,r+=2):e[r]===")"&&e[r+1]===")"?(s--,s>0&&(r+=2)):r++;let i=e.slice(o,r),{expr:a}=te(t,i,0);return r+=2,{expr:{type:"ArithNested",expression:a},pos:r}}if(e.slice(r,r+2)==="$("&&e[r+2]!=="("){r+=2;let s=1,o=r;for(;r<e.length&&s>0;)e[r]==="("?s++:e[r]===")"&&s--,s>0&&r++;let i=e.slice(o,r);return r++,{expr:{type:"ArithCommandSubst",command:i},pos:r}}if(e[r]==="`"){r++;let s=r;for(;r<e.length&&e[r]!=="`";)r++;let o=e.slice(s,r);return e[r]==="`"&&r++,{expr:{type:"ArithCommandSubst",command:o},pos:r}}if(e[r]==="("){r++;let{expr:s,pos:o}=te(t,e,r);return r=D(e,o),e[r]===")"&&r++,{expr:{type:"ArithGroup",expression:s},pos:r}}if(/[0-9]/.test(e[r])){let s="",o=!1;for(;r<e.length;){let a=e[r];if(o)if(/[0-9a-zA-Z@_]/.test(a))s+=a,r++;else break;else if(a==="#")o=!0,s+=a,r++;else if(/[0-9a-fA-FxX]/.test(a))s+=a,r++;else break}if(e[r]==="."&&/[0-9]/.test(e[r+1]))throw new F(`${s}.${e[r+1]}...: syntax error: invalid arithmetic operator`);if(e[r]==="["){let a=e.slice(r).trim();return{expr:{type:"ArithNumberSubscript",number:s,errorToken:a},pos:e.length}}return{expr:{type:"ArithNumber",value:xe(s)},pos:r}}if(e[r]==="$"&&e[r+1]==="{"){let s=r+2,o=1,i=s;for(;i<e.length&&o>0;)e[i]==="{"?o++:e[i]==="}"&&o--,o>0&&i++;let a=e.slice(s,i),c=i+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 s="";for(;r<e.length&&/[0-9]/.test(e[r]);)s+=e[r],r++;return{expr:{type:"ArithVariable",name:s},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[a-zA-Z_]/.test(e[r+1])&&r++,/[a-zA-Z_]/.test(e[r])){let s="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)s+=e[r],r++;if(e[r]==="["){r++;let i;if(e[r]==="'"||e[r]==='"'){let l=e[r];for(r++,i="";r<e.length&&e[r]!==l;)i+=e[r],r++;e[r]===l&&r++,r=D(e,r),e[r]==="]"&&r++}let a;if(i===void 0){let{expr:l,pos:u}=te(t,e,r);a=l,r=u,e[r]==="]"&&r++}if(r=D(e,r),e[r]==="["&&a)return{expr:{type:"ArithDoubleSubscript",array:s,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:d}=je(t,e,r);return{expr:{type:"ArithAssignment",operator:l,variable:s,subscript:a,stringKey:i,value:u},pos:d}}return{expr:{type:"ArithArrayElement",array:s,index:a,stringKey:i},pos:r}}r=D(e,r);let o=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let i of o)if(e.slice(r,r+i.length)===i&&e.slice(r,r+i.length+1)!=="=="){r+=i.length;let{expr:a,pos:c}=je(t,e,r);return{expr:{type:"ArithAssignment",operator:i,variable:s,value:a},pos:c}}return{expr:{type:"ArithVariable",name:s},pos:r}}return{expr:{type:"ArithNumber",value:0},pos:r}}function xe(t){if(t.includes("#")){let[e,n]=t.split("#"),r=Number.parseInt(e,10);if(r<2||r>64)return Number.NaN;if(r<=36)return Number.parseInt(n,r);let s=0;for(let o of n){let i;if(o>="0"&&o<="9")i=o.charCodeAt(0)-48;else if(o>="a"&&o<="z")i=o.charCodeAt(0)-97+10;else if(o>="A"&&o<="Z")i=o.charCodeAt(0)-65+36;else if(o==="@")i=62;else if(o==="_")i=63;else return Number.NaN;if(i>=r)return Number.NaN;s=s*r+i}return s}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 D(t,e){for(;e<t.length;){if(t[e]==="\\"&&t[e+1]===`
11
- `){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=[],n=!1){return{type:"Statement",pipelines:t,operators:e,background:n}},pipeline(t,e=!1){return{type:"Pipeline",commands:t,negated:e}},simpleCommand(t,e=[],n=[],r=[]){return{type:"SimpleCommand",name:t,args:e,assignments:n,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,n=!1,r=null){return{type:"Assignment",name:t,value:e,append:n,array:r}},redirection(t,e,n=null){return{type:"Redirection",fd:n,operator:t,target:e}},hereDoc(t,e,n=!1,r=!1){return{type:"HereDoc",delimiter:t,content:e,stripTabs:n,quoted:r}},ifNode(t,e=null,n=[]){return{type:"If",clauses:t,elseBody:e,redirections:n}},forNode(t,e,n,r=[]){return{type:"For",variable:t,words:e,body:n,redirections:r}},whileNode(t,e,n=[]){return{type:"While",condition:t,body:e,redirections:n}},untilNode(t,e,n=[]){return{type:"Until",condition:t,body:e,redirections:n}},caseNode(t,e,n=[]){return{type:"Case",word:t,items:e,redirections:n}},caseItem(t,e,n=";;"){return{type:"CaseItem",patterns:t,body:e,terminator:n}},subshell(t,e=[]){return{type:"Subshell",body:t,redirections:e}},group(t,e=[]){return{type:"Group",body:t,redirections:e}},functionDef(t,e,n=[]){return{type:"FunctionDef",name:t,body:e,redirections:n}},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 qe={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 Tr(t){let e=t.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!e)return!1;let n=t.slice(e[0].length);if(n===""||n==="+")return!0;if(n[0]==="["){let r=0,s=0;for(;s<n.length;s++)if(n[s]==="[")r++;else if(n[s]==="]"&&(r--,r===0))break;if(r!==0||s>=n.length)return!1;let o=n.slice(s+1);return o===""||o==="+"}return!1}var rs=[[";",";","&",f.SEMI_SEMI_AND],["<","<","<",f.TLESS],["&",">",">",f.AND_DGREAT]],ns=[["[","[",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]],ss={"|":f.PIPE,"&":f.AMP,";":f.SEMICOLON,"(":f.LPAREN,")":f.RPAREN,"<":f.LESS,">":f.GREAT};function is(t){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)}var Ze=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];constructor(e){this.input=e}tokenize(){let n=this.input.length,r=this.tokens,s=this.pendingHeredocs;for(;this.pos<n&&(this.skipWhitespace(),!(this.pos>=n));){if(s.length>0&&r.length>0&&r[r.length-1].type===f.NEWLINE){this.readHeredocContent();continue}let o=this.nextToken();o&&r.push(o)}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,n=e.length,r=this.pos,s=this.column,o=this.line;for(;r<n;){let i=e[r];if(i===" "||i===" ")r++,s++;else if(i==="\\"&&e[r+1]===`
12
- `)r+=2,o++,s=1;else break}this.pos=r,this.column=s,this.line=o}nextToken(){let e=this.input,n=this.pos,r=this.line,s=this.column,o=e[n],i=e[n+1],a=e[n+2];if(o==="#")return this.readComment(n,r,s);if(o===`
13
- `)return this.pos=n+1,this.line++,this.column=1,{type:f.NEWLINE,value:`
14
- `,start:n,end:n+1,line:r,column:s};if(o==="<"&&i==="<"&&a==="-")return this.pos=n+3,this.column=s+3,this.registerHeredocFromLookahead(!0),this.makeToken(f.DLESSDASH,"<<-",n,r,s);for(let[l,u,d,h]of rs)if(o===l&&i===u&&a===d)return this.pos=n+3,this.column=s+3,this.makeToken(h,l+u+d,n,r,s);if(o==="<"&&i==="<")return this.pos=n+2,this.column=s+2,this.registerHeredocFromLookahead(!1),this.makeToken(f.DLESS,"<<",n,r,s);for(let[l,u,d]of ns)if(o===l&&i===u)return this.pos=n+2,this.column=s+2,this.makeToken(d,l+u,n,r,s);let c=ss[o];return c?(this.pos=n+1,this.column=s+1,this.makeToken(c,o,n,r,s)):o==="{"?i==="}"?(this.pos=n+2,this.column=s+2,{type:f.WORD,value:"{}",start:n,end:n+2,line:r,column:s,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(n)!==null?this.readWordWithBraceExpansion(n,r,s):this.scanLiteralBraceWord(n)!==null?this.readWordWithBraceExpansion(n,r,s):i!==void 0&&i!==" "&&i!==" "&&i!==`
15
- `?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(f.LBRACE,"{",n,r,s)):o==="}"?this.isWordCharFollowing(n+1)?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(f.RBRACE,"}",n,r,s)):o==="!"?i==="="?(this.pos=n+2,this.column=s+2,this.makeToken(f.WORD,"!=",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(f.BANG,"!",n,r,s)):this.readWord(n,r,s)}makeToken(e,n,r,s,o){return{type:e,value:n,start:r,end:this.pos,line:s,column:o}}readComment(e,n,r){let s=this.input,o=s.length,i=this.pos;for(;i<o&&s[i]!==`
16
- `;)i++;let a=s.slice(e,i);return this.pos=i,this.column=r+(i-e),{type:f.COMMENT,value:a,start:e,end:i,line:n,column:r}}readWord(e,n,r){let s=this.input,o=s.length,i=this.pos,a=i;for(;i<o;){let p=s[i];if(p===" "||p===" "||p===`
17
- `||p===";"||p==="&"||p==="|"||p==="("||p===")"||p==="<"||p===">"||p==="'"||p==='"'||p==="\\"||p==="$"||p==="`"||p==="{"||p==="}"||p==="~"||p==="*"||p==="?"||p==="[")break;i++}if(i>a){let p=s[i];if(i>=o||p===" "||p===" "||p===`
18
- `||p===";"||p==="&"||p==="|"||p==="("||p===")"||p==="<"||p===">"){let w=s.slice(a,i);if(this.pos=i,this.column=r+(i-a),qe[w])return{type:qe[w],value:w,start:e,end:i,line:n,column:r};let g=w.indexOf("=");return g>0&&Tr(w.slice(0,g))?{type:f.ASSIGNMENT_WORD,value:w,start:e,end:i,line:n,column:r}:/^[0-9]+$/.test(w)?{type:f.NUMBER,value:w,start:e,end:i,line:n,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(w)?{type:f.NAME,value:w,start:e,end:i,line:n,column:r,quoted:!1,singleQuoted:!1}:{type:f.WORD,value:w,start:e,end:i,line:n,column:r,quoted:!1,singleQuoted:!1}}}i=this.pos;let c=this.column,l=this.line,u="",d=!1,h=!1,m=!1,y=!1,E=s[i]==='"'||s[i]==="'";for(;i<o;){let p=s[i];if(!m&&!y&&(p===" "||p===" "||p===`
19
- `||p===";"||p==="&"||p==="|"||p==="("||p===")"||p==="<"||p===">"))break;if(p==="$"&&i+1<o&&s[i+1]==="'"&&!m&&!y){for(u+="$'",i+=2,c+=2;i<o&&s[i]!=="'";)s[i]==="\\"&&i+1<o?(u+=s[i]+s[i+1],i+=2,c+=2):(u+=s[i],i++,c++);i<o&&(u+="'",i++,c++);continue}if(p==="$"&&i+1<o&&s[i+1]==='"'&&!m&&!y){i++,c++,y=!0,d=!0,u===""&&(E=!0),i++,c++;continue}if(p==="'"&&!y){m?(m=!1,E||(u+=p)):(m=!0,E?(h=!0,d=!0):u+=p),i++,c++;continue}if(p==='"'&&!m){y?(y=!1,E||(u+=p)):(y=!0,E?d=!0:u+=p),i++,c++;continue}if(p==="\\"&&!m&&i+1<o){let w=s[i+1];if(w===`
20
- `){i+=2,l++,c=1;continue}if(y){if(w==='"'||w==="\\"||w==="$"||w==="`"||w===`
21
- `){w==="$"||w==="`"?u+=p+w:u+=w,i+=2,c+=2;continue}}else{w==='"'||w==="'"?u+=p+w:u+=w,i+=2,c+=2;continue}}if(p==="$"&&i+1<o&&s[i+1]==="("){u+=p,i++,c++,u+=s[i],i++,c++;let w=1,g=!1,b=!1,C=0,I=!1,R="",me=s[i]==="(";for(;w>0&&i<o;){let _=s[i];if(u+=_,g)_==="'"&&(g=!1);else if(b)_==="\\"&&i+1<o?(u+=s[i+1],i++,c++):_==='"'&&(b=!1);else if(_==="'")g=!0,R="";else if(_==='"')b=!0,R="";else if(_==="\\"&&i+1<o)u+=s[i+1],i++,c++,R="";else if(_==="#"&&!me&&(R===""||/\s/.test(s[i-1]||""))){for(;i+1<o&&s[i+1]!==`
22
- `;)i++,c++,u+=s[i];R=""}else/[a-zA-Z_]/.test(_)?R+=_:(R==="case"?(C++,I=!1):R==="in"&&C>0?I=!0:R==="esac"&&C>0&&(C--,I=!1),R="",_==="("?i>0&&s[i-1]==="$"?w++:I||w++:_===")"?I?I=!1:w--:_===";"&&C>0&&i+1<o&&s[i+1]===";"&&(I=!0));_===`
23
- `&&(l++,c=0,R=""),i++,c++}continue}if(p==="$"&&i+1<o&&s[i+1]==="["){u+=p,i++,c++,u+=s[i],i++,c++;let w=1;for(;w>0&&i<o;){let g=s[i];u+=g,g==="["?w++:g==="]"?w--:g===`
24
- `&&(l++,c=0),i++,c++}continue}if(p==="$"&&i+1<o&&s[i+1]==="{"){u+=p,i++,c++,u+=s[i],i++,c++;let w=1;for(;w>0&&i<o;){let g=s[i];u+=g,g==="{"?w++:g==="}"?w--:g===`
25
- `&&(l++,c=0),i++,c++}continue}if(p==="$"&&i+1<o){let w=s[i+1];if(w==="#"||w==="?"||w==="$"||w==="!"||w==="@"||w==="*"||w==="-"||w>="0"&&w<="9"){u+=p+w,i+=2,c+=2;continue}}if(p==="`"){for(u+=p,i++,c++;i<o&&s[i]!=="`";){let w=s[i];u+=w,w==="\\"&&i+1<o&&(u+=s[i+1],i++,c++),w===`
26
- `&&(l++,c=0),i++,c++}i<o&&(u+=s[i],i++,c++);continue}u+=p,i++,p===`
27
- `?(l++,c=1):c++}if(this.pos=i,this.column=c,this.line=l,u==="")return{type:f.WORD,value:"",start:e,end:i,line:n,column:r,quoted:d,singleQuoted:h};if(!d&&qe[u])return{type:qe[u],value:u,start:e,end:i,line:n,column:r};if(!E){let p=u.indexOf("=");if(p>0&&Tr(u.slice(0,p)))return{type:f.ASSIGNMENT_WORD,value:u,start:e,end:i,line:n,column:r,quoted:d,singleQuoted:h}}return/^[0-9]+$/.test(u)?{type:f.NUMBER,value:u,start:e,end:i,line:n,column:r}:is(u)?{type:f.NAME,value:u,start:e,end:i,line:n,column:r,quoted:d,singleQuoted:h}:{type:f.WORD,value:u,start:e,end:i,line:n,column:r,quoted:d,singleQuoted:h}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let e=this.pendingHeredocs.shift();if(!e)break;let n=this.pos,r=this.line,s=this.column,o="";for(;this.pos<this.input.length;){let i=this.pos,a="";for(;this.pos<this.input.length&&this.input[this.pos]!==`
28
- `;)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]===`
29
- `&&(this.pos++,this.line++,this.column=1);break}o+=a,this.pos<this.input.length&&this.input[this.pos]===`
30
- `&&(o+=`
31
- `,this.pos++,this.line++,this.column=1)}this.tokens.push({type:f.HEREDOC_CONTENT,value:o,start:n,end:this.pos,line:r,column:s})}}addPendingHeredoc(e,n,r){this.pendingHeredocs.push({delimiter:e,stripTabs:n,quoted:r})}registerHeredocFromLookahead(e){let n=this.pos,r=this.column;for(;this.pos<this.input.length&&(this.input[this.pos]===" "||this.input[this.pos]===" ");)this.pos++,this.column++;let s="",o=!1,i=this.input[this.pos];if(i==="'"||i==='"'){o=!0;let a=i;for(this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]!==a;)s+=this.input[this.pos],this.pos++,this.column++}else for(;this.pos<this.input.length&&!/[\s;<>&|()]/.test(this.input[this.pos]);)s+=this.input[this.pos],this.pos++,this.column++;this.pos=n,this.column=r,s&&this.pendingHeredocs.push({delimiter:s,stripTabs:e,quoted:o})}isWordCharFollowing(e){if(e>=this.input.length)return!1;let n=this.input[e];return!(n===" "||n===" "||n===`
32
- `||n===";"||n==="&"||n==="|"||n==="("||n===")"||n==="<"||n===">")}readWordWithBraceExpansion(e,n,r){let s=this.input,o=s.length,i=e,a=r;for(;i<o;){let l=s[i];if(l===" "||l===" "||l===`
33
- `||l===";"||l==="&"||l==="|"||l==="("||l===")"||l==="<"||l===">")break;if(l==="{"){if(this.scanBraceExpansion(i)!==null){let d=1;for(i++,a++;i<o&&d>0;)s[i]==="{"?d++:s[i]==="}"&&d--,i++,a++;continue}i++,a++;continue}if(l==="}"){i++,a++;continue}if(l==="$"&&i+1<o&&s[i+1]==="("){i++,a++,i++,a++;let u=1;for(;u>0&&i<o;)s[i]==="("?u++:s[i]===")"&&u--,i++,a++;continue}if(l==="$"&&i+1<o&&s[i+1]==="{"){i++,a++,i++,a++;let u=1;for(;u>0&&i<o;)s[i]==="{"?u++:s[i]==="}"&&u--,i++,a++;continue}if(l==="`"){for(i++,a++;i<o&&s[i]!=="`";)s[i]==="\\"&&i+1<o?(i+=2,a+=2):(i++,a++);i<o&&(i++,a++);continue}i++,a++}let c=s.slice(e,i);return this.pos=i,this.column=a,{type:f.WORD,value:c,start:e,end:i,line:n,column:r,quoted:!1,singleQuoted:!1}}scanBraceExpansion(e){let n=this.input,r=n.length,s=e+1,o=1,i=!1,a=!1;for(;s<r&&o>0;){let c=n[s];if(c==="{")o++,s++;else if(c==="}")o--,s++;else if(c===","&&o===1)i=!0,s++;else if(c==="."&&s+1<r&&n[s+1]===".")a=!0,s+=2;else{if(c===" "||c===" "||c===`
34
- `||c===";"||c==="&"||c==="|")return null;s++}}return o===0&&(i||a)?n.slice(e,s):null}scanLiteralBraceWord(e){let n=this.input,r=n.length,s=e+1,o=1;for(;s<r&&o>0;){let i=n[s];if(i==="{")o++,s++;else if(i==="}"){if(o--,o===0)return n.slice(e,s+1);s++}else{if(i===" "||i===" "||i===`
35
- `||i===";"||i==="&"||i==="|")return null;s++}}return null}};var xt=1e6,bt=1e5,Wr=1e6,Fr=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]),Mr=new Set([f.LESS,f.GREAT,f.DLESS,f.DGREAT,f.LESSAND,f.GREATAND,f.LESSGREAT,f.DLESSDASH,f.CLOBBER,f.TLESS]),re=class extends Error{line;column;token;constructor(e,n,r,s=void 0){super(`Parse error at ${n}:${r}: ${e}`),this.line=n,this.column=r,this.token=s,this.name="ParseException"}};function zr(t,e,n){let r=n+1;for(;r<e.length&&/[a-zA-Z0-9_-]/.test(e[r]);)r++;return r}function Ct(t,e,n,r,s){let o=1,i=n+1;for(;i<e.length&&o>0;)e[i]===r?o++:e[i]===s&&o--,o>0&&i++;return o===0?i:-1}function ye(t,e,n){let r=n,s=1;for(;r<e.length&&s>0;){let o=e[r];if(o==="\\"&&r+1<e.length){r+=2;continue}if(o==="'"){let i=e.indexOf("'",r+1);if(i!==-1){r=i+1;continue}}if(o==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?r+=2:r++;r<e.length&&r++;continue}o==="{"?s++:o==="}"&&s--,s>0&&r++}return r}function Ur(t,e,n){let r=n,s=!1;for(;r<e.length;){let o=e[r];if(o==="/"&&s||o==="}")break;if(o==="'"){let i=e.indexOf("'",r+1);if(i!==-1){r=i+1,s=!0;continue}}if(o==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?r+=2:r++;r<e.length&&r++,s=!0;continue}o==="\\"?(r+=2,s=!0):(r++,s=!0)}return r}function Gr(t,e,n){let r=n,s="";for(;r<e.length;){let o=e[r];if(o==="*"||o==="?")s+=o,r++;else if(o==="["){let i=os(e,r);i===-1?(s+=o,r++):(s+=e.slice(r,i+1),r=i+1)}else break}return{pattern:s,endIndex:r}}function os(t,e){let n=e+1;for(n<t.length&&t[n]==="^"&&n++,n<t.length&&t[n]==="]"&&n++;n<t.length;){let r=t[n];if(r==="\\"&&n+1<t.length){n+=2;continue}if(r==="]")return n;if(r==='"'||r==="$"||r==="`")return-1;if(r==="'"){let s=t.indexOf("'",n+1);if(s!==-1){n=s+1;continue}}if(r==="["&&n+1<t.length&&t[n+1]===":"){let s=t.indexOf(":]",n+2);if(s!==-1){n=s+2;continue}}if(r==="["&&n+1<t.length&&(t[n+1]==="."||t[n+1]==="=")){let o=`${t[n+1]}]`,i=t.indexOf(o,n+2);if(i!==-1){n=i+2;continue}}n++}return-1}function Hr(t,e,n){let r="",s=n;for(;s<e.length&&e[s]!=="'";){let o=e[s];if(o==="\\"&&s+1<e.length)switch(e[s+1]){case"n":r+=`
36
- `,s+=2;break;case"t":r+=" ",s+=2;break;case"r":r+="\r",s+=2;break;case"\\":r+="\\",s+=2;break;case"'":r+="'",s+=2;break;case'"':r+='"',s+=2;break;case"a":r+="\x07",s+=2;break;case"b":r+="\b",s+=2;break;case"e":case"E":r+="\x1B",s+=2;break;case"f":r+="\f",s+=2;break;case"v":r+="\v",s+=2;break;case"x":{let a=e.slice(s+2,s+4),c=parseInt(a,16);Number.isNaN(c)?(r+="\\x",s+=2):(r+=String.fromCharCode(c),s+=4);break}case"u":{let a=e.slice(s+2,s+6),c=parseInt(a,16);Number.isNaN(c)?(r+="\\u",s+=2):(r+=String.fromCharCode(c),s+=6);break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let a="",c=s+1;for(;c<e.length&&c<s+4&&/[0-7]/.test(e[c]);)a+=e[c],c++;let l=parseInt(a,8);r+=String.fromCharCode(l),s=c;break}default:r+=o,s++}else r+=o,s++}return s<e.length&&e[s]==="'"&&s++,{part:A.literal(r),endIndex:s}}function $t(t,e){let n=e.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:L(t,n)}function Br(t){let e=[],n="",r=0;for(let s=0;s<t.length;s++){let o=t[s];o==="{"?(r++,n+=o):o==="}"?(r--,n+=o):o===","&&r===0?(e.push(n),n=""):n+=o}return e.push(n),e}function Vr(t,e,n,r){let s=Ct(t,e,n,"{","}");if(s===-1)return null;let o=e.slice(n+1,s),i=o.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(i)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(i[1],10),end:Number.parseInt(i[2],10),step:i[3]?Number.parseInt(i[3],10):void 0,startStr:i[1],endStr:i[2]}]},endIndex:s+1};let a=o.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return a?{part:{type:"BraceExpansion",items:[{type:"Range",start:a[1],end:a[2],step:a[3]?Number.parseInt(a[3],10):void 0}]},endIndex:s+1}:o.includes(",")&&r?{part:{type:"BraceExpansion",items:Br(o).map(u=>({type:"Word",word:A.word(r(t,u,!1,!1,!1))}))},endIndex:s+1}:o.includes(",")?{part:{type:"BraceExpansion",items:Br(o).map(u=>({type:"Word",word:A.word([A.literal(u)])}))},endIndex:s+1}:null}function jr(t,e){let n="";for(let r of e.parts)switch(r.type){case"Literal":case"SingleQuoted":case"Escaped":n+=r.value;break;case"DoubleQuoted":n+='"';for(let s of r.parts)s.type==="Literal"||s.type==="Escaped"?n+=s.value:s.type==="ParameterExpansion"&&(n+=`\${${s.parameter}}`);n+='"';break;case"ParameterExpansion":n+=`\${${r.parameter}}`;break;case"Glob":n+=r.pattern;break;default:n+=r.type}return n}function qr(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 Qe(t){let e=t.current(),n=e.type;if(n===f.NUMBER){let r=t.peek(1);return e.end!==r.start?!1:Mr.has(r.type)}return Fr.has(n)}function Ke(t){let e=null;t.check(f.NUMBER)&&(e=Number.parseInt(t.advance().value,10));let n=t.advance(),r=qr(t,n.type);if(n.type===f.DLESS||n.type===f.DLESSDASH)return as(t,r,e,n.type===f.DLESSDASH);t.isWord()||t.error("Expected redirection target");let s=t.parseWord();return A.redirection(r,s,e)}function as(t,e,n,r){t.isWord()||t.error("Expected here-document delimiter");let s=t.advance(),o=s.value,i=s.quoted||!1;(o.startsWith("'")&&o.endsWith("'")||o.startsWith('"')&&o.endsWith('"'))&&(o=o.slice(1,-1));let a=A.redirection(r?"<<-":"<<",A.hereDoc(o,A.word([]),r,i),n);return t.addPendingHeredoc(a,o,r,i),a}function Qr(t){let e=t.current().line,n=[],r=null,s=[],o=[];for(;t.check(f.ASSIGNMENT_WORD);)t.checkIterationLimit(),n.push(cs(t));for(;Qe(t);)t.checkIterationLimit(),o.push(Ke(t));for(t.isWord()&&(r=t.parseWord());(!t.isStatementEnd()||t.check(f.RBRACE))&&!t.check(f.PIPE,f.PIPE_AMP);)if(t.checkIterationLimit(),Qe(t))o.push(Ke(t));else if(t.check(f.RBRACE)){let a=t.advance();s.push(t.parseWordFromString(a.value,!1,!1))}else if(t.isWord())s.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 d=u?c.slice(0,-2):c.slice(0,-1);u||t.expect(f.LPAREN);let h=Nt(t);t.expect(f.RPAREN);let m=h.map(E=>jr(t,E)),y=`${d}=(${m.join(" ")})`;s.push(t.parseWordFromString(y,!1,!1))}else s.push(t.parseWordFromString(c,a.quoted,a.singleQuoted))}else if(t.check(f.LPAREN))t.error("syntax error near unexpected token `('");else break;let i=A.simpleCommand(r,s,n,o);return i.line=e,i}function cs(t){let e=t.expect(f.ASSIGNMENT_WORD),n=e.value,r=n.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||t.error(`Invalid assignment: ${n}`);let s=r[0],o,i=s.length;if(n[i]==="["){let d=0,h=i+1;for(;i<n.length;i++)if(n[i]==="[")d++;else if(n[i]==="]"&&(d--,d===0))break;d!==0&&t.error(`Invalid assignment: ${n}`),o=n.slice(h,i),i++}let a=n[i]==="+";a&&i++,n[i]!=="="&&t.error(`Invalid assignment: ${n}`),i++;let c=n.slice(i);if(c==="("){let d=Nt(t);t.expect(f.RPAREN);let h=o!==void 0?`${s}[${o}]`:s;return A.assignment(h,null,a,d)}if(c===""&&t.check(f.LPAREN)){let d=t.current();if(e.end===d.start){t.advance();let h=Nt(t);t.expect(f.RPAREN);let m=o!==void 0?`${s}[${o}]`:s;return A.assignment(m,null,a,h)}}let l=c?t.parseWordFromString(c,e.quoted,e.singleQuoted,!0):null,u=o!==void 0?`${s}[${o}]`:s;return A.assignment(u,l,a,null)}function Nt(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 vt(t){t.expect(f.IF);let e=[],n=t.parseCompoundList();t.expect(f.THEN);let r=t.parseCompoundList();if(r.length===0){let i=t.check(f.FI)?"fi":t.check(f.ELSE)?"else":t.check(f.ELIF)?"elif":"fi";t.error(`syntax error near unexpected token \`${i}'`)}for(e.push({condition:n,body:r});t.check(f.ELIF);){t.advance();let i=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:i,body:a})}let s=null;t.check(f.ELSE)&&(t.advance(),s=t.parseCompoundList(),s.length===0&&t.error("syntax error near unexpected token `fi'")),t.expect(f.FI);let o=t.parseOptionalRedirections();return A.ifNode(e,s,o)}function Pt(t){if(t.expect(f.FOR),t.check(f.DPAREN_START))return us(t);t.isWord()||t.error("Expected variable name in for loop");let n=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 s=t.parseCompoundList();t.expect(f.DONE);let o=t.parseOptionalRedirections();return A.forNode(n,r,s,o)}function us(t){t.expect(f.DPAREN_START);let e=null,n=null,r=null,s=["","",""],o=0,i=0;for(;!t.check(f.DPAREN_END,f.EOF);){let l=t.advance();if(l.type===f.SEMICOLON&&i===0){if(o++,o>2)break}else l.value==="("&&i++,l.value===")"&&i--,s[o]+=l.value}t.expect(f.DPAREN_END),s[0].trim()&&(e=L(t,s[0].trim())),s[1].trim()&&(n=L(t,s[1].trim())),s[2].trim()&&(r=L(t,s[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:n,update:r,body:a,redirections:c}}function It(t){t.expect(f.WHILE);let e=t.parseCompoundList();t.expect(f.DO);let n=t.parseCompoundList();n.length===0&&t.error("syntax error near unexpected token `done'"),t.expect(f.DONE);let r=t.parseOptionalRedirections();return A.whileNode(e,n,r)}function kt(t){t.expect(f.UNTIL);let e=t.parseCompoundList();t.expect(f.DO);let n=t.parseCompoundList();n.length===0&&t.error("syntax error near unexpected token `done'"),t.expect(f.DONE);let r=t.parseOptionalRedirections();return A.untilNode(e,n,r)}function Rt(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 n=[];for(;!t.check(f.ESAC,f.EOF);){t.checkIterationLimit();let s=t.getPos(),o=fs(t);if(o&&n.push(o),t.skipNewlines(),t.getPos()===s&&!o)break}t.expect(f.ESAC);let r=t.parseOptionalRedirections();return A.caseNode(e,n,r)}function fs(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 n=[];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 s=t.getPos(),o=t.parseStatement();if(o&&n.push(o),t.skipSeparators(!1),t.getPos()===s&&!o)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,n,r)}function Dt(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 n=t.parseOptionalRedirections();return A.subshell(e,n)}function Ot(t){t.expect(f.LBRACE);let e=t.parseCompoundList();t.expect(f.RBRACE);let n=t.parseOptionalRedirections();return A.group(e,n)}var hs=["-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"],ms=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function Lt(t){return t.skipNewlines(),ps(t)}function ps(t){let e=Kr(t);for(t.skipNewlines();t.check(f.OR_OR);){t.advance(),t.skipNewlines();let n=Kr(t);e={type:"CondOr",left:e,right:n},t.skipNewlines()}return e}function Kr(t){let e=_t(t);for(t.skipNewlines();t.check(f.AND_AND);){t.advance(),t.skipNewlines();let n=_t(t);e={type:"CondAnd",left:e,right:n},t.skipNewlines()}return e}function _t(t){return t.skipNewlines(),t.check(f.BANG)?(t.advance(),t.skipNewlines(),{type:"CondNot",operand:_t(t)}):ys(t)}function ys(t){if(t.check(f.LPAREN)){t.advance();let e=Lt(t);return t.expect(f.RPAREN),{type:"CondGroup",expression:e}}if(t.isWord()){let e=t.current(),n=e.value;if(hs.includes(n)&&!e.quoted&&(t.advance(),t.check(f.DBRACK_END)&&t.error(`Expected operand after ${n}`),t.isWord())){let s=t.parseWord();return{type:"CondUnary",operator:n,operand:s}}let r=t.parseWord();if(t.isWord()&&ms.includes(t.current().value)){let s=t.advance().value,o=t.parseWord();return{type:"CondBinary",operator:s,left:r,right:o}}if(t.check(f.LESS)){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:"<",left:r,right:s}}if(t.check(f.GREAT)){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:">",left:r,right:s}}if(t.isWord()&&t.current().value==="="){t.advance();let s=t.parseWord();return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}t.error("Expected conditional expression")}function Es(t,e,n){let r=n+1,s=e[r];if("@*#?$!-0123456789".includes(s))return{part:A.parameterExpansion(s),endIndex:r+1};let o="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)o+=e[r],r++;return{part:A.parameterExpansion(o),endIndex:r}}function gs(t,e,n,r=!1){let s=n+2,o=!1;e[s]==="!"&&(o=!0,s++);let i=!1;e[s]==="#"&&!/[}:#%/^,]/.test(e[s+1]||"}")&&(i=!0,s++);let a="",c=e[s];if(/[@*#?$!-]/.test(c)&&!/[a-zA-Z0-9_]/.test(e[s+1]||""))a=c,s++;else for(;s<e.length&&/[a-zA-Z0-9_]/.test(e[s]);)a+=e[s],s++;if(e[s]==="["){let u=Ct(t,e,s,"[","]");a+=e.slice(s,u+1),s=u+1}a===""&&!o&&!i&&e[s]!=="}"&&t.error(`\${${e[s]}}: bad substitution`);let l=null;if(o){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[s]==="*"||e[s]==="@"){let d=e[s];s++,l={type:"VarNamePrefix",prefix:a,star:d==="*"},a=""}else l={type:"Indirection"}}else if(i)if(e[s]===":")for(l={type:"LengthSliceError"};s<e.length&&e[s]!=="}";)s++;else e[s]!=="}"&&/[-+=?]/.test(e[s])?t.error(`\${#${a}${e.slice(s,e.indexOf("}",s))}}: bad substitution`):l={type:"Length"};if(!l&&s<e.length&&e[s]!=="}"){let u=As(t,e,s,a,r);l=u.operation,s=u.endIndex}if(s<e.length&&e[s]!=="}"){let u=e[s];if(!/[:\-+=?#%/^,@[]/.test(u)){let d=s;for(;d<e.length&&e[d]!=="}";)d++;let h=e.slice(n,d+1);t.error(`\${${h.slice(2,-1)}}: bad substitution`)}}for(;s<e.length&&e[s]!=="}";)s++;return{part:A.parameterExpansion(a,l),endIndex:s+1}}function As(t,e,n,r,s=!1){let o=n,i=e[o],a=e[o+1]||"";if(i===":"){let c=a;if("-=?+".includes(c)){o+=2;let w=ye(t,e,o),g=e.slice(o,w),b=ce(t,g,!1,!1,!0,!1,s),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}}o++;let l=ye(t,e,o),u=e.slice(o,l),d=-1,h=0,m=0;for(let p=0;p<u.length;p++){let w=u[p];if(w==="("||w==="[")h++;else if(w===")"||w==="]")h--;else if(w==="?"&&h===0)m++;else if(w===":"&&h===0)if(m>0)m--;else{d=p;break}}let y=d>=0?u.slice(0,d):u,E=d>=0?u.slice(d+1):null;return{operation:{type:"Substring",offset:$t(t,y),length:E?$t(t,E):null},endIndex:l}}if("-=?+".includes(i)){o++;let c=ye(t,e,o),l=e.slice(o,c),u=ce(t,l,!1,!1,!0,!1,s),d=A.word(u.length>0?u:[A.literal("")]);if(i==="-")return{operation:{type:"DefaultValue",word:d,checkEmpty:!1},endIndex:c};if(i==="=")return{operation:{type:"AssignDefault",word:d,checkEmpty:!1},endIndex:c};if(i==="?")return{operation:{type:"ErrorIfUnset",word:l?d:null,checkEmpty:!1},endIndex:c};if(i==="+")return{operation:{type:"UseAlternative",word:d,checkEmpty:!1},endIndex:c}}if(i==="#"||i==="%"){let c=a===i,l=i==="#"?"prefix":"suffix";o+=c?2:1;let u=ye(t,e,o),d=e.slice(o,u),h=ce(t,d,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:A.word(h.length>0?h:[A.literal("")]),side:l,greedy:c},endIndex:u}}if(i==="/"){let c=a==="/";o+=c?2:1;let l=null;e[o]==="#"?(l="start",o++):e[o]==="%"&&(l="end",o++);let u=Ur(t,e,o),d=e.slice(o,u),h=ce(t,d,!1,!1,!1),m=A.word(h.length>0?h:[A.literal("")]),y=null,E=u;if(e[u]==="/"){let p=u+1,w=ye(t,e,p),g=e.slice(p,w),b=ce(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(i==="^"||i===","){let c=a===i,l=i==="^"?"upper":"lower";o+=c?2:1;let u=ye(t,e,o),d=e.slice(o,u),h=d?A.word([A.literal(d)]):null;return{operation:{type:"CaseModification",direction:l,all:c,pattern:h},endIndex:u}}return i==="@"&&/[QPaAEK]/.test(a)?{operation:{type:"Transform",operator:a},endIndex:o+2}:{operation:null,endIndex:o}}function Tt(t,e,n,r=!1){let s=n+1;if(s>=e.length)return{part:A.literal("$"),endIndex:s};let o=e[s];if(o==="("&&e[s+1]==="(")return t.parseArithmeticExpansion(e,n);if(o==="["){let i=1,a=s+1;for(;a<e.length&&i>0;)e[a]==="["?i++:e[a]==="]"&&i--,i>0&&a++;if(i===0){let c=e.slice(s+1,a),l=L(t,c);return{part:A.arithmeticExpansion(l),endIndex:a+1}}}return o==="("?t.parseCommandSubstitution(e,n):o==="{"?gs(t,e,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(o)?Es(t,e,n):{part:A.literal("$"),endIndex:s}}function Ss(t,e){let n=[],r=0,s="",o=()=>{s&&(n.push(A.literal(s)),s="")};for(;r<e.length;){let i=e[r];if(i==="\\"&&r+1<e.length){let a=e[r+1];if(a==="$"||a==="`"){s+=a,r+=2;continue}s+=i,r++;continue}if(i==="$"){o();let{part:a,endIndex:c}=Tt(t,e,r,!0);a&&n.push(a),r=c;continue}if(i==="`"){o();let{part:a,endIndex:c}=t.parseBacktickSubstitution(e,r,!0);n.push(a),r=c;continue}s+=i,r++}return o(),n}function xs(t,e,n){let r=[],s=n,o="",i=()=>{o&&(r.push(A.literal(o)),o="")};for(;s<e.length&&e[s]!=='"';){let a=e[s];if(a==="\\"&&s+1<e.length){let c=e[s+1];if('"\\$`\n'.includes(c)){o+=c,s+=2;continue}o+=a,s++;continue}if(a==="$"){i();let{part:c,endIndex:l}=Tt(t,e,s,!0);c&&r.push(c),s=l;continue}if(a==="`"){i();let{part:c,endIndex:l}=t.parseBacktickSubstitution(e,s,!0);r.push(c),s=l;continue}o+=a,s++}return i(),{part:A.doubleQuoted(r),endIndex:s}}function ce(t,e,n=!1,r=!1,s=!1,o=!1,i=!1){if(r)return[A.singleQuoted(e)];if(n){let d=Ss(t,e);return[A.doubleQuoted(d)]}let a=[],c=0,l="",u=()=>{l&&(a.push(A.literal(l)),l="")};for(;c<e.length;){let d=e[c];if(d==="\\"&&c+1<e.length){let h=e[c+1];(o?h==="$"||h==="`"||h==="\\"||h===`
37
- `:h==="$"||h==="`"||h==="\\"||h==='"'||h===`
38
- `)?l+=h:l+=`\\${h}`,c+=2;continue}if(d==="'"&&!i&&!o){u();let h=e.indexOf("'",c+1);if(h===-1){l+=e.slice(c);break}a.push(A.singleQuoted(e.slice(c+1,h))),c=h+1;continue}if(d==='"'&&!o){u();let{part:h,endIndex:m}=xs(t,e,c+1);a.push(h),c=m+1;continue}if(d==="$"&&e[c+1]==="'"){u();let{part:h,endIndex:m}=Hr(t,e,c+2);a.push(h),c=m;continue}if(d==="$"){u();let{part:h,endIndex:m}=Tt(t,e,c);h&&a.push(h),c=m;continue}if(d==="`"){u();let{part:h,endIndex:m}=t.parseBacktickSubstitution(e,c);a.push(h),c=m;continue}if(d==="~"){let h=c>0?e[c-1]:"";if(c===0||h==="="||s&&h===":"){let y=zr(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(d==="*"||d==="?"||d==="["){u();let{pattern:h,endIndex:m}=Gr(t,e,c);a.push({type:"Glob",pattern:h}),c=m;continue}if(d==="{"&&!s){let h=Vr(t,e,c,ce);if(h){u(),a.push(h.part),c=h.endIndex;continue}}l+=d,c++}return u(),a}var B=class t{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;checkIterationLimit(){if(this.parseIterations++,this.parseIterations>Wr)throw new re("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}parse(e){if(e.length>xt)throw new re(`Input too large: ${e.length} bytes exceeds limit of ${xt}`,1,1);let n=new Ze(e);if(this.tokens=n.tokenize(),this.tokens.length>bt)throw new re(`Too many tokens: ${this.tokens.length} exceeds limit of ${bt}`,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,n,r,s,...o){let i=this.tokens[this.pos]?.type;return i===e||n!==void 0&&i===n||r!==void 0&&i===r||s!==void 0&&i===s?!0:o.length>0?o.includes(i):!1}expect(e,n){if(this.check(e))return this.advance();let r=this.current();throw new re(n||`Expected ${e}, got ${r.type}`,r.line,r.column,r)}error(e){let n=this.current();throw new re(e,n.line,n.column,n)}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,n,r,s){this.pendingHeredocs.push({redirect:e,delimiter:n,stripTabs:r,quoted:s})}processHeredocs(){for(let e of this.pendingHeredocs)if(this.check(f.HEREDOC_CONTENT)){let n=this.advance(),r;e.quoted?r=A.word([A.literal(n.value)]):r=this.parseWordFromString(n.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 s=this.pos,o=this.parseStatement();o&&e.push(o),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===s&&!this.check(f.EOF)&&this.advance()}return A.script(e)}checkUnexpectedToken(){let e=this.current().type,n=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 \`${n}'`),(e===f.RBRACE||e===f.RPAREN)&&this.error(`syntax error near unexpected token \`${n}'`),(e===f.DSEMI||e===f.SEMI_AND||e===f.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),e===f.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`)}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let e=[],n=[],r=!1,s=this.parsePipeline();for(e.push(s);this.check(f.AND_AND,f.OR_OR);){let o=this.advance();n.push(o.type===f.AND_AND?"&&":"||"),this.skipNewlines();let i=this.parsePipeline();e.push(i)}return this.check(f.AMP)&&(this.advance(),r=!0),A.statement(e,n,r)}parsePipeline(){let e=0;for(;this.check(f.BANG);)this.advance(),e++;let n=e%2===1,r=[],s=this.parseCommand();for(r.push(s);this.check(f.PIPE,f.PIPE_AMP);){let o=this.advance();this.skipNewlines();let i=this.parseCommand();o.type===f.PIPE_AMP&&i.type==="SimpleCommand"&&i.redirections.unshift(A.redirection(">&",A.word([A.literal("1")]),2)),r.push(i)}return A.pipeline(r,n)}parseCommand(){return this.check(f.IF)?vt(this):this.check(f.FOR)?Pt(this):this.check(f.WHILE)?It(this):this.check(f.UNTIL)?kt(this):this.check(f.CASE)?Rt(this):this.check(f.LPAREN)?Dt(this):this.check(f.LBRACE)?Ot(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():Qr(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,n=!1,r=!1,s=!1,o=!1){let i=ce(this,e,n,r,s,o);return A.word(i)}parseCommandSubstitution(e,n){let r=n+2,s=1,o=r,i=!1,a=!1,c=0,l=!1,u="";for(;o<e.length&&s>0;){let y=e[o];i?y==="'"&&(i=!1):a?y==="\\"&&o+1<e.length?o++:y==='"'&&(a=!1):y==="'"?(i=!0,u=""):y==='"'?(a=!0,u=""):y==="\\"&&o+1<e.length?(o++,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==="("?o>0&&e[o-1]==="$"?s++:l||s++:y===")"?l?l=!1:s--:y===";"&&c>0&&o+1<e.length&&e[o+1]===";"&&(l=!0)),s>0&&o++}s>0&&this.error("unexpected EOF while looking for matching `)'");let d=e.slice(r,o),m=new t().parse(d);return{part:A.commandSubstitution(m,!1),endIndex:o+1}}parseBacktickSubstitution(e,n,r=!1){let o=n+1,i="";for(;o<e.length&&e[o]!=="`";)if(e[o]==="\\"){let l=e[o+1];l==="$"||l==="`"||l==="\\"||l===`
39
- `||r&&l==='"'?(l!==`
40
- `&&(i+=l),o+=2):(i+=e[o],o++)}else i+=e[o],o++;o>=e.length&&this.error("unexpected EOF while looking for matching ``'");let c=new t().parse(i);return{part:A.commandSubstitution(c,!0),endIndex:o+1}}parseArithmeticExpansion(e,n){let r=n+3,s=1,o=0,i=r;for(;i<e.length-1&&s>0;)e[i]==="$"&&e[i+1]==="("?e[i+2]==="("?(s++,i+=3):(o++,i+=2):e[i]==="("&&e[i+1]==="("?(s++,i+=2):e[i]===")"&&e[i+1]===")"?o>0?(o--,i++):(s--,s>0&&(i+=2)):e[i]==="("?(o++,i++):(e[i]===")"&&o>0&&o--,i++);let a=e.slice(r,i),c=this.parseArithmeticExpression(a);return{part:A.arithmeticExpansion(c),endIndex:i+2}}parseArithmeticCommand(){this.expect(f.DPAREN_START);let e="",n=1,r=0,s=!1,o=!1;for(;n>0&&!this.check(f.EOF);){if(s){if(s=!1,r>0){r--,e+=")";continue}if(this.check(f.RPAREN)){n--,o=!0,this.advance();continue}if(this.check(f.DPAREN_END)){n--,o=!0;continue}e+=")";continue}this.check(f.DPAREN_START)?(n++,e+="((",this.advance()):this.check(f.DPAREN_END)?r>=2?(r-=2,e+="))",this.advance()):r===1?(r--,e+=")",s=!0,this.advance()):(n--,o=!0,n>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())}o||this.expect(f.DPAREN_END);let i=this.parseArithmeticExpression(e.trim()),a=this.parseOptionalRedirections();return A.arithmeticCommand(i,a)}parseConditionalCommand(){this.expect(f.DBRACK_START);let e=Lt(this);this.expect(f.DBRACK_END);let n=this.parseOptionalRedirections();return A.conditionalCommand(e,n)}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 n=this.parseCompoundCommandBody(),r=this.parseOptionalRedirections();return A.functionDef(e,n,r)}parseCompoundCommandBody(){if(this.check(f.LBRACE))return Ot(this);if(this.check(f.LPAREN))return Dt(this);if(this.check(f.IF))return vt(this);if(this.check(f.FOR))return Pt(this);if(this.check(f.WHILE))return It(this);if(this.check(f.UNTIL))return kt(this);if(this.check(f.CASE))return Rt(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 n=this.pos,r=this.parseStatement();if(r&&e.push(r),this.skipSeparators(),this.pos===n&&!r)break}return e}parseOptionalRedirections(){let e=[];for(;Qe(this);){this.checkIterationLimit();let n=this.pos;if(e.push(Ke(this)),this.pos===n)break}return e}parseArithmeticExpression(e){return L(this,e)}};function le(t){return new B().parse(t)}var Ce=class{fs;cwd;constructor(e,n){this.fs=e,this.cwd=n}isGlobPattern(e){return e.includes("*")||e.includes("?")||/\[.*\]/.test(e)}async expandArgs(e,n){let r=e.map((i,a)=>(n?.[a]??!1)||!this.isGlobPattern(i)?null:this.expand(i)),s=await Promise.all(r.map(i=>i||Promise.resolve(null))),o=[];for(let i=0;i<e.length;i++){let a=s[i];a===null?o.push(e[i]):a.length>0?o.push(...a):o.push(e[i])}return o}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 n=e.startsWith("/"),r=e.split("/").filter(l=>l!==""),s=-1;for(let l=0;l<r.length;l++)if(this.hasGlobChars(r[l])){s=l;break}if(s===-1)return[e];let o,i;if(s===0)n?(o="/",i="/"):(o=this.cwd,i="");else{let l=r.slice(0,s);n?(o=`/${l.join("/")}`,i=`/${l.join("/")}`):(o=this.fs.resolvePath(this.cwd,l.join("/")),i=l.join("/"))}let a=r.slice(s);return(await this.expandSegments(o,i,a)).sort()}async expandSegments(e,n,r){if(r.length===0)return[n];let[s,...o]=r,i=[];try{if(this.fs.readdirWithFileTypes){let a=await this.fs.readdirWithFileTypes(e),c=[];for(let u of a)if(!(u.name.startsWith(".")&&!s.startsWith("."))&&this.matchPattern(u.name,s)){let d=e==="/"?`/${u.name}`:`${e}/${u.name}`,h;n===""?h=u.name:n==="/"?h=`/${u.name}`:h=`${n}/${u.name}`,o.length===0?c.push(Promise.resolve([h])):u.isDirectory&&c.push(this.expandSegments(d,h,o))}let l=await Promise.all(c);for(let u of l)i.push(...u)}else{let a=await this.fs.readdir(e),c=[];for(let u of a)if(!(u.startsWith(".")&&!s.startsWith("."))&&this.matchPattern(u,s)){let d=e==="/"?`/${u}`:`${e}/${u}`,h;n===""?h=u:n==="/"?h=`/${u}`:h=`${n}/${u}`,o.length===0?c.push(Promise.resolve([h])):c.push((async()=>{try{if((await this.fs.stat(d)).isDirectory)return this.expandSegments(d,h,o)}catch{}return[]})())}let l=await Promise.all(c);for(let u of l)i.push(...u)}}catch{}return i}async expandRecursive(e){let n=[],r=e.indexOf("**"),s=e.slice(0,r).replace(/\/$/,"")||".",i=e.slice(r+2).replace(/^\//,"");return await this.walkDirectory(s,i,n),n.sort()}async walkDirectory(e,n,r){let s=this.fs.resolvePath(this.cwd,e);try{if(this.fs.readdirWithFileTypes){let o=await this.fs.readdirWithFileTypes(s),i=[],a=[];for(let c of o){let l=e==="."?c.name:`${e}/${c.name}`;c.isDirectory?a.push(l):n&&this.matchPattern(c.name,n)&&i.push(l)}r.push(...i);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,n,r)))}}else{let o=await this.fs.readdir(s),i=[];for(let c=0;c<o.length;c+=100){let l=o.slice(c,c+100),u=await Promise.all(l.map(async d=>{let h=e==="."?d:`${e}/${d}`,m=this.fs.resolvePath(this.cwd,h);try{let y=await this.fs.stat(m);return{name:d,path:h,isDirectory:y.isDirectory}}catch{return null}}));i.push(...u.filter(d=>d!==null))}for(let c of i)!c.isDirectory&&n&&this.matchPattern(c.name,n)&&r.push(c.path);let a=i.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,n,r)))}}}catch{}}matchPattern(e,n){return this.patternToRegex(n).test(e)}patternToRegex(e){let n="^";for(let r=0;r<e.length;r++){let s=e[r];if(s==="*")n+=".*";else if(s==="?")n+=".";else if(s==="["){let o=r+1,i="[";for(o<e.length&&(e[o]==="^"||e[o]==="!")&&(i+="^",o++),o<e.length&&e[o]==="]"&&(i+="\\]",o++);o<e.length&&e[o]!=="]";){if(e[o]==="["&&o+1<e.length&&e[o+1]===":"){let a=e.indexOf(":]",o+2);if(a!==-1){let c=e.slice(o+2,a),l=this.posixClassToRegex(c);i+=l,o=a+2;continue}}if(e[o]==="\\"&&o+1<e.length){i+=`\\${e[o+1]}`,o+=2;continue}e[o]==="-"?i+="\\-":i+=e[o],o++}i+="]",n+=i,r=o}else if(s==="\\"&&r+1<e.length){let o=e[r+1];/[.+^${}()|\\*?[\]]/.test(o)?n+=`\\${o}`:n+=o,r++}else/[.+^${}()|]/.test(s)?n+=`\\${s}`:n+=s}return n+="$",new RegExp(n)}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 q(t){switch(t.type){case"ArithCommandSubst":return!0;case"ArithNested":return q(t.expression);case"ArithBinary":return q(t.left)||q(t.right);case"ArithUnary":return q(t.operand);case"ArithTernary":return q(t.condition)||q(t.consequent)||q(t.alternate);case"ArithAssignment":return q(t.value);case"ArithGroup":return q(t.expression);case"ArithArrayElement":return t.index?q(t.index):!1;case"ArithConcat":return t.parts.some(q);default:return!1}}function Wt(t){let e=t.operation;return e?!!("word"in e&&e.word&&ne(e.word)||e.type==="PatternReplacement"&&(e.pattern&&ne(e.pattern)||e.replacement&&ne(e.replacement))||e.type==="PatternRemoval"&&e.pattern&&ne(e.pattern)):!1}function Xe(t){switch(t.type){case"CommandSubstitution":return!0;case"ArithmeticExpansion":return q(t.expression.expression);case"DoubleQuoted":return t.parts.some(Xe);case"BraceExpansion":return t.items.some(e=>e.type==="Word"&&ne(e.word));case"ParameterExpansion":return Wt(t);default:return!1}}function ne(t){return t.parts.some(Xe)}function Ft(t){if(!t.operation)return!1;let e=t.operation,n;if((e.type==="DefaultValue"||e.type==="AssignDefault"||e.type==="UseAlternative"||e.type==="ErrorIfUnset")&&(n=e.word?.parts),!n)return!1;for(let r of n)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function Xr(t){let e=!1,n=!1,r=!1,s=!1,o=!1;for(let i of t){if((i.type==="SingleQuoted"||i.type==="DoubleQuoted")&&(e=!0,i.type==="DoubleQuoted"))for(let a of i.parts)a.type==="ParameterExpansion"&&a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&!a.operation&&(s=!0);i.type==="CommandSubstitution"&&(n=!0),i.type==="ParameterExpansion"&&(o=!0,(i.parameter==="@"||i.parameter==="*")&&(r=!0),Ft(i)&&(e=!0))}return{hasQuoted:e,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:o}}function Cs(t,e,n,r,s){let o=n??1;o===0&&(o=1);let i=Math.abs(o),a=[],c=0;r?.match(/^-?0\d/)&&(c=Math.max(c,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(c=Math.max(c,s.replace(/^-/,"").length));let l=u=>{if(c>0){let d=u<0,h=String(Math.abs(u)).padStart(c,"0");return d?`-${h}`:h}return String(u)};if(t<=e)for(let u=t,d=0;u<=e&&d<1e4;u+=i,d++)a.push(l(u));else for(let u=t,d=0;u>=e&&d<1e4;u-=i,d++)a.push(l(u));return a}function $s(t,e,n){let r=n??1;r===0&&(r=1);let s=t.charCodeAt(0),o=e.charCodeAt(0),i=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 d=[];if(s<=o)for(let h=s,m=0;h<=o&&m<1e4;h+=i,m++)d.push(String.fromCharCode(h));else for(let h=s,m=0;h>=o&&m<1e4;h-=i,m++)d.push(String.fromCharCode(h));return d}function De(t,e,n,r,s){let o=n!==void 0?`..${n}`:"";return typeof t=="number"&&typeof e=="number"?{expanded:Cs(t,e,n,r,s),literal:`{${t}..${e}${o}}`}:typeof t=="string"&&typeof e=="string"?{expanded:$s(t,e,n),literal:`{${t}..${e}${o}}`}:{expanded:null,literal:`{${t}..${e}${o}}`}}function H(t,e){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\")if(r+1<t.length){let o=t[r+1];/[\\^$.|+(){}[\]*?]/.test(o)?n+=`\\${o}`:n+=o,r+=2}else n+="\\\\",r++;else if(s==="*")n+=e?".*":".*?",r++;else if(s==="?")n+=".",r++;else if(s==="["){let o=Ns(t,r);if(o===-1)n+="\\[",r++;else{let i=t.slice(r+1,o);n+=vs(i),r=o+1}}else/[\^$.|+(){}]/.test(s)?(n+=`\\${s}`,r++):(n+=s,r++)}return n}function Ns(t,e){let n=e+1;for(n<t.length&&t[n]==="^"&&n++,n<t.length&&t[n]==="]"&&n++;n<t.length;){if(t[n]==="\\"&&n+1<t.length){n+=2;continue}if(t[n]==="]")return n;if(t[n]==="'"){let r=t.indexOf("'",n+1);if(r!==-1){n=r+1;continue}}if(t[n]==="["&&n+1<t.length&&t[n+1]===":"){let r=t.indexOf(":]",n+2);if(r!==-1){n=r+2;continue}}n++}return-1}function vs(t){let e="[",n=0;for((t[0]==="^"||t[0]==="!")&&(e+="^",n++);n<t.length;){if(t[n]==="'"){let s=t.indexOf("'",n+1);if(s!==-1){let o=t.slice(n+1,s);for(let i of o)i==="\\"?e+="\\\\":i==="]"?e+="\\]":i==="^"&&e==="["?e+="\\^":e+=i;n=s+1;continue}}if(t[n]==="["&&n+1<t.length&&t[n+1]===":"){let s=t.indexOf(":]",n+2);if(s!==-1){let o=t.slice(n+2,s);e+=Is(o),n=s+2;continue}}let r=t[n];r==="\\"?n+1<t.length?(e+=`\\${t[n+1]}`,n+=2):(e+="\\\\",n++):r==="-"&&n>0&&n<t.length-1?(e+="-",n++):r==="^"&&n===0?(e+="^",n++):(r==="]"&&n===0?e+="\\]":e+=r,n++)}return e+="]",e}var Ps={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 Is(t){return Ps[t]??""}function Oe(t,e){let n=`${e}_`,r=[];for(let s of Object.keys(t.state.env))if(s.startsWith(n)){let o=s.slice(n.length),i=Number.parseInt(o,10);!Number.isNaN(i)&&String(i)===o&&r.push(i)}return r.sort((s,o)=>s-o)}function _e(t,e){let n=`${e}_`;for(let r of Object.keys(t.state.env))r.startsWith(n)&&delete t.state.env[r]}function Mt(t,e){let n=`${e}_`,r=[];for(let s of Object.keys(t.state.env))if(s.startsWith(n)&&!s.includes("__")){let o=s.slice(n.length);r.push(o)}return r.sort()}function Yr(t){return t.startsWith("'")&&t.endsWith("'")||t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function Ye(t){return t.IFS??`
41
- `}function Jr(t){return t.IFS===""}function Le(t){return t.split("").map(e=>/[\\^$.*+?()[\]{}|-]/.test(e)?`\\${e}`:e===" "?"\\t":e===`
42
- `?"\\n":e).join("")}function ks(t,e){let n=Le(t);return new RegExp(`[${n}]+`,e)}function Rs(t){let e=Le(t);return new RegExp(`^[${e}]+`)}function Ds(t){let e=Le(t);return new RegExp(`[${e}]+$`)}function $e(t){let e=t.IFS;return e===void 0?" ":e[0]||""}function en(t,e){if(e==="")return{words:[t],wordStarts:[0]};let n=[],r=[],s=ks(e,"g"),o=0,i=t.match(Rs(e));i&&(o=i[0].length),s.lastIndex=o;let a=s.exec(t);for(;a!==null;)a.index>o&&(r.push(o),n.push(t.substring(o,a.index))),o=s.lastIndex,a=s.exec(t);return o<t.length&&(r.push(o),n.push(t.substring(o))),{words:n,wordStarts:r}}function tn(t,e){return e===""?t:t.replace(Ds(e),"")}function T(t,e){return t.state.associativeArrays?.has(e)?Mt(t,e).map(o=>[o,t.state.env[`${e}_${o}`]]):Oe(t,e).map(s=>[s,t.state.env[`${e}_${s}`]])}function rn(t,e){return t.state.associativeArrays?.has(e)?Mt(t,e).length>0:Oe(t,e).length>0}function Z(t,e,n=!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 i="";return t.state.options.errexit&&(i+="e"),t.state.options.nounset&&(i+="u"),t.state.options.verbose&&(i+="v"),t.state.options.xtrace&&(i+="x"),t.state.options.pipefail&&(i+="p"),i}case"*":{let i=Number.parseInt(t.state.env["#"]||"0",10);if(i===0)return"";let a=[];for(let c=1;c<=i;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:i}=Re();return String(i)}case"UID":{let{uid:i}=Re();return String(i)}case"EUID":return String(process.geteuid?.()??Re().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 Sr;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 pe(`\${${e}}`);let s=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let i=s[1],a=s[2];if(a==="@"||a==="*"){let d=T(t,i);if(d.length>0)return d.map(([,m])=>m).join(" ");let h=t.state.env[i];return h!==void 0?h:""}if(t.state.associativeArrays?.has(i)){let d=Yr(a),h=t.state.env[`${i}_${d}`];if(h===void 0&&n&&t.state.options.nounset)throw new J(`${i}[${a}]`);return h||""}let l;if(/^-?\d+$/.test(a))l=Number.parseInt(a,10);else try{let d=new B,h=L(d,a);l=N(t,h.expression)}catch{let d=t.state.env[a];l=d?Number.parseInt(d,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let d=T(t,i);if(d.length===0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${i}: bad array subscript
43
- `,"";let m=Math.max(...d.map(([E])=>typeof E=="number"?E:0))+1+l;return m<0?(t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${i}: bad array subscript
44
- `,""):t.state.env[`${i}_${m}`]||""}let u=t.state.env[`${i}_${l}`];if(u===void 0&&n&&t.state.options.nounset)throw new J(`${i}[${l}]`);return u||""}if(/^[1-9][0-9]*$/.test(e)){let i=t.state.env[e];if(i===void 0&&n&&t.state.options.nounset)throw new J(e);return i||""}let o=t.state.env[e];if(o===void 0&&n&&t.state.options.nounset)throw new J(e);return o||""}async function nn(t,e,n,r,s){let o=[];for(let u of e){let d=u.type==="ParameterExpansion"||u.type==="CommandSubstitution"||u.type==="ArithmeticExpansion";if(u.type==="ParameterExpansion"&&Ft(u)){let h=await s(t,u);o.push({value:h,splittable:!1})}else{let h=await s(t,u);o.push({value:h,splittable:d})}}if(!o.some(u=>u.splittable&&new RegExp(`[${r}]`).test(u.value))){let u=o.map(d=>d.value).join("");return u?[u]:[]}let a=new RegExp(`[${r}]+`),c=[],l="";for(let u=0;u<o.length;u++){let d=o[u];if(!d.splittable)l+=d.value;else{let h=d.value.split(a);for(let m=0;m<h.length;m++)m===0?l+=h[m]:(l!==""&&c.push(l),l=h[m])}}return l!==""&&c.push(l),c}function V(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function sn(t){switch(t.type){case"Literal":return t.value;case"SingleQuoted":return t.value;case"Escaped":return t.value;default:return null}}function on(t){switch(t.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return t.value==="";default:return!1}}function Bt(t){if(t==="")return"''";if(!/['\\\n\r\t\x00-\x1f\x7f]/.test(t))return`'${t}'`;let e="$'";for(let n of t)switch(n){case"'":e+="\\'";break;case"\\":e+="\\\\";break;case`
45
- `:e+="\\n";break;case"\r":e+="\\r";break;case" ":e+="\\t";break;default:{let r=n.charCodeAt(0);r<32||r===127?e+=`\\x${r.toString(16).padStart(2,"0")}`:e+=n}}return`${e}'`}function we(t,e,n=!1){return e.map(r=>se(t,r,n)).join("")}async function Ee(t,e,n=!1){let r=[];for(let s of e)r.push(await Q(t,s));return r.join("")}function Os(t){return on(t)}function an(t){if(t.parts.length===0)return!0;for(let e of t.parts)if(!Os(e))return!1;return!0}function cn(t){return t.replace(/([*?[\]\\])/g,"\\$1")}function ln(t,e,n=!1){let r=sn(e);if(r!==null)return r;switch(e.type){case"ParameterExpansion":return mn(t,e,n);case"TildeExpansion":return n?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 se(t,e,n=!1){let r=ln(t,e,n);if(r!==null)return r;switch(e.type){case"DoubleQuoted":{let s=[];for(let o of e.parts)s.push(se(t,o,!0));return s.join("")}case"ArithmeticExpansion":return String(N(t,e.expression.expression));case"BraceExpansion":{let s=[];for(let o of e.items)if(o.type==="Range"){let i=De(o.start,o.end,o.step,o.startStr,o.endStr);if(i.expanded)s.push(...i.expanded);else return i.literal}else s.push(Je(t,o.word));return s.join(" ")}default:return""}}function Je(t,e){let n=e.parts,r=n.length;if(r===1)return se(t,n[0]);let s=[];for(let o=0;o<r;o++)s.push(se(t,n[o]));return s.join("")}async function P(t,e){return ne(e)?hn(t,e):Je(t,e)}function et(t){for(let e of t)if(e.type==="BraceExpansion"||e.type==="DoubleQuoted"&&et(e.parts))return!0;return!1}function _s(t){for(let e of t){if(e.type==="BraceExpansion"){for(let n of e.items)if(n.type==="Word"&&ne(n.word))return!0}if(Xe(e))return!0}return!1}var un=1e4,Ne=1e5;function fn(t,e,n={count:0}){if(n.count>Ne)return[[]];let r=[[]];for(let s of e)if(s.type==="BraceExpansion"){let o=[],i=!1,a="";for(let u of s.items)if(u.type==="Range"){let d=De(u.start,u.end,u.step,u.startStr,u.endStr);if(d.expanded)for(let h of d.expanded)n.count++,o.push(h);else{i=!0,a=d.literal;break}}else{let d=fn(t,u.word.parts,n);for(let h of d)n.count++,o.push(h.join(""))}if(i){for(let u of r)n.count++,u.push(a);continue}if(r.length*o.length>un||n.count>Ne)return r;let l=[];for(let u of r)for(let d of o){if(n.count++,n.count>Ne)return l.length>0?l:r;l.push([...u,d])}r=l}else{let o=se(t,s);for(let i of r)n.count++,i.push(o)}return r}function Ls(t,e){let n=e.parts;return et(n)?fn(t,n).map(s=>s.join("")):[Je(t,e)]}async function dn(t,e,n={count:0}){if(n.count>Ne)return[[]];let r=[[]];for(let s of e)if(s.type==="BraceExpansion"){let o=[],i=!1,a="";for(let u of s.items)if(u.type==="Range"){let d=De(u.start,u.end,u.step,u.startStr,u.endStr);if(d.expanded)for(let h of d.expanded)n.count++,o.push(h);else{i=!0,a=d.literal;break}}else{let d=await dn(t,u.word.parts,n);for(let h of d)n.count++,o.push(h.join(""))}if(i){for(let u of r)n.count++,u.push(a);continue}if(r.length*o.length>un||n.count>Ne)return r;let l=[];for(let u of r)for(let d of o){if(n.count++,n.count>Ne)return l.length>0?l:r;l.push([...u,d])}r=l}else{let o=await Q(t,s);for(let i of r)n.count++,i.push(o)}return r}async function Ts(t,e){let n=e.parts;return et(n)?(await dn(t,n)).map(s=>s.join("")):[await P(t,e)]}async function Te(t,e){let n=e.parts,{hasQuoted:r,hasCommandSub:s,hasArrayVar:o,hasArrayAtExpansion:i,hasParamExpansion:a}=Xr(n),l=et(n)?_s(n)?await Ts(t,e):Ls(t,e):null;if(l&&l.length>1){let h=[];for(let m of l)if(!r&&/[*?[]/.test(m)){let E=await new Ce(t.fs,t.state.cwd).expand(m);E.length>0?h.push(...E):h.push(m)}else h.push(m);return{values:h,quoted:!1}}if(i&&n.length===1&&n[0].type==="DoubleQuoted"){let h=n[0];if(h.parts.length===1&&h.parts[0].type==="ParameterExpansion"){let y=h.parts[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@]\]$/);if(y){let E=y[1],p=T(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(n.length===1&&n[0].type==="DoubleQuoted"){let h=n[0],m=-1,y=!1;for(let E=0;E<h.parts.length;E++){let p=h.parts[E];if(p.type==="ParameterExpansion"&&(p.parameter==="@"||p.parameter==="*")){m=E,y=p.parameter==="*";break}}if(m!==-1){let E=h.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 Q(t,h.parts[C]);let w="";for(let C=m+1;C<h.parts.length;C++)w+=await Q(t,h.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((s||o||a)&&!Jr(t.state.env)){let h=Ye(t.state.env),m=Le(h),y=await nn(t,n,h,m,Q),E=[],p=new Ce(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 d=ne(e)?await hn(t,e):Je(t,e);if(!r&&/[*?[]/.test(d)){let m=await new Ce(t.fs,t.state.cwd).expand(d);if(m.length>0)return{values:m,quoted:!1}}return d===""&&!r?{values:[],quoted:!1}:{values:[d],quoted:r}}async function hn(t,e){let n=e.parts,r=n.length;if(r===1)return Q(t,n[0]);let s=[];for(let o=0;o<r;o++)s.push(await Q(t,n[o]));return s.join("")}async function Q(t,e){if(e.type==="ParameterExpansion"&&Wt(e))return Ws(t,e);let n=ln(t,e);if(n!==null)return n;switch(e.type){case"DoubleQuoted":{let r=[];for(let s of e.parts)r.push(await Q(t,s));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 z)throw r;if(r instanceof k)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 s of e.items)if(s.type==="Range"){let o=De(s.start,s.end,s.step,s.startStr,s.endStr);if(o.expanded)r.push(...o.expanded);else return o.literal}else r.push(await P(t,s.word));return r.join(" ")}default:return""}}function mn(t,e,n=!1){let{parameter:r,operation:s}=e,o=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),i=Z(t,r,!o);if(!s)return i;let a=!(r in t.state.env),c=i==="";switch(s.type){case"DefaultValue":return(a||s.checkEmpty&&c)&&s.word?we(t,s.word.parts,n):i;case"AssignDefault":{if((a||s.checkEmpty&&c)&&s.word){let u=we(t,s.word.parts,n),d=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(d){let[,h,m]=d,y;if(/^\d+$/.test(m))y=Number.parseInt(m,10);else{try{let p=new B,w=L(p,m);y=N(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[`${h}_${y}`]=u;let E=Number.parseInt(t.state.env[`${h}__length`]||"0",10);y>=E&&(t.state.env[`${h}__length`]=String(y+1))}else t.state.env[r]=u;return u}return i}case"ErrorIfUnset":{if(a||s.checkEmpty&&c){let u=s.word?we(t,s.word.parts,n):`${r}: parameter null or not set`;throw new k(1,"",`bash: ${u}
46
- `)}return i}case"UseAlternative":return!(a||s.checkEmpty&&c)&&s.word?we(t,s.word.parts,n):"";case"Length":{let l=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(l){let u=T(t,l[1]);return String(u.length)}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&rn(t,r)){let u=t.state.env[`${r}_0`]||"";return String(u.length)}return String(i.length)}case"LengthSliceError":throw new pe(r);case"Substring":{let l=s.offset?N(t,s.offset.expression):0,u=s.length?N(t,s.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 d=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(d){let E=T(t,d[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 h=[...i],m=l;if(m<0&&(m=Math.max(0,h.length+m)),u!==void 0){if(u<0){let y=h.length+u;return h.slice(m,Math.max(m,y)).join("")}return h.slice(m,m+u).join("")}return h.slice(m).join("")}case"PatternRemoval":{let l="";if(s.pattern)for(let d of s.pattern.parts)if(d.type==="Glob")l+=H(d.pattern,s.greedy);else if(d.type==="Literal")l+=H(d.value,s.greedy);else if(d.type==="SingleQuoted"||d.type==="Escaped")l+=V(d.value);else if(d.type==="DoubleQuoted"){let h=we(t,d.parts);l+=V(h)}else if(d.type==="ParameterExpansion"){let h=se(t,d);l+=H(h,s.greedy)}else{let h=se(t,d);l+=V(h)}if(s.side==="prefix")return i.replace(new RegExp(`^${l}`),"");let u=new RegExp(`${l}$`);if(s.greedy)return i.replace(u,"");for(let d=i.length;d>=0;d--){let h=i.slice(d);if(u.test(h))return i.slice(0,d)}return i}case"PatternReplacement":{let l="";if(s.pattern)for(let h of s.pattern.parts)if(h.type==="Glob")l+=H(h.pattern,!0);else if(h.type==="Literal")l+=H(h.value,!0);else if(h.type==="SingleQuoted"||h.type==="Escaped")l+=V(h.value);else if(h.type==="DoubleQuoted"){let m=we(t,h.parts);l+=V(m)}else if(h.type==="ParameterExpansion"){let m=se(t,h);l+=H(m,!0)}else{let m=se(t,h);l+=V(m)}let u=s.replacement?we(t,s.replacement.parts):"";if(l==="")return i;s.anchor==="start"?l=`^${l}`:s.anchor==="end"&&(l=`${l}$`);let d=s.all?"g":"";try{let h=new RegExp(l,d);if(s.all){let m="",y=0,E=h.exec(i);for(;E!==null&&!(E[0].length===0&&E.index===i.length);)m+=i.slice(y,E.index)+u,y=E.index+E[0].length,E[0].length===0&&y++,E=h.exec(i);return m+=i.slice(y),m}return i.replace(h,u)}catch{return i}}case"CaseModification":return s.direction==="upper"?s.all?i.toUpperCase():i.charAt(0).toUpperCase()+i.slice(1):s.all?i.toLowerCase():i.charAt(0).toLowerCase()+i.slice(1);case"Transform":{let l=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(l&&s.operator==="Q")return T(t,l[1]).map(([,h])=>Bt(h)).join(" ");switch(s.operator){case"Q":return Bt(i);case"P":return i;case"a":return"";case"A":return`${r}=${Bt(i)}`;case"E":return i.replace(/\\([\\abefnrtv'"?])/g,(u,d)=>{switch(d){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
47
- `;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return d}});case"K":return"";default:return i}}case"Indirection":return Z(t,i);case"ArrayKeys":{let u=T(t,s.array).map(([d])=>String(d));return s.star?u.join($e(t.state.env)):u.join(" ")}case"VarNamePrefix":{let l=Object.keys(t.state.env).filter(u=>u.startsWith(s.prefix)&&!u.includes("__")).sort();return s.star?l.join($e(t.state.env)):l.join(" ")}default:return i}}async function Ws(t,e,n=!1){let{parameter:r,operation:s}=e,o=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),i=Z(t,r,!o);if(!s)return i;let a=!(r in t.state.env),c=i==="";switch(s.type){case"DefaultValue":return(a||s.checkEmpty&&c)&&s.word?Ee(t,s.word.parts,n):i;case"AssignDefault":{if((a||s.checkEmpty&&c)&&s.word){let u=await Ee(t,s.word.parts,n),d=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(d){let[,h,m]=d,y;if(/^\d+$/.test(m))y=Number.parseInt(m,10);else{try{let p=new B,w=L(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[`${h}_${y}`]=u;let E=Number.parseInt(t.state.env[`${h}__length`]||"0",10);y>=E&&(t.state.env[`${h}__length`]=String(y+1))}else t.state.env[r]=u;return u}return i}case"ErrorIfUnset":{if(a||s.checkEmpty&&c){let u=s.word?await Ee(t,s.word.parts,n):`${r}: parameter null or not set`;throw new k(1,"",`bash: ${u}
48
- `)}return i}case"UseAlternative":return!(a||s.checkEmpty&&c)&&s.word?Ee(t,s.word.parts,n):"";case"PatternRemoval":{let l="";if(s.pattern)for(let d of s.pattern.parts)if(d.type==="Glob")l+=H(d.pattern,s.greedy);else if(d.type==="Literal")l+=H(d.value,s.greedy);else if(d.type==="SingleQuoted"||d.type==="Escaped")l+=V(d.value);else if(d.type==="DoubleQuoted"){let h=await Ee(t,d.parts);l+=V(h)}else if(d.type==="ParameterExpansion"){let h=await Q(t,d);l+=H(h,s.greedy)}else{let h=await Q(t,d);l+=V(h)}if(s.side==="prefix")return i.replace(new RegExp(`^${l}`),"");let u=new RegExp(`${l}$`);if(s.greedy)return i.replace(u,"");for(let d=i.length;d>=0;d--){let h=i.slice(d);if(u.test(h))return i.slice(0,d)}return i}case"PatternReplacement":{let l="";if(s.pattern)for(let h of s.pattern.parts)if(h.type==="Glob")l+=H(h.pattern,!0);else if(h.type==="Literal")l+=H(h.value,!0);else if(h.type==="SingleQuoted"||h.type==="Escaped")l+=V(h.value);else if(h.type==="DoubleQuoted"){let m=await Ee(t,h.parts);l+=V(m)}else if(h.type==="ParameterExpansion"){let m=await Q(t,h);l+=H(m,!0)}else{let m=await Q(t,h);l+=V(m)}let u=s.replacement?await Ee(t,s.replacement.parts):"";if(l==="")return i;s.anchor==="start"?l=`^${l}`:s.anchor==="end"&&(l=`${l}$`);let d=s.all?"g":"";try{let h=new RegExp(l,d);if(s.all){let m="",y=0,E=h.exec(i);for(;E!==null&&!(E[0].length===0&&E.index===i.length);)m+=i.slice(y,E.index)+u,y=E.index+E[0].length,E[0].length===0&&y++,E=h.exec(i);return m+=i.slice(y),m}return i.replace(h,u)}catch{return i}}default:return mn(t,e,n)}}function zt(t,e,n){switch(n){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 F("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 pn(t,e,n){switch(n){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 Ut(t,e){switch(e){case"-":return-t;case"+":return+t;case"!":return t===0?1:0;case"~":return~t;default:return t}}function Fs(t,e){let n=t.state.env[e];if(n!==void 0)return n;let r=t.state.env[`${e}_0`];return r!==void 0?r:Z(t,e)}function ve(t){if(!t)return 0;let e=Number.parseInt(t,10);if(!Number.isNaN(e)&&/^-?\d+$/.test(t.trim()))return e;let n=t.trim();if(!n)return 0;try{let r=new B,{expr:s,pos:o}=te(r,n,0);if(o<n.length){let i=n.slice(o).trim().split(/\s+/)[0];throw new F(`${n}: syntax error in expression (error token is "${i}")`)}return s.type==="ArithNumber"?s.value:e||0}catch(r){if(r instanceof F)throw r;let s=n.split(/\s+/).slice(1)[0]||n;throw new F(`${n}: syntax error in expression (error token is "${s}")`)}}function tt(t,e,n=new Set){if(n.has(e))return 0;n.add(e);let r=Fs(t,e);if(!r)return 0;let s=Number.parseInt(r,10);if(!Number.isNaN(s)&&/^-?\d+$/.test(r.trim()))return s;let o=r.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o))return tt(t,o,n);try{let i=new B,{expr:a}=te(i,o,0);return K(t,a,n)}catch{return 0}}function K(t,e,n){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new F("value too great for base");return e.value;case"ArithVariable":return tt(t,e.name,n);case"ArithBinary":{if(e.operator==="||")return K(t,e.left,n)||K(t,e.right,n)?1:0;if(e.operator==="&&")return K(t,e.left,n)&&K(t,e.right,n)?1:0;let r=K(t,e.left,n),s=K(t,e.right,n);return zt(r,s,e.operator)}case"ArithUnary":{let r=K(t,e.operand,n);return Ut(r,e.operator)}case"ArithTernary":return K(t,e.condition,n)?K(t,e.consequent,n):K(t,e.alternate,n);case"ArithGroup":return K(t,e.expression,n);default:return N(t,e)}}function ue(t,e){if(e.startsWith("#")){let d=e.slice(1),h=t.state.env[d]||"";return String(h.length)}if(e.startsWith("!")){let d=e.slice(1),h=t.state.env[d]||"";return t.state.env[h]||""}let n=[":-",":=",":?",":+","-","=","?","+"],r=-1,s="";for(let d of n){let h=e.indexOf(d);h>0&&(r===-1||h<r)&&(r=h,s=d)}if(r===-1)return Z(t,e);let o=e.slice(0,r),i=e.slice(r+s.length),a=t.state.env[o],c=a===void 0,l=a==="",u=s.startsWith(":");switch(s){case":-":case"-":return c||u&&l?i:a||"";case":=":case"=":return c||u&&l?(t.state.env[o]=i,i):a||"";case":+":case"+":return!(c||u&&l)?i:"";case":?":case"?":{if(c||u&&l)throw new Error(i||`${o}: parameter null or not set`);return a||""}default:return a||""}}function N(t,e){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new F("value too great for base");return e.value;case"ArithVariable":return tt(t,e.name);case"ArithNested":return N(t,e.expression);case"ArithCommandSubst":return 0;case"ArithBracedExpansion":{let n=ue(t,e.content);return Number.parseInt(n,10)||0}case"ArithDynamicBase":{let n=ue(t,e.baseExpr),r=Number.parseInt(n,10);if(r<2||r>64)return 0;let s=`${r}#${e.value}`;return xe(s)}case"ArithDynamicNumber":{let r=ue(t,e.prefix)+e.suffix;return xe(r)}case"ArithArrayElement":{let n=t.state.associativeArrays?.has(e.array),r;if(e.stringKey!==void 0)r=`${e.array}_${e.stringKey}`;else if(n&&e.index?.type==="ArithVariable")r=`${e.array}_${e.index.name}`;else if(e.index){let o=N(t,e.index);if(o<0){let a=T(t,e.array);if(a.length===0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${e.array}: bad array subscript
49
- `,0;let l=Math.max(...a.map(([u])=>typeof u=="number"?u:0))+1+o;if(l<0)return t.state.expansionStderr=(t.state.expansionStderr||"")+`bash: ${e.array}: bad array subscript
50
- `,0;o=l}r=`${e.array}_${o}`;let i=t.state.env[r];if(i!==void 0)return ve(i);if(o===0){let a=t.state.env[e.array];if(a!==void 0)return ve(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}[${o}]`);return 0}else return 0;let s=t.state.env[r];return s!==void 0?ve(s):0}case"ArithDoubleSubscript":throw new F("double subscript","","");case"ArithNumberSubscript":throw new F(`${e.number}${e.errorToken}: syntax error: invalid arithmetic operator (error token is "${e.errorToken}")`);case"ArithBinary":{if(e.operator==="||")return N(t,e.left)||N(t,e.right)?1:0;if(e.operator==="&&")return N(t,e.left)&&N(t,e.right)?1:0;let n=N(t,e.left),r=N(t,e.right);return zt(n,r,e.operator)}case"ArithUnary":{let n=N(t,e.operand);if(e.operator==="++"||e.operator==="--"){if(e.operand.type==="ArithVariable"){let r=e.operand.name,s=Number.parseInt(Z(t,r),10)||0,o=e.operator==="++"?s+1:s-1;return t.state.env[r]=String(o),e.prefix?o:s}if(e.operand.type==="ArithArrayElement"){let r=e.operand.array,s=t.state.associativeArrays?.has(r),o;if(e.operand.stringKey!==void 0)o=`${r}_${e.operand.stringKey}`;else if(s&&e.operand.index?.type==="ArithVariable")o=`${r}_${e.operand.index.name}`;else if(e.operand.index){let c=N(t,e.operand.index);o=`${r}_${c}`}else return n;let i=Number.parseInt(t.state.env[o]||"0",10)||0,a=e.operator==="++"?i+1:i-1;return t.state.env[o]=String(a),e.prefix?a:i}return n}return Ut(n,e.operator)}case"ArithTernary":return N(t,e.condition)?N(t,e.consequent):N(t,e.alternate);case"ArithAssignment":{let n=e.variable,r=n;if(e.stringKey!==void 0)r=`${n}_${e.stringKey}`;else if(e.subscript){let a=t.state.associativeArrays?.has(n);if(a&&e.subscript.type==="ArithVariable")r=`${n}_${e.subscript.name}`;else if(a){let c=N(t,e.subscript);r=`${n}_${c}`}else{let c=N(t,e.subscript);if(c<0){let l=T(t,n);l.length>0&&(c=Math.max(...l.map(([d])=>typeof d=="number"?d:0))+1+c)}r=`${n}_${c}`}}let s=Number.parseInt(t.state.env[r]||"0",10)||0,o=N(t,e.value),i=pn(s,o,e.operator);return t.state.env[r]=String(i),i}case"ArithGroup":return N(t,e.expression);case"ArithConcat":{let n="";for(let r of e.parts)n+=yn(t,r);return Number.parseInt(n,10)||0}default:return 0}}function yn(t,e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return Z(t,e.name);case"ArithBracedExpansion":return ue(t,e.content);case"ArithCommandSubst":return"0";case"ArithConcat":{let n="";for(let r of e.parts)n+=yn(t,r);return n}default:return String(N(t,e))}}async function v(t,e){switch(e.type){case"ArithNumber":if(Number.isNaN(e.value))throw new F("value too great for base");return e.value;case"ArithVariable":return tt(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 n=ue(t,e.content);return Number.parseInt(n,10)||0}case"ArithDynamicBase":{let n=ue(t,e.baseExpr),r=Number.parseInt(n,10);if(r<2||r>64)return 0;let s=`${r}#${e.value}`;return xe(s)}case"ArithDynamicNumber":{let r=ue(t,e.prefix)+e.suffix;return xe(r)}case"ArithArrayElement":{let n=t.state.associativeArrays?.has(e.array),r;if(e.stringKey!==void 0)r=`${e.array}_${e.stringKey}`;else if(n&&e.index?.type==="ArithVariable")r=`${e.array}_${e.index.name}`;else if(e.index){let o=await v(t,e.index);r=`${e.array}_${o}`;let i=t.state.env[r];if(i!==void 0)return ve(i);if(o===0){let a=t.state.env[e.array];if(a!==void 0)return ve(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}[${o}]`);return 0}else return 0;let s=t.state.env[r];return s!==void 0?ve(s):0}case"ArithDoubleSubscript":throw new F("double subscript","","");case"ArithNumberSubscript":throw new F(`${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 n=await v(t,e.left),r=await v(t,e.right);return zt(n,r,e.operator)}case"ArithUnary":{let n=await v(t,e.operand);if(e.operator==="++"||e.operator==="--"){if(e.operand.type==="ArithVariable"){let r=e.operand.name,s=Number.parseInt(Z(t,r),10)||0,o=e.operator==="++"?s+1:s-1;return t.state.env[r]=String(o),e.prefix?o:s}if(e.operand.type==="ArithArrayElement"){let r=e.operand.array,s=t.state.associativeArrays?.has(r),o;if(e.operand.stringKey!==void 0)o=`${r}_${e.operand.stringKey}`;else if(s&&e.operand.index?.type==="ArithVariable")o=`${r}_${e.operand.index.name}`;else if(e.operand.index){let c=await v(t,e.operand.index);o=`${r}_${c}`}else return n;let i=Number.parseInt(t.state.env[o]||"0",10)||0,a=e.operator==="++"?i+1:i-1;return t.state.env[o]=String(a),e.prefix?a:i}return n}return Ut(n,e.operator)}case"ArithTernary":return await v(t,e.condition)?await v(t,e.consequent):await v(t,e.alternate);case"ArithAssignment":{let n=e.variable,r=n;if(e.stringKey!==void 0)r=`${n}_${e.stringKey}`;else if(e.subscript){let a=t.state.associativeArrays?.has(n);if(a&&e.subscript.type==="ArithVariable")r=`${n}_${e.subscript.name}`;else if(a){let c=await v(t,e.subscript);r=`${n}_${c}`}else{let c=await v(t,e.subscript);if(c<0){let l=T(t,n);l.length>0&&(c=Math.max(...l.map(([d])=>typeof d=="number"?d:0))+1+c)}r=`${n}_${c}`}}let s=Number.parseInt(t.state.env[r]||"0",10)||0,o=await v(t,e.value),i=pn(s,o,e.operator);return t.state.env[r]=String(i),i}case"ArithGroup":return await v(t,e.expression);case"ArithConcat":{let n="";for(let r of e.parts)n+=await wn(t,r);return Number.parseInt(n,10)||0}default:return 0}}async function wn(t,e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return Z(t,e.name);case"ArithBracedExpansion":return ue(t,e.content);case"ArithCommandSubst":return t.execFn?(await t.execFn(e.command)).stdout.trim():"0";case"ArithConcat":{let n="";for(let r of e.parts)n+=await wn(t,r);return n}default:return String(await v(t,e))}}var $=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,n){return{stdout:t,stderr:e,exitCode:n}}function O(t){return{stdout:"",stderr:"",exitCode:t?0:1}}function ie(t,e,n="",r=""){throw new z(t,e,n,r)}function Gt(t,e){if(t.state.loopDepth===0){if(t.state.parentHasLoopContext)throw new oe;return $}let n=1;if(e.length>0){let r=Number.parseInt(e[0],10);if(Number.isNaN(r)||r<1)throw new k(128,"",`bash: break: ${e[0]}: numeric argument required
51
- `);n=r}throw new U(n)}async function Ht(t,e){let n,r=!1,s=!1,o=0;for(;o<e.length;)if(e[o]==="--"){o++;break}else if(e[o]==="-L")s=!1,o++;else if(e[o]==="-P")s=!0,o++;else if(e[o].startsWith("-")&&e[o]!=="-")o++;else break;let i=e.slice(o);if(i.length===0||i[0]==="~"?n=t.state.env.HOME||"/":i[0]==="-"?(n=t.state.previousDir,r=!0):n=i[0],!n.startsWith("/")&&!n.startsWith("./")&&!n.startsWith("../")&&n!=="."&&n!==".."){let d=t.state.env.CDPATH;if(d){let h=d.split(":").filter(m=>m);for(let m of h){let y=m.startsWith("/")?`${m}/${n}`:`${t.state.cwd}/${m}/${n}`;try{if((await t.fs.stat(y)).isDirectory){n=y,r=!0;break}}catch{}}}}let c=(n.startsWith("/")?n:`${t.state.cwd}/${n}`).split("/").filter(d=>d&&d!=="."),l="";for(let d of c)if(d==="..")l=l.split("/").slice(0,-1).join("/")||"/";else{l=l?`${l}/${d}`:`/${d}`;try{if(!(await t.fs.stat(l)).isDirectory)return x(`bash: cd: ${n}: Not a directory
52
- `)}catch{return x(`bash: cd: ${n}: No such file or directory
53
- `)}}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}
54
- `:"")}function Vt(t,e){if(t.state.loopDepth===0){if(t.state.parentHasLoopContext)throw new oe;return $}if(e.length>1)throw new U(1);let n=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
55
- `);n=r}throw new X(n)}function ge(t,e){t.state.readonlyVars=t.state.readonlyVars||new Set,t.state.readonlyVars.add(e)}function Ms(t,e){return t.state.readonlyVars?.has(e)??!1}function fe(t,e,n="bash"){return Ms(t,e)?x(`${n}: ${e}: readonly variable
56
- `):null}function En(t){let e=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(e)return{name:e[1],isArray:!0,arrayElements:jt(e[2])};if(t.includes("=")){let n=t.indexOf("=");return{name:t.slice(0,n),isArray:!1,value:t.slice(n+1)}}return{name:t,isArray:!1}}function gn(t,e,n={}){let{name:r,isArray:s,arrayElements:o,value:i}=e,{makeReadonly:a=!1,checkReadonly:c=!0}=n;if(c){let l=fe(t,r);if(l)return l}if(s&&o){for(let l=0;l<o.length;l++)t.state.env[`${r}_${l}`]=o[l];t.state.env[`${r}__length`]=String(o.length)}else i!==void 0&&(t.state.env[r]=i);return a&&ge(t,r),null}function qt(t,e){let n=!1,r=!1,s=!1,o=!1,i=!1,a=[];for(let c=0;c<e.length;c++){let l=e[c];if(l==="-a")n=!0;else if(l==="-A")r=!0;else if(l==="-r")s=!0;else if(l==="-x")o=!0;else if(l==="-p")i=!0;else if(l==="--"){a.push(...e.slice(c+1));break}else if(l.startsWith("-"))for(let u of l.slice(1))u==="a"?n=!0:u==="A"?r=!0:u==="r"?s=!0:u==="x"?o=!0:u==="p"&&(i=!0);else a.push(l)}if(i&&a.length>0){let c="";for(let l of a){let u=t.state.env[l];if(u!==void 0){let d=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');c+=`declare -- ${l}="${d}"
57
- `}}return j(c)}if(a.length===0&&!i){let c="",l=Object.entries(t.state.env).filter(([u])=>!u.startsWith("BASH_")).sort(([u],[d])=>u.localeCompare(d));for(let[u,d]of l){let h=d.replace(/'/g,"'\\''");c+=`declare -- ${u}='${h}'
58
- `}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],d=l[2];if(r&&(t.state.associativeArrays??=new Set,t.state.associativeArrays.add(u)),r&&d.includes("[")){let h=Bs(d);for(let[m,y]of h)t.state.env[`${u}_${m}`]=y}else{let h=jt(d);for(let m=0;m<h.length;m++)t.state.env[`${u}_${m}`]=h[m];t.state.env[`${u}__length`]=String(h.length)}s&&ge(t,u);continue}if(c.includes("=")){let u=c.indexOf("="),d=c.slice(0,u),h=c.slice(u+1),m=fe(t,d);if(m)return m;t.state.env[d]=h,s&&ge(t,d)}else{let u=c;r&&(t.state.associativeArrays??=new Set,t.state.associativeArrays.add(u));let d=Object.keys(t.state.env).some(h=>h.startsWith(`${u}_`)&&!h.startsWith(`${u}__length`));!(u in t.state.env)&&!d&&(n||r?t.state.env[`${u}__length`]="0":t.state.env[u]=""),s&&ge(t,u)}}return $}function jt(t){let e=[],n="",r=!1,s=!1,o=!1;for(let i of t){if(o){n+=i,o=!1;continue}if(i==="\\"){o=!0;continue}if(i==="'"&&!s){r=!r;continue}if(i==='"'&&!r){s=!s;continue}if((i===" "||i===" "||i===`
59
- `)&&!r&&!s){n&&(e.push(n),n="");continue}n+=i}return n&&e.push(n),e}function Bs(t){let e=[],n=0;for(;n<t.length;){for(;n<t.length&&/\s/.test(t[n]);)n++;if(n>=t.length)break;if(t[n]!=="["){n++;continue}n++;let r="";if(t[n]==="'"||t[n]==='"'){let o=t[n];for(n++;n<t.length&&t[n]!==o;)r+=t[n],n++;t[n]===o&&n++}else for(;n<t.length&&t[n]!=="]"&&t[n]!=="=";)r+=t[n],n++;for(;n<t.length&&t[n]!=="]";)n++;if(t[n]==="]"&&n++,t[n]!=="=")continue;n++;let s="";if(t[n]==="'"||t[n]==='"'){let o=t[n];for(n++;n<t.length&&t[n]!==o;)t[n]==="\\"&&n+1<t.length&&n++,s+=t[n],n++;t[n]===o&&n++}else for(;n<t.length&&!/\s/.test(t[n]);)s+=t[n],n++;e.push([r,s])}return e}function Zt(t,e){let n=!1,r=!1,s=[];for(let o=0;o<e.length;o++){let i=e[o];if(i==="-a")n=!0;else if(i==="-A")r=!0;else if(i==="-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}"
60
- `)}return j(a)}}else if(i==="--"){s.push(...e.slice(o+1));break}else i.startsWith("-")||s.push(i)}for(let o of s){let i=En(o);if(i.value===void 0&&!i.isArray){ge(t,i.name);continue}let a=gn(t,i,{makeReadonly:!0});if(a)return a}return $}async function Qt(t,e){let n=e;if(n.length>0){let s=n[0];if(s==="--")n=n.slice(1);else if(s.startsWith("-")&&s!=="-"&&s.length>1)return x(`bash: eval: ${s}: invalid option
2
+ import{B as Zs,C as Gs,D as ne,E as Pe,F as K,G as ue,H as st,I as Ks,J as I,K as Xs,L as Ys,M as pe,N as Wt,O as nt,P as V,a as Fs,b as Ms,c as zs,d as et,e as q,f as M,g as de,h as J,i as he,j as be,k as It,l as tt,m as Vs,n as Tt,o as js,p as oe,q as ge,r as Bs,s as Hs,t as xt,u as Rt,v as Ee,w as Us,x as qs,y as fe,z as Lt}from"./chunks/chunk-FSAGDARS.js";import{a as re,b as ie,c as se,d as ae,e as Ls,f as z,g as Ce,h as Ye,i as Qe,j as Ws,k as te,l as ve,m as Je,n as ce}from"./chunks/chunk-K5IXNHO5.js";import"./chunks/chunk-OBH7XN5N.js";import{a as le}from"./chunks/chunk-4VDEBYW7.js";import"./chunks/chunk-KGOUQS5A.js";import*as Cr from"node:fs";import*as Pr from"node:readline";var Oe=[{name:"echo",load:async()=>(await import("./chunks/echo-7I42V66Q.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-AJXZOSPN.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-YPXD4CRE.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-BEHQBUMC.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-XJABRAUN.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-GOODLY5W.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-IBPHJBM3.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-2PKAWTSQ.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-XXWRVG2D.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-3ATZ2ABL.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-EFFNQ3RY.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-TYLTHXFR.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-L26WH2K4.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-VL3R4LAM.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-TJHLLIMR.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-YAUIERGN.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-SAOHEZYP.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-UEQ7KMY5.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-VX7MJMVN.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-VX7MJMVN.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-VX7MJMVN.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-RSDLLECO.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-JPDTWF4W.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-GFEJOWML.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-KUHOCH5S.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-IXHB2FVS.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-CPIFQTKY.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-IHF6BEOO.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-FT6WBQZG.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-MBLEXZBI.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-VP42N2JN.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-DSM3NUGM.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-452R4I2C.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-77K5HH2M.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-BFVYAPOU.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-ZEKN6D4Q.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-JJFZRWRC.js")).split},{name:"column",load:async()=>(await import("./chunks/column-TSFEMTG6.js")).column},{name:"join",load:async()=>(await import("./chunks/join-3IXMEGNA.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-ZFIT2GTM.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-PHDZK64M.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-SO5MVUEX.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-EES7TR26.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-DQBEJH47.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-XQPYLN3H.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-7A4MH7BJ.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-7A4MH7BJ.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-EGIS5LUE.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-EGIS5LUE.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-G5C2J2OY.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-IWT2HHEA.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-OVATH2SQ.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-OVATH2SQ.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-CI7A5IXQ.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-PGDTHIM2.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-PGDTHIM2.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-RGZHJNXC.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-O7TCK5TL.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-GI3QVUGD.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-IQLPMFYI.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-O5BOTJGJ.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-JED4EKFH.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-37F5EBPK.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-AVK43XM2.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-RMGXYNQJ.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-2VAAFCTS.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-67P4ME4N.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-MV3WQ4QF.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-6PCTL3MH.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-EPEXKI4B.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-7C5JICNL.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-FCDFBOMN.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-KNRFDAY7.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-WXDKRL2Z.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-JVLUNKSG.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-KRKGC2U3.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-YXK3WZQL.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-YXK3WZQL.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-YXK3WZQL.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Oe.push({name:"tar",load:async()=>(await import("./chunks/tar-LFENC54A.js")).tarCommand}),Oe.push({name:"yq",load:async()=>(await import("./chunks/yq-PFV4T2PV.js")).yqCommand}),Oe.push({name:"xan",load:async()=>(await import("./chunks/xan-5HNHTFMB.js")).xanCommand}),Oe.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-THMDBIGF.js")).sqlite3Command}));var Ir=[{name:"curl",load:async()=>(await import("./chunks/curl-TH7YRBSA.js")).curlCommand}],Qs=new Map;function Js(e){return{name:e.name,async execute(t,s){let n=Qs.get(e.name);return n||(n=await e.load(),Qs.set(e.name,n)),n.execute(t,s)}}}function en(e){return(e?Oe.filter(s=>e.includes(s.name)):Oe).map(Js)}function tn(){return Ir.map(Js)}function sn(e){return"load"in e&&typeof e.load=="function"}function nn(e){let t=null;return{name:e.name,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}var Tr=new TextEncoder,xr=new TextDecoder;function De(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)):Tr.encode(e)}function rt(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):xr.decode(e)}function $e(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var it=new TextEncoder;function Rr(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Me=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))Rr(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 a=$e(n),o=De(s,a);this.data.set(i,{type:"file",content:o,mode:r?.mode??420,mtime:r?.mtime??new Date})}async readFile(t,s){let n=await this.readFileBuffer(t),r=$e(s);return rt(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:it.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 a=$e(n),o=De(s,a);if(i?.type==="file"){let l=i.content instanceof Uint8Array?i.content:it.encode(i.content),f=new Uint8Array(l.length+o.length);f.set(l),f.set(o,l.length),this.data.set(r,{type:"file",content:f,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=it.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=it.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 a=0;a<n.length-1;a++){let o=n[a];r=`${r}/${o}`;let l=this.data.get(r),f=0,c=40;for(;l&&l.type==="symlink"&&f<c;){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),f++}if(f>=c)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 a of n){r=`${r}/${a}`;let o=this.data.get(r),l=0,f=40;for(;o&&o.type==="symlink"&&l<f;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(r),r=this.resolveSymlink(r,o.target),o=this.data.get(r),l++}if(l>=f)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}/`,a=new Map;for(let[o,l]of this.data.entries())if(o!==s&&o.startsWith(i)){let f=o.slice(i.length),c=f.split("/")[0];c&&!f.includes("/",c.length)&&!a.has(c)&&a.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(a.values()).sort((o,l)=>o.name<l.name?-1:o.name>l.name?1:0)}async rm(t,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 a of i){let o=n==="/"?`/${a}`:`${n}/${a}`;await this.rm(o,s)}}}this.data.delete(n)}async cp(t,s,n){let r=this.normalizePath(t),i=this.normalizePath(s),a=this.data.get(r);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(a.type==="file")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(r);for(let l of o){let f=r==="/"?`/${l}`:`${r}/${l}`,c=i==="/"?`/${l}`:`${i}/${l}`;await this.cp(f,c,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),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=n}};function Lr(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Wr(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 Fr(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 Mr(e){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Fs}
3
+ `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
4
+ `),e.writeFileSync("/proc/self/status",Ms()),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 rn(e,t){Lr(e)&&(Wr(e,t),Fr(e),Mr(e))}var zr=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],Vr=["braceexpand","hashall","interactive-comments"];function Ft(e){let t=[],s=[...Vr.map(n=>({name:n,enabled:!0})),...zr.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 Ie(e){e.state.env.SHELLOPTS=Ft(e.state.options)}var jr=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Mt(e){let t=[];for(let s of jr)e[s]&&t.push(s);return t.join(":")}function zt(e){e.state.env.BASHOPTS=Mt(e.state.shoptOptions)}var Br="BASH_ALIAS_";function an(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function on(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function ln(e,t){return e.env[`${Br}${t}`]}function Vt(e,t,s){if(!t.name||!an(t.name))return t;let n=on(t.name);if(!n)return t;let r=ln(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new M,a=r,o=r.endsWith(" ");if(!o)for(let u of t.args){let d=fn(u);a+=` ${d}`}let l;try{l=i.parse(a)}catch(u){if(u instanceof et)throw u;return t}if(l.statements.length!==1||l.statements[0].pipelines.length!==1||l.statements[0].pipelines[0].commands.length!==1)return cn(t,r);let f=l.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return cn(t,r);let c={...f,assignments:[...t.assignments,...f.assignments],redirections:[...f.redirections,...t.redirections],line:t.line};if(o&&t.args.length>0&&(c={...c,args:[...c.args,...t.args]},c.args.length>0)){let u=c.args[0];if(an(u)){let d=on(u);if(d&&ln(e,d)){let h={type:"SimpleCommand",name:u,args:c.args.slice(1),assignments:[],redirections:[]},m=Vt(e,h,s);m!==h&&(c={...c,name:m.name,args:[...m.args]})}}}return c}catch(i){throw s.delete(n),i}}function cn(e,t){let s=t;for(let a of e.args){let o=fn(a);s+=` ${o}`}let n=new M,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 fn(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 un(e,t){let s=t.parts.map(c=>c.type==="Literal"?c.value:"\0").join(""),n=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!n||!s.endsWith(")"))return null;let r=n[1],i=[],a=!1,o="",l=!1;for(let c of t.parts)if(c.type==="Literal"){let u=c.value;if(!a){let d=u.indexOf("=(");d!==-1&&(a=!0,u=u.slice(d+2))}if(a){u.endsWith(")")&&(u=u.slice(0,-1));let d=u.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(o||l)&&(i.push(o),o="",l=!1):h&&(o+=h)}}else if(a)if(c.type==="BraceExpansion")if(/^\[.+\]=/.test(o))o+=tt({type:"Word",parts:[c]});else{(o||l)&&(i.push(o),o="",l=!1);let d=await pe(e,{type:"Word",parts:[c]});i.push(...d.values)}else{(c.type==="SingleQuoted"||c.type==="DoubleQuoted"||c.type==="Escaped")&&(l=!0);let u=await I(e,{type:"Word",parts:[c]});o+=u}(o||l)&&i.push(o);let f=i.map(c=>/^\[.+\]=/.test(c)?c:c===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(c)&&!c.startsWith("'")&&!c.startsWith('"')?`'${c.replace(/'/g,"'\\''")}'`:c);return`${r}=(${f.join(" ")})`}async function dn(e,t){let s=-1,n=-1,r=!1;for(let p=0;p<t.parts.length;p++){let g=t.parts[p];if(g.type==="Literal"){let b=g.value.indexOf("+=");if(b!==-1){let N=g.value.slice(0,b);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(N)){s=p,n=b,r=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(N)){s=p,n=b,r=!0;break}}let $=g.value.indexOf("=");if($!==-1&&($===0||g.value[$-1]!=="+")){let N=g.value.slice(0,$);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(N)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(N)){s=p,n=$;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),a=t.parts[s];if(a.type!=="Literal")return null;let o=r?2:1,l=a.value.slice(0,n),f=a.value.slice(n+o),c=t.parts.slice(s+1),u="";for(let p of i)u+=await I(e,{type:"Word",parts:[p]});u+=l;let d={type:"Word",parts:f!==""?[{type:"Literal",value:f},...c]:c},h=d.parts.length>0?await I(e,d):"";return`${u}${r?"+=":"="}${h}`}var Hr=["tar","yq","xan","sqlite3"];function hn(e){return Hr.includes(e)}var L=Object.freeze({stdout:"",stderr:"",exitCode:0});function W(e=""){return{stdout:e,stderr:"",exitCode:0}}function S(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function _(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function U(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function we(e,t,s="",n=""){throw new te(e,t,s,n)}function jt(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new ve;return L}if(t.length>1)throw new z(1,"",`bash: break: too many arguments
5
+ `);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
6
+ `);s=n}throw new re(s)}async function Bt(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 a=t.slice(i);if(a.length===0||a[0]==="~"?s=e.state.env.HOME||"/":a[0]==="-"?(s=e.state.previousDir,n=!0):s=a[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!=="."),f="";for(let u of l)if(u==="..")f=f.split("/").slice(0,-1).join("/")||"/";else{f=f?`${f}/${u}`:`/${u}`;try{if(!(await e.fs.stat(f)).isDirectory)return S(`bash: cd: ${s}: Not a directory
7
+ `)}catch{return S(`bash: cd: ${s}: No such file or directory
8
+ `)}}let c=f||"/";if(r)try{c=await e.fs.realpath(c)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=c,e.state.env.PWD=e.state.cwd,e.state.env.OLDPWD=e.state.previousDir,W(n?`${c}
9
+ `:"")}function Ht(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Ur=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function at(e){return Ur.includes(e)}async function ot(e,t,s){let n=Ht(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 qr=["-nt","-ot","-ef"];function lt(e){return qr.includes(e)}async function ct(e,t,s,n){let r=Ht(e,s),i=Ht(e,n);switch(t){case"-nt":try{let a=await e.fs.stat(r),o=await e.fs.stat(i);return a.mtime>o.mtime}catch{return!1}case"-ot":try{let a=await e.fs.stat(r),o=await e.fs.stat(i);return a.mtime<o.mtime}catch{return!1}case"-ef":try{if(!await e.fs.exists(r)||!await e.fs.exists(i))return!1;let a=e.fs.resolvePath(e.state.cwd,r),o=e.fs.resolvePath(e.state.cwd,i);return a===o}catch{return!1}default:return!1}}var Zr=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function ft(e){return Zr.has(e)}function ut(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 dt(e,t,s,n=!1,r=!1,i=!1){if(n){let o=Te(t,s,r,i);return e==="!="?!o:o}if(r){let o=t.toLowerCase()===s.toLowerCase();return e==="!="?!o:o}let a=t===s;return e==="!="?!a:a}var Gr=new Set(["-z","-n"]);function ht(e){return Gr.has(e)}function pt(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function mt(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 o=r;return(o.startsWith("'")&&o.endsWith("'")||o.startsWith('"')&&o.endsWith('"'))&&(o=o.slice(1,-1)),o=o.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(l,f)=>e.state.env[f]||""),`${n}_${o}`in e.state.env}let a;try{let o=new M,l=q(o,r);a=await V(e,l.expression)}catch{if(/^-?\d+$/.test(r))a=Number.parseInt(r,10);else{let o=e.state.env[r];a=o?Number.parseInt(o,10):0}}if(a<0){let o=J(e,n),l=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${n}: bad array subscript
10
+ `,!1;if(a=Math.max(...o)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${n}: bad array subscript
11
+ `,!1}return`${n}_${a}`in e.state.env}return t in e.state.env?!0:e.state.associativeArrays?.has(t)?be(e,t).length>0:J(e,t).length>0}async function Se(e,t){switch(t.type){case"CondBinary":{let s=await I(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 I(e,t.right);r=Gs(i)}else r=await Xs(e,t.right);else ze(t.operator)&&!n?r=await Ys(e,t.right):r=await I(e,t.right);if(ze(t.operator)){let i=e.state.shoptOptions.nocasematch;return dt(t.operator,s,r,!n,i,!0)}if(ft(t.operator))return ut(t.operator,await mn(e,s),await mn(e,r));if(lt(t.operator))return ct(e,t.operator,s,r);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=Qr(r),o=new RegExp(a,i?"i":""),l=s.match(o);if(he(e,"BASH_REMATCH"),l)for(let f=0;f<l.length;f++)e.state.env[`BASH_REMATCH_${f}`]=l[f]||"";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 I(e,t.operand);return at(t.operator)?ot(e,t.operator,s):ht(t.operator)?pt(t.operator,s):t.operator==="-v"?await mt(e,s):t.operator==="-o"?qt(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await I(e,t.operand.expression.word)})`!=="":!await Se(e,t.operand);case"CondAnd":return await Se(e,t.left)?await Se(e,t.right):!1;case"CondOr":return await Se(e,t.left)?!0:await Se(e,t.right);case"CondGroup":return await Se(e,t.expression);case"CondWord":return await I(e,t.word)!=="";default:return!1}}async function Ve(e,t){if(t.length===0)return _("","",1);if(t.length===1)return U(!!t[0]);if(t.length===2){let n=t[0],r=t[1];return n==="("?S(`test: '(' without matching ')'
12
+ `,2):at(n)?U(await ot(e,n,r)):ht(n)?U(pt(n,r)):n==="!"?U(!r):n==="-v"?U(await mt(e,r)):n==="-o"?U(qt(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
13
+ `,2):_("","",1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(ze(r))return U(dt(r,n,i));if(ft(r)){let a=yt(n),o=yt(i);return!a.valid||!o.valid?_("","",2):U(ut(r,a.value,o.value))}if(lt(r))return U(await ct(e,r,n,i));switch(r){case"-a":return U(n!==""&&i!=="");case"-o":return U(n!==""||i!=="");case">":return U(n>i);case"<":return U(n<i)}if(n==="!"){let a=await Ve(e,[r,i]);return _("",a.stderr,a.exitCode===0?1:a.exitCode===1?0:a.exitCode)}if(n==="("&&i===")")return U(r!=="")}if(t.length===4){if(t[0]==="!"){let n=await Ve(e,t.slice(1));return _("",n.stderr,n.exitCode===0?1:n.exitCode===1?0:n.exitCode)}if(t[0]==="("&&t[3]===")")return Ve(e,[t[1],t[2]])}let s=await gn(e,t,0);return s.pos<t.length?S(`test: too many arguments
14
+ `,2):U(s.value)}async function gn(e,t,s){return Kr(e,t,s)}async function Kr(e,t,s){let{value:n,pos:r}=await pn(e,t,s);for(;t[r]==="-o";){let i=await pn(e,t,r+1);n=n||i.value,r=i.pos}return{value:n,pos:r}}async function pn(e,t,s){let{value:n,pos:r}=await Ut(e,t,s);for(;t[r]==="-a";){let i=await Ut(e,t,r+1);n=n&&i.value,r=i.pos}return{value:n,pos:r}}async function Ut(e,t,s){if(t[s]==="!"){let{value:n,pos:r}=await Ut(e,t,s+1);return{value:!n,pos:r}}return Xr(e,t,s)}async function Xr(e,t,s){let n=t[s];if(n==="("){let{value:i,pos:a}=await gn(e,t,s+1);return{value:i,pos:t[a]===")"?a+1:a}}let r=t[s+1];if(ze(r)){let i=n,a=t[s+2]??"";return{value:dt(r,i,a),pos:s+3}}if(ft(r)){let i=yt(n),a=yt(t[s+2]??"0");return!i.valid||!a.valid?{value:!1,pos:s+3}:{value:ut(r,i.value,a.value),pos:s+3}}if(lt(r)){let i=n,a=t[s+2]??"";return{value:await ct(e,r,i,a),pos:s+3}}if(at(n)){let i=t[s+1]??"";return{value:await ot(e,n,i),pos:s+2}}if(ht(n)){let i=t[s+1]??"";return{value:pt(n,i),pos:s+2}}if(n==="-v"){let i=t[s+1]??"";return{value:await mt(e,i),pos:s+2}}if(n==="-o"){let i=t[s+1]??"";return{value:qt(e,i),pos:s+2}}return{value:n!==void 0&&n!=="",pos:s+1}}function Te(e,t,s=!1,n=!1){let r=`^${wn(t,n)}$`,i=s?"is":"s";return new RegExp(r,i).test(e)}function wn(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=vn(e,n+1);if(i!==-1){let a=e.slice(n+2,i),o=bn(a),l=o.map(c=>wn(c,t)),f=l.length>0?l.join("|"):"(?:)";if(r==="@")s+=`(?:${f})`;else if(r==="*")s+=`(?:${f})*`;else if(r==="+")s+=`(?:${f})+`;else if(r==="?")s+=`(?:${f})?`;else if(r==="!")if(i<e.length-1){let u=o.map(h=>En(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(`(?!(?:${f})).{${h}}`),s+=`(?:${m.join("|")})`}}else s+=`(?:(?!(?:${f})).)*?`}else s+=`(?!(?:${f})$).*`;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 vn(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 bn(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 En(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=vn(e,n+1);if(i!==-1){if(r==="@"){let a=e.slice(n+2,i),l=bn(a).map(f=>En(f,t));if(l.every(f=>f!==null)&&l.every(f=>f===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 qt(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 mn(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 yn(t);try{let s=new M,n=q(s,t);return await V(e,n.expression)}catch{return yn(t)}}function Yr(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 yn(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=Yr(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 yt(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 Qr(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=Jr(e,s);t+=n.converted,s=n.endIndex}else t+=e[s],s++;return t}function Jr(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 a="",o=!1;for(;s<e.length;){let l=e[s];if(l==="]"){o=!0,s++;break}if(l==="["&&s+1<e.length&&e[s+1]===":"){let f=e.indexOf(":]",s+2);if(f!==-1){let c=e.slice(s+2,f);a+=ei(c),s=f+2;continue}}if(l==="["&&s+1<e.length){let f=e[s+1];if(f==="."||f==="="){let c=`${f}]`,u=e.indexOf(c,s+2);if(u!==-1){let d=e.slice(s+2,u);a+=d,s=u+2;continue}}}if(l==="\\"&&s+1<e.length){a+=l+e[s+1],s+=2;continue}a+=l,s++}return o?(r&&(n+="\\]"),i&&(n+="\\["),n+=a,n+="]",{converted:n,endIndex:s}):{converted:"\\[",endIndex:t+1}}function ei(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,a=!1;for(let o of e){if(i){s+=o,i=!1,a=!0;continue}if(o==="\\"){i=!0;continue}if(o==="'"&&!r){n||(a=!0),n=!n;continue}if(o==='"'&&!n){r||(a=!0),r=!r;continue}if((o===" "||o===" "||o===`
15
+ `)&&!n&&!r){a&&(t.push(s),s="",a=!1);continue}s+=o,a=!0}return a&&t.push(s),t}function gt(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 $n(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 ti(e,t){try{let s=new M,n=q(s,t);return await V(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}async function Sn(e,t,s={}){let{name:n,isArray:r,arrayElements:i,value:a,arrayIndex:o}=t,{makeReadonly:l=!1,checkReadonly:f=!0}=s;if(f){let c=K(e,n);if(c)return c}if(r&&i){for(let c=0;c<i.length;c++)e.state.env[`${n}_${c}`]=i[c];e.state.env[`${n}__length`]=String(i.length)}else if(o!==void 0&&a!==void 0){let c=await ti(e,o);e.state.env[`${n}_${c}`]=a;let u=parseInt(e.state.env[`${n}__length`]??"0",10);c>=u&&(e.state.env[`${n}__length`]=String(c+1))}else a!==void 0&&(e.state.env[n]=a);return l&&ne(e,n),null}function Ae(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function xe(e,t){return e.state.localVarDepth?.get(t)}function wt(e,t){e.state.localVarDepth?.delete(t)}function An(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 vt(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function _n(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 Zt=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Cn(e){return Zt.has(e)}var Gt=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),je=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 Ne(e,t,s,n){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory
16
+ `;if(n.checkNoclobber&&e.state.options.noclobber&&!n.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file
17
+ `}catch{}return null}function X(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return"utf8";return"binary"}function si(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),a=r+n+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let f=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(f)||f<0)return null;let c=o.slice(l+1);return{path:i,position:f,content:c}}async function Pn(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(Wt(e,r.target))return{targets:s,error:`bash: $@: ambiguous redirect
18
+ `};s.set(n,await I(e,r.target))}else{let a=await nt(e,r.target);if("error"in a)return{targets:s,error:a.error};s.set(n,a.target)}}return{targets:s}}function ni(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd;return e.state.nextFd++,t}async function bt(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 I(e,s.target)==="-"){let i=e.state.env[s.fdVariable];if(i!==void 0){let a=Number.parseInt(i,10);Number.isNaN(a)||e.state.fileDescriptors.delete(a)}continue}let n=ni(e);if(e.state.env[s.fdVariable]=String(n),s.target.type==="Word"){let r=await I(e,s.target);if(s.operator===">&"||s.operator==="<&"){let i=Number.parseInt(r,10);if(!Number.isNaN(i)){let a=e.state.fileDescriptors.get(i);a!==void 0&&e.state.fileDescriptors.set(n,a);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}
19
+ `);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,r),a=await e.fs.readFile(i);e.state.fileDescriptors.set(n,a)}catch{return _("",`bash: ${r}: No such file or directory
20
+ `,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 I(e,s.target),r==="-"||!Number.isNaN(Number.parseInt(r,10))||s.fd!=null)continue}else{let o=await nt(e,s.target);if("error"in o)return _("",o.error,1);r=o.target}let i=e.fs.resolvePath(e.state.cwd,r),a=s.operator===">|";try{let o=await e.fs.stat(i);if(o.isDirectory)return _("",`bash: ${r}: Is a directory
21
+ `,1);if(e.state.options.noclobber&&!a&&!o.isDirectory&&r!=="/dev/null")return _("",`bash: ${r}: cannot overwrite existing file
22
+ `,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 _("",`bash: /dev/full: No space left on device
23
+ `,1)}return null}async function j(e,t,s,n){let{stdout:r,stderr:i,exitCode:a}=t;for(let f=0;f<s.length;f++){let c=s[f];if(c.target.type==="HereDoc")continue;let u,d=n?.get(f);if(d!==void 0)u=d;else if(c.operator===">&"||c.operator==="<&"){if(Wt(e,c.target)){i+=`bash: $@: ambiguous redirect
24
+ `,a=1,r="";continue}u=await I(e,c.target)}else{let m=await nt(e,c.target);if("error"in m){i+=m.error,a=1,r="";continue}u=m.target}if(!c.fdVariable)switch(c.operator){case">":case">|":{let h=c.fd??1,m=c.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
25
+ `,a=1,r="";break}let p=e.fs.resolvePath(e.state.cwd,u),g=await Ne(e,p,u,{checkNoclobber:!0,isClobber:m});if(g){i+=g,a=1,r="";break}await e.fs.writeFile(p,r,X(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
26
+ `,a=1;break}if(u==="/dev/null")i="";else{let p=e.fs.resolvePath(e.state.cwd,u),g=await Ne(e,p,u,{checkNoclobber:!0,isClobber:m});if(g){i+=g,a=1;break}await e.fs.writeFile(p,i,X(i)),i=""}}break}case">>":{let h=c.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
27
+ `,a=1,r="";break}let m=e.fs.resolvePath(e.state.cwd,u),p=await Ne(e,m,u,{});if(p){i+=p,a=1,r="";break}await e.fs.appendFile(m,r,X(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
28
+ `,a=1;break}let m=e.fs.resolvePath(e.state.cwd,u),p=await Ne(e,m,u,{});if(p){i+=p,a=1;break}await e.fs.appendFile(m,i,X(i)),i=""}break}case">&":case"<&":{let h=c.fd??1;if(u==="-")break;if(u.endsWith("-")){let m=u.slice(0,-1),p=Number.parseInt(m,10);if(!Number.isNaN(p)){let g=e.state.fileDescriptors?.get(p);g!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,g),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
29
+ `,a=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(c.operator===">&"){let p=e.fs.resolvePath(e.state.cwd,u),g=await Ne(e,p,u,{checkNoclobber:!0});if(g){i=g,a=1,r="";break}if(c.fd==null){let b=r+i;await e.fs.writeFile(p,b,X(b)),r="",i=""}else h===1?(await e.fs.writeFile(p,r,X(r)),r=""):h===2&&(await e.fs.writeFile(p,i,X(i)),i="")}}else{let p=e.state.fileDescriptors?.get(m);if(p?.startsWith("__file__:")){let g=p.slice(9);h===1?(await e.fs.appendFile(g,r,X(r)),r=""):h===2&&(await e.fs.appendFile(g,i,X(i)),i="")}else if(p?.startsWith("__rw__:")){let g=si(p);g&&(h===1?(await e.fs.appendFile(g.path,r,X(r)),r=""):h===2&&(await e.fs.appendFile(g.path,i,X(i)),i=""))}else if(p?.startsWith("__dupout__:")){let g=Number.parseInt(p.slice(11),10);if(g!==1)if(g===2)h===1&&(i+=r,r="");else{let b=e.state.fileDescriptors?.get(g);if(b?.startsWith("__file__:")){let $=b.slice(9);h===1?(await e.fs.appendFile($,r,X(r)),r=""):h===2&&(await e.fs.appendFile($,i,X(i)),i="")}}}else p?.startsWith("__dupin__:")?(i+=`bash: ${m}: Bad file descriptor
30
+ `,a=1,r=""):m>=3&&(i+=`bash: ${m}: Bad file descriptor
31
+ `,a=1,r="")}}break}case"&>":{if(u==="/dev/full"){i=`bash: echo: write error: No space left on device
32
+ `,a=1,r="";break}let h=e.fs.resolvePath(e.state.cwd,u),m=await Ne(e,h,u,{checkNoclobber:!0});if(m){i=m,a=1,r="";break}let p=r+i;await e.fs.writeFile(h,p,X(p)),r="",i="";break}case"&>>":{if(u==="/dev/full"){i=`bash: echo: write error: No space left on device
33
+ `,a=1,r="";break}let h=e.fs.resolvePath(e.state.cwd,u),m=await Ne(e,h,u,{});if(m){i=m,a=1,r="";break}let p=r+i;await e.fs.appendFile(h,p,X(p)),r="",i="";break}}}let o=e.state.fileDescriptors?.get(1);if(o){if(o==="__dupout__:2")i+=r,r="";else if(o.startsWith("__file__:")){let f=o.slice(9);await e.fs.appendFile(f,r,X(r)),r=""}else if(o.startsWith("__file_append__:")){let f=o.slice(16);await e.fs.appendFile(f,r,X(r)),r=""}}let l=e.state.fileDescriptors?.get(2);if(l){if(l==="__dupout__:1")r+=i,i="";else if(l.startsWith("__file__:")){let f=l.slice(9);await e.fs.appendFile(f,i,X(i)),i=""}else if(l.startsWith("__file_append__:")){let f=l.slice(16);await e.fs.appendFile(f,i,X(i)),i=""}}return _(r,i,a)}function Nn(e,t){if(e.state.options.posix&&Zt.has(t.name)){let n=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
34
+ `;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 ri(e,t){let s="";for(let n of t)if((n.operator==="<<"||n.operator==="<<-")&&n.target.type==="HereDoc"){let r=n.target,i=await I(e,r.content);r.stripTabs&&(i=i.split(`
35
+ `).map(o=>o.replace(/^\t+/,"")).join(`
36
+ `)),(n.fd??0)===0&&(s=i)}else if(n.operator==="<<<"&&n.target.type==="Word")s=`${await I(e,n.target)}
37
+ `;else if(n.operator==="<"&&n.target.type==="Word"){let r=await I(e,n.target),i=e.fs.resolvePath(e.state.cwd,r);try{s=await e.fs.readFile(i)}catch{}}return s}async function Et(e,t,s,n="",r){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,we(`${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 f=0;f<s.length;f++)i[String(f+1)]=e.state.env[String(f+1)],e.state.env[String(f+1)]=s[f];i["@"]=e.state.env["@"],i["#"]=e.state.env["#"],e.state.env["@"]=s.join(" "),e.state.env["#"]=String(s.length);let a=()=>{let f=e.state.localScopes.length-1,c=e.state.localScopes.pop();if(c)for(let[u,d]of c)d===void 0?delete e.state.env[u]:e.state.env[u]=d;if(_n(e,f),e.state.fullyUnsetLocals)for(let[u,d]of e.state.fullyUnsetLocals.entries())d===f&&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:o,error:l}=await Pn(e,t.redirections);if(l)return a(),_("",l,1);try{let f=await ri(e,t.redirections),c=n||f,u=await e.executeCommand(t.body,c);return a(),j(e,u,t.redirections,o)}catch(f){if(a(),f instanceof se){let c=_(f.stdout,f.stderr,f.exitCode);return j(e,c,t.redirections,o)}throw f}}var On=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],Xt=[".",":","[","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"],ii=["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"],ai=Xt;async function Yt(e,t){let s=[],n=null,r="",i="",a=null,o=!1,l=!1,f=!1,c=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 w=t[y];if(w==="-v")s.push("variable");else if(w==="-e")s.push("export");else if(w==="-f")s.push("file");else if(w==="-d")s.push("directory");else if(w==="-k")s.push("keyword");else if(w==="-A"){if(y++,y>=t.length)return S(`compgen: -A: option requires an argument
38
+ `,2);let v=t[y];if(!m.includes(v))return S(`compgen: ${v}: invalid action name
39
+ `,2);s.push(v)}else if(w==="-W"){if(y++,y>=t.length)return S(`compgen: -W: option requires an argument
40
+ `,2);n=t[y]}else if(w==="-P"){if(y++,y>=t.length)return S(`compgen: -P: option requires an argument
41
+ `,2);r=t[y]}else if(w==="-S"){if(y++,y>=t.length)return S(`compgen: -S: option requires an argument
42
+ `,2);i=t[y]}else if(w==="-o"){if(y++,y>=t.length)return S(`compgen: -o: option requires an argument
43
+ `,2);let v=t[y];if(v==="plusdirs")o=!0;else if(v==="dirnames")l=!0;else if(v==="default")f=!0;else if(!(v==="filenames"||v==="nospace"||v==="bashdefault"||v==="noquote"))return S(`compgen: ${v}: invalid option name
44
+ `,2)}else if(w==="-F"){if(y++,y>=t.length)return S(`compgen: -F: option requires an argument
45
+ `,2);u=t[y]}else if(w==="-C"){if(y++,y>=t.length)return S(`compgen: -C: option requires an argument
46
+ `,2);d=t[y]}else if(w==="-X"){if(y++,y>=t.length)return S(`compgen: -X: option requires an argument
47
+ `,2);c=t[y]}else if(w==="-G"){if(y++,y>=t.length)return S(`compgen: -G: option requires an argument
48
+ `,2)}else if(w==="--"){h.push(...t.slice(y+1));break}else w.startsWith("-")||h.push(w)}a=h[0]??null;let p=[];if(l){let y=await Kt(e,a);p.push(...y)}if(f){let y=await kn(e,a);p.push(...y)}for(let y of s)if(y==="variable"){let w=oi(e,a);p.push(...w)}else if(y==="export"){let w=li(e,a);p.push(...w)}else if(y==="function"){let w=ci(e,a);p.push(...w)}else if(y==="builtin"){let w=fi(a);p.push(...w)}else if(y==="keyword"){let w=ui(a);p.push(...w)}else if(y==="alias"){let w=di(e,a);p.push(...w)}else if(y==="shopt"){let w=hi(a);p.push(...w)}else if(y==="helptopic"){let w=pi(a);p.push(...w)}else if(y==="directory"){let w=await Kt(e,a);p.push(...w)}else if(y==="file"){let w=await kn(e,a);p.push(...w)}else if(y==="user"){let w=mi(a);p.push(...w)}else if(y==="command"){let w=await yi(e,a);p.push(...w)}if(n!==null)try{let y=await gi(e,n),w=wi(e,y);for(let v of w)(a===null||v.startsWith(a))&&p.push(v)}catch{return _("","",1)}if(o){let y=await Kt(e,a);for(let w of y)p.includes(w)||p.push(w)}let g="";if(u!==null){let y=e.state.functions.get(u);if(y){let w={};w.COMP_WORDS__length=e.state.env.COMP_WORDS__length,e.state.env.COMP_WORDS__length="0",w.COMP_CWORD=e.state.env.COMP_CWORD,e.state.env.COMP_CWORD="-1",w.COMP_LINE=e.state.env.COMP_LINE,e.state.env.COMP_LINE="",w.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 C=["compgen",h[0]??"",""];try{let k=await Et(e,y,C,"");if(k.exitCode!==0)return Re(e,w),Re(e,v),_("",k.stderr,1);g=k.stdout;let T=vi(e);p.push(...T)}catch{return Re(e,w),Re(e,v),_("","",1)}Re(e,w),Re(e,v)}}if(d!==null)try{let y=de(d),w=await e.executeScript(y);if(w.exitCode!==0)return _("",w.stderr,w.exitCode);if(w.stdout){let v=w.stdout.split(`
49
+ `);for(let C of v)C.length>0&&p.push(C)}}catch(y){if(y.name==="ParseException")return S(`compgen: -C: ${y.message}
50
+ `,2);throw y}let b=p;if(c!==null){let y=c.startsWith("!"),w=y?c.slice(1):c;b=p.filter(v=>{let C=Te(v,w,!1,!0);return y?C:!C})}if(b.length===0&&a!==null)return _(g,"",1);let $=b.map(y=>`${r}${y}${i}`).join(`
51
+ `),N=g+($?`${$}
52
+ `:"");return W(N)}function oi(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 li(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 ci(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(n=>n.startsWith(t))),s.sort()}function fi(e){let t=[...Xt];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function ui(e){let t=[...On];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function di(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 hi(e){let t=[...ii];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function pi(e){let t=[...ai];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function Kt(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let o=t.slice(0,a)||"/";r=t.slice(a+1),o.startsWith("/")?n=o:n=`${e.state.cwd}/${o}`}}let i=await e.fs.readdir(n);for(let a of i){let o=`${n}/${a}`;try{if((await e.fs.stat(o)).isDirectory&&(!r||a.startsWith(r)))if(t?.includes("/")){let f=t.lastIndexOf("/"),c=t.slice(0,f+1);s.push(c+a)}else s.push(a)}catch{}}}catch{}return s.sort()}async function kn(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let o=t.slice(0,a)||"/";r=t.slice(a+1),o.startsWith("/")?n=o:n=`${e.state.cwd}/${o}`}}let i=await e.fs.readdir(n);for(let a of i)if(!r||a.startsWith(r))if(t?.includes("/")){let o=t.lastIndexOf("/"),l=t.slice(0,o+1);s.push(l+a)}else s.push(a)}catch{}return s.sort()}function mi(e){return["root","nobody"]}async function yi(e,t){let s=new Set;for(let i of Xt)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 On)s.add(i);let n=e.state.env.PATH??"/usr/bin:/bin";for(let i of n.split(":"))if(i)try{let a=await e.fs.readdir(i);for(let o of a)s.add(o)}catch{}let r=Array.from(s);return t!==null&&(r=r.filter(i=>i.startsWith(t))),r.sort()}async function gi(e,t){let n=new M().parseWordFromString(t,!1,!1);return await I(e,n)}function wi(e,t){let s=e.state.env.IFS??`
53
+ `;if(s.length===0)return[t];let n=new Set(s.split("")),r=[],i="",a=0;for(;a<t.length;){let o=t[a];if(o==="\\"&&a+1<t.length){let l=t[a+1];i+=l,a+=2}else n.has(o)?(i.length>0&&(r.push(i),i=""),a++):(i+=o,a++)}return i.length>0&&r.push(i),r}function Re(e,t){for(let[s,n]of Object.entries(t))n===void 0?delete e.state.env[s]:e.state.env[s]=n}function vi(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 bi=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Jt(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=!1,i,a,o,l=[],f=[],c=[];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
54
+ `,2);i=t[u]}else if(d==="-F"){if(u++,u>=t.length)return S(`complete: -F: option requires an argument
55
+ `,2);a=t[u]}else if(d==="-o"){if(u++,u>=t.length)return S(`complete: -o: option requires an argument
56
+ `,2);let h=t[u];if(!bi.includes(h))return S(`complete: ${h}: invalid option name
57
+ `,2);l.push(h)}else if(d==="-A"){if(u++,u>=t.length)return S(`complete: -A: option requires an argument
58
+ `,2);f.push(t[u])}else if(d==="-C"){if(u++,u>=t.length)return S(`complete: -C: option requires an argument
59
+ `,2);o=t[u]}else if(d==="-G"){if(u++,u>=t.length)return S(`complete: -G: option requires an argument
60
+ `,2)}else if(d==="-P"){if(u++,u>=t.length)return S(`complete: -P: option requires an argument
61
+ `,2)}else if(d==="-S"){if(u++,u>=t.length)return S(`complete: -S: option requires an argument
62
+ `,2)}else if(d==="-X"){if(u++,u>=t.length)return S(`complete: -X: option requires an argument
63
+ `,2)}else if(d==="--"){c.push(...t.slice(u+1));break}else d.startsWith("-")||c.push(d)}if(n){if(c.length===0)return e.state.completionSpecs.clear(),W("");for(let u of c)e.state.completionSpecs.delete(u);return W("")}if(s)return c.length===0?Qt(e):Qt(e,c);if(t.length===0||c.length===0&&!i&&!a&&!o&&l.length===0&&f.length===0&&!r)return Qt(e);if(a&&c.length===0&&!r)return S(`complete: -F: option requires a command name
64
+ `,2);if(r){let u={isDefault:!0};return i!==void 0&&(u.wordlist=i),a!==void 0&&(u.function=a),o!==void 0&&(u.command=o),l.length>0&&(u.options=l),f.length>0&&(u.actions=f),e.state.completionSpecs.set("__default__",u),W("")}for(let u of c){let d={};i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),o!==void 0&&(d.command=o),l.length>0&&(d.options=l),f.length>0&&(d.actions=f),e.state.completionSpecs.set(u,d)}return W("")}function Qt(e,t){let s=e.state.completionSpecs;if(!s||s.size===0){if(t&&t.length>0){let i="";for(let a of t)i+=`complete: ${a}: no completion specification
65
+ `;return _("",i,1)}return W("")}let n=[],r=t||Array.from(s.keys());for(let i of r){if(i==="__default__")continue;let a=s.get(i);if(!a){if(t)return _(n.join(`
66
+ `)+(n.length>0?`
67
+ `:""),`complete: ${i}: no completion specification
68
+ `,1);continue}let o="complete";if(a.options)for(let l of a.options)o+=` -o ${l}`;if(a.actions)for(let l of a.actions)o+=` -A ${l}`;a.wordlist!==void 0&&(a.wordlist.includes(" ")||a.wordlist.includes("'")?o+=` -W '${a.wordlist}'`:o+=` -W ${a.wordlist}`),a.function!==void 0&&(o+=` -F ${a.function}`),a.isDefault&&(o+=" -D"),o+=` ${i}`,n.push(o)}return n.length===0?W(""):W(`${n.join(`
69
+ `)}
70
+ `)}var Dn=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function es(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=[],i=[],a=[];for(let o=0;o<t.length;o++){let l=t[o];if(l==="-D")s=!0;else if(l==="-E")n=!0;else if(l==="-o"){if(o++,o>=t.length)return S(`compopt: -o: option requires an argument
71
+ `,2);let f=t[o];if(!Dn.includes(f))return S(`compopt: ${f}: invalid option name
72
+ `,2);r.push(f)}else if(l==="+o"){if(o++,o>=t.length)return S(`compopt: +o: option requires an argument
73
+ `,2);let f=t[o];if(!Dn.includes(f))return S(`compopt: ${f}: invalid option name
74
+ `,2);i.push(f)}else if(l==="--"){a.push(...t.slice(o+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&a.push(l)}if(s){let o=e.state.completionSpecs.get("__default__")??{isDefault:!0},l=new Set(o.options??[]);for(let f of r)l.add(f);for(let f of i)l.delete(f);return o.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set("__default__",o),W("")}if(n){let o=e.state.completionSpecs.get("__empty__")??{},l=new Set(o.options??[]);for(let f of r)l.add(f);for(let f of i)l.delete(f);return o.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set("__empty__",o),W("")}if(a.length>0){for(let o of a){let l=e.state.completionSpecs.get(o)??{},f=new Set(l.options??[]);for(let c of r)f.add(c);for(let c of i)f.delete(c);l.options=f.size>0?Array.from(f):void 0,e.state.completionSpecs.set(o,l)}return W("")}return S(`compopt: not currently executing completion function
75
+ `,1)}function ts(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new ve;return L}if(t.length>1)throw new z(1,"",`bash: continue: too many arguments
76
+ `);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
77
+ `);s=n}throw new ie(s)}function B(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 ss(e){for(let t=0;t<e.length;t++){let s=e.charCodeAt(t);if(s<32||s===127)return!0}return!1}function ns(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 ss(e)?ns(e):/^[a-zA-Z0-9_/.:\-@%+,=]*$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function ke(e){return ss(e)?ns(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function rs(e){return ss(e)?ns(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function In(e,t){let s="";return e.state.integerVars?.has(t)&&(s+="i"),e.state.lowercaseVars?.has(t)&&(s+="l"),oe(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 is(e){return e===""?"''":/[\s'\\]/.test(e)?`'${e.replace(/'/g,"'\\''")}'`:e}function Tn(e,t){let s="",n="",r=!1;for(let i of t){let a=In(e,i);if(e.state.associativeArrays?.has(i)){let c=be(e,i);if(c.length===0)s+=`declare -A ${i}=()
78
+ `;else{let u=c.map(d=>{let h=e.state.env[`${i}_${d}`]??"",m=is(h);return`['${d}']=${m}`});s+=`declare -A ${i}=(${u.join(" ")})
79
+ `}continue}let l=J(e,i);if(l.length>0){let c=l.map(u=>{let d=e.state.env[`${i}_${u}`]??"";return`[${u}]=${ke(d)}`});s+=`declare -a ${i}=(${c.join(" ")})
80
+ `;continue}if(e.state.env[`${i}__length`]!==void 0){s+=`declare -a ${i}=()
81
+ `;continue}let f=e.state.env[i];if(f!==void 0)s+=`declare ${a} ${i}=${rs(f)}
82
+ `;else{let c=e.state.declaredVars?.has(i),u=e.state.localVarDepth?.has(i);c||u?s+=`declare ${a} ${i}
83
+ `:(n+=`bash: declare: ${i}: not found
84
+ `,r=!0)}}return _(s,n,r?1:0)}function xn(e,t){let{filterExport:s,filterReadonly:n,filterNameref:r,filterIndexedArray:i,filterAssocArray:a}=t,o=s||n||r||i||a,l="",f=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);f.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)){f.add(h);continue}}f.add(u)}if(e.state.localVarDepth)for(let u of e.state.localVarDepth.keys())f.add(u);if(e.state.associativeArrays)for(let u of e.state.associativeArrays)f.add(u);let c=Array.from(f).sort();for(let u of c){let d=In(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(o&&(a&&!h||i&&!p||s&&!e.state.exportedVars?.has(u)||n&&!e.state.readonlyVars?.has(u)||r&&!oe(e,u)))continue;if(h){let b=be(e,u);if(b.length===0)l+=`declare -A ${u}=()
85
+ `;else{let $=b.map(N=>{let y=e.state.env[`${u}_${N}`]??"",w=is(y);return`['${N}']=${w}`});l+=`declare -A ${u}=(${$.join(" ")})
86
+ `}continue}if(m.length>0){let b=m.map($=>{let N=e.state.env[`${u}_${$}`]??"";return`[${$}]=${ke(N)}`});l+=`declare -a ${u}=(${b.join(" ")})
87
+ `;continue}if(e.state.env[`${u}__length`]!==void 0){l+=`declare -a ${u}=()
88
+ `;continue}let g=e.state.env[u];g!==void 0&&(l+=`declare ${d} ${u}=${rs(g)}
89
+ `)}return W(l)}function Rn(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let n of s){let r=be(e,n);if(r.length===0)t+=`declare -A ${n}=()
90
+ `;else{let i=r.map(a=>{let o=e.state.env[`${n}_${a}`]??"",l=is(o);return`['${a}']=${l}`});t+=`declare -A ${n}=(${i.join(" ")})
91
+ `}}return W(t)}function Ln(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 a=r.slice(0,-8);e.state.associativeArrays?.has(a)||s.add(a);continue}let i=r.lastIndexOf("_");if(i>0){let a=r.slice(0,i),o=r.slice(i+1);/^\d+$/.test(o)&&(e.state.associativeArrays?.has(a)||s.add(a))}}let n=Array.from(s).sort();for(let r of n){let i=J(e,r);if(i.length===0)t+=`declare -a ${r}=()
92
+ `;else{let a=i.map(o=>{let l=e.state.env[`${r}_${o}`]??"";return`[${o}]=${ke(l)}`});t+=`declare -a ${r}=(${a.join(" ")})
93
+ `}}return W(t)}function Wn(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 a=r.slice(0,-8);s.add(a);continue}let i=r.lastIndexOf("_");if(i>0){let a=r.slice(0,i),o=r.slice(i+1);if(/^\d+$/.test(o)||e.state.associativeArrays?.has(a)){s.add(a);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 o=e.state.env[r];o!==void 0&&(t+=`${r}=${$t(o)}
94
+ `)}return W(t)}function as(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function Be(e,t){return e.state.integerVars?.has(t)??!1}function os(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Ei(e,t){return e.state.lowercaseVars?.has(t)??!1}function ls(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function $i(e,t){return e.state.uppercaseVars?.has(t)??!1}function Le(e,t,s){return Ei(e,t)?s.toLowerCase():$i(e,t)?s.toUpperCase():s}async function Fn(e,t){try{let s=new M,n=q(s,t),r=await V(e,n.expression);return String(r)}catch{return"0"}}function Si(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 a=e.slice(i,n);if(n++,e[n]!=="=")return null;n++;let o=e.slice(n);return{name:s,indexExpr:a,value:o}}async function cs(e,t){let s=!1,n=!1,r=!1,i=!1,a=!1,o=!1,l=!1,f=!1,c=!1,u=!1,d=!1,h=!1,m=!1,p=!1,g=!1,b=[];for(let T=0;T<t.length;T++){let x=t[T];if(x==="-a")s=!0;else if(x==="-A")n=!0;else if(x==="-r")r=!0;else if(x==="-x")i=!0;else if(x==="-p")a=!0;else if(x==="-n")o=!0;else if(x==="+n")l=!0;else if(x==="+a")f=!0;else if(x==="+x")c=!0;else if(x==="--"){b.push(...t.slice(T+1));break}else if(x.startsWith("+")){for(let A of x.slice(1))if(A==="n")l=!0;else if(A==="a")f=!0;else if(A==="x")c=!0;else if(A!=="r"){if(A!=="i"){if(!(A==="f"||A==="F"))return _("",`bash: typeset: +${A}: invalid option
95
+ `,2)}}}else if(x==="-i")u=!0;else if(x==="-l")d=!0;else if(x==="-u")h=!0;else if(x==="-f")m=!0;else if(x==="-F")p=!0;else if(x==="-g")g=!0;else if(x.startsWith("-"))for(let A of x.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")a=!0;else if(A==="n")o=!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")g=!0;else return _("",`bash: typeset: -${A}: invalid option
96
+ `,2);else b.push(x)}let N=e.state.localScopes.length>0&&!g,y=T=>{if(!N)return;let x=e.state.localScopes[e.state.localScopes.length-1];x.has(T)||x.set(T,e.state.env[T])},w=T=>{if(!N)return;let x=e.state.localScopes[e.state.localScopes.length-1];x.has(T)||x.set(T,e.state.env[T]);let A=`${T}_`;for(let D of Object.keys(e.state.env))D.startsWith(A)&&!D.includes("__")&&(x.has(D)||x.set(D,e.state.env[D]));let P=`${T}__length`;e.state.env[P]!==void 0&&!x.has(P)&&x.set(P,e.state.env[P])},v=T=>{N&&Ae(e,T)};if(p){if(b.length===0){let A=Array.from(e.state.functions.keys()).sort(),P="";for(let D of A)P+=`declare -f ${D}
97
+ `;return W(P)}let T=!0,x="";for(let A of b)e.state.functions.has(A)?x+=`${A}
98
+ `:T=!1;return _(x,"",T?0:1)}if(m){if(b.length===0){let x="",A=Array.from(e.state.functions.keys()).sort();for(let P of A)x+=`${P} ()
99
+ {
100
+ # function body
101
+ }
102
+ `;return W(x)}let T=!0;for(let x of b)e.state.functions.has(x)||(T=!1);return _("","",T?0:1)}if(a&&b.length>0)return Tn(e,b);if(a&&b.length===0)return xn(e,{filterExport:i,filterReadonly:r,filterNameref:o,filterIndexedArray:s,filterAssocArray:n});if(b.length===0&&n&&!a)return Rn(e);if(b.length===0&&s&&!a)return Ln(e);if(b.length===0&&!a)return Wn(e);let C="",k=0;for(let T of b){let x=T.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(x&&!f){let E=x[1],O=x[2];if(n&&J(e,E).length>0){C+=`bash: declare: ${E}: cannot convert indexed to associative array
103
+ `,k=1;continue}if((s||!n&&!s)&&e.state.associativeArrays?.has(E)){C+=`bash: declare: ${E}: cannot convert associative to indexed array
104
+ `,k=1;continue}if(w(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 R=gt(O);for(let[G,F]of R){let H=B(e,F);e.state.env[`${E}_${G}`]=H}}else if(n){let R=me(O);for(let G=0;G<R.length;G+=2){let F=R[G],H=G+1<R.length?B(e,R[G+1]):"";e.state.env[`${E}_${F}`]=H}}else{let R=me(O);if(R.some(F=>/^\[[^\]]+\]=/.test(F))){let F=0;for(let H of R){let ee=H.match(/^\[([^\]]+)\]=(.*)$/);if(ee){let Q=ee[1],Nr=ee[2],kr=B(e,Nr),Fe;if(/^-?\d+$/.test(Q))Fe=Number.parseInt(Q,10);else try{let Or=new M,Dr=q(Or,Q);Fe=await V(e,Dr.expression)}catch{Fe=0}e.state.env[`${E}_${Fe}`]=kr,F=Fe+1}else{let Q=B(e,H);e.state.env[`${E}_${F}`]=Q,F++}}}else{for(let F=0;F<R.length;F++)e.state.env[`${E}_${F}`]=R[F];e.state.env[`${E}__length`]=String(R.length)}}v(E),r&&ne(e,E),i&&ue(e,E);continue}if(l){let E=T.includes("=")?T.slice(0,T.indexOf("=")):T;if(Bs(e,E),!T.includes("="))continue}if(c){let E=T.includes("=")?T.slice(0,T.indexOf("=")):T;if(st(e,E),!T.includes("="))continue}let A=Si(T);if(A){let{name:E,indexExpr:O,value:R}=A,G=K(e,E);if(G)return G;w(E);let F;try{let ee=new M,Q=q(ee,O);F=await V(e,Q.expression)}catch{let ee=parseInt(O,10);F=Number.isNaN(ee)?0:ee}e.state.env[`${E}_${F}`]=R;let H=parseInt(e.state.env[`${E}__length`]??"0",10);F>=H&&(e.state.env[`${E}__length`]=String(F+1)),v(E),r&&ne(e,E),i&&ue(e,E);continue}let P=T.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(P&&!f){let E=P[1],O=P[2],R=K(e,E);if(R)return R;w(E);let G=me(O);if(e.state.associativeArrays?.has(E)){let F=gt(O);for(let[H,ee]of F){let Q=B(e,ee);e.state.env[`${E}_${H}`]=Q}}else{let F=J(e,E),H=0;if(F.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],H=1}else F.length>0&&(H=Math.max(...F)+1);for(let Q=0;Q<G.length;Q++)e.state.env[`${E}_${H+Q}`]=B(e,G[Q]);let ee=H+G.length;e.state.env[`${E}__length`]=String(ee)}v(E),r&&ne(e,E),i&&ue(e,E);continue}let D=T.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(D){let E=D[1],O=B(e,D[2]),R=K(e,E);if(R)return R;y(E),u&&as(e,E),d&&os(e,E),h&&ls(e,E);let F=J(e,E).length>0||e.state.associativeArrays?.has(E);if(Be(e,E)){let H=e.state.env[E]??"0",ee=parseInt(H,10)||0,Q=parseInt(await Fn(e,O),10)||0;O=String(ee+Q),e.state.env[E]=O}else if(F){O=Le(e,E,O);let H=`${E}_0`,ee=e.state.env[H]??"";e.state.env[H]=ee+O}else{O=Le(e,E,O);let H=e.state.env[E]??"";e.state.env[E]=H+O}v(E),r&&ne(e,E),i&&ue(e,E),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(E));continue}if(T.includes("=")){let E=T.indexOf("="),O=T.slice(0,E),R=T.slice(E+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(O)){C+=`bash: typeset: \`${O}': not a valid identifier
105
+ `,k=1;continue}let G=K(e,O);if(G)return G;if(y(O),o){if(R!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(R)){C+=`bash: declare: \`${R}': invalid variable name for name reference
106
+ `,k=1;continue}e.state.env[O]=R,ge(e,O),R!==""&&Rt(e,R)&&xt(e,O),v(O),r&&ne(e,O),i&&ue(e,O);continue}if(u&&as(e,O),d&&os(e,O),h&&ls(e,O),Be(e,O)&&(R=await Fn(e,R)),R=Le(e,O,R),oe(e,O)){let F=Ee(e,O);F&&F!==O?e.state.env[F]=R:e.state.env[O]=R}else e.state.env[O]=R;v(O),r&&ne(e,O),i&&ue(e,O),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(O))}else{let E=T;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(E)){C+=`bash: typeset: \`${E}': not a valid identifier
107
+ `,k=1;continue}if(s||n?w(E):y(E),o){ge(e,E);let R=e.state.env[E];R!==void 0&&R!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(R)?Hs(e,E):R&&Rt(e,R)&&xt(e,E),v(E),r&&ne(e,E),i&&ue(e,E);continue}if(u&&as(e,E),d&&os(e,E),h&&ls(e,E),n){if(J(e,E).length>0){C+=`bash: declare: ${E}: cannot convert indexed to associative array
108
+ `,k=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(E)}let O=Object.keys(e.state.env).some(R=>R.startsWith(`${E}_`)&&!R.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 _("",C,k)}async function fs(e,t){let s=!1,n=!1,r=!1,i=[];for(let a=0;a<t.length;a++){let o=t[a];if(o==="-a")s=!0;else if(o==="-A")n=!0;else if(o==="-p")r=!0;else if(o==="--"){i.push(...t.slice(a+1));break}else o.startsWith("-")||i.push(o)}if(i.length===0){let a="",o=Array.from(e.state.readonlyVars||[]).sort();for(let l of o){let f=e.state.env[l];if(f!==void 0){let c=f.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${l}="${c}"
109
+ `}}return W(a)}for(let a of i){let o=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(o){let u=o[1],d=o[2],h=K(e,u);if(h)return h;let m=me(d);if(e.state.associativeArrays?.has(u)){let p=gt(d);for(let[g,b]of p){let $=B(e,b);e.state.env[`${u}_${g}`]=$}}else{let p=J(e,u),g=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],g=1}else p.length>0&&(g=Math.max(...p)+1);for(let $=0;$<m.length;$++)e.state.env[`${u}_${g+$}`]=B(e,m[$]);let b=g+m.length;e.state.env[`${u}__length`]=String(b)}ne(e,u);continue}let l=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(l){let u=l[1],d=B(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 f=$n(a);if(f.value===void 0&&!f.isArray){ne(e,f.name);continue}let c=await Sn(e,f,{makeReadonly:!0});if(c)return c}return L}function us(e){return e.state.directoryStack??=[],e.state.directoryStack}function He(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function Ai(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 ds(e,t){let s=us(e),n;for(let o=0;o<t.length;o++){let l=t[o];if(l==="--"){if(o+1<t.length){if(n!==void 0)return S(`bash: pushd: too many arguments
110
+ `,2);n=t[o+1],o++}}else{if(l.startsWith("-")&&l!=="-")return S(`bash: pushd: ${l}: invalid option
111
+ `,2);if(n!==void 0)return S(`bash: pushd: too many arguments
112
+ `,2);n=l}}if(n===void 0){if(s.length<2)return S(`bash: pushd: no other directory
113
+ `,1);let o=s[0];s[0]=s[1],s[1]=o,n=s[0]}let r;if(n.startsWith("/"))r=n;else if(n===".."){let o=e.state.cwd.split("/").filter(l=>l);o.pop(),r=`/${o.join("/")}`}else n==="."?r=e.state.cwd:n.startsWith("~")?r=(e.state.env.HOME||"/")+n.slice(1):r=`${e.state.cwd}/${n}`;r=Ai(r);try{if(!(await e.fs.stat(r)).isDirectory)return S(`bash: pushd: ${n}: Not a directory
114
+ `,1)}catch{return S(`bash: pushd: ${n}: No such file or directory
115
+ `,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||"",a=`${[r,...s].map(o=>He(o,i)).join(" ")}
116
+ `;return W(a)}function hs(e,t){let s=us(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?S(`bash: popd: ${a}: invalid option
117
+ `,2):S(`bash: popd: too many arguments
118
+ `,2);if(s.length===0)return S(`bash: popd: directory stack empty
119
+ `,1);let n=s.shift();if(!n)return S(`bash: popd: directory stack empty
120
+ `,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(a=>He(a,r)).join(" ")}
121
+ `;return W(i)}function ps(e,t){let s=us(e),n=!1,r=!1,i=!1,a=!1;for(let c of t)if(c!=="--")if(c.startsWith("-"))for(let u of c.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,a=!0;else return S(`bash: dirs: -${u}: invalid option
122
+ `,2);else return S(`bash: dirs: too many arguments
123
+ `,1);if(n)return e.state.directoryStack=[],L;let o=[e.state.cwd,...s],l=e.state.env.HOME||"",f;return a?(f=o.map((c,u)=>{let d=r?c:He(c,l);return` ${u} ${d}`}).join(`
124
+ `),f+=`
125
+ `):i?f=o.map(c=>r?c:He(c,l)).join(`
126
+ `)+`
127
+ `:f=o.map(c=>r?c:He(c,l)).join(" ")+`
128
+ `,W(f)}async function St(e,t,s){let n=t;if(n.length>0){let o=n[0];if(o==="--")n=n.slice(1);else if(o.startsWith("-")&&o!=="-"&&o.length>1)return S(`bash: eval: ${o}: invalid option
61
129
  eval: usage: eval [arg ...]
62
- `,2)}if(n.length===0)return $;let r=n.join(" ");if(r.trim()==="")return $;try{let s=le(r);return t.executeScript(s)}catch(s){if(s instanceof U||s instanceof X||s instanceof G||s instanceof k)throw s;if(s.name==="ParseException")return x(`bash: eval: ${s.message}
63
- `);throw s}}function Kt(t,e){let n,r="";if(e.length===0)n=t.state.lastExitCode;else{let s=e[0],o=Number.parseInt(s,10);s===""||Number.isNaN(o)||!/^-?\d+$/.test(s)?(r=`bash: exit: ${s}: numeric argument required
64
- `,n=2):n=(o%256+256)%256}throw new k(n,"",r)}function Xt(t,e){let n=!1,r=[];for(let i of e)i==="-n"?n=!0:i==="-p"||i==="--"||r.push(i);if(r.length===0&&!n){let i="",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,"'\\''");i+=`declare -x ${c}='${u}'
65
- `}return j(i)}if(n){for(let i of r){let a=i.split("=")[0];delete t.state.env[a]}return $}let s="",o=0;for(let i of r){let a,c;if(i.includes("=")){let l=i.indexOf("=");a=i.slice(0,l),c=i.slice(l+1)}else a=i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){s+=`bash: export: \`${i}': not a valid identifier
66
- `,o=1;continue}c!==void 0?t.state.env[a]=c:a in t.state.env||(t.state.env[a]="")}return S("",s,o)}function zs(t){let e=[],n="",r=0;for(let s of t){for(let o of s)o==="("?r++:o===")"&&r--;n?n+=` ${s}`:n=s,r===0&&(e.push(n),n="")}return n&&e.push(n),e}async function Yt(t,e){if(e.length===0)return x(`bash: let: expression expected
67
- `);let n=zs(e),r=0;for(let s of n)try{let i=le(`(( ${s} ))`).statements[0];if(i&&i.pipelines.length>0&&i.pipelines[0].commands.length>0){let a=i.pipelines[0].commands[0];a.type==="ArithmeticCommand"&&(r=await v(t,a.expression.expression))}}catch(o){return x(`bash: let: ${s}: ${o.message}
68
- `)}return S("","",r===0?1:0)}function Us(t,e){let n=t.state.env.HOME||"/home/user";return e.split(":").map(o=>o==="~"?n:o==="~root"?"/root":o.startsWith("~/")?n+o.slice(1):o.startsWith("~root/")?`/root${o.slice(5)}`:o).join(":")}function Jt(t,e){if(t.state.localScopes.length===0)return x(`bash: local: can only be used in a function
69
- `);let n=t.state.localScopes[t.state.localScopes.length-1],r="",s=0;for(let o of e){let i,a;if(o.includes("=")){let c=o.indexOf("=");i=o.slice(0,c),a=Us(t,o.slice(c+1))}else i=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)){r+=`bash: local: \`${o}': not a valid identifier
70
- `,s=1;continue}n.has(i)||n.set(i,t.state.env[i]),a!==void 0&&(t.state.env[i]=a)}return S("",r,s)}function er(t,e,n){let r=`
71
- `,s=0,o=0,i=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]||`
72
- `,l+=2):E==="-n"&&l+1<e.length?(s=Number.parseInt(e[l+1],10)||0,l+=2):E==="-O"&&l+1<e.length?(o=Number.parseInt(e[l+1],10)||0,l+=2):E==="-s"&&l+1<e.length?(i=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=n;!u&&t.state.groupStdin!==void 0&&(u=t.state.groupStdin);let d=[],h=u,m=0,y=0;for(;h.length>0;){let E=h.indexOf(r);if(E===-1){h.length>0&&(y<i?y++:(s===0||m<s)&&(d.push(h),m++));break}let p=h.substring(0,E);if(a||(p+=r),h=h.substring(E+r.length),y<i){y++;continue}if(s>0&&m>=s)break;d.push(p),m++}_e(t,c);for(let E=0;E<d.length;E++)t.state.env[`${c}_${o+E}`]=d[E];return d.length>0&&(t.state.env[`${c}__length`]=String(o+d.length)),t.state.groupStdin!==void 0&&!n&&(t.state.groupStdin=""),S("","",0)}function tr(t,e,n){let r=!1,s=`
73
- `,o="",i=-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?(s=e[l+1],l++):g==="-p"&&l+1<e.length?(o=e[l+1],l++):g==="-n"&&l+1<e.length?(i=Number.parseInt(e[l+1],10),(Number.isNaN(i)||i<0)&&(u=!0,i=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 d=n;!d&&t.state.groupStdin!==void 0&&(d=t.state.groupStdin);let h="",m=0,y=!0;if(i>=0){for(let g=0;g<d.length&&g<i;g++){let b=d[g];if(b===s){m=g+1;break}h+=b,m=g+1}t.state.groupStdin!==void 0&&!n&&(t.state.groupStdin=d.substring(m))}else{let g=d;for(m=0;;){let b=g.indexOf(s);if(b!==-1){let C=g.substring(0,b);if(m+=b+s.length,g=g.substring(b+s.length),!r&&C.endsWith("\\")){h+=C.slice(0,-1);continue}h+=C,y=!0;break}else if(g.length>0){h+=g,m+=g.length,y=!1,g="";break}else{if(h.length===0){for(let C of c)t.state.env[C]="";return a&&_e(t,a),S("","",1)}y=!1;break}}t.state.groupStdin!==void 0&&!n&&(t.state.groupStdin=d.substring(m))}if(s===`
74
- `&&h.endsWith(`
75
- `)&&(h=h.slice(0,-1)),r||(h=h.replace(/\\(.)/g,"$1")),c.length===1&&c[0]==="REPLY")return t.state.env.REPLY=h,S("","",y?0:1);let E=Ye(t.state.env),{words:p,wordStarts:w}=en(h,E);if(a){_e(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=tn(h.substring(w[g]),E);t.state.env[b]=C}else t.state.env[b]=""}return S("","",y?0:1)}function rr(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 n=t.state.lastExitCode;if(e.length>0){let r=e[0],s=Number.parseInt(r,10);if(r===""||Number.isNaN(s)||!/^-?\d+$/.test(r))return x(`bash: return: ${r}: numeric argument required
76
- `,2);n=(s%256+256)%256}throw new G(n)}function Gs(t){return/^[a-zA-Z0-9_/.:-]*$/.test(t)?t:`'${t.replace(/'/g,"'\\''")}'`}var rt=`set: usage: set [-eux] [+eux] [-o option] [+o option]
130
+ `,2)}if(n.length===0)return L;let r=n.join(" ");if(r.trim()==="")return L;let i=e.state.groupStdin,a=s??e.state.groupStdin;a!==void 0&&(e.state.groupStdin=a);try{let o=de(r);return await e.executeScript(o)}catch(o){if(o instanceof re||o instanceof ie||o instanceof se||o instanceof z)throw o;if(o.name==="ParseException")return S(`bash: eval: ${o.message}
131
+ `);throw o}finally{e.state.groupStdin=i}}function ms(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
132
+ `,s=2):s=(i%256+256)%256}throw new z(s,"",n)}function ys(e,t){let s=!1,n=[];for(let a of t)a==="-n"?s=!0:a==="-p"||a==="--"||n.push(a);if(n.length===0&&!s){let a="",o=e.state.exportedVars??new Set,l=Array.from(o).sort();for(let f of l){let c=e.state.env[f];if(c!==void 0){let u=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -x ${f}="${u}"
133
+ `}}return W(a)}if(s){for(let a of n){let o,l;if(a.includes("=")){let f=a.indexOf("=");o=a.slice(0,f),l=B(e,a.slice(f+1)),e.state.env[o]=l}else o=a;st(e,o)}return L}let r="",i=0;for(let a of n){let o,l,f=!1,c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c)o=c[1],l=B(e,c[2]),f=!0;else if(a.includes("=")){let u=a.indexOf("=");o=a.slice(0,u),l=B(e,a.slice(u+1))}else o=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){r+=`bash: export: \`${a}': not a valid identifier
134
+ `,i=1;continue}if(l!==void 0)if(f){let u=e.state.env[o]??"";e.state.env[o]=u+l}else e.state.env[o]=l;else o in e.state.env||(e.state.env[o]="");ue(e,o)}return _("",r,i)}function At(e,t){if(t.length<2)return S(`bash: getopts: usage: getopts optstring name [arg ...]
135
+ `);let s=t[0],n=t[1],r=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n),i=s.startsWith(":"),a=i?s.slice(1):s,o;if(t.length>2)o=t.slice(2);else{let p=Number.parseInt(e.state.env["#"]||"0",10);o=[];for(let g=1;g<=p;g++)o.push(e.state.env[String(g)]||"")}let l=Number.parseInt(e.state.env.OPTIND||"1",10);l<1&&(l=1);let f=Number.parseInt(e.state.env.__GETOPTS_CHARINDEX||"0",10);if(e.state.env.OPTARG="",l>o.length)return r||(e.state.env[n]="?"),e.state.env.OPTIND=String(o.length+1),e.state.env.__GETOPTS_CHARINDEX="0",{exitCode:r?2:1,stdout:"",stderr:""};let c=o[l-1];if(!c||c==="-"||!c.startsWith("-"))return r||(e.state.env[n]="?"),{exitCode:r?2:1,stdout:"",stderr:""};if(c==="--")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=f===0?1:f,d=c[u];if(!d)return e.state.env.OPTIND=String(l+1),e.state.env.__GETOPTS_CHARINDEX="0",At(e,t);let h=a.indexOf(d);if(h===-1){let p="";return i?e.state.env.OPTARG=d:p=`bash: illegal option -- ${d}
136
+ `,r||(e.state.env[n]="?"),u+1<c.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<a.length&&a[h+1]===":")if(u+1<c.length)e.state.env.OPTARG=c.slice(u+1),e.state.env.OPTIND=String(l+1),e.state.env.__GETOPTS_CHARINDEX="0";else{if(l>=o.length){let p="";return i?(e.state.env.OPTARG=d,r||(e.state.env[n]=":")):(p=`bash: option requires an argument -- ${d}
137
+ `,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=o[l],e.state.env.OPTIND=String(l+2),e.state.env.__GETOPTS_CHARINDEX="0"}else u+1<c.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 gs(e,t){e.state.hashTable||(e.state.hashTable=new Map);let s=!1,n=!1,r=!1,i=!1,a=!1,o="",l=[],f=0;for(;f<t.length;){let m=t[f];if(m==="--"){f++,l.push(...t.slice(f));break}if(m==="-r")s=!0,f++;else if(m==="-d")n=!0,f++;else if(m==="-l")r=!0,f++;else if(m==="-t")a=!0,f++;else if(m==="-p"){if(i=!0,f++,f>=t.length)return S(`bash: hash: -p: option requires an argument
138
+ `,1);o=t[f],f++}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")a=!0;else return p==="p"?S(`bash: hash: -p: option requires an argument
139
+ `,1):S(`bash: hash: -${p}: invalid option
140
+ `,1);f++}else l.push(m),f++}if(s)return e.state.hashTable.clear(),L;if(n){if(l.length===0)return S(`bash: hash: -d: option requires an argument
141
+ `,1);let m=!1,p="";for(let g of l)e.state.hashTable.has(g)?e.state.hashTable.delete(g):(p+=`bash: hash: ${g}: not found
142
+ `,m=!0);return m?S(p,1):L}if(a){if(l.length===0)return S(`bash: hash: -t: option requires an argument
143
+ `,1);let m="",p=!1,g="";for(let b of l){let $=e.state.hashTable.get(b);$?l.length>1?m+=`${b} ${$}
144
+ `:m+=`${$}
145
+ `:(g+=`bash: hash: ${b}: not found
146
+ `,p=!0)}return p?{exitCode:1,stdout:m,stderr:g}:W(m)}if(i){if(l.length===0)return S(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
147
+ `,1);let m=l[0];return e.state.hashTable.set(m,o),L}if(l.length===0){if(e.state.hashTable.size===0)return W(`hash: hash table empty
148
+ `);let m="";if(r)for(let[p,g]of e.state.hashTable)m+=`builtin hash -p ${g} ${p}
149
+ `;else{m=`hits command
150
+ `;for(let[,p]of e.state.hashTable)m+=` 1 ${p}
151
+ `}return W(m)}let c=!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
152
+ `,c=!0;continue}let p=!1;for(let g of h){if(!g)continue;let b=`${g}/${m}`;if(await e.fs.exists(b)){e.state.hashTable.set(m,b),p=!0;break}}p||(u+=`bash: hash: ${m}: not found
153
+ `,c=!0)}return c?S(u,1):L}var Mn={":":[": [arguments]",`Null command.
154
+ No effect; the command does nothing.
155
+ Exit Status:
156
+ Always succeeds.`],".":[". filename [arguments]",`Execute commands from a file in the current shell.
157
+ Read and execute commands from FILENAME in the current shell.
158
+ The entries in $PATH are used to find the directory containing FILENAME.
159
+ Exit Status:
160
+ Returns the status of the last command executed in FILENAME.`],"[":["[ arg... ]",`Evaluate conditional expression.
161
+ This is a synonym for the "test" builtin, but the last argument must
162
+ be a literal \`]', to match the opening \`['.`],alias:["alias [-p] [name[=value] ... ]",`Define or display aliases.
163
+ Without arguments, \`alias' prints the list of aliases in the reusable
164
+ form \`alias NAME=VALUE' on standard output.
165
+ Exit Status:
166
+ alias returns true unless a NAME is supplied for which no alias has been
167
+ defined.`],bg:["bg [job_spec ...]",`Move jobs to the background.
168
+ Place the jobs identified by each JOB_SPEC in the background, as if they
169
+ had been started with \`&'.`],break:["break [n]",`Exit for, while, or until loops.
170
+ Exit a FOR, WHILE or UNTIL loop. If N is specified, break N enclosing
171
+ loops.
172
+ Exit Status:
173
+ The exit status is 0 unless N is not greater than or equal to 1.`],builtin:["builtin [shell-builtin [arg ...]]",`Execute shell builtins.
174
+ Execute SHELL-BUILTIN with arguments ARGs without performing command
175
+ lookup. This is useful when you wish to reimplement a shell builtin
176
+ as a shell function, but need to execute the builtin within the function.
177
+ Exit Status:
178
+ Returns the exit status of SHELL-BUILTIN, or false if SHELL-BUILTIN is
179
+ not a shell builtin.`],caller:["caller [expr]",`Return the context of the current subroutine call.
180
+ Without EXPR, returns "$line $filename". With EXPR, returns
181
+ "$line $subroutine $filename"; this extra information can be used to
182
+ provide a stack trace.
183
+ Exit Status:
184
+ Returns 0 unless the shell is not executing a subroutine call or
185
+ EXPR is invalid.`],cd:["cd [-L|-P] [dir]",`Change the shell working directory.
186
+ Change the current directory to DIR. The default DIR is the value of the
187
+ HOME shell variable.
188
+
189
+ The variable CDPATH defines the search path for the directory containing
190
+ DIR. Alternative directory names in CDPATH are separated by a colon (:).
191
+ A null directory name is the same as the current directory. If DIR begins
192
+ with a slash (/), then CDPATH is not used.
193
+
194
+ If the directory is not found, and the shell option \`cdable_vars' is set,
195
+ the word is assumed to be a variable name. If that variable has a value,
196
+ its value is used for DIR.
197
+
198
+ Options:
199
+ -L force symbolic links to be followed
200
+ -P use the physical directory structure without following symbolic
201
+ links
202
+
203
+ The default is to follow symbolic links, as if \`-L' were specified.
204
+
205
+ Exit Status:
206
+ Returns 0 if the directory is changed; non-zero otherwise.`],command:["command [-pVv] command [arg ...]",`Execute a simple command or display information about commands.
207
+ Runs COMMAND with ARGS suppressing shell function lookup, or display
208
+ information about the specified COMMANDs.
209
+
210
+ Options:
211
+ -p use a default value for PATH that is guaranteed to find all of
212
+ the standard utilities
213
+ -v print a description of COMMAND similar to the \`type' builtin
214
+ -V print a more verbose description of each COMMAND
215
+
216
+ Exit Status:
217
+ 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.
218
+ Intended to be used from within a shell function generating possible
219
+ completions. If the optional WORD argument is supplied, matches against
220
+ WORD are generated.
221
+ Exit Status:
222
+ 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.
223
+ For each NAME, specify how arguments are to be completed.
224
+ Exit Status:
225
+ Returns success unless an invalid option is supplied or an error occurs.`],continue:["continue [n]",`Resume for, while, or until loops.
226
+ Resumes the next iteration of the enclosing FOR, WHILE or UNTIL loop.
227
+ If N is specified, resumes the Nth enclosing loop.
228
+ Exit Status:
229
+ 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.
230
+ Declare variables and give them attributes. If no NAMEs are given,
231
+ display the attributes and values of all variables.
232
+
233
+ Options:
234
+ -a to make NAMEs indexed arrays (if supported)
235
+ -A to make NAMEs associative arrays (if supported)
236
+ -i to make NAMEs have the \`integer' attribute
237
+ -l to convert the value of each NAME to lower case on assignment
238
+ -n make NAME a reference to the variable named by its value
239
+ -r to make NAMEs readonly
240
+ -t to make NAMEs have the \`trace' attribute
241
+ -u to convert the value of each NAME to upper case on assignment
242
+ -x to make NAMEs export
243
+
244
+ Exit Status:
245
+ Returns success unless an invalid option is supplied or a variable
246
+ assignment error occurs.`],dirs:["dirs [-clpv] [+N] [-N]",`Display directory stack.
247
+ Display the list of currently remembered directories. Directories
248
+ find their way onto the list with the \`pushd' command; you can get
249
+ back up through the list with the \`popd' command.
250
+ Exit Status:
251
+ Returns success unless an invalid option is supplied or an error occurs.`],disown:["disown [-h] [-ar] [jobspec ...]",`Remove jobs from current shell.
252
+ Without any JOBSPECs, remove the current job.`],echo:["echo [-neE] [arg ...]",`Write arguments to the standard output.
253
+ Display the ARGs, separated by a single space character and followed by a
254
+ newline, on the standard output.
255
+
256
+ Options:
257
+ -n do not append a newline
258
+ -e enable interpretation of the following backslash escapes
259
+ -E explicitly suppress interpretation of backslash escapes
260
+
261
+ Exit Status:
262
+ Returns success unless a write error occurs.`],enable:["enable [-a] [-dnps] [-f filename] [name ...]",`Enable and disable shell builtins.
263
+ Enables and disables builtin shell commands.
264
+ Exit Status:
265
+ Returns success unless NAME is not a shell builtin or an error occurs.`],eval:["eval [arg ...]",`Execute arguments as a shell command.
266
+ Combine ARGs into a single string, use the result as input to the shell,
267
+ and execute the resulting commands.
268
+ Exit Status:
269
+ 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.
270
+ Execute COMMAND, replacing this shell with the specified program.
271
+ ARGUMENTS become the arguments to COMMAND. If COMMAND is not specified,
272
+ any redirections take effect in the current shell.
273
+ Exit Status:
274
+ Returns success unless COMMAND is not found or a redirection error occurs.`],exit:["exit [n]",`Exit the shell.
275
+ Exits the shell with a status of N. If N is omitted, the exit status
276
+ is that of the last command executed.`],export:["export [-fn] [name[=value] ...] or export -p",`Set export attribute for shell variables.
277
+ Marks each NAME for automatic export to the environment of subsequently
278
+ executed commands. If VALUE is supplied, assign VALUE before exporting.
279
+
280
+ Options:
281
+ -f refer to shell functions
282
+ -n remove the export property from each NAME
283
+ -p display a list of all exported variables and functions
284
+
285
+ Exit Status:
286
+ Returns success unless an invalid option is given or NAME is invalid.`],false:["false",`Return an unsuccessful result.
287
+ Exit Status:
288
+ Always fails.`],fc:["fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]",`Display or execute commands from the history list.
289
+ Exit Status:
290
+ Returns success or status of executed command.`],fg:["fg [job_spec]",`Move job to the foreground.
291
+ Place the job identified by JOB_SPEC in the foreground, making it the
292
+ current job.`],getopts:["getopts optstring name [arg]",`Parse option arguments.
293
+ Getopts is used by shell procedures to parse positional parameters
294
+ as options.
295
+
296
+ OPTSTRING contains the option letters to be recognized; if a letter
297
+ is followed by a colon, the option is expected to have an argument,
298
+ which should be separated from it by white space.
299
+ Exit Status:
300
+ Returns success if an option is found; fails if the end of options is
301
+ encountered or an error occurs.`],hash:["hash [-lr] [-p pathname] [-dt] [name ...]",`Remember or display program locations.
302
+ Determine and remember the full pathname of each command NAME.
303
+ Exit Status:
304
+ Returns success unless NAME is not found or an invalid option is given.`],help:["help [-s] [pattern ...]",`Display information about builtin commands.
305
+ Displays brief summaries of builtin commands. If PATTERN is
306
+ specified, gives detailed help on all commands matching PATTERN,
307
+ otherwise the list of help topics is printed.
308
+
309
+ Options:
310
+ -s output only a short usage synopsis for each topic matching
311
+ PATTERN
312
+
313
+ Exit Status:
314
+ 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.
315
+ Display the history list with line numbers, prefixing each modified
316
+ entry with a \`*'.
317
+ Exit Status:
318
+ 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.
319
+ Lists the active jobs.
320
+ Exit Status:
321
+ 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.
322
+ Send the processes identified by PID or JOBSPEC the signal named by
323
+ SIGSPEC or SIGNUM.
324
+ Exit Status:
325
+ Returns success unless an invalid option is given or an error occurs.`],let:["let arg [arg ...]",`Evaluate arithmetic expressions.
326
+ Evaluate each ARG as an arithmetic expression. Evaluation is done in
327
+ fixed-width integers with no check for overflow, though division by 0
328
+ is trapped and flagged as an error.
329
+ Exit Status:
330
+ If the last ARG evaluates to 0, let returns 1; 0 is returned otherwise.`],local:["local [option] name[=value] ...",`Define local variables.
331
+ Create a local variable called NAME, and give it VALUE. OPTION can
332
+ be any option accepted by \`declare'.
333
+
334
+ Local can only be used within a function; it makes the variable NAME
335
+ have a visible scope restricted to that function and its children.
336
+ Exit Status:
337
+ Returns success unless an invalid option is supplied, a variable
338
+ assignment error occurs, or the shell is not executing a function.`],logout:["logout [n]",`Exit a login shell.
339
+ Exits a login shell with exit status N. Returns an error if not executed
340
+ 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.
341
+ Read lines from the standard input into the indexed array variable ARRAY,
342
+ or from file descriptor FD if the -u option is supplied.
343
+
344
+ Options:
345
+ -d delim Use DELIM to terminate lines, instead of newline
346
+ -n count Copy at most COUNT lines
347
+ -O origin Begin assigning to ARRAY at index ORIGIN
348
+ -s count Discard the first COUNT lines read
349
+ -t Remove a trailing DELIM from each line read (default newline)
350
+ -u fd Read lines from file descriptor FD instead of standard input
351
+
352
+ Exit Status:
353
+ Returns success unless an invalid option is given or ARRAY is readonly.`],popd:["popd [-n] [+N | -N]",`Remove directories from stack.
354
+ Removes entries from the directory stack.
355
+ Exit Status:
356
+ Returns success unless an invalid argument is supplied or the directory
357
+ change fails.`],printf:["printf [-v var] format [arguments]",`Formats and prints ARGUMENTS under control of the FORMAT.
358
+
359
+ Options:
360
+ -v var assign the output to shell variable VAR rather than
361
+ display it on the standard output
362
+
363
+ FORMAT is a character string which contains three types of objects: plain
364
+ characters, which are simply copied to standard output; character escape
365
+ sequences, which are converted and copied to the standard output; and
366
+ format specifications, each of which causes printing of the next successive
367
+ argument.
368
+ Exit Status:
369
+ Returns success unless an invalid option is given or a write or assignment
370
+ error occurs.`],pushd:["pushd [-n] [+N | -N | dir]",`Add directories to stack.
371
+ Adds a directory to the top of the directory stack, or rotates
372
+ the stack, making the new top of the stack the current working
373
+ directory.
374
+ Exit Status:
375
+ Returns success unless an invalid argument is supplied or the directory
376
+ change fails.`],pwd:["pwd [-LP]",`Print the name of the current working directory.
377
+
378
+ Options:
379
+ -L print the value of $PWD if it names the current working
380
+ directory
381
+ -P print the physical directory, without any symbolic links
382
+
383
+ By default, \`pwd' behaves as if \`-L' were specified.
384
+ Exit Status:
385
+ Returns 0 unless an invalid option is given or the current directory
386
+ 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.
387
+ Reads a single line from the standard input, or from file descriptor FD
388
+ if the -u option is supplied. The line is split into fields as with word
389
+ splitting, and the first word is assigned to the first NAME, the second
390
+ word to the second NAME, and so on, with any leftover words assigned to
391
+ the last NAME.
392
+ Exit Status:
393
+ The return code is zero, unless end-of-file is encountered, read times out,
394
+ 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.
395
+ Mark each NAME as read-only; the values of these NAMEs may not be
396
+ changed by subsequent assignment.
397
+ Exit Status:
398
+ Returns success unless an invalid option is given or NAME is invalid.`],return:["return [n]",`Return from a shell function.
399
+ Causes a function or sourced script to exit with the return value
400
+ specified by N. If N is omitted, the return status is that of the
401
+ last command executed within the function or script.
402
+ Exit Status:
403
+ 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.
404
+ Change the value of shell attributes and positional parameters, or
405
+ display the names and values of shell variables.
406
+
407
+ Options:
408
+ -e Exit immediately if a command exits with a non-zero status.
409
+ -u Treat unset variables as an error when substituting.
410
+ -x Print commands and their arguments as they are executed.
411
+ -o option-name
412
+ Set the variable corresponding to option-name
413
+
414
+ Exit Status:
415
+ Returns success unless an invalid option is given.`],shift:["shift [n]",`Shift positional parameters.
416
+ Rename the positional parameters $N+1,$N+2 ... to $1,$2 ... If N is
417
+ not given, it is assumed to be 1.
418
+ Exit Status:
419
+ Returns success unless N is negative or greater than $#.`],shopt:["shopt [-pqsu] [-o] [optname ...]",`Set and unset shell options.
420
+ Change the setting of each shell option OPTNAME. Without any option
421
+ arguments, list each supplied OPTNAME, or all shell options if no
422
+ OPTNAMEs are given, with an indication of whether or not each is set.
423
+
424
+ Options:
425
+ -o restrict OPTNAMEs to those defined for use with \`set -o'
426
+ -p print each shell option with an indication of its status
427
+ -q suppress output
428
+ -s enable (set) each OPTNAME
429
+ -u disable (unset) each OPTNAME
430
+
431
+ Exit Status:
432
+ Returns success if OPTNAME is enabled; fails if an invalid option is
433
+ given or OPTNAME is disabled.`],source:["source filename [arguments]",`Execute commands from a file in the current shell.
434
+ Read and execute commands from FILENAME in the current shell.
435
+ The entries in $PATH are used to find the directory containing FILENAME.
436
+ Exit Status:
437
+ Returns the status of the last command executed in FILENAME.`],suspend:["suspend [-f]",`Suspend shell execution.
438
+ Suspend the execution of this shell until it receives a SIGCONT signal.`],test:["test [expr]",`Evaluate conditional expression.
439
+ Exits with a status of 0 (true) or 1 (false) depending on
440
+ the evaluation of EXPR. Expressions may be unary or binary.
441
+ Exit Status:
442
+ Returns success if EXPR evaluates to true; fails if EXPR evaluates to
443
+ false or an invalid argument is given.`],times:["times",`Display process times.
444
+ Prints the accumulated user and system times for the shell and all of its
445
+ child processes.
446
+ Exit Status:
447
+ Always succeeds.`],trap:["trap [-lp] [[arg] signal_spec ...]",`Trap signals and other events.
448
+ Defines and activates handlers to be run when the shell receives signals
449
+ or other conditions.
450
+ Exit Status:
451
+ Returns success unless a SIGSPEC is invalid or an invalid option is given.`],true:["true",`Return a successful result.
452
+ Exit Status:
453
+ Always succeeds.`],type:["type [-afptP] name [name ...]",`Display information about command type.
454
+ For each NAME, indicate how it would be interpreted if used as a
455
+ command name.
456
+
457
+ Options:
458
+ -a display all locations containing an executable named NAME
459
+ -f suppress shell function lookup
460
+ -P force a PATH search for each NAME, even if it is an alias,
461
+ builtin, or function, and returns the name of the disk file
462
+ that would be executed
463
+ -p returns either the name of the disk file that would be executed,
464
+ or nothing if \`type -t NAME' would not return \`file'
465
+ -t output a single word which is one of \`alias', \`keyword',
466
+ \`function', \`builtin', \`file' or \`', if NAME is an alias,
467
+ shell reserved word, shell function, shell builtin, disk file,
468
+ or not found, respectively
469
+
470
+ Exit Status:
471
+ 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.
472
+ Provides control over the resources available to the shell and processes
473
+ it creates, on systems that allow such control.
474
+ Exit Status:
475
+ Returns success unless an invalid option is supplied or an error occurs.`],umask:["umask [-p] [-S] [mode]",`Display or set file mode mask.
476
+ Sets the user file-creation mask to MODE. If MODE is omitted, prints
477
+ the current value of the mask.
478
+ Exit Status:
479
+ 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.
480
+ Exit Status:
481
+ 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.
482
+ For each NAME, remove the corresponding variable or function.
483
+
484
+ Options:
485
+ -f treat each NAME as a shell function
486
+ -v treat each NAME as a shell variable
487
+ -n treat each NAME as a name reference and unset the variable itself
488
+ rather than the variable it references
489
+
490
+ Without options, unset first tries to unset a variable, and if that fails,
491
+ tries to unset a function.
492
+ Exit Status:
493
+ 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.
494
+ Waits for each process identified by an ID, which may be a process ID or a
495
+ job specification, and reports its termination status.
496
+ Exit Status:
497
+ Returns the status of the last ID; fails if ID is invalid or an invalid
498
+ option is given.`]},zn=Object.keys(Mn).sort();function ws(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 f=1;f<l.length;f++){let c=l[f];if(c==="s")s=!0;else return S(`bash: help: -${c}: invalid option
499
+ `,2)}r++}else n.push(l),r++}if(n.length===0)return Ci();let i="",a=!1,o="";for(let l of n){let f=_i(l);if(f.length===0){o+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
500
+ `,a=!0;continue}for(let c of f){let[u,d]=Mn[c];s?i+=`${c}: ${u}
501
+ `:i+=`${c}: ${u}
502
+ ${d}
503
+ `}}return{exitCode:a?1:0,stdout:i,stderr:o}}function _i(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),s=new RegExp(`^${t}$`);return zn.filter(n=>s.test(n))}function Ci(){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=zn.slice(),n=Math.ceil(s.length/2);for(let r=0;r<n;r++){let i=s[r]||"",a=s[r+n]||"",o=i.padEnd(t);e.push(a?`${o}${a}`:i)}return W(`${e.join(`
504
+ `)}
505
+ `)}function Pi(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 vs(e,t){if(t.length===0)return S(`bash: let: expression expected
506
+ `);let s=Pi(t),n=0;for(let r of s)try{let a=de(`(( ${r} ))`).statements[0];if(a&&a.pipelines.length>0&&a.pipelines[0].commands.length>0){let o=a.pipelines[0].commands[0];o.type==="ArithmeticCommand"&&(n=await V(e,o.expression.expression))}}catch(i){return S(`bash: let: ${r}: ${i.message}
507
+ `)}return _("","",n===0?1:0)}async function bs(e,t){if(e.state.localScopes.length===0)return S(`bash: local: can only be used in a function
508
+ `);let s=e.state.localScopes[e.state.localScopes.length-1],n="",r=0,i=!1,a=!1,o=!1,l=[];for(let f of t)if(f==="-n")i=!0;else if(f==="-a")a=!0;else if(f==="-p")o=!0;else if(f.startsWith("-")&&!f.includes("="))for(let c of f.slice(1))c==="n"?i=!0:c==="a"?a=!0:c==="p"&&(o=!0);else l.push(f);if(l.length===0){let f="",c=Array.from(s.keys()).filter(u=>!u.includes("_")||!u.match(/_\d+$/)).filter(u=>!u.includes("__length")).sort();for(let u of c){let d=e.state.env[u];d!==void 0&&(f+=`${u}=${d}
509
+ `)}return _(f,"",0)}for(let f of l){let c,u,d=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){c=d[1];let b=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){n+=`bash: local: \`${f}': not a valid identifier
510
+ `,r=1;continue}if(K(e,c,"bash"),!s.has(c)){s.set(c,e.state.env[c]);let y=`${c}_`;for(let w of Object.keys(e.state.env))w.startsWith(y)&&!w.includes("__")&&(s.has(w)||s.set(w,e.state.env[w]))}let $=`${c}_`;for(let y of Object.keys(e.state.env))y.startsWith($)&&!y.includes("__")&&delete e.state.env[y];let N=me(b);for(let y=0;y<N.length;y++)e.state.env[`${c}_${y}`]=N[y];e.state.env[`${c}__length`]=String(N.length),Ae(e,c),i&&ge(e,c);continue}let h=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(h){c=h[1];let b=h[2];if(K(e,c,"bash"),!s.has(c)){s.set(c,e.state.env[c]);let v=`${c}_`;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 C=`${c}__length`;e.state.env[C]!==void 0&&!s.has(C)&&s.set(C,e.state.env[C])}let $=me(b),N=J(e,c),y=0;if(N.length===0&&e.state.env[c]!==void 0){let v=e.state.env[c];e.state.env[`${c}_0`]=v,delete e.state.env[c],y=1}else N.length>0&&(y=Math.max(...N)+1);for(let v=0;v<$.length;v++)e.state.env[`${c}_${y+v}`]=B(e,$[v]);let w=y+$.length;e.state.env[`${c}__length`]=String(w),Ae(e,c),i&&ge(e,c);continue}let m=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(m){c=m[1];let b=B(e,m[2]);K(e,c,"bash"),s.has(c)||s.set(c,e.state.env[c]);let $=e.state.env[c]??"";e.state.env[c]=$+b,Ae(e,c),i&&ge(e,c);continue}let p=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(p){c=p[1];let b=p[2],$=B(e,p[3]);if(K(e,c,"bash"),!s.has(c)){s.set(c,e.state.env[c]);let w=`${c}_`;for(let C of Object.keys(e.state.env))C.startsWith(w)&&!C.includes("__")&&(s.has(C)||s.set(C,e.state.env[C]));let v=`${c}__length`;e.state.env[v]!==void 0&&!s.has(v)&&s.set(v,e.state.env[v])}let N;try{let w=new M,v=q(w,b);N=await V(e,v.expression)}catch{let w=parseInt(b,10);N=Number.isNaN(w)?0:w}e.state.env[`${c}_${N}`]=$;let y=parseInt(e.state.env[`${c}__length`]??"0",10);N>=y&&(e.state.env[`${c}__length`]=String(N+1)),Ae(e,c),i&&ge(e,c);continue}if(f.includes("=")){let b=f.indexOf("=");c=f.slice(0,b),u=B(e,f.slice(b+1))}else c=f;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){n+=`bash: local: \`${f}': not a valid identifier
511
+ `,r=1;continue}let g=s.has(c);if(u!==void 0){let b=e.state.env[c];if(e.state.tempEnvBindings){let $=e.state.accessedTempEnvVars?.has(c),N=e.state.mutatedTempEnvVars?.has(c);if(!$&&!N)for(let y=e.state.tempEnvBindings.length-1;y>=0;y--){let w=e.state.tempEnvBindings[y];if(w.has(c)){b=w.get(c);break}}}An(e,c,b)}if(!g){let b=e.state.env[c];if(e.state.tempEnvBindings)for(let $=e.state.tempEnvBindings.length-1;$>=0;$--){let N=e.state.tempEnvBindings[$];if(N.has(c)){b=N.get(c);break}}if(s.set(c,b),a){let $=`${c}_`;for(let y of Object.keys(e.state.env))y.startsWith($)&&!y.includes("__")&&(s.has(y)||s.set(y,e.state.env[y]));let N=`${c}__length`;e.state.env[N]!==void 0&&!s.has(N)&&s.set(N,e.state.env[N])}}if(a&&u===void 0){let b=`${c}_`;for(let $ of Object.keys(e.state.env))$.startsWith(b)&&!$.includes("__")&&delete e.state.env[$];e.state.env[`${c}__length`]="0"}else if(u!==void 0){if(K(e,c,"bash"),i&&u!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(u)){n+=`bash: local: \`${u}': invalid variable name for name reference
512
+ `,r=1;continue}e.state.env[c]=u,e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(c))}else{let b=e.state.tempEnvBindings?.some($=>$.has(c));!g&&!b&&delete e.state.env[c]}Ae(e,c),i&&ge(e,c)}return _("",n,r)}function Es(e,t,s){let n=`
513
+ `,r=0,i=0,a=0,o=!1,l="MAPFILE",f=0;for(;f<t.length;){let b=t[f];b==="-d"&&f+1<t.length?(n=t[f+1]===""?"\0":t[f+1]||`
514
+ `,f+=2):b==="-n"&&f+1<t.length?(r=Number.parseInt(t[f+1],10)||0,f+=2):b==="-O"&&f+1<t.length?(i=Number.parseInt(t[f+1],10)||0,f+=2):b==="-s"&&f+1<t.length?(a=Number.parseInt(t[f+1],10)||0,f+=2):b==="-t"?(o=!0,f++):b==="-u"||b==="-C"||b==="-c"?f+=2:(b.startsWith("-")||(l=b),f++)}let c=s;!c&&e.state.groupStdin!==void 0&&(c=e.state.groupStdin);let u=[],d=c,h=0,m=0;for(;d.length>0;){let b=d.indexOf(n);if(b===-1){if(d.length>0){if(m<a)m++;else if(r===0||h<r){let y=d,w=y.indexOf("\0");w!==-1&&(y=y.substring(0,w)),u.push(y),h++}}break}let $=d.substring(0,b),N=$.indexOf("\0");if(N!==-1&&($=$.substring(0,N)),!o&&n!=="\0"&&($+=n),d=d.substring(b+n.length),m<a){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),g=i+u.length;return e.state.env[`${l}__length`]=String(Math.max(p,g)),e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=""),_("","",0)}function Ni(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),a=r+n+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let f=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(f)||f<0)return null;let c=o.slice(l+1);return{path:i,position:f,content:c}}function ki(e,t,s){return`__rw__:${e.length}:${e}:${t}:${s}`}function $s(e,t,s,n=-1){let r=!1,i=`
515
+ `,a="",o=-1,l=-1,f=null,c=-1,u=-1,d=[],h=0,m=!1,p=(A,P)=>{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:P+1}):P+1<t.length?(i=t[P+1],{nextArgIndex:P+2}):{nextArgIndex:P+1};if(E==="n"){if(D+1<A.length){let O=A.substring(D+1);return o=Number.parseInt(O,10),(Number.isNaN(o)||o<0)&&(m=!0,o=0),{nextArgIndex:P+1}}else if(P+1<t.length)return o=Number.parseInt(t[P+1],10),(Number.isNaN(o)||o<0)&&(m=!0,o=0),{nextArgIndex:P+2};return{nextArgIndex:P+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:P+1}}else if(P+1<t.length)return l=Number.parseInt(t[P+1],10),(Number.isNaN(l)||l<0)&&(m=!0,l=0),{nextArgIndex:P+2};return{nextArgIndex:P+1}}else{if(E==="a")return D+1<A.length?(f=A.substring(D+1),{nextArgIndex:P+1}):P+1<t.length?(f=t[P+1],{nextArgIndex:P+2}):{nextArgIndex:P+1};if(E==="p")return D+1<A.length?(a=A.substring(D+1),{nextArgIndex:P+1}):P+1<t.length?(a=t[P+1],{nextArgIndex:P+2}):{nextArgIndex:P+1};if(E==="u"){if(D+1<A.length){let O=A.substring(D+1);return c=Number.parseInt(O,10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:P+1}}else if(P+1<t.length)return c=Number.parseInt(t[P+1],10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:P+2};return{nextArgIndex:P+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:P+1}}else if(P+1<t.length)return u=Number.parseFloat(t[P+1]),Number.isNaN(u)&&(u=0),{nextArgIndex:P+2};return{nextArgIndex:P+1}}else if(E==="e"||E==="i"||E==="P"){if(E==="i"&&P+1<t.length)return{nextArgIndex:P+2};D++}else D++}}}return{nextArgIndex:P+1}};for(;h<t.length;){let A=t[h];if(A.startsWith("-")&&A.length>1&&A!=="--"){let P=p(A,h);if(P.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(P.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=P.nextArgIndex}else if(A==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push(A),h++}if(m)return _("","",1);if(d.length===0&&f===null&&d.push("REPLY"),u===0){if(f)he(e,f);else{for(let A of d)e.state.env[A]="";d.length===0&&(e.state.env.REPLY="")}return _("","",0)}if(u<0&&u!==-1)return _("","",1);let g=s;c>=0?e.state.fileDescriptors?g=e.state.fileDescriptors.get(c)||"":g="":!g&&e.state.groupStdin!==void 0&&(g=e.state.groupStdin);let b=i===""?"\0":i,$="",N=0,y=!0,w=A=>{if(c>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(c,g.substring(A));else if(n>=0&&e.state.fileDescriptors){let P=e.state.fileDescriptors.get(n);if(P?.startsWith("__rw__:")){let D=Ni(P);if(D){let E=D.position+A;e.state.fileDescriptors.set(n,ki(D.path,E,D.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=g.substring(A))};if(l>=0){let A=Math.min(l,g.length);$=g.substring(0,A),N=A,y=A>=l,w(N);let P=d[0]||"REPLY";e.state.env[P]=$;for(let D=1;D<d.length;D++)e.state.env[d[D]]="";return _("","",y?0:1)}else if(o>=0){let A=0,P=0,D=!1;for(;P<g.length&&A<o;){let E=g[P];if(E===b){N=P+1,D=!0;break}if(!r&&E==="\\"&&P+1<g.length){let O=g[P+1];if(O===b&&b===`
516
+ `){P+=2,N=P;continue}if(O===b){P+=2,A++,$+=O,N=P;continue}$+=O,P+=2,A++,N=P}else $+=E,P++,A++,N=P}y=A>=o||D,w(N)}else{N=0;let A=0;for(;A<g.length;){let P=g[A];if(P===b){N=A+b.length,y=!0;break}if(!r&&P==="\\"&&A+1<g.length){let D=g[A+1];if(D===`
517
+ `){A+=2;continue}if(D===b){$+=D,A+=2;continue}$+=P,$+=D,A+=2;continue}$+=P,A++}if(A>=g.length&&(y=!1,N=A,$.length===0&&g.length===0)){for(let P of d)e.state.env[P]="";return f&&he(e,f),_("","",1)}w(N)}b===`
518
+ `&&$.endsWith(`
519
+ `)&&($=$.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($),_("","",y?0:1);let C=Vs(e.state.env);if(f){let{words:A}=Tt($,C,void 0,r);he(e,f);for(let P=0;P<A.length;P++)e.state.env[`${f}_${P}`]=v(A[P]);return _("","",y?0:1)}let k=d.length,{words:T,wordStarts:x}=Tt($,C,k,r);for(let A=0;A<d.length;A++){let P=d[A];if(A<d.length-1)e.state.env[P]=v(T[A]??"");else if(A<x.length){let D=$.substring(x[A]);D=js(D,C,r),D=v(D),e.state.env[P]=D}else e.state.env[P]=""}return _("","",y?0:1)}function Ss(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
520
+ `,2);s=(r%256+256)%256}throw new se(s)}var _t=`set: usage: set [-eux] [+eux] [-o option] [+o option]
77
521
  Options:
78
522
  -e Exit immediately if a command exits with non-zero status
79
523
  +e Disable -e
@@ -89,80 +533,160 @@ Options:
89
533
  +o pipefail Disable pipefail
90
534
  -o xtrace Same as -x
91
535
  +o xtrace Disable xtrace
92
- `,An={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},Sn={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},xn=["errexit","nounset","pipefail","verbose","xtrace"],bn=["allexport","braceexpand","emacs","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","noclobber","noexec","noglob","nolog","notify","onecmd","physical","posix","privileged","vi"];function Cn(t,e,n){e!==null&&(t.state.options[e]=n)}function Hs(t,e){return e+1<t.length&&!t[e+1].startsWith("-")&&!t[e+1].startsWith("+")}function sr(t,e){if(e.includes("--help"))return j(rt);if(e.length===0){let r=Object.entries(t.state.env).filter(([s])=>/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)).sort(([s],[o])=>s.localeCompare(o)).map(([s,o])=>`${s}=${Gs(o)}`).join(`
93
- `);return j(r?`${r}
94
- `:"")}let n=0;for(;n<e.length;){let r=e[n];if((r==="-o"||r==="+o")&&Hs(e,n)){let s=e[n+1];if(!(s in Sn))return x(`bash: set: ${s}: invalid option name
95
- ${rt}`);Cn(t,Sn[s],r==="-o"),n+=2;continue}if(r==="-o"){let s=xn.map(a=>`${a.padEnd(16)}${t.state.options[a]?"on":"off"}`),o=bn.map(a=>`${a.padEnd(16)}off`),i=[...s,...o].sort();return j(`${i.join(`
536
+ `,Vn={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},jn={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},Bn=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],Hn=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Un(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,Ie(e))}function Oi(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Di(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}]=${ke(i)}`});return`${t}=(${n.join(" ")})`}function Ii(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Ti(e,t){let s=be(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env[`${t}_${r}`]??"";return`[${Ii(r)}]=${ke(i)}`});return`${t}=(${n.join(" ")} )`}function xi(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 Ri(e){return e.state.associativeArrays??new Set}function _s(e,t){if(t.includes("--help"))return W(_t);if(t.length===0){let n=xi(e),r=Ri(e),i=l=>{for(let f of r){let c=`${f}_`,u=`${f}__length`;if(l!==u&&l.startsWith(c)){if(l.slice(c.length).startsWith("_length"))continue;return!0}}return!1},a=[];for(let[l,f]of Object.entries(e.state.env)){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l)||n.has(l)||r.has(l))continue;let c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(c&&n.has(c[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])||a.push([l,f])}let o=[];for(let[l,f]of a.sort(([c],[u])=>c<u?-1:c>u?1:0))o.push(`${l}=${$t(f)}`);for(let l of[...n].sort((f,c)=>f<c?-1:f>c?1:0))o.push(Di(e,l));for(let l of[...r].sort((f,c)=>f<c?-1:f>c?1:0))o.push(Ti(e,l));return o.sort((l,f)=>{let c=l.split("=")[0],u=f.split("=")[0];return c<u?-1:c>u?1:0}),W(o.length>0?`${o.join(`
537
+ `)}
538
+ `:"")}let s=0;for(;s<t.length;){let n=t[s];if((n==="-o"||n==="+o")&&Oi(t,s)){let r=t[s+1];if(!(r in jn)){let i=`bash: set: ${r}: invalid option name
539
+ ${_t}`;if(e.state.options.posix)throw new ce(1,"",i);return S(i)}Un(e,jn[r],n==="-o"),s+=2;continue}if(n==="-o"){let r=Bn.map(o=>`${o.padEnd(16)}${e.state.options[o]?"on":"off"}`),i=Hn.map(o=>`${o.padEnd(16)}off`),a=[...r,...i].sort();return W(`${a.join(`
540
+ `)}
541
+ `)}if(n==="+o"){let r=Bn.map(o=>`set ${e.state.options[o]?"-o":"+o"} ${o}`),i=Hn.map(o=>`set +o ${o}`),a=[...r,...i].sort();return W(`${a.join(`
542
+ `)}
543
+ `)}if(n.length>1&&(n[0]==="-"||n[0]==="+")&&n[1]!=="-"){let r=n[0]==="-";for(let i=1;i<n.length;i++){let a=n[i];if(!(a in Vn)){let o=`bash: set: ${n[0]}${a}: invalid option
544
+ ${_t}`;if(e.state.options.posix)throw new ce(1,"",o);return S(o)}Un(e,Vn[a],r)}s++;continue}if(n==="--")return As(e,t.slice(s+1)),L;if(n==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,Ie(e),s+1<t.length)return As(e,t.slice(s+1)),L;s++;continue}if(n==="+"){s++;continue}if(n.startsWith("-")||n.startsWith("+")){let r=`bash: set: ${n}: invalid option
545
+ ${_t}`;if(e.state.options.posix)throw new ce(1,"",r);return S(r)}return As(e,t.slice(s)),L}return L}function As(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 Cs(e,t){let s=1;if(t.length>0){let a=Number.parseInt(t[0],10);if(Number.isNaN(a)||a<0){let o=`bash: shift: ${t[0]}: numeric argument required
546
+ `;if(e.state.options.posix)throw new ce(1,"",o);return S(o)}s=a}let n=Number.parseInt(e.state.env["#"]||"0",10);if(s>n){let a=`bash: shift: shift count out of range
547
+ `;if(e.state.options.posix)throw new ce(1,"",a);return S(a)}if(s===0)return L;let r=[];for(let a=1;a<=n;a++)r.push(e.state.env[String(a)]||"");let i=r.slice(s);for(let a=1;a<=n;a++)delete e.state.env[String(a)];for(let a=0;a<i.length;a++)e.state.env[String(a+1)]=i[a];return e.state.env["#"]=String(i.length),e.state.env["@"]=i.join(" "),L}async function Ps(e,t){let s=t;if(s.length>0&&s[0]==="--"&&(s=s.slice(1)),s.length===0)return _("",`bash: source: filename argument required
548
+ `,2);let n=s[0],r=null,i=null;if(n.includes("/")){let f=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(f),r=f}catch{}}else{let c=(e.state.env.PATH||"").split(":").filter(u=>u);for(let u of c){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
549
+ `);let a={};if(s.length>1){for(let c=1;c<=9;c++)a[String(c)]=e.state.env[String(c)];a["#"]=e.state.env["#"],a["@"]=e.state.env["@"];let f=s.slice(1);e.state.env["#"]=String(f.length),e.state.env["@"]=f.join(" ");for(let c=0;c<f.length&&c<9;c++)e.state.env[String(c+1)]=f[c];for(let c=f.length+1;c<=9;c++)delete e.state.env[String(c)]}let o=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=o,s.length>1)for(let[f,c]of Object.entries(a))c===void 0?delete e.state.env[f]:e.state.env[f]=c};e.state.sourceDepth++,e.state.currentSource=n;try{let f=de(i),c=await e.executeScript(f);return l(),c}catch(f){if(l(),f instanceof z)throw f;if(f instanceof se)return _(f.stdout,f.stderr,f.exitCode);if(f.name==="ParseException")return S(`bash: ${n}: ${f.message}
550
+ `);throw f}}function qn(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Li(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function Zn(e,t){if(Li(t))return null;try{let s=new M,n=q(s,t);return await V(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}function Gn(e,t){if(e.state.localVarStack?.has(t)){let n=vt(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)wt(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,n.scopeIndex),Ns(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],wt(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 a=!1;for(let o=n-1;o>=0;o--)if(e.state.localScopes[o].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,o+1),a=!0;break}return a||wt(e,t),!0}}return!1}function Ns(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 Kn(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 M().parseWordFromString(s,!0,!1);return I(e,r)}if(t.includes("$")){let n=new M().parseWordFromString(t,!1,!1);return I(e,n)}return t}async function ks(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 f=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(f){let d=f[1],h=f[2];if(h==="@"||h==="*"){let N=fe(e,d);for(let[y]of N)delete e.state.env[`${d}_${y}`];delete e.state.env[d];continue}let m=e.state.associativeArrays?.has(d);if(m){let N=await Kn(e,h);delete e.state.env[`${d}_${N}`];continue}let p=Lt(e,d),g=e.state.declaredVars?.has(d);if((d in e.state.env||g)&&!p&&!m){n+=`bash: unset: ${d}: not an array variable
551
+ `,r=1;continue}let $=await Zn(e,h);if($===null&&p){n+=`bash: unset: ${h}: not a valid identifier
552
+ `,r=1;continue}if($===null)continue;if($<0){let N=fe(e,d),y=N.length,w=e.state.currentLine;if(y===0){n+=`bash: line ${w}: unset: [${$}]: bad array subscript
553
+ `,r=1;continue}let v=y+$;if(v<0){n+=`bash: line ${w}: unset: [${$}]: bad array subscript
554
+ `,r=1;continue}let C=N[v][0];delete e.state.env[`${d}_${C}`];continue}delete e.state.env[`${d}_${$}`];continue}if(!qn(i)){n+=`bash: unset: \`${i}': not a valid identifier
555
+ `,r=1;continue}let c=i;if(oe(e,i)){let d=Ee(e,i);d&&d!==i&&(c=d)}if(Pe(e,c)){n+=`bash: unset: ${c}: cannot unset: readonly variable
556
+ `,r=1;continue}let u=xe(e,c);if(u!==void 0&&u!==e.state.callDepth)Gn(e,c);else if(e.state.fullyUnsetLocals?.has(c))delete e.state.env[c];else if(u!==void 0){let d=e.state.accessedTempEnvVars?.has(c),h=e.state.mutatedTempEnvVars?.has(c);if((d||h)&&e.state.localVarStack?.has(c)){let m=vt(e,c);m?m.value===void 0?delete e.state.env[c]:e.state.env[c]=m.value:delete e.state.env[c]}else delete e.state.env[c]}else Ns(e,c)||delete e.state.env[c];e.state.exportedVars?.delete(c);continue}let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let f=a[1],c=a[2];if(c==="@"||c==="*"){let p=fe(e,f);for(let[g]of p)delete e.state.env[`${f}_${g}`];delete e.state.env[f];continue}let u=e.state.associativeArrays?.has(f);if(u){let p=await Kn(e,c);delete e.state.env[`${f}_${p}`];continue}let d=Lt(e,f);if(f in e.state.env&&!d&&!u){n+=`bash: unset: ${f}: not an array variable
557
+ `,r=1;continue}let m=await Zn(e,c);if(m===null&&d){n+=`bash: unset: ${c}: not a valid identifier
558
+ `,r=1;continue}if(m===null)continue;if(m<0){let p=fe(e,f),g=p.length,b=e.state.currentLine;if(g===0){n+=`bash: line ${b}: unset: [${m}]: bad array subscript
559
+ `,r=1;continue}let $=g+m;if($<0){n+=`bash: line ${b}: unset: [${m}]: bad array subscript
560
+ `,r=1;continue}let N=p[$][0];delete e.state.env[`${f}_${N}`];continue}delete e.state.env[`${f}_${m}`];continue}if(!qn(i)){n+=`bash: unset: \`${i}': not a valid identifier
561
+ `,r=1;continue}let o=i;if(oe(e,i)){let f=Ee(e,i);f&&f!==i&&(o=f)}if(Pe(e,o)){n+=`bash: unset: ${o}: cannot unset: readonly variable
562
+ `,r=1;continue}let l=xe(e,o);if(l!==void 0&&l!==e.state.callDepth)Gn(e,o);else if(e.state.fullyUnsetLocals?.has(o))delete e.state.env[o];else if(l!==void 0){let f=e.state.accessedTempEnvVars?.has(o),c=e.state.mutatedTempEnvVars?.has(o);if((f||c)&&e.state.localVarStack?.has(o)){let u=vt(e,o);u?u.value===void 0?delete e.state.env[o]:e.state.env[o]=u.value:delete e.state.env[o]}else delete e.state.env[o]}else Ns(e,o)||delete e.state.env[o];e.state.exportedVars?.delete(o),e.state.functions.delete(i)}return _("",n,r)}var Os=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],Wi=["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 Ct(e){return Os.includes(e)}function Fi(e){return Wi.includes(e)}function Xn(e,t){let s=!1,n=!1,r=!1,i=!1,a=!1,o=[],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":a=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${m}: invalid option
563
+ `}}}l++}else break}for(;l<t.length;)o.push(t[l]),l++;if(a)return Mi(e,o,s,n,r,i);if(s&&n)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
564
+ `};if(o.length===0){if(s||n){let h=[];for(let m of Os){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(`
565
+ `)}
566
+ `:"",stderr:""}}let d=[];for(let h of Os){let m=e.state.shoptOptions[h];d.push(r?`shopt ${m?"-s":"-u"} ${h}`:`${h} ${m?"on":"off"}`)}return{exitCode:0,stdout:`${d.join(`
567
+ `)}
568
+ `,stderr:""}}let f=!1,c="",u=[];for(let d of o){if(!Ct(d)&&!Fi(d)){c+=`shopt: ${d}: invalid shell option name
569
+ `,f=!0;continue}if(s)Ct(d)&&(e.state.shoptOptions[d]=!0,zt(e));else if(n)Ct(d)&&(e.state.shoptOptions[d]=!1,zt(e));else if(Ct(d)){let h=e.state.shoptOptions[d];i?h||(f=!0):r?(u.push(`shopt ${h?"-s":"-u"} ${d}`),h||(f=!0)):(u.push(`${d} ${h?"on":"off"}`),h||(f=!0))}else i?f=!0:r?(u.push(`shopt -u ${d}`),f=!0):(u.push(`${d} off`),f=!0)}return{exitCode:f?1:0,stdout:u.length>0?`${u.join(`
570
+ `)}
571
+ `:"",stderr:c}}function Mi(e,t,s,n,r,i){let a={errexit:"errexit",pipefail:"pipefail",nounset:"nounset",xtrace:"xtrace",verbose:"verbose",posix:"posix",allexport:"allexport",noclobber:"noclobber",noglob:"noglob",noexec:"noexec",vi:"vi",emacs:"emacs"},o=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],l=[...Object.keys(a),...o].sort();if(t.length===0){let d=[];for(let h of l){let p=o.includes(h)?!1:e.state.options[a[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(`
96
572
  `)}
97
- `)}if(r==="+o"){let s=xn.map(a=>`set ${t.state.options[a]?"-o":"+o"} ${a}`),o=bn.map(a=>`set +o ${a}`),i=[...s,...o].sort();return j(`${i.join(`
573
+ `:"",stderr:""}}let f=!1,c="",u=[];for(let d of t){let h=d in a,m=o.includes(d);if(!h&&!m){c+=`shopt: ${d}: invalid option name
574
+ `,f=!0;continue}if(m){s||n||(i?f=!0:r?(u.push(`set +o ${d}`),f=!0):(u.push(`${d} off`),f=!0));continue}let p=a[d];if(s)p==="vi"?e.state.options.emacs=!1:p==="emacs"&&(e.state.options.vi=!1),e.state.options[p]=!0,Ie(e);else if(n)e.state.options[p]=!1,Ie(e);else{let g=e.state.options[p];i?g||(f=!0):r?(u.push(`set ${g?"-o":"+o"} ${d}`),g||(f=!0)):(u.push(`${d} ${g?"on":"off"}`),g||(f=!0))}}return{exitCode:f?1:0,stdout:u.length>0?`${u.join(`
98
575
  `)}
99
- `)}if(r.length>1&&(r[0]==="-"||r[0]==="+")&&r[1]!=="-"){let s=r[0]==="-";for(let o=1;o<r.length;o++){let i=r[o];if(!(i in An))return x(`bash: set: ${r[0]}${i}: invalid option
100
- ${rt}`);Cn(t,An[i],s)}n++;continue}if(r==="--")return nr(t,e.slice(n+1)),$;if(r==="-"){if(t.state.options.xtrace=!1,t.state.options.verbose=!1,n+1<e.length)return nr(t,e.slice(n+1)),$;n++;continue}if(r==="+"){n++;continue}return r.startsWith("-")||r.startsWith("+")?x(`bash: set: ${r}: invalid option
101
- ${rt}`):(nr(t,e.slice(n)),$)}return $}function nr(t,e){let n=1;for(;t.state.env[String(n)]!==void 0;)delete t.state.env[String(n)],n++;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 ir(t,e){let n=1;if(e.length>0){let i=Number.parseInt(e[0],10);if(Number.isNaN(i)||i<0)return x(`bash: shift: ${e[0]}: numeric argument required
102
- `);n=i}let r=Number.parseInt(t.state.env["#"]||"0",10);if(n>r)return x(`bash: shift: shift count out of range
103
- `);if(n===0)return $;let s=[];for(let i=1;i<=r;i++)s.push(t.state.env[String(i)]||"");let o=s.slice(n);for(let i=1;i<=r;i++)delete t.state.env[String(i)];for(let i=0;i<o.length;i++)t.state.env[String(i+1)]=o[i];return t.state.env["#"]=String(o.length),t.state.env["@"]=o.join(" "),$}async function or(t,e){let n=e;if(n.length>0&&n[0]==="--"&&(n=n.slice(1)),n.length===0)return S("",`bash: source: filename argument required
104
- `,2);let r=n[0],s=null,o=null;if(r.includes("/")){let c=t.fs.resolvePath(t.state.cwd,r);try{o=await t.fs.readFile(c),s=c}catch{}}else{let l=(t.state.env.PATH||"").split(":").filter(u=>u);for(let u of l){let d=t.fs.resolvePath(t.state.cwd,`${u}/${r}`);try{if((await t.fs.stat(d)).isDirectory)continue;o=await t.fs.readFile(d),s=d;break}catch{}}if(o===null){let u=t.fs.resolvePath(t.state.cwd,r);try{o=await t.fs.readFile(u),s=u}catch{}}}if(o===null)return x(`bash: ${r}: No such file or directory
105
- `);let i={};if(n.length>1){for(let l=1;l<=9;l++)i[String(l)]=t.state.env[String(l)];i["#"]=t.state.env["#"],i["@"]=t.state.env["@"];let c=n.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--,n.length>1)for(let[c,l]of Object.entries(i))l===void 0?delete t.state.env[c]:t.state.env[c]=l};t.state.sourceDepth++;try{let c=le(o),l=await t.executeScript(c);return a(),l}catch(c){if(a(),c instanceof k)throw c;if(c instanceof G)return S(c.stdout,c.stderr,c.exitCode);if(c.name==="ParseException")return x(`bash: ${r}: ${c.message}
106
- `);throw c}}function ar(t,e){let n="variable",r="",s=0;for(let o of e){if(o==="-v"){n="variable";continue}if(o==="-f"){n="function";continue}if(n==="function"){t.state.functions.delete(o);continue}let i=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(i){let a=i[1],c=i[2];if(c==="@"||c==="*"){let u=T(t,a);for(let[d]of u)delete t.state.env[`${a}_${d}`];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=T(t,a),d=u.length;if(d===0){r+=`bash: unset: [${l}]: bad array subscript
107
- `,s=1;continue}let h=d+l;if(h<0){r+=`bash: unset: [${l}]: bad array subscript
108
- `,s=1;continue}let m=u[h][0];delete t.state.env[`${a}_${m}`];continue}delete t.state.env[`${a}_${l}`];continue}delete t.state.env[o],t.state.functions.delete(o)}return S("",r,s)}function cr(t,e){return t.fs.resolvePath(t.state.cwd,e)}var Vs=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function nt(t){return Vs.includes(t)}async function st(t,e,n){let r=cr(t,n);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(o=>r===o||r.endsWith(o));case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return t.fs.exists(r);default:return!1}}var js=["-nt","-ot","-ef"];function it(t){return js.includes(t)}async function ot(t,e,n,r){let s=cr(t,n),o=cr(t,r);switch(e){case"-nt":try{let i=await t.fs.stat(s),a=await t.fs.stat(o);return i.mtime>a.mtime}catch{return!1}case"-ot":try{let i=await t.fs.stat(s),a=await t.fs.stat(o);return i.mtime<a.mtime}catch{return!1}case"-ef":try{if(!await t.fs.exists(s)||!await t.fs.exists(o))return!1;let i=t.fs.resolvePath(t.state.cwd,s),a=t.fs.resolvePath(t.state.cwd,o);return i===a}catch{return!1}default:return!1}}var qs=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function at(t){return qs.has(t)}function ct(t,e,n){switch(t){case"-eq":return e===n;case"-ne":return e!==n;case"-lt":return e<n;case"-le":return e<=n;case"-gt":return e>n;case"-ge":return e>=n}}function lt(t){return t==="="||t==="=="||t==="!="}function ut(t,e,n,r=!1){let s=r?ft(e,n):e===n;return t==="!="?!s:s}var Zs=new Set(["-z","-n"]);function dt(t){return Zs.has(t)}function ht(t,e){switch(t){case"-z":return e==="";case"-n":return e!==""}}function mt(t,e){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let r=n[1],s=n[2];s=s.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(i,a)=>t.state.env[a]||"");let o;if(/^-?\d+$/.test(s))o=Number.parseInt(s,10);else try{let i=Function(`"use strict"; return (${s})`)();o=typeof i=="number"?Math.floor(i):0}catch{let i=t.state.env[s];o=i?Number.parseInt(i,10):0}if(o<0){let i=Oe(t,r);if(i.length===0||(o=Math.max(...i)+1+o,o<0))return!1}return`${r}_${o}`in t.state.env}return e in t.state.env}async function de(t,e){switch(e.type){case"CondBinary":{let n=await P(t,e.left),r=await P(t,e.right),s=e.right.parts.length>0&&e.right.parts.every(o=>o.type==="SingleQuoted"||o.type==="DoubleQuoted"||o.type==="Escaped");if(lt(e.operator))return ut(e.operator,n,r,!s);if(at(e.operator))return ct(e.operator,Nn(t,n),Nn(t,r));if(it(e.operator))return ot(t,e.operator,n,r);switch(e.operator){case"=~":try{let o=new RegExp(r),i=n.match(o);if(i){t.state.env.BASH_REMATCH=i[0];for(let a=1;a<i.length;a++)t.state.env[`BASH_REMATCH_${a}`]=i[a]||""}return i!==null}catch{throw new Error("syntax error in regular expression")}case"<":return n<r;case">":return n>r;default:return!1}}case"CondUnary":{let n=await P(t,e.operand);return nt(e.operator)?st(t,e.operator,n):dt(e.operator)?ht(e.operator,n):e.operator==="-v"?mt(t,n):e.operator==="-o"?ur(t,n):!1}case"CondNot":return!await de(t,e.operand);case"CondAnd":return await de(t,e.left)?await de(t,e.right):!1;case"CondOr":return await de(t,e.left)?!0:await de(t,e.right);case"CondGroup":return await de(t,e.expression);case"CondWord":return await P(t,e.word)!=="";default:return!1}}async function Pe(t,e){if(e.length===0)return S("","",1);if(e.length===1)return O(!!e[0]);if(e.length===2){let r=e[0],s=e[1];return r==="("?x(`test: '(' without matching ')'
109
- `,2):nt(r)?O(await st(t,r,s)):dt(r)?O(ht(r,s)):r==="!"?O(!s):r==="-v"?O(mt(t,s)):r==="-o"?O(ur(t,s)):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
110
- `,2):S("","",1)}if(e.length===3){let r=e[0],s=e[1],o=e[2];if(lt(s))return O(ut(s,r,o));if(at(s)){let i=pt(r),a=pt(o);return!i.valid||!a.valid?S("","",2):O(ct(s,i.value,a.value))}if(it(s))return O(await ot(t,s,r,o));switch(s){case"-a":return O(r!==""&&o!=="");case"-o":return O(r!==""||o!=="");case">":return O(r>o);case"<":return O(r<o)}if(r==="!"){let i=await Pe(t,[s,o]);return S("",i.stderr,i.exitCode===0?1:i.exitCode===1?0:i.exitCode)}if(r==="("&&o===")")return O(s!=="")}if(e.length===4){if(e[0]==="!"){let r=await Pe(t,e.slice(1));return S("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(e[0]==="("&&e[3]===")")return Pe(t,[e[1],e[2]])}let n=await Pn(t,e,0);return n.pos<e.length?x(`test: too many arguments
111
- `,2):O(n.value)}async function Pn(t,e,n){return Qs(t,e,n)}async function Qs(t,e,n){let{value:r,pos:s}=await $n(t,e,n);for(;e[s]==="-o";){let o=await $n(t,e,s+1);r=r||o.value,s=o.pos}return{value:r,pos:s}}async function $n(t,e,n){let{value:r,pos:s}=await lr(t,e,n);for(;e[s]==="-a";){let o=await lr(t,e,s+1);r=r&&o.value,s=o.pos}return{value:r,pos:s}}async function lr(t,e,n){if(e[n]==="!"){let{value:r,pos:s}=await lr(t,e,n+1);return{value:!r,pos:s}}return Ks(t,e,n)}async function Ks(t,e,n){let r=e[n];if(r==="("){let{value:o,pos:i}=await Pn(t,e,n+1);return{value:o,pos:e[i]===")"?i+1:i}}if(nt(r)){let o=e[n+1]??"";return{value:await st(t,r,o),pos:n+2}}if(dt(r)){let o=e[n+1]??"";return{value:ht(r,o),pos:n+2}}if(r==="-v"){let o=e[n+1]??"";return{value:mt(t,o),pos:n+2}}if(r==="-o"){let o=e[n+1]??"";return{value:ur(t,o),pos:n+2}}let s=e[n+1];if(lt(s)){let o=r,i=e[n+2]??"";return{value:ut(s,o,i),pos:n+3}}if(at(s)){let o=pt(r),i=pt(e[n+2]??"0");return!o.valid||!i.valid?{value:!1,pos:n+3}:{value:ct(s,o.value,i.value),pos:n+3}}if(it(s)){let o=r,i=e[n+2]??"";return{value:await ot(t,s,o,i),pos:n+3}}return{value:r!==void 0&&r!=="",pos:n+1}}function ft(t,e){let n="^";for(let r=0;r<e.length;r++){let s=e[r];if(s==="\\")if(r+1<e.length){let o=e[r+1];/[\\^$.|+(){}[\]*?]/.test(o)?n+=`\\${o}`:n+=o,r++}else n+="\\\\";else if(s==="*")n+=".*";else if(s==="?")n+=".";else if(s==="["){let o=e.indexOf("]",r+1);o!==-1?(n+=e.slice(r,o+1),r=o):n+="\\["}else/[\\^$.|+(){}]/.test(s)?n+=`\\${s}`:n+=s}return n+="$",new RegExp(n).test(t)}function ur(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 Nn(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 vn(e);try{let n=new B,r=L(n,e);return N(t,r.expression)}catch{return vn(e)}}function Xs(t,e){let n=0;for(let r of t){let s;if(r>="0"&&r<="9")s=r.charCodeAt(0)-48;else if(r>="a"&&r<="z")s=r.charCodeAt(0)-97+10;else if(r>="A"&&r<="Z")s=r.charCodeAt(0)-65+36;else if(r==="@")s=62;else if(r==="_")s=63;else return Number.NaN;if(s>=e)return Number.NaN;n=n*e+s}return n}function vn(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 n,r=t.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(r){let s=Number.parseInt(r[1],10);s>=2&&s<=64?n=Xs(r[2],s):n=0}else/^0[xX][0-9a-fA-F]+$/.test(t)?n=Number.parseInt(t,16):/^0[0-7]+$/.test(t)?n=Number.parseInt(t,8):n=Number.parseInt(t,10);return Number.isNaN(n)&&(n=0),e?-n:n}function pt(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 n=Number.parseInt(t,10);return Number.isNaN(n)?{value:0,valid:!1}:{value:e?-n:n,valid:!0}}async function fr(t,e){let n=t.state.inCondition;t.state.inCondition=!0;let r="",s="",o=0;try{for(let i of e){let a=await t.executeStatement(i);r+=a.stdout,s+=a.stderr,o=a.exitCode}}finally{t.state.inCondition=n}return{stdout:r,stderr:s,exitCode:o}}function We(t,e,n,r){if(t instanceof U)return e+=t.stdout,n+=t.stderr,t.levels>1&&r>1?(t.levels--,t.stdout=e,t.stderr=n,{action:"rethrow",stdout:e,stderr:n,error:t}):{action:"break",stdout:e,stderr:n};if(t instanceof X)return e+=t.stdout,n+=t.stderr,t.levels>1&&r>1?(t.levels--,t.stdout=e,t.stderr=n,{action:"rethrow",stdout:e,stderr:n,error:t}):{action:"continue",stdout:e,stderr:n};if(t instanceof G||t instanceof ee||t instanceof k||t instanceof z)return t.prependOutput(e,n),{action:"rethrow",stdout:e,stderr:n,error:t};let s=Y(t);return{action:"error",stdout:e,stderr:`${n}${s}
112
- `,exitCode:1}}async function yt(t,e,n="",r=""){let s=n,o=r,i=0;try{for(let a of e){let c=await t.executeStatement(a);s+=c.stdout,o+=c.stderr,i=c.exitCode}}catch(a){if(Ue(a)||a instanceof ee||a instanceof k||a instanceof z||a instanceof oe)throw a.prependOutput(s,o),a;return{stdout:s,stderr:`${o}${Y(a)}
113
- `,exitCode:1}}return{stdout:s,stderr:o,exitCode:i}}async function In(t,e){let n="",r="";for(let s of e.clauses){let o=await fr(t,s.condition);if(n+=o.stdout,r+=o.stderr,o.exitCode===0)return yt(t,s.body,n,r)}return e.elseBody?yt(t,e.elseBody,n,r):S(n,r,0)}async function kn(t,e){let n="",r="",s=0,o=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e.variable))return x(`bash: \`${e.variable}': not a valid identifier
114
- `);let i=[];if(e.words===null)i=(t.state.env["@"]||"").split(" ").filter(Boolean);else if(e.words.length===0)i=[];else for(let a of e.words){let c=await Te(t,a);i.push(...c.values)}t.state.loopDepth++;try{for(let a of i){o++,o>t.limits.maxLoopIterations&&ie(`for loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),t.state.env[e.variable]=a;try{for(let c of e.body){let l=await t.executeStatement(c);n+=l.stdout,r+=l.stderr,s=l.exitCode}}catch(c){let l=We(c,n,r,t.state.loopDepth);if(n=l.stdout,r=l.stderr,l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return S(n,r,l.exitCode??1);throw l.error}}}finally{t.state.loopDepth--}return S(n,r,s)}async function Rn(t,e){let n="",r="",s=0,o=0;e.init&&await v(t,e.init.expression),t.state.loopDepth++;try{for(;o++,o>t.limits.maxLoopIterations&&ie(`for loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),!(e.condition&&await v(t,e.condition.expression)===0);){try{for(let i of e.body){let a=await t.executeStatement(i);n+=a.stdout,r+=a.stderr,s=a.exitCode}}catch(i){let a=We(i,n,r,t.state.loopDepth);if(n=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(n,r,a.exitCode??1);throw a.error}e.update&&await v(t,e.update.expression)}}finally{t.state.loopDepth--}return S(n,r,s)}async function Dn(t,e,n=""){let r="",s="",o=0,i=0,a=n;for(let l of e.redirections)if((l.operator==="<<"||l.operator==="<<-")&&l.target.type==="HereDoc"){let u=l.target,d=await P(t,u.content);u.stripTabs&&(d=d.split(`
115
- `).map(h=>h.replace(/^\t+/,"")).join(`
116
- `)),a=d}else if(l.operator==="<<<"&&l.target.type==="Word")a=`${await P(t,l.target)}
117
- `;else if(l.operator==="<"&&l.target.type==="Word")try{let u=await P(t,l.target),d=t.fs.resolvePath(t.state.cwd,u);a=await t.fs.readFile(d)}catch{let u=await P(t,l.target);return x(`bash: ${u}: No such file or directory
118
- `)}let c=t.state.groupStdin;a&&(t.state.groupStdin=a),t.state.loopDepth++;try{for(;;){i++,i>t.limits.maxLoopIterations&&ie(`while loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,s);let l=0,u=!1,d=!1,h=t.state.inCondition;t.state.inCondition=!0;try{for(let m of e.condition){let y=await t.executeStatement(m);r+=y.stdout,s+=y.stderr,l=y.exitCode}}catch(m){if(m instanceof U){if(r+=m.stdout,s+=m.stderr,m.levels>1&&t.state.loopDepth>1)throw m.levels--,m.stdout=r,m.stderr=s,t.state.inCondition=h,m;u=!0}else if(m instanceof X){if(r+=m.stdout,s+=m.stderr,m.levels>1&&t.state.loopDepth>1)throw m.levels--,m.stdout=r,m.stderr=s,t.state.inCondition=h,m;d=!0}else throw t.state.inCondition=h,m}finally{t.state.inCondition=h}if(u)break;if(!d){if(l!==0)break;try{for(let m of e.body){let y=await t.executeStatement(m);r+=y.stdout,s+=y.stderr,o=y.exitCode}}catch(m){let y=We(m,r,s,t.state.loopDepth);if(r=y.stdout,s=y.stderr,y.action==="break")break;if(y.action==="continue")continue;if(y.action==="error")return S(r,s,y.exitCode??1);throw y.error}}}}finally{t.state.loopDepth--,t.state.groupStdin=c}return S(r,s,o)}async function On(t,e){let n="",r="",s=0,o=0;t.state.loopDepth++;try{for(;;){o++,o>t.limits.maxLoopIterations&&ie(`until loop: too many iterations (${t.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r);let i=await fr(t,e.condition);if(n+=i.stdout,r+=i.stderr,i.exitCode===0)break;try{for(let a of e.body){let c=await t.executeStatement(a);n+=c.stdout,r+=c.stderr,s=c.exitCode}}catch(a){let c=We(a,n,r,t.state.loopDepth);if(n=c.stdout,r=c.stderr,c.action==="break")break;if(c.action==="continue")continue;if(c.action==="error")return S(n,r,c.exitCode??1);throw c.error}}}finally{t.state.loopDepth--}return S(n,r,s)}async function _n(t,e){let n="",r="",s=0,o=await P(t,e.word),i=!1;for(let a=0;a<e.items.length;a++){let c=e.items[a],l=i;if(!i)for(let u of c.patterns){let d=await P(t,u);if(an(u)&&(d=cn(d)),ft(o,d)){l=!0;break}}if(l){let u=await yt(t,c.body,n,r);if(n=u.stdout,r=u.stderr,s=u.exitCode,c.terminator===";;")break;c.terminator===";&"?i=!0:i=!1}else i=!1}return S(n,r,s)}function Ln(t,e){return t.state.functions.set(e.name,e),$}async function Tn(t,e,n){t.state.callDepth++,t.state.callDepth>t.limits.maxCallDepth&&(t.state.callDepth--,ie(`${e.name}: maximum recursion depth (${t.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),t.state.localScopes.push(new Map);let r={};for(let o=0;o<n.length;o++)r[String(o+1)]=t.state.env[String(o+1)],t.state.env[String(o+1)]=n[o];r["@"]=t.state.env["@"],r["#"]=t.state.env["#"],t.state.env["@"]=n.join(" "),t.state.env["#"]=String(n.length);let s=()=>{let o=t.state.localScopes.pop();if(o)for(let[i,a]of o)a===void 0?delete t.state.env[i]:t.state.env[i]=a;for(let[i,a]of Object.entries(r))a===void 0?delete t.state.env[i]:t.state.env[i]=a;t.state.callDepth--};try{let o=await t.executeCommand(e.body,"");return s(),o}catch(o){if(s(),o instanceof G)return S(o.stdout,o.stderr,o.exitCode);throw o}}async function Wn(t,e,n){let{stdout:r,stderr:s,exitCode:o}=e;for(let i of n){if(i.target.type==="HereDoc")continue;let a=await P(t,i.target);switch(i.operator){case">":{let c=i.fd??1;if(c===1){let l=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(l)).isDirectory){s+=`bash: ${a}: Is a directory
119
- `,o=1,r="";break}}catch{}await t.fs.writeFile(l,r,"binary"),r=""}else if(c===2)if(a==="/dev/null")s="";else{let l=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(l)).isDirectory){s+=`bash: ${a}: Is a directory
120
- `,o=1;break}}catch{}await t.fs.writeFile(l,s,"binary"),s=""}break}case">>":{let c=i.fd??1;if(c===1){let l=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(l)).isDirectory){s+=`bash: ${a}: Is a directory
121
- `,o=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){s+=`bash: ${a}: Is a directory
122
- `,o=1;break}}catch{}await t.fs.appendFile(l,s,"binary"),s=""}break}case">&":{let c=i.fd??1;a==="2"||a==="&2"?c===1&&(s+=r,r=""):(a==="1"||a==="&1")&&(r+=s,s="");break}case"&>":{let c=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(c)).isDirectory){s=`bash: ${a}: Is a directory
123
- `,o=1,r="";break}}catch{}await t.fs.writeFile(c,r+s,"binary"),r="",s="";break}case"&>>":{let c=t.fs.resolvePath(t.state.cwd,a);try{if((await t.fs.stat(c)).isDirectory){s=`bash: ${a}: Is a directory
124
- `,o=1,r="";break}}catch{}await t.fs.appendFile(c,r+s,"binary"),r="",s="";break}}}return S(r,s,o)}var Fe=class{ctx;constructor(e,n){this.ctx={state:n,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 n="",r="",s=0;for(let o of e.statements)try{let i=await this.executeStatement(o);n+=i.stdout,r+=i.stderr,s=i.exitCode,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s)}catch(i){if(i instanceof k)throw i.prependOutput(n,r),i;if(i instanceof z)throw i;if(i instanceof ee)return n+=i.stdout,r+=i.stderr,s=i.exitCode,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s),{stdout:n,stderr:r,exitCode:s,env:{...this.ctx.state.env}};if(i instanceof J)return n+=i.stdout,r+=i.stderr,s=1,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s),{stdout:n,stderr:r,exitCode:s,env:{...this.ctx.state.env}};if(i instanceof pe)return n+=i.stdout,r+=i.stderr,s=1,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s),{stdout:n,stderr:r,exitCode:s,env:{...this.ctx.state.env}};if(i instanceof U||i instanceof X){if(this.ctx.state.loopDepth>0)throw i.prependOutput(n,r),i;n+=i.stdout,r+=i.stderr;continue}throw i instanceof G&&i.prependOutput(n,r),i}return{stdout:n,stderr:r,exitCode:s,env:{...this.ctx.state.env}}}async executeStatement(e){this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&ie(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands");let n="",r="",s=0,o=-1,i=!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==="&&"&&s!==0||l==="||"&&s===0)continue;let u=await this.executePipeline(c);n+=u.stdout,r+=u.stderr,s=u.exitCode,o=a,i=c.negated,this.ctx.state.lastExitCode=s,this.ctx.state.env["?"]=String(s)}if(this.ctx.state.options.errexit&&s!==0&&o===e.pipelines.length-1&&!i&&!this.ctx.state.inCondition)throw new ee(s,n,r);return S(n,r,s)}async executePipeline(e){let n="",r=$,s=0,o=[];for(let i=0;i<e.commands.length;i++){let a=e.commands[i],c=i===e.commands.length-1,l;try{l=await this.executeCommand(a,n)}catch(u){if(u instanceof pe)l={stdout:u.stdout,stderr:u.stderr,exitCode:1};else if(u instanceof k&&e.commands.length>1)l={stdout:u.stdout,stderr:u.stderr,exitCode:u.exitCode};else throw u}o.push(l.exitCode),l.exitCode!==0&&(s=l.exitCode),c?r=l:(n=l.stdout,r={stdout:"",stderr:l.stderr,exitCode:l.exitCode})}for(let i of Object.keys(this.ctx.state.env))i.startsWith("PIPESTATUS_")&&delete this.ctx.state.env[i];for(let i=0;i<o.length;i++)this.ctx.state.env[`PIPESTATUS_${i}`]=String(o[i]);return this.ctx.state.env.PIPESTATUS__length=String(o.length),this.ctx.state.options.pipefail&&s!==0&&(r={...r,exitCode:s}),e.negated&&(r={...r,exitCode:r.exitCode===0?1:0}),r}async executeCommand(e,n){switch(e.type){case"SimpleCommand":return this.executeSimpleCommand(e,n);case"If":return In(this.ctx,e);case"For":return kn(this.ctx,e);case"CStyleFor":return Rn(this.ctx,e);case"While":return Dn(this.ctx,e,n);case"Until":return On(this.ctx,e);case"Case":return _n(this.ctx,e);case"Subshell":return this.executeSubshell(e,n);case"Group":return this.executeGroup(e,n);case"FunctionDef":return Ln(this.ctx,e);case"ArithmeticCommand":return this.executeArithmeticCommand(e);case"ConditionalCommand":return this.executeConditionalCommand(e);default:return $}}async executeSimpleCommand(e,n){try{return await this.executeSimpleCommandInner(e,n)}catch(r){if(r instanceof F)return x(r.stderr);throw r}}async executeSimpleCommandInner(e,n){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
125
- `,1);let E=fe(this.ctx,l);if(E)return E;let p=[];for(let g of c.array){let b=await Te(this.ctx,g);p.push(...b.values)}let w=0;if(c.append){let g=T(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 P(this.ctx,c.value):"";if(l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return S("",`bash: ${l}: bad array subscript
126
- `,1);let h=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(h){let E=h[1],p=h[2],w=fe(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 R=p.slice(1,-1),_=new B().parseWordFromString(R,!0,!1);I=await P(this.ctx,_)}else if(p.includes("$")){let me=new B().parseWordFromString(p,!1,!1);I=await P(this.ctx,me)}else I=p;b=`${E}_${I}`}else{let I;if(/^-?\d+$/.test(p))I=Number.parseInt(p,10);else{try{let R=new B,me=L(R,p);I=N(this.ctx,me.expression)}catch{let R=this.ctx.state.env[p];I=R?Number.parseInt(R,10):0}Number.isNaN(I)&&(I=0)}if(I<0){let R=T(this.ctx,E);if(R.length===0)return S("",`bash: ${E}[${p}]: bad array subscript
127
- `,1);if(I=Math.max(...R.map(([_])=>typeof _=="number"?_:0))+1+I,I<0)return S("",`bash: ${E}[${p}]: bad array subscript
128
- `,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=fe(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 P(this.ctx,l.content);l.stripTabs&&(u=u.split(`
576
+ `:"",stderr:c}}async function Yn(e,t,s){if(t.includes("/")){let a=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(a))return{error:"not_found",path:a};let o=a.split("/").pop()||t,l=e.commands.get(o);try{let f=await e.fs.stat(a);return f.isDirectory?{error:"permission_denied",path:a}:l?{cmd:l,path:a}:(f.mode&73)!==0?{script:!0,path:a}:{error:"permission_denied",path:a}}catch{return{error:"not_found",path:a}}}if(!s&&e.state.hashTable){let a=e.state.hashTable.get(t);if(a)if(await e.fs.exists(a)){let o=e.commands.get(t);if(o)return{cmd:o,path:a};try{let l=await e.fs.stat(a);if(!l.isDirectory&&(l.mode&73)!==0)return{script:!0,path:a}}catch{}}else e.state.hashTable.delete(t)}let r=(s??e.state.env.PATH??"/usr/bin:/bin").split(":");for(let a of r){if(!a)continue;let l=`${a.startsWith("/")?a:e.fs.resolvePath(e.state.cwd,a)}/${t}`;if(await e.fs.exists(l))try{let f=await e.fs.stat(l);if(f.isDirectory)continue;let c=(f.mode&73)!==0,u=e.commands.get(t),d=a==="/bin"||a==="/usr/bin";if(u&&d)return{cmd:u,path:l};if(c){if(u&&!d)return{script:!0,path:l};if(!u)return{script:!0,path:l}}}catch{}}if(!await e.fs.exists("/usr/bin")){let a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function Pt(e,t){let s=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let a=await e.fs.stat(i);a.isDirectory||(a.mode&73)!==0&&s.push(t)}catch{}return s}let r=(e.state.env.PATH||"/usr/bin:/bin").split(":");for(let i of r){if(!i)continue;let o=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(o)){try{if((await e.fs.stat(o)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?o:`${i}/${t}`)}}return s}async function tr(e,t,s,n){let r=!1,i=!1,a=!1,o=!1,l=!1,f=[];for(let p of t)if(p.startsWith("-")&&p.length>1)for(let g of p.slice(1))g==="t"?r=!0:g==="p"?i=!0:g==="P"?a=!0:g==="a"?o=!0:g==="f"&&(l=!0);else f.push(p);let c="",u="",d=0,h=!1,m=!1;for(let p of f){let g=!1;if(a){if(o){let v=await n(p);if(v.length>0){for(let C of v)c+=`${C}
577
+ `;h=!0,g=!0}}else{let v=await s(p);v&&(c+=`${v}
578
+ `,h=!0,g=!0)}g||(m=!0);continue}let b=!l&&e.state.functions.has(p);if(o&&b){if(!i)if(r)c+=`function
579
+ `;else{let v=e.state.functions.get(p),C=v?Qn(p,v):`${p} is a function
580
+ `;c+=C}g=!0}let $=e.state.env[`BASH_ALIAS_${p}`];if($!==void 0&&(o||!g)&&(i||(r?c+=`alias
581
+ `:c+=`${p} is aliased to \`${$}'
582
+ `),g=!0,!o)||Gt.has(p)&&(o||!g)&&(i||(r?c+=`keyword
583
+ `:c+=`${p} is a shell keyword
584
+ `),g=!0,!o))continue;if(!o&&b&&!g){if(!i)if(r)c+=`function
585
+ `;else{let v=e.state.functions.get(p),C=v?Qn(p,v):`${p} is a function
586
+ `;c+=C}g=!0;continue}if(!(je.has(p)&&(o||!g)&&(i||(r?c+=`builtin
587
+ `:c+=`${p} is a shell builtin
588
+ `),g=!0,!o))){if(o){let v=await n(p);for(let C of v)i?c+=`${C}
589
+ `:r?c+=`file
590
+ `:c+=`${p} is ${C}
591
+ `,h=!0,g=!0}else if(!g){let v=await s(p);v&&(i?c+=`${v}
592
+ `:r?c+=`file
593
+ `:c+=`${p} is ${v}
594
+ `,h=!0,g=!0)}if(!g&&(m=!0,!r&&!i)){let v=!0;if(p.includes("/")){let C=e.fs.resolvePath(e.state.cwd,p);await e.fs.exists(C)&&(v=!1)}v&&(u+=`bash: type: ${p}: not found
595
+ `)}}}return i?d=m&&!h?1:0:d=m?1:0,_(c,u,d)}function Qn(e,t){let s;return t.body.type==="Group"?s=t.body.body.map(r=>Ue(r)).join("; "):s=Ue(t.body),`${e} is a function
596
+ ${e} ()
597
+ {
598
+ ${s}
599
+ }
600
+ `}function Ue(e){if(Array.isArray(e))return e.map(t=>Ue(t)).join("; ");if(e.type==="Statement"){let t=[];for(let s=0;s<e.pipelines.length;s++){let n=e.pipelines[s];t.push(zi(n)),e.operators[s]&&t.push(e.operators[s])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,s=[];t.name&&s.push(Jn(t.name));for(let n of t.args)s.push(Jn(n));return s.join(" ")}return e.type==="Group"?`{ ${e.body.map(n=>Ue(n)).join("; ")}; }`:"..."}function zi(e){let t=e.commands.map(s=>Ue(s));return(e.negated?"! ":"")+t.join(" | ")}function Jn(e){let t="";for(let s of e.parts)s.type==="Literal"?t+=s.value:s.type==="DoubleQuoted"?t+=`"${s.parts.map(n=>er(n)).join("")}"`:s.type==="SingleQuoted"?t+=`'${s.value}'`:t+=er(s);return t}function er(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function sr(e,t,s,n){let r="",i="",a=0;for(let o of t){if(!o){a=1;continue}let l=e.state.env[`BASH_ALIAS_${o}`];if(l!==void 0)n?r+=`${o} is an alias for "${l}"
601
+ `:r+=`alias ${o}='${l}'
602
+ `;else if(Gt.has(o))n?r+=`${o} is a shell keyword
603
+ `:r+=`${o}
604
+ `;else if(je.has(o))n?r+=`${o} is a shell builtin
605
+ `:r+=`${o}
606
+ `;else if(e.state.functions.has(o))n?r+=`${o} is a function
607
+ `:r+=`${o}
608
+ `;else if(o.includes("/")){let f=e.fs.resolvePath(e.state.cwd,o),c=!1;if(await e.fs.exists(f))try{let u=await e.fs.stat(f);u.isDirectory||(u.mode&73)!==0&&(n?r+=`${o} is ${o}
609
+ `:r+=`${o}
610
+ `,c=!0)}catch{}c||(n&&(i+=`${o}: not found
611
+ `),a=1)}else if(e.commands.has(o)){let c=(e.state.env.PATH??"/usr/bin:/bin").split(":"),u=null;for(let d of c){if(!d)continue;let h=`${d}/${o}`;try{let m=await e.fs.stat(h);if(!m.isDirectory&&(m.mode&73)!==0){u=h;break}}catch{}}u||(u=`/usr/bin/${o}`),n?r+=`${o} is ${u}
612
+ `:r+=`${u}
613
+ `}else n&&(i+=`${o}: not found
614
+ `),a=1}return _(r,i,a)}async function nr(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 a=`${r.startsWith("/")?r:e.fs.resolvePath(e.state.cwd,r)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).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 rr(e,t,s,n,r,i,a,o){let{ctx:l,runCommand:f}=e;if(t==="export")return ys(l,s);if(t==="unset")return ks(l,s);if(t==="exit")return ms(l,s);if(t==="local")return bs(l,s);if(t==="set")return _s(l,s);if(t==="break")return jt(l,s);if(t==="continue")return ts(l,s);if(t==="return")return Ss(l,s);if(t==="eval"&&l.state.options.posix)return St(l,s,r);if(t==="shift")return Cs(l,s);if(t==="getopts")return At(l,s);if(t==="compgen")return Yt(l,s);if(t==="complete")return Jt(l,s);if(t==="compopt")return es(l,s);if(t==="pushd")return await ds(l,s);if(t==="popd")return hs(l,s);if(t==="dirs")return ps(l,s);if(t==="source"||t===".")return Ps(l,s);if(t==="read")return $s(l,s,r,o);if(t==="mapfile"||t==="readarray")return Es(l,s,r);if(t==="declare"||t==="typeset")return cs(l,s);if(t==="readonly")return fs(l,s);if(!i){let c=l.state.functions.get(t);if(c)return Et(l,c,s,r)}if(t==="eval")return St(l,s,r);if(t==="cd")return await Bt(l,s);if(t===":"||t==="true")return L;if(t==="false")return U(!1);if(t==="let")return vs(l,s);if(t==="command")return Vi(e,s,r);if(t==="builtin")return ji(e,s,r);if(t==="shopt")return Xn(l,s);if(t==="exec"){if(s.length===0)return L;let[c,...u]=s;return f(c,u,[],r,!1,!1,-1)}if(t==="wait")return L;if(t==="type")return await tr(l,s,c=>nr(l,c),c=>Pt(l,c));if(t==="hash")return gs(l,s);if(t==="help")return ws(l,s);if(t==="["||t==="test"){let c=s;if(t==="["){if(s[s.length-1]!=="]")return S("[: missing `]'\n",2);c=s.slice(0,-1)}return Ve(l,c)}return null}async function Vi(e,t,s){let{ctx:n,runCommand:r}=e;if(t.length===0)return L;let i=!1,a=!1,o=!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"?a=!0:d==="v"&&(o=!0);l=l.slice(1)}if(l.length===0)return L;if(o||a)return await sr(n,l,o,a);let[f,...c]=l;return r(f,c,[],s,!0,i,-1)}async function ji(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(!je.has(i))return S(`bash: builtin: ${i}: not a shell builtin
615
+ `);let[,...a]=r;return n(i,a,[],s,!0,!1,-1)}async function ir(e,t,s,n,r){let{ctx:i,buildExportedEnv:a,executeUserScript:o}=e,f=await Yn(i,t,r?"/usr/bin:/bin":void 0);if(!f)return hn(t)?S(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
616
+ `,127):S(`bash: ${t}: command not found
617
+ `,127);if("error"in f)return f.error==="permission_denied"?S(`bash: ${t}: Permission denied
618
+ `,126):S(`bash: ${t}: No such file or directory
619
+ `,127);if("script"in f)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f.path)),await o(f.path,s,n);let{cmd:c,path:u}=f;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u));let d=n||i.state.groupStdin||"",h=a(),m={fs:i.fs,cwd:i.state.cwd,env:i.state.env,exportedEnv:h,stdin:d,limits:i.limits,exec:i.execFn,fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo};try{return await c.execute(s,m)}catch(p){return S(`${t}: ${le(p)}
620
+ `)}}async function Ds(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let n="",r="",i=0;try{for(let a of t){let o=await e.executeStatement(a);n+=o.stdout,r+=o.stderr,i=o.exitCode}}finally{e.state.inCondition=s}return{stdout:n,stderr:r,exitCode:i}}function qe(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 ae||e instanceof z||e instanceof te)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let r=le(e);return{action:"error",stdout:t,stderr:`${s}${r}
621
+ `,exitCode:1}}async function Nt(e,t,s="",n=""){let r=s,i=n,a=0;try{for(let o of t){let l=await e.executeStatement(o);r+=l.stdout,i+=l.stderr,a=l.exitCode}}catch(o){if(Je(o)||o instanceof ae||o instanceof z||o instanceof te||o instanceof ve)throw o.prependOutput(r,i),o;return{stdout:r,stderr:`${i}${le(o)}
622
+ `,exitCode:1}}return{stdout:r,stderr:i,exitCode:a}}async function ar(e,t){let s="",n="";for(let r of t.clauses){let i=await Ds(e,r.condition);if(s+=i.stdout,n+=i.stderr,i.exitCode===0)return Nt(e,r.body,s,n)}return t.elseBody?Nt(e,t.elseBody,s,n):_(s,n,0)}async function or(e,t){let s=await ye(e,t.redirections);if(s)return s;let n="",r="",i=0,a=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return S(`bash: \`${t.variable}': not a valid identifier
623
+ `);let o=[];if(t.words===null)o=(e.state.env["@"]||"").split(" ").filter(Boolean);else if(t.words.length===0)o=[];else try{for(let f of t.words){let c=await pe(e,f);o.push(...c.values)}}catch(f){if(f instanceof Qe)return{stdout:"",stderr:f.stderr,exitCode:1};throw f}e.state.loopDepth++;try{for(let f of o){a++,a>e.limits.maxLoopIterations&&we(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),e.state.env[t.variable]=f;try{for(let c of t.body){let u=await e.executeStatement(c);n+=u.stdout,r+=u.stderr,i=u.exitCode}}catch(c){let u=qe(c,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=_(n,r,u.exitCode??1);return j(e,d,t.redirections)}throw u.error}}}finally{e.state.loopDepth--}let l=_(n,r,i);return j(e,l,t.redirections)}async function lr(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="",a=0,o=0;t.init&&await V(e,t.init.expression),e.state.loopDepth++;try{for(;o++,o>e.limits.maxLoopIterations&&we(`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 f of t.body){let c=await e.executeStatement(f);r+=c.stdout,i+=c.stderr,a=c.exitCode}}catch(f){let c=qe(f,r,i,e.state.loopDepth);if(r=c.stdout,i=c.stderr,c.action==="break")break;if(c.action==="continue"){t.update&&await V(e,t.update.expression);continue}if(c.action==="error"){let u=_(r,i,c.exitCode??1);return j(e,u,t.redirections)}throw c.error}t.update&&await V(e,t.update.expression)}}finally{e.state.loopDepth--}let l=_(r,i,a);return j(e,l,t.redirections)}async function cr(e,t,s=""){let n="",r="",i=0,a=0,o=s;for(let f of t.redirections)if((f.operator==="<<"||f.operator==="<<-")&&f.target.type==="HereDoc"){let c=f.target,u=await I(e,c.content);c.stripTabs&&(u=u.split(`
129
624
  `).map(d=>d.replace(/^\t+/,"")).join(`
130
- `)),n=u;continue}if(c.operator==="<<<"&&c.target.type==="Word"){n=`${await P(this.ctx,c.target)}
131
- `;continue}if(c.operator==="<"&&c.target.type==="Word")try{let l=await P(this.ctx,c.target),u=this.ctx.fs.resolvePath(this.ctx.state.cwd,l);n=await this.ctx.fs.readFile(u)}catch{let l=await P(this.ctx,c.target);for(let[u,d]of Object.entries(r))d===void 0?delete this.ctx.state.env[u]:this.ctx.state.env[u]=d;return x(`bash: ${l}: No such file or directory
132
- `)}}let s=await P(this.ctx,e.name),o=[],i=[];for(let c of e.args){let l=await Te(this.ctx,c);for(let u of l.values)o.push(u),i.push(l.quoted)}if(!s){if(e.name.parts.every(l=>l.type==="CommandSubstitution"||l.type==="ParameterExpansion"||l.type==="ArithmeticExpansion")){if(o.length>0){let l=o.shift();return i.shift(),await this.runCommand(l,o,i,n)}return S("","",this.ctx.state.lastExitCode)}return x(`bash: : command not found
133
- `,127)}let a=await this.runCommand(s,o,i,n);a=await Wn(this.ctx,a,e.redirections),this.ctx.state.lastArg=o.length>0?o[o.length-1]:s;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,n,r,s,o=!1){if(e==="cd")return await Ht(this.ctx,n);if(e==="export")return Xt(this.ctx,n);if(e==="unset")return ar(this.ctx,n);if(e==="exit")return Kt(this.ctx,n);if(e==="local")return Jt(this.ctx,n);if(e==="set")return sr(this.ctx,n);if(e==="break")return Gt(this.ctx,n);if(e==="continue")return Vt(this.ctx,n);if(e==="return")return rr(this.ctx,n);if(e==="eval")return Qt(this.ctx,n);if(e==="shift")return ir(this.ctx,n);if(e==="source"||e===".")return or(this.ctx,n);if(e==="read")return tr(this.ctx,n,s);if(e==="mapfile"||e==="readarray")return er(this.ctx,n,s);if(e==="declare"||e==="typeset")return qt(this.ctx,n);if(e==="readonly")return Zt(this.ctx,n);if(!o){let u=this.ctx.state.functions.get(e);if(u)return Tn(this.ctx,u,n)}if(e===":"||e==="true")return $;if(e==="false")return O(!1);if(e==="let")return Yt(this.ctx,n);if(e==="command"){if(n.length===0)return $;let u=n;for(;u.length>0&&u[0].startsWith("-");)u=u.slice(1);if(u.length===0)return $;let[d,...h]=u;return this.runCommand(d,h,[],s,!0)}if(e==="builtin"){if(n.length===0)return $;let[u,...d]=n;return this.runCommand(u,d,[],s)}if(e==="shopt")return $;if(e==="exec"){if(n.length===0)return $;let[u,...d]=n;return this.runCommand(u,d,[],s)}if(e==="wait")return $;if(e==="type")return this.handleType(n);if(e==="[["){let u=n.lastIndexOf("]]");if(u!==-1){let d=n.slice(0,u);return Pe(this.ctx,d)}return x("bash: [[: missing `]]'\n",2)}if(e==="["||e==="test"){let u=n;if(e==="["){if(n[n.length-1]!=="]")return x("[: missing `]'\n",2);u=n.slice(0,-1)}return Pe(this.ctx,u)}let i=await this.resolveCommand(e);if(!i)return $r(e)?x(`bash: ${e}: command not available in browser environments. Exclude '${e}' from your commands or use the Node.js bundle.
134
- `,127):x(`bash: ${e}: command not found
135
- `,127);let{cmd:a,path:c}=i,l={fs:this.ctx.fs,cwd:this.ctx.state.cwd,env:this.ctx.state.env,stdin:s,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(n,l)}catch(u){return x(`${e}: ${Y(u)}
136
- `)}}async resolveCommand(e){if(e.includes("/")){let o=this.ctx.fs.resolvePath(this.ctx.state.cwd,e);if(!await this.ctx.fs.exists(o))return null;let i=o.split("/").pop()||e,a=this.ctx.commands.get(i);return a?{cmd:a,path:o}:null}let r=(this.ctx.state.env.PATH||"/bin:/usr/bin").split(":");for(let o of r){if(!o)continue;let i=`${o}/${e}`;if(await this.ctx.fs.exists(i)){let a=this.ctx.commands.get(e);if(a)return{cmd:a,path:i}}}if(!await this.ctx.fs.exists("/bin")){let o=this.ctx.commands.get(e);if(o)return{cmd:o,path:`/bin/${e}`}}return null}async findCommandInPath(e){let n=[],s=(this.ctx.state.env.PATH||"/bin:/usr/bin").split(":");for(let o of s){if(!o)continue;let i=`${o}/${e}`;await this.ctx.fs.exists(i)&&n.push(i)}return n}handleType(e){let n=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"]),s="",o="",i=0;for(let a of e)n.has(a)?s+=`${a} is a shell keyword
137
- `:r.has(a)?s+=`${a} is a shell builtin
138
- `:this.ctx.state.functions.has(a)?s+=`${a} is a function
139
- `:this.ctx.commands.has(a)?s+=`${a} is /bin/${a}
140
- `:(o+=`bash: type: ${a}: not found
141
- `,i=1);return S(s,o,i)}async executeSubshell(e,n=""){let r={...this.ctx.state.env},s=this.ctx.state.cwd,o=this.ctx.state.loopDepth,i=this.ctx.state.parentHasLoopContext;this.ctx.state.parentHasLoopContext=o>0,this.ctx.state.loopDepth=0;let a=this.ctx.state.groupStdin;n&&(this.ctx.state.groupStdin=n);let c="",l="",u=0;try{for(let d of e.body){let h=await this.executeStatement(d);c+=h.stdout,l+=h.stderr,u=h.exitCode}}catch(d){if(this.ctx.state.env=r,this.ctx.state.cwd=s,this.ctx.state.loopDepth=o,this.ctx.state.parentHasLoopContext=i,this.ctx.state.groupStdin=a,d instanceof z)throw d;if(d instanceof oe)return c+=d.stdout,l+=d.stderr,S(c,l,0);if(d instanceof U||d instanceof X)return c+=d.stdout,l+=d.stderr,S(c,l,0);if(d instanceof k)return c+=d.stdout,l+=d.stderr,S(c,l,d.exitCode);if(d instanceof G)return c+=d.stdout,l+=d.stderr,S(c,l,d.exitCode);if(d instanceof ee)throw d.stdout=c+d.stdout,d.stderr=l+d.stderr,d;return S(c,`${l}${Y(d)}
142
- `,1)}return this.ctx.state.env=r,this.ctx.state.cwd=s,this.ctx.state.loopDepth=o,this.ctx.state.parentHasLoopContext=i,this.ctx.state.groupStdin=a,S(c,l,u)}async executeGroup(e,n=""){let r="",s="",o=0,i=this.ctx.state.groupStdin;n&&(this.ctx.state.groupStdin=n);try{for(let a of e.body){let c=await this.executeStatement(a);r+=c.stdout,s+=c.stderr,o=c.exitCode}}catch(a){if(this.ctx.state.groupStdin=i,a instanceof z)throw a;if(Ue(a)||a instanceof ee||a instanceof k)throw a.prependOutput(r,s),a;return S(r,`${s}${Y(a)}
143
- `,1)}return this.ctx.state.groupStdin=i,S(r,s,o)}async executeArithmeticCommand(e){try{let n=await v(this.ctx,e.expression.expression);return O(n!==0)}catch(n){return x(`bash: arithmetic expression: ${n.message}
144
- `)}}async executeConditionalCommand(e){try{let n=await de(this.ctx,e.expression);return O(n)}catch(n){return x(`bash: conditional expression: ${n.message}
145
- `,2)}}};var he={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3};function Fn(t){return t?{maxCallDepth:t.maxCallDepth??he.maxCallDepth,maxCommandCount:t.maxCommandCount??he.maxCommandCount,maxLoopIterations:t.maxLoopIterations??he.maxLoopIterations,maxAwkIterations:t.maxAwkIterations??he.maxAwkIterations,maxSedIterations:t.maxSedIterations??he.maxSedIterations,maxJqIterations:t.maxJqIterations??he.maxJqIterations,maxSqliteTimeoutMs:t.maxSqliteTimeoutMs??he.maxSqliteTimeoutMs}:{...he}}function Mn(t){try{let e=new URL(t);return{origin:e.origin,pathname:e.pathname,href:e.href}}catch{return null}}function Ys(t){let e=Mn(t);return e?{origin:e.origin,pathPrefix:e.pathname}:null}function Js(t,e){let n=Mn(t);if(!n)return!1;let r=Ys(e);return!r||n.origin!==r.origin?!1:r.pathPrefix==="/"||r.pathPrefix===""?!0:n.pathname.startsWith(r.pathPrefix)}function dr(t,e){return!e||e.length===0?!1:e.some(n=>Js(t,n))}var Me=class extends Error{constructor(e){super(`Network access denied: URL not in allow-list: ${e}`),this.name="NetworkAccessDeniedError"}},Be=class extends Error{constructor(e){super(`Too many redirects (max: ${e})`),this.name="TooManyRedirectsError"}},ze=class extends Error{constructor(e){super(`Redirect target not in allow-list: ${e}`),this.name="RedirectNotAllowedError"}},wt=class extends Error{constructor(e,n){super(`HTTP method '${e}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}};var ei=20,ti=3e4,ri=["GET","HEAD"],ni=new Set(["GET","HEAD","OPTIONS"]),si=new Set([301,302,303,307,308]);function hr(t){let e=t.maxRedirects??ei,n=t.timeoutMs??ti,r=t.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:t.allowedMethods??ri;function s(a){if(!t.dangerouslyAllowFullInternetAccess&&!dr(a,t.allowedUrlPrefixes??[]))throw new Me(a)}function o(a){if(t.dangerouslyAllowFullInternetAccess)return;let c=a.toUpperCase();if(!r.includes(c))throw new wt(c,r)}async function i(a,c={}){let l=c.method?.toUpperCase()??"GET";s(a),o(l);let u=a,d=0,h=c.followRedirects??!0,m=c.timeoutMs!==void 0?Math.min(c.timeoutMs,n):n;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&&!ni.has(l)&&(p.body=c.body);let w=await fetch(u,p);if(si.has(w.status)&&h){let g=w.headers.get("location");if(!g)return await Bn(w,u);let b=new URL(g,u).href;if(!t.dangerouslyAllowFullInternetAccess&&!dr(b,t.allowedUrlPrefixes??[]))throw new ze(b);if(d++,d>e)throw new Be(e);u=b;continue}return await Bn(w,u)}finally{clearTimeout(E)}}}return i}async function Bn(t,e){let n={};return t.headers.forEach((r,s)=>{n[s.toLowerCase()]=r}),{status:t.status,statusText:t.statusText,headers:n,body:await t.text(),url:e}}var Et=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;state;constructor(e={}){let n=e.fs??new ke(e.files);this.fs=n,this.useDefaultLayout=!e.cwd&&!e.files;let r=e.cwd||(this.useDefaultLayout?"/home/user":"/"),s={HOME:this.useDefaultLayout?"/home/user":"/",PATH:"/bin:/usr/bin",IFS:`
146
- `,OSTYPE:"linux-gnu",MACHTYPE:"x86_64-pc-linux-gnu",HOSTTYPE:"x86_64",PWD:r,OLDPWD:r,...e.env};if(this.limits=Fn({...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=hr(e.network)),this.sleepFn=e.sleep,this.traceFn=e.trace,this.logger=e.logger,this.state={env:s,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},Cr(n,this.useDefaultLayout),r!=="/"&&n instanceof ke)try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of wr(e.commands))this.registerCommand(o);if(e.network)for(let o of Er())this.registerCommand(o);if(e.customCommands)for(let o of e.customCommands)gr(o)?this.registerCommand(Ar(o)):this.registerCommand(o)}registerCommand(e){this.commands.set(e.name,e);let n=this.fs;if(typeof n.writeFileSync=="function")try{n.writeFileSync(`/bin/${e.name}`,`#!/bin/bash
147
- # Built-in command: ${e.name}
148
- `)}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,n){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.
149
- `,exitCode:1,env:{...this.state.env,...n?.env}};if(!e.trim())return{stdout:"",stderr:"",exitCode:0,env:{...this.state.env,...n?.env}};this.logger?.info("exec",{command:e});let r=n?.cwd??this.state.cwd,s={...this.state,env:{...this.state.env,...n?.env,...n?.cwd?{PWD:n.cwd}:{}},cwd:r,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options}},o=e;n?.rawScript||(o=e.split(`
150
- `).map(a=>a.trimStart()).join(`
151
- `));try{let i=le(o),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 Fe(a,s).executeScript(i);return this.logResult(l)}catch(i){if(i instanceof k)return this.logResult({stdout:i.stdout,stderr:i.stderr,exitCode:i.exitCode,env:{...this.state.env,...n?.env}});if(i instanceof F)return this.logResult({stdout:i.stdout,stderr:i.stderr,exitCode:1,env:{...this.state.env,...n?.env}});if(i instanceof z)return this.logResult({stdout:i.stdout,stderr:i.stderr,exitCode:z.EXIT_CODE,env:{...this.state.env,...n?.env}});if(i.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${i.message}
152
- `,exitCode:2,env:{...this.state.env,...n?.env}});if(i instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${i.message}
153
- `,exitCode:1,env:{...this.state.env,...n?.env}});throw i}}async readFile(e){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,e))}async writeFile(e,n){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,e),n)}getCwd(){return this.state.cwd}getEnv(){return{...this.state.env}}};import*as M from"node:fs";import*as Ie from"node:path";var ii="/home/user/project",gt=class{root;mountPoint;readOnly;memory=new Map;deleted=new Set;constructor(e){this.root=Ie.resolve(e.root);let n=e.mountPoint??ii;if(this.mountPoint=n==="/"?"/":n.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${n}`);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),n="";for(let r of e)n+=`/${r}`,this.memory.has(n)||this.memory.set(n,{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,n){let s=this.normalizePath(e).split("/").filter(Boolean),o="";for(let i of s)o+=`/${i}`,this.memory.has(o)||this.memory.set(o,{type:"directory",mode:493,mtime:new Date})}writeFileSync(e,n){let r=this.normalizePath(e),s=this.getDirname(r);s!=="/"&&this.mkdirSync(s);let o=n instanceof Uint8Array?n:new TextEncoder().encode(n);this.memory.set(r,{type:"file",content:o,mode:420,mtime:new Date})}getDirname(e){let n=e.lastIndexOf("/");return n===0?"/":e.slice(0,n)}normalizePath(e){if(!e||e==="/")return"/";let n=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;n.startsWith("/")||(n=`/${n}`);let r=n.split("/").filter(o=>o&&o!=="."),s=[];for(let o of r)o===".."?s.pop():s.push(o);return`/${s.join("/")}`||"/"}getRelativeToMount(e){return this.mountPoint==="/"?e:e===this.mountPoint?"/":e.startsWith(`${this.mountPoint}/`)?e.slice(this.mountPoint.length):null}toRealPath(e){let n=this.normalizePath(e),r=this.getRelativeToMount(n);if(r===null)return null;let s=Ie.join(this.root,r),o=Ie.resolve(s);return!o.startsWith(this.root)&&o!==this.root.replace(/\/$/,"")?null:o}dirname(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.lastIndexOf("/");return r===0?"/":n.slice(0,r)}ensureParentDirs(e){let n=this.dirname(e);n!=="/"&&(this.memory.has(n)||(this.ensureParentDirs(n),this.memory.set(n,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(n))}async existsInOverlay(e){let n=this.normalizePath(e);if(this.deleted.has(n))return!1;if(this.memory.has(n))return!0;let r=this.toRealPath(n);if(!r)return!1;try{return await M.promises.access(r),!0}catch{return!1}}async readFile(e,n){let r=await this.readFileBuffer(e),s=ae(n);return Ge(r,s)}async readFileBuffer(e,n=new Set){let r=this.normalizePath(e);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${e}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let i=this.resolveSymlink(r,s.target);return this.readFileBuffer(i,n)}if(s.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return s.content}let o=this.toRealPath(r);if(!o)throw new Error(`ENOENT: no such file or directory, open '${e}'`);try{let i=await M.promises.lstat(o);if(i.isSymbolicLink()){let c=await M.promises.readlink(o),l=this.resolveSymlink(r,c);return this.readFileBuffer(l,n)}if(i.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);let a=await M.promises.readFile(o);return new Uint8Array(a)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${e}'`):i}}async writeFile(e,n,r){this.assertWritable(`write '${e}'`);let s=this.normalizePath(e);this.ensureParentDirs(s);let o=ae(r),i=Se(n,o);this.memory.set(s,{type:"file",content:i,mode:420,mtime:new Date}),this.deleted.delete(s)}async appendFile(e,n,r){this.assertWritable(`append '${e}'`);let s=this.normalizePath(e),o=ae(r),i=Se(n,o),a;try{a=await this.readFileBuffer(s)}catch{a=new Uint8Array(0)}let c=new Uint8Array(a.length+i.length);c.set(a),c.set(i,a.length),this.ensureParentDirs(s),this.memory.set(s,{type:"file",content:c,mode:420,mtime:new Date}),this.deleted.delete(s)}async exists(e){return this.existsInOverlay(e)}async stat(e,n=new Set){let r=this.normalizePath(e);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${e}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let a=this.resolveSymlink(r,s.target);return this.stat(a,n)}let i=0;return s.type==="file"&&(i=s.content.length),{isFile:s.type==="file",isDirectory:s.type==="directory",isSymbolicLink:!1,mode:s.mode,size:i,mtime:s.mtime}}let o=this.toRealPath(r);if(!o)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);try{let i=await M.promises.stat(o);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:!1,mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${e}'`):i}}async lstat(e){let n=this.normalizePath(e);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let 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 s=this.toRealPath(n);if(!s)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);try{let o=await M.promises.lstat(s);return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:o.isSymbolicLink(),mode:o.mode,size:o.size,mtime:o.mtime}}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${e}'`):o}}resolveSymlink(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${n}`:`${r}/${n}`)}async mkdir(e,n){this.assertWritable(`mkdir '${e}'`);let r=this.normalizePath(e);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${e}'`);return}let o=this.dirname(r);if(o!=="/"&&!await this.existsInOverlay(o))if(n?.recursive)await this.mkdir(o,{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,n){if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let r=new Map,s=new Set,o=n==="/"?"/":`${n}/`;for(let a of this.deleted)if(a.startsWith(o)){let c=a.slice(o.length),l=c.split("/")[0];l&&!c.includes("/",l.length)&&s.add(l)}for(let[a,c]of this.memory)if(a!==n&&a.startsWith(o)){let l=a.slice(o.length),u=l.split("/")[0];u&&!s.has(u)&&!l.includes("/",1)&&r.set(u,{name:u,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}let i=this.toRealPath(n);if(i)try{let a=await M.promises.readdir(i,{withFileTypes:!0});for(let c of a)!s.has(c.name)&&!r.has(c.name)&&r.set(c.name,{name:c.name,isFile:c.isFile(),isDirectory:c.isDirectory(),isSymbolicLink:c.isSymbolicLink()})}catch(a){if(a.code==="ENOENT"){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`)}else if(a.code!=="ENOTDIR")throw a}return r}async resolveForReaddir(e,n=!1){let r=this.normalizePath(e),s=new Set,o=n,i=this.memory.get(r);for(;i&&i.type==="symlink";){if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${e}'`);s.add(r),o=!0,r=this.resolveSymlink(r,i.target),i=this.memory.get(r)}if(i)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),d=this.resolveSymlink(r,u);return this.resolveForReaddir(d,!0)}return{normalized:r,outsideOverlay:!1}}catch{return o?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async readdir(e){let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(e);if(r)return[];let s=await this.readdirCore(e,n);return Array.from(s.keys()).sort((o,i)=>o<i?-1:o>i?1:0)}async readdirWithFileTypes(e){let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(e);if(r)return[];let s=await this.readdirCore(e,n);return Array.from(s.values()).sort((o,i)=>o.name<i.name?-1:o.name>i.name?1:0)}async rm(e,n){this.assertWritable(`rm '${e}'`);let r=this.normalizePath(e);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}try{if((await this.stat(r)).isDirectory){let i=await this.readdir(r);if(i.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let a of i){let c=r==="/"?`/${a}`:`${r}/${a}`;await this.rm(c,n)}}}}catch{}this.deleted.add(r),this.memory.delete(r)}async cp(e,n,r){this.assertWritable(`cp '${n}'`);let s=this.normalizePath(e),o=this.normalizePath(n);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, cp '${e}'`);let a=await this.stat(s);if(a.isFile){let c=await this.readFileBuffer(s);await this.writeFile(o,c)}else if(a.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(o,{recursive:!0});let c=await this.readdir(s);for(let l of c){let u=s==="/"?`/${l}`:`${s}/${l}`,d=o==="/"?`/${l}`:`${o}/${l}`;await this.cp(u,d,r)}}}async mv(e,n){this.assertWritable(`mv '${n}'`),await this.cp(e,n,{recursive:!0}),await this.rm(e,{recursive:!0})}resolvePath(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=e==="/"?`/${n}`:`${e}/${n}`;return this.normalizePath(r)}getAllPaths(){let e=new Set(this.memory.keys());for(let n of this.deleted)e.delete(n);return this.scanRealFs("/",e),Array.from(e)}scanRealFs(e,n){if(this.deleted.has(e))return;let r=this.toRealPath(e);if(r)try{let s=M.readdirSync(r);for(let o of s){let i=e==="/"?`/${o}`:`${e}/${o}`;if(this.deleted.has(i))continue;n.add(i);let a=Ie.join(r,o);M.statSync(a).isDirectory()&&this.scanRealFs(i,n)}}catch{}}async chmod(e,n){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 o=this.memory.get(r);if(o){o.mode=n;return}let i=await this.stat(r);if(i.isFile){let a=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:a,mode:n,mtime:new Date})}else i.isDirectory&&this.memory.set(r,{type:"directory",mode:n,mtime:new Date})}async symlink(e,n){this.assertWritable(`symlink '${n}'`);let r=this.normalizePath(n);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.memory.set(r,{type:"symlink",target:e,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(e,n){this.assertWritable(`link '${n}'`);let r=this.normalizePath(e),s=this.normalizePath(n);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${e}'`);let i=await this.stat(r);if(!i.isFile)throw new Error(`EPERM: operation not permitted, link '${e}'`);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let c=await this.readFileBuffer(r);this.ensureParentDirs(s),this.memory.set(s,{type:"file",content:c,mode:i.mode,mtime:new Date}),this.deleted.delete(s)}async readlink(e){let n=this.normalizePath(e);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);let r=this.memory.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}let s=this.toRealPath(n);if(!s)throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);try{return await M.promises.readlink(s)}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${e}'`):o.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${e}'`):o}}};var W={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"},mr=class{env;rl;running=!0;history=[];isInteractive;constructor(e={}){let n=process.cwd(),r=new gt({root:n,mountPoint:"/"});this.env=new Et({fs:r,cwd:e.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...e.env},network:e.network!==!1?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.isInteractive=process.stdin.isTTY===!0,this.rl=Un.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C
625
+ `)),o=u}else if(f.operator==="<<<"&&f.target.type==="Word")o=`${await I(e,f.target)}
626
+ `;else if(f.operator==="<"&&f.target.type==="Word")try{let c=await I(e,f.target),u=e.fs.resolvePath(e.state.cwd,c);o=await e.fs.readFile(u)}catch{let c=await I(e,f.target);return S(`bash: ${c}: No such file or directory
627
+ `)}let l=e.state.groupStdin;o&&(e.state.groupStdin=o),e.state.loopDepth++;try{for(;;){a++,a>e.limits.maxLoopIterations&&we(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r);let f=0,c=!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,f=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;c=!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(c)break;if(!u){if(f!==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=qe(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 _(n,r,m.exitCode??1);throw m.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=l}return _(n,r,i)}async function fr(e,t){let s="",n="",r=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&we(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,n);let a=await Ds(e,t.condition);if(s+=a.stdout,n+=a.stderr,a.exitCode===0)break;try{for(let o of t.body){let l=await e.executeStatement(o);s+=l.stdout,n+=l.stderr,r=l.exitCode}}catch(o){let l=qe(o,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 _(s,n,l.exitCode??1);throw l.error}}}finally{e.state.loopDepth--}return _(s,n,r)}async function ur(e,t){let s=await ye(e,t.redirections);if(s)return s;let n="",r="",i=0,a=await I(e,t.word),o=!1;for(let f=0;f<t.items.length;f++){let c=t.items[f],u=o;if(!o)for(let d of c.patterns){let h=await I(e,d);Ks(d)&&(h=Zs(h));let m=e.state.shoptOptions.nocasematch,p=e.state.shoptOptions.extglob;if(Te(a,h,m,p)){u=!0;break}}if(u){let d=await Nt(e,c.body,n,r);if(n=d.stdout,r=d.stderr,i=d.exitCode,c.terminator===";;")break;c.terminator===";&"?o=!0:o=!1}else o=!1}let l=_(n,r,i);return j(e,l,t.redirections)}function Is(e,t){if(e.parts.length!==1)return!1;let s=e.parts[0];return s.type!=="Literal"?!1:t.includes(s.value)}function dr(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),a=r+n+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let f=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(f)||f<0)return null;let c=o.slice(l+1);return{path:i,position:f,content:c}}var hr="+ ";async function pr(e){let t=e.state.env.PS4;if(t===void 0)return hr;if(t==="")return"";try{let n=new M().parseWordFromString(t,!1,!1);return await I(e,n)}catch{return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
628
+ `,t||hr}}function Bi(e){return e.map(t=>Hi(t)).join(" ")}function Hi(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),n=e.includes(`
629
+ `),r=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(s||n||r||i){let l="";for(let f of e){let c=f.charCodeAt(0);f===`
630
+ `?l+="\\n":f===" "?l+="\\t":f==="\\"?l+="\\\\":f==="'"?l+="'":f==='"'?l+='"':c<32||c===127?c<256?l+=`\\x${c.toString(16).padStart(2,"0")}`:l+=`\\u${c.toString(16).padStart(4,"0")}`:l+=f}return`$'${l}'`}return a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function mr(e,t,s){if(!e.state.options.xtrace)return"";let n=await pr(e),r=[t,...s],i=Bi(r);return`${n}${i}
631
+ `}async function yr(e,t,s){return e.state.options.xtrace?`${await pr(e)}${t}=${s}
632
+ `:""}async function gr(e,t,s){let n=t.timed?performance.now():0,r="",i=L,a=0,o=[],l=t.commands.length>1,f=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,g;try{g=await s(d,r)}catch(b){if(b instanceof Ye)g={stdout:b.stdout,stderr:b.stderr,exitCode:1};else if(b instanceof z&&t.commands.length>1)g={stdout:b.stdout,stderr:b.stderr,exitCode:b.exitCode};else if(b instanceof ae&&t.commands.length>1)g={stdout:b.stdout,stderr:b.stderr,exitCode:b.exitCode};else throw p&&(e.state.env=p),b}p&&(e.state.env=p),o.push(g.exitCode),g.exitCode!==0&&(a=g.exitCode),h?i=g:t.pipeStderr?.[u]??!1?(r=g.stderr+g.stdout,i={stdout:"",stderr:"",exitCode:g.exitCode}):(r=g.stdout,i={stdout:"",stderr:g.stderr,exitCode:g.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<o.length;u++)e.state.env[`PIPESTATUS_${u}`]=String(o[u]);e.state.env.PIPESTATUS__length=String(o.length)}if(e.state.options.pipefail&&a!==0&&(i={...i,exitCode:a}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let d=(performance.now()-n)/1e3,h=Math.floor(d/60),m=d%60,p;t.timePosix?p=`real ${d.toFixed(2)}
633
+ user 0.00
634
+ sys 0.00
635
+ `:p=`
636
+ real ${`${h}m${m.toFixed(3)}s`}
637
+ user 0m0.000s
638
+ sys 0m0.000s
639
+ `,i={...i,stderr:i.stderr+p}}return l&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=f),i}async function wr(e,t){let s={},n="";for(let r of t.assignments){let i=r.name;if(r.array){let c=await Ui(e,t,i,r.array,r.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:c.error};if(n+=c.xtraceOutput,c.continueToNext)continue}let a=r.value?await I(e,r.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:_("",`bash: ${i}: bad array subscript
640
+ `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let c=await Xi(e,t,l[1],l[2],a,r.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:c.error};if(c.continueToNext)continue}let f=await Qi(e,t,i,a,r.append,s);if(f.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:f.error};n+=f.xtraceOutput,f.continueToNext}return{continueToNext:!1,xtraceOutput:n,tempAssignments:s}}async function Ui(e,t,s,n,r,i){let a="";if(/\[.+\]$/.test(s))return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: ${s}: cannot assign list to array member
641
+ `,1)};if(oe(e,s)){let c=Us(e,s);if(c===void 0||c==="")throw new z(1,"","");let u=Ee(e,s);if(u&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(u))return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: ${s}: cannot assign list to array member
642
+ `,1)}}if(Pe(e,s)){if(t.name)return a+=`bash: ${s}: readonly variable
643
+ `,{continueToNext:!0,xtraceOutput:a};let c=K(e,s);if(c)return{continueToNext:!1,xtraceOutput:"",error:c}}let o=e.state.associativeArrays?.has(s),l=qi(n),f=()=>{let c=`${s}_`;for(let u of Object.keys(e.state.env))u.startsWith(c)&&!u.includes("__")&&delete e.state.env[u];delete e.state.env[s]};if(o&&l?await Zi(e,t,s,n,r,f,c=>{a+=c}):l?await Gi(e,s,n,r,f):await Ki(e,s,n,r,f),t.name){i[s]=e.state.env[s];let u=`(${n.map(d=>tt(d)).join(" ")})`;e.state.env[s]=u}return{continueToNext:!0,xtraceOutput:a}}function qi(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 Zi(e,t,s,n,r,i,a){let o=[];for(let l of n){let f=It(l);if(f){let{key:c,valueParts:u,append:d}=f,h;u.length>0?h=await I(e,{type:"Word",parts:u}):h="",h=B(e,h),o.push({type:"keyed",key:c,value:h,append:d})}else{let c=await I(e,l);o.push({type:"invalid",expandedValue:c})}}r||i();for(let l of o)if(l.type==="keyed")if(l.append){let f=e.state.env[`${s}_${l.key}`]??"";e.state.env[`${s}_${l.key}`]=f+l.value}else e.state.env[`${s}_${l.key}`]=l.value;else{let f=t.line??e.state.currentLine??1;a(`bash: line ${f}: ${s}: ${l.expandedValue}: must use subscript when assigning associative array
644
+ `)}}async function Gi(e,t,s,n,r){let i=[];for(let o of s){let l=It(o);if(l){let{key:f,valueParts:c,append:u}=l,d;c.length>0?d=await I(e,{type:"Word",parts:c}):d="",d=B(e,d),i.push({type:"keyed",indexExpr:f,value:d,append:u})}else{let f=await pe(e,o);i.push({type:"non-keyed",values:f.values})}}n||r();let a=0;for(let o of i)if(o.type==="keyed"){let l;try{let f=new M,c=q(f,o.indexExpr);l=await V(e,c.expression,!1)}catch{if(/^-?\d+$/.test(o.indexExpr))l=Number.parseInt(o.indexExpr,10);else{let f=e.state.env[o.indexExpr];l=f?Number.parseInt(f,10):0,Number.isNaN(l)&&(l=0)}}if(o.append){let f=e.state.env[`${t}_${l}`]??"";e.state.env[`${t}_${l}`]=f+o.value}else e.state.env[`${t}_${l}`]=o.value;a=l+1}else for(let l of o.values)e.state.env[`${t}_${a++}`]=l}async function Ki(e,t,s,n,r){let i=[];for(let o of s){let l=await pe(e,o);i.push(...l.values)}let a=0;if(n){let o=fe(e,t);if(o.length>0)a=Math.max(...o.map(([f])=>typeof f=="number"?f: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],a=1}}else r();for(let o=0;o<i.length;o++)e.state.env[`${t}_${a+o}`]=i[o];n||(e.state.env[`${t}__length`]=String(i.length))}async function Xi(e,t,s,n,r,i,a){let o=s;if(oe(e,s)){let u=Ee(e,s);if(u&&u!==s){if(u.includes("["))return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: \`${u}': not a valid identifier
645
+ `,1)};o=u}}if(Pe(e,o)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let u=K(e,o);if(u)return{continueToNext:!1,xtraceOutput:"",error:u}}let l=e.state.associativeArrays?.has(o),f;if(l)f=await vr(e,o,n);else{let u=await Yi(e,o,n);if(u.error)return{continueToNext:!1,xtraceOutput:"",error:u.error};f=`${o}_${u.index}`}let c=i?(e.state.env[f]||"")+r:r;if(t.name)a[f]=e.state.env[f],e.state.env[f]=c;else{let u=xe(e,o);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(f)||d.set(f,e.state.env[f])}e.state.env[f]=c}return{continueToNext:!0,xtraceOutput:""}}async function vr(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),a=new M().parseWordFromString(r,!0,!1);n=await I(e,a)}else if(s.includes("$")){let i=new M().parseWordFromString(s,!1,!1);n=await I(e,i)}else n=s;return`${t}_${n}`}async function Yi(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 M,a=q(i,n);r=await V(e,a.expression,!1)}catch(i){if(i instanceof Ce){let l=`bash: line ${e.state.currentLine}: ${s}: ${i.message}
646
+ `;if(i.fatal)throw new z(1,"",l);return{index:0,error:_("",l,1)}}let a=e.state.env[s];r=a?Number.parseInt(a,10):0}Number.isNaN(r)&&(r=0)}if(r<0){let i=fe(e,t);if(i.length===0){let o=e.state.currentLine;return{index:0,error:_("",`bash: line ${o}: ${t}[${s}]: bad array subscript
647
+ `,1)}}if(r=Math.max(...i.map(([o])=>typeof o=="number"?o:0))+1+r,r<0){let o=e.state.currentLine;return{index:0,error:_("",`bash: line ${o}: ${t}[${s}]: bad array subscript
648
+ `,1)}}}return{index:r}}async function Qi(e,t,s,n,r,i){let a="",o=s,l=null;if(oe(e,s)){let u=qs(e,s,n);if(u===void 0)return{continueToNext:!1,xtraceOutput:"",error:_("",`bash: ${s}: circular name reference
649
+ `,1)};if(u===null)return{continueToNext:!0,xtraceOutput:""};o=u;let d=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(l={arrayName:d[1],subscriptExpr:d[2]},o=d[1])}if(Pe(e,o)){if(t.name)return a+=`bash: ${o}: readonly variable
650
+ `,{continueToNext:!0,xtraceOutput:a};let u=K(e,o);if(u)return{continueToNext:!1,xtraceOutput:"",error:u}}let f;if(Be(e,o))try{let u=new M;if(r){let h=`(${e.state.env[o]||"0"}) + (${n})`,m=q(u,h);f=String(await V(e,m.expression))}else{let d=q(u,n);f=String(await V(e,d.expression))}}catch{f="0"}else{let{isArray:u}=await import("./chunks/expansion-BOR3ELLC.js"),d=u(e,o)?`${o}_0`:o;f=r?(e.state.env[d]||"")+n:n}f=Le(e,o,f),a+=await yr(e,o,f);let c=o;if(l)c=await Ji(e,l);else{let{isArray:u}=await import("./chunks/expansion-BOR3ELLC.js");u(e,o)&&(c=`${o}_0`)}return t.name?(i[c]=e.state.env[c],e.state.env[c]=f):(e.state.env[c]=f,e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(o)),e.state.tempEnvBindings?.some(u=>u.has(o))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(o))),{continueToNext:!1,xtraceOutput:a}}async function Ji(e,t){let{arrayName:s,subscriptExpr:n}=t;if(e.state.associativeArrays?.has(s))return vr(e,s,n);let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else{try{let a=new M,o=q(a,n);i=await V(e,o.expression,!1)}catch{let a=e.state.env[n];i=a?Number.parseInt(a,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let a=fe(e,s);a.length>0&&(i=Math.max(...a.map(l=>l[0]))+1+i)}return`${s}_${i}`}async function br(e,t,s,n){let r=await ye(e,t.redirections);if(r)return r;let i={...e.state.env},a=e.state.cwd,o={...e.state.options},l=e.state.localScopes,f=e.state.localVarStack,c=e.state.localVarDepth,u=e.state.fullyUnsetLocals;if(e.state.localScopes=l.map(v=>new Map(v)),f){e.state.localVarStack=new Map;for(let[v,C]of f.entries())e.state.localVarStack.set(v,C.map(k=>({...k})))}c&&(e.state.localVarDepth=new Map(c)),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 g=e.state.groupStdin;s&&(e.state.groupStdin=s);let b="",$="",N=0,y=()=>{e.state.env=i,e.state.cwd=a,e.state.options=o,e.state.localScopes=l,e.state.localVarStack=f,e.state.localVarDepth=c,e.state.fullyUnsetLocals=u,e.state.loopDepth=d,e.state.parentHasLoopContext=h,e.state.groupStdin=g,e.state.bashPid=p,e.state.lastArg=m};try{for(let v of t.body){let C=await n(v);b+=C.stdout,$+=C.stderr,N=C.exitCode}}catch(v){if(y(),v instanceof te)throw v;if(v instanceof ve){b+=v.stdout,$+=v.stderr;let k=_(b,$,0);return j(e,k,t.redirections)}if(v instanceof re||v instanceof ie){b+=v.stdout,$+=v.stderr;let k=_(b,$,0);return j(e,k,t.redirections)}if(v instanceof z){b+=v.stdout,$+=v.stderr;let k=_(b,$,v.exitCode);return j(e,k,t.redirections)}if(v instanceof se){b+=v.stdout,$+=v.stderr;let k=_(b,$,v.exitCode);return j(e,k,t.redirections)}if(v instanceof ae){let k=_(b+v.stdout,$+v.stderr,v.exitCode);return j(e,k,t.redirections)}let C=_(b,`${$}${le(v)}
651
+ `,1);return j(e,C,t.redirections)}y();let w=_(b,$,N);return j(e,w,t.redirections)}async function Er(e,t,s,n){let r="",i="",a=0,o=await bt(e,t.redirections);if(o)return o;let l=s;for(let u of t.redirections)if((u.operator==="<<"||u.operator==="<<-")&&u.target.type==="HereDoc"){let d=u.target,h=await I(e,d.content);d.stripTabs&&(h=h.split(`
652
+ `).map(p=>p.replace(/^\t+/,"")).join(`
653
+ `));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 I(e,u.target)}
654
+ `;else if(u.operator==="<"&&u.target.type==="Word")try{let d=await I(e,u.target),h=e.fs.resolvePath(e.state.cwd,d);l=await e.fs.readFile(h)}catch{let d=await I(e,u.target);return _("",`bash: ${d}: No such file or directory
655
+ `,1)}let f=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,a=d.exitCode}}catch(u){if(e.state.groupStdin=f,u instanceof te)throw u;if(Je(u)||u instanceof ae||u instanceof z)throw u.prependOutput(r,i),u;return _(r,`${i}${le(u)}
656
+ `,1)}e.state.groupStdin=f;let c=_(r,i,a);return j(e,c,t.redirections)}async function $r(e,t,s,n,r){let i;try{i=await e.fs.readFile(t)}catch{return S(`bash: ${t}: No such file or directory
657
+ `,127)}if(i.startsWith("#!")){let g=i.indexOf(`
658
+ `);g!==-1&&(i=i.slice(g+1))}let a={...e.state.env},o=e.state.cwd,l={...e.state.options},f=e.state.loopDepth,c=e.state.parentHasLoopContext,u=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,m=e.state.currentSource;e.state.parentHasLoopContext=f>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 g=0;g<s.length&&g<9;g++)e.state.env[String(g+1)]=s[g];for(let g=s.length+1;g<=9;g++)delete e.state.env[String(g)];let p=()=>{e.state.env=a,e.state.cwd=o,e.state.options=l,e.state.loopDepth=f,e.state.parentHasLoopContext=c,e.state.lastArg=u,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=m};try{let b=new M().parse(i),$=await r(b);return p(),$}catch(g){if(p(),g instanceof z||g instanceof te)throw g;if(g.name==="ParseException")return S(`bash: ${t}: ${g.message}
659
+ `);throw g}}var Ze=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 a=this.ctx.state.env[i];a!==void 0&&(r[i]=a)}return r}async executeScript(t){let s="",n="",r=0;for(let i of t.statements)try{let a=await this.executeStatement(i);s+=a.stdout,n+=a.stderr,r=a.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r)}catch(a){if(a instanceof z)throw a.prependOutput(s,n),a;if(a instanceof ce)return s+=a.stdout,n+=a.stderr,r=a.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(a instanceof te)throw a;if(a instanceof ae)return s+=a.stdout,n+=a.stderr,r=a.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(a instanceof Ls)return s+=a.stdout,n+=a.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(a instanceof Ye)return s+=a.stdout,n+=a.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(a instanceof Ce){s+=a.stdout,n+=a.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r);continue}if(a instanceof Ws){s+=a.stdout,n+=a.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r);continue}if(a instanceof re||a instanceof ie){if(this.ctx.state.loopDepth>0)throw a.prependOutput(s,n),a;s+=a.stdout,n+=a.stderr;continue}throw a instanceof se&&a.prependOutput(s,n),a}return{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}}}async executeUserScript(t,s,n=""){return $r(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&&we(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new et(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}
660
+ `);let r=0,i=-1,a=!1;for(let f=0;f<t.pipelines.length;f++){let c=t.pipelines[f],u=f>0?t.operators[f-1]:null;if(u==="&&"&&r!==0||u==="||"&&r===0)continue;let d=await this.executePipeline(c);s+=d.stdout,n+=d.stderr,r=d.exitCode,i=f,a=c.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r)}let o=i<t.pipelines.length-1,l=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=o||a||l,this.ctx.state.options.errexit&&r!==0&&i===t.pipelines.length-1&&!a&&!this.ctx.state.inCondition&&!l)throw new ae(r,s,n);return _(s,n,r)}async executePipeline(t){return gr(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 ar(this.ctx,t);case"For":return or(this.ctx,t);case"CStyleFor":return lr(this.ctx,t);case"While":return cr(this.ctx,t,s);case"Until":return fr(this.ctx,t);case"Case":return ur(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return Nn(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 Qe)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,w=100;for(;w>0;){let v=this.expandAlias(y);if(v===y)break;y=v,w--}this.aliasExpansionStack.clear(),y!==t&&(t=y)}this.ctx.state.expansionStderr="";let n=await wr(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 w=await ye(this.ctx,t.redirections);if(w)return w;let v=_("",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="",_("",y,this.ctx.state.lastExitCode)}let a=t.name&&Is(t.name,["local","declare","typeset","export","readonly"]),o=Object.keys(r);if(o.length>0&&!a){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let y of o)this.ctx.state.tempExportedVars.add(y)}let l=await bt(this.ctx,t.redirections);if(l){for(let[y,w]of Object.entries(r))w===void 0?delete this.ctx.state.env[y]:this.ctx.state.env[y]=w;return l}let f=-1;for(let y of t.redirections){if((y.operator==="<<"||y.operator==="<<-")&&y.target.type==="HereDoc"){let w=y.target,v=await I(this.ctx,w.content);w.stripTabs&&(v=v.split(`
661
+ `).map(k=>k.replace(/^\t+/,"")).join(`
662
+ `));let C=y.fd??0;C!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),this.ctx.state.fileDescriptors.set(C,v)):s=v;continue}if(y.operator==="<<<"&&y.target.type==="Word"){s=`${await I(this.ctx,y.target)}
663
+ `;continue}if(y.operator==="<"&&y.target.type==="Word")try{let w=await I(this.ctx,y.target),v=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);s=await this.ctx.fs.readFile(v)}catch{let w=await I(this.ctx,y.target);for(let[v,C]of Object.entries(r))C===void 0?delete this.ctx.state.env[v]:this.ctx.state.env[v]=C;return S(`bash: ${w}: No such file or directory
664
+ `)}if(y.operator==="<&"&&y.target.type==="Word"){let w=await I(this.ctx,y.target),v=Number.parseInt(w,10);if(!Number.isNaN(v)&&this.ctx.state.fileDescriptors){let C=this.ctx.state.fileDescriptors.get(v);if(C!==void 0)if(C.startsWith("__rw__:")){let k=dr(C);k&&(s=k.content.slice(k.position),f=v)}else C.startsWith("__file__:")||C.startsWith("__file_append__:")||(s=C)}}}let c=await I(this.ctx,t.name),u=[],d=[];if(Is(t.name,["local","declare","typeset","export","readonly"])&&(c==="local"||c==="declare"||c==="typeset"||c==="export"||c==="readonly"))for(let y of t.args){let w=await un(this.ctx,y);if(w)u.push(w),d.push(!0);else{let v=await dn(this.ctx,y);if(v!==null)u.push(v),d.push(!0);else{let C=await pe(this.ctx,y);for(let k of C.values)u.push(k),d.push(C.quoted)}}}else for(let y of t.args){let w=await pe(this.ctx,y);for(let v of w.values)u.push(v),d.push(w.quoted)}if(!c){if(t.name.parts.every(w=>w.type==="CommandSubstitution"||w.type==="ParameterExpansion"||w.type==="ArithmeticExpansion")){if(u.length>0){let w=u.shift();return d.shift(),await this.runCommand(w,u,d,s,!1,!1,f)}return _("","",this.ctx.state.lastExitCode)}return S(`bash: : command not found
665
+ `,127)}if(c==="exec"&&(u.length===0||u[0]==="--")){for(let y of t.redirections){if(y.target.type==="HereDoc"||y.fdVariable)continue;let w=await I(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 C=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);await this.ctx.fs.writeFile(C,"","utf8"),this.ctx.state.fileDescriptors.set(v,`__file__:${C}`);break}case">>":{let C=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);this.ctx.state.fileDescriptors.set(v,`__file_append__:${C}`);break}case"<":{let C=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);try{let k=await this.ctx.fs.readFile(C);this.ctx.state.fileDescriptors.set(v,k)}catch{return S(`bash: ${w}: No such file or directory
666
+ `)}break}case"<>":{let C=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);try{let k=await this.ctx.fs.readFile(C);this.ctx.state.fileDescriptors.set(v,`__rw__:${C.length}:${C}:0:${k}`)}catch{await this.ctx.fs.writeFile(C,"","utf8"),this.ctx.state.fileDescriptors.set(v,`__rw__:${C.length}:${C}:0:`)}break}case">&":{if(w==="-")this.ctx.state.fileDescriptors.delete(v);else if(w.endsWith("-")){let C=w.slice(0,-1),k=Number.parseInt(C,10);if(!Number.isNaN(k)){let T=this.ctx.state.fileDescriptors.get(k);T!==void 0?this.ctx.state.fileDescriptors.set(v,T):this.ctx.state.fileDescriptors.set(v,`__dupout__:${k}`),this.ctx.state.fileDescriptors.delete(k)}}else{let C=Number.parseInt(w,10);Number.isNaN(C)||this.ctx.state.fileDescriptors.set(v,`__dupout__:${C}`)}break}case"<&":{if(w==="-")this.ctx.state.fileDescriptors.delete(v);else if(w.endsWith("-")){let C=w.slice(0,-1),k=Number.parseInt(C,10);if(!Number.isNaN(k)){let T=this.ctx.state.fileDescriptors.get(k);T!==void 0?this.ctx.state.fileDescriptors.set(v,T):this.ctx.state.fileDescriptors.set(v,`__dupin__:${k}`),this.ctx.state.fileDescriptors.delete(k)}}else{let C=Number.parseInt(w,10);Number.isNaN(C)||this.ctx.state.fileDescriptors.set(v,`__dupin__:${C}`)}break}}}for(let[y,w]of Object.entries(r))w===void 0?delete this.ctx.state.env[y]:this.ctx.state.env[y]=w;if(this.ctx.state.tempExportedVars)for(let y of Object.keys(r))this.ctx.state.tempExportedVars.delete(y);return L}let m=await mr(this.ctx,c,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,g=null;try{p=await this.runCommand(c,u,d,s,!1,!1,f)}catch(y){if(y instanceof re||y instanceof ie)g=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),g)throw g;if(u.length>0){let y=u[u.length-1];if((c==="declare"||c==="local"||c==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(y)){let w=y.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);w&&(y=w[1])}this.ctx.state.lastArg=y}else this.ctx.state.lastArg=c;let $=Cn(c)&&c!=="unset"&&c!=="eval";if(!this.ctx.state.options.posix||!$)for(let[y,w]of Object.entries(r))this.ctx.state.fullyUnsetLocals?.has(y)||(w===void 0?delete this.ctx.state.env[y]:this.ctx.state.env[y]=w);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,a=!1,o=-1){let l={ctx:this.ctx,runCommand:(c,u,d,h,m,p,g)=>this.runCommand(c,u,d,h,m,p,g),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(c,u,d)=>this.executeUserScript(c,u,d)},f=await rr(l,t,s,n,r,i,a,o);return f!==null?f:ir(l,t,s,r,a)}aliasExpansionStack=new Set;expandAlias(t){return Vt(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return Pt(this.ctx,t)}async executeSubshell(t,s=""){return br(this.ctx,t,s,n=>this.executeStatement(n))}async executeGroup(t,s=""){return Er(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=U(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}
667
+ `);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 Se(this.ctx,t.expression),r=U(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 Ce?1:2,i=S(`bash: conditional expression: ${n.message}
668
+ `,r);return j(this.ctx,i,t.redirections)}}};var _e={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3};function Sr(e){return e?{maxCallDepth:e.maxCallDepth??_e.maxCallDepth,maxCommandCount:e.maxCommandCount??_e.maxCommandCount,maxLoopIterations:e.maxLoopIterations??_e.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??_e.maxAwkIterations,maxSedIterations:e.maxSedIterations??_e.maxSedIterations,maxJqIterations:e.maxJqIterations??_e.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??_e.maxSqliteTimeoutMs}:{..._e}}function Ar(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function ea(e){let t=Ar(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function ta(e,t){let s=Ar(e);if(!s)return!1;let n=ea(t);return!n||s.origin!==n.origin?!1:n.pathPrefix==="/"||n.pathPrefix===""?!0:s.pathname.startsWith(n.pathPrefix)}function Ts(e,t){return!t||t.length===0?!1:t.some(s=>ta(e,s))}var Ge=class extends Error{constructor(t){super(`Network access denied: URL not in allow-list: ${t}`),this.name="NetworkAccessDeniedError"}},Ke=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},Xe=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},kt=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}};var sa=20,na=3e4,ra=["GET","HEAD"],ia=new Set(["GET","HEAD","OPTIONS"]),aa=new Set([301,302,303,307,308]);function xs(e){let t=e.maxRedirects??sa,s=e.timeoutMs??na,n=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??ra;function r(o){if(!e.dangerouslyAllowFullInternetAccess&&!Ts(o,e.allowedUrlPrefixes??[]))throw new Ge(o)}function i(o){if(e.dangerouslyAllowFullInternetAccess)return;let l=o.toUpperCase();if(!n.includes(l))throw new kt(l,n)}async function a(o,l={}){let f=l.method?.toUpperCase()??"GET";r(o),i(f);let c=o,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 g={method:f,headers:l.headers,signal:m.signal,redirect:"manual"};l.body&&!ia.has(f)&&(g.body=l.body);let b=await fetch(c,g);if(aa.has(b.status)&&d){let $=b.headers.get("location");if(!$)return await _r(b,c);let N=new URL($,c).href;if(!e.dangerouslyAllowFullInternetAccess&&!Ts(N,e.allowedUrlPrefixes??[]))throw new Xe(N);if(u++,u>t)throw new Ke(t);c=N;continue}return await _r(b,c)}finally{clearTimeout(p)}}}return a}async function _r(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 Ot=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;state;constructor(t={}){let s=t.fs??new Me(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:`
669
+ `,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=Sr({...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=xs(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=Ft(this.state.options),this.state.env.BASHOPTS=Mt(this.state.shoptOptions),rn(s,this.useDefaultLayout),n!=="/"&&s instanceof Me)try{s.mkdirSync(n,{recursive:!0})}catch{}for(let i of en(t.commands))this.registerCommand(i);if(t.network)for(let i of tn())this.registerCommand(i);if(t.customCommands)for(let i of t.customCommands)sn(i)?this.registerCommand(nn(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
670
+ # Built-in command: ${t.name}
671
+ `;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.
672
+ `,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 a={...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},o=t;s?.rawScript||(o=oa(t));try{let l=de(o),f={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 Ze(f,a).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 Ce)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}
673
+ `,exitCode:2,env:{...this.state.env,...s?.env}});if(l instanceof zs)return this.logResult({stdout:"",stderr:`bash: ${l.message}
674
+ `,exitCode:2,env:{...this.state.env,...s?.env}});if(l instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${l.message}
675
+ `,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 oa(e){let t=e.split(`
676
+ `),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 a=i.trimStart();s.push(a);let o=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let l of a.matchAll(o)){let f=l[1]==="-",c=l[3];n.push({delimiter:c,stripTabs:f})}}return s.join(`
677
+ `)}import*as Z from"node:fs";import*as We from"node:path";var la="/home/user/project",Dt=class{root;mountPoint;readOnly;memory=new Map;deleted=new Set;constructor(t){this.root=We.resolve(t.root);let s=t.mountPoint??la;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,!Z.existsSync(this.root))throw new Error(`OverlayFs root does not exist: ${this.root}`);if(!Z.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 a of r)i+=`/${a}`,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=We.join(this.root,n),i=We.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 Z.promises.access(n),!0}catch{return!1}}async readFile(t,s){let n=await this.readFileBuffer(t),r=$e(s);return rt(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 a=this.resolveSymlink(n,r.target);return this.readFileBuffer(a,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 a=await Z.promises.lstat(i);if(a.isSymbolicLink()){let l=await Z.promises.readlink(i),f=this.resolveSymlink(n,l);return this.readFileBuffer(f,s)}if(a.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);let o=await Z.promises.readFile(i);return new Uint8Array(o)}catch(a){throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${t}'`):a}}async writeFile(t,s,n){this.assertWritable(`write '${t}'`);let r=this.normalizePath(t);this.ensureParentDirs(r);let i=$e(n),a=De(s,i);this.memory.set(r,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(r)}async appendFile(t,s,n){this.assertWritable(`append '${t}'`);let r=this.normalizePath(t),i=$e(n),a=De(s,i),o;try{o=await this.readFileBuffer(r)}catch{o=new Uint8Array(0)}let l=new Uint8Array(o.length+a.length);l.set(o),l.set(a,o.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 o=this.resolveSymlink(n,r.target);return this.stat(o,s)}let a=0;return r.type==="file"&&(a=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:a,mtime:r.mtime}}let i=this.toRealPath(n);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let a=await Z.promises.stat(i);return{isFile:a.isFile(),isDirectory:a.isDirectory(),isSymbolicLink:!1,mode:a.mode,size:a.size,mtime:a.mtime}}catch(a){throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${t}'`):a}}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 Z.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 o of this.deleted)if(o.startsWith(i)){let l=o.slice(i.length),f=l.split("/")[0];f&&!l.includes("/",f.length)&&r.add(f)}for(let[o,l]of this.memory)if(o!==s&&o.startsWith(i)){let f=o.slice(i.length),c=f.split("/")[0];c&&!r.has(c)&&!f.includes("/",1)&&n.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let a=this.toRealPath(s);if(a)try{let o=await Z.promises.readdir(a,{withFileTypes:!0});for(let l of o)!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(o){if(o.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else if(o.code!=="ENOTDIR")throw o}return n}async resolveForReaddir(t,s=!1){let n=this.normalizePath(t),r=new Set,i=s,a=this.memory.get(n);for(;a&&a.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,a.target),a=this.memory.get(n)}if(a)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 Z.promises.lstat(l)).isSymbolicLink()){let c=await Z.promises.readlink(l),u=this.resolveSymlink(n,c);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,a)=>i<a?-1:i>a?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,a)=>i.name<a.name?-1:i.name>a.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 a=await this.readdir(n);if(a.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of a){let l=n==="/"?`/${o}`:`${n}/${o}`;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 o=await this.stat(r);if(o.isFile){let l=await this.readFileBuffer(r);await this.writeFile(i,l)}else if(o.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 f of l){let c=r==="/"?`/${f}`:`${r}/${f}`,u=i==="/"?`/${f}`:`${i}/${f}`;await this.cp(c,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=Z.readdirSync(n);for(let i of r){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;s.add(a);let o=We.join(n,i);Z.statSync(o).isDirectory()&&this.scanRealFs(a,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 a=await this.stat(n);if(a.isFile){let o=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:o,mode:s,mtime:new Date})}else a.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 a=await this.stat(n);if(!a.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:a.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 Z.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 o=>{let l=o==="/"?[]:o.slice(1).split("/"),f="";for(let c of l){if(f=`${f}/${c}`,n.has(f))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(f))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let u=this.memory.get(f),d=0,h=40;for(;u&&u.type==="symlink"&&d<h;){if(n.add(f),f=this.resolveSymlink(f,u.target),d++,n.has(f))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(f))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);u=this.memory.get(f)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!u){let m=this.toRealPath(f);if(m)try{if((await Z.promises.lstat(m)).isSymbolicLink()){let g=await Z.promises.readlink(m);return n.add(f),f=this.resolveSymlink(f,g),r(f)}}catch(p){throw p.code==="ENOENT"?new Error(`ENOENT: no such file or directory, realpath '${t}'`):p}}}return f||"/"},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 a=this.memory.get(r);if(a){a.mtime=n;return}let o=await this.stat(r);if(o.isFile){let l=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:l,mode:o.mode,mtime:n})}else o.isDirectory&&this.memory.set(r,{type:"directory",mode:o.mode,mtime:n})}};var Y={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"},Rs=class{env;rl;running=!0;history=[];isInteractive;constructor(t={}){let s=process.cwd(),n=new Dt({root:s,mountPoint:"/"});this.env=new Ot({fs:n,cwd:t.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...t.env},network:t.network!==!1?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.isInteractive=process.stdin.isTTY===!0,this.rl=Pr.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C
154
678
  `),this.prompt()}),process.stdin.isTTY&&this.rl.on("close",()=>{this.running=!1,console.log(`
155
- Goodbye!`),process.exit(0)})}syncHistory(){let e=this.env.getEnv();e.BASH_HISTORY=JSON.stringify(this.history)}getPrompt(){let e=this.env.getCwd(),n=this.env.getEnv().HOME||"/home/user",r=e;return e===n?r="~":e.startsWith(`${n}/`)&&(r=`~${e.slice(n.length)}`),`${W.green}${W.bold}user@virtual${W.reset}:${W.blue}${W.bold}${r}${W.reset}$ `}async executeCommand(e){let n=e.trim();if(n){if(this.history.push(n),n==="exit"||n.startsWith("exit ")){let r=n.split(/\s+/),s=r[1]?parseInt(r[1],10):0;console.log("exit"),process.exit(s)}this.syncHistory();try{let r=await this.env.exec(n);r.stdout&&process.stdout.write(r.stdout),r.stderr&&process.stderr.write(`${W.red}${r.stderr}${W.reset}`)}catch(r){console.error(`${W.red}Error: ${Y(r)}${W.reset}`)}}}printWelcome(){console.log(`
156
- ${W.cyan}${W.bold}\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
679
+ Goodbye!`),process.exit(0)})}syncHistory(){let t=this.env.getEnv();t.BASH_HISTORY=JSON.stringify(this.history)}getPrompt(){let t=this.env.getCwd(),s=this.env.getEnv().HOME||"/home/user",n=t;return t===s?n="~":t.startsWith(`${s}/`)&&(n=`~${t.slice(s.length)}`),`${Y.green}${Y.bold}user@virtual${Y.reset}:${Y.blue}${Y.bold}${n}${Y.reset}$ `}async executeCommand(t){let s=t.trim();if(s){if(this.history.push(s),s==="exit"||s.startsWith("exit ")){let n=s.split(/\s+/),r=n[1]?parseInt(n[1],10):0;console.log("exit"),process.exit(r)}this.syncHistory();try{let n=await this.env.exec(s);n.stdout&&process.stdout.write(n.stdout),n.stderr&&process.stderr.write(`${Y.red}${n.stderr}${Y.reset}`)}catch(n){console.error(`${Y.red}Error: ${le(n)}${Y.reset}`)}}}printWelcome(){console.log(`
680
+ ${Y.cyan}${Y.bold}\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
157
681
  \u2551 Virtual Shell v1.0 \u2551
158
682
  \u2551 A simulated bash environment in TypeScript \u2551
159
- \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D${W.reset}
683
+ \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D${Y.reset}
160
684
 
161
- ${W.dim}Exploring: ${process.cwd()}${W.reset}
685
+ ${Y.dim}Exploring: ${process.cwd()}${Y.reset}
162
686
 
163
- Type ${W.green}help${W.reset} for available commands, ${W.green}exit${W.reset} to quit.
687
+ Type ${Y.green}help${Y.reset} for available commands, ${Y.green}exit${Y.reset} to quit.
164
688
  Reads from real filesystem, writes stay in memory (OverlayFs).
165
- `)}prompt(){this.rl.question(this.getPrompt(),async e=>{this.running&&(await this.executeCommand(e),this.prompt())})}async run(){if(this.isInteractive)this.printWelcome(),this.prompt();else{let e=[];this.rl.on("line",n=>{e.push(n)}),await new Promise(n=>{this.rl.on("close",n)});for(let n of e)await this.executeCommand(n)}}};function oi(){let t=process.argv.slice(2),e={network:!0};for(let n=0;n<t.length;n++)if(t[n]==="--cwd"&&t[n+1])e.cwd=t[++n];else if(t[n]==="--files"&&t[n+1]){let r=t[++n];try{let s=zn.readFileSync(r,"utf-8");e.files=JSON.parse(s)}catch(s){console.error(`Error reading files from ${r}:`,s),process.exit(1)}}else t[n]==="--no-network"?e.network=!1:(t[n]==="--help"||t[n]==="-h")&&(console.log(`
689
+ `)}prompt(){this.rl.question(this.getPrompt(),async t=>{this.running&&(await this.executeCommand(t),this.prompt())})}async run(){if(this.isInteractive)this.printWelcome(),this.prompt();else{let t=[];this.rl.on("line",s=>{t.push(s)}),await new Promise(s=>{this.rl.on("close",s)});for(let s of t)await this.executeCommand(s)}}};function ca(){let e=process.argv.slice(2),t={network:!0};for(let s=0;s<e.length;s++)if(e[s]==="--cwd"&&e[s+1])t.cwd=e[++s];else if(e[s]==="--files"&&e[s+1]){let n=e[++s];try{let r=Cr.readFileSync(n,"utf-8");t.files=JSON.parse(r)}catch(r){console.error(`Error reading files from ${n}:`,r),process.exit(1)}}else e[s]==="--no-network"?t.network=!1:(e[s]==="--help"||e[s]==="-h")&&(console.log(`
166
690
  Usage: pnpm shell [options]
167
691
 
168
692
  Interactive shell using OverlayFs - reads from the current directory,
@@ -176,4 +700,4 @@ Options:
176
700
  Example:
177
701
  pnpm shell
178
702
  pnpm shell --no-network
179
- `),process.exit(0));return e}var ai=oi(),ci=new mr(ai);ci.run();
703
+ `),process.exit(0));return t}var fa=ca(),ua=new Rs(fa);ua.run();