just-bash 3.6.0 → 3.6.1
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.
- package/CHANGELOG.md +53 -0
- package/README.md +6 -0
- package/dist/bin/chunks/awk2-EPZ2CEQT.js +3 -0
- package/dist/bin/chunks/base64-D7ZXJQN6.js +3 -0
- package/dist/bin/chunks/bash-4Q4RMIZL.js +3 -0
- package/dist/bin/chunks/cat-AST5Y57Y.js +3 -0
- package/dist/bin/chunks/chmod-BFP7P5CD.js +3 -0
- package/dist/bin/chunks/chunk-26O2G5LX.js +34 -0
- package/dist/bin/chunks/chunk-2RDKEB6Z.js +15 -0
- package/dist/bin/chunks/chunk-35U2THFB.js +3 -0
- package/dist/bin/chunks/chunk-3F7UWBEM.js +17 -0
- package/dist/bin/chunks/chunk-3WLAERUX.js +3 -0
- package/dist/bin/chunks/chunk-3WZIZUMC.js +8 -0
- package/dist/bin/chunks/chunk-4ARWO6Y3.js +4 -0
- package/dist/bin/chunks/chunk-4HVMRZ5N.js +8 -0
- package/dist/bin/chunks/chunk-5AS7PRVN.js +34 -0
- package/dist/bin/chunks/chunk-5GYAEVIB.js +10 -0
- package/dist/bin/chunks/chunk-5IPYW47P.js +27 -0
- package/dist/bin/chunks/chunk-5ZTIV6TI.js +20 -0
- package/dist/bin/chunks/chunk-6C2YS7G6.js +14 -0
- package/dist/bin/chunks/chunk-74MYVPDY.js +3 -0
- package/dist/bin/chunks/chunk-74UP5NWP.js +3 -0
- package/dist/bin/chunks/chunk-7DPD5PK3.js +3 -0
- package/dist/bin/chunks/chunk-7LJGZPVP.js +18 -0
- package/dist/bin/chunks/chunk-7NEXHFSS.js +3 -0
- package/dist/bin/chunks/chunk-7XFMCB5C.js +21 -0
- package/dist/bin/chunks/chunk-A53Y4KDG.js +7 -0
- package/dist/bin/chunks/chunk-AALAYQ6J.js +17 -0
- package/dist/bin/chunks/chunk-AM4WIHAG.js +10 -0
- package/dist/bin/chunks/chunk-BC5OXEFJ.js +3 -0
- package/dist/bin/chunks/chunk-C5ABXV4P.js +15 -0
- package/dist/bin/chunks/chunk-CT6P7ILU.js +3 -0
- package/dist/bin/chunks/chunk-CYHG3NVG.js +9 -0
- package/dist/bin/chunks/chunk-D7PDAJWE.js +7 -0
- package/dist/bin/chunks/chunk-DB3G3UVZ.js +5 -0
- package/dist/bin/chunks/chunk-EIUU35ZP.js +37 -0
- package/dist/bin/chunks/chunk-EMHJNKV5.js +20 -0
- package/dist/bin/chunks/chunk-EPWMLTS6.js +9 -0
- package/dist/bin/chunks/chunk-F4QFFLWZ.js +8 -0
- package/dist/bin/chunks/chunk-F5R5O2Y6.js +9 -0
- package/dist/bin/chunks/chunk-FBEYY2HM.js +13 -0
- package/dist/bin/chunks/chunk-FIJBWMXU.js +12 -0
- package/dist/bin/chunks/chunk-FMVH4N2P.js +5 -0
- package/dist/bin/chunks/chunk-G6W2HMNY.js +7 -0
- package/dist/bin/chunks/chunk-GFI5BHZX.js +3 -0
- package/dist/bin/chunks/chunk-GJAVHEWO.js +143 -0
- package/dist/bin/chunks/chunk-GUVSOVQU.js +8 -0
- package/dist/bin/chunks/chunk-H22PAKR6.js +3 -0
- package/dist/bin/chunks/chunk-HXOJHK2Z.js +8 -0
- package/dist/bin/chunks/chunk-IAAYIH44.js +3 -0
- package/dist/bin/chunks/chunk-J7W2CRXT.js +7 -0
- package/dist/bin/chunks/chunk-JNWWOKCN.js +6 -0
- package/dist/bin/chunks/chunk-JQLGE4OW.js +22 -0
- package/dist/bin/chunks/chunk-K3U4M4MF.js +7 -0
- package/dist/bin/chunks/chunk-KRXYOWIP.js +12 -0
- package/dist/bin/chunks/chunk-L4L2QFS4.js +10 -0
- package/dist/bin/chunks/chunk-LU6ZEQNN.js +13 -0
- package/dist/bin/chunks/chunk-MLMKRR7L.js +12 -0
- package/dist/bin/chunks/chunk-MVN5WALS.js +7 -0
- package/dist/bin/chunks/chunk-MYOGTYIH.js +22 -0
- package/dist/bin/chunks/chunk-NF5LHCVV.js +275 -0
- package/dist/bin/chunks/chunk-OUGDZVL6.js +10 -0
- package/dist/bin/chunks/chunk-QCNQD6ME.js +11 -0
- package/dist/bin/chunks/chunk-QIDBJNMB.js +3 -0
- package/dist/bin/chunks/chunk-QKTQYL37.js +9 -0
- package/dist/bin/chunks/chunk-R6CMNMNX.js +22 -0
- package/dist/bin/chunks/chunk-RCP3WQND.js +7 -0
- package/dist/bin/chunks/chunk-RJG4JS32.js +6 -0
- package/dist/bin/chunks/chunk-SIMSIBUA.js +13 -0
- package/dist/bin/chunks/chunk-TNB7M24H.js +87 -0
- package/dist/bin/chunks/chunk-TU6P6AC2.js +4 -0
- package/dist/bin/chunks/chunk-TX4WSLXK.js +101 -0
- package/dist/bin/chunks/chunk-U4UY6P77.js +3 -0
- package/dist/bin/chunks/chunk-U5BNATW4.js +3 -0
- package/dist/bin/chunks/chunk-U7VJCJQR.js +16 -0
- package/dist/bin/chunks/chunk-VJE2PQW6.js +15 -0
- package/dist/bin/chunks/chunk-W4ENG3BR.js +44 -0
- package/dist/bin/chunks/chunk-XUFO4QPW.js +65 -0
- package/dist/bin/chunks/chunk-XVKL2UZA.js +4 -0
- package/dist/bin/chunks/chunk-YCUNLSHF.js +12 -0
- package/dist/bin/chunks/chunk-YDH7Q5WV.js +6 -0
- package/dist/bin/chunks/chunk-YDWLU56G.js +26 -0
- package/dist/bin/chunks/chunk-YILPYZYP.js +16 -0
- package/dist/bin/chunks/chunk-YZQ4SVJV.js +13 -0
- package/dist/bin/chunks/chunk-ZKLKNN6B.js +3 -0
- package/dist/bin/chunks/column-EGAQ7QMC.js +3 -0
- package/dist/bin/chunks/comm-JEJ6GWEA.js +3 -0
- package/dist/bin/chunks/cp-7AH7TSQ6.js +3 -0
- package/dist/bin/chunks/curl-7FCZQCFU.js +31 -0
- package/dist/bin/chunks/cut-OVTLUT2B.js +3 -0
- package/dist/bin/chunks/date-MKP5YWWY.js +3 -0
- package/dist/bin/chunks/diff-R6QTSWD2.js +3 -0
- package/dist/bin/chunks/du-M2PB5NUH.js +3 -0
- package/dist/bin/chunks/env-EUSAZGWO.js +3 -0
- package/dist/bin/chunks/expand-B4CPOZN5.js +3 -0
- package/dist/bin/chunks/expr-AQBMSEFL.js +3 -0
- package/dist/bin/chunks/file-22CVQBNS.js +3 -0
- package/dist/bin/chunks/find-QYLHUYOP.js +3 -0
- package/dist/bin/chunks/flag-coverage-CTPK5ZWJ.js +3 -0
- package/dist/bin/chunks/fold-E6A5I4DW.js +3 -0
- package/dist/bin/chunks/grep-HI55D7F7.js +3 -0
- package/dist/bin/chunks/gzip-2GJMVXCF.js +3 -0
- package/dist/bin/chunks/head-ZQIB2GSI.js +3 -0
- package/dist/bin/chunks/html-to-markdown-7ZNLM4SQ.js +3 -0
- package/dist/bin/chunks/join-KCYMLQ3V.js +3 -0
- package/dist/bin/chunks/jq-KNI4FJIL.js +3 -0
- package/dist/bin/chunks/js-exec-OWDAX677.js +1617 -0
- package/dist/bin/chunks/ls-QCAGDEDW.js +3 -0
- package/dist/bin/chunks/md5sum-OPJ77ZY7.js +3 -0
- package/dist/bin/chunks/mkdir-3XFSFVPC.js +3 -0
- package/dist/bin/chunks/mktemp-5FA55IJS.js +3 -0
- package/dist/bin/chunks/mv-UASF6NAX.js +3 -0
- package/dist/bin/chunks/nl-HUDE6DQC.js +3 -0
- package/dist/bin/chunks/od-CECQKF5P.js +3 -0
- package/dist/bin/chunks/paste-SH5RZ4ZO.js +3 -0
- package/dist/bin/chunks/printf-PQKUEWX5.js +3 -0
- package/dist/bin/chunks/python3-UE36ZXQT.js +23 -0
- package/dist/bin/chunks/readlink-4Z75K3AI.js +3 -0
- package/dist/bin/chunks/rev-6SA3VC3J.js +3 -0
- package/dist/bin/chunks/rg-ULWB5MQG.js +3 -0
- package/dist/bin/chunks/rm-NPIAQT6U.js +3 -0
- package/dist/bin/chunks/rmdir-57J3AGQU.js +3 -0
- package/dist/bin/chunks/sed-XV7BZPKI.js +3 -0
- package/dist/bin/chunks/seq-ZVBT2JEI.js +3 -0
- package/dist/bin/chunks/sha1sum-JGOB5K4J.js +3 -0
- package/dist/bin/chunks/sha256sum-S5DS6Q6N.js +3 -0
- package/dist/bin/chunks/sort-UOMFLGRW.js +3 -0
- package/dist/bin/chunks/split-IBL3NIVH.js +3 -0
- package/dist/bin/chunks/sqlite3-YIM3BYLS.js +3 -0
- package/dist/bin/chunks/stat-RKSIL4YV.js +3 -0
- package/dist/bin/chunks/strings-AL7T5GDQ.js +3 -0
- package/dist/bin/chunks/tac-36B6LBNS.js +3 -0
- package/dist/bin/chunks/tail-G4PLDIOK.js +3 -0
- package/dist/bin/chunks/tar-YG6SY2RU.js +3 -0
- package/dist/bin/chunks/tee-NP4ULCWD.js +3 -0
- package/dist/bin/chunks/time-ZMFJL7MD.js +3 -0
- package/dist/bin/chunks/timeout-EJIGKZUX.js +3 -0
- package/dist/bin/chunks/touch-YE5LMLLE.js +3 -0
- package/dist/bin/chunks/tr-7KFUMSUF.js +3 -0
- package/dist/bin/chunks/unexpand-67EBVEPB.js +3 -0
- package/dist/bin/chunks/uniq-SZDRNEYK.js +3 -0
- package/dist/bin/chunks/wc-VLOME6PL.js +3 -0
- package/dist/bin/chunks/xan-FVGJAHFV.js +3 -0
- package/dist/bin/chunks/xan-view-LYATQWQB.js +3 -0
- package/dist/bin/chunks/xargs-CLQL2WFV.js +3 -0
- package/dist/bin/chunks/yes-OOBLAITP.js +3 -0
- package/dist/bin/chunks/yq-YQ4YFM26.js +3 -0
- package/dist/bin/just-bash.js +347 -345
- package/dist/bin/shell/chunks/awk2-EPZ2CEQT.js +3 -0
- package/dist/bin/shell/chunks/base64-D7ZXJQN6.js +3 -0
- package/dist/bin/shell/chunks/bash-4Q4RMIZL.js +3 -0
- package/dist/bin/shell/chunks/cat-AST5Y57Y.js +3 -0
- package/dist/bin/shell/chunks/chmod-BFP7P5CD.js +3 -0
- package/dist/bin/shell/chunks/chunk-26O2G5LX.js +34 -0
- package/dist/bin/shell/chunks/chunk-2RDKEB6Z.js +15 -0
- package/dist/bin/shell/chunks/chunk-35U2THFB.js +3 -0
- package/dist/bin/shell/chunks/chunk-3F7UWBEM.js +17 -0
- package/dist/bin/shell/chunks/chunk-3WLAERUX.js +3 -0
- package/dist/bin/shell/chunks/chunk-3WZIZUMC.js +8 -0
- package/dist/bin/shell/chunks/chunk-4ARWO6Y3.js +4 -0
- package/dist/bin/shell/chunks/chunk-4HVMRZ5N.js +8 -0
- package/dist/bin/shell/chunks/chunk-5AS7PRVN.js +34 -0
- package/dist/bin/shell/chunks/chunk-5GYAEVIB.js +10 -0
- package/dist/bin/shell/chunks/chunk-5IPYW47P.js +27 -0
- package/dist/bin/shell/chunks/chunk-5ZTIV6TI.js +20 -0
- package/dist/bin/shell/chunks/chunk-6C2YS7G6.js +14 -0
- package/dist/bin/shell/chunks/chunk-74MYVPDY.js +3 -0
- package/dist/bin/shell/chunks/chunk-74UP5NWP.js +3 -0
- package/dist/bin/shell/chunks/chunk-7DPD5PK3.js +3 -0
- package/dist/bin/shell/chunks/chunk-7LJGZPVP.js +18 -0
- package/dist/bin/shell/chunks/chunk-7NEXHFSS.js +3 -0
- package/dist/bin/shell/chunks/chunk-7XFMCB5C.js +21 -0
- package/dist/bin/shell/chunks/chunk-A53Y4KDG.js +7 -0
- package/dist/bin/shell/chunks/chunk-AALAYQ6J.js +17 -0
- package/dist/bin/shell/chunks/chunk-AM4WIHAG.js +10 -0
- package/dist/bin/shell/chunks/chunk-BC5OXEFJ.js +3 -0
- package/dist/bin/shell/chunks/chunk-C5ABXV4P.js +15 -0
- package/dist/bin/shell/chunks/chunk-CT6P7ILU.js +3 -0
- package/dist/bin/shell/chunks/chunk-CYHG3NVG.js +9 -0
- package/dist/bin/shell/chunks/chunk-D7PDAJWE.js +7 -0
- package/dist/bin/shell/chunks/chunk-DB3G3UVZ.js +5 -0
- package/dist/bin/shell/chunks/chunk-EIUU35ZP.js +37 -0
- package/dist/bin/shell/chunks/chunk-EMHJNKV5.js +20 -0
- package/dist/bin/shell/chunks/chunk-EPWMLTS6.js +9 -0
- package/dist/bin/shell/chunks/chunk-F4QFFLWZ.js +8 -0
- package/dist/bin/shell/chunks/chunk-F5R5O2Y6.js +9 -0
- package/dist/bin/shell/chunks/chunk-FBEYY2HM.js +13 -0
- package/dist/bin/shell/chunks/chunk-FIJBWMXU.js +12 -0
- package/dist/bin/shell/chunks/chunk-FMVH4N2P.js +5 -0
- package/dist/bin/shell/chunks/chunk-G6W2HMNY.js +7 -0
- package/dist/bin/shell/chunks/chunk-GFI5BHZX.js +3 -0
- package/dist/bin/shell/chunks/chunk-GJAVHEWO.js +143 -0
- package/dist/bin/shell/chunks/chunk-GUVSOVQU.js +8 -0
- package/dist/bin/shell/chunks/chunk-H22PAKR6.js +3 -0
- package/dist/bin/shell/chunks/chunk-HXOJHK2Z.js +8 -0
- package/dist/bin/shell/chunks/chunk-IAAYIH44.js +3 -0
- package/dist/bin/shell/chunks/chunk-J7W2CRXT.js +7 -0
- package/dist/bin/shell/chunks/chunk-JNWWOKCN.js +6 -0
- package/dist/bin/shell/chunks/chunk-JQLGE4OW.js +22 -0
- package/dist/bin/shell/chunks/chunk-K3U4M4MF.js +7 -0
- package/dist/bin/shell/chunks/chunk-KRXYOWIP.js +12 -0
- package/dist/bin/shell/chunks/chunk-L4L2QFS4.js +10 -0
- package/dist/bin/shell/chunks/chunk-LU6ZEQNN.js +13 -0
- package/dist/bin/shell/chunks/chunk-MLMKRR7L.js +12 -0
- package/dist/bin/shell/chunks/chunk-MVN5WALS.js +7 -0
- package/dist/bin/shell/chunks/chunk-MYOGTYIH.js +22 -0
- package/dist/bin/shell/chunks/chunk-NF5LHCVV.js +275 -0
- package/dist/bin/shell/chunks/chunk-OUGDZVL6.js +10 -0
- package/dist/bin/shell/chunks/chunk-QCNQD6ME.js +11 -0
- package/dist/bin/shell/chunks/chunk-QIDBJNMB.js +3 -0
- package/dist/bin/shell/chunks/chunk-QKTQYL37.js +9 -0
- package/dist/bin/shell/chunks/chunk-R6CMNMNX.js +22 -0
- package/dist/bin/shell/chunks/chunk-RCP3WQND.js +7 -0
- package/dist/bin/shell/chunks/chunk-RJG4JS32.js +6 -0
- package/dist/bin/shell/chunks/chunk-SIMSIBUA.js +13 -0
- package/dist/bin/shell/chunks/chunk-TNB7M24H.js +87 -0
- package/dist/bin/shell/chunks/chunk-TU6P6AC2.js +4 -0
- package/dist/bin/shell/chunks/chunk-TX4WSLXK.js +101 -0
- package/dist/bin/shell/chunks/chunk-U4UY6P77.js +3 -0
- package/dist/bin/shell/chunks/chunk-U5BNATW4.js +3 -0
- package/dist/bin/shell/chunks/chunk-U7VJCJQR.js +16 -0
- package/dist/bin/shell/chunks/chunk-VJE2PQW6.js +15 -0
- package/dist/bin/shell/chunks/chunk-W4ENG3BR.js +44 -0
- package/dist/bin/shell/chunks/chunk-XUFO4QPW.js +65 -0
- package/dist/bin/shell/chunks/chunk-XVKL2UZA.js +4 -0
- package/dist/bin/shell/chunks/chunk-YCUNLSHF.js +12 -0
- package/dist/bin/shell/chunks/chunk-YDH7Q5WV.js +6 -0
- package/dist/bin/shell/chunks/chunk-YDWLU56G.js +26 -0
- package/dist/bin/shell/chunks/chunk-YILPYZYP.js +16 -0
- package/dist/bin/shell/chunks/chunk-YZQ4SVJV.js +13 -0
- package/dist/bin/shell/chunks/chunk-ZKLKNN6B.js +3 -0
- package/dist/bin/shell/chunks/column-EGAQ7QMC.js +3 -0
- package/dist/bin/shell/chunks/comm-JEJ6GWEA.js +3 -0
- package/dist/bin/shell/chunks/cp-7AH7TSQ6.js +3 -0
- package/dist/bin/shell/chunks/curl-7FCZQCFU.js +31 -0
- package/dist/bin/shell/chunks/cut-OVTLUT2B.js +3 -0
- package/dist/bin/shell/chunks/date-MKP5YWWY.js +3 -0
- package/dist/bin/shell/chunks/diff-R6QTSWD2.js +3 -0
- package/dist/bin/shell/chunks/du-M2PB5NUH.js +3 -0
- package/dist/bin/shell/chunks/env-EUSAZGWO.js +3 -0
- package/dist/bin/shell/chunks/expand-B4CPOZN5.js +3 -0
- package/dist/bin/shell/chunks/expr-AQBMSEFL.js +3 -0
- package/dist/bin/shell/chunks/file-22CVQBNS.js +3 -0
- package/dist/bin/shell/chunks/find-QYLHUYOP.js +3 -0
- package/dist/bin/shell/chunks/flag-coverage-CTPK5ZWJ.js +3 -0
- package/dist/bin/shell/chunks/fold-E6A5I4DW.js +3 -0
- package/dist/bin/shell/chunks/grep-HI55D7F7.js +3 -0
- package/dist/bin/shell/chunks/gzip-2GJMVXCF.js +3 -0
- package/dist/bin/shell/chunks/head-ZQIB2GSI.js +3 -0
- package/dist/bin/shell/chunks/html-to-markdown-7ZNLM4SQ.js +3 -0
- package/dist/bin/shell/chunks/join-KCYMLQ3V.js +3 -0
- package/dist/bin/shell/chunks/jq-KNI4FJIL.js +3 -0
- package/dist/bin/shell/chunks/js-exec-OWDAX677.js +1617 -0
- package/dist/bin/shell/chunks/ls-QCAGDEDW.js +3 -0
- package/dist/bin/shell/chunks/md5sum-OPJ77ZY7.js +3 -0
- package/dist/bin/shell/chunks/mkdir-3XFSFVPC.js +3 -0
- package/dist/bin/shell/chunks/mktemp-5FA55IJS.js +3 -0
- package/dist/bin/shell/chunks/mv-UASF6NAX.js +3 -0
- package/dist/bin/shell/chunks/nl-HUDE6DQC.js +3 -0
- package/dist/bin/shell/chunks/od-CECQKF5P.js +3 -0
- package/dist/bin/shell/chunks/paste-SH5RZ4ZO.js +3 -0
- package/dist/bin/shell/chunks/printf-PQKUEWX5.js +3 -0
- package/dist/bin/shell/chunks/python3-UE36ZXQT.js +23 -0
- package/dist/bin/shell/chunks/readlink-4Z75K3AI.js +3 -0
- package/dist/bin/shell/chunks/rev-6SA3VC3J.js +3 -0
- package/dist/bin/shell/chunks/rg-ULWB5MQG.js +3 -0
- package/dist/bin/shell/chunks/rm-NPIAQT6U.js +3 -0
- package/dist/bin/shell/chunks/rmdir-57J3AGQU.js +3 -0
- package/dist/bin/shell/chunks/sed-XV7BZPKI.js +3 -0
- package/dist/bin/shell/chunks/seq-ZVBT2JEI.js +3 -0
- package/dist/bin/shell/chunks/sha1sum-JGOB5K4J.js +3 -0
- package/dist/bin/shell/chunks/sha256sum-S5DS6Q6N.js +3 -0
- package/dist/bin/shell/chunks/sort-UOMFLGRW.js +3 -0
- package/dist/bin/shell/chunks/split-IBL3NIVH.js +3 -0
- package/dist/bin/shell/chunks/sqlite3-YIM3BYLS.js +3 -0
- package/dist/bin/shell/chunks/stat-RKSIL4YV.js +3 -0
- package/dist/bin/shell/chunks/strings-AL7T5GDQ.js +3 -0
- package/dist/bin/shell/chunks/tac-36B6LBNS.js +3 -0
- package/dist/bin/shell/chunks/tail-G4PLDIOK.js +3 -0
- package/dist/bin/shell/chunks/tar-YG6SY2RU.js +3 -0
- package/dist/bin/shell/chunks/tee-NP4ULCWD.js +3 -0
- package/dist/bin/shell/chunks/time-ZMFJL7MD.js +3 -0
- package/dist/bin/shell/chunks/timeout-EJIGKZUX.js +3 -0
- package/dist/bin/shell/chunks/touch-YE5LMLLE.js +3 -0
- package/dist/bin/shell/chunks/tr-7KFUMSUF.js +3 -0
- package/dist/bin/shell/chunks/unexpand-67EBVEPB.js +3 -0
- package/dist/bin/shell/chunks/uniq-SZDRNEYK.js +3 -0
- package/dist/bin/shell/chunks/wc-VLOME6PL.js +3 -0
- package/dist/bin/shell/chunks/xan-FVGJAHFV.js +3 -0
- package/dist/bin/shell/chunks/xan-view-LYATQWQB.js +3 -0
- package/dist/bin/shell/chunks/xargs-CLQL2WFV.js +3 -0
- package/dist/bin/shell/chunks/yes-OOBLAITP.js +3 -0
- package/dist/bin/shell/chunks/yq-YQ4YFM26.js +3 -0
- package/dist/bin/shell/shell.js +385 -383
- package/dist/bundle/browser.js +873 -863
- package/dist/bundle/chunks/awk2-LEEKKBPN.js +2 -0
- package/dist/bundle/chunks/base64-GBEVK7UP.js +2 -0
- package/dist/bundle/chunks/bash-QTX2IUM4.js +2 -0
- package/dist/bundle/chunks/cat-UBR2ABBH.js +2 -0
- package/dist/bundle/chunks/chmod-5VBARXGU.js +2 -0
- package/dist/bundle/chunks/chunk-2LOOLBWC.js +33 -0
- package/dist/bundle/chunks/chunk-34XJ6PLO.js +20 -0
- package/dist/bundle/chunks/chunk-3DUKINTI.js +7 -0
- package/dist/bundle/chunks/chunk-3VXY25LY.js +2 -0
- package/dist/bundle/chunks/chunk-5G2D2EZB.js +7 -0
- package/dist/bundle/chunks/chunk-5Q4R6KJE.js +4 -0
- package/dist/bundle/chunks/chunk-5ZVTEBKG.js +7 -0
- package/dist/bundle/chunks/chunk-77XFWF43.js +13 -0
- package/dist/bundle/chunks/chunk-B2EYYRZX.js +9 -0
- package/dist/bundle/chunks/chunk-BC3VKZCL.js +10 -0
- package/dist/bundle/chunks/chunk-BEIP3OYT.js +6 -0
- package/dist/bundle/chunks/chunk-BLTFJFWH.js +2 -0
- package/dist/bundle/chunks/chunk-C2GCPQ2D.js +15 -0
- package/dist/bundle/chunks/chunk-CGCA7SGA.js +25 -0
- package/dist/bundle/chunks/chunk-CIY4XCGA.js +2 -0
- package/dist/bundle/chunks/chunk-CXBOPNEG.js +11 -0
- package/dist/bundle/chunks/chunk-CYJQAYUX.js +142 -0
- package/dist/bundle/chunks/chunk-D55UUXDJ.js +100 -0
- package/dist/bundle/chunks/chunk-EOMWWW4L.js +33 -0
- package/dist/bundle/chunks/chunk-ER6ZGLPS.js +26 -0
- package/dist/bundle/chunks/chunk-EZHC6HLV.js +3 -0
- package/dist/bundle/chunks/chunk-FBRDM6EM.js +12 -0
- package/dist/bundle/chunks/chunk-FDAXSABU.js +11 -0
- package/dist/bundle/chunks/chunk-FEKEA5Y2.js +2 -0
- package/dist/bundle/chunks/chunk-GEANXVKK.js +15 -0
- package/dist/bundle/chunks/chunk-GIQ3LRFL.js +21 -0
- package/dist/bundle/chunks/chunk-HBIJBKHP.js +14 -0
- package/dist/bundle/chunks/chunk-IDYF47VD.js +11 -0
- package/dist/bundle/chunks/chunk-IH6MZAKK.js +6 -0
- package/dist/bundle/chunks/chunk-IIWAWB3H.js +274 -0
- package/dist/bundle/chunks/chunk-IQGNPH54.js +8 -0
- package/dist/bundle/chunks/chunk-IVYY6YFV.js +7 -0
- package/dist/bundle/chunks/chunk-IXOG2DXK.js +14 -0
- package/dist/bundle/chunks/chunk-J6QAN4PZ.js +6 -0
- package/dist/bundle/chunks/chunk-JMGGZYF2.js +2 -0
- package/dist/bundle/chunks/chunk-JU5GJH4X.js +9 -0
- package/dist/bundle/chunks/chunk-JWGTQTBU.js +16 -0
- package/dist/bundle/chunks/chunk-KQSMX4HM.js +11 -0
- package/dist/bundle/chunks/chunk-KZMK2KYL.js +43 -0
- package/dist/bundle/chunks/chunk-L4MC7WH4.js +14 -0
- package/dist/bundle/chunks/chunk-L5AKA7GO.js +5 -0
- package/dist/bundle/chunks/chunk-LBKOJW6K.js +2 -0
- package/dist/bundle/chunks/chunk-LNJ6EIKX.js +2 -0
- package/dist/bundle/chunks/chunk-LQXMSLW5.js +16 -0
- package/dist/bundle/chunks/chunk-MOOFDAFS.js +7 -0
- package/dist/bundle/chunks/chunk-N3VQQRLQ.js +8 -0
- package/dist/bundle/chunks/chunk-NJUHQKMR.js +3 -0
- package/dist/bundle/chunks/chunk-NOZTFL4F.js +12 -0
- package/dist/bundle/chunks/chunk-OEZKBUXP.js +8 -0
- package/dist/bundle/chunks/chunk-OZMQI3HV.js +17 -0
- package/dist/bundle/chunks/chunk-POI4XBDP.js +6 -0
- package/dist/bundle/chunks/chunk-PV2DCWLJ.js +6 -0
- package/dist/bundle/chunks/chunk-Q6ZH76O4.js +2 -0
- package/dist/bundle/chunks/chunk-QECDICRF.js +9 -0
- package/dist/bundle/chunks/chunk-QJTRVYQA.js +5 -0
- package/dist/bundle/chunks/chunk-QZPG6UCH.js +9 -0
- package/dist/bundle/chunks/chunk-R23EAHN5.js +2 -0
- package/dist/bundle/chunks/chunk-R3HY2GCO.js +3 -0
- package/dist/bundle/chunks/chunk-RQTEROQ5.js +6 -0
- package/dist/bundle/chunks/chunk-SAE7VUIM.js +21 -0
- package/dist/bundle/chunks/chunk-SBG7KYI4.js +12 -0
- package/dist/bundle/chunks/chunk-SRNYBHIU.js +21 -0
- package/dist/bundle/chunks/chunk-T7CFNHX6.js +2 -0
- package/dist/bundle/chunks/chunk-U3UTFNHI.js +2 -0
- package/dist/bundle/chunks/chunk-UQZ5HJXB.js +64 -0
- package/dist/bundle/chunks/chunk-US6XQQ6W.js +19 -0
- package/dist/bundle/chunks/chunk-UZ4TKNEJ.js +2 -0
- package/dist/bundle/chunks/chunk-VW6FDS6X.js +2 -0
- package/dist/bundle/chunks/chunk-W4A6TADR.js +36 -0
- package/dist/bundle/chunks/chunk-WAL3MOLR.js +6 -0
- package/dist/bundle/chunks/chunk-WFEUQRHM.js +2 -0
- package/dist/bundle/chunks/chunk-WNAEYQTE.js +8 -0
- package/dist/bundle/chunks/chunk-WOSSFIAE.js +12 -0
- package/dist/bundle/chunks/chunk-WTG3OCY4.js +5 -0
- package/dist/bundle/chunks/chunk-XIEMQVCO.js +19 -0
- package/dist/bundle/chunks/chunk-YFGP6M45.js +7 -0
- package/dist/bundle/chunks/chunk-ZARLSKBF.js +2 -0
- package/dist/bundle/chunks/chunk-ZVANIJV2.js +4 -0
- package/dist/bundle/chunks/column-46NX3HG3.js +2 -0
- package/dist/bundle/chunks/comm-QHEYSM4I.js +2 -0
- package/dist/bundle/chunks/cp-AQ4Y4WVV.js +2 -0
- package/dist/bundle/chunks/curl-LMCQFYWH.js +30 -0
- package/dist/bundle/chunks/cut-A6NXJGOH.js +2 -0
- package/dist/bundle/chunks/date-YMEJ62OQ.js +2 -0
- package/dist/bundle/chunks/diff-SECJC7CN.js +2 -0
- package/dist/bundle/chunks/du-JOLY42MC.js +2 -0
- package/dist/bundle/chunks/env-MI6QVNMM.js +2 -0
- package/dist/bundle/chunks/expand-YVEZTU7W.js +2 -0
- package/dist/bundle/chunks/expr-U7WETT5R.js +2 -0
- package/dist/bundle/chunks/file-6QDI3H7G.js +2 -0
- package/dist/bundle/chunks/find-UYQIFSZI.js +2 -0
- package/dist/bundle/chunks/flag-coverage-5YCE6ILG.js +2 -0
- package/dist/bundle/chunks/fold-A24KLKHY.js +2 -0
- package/dist/bundle/chunks/grep-ZELVZ7JB.js +2 -0
- package/dist/bundle/chunks/gzip-3IFADYVU.js +2 -0
- package/dist/bundle/chunks/head-5YWCKNNQ.js +2 -0
- package/dist/bundle/chunks/html-to-markdown-EOWI2I5J.js +2 -0
- package/dist/bundle/chunks/join-MSZXRLNV.js +2 -0
- package/dist/bundle/chunks/jq-MKA6BDYV.js +2 -0
- package/dist/bundle/chunks/js-exec-CNDWLKWB.js +1616 -0
- package/dist/bundle/chunks/ls-WMN4WCCI.js +2 -0
- package/dist/bundle/chunks/md5sum-OCX4NZ2Q.js +2 -0
- package/dist/bundle/chunks/mkdir-YJMG55FX.js +2 -0
- package/dist/bundle/chunks/mktemp-RA55VAN3.js +2 -0
- package/dist/bundle/chunks/mv-NTJL2AHI.js +2 -0
- package/dist/bundle/chunks/nl-Z5DVHZ3S.js +2 -0
- package/dist/bundle/chunks/od-TRWBMEIO.js +2 -0
- package/dist/bundle/chunks/paste-VPYCLIL6.js +2 -0
- package/dist/bundle/chunks/printf-BNADL4RX.js +2 -0
- package/dist/bundle/chunks/python3-TIKLWPZJ.js +22 -0
- package/dist/bundle/chunks/readlink-HGACDFRD.js +2 -0
- package/dist/bundle/chunks/rev-W57N4M5B.js +2 -0
- package/dist/bundle/chunks/rg-IN3KT335.js +2 -0
- package/dist/bundle/chunks/rm-CDVWO5CO.js +2 -0
- package/dist/bundle/chunks/rmdir-HI3UE4KQ.js +2 -0
- package/dist/bundle/chunks/sed-MXZDFQ7I.js +2 -0
- package/dist/bundle/chunks/seq-E3UP3G65.js +2 -0
- package/dist/bundle/chunks/sha1sum-QUWYL7G6.js +2 -0
- package/dist/bundle/chunks/sha256sum-FGHIABMA.js +2 -0
- package/dist/bundle/chunks/sort-ATCMEITA.js +2 -0
- package/dist/bundle/chunks/split-YZFCWIZI.js +2 -0
- package/dist/bundle/chunks/sqlite3-JL36RFBZ.js +2 -0
- package/dist/bundle/chunks/stat-APUQD6WQ.js +2 -0
- package/dist/bundle/chunks/strings-WA2ZGNUN.js +2 -0
- package/dist/bundle/chunks/tac-OCV6R4TG.js +2 -0
- package/dist/bundle/chunks/tail-IBKQAMFW.js +2 -0
- package/dist/bundle/chunks/tar-WJV4DGKA.js +2 -0
- package/dist/bundle/chunks/tee-VOXQ2UGV.js +2 -0
- package/dist/bundle/chunks/time-GOHAC6VO.js +2 -0
- package/dist/bundle/chunks/timeout-FVGYB3MD.js +2 -0
- package/dist/bundle/chunks/touch-57OKADDG.js +2 -0
- package/dist/bundle/chunks/tr-M4D6SICQ.js +2 -0
- package/dist/bundle/chunks/unexpand-SYZZ5ZBE.js +2 -0
- package/dist/bundle/chunks/uniq-TUUUYPVF.js +2 -0
- package/dist/bundle/chunks/wc-HQPGW3KR.js +2 -0
- package/dist/bundle/chunks/xan-CZJZCC57.js +2 -0
- package/dist/bundle/chunks/xan-view-HETEUD3G.js +2 -0
- package/dist/bundle/chunks/xargs-WFPZZ3FK.js +2 -0
- package/dist/bundle/chunks/yes-ACSNSE7T.js +2 -0
- package/dist/bundle/chunks/yq-XDJLIJPZ.js +2 -0
- package/dist/bundle/index.cjs +1042 -993
- package/dist/bundle/index.js +345 -343
- package/dist/commands/awk/interpreter/fields.d.ts +16 -0
- package/dist/commands/js-exec/module-shims.d.ts +1 -1
- package/dist/commands/rg/rg-options.d.ts +2 -0
- package/dist/commands/search-engine/matcher.d.ts +2 -0
- package/dist/interpreter/builtin-dispatch.d.ts +9 -3
- package/dist/interpreter/fd-table.d.ts +4 -1
- package/dist/interpreter/helpers/errors.d.ts +5 -0
- package/dist/interpreter/pipeline-execution.d.ts +1 -1
- package/dist/interpreter/redirections.d.ts +25 -10
- package/dist/interpreter/types.d.ts +2 -0
- package/dist/types.d.ts +15 -0
- package/dist/utils/string-builder.d.ts +9 -0
- package/package.json +1 -1
- package/dist/bin/chunks/awk2-U22OR5B5.js +0 -3
- package/dist/bin/chunks/base64-2KKH5BCT.js +0 -3
- package/dist/bin/chunks/bash-CFCBBWVH.js +0 -3
- package/dist/bin/chunks/cat-V45MVNBT.js +0 -3
- package/dist/bin/chunks/chmod-A54R4UUQ.js +0 -3
- package/dist/bin/chunks/chunk-2NJJXU4K.js +0 -27
- package/dist/bin/chunks/chunk-2YLY6FJA.js +0 -10
- package/dist/bin/chunks/chunk-3LKMI5IX.js +0 -34
- package/dist/bin/chunks/chunk-3VSWQCPN.js +0 -18
- package/dist/bin/chunks/chunk-44SKMHU6.js +0 -16
- package/dist/bin/chunks/chunk-5SKEZPTU.js +0 -12
- package/dist/bin/chunks/chunk-5SR55TXB.js +0 -16
- package/dist/bin/chunks/chunk-6D75E4LV.js +0 -3
- package/dist/bin/chunks/chunk-6DAR25KN.js +0 -12
- package/dist/bin/chunks/chunk-6SAZRW7E.js +0 -15
- package/dist/bin/chunks/chunk-723HNGID.js +0 -13
- package/dist/bin/chunks/chunk-7FGDUBSN.js +0 -14
- package/dist/bin/chunks/chunk-7X4QBCFW.js +0 -36
- package/dist/bin/chunks/chunk-AINNAQBQ.js +0 -6
- package/dist/bin/chunks/chunk-AL7RVSF4.js +0 -8
- package/dist/bin/chunks/chunk-ARYCSNJJ.js +0 -101
- package/dist/bin/chunks/chunk-BCJ42NCM.js +0 -15
- package/dist/bin/chunks/chunk-BJF6B4YW.js +0 -22
- package/dist/bin/chunks/chunk-BOXG6XBN.js +0 -143
- package/dist/bin/chunks/chunk-CPKBPQ2C.js +0 -3
- package/dist/bin/chunks/chunk-DA3RFNKK.js +0 -17
- package/dist/bin/chunks/chunk-DH7M46D3.js +0 -20
- package/dist/bin/chunks/chunk-DTGQQKI2.js +0 -87
- package/dist/bin/chunks/chunk-ECZAFQ22.js +0 -9
- package/dist/bin/chunks/chunk-ETWDDV6I.js +0 -10
- package/dist/bin/chunks/chunk-HFW2LXQV.js +0 -13
- package/dist/bin/chunks/chunk-HRKG3ZK2.js +0 -8
- package/dist/bin/chunks/chunk-I4IRHQDW.js +0 -3
- package/dist/bin/chunks/chunk-IKUY74NG.js +0 -3
- package/dist/bin/chunks/chunk-ILXMFIYG.js +0 -7
- package/dist/bin/chunks/chunk-IMVXTSPG.js +0 -275
- package/dist/bin/chunks/chunk-ISW2U76N.js +0 -17
- package/dist/bin/chunks/chunk-K5KT6DMM.js +0 -4
- package/dist/bin/chunks/chunk-KG2KXL4Y.js +0 -3
- package/dist/bin/chunks/chunk-LCP3IKI7.js +0 -9
- package/dist/bin/chunks/chunk-LG6IN6SW.js +0 -34
- package/dist/bin/chunks/chunk-LMFAALLO.js +0 -21
- package/dist/bin/chunks/chunk-LXFMIXGA.js +0 -3
- package/dist/bin/chunks/chunk-M5ZBECGM.js +0 -22
- package/dist/bin/chunks/chunk-MA6BMA4M.js +0 -3
- package/dist/bin/chunks/chunk-MPQMTLXN.js +0 -3
- package/dist/bin/chunks/chunk-MUIYG2RB.js +0 -65
- package/dist/bin/chunks/chunk-MYTNZ7MA.js +0 -7
- package/dist/bin/chunks/chunk-NGMFI3RH.js +0 -15
- package/dist/bin/chunks/chunk-NLMTGTSG.js +0 -11
- package/dist/bin/chunks/chunk-O74FSWB4.js +0 -4
- package/dist/bin/chunks/chunk-OBVTFHVP.js +0 -7
- package/dist/bin/chunks/chunk-OOKVPG5D.js +0 -6
- package/dist/bin/chunks/chunk-PL4EU7Y2.js +0 -3
- package/dist/bin/chunks/chunk-Q3LE3Y66.js +0 -13
- package/dist/bin/chunks/chunk-QCGH2ZOW.js +0 -13
- package/dist/bin/chunks/chunk-QKWMWSV3.js +0 -3
- package/dist/bin/chunks/chunk-QL33F2W6.js +0 -8
- package/dist/bin/chunks/chunk-S5Z7DMIE.js +0 -26
- package/dist/bin/chunks/chunk-SQ7SZZMW.js +0 -8
- package/dist/bin/chunks/chunk-SQUH76NP.js +0 -3
- package/dist/bin/chunks/chunk-TGRZ42DS.js +0 -12
- package/dist/bin/chunks/chunk-THTKNRO6.js +0 -7
- package/dist/bin/chunks/chunk-TQXLQEIT.js +0 -9
- package/dist/bin/chunks/chunk-TZ3S7MY6.js +0 -12
- package/dist/bin/chunks/chunk-U6BXPMLD.js +0 -7
- package/dist/bin/chunks/chunk-U6DBRMD5.js +0 -5
- package/dist/bin/chunks/chunk-URRH3GPG.js +0 -10
- package/dist/bin/chunks/chunk-VBU3UEG5.js +0 -7
- package/dist/bin/chunks/chunk-VLWZ6L7C.js +0 -4
- package/dist/bin/chunks/chunk-VTHA5UK5.js +0 -7
- package/dist/bin/chunks/chunk-WBST7XJW.js +0 -9
- package/dist/bin/chunks/chunk-WDV2ECOC.js +0 -3
- package/dist/bin/chunks/chunk-WEQ5WM2M.js +0 -20
- package/dist/bin/chunks/chunk-WFVCEB5T.js +0 -3
- package/dist/bin/chunks/chunk-WZ7MIBLR.js +0 -37
- package/dist/bin/chunks/chunk-X45GP3AQ.js +0 -3
- package/dist/bin/chunks/chunk-XEQ7KSRM.js +0 -5
- package/dist/bin/chunks/chunk-YIANER7Y.js +0 -8
- package/dist/bin/chunks/chunk-YYZSYLJO.js +0 -6
- package/dist/bin/chunks/chunk-Z3KAV6YJ.js +0 -10
- package/dist/bin/chunks/chunk-Z5KICK5X.js +0 -22
- package/dist/bin/chunks/column-LHHS4D3K.js +0 -3
- package/dist/bin/chunks/comm-URDMZCXL.js +0 -3
- package/dist/bin/chunks/cp-HPLQA35N.js +0 -3
- package/dist/bin/chunks/curl-FIRG3RB6.js +0 -31
- package/dist/bin/chunks/cut-KP3S36XS.js +0 -3
- package/dist/bin/chunks/date-FJUBX7TJ.js +0 -3
- package/dist/bin/chunks/diff-JSJ56EOK.js +0 -3
- package/dist/bin/chunks/du-WEF5YWQK.js +0 -3
- package/dist/bin/chunks/env-2TSVF4W7.js +0 -3
- package/dist/bin/chunks/expand-P6SNTBGZ.js +0 -3
- package/dist/bin/chunks/expr-FLWT4OCO.js +0 -3
- package/dist/bin/chunks/file-JLUCGBCB.js +0 -3
- package/dist/bin/chunks/find-XGVQ6N6L.js +0 -3
- package/dist/bin/chunks/flag-coverage-4JYKIAVV.js +0 -3
- package/dist/bin/chunks/fold-YEY7X54W.js +0 -3
- package/dist/bin/chunks/grep-DCPCPQOS.js +0 -3
- package/dist/bin/chunks/gzip-6DZIKNBW.js +0 -3
- package/dist/bin/chunks/head-TLFXMM2T.js +0 -3
- package/dist/bin/chunks/html-to-markdown-E22RLT2U.js +0 -3
- package/dist/bin/chunks/join-UQKXU2QP.js +0 -3
- package/dist/bin/chunks/jq-GDM3OBBK.js +0 -3
- package/dist/bin/chunks/js-exec-VU6F6WLS.js +0 -1578
- package/dist/bin/chunks/ls-67NUUIYT.js +0 -3
- package/dist/bin/chunks/md5sum-Z6KAYGDK.js +0 -3
- package/dist/bin/chunks/mkdir-AWDWRBKC.js +0 -3
- package/dist/bin/chunks/mktemp-L6OGMDUO.js +0 -3
- package/dist/bin/chunks/mv-4BJSOT4Y.js +0 -3
- package/dist/bin/chunks/nl-XHWFVVKH.js +0 -3
- package/dist/bin/chunks/od-SI75GLRE.js +0 -3
- package/dist/bin/chunks/paste-5TSIBDF7.js +0 -3
- package/dist/bin/chunks/printf-CNXNRQ3I.js +0 -3
- package/dist/bin/chunks/python3-GUWCSSDP.js +0 -23
- package/dist/bin/chunks/readlink-URO5XTBB.js +0 -3
- package/dist/bin/chunks/rev-CZTQCNOZ.js +0 -3
- package/dist/bin/chunks/rg-RVULUPDH.js +0 -3
- package/dist/bin/chunks/rm-UCUTHC3I.js +0 -3
- package/dist/bin/chunks/rmdir-J3HM7GGM.js +0 -3
- package/dist/bin/chunks/sed-MCLGHZOI.js +0 -3
- package/dist/bin/chunks/seq-I54NZE75.js +0 -3
- package/dist/bin/chunks/sha1sum-CATBXX76.js +0 -3
- package/dist/bin/chunks/sha256sum-YGSNBVY3.js +0 -3
- package/dist/bin/chunks/sort-M3DO25D5.js +0 -3
- package/dist/bin/chunks/split-VZO7223N.js +0 -3
- package/dist/bin/chunks/sqlite3-HXVFVP4Z.js +0 -3
- package/dist/bin/chunks/stat-UJ37RBMM.js +0 -3
- package/dist/bin/chunks/strings-J2X2Z6N2.js +0 -3
- package/dist/bin/chunks/tac-DG4BMYM5.js +0 -3
- package/dist/bin/chunks/tail-5TSF5YM4.js +0 -3
- package/dist/bin/chunks/tar-ZGZZDQXO.js +0 -3
- package/dist/bin/chunks/tee-L4HKV5PD.js +0 -3
- package/dist/bin/chunks/time-J2DAZUIN.js +0 -3
- package/dist/bin/chunks/timeout-ATTDYXLX.js +0 -3
- package/dist/bin/chunks/touch-TVQAUQOG.js +0 -3
- package/dist/bin/chunks/tr-6RPFASYV.js +0 -3
- package/dist/bin/chunks/unexpand-JPOQORZF.js +0 -3
- package/dist/bin/chunks/uniq-K5VRDP4Q.js +0 -3
- package/dist/bin/chunks/wc-VSQBRD6B.js +0 -3
- package/dist/bin/chunks/xan-CCS53B7D.js +0 -3
- package/dist/bin/chunks/xan-view-KOXASOEV.js +0 -3
- package/dist/bin/chunks/xargs-HMISWW4I.js +0 -3
- package/dist/bin/chunks/yes-ELH3XQWY.js +0 -3
- package/dist/bin/chunks/yq-GSCDUHGM.js +0 -3
- package/dist/bin/shell/chunks/awk2-U22OR5B5.js +0 -3
- package/dist/bin/shell/chunks/base64-2KKH5BCT.js +0 -3
- package/dist/bin/shell/chunks/bash-CFCBBWVH.js +0 -3
- package/dist/bin/shell/chunks/cat-V45MVNBT.js +0 -3
- package/dist/bin/shell/chunks/chmod-A54R4UUQ.js +0 -3
- package/dist/bin/shell/chunks/chunk-2NJJXU4K.js +0 -27
- package/dist/bin/shell/chunks/chunk-2YLY6FJA.js +0 -10
- package/dist/bin/shell/chunks/chunk-3LKMI5IX.js +0 -34
- package/dist/bin/shell/chunks/chunk-3VSWQCPN.js +0 -18
- package/dist/bin/shell/chunks/chunk-44SKMHU6.js +0 -16
- package/dist/bin/shell/chunks/chunk-5SKEZPTU.js +0 -12
- package/dist/bin/shell/chunks/chunk-5SR55TXB.js +0 -16
- package/dist/bin/shell/chunks/chunk-6D75E4LV.js +0 -3
- package/dist/bin/shell/chunks/chunk-6DAR25KN.js +0 -12
- package/dist/bin/shell/chunks/chunk-6SAZRW7E.js +0 -15
- package/dist/bin/shell/chunks/chunk-723HNGID.js +0 -13
- package/dist/bin/shell/chunks/chunk-7FGDUBSN.js +0 -14
- package/dist/bin/shell/chunks/chunk-7X4QBCFW.js +0 -36
- package/dist/bin/shell/chunks/chunk-AINNAQBQ.js +0 -6
- package/dist/bin/shell/chunks/chunk-AL7RVSF4.js +0 -8
- package/dist/bin/shell/chunks/chunk-ARYCSNJJ.js +0 -101
- package/dist/bin/shell/chunks/chunk-BCJ42NCM.js +0 -15
- package/dist/bin/shell/chunks/chunk-BJF6B4YW.js +0 -22
- package/dist/bin/shell/chunks/chunk-BOXG6XBN.js +0 -143
- package/dist/bin/shell/chunks/chunk-CPKBPQ2C.js +0 -3
- package/dist/bin/shell/chunks/chunk-DA3RFNKK.js +0 -17
- package/dist/bin/shell/chunks/chunk-DH7M46D3.js +0 -20
- package/dist/bin/shell/chunks/chunk-DTGQQKI2.js +0 -87
- package/dist/bin/shell/chunks/chunk-ECZAFQ22.js +0 -9
- package/dist/bin/shell/chunks/chunk-ETWDDV6I.js +0 -10
- package/dist/bin/shell/chunks/chunk-HFW2LXQV.js +0 -13
- package/dist/bin/shell/chunks/chunk-HRKG3ZK2.js +0 -8
- package/dist/bin/shell/chunks/chunk-I4IRHQDW.js +0 -3
- package/dist/bin/shell/chunks/chunk-IKUY74NG.js +0 -3
- package/dist/bin/shell/chunks/chunk-ILXMFIYG.js +0 -7
- package/dist/bin/shell/chunks/chunk-IMVXTSPG.js +0 -275
- package/dist/bin/shell/chunks/chunk-ISW2U76N.js +0 -17
- package/dist/bin/shell/chunks/chunk-K5KT6DMM.js +0 -4
- package/dist/bin/shell/chunks/chunk-KG2KXL4Y.js +0 -3
- package/dist/bin/shell/chunks/chunk-LCP3IKI7.js +0 -9
- package/dist/bin/shell/chunks/chunk-LG6IN6SW.js +0 -34
- package/dist/bin/shell/chunks/chunk-LMFAALLO.js +0 -21
- package/dist/bin/shell/chunks/chunk-LXFMIXGA.js +0 -3
- package/dist/bin/shell/chunks/chunk-M5ZBECGM.js +0 -22
- package/dist/bin/shell/chunks/chunk-MA6BMA4M.js +0 -3
- package/dist/bin/shell/chunks/chunk-MPQMTLXN.js +0 -3
- package/dist/bin/shell/chunks/chunk-MUIYG2RB.js +0 -65
- package/dist/bin/shell/chunks/chunk-MYTNZ7MA.js +0 -7
- package/dist/bin/shell/chunks/chunk-NGMFI3RH.js +0 -15
- package/dist/bin/shell/chunks/chunk-NLMTGTSG.js +0 -11
- package/dist/bin/shell/chunks/chunk-O74FSWB4.js +0 -4
- package/dist/bin/shell/chunks/chunk-OBVTFHVP.js +0 -7
- package/dist/bin/shell/chunks/chunk-OOKVPG5D.js +0 -6
- package/dist/bin/shell/chunks/chunk-PL4EU7Y2.js +0 -3
- package/dist/bin/shell/chunks/chunk-Q3LE3Y66.js +0 -13
- package/dist/bin/shell/chunks/chunk-QCGH2ZOW.js +0 -13
- package/dist/bin/shell/chunks/chunk-QKWMWSV3.js +0 -3
- package/dist/bin/shell/chunks/chunk-QL33F2W6.js +0 -8
- package/dist/bin/shell/chunks/chunk-S5Z7DMIE.js +0 -26
- package/dist/bin/shell/chunks/chunk-SQ7SZZMW.js +0 -8
- package/dist/bin/shell/chunks/chunk-SQUH76NP.js +0 -3
- package/dist/bin/shell/chunks/chunk-TGRZ42DS.js +0 -12
- package/dist/bin/shell/chunks/chunk-THTKNRO6.js +0 -7
- package/dist/bin/shell/chunks/chunk-TQXLQEIT.js +0 -9
- package/dist/bin/shell/chunks/chunk-TZ3S7MY6.js +0 -12
- package/dist/bin/shell/chunks/chunk-U6BXPMLD.js +0 -7
- package/dist/bin/shell/chunks/chunk-U6DBRMD5.js +0 -5
- package/dist/bin/shell/chunks/chunk-URRH3GPG.js +0 -10
- package/dist/bin/shell/chunks/chunk-VBU3UEG5.js +0 -7
- package/dist/bin/shell/chunks/chunk-VLWZ6L7C.js +0 -4
- package/dist/bin/shell/chunks/chunk-VTHA5UK5.js +0 -7
- package/dist/bin/shell/chunks/chunk-WBST7XJW.js +0 -9
- package/dist/bin/shell/chunks/chunk-WDV2ECOC.js +0 -3
- package/dist/bin/shell/chunks/chunk-WEQ5WM2M.js +0 -20
- package/dist/bin/shell/chunks/chunk-WFVCEB5T.js +0 -3
- package/dist/bin/shell/chunks/chunk-WZ7MIBLR.js +0 -37
- package/dist/bin/shell/chunks/chunk-X45GP3AQ.js +0 -3
- package/dist/bin/shell/chunks/chunk-XEQ7KSRM.js +0 -5
- package/dist/bin/shell/chunks/chunk-YIANER7Y.js +0 -8
- package/dist/bin/shell/chunks/chunk-YYZSYLJO.js +0 -6
- package/dist/bin/shell/chunks/chunk-Z3KAV6YJ.js +0 -10
- package/dist/bin/shell/chunks/chunk-Z5KICK5X.js +0 -22
- package/dist/bin/shell/chunks/column-LHHS4D3K.js +0 -3
- package/dist/bin/shell/chunks/comm-URDMZCXL.js +0 -3
- package/dist/bin/shell/chunks/cp-HPLQA35N.js +0 -3
- package/dist/bin/shell/chunks/curl-FIRG3RB6.js +0 -31
- package/dist/bin/shell/chunks/cut-KP3S36XS.js +0 -3
- package/dist/bin/shell/chunks/date-FJUBX7TJ.js +0 -3
- package/dist/bin/shell/chunks/diff-JSJ56EOK.js +0 -3
- package/dist/bin/shell/chunks/du-WEF5YWQK.js +0 -3
- package/dist/bin/shell/chunks/env-2TSVF4W7.js +0 -3
- package/dist/bin/shell/chunks/expand-P6SNTBGZ.js +0 -3
- package/dist/bin/shell/chunks/expr-FLWT4OCO.js +0 -3
- package/dist/bin/shell/chunks/file-JLUCGBCB.js +0 -3
- package/dist/bin/shell/chunks/find-XGVQ6N6L.js +0 -3
- package/dist/bin/shell/chunks/flag-coverage-4JYKIAVV.js +0 -3
- package/dist/bin/shell/chunks/fold-YEY7X54W.js +0 -3
- package/dist/bin/shell/chunks/grep-DCPCPQOS.js +0 -3
- package/dist/bin/shell/chunks/gzip-6DZIKNBW.js +0 -3
- package/dist/bin/shell/chunks/head-TLFXMM2T.js +0 -3
- package/dist/bin/shell/chunks/html-to-markdown-E22RLT2U.js +0 -3
- package/dist/bin/shell/chunks/join-UQKXU2QP.js +0 -3
- package/dist/bin/shell/chunks/jq-GDM3OBBK.js +0 -3
- package/dist/bin/shell/chunks/js-exec-VU6F6WLS.js +0 -1578
- package/dist/bin/shell/chunks/ls-67NUUIYT.js +0 -3
- package/dist/bin/shell/chunks/md5sum-Z6KAYGDK.js +0 -3
- package/dist/bin/shell/chunks/mkdir-AWDWRBKC.js +0 -3
- package/dist/bin/shell/chunks/mktemp-L6OGMDUO.js +0 -3
- package/dist/bin/shell/chunks/mv-4BJSOT4Y.js +0 -3
- package/dist/bin/shell/chunks/nl-XHWFVVKH.js +0 -3
- package/dist/bin/shell/chunks/od-SI75GLRE.js +0 -3
- package/dist/bin/shell/chunks/paste-5TSIBDF7.js +0 -3
- package/dist/bin/shell/chunks/printf-CNXNRQ3I.js +0 -3
- package/dist/bin/shell/chunks/python3-GUWCSSDP.js +0 -23
- package/dist/bin/shell/chunks/readlink-URO5XTBB.js +0 -3
- package/dist/bin/shell/chunks/rev-CZTQCNOZ.js +0 -3
- package/dist/bin/shell/chunks/rg-RVULUPDH.js +0 -3
- package/dist/bin/shell/chunks/rm-UCUTHC3I.js +0 -3
- package/dist/bin/shell/chunks/rmdir-J3HM7GGM.js +0 -3
- package/dist/bin/shell/chunks/sed-MCLGHZOI.js +0 -3
- package/dist/bin/shell/chunks/seq-I54NZE75.js +0 -3
- package/dist/bin/shell/chunks/sha1sum-CATBXX76.js +0 -3
- package/dist/bin/shell/chunks/sha256sum-YGSNBVY3.js +0 -3
- package/dist/bin/shell/chunks/sort-M3DO25D5.js +0 -3
- package/dist/bin/shell/chunks/split-VZO7223N.js +0 -3
- package/dist/bin/shell/chunks/sqlite3-HXVFVP4Z.js +0 -3
- package/dist/bin/shell/chunks/stat-UJ37RBMM.js +0 -3
- package/dist/bin/shell/chunks/strings-J2X2Z6N2.js +0 -3
- package/dist/bin/shell/chunks/tac-DG4BMYM5.js +0 -3
- package/dist/bin/shell/chunks/tail-5TSF5YM4.js +0 -3
- package/dist/bin/shell/chunks/tar-ZGZZDQXO.js +0 -3
- package/dist/bin/shell/chunks/tee-L4HKV5PD.js +0 -3
- package/dist/bin/shell/chunks/time-J2DAZUIN.js +0 -3
- package/dist/bin/shell/chunks/timeout-ATTDYXLX.js +0 -3
- package/dist/bin/shell/chunks/touch-TVQAUQOG.js +0 -3
- package/dist/bin/shell/chunks/tr-6RPFASYV.js +0 -3
- package/dist/bin/shell/chunks/unexpand-JPOQORZF.js +0 -3
- package/dist/bin/shell/chunks/uniq-K5VRDP4Q.js +0 -3
- package/dist/bin/shell/chunks/wc-VSQBRD6B.js +0 -3
- package/dist/bin/shell/chunks/xan-CCS53B7D.js +0 -3
- package/dist/bin/shell/chunks/xan-view-KOXASOEV.js +0 -3
- package/dist/bin/shell/chunks/xargs-HMISWW4I.js +0 -3
- package/dist/bin/shell/chunks/yes-ELH3XQWY.js +0 -3
- package/dist/bin/shell/chunks/yq-GSCDUHGM.js +0 -3
- package/dist/bundle/chunks/awk2-V7KYQWCD.js +0 -2
- package/dist/bundle/chunks/base64-QPSYZAAJ.js +0 -2
- package/dist/bundle/chunks/bash-HIEWVHJ2.js +0 -2
- package/dist/bundle/chunks/cat-54BXBS6X.js +0 -2
- package/dist/bundle/chunks/chmod-4OPV4QKK.js +0 -2
- package/dist/bundle/chunks/chunk-2KNTH3KH.js +0 -9
- package/dist/bundle/chunks/chunk-2VWG4LDT.js +0 -11
- package/dist/bundle/chunks/chunk-2WBUTDF5.js +0 -2
- package/dist/bundle/chunks/chunk-3HDTNUL3.js +0 -6
- package/dist/bundle/chunks/chunk-3KWM4FFA.js +0 -12
- package/dist/bundle/chunks/chunk-4AKAIZPW.js +0 -15
- package/dist/bundle/chunks/chunk-4IMUNIUJ.js +0 -21
- package/dist/bundle/chunks/chunk-5ATEFZLC.js +0 -4
- package/dist/bundle/chunks/chunk-5BMPT6SF.js +0 -19
- package/dist/bundle/chunks/chunk-5QWGR2WA.js +0 -21
- package/dist/bundle/chunks/chunk-5UTZMNI5.js +0 -64
- package/dist/bundle/chunks/chunk-5VCAQBXL.js +0 -17
- package/dist/bundle/chunks/chunk-65LVAUWW.js +0 -7
- package/dist/bundle/chunks/chunk-6D3WD6YU.js +0 -3
- package/dist/bundle/chunks/chunk-6R4OQQWP.js +0 -16
- package/dist/bundle/chunks/chunk-6WGIZV3E.js +0 -13
- package/dist/bundle/chunks/chunk-72JHTO7E.js +0 -2
- package/dist/bundle/chunks/chunk-7GA3QWJJ.js +0 -33
- package/dist/bundle/chunks/chunk-7M672HB6.js +0 -21
- package/dist/bundle/chunks/chunk-AFFAMSJT.js +0 -14
- package/dist/bundle/chunks/chunk-ANCQ4SCV.js +0 -2
- package/dist/bundle/chunks/chunk-B3NGH6KE.js +0 -5
- package/dist/bundle/chunks/chunk-B5Z5HTFY.js +0 -14
- package/dist/bundle/chunks/chunk-B6OSJB22.js +0 -26
- package/dist/bundle/chunks/chunk-BM3X75NC.js +0 -36
- package/dist/bundle/chunks/chunk-CGI6V2HW.js +0 -11
- package/dist/bundle/chunks/chunk-CHHWTPDH.js +0 -3
- package/dist/bundle/chunks/chunk-D5ZJISRS.js +0 -11
- package/dist/bundle/chunks/chunk-DIRWTBKE.js +0 -19
- package/dist/bundle/chunks/chunk-DIWMSSQY.js +0 -2
- package/dist/bundle/chunks/chunk-DPZVOEUP.js +0 -6
- package/dist/bundle/chunks/chunk-EFORKKSH.js +0 -8
- package/dist/bundle/chunks/chunk-EGTVQWAP.js +0 -20
- package/dist/bundle/chunks/chunk-EJFBIRMD.js +0 -6
- package/dist/bundle/chunks/chunk-EQQGPAXI.js +0 -9
- package/dist/bundle/chunks/chunk-EXXOLIVE.js +0 -35
- package/dist/bundle/chunks/chunk-FIMO5HLX.js +0 -2
- package/dist/bundle/chunks/chunk-FT6ODGOU.js +0 -2
- package/dist/bundle/chunks/chunk-FZRQOL3C.js +0 -7
- package/dist/bundle/chunks/chunk-GLAFXDZC.js +0 -4
- package/dist/bundle/chunks/chunk-GN6CQ3J4.js +0 -2
- package/dist/bundle/chunks/chunk-H42OAUJL.js +0 -12
- package/dist/bundle/chunks/chunk-H53EPEGD.js +0 -12
- package/dist/bundle/chunks/chunk-HDOXCDVK.js +0 -7
- package/dist/bundle/chunks/chunk-HIQEVPXM.js +0 -2
- package/dist/bundle/chunks/chunk-J2OBOJ64.js +0 -2
- package/dist/bundle/chunks/chunk-LVDUF74R.js +0 -7
- package/dist/bundle/chunks/chunk-M4LDT7V7.js +0 -6
- package/dist/bundle/chunks/chunk-MDE25PQK.js +0 -15
- package/dist/bundle/chunks/chunk-MHDZERK4.js +0 -6
- package/dist/bundle/chunks/chunk-MHZF23KB.js +0 -33
- package/dist/bundle/chunks/chunk-N6W6FM4N.js +0 -8
- package/dist/bundle/chunks/chunk-NRLE7KYI.js +0 -6
- package/dist/bundle/chunks/chunk-OB46N7Q7.js +0 -2
- package/dist/bundle/chunks/chunk-OQ7C4FYO.js +0 -2
- package/dist/bundle/chunks/chunk-P5BOIHWV.js +0 -6
- package/dist/bundle/chunks/chunk-PPDMRIJ7.js +0 -11
- package/dist/bundle/chunks/chunk-PPHGMG47.js +0 -142
- package/dist/bundle/chunks/chunk-R6ZGLVXI.js +0 -9
- package/dist/bundle/chunks/chunk-RCRHDT54.js +0 -274
- package/dist/bundle/chunks/chunk-RIIUVFUS.js +0 -7
- package/dist/bundle/chunks/chunk-SQX6WQXB.js +0 -7
- package/dist/bundle/chunks/chunk-SRB6FXRH.js +0 -2
- package/dist/bundle/chunks/chunk-T4INBNHX.js +0 -8
- package/dist/bundle/chunks/chunk-TUQG2YRH.js +0 -5
- package/dist/bundle/chunks/chunk-U7UNEMLJ.js +0 -2
- package/dist/bundle/chunks/chunk-UHHCL65P.js +0 -3
- package/dist/bundle/chunks/chunk-UK2K3DHN.js +0 -8
- package/dist/bundle/chunks/chunk-VDJ53ESK.js +0 -9
- package/dist/bundle/chunks/chunk-VGCXKMXN.js +0 -10
- package/dist/bundle/chunks/chunk-W5DWRFSU.js +0 -2
- package/dist/bundle/chunks/chunk-W5J5ADJF.js +0 -100
- package/dist/bundle/chunks/chunk-XHFP44Y4.js +0 -5
- package/dist/bundle/chunks/chunk-Y32R7EZP.js +0 -25
- package/dist/bundle/chunks/chunk-Y62SXZKJ.js +0 -12
- package/dist/bundle/chunks/chunk-YUFU7O6I.js +0 -16
- package/dist/bundle/chunks/chunk-YZH7FUSY.js +0 -14
- package/dist/bundle/chunks/column-F5JDBRV6.js +0 -2
- package/dist/bundle/chunks/comm-DTWKU2MC.js +0 -2
- package/dist/bundle/chunks/cp-LTFB4EUA.js +0 -2
- package/dist/bundle/chunks/curl-XCX2ZQEA.js +0 -30
- package/dist/bundle/chunks/cut-IRSHL3BB.js +0 -2
- package/dist/bundle/chunks/date-FN2DXAEE.js +0 -2
- package/dist/bundle/chunks/diff-VDB6RXHO.js +0 -2
- package/dist/bundle/chunks/du-DOWSRLXR.js +0 -2
- package/dist/bundle/chunks/env-VUUMB47B.js +0 -2
- package/dist/bundle/chunks/expand-2BPPGGSM.js +0 -2
- package/dist/bundle/chunks/expr-GZ4DABKB.js +0 -2
- package/dist/bundle/chunks/file-UI6QJAAU.js +0 -2
- package/dist/bundle/chunks/find-JTXDH3MR.js +0 -2
- package/dist/bundle/chunks/flag-coverage-EDO3VM43.js +0 -2
- package/dist/bundle/chunks/fold-QJBPHRFJ.js +0 -2
- package/dist/bundle/chunks/grep-OZCR76FT.js +0 -2
- package/dist/bundle/chunks/gzip-GQC6CWVL.js +0 -2
- package/dist/bundle/chunks/head-J6RVJFRS.js +0 -2
- package/dist/bundle/chunks/html-to-markdown-7OG5VWYG.js +0 -2
- package/dist/bundle/chunks/join-KQ4Z5OD4.js +0 -2
- package/dist/bundle/chunks/jq-FCG2IUBK.js +0 -2
- package/dist/bundle/chunks/js-exec-NDLXDUBN.js +0 -1577
- package/dist/bundle/chunks/ls-MQTYWW4T.js +0 -2
- package/dist/bundle/chunks/md5sum-JEDX55KS.js +0 -2
- package/dist/bundle/chunks/mkdir-4A5W3RXH.js +0 -2
- package/dist/bundle/chunks/mktemp-XKIE5N3X.js +0 -2
- package/dist/bundle/chunks/mv-ZPIATQJL.js +0 -2
- package/dist/bundle/chunks/nl-RFXH2GNX.js +0 -2
- package/dist/bundle/chunks/od-LUHOH7CG.js +0 -2
- package/dist/bundle/chunks/paste-U57ZU47S.js +0 -2
- package/dist/bundle/chunks/printf-V42QCPHL.js +0 -2
- package/dist/bundle/chunks/python3-SDFCGIU4.js +0 -22
- package/dist/bundle/chunks/readlink-YNNS6F7K.js +0 -2
- package/dist/bundle/chunks/rev-EPOS3MFH.js +0 -2
- package/dist/bundle/chunks/rg-F4SX2PHI.js +0 -2
- package/dist/bundle/chunks/rm-3XUUYAXQ.js +0 -2
- package/dist/bundle/chunks/rmdir-OGSEXEF4.js +0 -2
- package/dist/bundle/chunks/sed-MBB5SXGD.js +0 -2
- package/dist/bundle/chunks/seq-IN77HD3S.js +0 -2
- package/dist/bundle/chunks/sha1sum-BLPZJ6MP.js +0 -2
- package/dist/bundle/chunks/sha256sum-VJZ4PHQ4.js +0 -2
- package/dist/bundle/chunks/sort-PV2NEQHF.js +0 -2
- package/dist/bundle/chunks/split-6R2TSQY6.js +0 -2
- package/dist/bundle/chunks/sqlite3-7MBPFI6W.js +0 -2
- package/dist/bundle/chunks/stat-YLVJ4L67.js +0 -2
- package/dist/bundle/chunks/strings-WTD7Q2EF.js +0 -2
- package/dist/bundle/chunks/tac-YXC4HBTR.js +0 -2
- package/dist/bundle/chunks/tail-UGFWX3YY.js +0 -2
- package/dist/bundle/chunks/tar-BNHPWTOY.js +0 -2
- package/dist/bundle/chunks/tee-OOWSWHRQ.js +0 -2
- package/dist/bundle/chunks/time-N6J6DC6C.js +0 -2
- package/dist/bundle/chunks/timeout-ZHCL5KTP.js +0 -2
- package/dist/bundle/chunks/touch-W4DF6Z4T.js +0 -2
- package/dist/bundle/chunks/tr-4NGL47UU.js +0 -2
- package/dist/bundle/chunks/unexpand-YD5BWFH4.js +0 -2
- package/dist/bundle/chunks/uniq-OVOW532K.js +0 -2
- package/dist/bundle/chunks/wc-RUR7HE5O.js +0 -2
- package/dist/bundle/chunks/xan-7R3I2DJO.js +0 -2
- package/dist/bundle/chunks/xan-view-S4ZILLPU.js +0 -2
- package/dist/bundle/chunks/xargs-L7TJHOJT.js +0 -2
- package/dist/bundle/chunks/yes-I7SAR7XX.js +0 -2
- package/dist/bundle/chunks/yq-IOMBQYB2.js +0 -2
package/dist/bundle/index.js
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
1
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
2
|
-
import{a as Ft,b as Mt,c as
|
|
3
|
-
`)),
|
|
4
|
-
`);s(n.coverage,e.name,t)}return r.execute(t,n)}}}function
|
|
5
|
-
`)}finally{u&&r.delete(u)}}let c=t;if(!c)throw new Error(`Failed to load command: ${e.name}`);return c.execute(a,l)}}}var
|
|
2
|
+
import{a as Ft,b as Mt,c as it}from"./chunks/chunk-353VO5TF.js";import{a as Wr,b as or}from"./chunks/chunk-LBKOJW6K.js";import{a as Lr,b as Fr,c as rr,d as sr}from"./chunks/chunk-43OP7DFL.js";import{c as fi,e as Oa,f as Da}from"./chunks/chunk-XZ34OGNM.js";import{a as Qt}from"./chunks/chunk-BLTFJFWH.js";import{a as ui}from"./chunks/chunk-L2UW7DWF.js";import{a as Zt,b as Ye,c as lr}from"./chunks/chunk-DLL7UR66.js";import{a as ar,b as Ra}from"./chunks/chunk-CHWP6GRK.js";import{a as ge}from"./chunks/chunk-EOMWWW4L.js";import{a as zt,b as Ce}from"./chunks/chunk-CBM6J4AL.js";import"./chunks/chunk-NJUHQKMR.js";import{d as Gt,e as Ln}from"./chunks/chunk-Q6ZH76O4.js";import"./chunks/chunk-STHBFACM.js";import{a as Na}from"./chunks/chunk-RK2WBVP4.js";import{a as j,b as Lt,c as q,d as mt,e as Ht,f as st,g as Fn}from"./chunks/chunk-YUSFCOM7.js";import{a as Tn,b as Qe,c as Ke,d as Le,e as Ve,f as ze,g as G,h as le,i as Xe,j as jt,k as Mr,l as C,m as Ue,n as qt,o as Br,p as rt}from"./chunks/chunk-IQGNPH54.js";import{a as V,b as ir,c as wn,d as td,e as Ut,f as li,g as _n,h as nd,i as _t,j as ci,k as rd,l as sd}from"./chunks/chunk-U3UTFNHI.js";import{a as Tt,b as Ca}from"./chunks/chunk-WFEUQRHM.js";import{a as kt}from"./chunks/chunk-FOCWZZDE.js";import{a as ai}from"./chunks/chunk-NCUTH6QL.js";var En=[{name:"echo",load:async()=>(await import("./chunks/echo-PLLZYM2L.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-UBR2ABBH.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-BNADL4RX.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-WMN4WCCI.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-YJMG55FX.js")).mkdirCommand},{name:"mktemp",load:async()=>(await import("./chunks/mktemp-RA55VAN3.js")).mktempCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-HI3UE4KQ.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-57OKADDG.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-CDVWO5CO.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-AQ4Y4WVV.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-NTJL2AHI.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-OPY2ZVGQ.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-5VBARXGU.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-76BPYV5F.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-HGACDFRD.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-5YWCKNNQ.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-IBKQAMFW.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-HQPGW3KR.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-APUQD6WQ.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-ZELVZ7JB.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-ZELVZ7JB.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-ZELVZ7JB.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-IN3KT335.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-MXZDFQ7I.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-LEEKKBPN.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-ATCMEITA.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-TUUUYPVF.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-QHEYSM4I.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-A6NXJGOH.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-VPYCLIL6.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-M4D6SICQ.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-W57N4M5B.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-Z5DVHZ3S.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-A24KLKHY.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-YVEZTU7W.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-SYZZ5ZBE.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-WA2ZGNUN.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-YZFCWIZI.js")).split},{name:"column",load:async()=>(await import("./chunks/column-46NX3HG3.js")).column},{name:"join",load:async()=>(await import("./chunks/join-MSZXRLNV.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-VOXQ2UGV.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-UYQIFSZI.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-SJZQ5W65.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-Z2ZMOOW2.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-7OOL2MH6.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-JOLY42MC.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-MI6QVNMM.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-MI6QVNMM.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-T5TO5GWK.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-T5TO5GWK.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-3N762S3K.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-WFPZZ3FK.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-QUBPEGGU.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-QUBPEGGU.js")).falseCommand},{name:"yes",load:async()=>(await import("./chunks/yes-ACSNSE7T.js")).yesCommand},{name:"clear",load:async()=>(await import("./chunks/clear-KPIUNI6K.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-QTX2IUM4.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-QTX2IUM4.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-MKA6BDYV.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-GBEVK7UP.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-SECJC7CN.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-YMEJ62OQ.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-3QNP3BGR.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-FVGYB3MD.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-GOHAC6VO.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-E3UP3G65.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-U7WETT5R.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-OCX4NZ2Q.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-QUWYL7G6.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-FGHIABMA.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-6QDI3H7G.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-EOWI2I5J.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-62M75TSG.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-UWVKETYW.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-OCV6R4TG.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-CESD3CQR.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-KR6E7UIR.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-TRWBMEIO.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-3IFADYVU.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-3IFADYVU.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-3IFADYVU.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(En.push({name:"tar",load:async()=>(await import("./chunks/tar-WJV4DGKA.js")).tarCommand}),En.push({name:"yq",load:async()=>(await import("./chunks/yq-XDJLIJPZ.js")).yqCommand}),En.push({name:"xan",load:async()=>(await import("./chunks/xan-CZJZCC57.js")).xanCommand}),En.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-JL36RFBZ.js")).sqlite3Command}));var Vr=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Vr.push({name:"python3",load:async()=>(await import("./chunks/python3-TIKLWPZJ.js")).python3Command}),Vr.push({name:"python",load:async()=>(await import("./chunks/python3-TIKLWPZJ.js")).pythonCommand}));var zr=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(zr.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-CNDWLKWB.js")).jsExecCommand}),zr.push({name:"node",load:async()=>(await import("./chunks/js-exec-CNDWLKWB.js")).nodeStubCommand}));var _a=[{name:"curl",load:async()=>(await import("./chunks/curl-LMCQFYWH.js")).curlCommand}],Ia=new Map;function Ur(e){return{name:e.name,async execute(t,n){let r=Ia.get(e.name);if(r||(r=await Ce.runTrustedAsync(()=>or(e.load(),n.signal,`bash: ${e.name} was cancelled before it started
|
|
3
|
+
`)),Ia.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await or(import("./chunks/flag-coverage-5YCE6ILG.js"),n.signal,`bash: ${e.name} was cancelled before it started
|
|
4
|
+
`);s(n.coverage,e.name,t)}return r.execute(t,n)}}}function id(){return En.map(e=>e.name)}function od(){return _a.map(e=>e.name)}function Ta(e){return(e?En.filter(n=>e.includes(n.name)):En).map(Ur)}function La(){return _a.map(Ur)}function ad(){return Vr.map(e=>e.name)}function Fa(){return Vr.map(Ur)}function ld(){return zr.map(e=>e.name)}function Ma(){return zr.map(Ur)}var Ba=new WeakMap,Wa=new WeakSet;function jr(e){let t=Ba.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),Ba.set(e,t),Wa.add(t)),t}function Va(e){return Wa.has(e)}var za={maxSourceBytes:67108864,maxExecDepth:64,maxCallDepth:100,maxCommandCount:1e5,maxLoopIterations:1e5,maxAwkIterations:1e5,maxSedIterations:1e5,maxJqIterations:1e7,maxQueryTokens:1e5,maxQueryDepth:1e3,maxQueryElements:1e6,maxAwkParserTokens:1e5,maxAwkParserDepth:256,maxAwkParserOperations:1e6,maxCsvRows:1e6,maxCsvCells:1e7,maxWorkUnits:1e8,maxTraversalEntries:1e6,maxTraversalDepth:1e3,maxTraversalWork:1e6,maxLiveBytes:536870912,maxInputBytes:536870912,maxFileSystemBytes:1073741824,maxDatabaseBytes:1073741824,maxDatabaseResultBytes:268435456,maxArchiveBytes:1073741824,maxArchiveCompressedBytes:536870912,maxArchiveEntryBytes:536870912,maxArchiveEntries:1e6,maxWorkerMessageBytes:67108864,maxExecutionTimeMs:36e5,maxExtensionCleanupTimeMs:100,maxSqliteTimeoutMs:3e4,maxPythonTimeoutMs:3e4,maxJsTimeoutMs:3e4,maxJsBridgeRequests:1e6,maxGlobOperations:1e6,maxStringLength:67108864,maxArrayElements:1e6,maxHeredocSize:67108864,maxSubstitutionDepth:50,maxBraceExpansionResults:1e5,maxOutputSize:268435456,maxFileDescriptors:4096,maxSourceDepth:100},cd={...za,maxSourceBytes:8*1024*1024,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,maxJsBridgeRequests:1e5,maxExtensionCleanupTimeMs:25,maxGlobOperations:1e5,maxStringLength:10*1024*1024,maxArrayElements:1e5,maxHeredocSize:10*1024*1024,maxBraceExpansionResults:1e4,maxOutputSize:10*1024*1024,maxFileDescriptors:1024,maxQueryTokens:25e3,maxQueryDepth:256,maxQueryElements:1e5,maxAwkParserTokens:25e3,maxAwkParserDepth:128,maxAwkParserOperations:1e5,maxCsvRows:1e5,maxCsvCells:1e6,maxWorkUnits:1e5,maxTraversalEntries:1e5,maxTraversalDepth:256,maxTraversalWork:1e5,maxLiveBytes:64*1024*1024,maxInputBytes:32*1024*1024,maxFileSystemBytes:128*1024*1024,maxDatabaseBytes:64*1024*1024,maxDatabaseResultBytes:16*1024*1024,maxArchiveBytes:128*1024*1024,maxArchiveCompressedBytes:64*1024*1024,maxArchiveEntryBytes:64*1024*1024,maxArchiveEntries:1e5,maxWorkerMessageBytes:16*1024*1024,maxExecutionTimeMs:3e4};function qr(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?cd:za;if(!e)return{...n};let r={maxSourceBytes:e.maxSourceBytes??n.maxSourceBytes,maxExecDepth:e.maxExecDepth??n.maxExecDepth,maxCallDepth:e.maxCallDepth??n.maxCallDepth,maxCommandCount:e.maxCommandCount??n.maxCommandCount,maxLoopIterations:e.maxLoopIterations??n.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??n.maxAwkIterations,maxSedIterations:e.maxSedIterations??n.maxSedIterations,maxJqIterations:e.maxJqIterations??n.maxJqIterations,maxQueryTokens:e.maxQueryTokens??n.maxQueryTokens,maxQueryDepth:e.maxQueryDepth??n.maxQueryDepth,maxQueryElements:e.maxQueryElements??n.maxQueryElements,maxAwkParserTokens:e.maxAwkParserTokens??n.maxAwkParserTokens,maxAwkParserDepth:e.maxAwkParserDepth??n.maxAwkParserDepth,maxAwkParserOperations:e.maxAwkParserOperations??n.maxAwkParserOperations,maxCsvRows:e.maxCsvRows??n.maxCsvRows,maxCsvCells:e.maxCsvCells??n.maxCsvCells,maxWorkUnits:e.maxWorkUnits??n.maxWorkUnits,maxTraversalEntries:e.maxTraversalEntries??n.maxTraversalEntries,maxTraversalDepth:e.maxTraversalDepth??n.maxTraversalDepth,maxTraversalWork:e.maxTraversalWork??n.maxTraversalWork,maxLiveBytes:e.maxLiveBytes??n.maxLiveBytes,maxInputBytes:e.maxInputBytes??n.maxInputBytes,maxFileSystemBytes:e.maxFileSystemBytes??n.maxFileSystemBytes,maxDatabaseBytes:e.maxDatabaseBytes??n.maxDatabaseBytes,maxDatabaseResultBytes:e.maxDatabaseResultBytes??n.maxDatabaseResultBytes,maxArchiveBytes:e.maxArchiveBytes??n.maxArchiveBytes,maxArchiveCompressedBytes:e.maxArchiveCompressedBytes??n.maxArchiveCompressedBytes,maxArchiveEntryBytes:e.maxArchiveEntryBytes??n.maxArchiveEntryBytes,maxArchiveEntries:e.maxArchiveEntries??n.maxArchiveEntries,maxWorkerMessageBytes:e.maxWorkerMessageBytes??n.maxWorkerMessageBytes,maxExecutionTimeMs:e.maxExecutionTimeMs??n.maxExecutionTimeMs,maxExtensionCleanupTimeMs:e.maxExtensionCleanupTimeMs??n.maxExtensionCleanupTimeMs,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??n.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??n.maxPythonTimeoutMs,maxJsTimeoutMs:e.maxJsTimeoutMs??n.maxJsTimeoutMs,maxJsBridgeRequests:e.maxJsBridgeRequests??n.maxJsBridgeRequests,maxGlobOperations:e.maxGlobOperations??n.maxGlobOperations,maxStringLength:e.maxStringLength??n.maxStringLength,maxArrayElements:e.maxArrayElements??n.maxArrayElements,maxHeredocSize:e.maxHeredocSize??n.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??n.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??n.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??n.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??n.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??n.maxSourceDepth};for(let s of Object.keys(r)){let i=r[s];if(i!==Number.POSITIVE_INFINITY&&(!Number.isSafeInteger(i)||i<0))throw new RangeError(`${s} must be a non-negative safe integer or positive Infinity`)}return r}function ud(e){let{executionLimits:t,executionLimitProfile:n,fs:r,stdin:s=li,...i}=e;return{fs:r,fsIdentity:i.fsIdentity??jr(r),cwd:"/",env:new Map,stdin:s,limits:qr(t,n),...i}}function Ua(e){return"load"in e&&typeof e.load=="function"}function fd(e,t,n={}){return{name:e,trusted:n.trusted!==!1,execute:t}}function ja(e){let t=null,n=!1,r=new Set,s=a=>{t=a;for(let l of r)l.resolve(a);r.clear()},i=a=>{n=!1;for(let l of r)l.reject(a);r.clear()},o=()=>{n=!0;let a;try{a=Promise.resolve(e.load())}catch(l){i(l);return}Da.call(a,s,i)};return{name:e.name,trusted:e.trusted!==!1,async execute(a,l){if(!t){let u,f=new Promise((d,h)=>{u={resolve:d,reject:h},r.add(u)});n||o();try{t=await or(f,l.signal,`bash: ${e.name} was cancelled before it started
|
|
5
|
+
`)}finally{u&&r.delete(u)}}let c=t;if(!c)throw new Error(`Failed to load command: ${e.name}`);return c.execute(a,l)}}}var qa=Object.freeze(Object.create(null)),Gr=class{limits;signal;commandCount=0;workUnits=0;liveBytes=0;inputBytes=0;outputBytes=0;countersByKind=new Map;bytesByKind=new Map;depthByKind=new Map;cleanupCallbacks=[];poisoned;closed=!1;startedAt=Date.now();get remainingLiveBytes(){return Math.max(0,this.limits.maxLiveBytes-this.liveBytes)}get outputBytesUsed(){return this.outputBytes}constructor(t,n=void 0){this.limits=t,this.signal=n}fail(t){throw this.poisoned??=t,this.poisoned}poisonAfterAbort(t){this.poisoned??=t}assertUsable(){if(this.poisoned)throw this.poisoned;if(this.closed)throw new Error("execution budget is already closed");this.throwIfAborted()}chargeCommand(){return this.consume("commands",1,"execution")}consumeWork(t=1,n="execution"){return this.consume("work",t,n)}consumeLimited(t,n,r,s=t){this.assertUsable();let i=this.countersByKind.get(t)??0;return(!Number.isSafeInteger(n)||n<0||!Number.isSafeInteger(r)||r<0||n>r-i)&&this.fail(new C(`${s}: ${t} work limit exceeded (${r})`,"iterations")),n>this.limits.maxWorkUnits-this.workUnits&&this.fail(new C(`${s}: aggregate work limit exceeded (${this.limits.maxWorkUnits})`,"iterations")),this.countersByKind.set(t,i+n),this.workUnits+=n,i+n}consumeInput(t,n="execution"){return this.assertUsable(),(!Number.isSafeInteger(t)||t<0||t>this.limits.maxInputBytes-this.inputBytes)&&this.fail(new C(`${n}: aggregate input size limit exceeded (${this.limits.maxInputBytes} bytes)`,"string_length")),this.inputBytes+=t,this.inputBytes}consume(t,n=1,r=t){this.assertUsable();let s=this.countersByKind.get(t)??0,i=t==="commands"?this.commandCount:this.workUnits,o=t==="commands"?this.limits.maxCommandCount:this.limits.maxWorkUnits;(!Number.isSafeInteger(n)||n<0||n>o-i)&&this.fail(new C(t==="commands"?`too many commands executed (>${o}), increase executionLimits.maxCommandCount`:`${r}: ${t} work limit exceeded (${o})`,t==="commands"?"commands":"iterations"));let a=i+n;return t==="commands"?this.commandCount=a:this.workUnits=a,this.countersByKind.set(t,s+n),a}reserveBytes(t,n,r){this.assertUsable();let s=typeof t=="string"?t:"live",i=typeof t=="string"?n:t,o=typeof t=="string"?r??s:n??"execution";(!Number.isSafeInteger(i)||i<0||i>this.limits.maxLiveBytes-this.liveBytes)&&this.fail(new C(`${o}: live byte limit exceeded (${this.limits.maxLiveBytes} bytes)`,"string_length")),this.liveBytes+=i,this.bytesByKind.set(s,(this.bytesByKind.get(s)??0)+i);let a=!1;return{release:()=>{if(a)return;a=!0,this.liveBytes-=i;let l=(this.bytesByKind.get(s)??i)-i;l<=0?this.bytesByKind.delete(s):this.bytesByKind.set(s,l)}}}appendOutput(t,n,r="execution",s=0,i="text"){this.assertUsable();let o=i==="bytes"?n.length:V(n);(!Number.isSafeInteger(s)||s<0||s>o)&&this.fail(new C(`${r}: invalid ${t} accounting`,"output_size"));let a=o-s;return a>this.limits.maxOutputSize-this.outputBytes&&this.fail(new C(`${r}: total output size exceeded (>${this.limits.maxOutputSize} bytes), increase executionLimits.maxOutputSize`,"output_size")),this.outputBytes+=a,o}accountResult(t,n="execution",r=Number.POSITIVE_INFINITY){let s=t.internalOutputAccounting,i=Math.min(s?.stdout??0,r),o=Math.min(s?.stderr??0,Math.max(0,r-i)),a=this.appendOutput("stdout",t.stdout,n,i,t.stdoutKind==="bytes"||t.stdoutEncoding==="binary"?"bytes":"text"),l=this.appendOutput("stderr",t.stderr,n,o);return Object.isExtensible(t)?(t.internalOutputAccounting={stdout:a,stderr:l},t):a===0&&l===0?t:{...t,internalOutputAccounting:{stdout:a,stderr:l}}}relinquishOutput(t,n,r){this.assertUsable(),r!==qa&&this.fail(new C(`${n}: unauthorized output accounting release`,"output_size")),(!Number.isSafeInteger(t)||t<0||t>this.outputBytes)&&this.fail(new C(`${n}: invalid output accounting release`,"output_size")),this.outputBytes-=t}enterDepth(t,n=this.limits.maxCallDepth,r){this.assertUsable();let s=typeof n=="number"?n:this.limits.maxCallDepth,i=typeof n=="string"?n:r??t,o=this.depthByKind.get(t)??0;o>=s&&this.fail(new C(`${i}: maximum depth (${s}) exceeded`,"recursion")),this.depthByKind.set(t,o+1);let a=!1;return{release:()=>{if(a)return;a=!0;let l=(this.depthByKind.get(t)??1)-1;l<=0?this.depthByKind.delete(t):this.depthByKind.set(t,l)}}}throwIfAborted(t="execution"){this.signal?.aborted&&this.fail(new Ue("",`bash: ${t} aborted
|
|
6
6
|
`)),Date.now()-this.startedAt>this.limits.maxExecutionTimeMs&&this.fail(new Ue("",`bash: ${t} exceeded execution deadline (${this.limits.maxExecutionTimeMs}ms)
|
|
7
|
-
`))}remainingTimeMs(){return Math.max(0,this.limits.maxExecutionTimeMs-(Date.now()-this.startedAt))}registerCleanup(t){this.assertUsable(),this.cleanupCallbacks.push(t);let n=!0;return()=>{if(!n)return;n=!1;let r=this.cleanupCallbacks.indexOf(t);r>=0&&this.cleanupCallbacks.splice(r,1)}}async close(){if(this.closed)return;this.closed=!0;let t=[],n=Date.now()+this.limits.maxExtensionCleanupTimeMs;for(let r=this.cleanupCallbacks.length-1;r>=0;r--)try{let s=n-Date.now();if(s<=0){t.push(new Error("execution cleanup grace period exceeded"));break}let i,o=await Promise.race([Promise.resolve().then(this.cleanupCallbacks[r]).then(()=>({ok:!0}),a=>({ok:!1,error:a})),new Promise(a=>{i=nr(()=>a({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(rr(i),!o.ok&&(t.push(o.error),Date.now()>=n))break}catch(s){t.push(s)}if(this.cleanupCallbacks.length=0,this.depthByKind.clear(),this.bytesByKind.clear(),this.liveBytes=0,t.length>0)throw new AggregateError(t,"execution cleanup failed")}assertExecDepth(t){this.assertUsable(),t>this.limits.maxExecDepth&&this.fail(new $(`maximum nested execution depth (${this.limits.maxExecDepth}) exceeded`,"recursion"))}};function za(e){let t=Object.create(null);return Object.defineProperties(t,{remainingLiveBytes:{enumerable:!0,get:()=>e.remainingLiveBytes},consumeWork:{enumerable:!0,value:e.consumeWork.bind(e)},consumeLimited:{enumerable:!0,value:e.consumeLimited.bind(e)},consumeInput:{enumerable:!0,value:e.consumeInput.bind(e)},reserveBytes:{enumerable:!0,value:e.reserveBytes.bind(e)},enterDepth:{enumerable:!0,value:e.enterDepth.bind(e)},throwIfAborted:{enumerable:!0,value:e.throwIfAborted.bind(e)},remainingTimeMs:{enumerable:!0,value:e.remainingTimeMs.bind(e)},registerCleanup:{enumerable:!0,value:e.registerCleanup.bind(e)}}),Object.freeze(t)}function Ua(e,t,n="pipeline"){e.relinquishOutput(t,n,Va)}var bn=new TextEncoder;function od(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var gt=class{data=new Map;entryIdentities=new WeakMap;nextEntryIdentity=1;maxTotalBytes;retainedBytes=0;contentReferences=new WeakMap;materializedContent(t){return t?.type==="file"&&"content"in t?t.content:null}storedByteLength(t){return t===null?0:t instanceof Uint8Array?t.byteLength:M(t)}wouldReleaseBytes(t){let n=this.materializedContent(t);return n===null?0:n instanceof Uint8Array?this.contentReferences.get(n)===1?n.byteLength:0:this.storedByteLength(n)}assertCanAllocate(t,n){let r=this.wouldReleaseBytes(this.data.get(t));if(!Number.isSafeInteger(n)||n<0||n>this.maxTotalBytes-this.retainedBytes+r)throw new Error(`ENOSPC: in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`)}setEntry(t,n){let r=this.data.get(t),s=this.materializedContent(r),i=this.materializedContent(n);if(s===i){this.data.set(t,n);return}let o=this.wouldReleaseBytes(r),a=i instanceof Uint8Array?this.contentReferences.has(i)?0:i.byteLength:this.storedByteLength(i);if(a>this.maxTotalBytes-this.retainedBytes+o)throw new Error(`ENOSPC: in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`);if(s instanceof Uint8Array){let l=this.contentReferences.get(s)??0;l<=1?this.contentReferences.delete(s):this.contentReferences.set(s,l-1)}i instanceof Uint8Array&&this.contentReferences.set(i,(this.contentReferences.get(i)??0)+1),this.retainedBytes+=a-o,this.data.set(t,n)}deleteEntry(t){let n=this.data.get(t);if(!n)return!1;let r=this.materializedContent(n),s=this.wouldReleaseBytes(n);if(r instanceof Uint8Array){let i=this.contentReferences.get(r)??0;i<=1?this.contentReferences.delete(r):this.contentReferences.set(r,i-1)}return this.retainedBytes-=s,this.data.delete(t)}contentByteLength(t,n){if(t instanceof Uint8Array)return t.byteLength;if(n==="hex")return Math.floor(t.length/2);if(n==="base64"){let r=t.endsWith("==")?2:t.endsWith("=")?1:0;return Math.max(0,Math.floor(t.length*3/4)-r)}return n==="binary"||n==="latin1"?t.length:M(t)}identityFor(t){let n=this.entryIdentities.get(t);return n||(n=`memfs:${this.nextEntryIdentity++}`,this.entryIdentities.set(t,n)),n}constructor(t,n={}){if(this.maxTotalBytes=n.maxTotalBytes??1024*1024*1024,!Number.isSafeInteger(this.maxTotalBytes)||this.maxTotalBytes<0)throw new Error("InMemoryFs: invalid maxTotalBytes");if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[r,s]of Object.entries(t))typeof s=="function"?this.writeFileLazy(r,s):od(s)?this.writeFileSync(r,s.content,void 0,{mode:s.mode,mtime:s.mtime}):this.writeFileSync(r,s)}ensureParentDirs(t){let n=yt(t);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,n,r,s){z(t,"write");let i=W(t);this.ensureParentDirs(i);let o=ot(r);this.assertCanAllocate(i,this.contentByteLength(n,o));let a=Ft(n,o);this.setEntry(i,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}writeFileLazy(t,n,r){z(t,"write");let s=W(t);this.ensureParentDirs(s),this.setEntry(s,{type:"file",lazy:n,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,n){let r=await Ce.runTrustedAsync(async()=>n.lazy()),s=typeof r=="string"?bn.encode(r):r,i={type:"file",content:s,mode:n.mode,mtime:n.mtime};return this.assertCanAllocate(t,s.byteLength),this.setEntry(t,i),i}async readFile(t,n){let r=await this.readFileBuffer(t),s=ot(n);return Mt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Mt(n,"binary")}async readFileBuffer(t){z(t,"open");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in r){let s=await this.materializeLazy(n,r);return s.content instanceof Uint8Array?s.content:bn.encode(s.content)}return r.content instanceof Uint8Array?r.content:bn.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){z(t,"append");let s=W(t),i=this.data.get(s);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=ot(r),a=this.contentByteLength(n,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(s,l));let c="content"in l&&l.content instanceof Uint8Array?l.content:bn.encode("content"in l?l.content:"");this.assertCanAllocate(s,c.byteLength+a);let u=Ft(n,o),f=new Uint8Array(c.length+u.length);f.set(c),f.set(u,c.length),this.setEntry(s,{type:"file",content:f,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,n,r)}async exists(t){if(t.includes("\0"))return!1;try{let n=this.resolvePathWithSymlinks(t);return this.data.has(n)}catch{return!1}}async stat(t){z(t,"stat");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=bn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}async lstat(t){z(t,"lstat");let n=this.resolveIntermediateSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=bn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}resolveIntermediateSymlinks(t){let n=W(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];s=`${s}/${a}`;let l=this.data.get(s),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(s),s=Ln(s,l.target),l=this.data.get(s),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let n=W(t);if(n==="/")return"/";let r=n.slice(1).split("/"),s="",i=new Set;for(let o of r){s=`${s}/${o}`;let a=this.data.get(s),l=0,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(s),s=Ln(s,a.target),a=this.data.get(s),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return s}async mkdir(t,n){this.mkdirSync(t,n)}async createExclusive(t,n){let r=n.directory?"mkdir":"open";z(t,n.directory?"mkdir":"write");let s=W(t),i=yt(s),o=i==="/"?"/":this.resolvePathWithSymlinks(i),a=it(o,s.slice(s.lastIndexOf("/")+1));if(this.data.has(a))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);if(o!=="/"){let l=this.data.get(o);if(!l)throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);if(l.type!=="directory")throw new Error(`ENOTDIR: not a directory, ${r} '${t}'`)}if(n.directory){this.setEntry(a,{type:"directory",mode:n.mode,mtime:new Date});return}this.assertCanAllocate(a,0),this.setEntry(a,{type:"file",content:new Uint8Array(0),mode:n.mode,mtime:new Date})}mkdirSync(t,n){z(t,"mkdir");let r=W(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let s=yt(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){z(t,"scandir");let n=W(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let s=new Set;for(;r&&r.type==="symlink";){if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(n),n=Ln(n,r.target),r=this.data.get(n)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=n==="/"?"/":`${n}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==n&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,n){z(t,"rm");let r=W(t),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(s.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=it(r,o);await this.rm(a,n)}}}this.deleteEntry(r)}async cp(t,n,r){z(t,"cp"),z(n,"cp");let s=W(t),i=W(n),o=this.data.get(s);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")if(this.ensureParentDirs(i),"content"in o){let a=o.content instanceof Uint8Array?o.content.byteLength:bn.encode(o.content).byteLength;this.assertCanAllocate(i,a);let l=o.content instanceof Uint8Array?new Uint8Array(o.content):o.content;this.setEntry(i,{...o,content:l})}else this.setEntry(i,{...o});else if(o.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(Lt(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(s);for(let l of a){let c=it(s,l),u=it(i,l);await this.cp(c,u,r)}}}async mv(t,n){z(t,"mv"),z(n,"mv");let r=W(t),s=W(n);if(r===s)return;let i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(i.type==="directory"&&Lt(r,s))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);if(i.type==="directory"){await this.mkdir(s,{recursive:!0});let o=await this.readdir(r);for(let a of o)await this.mv(it(r,a),it(s,a));this.deleteEntry(r);return}this.ensureParentDirs(s),this.setEntry(s,i),this.deleteEntry(r)}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,n){return Ht(t,n)}async chmod(t,n){z(t,"chmod");let r=W(t),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);s.mode=n}async symlink(t,n){z(n,"symlink");let r=W(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,n){z(t,"link"),z(n,"link");let r=W(t),s=W(n),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let o=i;"lazy"in o&&(o=await this.materializeLazy(r,o)),this.ensureParentDirs(s);let a={type:"file",content:o.content,mode:o.mode,mtime:o.mtime};this.entryIdentities.set(a,this.identityFor(o)),this.setEntry(s,a)}async readlink(t){z(t,"readlink");let n=W(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){z(t,"realpath");let n=this.resolvePathWithSymlinks(t);if(!this.data.has(n))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return n}async utimes(t,n,r){z(t,"utimes");let s=W(t),i=this.resolvePathWithSymlinks(s),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=r}};var ja="5.1.0(1)-release",qa="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function ci(e){let{pid:t,ppid:n,uid:r,gid:s}=e;return`Name: bash
|
|
7
|
+
`))}remainingTimeMs(){return Math.max(0,this.limits.maxExecutionTimeMs-(Date.now()-this.startedAt))}registerCleanup(t){this.assertUsable(),this.cleanupCallbacks.push(t);let n=!0;return()=>{if(!n)return;n=!1;let r=this.cleanupCallbacks.indexOf(t);r>=0&&this.cleanupCallbacks.splice(r,1)}}async close(){if(this.closed)return;this.closed=!0;let t=[],n=Date.now()+this.limits.maxExtensionCleanupTimeMs;for(let r=this.cleanupCallbacks.length-1;r>=0;r--)try{let s=n-Date.now();if(s<=0){t.push(new Error("execution cleanup grace period exceeded"));break}let i,o=await Promise.race([Promise.resolve().then(this.cleanupCallbacks[r]).then(()=>({ok:!0}),a=>({ok:!1,error:a})),new Promise(a=>{i=rr(()=>a({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(sr(i),!o.ok&&(t.push(o.error),Date.now()>=n))break}catch(s){t.push(s)}if(this.cleanupCallbacks.length=0,this.depthByKind.clear(),this.bytesByKind.clear(),this.liveBytes=0,t.length>0)throw new AggregateError(t,"execution cleanup failed")}assertExecDepth(t){this.assertUsable(),t>this.limits.maxExecDepth&&this.fail(new C(`maximum nested execution depth (${this.limits.maxExecDepth}) exceeded`,"recursion"))}};function Ga(e){let t=Object.create(null);return Object.defineProperties(t,{remainingLiveBytes:{enumerable:!0,get:()=>e.remainingLiveBytes},consumeWork:{enumerable:!0,value:e.consumeWork.bind(e)},consumeLimited:{enumerable:!0,value:e.consumeLimited.bind(e)},consumeInput:{enumerable:!0,value:e.consumeInput.bind(e)},reserveBytes:{enumerable:!0,value:e.reserveBytes.bind(e)},enterDepth:{enumerable:!0,value:e.enterDepth.bind(e)},throwIfAborted:{enumerable:!0,value:e.throwIfAborted.bind(e)},remainingTimeMs:{enumerable:!0,value:e.remainingTimeMs.bind(e)},registerCleanup:{enumerable:!0,value:e.registerCleanup.bind(e)}}),Object.freeze(t)}function Ha(e,t,n="pipeline"){e.relinquishOutput(t,n,qa)}var bn=new TextEncoder;function dd(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var yt=class{data=new Map;entryIdentities=new WeakMap;nextEntryIdentity=1;maxTotalBytes;retainedBytes=0;contentReferences=new WeakMap;materializedContent(t){return t?.type==="file"&&"content"in t?t.content:null}storedByteLength(t){return t===null?0:t instanceof Uint8Array?t.byteLength:V(t)}wouldReleaseBytes(t){let n=this.materializedContent(t);return n===null?0:n instanceof Uint8Array?this.contentReferences.get(n)===1?n.byteLength:0:this.storedByteLength(n)}assertCanAllocate(t,n){let r=this.wouldReleaseBytes(this.data.get(t));if(!Number.isSafeInteger(n)||n<0||n>this.maxTotalBytes-this.retainedBytes+r)throw new Error(`ENOSPC: in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`)}setEntry(t,n){let r=this.data.get(t),s=this.materializedContent(r),i=this.materializedContent(n);if(s===i){this.data.set(t,n);return}let o=this.wouldReleaseBytes(r),a=i instanceof Uint8Array?this.contentReferences.has(i)?0:i.byteLength:this.storedByteLength(i);if(a>this.maxTotalBytes-this.retainedBytes+o)throw new Error(`ENOSPC: in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`);if(s instanceof Uint8Array){let l=this.contentReferences.get(s)??0;l<=1?this.contentReferences.delete(s):this.contentReferences.set(s,l-1)}i instanceof Uint8Array&&this.contentReferences.set(i,(this.contentReferences.get(i)??0)+1),this.retainedBytes+=a-o,this.data.set(t,n)}deleteEntry(t){let n=this.data.get(t);if(!n)return!1;let r=this.materializedContent(n),s=this.wouldReleaseBytes(n);if(r instanceof Uint8Array){let i=this.contentReferences.get(r)??0;i<=1?this.contentReferences.delete(r):this.contentReferences.set(r,i-1)}return this.retainedBytes-=s,this.data.delete(t)}contentByteLength(t,n){if(t instanceof Uint8Array)return t.byteLength;if(n==="hex")return Math.floor(t.length/2);if(n==="base64"){let r=t.endsWith("==")?2:t.endsWith("=")?1:0;return Math.max(0,Math.floor(t.length*3/4)-r)}return n==="binary"||n==="latin1"?t.length:V(t)}identityFor(t){let n=this.entryIdentities.get(t);return n||(n=`memfs:${this.nextEntryIdentity++}`,this.entryIdentities.set(t,n)),n}constructor(t,n={}){if(this.maxTotalBytes=n.maxTotalBytes??1024*1024*1024,!Number.isSafeInteger(this.maxTotalBytes)||this.maxTotalBytes<0)throw new Error("InMemoryFs: invalid maxTotalBytes");if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[r,s]of Object.entries(t))typeof s=="function"?this.writeFileLazy(r,s):dd(s)?this.writeFileSync(r,s.content,void 0,{mode:s.mode,mtime:s.mtime}):this.writeFileSync(r,s)}ensureParentDirs(t){let n=mt(t);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,n,r,s){q(t,"write");let i=j(t);this.ensureParentDirs(i);let o=it(r);this.assertCanAllocate(i,this.contentByteLength(n,o));let a=Ft(n,o);this.setEntry(i,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}writeFileLazy(t,n,r){q(t,"write");let s=j(t);this.ensureParentDirs(s),this.setEntry(s,{type:"file",lazy:n,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,n){let r=await Ce.runTrustedAsync(async()=>n.lazy()),s=typeof r=="string"?bn.encode(r):r,i={type:"file",content:s,mode:n.mode,mtime:n.mtime};return this.assertCanAllocate(t,s.byteLength),this.setEntry(t,i),i}async readFile(t,n){let r=await this.readFileBuffer(t),s=it(n);return Mt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Mt(n,"binary")}async readFileBuffer(t){q(t,"open");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in r){let s=await this.materializeLazy(n,r);return s.content instanceof Uint8Array?s.content:bn.encode(s.content)}return r.content instanceof Uint8Array?r.content:bn.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){q(t,"append");let s=j(t),i=this.data.get(s);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=it(r),a=this.contentByteLength(n,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(s,l));let c="content"in l&&l.content instanceof Uint8Array?l.content:bn.encode("content"in l?l.content:"");this.assertCanAllocate(s,c.byteLength+a);let u=Ft(n,o),f=new Uint8Array(c.length+u.length);f.set(c),f.set(u,c.length),this.setEntry(s,{type:"file",content:f,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,n,r)}async exists(t){if(t.includes("\0"))return!1;try{let n=this.resolvePathWithSymlinks(t);return this.data.has(n)}catch{return!1}}async stat(t){q(t,"stat");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=bn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}async lstat(t){q(t,"lstat");let n=this.resolveIntermediateSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=bn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}resolveIntermediateSymlinks(t){let n=j(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];s=`${s}/${a}`;let l=this.data.get(s),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(s),s=Fn(s,l.target),l=this.data.get(s),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let n=j(t);if(n==="/")return"/";let r=n.slice(1).split("/"),s="",i=new Set;for(let o of r){s=`${s}/${o}`;let a=this.data.get(s),l=0,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(s),s=Fn(s,a.target),a=this.data.get(s),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return s}async mkdir(t,n){this.mkdirSync(t,n)}async createExclusive(t,n){let r=n.directory?"mkdir":"open";q(t,n.directory?"mkdir":"write");let s=j(t),i=mt(s),o=i==="/"?"/":this.resolvePathWithSymlinks(i),a=st(o,s.slice(s.lastIndexOf("/")+1));if(this.data.has(a))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);if(o!=="/"){let l=this.data.get(o);if(!l)throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);if(l.type!=="directory")throw new Error(`ENOTDIR: not a directory, ${r} '${t}'`)}if(n.directory){this.setEntry(a,{type:"directory",mode:n.mode,mtime:new Date});return}this.assertCanAllocate(a,0),this.setEntry(a,{type:"file",content:new Uint8Array(0),mode:n.mode,mtime:new Date})}mkdirSync(t,n){q(t,"mkdir");let r=j(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let s=mt(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){q(t,"scandir");let n=j(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let s=new Set;for(;r&&r.type==="symlink";){if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(n),n=Fn(n,r.target),r=this.data.get(n)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=n==="/"?"/":`${n}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==n&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,n){q(t,"rm");let r=j(t),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(s.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=st(r,o);await this.rm(a,n)}}}this.deleteEntry(r)}async cp(t,n,r){q(t,"cp"),q(n,"cp");let s=j(t),i=j(n),o=this.data.get(s);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")if(this.ensureParentDirs(i),"content"in o){let a=o.content instanceof Uint8Array?o.content.byteLength:bn.encode(o.content).byteLength;this.assertCanAllocate(i,a);let l=o.content instanceof Uint8Array?new Uint8Array(o.content):o.content;this.setEntry(i,{...o,content:l})}else this.setEntry(i,{...o});else if(o.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(Lt(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(s);for(let l of a){let c=st(s,l),u=st(i,l);await this.cp(c,u,r)}}}async mv(t,n){q(t,"mv"),q(n,"mv");let r=j(t),s=j(n);if(r===s)return;let i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(i.type==="directory"&&Lt(r,s))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);if(i.type==="directory"){await this.mkdir(s,{recursive:!0});let o=await this.readdir(r);for(let a of o)await this.mv(st(r,a),st(s,a));this.deleteEntry(r);return}this.ensureParentDirs(s),this.setEntry(s,i),this.deleteEntry(r)}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,n){return Ht(t,n)}async chmod(t,n){q(t,"chmod");let r=j(t),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);s.mode=n}async symlink(t,n){q(n,"symlink");let r=j(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,n){q(t,"link"),q(n,"link");let r=j(t),s=j(n),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let o=i;"lazy"in o&&(o=await this.materializeLazy(r,o)),this.ensureParentDirs(s);let a={type:"file",content:o.content,mode:o.mode,mtime:o.mtime};this.entryIdentities.set(a,this.identityFor(o)),this.setEntry(s,a)}async readlink(t){q(t,"readlink");let n=j(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){q(t,"realpath");let n=this.resolvePathWithSymlinks(t);if(!this.data.has(n))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return n}async utimes(t,n,r){q(t,"utimes");let s=j(t),i=this.resolvePathWithSymlinks(s),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=r}};var Za="5.1.0(1)-release",Qa="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function hi(e){let{pid:t,ppid:n,uid:r,gid:s}=e;return`Name: bash
|
|
8
8
|
State: R (running)
|
|
9
9
|
Pid: ${t}
|
|
10
10
|
PPid: ${n}
|
|
11
11
|
Uid: ${r} ${r} ${r} ${r}
|
|
12
12
|
Gid: ${s} ${s} ${s} ${s}
|
|
13
|
-
`}function
|
|
13
|
+
`}function hd(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function pd(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 md(e){e.mkdirSync("/dev",{recursive:!0}),e.mkdirSync("/dev/fd",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function yd(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Qa}
|
|
14
14
|
`),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
|
|
15
|
-
`),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>ci(t)):e.writeFileSync("/proc/self/status",ci(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function Ga(e,t,n={pid:1,ppid:0,uid:1e3,gid:1e3}){if(ad(e)){let r=fd(e);ld(r,t),cd(r),ud(r,n)}}function fd(e){let t=r=>{try{r()}catch(s){if(!(s instanceof Error&&s.message.startsWith("ENOSYS")))throw s}},n={mkdirSync:(r,s)=>t(()=>e.mkdirSync(r,s)),writeFileSync:(r,s)=>t(()=>e.writeFileSync(r,s))};return e.writeFileLazy&&(n.writeFileLazy=(r,s)=>t(()=>e.writeFileLazy?.(r,s))),n}var Kt=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new gt,t?.mounts)for(let{mountPoint:n,filesystem:r}of t.mounts)this.mount(n,r)}mount(t,n){this.validateMountPath(t);let r=W(t);this.validateMount(r),this.mounts.set(r,n)}unmount(t){let n=W(t);if(!this.mounts.has(n))throw new Error(`No filesystem mounted at '${t}'`);this.mounts.delete(n)}getMounts(){return Array.from(this.mounts,([t,n])=>({mountPoint:t,filesystem:n}))}isMountPoint(t){let n=W(t);return this.mounts.has(n)}validateMountPath(t){let n=t.split("/");for(let r of n)if(r==="."||r==="..")throw new Error(`Invalid mount point '${t}': contains '.' or '..' segments`)}validateMount(t){if(t==="/")throw new Error("Cannot mount at root '/'");for(let n of this.mounts.keys())if(n!==t){if(t.startsWith(`${n}/`))throw new Error(`Cannot mount at '${t}': inside existing mount '${n}'`);if(n.startsWith(`${t}/`))throw new Error(`Cannot mount at '${t}': would contain existing mount '${n}'`)}}routePath(t){z(t,"access");let n=W(t);for(let[r,s]of this.mounts){if(n===r)return{fs:s,relativePath:"/"};if(n.startsWith(`${r}/`))return{fs:s,relativePath:n.slice(r.length)}}return{fs:this.baseFs,relativePath:n}}getChildMountPoints(t){let n=W(t),r=n==="/"?"/":`${n}/`,s=[];for(let i of this.mounts.keys())if(i.startsWith(r)){let a=i.slice(r.length).split("/")[0];a&&!s.includes(a)&&s.push(a)}return s}async readFile(t,n){let{fs:r,relativePath:s}=this.routePath(t);return r.readFile(s,n)}async readFileBytes(t){let{fs:n,relativePath:r}=this.routePath(t);return In(n,r)}async readFileBuffer(t){let{fs:n,relativePath:r}=this.routePath(t);return n.readFileBuffer(r)}async writeFile(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.writeFile(i,n,r)}async appendFile(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.appendFile(i,n,r)}async exists(t){let n=W(t);if(this.mounts.has(n)||this.getChildMountPoints(n).length>0)return!0;let{fs:s,relativePath:i}=this.routePath(t);return s.exists(i)}async stat(t){let n=W(t),r=this.mounts.get(n);if(r)try{return await r.stat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(n).length>0)try{return await this.baseFs.stat(n)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.stat(o)}async lstat(t){let n=W(t),r=this.mounts.get(n);if(r)try{return await r.lstat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(n).length>0)try{return await this.baseFs.lstat(n)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.lstat(o)}async mkdir(t,n){let r=W(t);if(this.mounts.has(r)){if(n?.recursive)return;throw new Error(`EEXIST: directory already exists, mkdir '${t}'`)}if(this.getChildMountPoints(r).length>0&&n?.recursive)return;let{fs:i,relativePath:o}=this.routePath(t);return i.mkdir(o,n)}async createExclusive(t,n){let r=W(t),s=n.directory?"mkdir":"open";if(this.mounts.has(r))throw new Error(`EEXIST: file already exists, ${s} '${t}'`);let{fs:i,relativePath:o}=this.routePath(t);if(!i.createExclusive)throw new xa(t,s);let a=yt(o);return a!=="/"&&this.getChildMountPoints(yt(r)).length>0&&!await i.exists(a)&&await i.mkdir(a,{recursive:!0}),i.createExclusive(o,n)}mkdirSync(t,n){let{fs:r,relativePath:s}=this.routePath(t),i=r;if(!i.mkdirSync)throw new Error(`ENOSYS: function not implemented, mkdir '${t}'`);i.mkdirSync(s,n)}writeFileSync(t,n){let{fs:r,relativePath:s}=this.routePath(t),i=r;if(!i.writeFileSync)throw new Error(`ENOSYS: function not implemented, write '${t}'`);i.writeFileSync(s,n)}async readdir(t){let n=W(t),r=new Set,s=null,{fs:i,relativePath:o}=this.routePath(t);try{let l=await i.readdir(o);for(let c of l)r.add(c)}catch(l){let c=l.code,u=l.message||"";if(c!=="ENOENT"&&!u.includes("ENOENT"))throw l;s=l}let a=this.getChildMountPoints(n);for(let l of a)r.add(l);if(r.size===0&&s&&!this.mounts.has(n))throw s;return Array.from(r).sort()}async rm(t,n){let r=W(t);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot remove '${t}'`);if(this.getChildMountPoints(r).length>0)throw new Error(`EBUSY: contains mount points, cannot remove '${t}'`);let{fs:i,relativePath:o}=this.routePath(t);return i.rm(o,n)}async cp(t,n,r){if((await this.stat(t)).isDirectory&&Lt(t,n))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);let i=this.routePath(t),o=this.routePath(n);return i.fs===o.fs?i.fs.cp(i.relativePath,o.relativePath,r):this.crossMountCopy(t,n,r)}async mv(t,n){let r=W(t);if((await this.stat(t)).isDirectory&&Lt(t,n))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot move '${t}'`);let i=this.routePath(t),o=this.routePath(n);if(i.fs===o.fs)return i.fs.mv(i.relativePath,o.relativePath);await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return Ht(t,n)}getAllPaths(){let t=new Set;for(let n of this.baseFs.getAllPaths())t.add(n);for(let[n,r]of this.mounts){let s=n.split("/").filter(Boolean),i="";for(let o of s)i=`${i}/${o}`,t.add(i);for(let o of r.getAllPaths())o==="/"?t.add(n):t.add(`${n}${o}`)}return Array.from(t).sort()}async chmod(t,n){let r=W(t),s=this.mounts.get(r);if(s)return s.chmod("/",n);let{fs:i,relativePath:o}=this.routePath(t);return i.chmod(o,n)}async symlink(t,n){let{fs:r,relativePath:s}=this.routePath(n);return r.symlink(t,s)}async link(t,n){let r=this.routePath(t),s=this.routePath(n);if(r.fs!==s.fs)throw new Error(`EXDEV: cross-device link not permitted, link '${t}' -> '${n}'`);return r.fs.link(r.relativePath,s.relativePath)}async readlink(t){let{fs:n,relativePath:r}=this.routePath(t);return n.readlink(r)}async realpath(t){let n=W(t);if(this.mounts.has(n))return n;let{fs:r,relativePath:s}=this.routePath(t),i=await r.realpath(s);for(let o of this.mounts.keys())if(n===o||n.startsWith(`${o}/`))return i==="/"?o:`${o}${i}`;return i}async crossMountCopy(t,n,r){let s=await this.lstat(t);if(s.isFile){let i=await this.readFileBuffer(t);await this.writeFile(n,i),await this.chmod(n,s.mode)}else if(s.isDirectory){if(!r?.recursive)throw new Error(`cp: ${t} is a directory (not copied)`);await this.mkdir(n,{recursive:!0});let i=await this.readdir(t);for(let o of i){let a=it(t,o),l=it(n,o);await this.crossMountCopy(a,l,r)}}else if(s.isSymbolicLink){let i=await this.readlink(t);await this.symlink(i,n)}}async utimes(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.utimes(i,n,r)}};function Me(e){return{kind:e.kind,elements:new Map(e.elements)}}function at(e){return new Map(Array.from(e??[],([t,n])=>[t,Me(n)]))}function xe(e,t){return e.state.arrays?.get(t)}function lr(e,t,n="indexed"){e.state.arrays??=new Map;let r=e.state.arrays.get(t);return r||(r={kind:n,elements:new Map},e.state.arrays.set(t,r)),r}function Xt(e,t,n){let r=lr(e,t,n);return r.kind=n,r}function Ne(e,t){return e.state.arrays?.has(t)??!1}function ae(e,t,n){return xe(e,t)?.elements.get(String(n))}function Yt(e,t,n){return xe(e,t)?.elements.has(String(n))??!1}function G(e,t,n,r,s){let i=lr(e,t,s),o=String(n);if(!i.elements.has(o)&&i.elements.size>=e.limits.maxArrayElements)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(M(r)>e.limits.maxStringLength)throw new $(`array value string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");i.elements.set(o,r)}function Sn(e,t,n,r=!1){let s=new Set(r?[]:xe(e,t)?.elements.keys()??[]);for(let i of n)if(s.add(String(i)),s.size>e.limits.maxArrayElements)throw new $(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements")}function An(e,t,n){return xe(e,t)?.elements.delete(String(n))??!1}function cr(e,t){e.state.arrays?.delete(t),e.state.associativeArrays?.delete(t)}function ve(e,t){return Array.from(xe(e,t)?.elements.keys()??[]).filter(r=>/^(0|[1-9]\d*)$/.test(r)).map(Number).sort((r,s)=>r-s)}function Ee(e,t){lr(e,t,e.state.associativeArrays?.has(t)?"associative":"indexed").elements.clear()}function xt(e,t){return Array.from(xe(e,t)?.elements.keys()??[]).sort()}function Gr(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function ui(e){if(e.parts.length<2)return null;let t=e.parts[0],n=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let r,s=n,i=1;if(n.type==="Literal"&&n.value.startsWith("]")){let f=n.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))r=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let d=e.parts[2];if(d.type!=="Literal"||!d.value.startsWith("=")&&!d.value.startsWith("+="))return null;r=t.pattern.slice(1),s=d,i=2}else return null}else if(t.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(n.type==="SingleQuoted")r=n.value;else{r="";for(let d of n.parts)(d.type==="Literal"||d.type==="Escaped")&&(r+=d.value)}s=f,i=2}else if(t.pattern.endsWith("]")){if(n.type!=="Literal"||!n.value.startsWith("=")&&!n.value.startsWith("+="))return null;r=t.pattern.slice(1,-1)}else return null;r=Gr(r);let o;if(s.type!=="Literal")return null;s.value.startsWith("]=")||s.value.startsWith("]+=")?o=s.value.slice(1):o=s.value;let a=o.startsWith("+=");if(!a&&!o.startsWith("="))return null;let l=[],c=a?2:1,u=o.slice(c);u&&l.push({type:"Literal",value:u});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?l.push({type:"Literal",value:dd(d)}):l.push(d)}return{key:r,valueParts:l,append:a}}function dd(e){return`{${e.items.map(n=>{if(n.type==="Range"){let r=n.startStr??String(n.start),s=n.endStr??String(n.end),i=`${r}..${s}`;return n.step&&(i+=`..${n.step}`),i}return Mn(n.word)}).join(",")}}`}function Mn(e){let t="";for(let n of e.parts)switch(n.type){case"Literal":t+=n.value;break;case"Glob":t+=n.pattern;break;case"SingleQuoted":t+=n.value;break;case"DoubleQuoted":for(let r of n.parts)(r.type==="Literal"||r.type==="Escaped")&&(t+=r.value);break;case"Escaped":t+=n.value;break;case"BraceExpansion":t+="{",t+=n.items.map(r=>r.type==="Range"?`${r.startStr}..${r.endStr}${r.step?`..${r.step}`:""}`:Mn(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",n.user&&(t+=n.user);break}return t}var hd=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],pd=["braceexpand","hashall","interactive-comments"];function fi(e){let t=[],n=[...pd.map(r=>({name:r,enabled:!0})),...hd.map(r=>({name:r,enabled:e[r]}))].sort((r,s)=>r.name.localeCompare(s.name));for(let r of n)r.enabled&&t.push(r.name);return t.join(":")}function Bn(e){e.state.env.set("SHELLOPTS",fi(e.state.options))}var md=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function di(e){let t=[];for(let n of md)e[n]&&t.push(n);return t.join(":")}function hi(e){e.state.env.set("BASHOPTS",di(e.state.shoptOptions))}var F={script(e){return{type:"Script",statements:e}},statement(e,t=[],n=!1,r,s){let i={type:"Statement",pipelines:e,operators:t,background:n};return r&&(i.deferredError=r),s!==void 0&&(i.sourceText=s),i},pipeline(e,t=!1,n=!1,r=!1,s){return{type:"Pipeline",commands:e,negated:t,timed:n,timePosix:r,pipeStderr:s}},simpleCommand(e,t=[],n=[],r=[]){return{type:"SimpleCommand",name:e,args:t,assignments:n,redirections:r}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},processSubstitution(e,t){return{type:"ProcessSubstitution",body:e,direction:t}},assignment(e,t,n=!1,r=null){return{type:"Assignment",name:e,value:t,append:n,array:r}},redirection(e,t,n=null,r){let s={type:"Redirection",fd:n,operator:e,target:t};return r&&(s.fdVariable=r),s},hereDoc(e,t,n=!1,r=!1,s){let i={type:"HereDoc",delimiter:e,content:t,stripTabs:n,quoted:r};return s!==void 0&&(i.terminated=s),i},ifNode(e,t=null,n=[]){return{type:"If",clauses:e,elseBody:t,redirections:n}},forNode(e,t,n,r=[]){return{type:"For",variable:e,words:t,body:n,redirections:r}},whileNode(e,t,n=[]){return{type:"While",condition:e,body:t,redirections:n}},untilNode(e,t,n=[]){return{type:"Until",condition:e,body:t,redirections:n}},caseNode(e,t,n=[]){return{type:"Case",word:e,items:t,redirections:n}},caseItem(e,t,n=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:n}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,n=[],r){return{type:"FunctionDef",name:e,body:t,redirections:n,sourceFile:r}},conditionalCommand(e,t=[],n){return{type:"ConditionalCommand",expression:e,redirections:t,line:n}},arithmeticCommand(e,t=[],n){return{type:"ArithmeticCommand",expression:e,redirections:t,line:n}}};function Ha(e,t){let n=e.length,r=t+3,s=2,i=!1,o=!1;for(;r<n&&s>0;){let a=e[r];if(i){a==="'"&&(i=!1),r++;continue}if(o){if(a==="\\"){r+=2;continue}a==='"'&&(o=!1),r++;continue}if(a==="'"){i=!0,r++;continue}if(a==='"'){o=!0,r++;continue}if(a==="\\"){r+=2;continue}if(a==="("){s++,r++;continue}if(a===")"){if(s--,s===1){let l=r+1;return!(l<n&&e[l]===")")}if(s===0)return!1;r++;continue}if(s===1&&(a==="|"&&r+1<n&&e[r+1]==="|"||a==="&"&&r+1<n&&e[r+1]==="&"||a==="|"&&r+1<n&&e[r+1]!=="|"))return!0;r++}return!1}function Hr(e,t){let n="",r=t,s=0,i=!1,o,a=l=>l===" "||l===" "||l===`
|
|
15
|
+
`),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>hi(t)):e.writeFileSync("/proc/self/status",hi(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function Ka(e,t,n={pid:1,ppid:0,uid:1e3,gid:1e3}){if(hd(e)){let r=gd(e);pd(r,t),md(r),yd(r,n)}}function gd(e){let t=r=>{try{r()}catch(s){if(!(s instanceof Error&&s.message.startsWith("ENOSYS")))throw s}},n={mkdirSync:(r,s)=>t(()=>e.mkdirSync(r,s)),writeFileSync:(r,s)=>t(()=>e.writeFileSync(r,s))};return e.writeFileLazy&&(n.writeFileLazy=(r,s)=>t(()=>e.writeFileLazy?.(r,s))),n}var Kt=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new yt,t?.mounts)for(let{mountPoint:n,filesystem:r}of t.mounts)this.mount(n,r)}mount(t,n){this.validateMountPath(t);let r=j(t);this.validateMount(r),this.mounts.set(r,n)}unmount(t){let n=j(t);if(!this.mounts.has(n))throw new Error(`No filesystem mounted at '${t}'`);this.mounts.delete(n)}getMounts(){return Array.from(this.mounts,([t,n])=>({mountPoint:t,filesystem:n}))}isMountPoint(t){let n=j(t);return this.mounts.has(n)}validateMountPath(t){let n=t.split("/");for(let r of n)if(r==="."||r==="..")throw new Error(`Invalid mount point '${t}': contains '.' or '..' segments`)}validateMount(t){if(t==="/")throw new Error("Cannot mount at root '/'");for(let n of this.mounts.keys())if(n!==t){if(t.startsWith(`${n}/`))throw new Error(`Cannot mount at '${t}': inside existing mount '${n}'`);if(n.startsWith(`${t}/`))throw new Error(`Cannot mount at '${t}': would contain existing mount '${n}'`)}}routePath(t){q(t,"access");let n=j(t);for(let[r,s]of this.mounts){if(n===r)return{fs:s,relativePath:"/"};if(n.startsWith(`${r}/`))return{fs:s,relativePath:n.slice(r.length)}}return{fs:this.baseFs,relativePath:n}}getChildMountPoints(t){let n=j(t),r=n==="/"?"/":`${n}/`,s=[];for(let i of this.mounts.keys())if(i.startsWith(r)){let a=i.slice(r.length).split("/")[0];a&&!s.includes(a)&&s.push(a)}return s}async readFile(t,n){let{fs:r,relativePath:s}=this.routePath(t);return r.readFile(s,n)}async readFileBytes(t){let{fs:n,relativePath:r}=this.routePath(t);return _n(n,r)}async readFileBuffer(t){let{fs:n,relativePath:r}=this.routePath(t);return n.readFileBuffer(r)}async writeFile(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.writeFile(i,n,r)}async appendFile(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.appendFile(i,n,r)}async exists(t){let n=j(t);if(this.mounts.has(n)||this.getChildMountPoints(n).length>0)return!0;let{fs:s,relativePath:i}=this.routePath(t);return s.exists(i)}async stat(t){let n=j(t),r=this.mounts.get(n);if(r)try{return await r.stat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(n).length>0)try{return await this.baseFs.stat(n)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.stat(o)}async lstat(t){let n=j(t),r=this.mounts.get(n);if(r)try{return await r.lstat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(n).length>0)try{return await this.baseFs.lstat(n)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.lstat(o)}async mkdir(t,n){let r=j(t);if(this.mounts.has(r)){if(n?.recursive)return;throw new Error(`EEXIST: directory already exists, mkdir '${t}'`)}if(this.getChildMountPoints(r).length>0&&n?.recursive)return;let{fs:i,relativePath:o}=this.routePath(t);return i.mkdir(o,n)}async createExclusive(t,n){let r=j(t),s=n.directory?"mkdir":"open";if(this.mounts.has(r))throw new Error(`EEXIST: file already exists, ${s} '${t}'`);let{fs:i,relativePath:o}=this.routePath(t);if(!i.createExclusive)throw new Na(t,s);let a=mt(o);return a!=="/"&&this.getChildMountPoints(mt(r)).length>0&&!await i.exists(a)&&await i.mkdir(a,{recursive:!0}),i.createExclusive(o,n)}mkdirSync(t,n){let{fs:r,relativePath:s}=this.routePath(t),i=r;if(!i.mkdirSync)throw new Error(`ENOSYS: function not implemented, mkdir '${t}'`);i.mkdirSync(s,n)}writeFileSync(t,n){let{fs:r,relativePath:s}=this.routePath(t),i=r;if(!i.writeFileSync)throw new Error(`ENOSYS: function not implemented, write '${t}'`);i.writeFileSync(s,n)}async readdir(t){let n=j(t),r=new Set,s=null,{fs:i,relativePath:o}=this.routePath(t);try{let l=await i.readdir(o);for(let c of l)r.add(c)}catch(l){let c=l.code,u=l.message||"";if(c!=="ENOENT"&&!u.includes("ENOENT"))throw l;s=l}let a=this.getChildMountPoints(n);for(let l of a)r.add(l);if(r.size===0&&s&&!this.mounts.has(n))throw s;return Array.from(r).sort()}async rm(t,n){let r=j(t);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot remove '${t}'`);if(this.getChildMountPoints(r).length>0)throw new Error(`EBUSY: contains mount points, cannot remove '${t}'`);let{fs:i,relativePath:o}=this.routePath(t);return i.rm(o,n)}async cp(t,n,r){if((await this.stat(t)).isDirectory&&Lt(t,n))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);let i=this.routePath(t),o=this.routePath(n);return i.fs===o.fs?i.fs.cp(i.relativePath,o.relativePath,r):this.crossMountCopy(t,n,r)}async mv(t,n){let r=j(t);if((await this.stat(t)).isDirectory&&Lt(t,n))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot move '${t}'`);let i=this.routePath(t),o=this.routePath(n);if(i.fs===o.fs)return i.fs.mv(i.relativePath,o.relativePath);await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return Ht(t,n)}getAllPaths(){let t=new Set;for(let n of this.baseFs.getAllPaths())t.add(n);for(let[n,r]of this.mounts){let s=n.split("/").filter(Boolean),i="";for(let o of s)i=`${i}/${o}`,t.add(i);for(let o of r.getAllPaths())o==="/"?t.add(n):t.add(`${n}${o}`)}return Array.from(t).sort()}async chmod(t,n){let r=j(t),s=this.mounts.get(r);if(s)return s.chmod("/",n);let{fs:i,relativePath:o}=this.routePath(t);return i.chmod(o,n)}async symlink(t,n){let{fs:r,relativePath:s}=this.routePath(n);return r.symlink(t,s)}async link(t,n){let r=this.routePath(t),s=this.routePath(n);if(r.fs!==s.fs)throw new Error(`EXDEV: cross-device link not permitted, link '${t}' -> '${n}'`);return r.fs.link(r.relativePath,s.relativePath)}async readlink(t){let{fs:n,relativePath:r}=this.routePath(t);return n.readlink(r)}async realpath(t){let n=j(t);if(this.mounts.has(n))return n;let{fs:r,relativePath:s}=this.routePath(t),i=await r.realpath(s);for(let o of this.mounts.keys())if(n===o||n.startsWith(`${o}/`))return i==="/"?o:`${o}${i}`;return i}async crossMountCopy(t,n,r){let s=await this.lstat(t);if(s.isFile){let i=await this.readFileBuffer(t);await this.writeFile(n,i),await this.chmod(n,s.mode)}else if(s.isDirectory){if(!r?.recursive)throw new Error(`cp: ${t} is a directory (not copied)`);await this.mkdir(n,{recursive:!0});let i=await this.readdir(t);for(let o of i){let a=st(t,o),l=st(n,o);await this.crossMountCopy(a,l,r)}}else if(s.isSymbolicLink){let i=await this.readlink(t);await this.symlink(i,n)}}async utimes(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.utimes(i,n,r)}};function Me(e){return{kind:e.kind,elements:new Map(e.elements)}}function ot(e){return new Map(Array.from(e??[],([t,n])=>[t,Me(n)]))}function ke(e,t){return e.state.arrays?.get(t)}function cr(e,t,n="indexed"){e.state.arrays??=new Map;let r=e.state.arrays.get(t);return r||(r={kind:n,elements:new Map},e.state.arrays.set(t,r)),r}function Xt(e,t,n){let r=cr(e,t,n);return r.kind=n,r}function Ne(e,t){return e.state.arrays?.has(t)??!1}function ae(e,t,n){return ke(e,t)?.elements.get(String(n))}function Yt(e,t,n){return ke(e,t)?.elements.has(String(n))??!1}function H(e,t,n,r,s){let i=cr(e,t,s),o=String(n);if(!i.elements.has(o)&&i.elements.size>=e.limits.maxArrayElements)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(V(r)>e.limits.maxStringLength)throw new C(`array value string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");i.elements.set(o,r)}function Sn(e,t,n,r=!1){let s=new Set(r?[]:ke(e,t)?.elements.keys()??[]);for(let i of n)if(s.add(String(i)),s.size>e.limits.maxArrayElements)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements")}function An(e,t,n){return ke(e,t)?.elements.delete(String(n))??!1}function ur(e,t){e.state.arrays?.delete(t),e.state.associativeArrays?.delete(t)}function Ae(e,t){return Array.from(ke(e,t)?.elements.keys()??[]).filter(r=>/^(0|[1-9]\d*)$/.test(r)).map(Number).sort((r,s)=>r-s)}function Ee(e,t){cr(e,t,e.state.associativeArrays?.has(t)?"associative":"indexed").elements.clear()}function xt(e,t){return Array.from(ke(e,t)?.elements.keys()??[]).sort()}function Zr(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function pi(e){if(e.parts.length<2)return null;let t=e.parts[0],n=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let r,s=n,i=1;if(n.type==="Literal"&&n.value.startsWith("]")){let f=n.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))r=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let d=e.parts[2];if(d.type!=="Literal"||!d.value.startsWith("=")&&!d.value.startsWith("+="))return null;r=t.pattern.slice(1),s=d,i=2}else return null}else if(t.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(n.type==="SingleQuoted")r=n.value;else{r="";for(let d of n.parts)(d.type==="Literal"||d.type==="Escaped")&&(r+=d.value)}s=f,i=2}else if(t.pattern.endsWith("]")){if(n.type!=="Literal"||!n.value.startsWith("=")&&!n.value.startsWith("+="))return null;r=t.pattern.slice(1,-1)}else return null;r=Zr(r);let o;if(s.type!=="Literal")return null;s.value.startsWith("]=")||s.value.startsWith("]+=")?o=s.value.slice(1):o=s.value;let a=o.startsWith("+=");if(!a&&!o.startsWith("="))return null;let l=[],c=a?2:1,u=o.slice(c);u&&l.push({type:"Literal",value:u});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?l.push({type:"Literal",value:wd(d)}):l.push(d)}return{key:r,valueParts:l,append:a}}function wd(e){return`{${e.items.map(n=>{if(n.type==="Range"){let r=n.startStr??String(n.start),s=n.endStr??String(n.end),i=`${r}..${s}`;return n.step&&(i+=`..${n.step}`),i}return Bn(n.word)}).join(",")}}`}function Bn(e){let t="";for(let n of e.parts)switch(n.type){case"Literal":t+=n.value;break;case"Glob":t+=n.pattern;break;case"SingleQuoted":t+=n.value;break;case"DoubleQuoted":for(let r of n.parts)(r.type==="Literal"||r.type==="Escaped")&&(t+=r.value);break;case"Escaped":t+=n.value;break;case"BraceExpansion":t+="{",t+=n.items.map(r=>r.type==="Range"?`${r.startStr}..${r.endStr}${r.step?`..${r.step}`:""}`:Bn(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",n.user&&(t+=n.user);break}return t}var Ed=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],bd=["braceexpand","hashall","interactive-comments"];function Qr(e){let t=[],n=[...bd.map(r=>({name:r,enabled:!0})),...Ed.map(r=>({name:r,enabled:e[r]}))].sort((r,s)=>r.name.localeCompare(s.name));for(let r of n)r.enabled&&t.push(r.name);return t.join(":")}function Wn(e){e.state.env.set("SHELLOPTS",Qr(e.state.options))}var Sd=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Kr(e){let t=[];for(let n of Sd)e[n]&&t.push(n);return t.join(":")}function mi(e){e.state.env.set("BASHOPTS",Kr(e.state.shoptOptions))}var M={script(e){return{type:"Script",statements:e}},statement(e,t=[],n=!1,r,s){let i={type:"Statement",pipelines:e,operators:t,background:n};return r&&(i.deferredError=r),s!==void 0&&(i.sourceText=s),i},pipeline(e,t=!1,n=!1,r=!1,s){return{type:"Pipeline",commands:e,negated:t,timed:n,timePosix:r,pipeStderr:s}},simpleCommand(e,t=[],n=[],r=[]){return{type:"SimpleCommand",name:e,args:t,assignments:n,redirections:r}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},processSubstitution(e,t){return{type:"ProcessSubstitution",body:e,direction:t}},assignment(e,t,n=!1,r=null){return{type:"Assignment",name:e,value:t,append:n,array:r}},redirection(e,t,n=null,r){let s={type:"Redirection",fd:n,operator:e,target:t};return r&&(s.fdVariable=r),s},hereDoc(e,t,n=!1,r=!1,s){let i={type:"HereDoc",delimiter:e,content:t,stripTabs:n,quoted:r};return s!==void 0&&(i.terminated=s),i},ifNode(e,t=null,n=[]){return{type:"If",clauses:e,elseBody:t,redirections:n}},forNode(e,t,n,r=[]){return{type:"For",variable:e,words:t,body:n,redirections:r}},whileNode(e,t,n=[]){return{type:"While",condition:e,body:t,redirections:n}},untilNode(e,t,n=[]){return{type:"Until",condition:e,body:t,redirections:n}},caseNode(e,t,n=[]){return{type:"Case",word:e,items:t,redirections:n}},caseItem(e,t,n=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:n}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,n=[],r){return{type:"FunctionDef",name:e,body:t,redirections:n,sourceFile:r}},conditionalCommand(e,t=[],n){return{type:"ConditionalCommand",expression:e,redirections:t,line:n}},arithmeticCommand(e,t=[],n){return{type:"ArithmeticCommand",expression:e,redirections:t,line:n}}};function Xa(e,t){let n=e.length,r=t+3,s=2,i=!1,o=!1;for(;r<n&&s>0;){let a=e[r];if(i){a==="'"&&(i=!1),r++;continue}if(o){if(a==="\\"){r+=2;continue}a==='"'&&(o=!1),r++;continue}if(a==="'"){i=!0,r++;continue}if(a==='"'){o=!0,r++;continue}if(a==="\\"){r+=2;continue}if(a==="("){s++,r++;continue}if(a===")"){if(s--,s===1){let l=r+1;return!(l<n&&e[l]===")")}if(s===0)return!1;r++;continue}if(s===1&&(a==="|"&&r+1<n&&e[r+1]==="|"||a==="&"&&r+1<n&&e[r+1]==="&"||a==="|"&&r+1<n&&e[r+1]!=="|"))return!0;r++}return!1}function Xr(e,t){let n="",r=t,s=0,i=!1,o,a=l=>l===" "||l===" "||l===`
|
|
16
16
|
`||l===";"||l==="&"||l==="|"||l==="<"||l===">"||l==="("||l===")";for(;r<e.length;){let l=e[r];if(l==="'"){let c=s>0;for(c||(i=!0),c&&(n+=l),r++;r<e.length&&e[r]!=="'";)n+=e[r],r++;r<e.length?(c&&(n+=e[r]),r++):o=l;continue}if(l==='"'){let c=s>0;for(c||(i=!0),c&&(n+=l),r++;r<e.length&&e[r]!=='"';){if(e[r]==="\\"&&r+1<e.length){if(c){n+=e.slice(r,r+2),r+=2;continue}let u=e[r+1];if(u==="$"||u==="`"||u==='"'||u==="\\"||u===`
|
|
17
17
|
`){r+=2,u!==`
|
|
18
18
|
`&&(n+=u);continue}}n+=e[r],r++}r<e.length?(c&&(n+=e[r]),r++):o=l;continue}if(l==="\\"&&r+1<e.length){if(s>0){n+=e.slice(r,r+2),r+=2;continue}i=!0;let c=e[r+1];c!==`
|
|
19
|
-
`&&(n+=c),r+=2;continue}if(s===0&&(l==="$"||l==="<"||l===">")&&e[r+1]==="("){n+=`${l}(`,s=1,r+=2;continue}if(s===0&&a(l))break;s>0&&(l==="("?s++:l===")"&&s--),n+=l,r++}return{delim:n,endPos:r,quoted:i,unclosedQuote:o,unclosedSubstitution:s>0}}function
|
|
20
|
-
`,r);o===-1&&(o=e.length);let a=e.slice(r,o);if(i&&(a=a.replace(/^\t+/,"")),a===s){r=o+1;break}if(o>=e.length)return e.length;r=o+1}return Math.min(r,e.length)}function
|
|
21
|
-
`&&u.length>0){let h=
|
|
19
|
+
`&&(n+=c),r+=2;continue}if(s===0&&(l==="$"||l==="<"||l===">")&&e[r+1]==="("){n+=`${l}(`,s=1,r+=2;continue}if(s===0&&a(l))break;s>0&&(l==="("?s++:l===")"&&s--),n+=l,r++}return{delim:n,endPos:r,quoted:i,unclosedQuote:o,unclosedSubstitution:s>0}}function Ad(e,t,n){let r=t+1;for(let{delim:s,stripTabs:i}of n)for(;;){if(r>=e.length)return e.length;let o=e.indexOf(`
|
|
20
|
+
`,r);o===-1&&(o=e.length);let a=e.slice(r,o);if(i&&(a=a.replace(/^\t+/,"")),a===s){r=o+1;break}if(o>=e.length)return e.length;r=o+1}return Math.min(r,e.length)}function Ya(e,t,n){let r=1,s=t,i=!1,o=!1,a=0,l=!1,c="",u=[],f=0;for(;s<e.length&&r>0;){let d=e[s];if(i)d==="'"&&(i=!1);else if(o)d==="\\"&&s+1<e.length?s++:d==='"'&&(o=!1);else{if(d==="("&&e[s+1]==="("?f++:d===")"&&e[s+1]===")"&&f>0&&f--,f===0&&d==="<"&&e[s+1]==="<"&&e[s+2]!=="<"){let h=s+2,p=!1;for(e[h]==="-"&&(p=!0,h++);e[h]===" "||e[h]===" ";)h++;let{delim:m,endPos:y,unclosedQuote:b,unclosedSubstitution:w}=Xr(e,h);if(b&&n(`unexpected EOF while looking for matching \`${b}'`),w&&n("unexpected EOF while looking for matching `)'"),m.length>0){u.push({delim:m,stripTabs:p}),c="",s=y;continue}}if(d===`
|
|
21
|
+
`&&u.length>0){let h=Ad(e,s,u);u.length=0,c="",s=h;continue}d==="'"?(i=!0,c=""):d==='"'?(o=!0,c=""):d==="\\"&&s+1<e.length?(s++,c=""):/[a-zA-Z_]/.test(d)?c+=d:(c==="case"?(a++,l=!1):c==="in"&&a>0?l=!0:c==="esac"&&a>0&&(a--,l=!1),c="",d==="("?s>0&&e[s-1]==="$"?r++:l||r++:d===")"?l?l=!1:r--:d===";"&&a>0&&s+1<e.length&&e[s+1]===";"&&(l=!0))}r>0&&s++}return r>0&&n("unexpected EOF while looking for matching `)'"),s}function Ja(e,t,n,r){let s=t+2,i=Ya(e,s,r),o=e.slice(s,i),l=n().parse(o);return{part:M.commandSubstitution(l,!1),endIndex:i+1}}function el(e,t,n,r){let s=e[t]==="<"?"input":"output",i=t+2,o=Ya(e,i,r),a=n().parse(e.slice(i,o));return{part:M.processSubstitution(a,s),endIndex:o+1}}function tl(e,t,n,r,s){let o=t+1,a="";for(;o<e.length&&e[o]!=="`";)if(e[o]==="\\"){let u=e[o+1];u==="$"||u==="`"||u==="\\"||u===`
|
|
22
22
|
`||n&&u==='"'?(u!==`
|
|
23
|
-
`&&(a+=u),o+=2):(a+=e[o],o++)}else a+=e[o],o++;o>=e.length&&s("unexpected EOF while looking for matching ``'");let c=r().parse(a);return{part:
|
|
24
|
-
`||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var
|
|
23
|
+
`&&(a+=u),o+=2):(a+=e[o],o++)}else a+=e[o],o++;o>=e.length&&s("unexpected EOF while looking for matching ``'");let c=r().parse(a);return{part:M.commandSubstitution(c,!0),endIndex:o+1}}var vd=10485760,g;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(g||(g={}));var Je=class extends Error{line;column;constructor(t,n,r){super(`line ${n}: ${t}`),this.line=n,this.column=r,this.name="LexerError"}},yi=new Map([["if",g.IF],["then",g.THEN],["else",g.ELSE],["elif",g.ELIF],["fi",g.FI],["for",g.FOR],["while",g.WHILE],["until",g.UNTIL],["do",g.DO],["done",g.DONE],["case",g.CASE],["esac",g.ESAC],["in",g.IN],["function",g.FUNCTION],["select",g.SELECT],["time",g.TIME],["coproc",g.COPROC]]),kd=new Set(yi.values());function gi(e){return kd.has(e)}function nl(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return!1;let n=e.slice(t[0].length);if(n===""||n==="+")return!0;if(n[0]==="["){let r=0,s=0;for(;s<n.length;s++)if(n[s]==="[")r++;else if(n[s]==="]"&&(r--,r===0))break;if(r!==0||s>=n.length)return!1;let i=n.slice(s+1);return i===""||i==="+"}return!1}function rl(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];if(r==="[")t++;else if(r==="]")t--;else{if(t===0&&r==="=")return n;if(t===0&&r==="+"&&e[n+1]==="=")return n+1}}return-1}var xd=[[";",";","&",g.SEMI_SEMI_AND],["<","<","<",g.TLESS],["&",">",">",g.AND_DGREAT]],Pd=[["[","[",g.DBRACK_START],["]","]",g.DBRACK_END],["(","(",g.DPAREN_START],[")",")",g.DPAREN_END],["&","&",g.AND_AND],["|","|",g.OR_OR],[";",";",g.DSEMI],[";","&",g.SEMI_AND],["|","&",g.PIPE_AMP],[">",">",g.DGREAT],["<","&",g.LESSAND],[">","&",g.GREATAND],["<",">",g.LESSGREAT],[">","|",g.CLOBBER],["&",">",g.AND_GREAT]],$d=new Map([["|",g.PIPE],["&",g.AMP],[";",g.SEMICOLON],["(",g.LPAREN],[")",g.RPAREN],["<",g.LESS],[">",g.GREAT]]);function Cd(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function sl(e){return e===" "||e===" "||e===`
|
|
24
|
+
`||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var Yr=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];pendingHeredocDelimiterMode;dparenDepth=0;maxHeredocSize;constructor(t,n){this.input=t,this.maxHeredocSize=n?.maxHeredocSize??vd}tokenize(){let n=this.input.length,r=this.tokens,s=this.pendingHeredocs;for(;this.pos<n;){if(s.length>0&&r.length>0&&r[r.length-1].type===g.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=n)break;let i=this.nextToken();i&&r.push(i)}return s.length>0&&this.readHeredocContent(),r.push({type:g.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let t=this.input,n=t.length,r=this.pos,s=this.column,i=this.line;for(;r<n;){let o=t[r];if(o===" "||o===" ")r++,s++;else if(o==="\\"&&t[r+1]===`
|
|
25
25
|
`)r+=2,i++,s=1;else break}this.pos=r,this.column=s,this.line=i}nextToken(){let t=this.input,n=this.pos,r=this.line,s=this.column,i=t[n],o=t[n+1],a=t[n+2],l=this.pendingHeredocDelimiterMode;if(this.pendingHeredocDelimiterMode=void 0,l!==void 0&&i!==`
|
|
26
26
|
`&&!(i==="#"&&this.dparenDepth===0))return this.readHeredocDelimiterToken(n,r,s,l);if(i==="#"&&this.dparenDepth===0)return this.readComment(n,r,s);if(i===`
|
|
27
|
-
`)return this.pos=n+1,this.line++,this.column=1,{type:
|
|
28
|
-
`,start:n,end:n+1,line:r,column:s};if(i==="<"&&o==="<"&&a==="-")return this.pos=n+3,this.column=s+3,this.pendingHeredocDelimiterMode=!0,this.makeToken(
|
|
29
|
-
`&&h!==";"&&h!=="&"&&h!=="|"&&h!=="("&&h!==")"&&h!=="<"&&h!==">")break}return this.pos=n+2,this.column=s+2,this.makeToken(d,u+f,n,r,s)}if(i==="("&&this.dparenDepth>0)return this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(
|
|
30
|
-
`?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(
|
|
27
|
+
`)return this.pos=n+1,this.line++,this.column=1,{type:g.NEWLINE,value:`
|
|
28
|
+
`,start:n,end:n+1,line:r,column:s};if(i==="<"&&o==="<"&&a==="-")return this.pos=n+3,this.column=s+3,this.pendingHeredocDelimiterMode=!0,this.makeToken(g.DLESSDASH,"<<-",n,r,s);for(let[u,f,d,h]of xd)if(i===u&&o===f&&a===d)return this.pos=n+3,this.column=s+3,this.makeToken(h,u+f+d,n,r,s);if(i==="<"&&o==="<")return this.pos=n+2,this.column=s+2,this.pendingHeredocDelimiterMode=!1,this.makeToken(g.DLESS,"<<",n,r,s);if(i==="("&&o==="("){let u=this.tokens[this.tokens.length-1];return this.dparenDepth===0&&u?.end===n&&(u.type===g.LESS||u.type===g.GREAT)?(this.pos=n+1,this.column=s+1,this.makeToken(g.LPAREN,"(",n,r,s)):this.dparenDepth>0?(this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(g.LPAREN,"(",n,r,s)):this.looksLikeNestedSubshells(n+2)||this.dparenClosesWithSpacedParens(n+2)?(this.pos=n+1,this.column=s+1,this.makeToken(g.LPAREN,"(",n,r,s)):(this.pos=n+2,this.column=s+2,this.dparenDepth=1,this.makeToken(g.DPAREN_START,"((",n,r,s))}if(i===")"&&o===")")return this.dparenDepth===1?(this.pos=n+2,this.column=s+2,this.dparenDepth=0,this.makeToken(g.DPAREN_END,"))",n,r,s)):this.dparenDepth>1?(this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(g.RPAREN,")",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(g.RPAREN,")",n,r,s));for(let[u,f,d]of Pd)if(!(u==="("&&f==="("||u===")"&&f===")")&&!(this.dparenDepth>0&&u===";"&&(d===g.DSEMI||d===g.SEMI_AND||d===g.SEMI_SEMI_AND))&&i===u&&o===f){if(d===g.DBRACK_START||d===g.DBRACK_END){let h=t[n+2];if(h!==void 0&&h!==" "&&h!==" "&&h!==`
|
|
29
|
+
`&&h!==";"&&h!=="&"&&h!=="|"&&h!=="("&&h!==")"&&h!=="<"&&h!==">")break}return this.pos=n+2,this.column=s+2,this.makeToken(d,u+f,n,r,s)}if(i==="("&&this.dparenDepth>0)return this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(g.LPAREN,"(",n,r,s);if(i===")"&&this.dparenDepth>1)return this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(g.RPAREN,")",n,r,s);let c=$d.get(i);if(c!==void 0)return this.pos=n+1,this.column=s+1,this.makeToken(c,i,n,r,s);if(i==="{"){let u=this.scanFdVariable(n);return u!==null?(this.pos=u.end,this.column=s+(u.end-n),{type:g.FD_VARIABLE,value:u.varname,start:n,end:u.end,line:r,column:s}):o==="}"?(this.pos=n+2,this.column=s+2,{type:g.WORD,value:"{}",start:n,end:n+2,line:r,column:s,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(n)!==null?this.readWordWithBraceExpansion(n,r,s):this.scanLiteralBraceWord(n)!==null?this.readWordWithBraceExpansion(n,r,s):o!==void 0&&o!==" "&&o!==" "&&o!==`
|
|
30
|
+
`?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(g.LBRACE,"{",n,r,s))}return i==="}"?this.isWordCharFollowing(n+1)?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(g.RBRACE,"}",n,r,s)):i==="!"?o==="="?(this.pos=n+2,this.column=s+2,this.makeToken(g.WORD,"!=",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(g.BANG,"!",n,r,s)):this.readWord(n,r,s)}looksLikeNestedSubshells(t){let n=this.input,r=n.length,s=t;for(;s<r&&(n[s]===" "||n[s]===" ");)s++;if(s>=r)return!1;let i=n[s];if(i==="(")return this.looksLikeNestedSubshells(s+1);let o=/[a-zA-Z_]/.test(i),a=i==="!"||i==="[";if(!o&&!a)return!1;let l=s;for(;l<r&&/[a-zA-Z0-9_\-.]/.test(n[l]);)l++;if(l===s)return a;let c=l;for(;c<r&&(n[c]===" "||n[c]===" ");)c++;if(c>=r)return!1;let u=n[c];if(u==="="&&n[c+1]!=="="||u===`
|
|
31
31
|
`||l===c&&/[+\-*/%<>&|^!~?:]/.test(u)&&u!=="-"||u===")"&&n[c+1]===")")return!1;if(c>l&&(u==="-"||u==='"'||u==="'"||u==="$"||/[a-zA-Z_/.]/.test(u))){let f=c;for(;f<r&&n[f]!==`
|
|
32
32
|
`;){if(n[f]===")")return!0;f++}return!1}if(u===")"){let f=c+1;for(;f<r&&(n[f]===" "||n[f]===" ");)f++;if(n[f]==="|"&&n[f+1]==="|"||n[f]==="&"&&n[f+1]==="&"||n[f]===";"||n[f]==="|"&&n[f+1]!=="|")return!0}return!1}makeToken(t,n,r,s,i){return{type:t,value:n,start:r,end:this.pos,line:s,column:i}}readComment(t,n,r){let s=this.input,i=s.length,o=this.pos;for(;o<i&&s[o]!==`
|
|
33
|
-
`;)o++;let a=s.slice(t,o);return this.pos=o,this.column=r+(o-t),{type:
|
|
34
|
-
`||
|
|
35
|
-
`||
|
|
36
|
-
`)break;u+=
|
|
37
|
-
`||
|
|
38
|
-
`){o+=2,c++,l=1;continue}if(p){if(
|
|
39
|
-
`){if(
|
|
40
|
-
`){o+=2,l=1,c++;continue}u+=
|
|
41
|
-
|
|
42
|
-
`,
|
|
43
|
-
`?(c++,l=0):l++,o++}
|
|
44
|
-
`;)o++,l++,u+=s[o];
|
|
45
|
-
`&&(c++,l=0,
|
|
46
|
-
`&&(c++,l=0),o++,l++}continue}if(
|
|
47
|
-
`){o+=2,c++,l=1;continue}if(
|
|
48
|
-
`&&(c++,l=0),o++,l++}if(v)throw new Je("unexpected EOF while looking for matching `''",
|
|
49
|
-
`&&(c++,l=0),o++,l++}o<i&&(u+=s[o],o++,l++);continue}u+=
|
|
50
|
-
`?(c++,l=1):l++}if(this.pos=o,this.column=l,this.line=c,
|
|
33
|
+
`;)o++;let a=s.slice(t,o);return this.pos=o,this.column=r+(o-t),{type:g.COMMENT,value:a,start:t,end:o,line:n,column:r}}readWord(t,n,r){let s=this.input,i=s.length,o=this.pos,a=o;for(;o<i;){let E=s[o];if(E===" "||E===" "||E===`
|
|
34
|
+
`||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">"||E==="'"||E==='"'||E==="\\"||E==="$"||E==="`"||E==="{"||E==="}"||E==="~"||E==="*"||E==="?"||E==="[")break;o++}if(o>a){let E=s[o];if(!(E==="("&&o>a&&"@*+?!".includes(s[o-1]))){if(o>=i||E===" "||E===" "||E===`
|
|
35
|
+
`||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">"){let S=s.slice(a,o);this.pos=o,this.column=r+(o-a);let v=yi.get(S);if(v!==void 0)return{type:v,value:S,start:t,end:o,line:n,column:r};let A=rl(S);return A>0&&nl(S.slice(0,A))?{type:g.ASSIGNMENT_WORD,value:S,start:t,end:o,line:n,column:r}:/^[0-9]+$/.test(S)?{type:g.NUMBER,value:S,start:t,end:o,line:n,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(S)?{type:g.NAME,value:S,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}:{type:g.WORD,value:S,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}}}}o=this.pos;let l=this.column,c=this.line,u="",f=!1,d=!1,h=!1,p=!1,m=s[o]==='"'||s[o]==="'",y=!1,b=0;for(;o<i;){let E=s[o];if(!h&&!p){if(E==="("&&u.length>0&&"@*+?!".includes(u[u.length-1])){let S=this.scanExtglobPattern(o);if(S!==null){u+=S.content,o=S.end,l+=S.content.length;continue}}if(E==="["&&b===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){let S=o+1<i?s[o+1]:"";if(S==="^"||S==="!"){u+=E,o++,l++;continue}b=1,u+=E,o++,l++;continue}}else if(E==="["&&b>0){u.length>0&&u[u.length-1]!=="\\"&&b++,u+=E,o++,l++;continue}else if(E==="]"&&b>0){u.length>0&&u[u.length-1]!=="\\"&&b--,u+=E,o++,l++;continue}if(b>0){if(E===`
|
|
36
|
+
`)break;u+=E,o++,l++;continue}if(E===" "||E===" "||E===`
|
|
37
|
+
`||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">")break}if(E==="$"&&o+1<i&&s[o+1]==="'"&&!h&&!p){for(u+="$'",o+=2,l+=2;o<i&&s[o]!=="'";)s[o]==="\\"&&o+1<i?(u+=s[o]+s[o+1],o+=2,l+=2):(u+=s[o],o++,l++);o<i&&(u+="'",o++,l++);continue}if(E==="$"&&o+1<i&&s[o+1]==='"'&&!h&&!p){o++,l++,p=!0,f=!0,u===""&&(m=!0),o++,l++;continue}if(E==="'"&&!p){if(h)if(h=!1,!m||y)u+=E;else{let S=o+1<i?s[o+1]:"";S&&!sl(S)&&S!=="'"&&(S==='"'?(y=!0,u+=E,d=!1,f=!1):(y=!0,u+=E))}else h=!0,m&&!y?(d=!0,f=!0):u+=E;o++,l++;continue}if(E==='"'&&!h){if(p)if(p=!1,!m||y)u+=E;else{let S=o+1<i?s[o+1]:"";S&&!sl(S)&&S!=='"'&&(S==="'"?(y=!0,u+=E,d=!1,f=!1):(y=!0,u+=E))}else p=!0,m&&!y?f=!0:u+=E;o++,l++;continue}if(E==="\\"&&!h&&o+1<i){let S=s[o+1];if(S===`
|
|
38
|
+
`){o+=2,c++,l=1;continue}if(p){if(S==='"'||S==="\\"||S==="$"||S==="`"||S===`
|
|
39
|
+
`){if(S===`
|
|
40
|
+
`){o+=2,l=1,c++;continue}u+=E+S,o+=2,l+=2;continue}}else{u+=E+S,o+=2,l+=2;continue}}if(E==="$"&&o+1<i&&s[o+1]==="("&&!h){u+=E,o++,l++,u+=s[o],o++,l++;let S=1,v=!1,A=!1,k=0,x=!1,D="",$=[],N=s[o]==="("&&!this.dollarDparenIsSubshell(o),O=N?1:0;for(;S>0&&o<i;){let R=s[o];if(u+=R,v)R==="'"&&(v=!1);else if(A)R==="\\"&&o+1<i?(u+=s[o+1],o++,l++):R==='"'&&(A=!1);else{if(R==="("&&s[o+1]==="("?O++:R===")"&&s[o+1]===")"&&O>0&&O--,O===0&&R==="<"&&s[o+1]==="<"&&s[o+2]!=="<"){let W=o+2,P=!1;for(s[W]==="-"&&(P=!0,W++);s[W]===" "||s[W]===" ";)W++;let{delim:B,endPos:U,unclosedQuote:_,unclosedSubstitution:T}=Xr(s,W);if(_)throw new Je(`unexpected EOF while looking for matching \`${_}'`,c,l);if(T)throw new Je("unexpected EOF while looking for matching `)'",c,l);if(B.length>0){u+=s.slice(o+1,U),l+=U-o,$.push({delim:B,stripTabs:P}),o=U;continue}}if(R===`
|
|
41
|
+
`&&$.length>0){c++,l=0;let W=o+1;for(let{delim:P,stripTabs:B}of $)for(;!(W>=i);){let U=s.indexOf(`
|
|
42
|
+
`,W);U===-1&&(U=i);let _=s.slice(W,U),T=B?_.replace(/^\t+/,""):_;u+=s.slice(W,Math.min(U+1,i)),U<i&&c++;let z=U>=i;if(W=U+1,T===P||z)break}$.length=0,l=0,o=Math.min(W,i);continue}if(R==="'")v=!0,D="";else if(R==='"')A=!0,D="";else if(R==="\\"&&o+1<i)u+=s[o+1],o++,l++,D="";else if(R==="$"&&o+1<i&&s[o+1]==="{"){o++,l++,u+=s[o],o++,l++;let W=1,P=!1,B=!1;for(;W>0&&o<i;){let U=s[o];if(U==="\\"&&o+1<i&&!P){u+=U,o++,l++,u+=s[o],o++,l++;continue}u+=U,P?U==="'"&&(P=!1):B?U==='"'&&(B=!1):U==="'"?P=!0:U==='"'?B=!0:U==="{"?W++:U==="}"&&W--,U===`
|
|
43
|
+
`?(c++,l=0):l++,o++}D="";continue}else if(R==="#"&&!N&&(D===""||/\s/.test(s[o-1]||""))){for(;o+1<i&&s[o+1]!==`
|
|
44
|
+
`;)o++,l++,u+=s[o];D=""}else/[a-zA-Z_]/.test(R)?D+=R:(D==="case"?(k++,x=!1):D==="in"&&k>0?x=!0:D==="esac"&&k>0&&(k--,x=!1),D="",R==="("?o>0&&s[o-1]==="$"?S++:x||S++:R===")"?x?x=!1:S--:R===";"&&k>0&&(o+1<i&&s[o+1]===";"||o+1<i&&s[o+1]==="&")&&(x=!0))}R===`
|
|
45
|
+
`&&(c++,l=0,D=""),o++,l++}continue}if(E==="$"&&o+1<i&&s[o+1]==="["&&!h){u+=E,o++,l++,u+=s[o],o++,l++;let S=1;for(;S>0&&o<i;){let v=s[o];u+=v,v==="["?S++:v==="]"?S--:v===`
|
|
46
|
+
`&&(c++,l=0),o++,l++}continue}if(E==="$"&&o+1<i&&s[o+1]==="{"&&!h){u+=E,o++,l++,u+=s[o],o++,l++;let S=1,v=!1,A=!1,k=c,x=l,D=c,$=l;for(;S>0&&o<i;){let N=s[o];if(N==="\\"&&o+1<i&&s[o+1]===`
|
|
47
|
+
`){o+=2,c++,l=1;continue}if(N==="\\"&&o+1<i&&!v){u+=N,o++,l++,u+=s[o],o++,l++;continue}u+=N,v?N==="'"&&(v=!1):A?N==='"'&&(A=!1):N==="'"?(v=!0,k=c,x=l):N==='"'?(A=!0,D=c,$=l):N==="{"?S++:N==="}"&&S--,N===`
|
|
48
|
+
`&&(c++,l=0),o++,l++}if(v)throw new Je("unexpected EOF while looking for matching `''",k,x);if(A)throw new Je("unexpected EOF while looking for matching `\"'",D,$);continue}if(E==="$"&&o+1<i&&!h){let S=s[o+1];if(S==="#"||S==="?"||S==="$"||S==="!"||S==="@"||S==="*"||S==="-"||S>="0"&&S<="9"){u+=E+S,o+=2,l+=2;continue}}if(E==="`"&&!h){for(u+=E,o++,l++;o<i&&s[o]!=="`";){let S=s[o];u+=S,S==="\\"&&o+1<i&&(u+=s[o+1],o++,l++),S===`
|
|
49
|
+
`&&(c++,l=0),o++,l++}o<i&&(u+=s[o],o++,l++);continue}u+=E,o++,E===`
|
|
50
|
+
`?(c++,l=1):l++}if(this.pos=o,this.column=l,this.line=c,y&&m&&(u=s[t]+u,f=!1,d=!1),h||p){let E=h?"'":'"';throw new Je(`unexpected EOF while looking for matching \`${E}'`,n,r)}if(!m&&u.length>=2){if(u[0]==="'"&&u[u.length-1]==="'"){let E=u.slice(1,-1);!E.includes("'")&&!E.includes('"')&&(u=E,f=!0,d=!0)}else if(u[0]==='"'&&u[u.length-1]==='"'){let E=u.slice(1,-1),S=!1;for(let v=0;v<E.length;v++){if(E[v]==='"'){S=!0;break}E[v]==="\\"&&v+1<E.length&&v++}S||(u=E,f=!0,d=!1)}}if(u==="")return{type:g.WORD,value:"",start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d};let w=yi.get(u);if(!f&&w!==void 0)return{type:w,value:u,start:t,end:o,line:n,column:r};if(!m){let E=rl(u);if(E>0&&nl(u.slice(0,E)))return{type:g.ASSIGNMENT_WORD,value:u,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(u)?{type:g.NUMBER,value:u,start:t,end:o,line:n,column:r}:Cd(u)?{type:g.NAME,value:u,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}:{type:g.WORD,value:u,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let n=this.pos,r=this.line,s=this.column,i="",o=!1;for(;this.pos<this.input.length;){let a="",l="",c="";for(;;){for(a="";this.pos<this.input.length&&this.input[this.pos]!==`
|
|
51
51
|
`;)a+=this.input[this.pos],this.pos++,this.column++;let f=0;for(let d=a.length-1;a[d]==="\\";d-=1)f+=1;if(c+=a,t.quoted||f%2===0||this.pos+1>=this.input.length)break;c=c.slice(0,-1),l+=`${a}
|
|
52
52
|
`,this.pos++,this.line++,this.column=1}if((t.stripTabs?c.replace(/^\t+/,""):c)===t.delimiter){o=!0,this.pos<this.input.length&&this.input[this.pos]===`
|
|
53
53
|
`&&(this.pos++,this.line++,this.column=1);break}if(i+=l,i+=a,this.pos<this.input.length&&this.input[this.pos]===`
|
|
54
54
|
`?(i+=`
|
|
55
55
|
`,this.pos++,this.line++,this.column=1):a.length>0&&(i+=`
|
|
56
|
-
`),i.length>this.maxHeredocSize)throw new Je(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,s)}this.tokens.push({type:
|
|
57
|
-
`?(f+=1,d=1):d+=1;return this.pos=a,this.line=f,this.column=d,this.pendingHeredocs.push({delimiter:o,stripTabs:s,quoted:l}),{type:
|
|
56
|
+
`),i.length>this.maxHeredocSize)throw new Je(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,s)}this.tokens.push({type:g.HEREDOC_CONTENT,value:i,start:n,end:this.pos,line:r,column:s,heredocTerminated:o})}}readHeredocDelimiterToken(t,n,r,s){let i=this.input,{delim:o,endPos:a,quoted:l,unclosedQuote:c,unclosedSubstitution:u}=Xr(i,t);if(c)throw new Je(`unexpected EOF while looking for matching \`${c}'`,n,r);if(u)throw new Je("unexpected EOF while looking for matching `)'",n,r);if(a===t)throw new Je("Expected here-document delimiter",n,r);let f=n,d=r;for(let h=t;h<a;h++)i[h]===`
|
|
57
|
+
`?(f+=1,d=1):d+=1;return this.pos=a,this.line=f,this.column=d,this.pendingHeredocs.push({delimiter:o,stripTabs:s,quoted:l}),{type:g.WORD,value:i.slice(t,a),start:t,end:a,line:n,column:r,quoted:l,heredocDelimiter:o}}isWordCharFollowing(t){if(t>=this.input.length)return!1;let n=this.input[t];return!(n===" "||n===" "||n===`
|
|
58
58
|
`||n===";"||n==="&"||n==="|"||n==="("||n===")"||n==="<"||n===">")}readWordWithBraceExpansion(t,n,r){let s=this.input,i=s.length,o=t,a=r;for(;o<i;){let c=s[o];if(c===" "||c===" "||c===`
|
|
59
|
-
`||c===";"||c==="&"||c==="|"||c==="("||c===")"||c==="<"||c===">")break;if(c==="{"){if(this.scanBraceExpansion(o)!==null){let f=1;for(o++,a++;o<i&&f>0;)s[o]==="{"?f++:s[o]==="}"&&f--,o++,a++;continue}o++,a++;continue}if(c==="}"){o++,a++;continue}if(c==="$"&&o+1<i&&s[o+1]==="("){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="("?u++:s[o]===")"&&u--,o++,a++;continue}if(c==="$"&&o+1<i&&s[o+1]==="{"){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="{"?u++:s[o]==="}"&&u--,o++,a++;continue}if(c==="`"){for(o++,a++;o<i&&s[o]!=="`";)s[o]==="\\"&&o+1<i?(o+=2,a+=2):(o++,a++);o<i&&(o++,a++);continue}o++,a++}let l=s.slice(t,o);return this.pos=o,this.column=a,{type:
|
|
59
|
+
`||c===";"||c==="&"||c==="|"||c==="("||c===")"||c==="<"||c===">")break;if(c==="{"){if(this.scanBraceExpansion(o)!==null){let f=1;for(o++,a++;o<i&&f>0;)s[o]==="{"?f++:s[o]==="}"&&f--,o++,a++;continue}o++,a++;continue}if(c==="}"){o++,a++;continue}if(c==="$"&&o+1<i&&s[o+1]==="("){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="("?u++:s[o]===")"&&u--,o++,a++;continue}if(c==="$"&&o+1<i&&s[o+1]==="{"){o++,a++,o++,a++;let u=1;for(;u>0&&o<i;)s[o]==="{"?u++:s[o]==="}"&&u--,o++,a++;continue}if(c==="`"){for(o++,a++;o<i&&s[o]!=="`";)s[o]==="\\"&&o+1<i?(o+=2,a+=2):(o++,a++);o<i&&(o++,a++);continue}o++,a++}let l=s.slice(t,o);return this.pos=o,this.column=a,{type:g.WORD,value:l,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}}scanBraceExpansion(t){let n=this.input,r=n.length,s=t+1,i=1,o=!1,a=!1;for(;s<r&&i>0;){let l=n[s];if(l==="{")i++,s++;else if(l==="}")i--,s++;else if(l===","&&i===1)o=!0,s++;else if(l==="."&&s+1<r&&n[s+1]===".")a=!0,s+=2;else{if(l===" "||l===" "||l===`
|
|
60
60
|
`||l===";"||l==="&"||l==="|")return null;s++}}return i===0&&(o||a)?n.slice(t,s):null}scanLiteralBraceWord(t){let n=this.input,r=n.length,s=t+1,i=1;for(;s<r&&i>0;){let o=n[s];if(o==="{")i++,s++;else if(o==="}"){if(i--,i===0)return n.slice(t,s+1);s++}else{if(o===" "||o===" "||o===`
|
|
61
61
|
`||o===";"||o==="&"||o==="|")return null;s++}}return null}scanExtglobPattern(t){let n=this.input,r=n.length,s=t+1,i=1;for(;s<r&&i>0;){let o=n[s];if(o==="\\"&&s+1<r){s+=2;continue}if("@*+?!".includes(o)&&s+1<r&&n[s+1]==="("){s++,i++,s++;continue}if(o==="(")i++,s++;else if(o===")")i--,s++;else{if(o===`
|
|
62
62
|
`)return null;s++}}return i===0?{content:n.slice(t,s),end:s}:null}scanFdVariable(t){let n=this.input,r=n.length,s=t+1,i=s;for(;s<r;){let u=n[s];if(s===i){if(!(u>="a"&&u<="z"||u>="A"&&u<="Z"||u==="_"))return null}else if(!(u>="a"&&u<="z"||u>="A"&&u<="Z"||u>="0"&&u<="9"||u==="_"))break;s++}if(s===i)return null;let o=n.slice(i,s);if(s>=r||n[s]!=="}"||(s++,s>=r))return null;let a=n[s],l=s+1<r?n[s+1]:"";return a===">"||a==="<"||a==="&"&&(l===">"||l==="<")?{varname:o,end:s}:null}dollarDparenIsSubshell(t){let n=this.input,r=n.length,s=t+1,i=2,o=!1,a=!1,l=!1;for(;s<r&&i>0;){let c=n[s];if(o){c==="'"&&(o=!1),c===`
|
|
@@ -64,215 +64,216 @@ Gid: ${s} ${s} ${s} ${s}
|
|
|
64
64
|
`&&(l=!0),s++;continue}if(c==="'"){o=!0,s++;continue}if(c==='"'){a=!0,s++;continue}if(c==="\\"){s+=2;continue}if(c===`
|
|
65
65
|
`&&(l=!0),c==="("){i++,s++;continue}if(c===")"){if(i--,i===1){let u=s+1;if(u<r&&n[u]===")")return!1;let f=u,d=!1;for(;f<r&&(n[f]===" "||n[f]===" "||n[f]===`
|
|
66
66
|
`);)d=!0,f++;if(d&&f<r&&n[f]===")"||l)return!0}if(i===0)return!1;s++;continue}s++}return!1}dparenClosesWithSpacedParens(t){let n=this.input,r=n.length,s=t,i=2,o=!1,a=!1;for(;s<r&&i>0;){let l=n[s];if(o){l==="'"&&(o=!1),s++;continue}if(a){if(l==="\\"){s+=2;continue}l==='"'&&(a=!1),s++;continue}if(l==="'"){o=!0,s++;continue}if(l==='"'){a=!0,s++;continue}if(l==="\\"){s+=2;continue}if(l==="("){i++,s++;continue}if(l===")"){if(i--,i===1){let c=s+1;if(c<r&&n[c]===")")return!1;let u=c,f=!1;for(;u<r&&(n[u]===" "||n[u]===" "||n[u]===`
|
|
67
|
-
`);)f=!0,u++;if(f&&u<r&&n[u]===")")return!0}if(i===0)return!1;s++;continue}if(i===1&&(l==="|"&&s+1<r&&n[s+1]==="|"||l==="&"&&s+1<r&&n[s+1]==="&"||l==="|"&&s+1<r&&n[s+1]!=="|"))return!0;s++}return!1}};var
|
|
68
|
-
`){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var
|
|
69
|
-
`;break;case"t":r+=" ";break;case"r":r+="\r";break;case"\\":r+="\\";break;case"'":r+="'";break;default:r+=i}n+=2}else r+=e[n],n++;e[n]==="'"&&n++;let s=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(s)?0:s},pos:n}}function al(e,t){if(e.slice(t,t+2)!=='$"')return null;let n=t+2,r="";for(;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?(r+=e[n+1],n+=2):(r+=e[n],n++);e[n]==='"'&&n++;let s=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(s)?0:s},pos:n}}function kd(e){let t="",n=0;for(;n<e.length;)if(e[n]==='"'){for(n++;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);n<e.length&&n++}else t+=e[n],n++;return t}function re(e,t){let n=kd(t),{expr:r,pos:s}=Wn(e,n,0),i=ye(n,s);if(i<n.length){let o=t.slice(i).trim();if(o)return{type:"ArithmeticExpression",originalText:t,expression:{type:"ArithSyntaxError",errorToken:o,message:`${o}: syntax error: invalid arithmetic operator (error token is "${o}")`}}}return{type:"ArithmeticExpression",expression:r,originalText:t}}function qe(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function Ge(e,t){return ye(e,t)>=e.length}function Wn(e,t,n){return xd(e,t,n)}function vn(e,t,n){return e.withDepth(()=>Wn(e,t,n))}function xd(e,t,n){let{expr:r,pos:s}=dr(e,t,n);for(s=ye(t,s);t[s]===",";){if(s++,Ge(t,s))return qe(",",s);let{expr:o,pos:a}=dr(e,t,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=ye(t,a)}return{expr:r,pos:s}}function dr(e,t,n){let{expr:r,pos:s}=Pd(e,t,n);if(s=ye(t,s),t[s]==="?"){s++;let{expr:i,pos:o}=vn(e,t,s);if(s=ye(t,o),t[s]===":"){s++;let{expr:a,pos:l}=vn(e,t,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:a},pos:l}}}return{expr:r,pos:s}}function Pd(e,t,n){let{expr:r,pos:s}=ll(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="||";){if(s+=2,Ge(t,s))return qe("||",s);let{expr:o,pos:a}=ll(e,t,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=a}return{expr:r,pos:s}}function ll(e,t,n){let{expr:r,pos:s}=cl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="&&";){if(s+=2,Ge(t,s))return qe("&&",s);let{expr:o,pos:a}=cl(e,t,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=a}return{expr:r,pos:s}}function cl(e,t,n){let{expr:r,pos:s}=ul(e,t,n);for(;s=ye(t,s),t[s]==="|"&&t[s+1]!=="|";){if(s++,Ge(t,s))return qe("|",s);let{expr:o,pos:a}=ul(e,t,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=a}return{expr:r,pos:s}}function ul(e,t,n){let{expr:r,pos:s}=fl(e,t,n);for(;s=ye(t,s),t[s]==="^";){if(s++,Ge(t,s))return qe("^",s);let{expr:o,pos:a}=fl(e,t,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=a}return{expr:r,pos:s}}function fl(e,t,n){let{expr:r,pos:s}=dl(e,t,n);for(;s=ye(t,s),t[s]==="&"&&t[s+1]!=="&";){if(s++,Ge(t,s))return qe("&",s);let{expr:o,pos:a}=dl(e,t,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=a}return{expr:r,pos:s}}function dl(e,t,n){let{expr:r,pos:s}=hl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="=="||t.slice(s,s+2)==="!=";){let i=t.slice(s,s+2);if(s+=2,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=hl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function hl(e,t,n){let{expr:r,pos:s}=gi(e,t,n);for(;;)if(s=ye(t,s),t.slice(s,s+2)==="<="||t.slice(s,s+2)===">="){let i=t.slice(s,s+2);if(s+=2,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=gi(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else if(t[s]==="<"||t[s]===">"){let i=t[s];if(s++,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=gi(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function gi(e,t,n){let{expr:r,pos:s}=pl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="<<"||t.slice(s,s+2)===">>";){let i=t.slice(s,s+2);if(s+=2,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=pl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function pl(e,t,n){let{expr:r,pos:s}=ml(e,t,n);for(;s=ye(t,s),(t[s]==="+"||t[s]==="-")&&t[s+1]!==t[s];){let i=t[s];if(s++,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=ml(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function ml(e,t,n){let{expr:r,pos:s}=Xr(e,t,n);for(;;)if(s=ye(t,s),t[s]==="*"&&t[s+1]!=="*"){if(s++,Ge(t,s))return qe("*",s);let{expr:o,pos:a}=Xr(e,t,s);r={type:"ArithBinary",operator:"*",left:r,right:o},s=a}else if(t[s]==="/"||t[s]==="%"){let i=t[s];if(s++,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=Xr(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function Xr(e,t,n){let{expr:r,pos:s}=wi(e,t,n),i=ye(t,s);if(t.slice(i,i+2)==="**"){if(i+=2,Ge(t,i))return qe("**",i);let{expr:a,pos:l}=e.withDepth(()=>Xr(e,t,i));return{expr:{type:"ArithBinary",operator:"**",left:r,right:a},pos:l}}return{expr:r,pos:s}}function wi(e,t,n){let r=ye(t,n);if(t.slice(r,r+2)==="++"||t.slice(r,r+2)==="--"){let s=t.slice(r,r+2);r+=2;let{expr:i,pos:o}=e.withDepth(()=>wi(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}if(t[r]==="+"||t[r]==="-"||t[r]==="!"||t[r]==="~"){let s=t[r];r++;let{expr:i,pos:o}=e.withDepth(()=>wi(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}return Cd(e,t,r)}function $d(e,t){let n=e[t];return n==="$"||n==="`"}function Cd(e,t,n){let{expr:r,pos:s}=yl(e,t,n,!1),i=[r];for(;$d(t,s);){let{expr:a,pos:l}=yl(e,t,s,!0);i.push(a),s=l}i.length>1&&(r={type:"ArithConcat",parts:i});let o;if(t[s]==="["&&r.type==="ArithConcat"){s++;let{expr:a,pos:l}=vn(e,t,s);o=a,s=l,t[s]==="]"&&s++}if(o&&r.type==="ArithConcat"&&(r={type:"ArithDynamicElement",nameExpr:r,subscript:o},o=void 0),s=ye(t,s),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let a of Kr)if(t.slice(s,s+a.length)===a&&t.slice(s,s+a.length+1)!=="=="){s+=a.length;let{expr:l,pos:c}=e.withDepth(()=>dr(e,t,s));return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r.nameExpr,subscript:r.subscript,value:l},pos:c}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r,value:l},pos:c}:{expr:{type:"ArithAssignment",operator:a,variable:r.name,value:l},pos:c}}}if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let a=t.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:a,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function yl(e,t,n,r=!1){let s=ye(t,n),i=il(vn,e,t,s);if(i)return i;let o=ol(t,s);if(o)return o;let a=al(t,s);if(a)return a;if(t.slice(s,s+2)==="$("&&t[s+2]!=="("){s+=2;let c=1,u=s;for(;s<t.length&&c>0;)t[s]==="("?c++:t[s]===")"&&c--,c>0&&s++;let f=t.slice(u,s);return s++,{expr:{type:"ArithCommandSubst",command:f},pos:s}}if(t[s]==="`"){s++;let c=s;for(;s<t.length&&t[s]!=="`";)s++;let u=t.slice(c,s);return t[s]==="`"&&s++,{expr:{type:"ArithCommandSubst",command:u},pos:s}}if(t[s]==="("){s++;let{expr:c,pos:u}=vn(e,t,s);return s=ye(t,u),t[s]===")"&&s++,{expr:{type:"ArithGroup",expression:c},pos:s}}if(t[s]==="'"){s++;let c="";for(;s<t.length&&t[s]!=="'";)c+=t[s],s++;t[s]==="'"&&s++;let u=Number.parseInt(c,10);return{expr:{type:"ArithSingleQuote",content:c,value:Number.isNaN(u)?0:u},pos:s}}if(t[s]==='"'){s++;let c="";for(;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?(c+=t[s+1],s+=2):(c+=t[s],s++);t[s]==='"'&&s++;let u=c.trim();if(!u)return{expr:{type:"ArithNumber",value:0},pos:s};let{expr:f}=vn(e,u,0);return{expr:f,pos:s}}if(/[0-9]/.test(t[s])){let c="",u=!1,f=!1;for(;s<t.length;){let h=t[s];if(u)if(/[0-9a-zA-Z@_]/.test(h))c+=h,s++;else break;else if(h==="#")u=!0,c+=h,s++;else if(c==="0"&&(h==="x"||h==="X")&&s+1<t.length&&/[0-9a-fA-F]/.test(t[s+1]))f=!0,c+=h,s++;else if(f&&/[0-9a-fA-F]/.test(h))c+=h,s++;else if(!f&&/[0-9]/.test(h))c+=h,s++;else break}if(s<t.length&&/[a-zA-Z_]/.test(t[s])){let h=c;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)h+=t[s],s++;return{expr:{type:"ArithSyntaxError",errorToken:h,message:`${h}: value too great for base (error token is "${h}")`},pos:s}}if(t[s]==="."&&/[0-9]/.test(t[s+1]))throw new le(`${c}.${t[s+1]}...: syntax error: invalid arithmetic operator`);if(t[s]==="["){let h=t.slice(s).trim();return{expr:{type:"ArithNumberSubscript",number:c,errorToken:h},pos:t.length}}return{expr:{type:"ArithNumber",value:fr(c)},pos:s}}if(t[s]==="$"&&t[s+1]==="{"){let c=s+2,u=1,f=c;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;let d=t.slice(c,f),h=f+1;if(t[h]==="#"){let p=h+1;for(;p<t.length&&/[0-9a-zA-Z@_]/.test(t[p]);)p++;let m=t.slice(h+1,p);return{expr:{type:"ArithDynamicBase",baseExpr:d,value:m},pos:p}}if(/[0-9]/.test(t[h])||t[h]==="x"||t[h]==="X"){let p=h;if(t[h]==="x"||t[h]==="X")for(p++;p<t.length&&/[0-9a-fA-F]/.test(t[p]);)p++;else for(;p<t.length&&/[0-9]/.test(t[p]);)p++;let m=t.slice(h,p);return{expr:{type:"ArithDynamicNumber",prefix:d,suffix:m},pos:p}}return s=h,{expr:{type:"ArithBracedExpansion",content:d},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[0-9]/.test(t[s+1])){s++;let c="";for(;s<t.length&&/[0-9]/.test(t[s]);)c+=t[s],s++;return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:!0},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[*@#?\-!$]/.test(t[s+1])){let c=t[s+1];return s+=2,{expr:{type:"ArithSpecialVar",name:c},pos:s}}let l=!1;if(t[s]==="$"&&s+1<t.length&&/[a-zA-Z_]/.test(t[s+1])&&(l=!0,s++),s<t.length&&/[a-zA-Z_]/.test(t[s])){let c="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)c+=t[s],s++;if(t[s]==="["&&!r){s++;let u;if(t[s]==="'"||t[s]==='"'){let d=t[s];for(s++,u="";s<t.length&&t[s]!==d;)u+=t[s],s++;t[s]===d&&s++,s=ye(t,s),t[s]==="]"&&s++}let f;if(u===void 0){let{expr:d,pos:h}=vn(e,t,s);f=d,s=h,t[s]==="]"&&s++}if(s=ye(t,s),t[s]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:c,index:f},pos:s};if(!r){for(let d of Kr)if(t.slice(s,s+d.length)===d&&t.slice(s,s+d.length+1)!=="=="){s+=d.length;let{expr:h,pos:p}=e.withDepth(()=>dr(e,t,s));return{expr:{type:"ArithAssignment",operator:d,variable:c,subscript:f,stringKey:u,value:h},pos:p}}}return{expr:{type:"ArithArrayElement",array:c,index:f,stringKey:u},pos:s}}if(s=ye(t,s),!r){for(let u of Kr)if(t.slice(s,s+u.length)===u&&t.slice(s,s+u.length+1)!=="=="){s+=u.length;let{expr:f,pos:d}=e.withDepth(()=>dr(e,t,s));return{expr:{type:"ArithAssignment",operator:u,variable:c,value:f},pos:d}}}return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:l},pos:s}}if(t[s]==="#"){let c=s+1;for(;c<t.length&&t[c]!==`
|
|
70
|
-
`;)c++;let u=t.slice(s,c).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:u,message:`${u}: syntax error: invalid arithmetic operator (error token is "${u}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:s}}var
|
|
71
|
-
`,s+=2;break;case"t":r+=" ",s+=2;break;case"r":r+="\r",s+=2;break;case"\\":r+="\\",s+=2;break;case"'":r+="'",s+=2;break;case'"':r+='"',s+=2;break;case"a":r+="\x07",s+=2;break;case"b":r+="\b",s+=2;break;case"e":case"E":r+="\x1B",s+=2;break;case"f":r+="\f",s+=2;break;case"v":r+="\v",s+=2;break;case"x":{let a=[],l=s;for(;l+1<t.length&&t[l]==="\\"&&t[l+1]==="x";){let c=t.slice(l+2,l+4),u=parseInt(c,16);if(!Number.isNaN(u)&&c.length>0)a.push(u),l+=2+c.length;else break}a.length>0?(r+=Nd(a),s=l):(r+="\\x",s+=2);break}case"u":{let a=t.slice(s+2,s+6),l=parseInt(a,16);Number.isNaN(l)?(r+="\\u",s+=2):(r+=String.fromCharCode(l),s+=6);break}case"c":{if(s+2<t.length){let l=t[s+2].charCodeAt(0)&31;r+=String.fromCharCode(l),s+=3}else r+="\\c",s+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let a="",l=s+1;for(;l<t.length&&l<s+4&&/[0-7]/.test(t[l]);)a+=t[l],l++;let c=parseInt(a,8);r+=String.fromCharCode(c),s=l;break}default:r+=i,s++}else r+=i,s++}return s<t.length&&t[s]==="'"&&s++,{part:F.literal(r),endIndex:s}}function bi(e,t){let n=t.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:re(e,n)}function wl(e){let t=[],n="",r=0;for(let s=0;s<e.length;s++){let i=e[s];i==="{"?(r++,n+=i):i==="}"?(r--,n+=i):i===","&&r===0?(t.push(n),n=""):n+=i}return t.push(n),t}function vl(e,t,n,r){let s=Ei(e,t,n,"{","}");if(s===-1)return null;let i=t.slice(n+1,s),o=i.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(o)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(o[1],10),end:Number.parseInt(o[2],10),step:o[3]?Number.parseInt(o[3],10):void 0,startStr:o[1],endStr:o[2]}]},endIndex:s+1};let a=i.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return a?{part:{type:"BraceExpansion",items:[{type:"Range",start:a[1],end:a[2],step:a[3]?Number.parseInt(a[3],10):void 0}]},endIndex:s+1}:i.includes(",")&&r?{part:{type:"BraceExpansion",items:wl(i).map(u=>e.withDepth(()=>({type:"Word",word:F.word(r(e,u,!1,!1,!1))})))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:wl(i).map(u=>({type:"Word",word:F.word([F.literal(u)])}))},endIndex:s+1}:null}function Si(e,t){let n="";for(let r of t.parts)switch(r.type){case"Literal":n+=r.value;break;case"SingleQuoted":n+=`'${r.value}'`;break;case"Escaped":n+=r.value;break;case"DoubleQuoted":n+='"';for(let s of r.parts)s.type==="Literal"||s.type==="Escaped"?n+=s.value:s.type==="ParameterExpansion"&&(n+=`\${${s.parameter}}`);n+='"';break;case"ParameterExpansion":n+=`\${${r.parameter}}`;break;case"Glob":n+=r.pattern;break;case"TildeExpansion":n+="~",r.user&&(n+=r.user);break;case"BraceExpansion":{n+="{";let s=[];for(let i of r.items)if(i.type==="Range"){let o=i.startStr??String(i.start),a=i.endStr??String(i.end);i.step!==void 0?s.push(`${o}..${a}..${i.step}`):s.push(`${o}..${a}`)}else s.push(Si(e,i.word));s.length===1&&r.items[0].type==="Range"?n+=s[0]:n+=s.join(","),n+="}";break}default:n+=r.type}return n}function kl(e,t){return{[w.LESS]:"<",[w.GREAT]:">",[w.DGREAT]:">>",[w.LESSAND]:"<&",[w.GREATAND]:">&",[w.LESSGREAT]:"<>",[w.CLOBBER]:">|",[w.TLESS]:"<<<",[w.AND_GREAT]:"&>",[w.AND_DGREAT]:"&>>",[w.DLESS]:"<",[w.DLESSDASH]:"<"}[t]||">"}function hr(e){let t=e.current(),n=t.type;if(n===w.NUMBER){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:rl.has(r.type)}if(n===w.FD_VARIABLE){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:sl.has(r.type)}return!e.isProcessSubstitutionStart()&&nl.has(n)}function Jr(e){let t=null,n;e.check(w.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(w.FD_VARIABLE)&&(n=e.advance().value);let r=e.advance(),s=kl(e,r.type);if(r.type===w.DLESS||r.type===w.DLESSDASH)return Od(e,t,n,r.type===w.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return F.redirection(s,i,t,n)}function Od(e,t,n,r){e.isWord()||e.error("Expected here-document delimiter");let s=e.advance(),i=s.heredocDelimiter??s.value,o=s.quoted||!1,a=F.redirection(r?"<<-":"<<",F.hereDoc(i,F.word([]),r,o),t,n);return e.addPendingHeredoc(a,i,r,o),a}function vi(e){let t=e.getSourceLine(),n=[],r=null,s=[],i=[];for(;e.check(w.ASSIGNMENT_WORD)||hr(e);)e.checkIterationLimit(),e.check(w.ASSIGNMENT_WORD)?n.push(Dd(e)):i.push(Jr(e));if(e.isWord())r=e.parseWord();else if(n.length>0&&(e.check(w.DBRACK_START)||e.check(w.DPAREN_START))){let a=e.advance();r=F.word([F.literal(a.value)])}for(;(!e.isStatementEnd()||e.check(w.RBRACE))&&!e.check(w.PIPE,w.PIPE_AMP);)if(e.checkIterationLimit(),hr(e))i.push(Jr(e));else if(e.check(w.ASSIGNMENT_WORD)){let a=e.advance(),l=a.value,c=l.endsWith("="),u=l.endsWith("=(");if((c||u)&&(u||e.check(w.LPAREN))){let f=u?l.slice(0,-2):l.slice(0,-1);u||e.expect(w.LPAREN);let d=Ai(e);e.expect(w.RPAREN);let h=d.map(m=>Si(e,m)),p=`${f}=(${h.join(" ")})`;s.push(e.parseWordFromString(p,!1,!1,!0))}else{let f=e.parseWordFromString(l,a.quoted,a.singleQuoted,!0);s.push(e.parseAdjacentWordParts(f.parts,a.end,Re.Assignment))}}else if(e.isWord())s.push(e.parseWord());else if(e.check(w.RBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.LBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.DBRACK_END)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.LPAREN))e.error("syntax error near unexpected token `('");else break;let o=F.simpleCommand(r,s,n,i);return o.line=t,o}function Dd(e){let t=e.expect(w.ASSIGNMENT_WORD),n=t.value,r=n.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||e.error(`Invalid assignment: ${n}`);let s=r[0],i,o=s.length;if(n[o]==="["){let f=0,d=o+1;for(;o<n.length;o++)if(n[o]==="[")f++;else if(n[o]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${n}`),i=Yr(n.slice(d,o)),o++}let a=n[o]==="+";a&&o++,n[o]!=="="&&e.error(`Invalid assignment: ${n}`),o++;let l=n.slice(o);if(l==="("){let f=Ai(e);e.expect(w.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return F.assignment(d,null,a,f)}if(l===""&&e.check(w.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=Ai(e);e.expect(w.RPAREN);let h=i!==void 0?`${s}[${i}]`:s;return F.assignment(h,null,a,d)}}let c=l?e.parseWordFromString(l,t.quoted,t.singleQuoted,!0):null;t.end===e.current().start&&e.isProcessSubstitutionStart()&&(c=e.parseAdjacentWordParts(c?.parts??[],t.end,Re.Assignment));let u=i!==void 0?`${s}[${i}]`:s;return F.assignment(u,c,a,null)}var Id=new Set([w.AMP,w.PIPE,w.PIPE_AMP,w.SEMICOLON,w.AND_AND,w.OR_OR,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND]);function Ai(e){let t=[];for(e.skipNewlines();!e.check(w.RPAREN,w.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):Id.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function ki(e,t){e.expect(w.IF);let n=[],r=e.parseCompoundList();e.expect(w.THEN);let s=e.parseCompoundList();if(s.length===0){let a=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${a}'`)}for(n.push({condition:r,body:s});e.check(w.ELIF);){e.advance();let a=e.parseCompoundList();e.expect(w.THEN);let l=e.parseCompoundList();if(l.length===0){let c=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${c}'`)}n.push({condition:a,body:l})}let i=null;e.check(w.ELSE)&&(e.advance(),i=e.parseCompoundList(),i.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(w.FI);let o=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.ifNode(n,i,o)}function xi(e,t){let n=e.expect(w.FOR);if(e.check(w.DPAREN_START))return Td(e,t,e.getSourceLine(n));e.isWord()||e.error("Expected variable name in for loop");let s=e.advance().value,i=null;if(e.skipNewlines(),e.check(w.IN))for(e.advance(),i=[];!e.check(w.SEMICOLON,w.NEWLINE,w.DO,w.EOF)&&e.isWord();)i.push(e.parseWord());e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(w.DO);let o=e.parseCompoundList();e.expect(w.DONE);let a=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.forNode(s,i,o,a)}function Td(e,t,n){e.expect(w.DPAREN_START);let r=null,s=null,i=null,o=["","",""],a=0,l=0;for(;!e.check(w.DPAREN_END,w.EOF);){let f=e.advance();if(f.type===w.SEMICOLON&&l===0){if(a++,a>2)break}else f.value==="("&&l++,f.value===")"&&l--,o[a]+=f.value}e.expect(w.DPAREN_END),o[0].trim()&&(r=re(e,o[0].trim())),o[1].trim()&&(s=re(e,o[1].trim())),o[2].trim()&&(i=re(e,o[2].trim())),e.skipNewlines(),e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines();let c;e.check(w.LBRACE)?(e.advance(),c=e.parseCompoundList(),e.expect(w.RBRACE)):(e.expect(w.DO),c=e.parseCompoundList(),e.expect(w.DONE));let u=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:s,update:i,body:c,redirections:u,line:n}}function Pi(e,t){e.expect(w.WHILE);let n=e.parseCompoundList();e.expect(w.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(w.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.whileNode(n,r,s)}function $i(e,t){e.expect(w.UNTIL);let n=e.parseCompoundList();e.expect(w.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(w.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.untilNode(n,r,s)}function Ci(e,t){e.expect(w.CASE),e.isWord()||e.error("Expected word after 'case'");let n=e.parseWord();e.skipNewlines(),e.expect(w.IN),e.skipNewlines();let r=[];for(;!e.check(w.ESAC,w.EOF);){e.checkIterationLimit();let i=e.getPos(),o=Ld(e);if(o&&r.push(o),e.skipNewlines(),e.getPos()===i&&!o)break}e.expect(w.ESAC);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.caseNode(n,r,s)}function Ld(e){e.check(w.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(w.PIPE));)e.advance();if(t.length===0)return null;e.expect(w.RPAREN),e.skipNewlines();let n=[];for(;!e.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND,w.ESAC,w.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===w.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(w.LPAREN)&&e.peek(1).type===w.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let s=e.getPos(),i=e.parseStatement();if(i&&n.push(i),e.skipSeparators(!1),e.getPos()===s&&!i)break}let r=";;";return e.check(w.DSEMI)?(e.advance(),r=";;"):e.check(w.SEMI_AND)?(e.advance(),r=";&"):e.check(w.SEMI_SEMI_AND)&&(e.advance(),r=";;&"),F.caseItem(t,n,r)}function Ni(e,t){e.expect(w.LPAREN);let n=e.parseCompoundList();e.expect(w.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.subshell(n,r)}function Ri(e,t){e.expect(w.LBRACE);let n=e.parseCompoundList();e.expect(w.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.group(n,r)}var Md=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],Bd=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function Pl(e){return e.isWord()||e.check(w.LBRACE)||e.check(w.RBRACE)||e.check(w.ASSIGNMENT_WORD)}function $l(e){if(e.check(w.BANG)&&e.peek(1).type===w.LPAREN){e.advance(),e.advance();let t=1,n="!(";for(;t>0&&!e.check(w.EOF);)if(e.check(w.LPAREN))t++,n+="(",e.advance();else if(e.check(w.RPAREN))t--,t>0&&(n+=")"),e.advance();else if(e.isWord())n+=e.advance().value;else if(e.check(w.PIPE))n+="|",e.advance();else break;return n+=")",e.parseWordFromString(n,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function Di(e){return e.skipNewlines(),Wd(e)}function Wd(e){let t=Cl(e);for(e.skipNewlines();e.check(w.OR_OR);){e.advance(),e.skipNewlines();let n=Cl(e);t={type:"CondOr",left:t,right:n},e.skipNewlines()}return t}function Cl(e){let t=Oi(e);for(e.skipNewlines();e.check(w.AND_AND);){e.advance(),e.skipNewlines();let n=Oi(e);t={type:"CondAnd",left:t,right:n},e.skipNewlines()}return t}function Oi(e){return e.skipNewlines(),e.check(w.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:e.withDepth(()=>Oi(e))}):Vd(e)}function Vd(e){if(e.check(w.LPAREN)){e.advance();let t=e.withDepth(()=>Di(e));return e.expect(w.RPAREN),{type:"CondGroup",expression:t}}if(Pl(e)){let t=e.current(),n=t.value;if(Md.includes(n)&&!t.quoted){if(e.advance(),e.check(w.DBRACK_END)&&e.error(`Expected operand after ${n}`),Pl(e)){let i=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:n,operand:i}}let s=e.current();e.error(`unexpected argument \`${s.value}' to conditional unary operator`)}let r=e.parseWordNoBraceExpansion();if(e.isWord()&&Bd.includes(e.current().value)){let s=e.advance().value,i;return s==="=~"?i=zd(e):s==="=="||s==="!="?i=$l(e):i=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:s,left:r,right:i}}if(e.check(w.LESS)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:r,right:s}}if(e.check(w.GREAT)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:r,right:s}}if(e.isWord()&&e.current().value==="="){e.advance();let s=$l(e);return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function zd(e){let t=[],n=0,r=-1,s=e.getInput(),i=()=>e.check(w.DBRACK_END)||e.check(w.AND_AND)||e.check(w.OR_OR)||e.check(w.NEWLINE)||e.check(w.EOF);for(;!i();){let o=e.current(),a=r>=0&&o.start>r;if(n===0&&a)break;if(n>0&&a){let l=s.slice(r,o.start);t.push({type:"Literal",value:l})}if(e.isWord()||e.check(w.ASSIGNMENT_WORD)){let l=e.parseWordForRegex();t.push(...l.parts),r=e.peek(-1).end}else if(e.check(w.LPAREN)){let l=e.advance();t.push({type:"Literal",value:"("}),n++,r=l.end}else if(e.check(w.DPAREN_START)){let l=e.advance();t.push({type:"Literal",value:"(("}),n+=2,r=l.end}else if(e.check(w.DPAREN_END))if(n>=2){let l=e.advance();t.push({type:"Literal",value:"))"}),n-=2,r=l.end}else{if(n===1)break;break}else if(e.check(w.RPAREN))if(n>0){let l=e.advance();t.push({type:"Literal",value:")"}),n--,r=l.end}else break;else if(e.check(w.PIPE)){let l=e.advance();t.push({type:"Literal",value:"|"}),r=l.end}else if(e.check(w.SEMICOLON))if(n>0){let l=e.advance();t.push({type:"Literal",value:";"}),r=l.end}else break;else if(n>0&&e.check(w.LESS)){let l=e.advance();t.push({type:"Literal",value:"<"}),r=l.end}else if(n>0&&e.check(w.GREAT)){let l=e.advance();t.push({type:"Literal",value:">"}),r=l.end}else if(n>0&&e.check(w.DGREAT)){let l=e.advance();t.push({type:"Literal",value:">>"}),r=l.end}else if(n>0&&e.check(w.DLESS)){let l=e.advance();t.push({type:"Literal",value:"<<"}),r=l.end}else if(n>0&&e.check(w.LESSAND)){let l=e.advance();t.push({type:"Literal",value:"<&"}),r=l.end}else if(n>0&&e.check(w.GREATAND)){let l=e.advance();t.push({type:"Literal",value:">&"}),r=l.end}else if(n>0&&e.check(w.LESSGREAT)){let l=e.advance();t.push({type:"Literal",value:"<>"}),r=l.end}else if(n>0&&e.check(w.CLOBBER)){let l=e.advance();t.push({type:"Literal",value:">|"}),r=l.end}else if(n>0&&e.check(w.TLESS)){let l=e.advance();t.push({type:"Literal",value:"<<<"}),r=l.end}else if(n>0&&e.check(w.AMP)){let l=e.advance();t.push({type:"Literal",value:"&"}),r=l.end}else if(n>0&&e.check(w.LBRACE)){let l=e.advance();t.push({type:"Literal",value:"{"}),r=l.end}else if(n>0&&e.check(w.RBRACE)){let l=e.advance();t.push({type:"Literal",value:"}"}),r=l.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function jd(e){let t="";for(let n=0;n<e.length;n++){let r=e[n],s=e[n+1];if(r!=="\\"||s===void 0){t+=r;continue}"\\[]^-".includes(s)&&(t+="\\"),t+=s,n++}return t}function pr(e){return e.length>0?e:[F.literal("")]}function qd(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if("@*+?!".includes(s)&&r+1<e.length&&e[r+1]==="("){r++,n++,r++;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function Gd(e,t,n){let r=n+1,s=t[r];if("@*#?$!-0123456789".includes(s))return{part:F.parameterExpansion(s),endIndex:r+1};let i="";for(;r<t.length&&/[a-zA-Z0-9_]/.test(t[r]);)i+=t[r],r++;return{part:F.parameterExpansion(i),endIndex:r}}function Hd(e,t,n,r=!1){let s=n+2,i=!1;t[s]==="!"&&(i=!0,s++);let o=!1;t[s]==="#"&&!/[}:#%/^,]/.test(t[s+1]||"}")&&(o=!0,s++);let a="",l=t[s];if(/[@*#?$!-]/.test(l)&&!/[a-zA-Z0-9_]/.test(t[s+1]||""))a=l,s++;else for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)a+=t[s],s++;if(t[s]==="["){let u=Ei(e,t,s,"[","]");if(a+=`[${Yr(t.slice(s+1,u))}]`,s=u+1,t[s]==="["){let f=1,d=s;for(;d<t.length&&f>0;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let h=t.slice(n+2,d);return{part:F.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:d+1}}}if(a===""&&!i&&!o&&t[s]!=="}"){let u=1,f=s;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;if(u>0)throw new Pe("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(n+2,f);return{part:F.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let c=null;if(i){let u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Ii(e,t,s,a,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):(c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="")}else c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="";else if(t[s]==="*"||t[s]==="@"&&!/[QPaAEKkuUL]/.test(t[s+1]||"")){let f=t[s];s++,c={type:"VarNamePrefix",prefix:a,star:f==="*"},a=""}else if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Ii(e,t,s,a,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):c={type:"Indirection"}}else c={type:"Indirection"}}else if(o)if(t[s]===":")for(c={type:"LengthSliceError"};s<t.length&&t[s]!=="}";)s++;else t[s]!=="}"&&/[-+=?]/.test(t[s])?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):t[s]==="/"?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):c={type:"Length"};if(!c&&s<t.length&&t[s]!=="}"){let u=Ii(e,t,s,a,r);c=u.operation,s=u.endIndex}if(s<t.length&&t[s]!=="}"){let u=t[s];if(!/[:\-+=?#%/^,@[]/.test(u)){let f=s;for(;f<t.length&&t[f]!=="}";)f++;let d=t.slice(n,f+1);e.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<t.length&&t[s]!=="}";)s++;if(s>=t.length)throw new Pe("unexpected EOF while looking for matching '}'",0,0);return{part:F.parameterExpansion(a,c),endIndex:s+1}}function Ii(e,t,n,r,s=!1){let i=n,o=t[i],a=t[i+1]||"";if(o===":"){let l=a;if("-=?+".includes(l)){i+=2;let S=kn(e,t,i),y=t.slice(i,S),g=e.withDepth(()=>Jt(e,y,!1,!1,!0,!1,s,!1,!1,!0)),b=F.word(pr(g));if(l==="-")return{operation:{type:"DefaultValue",word:b,checkEmpty:!0},endIndex:S};if(l==="=")return{operation:{type:"AssignDefault",word:b,checkEmpty:!0},endIndex:S};if(l==="?")return{operation:{type:"ErrorIfUnset",word:b,checkEmpty:!0},endIndex:S};if(l==="+")return{operation:{type:"UseAlternative",word:b,checkEmpty:!0},endIndex:S}}i++;let c=kn(e,t,i),u=t.slice(i,c),f=-1,d=0,h=0;for(let E=0;E<u.length;E++){let S=u[E];if(S==="("||S==="[")d++;else if(S===")"||S==="]")d--;else if(S==="?"&&d===0)h++;else if(S===":"&&d===0)if(h>0)h--;else{f=E;break}}let p=f>=0?u.slice(0,f):u,m=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:bi(e,p),length:m!==null?bi(e,m):null},endIndex:c}}if("-=?+".includes(o)){i++;let l=kn(e,t,i),c=t.slice(i,l),u=e.withDepth(()=>Jt(e,c,!1,!1,!0,!1,s,!1,!1,!0)),f=F.word(pr(u));if(o==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:l};if(o==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:l};if(o==="?")return{operation:{type:"ErrorIfUnset",word:c?f:null,checkEmpty:!1},endIndex:l};if(o==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:l}}if(o==="#"||o==="%"){let l=a===o,c=o==="#"?"prefix":"suffix";i+=l?2:1;let u=kn(e,t,i),f=t.slice(i,u),d=e.withDepth(()=>Jt(e,f,!1,!1,!1));return{operation:{type:"PatternRemoval",pattern:F.word(pr(d)),side:c,greedy:l},endIndex:u}}if(o==="/"){let l=a==="/";i+=l?2:1;let c=null;t[i]==="#"?(c="start",i++):t[i]==="%"&&(c="end",i++);let u;c!==null&&(t[i]==="/"||t[i]==="}")?u=i:u=bl(e,t,i);let f=t.slice(i,u),d=e.withDepth(()=>Jt(e,f,!1,!1,!1)),h=F.word(pr(d)),p=null,m=u;if(t[u]==="/"){let E=u+1,S=kn(e,t,E),y=t.slice(E,S),g=e.withDepth(()=>Jt(e,y,!1,!1,!1));p=F.word(pr(g)),m=S}return{operation:{type:"PatternReplacement",pattern:h,replacement:p,all:l,anchor:c},endIndex:m}}if(o==="^"||o===","){let l=a===o,c=o==="^"?"upper":"lower";i+=l?2:1;let u=kn(e,t,i),f=t.slice(i,u),d=f?F.word([F.literal(f)]):null;return{operation:{type:"CaseModification",direction:c,all:l,pattern:d},endIndex:u}}return o==="@"&&/[QPaAEKkuUL]/.test(a)?{operation:{type:"Transform",operator:a},endIndex:i+2}:{operation:null,endIndex:i}}function _i(e,t,n,r=!1){let s=n+1;if(s>=t.length)return{part:F.literal("$"),endIndex:s};let i=t[s];if(i==="("&&t[s+1]==="(")return e.isDollarDparenSubshell(t,n)?e.parseCommandSubstitution(t,n):e.parseArithmeticExpansion(t,n);if(i==="["){let o=1,a=s+1;for(;a<t.length&&o>0;)t[a]==="["?o++:t[a]==="]"&&o--,o>0&&a++;if(o===0){let l=t.slice(s+1,a),c=re(e,l);return{part:F.arithmeticExpansion(c),endIndex:a+1}}}return i==="("?e.parseCommandSubstitution(t,n):i==="{"?Hd(e,t,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?Gd(e,t,n):{part:F.literal("$"),endIndex:s}}function Nl(e,t){let n=[],r=0,s="",i=()=>{s&&(n.push(F.literal(s)),s="")};for(;r<t.length;){let o=t[r];if(o==="\\"&&r+1<t.length){let a=t[r+1];if(a==="$"||a==="`"||a==='"'||a==="\\"){s+=a,r+=2;continue}s+=o,r++;continue}if(o==="$"){i();let{part:a,endIndex:l}=_i(e,t,r,!0);a&&n.push(a),r=l;continue}if(o==="`"){i();let{part:a,endIndex:l}=e.parseBacktickSubstitution(t,r,!0);n.push(a),r=l;continue}s+=o,r++}return i(),n}function Zd(e,t,n){let r=[],s=n,i="",o=()=>{i&&(r.push(F.literal(i)),i="")};for(;s<t.length&&t[s]!=='"';){let a=t[s];if(a==="\\"&&s+1<t.length){let l=t[s+1];if('"\\$`\n'.includes(l)){i+=l,s+=2;continue}i+=a,s++;continue}if(a==="$"){o();let{part:l,endIndex:c}=_i(e,t,s,!0);l&&r.push(l),s=c;continue}if(a==="`"){o();let{part:l,endIndex:c}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=c;continue}i+=a,s++}return o(),{part:F.doubleQuoted(r),endIndex:s}}function Jt(e,t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!0){if(r)return[F.singleQuoted(t)];if(n){let m=Nl(e,t);return[F.doubleQuoted(m)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let m=t.slice(1,-1),E=!1;for(let S=0;S<m.length;S++){if(m[S]==='"'){E=!0;break}m[S]==="\\"&&S+1<m.length&&S++}if(!E){let S=Nl(e,m);return[F.doubleQuoted(S)]}}let f=[],d=0,h="",p=()=>{h&&(f.push(F.literal(h)),h="")};for(;d<t.length;){let m=t[d];if(m==="\\"&&d+1<t.length){let E=t[d+1];if(l){p(),f.push(F.escaped(E)),d+=2;continue}if(!i&&!o){E!==`
|
|
72
|
-
`&&(p(),f.push(
|
|
73
|
-
`:
|
|
74
|
-
`||c&&
|
|
75
|
-
`&&(h+=E):y?(p(),f.push(F.escaped(E))):h+=`\\${E}`,d+=2;continue}if(m==="'"&&!o&&!i){p();let E=t.indexOf("'",d+1);if(E===-1){h+=t.slice(d);break}f.push(F.singleQuoted(t.slice(d+1,E))),d=E+1;continue}if(m==='"'&&!i){p();let{part:E,endIndex:S}=Zd(e,t,d+1);f.push(E),d=S+1;continue}if(m==="$"&&t[d+1]==="'"){p();let{part:E,endIndex:S}=Al(e,t,d+2);f.push(E),d=S;continue}if(m==="$"){p();let{part:E,endIndex:S}=_i(e,t,d);E&&f.push(E),d=S;continue}if(m==="`"){p();let{part:E,endIndex:S}=e.parseBacktickSubstitution(t,d);f.push(E),d=S;continue}if((m==="<"||m===">")&&t[d+1]==="("&&!i&&!o){p();let{part:E,endIndex:S}=e.parseProcessSubstitutionFromString(t,d);f.push(E),d=S;continue}if(m==="~"){let E=d>0?t[d-1]:"";if(d===0&&u||E==="="||s&&E===":"){let y=El(e,t,d),g=t[y];if(g===void 0||g==="/"||g===":"){p();let b=t.slice(d+1,y)||null;f.push({type:"TildeExpansion",user:b}),d=y;continue}}}if("@*+?!".includes(m)&&d+1<t.length&&t[d+1]==="("){let E=qd(t,d+1);if(E!==-1){p();let S=t.slice(d,E+1);f.push({type:"Glob",pattern:S}),d=E+1;continue}}if(m==="*"||m==="?"||m==="["){p();let{pattern:E,endIndex:S}=Sl(e,t,d);f.push({type:"Glob",pattern:l?jd(E):E}),d=S;continue}if(m==="{"&&!s&&!a&&!i){let E=vl(e,t,d,Jt);if(E){p(),f.push(E.part),d=E.endIndex;continue}}h+=m,d++}return p(),f}var Z=class e{tokens=[];pos=0;pendingHeredocs=[];parseBudget;ownsParseBudget;_input="";processLineState;constructor(t){this.parseBudget=t??new Qr,this.ownsParseBudget=t===void 0}getInput(){return this._input}checkIterationLimit(){let t=this.current();this.parseBudget.chargeIteration(t?.line??1,t?.column??1)}enterDepth(){let t=this.current();return this.parseBudget.enter(t?.line??1,t?.column??1)}withDepth(t){let n=this.enterDepth();try{return t()}finally{n()}}parse(t,n){this.ownsParseBudget&&this.parseBudget.reset();let r=this.ownsParseBudget?void 0:this.enterDepth();try{if(t.length>yi)throw new Pe(`Input too large: ${t.length} bytes exceeds limit of ${yi}`,1,1);this._input=t,this.processLineState=void 0;let s=new Zr(t,n);if(this.tokens=s.tokenize(),this.tokens.length>ur)throw new Pe(`Too many tokens: ${this.tokens.length} exceeds limit of ${ur}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseBudget.chargeTokens(this.tokens.length),this.parseScript()}finally{r?.()}}parseTokens(t){this.ownsParseBudget&&this.parseBudget.reset();let n=this.ownsParseBudget?void 0:this.enterDepth();try{return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.processLineState=void 0,this.parseBudget.chargeTokens(t.length),this.parseScript()}finally{n?.()}}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}getSourceLine(t=this.current()){let n=this.processLineState;return n?(n.currentPhysicalLine===void 0?n.currentPhysicalLine=t.line:t.line>n.currentPhysicalLine&&(n.currentPhysicalLine=t.line,n.currentLogicalLine+=1),n.currentLogicalLine):t.line}check(t,n,r,s,...i){let o=this.tokens[this.pos]?.type;return o===t||n!==void 0&&o===n||r!==void 0&&o===r||s!==void 0&&o===s?!0:i.length>0?i.includes(o):!1}expect(t,n){if(this.check(t))return this.advance();let r=this.current();throw new Pe(n||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let n=this.current();throw new Pe(t,n.line,n.column,n)}skipNewlines(){for(;this.check(w.NEWLINE,w.COMMENT);)this.check(w.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(w.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(w.SEMICOLON,w.COMMENT)){this.advance();continue}if(t&&this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,n,r,s){this.pendingHeredocs.push({redirect:t,delimiter:n,stripTabs:r,quoted:s})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(w.HEREDOC_CONTENT)){let n=this.advance(),r;t.quoted?r=F.word([F.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),t.redirect.target=F.hereDoc(t.delimiter,r,t.stripTabs,t.quoted,n.heredocTerminated??!1)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(w.EOF,w.NEWLINE,w.SEMICOLON,w.AMP,w.AND_AND,w.OR_OR,w.RPAREN,w.RBRACE,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return this.isWord()||t===w.ASSIGNMENT_WORD||t===w.FD_VARIABLE||t===w.LPAREN||t===w.LBRACE||t===w.DPAREN_START||t===w.DBRACK_START||hr(this)}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(w.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)");let s=this.checkUnexpectedToken();if(s){t.push(s),this.skipSeparators(!1);continue}let i=this.pos,o=this.parseStatement();o&&t.push(o),this.check(w.HEREDOC_CONTENT)&&this.processHeredocs(),this.skipSeparators(!1),this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(w.EOF)&&this.error(`syntax error near unexpected token \`${this.current().value}'`)}return F.script(t)}checkUnexpectedToken(){let t=this.current().type,n=this.current().value;if(this.currentTokenJoinsProcessSubstitution())return null;if((t===w.DO||t===w.DONE||t===w.THEN||t===w.ELSE||t===w.ELIF||t===w.FI||t===w.ESAC)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.RBRACE||t===w.RPAREN){let r=`syntax error near unexpected token \`${n}'`;return this.advance(),F.statement([F.pipeline([F.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:n})}return(t===w.DSEMI||t===w.SEMI_AND||t===w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`),(t===w.AMP||t===w.AND_AND||t===w.OR_OR||t===w.PIPE||t===w.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${n}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,n=[],r=[],s=!1,i=this.parsePipeline();for(n.push(i);this.check(w.AND_AND,w.OR_OR);){let l=this.advance();r.push(l.type===w.AND_AND?"&&":"||"),this.skipNewlines();let c=this.parsePipeline();n.push(c)}this.check(w.AMP)&&(this.advance(),s=!0);let o=this.pos>0?this.tokens[this.pos-1].end:t,a=this._input.slice(t,o);return F.statement(n,r,s,void 0,a)}parseTimePrefix(){if(!this.check(w.TIME)||this.currentTokenJoinsProcessSubstitution())return;this.advance();let t=!1;return this.check(w.WORD,w.NAME)&&this.current().value==="-p"&&(this.advance(),t=!0),t}parsePipeline(){let t=!1,n=!1,r=0;for(;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++;if(r===0){let l=this.parseTimePrefix();if(l!==void 0)for(t=!0,n=l;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++}let s=r%2===1,i=[],o=[],a=this.parseCommand();for(i.push(a);this.check(w.PIPE,w.PIPE_AMP);){let l=this.advance();this.skipNewlines(),o.push(l.type===w.PIPE_AMP);let c=this.parseCommand();i.push(c)}return F.pipeline(i,s,t,n,o.length>0?o:void 0)}parseCommand(){if(this.currentTokenJoinsProcessSubstitution())return vi(this);let t=this.current();switch(t.type){case w.IF:return ki(this);case w.FOR:return xi(this);case w.WHILE:return Pi(this);case w.UNTIL:return $i(this);case w.CASE:return Ci(this);case w.LPAREN:return Ni(this);case w.LBRACE:return Ri(this);case w.DPAREN_START:return this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand();case w.DBRACK_START:return this.parseConditionalCommand();case w.FUNCTION:return this.parseFunctionDef();case w.TIME:break;case w.BANG:this.error(`syntax error near unexpected token \`${t.value}'`);break;default:mi(t.type)&&this.error(`syntax error near unexpected token \`${t.value}'`)}return this.check(w.NAME,w.WORD)&&this.peek(1).type===w.LPAREN&&this.peek(2).type===w.RPAREN?this.parseFunctionDef():vi(this)}dparenClosesWithSpacedParens(){let t=1,n=1;for(;n<this.tokens.length-this.pos;){let r=this.peek(n);if(r.type===w.EOF)return!1;if(r.type===w.DPAREN_START||r.type===w.LPAREN)t++;else if(r.type===w.DPAREN_END){if(t-=2,t<=0)return!1}else if(r.type===w.RPAREN&&(t--,t===0&&this.peek(n+1).type===w.RPAREN))return!0;n++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(w.RPAREN),this.expect(w.RPAREN);let n=this.parseOptionalRedirections(),r=F.subshell(t,[]);return F.subshell([F.statement([F.pipeline([r],!1,!1,!1)])],n)}isWord(){return this.isWordToken(Re.Default)||this.isProcessSubstitutionStart()||this.currentTokenJoinsProcessSubstitution()}isWordToken(t){let n=this.current().type;return n===w.WORD||n===w.NAME||n===w.NUMBER||mi(n)||n===w.BANG||n===w.ASSIGNMENT_WORD&&(t&Re.Regex)!==0}isProcessSubstitutionStart(t=0){let n=this.peek(t),r=this.peek(t+1);return(n.type===w.LESS||n.type===w.GREAT)&&r.type===w.LPAREN&&n.end===r.start}currentTokenJoinsProcessSubstitution(){return this.current().type===w.COMMENT||!this.isAdjacentWordToken(Re.Default)?!1:this.current().end===this.peek(1).start&&this.isProcessSubstitutionStart(1)}isAdjacentWordToken(t){let n=this.current().type;return this.isWordToken(t)||n===w.ASSIGNMENT_WORD||n===w.COMMENT||n===w.LBRACE||n===w.RBRACE||n===w.DBRACK_START||n===w.DBRACK_END||n===w.FD_VARIABLE}parseWord(t=Re.Default){if(this.isProcessSubstitutionStart())return this.parseAdjacentWordParts([],this.current().start,t);let n=this.advance(),r=this.parseWordToken(n,t);return this.parseAdjacentWordParts(r.parts,n.end,t)}parseAdjacentWordParts(t,n,r=Re.Default){for(;n===this.current().start;){if(this.isProcessSubstitutionStart()){t.push(this.parseProcessSubstitution()),n=this.tokens[this.pos-1].end;continue}if(!this.isAdjacentWordToken(r))break;let s=this.advance();t.push(...this.parseWordToken(s,r,t.length===0).parts),n=s.end}return F.word(t)}parseWordNoBraceExpansion(){return this.parseWord(Re.NoBraceExpansion)}parseWordForRegex(){return this.parseWord(Re.NoBraceExpansion|Re.Regex)}parseWordToken(t,n,r=!0){return t.type===w.LBRACE||t.type===w.RBRACE||t.type===w.DBRACK_START||t.type===w.DBRACK_END||t.type===w.FD_VARIABLE?F.word([F.literal(t.type===w.FD_VARIABLE?`{${t.value}}`:t.value)]):this.parseWordFromString(t.value,t.quoted,t.singleQuoted,(n&Re.Assignment)!==0,!1,(n&Re.NoBraceExpansion)!==0,(n&Re.Regex)!==0,r)}parseWordFromString(t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!0){let c=Jt(this,t,n,r,s,i,!1,o,a,!1,l);return F.word(c)}parseCommandSubstitution(t,n){return Qa(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitutionFromString(t,n){return Ka(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitution(){let t=this.advance();this.expect(w.LPAREN);let n=this.processLineState,r=this.getSourceLine(t);this.processLineState={currentLogicalLine:r};let s;try{s=F.script(this.parseCompoundList())}finally{this.processLineState=n}return this.check(w.EOF)&&this.error("unexpected EOF while looking for matching `)'"),this.expect(w.RPAREN),F.processSubstitution(s,t.type===w.LESS?"input":"output")}parseBacktickSubstitution(t,n,r=!1){return Xa(t,n,r,()=>new e(this.parseBudget),s=>this.error(s))}isDollarDparenSubshell(t,n){return Ha(t,n)}parseArithmeticExpansion(t,n){let r=n+3,s=1,i=0,o=r;for(;o<t.length-1&&s>0;)t[o]==="$"&&t[o+1]==="("?t[o+2]==="("?(s++,o+=3):(i++,o+=2):t[o]==="("&&t[o+1]==="("?(s++,o+=2):t[o]===")"&&t[o+1]===")"?i>0?(i--,o++):(s--,s>0&&(o+=2)):t[o]==="("?(i++,o++):(t[o]===")"&&i>0&&i--,o++);let a=t.slice(r,o),l=this.parseArithmeticExpression(a);return{part:F.arithmeticExpansion(l),endIndex:o+2}}parseArithmeticCommand(){let t=this.expect(w.DPAREN_START),n="",r=1,s=0,i=!1,o=!1;for(;r>0&&!this.check(w.EOF);){if(i){if(i=!1,s>0){s--,n+=")";continue}if(this.check(w.RPAREN)){r--,o=!0,this.advance();continue}if(this.check(w.DPAREN_END)){r--,o=!0;continue}n+=")";continue}if(this.check(w.DPAREN_START))r++,n+="((",this.advance();else if(this.check(w.DPAREN_END))s>=2?(s-=2,n+="))",this.advance()):s===1?(s--,n+=")",i=!0,this.advance()):(r--,o=!0,r>0&&(n+="))"),this.advance());else if(this.check(w.LPAREN))s++,n+="(",this.advance();else if(this.check(w.RPAREN))s>0&&s--,n+=")",this.advance();else{let c=this.current().value,u=n.length>0?n[n.length-1]:"";n.length>0&&!n.endsWith(" ")&&!(c==="="&&/[|&^+\-*/%<>]$/.test(n))&&!(c==="<"&&u==="<")&&!(c===">"&&u===">")&&(n+=" "),n+=c,this.advance()}}o||this.expect(w.DPAREN_END);let a=this.parseArithmeticExpression(n.trim()),l=this.parseOptionalRedirections();return F.arithmeticCommand(a,l,this.getSourceLine(t))}parseConditionalCommand(){let t=this.expect(w.DBRACK_START),n=Di(this);this.expect(w.DBRACK_END);let r=this.parseOptionalRedirections();return F.conditionalCommand(n,r,this.getSourceLine(t))}parseFunctionDef(){let t;if(this.check(w.FUNCTION)){if(this.advance(),this.check(w.NAME)||this.check(w.WORD))t=this.advance().value;else{let s=this.current();throw new Pe("Expected function name",s.line,s.column,s)}this.check(w.LPAREN)&&(this.advance(),this.expect(w.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(w.LPAREN),this.expect(w.RPAREN);this.skipNewlines();let n=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return F.functionDef(t,n,r)}parseCompoundCommandBody(t){let n=t?.forFunctionBody;if(this.check(w.LBRACE))return Ri(this,{skipRedirections:n});if(this.check(w.LPAREN))return Ni(this,{skipRedirections:n});if(this.check(w.IF))return ki(this,{skipRedirections:n});if(this.check(w.FOR))return xi(this,{skipRedirections:n});if(this.check(w.WHILE))return Pi(this,{skipRedirections:n});if(this.check(w.UNTIL))return $i(this,{skipRedirections:n});if(this.check(w.CASE))return Ci(this,{skipRedirections:n});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth();try{let n=[];for(this.skipNewlines();(this.currentTokenJoinsProcessSubstitution()||!this.check(w.EOF,w.FI,w.ELSE,w.ELIF,w.THEN,w.DO,w.DONE,w.ESAC,w.RPAREN,w.RBRACE,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND))&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,s=this.parseStatement();if(s&&n.push(s),this.skipSeparators(),this.pos===r&&!s)break}return n}finally{t()}}parseOptionalRedirections(){let t=[];for(;hr(this);){this.checkIterationLimit();let n=this.pos;if(t.push(Jr(this)),this.pos===n)break}return t}parseArithmeticExpression(t){return re(this,t)}};function He(e,t){return new Z().parse(e,t)}function mr(e){return Pn(e)}function Pn(e){return e.statements.map(Rl).join(`
|
|
76
|
-
`)}function
|
|
77
|
-
${s}${n.delimiter}`}return e.operator==="<<<"?`${t}<<< ${we(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${we(e.target)}`:`${t}${e.operator} ${we(e.target)}`}function
|
|
78
|
-
`)}function
|
|
79
|
-
${
|
|
80
|
-
${
|
|
67
|
+
`);)f=!0,u++;if(f&&u<r&&n[u]===")")return!0}if(i===0)return!1;s++;continue}if(i===1&&(l==="|"&&s+1<r&&n[s+1]==="|"||l==="&"&&s+1<r&&n[s+1]==="&"||l==="|"&&s+1<r&&n[s+1]!=="|"))return!0;s++}return!1}};var wi=1e6,fr=1e5,Nd=1e6,il=200,Re;(function(e){e[e.Default=0]="Default",e[e.Assignment=1]="Assignment",e[e.NoBraceExpansion=2]="NoBraceExpansion",e[e.Regex=4]="Regex"})(Re||(Re={}));var ol=new Set([g.LESS,g.GREAT,g.DLESS,g.DGREAT,g.LESSAND,g.GREATAND,g.LESSGREAT,g.DLESSDASH,g.CLOBBER,g.TLESS,g.AND_GREAT,g.AND_DGREAT]),al=new Set([g.LESS,g.GREAT,g.DLESS,g.DGREAT,g.LESSAND,g.GREATAND,g.LESSGREAT,g.DLESSDASH,g.CLOBBER,g.TLESS]),ll=new Set([g.LESS,g.GREAT,g.DLESS,g.DGREAT,g.LESSAND,g.GREATAND,g.LESSGREAT,g.DLESSDASH,g.CLOBBER,g.TLESS,g.AND_GREAT,g.AND_DGREAT]),xe=class extends Error{line;column;token;constructor(t,n,r,s=void 0){super(`Parse error at ${n}:${r}: ${t}`),this.line=n,this.column=r,this.token=s,this.name="ParseException"}},Jr=class{iterations=0;tokens=0;depth=0;reset(){this.iterations=0,this.tokens=0,this.depth=0}chargeIteration(t,n){if(this.iterations++,this.iterations>Nd)throw new xe("Maximum parse iterations exceeded (possible infinite loop)",t,n)}chargeTokens(t,n=1,r=1){if(this.tokens+=t,this.tokens>fr)throw new xe(`Too many tokens: cumulative count exceeds limit of ${fr}`,n,r)}enter(t,n){if(this.depth++,this.depth>il)throw this.depth--,new xe(`Maximum parser nesting depth exceeded (${il})`,t,n);let r=!0;return()=>{r&&(r=!1,this.depth--)}}};function ye(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
|
|
68
|
+
`){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var es=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function dr(e){if(e.includes("#")){let n=e.split("#");if(n.length!==2)return Number.NaN;let[r,s]=n;if(!/^\d+$/.test(r)||s.length===0)return Number.NaN;let i=Number.parseInt(r,10);if(i<2||i>64)return Number.NaN;let o=0;for(let a of s){let l;if(/[0-9]/.test(a))l=a.charCodeAt(0)-48;else if(/[a-z]/.test(a))l=a.charCodeAt(0)-97+10;else if(/[A-Z]/.test(a))l=a.charCodeAt(0)-65+(i<=36?10:36);else if(a==="@")l=62;else if(a==="_")l=63;else return Number.NaN;if(l>=i)return Number.NaN;if(o=o*i+l,o>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return o}if(e.startsWith("0x")||e.startsWith("0X")){let n=Number.parseInt(e.slice(2),16);return n>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:n}if(e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)){if(/[89]/.test(e))return Number.NaN;let n=Number.parseInt(e,8);return n>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:n}let t=Number.parseInt(e,10);return t>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t}function cl(e,t,n,r){if(n.slice(r,r+3)!=="$((")return null;let s=r+3,i=1,o=s;for(;s<n.length-1&&i>0;)n[s]==="("&&n[s+1]==="("?(i++,s+=2):n[s]===")"&&n[s+1]===")"?(i--,i>0&&(s+=2)):s++;let a=n.slice(o,s),{expr:l}=e(t,a,0);return s+=2,{expr:{type:"ArithNested",expression:l},pos:s}}function ul(e,t){if(e.slice(t,t+2)!=="$'")return null;let n=t+2,r="";for(;n<e.length&&e[n]!=="'";)if(e[n]==="\\"&&n+1<e.length){let i=e[n+1];switch(i){case"n":r+=`
|
|
69
|
+
`;break;case"t":r+=" ";break;case"r":r+="\r";break;case"\\":r+="\\";break;case"'":r+="'";break;default:r+=i}n+=2}else r+=e[n],n++;e[n]==="'"&&n++;let s=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(s)?0:s},pos:n}}function fl(e,t){if(e.slice(t,t+2)!=='$"')return null;let n=t+2,r="";for(;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?(r+=e[n+1],n+=2):(r+=e[n],n++);e[n]==='"'&&n++;let s=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(s)?0:s},pos:n}}function Rd(e){let t="",n=0;for(;n<e.length;)if(e[n]==='"'){for(n++;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);n<e.length&&n++}else t+=e[n],n++;return t}function re(e,t){let n=Rd(t),{expr:r,pos:s}=Vn(e,n,0),i=ye(n,s);if(i<n.length){let o=t.slice(i).trim();if(o)return{type:"ArithmeticExpression",originalText:t,expression:{type:"ArithSyntaxError",errorToken:o,message:`${o}: syntax error: invalid arithmetic operator (error token is "${o}")`}}}return{type:"ArithmeticExpression",expression:r,originalText:t}}function qe(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function Ge(e,t){return ye(e,t)>=e.length}function Vn(e,t,n){return Od(e,t,n)}function vn(e,t,n){return e.withDepth(()=>Vn(e,t,n))}function Od(e,t,n){let{expr:r,pos:s}=hr(e,t,n);for(s=ye(t,s);t[s]===",";){if(s++,Ge(t,s))return qe(",",s);let{expr:o,pos:a}=hr(e,t,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=ye(t,a)}return{expr:r,pos:s}}function hr(e,t,n){let{expr:r,pos:s}=Dd(e,t,n);if(s=ye(t,s),t[s]==="?"){s++;let{expr:i,pos:o}=vn(e,t,s);if(s=ye(t,o),t[s]===":"){s++;let{expr:a,pos:l}=vn(e,t,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:a},pos:l}}}return{expr:r,pos:s}}function Dd(e,t,n){let{expr:r,pos:s}=dl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="||";){if(s+=2,Ge(t,s))return qe("||",s);let{expr:o,pos:a}=dl(e,t,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=a}return{expr:r,pos:s}}function dl(e,t,n){let{expr:r,pos:s}=hl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="&&";){if(s+=2,Ge(t,s))return qe("&&",s);let{expr:o,pos:a}=hl(e,t,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=a}return{expr:r,pos:s}}function hl(e,t,n){let{expr:r,pos:s}=pl(e,t,n);for(;s=ye(t,s),t[s]==="|"&&t[s+1]!=="|";){if(s++,Ge(t,s))return qe("|",s);let{expr:o,pos:a}=pl(e,t,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=a}return{expr:r,pos:s}}function pl(e,t,n){let{expr:r,pos:s}=ml(e,t,n);for(;s=ye(t,s),t[s]==="^";){if(s++,Ge(t,s))return qe("^",s);let{expr:o,pos:a}=ml(e,t,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=a}return{expr:r,pos:s}}function ml(e,t,n){let{expr:r,pos:s}=yl(e,t,n);for(;s=ye(t,s),t[s]==="&"&&t[s+1]!=="&";){if(s++,Ge(t,s))return qe("&",s);let{expr:o,pos:a}=yl(e,t,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=a}return{expr:r,pos:s}}function yl(e,t,n){let{expr:r,pos:s}=gl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="=="||t.slice(s,s+2)==="!=";){let i=t.slice(s,s+2);if(s+=2,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=gl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function gl(e,t,n){let{expr:r,pos:s}=Ei(e,t,n);for(;;)if(s=ye(t,s),t.slice(s,s+2)==="<="||t.slice(s,s+2)===">="){let i=t.slice(s,s+2);if(s+=2,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=Ei(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else if(t[s]==="<"||t[s]===">"){let i=t[s];if(s++,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=Ei(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function Ei(e,t,n){let{expr:r,pos:s}=wl(e,t,n);for(;s=ye(t,s),t.slice(s,s+2)==="<<"||t.slice(s,s+2)===">>";){let i=t.slice(s,s+2);if(s+=2,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=wl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function wl(e,t,n){let{expr:r,pos:s}=El(e,t,n);for(;s=ye(t,s),(t[s]==="+"||t[s]==="-")&&t[s+1]!==t[s];){let i=t[s];if(s++,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=El(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function El(e,t,n){let{expr:r,pos:s}=ts(e,t,n);for(;;)if(s=ye(t,s),t[s]==="*"&&t[s+1]!=="*"){if(s++,Ge(t,s))return qe("*",s);let{expr:o,pos:a}=ts(e,t,s);r={type:"ArithBinary",operator:"*",left:r,right:o},s=a}else if(t[s]==="/"||t[s]==="%"){let i=t[s];if(s++,Ge(t,s))return qe(i,s);let{expr:o,pos:a}=ts(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function ts(e,t,n){let{expr:r,pos:s}=bi(e,t,n),i=ye(t,s);if(t.slice(i,i+2)==="**"){if(i+=2,Ge(t,i))return qe("**",i);let{expr:a,pos:l}=e.withDepth(()=>ts(e,t,i));return{expr:{type:"ArithBinary",operator:"**",left:r,right:a},pos:l}}return{expr:r,pos:s}}function bi(e,t,n){let r=ye(t,n);if(t.slice(r,r+2)==="++"||t.slice(r,r+2)==="--"){let s=t.slice(r,r+2);r+=2;let{expr:i,pos:o}=e.withDepth(()=>bi(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}if(t[r]==="+"||t[r]==="-"||t[r]==="!"||t[r]==="~"){let s=t[r];r++;let{expr:i,pos:o}=e.withDepth(()=>bi(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}return _d(e,t,r)}function Id(e,t){let n=e[t];return n==="$"||n==="`"}function _d(e,t,n){let{expr:r,pos:s}=bl(e,t,n,!1),i=[r];for(;Id(t,s);){let{expr:a,pos:l}=bl(e,t,s,!0);i.push(a),s=l}i.length>1&&(r={type:"ArithConcat",parts:i});let o;if(t[s]==="["&&r.type==="ArithConcat"){s++;let{expr:a,pos:l}=vn(e,t,s);o=a,s=l,t[s]==="]"&&s++}if(o&&r.type==="ArithConcat"&&(r={type:"ArithDynamicElement",nameExpr:r,subscript:o},o=void 0),s=ye(t,s),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let a of es)if(t.slice(s,s+a.length)===a&&t.slice(s,s+a.length+1)!=="=="){s+=a.length;let{expr:l,pos:c}=e.withDepth(()=>hr(e,t,s));return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r.nameExpr,subscript:r.subscript,value:l},pos:c}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r,value:l},pos:c}:{expr:{type:"ArithAssignment",operator:a,variable:r.name,value:l},pos:c}}}if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let a=t.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:a,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function bl(e,t,n,r=!1){let s=ye(t,n),i=cl(vn,e,t,s);if(i)return i;let o=ul(t,s);if(o)return o;let a=fl(t,s);if(a)return a;if(t.slice(s,s+2)==="$("&&t[s+2]!=="("){s+=2;let c=1,u=s;for(;s<t.length&&c>0;)t[s]==="("?c++:t[s]===")"&&c--,c>0&&s++;let f=t.slice(u,s);return s++,{expr:{type:"ArithCommandSubst",command:f},pos:s}}if(t[s]==="`"){s++;let c=s;for(;s<t.length&&t[s]!=="`";)s++;let u=t.slice(c,s);return t[s]==="`"&&s++,{expr:{type:"ArithCommandSubst",command:u},pos:s}}if(t[s]==="("){s++;let{expr:c,pos:u}=vn(e,t,s);return s=ye(t,u),t[s]===")"&&s++,{expr:{type:"ArithGroup",expression:c},pos:s}}if(t[s]==="'"){s++;let c="";for(;s<t.length&&t[s]!=="'";)c+=t[s],s++;t[s]==="'"&&s++;let u=Number.parseInt(c,10);return{expr:{type:"ArithSingleQuote",content:c,value:Number.isNaN(u)?0:u},pos:s}}if(t[s]==='"'){s++;let c="";for(;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?(c+=t[s+1],s+=2):(c+=t[s],s++);t[s]==='"'&&s++;let u=c.trim();if(!u)return{expr:{type:"ArithNumber",value:0},pos:s};let{expr:f}=vn(e,u,0);return{expr:f,pos:s}}if(/[0-9]/.test(t[s])){let c="",u=!1,f=!1;for(;s<t.length;){let h=t[s];if(u)if(/[0-9a-zA-Z@_]/.test(h))c+=h,s++;else break;else if(h==="#")u=!0,c+=h,s++;else if(c==="0"&&(h==="x"||h==="X")&&s+1<t.length&&/[0-9a-fA-F]/.test(t[s+1]))f=!0,c+=h,s++;else if(f&&/[0-9a-fA-F]/.test(h))c+=h,s++;else if(!f&&/[0-9]/.test(h))c+=h,s++;else break}if(s<t.length&&/[a-zA-Z_]/.test(t[s])){let h=c;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)h+=t[s],s++;return{expr:{type:"ArithSyntaxError",errorToken:h,message:`${h}: value too great for base (error token is "${h}")`},pos:s}}if(t[s]==="."&&/[0-9]/.test(t[s+1]))throw new le(`${c}.${t[s+1]}...: syntax error: invalid arithmetic operator`);if(t[s]==="["){let h=t.slice(s).trim();return{expr:{type:"ArithNumberSubscript",number:c,errorToken:h},pos:t.length}}return{expr:{type:"ArithNumber",value:dr(c)},pos:s}}if(t[s]==="$"&&t[s+1]==="{"){let c=s+2,u=1,f=c;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;let d=t.slice(c,f),h=f+1;if(t[h]==="#"){let p=h+1;for(;p<t.length&&/[0-9a-zA-Z@_]/.test(t[p]);)p++;let m=t.slice(h+1,p);return{expr:{type:"ArithDynamicBase",baseExpr:d,value:m},pos:p}}if(/[0-9]/.test(t[h])||t[h]==="x"||t[h]==="X"){let p=h;if(t[h]==="x"||t[h]==="X")for(p++;p<t.length&&/[0-9a-fA-F]/.test(t[p]);)p++;else for(;p<t.length&&/[0-9]/.test(t[p]);)p++;let m=t.slice(h,p);return{expr:{type:"ArithDynamicNumber",prefix:d,suffix:m},pos:p}}return s=h,{expr:{type:"ArithBracedExpansion",content:d},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[0-9]/.test(t[s+1])){s++;let c="";for(;s<t.length&&/[0-9]/.test(t[s]);)c+=t[s],s++;return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:!0},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[*@#?\-!$]/.test(t[s+1])){let c=t[s+1];return s+=2,{expr:{type:"ArithSpecialVar",name:c},pos:s}}let l=!1;if(t[s]==="$"&&s+1<t.length&&/[a-zA-Z_]/.test(t[s+1])&&(l=!0,s++),s<t.length&&/[a-zA-Z_]/.test(t[s])){let c="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)c+=t[s],s++;if(t[s]==="["&&!r){s++;let u;if(t[s]==="'"||t[s]==='"'){let d=t[s];for(s++,u="";s<t.length&&t[s]!==d;)u+=t[s],s++;t[s]===d&&s++,s=ye(t,s),t[s]==="]"&&s++}let f;if(u===void 0){let{expr:d,pos:h}=vn(e,t,s);f=d,s=h,t[s]==="]"&&s++}if(s=ye(t,s),t[s]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:c,index:f},pos:s};if(!r){for(let d of es)if(t.slice(s,s+d.length)===d&&t.slice(s,s+d.length+1)!=="=="){s+=d.length;let{expr:h,pos:p}=e.withDepth(()=>hr(e,t,s));return{expr:{type:"ArithAssignment",operator:d,variable:c,subscript:f,stringKey:u,value:h},pos:p}}}return{expr:{type:"ArithArrayElement",array:c,index:f,stringKey:u},pos:s}}if(s=ye(t,s),!r){for(let u of es)if(t.slice(s,s+u.length)===u&&t.slice(s,s+u.length+1)!=="=="){s+=u.length;let{expr:f,pos:d}=e.withDepth(()=>hr(e,t,s));return{expr:{type:"ArithAssignment",operator:u,variable:c,value:f},pos:d}}}return{expr:{type:"ArithVariable",name:c,hasDollarPrefix:l},pos:s}}if(t[s]==="#"){let c=s+1;for(;c<t.length&&t[c]!==`
|
|
70
|
+
`;)c++;let u=t.slice(s,c).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:u,message:`${u}: syntax error: invalid arithmetic operator (error token is "${u}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:s}}var ns=e=>{let t,n="";for(let r=0;r<e.length;r++){let s=e[r];if(s==="\\"&&t==='"'&&r+1<e.length){n+=s+e[r+1],r+=1;continue}if(s==="'"||s==='"'){t===s?t=void 0:t||(t=s),n+=s;continue}if(s==="\\"&&!t&&r+1<e.length){let i=e[r+1];n+=i==="$"||i==="`"?`\\${i}`:i,r+=1;continue}n+=s}return n};function Td(e){let t="",n=0;for(;n<e.length;){let r=e[n];if(r<128){t+=String.fromCharCode(r),n++;continue}if((r&224)===192){if(n+1<e.length&&(e[n+1]&192)===128&&r>=194){let s=(r&31)<<6|e[n+1]&63;t+=String.fromCharCode(s),n+=2;continue}t+=String.fromCharCode(r),n++;continue}if((r&240)===224){if(n+2<e.length&&(e[n+1]&192)===128&&(e[n+2]&192)===128){if(r===224&&e[n+1]<160){t+=String.fromCharCode(r),n++;continue}let s=(r&15)<<12|(e[n+1]&63)<<6|e[n+2]&63;if(s>=55296&&s<=57343){t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(s),n+=3;continue}t+=String.fromCharCode(r),n++;continue}if((r&248)===240&&r<=244){if(n+3<e.length&&(e[n+1]&192)===128&&(e[n+2]&192)===128&&(e[n+3]&192)===128){if(r===240&&e[n+1]<144){t+=String.fromCharCode(r),n++;continue}let s=(r&7)<<18|(e[n+1]&63)<<12|(e[n+2]&63)<<6|e[n+3]&63;if(s>1114111){t+=String.fromCharCode(r),n++;continue}t+=String.fromCodePoint(s),n+=4;continue}t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(r),n++}return t}function vl(e,t,n){let r=n+1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;return r}function Si(e,t,n,r,s){let i=1,o=n+1;for(;o<t.length&&i>0;)t[o]===r?i++:t[o]===s&&i--,i>0&&o++;return i===0?o:-1}function kn(e,t,n){let r=n,s=1;for(;r<t.length&&s>0;){let i=t[r];if(i==="\\"&&r+1<t.length){r+=2;continue}if(i==="'"){let o=t.indexOf("'",r+1);if(o!==-1){r=o+1;continue}}if(i==='"'){for(r++;r<t.length&&t[r]!=='"';)t[r]==="\\"&&r+1<t.length?r+=2:r++;r<t.length&&r++;continue}i==="{"?s++:i==="}"&&s--,s>0&&r++}return r}function kl(e,t,n){let r=n,s=!1;for(;r<t.length;){let i=t[r];if(i==="/"&&s||i==="}")break;if(i==="'"){let o=t.indexOf("'",r+1);if(o!==-1){r=o+1,s=!0;continue}}if(i==='"'){for(r++;r<t.length&&t[r]!=='"';)t[r]==="\\"&&r+1<t.length?r+=2:r++;r<t.length&&r++,s=!0;continue}i==="\\"?(r+=2,s=!0):(r++,s=!0)}return r}function xl(e,t,n){let r=n,s="";for(;r<t.length;){let i=t[r];if(i==="*"||i==="?")s+=i,r++;else if(i==="["){let o=Ld(t,r);o===-1?(s+=i,r++):(s+=t.slice(r,o+1),r=o+1)}else break}return{pattern:s,endIndex:r}}function Ld(e,t){let n=t+1;for(n<e.length&&e[n]==="^"&&n++,n<e.length&&e[n]==="]"&&n++;n<e.length;){let r=e[n];if(r==="\\"&&n+1<e.length){let s=e[n+1];if(s==='"'||s==="'")return-1;n+=2;continue}if(r==="]")return n;if(r==='"'||r==="$"||r==="`")return-1;if(r==="'"){let s=e.indexOf("'",n+1);if(s!==-1){n=s+1;continue}}if(r==="["&&n+1<e.length&&e[n+1]===":"){let s=e.indexOf(":]",n+2);if(s!==-1){n=s+2;continue}}if(r==="["&&n+1<e.length&&(e[n+1]==="."||e[n+1]==="=")){let i=`${e[n+1]}]`,o=e.indexOf(i,n+2);if(o!==-1){n=o+2;continue}}n++}return-1}function Pl(e,t,n){let r="",s=n;for(;s<t.length&&t[s]!=="'";){let i=t[s];if(i==="\\"&&s+1<t.length)switch(t[s+1]){case"n":r+=`
|
|
71
|
+
`,s+=2;break;case"t":r+=" ",s+=2;break;case"r":r+="\r",s+=2;break;case"\\":r+="\\",s+=2;break;case"'":r+="'",s+=2;break;case'"':r+='"',s+=2;break;case"a":r+="\x07",s+=2;break;case"b":r+="\b",s+=2;break;case"e":case"E":r+="\x1B",s+=2;break;case"f":r+="\f",s+=2;break;case"v":r+="\v",s+=2;break;case"x":{let a=[],l=s;for(;l+1<t.length&&t[l]==="\\"&&t[l+1]==="x";){let c=t.slice(l+2,l+4),u=parseInt(c,16);if(!Number.isNaN(u)&&c.length>0)a.push(u),l+=2+c.length;else break}a.length>0?(r+=Td(a),s=l):(r+="\\x",s+=2);break}case"u":{let a=t.slice(s+2,s+6),l=parseInt(a,16);Number.isNaN(l)?(r+="\\u",s+=2):(r+=String.fromCharCode(l),s+=6);break}case"c":{if(s+2<t.length){let l=t[s+2].charCodeAt(0)&31;r+=String.fromCharCode(l),s+=3}else r+="\\c",s+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let a="",l=s+1;for(;l<t.length&&l<s+4&&/[0-7]/.test(t[l]);)a+=t[l],l++;let c=parseInt(a,8);r+=String.fromCharCode(c),s=l;break}default:r+=i,s++}else r+=i,s++}return s<t.length&&t[s]==="'"&&s++,{part:M.literal(r),endIndex:s}}function Ai(e,t){let n=t.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:re(e,n)}function Al(e){let t=[],n="",r=0;for(let s=0;s<e.length;s++){let i=e[s];i==="{"?(r++,n+=i):i==="}"?(r--,n+=i):i===","&&r===0?(t.push(n),n=""):n+=i}return t.push(n),t}function $l(e,t,n,r){let s=Si(e,t,n,"{","}");if(s===-1)return null;let i=t.slice(n+1,s),o=i.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(o)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(o[1],10),end:Number.parseInt(o[2],10),step:o[3]?Number.parseInt(o[3],10):void 0,startStr:o[1],endStr:o[2]}]},endIndex:s+1};let a=i.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return a?{part:{type:"BraceExpansion",items:[{type:"Range",start:a[1],end:a[2],step:a[3]?Number.parseInt(a[3],10):void 0}]},endIndex:s+1}:i.includes(",")&&r?{part:{type:"BraceExpansion",items:Al(i).map(u=>e.withDepth(()=>({type:"Word",word:M.word(r(e,u,!1,!1,!1))})))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:Al(i).map(u=>({type:"Word",word:M.word([M.literal(u)])}))},endIndex:s+1}:null}function vi(e,t){let n="";for(let r of t.parts)switch(r.type){case"Literal":n+=r.value;break;case"SingleQuoted":n+=`'${r.value}'`;break;case"Escaped":n+=r.value;break;case"DoubleQuoted":n+='"';for(let s of r.parts)s.type==="Literal"||s.type==="Escaped"?n+=s.value:s.type==="ParameterExpansion"&&(n+=`\${${s.parameter}}`);n+='"';break;case"ParameterExpansion":n+=`\${${r.parameter}}`;break;case"Glob":n+=r.pattern;break;case"TildeExpansion":n+="~",r.user&&(n+=r.user);break;case"BraceExpansion":{n+="{";let s=[];for(let i of r.items)if(i.type==="Range"){let o=i.startStr??String(i.start),a=i.endStr??String(i.end);i.step!==void 0?s.push(`${o}..${a}..${i.step}`):s.push(`${o}..${a}`)}else s.push(vi(e,i.word));s.length===1&&r.items[0].type==="Range"?n+=s[0]:n+=s.join(","),n+="}";break}default:n+=r.type}return n}function Cl(e,t){return{[g.LESS]:"<",[g.GREAT]:">",[g.DGREAT]:">>",[g.LESSAND]:"<&",[g.GREATAND]:">&",[g.LESSGREAT]:"<>",[g.CLOBBER]:">|",[g.TLESS]:"<<<",[g.AND_GREAT]:"&>",[g.AND_DGREAT]:"&>>",[g.DLESS]:"<",[g.DLESSDASH]:"<"}[t]||">"}function pr(e){let t=e.current(),n=t.type;if(n===g.NUMBER){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:al.has(r.type)}if(n===g.FD_VARIABLE){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:ll.has(r.type)}return!e.isProcessSubstitutionStart()&&ol.has(n)}function rs(e){let t=null,n;e.check(g.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(g.FD_VARIABLE)&&(n=e.advance().value);let r=e.advance(),s=Cl(e,r.type);if(r.type===g.DLESS||r.type===g.DLESSDASH)return Fd(e,t,n,r.type===g.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return M.redirection(s,i,t,n)}function Fd(e,t,n,r){e.isWord()||e.error("Expected here-document delimiter");let s=e.advance(),i=s.heredocDelimiter??s.value,o=s.quoted||!1,a=M.redirection(r?"<<-":"<<",M.hereDoc(i,M.word([]),r,o),t,n);return e.addPendingHeredoc(a,i,r,o),a}function xi(e){let t=e.getSourceLine(),n=[],r=null,s=[],i=[];for(;e.check(g.ASSIGNMENT_WORD)||pr(e);)e.checkIterationLimit(),e.check(g.ASSIGNMENT_WORD)?n.push(Md(e)):i.push(rs(e));if(e.isWord())r=e.parseWord();else if(n.length>0&&(e.check(g.DBRACK_START)||e.check(g.DPAREN_START))){let a=e.advance();r=M.word([M.literal(a.value)])}for(;(!e.isStatementEnd()||e.check(g.RBRACE))&&!e.check(g.PIPE,g.PIPE_AMP);)if(e.checkIterationLimit(),pr(e))i.push(rs(e));else if(e.check(g.ASSIGNMENT_WORD)){let a=e.advance(),l=a.value,c=l.endsWith("="),u=l.endsWith("=(");if((c||u)&&(u||e.check(g.LPAREN))){let f=u?l.slice(0,-2):l.slice(0,-1);u||e.expect(g.LPAREN);let d=ki(e);e.expect(g.RPAREN);let h=d.map(m=>vi(e,m)),p=`${f}=(${h.join(" ")})`;s.push(e.parseWordFromString(p,!1,!1,!0))}else{let f=e.parseWordFromString(l,a.quoted,a.singleQuoted,!0);s.push(e.parseAdjacentWordParts(f.parts,a.end,Re.Assignment))}}else if(e.isWord())s.push(e.parseWord());else if(e.check(g.RBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(g.LBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(g.DBRACK_END)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(g.LPAREN))e.error("syntax error near unexpected token `('");else break;let o=M.simpleCommand(r,s,n,i);return o.line=t,o}function Md(e){let t=e.expect(g.ASSIGNMENT_WORD),n=t.value,r=n.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||e.error(`Invalid assignment: ${n}`);let s=r[0],i,o=s.length;if(n[o]==="["){let f=0,d=o+1;for(;o<n.length;o++)if(n[o]==="[")f++;else if(n[o]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${n}`),i=ns(n.slice(d,o)),o++}let a=n[o]==="+";a&&o++,n[o]!=="="&&e.error(`Invalid assignment: ${n}`),o++;let l=n.slice(o);if(l==="("){let f=ki(e);e.expect(g.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return M.assignment(d,null,a,f)}if(l===""&&e.check(g.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=ki(e);e.expect(g.RPAREN);let h=i!==void 0?`${s}[${i}]`:s;return M.assignment(h,null,a,d)}}let c=l?e.parseWordFromString(l,t.quoted,t.singleQuoted,!0):null;t.end===e.current().start&&e.isProcessSubstitutionStart()&&(c=e.parseAdjacentWordParts(c?.parts??[],t.end,Re.Assignment));let u=i!==void 0?`${s}[${i}]`:s;return M.assignment(u,c,a,null)}var Bd=new Set([g.AMP,g.PIPE,g.PIPE_AMP,g.SEMICOLON,g.AND_AND,g.OR_OR,g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND]);function ki(e){let t=[];for(e.skipNewlines();!e.check(g.RPAREN,g.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):Bd.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function Pi(e,t){e.expect(g.IF);let n=[],r=e.parseCompoundList();e.expect(g.THEN);let s=e.parseCompoundList();if(s.length===0){let a=e.check(g.FI)?"fi":e.check(g.ELSE)?"else":e.check(g.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${a}'`)}for(n.push({condition:r,body:s});e.check(g.ELIF);){e.advance();let a=e.parseCompoundList();e.expect(g.THEN);let l=e.parseCompoundList();if(l.length===0){let c=e.check(g.FI)?"fi":e.check(g.ELSE)?"else":e.check(g.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${c}'`)}n.push({condition:a,body:l})}let i=null;e.check(g.ELSE)&&(e.advance(),i=e.parseCompoundList(),i.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(g.FI);let o=t?.skipRedirections?[]:e.parseOptionalRedirections();return M.ifNode(n,i,o)}function $i(e,t){let n=e.expect(g.FOR);if(e.check(g.DPAREN_START))return Vd(e,t,e.getSourceLine(n));e.isWord()||e.error("Expected variable name in for loop");let s=e.advance().value,i=null;if(e.skipNewlines(),e.check(g.IN))for(e.advance(),i=[];!e.check(g.SEMICOLON,g.NEWLINE,g.DO,g.EOF)&&e.isWord();)i.push(e.parseWord());e.check(g.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(g.DO);let o=e.parseCompoundList();e.expect(g.DONE);let a=t?.skipRedirections?[]:e.parseOptionalRedirections();return M.forNode(s,i,o,a)}function Vd(e,t,n){e.expect(g.DPAREN_START);let r=null,s=null,i=null,o=["","",""],a=0,l=0;for(;!e.check(g.DPAREN_END,g.EOF);){let f=e.advance();if(f.type===g.SEMICOLON&&l===0){if(a++,a>2)break}else f.value==="("&&l++,f.value===")"&&l--,o[a]+=f.value}e.expect(g.DPAREN_END),o[0].trim()&&(r=re(e,o[0].trim())),o[1].trim()&&(s=re(e,o[1].trim())),o[2].trim()&&(i=re(e,o[2].trim())),e.skipNewlines(),e.check(g.SEMICOLON)&&e.advance(),e.skipNewlines();let c;e.check(g.LBRACE)?(e.advance(),c=e.parseCompoundList(),e.expect(g.RBRACE)):(e.expect(g.DO),c=e.parseCompoundList(),e.expect(g.DONE));let u=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:s,update:i,body:c,redirections:u,line:n}}function Ci(e,t){e.expect(g.WHILE);let n=e.parseCompoundList();e.expect(g.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(g.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return M.whileNode(n,r,s)}function Ni(e,t){e.expect(g.UNTIL);let n=e.parseCompoundList();e.expect(g.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(g.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return M.untilNode(n,r,s)}function Ri(e,t){e.expect(g.CASE),e.isWord()||e.error("Expected word after 'case'");let n=e.parseWord();e.skipNewlines(),e.expect(g.IN),e.skipNewlines();let r=[];for(;!e.check(g.ESAC,g.EOF);){e.checkIterationLimit();let i=e.getPos(),o=zd(e);if(o&&r.push(o),e.skipNewlines(),e.getPos()===i&&!o)break}e.expect(g.ESAC);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return M.caseNode(n,r,s)}function zd(e){e.check(g.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(g.PIPE));)e.advance();if(t.length===0)return null;e.expect(g.RPAREN),e.skipNewlines();let n=[];for(;!e.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND,g.ESAC,g.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===g.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(g.LPAREN)&&e.peek(1).type===g.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let s=e.getPos(),i=e.parseStatement();if(i&&n.push(i),e.skipSeparators(!1),e.getPos()===s&&!i)break}let r=";;";return e.check(g.DSEMI)?(e.advance(),r=";;"):e.check(g.SEMI_AND)?(e.advance(),r=";&"):e.check(g.SEMI_SEMI_AND)&&(e.advance(),r=";;&"),M.caseItem(t,n,r)}function Oi(e,t){e.expect(g.LPAREN);let n=e.parseCompoundList();e.expect(g.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return M.subshell(n,r)}function Di(e,t){e.expect(g.LBRACE);let n=e.parseCompoundList();e.expect(g.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return M.group(n,r)}var jd=["-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"],qd=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function Rl(e){return e.isWord()||e.check(g.LBRACE)||e.check(g.RBRACE)||e.check(g.ASSIGNMENT_WORD)}function Ol(e){if(e.check(g.BANG)&&e.peek(1).type===g.LPAREN){e.advance(),e.advance();let t=1,n="!(";for(;t>0&&!e.check(g.EOF);)if(e.check(g.LPAREN))t++,n+="(",e.advance();else if(e.check(g.RPAREN))t--,t>0&&(n+=")"),e.advance();else if(e.isWord())n+=e.advance().value;else if(e.check(g.PIPE))n+="|",e.advance();else break;return n+=")",e.parseWordFromString(n,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function _i(e){return e.skipNewlines(),Gd(e)}function Gd(e){let t=Dl(e);for(e.skipNewlines();e.check(g.OR_OR);){e.advance(),e.skipNewlines();let n=Dl(e);t={type:"CondOr",left:t,right:n},e.skipNewlines()}return t}function Dl(e){let t=Ii(e);for(e.skipNewlines();e.check(g.AND_AND);){e.advance(),e.skipNewlines();let n=Ii(e);t={type:"CondAnd",left:t,right:n},e.skipNewlines()}return t}function Ii(e){return e.skipNewlines(),e.check(g.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:e.withDepth(()=>Ii(e))}):Hd(e)}function Hd(e){if(e.check(g.LPAREN)){e.advance();let t=e.withDepth(()=>_i(e));return e.expect(g.RPAREN),{type:"CondGroup",expression:t}}if(Rl(e)){let t=e.current(),n=t.value;if(jd.includes(n)&&!t.quoted){if(e.advance(),e.check(g.DBRACK_END)&&e.error(`Expected operand after ${n}`),Rl(e)){let i=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:n,operand:i}}let s=e.current();e.error(`unexpected argument \`${s.value}' to conditional unary operator`)}let r=e.parseWordNoBraceExpansion();if(e.isWord()&&qd.includes(e.current().value)){let s=e.advance().value,i;return s==="=~"?i=Zd(e):s==="=="||s==="!="?i=Ol(e):i=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:s,left:r,right:i}}if(e.check(g.LESS)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:r,right:s}}if(e.check(g.GREAT)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:r,right:s}}if(e.isWord()&&e.current().value==="="){e.advance();let s=Ol(e);return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function Zd(e){let t=[],n=0,r=-1,s=e.getInput(),i=()=>e.check(g.DBRACK_END)||e.check(g.AND_AND)||e.check(g.OR_OR)||e.check(g.NEWLINE)||e.check(g.EOF);for(;!i();){let o=e.current(),a=r>=0&&o.start>r;if(n===0&&a)break;if(n>0&&a){let l=s.slice(r,o.start);t.push({type:"Literal",value:l})}if(e.isWord()||e.check(g.ASSIGNMENT_WORD)){let l=e.parseWordForRegex();t.push(...l.parts),r=e.peek(-1).end}else if(e.check(g.LPAREN)){let l=e.advance();t.push({type:"Literal",value:"("}),n++,r=l.end}else if(e.check(g.DPAREN_START)){let l=e.advance();t.push({type:"Literal",value:"(("}),n+=2,r=l.end}else if(e.check(g.DPAREN_END))if(n>=2){let l=e.advance();t.push({type:"Literal",value:"))"}),n-=2,r=l.end}else{if(n===1)break;break}else if(e.check(g.RPAREN))if(n>0){let l=e.advance();t.push({type:"Literal",value:")"}),n--,r=l.end}else break;else if(e.check(g.PIPE)){let l=e.advance();t.push({type:"Literal",value:"|"}),r=l.end}else if(e.check(g.SEMICOLON))if(n>0){let l=e.advance();t.push({type:"Literal",value:";"}),r=l.end}else break;else if(n>0&&e.check(g.LESS)){let l=e.advance();t.push({type:"Literal",value:"<"}),r=l.end}else if(n>0&&e.check(g.GREAT)){let l=e.advance();t.push({type:"Literal",value:">"}),r=l.end}else if(n>0&&e.check(g.DGREAT)){let l=e.advance();t.push({type:"Literal",value:">>"}),r=l.end}else if(n>0&&e.check(g.DLESS)){let l=e.advance();t.push({type:"Literal",value:"<<"}),r=l.end}else if(n>0&&e.check(g.LESSAND)){let l=e.advance();t.push({type:"Literal",value:"<&"}),r=l.end}else if(n>0&&e.check(g.GREATAND)){let l=e.advance();t.push({type:"Literal",value:">&"}),r=l.end}else if(n>0&&e.check(g.LESSGREAT)){let l=e.advance();t.push({type:"Literal",value:"<>"}),r=l.end}else if(n>0&&e.check(g.CLOBBER)){let l=e.advance();t.push({type:"Literal",value:">|"}),r=l.end}else if(n>0&&e.check(g.TLESS)){let l=e.advance();t.push({type:"Literal",value:"<<<"}),r=l.end}else if(n>0&&e.check(g.AMP)){let l=e.advance();t.push({type:"Literal",value:"&"}),r=l.end}else if(n>0&&e.check(g.LBRACE)){let l=e.advance();t.push({type:"Literal",value:"{"}),r=l.end}else if(n>0&&e.check(g.RBRACE)){let l=e.advance();t.push({type:"Literal",value:"}"}),r=l.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function Kd(e){let t="";for(let n=0;n<e.length;n++){let r=e[n],s=e[n+1];if(r!=="\\"||s===void 0){t+=r;continue}"\\[]^-".includes(s)&&(t+="\\"),t+=s,n++}return t}function mr(e){return e.length>0?e:[M.literal("")]}function Xd(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if("@*+?!".includes(s)&&r+1<e.length&&e[r+1]==="("){r++,n++,r++;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function Yd(e,t,n){let r=n+1,s=t[r];if("@*#?$!-0123456789".includes(s))return{part:M.parameterExpansion(s),endIndex:r+1};let i="";for(;r<t.length&&/[a-zA-Z0-9_]/.test(t[r]);)i+=t[r],r++;return{part:M.parameterExpansion(i),endIndex:r}}function Jd(e,t,n,r=!1){let s=n+2,i=!1;t[s]==="!"&&(i=!0,s++);let o=!1;t[s]==="#"&&!/[}:#%/^,]/.test(t[s+1]||"}")&&(o=!0,s++);let a="",l=t[s];if(/[@*#?$!-]/.test(l)&&!/[a-zA-Z0-9_]/.test(t[s+1]||""))a=l,s++;else for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)a+=t[s],s++;if(t[s]==="["){let u=Si(e,t,s,"[","]");if(a+=`[${ns(t.slice(s+1,u))}]`,s=u+1,t[s]==="["){let f=1,d=s;for(;d<t.length&&f>0;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let h=t.slice(n+2,d);return{part:M.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:d+1}}}if(a===""&&!i&&!o&&t[s]!=="}"){let u=1,f=s;for(;f<t.length&&u>0;)t[f]==="{"?u++:t[f]==="}"&&u--,u>0&&f++;if(u>0)throw new xe("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(n+2,f);return{part:M.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let c=null;if(i){let u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(u)if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Ti(e,t,s,a,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):(c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="")}else c={type:"ArrayKeys",array:u[1],star:u[2]==="*"},a="";else if(t[s]==="*"||t[s]==="@"&&!/[QPaAEKkuUL]/.test(t[s+1]||"")){let f=t[s];s++,c={type:"VarNamePrefix",prefix:a,star:f==="*"},a=""}else if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=Ti(e,t,s,a,r);f.operation?(c={type:"Indirection",innerOp:f.operation},s=f.endIndex):c={type:"Indirection"}}else c={type:"Indirection"}}else if(o)if(t[s]===":")for(c={type:"LengthSliceError"};s<t.length&&t[s]!=="}";)s++;else t[s]!=="}"&&/[-+=?]/.test(t[s])?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):t[s]==="/"?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):c={type:"Length"};if(!c&&s<t.length&&t[s]!=="}"){let u=Ti(e,t,s,a,r);c=u.operation,s=u.endIndex}if(s<t.length&&t[s]!=="}"){let u=t[s];if(!/[:\-+=?#%/^,@[]/.test(u)){let f=s;for(;f<t.length&&t[f]!=="}";)f++;let d=t.slice(n,f+1);e.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<t.length&&t[s]!=="}";)s++;if(s>=t.length)throw new xe("unexpected EOF while looking for matching '}'",0,0);return{part:M.parameterExpansion(a,c),endIndex:s+1}}function Ti(e,t,n,r,s=!1){let i=n,o=t[i],a=t[i+1]||"";if(o===":"){let l=a;if("-=?+".includes(l)){i+=2;let b=kn(e,t,i),w=t.slice(i,b),E=e.withDepth(()=>Jt(e,w,!1,!1,!0,!1,s,!1,!1,!0)),S=M.word(mr(E));if(l==="-")return{operation:{type:"DefaultValue",word:S,checkEmpty:!0},endIndex:b};if(l==="=")return{operation:{type:"AssignDefault",word:S,checkEmpty:!0},endIndex:b};if(l==="?")return{operation:{type:"ErrorIfUnset",word:S,checkEmpty:!0},endIndex:b};if(l==="+")return{operation:{type:"UseAlternative",word:S,checkEmpty:!0},endIndex:b}}i++;let c=kn(e,t,i),u=t.slice(i,c),f=-1,d=0,h=0;for(let y=0;y<u.length;y++){let b=u[y];if(b==="("||b==="[")d++;else if(b===")"||b==="]")d--;else if(b==="?"&&d===0)h++;else if(b===":"&&d===0)if(h>0)h--;else{f=y;break}}let p=f>=0?u.slice(0,f):u,m=f>=0?u.slice(f+1):null;return{operation:{type:"Substring",offset:Ai(e,p),length:m!==null?Ai(e,m):null},endIndex:c}}if("-=?+".includes(o)){i++;let l=kn(e,t,i),c=t.slice(i,l),u=e.withDepth(()=>Jt(e,c,!1,!1,!0,!1,s,!1,!1,!0)),f=M.word(mr(u));if(o==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:l};if(o==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:l};if(o==="?")return{operation:{type:"ErrorIfUnset",word:c?f:null,checkEmpty:!1},endIndex:l};if(o==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:l}}if(o==="#"||o==="%"){let l=a===o,c=o==="#"?"prefix":"suffix";i+=l?2:1;let u=kn(e,t,i),f=t.slice(i,u),d=e.withDepth(()=>Jt(e,f,!1,!1,!1));return{operation:{type:"PatternRemoval",pattern:M.word(mr(d)),side:c,greedy:l},endIndex:u}}if(o==="/"){let l=a==="/";i+=l?2:1;let c=null;t[i]==="#"?(c="start",i++):t[i]==="%"&&(c="end",i++);let u;c!==null&&(t[i]==="/"||t[i]==="}")?u=i:u=kl(e,t,i);let f=t.slice(i,u),d=e.withDepth(()=>Jt(e,f,!1,!1,!1)),h=M.word(mr(d)),p=null,m=u;if(t[u]==="/"){let y=u+1,b=kn(e,t,y),w=t.slice(y,b),E=e.withDepth(()=>Jt(e,w,!1,!1,!1));p=M.word(mr(E)),m=b}return{operation:{type:"PatternReplacement",pattern:h,replacement:p,all:l,anchor:c},endIndex:m}}if(o==="^"||o===","){let l=a===o,c=o==="^"?"upper":"lower";i+=l?2:1;let u=kn(e,t,i),f=t.slice(i,u),d=f?M.word([M.literal(f)]):null;return{operation:{type:"CaseModification",direction:c,all:l,pattern:d},endIndex:u}}return o==="@"&&/[QPaAEKkuUL]/.test(a)?{operation:{type:"Transform",operator:a},endIndex:i+2}:{operation:null,endIndex:i}}function Li(e,t,n,r=!1){let s=n+1;if(s>=t.length)return{part:M.literal("$"),endIndex:s};let i=t[s];if(i==="("&&t[s+1]==="(")return e.isDollarDparenSubshell(t,n)?e.parseCommandSubstitution(t,n):e.parseArithmeticExpansion(t,n);if(i==="["){let o=1,a=s+1;for(;a<t.length&&o>0;)t[a]==="["?o++:t[a]==="]"&&o--,o>0&&a++;if(o===0){let l=t.slice(s+1,a),c=re(e,l);return{part:M.arithmeticExpansion(c),endIndex:a+1}}}return i==="("?e.parseCommandSubstitution(t,n):i==="{"?Jd(e,t,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?Yd(e,t,n):{part:M.literal("$"),endIndex:s}}function Il(e,t){let n=[],r=0,s="",i=()=>{s&&(n.push(M.literal(s)),s="")};for(;r<t.length;){let o=t[r];if(o==="\\"&&r+1<t.length){let a=t[r+1];if(a==="$"||a==="`"||a==='"'||a==="\\"){s+=a,r+=2;continue}s+=o,r++;continue}if(o==="$"){i();let{part:a,endIndex:l}=Li(e,t,r,!0);a&&n.push(a),r=l;continue}if(o==="`"){i();let{part:a,endIndex:l}=e.parseBacktickSubstitution(t,r,!0);n.push(a),r=l;continue}s+=o,r++}return i(),n}function eh(e,t,n){let r=[],s=n,i="",o=()=>{i&&(r.push(M.literal(i)),i="")};for(;s<t.length&&t[s]!=='"';){let a=t[s];if(a==="\\"&&s+1<t.length){let l=t[s+1];if('"\\$`\n'.includes(l)){i+=l,s+=2;continue}i+=a,s++;continue}if(a==="$"){o();let{part:l,endIndex:c}=Li(e,t,s,!0);l&&r.push(l),s=c;continue}if(a==="`"){o();let{part:l,endIndex:c}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=c;continue}i+=a,s++}return o(),{part:M.doubleQuoted(r),endIndex:s}}function Jt(e,t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!0){if(r)return[M.singleQuoted(t)];if(n){let m=Il(e,t);return[M.doubleQuoted(m)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let m=t.slice(1,-1),y=!1;for(let b=0;b<m.length;b++){if(m[b]==='"'){y=!0;break}m[b]==="\\"&&b+1<m.length&&b++}if(!y){let b=Il(e,m);return[M.doubleQuoted(b)]}}let f=[],d=0,h="",p=()=>{h&&(f.push(M.literal(h)),h="")};for(;d<t.length;){let m=t[d];if(m==="\\"&&d+1<t.length){let y=t[d+1];if(l){p(),f.push(M.escaped(y)),d+=2;continue}if(!i&&!o){y!==`
|
|
72
|
+
`&&(p(),f.push(M.escaped(y))),d+=2;continue}let b=i?y==="$"||y==="`"||y===`
|
|
73
|
+
`:y==="$"||y==="`"||y==='"'||y==="'"||y===`
|
|
74
|
+
`||c&&y==="}",w=o?"*?[]\\".includes(y):"*?[]\\(){}.^+".includes(y);b?y!==`
|
|
75
|
+
`&&(h+=y):w?(p(),f.push(M.escaped(y))):h+=`\\${y}`,d+=2;continue}if(m==="'"&&!o&&!i){p();let y=t.indexOf("'",d+1);if(y===-1){h+=t.slice(d);break}f.push(M.singleQuoted(t.slice(d+1,y))),d=y+1;continue}if(m==='"'&&!i){p();let{part:y,endIndex:b}=eh(e,t,d+1);f.push(y),d=b+1;continue}if(m==="$"&&t[d+1]==="'"){p();let{part:y,endIndex:b}=Pl(e,t,d+2);f.push(y),d=b;continue}if(m==="$"){p();let{part:y,endIndex:b}=Li(e,t,d);y&&f.push(y),d=b;continue}if(m==="`"){p();let{part:y,endIndex:b}=e.parseBacktickSubstitution(t,d);f.push(y),d=b;continue}if((m==="<"||m===">")&&t[d+1]==="("&&!i&&!o){p();let{part:y,endIndex:b}=e.parseProcessSubstitutionFromString(t,d);f.push(y),d=b;continue}if(m==="~"){let y=d>0?t[d-1]:"";if(d===0&&u||y==="="||s&&y===":"){let w=vl(e,t,d),E=t[w];if(E===void 0||E==="/"||E===":"){p();let S=t.slice(d+1,w)||null;f.push({type:"TildeExpansion",user:S}),d=w;continue}}}if("@*+?!".includes(m)&&d+1<t.length&&t[d+1]==="("){let y=Xd(t,d+1);if(y!==-1){p();let b=t.slice(d,y+1);f.push({type:"Glob",pattern:b}),d=y+1;continue}}if(m==="*"||m==="?"||m==="["){p();let{pattern:y,endIndex:b}=xl(e,t,d);f.push({type:"Glob",pattern:l?Kd(y):y}),d=b;continue}if(m==="{"&&!s&&!a&&!i){let y=$l(e,t,d,Jt);if(y){p(),f.push(y.part),d=y.endIndex;continue}}h+=m,d++}return p(),f}var Q=class e{tokens=[];pos=0;pendingHeredocs=[];parseBudget;ownsParseBudget;_input="";processLineState;constructor(t){this.parseBudget=t??new Jr,this.ownsParseBudget=t===void 0}getInput(){return this._input}checkIterationLimit(){let t=this.current();this.parseBudget.chargeIteration(t?.line??1,t?.column??1)}enterDepth(){let t=this.current();return this.parseBudget.enter(t?.line??1,t?.column??1)}withDepth(t){let n=this.enterDepth();try{return t()}finally{n()}}parse(t,n){this.ownsParseBudget&&this.parseBudget.reset();let r=this.ownsParseBudget?void 0:this.enterDepth();try{if(t.length>wi)throw new xe(`Input too large: ${t.length} bytes exceeds limit of ${wi}`,1,1);this._input=t,this.processLineState=void 0;let s=new Yr(t,n);if(this.tokens=s.tokenize(),this.tokens.length>fr)throw new xe(`Too many tokens: ${this.tokens.length} exceeds limit of ${fr}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseBudget.chargeTokens(this.tokens.length),this.parseScript()}finally{r?.()}}parseTokens(t){this.ownsParseBudget&&this.parseBudget.reset();let n=this.ownsParseBudget?void 0:this.enterDepth();try{return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.processLineState=void 0,this.parseBudget.chargeTokens(t.length),this.parseScript()}finally{n?.()}}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}getSourceLine(t=this.current()){let n=this.processLineState;return n?(n.currentPhysicalLine===void 0?n.currentPhysicalLine=t.line:t.line>n.currentPhysicalLine&&(n.currentPhysicalLine=t.line,n.currentLogicalLine+=1),n.currentLogicalLine):t.line}check(t,n,r,s,...i){let o=this.tokens[this.pos]?.type;return o===t||n!==void 0&&o===n||r!==void 0&&o===r||s!==void 0&&o===s?!0:i.length>0?i.includes(o):!1}expect(t,n){if(this.check(t))return this.advance();let r=this.current();throw new xe(n||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let n=this.current();throw new xe(t,n.line,n.column,n)}skipNewlines(){for(;this.check(g.NEWLINE,g.COMMENT);)this.check(g.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(g.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(g.SEMICOLON,g.COMMENT)){this.advance();continue}if(t&&this.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,n,r,s){this.pendingHeredocs.push({redirect:t,delimiter:n,stripTabs:r,quoted:s})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(g.HEREDOC_CONTENT)){let n=this.advance(),r;t.quoted?r=M.word([M.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),t.redirect.target=M.hereDoc(t.delimiter,r,t.stripTabs,t.quoted,n.heredocTerminated??!1)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(g.EOF,g.NEWLINE,g.SEMICOLON,g.AMP,g.AND_AND,g.OR_OR,g.RPAREN,g.RBRACE,g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return this.isWord()||t===g.ASSIGNMENT_WORD||t===g.FD_VARIABLE||t===g.LPAREN||t===g.LBRACE||t===g.DPAREN_START||t===g.DBRACK_START||pr(this)}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(g.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)");let s=this.checkUnexpectedToken();if(s){t.push(s),this.skipSeparators(!1);continue}let i=this.pos,o=this.parseStatement();o&&t.push(o),this.check(g.HEREDOC_CONTENT)&&this.processHeredocs(),this.skipSeparators(!1),this.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(g.EOF)&&this.error(`syntax error near unexpected token \`${this.current().value}'`)}return M.script(t)}checkUnexpectedToken(){let t=this.current().type,n=this.current().value;if(this.currentTokenJoinsProcessSubstitution())return null;if((t===g.DO||t===g.DONE||t===g.THEN||t===g.ELSE||t===g.ELIF||t===g.FI||t===g.ESAC)&&this.error(`syntax error near unexpected token \`${n}'`),t===g.RBRACE||t===g.RPAREN){let r=`syntax error near unexpected token \`${n}'`;return this.advance(),M.statement([M.pipeline([M.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:n})}return(t===g.DSEMI||t===g.SEMI_AND||t===g.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),t===g.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`),(t===g.AMP||t===g.AND_AND||t===g.OR_OR||t===g.PIPE||t===g.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${n}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,n=[],r=[],s=!1,i=this.parsePipeline();for(n.push(i);this.check(g.AND_AND,g.OR_OR);){let l=this.advance();r.push(l.type===g.AND_AND?"&&":"||"),this.skipNewlines();let c=this.parsePipeline();n.push(c)}this.check(g.AMP)&&(this.advance(),s=!0);let o=this.pos>0?this.tokens[this.pos-1].end:t,a=this._input.slice(t,o);return M.statement(n,r,s,void 0,a)}parseTimePrefix(){if(!this.check(g.TIME)||this.currentTokenJoinsProcessSubstitution())return;this.advance();let t=!1;return this.check(g.WORD,g.NAME)&&this.current().value==="-p"&&(this.advance(),t=!0),t}parsePipeline(){let t=!1,n=!1,r=0;for(;this.check(g.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++;if(r===0){let l=this.parseTimePrefix();if(l!==void 0)for(t=!0,n=l;this.check(g.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++}let s=r%2===1,i=[],o=[],a=this.parseCommand();for(i.push(a);this.check(g.PIPE,g.PIPE_AMP);){let l=this.advance();this.skipNewlines(),o.push(l.type===g.PIPE_AMP);let c=this.parseCommand();i.push(c)}return M.pipeline(i,s,t,n,o.length>0?o:void 0)}parseCommand(){if(this.currentTokenJoinsProcessSubstitution())return xi(this);let t=this.current();switch(t.type){case g.IF:return Pi(this);case g.FOR:return $i(this);case g.WHILE:return Ci(this);case g.UNTIL:return Ni(this);case g.CASE:return Ri(this);case g.LPAREN:return Oi(this);case g.LBRACE:return Di(this);case g.DPAREN_START:return this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand();case g.DBRACK_START:return this.parseConditionalCommand();case g.FUNCTION:return this.parseFunctionDef();case g.TIME:break;case g.BANG:this.error(`syntax error near unexpected token \`${t.value}'`);break;default:gi(t.type)&&this.error(`syntax error near unexpected token \`${t.value}'`)}return this.check(g.NAME,g.WORD)&&this.peek(1).type===g.LPAREN&&this.peek(2).type===g.RPAREN?this.parseFunctionDef():xi(this)}dparenClosesWithSpacedParens(){let t=1,n=1;for(;n<this.tokens.length-this.pos;){let r=this.peek(n);if(r.type===g.EOF)return!1;if(r.type===g.DPAREN_START||r.type===g.LPAREN)t++;else if(r.type===g.DPAREN_END){if(t-=2,t<=0)return!1}else if(r.type===g.RPAREN&&(t--,t===0&&this.peek(n+1).type===g.RPAREN))return!0;n++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(g.RPAREN),this.expect(g.RPAREN);let n=this.parseOptionalRedirections(),r=M.subshell(t,[]);return M.subshell([M.statement([M.pipeline([r],!1,!1,!1)])],n)}isWord(){return this.isWordToken(Re.Default)||this.isProcessSubstitutionStart()||this.currentTokenJoinsProcessSubstitution()}isWordToken(t){let n=this.current().type;return n===g.WORD||n===g.NAME||n===g.NUMBER||gi(n)||n===g.BANG||n===g.ASSIGNMENT_WORD&&(t&Re.Regex)!==0}isProcessSubstitutionStart(t=0){let n=this.peek(t),r=this.peek(t+1);return(n.type===g.LESS||n.type===g.GREAT)&&r.type===g.LPAREN&&n.end===r.start}currentTokenJoinsProcessSubstitution(){return this.current().type===g.COMMENT||!this.isAdjacentWordToken(Re.Default)?!1:this.current().end===this.peek(1).start&&this.isProcessSubstitutionStart(1)}isAdjacentWordToken(t){let n=this.current().type;return this.isWordToken(t)||n===g.ASSIGNMENT_WORD||n===g.COMMENT||n===g.LBRACE||n===g.RBRACE||n===g.DBRACK_START||n===g.DBRACK_END||n===g.FD_VARIABLE}parseWord(t=Re.Default){if(this.isProcessSubstitutionStart())return this.parseAdjacentWordParts([],this.current().start,t);let n=this.advance(),r=this.parseWordToken(n,t);return this.parseAdjacentWordParts(r.parts,n.end,t)}parseAdjacentWordParts(t,n,r=Re.Default){for(;n===this.current().start;){if(this.isProcessSubstitutionStart()){t.push(this.parseProcessSubstitution()),n=this.tokens[this.pos-1].end;continue}if(!this.isAdjacentWordToken(r))break;let s=this.advance();t.push(...this.parseWordToken(s,r,t.length===0).parts),n=s.end}return M.word(t)}parseWordNoBraceExpansion(){return this.parseWord(Re.NoBraceExpansion)}parseWordForRegex(){return this.parseWord(Re.NoBraceExpansion|Re.Regex)}parseWordToken(t,n,r=!0){return t.type===g.LBRACE||t.type===g.RBRACE||t.type===g.DBRACK_START||t.type===g.DBRACK_END||t.type===g.FD_VARIABLE?M.word([M.literal(t.type===g.FD_VARIABLE?`{${t.value}}`:t.value)]):this.parseWordFromString(t.value,t.quoted,t.singleQuoted,(n&Re.Assignment)!==0,!1,(n&Re.NoBraceExpansion)!==0,(n&Re.Regex)!==0,r)}parseWordFromString(t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!0){let c=Jt(this,t,n,r,s,i,!1,o,a,!1,l);return M.word(c)}parseCommandSubstitution(t,n){return Ja(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitutionFromString(t,n){return el(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitution(){let t=this.advance();this.expect(g.LPAREN);let n=this.processLineState,r=this.getSourceLine(t);this.processLineState={currentLogicalLine:r};let s;try{s=M.script(this.parseCompoundList())}finally{this.processLineState=n}return this.check(g.EOF)&&this.error("unexpected EOF while looking for matching `)'"),this.expect(g.RPAREN),M.processSubstitution(s,t.type===g.LESS?"input":"output")}parseBacktickSubstitution(t,n,r=!1){return tl(t,n,r,()=>new e(this.parseBudget),s=>this.error(s))}isDollarDparenSubshell(t,n){return Xa(t,n)}parseArithmeticExpansion(t,n){let r=n+3,s=1,i=0,o=r;for(;o<t.length-1&&s>0;)t[o]==="$"&&t[o+1]==="("?t[o+2]==="("?(s++,o+=3):(i++,o+=2):t[o]==="("&&t[o+1]==="("?(s++,o+=2):t[o]===")"&&t[o+1]===")"?i>0?(i--,o++):(s--,s>0&&(o+=2)):t[o]==="("?(i++,o++):(t[o]===")"&&i>0&&i--,o++);let a=t.slice(r,o),l=this.parseArithmeticExpression(a);return{part:M.arithmeticExpansion(l),endIndex:o+2}}parseArithmeticCommand(){let t=this.expect(g.DPAREN_START),n="",r=1,s=0,i=!1,o=!1;for(;r>0&&!this.check(g.EOF);){if(i){if(i=!1,s>0){s--,n+=")";continue}if(this.check(g.RPAREN)){r--,o=!0,this.advance();continue}if(this.check(g.DPAREN_END)){r--,o=!0;continue}n+=")";continue}if(this.check(g.DPAREN_START))r++,n+="((",this.advance();else if(this.check(g.DPAREN_END))s>=2?(s-=2,n+="))",this.advance()):s===1?(s--,n+=")",i=!0,this.advance()):(r--,o=!0,r>0&&(n+="))"),this.advance());else if(this.check(g.LPAREN))s++,n+="(",this.advance();else if(this.check(g.RPAREN))s>0&&s--,n+=")",this.advance();else{let c=this.current().value,u=n.length>0?n[n.length-1]:"";n.length>0&&!n.endsWith(" ")&&!(c==="="&&/[|&^+\-*/%<>]$/.test(n))&&!(c==="<"&&u==="<")&&!(c===">"&&u===">")&&(n+=" "),n+=c,this.advance()}}o||this.expect(g.DPAREN_END);let a=this.parseArithmeticExpression(n.trim()),l=this.parseOptionalRedirections();return M.arithmeticCommand(a,l,this.getSourceLine(t))}parseConditionalCommand(){let t=this.expect(g.DBRACK_START),n=_i(this);this.expect(g.DBRACK_END);let r=this.parseOptionalRedirections();return M.conditionalCommand(n,r,this.getSourceLine(t))}parseFunctionDef(){let t;if(this.check(g.FUNCTION)){if(this.advance(),this.check(g.NAME)||this.check(g.WORD))t=this.advance().value;else{let s=this.current();throw new xe("Expected function name",s.line,s.column,s)}this.check(g.LPAREN)&&(this.advance(),this.expect(g.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(g.LPAREN),this.expect(g.RPAREN);this.skipNewlines();let n=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return M.functionDef(t,n,r)}parseCompoundCommandBody(t){let n=t?.forFunctionBody;if(this.check(g.LBRACE))return Di(this,{skipRedirections:n});if(this.check(g.LPAREN))return Oi(this,{skipRedirections:n});if(this.check(g.IF))return Pi(this,{skipRedirections:n});if(this.check(g.FOR))return $i(this,{skipRedirections:n});if(this.check(g.WHILE))return Ci(this,{skipRedirections:n});if(this.check(g.UNTIL))return Ni(this,{skipRedirections:n});if(this.check(g.CASE))return Ri(this,{skipRedirections:n});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth();try{let n=[];for(this.skipNewlines();(this.currentTokenJoinsProcessSubstitution()||!this.check(g.EOF,g.FI,g.ELSE,g.ELIF,g.THEN,g.DO,g.DONE,g.ESAC,g.RPAREN,g.RBRACE,g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND))&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,s=this.parseStatement();if(s&&n.push(s),this.skipSeparators(),this.pos===r&&!s)break}return n}finally{t()}}parseOptionalRedirections(){let t=[];for(;pr(this);){this.checkIterationLimit();let n=this.pos;if(t.push(rs(this)),this.pos===n)break}return t}parseArithmeticExpression(t){return re(this,t)}};function He(e,t){return new Q().parse(e,t)}function yr(e){return Pn(e)}function Pn(e){return e.statements.map(_l).join(`
|
|
76
|
+
`)}function _l(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(nh(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let n=t.join(" ");return e.background&&(n+=" &"),n}function nh(e){let t=[];e.timed&&t.push(e.timePosix?"time -p":"time"),e.negated&&t.push("!");let n=[];for(let s=0;s<e.commands.length;s++)if(n.push(Tl(e.commands[s])),s<e.commands.length-1){let i=e.pipeStderr?.[s];n.push(i?"|&":"|")}return(t.length>0?`${t.join(" ")} `:"")+n.join(" ")}function Tl(e){switch(e.type){case"SimpleCommand":return rh(e);case"If":return dh(e);case"For":return hh(e);case"CStyleFor":return ph(e);case"While":return mh(e);case"Until":return yh(e);case"Case":return gh(e);case"Subshell":return Eh(e);case"Group":return bh(e);case"ArithmeticCommand":return Sh(e);case"ConditionalCommand":return Ah(e);case"FunctionDef":return vh(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function rh(e){let t=[];for(let n of e.assignments)t.push(sh(n));e.name&&t.push(we(e.name));for(let n of e.args)t.push(we(n));for(let n of e.redirections)t.push(Ml(n));return t.join(" ")}function sh(e){let t=e.append?"+=":"=";if(e.array){let n=e.array.map(we).join(" ");return`${e.name}${t}(${n})`}return e.value?`${e.name}${t}${we(e.value)}`:`${e.name}${t}`}function we(e){return e.parts.map(t=>ss(t,!1)).join("")}function en(e){return e.parts.map(t=>ss(t,!0)).join("")}function ss(e,t){switch(e.type){case"Literal":return t?oh(e.value):ih(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(n=>ss(n,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Ll(e);case"CommandSubstitution":return e.legacy?`\`${Pn(e.body)}\``:`$(${Pn(e.body)})`;case"ArithmeticExpansion":return`$((${he(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${Pn(e.body)})`:`>(${Pn(e.body)})`;case"BraceExpansion":return uh(e);case"TildeExpansion":return e.user!==null?`~${e.user}`:"~";case"Glob":return e.pattern;default:{let n=e;throw new Error(`Unsupported word part type: ${n.type}`)}}}function ih(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function oh(e){return e.replace(/[$`"\\]/g,"\\$&")}function ah(e,t){return e.parts.map(n=>lh(n,t)).join("")}function lh(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Ll(e);case"CommandSubstitution":return e.legacy?`\`${Pn(e.body)}\``:`$(${Pn(e.body)})`;case"ArithmeticExpansion":return`$((${he(e.expression.expression)}))`;default:return ss(e,!1)}}function Ll(e){return e.operation?`\${${Fl(e.parameter,e.operation)}}`:ch(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function ch(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function Fl(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${en(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${en(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?en(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${en(t.word)}`;case"Substring":{let n=he(t.offset.expression);return t.length?`${e}:${n}:${he(t.length.expression)}`:`${e}:${n}`}case"PatternRemoval":{let n=t.side==="prefix"?"#":"%",r=t.greedy?`${n}${n}`:n;return`${e}${r}${en(t.pattern)}`}case"PatternReplacement":{let n="/";t.all?n="//":t.anchor==="start"?n="/#":t.anchor==="end"&&(n="/%");let r=t.replacement?`/${en(t.replacement)}`:"";return`${e}${n}${en(t.pattern)}${r}`}case"CaseModification":{let n=t.direction==="upper"?"^":",",r=t.all?`${n}${n}`:n,s=t.pattern?en(t.pattern):"";return`${e}${r}${s}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${Fl(e,t.innerOp)}`:`!${e}`;case"ArrayKeys":return`!${t.array}[${t.star?"*":"@"}]`;case"VarNamePrefix":return`!${t.prefix}${t.star?"*":"@"}`;default:{let n=t;throw new Error(`Unsupported parameter operation type: ${n.type}`)}}}function uh(e){return`{${e.items.map(fh).join(",")}}`}function fh(e){if(e.type==="Word")return we(e.word);let t=e.startStr??String(e.start),n=e.endStr??String(e.end);return e.step!==void 0?`${t}..${n}..${e.step}`:`${t}..${n}`}function Ml(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let n=e.target;if(n.terminated===!1)throw new Error("Cannot serialize an unterminated here-document");let r=n.quoted?`'${n.delimiter}'`:n.delimiter,s=ah(n.content,n.quoted);return`${t}${e.operator}${r}
|
|
77
|
+
${s}${n.delimiter}`}return e.operator==="<<<"?`${t}<<< ${we(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${we(e.target)}`:`${t}${e.operator} ${we(e.target)}`}function gt(e){return e.length===0?"":` ${e.map(Ml).join(" ")}`}function at(e){return e.map(_l).join(`
|
|
78
|
+
`)}function dh(e){let t=[];for(let n=0;n<e.clauses.length;n++){let r=e.clauses[n],s=n===0?"if":"elif";t.push(`${s} ${at(r.condition)}; then
|
|
79
|
+
${at(r.body)}`)}return e.elseBody&&t.push(`else
|
|
80
|
+
${at(e.elseBody)}`),`${t.join(`
|
|
81
81
|
`)}
|
|
82
|
-
fi${
|
|
83
|
-
${
|
|
84
|
-
done${
|
|
85
|
-
${
|
|
86
|
-
done${
|
|
87
|
-
${
|
|
88
|
-
done${
|
|
89
|
-
${
|
|
90
|
-
done${
|
|
82
|
+
fi${gt(e.redirections)}`}function hh(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let n=e.words.map(we).join(" ");t=`for ${e.variable} in ${n}`}return`${t}; do
|
|
83
|
+
${at(e.body)}
|
|
84
|
+
done${gt(e.redirections)}`}function ph(e){let t=e.init?he(e.init.expression):"",n=e.condition?he(e.condition.expression):"",r=e.update?he(e.update.expression):"";return`for ((${t}; ${n}; ${r})); do
|
|
85
|
+
${at(e.body)}
|
|
86
|
+
done${gt(e.redirections)}`}function mh(e){return`while ${at(e.condition)}; do
|
|
87
|
+
${at(e.body)}
|
|
88
|
+
done${gt(e.redirections)}`}function yh(e){return`until ${at(e.condition)}; do
|
|
89
|
+
${at(e.body)}
|
|
90
|
+
done${gt(e.redirections)}`}function gh(e){let t=e.items.map(wh).join(`
|
|
91
91
|
`);return`case ${we(e.word)} in
|
|
92
92
|
${t}
|
|
93
|
-
esac${
|
|
93
|
+
esac${gt(e.redirections)}`}function wh(e){let t=e.patterns.map(we).join(" | "),n=at(e.body);return n?`${t})
|
|
94
94
|
${n}
|
|
95
95
|
${e.terminator}`:`${t})
|
|
96
|
-
${e.terminator}`}function hh(e){return`(${lt(e.body)})${wt(e.redirections)}`}function ph(e){return`{ ${lt(e.body)}; }${wt(e.redirections)}`}function mh(e){return`((${he(e.expression.expression)}))${wt(e.redirections)}`}function yh(e){return`[[ ${xn(e.expression)} ]]${wt(e.redirections)}`}function gh(e){let t=Ol(e.body);return`${e.name}() ${t}${wt(e.redirections)}`}function he(e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return e.hasDollarPrefix?`$${e.name}`:e.name;case"ArithSpecialVar":return`$${e.name}`;case"ArithBinary":return`${he(e.left)} ${e.operator} ${he(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${he(e.operand)}`:`${he(e.operand)}${e.operator}`;case"ArithTernary":return`${he(e.condition)} ? ${he(e.consequent)} : ${he(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${he(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${he(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${he(e.target)}[${he(e.subscript)}]`:he(e.target)} ${e.operator} ${he(e.value)}`;case"ArithDynamicElement":return`${he(e.nameExpr)}[${he(e.subscript)}]`;case"ArithGroup":return`(${he(e.expression)})`;case"ArithNested":return`$((${he(e.expression)}))`;case"ArithCommandSubst":return`$(${e.command})`;case"ArithBracedExpansion":return`\${${e.content}}`;case"ArithArrayElement":return e.stringKey!==void 0?`${e.array}[${e.stringKey}]`:e.index?`${e.array}[${he(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(he).join("");case"ArithDoubleSubscript":return`${e.array}[${he(e.index)}]`;case"ArithNumberSubscript":return`${e.number}[${e.errorToken}]`;case"ArithSyntaxError":return e.errorToken;case"ArithSingleQuote":return`'${e.content}'`;default:{let t=e;throw new Error(`Unsupported arithmetic expression type: ${t.type}`)}}}function xn(e){switch(e.type){case"CondBinary":return`${we(e.left)} ${e.operator} ${we(e.right)}`;case"CondUnary":return`${e.operator} ${we(e.operand)}`;case"CondNot":return`! ${xn(e.operand)}`;case"CondAnd":return`${xn(e.left)} && ${xn(e.right)}`;case"CondOr":return`${xn(e.left)} || ${xn(e.right)}`;case"CondGroup":return`( ${xn(e.expression)} )`;case"CondWord":return we(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var wh="BASH_ALIAS_";function ts(e,t,n,r){let s=M(t);if(s>n-r.value)throw new $(`alias expansion exceeds string length limit (${n} bytes)`,"string_length");return r.value+=s,e+t}function Tl(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function Ll(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function Fl(e,t){return e.env.get(`${wh}${t}`)}function Bl(e,t,n){return Wl(e,t,n)}function Wl(e,t,n,r=!0){if(!t.name||!Tl(t.name))return t;let s=Ll(t.name);if(!s)return t;let i=Fl(e,s);if(!i||n.has(s))return t;try{n.add(s);let o=new Z,a={value:0},l=ts("",i,e.limits.maxStringLength,a),c=i.endsWith(" ");if(!c)for(let h of t.args){let p=we(h);l=ts(l,` ${p}`,e.limits.maxStringLength,a)}let u;try{u=o.parse(l)}catch(h){if(h instanceof Pe)throw h;return t}if(u.statements.length!==1||u.statements[0].pipelines.length!==1||u.statements[0].pipelines[0].commands.length!==1)return Ml(e,t,i);let f=u.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return Ml(e,t,i);let d={...f,assignments:[...t.assignments,...f.assignments],redirections:[...f.redirections,...t.redirections],line:t.line};if(c&&t.args.length>0){d={...d,args:[...d.args,...t.args]};let h=1;for(;r&&d.args.length>0;){let p=d.args[0];if(!Tl(p))break;let m=Ll(p),E=m?Fl(e,m):null;if(!E)break;if(h>=e.limits.maxCallDepth)throw new $(`alias expansion depth limit exceeded (${e.limits.maxCallDepth})`,"recursion");h++;let S={type:"SimpleCommand",name:p,args:d.args.slice(1),assignments:[],redirections:[]},y=Wl(e,S,n,!1);if(y===S||(d={...d,name:y.name,args:[...y.args]},!E.endsWith(" ")))break}}return d}catch(o){throw n.delete(s),o}}function Ml(e,t,n){let r={value:0},s=ts("",n,e.limits.maxStringLength,r);for(let c of t.args){let u=we(c);s=ts(s,` ${u}`,e.limits.maxStringLength,r)}let i=new Z,o=i.parseWordFromString("eval",!1,!1),a=0;for(let c of s)c==="'"&&a++;if(r.value+2+a*3>e.limits.maxStringLength)throw new $(`alias expansion exceeds string length limit (${e.limits.maxStringLength} bytes)`,"string_length");let l=i.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:o,args:[l],assignments:t.assignments,redirections:t.redirections,line:t.line}}var Eh=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function Ti(e){return Eh.get(e)??""}function Vl(e){let t=[],n="",r=0;for(;r<e.length;){let s=e[r];if(s==="["){for(n+=s,r++,r<e.length&&(e[r]==="!"||e[r]==="^")&&(n+=e[r],r++),r<e.length&&e[r]==="]"&&(n+=e[r],r++);r<e.length&&e[r]!=="]";){if(e[r]==="["&&r+1<e.length&&e[r+1]===":"){let i=e.indexOf(":]",r+2);if(i!==-1){n+=e.slice(r,i+2),r=i+2;continue}}if(e[r]==="\\"&&r+1<e.length){n+=e[r]+e[r+1],r+=2;continue}n+=e[r],r++}r<e.length&&e[r]==="]"&&(n+=e[r],r++)}else s===":"?(n!==""&&t.push(n),n="",r++):s==="\\"&&r+1<e.length?(n+=s+e[r+1],r+=2):(n+=s,r++)}return n!==""&&t.push(n),t}function zl(e){let t="^";for(let n=0;n<e.length;n++){let r=e[n];if(r==="*")t+="[^/]*";else if(r==="?")t+="[^/]";else if(r==="["){let s=n+1,i="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(i+="^",s++),s<e.length&&e[s]==="]"&&(i+="\\]",s++);let o=s;for(;o<e.length;){if(e[o]==="\\"&&o+1<e.length){o+=2;continue}if(e[o]==="["&&o+1<e.length&&e[o+1]===":"){let l=e.indexOf(":]",o+2);if(l!==-1){o=l+2;continue}}if(e[o]==="]")break;o++}let a=s;for(;s<e.length&&e[s]!=="]";){if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let l=e.indexOf(":]",s+2);if(l!==-1){let c=e.slice(s+2,l),u=Ti(c);i+=u,s=l+2;continue}}if(e[s]==="\\"&&s+1<e.length){i+=`\\${e[s+1]}`,s+=2;continue}if(e[s]==="-"){let l=s===a,c=s+1===o;l||c?i+="\\-":i+="-"}else i+=e[s];s++}i+="]",t+=i,n=s}else if(r==="\\"&&n+1<e.length){let s=e[n+1];/[.+^${}()|\\*?[\]]/.test(s)?t+=`\\${s}`:t+=s,n++}else/[.+^${}()|]/.test(r)?t+=`\\${r}`:t+=r}return t+="$",ge(t)}function Li(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function Fi(e){let t=[],n="",r=0,s=!1,i=0;for(;i<e.length;){let o=e[i];if(o==="'"&&!s){s=!0,n+="\0QUOTE_START\0",i++;continue}if(o==="'"&&s){s=!1,n+="\0QUOTE_END\0",i++;continue}if(s){n+=o,i++;continue}if(o==="\\"){n+=o,i+1<e.length?(n+=e[i+1],i+=2):i++;continue}o==="("?(r++,n+=o):o===")"?(r--,n+=o):o==="|"&&r===0?(t.push(n),n=""):n+=o,i++}return t.push(n),t}var Ul=5,tn=class{fs;cwd;globignorePatterns=[];hasGlobignore=!1;globstar=!1;nullglob=!1;failglob=!1;dotglob=!1;extglob=!1;globskipdots=!0;ops={count:0};maxOps;consumeOperation;constructor(t,n,r,s){this.fs=t,this.cwd=n,typeof s=="boolean"?(this.globstar=s,this.maxOps=1e5):s?(this.globstar=s.globstar??!1,this.nullglob=s.nullglob??!1,this.failglob=s.failglob??!1,this.dotglob=s.dotglob??!1,this.extglob=s.extglob??!1,this.globskipdots=s.globskipdots??!0,this.maxOps=s.maxGlobOperations??1e5,this.consumeOperation=s.consumeOperation):this.maxOps=1e5;let i=r?.get("GLOBIGNORE");i!==void 0&&i!==""&&(this.hasGlobignore=!0,this.globignorePatterns=Vl(i))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new $(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations");this.consumeOperation?.()}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(n=>{let r=n.split("/").pop()||n;if((this.hasGlobignore||this.globskipdots)&&(r==="."||r===".."))return!1;if(this.hasGlobignore){for(let s of this.globignorePatterns)if(this.matchGlobignorePattern(n,s))return!1}return!0})}matchGlobignorePattern(t,n){return zl(n).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,n){let r=t.map((o,a)=>(n?.[a]??!1)||!this.isGlobPattern(o)?null:this.expand(o)),s=await Promise.all(r.map(o=>o||Promise.resolve(null))),i=[];for(let o=0;o<t.length;o++){let a=s[o];a===null?i.push(t[o]):a.length>0?i.push(...a):i.push(t[o])}return i}async expand(t){if(this.globstar){let r=t.split("/"),s=0;for(let i of r)if(i==="**"&&(s++,s>Ul))throw new $(`Glob pattern has too many ** segments (max ${Ul})`,"glob_operations")}let n;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))n=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");n=await this.expandSimple(r)}return this.filterGlobignore(n)}isGlobstarValid(t){let n=t.split("/");for(let r of n)if(r.includes("**")&&r!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let n=t.startsWith("/"),r=t.split("/").filter(c=>c!==""),s=-1;for(let c=0;c<r.length;c++)if(this.hasGlobChars(r[c])){s=c;break}if(s===-1)return[t];let i,o;if(s===0)n?(i="/",o="/"):(i=this.cwd,o="");else{let c=r.slice(0,s);n?(i=`/${c.join("/")}`,o=`/${c.join("/")}`):(i=this.fs.resolvePath(this.cwd,c.join("/")),o=c.join("/"))}let a=r.slice(s);return(await this.expandSegments(i,o,a)).sort()}async expandSegments(t,n,r){if(this.checkOpsLimit(),r.length===0)return[n];let[s,...i]=r,o=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(t),l=[],c=[...a],u=this.dotglob||this.hasGlobignore;if(s.startsWith(".")||this.dotglob){let d=a.some(p=>p.name==="."),h=a.some(p=>p.name==="..");d||c.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),h||c.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of c)if(!(d.name.startsWith(".")&&!s.startsWith(".")&&!u)&&this.matchPattern(d.name,s)){let h=t==="/"?`/${d.name}`:`${t}/${d.name}`,p;n===""?p=d.name:n==="/"?p=`/${d.name}`:p=`${n}/${d.name}`,i.length===0?l.push(Promise.resolve([p])):d.isDirectory&&l.push(this.expandSegments(h,p,i))}let f=await Promise.all(l);for(let d of f)o.push(...d)}else{this.checkOpsLimit();let a=await this.fs.readdir(t),l=[],c=[...a],u=this.dotglob||this.hasGlobignore;(s.startsWith(".")||this.dotglob)&&(a.includes(".")||c.push("."),a.includes("..")||c.push(".."));for(let d of c)if(!(d.startsWith(".")&&!s.startsWith(".")&&!u)&&this.matchPattern(d,s)){let h=t==="/"?`/${d}`:`${t}/${d}`,p;n===""?p=d:n==="/"?p=`/${d}`:p=`${n}/${d}`,i.length===0?l.push(Promise.resolve([p])):l.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(h)).isDirectory)return this.expandSegments(h,p,i)}catch(m){if(m instanceof $)throw m}return[]})())}let f=await Promise.all(l);for(let d of f)o.push(...d)}}catch(a){if(a instanceof $)throw a}return o}async expandRecursive(t){let n=[],r=t.indexOf("**"),s=t.slice(0,r).replace(/\/$/,"")||".",o=t.slice(r+2).replace(/^\//,"");return o.includes("**")&&this.isGlobstarValid(o)?(await this.walkDirectoryMultiGlobstar(s,o,n),[...new Set(n)].sort()):(await this.walkDirectory(s,o,n),n.sort())}async walkDirectoryMultiGlobstar(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let i=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(s):null;if(i){let o=[];for(let c of i){let u=t==="."?c.name:`${t}/${c.name}`;c.isDirectory&&o.push(u)}let a=t==="."?n:`${t}/${n}`,l=await this.expandRecursive(a);r.push(...l);for(let c=0;c<o.length;c+=100){let u=o.slice(c,c+100);await Promise.all(u.map(f=>this.walkDirectoryMultiGlobstar(f,n,r)))}}else{this.checkOpsLimit();let o=await this.fs.readdir(s),a=[];for(let u of o){let f=t==="."?u:`${t}/${u}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&a.push(f)}catch(h){if(h instanceof $)throw h}}let l=t==="."?n:`${t}/${n}`,c=await this.expandRecursive(l);r.push(...c);for(let u=0;u<a.length;u+=100){let f=a.slice(u,u+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,n,r)))}}}catch(i){if(i instanceof $)throw i}}async walkDirectory(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let i=await this.fs.readdirWithFileTypes(s),o=[],a=[];for(let l of i){let c=t==="."?l.name:`${t}/${l.name}`;l.isDirectory?a.push(c):n&&this.matchPattern(l.name,n)&&o.push(c)}r.push(...o);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u,n,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(s),o=[];for(let l=0;l<i.length;l+=100){let c=i.slice(l,l+100),u=await Promise.all(c.map(async f=>{let d=t==="."?f:`${t}/${f}`,h=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let p=await this.fs.stat(h);return{name:f,path:d,isDirectory:p.isDirectory}}catch(p){if(p instanceof $)throw p;return null}}));o.push(...u.filter(f=>f!==null))}for(let l of o)!l.isDirectory&&n&&this.matchPattern(l.name,n)&&r.push(l.path);let a=o.filter(l=>l.isDirectory);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,n,r)))}}}catch(i){if(i instanceof $)throw i}}matchPattern(t,n){return this.patternToRegex(n).test(t)}patternToRegex(t){let n=this.patternToRegexStr(t);return ge(`^${n}$`)}patternToRegexStr(t){let n="",r=!1;for(let s=0;s<t.length;s++){if(t.slice(s,s+13)==="\0QUOTE_START\0"){r=!0,s+=12;continue}if(t.slice(s,s+11)==="\0QUOTE_END\0"){r=!1,s+=10;continue}let i=t[s];if(r){/[.+^${}()|\\*?[\]]/.test(i)?n+=`\\${i}`:n+=i;continue}if(this.extglob&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&s+1<t.length&&t[s+1]==="("){let o=Li(t,s+1);if(o!==-1){let a=t.slice(s+2,o),l=Fi(a),c=l.map(f=>this.patternToRegexStr(f)),u=c.length>0?c.join("|"):"(?:)";if(i==="@")n+=`(?:${u})`;else if(i==="*")n+=`(?:${u})*`;else if(i==="+")n+=`(?:${u})+`;else if(i==="?")n+=`(?:${u})?`;else if(i==="!")if(o<t.length-1){let d=l.map(p=>this.computePatternLength(p));if(d.every(p=>p!==null)&&d.every(p=>p===d[0])&&d[0]!==null){let p=d[0];if(p===0)n+="(?:.+)";else{let m=[];p>0&&m.push(`.{0,${p-1}}`),m.push(`.{${p+1},}`),m.push(`(?!(?:${u})).{${p}}`),n+=`(?:${m.join("|")})`}}else n+=`(?:(?!(?:${u})).)*?`}else n+=`(?!(?:${u})$).*`;s=o;continue}}if(i==="*")n+=".*";else if(i==="?")n+=".";else if(i==="["){let o=s+1,a="[";o<t.length&&(t[o]==="^"||t[o]==="!")&&(a+="^",o++),o<t.length&&t[o]==="]"&&(a+="\\]",o++);let l=o;for(;l<t.length;){if(t[l]==="\\"&&l+1<t.length){l+=2;continue}if(t[l]==="["&&l+1<t.length&&t[l+1]===":"){let u=t.indexOf(":]",l+2);if(u!==-1){l=u+2;continue}}if(t[l]==="]")break;l++}let c=o;for(;o<t.length&&t[o]!=="]";){if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let u=t.indexOf(":]",o+2);if(u!==-1){let f=t.slice(o+2,u),d=Ti(f);a+=d,o=u+2;continue}}if(t[o]==="\\"&&o+1<t.length){a+=`\\${t[o+1]}`,o+=2;continue}if(t[o]==="-"){let u=o===c,f=o+1===l;u||f?a+="\\-":a+="-"}else a+=t[o];o++}a+="]",n+=a,s=o}else if(i==="\\"&&s+1<t.length){let o=t[s+1];/[.+^${}()|\\*?[\]]/.test(o)?n+=`\\${o}`:n+=o,s++}else/[.+^${}()|]/.test(i)?n+=`\\${i}`:n+=i}return n}computePatternLength(t){let n=0,r=0,s=!1;for(;r<t.length;){if(t.slice(r,r+13)==="\0QUOTE_START\0"){s=!0,r+=13;continue}if(t.slice(r,r+11)==="\0QUOTE_END\0"){s=!1,r+=11;continue}let i=t[r];if(s){n+=1,r++;continue}if((i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&r+1<t.length&&t[r+1]==="("){let o=Li(t,r+1);if(o!==-1){if(i==="@"){let a=t.slice(r+2,o),c=Fi(a).map(u=>this.computePatternLength(u));if(c.every(u=>u!==null)&&c.every(u=>u===c[0])){n+=c[0],r=o+1;continue}return null}return null}}if(i==="*")return null;if(i==="?"){n+=1,r++;continue}if(i==="["){let o=t.indexOf("]",r+1);if(o!==-1){n+=1,r=o+1;continue}n+=1,r++;continue}if(i==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}};function Mi(e){for(let t=0;t<e.length;t++){if(e[t]==="\\"){t++;continue}if(e[t]==="$"){let n=e[t+1];if(n==="{"||n&&/[a-zA-Z_]/.test(n))return!0}}return!1}function bh(e){if(!e.operation)return!1;let t=e.operation,n;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(n=t.word?.parts),!n)return!1;for(let r of n)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function jl(e){if(!e.operation)return!1;let t=e.operation,n;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(n=t.word?.parts),!n||n.length===0)return!1;for(let r of n)if(r.type!=="DoubleQuoted"&&r.type!=="SingleQuoted")return!1;return!0}function yr(e){let t=!1,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1;for(let l of e){if((l.type==="SingleQuoted"||l.type==="DoubleQuoted")&&(t=!0,l.type==="DoubleQuoted"))for(let c of l.parts)c.type==="ParameterExpansion"&&(c.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!c.operation||c.operation.type==="PatternRemoval"||c.operation.type==="PatternReplacement")&&(s=!0),(c.operation?.type==="VarNamePrefix"||c.operation?.type==="ArrayKeys")&&(o=!0),c.operation?.type==="Indirection"&&(a=!0));l.type==="CommandSubstitution"&&(n=!0),l.type==="ParameterExpansion"&&(i=!0,(l.parameter==="@"||l.parameter==="*")&&(r=!0),bh(l)&&(t=!0),(l.operation?.type==="VarNamePrefix"||l.operation?.type==="ArrayKeys")&&(o=!0),l.operation?.type==="Indirection"&&(a=!0)),l.type==="Glob"&&Mi(l.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i,hasVarNamePrefixExpansion:o,hasIndirection:a}}var Sh=`
|
|
97
|
-
`;function $n(e,t){if(e>=t)throw new
|
|
98
|
-
`)return!1;return!0}function
|
|
99
|
-
`?n.push("\\n"):n.push(r);return t&&n.push("\\-"),n.join("")}function X(e){let t=e.get("IFS");if(t===void 0)return" ";let n=t.codePointAt(0);return n===void 0?"":String.fromCodePoint(n)}var
|
|
100
|
-
`;function
|
|
96
|
+
${e.terminator}`}function Eh(e){return`(${at(e.body)})${gt(e.redirections)}`}function bh(e){return`{ ${at(e.body)}; }${gt(e.redirections)}`}function Sh(e){return`((${he(e.expression.expression)}))${gt(e.redirections)}`}function Ah(e){return`[[ ${xn(e.expression)} ]]${gt(e.redirections)}`}function vh(e){let t=Tl(e.body);return`${e.name}() ${t}${gt(e.redirections)}`}function he(e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return e.hasDollarPrefix?`$${e.name}`:e.name;case"ArithSpecialVar":return`$${e.name}`;case"ArithBinary":return`${he(e.left)} ${e.operator} ${he(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${he(e.operand)}`:`${he(e.operand)}${e.operator}`;case"ArithTernary":return`${he(e.condition)} ? ${he(e.consequent)} : ${he(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${he(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${he(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${he(e.target)}[${he(e.subscript)}]`:he(e.target)} ${e.operator} ${he(e.value)}`;case"ArithDynamicElement":return`${he(e.nameExpr)}[${he(e.subscript)}]`;case"ArithGroup":return`(${he(e.expression)})`;case"ArithNested":return`$((${he(e.expression)}))`;case"ArithCommandSubst":return`$(${e.command})`;case"ArithBracedExpansion":return`\${${e.content}}`;case"ArithArrayElement":return e.stringKey!==void 0?`${e.array}[${e.stringKey}]`:e.index?`${e.array}[${he(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(he).join("");case"ArithDoubleSubscript":return`${e.array}[${he(e.index)}]`;case"ArithNumberSubscript":return`${e.number}[${e.errorToken}]`;case"ArithSyntaxError":return e.errorToken;case"ArithSingleQuote":return`'${e.content}'`;default:{let t=e;throw new Error(`Unsupported arithmetic expression type: ${t.type}`)}}}function xn(e){switch(e.type){case"CondBinary":return`${we(e.left)} ${e.operator} ${we(e.right)}`;case"CondUnary":return`${e.operator} ${we(e.operand)}`;case"CondNot":return`! ${xn(e.operand)}`;case"CondAnd":return`${xn(e.left)} && ${xn(e.right)}`;case"CondOr":return`${xn(e.left)} || ${xn(e.right)}`;case"CondGroup":return`( ${xn(e.expression)} )`;case"CondWord":return we(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var kh="BASH_ALIAS_";function is(e,t,n,r){let s=V(t);if(s>n-r.value)throw new C(`alias expansion exceeds string length limit (${n} bytes)`,"string_length");return r.value+=s,e+t}function Bl(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function Wl(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function Vl(e,t){return e.env.get(`${kh}${t}`)}function Ul(e,t,n){return jl(e,t,n)}function jl(e,t,n,r=!0){if(!t.name||!Bl(t.name))return t;let s=Wl(t.name);if(!s)return t;let i=Vl(e,s);if(!i||n.has(s))return t;try{n.add(s);let o=new Q,a={value:0},l=is("",i,e.limits.maxStringLength,a),c=i.endsWith(" ");if(!c)for(let h of t.args){let p=we(h);l=is(l,` ${p}`,e.limits.maxStringLength,a)}let u;try{u=o.parse(l)}catch(h){if(h instanceof xe)throw h;return t}if(u.statements.length!==1||u.statements[0].pipelines.length!==1||u.statements[0].pipelines[0].commands.length!==1)return zl(e,t,i);let f=u.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return zl(e,t,i);let d={...f,assignments:[...t.assignments,...f.assignments],redirections:[...f.redirections,...t.redirections],line:t.line};if(c&&t.args.length>0){d={...d,args:[...d.args,...t.args]};let h=1;for(;r&&d.args.length>0;){let p=d.args[0];if(!Bl(p))break;let m=Wl(p),y=m?Vl(e,m):null;if(!y)break;if(h>=e.limits.maxCallDepth)throw new C(`alias expansion depth limit exceeded (${e.limits.maxCallDepth})`,"recursion");h++;let b={type:"SimpleCommand",name:p,args:d.args.slice(1),assignments:[],redirections:[]},w=jl(e,b,n,!1);if(w===b||(d={...d,name:w.name,args:[...w.args]},!y.endsWith(" ")))break}}return d}catch(o){throw n.delete(s),o}}function zl(e,t,n){let r={value:0},s=is("",n,e.limits.maxStringLength,r);for(let c of t.args){let u=we(c);s=is(s,` ${u}`,e.limits.maxStringLength,r)}let i=new Q,o=i.parseWordFromString("eval",!1,!1),a=0;for(let c of s)c==="'"&&a++;if(r.value+2+a*3>e.limits.maxStringLength)throw new C(`alias expansion exceeds string length limit (${e.limits.maxStringLength} bytes)`,"string_length");let l=i.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:o,args:[l],assignments:t.assignments,redirections:t.redirections,line:t.line}}var xh=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function Fi(e){return xh.get(e)??""}function ql(e){let t=[],n="",r=0;for(;r<e.length;){let s=e[r];if(s==="["){for(n+=s,r++,r<e.length&&(e[r]==="!"||e[r]==="^")&&(n+=e[r],r++),r<e.length&&e[r]==="]"&&(n+=e[r],r++);r<e.length&&e[r]!=="]";){if(e[r]==="["&&r+1<e.length&&e[r+1]===":"){let i=e.indexOf(":]",r+2);if(i!==-1){n+=e.slice(r,i+2),r=i+2;continue}}if(e[r]==="\\"&&r+1<e.length){n+=e[r]+e[r+1],r+=2;continue}n+=e[r],r++}r<e.length&&e[r]==="]"&&(n+=e[r],r++)}else s===":"?(n!==""&&t.push(n),n="",r++):s==="\\"&&r+1<e.length?(n+=s+e[r+1],r+=2):(n+=s,r++)}return n!==""&&t.push(n),t}function Gl(e){let t="^";for(let n=0;n<e.length;n++){let r=e[n];if(r==="*")t+="[^/]*";else if(r==="?")t+="[^/]";else if(r==="["){let s=n+1,i="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(i+="^",s++),s<e.length&&e[s]==="]"&&(i+="\\]",s++);let o=s;for(;o<e.length;){if(e[o]==="\\"&&o+1<e.length){o+=2;continue}if(e[o]==="["&&o+1<e.length&&e[o+1]===":"){let l=e.indexOf(":]",o+2);if(l!==-1){o=l+2;continue}}if(e[o]==="]")break;o++}let a=s;for(;s<e.length&&e[s]!=="]";){if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let l=e.indexOf(":]",s+2);if(l!==-1){let c=e.slice(s+2,l),u=Fi(c);i+=u,s=l+2;continue}}if(e[s]==="\\"&&s+1<e.length){i+=`\\${e[s+1]}`,s+=2;continue}if(e[s]==="-"){let l=s===a,c=s+1===o;l||c?i+="\\-":i+="-"}else i+=e[s];s++}i+="]",t+=i,n=s}else if(r==="\\"&&n+1<e.length){let s=e[n+1];/[.+^${}()|\\*?[\]]/.test(s)?t+=`\\${s}`:t+=s,n++}else/[.+^${}()|]/.test(r)?t+=`\\${r}`:t+=r}return t+="$",ge(t)}function Mi(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function Bi(e){let t=[],n="",r=0,s=!1,i=0;for(;i<e.length;){let o=e[i];if(o==="'"&&!s){s=!0,n+="\0QUOTE_START\0",i++;continue}if(o==="'"&&s){s=!1,n+="\0QUOTE_END\0",i++;continue}if(s){n+=o,i++;continue}if(o==="\\"){n+=o,i+1<e.length?(n+=e[i+1],i+=2):i++;continue}o==="("?(r++,n+=o):o===")"?(r--,n+=o):o==="|"&&r===0?(t.push(n),n=""):n+=o,i++}return t.push(n),t}var Hl=5,tn=class{fs;cwd;globignorePatterns=[];hasGlobignore=!1;globstar=!1;nullglob=!1;failglob=!1;dotglob=!1;extglob=!1;globskipdots=!0;ops={count:0};maxOps;consumeOperation;constructor(t,n,r,s){this.fs=t,this.cwd=n,typeof s=="boolean"?(this.globstar=s,this.maxOps=1e5):s?(this.globstar=s.globstar??!1,this.nullglob=s.nullglob??!1,this.failglob=s.failglob??!1,this.dotglob=s.dotglob??!1,this.extglob=s.extglob??!1,this.globskipdots=s.globskipdots??!0,this.maxOps=s.maxGlobOperations??1e5,this.consumeOperation=s.consumeOperation):this.maxOps=1e5;let i=r?.get("GLOBIGNORE");i!==void 0&&i!==""&&(this.hasGlobignore=!0,this.globignorePatterns=ql(i))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new C(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations");this.consumeOperation?.()}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(n=>{let r=n.split("/").pop()||n;if((this.hasGlobignore||this.globskipdots)&&(r==="."||r===".."))return!1;if(this.hasGlobignore){for(let s of this.globignorePatterns)if(this.matchGlobignorePattern(n,s))return!1}return!0})}matchGlobignorePattern(t,n){return Gl(n).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,n){let r=t.map((o,a)=>(n?.[a]??!1)||!this.isGlobPattern(o)?null:this.expand(o)),s=await Promise.all(r.map(o=>o||Promise.resolve(null))),i=[];for(let o=0;o<t.length;o++){let a=s[o];a===null?i.push(t[o]):a.length>0?i.push(...a):i.push(t[o])}return i}async expand(t){if(this.globstar){let r=t.split("/"),s=0;for(let i of r)if(i==="**"&&(s++,s>Hl))throw new C(`Glob pattern has too many ** segments (max ${Hl})`,"glob_operations")}let n;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))n=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");n=await this.expandSimple(r)}return this.filterGlobignore(n)}isGlobstarValid(t){let n=t.split("/");for(let r of n)if(r.includes("**")&&r!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let n=t.startsWith("/"),r=t.split("/").filter(c=>c!==""),s=-1;for(let c=0;c<r.length;c++)if(this.hasGlobChars(r[c])){s=c;break}if(s===-1)return[t];let i,o;if(s===0)n?(i="/",o="/"):(i=this.cwd,o="");else{let c=r.slice(0,s);n?(i=`/${c.join("/")}`,o=`/${c.join("/")}`):(i=this.fs.resolvePath(this.cwd,c.join("/")),o=c.join("/"))}let a=r.slice(s);return(await this.expandSegments(i,o,a)).sort()}async expandSegments(t,n,r){if(this.checkOpsLimit(),r.length===0)return[n];let[s,...i]=r,o=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(t),l=[],c=[...a],u=this.dotglob||this.hasGlobignore;if(s.startsWith(".")||this.dotglob){let d=a.some(p=>p.name==="."),h=a.some(p=>p.name==="..");d||c.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),h||c.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of c)if(!(d.name.startsWith(".")&&!s.startsWith(".")&&!u)&&this.matchPattern(d.name,s)){let h=t==="/"?`/${d.name}`:`${t}/${d.name}`,p;n===""?p=d.name:n==="/"?p=`/${d.name}`:p=`${n}/${d.name}`,i.length===0?l.push(Promise.resolve([p])):d.isDirectory&&l.push(this.expandSegments(h,p,i))}let f=await Promise.all(l);for(let d of f)o.push(...d)}else{this.checkOpsLimit();let a=await this.fs.readdir(t),l=[],c=[...a],u=this.dotglob||this.hasGlobignore;(s.startsWith(".")||this.dotglob)&&(a.includes(".")||c.push("."),a.includes("..")||c.push(".."));for(let d of c)if(!(d.startsWith(".")&&!s.startsWith(".")&&!u)&&this.matchPattern(d,s)){let h=t==="/"?`/${d}`:`${t}/${d}`,p;n===""?p=d:n==="/"?p=`/${d}`:p=`${n}/${d}`,i.length===0?l.push(Promise.resolve([p])):l.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(h)).isDirectory)return this.expandSegments(h,p,i)}catch(m){if(m instanceof C)throw m}return[]})())}let f=await Promise.all(l);for(let d of f)o.push(...d)}}catch(a){if(a instanceof C)throw a}return o}async expandRecursive(t){let n=[],r=t.indexOf("**"),s=t.slice(0,r).replace(/\/$/,"")||".",o=t.slice(r+2).replace(/^\//,"");return o.includes("**")&&this.isGlobstarValid(o)?(await this.walkDirectoryMultiGlobstar(s,o,n),[...new Set(n)].sort()):(await this.walkDirectory(s,o,n),n.sort())}async walkDirectoryMultiGlobstar(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let i=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(s):null;if(i){let o=[];for(let c of i){let u=t==="."?c.name:`${t}/${c.name}`;c.isDirectory&&o.push(u)}let a=t==="."?n:`${t}/${n}`,l=await this.expandRecursive(a);r.push(...l);for(let c=0;c<o.length;c+=100){let u=o.slice(c,c+100);await Promise.all(u.map(f=>this.walkDirectoryMultiGlobstar(f,n,r)))}}else{this.checkOpsLimit();let o=await this.fs.readdir(s),a=[];for(let u of o){let f=t==="."?u:`${t}/${u}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&a.push(f)}catch(h){if(h instanceof C)throw h}}let l=t==="."?n:`${t}/${n}`,c=await this.expandRecursive(l);r.push(...c);for(let u=0;u<a.length;u+=100){let f=a.slice(u,u+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,n,r)))}}}catch(i){if(i instanceof C)throw i}}async walkDirectory(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let i=await this.fs.readdirWithFileTypes(s),o=[],a=[];for(let l of i){let c=t==="."?l.name:`${t}/${l.name}`;l.isDirectory?a.push(c):n&&this.matchPattern(l.name,n)&&o.push(c)}r.push(...o);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u,n,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(s),o=[];for(let l=0;l<i.length;l+=100){let c=i.slice(l,l+100),u=await Promise.all(c.map(async f=>{let d=t==="."?f:`${t}/${f}`,h=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let p=await this.fs.stat(h);return{name:f,path:d,isDirectory:p.isDirectory}}catch(p){if(p instanceof C)throw p;return null}}));o.push(...u.filter(f=>f!==null))}for(let l of o)!l.isDirectory&&n&&this.matchPattern(l.name,n)&&r.push(l.path);let a=o.filter(l=>l.isDirectory);for(let l=0;l<a.length;l+=100){let c=a.slice(l,l+100);await Promise.all(c.map(u=>this.walkDirectory(u.path,n,r)))}}}catch(i){if(i instanceof C)throw i}}matchPattern(t,n){return this.patternToRegex(n).test(t)}patternToRegex(t){let n=this.patternToRegexStr(t);return ge(`^${n}$`)}patternToRegexStr(t){let n="",r=!1;for(let s=0;s<t.length;s++){if(t.slice(s,s+13)==="\0QUOTE_START\0"){r=!0,s+=12;continue}if(t.slice(s,s+11)==="\0QUOTE_END\0"){r=!1,s+=10;continue}let i=t[s];if(r){/[.+^${}()|\\*?[\]]/.test(i)?n+=`\\${i}`:n+=i;continue}if(this.extglob&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&s+1<t.length&&t[s+1]==="("){let o=Mi(t,s+1);if(o!==-1){let a=t.slice(s+2,o),l=Bi(a),c=l.map(f=>this.patternToRegexStr(f)),u=c.length>0?c.join("|"):"(?:)";if(i==="@")n+=`(?:${u})`;else if(i==="*")n+=`(?:${u})*`;else if(i==="+")n+=`(?:${u})+`;else if(i==="?")n+=`(?:${u})?`;else if(i==="!")if(o<t.length-1){let d=l.map(p=>this.computePatternLength(p));if(d.every(p=>p!==null)&&d.every(p=>p===d[0])&&d[0]!==null){let p=d[0];if(p===0)n+="(?:.+)";else{let m=[];p>0&&m.push(`.{0,${p-1}}`),m.push(`.{${p+1},}`),m.push(`(?!(?:${u})).{${p}}`),n+=`(?:${m.join("|")})`}}else n+=`(?:(?!(?:${u})).)*?`}else n+=`(?!(?:${u})$).*`;s=o;continue}}if(i==="*")n+=".*";else if(i==="?")n+=".";else if(i==="["){let o=s+1,a="[";o<t.length&&(t[o]==="^"||t[o]==="!")&&(a+="^",o++),o<t.length&&t[o]==="]"&&(a+="\\]",o++);let l=o;for(;l<t.length;){if(t[l]==="\\"&&l+1<t.length){l+=2;continue}if(t[l]==="["&&l+1<t.length&&t[l+1]===":"){let u=t.indexOf(":]",l+2);if(u!==-1){l=u+2;continue}}if(t[l]==="]")break;l++}let c=o;for(;o<t.length&&t[o]!=="]";){if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let u=t.indexOf(":]",o+2);if(u!==-1){let f=t.slice(o+2,u),d=Fi(f);a+=d,o=u+2;continue}}if(t[o]==="\\"&&o+1<t.length){a+=`\\${t[o+1]}`,o+=2;continue}if(t[o]==="-"){let u=o===c,f=o+1===l;u||f?a+="\\-":a+="-"}else a+=t[o];o++}a+="]",n+=a,s=o}else if(i==="\\"&&s+1<t.length){let o=t[s+1];/[.+^${}()|\\*?[\]]/.test(o)?n+=`\\${o}`:n+=o,s++}else/[.+^${}()|]/.test(i)?n+=`\\${i}`:n+=i}return n}computePatternLength(t){let n=0,r=0,s=!1;for(;r<t.length;){if(t.slice(r,r+13)==="\0QUOTE_START\0"){s=!0,r+=13;continue}if(t.slice(r,r+11)==="\0QUOTE_END\0"){s=!1,r+=11;continue}let i=t[r];if(s){n+=1,r++;continue}if((i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&r+1<t.length&&t[r+1]==="("){let o=Mi(t,r+1);if(o!==-1){if(i==="@"){let a=t.slice(r+2,o),c=Bi(a).map(u=>this.computePatternLength(u));if(c.every(u=>u!==null)&&c.every(u=>u===c[0])){n+=c[0],r=o+1;continue}return null}return null}}if(i==="*")return null;if(i==="?"){n+=1,r++;continue}if(i==="["){let o=t.indexOf("]",r+1);if(o!==-1){n+=1,r=o+1;continue}n+=1,r++;continue}if(i==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}};function Wi(e){for(let t=0;t<e.length;t++){if(e[t]==="\\"){t++;continue}if(e[t]==="$"){let n=e[t+1];if(n==="{"||n&&/[a-zA-Z_]/.test(n))return!0}}return!1}function Ph(e){if(!e.operation)return!1;let t=e.operation,n;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(n=t.word?.parts),!n)return!1;for(let r of n)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function Zl(e){if(!e.operation)return!1;let t=e.operation,n;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(n=t.word?.parts),!n||n.length===0)return!1;for(let r of n)if(r.type!=="DoubleQuoted"&&r.type!=="SingleQuoted")return!1;return!0}function gr(e){let t=!1,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1;for(let l of e){if((l.type==="SingleQuoted"||l.type==="DoubleQuoted")&&(t=!0,l.type==="DoubleQuoted"))for(let c of l.parts)c.type==="ParameterExpansion"&&(c.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!c.operation||c.operation.type==="PatternRemoval"||c.operation.type==="PatternReplacement")&&(s=!0),(c.operation?.type==="VarNamePrefix"||c.operation?.type==="ArrayKeys")&&(o=!0),c.operation?.type==="Indirection"&&(a=!0));l.type==="CommandSubstitution"&&(n=!0),l.type==="ParameterExpansion"&&(i=!0,(l.parameter==="@"||l.parameter==="*")&&(r=!0),Ph(l)&&(t=!0),(l.operation?.type==="VarNamePrefix"||l.operation?.type==="ArrayKeys")&&(o=!0),l.operation?.type==="Indirection"&&(a=!0)),l.type==="Glob"&&Wi(l.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i,hasVarNamePrefixExpansion:o,hasIndirection:a}}var $h=`
|
|
97
|
+
`;function $n(e,t){if(e>=t)throw new C(`array element limit exceeded (${t})`,"array_elements")}function Vi(e,t,n,r,s){$n(e.length,s),$n(t.length,s),e.push(n),t.push(r)}function ve(e){return e.get("IFS")??$h}function Oe(e){return e.get("IFS")===""}function os(e){let t=ve(e);if(t==="")return!0;for(let n of t)if(n!==" "&&n!==" "&&n!==`
|
|
98
|
+
`)return!1;return!0}function Ql(e){let t=!1,n=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?n.push(`\\${r}`):r===" "?n.push("\\t"):r===`
|
|
99
|
+
`?n.push("\\n"):n.push(r);return t&&n.push("\\-"),n.join("")}function X(e){let t=e.get("IFS");if(t===void 0)return" ";let n=t.codePointAt(0);return n===void 0?"":String.fromCodePoint(n)}var Ch=`
|
|
100
|
+
`;function Nh(e){return Ch.includes(e)}function zi(e){let t=new Set,n=new Set;for(let r of e)Nh(r)?t.add(r):n.add(r);return{whitespace:t,nonWhitespace:n}}function Ui(e,t,n,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:($n(0,n),{words:[e],wordStarts:[0]});let{whitespace:i,nonWhitespace:o}=zi(t),a=[],l=[],c=0;for(;c<e.length&&i.has(e[c]);)c++;if(c>=e.length)return{words:[],wordStarts:[]};if(o.has(e[c]))for(Vi(a,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&!(r!==void 0&&a.length>=r);){let u=c;for(;c<e.length;){let f=e[c];if(!s&&f==="\\"){c++,c<e.length&&c++;continue}if(i.has(f)||o.has(f))break;c++}if(Vi(a,l,e.substring(u,c),u,n),c>=e.length)break;for(;c<e.length&&i.has(e[c]);)c++;if(c<e.length&&o.has(e[c])){for(c++;c<e.length&&i.has(e[c]);)c++;for(;c<e.length&&o.has(e[c])&&!(r!==void 0&&a.length>=r);)for(Vi(a,l,"",c,n),c++;c<e.length&&i.has(e[c]);)c++}}return{words:a,wordStarts:l}}function as(e,t,n){if(t==="")return e&&$n(0,n),{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=zi(t),i=[],o=0,a=!1,l=!1,c=o;for(;o<e.length&&r.has(e[o]);)o++;if(o>c&&(a=!0),o>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[o]))for($n(i.length,n),i.push(""),o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length;){let u=o;for(;o<e.length;){let d=e[o];if(r.has(d)||s.has(d))break;o++}if($n(i.length,n),i.push(e.substring(u,o)),o>=e.length){l=!1;break}let f=o;for(;o<e.length&&r.has(e[o]);)o++;if(o<e.length&&s.has(e[o])){for(o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length&&s.has(e[o]);)for($n(i.length,n),i.push(""),o++;o<e.length&&r.has(e[o]);)o++}o>=e.length&&o>f&&(l=!0)}return{words:i,hadLeadingDelimiter:a,hadTrailingDelimiter:l}}function de(e,t,n){return as(e,t,n).words}function Rh(e,t){for(let n of e)if(t.has(n))return!0;return!1}function Kl(e,t,n){if(t==="")return e;let{whitespace:r,nonWhitespace:s}=zi(t),i=e.length;for(;i>0&&r.has(e[i-1]);){if(!n&&i>=2){let a=0,l=i-2;for(;l>=0&&e[l]==="\\";)a++,l--;if(a%2===1)break}i--}let o=e.substring(0,i);if(o.length>=1&&s.has(o[o.length-1])){if(!n&&o.length>=2){let l=0,c=o.length-2;for(;c>=0&&o[c]==="\\";)l++,c--;if(l%2===1)return o}let a=o.substring(0,o.length-1);if(!Rh(a,s))return a}return o}function ue(e,t){return e.state.namerefs?.has(t)??!1}function Bt(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function Xl(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Yl(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function Jl(e,t){return e.state.invalidNamerefs?.has(t)??!1}function ji(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function ls(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let s=n[1],i=Ne(e,s),o=e.state.associativeArrays?.has(s)??!1;return i||o}return Ne(e,t)?!0:e.state.env.has(t)}function Be(e,t,n=100){if(!ue(e,t)||Jl(e,t))return t;let r=new Set,s=t;for(;n-- >0;){if(r.has(s))return;if(r.add(s),!ue(e,s))return s;let i=e.state.env.get(s);if(i===void 0||i===""||!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(i))return s;s=i}}function Cn(e,t){if(ue(e,t))return e.state.env.get(t)}function cs(e,t,n,r=100){if(!ue(e,t)||Jl(e,t))return t;let s=new Set,i=t;for(;r-- >0;){if(s.has(i))return;if(s.add(i),!ue(e,i))return i;let o=e.state.env.get(i);if(o===void 0||o==="")return n!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)&&ls(e,n)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(o))return i;i=o}}function ec(e,t){let n=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(r,s)=>e.state.env.get(s)??"");return n=n.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(r,s)=>e.state.env.get(s)??""),n}function K(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((i,o)=>[o,i]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((i,o)=>[o,String(i)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((i,o)=>[o,i]):e.state.associativeArrays?.has(t)?xt(e,t).map(i=>[i,ae(e,t,i)??""]):Ae(e,t).map(s=>[s,ae(e,t,s)??""])}function wt(e,t){return t==="FUNCNAME"?(e.state.funcNameStack?.length??0)>0:t==="BASH_LINENO"?(e.state.callLineStack?.length??0)>0:t==="BASH_SOURCE"?(e.state.sourceStack?.length??0)>0:e.state.associativeArrays?.has(t)?Ne(e,t):Ne(e,t)}async function ie(e,t,n=!0){switch(t){case"?":return String(e.state.lastExitCode);case"$":return String(e.state.virtualPid);case"#":return e.state.env.get("#")||"0";case"@":return e.state.env.get("@")||"";case"_":return e.state.lastArg;case"-":{let i="";return i+="h",e.state.options.errexit&&(i+="e"),e.state.options.noglob&&(i+="f"),e.state.options.nounset&&(i+="u"),e.state.options.verbose&&(i+="v"),e.state.options.xtrace&&(i+="x"),i+="B",e.state.options.noclobber&&(i+="C"),i+="s",i}case"*":{let i=Number.parseInt(e.state.env.get("#")||"0",10);if(i===0)return"";let o=[];for(let a=1;a<=i;a++)o.push(e.state.env.get(String(a))||"");return o.join(X(e.state.env))}case"0":return e.state.env.get("0")||"bash";case"PWD":return e.state.env.get("PWD")??"";case"OLDPWD":return e.state.env.get("OLDPWD")??"";case"PPID":return String(e.state.virtualPpid);case"UID":return String(e.state.virtualUid);case"EUID":return String(e.state.virtualUid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-e.state.startTime)/1e3));case"BASH_VERSION":return Za;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let i=e.state.funcNameStack?.[0];if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new ze("FUNCNAME");return""}case"BASH_LINENO":{let i=e.state.callLineStack?.[0];if(i!==void 0)return String(i);if(n&&e.state.options.nounset)throw new ze("BASH_LINENO");return""}case"BASH_SOURCE":{let i=e.state.sourceStack?.[0];if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new ze("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new Xe(`\${${t}}`);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let i=r[1],o=r[2];if(ue(e,i)){let u=Be(e,i);if(u&&u!==i){if(u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";i=u}}if(o==="@"||o==="*"){let u=K(e,i);if(u.length>0){let d=o==="*"?X(e.state.env):" ",h=V(d)*(u.length-1);for(let[,p]of u)if(h+=V(p),h>e.limits.maxStringLength)throw new C(`array expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return u.map(([,p])=>p).join(d)}let f=e.state.env.get(i);return f!==void 0?f:""}if(i==="FUNCNAME"){let u=Number.parseInt(o,10);return!Number.isNaN(u)&&u>=0?e.state.funcNameStack?.[u]??"":""}if(i==="BASH_LINENO"){let u=Number.parseInt(o,10);if(!Number.isNaN(u)&&u>=0){let f=e.state.callLineStack?.[u];return f!==void 0?String(f):""}return""}if(i==="BASH_SOURCE"){let u=Number.parseInt(o,10);return!Number.isNaN(u)&&u>=0?e.state.sourceStack?.[u]??"":""}if(e.state.associativeArrays?.has(i)){let u=Zr(o);u=ec(e,u);let f=ae(e,i,u);if(f===void 0&&n&&e.state.options.nounset)throw new ze(`${i}[${o}]`);return f||""}let l;if(/^-?\d+$/.test(o))l=Number.parseInt(o,10);else try{let u=new Q,f=re(u,o);l=await J(e,f.expression)}catch{let u=e.state.env.get(o);l=u?Number.parseInt(u,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let u=K(e,i),f=e.state.currentLine;if(u.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${i}: bad array subscript
|
|
101
101
|
`,"";let h=Math.max(...u.map(([m])=>typeof m=="number"?m:0))+1+l;return h<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${i}: bad array subscript
|
|
102
|
-
`,""):ae(e,i,h)||""}let c=ae(e,i,l);if(c!==void 0)return c;if(l===0){let u=e.state.env.get(i);if(u!==void 0)return u}if(n&&e.state.options.nounset)throw new ze(`${i}[${l}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let i=e.state.env.get(t);if(i===void 0&&n&&e.state.options.nounset)throw new ze(t);return i||""}if(ue(e,t)){let i=Be(e,t);if(i===void 0)return"";if(i!==t)return await ie(e,i,n);let o=e.state.env.get(t);if((o===void 0||o==="")&&n&&e.state.options.nounset)throw new ze(t);return o||""}let s=e.state.env.get(t);if(s!==void 0)return e.state.tempEnvBindings?.some(i=>i.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),s;if(Et(e,t)){let i=ae(e,t,0);if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new ze(t);return""}if(n&&e.state.options.nounset)throw new ze(t);return""}async function $t(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let s=r[1],i=r[2];if(ue(e,s)){let l=Be(e,s);if(l&&l!==s){if(l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;s=l}}if(i==="@"||i==="*")return Q(e,s).length>0?!0:e.state.env.has(s);if(e.state.associativeArrays?.has(s)){let l=Kl(e,Gr(i));return Yt(e,s,l)}let a;if(/^-?\d+$/.test(i))a=Number.parseInt(i,10);else try{let l=new Z,c=re(l,i);a=await J(e,c.expression)}catch{let l=e.state.env.get(i);a=l?Number.parseInt(l,10):0,Number.isNaN(a)&&(a=0)}if(a<0){let l=Q(e,s);if(l.length===0)return!1;let u=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+a;return u<0?!1:Yt(e,s,u)}return Yt(e,s,a)}if(ue(e,t)){let s=Be(e,t);return s===void 0||s===t?e.state.env.has(t):$t(e,s)}return e.state.env.has(t)?!0:Et(e,t)?Yt(e,t,0):!1}async function Xl(e,t){let n="",r=0;for(;r<t.length;){if(t[r]==="$"){if(t[r+1]==="{"){let s=1,i=r+2;for(;i<t.length&&s>0;)t[i]==="{"?s++:t[i]==="}"&&s--,i++;n+=t.slice(r,i),r=i;continue}if(t[r+1]==="("){let s=1,i=r+2;for(;i<t.length&&s>0;)t[i]==="("?s++:t[i]===")"&&s--,i++;n+=t.slice(r,i),r=i;continue}if(/[a-zA-Z_]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await ie(e,i);n+=o,r=s;continue}if(/[0-9]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[0-9]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await ie(e,i);n+=o,r=s;continue}if(/[*@#?\-!$]/.test(t[r+1]||"")){let s=t[r+1],i=await ie(e,s);n+=i,r+=2;continue}}if(t[r]==='"'){for(n+='"',r++;r<t.length&&t[r]!=='"';)if(t[r]==="$"&&/[a-zA-Z_]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await ie(e,i);n+=o,r=s}else t[r]==="\\"?(n+=t[r],r++,r<t.length&&(n+=t[r],r++)):(n+=t[r],r++);r<t.length&&(n+='"',r++);continue}n+=t[r],r++}return n}async function Ui(e,t){let n=t,r=t.startsWith('"')&&t.endsWith('"'),s=t.startsWith("'")&&t.endsWith("'");if((r||s)&&(n=t.slice(1,-1)),s)return n;let i="",o=0;for(;o<n.length;)if(n[o]==="$")if(n[o+1]==="("){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="("&&n[l-1]==="$"||n[l]==="("?a++:n[l]===")"&&a--,l++;let c=n.slice(o+2,l-1);if(e.execFn){let u=await e.execFn(c,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}o=l}else if(n[o+1]==="{"){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="{"?a++:n[l]==="}"&&a--,l++;let c=n.slice(o+2,l-1),u=await ie(e,c);i+=u,o=l}else if(/[a-zA-Z_]/.test(n[o+1]||"")){let a=o+1;for(;a<n.length&&/[a-zA-Z0-9_]/.test(n[a]);)a++;let l=n.slice(o+1,a),c=await ie(e,l);i+=c,o=a}else i+=n[o],o++;else if(n[o]==="`"){let a=o+1;for(;a<n.length&&n[a]!=="`";)a++;let l=n.slice(o+1,a);if(e.execFn){let c=await e.execFn(l,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}o=a+1}else i+=n[o],o++;return i}var gr=1e4,ji={maxResults:gr,maxStringBytes:10*1024*1024};function os(e,t,n,r){if(e.length>=n.maxResults)return!1;let s=M(t);if(s>n.maxStringBytes-r.value)throw new $(`brace expansion string limit exceeded (${n.maxStringBytes} bytes)`,"string_length");return e.push(t),r.value+=s,!0}function xh(e,t,n,r,s,i=ji){let o=n??1;o===0&&(o=1);let a=Math.abs(o),l=[],c=0;if(r?.match(/^-?0\d/)&&(c=Math.max(c,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(c=Math.max(c,s.replace(/^-/,"").length)),c>i.maxStringBytes)throw new $(`brace expansion padding limit exceeded (${i.maxStringBytes} bytes)`,"string_length");let u={value:0},f=d=>{if(c>0){let h=d<0,p=String(Math.abs(d)).padStart(c,"0");return h?`-${p}`:p}return String(d)};if(e<=t)for(let d=e,h=0;d<=t&&h<gr&&os(l,f(d),i,u);d+=a,h++);else for(let d=e,h=0;d>=t&&h<gr&&os(l,f(d),i,u);d-=a,h++);return l}function Ph(e,t,n,r=ji){let s=n??1;s===0&&(s=1);let i=e.charCodeAt(0),o=t.charCodeAt(0),a=Math.abs(s),l=e>="A"&&e<="Z",c=e>="a"&&e<="z",u=t>="A"&&t<="Z",f=t>="a"&&t<="z";if(l&&f||c&&u){let p=n!==void 0?`..${n}`:"";throw new Lr(`{${e}..${t}${p}}: invalid sequence`)}let d=[],h={value:0};if(i<=o)for(let p=i,m=0;p<=o&&m<gr&&os(d,String.fromCharCode(p),r,h);p+=a,m++);else for(let p=i,m=0;p>=o&&m<gr&&os(d,String.fromCharCode(p),r,h);p-=a,m++);return d}function qi(e,t,n,r,s,i=ji){let o=n!==void 0?`..${n}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:xh(e,t,n,r,s,i),literal:`{${e}..${t}${o}}`}:typeof e=="string"&&typeof t=="string"?{expanded:Ph(e,t,n,i),literal:`{${e}..${t}${o}}`}:{expanded:null,literal:`{${e}..${t}${o}}`}}function Yl(e){if(e.statements.length!==1)return null;let t=e.statements[0];if(t.operators.length!==0||t.pipelines.length!==1)return null;let n=t.pipelines[0];if(n.negated||n.commands.length!==1)return null;let r=n.commands[0];if(r.type!=="SimpleCommand")return null;let s=r;if(s.name!==null||s.args.length!==0||s.assignments.length!==0||s.redirections.length!==1)return null;let i=s.redirections[0];return i.operator!=="<"||i.target.type!=="Word"?null:{target:i.target}}function Ct(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function Gi(e){let t="",n=0;for(;n<e.length;)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);return t}function et(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function Vn(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function ce(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function oe(e,t,n=!1){let r="",s=0;for(;s<e.length;){let i=e[s];if(n&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&s+1<e.length&&e[s+1]==="("){let o=$h(e,s+1);if(o!==-1){let a=e.slice(s+2,o),c=Ch(a).map(f=>oe(f,t,n)),u=c.length>0?c.join("|"):"(?:)";i==="@"?r+=`(?:${u})`:i==="*"?r+=`(?:${u})*`:i==="+"?r+=`(?:${u})+`:i==="?"?r+=`(?:${u})?`:i==="!"&&(r+=`(?!(?:${u})$).*`),s=o+1;continue}}if(i==="\\")if(s+1<e.length){let o=e[s+1];/[\\^$.|+(){}[\]*?]/.test(o)?r+=`\\${o}`:r+=o,s+=2}else r+="\\\\",s++;else if(i==="*")r+=t?".*":".*?",s++;else if(i==="?")r+=".",s++;else if(i==="["){let o=Nh(e,s);if(o===-1)r+="\\[",s++;else{let a=e.slice(s+1,o);r+=Rh(a),s=o+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,s++):(r+=i,s++)}return r}function $h(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function Ch(e){let t=[],n="",r=0,s=0;for(;s<e.length;){let i=e[s];if(i==="\\"){n+=i,s+1<e.length?(n+=e[s+1],s+=2):s++;continue}i==="("?(r++,n+=i):i===")"?(r--,n+=i):i==="|"&&r===0?(t.push(n),n=""):n+=i,s++}return t.push(n),t}function Nh(e,t){let n=t+1;for(n<e.length&&e[n]==="^"&&n++,n<e.length&&e[n]==="]"&&n++;n<e.length;){if(e[n]==="\\"&&n+1<e.length){n+=2;continue}if(e[n]==="]")return n;if(e[n]==="'"){let r=e.indexOf("'",n+1);if(r!==-1){n=r+1;continue}}if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let r=e.indexOf(":]",n+2);if(r!==-1){n=r+2;continue}}n++}return-1}function Rh(e){let t="[",n=0;for((e[0]==="^"||e[0]==="!")&&(t+="^",n++);n<e.length;){if(e[n]==="'"){let s=e.indexOf("'",n+1);if(s!==-1){let i=e.slice(n+1,s);for(let o of i)o==="\\"?t+="\\\\":o==="]"?t+="\\]":o==="^"&&t==="["?t+="\\^":t+=o;n=s+1;continue}}if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let s=e.indexOf(":]",n+2);if(s!==-1){let i=e.slice(n+2,s);t+=Dh(i),n=s+2;continue}}let r=e[n];r==="\\"?n+1<e.length?(t+=`\\${e[n+1]}`,n+=2):(t+="\\\\",n++):r==="-"&&n>0&&n<e.length-1?(t+="-",n++):r==="^"&&n===0?(t+="^",n++):(r==="]"&&n===0?t+="\\]":t+=r,n++)}return t+="]",t}var Oh=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]);function Dh(e){return Oh.get(e)??""}async function nn(e,t,n,r,s){let i="",o=e.state.shoptOptions.extglob;for(let a of t.parts)if(a.type==="Glob")i+=oe(a.pattern,n,o);else if(a.type==="Literal")i+=oe(a.value,n,o);else if(a.type==="SingleQuoted"||a.type==="Escaped")i+=ce(a.value);else if(a.type==="DoubleQuoted"){let l=await r(e,a.parts);i+=ce(l)}else if(a.type==="ParameterExpansion"){let l=await s(e,a);i+=oe(l,n,o)}else{let l=await s(e,a);i+=ce(l)}return i}function bt(e,t,n,r,s){if(r==="prefix")return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),ge(`^${n}`,"s").replace(t,"");let i=ge(`${n}$`,"s");if(s)return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),i.replace(t,"");e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal");let o=ge(`^(?:.*)(${n})$`,"s").exec(t);if(!o)return t;let a=o[1]??"";return t.slice(0,t.length-a.length)}function zn(e,t){let n=new Set;for(let r of e.state.env.keys())r.startsWith(t)&&n.add(r);for(let r of e.state.arrays?.keys()??[])r.startsWith(t)&&n.add(r);return[...n].sort()}function as(e,t,n,r,s){let i=new Tn(e.limits.maxStringLength,"pattern replacement",()=>new $(`pattern replacement: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length"));n.lastIndex=0;let o=0,a=n.exec(t);for(;a!==null&&(e.executionScope.consumeLimited("pattern_operations",1,e.limits.maxGlobOperations,"pattern replacement"),!(s&&a[0].length===0&&a.index===t.length||(i.append(t.slice(o,a.index)),i.append(r),o=a.index+a[0].length,!s)));)a[0].length===0&&(o++,n.lastIndex<=a.index&&(n.lastIndex=a.index+1)),a=n.exec(t);return i.append(t.slice(o)),n.lastIndex=0,i.build()}function Jl(e){let t=[],n=0;return{append(r){let s=M(r);if(s>e-n)throw new $(`prompt expansion exceeds string length limit (${e} bytes)`,"string_length");r&&t.push(r),n+=s},build:()=>t.join("")}}function Ih(e,t,n){let r=(o,a=2)=>String(o).padStart(a,"0");if(e===""){let o=r(t.getHours()),a=r(t.getMinutes()),l=r(t.getSeconds());return`${o}:${a}:${l}`}let s=Jl(n),i=0;for(;i<e.length;)if(e[i]==="%"){if(i+1>=e.length){s.append("%"),i++;continue}let o=e[i+1];switch(o){case"H":s.append(r(t.getHours()));break;case"M":s.append(r(t.getMinutes()));break;case"S":s.append(r(t.getSeconds()));break;case"d":s.append(r(t.getDate()));break;case"m":s.append(r(t.getMonth()+1));break;case"Y":s.append(String(t.getFullYear()));break;case"y":s.append(r(t.getFullYear()%100));break;case"I":{let a=t.getHours()%12;a===0&&(a=12),s.append(r(a));break}case"p":s.append(t.getHours()<12?"AM":"PM");break;case"P":s.append(t.getHours()<12?"am":"pm");break;case"%":s.append("%");break;case"a":{let a=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];s.append(a[t.getDay()]);break}case"b":{let a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];s.append(a[t.getMonth()]);break}default:s.append(`%${o}`)}i+=2}else s.append(e[i]),i++;return s.build()}function wr(e,t){let n=Jl(e.limits.maxStringLength),r=0,s=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",i=e.state.env.get("HOSTNAME")||"localhost",o=i.split(".")[0],a=e.state.env.get("PWD")||"/",l=e.state.env.get("HOME")||"/",c=a.startsWith(l)?`~${a.slice(l.length)}`:a,u=a.split("/").pop()||a,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],p=e.state.env.get("__COMMAND_NUMBER")||"1";for(;r<t.length;){let m=t[r];if(m==="\\"){if(r+1>=t.length){n.append("\\"),r++;continue}let E=t[r+1];if(E>="0"&&E<="7"){let S="",y=r+1;for(;y<t.length&&y<r+4&&t[y]>="0"&&t[y]<="7";)S+=t[y],y++;let g=Number.parseInt(S,8)%256;n.append(String.fromCharCode(g)),r=y;continue}switch(E){case"\\":n.append("\\"),r+=2;break;case"a":n.append("\x07"),r+=2;break;case"e":n.append("\x1B"),r+=2;break;case"n":n.append(`
|
|
103
|
-
`),r+=2;break;case"r":n.append("\r"),r+=2;break;case"$":n.append("$"),r+=2;break;case"[":case"]":r+=2;break;case"u":n.append(s),r+=2;break;case"h":n.append(o),r+=2;break;case"H":n.append(i),r+=2;break;case"w":n.append(c),r+=2;break;case"W":n.append(u),r+=2;break;case"d":{let
|
|
102
|
+
`,""):ae(e,i,h)||""}let c=ae(e,i,l);if(c!==void 0)return c;if(l===0){let u=e.state.env.get(i);if(u!==void 0)return u}if(n&&e.state.options.nounset)throw new ze(`${i}[${l}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let i=e.state.env.get(t);if(i===void 0&&n&&e.state.options.nounset)throw new ze(t);return i||""}if(ue(e,t)){let i=Be(e,t);if(i===void 0)return"";if(i!==t)return await ie(e,i,n);let o=e.state.env.get(t);if((o===void 0||o==="")&&n&&e.state.options.nounset)throw new ze(t);return o||""}let s=e.state.env.get(t);if(s!==void 0)return e.state.tempEnvBindings?.some(i=>i.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),s;if(wt(e,t)){let i=ae(e,t,0);if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new ze(t);return""}if(n&&e.state.options.nounset)throw new ze(t);return""}async function $t(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let s=r[1],i=r[2];if(ue(e,s)){let l=Be(e,s);if(l&&l!==s){if(l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;s=l}}if(i==="@"||i==="*")return K(e,s).length>0?!0:e.state.env.has(s);if(e.state.associativeArrays?.has(s)){let l=ec(e,Zr(i));return Yt(e,s,l)}let a;if(/^-?\d+$/.test(i))a=Number.parseInt(i,10);else try{let l=new Q,c=re(l,i);a=await J(e,c.expression)}catch{let l=e.state.env.get(i);a=l?Number.parseInt(l,10):0,Number.isNaN(a)&&(a=0)}if(a<0){let l=K(e,s);if(l.length===0)return!1;let u=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+a;return u<0?!1:Yt(e,s,u)}return Yt(e,s,a)}if(ue(e,t)){let s=Be(e,t);return s===void 0||s===t?e.state.env.has(t):$t(e,s)}return e.state.env.has(t)?!0:wt(e,t)?Yt(e,t,0):!1}async function tc(e,t){let n="",r=0;for(;r<t.length;){if(t[r]==="$"){if(t[r+1]==="{"){let s=1,i=r+2;for(;i<t.length&&s>0;)t[i]==="{"?s++:t[i]==="}"&&s--,i++;n+=t.slice(r,i),r=i;continue}if(t[r+1]==="("){let s=1,i=r+2;for(;i<t.length&&s>0;)t[i]==="("?s++:t[i]===")"&&s--,i++;n+=t.slice(r,i),r=i;continue}if(/[a-zA-Z_]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await ie(e,i);n+=o,r=s;continue}if(/[0-9]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[0-9]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await ie(e,i);n+=o,r=s;continue}if(/[*@#?\-!$]/.test(t[r+1]||"")){let s=t[r+1],i=await ie(e,s);n+=i,r+=2;continue}}if(t[r]==='"'){for(n+='"',r++;r<t.length&&t[r]!=='"';)if(t[r]==="$"&&/[a-zA-Z_]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await ie(e,i);n+=o,r=s}else t[r]==="\\"?(n+=t[r],r++,r<t.length&&(n+=t[r],r++)):(n+=t[r],r++);r<t.length&&(n+='"',r++);continue}n+=t[r],r++}return n}async function qi(e,t){let n=t,r=t.startsWith('"')&&t.endsWith('"'),s=t.startsWith("'")&&t.endsWith("'");if((r||s)&&(n=t.slice(1,-1)),s)return n;let i="",o=0;for(;o<n.length;)if(n[o]==="$")if(n[o+1]==="("){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="("&&n[l-1]==="$"||n[l]==="("?a++:n[l]===")"&&a--,l++;let c=n.slice(o+2,l-1);if(e.execFn){let u=await e.execFn(c,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}o=l}else if(n[o+1]==="{"){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="{"?a++:n[l]==="}"&&a--,l++;let c=n.slice(o+2,l-1),u=await ie(e,c);i+=u,o=l}else if(/[a-zA-Z_]/.test(n[o+1]||"")){let a=o+1;for(;a<n.length&&/[a-zA-Z0-9_]/.test(n[a]);)a++;let l=n.slice(o+1,a),c=await ie(e,l);i+=c,o=a}else i+=n[o],o++;else if(n[o]==="`"){let a=o+1;for(;a<n.length&&n[a]!=="`";)a++;let l=n.slice(o+1,a);if(e.execFn){let c=await e.execFn(l,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}o=a+1}else i+=n[o],o++;return i}var wr=1e4,Gi={maxResults:wr,maxStringBytes:10*1024*1024};function us(e,t,n,r){if(e.length>=n.maxResults)return!1;let s=V(t);if(s>n.maxStringBytes-r.value)throw new C(`brace expansion string limit exceeded (${n.maxStringBytes} bytes)`,"string_length");return e.push(t),r.value+=s,!0}function Oh(e,t,n,r,s,i=Gi){let o=n??1;o===0&&(o=1);let a=Math.abs(o),l=[],c=0;if(r?.match(/^-?0\d/)&&(c=Math.max(c,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(c=Math.max(c,s.replace(/^-/,"").length)),c>i.maxStringBytes)throw new C(`brace expansion padding limit exceeded (${i.maxStringBytes} bytes)`,"string_length");let u={value:0},f=d=>{if(c>0){let h=d<0,p=String(Math.abs(d)).padStart(c,"0");return h?`-${p}`:p}return String(d)};if(e<=t)for(let d=e,h=0;d<=t&&h<wr&&us(l,f(d),i,u);d+=a,h++);else for(let d=e,h=0;d>=t&&h<wr&&us(l,f(d),i,u);d-=a,h++);return l}function Dh(e,t,n,r=Gi){let s=n??1;s===0&&(s=1);let i=e.charCodeAt(0),o=t.charCodeAt(0),a=Math.abs(s),l=e>="A"&&e<="Z",c=e>="a"&&e<="z",u=t>="A"&&t<="Z",f=t>="a"&&t<="z";if(l&&f||c&&u){let p=n!==void 0?`..${n}`:"";throw new Mr(`{${e}..${t}${p}}: invalid sequence`)}let d=[],h={value:0};if(i<=o)for(let p=i,m=0;p<=o&&m<wr&&us(d,String.fromCharCode(p),r,h);p+=a,m++);else for(let p=i,m=0;p>=o&&m<wr&&us(d,String.fromCharCode(p),r,h);p-=a,m++);return d}function Hi(e,t,n,r,s,i=Gi){let o=n!==void 0?`..${n}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:Oh(e,t,n,r,s,i),literal:`{${e}..${t}${o}}`}:typeof e=="string"&&typeof t=="string"?{expanded:Dh(e,t,n,i),literal:`{${e}..${t}${o}}`}:{expanded:null,literal:`{${e}..${t}${o}}`}}function nc(e){if(e.statements.length!==1)return null;let t=e.statements[0];if(t.operators.length!==0||t.pipelines.length!==1)return null;let n=t.pipelines[0];if(n.negated||n.commands.length!==1)return null;let r=n.commands[0];if(r.type!=="SimpleCommand")return null;let s=r;if(s.name!==null||s.args.length!==0||s.assignments.length!==0||s.redirections.length!==1)return null;let i=s.redirections[0];return i.operator!=="<"||i.target.type!=="Word"?null:{target:i.target}}function Ct(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function Zi(e){let t="",n=0;for(;n<e.length;)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);return t}function et(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function zn(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function ce(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function oe(e,t,n=!1){let r="",s=0;for(;s<e.length;){let i=e[s];if(n&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&s+1<e.length&&e[s+1]==="("){let o=Ih(e,s+1);if(o!==-1){let a=e.slice(s+2,o),c=_h(a).map(f=>oe(f,t,n)),u=c.length>0?c.join("|"):"(?:)";i==="@"?r+=`(?:${u})`:i==="*"?r+=`(?:${u})*`:i==="+"?r+=`(?:${u})+`:i==="?"?r+=`(?:${u})?`:i==="!"&&(r+=`(?!(?:${u})$).*`),s=o+1;continue}}if(i==="\\")if(s+1<e.length){let o=e[s+1];/[\\^$.|+(){}[\]*?]/.test(o)?r+=`\\${o}`:r+=o,s+=2}else r+="\\\\",s++;else if(i==="*")r+=t?".*":".*?",s++;else if(i==="?")r+=".",s++;else if(i==="["){let o=Th(e,s);if(o===-1)r+="\\[",s++;else{let a=e.slice(s+1,o);r+=Lh(a),s=o+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,s++):(r+=i,s++)}return r}function Ih(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function _h(e){let t=[],n="",r=0,s=0;for(;s<e.length;){let i=e[s];if(i==="\\"){n+=i,s+1<e.length?(n+=e[s+1],s+=2):s++;continue}i==="("?(r++,n+=i):i===")"?(r--,n+=i):i==="|"&&r===0?(t.push(n),n=""):n+=i,s++}return t.push(n),t}function Th(e,t){let n=t+1;for(n<e.length&&e[n]==="^"&&n++,n<e.length&&e[n]==="]"&&n++;n<e.length;){if(e[n]==="\\"&&n+1<e.length){n+=2;continue}if(e[n]==="]")return n;if(e[n]==="'"){let r=e.indexOf("'",n+1);if(r!==-1){n=r+1;continue}}if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let r=e.indexOf(":]",n+2);if(r!==-1){n=r+2;continue}}n++}return-1}function Lh(e){let t="[",n=0;for((e[0]==="^"||e[0]==="!")&&(t+="^",n++);n<e.length;){if(e[n]==="'"){let s=e.indexOf("'",n+1);if(s!==-1){let i=e.slice(n+1,s);for(let o of i)o==="\\"?t+="\\\\":o==="]"?t+="\\]":o==="^"&&t==="["?t+="\\^":t+=o;n=s+1;continue}}if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let s=e.indexOf(":]",n+2);if(s!==-1){let i=e.slice(n+2,s);t+=Mh(i),n=s+2;continue}}let r=e[n];r==="\\"?n+1<e.length?(t+=`\\${e[n+1]}`,n+=2):(t+="\\\\",n++):r==="-"&&n>0&&n<e.length-1?(t+="-",n++):r==="^"&&n===0?(t+="^",n++):(r==="]"&&n===0?t+="\\]":t+=r,n++)}return t+="]",t}var Fh=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]);function Mh(e){return Fh.get(e)??""}async function nn(e,t,n,r,s){let i="",o=e.state.shoptOptions.extglob;for(let a of t.parts)if(a.type==="Glob")i+=oe(a.pattern,n,o);else if(a.type==="Literal")i+=oe(a.value,n,o);else if(a.type==="SingleQuoted"||a.type==="Escaped")i+=ce(a.value);else if(a.type==="DoubleQuoted"){let l=await r(e,a.parts);i+=ce(l)}else if(a.type==="ParameterExpansion"){let l=await s(e,a);i+=oe(l,n,o)}else{let l=await s(e,a);i+=ce(l)}return i}function Et(e,t,n,r,s){if(r==="prefix")return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),ge(`^${n}`,"s").replace(t,"");let i=ge(`${n}$`,"s");if(s)return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),i.replace(t,"");e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal");let o=ge(`^(?:.*)(${n})$`,"s").exec(t);if(!o)return t;let a=o[1]??"";return t.slice(0,t.length-a.length)}function Un(e,t){let n=new Set;for(let r of e.state.env.keys())r.startsWith(t)&&n.add(r);for(let r of e.state.arrays?.keys()??[])r.startsWith(t)&&n.add(r);return[...n].sort()}function fs(e,t,n,r,s){let i=new Ln(e.limits.maxStringLength,"pattern replacement",()=>new C(`pattern replacement: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length"));n.lastIndex=0;let o=0,a=n.exec(t);for(;a!==null&&(e.executionScope.consumeLimited("pattern_operations",1,e.limits.maxGlobOperations,"pattern replacement"),!(s&&a[0].length===0&&a.index===t.length||(i.append(t.slice(o,a.index)),i.append(r),o=a.index+a[0].length,!s)));)a[0].length===0&&(o++,n.lastIndex<=a.index&&(n.lastIndex=a.index+1)),a=n.exec(t);return i.append(t.slice(o)),n.lastIndex=0,i.build()}function rc(e){let t=[],n=0;return{append(r){let s=V(r);if(s>e-n)throw new C(`prompt expansion exceeds string length limit (${e} bytes)`,"string_length");r&&t.push(r),n+=s},build:()=>t.join("")}}function Bh(e,t,n){let r=(o,a=2)=>String(o).padStart(a,"0");if(e===""){let o=r(t.getHours()),a=r(t.getMinutes()),l=r(t.getSeconds());return`${o}:${a}:${l}`}let s=rc(n),i=0;for(;i<e.length;)if(e[i]==="%"){if(i+1>=e.length){s.append("%"),i++;continue}let o=e[i+1];switch(o){case"H":s.append(r(t.getHours()));break;case"M":s.append(r(t.getMinutes()));break;case"S":s.append(r(t.getSeconds()));break;case"d":s.append(r(t.getDate()));break;case"m":s.append(r(t.getMonth()+1));break;case"Y":s.append(String(t.getFullYear()));break;case"y":s.append(r(t.getFullYear()%100));break;case"I":{let a=t.getHours()%12;a===0&&(a=12),s.append(r(a));break}case"p":s.append(t.getHours()<12?"AM":"PM");break;case"P":s.append(t.getHours()<12?"am":"pm");break;case"%":s.append("%");break;case"a":{let a=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];s.append(a[t.getDay()]);break}case"b":{let a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];s.append(a[t.getMonth()]);break}default:s.append(`%${o}`)}i+=2}else s.append(e[i]),i++;return s.build()}function Er(e,t){let n=rc(e.limits.maxStringLength),r=0,s=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",i=e.state.env.get("HOSTNAME")||"localhost",o=i.split(".")[0],a=e.state.env.get("PWD")||"/",l=e.state.env.get("HOME")||"/",c=a.startsWith(l)?`~${a.slice(l.length)}`:a,u=a.split("/").pop()||a,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],p=e.state.env.get("__COMMAND_NUMBER")||"1";for(;r<t.length;){let m=t[r];if(m==="\\"){if(r+1>=t.length){n.append("\\"),r++;continue}let y=t[r+1];if(y>="0"&&y<="7"){let b="",w=r+1;for(;w<t.length&&w<r+4&&t[w]>="0"&&t[w]<="7";)b+=t[w],w++;let E=Number.parseInt(b,8)%256;n.append(String.fromCharCode(E)),r=w;continue}switch(y){case"\\":n.append("\\"),r+=2;break;case"a":n.append("\x07"),r+=2;break;case"e":n.append("\x1B"),r+=2;break;case"n":n.append(`
|
|
103
|
+
`),r+=2;break;case"r":n.append("\r"),r+=2;break;case"$":n.append("$"),r+=2;break;case"[":case"]":r+=2;break;case"u":n.append(s),r+=2;break;case"h":n.append(o),r+=2;break;case"H":n.append(i),r+=2;break;case"w":n.append(c),r+=2;break;case"W":n.append(u),r+=2;break;case"d":{let b=String(f.getDate()).padStart(2," ");n.append(`${d[f.getDay()]} ${h[f.getMonth()]} ${b}`),r+=2;break}case"t":{let b=String(f.getHours()).padStart(2,"0"),w=String(f.getMinutes()).padStart(2,"0"),E=String(f.getSeconds()).padStart(2,"0");n.append(`${b}:${w}:${E}`),r+=2;break}case"T":{let b=f.getHours()%12;b===0&&(b=12);let w=String(b).padStart(2,"0"),E=String(f.getMinutes()).padStart(2,"0"),S=String(f.getSeconds()).padStart(2,"0");n.append(`${w}:${E}:${S}`),r+=2;break}case"@":{let b=f.getHours()%12;b===0&&(b=12);let w=String(b).padStart(2,"0"),E=String(f.getMinutes()).padStart(2,"0"),S=f.getHours()<12?"AM":"PM";n.append(`${w}:${E} ${S}`),r+=2;break}case"A":{let b=String(f.getHours()).padStart(2,"0"),w=String(f.getMinutes()).padStart(2,"0");n.append(`${b}:${w}`),r+=2;break}case"D":if(r+2<t.length&&t[r+2]==="{"){let b=t.indexOf("}",r+3);if(b!==-1){let w=t.slice(r+3,b);n.append(Bh(w,f,e.limits.maxStringLength)),r=b+1}else n.append("\\D"),r+=2}else n.append("\\D"),r+=2;break;case"s":n.append("bash"),r+=2;break;case"v":n.append("5.0"),r+=2;break;case"V":n.append("5.0.0"),r+=2;break;case"j":n.append("0"),r+=2;break;case"l":n.append("tty"),r+=2;break;case"#":n.append(p),r+=2;break;case"!":n.append(p),r+=2;break;case"x":n.append("\\x"),r+=2;break;default:n.append(`\\${y}`),r+=2}}else n.append(m),r++}return n.build()}function rn(e){if(e==="")return"''";if(/[\n\r\t\x00-\x1f\x7f']/.test(e)){let n="$'";for(let r of e)switch(r){case"'":n+="\\'";break;case"\\":n+="\\\\";break;case`
|
|
104
104
|
`:n+="\\n";break;case"\r":n+="\\r";break;case" ":n+="\\t";break;default:{let s=r.charCodeAt(0);s<32||s===127?n+=`\\${s.toString(8).padStart(3,"0")}`:n+=r}}return`${n}'`}return`'${e}'`}function Ze(e,t){e.state.readonlyVars=e.state.readonlyVars||new Set,e.state.readonlyVars.add(t)}function We(e,t){return e.state.readonlyVars?.has(t)??!1}function fe(e,t,n="bash"){if(We(e,t)){let r=`${n}: ${t}: readonly variable
|
|
105
|
-
`;throw new
|
|
106
|
-
`)}async function
|
|
107
|
-
`);let u;if(/^\d+$/.test(c))u=Number.parseInt(c,10);else{try{let f=new
|
|
108
|
-
`)}return r.effectiveValue}async function
|
|
109
|
-
`);let u=
|
|
110
|
-
`;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return l}});case"K":case"k":return r?"":rn(n);case"u":return n.charAt(0).toUpperCase()+n.slice(1);case"U":return n.toUpperCase();case"L":return n.toLowerCase();default:return n}}async function cc(e,t,n,r,s,i,o=!1){if(e.coverage?.hit("bash:expansion:indirection"),ue(e,t))return Cn(e,t)||"";let a=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(s.innerOp?.type==="UseAlternative")return"";throw new Xe(`\${!${t}}`)}let l=n;if(a&&(l===""||l.includes(" ")))throw new Xe(`\${!${t}}`);let c=l.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(c&&c[1].includes("~"))throw new Xe(`\${!${t}}`);if(s.innerOp){let u={type:"ParameterExpansion",parameter:l,operation:s.innerOp};return i(e,u,o)}return await ie(e,l)}function uc(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=Q(e,t.array).map(([s])=>String(s));return t.star?r.join(X(e.state.env)):r.join(" ")}function fc(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let n=zn(e,t.prefix);return t.star?n.join(X(e.state.env)):n.join(" ")}function dc(e,t,n,r){let s=Number.parseInt(e.state.env.get("#")||"0",10),i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:s===0,effectiveValue:n};if(t==="@")return{isEmpty:s===0||s===1&&e.state.env.get("1")==="",effectiveValue:n};if(i){let[,o,a]=i,l=Q(e,o);return l.length===0?{isEmpty:!0,effectiveValue:""}:a==="*"?{isEmpty:r?n==="":!1,effectiveValue:n}:{isEmpty:l.length===1&&l.every(([,c])=>c===""),effectiveValue:n}}return{isEmpty:n==="",effectiveValue:n}}function on(e,t){e.lastExitCode=t,e.env.set("?",String(t)),e.lastSubstitutionExitCode=t}function _h(e){switch(e.operator){case"<":case"<&":case"<<":case"<<-":case"<<<":case"<>":return e.fd===null||e.fd===0;default:return!1}}function cs(e,t){return t.some(_h)?0:e.lastSubstitutionExitCode??0}function hc(e){let t=0;for(;t<e.length;){let n=e[t];if(n==="\\"&&t+1<e.length){t+=2;continue}if(n==="'"){let r=e.indexOf("'",t+1);if(r!==-1){t=r+1;continue}}if(n==="$"&&t+1<e.length&&e[t+1]==="("||n==="`")return!0;t++}return!1}function pc(e,t){let n=1,r=t,s=!1,i=!1;for(;r<e.length&&n>0;){let o=e[r];if(o==="\\"&&!s&&r+1<e.length){r+=2;continue}if(o==="'"&&!i){s=!s,r++;continue}if(o==='"'&&!s){i=!i,r++;continue}if(!s&&!i){if(o==="(")n++;else if(o===")"&&(n--,n===0))return r}r++}return-1}async function us(e,t){let n=new Z,r;try{r=n.parse(t)}catch{return""}let s=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let i=new Map(e.state.env),o=at(e.state.arrays),a=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let c=await e.executeScript(r),u=c.exitCode;return e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.suppressVerbose=l,on(e.state,u),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr),e.state.bashPid=s,c.stdout.replace(/\n+$/,"")}catch(c){if(e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.bashPid=s,e.state.suppressVerbose=l,c instanceof $)throw c;return c instanceof q?(on(e.state,c.exitCode),c.stdout?.replace(/\n+$/,"")??""):""}}function Qi(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=et(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=Th(e,a);n+=et(l),r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}function Th(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){n+=i,r+=2;continue}n+=s,r++;continue}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}n+=s,r++}return n}async function mc(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=et(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=await Lh(e,a);n+=et(l),r=i+1;continue}}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=pc(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await us(e,o);n+=a,r=i+1;continue}}if(s==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let o=t.slice(r+1,i),a=await us(e,o);n+=a,r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}async function Lh(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){n+=i,r+=2;continue}n+=s,r++;continue}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=pc(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await us(e,o);n+=a,r=i+1;continue}}if(s==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let o=t.slice(r+1,i),a=await us(e,o);n+=a,r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}n+=s,r++}return n}function Ki(e,t){if(!t.startsWith("~"))return t;e.coverage?.hit("bash:expansion:tilde");let n=e.state.env.get("HOME")!==void 0?e.state.env.get("HOME"):"/home/user";if(t==="~"||t.startsWith("~/"))return n+t.slice(1);let r=1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;let s=t.slice(1,r),i=t.slice(r);return i!==""&&!i.startsWith("/")?t:s==="root"?`/root${i}`:t}function an(e,t){return t.split(":").map(n=>Ki(e,n)).join(":")}function De(e,t,n,r){if(e.length>n-t.length)throw new $(`${r} element limit exceeded (${n})`,"array_elements");for(let s of t)e.push(s)}async function Fh(e,t,n,r){let s="";for(let i of t.parts)if(i.type==="Glob")s+=oe(i.pattern,!0,e.state.shoptOptions.extglob);else if(i.type==="Literal")s+=oe(i.value,!0,e.state.shoptOptions.extglob);else if(i.type==="SingleQuoted"||i.type==="Escaped")s+=ce(i.value);else if(i.type==="DoubleQuoted"){let o=await n(e,i.parts);s+=ce(o)}else if(i.type==="ParameterExpansion"){let o=await r(e,i);s+=oe(o,!0,e.state.shoptOptions.extglob)}else{let o=await r(e,i);s+=ce(o)}return s}async function yc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternReplacement")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",c=i.operation,u=Q(e,a),f=u.map(([,E])=>E);if(u.length===0){let E=e.state.env.get(a);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let d="";c.pattern&&(d=await Fh(e,c.pattern,n,r));let h=c.replacement?await n(e,c.replacement.parts):"",p=d;c.anchor==="start"?p=`^${d}`:c.anchor==="end"&&(p=`${d}$`);let m=[];try{let E=ge(p,c.all?"g":"");for(let S of f)m.push(E.replace(S,h))}catch{m.push(...f)}if(l){let E=X(e.state.env);return{values:[m.join(E)],quoted:!0}}return{values:m,quoted:!0}}async function gc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternRemoval")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",c=i.operation,u=Q(e,a),f=u.map(([,p])=>p);if(u.length===0){let p=e.state.env.get(a);p!==void 0&&f.push(p)}if(f.length===0)return{values:[],quoted:!0};let d=c.pattern?await nn(e,c.pattern,c.greedy,n,r):"",h=[];for(let p of f)h.push(bt(e,p,d,c.side,c.greedy));if(l){let p=X(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}async function wc(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="DefaultValue"&&n.parts[0].operation?.type!=="UseAlternative"&&n.parts[0].operation?.type!=="AssignDefault")return null;let r=n.parts[0];if(r.operation?.type==="AssignDefault"&&/^(?:\d+|[@*#?$!-])$/.test(r.parameter))return null;let s=r.operation,i=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(s.type==="AssignDefault"&&(!i||i[2]==="*"))return null;let o,a=!1;if(i){let l=i[1];a=i[2]==="*";let c=Q(e,l),u=c.length>0||e.state.env.has(l),f=c.length===0||c.length===1&&c.every(([,h])=>h===""),d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=u&&!(d&&f):o=!u||d&&f,!o){if(c.length>0){let p=c.map(([,m])=>m);if(a){let m=X(e.state.env);return{values:[p.join(m)],quoted:!0}}return{values:p,quoted:!0}}let h=e.state.env.get(l);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}else{let l=r.parameter,c=await $t(e,l),u=await ie(e,l,!1),f=u==="",d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=c&&!(d&&f):o=!c||d&&f,!o)return{values:[u],quoted:!0}}if(s.type==="AssignDefault")return null;if(o&&s.word){let l=s.word.parts,c=null,u=!1;for(let f of l)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){c=d[1],u=d[2]==="*";break}}if(c){let f=Q(e,c);if(f.length>0){let h=f.map(([,p])=>p);if(u||a){let p=X(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}let d=e.state.env.get(c);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}return null}async function Ec(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0],o=-1,a="",l=!1,c=null;for(let m=0;m<i.parts.length;m++){let E=i.parts[m];if(E.type==="ParameterExpansion"&&(E.operation?.type==="PatternRemoval"||E.operation?.type==="PatternReplacement")){let S=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(S){o=m,a=S[1],l=S[2]==="*",c=E.operation;break}}}if(o===-1||o===0&&o===i.parts.length-1)return null;let u="";for(let m=0;m<o;m++)u+=await r(e,i.parts[m]);let f="";for(let m=o+1;m<i.parts.length;m++)f+=await r(e,i.parts[m]);let d=Q(e,a),h=d.map(([,m])=>m);if(d.length===0){let m=e.state.env.get(a);if(m!==void 0)h=[m];else{if(l)return{values:[u+f],quoted:!0};let E=u+f;return{values:E?[E]:[],quoted:!0}}}if(c?.type==="PatternRemoval"){let m=c,E=m.pattern?await nn(e,m.pattern,m.greedy,s,r):"";h=h.map(S=>bt(e,S,E,m.side,m.greedy))}else if(c?.type==="PatternReplacement"){let m=c,E="";if(m.pattern)for(let g of m.pattern.parts)if(g.type==="Glob")E+=oe(g.pattern,!0,e.state.shoptOptions.extglob);else if(g.type==="Literal")E+=oe(g.value,!0,e.state.shoptOptions.extglob);else if(g.type==="SingleQuoted"||g.type==="Escaped")E+=ce(g.value);else if(g.type==="DoubleQuoted"){let b=await s(e,g.parts);E+=ce(b)}else if(g.type==="ParameterExpansion"){let b=await r(e,g);E+=oe(b,!0,e.state.shoptOptions.extglob)}else{let b=await r(e,g);E+=ce(b)}let S=m.replacement?await s(e,m.replacement.parts):"",y=E;m.anchor==="start"?y=`^${E}`:m.anchor==="end"&&(y=`${E}$`);try{let g=ge(y,m.all?"g":"");h=h.map(b=>g.replace(b,S))}catch{}}if(l){let m=X(e.state.env);return{values:[u+h.join(m)+f],quoted:!0}}return h.length===1?{values:[u+h[0]+f],quoted:!0}:{values:[u+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function bc(e,t,n,r){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o="",a=!1;for(let h=0;h<s.parts.length;h++){let p=s.parts[h];if(p.type==="ParameterExpansion"&&!p.operation){let m=p.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(m){i=h,o=m[1],a=m[2]==="*";break}}}if(i===-1)return null;let l="";for(let h=0;h<i;h++)l+=await r(e,s.parts[h]);let c="";for(let h=i+1;h<s.parts.length;h++)c+=await r(e,s.parts[h]);let u=Q(e,o),f=u.map(([,h])=>h);if(u.length===0){let h=e.state.env.get(o);if(h!==void 0)return{values:[l+h+c],quoted:!0};if(a)return{values:[l+c],quoted:!0};let p=l+c;return{values:p?[p]:[],quoted:!0}}if(a){let h=X(e.state.env);return{values:[l+f.join(h)+c],quoted:!0}}return f.length===1?{values:[l+f[0]+c],quoted:!0}:{values:[l+f[0],...f.slice(1,-1),f[f.length-1]+c],quoted:!0}}async function Sc(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Substring")return null;let s=r.parts[0],i=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let o=i[1],a=i[2]==="*",l=s.operation;if(e.state.associativeArrays?.has(o))throw new q(1,"",`bash: \${${o}[@]: 0: 3}: bad substitution
|
|
111
|
-
`);let c=l.offset?await n(e,l.offset.expression):0,u=l.length?await n(e,l.length.expression):void 0,f=Q(e,o);if(f.length>e.limits.maxArrayElements)throw new $(`array transform element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let d=0;if(c<0){if(f.length>0){let p=f[f.length-1][0],E=(typeof p=="number"?p:0)+1+c;if(E<0)return{values:[],quoted:!0};d=f.findIndex(([S])=>typeof S=="number"&&S>=E),d<0&&(d=f.length)}}else d=f.findIndex(([p])=>typeof p=="number"&&p>=c),d<0&&(d=f.length);let h;if(u!==void 0){if(u<0)throw new le(`${o}[@]: substring expression < 0`);h=f.slice(d,d+u).map(([,p])=>p)}else h=f.slice(d).map(([,p])=>p);if(h.length===0)return{values:[],quoted:!0};if(a){let p=X(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}function Ac(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="Transform")return null;let r=n.parts[0],s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!s)return null;let i=s[1],o=s[2]==="*",a=r.operation,l=Q(e,i);if(l.length===0){let d=e.state.env.get(i);if(d!==void 0){let h;switch(a.operator){case"a":h="";break;case"P":h=wr(e,d);break;case"Q":h=rn(d);break;default:h=d}if(M(h)>e.limits.maxStringLength)throw new $(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[h],quoted:!0}}return o?{values:[""],quoted:!0}:{values:[],quoted:!0}}let c=sn(e,i),u=[],f=0;for(let[,d]of l){let h;switch(a.operator){case"a":h=c;break;case"P":h=wr(e,d);break;case"Q":h=rn(d);break;case"u":h=d.charAt(0).toUpperCase()+d.slice(1);break;case"U":h=d.toUpperCase();break;case"L":h=d.toLowerCase();break;default:h=d}let p=M(h);if(p>e.limits.maxStringLength-f)throw new $(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u.push(h),f+=p}if(o){let d=X(e.state.env);if(Math.max(0,u.length-1)*M(d)>e.limits.maxStringLength-f)throw new $(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u.join(d)],quoted:!0}}return{values:u,quoted:!0}}function vc(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion")return null;let r=n.parts[0];if(r.operation)return null;let s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!s)return null;let i=s[1];if(ue(e,i)){let l=Cn(e,i);if(l?.endsWith("[@]")||l?.endsWith("[*]"))return{values:[],quoted:!0}}let o=Q(e,i);if(o.length>0)return{values:o.map(([,l])=>l),quoted:!0};let a=e.state.env.get(i);return a!==void 0?{values:[a],quoted:!0}:{values:[],quoted:!0}}function kc(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation)return null;let s=n.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)||!ue(e,s))return null;let i=Cn(e,s);if(!i)return null;let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!o)return null;let a=o[1],l=Q(e,a);if(l.length>0)return{values:l.map(([,u])=>u),quoted:!0};let c=e.state.env.get(a);return c!==void 0?{values:[c],quoted:!0}:{values:[],quoted:!0}}async function xc(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let o=i.parts[0],a=o.operation,l=await ie(e,o.parameter),c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c){if(!a.innerOp&&(l==="@"||l==="*")){let p=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let E=1;E<=p;E++)m.push(e.state.env.get(String(E))||"");return l==="*"?{values:[m.join(X(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let u=c[1],f=c[2]==="*",d=Q(e,u);if(a.innerOp){if(a.innerOp.type==="Substring")return Mh(e,d,u,f,a.innerOp);if(a.innerOp.type==="DefaultValue"||a.innerOp.type==="UseAlternative"||a.innerOp.type==="AssignDefault"||a.innerOp.type==="ErrorIfUnset")return Bh(e,d,u,f,a.innerOp,s);if(a.innerOp.type==="Transform"&&a.innerOp.operator==="a"){let m=sn(e,u),E=d.map(()=>m);return f?{values:[E.join(X(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let p=[];for(let[,m]of d){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:a.innerOp},S=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",m);try{let y=await r(e,E,!0);p.push(y)}finally{S!==void 0?e.state.env.set("_indirect_elem_",S):e.state.env.delete("_indirect_elem_")}}return f?{values:[p.join(X(e.state.env))],quoted:!0}:{values:p,quoted:!0}}if(d.length>0){let p=d.map(([,m])=>m);return f?{values:[p.join(X(e.state.env))],quoted:!0}:{values:p,quoted:!0}}let h=e.state.env.get(u);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}async function Mh(e,t,n,r,s){let i=s.offset?await J(e,s.offset.expression):0,o=s.length?await J(e,s.length.expression):void 0,a=0;if(i<0){if(t.length>0){let u=t[t.length-1][0],d=(typeof u=="number"?u:0)+1+i;if(d<0)return{values:[],quoted:!0};if(a=t.findIndex(([h])=>typeof h=="number"&&h>=d),a<0)return{values:[],quoted:!0}}}else if(a=t.findIndex(([u])=>typeof u=="number"&&u>=i),a<0)return{values:[],quoted:!0};let l;if(o!==void 0){if(o<0)throw new le(`${n}[@]: substring expression < 0`);l=t.slice(a,a+o)}else l=t.slice(a);let c=l.map(([,u])=>u);return r?{values:[c.join(X(e.state.env))],quoted:!0}:{values:c,quoted:!0}}async function Bh(e,t,n,r,s,i){let o=s.checkEmpty??!1,a=t.map(([,u])=>u),l=t.length===0,c=t.length===0;if(s.type==="UseAlternative")return!c&&!(o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(s.type==="DefaultValue")return(c||o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:r?{values:[a.join(X(e.state.env))],quoted:!0}:{values:a,quoted:!0};if(s.type==="AssignDefault"){if((c||o&&l)&&s.word){let f=await i(e,s.word.parts,!0);return G(e,n,0,f),{values:[f],quoted:!0}}return r?{values:[a.join(X(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return r?{values:[a.join(X(e.state.env))],quoted:!0}:{values:a,quoted:!0}}async function Pc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let n=t[0],r=n.operation,s=r?.word;if(!s||s.parts.length!==1||s.parts[0].type!=="DoubleQuoted")return null;let i=s.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let o=i.parts[0],l=(await ie(e,o.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!l)return null;let c=await $t(e,n.parameter),u=await ie(e,n.parameter)==="",f=r.checkEmpty??!1,d;if(r.type==="UseAlternative"?d=c&&!(f&&u):d=!c||f&&u,d){let h=l[1],p=l[2]==="*",m=Q(e,h);if(m.length>0){let S=m.map(([,y])=>y);return p?{values:[S.join(X(e.state.env))],quoted:!0}:{values:S,quoted:!0}}let E=e.state.env.get(h);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function $c(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let n=t[0],s=n.operation.innerOp;if(!s||s.type!=="UseAlternative"&&s.type!=="DefaultValue")return null;let i=s.word;if(!i||i.parts.length!==1||i.parts[0].type!=="DoubleQuoted")return null;let o=i.parts[0];if(o.parts.length!==1||o.parts[0].type!=="ParameterExpansion"||o.parts[0].operation?.type!=="Indirection")return null;let a=o.parts[0],c=(await ie(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c)return null;let u=await ie(e,n.parameter),f=await $t(e,n.parameter),d=u==="",h=s.checkEmpty??!1,p;if(s.type==="UseAlternative"?p=f&&!(h&&d):p=!f||h&&d,p){let m=c[1],E=c[2]==="*",S=Q(e,m);if(S.length>0){let g=S.map(([,b])=>b);return E?{values:[g.join(X(e.state.env))],quoted:!0}:{values:g,quoted:!0}}let y=e.state.env.get(m);return y!==void 0?{values:[y],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function Cc(e){let t=Number.parseInt(e.state.env.get("#")||"0",10);if(t>e.limits.maxArrayElements)throw new $(`positional parameter element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let n=[],r=0;for(let s=1;s<=t;s++){let i=e.state.env.get(String(s))||"",o=M(i);if(o>e.limits.maxStringLength-r)throw new $(`positional parameter string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n.push(i),r+=o}return n}function fs(e,t,n){if(M(t)>n-M(e))throw new $(`positional expansion string limit exceeded (${n} bytes)`,"string_length");return e+t}function Xi(e,t,n,r){if(e.length>=r.limits.maxArrayElements)throw new $(`positional expansion element limit exceeded (${r.limits.maxArrayElements})`,"array_elements");let s=M(t);if(s>r.limits.maxStringLength-n.value)throw new $(`positional expansion string limit exceeded (${r.limits.maxStringLength} bytes)`,"string_length");e.push(t),n.value+=s}async function Nc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let y=0;y<s.parts.length;y++){let g=s.parts[y];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="Substring"){i=y,o=g.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=l.offset?await n(e,l.offset.expression):0,u=l.length?await n(e,l.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),d=[];for(let y=1;y<=f;y++)d.push(e.state.env.get(String(y))||"");let h=e.state.env.get("0")||"bash",p;if(c<=0){let y=[h,...d],g=y.length+c;if(g<0)p=[];else{let b=c<0?g:0;if(u!==void 0){let v=u<0?y.length+u:b+u;p=y.slice(b,Math.max(b,v))}else p=y.slice(b)}}else{let y=c-1;if(y>=d.length)p=[];else if(u!==void 0){let g=u<0?d.length+u:y+u;p=d.slice(y,Math.max(y,g))}else p=d.slice(y)}let m="";for(let y=0;y<i;y++)m+=await r(e,s.parts[y]);let E="";for(let y=i+1;y<s.parts.length;y++)E+=await r(e,s.parts[y]);if(p.length===0){let y=m+E;return{values:y?[y]:[],quoted:!0}}if(o){let y=X(e.state.env);return{values:[m+p.join(y)+E],quoted:!0}}return p.length===1?{values:[m+p[0]+E],quoted:!0}:{values:[m+p[0],...p.slice(1,-1),p[p.length-1]+E],quoted:!0}}async function Rc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let y=0;y<s.parts.length;y++){let g=s.parts[y];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="PatternReplacement"){i=y,o=g.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=Cc(e),u="";for(let y=0;y<i;y++)u=fs(u,await n(e,s.parts[y]),e.limits.maxStringLength);let f="";for(let y=i+1;y<s.parts.length;y++)f=fs(f,await n(e,s.parts[y]),e.limits.maxStringLength);if(c.length===0){let y=u+f;return{values:y?[y]:[],quoted:!0}}let d="";if(l.pattern)for(let y of l.pattern.parts)if(y.type==="Glob")d+=oe(y.pattern,!0,e.state.shoptOptions.extglob);else if(y.type==="Literal")d+=oe(y.value,!0,e.state.shoptOptions.extglob);else if(y.type==="SingleQuoted"||y.type==="Escaped")d+=ce(y.value);else if(y.type==="DoubleQuoted"){let g=await r(e,y.parts);d+=ce(g)}else if(y.type==="ParameterExpansion"){let g=await n(e,y);d+=oe(g,!0,e.state.shoptOptions.extglob)}else{let g=await n(e,y);d+=ce(g)}let h=l.replacement?await r(e,l.replacement.parts):"",p=d;l.anchor==="start"?p=`^${d}`:l.anchor==="end"&&(p=`${d}$`);let m=[],E={value:0};try{let y=ge(p,l.all?"g":"");for(let g of c){let b=0;y.lastIndex=0;for(let x=y.exec(g);x&&(b++,!!l.all);x=y.exec(g))x[0].length===0&&y.lastIndex++;let v=M(g),k=M(h),A=0,P=/\$(?:\$|&|\d+|<[^>]+>|`|')/g;for(;P.exec(h)!==null;)A++;if(v+b*k+b*A*v>e.limits.maxStringLength-E.value)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");Xi(m,y.replace(g,h),E,e)}}catch(y){if(y instanceof $)throw y;for(let g of c)Xi(m,g,E,e)}if(o){let y=X(e.state.env);if(E.value+Math.max(0,m.length-1)*M(y)+M(u)+M(f)>e.limits.maxStringLength)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+m.join(y)+f],quoted:!0}}if(M(u)+E.value+M(f)>e.limits.maxStringLength)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return m.length===1?{values:[u+m[0]+f],quoted:!0}:{values:[u+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function Oc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let S=0;S<s.parts.length;S++){let y=s.parts[S];if(y.type==="ParameterExpansion"&&(y.parameter==="@"||y.parameter==="*")&&y.operation?.type==="PatternRemoval"){i=S,o=y.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=Cc(e),u="";for(let S=0;S<i;S++)u=fs(u,await n(e,s.parts[S]),e.limits.maxStringLength);let f="";for(let S=i+1;S<s.parts.length;S++)f=fs(f,await n(e,s.parts[S]),e.limits.maxStringLength);if(c.length===0){let S=u+f;return{values:S?[S]:[],quoted:!0}}let d="",h=e.state.shoptOptions.extglob;if(l.pattern)for(let S of l.pattern.parts)if(S.type==="Glob")d+=oe(S.pattern,l.greedy,h);else if(S.type==="Literal")d+=oe(S.value,l.greedy,h);else if(S.type==="SingleQuoted"||S.type==="Escaped")d+=ce(S.value);else if(S.type==="DoubleQuoted"){let y=await r(e,S.parts);d+=ce(y)}else if(S.type==="ParameterExpansion"){let y=await n(e,S);d+=oe(y,l.greedy,h)}else{let y=await n(e,S);d+=ce(y)}let p=[],m={value:0};for(let S of c)Xi(p,bt(e,S,d,l.side,l.greedy),m,e);if(o){let S=X(e.state.env);if(m.value+Math.max(0,p.length-1)*M(S)+M(u)+M(f)>e.limits.maxStringLength)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+p.join(S)+f],quoted:!0}}if(M(u)+m.value+M(f)>e.limits.maxStringLength)throw new $(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return p.length===1?{values:[u+p[0]+f],quoted:!0}:{values:[u+p[0],...p.slice(1,-1),p[p.length-1]+f],quoted:!0}}async function Dc(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0],s=-1,i=!1;for(let d=0;d<r.parts.length;d++){let h=r.parts[d];if(h.type==="ParameterExpansion"&&(h.parameter==="@"||h.parameter==="*")){s=d,i=h.parameter==="*";break}}if(s===-1)return null;let o=r.parts[s];if(o.type==="ParameterExpansion"&&o.operation)return null;let a=Number.parseInt(e.state.env.get("#")||"0",10),l="";for(let d=0;d<s;d++)l+=await n(e,r.parts[d]);let c="";for(let d=s+1;d<r.parts.length;d++)c+=await n(e,r.parts[d]);if(a===0){if(i)return{values:[l+c],quoted:!0};let d=l+c;return{values:d?[d]:[],quoted:!0}}let u=[];for(let d=1;d<=a;d++)u.push(e.state.env.get(String(d))||"");if(i){let d=X(e.state.env);return{values:[l+u.join(d)+c],quoted:!0}}return u.length===1?{values:[l+u[0]+c],quoted:!0}:{values:[l+u[0],...u.slice(1,-1),u[u.length-1]+c],quoted:!0}}function Nt(e,t,n,r){if(t.length>=e.limits.maxArrayElements)throw new $(`unquoted expansion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let s=M(n);if(s>e.limits.maxStringLength-r.value)throw new $(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");t.push(n),r.value+=s}function Yi(e,t,n,r){let s=M(n),i=Math.max(0,t.length-1);if(s>0&&i>Math.floor((e.limits.maxStringLength-r)/s))throw new $(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return t.join(n)}function Wh(e){return new tn(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")})}async function ds(e,t){if(e.state.options.noglob)return t;let n=Wh(e),r=[];for(let s of t)if(Ct(s,e.state.shoptOptions.extglob)){let i=await n.expand(s);if(i.length>0)De(r,i,e.limits.maxArrayElements,"unquoted glob expansion");else{if(n.hasFailglob())throw new jt(s);n.hasNullglob()||r.push(s)}}else r.push(s);return r}async function Ic(e,t,n,r){let s=-1,i="",o=!1;for(let b=0;b<t.length;b++){let v=t[b];if(v.type==="ParameterExpansion"&&v.operation?.type==="PatternReplacement"){let k=v.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(k){s=b,i=k[1],o=k[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,c=Q(e,i),u=c.map(([,b])=>b);if(c.length===0){let b=e.state.env.get(i);b!==void 0&&(u=[b])}if(u.length===0)return{values:[],quoted:!1};let f="";if(l.pattern)for(let b of l.pattern.parts)if(b.type==="Glob")f+=oe(b.pattern,!0,e.state.shoptOptions.extglob);else if(b.type==="Literal")f+=oe(b.value,!0,e.state.shoptOptions.extglob);else if(b.type==="SingleQuoted"||b.type==="Escaped")f+=ce(b.value);else if(b.type==="DoubleQuoted"){let v=await n(e,b.parts);f+=ce(v)}else if(b.type==="ParameterExpansion"){let v=await r(e,b);f+=oe(v,!0,e.state.shoptOptions.extglob)}else{let v=await r(e,b);f+=ce(v)}let d=l.replacement?await n(e,l.replacement.parts):"",h=f;l.anchor==="start"?h=`^${f}`:l.anchor==="end"&&(h=`${f}$`);let p=[],m={value:0};try{let b=ge(h,l.all?"g":"");for(let v of u)Nt(e,p,as(e,v,b,d,l.all),m)}catch(b){if(b instanceof $)throw b;for(let v of u)Nt(e,p,v,m)}let E=ke(e.state.env),S=Oe(e.state.env);if(o){let b=X(e.state.env),v=Yi(e,p,b,m.value);return S?{values:v?[v]:[],quoted:!1}:{values:de(v,E,e.limits.maxArrayElements),quoted:!1}}if(S)return{values:p,quoted:!1};let y=[],g={value:0};for(let b of p)if(b==="")Nt(e,y,"",g);else for(let v of de(b,E,e.limits.maxArrayElements))Nt(e,y,v,g);return{values:y,quoted:!1}}async function _c(e,t,n,r){let s=-1,i="",o=!1;for(let y=0;y<t.length;y++){let g=t[y];if(g.type==="ParameterExpansion"&&g.operation?.type==="PatternRemoval"){let b=g.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){s=y,i=b[1],o=b[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,c=Q(e,i),u=c.map(([,y])=>y);if(c.length===0){let y=e.state.env.get(i);y!==void 0&&(u=[y])}if(u.length===0)return{values:[],quoted:!1};let f=l.pattern?await nn(e,l.pattern,l.greedy,n,r):"",d=[],h={value:0};for(let y of u)Nt(e,d,bt(e,y,f,l.side,l.greedy),h);let p=ke(e.state.env),m=Oe(e.state.env);if(o){let y=X(e.state.env),g=Yi(e,d,y,h.value);return m?{values:g?[g]:[],quoted:!1}:{values:de(g,p,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[],S={value:0};for(let y of d)if(y==="")Nt(e,E,"",S);else for(let g of de(y,p,e.limits.maxArrayElements))Nt(e,E,g,S);return{values:E,quoted:!1}}async function Tc(e,t,n,r){let s=-1,i=!1;for(let y=0;y<t.length;y++){let g=t[y];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="PatternRemoval"){s=y,i=g.parameter==="*";break}}if(s===-1)return null;let a=t[s].operation,l=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let y=1;y<=l;y++)c.push(e.state.env.get(String(y))||"");if(c.length===0)return{values:[],quoted:!1};let u="",f=e.state.shoptOptions.extglob;if(a.pattern)for(let y of a.pattern.parts)if(y.type==="Glob")u+=oe(y.pattern,a.greedy,f);else if(y.type==="Literal")u+=oe(y.value,a.greedy,f);else if(y.type==="SingleQuoted"||y.type==="Escaped")u+=ce(y.value);else if(y.type==="DoubleQuoted"){let g=await n(e,y.parts);u+=ce(g)}else if(y.type==="ParameterExpansion"){let g=await r(e,y);u+=oe(g,a.greedy,f)}else{let g=await r(e,y);u+=ce(g)}let d=[],h={value:0};for(let y of c)Nt(e,d,bt(e,y,u,a.side,a.greedy),h);let p=ke(e.state.env),m=Oe(e.state.env);if(i){let y=X(e.state.env),g=Yi(e,d,y,h.value);return m?{values:g?[g]:[],quoted:!1}:{values:de(g,p,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[],S={value:0};for(let y of d)if(y==="")Nt(e,E,"",S);else for(let g of de(y,p,e.limits.maxArrayElements))Nt(e,E,g,S);return{values:E,quoted:!1}}async function Lc(e,t,n,r){let s=-1,i=!1;for(let g=0;g<t.length;g++){let b=t[g];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="Substring"){s=g,i=b.parameter==="*";break}}if(s===-1)return null;let a=t[s].operation,l=a.offset?await n(e,a.offset.expression):0,c=a.length?await n(e,a.length.expression):void 0,u=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let g=1;g<=u;g++)f.push(e.state.env.get(String(g))||"");let d=e.state.env.get("0")||"bash",h;if(l<=0){let g=[d,...f],b=g.length+l;if(b<0)h=[];else{let v=l<0?b:0;if(c!==void 0){let k=c<0?g.length+c:v+c;h=g.slice(v,Math.max(v,k))}else h=g.slice(v)}}else{let g=l-1;if(g>=f.length)h=[];else if(c!==void 0){let b=c<0?f.length+c:g+c;h=f.slice(g,Math.max(g,b))}else h=f.slice(g)}let p="";for(let g=0;g<s;g++)p+=await r(e,t[g]);let m="";for(let g=s+1;g<t.length;g++)m+=await r(e,t[g]);let E=ke(e.state.env),S=Oe(e.state.env);if(h.length===0){let g=p+m;return g?S?{values:[g],quoted:!1}:{values:de(g,E,e.limits.maxArrayElements),quoted:!1}:{values:[],quoted:!1}}let y;if(i){let g=X(e.state.env),b=p+h.join(g)+m;S?y=b?[b]:[]:y=de(b,E,e.limits.maxArrayElements)}else if(S)h.length===1?y=[p+h[0]+m]:y=[p+h[0],...h.slice(1,-1),h[h.length-1]+m];else{y=[];for(let g=0;g<h.length;g++){let b=h[g];if(g===0&&(b=p+b),g===h.length-1&&(b=b+m),b==="")y.push("");else{let v=de(b,E,e.limits.maxArrayElements);De(y,v,e.limits.maxArrayElements,"unquoted expansion")}}}return{values:await ds(e,y),quoted:!1}}async function Fc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let n=t[0].parameter==="*",r=Number.parseInt(e.state.env.get("#")||"0",10);if(r===0)return{values:[],quoted:!1};let s=[];for(let c=1;c<=r;c++)s.push(e.state.env.get(String(c))||"");let i=ke(e.state.env),o=Oe(e.state.env),a=ns(e.state.env),l;if(n)if(o)l=s.filter(c=>c!=="");else{let c=X(e.state.env),u=s.join(c);l=de(u,i,e.limits.maxArrayElements)}else if(o)l=s.filter(c=>c!=="");else if(a){l=[];for(let c of s){if(c==="")continue;let u=de(c,i,e.limits.maxArrayElements);De(l,u,e.limits.maxArrayElements,"unquoted expansion")}}else{l=[];for(let c of s)if(c==="")l.push("");else{let u=de(c,i,e.limits.maxArrayElements);De(l,u,e.limits.maxArrayElements,"unquoted expansion")}for(;l.length>0&&l[l.length-1]==="";)l.pop()}return{values:await ds(e,l),quoted:!1}}async function Mc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let n=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let r=n[1],s=n[2]==="*",i=Q(e,r),o;if(i.length===0){let f=e.state.env.get(r);if(f!==void 0)o=[f];else return{values:[],quoted:!1}}else o=i.map(([,f])=>f);let a=ke(e.state.env),l=Oe(e.state.env),c=ns(e.state.env),u;if(s)if(l)u=o.filter(f=>f!=="");else{let f=X(e.state.env),d=o.join(f);u=de(d,a,e.limits.maxArrayElements)}else if(l)u=o.filter(f=>f!=="");else if(c){u=[];for(let f of o){if(f==="")continue;let d=de(f,a,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}}else{u=[];for(let f of o)if(f==="")u.push("");else{let d=de(f,a,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}for(;u.length>0&&u[u.length-1]==="";)u.pop()}return{values:await ds(e,u),quoted:!1}}function Bc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let n=t[0].operation,r=zn(e,n.prefix);if(r.length===0)return{values:[],quoted:!1};let s=ke(e.state.env),i=Oe(e.state.env),o;if(n.star)if(i)o=r;else{let a=X(e.state.env),l=r.join(a);o=de(l,s,e.limits.maxArrayElements)}else if(i)o=r;else{o=[];for(let a of r){let l=de(a,s,e.limits.maxArrayElements);De(o,l,e.limits.maxArrayElements,"unquoted expansion")}}return{values:o,quoted:!1}}function Wc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let n=t[0].operation,s=Q(e,n.array).map(([l])=>String(l));if(s.length===0)return{values:[],quoted:!1};let i=ke(e.state.env),o=Oe(e.state.env),a;if(n.star)if(o)a=s;else{let l=X(e.state.env),c=s.join(l);a=de(c,i,e.limits.maxArrayElements)}else if(o)a=s;else{a=[];for(let l of s){let c=de(l,i,e.limits.maxArrayElements);De(a,c,e.limits.maxArrayElements,"unquoted expansion")}}return{values:a,quoted:!1}}async function Vc(e,t,n){let r=-1;for(let d=0;d<t.length;d++){let h=t[d];if(h.type==="ParameterExpansion"&&(h.parameter==="@"||h.parameter==="*")&&!h.operation){r=d;break}}if(r===-1||t.length<=1)return null;let s=Number.parseInt(e.state.env.get("#")||"0",10),i=[];for(let d=1;d<=s;d++)i.push(e.state.env.get(String(d))||"");let o="";for(let d=0;d<r;d++)o+=await n(e,t[d]);let a="";for(let d=r+1;d<t.length;d++)a+=await n(e,t[d]);let l=ke(e.state.env),c=Oe(e.state.env),u=ns(e.state.env);if(s===0){let d=o+a;return{values:d?[d]:[],quoted:!1}}let f;{let d=[];for(let h=0;h<i.length;h++){let p=i[h];h===0&&(p=o+p),h===i.length-1&&(p=p+a),d.push(p)}if(c)f=d.filter(h=>h!=="");else if(u){f=[];for(let h of d){if(h==="")continue;let p=de(h,l,e.limits.maxArrayElements);De(f,p,e.limits.maxArrayElements,"unquoted expansion")}}else{f=[];for(let h of d)if(h==="")f.push("");else{let p=de(h,l,e.limits.maxArrayElements);De(f,p,e.limits.maxArrayElements,"unquoted expansion")}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await ds(e,f),quoted:!1}}async function jc(e,t,n){e.coverage?.hit("bash:expansion:word_glob");let r=t.parts,{hasQuoted:s,hasCommandSub:i,hasArrayVar:o,hasArrayAtExpansion:a,hasParamExpansion:l,hasVarNamePrefixExpansion:c,hasIndirection:u}=yr(r),d=n.hasBraceExpansion(r)?await n.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return Vh(e,d,s);let h=await zh(e,r,a,c,u,n);if(h!==null)return h;let p=await jh(e,r,n);if(p!==null)return p;let m=await qh(e,r,n);if(m!==null)return m;let E=await Hh(e,r,n.expandPart);if(E!==null)return Uc(e,E);if((i||o||l)&&!Oe(e.state.env)){let y=ke(e.state.env),g=n.buildIfsCharClassPattern(y),b=await n.smartWordSplit(e,r,y,g,n.expandPart);return Uc(e,b)}let S=await n.expandWordAsync(e,t);return Zh(e,t,r,S,s,n.expandWordForGlobbing)}async function Vh(e,t,n){let r=[];for(let s of t)if(!(!n&&s===""))if(!n&&!e.state.options.noglob&&Ct(s,e.state.shoptOptions.extglob)){let i=await hs(e,s);De(r,i,e.limits.maxArrayElements,"brace/glob expansion")}else r.push(s);return{values:r,quoted:!1}}async function zh(e,t,n,r,s,i){if(n){let o=vc(e,t);if(o!==null)return o}{let o=kc(e,t);if(o!==null)return o}{let o=await wc(e,t);if(o!==null)return o}{let o=await Ec(e,t,n,i.expandPart,i.expandWordPartsAsync);if(o!==null)return o}{let o=await bc(e,t,n,i.expandPart);if(o!==null)return o}{let o=await Sc(e,t,i.evaluateArithmetic);if(o!==null)return o}{let o=Ac(e,t);if(o!==null)return o}{let o=await yc(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}{let o=await gc(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let o=Uh(e,t);if(o!==null)return o}{let o=await xc(e,t,s,i.expandParameterAsync,i.expandWordPartsAsync);if(o!==null)return o}{let o=await Pc(e,t);if(o!==null)return o}{let o=await $c(e,t);if(o!==null)return o}return null}function Uh(e,t){let n=t[0];if(n.type!=="DoubleQuoted")return null;if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="VarNamePrefix"){let r=n.parts[0].operation,s=zn(e,r.prefix);return r.star?{values:[s.join(X(e.state.env))],quoted:!0}:{values:s,quoted:!0}}if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="ArrayKeys"){let r=n.parts[0].operation,i=Q(e,r.array).map(([o])=>String(o));return r.star?{values:[i.join(X(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function jh(e,t,n){{let r=await Nc(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await Rc(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Oc(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Dc(e,t,n.expandPart);if(r!==null)return r}return null}async function qh(e,t,n){{let r=await Ic(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await _c(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Tc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Lc(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await Fc(e,t);if(r!==null)return r}{let r=await Mc(e,t);if(r!==null)return r}{let r=Bc(e,t);if(r!==null)return r}{let r=Wc(e,t);if(r!==null)return r}{let r=await Vc(e,t,n.expandPart);if(r!==null)return r}return null}function zc(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;t<e.parts.length;t++){let n=e.parts[t];if(n.type!=="ParameterExpansion"||n.operation)continue;let r=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(r)return{type:"array",name:r[1],atIndex:t,isStar:r[2]==="*"};if(n.parameter==="@"||n.parameter==="*")return{type:"positional",atIndex:t,isStar:n.parameter==="*"}}return null}async function Gh(e,t,n,r){let s="";for(let a=0;a<n.atIndex;a++)s+=await r(e,t.parts[a]);let i="";for(let a=n.atIndex+1;a<t.parts.length;a++)i+=await r(e,t.parts[a]);let o;if(n.type==="array"){if(o=Q(e,n.name).map(([,l])=>l),o.length===0){let l=e.state.env.get(n.name);l!==void 0&&(o=[l])}}else{let a=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let l=1;l<=a;l++)o.push(e.state.env.get(String(l))||"")}if(n.isStar){let a=X(e.state.env),l=o.join(a);return[s+l+i]}if(o.length===0){let a=s+i;return a?[a]:[]}return o.length===1?[s+o[0]+i]:[s+o[0],...o.slice(1,-1),o[o.length-1]+i]}async function Hh(e,t,n){if(t.length<2)return null;let r=!1;for(let l of t)if(zc(l)){r=!0;break}if(!r)return null;let s=ke(e.state.env),i=Oe(e.state.env),o=[];for(let l of t){let c=zc(l);if(c&&l.type==="DoubleQuoted"){let u=await Gh(e,l,c,n);o.push(u)}else if(l.type==="DoubleQuoted"||l.type==="SingleQuoted"){let u=await n(e,l);o.push([u])}else if(l.type==="Literal")o.push([l.value]);else if(l.type==="ParameterExpansion"){let u=await n(e,l);if(i)o.push(u?[u]:[]);else{let f=de(u,s,e.limits.maxArrayElements);o.push(f)}}else{let u=await n(e,l);if(i)o.push(u?[u]:[]);else{let f=de(u,s,e.limits.maxArrayElements);o.push(f)}}}let a=[];for(let l of o)if(l.length!==0)if(a.length===0)De(a,l,e.limits.maxArrayElements,"word expansion");else{let c=a.length-1;a[c]=a[c]+l[0];for(let u=1;u<l.length;u++)a.push(l[u])}return a}async function Uc(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let n=[];for(let r of t)if(Ct(r,e.state.shoptOptions.extglob)){let s=await hs(e,r);De(n,s,e.limits.maxArrayElements,"glob expansion")}else n.push(r);return{values:n,quoted:!1}}async function hs(e,t){let n=new tn(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")}),r=await n.expand(t);if(r.length>0)return r;if(n.hasFailglob())throw new jt(t);return n.hasNullglob()?[]:[t]}async function Zh(e,t,n,r,s,i){let o=n.some(a=>a.type==="Glob");if(!e.state.options.noglob&&o){let a=await i(e,t);if(Ct(a,e.state.shoptOptions.extglob)){let c=await hs(e,a);if(c.length>0&&c[0]!==a)return{values:c,quoted:!1};if(c.length===0)return{values:[],quoted:!1}}let l=Gi(r);if(!Oe(e.state.env)){let c=ke(e.state.env);return{values:de(l,c,e.limits.maxArrayElements),quoted:!1}}return{values:[l],quoted:!1}}if(!s&&!e.state.options.noglob&&Ct(r,e.state.shoptOptions.extglob)){let a=await i(e,t);if(Ct(a,e.state.shoptOptions.extglob)){let l=await hs(e,a);if(l.length>0&&l[0]!==a)return{values:l,quoted:!1}}}if(r===""&&!s)return{values:[],quoted:!1};if(o&&!s){let a=Gi(r);if(!Oe(e.state.env)){let l=ke(e.state.env);return{values:de(a,l,e.limits.maxArrayElements),quoted:!1}}return{values:[a],quoted:!1}}return{values:[r],quoted:s}}function Fe(e,t,n){if(t.length>=e.limits.maxArrayElements)throw new $(`word splitting element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");t.push(n)}async function Gc(e,t){let n=t.operation;if(!n||n.type!=="DefaultValue"&&n.type!=="AssignDefault"&&n.type!=="UseAlternative")return null;let r=n.word;if(!r||r.parts.length===0)return null;let s=await $t(e,t.parameter),o=await ie(e,t.parameter,!1)==="",a=n.checkEmpty??!1,l;return n.type==="UseAlternative"?l=s&&!(a&&o):l=!s||a&&o,l?(n.type==="AssignDefault"&&Hi(t.parameter),r.parts):null}function Qh(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(n=>n.type==="Literal"):!1}async function Kh(e,t){if(t.type!=="ParameterExpansion")return null;let n=await Gc(e,t);if(!n||n.length<=1)return null;let r=n.some(i=>Qh(i)),s=n.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&s?n:null}function Xh(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?Mi(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&jl(e))}async function Hc(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let d=t[0],h=await Gc(e,d);if(h&&h.length>0&&h.length>1&&h.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&h.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return qc(e,h,n,r,s)}let i=[],o=!1;for(let d of t){let h=Xh(d),p=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=h?await Kh(e,d):null,E=await s(e,d);i.push({value:E,isSplittable:h,isQuoted:p,mixedDefaultParts:m??void 0}),h&&(o=!0)}if(!o){let d=i.map(h=>h.value).join("");return d?[d]:[]}let a=[],l="",c=!1,u=!1,f=!1;for(let d of i)if(!d.isSplittable)u?d.isQuoted&&d.value===""?(l!==""&&Fe(e,a,l),Fe(e,a,""),c=!0,l="",u=!1,f=!0):d.value!==""?(l!==""&&Fe(e,a,l),l=d.value,u=!1,f=!1):(l+=d.value,f=!1):(l+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let h=await qc(e,d.mixedDefaultParts,n,r,s);if(h.length!==0)if(h.length===1)l+=h[0],c=!0;else{l+=h[0],Fe(e,a,l),c=!0;for(let p=1;p<h.length-1;p++)Fe(e,a,h[p]);l=h[h.length-1]}u=!1,f=!1}else{let{words:h,hadLeadingDelimiter:p,hadTrailingDelimiter:m}=rs(d.value,n,e.limits.maxArrayElements);if(f&&p&&l===""&&(Fe(e,a,""),c=!0),h.length===0)m&&(u=!0);else if(h.length===1)l+=h[0],c=!0,u=m;else{l+=h[0],Fe(e,a,l),c=!0;for(let E=1;E<h.length-1;E++)Fe(e,a,h[E]);l=h[h.length-1],u=m}f=!1}return l!==""?Fe(e,a,l):a.length===0&&c&&Fe(e,a,""),a}function Yh(e,t){return e.length>0&&t.includes(e[0])}async function qc(e,t,n,r,s){let i=[];for(let u of t){let d=!(u.type==="DoubleQuoted"||u.type==="SingleQuoted"),h=await s(e,u);i.push({value:h,isSplittable:d})}let o=[],a="",l=!1,c=!1;for(let u of i)if(!u.isSplittable)c&&u.value!==""?(a!==""&&Fe(e,o,a),a=u.value,c=!1):a+=u.value;else{Yh(u.value,n)&&a!==""&&(Fe(e,o,a),a="",l=!0);let{words:d,hadTrailingDelimiter:h}=rs(u.value,n,e.limits.maxArrayElements);if(d.length===0)h&&(c=!0);else if(d.length===1)a+=d[0],l=!0,c=h;else{a+=d[0],Fe(e,o,a),l=!0;for(let p=1;p<d.length-1;p++)Fe(e,o,d[p]);a=d[d.length-1],c=h}}return a!==""?Fe(e,o,a):o.length===0&&l&&Fe(e,o,""),o}function Zc(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Qc(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}var ps="/dev/fd",Xc=63,Jh=10,Kc=Xc-Jh+1,Ji=class extends gt{isLiveDescriptor;constructor(t){super(),this.isLiveDescriptor=t}assertLiveDescriptor(t,n){this.isLiveDescriptor(t)||this.refuse(t,n)}refuse(t,n){throw new Error(`EROFS: read-only file system, ${n} '${ps}${t}'`)}async writeFile(t,n,r){return this.assertLiveDescriptor(t,"write"),super.writeFile(t,n,r)}async appendFile(t,n,r){return this.assertLiveDescriptor(t,"append"),super.appendFile(t,n,r)}async rm(t,n){return this.assertLiveDescriptor(t,"rm"),super.rm(t,n)}async mkdir(t,n){this.refuse(t,"mkdir")}async cp(t,n){this.refuse(n,"cp")}async mv(t,n){this.refuse(n,"mv")}async symlink(t,n){this.refuse(n,"symlink")}async link(t,n){this.refuse(n,"link")}async chmod(t,n){this.refuse(t,"chmod")}async utimes(t,n,r){this.refuse(t,"utimes")}};function ep(e){let t=new Ji(n=>Yc(e).some(r=>r.path===`${ps}${n}`));e.fs=new Kt({base:e.fs,mounts:[{mountPoint:ps,filesystem:t}]}),e.state.processSubstitutionFsMounted=!0}async function tp(e,t,n){try{await e.fs.writeFile(t,n,"binary");return}catch(r){if(e.state.processSubstitutionFsMounted)throw r;ep(e)}await e.fs.writeFile(t,n,"binary")}async function np(e,t){try{await e.fs.rm(t,{force:!0})}catch{}}function Yc(e){let t=e.state.processSubstitutions;if(t)return t;let n=[];return e.state.processSubstitutions=n,n}async function Jc(e,t,n){let r=e.substitutionDepth??0,s=e.limits.maxSubstitutionDepth;if(r>=s)throw new $(`Process substitution nesting limit exceeded (${s})`,"substitution_depth");let i=e.substitutionDepth,o=new Map(e.state.env),a=at(e.state.arrays),l=e.state.cwd,c=e.state.bashPid,u=e.state.suppressVerbose,f=e.state.groupStdin,d=e.state.lastExitCode,h=e.state.env.get("?"),p=e.state.lastSubstitutionExitCode;e.substitutionDepth=r+1,e.state.bashPid=e.state.nextVirtualPid++,e.state.suppressVerbose=!0,n!==void 0&&(e.state.groupStdin=n);let m;try{m=await e.executeScript(t)}catch(E){if(E instanceof $)throw E;if(E instanceof q)return{stdout:E.stdout,stderr:E.stderr,exitCode:E.exitCode};throw E}finally{e.substitutionDepth=i,e.state.env=o,e.state.arrays=a,e.state.cwd=l,e.state.bashPid=c,e.state.suppressVerbose=u,e.state.groupStdin=f,e.state.lastExitCode=d,e.state.lastSubstitutionExitCode=p,h!==void 0?e.state.env.set("?",h):e.state.env.delete("?")}return m}async function eu(e,t){let n=Yc(e);if(n.length>=Kc)throw new $(`Process substitution limit exceeded (${Kc} concurrent)`,"file_descriptors");let r="";if(t.direction==="input"){let o=await Jc(e,t.body,void 0);if(o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),r=_t(o),r.length>e.limits.maxStringLength)throw new $(`process substitution: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")}let s=Xc-n.length,i=`${ps}/${s}`;n.push({fd:s,path:i,direction:t.direction,body:t.body});try{await tp(e,i,r)}catch(o){throw n.pop(),o}return i}function tu(e){return e.state.processSubstitutions?.length??0}var rp={stdout:"",stderr:""};async function eo(e,t){let n=e.state.processSubstitutions;if(!n||n.length<=t)return rp;let r="",s="";for(;n.length>t;){let i=n[n.length-1],o="";if(i.direction==="output")try{o=await In(e.fs,i.path)}catch{}if(await np(e,i.path),n.pop(),i.direction==="output"){let a=await Jc(e,i.body,o);r+=_t(a),s+=a.stderr}}return{stdout:r,stderr:s}}function ln(e,t,n){if(e.length>t)throw new $(`${n}: string length limit exceeded (${t} bytes)`,"string_length")}async function At(e,t,n=!1){let r=[],s=0;for(let i of t){let o=await tt(e,i,n);if(s+=M(o),s>e.limits.maxStringLength)throw new $(`parameter word string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");r.push(o)}return r.join("")}function sp(e){return Qc(e)}function ru(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!sp(t))return!1;return!0}function ip(e,t,n=!1){let r=Zc(t);if(r!==null)return r;switch(t.type){case"TildeExpansion":return n?t.user===null?"~":`~${t.user}`:(e.coverage?.hit("bash:expansion:tilde"),t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`);case"Glob":return Qi(e,t.pattern);default:return null}}async function se(e,t){return no(e,t)}async function su(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped")n.push(Vn(r.value));else if(r.type==="SingleQuoted")n.push(r.value);else if(r.type==="DoubleQuoted"){let s=await At(e,r.parts);n.push(s)}else if(r.type==="TildeExpansion"){let s=await tt(e,r);n.push(Vn(s))}else n.push(await tt(e,r));return n.join("")}async function iu(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped"){let s=r.value;"()|*?[]".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="SingleQuoted")n.push(et(r.value));else if(r.type==="DoubleQuoted"){let s=await At(e,r.parts);n.push(et(s))}else n.push(await tt(e,r));return n.join("")}async function ou(e,t){let n=[];for(let r of t.parts)if(r.type==="SingleQuoted")n.push(et(r.value));else if(r.type==="Escaped"){let s=r.value;"*?[]\\()|".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="DoubleQuoted"){let s=await At(e,r.parts);n.push(et(s))}else r.type==="Glob"?hc(r.pattern)?n.push(await mc(e,r.pattern)):n.push(Qi(e,r.pattern)):r.type==="Literal"?n.push(r.value):n.push(await tt(e,r));return n.join("")}function ys(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&ys(t.parts))return!0;return!1}var nu=1e5;async function au(e,t,n={count:0}){let r=()=>{n.count++,e.executionScope.consumeLimited("brace_operations",1,Math.min(nu,e.limits.maxBraceExpansionResults),"brace expansion")},s=(o,a)=>{if(o.length>=e.limits.maxBraceExpansionResults)throw new $(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),o.push(a)},i=[[]];for(let o of t)if(o.type==="BraceExpansion"){let a=[],l=!1,c="";for(let d of o.items)if(d.type==="Range"){let h=qi(d.start,d.end,d.step,d.startStr,d.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(h.expanded)for(let p of h.expanded)s(a,p);else{l=!0,c=h.literal;break}}else{let h=await au(e,d.word.parts,n);for(let p of h){let m=[];for(let E of p)typeof E=="string"?m.push(E):m.push(await tt(e,E));s(a,m.join(""))}}if(l){for(let d of i)r(),d.push(c);continue}if(i.length*a.length>e.limits.maxBraceExpansionResults||n.count>nu)throw new $(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");let f=[];for(let d of i)for(let h of a){if(f.length>=e.limits.maxBraceExpansionResults)throw new $(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),f.push([...d,h])}i=f}else for(let a of i)r(),a.push(o);return i}async function lu(e,t){let n=t.parts;if(!ys(n))return[await se(e,t)];let r=await au(e,n),s=[];for(let i of r){let o=[];for(let a of i)typeof a=="string"?o.push(a):o.push(await tt(e,a));s.push(Ki(e,o.join("")))}return s}function op(){return{expandWordAsync:no,expandWordForGlobbing:ou,expandWordWithBracesAsync:lu,expandWordPartsAsync:At,expandPart:tt,expandParameterAsync:ms,hasBraceExpansion:ys,evaluateArithmetic:J,buildIfsCharClassPattern:ql,smartWordSplit:Hc}}async function vt(e,t){return jc(e,t,op())}function ap(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function to(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function r(s){for(let i of s)if(i.type==="DoubleQuoted"){for(let o of i.parts)if(o.type==="ParameterExpansion"&&o.parameter==="@"&&!o.operation)return!0}return!1}return r(t.parts)}async function cu(e,t){if(to(e,t))return{error:`bash: $@: ambiguous redirect
|
|
112
|
-
`};let n=t.parts,{hasQuoted:r}=
|
|
113
|
-
`};let s=await
|
|
114
|
-
`}}if(r||e.state.options.noglob||n.some(f=>f.type==="ProcessSubstitution"))return{target:s};let l=await
|
|
105
|
+
`;throw new G(1,"",r)}return null}function bt(e,t){let n=e.state.exportedVars?.has(t)??!1;if(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(t),e.state.localScopes.length>0&&e.state.localScopes[e.state.localScopes.length-1].has(t)&&!n){for(e.state.localExportedVars||(e.state.localExportedVars=[]);e.state.localExportedVars.length<e.state.localScopes.length;)e.state.localExportedVars.push(new Set);e.state.localExportedVars[e.state.localExportedVars.length-1].add(t)}}function ds(e,t){e.state.exportedVars?.delete(t)}function sn(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let n="",r=ke(e,t)?.kind==="indexed",s=e.state.associativeArrays?.has(t)??!1;return r&&!s&&(n+="a"),s&&(n+="A"),e.state.integerVars?.has(t)&&(n+="i"),ue(e,t)&&(n+="n"),We(e,t)&&(n+="r"),e.state.exportedVars?.has(t)&&(n+="x"),n}async function sc(e,t,n,r){return e.coverage?.hit("bash:expansion:default_value"),(n.isUnset||t.checkEmpty&&n.isEmpty)&&t.word?r(e,t.word.parts,n.inDoubleQuotes):n.effectiveValue}function Qi(e){if(/^(?:\d+|[@*#?$!-])$/.test(e))throw new G(1,"",`bash: $${e}: cannot assign in this way
|
|
106
|
+
`)}async function ic(e,t,n,r,s){e.coverage?.hit("bash:expansion:assign_default");let i=r.isUnset||n.checkEmpty&&r.isEmpty;if(i&&Qi(t),i&&n.word){let o=await s(e,n.word.parts,r.inDoubleQuotes),a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let[,l,c]=a;if(c==="@"||c==="*")throw new G(1,"",`${e.state.expansionStderr||""}bash: ${t}: bad array subscript
|
|
107
|
+
`);let u;if(/^\d+$/.test(c))u=Number.parseInt(c,10);else{try{let f=new Q,d=re(f,c);u=await J(e,d.expression)}catch{let f=e.state.env.get(c);u=f?Number.parseInt(f,10):0}Number.isNaN(u)&&(u=0)}H(e,l,u,o)}else e.state.env.set(t,o);return o}return r.effectiveValue}async function oc(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:error_if_unset"),r.isUnset||n.checkEmpty&&r.isEmpty){let o=n.word?await s(e,n.word.parts,r.inDoubleQuotes):`${t}: parameter null or not set`;throw new G(1,"",`bash: ${o}
|
|
108
|
+
`)}return r.effectiveValue}async function ac(e,t,n,r){return e.coverage?.hit("bash:expansion:use_alternative"),!(n.isUnset||t.checkEmpty&&n.isEmpty)&&t.word?r(e,t.word.parts,n.inDoubleQuotes):""}async function lc(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_removal");let i=n.pattern?await nn(e,n.pattern,n.greedy,r,s):"";return Et(e,t,i,n.side,n.greedy)}async function cc(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",o=e.state.shoptOptions.extglob;if(n.pattern)for(let c of n.pattern.parts)if(c.type==="Glob")i+=oe(c.pattern,!0,o);else if(c.type==="Literal")i+=oe(c.value,!0,o);else if(c.type==="SingleQuoted"||c.type==="Escaped")i+=ce(c.value);else if(c.type==="DoubleQuoted"){let u=await r(e,c.parts);i+=ce(u)}else if(c.type==="ParameterExpansion"){let u=await s(e,c);i+=oe(u,!0,o)}else{let u=await s(e,c);i+=ce(u)}let a=n.replacement?await r(e,n.replacement.parts):"";if(n.anchor==="start"?i=`^${i}`:n.anchor==="end"&&(i=`${i}$`),i==="")return t;let l=n.all?"gs":"s";try{let c=ge(i,l);return fs(e,t,c,a,n.all)}catch(c){if(c instanceof C)throw c;return t}}function Ki(e,t,n){e.coverage?.hit("bash:expansion:length");let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(r){let s=r[1],i=K(e,s);return i.length>0?String(i.length):e.state.env.get(s)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&wt(e,t)){if(t==="FUNCNAME"){let i=e.state.funcNameStack?.[0]||"";return String([...i].length)}if(t==="BASH_LINENO"){let i=e.state.callLineStack?.[0];return String(i!==void 0?[...String(i)].length:0)}let s=ae(e,t,0)||"";return String([...s].length)}return String([...n].length)}async function uc(e,t,n,r){e.coverage?.hit("bash:expansion:substring");let s=await J(e,r.offset.expression),i=r.length?await J(e,r.length.expression):void 0;if(t==="@"||t==="*"){let c=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let p=1;p<=c;p++)u.push(e.state.env.get(String(p))||"");let f=e.state.env.get("0")||"bash",d,h;if(s<=0)if(d=[f,...u],s<0){if(h=d.length+s,h<0)return""}else h=0;else d=u,h=s-1;if(h<0||h>=d.length)return"";if(i!==void 0){let p=i<0?d.length+i:h+i;return d.slice(h,Math.max(h,p)).join(" ")}return d.slice(h).join(" ")}let o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(o){let c=o[1];if(e.state.associativeArrays?.has(c))throw new G(1,"",`bash: \${${c}[@]: 0: 3}: bad substitution
|
|
109
|
+
`);let u=K(e,c),f=0;if(s<0){if(u.length>0){let d=u[u.length-1][0],p=(typeof d=="number"?d:0)+1+s;if(p<0||(f=u.findIndex(([m])=>typeof m=="number"&&m>=p),f<0))return""}}else if(f=u.findIndex(([d])=>typeof d=="number"&&d>=s),f<0)return"";if(i!==void 0){if(i<0)throw new le(`${o[1]}[@]: substring expression < 0`);return u.slice(f,f+i).map(([,d])=>d).join(" ")}return u.slice(f).map(([,d])=>d).join(" ")}let a=[...n],l=s;if(l<0&&(l=Math.max(0,a.length+l)),i!==void 0){if(i<0){let c=a.length+i;return a.slice(l,Math.max(l,c)).join("")}return a.slice(l,l+i).join("")}return a.slice(l).join("")}async function fc(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:case_modification"),n.pattern){let i=e.state.shoptOptions.extglob,o="";for(let f of n.pattern.parts)if(f.type==="Glob")o+=oe(f.pattern,!0,i);else if(f.type==="Literal")o+=oe(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")o+=ce(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);o+=ce(d)}else if(f.type==="ParameterExpansion"){let d=await s(e,f);o+=oe(d,!0,i)}let a=ge(`^(?:${o})$`),l=n.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),c="",u=!1;for(let f of t)!n.all&&u?c+=f:a.test(f)?(c+=l(f),u=!0):c+=f;return c}return n.direction==="upper"?n.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):n.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function dc(e,t,n,r,s){e.coverage?.hit("bash:expansion:transform");let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i&&s.operator==="Q")return K(e,i[1]).map(([,c])=>rn(c)).join(" ");if(i&&s.operator==="a")return sn(e,i[1]);let o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(o&&s.operator==="a")return sn(e,o[1]);switch(s.operator){case"Q":return r?"":rn(n);case"P":return Er(e,n);case"a":return sn(e,t);case"A":return r?"":`${t}=${rn(n)}`;case"E":return n.replace(/\\([\\abefnrtv'"?])/g,(a,l)=>{switch(l){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
|
|
110
|
+
`;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return l}});case"K":case"k":return r?"":rn(n);case"u":return n.charAt(0).toUpperCase()+n.slice(1);case"U":return n.toUpperCase();case"L":return n.toLowerCase();default:return n}}async function hc(e,t,n,r,s,i,o=!1){if(e.coverage?.hit("bash:expansion:indirection"),ue(e,t))return Cn(e,t)||"";let a=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(s.innerOp?.type==="UseAlternative")return"";throw new Xe(`\${!${t}}`)}let l=n;if(a&&(l===""||l.includes(" ")))throw new Xe(`\${!${t}}`);let c=l.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(c&&c[1].includes("~"))throw new Xe(`\${!${t}}`);if(s.innerOp){let u={type:"ParameterExpansion",parameter:l,operation:s.innerOp};return i(e,u,o)}return await ie(e,l)}function pc(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=K(e,t.array).map(([s])=>String(s));return t.star?r.join(X(e.state.env)):r.join(" ")}function mc(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let n=Un(e,t.prefix);return t.star?n.join(X(e.state.env)):n.join(" ")}function yc(e,t,n,r){let s=Number.parseInt(e.state.env.get("#")||"0",10),i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:s===0,effectiveValue:n};if(t==="@")return{isEmpty:s===0||s===1&&e.state.env.get("1")==="",effectiveValue:n};if(i){let[,o,a]=i,l=K(e,o);return l.length===0?{isEmpty:!0,effectiveValue:""}:a==="*"?{isEmpty:r?n==="":!1,effectiveValue:n}:{isEmpty:l.length===1&&l.every(([,c])=>c===""),effectiveValue:n}}return{isEmpty:n==="",effectiveValue:n}}function on(e,t){e.lastExitCode=t,e.env.set("?",String(t)),e.lastSubstitutionExitCode=t}function Wh(e){switch(e.operator){case"<":case"<&":case"<<":case"<<-":case"<<<":case"<>":return e.fd===null||e.fd===0;default:return!1}}function hs(e,t){return t.some(Wh)?0:e.lastSubstitutionExitCode??0}function gc(e){let t=0;for(;t<e.length;){let n=e[t];if(n==="\\"&&t+1<e.length){t+=2;continue}if(n==="'"){let r=e.indexOf("'",t+1);if(r!==-1){t=r+1;continue}}if(n==="$"&&t+1<e.length&&e[t+1]==="("||n==="`")return!0;t++}return!1}function wc(e,t){let n=1,r=t,s=!1,i=!1;for(;r<e.length&&n>0;){let o=e[r];if(o==="\\"&&!s&&r+1<e.length){r+=2;continue}if(o==="'"&&!i){s=!s,r++;continue}if(o==='"'&&!s){i=!i,r++;continue}if(!s&&!i){if(o==="(")n++;else if(o===")"&&(n--,n===0))return r}r++}return-1}async function ps(e,t){let n=new Q,r;try{r=n.parse(t)}catch{return""}let s=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let i=new Map(e.state.env),o=ot(e.state.arrays),a=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let c=await e.executeScript(r),u=c.exitCode;return e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.suppressVerbose=l,on(e.state,u),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr),e.state.bashPid=s,c.stdout.replace(/\n+$/,"")}catch(c){if(e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.bashPid=s,e.state.suppressVerbose=l,c instanceof C)throw c;return c instanceof G?(on(e.state,c.exitCode),c.stdout?.replace(/\n+$/,"")??""):""}}function Xi(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=et(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=Vh(e,a);n+=et(l),r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}function Vh(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){n+=i,r+=2;continue}n+=s,r++;continue}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}n+=s,r++}return n}async function Ec(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=et(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=await zh(e,a);n+=et(l),r=i+1;continue}}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=wc(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await ps(e,o);n+=a,r=i+1;continue}}if(s==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let o=t.slice(r+1,i),a=await ps(e,o);n+=a,r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}async function zh(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){n+=i,r+=2;continue}n+=s,r++;continue}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=wc(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await ps(e,o);n+=a,r=i+1;continue}}if(s==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let o=t.slice(r+1,i),a=await ps(e,o);n+=a,r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}n+=s,r++}return n}function Yi(e,t){if(!t.startsWith("~"))return t;e.coverage?.hit("bash:expansion:tilde");let n=e.state.env.get("HOME")!==void 0?e.state.env.get("HOME"):"/home/user";if(t==="~"||t.startsWith("~/"))return n+t.slice(1);let r=1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;let s=t.slice(1,r),i=t.slice(r);return i!==""&&!i.startsWith("/")?t:s==="root"?`/root${i}`:t}function an(e,t){return t.split(":").map(n=>Yi(e,n)).join(":")}function De(e,t,n,r){if(e.length>n-t.length)throw new C(`${r} element limit exceeded (${n})`,"array_elements");for(let s of t)e.push(s)}async function Uh(e,t,n,r){let s="";for(let i of t.parts)if(i.type==="Glob")s+=oe(i.pattern,!0,e.state.shoptOptions.extglob);else if(i.type==="Literal")s+=oe(i.value,!0,e.state.shoptOptions.extglob);else if(i.type==="SingleQuoted"||i.type==="Escaped")s+=ce(i.value);else if(i.type==="DoubleQuoted"){let o=await n(e,i.parts);s+=ce(o)}else if(i.type==="ParameterExpansion"){let o=await r(e,i);s+=oe(o,!0,e.state.shoptOptions.extglob)}else{let o=await r(e,i);s+=ce(o)}return s}async function bc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternReplacement")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",c=i.operation,u=K(e,a),f=u.map(([,y])=>y);if(u.length===0){let y=e.state.env.get(a);y!==void 0&&f.push(y)}if(f.length===0)return{values:[],quoted:!0};let d="";c.pattern&&(d=await Uh(e,c.pattern,n,r));let h=c.replacement?await n(e,c.replacement.parts):"",p=d;c.anchor==="start"?p=`^${d}`:c.anchor==="end"&&(p=`${d}$`);let m=[];try{let y=ge(p,c.all?"g":"");for(let b of f)m.push(y.replace(b,h))}catch{m.push(...f)}if(l){let y=X(e.state.env);return{values:[m.join(y)],quoted:!0}}return{values:m,quoted:!0}}async function Sc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternRemoval")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",c=i.operation,u=K(e,a),f=u.map(([,p])=>p);if(u.length===0){let p=e.state.env.get(a);p!==void 0&&f.push(p)}if(f.length===0)return{values:[],quoted:!0};let d=c.pattern?await nn(e,c.pattern,c.greedy,n,r):"",h=[];for(let p of f)h.push(Et(e,p,d,c.side,c.greedy));if(l){let p=X(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}async function Ac(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="DefaultValue"&&n.parts[0].operation?.type!=="UseAlternative"&&n.parts[0].operation?.type!=="AssignDefault")return null;let r=n.parts[0];if(r.operation?.type==="AssignDefault"&&/^(?:\d+|[@*#?$!-])$/.test(r.parameter))return null;let s=r.operation,i=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(s.type==="AssignDefault"&&(!i||i[2]==="*"))return null;let o,a=!1;if(i){let l=i[1];a=i[2]==="*";let c=K(e,l),u=c.length>0||e.state.env.has(l),f=c.length===0||c.length===1&&c.every(([,h])=>h===""),d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=u&&!(d&&f):o=!u||d&&f,!o){if(c.length>0){let p=c.map(([,m])=>m);if(a){let m=X(e.state.env);return{values:[p.join(m)],quoted:!0}}return{values:p,quoted:!0}}let h=e.state.env.get(l);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}else{let l=r.parameter,c=await $t(e,l),u=await ie(e,l,!1),f=u==="",d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=c&&!(d&&f):o=!c||d&&f,!o)return{values:[u],quoted:!0}}if(s.type==="AssignDefault")return null;if(o&&s.word){let l=s.word.parts,c=null,u=!1;for(let f of l)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){c=d[1],u=d[2]==="*";break}}if(c){let f=K(e,c);if(f.length>0){let h=f.map(([,p])=>p);if(u||a){let p=X(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}let d=e.state.env.get(c);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}return null}async function vc(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0],o=-1,a="",l=!1,c=null;for(let m=0;m<i.parts.length;m++){let y=i.parts[m];if(y.type==="ParameterExpansion"&&(y.operation?.type==="PatternRemoval"||y.operation?.type==="PatternReplacement")){let b=y.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){o=m,a=b[1],l=b[2]==="*",c=y.operation;break}}}if(o===-1||o===0&&o===i.parts.length-1)return null;let u="";for(let m=0;m<o;m++)u+=await r(e,i.parts[m]);let f="";for(let m=o+1;m<i.parts.length;m++)f+=await r(e,i.parts[m]);let d=K(e,a),h=d.map(([,m])=>m);if(d.length===0){let m=e.state.env.get(a);if(m!==void 0)h=[m];else{if(l)return{values:[u+f],quoted:!0};let y=u+f;return{values:y?[y]:[],quoted:!0}}}if(c?.type==="PatternRemoval"){let m=c,y=m.pattern?await nn(e,m.pattern,m.greedy,s,r):"";h=h.map(b=>Et(e,b,y,m.side,m.greedy))}else if(c?.type==="PatternReplacement"){let m=c,y="";if(m.pattern)for(let E of m.pattern.parts)if(E.type==="Glob")y+=oe(E.pattern,!0,e.state.shoptOptions.extglob);else if(E.type==="Literal")y+=oe(E.value,!0,e.state.shoptOptions.extglob);else if(E.type==="SingleQuoted"||E.type==="Escaped")y+=ce(E.value);else if(E.type==="DoubleQuoted"){let S=await s(e,E.parts);y+=ce(S)}else if(E.type==="ParameterExpansion"){let S=await r(e,E);y+=oe(S,!0,e.state.shoptOptions.extglob)}else{let S=await r(e,E);y+=ce(S)}let b=m.replacement?await s(e,m.replacement.parts):"",w=y;m.anchor==="start"?w=`^${y}`:m.anchor==="end"&&(w=`${y}$`);try{let E=ge(w,m.all?"g":"");h=h.map(S=>E.replace(S,b))}catch{}}if(l){let m=X(e.state.env);return{values:[u+h.join(m)+f],quoted:!0}}return h.length===1?{values:[u+h[0]+f],quoted:!0}:{values:[u+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function kc(e,t,n,r){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o="",a=!1;for(let h=0;h<s.parts.length;h++){let p=s.parts[h];if(p.type==="ParameterExpansion"&&!p.operation){let m=p.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(m){i=h,o=m[1],a=m[2]==="*";break}}}if(i===-1)return null;let l="";for(let h=0;h<i;h++)l+=await r(e,s.parts[h]);let c="";for(let h=i+1;h<s.parts.length;h++)c+=await r(e,s.parts[h]);let u=K(e,o),f=u.map(([,h])=>h);if(u.length===0){let h=e.state.env.get(o);if(h!==void 0)return{values:[l+h+c],quoted:!0};if(a)return{values:[l+c],quoted:!0};let p=l+c;return{values:p?[p]:[],quoted:!0}}if(a){let h=X(e.state.env);return{values:[l+f.join(h)+c],quoted:!0}}return f.length===1?{values:[l+f[0]+c],quoted:!0}:{values:[l+f[0],...f.slice(1,-1),f[f.length-1]+c],quoted:!0}}async function xc(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Substring")return null;let s=r.parts[0],i=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let o=i[1],a=i[2]==="*",l=s.operation;if(e.state.associativeArrays?.has(o))throw new G(1,"",`bash: \${${o}[@]: 0: 3}: bad substitution
|
|
111
|
+
`);let c=l.offset?await n(e,l.offset.expression):0,u=l.length?await n(e,l.length.expression):void 0,f=K(e,o);if(f.length>e.limits.maxArrayElements)throw new C(`array transform element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let d=0;if(c<0){if(f.length>0){let p=f[f.length-1][0],y=(typeof p=="number"?p:0)+1+c;if(y<0)return{values:[],quoted:!0};d=f.findIndex(([b])=>typeof b=="number"&&b>=y),d<0&&(d=f.length)}}else d=f.findIndex(([p])=>typeof p=="number"&&p>=c),d<0&&(d=f.length);let h;if(u!==void 0){if(u<0)throw new le(`${o}[@]: substring expression < 0`);h=f.slice(d,d+u).map(([,p])=>p)}else h=f.slice(d).map(([,p])=>p);if(h.length===0)return{values:[],quoted:!0};if(a){let p=X(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}function Pc(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="Transform")return null;let r=n.parts[0],s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!s)return null;let i=s[1],o=s[2]==="*",a=r.operation,l=K(e,i);if(l.length===0){let d=e.state.env.get(i);if(d!==void 0){let h;switch(a.operator){case"a":h="";break;case"P":h=Er(e,d);break;case"Q":h=rn(d);break;default:h=d}if(V(h)>e.limits.maxStringLength)throw new C(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[h],quoted:!0}}return o?{values:[""],quoted:!0}:{values:[],quoted:!0}}let c=sn(e,i),u=[],f=0;for(let[,d]of l){let h;switch(a.operator){case"a":h=c;break;case"P":h=Er(e,d);break;case"Q":h=rn(d);break;case"u":h=d.charAt(0).toUpperCase()+d.slice(1);break;case"U":h=d.toUpperCase();break;case"L":h=d.toLowerCase();break;default:h=d}let p=V(h);if(p>e.limits.maxStringLength-f)throw new C(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u.push(h),f+=p}if(o){let d=X(e.state.env);if(Math.max(0,u.length-1)*V(d)>e.limits.maxStringLength-f)throw new C(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u.join(d)],quoted:!0}}return{values:u,quoted:!0}}function $c(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion")return null;let r=n.parts[0];if(r.operation)return null;let s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!s)return null;let i=s[1];if(ue(e,i)){let l=Cn(e,i);if(l?.endsWith("[@]")||l?.endsWith("[*]"))return{values:[],quoted:!0}}let o=K(e,i);if(o.length>0)return{values:o.map(([,l])=>l),quoted:!0};let a=e.state.env.get(i);return a!==void 0?{values:[a],quoted:!0}:{values:[],quoted:!0}}function Cc(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation)return null;let s=n.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)||!ue(e,s))return null;let i=Cn(e,s);if(!i)return null;let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!o)return null;let a=o[1],l=K(e,a);if(l.length>0)return{values:l.map(([,u])=>u),quoted:!0};let c=e.state.env.get(a);return c!==void 0?{values:[c],quoted:!0}:{values:[],quoted:!0}}async function Nc(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let o=i.parts[0],a=o.operation,l=await ie(e,o.parameter),c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c){if(!a.innerOp&&(l==="@"||l==="*")){let p=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let y=1;y<=p;y++)m.push(e.state.env.get(String(y))||"");return l==="*"?{values:[m.join(X(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let u=c[1],f=c[2]==="*",d=K(e,u);if(a.innerOp){if(a.innerOp.type==="Substring")return jh(e,d,u,f,a.innerOp);if(a.innerOp.type==="DefaultValue"||a.innerOp.type==="UseAlternative"||a.innerOp.type==="AssignDefault"||a.innerOp.type==="ErrorIfUnset")return qh(e,d,u,f,a.innerOp,s);if(a.innerOp.type==="Transform"&&a.innerOp.operator==="a"){let m=sn(e,u),y=d.map(()=>m);return f?{values:[y.join(X(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let p=[];for(let[,m]of d){let y={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:a.innerOp},b=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",m);try{let w=await r(e,y,!0);p.push(w)}finally{b!==void 0?e.state.env.set("_indirect_elem_",b):e.state.env.delete("_indirect_elem_")}}return f?{values:[p.join(X(e.state.env))],quoted:!0}:{values:p,quoted:!0}}if(d.length>0){let p=d.map(([,m])=>m);return f?{values:[p.join(X(e.state.env))],quoted:!0}:{values:p,quoted:!0}}let h=e.state.env.get(u);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}async function jh(e,t,n,r,s){let i=s.offset?await J(e,s.offset.expression):0,o=s.length?await J(e,s.length.expression):void 0,a=0;if(i<0){if(t.length>0){let u=t[t.length-1][0],d=(typeof u=="number"?u:0)+1+i;if(d<0)return{values:[],quoted:!0};if(a=t.findIndex(([h])=>typeof h=="number"&&h>=d),a<0)return{values:[],quoted:!0}}}else if(a=t.findIndex(([u])=>typeof u=="number"&&u>=i),a<0)return{values:[],quoted:!0};let l;if(o!==void 0){if(o<0)throw new le(`${n}[@]: substring expression < 0`);l=t.slice(a,a+o)}else l=t.slice(a);let c=l.map(([,u])=>u);return r?{values:[c.join(X(e.state.env))],quoted:!0}:{values:c,quoted:!0}}async function qh(e,t,n,r,s,i){let o=s.checkEmpty??!1,a=t.map(([,u])=>u),l=t.length===0,c=t.length===0;if(s.type==="UseAlternative")return!c&&!(o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(s.type==="DefaultValue")return(c||o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:r?{values:[a.join(X(e.state.env))],quoted:!0}:{values:a,quoted:!0};if(s.type==="AssignDefault"){if((c||o&&l)&&s.word){let f=await i(e,s.word.parts,!0);return H(e,n,0,f),{values:[f],quoted:!0}}return r?{values:[a.join(X(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return r?{values:[a.join(X(e.state.env))],quoted:!0}:{values:a,quoted:!0}}async function Rc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let n=t[0],r=n.operation,s=r?.word;if(!s||s.parts.length!==1||s.parts[0].type!=="DoubleQuoted")return null;let i=s.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let o=i.parts[0],l=(await ie(e,o.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!l)return null;let c=await $t(e,n.parameter),u=await ie(e,n.parameter)==="",f=r.checkEmpty??!1,d;if(r.type==="UseAlternative"?d=c&&!(f&&u):d=!c||f&&u,d){let h=l[1],p=l[2]==="*",m=K(e,h);if(m.length>0){let b=m.map(([,w])=>w);return p?{values:[b.join(X(e.state.env))],quoted:!0}:{values:b,quoted:!0}}let y=e.state.env.get(h);return y!==void 0?{values:[y],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function Oc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let n=t[0],s=n.operation.innerOp;if(!s||s.type!=="UseAlternative"&&s.type!=="DefaultValue")return null;let i=s.word;if(!i||i.parts.length!==1||i.parts[0].type!=="DoubleQuoted")return null;let o=i.parts[0];if(o.parts.length!==1||o.parts[0].type!=="ParameterExpansion"||o.parts[0].operation?.type!=="Indirection")return null;let a=o.parts[0],c=(await ie(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!c)return null;let u=await ie(e,n.parameter),f=await $t(e,n.parameter),d=u==="",h=s.checkEmpty??!1,p;if(s.type==="UseAlternative"?p=f&&!(h&&d):p=!f||h&&d,p){let m=c[1],y=c[2]==="*",b=K(e,m);if(b.length>0){let E=b.map(([,S])=>S);return y?{values:[E.join(X(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let w=e.state.env.get(m);return w!==void 0?{values:[w],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function Dc(e){let t=Number.parseInt(e.state.env.get("#")||"0",10);if(t>e.limits.maxArrayElements)throw new C(`positional parameter element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let n=[],r=0;for(let s=1;s<=t;s++){let i=e.state.env.get(String(s))||"",o=V(i);if(o>e.limits.maxStringLength-r)throw new C(`positional parameter string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n.push(i),r+=o}return n}function ms(e,t,n){if(V(t)>n-V(e))throw new C(`positional expansion string limit exceeded (${n} bytes)`,"string_length");return e+t}function Ji(e,t,n,r){if(e.length>=r.limits.maxArrayElements)throw new C(`positional expansion element limit exceeded (${r.limits.maxArrayElements})`,"array_elements");let s=V(t);if(s>r.limits.maxStringLength-n.value)throw new C(`positional expansion string limit exceeded (${r.limits.maxStringLength} bytes)`,"string_length");e.push(t),n.value+=s}async function Ic(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let w=0;w<s.parts.length;w++){let E=s.parts[w];if(E.type==="ParameterExpansion"&&(E.parameter==="@"||E.parameter==="*")&&E.operation?.type==="Substring"){i=w,o=E.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=l.offset?await n(e,l.offset.expression):0,u=l.length?await n(e,l.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),d=[];for(let w=1;w<=f;w++)d.push(e.state.env.get(String(w))||"");let h=e.state.env.get("0")||"bash",p;if(c<=0){let w=[h,...d],E=w.length+c;if(E<0)p=[];else{let S=c<0?E:0;if(u!==void 0){let v=u<0?w.length+u:S+u;p=w.slice(S,Math.max(S,v))}else p=w.slice(S)}}else{let w=c-1;if(w>=d.length)p=[];else if(u!==void 0){let E=u<0?d.length+u:w+u;p=d.slice(w,Math.max(w,E))}else p=d.slice(w)}let m="";for(let w=0;w<i;w++)m+=await r(e,s.parts[w]);let y="";for(let w=i+1;w<s.parts.length;w++)y+=await r(e,s.parts[w]);if(p.length===0){let w=m+y;return{values:w?[w]:[],quoted:!0}}if(o){let w=X(e.state.env);return{values:[m+p.join(w)+y],quoted:!0}}return p.length===1?{values:[m+p[0]+y],quoted:!0}:{values:[m+p[0],...p.slice(1,-1),p[p.length-1]+y],quoted:!0}}async function _c(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let w=0;w<s.parts.length;w++){let E=s.parts[w];if(E.type==="ParameterExpansion"&&(E.parameter==="@"||E.parameter==="*")&&E.operation?.type==="PatternReplacement"){i=w,o=E.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=Dc(e),u="";for(let w=0;w<i;w++)u=ms(u,await n(e,s.parts[w]),e.limits.maxStringLength);let f="";for(let w=i+1;w<s.parts.length;w++)f=ms(f,await n(e,s.parts[w]),e.limits.maxStringLength);if(c.length===0){let w=u+f;return{values:w?[w]:[],quoted:!0}}let d="";if(l.pattern)for(let w of l.pattern.parts)if(w.type==="Glob")d+=oe(w.pattern,!0,e.state.shoptOptions.extglob);else if(w.type==="Literal")d+=oe(w.value,!0,e.state.shoptOptions.extglob);else if(w.type==="SingleQuoted"||w.type==="Escaped")d+=ce(w.value);else if(w.type==="DoubleQuoted"){let E=await r(e,w.parts);d+=ce(E)}else if(w.type==="ParameterExpansion"){let E=await n(e,w);d+=oe(E,!0,e.state.shoptOptions.extglob)}else{let E=await n(e,w);d+=ce(E)}let h=l.replacement?await r(e,l.replacement.parts):"",p=d;l.anchor==="start"?p=`^${d}`:l.anchor==="end"&&(p=`${d}$`);let m=[],y={value:0};try{let w=ge(p,l.all?"g":"");for(let E of c){let S=0;w.lastIndex=0;for(let $=w.exec(E);$&&(S++,!!l.all);$=w.exec(E))$[0].length===0&&w.lastIndex++;let v=V(E),A=V(h),k=0,x=/\$(?:\$|&|\d+|<[^>]+>|`|')/g;for(;x.exec(h)!==null;)k++;if(v+S*A+S*k*v>e.limits.maxStringLength-y.value)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");Ji(m,w.replace(E,h),y,e)}}catch(w){if(w instanceof C)throw w;for(let E of c)Ji(m,E,y,e)}if(o){let w=X(e.state.env);if(y.value+Math.max(0,m.length-1)*V(w)+V(u)+V(f)>e.limits.maxStringLength)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+m.join(w)+f],quoted:!0}}if(V(u)+y.value+V(f)>e.limits.maxStringLength)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return m.length===1?{values:[u+m[0]+f],quoted:!0}:{values:[u+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function Tc(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let b=0;b<s.parts.length;b++){let w=s.parts[b];if(w.type==="ParameterExpansion"&&(w.parameter==="@"||w.parameter==="*")&&w.operation?.type==="PatternRemoval"){i=b,o=w.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,c=Dc(e),u="";for(let b=0;b<i;b++)u=ms(u,await n(e,s.parts[b]),e.limits.maxStringLength);let f="";for(let b=i+1;b<s.parts.length;b++)f=ms(f,await n(e,s.parts[b]),e.limits.maxStringLength);if(c.length===0){let b=u+f;return{values:b?[b]:[],quoted:!0}}let d="",h=e.state.shoptOptions.extglob;if(l.pattern)for(let b of l.pattern.parts)if(b.type==="Glob")d+=oe(b.pattern,l.greedy,h);else if(b.type==="Literal")d+=oe(b.value,l.greedy,h);else if(b.type==="SingleQuoted"||b.type==="Escaped")d+=ce(b.value);else if(b.type==="DoubleQuoted"){let w=await r(e,b.parts);d+=ce(w)}else if(b.type==="ParameterExpansion"){let w=await n(e,b);d+=oe(w,l.greedy,h)}else{let w=await n(e,b);d+=ce(w)}let p=[],m={value:0};for(let b of c)Ji(p,Et(e,b,d,l.side,l.greedy),m,e);if(o){let b=X(e.state.env);if(m.value+Math.max(0,p.length-1)*V(b)+V(u)+V(f)>e.limits.maxStringLength)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[u+p.join(b)+f],quoted:!0}}if(V(u)+m.value+V(f)>e.limits.maxStringLength)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return p.length===1?{values:[u+p[0]+f],quoted:!0}:{values:[u+p[0],...p.slice(1,-1),p[p.length-1]+f],quoted:!0}}async function Lc(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0],s=-1,i=!1;for(let d=0;d<r.parts.length;d++){let h=r.parts[d];if(h.type==="ParameterExpansion"&&(h.parameter==="@"||h.parameter==="*")){s=d,i=h.parameter==="*";break}}if(s===-1)return null;let o=r.parts[s];if(o.type==="ParameterExpansion"&&o.operation)return null;let a=Number.parseInt(e.state.env.get("#")||"0",10),l="";for(let d=0;d<s;d++)l+=await n(e,r.parts[d]);let c="";for(let d=s+1;d<r.parts.length;d++)c+=await n(e,r.parts[d]);if(a===0){if(i)return{values:[l+c],quoted:!0};let d=l+c;return{values:d?[d]:[],quoted:!0}}let u=[];for(let d=1;d<=a;d++)u.push(e.state.env.get(String(d))||"");if(i){let d=X(e.state.env);return{values:[l+u.join(d)+c],quoted:!0}}return u.length===1?{values:[l+u[0]+c],quoted:!0}:{values:[l+u[0],...u.slice(1,-1),u[u.length-1]+c],quoted:!0}}function Nt(e,t,n,r){if(t.length>=e.limits.maxArrayElements)throw new C(`unquoted expansion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let s=V(n);if(s>e.limits.maxStringLength-r.value)throw new C(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");t.push(n),r.value+=s}function eo(e,t,n,r){let s=V(n),i=Math.max(0,t.length-1);if(s>0&&i>Math.floor((e.limits.maxStringLength-r)/s))throw new C(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return t.join(n)}function Gh(e){return new tn(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")})}async function ys(e,t){if(e.state.options.noglob)return t;let n=Gh(e),r=[];for(let s of t)if(Ct(s,e.state.shoptOptions.extglob)){let i=await n.expand(s);if(i.length>0)De(r,i,e.limits.maxArrayElements,"unquoted glob expansion");else{if(n.hasFailglob())throw new jt(s);n.hasNullglob()||r.push(s)}}else r.push(s);return r}async function Fc(e,t,n,r){let s=-1,i="",o=!1;for(let S=0;S<t.length;S++){let v=t[S];if(v.type==="ParameterExpansion"&&v.operation?.type==="PatternReplacement"){let A=v.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(A){s=S,i=A[1],o=A[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,c=K(e,i),u=c.map(([,S])=>S);if(c.length===0){let S=e.state.env.get(i);S!==void 0&&(u=[S])}if(u.length===0)return{values:[],quoted:!1};let f="";if(l.pattern)for(let S of l.pattern.parts)if(S.type==="Glob")f+=oe(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")f+=oe(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=ce(S.value);else if(S.type==="DoubleQuoted"){let v=await n(e,S.parts);f+=ce(v)}else if(S.type==="ParameterExpansion"){let v=await r(e,S);f+=oe(v,!0,e.state.shoptOptions.extglob)}else{let v=await r(e,S);f+=ce(v)}let d=l.replacement?await n(e,l.replacement.parts):"",h=f;l.anchor==="start"?h=`^${f}`:l.anchor==="end"&&(h=`${f}$`);let p=[],m={value:0};try{let S=ge(h,l.all?"g":"");for(let v of u)Nt(e,p,fs(e,v,S,d,l.all),m)}catch(S){if(S instanceof C)throw S;for(let v of u)Nt(e,p,v,m)}let y=ve(e.state.env),b=Oe(e.state.env);if(o){let S=X(e.state.env),v=eo(e,p,S,m.value);return b?{values:v?[v]:[],quoted:!1}:{values:de(v,y,e.limits.maxArrayElements),quoted:!1}}if(b)return{values:p,quoted:!1};let w=[],E={value:0};for(let S of p)if(S==="")Nt(e,w,"",E);else for(let v of de(S,y,e.limits.maxArrayElements))Nt(e,w,v,E);return{values:w,quoted:!1}}async function Mc(e,t,n,r){let s=-1,i="",o=!1;for(let w=0;w<t.length;w++){let E=t[w];if(E.type==="ParameterExpansion"&&E.operation?.type==="PatternRemoval"){let S=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(S){s=w,i=S[1],o=S[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,c=K(e,i),u=c.map(([,w])=>w);if(c.length===0){let w=e.state.env.get(i);w!==void 0&&(u=[w])}if(u.length===0)return{values:[],quoted:!1};let f=l.pattern?await nn(e,l.pattern,l.greedy,n,r):"",d=[],h={value:0};for(let w of u)Nt(e,d,Et(e,w,f,l.side,l.greedy),h);let p=ve(e.state.env),m=Oe(e.state.env);if(o){let w=X(e.state.env),E=eo(e,d,w,h.value);return m?{values:E?[E]:[],quoted:!1}:{values:de(E,p,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let y=[],b={value:0};for(let w of d)if(w==="")Nt(e,y,"",b);else for(let E of de(w,p,e.limits.maxArrayElements))Nt(e,y,E,b);return{values:y,quoted:!1}}async function Bc(e,t,n,r){let s=-1,i=!1;for(let w=0;w<t.length;w++){let E=t[w];if(E.type==="ParameterExpansion"&&(E.parameter==="@"||E.parameter==="*")&&E.operation?.type==="PatternRemoval"){s=w,i=E.parameter==="*";break}}if(s===-1)return null;let a=t[s].operation,l=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let w=1;w<=l;w++)c.push(e.state.env.get(String(w))||"");if(c.length===0)return{values:[],quoted:!1};let u="",f=e.state.shoptOptions.extglob;if(a.pattern)for(let w of a.pattern.parts)if(w.type==="Glob")u+=oe(w.pattern,a.greedy,f);else if(w.type==="Literal")u+=oe(w.value,a.greedy,f);else if(w.type==="SingleQuoted"||w.type==="Escaped")u+=ce(w.value);else if(w.type==="DoubleQuoted"){let E=await n(e,w.parts);u+=ce(E)}else if(w.type==="ParameterExpansion"){let E=await r(e,w);u+=oe(E,a.greedy,f)}else{let E=await r(e,w);u+=ce(E)}let d=[],h={value:0};for(let w of c)Nt(e,d,Et(e,w,u,a.side,a.greedy),h);let p=ve(e.state.env),m=Oe(e.state.env);if(i){let w=X(e.state.env),E=eo(e,d,w,h.value);return m?{values:E?[E]:[],quoted:!1}:{values:de(E,p,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let y=[],b={value:0};for(let w of d)if(w==="")Nt(e,y,"",b);else for(let E of de(w,p,e.limits.maxArrayElements))Nt(e,y,E,b);return{values:y,quoted:!1}}async function Wc(e,t,n,r){let s=-1,i=!1;for(let E=0;E<t.length;E++){let S=t[E];if(S.type==="ParameterExpansion"&&(S.parameter==="@"||S.parameter==="*")&&S.operation?.type==="Substring"){s=E,i=S.parameter==="*";break}}if(s===-1)return null;let a=t[s].operation,l=a.offset?await n(e,a.offset.expression):0,c=a.length?await n(e,a.length.expression):void 0,u=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let E=1;E<=u;E++)f.push(e.state.env.get(String(E))||"");let d=e.state.env.get("0")||"bash",h;if(l<=0){let E=[d,...f],S=E.length+l;if(S<0)h=[];else{let v=l<0?S:0;if(c!==void 0){let A=c<0?E.length+c:v+c;h=E.slice(v,Math.max(v,A))}else h=E.slice(v)}}else{let E=l-1;if(E>=f.length)h=[];else if(c!==void 0){let S=c<0?f.length+c:E+c;h=f.slice(E,Math.max(E,S))}else h=f.slice(E)}let p="";for(let E=0;E<s;E++)p+=await r(e,t[E]);let m="";for(let E=s+1;E<t.length;E++)m+=await r(e,t[E]);let y=ve(e.state.env),b=Oe(e.state.env);if(h.length===0){let E=p+m;return E?b?{values:[E],quoted:!1}:{values:de(E,y,e.limits.maxArrayElements),quoted:!1}:{values:[],quoted:!1}}let w;if(i){let E=X(e.state.env),S=p+h.join(E)+m;b?w=S?[S]:[]:w=de(S,y,e.limits.maxArrayElements)}else if(b)h.length===1?w=[p+h[0]+m]:w=[p+h[0],...h.slice(1,-1),h[h.length-1]+m];else{w=[];for(let E=0;E<h.length;E++){let S=h[E];if(E===0&&(S=p+S),E===h.length-1&&(S=S+m),S==="")w.push("");else{let v=de(S,y,e.limits.maxArrayElements);De(w,v,e.limits.maxArrayElements,"unquoted expansion")}}}return{values:await ys(e,w),quoted:!1}}async function Vc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let n=t[0].parameter==="*",r=Number.parseInt(e.state.env.get("#")||"0",10);if(r===0)return{values:[],quoted:!1};let s=[];for(let c=1;c<=r;c++)s.push(e.state.env.get(String(c))||"");let i=ve(e.state.env),o=Oe(e.state.env),a=os(e.state.env),l;if(n)if(o)l=s.filter(c=>c!=="");else{let c=X(e.state.env),u=s.join(c);l=de(u,i,e.limits.maxArrayElements)}else if(o)l=s.filter(c=>c!=="");else if(a){l=[];for(let c of s){if(c==="")continue;let u=de(c,i,e.limits.maxArrayElements);De(l,u,e.limits.maxArrayElements,"unquoted expansion")}}else{l=[];for(let c of s)if(c==="")l.push("");else{let u=de(c,i,e.limits.maxArrayElements);De(l,u,e.limits.maxArrayElements,"unquoted expansion")}for(;l.length>0&&l[l.length-1]==="";)l.pop()}return{values:await ys(e,l),quoted:!1}}async function zc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let n=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let r=n[1],s=n[2]==="*",i=K(e,r),o;if(i.length===0){let f=e.state.env.get(r);if(f!==void 0)o=[f];else return{values:[],quoted:!1}}else o=i.map(([,f])=>f);let a=ve(e.state.env),l=Oe(e.state.env),c=os(e.state.env),u;if(s)if(l)u=o.filter(f=>f!=="");else{let f=X(e.state.env),d=o.join(f);u=de(d,a,e.limits.maxArrayElements)}else if(l)u=o.filter(f=>f!=="");else if(c){u=[];for(let f of o){if(f==="")continue;let d=de(f,a,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}}else{u=[];for(let f of o)if(f==="")u.push("");else{let d=de(f,a,e.limits.maxArrayElements);De(u,d,e.limits.maxArrayElements,"unquoted expansion")}for(;u.length>0&&u[u.length-1]==="";)u.pop()}return{values:await ys(e,u),quoted:!1}}function Uc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let n=t[0].operation,r=Un(e,n.prefix);if(r.length===0)return{values:[],quoted:!1};let s=ve(e.state.env),i=Oe(e.state.env),o;if(n.star)if(i)o=r;else{let a=X(e.state.env),l=r.join(a);o=de(l,s,e.limits.maxArrayElements)}else if(i)o=r;else{o=[];for(let a of r){let l=de(a,s,e.limits.maxArrayElements);De(o,l,e.limits.maxArrayElements,"unquoted expansion")}}return{values:o,quoted:!1}}function jc(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let n=t[0].operation,s=K(e,n.array).map(([l])=>String(l));if(s.length===0)return{values:[],quoted:!1};let i=ve(e.state.env),o=Oe(e.state.env),a;if(n.star)if(o)a=s;else{let l=X(e.state.env),c=s.join(l);a=de(c,i,e.limits.maxArrayElements)}else if(o)a=s;else{a=[];for(let l of s){let c=de(l,i,e.limits.maxArrayElements);De(a,c,e.limits.maxArrayElements,"unquoted expansion")}}return{values:a,quoted:!1}}async function qc(e,t,n){let r=-1;for(let d=0;d<t.length;d++){let h=t[d];if(h.type==="ParameterExpansion"&&(h.parameter==="@"||h.parameter==="*")&&!h.operation){r=d;break}}if(r===-1||t.length<=1)return null;let s=Number.parseInt(e.state.env.get("#")||"0",10),i=[];for(let d=1;d<=s;d++)i.push(e.state.env.get(String(d))||"");let o="";for(let d=0;d<r;d++)o+=await n(e,t[d]);let a="";for(let d=r+1;d<t.length;d++)a+=await n(e,t[d]);let l=ve(e.state.env),c=Oe(e.state.env),u=os(e.state.env);if(s===0){let d=o+a;return{values:d?[d]:[],quoted:!1}}let f;{let d=[];for(let h=0;h<i.length;h++){let p=i[h];h===0&&(p=o+p),h===i.length-1&&(p=p+a),d.push(p)}if(c)f=d.filter(h=>h!=="");else if(u){f=[];for(let h of d){if(h==="")continue;let p=de(h,l,e.limits.maxArrayElements);De(f,p,e.limits.maxArrayElements,"unquoted expansion")}}else{f=[];for(let h of d)if(h==="")f.push("");else{let p=de(h,l,e.limits.maxArrayElements);De(f,p,e.limits.maxArrayElements,"unquoted expansion")}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await ys(e,f),quoted:!1}}async function Zc(e,t,n){e.coverage?.hit("bash:expansion:word_glob");let r=t.parts,{hasQuoted:s,hasCommandSub:i,hasArrayVar:o,hasArrayAtExpansion:a,hasParamExpansion:l,hasVarNamePrefixExpansion:c,hasIndirection:u}=gr(r),d=n.hasBraceExpansion(r)?await n.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return Hh(e,d,s);let h=await Zh(e,r,a,c,u,n);if(h!==null)return h;let p=await Kh(e,r,n);if(p!==null)return p;let m=await Xh(e,r,n);if(m!==null)return m;let y=await Jh(e,r,n.expandPart);if(y!==null)return Hc(e,y);if((i||o||l)&&!Oe(e.state.env)){let w=ve(e.state.env),E=n.buildIfsCharClassPattern(w),S=await n.smartWordSplit(e,r,w,E,n.expandPart);return Hc(e,S)}let b=await n.expandWordAsync(e,t);return ep(e,t,r,b,s,n.expandWordForGlobbing)}async function Hh(e,t,n){let r=[];for(let s of t)if(!(!n&&s===""))if(!n&&!e.state.options.noglob&&Ct(s,e.state.shoptOptions.extglob)){let i=await gs(e,s);De(r,i,e.limits.maxArrayElements,"brace/glob expansion")}else r.push(s);return{values:r,quoted:!1}}async function Zh(e,t,n,r,s,i){if(n){let o=$c(e,t);if(o!==null)return o}{let o=Cc(e,t);if(o!==null)return o}{let o=await Ac(e,t);if(o!==null)return o}{let o=await vc(e,t,n,i.expandPart,i.expandWordPartsAsync);if(o!==null)return o}{let o=await kc(e,t,n,i.expandPart);if(o!==null)return o}{let o=await xc(e,t,i.evaluateArithmetic);if(o!==null)return o}{let o=Pc(e,t);if(o!==null)return o}{let o=await bc(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}{let o=await Sc(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let o=Qh(e,t);if(o!==null)return o}{let o=await Nc(e,t,s,i.expandParameterAsync,i.expandWordPartsAsync);if(o!==null)return o}{let o=await Rc(e,t);if(o!==null)return o}{let o=await Oc(e,t);if(o!==null)return o}return null}function Qh(e,t){let n=t[0];if(n.type!=="DoubleQuoted")return null;if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="VarNamePrefix"){let r=n.parts[0].operation,s=Un(e,r.prefix);return r.star?{values:[s.join(X(e.state.env))],quoted:!0}:{values:s,quoted:!0}}if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="ArrayKeys"){let r=n.parts[0].operation,i=K(e,r.array).map(([o])=>String(o));return r.star?{values:[i.join(X(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function Kh(e,t,n){{let r=await Ic(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await _c(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Tc(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Lc(e,t,n.expandPart);if(r!==null)return r}return null}async function Xh(e,t,n){{let r=await Fc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Mc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Bc(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Wc(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await Vc(e,t);if(r!==null)return r}{let r=await zc(e,t);if(r!==null)return r}{let r=Uc(e,t);if(r!==null)return r}{let r=jc(e,t);if(r!==null)return r}{let r=await qc(e,t,n.expandPart);if(r!==null)return r}return null}function Gc(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;t<e.parts.length;t++){let n=e.parts[t];if(n.type!=="ParameterExpansion"||n.operation)continue;let r=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(r)return{type:"array",name:r[1],atIndex:t,isStar:r[2]==="*"};if(n.parameter==="@"||n.parameter==="*")return{type:"positional",atIndex:t,isStar:n.parameter==="*"}}return null}async function Yh(e,t,n,r){let s="";for(let a=0;a<n.atIndex;a++)s+=await r(e,t.parts[a]);let i="";for(let a=n.atIndex+1;a<t.parts.length;a++)i+=await r(e,t.parts[a]);let o;if(n.type==="array"){if(o=K(e,n.name).map(([,l])=>l),o.length===0){let l=e.state.env.get(n.name);l!==void 0&&(o=[l])}}else{let a=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let l=1;l<=a;l++)o.push(e.state.env.get(String(l))||"")}if(n.isStar){let a=X(e.state.env),l=o.join(a);return[s+l+i]}if(o.length===0){let a=s+i;return a?[a]:[]}return o.length===1?[s+o[0]+i]:[s+o[0],...o.slice(1,-1),o[o.length-1]+i]}async function Jh(e,t,n){if(t.length<2)return null;let r=!1;for(let l of t)if(Gc(l)){r=!0;break}if(!r)return null;let s=ve(e.state.env),i=Oe(e.state.env),o=[];for(let l of t){let c=Gc(l);if(c&&l.type==="DoubleQuoted"){let u=await Yh(e,l,c,n);o.push(u)}else if(l.type==="DoubleQuoted"||l.type==="SingleQuoted"){let u=await n(e,l);o.push([u])}else if(l.type==="Literal")o.push([l.value]);else if(l.type==="ParameterExpansion"){let u=await n(e,l);if(i)o.push(u?[u]:[]);else{let f=de(u,s,e.limits.maxArrayElements);o.push(f)}}else{let u=await n(e,l);if(i)o.push(u?[u]:[]);else{let f=de(u,s,e.limits.maxArrayElements);o.push(f)}}}let a=[];for(let l of o)if(l.length!==0)if(a.length===0)De(a,l,e.limits.maxArrayElements,"word expansion");else{let c=a.length-1;a[c]=a[c]+l[0];for(let u=1;u<l.length;u++)a.push(l[u])}return a}async function Hc(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let n=[];for(let r of t)if(Ct(r,e.state.shoptOptions.extglob)){let s=await gs(e,r);De(n,s,e.limits.maxArrayElements,"glob expansion")}else n.push(r);return{values:n,quoted:!1}}async function gs(e,t){let n=new tn(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")}),r=await n.expand(t);if(r.length>0)return r;if(n.hasFailglob())throw new jt(t);return n.hasNullglob()?[]:[t]}async function ep(e,t,n,r,s,i){let o=n.some(a=>a.type==="Glob");if(!e.state.options.noglob&&o){let a=await i(e,t);if(Ct(a,e.state.shoptOptions.extglob)){let c=await gs(e,a);if(c.length>0&&c[0]!==a)return{values:c,quoted:!1};if(c.length===0)return{values:[],quoted:!1}}let l=Zi(r);if(!Oe(e.state.env)){let c=ve(e.state.env);return{values:de(l,c,e.limits.maxArrayElements),quoted:!1}}return{values:[l],quoted:!1}}if(!s&&!e.state.options.noglob&&Ct(r,e.state.shoptOptions.extglob)){let a=await i(e,t);if(Ct(a,e.state.shoptOptions.extglob)){let l=await gs(e,a);if(l.length>0&&l[0]!==a)return{values:l,quoted:!1}}}if(r===""&&!s)return{values:[],quoted:!1};if(o&&!s){let a=Zi(r);if(!Oe(e.state.env)){let l=ve(e.state.env);return{values:de(a,l,e.limits.maxArrayElements),quoted:!1}}return{values:[a],quoted:!1}}return{values:[r],quoted:s}}function Fe(e,t,n){if(t.length>=e.limits.maxArrayElements)throw new C(`word splitting element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");t.push(n)}async function Kc(e,t){let n=t.operation;if(!n||n.type!=="DefaultValue"&&n.type!=="AssignDefault"&&n.type!=="UseAlternative")return null;let r=n.word;if(!r||r.parts.length===0)return null;let s=await $t(e,t.parameter),o=await ie(e,t.parameter,!1)==="",a=n.checkEmpty??!1,l;return n.type==="UseAlternative"?l=s&&!(a&&o):l=!s||a&&o,l?(n.type==="AssignDefault"&&Qi(t.parameter),r.parts):null}function tp(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(n=>n.type==="Literal"):!1}async function np(e,t){if(t.type!=="ParameterExpansion")return null;let n=await Kc(e,t);if(!n||n.length<=1)return null;let r=n.some(i=>tp(i)),s=n.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&s?n:null}function rp(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?Wi(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&Zl(e))}async function Xc(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let d=t[0],h=await Kc(e,d);if(h&&h.length>0&&h.length>1&&h.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&h.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return Qc(e,h,n,r,s)}let i=[],o=!1;for(let d of t){let h=rp(d),p=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=h?await np(e,d):null,y=await s(e,d);i.push({value:y,isSplittable:h,isQuoted:p,mixedDefaultParts:m??void 0}),h&&(o=!0)}if(!o){let d=i.map(h=>h.value).join("");return d?[d]:[]}let a=[],l="",c=!1,u=!1,f=!1;for(let d of i)if(!d.isSplittable)u?d.isQuoted&&d.value===""?(l!==""&&Fe(e,a,l),Fe(e,a,""),c=!0,l="",u=!1,f=!0):d.value!==""?(l!==""&&Fe(e,a,l),l=d.value,u=!1,f=!1):(l+=d.value,f=!1):(l+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let h=await Qc(e,d.mixedDefaultParts,n,r,s);if(h.length!==0)if(h.length===1)l+=h[0],c=!0;else{l+=h[0],Fe(e,a,l),c=!0;for(let p=1;p<h.length-1;p++)Fe(e,a,h[p]);l=h[h.length-1]}u=!1,f=!1}else{let{words:h,hadLeadingDelimiter:p,hadTrailingDelimiter:m}=as(d.value,n,e.limits.maxArrayElements);if(f&&p&&l===""&&(Fe(e,a,""),c=!0),h.length===0)m&&(u=!0);else if(h.length===1)l+=h[0],c=!0,u=m;else{l+=h[0],Fe(e,a,l),c=!0;for(let y=1;y<h.length-1;y++)Fe(e,a,h[y]);l=h[h.length-1],u=m}f=!1}return l!==""?Fe(e,a,l):a.length===0&&c&&Fe(e,a,""),a}function sp(e,t){return e.length>0&&t.includes(e[0])}async function Qc(e,t,n,r,s){let i=[];for(let u of t){let d=!(u.type==="DoubleQuoted"||u.type==="SingleQuoted"),h=await s(e,u);i.push({value:h,isSplittable:d})}let o=[],a="",l=!1,c=!1;for(let u of i)if(!u.isSplittable)c&&u.value!==""?(a!==""&&Fe(e,o,a),a=u.value,c=!1):a+=u.value;else{sp(u.value,n)&&a!==""&&(Fe(e,o,a),a="",l=!0);let{words:d,hadTrailingDelimiter:h}=as(u.value,n,e.limits.maxArrayElements);if(d.length===0)h&&(c=!0);else if(d.length===1)a+=d[0],l=!0,c=h;else{a+=d[0],Fe(e,o,a),l=!0;for(let p=1;p<d.length-1;p++)Fe(e,o,d[p]);a=d[d.length-1],c=h}}return a!==""?Fe(e,o,a):o.length===0&&l&&Fe(e,o,""),o}function Yc(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Jc(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}var ws="/dev/fd",tu=63,ip=10,eu=tu-ip+1,to=class extends yt{isLiveDescriptor;constructor(t){super(),this.isLiveDescriptor=t}assertLiveDescriptor(t,n){this.isLiveDescriptor(t)||this.refuse(t,n)}refuse(t,n){throw new Error(`EROFS: read-only file system, ${n} '${ws}${t}'`)}async writeFile(t,n,r){return this.assertLiveDescriptor(t,"write"),super.writeFile(t,n,r)}async appendFile(t,n,r){return this.assertLiveDescriptor(t,"append"),super.appendFile(t,n,r)}async rm(t,n){return this.assertLiveDescriptor(t,"rm"),super.rm(t,n)}async mkdir(t,n){this.refuse(t,"mkdir")}async cp(t,n){this.refuse(n,"cp")}async mv(t,n){this.refuse(n,"mv")}async symlink(t,n){this.refuse(n,"symlink")}async link(t,n){this.refuse(n,"link")}async chmod(t,n){this.refuse(t,"chmod")}async utimes(t,n,r){this.refuse(t,"utimes")}};function op(e){let t=new to(n=>nu(e).some(r=>r.path===`${ws}${n}`));e.fs=new Kt({base:e.fs,mounts:[{mountPoint:ws,filesystem:t}]}),e.state.processSubstitutionFsMounted=!0}async function ap(e,t,n){try{await e.fs.writeFile(t,n,"binary");return}catch(r){if(e.state.processSubstitutionFsMounted)throw r;op(e)}await e.fs.writeFile(t,n,"binary")}async function lp(e,t){try{await e.fs.rm(t,{force:!0})}catch{}}function nu(e){let t=e.state.processSubstitutions;if(t)return t;let n=[];return e.state.processSubstitutions=n,n}async function ru(e,t,n){let r=e.substitutionDepth??0,s=e.limits.maxSubstitutionDepth;if(r>=s)throw new C(`Process substitution nesting limit exceeded (${s})`,"substitution_depth");let i=e.substitutionDepth,o=new Map(e.state.env),a=ot(e.state.arrays),l=e.state.cwd,c=e.state.bashPid,u=e.state.suppressVerbose,f=e.state.groupStdin,d=e.state.lastExitCode,h=e.state.env.get("?"),p=e.state.lastSubstitutionExitCode;e.substitutionDepth=r+1,e.state.bashPid=e.state.nextVirtualPid++,e.state.suppressVerbose=!0,n!==void 0&&(e.state.groupStdin=n);let m;try{m=await e.executeScript(t)}catch(y){if(y instanceof C)throw y;if(y instanceof G)return{stdout:y.stdout,stderr:y.stderr,exitCode:y.exitCode};throw y}finally{e.substitutionDepth=i,e.state.env=o,e.state.arrays=a,e.state.cwd=l,e.state.bashPid=c,e.state.suppressVerbose=u,e.state.groupStdin=f,e.state.lastExitCode=d,e.state.lastSubstitutionExitCode=p,h!==void 0?e.state.env.set("?",h):e.state.env.delete("?")}return m}async function su(e,t){let n=nu(e);if(n.length>=eu)throw new C(`Process substitution limit exceeded (${eu} concurrent)`,"file_descriptors");let r="";if(t.direction==="input"){let o=await ru(e,t.body,void 0);if(o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),r=_t(o),r.length>e.limits.maxStringLength)throw new C(`process substitution: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")}let s=tu-n.length,i=`${ws}/${s}`;n.push({fd:s,path:i,direction:t.direction,body:t.body});try{await ap(e,i,r)}catch(o){throw n.pop(),o}return i}function iu(e){return e.state.processSubstitutions?.length??0}var cp={stdout:"",stderr:""};async function no(e,t){let n=e.state.processSubstitutions;if(!n||n.length<=t)return cp;let r="",s="";for(;n.length>t;){let i=n[n.length-1],o="";if(i.direction==="output")try{o=await _n(e.fs,i.path)}catch{}if(await lp(e,i.path),n.pop(),i.direction==="output"){let a=await ru(e,i.body,o);r+=_t(a),s+=a.stderr}}return{stdout:r,stderr:s}}function ln(e,t,n){if(e.length>t)throw new C(`${n}: string length limit exceeded (${t} bytes)`,"string_length")}async function St(e,t,n=!1){let r=[],s=0;for(let i of t){let o=await tt(e,i,n);if(s+=V(o),s>e.limits.maxStringLength)throw new C(`parameter word string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");r.push(o)}return r.join("")}function up(e){return Jc(e)}function au(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!up(t))return!1;return!0}function fp(e,t,n=!1){let r=Yc(t);if(r!==null)return r;switch(t.type){case"TildeExpansion":return n?t.user===null?"~":`~${t.user}`:(e.coverage?.hit("bash:expansion:tilde"),t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`);case"Glob":return Xi(e,t.pattern);default:return null}}async function se(e,t){return so(e,t)}async function lu(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped")n.push(zn(r.value));else if(r.type==="SingleQuoted")n.push(r.value);else if(r.type==="DoubleQuoted"){let s=await St(e,r.parts);n.push(s)}else if(r.type==="TildeExpansion"){let s=await tt(e,r);n.push(zn(s))}else n.push(await tt(e,r));return n.join("")}async function cu(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped"){let s=r.value;"()|*?[]".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="SingleQuoted")n.push(et(r.value));else if(r.type==="DoubleQuoted"){let s=await St(e,r.parts);n.push(et(s))}else n.push(await tt(e,r));return n.join("")}async function uu(e,t){let n=[];for(let r of t.parts)if(r.type==="SingleQuoted")n.push(et(r.value));else if(r.type==="Escaped"){let s=r.value;"*?[]\\()|".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="DoubleQuoted"){let s=await St(e,r.parts);n.push(et(s))}else r.type==="Glob"?gc(r.pattern)?n.push(await Ec(e,r.pattern)):n.push(Xi(e,r.pattern)):r.type==="Literal"?n.push(r.value):n.push(await tt(e,r));return n.join("")}function bs(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&bs(t.parts))return!0;return!1}var ou=1e5;async function fu(e,t,n={count:0}){let r=()=>{n.count++,e.executionScope.consumeLimited("brace_operations",1,Math.min(ou,e.limits.maxBraceExpansionResults),"brace expansion")},s=(o,a)=>{if(o.length>=e.limits.maxBraceExpansionResults)throw new C(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),o.push(a)},i=[[]];for(let o of t)if(o.type==="BraceExpansion"){let a=[],l=!1,c="";for(let d of o.items)if(d.type==="Range"){let h=Hi(d.start,d.end,d.step,d.startStr,d.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(h.expanded)for(let p of h.expanded)s(a,p);else{l=!0,c=h.literal;break}}else{let h=await fu(e,d.word.parts,n);for(let p of h){let m=[];for(let y of p)typeof y=="string"?m.push(y):m.push(await tt(e,y));s(a,m.join(""))}}if(l){for(let d of i)r(),d.push(c);continue}if(i.length*a.length>e.limits.maxBraceExpansionResults||n.count>ou)throw new C(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");let f=[];for(let d of i)for(let h of a){if(f.length>=e.limits.maxBraceExpansionResults)throw new C(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),f.push([...d,h])}i=f}else for(let a of i)r(),a.push(o);return i}async function du(e,t){let n=t.parts;if(!bs(n))return[await se(e,t)];let r=await fu(e,n),s=[];for(let i of r){let o=[];for(let a of i)typeof a=="string"?o.push(a):o.push(await tt(e,a));s.push(Yi(e,o.join("")))}return s}function dp(){return{expandWordAsync:so,expandWordForGlobbing:uu,expandWordWithBracesAsync:du,expandWordPartsAsync:St,expandPart:tt,expandParameterAsync:Es,hasBraceExpansion:bs,evaluateArithmetic:J,buildIfsCharClassPattern:Ql,smartWordSplit:Xc}}async function At(e,t){return Zc(e,t,dp())}function hp(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function ro(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function r(s){for(let i of s)if(i.type==="DoubleQuoted"){for(let o of i.parts)if(o.type==="ParameterExpansion"&&o.parameter==="@"&&!o.operation)return!0}return!1}return r(t.parts)}async function hu(e,t){if(ro(e,t))return{error:`bash: $@: ambiguous redirect
|
|
112
|
+
`};let n=t.parts,{hasQuoted:r}=gr(n);if(bs(n)&&(await du(e,t)).length>1)return{error:`bash: ${n.map(h=>h.type==="Literal"?h.value:h.type==="BraceExpansion"?`{${h.items.map(m=>{if(m.type==="Range"){let y=m.step?`..${m.step}`:"";return`${m.startStr??m.start}..${m.endStr??m.end}${y}`}return m.word.parts.map(y=>y.type==="Literal"?y.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect
|
|
113
|
+
`};let s=await so(e,t),{hasParamExpansion:i,hasCommandSub:o}=gr(n);if((i||o)&&!r&&!Oe(e.state.env)){let f=ve(e.state.env);if(de(s,f,e.limits.maxArrayElements).length>1)return{error:`bash: $${hp(n)}: ambiguous redirect
|
|
114
|
+
`}}if(r||e.state.options.noglob||n.some(f=>f.type==="ProcessSubstitution"))return{target:s};let l=await uu(e,t);if(!Ct(l,e.state.shoptOptions.extglob))return{target:s};let c=new tn(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")}),u=await c.expand(l);return u.length===0?c.hasFailglob()?{error:`bash: no match: ${s}
|
|
115
115
|
`}:{target:s}:u.length===1?{target:u[0]}:{error:`bash: ${s}: ambiguous redirect
|
|
116
|
-
`}}async function
|
|
116
|
+
`}}async function so(e,t){let n=t.parts,r=n.length;if(r===1){let o=await tt(e,n[0]);return ln(o,e.limits.maxStringLength,"word expansion"),o}let s=[];for(let o=0;o<r;o++)s.push(await tt(e,n[o]));let i=s.join("");return ln(i,e.limits.maxStringLength,"word expansion"),i}async function tt(e,t,n=!1){if(t.type==="ParameterExpansion")return Es(e,t,n);let r=fp(e,t,n);if(r!==null)return r;switch(t.type){case"DoubleQuoted":{let s=[];for(let i of t.parts)s.push(await tt(e,i,!0));return s.join("")}case"CommandSubstitution":{let s=nc(t.body);if(s)try{let h=await se(e,s.target),p=h.startsWith("/")?h:`${e.state.cwd}/${h}`,m=await e.fs.readFile(p);on(e.state,0);let y=m.replace(/\n+$/,"");return ln(y,e.limits.maxStringLength,"command substitution"),y}catch(h){if(h instanceof C)throw h;return on(e.state,1),""}let i=e.substitutionDepth??0,o=e.limits.maxSubstitutionDepth;if(i>=o)throw new C(`Command substitution nesting limit exceeded (${o})`,"substitution_depth");let a=e.substitutionDepth;e.substitutionDepth=i+1;let l=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let c=new Map(e.state.env),u=ot(e.state.arrays),f=e.state.cwd,d=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let h=await e.executeScript(t.body),p=h.exitCode;e.state.env=c,e.state.arrays=u,e.state.cwd=f,e.state.suppressVerbose=d,on(e.state,p),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr),e.state.bashPid=l,e.substitutionDepth=a;let m=h.stdout.replace(/\n+$/,"");return ln(m,e.limits.maxStringLength,"command substitution"),m}catch(h){if(e.state.env=c,e.state.arrays=u,e.state.cwd=f,e.state.bashPid=l,e.substitutionDepth=a,e.state.suppressVerbose=d,h instanceof C)throw h;if(h instanceof G){on(e.state,h.exitCode),h.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+h.stderr);let p=h.stdout.replace(/\n+$/,"");return ln(p,e.limits.maxStringLength,"command substitution"),p}throw h}}case"ProcessSubstitution":return su(e,t);case"ArithmeticExpansion":{let s=t.expression.originalText;if(s&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(s)){let o=await tc(e,s),a=new Q,l=re(a,o);return String(await J(e,l.expression,!0))}return String(await J(e,t.expression.expression,!0))}case"BraceExpansion":{let s=[];for(let i of t.items)if(i.type==="Range"){let o=Hi(i.start,i.end,i.step,i.startStr,i.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(o.expanded)s.push(...o.expanded);else return o.literal}else s.push(await se(e,i.word));return s.join(" ")}default:return""}}async function Es(e,t,n=!1){let{parameter:r}=t,{operation:s}=t,i=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(i){let[,d,h]=i;if(e.state.associativeArrays?.has(d)||h.includes("$(")||h.includes("`")||h.includes("${")){let m=await qi(e,h);r=`${d}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ue(e,r)){let d=Be(e,r);if(d&&d!==r){let h=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(h){let[,p,m]=h;if(e.state.associativeArrays?.has(p)||m.includes("$(")||m.includes("`")||m.includes("${")){let b=await qi(e,m);r=`${p}[${b}]`}}}}if(s?.type==="Length"&&/^[a-zA-Z_][a-zA-Z0-9_]*\[[@*]\]$/.test(r))return Ki(e,r,"");let o=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),a=await ie(e,r,!o);if(!s)return a;let l=!await $t(e,r),{isEmpty:c,effectiveValue:u}=yc(e,r,a,n),f={value:a,isUnset:l,isEmpty:c,effectiveValue:u,inDoubleQuotes:n};switch(s.type){case"DefaultValue":return sc(e,s,f,St);case"AssignDefault":return ic(e,r,s,f,St);case"ErrorIfUnset":return oc(e,r,s,f,St);case"UseAlternative":return ac(e,s,f,St);case"PatternRemoval":{let d=await lc(e,a,s,St,tt);return ln(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await cc(e,a,s,St,tt);return ln(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return Ki(e,r,a);case"LengthSliceError":throw new Xe(r);case"BadSubstitution":throw new Xe(s.text);case"Substring":return uc(e,r,a,s);case"CaseModification":{let d=await fc(e,a,s,St,Es);return ln(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return dc(e,r,a,l,s);case"Indirection":return hc(e,r,a,l,s,Es,n);case"ArrayKeys":return pc(e,s);case"VarNamePrefix":return mc(e,s);default:return a}}function mu(){return{visited:new Set,depth:0}}function pp(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new le("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new le("division by 0");return e%t;case"**":if(t<0)throw new le("exponent less than 0");return e**t;case"<<":return e<<t;case">>":return e>>t;case"<":return e<t?1:0;case"<=":return e<=t?1:0;case">":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function pu(e,t,n){switch(n){case"=":return t;case"+=":return e+t;case"-=":return e-t;case"*=":return e*t;case"/=":return t!==0?Math.trunc(e/t):0;case"%=":return t!==0?e%t:0;case"<<=":return e<<t;case">>=":return e>>t;case"&=":return e&t;case"|=":return e|t;case"^=":return e^t;default:return t}}function mp(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function yp(e,t){let n=e.state.env.get(t);if(n!==void 0)return n;let r=ae(e,t,0);return r!==void 0?r:await ie(e,t)}async function gp(e,t,n){if(!t)return 0;let r=Number.parseInt(t,10);if(!Number.isNaN(r)&&/^-?\d+$/.test(t.trim()))return r;let s=t.trim();if(!s)return 0;let i=new Q,{expr:o,pos:a}=Vn(i,s,0);if(a<s.length){let l=s.slice(a).trim(),c=l.split(/\s+/)[0]||l;throw new le(`syntax error in expression (error token is "${c}")`,"","")}return await qn(e,o,!1,n)}async function Ss(e,t,n,r){if(r.depth>100)throw new le("maximum variable indirection depth exceeded");if(r.visited.has(t))throw new le(`arithmetic variable cycle detected at ${t}`);r.visited.add(t),r.depth++;try{return await gp(e,n,r)}finally{r.depth--,r.visited.delete(t)}}async function io(e,t,n){if(n.depth>100)throw new le("maximum variable indirection depth exceeded");if(n.visited.has(t))throw new le(`arithmetic variable cycle detected at ${t}`);n.visited.add(t),n.depth++;try{let r=await yp(e,t);if(!r)return 0;let s=Number.parseInt(r,10);if(!Number.isNaN(s)&&/^-?\d+$/.test(r.trim()))return s;let i=r.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return await io(e,i,n);let o=new Q,{expr:a,pos:l}=Vn(o,i,0);if(l<i.length){let c=i.slice(l).trim(),u=c.split(/\s+/)[0]||c;throw new le(`${i}: syntax error in expression (error token is "${u}")`)}return await qn(e,a,!1,n)}finally{n.depth--,n.visited.delete(t)}}async function As(e,t){if(t.startsWith("#")){let f=t.slice(1),d=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(d){let p=d[1],m=K(e,p);return String(m.length)}let h=e.state.env.get(f)||"";return String(h.length)}if(t.startsWith("!")){let f=t.slice(1),d=e.state.env.get(f)||"";return e.state.env.get(d)||""}let n=[":-",":=",":?",":+","-","=","?","+"],r=-1,s="";for(let f of n){let d=t.indexOf(f);d>0&&(r===-1||d<r)&&(r=d,s=f)}if(r===-1)return await ie(e,t);let i=t.slice(0,r),o=t.slice(r+s.length),a=e.state.env.get(i),l=a===void 0,c=a==="",u=s.startsWith(":");switch(s){case":-":case"-":return l||u&&c?o:a||"";case":=":case"=":return l||u&&c?(e.state.env.set(i,o),o):a||"";case":+":case"+":return!(l||u&&c)?o:"";case":?":case"?":{if(l||u&&c)throw new Error(o||`${i}: parameter null or not set`);return a||""}default:return a||""}}async function J(e,t,n=!1){return qn(e,t,n,mu())}async function qn(e,t,n,r){let s=(i,o=n)=>qn(e,i,o,r);switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new le("value too great for base");return t.value;case"ArithVariable":return await io(e,t.name,r);case"ArithSpecialVar":{let o=(await ie(e,t.name)).trim();if(!o)return 0;let a=Number.parseInt(o,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(o))return a;let l=new Q,{expr:c}=Vn(l,o,0);return await s(c)}case"ArithNested":return await s(t.expression);case"ArithCommandSubst":{if(e.execFn){let i=await e.execFn(t.command,{signal:e.state.signal});i.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+i.stderr);let o=i.stdout.trim();return Number.parseInt(o,10)||0}return 0}case"ArithBracedExpansion":{let i=await As(e,t.content);return Number.parseInt(i,10)||0}case"ArithDynamicBase":{let i=await As(e,t.baseExpr),o=Number.parseInt(i,10);if(o<2||o>64)return 0;let a=`${o}#${t.value}`;return dr(a)}case"ArithDynamicNumber":{let o=await As(e,t.prefix)+t.suffix;return dr(o)}case"ArithArrayElement":{let i=e.state.associativeArrays?.has(t.array),o=async a=>{let l=ae(e,t.array,a);return l!==void 0?await Ss(e,`${t.array}[${a}]`,l,r):0};if(t.stringKey!==void 0)return await o(t.stringKey);if(i&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await o(t.index.name);if(i&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let a=await ie(e,t.index.name);return await o(a)}if(t.index){let a=await s(t.index);if(a<0){let u=K(e,t.array),f=e.state.currentLine;if(u.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
|
|
117
117
|
`,0;let h=Math.max(...u.map(([p])=>typeof p=="number"?p:0))+1+a;if(h<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
|
|
118
|
-
`,0;a=h}let l=`${t.array}[${a}]`,c=ae(e,t.array,a);if(c!==void 0)return
|
|
119
|
-
`);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new
|
|
120
|
-
`);n=r}throw new Qe(n)}async function
|
|
121
|
-
`)}catch{return
|
|
122
|
-
`)}
|
|
123
|
-
|
|
118
|
+
`,0;a=h}let l=`${t.array}[${a}]`,c=ae(e,t.array,a);if(c!==void 0)return Ss(e,l,c,r);if(a===0){let u=e.state.env.get(t.array);if(u!==void 0)return Ss(e,t.array,u,r)}if(e.state.options.nounset&&!(e.state.env.has(t.array)||Ne(e,t.array)))throw new ze(`${t.array}[${a}]`);return 0}return 0}case"ArithDoubleSubscript":throw new le("double subscript","","");case"ArithNumberSubscript":throw new le(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new le(t.message,"","",!0);case"ArithSingleQuote":{if(n)throw new le(`syntax error: operand expected (error token is "'${t.content}'")`);return t.value}case"ArithBinary":{if(t.operator==="||")return await s(t.left)||await s(t.right)?1:0;if(t.operator==="&&")return await s(t.left)&&await s(t.right)?1:0;let i=await s(t.left),o=await s(t.right);return pp(i,o,t.operator)}case"ArithUnary":{let i=await s(t.operand);if(t.operator==="++"||t.operator==="--"){if(t.operand.type==="ArithVariable"){let o=t.operand.name,a=Number.parseInt(await ie(e,o),10)||0,l=t.operator==="++"?a+1:a-1;return e.state.env.set(o,String(l)),t.prefix?l:a}if(t.operand.type==="ArithArrayElement"){let o=t.operand.array,a=e.state.associativeArrays?.has(o),l;if(t.operand.stringKey!==void 0)l=t.operand.stringKey;else if(a&&t.operand.index?.type==="ArithVariable"&&!t.operand.index.hasDollarPrefix)l=t.operand.index.name;else if(a&&t.operand.index?.type==="ArithVariable"&&t.operand.index.hasDollarPrefix)l=await ie(e,t.operand.index.name);else if(t.operand.index){let f=await s(t.operand.index);l=String(f)}else return i;let c=Number.parseInt(ae(e,o,l)||"0",10)||0,u=t.operator==="++"?c+1:c-1;return H(e,o,l,String(u),a?"associative":"indexed"),t.prefix?u:c}if(t.operand.type==="ArithConcat"){let o="";for(let a of t.operand.parts)o+=await jn(e,a,n,r);if(o&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){let a=Number.parseInt(e.state.env.get(o)||"0",10)||0,l=t.operator==="++"?a+1:a-1;return e.state.env.set(o,String(l)),t.prefix?l:a}}if(t.operand.type==="ArithDynamicElement"){let o="";if(t.operand.nameExpr.type==="ArithConcat")for(let a of t.operand.nameExpr.parts)o+=await jn(e,a,n,r);else t.operand.nameExpr.type==="ArithVariable"&&(o=t.operand.nameExpr.hasDollarPrefix?await ie(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(o&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){let a=await s(t.operand.subscript),l=Number.parseInt(ae(e,o,a)||"0",10)||0,c=t.operator==="++"?l+1:l-1;return H(e,o,a,String(c)),t.prefix?c:l}}return i}return mp(i,t.operator)}case"ArithTernary":return await s(t.condition)?await s(t.consequent):await s(t.alternate);case"ArithAssignment":{let i=t.variable,o=i,a;if(t.stringKey!==void 0)a=t.stringKey;else if(t.subscript){let d=e.state.associativeArrays?.has(i);if(d&&t.subscript.type==="ArithVariable"&&!t.subscript.hasDollarPrefix)a=t.subscript.name;else if(d&&t.subscript.type==="ArithVariable"&&t.subscript.hasDollarPrefix)a=await ie(e,t.subscript.name)||"\\";else if(d){let h=await s(t.subscript);a=String(h)}else{let h=await s(t.subscript);if(h<0){let p=K(e,i);p.length>0&&(h=Math.max(...p.map(([y])=>typeof y=="number"?y:0))+1+h)}a=String(h)}}let l=a===void 0?e.state.env.get(o):ae(e,i,a),c=Number.parseInt(l||"0",10)||0,u=await s(t.value),f=pu(c,u,t.operator);return a===void 0?e.state.env.set(o,String(f)):H(e,i,a,String(f),e.state.associativeArrays?.has(i)?"associative":"indexed"),f}case"ArithGroup":return await s(t.expression);case"ArithConcat":{let i="";for(let o of t.parts)i+=await jn(e,o,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)?await io(e,i,r):Number.parseInt(i,10)||0}case"ArithDynamicAssignment":{let i="";if(t.target.type==="ArithConcat")for(let u of t.target.parts)i+=await jn(e,u,n,r);else t.target.type==="ArithVariable"&&(i=t.target.hasDollarPrefix?await ie(e,t.target.name):t.target.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let o=i;if(t.subscript){let u=await s(t.subscript);o=`${i}_${u}`}let a=Number.parseInt(e.state.env.get(o)||"0",10)||0,l=await s(t.value),c=pu(a,l,t.operator);return e.state.env.set(o,String(c)),c}case"ArithDynamicElement":{let i="";if(t.nameExpr.type==="ArithConcat")for(let c of t.nameExpr.parts)i+=await jn(e,c,n,r);else t.nameExpr.type==="ArithVariable"&&(i=t.nameExpr.hasDollarPrefix?await ie(e,t.nameExpr.name):t.nameExpr.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let o=await s(t.subscript),a=`${i}_${o}`,l=e.state.env.get(a);return l!==void 0?Ss(e,a,l,r):0}default:return 0}}async function jn(e,t,n=!1,r=mu()){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await qn(e,t,n,r));case"ArithVariable":return t.hasDollarPrefix?await ie(e,t.name):t.name;case"ArithSpecialVar":return await ie(e,t.name);case"ArithBracedExpansion":return await As(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command,{signal:e.state.signal})).stdout.trim():"0";case"ArithConcat":{let s="";for(let i of t.parts)s+=await jn(e,i,n,r);return s}default:return String(await qn(e,t,n,r))}}async function yu(e,t){let n="",r=0;for(let A of t.parts){let k=A.type==="Literal"?A.value:"\0",x=V(k);if(x>e.limits.maxStringLength-r)throw new C(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n+=k,r+=x}let s=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(\+?=)\(/);if(!s||!n.endsWith(")"))return null;let i=s[1],o=s[2],a=[],l=[],c=!1,u="",f=0,d=0,h=!1,p=!0,m=A=>{let k=V(A);if(k>e.limits.maxStringLength-d-f)throw new C(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");u+=A,f+=k},y=(A,k=!1)=>{if(a.length>=e.limits.maxArrayElements)throw new C(`array assignment element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let x=V(A);if(x>e.limits.maxStringLength-d)throw new C(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");a.push(A),l.push(k),d+=x},b=()=>{y(u,p),u="",f=0,h=!1,p=!0};for(let A of t.parts)if(A.type==="Literal"){let k=A.value;if(!c){let x=k.indexOf("=(");x!==-1&&(c=!0,k=k.slice(x+2))}if(c){k.endsWith(")")&&(k=k.slice(0,-1));for(let x of k)/\s/.test(x)?(u||h)&&b():m(x)}}else if(c)if(A.type==="BraceExpansion")if(/^\[.+\]=/.test(u))m(Bn({type:"Word",parts:[A]}));else{(u||h)&&b();let x=await At(e,{type:"Word",parts:[A]});for(let D of x.values)y(D)}else{(A.type==="SingleQuoted"||A.type==="DoubleQuoted"||A.type==="Escaped")&&(h=!0),p=!1;let k=await se(e,{type:"Word",parts:[A]});m(k)}(u||h)&&b();let w=a.splice(0),E=l.splice(0);d=0;for(let A=0;A<w.length;A++){let k=w[A];if(!E[A]){y(k);continue}let x=k.match(/^(\[[^\]]+\]=)(.*)$/s);if(x){let D=an(e,x[2]);k=x[1]+D}if(k.includes("{")&&k.includes("}")){let D=new Q().parseWordFromString(k,!1,!1);if(D.parts.some($=>$.type==="BraceExpansion")){let $=await At(e,D);for(let N of $.values)y(N);continue}}y(k)}let S=[`${i}${o}(`],v=V(S[0]);for(let A=0;A<a.length;A++){let k=a[A],x,D=k.match(/^(\[[^\]]+\]=)(.*)$/s);if(D){let O=D[2].replace(/\\/g,"\\\\").replace(/"/g,'\\"');x=`${D[1]}"${O}"`}else k===""?x="''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(k)&&!k.startsWith("'")&&!k.startsWith('"')?x=`'${k.replace(/'/g,"'\\''")}'`:x=k;let $=`${A>0?" ":""}${x}`,N=V($);if(N+1>e.limits.maxStringLength-v)throw new C(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");S.push($),v+=N}return S.push(")"),S.join("")}async function gu(e,t){let n=-1,r=-1,s=!1;for(let m=0;m<t.parts.length;m++){let y=t.parts[m];if(y.type==="Literal"){let b=y.value.indexOf("+=");if(b!==-1){let E=y.value.slice(0,b);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(E)){n=m,r=b,s=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(E)){n=m,r=b,s=!0;break}}let w=y.value.indexOf("=");if(w!==-1&&(w===0||y.value[w-1]!=="+")){let E=y.value.slice(0,w);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(E)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(E)){n=m,r=w;break}}}}if(n===-1)return null;let i=t.parts.slice(0,n),o=t.parts[n];if(o.type!=="Literal")return null;let a=s?2:1,l=o.value.slice(0,r),c=o.value.slice(r+a),u=t.parts.slice(n+1),f="";for(let m of i)f+=await se(e,{type:"Word",parts:[m]});f+=l;let d={type:"Word",parts:c!==""?[{type:"Literal",value:c},...u]:u},h=d.parts.length>0?await se(e,d):"";return`${f}${s?"+=":"="}${h}`}var wp=["tar","yq","xan","sqlite3","python3","python"];function wu(e){return wp.includes(e)}var te=Object.freeze({stdout:"",stderr:"",exitCode:0,internalStdinConsumed:0});function ee(e=""){return{stdout:e,stderr:"",exitCode:0}}function L(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function F(e,t,n){return{stdout:e,stderr:t,exitCode:n}}function be(e){return{stdout:"",stderr:"",exitCode:e?0:1,internalStdinConsumed:0}}function cn(e,t,n="",r=""){throw new C(e,t,n,r)}function Eu(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new C(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function oo(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new qt;return te}if(t.length>1)throw new G(1,"",`bash: break: too many arguments
|
|
119
|
+
`);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new G(128,"",`bash: break: ${t[0]}: numeric argument required
|
|
120
|
+
`);n=r}throw new Qe(n)}async function ao(e,t){let n,r=!1,s=!1,i=0;for(;i<t.length;)if(t[i]==="--"){i++;break}else if(t[i]==="-L")s=!1,i++;else if(t[i]==="-P")s=!0,i++;else if(t[i].startsWith("-")&&t[i]!=="-")i++;else break;let o=t.slice(i);if(o.length===0)n=e.state.env.get("HOME")||"/";else if(o[0]==="~")n=e.state.env.get("HOME")||"/";else if(o[0]==="-"){let f=e.state.env.get("OLDPWD");if(f===void 0)return L(`bash: cd: OLDPWD not set
|
|
121
|
+
`);n=f,r=!0}else n=o[0];if(n!==""&&!n.startsWith("/")&&!n.startsWith("./")&&!n.startsWith("../")&&n!=="."&&n!==".."){let f=e.state.env.get("CDPATH");if(f){let d=f.split(":").filter(h=>h);for(let h of d){let p=h.startsWith("/")?`${h}/${n}`:`${e.state.cwd}/${h}/${n}`;try{if((await e.fs.stat(p)).isDirectory){n=p,r=!0;break}}catch{}}}}let l=(n.startsWith("/")?n:`${e.state.cwd}/${n}`).split("/").filter(f=>f&&f!=="."),c="";for(let f of l)if(f==="..")c=c.split("/").slice(0,-1).join("/")||"/";else{c=c?`${c}/${f}`:`/${f}`;try{if(!(await e.fs.stat(c)).isDirectory)return L(`bash: cd: ${n}: Not a directory
|
|
122
|
+
`)}catch{return L(`bash: cd: ${n}: No such file or directory
|
|
123
|
+
`)}}let u=c||"/";if(s)try{u=await e.fs.realpath(u)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=u,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),ee(r?`${n===""?"":u}
|
|
124
|
+
`:"")}function lo(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Ep=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function vs(e){return Ep.includes(e)}async function ks(e,t,n){let r=lo(e,n);switch(t){case"-e":case"-a":return e.fs.exists(r);case"-f":return await e.fs.exists(r)?(await e.fs.stat(r)).isFile:!1;case"-d":return await e.fs.exists(r)?(await e.fs.stat(r)).isDirectory:!1;case"-r":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&256)!==0:!1;case"-w":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&128)!==0:!1;case"-x":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&64)!==0:!1;case"-s":return await e.fs.exists(r)?(await e.fs.stat(r)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(r)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&512)!==0:!1;case"-g":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(r);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].includes(r);case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(r);default:return!1}}var bp=["-nt","-ot","-ef"];function xs(e){return bp.includes(e)}async function Ps(e,t,n,r){let s=lo(e,n),i=lo(e,r);switch(t){case"-nt":{let[o,a]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return o!==null&&(a===null||o.mtime>a.mtime)}case"-ot":{let[o,a]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return a!==null&&(o===null||o.mtime<a.mtime)}case"-ef":try{let[o,a]=await Promise.all([e.fs.realpath(s),e.fs.realpath(i)]);if(o===a)return!0;let[l,c]=await Promise.all([e.fs.stat(s),e.fs.stat(i)]);return l.dev!==void 0&&l.ino!==void 0&&c.dev!==void 0&&c.ino!==void 0?l.dev===c.dev&&l.ino===c.ino:l.identity&&c.identity?l.identity===c.identity:!1}catch{return!1}default:return!1}}var Sp=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function $s(e){return Sp.has(e)}function Cs(e,t,n){switch(e){case"-eq":return t===n;case"-ne":return t!==n;case"-lt":return t<n;case"-le":return t<=n;case"-gt":return t>n;case"-ge":return t>=n}}function br(e){return e==="="||e==="=="||e==="!="}function Ns(e,t,n,r=!1,s=!1,i=!1,o=256){if(r){let l=Gn(t,n,s,i,o);return e==="!="?!l:l}if(s){let l=t.toLowerCase()===n.toLowerCase();return e==="!="?!l:l}let a=t===n;return e==="!="?!a:a}var Ap=new Set(["-z","-n"]);function Rs(e){return Ap.has(e)}function Os(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Ds(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let r=n[1],s=n[2];if(e.state.associativeArrays?.has(r)){let a=s;return(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1)),a=a.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(l,c)=>e.state.env.get(c)||""),Yt(e,r,a)}let o;try{let a=new Q,l=re(a,s);o=await J(e,l.expression)}catch{if(/^-?\d+$/.test(s))o=Number.parseInt(s,10);else{let a=e.state.env.get(s);o=a?Number.parseInt(a,10):0}}if(o<0){let a=Ae(e,r),l=e.state.currentLine;if(a.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
|
|
124
125
|
`,!1;if(o=Math.max(...a)+1+o,o<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
|
|
125
|
-
`,!1}return Yt(e,r,o)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?xt(e,t).length>0:
|
|
126
|
-
`,2):
|
|
127
|
-
`,2):
|
|
128
|
-
`,2):be(n.value)}async function
|
|
129
|
-
`)&&!s&&!i){a&&(
|
|
126
|
+
`,!1}return Yt(e,r,o)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?xt(e,t).length>0:Ae(e,t).length>0}async function un(e,t){switch(t.type){case"CondBinary":{let n=await se(e,t.left),r=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),s;if(t.operator==="=~")if(r){let i=await se(e,t.right);s=zn(i)}else s=await lu(e,t.right);else br(t.operator)&&!r?s=await cu(e,t.right):s=await se(e,t.right);if(br(t.operator)){let i=e.state.shoptOptions.nocasematch;return Ns(t.operator,n,s,!r,i,!0,e.limits.maxCallDepth)}if($s(t.operator))return Cs(t.operator,await Su(e,n),await Su(e,s));if(xs(t.operator))return Ps(e,t.operator,n,s);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=$p(s),l=ge(o,i?"i":"").match(n);if(Ee(e,"BASH_REMATCH"),l)for(let c=0;c<l.length;c++)H(e,"BASH_REMATCH",c,l[c]||"");return l!==null}catch{throw new Error("syntax error in regular expression")}case"<":return n<s;case">":return n>s;default:return!1}}case"CondUnary":{let n=await se(e,t.operand);return vs(t.operator)?ks(e,t.operator,n):Rs(t.operator)?Os(t.operator,n):t.operator==="-v"?await Ds(e,n):t.operator==="-o"?uo(e,n):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await se(e,t.operand.expression.word)})`!=="":!await un(e,t.operand);case"CondAnd":return await un(e,t.left)?await un(e,t.right):!1;case"CondOr":return await un(e,t.left)?!0:await un(e,t.right);case"CondGroup":return await un(e,t.expression);case"CondWord":return await se(e,t.word)!=="";default:return!1}}async function Sr(e,t){if(t.length===0)return F("","",1);if(t.length===1)return be(!!t[0]);if(t.length===2){let r=t[0],s=t[1];return r==="("?L(`test: '(' without matching ')'
|
|
127
|
+
`,2):vs(r)?be(await ks(e,r,s)):Rs(r)?be(Os(r,s)):r==="!"?be(!s):r==="-v"?be(await Ds(e,s)):r==="-o"?be(uo(e,s)):r==="="||r==="=="||r==="!="||r==="<"||r===">"||r==="-eq"||r==="-ne"||r==="-lt"||r==="-le"||r==="-gt"||r==="-ge"||r==="-nt"||r==="-ot"||r==="-ef"?L(`test: ${r}: unary operator expected
|
|
128
|
+
`,2):F("","",1)}if(t.length===3){let r=t[0],s=t[1],i=t[2];if(br(s))return be(Ns(s,r,i));if($s(s)){let o=Is(r),a=Is(i);return!o.valid||!a.valid?F("","",2):be(Cs(s,o.value,a.value))}if(xs(s))return be(await Ps(e,s,r,i));switch(s){case"-a":return be(r!==""&&i!=="");case"-o":return be(r!==""||i!=="");case">":return be(r>i);case"<":return be(r<i)}if(r==="!"){let o=await Sr(e,[s,i]);return F("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(r==="("&&i===")")return be(s!=="")}if(t.length===4){if(t[0]==="!"){let r=await Sr(e,t.slice(1));return F("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(t[0]==="("&&t[3]===")")return Sr(e,[t[1],t[2]])}let n=await vu(e,t,0);return n.pos<t.length?L(`test: too many arguments
|
|
129
|
+
`,2):be(n.value)}async function vu(e,t,n){return vp(e,t,n)}async function vp(e,t,n){let{value:r,pos:s}=await bu(e,t,n);for(;t[s]==="-o";){let i=await bu(e,t,s+1);r=r||i.value,s=i.pos}return{value:r,pos:s}}async function bu(e,t,n){let{value:r,pos:s}=await co(e,t,n);for(;t[s]==="-a";){let i=await co(e,t,s+1);r=r&&i.value,s=i.pos}return{value:r,pos:s}}async function co(e,t,n){let r=e.executionScope.enterDepth("test_expression",e.limits.maxCallDepth,"test expression");try{if(t[n]==="!"){let{value:s,pos:i}=await co(e,t,n+1);return{value:!s,pos:i}}return kp(e,t,n)}finally{r.release()}}async function kp(e,t,n){let r=t[n];if(r==="("){let{value:i,pos:o}=await vu(e,t,n+1);return{value:i,pos:t[o]===")"?o+1:o}}let s=t[n+1];if(br(s)){let i=r,o=t[n+2]??"";return{value:Ns(s,i,o),pos:n+3}}if($s(s)){let i=Is(r),o=Is(t[n+2]??"0");return!i.valid||!o.valid?{value:!1,pos:n+3}:{value:Cs(s,i.value,o.value),pos:n+3}}if(xs(s)){let i=r,o=t[n+2]??"";return{value:await Ps(e,s,i,o),pos:n+3}}if(vs(r)){let i=t[n+1]??"";return{value:await ks(e,r,i),pos:n+2}}if(Rs(r)){let i=t[n+1]??"";return{value:Os(r,i),pos:n+2}}if(r==="-v"){let i=t[n+1]??"";return{value:await Ds(e,i),pos:n+2}}if(r==="-o"){let i=t[n+1]??"";return{value:uo(e,i),pos:n+2}}return{value:r!==void 0&&r!=="",pos:n+1}}function Gn(e,t,n=!1,r=!1,s=256){r&&xp(t,s);let i=`^${ku(t,r)}$`;return ge(i,n?"is":"s").test(e)}function xp(e,t){let n=0,r=[];for(let s=0;s<e.length;s++){if(e[s]==="\\"){s++;continue}if(e[s]==="("){let i=s>0&&"@*+?!".includes(e[s-1]);if(r.push(i),i&&n++,n>t)throw new C(`extglob maximum depth (${t}) exceeded`,"recursion")}else e[s]===")"&&r.length>0&&r.pop()&&n--}}function ku(e,t){let n="";for(let r=0;r<e.length;r++){let s=e[r];if(t&&(s==="@"||s==="*"||s==="+"||s==="?"||s==="!")&&r+1<e.length&&e[r+1]==="("){let i=xu(e,r+1);if(i!==-1){let o=e.slice(r+2,i),a=Pu(o),l=a.map(u=>ku(u,t)),c=l.length>0?l.join("|"):"(?:)";if(s==="@")n+=`(?:${c})`;else if(s==="*")n+=`(?:${c})*`;else if(s==="+")n+=`(?:${c})+`;else if(s==="?")n+=`(?:${c})?`;else if(s==="!")if(i<e.length-1){let f=a.map(h=>$u(h,t));if(f.every(h=>h!==null)&&f.every(h=>h===f[0])&&f[0]!==null){let h=f[0];if(h===0)n+="(?:.+)";else{let p=[];h>0&&p.push(`.{0,${h-1}}`),p.push(`.{${h+1},}`),p.push(`(?!(?:${c})).{${h}}`),n+=`(?:${p.join("|")})`}}else n+=`(?:(?!(?:${c})).)*?`}else n+=`(?!(?:${c})$).*`;r=i;continue}}if(s==="\\")if(r+1<e.length){let i=e[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?n+=`\\${i}`:n+=i,r++}else n+="\\\\";else if(s==="*")n+=".*";else if(s==="?")n+=".";else if(s==="["){let i=e.indexOf("]",r+1);i!==-1?(n+=e.slice(r,i+1),r=i):n+="\\["}else/[\\^$.|+(){}]/.test(s)?n+=`\\${s}`:n+=s}return n}function xu(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function Pu(e){let t=[],n="",r=0,s=0;for(;s<e.length;){let i=e[s];if(i==="\\"){n+=i,s+1<e.length?(n+=e[s+1],s+=2):s++;continue}i==="("?(r++,n+=i):i===")"?(r--,n+=i):i==="|"&&r===0?(t.push(n),n=""):n+=i,s++}return t.push(n),t}function $u(e,t){let n=0,r=0;for(;r<e.length;){let s=e[r];if(t&&(s==="@"||s==="*"||s==="+"||s==="?"||s==="!")&&r+1<e.length&&e[r+1]==="("){let i=xu(e,r+1);if(i!==-1){if(s==="@"){let o=e.slice(r+2,i),l=Pu(o).map(c=>$u(c,t));if(l.every(c=>c!==null)&&l.every(c=>c===l[0])){n+=l[0],r=i+1;continue}return null}return null}}if(s==="*")return null;if(s==="?"){n+=1,r++;continue}if(s==="["){let i=e.indexOf("]",r+1);if(i!==-1){n+=1,r=i+1;continue}n+=1,r++;continue}if(s==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}function uo(e,t){let r=new Map([["errexit",()=>e.state.options.errexit===!0],["nounset",()=>e.state.options.nounset===!0],["pipefail",()=>e.state.options.pipefail===!0],["xtrace",()=>e.state.options.xtrace===!0],["e",()=>e.state.options.errexit===!0],["u",()=>e.state.options.nounset===!0],["x",()=>e.state.options.xtrace===!0]]).get(t);return r?r():!1}async function Su(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 Au(t);try{let n=new Q,r=re(n,t);return await J(e,r.expression)}catch{return Au(t)}}function Pp(e,t){let n=0;for(let r of e){let s;if(r>="0"&&r<="9")s=r.charCodeAt(0)-48;else if(r>="a"&&r<="z")s=r.charCodeAt(0)-97+10;else if(r>="A"&&r<="Z")s=r.charCodeAt(0)-65+36;else if(r==="@")s=62;else if(r==="_")s=63;else return Number.NaN;if(s>=t)return Number.NaN;n=n*t+s}return n}function Au(e){if(e=e.trim(),e==="")return 0;let t=!1;e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1));let n,r=e.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(r){let s=Number.parseInt(r[1],10);s>=2&&s<=64?n=Pp(r[2],s):n=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?n=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?n=Number.parseInt(e,8):n=Number.parseInt(e,10);return Number.isNaN(n)&&(n=0),t?-n:n}function Is(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let n=Number.parseInt(e,10);return Number.isNaN(n)?{value:0,valid:!1}:{value:t?-n:n,valid:!0}}function $p(e){let t="",n=0;for(;n<e.length;)if(e[n]==="\\"&&n+1<e.length)t+=e[n]+e[n+1],n+=2;else if(e[n]==="["){let r=Cp(e,n);t+=r.converted,n=r.endIndex}else t+=e[n],n++;return t}function Cp(e,t){let n=t+1,r="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(r+="^",n++);let s=!1;n<e.length&&e[n]==="]"&&(s=!0,n++);let i=!1;n<e.length&&e[n]==="["&&n+1<e.length&&e[n+1]!==":"&&(i=!0,n++);let o="",a=!1;for(;n<e.length;){let l=e[n];if(l==="]"){a=!0,n++;break}if(l==="["&&n+1<e.length&&e[n+1]===":"){let c=e.indexOf(":]",n+2);if(c!==-1){let u=e.slice(n+2,c);o+=Np(u),n=c+2;continue}}if(l==="["&&n+1<e.length){let c=e[n+1];if(c==="."||c==="="){let u=`${c}]`,f=e.indexOf(u,n+2);if(f!==-1){let d=e.slice(n+2,f);o+=d,n=f+2;continue}}}if(l==="\\"&&n+1<e.length){o+=l+e[n+1],n+=2;continue}o+=l,n++}return a?(s&&(r+="\\]"),i&&(r+="\\["),r+=o,r+="]",{converted:r,endIndex:n}):{converted:"\\[",endIndex:t+1}}function Np(e){return new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]).get(e)??""}function fo(e,t,n){if(n&&e.length>=n.maxElements)throw new C(`array element limit exceeded (${n.maxElements})`,"array_elements");e.push(t)}function Wt(e,t){if(t&&V(e)>t.maxStringBytes)throw new C(`array assignment string limit exceeded (${t.maxStringBytes} bytes)`,"string_length");let n=[],r="",s=!1,i=!1,o=!1,a=!1;for(let l of e){if(o){r+=l,o=!1,a=!0;continue}if(l==="\\"){o=!0;continue}if(l==="'"&&!i){s||(a=!0),s=!s;continue}if(l==='"'&&!s){i||(a=!0),i=!i;continue}if((l===" "||l===" "||l===`
|
|
130
|
+
`)&&!s&&!i){a&&(fo(n,r,t),r="",a=!1);continue}r+=l,a=!0}return a&&fo(n,r,t),n}function _s(e,t){if(t&&V(e)>t.maxStringBytes)throw new C(`array assignment string limit exceeded (${t.maxStringBytes} bytes)`,"string_length");let n=[],r=0;for(;r<e.length;){for(;r<e.length&&/\s/.test(e[r]);)r++;if(r>=e.length)break;if(e[r]!=="["){r++;continue}r++;let s="";if(e[r]==="'"||e[r]==='"'){let o=e[r];for(r++;r<e.length&&e[r]!==o;)s+=e[r],r++;e[r]===o&&r++}else for(;r<e.length&&e[r]!=="]"&&e[r]!=="=";)s+=e[r],r++;for(;r<e.length&&e[r]!=="]";)r++;if(e[r]==="]"&&r++,e[r]!=="=")continue;r++;let i="";if(e[r]==="'"||e[r]==='"'){let o=e[r];for(r++;r<e.length&&e[r]!==o;)e[r]==="\\"&&r+1<e.length&&r++,i+=e[r],r++;e[r]===o&&r++}else for(;r<e.length&&!/\s/.test(e[r]);)i+=e[r],r++;fo(n,[s,i],t)}return n}function Cu(e,t){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(n)return{name:n[1],isArray:!0,arrayElements:Wt(n[2],t)};let r=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(r)return{name:r[1],isArray:!1,arrayIndex:r[2],value:r[3]};if(e.includes("=")){let s=e.indexOf("=");return{name:e.slice(0,s),isArray:!1,value:e.slice(s+1)}}return{name:e,isArray:!1}}async function Rp(e,t){try{let n=new Q,r=re(n,t);return await J(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}async function Nu(e,t,n={}){let{name:r,isArray:s,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:l=!1,checkReadonly:c=!0}=n;if(c){let u=fe(e,r);if(u)return u}if(s&&i){e.executionScope.consumeWork(i.length,"array assignment");let u=ke(e,r),f=u?Me(u):void 0,d=e.state.env.get(r);try{Ee(e,r);for(let h=0;h<i.length;h++)H(e,r,h,i[h]);e.state.env.delete(r)}catch(h){throw e.state.arrays??=new Map,f?e.state.arrays.set(r,f):e.state.arrays.delete(r),d===void 0?e.state.env.delete(r):e.state.env.set(r,d),h}}else if(a!==void 0&&o!==void 0){let u=await Rp(e,a);H(e,r,u,o)}else o!==void 0&&e.state.env.set(r,o);return l&&Ze(e,r),null}function fn(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function ho(e,t){return e.state.localVarDepth?.get(t)}function Ts(e,t){e.state.localVarDepth?.delete(t)}function Ru(e,t,n){e.state.localVarStack=e.state.localVarStack||new Map;let r=e.state.localVarStack.get(t)||[];r.push({value:n,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,r)}function Ls(e,t){let n=e.state.localVarStack?.get(t);if(!(!n||n.length===0))return n.pop()}function Ou(e,t){if(e.state.localVarStack)for(let[n,r]of e.state.localVarStack.entries()){for(;r.length>0&&r[r.length-1].scopeIndex===t;)r.pop();r.length===0&&e.state.localVarStack.delete(n)}}var po=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Du(e){return po.has(e)}var mo=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Hn=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);var yo="__file__:",go="__file_append__:",bo="__rw__:",wo="__dupout__:",Eo="__dupin__:",Pe=3;function Op(e){let t=e.slice(bo.length),n=t.indexOf(":");if(n===-1)return null;let r=Number.parseInt(t.slice(0,n),10);if(Number.isNaN(r)||r<0)return null;let s=n+1,i=t.slice(s,s+r),o=t.slice(s+r+1),a=o.indexOf(":");if(a===-1)return null;let l=Number.parseInt(o.slice(0,a),10);return Number.isNaN(l)||l<0?null:{path:i,position:l,content:o.slice(a+1)}}function Iu(e,t){let n=Number.parseInt(e.slice(t.length),10);return Number.isNaN(n)?null:n}function Dp(e){if(e.startsWith(yo))return{kind:"output",path:e.slice(yo.length),append:!1};if(e.startsWith(go))return{kind:"output",path:e.slice(go.length),append:!0};if(e.startsWith(bo)){let t=Op(e);if(t)return{kind:"readwrite",...t}}if(e.startsWith(wo)){let t=Iu(e,wo);if(t!==null)return{kind:"dup-out",sourceFd:t}}if(e.startsWith(Eo)){let t=Iu(e,Eo);if(t!==null)return{kind:"dup-in",sourceFd:t}}return{kind:"input",content:e}}function So(e){switch(e.kind){case"input":return e.content;case"output":return`${e.append?go:yo}${e.path}`;case"readwrite":return`${bo}${e.path.length}:${e.path}:${e.position}:${e.content}`;case"dup-out":return`${wo}${e.sourceFd}`;case"dup-in":return`${Eo}${e.sourceFd}`;case"closed":throw new Error("Closed descriptors have no table encoding")}}function Ip(e){return e.state.fileDescriptors??=new Map,e.state.fileDescriptors}function _p(e,t,n){n?(e.state.inputFds??=new Set,e.state.inputFds.add(t)):e.state.inputFds?.delete(t)}function Zn(e,t){return e.state.fdAliases?.get(t)}function dn(e,t){return[...Zn(e,t)??[t]]}function _u(e,t){let n=Zn(e,t);if(n&&(n.delete(t),e.state.fdAliases?.delete(t),n.size<2))for(let r of n)e.state.fdAliases?.delete(r)}function Ao(e,t,n){if(t===n)return;e.state.fdAliases??=new Map;let r=Zn(e,n)??new Set([n]);r.add(t);for(let s of r)e.state.fdAliases.set(s,r)}function Fs(e,t){return e.state.fileDescriptors?.get(t)}function lt(e,t){let n=Fs(e,t);if(n===void 0)return;let r=e.state.inputFds?.has(t)?{kind:"input",content:n}:Dp(n);return e.state.deviceFds?.has(t)&&(r.kind==="input"||r.kind==="readwrite")?{...r,device:!0}:r}function Nn(e,t){return e.state.fileDescriptors?.has(t)===!0}function vo(e,t,n,r,s=!1){let i=Ip(e);i.has(t)||Eu(e),i.set(t,n),_p(e,t,r),s?(e.state.deviceFds??=new Set,e.state.deviceFds.add(t)):e.state.deviceFds?.delete(t)}function Ms(e,t,n,r=!1,s=!1){_u(e,t),vo(e,t,n,r,s)}function vt(e,t,n){Ms(e,t,So(n),n.kind==="input",(n.kind==="input"||n.kind==="readwrite")&&n.device===!0)}function Rt(e,t){e.state.fileDescriptors?.delete(t),e.state.inputFds?.delete(t),e.state.deviceFds?.delete(t),_u(e,t)}function Bs(e,t,n){let r=Fs(e,n);return r===void 0?!1:(Ms(e,t,r,e.state.inputFds?.has(n)===!0,e.state.deviceFds?.has(n)===!0),Ao(e,t,n),!0)}function ko(e,t,n){let r=Fs(e,n);if(r===void 0)return!1;if(t===n)return!0;let s=e.state.inputFds?.has(n)===!0,i=e.state.deviceFds?.has(n)===!0,o=[...Zn(e,n)??[]].filter(l=>l!==n);Rt(e,n),Ms(e,t,r,s,i);let a=o.find(l=>Nn(e,l));return a!==void 0&&Ao(e,t,a),!0}function Ws(e,t){let n=lt(e,t);if(n===void 0)return{error:"not-open"};switch(n.kind){case"input":return{content:n.content};case"readwrite":return{content:n.content.slice(n.position)};case"output":case"dup-out":return{error:"write-only"};case"dup-in":return{error:"not-open"};case"closed":return{error:"not-open"}}}function hn(e,t,n){let r=lt(e,t);if(r===void 0)return;let s;if(r.kind==="input")s={...r,content:r.content.slice(n)};else if(r.kind==="readwrite")s={...r,position:r.position+n};else return;let i=So(s),o=s.kind==="input";for(let a of Zn(e,t)??[t])vo(e,a,i,o,s.device===!0)}async function xo(e,t,n,r,s){if(t.kind==="output")return await e.fs.appendFile(t.path,r,s),!0;let o=n.map(u=>lt(e,u)).find(u=>u?.kind==="readwrite")??t;if(o.kind!=="readwrite")return!1;let a=o.content.slice(0,o.position)+r+o.content.slice(o.position+r.length),l={...o,position:o.position+r.length,content:a};await e.fs.writeFile(o.path,a,s);let c=So(l);for(let u of n)Nn(e,u)&&vo(e,u,c,!1,l.device===!0);return!0}function pn(e,t,n){if(t.has(n))return;let r=Zn(e,n);t.set(n,{raw:Fs(e,n),isInput:e.state.inputFds?.has(n)===!0,isDevice:e.state.deviceFds?.has(n)===!0,aliases:r?[...r].filter(s=>s!==n):[]})}function Vs(e,t){let n=e.state.fileDescriptors;if(n)for(let[r,{raw:s,isInput:i,isDevice:o,aliases:a}]of t){if(s===void 0){Rt(e,r);continue}Ms(e,r,s,i,o);let l=a.find(c=>n.has(c));l!==void 0&&Ao(e,r,l)}}function Po(e){switch(e.operator){case"<":case"<>":case"<<":case"<<-":case"<<<":case"<&":return e.fd??0;case">":case">>":case">|":case">&":return e.fd??1;default:return null}}function Tu(e){if(e.fdVariable)return!1;let t=Po(e);return t!==null&&t>=Pe}async function Tp(e,t,n,r){try{if(!await e.fs.exists(t))return null;if((await e.fs.stat(t)).isDirectory)return`bash: ${n}: Is a directory
|
|
130
131
|
`;if(r.checkNoclobber&&e.state.options.noclobber&&!r.isClobber&&n!=="/dev/null")return`bash: ${n}: cannot overwrite existing file
|
|
131
132
|
`}catch{return`bash: ${n}: cannot open redirect target
|
|
132
|
-
`}return null}function
|
|
133
|
-
`,1)};if(t==="/dev/stdout")return{entry:{kind:"dup-out",sourceFd:1}};if(t==="/dev/stderr")return{entry:{kind:"dup-out",sourceFd:2}};try{n?await e.fs.appendFile(i,"","binary"):await e.fs.writeFile(i,"","binary")}catch(a){if(
|
|
134
|
-
`,1)}
|
|
135
|
-
`,1)};try{
|
|
136
|
-
`,1)}
|
|
133
|
+
`}return null}var Rn="/dev/null",zs=new Set([Rn,"/dev/zero","/dev/random","/dev/urandom"]);function Lu(e){let n=Math.min(e.length,8192);for(let r=0;r<n;r++)if(e.charCodeAt(r)>127)return"utf8";return"binary"}function Ar(e,t){let{entry:n}=e;if(n.kind==="dup-out"){if(n.sourceFd===1)return{kind:"live-stdout"};if(n.sourceFd===2)return{kind:"live-stderr"}}return n.kind==="output"||n.kind==="readwrite"?n.path===Rn?{kind:"discard"}:{kind:"descriptor",source:e}:{kind:"invalid-output",fd:t}}var vr="scoped",Mu="bare",Bu="persistent",Lp=e=>new C(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors"),Fp=(e,t)=>Nn(e,t)||(e.state.fileDescriptors?.size??0)<e.limits.maxFileDescriptors,Fu=e=>{let t=Math.max(e.state.nextFd??10,10);for(;Nn(e,t);)t+=1;return t},$o=e=>{let t=e.endsWith("-"),n=t?e.slice(0,-1):e;return/^\d+$/.test(n)?{sourceFd:Number.parseInt(n,10),move:t}:null},Mp=(e,t,n)=>{let r=lt(e,t);return r?n?r.kind==="input"||r.kind==="readwrite"||r.kind==="dup-in"?{kind:"entry",entry:r,descriptors:dn(e,t)}:null:r.kind==="output"||r.kind==="readwrite"||r.kind==="dup-out"?{kind:"entry",entry:r,descriptors:dn(e,t)}:null:null},Bp=new Map([["ENOENT","No such file or directory"],["ENOTDIR","Not a directory"]]);async function Qn(e,t,n,r,s=!0){let i=e.fs.resolvePath(e.state.cwd,t);if(i===Rn)return{entry:{kind:"output",path:Rn,append:n}};let o=await Tp(e,i,t,{checkNoclobber:!n,isClobber:r});if(o)return{error:F("",o,1)};if(t==="/dev/full")return{error:F("",`bash: /dev/full: No space left on device
|
|
134
|
+
`,1)};if(t==="/dev/stdout")return{entry:{kind:"dup-out",sourceFd:1}};if(t==="/dev/stderr")return{entry:{kind:"dup-out",sourceFd:2}};try{n?await e.fs.appendFile(i,"","binary"):await e.fs.writeFile(i,"","binary")}catch(a){let l=Ca(a),c=l&&Bp.get(l);if(c)return{error:F("",`bash: ${t}: ${c}
|
|
135
|
+
`,1)};if(!s)throw a;return{error:F("",`bash: ${t}: cannot open redirect target
|
|
136
|
+
`,1)}}return{entry:{kind:"output",path:i,append:n}}}async function Co(e,t,n){let r=e.fs.resolvePath(e.state.cwd,t);try{let s=r===Rn?"":await e.fs.readFile(r);return n?{entry:{kind:"readwrite",path:r,position:0,content:s,device:zs.has(r)}}:{entry:{kind:"input",content:s,device:zs.has(r)}}}catch{if(!n)return{error:F("",`bash: ${t}: No such file or directory
|
|
137
|
+
`,1)};try{return await e.fs.writeFile(r,"","binary"),{entry:{kind:"readwrite",path:r,position:0,content:"",device:zs.has(r)}}}catch{return{error:F("",`bash: ${t}: No such file or directory
|
|
138
|
+
`,1)}}}}var Wp=async(e,t)=>{let n=await se(e,t.content);return t.stripTabs?n.split(`
|
|
137
139
|
`).map(r=>r.replace(/^\t+/,"")).join(`
|
|
138
|
-
`):n};async function
|
|
139
|
-
`,1),
|
|
140
|
-
`,1),
|
|
141
|
-
`,1),
|
|
142
|
-
`,1),
|
|
143
|
-
`,1),
|
|
144
|
-
`};else if(
|
|
145
|
-
`,1),
|
|
146
|
-
`,1),
|
|
147
|
-
`,1),
|
|
148
|
-
`,1),
|
|
149
|
-
`,1),
|
|
150
|
-
`});else if(
|
|
151
|
-
`,1),
|
|
152
|
-
`,1),
|
|
153
|
-
`,1),
|
|
154
|
-
`,1),
|
|
155
|
-
`)
|
|
156
|
-
`,1),
|
|
157
|
-
`,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
`,2);
|
|
161
|
-
`,2);
|
|
162
|
-
`,2);
|
|
163
|
-
`,2);
|
|
164
|
-
`,2);
|
|
165
|
-
`,2)
|
|
166
|
-
`,2)}else if(
|
|
167
|
-
`,2);
|
|
168
|
-
`,2);
|
|
169
|
-
`,2);
|
|
170
|
-
`,2)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
`,
|
|
175
|
-
`,2);
|
|
176
|
-
`,2);
|
|
177
|
-
`,2);
|
|
178
|
-
`,2);
|
|
179
|
-
`,2);
|
|
180
|
-
`,2)
|
|
181
|
-
`,2)}else if(d==="-
|
|
182
|
-
`,2)}else if(d==="-
|
|
183
|
-
`,2)}else if(d==="-
|
|
184
|
-
`,2)
|
|
185
|
-
|
|
186
|
-
`;return L("",i,1)}return ee("")}let r=[],s=t||Array.from(n.keys());for(let i of s){let o=n.get(i);if(!o){if(t)return L(r.join(`
|
|
140
|
+
`):n};async function Vp(e,t,n,r){let s=(v,A)=>e.state.closedStandardFds?.has(v)?{kind:"closed"}:lt(e,v)??A,i=new Map([[0,s(0,{kind:"dup-in",sourceFd:0})],[1,s(1,{kind:"dup-out",sourceFd:1})],[2,s(2,{kind:"dup-out",sourceFd:2})]]),o={stdout:Ar({kind:"entry",entry:i.get(1),descriptors:dn(e,1)},1),stderr:Ar({kind:"entry",entry:i.get(2),descriptors:dn(e,2)},2)},a=(v,A)=>{v===1?o.stdout=A:v===2&&(o.stderr=A)},l=v=>v.kind==="dup-out"?v.sourceFd===1?o.stdout:o.stderr:v.path===Rn?{kind:"discard"}:{kind:"file",path:v.path,append:v.append},c=r.numericSnapshot,u,f=-1,d=!1,h=!1,p=i.get(0);p?.kind==="input"?(u=p.content,f=0,h=p.device===!0):p?.kind==="readwrite"?(u=p.content.slice(p.position),f=0,h=p.device===!0):p?.kind==="closed"&&(u="",h=!0);let m=()=>({outputRoutes:o,stdin:u,stdinSourceFd:f,stdinReplaced:d,stdinUnavailable:h,error:null}),y=async(v,A,k)=>{let x={...m(),error:await mn(e,v,A>0,o)};return k?{...x,errorCause:k}:x},b=async(v,A)=>{if(Fp(e,v))return null;let k=Lp(e);return y(F("",k.stderr,C.EXIT_CODE),A,k)},w=(v,A,k)=>{v!==null&&v<Pe&&i.set(v,A),(v===1||v===2)&&a(v,k??Ar({kind:"entry",entry:A,descriptors:r.policy==="persistent"?[v]:[]},v)),r.policy==="persistent"&&v!==null&&v<Pe&&(e.state.closedStandardFds?.delete(v),vt(e,v,A))},E=(v,A)=>{i.set(v,A),(v===1||v===2)&&a(v,Ar({kind:"entry",entry:A,descriptors:[]},v)),pn(e,r.standardSnapshot,v),r.standardClosedSnapshot.has(v)||r.standardClosedSnapshot.set(v,e.state.closedStandardFds?.has(v)===!0),e.state.closedStandardFds?.delete(v),vt(e,v,A)},S=(v,A)=>{if(v<Pe){let k=i.get(v);return k?.kind==="closed"?null:{kind:"entry",entry:k,descriptors:dn(e,v)}}return Mp(e,v,A)};for(let v=0;v<t.length;v++){let A=t[v],k=Po(A);if(A.target.type==="HereDoc"){let $=await Wp(e,A.target);if(A.fdVariable){try{fe(e,A.fdVariable)}catch(R){if(!(R instanceof G))throw R;return y(F(R.stdout,R.stderr,R.exitCode),v,R)}let N=Fu(e),O=await b(N,v);if(O)return O;pn(e,r.fdVariableSnapshot,N),r.fdVariableEnv.has(A.fdVariable)||r.fdVariableEnv.set(A.fdVariable,e.state.env.get(A.fdVariable)),vt(e,N,{kind:"input",content:$}),e.state.env.set(A.fdVariable,String(N)),e.state.nextFd=N+1}else if(k!==null&&k>=Pe){let N=await b(k,v);if(N)return N;pn(e,c,k),vt(e,k,{kind:"input",content:$})}else if(k===0||k===null)u=Ut($),f=-1,w(k,{kind:"input",content:u}),d=!0,h=!1;else{let N={kind:"input",content:$};r.policy==="persistent"?w(k,N):E(k,N)}continue}let x,D=A.operator===">&"||A.operator==="<&";if(D){if(ro(e,A.target))return y(F("",`bash: $@: ambiguous redirect
|
|
141
|
+
`,1),v);x=await se(e,A.target)}else if(A.operator==="<<<")x=await se(e,A.target);else{let $=await hu(e,A.target);if("error"in $)return y(F("",$.error,1),v);x=$.target}if(x.includes("\0"))return y(F("",`bash: ${x.replace(/\0/g,"")}: No such file or directory
|
|
142
|
+
`,1),v);if(A.fdVariable){try{fe(e,A.fdVariable)}catch(P){if(!(P instanceof G))throw P;return y(F(P.stdout,P.stderr,P.exitCode),v,P)}if(D&&x==="-"){let P=Number.parseInt(e.state.env.get(A.fdVariable)??"",10);Number.isNaN(P)||(pn(e,r.fdVariableSnapshot,P),Rt(e,P));continue}let $=Fu(e),N=D?$o(x):null;if(N&&!S(N.sourceFd,A.operator==="<&"))return y(F("",`bash: ${N.sourceFd}: Bad file descriptor
|
|
143
|
+
`,1),v);if(!(N?.move===!0&&N.sourceFd>=Pe)){let P=await b($,v);if(P)return P}pn(e,r.fdVariableSnapshot,$),r.fdVariableEnv.has(A.fdVariable)||r.fdVariableEnv.set(A.fdVariable,e.state.env.get(A.fdVariable));let R,W;if(D){let P=N;if(P){let B=S(P.sourceFd,A.operator==="<&");if(!B)return y(F("",`bash: ${P.sourceFd}: Bad file descriptor
|
|
144
|
+
`,1),v);W=P,P.sourceFd<Pe&&(R=B.entry)}else{if(A.operator==="<&")return y(F("",`bash: ${x}: ambiguous redirect
|
|
145
|
+
`,1),v);let B=await Qn(e,x,!1,!1);if(B.error)return y(B.error,v);R=B.entry}}else if(A.operator===">"||A.operator===">|"||A.operator===">>"||A.operator==="&>"||A.operator==="&>>"){let P=A.operator===">>"||A.operator==="&>>",B=await Qn(e,x,P,A.operator===">|");if(B.error)return y(B.error,v);R=B.entry}else if(A.operator==="<<<")R={kind:"input",content:`${x}
|
|
146
|
+
`};else if(A.operator==="<"||A.operator==="<>"){let P=await Co(e,x,A.operator==="<>");if(P.error)return y(P.error,v);R=P.entry}if(W&&W.sourceFd>=Pe){if(!(W.move?ko(e,$,W.sourceFd):Bs(e,$,W.sourceFd)))return y(F("",`bash: ${W.sourceFd}: Bad file descriptor
|
|
147
|
+
`,1),v)}else R&&vt(e,$,R);W?.move&&W.sourceFd!==$&&W.sourceFd<Pe&&Rt(e,W.sourceFd),e.state.env.set(A.fdVariable,String($)),e.state.nextFd=$+1;continue}if(Tu(A)){let $=k;if(D&&x==="-"){pn(e,c,$),Rt(e,$);continue}let N=D?$o(x):null;if(N&&!S(N.sourceFd,A.operator==="<&"))return y(F("",`bash: ${N.sourceFd}: Bad file descriptor
|
|
148
|
+
`,1),v);if(!(N?.move===!0&&N.sourceFd>=Pe)){let R=await b($,v);if(R)return R}if(pn(e,c,$),D){let R=N;if(!R){if(A.operator==="<&")return y(F("",`bash: ${x}: ambiguous redirect
|
|
149
|
+
`,1),v);let P=await Qn(e,x,!1,!1);if(P.error)return y(P.error,v);vt(e,$,P.entry);continue}let W=S(R.sourceFd,A.operator==="<&");if(!W)return y(F("",`bash: ${R.sourceFd}: Bad file descriptor
|
|
150
|
+
`,1),v);if(R.sourceFd<Pe)vt(e,$,W.entry);else if(!(R.move?ko(e,$,R.sourceFd):Bs(e,$,R.sourceFd)))return y(F("",`bash: ${R.sourceFd}: Bad file descriptor
|
|
151
|
+
`,1),v);R.move&&R.sourceFd!==$&&R.sourceFd<Pe&&Rt(e,R.sourceFd);continue}if(A.operator===">"||A.operator===">|"||A.operator===">>"){let R=await Qn(e,x,A.operator===">>",A.operator===">|");if(R.error)return y(R.error,v);vt(e,$,R.entry)}else if(A.operator==="<<<")vt(e,$,{kind:"input",content:`${x}
|
|
152
|
+
`});else if(A.operator==="<"||A.operator==="<>"){let R=await Co(e,x,A.operator==="<>");if(R.error)return y(R.error,v);vt(e,$,R.entry)}continue}if(D){if(x==="-"){k===0&&(u="",f=-1,d=!0,h=!0),k!==null&&k<Pe&&(i.set(k,{kind:"closed"}),(k===1||k===2)&&a(k,{kind:"invalid-output",fd:k}),r.policy==="persistent"&&(Rt(e,k),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(k)));continue}let $=$o(x);if(!$){if(A.operator==="<&")return y(F("",`bash: ${x}: ambiguous redirect
|
|
153
|
+
`,1),v);let R=await Qn(e,x,!1,!1,!1);if(R.error)return y(R.error,v);let W=R.entry,P=l(W);A.fd==null?(w(1,W,P),w(2,W,P)):w(k,W,P);continue}let N=S($.sourceFd,A.operator==="<&");if(!N)return y(F("",`bash: ${$.sourceFd}: Bad file descriptor
|
|
154
|
+
`,1),v);let O=$.sourceFd===1?o.stdout:$.sourceFd===2?o.stderr:Ar(N,k===2?2:1);if(r.policy==="persistent"&&k!==null&&k<Pe&&$.sourceFd>=Pe){if(!Bs(e,k,$.sourceFd))return y(F("",`bash: ${$.sourceFd}: Bad file descriptor
|
|
155
|
+
`,1),v);i.set(k,lt(e,k)),e.state.closedStandardFds?.delete(k),a(k,O)}else w(k,N.entry,O);if(A.operator==="<&"&&k===0)if(N.entry.kind==="input"||N.entry.kind==="readwrite"){let R=$.sourceFd<Pe&&!Nn(e,$.sourceFd)?{content:N.entry.kind==="input"?N.entry.content:N.entry.content.slice(N.entry.position)}:Ws(e,$.sourceFd);if("error"in R)return y(F("",`bash: ${$.sourceFd}: Bad file descriptor
|
|
156
|
+
`,1),v);u=R.content,f=Nn(e,$.sourceFd)?$.sourceFd:-1,d=!0,h=N.entry.device===!0}else u=n,f=-1,d=!1,h=!1;$.move&&($.sourceFd>=Pe?Rt(e,$.sourceFd):(i.set($.sourceFd,{kind:"closed"}),($.sourceFd===1||$.sourceFd===2)&&a($.sourceFd,{kind:"invalid-output",fd:$.sourceFd}),r.policy==="persistent"&&(Rt(e,$.sourceFd),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add($.sourceFd))));continue}if(A.operator===">"||A.operator===">|"||A.operator===">>"||A.operator==="&>"||A.operator==="&>>"){let $=await Qn(e,x,A.operator===">>"||A.operator==="&>>",A.operator===">|",!1);if($.error)return y($.error,v);let N=$.entry,O=l(N);A.operator==="&>"||A.operator==="&>>"?(w(1,N,O),w(2,N,O)):w(k,N,O);continue}if(A.operator==="<<<"){let $=Ut(`${x}
|
|
157
|
+
`);w(k,{kind:"input",content:$}),k===0&&(u=$,f=-1,d=!0,h=!1)}else if(A.operator==="<"){let $=e.fs.resolvePath(e.state.cwd,x);try{let N=$===Rn?"":await _n(e.fs,$),O=zs.has($);w(k,{kind:"input",content:N,device:O}),k===0&&(u=N,f=-1,d=!0,h=O)}catch{return y(F("",`bash: ${x}: No such file or directory
|
|
158
|
+
`,1),v)}}else if(A.operator==="<>"){let $=await Co(e,x,!0);if($.error)return y($.error,v);let N=$.entry;w(k,N),k===0&&N.kind==="readwrite"&&(u=N.content,f=-1,d=!0,h=N.device===!0)}}return m()}function Kn(e,t,n){let r={numericSnapshot:new Map,fdVariableSnapshot:new Map,standardSnapshot:new Map,standardClosedSnapshot:new Map,fdVariableEnv:new Map,nextFd:e.state.nextFd,policy:n},s=!1;return{prepare:(i="")=>Vp(e,t,i,r),finish:()=>{if(!s){if(s=!0,n!=="persistent"&&Vs(e,r.numericSnapshot),n!=="persistent"){Vs(e,r.standardSnapshot);for(let[i,o]of r.standardClosedSnapshot)o?(e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(i)):e.state.closedStandardFds?.delete(i)}if(n==="bare"){Vs(e,r.fdVariableSnapshot);for(let[i,o]of r.fdVariableEnv)o===void 0?e.state.env.delete(i):e.state.env.set(i,o);e.state.nextFd=r.nextFd}}}}}function Xn(e){if(!e.error)throw new Error("Expected a redirection error");if(e.errorCause)throw e.errorCause.stdout=e.error.stdout,e.errorCause.stderr=e.error.stderr,e.errorCause;return e.error}async function No(e,t,n,r){let s=t instanceof G||t instanceof Le||t instanceof Ve?t.exitCode:t instanceof C?C.EXIT_CODE:0,i=await mn(e,F(t.stdout,t.stderr,s),n.length>0,r.outputRoutes);t.stdout=i.stdout,t.stderr=i.stderr,t.internalOutputAccounting=i.internalOutputAccounting??{stdout:V(i.stdout),stderr:V(i.stderr)}}async function nt(e,t,n,r){let s=Kn(e,t,vr),i;try{if(i=await s.prepare(n),i.error)return Xn(i);let o=e.state.groupStdin,a=e.state.groupStdinSourceFd;i.stdin!==void 0&&(e.state.groupStdin=i.stdin,e.state.groupStdinSourceFd=i.stdinSourceFd);try{let l=await r(i);return await mn(e,l,t.length>0,i.outputRoutes)}finally{i.stdin!==void 0&&(e.state.groupStdin=o,e.state.groupStdinSourceFd=a)}}catch(o){throw!(o instanceof Tn)||!i||await No(e,o,t,i),o}finally{s.finish()}}async function mn(e,t,n,r,s="bash",i=!1){n&&(t=e.executionScope.accountResult(t,"redirection"));let{stdout:o,stderr:a,exitCode:l}=t,u=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",f=y=>u,{stdout:d,stderr:h}=r;if(o!==""||a!==""){let y=o,b=a;o="",a="",d.kind==="invalid-output"&&y!==""&&(y="",b+=`${i?"":"bash: "}${s}: write error: Bad file descriptor
|
|
159
|
+
`,l=1),h.kind==="invalid-output"&&b!==""&&(b="",l===0&&(l=1));let w=async(E,S,v)=>{E.append?await e.fs.appendFile(E.path,S,v):await e.fs.writeFile(E.path,S,v)};if(d===h&&(d.kind==="file"||d.kind==="descriptor")){let E=y+b;E!==""&&(d.kind==="file"?await w(d,E,f(E)):await xo(e,d.source.entry,d.source.descriptors,E,f(E)))}else for(let[E,S,v]of[[y,d,!0],[b,h,!1]])if(E!=="")switch(S.kind){case"live-stdout":o+=E;break;case"live-stderr":a+=E;break;case"file":await w(S,E,v?f(E):Lu(E));break;case"descriptor":await xo(e,S.source.entry,S.source.descriptors,E,v?f(E):Lu(E));break;case"invalid-output":break;case"discard":break}}let p=F(o,a,l);if(t.stdoutKind&&(p.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(p.stdoutEncoding="binary"),t.internalPipeStatusOverride&&(p.internalPipeStatusOverride=t.internalPipeStatusOverride),n||e.state.fileDescriptors?.has(1)===!0||e.state.fileDescriptors?.has(2)===!0){let y=(t.internalOutputAccounting?.stdout??0)+(t.internalOutputAccounting?.stderr??0),b=V(p.stdout),w=V(p.stderr),E=Math.min(b,y);p.internalOutputAccounting={stdout:E,stderr:Math.min(w,y-E)},e.executionScope.accountResult(p,"redirection")}else t.internalOutputAccounting&&(p.internalOutputAccounting=t.internalOutputAccounting);return p}function Wu(e,t){if(e.state.options.posix&&po.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
|
|
160
|
+
`;throw new G(2,"",r)}let n={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,n),te}async function Us(e,t,n,r="",s,i=!1){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,cn(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(s??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localArrayScopes??=[],e.state.localArrayScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let o=new Map,a=Number.parseInt(e.state.env.get("#")??"0",10),l=Math.max(n.length,a);for(let h=0;h<l;h++){let p=String(h+1);o.set(p,e.state.env.get(p)),h<n.length?e.state.env.set(p,n[h]):e.state.env.delete(p)}o.set("@",e.state.env.get("@")),o.set("#",e.state.env.get("#")),e.state.env.set("@",n.join(" ")),e.state.env.set("#",String(n.length));let c=!1,u=()=>{if(c)return;c=!0;let h=e.state.localScopes.length-1,p=e.state.localScopes.pop(),m=e.state.localArrayScopes?.pop();if(p)for(let[y,b]of p)b===void 0?e.state.env.delete(y):e.state.env.set(y,b);if(m){e.state.arrays??=new Map;for(let[y,b]of m)b===void 0?(e.state.arrays.delete(y),e.state.associativeArrays?.delete(y)):(e.state.arrays.set(y,Me(b)),e.state.associativeArrays??=new Set,b.kind==="associative"?e.state.associativeArrays.add(y):e.state.associativeArrays.delete(y))}if(Ou(e,h),e.state.fullyUnsetLocals)for(let[y,b]of e.state.fullyUnsetLocals.entries())b===h&&e.state.fullyUnsetLocals.delete(y);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let y=e.state.localExportedVars.pop();if(y)for(let b of y)e.state.exportedVars?.delete(b)}for(let[y,b]of o)b===void 0?e.state.env.delete(y):e.state.env.set(y,b);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},f=null,d=Kn(e,t.redirections,vr);try{if(f=await d.prepare(r),f.error)return Xn(f);let h=f.stdin??r,p=i||f.stdin!==void 0||r!=="",m=await e.executeCommand(t.body,h,p);return mn(e,m,t.redirections.length>0,f.outputRoutes)}catch(h){if(h instanceof Tn&&f&&(await No(e,h,t.redirections,f),h instanceof Le))return F(h.stdout,h.stderr,h.exitCode);throw h}finally{d.finish(),u()}}var zu=e=>e.type==="Escaped"?M.literal(`\\${e.value}`):e.type==="DoubleQuoted"?{...e,parts:e.parts.map(zu)}:e,Uu=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],Do=[".",":","[","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"],zp=["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"],Up=Do;async function Io(e,t){let n=[],r=null,s="",i="",o=null,a=!1,l=!1,c=!1,u=null,f=null,d=null,h=[],p=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let A=0;A<t.length;A++){let k=t[A];if(k==="-v")n.push("variable");else if(k==="-e")n.push("export");else if(k==="-f")n.push("file");else if(k==="-d")n.push("directory");else if(k==="-k")n.push("keyword");else if(k==="-A"){if(A++,A>=t.length)return L(`compgen: -A: option requires an argument
|
|
161
|
+
`,2);let x=t[A];if(!p.includes(x))return L(`compgen: ${x}: invalid action name
|
|
162
|
+
`,2);n.push(x)}else if(k==="-W"){if(A++,A>=t.length)return L(`compgen: -W: option requires an argument
|
|
163
|
+
`,2);r=t[A]}else if(k==="-P"){if(A++,A>=t.length)return L(`compgen: -P: option requires an argument
|
|
164
|
+
`,2);s=t[A]}else if(k==="-S"){if(A++,A>=t.length)return L(`compgen: -S: option requires an argument
|
|
165
|
+
`,2);i=t[A]}else if(k==="-o"){if(A++,A>=t.length)return L(`compgen: -o: option requires an argument
|
|
166
|
+
`,2);let x=t[A];if(x==="plusdirs")a=!0;else if(x==="dirnames")l=!0;else if(x==="default")c=!0;else if(!(x==="filenames"||x==="nospace"||x==="bashdefault"||x==="noquote"))return L(`compgen: ${x}: invalid option name
|
|
167
|
+
`,2)}else if(k==="-F"){if(A++,A>=t.length)return L(`compgen: -F: option requires an argument
|
|
168
|
+
`,2);f=t[A]}else if(k==="-C"){if(A++,A>=t.length)return L(`compgen: -C: option requires an argument
|
|
169
|
+
`,2);d=t[A]}else if(k==="-X"){if(A++,A>=t.length)return L(`compgen: -X: option requires an argument
|
|
170
|
+
`,2);u=t[A]}else if(k==="-G"){if(A++,A>=t.length)return L(`compgen: -G: option requires an argument
|
|
171
|
+
`,2)}else if(k==="--"){h.push(...t.slice(A+1));break}else k.startsWith("-")||h.push(k)}o=h[0]??null;let m=[],y=new Set,b=()=>e.limits.maxArrayElements-m.length,w=A=>{for(let k of A){if(m.length>=e.limits.maxArrayElements)throw new C(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(V(k)>e.limits.maxStringLength)throw new C(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");e.executionScope.consumeWork(1,"compgen completion"),m.push(k),y.add(k)}};if(l){let A=await Ro(e,o,b());w(A)}if(c){let A=await Vu(e,o,b());w(A)}for(let A of n)if(A==="variable"){let k=jp(e,o,b());w(k)}else if(A==="export"){let k=qp(e,o,b());w(k)}else if(A==="function"){let k=Gp(e,o,b());w(k)}else if(A==="builtin"){let k=Hp(e,o,b());w(k)}else if(A==="keyword"){let k=Zp(e,o,b());w(k)}else if(A==="alias"){let k=Qp(e,o,b());w(k)}else if(A==="shopt"){let k=Kp(e,o,b());w(k)}else if(A==="helptopic"){let k=Xp(e,o,b());w(k)}else if(A==="directory"){let k=await Ro(e,o,b());w(k)}else if(A==="file"){let k=await Vu(e,o,b());w(k)}else if(A==="user"){let k=Yp(e,o,b());w(k)}else if(A==="command"){let k=await Jp(e,o,b());w(k)}if(r!==null)try{let A=await em(e,r),k=tm(e,A,b(),o);for(let x of k)w([x])}catch(A){if(A instanceof C)throw A;return F("","",1)}if(a){let A=await Ro(e,o,b(),y);for(let k of A)y.has(k)||w([k])}let E="";if(f!==null){let A=e.state.functions.get(f);if(A){let k=new Map,x=ke(e,"COMP_WORDS"),D=x?Me(x):void 0;Ee(e,"COMP_WORDS"),cr(e,"COMP_WORDS"),k.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),k.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),k.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let $=ke(e,"COMPREPLY"),N=$?Me($):void 0,O=e.state.env.get("COMPREPLY");Ee(e,"COMPREPLY"),e.state.env.delete("COMPREPLY");let R=["compgen",h[0]??"",""];try{let W=await Us(e,A,R,"");if(W.exitCode!==0)return Oo(e,k),Yn(e,"COMP_WORDS",D),Yn(e,"COMPREPLY",N),O!==void 0&&e.state.env.set("COMPREPLY",O),F("",W.stderr,1);E=W.stdout;let P=nm(e,b());w(P)}catch(W){if(W instanceof C)throw W;return Oo(e,k),Yn(e,"COMP_WORDS",D),Yn(e,"COMPREPLY",N),O!==void 0&&e.state.env.set("COMPREPLY",O),F("","",1)}Oo(e,k),Yn(e,"COMP_WORDS",D),Yn(e,"COMPREPLY",N),O!==void 0&&e.state.env.set("COMPREPLY",O)}}if(d!==null)try{let A=He(d),k=await e.executeScript(A);if(k.exitCode!==0)return F("",k.stderr,k.exitCode);if(k.stdout)for(let x of rm(k.stdout))x.length>0&&w([x])}catch(A){if(A.name==="ParseException")return L(`compgen: -C: ${A.message}
|
|
172
|
+
`,2);throw A}let S=m;if(u!==null){let A=u.startsWith("!"),k=A?u.slice(1):u;S=m.filter(x=>{let D=Gn(x,k,!1,!0,e.limits.maxCallDepth);return A?D:!D})}if(S.length===0&&o!==null)return F(E,"",1);let v=new Ln(e.limits.maxOutputSize,"compgen");v.append(E);for(let A of S)v.append(s).append(A).append(i).append(`
|
|
173
|
+
`);return ee(v.build())}function jp(e,t,n){let r=ct(e,t,n);for(let s of e.state.env.keys())/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&r.add(s);for(let s of e.state.arrays?.keys()??[])r.add(s);return r.build()}function qp(e,t,n){let r=ct(e,t,n),s=e.state.exportedVars??new Set;for(let i of s)e.state.env.has(i)&&r.add(i);return r.build()}function Gp(e,t,n){let r=ct(e,t,n);for(let s of e.state.functions.keys())r.add(s);return r.build()}function Hp(e,t,n){let r=ct(e,t,n);for(let s of Do)r.add(s);return r.build()}function Zp(e,t,n){let r=ct(e,t,n);for(let s of Uu)r.add(s);return r.build()}function Qp(e,t,n){let r=ct(e,t,n);for(let s of e.state.env.keys())if(s.startsWith("BASH_ALIAS_")){let i=s.slice(11);r.add(i)}return r.build()}function Kp(e,t,n){let r=ct(e,t,n);for(let s of zp)r.add(s);return r.build()}function Xp(e,t,n){let r=ct(e,t,n);for(let s of Up)r.add(s);return r.build()}async function Ro(e,t,n=e.limits.maxArrayElements,r){let s=ct(e,null,n,r);try{let i=e.state.cwd,o=t??"";if(t){let l=t.lastIndexOf("/");if(l!==-1){let c=t.slice(0,l)||"/";o=t.slice(l+1),c.startsWith("/")?i=c:i=`${e.state.cwd}/${c}`}}let a=await e.fs.readdir(i);for(let l of a){e.executionScope.consumeWork(1,"compgen directory scan");let c=`${i}/${l}`;try{if((await e.fs.stat(c)).isDirectory&&(!o||l.startsWith(o)))if(t?.includes("/")){let f=t.lastIndexOf("/"),d=t.slice(0,f+1);s.add(d+l)}else s.add(l)}catch(u){if(u instanceof C)throw u}}}catch(i){if(i instanceof C)throw i}return s.build()}async function Vu(e,t,n=e.limits.maxArrayElements){let r=ct(e,null,n);try{let s=e.state.cwd,i=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";i=t.slice(a+1),l.startsWith("/")?s=l:s=`${e.state.cwd}/${l}`}}let o=await e.fs.readdir(s);for(let a of o)if(e.executionScope.consumeWork(1,"compgen file scan"),!i||a.startsWith(i))if(t?.includes("/")){let l=t.lastIndexOf("/"),c=t.slice(0,l+1);r.add(c+a)}else r.add(a)}catch(s){if(s instanceof C)throw s}return r.build()}function Yp(e,t,n){let r=ct(e,t,n);return r.add("root"),r.add("nobody"),r.build()}async function Jp(e,t,n){let r=ct(e,t,n);for(let i of Do)r.add(i);for(let i of e.state.functions.keys())r.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&r.add(i.slice(11));for(let i of Uu)r.add(i);let s=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of s.split(":"))if(i)try{let o=await e.fs.readdir(i);for(let a of o)r.add(a)}catch(o){if(o instanceof C)throw o}return r.build()}function ct(e,t,n,r){let s=new Set;return{add(i){if(e.executionScope.consumeWork(1,"compgen candidate collection"),!(t!==null&&!i.startsWith(t))&&!r?.has(i)&&!s.has(i)){if(s.size>=n)throw new C(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(V(i)>e.limits.maxStringLength)throw new C(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");s.add(i)}},build(){return Array.from(s).sort()}}}async function em(e,t){let r=new Q().parseWordFromString(t,!1,!1);return await se(e,M.word(r.parts.map(zu)))}function tm(e,t,n,r){let s=e.state.env.get("IFS")??`
|
|
174
|
+
`;if(s.length===0){if(r!==null&&!t.startsWith(r))return[];if(n===0)throw new C(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");return[t]}let i=new Set(s.split("")),o=[],a=u=>{if(!(r!==null&&!u.startsWith(r))){if(o.length>=n)throw new C(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");o.push(u)}},l="",c=0;for(;c<t.length;){let u=t[c];if(u==="\\"&&c+1<t.length){let f=t[c+1];l+=f,c+=2}else i.has(u)?(l.length>0&&(a(l),l=""),c++):(l+=u,c++)}return l.length>0&&a(l),o}function Oo(e,t){for(let[n,r]of t)r===void 0?e.state.env.delete(n):e.state.env.set(n,r)}function Yn(e,t,n){e.state.arrays??=new Map,n?e.state.arrays.set(t,Me(n)):e.state.arrays.delete(t)}function nm(e,t){let n=[],r=s=>{if(n.length>=t)throw new C(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");n.push(s)};if(Ne(e,"COMPREPLY")){let s=K(e,"COMPREPLY");for(let[,i]of s)r(i)}else{let s=e.state.env.get("COMPREPLY");s!==void 0&&r(s)}return n}function*rm(e){let t=0;for(;t<=e.length;){let n=e.indexOf(`
|
|
175
|
+
`,t),r=n===-1?e.length:n;if(r>t&&(yield e.slice(t,r)),n===-1)return;t=n+1}}function kr(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n===127)return!0}return!1}function _o(e){let t="$'";for(let n=0;n<e.length;n++){let r=e[n],s=e.charCodeAt(n);s===7?t+="\\a":s===8?t+="\\b":s===9?t+="\\t":s===10?t+="\\n":s===11?t+="\\v":s===12?t+="\\f":s===13?t+="\\r":s===27?t+="\\e":s===39?t+="\\'":s===92?t+="\\\\":s<32||s===127?t+=`\\${s.toString(8).padStart(3,"0")}`:t+=r}return t+="'",t}function ju(e){if(kr(e))return qu(e);if(e==="")return 2;if(/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e))return V(e);let t=V(e)+2;for(let n of e)n==="'"&&(t+=3);return t}function Se(e){return kr(e)?_o(e):e===""?"''":/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function js(e){if(kr(e))return qu(e);let t=V(e)+2;for(let n of e)(n==="\\"||n==='"'||n==="$"||n==="`")&&t++;return t}function yn(e){return kr(e)?_o(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}function qu(e){let t=3;for(let n of e){let r=n.codePointAt(0)??0;r===7||r===8||r===9||r===10||r===11||r===12||r===13||r===27||r===39||r===92?t+=2:r<32||r===127?t+=4:t+=V(n)}return t}function xr(e){return kr(e)?_o(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}var sm=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Lo(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=!1,i,o,a,l=[],c=[],u=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-p")n=!0;else if(d==="-r")r=!0;else if(d==="-D")s=!0;else if(d==="-W"){if(f++,f>=t.length)return L(`complete: -W: option requires an argument
|
|
176
|
+
`,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return L(`complete: -F: option requires an argument
|
|
177
|
+
`,2);o=t[f]}else if(d==="-o"){if(f++,f>=t.length)return L(`complete: -o: option requires an argument
|
|
178
|
+
`,2);let h=t[f];if(!sm.includes(h))return L(`complete: ${h}: invalid option name
|
|
179
|
+
`,2);l.push(h)}else if(d==="-A"){if(f++,f>=t.length)return L(`complete: -A: option requires an argument
|
|
180
|
+
`,2);c.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return L(`complete: -C: option requires an argument
|
|
181
|
+
`,2);a=t[f]}else if(d==="-G"){if(f++,f>=t.length)return L(`complete: -G: option requires an argument
|
|
182
|
+
`,2)}else if(d==="-P"){if(f++,f>=t.length)return L(`complete: -P: option requires an argument
|
|
183
|
+
`,2)}else if(d==="-S"){if(f++,f>=t.length)return L(`complete: -S: option requires an argument
|
|
184
|
+
`,2)}else if(d==="-X"){if(f++,f>=t.length)return L(`complete: -X: option requires an argument
|
|
185
|
+
`,2)}else if(d==="--"){u.push(...t.slice(f+1));break}else d.startsWith("-")||u.push(d)}if(r){if(u.length===0)return e.state.completionSpecs.clear(),e.state.defaultCompletionSpec=void 0,e.state.emptyCompletionSpec=void 0,ee("");for(let f of u)e.state.completionSpecs.delete(f);return ee("")}if(n)return u.length===0?To(e):To(e,u);if(t.length===0||u.length===0&&!i&&!o&&!a&&l.length===0&&c.length===0&&!s)return To(e);if(o&&u.length===0&&!s)return L(`complete: -F: option requires a command name
|
|
186
|
+
`,2);if(s){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),o!==void 0&&(f.function=o),a!==void 0&&(f.command=a),l.length>0&&(f.options=l),c.length>0&&(f.actions=c),e.state.defaultCompletionSpec=f,ee("")}for(let f of u){let d=Object.create(null);i!==void 0&&(d.wordlist=i),o!==void 0&&(d.function=o),a!==void 0&&(d.command=a),l.length>0&&(d.options=l),c.length>0&&(d.actions=c),e.state.completionSpecs.set(f,d)}return ee("")}function To(e,t){let n=e.state.completionSpecs??new Map;if(n.size===0&&!e.state.defaultCompletionSpec){if(t&&t.length>0){let i="";for(let o of t)i+=`complete: ${o}: no completion specification
|
|
187
|
+
`;return F("",i,1)}return ee("")}let r=[],s=t||Array.from(n.keys());for(let i of s){let o=n.get(i);if(!o){if(t)return F(r.join(`
|
|
187
188
|
`)+(r.length>0?`
|
|
188
189
|
`:""),`complete: ${i}: no completion specification
|
|
189
|
-
`,1);continue}let a="complete";if(o.options)for(let l of o.options)a+=` -o ${
|
|
190
|
+
`,1);continue}let a="complete";if(o.options)for(let l of o.options)a+=` -o ${Se(l)}`;if(o.actions)for(let l of o.actions)a+=` -A ${Se(l)}`;o.wordlist!==void 0&&(o.wordlist.includes(" ")||o.wordlist.includes("'")?a+=` -W ${Se(o.wordlist)}`:a+=` -W ${Se(o.wordlist)}`),o.function!==void 0&&(a+=` -F ${Se(o.function)}`),o.command!==void 0&&(a+=` -C ${Se(o.command)}`),o.isDefault&&(a+=" -D"),a+=`${i.startsWith("-")?" -- ":" "}${Se(i)}`,r.push(a)}if(!t&&e.state.defaultCompletionSpec){let i=e.state.defaultCompletionSpec,o="complete";for(let a of i.options??[])o+=` -o ${Se(a)}`;for(let a of i.actions??[])o+=` -A ${Se(a)}`;i.wordlist!==void 0&&(o+=` -W ${Se(i.wordlist)}`),i.function!==void 0&&(o+=` -F ${Se(i.function)}`),i.command!==void 0&&(o+=` -C ${Se(i.command)}`),o+=" -D",r.push(o)}return r.length===0?ee(""):ee(`${r.join(`
|
|
190
191
|
`)}
|
|
191
|
-
`)}var
|
|
192
|
-
`,2);let c=t[a];if(!
|
|
193
|
-
`,2);s.push(c)}else if(l==="+o"){if(a++,a>=t.length)return
|
|
194
|
-
`,2);let c=t[a];if(!
|
|
195
|
-
`,2);i.push(c)}else if(l==="--"){o.push(...t.slice(a+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&o.push(l)}if(n){let a=e.state.defaultCompletionSpec??{isDefault:!0},l=new Set(a.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.defaultCompletionSpec=a,ee("")}if(r){let a=e.state.emptyCompletionSpec??Object.create(null),l=new Set(a.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.emptyCompletionSpec=a,ee("")}if(o.length>0){for(let a of o){let l=e.state.completionSpecs.get(a)??{},c=new Set(l.options??[]);for(let u of s)c.add(u);for(let u of i)c.delete(u);l.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set(a,l)}return ee("")}return
|
|
196
|
-
`,1)}function
|
|
197
|
-
`);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new
|
|
198
|
-
`);n=r}throw new Ke(n)}function
|
|
199
|
-
`;else{let f=u.map(d=>{let h=ae(e,i,d)??"",p=
|
|
200
|
-
`}continue}let l=
|
|
192
|
+
`)}var Gu=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Fo(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=[],i=[],o=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-D")n=!0;else if(l==="-E")r=!0;else if(l==="-o"){if(a++,a>=t.length)return L(`compopt: -o: option requires an argument
|
|
193
|
+
`,2);let c=t[a];if(!Gu.includes(c))return L(`compopt: ${c}: invalid option name
|
|
194
|
+
`,2);s.push(c)}else if(l==="+o"){if(a++,a>=t.length)return L(`compopt: +o: option requires an argument
|
|
195
|
+
`,2);let c=t[a];if(!Gu.includes(c))return L(`compopt: ${c}: invalid option name
|
|
196
|
+
`,2);i.push(c)}else if(l==="--"){o.push(...t.slice(a+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&o.push(l)}if(n){let a=e.state.defaultCompletionSpec??{isDefault:!0},l=new Set(a.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.defaultCompletionSpec=a,ee("")}if(r){let a=e.state.emptyCompletionSpec??Object.create(null),l=new Set(a.options??[]);for(let c of s)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.emptyCompletionSpec=a,ee("")}if(o.length>0){for(let a of o){let l=e.state.completionSpecs.get(a)??{},c=new Set(l.options??[]);for(let u of s)c.add(u);for(let u of i)c.delete(u);l.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set(a,l)}return ee("")}return L(`compopt: not currently executing completion function
|
|
197
|
+
`,1)}function Mo(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new qt;return te}if(t.length>1)throw new G(1,"",`bash: continue: too many arguments
|
|
198
|
+
`);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new G(1,"",`bash: continue: ${t[0]}: numeric argument required
|
|
199
|
+
`);n=r}throw new Ke(n)}function Hu(e,t){let n="";return e.state.integerVars?.has(t)&&(n+="i"),e.state.lowercaseVars?.has(t)&&(n+="l"),ue(e,t)&&(n+="n"),e.state.readonlyVars?.has(t)&&(n+="r"),e.state.uppercaseVars?.has(t)&&(n+="u"),e.state.exportedVars?.has(t)&&(n+="x"),n===""?"--":`-${n}`}function Bo(e){return Se(e)}function Wo(e){return`'${e.replace(/'/g,"'\\''")}'`}function Zu(e,t){let n="",r="",s=!1;for(let i of t){let o=Hu(e,i);if(e.state.associativeArrays?.has(i)){let u=xt(e,i);if(u.length===0)n+=`declare -A ${i}=()
|
|
200
|
+
`;else{let f=u.map(d=>{let h=ae(e,i,d)??"",p=Bo(h);return`[${Wo(d)}]=${p}`});n+=`declare -A ${i}=(${f.join(" ")})
|
|
201
|
+
`}continue}let l=Ae(e,i);if(l.length>0){let u=l.map(f=>{let d=ae(e,i,f)??"";return`[${f}]=${yn(d)}`});n+=`declare -a ${i}=(${u.join(" ")})
|
|
201
202
|
`;continue}if(Ne(e,i)){n+=`declare -a ${i}=()
|
|
202
|
-
`;continue}let c=e.state.env.get(i);if(c!==void 0)n+=`declare ${o} ${i}=${
|
|
203
|
+
`;continue}let c=e.state.env.get(i);if(c!==void 0)n+=`declare ${o} ${i}=${xr(c)}
|
|
203
204
|
`;else{let u=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);u||f?n+=`declare ${o} ${i}
|
|
204
205
|
`:(r+=`bash: declare: ${i}: not found
|
|
205
|
-
`,s=!0)}}return
|
|
206
|
-
`;else{let
|
|
207
|
-
`}continue}if(p.length>0){let
|
|
206
|
+
`,s=!0)}}return F(n,r,s?1:0)}function Qu(e,t){let{filterExport:n,filterReadonly:r,filterNameref:s,filterIndexedArray:i,filterAssocArray:o}=t,a=n||r||s||i||o,l="",c=new Set;for(let f of e.state.env.keys())f.startsWith("BASH_")||c.add(f);for(let f of e.state.arrays?.keys()??[])c.add(f);if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())c.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)c.add(f);let u=Array.from(c).sort();for(let f of u){let d=Hu(e,f),h=e.state.associativeArrays?.has(f),p=Ae(e,f),m=!h&&Ne(e,f);if(a&&(o&&!h||i&&!m||n&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||s&&!ue(e,f)))continue;if(h){let b=xt(e,f);if(b.length===0)l+=`declare -A ${f}=()
|
|
207
|
+
`;else{let w=b.map(E=>{let S=ae(e,f,E)??"",v=Bo(S);return`[${Wo(E)}]=${v}`});l+=`declare -A ${f}=(${w.join(" ")})
|
|
208
|
+
`}continue}if(p.length>0){let b=p.map(w=>{let E=ae(e,f,w)??"";return`[${w}]=${yn(E)}`});l+=`declare -a ${f}=(${b.join(" ")})
|
|
208
209
|
`;continue}if(Ne(e,f)){l+=`declare -a ${f}=()
|
|
209
|
-
`;continue}let
|
|
210
|
-
`)}return ee(l)}function
|
|
211
|
-
`;else{let i=s.map(o=>{let a=ae(e,r,o)??"",l=
|
|
212
|
-
`}}return ee(t)}function
|
|
210
|
+
`;continue}let y=e.state.env.get(f);y!==void 0&&(l+=`declare ${d} ${f}=${xr(y)}
|
|
211
|
+
`)}return ee(l)}function Ku(e){let t="",n=Array.from(e.state.associativeArrays??[]).sort();for(let r of n){let s=xt(e,r);if(s.length===0)t+=`declare -A ${r}=()
|
|
212
|
+
`;else{let i=s.map(o=>{let a=ae(e,r,o)??"",l=Bo(a);return`[${Wo(o)}]=${l}`});t+=`declare -A ${r}=(${i.join(" ")})
|
|
213
|
+
`}}return ee(t)}function Xu(e){let t="",n=new Set(Array.from(e.state.arrays??[]).filter(([,s])=>s.kind==="indexed").map(([s])=>s)),r=Array.from(n).sort();for(let s of r){let i=Ae(e,s);if(i.length===0)t+=`declare -a ${s}=()
|
|
213
214
|
`;else{let o=i.map(a=>{let l=ae(e,s,a)??"";return`[${a}]=${yn(l)}`});t+=`declare -a ${s}=(${o.join(" ")})
|
|
214
|
-
`}}return ee(t)}function
|
|
215
|
-
`)}return ee(t)}function
|
|
216
|
-
`,2)}}}else if(
|
|
217
|
-
`,2);else
|
|
218
|
-
`;return ee(
|
|
219
|
-
|
|
215
|
+
`}}return ee(t)}function Yu(e){let t="",n=new Set;for(let s of e.state.env.keys())s.startsWith("BASH_")||n.add(s);let r=Array.from(n).sort();for(let s of r){if(e.state.associativeArrays?.has(s)||Ae(e,s).length>0||Ne(e,s))continue;let a=e.state.env.get(s);a!==void 0&&(t+=`${s}=${Se(a)}
|
|
216
|
+
`)}return ee(t)}function Vo(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function Pr(e,t){return e.state.integerVars?.has(t)??!1}function zo(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function im(e,t){return e.state.lowercaseVars?.has(t)??!1}function Uo(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function om(e,t){return e.state.uppercaseVars?.has(t)??!1}function Jn(e,t,n){return im(e,t)?n.toLowerCase():om(e,t)?n.toUpperCase():n}async function Ju(e,t){try{let n=new Q,r=re(n,t),s=await J(e,r.expression);return String(s)}catch{return"0"}}function am(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let n=t[0],r=n.length;if(e[r]!=="[")return null;let s=0,i=r+1;for(;r<e.length;r++)if(e[r]==="[")s++;else if(e[r]==="]"&&(s--,s===0))break;if(s!==0)return null;let o=e.slice(i,r);if(r++,e[r]!=="=")return null;r++;let a=e.slice(r);return{name:n,indexExpr:o,value:a}}async function jo(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,c=!1,u=!1,f=!1,d=!1,h=!1,p=!1,m=!1,y=!1,b=!1,w=[];for(let $=0;$<t.length;$++){let N=t[$];if(N==="-a")r=!0;else if(N==="-A")s=!0;else if(N==="-r")i=!0;else if(N==="-x")o=!0;else if(N==="-p")a=!0;else if(N==="-n")l=!0;else if(N==="+n")c=!0;else if(N==="+a")u=!0;else if(N==="+x")f=!0;else if(N==="--"){w.push(...t.slice($+1));break}else if(N.startsWith("+")){for(let O of N.slice(1))if(O==="n")c=!0;else if(O==="a")u=!0;else if(O==="x")f=!0;else if(O!=="r"){if(O!=="i"){if(!(O==="f"||O==="F"))return F("",`bash: typeset: +${O}: invalid option
|
|
217
|
+
`,2)}}}else if(N==="-i")d=!0;else if(N==="-l")h=!0;else if(N==="-u")p=!0;else if(N==="-f")m=!0;else if(N==="-F")y=!0;else if(N==="-g")b=!0;else if(N.startsWith("-"))for(let O of N.slice(1))if(O==="a")r=!0;else if(O==="A")s=!0;else if(O==="r")i=!0;else if(O==="x")o=!0;else if(O==="p")a=!0;else if(O==="n")l=!0;else if(O==="i")d=!0;else if(O==="l")h=!0;else if(O==="u")p=!0;else if(O==="f")m=!0;else if(O==="F")y=!0;else if(O==="g")b=!0;else return F("",`bash: typeset: -${O}: invalid option
|
|
218
|
+
`,2);else w.push(N)}let S=e.state.localScopes.length>0&&!b,v=$=>{if(!S)return;let N=e.state.localScopes[e.state.localScopes.length-1];N.has($)||N.set($,e.state.env.get($))},A=$=>{if(!S)return;let N=e.state.localScopes[e.state.localScopes.length-1];for(N.has($)||N.set($,e.state.env.get($)),e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let O=e.state.localArrayScopes.at(-1);if(O&&!O.has($)){let R=ke(e,$);O.set($,R?Me(R):void 0)}},k=$=>{S&&fn(e,$)};if(y){if(w.length===0){let O=Array.from(e.state.functions.keys()).sort(),R="";for(let W of O)R+=`declare -f ${W}
|
|
219
|
+
`;return ee(R)}let $=!0,N="";for(let O of w)e.state.functions.has(O)?N+=`${O}
|
|
220
|
+
`:$=!1;return F(N,"",$?0:1)}if(m){if(w.length===0){let N="",O=Array.from(e.state.functions.keys()).sort();for(let R of O)N+=`${R} ()
|
|
220
221
|
{
|
|
221
222
|
# function body
|
|
222
223
|
}
|
|
223
|
-
`;return ee(
|
|
224
|
-
`,
|
|
225
|
-
`,
|
|
226
|
-
`,
|
|
227
|
-
`,
|
|
228
|
-
`,
|
|
229
|
-
`,
|
|
230
|
-
`}}return ee(a)}for(let a of o){let l=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(l){let d=l[1],h=l[2],p=fe(e,d);if(p)return p;let m=Wt(h,n);if(e.state.associativeArrays?.has(d)){let
|
|
231
|
-
`,2);r=t[a+1],a++}}else{if(l.startsWith("-")&&l!=="-")return
|
|
232
|
-
`,2);if(r!==void 0)return
|
|
233
|
-
`,2);r=l}}if(r===void 0){if(n.length<2)return
|
|
234
|
-
`,1);let a=n[0];n[0]=n[1],n[1]=a,r=n[0]}let s;if(r.startsWith("/"))s=r;else if(r===".."){let a=e.state.cwd.split("/").filter(l=>l);a.pop(),s=`/${a.join("/")}`}else r==="."?s=e.state.cwd:r.startsWith("~")?s=(e.state.env.get("HOME")||"/")+r.slice(1):s=`${e.state.cwd}/${r}`;s=
|
|
235
|
-
`,1)}catch{return
|
|
236
|
-
`,1)}n.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=s,e.state.env.set("PWD",s),e.state.env.set("OLDPWD",e.state.previousDir);let i=e.state.env.get("HOME")||"",o=`${[s,...n].map(a
|
|
237
|
-
`;return ee(o)}function
|
|
238
|
-
`,2):
|
|
239
|
-
`,2);if(n.length===0)return
|
|
240
|
-
`,1);let r=n.shift();if(!r)return
|
|
241
|
-
`,1);e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.set("PWD",r),e.state.env.set("OLDPWD",e.state.previousDir);let s=e.state.env.get("HOME")||"",i=`${[r,...n].map(o
|
|
242
|
-
`;return ee(i)}function
|
|
243
|
-
`,2);else return
|
|
244
|
-
`,1);if(r)return e.state.directoryStack=[],te;let a=[e.state.cwd,...n],l=e.state.env.get("HOME")||"",c;return o?(c=a.map((u,f)=>{let d=s?u
|
|
224
|
+
`;return ee(N)}let $=!0;for(let N of w)e.state.functions.has(N)||($=!1);return F("","",$?0:1)}if(a&&w.length>0)return Zu(e,w);if(a&&w.length===0)return Qu(e,{filterExport:o,filterReadonly:i,filterNameref:l,filterIndexedArray:r,filterAssocArray:s});if(w.length===0&&s&&!a)return Ku(e);if(w.length===0&&r&&!a)return Xu(e);if(w.length===0&&!a)return Yu(e);let x="",D=0;for(let $ of w){let N=$.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(N&&!u){let P=N[1],B=N[2],U=fe(e,P);if(U)return U;if(s&&Ae(e,P).length>0){x+=`bash: declare: ${P}: cannot convert indexed to associative array
|
|
225
|
+
`,D=1;continue}if((r||!s&&!r)&&e.state.associativeArrays?.has(P)){x+=`bash: declare: ${P}: cannot convert associative to indexed array
|
|
226
|
+
`,D=1;continue}let _=s&&B.includes("[")?_s(B,n):void 0,T=_===void 0?Wt(B,{...n,maxElements:s?n.maxElements*2:n.maxElements}):void 0;if(e.executionScope.consumeWork(_?.length??T?.length??0,"declare array assignment"),A(P),s?(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(P),Xt(e,P,"associative")):Xt(e,P,"indexed"),Ee(e,P),e.state.env.delete(P),s&&B.includes("["))for(let[z,ne]of _??[])H(e,P,z,an(e,ne),"associative");else if(s){let z=T??[];for(let ne=0;ne<z.length;ne+=2){let Y=z[ne],Te=ne+1<z.length?z[ne+1]:"";H(e,P,Y,Te,"associative")}}else{let z=T??[];if(z.some(Y=>/^\[[^\]]+\]=/.test(Y))){let Y=0;for(let Te of z){let dt=Te.match(/^\[([^\]]+)\]=(.*)$/);if(dt){let Dt=dt[1],ht=dt[2],pt;if(/^-?\d+$/.test(Dt))pt=Number.parseInt(Dt,10);else try{let It=new Q,ed=re(It,Dt);pt=await J(e,ed.expression)}catch{pt=0}H(e,P,pt,an(e,ht)),Y=pt+1}else H(e,P,Y,Te),Y++}}else for(let Y=0;Y<z.length;Y++)H(e,P,Y,z[Y])}k(P),i&&Ze(e,P),o&&bt(e,P);continue}if(c){let P=$.includes("=")?$.slice(0,$.indexOf("=")):$;if(Xl(e,P),!$.includes("="))continue}if(f){let P=$.includes("=")?$.slice(0,$.indexOf("=")):$;if(ds(e,P),!$.includes("="))continue}let O=am($);if(O){let{name:P,indexExpr:B,value:U}=O,_=fe(e,P);if(_)return _;A(P);let T;try{let z=new Q,ne=re(z,B);T=await J(e,ne.expression)}catch{let z=parseInt(B,10);T=Number.isNaN(z)?0:z}H(e,P,T,U),k(P),i&&Ze(e,P),o&&bt(e,P);continue}let R=$.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(R&&!u){let P=R[1],B=R[2],U=fe(e,P);if(U)return U;A(P);let _=Wt(B,n);if(e.state.associativeArrays?.has(P)){let T=_s(B,n);e.executionScope.consumeWork(T.length,"declare array append"),Sn(e,P,T.map(([z])=>z));for(let[z,ne]of T)H(e,P,z,ne,"associative")}else{e.executionScope.consumeWork(_.length,"declare array append");let T=Ae(e,P),z=0,ne=e.state.env.get(P);T.length===0&&ne!==void 0?(H(e,P,0,ne),e.state.env.delete(P),z=1):T.length>0&&(z=Math.max(...T)+1),Sn(e,P,Array.from({length:_.length},(Y,Te)=>z+Te));for(let Y=0;Y<_.length;Y++)H(e,P,z+Y,_[Y])}k(P),i&&Ze(e,P),o&&bt(e,P);continue}let W=$.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(W){let P=W[1],B=W[2],U=fe(e,P);if(U)return U;v(P),d&&Vo(e,P),h&&zo(e,P),p&&Uo(e,P);let T=Ae(e,P).length>0||e.state.associativeArrays?.has(P);if(Pr(e,P)){let z=e.state.env.get(P)??"0",ne=parseInt(z,10)||0,Y=parseInt(await Ju(e,B),10)||0;B=String(ne+Y),e.state.env.set(P,B)}else if(T){B=Jn(e,P,B);let z=ae(e,P,0)??"";H(e,P,0,Gt([z,B],"",e.limits.maxStringLength,"declare append"))}else{B=Jn(e,P,B);let z=e.state.env.get(P)??"";e.state.env.set(P,Gt([z,B],"",e.limits.maxStringLength,"declare append"))}k(P),i&&Ze(e,P),o&&bt(e,P),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(P));continue}if($.includes("=")){let P=$.indexOf("="),B=$.slice(0,P),U=$.slice(P+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(B)){x+=`bash: typeset: \`${B}': not a valid identifier
|
|
227
|
+
`,D=1;continue}let _=fe(e,B);if(_)return _;if(v(B),l){if(U!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(U)){x+=`bash: declare: \`${U}': invalid variable name for name reference
|
|
228
|
+
`,D=1;continue}e.state.env.set(B,U),Bt(e,B),U!==""&&ls(e,U)&&ji(e,B),k(B),i&&Ze(e,B),o&&bt(e,B);continue}if(d&&Vo(e,B),h&&zo(e,B),p&&Uo(e,B),Pr(e,B)&&(U=await Ju(e,U)),U=Jn(e,B,U),ue(e,B)){let T=Be(e,B);T&&T!==B?e.state.env.set(T,U):e.state.env.set(B,U)}else e.state.env.set(B,U);k(B),i&&Ze(e,B),o&&bt(e,B),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(B))}else{let P=$;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(P)){x+=`bash: typeset: \`${P}': not a valid identifier
|
|
229
|
+
`,D=1;continue}if(r||s?A(P):v(P),l){Bt(e,P);let U=e.state.env.get(P);U!==void 0&&U!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(U)?Yl(e,P):U&&ls(e,U)&&ji(e,P),k(P),i&&Ze(e,P),o&&bt(e,P);continue}if(d&&Vo(e,P),h&&zo(e,P),p&&Uo(e,P),s){if(Ae(e,P).length>0){x+=`bash: declare: ${P}: cannot convert indexed to associative array
|
|
230
|
+
`,D=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(P),Xt(e,P,"associative")}let B=Ne(e,P);!e.state.env.has(P)&&!B&&(r||s?Xt(e,P,s?"associative":"indexed"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(P))),k(P),i&&Ze(e,P),o&&bt(e,P)}}return F("",x,D)}async function qo(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-a")r=!0;else if(l==="-A")s=!0;else if(l==="-p")i=!0;else if(l==="--"){o.push(...t.slice(a+1));break}else l.startsWith("-")||o.push(l)}if(o.length===0){let a="",l=Array.from(e.state.readonlyVars||[]).sort();for(let c of l){let u=e.state.env.get(c);if(u!==void 0){let f=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${c}="${f}"
|
|
231
|
+
`}}return ee(a)}for(let a of o){let l=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(l){let d=l[1],h=l[2],p=fe(e,d);if(p)return p;let m=Wt(h,n);if(e.state.associativeArrays?.has(d)){let y=_s(h,n);e.executionScope.consumeWork(y.length,"readonly array append"),Sn(e,d,y.map(([b])=>b));for(let[b,w]of y)H(e,d,b,w,"associative")}else{e.executionScope.consumeWork(m.length,"readonly array append");let y=Ae(e,d),b=0,w=e.state.env.get(d);y.length===0&&w!==void 0?(H(e,d,0,w),e.state.env.delete(d),b=1):y.length>0&&(b=Math.max(...y)+1),Sn(e,d,Array.from({length:m.length},(E,S)=>b+S));for(let E=0;E<m.length;E++)H(e,d,b+E,m[E])}Ze(e,d);continue}let c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c){let d=c[1],h=c[2],p=fe(e,d);if(p)return p;let m=e.state.env.get(d)??"";e.state.env.set(d,Gt([m,h],"",e.limits.maxStringLength,"readonly append")),Ze(e,d);continue}let u=Cu(a,n);if(u.value===void 0&&!u.isArray){Ze(e,u.name);continue}let f=await Nu(e,u,{makeReadonly:!0});if(f)return f}return te}function Go(e){return e.state.directoryStack??=[],e.state.directoryStack}function $r(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function lm(e){let t=e.split("/").filter(r=>r&&r!=="."),n=[];for(let r of t)r===".."?n.pop():n.push(r);return`/${n.join("/")}`}async function Ho(e,t){let n=Go(e),r;for(let a=0;a<t.length;a++){let l=t[a];if(l==="--"){if(a+1<t.length){if(r!==void 0)return L(`bash: pushd: too many arguments
|
|
232
|
+
`,2);r=t[a+1],a++}}else{if(l.startsWith("-")&&l!=="-")return L(`bash: pushd: ${l}: invalid option
|
|
233
|
+
`,2);if(r!==void 0)return L(`bash: pushd: too many arguments
|
|
234
|
+
`,2);r=l}}if(r===void 0){if(n.length<2)return L(`bash: pushd: no other directory
|
|
235
|
+
`,1);let a=n[0];n[0]=n[1],n[1]=a,r=n[0]}let s;if(r.startsWith("/"))s=r;else if(r===".."){let a=e.state.cwd.split("/").filter(l=>l);a.pop(),s=`/${a.join("/")}`}else r==="."?s=e.state.cwd:r.startsWith("~")?s=(e.state.env.get("HOME")||"/")+r.slice(1):s=`${e.state.cwd}/${r}`;s=lm(s);try{if(!(await e.fs.stat(s)).isDirectory)return L(`bash: pushd: ${r}: Not a directory
|
|
236
|
+
`,1)}catch{return L(`bash: pushd: ${r}: No such file or directory
|
|
237
|
+
`,1)}n.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=s,e.state.env.set("PWD",s),e.state.env.set("OLDPWD",e.state.previousDir);let i=e.state.env.get("HOME")||"",o=`${[s,...n].map(a=>$r(a,i)).join(" ")}
|
|
238
|
+
`;return ee(o)}function Zo(e,t){let n=Go(e);for(let o of t)if(o!=="--")return o.startsWith("-")&&o!=="-"?L(`bash: popd: ${o}: invalid option
|
|
239
|
+
`,2):L(`bash: popd: too many arguments
|
|
240
|
+
`,2);if(n.length===0)return L(`bash: popd: directory stack empty
|
|
241
|
+
`,1);let r=n.shift();if(!r)return L(`bash: popd: directory stack empty
|
|
242
|
+
`,1);e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.set("PWD",r),e.state.env.set("OLDPWD",e.state.previousDir);let s=e.state.env.get("HOME")||"",i=`${[r,...n].map(o=>$r(o,s)).join(" ")}
|
|
243
|
+
`;return ee(i)}function Qo(e,t){let n=Go(e),r=!1,s=!1,i=!1,o=!1;for(let u of t)if(u!=="--")if(u.startsWith("-"))for(let f of u.slice(1))if(f==="c")r=!0;else if(f==="l")s=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,o=!0;else return L(`bash: dirs: -${f}: invalid option
|
|
244
|
+
`,2);else return L(`bash: dirs: too many arguments
|
|
245
|
+
`,1);if(r)return e.state.directoryStack=[],te;let a=[e.state.cwd,...n],l=e.state.env.get("HOME")||"",c;return o?(c=a.map((u,f)=>{let d=s?u:$r(u,l);return` ${f} ${d}`}).join(`
|
|
245
246
|
`),c+=`
|
|
246
|
-
`):i?c=a.map(u=>s?u
|
|
247
|
+
`):i?c=a.map(u=>s?u:$r(u,l)).join(`
|
|
247
248
|
`)+`
|
|
248
|
-
`:c=a.map(u=>s?u
|
|
249
|
-
`,ee(c)}async function
|
|
249
|
+
`:c=a.map(u=>s?u:$r(u,l)).join(" ")+`
|
|
250
|
+
`,ee(c)}async function qs(e,t,n,r=!1){let s=t;if(s.length>0){let l=s[0];if(l==="--")s=s.slice(1);else if(l.startsWith("-")&&l!=="-"&&l.length>1)return L(`bash: eval: ${l}: invalid option
|
|
250
251
|
eval: usage: eval [arg ...]
|
|
251
|
-
`,2)}if(s.length===0)return te;let i=s.join(" ");if(i.trim()==="")return te;let o=e.state.groupStdin,a=r||n!==void 0&&n!=="";a&&(e.state.groupStdin=n??"");try{let l=He(i);return await e.executeScript(l)}catch(l){if(l instanceof Qe||l instanceof Ke||l instanceof Le||l instanceof
|
|
252
|
-
`);throw l}finally{(a||o!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=o)}}function
|
|
253
|
-
`,n=2;else{let i=BigInt(s);n=Number((i%256n+256n)%256n)}}throw new
|
|
254
|
-
`)}return ee(o)}if(n){for(let o of r){let a,l;if(o.includes("=")){let c=o.indexOf("=");a=o.slice(0,c),l=o.slice(c+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return
|
|
255
|
-
`,1);l!==void 0&&(fe(e,a),e.state.env.set(a,l)),
|
|
256
|
-
`,i=1;continue}if(l!==void 0)if(fe(e,a),c){let f=e.state.env.get(a)??"";e.state.env.set(a,f+l)}else e.state.env.set(a,l);else e.state.env.has(a)||e.state.env.set(a,"");
|
|
257
|
-
`);let n=t[0],r=t[1],s=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r),i=n.startsWith(":"),o=i?n.slice(1):n,a;if(t.length>2)a=t.slice(2);else{let m=Number.parseInt(e.state.env.get("#")||"0",10);a=[];for(let
|
|
252
|
+
`,2)}if(s.length===0)return te;let i=s.join(" ");if(i.trim()==="")return te;let o=e.state.groupStdin,a=r||n!==void 0&&n!=="";a&&(e.state.groupStdin=n??"");try{let l=He(i);return await e.executeScript(l)}catch(l){if(l instanceof Qe||l instanceof Ke||l instanceof Le||l instanceof G)throw l;if(l.name==="ParseException")return L(`bash: eval: ${l.message}
|
|
253
|
+
`);throw l}finally{(a||o!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=o)}}function Ko(e,t){let n,r="";if(t.length===0)n=e.state.lastExitCode;else{let s=t[0];if(s===""||!/^-?\d+$/.test(s))r=`bash: exit: ${s}: numeric argument required
|
|
254
|
+
`,n=2;else{let i=BigInt(s);n=Number((i%256n+256n)%256n)}}throw new G(n,"",r)}function Xo(e,t){let n=!1,r=[];for(let o of t)o==="-n"?n=!0:o==="-p"||o==="--"||r.push(o);if(r.length===0&&!n){let o="",a=e.state.exportedVars??new Set,l=Array.from(a).sort();for(let c of l){let u=e.state.env.get(c);u!==void 0&&(o+=`declare -x ${c}=${xr(u)}
|
|
255
|
+
`)}return ee(o)}if(n){for(let o of r){let a,l;if(o.includes("=")){let c=o.indexOf("=");a=o.slice(0,c),l=o.slice(c+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return F("",`bash: export: \`${o}': not a valid identifier
|
|
256
|
+
`,1);l!==void 0&&(fe(e,a),e.state.env.set(a,l)),ds(e,a)}return te}let s="",i=0;for(let o of r){let a,l,c=!1,u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(u)a=u[1],l=u[2],c=!0;else if(o.includes("=")){let f=o.indexOf("=");a=o.slice(0,f),l=o.slice(f+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){s+=`bash: export: \`${o}': not a valid identifier
|
|
257
|
+
`,i=1;continue}if(l!==void 0)if(fe(e,a),c){let f=e.state.env.get(a)??"";e.state.env.set(a,f+l)}else e.state.env.set(a,l);else e.state.env.has(a)||e.state.env.set(a,"");bt(e,a)}return F("",s,i)}function Gs(e,t){if(t.length<2)return L(`bash: getopts: usage: getopts optstring name [arg ...]
|
|
258
|
+
`);let n=t[0],r=t[1],s=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r),i=n.startsWith(":"),o=i?n.slice(1):n,a;if(t.length>2)a=t.slice(2);else{let m=Number.parseInt(e.state.env.get("#")||"0",10);a=[];for(let y=1;y<=m;y++)a.push(e.state.env.get(String(y))||"")}let l=Number.parseInt(e.state.env.get("OPTIND")||"1",10);l<1&&(l=1);let c=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),l>a.length)return s||e.state.env.set(r,"?"),e.state.env.set("OPTIND",String(a.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:1,stdout:"",stderr:""};let u=a[l-1];if(!u||u==="-"||!u.startsWith("-"))return s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};if(u==="--")return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};let f=c===0?1:c,d=u[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),Gs(e,t);let h=o.indexOf(d);if(h===-1){let m="";return i?e.state.env.set("OPTARG",d):m=`bash: illegal option -- ${d}
|
|
258
259
|
`,s||e.state.env.set(r,"?"),f+1<u.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0")),{exitCode:s?2:0,stdout:"",stderr:m}}if(h+1<o.length&&o[h+1]===":")if(f+1<u.length)e.state.env.set("OPTARG",u.slice(f+1)),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0");else{if(l>=a.length){let m="";return i?(e.state.env.set("OPTARG",d),s||e.state.env.set(r,":")):(m=`bash: option requires an argument -- ${d}
|
|
259
|
-
`,s||e.state.env.set(r,"?")),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:0,stdout:"",stderr:m}}e.state.env.set("OPTARG",a[l]),e.state.env.set("OPTIND",String(l+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1<u.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return s||e.state.env.set(r,d),{exitCode:s?2:0,stdout:"",stderr:""}}async function
|
|
260
|
-
`,1);a=t[c],c++}else if(p.startsWith("-")&&p.length>1){for(let m of p.slice(1))if(m==="r")n=!0;else if(m==="d")r=!0;else if(m==="l")s=!0;else if(m==="t")o=!0;else return m==="p"?
|
|
261
|
-
`,1):
|
|
262
|
-
`,1);c++}else l.push(p),c++}if(n)return e.state.hashTable.clear(),te;if(r){if(l.length===0)return
|
|
263
|
-
`,1);let p=!1,m="";for(let
|
|
264
|
-
`,p=!0);return p?
|
|
265
|
-
`,1);let p="",m=!1,
|
|
266
|
-
`:p+=`${
|
|
267
|
-
`:(
|
|
268
|
-
`,m=!0)}return m?{exitCode:1,stdout:p,stderr:
|
|
260
|
+
`,s||e.state.env.set(r,"?")),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:0,stdout:"",stderr:m}}e.state.env.set("OPTARG",a[l]),e.state.env.set("OPTIND",String(l+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1<u.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return s||e.state.env.set(r,d),{exitCode:s?2:0,stdout:"",stderr:""}}async function Yo(e,t){e.state.hashTable||(e.state.hashTable=new Map);let n=!1,r=!1,s=!1,i=!1,o=!1,a="",l=[],c=0;for(;c<t.length;){let p=t[c];if(p==="--"){c++,l.push(...t.slice(c));break}if(p==="-r")n=!0,c++;else if(p==="-d")r=!0,c++;else if(p==="-l")s=!0,c++;else if(p==="-t")o=!0,c++;else if(p==="-p"){if(i=!0,c++,c>=t.length)return L(`bash: hash: -p: option requires an argument
|
|
261
|
+
`,1);a=t[c],c++}else if(p.startsWith("-")&&p.length>1){for(let m of p.slice(1))if(m==="r")n=!0;else if(m==="d")r=!0;else if(m==="l")s=!0;else if(m==="t")o=!0;else return m==="p"?L(`bash: hash: -p: option requires an argument
|
|
262
|
+
`,1):L(`bash: hash: -${m}: invalid option
|
|
263
|
+
`,1);c++}else l.push(p),c++}if(n)return e.state.hashTable.clear(),te;if(r){if(l.length===0)return L(`bash: hash: -d: option requires an argument
|
|
264
|
+
`,1);let p=!1,m="";for(let y of l)e.state.hashTable.has(y)?e.state.hashTable.delete(y):(m+=`bash: hash: ${y}: not found
|
|
265
|
+
`,p=!0);return p?L(m,1):te}if(o){if(l.length===0)return L(`bash: hash: -t: option requires an argument
|
|
266
|
+
`,1);let p="",m=!1,y="";for(let b of l){let w=e.state.hashTable.get(b);w?l.length>1?p+=`${b} ${w}
|
|
267
|
+
`:p+=`${w}
|
|
268
|
+
`:(y+=`bash: hash: ${b}: not found
|
|
269
|
+
`,m=!0)}return m?{exitCode:1,stdout:p,stderr:y}:ee(p)}if(i){if(l.length===0)return L(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
|
|
269
270
|
`,1);let p=l[0];return e.state.hashTable.set(p,a),te}if(l.length===0){if(e.state.hashTable.size===0)return ee(`hash: hash table empty
|
|
270
|
-
`);let p="";if(s)for(let[m,
|
|
271
|
+
`);let p="";if(s)for(let[m,y]of e.state.hashTable){let b=m.startsWith("-")?" --":"";p+=`builtin hash -p ${Se(y)}${b} ${Se(m)}
|
|
271
272
|
`}else{p=`hits command
|
|
272
273
|
`;for(let[,m]of e.state.hashTable)p+=` 1 ${m}
|
|
273
274
|
`}return ee(p)}let u=!1,f="",h=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let p of l){if(p.includes("/")){f+=`bash: hash: ${p}: cannot use / in name
|
|
274
|
-
`,u=!0;continue}let m=!1;for(let
|
|
275
|
-
`,u=!0)}return u?
|
|
275
|
+
`,u=!0;continue}let m=!1;for(let y of h){if(!y)continue;let b=`${y}/${p}`;if(await e.fs.exists(b)){e.state.hashTable.set(p,b),m=!0;break}}m||(f+=`bash: hash: ${p}: not found
|
|
276
|
+
`,u=!0)}return u?L(f,1):te}var ef=new Map([[":",[": [arguments]",`Null command.
|
|
276
277
|
No effect; the command does nothing.
|
|
277
278
|
Exit Status:
|
|
278
279
|
Always succeeds.`]],[".",[". filename [arguments]",`Execute commands from a file in the current shell.
|
|
@@ -617,37 +618,37 @@ eval: usage: eval [arg ...]
|
|
|
617
618
|
job specification, and reports its termination status.
|
|
618
619
|
Exit Status:
|
|
619
620
|
Returns the status of the last ID; fails if ID is invalid or an invalid
|
|
620
|
-
option is given.`]]]),
|
|
621
|
-
`,2)}s++}else r.push(l),s++}if(r.length===0)return
|
|
622
|
-
`,o=!0;continue}for(let u of c){let f=
|
|
621
|
+
option is given.`]]]),tf=[...ef.keys()].sort();function Jo(e,t){let n=!1,r=[],s=0;for(;s<t.length;){let l=t[s];if(l==="--"){for(s++;s<t.length;)r.push(t[s]),s++;break}if(l.startsWith("-")&&l.length>1){for(let c=1;c<l.length;c++){let u=l[c];if(u==="s")n=!0;else return L(`bash: help: -${u}: invalid option
|
|
622
|
+
`,2)}s++}else r.push(l),s++}if(r.length===0)return um();let i="",o=!1,a="";for(let l of r){let c=cm(l);if(c.length===0){a+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
|
|
623
|
+
`,o=!0;continue}for(let u of c){let f=ef.get(u);if(!f)continue;let[d,h]=f;n?i+=`${u}: ${d}
|
|
623
624
|
`:i+=`${u}: ${d}
|
|
624
625
|
${h}
|
|
625
|
-
`}}return{exitCode:o?1:0,stdout:i,stderr:a}}function
|
|
626
|
+
`}}return{exitCode:o?1:0,stdout:i,stderr:a}}function cm(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),n=ge(`^${t}$`);return tf.filter(r=>n.test(r))}function um(){let e=[];e.push("just-bash shell builtins"),e.push("These shell commands are defined internally. Type `help' to see this list."),e.push("Type `help name' to find out more about the function `name'."),e.push("");let t=36,n=tf.slice(),r=Math.ceil(n.length/2);for(let s=0;s<r;s++){let i=n[s]||"",o=n[s+r]||"",a=i.padEnd(t);e.push(o?`${a}${o}`:i)}return ee(`${e.join(`
|
|
626
627
|
`)}
|
|
627
|
-
`)}function
|
|
628
|
-
`);let n=
|
|
629
|
-
`)}return
|
|
630
|
-
`);let r=e.state.localScopes[e.state.localScopes.length-1];for(e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let s=e.state.localArrayScopes.at(-1),i=d=>{if(r.has(d)||r.set(d,e.state.env.get(d)),s&&!s.has(d)){let h=
|
|
631
|
-
`)}return
|
|
632
|
-
`,a=1;continue}fe(e,h,"bash");let v=Wt(
|
|
633
|
-
`,a=1;continue}let
|
|
634
|
-
`,a=1;continue}e.state.env.set(h,p),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(h))}else{let
|
|
635
|
-
`,s=0,i=0,o=0,a=!1,l="MAPFILE",c=0;for(;c<t.length;){let
|
|
636
|
-
`,c+=2):
|
|
637
|
-
`,1);if(!Number.isSafeInteger(i)||i<0)return
|
|
638
|
-
`,1);fe(e,l,"mapfile");let u=n;!u&&e.state.groupStdin!==void 0&&(u=e.state.groupStdin);let f=[],d=0,h=0,p=0,m=e.limits.maxArrayElements,
|
|
639
|
-
`,1);
|
|
640
|
-
`,1);E
|
|
641
|
-
`,1);i===0&&Ee(e,l);for(let
|
|
642
|
-
`,o="",a=-1,l=-1,c=null,u=-1,f=-1,d=[],h=0,p=!1,m=(
|
|
643
|
-
`,1);fe(e,
|
|
628
|
+
`)}function fm(e){let t=[],n="",r=0;for(let s of e){for(let i of s)i==="("?r++:i===")"&&r--;n?n+=` ${s}`:n=s,r===0&&(t.push(n),n="")}return n&&t.push(n),t}async function ea(e,t){if(t.length===0)return L(`bash: let: expression expected
|
|
629
|
+
`);let n=fm(t),r=0;for(let s of n)try{let o=He(`(( ${s} ))`).statements[0];if(o&&o.pipelines.length>0&&o.pipelines[0].commands.length>0){let a=o.pipelines[0].commands[0];a.type==="ArithmeticCommand"&&(r=await J(e,a.expression.expression))}}catch(i){return L(`bash: let: ${s}: ${i.message}
|
|
630
|
+
`)}return F("","",r===0?1:0)}async function ta(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength};if(e.state.localScopes.length===0)return L(`bash: local: can only be used in a function
|
|
631
|
+
`);let r=e.state.localScopes[e.state.localScopes.length-1];for(e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let s=e.state.localArrayScopes.at(-1),i=d=>{if(r.has(d)||r.set(d,e.state.env.get(d)),s&&!s.has(d)){let h=ke(e,d);s.set(d,h?Me(h):void 0)}},o="",a=0,l=!1,c=!1,u=!1,f=[];for(let d of t)if(d==="-n")l=!0;else if(d==="-a")c=!0;else if(d==="-p")u=!0;else if(d.startsWith("-")&&!d.includes("="))for(let h of d.slice(1))h==="n"?l=!0:h==="a"?c=!0:h==="p"&&(u=!0);else f.push(d);if(f.length===0){let d="",h=Array.from(r.keys()).sort();for(let p of h){let m=e.state.env.get(p);m!==void 0&&(d+=`${p}=${m}
|
|
632
|
+
`)}return F(d,"",0)}for(let d of f){let h,p,m=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(m){h=m[1];let S=m[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(h)){o+=`bash: local: \`${d}': not a valid identifier
|
|
633
|
+
`,a=1;continue}fe(e,h,"bash");let v=Wt(S,n);e.executionScope.consumeWork(v.length,"local array assignment"),i(h),Ee(e,h),Xt(e,h,"indexed");for(let A=0;A<v.length;A++)H(e,h,A,v[A]);fn(e,h),l&&Bt(e,h);continue}let y=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(y){h=y[1];let S=y[2];fe(e,h,"bash"),i(h);let v=Wt(S,n);e.executionScope.consumeWork(v.length,"local array append");let A=Ae(e,h),k=0,x=e.state.env.get(h);A.length===0&&x!==void 0?(H(e,h,0,x),e.state.env.delete(h),k=1):A.length>0&&(k=Math.max(...A)+1),Sn(e,h,Array.from({length:v.length},(D,$)=>k+$));for(let D=0;D<v.length;D++)H(e,h,k+D,v[D]);fn(e,h),l&&Bt(e,h);continue}let b=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(b){h=b[1];let S=b[2];fe(e,h,"bash"),r.has(h)||r.set(h,e.state.env.get(h));let v=e.state.env.get(h)??"";e.state.env.set(h,Gt([v,S],"",e.limits.maxStringLength,"local append")),fn(e,h),l&&Bt(e,h);continue}let w=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(w){h=w[1];let S=w[2],v=w[3];fe(e,h,"bash"),i(h);let A;try{let k=new Q,x=re(k,S);A=await J(e,x.expression)}catch{let k=parseInt(S,10);A=Number.isNaN(k)?0:k}H(e,h,A,v),fn(e,h),l&&Bt(e,h);continue}if(d.includes("=")){let S=d.indexOf("=");h=d.slice(0,S),p=d.slice(S+1)}else h=d;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(h)){o+=`bash: local: \`${d}': not a valid identifier
|
|
634
|
+
`,a=1;continue}let E=r.has(h);if(p!==void 0){let S=e.state.env.get(h);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(h),A=e.state.mutatedTempEnvVars?.has(h);if(!v&&!A)for(let k=e.state.tempEnvBindings.length-1;k>=0;k--){let x=e.state.tempEnvBindings[k];if(x.has(h)){S=x.get(h);break}}}Ru(e,h,S)}if(!E){let S=e.state.env.get(h);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let A=e.state.tempEnvBindings[v];if(A.has(h)){S=A.get(h);break}}r.set(h,S),c&&i(h)}if(c&&p===void 0)Ee(e,h),Xt(e,h,"indexed");else if(p!==void 0){if(fe(e,h,"bash"),l&&p!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(p)){o+=`bash: local: \`${p}': invalid variable name for name reference
|
|
635
|
+
`,a=1;continue}e.state.env.set(h,p),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(h))}else{let S=e.state.tempEnvBindings?.some(v=>v.has(h));!E&&!S&&e.state.env.delete(h)}fn(e,h),l&&Bt(e,h)}return F("",o,a)}function na(e,t,n){let r=`
|
|
636
|
+
`,s=0,i=0,o=0,a=!1,l="MAPFILE",c=0;for(;c<t.length;){let w=t[c];w==="-d"&&c+1<t.length?(r=t[c+1]===""?"\0":t[c+1]||`
|
|
637
|
+
`,c+=2):w==="-n"&&c+1<t.length?(s=Number.parseInt(t[c+1],10)||0,c+=2):w==="-O"&&c+1<t.length?(i=Number.parseInt(t[c+1],10)||0,c+=2):w==="-s"&&c+1<t.length?(o=Number.parseInt(t[c+1],10)||0,c+=2):w==="-t"?(a=!0,c++):w==="-u"||w==="-C"||w==="-c"?c+=2:(w.startsWith("-")||(l=w),c++)}if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l))return F("",`mapfile: ${l}: not a valid identifier
|
|
638
|
+
`,1);if(!Number.isSafeInteger(i)||i<0)return F("",`mapfile: invalid array origin
|
|
639
|
+
`,1);fe(e,l,"mapfile");let u=n;!u&&e.state.groupStdin!==void 0&&(u=e.state.groupStdin);let f=[],d=0,h=0,p=0,m=e.limits.maxArrayElements,y=w=>{if(V(w)>e.limits.maxStringLength)throw new C(`mapfile: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");f.push(w)};for(;d<u.length;){e.executionScope.consumeWork(1,"mapfile input");let w=u.indexOf(r,d);if(w===-1){if(d<u.length){if(p<o)p++;else if(s===0||h<s){let v=u.slice(d),A=v.indexOf("\0");if(A!==-1&&(v=v.substring(0,A)),f.length>=m)return F("",`mapfile: array element limit exceeded (${m})
|
|
640
|
+
`,1);y(v),h++}}break}let E=u.slice(d,w),S=E.indexOf("\0");if(S!==-1&&(E=E.substring(0,S)),!a&&r!=="\0"&&(E+=r),d=w+r.length,p<o){p++;continue}if(s>0&&h>=s)break;if(f.length>=m)return F("",`mapfile: array element limit exceeded (${m})
|
|
641
|
+
`,1);y(E),h++}let b=new Set(i===0?[]:e.state.arrays?.get(l)?.elements.keys()??[]);for(let w=0;w<f.length;w++)if(b.add(String(i+w)),b.size>m)return F("",`mapfile: array element limit exceeded (${m})
|
|
642
|
+
`,1);i===0&&Ee(e,l);for(let w=0;w<f.length;w++)H(e,l,i+w,f[w]);return e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=""),{...F("","",0),internalStdinConsumed:u.length}}function ra(e,t,n,r=-1){let s=!1,i=`
|
|
643
|
+
`,o="",a=-1,l=-1,c=null,u=-1,f=-1,d=[],h=0,p=!1,m=(_,T)=>{let z=1;for(;z<_.length;){let ne=_[z];if(ne==="r")s=!0,z++;else if(ne==="s")z++;else{if(ne==="d")return z+1<_.length?(i=_.substring(z+1),{nextArgIndex:T+1}):T+1<t.length?(i=t[T+1],{nextArgIndex:T+2}):{nextArgIndex:T+1};if(ne==="n"){if(z+1<_.length){let Y=_.substring(z+1);return a=Number.parseInt(Y,10),(Number.isNaN(a)||a<0)&&(p=!0,a=0),{nextArgIndex:T+1}}else if(T+1<t.length)return a=Number.parseInt(t[T+1],10),(Number.isNaN(a)||a<0)&&(p=!0,a=0),{nextArgIndex:T+2};return{nextArgIndex:T+1}}else if(ne==="N"){if(z+1<_.length){let Y=_.substring(z+1);return l=Number.parseInt(Y,10),(Number.isNaN(l)||l<0)&&(p=!0,l=0),{nextArgIndex:T+1}}else if(T+1<t.length)return l=Number.parseInt(t[T+1],10),(Number.isNaN(l)||l<0)&&(p=!0,l=0),{nextArgIndex:T+2};return{nextArgIndex:T+1}}else{if(ne==="a")return z+1<_.length?(c=_.substring(z+1),{nextArgIndex:T+1}):T+1<t.length?(c=t[T+1],{nextArgIndex:T+2}):{nextArgIndex:T+1};if(ne==="p")return z+1<_.length?(o=_.substring(z+1),{nextArgIndex:T+1}):T+1<t.length?(o=t[T+1],{nextArgIndex:T+2}):{nextArgIndex:T+1};if(ne==="u"){if(z+1<_.length){let Y=_.substring(z+1);return u=Number.parseInt(Y,10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:T+1}}else if(T+1<t.length)return u=Number.parseInt(t[T+1],10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:T+2};return{nextArgIndex:T+1}}else if(ne==="t"){if(z+1<_.length){let Y=_.substring(z+1);return f=Number.parseFloat(Y),Number.isNaN(f)&&(f=0),{nextArgIndex:T+1}}else if(T+1<t.length)return f=Number.parseFloat(t[T+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:T+2};return{nextArgIndex:T+1}}else if(ne==="e"||ne==="i"||ne==="P"){if(ne==="i"&&T+1<t.length)return{nextArgIndex:T+2};z++}else z++}}}return{nextArgIndex:T+1}};for(;h<t.length;){let _=t[h];if(_.startsWith("-")&&_.length>1&&_!=="--"){let T=m(_,h);if(T.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(T.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=T.nextArgIndex}else if(_==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push(_),h++}if(p)return F("","",1);d.length===0&&c===null&&d.push("REPLY");let y=new Set;c&&y.add(c);for(let _ of d)y.add(_);l>=0&&d.length===0&&y.add("REPLY");for(let _ of y){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(_))return F("",`bash: read: \`${_}': not a valid identifier
|
|
644
|
+
`,1);fe(e,_,"bash")}if(f===0){if(c)Ee(e,c);else{for(let _ of d)e.state.env.set(_,"");d.length===0&&e.state.env.set("REPLY","")}return F("","",0)}if(f<0&&f!==-1)return F("","",1);let b=n,w=lt(e,u),E=u>0&&!(w?.kind==="dup-in"&&w.sourceFd===0);if(E){let _=Ws(e,u);if("error"in _){let z=_.error==="write-only"||u===1||u===2?`bash: read: read error: ${u}: Bad file descriptor
|
|
644
645
|
`:`bash: read: ${u}: invalid file descriptor: Bad file descriptor
|
|
645
|
-
`;return
|
|
646
|
-
`){
|
|
647
|
-
`){
|
|
646
|
+
`;return F("",z,1)}b=_.content}else!b&&e.state.groupStdin!==void 0&&(b=e.state.groupStdin);let S=i===""?"\0":i,v="",A=0,k=_=>{let T=V(_);if(T>e.limits.maxStringLength-A)throw new C(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");v+=_,A+=T},x=_=>{if(V(_)>e.limits.maxStringLength)throw new C(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")},D=0,$=!0,N=_=>{E?hn(e,u,_):r>=0?hn(e,r,_):e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=b.substring(_),e.state.groupStdinSourceFd!==void 0&&hn(e,e.state.groupStdinSourceFd,_))};if(l>=0){let _=Math.min(l,b.length);v=b.substring(0,_),x(v),D=_,$=_>=l,N(D);let T=d[0]||"REPLY";e.state.env.set(T,v);for(let z=1;z<d.length;z++)e.state.env.set(d[z],"");return F("","",$?0:1)}else if(a>=0){let _=0,T=0,z=!1;for(;T<b.length&&_<a;){let ne=b[T];if(ne===S){D=T+1,z=!0;break}if(!s&&ne==="\\"&&T+1<b.length){let Y=b[T+1];if(Y===S&&S===`
|
|
647
|
+
`){T+=2,D=T;continue}if(Y===S){T+=2,_++,k(Y),D=T;continue}k(Y),T+=2,_++,D=T}else k(ne),T++,_++,D=T}$=_>=a||z,N(D)}else{D=0;let _=0;for(;_<b.length;){let T=b[_];if(T===S){D=_+S.length,$=!0;break}if(!s&&T==="\\"&&_+1<b.length){let z=b[_+1];if(z===`
|
|
648
|
+
`){_+=2;continue}if(z===S){k(z),_+=2;continue}k(T),k(z),_+=2;continue}k(T),_++}if(_>=b.length&&($=!1,D=_,v.length===0&&b.length===0)){for(let T of d)e.state.env.set(T,"");return c&&Ee(e,c),F("","",1)}N(D)}S===`
|
|
648
649
|
`&&v.endsWith(`
|
|
649
|
-
`)&&(v=v.slice(0,-1));let
|
|
650
|
-
`,2);n=(s%256+256)%256}throw new Le(n)}var
|
|
650
|
+
`)&&(v=v.slice(0,-1));let O=_=>s?_:_.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",O(v)),F("","",$?0:1);let R=ve(e.state.env),W=e.limits.maxArrayElements;if(c){let{words:_}=Ui(v,R,W,void 0,s);Ee(e,c);for(let T=0;T<_.length;T++)H(e,c,T,O(_[T]));return F("","",$?0:1)}let P=d.length,{words:B,wordStarts:U}=Ui(v,R,W,P,s);for(let _=0;_<d.length;_++){let T=d[_];if(_<d.length-1)e.state.env.set(T,O(B[_]??""));else if(_<U.length){let z=v.substring(U[_]);z=Kl(z,R,s),z=O(z),e.state.env.set(T,z)}else e.state.env.set(T,"")}return F("","",$?0:1)}function sa(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return L("bash: return: can only `return' from a function or sourced script\n");let n=e.state.lastExitCode;if(t.length>0){let r=t[0],s=Number.parseInt(r,10);if(r===""||Number.isNaN(s)||!/^-?\d+$/.test(r))return L(`bash: return: ${r}: numeric argument required
|
|
651
|
+
`,2);n=(s%256+256)%256}throw new Le(n)}var Cr=`set: usage: set [-eux] [+eux] [-o option] [+o option]
|
|
651
652
|
Options:
|
|
652
653
|
-e Exit immediately if a command exits with non-zero status
|
|
653
654
|
+e Disable -e
|
|
@@ -663,96 +664,96 @@ Options:
|
|
|
663
664
|
+o pipefail Disable pipefail
|
|
664
665
|
-o xtrace Same as -x
|
|
665
666
|
+o xtrace Disable xtrace
|
|
666
|
-
`,
|
|
667
|
+
`,nf=new Map([["e","errexit"],["u","nounset"],["x","xtrace"],["v","verbose"],["f","noglob"],["C","noclobber"],["a","allexport"],["n","noexec"],["h",null],["b",null],["m",null],["B",null],["H",null],["P",null],["T",null],["E",null],["p",null]]),Hs=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["noclobber","noclobber"],["noglob","noglob"],["allexport","allexport"],["noexec","noexec"],["posix","posix"],["vi","vi"],["emacs","emacs"],["notify",null],["monitor",null],["braceexpand",null],["histexpand",null],["physical",null],["functrace",null],["errtrace",null],["privileged",null],["hashall",null],["ignoreeof",null],["interactive-comments",null],["keyword",null],["onecmd",null]]),of=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],af=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function ia(e,t,n){t!==null&&(n&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=n,Wn(e))}function dm(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function hm(e,t,n){let r=Ae(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],o=ae(e,n,i)??"";s>0&&t.append(" "),t.append(`[${i}]=`),t.reserve(js(o)),t.append(yn(o))}t.append(")")}function pm(e,t){if(/^[a-zA-Z0-9_]+$/.test(t)){e.append(t);return}e.reserve(js(t)),e.append(yn(t))}function mm(e,t,n){let r=xt(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],o=ae(e,n,i)??"";s>0&&t.append(" "),t.append("["),pm(t,i),t.append("]="),t.reserve(js(o)),t.append(yn(o))}t.append(" )")}function ym(e){let t=new Set,n=e.state.associativeArrays??new Set;for(let[r,s]of e.state.arrays??[])s.kind==="indexed"&&!n.has(r)&&t.add(r);return t}function gm(e){return e.state.associativeArrays??new Set}function rf(e){let t=of.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),n=af.map(r=>`${r.padEnd(16)}off`);return`${[...t,...n].sort().join(`
|
|
667
668
|
`)}
|
|
668
|
-
`}function
|
|
669
|
+
`}function sf(e){let t=of.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),n=af.map(r=>`set +o ${r}`);return`${[...t,...n].sort().join(`
|
|
669
670
|
`)}
|
|
670
|
-
`}function
|
|
671
|
-
`);return ee(c.build())}let n=[],r=()=>n.length>0?ee(n.join("")):te,s=0;for(;s<t.length;){let i=t[s];if((i==="-o"||i==="+o")&&
|
|
672
|
-
${
|
|
673
|
-
${
|
|
674
|
-
${
|
|
675
|
-
${
|
|
676
|
-
`;if(e.state.options.posix)throw new
|
|
677
|
-
`;if(e.state.options.posix)throw new
|
|
678
|
-
`,2);let r=n[0],s=null,i=null;if(r.includes("/")){let c=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(c),s=c}catch{}}else{let u=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of u){let d=e.fs.resolvePath(e.state.cwd,`${f}/${r}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),s=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(f),s=f}catch{}}}if(i===null)return
|
|
679
|
-
`);let o=new Map;if(n.length>1){for(let u=1;u<=9;u++)o.set(String(u),e.state.env.get(String(u)));o.set("#",e.state.env.get("#")),o.set("@",e.state.env.get("@"));let c=n.slice(1);e.state.env.set("#",String(c.length)),e.state.env.set("@",c.join(" "));for(let u=0;u<c.length&&u<9;u++)e.state.env.set(String(u+1),c[u]);for(let u=c.length+1;u<=9;u++)e.state.env.delete(String(u))}let a=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=a,n.length>1)for(let[c,u]of o)u===void 0?e.state.env.delete(c):e.state.env.set(c,u)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new
|
|
680
|
-
`);throw c}}function
|
|
681
|
-
`,s=1;continue}if(h==="@"||h==="*"){
|
|
682
|
-
`,s=1;continue}let
|
|
683
|
-
`,s=1;continue}if(
|
|
684
|
-
`,s=1;continue}let
|
|
685
|
-
`,s=1;continue}let
|
|
671
|
+
`}function aa(e,t){if(t.includes("--help"))return ee(Cr);if(t.length===0){let i=ym(e),o=gm(e),a=[];for(let[u,f]of e.state.env)/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)&&(i.has(u)||o.has(u)||a.push([u,f]));let l=[...a.map(([u,f])=>({kind:"scalar",name:u,value:f})),...Array.from(i,u=>({kind:"indexed",name:u})),...Array.from(o,u=>({kind:"associative",name:u}))];l.sort((u,f)=>u.name<f.name?-1:u.name>f.name?1:0);let c=new Ln(e.limits.maxOutputSize,"set");for(let u of l)e.executionScope.consumeWork(1,"set variable listing"),u.kind==="scalar"?(c.append(u.name).append("="),c.reserve(ju(u.value)),c.append(Se(u.value))):u.kind==="indexed"?hm(e,c,u.name):mm(e,c,u.name),c.append(`
|
|
672
|
+
`);return ee(c.build())}let n=[],r=()=>n.length>0?ee(n.join("")):te,s=0;for(;s<t.length;){let i=t[s];if((i==="-o"||i==="+o")&&dm(t,s)){let o=t[s+1];if(!Hs.has(o)){let a=`bash: set: ${o}: invalid option name
|
|
673
|
+
${Cr}`;if(e.state.options.posix)throw new rt(1,"",a);return L(a)}ia(e,Hs.get(o)??null,i==="-o"),s+=2;continue}if(i==="-o"){n.push(rf(e)),s++;continue}if(i==="+o"){n.push(sf(e)),s++;continue}if(i.length>1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let o=i[0]==="-",a=0;for(let l=1;l<i.length;l++){let c=i[l];if(c==="o"){let u=s+1+a;if(u<t.length&&!t[u].startsWith("-")&&!t[u].startsWith("+")){let d=t[u];if(!Hs.has(d)){let h=`bash: set: ${d}: invalid option name
|
|
674
|
+
${Cr}`;if(e.state.options.posix)throw new rt(1,"",h);return L(h)}ia(e,Hs.get(d)??null,o),a++;continue}n.push(o?rf(e):sf(e));continue}if(!nf.has(c)){let u=`bash: set: ${i[0]}${c}: invalid option
|
|
675
|
+
${Cr}`;if(e.state.options.posix)throw new rt(1,"",u);return L(u)}ia(e,nf.get(c)??null,o)}s+=1+a;continue}if(i==="--")return oa(e,t.slice(s+1)),r();if(i==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,Wn(e),s+1<t.length)return oa(e,t.slice(s+1)),r();s++;continue}if(i==="+"){s++;continue}if(i.startsWith("-")||i.startsWith("+")){let o=`bash: set: ${i}: invalid option
|
|
676
|
+
${Cr}`;if(e.state.options.posix)throw new rt(1,"",o);return L(o)}return oa(e,t.slice(s)),r()}return r()}function oa(e,t){let n=1;for(;e.state.env.has(String(n));)e.state.env.delete(String(n)),n++;for(let r=0;r<t.length;r++)e.state.env.set(String(r+1),t[r]);e.state.env.set("#",String(t.length)),e.state.env.set("@",t.join(" ")),e.state.env.set("*",t.join(" "))}function la(e,t){let n=1;if(t.length>0){let o=Number.parseInt(t[0],10);if(Number.isNaN(o)||o<0){let a=`bash: shift: ${t[0]}: numeric argument required
|
|
677
|
+
`;if(e.state.options.posix)throw new rt(1,"",a);return L(a)}n=o}let r=Number.parseInt(e.state.env.get("#")||"0",10);if(n>r){let o=`bash: shift: shift count out of range
|
|
678
|
+
`;if(e.state.options.posix)throw new rt(1,"",o);return L(o)}if(n===0)return te;let s=[];for(let o=1;o<=r;o++)s.push(e.state.env.get(String(o))||"");let i=s.slice(n);for(let o=1;o<=r;o++)e.state.env.delete(String(o));for(let o=0;o<i.length;o++)e.state.env.set(String(o+1),i[o]);return e.state.env.set("#",String(i.length)),e.state.env.set("@",i.join(" ")),te}async function ca(e,t){let n=t;if(n.length>0&&n[0]==="--"&&(n=n.slice(1)),n.length===0)return F("",`bash: source: filename argument required
|
|
679
|
+
`,2);let r=n[0],s=null,i=null;if(r.includes("/")){let c=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(c),s=c}catch{}}else{let u=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of u){let d=e.fs.resolvePath(e.state.cwd,`${f}/${r}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),s=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(f),s=f}catch{}}}if(i===null)return L(`bash: ${r}: No such file or directory
|
|
680
|
+
`);let o=new Map;if(n.length>1){for(let u=1;u<=9;u++)o.set(String(u),e.state.env.get(String(u)));o.set("#",e.state.env.get("#")),o.set("@",e.state.env.get("@"));let c=n.slice(1);e.state.env.set("#",String(c.length)),e.state.env.set("@",c.join(" "));for(let u=0;u<c.length&&u<9;u++)e.state.env.set(String(u+1),c[u]);for(let u=c.length+1;u<=9;u++)e.state.env.delete(String(u))}let a=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=a,n.length>1)for(let[c,u]of o)u===void 0?e.state.env.delete(c):e.state.env.set(c,u)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new C(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let c=He(i),u=await e.executeScript(c);return l(),u}catch(c){if(l(),c instanceof G)throw c;if(c instanceof Le)return F(c.stdout,c.stderr,c.exitCode);if(c.name==="ParseException")return L(`bash: ${r}: ${c.message}
|
|
681
|
+
`);throw c}}function lf(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function wm(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function cf(e,t){if(wm(t))return null;try{let n=new Q,r=re(n,t);return await J(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}function uf(e,t){if(e.state.localVarStack?.has(t)){let r=Ls(e,t);if(r){r.value===void 0?e.state.env.delete(t):e.state.env.set(t,r.value);let s=e.state.localVarStack?.get(t);if(!s||s.length===0)Ts(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),ua(e,t);else{let i=s[s.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return e.state.env.delete(t),Ts(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let r=e.state.localScopes.length-1;r>=0;r--){let s=e.state.localScopes[r];if(s.has(t)){let i=s.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),s.delete(t);let o=!1;for(let a=r-1;a>=0;a--)if(e.state.localScopes[a].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,a+1),o=!0;break}return o||Ts(e,t),!0}}return!1}function ua(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let n=e.state.tempEnvBindings.length-1;n>=0;n--){let r=e.state.tempEnvBindings[n];if(r.has(t)){let s=r.get(t);return s===void 0?e.state.env.delete(t):e.state.env.set(t,s),r.delete(t),!0}}return!1}async function ff(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let n=t.slice(1,-1),s=new Q().parseWordFromString(n,!0,!1);return se(e,s)}if(t.includes("$")){let r=new Q().parseWordFromString(t,!1,!1);return se(e,r)}return t}async function fa(e,t){let n="both",r="",s=0;for(let i of t){if(i==="-v"){n="variable";continue}if(i==="-f"){n="function";continue}if(n==="function"){e.state.functions.delete(i);continue}if(n==="variable"){let c=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(c){let d=c[1],h=c[2];if(We(e,d)){r+=`bash: unset: ${d}: cannot unset: readonly variable
|
|
682
|
+
`,s=1;continue}if(h==="@"||h==="*"){ur(e,d),e.state.env.delete(d);continue}let p=e.state.associativeArrays?.has(d);if(p){let E=await ff(e,h);An(e,d,E);continue}let m=wt(e,d),y=e.state.declaredVars?.has(d);if((e.state.env.has(d)||y)&&!m&&!p){r+=`bash: unset: ${d}: not an array variable
|
|
683
|
+
`,s=1;continue}let w=await cf(e,h);if(w===null&&m){r+=`bash: unset: ${h}: not a valid identifier
|
|
684
|
+
`,s=1;continue}if(w===null)continue;if(w<0){let E=K(e,d),S=E.length,v=e.state.currentLine;if(S===0){r+=`bash: line ${v}: unset: [${w}]: bad array subscript
|
|
685
|
+
`,s=1;continue}let A=S+w;if(A<0){r+=`bash: line ${v}: unset: [${w}]: bad array subscript
|
|
686
|
+
`,s=1;continue}let k=E[A][0];An(e,d,k);continue}An(e,d,w);continue}if(!lf(i)){r+=`bash: unset: \`${i}': not a valid identifier
|
|
686
687
|
`,s=1;continue}let u=i;if(ue(e,i)){let d=Be(e,i);d&&d!==i&&(u=d)}if(We(e,u)){r+=`bash: unset: ${u}: cannot unset: readonly variable
|
|
687
|
-
`,s=1;continue}
|
|
688
|
-
`,s=1;continue}if(u==="@"||u==="*"){
|
|
689
|
-
`,s=1;continue}let p=await
|
|
690
|
-
`,s=1;continue}if(p===null)continue;if(p<0){let m=
|
|
691
|
-
`,s=1;continue}let y
|
|
692
|
-
`,s=1;continue}let
|
|
688
|
+
`,s=1;continue}ur(e,u);let f=ho(e,u);if(f!==void 0&&f!==e.state.callDepth)uf(e,u);else if(e.state.fullyUnsetLocals?.has(u))e.state.env.delete(u);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(u),h=e.state.mutatedTempEnvVars?.has(u);if((d||h)&&e.state.localVarStack?.has(u)){let p=Ls(e,u);p?p.value===void 0?e.state.env.delete(u):e.state.env.set(u,p.value):e.state.env.delete(u)}else e.state.env.delete(u)}else ua(e,u)||e.state.env.delete(u);e.state.exportedVars?.delete(u);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let c=o[1],u=o[2];if(We(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable
|
|
689
|
+
`,s=1;continue}if(u==="@"||u==="*"){ur(e,c),e.state.env.delete(c);continue}let f=e.state.associativeArrays?.has(c);if(f){let m=await ff(e,u);An(e,c,m);continue}let d=wt(e,c);if(e.state.env.has(c)&&!d&&!f){r+=`bash: unset: ${c}: not an array variable
|
|
690
|
+
`,s=1;continue}let p=await cf(e,u);if(p===null&&d){r+=`bash: unset: ${u}: not a valid identifier
|
|
691
|
+
`,s=1;continue}if(p===null)continue;if(p<0){let m=K(e,c),y=m.length,b=e.state.currentLine;if(y===0){r+=`bash: line ${b}: unset: [${p}]: bad array subscript
|
|
692
|
+
`,s=1;continue}let w=y+p;if(w<0){r+=`bash: line ${b}: unset: [${p}]: bad array subscript
|
|
693
|
+
`,s=1;continue}let E=m[w][0];An(e,c,E);continue}An(e,c,p);continue}if(!lf(i)){r+=`bash: unset: \`${i}': not a valid identifier
|
|
693
694
|
`,s=1;continue}let a=i;if(ue(e,i)){let c=Be(e,i);c&&c!==i&&(a=c)}if(We(e,a)){r+=`bash: unset: ${a}: cannot unset: readonly variable
|
|
694
|
-
`,s=1;continue}
|
|
695
|
-
`}}}u++}else break}for(;u<t.length;)c.push(t[u]),u++;if(l)return
|
|
696
|
-
`};if(c.length===0){if(s||i){let
|
|
695
|
+
`,s=1;continue}ur(e,a);let l=ho(e,a);if(l!==void 0&&l!==e.state.callDepth)uf(e,a);else if(e.state.fullyUnsetLocals?.has(a))e.state.env.delete(a);else if(l!==void 0){let c=e.state.accessedTempEnvVars?.has(a),u=e.state.mutatedTempEnvVars?.has(a);if((c||u)&&e.state.localVarStack?.has(a)){let f=Ls(e,a);f?f.value===void 0?e.state.env.delete(a):e.state.env.set(a,f.value):e.state.env.delete(a)}else e.state.env.delete(a)}else ua(e,a)||e.state.env.delete(a);e.state.exportedVars?.delete(a),e.state.functions.delete(i)}return F("",r,s)}function Ot(e,t,n,r){let s=n+V(t)+1;if(s>r)throw new C(`shopt: output size limit exceeded (${r} bytes)`,"output_size");return e.push(t),s}var da=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],Em=["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 Zs(e){return da.includes(e)}function bm(e){return Em.includes(e)}function df(e,t){let n=e.limits.maxArrayElements;if(t.length>n)throw new C(`shopt: argument limit exceeded (${n})`,"array_elements");let r=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),s=!1,i=!1,o=!1,a=!1,l=!1,c=[],u=0;for(;u<t.length;){let y=t[u];if(y==="--"){u++;break}if(y.startsWith("-")&&y.length>1){for(let b=1;b<y.length;b++){let w=y[b];switch(w){case"s":s=!0;break;case"u":i=!0;break;case"p":o=!0;break;case"q":a=!0;break;case"o":l=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${w}: invalid option
|
|
696
|
+
`}}}u++}else break}for(;u<t.length;)c.push(t[u]),u++;if(l)return Sm(e,c,s,i,o,a);if(s&&i)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
|
|
697
|
+
`};if(c.length===0){if(s||i){let b=[];for(let w of da){let E=e.state.shoptOptions[w];s&&E?b.push(o?`shopt -s ${w}`:`${w} on`):i&&!E&&b.push(o?`shopt -u ${w}`:`${w} off`)}return{exitCode:0,stdout:b.length>0?`${b.join(`
|
|
697
698
|
`)}
|
|
698
|
-
`:"",stderr:""}}let
|
|
699
|
+
`:"",stderr:""}}let y=[];for(let b of da){let w=e.state.shoptOptions[b];y.push(o?`shopt ${w?"-s":"-u"} ${b}`:`${b} ${w?"on":"off"}`)}return{exitCode:0,stdout:`${y.join(`
|
|
699
700
|
`)}
|
|
700
|
-
`,stderr:""}}let f=!1,d=[],h=0,p=[],m=0;for(let
|
|
701
|
+
`,stderr:""}}let f=!1,d=[],h=0,p=[],m=0;for(let y of c){if(!Zs(y)&&!bm(y)){h=Ot(d,`shopt: ${y}: invalid shell option name`,h,r),f=!0;continue}if(s)Zs(y)&&(e.state.shoptOptions[y]=!0,mi(e));else if(i)Zs(y)&&(e.state.shoptOptions[y]=!1,mi(e));else if(Zs(y)){let b=e.state.shoptOptions[y];a?b||(f=!0):o?(m=Ot(p,`shopt ${b?"-s":"-u"} ${y}`,m,r),b||(f=!0)):(m=Ot(p,`${y} ${b?"on":"off"}`,m,r),b||(f=!0))}else a?f=!0:o?(m=Ot(p,`shopt -u ${y}`,m,r),f=!0):(m=Ot(p,`${y} off`,m,r),f=!0)}return{exitCode:f?1:0,stdout:p.length>0?`${p.join(`
|
|
701
702
|
`)}
|
|
702
703
|
`:"",stderr:d.length>0?`${d.join(`
|
|
703
704
|
`)}
|
|
704
|
-
`:""}}function
|
|
705
|
+
`:""}}function Sm(e,t,n,r,s,i){let o=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),a=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),l=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],c=[...a.keys(),...l].sort();if(t.length===0){let m=[];for(let y of c){let b=l.includes(y),w=a.get(y),E=b||!w?!1:e.state.options[w];n&&!E||r&&E||m.push(s?`set ${E?"-o":"+o"} ${y}`:`${y} ${E?"on":"off"}`)}return{exitCode:0,stdout:m.length>0?`${m.join(`
|
|
705
706
|
`)}
|
|
706
|
-
`:"",stderr:""}}let u=!1,f=[],d=0,h=[],p=0;for(let m of t){let
|
|
707
|
+
`:"",stderr:""}}let u=!1,f=[],d=0,h=[],p=0;for(let m of t){let y=a.has(m),b=l.includes(m);if(!y&&!b){d=Ot(f,`shopt: ${m}: invalid option name`,d,o),u=!0;continue}if(b){n||r||(i?u=!0:s?(p=Ot(h,`set +o ${m}`,p,o),u=!0):(p=Ot(h,`${m} off`,p,o),u=!0));continue}let w=a.get(m);if(w)if(n)w==="vi"?e.state.options.emacs=!1:w==="emacs"&&(e.state.options.vi=!1),e.state.options[w]=!0,Wn(e);else if(r)e.state.options[w]=!1,Wn(e);else{let E=e.state.options[w];i?E||(u=!0):s?(p=Ot(h,`set ${E?"-o":"+o"} ${m}`,p,o),E||(u=!0)):(p=Ot(h,`${m} ${E?"on":"off"}`,p,o),E||(u=!0))}}return{exitCode:u?1:0,stdout:h.length>0?`${h.join(`
|
|
707
708
|
`)}
|
|
708
709
|
`:"",stderr:f.length>0?`${f.join(`
|
|
709
710
|
`)}
|
|
710
|
-
`:""}}function
|
|
711
|
-
`,t||
|
|
711
|
+
`:""}}function Qs(e,t){return e===`/bin/${t}`||e===`/usr/bin/${t}`}async function hf(e,t,n){if(t.includes("/")){let o=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(o))return{error:"not_found",path:o};try{let a=await e.fs.stat(o);if(a.isDirectory)return{error:"permission_denied",path:o};let l=o.split("/").pop()||t,c=e.commands.get(l);return c&&Qs(o,l)?{cmd:c,path:o}:(a.mode&73)!==0?{script:!0,path:o}:{error:"permission_denied",path:o}}catch{return{error:"not_found",path:o}}}if(!n&&e.state.hashTable){let o=e.state.hashTable.get(t);if(o){try{let a=await e.fs.stat(o);if(!a.isDirectory){let l=e.commands.get(t);if(l&&Qs(o,t))return{cmd:l,path:o};if((a.mode&73)!==0)return{script:!0,path:o}}}catch{}e.state.hashTable.delete(t)}}let s=(n??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let o of s){if(!o)continue;let l=`${o.startsWith("/")?o:e.fs.resolvePath(e.state.cwd,o)}/${t}`;if(await e.fs.exists(l))try{let c=await e.fs.stat(l);if(c.isDirectory)continue;let u=(c.mode&73)!==0,f=e.commands.get(t),d=Qs(l,t);if(f&&d)return{cmd:f,path:l};if(u){if(f&&!d)return{script:!0,path:l};if(!f)return{script:!0,path:l}}}catch{}}if(!await e.fs.exists("/usr/bin")){let o=e.commands.get(t);if(o)return{cmd:o,path:`/usr/bin/${t}`}}return null}async function Ks(e,t){let n=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let o=await e.fs.stat(i);o.isDirectory||(o.mode&73)!==0&&n.push(t)}catch{}return n}let s=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of s){if(!i)continue;let a=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(Qs(a,t)&&e.commands.has(t)){n.push(a);continue}if(await e.fs.exists(a)){try{let l=await e.fs.stat(a);if(l.isDirectory||(l.mode&73)===0)continue}catch{continue}n.push(i.startsWith("/")?a:`${i}/${t}`)}}return n}function Am(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function pe(e,t,n,r){return((...s)=>{ar(t,n,`${r} call`);let i=e(...s);return Am(i)?i.then(o=>(ar(t,n,`${r} post-await`),o),o=>{throw ar(t,n,`${r} post-await`),o}):(ar(t,n,`${r} return`),i)})}function vm(e,t,n){let r={readFile:pe(e.readFile.bind(e),t,n,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:pe(e.readFileBytes.bind(e),t,n,"fs.readFileBytes")}:Object.create(null),readFileBuffer:pe(e.readFileBuffer.bind(e),t,n,"fs.readFileBuffer"),writeFile:pe(e.writeFile.bind(e),t,n,"fs.writeFile"),appendFile:pe(e.appendFile.bind(e),t,n,"fs.appendFile"),exists:pe(e.exists.bind(e),t,n,"fs.exists"),stat:pe(e.stat.bind(e),t,n,"fs.stat"),mkdir:pe(e.mkdir.bind(e),t,n,"fs.mkdir"),readdir:pe(e.readdir.bind(e),t,n,"fs.readdir"),rm:pe(e.rm.bind(e),t,n,"fs.rm"),cp:pe(e.cp.bind(e),t,n,"fs.cp"),mv:pe(e.mv.bind(e),t,n,"fs.mv"),resolvePath:pe(e.resolvePath.bind(e),t,n,"fs.resolvePath"),getAllPaths:pe(e.getAllPaths.bind(e),t,n,"fs.getAllPaths"),chmod:pe(e.chmod.bind(e),t,n,"fs.chmod"),symlink:pe(e.symlink.bind(e),t,n,"fs.symlink"),link:pe(e.link.bind(e),t,n,"fs.link"),readlink:pe(e.readlink.bind(e),t,n,"fs.readlink"),lstat:pe(e.lstat.bind(e),t,n,"fs.lstat"),realpath:pe(e.realpath.bind(e),t,n,"fs.realpath"),utimes:pe(e.utimes.bind(e),t,n,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=pe(e.readdirWithFileTypes.bind(e),t,n,"fs.readdirWithFileTypes")),e.createExclusive&&(r.createExclusive=pe(e.createExclusive.bind(e),t,n,"fs.createExclusive")),r}function ha(e,t){if(!e.requireDefenseContext)return e;let n=`command:${t}`,r=Object.getOwnPropertyDescriptors(e);r.fs={value:vm(e.fs,e.requireDefenseContext,n),enumerable:!0,configurable:!0,writable:!0};let s=Object.defineProperties(Object.create(Object.getPrototypeOf(e)),r);return e.exec&&(s.exec=pe(e.exec,e.requireDefenseContext,n,"exec")),e.origCommand&&(s.origCommand=pe(e.origCommand,e.requireDefenseContext,n,"origCommand")),e.fetch&&(s.fetch=pe(e.fetch,e.requireDefenseContext,n,"fetch")),e.sleep&&(s.sleep=pe(e.sleep,e.requireDefenseContext,n,"sleep")),e.getRegisteredCommands&&(s.getRegisteredCommands=pe(e.getRegisteredCommands,e.requireDefenseContext,n,"getRegisteredCommands")),s}var pf="+ ";async function mf(e){let t=e.state.env.get("PS4");if(t===void 0)return pf;if(t==="")return"";let n=e.state.options.xtrace;e.state.options.xtrace=!1;let r=e.state.lastExitCode,s=e.state.env.get("?"),i=e.state.lastSubstitutionExitCode;try{let a=new Q().parseWordFromString(t,!1,!1);return await se(e,a)}catch(o){if(o instanceof le&&!o.fatal)return t;if(o instanceof Tn||o instanceof Error&&o.name==="AbortError")throw o;return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
|
|
712
|
+
`,t||pf}finally{e.state.options.xtrace=n,e.state.lastExitCode=r,e.state.lastSubstitutionExitCode=i,s===void 0?e.state.env.delete("?"):e.state.env.set("?",s)}}function km(e){return e.map(t=>xm(t)).join(" ")}function xm(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let n=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
|
|
712
713
|
`),s=e.includes(" "),i=e.includes("\\"),o=e.includes("'");if(n||r||s||i){let l="";for(let c of e){let u=c.charCodeAt(0);c===`
|
|
713
|
-
`?l+="\\n":c===" "?l+="\\t":c==="\\"?l+="\\\\":c==="'"?l+="'":c==='"'?l+='"':u<32||u===127?u<256?l+=`\\x${u.toString(16).padStart(2,"0")}`:l+=`\\u${u.toString(16).padStart(4,"0")}`:l+=c}return`$'${l}'`}return o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function
|
|
714
|
-
`}async function
|
|
715
|
-
`:""}function
|
|
716
|
-
`,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let u=await
|
|
717
|
-
`,1)};if(ue(e,n)){let p=Cn(e,n);if(p===void 0||p==="")throw new
|
|
714
|
+
`?l+="\\n":c===" "?l+="\\t":c==="\\"?l+="\\\\":c==="'"?l+="'":c==='"'?l+='"':u<32||u===127?u<256?l+=`\\x${u.toString(16).padStart(2,"0")}`:l+=`\\u${u.toString(16).padStart(4,"0")}`:l+=c}return`$'${l}'`}return o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function yf(e,t,n){if(!e.state.options.xtrace)return"";let r=await mf(e),s=[t,...n],i=km(s);return`${r}${i}
|
|
715
|
+
`}async function gf(e,t,n){return e.state.options.xtrace?`${await mf(e)}${t}=${n}
|
|
716
|
+
`:""}function Xs(e,t,n){return Gt([t,n],"",e.limits.maxStringLength,"array assignment")}async function wf(e,t){let n=new Map,r="";for(let s of t.assignments){let i=s.name;if(s.array){let u=await Pm(e,t,i,s.array,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};if(r+=u.xtraceOutput,u.continueToNext)continue}let o=s.value?await se(e,s.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:F("",`bash: ${i}: bad array subscript
|
|
717
|
+
`,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let u=await Om(e,t,l[1],l[2],o,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};if(u.continueToNext)continue}let c=await Dm(e,t,i,o,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};r+=c.xtraceOutput,c.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:n}}async function Pm(e,t,n,r,s,i){let o="";if(/\[.+\]$/.test(n))return{continueToNext:!1,xtraceOutput:"",error:F("",`bash: ${n}: cannot assign list to array member
|
|
718
|
+
`,1)};if(ue(e,n)){let p=Cn(e,n);if(p===void 0||p==="")throw new G(1,"","");let m=Be(e,n);if(m&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(m))return{continueToNext:!1,xtraceOutput:"",error:F("",`bash: ${n}: cannot assign list to array member
|
|
718
719
|
`,1)}}if(We(e,n)){if(t.name)return o+=`bash: ${n}: readonly variable
|
|
719
|
-
`,{continueToNext:!0,xtraceOutput:o};let p=fe(e,n);if(p)return{continueToNext:!1,xtraceOutput:"",error:p}}let a=e.state.associativeArrays?.has(n),l=
|
|
720
|
-
`)}}async function
|
|
721
|
-
`,1)};a=f}}if(We(e,a)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=fe(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l=e.state.associativeArrays?.has(a),c;if(l)c=await
|
|
722
|
-
`;if(i.fatal)throw new
|
|
723
|
-
`,1)}}Number.isNaN(s)&&(s=0)}if(s<0){let i=
|
|
724
|
-
`,1)}}if(s=Math.max(...i.map(([a])=>typeof a=="number"?a:0))+1+s,s<0){let a=e.state.currentLine;return{index:0,error:
|
|
725
|
-
`,1)}}}return{index:s}}async function
|
|
720
|
+
`,{continueToNext:!0,xtraceOutput:o};let p=fe(e,n);if(p)return{continueToNext:!1,xtraceOutput:"",error:p}}let a=e.state.associativeArrays?.has(n),l=ke(e,n),c=l?Me(l):void 0,u=e.state.env.get(n),f=()=>{e.state.arrays??=new Map,c?e.state.arrays.set(n,c):e.state.arrays.delete(n),u===void 0?e.state.env.delete(n):e.state.env.set(n,u)},d=$m(r),h=()=>{Ee(e,n),e.state.env.delete(n)};try{a&&d?await Cm(e,t,n,r,s,h,p=>{o+=p}):d?await Nm(e,n,r,s,h):await Rm(e,n,r,s,h)}catch(p){throw f(),p}if(t.name){i.set(n,e.state.env.get(n));let m=`(${r.map(y=>Bn(y)).join(" ")})`;e.state.env.set(n,m)}return{continueToNext:!0,xtraceOutput:o}}function $m(e){return e.some(t=>{if(t.parts.length>=2){let n=t.parts[0],r=t.parts[1];if(n.type!=="Glob"||!n.pattern.startsWith("["))return!1;if(n.pattern==="["&&(r.type==="DoubleQuoted"||r.type==="SingleQuoted")){if(t.parts.length<3)return!1;let s=t.parts[2];return s.type!=="Literal"?!1:s.value.startsWith("]=")||s.value.startsWith("]+=")}return r.type!=="Literal"?!1:r.value.startsWith("]")?r.value.startsWith("]=")||r.value.startsWith("]+="):n.pattern.endsWith("]")?r.value.startsWith("=")||r.value.startsWith("+="):!1}return!1})}async function Cm(e,t,n,r,s,i,o){let a=[];for(let l of r){if(a.length>=e.limits.maxArrayElements)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let c=pi(l);if(c){let{key:u,valueParts:f,append:d}=c,h;f.length>0?(h=await se(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(h=an(e,h))):h="",a.push({type:"keyed",key:u,value:h,append:d})}else{let u=await se(e,l);a.push({type:"invalid",expandedValue:u})}}e.executionScope.consumeWork(a.length,"associative array assignment"),s||i();for(let l of a)if(l.type==="keyed")if(l.append){let c=ae(e,n,l.key)??"";H(e,n,l.key,Xs(e,c,l.value),"associative")}else H(e,n,l.key,l.value,"associative");else{let c=t.line??e.state.currentLine??1;o(`bash: line ${c}: ${n}: ${l.expandedValue}: must use subscript when assigning associative array
|
|
721
|
+
`)}}async function Nm(e,t,n,r,s){let i=[],o=0;for(let l of n){let c=pi(l);if(c){if(o>=e.limits.maxArrayElements)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let{key:u,valueParts:f,append:d}=c,h;f.length>0?(h=await se(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(h=an(e,h))):h="",i.push({type:"keyed",indexExpr:u,value:h,append:d}),o++}else{let u=await At(e,l);if(u.values.length>e.limits.maxArrayElements-o)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push({type:"non-keyed",values:u.values}),o+=u.values.length}}e.executionScope.consumeWork(o,"indexed array assignment"),r||s();let a=0;for(let l of i)if(l.type==="keyed"){let c;try{let u=new Q,f=re(u,l.indexExpr);c=await J(e,f.expression,!1)}catch{if(/^-?\d+$/.test(l.indexExpr))c=Number.parseInt(l.indexExpr,10);else{let u=e.state.env.get(l.indexExpr);c=u?Number.parseInt(u,10):0,Number.isNaN(c)&&(c=0)}}if(l.append){let u=ae(e,t,c)??"";H(e,t,c,Xs(e,u,l.value))}else H(e,t,c,l.value);a=c+1}else for(let c of l.values)H(e,t,a++,c)}async function Rm(e,t,n,r,s){let i=[];for(let a of n){let l=await At(e,a);for(let c of l.values){if(i.length>=e.limits.maxArrayElements)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push(c)}}let o=0;if(e.executionScope.consumeWork(i.length,"indexed array assignment"),r){let a=K(e,t);if(a.length>0)o=Math.max(...a.map(([c])=>typeof c=="number"?c:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(H(e,t,0,l),e.state.env.delete(t),o=1)}}else s();for(let a=0;a<i.length;a++)H(e,t,o+a,i[a])}async function Om(e,t,n,r,s,i,o){let a=n;if(ue(e,n)){let f=Be(e,n);if(f&&f!==n){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:F("",`bash: \`${f}': not a valid identifier
|
|
722
|
+
`,1)};a=f}}if(We(e,a)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=fe(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l=e.state.associativeArrays?.has(a),c;if(l)c=await Ef(e,r);else{let f=await pa(e,a,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};c=String(f.index)}let u=i?Xs(e,ae(e,a,c)||"",s):s;return t.name||H(e,a,c,u,l?"associative":"indexed"),{continueToNext:!0,xtraceOutput:""}}async function Ef(e,t){let n;if(t.startsWith("'")&&t.endsWith("'"))n=t.slice(1,-1);else if(t.startsWith('"')&&t.endsWith('"')){let r=t.slice(1,-1),i=new Q().parseWordFromString(r,!0,!1);n=await se(e,i)}else if(t.includes("$")){let s=new Q().parseWordFromString(t,!1,!1);n=await se(e,s)}else n=t;return n}async function pa(e,t,n){let r=n;n.startsWith('"')&&n.endsWith('"')&&n.length>=2&&(r=n.slice(1,-1));let s;if(/^-?\d+$/.test(r))s=Number.parseInt(r,10);else{try{let i=new Q,o=re(i,r);s=await J(e,o.expression,!1)}catch(i){if(i instanceof G)throw i;if(i instanceof le){let l=`bash: line ${e.state.currentLine}: ${n}: ${i.message}
|
|
723
|
+
`;if(i.fatal)throw new G(1,"",l);return{index:0,error:F("",l,1)}}let o=e.state.currentLine;return{index:0,error:F("",`bash: line ${o}: ${t}[${n}]: bad array subscript
|
|
724
|
+
`,1)}}Number.isNaN(s)&&(s=0)}if(s<0){let i=K(e,t);if(i.length===0){let a=e.state.currentLine;return{index:0,error:F("",`bash: line ${a}: ${t}[${n}]: bad array subscript
|
|
725
|
+
`,1)}}if(s=Math.max(...i.map(([a])=>typeof a=="number"?a:0))+1+s,s<0){let a=e.state.currentLine;return{index:0,error:F("",`bash: line ${a}: ${t}[${n}]: bad array subscript
|
|
726
|
+
`,1)}}}return{index:s}}async function Dm(e,t,n,r,s,i){let o="",a=n,l=null;if(ue(e,n)){let f=cs(e,n,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:F("",`bash: ${n}: circular name reference
|
|
726
727
|
`,1)};if(f===null)return{continueToNext:!0,xtraceOutput:""};a=f;let d=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(l={arrayName:d[1],subscriptExpr:d[2]},a=d[1])}if(We(e,a)){if(t.name)return o+=`bash: ${a}: readonly variable
|
|
727
|
-
`,{continueToNext:!0,xtraceOutput:o};let f=fe(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let c;if(
|
|
728
|
-
`;h=!0,
|
|
729
|
-
`,h=!0,
|
|
730
|
-
`;else{let
|
|
731
|
-
`;u+=
|
|
732
|
-
`:u+=`${m} is aliased to \`${
|
|
733
|
-
`),
|
|
728
|
+
`,{continueToNext:!0,xtraceOutput:o};let f=fe(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let c;if(Pr(e,a))try{let f=new Q;if(s){let h=`(${e.state.env.get(a)||"0"}) + (${r})`,p=re(f,h);c=String(await J(e,p.expression))}else{let d=re(f,r);c=String(await J(e,d.expression))}}catch{c="0"}else{let f=wt(e,a)?ae(e,a,0):e.state.env.get(a);c=s?Xs(e,f||"",r):r}c=Jn(e,a,c),o+=await gf(e,a,c);let u;return l?u=await Im(e,l):wt(e,a)&&(u="0"),t.name?u===void 0&&(i.set(a,e.state.env.get(a)),e.state.env.set(a,c)):(u===void 0?e.state.env.set(a,c):H(e,a,u,c),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(a)),e.state.tempEnvBindings?.some(f=>f.has(a))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(a))),{continueToNext:!1,xtraceOutput:o}}async function Im(e,t){let{arrayName:n,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(n))return Ef(e,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let o=new Q,a=re(o,r);i=await J(e,a.expression,!1)}catch{let o=e.state.env.get(r);i=o?Number.parseInt(o,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let o=K(e,n);o.length>0&&(i=Math.max(...o.map(l=>l[0]))+1+i)}return String(i)}async function Af(e,t,n,r){let s=!1,i=!1,o=!1,a=!1,l=!1,c=[];for(let m of t)if(m.startsWith("-")&&m.length>1)for(let y of m.slice(1))y==="t"?s=!0:y==="p"?i=!0:y==="P"?o=!0:y==="a"?a=!0:y==="f"&&(l=!0);else c.push(m);let u="",f="",d=0,h=!1,p=!1;for(let m of c){let y=!1;if(o){if(a){let A=await r(m);if(A.length>0){for(let k of A)u+=`${k}
|
|
729
|
+
`;h=!0,y=!0}}else{let A=await n(m);A&&(u+=`${A}
|
|
730
|
+
`,h=!0,y=!0)}y||(p=!0);continue}let b=!l&&e.state.functions.has(m);if(a&&b){if(!i)if(s)u+=`function
|
|
731
|
+
`;else{let A=e.state.functions.get(m),k=A?bf(m,A):`${m} is a function
|
|
732
|
+
`;u+=k}y=!0}let w=e.state.env.get(`BASH_ALIAS_${m}`);if(w!==void 0&&(a||!y)&&(i||(s?u+=`alias
|
|
733
|
+
`:u+=`${m} is aliased to \`${w}'
|
|
734
|
+
`),y=!0,!a)||mo.has(m)&&(a||!y)&&(i||(s?u+=`keyword
|
|
734
735
|
`:u+=`${m} is a shell keyword
|
|
735
|
-
`),
|
|
736
|
-
`;else{let
|
|
737
|
-
`;u+=
|
|
736
|
+
`),y=!0,!a))continue;if(!a&&b&&!y){if(!i)if(s)u+=`function
|
|
737
|
+
`;else{let A=e.state.functions.get(m),k=A?bf(m,A):`${m} is a function
|
|
738
|
+
`;u+=k}y=!0;continue}if(!(Hn.has(m)&&(a||!y)&&(i||(s?u+=`builtin
|
|
738
739
|
`:u+=`${m} is a shell builtin
|
|
739
|
-
`),
|
|
740
|
-
`:s?u+=`file
|
|
741
|
-
`:u+=`${m} is ${A}
|
|
742
|
-
`,h=!0,E=!0}else if(!E){let k=await n(m);k&&(i?u+=`${k}
|
|
740
|
+
`),y=!0,!a))){if(a){let A=await r(m);for(let k of A)i?u+=`${k}
|
|
743
741
|
`:s?u+=`file
|
|
744
742
|
`:u+=`${m} is ${k}
|
|
745
|
-
`,h=!0,
|
|
746
|
-
|
|
743
|
+
`,h=!0,y=!0}else if(!y){let A=await n(m);A&&(i?u+=`${A}
|
|
744
|
+
`:s?u+=`file
|
|
745
|
+
`:u+=`${m} is ${A}
|
|
746
|
+
`,h=!0,y=!0)}if(!y&&(p=!0,!s&&!i)){let A=!0;if(m.includes("/")){let k=e.fs.resolvePath(e.state.cwd,m);await e.fs.exists(k)&&(A=!1)}A&&(f+=`bash: type: ${m}: not found
|
|
747
|
+
`)}}}return i?d=p&&!h?1:0:d=p?1:0,F(u,f,d)}function bf(e,t){let n;return t.body.type==="Group"?n=t.body.body.map(s=>Nr(s)).join("; "):n=Nr(t.body),`${e} is a function
|
|
747
748
|
${e} ()
|
|
748
749
|
{
|
|
749
750
|
${n}
|
|
750
751
|
}
|
|
751
|
-
`}function
|
|
752
|
+
`}function Nr(e){if(Array.isArray(e))return e.map(t=>Nr(t)).join("; ");if(e.type==="Statement"){let t=[];for(let n=0;n<e.pipelines.length;n++){let r=e.pipelines[n];t.push(_m(r)),e.operators[n]&&t.push(e.operators[n])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,n=[];t.name&&n.push(Sf(t.name));for(let r of t.args)n.push(Sf(r));return n.join(" ")}return e.type==="Group"?`{ ${e.body.map(r=>Nr(r)).join("; ")}; }`:"..."}function Sf(e){return e.parts.map(vf).join("")}function vf(e){switch(e.type){case"Literal":return e.value;case"Escaped":return`\\${e.value}`;case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(vf).join("")}"`;default:return we(M.word([e]))}}function _m(e){let t=e.commands.map(n=>Nr(n));return(e.negated?"! ":"")+t.join(" | ")}async function kf(e,t,n,r){let s="",i="",o=0;for(let a of t){if(!a){o=1;continue}let l=e.state.env.get(`BASH_ALIAS_${a}`);if(l!==void 0)r?s+=`${a} is an alias for "${l}"
|
|
752
753
|
`:s+=`alias ${a}='${l}'
|
|
753
|
-
`;else if(
|
|
754
|
+
`;else if(mo.has(a))r?s+=`${a} is a shell keyword
|
|
754
755
|
`:s+=`${a}
|
|
755
|
-
`;else if(
|
|
756
|
+
`;else if(Hn.has(a))r?s+=`${a} is a shell builtin
|
|
756
757
|
`:s+=`${a}
|
|
757
758
|
`;else if(e.state.functions.has(a))r?s+=`${a} is a function
|
|
758
759
|
`:s+=`${a}
|
|
@@ -762,52 +763,53 @@ ${e} ()
|
|
|
762
763
|
`),o=1)}else if(e.commands.has(a)){let u=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of u){if(!d)continue;let h=`${d}/${a}`;try{let p=await e.fs.stat(h);if(!p.isDirectory&&(p.mode&73)!==0){f=h;break}}catch{}}f||(f=`/usr/bin/${a}`),r?s+=`${a} is ${f}
|
|
763
764
|
`:s+=`${f}
|
|
764
765
|
`}else r&&(i+=`${a}: not found
|
|
765
|
-
`),o=1}return
|
|
766
|
-
`)},o=f=>{if(f===null||typeof f!="object"&&typeof f!="function")return f;let d=s.get(f);if(d!==void 0)return d;if(typeof f=="object"&&
|
|
767
|
-
`))}}}async function
|
|
766
|
+
`),o=1}return F(s,i,o)}async function xf(e,t){if(t.includes("/")){let s=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(s)){try{let i=await e.fs.stat(s);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let r=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let s of r){if(!s)continue;let o=`${s.startsWith("/")?s:e.fs.resolvePath(e.state.cwd,s)}/${t}`;if(await e.fs.exists(o)){try{let a=await e.fs.stat(o);if(a.isDirectory||(a.mode&73)===0)continue}catch{continue}return`${s}/${t}`}}if(e.commands.has(t)){for(let s of r)if(s==="/usr/bin"||s==="/bin")return`${s}/${t}`;return`/usr/bin/${t}`}return null}function Pf(e,t){let n=!0,r=e.signal?new AbortController:void 0,s=new WeakMap,i=()=>{if(!n)throw new Ue("",`bash: ${t} used its context after cancellation
|
|
767
|
+
`)},o=f=>{if(f===null||typeof f!="object"&&typeof f!="function")return f;let d=s.get(f);if(d!==void 0)return d;if(typeof f=="object"&&Va(f))return f;if(f instanceof Uint8Array){let y=new Uint8Array(f);return s.set(f,y),y}if(f instanceof ArrayBuffer){let y=f.slice(0);return s.set(f,y),y}if(f instanceof Promise){let y=f.then(b=>(i(),o(b)));return s.set(f,y),y}if(typeof f=="function"){let y=function(...b){return i(),o(Reflect.apply(f,this,b))};return s.set(f,y),y}let h=Object.getPrototypeOf(f);if(Array.isArray(f)||h===Object.prototype||h===null){let y=Array.isArray(f)?[]:Object.create(h);s.set(f,y);let b=Object.getOwnPropertyDescriptors(f);for(let w of Object.values(b)){if("value"in w){let E=w.value;w.value=typeof E=="function"?(...S)=>(i(),o(Reflect.apply(E,f,S))):o(E)}if(w.get){let E=w.get;w.get=()=>(i(),o(Reflect.apply(E,f,[])))}if(w.set){let E=w.set;w.set=S=>{i(),Reflect.apply(E,f,[S])}}}return Object.defineProperties(y,b),y}let p=new Map,m=new Oa(f,{get(y,b){if(i(),b==="constructor"||b==="prototype"||b==="__proto__")throw new Error(`${t}: unsafe context property access`);let w=Reflect.get(y,b,y);if(typeof w!="function")return o(w);if(p.has(b))return p.get(b);let E=(...S)=>(i(),o(Reflect.apply(w,y,S)));return p.set(b,E),E},set(y,b,w){if(i(),b==="constructor"||b==="prototype"||b==="__proto__")throw new Error(`${t}: unsafe context property access`);return Reflect.set(y,b,w,y)}});return s.set(f,m),m},a=f=>o(f),l=f=>f&&((...d)=>(i(),o(f(...d)))),c=f=>({value:f,enumerable:!0,configurable:!0,writable:!0}),u=Object.getOwnPropertyDescriptors(e);return Object.assign(u,{fs:c(a(e.fs)),env:c(a(e.env)),limits:c(Object.freeze({...e.limits})),exportedEnv:c(e.exportedEnv?Object.freeze({...e.exportedEnv}):void 0),executionScope:c(e.executionScope?a(e.executionScope):void 0),fileDescriptors:c(e.fileDescriptors?a(e.fileDescriptors):void 0),coverage:c(e.coverage?a(e.coverage):void 0),assignShellVariable:c(l(e.assignShellVariable)),exec:c(l(e.exec)),origCommand:c(l(e.origCommand)),execWithInheritedStdin:c(l(e.execWithInheritedStdin)),fetch:c(l(e.fetch)),getRegisteredCommands:c(l(e.getRegisteredCommands)),sleep:c(l(e.sleep)),trace:c(l(e.trace)),invokeTool:c(l(e.invokeTool)),signal:c(r?.signal)}),{context:Object.defineProperties(Object.create(Object.getPrototypeOf(e)),u),revoke(){n=!1,r?.signal.aborted||r?.abort(new Ue("",`bash: ${t} context revoked
|
|
768
|
+
`))}}}async function Tm(e,t,n,r,s,i){let o=s.remainingTimeMs()??t.limits.maxExecutionTimeMs,a=t.limits.maxExtensionCleanupTimeMs,l,c,u,d=Promise.resolve().then(e).then(p=>({kind:"result",result:p}),p=>({kind:"error",error:p})),h=new Promise(p=>{let m=()=>{n(),p({kind:"abort"})};c=m,i?.addEventListener("abort",m,{once:!0}),i?.aborted&&m(),l=rr(()=>{n(),p({kind:"deadline"})},o)});try{let p=await Promise.race([d,h]);if(p.kind==="result")return p.result;if(p.kind==="error")throw p.error;n();let m=await Promise.race([d.then(()=>!0),new Promise(b=>{u=rr(()=>b(!1),a)})]),y=p.kind==="deadline"?new Ue("",`bash: ${r} exceeded its execution deadline
|
|
768
769
|
`):new Ue("",`bash: execution aborted
|
|
769
|
-
`);throw m||s.poisonAfterAbort(
|
|
770
|
-
`,2);let
|
|
771
|
-
`,2);let
|
|
772
|
-
`,2);
|
|
773
|
-
`);let[,...
|
|
774
|
-
`,127):
|
|
775
|
-
`,127);if("error"in
|
|
776
|
-
`,126):
|
|
777
|
-
`,127);if("script"in
|
|
778
|
-
`)}}async function
|
|
779
|
-
`,exitCode:1}}function
|
|
780
|
-
`),n.build(1)}return n.build(r)}async function
|
|
781
|
-
`);let i=[];if(t.words===null)i=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)i=[];else try{for(let o of t.words){let a=await
|
|
770
|
+
`);throw m||s.poisonAfterAbort(y),y}finally{n(),sr(l),sr(u),c&&i?.removeEventListener("abort",c)}}async function $f(e,t,n,r,s,i,o,a,l=!1,c=!1,u=!1){let{ctx:f,runCommand:d}=e;if(f.coverage&&Hn.has(t)&&f.coverage.hit(`bash:builtin:${t}`),t==="export")return Xo(f,n);if(t==="unset")return fa(f,n);if(t==="exit")return Ko(f,n);if(t==="local")return ta(f,n);if(t==="set")return aa(f,n);if(t==="break")return oo(f,n);if(t==="continue")return Mo(f,n);if(t==="return")return sa(f,n);if(t==="eval"&&f.state.options.posix)return qs(f,n,s,l);if(t==="shift")return la(f,n);if(t==="getopts")return Gs(f,n);if(t==="compgen")return Io(f,n);if(t==="complete")return Lo(f,n);if(t==="compopt")return Fo(f,n);if(t==="pushd")return await Ho(f,n);if(t==="popd")return Zo(f,n);if(t==="dirs")return Qo(f,n);if(t==="source"||t===".")return ca(f,n);if(t==="read")return ra(f,n,s,a);if(t==="mapfile"||t==="readarray")return na(f,n,s);if(t==="declare"||t==="typeset")return jo(f,n);if(t==="readonly")return qo(f,n);if(!i){let h=f.state.functions.get(t);if(h)return Us(f,h,n,s,void 0,l)}if(t==="__just_bash_tee_restore"){if(n.length===0||n.length>f.limits.maxArrayElements)return L(`bash: invalid internal pipeline status restore
|
|
771
|
+
`,2);let h=[];for(let y of n){if(!/^(?:0|[1-9][0-9]{0,2})$/.test(y))return L(`bash: invalid internal pipeline status restore
|
|
772
|
+
`,2);let b=Number(y);if(!Number.isSafeInteger(b)||b>255)return L(`bash: invalid internal pipeline status restore
|
|
773
|
+
`,2);h.push(b)}let p=h[h.length-1]??0,m=[...h].reverse().find(y=>y!==0);return{stdout:"",stderr:"",exitCode:f.state.options.pipefail&&m!==void 0?m:p,internalPipeStatusOverride:h}}if(t==="eval")return qs(f,n,s,l);if(t==="cd")return await ao(f,n);if(t===":"||t==="true")return te;if(t==="false")return be(!1);if(t==="let")return ea(f,n);if(t==="command")return Lm(e,n,s,l,c,u);if(t==="builtin")return Fm(e,n,s,l,c,u);if(t==="shopt")return df(f,n);if(t==="exec"){if(n.length===0)return te;let[h,...p]=n;return{...await d(h,p,[],s,!1,!1,-1,l,c,u),internalProducerOmitsShellPrefix:!0}}if(t==="wait")return te;if(t==="type")return await Af(f,n,h=>xf(f,h),h=>Ks(f,h));if(t==="hash")return Yo(f,n);if(t==="help")return Jo(f,n);if(t==="["||t==="test"){let h=n;if(t==="["){if(n[n.length-1]!=="]")return L("[: missing `]'\n",2);h=n.slice(0,-1)}return Sr(f,h)}return null}async function Lm(e,t,n,r=!1,s=!1,i=!1){let{ctx:o,runCommand:a}=e;if(t.length===0)return te;let l=!1,c=!1,u=!1,f=t;for(;f.length>0&&f[0].startsWith("-");){let p=f[0];if(p==="--"){f=f.slice(1);break}for(let m of p.slice(1))m==="p"?l=!0:m==="V"?c=!0:m==="v"&&(u=!0);f=f.slice(1)}if(f.length===0)return te;if(u||c)return await kf(o,f,u,c);let[d,...h]=f;return a(d,h,[],n,!0,l,-1,r,s,i)}async function Fm(e,t,n,r=!1,s=!1,i=!1){let{runCommand:o}=e;if(t.length===0)return te;let a=t;if(a[0]==="--"&&(a=a.slice(1),a.length===0))return te;let l=a[0];if(l!=="__just_bash_tee_restore"&&!Hn.has(l))return L(`bash: builtin: ${l}: not a shell builtin
|
|
774
|
+
`);let[,...c]=a;return o(l,c,[],n,!0,!1,-1,r,s,i)}async function Cf(e,t,n,r,s,i=!1,o=!1){let{ctx:a,buildExportedEnv:l,executeUserScript:c}=e,f=await hf(a,t,s?"/usr/bin:/bin":void 0);if(!f)return wu(t)?L(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
|
|
775
|
+
`,127):L(`bash: ${t}: command not found
|
|
776
|
+
`,127);if("error"in f)return f.error==="permission_denied"?L(`bash: ${t}: Permission denied
|
|
777
|
+
`,126):L(`bash: ${t}: No such file or directory
|
|
778
|
+
`,127);if("script"in f)return t.includes("/")||(a.state.hashTable||(a.state.hashTable=new Map),a.state.hashTable.set(t,f.path)),await c(f.path,n,r);let{cmd:d,path:h}=f;t.includes("/")||(a.state.hashTable||(a.state.hashTable=new Map),a.state.hashTable.set(t,h));let p=i||o||r.length>0,m=p?r:a.state.groupStdin||"",y=!1,b=l();a.state.fileDescriptors??=new Map;let w={fs:a.fs,fsIdentity:jr(a.fs),cwd:a.state.cwd,env:a.state.env,assignShellVariable:async(x,D,$)=>{if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(x))throw new Error(`${x}: not a valid identifier`);let N=$===void 0?x:`${x}[${$}]`,O=cs(a,x,D);if(O===void 0)throw new Error(`${x}: circular name reference`);if(O===null)return;let R=O.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(?:\[(.*)\])?$/);if(!R)throw new Error(`${N}: not a valid identifier`);let W=R[1],P=R[2]??$;if(We(a,x)||We(a,W))throw new Error(`${W}: readonly variable`);if(P===void 0)a.state.env.set(W,D);else{let B=a.state.associativeArrays?.has(W)?"associative":"indexed";if(B==="associative"){H(a,W,P,D,B);return}let U=await pa(a,W,P);if(U.error)throw new G(U.error.exitCode,U.error.stdout,U.error.stderr);H(a,W,U.index,D,B)}},exportedEnv:b,get stdin(){return y=!0,m},stdinProvided:p,stdinUnavailable:o,limits:a.limits,executionScope:d.internalIsExtension?Ga(a.executionScope):a.executionScope,exec:(x,D)=>a.execFn(x,D,!1),execWithInheritedStdin:(x,D)=>a.execFn(x,{...D,stdin:m,stdinKind:"bytes"},!0),fetch:a.fetch,getRegisteredCommands:()=>Array.from(a.commands.keys()),sleep:a.sleep,trace:a.trace,fileDescriptors:a.state.fileDescriptors,xpgEcho:a.state.shoptOptions.xpg_echo,coverage:a.coverage,signal:a.state.signal,requireDefenseContext:a.requireDefenseContext,jsBootstrapCode:a.jsBootstrapCode,invokeTool:a.invokeTool},E=d.internalOriginalCommand,S=()=>{};if(E){let x=Object.getOwnPropertyDescriptors(w);x.executionScope={value:a.executionScope,enumerable:!0,configurable:!0,writable:!0};let D=Object.defineProperties(Object.create(Object.getPrototypeOf(w)),x),$=Pf(D,E.name),N=ha($.context,E.name);S=$.revoke,w.origCommand=O=>{let R=()=>E.execute(O,N);return E.trusted?Ce.runTrustedAsync(R):Ce.runUntrustedAsync(R)}}let v=Pf(w,t),A=ha(v.context,t),k=()=>{v.revoke(),S()};try{let x=()=>Ra(a.requireDefenseContext,"command",`${t} execution`,()=>d.execute(n,A)),D=()=>Tm(x,A,k,t,a.executionScope,a.state.signal),$=d.trusted?await Ce.runTrustedAsync(D):await D();return{...$,internalStdinConsumed:$.internalStdinConsumed??(y?r.length:0)}}catch(x){if(x instanceof C||x instanceof Ue||x instanceof zt)throw x;return L(`${t}: ${kt(Tt(x))}
|
|
779
|
+
`)}}async function ma(e,t){let n=e.state.inCondition;e.state.inCondition=!0;let r=new Qt(e.executionScope,"condition"),s=0;try{for(let i of t){let o=await e.executeStatement(i);r.appendResult(o),s=o.exitCode}}catch(i){throw r.prependTo(i),i}finally{e.state.inCondition=n}return r.build(s)}var Ys=0;function er(e,t){return e.state.lastExitCode=t,e.state.env.set("?",String(t)),t}function Rr(e,t,n,r){if(e instanceof Qe)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"break",stdout:t,stderr:n,exitCode:Ys};if(e instanceof Ke)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"continue",stdout:t,stderr:n,exitCode:Ys};if(e instanceof Le||e instanceof Ve||e instanceof G||e instanceof C)return e.prependOutput(t,n),{action:"rethrow",stdout:t,stderr:n,error:e};let s=Tt(e);return{action:"error",stdout:t,stderr:`${n}${s}
|
|
780
|
+
`,exitCode:1}}function Nf(e,t){return e!==void 0?{owns:!0,stdin:e}:t!==""?{owns:!0,stdin:t}:{owns:!1}}var gn=class{ctx;stdoutChunks=[];stderrChunks=[];totalBytes=0;constructor(t){this.ctx=t}append(t,n){let r=V(t)+V(n);r>this.ctx.limits.maxOutputSize-this.totalBytes&&cn(`total output size exceeded (>${this.ctx.limits.maxOutputSize} bytes), increase executionLimits.maxOutputSize`,"output_size"),t&&this.stdoutChunks.push(t),n&&this.stderrChunks.push(n),this.totalBytes+=r}appendUnaccounted(t,n){this.ctx.executionScope.appendOutput("stdout",t,"control-flow"),this.ctx.executionScope.appendOutput("stderr",n,"control-flow"),this.append(t,n)}replace(t,n){this.stdoutChunks=[],this.stderrChunks=[],this.totalBytes=0,this.append(t,n)}get stdout(){return this.stdoutChunks.join("")}get stderr(){return this.stderrChunks.join("")}build(t){let n=this.stdout,r=this.stderr;return{stdout:n,stderr:r,exitCode:t,internalOutputAccounting:{stdout:V(n),stderr:V(r)}}}};async function ya(e,t,n){let r=0;try{for(let s of t){let i=await e.executeStatement(s);n.append(i.stdout,i.stderr),r=i.exitCode}}catch(s){if(Br(s)||s instanceof Ve||s instanceof G||s instanceof C||s instanceof qt)throw s.prependOutput(n.stdout,n.stderr),s;return n.appendUnaccounted("",`${Tt(s)}
|
|
781
|
+
`),n.build(1)}return n.build(r)}async function Rf(e,t){return nt(e,t.redirections,"",()=>Mm(e,t))}async function Mm(e,t){let n=new gn(e);for(let r of t.clauses){let s=await ma(e,r.condition);if(n.append(s.stdout,s.stderr),s.exitCode===0)return ya(e,r.body,n)}return t.elseBody?ya(e,t.elseBody,n):n.build(0)}async function Of(e,t){return nt(e,t.redirections,"",()=>Bm(e,t))}async function Bm(e,t){let n=new gn(e),r=0,s=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return L(`bash: \`${t.variable}': not a valid identifier
|
|
782
|
+
`);let i=[];if(t.words===null)i=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)i=[];else try{for(let o of t.words){let a=await At(e,o);De(i,a.values,e.limits.maxArrayElements,"for-loop expansion")}}catch(o){if(o instanceof jt)return{stdout:"",stderr:o.stderr,exitCode:1};throw o}e.state.loopDepth++;try{for(let o of i){s++,s>e.limits.maxLoopIterations&&cn(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n.stdout,n.stderr),e.state.env.set(t.variable,o);try{for(let a of t.body){let l=await e.executeStatement(a);n.append(l.stdout,l.stderr),r=l.exitCode}}catch(a){let l=Rr(a,n.stdout,n.stderr,e.state.loopDepth);if(n.replace(l.stdout,l.stderr),l.exitCode!==void 0&&(r=er(e,l.exitCode)),l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return n.build(l.exitCode??1);throw l.error}}}finally{e.state.loopDepth--}return n.build(r)}async function Df(e,t){return nt(e,t.redirections,"",()=>Wm(e,t))}async function Wm(e,t){let n=t.line;n!==void 0&&(e.state.currentLine=n);let r=new gn(e),s=0,i=0;t.init&&await J(e,t.init.expression),e.state.loopDepth++;try{for(;i++,i>e.limits.maxLoopIterations&&cn(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r.stdout,r.stderr),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await J(e,t.condition.expression)===0));){try{for(let o of t.body){let a=await e.executeStatement(o);r.append(a.stdout,a.stderr),s=a.exitCode}}catch(o){let a=Rr(o,r.stdout,r.stderr,e.state.loopDepth);if(r.replace(a.stdout,a.stderr),a.exitCode!==void 0&&(s=er(e,a.exitCode)),a.action==="break")break;if(a.action==="continue"){t.update&&await J(e,t.update.expression);continue}if(a.action==="error")return r.build(a.exitCode??1);throw a.error}t.update&&await J(e,t.update.expression)}}finally{e.state.loopDepth--}return r.build(s)}async function If(e,t,n=""){return nt(e,t.redirections,n,r=>Vm(e,t,n,r))}async function Vm(e,t,n,r){let s=new gn(e),i=0,o=0,a=Nf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&cn(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let c=0,u=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let p=await e.executeStatement(h);s.append(p.stdout,p.stderr),c=p.exitCode}}catch(h){if(h instanceof Qe){if(s.append(h.stdout,h.stderr),h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=s.stdout,h.stderr=s.stderr,e.state.inCondition=d,h;u=!0}else if(h instanceof Ke){if(s.append(h.stdout,h.stderr),h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=s.stdout,h.stderr=s.stderr,e.state.inCondition=d,h;f=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if((u||f)&&(i=er(e,Ys)),u)break;if(!f){if(c!==0)break;try{for(let h of t.body){let p=await e.executeStatement(h);s.append(p.stdout,p.stderr),i=p.exitCode}}catch(h){let p=Rr(h,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(p.stdout,p.stderr),p.exitCode!==void 0&&(i=er(e,p.exitCode)),p.action==="break")break;if(p.action==="continue")continue;if(p.action==="error")return s.build(p.exitCode??1);throw p.error}}}}finally{e.state.loopDepth--,a.owns&&(e.state.groupStdin=l)}return s.build(i)}async function _f(e,t,n=""){return nt(e,t.redirections,n,r=>zm(e,t,n,r))}async function zm(e,t,n,r){let s=new gn(e),i=0,o=0,a=Nf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&cn(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let c=await ma(e,t.condition);if(s.append(c.stdout,c.stderr),c.exitCode===0)break;try{for(let u of t.body){let f=await e.executeStatement(u);s.append(f.stdout,f.stderr),i=f.exitCode}}catch(u){let f=Rr(u,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(f.stdout,f.stderr),f.exitCode!==void 0&&(i=er(e,f.exitCode)),f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error")return s.build(f.exitCode??1);throw f.error}}}finally{e.state.loopDepth--,a.owns&&(e.state.groupStdin=l)}return s.build(i)}async function Tf(e,t){return nt(e,t.redirections,"",()=>Um(e,t))}async function Um(e,t){let n=new gn(e),r=0,s=await se(e,t.word),i=!1;for(let o=0;o<t.items.length;o++){let a=t.items[o],l=i;if(!i)for(let c of a.patterns){let u=await se(e,c);au(c)&&(u=et(u));let f=e.state.shoptOptions.nocasematch,d=e.state.shoptOptions.extglob;if(Gn(s,u,f,d,e.limits.maxCallDepth)){l=!0;break}}if(l){let c=await ya(e,a.body,n);if(n.replace(c.stdout,c.stderr),r=c.exitCode,a.terminator===";;")break;a.terminator===";&"?i=!0:i=!1}else i=!1}return n.build(r)}function ga(e,t){if(e.parts.length!==1)return!1;let n=e.parts[0];return n.type!=="Literal"?!1:t.includes(n.value)}async function Lf(e,t,n){let r=t.timed?fi():0,s="",i=te,o=0,a=[],l="",c=0,u=t.commands.length>1,f=e.state.lastArg,d=e.state.groupStdin,h=e.state.groupStdinSourceFd;for(let w=0;w<t.commands.length;w++){let E=t.commands[w],S=w===t.commands.length-1,v=w===0;u&&(e.state.lastArg="",e.state.groupStdin=v?d:void 0,e.state.groupStdinSourceFd=v?h:void 0);let A=u&&(!S||!e.state.shoptOptions.lastpipe),k=A?new Map(e.state.env):null,x=A?ot(e.state.arrays):null,D,$=e.executionScope.outputBytesUsed;try{e.state.commandCount=e.executionScope.chargeCommand(),D=await n(E,s,!v)}catch(N){if(N instanceof Xe)D={stdout:N.stdout,stderr:N.stderr,exitCode:1};else if(N instanceof G&&t.commands.length>1)D={stdout:N.stdout,stderr:N.stderr,exitCode:N.exitCode};else if(N instanceof Ve&&t.commands.length>1)D={stdout:N.stdout,stderr:N.stderr,exitCode:N.exitCode};else throw k&&(e.state.env=k,e.state.arrays=x??new Map),N}finally{u&&(v&&(d=e.state.groupStdin,h=e.state.groupStdinSourceFd),e.state.groupStdin=d,e.state.groupStdinSourceFd=h)}if(k&&(e.state.env=k,e.state.arrays=x??new Map),D=e.executionScope.accountResult(D,"pipeline",e.executionScope.outputBytesUsed-$),!S){let N=t.pipeStderr?.[w]??!1,O=D.internalOutputAccounting?.stdout??0,R=N?D.internalOutputAccounting?.stderr??0:0;Ha(e.executionScope,O+R,"pipeline"),D={...D,internalOutputAccounting:{stdout:0,stderr:N?0:D.internalOutputAccounting?.stderr??0}}}a.push(D.exitCode),D.exitCode!==0&&(o=D.exitCode),S?i=D:(t.pipeStderr?.[w]??!1?s=Ut(D.stderr)+_t(D):(s=_t(D),l+=D.stderr,c+=D.internalOutputAccounting?.stderr??0),i={stdout:"",stderr:"",exitCode:D.exitCode})}l&&(i={...i,stderr:l+i.stderr,internalOutputAccounting:{stdout:i.internalOutputAccounting?.stdout??0,stderr:c+(i.internalOutputAccounting?.stderr??0)}});let p=t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand",m=i.internalPipeStatusOverride??a;if(p){Ee(e,"PIPESTATUS");for(let w=0;w<m.length;w++)H(e,"PIPESTATUS",w,String(m[w]))}if(e.state.options.pipefail&&o!==0&&(i={...i,exitCode:o}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let E=(fi()-r)/1e3,S=Math.floor(E/60),v=E%60,A;t.timePosix?A=`real ${E.toFixed(2)}
|
|
782
783
|
user 0.00
|
|
783
784
|
sys 0.00
|
|
784
|
-
`:
|
|
785
|
-
real ${`${
|
|
785
|
+
`:A=`
|
|
786
|
+
real ${`${S}m${v.toFixed(3)}s`}
|
|
786
787
|
user 0m0.000s
|
|
787
788
|
sys 0m0.000s
|
|
788
|
-
`,i={...i,stderr:i.stderr+
|
|
789
|
-
`),i.build(1))}return i.build(o)}async function
|
|
790
|
-
`),o.build(1)}return f(),o.build(a)}async function
|
|
789
|
+
`,i={...i,stderr:i.stderr+A}}u&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=f),i=e.executionScope.accountResult(i,"pipeline");let{internalPipeStatusOverride:y,...b}=i;return b}function wa(e){return e?{...e,options:e.options?[...e.options]:void 0,actions:e.actions?[...e.actions]:void 0}:void 0}function jm(e){return e?new Map(Array.from(e,([t,n])=>[t,wa(n)])):void 0}function qm(e){if(!e)return;let t=new Map,n=new Map;for(let[r,s]of e){let i=t.get(s);i||(i=new Set(s),t.set(s,i)),n.set(r,i)}return n}function Gm(e){return e?.map(t=>new Map(Array.from(t,([n,r])=>[n,r?{kind:r.kind,elements:new Map(r.elements)}:void 0])))}function Hm(e){return e?new Map(Array.from(e,([t,n])=>[t,n.map(r=>({...r}))])):void 0}function Ea(e){let t={env:e.env,arrays:e.arrays,cwd:e.cwd,previousDir:e.previousDir,lastExitCode:e.lastExitCode,lastArg:e.lastArg,currentLine:e.currentLine,options:e.options,shoptOptions:e.shoptOptions,fileDescriptors:e.fileDescriptors,inputFds:e.inputFds,deviceFds:e.deviceFds,fdAliases:e.fdAliases,closedStandardFds:e.closedStandardFds,nextFd:e.nextFd,readonlyVars:e.readonlyVars,associativeArrays:e.associativeArrays,namerefs:e.namerefs,boundNamerefs:e.boundNamerefs,invalidNamerefs:e.invalidNamerefs,integerVars:e.integerVars,lowercaseVars:e.lowercaseVars,uppercaseVars:e.uppercaseVars,exportedVars:e.exportedVars,tempExportedVars:e.tempExportedVars,localExportedVars:e.localExportedVars,declaredVars:e.declaredVars,localScopes:e.localScopes,localArrayScopes:e.localArrayScopes,localVarDepth:e.localVarDepth,localVarStack:e.localVarStack,fullyUnsetLocals:e.fullyUnsetLocals,tempEnvBindings:e.tempEnvBindings,mutatedTempEnvVars:e.mutatedTempEnvVars,accessedTempEnvVars:e.accessedTempEnvVars,functions:e.functions,callDepth:e.callDepth,sourceDepth:e.sourceDepth,callLineStack:e.callLineStack,funcNameStack:e.funcNameStack,sourceStack:e.sourceStack,currentSource:e.currentSource,inCondition:e.inCondition,loopDepth:e.loopDepth,parentHasLoopContext:e.parentHasLoopContext,errexitSafe:e.errexitSafe,directoryStack:e.directoryStack,hashTable:e.hashTable,completionSpecs:e.completionSpecs,defaultCompletionSpec:e.defaultCompletionSpec,emptyCompletionSpec:e.emptyCompletionSpec,groupStdin:e.groupStdin,groupStdinSourceFd:e.groupStdinSourceFd,bashPid:e.bashPid,expansionExitCode:e.expansionExitCode,expansionStderr:e.expansionStderr};e.env=new Map(e.env),e.arrays=ot(e.arrays),e.options={...e.options},e.shoptOptions={...e.shoptOptions},e.fileDescriptors=e.fileDescriptors?new Map(e.fileDescriptors):void 0,e.inputFds=e.inputFds?new Set(e.inputFds):void 0,e.deviceFds=e.deviceFds?new Set(e.deviceFds):void 0,e.fdAliases=qm(e.fdAliases),e.closedStandardFds=e.closedStandardFds?new Set(e.closedStandardFds):void 0,e.readonlyVars=new Set(e.readonlyVars),e.associativeArrays=new Set(e.associativeArrays),e.namerefs=new Set(e.namerefs),e.boundNamerefs=new Set(e.boundNamerefs),e.invalidNamerefs=new Set(e.invalidNamerefs),e.integerVars=new Set(e.integerVars),e.lowercaseVars=new Set(e.lowercaseVars),e.uppercaseVars=new Set(e.uppercaseVars),e.exportedVars=new Set(e.exportedVars),e.tempExportedVars=new Set(e.tempExportedVars),e.localExportedVars=e.localExportedVars?.map(r=>new Set(r)),e.declaredVars=new Set(e.declaredVars),e.localScopes=e.localScopes.map(r=>new Map(r)),e.localArrayScopes=Gm(e.localArrayScopes),e.localVarDepth=e.localVarDepth?new Map(e.localVarDepth):void 0,e.localVarStack=Hm(e.localVarStack),e.fullyUnsetLocals=e.fullyUnsetLocals?new Map(e.fullyUnsetLocals):void 0,e.tempEnvBindings=e.tempEnvBindings?.map(r=>new Map(r)),e.mutatedTempEnvVars=e.mutatedTempEnvVars?new Set(e.mutatedTempEnvVars):void 0,e.accessedTempEnvVars=e.accessedTempEnvVars?new Set(e.accessedTempEnvVars):void 0,e.functions=new Map(e.functions),e.callLineStack=e.callLineStack?[...e.callLineStack]:void 0,e.funcNameStack=e.funcNameStack?[...e.funcNameStack]:void 0,e.sourceStack=e.sourceStack?[...e.sourceStack]:void 0,e.directoryStack=e.directoryStack?[...e.directoryStack]:void 0,e.hashTable=e.hashTable?new Map(e.hashTable):void 0,e.completionSpecs=jm(e.completionSpecs),e.defaultCompletionSpec=wa(e.defaultCompletionSpec),e.emptyCompletionSpec=wa(e.emptyCompletionSpec);let n=!1;return()=>{n||(n=!0,Object.assign(e,t))}}async function Ff(e,t,n,r,s=!1){let i=e.state.loopDepth,o=new Map;for(let l of e.state.fileDescriptors?.keys()??[]){let c=lt(e,l);c&&o.set(l,c)}let a=Ea(e.state);e.state.parentHasLoopContext=i>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++;try{return await nt(e,t.redirections,n,l=>Zm(e,t,l.stdin??n,r,s||l.stdin!==void 0))}finally{let l=new Map;for(let[c,u]of o){let f=lt(e,c),d=u.kind==="input"&&f?.kind==="input"?u.content.length-f.content.length:u.kind==="readwrite"&&f?.kind==="readwrite"&&u.path===f.path?f.position-u.position:0;if(d<=0)continue;let h=Math.min(...dn(e,c));l.set(h,Math.max(l.get(h)??0,d))}a();for(let[c,u]of l)hn(e,c,u)}}async function Zm(e,t,n,r,s){(s||n)&&(e.state.groupStdin=n);let i=new Qt(e.executionScope,"subshell"),o=0;try{for(let a of t.body){let l=await r(a);i.appendResult(l),o=l.exitCode}}catch(a){if(a instanceof C)throw i.prependTo(a),a;return a instanceof qt||a instanceof Qe||a instanceof Ke?(i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(0)):a instanceof G||a instanceof Le||a instanceof Ve?(i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(a.exitCode)):(i.append("stderr",`${Tt(a)}
|
|
790
|
+
`),i.build(1))}return i.build(o)}async function Mf(e,t,n,r,s=!1){return nt(e,t.redirections,n,i=>Qm(e,t,n,r,s,i))}async function Qm(e,t,n,r,s,i){let o=new Qt(e.executionScope,"group"),a=0,l=i.stdin??n,c=s||n!==""||i.stdin!==void 0,u=e.state.groupStdin;c&&(e.state.groupStdin=l);let f=()=>{(c||u!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=u)};try{for(let d of t.body){let h=await r(d);o.appendResult(h),a=h.exitCode}}catch(d){if(f(),d instanceof C)throw o.prependTo(d),d;if(Br(d)||d instanceof Ve||d instanceof G)throw d.prependOutput(o.stdout,o.stderr),d;return o.append("stderr",`${Tt(d)}
|
|
791
|
+
`),o.build(1)}return f(),o.build(a)}async function Bf(e,t,n,r,s){let i;try{i=await e.fs.readFile(t)}catch{return L(`bash: ${t}: No such file or directory
|
|
791
792
|
`,127)}if(i.startsWith("#!")){let l=i.indexOf(`
|
|
792
|
-
`);l!==-1&&(i=i.slice(l+1))}let o=e.state.loopDepth,a=
|
|
793
|
-
`);throw l}}function
|
|
794
|
-
`);let r=0,s=-1,i=!1;try{for(let l=0;l<t.pipelines.length;l++){let c=t.pipelines[l],u=l>0?t.operators[l-1]:null;if(u==="&&"&&r!==0||u==="||"&&r===0)continue;let f=await this.executePipeline(c);n.appendResult(f,
|
|
795
|
-
`,127));if(
|
|
796
|
-
`)}})}async executeConditionalCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),
|
|
797
|
-
`,r)}})}};function
|
|
798
|
-
${
|
|
799
|
-
`)}`)}let r=[];for(let
|
|
800
|
-
`],["
|
|
793
|
+
`);l!==-1&&(i=i.slice(l+1))}let o=e.state.loopDepth,a=Ea(e.state);e.state.parentHasLoopContext=o>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,r&&(e.state.groupStdin=r),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(n.length)),e.state.env.set("@",n.join(" ")),e.state.env.set("*",n.join(" "));for(let l=0;l<n.length&&l<9;l++)e.state.env.set(String(l+1),n[l]);for(let l=n.length+1;l<=9;l++)e.state.env.delete(String(l));try{let c=new Q().parse(i),u=await s(c);return a(),u}catch(l){if(a(),l instanceof G)return F(l.stdout,l.stderr,l.exitCode);if(l instanceof C)throw l;if(l.name==="ParseException")return L(`bash: ${t}: ${l.message}
|
|
794
|
+
`);throw l}}function Km(e){throw new TypeError(`Unsupported command node: ${JSON.stringify(e)}`)}var Or=class{ctx;constructor(t,n){this.ctx={state:n,fs:t.fs,commands:t.commands,limits:t.limits,executionScope:t.executionScope,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode,invokeTool:t.invokeTool}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||Ce.isInSandboxedContext())return;let n=`interpreter ${t} attempted outside defense context`;throw new zt(n,{timestamp:Date.now(),type:"missing_defense_context",message:n,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:Ce.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,n=this.ctx.state.tempExportedVars,r=new Set;if(t)for(let i of t)r.add(i);if(n)for(let i of n)r.add(i);if(r.size===0)return Object.create(null);let s=Object.create(null);for(let i of r){let o=this.ctx.state.env.get(i);o!==void 0&&(s[i]=o)}return s}async executeScript(t){this.assertDefenseContext("execution");let n=0,r=new Qt(this.ctx.executionScope,"script");for(let s of t.statements)try{let i=await this.executeStatement(s);r.appendResult(i,ci(i)),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(i){if(i instanceof G)throw i.prependOutput(r.stdout,r.stderr),i;if(i instanceof rt)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Zt(this.ctx.state.env)};if(i instanceof C)throw r.prependTo(i),i;if(i instanceof Ve)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Zt(this.ctx.state.env)};if(i instanceof ze)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Zt(this.ctx.state.env)};if(i instanceof Xe)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Zt(this.ctx.state.env)};if(i instanceof le){r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(i instanceof Mr){r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(i instanceof Qe||i instanceof Ke){if(this.ctx.state.loopDepth>0)throw i.prependOutput(r.stdout,r.stderr),i;r.append("stdout",i.stdout),r.append("stderr",i.stderr);continue}throw i instanceof Le&&i.prependOutput(r.stdout,r.stderr),i}return{...r.build(n),env:Zt(this.ctx.state.env)}}async executeUserScript(t,n,r=""){return Bf(this.ctx,t,n,r,s=>this.executeScript(s))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Ue;if(t.deferredError)throw new xe(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return te;this.ctx.state.errexitSafe=!1;let n=new Qt(this.ctx.executionScope,"statement");this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&n.append("stderr",`${t.sourceText}
|
|
795
|
+
`);let r=0,s=-1,i=!1;try{for(let l=0;l<t.pipelines.length;l++){let c=t.pipelines[l],u=l>0?t.operators[l-1]:null;if(u==="&&"&&r!==0||u==="||"&&r===0)continue;let f=await this.executePipeline(c);n.appendResult(f,ci(f)),r=f.exitCode,s=l,i=c.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}}catch(l){throw n.prependTo(l),l}let o=s<t.pipelines.length-1,a=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=o||i||a,this.ctx.state.options.errexit&&r!==0&&s===t.pipelines.length-1&&!i&&!this.ctx.state.inCondition&&!a){let l=new Ve(r);throw l.prependOutput(n.stdout,n.stderr),l}return n.build(r)}async executePipeline(t){return Lf(this.ctx,t,(n,r,s)=>this.executeCommand(n,r,s))}async executeCommand(t,n,r=!1){let s=iu(this.ctx),i;try{i=await this.executeCommandInner(t,n,r)}catch(a){throw await no(this.ctx,s).catch(()=>{}),a}let o=await no(this.ctx,s);return!o.stdout&&!o.stderr?i:{...i,stdout:o.stdout?_t(i)+o.stdout:i.stdout,stdoutKind:o.stdout?"bytes":i.stdoutKind,stderr:i.stderr+o.stderr}}async executeCommandInner(t,n,r){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,n,r);case"If":return Rf(this.ctx,t);case"For":return Of(this.ctx,t);case"CStyleFor":return Df(this.ctx,t);case"While":return If(this.ctx,t,n);case"Until":return _f(this.ctx,t,n);case"Case":return Tf(this.ctx,t);case"Subshell":return this.executeSubshell(t,n,r);case"Group":return this.executeGroup(t,n,r);case"FunctionDef":return Wu(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return Km(t)}}async executeSimpleCommand(t,n,r){let s;try{return await this.executeSimpleCommandInner(t,n,r,i=>{s=i})}catch(i){if(s?.finish(),i instanceof jt)return L(i.stderr);throw i}}async executeSimpleCommandInner(t,n,r,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let O=t,R=0;for(;;){let W=this.expandAlias(O);if(W===O)break;if(R>=this.ctx.limits.maxCallDepth)throw new C(`alias expansion depth limit exceeded (${this.ctx.limits.maxCallDepth})`,"recursion");R++,O=W}this.aliasExpansionStack.clear(),O!==t&&(t=O)}this.ctx.state.expansionStderr="",this.ctx.state.lastSubstitutionExitCode=null;let i=await wf(this.ctx,t);if(i.error)return i.error;let o=i.tempAssignments,a=i.xtraceOutput,l=()=>{for(let[O,R]of o)R===void 0?this.ctx.state.env.delete(O):this.ctx.state.env.set(O,R)};if(!t.name){if(t.redirections.length>0){let R=Kn(this.ctx,t.redirections,Mu);s(R);let W=await R.prepare(n);if(W.error){if(l(),!W.errorCause)return R.finish(),W.error;try{return Xn(W)}finally{R.finish()}}let P=F("",a,hs(this.ctx.state,t.redirections)),B=await mn(this.ctx,P,t.redirections.length>0,W.outputRoutes);return R.finish(),B}this.ctx.state.lastArg="";let O=(this.ctx.state.expansionStderr||"")+a;return this.ctx.state.expansionStderr="",F("",O,hs(this.ctx.state,[]))}let c=t.name&&ga(t.name,["local","declare","typeset","export","readonly"]),u=Array.from(o.keys());if(u.length>0&&!c){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let O of u)this.ctx.state.tempExportedVars.add(O)}let f=await se(this.ctx,t.name),d=[],h=[],p=(O,R)=>{if(d.length>=this.ctx.limits.maxArrayElements)throw new C(`expanded argument element limit exceeded (${this.ctx.limits.maxArrayElements})`,"array_elements");d.push(O),h.push(R)};if(ga(t.name,["local","declare","typeset","export","readonly"])&&(f==="local"||f==="declare"||f==="typeset"||f==="export"||f==="readonly"))for(let O of t.args){let R=await yu(this.ctx,O);if(R)p(R,!0);else{let W=await gu(this.ctx,O);if(W!==null)p(W,!0);else{let P=await At(this.ctx,O);for(let B of P.values)p(B,P.quoted)}}}else for(let O of t.args){let R=await At(this.ctx,O);for(let W of R.values)p(W,R.quoted)}let y=t.name.parts.every(O=>O.type==="CommandSubstitution"||O.type==="ParameterExpansion"||O.type==="ArithmeticExpansion");!f&&y&&d.length>0&&(f=d.shift(),h.shift());let b=Kn(this.ctx,t.redirections,f==="exec"?Bu:vr);s(b);let w=await b.prepare(n);if(w.error)return l(),w.errorCause?Xn(w):(b.finish(),w.error);let E=w.stdinSourceFd,S=w.stdin!==void 0,v=r||w.stdinReplaced;if(w.stdin!==void 0&&(n=w.stdin),!f)return y?(b.finish(),F("","",hs(this.ctx.state,t.redirections))):(b.finish(),L(`bash: : command not found
|
|
796
|
+
`,127));if(f==="exec"&&(d.length===0||d[0]==="--")){for(let[O,R]of o)R===void 0?this.ctx.state.env.delete(O):this.ctx.state.env.set(O,R);if(this.ctx.state.tempExportedVars)for(let O of o.keys())this.ctx.state.tempExportedVars.delete(O);return b.finish(),te}if(this.ctx.state.extraArgs){let O=this.ctx.state.extraArgs;this.ctx.state.extraArgs=void 0;for(let R of O)p(R,!0)}let A=await yf(this.ctx,f,d);o.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(o)));let k,x=null;try{k=await this.runCommand(f,d,h,n,!1,!1,E,S,v,w.stdinUnavailable)}catch(O){if(O instanceof Qe||O instanceof Ke)x=O,k=te;else throw O}E>=0&&f!=="read"&&hn(this.ctx,E,k.internalStdinConsumed??0);let D=a+A;if(D&&(k={...k,stderr:D+k.stderr}),k=await mn(this.ctx,k,t.redirections.length>0,w.outputRoutes,k.internalProducerCommand??f,k.internalProducerOmitsShellPrefix),b.finish(),x)throw x;if(d.length>0){let O=d[d.length-1];if((f==="declare"||f==="local"||f==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(O)){let R=O.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);R&&(O=R[1])}this.ctx.state.lastArg=O}else this.ctx.state.lastArg=f;let $=Du(f)&&f!=="unset"&&f!=="eval";if(!this.ctx.state.options.posix||!$)for(let[O,R]of o)this.ctx.state.fullyUnsetLocals?.has(O)||(R===void 0?this.ctx.state.env.delete(O):this.ctx.state.env.set(O,R));if(this.ctx.state.tempExportedVars)for(let O of o.keys())this.ctx.state.tempExportedVars.delete(O);return o.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(k={...k,stderr:this.ctx.state.expansionStderr+k.stderr},this.ctx.state.expansionStderr=""),k}async runCommand(t,n,r,s,i=!1,o=!1,a=-1,l=!1,c=!1,u=!1){let f={ctx:this.ctx,runCommand:(p,m,y,b,w,E,S,v,A,k)=>this.runCommand(p,m,y,b,w,E,S,v,A,k),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(p,m,y)=>this.executeUserScript(p,m,y)},d=await $f(f,t,n,r,s,i,o,a,l,c,u);return d!==null?d.internalProducerCommand===void 0?{...d,internalProducerCommand:t}:d:{...await Cf(f,t,n,s,o,c,u),internalProducerCommand:t}}aliasExpansionStack=new Set;expandAlias(t){return Ul({env:this.ctx.state.env,limits:this.ctx.limits},t,this.aliasExpansionStack)}async findCommandInPath(t){return Ks(this.ctx,t)}async executeSubshell(t,n="",r=!1){return Ff(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeGroup(t,n="",r=!1){return Mf(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeArithmeticCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),nt(this.ctx,t.redirections,"",async()=>{try{let n=await J(this.ctx,t.expression.expression),r=be(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){return L(`bash: arithmetic expression: ${n.message}
|
|
797
|
+
`)}})}async executeConditionalCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),nt(this.ctx,t.redirections,"",async()=>{try{let n=await un(this.ctx,t.expression),r=be(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){let r=n instanceof le?1:2;return L(`bash: conditional expression: ${n.message}
|
|
798
|
+
`,r)}})}};function ba(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function Xm(e){let t=ba(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var Ym=3;function Wf(e){let t=e;for(let n=0;n<Ym;n++){if(t.includes("\\")||t.includes(";")||/%(?![0-9a-f]{2})/i.test(t))return!0;let r=t.toLowerCase();if(r.includes("%2f")||r.includes("%2e")||r.includes("%5c")||r.includes("%3b"))return!0;let s;try{s=decodeURIComponent(t)}catch{return!0}if(s===t)return!1;t=s}return t.includes("%")}function Jm(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function Sa(e,t){let n=ba(e);if(!n)return!1;let r=Xm(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&Wf(n.pathname)?!1:Jm(n.pathname,r.pathPrefix)}function Vf(e){return typeof e=="string"?e:e.url}function zf(e,t){return!t||t.length===0?!1:t.some(n=>Sa(e,Vf(n)))}function Aa(e){let t=ey(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=Uf(t);if(n)return Js(n);let r=ny(t);return r?ry(r):!1}function ey(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function ty(e){if(!e)return null;let t=10,n=e;if(n.startsWith("0x")||n.startsWith("0X")?(t=16,n=n.slice(2)):n.length>1&&n.startsWith("0")&&(t=8),!n||t===16&&!/^[0-9a-fA-F]+$/.test(n)||t===10&&!/^\d+$/.test(n)||t===8&&!/^[0-7]+$/.test(n))return null;let r=Number.parseInt(n,t);return!Number.isFinite(r)||r<0?null:r}function Uf(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>ty(l));if(n.some(l=>l===null))return null;let r=n;if(t.length===1){let l=r[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,c]=r;return l>255||c>16777215?null:[l,c>>>16&255,c>>>8&255,c&255]}if(t.length===3){let[l,c,u]=r;return l>255||c>255||u>65535?null:[l,c,u>>>8&255,u&255]}let[s,i,o,a]=r;return s>255||i>255||o>255||a>255?null:[s,i,o,a]}function ny(e){let t=e,n=null;if(t.includes(".")){let m=t.lastIndexOf(":");if(m<0)return null;let y=t.slice(m+1),b=Uf(y);if(!b)return null;n=b,t=t.slice(0,m)}let r=t.includes("::")?t.split("::").length-1:0;if(r>1)return null;let[s,i]=t.split("::"),o=s?s.split(":").filter(Boolean):[],a=i?i.split(":").filter(Boolean):[],l=m=>/^[0-9a-f]{1,4}$/i.test(m)?Number.parseInt(m,16):null,c=o.map(l),u=a.map(l);if(c.some(m=>m===null)||u.some(m=>m===null))return null;let f=n?2:0,d=c.length+u.length+f,h=0;if(r===1){if(h=8-d,h<0)return null}else if(d!==8)return null;let p=[...c,...new Array(h).fill(0),...u];return n&&(p.push(n[0]<<8|n[1]),p.push(n[2]<<8|n[3])),p.length===8?p:null}function Js(e){let[t,n]=e;return t===127||t===10||t===172&&n>=16&&n<=31||t===192&&n===168||t===169&&n===254||t===0||t===100&&n>=64&&n<=127||t===198&&(n===18||n===19)||t===192&&n===0&&e[2]===0||t===192&&n===0&&e[2]===2||t===198&&n===51&&e[2]===100||t===203&&n===0&&e[2]===113||t>=240}function ry(e){if(e.every(s=>s===0)||e.slice(0,7).every(s=>s===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Js(s)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Js(s)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let s=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return Js(s)}return!1}function jf(e){let t=[];for(let n of e){if(typeof n!="string"&&(n===null||typeof n!="object"||!("url"in n)||typeof n.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let r=Vf(n);if(!ba(r)){t.push(`Invalid URL in allow-list: "${r}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(r);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${r}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${r}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&Wf(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${r}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${r}"`)}return t}var ut=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},On=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},Vt=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},ei=class extends Error{constructor(t,n){super(`HTTP method '${t}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}},Dn=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var sy=20,iy=3e4,oy=10485760,ay=["GET","HEAD"],Dr;typeof __BROWSER__<"u"&&__BROWSER__?Dr=null:(Dr=import("guarded-fetch"),Dr.catch(()=>{}));var ly=new Set(["GET","HEAD","OPTIONS"]),cy=new Set([301,302,303,307,308]);function Ir(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function uy(e){if(e?.aborted)throw Ir(e)}function ka(e){let t=e.allowedUrlPrefixes??[];if(e._dnsResolve)throw new Error("NetworkConfig._dnsResolve is no longer supported: DNS resolution is performed by guarded-fetch and cannot be overridden");if(e._createConnectionOwner)throw new Error("NetworkConfig._createConnectionOwner is no longer supported: connect-time IP pinning is performed by guarded-fetch and cannot be overridden");let n=e._fetch;if(!e.dangerouslyAllowFullInternetAccess){let S=jf(t);if(S.length>0)throw new Error(`Invalid network allow-list:
|
|
799
|
+
${S.join(`
|
|
800
|
+
`)}`)}let r=[];for(let S of t)typeof S=="object"&&S.transform&&S.transform.length>0&&r.push(S);function s(S){if(r.length===0)return null;let v=null;for(let A of r)if(Sa(S,A.url)&&A.transform){v||(v=new Headers);for(let k of A.transform)for(let[x,D]of Object.entries(k.headers))v.set(x,D)}return v}if(e.maxRedirects!==void 0&&(!Number.isSafeInteger(e.maxRedirects)||e.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let i=e.maxRedirects??sy,o=e.timeoutMs??iy,a=e.maxResponseSize??oy,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??ay,c=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),u=[];for(let S of t){let v=typeof S=="string"?S:S.url;try{u.push(new URL(v).hostname)}catch{}}function f(S){try{return new URL(S).hostname||"localhost.invalid"}catch{return"localhost.invalid"}}function d(S){return e.dangerouslyAllowFullInternetAccess?c?{allowedHosts:void 0,skipSsrfCheckForAllowedHosts:void 0}:{allowedHosts:[f(S)],skipSsrfCheckForAllowedHosts:!0}:{allowedHosts:u,skipSsrfCheckForAllowedHosts:!c}}function h(S){try{return Aa(new URL(S).hostname)}catch{return!1}}async function p(S,v){let A={method:v.method,headers:v.headers,signal:v.signal,redirect:"manual"};return v.body!==void 0&&(A.body=v.body),await(n??globalThis.fetch)(S,A)}function m(S){if(!e.dangerouslyAllowFullInternetAccess&&!zf(S,t))throw new ut(S)}function y(S){if(!c)return;let v;try{v=new URL(S)}catch{throw new ut(S,"invalid URL")}if(Aa(v.hostname))throw new ut(S,"private/loopback IP address blocked")}function b(S){if(e.dangerouslyAllowFullInternetAccess)return;let v=S.toUpperCase();if(!l.includes(v))throw new ei(v,l)}function w(S,v,A,k){if(!A.isGuardedFetchError(S))return S;let x=S,{onRedirectHop:D,subReason:$}=k;switch(x.code){case"host_not_allowed":case"protocol_not_allowed":return D?new Vt(v):new ut(v);case"hostname_unsafe":return D?new Vt(v):new ut(v,$==="dns_resolution_failed"?"DNS resolution failed for private IP check":"hostname resolves to private/loopback IP address");case"redirect_to_unsafe_host":return new Vt(v);case"too_many_redirects":return new On(i);case"response_too_large":return new Dn(a);default:return S}}async function E(S,v={}){let A=v.method?.toUpperCase()??"GET",k=v.followRedirects??!0;if(v.maxRedirects!==void 0&&(!Number.isSafeInteger(v.maxRedirects)||v.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let x=v.maxRedirects??i,D=Math.min(i,x),$=v.timeoutMs!==void 0?Math.min(v.timeoutMs,o):o,N=new AbortController,O=Lr(()=>N.abort(new DOMException("The operation was aborted","AbortError")),$),R=Wr(v.signal,N.signal);try{m(S),y(S),b(A);let W=Dr?await Dr:null,P=S,B=0,U=[],_=A,T=v.body,z=v.headers,ne=!1;for(;;){uy(R.signal);let Y=await Ce.runTrustedAsync(async()=>{let Te=z;if(ne&&Te){let It=Te instanceof Headers?new Headers(Te):new Headers(Te);It.delete("authorization"),It.delete("cookie"),Te=It}let dt=s(P),Dt=dy(Te,dt),ht={method:_,headers:Dt,signal:R.signal,followRedirects:!1,timeoutMs:$,sanitizeHeaders:!1};if(T&&!ly.has(_)&&(ht.body=T),Object.assign(ht,d(P)),!W||h(P)){if(c)throw new ut(P,"DNS pinning unavailable for private IP enforcement");return await p(P,ht)}c?n&&(ht.fetch=n):(ht.fetch=n??globalThis.fetch,ht.dispatcher=null);let pt;ht.onUrlBlocked=It=>{pt=It.subReason};try{return await W.guardedFetch(P,ht)}catch(It){throw w(It,P,W,{onRedirectHop:B>0,subReason:pt})}});if(cy.has(Y.status)&&k){let Te=Y.headers.get("location");if(!Te)return await qf(Y,P,a,R.signal,U);U.push({status:Y.status,statusText:Y.statusText,headers:Gf(Y.headers)});let dt=new URL(Te,P).href;await va(fy(Y),R.signal);try{m(dt),y(dt)}catch(pt){throw R.signal?.aborted?Ir(R.signal):pt instanceof ut?new Vt(dt):pt}let Dt=Y.status;if(((Dt===301||Dt===302)&&_==="POST"||Dt===303&&_!=="GET"&&_!=="HEAD")&&(_="GET",T=void 0,b(_)),new URL(dt).origin!==new URL(P).origin&&(ne=!0),B++,B>D)throw new On(D);P=dt;continue}return await qf(Y,P,a,R.signal,U)}}finally{Fr(O),R.cleanup()}}return E}async function va(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),Ir(t);let n,r=new Promise((s,i)=>{n=()=>i(Ir(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function fy(e){e.body&&!e.body.locked&&await e.body.cancel()}function dy(e,t){if(!e&&!t)return;if(!t)return e;let n=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,s]of t)n.set(r,s);return n}function Gf(e){let t=Object.create(null);return e.forEach((n,r)=>{t[r.toLowerCase()]=n}),t}async function qf(e,t,n,r,s){let i=Gf(e.headers);if(n>0){let l=e.headers.get("content-length");if(l){let c=parseInt(l,10);if(!Number.isNaN(c)&&c>n)throw new Dn(n)}}let o;if(n>0&&e.body){let l=e.body.getReader(),c=[],u=0;try{for(;;){let{done:d,value:h}=await va(l.read(),r);if(d)break;if(h){if(u+=h.byteLength,u>n)throw await l.cancel(),new Dn(n);c.push(h)}}}catch(d){throw r?.aborted&&await l.cancel(Ir(r)).catch(()=>{}),d}o=new Uint8Array(u);let f=0;for(let d of c)o.set(d,f),f+=d.byteLength}else{let l=await va(e.arrayBuffer(),r);if(n>0&&l.byteLength>n)throw new Dn(n);o=new Uint8Array(l)}let a={status:e.status,statusText:e.statusText,headers:i,body:o,url:t};return s&&s.length>0&&(a.redirectChain=s),a}function _r(e,t){if(e.length>t||V(e)>t)throw new C(`script input size limit exceeded (${t} bytes)`,"string_length")}var Hf="/usr/bin:/bin",Zf=[["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"]],Tr=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;invokeToolFn;transformPlugins=[];state;constructor(t={}){this.limits=qr({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}},t.executionLimitProfile);let n=t.fs??new yt(t.files,{maxTotalBytes:this.limits.maxFileSystemBytes});this.fs=n,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),s=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH",Hf],["IFS",`
|
|
801
|
+
`],...Zf,["PWD",r],["OLDPWD",r],["OPTIND","1"],...Object.entries(t.env??{})]);if(t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=ka(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.coverageWriter=t.coverage,this.state={env:s,arrays:new Map,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastSubstitutionExitCode:null,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,virtualPid:t.processInfo?.pid??1,virtualPpid:t.processInfo?.ppid??0,virtualUid:t.processInfo?.uid??1e3,virtualGid:t.processInfo?.gid??1e3,bashPid:t.processInfo?.pid??1,nextVirtualPid:(t.processInfo?.pid??1)+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",Qr(this.state.options)),this.state.env.set("BASHOPTS",Kr(this.state.shoptOptions)),Ka(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&(n instanceof yt||n instanceof Kt))try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of Ta(t.commands))this.registerBundledCommand(o);if(t.fetch||t.network)for(let o of La())this.registerBundledCommand(o);if(t.python)for(let o of Fa())this.registerBundledCommand(o);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let o of Ma())this.registerBundledCommand(o);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap),i.invokeTool&&(this.invokeToolFn=i.invokeTool)}if(t.customCommands)for(let o of t.customCommands)if(Ua(o)){let a=ja(o);this.registerCommandInternal(a,!0)}else this.registerCommandInternal(o,!0)}registerCommand(t){this.registerCommandInternal(t,!0)}registerBundledCommand(t){this.registerCommandInternal(t,!1)}registerCommandInternal(t,n,r=n?t.trusted??!0:t.trusted){let s=this.commands.get(t.name),i=n?s?.internalOriginalCommand??(s&&!s.internalIsExtension?s:void 0):void 0,o={name:t.name,trusted:r,internalIsExtension:n,internalOriginalCommand:i,execute:(l,c)=>t.execute(l,c)};this.commands.set(t.name,o);let a=this.fs;if(typeof a.writeFileSync=="function"){let l=`#!/bin/bash
|
|
801
802
|
# Built-in command: ${t.name}
|
|
802
|
-
`;try{a.writeFileSync(`/bin/${t.name}`,l)}catch{}try{a.writeFileSync(`/usr/bin/${t.name}`,l)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=
|
|
803
|
-
`,exitCode:126}}return t.trim()?this.logResult(i):i}async execInScope(t,n,r,s,i,o=!1,a=!0){let
|
|
804
|
-
|
|
805
|
-
`,exitCode:
|
|
806
|
-
`,exitCode:2,env:Ye(this.state.env,
|
|
807
|
-
`,exitCode:
|
|
808
|
-
|
|
809
|
-
`)}var ay=new TextDecoder("utf-8",{fatal:!0});function jf(e){if(!e)return e;let t=!1;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);if(s>255)return e;s>127&&(t=!0)}if(!t)return e;let n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);try{return ay.decode(n)}catch{return e}}function ly(e,t,n,r,s,i){if(e===void 0)return;let o=t==="bytes"?e.length:M(e);if(o>n||o>r)throw new $(`stdin size limit exceeded (${Math.min(n,r)} bytes)`,"string_length");return i||s.consumeInput(o,"stdin"),t==="bytes"?e:Ut(e)}import*as me from"node:fs";import*as _e from"node:path";import*as dt from"node:fs";import*as $e from"node:path";function Ie(e,t){let n=/^[A-Za-z]:[\\/]/.test(t)?$e.win32:$e.posix,r=n.relative(t,e);return r===""||r!==".."&&!r.startsWith(`..${n.sep}`)&&!n.isAbsolute(r)}function Dn(e,t){try{let n=dt.realpathSync(e);return Ie(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=$e.dirname(e);if(r===e)return null;let s=Dn(r,t);if(s===null)return null;try{if(dt.lstatSync(e).isSymbolicLink()){let o=dt.readlinkSync(e),a=$e.isAbsolute(o)?o:$e.resolve($e.dirname(e),o),l=Dn(a,t);return l===null?null:l}}catch{}return $e.join(s,$e.basename(e))}return null}}function Xs(e,t,n){let r=Dn(e,n);if(r===null)return null;let s=$e.resolve(e),i=s.slice(t.length),o=r.slice(n.length);if(i!==o)return null;try{if(dt.lstatSync(s).isSymbolicLink())return null}catch{}return r}function Ys(e,t){if(!dt.existsSync(e))throw new Error(`${t} root does not exist`);if(!dt.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function qf(e,t){if(!$e.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=dt.realpathSync(e)}catch{n=$e.resolve(e)}return Ie(n,t)?{withinRoot:!0,relativePath:n.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:$e.basename(e)}}function Js(e,t,n,r){let s=e;if(s.path===void 0){for(let o of r)if(s.message?.includes(o))throw e}let i=s.code||"EIO";throw new Error(`${i}: ${n} '${t}'`)}var cy=["ELOOP","EFBIG","EPERM"],uy="/home/user/project",er=class{root;canonicalRoot;mountPoint;readOnly;maxFileReadSize;maxMemoryBytes;allowSymlinks;memory=new Map;deleted=new Set;nextMemoryIdentity=1;retainedMemoryBytes=0;memoryEntryBytes(t){if(!t||t.type!=="file")return 0;let n=t.content.byteLength;for(let r of t.appendChunks??[])n+=r.byteLength;return n}assertMemoryCapacity(t,n=0){if(!Number.isSafeInteger(t)||t<0||t>this.maxMemoryBytes-this.retainedMemoryBytes+n)throw new Error(`ENOSPC: overlay memory byte limit exceeded (${this.maxMemoryBytes} bytes)`)}setMemoryEntry(t,n){let r=this.memoryEntryBytes(this.memory.get(t)),s=this.memoryEntryBytes(n);this.assertMemoryCapacity(s,r),this.memory.set(t,n),this.retainedMemoryBytes+=s-r}deleteMemoryEntry(t){let n=this.memory.get(t);n&&(this.retainedMemoryBytes-=this.memoryEntryBytes(n),this.memory.delete(t))}identityFor(t){return t.type==="symlink"?"":(t.identity||(t.identity=`overlay:${this.nextMemoryIdentity++}`),t.identity)}constructor(t){this.root=_e.resolve(t.root);let n=t.mountPoint??uy;if(this.mountPoint=n==="/"?"/":n.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${n}`);if(this.readOnly=t.readOnly??!1,this.maxFileReadSize=t.maxFileReadSize??10485760,this.maxMemoryBytes=t.maxMemoryBytes??1024*1024*1024,!Number.isSafeInteger(this.maxMemoryBytes)||this.maxMemoryBytes<0)throw new Error("OverlayFs: invalid maxMemoryBytes");this.allowSymlinks=t.allowSymlinks??!1,Ys(this.root,"OverlayFs"),this.canonicalRoot=me.realpathSync(this.root),this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){let t=this.mountPoint.split("/").filter(Boolean),n="";for(let r of t)n+=`/${r}`,this.memory.has(n)||this.setMemoryEntry(n,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.setMemoryEntry("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}mkdirSync(t,n){let s=W(t).split("/").filter(Boolean),i="";for(let o of s)i+=`/${o}`,this.memory.has(i)||this.setMemoryEntry(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,n){let r=W(t),s=this.getDirname(r);s!=="/"&&this.mkdirSync(s);let i=n instanceof Uint8Array?n:new TextEncoder().encode(n);this.setMemoryEntry(r,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let n=t.lastIndexOf("/");return n===0?"/":t.slice(0,n)}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let n=W(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=_e.join(this.root,r),i=_e.resolve(s);return Ie(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?Dn(t,this.canonicalRoot):Xs(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=_e.dirname(t),r=this.resolveRealPath_(n);return r===null?null:_e.join(r,_e.basename(t))}sanitizeError(t,n,r){Js(t,n,r,cy)}ensureParentDirs(t){let n=yt(t);n!=="/"&&(this.memory.has(n)||(this.ensureParentDirs(n),this.setMemoryEntry(n,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(n))}async existsInOverlay(t){let n=W(t);if(this.deleted.has(n))return!1;if(this.memory.has(n))return!0;let r=this.resolveRealPathParent_(this.toRealPath(n));if(!r)return!1;try{return await me.promises.lstat(r),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=ot(n);return Mt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Mt(n,"binary")}async readFileBuffer(t,n=new Set){z(t,"open");let r=W(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let c=this.resolveSymlink(r,s.target);return this.readFileBuffer(c,n)}if(s.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(!s.appendChunks||s.appendChunks.length===0)return s.content;let o=s.appendChunks.reduce((c,u)=>c+u.byteLength,s.content.byteLength);if(!Number.isSafeInteger(o))throw new Error(`EFBIG: file too large, read '${t}'`);let a=new Uint8Array(o);a.set(s.content);let l=s.content.byteLength;for(let c of s.appendChunks)a.set(c,l),l+=c.byteLength;return s.content=a,s.appendChunks=void 0,a}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let o=await me.promises.lstat(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${t}'`);let c=await me.promises.readlink(i),u=this.realTargetToVirtual(r,c),f=this.resolveSymlink(r,u);return this.readFileBuffer(f,n)}if(o.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(this.maxFileReadSize>0&&o.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${o.size} bytes, max ${this.maxFileReadSize})`);let a=this.allowSymlinks?me.constants.O_RDONLY:me.constants.O_RDONLY|me.constants.O_NOFOLLOW,l=await me.promises.open(i,a);try{let c=await l.readFile();return new Uint8Array(c)}finally{await l.close()}}catch(o){let a=o.code;if(a==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(a==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(o,t,"open")}}async writeFile(t,n,r){z(t,"write"),this.assertWritable(`write '${t}'`);let s=W(t);this.ensureParentDirs(s);let i=ot(r),o=Ft(n,i);this.setMemoryEntry(s,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(s)}async appendFile(t,n,r){z(t,"append"),this.assertWritable(`append '${t}'`);let s=W(t),i=ot(r),o=Ft(n,i),a=this.memory.get(s);if(a?.type==="file"){this.assertMemoryCapacity(o.byteLength),a.appendChunks||(a.appendChunks=[]),a.appendChunks.push(o),this.retainedMemoryBytes+=o.byteLength,a.mtime=new Date,this.deleted.delete(s);return}let l;try{l=await this.readFileBuffer(s)}catch{l=new Uint8Array(0)}this.ensureParentDirs(s),this.setMemoryEntry(s,{type:"file",content:l,appendChunks:[o],mode:420,mtime:new Date}),this.deleted.delete(s)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,n=new Set){z(t,"stat");let r=W(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let a=this.resolveSymlink(r,s.target);return this.stat(a,n)}let o=0;return s.type==="file"&&(o=s.content.length+(s.appendChunks?.reduce((a,l)=>a+l.byteLength,0)??0)),{isFile:s.type==="file",isDirectory:s.type==="directory",isSymbolicLink:!1,mode:s.mode,size:o,mtime:s.mtime,identity:this.identityFor(s)}}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let o=await me.promises.lstat(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let a=await me.promises.readlink(i),l=this.realTargetToVirtual(r,a),c=this.resolveSymlink(r,l);return this.stat(c,n)}return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:!1,mode:o.mode,size:o.size,mtime:o.mtime,dev:o.dev,ino:o.ino}}catch(o){if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(o,t,"stat")}}async lstat(t){z(t,"lstat");let n=W(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let i=0;return r.type==="file"&&(i=r.content.length+(r.appendChunks?.reduce((o,a)=>o+a.byteLength,0)??0)),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:i,mtime:r.mtime,identity:this.identityFor(r)}}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await me.promises.lstat(s);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime,dev:i.dev,ino:i.ino}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}resolveSymlink(t,n){return Ln(t,n)}realTargetToVirtual(t,n){let r=qf(n,this.canonicalRoot);if(r.withinRoot){if(!_e.isAbsolute(n))return n;let s=r.relativePath;return this.mountPoint==="/"?s:`${this.mountPoint}${s}`}return r.safeName}async mkdir(t,n){z(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=W(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=yt(r);if(i!=="/"&&!await this.existsInOverlay(i))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.setMemoryEntry(r,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(r)}async readdirCore(t,n){if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Map,s=new Set,i=n==="/"?"/":`${n}/`;for(let a of this.deleted)if(a.startsWith(i)){let l=a.slice(i.length),c=l.split("/")[0];c&&!l.includes("/",c.length)&&s.add(c)}for(let[a,l]of this.memory)if(a!==n&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!s.has(u)&&!c.includes("/",1)&&r.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let o=this.resolveRealPath_(this.toRealPath(n));if(o)try{if(!this.allowSymlinks&&(await me.promises.lstat(o)).isSymbolicLink()){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);return r}let a=await me.promises.readdir(o,{withFileTypes:!0});for(let l of a)!s.has(l.name)&&!r.has(l.name)&&r.set(l.name,{name:l.name,isFile:l.isFile(),isDirectory:l.isDirectory(),isSymbolicLink:l.isSymbolicLink()})}catch(a){if(a.code==="ENOENT"){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else a.code!=="ENOTDIR"&&this.sanitizeError(a,t,"scandir")}return r}async resolveForReaddir(t,n=!1){let r=W(t),s=new Set,i=n,o=this.memory.get(r);for(;o&&o.type==="symlink";){if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(r),i=!0,r=this.resolveSymlink(r,o.target),o=this.memory.get(r)}if(o)return{normalized:r,outsideOverlay:!1};if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let l=this.resolveRealPath_(this.toRealPath(r));if(!l)return{normalized:r,outsideOverlay:!0};try{if((await me.promises.lstat(l)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let u=await me.promises.readlink(l),f=this.realTargetToVirtual(r,u),d=this.resolveSymlink(r,f);return this.resolveForReaddir(d,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async createExclusive(t,n){let r=n.directory?"mkdir":"open";z(t,r),this.assertWritable(`${r} '${t}'`);let s=W(t);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);let i=yt(s),o=s;if(i!=="/"){let a;try{a=await this.realpath(i)}catch{throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`)}let l=await this.stat(a).catch(()=>null);if(!l)throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);if(!l.isDirectory)throw new Error(`ENOTDIR: not a directory, ${r} '${t}'`);if(o=it(a,s.slice(s.lastIndexOf("/")+1)),o!==s&&await this.existsInOverlay(o))throw new Error(`EEXIST: file already exists, ${r} '${t}'`)}if(this.memory.has(o))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);this.setMemoryEntry(o,n.directory?{type:"directory",mode:n.mode,mtime:new Date}:{type:"file",content:new Uint8Array(0),mode:n.mode,mtime:new Date}),this.deleted.delete(o)}async readdir(t){z(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.keys()).sort((i,o)=>i<o?-1:i>o?1:0)}async readdirWithFileTypes(t){z(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.values()).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async rm(t,n){z(t,"rm"),this.assertWritable(`rm '${t}'`);let r=W(t);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(r)).isDirectory){let o=await this.readdir(r);if(o.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of o){let l=r==="/"?`/${a}`:`${r}/${a}`;await this.rm(l,n)}}}}catch(i){if(i instanceof Error&&(i.message.includes("ENOTEMPTY")||i.message.includes("EISDIR")))throw i}this.deleteMemoryEntry(r),this.existsOnRealFs(r)&&this.deleted.add(r)}existsOnRealFs(t){let n=this.toRealPath(t),r=this.resolveRealPathParent_(n);if(!r)return!1;try{return me.lstatSync(r),!0}catch{return!1}}async cp(t,n,r){z(t,"cp"),z(n,"cp"),this.assertWritable(`cp '${n}'`);let s=W(t),i=W(n);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let a=await this.stat(s);if(a.isFile){let l=await this.readFileBuffer(s);await this.writeFile(i,l)}else if(a.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(Lt(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(s);for(let c of l){let u=s==="/"?`/${c}`:`${s}/${c}`,f=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(u,f,r)}}}async mv(t,n){this.assertWritable(`mv '${n}'`),await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return Ht(t,n)}getAllPaths(){let t=new Set(this.memory.keys());for(let n of this.deleted)t.delete(n);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,n){if(this.deleted.has(t))return;let r=this.resolveRealPath_(this.toRealPath(t));if(r)try{let s=me.readdirSync(r);for(let i of s){let o=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(o))continue;n.add(o);let a=_e.join(r,i);me.lstatSync(a).isDirectory()&&this.scanRealFs(o,n)}}catch{}}async chmod(t,n){z(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=W(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(r);if(i){i.mode=n;return}let o=await this.stat(r);if(o.isFile){let a=await this.readFileBuffer(r);this.setMemoryEntry(r,{type:"file",content:a,mode:n,mtime:new Date})}else o.isDirectory&&this.setMemoryEntry(r,{type:"directory",mode:n,mtime:new Date})}async symlink(t,n){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${n}'`);z(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=W(n);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.setMemoryEntry(r,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(t,n){z(t,"link"),z(n,"link"),this.assertWritable(`link '${n}'`);let r=W(t),s=W(n);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let o=await this.stat(r);if(!o.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let l=await this.readFileBuffer(r);this.ensureParentDirs(s),this.setMemoryEntry(s,{type:"file",content:l,mode:o.mode,mtime:new Date,identity:o.identity??`overlay:${this.nextMemoryIdentity++}`}),this.deleted.delete(s)}async readlink(t){z(t,"readlink");let n=W(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let r=this.memory.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await me.promises.readlink(s);if(!_e.isAbsolute(i)){let o=_e.resolve(_e.dirname(s),i),a;try{a=me.realpathSync(o)}catch{a=o}if(!Ie(a,this.canonicalRoot))return _e.basename(i)}return this.realTargetToVirtual(n,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){z(t,"realpath");let n=W(t),r=new Set,s=async a=>{let l=a==="/"?[]:a.slice(1).split("/"),c="";for(let u of l){if(c=`${c}/${u}`,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(c),d=0,h=40;for(;f&&f.type==="symlink"&&d<h;){if(r.add(c),c=this.resolveSymlink(c,f.target),d++,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(c)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let p=this.toRealPath(c),m=this.resolveRealPath_(p);if(m)try{if((await me.promises.lstat(m)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let S=await me.promises.readlink(m),y=this.realTargetToVirtual(c,S);return r.add(c),c=this.resolveSymlink(c,y),s(c)}}catch(E){if(E.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(E,t,"realpath")}else if(!this.allowSymlinks){let E=this.resolveRealPathParent_(p);if(E)try{if((await me.promises.lstat(E)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch(S){if(S.message?.includes("ENOENT")||S.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(S,t,"realpath")}}}}return c||"/"},i=await s(n);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,n,r){z(t,"utimes"),this.assertWritable(`utimes '${t}'`);let s=W(t);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let o=this.memory.get(s);if(o){o.mtime=r;return}let a=await this.stat(s);if(a.isFile){let l=await this.readFileBuffer(s);this.setMemoryEntry(s,{type:"file",content:l,mode:a.mode,mtime:r})}else a.isDirectory&&this.setMemoryEntry(s,{type:"directory",mode:a.mode,mtime:r})}};import{randomBytes as fy}from"node:crypto";import*as O from"node:fs";import*as H from"node:path";var dy=["EACCES","escaping sandbox","EFBIG","ENOTSUP"],ei=class e{static activeMutationRoots=new Set;static pendingMutations=[];root;canonicalRoot;maxFileReadSize;maxCopyOnWriteSize;maxCopySize;allowSymlinks;constructor(t){this.root=H.resolve(t.root),this.maxFileReadSize=t.maxFileReadSize??10485760,this.maxCopyOnWriteSize=t.maxCopyOnWriteSize??104857600,this.maxCopySize=t.maxCopySize??0,this.allowSymlinks=t.allowSymlinks??!1,Ys(this.root,"ReadWriteFs"),this.canonicalRoot=O.realpathSync(this.root)}resolveAndValidate(t,n){let r=this.allowSymlinks?Dn(t,this.canonicalRoot):Xs(t,this.root,this.canonicalRoot);if(r===null)throw new Error(`EACCES: permission denied, '${n}' resolves outside sandbox`);return r}validateParent(t,n){let r=H.dirname(t),s=this.resolveAndValidate(r,n);return H.join(s,H.basename(t))}toRealPath(t){let n=W(t),r=H.join(this.root,n);return H.resolve(r)}async readFile(t,n){let r=await this.readFileBuffer(t),s=ot(n);return Mt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Mt(n,"binary")}async readFileBuffer(t){z(t,"open");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{let s=this.allowSymlinks?O.constants.O_RDONLY:O.constants.O_RDONLY|O.constants.O_NOFOLLOW,i=await O.promises.open(r,s);try{if(this.maxFileReadSize>0){let a=await i.stat();if(a.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${a.size} bytes, max ${this.maxFileReadSize})`)}let o=await i.readFile();return new Uint8Array(o)}finally{await i.close()}}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(i.code==="EISDIR")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(i.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(s,t,"open")}}async writeFile(t,n,r){await this.withFilesystemMutation(()=>this.writeFileUnlocked(t,n,r))}async writeFileUnlocked(t,n,r){z(t,"write");let s=this.toRealPath(t),i=this.resolveAndValidate(s,t),o=ot(r),a=Ft(n,o),l=H.dirname(i);try{await O.promises.mkdir(l,{recursive:!0}),i=this.resolveAndValidate(s,t);let c=this.allowSymlinks?0:O.constants.O_NOFOLLOW,u=null;try{let f=await O.promises.lstat(i);if(!f.isFile()&&!f.isDirectory())throw new Error(`EACCES: cannot write special file '${t}'`);let d=await O.promises.open(i,O.constants.O_WRONLY|O.constants.O_NONBLOCK|c);try{if(u=await d.stat(),!u.isFile())throw new Error(`EACCES: cannot write special file '${t}'`);if(u.nlink<=1){await d.truncate(0),await d.writeFile(a);return}}finally{await d.close()}}catch(f){if(f.code!=="ENOENT")throw f}await this.replaceFile(i,a,u)}catch(c){if(c.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(c,t,"write")}}async appendFile(t,n,r){await this.withFilesystemMutation(()=>this.appendFileUnlocked(t,n,r))}async appendFileUnlocked(t,n,r){z(t,"append");let s=this.toRealPath(t),i=ot(r),o=Ft(n,i),a=this.resolveAndValidate(s,t),l=H.dirname(a);try{await O.promises.mkdir(l,{recursive:!0}),a=this.resolveAndValidate(s,t);let c=this.allowSymlinks?0:O.constants.O_NOFOLLOW,u=null;try{let d=await O.promises.lstat(a);if(!d.isFile()&&!d.isDirectory())throw new Error(`EACCES: cannot append special file '${t}'`);let h=await O.promises.open(a,O.constants.O_WRONLY|O.constants.O_APPEND|O.constants.O_NONBLOCK|c);try{if(u=await h.stat(),!u.isFile())throw new Error(`EACCES: cannot append special file '${t}'`);if(u.nlink<=1){await h.writeFile(o);return}}finally{await h.close()}}catch(d){if(d.code!=="ENOENT")throw d}if(!u){await this.replaceFile(a,o,null);return}this.assertCopyOnWriteSize(u.size,"append",t);let f=await this.openCopySource(a);try{let d=await f.stat();if(!d.isFile()||d.dev!==u.dev||d.ino!==u.ino)throw new Error(`EACCES: file identity changed, append '${t}'`);await this.replaceFile(a,o,d,{handle:f,size:u.size})}finally{await f.close()}}catch(c){if(c.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(c,t,"append")}}async withFilesystemMutation(t){return new Promise((n,r)=>{e.pendingMutations.push({root:this.canonicalRoot,start:()=>{e.activeMutationRoots.add(this.canonicalRoot),t().then(n,r).finally(()=>{e.activeMutationRoots.delete(this.canonicalRoot),e.drainMutationQueue()})}}),e.drainMutationQueue()})}static drainMutationQueue(){for(let t=0;t<e.pendingMutations.length;){let n=e.pendingMutations[t];if([...e.activeMutationRoots].some(s=>Ie(n.root,s)||Ie(s,n.root))){t++;continue}e.pendingMutations.splice(t,1),n.start()}}assertCopyOnWriteSize(t,n,r){if(this.maxCopyOnWriteSize>0&&t>this.maxCopyOnWriteSize)throw new Error(`EFBIG: file too large for copy-on-write ${n} '${r}' (${t} bytes, max ${this.maxCopyOnWriteSize})`)}assertCopySize(t,n){if(this.maxCopySize>0&&t.size>this.maxCopySize)throw new Error(`EFBIG: file too large to copy '${n}' (${t.size} bytes, max ${this.maxCopySize})`)}randomTransactionToken(){return fy(16).toString("hex")}async openCopySource(t){let n=this.allowSymlinks?0:O.constants.O_NOFOLLOW,r=O.constants.O_RDONLY|O.constants.O_NONBLOCK|n,s=O.constants.O_NOATIME;if(process.platform!=="linux"||s===void 0)return O.promises.open(t,r);try{return await O.promises.open(t,r|s)}catch(i){if(i.code!=="EPERM")throw i;return O.promises.open(t,r)}}async replaceFile(t,n,r,s,i,o=!1){let a=H.dirname(t),l="",c=null,u=r===null?438:384;for(let p=0;p<16;p++){l=H.join(a,`.just-bash-write-${this.randomTransactionToken()}`);try{c=await O.promises.open(l,O.constants.O_WRONLY|O.constants.O_CREAT|O.constants.O_EXCL,u);break}catch(m){if(m.code!=="EEXIST")throw m}}if(!c)throw new Error(`EEXIST: replacement write '${t}'`);let f=c,d=await f.stat(),h=!1;try{try{let m=0,E=async S=>{let y=0;for(;y<S.byteLength;){let{bytesWritten:g}=await f.write(S,y,S.byteLength-y,m+y);if(g===0)throw new Error("EIO: replacement write made no progress");y+=g}m+=y};if(s){let S=Buffer.allocUnsafe(65536),y=0,g=s.size;for(;g>0;){let b=Math.min(S.length,g),{bytesRead:v}=await s.handle.read(S,0,b,y);if(v===0)break;await E(S.subarray(0,v)),y+=v,g-=v}}if(await E(n),r!==null&&await f.chmod(r.mode&(o?4095:511)),i)await f.utimes(i.atime,i.mtime);else if(r!==null){let S=await f.stat();await f.utimes(r.atime,S.mtime)}}finally{await f.close(),c=null}let p=await O.promises.lstat(l);if(!p.isFile()||p.dev!==d.dev||p.ino!==d.ino)throw new Error("EACCES: replacement staging entry changed");await O.promises.rename(l,t),h=!0}finally{c&&await c.close().catch(()=>{}),h||await O.promises.rm(l,{force:!0}).catch(()=>{})}}async exists(t){if(t.includes("\0"))return!1;let n=this.toRealPath(t);try{let r=this.resolveAndValidate(n,t);return await O.promises.access(r),!0}catch{return!1}}async stat(t){z(t,"stat");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{let s=await O.promises.lstat(r);if(!this.allowSymlinks&&s.isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);return{isFile:s.isFile(),isDirectory:s.isDirectory(),isSymbolicLink:s.isSymbolicLink(),mode:s.mode,size:s.size,mtime:s.mtime,dev:s.dev,ino:s.ino,identity:`real:${s.dev}:${s.ino}`}}catch(s){if(s.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(s,t,"stat")}}async lstat(t){z(t,"lstat");let n=this.toRealPath(t),r=n===this.root?this.resolveAndValidate(n,t):this.validateParent(n,t);try{let s=await O.promises.lstat(r);return{isFile:s.isFile(),isDirectory:s.isDirectory(),isSymbolicLink:s.isSymbolicLink(),mode:s.mode,size:s.size,mtime:s.mtime,dev:s.dev,ino:s.ino,identity:`real:${s.dev}:${s.ino}`}}catch(s){if(s.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(s,t,"lstat")}}async mkdir(t,n){await this.withFilesystemMutation(()=>this.mkdirUnlocked(t,n))}async createExclusive(t,n){await this.withFilesystemMutation(()=>this.createExclusiveUnlocked(t,n))}async assertCreatedInsideRoot(t,n,r,s,i){let o=!1;try{let a=this.resolveAndValidate(n,r),l=await O.promises.lstat(a);o=a===t&&l.dev===i.dev&&l.ino===i.ino}catch{o=!1}if(!o)throw new Error(`EACCES: permission denied, '${r}' resolves outside sandbox during ${s}`)}async createExclusiveUnlocked(t,n){let r=n.directory?"mkdir":"open";z(t,r);let s=this.toRealPath(t),i=s===this.root?this.resolveAndValidate(s,t):this.validateParent(s,t);try{if(n.directory){await O.promises.mkdir(i,{mode:n.mode});let l=await O.promises.open(i,O.constants.O_RDONLY|(O.constants.O_DIRECTORY??0)|(this.allowSymlinks?0:O.constants.O_NOFOLLOW));try{await this.assertCreatedInsideRoot(i,s,t,r,await l.stat())}finally{await l.close()}return}let o=this.allowSymlinks?0:O.constants.O_NOFOLLOW,a=await O.promises.open(i,O.constants.O_WRONLY|O.constants.O_CREAT|O.constants.O_EXCL|o,n.mode);try{await this.assertCreatedInsideRoot(i,s,t,r,await a.stat())}finally{await a.close()}}catch(o){let a=o;if(a.code==="EEXIST")throw new Error(`EEXIST: file already exists, ${r} '${t}'`);if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);this.sanitizeError(o,t,r)}}async mkdirUnlocked(t,n){z(t,"mkdir");let r=this.toRealPath(t),s=r===this.root?this.resolveAndValidate(r,t):this.validateParent(r,t);try{await O.promises.mkdir(s,{recursive:n?.recursive})}catch(i){let o=i;if(o.code==="EEXIST")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.sanitizeError(i,t,"mkdir")}}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){z(t,"scandir");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{if(!this.allowSymlinks&&(await O.promises.lstat(r)).isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);return(await O.promises.readdir(r,{withFileTypes:!0})).map(i=>({name:i.name,isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink()})).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(i.code==="ENOTDIR")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);this.sanitizeError(s,t,"scandir")}}async rm(t,n){await this.withFilesystemMutation(()=>this.rmUnlocked(t,n))}async rmUnlocked(t,n){z(t,"rm");let r=this.toRealPath(t),s=this.validateParent(r,t);try{let i=await O.promises.lstat(s);if(!this.allowSymlinks&&i.isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);await O.promises.rm(s,{recursive:n?.recursive??!1,force:n?.force??!1})}catch(i){let o=i;if(o.code==="ENOENT"){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(o.code==="ENOTEMPTY")throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);this.sanitizeError(i,t,"rm")}}async cp(t,n,r){await this.withFilesystemMutation(()=>this.cpUnlocked(t,n,r))}async cpUnlocked(t,n,r){z(t,"cp"),z(n,"cp");let s=this.toRealPath(t),i=this.toRealPath(n),o=this.validateParent(s,t),a=this.resolveAndValidate(i,n),l;try{l=await O.promises.lstat(o)}catch(c){if(c.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, cp '${t}'`);this.sanitizeError(c,t,"cp")}if(l.isDirectory()&&Ie(a,o))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);if(!l.isDirectory())try{let c=this.validateParent(i,n),u=await O.promises.lstat(c);if(l.dev===u.dev&&l.ino===u.ino)throw new Error(`EINVAL: cannot copy '${t}' onto itself, '${n}'`)}catch(c){if(c.code!=="ENOENT")throw c}if(l.isFile())try{let c=await O.promises.stat(a);if(l.dev===c.dev&&l.ino===c.ino)throw new Error(`EINVAL: cannot copy '${t}' onto itself, '${n}'`)}catch(c){if(c.code!=="ENOENT")throw c}try{await this.preflightCopyTree(o,t)}catch(c){this.sanitizeError(c,t,"cp")}if(l.isFile()||l.isSymbolicLink())try{await O.promises.mkdir(H.dirname(a),{recursive:!0}),this.resolveAndValidate(i,n)}catch(c){this.sanitizeError(c,n,"cp")}try{await this.copyTreeEntry(o,i,t,n,r?.recursive??!1)}catch(c){let u=c;if(u.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(u.code==="EISDIR")throw new Error(`EISDIR: is a directory, cp '${t}'`);this.sanitizeError(c,t,"cp")}}async copyTreeEntry(t,n,r,s,i){let o=await O.promises.lstat(t);if(o.isFile()){this.assertCopySize(o,r);let a=this.resolveAndValidate(n,s),l=await this.assertCopyDestinationWritable(a,s),c=await this.openCopySource(t);try{let u=await c.stat();if(!u.isFile()||u.dev!==o.dev||u.ino!==o.ino)throw new Error(`EACCES: file identity changed, cp '${r}'`);await this.replaceFile(a,new Uint8Array(0),l??o,{handle:c,size:o.size})}finally{await c.close()}return}if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`EACCES: permission denied, cp '${r}' contains a symlink`);let a=await O.promises.readlink(t),l=H.isAbsolute(a)?await this.toVirtualAbsoluteSymlinkTarget(a,r):a;await this.replaceSymlink(n,s,l);return}if(o.isDirectory()){if(!i)throw new Error(`EISDIR: is a directory, cp '${r}'`);let a=this.resolveAndValidate(n,s);await O.promises.mkdir(a,{recursive:!0}),a=this.resolveAndValidate(n,s);for(let l of await O.promises.readdir(t))await this.copyTreeEntry(H.join(t,l),H.join(n,l),H.join(r,l),H.join(s,l),!0);await O.promises.chmod(a,o.mode&4095);return}throw new Error(`EINVAL: unsupported file type, cp '${r}'`)}async assertCopyDestinationWritable(t,n){let r;try{r=await O.promises.lstat(t)}catch(o){if(o.code==="ENOENT")return null;throw o}if(!r.isFile()){if(r.isDirectory())return r;throw new Error(`EACCES: cannot copy over special file '${n}'`)}let s=this.allowSymlinks?0:O.constants.O_NOFOLLOW,i=await O.promises.open(t,O.constants.O_WRONLY|O.constants.O_NONBLOCK|s);try{let o=await i.stat();if(!o.isFile()||o.dev!==r.dev||o.ino!==r.ino)throw new Error(`EACCES: destination changed, cp '${n}'`)}finally{await i.close()}return r}async replaceSymlink(t,n,r){let s=this.validateParent(t,n),i=H.dirname(W(n)),o="",a="",l="",c=null;for(let f=0;f<16;f++){let d=`.just-bash-copy-link-${this.randomTransactionToken()}`;o=i==="/"?`/${d}`:`${i}/${d}`,a=this.toRealPath(o);try{await this.symlinkUnlocked(r,o),l=this.validateParent(a,o),c=await O.promises.lstat(l);break}catch(h){let p=h;if(p.code!=="EEXIST"&&!p.message.startsWith("EEXIST:"))throw h}}if(!c)throw new Error(`EEXIST: replacement symlink '${n}'`);let u=!1;try{let f=await O.promises.lstat(l);if(!f.isSymbolicLink()||f.dev!==c.dev||f.ino!==c.ino)throw new Error("EACCES: replacement symlink entry changed");await O.promises.rename(l,s),u=!0}finally{!u&&l&&await O.promises.rm(l,{force:!0}).catch(()=>{})}}async toVirtualAbsoluteSymlinkTarget(t,n){let r=H.resolve(t),s=await O.promises.realpath(r),i=await O.promises.realpath(H.dirname(r)),o=H.join(i,H.basename(r));if(!Ie(s,this.canonicalRoot)||!Ie(o,this.canonicalRoot))throw new Error(`EACCES: permission denied, cp '${n}' contains an unsafe symlink`);return o.slice(this.canonicalRoot.length)||"/"}async preflightCopyTree(t,n,r=new Set){let s=await O.promises.lstat(t),i=`${s.dev}:${s.ino}`;if(r.has(i))throw new Error(`ELOOP: cp '${n}' contains a cycle`);if(s.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`EACCES: permission denied, cp '${n}' contains a symlink`);let o=await O.promises.realpath(t);if(!Ie(o,this.canonicalRoot))throw new Error(`EACCES: permission denied, cp '${n}' contains an unsafe symlink`);return}if(s.isDirectory()){r.add(i);try{let o=await O.promises.readdir(t);for(let a of o)await this.preflightCopyTree(H.join(t,a),H.join(n,a),r)}finally{r.delete(i)}}}async mv(t,n){await this.withFilesystemMutation(()=>this.mvUnlocked(t,n))}async mvUnlocked(t,n){z(t,"mv"),z(n,"mv");let r=this.toRealPath(t),s=this.toRealPath(n),i=this.validateParent(r,t),o=this.validateParent(s,n),a;try{a=await O.promises.lstat(i)}catch(c){if(c.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);this.sanitizeError(c,t,"mv")}if(a.isDirectory()&&this.isSameOrDescendantIdentity(i,o))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);try{if(a.isSymbolicLink()){let c=await O.promises.readlink(i),u=H.resolve(H.dirname(o),c),f=await O.promises.realpath(u).catch(()=>u);if(!Ie(f,this.canonicalRoot))throw new Error(`EACCES: permission denied, mv '${t}' -> '${n}' would create symlink escaping sandbox`)}}catch(c){let u=c;if(u.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(u.message?.includes("EACCES")||u.message?.includes("escaping sandbox"))throw c}let l=H.dirname(o);try{await O.promises.mkdir(l,{recursive:!0})}catch(c){this.sanitizeError(c,n,"mv")}try{await O.promises.rename(i,o)}catch(c){let u=c;if(u.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(u.code==="EXDEV"){await this.moveAcrossDevices(t,n);return}this.sanitizeError(c,t,"mv")}try{if(O.lstatSync(o).isDirectory()&&this.findEscapingSymlinks(o).length>0)throw await O.promises.rename(o,i),new Error(`EACCES: permission denied, mv '${t}' -> '${n}' would create symlinks escaping sandbox`)}catch(c){if(c.message?.includes("EACCES")||c.message?.includes("escaping sandbox"))throw c;await O.promises.rename(o,i).catch(()=>{}),this.sanitizeError(c,n,"mv")}}isSameOrDescendantIdentity(t,n){let r=t,s=n;try{r=O.realpathSync(t)}catch{}try{s=O.realpathSync(n)}catch{try{let i=O.realpathSync(H.dirname(n));s=H.join(i,H.basename(n))}catch{}}return Ie(s,r)}async uniqueTransactionPath(t,n){let r=H.posix.dirname(t);for(let s=0;s<16;s++){let i=H.posix.join(r,`.just-bash-mv-${n}-${this.randomTransactionToken()}`);if(!await this.exists(i))return i}throw new Error(`EEXIST: mv '${t}'`)}async moveAcrossDevices(t,n){let r=await this.uniqueTransactionPath(n,"stage"),s=await this.uniqueTransactionPath(n,"backup"),i=await this.uniqueTransactionPath(t,"source"),o=this.validateParent(this.toRealPath(r),r),a=this.validateParent(this.toRealPath(s),s),l=this.validateParent(this.toRealPath(t),t),c=this.validateParent(this.toRealPath(i),i),u=this.validateParent(this.toRealPath(n),n),f=!1,d=!1,h=!1,p=async()=>{h&&await O.promises.rename(c,l).catch(()=>{}),d&&await O.promises.rm(u,{recursive:!0,force:!0}).catch(()=>{}),f&&await O.promises.rename(a,u).catch(()=>{}),await O.promises.rm(o,{recursive:!0,force:!0}).catch(()=>{})};try{if(await this.cpUnlocked(t,r,{recursive:!0}),(await O.promises.lstat(o)).isDirectory()&&this.findEscapingSymlinks(o).length>0)throw new Error(`EACCES: permission denied, mv '${t}' -> '${n}' would create symlinks escaping sandbox`);try{await O.promises.rename(u,a),f=!0}catch(E){if(E.code!=="ENOENT")throw E}await O.promises.rename(o,u),d=!0,await O.promises.rename(l,c),h=!0,await O.promises.rm(c,{recursive:!0,force:!1}),h=!1,f&&await O.promises.rm(a,{recursive:!0,force:!0}).catch(()=>{})}catch(m){await p(),this.sanitizeError(m,t,"mv")}}resolvePath(t,n){return Ht(t,n)}getAllPaths(){let t=[];return this.scanDir("/",t),t}sanitizeError(t,n,r){Js(t,n,r,dy)}findEscapingSymlinks(t){let n=[],r=O.readdirSync(t);for(let s of r){let i=H.join(t,s),o=O.lstatSync(i);if(o.isSymbolicLink()){let a=O.readlinkSync(i),l=H.resolve(t,a),c;try{c=O.realpathSync(l)}catch(u){if(u.code!=="ENOENT")throw u;c=l}Ie(c,this.canonicalRoot)||n.push(i)}else o.isDirectory()&&n.push(...this.findEscapingSymlinks(i))}return n}scanDir(t,n){let r=this.toRealPath(t),s;try{s=this.resolveAndValidate(r,t)}catch{return}try{let i=O.readdirSync(s);for(let o of i){let a=t==="/"?`/${o}`:`${t}/${o}`;n.push(a);let l=H.join(s,o);O.lstatSync(l).isDirectory()&&this.scanDir(a,n)}}catch{}}async chmod(t,n){await this.withFilesystemMutation(()=>this.chmodUnlocked(t,n))}async chmodUnlocked(t,n){z(t,"chmod");let r=this.toRealPath(t),s=this.resolveAndValidate(r,t);try{let i=await O.promises.lstat(s);if(!i.isFile()){if(!i.isDirectory()&&i.nlink>1)throw new Error(`EACCES: cannot chmod multiply-linked special file '${t}'`);await O.promises.chmod(s,n);return}if(i.nlink<=1){await O.promises.chmod(s,n);return}this.assertCopyOnWriteSize(i.size,"chmod",t);let o=await this.openCopySource(s);try{let a=await o.stat();if(!a.isFile())throw new Error(`EACCES: file type changed, chmod '${t}'`);await this.replaceFile(s,new Uint8Array(0),{mode:n,atime:a.atime,mtime:a.mtime},{handle:o,size:a.size},{atime:a.atime,mtime:a.mtime},!0)}finally{await o.close()}}catch(i){let o=i;if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);if(o.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(i,t,"chmod")}}async symlink(t,n){await this.withFilesystemMutation(()=>this.symlinkUnlocked(t,n))}async symlinkUnlocked(t,n){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${n}'`);z(n,"symlink");let r=this.toRealPath(n),s=this.validateParent(r,n),i=W(n),o=W(H.dirname(i)),a=t.startsWith("/")?W(t):W(o==="/"?`/${t}`:`${o}/${t}`),l=H.join(this.canonicalRoot,a),c=H.dirname(s),u=t.startsWith("/")?l:H.relative(c,l)||".";try{await O.promises.symlink(u,s)}catch(f){if(f.code==="EEXIST")throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.sanitizeError(f,n,"symlink")}}async link(t,n){await this.withFilesystemMutation(()=>this.linkUnlocked(t,n))}async linkUnlocked(t,n){z(t,"link"),z(n,"link");let r=this.toRealPath(t),s=this.toRealPath(n),i=this.resolveAndValidate(r,t),o=s===this.root?this.resolveAndValidate(s,n):this.validateParent(s,n);try{await O.promises.link(i,o)}catch(a){let l=a;if(l.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(l.code==="EEXIST")throw new Error(`EEXIST: file already exists, link '${n}'`);if(l.code==="EPERM")throw new Error(`EPERM: operation not permitted, link '${t}'`);this.sanitizeError(a,t,"link")}}async readlink(t){z(t,"readlink");let n=this.toRealPath(t),r=n===this.root?this.resolveAndValidate(n,t):this.validateParent(n,t);try{let s=await O.promises.readlink(r),i=W(t),o=H.dirname(i),a=H.isAbsolute(s)?s:H.resolve(H.dirname(r),s),l=await O.promises.realpath(a).catch(()=>a);if(Ie(l,this.canonicalRoot)){let c=l.slice(this.canonicalRoot.length)||"/";return o==="/"?c.startsWith("/")?c.slice(1)||".":c:H.relative(o,c)}return H.basename(s)}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(s,t,"readlink")}}async realpath(t){z(t,"realpath");let n=this.toRealPath(t);try{this.resolveAndValidate(n,t)}catch{throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}let r;try{r=await O.promises.realpath(n)}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);if(i.code==="ELOOP")throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);this.sanitizeError(s,t,"realpath")}if(Ie(r,this.canonicalRoot))return r.slice(this.canonicalRoot.length)||"/";throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}async utimes(t,n,r){await this.withFilesystemMutation(()=>this.utimesUnlocked(t,n,r))}async utimesUnlocked(t,n,r){z(t,"utimes");let s=this.toRealPath(t),i=this.resolveAndValidate(s,t);try{let o=await O.promises.lstat(i);if(!o.isFile()){if(!o.isDirectory()&&o.nlink>1)throw new Error(`EACCES: cannot change times on multiply-linked special file '${t}'`);await O.promises.utimes(i,n,r);return}if(o.nlink<=1){await O.promises.utimes(i,n,r);return}this.assertCopyOnWriteSize(o.size,"utimes",t);let a=await this.openCopySource(i);try{let l=await a.stat();if(!l.isFile())throw new Error(`EACCES: file type changed, utimes '${t}'`);await this.replaceFile(i,new Uint8Array(0),l,{handle:a,size:l.size},{atime:n,mtime:r},!0)}finally{await a.close()}}catch(o){let a=o;if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);if(a.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(o,t,"utimes")}}};var tr=class{cmdId;cwd;startedAt;exitCode;bashEnv;cmdLine;env;explicitCwd;signal;timeoutMs;abortController=new AbortController;timeoutId;externalAbortListener;resultPromise;constructor(t,n,r,s,i=!1,o,a){this.cmdId=crypto.randomUUID(),this.cwd=r,this.startedAt=new Date,this.bashEnv=t,this.cmdLine=n,this.env=s,this.explicitCwd=i,this.signal=o,this.timeoutMs=a,this.setupCancellation(),this.resultPromise=this.execute()}setupCancellation(){if(this.signal&&(this.signal.aborted?this.abortController.abort(this.signal.reason):(this.externalAbortListener=()=>{this.abortController.abort(this.signal?.reason)},this.signal.addEventListener("abort",this.externalAbortListener,{once:!0}))),this.timeoutMs!==void 0){let t=Math.max(0,this.timeoutMs);this.timeoutId=_r(()=>{this.abortController.abort(new Error(`sandbox command timeout after ${t}ms`))},t)}}cleanupCancellation(){this.timeoutId!==void 0&&(Tr(this.timeoutId),this.timeoutId=void 0),this.signal&&this.externalAbortListener&&(this.signal.removeEventListener("abort",this.externalAbortListener),this.externalAbortListener=void 0)}async execute(){let t={cwd:this.explicitCwd?this.cwd:void 0,env:this.env,signal:this.abortController.signal};try{let n=await this.bashEnv.exec(this.cmdLine,t);return this.exitCode=n.exitCode,n}finally{this.cleanupCancellation()}}async*logs(){let t=await this.resultPromise;t.stdout&&(yield{type:"stdout",data:t.stdout,timestamp:new Date}),t.stderr&&(yield{type:"stderr",data:t.stderr,timestamp:new Date})}async wait(){return await this.resultPromise,this}async output(){let t=await this.resultPromise;return t.stdout+t.stderr}async stdout(){return(await this.resultPromise).stdout}async stderr(){return(await this.resultPromise).stderr}async kill(){this.abortController.abort(new Error("command killed"))}};var ti=class e{bashEnv;timeoutMs;constructor(t,n){this.bashEnv=t,this.timeoutMs=n}static async create(t){let n=t?.fs;if(t?.overlayRoot){if(t?.fs)throw new Error("Cannot specify both 'fs' and 'overlayRoot' options");n=new er({root:t.overlayRoot})}let r=new Ir({env:t?.env,cwd:t?.cwd,fs:n,maxCallDepth:t?.maxCallDepth,maxCommandCount:t?.maxCommandCount,maxLoopIterations:t?.maxLoopIterations,network:t?.network,defenseInDepth:t?.defenseInDepth,python:t?.python,javascript:t?.javascript,commands:t?.commands,customCommands:t?.customCommands,fetch:t?.fetch});return new e(r,t?.timeoutMs)}async runCommand(t,n,r){let s,i,o,a,l=!1,c,u;if(typeof t=="object"){let m=t,E=[m.cmd,...m.args??[]];s=oi(E),i=m.cwd,o=m.env,a=m.signal,l=m.detached??!1,c=m.stdout,u=m.stderr}else if(Array.isArray(n)){let m=r;s=oi([t,...n]),a=m?.signal}else{s=t;let m=n;i=m?.cwd,o=m?.env}let f=i??this.bashEnv.getCwd(),d=i!==void 0,h=new tr(this.bashEnv,s,f,o,d,a,this.timeoutMs);if(l)return h;let p=await h.wait();if(c){let m=await h.stdout();m&&c.write(m)}if(u){let m=await h.stderr();m&&u.write(m)}return p}async writeFiles(t){let n=this.bashEnv.getCwd();for(let[r,s]of Object.entries(t)){let i;typeof s=="string"?i=s:s.encoding==="base64"?i=Buffer.from(s.content,"base64").toString("utf-8"):i=s.content;let o=this.bashEnv.fs.resolvePath(n,r),a=o.substring(0,o.lastIndexOf("/"))||"/";a!=="/"&&await this.bashEnv.fs.mkdir(a,{recursive:!0}),await this.bashEnv.writeFile(o,i)}}async readFile(t,n){let r=await this.bashEnv.readFile(t);return n==="base64"?Buffer.from(r).toString("base64"):r}async mkDir(t,n){let r=this.bashEnv.fs.resolvePath(this.bashEnv.getCwd(),t);await this.bashEnv.fs.mkdir(r,{recursive:n?.recursive??!1})}async stop(){}async extendTimeout(t){}get domain(){}get bashEnvInstance(){return this.bashEnv}};var ni=class{violations=[];violationsByType=new Map;options;constructor(t={}){this.options={maxViolationsPerType:t.maxViolationsPerType??100,maxViolationsTotal:t.maxViolationsTotal??1e3,includeStackTraces:t.includeStackTraces??!0,onViolation:t.onViolation??(()=>{}),logToConsole:t.logToConsole??!1}}record(t){let n=this.options.includeStackTraces?t:{...t,stack:void 0};this.violations.unshift(n),this.violations.length>this.options.maxViolationsTotal&&(this.violations.length=this.options.maxViolationsTotal);let r=this.violationsByType.get(t.type);r||(r=[],this.violationsByType.set(t.type,r)),r.length<this.options.maxViolationsPerType&&r.push(n),this.options.logToConsole&&console.warn(`[SecurityViolation] ${t.type}: ${t.message}`,t.path),this.options.onViolation(n)}getViolations(){return[...this.violations]}getViolationsByType(t){return[...this.violationsByType.get(t)??[]]}getSummary(){let t=[];for(let[n,r]of this.violationsByType){if(r.length===0)continue;let s=new Set,i=Number.POSITIVE_INFINITY,o=0;for(let a of r)s.add(a.path),i=Math.min(i,a.timestamp),o=Math.max(o,a.timestamp);t.push({type:n,count:r.length,firstSeen:i,lastSeen:o,paths:Array.from(s)})}return t.sort((n,r)=>r.count-n.count),t}getTotalCount(){return this.violations.length}hasViolations(){return this.violations.length>0}clear(){this.violations=[],this.violationsByType.clear()}createCallback(){return t=>this.record(t)}};function Gf(){return e=>{console.warn("[DefenseInDepth] Security violation detected:",`
|
|
803
|
+
`;try{a.writeFileSync(`/bin/${t.name}`,l)}catch{}try{a.writeFileSync(`/usr/bin/${t.name}`,l)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=Kf(t.stdout),t.stderr=Kf(t.stderr),t}async exec(t,n){let r=new Gr(this.limits,n?.signal),s;try{s=await this.execInScope(t,n,r,0,n?.signal,!1,!1)}catch(o){try{await r.close()}catch{}throw o}let i=s;try{await r.close()}catch{i={...s,stderr:`${s.stderr}bash: execution cleanup failed
|
|
804
|
+
`,exitCode:126}}return t.trim()?this.logResult(i):i}async execInScope(t,n,r,s,i,o=!1,a=!0,l){let c=d=>a?this.logResult(d):d,u=Wr(i,n?.signal),f=n?{...n,signal:u.signal}:{signal:u.signal};try{if(r.assertExecDepth(s),_r(t,this.limits.maxSourceBytes),!t.trim())return{stdout:"",stderr:"",exitCode:0,env:Ye(this.state.env,f.env)};this.logger?.info("exec",{command:t});let d=f.cwd??this.state.cwd,h,p=d;if(f.cwd)if(f.env&&"PWD"in f.env)h=f.env.PWD;else if(f.env&&!("PWD"in f.env))try{h=await this.fs.realpath(d),p=h}catch{h=d}else h=d;let m=f.replaceEnv||f.newShell,y=m?new Map:new Map((l??this.state).env);if(f.env)for(let[x,D]of Object.entries(f.env))y.set(x,D);h!==void 0&&y.set("PWD",h);let b=!l||f.newShell,w=m&&b?new Set:l?new Set([...l.exportedVars??[],...l.tempExportedVars??[]]):new Set(this.state.exportedVars);if(b){for(let x of Object.keys(f.env??{}))/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(x)&&w.add(x);h!==void 0&&w.add("PWD")}if(f.newShell){y.has("PATH")||y.set("PATH",Hf);for(let[x,D]of Zf)y.has(x)||y.set(x,D);y.set("IFS",`
|
|
805
|
+
`),y.set("OPTIND","1"),y.set("SHELLOPTS",Qr(this.state.options)),y.set("BASHOPTS",Kr(this.state.shoptOptions))}let E=l&&!f.newShell?l:this.state,S={...this.state,env:y,exportedVars:w,arrays:m?new Map:ot(this.state.arrays),cwd:p,previousDir:f.env?.OLDPWD??(m?"":this.state.previousDir),functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},shoptOptions:{...E.shoptOptions},readonlyVars:new Set(E.readonlyVars),hashTable:new Map(E.hashTable),groupStdin:my(f.stdin,f.stdinKind,this.limits.maxInputBytes,this.limits.maxStringLength,r,o),signal:f.signal,extraArgs:f.args},v=t;f.rawScript||(v=Qf(t));let A=this.defenseInDepthConfig?Ce.getInstance(this.defenseInDepthConfig):null,k=A?.activate();try{let x=async()=>{let D=He(v,{maxHeredocSize:this.limits.maxHeredocSize}),$;if(this.transformPlugins.length>0){let P=Object.create(null);for(let B of this.transformPlugins){let U=B.transform({ast:D,metadata:P});D=U.ast,U.metadata&&(P=lr(P,U.metadata))}$=P}let N={fs:this.fs,commands:this.commands,limits:this.limits,executionScope:r,exec:(P,B,U=!1)=>this.execInScope(P,B,r,s+1,f.signal,U,!0,S),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:A?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},W=await new Or(N,S).executeScript(D);return $&&(W.metadata=$),c(W)};return k?await k.run(x):await x()}catch(x){if(x instanceof G)return c({stdout:x.stdout,stderr:x.stderr,exitCode:x.exitCode,internalOutputAccounting:x.internalOutputAccounting,env:Ye(this.state.env,f.env)});if(x instanceof rt)return c({stdout:x.stdout,stderr:x.stderr,exitCode:x.exitCode,env:Ye(this.state.env,f.env)});if(x instanceof le)return c({stdout:x.stdout,stderr:x.stderr,exitCode:1,env:Ye(this.state.env,f.env)});if(x instanceof Ue)return c({stdout:x.stdout,stderr:x.stderr,exitCode:124,env:Ye(this.state.env,f.env)});if(x instanceof C)return c({stdout:x.stdout,stderr:kt(x.stderr),exitCode:C.EXIT_CODE,internalOutputAccounting:x.internalOutputAccounting,env:Ye(this.state.env,f.env)});if(x instanceof zt)return c({stdout:"",stderr:`bash: security violation: ${kt(x.message)}
|
|
806
|
+
`,exitCode:1,env:Ye(this.state.env,f.env)});if(x.name==="ParseException")return c({stdout:"",stderr:`bash: syntax error: ${kt(x.message)}
|
|
807
|
+
`,exitCode:2,env:Ye(this.state.env,f.env)});if(x instanceof Je)return c({stdout:"",stderr:`bash: ${kt(x.message)}
|
|
808
|
+
`,exitCode:2,env:Ye(this.state.env,f.env)});if(x instanceof RangeError)return c({stdout:"",stderr:`bash: ${kt(x.message)}
|
|
809
|
+
`,exitCode:1,env:Ye(this.state.env,f.env)});throw x}finally{k?.deactivate()}}catch(d){if(d instanceof Ue)return c({stdout:d.stdout,stderr:d.stderr,exitCode:124,env:Ye(this.state.env,f.env)});if(d instanceof C)return c({stdout:d.stdout,stderr:kt(d.stderr),exitCode:C.EXIT_CODE,internalOutputAccounting:d.internalOutputAccounting,env:Ye(this.state.env,f.env)});throw d}finally{u.cleanup()}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,n){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),n)}getCwd(){return this.state.cwd}getEnv(){return Zt(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){_r(t,this.limits.maxSourceBytes);let n=Qf(t),r=He(n,{maxHeredocSize:this.limits.maxHeredocSize}),s=Object.create(null);for(let i of this.transformPlugins){let o=i.transform({ast:r,metadata:s});r=o.ast,o.metadata&&(s=lr(s,o.metadata))}return{script:yr(r),ast:r,metadata:s}}};function hy(e,t){let n=t;for(let r=0;r<e.length;r++){let s=e[r];if(n==="single")s==="'"&&(n="none");else if(n==="double")s==="\\"?r++:s==='"'&&(n="none");else if(s==="'")n="single";else if(s==='"')n="double";else if(s==="\\")r++;else if(s==="#"&&(r===0||/\s/.test(e[r-1])))break}return n}function Qf(e){let t=e.split(`
|
|
810
|
+
`),n=[],r=[],s="none";for(let i=0;i<t.length;i++){let o=t[i];if(r.length>0){let u=r[r.length-1];if((u.stripTabs?o.replace(/^\t+/,""):o)===u.delimiter){n.push(o.trimStart()),r.pop();continue}n.push(o);continue}let a=s,l=a==="none"?o.trimStart():o;if(n.push(l),s=hy(o,a),a!=="none")continue;let c=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let u of l.matchAll(c)){let f=u[1]==="-",d=u[3];r.push({delimiter:d,stripTabs:f})}}return n.join(`
|
|
811
|
+
`)}var py=new TextDecoder("utf-8",{fatal:!0});function Kf(e){if(!e)return e;let t=!1;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);if(s>255)return e;s>127&&(t=!0)}if(!t)return e;let n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);try{return py.decode(n)}catch{return e}}function my(e,t,n,r,s,i){if(e===void 0)return;let o=t==="bytes"?e.length:V(e);if(o>n||o>r)throw new C(`stdin size limit exceeded (${Math.min(n,r)} bytes)`,"string_length");return i||s.consumeInput(o,"stdin"),t==="bytes"?e:Ut(e)}import*as me from"node:fs";import*as _e from"node:path";import*as ft from"node:fs";import*as $e from"node:path";function Ie(e,t){let n=/^[A-Za-z]:[\\/]/.test(t)?$e.win32:$e.posix,r=n.relative(t,e);return r===""||r!==".."&&!r.startsWith(`..${n.sep}`)&&!n.isAbsolute(r)}function In(e,t){try{let n=ft.realpathSync(e);return Ie(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=$e.dirname(e);if(r===e)return null;let s=In(r,t);if(s===null)return null;try{if(ft.lstatSync(e).isSymbolicLink()){let o=ft.readlinkSync(e),a=$e.isAbsolute(o)?o:$e.resolve($e.dirname(e),o),l=In(a,t);return l===null?null:l}}catch{}return $e.join(s,$e.basename(e))}return null}}function ti(e,t,n){let r=In(e,n);if(r===null)return null;let s=$e.resolve(e),i=s.slice(t.length),o=r.slice(n.length);if(i!==o)return null;try{if(ft.lstatSync(s).isSymbolicLink())return null}catch{}return r}function ni(e,t){if(!ft.existsSync(e))throw new Error(`${t} root does not exist`);if(!ft.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function Xf(e,t){if(!$e.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=ft.realpathSync(e)}catch{n=$e.resolve(e)}return Ie(n,t)?{withinRoot:!0,relativePath:n.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:$e.basename(e)}}function ri(e,t,n,r){let s=e;if(s.path===void 0){for(let o of r)if(s.message?.includes(o))throw e}let i=s.code||"EIO";throw new Error(`${i}: ${n} '${t}'`)}var yy=["ELOOP","EFBIG","EPERM"],gy="/home/user/project",tr=class{root;canonicalRoot;mountPoint;readOnly;maxFileReadSize;maxMemoryBytes;allowSymlinks;memory=new Map;deleted=new Set;nextMemoryIdentity=1;retainedMemoryBytes=0;memoryEntryBytes(t){if(!t||t.type!=="file")return 0;let n=t.content.byteLength;for(let r of t.appendChunks??[])n+=r.byteLength;return n}assertMemoryCapacity(t,n=0){if(!Number.isSafeInteger(t)||t<0||t>this.maxMemoryBytes-this.retainedMemoryBytes+n)throw new Error(`ENOSPC: overlay memory byte limit exceeded (${this.maxMemoryBytes} bytes)`)}setMemoryEntry(t,n){let r=this.memoryEntryBytes(this.memory.get(t)),s=this.memoryEntryBytes(n);this.assertMemoryCapacity(s,r),this.memory.set(t,n),this.retainedMemoryBytes+=s-r}deleteMemoryEntry(t){let n=this.memory.get(t);n&&(this.retainedMemoryBytes-=this.memoryEntryBytes(n),this.memory.delete(t))}identityFor(t){return t.type==="symlink"?"":(t.identity||(t.identity=`overlay:${this.nextMemoryIdentity++}`),t.identity)}constructor(t){this.root=_e.resolve(t.root);let n=t.mountPoint??gy;if(this.mountPoint=n==="/"?"/":n.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${n}`);if(this.readOnly=t.readOnly??!1,this.maxFileReadSize=t.maxFileReadSize??10485760,this.maxMemoryBytes=t.maxMemoryBytes??1024*1024*1024,!Number.isSafeInteger(this.maxMemoryBytes)||this.maxMemoryBytes<0)throw new Error("OverlayFs: invalid maxMemoryBytes");this.allowSymlinks=t.allowSymlinks??!1,ni(this.root,"OverlayFs"),this.canonicalRoot=me.realpathSync(this.root),this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){let t=this.mountPoint.split("/").filter(Boolean),n="";for(let r of t)n+=`/${r}`,this.memory.has(n)||this.setMemoryEntry(n,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.setMemoryEntry("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}mkdirSync(t,n){let s=j(t).split("/").filter(Boolean),i="";for(let o of s)i+=`/${o}`,this.memory.has(i)||this.setMemoryEntry(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,n){let r=j(t),s=this.getDirname(r);s!=="/"&&this.mkdirSync(s);let i=n instanceof Uint8Array?n:new TextEncoder().encode(n);this.setMemoryEntry(r,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let n=t.lastIndexOf("/");return n===0?"/":t.slice(0,n)}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let n=j(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=_e.join(this.root,r),i=_e.resolve(s);return Ie(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?In(t,this.canonicalRoot):ti(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=_e.dirname(t),r=this.resolveRealPath_(n);return r===null?null:_e.join(r,_e.basename(t))}sanitizeError(t,n,r){ri(t,n,r,yy)}ensureParentDirs(t){let n=mt(t);n!=="/"&&(this.memory.has(n)||(this.ensureParentDirs(n),this.setMemoryEntry(n,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(n))}async existsInOverlay(t){let n=j(t);if(this.deleted.has(n))return!1;if(this.memory.has(n))return!0;let r=this.resolveRealPathParent_(this.toRealPath(n));if(!r)return!1;try{return await me.promises.lstat(r),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=it(n);return Mt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Mt(n,"binary")}async readFileBuffer(t,n=new Set){q(t,"open");let r=j(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let c=this.resolveSymlink(r,s.target);return this.readFileBuffer(c,n)}if(s.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(!s.appendChunks||s.appendChunks.length===0)return s.content;let o=s.appendChunks.reduce((c,u)=>c+u.byteLength,s.content.byteLength);if(!Number.isSafeInteger(o))throw new Error(`EFBIG: file too large, read '${t}'`);let a=new Uint8Array(o);a.set(s.content);let l=s.content.byteLength;for(let c of s.appendChunks)a.set(c,l),l+=c.byteLength;return s.content=a,s.appendChunks=void 0,a}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let o=await me.promises.lstat(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${t}'`);let c=await me.promises.readlink(i),u=this.realTargetToVirtual(r,c),f=this.resolveSymlink(r,u);return this.readFileBuffer(f,n)}if(o.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(this.maxFileReadSize>0&&o.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${o.size} bytes, max ${this.maxFileReadSize})`);let a=this.allowSymlinks?me.constants.O_RDONLY:me.constants.O_RDONLY|me.constants.O_NOFOLLOW,l=await me.promises.open(i,a);try{let c=await l.readFile();return new Uint8Array(c)}finally{await l.close()}}catch(o){let a=o.code;if(a==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(a==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(o,t,"open")}}async writeFile(t,n,r){q(t,"write"),this.assertWritable(`write '${t}'`);let s=j(t);this.ensureParentDirs(s);let i=it(r),o=Ft(n,i);this.setMemoryEntry(s,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(s)}async appendFile(t,n,r){q(t,"append"),this.assertWritable(`append '${t}'`);let s=j(t),i=it(r),o=Ft(n,i),a=this.memory.get(s);if(a?.type==="file"){this.assertMemoryCapacity(o.byteLength),a.appendChunks||(a.appendChunks=[]),a.appendChunks.push(o),this.retainedMemoryBytes+=o.byteLength,a.mtime=new Date,this.deleted.delete(s);return}let l;try{l=await this.readFileBuffer(s)}catch{l=new Uint8Array(0)}this.ensureParentDirs(s),this.setMemoryEntry(s,{type:"file",content:l,appendChunks:[o],mode:420,mtime:new Date}),this.deleted.delete(s)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,n=new Set){q(t,"stat");let r=j(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let a=this.resolveSymlink(r,s.target);return this.stat(a,n)}let o=0;return s.type==="file"&&(o=s.content.length+(s.appendChunks?.reduce((a,l)=>a+l.byteLength,0)??0)),{isFile:s.type==="file",isDirectory:s.type==="directory",isSymbolicLink:!1,mode:s.mode,size:o,mtime:s.mtime,identity:this.identityFor(s)}}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let o=await me.promises.lstat(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let a=await me.promises.readlink(i),l=this.realTargetToVirtual(r,a),c=this.resolveSymlink(r,l);return this.stat(c,n)}return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:!1,mode:o.mode,size:o.size,mtime:o.mtime,dev:o.dev,ino:o.ino}}catch(o){if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(o,t,"stat")}}async lstat(t){q(t,"lstat");let n=j(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let i=0;return r.type==="file"&&(i=r.content.length+(r.appendChunks?.reduce((o,a)=>o+a.byteLength,0)??0)),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:i,mtime:r.mtime,identity:this.identityFor(r)}}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await me.promises.lstat(s);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime,dev:i.dev,ino:i.ino}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}resolveSymlink(t,n){return Fn(t,n)}realTargetToVirtual(t,n){let r=Xf(n,this.canonicalRoot);if(r.withinRoot){if(!_e.isAbsolute(n))return n;let s=r.relativePath;return this.mountPoint==="/"?s:`${this.mountPoint}${s}`}return r.safeName}async mkdir(t,n){q(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=j(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=mt(r);if(i!=="/"&&!await this.existsInOverlay(i))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.setMemoryEntry(r,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(r)}async readdirCore(t,n){if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Map,s=new Set,i=n==="/"?"/":`${n}/`;for(let a of this.deleted)if(a.startsWith(i)){let l=a.slice(i.length),c=l.split("/")[0];c&&!l.includes("/",c.length)&&s.add(c)}for(let[a,l]of this.memory)if(a!==n&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!s.has(u)&&!c.includes("/",1)&&r.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let o=this.resolveRealPath_(this.toRealPath(n));if(o)try{if(!this.allowSymlinks&&(await me.promises.lstat(o)).isSymbolicLink()){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);return r}let a=await me.promises.readdir(o,{withFileTypes:!0});for(let l of a)!s.has(l.name)&&!r.has(l.name)&&r.set(l.name,{name:l.name,isFile:l.isFile(),isDirectory:l.isDirectory(),isSymbolicLink:l.isSymbolicLink()})}catch(a){if(a.code==="ENOENT"){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else a.code!=="ENOTDIR"&&this.sanitizeError(a,t,"scandir")}return r}async resolveForReaddir(t,n=!1){let r=j(t),s=new Set,i=n,o=this.memory.get(r);for(;o&&o.type==="symlink";){if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(r),i=!0,r=this.resolveSymlink(r,o.target),o=this.memory.get(r)}if(o)return{normalized:r,outsideOverlay:!1};if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let l=this.resolveRealPath_(this.toRealPath(r));if(!l)return{normalized:r,outsideOverlay:!0};try{if((await me.promises.lstat(l)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let u=await me.promises.readlink(l),f=this.realTargetToVirtual(r,u),d=this.resolveSymlink(r,f);return this.resolveForReaddir(d,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async createExclusive(t,n){let r=n.directory?"mkdir":"open";q(t,r),this.assertWritable(`${r} '${t}'`);let s=j(t);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);let i=mt(s),o=s;if(i!=="/"){let a;try{a=await this.realpath(i)}catch{throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`)}let l=await this.stat(a).catch(()=>null);if(!l)throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);if(!l.isDirectory)throw new Error(`ENOTDIR: not a directory, ${r} '${t}'`);if(o=st(a,s.slice(s.lastIndexOf("/")+1)),o!==s&&await this.existsInOverlay(o))throw new Error(`EEXIST: file already exists, ${r} '${t}'`)}if(this.memory.has(o))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);this.setMemoryEntry(o,n.directory?{type:"directory",mode:n.mode,mtime:new Date}:{type:"file",content:new Uint8Array(0),mode:n.mode,mtime:new Date}),this.deleted.delete(o)}async readdir(t){q(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.keys()).sort((i,o)=>i<o?-1:i>o?1:0)}async readdirWithFileTypes(t){q(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.values()).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async rm(t,n){q(t,"rm"),this.assertWritable(`rm '${t}'`);let r=j(t);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(r)).isDirectory){let o=await this.readdir(r);if(o.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of o){let l=r==="/"?`/${a}`:`${r}/${a}`;await this.rm(l,n)}}}}catch(i){if(i instanceof Error&&(i.message.includes("ENOTEMPTY")||i.message.includes("EISDIR")))throw i}this.deleteMemoryEntry(r),this.existsOnRealFs(r)&&this.deleted.add(r)}existsOnRealFs(t){let n=this.toRealPath(t),r=this.resolveRealPathParent_(n);if(!r)return!1;try{return me.lstatSync(r),!0}catch{return!1}}async cp(t,n,r){q(t,"cp"),q(n,"cp"),this.assertWritable(`cp '${n}'`);let s=j(t),i=j(n);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let a=await this.stat(s);if(a.isFile){let l=await this.readFileBuffer(s);await this.writeFile(i,l)}else if(a.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(Lt(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(s);for(let c of l){let u=s==="/"?`/${c}`:`${s}/${c}`,f=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(u,f,r)}}}async mv(t,n){this.assertWritable(`mv '${n}'`),await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return Ht(t,n)}getAllPaths(){let t=new Set(this.memory.keys());for(let n of this.deleted)t.delete(n);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,n){if(this.deleted.has(t))return;let r=this.resolveRealPath_(this.toRealPath(t));if(r)try{let s=me.readdirSync(r);for(let i of s){let o=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(o))continue;n.add(o);let a=_e.join(r,i);me.lstatSync(a).isDirectory()&&this.scanRealFs(o,n)}}catch{}}async chmod(t,n){q(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=j(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(r);if(i){i.mode=n;return}let o=await this.stat(r);if(o.isFile){let a=await this.readFileBuffer(r);this.setMemoryEntry(r,{type:"file",content:a,mode:n,mtime:new Date})}else o.isDirectory&&this.setMemoryEntry(r,{type:"directory",mode:n,mtime:new Date})}async symlink(t,n){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${n}'`);q(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=j(n);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.setMemoryEntry(r,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(t,n){q(t,"link"),q(n,"link"),this.assertWritable(`link '${n}'`);let r=j(t),s=j(n);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let o=await this.stat(r);if(!o.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let l=await this.readFileBuffer(r);this.ensureParentDirs(s),this.setMemoryEntry(s,{type:"file",content:l,mode:o.mode,mtime:new Date,identity:o.identity??`overlay:${this.nextMemoryIdentity++}`}),this.deleted.delete(s)}async readlink(t){q(t,"readlink");let n=j(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let r=this.memory.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await me.promises.readlink(s);if(!_e.isAbsolute(i)){let o=_e.resolve(_e.dirname(s),i),a;try{a=me.realpathSync(o)}catch{a=o}if(!Ie(a,this.canonicalRoot))return _e.basename(i)}return this.realTargetToVirtual(n,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){q(t,"realpath");let n=j(t),r=new Set,s=async a=>{let l=a==="/"?[]:a.slice(1).split("/"),c="";for(let u of l){if(c=`${c}/${u}`,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(c),d=0,h=40;for(;f&&f.type==="symlink"&&d<h;){if(r.add(c),c=this.resolveSymlink(c,f.target),d++,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(c)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let p=this.toRealPath(c),m=this.resolveRealPath_(p);if(m)try{if((await me.promises.lstat(m)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let b=await me.promises.readlink(m),w=this.realTargetToVirtual(c,b);return r.add(c),c=this.resolveSymlink(c,w),s(c)}}catch(y){if(y.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(y,t,"realpath")}else if(!this.allowSymlinks){let y=this.resolveRealPathParent_(p);if(y)try{if((await me.promises.lstat(y)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch(b){if(b.message?.includes("ENOENT")||b.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(b,t,"realpath")}}}}return c||"/"},i=await s(n);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,n,r){q(t,"utimes"),this.assertWritable(`utimes '${t}'`);let s=j(t);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let o=this.memory.get(s);if(o){o.mtime=r;return}let a=await this.stat(s);if(a.isFile){let l=await this.readFileBuffer(s);this.setMemoryEntry(s,{type:"file",content:l,mode:a.mode,mtime:r})}else a.isDirectory&&this.setMemoryEntry(s,{type:"directory",mode:a.mode,mtime:r})}};import{randomBytes as wy}from"node:crypto";import*as I from"node:fs";import*as Z from"node:path";var Ey=["EACCES","escaping sandbox","EFBIG","ENOTSUP"],si=class e{static activeMutationRoots=new Set;static pendingMutations=[];root;canonicalRoot;maxFileReadSize;maxCopyOnWriteSize;maxCopySize;allowSymlinks;constructor(t){this.root=Z.resolve(t.root),this.maxFileReadSize=t.maxFileReadSize??10485760,this.maxCopyOnWriteSize=t.maxCopyOnWriteSize??104857600,this.maxCopySize=t.maxCopySize??0,this.allowSymlinks=t.allowSymlinks??!1,ni(this.root,"ReadWriteFs"),this.canonicalRoot=I.realpathSync(this.root)}resolveAndValidate(t,n){let r=this.allowSymlinks?In(t,this.canonicalRoot):ti(t,this.root,this.canonicalRoot);if(r===null)throw new Error(`EACCES: permission denied, '${n}' resolves outside sandbox`);return r}validateParent(t,n){let r=Z.dirname(t),s=this.resolveAndValidate(r,n);return Z.join(s,Z.basename(t))}toRealPath(t){let n=j(t),r=Z.join(this.root,n);return Z.resolve(r)}async readFile(t,n){let r=await this.readFileBuffer(t),s=it(n);return Mt(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Mt(n,"binary")}async readFileBuffer(t){q(t,"open");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{let s=this.allowSymlinks?I.constants.O_RDONLY:I.constants.O_RDONLY|I.constants.O_NOFOLLOW,i=await I.promises.open(r,s);try{if(this.maxFileReadSize>0){let a=await i.stat();if(a.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${a.size} bytes, max ${this.maxFileReadSize})`)}let o=await i.readFile();return new Uint8Array(o)}finally{await i.close()}}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(i.code==="EISDIR")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(i.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(s,t,"open")}}async writeFile(t,n,r){await this.withFilesystemMutation(()=>this.writeFileUnlocked(t,n,r))}async writeFileUnlocked(t,n,r){q(t,"write");let s=this.toRealPath(t),i=this.resolveAndValidate(s,t),o=it(r),a=Ft(n,o),l=Z.dirname(i);try{await I.promises.mkdir(l,{recursive:!0}),i=this.resolveAndValidate(s,t);let c=this.allowSymlinks?0:I.constants.O_NOFOLLOW,u=null;try{let f=await I.promises.lstat(i);if(!f.isFile()&&!f.isDirectory())throw new Error(`EACCES: cannot write special file '${t}'`);let d=await I.promises.open(i,I.constants.O_WRONLY|I.constants.O_NONBLOCK|c);try{if(u=await d.stat(),!u.isFile())throw new Error(`EACCES: cannot write special file '${t}'`);if(u.nlink<=1){await d.truncate(0),await d.writeFile(a);return}}finally{await d.close()}}catch(f){if(f.code!=="ENOENT")throw f}await this.replaceFile(i,a,u)}catch(c){if(c.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(c,t,"write")}}async appendFile(t,n,r){await this.withFilesystemMutation(()=>this.appendFileUnlocked(t,n,r))}async appendFileUnlocked(t,n,r){q(t,"append");let s=this.toRealPath(t),i=it(r),o=Ft(n,i),a=this.resolveAndValidate(s,t),l=Z.dirname(a);try{await I.promises.mkdir(l,{recursive:!0}),a=this.resolveAndValidate(s,t);let c=this.allowSymlinks?0:I.constants.O_NOFOLLOW,u=null;try{let d=await I.promises.lstat(a);if(!d.isFile()&&!d.isDirectory())throw new Error(`EACCES: cannot append special file '${t}'`);let h=await I.promises.open(a,I.constants.O_WRONLY|I.constants.O_APPEND|I.constants.O_NONBLOCK|c);try{if(u=await h.stat(),!u.isFile())throw new Error(`EACCES: cannot append special file '${t}'`);if(u.nlink<=1){await h.writeFile(o);return}}finally{await h.close()}}catch(d){if(d.code!=="ENOENT")throw d}if(!u){await this.replaceFile(a,o,null);return}this.assertCopyOnWriteSize(u.size,"append",t);let f=await this.openCopySource(a);try{let d=await f.stat();if(!d.isFile()||d.dev!==u.dev||d.ino!==u.ino)throw new Error(`EACCES: file identity changed, append '${t}'`);await this.replaceFile(a,o,d,{handle:f,size:u.size})}finally{await f.close()}}catch(c){if(c.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(c,t,"append")}}async withFilesystemMutation(t){return new Promise((n,r)=>{e.pendingMutations.push({root:this.canonicalRoot,start:()=>{e.activeMutationRoots.add(this.canonicalRoot),t().then(n,r).finally(()=>{e.activeMutationRoots.delete(this.canonicalRoot),e.drainMutationQueue()})}}),e.drainMutationQueue()})}static drainMutationQueue(){for(let t=0;t<e.pendingMutations.length;){let n=e.pendingMutations[t];if([...e.activeMutationRoots].some(s=>Ie(n.root,s)||Ie(s,n.root))){t++;continue}e.pendingMutations.splice(t,1),n.start()}}assertCopyOnWriteSize(t,n,r){if(this.maxCopyOnWriteSize>0&&t>this.maxCopyOnWriteSize)throw new Error(`EFBIG: file too large for copy-on-write ${n} '${r}' (${t} bytes, max ${this.maxCopyOnWriteSize})`)}assertCopySize(t,n){if(this.maxCopySize>0&&t.size>this.maxCopySize)throw new Error(`EFBIG: file too large to copy '${n}' (${t.size} bytes, max ${this.maxCopySize})`)}randomTransactionToken(){return wy(16).toString("hex")}async openCopySource(t){let n=this.allowSymlinks?0:I.constants.O_NOFOLLOW,r=I.constants.O_RDONLY|I.constants.O_NONBLOCK|n,s=I.constants.O_NOATIME;if(process.platform!=="linux"||s===void 0)return I.promises.open(t,r);try{return await I.promises.open(t,r|s)}catch(i){if(i.code!=="EPERM")throw i;return I.promises.open(t,r)}}async replaceFile(t,n,r,s,i,o=!1){let a=Z.dirname(t),l="",c=null,u=r===null?438:384;for(let p=0;p<16;p++){l=Z.join(a,`.just-bash-write-${this.randomTransactionToken()}`);try{c=await I.promises.open(l,I.constants.O_WRONLY|I.constants.O_CREAT|I.constants.O_EXCL,u);break}catch(m){if(m.code!=="EEXIST")throw m}}if(!c)throw new Error(`EEXIST: replacement write '${t}'`);let f=c,d=await f.stat(),h=!1;try{try{let m=0,y=async b=>{let w=0;for(;w<b.byteLength;){let{bytesWritten:E}=await f.write(b,w,b.byteLength-w,m+w);if(E===0)throw new Error("EIO: replacement write made no progress");w+=E}m+=w};if(s){let b=Buffer.allocUnsafe(65536),w=0,E=s.size;for(;E>0;){let S=Math.min(b.length,E),{bytesRead:v}=await s.handle.read(b,0,S,w);if(v===0)break;await y(b.subarray(0,v)),w+=v,E-=v}}if(await y(n),r!==null&&await f.chmod(r.mode&(o?4095:511)),i)await f.utimes(i.atime,i.mtime);else if(r!==null){let b=await f.stat();await f.utimes(r.atime,b.mtime)}}finally{await f.close(),c=null}let p=await I.promises.lstat(l);if(!p.isFile()||p.dev!==d.dev||p.ino!==d.ino)throw new Error("EACCES: replacement staging entry changed");await I.promises.rename(l,t),h=!0}finally{c&&await c.close().catch(()=>{}),h||await I.promises.rm(l,{force:!0}).catch(()=>{})}}async exists(t){if(t.includes("\0"))return!1;let n=this.toRealPath(t);try{let r=this.resolveAndValidate(n,t);return await I.promises.access(r),!0}catch{return!1}}async stat(t){q(t,"stat");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{let s=await I.promises.lstat(r);if(!this.allowSymlinks&&s.isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);return{isFile:s.isFile(),isDirectory:s.isDirectory(),isSymbolicLink:s.isSymbolicLink(),mode:s.mode,size:s.size,mtime:s.mtime,dev:s.dev,ino:s.ino,identity:`real:${s.dev}:${s.ino}`}}catch(s){if(s.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(s,t,"stat")}}async lstat(t){q(t,"lstat");let n=this.toRealPath(t),r=n===this.root?this.resolveAndValidate(n,t):this.validateParent(n,t);try{let s=await I.promises.lstat(r);return{isFile:s.isFile(),isDirectory:s.isDirectory(),isSymbolicLink:s.isSymbolicLink(),mode:s.mode,size:s.size,mtime:s.mtime,dev:s.dev,ino:s.ino,identity:`real:${s.dev}:${s.ino}`}}catch(s){if(s.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(s,t,"lstat")}}async mkdir(t,n){await this.withFilesystemMutation(()=>this.mkdirUnlocked(t,n))}async createExclusive(t,n){await this.withFilesystemMutation(()=>this.createExclusiveUnlocked(t,n))}async assertCreatedInsideRoot(t,n,r,s,i){let o=!1;try{let a=this.resolveAndValidate(n,r),l=await I.promises.lstat(a);o=a===t&&l.dev===i.dev&&l.ino===i.ino}catch{o=!1}if(!o)throw new Error(`EACCES: permission denied, '${r}' resolves outside sandbox during ${s}`)}async createExclusiveUnlocked(t,n){let r=n.directory?"mkdir":"open";q(t,r);let s=this.toRealPath(t),i=s===this.root?this.resolveAndValidate(s,t):this.validateParent(s,t);try{if(n.directory){await I.promises.mkdir(i,{mode:n.mode});let l=await I.promises.open(i,I.constants.O_RDONLY|(I.constants.O_DIRECTORY??0)|(this.allowSymlinks?0:I.constants.O_NOFOLLOW));try{await this.assertCreatedInsideRoot(i,s,t,r,await l.stat())}finally{await l.close()}return}let o=this.allowSymlinks?0:I.constants.O_NOFOLLOW,a=await I.promises.open(i,I.constants.O_WRONLY|I.constants.O_CREAT|I.constants.O_EXCL|o,n.mode);try{await this.assertCreatedInsideRoot(i,s,t,r,await a.stat())}finally{await a.close()}}catch(o){let a=o;if(a.code==="EEXIST")throw new Error(`EEXIST: file already exists, ${r} '${t}'`);if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);this.sanitizeError(o,t,r)}}async mkdirUnlocked(t,n){q(t,"mkdir");let r=this.toRealPath(t),s=r===this.root?this.resolveAndValidate(r,t):this.validateParent(r,t);try{await I.promises.mkdir(s,{recursive:n?.recursive})}catch(i){let o=i;if(o.code==="EEXIST")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.sanitizeError(i,t,"mkdir")}}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){q(t,"scandir");let n=this.toRealPath(t),r=this.resolveAndValidate(n,t);try{if(!this.allowSymlinks&&(await I.promises.lstat(r)).isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);return(await I.promises.readdir(r,{withFileTypes:!0})).map(i=>({name:i.name,isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink()})).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(i.code==="ENOTDIR")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);this.sanitizeError(s,t,"scandir")}}async rm(t,n){await this.withFilesystemMutation(()=>this.rmUnlocked(t,n))}async rmUnlocked(t,n){q(t,"rm");let r=this.toRealPath(t),s=this.validateParent(r,t);try{let i=await I.promises.lstat(s);if(!this.allowSymlinks&&i.isSymbolicLink())throw new Error(`EACCES: permission denied, '${t}' is a symlink`);await I.promises.rm(s,{recursive:n?.recursive??!1,force:n?.force??!1})}catch(i){let o=i;if(o.code==="ENOENT"){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(o.code==="ENOTEMPTY")throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);this.sanitizeError(i,t,"rm")}}async cp(t,n,r){await this.withFilesystemMutation(()=>this.cpUnlocked(t,n,r))}async cpUnlocked(t,n,r){q(t,"cp"),q(n,"cp");let s=this.toRealPath(t),i=this.toRealPath(n),o=this.validateParent(s,t),a=this.resolveAndValidate(i,n),l;try{l=await I.promises.lstat(o)}catch(c){if(c.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, cp '${t}'`);this.sanitizeError(c,t,"cp")}if(l.isDirectory()&&Ie(a,o))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);if(!l.isDirectory())try{let c=this.validateParent(i,n),u=await I.promises.lstat(c);if(l.dev===u.dev&&l.ino===u.ino)throw new Error(`EINVAL: cannot copy '${t}' onto itself, '${n}'`)}catch(c){if(c.code!=="ENOENT")throw c}if(l.isFile())try{let c=await I.promises.stat(a);if(l.dev===c.dev&&l.ino===c.ino)throw new Error(`EINVAL: cannot copy '${t}' onto itself, '${n}'`)}catch(c){if(c.code!=="ENOENT")throw c}try{await this.preflightCopyTree(o,t)}catch(c){this.sanitizeError(c,t,"cp")}if(l.isFile()||l.isSymbolicLink())try{await I.promises.mkdir(Z.dirname(a),{recursive:!0}),this.resolveAndValidate(i,n)}catch(c){this.sanitizeError(c,n,"cp")}try{await this.copyTreeEntry(o,i,t,n,r?.recursive??!1)}catch(c){let u=c;if(u.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(u.code==="EISDIR")throw new Error(`EISDIR: is a directory, cp '${t}'`);this.sanitizeError(c,t,"cp")}}async copyTreeEntry(t,n,r,s,i){let o=await I.promises.lstat(t);if(o.isFile()){this.assertCopySize(o,r);let a=this.resolveAndValidate(n,s),l=await this.assertCopyDestinationWritable(a,s),c=await this.openCopySource(t);try{let u=await c.stat();if(!u.isFile()||u.dev!==o.dev||u.ino!==o.ino)throw new Error(`EACCES: file identity changed, cp '${r}'`);await this.replaceFile(a,new Uint8Array(0),l??o,{handle:c,size:o.size})}finally{await c.close()}return}if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`EACCES: permission denied, cp '${r}' contains a symlink`);let a=await I.promises.readlink(t),l=Z.isAbsolute(a)?await this.toVirtualAbsoluteSymlinkTarget(a,r):a;await this.replaceSymlink(n,s,l);return}if(o.isDirectory()){if(!i)throw new Error(`EISDIR: is a directory, cp '${r}'`);let a=this.resolveAndValidate(n,s);await I.promises.mkdir(a,{recursive:!0}),a=this.resolveAndValidate(n,s);for(let l of await I.promises.readdir(t))await this.copyTreeEntry(Z.join(t,l),Z.join(n,l),Z.join(r,l),Z.join(s,l),!0);await I.promises.chmod(a,o.mode&4095);return}throw new Error(`EINVAL: unsupported file type, cp '${r}'`)}async assertCopyDestinationWritable(t,n){let r;try{r=await I.promises.lstat(t)}catch(o){if(o.code==="ENOENT")return null;throw o}if(!r.isFile()){if(r.isDirectory())return r;throw new Error(`EACCES: cannot copy over special file '${n}'`)}let s=this.allowSymlinks?0:I.constants.O_NOFOLLOW,i=await I.promises.open(t,I.constants.O_WRONLY|I.constants.O_NONBLOCK|s);try{let o=await i.stat();if(!o.isFile()||o.dev!==r.dev||o.ino!==r.ino)throw new Error(`EACCES: destination changed, cp '${n}'`)}finally{await i.close()}return r}async replaceSymlink(t,n,r){let s=this.validateParent(t,n),i=Z.dirname(j(n)),o="",a="",l="",c=null;for(let f=0;f<16;f++){let d=`.just-bash-copy-link-${this.randomTransactionToken()}`;o=i==="/"?`/${d}`:`${i}/${d}`,a=this.toRealPath(o);try{await this.symlinkUnlocked(r,o),l=this.validateParent(a,o),c=await I.promises.lstat(l);break}catch(h){let p=h;if(p.code!=="EEXIST"&&!p.message.startsWith("EEXIST:"))throw h}}if(!c)throw new Error(`EEXIST: replacement symlink '${n}'`);let u=!1;try{let f=await I.promises.lstat(l);if(!f.isSymbolicLink()||f.dev!==c.dev||f.ino!==c.ino)throw new Error("EACCES: replacement symlink entry changed");await I.promises.rename(l,s),u=!0}finally{!u&&l&&await I.promises.rm(l,{force:!0}).catch(()=>{})}}async toVirtualAbsoluteSymlinkTarget(t,n){let r=Z.resolve(t),s=await I.promises.realpath(r),i=await I.promises.realpath(Z.dirname(r)),o=Z.join(i,Z.basename(r));if(!Ie(s,this.canonicalRoot)||!Ie(o,this.canonicalRoot))throw new Error(`EACCES: permission denied, cp '${n}' contains an unsafe symlink`);return o.slice(this.canonicalRoot.length)||"/"}async preflightCopyTree(t,n,r=new Set){let s=await I.promises.lstat(t),i=`${s.dev}:${s.ino}`;if(r.has(i))throw new Error(`ELOOP: cp '${n}' contains a cycle`);if(s.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`EACCES: permission denied, cp '${n}' contains a symlink`);let o=await I.promises.realpath(t);if(!Ie(o,this.canonicalRoot))throw new Error(`EACCES: permission denied, cp '${n}' contains an unsafe symlink`);return}if(s.isDirectory()){r.add(i);try{let o=await I.promises.readdir(t);for(let a of o)await this.preflightCopyTree(Z.join(t,a),Z.join(n,a),r)}finally{r.delete(i)}}}async mv(t,n){await this.withFilesystemMutation(()=>this.mvUnlocked(t,n))}async mvUnlocked(t,n){q(t,"mv"),q(n,"mv");let r=this.toRealPath(t),s=this.toRealPath(n),i=this.validateParent(r,t),o=this.validateParent(s,n),a;try{a=await I.promises.lstat(i)}catch(c){if(c.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);this.sanitizeError(c,t,"mv")}if(a.isDirectory()&&this.isSameOrDescendantIdentity(i,o))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);try{if(a.isSymbolicLink()){let c=await I.promises.readlink(i),u=Z.resolve(Z.dirname(o),c),f=await I.promises.realpath(u).catch(()=>u);if(!Ie(f,this.canonicalRoot))throw new Error(`EACCES: permission denied, mv '${t}' -> '${n}' would create symlink escaping sandbox`)}}catch(c){let u=c;if(u.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(u.message?.includes("EACCES")||u.message?.includes("escaping sandbox"))throw c}let l=Z.dirname(o);try{await I.promises.mkdir(l,{recursive:!0})}catch(c){this.sanitizeError(c,n,"mv")}try{await I.promises.rename(i,o)}catch(c){let u=c;if(u.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(u.code==="EXDEV"){await this.moveAcrossDevices(t,n);return}this.sanitizeError(c,t,"mv")}try{if(I.lstatSync(o).isDirectory()&&this.findEscapingSymlinks(o).length>0)throw await I.promises.rename(o,i),new Error(`EACCES: permission denied, mv '${t}' -> '${n}' would create symlinks escaping sandbox`)}catch(c){if(c.message?.includes("EACCES")||c.message?.includes("escaping sandbox"))throw c;await I.promises.rename(o,i).catch(()=>{}),this.sanitizeError(c,n,"mv")}}isSameOrDescendantIdentity(t,n){let r=t,s=n;try{r=I.realpathSync(t)}catch{}try{s=I.realpathSync(n)}catch{try{let i=I.realpathSync(Z.dirname(n));s=Z.join(i,Z.basename(n))}catch{}}return Ie(s,r)}async uniqueTransactionPath(t,n){let r=Z.posix.dirname(t);for(let s=0;s<16;s++){let i=Z.posix.join(r,`.just-bash-mv-${n}-${this.randomTransactionToken()}`);if(!await this.exists(i))return i}throw new Error(`EEXIST: mv '${t}'`)}async moveAcrossDevices(t,n){let r=await this.uniqueTransactionPath(n,"stage"),s=await this.uniqueTransactionPath(n,"backup"),i=await this.uniqueTransactionPath(t,"source"),o=this.validateParent(this.toRealPath(r),r),a=this.validateParent(this.toRealPath(s),s),l=this.validateParent(this.toRealPath(t),t),c=this.validateParent(this.toRealPath(i),i),u=this.validateParent(this.toRealPath(n),n),f=!1,d=!1,h=!1,p=async()=>{h&&await I.promises.rename(c,l).catch(()=>{}),d&&await I.promises.rm(u,{recursive:!0,force:!0}).catch(()=>{}),f&&await I.promises.rename(a,u).catch(()=>{}),await I.promises.rm(o,{recursive:!0,force:!0}).catch(()=>{})};try{if(await this.cpUnlocked(t,r,{recursive:!0}),(await I.promises.lstat(o)).isDirectory()&&this.findEscapingSymlinks(o).length>0)throw new Error(`EACCES: permission denied, mv '${t}' -> '${n}' would create symlinks escaping sandbox`);try{await I.promises.rename(u,a),f=!0}catch(y){if(y.code!=="ENOENT")throw y}await I.promises.rename(o,u),d=!0,await I.promises.rename(l,c),h=!0,await I.promises.rm(c,{recursive:!0,force:!1}),h=!1,f&&await I.promises.rm(a,{recursive:!0,force:!0}).catch(()=>{})}catch(m){await p(),this.sanitizeError(m,t,"mv")}}resolvePath(t,n){return Ht(t,n)}getAllPaths(){let t=[];return this.scanDir("/",t),t}sanitizeError(t,n,r){ri(t,n,r,Ey)}findEscapingSymlinks(t){let n=[],r=I.readdirSync(t);for(let s of r){let i=Z.join(t,s),o=I.lstatSync(i);if(o.isSymbolicLink()){let a=I.readlinkSync(i),l=Z.resolve(t,a),c;try{c=I.realpathSync(l)}catch(u){if(u.code!=="ENOENT")throw u;c=l}Ie(c,this.canonicalRoot)||n.push(i)}else o.isDirectory()&&n.push(...this.findEscapingSymlinks(i))}return n}scanDir(t,n){let r=this.toRealPath(t),s;try{s=this.resolveAndValidate(r,t)}catch{return}try{let i=I.readdirSync(s);for(let o of i){let a=t==="/"?`/${o}`:`${t}/${o}`;n.push(a);let l=Z.join(s,o);I.lstatSync(l).isDirectory()&&this.scanDir(a,n)}}catch{}}async chmod(t,n){await this.withFilesystemMutation(()=>this.chmodUnlocked(t,n))}async chmodUnlocked(t,n){q(t,"chmod");let r=this.toRealPath(t),s=this.resolveAndValidate(r,t);try{let i=await I.promises.lstat(s);if(!i.isFile()){if(!i.isDirectory()&&i.nlink>1)throw new Error(`EACCES: cannot chmod multiply-linked special file '${t}'`);await I.promises.chmod(s,n);return}if(i.nlink<=1){await I.promises.chmod(s,n);return}this.assertCopyOnWriteSize(i.size,"chmod",t);let o=await this.openCopySource(s);try{let a=await o.stat();if(!a.isFile())throw new Error(`EACCES: file type changed, chmod '${t}'`);await this.replaceFile(s,new Uint8Array(0),{mode:n,atime:a.atime,mtime:a.mtime},{handle:o,size:a.size},{atime:a.atime,mtime:a.mtime},!0)}finally{await o.close()}}catch(i){let o=i;if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);if(o.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(i,t,"chmod")}}async symlink(t,n){await this.withFilesystemMutation(()=>this.symlinkUnlocked(t,n))}async symlinkUnlocked(t,n){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${n}'`);q(n,"symlink");let r=this.toRealPath(n),s=this.validateParent(r,n),i=j(n),o=j(Z.dirname(i)),a=t.startsWith("/")?j(t):j(o==="/"?`/${t}`:`${o}/${t}`),l=Z.join(this.canonicalRoot,a),c=Z.dirname(s),u=t.startsWith("/")?l:Z.relative(c,l)||".";try{await I.promises.symlink(u,s)}catch(f){if(f.code==="EEXIST")throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.sanitizeError(f,n,"symlink")}}async link(t,n){await this.withFilesystemMutation(()=>this.linkUnlocked(t,n))}async linkUnlocked(t,n){q(t,"link"),q(n,"link");let r=this.toRealPath(t),s=this.toRealPath(n),i=this.resolveAndValidate(r,t),o=s===this.root?this.resolveAndValidate(s,n):this.validateParent(s,n);try{await I.promises.link(i,o)}catch(a){let l=a;if(l.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(l.code==="EEXIST")throw new Error(`EEXIST: file already exists, link '${n}'`);if(l.code==="EPERM")throw new Error(`EPERM: operation not permitted, link '${t}'`);this.sanitizeError(a,t,"link")}}async readlink(t){q(t,"readlink");let n=this.toRealPath(t),r=n===this.root?this.resolveAndValidate(n,t):this.validateParent(n,t);try{let s=await I.promises.readlink(r),i=j(t),o=Z.dirname(i),a=Z.isAbsolute(s)?s:Z.resolve(Z.dirname(r),s),l=await I.promises.realpath(a).catch(()=>a);if(Ie(l,this.canonicalRoot)){let c=l.slice(this.canonicalRoot.length)||"/";return o==="/"?c.startsWith("/")?c.slice(1)||".":c:Z.relative(o,c)}return Z.basename(s)}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(s,t,"readlink")}}async realpath(t){q(t,"realpath");let n=this.toRealPath(t);try{this.resolveAndValidate(n,t)}catch{throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}let r;try{r=await I.promises.realpath(n)}catch(s){let i=s;if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);if(i.code==="ELOOP")throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);this.sanitizeError(s,t,"realpath")}if(Ie(r,this.canonicalRoot))return r.slice(this.canonicalRoot.length)||"/";throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}async utimes(t,n,r){await this.withFilesystemMutation(()=>this.utimesUnlocked(t,n,r))}async utimesUnlocked(t,n,r){q(t,"utimes");let s=this.toRealPath(t),i=this.resolveAndValidate(s,t);try{let o=await I.promises.lstat(i);if(!o.isFile()){if(!o.isDirectory()&&o.nlink>1)throw new Error(`EACCES: cannot change times on multiply-linked special file '${t}'`);await I.promises.utimes(i,n,r);return}if(o.nlink<=1){await I.promises.utimes(i,n,r);return}this.assertCopyOnWriteSize(o.size,"utimes",t);let a=await this.openCopySource(i);try{let l=await a.stat();if(!l.isFile())throw new Error(`EACCES: file type changed, utimes '${t}'`);await this.replaceFile(i,new Uint8Array(0),l,{handle:a,size:l.size},{atime:n,mtime:r},!0)}finally{await a.close()}}catch(o){let a=o;if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);if(a.code==="ELOOP")throw new Error(`EACCES: permission denied, '${t}' is a symlink`);this.sanitizeError(o,t,"utimes")}}};var nr=class{cmdId;cwd;startedAt;exitCode;bashEnv;cmdLine;env;explicitCwd;signal;timeoutMs;abortController=new AbortController;timeoutId;externalAbortListener;resultPromise;constructor(t,n,r,s,i=!1,o,a){this.cmdId=crypto.randomUUID(),this.cwd=r,this.startedAt=new Date,this.bashEnv=t,this.cmdLine=n,this.env=s,this.explicitCwd=i,this.signal=o,this.timeoutMs=a,this.setupCancellation(),this.resultPromise=this.execute()}setupCancellation(){if(this.signal&&(this.signal.aborted?this.abortController.abort(this.signal.reason):(this.externalAbortListener=()=>{this.abortController.abort(this.signal?.reason)},this.signal.addEventListener("abort",this.externalAbortListener,{once:!0}))),this.timeoutMs!==void 0){let t=Math.max(0,this.timeoutMs);this.timeoutId=Lr(()=>{this.abortController.abort(new Error(`sandbox command timeout after ${t}ms`))},t)}}cleanupCancellation(){this.timeoutId!==void 0&&(Fr(this.timeoutId),this.timeoutId=void 0),this.signal&&this.externalAbortListener&&(this.signal.removeEventListener("abort",this.externalAbortListener),this.externalAbortListener=void 0)}async execute(){let t={cwd:this.explicitCwd?this.cwd:void 0,env:this.env,signal:this.abortController.signal};try{let n=await this.bashEnv.exec(this.cmdLine,t);return this.exitCode=n.exitCode,n}finally{this.cleanupCancellation()}}async*logs(){let t=await this.resultPromise;t.stdout&&(yield{type:"stdout",data:t.stdout,timestamp:new Date}),t.stderr&&(yield{type:"stderr",data:t.stderr,timestamp:new Date})}async wait(){return await this.resultPromise,this}async output(){let t=await this.resultPromise;return t.stdout+t.stderr}async stdout(){return(await this.resultPromise).stdout}async stderr(){return(await this.resultPromise).stderr}async kill(){this.abortController.abort(new Error("command killed"))}};var ii=class e{bashEnv;timeoutMs;constructor(t,n){this.bashEnv=t,this.timeoutMs=n}static async create(t){let n=t?.fs;if(t?.overlayRoot){if(t?.fs)throw new Error("Cannot specify both 'fs' and 'overlayRoot' options");n=new tr({root:t.overlayRoot})}let r=new Tr({env:t?.env,cwd:t?.cwd,fs:n,maxCallDepth:t?.maxCallDepth,maxCommandCount:t?.maxCommandCount,maxLoopIterations:t?.maxLoopIterations,network:t?.network,defenseInDepth:t?.defenseInDepth,python:t?.python,javascript:t?.javascript,commands:t?.commands,customCommands:t?.customCommands,fetch:t?.fetch});return new e(r,t?.timeoutMs)}async runCommand(t,n,r){let s,i,o,a,l=!1,c,u;if(typeof t=="object"){let m=t,y=[m.cmd,...m.args??[]];s=ui(y),i=m.cwd,o=m.env,a=m.signal,l=m.detached??!1,c=m.stdout,u=m.stderr}else if(Array.isArray(n)){let m=r;s=ui([t,...n]),a=m?.signal}else{s=t;let m=n;i=m?.cwd,o=m?.env}let f=i??this.bashEnv.getCwd(),d=i!==void 0,h=new nr(this.bashEnv,s,f,o,d,a,this.timeoutMs);if(l)return h;let p=await h.wait();if(c){let m=await h.stdout();m&&c.write(m)}if(u){let m=await h.stderr();m&&u.write(m)}return p}async writeFiles(t){let n=this.bashEnv.getCwd();for(let[r,s]of Object.entries(t)){let i;typeof s=="string"?i=s:s.encoding==="base64"?i=Buffer.from(s.content,"base64").toString("utf-8"):i=s.content;let o=this.bashEnv.fs.resolvePath(n,r),a=o.substring(0,o.lastIndexOf("/"))||"/";a!=="/"&&await this.bashEnv.fs.mkdir(a,{recursive:!0}),await this.bashEnv.writeFile(o,i)}}async readFile(t,n){let r=await this.bashEnv.readFile(t);return n==="base64"?Buffer.from(r).toString("base64"):r}async mkDir(t,n){let r=this.bashEnv.fs.resolvePath(this.bashEnv.getCwd(),t);await this.bashEnv.fs.mkdir(r,{recursive:n?.recursive??!1})}async stop(){}async extendTimeout(t){}get domain(){}get bashEnvInstance(){return this.bashEnv}};var oi=class{violations=[];violationsByType=new Map;options;constructor(t={}){this.options={maxViolationsPerType:t.maxViolationsPerType??100,maxViolationsTotal:t.maxViolationsTotal??1e3,includeStackTraces:t.includeStackTraces??!0,onViolation:t.onViolation??(()=>{}),logToConsole:t.logToConsole??!1}}record(t){let n=this.options.includeStackTraces?t:{...t,stack:void 0};this.violations.unshift(n),this.violations.length>this.options.maxViolationsTotal&&(this.violations.length=this.options.maxViolationsTotal);let r=this.violationsByType.get(t.type);r||(r=[],this.violationsByType.set(t.type,r)),r.length<this.options.maxViolationsPerType&&r.push(n),this.options.logToConsole&&console.warn(`[SecurityViolation] ${t.type}: ${t.message}`,t.path),this.options.onViolation(n)}getViolations(){return[...this.violations]}getViolationsByType(t){return[...this.violationsByType.get(t)??[]]}getSummary(){let t=[];for(let[n,r]of this.violationsByType){if(r.length===0)continue;let s=new Set,i=Number.POSITIVE_INFINITY,o=0;for(let a of r)s.add(a.path),i=Math.min(i,a.timestamp),o=Math.max(o,a.timestamp);t.push({type:n,count:r.length,firstSeen:i,lastSeen:o,paths:Array.from(s)})}return t.sort((n,r)=>r.count-n.count),t}getTotalCount(){return this.violations.length}hasViolations(){return this.violations.length>0}clear(){this.violations=[],this.violationsByType.clear()}createCallback(){return t=>this.record(t)}};function Yf(){return e=>{console.warn("[DefenseInDepth] Security violation detected:",`
|
|
810
812
|
Type: ${e.type}`,`
|
|
811
813
|
Path: ${e.path}`,`
|
|
812
814
|
Message: ${e.message}`,e.executionId?`
|
|
813
|
-
ExecutionId: ${e.executionId}`:"")}}var
|
|
815
|
+
ExecutionId: ${e.executionId}`:"")}}var Jf=null;try{let e=process.getBuiltinModule,t=typeof e=="function"?e("module"):typeof ai=="function"?ai("node:module"):null;Jf=t?.Module??t?.default??null,typeof e=="function"&&e("worker_threads")?.isMainThread===!1&&e("crypto")?.randomUUID?.()}catch{Jf=null}var xa=class{maxSourceBytes;plugins=[];constructor(t=67108864){if(this.maxSourceBytes=t,!Number.isSafeInteger(t)||t<0)throw new Error("BashTransformPipeline: invalid maxSourceBytes")}use(t){return this.plugins.push(t),this}transform(t){_r(t,this.maxSourceBytes);let n=He(t),r=Object.create(null);for(let s of this.plugins){let i=s.transform({ast:n,metadata:r});n=i.ast,i.metadata&&(r=lr(r,i.metadata))}return{script:yr(n),ast:n,metadata:r}}};var Pa=class{name="command-collector";transform(t){let n=new Set;return this.walkScript(t.ast,n),{ast:t.ast,metadata:{commands:[...n].sort()}}}walkScript(t,n){for(let r of t.statements)this.walkStatement(r,n)}walkStatement(t,n){for(let r of t.pipelines)this.walkPipeline(r,n)}walkPipeline(t,n){for(let r of t.commands)this.walkCommand(r,n)}walkCommand(t,n){switch(t.type){case"SimpleCommand":if(t.name){let r=this.extractName(t.name);r&&n.add(r)}t.name&&this.walkWordParts(t.name.parts,n);for(let r of t.args)this.walkWordParts(r.parts,n);for(let r of t.assignments)if(r.value&&this.walkWordParts(r.value.parts,n),r.array)for(let s of r.array)this.walkWordParts(s.parts,n);break;case"If":for(let r of t.clauses){for(let s of r.condition)this.walkStatement(s,n);for(let s of r.body)this.walkStatement(s,n)}if(t.elseBody)for(let r of t.elseBody)this.walkStatement(r,n);break;case"For":if(t.words)for(let r of t.words)this.walkWordParts(r.parts,n);for(let r of t.body)this.walkStatement(r,n);break;case"CStyleFor":for(let r of t.body)this.walkStatement(r,n);break;case"While":case"Until":for(let r of t.condition)this.walkStatement(r,n);for(let r of t.body)this.walkStatement(r,n);break;case"Case":this.walkWordParts(t.word.parts,n);for(let r of t.items)for(let s of r.body)this.walkStatement(s,n);break;case"Subshell":case"Group":for(let r of t.body)this.walkStatement(r,n);break;case"ArithmeticCommand":case"ConditionalCommand":break;case"FunctionDef":this.walkCommand(t.body,n);break}}walkWordParts(t,n){for(let r of t)switch(r.type){case"CommandSubstitution":this.walkScript(r.body,n);break;case"ProcessSubstitution":this.walkScript(r.body,n);break;case"DoubleQuoted":this.walkWordParts(r.parts,n);break;case"ParameterExpansion":r.operation&&this.walkParameterOp(r.operation,n);break}}walkParameterOp(t,n){switch(t.type){case"DefaultValue":case"AssignDefault":case"UseAlternative":this.walkWordParts(t.word.parts,n);break;case"ErrorIfUnset":t.word&&this.walkWordParts(t.word.parts,n);break;case"PatternRemoval":this.walkWordParts(t.pattern.parts,n);break;case"PatternReplacement":this.walkWordParts(t.pattern.parts,n),t.replacement&&this.walkWordParts(t.replacement.parts,n);break;case"CaseModification":t.pattern&&this.walkWordParts(t.pattern.parts,n);break;case"Indirection":t.innerOp&&this.walkParameterOp(t.innerOp,n);break}}extractName(t){return t.parts.length===1&&t.parts[0].type==="Literal"?t.parts[0].value:null}};var $a=class{name="tee";options;counter=0;constructor(t){this.options=t}transform(t){let n=[],r=this.options.timestamp??new Date;return{ast:this.transformScript(t.ast,n,r),metadata:{teeFiles:n}}}formatTimestamp(t){return t.toISOString().replace(/:/g,"-")}generateStdoutPath(t,n,r){let s=this.formatTimestamp(r),i=String(t).padStart(3,"0");if(q(this.options.outputDir,"create tee output"),!this.options.outputDir.startsWith("/")||this.options.outputDir.split("/").includes(".."))throw new Error("tee output directory must be an absolute safe path");let o=j(this.options.outputDir),a=this.encodeCommandName(n),l=j(`${o}/${s}-${i}-${a}.stdout.txt`);if(o!=="/"&&!l.startsWith(`${o}/`))throw new Error("tee output path escapes configured output directory");return l}encodeCommandName(t){if(/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/.test(t))return t;let n=2166136261;for(let s=0;s<t.length;s++)n^=t.charCodeAt(s),n=Math.imul(n,16777619)>>>0;return`${t.replace(/[^A-Za-z0-9_-]/g,"_").replace(/^_+|_+$/g,"").slice(0,32)||"command"}-${n.toString(16).padStart(8,"0")}`}transformScript(t,n,r){return{...t,statements:t.statements.map(s=>this.transformStatement(s,n,r))}}transformStatement(t,n,r){let s=[],i=[];for(let o=0;o<t.pipelines.length;o++){let a=t.pipelines[o];o>0&&i.push(t.operators[o-1]);let l=this.transformPipeline(a,n,r);s.push(l.pipeline),l.origCmdNewIndices!==null&&(i.push(";"),s.push(this.makePipestatusRestore(l.origCmdNewIndices,l.negated)))}return{...t,pipelines:s,operators:i}}transformPipeline(t,n,r){if(t.commands.length<=1)return{pipeline:t,origCmdNewIndices:null,negated:!1};let s=[],i=[],o=[],a=!1;for(let l=0;l<t.commands.length;l++){let c=t.commands[l],u=l===t.commands.length-1;if(c.type!=="SimpleCommand"||!c.name||!this.shouldTarget(c)){o.push(s.length),s.push(c),u||i.push(t.pipeStderr?.[l]??!1);continue}let f=this.getCommandName(c.name)??"unknown",d=this.counter++,h=this.generateStdoutPath(d,f,r),p=this.makeTeeCommand(h),m=this.serializeCommand(c);n.push({commandIndex:d,commandName:f,command:m,stdoutFile:h}),o.push(s.length),s.push(c),i.push(t.pipeStderr?.[l]??!1),s.push(p),u||i.push(!1),a=!0}return a?{pipeline:{...t,negated:!1,commands:s,pipeStderr:i.length>0?i:void 0},origCmdNewIndices:o,negated:t.negated}:{pipeline:t,origCmdNewIndices:null,negated:!1}}makePipestatusRestore(t,n){return{type:"Pipeline",commands:[{type:"SimpleCommand",assignments:[],name:{type:"Word",parts:[{type:"Literal",value:"builtin"}]},args:[{type:"Word",parts:[{type:"Literal",value:"__just_bash_tee_restore"}]},...t.map(r=>({type:"Word",parts:[{type:"ParameterExpansion",parameter:`PIPESTATUS[${r}]`,operation:null}]}))],redirections:[]}],negated:n}}shouldTarget(t){if(!this.options.targetCommandPattern)return!0;let n=this.getCommandName(t.name);return n!==null&&this.options.targetCommandPattern.test(n)}getCommandName(t){return t&&t.parts.length===1&&t.parts[0].type==="Literal"?t.parts[0].value:null}serializeCommand(t){let n=[];t.name&&n.push(we(t.name));for(let r of t.args)n.push(we(r));return n.join(" ")}makeTeeCommand(t){return{type:"SimpleCommand",assignments:[],name:{type:"Word",parts:[{type:"Literal",value:"tee"}]},args:[{type:"Word",parts:[{type:"Literal",value:t}]}],redirections:[]}}};export{Tr as Bash,xa as BashTransformPipeline,Pa as CommandCollectorPlugin,Ce as DefenseInDepthBox,li as EMPTY_BYTES,yt as InMemoryFs,Kt as MountableFs,ut as NetworkAccessDeniedError,tr as OverlayFs,si as ReadWriteFs,Vt as RedirectNotAllowedError,ii as Sandbox,nr as SandboxCommand,zt as SecurityViolationError,oi as SecurityViolationLogger,$a as TeePlugin,On as TooManyRedirectsError,sd as bytesOutput,ud as createCommandContext,Yf as createConsoleViolationCallback,td as decodeBytesToUtf8,fd as defineCommand,Ut as encodeUtf8ToBytes,id as getCommandNames,ld as getJavaScriptCommandNames,od as getNetworkCommandNames,ad as getPythonCommandNames,wn as latin1FromBytes,He as parse,yr as serialize,_t as stdoutAsBytes,nd as stdoutKind,rd as textOutput,ir as unsafeBytesFromLatin1};
|