just-bash 2.7.0 → 2.7.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/dist/bin/chunks/alias-MGDOL4KG.js +7 -0
- package/dist/bin/chunks/awk2-ASLLINAN.js +21 -0
- package/dist/bin/{shell/chunks/base64-O7TCK5TL.js → chunks/base64-43KPK6TL.js} +1 -1
- package/dist/bin/chunks/bash-OAUBNRSG.js +6 -0
- package/dist/bin/{shell/chunks/cat-AJXZOSPN.js → chunks/cat-HNXE2ES2.js} +1 -1
- package/dist/bin/chunks/chunk-4PRVMER6.js +2 -0
- package/dist/bin/chunks/chunk-C6FK2JV3.js +74 -0
- package/dist/bin/chunks/chunk-GZHFXDDO.js +10 -0
- package/dist/bin/chunks/chunk-JBABAK44.js +4 -0
- package/dist/bin/chunks/chunk-YNACG4DZ.js +6 -0
- package/dist/bin/chunks/{column-TSFEMTG6.js → column-HQ4AK5DM.js} +1 -1
- package/dist/bin/chunks/{cp-XXWRVG2D.js → cp-VFXCUKXO.js} +1 -1
- package/dist/bin/chunks/{curl-TH7YRBSA.js → curl-7IUASLUJ.js} +1 -1
- package/dist/bin/chunks/{diff-GI3QVUGD.js → diff-ZGXLP3DN.js} +1 -1
- package/dist/bin/chunks/{du-XQPYLN3H.js → du-PECPOFQT.js} +1 -1
- package/dist/bin/chunks/env-W6IMQ43Y.js +9 -0
- package/dist/bin/chunks/{expansion-BOR3ELLC.js → expansion-IEMZ6T22.js} +1 -1
- package/dist/bin/{shell/chunks/gzip-YXK3WZQL.js → chunks/gzip-5ILPB46W.js} +1 -1
- package/dist/bin/chunks/history-56DL6SXU.js +3 -0
- package/dist/bin/{shell/chunks/jq-RGZHJNXC.js → chunks/jq-M2WXBRXF.js} +1 -1
- package/dist/bin/chunks/{ls-BEHQBUMC.js → ls-5LN47VHU.js} +1 -1
- package/dist/bin/chunks/{mkdir-XJABRAUN.js → mkdir-XMSNS6S5.js} +1 -1
- package/dist/bin/chunks/{mv-3ATZ2ABL.js → mv-P4KHB27X.js} +1 -1
- package/dist/bin/chunks/{paste-FT6WBQZG.js → paste-UCH462KK.js} +1 -1
- package/dist/bin/{shell/chunks/printf-YPXD4CRE.js → chunks/printf-XPBSFXJE.js} +1 -1
- package/dist/bin/{shell/chunks/python3-JGT65AEB.js → chunks/python3-ZWX5SFJ3.js} +5 -5
- package/dist/bin/{shell/chunks/rm-2PKAWTSQ.js → chunks/rm-S7ASVG34.js} +1 -1
- package/dist/bin/chunks/{rmdir-GOODLY5W.js → rmdir-OEMA5ZTD.js} +1 -1
- package/dist/bin/chunks/{stat-UEQ7KMY5.js → stat-ZZVPXHLF.js} +1 -1
- package/dist/bin/{shell/chunks/tee-ZFIT2GTM.js → chunks/tee-XSKPK43X.js} +1 -1
- package/dist/bin/chunks/time-F4NVQOJH.js +14 -0
- package/dist/bin/chunks/{tr-MBLEXZBI.js → tr-FMT6JWLE.js} +1 -1
- package/dist/bin/chunks/{tree-DQBEJH47.js → tree-WC3AXFHC.js} +1 -1
- package/dist/bin/chunks/{uniq-IXHB2FVS.js → uniq-NNXAFO6D.js} +1 -1
- package/dist/bin/{shell/chunks/wc-SAOHEZYP.js → chunks/wc-CZ2TD6T6.js} +1 -1
- package/dist/bin/{shell/chunks/which-FCDFBOMN.js → chunks/which-5QEJAXNR.js} +1 -1
- package/dist/bin/chunks/xan-OPVCJ3ZA.js +140 -0
- package/dist/bin/chunks/{xan-view-6Z6TWXMY.js → xan-view-5SZBYPLG.js} +1 -1
- package/dist/bin/chunks/{yq-PFV4T2PV.js → yq-JU6VN4X4.js} +1 -1
- package/dist/bin/just-bash.js +251 -251
- package/dist/bin/shell/chunks/alias-MGDOL4KG.js +7 -0
- package/dist/bin/shell/chunks/awk2-ASLLINAN.js +21 -0
- package/dist/bin/{chunks/base64-O7TCK5TL.js → shell/chunks/base64-43KPK6TL.js} +1 -1
- package/dist/bin/shell/chunks/bash-OAUBNRSG.js +6 -0
- package/dist/bin/{chunks/cat-AJXZOSPN.js → shell/chunks/cat-HNXE2ES2.js} +1 -1
- package/dist/bin/shell/chunks/chunk-4PRVMER6.js +2 -0
- package/dist/bin/shell/chunks/chunk-C6FK2JV3.js +74 -0
- package/dist/bin/shell/chunks/chunk-GZHFXDDO.js +10 -0
- package/dist/bin/shell/chunks/chunk-JBABAK44.js +4 -0
- package/dist/bin/shell/chunks/chunk-YNACG4DZ.js +6 -0
- package/dist/bin/shell/chunks/{column-TSFEMTG6.js → column-HQ4AK5DM.js} +1 -1
- package/dist/bin/shell/chunks/{cp-XXWRVG2D.js → cp-VFXCUKXO.js} +1 -1
- package/dist/bin/shell/chunks/{curl-TH7YRBSA.js → curl-7IUASLUJ.js} +1 -1
- package/dist/bin/shell/chunks/{diff-GI3QVUGD.js → diff-ZGXLP3DN.js} +1 -1
- package/dist/bin/shell/chunks/{du-XQPYLN3H.js → du-PECPOFQT.js} +1 -1
- package/dist/bin/shell/chunks/env-W6IMQ43Y.js +9 -0
- package/dist/bin/shell/chunks/{expansion-BOR3ELLC.js → expansion-IEMZ6T22.js} +1 -1
- package/dist/bin/{chunks/gzip-YXK3WZQL.js → shell/chunks/gzip-5ILPB46W.js} +1 -1
- package/dist/bin/shell/chunks/history-56DL6SXU.js +3 -0
- package/dist/bin/{chunks/jq-RGZHJNXC.js → shell/chunks/jq-M2WXBRXF.js} +1 -1
- package/dist/bin/shell/chunks/{ls-BEHQBUMC.js → ls-5LN47VHU.js} +1 -1
- package/dist/bin/shell/chunks/{mkdir-XJABRAUN.js → mkdir-XMSNS6S5.js} +1 -1
- package/dist/bin/shell/chunks/{mv-3ATZ2ABL.js → mv-P4KHB27X.js} +1 -1
- package/dist/bin/shell/chunks/{paste-FT6WBQZG.js → paste-UCH462KK.js} +1 -1
- package/dist/bin/{chunks/printf-YPXD4CRE.js → shell/chunks/printf-XPBSFXJE.js} +1 -1
- package/dist/bin/{chunks/python3-JGT65AEB.js → shell/chunks/python3-ZWX5SFJ3.js} +5 -5
- package/dist/bin/{chunks/rm-2PKAWTSQ.js → shell/chunks/rm-S7ASVG34.js} +1 -1
- package/dist/bin/shell/chunks/{rmdir-GOODLY5W.js → rmdir-OEMA5ZTD.js} +1 -1
- package/dist/bin/shell/chunks/{stat-UEQ7KMY5.js → stat-ZZVPXHLF.js} +1 -1
- package/dist/bin/{chunks/tee-ZFIT2GTM.js → shell/chunks/tee-XSKPK43X.js} +1 -1
- package/dist/bin/shell/chunks/time-F4NVQOJH.js +14 -0
- package/dist/bin/shell/chunks/{tr-MBLEXZBI.js → tr-FMT6JWLE.js} +1 -1
- package/dist/bin/shell/chunks/{tree-DQBEJH47.js → tree-WC3AXFHC.js} +1 -1
- package/dist/bin/shell/chunks/{uniq-IXHB2FVS.js → uniq-NNXAFO6D.js} +1 -1
- package/dist/bin/{chunks/wc-SAOHEZYP.js → shell/chunks/wc-CZ2TD6T6.js} +1 -1
- package/dist/bin/{chunks/which-FCDFBOMN.js → shell/chunks/which-5QEJAXNR.js} +1 -1
- package/dist/bin/shell/chunks/xan-OPVCJ3ZA.js +140 -0
- package/dist/bin/shell/chunks/{xan-view-6Z6TWXMY.js → xan-view-5SZBYPLG.js} +1 -1
- package/dist/bin/shell/chunks/{yq-PFV4T2PV.js → yq-JU6VN4X4.js} +1 -1
- package/dist/bin/shell/shell.js +226 -226
- package/dist/bundle/browser.js +623 -623
- package/dist/bundle/chunks/alias-YGOORMWI.js +6 -0
- package/dist/bundle/chunks/awk2-5K7HVGCQ.js +20 -0
- package/dist/bundle/chunks/{base64-3BME25ON.js → base64-2JFR3HGT.js} +1 -1
- package/dist/bundle/chunks/bash-BYWM5OPC.js +5 -0
- package/dist/bundle/chunks/{cat-MV4K6AUA.js → cat-GPKR7D6K.js} +1 -1
- package/dist/bundle/chunks/chunk-76ZRJPDK.js +73 -0
- package/dist/bundle/chunks/chunk-F55TLFGB.js +9 -0
- package/dist/bundle/chunks/chunk-HWKDQ44K.js +3 -0
- package/dist/bundle/chunks/chunk-IEPFPINK.js +5 -0
- package/dist/bundle/chunks/chunk-OJDRYQWQ.js +1 -0
- package/dist/bundle/chunks/{column-XPDNNO5Y.js → column-R6OLMEUA.js} +1 -1
- package/dist/bundle/chunks/{cp-PBJT3GBF.js → cp-NJSENVKC.js} +1 -1
- package/dist/bundle/chunks/{curl-XLP4VABU.js → curl-QDCXHQMX.js} +1 -1
- package/dist/bundle/chunks/{diff-ZLJYSBRK.js → diff-ELUS3RW7.js} +1 -1
- package/dist/bundle/chunks/{du-NQXEC3EF.js → du-T4JUAAB2.js} +1 -1
- package/dist/bundle/chunks/env-M3AXY56V.js +8 -0
- package/dist/bundle/chunks/{expansion-RIGCFEMA.js → expansion-DXWR3WZB.js} +1 -1
- package/dist/bundle/chunks/{gzip-L3NDJG3F.js → gzip-4P4KGYT5.js} +1 -1
- package/dist/bundle/chunks/history-TMBGOQO6.js +2 -0
- package/dist/bundle/chunks/{jq-RLRYRPOJ.js → jq-KF5D2PYR.js} +1 -1
- package/dist/bundle/chunks/{ls-5W3NU5OJ.js → ls-PUJHEPXS.js} +1 -1
- package/dist/bundle/chunks/{mkdir-7UKY4B3B.js → mkdir-SF2UE4KB.js} +1 -1
- package/dist/bundle/chunks/{mv-FXHEKRTB.js → mv-JPBZPM4O.js} +1 -1
- package/dist/bundle/chunks/{paste-QTGVEPH5.js → paste-QAP6Y75J.js} +1 -1
- package/dist/bundle/chunks/{printf-66XGXFCD.js → printf-OAPYPRGV.js} +1 -1
- package/dist/bundle/chunks/{python3-3OP7EKER.js → python3-SKZGHYDO.js} +5 -5
- package/dist/bundle/chunks/{rm-I2SRVF7H.js → rm-MJFRIDNT.js} +1 -1
- package/dist/bundle/chunks/{rmdir-XFQE4ZYV.js → rmdir-DU6C7ZEO.js} +1 -1
- package/dist/bundle/chunks/{stat-IVQBBOKN.js → stat-IOLJTP7U.js} +1 -1
- package/dist/bundle/chunks/{tee-2QU4NRSJ.js → tee-4KHTWVWB.js} +1 -1
- package/dist/bundle/chunks/time-EGF4KTWV.js +13 -0
- package/dist/bundle/chunks/{tr-EDGW5FG6.js → tr-P43NRVKL.js} +1 -1
- package/dist/bundle/chunks/{tree-MEM64BW3.js → tree-UFVZH4SS.js} +1 -1
- package/dist/bundle/chunks/{uniq-47QVBRNC.js → uniq-XBP4SJA3.js} +1 -1
- package/dist/bundle/chunks/{wc-HE5XARI4.js → wc-VDPK3LVS.js} +1 -1
- package/dist/bundle/chunks/{which-UBLRBDHN.js → which-GF77XMJD.js} +1 -1
- package/dist/bundle/chunks/xan-RW5GSH6C.js +139 -0
- package/dist/bundle/chunks/{xan-view-DMFUMZG7.js → xan-view-ECQUO7AJ.js} +1 -1
- package/dist/bundle/chunks/{yq-L665QPQU.js → yq-EMWRPC7R.js} +1 -1
- package/dist/bundle/index.js +253 -253
- package/dist/commands/query-engine/evaluator.d.ts +2 -2
- package/dist/commands/query-engine/safe-object.d.ts +49 -0
- package/dist/commands/query-engine/value-operations.d.ts +1 -0
- package/dist/commands/xan/aggregation.d.ts +1 -1
- package/dist/commands/xan/csv.d.ts +16 -0
- package/dist/interpreter/alias-expansion.d.ts +1 -1
- package/dist/interpreter/helpers/ifs.d.ts +4 -4
- package/dist/interpreter/simple-command-assignments.d.ts +1 -1
- package/dist/interpreter/types.d.ts +2 -2
- package/dist/types.d.ts +2 -2
- package/package.json +1 -1
- package/dist/bin/chunks/alias-EGIS5LUE.js +0 -7
- package/dist/bin/chunks/awk2-GFEJOWML.js +0 -21
- package/dist/bin/chunks/bash-PGDTHIM2.js +0 -6
- package/dist/bin/chunks/chunk-FSAGDARS.js +0 -74
- package/dist/bin/chunks/chunk-KD3EODLB.js +0 -6
- package/dist/bin/chunks/chunk-TA7RUHGQ.js +0 -4
- package/dist/bin/chunks/chunk-UUQYHLBO.js +0 -10
- package/dist/bin/chunks/env-7A4MH7BJ.js +0 -9
- package/dist/bin/chunks/history-G5C2J2OY.js +0 -3
- package/dist/bin/chunks/time-37F5EBPK.js +0 -14
- package/dist/bin/chunks/xan-5HNHTFMB.js +0 -140
- package/dist/bin/shell/chunks/alias-EGIS5LUE.js +0 -7
- package/dist/bin/shell/chunks/awk2-GFEJOWML.js +0 -21
- package/dist/bin/shell/chunks/bash-PGDTHIM2.js +0 -6
- package/dist/bin/shell/chunks/chunk-FSAGDARS.js +0 -74
- package/dist/bin/shell/chunks/chunk-KD3EODLB.js +0 -6
- package/dist/bin/shell/chunks/chunk-TA7RUHGQ.js +0 -4
- package/dist/bin/shell/chunks/chunk-UUQYHLBO.js +0 -10
- package/dist/bin/shell/chunks/env-7A4MH7BJ.js +0 -9
- package/dist/bin/shell/chunks/history-G5C2J2OY.js +0 -3
- package/dist/bin/shell/chunks/time-37F5EBPK.js +0 -14
- package/dist/bin/shell/chunks/xan-5HNHTFMB.js +0 -140
- package/dist/bundle/chunks/alias-ATFBB6D2.js +0 -6
- package/dist/bundle/chunks/awk2-6FBZTP57.js +0 -20
- package/dist/bundle/chunks/bash-OLRNM52U.js +0 -5
- package/dist/bundle/chunks/chunk-3AWP5CWK.js +0 -73
- package/dist/bundle/chunks/chunk-A263W2RD.js +0 -9
- package/dist/bundle/chunks/chunk-CZPA5RBA.js +0 -5
- package/dist/bundle/chunks/chunk-ZVV5VXYZ.js +0 -3
- package/dist/bundle/chunks/env-2UI6XINU.js +0 -8
- package/dist/bundle/chunks/history-MQDK2OPD.js +0 -2
- package/dist/bundle/chunks/time-UWXBG6CS.js +0 -13
- package/dist/bundle/chunks/xan-A6VPI4HJ.js +0 -139
package/dist/bundle/index.js
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
import{B as Ys,C as Qs,D as ne,E as De,F as K,G as ue,H as at,I as Js,J as T,K as en,L as tn,M as pe,N as Bt,O as lt,P as V,a as Bs,b as js,c as Hs,d as it,e as Z,f as W,g as de,h as J,i as he,j as _e,k as Ft,l as ot,m as Us,n as Mt,o as qs,p as ae,q as ve,r as Zs,s as Gs,t as Wt,u as zt,v as Ne,w as Xs,x as Ks,y as fe,z as Vt}from"./chunks/chunk-3AWP5CWK.js";import{a as re,b as ie,c as se,d as oe,e as zs,f as z,g as Oe,h as st,i as nt,j as Vs,k as te,l as Pe,m as rt,n as ce}from"./chunks/chunk-PSW6BMXW.js";import"./chunks/chunk-NUFRM6SI.js";import{a as ge}from"./chunks/chunk-44UOCSGV.js";import"./chunks/chunk-DXB73IDG.js";var be=[{name:"echo",load:async()=>(await import("./chunks/echo-6S7WE7XB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-MV4K6AUA.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-66XGXFCD.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-5W3NU5OJ.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-7UKY4B3B.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-XFQE4ZYV.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-TDTEBHHI.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-I2SRVF7H.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-PBJT3GBF.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-FXHEKRTB.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-Y7YB677N.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-ODWUR7E6.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-S4NVAMC4.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-EM4O3U4P.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-SA7P5NJ7.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-52LRAWXT.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-HE5XARI4.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-IVQBBOKN.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-NIC6JNLH.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-NIC6JNLH.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-NIC6JNLH.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-SRMB7L6G.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-IV6HLDXU.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-6FBZTP57.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-EJUT5LXD.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-47QVBRNC.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-AXQM7FFF.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-NVKWEAZF.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-QTGVEPH5.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-EDGW5FG6.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-FKUV5GH5.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-KWQGFZH5.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-6CFXIPYZ.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-VSTNOVF5.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-I7A2VXFD.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-LRU5XCFP.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-YBTFW7MT.js")).split},{name:"column",load:async()=>(await import("./chunks/column-XPDNNO5Y.js")).column},{name:"join",load:async()=>(await import("./chunks/join-X3QYPZUA.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-2QU4NRSJ.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-YGMSVGUV.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-CFA5ZIGT.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-YPJLCQYA.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-MEM64BW3.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-NQXEC3EF.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-2UI6XINU.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-2UI6XINU.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-ATFBB6D2.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-ATFBB6D2.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-MQDK2OPD.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-4FRA6OJ7.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-CNJ54NE6.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-CNJ54NE6.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-VT2LJIDX.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-OLRNM52U.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-OLRNM52U.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-RLRYRPOJ.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-3BME25ON.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-ZLJYSBRK.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-PN3CMG7K.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-AK4QE4WR.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-X3X3N6IE.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-UWXBG6CS.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-5VRIVQYP.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-DG4E7SIS.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-KLHZSRUA.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-WKWTIZGQ.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-IUVNMBTA.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-NQP3CKRV.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-ZK6GQVSL.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-75YOGKM4.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-UBLRBDHN.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-2X4JLF4W.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-NWR32CGF.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-YUDAIS32.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-3FPDPLWJ.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-L3NDJG3F.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-L3NDJG3F.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-L3NDJG3F.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(be.push({name:"tar",load:async()=>(await import("./chunks/tar-LWIHPMT6.js")).tarCommand}),be.push({name:"yq",load:async()=>(await import("./chunks/yq-L665QPQU.js")).yqCommand}),be.push({name:"xan",load:async()=>(await import("./chunks/xan-A6VPI4HJ.js")).xanCommand}),be.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-5QVZOGER.js")).sqlite3Command}),be.push({name:"python3",load:async()=>(await import("./chunks/python3-3OP7EKER.js")).python3Command}),be.push({name:"python",load:async()=>(await import("./chunks/python3-3OP7EKER.js")).pythonCommand}));var nn=[{name:"curl",load:async()=>(await import("./chunks/curl-XLP4VABU.js")).curlCommand}],sn=new Map;function rn(e){return{name:e.name,async execute(t,s){let n=sn.get(e.name);return n||(n=await e.load(),sn.set(e.name,n)),n.execute(t,s)}}}function xr(){return be.map(e=>e.name)}function Lr(){return nn.map(e=>e.name)}function on(e){return(e?be.filter(s=>e.includes(s.name)):be).map(rn)}function an(){return nn.map(rn)}function ln(e){return"load"in e&&typeof e.load=="function"}function Fr(e,t){return{name:e,execute:t}}function cn(e){let t=null;return{name:e.name,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}var Mr=new TextEncoder,Wr=new TextDecoder;function Ee(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)s[n/2]=parseInt(e.slice(n,n+2),16);return s}return t==="binary"||t==="latin1"?Uint8Array.from(e,s=>s.charCodeAt(0)):Mr.encode(e)}function Re(e,t){return t==="base64"?btoa(String.fromCharCode(...e)):t==="hex"?Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join(""):t==="binary"||t==="latin1"?String.fromCharCode(...e):Wr.decode(e)}function le(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var ct=new TextEncoder;function zr(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var $e=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,n]of Object.entries(t))zr(n)?this.writeFileSync(s,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(s,n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,n,r){let i=this.normalizePath(t);this.ensureParentDirs(i);let o=le(n),a=Ee(s,o);this.data.set(i,{type:"file",content:a,mode:r?.mode??420,mtime:r?.mtime??new Date})}async readFile(t,s){let n=await this.readFileBuffer(t),r=le(s);return Re(n,r)}async readFileBuffer(t){let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content instanceof Uint8Array?n.content:ct.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){let r=this.normalizePath(t),i=this.data.get(r);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=le(n),a=Ee(s,o);if(i?.type==="file"){let l=i.content instanceof Uint8Array?i.content:ct.encode(i.content),c=new Uint8Array(l.length+a.length);c.set(l),c.set(a,l.length),this.data.set(r,{type:"file",content:c,mode:i.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=ct.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}async lstat(t){let s=this.resolveIntermediateSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=ct.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}resolveIntermediateSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/");if(n.length<=1)return s;let r="",i=new Set;for(let o=0;o<n.length-1;o++){let a=n[o];r=`${r}/${a}`;let l=this.data.get(r),c=0,f=40;for(;l&&l.type==="symlink"&&c<f;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(r),r=this.resolveSymlink(r,l.target),l=this.data.get(r),c++}if(c>=f)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${r}/${n[n.length-1]}`}resolvePathWithSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/"),r="",i=new Set;for(let o of n){r=`${r}/${o}`;let a=this.data.get(r),l=0,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(r),r=this.resolveSymlink(r,a.target),a=this.data.get(r),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return r}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){let n=this.normalizePath(t);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let r=this.dirname(n);if(r!=="/"&&!this.data.has(r))if(s?.recursive)this.mkdirSync(r,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Set;for(;n&&n.type==="symlink";){if(r.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(s),s=this.resolveSymlink(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==s&&a.startsWith(i)){let c=a.slice(i.length),f=c.split("/")[0];f&&!c.includes("/",f.length)&&!o.has(f)&&o.set(f,{name:f,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,s){let n=this.normalizePath(t),r=this.data.get(n);if(!r){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(r.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(a,s)}}}this.data.delete(n)}async cp(t,s,n){let r=this.normalizePath(t),i=this.normalizePath(s),o=this.data.get(r);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(r);for(let l of a){let c=r==="/"?`/${l}`:`${r}/${l}`,f=i==="/"?`/${l}`:`${i}/${l}`;await this.cp(c,f,n)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}async chmod(t,s){let n=this.normalizePath(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);r.mode=s}async symlink(t,s){let n=this.normalizePath(s);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){let n=this.normalizePath(t),r=this.normalizePath(s),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(r))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(t){let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}async realpath(t){let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,n){let r=this.normalizePath(t),i=this.resolvePathWithSymlinks(r),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=n}};function Vr(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Br(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function jr(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function Hr(e){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Bs}
|
|
1
|
+
import{B as en,C as tn,D as se,E as Ie,F as K,G as ue,H as ft,I as sn,J as I,K as nn,L as rn,M as me,N as Ut,O as ut,P as V,a as Us,b as qs,c as Zs,d as lt,e as Z,f as W,g as he,h as Q,i as pe,j as Ce,k as zt,l as ct,m as Gs,n as Vt,o as Xs,p as oe,q as Ee,r as Ks,s as Ys,t as Bt,u as Ht,v as ke,w as Qs,x as Js,y as fe,z as jt}from"./chunks/chunk-76ZRJPDK.js";import{a as Ne,b as de}from"./chunks/chunk-OJDRYQWQ.js";import{a as re,b as ie,c as te,d as ae,e as Hs,f as z,g as Te,h as it,i as at,j as js,k as ee,l as _e,m as ot,n as ce}from"./chunks/chunk-PSW6BMXW.js";import"./chunks/chunk-NUFRM6SI.js";import{a as ve}from"./chunks/chunk-44UOCSGV.js";import"./chunks/chunk-DXB73IDG.js";var be=[{name:"echo",load:async()=>(await import("./chunks/echo-6S7WE7XB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-GPKR7D6K.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-OAPYPRGV.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-PUJHEPXS.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-SF2UE4KB.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-DU6C7ZEO.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-TDTEBHHI.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-MJFRIDNT.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-NJSENVKC.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-JPBZPM4O.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-Y7YB677N.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-ODWUR7E6.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-S4NVAMC4.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-EM4O3U4P.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-SA7P5NJ7.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-52LRAWXT.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-VDPK3LVS.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-IOLJTP7U.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-NIC6JNLH.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-NIC6JNLH.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-NIC6JNLH.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-SRMB7L6G.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-IV6HLDXU.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-5K7HVGCQ.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-EJUT5LXD.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-XBP4SJA3.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-AXQM7FFF.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-NVKWEAZF.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-QAP6Y75J.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-P43NRVKL.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-FKUV5GH5.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-KWQGFZH5.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-6CFXIPYZ.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-VSTNOVF5.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-I7A2VXFD.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-LRU5XCFP.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-YBTFW7MT.js")).split},{name:"column",load:async()=>(await import("./chunks/column-R6OLMEUA.js")).column},{name:"join",load:async()=>(await import("./chunks/join-X3QYPZUA.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-4KHTWVWB.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-YGMSVGUV.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-CFA5ZIGT.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-YPJLCQYA.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-UFVZH4SS.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-T4JUAAB2.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-M3AXY56V.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-M3AXY56V.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-YGOORMWI.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-YGOORMWI.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-TMBGOQO6.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-4FRA6OJ7.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-CNJ54NE6.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-CNJ54NE6.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-VT2LJIDX.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-BYWM5OPC.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-BYWM5OPC.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-KF5D2PYR.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-2JFR3HGT.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-ELUS3RW7.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-PN3CMG7K.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-AK4QE4WR.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-X3X3N6IE.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-EGF4KTWV.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-5VRIVQYP.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-DG4E7SIS.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-KLHZSRUA.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-WKWTIZGQ.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-IUVNMBTA.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-NQP3CKRV.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-ZK6GQVSL.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-75YOGKM4.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-GF77XMJD.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-2X4JLF4W.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-NWR32CGF.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-YUDAIS32.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-3FPDPLWJ.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-4P4KGYT5.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-4P4KGYT5.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-4P4KGYT5.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(be.push({name:"tar",load:async()=>(await import("./chunks/tar-LWIHPMT6.js")).tarCommand}),be.push({name:"yq",load:async()=>(await import("./chunks/yq-EMWRPC7R.js")).yqCommand}),be.push({name:"xan",load:async()=>(await import("./chunks/xan-RW5GSH6C.js")).xanCommand}),be.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-5QVZOGER.js")).sqlite3Command}),be.push({name:"python3",load:async()=>(await import("./chunks/python3-SKZGHYDO.js")).python3Command}),be.push({name:"python",load:async()=>(await import("./chunks/python3-SKZGHYDO.js")).pythonCommand}));var on=[{name:"curl",load:async()=>(await import("./chunks/curl-QDCXHQMX.js")).curlCommand}],an=new Map;function ln(e){return{name:e.name,async execute(t,s){let n=an.get(e.name);return n||(n=await e.load(),an.set(e.name,n)),n.execute(t,s)}}}function Fr(){return be.map(e=>e.name)}function Mr(){return on.map(e=>e.name)}function cn(e){return(e?be.filter(s=>e.includes(s.name)):be).map(ln)}function fn(){return on.map(ln)}function un(e){return"load"in e&&typeof e.load=="function"}function Wr(e,t){return{name:e,execute:t}}function dn(e){let t=null;return{name:e.name,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}var zr=new TextEncoder,Vr=new TextDecoder;function $e(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)s[n/2]=parseInt(e.slice(n,n+2),16);return s}return t==="binary"||t==="latin1"?Uint8Array.from(e,s=>s.charCodeAt(0)):zr.encode(e)}function Fe(e,t){return t==="base64"?btoa(String.fromCharCode(...e)):t==="hex"?Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join(""):t==="binary"||t==="latin1"?String.fromCharCode(...e):Vr.decode(e)}function le(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var dt=new TextEncoder;function Br(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Se=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,n]of Object.entries(t))Br(n)?this.writeFileSync(s,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(s,n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,n,r){let i=this.normalizePath(t);this.ensureParentDirs(i);let a=le(n),o=$e(s,a);this.data.set(i,{type:"file",content:o,mode:r?.mode??420,mtime:r?.mtime??new Date})}async readFile(t,s){let n=await this.readFileBuffer(t),r=le(s);return Fe(n,r)}async readFileBuffer(t){let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content instanceof Uint8Array?n.content:dt.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){let r=this.normalizePath(t),i=this.data.get(r);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let a=le(n),o=$e(s,a);if(i?.type==="file"){let c=i.content instanceof Uint8Array?i.content:dt.encode(i.content),l=new Uint8Array(c.length+o.length);l.set(c),l.set(o,c.length),this.data.set(r,{type:"file",content:l,mode:i.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=dt.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}async lstat(t){let s=this.resolveIntermediateSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=dt.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}resolveIntermediateSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/");if(n.length<=1)return s;let r="",i=new Set;for(let a=0;a<n.length-1;a++){let o=n[a];r=`${r}/${o}`;let c=this.data.get(r),l=0,f=40;for(;c&&c.type==="symlink"&&l<f;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(r),r=this.resolveSymlink(r,c.target),c=this.data.get(r),l++}if(l>=f)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${r}/${n[n.length-1]}`}resolvePathWithSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/"),r="",i=new Set;for(let a of n){r=`${r}/${a}`;let o=this.data.get(r),c=0,l=40;for(;o&&o.type==="symlink"&&c<l;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(r),r=this.resolveSymlink(r,o.target),o=this.data.get(r),c++}if(c>=l)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return r}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){let n=this.normalizePath(t);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let r=this.dirname(n);if(r!=="/"&&!this.data.has(r))if(s?.recursive)this.mkdirSync(r,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Set;for(;n&&n.type==="symlink";){if(r.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(s),s=this.resolveSymlink(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,a=new Map;for(let[o,c]of this.data.entries())if(o!==s&&o.startsWith(i)){let l=o.slice(i.length),f=l.split("/")[0];f&&!l.includes("/",f.length)&&!a.has(f)&&a.set(f,{name:f,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}return Array.from(a.values()).sort((o,c)=>o.name<c.name?-1:o.name>c.name?1:0)}async rm(t,s){let n=this.normalizePath(t),r=this.data.get(n);if(!r){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(r.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of i){let o=n==="/"?`/${a}`:`${n}/${a}`;await this.rm(o,s)}}}this.data.delete(n)}async cp(t,s,n){let r=this.normalizePath(t),i=this.normalizePath(s),a=this.data.get(r);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(a.type==="file")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(r);for(let c of o){let l=r==="/"?`/${c}`:`${r}/${c}`,f=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(l,f,n)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}async chmod(t,s){let n=this.normalizePath(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);r.mode=s}async symlink(t,s){let n=this.normalizePath(s);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){let n=this.normalizePath(t),r=this.normalizePath(s),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(r))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(t){let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}async realpath(t){let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,n){let r=this.normalizePath(t),i=this.resolvePathWithSymlinks(r),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=n}};function Hr(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function jr(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 Ur(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function qr(e){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Us}
|
|
2
2
|
`),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
|
|
3
|
-
`),e.writeFileSync("/proc/self/status",
|
|
3
|
+
`),e.writeFileSync("/proc/self/status",qs()),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 hn(e,t){Hr(e)&&(jr(e,t),Ur(e),qr(e))}var Zr=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],Gr=["braceexpand","hashall","interactive-comments"];function qt(e){let t=[],s=[...Gr.map(n=>({name:n,enabled:!0})),...Zr.map(n=>({name:n,enabled:e[n]}))].sort((n,r)=>n.name.localeCompare(r.name));for(let n of s)n.enabled&&t.push(n.name);return t.join(":")}function Me(e){e.state.env.set("SHELLOPTS",qt(e.state.options))}var Xr=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Zt(e){let t=[];for(let s of Xr)e[s]&&t.push(s);return t.join(":")}function Gt(e){e.state.env.set("BASHOPTS",Zt(e.state.shoptOptions))}var Kr="BASH_ALIAS_";function pn(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function mn(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function yn(e,t){return e.env.get(`${Kr}${t}`)}function Xt(e,t,s){if(!t.name||!pn(t.name))return t;let n=mn(t.name);if(!n)return t;let r=yn(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new W,a=r,o=r.endsWith(" ");if(!o)for(let u of t.args){let d=wn(u);a+=` ${d}`}let c;try{c=i.parse(a)}catch(u){if(u instanceof lt)throw u;return t}if(c.statements.length!==1||c.statements[0].pipelines.length!==1||c.statements[0].pipelines[0].commands.length!==1)return gn(t,r);let l=c.statements[0].pipelines[0].commands[0];if(l.type!=="SimpleCommand")return gn(t,r);let f={...l,assignments:[...t.assignments,...l.assignments],redirections:[...l.redirections,...t.redirections],line:t.line};if(o&&t.args.length>0&&(f={...f,args:[...f.args,...t.args]},f.args.length>0)){let u=f.args[0];if(pn(u)){let d=mn(u);if(d&&yn(e,d)){let h={type:"SimpleCommand",name:u,args:f.args.slice(1),assignments:[],redirections:[]},m=Xt(e,h,s);m!==h&&(f={...f,name:m.name,args:[...m.args]})}}}return f}catch(i){throw s.delete(n),i}}function gn(e,t){let s=t;for(let a of e.args){let o=wn(a);s+=` ${o}`}let n=new W,r=n.parseWordFromString("eval",!1,!1),i=n.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:r,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function wn(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${s.value}'`;break;case"DoubleQuoted":t+=`"${s.parts.map(n=>n.type==="Literal"?n.value:`$${n.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${s.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${s.expression}))`;break;case"Glob":t+=s.pattern;break;default:break}return t}async function vn(e,t){let s=t.parts.map(f=>f.type==="Literal"?f.value:"\0").join(""),n=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!n||!s.endsWith(")"))return null;let r=n[1],i=[],a=!1,o="",c=!1;for(let f of t.parts)if(f.type==="Literal"){let u=f.value;if(!a){let d=u.indexOf("=(");d!==-1&&(a=!0,u=u.slice(d+2))}if(a){u.endsWith(")")&&(u=u.slice(0,-1));let d=u.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(o||c)&&(i.push(o),o="",c=!1):h&&(o+=h)}}else if(a)if(f.type==="BraceExpansion")if(/^\[.+\]=/.test(o))o+=ct({type:"Word",parts:[f]});else{(o||c)&&(i.push(o),o="",c=!1);let d=await me(e,{type:"Word",parts:[f]});i.push(...d.values)}else{(f.type==="SingleQuoted"||f.type==="DoubleQuoted"||f.type==="Escaped")&&(c=!0);let u=await I(e,{type:"Word",parts:[f]});o+=u}(o||c)&&i.push(o);let l=i.map(f=>/^\[.+\]=/.test(f)?f:f===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(f)&&!f.startsWith("'")&&!f.startsWith('"')?`'${f.replace(/'/g,"'\\''")}'`:f);return`${r}=(${l.join(" ")})`}async function En(e,t){let s=-1,n=-1,r=!1;for(let p=0;p<t.parts.length;p++){let g=t.parts[p];if(g.type==="Literal"){let v=g.value.indexOf("+=");if(v!==-1){let C=g.value.slice(0,v);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(C)){s=p,n=v,r=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(C)){s=p,n=v,r=!0;break}}let $=g.value.indexOf("=");if($!==-1&&($===0||g.value[$-1]!=="+")){let C=g.value.slice(0,$);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(C)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(C)){s=p,n=$;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),a=t.parts[s];if(a.type!=="Literal")return null;let o=r?2:1,c=a.value.slice(0,n),l=a.value.slice(n+o),f=t.parts.slice(s+1),u="";for(let p of i)u+=await I(e,{type:"Word",parts:[p]});u+=c;let d={type:"Word",parts:l!==""?[{type:"Literal",value:l},...f]:f},h=d.parts.length>0?await I(e,d):"";return`${u}${r?"+=":"="}${h}`}var Yr=["tar","yq","xan","sqlite3","python3","python"];function bn(e){return Yr.includes(e)}var L=Object.freeze({stdout:"",stderr:"",exitCode:0});function F(e=""){return{stdout:e,stderr:"",exitCode:0}}function S(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function P(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function q(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function Ae(e,t,s="",n=""){throw new ee(e,t,s,n)}function Kt(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new _e;return L}if(t.length>1)throw new z(1,"",`bash: break: too many arguments
|
|
4
4
|
`);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new z(128,"",`bash: break: ${t[0]}: numeric argument required
|
|
5
|
-
`);s=n}throw new re(s)}async function
|
|
5
|
+
`);s=n}throw new re(s)}async function Yt(e,t){let s,n=!1,r=!1,i=0;for(;i<t.length;)if(t[i]==="--"){i++;break}else if(t[i]==="-L")r=!1,i++;else if(t[i]==="-P")r=!0,i++;else if(t[i].startsWith("-")&&t[i]!=="-")i++;else break;let a=t.slice(i);if(a.length===0||a[0]==="~"?s=e.state.env.get("HOME")||"/":a[0]==="-"?(s=e.state.previousDir,n=!0):s=a[0],!s.startsWith("/")&&!s.startsWith("./")&&!s.startsWith("../")&&s!=="."&&s!==".."){let u=e.state.env.get("CDPATH");if(u){let d=u.split(":").filter(h=>h);for(let h of d){let m=h.startsWith("/")?`${h}/${s}`:`${e.state.cwd}/${h}/${s}`;try{if((await e.fs.stat(m)).isDirectory){s=m,n=!0;break}}catch{}}}}let c=(s.startsWith("/")?s:`${e.state.cwd}/${s}`).split("/").filter(u=>u&&u!=="."),l="";for(let u of c)if(u==="..")l=l.split("/").slice(0,-1).join("/")||"/";else{l=l?`${l}/${u}`:`/${u}`;try{if(!(await e.fs.stat(l)).isDirectory)return S(`bash: cd: ${s}: Not a directory
|
|
6
6
|
`)}catch{return S(`bash: cd: ${s}: No such file or directory
|
|
7
|
-
`)}}let f=
|
|
8
|
-
`:"")}function
|
|
9
|
-
`,!1;if(
|
|
10
|
-
`,!1}return`${n}_${
|
|
11
|
-
`,2):
|
|
12
|
-
`,2):P("","",1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(
|
|
13
|
-
`,2):q(s.value)}async function
|
|
14
|
-
`)&&!n&&!r){
|
|
7
|
+
`)}}let f=l||"/";if(r)try{f=await e.fs.realpath(f)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=f,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),F(n?`${f}
|
|
8
|
+
`:"")}function Qt(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Qr=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function ht(e){return Qr.includes(e)}async function pt(e,t,s){let n=Qt(e,s);switch(t){case"-e":case"-a":return e.fs.exists(n);case"-f":return await e.fs.exists(n)?(await e.fs.stat(n)).isFile:!1;case"-d":return await e.fs.exists(n)?(await e.fs.stat(n)).isDirectory:!1;case"-r":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&256)!==0:!1;case"-w":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&128)!==0:!1;case"-x":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&64)!==0:!1;case"-s":return await e.fs.exists(n)?(await e.fs.stat(n)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(n)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&512)!==0:!1;case"-g":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(n);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].some(i=>n===i||n.endsWith(i));case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(n);default:return!1}}var Jr=["-nt","-ot","-ef"];function mt(e){return Jr.includes(e)}async function yt(e,t,s,n){let r=Qt(e,s),i=Qt(e,n);switch(t){case"-nt":try{let a=await e.fs.stat(r),o=await e.fs.stat(i);return a.mtime>o.mtime}catch{return!1}case"-ot":try{let a=await e.fs.stat(r),o=await e.fs.stat(i);return a.mtime<o.mtime}catch{return!1}case"-ef":try{if(!await e.fs.exists(r)||!await e.fs.exists(i))return!1;let a=e.fs.resolvePath(e.state.cwd,r),o=e.fs.resolvePath(e.state.cwd,i);return a===o}catch{return!1}default:return!1}}var ei=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function gt(e){return ei.has(e)}function wt(e,t,s){switch(e){case"-eq":return t===s;case"-ne":return t!==s;case"-lt":return t<s;case"-le":return t<=s;case"-gt":return t>s;case"-ge":return t>=s}}function Ke(e){return e==="="||e==="=="||e==="!="}function vt(e,t,s,n=!1,r=!1,i=!1){if(n){let o=We(t,s,r,i);return e==="!="?!o:o}if(r){let o=t.toLowerCase()===s.toLowerCase();return e==="!="?!o:o}let a=t===s;return e==="!="?!a:a}var ti=new Set(["-z","-n"]);function Et(e){return ti.has(e)}function bt(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function $t(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],r=s[2];if(e.state.associativeArrays?.has(n)){let o=r;return(o.startsWith("'")&&o.endsWith("'")||o.startsWith('"')&&o.endsWith('"'))&&(o=o.slice(1,-1)),o=o.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(c,l)=>e.state.env.get(l)||""),e.state.env.has(`${n}_${o}`)}let a;try{let o=new W,c=Z(o,r);a=await V(e,c.expression)}catch{if(/^-?\d+$/.test(r))a=Number.parseInt(r,10);else{let o=e.state.env.get(r);a=o?Number.parseInt(o,10):0}}if(a<0){let o=Q(e,n),c=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${c}: ${n}: bad array subscript
|
|
9
|
+
`,!1;if(a=Math.max(...o)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${c}: ${n}: bad array subscript
|
|
10
|
+
`,!1}return e.state.env.has(`${n}_${a}`)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?Ce(e,t).length>0:Q(e,t).length>0}async function Oe(e,t){switch(t.type){case"CondBinary":{let s=await I(e,t.left),n=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),r;if(t.operator==="=~")if(n){let i=await I(e,t.right);r=tn(i)}else r=await nn(e,t.right);else Ke(t.operator)&&!n?r=await rn(e,t.right):r=await I(e,t.right);if(Ke(t.operator)){let i=e.state.shoptOptions.nocasematch;return vt(t.operator,s,r,!n,i,!0)}if(gt(t.operator))return wt(t.operator,await Sn(e,s),await Sn(e,r));if(mt(t.operator))return yt(e,t.operator,s,r);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=ii(r),o=new RegExp(a,i?"i":""),c=s.match(o);if(pe(e,"BASH_REMATCH"),c)for(let l=0;l<c.length;l++)e.state.env.set(`BASH_REMATCH_${l}`,c[l]||"");return c!==null}catch{throw new Error("syntax error in regular expression")}case"<":return s<r;case">":return s>r;default:return!1}}case"CondUnary":{let s=await I(e,t.operand);return ht(t.operator)?pt(e,t.operator,s):Et(t.operator)?bt(t.operator,s):t.operator==="-v"?await $t(e,s):t.operator==="-o"?es(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await I(e,t.operand.expression.word)})`!=="":!await Oe(e,t.operand);case"CondAnd":return await Oe(e,t.left)?await Oe(e,t.right):!1;case"CondOr":return await Oe(e,t.left)?!0:await Oe(e,t.right);case"CondGroup":return await Oe(e,t.expression);case"CondWord":return await I(e,t.word)!=="";default:return!1}}async function Ye(e,t){if(t.length===0)return P("","",1);if(t.length===1)return q(!!t[0]);if(t.length===2){let n=t[0],r=t[1];return n==="("?S(`test: '(' without matching ')'
|
|
11
|
+
`,2):ht(n)?q(await pt(e,n,r)):Et(n)?q(bt(n,r)):n==="!"?q(!r):n==="-v"?q(await $t(e,r)):n==="-o"?q(es(e,r)):n==="="||n==="=="||n==="!="||n==="<"||n===">"||n==="-eq"||n==="-ne"||n==="-lt"||n==="-le"||n==="-gt"||n==="-ge"||n==="-nt"||n==="-ot"||n==="-ef"?S(`test: ${n}: unary operator expected
|
|
12
|
+
`,2):P("","",1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(Ke(r))return q(vt(r,n,i));if(gt(r)){let a=St(n),o=St(i);return!a.valid||!o.valid?P("","",2):q(wt(r,a.value,o.value))}if(mt(r))return q(await yt(e,r,n,i));switch(r){case"-a":return q(n!==""&&i!=="");case"-o":return q(n!==""||i!=="");case">":return q(n>i);case"<":return q(n<i)}if(n==="!"){let a=await Ye(e,[r,i]);return P("",a.stderr,a.exitCode===0?1:a.exitCode===1?0:a.exitCode)}if(n==="("&&i===")")return q(r!=="")}if(t.length===4){if(t[0]==="!"){let n=await Ye(e,t.slice(1));return P("",n.stderr,n.exitCode===0?1:n.exitCode===1?0:n.exitCode)}if(t[0]==="("&&t[3]===")")return Ye(e,[t[1],t[2]])}let s=await Pn(e,t,0);return s.pos<t.length?S(`test: too many arguments
|
|
13
|
+
`,2):q(s.value)}async function Pn(e,t,s){return si(e,t,s)}async function si(e,t,s){let{value:n,pos:r}=await $n(e,t,s);for(;t[r]==="-o";){let i=await $n(e,t,r+1);n=n||i.value,r=i.pos}return{value:n,pos:r}}async function $n(e,t,s){let{value:n,pos:r}=await Jt(e,t,s);for(;t[r]==="-a";){let i=await Jt(e,t,r+1);n=n&&i.value,r=i.pos}return{value:n,pos:r}}async function Jt(e,t,s){if(t[s]==="!"){let{value:n,pos:r}=await Jt(e,t,s+1);return{value:!n,pos:r}}return ni(e,t,s)}async function ni(e,t,s){let n=t[s];if(n==="("){let{value:i,pos:a}=await Pn(e,t,s+1);return{value:i,pos:t[a]===")"?a+1:a}}let r=t[s+1];if(Ke(r)){let i=n,a=t[s+2]??"";return{value:vt(r,i,a),pos:s+3}}if(gt(r)){let i=St(n),a=St(t[s+2]??"0");return!i.valid||!a.valid?{value:!1,pos:s+3}:{value:wt(r,i.value,a.value),pos:s+3}}if(mt(r)){let i=n,a=t[s+2]??"";return{value:await yt(e,r,i,a),pos:s+3}}if(ht(n)){let i=t[s+1]??"";return{value:await pt(e,n,i),pos:s+2}}if(Et(n)){let i=t[s+1]??"";return{value:bt(n,i),pos:s+2}}if(n==="-v"){let i=t[s+1]??"";return{value:await $t(e,i),pos:s+2}}if(n==="-o"){let i=t[s+1]??"";return{value:es(e,i),pos:s+2}}return{value:n!==void 0&&n!=="",pos:s+1}}function We(e,t,s=!1,n=!1){let r=`^${_n(t,n)}$`,i=s?"is":"s";return new RegExp(r,i).test(e)}function _n(e,t){let s="";for(let n=0;n<e.length;n++){let r=e[n];if(t&&(r==="@"||r==="*"||r==="+"||r==="?"||r==="!")&&n+1<e.length&&e[n+1]==="("){let i=Nn(e,n+1);if(i!==-1){let a=e.slice(n+2,i),o=Cn(a),c=o.map(f=>_n(f,t)),l=c.length>0?c.join("|"):"(?:)";if(r==="@")s+=`(?:${l})`;else if(r==="*")s+=`(?:${l})*`;else if(r==="+")s+=`(?:${l})+`;else if(r==="?")s+=`(?:${l})?`;else if(r==="!")if(i<e.length-1){let u=o.map(h=>kn(h,t));if(u.every(h=>h!==null)&&u.every(h=>h===u[0])&&u[0]!==null){let h=u[0];if(h===0)s+="(?:.+)";else{let m=[];h>0&&m.push(`.{0,${h-1}}`),m.push(`.{${h+1},}`),m.push(`(?!(?:${l})).{${h}}`),s+=`(?:${m.join("|")})`}}else s+=`(?:(?!(?:${l})).)*?`}else s+=`(?!(?:${l})$).*`;n=i;continue}}if(r==="\\")if(n+1<e.length){let i=e[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,n++}else s+="\\\\";else if(r==="*")s+=".*";else if(r==="?")s+=".";else if(r==="["){let i=e.indexOf("]",n+1);i!==-1?(s+=e.slice(n,i+1),n=i):s+="\\["}else/[\\^$.|+(){}]/.test(r)?s+=`\\${r}`:s+=r}return s}function Nn(e,t){let s=1,n=t+1;for(;n<e.length&&s>0;){let r=e[n];if(r==="\\"){n+=2;continue}if(r==="(")s++;else if(r===")"&&(s--,s===0))return n;n++}return-1}function Cn(e){let t=[],s="",n=0,r=0;for(;r<e.length;){let i=e[r];if(i==="\\"){s+=i,r+1<e.length?(s+=e[r+1],r+=2):r++;continue}i==="("?(n++,s+=i):i===")"?(n--,s+=i):i==="|"&&n===0?(t.push(s),s=""):s+=i,r++}return t.push(s),t}function kn(e,t){let s=0,n=0;for(;n<e.length;){let r=e[n];if(t&&(r==="@"||r==="*"||r==="+"||r==="?"||r==="!")&&n+1<e.length&&e[n+1]==="("){let i=Nn(e,n+1);if(i!==-1){if(r==="@"){let a=e.slice(n+2,i),c=Cn(a).map(l=>kn(l,t));if(c.every(l=>l!==null)&&c.every(l=>l===c[0])){s+=c[0],n=i+1;continue}return null}return null}}if(r==="*")return null;if(r==="?"){s+=1,n++;continue}if(r==="["){let i=e.indexOf("]",n+1);if(i!==-1){s+=1,n=i+1;continue}s+=1,n++;continue}if(r==="\\"){s+=1,n+=2;continue}s+=1,n++}return s}function es(e,t){let n=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 n?n():!1}async function Sn(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 An(t);try{let s=new W,n=Z(s,t);return await V(e,n.expression)}catch{return An(t)}}function ri(e,t){let s=0;for(let n of e){let r;if(n>="0"&&n<="9")r=n.charCodeAt(0)-48;else if(n>="a"&&n<="z")r=n.charCodeAt(0)-97+10;else if(n>="A"&&n<="Z")r=n.charCodeAt(0)-65+36;else if(n==="@")r=62;else if(n==="_")r=63;else return Number.NaN;if(r>=t)return Number.NaN;s=s*t+r}return s}function An(e){if(e=e.trim(),e==="")return 0;let t=!1;e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1));let s,n=e.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(n){let r=Number.parseInt(n[1],10);r>=2&&r<=64?s=ri(n[2],r):s=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?s=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?s=Number.parseInt(e,8):s=Number.parseInt(e,10);return Number.isNaN(s)&&(s=0),t?-s:s}function St(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let s=Number.parseInt(e,10);return Number.isNaN(s)?{value:0,valid:!1}:{value:t?-s:s,valid:!0}}function ii(e){let t="",s=0;for(;s<e.length;)if(e[s]==="\\"&&s+1<e.length)t+=e[s]+e[s+1],s+=2;else if(e[s]==="["){let n=ai(e,s);t+=n.converted,s=n.endIndex}else t+=e[s],s++;return t}function ai(e,t){let s=t+1,n="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(n+="^",s++);let r=!1;s<e.length&&e[s]==="]"&&(r=!0,s++);let i=!1;s<e.length&&e[s]==="["&&s+1<e.length&&e[s+1]!==":"&&(i=!0,s++);let a="",o=!1;for(;s<e.length;){let c=e[s];if(c==="]"){o=!0,s++;break}if(c==="["&&s+1<e.length&&e[s+1]===":"){let l=e.indexOf(":]",s+2);if(l!==-1){let f=e.slice(s+2,l);a+=oi(f),s=l+2;continue}}if(c==="["&&s+1<e.length){let l=e[s+1];if(l==="."||l==="="){let f=`${l}]`,u=e.indexOf(f,s+2);if(u!==-1){let d=e.slice(s+2,u);a+=d,s=u+2;continue}}}if(c==="\\"&&s+1<e.length){a+=c+e[s+1],s+=2;continue}a+=c,s++}return o?(r&&(n+="\\]"),i&&(n+="\\["),n+=a,n+="]",{converted:n,endIndex:s}):{converted:"\\[",endIndex:t+1}}function oi(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 ye(e){let t=[],s="",n=!1,r=!1,i=!1,a=!1;for(let o of e){if(i){s+=o,i=!1,a=!0;continue}if(o==="\\"){i=!0;continue}if(o==="'"&&!r){n||(a=!0),n=!n;continue}if(o==='"'&&!n){r||(a=!0),r=!r;continue}if((o===" "||o===" "||o===`
|
|
14
|
+
`)&&!n&&!r){a&&(t.push(s),s="",a=!1);continue}s+=o,a=!0}return a&&t.push(s),t}function At(e){let t=[],s=0;for(;s<e.length;){for(;s<e.length&&/\s/.test(e[s]);)s++;if(s>=e.length)break;if(e[s]!=="["){s++;continue}s++;let n="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)n+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&e[s]!=="]"&&e[s]!=="=";)n+=e[s],s++;for(;s<e.length&&e[s]!=="]";)s++;if(e[s]==="]"&&s++,e[s]!=="=")continue;s++;let r="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)e[s]==="\\"&&s+1<e.length&&s++,r+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&!/\s/.test(e[s]);)r+=e[s],s++;t.push([n,r])}return t}function On(e){let t=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(t)return{name:t[1],isArray:!0,arrayElements:ye(t[2])};let s=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(s)return{name:s[1],isArray:!1,arrayIndex:s[2],value:s[3]};if(e.includes("=")){let n=e.indexOf("=");return{name:e.slice(0,n),isArray:!1,value:e.slice(n+1)}}return{name:e,isArray:!1}}async function li(e,t){try{let s=new W,n=Z(s,t);return await V(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}async function Dn(e,t,s={}){let{name:n,isArray:r,arrayElements:i,value:a,arrayIndex:o}=t,{makeReadonly:c=!1,checkReadonly:l=!0}=s;if(l){let f=K(e,n);if(f)return f}if(r&&i){for(let f=0;f<i.length;f++)e.state.env.set(`${n}_${f}`,i[f]);e.state.env.set(`${n}__length`,String(i.length))}else if(o!==void 0&&a!==void 0){let f=await li(e,o);e.state.env.set(`${n}_${f}`,a);let u=parseInt(e.state.env.get(`${n}__length`)??"0",10);f>=u&&e.state.env.set(`${n}__length`,String(f+1))}else a!==void 0&&e.state.env.set(n,a);return c&&se(e,n),null}function De(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function ze(e,t){return e.state.localVarDepth?.get(t)}function Pt(e,t){e.state.localVarDepth?.delete(t)}function Tn(e,t,s){e.state.localVarStack=e.state.localVarStack||new Map;let n=e.state.localVarStack.get(t)||[];n.push({value:s,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,n)}function _t(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function In(e,t){if(e.state.localVarStack)for(let[s,n]of e.state.localVarStack.entries()){for(;n.length>0&&n[n.length-1].scopeIndex===t;)n.pop();n.length===0&&e.state.localVarStack.delete(s)}}var ts=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Rn(e){return ts.has(e)}var ss=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Qe=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);async function Re(e,t,s,n){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory
|
|
15
15
|
`;if(n.checkNoclobber&&e.state.options.noclobber&&!n.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file
|
|
16
|
-
`}catch{}return null}function Y(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return"utf8";return"binary"}function
|
|
17
|
-
`};s.set(n,await
|
|
18
|
-
`);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,r),
|
|
19
|
-
`,1)}}}return null}async function
|
|
20
|
-
`,1);if(e.state.options.noclobber&&!o
|
|
16
|
+
`}catch{}return null}function Y(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return"utf8";return"binary"}function ci(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),a=r+n+1,o=t.slice(a),c=o.indexOf(":");if(c===-1)return null;let l=Number.parseInt(o.slice(0,c),10);if(Number.isNaN(l)||l<0)return null;let f=o.slice(c+1);return{path:i,position:l,content:f}}async function xn(e,t){let s=new Map;for(let n=0;n<t.length;n++){let r=t[n];if(r.target.type==="HereDoc")continue;if(r.operator===">&"||r.operator==="<&"){if(Ut(e,r.target))return{targets:s,error:`bash: $@: ambiguous redirect
|
|
17
|
+
`};s.set(n,await I(e,r.target))}else{let a=await ut(e,r.target);if("error"in a)return{targets:s,error:a.error};s.set(n,a.target)}}return{targets:s}}function fi(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd;return e.state.nextFd++,t}async function Nt(e,t){for(let s of t){if(!s.fdVariable)continue;if(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),(s.operator===">&"||s.operator==="<&")&&s.target.type==="Word"&&await I(e,s.target)==="-"){let i=e.state.env.get(s.fdVariable);if(i!==void 0){let a=Number.parseInt(i,10);Number.isNaN(a)||e.state.fileDescriptors.delete(a)}continue}let n=fi(e);if(e.state.env.set(s.fdVariable,String(n)),s.target.type==="Word"){let r=await I(e,s.target);if(s.operator===">&"||s.operator==="<&"){let i=Number.parseInt(r,10);if(!Number.isNaN(i)){let a=e.state.fileDescriptors.get(i);a!==void 0&&e.state.fileDescriptors.set(n,a);continue}}if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let i=e.fs.resolvePath(e.state.cwd,r);(s.operator===">"||s.operator===">|"||s.operator==="&>")&&await e.fs.writeFile(i,"","binary"),e.state.fileDescriptors.set(n,`__file__:${i}`)}else if(s.operator==="<<<")e.state.fileDescriptors.set(n,`${r}
|
|
18
|
+
`);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,r),a=await e.fs.readFile(i);e.state.fileDescriptors.set(n,a)}catch{return P("",`bash: ${r}: No such file or directory
|
|
19
|
+
`,1)}}}return null}async function ge(e,t){for(let s of t){if(s.target.type==="HereDoc")continue;let n=s.operator===">&";if(s.operator!==">"&&s.operator!==">|"&&s.operator!=="&>"&&!n)continue;let r;if(n){if(r=await I(e,s.target),r==="-"||!Number.isNaN(Number.parseInt(r,10))||s.fd!=null)continue}else{let o=await ut(e,s.target);if("error"in o)return P("",o.error,1);r=o.target}let i=e.fs.resolvePath(e.state.cwd,r),a=s.operator===">|";try{let o=await e.fs.stat(i);if(o.isDirectory)return P("",`bash: ${r}: Is a directory
|
|
20
|
+
`,1);if(e.state.options.noclobber&&!a&&!o.isDirectory&&r!=="/dev/null")return P("",`bash: ${r}: cannot overwrite existing file
|
|
21
21
|
`,1)}catch{}if(r!=="/dev/null"&&r!=="/dev/stdout"&&r!=="/dev/stderr"&&r!=="/dev/full"&&await e.fs.writeFile(i,"","binary"),r==="/dev/full")return P("",`bash: /dev/full: No space left on device
|
|
22
|
-
`,1)}return null}async function
|
|
23
|
-
`,
|
|
24
|
-
`,
|
|
25
|
-
`,
|
|
26
|
-
`,
|
|
27
|
-
`,
|
|
28
|
-
`,
|
|
29
|
-
`,
|
|
30
|
-
`,
|
|
31
|
-
`,
|
|
32
|
-
`,
|
|
33
|
-
`;throw new z(2,"",n)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),L}async function
|
|
34
|
-
`).map(
|
|
35
|
-
`)),(n.fd??0)===0&&(s=i)}else if(n.operator==="<<<"&&n.target.type==="Word")s=`${await
|
|
36
|
-
`;else if(n.operator==="<"&&n.target.type==="Word"){let r=await
|
|
37
|
-
`,2);let
|
|
38
|
-
`,2);s.push(
|
|
39
|
-
`,2);n=t[y]}else if(
|
|
40
|
-
`,2);r=t[y]}else if(
|
|
41
|
-
`,2);i=t[y]}else if(
|
|
42
|
-
`,2);let
|
|
43
|
-
`,2)}else if(
|
|
44
|
-
`,2);u=t[y]}else if(
|
|
45
|
-
`,2);d=t[y]}else if(
|
|
46
|
-
`,2);f=t[y]}else if(
|
|
47
|
-
`,2)}else if(
|
|
48
|
-
`);for(let _ of
|
|
49
|
-
`,2);throw y}let
|
|
50
|
-
`),C=
|
|
51
|
-
`:"");return F(C)}function
|
|
52
|
-
`;if(s.length===0)return[t];let n=new Set(s.split("")),r=[],i="",
|
|
22
|
+
`,1)}return null}async function H(e,t,s,n){let{stdout:r,stderr:i,exitCode:a}=t;for(let l=0;l<s.length;l++){let f=s[l];if(f.target.type==="HereDoc")continue;let u,d=n?.get(l);if(d!==void 0)u=d;else if(f.operator===">&"||f.operator==="<&"){if(Ut(e,f.target)){i+=`bash: $@: ambiguous redirect
|
|
23
|
+
`,a=1,r="";continue}u=await I(e,f.target)}else{let m=await ut(e,f.target);if("error"in m){i+=m.error,a=1,r="";continue}u=m.target}if(!f.fdVariable)switch(f.operator){case">":case">|":{let h=f.fd??1,m=f.operator===">|";if(h===1){if(u==="/dev/stdout")break;if(u==="/dev/stderr"){i+=r,r="";break}if(u==="/dev/full"){i+=`bash: echo: write error: No space left on device
|
|
24
|
+
`,a=1,r="";break}let p=e.fs.resolvePath(e.state.cwd,u),g=await Re(e,p,u,{checkNoclobber:!0,isClobber:m});if(g){i+=g,a=1,r="";break}await e.fs.writeFile(p,r,Y(r)),r=""}else if(h===2){if(u==="/dev/stderr")break;if(u==="/dev/stdout"){r+=i,i="";break}if(u==="/dev/full"){i+=`bash: echo: write error: No space left on device
|
|
25
|
+
`,a=1;break}if(u==="/dev/null")i="";else{let p=e.fs.resolvePath(e.state.cwd,u),g=await Re(e,p,u,{checkNoclobber:!0,isClobber:m});if(g){i+=g,a=1;break}await e.fs.writeFile(p,i,Y(i)),i=""}}break}case">>":{let h=f.fd??1;if(h===1){if(u==="/dev/stdout")break;if(u==="/dev/stderr"){i+=r,r="";break}if(u==="/dev/full"){i+=`bash: echo: write error: No space left on device
|
|
26
|
+
`,a=1,r="";break}let m=e.fs.resolvePath(e.state.cwd,u),p=await Re(e,m,u,{});if(p){i+=p,a=1,r="";break}await e.fs.appendFile(m,r,Y(r)),r=""}else if(h===2){if(u==="/dev/stderr")break;if(u==="/dev/stdout"){r+=i,i="";break}if(u==="/dev/full"){i+=`bash: echo: write error: No space left on device
|
|
27
|
+
`,a=1;break}let m=e.fs.resolvePath(e.state.cwd,u),p=await Re(e,m,u,{});if(p){i+=p,a=1;break}await e.fs.appendFile(m,i,Y(i)),i=""}break}case">&":case"<&":{let h=f.fd??1;if(u==="-")break;if(u.endsWith("-")){let m=u.slice(0,-1),p=Number.parseInt(m,10);if(!Number.isNaN(p)){let g=e.state.fileDescriptors?.get(p);g!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,g),p>=3&&e.state.fileDescriptors?.delete(p)):p===1||p===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,`__dupout__:${p}`)):p===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,`__dupin__:${p}`)):p>=3&&(i+=`bash: ${p}: Bad file descriptor
|
|
28
|
+
`,a=1)}break}if(u==="2"||u==="&2")h===1&&(i+=r,r="");else if(u==="1"||u==="&1")r+=i,i="";else{let m=Number.parseInt(u,10);if(Number.isNaN(m)){if(f.operator===">&"){let p=e.fs.resolvePath(e.state.cwd,u),g=await Re(e,p,u,{checkNoclobber:!0});if(g){i=g,a=1,r="";break}if(f.fd==null){let v=r+i;await e.fs.writeFile(p,v,Y(v)),r="",i=""}else h===1?(await e.fs.writeFile(p,r,Y(r)),r=""):h===2&&(await e.fs.writeFile(p,i,Y(i)),i="")}}else{let p=e.state.fileDescriptors?.get(m);if(p?.startsWith("__file__:")){let g=p.slice(9);h===1?(await e.fs.appendFile(g,r,Y(r)),r=""):h===2&&(await e.fs.appendFile(g,i,Y(i)),i="")}else if(p?.startsWith("__rw__:")){let g=ci(p);g&&(h===1?(await e.fs.appendFile(g.path,r,Y(r)),r=""):h===2&&(await e.fs.appendFile(g.path,i,Y(i)),i=""))}else if(p?.startsWith("__dupout__:")){let g=Number.parseInt(p.slice(11),10);if(g!==1)if(g===2)h===1&&(i+=r,r="");else{let v=e.state.fileDescriptors?.get(g);if(v?.startsWith("__file__:")){let $=v.slice(9);h===1?(await e.fs.appendFile($,r,Y(r)),r=""):h===2&&(await e.fs.appendFile($,i,Y(i)),i="")}}}else p?.startsWith("__dupin__:")?(i+=`bash: ${m}: Bad file descriptor
|
|
29
|
+
`,a=1,r=""):m>=3&&(i+=`bash: ${m}: Bad file descriptor
|
|
30
|
+
`,a=1,r="")}}break}case"&>":{if(u==="/dev/full"){i=`bash: echo: write error: No space left on device
|
|
31
|
+
`,a=1,r="";break}let h=e.fs.resolvePath(e.state.cwd,u),m=await Re(e,h,u,{checkNoclobber:!0});if(m){i=m,a=1,r="";break}let p=r+i;await e.fs.writeFile(h,p,Y(p)),r="",i="";break}case"&>>":{if(u==="/dev/full"){i=`bash: echo: write error: No space left on device
|
|
32
|
+
`,a=1,r="";break}let h=e.fs.resolvePath(e.state.cwd,u),m=await Re(e,h,u,{});if(m){i=m,a=1,r="";break}let p=r+i;await e.fs.appendFile(h,p,Y(p)),r="",i="";break}}}let o=e.state.fileDescriptors?.get(1);if(o){if(o==="__dupout__:2")i+=r,r="";else if(o.startsWith("__file__:")){let l=o.slice(9);await e.fs.appendFile(l,r,Y(r)),r=""}else if(o.startsWith("__file_append__:")){let l=o.slice(16);await e.fs.appendFile(l,r,Y(r)),r=""}}let c=e.state.fileDescriptors?.get(2);if(c){if(c==="__dupout__:1")r+=i,i="";else if(c.startsWith("__file__:")){let l=c.slice(9);await e.fs.appendFile(l,i,Y(i)),i=""}else if(c.startsWith("__file_append__:")){let l=c.slice(16);await e.fs.appendFile(l,i,Y(i)),i=""}}return P(r,i,a)}function Ln(e,t){if(e.state.options.posix&&ts.has(t.name)){let n=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
|
|
33
|
+
`;throw new z(2,"",n)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),L}async function ui(e,t){let s="";for(let n of t)if((n.operator==="<<"||n.operator==="<<-")&&n.target.type==="HereDoc"){let r=n.target,i=await I(e,r.content);r.stripTabs&&(i=i.split(`
|
|
34
|
+
`).map(o=>o.replace(/^\t+/,"")).join(`
|
|
35
|
+
`)),(n.fd??0)===0&&(s=i)}else if(n.operator==="<<<"&&n.target.type==="Word")s=`${await I(e,n.target)}
|
|
36
|
+
`;else if(n.operator==="<"&&n.target.type==="Word"){let r=await I(e,n.target),i=e.fs.resolvePath(e.state.cwd,r);try{s=await e.fs.readFile(i)}catch{}}return s}async function Ct(e,t,s,n="",r){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,Ae(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(r??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i=new Map;for(let l=0;l<s.length;l++)i.set(String(l+1),e.state.env.get(String(l+1))),e.state.env.set(String(l+1),s[l]);i.set("@",e.state.env.get("@")),i.set("#",e.state.env.get("#")),e.state.env.set("@",s.join(" ")),e.state.env.set("#",String(s.length));let a=()=>{let l=e.state.localScopes.length-1,f=e.state.localScopes.pop();if(f)for(let[u,d]of f)d===void 0?e.state.env.delete(u):e.state.env.set(u,d);if(In(e,l),e.state.fullyUnsetLocals)for(let[u,d]of e.state.fullyUnsetLocals.entries())d===l&&e.state.fullyUnsetLocals.delete(u);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let u=e.state.localExportedVars.pop();if(u)for(let d of u)e.state.exportedVars?.delete(d)}for(let[u,d]of i)d===void 0?e.state.env.delete(u):e.state.env.set(u,d);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},{targets:o,error:c}=await xn(e,t.redirections);if(c)return a(),P("",c,1);try{let l=await ui(e,t.redirections),f=n||l,u=await e.executeCommand(t.body,f);return a(),H(e,u,t.redirections,o)}catch(l){if(a(),l instanceof te){let f=P(l.stdout,l.stderr,l.exitCode);return H(e,f,t.redirections,o)}throw l}}var Mn=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],rs=[".",":","[","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"],di=["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"],hi=rs;async function is(e,t){let s=[],n=null,r="",i="",a=null,o=!1,c=!1,l=!1,f=null,u=null,d=null,h=[],m=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let y=0;y<t.length;y++){let w=t[y];if(w==="-v")s.push("variable");else if(w==="-e")s.push("export");else if(w==="-f")s.push("file");else if(w==="-d")s.push("directory");else if(w==="-k")s.push("keyword");else if(w==="-A"){if(y++,y>=t.length)return S(`compgen: -A: option requires an argument
|
|
37
|
+
`,2);let E=t[y];if(!m.includes(E))return S(`compgen: ${E}: invalid action name
|
|
38
|
+
`,2);s.push(E)}else if(w==="-W"){if(y++,y>=t.length)return S(`compgen: -W: option requires an argument
|
|
39
|
+
`,2);n=t[y]}else if(w==="-P"){if(y++,y>=t.length)return S(`compgen: -P: option requires an argument
|
|
40
|
+
`,2);r=t[y]}else if(w==="-S"){if(y++,y>=t.length)return S(`compgen: -S: option requires an argument
|
|
41
|
+
`,2);i=t[y]}else if(w==="-o"){if(y++,y>=t.length)return S(`compgen: -o: option requires an argument
|
|
42
|
+
`,2);let E=t[y];if(E==="plusdirs")o=!0;else if(E==="dirnames")c=!0;else if(E==="default")l=!0;else if(!(E==="filenames"||E==="nospace"||E==="bashdefault"||E==="noquote"))return S(`compgen: ${E}: invalid option name
|
|
43
|
+
`,2)}else if(w==="-F"){if(y++,y>=t.length)return S(`compgen: -F: option requires an argument
|
|
44
|
+
`,2);u=t[y]}else if(w==="-C"){if(y++,y>=t.length)return S(`compgen: -C: option requires an argument
|
|
45
|
+
`,2);d=t[y]}else if(w==="-X"){if(y++,y>=t.length)return S(`compgen: -X: option requires an argument
|
|
46
|
+
`,2);f=t[y]}else if(w==="-G"){if(y++,y>=t.length)return S(`compgen: -G: option requires an argument
|
|
47
|
+
`,2)}else if(w==="--"){h.push(...t.slice(y+1));break}else w.startsWith("-")||h.push(w)}a=h[0]??null;let p=[];if(c){let y=await ns(e,a);p.push(...y)}if(l){let y=await Fn(e,a);p.push(...y)}for(let y of s)if(y==="variable"){let w=pi(e,a);p.push(...w)}else if(y==="export"){let w=mi(e,a);p.push(...w)}else if(y==="function"){let w=yi(e,a);p.push(...w)}else if(y==="builtin"){let w=gi(a);p.push(...w)}else if(y==="keyword"){let w=wi(a);p.push(...w)}else if(y==="alias"){let w=vi(e,a);p.push(...w)}else if(y==="shopt"){let w=Ei(a);p.push(...w)}else if(y==="helptopic"){let w=bi(a);p.push(...w)}else if(y==="directory"){let w=await ns(e,a);p.push(...w)}else if(y==="file"){let w=await Fn(e,a);p.push(...w)}else if(y==="user"){let w=$i(a);p.push(...w)}else if(y==="command"){let w=await Si(e,a);p.push(...w)}if(n!==null)try{let y=await Ai(e,n),w=Pi(e,y);for(let E of w)(a===null||E.startsWith(a))&&p.push(E)}catch{return P("","",1)}if(o){let y=await ns(e,a);for(let w of y)p.includes(w)||p.push(w)}let g="";if(u!==null){let y=e.state.functions.get(u);if(y){let w=new Map;w.set("COMP_WORDS__length",e.state.env.get("COMP_WORDS__length")),e.state.env.set("COMP_WORDS__length","0"),w.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),w.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),w.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let E=new Map;for(let O of e.state.env.keys())(O==="COMPREPLY"||O.startsWith("COMPREPLY_")||O==="COMPREPLY__length")&&(E.set(O,e.state.env.get(O)),e.state.env.delete(O));let _=["compgen",h[0]??"",""];try{let O=await Ct(e,y,_,"");if(O.exitCode!==0)return Ve(e,w),Ve(e,E),P("",O.stderr,1);g=O.stdout;let D=_i(e);p.push(...D)}catch{return Ve(e,w),Ve(e,E),P("","",1)}Ve(e,w),Ve(e,E)}}if(d!==null)try{let y=he(d),w=await e.executeScript(y);if(w.exitCode!==0)return P("",w.stderr,w.exitCode);if(w.stdout){let E=w.stdout.split(`
|
|
48
|
+
`);for(let _ of E)_.length>0&&p.push(_)}}catch(y){if(y.name==="ParseException")return S(`compgen: -C: ${y.message}
|
|
49
|
+
`,2);throw y}let v=p;if(f!==null){let y=f.startsWith("!"),w=y?f.slice(1):f;v=p.filter(E=>{let _=We(E,w,!1,!0);return y?_:!_})}if(v.length===0&&a!==null)return P(g,"",1);let $=v.map(y=>`${r}${y}${i}`).join(`
|
|
50
|
+
`),C=g+($?`${$}
|
|
51
|
+
`:"");return F(C)}function pi(e,t){let s=new Set;for(let r of e.state.env.keys()){if(r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length"))continue;let i=r.split("_")[0];/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)?s.add(r):i&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)&&e.state.env.has(`${i}__length`)&&s.add(i)}let n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function mi(e,t){let s=e.state.exportedVars??new Set,n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n=n.filter(r=>r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length")?!1:e.state.env.has(r)),n.sort()}function yi(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(n=>n.startsWith(t))),s.sort()}function gi(e){let t=[...rs];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function wi(e){let t=[...Mn];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function vi(e,t){let s=[];for(let r of e.state.env.keys())if(r.startsWith("BASH_ALIAS_")){let i=r.slice(11);s.push(i)}let n=s;return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function Ei(e){let t=[...di];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function bi(e){let t=[...hi];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function ns(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let o=t.slice(0,a)||"/";r=t.slice(a+1),o.startsWith("/")?n=o:n=`${e.state.cwd}/${o}`}}let i=await e.fs.readdir(n);for(let a of i){let o=`${n}/${a}`;try{if((await e.fs.stat(o)).isDirectory&&(!r||a.startsWith(r)))if(t?.includes("/")){let l=t.lastIndexOf("/"),f=t.slice(0,l+1);s.push(f+a)}else s.push(a)}catch{}}}catch{}return s.sort()}async function Fn(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let o=t.slice(0,a)||"/";r=t.slice(a+1),o.startsWith("/")?n=o:n=`${e.state.cwd}/${o}`}}let i=await e.fs.readdir(n);for(let a of i)if(!r||a.startsWith(r))if(t?.includes("/")){let o=t.lastIndexOf("/"),c=t.slice(0,o+1);s.push(c+a)}else s.push(a)}catch{}return s.sort()}function $i(e){return["root","nobody"]}async function Si(e,t){let s=new Set;for(let i of rs)s.add(i);for(let i of e.state.functions.keys())s.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&s.add(i.slice(11));for(let i of Mn)s.add(i);let n=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of n.split(":"))if(i)try{let a=await e.fs.readdir(i);for(let o of a)s.add(o)}catch{}let r=Array.from(s);return t!==null&&(r=r.filter(i=>i.startsWith(t))),r.sort()}async function Ai(e,t){let n=new W().parseWordFromString(t,!1,!1);return await I(e,n)}function Pi(e,t){let s=e.state.env.get("IFS")??`
|
|
52
|
+
`;if(s.length===0)return[t];let n=new Set(s.split("")),r=[],i="",a=0;for(;a<t.length;){let o=t[a];if(o==="\\"&&a+1<t.length){let c=t[a+1];i+=c,a+=2}else n.has(o)?(i.length>0&&(r.push(i),i=""),a++):(i+=o,a++)}return i.length>0&&r.push(i),r}function Ve(e,t){for(let[s,n]of t)n===void 0?e.state.env.delete(s):e.state.env.set(s,n)}function _i(e){let t=[];if(e.state.env.get("COMPREPLY__length")!==void 0){let r=fe(e,"COMPREPLY");for(let[,i]of r)t.push(i)}else{let r=e.state.env.get("COMPREPLY");r!==void 0&&t.push(r)}return t}var Ni=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function os(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=!1,i,a,o,c=[],l=[],f=[];for(let u=0;u<t.length;u++){let d=t[u];if(d==="-p")s=!0;else if(d==="-r")n=!0;else if(d==="-D")r=!0;else if(d==="-W"){if(u++,u>=t.length)return S(`complete: -W: option requires an argument
|
|
53
53
|
`,2);i=t[u]}else if(d==="-F"){if(u++,u>=t.length)return S(`complete: -F: option requires an argument
|
|
54
|
-
`,2);
|
|
55
|
-
`,2);let h=t[u];if(!
|
|
56
|
-
`,2);
|
|
57
|
-
`,2);
|
|
58
|
-
`,2);
|
|
54
|
+
`,2);a=t[u]}else if(d==="-o"){if(u++,u>=t.length)return S(`complete: -o: option requires an argument
|
|
55
|
+
`,2);let h=t[u];if(!Ni.includes(h))return S(`complete: ${h}: invalid option name
|
|
56
|
+
`,2);c.push(h)}else if(d==="-A"){if(u++,u>=t.length)return S(`complete: -A: option requires an argument
|
|
57
|
+
`,2);l.push(t[u])}else if(d==="-C"){if(u++,u>=t.length)return S(`complete: -C: option requires an argument
|
|
58
|
+
`,2);o=t[u]}else if(d==="-G"){if(u++,u>=t.length)return S(`complete: -G: option requires an argument
|
|
59
59
|
`,2)}else if(d==="-P"){if(u++,u>=t.length)return S(`complete: -P: option requires an argument
|
|
60
60
|
`,2)}else if(d==="-S"){if(u++,u>=t.length)return S(`complete: -S: option requires an argument
|
|
61
61
|
`,2)}else if(d==="-X"){if(u++,u>=t.length)return S(`complete: -X: option requires an argument
|
|
62
|
-
`,2)}else if(d==="--"){f.push(...t.slice(u+1));break}else d.startsWith("-")||f.push(d)}if(n){if(f.length===0)return e.state.completionSpecs.clear(),F("");for(let u of f)e.state.completionSpecs.delete(u);return F("")}if(s)return f.length===0?
|
|
63
|
-
`,2);if(r){let u={isDefault:!0};return i!==void 0&&(u.wordlist=i),
|
|
64
|
-
`;return P("",i,1)}return F("")}let n=[],r=t||Array.from(s.keys());for(let i of r){if(i==="__default__")continue;let
|
|
62
|
+
`,2)}else if(d==="--"){f.push(...t.slice(u+1));break}else d.startsWith("-")||f.push(d)}if(n){if(f.length===0)return e.state.completionSpecs.clear(),F("");for(let u of f)e.state.completionSpecs.delete(u);return F("")}if(s)return f.length===0?as(e):as(e,f);if(t.length===0||f.length===0&&!i&&!a&&!o&&c.length===0&&l.length===0&&!r)return as(e);if(a&&f.length===0&&!r)return S(`complete: -F: option requires a command name
|
|
63
|
+
`,2);if(r){let u={isDefault:!0};return i!==void 0&&(u.wordlist=i),a!==void 0&&(u.function=a),o!==void 0&&(u.command=o),c.length>0&&(u.options=c),l.length>0&&(u.actions=l),e.state.completionSpecs.set("__default__",u),F("")}for(let u of f){let d={};i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),o!==void 0&&(d.command=o),c.length>0&&(d.options=c),l.length>0&&(d.actions=l),e.state.completionSpecs.set(u,d)}return F("")}function as(e,t){let s=e.state.completionSpecs;if(!s||s.size===0){if(t&&t.length>0){let i="";for(let a of t)i+=`complete: ${a}: no completion specification
|
|
64
|
+
`;return P("",i,1)}return F("")}let n=[],r=t||Array.from(s.keys());for(let i of r){if(i==="__default__")continue;let a=s.get(i);if(!a){if(t)return P(n.join(`
|
|
65
65
|
`)+(n.length>0?`
|
|
66
66
|
`:""),`complete: ${i}: no completion specification
|
|
67
|
-
`,1);continue}let
|
|
67
|
+
`,1);continue}let o="complete";if(a.options)for(let c of a.options)o+=` -o ${c}`;if(a.actions)for(let c of a.actions)o+=` -A ${c}`;a.wordlist!==void 0&&(a.wordlist.includes(" ")||a.wordlist.includes("'")?o+=` -W '${a.wordlist}'`:o+=` -W ${a.wordlist}`),a.function!==void 0&&(o+=` -F ${a.function}`),a.isDefault&&(o+=" -D"),o+=` ${i}`,n.push(o)}return n.length===0?F(""):F(`${n.join(`
|
|
68
68
|
`)}
|
|
69
|
-
`)}var
|
|
70
|
-
`,2);let
|
|
71
|
-
`,2);r.push(
|
|
72
|
-
`,2);let
|
|
73
|
-
`,2);i.push(
|
|
74
|
-
`,1)}function
|
|
69
|
+
`)}var Wn=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function ls(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=[],i=[],a=[];for(let o=0;o<t.length;o++){let c=t[o];if(c==="-D")s=!0;else if(c==="-E")n=!0;else if(c==="-o"){if(o++,o>=t.length)return S(`compopt: -o: option requires an argument
|
|
70
|
+
`,2);let l=t[o];if(!Wn.includes(l))return S(`compopt: ${l}: invalid option name
|
|
71
|
+
`,2);r.push(l)}else if(c==="+o"){if(o++,o>=t.length)return S(`compopt: +o: option requires an argument
|
|
72
|
+
`,2);let l=t[o];if(!Wn.includes(l))return S(`compopt: ${l}: invalid option name
|
|
73
|
+
`,2);i.push(l)}else if(c==="--"){a.push(...t.slice(o+1));break}else!c.startsWith("-")&&!c.startsWith("+")&&a.push(c)}if(s){let o=e.state.completionSpecs.get("__default__")??{isDefault:!0},c=new Set(o.options??[]);for(let l of r)c.add(l);for(let l of i)c.delete(l);return o.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set("__default__",o),F("")}if(n){let o=e.state.completionSpecs.get("__empty__")??{},c=new Set(o.options??[]);for(let l of r)c.add(l);for(let l of i)c.delete(l);return o.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set("__empty__",o),F("")}if(a.length>0){for(let o of a){let c=e.state.completionSpecs.get(o)??{},l=new Set(c.options??[]);for(let f of r)l.add(f);for(let f of i)l.delete(f);c.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set(o,c)}return F("")}return S(`compopt: not currently executing completion function
|
|
74
|
+
`,1)}function cs(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new _e;return L}if(t.length>1)throw new z(1,"",`bash: continue: too many arguments
|
|
75
75
|
`);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new z(1,"",`bash: continue: ${t[0]}: numeric argument required
|
|
76
|
-
`);s=n}throw new ie(s)}function
|
|
77
|
-
`;else{let u=f.map(d=>{let h=e.state.env
|
|
78
|
-
`}continue}let
|
|
79
|
-
`;continue}if(e.state.env
|
|
80
|
-
`;continue}let
|
|
81
|
-
`;else{let f=e.state.declaredVars?.has(i),u=e.state.localVarDepth?.has(i);f||u?s+=`declare ${
|
|
76
|
+
`);s=n}throw new ie(s)}function j(e,t){let s=e.state.env.get("HOME")||"/home/user";return t.split(":").map(i=>i==="~"?s:i==="~root"?"/root":i.startsWith("~/")?s+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function fs(e){for(let t=0;t<e.length;t++){let s=e.charCodeAt(t);if(s<32||s===127)return!0}return!1}function us(e){let t="$'";for(let s=0;s<e.length;s++){let n=e[s],r=e.charCodeAt(s);r===7?t+="\\a":r===8?t+="\\b":r===9?t+="\\t":r===10?t+="\\n":r===11?t+="\\v":r===12?t+="\\f":r===13?t+="\\r":r===27?t+="\\e":r===39?t+="\\'":r===92?t+="\\\\":r<32||r===127?t+=`\\${r.toString(8).padStart(3,"0")}`:t+=n}return t+="'",t}function kt(e){return fs(e)?us(e):/^[a-zA-Z0-9_/.:\-@%+,=]*$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function xe(e){return fs(e)?us(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function ds(e){return fs(e)?us(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function zn(e,t){let s="";return e.state.integerVars?.has(t)&&(s+="i"),e.state.lowercaseVars?.has(t)&&(s+="l"),oe(e,t)&&(s+="n"),e.state.readonlyVars?.has(t)&&(s+="r"),e.state.uppercaseVars?.has(t)&&(s+="u"),e.state.exportedVars?.has(t)&&(s+="x"),s===""?"--":`-${s}`}function hs(e){return e===""?"''":/[\s'\\]/.test(e)?`'${e.replace(/'/g,"'\\''")}'`:e}function Vn(e,t){let s="",n="",r=!1;for(let i of t){let a=zn(e,i);if(e.state.associativeArrays?.has(i)){let f=Ce(e,i);if(f.length===0)s+=`declare -A ${i}=()
|
|
77
|
+
`;else{let u=f.map(d=>{let h=e.state.env.get(`${i}_${d}`)??"",m=hs(h);return`['${d}']=${m}`});s+=`declare -A ${i}=(${u.join(" ")})
|
|
78
|
+
`}continue}let c=Q(e,i);if(c.length>0){let f=c.map(u=>{let d=e.state.env.get(`${i}_${u}`)??"";return`[${u}]=${xe(d)}`});s+=`declare -a ${i}=(${f.join(" ")})
|
|
79
|
+
`;continue}if(e.state.env.has(`${i}__length`)){s+=`declare -a ${i}=()
|
|
80
|
+
`;continue}let l=e.state.env.get(i);if(l!==void 0)s+=`declare ${a} ${i}=${ds(l)}
|
|
81
|
+
`;else{let f=e.state.declaredVars?.has(i),u=e.state.localVarDepth?.has(i);f||u?s+=`declare ${a} ${i}
|
|
82
82
|
`:(n+=`bash: declare: ${i}: not found
|
|
83
|
-
`,r=!0)}}return P(s,n,r?1:0)}function
|
|
84
|
-
`;else{let $=
|
|
85
|
-
`}continue}if(m.length>0){let
|
|
86
|
-
`;continue}if(e.state.env
|
|
87
|
-
`;continue}let
|
|
88
|
-
`)}return F(
|
|
89
|
-
`;else{let i=r.map(
|
|
90
|
-
`}}return F(t)}function
|
|
91
|
-
`;else{let
|
|
92
|
-
`}}return F(t)}function
|
|
93
|
-
`)}return F(t)}function
|
|
94
|
-
`,2)}}}else if(R==="-i")u=!0;else if(R==="-l")d=!0;else if(R==="-u")h=!0;else if(R==="-f")m=!0;else if(R==="-F")p=!0;else if(R==="-g")
|
|
95
|
-
`,2);else
|
|
96
|
-
`;return F(N)}let
|
|
97
|
-
`:
|
|
83
|
+
`,r=!0)}}return P(s,n,r?1:0)}function Bn(e,t){let{filterExport:s,filterReadonly:n,filterNameref:r,filterIndexedArray:i,filterAssocArray:a}=t,o=s||n||r||i||a,c="",l=new Set;for(let u of e.state.env.keys()){if(u.startsWith("BASH_"))continue;if(u.endsWith("__length")){let h=u.slice(0,-8);l.add(h);continue}let d=u.lastIndexOf("_");if(d>0){let h=u.slice(0,d),m=u.slice(d+1);if(/^\d+$/.test(m)||e.state.associativeArrays?.has(h)){l.add(h);continue}}l.add(u)}if(e.state.localVarDepth)for(let u of e.state.localVarDepth.keys())l.add(u);if(e.state.associativeArrays)for(let u of e.state.associativeArrays)l.add(u);let f=Array.from(l).sort();for(let u of f){let d=zn(e,u),h=e.state.associativeArrays?.has(u),m=Q(e,u),p=!h&&(m.length>0||e.state.env.has(`${u}__length`));if(o&&(a&&!h||i&&!p||s&&!e.state.exportedVars?.has(u)||n&&!e.state.readonlyVars?.has(u)||r&&!oe(e,u)))continue;if(h){let v=Ce(e,u);if(v.length===0)c+=`declare -A ${u}=()
|
|
84
|
+
`;else{let $=v.map(C=>{let y=e.state.env.get(`${u}_${C}`)??"",w=hs(y);return`['${C}']=${w}`});c+=`declare -A ${u}=(${$.join(" ")})
|
|
85
|
+
`}continue}if(m.length>0){let v=m.map($=>{let C=e.state.env.get(`${u}_${$}`)??"";return`[${$}]=${xe(C)}`});c+=`declare -a ${u}=(${v.join(" ")})
|
|
86
|
+
`;continue}if(e.state.env.has(`${u}__length`)){c+=`declare -a ${u}=()
|
|
87
|
+
`;continue}let g=e.state.env.get(u);g!==void 0&&(c+=`declare ${d} ${u}=${ds(g)}
|
|
88
|
+
`)}return F(c)}function Hn(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let n of s){let r=Ce(e,n);if(r.length===0)t+=`declare -A ${n}=()
|
|
89
|
+
`;else{let i=r.map(a=>{let o=e.state.env.get(`${n}_${a}`)??"",c=hs(o);return`['${a}']=${c}`});t+=`declare -A ${n}=(${i.join(" ")})
|
|
90
|
+
`}}return F(t)}function jn(e){let t="",s=new Set;for(let r of e.state.env.keys()){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let a=r.slice(0,-8);e.state.associativeArrays?.has(a)||s.add(a);continue}let i=r.lastIndexOf("_");if(i>0){let a=r.slice(0,i),o=r.slice(i+1);/^\d+$/.test(o)&&(e.state.associativeArrays?.has(a)||s.add(a))}}let n=Array.from(s).sort();for(let r of n){let i=Q(e,r);if(i.length===0)t+=`declare -a ${r}=()
|
|
91
|
+
`;else{let a=i.map(o=>{let c=e.state.env.get(`${r}_${o}`)??"";return`[${o}]=${xe(c)}`});t+=`declare -a ${r}=(${a.join(" ")})
|
|
92
|
+
`}}return F(t)}function Un(e){let t="",s=new Set;for(let r of e.state.env.keys()){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let a=r.slice(0,-8);s.add(a);continue}let i=r.lastIndexOf("_");if(i>0){let a=r.slice(0,i),o=r.slice(i+1);if(/^\d+$/.test(o)||e.state.associativeArrays?.has(a)){s.add(a);continue}}s.add(r)}let n=Array.from(s).sort();for(let r of n){if(e.state.associativeArrays?.has(r)||Q(e,r).length>0||e.state.env.has(`${r}__length`))continue;let o=e.state.env.get(r);o!==void 0&&(t+=`${r}=${kt(o)}
|
|
93
|
+
`)}return F(t)}function ps(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function Je(e,t){return e.state.integerVars?.has(t)??!1}function ms(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Ci(e,t){return e.state.lowercaseVars?.has(t)??!1}function ys(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function ki(e,t){return e.state.uppercaseVars?.has(t)??!1}function Be(e,t,s){return Ci(e,t)?s.toLowerCase():ki(e,t)?s.toUpperCase():s}async function qn(e,t){try{let s=new W,n=Z(s,t),r=await V(e,n.expression);return String(r)}catch{return"0"}}function Oi(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let s=t[0],n=s.length;if(e[n]!=="[")return null;let r=0,i=n+1;for(;n<e.length;n++)if(e[n]==="[")r++;else if(e[n]==="]"&&(r--,r===0))break;if(r!==0)return null;let a=e.slice(i,n);if(n++,e[n]!=="=")return null;n++;let o=e.slice(n);return{name:s,indexExpr:a,value:o}}async function gs(e,t){let s=!1,n=!1,r=!1,i=!1,a=!1,o=!1,c=!1,l=!1,f=!1,u=!1,d=!1,h=!1,m=!1,p=!1,g=!1,v=[];for(let D=0;D<t.length;D++){let R=t[D];if(R==="-a")s=!0;else if(R==="-A")n=!0;else if(R==="-r")r=!0;else if(R==="-x")i=!0;else if(R==="-p")a=!0;else if(R==="-n")o=!0;else if(R==="+n")c=!0;else if(R==="+a")l=!0;else if(R==="+x")f=!0;else if(R==="--"){v.push(...t.slice(D+1));break}else if(R.startsWith("+")){for(let A of R.slice(1))if(A==="n")c=!0;else if(A==="a")l=!0;else if(A==="x")f=!0;else if(A!=="r"){if(A!=="i"){if(!(A==="f"||A==="F"))return P("",`bash: typeset: +${A}: invalid option
|
|
94
|
+
`,2)}}}else if(R==="-i")u=!0;else if(R==="-l")d=!0;else if(R==="-u")h=!0;else if(R==="-f")m=!0;else if(R==="-F")p=!0;else if(R==="-g")g=!0;else if(R.startsWith("-"))for(let A of R.slice(1))if(A==="a")s=!0;else if(A==="A")n=!0;else if(A==="r")r=!0;else if(A==="x")i=!0;else if(A==="p")a=!0;else if(A==="n")o=!0;else if(A==="i")u=!0;else if(A==="l")d=!0;else if(A==="u")h=!0;else if(A==="f")m=!0;else if(A==="F")p=!0;else if(A==="g")g=!0;else return P("",`bash: typeset: -${A}: invalid option
|
|
95
|
+
`,2);else v.push(R)}let C=e.state.localScopes.length>0&&!g,y=D=>{if(!C)return;let R=e.state.localScopes[e.state.localScopes.length-1];R.has(D)||R.set(D,e.state.env.get(D))},w=D=>{if(!C)return;let R=e.state.localScopes[e.state.localScopes.length-1];R.has(D)||R.set(D,e.state.env.get(D));let A=`${D}_`;for(let T of e.state.env.keys())T.startsWith(A)&&!T.includes("__")&&(R.has(T)||R.set(T,e.state.env.get(T)));let N=`${D}__length`;e.state.env.has(N)&&!R.has(N)&&R.set(N,e.state.env.get(N))},E=D=>{C&&De(e,D)};if(p){if(v.length===0){let A=Array.from(e.state.functions.keys()).sort(),N="";for(let T of A)N+=`declare -f ${T}
|
|
96
|
+
`;return F(N)}let D=!0,R="";for(let A of v)e.state.functions.has(A)?R+=`${A}
|
|
97
|
+
`:D=!1;return P(R,"",D?0:1)}if(m){if(v.length===0){let R="",A=Array.from(e.state.functions.keys()).sort();for(let N of A)R+=`${N} ()
|
|
98
98
|
{
|
|
99
99
|
# function body
|
|
100
100
|
}
|
|
101
|
-
`;return F(R)}let
|
|
102
|
-
`,
|
|
103
|
-
`,
|
|
104
|
-
`,
|
|
105
|
-
`,
|
|
106
|
-
`,
|
|
107
|
-
`,
|
|
108
|
-
`}}return F(
|
|
109
|
-
`,2);n=t[
|
|
101
|
+
`;return F(R)}let D=!0;for(let R of v)e.state.functions.has(R)||(D=!1);return P("","",D?0:1)}if(a&&v.length>0)return Vn(e,v);if(a&&v.length===0)return Bn(e,{filterExport:i,filterReadonly:r,filterNameref:o,filterIndexedArray:s,filterAssocArray:n});if(v.length===0&&n&&!a)return Hn(e);if(v.length===0&&s&&!a)return jn(e);if(v.length===0&&!a)return Un(e);let _="",O=0;for(let D of v){let R=D.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(R&&!l){let b=R[1],k=R[2];if(n&&Q(e,b).length>0){_+=`bash: declare: ${b}: cannot convert indexed to associative array
|
|
102
|
+
`,O=1;continue}if((s||!n&&!s)&&e.state.associativeArrays?.has(b)){_+=`bash: declare: ${b}: cannot convert associative to indexed array
|
|
103
|
+
`,O=1;continue}if(w(b),n&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(b)),pe(e,b),e.state.env.delete(b),e.state.env.delete(`${b}__length`),n&&k.includes("[")){let x=At(k);for(let[X,M]of x){let U=j(e,M);e.state.env.set(`${b}_${X}`,U)}}else if(n){let x=ye(k);for(let X=0;X<x.length;X+=2){let M=x[X],U=X+1<x.length?j(e,x[X+1]):"";e.state.env.set(`${b}_${M}`,U)}}else{let x=ye(k);if(x.some(M=>/^\[[^\]]+\]=/.test(M))){let M=0;for(let U of x){let J=U.match(/^\[([^\]]+)\]=(.*)$/);if(J){let ne=J[1],Le=J[2],Rr=j(e,Le),Xe;if(/^-?\d+$/.test(ne))Xe=Number.parseInt(ne,10);else try{let xr=new W,Lr=Z(xr,ne);Xe=await V(e,Lr.expression)}catch{Xe=0}e.state.env.set(`${b}_${Xe}`,Rr),M=Xe+1}else{let ne=j(e,U);e.state.env.set(`${b}_${M}`,ne),M++}}}else{for(let M=0;M<x.length;M++)e.state.env.set(`${b}_${M}`,x[M]);e.state.env.set(`${b}__length`,String(x.length))}}E(b),r&&se(e,b),i&&ue(e,b);continue}if(c){let b=D.includes("=")?D.slice(0,D.indexOf("=")):D;if(Ks(e,b),!D.includes("="))continue}if(f){let b=D.includes("=")?D.slice(0,D.indexOf("=")):D;if(ft(e,b),!D.includes("="))continue}let A=Oi(D);if(A){let{name:b,indexExpr:k,value:x}=A,X=K(e,b);if(X)return X;w(b);let M;try{let J=new W,ne=Z(J,k);M=await V(e,ne.expression)}catch{let J=parseInt(k,10);M=Number.isNaN(J)?0:J}e.state.env.set(`${b}_${M}`,x);let U=parseInt(e.state.env.get(`${b}__length`)??"0",10);M>=U&&e.state.env.set(`${b}__length`,String(M+1)),E(b),r&&se(e,b),i&&ue(e,b);continue}let N=D.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(N&&!l){let b=N[1],k=N[2],x=K(e,b);if(x)return x;w(b);let X=ye(k);if(e.state.associativeArrays?.has(b)){let M=At(k);for(let[U,J]of M){let ne=j(e,J);e.state.env.set(`${b}_${U}`,ne)}}else{let M=Q(e,b),U=0,J=e.state.env.get(b);M.length===0&&J!==void 0?(e.state.env.set(`${b}_0`,J),e.state.env.delete(b),U=1):M.length>0&&(U=Math.max(...M)+1);for(let Le=0;Le<X.length;Le++)e.state.env.set(`${b}_${U+Le}`,j(e,X[Le]));let ne=U+X.length;e.state.env.set(`${b}__length`,String(ne))}E(b),r&&se(e,b),i&&ue(e,b);continue}let T=D.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(T){let b=T[1],k=j(e,T[2]),x=K(e,b);if(x)return x;y(b),u&&ps(e,b),d&&ms(e,b),h&&ys(e,b);let M=Q(e,b).length>0||e.state.associativeArrays?.has(b);if(Je(e,b)){let U=e.state.env.get(b)??"0",J=parseInt(U,10)||0,ne=parseInt(await qn(e,k),10)||0;k=String(J+ne),e.state.env.set(b,k)}else if(M){k=Be(e,b,k);let U=`${b}_0`,J=e.state.env.get(U)??"";e.state.env.set(U,J+k)}else{k=Be(e,b,k);let U=e.state.env.get(b)??"";e.state.env.set(b,U+k)}E(b),r&&se(e,b),i&&ue(e,b),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(b));continue}if(D.includes("=")){let b=D.indexOf("="),k=D.slice(0,b),x=D.slice(b+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(k)){_+=`bash: typeset: \`${k}': not a valid identifier
|
|
104
|
+
`,O=1;continue}let X=K(e,k);if(X)return X;if(y(k),o){if(x!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(x)){_+=`bash: declare: \`${x}': invalid variable name for name reference
|
|
105
|
+
`,O=1;continue}e.state.env.set(k,x),Ee(e,k),x!==""&&Ht(e,x)&&Bt(e,k),E(k),r&&se(e,k),i&&ue(e,k);continue}if(u&&ps(e,k),d&&ms(e,k),h&&ys(e,k),Je(e,k)&&(x=await qn(e,x)),x=Be(e,k,x),oe(e,k)){let M=ke(e,k);M&&M!==k?e.state.env.set(M,x):e.state.env.set(k,x)}else e.state.env.set(k,x);E(k),r&&se(e,k),i&&ue(e,k),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(k))}else{let b=D;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(b)){_+=`bash: typeset: \`${b}': not a valid identifier
|
|
106
|
+
`,O=1;continue}if(s||n?w(b):y(b),o){Ee(e,b);let x=e.state.env.get(b);x!==void 0&&x!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(x)?Ys(e,b):x&&Ht(e,x)&&Bt(e,b),E(b),r&&se(e,b),i&&ue(e,b);continue}if(u&&ps(e,b),d&&ms(e,b),h&&ys(e,b),n){if(Q(e,b).length>0){_+=`bash: declare: ${b}: cannot convert indexed to associative array
|
|
107
|
+
`,O=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(b)}let k=Array.from(e.state.env.keys()).some(x=>x.startsWith(`${b}_`)&&!x.startsWith(`${b}__length`));!e.state.env.has(b)&&!k&&(s||n?e.state.env.set(`${b}__length`,"0"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(b))),E(b),r&&se(e,b),i&&ue(e,b)}}return P("",_,O)}async function ws(e,t){let s=!1,n=!1,r=!1,i=[];for(let a=0;a<t.length;a++){let o=t[a];if(o==="-a")s=!0;else if(o==="-A")n=!0;else if(o==="-p")r=!0;else if(o==="--"){i.push(...t.slice(a+1));break}else o.startsWith("-")||i.push(o)}if(i.length===0){let a="",o=Array.from(e.state.readonlyVars||[]).sort();for(let c of o){let l=e.state.env.get(c);if(l!==void 0){let f=l.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${c}="${f}"
|
|
108
|
+
`}}return F(a)}for(let a of i){let o=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(o){let u=o[1],d=o[2],h=K(e,u);if(h)return h;let m=ye(d);if(e.state.associativeArrays?.has(u)){let p=At(d);for(let[g,v]of p){let $=j(e,v);e.state.env.set(`${u}_${g}`,$)}}else{let p=Q(e,u),g=0,v=e.state.env.get(u);p.length===0&&v!==void 0?(e.state.env.set(`${u}_0`,v),e.state.env.delete(u),g=1):p.length>0&&(g=Math.max(...p)+1);for(let C=0;C<m.length;C++)e.state.env.set(`${u}_${g+C}`,j(e,m[C]));let $=g+m.length;e.state.env.set(`${u}__length`,String($))}se(e,u);continue}let c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c){let u=c[1],d=j(e,c[2]),h=K(e,u);if(h)return h;let m=e.state.env.get(u)??"";e.state.env.set(u,m+d),se(e,u);continue}let l=On(a);if(l.value===void 0&&!l.isArray){se(e,l.name);continue}let f=await Dn(e,l,{makeReadonly:!0});if(f)return f}return L}function vs(e){return e.state.directoryStack??=[],e.state.directoryStack}function et(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function Di(e){let t=e.split("/").filter(n=>n&&n!=="."),s=[];for(let n of t)n===".."?s.pop():s.push(n);return`/${s.join("/")}`}async function Es(e,t){let s=vs(e),n;for(let o=0;o<t.length;o++){let c=t[o];if(c==="--"){if(o+1<t.length){if(n!==void 0)return S(`bash: pushd: too many arguments
|
|
109
|
+
`,2);n=t[o+1],o++}}else{if(c.startsWith("-")&&c!=="-")return S(`bash: pushd: ${c}: invalid option
|
|
110
110
|
`,2);if(n!==void 0)return S(`bash: pushd: too many arguments
|
|
111
|
-
`,2);n=
|
|
112
|
-
`,1);let
|
|
111
|
+
`,2);n=c}}if(n===void 0){if(s.length<2)return S(`bash: pushd: no other directory
|
|
112
|
+
`,1);let o=s[0];s[0]=s[1],s[1]=o,n=s[0]}let r;if(n.startsWith("/"))r=n;else if(n===".."){let o=e.state.cwd.split("/").filter(c=>c);o.pop(),r=`/${o.join("/")}`}else n==="."?r=e.state.cwd:n.startsWith("~")?r=(e.state.env.get("HOME")||"/")+n.slice(1):r=`${e.state.cwd}/${n}`;r=Di(r);try{if(!(await e.fs.stat(r)).isDirectory)return S(`bash: pushd: ${n}: Not a directory
|
|
113
113
|
`,1)}catch{return S(`bash: pushd: ${n}: No such file or directory
|
|
114
|
-
`,1)}s.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.PWD
|
|
115
|
-
`;return F(
|
|
114
|
+
`,1)}s.unshift(e.state.cwd),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 i=e.state.env.get("HOME")||"",a=`${[r,...s].map(o=>et(o,i)).join(" ")}
|
|
115
|
+
`;return F(a)}function bs(e,t){let s=vs(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?S(`bash: popd: ${a}: invalid option
|
|
116
116
|
`,2):S(`bash: popd: too many arguments
|
|
117
117
|
`,2);if(s.length===0)return S(`bash: popd: directory stack empty
|
|
118
118
|
`,1);let n=s.shift();if(!n)return S(`bash: popd: directory stack empty
|
|
119
|
-
`,1);e.state.previousDir=e.state.cwd,e.state.cwd=n,e.state.env.PWD
|
|
120
|
-
`;return F(i)}function
|
|
119
|
+
`,1);e.state.previousDir=e.state.cwd,e.state.cwd=n,e.state.env.set("PWD",n),e.state.env.set("OLDPWD",e.state.previousDir);let r=e.state.env.get("HOME")||"",i=`${[n,...s].map(a=>et(a,r)).join(" ")}
|
|
120
|
+
`;return F(i)}function $s(e,t){let s=vs(e),n=!1,r=!1,i=!1,a=!1;for(let f of t)if(f!=="--")if(f.startsWith("-"))for(let u of f.slice(1))if(u==="c")n=!0;else if(u==="l")r=!0;else if(u==="p")i=!0;else if(u==="v")i=!0,a=!0;else return S(`bash: dirs: -${u}: invalid option
|
|
121
121
|
`,2);else return S(`bash: dirs: too many arguments
|
|
122
|
-
`,1);if(n)return e.state.directoryStack=[],L;let
|
|
123
|
-
`),
|
|
124
|
-
`):i?
|
|
122
|
+
`,1);if(n)return e.state.directoryStack=[],L;let o=[e.state.cwd,...s],c=e.state.env.get("HOME")||"",l;return a?(l=o.map((f,u)=>{let d=r?f:et(f,c);return` ${u} ${d}`}).join(`
|
|
123
|
+
`),l+=`
|
|
124
|
+
`):i?l=o.map(f=>r?f:et(f,c)).join(`
|
|
125
125
|
`)+`
|
|
126
|
-
`:
|
|
127
|
-
`,F(
|
|
126
|
+
`:l=o.map(f=>r?f:et(f,c)).join(" ")+`
|
|
127
|
+
`,F(l)}async function Ot(e,t,s){let n=t;if(n.length>0){let o=n[0];if(o==="--")n=n.slice(1);else if(o.startsWith("-")&&o!=="-"&&o.length>1)return S(`bash: eval: ${o}: invalid option
|
|
128
128
|
eval: usage: eval [arg ...]
|
|
129
|
-
`,2)}if(n.length===0)return L;let r=n.join(" ");if(r.trim()==="")return L;let i=e.state.groupStdin,
|
|
130
|
-
`);throw
|
|
131
|
-
`,s=2):s=(i%256+256)%256}throw new z(s,"",n)}function
|
|
132
|
-
`}}return F(
|
|
133
|
-
`,i=1;continue}if(
|
|
134
|
-
`);let s=t[0],n=t[1],r=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n),i=s.startsWith(":"),
|
|
135
|
-
`,r||
|
|
136
|
-
`,r||
|
|
137
|
-
`,1);
|
|
129
|
+
`,2)}if(n.length===0)return L;let r=n.join(" ");if(r.trim()==="")return L;let i=e.state.groupStdin,a=s??e.state.groupStdin;a!==void 0&&(e.state.groupStdin=a);try{let o=he(r);return await e.executeScript(o)}catch(o){if(o instanceof re||o instanceof ie||o instanceof te||o instanceof z)throw o;if(o.name==="ParseException")return S(`bash: eval: ${o.message}
|
|
130
|
+
`);throw o}finally{e.state.groupStdin=i}}function Ss(e,t){let s,n="";if(t.length===0)s=e.state.lastExitCode;else{let r=t[0],i=Number.parseInt(r,10);r===""||Number.isNaN(i)||!/^-?\d+$/.test(r)?(n=`bash: exit: ${r}: numeric argument required
|
|
131
|
+
`,s=2):s=(i%256+256)%256}throw new z(s,"",n)}function As(e,t){let s=!1,n=[];for(let a of t)a==="-n"?s=!0:a==="-p"||a==="--"||n.push(a);if(n.length===0&&!s){let a="",o=e.state.exportedVars??new Set,c=Array.from(o).sort();for(let l of c){let f=e.state.env.get(l);if(f!==void 0){let u=f.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -x ${l}="${u}"
|
|
132
|
+
`}}return F(a)}if(s){for(let a of n){let o,c;if(a.includes("=")){let l=a.indexOf("=");o=a.slice(0,l),c=j(e,a.slice(l+1)),e.state.env.set(o,c)}else o=a;ft(e,o)}return L}let r="",i=0;for(let a of n){let o,c,l=!1,f=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(f)o=f[1],c=j(e,f[2]),l=!0;else if(a.includes("=")){let u=a.indexOf("=");o=a.slice(0,u),c=j(e,a.slice(u+1))}else o=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){r+=`bash: export: \`${a}': not a valid identifier
|
|
133
|
+
`,i=1;continue}if(c!==void 0)if(l){let u=e.state.env.get(o)??"";e.state.env.set(o,u+c)}else e.state.env.set(o,c);else e.state.env.has(o)||e.state.env.set(o,"");ue(e,o)}return P("",r,i)}function Dt(e,t){if(t.length<2)return S(`bash: getopts: usage: getopts optstring name [arg ...]
|
|
134
|
+
`);let s=t[0],n=t[1],r=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n),i=s.startsWith(":"),a=i?s.slice(1):s,o;if(t.length>2)o=t.slice(2);else{let p=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let g=1;g<=p;g++)o.push(e.state.env.get(String(g))||"")}let c=Number.parseInt(e.state.env.get("OPTIND")||"1",10);c<1&&(c=1);let l=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),c>o.length)return r||e.state.env.set(n,"?"),e.state.env.set("OPTIND",String(o.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:r?2:1,stdout:"",stderr:""};let f=o[c-1];if(!f||f==="-"||!f.startsWith("-"))return r||e.state.env.set(n,"?"),{exitCode:r?2:1,stdout:"",stderr:""};if(f==="--")return e.state.env.set("OPTIND",String(c+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),r||e.state.env.set(n,"?"),{exitCode:r?2:1,stdout:"",stderr:""};let u=l===0?1:l,d=f[u];if(!d)return e.state.env.set("OPTIND",String(c+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),Dt(e,t);let h=a.indexOf(d);if(h===-1){let p="";return i?e.state.env.set("OPTARG",d):p=`bash: illegal option -- ${d}
|
|
135
|
+
`,r||e.state.env.set(n,"?"),u+1<f.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(u+1)),e.state.env.set("OPTIND",String(c))):(e.state.env.set("OPTIND",String(c+1)),e.state.env.set("__GETOPTS_CHARINDEX","0")),{exitCode:r?2:0,stdout:"",stderr:p}}if(h+1<a.length&&a[h+1]===":")if(u+1<f.length)e.state.env.set("OPTARG",f.slice(u+1)),e.state.env.set("OPTIND",String(c+1)),e.state.env.set("__GETOPTS_CHARINDEX","0");else{if(c>=o.length){let p="";return i?(e.state.env.set("OPTARG",d),r||e.state.env.set(n,":")):(p=`bash: option requires an argument -- ${d}
|
|
136
|
+
`,r||e.state.env.set(n,"?")),e.state.env.set("OPTIND",String(c+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:r?2:0,stdout:"",stderr:p}}e.state.env.set("OPTARG",o[c]),e.state.env.set("OPTIND",String(c+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else u+1<f.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(u+1)),e.state.env.set("OPTIND",String(c))):(e.state.env.set("OPTIND",String(c+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return r||e.state.env.set(n,d),{exitCode:r?2:0,stdout:"",stderr:""}}async function Ps(e,t){e.state.hashTable||(e.state.hashTable=new Map);let s=!1,n=!1,r=!1,i=!1,a=!1,o="",c=[],l=0;for(;l<t.length;){let m=t[l];if(m==="--"){l++,c.push(...t.slice(l));break}if(m==="-r")s=!0,l++;else if(m==="-d")n=!0,l++;else if(m==="-l")r=!0,l++;else if(m==="-t")a=!0,l++;else if(m==="-p"){if(i=!0,l++,l>=t.length)return S(`bash: hash: -p: option requires an argument
|
|
137
|
+
`,1);o=t[l],l++}else if(m.startsWith("-")&&m.length>1){for(let p of m.slice(1))if(p==="r")s=!0;else if(p==="d")n=!0;else if(p==="l")r=!0;else if(p==="t")a=!0;else return p==="p"?S(`bash: hash: -p: option requires an argument
|
|
138
138
|
`,1):S(`bash: hash: -${p}: invalid option
|
|
139
|
-
`,1);
|
|
140
|
-
`,1);let m=!1,p="";for(let
|
|
141
|
-
`,m=!0);return m?S(p,1):L}if(
|
|
142
|
-
`,1);let m="",p=!1,
|
|
139
|
+
`,1);l++}else c.push(m),l++}if(s)return e.state.hashTable.clear(),L;if(n){if(c.length===0)return S(`bash: hash: -d: option requires an argument
|
|
140
|
+
`,1);let m=!1,p="";for(let g of c)e.state.hashTable.has(g)?e.state.hashTable.delete(g):(p+=`bash: hash: ${g}: not found
|
|
141
|
+
`,m=!0);return m?S(p,1):L}if(a){if(c.length===0)return S(`bash: hash: -t: option requires an argument
|
|
142
|
+
`,1);let m="",p=!1,g="";for(let v of c){let $=e.state.hashTable.get(v);$?c.length>1?m+=`${v} ${$}
|
|
143
143
|
`:m+=`${$}
|
|
144
|
-
`:(
|
|
145
|
-
`,p=!0)}return p?{exitCode:1,stdout:m,stderr:
|
|
146
|
-
`,1);let m=
|
|
147
|
-
`);let m="";if(r)for(let[p,
|
|
144
|
+
`:(g+=`bash: hash: ${v}: not found
|
|
145
|
+
`,p=!0)}return p?{exitCode:1,stdout:m,stderr:g}:F(m)}if(i){if(c.length===0)return S(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
|
|
146
|
+
`,1);let m=c[0];return e.state.hashTable.set(m,o),L}if(c.length===0){if(e.state.hashTable.size===0)return F(`hash: hash table empty
|
|
147
|
+
`);let m="";if(r)for(let[p,g]of e.state.hashTable)m+=`builtin hash -p ${g} ${p}
|
|
148
148
|
`;else{m=`hits command
|
|
149
149
|
`;for(let[,p]of e.state.hashTable)m+=` 1 ${p}
|
|
150
|
-
`}return F(m)}let f=!1,u="",h=(e.state.env.PATH||"/usr/bin:/bin").split(":");for(let m of
|
|
151
|
-
`,f=!0;continue}let p=!1;for(let
|
|
152
|
-
`,f=!0)}return f?S(u,1):L}var
|
|
150
|
+
`}return F(m)}let f=!1,u="",h=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let m of c){if(m.includes("/")){u+=`bash: hash: ${m}: cannot use / in name
|
|
151
|
+
`,f=!0;continue}let p=!1;for(let g of h){if(!g)continue;let v=`${g}/${m}`;if(await e.fs.exists(v)){e.state.hashTable.set(m,v),p=!0;break}}p||(u+=`bash: hash: ${m}: not found
|
|
152
|
+
`,f=!0)}return f?S(u,1):L}var Zn={":":[": [arguments]",`Null command.
|
|
153
153
|
No effect; the command does nothing.
|
|
154
154
|
Exit Status:
|
|
155
155
|
Always succeeds.`],".":[". filename [arguments]",`Execute commands from a file in the current shell.
|
|
@@ -494,29 +494,29 @@ eval: usage: eval [arg ...]
|
|
|
494
494
|
job specification, and reports its termination status.
|
|
495
495
|
Exit Status:
|
|
496
496
|
Returns the status of the last ID; fails if ID is invalid or an invalid
|
|
497
|
-
option is given.`]},
|
|
498
|
-
`,2)}r++}else n.push(
|
|
499
|
-
`,
|
|
497
|
+
option is given.`]},Gn=Object.keys(Zn).sort();function _s(e,t){let s=!1,n=[],r=0;for(;r<t.length;){let c=t[r];if(c==="--"){for(r++;r<t.length;)n.push(t[r]),r++;break}if(c.startsWith("-")&&c.length>1){for(let l=1;l<c.length;l++){let f=c[l];if(f==="s")s=!0;else return S(`bash: help: -${f}: invalid option
|
|
498
|
+
`,2)}r++}else n.push(c),r++}if(n.length===0)return Ii();let i="",a=!1,o="";for(let c of n){let l=Ti(c);if(l.length===0){o+=`bash: help: no help topics match \`${c}'. Try \`help help' or \`man -k ${c}' or \`info ${c}'.
|
|
499
|
+
`,a=!0;continue}for(let f of l){let[u,d]=Zn[f];s?i+=`${f}: ${u}
|
|
500
500
|
`:i+=`${f}: ${u}
|
|
501
501
|
${d}
|
|
502
|
-
`}}return{exitCode:
|
|
502
|
+
`}}return{exitCode:a?1:0,stdout:i,stderr:o}}function Ti(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),s=new RegExp(`^${t}$`);return Gn.filter(n=>s.test(n))}function Ii(){let e=[];e.push("just-bash shell builtins"),e.push("These shell commands are defined internally. Type `help' to see this list."),e.push("Type `help name' to find out more about the function `name'."),e.push("");let t=36,s=Gn.slice(),n=Math.ceil(s.length/2);for(let r=0;r<n;r++){let i=s[r]||"",a=s[r+n]||"",o=i.padEnd(t);e.push(a?`${o}${a}`:i)}return F(`${e.join(`
|
|
503
503
|
`)}
|
|
504
|
-
`)}function
|
|
505
|
-
`);let s=
|
|
506
|
-
`)}return P("","",n===0?1:0)}async function
|
|
507
|
-
`);let s=e.state.localScopes[e.state.localScopes.length-1],n="",r=0,i=!1,
|
|
508
|
-
`)}return P(
|
|
509
|
-
`,r=1;continue}if(K(e,f,"bash"),!s.has(f)){s.set(f,e.state.env
|
|
510
|
-
`,r=1;continue}let
|
|
511
|
-
`,r=1;continue}e.state.env
|
|
512
|
-
`,r=0,i=0,
|
|
513
|
-
`,
|
|
514
|
-
`,
|
|
515
|
-
`){N+=2,C=N;continue}if(
|
|
516
|
-
`){A+=2;continue}if(
|
|
504
|
+
`)}function Ri(e){let t=[],s="",n=0;for(let r of e){for(let i of r)i==="("?n++:i===")"&&n--;s?s+=` ${r}`:s=r,n===0&&(t.push(s),s="")}return s&&t.push(s),t}async function Ns(e,t){if(t.length===0)return S(`bash: let: expression expected
|
|
505
|
+
`);let s=Ri(t),n=0;for(let r of s)try{let a=he(`(( ${r} ))`).statements[0];if(a&&a.pipelines.length>0&&a.pipelines[0].commands.length>0){let o=a.pipelines[0].commands[0];o.type==="ArithmeticCommand"&&(n=await V(e,o.expression.expression))}}catch(i){return S(`bash: let: ${r}: ${i.message}
|
|
506
|
+
`)}return P("","",n===0?1:0)}async function Cs(e,t){if(e.state.localScopes.length===0)return S(`bash: local: can only be used in a function
|
|
507
|
+
`);let s=e.state.localScopes[e.state.localScopes.length-1],n="",r=0,i=!1,a=!1,o=!1,c=[];for(let l of t)if(l==="-n")i=!0;else if(l==="-a")a=!0;else if(l==="-p")o=!0;else if(l.startsWith("-")&&!l.includes("="))for(let f of l.slice(1))f==="n"?i=!0:f==="a"?a=!0:f==="p"&&(o=!0);else c.push(l);if(c.length===0){let l="",f=Array.from(s.keys()).filter(u=>!u.includes("_")||!u.match(/_\d+$/)).filter(u=>!u.includes("__length")).sort();for(let u of f){let d=e.state.env.get(u);d!==void 0&&(l+=`${u}=${d}
|
|
508
|
+
`)}return P(l,"",0)}for(let l of c){let f,u,d=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){f=d[1];let v=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(f)){n+=`bash: local: \`${l}': not a valid identifier
|
|
509
|
+
`,r=1;continue}if(K(e,f,"bash"),!s.has(f)){s.set(f,e.state.env.get(f));let y=`${f}_`;for(let w of e.state.env.keys())w.startsWith(y)&&!w.includes("__")&&(s.has(w)||s.set(w,e.state.env.get(w)))}let $=`${f}_`;for(let y of e.state.env.keys())y.startsWith($)&&!y.includes("__")&&e.state.env.delete(y);let C=ye(v);for(let y=0;y<C.length;y++)e.state.env.set(`${f}_${y}`,C[y]);e.state.env.set(`${f}__length`,String(C.length)),De(e,f),i&&Ee(e,f);continue}let h=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(h){f=h[1];let v=h[2];if(K(e,f,"bash"),!s.has(f)){s.set(f,e.state.env.get(f));let _=`${f}_`;for(let D of e.state.env.keys())D.startsWith(_)&&!D.includes("__")&&(s.has(D)||s.set(D,e.state.env.get(D)));let O=`${f}__length`;e.state.env.has(O)&&!s.has(O)&&s.set(O,e.state.env.get(O))}let $=ye(v),C=Q(e,f),y=0,w=e.state.env.get(f);C.length===0&&w!==void 0?(e.state.env.set(`${f}_0`,w),e.state.env.delete(f),y=1):C.length>0&&(y=Math.max(...C)+1);for(let _=0;_<$.length;_++)e.state.env.set(`${f}_${y+_}`,j(e,$[_]));let E=y+$.length;e.state.env.set(`${f}__length`,String(E)),De(e,f),i&&Ee(e,f);continue}let m=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(m){f=m[1];let v=j(e,m[2]);K(e,f,"bash"),s.has(f)||s.set(f,e.state.env.get(f));let $=e.state.env.get(f)??"";e.state.env.set(f,$+v),De(e,f),i&&Ee(e,f);continue}let p=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(p){f=p[1];let v=p[2],$=j(e,p[3]);if(K(e,f,"bash"),!s.has(f)){s.set(f,e.state.env.get(f));let w=`${f}_`;for(let _ of e.state.env.keys())_.startsWith(w)&&!_.includes("__")&&(s.has(_)||s.set(_,e.state.env.get(_)));let E=`${f}__length`;e.state.env.has(E)&&!s.has(E)&&s.set(E,e.state.env.get(E))}let C;try{let w=new W,E=Z(w,v);C=await V(e,E.expression)}catch{let w=parseInt(v,10);C=Number.isNaN(w)?0:w}e.state.env.set(`${f}_${C}`,$);let y=parseInt(e.state.env.get(`${f}__length`)??"0",10);C>=y&&e.state.env.set(`${f}__length`,String(C+1)),De(e,f),i&&Ee(e,f);continue}if(l.includes("=")){let v=l.indexOf("=");f=l.slice(0,v),u=j(e,l.slice(v+1))}else f=l;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(f)){n+=`bash: local: \`${l}': not a valid identifier
|
|
510
|
+
`,r=1;continue}let g=s.has(f);if(u!==void 0){let v=e.state.env.get(f);if(e.state.tempEnvBindings){let $=e.state.accessedTempEnvVars?.has(f),C=e.state.mutatedTempEnvVars?.has(f);if(!$&&!C)for(let y=e.state.tempEnvBindings.length-1;y>=0;y--){let w=e.state.tempEnvBindings[y];if(w.has(f)){v=w.get(f);break}}}Tn(e,f,v)}if(!g){let v=e.state.env.get(f);if(e.state.tempEnvBindings)for(let $=e.state.tempEnvBindings.length-1;$>=0;$--){let C=e.state.tempEnvBindings[$];if(C.has(f)){v=C.get(f);break}}if(s.set(f,v),a){let $=`${f}_`;for(let y of e.state.env.keys())y.startsWith($)&&!y.includes("__")&&(s.has(y)||s.set(y,e.state.env.get(y)));let C=`${f}__length`;e.state.env.has(C)&&!s.has(C)&&s.set(C,e.state.env.get(C))}}if(a&&u===void 0){let v=`${f}_`;for(let $ of e.state.env.keys())$.startsWith(v)&&!$.includes("__")&&e.state.env.delete($);e.state.env.set(`${f}__length`,"0")}else if(u!==void 0){if(K(e,f,"bash"),i&&u!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(u)){n+=`bash: local: \`${u}': invalid variable name for name reference
|
|
511
|
+
`,r=1;continue}e.state.env.set(f,u),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(f))}else{let v=e.state.tempEnvBindings?.some($=>$.has(f));!g&&!v&&e.state.env.delete(f)}De(e,f),i&&Ee(e,f)}return P("",n,r)}function ks(e,t,s){let n=`
|
|
512
|
+
`,r=0,i=0,a=0,o=!1,c="MAPFILE",l=0;for(;l<t.length;){let v=t[l];v==="-d"&&l+1<t.length?(n=t[l+1]===""?"\0":t[l+1]||`
|
|
513
|
+
`,l+=2):v==="-n"&&l+1<t.length?(r=Number.parseInt(t[l+1],10)||0,l+=2):v==="-O"&&l+1<t.length?(i=Number.parseInt(t[l+1],10)||0,l+=2):v==="-s"&&l+1<t.length?(a=Number.parseInt(t[l+1],10)||0,l+=2):v==="-t"?(o=!0,l++):v==="-u"||v==="-C"||v==="-c"?l+=2:(v.startsWith("-")||(c=v),l++)}let f=s;!f&&e.state.groupStdin!==void 0&&(f=e.state.groupStdin);let u=[],d=f,h=0,m=0;for(;d.length>0;){let v=d.indexOf(n);if(v===-1){if(d.length>0){if(m<a)m++;else if(r===0||h<r){let y=d,w=y.indexOf("\0");w!==-1&&(y=y.substring(0,w)),u.push(y),h++}}break}let $=d.substring(0,v),C=$.indexOf("\0");if(C!==-1&&($=$.substring(0,C)),!o&&n!=="\0"&&($+=n),d=d.substring(v+n.length),m<a){m++;continue}if(r>0&&h>=r)break;u.push($),h++}i===0&&pe(e,c);for(let v=0;v<u.length;v++)e.state.env.set(`${c}_${i+v}`,u[v]);let p=parseInt(e.state.env.get(`${c}__length`)||"0",10),g=i+u.length;return e.state.env.set(`${c}__length`,String(Math.max(p,g))),e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=""),P("","",0)}function xi(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),a=r+n+1,o=t.slice(a),c=o.indexOf(":");if(c===-1)return null;let l=Number.parseInt(o.slice(0,c),10);if(Number.isNaN(l)||l<0)return null;let f=o.slice(c+1);return{path:i,position:l,content:f}}function Li(e,t,s){return`__rw__:${e.length}:${e}:${t}:${s}`}function Os(e,t,s,n=-1){let r=!1,i=`
|
|
514
|
+
`,a="",o=-1,c=-1,l=null,f=-1,u=-1,d=[],h=0,m=!1,p=(A,N)=>{let T=1;for(;T<A.length;){let b=A[T];if(b==="r")r=!0,T++;else if(b==="s")T++;else{if(b==="d")return T+1<A.length?(i=A.substring(T+1),{nextArgIndex:N+1}):N+1<t.length?(i=t[N+1],{nextArgIndex:N+2}):{nextArgIndex:N+1};if(b==="n"){if(T+1<A.length){let k=A.substring(T+1);return o=Number.parseInt(k,10),(Number.isNaN(o)||o<0)&&(m=!0,o=0),{nextArgIndex:N+1}}else if(N+1<t.length)return o=Number.parseInt(t[N+1],10),(Number.isNaN(o)||o<0)&&(m=!0,o=0),{nextArgIndex:N+2};return{nextArgIndex:N+1}}else if(b==="N"){if(T+1<A.length){let k=A.substring(T+1);return c=Number.parseInt(k,10),(Number.isNaN(c)||c<0)&&(m=!0,c=0),{nextArgIndex:N+1}}else if(N+1<t.length)return c=Number.parseInt(t[N+1],10),(Number.isNaN(c)||c<0)&&(m=!0,c=0),{nextArgIndex:N+2};return{nextArgIndex:N+1}}else{if(b==="a")return T+1<A.length?(l=A.substring(T+1),{nextArgIndex:N+1}):N+1<t.length?(l=t[N+1],{nextArgIndex:N+2}):{nextArgIndex:N+1};if(b==="p")return T+1<A.length?(a=A.substring(T+1),{nextArgIndex:N+1}):N+1<t.length?(a=t[N+1],{nextArgIndex:N+2}):{nextArgIndex:N+1};if(b==="u"){if(T+1<A.length){let k=A.substring(T+1);return f=Number.parseInt(k,10),Number.isNaN(f)||f<0?{nextArgIndex:-2}:{nextArgIndex:N+1}}else if(N+1<t.length)return f=Number.parseInt(t[N+1],10),Number.isNaN(f)||f<0?{nextArgIndex:-2}:{nextArgIndex:N+2};return{nextArgIndex:N+1}}else if(b==="t"){if(T+1<A.length){let k=A.substring(T+1);return u=Number.parseFloat(k),Number.isNaN(u)&&(u=0),{nextArgIndex:N+1}}else if(N+1<t.length)return u=Number.parseFloat(t[N+1]),Number.isNaN(u)&&(u=0),{nextArgIndex:N+2};return{nextArgIndex:N+1}}else if(b==="e"||b==="i"||b==="P"){if(b==="i"&&N+1<t.length)return{nextArgIndex:N+2};T++}else T++}}}return{nextArgIndex:N+1}};for(;h<t.length;){let A=t[h];if(A.startsWith("-")&&A.length>1&&A!=="--"){let N=p(A,h);if(N.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(N.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=N.nextArgIndex}else if(A==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push(A),h++}if(m)return P("","",1);if(d.length===0&&l===null&&d.push("REPLY"),u===0){if(l)pe(e,l);else{for(let A of d)e.state.env.set(A,"");d.length===0&&e.state.env.set("REPLY","")}return P("","",0)}if(u<0&&u!==-1)return P("","",1);let g=s;f>=0?e.state.fileDescriptors?g=e.state.fileDescriptors.get(f)||"":g="":!g&&e.state.groupStdin!==void 0&&(g=e.state.groupStdin);let v=i===""?"\0":i,$="",C=0,y=!0,w=A=>{if(f>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(f,g.substring(A));else if(n>=0&&e.state.fileDescriptors){let N=e.state.fileDescriptors.get(n);if(N?.startsWith("__rw__:")){let T=xi(N);if(T){let b=T.position+A;e.state.fileDescriptors.set(n,Li(T.path,b,T.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=g.substring(A))};if(c>=0){let A=Math.min(c,g.length);$=g.substring(0,A),C=A,y=A>=c,w(C);let N=d[0]||"REPLY";e.state.env.set(N,$);for(let T=1;T<d.length;T++)e.state.env.set(d[T],"");return P("","",y?0:1)}else if(o>=0){let A=0,N=0,T=!1;for(;N<g.length&&A<o;){let b=g[N];if(b===v){C=N+1,T=!0;break}if(!r&&b==="\\"&&N+1<g.length){let k=g[N+1];if(k===v&&v===`
|
|
515
|
+
`){N+=2,C=N;continue}if(k===v){N+=2,A++,$+=k,C=N;continue}$+=k,N+=2,A++,C=N}else $+=b,N++,A++,C=N}y=A>=o||T,w(C)}else{C=0;let A=0;for(;A<g.length;){let N=g[A];if(N===v){C=A+v.length,y=!0;break}if(!r&&N==="\\"&&A+1<g.length){let T=g[A+1];if(T===`
|
|
516
|
+
`){A+=2;continue}if(T===v){$+=T,A+=2;continue}$+=N,$+=T,A+=2;continue}$+=N,A++}if(A>=g.length&&(y=!1,C=A,$.length===0&&g.length===0)){for(let N of d)e.state.env.set(N,"");return l&&pe(e,l),P("","",1)}w(C)}v===`
|
|
517
517
|
`&&$.endsWith(`
|
|
518
|
-
`)&&($=$.slice(0,-1));let
|
|
519
|
-
`,2);s=(r%256+256)%256}throw new
|
|
518
|
+
`)&&($=$.slice(0,-1));let E=A=>r?A:A.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",E($)),P("","",y?0:1);let _=Gs(e.state.env);if(l){let{words:A}=Vt($,_,void 0,r);pe(e,l);for(let N=0;N<A.length;N++)e.state.env.set(`${l}_${N}`,E(A[N]));return P("","",y?0:1)}let O=d.length,{words:D,wordStarts:R}=Vt($,_,O,r);for(let A=0;A<d.length;A++){let N=d[A];if(A<d.length-1)e.state.env.set(N,E(D[A]??""));else if(A<R.length){let T=$.substring(R[A]);T=Xs(T,_,r),T=E(T),e.state.env.set(N,T)}else e.state.env.set(N,"")}return P("","",y?0:1)}function Ds(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return S("bash: return: can only `return' from a function or sourced script\n");let s=e.state.lastExitCode;if(t.length>0){let n=t[0],r=Number.parseInt(n,10);if(n===""||Number.isNaN(r)||!/^-?\d+$/.test(n))return S(`bash: return: ${n}: numeric argument required
|
|
519
|
+
`,2);s=(r%256+256)%256}throw new te(s)}var Tt=`set: usage: set [-eux] [+eux] [-o option] [+o option]
|
|
520
520
|
Options:
|
|
521
521
|
-e Exit immediately if a command exits with non-zero status
|
|
522
522
|
+e Disable -e
|
|
@@ -532,145 +532,145 @@ Options:
|
|
|
532
532
|
+o pipefail Disable pipefail
|
|
533
533
|
-o xtrace Same as -x
|
|
534
534
|
+o xtrace Disable xtrace
|
|
535
|
-
`,
|
|
535
|
+
`,Xn=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]]),Kn=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]]),Yn=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],Qn=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Jn(e,t,s){t!==null&&(s&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=s,Me(e))}function Fi(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Mi(e,t){let s=Q(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env.get(`${t}_${r}`)??"";return`[${r}]=${xe(i)}`});return`${t}=(${n.join(" ")})`}function Wi(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function zi(e,t){let s=Ce(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env.get(`${t}_${r}`)??"";return`[${Wi(r)}]=${xe(i)}`});return`${t}=(${n.join(" ")} )`}function Vi(e){let t=new Set,s=e.state.associativeArrays??new Set;for(let n of e.state.env.keys()){let r=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(r){let i=r[1];s.has(i)||t.add(i)}}return t}function Bi(e){return e.state.associativeArrays??new Set}function Is(e,t){if(t.includes("--help"))return F(Tt);if(t.length===0){let n=Vi(e),r=Bi(e),i=c=>{for(let l of r){let f=`${l}_`,u=`${l}__length`;if(c!==u&&c.startsWith(f)){if(c.slice(f.length).startsWith("_length"))continue;return!0}}return!1},a=[];for(let[c,l]of e.state.env){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)||n.has(c)||r.has(c))continue;let f=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(f&&n.has(f[1]))continue;let u=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);u&&n.has(u[1])||i(c)||u&&r.has(u[1])||a.push([c,l])}let o=[];for(let[c,l]of a.sort(([f],[u])=>f<u?-1:f>u?1:0))o.push(`${c}=${kt(l)}`);for(let c of[...n].sort((l,f)=>l<f?-1:l>f?1:0))o.push(Mi(e,c));for(let c of[...r].sort((l,f)=>l<f?-1:l>f?1:0))o.push(zi(e,c));return o.sort((c,l)=>{let f=c.split("=")[0],u=l.split("=")[0];return f<u?-1:f>u?1:0}),F(o.length>0?`${o.join(`
|
|
536
536
|
`)}
|
|
537
|
-
`:"")}let s=0;for(;s<t.length;){let n=t[s];if((n==="-o"||n==="+o")&&
|
|
538
|
-
${
|
|
537
|
+
`:"")}let s=0;for(;s<t.length;){let n=t[s];if((n==="-o"||n==="+o")&&Fi(t,s)){let r=t[s+1];if(!Kn.has(r)){let i=`bash: set: ${r}: invalid option name
|
|
538
|
+
${Tt}`;if(e.state.options.posix)throw new ce(1,"",i);return S(i)}Jn(e,Kn.get(r)??null,n==="-o"),s+=2;continue}if(n==="-o"){let r=Yn.map(o=>`${o.padEnd(16)}${e.state.options[o]?"on":"off"}`),i=Qn.map(o=>`${o.padEnd(16)}off`),a=[...r,...i].sort();return F(`${a.join(`
|
|
539
539
|
`)}
|
|
540
|
-
`)}if(n==="+o"){let r=
|
|
540
|
+
`)}if(n==="+o"){let r=Yn.map(o=>`set ${e.state.options[o]?"-o":"+o"} ${o}`),i=Qn.map(o=>`set +o ${o}`),a=[...r,...i].sort();return F(`${a.join(`
|
|
541
541
|
`)}
|
|
542
|
-
`)}if(n.length>1&&(n[0]==="-"||n[0]==="+")&&n[1]!=="-"){let r=n[0]==="-";for(let i=1;i<n.length;i++){let
|
|
543
|
-
${
|
|
544
|
-
${
|
|
545
|
-
`;if(e.state.options.posix)throw new ce(1,"",
|
|
546
|
-
`;if(e.state.options.posix)throw new ce(1,"",
|
|
547
|
-
`,2);let n=s[0],r=null,i=null;if(n.includes("/")){let
|
|
548
|
-
`);let
|
|
549
|
-
`);throw
|
|
550
|
-
`,r=1;continue}let $=await
|
|
551
|
-
`,r=1;continue}if($===null)continue;if($<0){let C=fe(e,d),y=C.length,
|
|
552
|
-
`,r=1;continue}let
|
|
553
|
-
`,r=1;continue}let _=C[
|
|
554
|
-
`,r=1;continue}let f=i;if(
|
|
555
|
-
`,r=1;continue}let u=
|
|
556
|
-
`,r=1;continue}let m=await
|
|
557
|
-
`,r=1;continue}if(m===null)continue;if(m<0){let p=fe(e,
|
|
558
|
-
`,r=1;continue}let $=
|
|
559
|
-
`,r=1;continue}let C=p[$][0];
|
|
560
|
-
`,r=1;continue}let
|
|
561
|
-
`,r=1;continue}let
|
|
562
|
-
`}}}
|
|
563
|
-
`};if(
|
|
542
|
+
`)}if(n.length>1&&(n[0]==="-"||n[0]==="+")&&n[1]!=="-"){let r=n[0]==="-";for(let i=1;i<n.length;i++){let a=n[i];if(!Xn.has(a)){let o=`bash: set: ${n[0]}${a}: invalid option
|
|
543
|
+
${Tt}`;if(e.state.options.posix)throw new ce(1,"",o);return S(o)}Jn(e,Xn.get(a)??null,r)}s++;continue}if(n==="--")return Ts(e,t.slice(s+1)),L;if(n==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,Me(e),s+1<t.length)return Ts(e,t.slice(s+1)),L;s++;continue}if(n==="+"){s++;continue}if(n.startsWith("-")||n.startsWith("+")){let r=`bash: set: ${n}: invalid option
|
|
544
|
+
${Tt}`;if(e.state.options.posix)throw new ce(1,"",r);return S(r)}return Ts(e,t.slice(s)),L}return L}function Ts(e,t){let s=1;for(;e.state.env.has(String(s));)e.state.env.delete(String(s)),s++;for(let n=0;n<t.length;n++)e.state.env.set(String(n+1),t[n]);e.state.env.set("#",String(t.length)),e.state.env.set("@",t.join(" ")),e.state.env.set("*",t.join(" "))}function Rs(e,t){let s=1;if(t.length>0){let a=Number.parseInt(t[0],10);if(Number.isNaN(a)||a<0){let o=`bash: shift: ${t[0]}: numeric argument required
|
|
545
|
+
`;if(e.state.options.posix)throw new ce(1,"",o);return S(o)}s=a}let n=Number.parseInt(e.state.env.get("#")||"0",10);if(s>n){let a=`bash: shift: shift count out of range
|
|
546
|
+
`;if(e.state.options.posix)throw new ce(1,"",a);return S(a)}if(s===0)return L;let r=[];for(let a=1;a<=n;a++)r.push(e.state.env.get(String(a))||"");let i=r.slice(s);for(let a=1;a<=n;a++)e.state.env.delete(String(a));for(let a=0;a<i.length;a++)e.state.env.set(String(a+1),i[a]);return e.state.env.set("#",String(i.length)),e.state.env.set("@",i.join(" ")),L}async function xs(e,t){let s=t;if(s.length>0&&s[0]==="--"&&(s=s.slice(1)),s.length===0)return P("",`bash: source: filename argument required
|
|
547
|
+
`,2);let n=s[0],r=null,i=null;if(n.includes("/")){let l=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(l),r=l}catch{}}else{let f=(e.state.env.get("PATH")||"").split(":").filter(u=>u);for(let u of f){let d=e.fs.resolvePath(e.state.cwd,`${u}/${n}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),r=d;break}catch{}}if(i===null){let u=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(u),r=u}catch{}}}if(i===null)return S(`bash: ${n}: No such file or directory
|
|
548
|
+
`);let a=new Map;if(s.length>1){for(let f=1;f<=9;f++)a.set(String(f),e.state.env.get(String(f)));a.set("#",e.state.env.get("#")),a.set("@",e.state.env.get("@"));let l=s.slice(1);e.state.env.set("#",String(l.length)),e.state.env.set("@",l.join(" "));for(let f=0;f<l.length&&f<9;f++)e.state.env.set(String(f+1),l[f]);for(let f=l.length+1;f<=9;f++)e.state.env.delete(String(f))}let o=e.state.currentSource,c=()=>{if(e.state.sourceDepth--,e.state.currentSource=o,s.length>1)for(let[l,f]of a)f===void 0?e.state.env.delete(l):e.state.env.set(l,f)};e.state.sourceDepth++,e.state.currentSource=n;try{let l=he(i),f=await e.executeScript(l);return c(),f}catch(l){if(c(),l instanceof z)throw l;if(l instanceof te)return P(l.stdout,l.stderr,l.exitCode);if(l.name==="ParseException")return S(`bash: ${n}: ${l.message}
|
|
549
|
+
`);throw l}}function er(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Hi(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function tr(e,t){if(Hi(t))return null;try{let s=new W,n=Z(s,t);return await V(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}function sr(e,t){if(e.state.localVarStack?.has(t)){let n=_t(e,t);if(n){n.value===void 0?e.state.env.delete(t):e.state.env.set(t,n.value);let r=e.state.localVarStack?.get(t);if(!r||r.length===0)Pt(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,n.scopeIndex),Ls(e,t);else{let i=r[r.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return e.state.env.delete(t),Pt(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let n=e.state.localScopes.length-1;n>=0;n--){let r=e.state.localScopes[n];if(r.has(t)){let i=r.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),r.delete(t);let a=!1;for(let o=n-1;o>=0;o--)if(e.state.localScopes[o].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,o+1),a=!0;break}return a||Pt(e,t),!0}}return!1}function Ls(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let s=e.state.tempEnvBindings.length-1;s>=0;s--){let n=e.state.tempEnvBindings[s];if(n.has(t)){let r=n.get(t);return r===void 0?e.state.env.delete(t):e.state.env.set(t,r),n.delete(t),!0}}return!1}async function nr(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let s=t.slice(1,-1),r=new W().parseWordFromString(s,!0,!1);return I(e,r)}if(t.includes("$")){let n=new W().parseWordFromString(t,!1,!1);return I(e,n)}return t}async function Fs(e,t){let s="both",n="",r=0;for(let i of t){if(i==="-v"){s="variable";continue}if(i==="-f"){s="function";continue}if(s==="function"){e.state.functions.delete(i);continue}if(s==="variable"){let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let d=l[1],h=l[2];if(h==="@"||h==="*"){let C=fe(e,d);for(let[y]of C)e.state.env.delete(`${d}_${y}`);e.state.env.delete(d);continue}let m=e.state.associativeArrays?.has(d);if(m){let C=await nr(e,h);e.state.env.delete(`${d}_${C}`);continue}let p=jt(e,d),g=e.state.declaredVars?.has(d);if((e.state.env.has(d)||g)&&!p&&!m){n+=`bash: unset: ${d}: not an array variable
|
|
550
|
+
`,r=1;continue}let $=await tr(e,h);if($===null&&p){n+=`bash: unset: ${h}: not a valid identifier
|
|
551
|
+
`,r=1;continue}if($===null)continue;if($<0){let C=fe(e,d),y=C.length,w=e.state.currentLine;if(y===0){n+=`bash: line ${w}: unset: [${$}]: bad array subscript
|
|
552
|
+
`,r=1;continue}let E=y+$;if(E<0){n+=`bash: line ${w}: unset: [${$}]: bad array subscript
|
|
553
|
+
`,r=1;continue}let _=C[E][0];e.state.env.delete(`${d}_${_}`);continue}e.state.env.delete(`${d}_${$}`);continue}if(!er(i)){n+=`bash: unset: \`${i}': not a valid identifier
|
|
554
|
+
`,r=1;continue}let f=i;if(oe(e,i)){let d=ke(e,i);d&&d!==i&&(f=d)}if(Ie(e,f)){n+=`bash: unset: ${f}: cannot unset: readonly variable
|
|
555
|
+
`,r=1;continue}let u=ze(e,f);if(u!==void 0&&u!==e.state.callDepth)sr(e,f);else if(e.state.fullyUnsetLocals?.has(f))e.state.env.delete(f);else if(u!==void 0){let d=e.state.accessedTempEnvVars?.has(f),h=e.state.mutatedTempEnvVars?.has(f);if((d||h)&&e.state.localVarStack?.has(f)){let m=_t(e,f);m?m.value===void 0?e.state.env.delete(f):e.state.env.set(f,m.value):e.state.env.delete(f)}else e.state.env.delete(f)}else Ls(e,f)||e.state.env.delete(f);e.state.exportedVars?.delete(f);continue}let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let l=a[1],f=a[2];if(f==="@"||f==="*"){let p=fe(e,l);for(let[g]of p)e.state.env.delete(`${l}_${g}`);e.state.env.delete(l);continue}let u=e.state.associativeArrays?.has(l);if(u){let p=await nr(e,f);e.state.env.delete(`${l}_${p}`);continue}let d=jt(e,l);if(e.state.env.has(l)&&!d&&!u){n+=`bash: unset: ${l}: not an array variable
|
|
556
|
+
`,r=1;continue}let m=await tr(e,f);if(m===null&&d){n+=`bash: unset: ${f}: not a valid identifier
|
|
557
|
+
`,r=1;continue}if(m===null)continue;if(m<0){let p=fe(e,l),g=p.length,v=e.state.currentLine;if(g===0){n+=`bash: line ${v}: unset: [${m}]: bad array subscript
|
|
558
|
+
`,r=1;continue}let $=g+m;if($<0){n+=`bash: line ${v}: unset: [${m}]: bad array subscript
|
|
559
|
+
`,r=1;continue}let C=p[$][0];e.state.env.delete(`${l}_${C}`);continue}e.state.env.delete(`${l}_${m}`);continue}if(!er(i)){n+=`bash: unset: \`${i}': not a valid identifier
|
|
560
|
+
`,r=1;continue}let o=i;if(oe(e,i)){let l=ke(e,i);l&&l!==i&&(o=l)}if(Ie(e,o)){n+=`bash: unset: ${o}: cannot unset: readonly variable
|
|
561
|
+
`,r=1;continue}let c=ze(e,o);if(c!==void 0&&c!==e.state.callDepth)sr(e,o);else if(e.state.fullyUnsetLocals?.has(o))e.state.env.delete(o);else if(c!==void 0){let l=e.state.accessedTempEnvVars?.has(o),f=e.state.mutatedTempEnvVars?.has(o);if((l||f)&&e.state.localVarStack?.has(o)){let u=_t(e,o);u?u.value===void 0?e.state.env.delete(o):e.state.env.set(o,u.value):e.state.env.delete(o)}else e.state.env.delete(o)}else Ls(e,o)||e.state.env.delete(o);e.state.exportedVars?.delete(o),e.state.functions.delete(i)}return P("",n,r)}var Ms=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],ji=["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 It(e){return Ms.includes(e)}function Ui(e){return ji.includes(e)}function rr(e,t){let s=!1,n=!1,r=!1,i=!1,a=!1,o=[],c=0;for(;c<t.length;){let d=t[c];if(d==="--"){c++;break}if(d.startsWith("-")&&d.length>1){for(let h=1;h<d.length;h++){let m=d[h];switch(m){case"s":s=!0;break;case"u":n=!0;break;case"p":r=!0;break;case"q":i=!0;break;case"o":a=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${m}: invalid option
|
|
562
|
+
`}}}c++}else break}for(;c<t.length;)o.push(t[c]),c++;if(a)return qi(e,o,s,n,r,i);if(s&&n)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
|
|
563
|
+
`};if(o.length===0){if(s||n){let h=[];for(let m of Ms){let p=e.state.shoptOptions[m];s&&p?h.push(r?`shopt -s ${m}`:`${m} on`):n&&!p&&h.push(r?`shopt -u ${m}`:`${m} off`)}return{exitCode:0,stdout:h.length>0?`${h.join(`
|
|
564
564
|
`)}
|
|
565
|
-
`:"",stderr:""}}let d=[];for(let h of
|
|
565
|
+
`:"",stderr:""}}let d=[];for(let h of Ms){let m=e.state.shoptOptions[h];d.push(r?`shopt ${m?"-s":"-u"} ${h}`:`${h} ${m?"on":"off"}`)}return{exitCode:0,stdout:`${d.join(`
|
|
566
566
|
`)}
|
|
567
|
-
`,stderr:""}}let
|
|
568
|
-
`,
|
|
567
|
+
`,stderr:""}}let l=!1,f="",u=[];for(let d of o){if(!It(d)&&!Ui(d)){f+=`shopt: ${d}: invalid shell option name
|
|
568
|
+
`,l=!0;continue}if(s)It(d)&&(e.state.shoptOptions[d]=!0,Gt(e));else if(n)It(d)&&(e.state.shoptOptions[d]=!1,Gt(e));else if(It(d)){let h=e.state.shoptOptions[d];i?h||(l=!0):r?(u.push(`shopt ${h?"-s":"-u"} ${d}`),h||(l=!0)):(u.push(`${d} ${h?"on":"off"}`),h||(l=!0))}else i?l=!0:r?(u.push(`shopt -u ${d}`),l=!0):(u.push(`${d} off`),l=!0)}return{exitCode:l?1:0,stdout:u.length>0?`${u.join(`
|
|
569
569
|
`)}
|
|
570
|
-
`:"",stderr:f}}function
|
|
570
|
+
`:"",stderr:f}}function qi(e,t,s,n,r,i){let 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"]]),o=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],c=[...a.keys(),...o].sort();if(t.length===0){let d=[];for(let h of c){let m=o.includes(h),p=a.get(h),g=m||!p?!1:e.state.options[p];s&&!g||n&&g||d.push(r?`set ${g?"-o":"+o"} ${h}`:`${h} ${g?"on":"off"}`)}return{exitCode:0,stdout:d.length>0?`${d.join(`
|
|
571
571
|
`)}
|
|
572
|
-
`:"",stderr:""}}let
|
|
573
|
-
`,
|
|
572
|
+
`:"",stderr:""}}let l=!1,f="",u=[];for(let d of t){let h=a.has(d),m=o.includes(d);if(!h&&!m){f+=`shopt: ${d}: invalid option name
|
|
573
|
+
`,l=!0;continue}if(m){s||n||(i?l=!0:r?(u.push(`set +o ${d}`),l=!0):(u.push(`${d} off`),l=!0));continue}let p=a.get(d);if(p)if(s)p==="vi"?e.state.options.emacs=!1:p==="emacs"&&(e.state.options.vi=!1),e.state.options[p]=!0,Me(e);else if(n)e.state.options[p]=!1,Me(e);else{let g=e.state.options[p];i?g||(l=!0):r?(u.push(`set ${g?"-o":"+o"} ${d}`),g||(l=!0)):(u.push(`${d} ${g?"on":"off"}`),g||(l=!0))}}return{exitCode:l?1:0,stdout:u.length>0?`${u.join(`
|
|
574
574
|
`)}
|
|
575
|
-
`:"",stderr:f}}async function
|
|
576
|
-
`;h=!0,
|
|
577
|
-
`,h=!0,
|
|
578
|
-
`;else{let
|
|
579
|
-
`;f+=_}
|
|
575
|
+
`:"",stderr:f}}async function ir(e,t,s){if(t.includes("/")){let a=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(a))return{error:"not_found",path:a};let o=a.split("/").pop()||t,c=e.commands.get(o);try{let l=await e.fs.stat(a);return l.isDirectory?{error:"permission_denied",path:a}:c?{cmd:c,path:a}:(l.mode&73)!==0?{script:!0,path:a}:{error:"permission_denied",path:a}}catch{return{error:"not_found",path:a}}}if(!s&&e.state.hashTable){let a=e.state.hashTable.get(t);if(a)if(await e.fs.exists(a)){let o=e.commands.get(t);if(o)return{cmd:o,path:a};try{let c=await e.fs.stat(a);if(!c.isDirectory&&(c.mode&73)!==0)return{script:!0,path:a}}catch{}}else e.state.hashTable.delete(t)}let r=(s??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let a of r){if(!a)continue;let c=`${a.startsWith("/")?a:e.fs.resolvePath(e.state.cwd,a)}/${t}`;if(await e.fs.exists(c))try{let l=await e.fs.stat(c);if(l.isDirectory)continue;let f=(l.mode&73)!==0,u=e.commands.get(t),d=a==="/bin"||a==="/usr/bin";if(u&&d)return{cmd:u,path:c};if(f){if(u&&!d)return{script:!0,path:c};if(!u)return{script:!0,path:c}}}catch{}}if(!await e.fs.exists("/usr/bin")){let a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function Rt(e,t){let s=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let a=await e.fs.stat(i);a.isDirectory||(a.mode&73)!==0&&s.push(t)}catch{}return s}let r=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of r){if(!i)continue;let o=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(o)){try{if((await e.fs.stat(o)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?o:`${i}/${t}`)}}return s}async function cr(e,t,s,n){let r=!1,i=!1,a=!1,o=!1,c=!1,l=[];for(let p of t)if(p.startsWith("-")&&p.length>1)for(let g of p.slice(1))g==="t"?r=!0:g==="p"?i=!0:g==="P"?a=!0:g==="a"?o=!0:g==="f"&&(c=!0);else l.push(p);let f="",u="",d=0,h=!1,m=!1;for(let p of l){let g=!1;if(a){if(o){let E=await n(p);if(E.length>0){for(let _ of E)f+=`${_}
|
|
576
|
+
`;h=!0,g=!0}}else{let E=await s(p);E&&(f+=`${E}
|
|
577
|
+
`,h=!0,g=!0)}g||(m=!0);continue}let v=!c&&e.state.functions.has(p);if(o&&v){if(!i)if(r)f+=`function
|
|
578
|
+
`;else{let E=e.state.functions.get(p),_=E?ar(p,E):`${p} is a function
|
|
579
|
+
`;f+=_}g=!0}let $=e.state.env.get(`BASH_ALIAS_${p}`);if($!==void 0&&(o||!g)&&(i||(r?f+=`alias
|
|
580
580
|
`:f+=`${p} is aliased to \`${$}'
|
|
581
|
-
`),
|
|
581
|
+
`),g=!0,!o)||ss.has(p)&&(o||!g)&&(i||(r?f+=`keyword
|
|
582
582
|
`:f+=`${p} is a shell keyword
|
|
583
|
-
`),
|
|
584
|
-
`;else{let
|
|
585
|
-
`;f+=_}
|
|
583
|
+
`),g=!0,!o))continue;if(!o&&v&&!g){if(!i)if(r)f+=`function
|
|
584
|
+
`;else{let E=e.state.functions.get(p),_=E?ar(p,E):`${p} is a function
|
|
585
|
+
`;f+=_}g=!0;continue}if(!(Qe.has(p)&&(o||!g)&&(i||(r?f+=`builtin
|
|
586
586
|
`:f+=`${p} is a shell builtin
|
|
587
|
-
`),
|
|
587
|
+
`),g=!0,!o))){if(o){let E=await n(p);for(let _ of E)i?f+=`${_}
|
|
588
588
|
`:r?f+=`file
|
|
589
589
|
`:f+=`${p} is ${_}
|
|
590
|
-
`,h=!0,
|
|
590
|
+
`,h=!0,g=!0}else if(!g){let E=await s(p);E&&(i?f+=`${E}
|
|
591
591
|
`:r?f+=`file
|
|
592
|
-
`:f+=`${p} is ${
|
|
593
|
-
`,h=!0,
|
|
594
|
-
`)}}}return i?d=m&&!h?1:0:d=m?1:0,P(f,u,d)}function
|
|
592
|
+
`:f+=`${p} is ${E}
|
|
593
|
+
`,h=!0,g=!0)}if(!g&&(m=!0,!r&&!i)){let E=!0;if(p.includes("/")){let _=e.fs.resolvePath(e.state.cwd,p);await e.fs.exists(_)&&(E=!1)}E&&(u+=`bash: type: ${p}: not found
|
|
594
|
+
`)}}}return i?d=m&&!h?1:0:d=m?1:0,P(f,u,d)}function ar(e,t){let s;return t.body.type==="Group"?s=t.body.body.map(r=>tt(r)).join("; "):s=tt(t.body),`${e} is a function
|
|
595
595
|
${e} ()
|
|
596
596
|
{
|
|
597
597
|
${s}
|
|
598
598
|
}
|
|
599
|
-
`}function
|
|
600
|
-
`:r+=`alias ${
|
|
601
|
-
`;else if(
|
|
602
|
-
`:r+=`${
|
|
603
|
-
`;else if(
|
|
604
|
-
`:r+=`${
|
|
605
|
-
`;else if(e.state.functions.has(
|
|
606
|
-
`:r+=`${
|
|
607
|
-
`;else if(
|
|
608
|
-
`:r+=`${
|
|
609
|
-
`,f=!0)}catch{}f||(n&&(i+=`${
|
|
610
|
-
`),
|
|
599
|
+
`}function tt(e){if(Array.isArray(e))return e.map(t=>tt(t)).join("; ");if(e.type==="Statement"){let t=[];for(let s=0;s<e.pipelines.length;s++){let n=e.pipelines[s];t.push(Zi(n)),e.operators[s]&&t.push(e.operators[s])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,s=[];t.name&&s.push(or(t.name));for(let n of t.args)s.push(or(n));return s.join(" ")}return e.type==="Group"?`{ ${e.body.map(n=>tt(n)).join("; ")}; }`:"..."}function Zi(e){let t=e.commands.map(s=>tt(s));return(e.negated?"! ":"")+t.join(" | ")}function or(e){let t="";for(let s of e.parts)s.type==="Literal"?t+=s.value:s.type==="DoubleQuoted"?t+=`"${s.parts.map(n=>lr(n)).join("")}"`:s.type==="SingleQuoted"?t+=`'${s.value}'`:t+=lr(s);return t}function lr(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function fr(e,t,s,n){let r="",i="",a=0;for(let o of t){if(!o){a=1;continue}let c=e.state.env.get(`BASH_ALIAS_${o}`);if(c!==void 0)n?r+=`${o} is an alias for "${c}"
|
|
600
|
+
`:r+=`alias ${o}='${c}'
|
|
601
|
+
`;else if(ss.has(o))n?r+=`${o} is a shell keyword
|
|
602
|
+
`:r+=`${o}
|
|
603
|
+
`;else if(Qe.has(o))n?r+=`${o} is a shell builtin
|
|
604
|
+
`:r+=`${o}
|
|
605
|
+
`;else if(e.state.functions.has(o))n?r+=`${o} is a function
|
|
606
|
+
`:r+=`${o}
|
|
607
|
+
`;else if(o.includes("/")){let l=e.fs.resolvePath(e.state.cwd,o),f=!1;if(await e.fs.exists(l))try{let u=await e.fs.stat(l);u.isDirectory||(u.mode&73)!==0&&(n?r+=`${o} is ${o}
|
|
608
|
+
`:r+=`${o}
|
|
609
|
+
`,f=!0)}catch{}f||(n&&(i+=`${o}: not found
|
|
610
|
+
`),a=1)}else if(e.commands.has(o)){let f=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),u=null;for(let d of f){if(!d)continue;let h=`${d}/${o}`;try{let m=await e.fs.stat(h);if(!m.isDirectory&&(m.mode&73)!==0){u=h;break}}catch{}}u||(u=`/usr/bin/${o}`),n?r+=`${o} is ${u}
|
|
611
611
|
`:r+=`${u}
|
|
612
|
-
`}else n&&(i+=`${
|
|
613
|
-
`),
|
|
614
|
-
`);let[,...
|
|
612
|
+
`}else n&&(i+=`${o}: not found
|
|
613
|
+
`),a=1}return P(r,i,a)}async function ur(e,t){if(t.includes("/")){let r=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(r)){try{let i=await e.fs.stat(r);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let n=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let r of n){if(!r)continue;let a=`${r.startsWith("/")?r:e.fs.resolvePath(e.state.cwd,r)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).isDirectory)continue}catch{continue}return`${r}/${t}`}}if(e.commands.has(t)){for(let r of n)if(r==="/usr/bin"||r==="/bin")return`${r}/${t}`;return`/usr/bin/${t}`}return null}async function dr(e,t,s,n,r,i,a,o){let{ctx:c,runCommand:l}=e;if(t==="export")return As(c,s);if(t==="unset")return Fs(c,s);if(t==="exit")return Ss(c,s);if(t==="local")return Cs(c,s);if(t==="set")return Is(c,s);if(t==="break")return Kt(c,s);if(t==="continue")return cs(c,s);if(t==="return")return Ds(c,s);if(t==="eval"&&c.state.options.posix)return Ot(c,s,r);if(t==="shift")return Rs(c,s);if(t==="getopts")return Dt(c,s);if(t==="compgen")return is(c,s);if(t==="complete")return os(c,s);if(t==="compopt")return ls(c,s);if(t==="pushd")return await Es(c,s);if(t==="popd")return bs(c,s);if(t==="dirs")return $s(c,s);if(t==="source"||t===".")return xs(c,s);if(t==="read")return Os(c,s,r,o);if(t==="mapfile"||t==="readarray")return ks(c,s,r);if(t==="declare"||t==="typeset")return gs(c,s);if(t==="readonly")return ws(c,s);if(!i){let f=c.state.functions.get(t);if(f)return Ct(c,f,s,r)}if(t==="eval")return Ot(c,s,r);if(t==="cd")return await Yt(c,s);if(t===":"||t==="true")return L;if(t==="false")return q(!1);if(t==="let")return Ns(c,s);if(t==="command")return Gi(e,s,r);if(t==="builtin")return Xi(e,s,r);if(t==="shopt")return rr(c,s);if(t==="exec"){if(s.length===0)return L;let[f,...u]=s;return l(f,u,[],r,!1,!1,-1)}if(t==="wait")return L;if(t==="type")return await cr(c,s,f=>ur(c,f),f=>Rt(c,f));if(t==="hash")return Ps(c,s);if(t==="help")return _s(c,s);if(t==="["||t==="test"){let f=s;if(t==="["){if(s[s.length-1]!=="]")return S("[: missing `]'\n",2);f=s.slice(0,-1)}return Ye(c,f)}return null}async function Gi(e,t,s){let{ctx:n,runCommand:r}=e;if(t.length===0)return L;let i=!1,a=!1,o=!1,c=t;for(;c.length>0&&c[0].startsWith("-");){let u=c[0];if(u==="--"){c=c.slice(1);break}for(let d of u.slice(1))d==="p"?i=!0:d==="V"?a=!0:d==="v"&&(o=!0);c=c.slice(1)}if(c.length===0)return L;if(o||a)return await fr(n,c,o,a);let[l,...f]=c;return r(l,f,[],s,!0,i,-1)}async function Xi(e,t,s){let{runCommand:n}=e;if(t.length===0)return L;let r=t;if(r[0]==="--"&&(r=r.slice(1),r.length===0))return L;let i=r[0];if(!Qe.has(i))return S(`bash: builtin: ${i}: not a shell builtin
|
|
614
|
+
`);let[,...a]=r;return n(i,a,[],s,!0,!1,-1)}async function hr(e,t,s,n,r){let{ctx:i,buildExportedEnv:a,executeUserScript:o}=e,l=await ir(i,t,r?"/usr/bin:/bin":void 0);if(!l)return bn(t)?S(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
|
|
615
615
|
`,127):S(`bash: ${t}: command not found
|
|
616
|
-
`,127);if("error"in
|
|
616
|
+
`,127);if("error"in l)return l.error==="permission_denied"?S(`bash: ${t}: Permission denied
|
|
617
617
|
`,126):S(`bash: ${t}: No such file or directory
|
|
618
|
-
`,127);if("script"in
|
|
619
|
-
`)}}async function
|
|
620
|
-
`,exitCode:1}}async function
|
|
621
|
-
`,exitCode:1}}return{stdout:r,stderr:i,exitCode:
|
|
622
|
-
`);let
|
|
618
|
+
`,127);if("script"in l)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,l.path)),await o(l.path,s,n);let{cmd:f,path:u}=l;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u));let d=n||i.state.groupStdin||"",h=a(),m={fs:i.fs,cwd:i.state.cwd,env:i.state.env,exportedEnv:h,stdin:d,limits:i.limits,exec:i.execFn,fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo};try{return await f.execute(s,m)}catch(p){return S(`${t}: ${ve(p)}
|
|
619
|
+
`)}}async function Ws(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let n="",r="",i=0;try{for(let a of t){let o=await e.executeStatement(a);n+=o.stdout,r+=o.stderr,i=o.exitCode}}finally{e.state.inCondition=s}return{stdout:n,stderr:r,exitCode:i}}function st(e,t,s,n){if(e instanceof re)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"break",stdout:t,stderr:s};if(e instanceof ie)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"continue",stdout:t,stderr:s};if(e instanceof te||e instanceof ae||e instanceof z||e instanceof ee)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let r=ve(e);return{action:"error",stdout:t,stderr:`${s}${r}
|
|
620
|
+
`,exitCode:1}}async function xt(e,t,s="",n=""){let r=s,i=n,a=0;try{for(let o of t){let c=await e.executeStatement(o);r+=c.stdout,i+=c.stderr,a=c.exitCode}}catch(o){if(ot(o)||o instanceof ae||o instanceof z||o instanceof ee||o instanceof _e)throw o.prependOutput(r,i),o;return{stdout:r,stderr:`${i}${ve(o)}
|
|
621
|
+
`,exitCode:1}}return{stdout:r,stderr:i,exitCode:a}}async function pr(e,t){let s="",n="";for(let r of t.clauses){let i=await Ws(e,r.condition);if(s+=i.stdout,n+=i.stderr,i.exitCode===0)return xt(e,r.body,s,n)}return t.elseBody?xt(e,t.elseBody,s,n):P(s,n,0)}async function mr(e,t){let s=await ge(e,t.redirections);if(s)return s;let n="",r="",i=0,a=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return S(`bash: \`${t.variable}': not a valid identifier
|
|
622
|
+
`);let o=[];if(t.words===null)o=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)o=[];else try{for(let l of t.words){let f=await me(e,l);o.push(...f.values)}}catch(l){if(l instanceof at)return{stdout:"",stderr:l.stderr,exitCode:1};throw l}e.state.loopDepth++;try{for(let l of o){a++,a>e.limits.maxLoopIterations&&Ae(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),e.state.env.set(t.variable,l);try{for(let f of t.body){let u=await e.executeStatement(f);n+=u.stdout,r+=u.stderr,i=u.exitCode}}catch(f){let u=st(f,n,r,e.state.loopDepth);if(n=u.stdout,r=u.stderr,u.action==="break")break;if(u.action==="continue")continue;if(u.action==="error"){let d=P(n,r,u.exitCode??1);return H(e,d,t.redirections)}throw u.error}}}finally{e.state.loopDepth--}let c=P(n,r,i);return H(e,c,t.redirections)}async function yr(e,t){let s=await ge(e,t.redirections);if(s)return s;let n=t.line;n!==void 0&&(e.state.currentLine=n);let r="",i="",a=0,o=0;t.init&&await V(e,t.init.expression),e.state.loopDepth++;try{for(;o++,o>e.limits.maxLoopIterations&&Ae(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,i),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await V(e,t.condition.expression)===0));){try{for(let l of t.body){let f=await e.executeStatement(l);r+=f.stdout,i+=f.stderr,a=f.exitCode}}catch(l){let f=st(l,r,i,e.state.loopDepth);if(r=f.stdout,i=f.stderr,f.action==="break")break;if(f.action==="continue"){t.update&&await V(e,t.update.expression);continue}if(f.action==="error"){let u=P(r,i,f.exitCode??1);return H(e,u,t.redirections)}throw f.error}t.update&&await V(e,t.update.expression)}}finally{e.state.loopDepth--}let c=P(r,i,a);return H(e,c,t.redirections)}async function gr(e,t,s=""){let n="",r="",i=0,a=0,o=s;for(let l of t.redirections)if((l.operator==="<<"||l.operator==="<<-")&&l.target.type==="HereDoc"){let f=l.target,u=await I(e,f.content);f.stripTabs&&(u=u.split(`
|
|
623
623
|
`).map(d=>d.replace(/^\t+/,"")).join(`
|
|
624
|
-
`)),
|
|
625
|
-
`;else if(
|
|
626
|
-
`)}let
|
|
627
|
-
`,t||
|
|
628
|
-
`),r=e.includes(" "),i=e.includes("\\"),
|
|
629
|
-
`?
|
|
630
|
-
`}async function
|
|
631
|
-
`:""}async function
|
|
624
|
+
`)),o=u}else if(l.operator==="<<<"&&l.target.type==="Word")o=`${await I(e,l.target)}
|
|
625
|
+
`;else if(l.operator==="<"&&l.target.type==="Word")try{let f=await I(e,l.target),u=e.fs.resolvePath(e.state.cwd,f);o=await e.fs.readFile(u)}catch{let f=await I(e,l.target);return S(`bash: ${f}: No such file or directory
|
|
626
|
+
`)}let c=e.state.groupStdin;o&&(e.state.groupStdin=o),e.state.loopDepth++;try{for(;;){a++,a>e.limits.maxLoopIterations&&Ae(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r);let l=0,f=!1,u=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let m=await e.executeStatement(h);n+=m.stdout,r+=m.stderr,l=m.exitCode}}catch(h){if(h instanceof re){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;f=!0}else if(h instanceof ie){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;u=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if(f)break;if(!u){if(l!==0)break;try{for(let h of t.body){let m=await e.executeStatement(h);n+=m.stdout,r+=m.stderr,i=m.exitCode}}catch(h){let m=st(h,n,r,e.state.loopDepth);if(n=m.stdout,r=m.stderr,m.action==="break")break;if(m.action==="continue")continue;if(m.action==="error")return P(n,r,m.exitCode??1);throw m.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=c}return P(n,r,i)}async function wr(e,t){let s="",n="",r=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&Ae(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,n);let a=await Ws(e,t.condition);if(s+=a.stdout,n+=a.stderr,a.exitCode===0)break;try{for(let o of t.body){let c=await e.executeStatement(o);s+=c.stdout,n+=c.stderr,r=c.exitCode}}catch(o){let c=st(o,s,n,e.state.loopDepth);if(s=c.stdout,n=c.stderr,c.action==="break")break;if(c.action==="continue")continue;if(c.action==="error")return P(s,n,c.exitCode??1);throw c.error}}}finally{e.state.loopDepth--}return P(s,n,r)}async function vr(e,t){let s=await ge(e,t.redirections);if(s)return s;let n="",r="",i=0,a=await I(e,t.word),o=!1;for(let l=0;l<t.items.length;l++){let f=t.items[l],u=o;if(!o)for(let d of f.patterns){let h=await I(e,d);sn(d)&&(h=en(h));let m=e.state.shoptOptions.nocasematch,p=e.state.shoptOptions.extglob;if(We(a,h,m,p)){u=!0;break}}if(u){let d=await xt(e,f.body,n,r);if(n=d.stdout,r=d.stderr,i=d.exitCode,f.terminator===";;")break;f.terminator===";&"?o=!0:o=!1}else o=!1}let c=P(n,r,i);return H(e,c,t.redirections)}function zs(e,t){if(e.parts.length!==1)return!1;let s=e.parts[0];return s.type!=="Literal"?!1:t.includes(s.value)}function Er(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),a=r+n+1,o=t.slice(a),c=o.indexOf(":");if(c===-1)return null;let l=Number.parseInt(o.slice(0,c),10);if(Number.isNaN(l)||l<0)return null;let f=o.slice(c+1);return{path:i,position:l,content:f}}var br="+ ";async function $r(e){let t=e.state.env.get("PS4");if(t===void 0)return br;if(t==="")return"";try{let n=new W().parseWordFromString(t,!1,!1);return await I(e,n)}catch{return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
|
|
627
|
+
`,t||br}}function Ki(e){return e.map(t=>Yi(t)).join(" ")}function Yi(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),n=e.includes(`
|
|
628
|
+
`),r=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(s||n||r||i){let c="";for(let l of e){let f=l.charCodeAt(0);l===`
|
|
629
|
+
`?c+="\\n":l===" "?c+="\\t":l==="\\"?c+="\\\\":l==="'"?c+="'":l==='"'?c+='"':f<32||f===127?f<256?c+=`\\x${f.toString(16).padStart(2,"0")}`:c+=`\\u${f.toString(16).padStart(4,"0")}`:c+=l}return`$'${c}'`}return a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function Sr(e,t,s){if(!e.state.options.xtrace)return"";let n=await $r(e),r=[t,...s],i=Ki(r);return`${n}${i}
|
|
630
|
+
`}async function Ar(e,t,s){return e.state.options.xtrace?`${await $r(e)}${t}=${s}
|
|
631
|
+
`:""}async function Pr(e,t,s){let n=t.timed?performance.now():0,r="",i=L,a=0,o=[],c=t.commands.length>1,l=e.state.lastArg;for(let u=0;u<t.commands.length;u++){let d=t.commands[u],h=u===t.commands.length-1;c&&(e.state.lastArg="");let p=c&&(!h||!e.state.shoptOptions.lastpipe)?new Map(e.state.env):null,g;try{g=await s(d,r)}catch(v){if(v instanceof it)g={stdout:v.stdout,stderr:v.stderr,exitCode:1};else if(v instanceof z&&t.commands.length>1)g={stdout:v.stdout,stderr:v.stderr,exitCode:v.exitCode};else if(v instanceof ae&&t.commands.length>1)g={stdout:v.stdout,stderr:v.stderr,exitCode:v.exitCode};else throw p&&(e.state.env=p),v}p&&(e.state.env=p),o.push(g.exitCode),g.exitCode!==0&&(a=g.exitCode),h?i=g:t.pipeStderr?.[u]??!1?(r=g.stderr+g.stdout,i={stdout:"",stderr:"",exitCode:g.exitCode}):(r=g.stdout,i={stdout:"",stderr:g.stderr,exitCode:g.exitCode})}if(t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let u of e.state.env.keys())u.startsWith("PIPESTATUS_")&&e.state.env.delete(u);for(let u=0;u<o.length;u++)e.state.env.set(`PIPESTATUS_${u}`,String(o[u]));e.state.env.set("PIPESTATUS__length",String(o.length))}if(e.state.options.pipefail&&a!==0&&(i={...i,exitCode:a}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let d=(performance.now()-n)/1e3,h=Math.floor(d/60),m=d%60,p;t.timePosix?p=`real ${d.toFixed(2)}
|
|
632
632
|
user 0.00
|
|
633
633
|
sys 0.00
|
|
634
634
|
`:p=`
|
|
635
635
|
real ${`${h}m${m.toFixed(3)}s`}
|
|
636
636
|
user 0m0.000s
|
|
637
637
|
sys 0m0.000s
|
|
638
|
-
`,i={...i,stderr:i.stderr+p}}return
|
|
639
|
-
`,1)};let
|
|
640
|
-
`,1)};if(
|
|
641
|
-
`,1)}}if(
|
|
642
|
-
`,{continueToNext:!0,xtraceOutput:
|
|
643
|
-
`)}}async function
|
|
644
|
-
`,1)};
|
|
645
|
-
`;if(i.fatal)throw new z(1,"",
|
|
646
|
-
`,1)}}if(r=Math.max(...i.map(([
|
|
647
|
-
`,1)}}}return{index:r}}async function
|
|
648
|
-
`,1)};if(u===null)return{continueToNext:!0,xtraceOutput:""};
|
|
649
|
-
`,{continueToNext:!0,xtraceOutput:
|
|
650
|
-
`,1);return
|
|
638
|
+
`,i={...i,stderr:i.stderr+p}}return c&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=l),i}async function _r(e,t){let s=new Map,n="";for(let r of t.assignments){let i=r.name;if(r.array){let f=await Qi(e,t,i,r.array,r.append,s);if(f.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:f.error};if(n+=f.xtraceOutput,f.continueToNext)continue}let a=r.value?await I(e,r.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:P("",`bash: ${i}: bad array subscript
|
|
639
|
+
`,1)};let c=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(c){let f=await na(e,t,c[1],c[2],a,r.append,s);if(f.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:f.error};if(f.continueToNext)continue}let l=await ia(e,t,i,a,r.append,s);if(l.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:l.error};n+=l.xtraceOutput,l.continueToNext}return{continueToNext:!1,xtraceOutput:n,tempAssignments:s}}async function Qi(e,t,s,n,r,i){let a="";if(/\[.+\]$/.test(s))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: cannot assign list to array member
|
|
640
|
+
`,1)};if(oe(e,s)){let f=Qs(e,s);if(f===void 0||f==="")throw new z(1,"","");let u=ke(e,s);if(u&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(u))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: cannot assign list to array member
|
|
641
|
+
`,1)}}if(Ie(e,s)){if(t.name)return a+=`bash: ${s}: readonly variable
|
|
642
|
+
`,{continueToNext:!0,xtraceOutput:a};let f=K(e,s);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let o=e.state.associativeArrays?.has(s),c=Ji(n),l=()=>{let f=`${s}_`;for(let u of e.state.env.keys())u.startsWith(f)&&!u.includes("__")&&e.state.env.delete(u);e.state.env.delete(s)};if(o&&c?await ea(e,t,s,n,r,l,f=>{a+=f}):c?await ta(e,s,n,r,l):await sa(e,s,n,r,l),t.name){i.set(s,e.state.env.get(s));let u=`(${n.map(d=>ct(d)).join(" ")})`;e.state.env.set(s,u)}return{continueToNext:!0,xtraceOutput:a}}function Ji(e){return e.some(t=>{if(t.parts.length>=2){let s=t.parts[0],n=t.parts[1];if(s.type!=="Glob"||!s.pattern.startsWith("["))return!1;if(s.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(t.parts.length<3)return!1;let r=t.parts[2];return r.type!=="Literal"?!1:r.value.startsWith("]=")||r.value.startsWith("]+=")}return n.type!=="Literal"?!1:n.value.startsWith("]")?n.value.startsWith("]=")||n.value.startsWith("]+="):s.pattern.endsWith("]")?n.value.startsWith("=")||n.value.startsWith("+="):!1}return!1})}async function ea(e,t,s,n,r,i,a){let o=[];for(let c of n){let l=zt(c);if(l){let{key:f,valueParts:u,append:d}=l,h;u.length>0?h=await I(e,{type:"Word",parts:u}):h="",h=j(e,h),o.push({type:"keyed",key:f,value:h,append:d})}else{let f=await I(e,c);o.push({type:"invalid",expandedValue:f})}}r||i();for(let c of o)if(c.type==="keyed")if(c.append){let l=e.state.env.get(`${s}_${c.key}`)??"";e.state.env.set(`${s}_${c.key}`,l+c.value)}else e.state.env.set(`${s}_${c.key}`,c.value);else{let l=t.line??e.state.currentLine??1;a(`bash: line ${l}: ${s}: ${c.expandedValue}: must use subscript when assigning associative array
|
|
643
|
+
`)}}async function ta(e,t,s,n,r){let i=[];for(let o of s){let c=zt(o);if(c){let{key:l,valueParts:f,append:u}=c,d;f.length>0?d=await I(e,{type:"Word",parts:f}):d="",d=j(e,d),i.push({type:"keyed",indexExpr:l,value:d,append:u})}else{let l=await me(e,o);i.push({type:"non-keyed",values:l.values})}}n||r();let a=0;for(let o of i)if(o.type==="keyed"){let c;try{let l=new W,f=Z(l,o.indexExpr);c=await V(e,f.expression,!1)}catch{if(/^-?\d+$/.test(o.indexExpr))c=Number.parseInt(o.indexExpr,10);else{let l=e.state.env.get(o.indexExpr);c=l?Number.parseInt(l,10):0,Number.isNaN(c)&&(c=0)}}if(o.append){let l=e.state.env.get(`${t}_${c}`)??"";e.state.env.set(`${t}_${c}`,l+o.value)}else e.state.env.set(`${t}_${c}`,o.value);a=c+1}else for(let c of o.values)e.state.env.set(`${t}_${a++}`,c)}async function sa(e,t,s,n,r){let i=[];for(let o of s){let c=await me(e,o);i.push(...c.values)}let a=0;if(n){let o=fe(e,t);if(o.length>0)a=Math.max(...o.map(([l])=>typeof l=="number"?l:0))+1;else{let c=e.state.env.get(t);c!==void 0&&(e.state.env.set(`${t}_0`,c),e.state.env.delete(t),a=1)}}else r();for(let o=0;o<i.length;o++)e.state.env.set(`${t}_${a+o}`,i[o]);n||e.state.env.set(`${t}__length`,String(i.length))}async function na(e,t,s,n,r,i,a){let o=s;if(oe(e,s)){let u=ke(e,s);if(u&&u!==s){if(u.includes("["))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: \`${u}': not a valid identifier
|
|
644
|
+
`,1)};o=u}}if(Ie(e,o)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let u=K(e,o);if(u)return{continueToNext:!1,xtraceOutput:"",error:u}}let c=e.state.associativeArrays?.has(o),l;if(c)l=await Nr(e,o,n);else{let u=await ra(e,o,n);if(u.error)return{continueToNext:!1,xtraceOutput:"",error:u.error};l=`${o}_${u.index}`}let f=i?(e.state.env.get(l)||"")+r:r;if(t.name)a.set(l,e.state.env.get(l)),e.state.env.set(l,f);else{let u=ze(e,o);if(u!==void 0&&u===e.state.callDepth&&e.state.localScopes.length>0){let d=e.state.localScopes[e.state.localScopes.length-1];d.has(l)||d.set(l,e.state.env.get(l))}e.state.env.set(l,f)}return{continueToNext:!0,xtraceOutput:""}}async function Nr(e,t,s){let n;if(s.startsWith("'")&&s.endsWith("'"))n=s.slice(1,-1);else if(s.startsWith('"')&&s.endsWith('"')){let r=s.slice(1,-1),a=new W().parseWordFromString(r,!0,!1);n=await I(e,a)}else if(s.includes("$")){let i=new W().parseWordFromString(s,!1,!1);n=await I(e,i)}else n=s;return`${t}_${n}`}async function ra(e,t,s){let n=s;s.startsWith('"')&&s.endsWith('"')&&s.length>=2&&(n=s.slice(1,-1));let r;if(/^-?\d+$/.test(n))r=Number.parseInt(n,10);else{try{let i=new W,a=Z(i,n);r=await V(e,a.expression,!1)}catch(i){if(i instanceof Te){let c=`bash: line ${e.state.currentLine}: ${s}: ${i.message}
|
|
645
|
+
`;if(i.fatal)throw new z(1,"",c);return{index:0,error:P("",c,1)}}let a=e.state.env.get(s);r=a?Number.parseInt(a,10):0}Number.isNaN(r)&&(r=0)}if(r<0){let i=fe(e,t);if(i.length===0){let o=e.state.currentLine;return{index:0,error:P("",`bash: line ${o}: ${t}[${s}]: bad array subscript
|
|
646
|
+
`,1)}}if(r=Math.max(...i.map(([o])=>typeof o=="number"?o:0))+1+r,r<0){let o=e.state.currentLine;return{index:0,error:P("",`bash: line ${o}: ${t}[${s}]: bad array subscript
|
|
647
|
+
`,1)}}}return{index:r}}async function ia(e,t,s,n,r,i){let a="",o=s,c=null;if(oe(e,s)){let u=Js(e,s,n);if(u===void 0)return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: circular name reference
|
|
648
|
+
`,1)};if(u===null)return{continueToNext:!0,xtraceOutput:""};o=u;let d=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(c={arrayName:d[1],subscriptExpr:d[2]},o=d[1])}if(Ie(e,o)){if(t.name)return a+=`bash: ${o}: readonly variable
|
|
649
|
+
`,{continueToNext:!0,xtraceOutput:a};let u=K(e,o);if(u)return{continueToNext:!1,xtraceOutput:"",error:u}}let l;if(Je(e,o))try{let u=new W;if(r){let h=`(${e.state.env.get(o)||"0"}) + (${n})`,m=Z(u,h);l=String(await V(e,m.expression))}else{let d=Z(u,n);l=String(await V(e,d.expression))}}catch{l="0"}else{let{isArray:u}=await import("./chunks/expansion-DXWR3WZB.js"),d=u(e,o)?`${o}_0`:o;l=r?(e.state.env.get(d)||"")+n:n}l=Be(e,o,l),a+=await Ar(e,o,l);let f=o;if(c)f=await aa(e,c);else{let{isArray:u}=await import("./chunks/expansion-DXWR3WZB.js");u(e,o)&&(f=`${o}_0`)}return t.name?(i.set(f,e.state.env.get(f)),e.state.env.set(f,l)):(e.state.env.set(f,l),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(o)),e.state.tempEnvBindings?.some(u=>u.has(o))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(o))),{continueToNext:!1,xtraceOutput:a}}async function aa(e,t){let{arrayName:s,subscriptExpr:n}=t;if(e.state.associativeArrays?.has(s))return Nr(e,s,n);let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else{try{let a=new W,o=Z(a,n);i=await V(e,o.expression,!1)}catch{let a=e.state.env.get(n);i=a?Number.parseInt(a,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let a=fe(e,s);a.length>0&&(i=Math.max(...a.map(c=>c[0]))+1+i)}return`${s}_${i}`}async function Cr(e,t,s,n){let r=await ge(e,t.redirections);if(r)return r;let i=new Map(e.state.env),a=e.state.cwd,o={...e.state.options},c=e.state.localScopes,l=e.state.localVarStack,f=e.state.localVarDepth,u=e.state.fullyUnsetLocals;if(e.state.localScopes=c.map(E=>new Map(E)),l){e.state.localVarStack=new Map;for(let[E,_]of l.entries())e.state.localVarStack.set(E,_.map(O=>({...O})))}f&&(e.state.localVarDepth=new Map(f)),u&&(e.state.fullyUnsetLocals=new Map(u));let d=e.state.loopDepth,h=e.state.parentHasLoopContext;e.state.parentHasLoopContext=d>0,e.state.loopDepth=0;let m=e.state.lastArg,p=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let g=e.state.groupStdin;s&&(e.state.groupStdin=s);let v="",$="",C=0,y=()=>{e.state.env=i,e.state.cwd=a,e.state.options=o,e.state.localScopes=c,e.state.localVarStack=l,e.state.localVarDepth=f,e.state.fullyUnsetLocals=u,e.state.loopDepth=d,e.state.parentHasLoopContext=h,e.state.groupStdin=g,e.state.bashPid=p,e.state.lastArg=m};try{for(let E of t.body){let _=await n(E);v+=_.stdout,$+=_.stderr,C=_.exitCode}}catch(E){if(y(),E instanceof ee)throw E;if(E instanceof _e){v+=E.stdout,$+=E.stderr;let O=P(v,$,0);return H(e,O,t.redirections)}if(E instanceof re||E instanceof ie){v+=E.stdout,$+=E.stderr;let O=P(v,$,0);return H(e,O,t.redirections)}if(E instanceof z){v+=E.stdout,$+=E.stderr;let O=P(v,$,E.exitCode);return H(e,O,t.redirections)}if(E instanceof te){v+=E.stdout,$+=E.stderr;let O=P(v,$,E.exitCode);return H(e,O,t.redirections)}if(E instanceof ae){let O=P(v+E.stdout,$+E.stderr,E.exitCode);return H(e,O,t.redirections)}let _=P(v,`${$}${ve(E)}
|
|
650
|
+
`,1);return H(e,_,t.redirections)}y();let w=P(v,$,C);return H(e,w,t.redirections)}async function kr(e,t,s,n){let r="",i="",a=0,o=await Nt(e,t.redirections);if(o)return o;let c=s;for(let u of t.redirections)if((u.operator==="<<"||u.operator==="<<-")&&u.target.type==="HereDoc"){let d=u.target,h=await I(e,d.content);d.stripTabs&&(h=h.split(`
|
|
651
651
|
`).map(p=>p.replace(/^\t+/,"")).join(`
|
|
652
|
-
`));let m=u.fd??0;m!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(m,h)):
|
|
653
|
-
`;else if(u.operator==="<"&&u.target.type==="Word")try{let d=await
|
|
654
|
-
`,1)}let
|
|
655
|
-
`,1)}e.state.groupStdin=
|
|
656
|
-
`,127)}if(i.startsWith("#!")){let
|
|
657
|
-
`);
|
|
658
|
-
`);throw
|
|
659
|
-
`);let r=0,i=-1,
|
|
660
|
-
`).map(
|
|
661
|
-
`));let _=y.fd??0;_!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),this.ctx.state.fileDescriptors.set(_,
|
|
662
|
-
`;continue}if(y.operator==="<"&&y.target.type==="Word")try{let
|
|
663
|
-
`)}if(y.operator==="<&"&&y.target.type==="Word"){let
|
|
664
|
-
`,127)}if(f==="exec"&&(u.length===0||u[0]==="--")){for(let y of t.redirections){if(y.target.type==="HereDoc"||y.fdVariable)continue;let
|
|
665
|
-
`)}break}case"<>":{let _=this.ctx.fs.resolvePath(this.ctx.state.cwd,
|
|
666
|
-
`);return
|
|
667
|
-
`,r);return
|
|
668
|
-
|
|
652
|
+
`));let m=u.fd??0;m!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(m,h)):c=h}else if(u.operator==="<<<"&&u.target.type==="Word")c=`${await I(e,u.target)}
|
|
653
|
+
`;else if(u.operator==="<"&&u.target.type==="Word")try{let d=await I(e,u.target),h=e.fs.resolvePath(e.state.cwd,d);c=await e.fs.readFile(h)}catch{let d=await I(e,u.target);return P("",`bash: ${d}: No such file or directory
|
|
654
|
+
`,1)}let l=e.state.groupStdin;c&&(e.state.groupStdin=c);try{for(let u of t.body){let d=await n(u);r+=d.stdout,i+=d.stderr,a=d.exitCode}}catch(u){if(e.state.groupStdin=l,u instanceof ee)throw u;if(ot(u)||u instanceof ae||u instanceof z)throw u.prependOutput(r,i),u;return P(r,`${i}${ve(u)}
|
|
655
|
+
`,1)}e.state.groupStdin=l;let f=P(r,i,a);return H(e,f,t.redirections)}async function Or(e,t,s,n,r){let i;try{i=await e.fs.readFile(t)}catch{return S(`bash: ${t}: No such file or directory
|
|
656
|
+
`,127)}if(i.startsWith("#!")){let g=i.indexOf(`
|
|
657
|
+
`);g!==-1&&(i=i.slice(g+1))}let a=new Map(e.state.env),o=e.state.cwd,c={...e.state.options},l=e.state.loopDepth,f=e.state.parentHasLoopContext,u=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,m=e.state.currentSource;e.state.parentHasLoopContext=l>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,n&&(e.state.groupStdin=n),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(s.length)),e.state.env.set("@",s.join(" ")),e.state.env.set("*",s.join(" "));for(let g=0;g<s.length&&g<9;g++)e.state.env.set(String(g+1),s[g]);for(let g=s.length+1;g<=9;g++)e.state.env.delete(String(g));let p=()=>{e.state.env=a,e.state.cwd=o,e.state.options=c,e.state.loopDepth=l,e.state.parentHasLoopContext=f,e.state.lastArg=u,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=m};try{let v=new W().parse(i),$=await r(v);return p(),$}catch(g){if(p(),g instanceof z||g instanceof ee)throw g;if(g.name==="ParseException")return S(`bash: ${t}: ${g.message}
|
|
658
|
+
`);throw g}}var nt=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace}}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,n=new Set;if(t)for(let i of t)n.add(i);if(s)for(let i of s)n.add(i);if(n.size===0)return Object.create(null);let r=Object.create(null);for(let i of n){let a=this.ctx.state.env.get(i);a!==void 0&&(r[i]=a)}return r}async executeScript(t){let s="",n="",r=0;for(let i of t.statements)try{let a=await this.executeStatement(i);s+=a.stdout,n+=a.stderr,r=a.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}catch(a){if(a instanceof z)throw a.prependOutput(s,n),a;if(a instanceof ce)return s+=a.stdout,n+=a.stderr,r=a.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Ne(this.ctx.state.env)};if(a instanceof ee)throw a;if(a instanceof ae)return s+=a.stdout,n+=a.stderr,r=a.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Ne(this.ctx.state.env)};if(a instanceof Hs)return s+=a.stdout,n+=a.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Ne(this.ctx.state.env)};if(a instanceof it)return s+=a.stdout,n+=a.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Ne(this.ctx.state.env)};if(a instanceof Te){s+=a.stdout,n+=a.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(a instanceof js){s+=a.stdout,n+=a.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(a instanceof re||a instanceof ie){if(this.ctx.state.loopDepth>0)throw a.prependOutput(s,n),a;s+=a.stdout,n+=a.stderr;continue}throw a instanceof te&&a.prependOutput(s,n),a}return{stdout:s,stderr:n,exitCode:r,env:Ne(this.ctx.state.env)}}async executeUserScript(t,s,n=""){return Or(this.ctx,t,s,n,r=>this.executeScript(r))}async executeStatement(t){if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&Ae(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new lt(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return L;this.ctx.state.errexitSafe=!1;let s="",n="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(n+=`${t.sourceText}
|
|
659
|
+
`);let r=0,i=-1,a=!1;for(let l=0;l<t.pipelines.length;l++){let f=t.pipelines[l],u=l>0?t.operators[l-1]:null;if(u==="&&"&&r!==0||u==="||"&&r===0)continue;let d=await this.executePipeline(f);s+=d.stdout,n+=d.stderr,r=d.exitCode,i=l,a=f.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}let o=i<t.pipelines.length-1,c=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=o||a||c,this.ctx.state.options.errexit&&r!==0&&i===t.pipelines.length-1&&!a&&!this.ctx.state.inCondition&&!c)throw new ae(r,s,n);return P(s,n,r)}async executePipeline(t){return Pr(this.ctx,t,(s,n)=>this.executeCommand(s,n))}async executeCommand(t,s){switch(t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return pr(this.ctx,t);case"For":return mr(this.ctx,t);case"CStyleFor":return yr(this.ctx,t);case"While":return gr(this.ctx,t,s);case"Until":return wr(this.ctx,t);case"Case":return vr(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return Ln(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return L}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(n){if(n instanceof at)return S(n.stderr);throw n}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let y=t,w=100;for(;w>0;){let E=this.expandAlias(y);if(E===y)break;y=E,w--}this.aliasExpansionStack.clear(),y!==t&&(t=y)}this.ctx.state.expansionStderr="";let n=await _r(this.ctx,t);if(n.error)return n.error;let r=n.tempAssignments,i=n.xtraceOutput;if(!t.name){if(t.redirections.length>0){let w=await ge(this.ctx,t.redirections);if(w)return w;let E=P("",i,0);return H(this.ctx,E,t.redirections)}this.ctx.state.lastArg="";let y=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",P("",y,this.ctx.state.lastExitCode)}let a=t.name&&zs(t.name,["local","declare","typeset","export","readonly"]),o=Array.from(r.keys());if(o.length>0&&!a){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let y of o)this.ctx.state.tempExportedVars.add(y)}let c=await Nt(this.ctx,t.redirections);if(c){for(let[y,w]of r)w===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,w);return c}let l=-1;for(let y of t.redirections){if((y.operator==="<<"||y.operator==="<<-")&&y.target.type==="HereDoc"){let w=y.target,E=await I(this.ctx,w.content);w.stripTabs&&(E=E.split(`
|
|
660
|
+
`).map(O=>O.replace(/^\t+/,"")).join(`
|
|
661
|
+
`));let _=y.fd??0;_!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),this.ctx.state.fileDescriptors.set(_,E)):s=E;continue}if(y.operator==="<<<"&&y.target.type==="Word"){s=`${await I(this.ctx,y.target)}
|
|
662
|
+
`;continue}if(y.operator==="<"&&y.target.type==="Word")try{let w=await I(this.ctx,y.target),E=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);s=await this.ctx.fs.readFile(E)}catch{let w=await I(this.ctx,y.target);for(let[E,_]of r)_===void 0?this.ctx.state.env.delete(E):this.ctx.state.env.set(E,_);return S(`bash: ${w}: No such file or directory
|
|
663
|
+
`)}if(y.operator==="<&"&&y.target.type==="Word"){let w=await I(this.ctx,y.target),E=Number.parseInt(w,10);if(!Number.isNaN(E)&&this.ctx.state.fileDescriptors){let _=this.ctx.state.fileDescriptors.get(E);if(_!==void 0)if(_.startsWith("__rw__:")){let O=Er(_);O&&(s=O.content.slice(O.position),l=E)}else _.startsWith("__file__:")||_.startsWith("__file_append__:")||(s=_)}}}let f=await I(this.ctx,t.name),u=[],d=[];if(zs(t.name,["local","declare","typeset","export","readonly"])&&(f==="local"||f==="declare"||f==="typeset"||f==="export"||f==="readonly"))for(let y of t.args){let w=await vn(this.ctx,y);if(w)u.push(w),d.push(!0);else{let E=await En(this.ctx,y);if(E!==null)u.push(E),d.push(!0);else{let _=await me(this.ctx,y);for(let O of _.values)u.push(O),d.push(_.quoted)}}}else for(let y of t.args){let w=await me(this.ctx,y);for(let E of w.values)u.push(E),d.push(w.quoted)}if(!f){if(t.name.parts.every(w=>w.type==="CommandSubstitution"||w.type==="ParameterExpansion"||w.type==="ArithmeticExpansion")){if(u.length>0){let w=u.shift();return d.shift(),await this.runCommand(w,u,d,s,!1,!1,l)}return P("","",this.ctx.state.lastExitCode)}return S(`bash: : command not found
|
|
664
|
+
`,127)}if(f==="exec"&&(u.length===0||u[0]==="--")){for(let y of t.redirections){if(y.target.type==="HereDoc"||y.fdVariable)continue;let w=await I(this.ctx,y.target),E=y.fd??(y.operator==="<"||y.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),y.operator){case">":case">|":{let _=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);await this.ctx.fs.writeFile(_,"","utf8"),this.ctx.state.fileDescriptors.set(E,`__file__:${_}`);break}case">>":{let _=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);this.ctx.state.fileDescriptors.set(E,`__file_append__:${_}`);break}case"<":{let _=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);try{let O=await this.ctx.fs.readFile(_);this.ctx.state.fileDescriptors.set(E,O)}catch{return S(`bash: ${w}: No such file or directory
|
|
665
|
+
`)}break}case"<>":{let _=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);try{let O=await this.ctx.fs.readFile(_);this.ctx.state.fileDescriptors.set(E,`__rw__:${_.length}:${_}:0:${O}`)}catch{await this.ctx.fs.writeFile(_,"","utf8"),this.ctx.state.fileDescriptors.set(E,`__rw__:${_.length}:${_}:0:`)}break}case">&":{if(w==="-")this.ctx.state.fileDescriptors.delete(E);else if(w.endsWith("-")){let _=w.slice(0,-1),O=Number.parseInt(_,10);if(!Number.isNaN(O)){let D=this.ctx.state.fileDescriptors.get(O);D!==void 0?this.ctx.state.fileDescriptors.set(E,D):this.ctx.state.fileDescriptors.set(E,`__dupout__:${O}`),this.ctx.state.fileDescriptors.delete(O)}}else{let _=Number.parseInt(w,10);Number.isNaN(_)||this.ctx.state.fileDescriptors.set(E,`__dupout__:${_}`)}break}case"<&":{if(w==="-")this.ctx.state.fileDescriptors.delete(E);else if(w.endsWith("-")){let _=w.slice(0,-1),O=Number.parseInt(_,10);if(!Number.isNaN(O)){let D=this.ctx.state.fileDescriptors.get(O);D!==void 0?this.ctx.state.fileDescriptors.set(E,D):this.ctx.state.fileDescriptors.set(E,`__dupin__:${O}`),this.ctx.state.fileDescriptors.delete(O)}}else{let _=Number.parseInt(w,10);Number.isNaN(_)||this.ctx.state.fileDescriptors.set(E,`__dupin__:${_}`)}break}}}for(let[y,w]of r)w===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,w);if(this.ctx.state.tempExportedVars)for(let y of r.keys())this.ctx.state.tempExportedVars.delete(y);return L}let m=await Sr(this.ctx,f,u);r.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(r)));let p,g=null;try{p=await this.runCommand(f,u,d,s,!1,!1,l)}catch(y){if(y instanceof re||y instanceof ie)g=y,p=L;else throw y}let v=i+m;if(v&&(p={...p,stderr:v+p.stderr}),p=await H(this.ctx,p,t.redirections),g)throw g;if(u.length>0){let y=u[u.length-1];if((f==="declare"||f==="local"||f==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(y)){let w=y.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);w&&(y=w[1])}this.ctx.state.lastArg=y}else this.ctx.state.lastArg=f;let $=Rn(f)&&f!=="unset"&&f!=="eval";if(!this.ctx.state.options.posix||!$)for(let[y,w]of r)this.ctx.state.fullyUnsetLocals?.has(y)||(w===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,w));if(this.ctx.state.tempExportedVars)for(let y of r.keys())this.ctx.state.tempExportedVars.delete(y);return r.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(p={...p,stderr:this.ctx.state.expansionStderr+p.stderr},this.ctx.state.expansionStderr=""),p}async runCommand(t,s,n,r,i=!1,a=!1,o=-1){let c={ctx:this.ctx,runCommand:(f,u,d,h,m,p,g)=>this.runCommand(f,u,d,h,m,p,g),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(f,u,d)=>this.executeUserScript(f,u,d)},l=await dr(c,t,s,n,r,i,a,o);return l!==null?l:hr(c,t,s,r,a)}aliasExpansionStack=new Set;expandAlias(t){return Xt(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return Rt(this.ctx,t)}async executeSubshell(t,s=""){return Cr(this.ctx,t,s,n=>this.executeStatement(n))}async executeGroup(t,s=""){return kr(this.ctx,t,s,n=>this.executeStatement(n))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await ge(this.ctx,t.redirections);if(s)return s;try{let n=await V(this.ctx,t.expression.expression),r=q(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),H(this.ctx,r,t.redirections)}catch(n){let r=S(`bash: arithmetic expression: ${n.message}
|
|
666
|
+
`);return H(this.ctx,r,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await ge(this.ctx,t.redirections);if(s)return s;try{let n=await Oe(this.ctx,t.expression),r=q(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),H(this.ctx,r,t.redirections)}catch(n){let r=n instanceof Te?1:2,i=S(`bash: conditional expression: ${n.message}
|
|
667
|
+
`,r);return H(this.ctx,i,t.redirections)}}};var Pe={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:3e4};function Dr(e){return e?{maxCallDepth:e.maxCallDepth??Pe.maxCallDepth,maxCommandCount:e.maxCommandCount??Pe.maxCommandCount,maxLoopIterations:e.maxLoopIterations??Pe.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??Pe.maxAwkIterations,maxSedIterations:e.maxSedIterations??Pe.maxSedIterations,maxJqIterations:e.maxJqIterations??Pe.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??Pe.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??Pe.maxPythonTimeoutMs}:{...Pe}}function Tr(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function oa(e){let t=Tr(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function la(e,t){let s=Tr(e);if(!s)return!1;let n=oa(t);return!n||s.origin!==n.origin?!1:n.pathPrefix==="/"||n.pathPrefix===""?!0:s.pathname.startsWith(n.pathPrefix)}function Vs(e,t){return!t||t.length===0?!1:t.some(s=>la(e,s))}var He=class extends Error{constructor(t){super(`Network access denied: URL not in allow-list: ${t}`),this.name="NetworkAccessDeniedError"}},je=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},Ue=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Lt=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}};var ca=20,fa=3e4,ua=["GET","HEAD"],da=new Set(["GET","HEAD","OPTIONS"]),ha=new Set([301,302,303,307,308]);function Bs(e){let t=e.maxRedirects??ca,s=e.timeoutMs??fa,n=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??ua;function r(o){if(!e.dangerouslyAllowFullInternetAccess&&!Vs(o,e.allowedUrlPrefixes??[]))throw new He(o)}function i(o){if(e.dangerouslyAllowFullInternetAccess)return;let c=o.toUpperCase();if(!n.includes(c))throw new Lt(c,n)}async function a(o,c={}){let l=c.method?.toUpperCase()??"GET";r(o),i(l);let f=o,u=0,d=c.followRedirects??!0,h=c.timeoutMs!==void 0?Math.min(c.timeoutMs,s):s;for(;;){let m=new AbortController,p=setTimeout(()=>m.abort(),h);try{let g={method:l,headers:c.headers,signal:m.signal,redirect:"manual"};c.body&&!da.has(l)&&(g.body=c.body);let v=await fetch(f,g);if(ha.has(v.status)&&d){let $=v.headers.get("location");if(!$)return await Ir(v,f);let C=new URL($,f).href;if(!e.dangerouslyAllowFullInternetAccess&&!Vs(C,e.allowedUrlPrefixes??[]))throw new Ue(C);if(u++,u>t)throw new je(t);f=C;continue}return await Ir(v,f)}finally{clearTimeout(p)}}}return a}async function Ir(e,t){let s=Object.create(null);return e.headers.forEach((n,r)=>{s[r.toLowerCase()]=n}),{status:e.status,statusText:e.statusText,headers:s,body:await e.text(),url:t}}var rt=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;state;constructor(t={}){let s=t.fs??new Se(t.files);this.fs=s,this.useDefaultLayout=!t.cwd&&!t.files;let n=t.cwd||(this.useDefaultLayout?"/home/user":"/"),r=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
|
|
668
|
+
`],["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"],["PWD",n],["OLDPWD",n],["OPTIND","1"],...Object.entries(t.env??{})]);if(this.limits=Dr({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}}),t.network&&(this.secureFetch=Bs(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.state={env:r,cwd:n,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,bashPid:process.pid,nextVirtualPid:process.pid+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",qt(this.state.options)),this.state.env.set("BASHOPTS",Zt(this.state.shoptOptions)),hn(s,this.useDefaultLayout),n!=="/"&&s instanceof Se)try{s.mkdirSync(n,{recursive:!0})}catch{}for(let i of cn(t.commands))this.registerCommand(i);if(t.network)for(let i of fn())this.registerCommand(i);if(t.customCommands)for(let i of t.customCommands)un(i)?this.registerCommand(dn(i)):this.registerCommand(i)}registerCommand(t){this.commands.set(t.name,t);let s=this.fs;if(typeof s.writeFileSync=="function"){let n=`#!/bin/bash
|
|
669
669
|
# Built-in command: ${t.name}
|
|
670
670
|
`;try{s.writeFileSync(`/bin/${t.name}`,n)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,n)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t}async exec(t,s){if(this.state.callDepth===0&&(this.state.commandCount=0),this.state.commandCount++,this.state.commandCount>this.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option.
|
|
671
|
-
`,exitCode:1,env:
|
|
672
|
-
`,exitCode:2,env:
|
|
673
|
-
`,exitCode:2,env:
|
|
674
|
-
`,exitCode:1,env:
|
|
675
|
-
`),s=[],n=[];for(let r=0;r<t.length;r++){let i=t[r];if(n.length>0){let
|
|
676
|
-
`)}var Rt=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new $e,t?.mounts)for(let{mountPoint:s,filesystem:n}of t.mounts)this.mount(s,n)}mount(t,s){this.validateMountPath(t);let n=this.normalizePath(t);this.validateMount(n),this.mounts.set(n,{mountPoint:n,filesystem:s})}unmount(t){let s=this.normalizePath(t);if(!this.mounts.has(s))throw new Error(`No filesystem mounted at '${t}'`);this.mounts.delete(s)}getMounts(){return Array.from(this.mounts.values()).map(t=>({mountPoint:t.mountPoint,filesystem:t.filesystem}))}isMountPoint(t){let s=this.normalizePath(t);return this.mounts.has(s)}validateMountPath(t){let s=t.split("/");for(let n of s)if(n==="."||n==="..")throw new Error(`Invalid mount point '${t}': contains '.' or '..' segments`)}validateMount(t){if(t==="/")throw new Error("Cannot mount at root '/'");for(let s of this.mounts.keys())if(s!==t){if(t.startsWith(`${s}/`))throw new Error(`Cannot mount at '${t}': inside existing mount '${s}'`);if(s.startsWith(`${t}/`))throw new Error(`Cannot mount at '${t}': would contain existing mount '${s}'`)}}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`}routePath(t){let s=this.normalizePath(t),n=null,r=0;for(let i of this.mounts.values()){let o=i.mountPoint;if(s===o)return{fs:i.filesystem,relativePath:"/"};s.startsWith(`${o}/`)&&o.length>r&&(n=i,r=o.length)}if(n){let i=s.slice(r);return{fs:n.filesystem,relativePath:i||"/"}}return{fs:this.baseFs,relativePath:s}}getChildMountPoints(t){let s=this.normalizePath(t),n=s==="/"?"/":`${s}/`,r=[];for(let i of this.mounts.keys())if(i.startsWith(n)){let a=i.slice(n.length).split("/")[0];a&&!r.includes(a)&&r.push(a)}return r}async readFile(t,s){let{fs:n,relativePath:r}=this.routePath(t);return n.readFile(r,s)}async readFileBuffer(t){let{fs:s,relativePath:n}=this.routePath(t);return s.readFileBuffer(n)}async writeFile(t,s,n){let{fs:r,relativePath:i}=this.routePath(t);return r.writeFile(i,s,n)}async appendFile(t,s,n){let{fs:r,relativePath:i}=this.routePath(t);return r.appendFile(i,s,n)}async exists(t){let s=this.normalizePath(t);if(this.mounts.has(s)||this.getChildMountPoints(s).length>0)return!0;let{fs:r,relativePath:i}=this.routePath(t);return r.exists(i)}async stat(t){let s=this.normalizePath(t),n=this.mounts.get(s);if(n)try{return await n.filesystem.stat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(s).length>0)try{return await this.baseFs.stat(s)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.stat(o)}async lstat(t){let s=this.normalizePath(t),n=this.mounts.get(s);if(n)try{return await n.filesystem.lstat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(s).length>0)try{return await this.baseFs.lstat(s)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.lstat(o)}async mkdir(t,s){let n=this.normalizePath(t);if(this.mounts.has(n)){if(s?.recursive)return;throw new Error(`EEXIST: directory already exists, mkdir '${t}'`)}if(this.getChildMountPoints(n).length>0&&s?.recursive)return;let{fs:i,relativePath:o}=this.routePath(t);return i.mkdir(o,s)}async readdir(t){let s=this.normalizePath(t),n=new Set,r=null,{fs:i,relativePath:o}=this.routePath(t);try{let l=await i.readdir(o);for(let c of l)n.add(c)}catch(l){let c=l.code,f=l.message||"";if(c!=="ENOENT"&&!f.includes("ENOENT"))throw l;r=l}let a=this.getChildMountPoints(s);for(let l of a)n.add(l);if(n.size===0&&r&&!this.mounts.has(s))throw r;return Array.from(n).sort()}async rm(t,s){let n=this.normalizePath(t);if(this.mounts.has(n))throw new Error(`EBUSY: mount point, cannot remove '${t}'`);if(this.getChildMountPoints(n).length>0)throw new Error(`EBUSY: contains mount points, cannot remove '${t}'`);let{fs:i,relativePath:o}=this.routePath(t);return i.rm(o,s)}async cp(t,s,n){let r=this.routePath(t),i=this.routePath(s);return r.fs===i.fs?r.fs.cp(r.relativePath,i.relativePath,n):this.crossMountCopy(t,s,n)}async mv(t,s){let n=this.normalizePath(t);if(this.mounts.has(n))throw new Error(`EBUSY: mount point, cannot move '${t}'`);let r=this.routePath(t),i=this.routePath(s);if(r.fs===i.fs)return r.fs.mv(r.relativePath,i.relativePath);await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=new Set;for(let s of this.baseFs.getAllPaths())t.add(s);for(let s of this.mounts.keys()){let n=s.split("/").filter(Boolean),r="";for(let o of n)r=`${r}/${o}`,t.add(r);let i=this.mounts.get(s);if(i)for(let o of i.filesystem.getAllPaths())o==="/"?t.add(s):t.add(`${s}${o}`)}return Array.from(t).sort()}async chmod(t,s){let n=this.normalizePath(t),r=this.mounts.get(n);if(r)return r.filesystem.chmod("/",s);let{fs:i,relativePath:o}=this.routePath(t);return i.chmod(o,s)}async symlink(t,s){let{fs:n,relativePath:r}=this.routePath(s);return n.symlink(t,r)}async link(t,s){let n=this.routePath(t),r=this.routePath(s);if(n.fs!==r.fs)throw new Error(`EXDEV: cross-device link not permitted, link '${t}' -> '${s}'`);return n.fs.link(n.relativePath,r.relativePath)}async readlink(t){let{fs:s,relativePath:n}=this.routePath(t);return s.readlink(n)}async realpath(t){let s=this.normalizePath(t);if(this.mounts.get(s))return s;let{fs:r,relativePath:i}=this.routePath(t),o=await r.realpath(i);for(let[a,l]of this.mounts)if(s===a||s.startsWith(`${a}/`))return o==="/"?a:`${a}${o}`;return o}async crossMountCopy(t,s,n){let r=await this.lstat(t);if(r.isFile){let i=await this.readFileBuffer(t);await this.writeFile(s,i),await this.chmod(s,r.mode)}else if(r.isDirectory){if(!n?.recursive)throw new Error(`cp: ${t} is a directory (not copied)`);await this.mkdir(s,{recursive:!0});let i=await this.readdir(t);for(let o of i){let a=t==="/"?`/${o}`:`${t}/${o}`,l=s==="/"?`/${o}`:`${s}/${o}`;await this.crossMountCopy(a,l,n)}}else if(r.isSymbolicLink){let i=await this.readlink(t);await this.symlink(i,s)}}async utimes(t,s,n){let{fs:r,relativePath:i}=this.routePath(t);return r.utimes(i,s,n)}};import*as G from"node:fs";import*as je from"node:path";var po="/home/user/project",He=class{root;mountPoint;readOnly;memory=new Map;deleted=new Set;constructor(t){this.root=je.resolve(t.root);let s=t.mountPoint??po;if(this.mountPoint=s==="/"?"/":s.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${s}`);if(this.readOnly=t.readOnly??!1,!G.existsSync(this.root))throw new Error(`OverlayFs root does not exist: ${this.root}`);if(!G.statSync(this.root).isDirectory())throw new Error(`OverlayFs root is not a directory: ${this.root}`);this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){let t=this.mountPoint.split("/").filter(Boolean),s="";for(let n of t)s+=`/${n}`,this.memory.has(s)||this.memory.set(s,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.memory.set("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}mkdirSync(t,s){let r=this.normalizePath(t).split("/").filter(Boolean),i="";for(let o of r)i+=`/${o}`,this.memory.has(i)||this.memory.set(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,s){let n=this.normalizePath(t),r=this.getDirname(n);r!=="/"&&this.mkdirSync(r);let i=s instanceof Uint8Array?s:new TextEncoder().encode(s);this.memory.set(n,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let s=this.normalizePath(t),n=this.getRelativeToMount(s);if(n===null)return null;let r=je.join(this.root,n),i=je.resolve(r);return!i.startsWith(this.root)&&i!==this.root.replace(/\/$/,"")?null:i}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.memory.has(s)||(this.ensureParentDirs(s),this.memory.set(s,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(s))}async existsInOverlay(t){let s=this.normalizePath(t);if(this.deleted.has(s))return!1;if(this.memory.has(s))return!0;let n=this.toRealPath(s);if(!n)return!1;try{return await G.promises.access(n),!0}catch{return!1}}async readFile(t,s){let n=await this.readFileBuffer(t),r=le(s);return Re(n,r)}async readFileBuffer(t,s=new Set){let n=this.normalizePath(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let o=this.resolveSymlink(n,r.target);return this.readFileBuffer(o,s)}if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return r.content}let i=this.toRealPath(n);if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let o=await G.promises.lstat(i);if(o.isSymbolicLink()){let l=await G.promises.readlink(i),c=this.resolveSymlink(n,l);return this.readFileBuffer(c,s)}if(o.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);let a=await G.promises.readFile(i);return new Uint8Array(a)}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${t}'`):o}}async writeFile(t,s,n){this.assertWritable(`write '${t}'`);let r=this.normalizePath(t);this.ensureParentDirs(r);let i=le(n),o=Ee(s,i);this.memory.set(r,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(r)}async appendFile(t,s,n){this.assertWritable(`append '${t}'`);let r=this.normalizePath(t),i=le(n),o=Ee(s,i),a;try{a=await this.readFileBuffer(r)}catch{a=new Uint8Array(0)}let l=new Uint8Array(a.length+o.length);l.set(a),l.set(o,a.length),this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:420,mtime:new Date}),this.deleted.delete(r)}async exists(t){return this.existsInOverlay(t)}async stat(t,s=new Set){let n=this.normalizePath(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let a=this.resolveSymlink(n,r.target);return this.stat(a,s)}let o=0;return r.type==="file"&&(o=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:o,mtime:r.mtime}}let i=this.toRealPath(n);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let o=await G.promises.stat(i);return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:!1,mode:o.mode,size:o.size,mtime:o.mtime}}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${t}'`):o}}async lstat(t){let s=this.normalizePath(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let n=this.memory.get(s);if(n){if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime};let i=0;return n.type==="file"&&(i=n.content.length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:i,mtime:n.mtime}}let r=this.toRealPath(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await G.promises.lstat(r);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${t}'`):i}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}async mkdir(t,s){this.assertWritable(`mkdir '${t}'`);let n=this.normalizePath(t);if(await this.existsInOverlay(n)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=this.dirname(n);if(i!=="/"&&!await this.existsInOverlay(i))if(s?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.memory.set(n,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(n)}async readdirCore(t,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Map,r=new Set,i=s==="/"?"/":`${s}/`;for(let a of this.deleted)if(a.startsWith(i)){let l=a.slice(i.length),c=l.split("/")[0];c&&!l.includes("/",c.length)&&r.add(c)}for(let[a,l]of this.memory)if(a!==s&&a.startsWith(i)){let c=a.slice(i.length),f=c.split("/")[0];f&&!r.has(f)&&!c.includes("/",1)&&n.set(f,{name:f,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let o=this.toRealPath(s);if(o)try{let a=await G.promises.readdir(o,{withFileTypes:!0});for(let l of a)!r.has(l.name)&&!n.has(l.name)&&n.set(l.name,{name:l.name,isFile:l.isFile(),isDirectory:l.isDirectory(),isSymbolicLink:l.isSymbolicLink()})}catch(a){if(a.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else if(a.code!=="ENOTDIR")throw a}return n}async resolveForReaddir(t,s=!1){let n=this.normalizePath(t),r=new Set,i=s,o=this.memory.get(n);for(;o&&o.type==="symlink";){if(r.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(n),i=!0,n=this.resolveSymlink(n,o.target),o=this.memory.get(n)}if(o)return{normalized:n,outsideOverlay:!1};if(this.getRelativeToMount(n)===null)return{normalized:n,outsideOverlay:!0};let l=this.toRealPath(n);if(!l)return{normalized:n,outsideOverlay:!0};try{if((await G.promises.lstat(l)).isSymbolicLink()){let f=await G.promises.readlink(l),u=this.resolveSymlink(n,f);return this.resolveForReaddir(u,!0)}return{normalized:n,outsideOverlay:!1}}catch{return i?{normalized:n,outsideOverlay:!0}:{normalized:n,outsideOverlay:!1}}}async readdir(t){let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.keys()).sort((i,o)=>i<o?-1:i>o?1:0)}async readdirWithFileTypes(t){let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.values()).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async rm(t,s){this.assertWritable(`rm '${t}'`);let n=this.normalizePath(t);if(!await this.existsInOverlay(n)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(n)).isDirectory){let o=await this.readdir(n);if(o.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of o){let l=n==="/"?`/${a}`:`${n}/${a}`;await this.rm(l,s)}}}}catch{}this.deleted.add(n),this.memory.delete(n)}async cp(t,s,n){this.assertWritable(`cp '${s}'`);let r=this.normalizePath(t),i=this.normalizePath(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let a=await this.stat(r);if(a.isFile){let l=await this.readFileBuffer(r);await this.writeFile(i,l)}else if(a.isDirectory){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(r);for(let c of l){let f=r==="/"?`/${c}`:`${r}/${c}`,u=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(f,u,n)}}}async mv(t,s){this.assertWritable(`mv '${s}'`),await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=new Set(this.memory.keys());for(let s of this.deleted)t.delete(s);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,s){if(this.deleted.has(t))return;let n=this.toRealPath(t);if(n)try{let r=G.readdirSync(n);for(let i of r){let o=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(o))continue;s.add(o);let a=je.join(n,i);G.statSync(a).isDirectory()&&this.scanRealFs(o,s)}}catch{}}async chmod(t,s){this.assertWritable(`chmod '${t}'`);let n=this.normalizePath(t);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(n);if(i){i.mode=s;return}let o=await this.stat(n);if(o.isFile){let a=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:a,mode:s,mtime:new Date})}else o.isDirectory&&this.memory.set(n,{type:"directory",mode:s,mtime:new Date})}async symlink(t,s){this.assertWritable(`symlink '${s}'`);let n=this.normalizePath(s);if(await this.existsInOverlay(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.memory.set(n,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(n)}async link(t,s){this.assertWritable(`link '${s}'`);let n=this.normalizePath(t),r=this.normalizePath(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let o=await this.stat(n);if(!o.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, link '${s}'`);let l=await this.readFileBuffer(n);this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:o.mode,mtime:new Date}),this.deleted.delete(r)}async readlink(t){let s=this.normalizePath(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let n=this.memory.get(s);if(n){if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}let r=this.toRealPath(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{return await G.promises.readlink(r)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${t}'`):i.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${t}'`):i}}async realpath(t){let s=this.normalizePath(t),n=new Set,r=async a=>{let l=a==="/"?[]:a.slice(1).split("/"),c="";for(let f of l){if(c=`${c}/${f}`,n.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let u=this.memory.get(c),d=0,h=40;for(;u&&u.type==="symlink"&&d<h;){if(n.add(c),c=this.resolveSymlink(c,u.target),d++,n.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);u=this.memory.get(c)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!u){let m=this.toRealPath(c);if(m)try{if((await G.promises.lstat(m)).isSymbolicLink()){let w=await G.promises.readlink(m);return n.add(c),c=this.resolveSymlink(c,w),r(c)}}catch(p){throw p.code==="ENOENT"?new Error(`ENOENT: no such file or directory, realpath '${t}'`):p}}}return c||"/"},i=await r(s);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,s,n){this.assertWritable(`utimes '${t}'`);let r=this.normalizePath(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let o=this.memory.get(r);if(o){o.mtime=n;return}let a=await this.stat(r);if(a.isFile){let l=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:l,mode:a.mode,mtime:n})}else a.isDirectory&&this.memory.set(r,{type:"directory",mode:a.mode,mtime:n})}};import*as B from"node:fs";import*as we from"node:path";var xt=class{root;constructor(t){if(this.root=we.resolve(t.root),!B.existsSync(this.root))throw new Error(`ReadWriteFs root does not exist: ${this.root}`);if(!B.statSync(this.root).isDirectory())throw new Error(`ReadWriteFs root is not a directory: ${this.root}`)}toRealPath(t){let s=this.normalizePath(t),n=we.join(this.root,s);return we.resolve(n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}async readFile(t,s){let n=await this.readFileBuffer(t),r=le(s);return Re(n,r)}async readFileBuffer(t){let s=this.toRealPath(t);try{let n=await B.promises.readFile(s);return new Uint8Array(n)}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${t}'`):r.code==="EISDIR"?new Error(`EISDIR: illegal operation on a directory, read '${t}'`):n}}async writeFile(t,s,n){let r=this.toRealPath(t),i=le(n),o=Ee(s,i),a=we.dirname(r);await B.promises.mkdir(a,{recursive:!0}),await B.promises.writeFile(r,o)}async appendFile(t,s,n){let r=this.toRealPath(t),i=le(n),o=Ee(s,i),a=we.dirname(r);await B.promises.mkdir(a,{recursive:!0}),await B.promises.appendFile(r,o)}async exists(t){let s=this.toRealPath(t);try{return await B.promises.access(s),!0}catch{return!1}}async stat(t){let s=this.toRealPath(t);try{let n=await B.promises.stat(s);return{isFile:n.isFile(),isDirectory:n.isDirectory(),isSymbolicLink:!1,mode:n.mode,size:n.size,mtime:n.mtime}}catch(n){throw n.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${t}'`):n}}async lstat(t){let s=this.toRealPath(t);try{let n=await B.promises.lstat(s);return{isFile:n.isFile(),isDirectory:n.isDirectory(),isSymbolicLink:n.isSymbolicLink(),mode:n.mode,size:n.size,mtime:n.mtime}}catch(n){throw n.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${t}'`):n}}async mkdir(t,s){let n=this.toRealPath(t);try{await B.promises.mkdir(n,{recursive:s?.recursive})}catch(r){let i=r;throw i.code==="EEXIST"?new Error(`EEXIST: file already exists, mkdir '${t}'`):i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, mkdir '${t}'`):r}}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){let s=this.toRealPath(t);try{return(await B.promises.readdir(s,{withFileTypes:!0})).map(r=>({name:r.name,isFile:r.isFile(),isDirectory:r.isDirectory(),isSymbolicLink:r.isSymbolicLink()})).sort((r,i)=>r.name<i.name?-1:r.name>i.name?1:0)}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, scandir '${t}'`):r.code==="ENOTDIR"?new Error(`ENOTDIR: not a directory, scandir '${t}'`):n}}async rm(t,s){let n=this.toRealPath(t);try{await B.promises.rm(n,{recursive:s?.recursive??!1,force:s?.force??!1})}catch(r){let i=r;throw i.code==="ENOENT"&&!s?.force?new Error(`ENOENT: no such file or directory, rm '${t}'`):i.code==="ENOTEMPTY"?new Error(`ENOTEMPTY: directory not empty, rm '${t}'`):r}}async cp(t,s,n){let r=this.toRealPath(t),i=this.toRealPath(s);try{await B.promises.cp(r,i,{recursive:n?.recursive??!1})}catch(o){let a=o;throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, cp '${t}'`):a.code==="EISDIR"?new Error(`EISDIR: is a directory, cp '${t}'`):o}}async mv(t,s){let n=this.toRealPath(t),r=this.toRealPath(s),i=we.dirname(r);await B.promises.mkdir(i,{recursive:!0});try{await B.promises.rename(n,r)}catch(o){let a=o;if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(a.code==="EXDEV"){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0});return}throw o}}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=[];return this.scanDir("/",t),t}scanDir(t,s){let n=this.toRealPath(t);try{let r=B.readdirSync(n);for(let i of r){let o=t==="/"?`/${i}`:`${t}/${i}`;s.push(o);let a=we.join(n,i);B.statSync(a).isDirectory()&&this.scanDir(o,s)}}catch{}}async chmod(t,s){let n=this.toRealPath(t);try{await B.promises.chmod(n,s)}catch(r){throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, chmod '${t}'`):r}}async symlink(t,s){let n=this.toRealPath(s);try{await B.promises.symlink(t,n)}catch(r){throw r.code==="EEXIST"?new Error(`EEXIST: file already exists, symlink '${s}'`):r}}async link(t,s){let n=this.toRealPath(t),r=this.toRealPath(s);try{await B.promises.link(n,r)}catch(i){let o=i;throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, link '${t}'`):o.code==="EEXIST"?new Error(`EEXIST: file already exists, link '${s}'`):o.code==="EPERM"?new Error(`EPERM: operation not permitted, link '${t}'`):i}}async readlink(t){let s=this.toRealPath(t);try{return await B.promises.readlink(s)}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${t}'`):r.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${t}'`):n}}async realpath(t){let s=this.toRealPath(t);try{let n=await B.promises.realpath(s);return n.startsWith(this.root)?n.slice(this.root.length)||"/":n}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, realpath '${t}'`):r.code==="ELOOP"?new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`):n}}async utimes(t,s,n){let r=this.toRealPath(t);try{await B.promises.utimes(r,s,n)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, utimes '${t}'`):i}}};var Ue=class{cmdId;cwd;startedAt;exitCode;bashEnv;cmdLine;env;explicitCwd;resultPromise;constructor(t,s,n,r,i=!1){this.cmdId=crypto.randomUUID(),this.cwd=n,this.startedAt=new Date,this.bashEnv=t,this.cmdLine=s,this.env=r,this.explicitCwd=i,this.resultPromise=this.execute()}async execute(){let t=this.env||this.explicitCwd?{cwd:this.explicitCwd?this.cwd:void 0,env:this.env}:void 0,s=await this.bashEnv.exec(this.cmdLine,t);return this.exitCode=s.exitCode,s}async*logs(){let t=await this.resultPromise;t.stdout&&(yield{type:"stdout",data:t.stdout,timestamp:new Date}),t.stderr&&(yield{type:"stderr",data:t.stderr,timestamp:new Date})}async wait(){return await this.resultPromise,this}async output(){let t=await this.resultPromise;return t.stdout+t.stderr}async stdout(){return(await this.resultPromise).stdout}async stderr(){return(await this.resultPromise).stderr}async kill(){}};var Lt=class e{bashEnv;constructor(t){this.bashEnv=t}static async create(t){let s=t?.fs;if(t?.overlayRoot){if(t?.fs)throw new Error("Cannot specify both 'fs' and 'overlayRoot' options");s=new He({root:t.overlayRoot})}let n=new tt({env:t?.env,cwd:t?.cwd,fs:s,maxCallDepth:t?.maxCallDepth,maxCommandCount:t?.maxCommandCount,maxLoopIterations:t?.maxLoopIterations,network:t?.network});return new e(n)}async runCommand(t,s){let n=s?.cwd??this.bashEnv.getCwd(),r=s?.cwd!==void 0;return new Ue(this.bashEnv,t,n,s?.env,r)}async writeFiles(t){for(let[s,n]of Object.entries(t)){let r;typeof n=="string"?r=n:n.encoding==="base64"?r=Buffer.from(n.content,"base64").toString("utf-8"):r=n.content;let i=s.substring(0,s.lastIndexOf("/"))||"/";i!=="/"&&await this.bashEnv.exec(`mkdir -p ${i}`),await this.bashEnv.writeFile(s,r)}}async readFile(t,s){let n=await this.bashEnv.readFile(t);return s==="base64"?Buffer.from(n).toString("base64"):n}async mkDir(t,s){let n=s?.recursive?"-p":"";await this.bashEnv.exec(`mkdir ${n} ${t}`)}async stop(){}async extendTimeout(t){}get domain(){}get bashEnvInstance(){return this.bashEnv}};export{tt as Bash,$e as InMemoryFs,Rt as MountableFs,ze as NetworkAccessDeniedError,He as OverlayFs,xt as ReadWriteFs,Be as RedirectNotAllowedError,Lt as Sandbox,Ue as SandboxCommand,Ve as TooManyRedirectsError,Fr as defineCommand,xr as getCommandNames,Lr as getNetworkCommandNames};
|
|
671
|
+
`,exitCode:1,env:de(this.state.env,s?.env)};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:de(this.state.env,s?.env)};this.logger?.info("exec",{command:t});let n=s?.cwd??this.state.cwd,r,i=n;if(s?.cwd)if(s.env&&"PWD"in s.env)r=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{r=await this.fs.realpath(n),i=r}catch{r=n}else r=n;let a=new Map(this.state.env);if(s?.env)for(let[l,f]of Object.entries(s.env))a.set(l,f);r!==void 0&&a.set("PWD",r);let o={...this.state,env:a,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable},c=t;s?.rawScript||(c=pa(t));try{let l=he(c),f={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn},d=await new nt(f,o).executeScript(l);return this.logResult(d)}catch(l){if(l instanceof z)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode,env:de(this.state.env,s?.env)});if(l instanceof ce)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode,env:de(this.state.env,s?.env)});if(l instanceof Te)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:1,env:de(this.state.env,s?.env)});if(l instanceof ee)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:ee.EXIT_CODE,env:de(this.state.env,s?.env)});if(l.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${l.message}
|
|
672
|
+
`,exitCode:2,env:de(this.state.env,s?.env)});if(l instanceof Zs)return this.logResult({stdout:"",stderr:`bash: ${l.message}
|
|
673
|
+
`,exitCode:2,env:de(this.state.env,s?.env)});if(l instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${l.message}
|
|
674
|
+
`,exitCode:1,env:de(this.state.env,s?.env)});throw l}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,s){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),s)}getCwd(){return this.state.cwd}getEnv(){return Ne(this.state.env)}};function pa(e){let t=e.split(`
|
|
675
|
+
`),s=[],n=[];for(let r=0;r<t.length;r++){let i=t[r];if(n.length>0){let c=n[n.length-1];if((c.stripTabs?i.replace(/^\t+/,""):i)===c.delimiter){s.push(i.trimStart()),n.pop();continue}s.push(i);continue}let a=i.trimStart();s.push(a);let o=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let c of a.matchAll(o)){let l=c[1]==="-",f=c[3];n.push({delimiter:f,stripTabs:l})}}return s.join(`
|
|
676
|
+
`)}var Ft=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new Se,t?.mounts)for(let{mountPoint:s,filesystem:n}of t.mounts)this.mount(s,n)}mount(t,s){this.validateMountPath(t);let n=this.normalizePath(t);this.validateMount(n),this.mounts.set(n,{mountPoint:n,filesystem:s})}unmount(t){let s=this.normalizePath(t);if(!this.mounts.has(s))throw new Error(`No filesystem mounted at '${t}'`);this.mounts.delete(s)}getMounts(){return Array.from(this.mounts.values()).map(t=>({mountPoint:t.mountPoint,filesystem:t.filesystem}))}isMountPoint(t){let s=this.normalizePath(t);return this.mounts.has(s)}validateMountPath(t){let s=t.split("/");for(let n of s)if(n==="."||n==="..")throw new Error(`Invalid mount point '${t}': contains '.' or '..' segments`)}validateMount(t){if(t==="/")throw new Error("Cannot mount at root '/'");for(let s of this.mounts.keys())if(s!==t){if(t.startsWith(`${s}/`))throw new Error(`Cannot mount at '${t}': inside existing mount '${s}'`);if(s.startsWith(`${t}/`))throw new Error(`Cannot mount at '${t}': would contain existing mount '${s}'`)}}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`}routePath(t){let s=this.normalizePath(t),n=null,r=0;for(let i of this.mounts.values()){let a=i.mountPoint;if(s===a)return{fs:i.filesystem,relativePath:"/"};s.startsWith(`${a}/`)&&a.length>r&&(n=i,r=a.length)}if(n){let i=s.slice(r);return{fs:n.filesystem,relativePath:i||"/"}}return{fs:this.baseFs,relativePath:s}}getChildMountPoints(t){let s=this.normalizePath(t),n=s==="/"?"/":`${s}/`,r=[];for(let i of this.mounts.keys())if(i.startsWith(n)){let o=i.slice(n.length).split("/")[0];o&&!r.includes(o)&&r.push(o)}return r}async readFile(t,s){let{fs:n,relativePath:r}=this.routePath(t);return n.readFile(r,s)}async readFileBuffer(t){let{fs:s,relativePath:n}=this.routePath(t);return s.readFileBuffer(n)}async writeFile(t,s,n){let{fs:r,relativePath:i}=this.routePath(t);return r.writeFile(i,s,n)}async appendFile(t,s,n){let{fs:r,relativePath:i}=this.routePath(t);return r.appendFile(i,s,n)}async exists(t){let s=this.normalizePath(t);if(this.mounts.has(s)||this.getChildMountPoints(s).length>0)return!0;let{fs:r,relativePath:i}=this.routePath(t);return r.exists(i)}async stat(t){let s=this.normalizePath(t),n=this.mounts.get(s);if(n)try{return await n.filesystem.stat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(s).length>0)try{return await this.baseFs.stat(s)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:a}=this.routePath(t);return i.stat(a)}async lstat(t){let s=this.normalizePath(t),n=this.mounts.get(s);if(n)try{return await n.filesystem.lstat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(s).length>0)try{return await this.baseFs.lstat(s)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:a}=this.routePath(t);return i.lstat(a)}async mkdir(t,s){let n=this.normalizePath(t);if(this.mounts.has(n)){if(s?.recursive)return;throw new Error(`EEXIST: directory already exists, mkdir '${t}'`)}if(this.getChildMountPoints(n).length>0&&s?.recursive)return;let{fs:i,relativePath:a}=this.routePath(t);return i.mkdir(a,s)}async readdir(t){let s=this.normalizePath(t),n=new Set,r=null,{fs:i,relativePath:a}=this.routePath(t);try{let c=await i.readdir(a);for(let l of c)n.add(l)}catch(c){let l=c.code,f=c.message||"";if(l!=="ENOENT"&&!f.includes("ENOENT"))throw c;r=c}let o=this.getChildMountPoints(s);for(let c of o)n.add(c);if(n.size===0&&r&&!this.mounts.has(s))throw r;return Array.from(n).sort()}async rm(t,s){let n=this.normalizePath(t);if(this.mounts.has(n))throw new Error(`EBUSY: mount point, cannot remove '${t}'`);if(this.getChildMountPoints(n).length>0)throw new Error(`EBUSY: contains mount points, cannot remove '${t}'`);let{fs:i,relativePath:a}=this.routePath(t);return i.rm(a,s)}async cp(t,s,n){let r=this.routePath(t),i=this.routePath(s);return r.fs===i.fs?r.fs.cp(r.relativePath,i.relativePath,n):this.crossMountCopy(t,s,n)}async mv(t,s){let n=this.normalizePath(t);if(this.mounts.has(n))throw new Error(`EBUSY: mount point, cannot move '${t}'`);let r=this.routePath(t),i=this.routePath(s);if(r.fs===i.fs)return r.fs.mv(r.relativePath,i.relativePath);await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=new Set;for(let s of this.baseFs.getAllPaths())t.add(s);for(let s of this.mounts.keys()){let n=s.split("/").filter(Boolean),r="";for(let a of n)r=`${r}/${a}`,t.add(r);let i=this.mounts.get(s);if(i)for(let a of i.filesystem.getAllPaths())a==="/"?t.add(s):t.add(`${s}${a}`)}return Array.from(t).sort()}async chmod(t,s){let n=this.normalizePath(t),r=this.mounts.get(n);if(r)return r.filesystem.chmod("/",s);let{fs:i,relativePath:a}=this.routePath(t);return i.chmod(a,s)}async symlink(t,s){let{fs:n,relativePath:r}=this.routePath(s);return n.symlink(t,r)}async link(t,s){let n=this.routePath(t),r=this.routePath(s);if(n.fs!==r.fs)throw new Error(`EXDEV: cross-device link not permitted, link '${t}' -> '${s}'`);return n.fs.link(n.relativePath,r.relativePath)}async readlink(t){let{fs:s,relativePath:n}=this.routePath(t);return s.readlink(n)}async realpath(t){let s=this.normalizePath(t);if(this.mounts.get(s))return s;let{fs:r,relativePath:i}=this.routePath(t),a=await r.realpath(i);for(let[o,c]of this.mounts)if(s===o||s.startsWith(`${o}/`))return a==="/"?o:`${o}${a}`;return a}async crossMountCopy(t,s,n){let r=await this.lstat(t);if(r.isFile){let i=await this.readFileBuffer(t);await this.writeFile(s,i),await this.chmod(s,r.mode)}else if(r.isDirectory){if(!n?.recursive)throw new Error(`cp: ${t} is a directory (not copied)`);await this.mkdir(s,{recursive:!0});let i=await this.readdir(t);for(let a of i){let o=t==="/"?`/${a}`:`${t}/${a}`,c=s==="/"?`/${a}`:`${s}/${a}`;await this.crossMountCopy(o,c,n)}}else if(r.isSymbolicLink){let i=await this.readlink(t);await this.symlink(i,s)}}async utimes(t,s,n){let{fs:r,relativePath:i}=this.routePath(t);return r.utimes(i,s,n)}};import*as G from"node:fs";import*as qe from"node:path";var ma="/home/user/project",Ze=class{root;mountPoint;readOnly;memory=new Map;deleted=new Set;constructor(t){this.root=qe.resolve(t.root);let s=t.mountPoint??ma;if(this.mountPoint=s==="/"?"/":s.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${s}`);if(this.readOnly=t.readOnly??!1,!G.existsSync(this.root))throw new Error(`OverlayFs root does not exist: ${this.root}`);if(!G.statSync(this.root).isDirectory())throw new Error(`OverlayFs root is not a directory: ${this.root}`);this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){let t=this.mountPoint.split("/").filter(Boolean),s="";for(let n of t)s+=`/${n}`,this.memory.has(s)||this.memory.set(s,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.memory.set("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}mkdirSync(t,s){let r=this.normalizePath(t).split("/").filter(Boolean),i="";for(let a of r)i+=`/${a}`,this.memory.has(i)||this.memory.set(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,s){let n=this.normalizePath(t),r=this.getDirname(n);r!=="/"&&this.mkdirSync(r);let i=s instanceof Uint8Array?s:new TextEncoder().encode(s);this.memory.set(n,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let s=this.normalizePath(t),n=this.getRelativeToMount(s);if(n===null)return null;let r=qe.join(this.root,n),i=qe.resolve(r);return!i.startsWith(this.root)&&i!==this.root.replace(/\/$/,"")?null:i}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.memory.has(s)||(this.ensureParentDirs(s),this.memory.set(s,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(s))}async existsInOverlay(t){let s=this.normalizePath(t);if(this.deleted.has(s))return!1;if(this.memory.has(s))return!0;let n=this.toRealPath(s);if(!n)return!1;try{return await G.promises.access(n),!0}catch{return!1}}async readFile(t,s){let n=await this.readFileBuffer(t),r=le(s);return Fe(n,r)}async readFileBuffer(t,s=new Set){let n=this.normalizePath(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let a=this.resolveSymlink(n,r.target);return this.readFileBuffer(a,s)}if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return r.content}let i=this.toRealPath(n);if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let a=await G.promises.lstat(i);if(a.isSymbolicLink()){let c=await G.promises.readlink(i),l=this.resolveSymlink(n,c);return this.readFileBuffer(l,s)}if(a.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);let o=await G.promises.readFile(i);return new Uint8Array(o)}catch(a){throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${t}'`):a}}async writeFile(t,s,n){this.assertWritable(`write '${t}'`);let r=this.normalizePath(t);this.ensureParentDirs(r);let i=le(n),a=$e(s,i);this.memory.set(r,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(r)}async appendFile(t,s,n){this.assertWritable(`append '${t}'`);let r=this.normalizePath(t),i=le(n),a=$e(s,i),o;try{o=await this.readFileBuffer(r)}catch{o=new Uint8Array(0)}let c=new Uint8Array(o.length+a.length);c.set(o),c.set(a,o.length),this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:c,mode:420,mtime:new Date}),this.deleted.delete(r)}async exists(t){return this.existsInOverlay(t)}async stat(t,s=new Set){let n=this.normalizePath(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let o=this.resolveSymlink(n,r.target);return this.stat(o,s)}let a=0;return r.type==="file"&&(a=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:a,mtime:r.mtime}}let i=this.toRealPath(n);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let a=await G.promises.stat(i);return{isFile:a.isFile(),isDirectory:a.isDirectory(),isSymbolicLink:!1,mode:a.mode,size:a.size,mtime:a.mtime}}catch(a){throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${t}'`):a}}async lstat(t){let s=this.normalizePath(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let n=this.memory.get(s);if(n){if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime};let i=0;return n.type==="file"&&(i=n.content.length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:i,mtime:n.mtime}}let r=this.toRealPath(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await G.promises.lstat(r);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${t}'`):i}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}async mkdir(t,s){this.assertWritable(`mkdir '${t}'`);let n=this.normalizePath(t);if(await this.existsInOverlay(n)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=this.dirname(n);if(i!=="/"&&!await this.existsInOverlay(i))if(s?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.memory.set(n,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(n)}async readdirCore(t,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Map,r=new Set,i=s==="/"?"/":`${s}/`;for(let o of this.deleted)if(o.startsWith(i)){let c=o.slice(i.length),l=c.split("/")[0];l&&!c.includes("/",l.length)&&r.add(l)}for(let[o,c]of this.memory)if(o!==s&&o.startsWith(i)){let l=o.slice(i.length),f=l.split("/")[0];f&&!r.has(f)&&!l.includes("/",1)&&n.set(f,{name:f,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}let a=this.toRealPath(s);if(a)try{let o=await G.promises.readdir(a,{withFileTypes:!0});for(let c of o)!r.has(c.name)&&!n.has(c.name)&&n.set(c.name,{name:c.name,isFile:c.isFile(),isDirectory:c.isDirectory(),isSymbolicLink:c.isSymbolicLink()})}catch(o){if(o.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else if(o.code!=="ENOTDIR")throw o}return n}async resolveForReaddir(t,s=!1){let n=this.normalizePath(t),r=new Set,i=s,a=this.memory.get(n);for(;a&&a.type==="symlink";){if(r.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(n),i=!0,n=this.resolveSymlink(n,a.target),a=this.memory.get(n)}if(a)return{normalized:n,outsideOverlay:!1};if(this.getRelativeToMount(n)===null)return{normalized:n,outsideOverlay:!0};let c=this.toRealPath(n);if(!c)return{normalized:n,outsideOverlay:!0};try{if((await G.promises.lstat(c)).isSymbolicLink()){let f=await G.promises.readlink(c),u=this.resolveSymlink(n,f);return this.resolveForReaddir(u,!0)}return{normalized:n,outsideOverlay:!1}}catch{return i?{normalized:n,outsideOverlay:!0}:{normalized:n,outsideOverlay:!1}}}async readdir(t){let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.keys()).sort((i,a)=>i<a?-1:i>a?1:0)}async readdirWithFileTypes(t){let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.values()).sort((i,a)=>i.name<a.name?-1:i.name>a.name?1:0)}async rm(t,s){this.assertWritable(`rm '${t}'`);let n=this.normalizePath(t);if(!await this.existsInOverlay(n)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(n)).isDirectory){let a=await this.readdir(n);if(a.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of a){let c=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(c,s)}}}}catch{}this.deleted.add(n),this.memory.delete(n)}async cp(t,s,n){this.assertWritable(`cp '${s}'`);let r=this.normalizePath(t),i=this.normalizePath(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let o=await this.stat(r);if(o.isFile){let c=await this.readFileBuffer(r);await this.writeFile(i,c)}else if(o.isDirectory){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let c=await this.readdir(r);for(let l of c){let f=r==="/"?`/${l}`:`${r}/${l}`,u=i==="/"?`/${l}`:`${i}/${l}`;await this.cp(f,u,n)}}}async mv(t,s){this.assertWritable(`mv '${s}'`),await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=new Set(this.memory.keys());for(let s of this.deleted)t.delete(s);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,s){if(this.deleted.has(t))return;let n=this.toRealPath(t);if(n)try{let r=G.readdirSync(n);for(let i of r){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;s.add(a);let o=qe.join(n,i);G.statSync(o).isDirectory()&&this.scanRealFs(a,s)}}catch{}}async chmod(t,s){this.assertWritable(`chmod '${t}'`);let n=this.normalizePath(t);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(n);if(i){i.mode=s;return}let a=await this.stat(n);if(a.isFile){let o=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:o,mode:s,mtime:new Date})}else a.isDirectory&&this.memory.set(n,{type:"directory",mode:s,mtime:new Date})}async symlink(t,s){this.assertWritable(`symlink '${s}'`);let n=this.normalizePath(s);if(await this.existsInOverlay(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.memory.set(n,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(n)}async link(t,s){this.assertWritable(`link '${s}'`);let n=this.normalizePath(t),r=this.normalizePath(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let a=await this.stat(n);if(!a.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, link '${s}'`);let c=await this.readFileBuffer(n);this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:c,mode:a.mode,mtime:new Date}),this.deleted.delete(r)}async readlink(t){let s=this.normalizePath(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let n=this.memory.get(s);if(n){if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}let r=this.toRealPath(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{return await G.promises.readlink(r)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${t}'`):i.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${t}'`):i}}async realpath(t){let s=this.normalizePath(t),n=new Set,r=async o=>{let c=o==="/"?[]:o.slice(1).split("/"),l="";for(let f of c){if(l=`${l}/${f}`,n.has(l))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(l))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let u=this.memory.get(l),d=0,h=40;for(;u&&u.type==="symlink"&&d<h;){if(n.add(l),l=this.resolveSymlink(l,u.target),d++,n.has(l))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(l))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);u=this.memory.get(l)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!u){let m=this.toRealPath(l);if(m)try{if((await G.promises.lstat(m)).isSymbolicLink()){let g=await G.promises.readlink(m);return n.add(l),l=this.resolveSymlink(l,g),r(l)}}catch(p){throw p.code==="ENOENT"?new Error(`ENOENT: no such file or directory, realpath '${t}'`):p}}}return l||"/"},i=await r(s);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,s,n){this.assertWritable(`utimes '${t}'`);let r=this.normalizePath(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let a=this.memory.get(r);if(a){a.mtime=n;return}let o=await this.stat(r);if(o.isFile){let c=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:c,mode:o.mode,mtime:n})}else o.isDirectory&&this.memory.set(r,{type:"directory",mode:o.mode,mtime:n})}};import*as B from"node:fs";import*as we from"node:path";var Mt=class{root;constructor(t){if(this.root=we.resolve(t.root),!B.existsSync(this.root))throw new Error(`ReadWriteFs root does not exist: ${this.root}`);if(!B.statSync(this.root).isDirectory())throw new Error(`ReadWriteFs root is not a directory: ${this.root}`)}toRealPath(t){let s=this.normalizePath(t),n=we.join(this.root,s);return we.resolve(n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}async readFile(t,s){let n=await this.readFileBuffer(t),r=le(s);return Fe(n,r)}async readFileBuffer(t){let s=this.toRealPath(t);try{let n=await B.promises.readFile(s);return new Uint8Array(n)}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${t}'`):r.code==="EISDIR"?new Error(`EISDIR: illegal operation on a directory, read '${t}'`):n}}async writeFile(t,s,n){let r=this.toRealPath(t),i=le(n),a=$e(s,i),o=we.dirname(r);await B.promises.mkdir(o,{recursive:!0}),await B.promises.writeFile(r,a)}async appendFile(t,s,n){let r=this.toRealPath(t),i=le(n),a=$e(s,i),o=we.dirname(r);await B.promises.mkdir(o,{recursive:!0}),await B.promises.appendFile(r,a)}async exists(t){let s=this.toRealPath(t);try{return await B.promises.access(s),!0}catch{return!1}}async stat(t){let s=this.toRealPath(t);try{let n=await B.promises.stat(s);return{isFile:n.isFile(),isDirectory:n.isDirectory(),isSymbolicLink:!1,mode:n.mode,size:n.size,mtime:n.mtime}}catch(n){throw n.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${t}'`):n}}async lstat(t){let s=this.toRealPath(t);try{let n=await B.promises.lstat(s);return{isFile:n.isFile(),isDirectory:n.isDirectory(),isSymbolicLink:n.isSymbolicLink(),mode:n.mode,size:n.size,mtime:n.mtime}}catch(n){throw n.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${t}'`):n}}async mkdir(t,s){let n=this.toRealPath(t);try{await B.promises.mkdir(n,{recursive:s?.recursive})}catch(r){let i=r;throw i.code==="EEXIST"?new Error(`EEXIST: file already exists, mkdir '${t}'`):i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, mkdir '${t}'`):r}}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){let s=this.toRealPath(t);try{return(await B.promises.readdir(s,{withFileTypes:!0})).map(r=>({name:r.name,isFile:r.isFile(),isDirectory:r.isDirectory(),isSymbolicLink:r.isSymbolicLink()})).sort((r,i)=>r.name<i.name?-1:r.name>i.name?1:0)}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, scandir '${t}'`):r.code==="ENOTDIR"?new Error(`ENOTDIR: not a directory, scandir '${t}'`):n}}async rm(t,s){let n=this.toRealPath(t);try{await B.promises.rm(n,{recursive:s?.recursive??!1,force:s?.force??!1})}catch(r){let i=r;throw i.code==="ENOENT"&&!s?.force?new Error(`ENOENT: no such file or directory, rm '${t}'`):i.code==="ENOTEMPTY"?new Error(`ENOTEMPTY: directory not empty, rm '${t}'`):r}}async cp(t,s,n){let r=this.toRealPath(t),i=this.toRealPath(s);try{await B.promises.cp(r,i,{recursive:n?.recursive??!1})}catch(a){let o=a;throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, cp '${t}'`):o.code==="EISDIR"?new Error(`EISDIR: is a directory, cp '${t}'`):a}}async mv(t,s){let n=this.toRealPath(t),r=this.toRealPath(s),i=we.dirname(r);await B.promises.mkdir(i,{recursive:!0});try{await B.promises.rename(n,r)}catch(a){let o=a;if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(o.code==="EXDEV"){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0});return}throw a}}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=[];return this.scanDir("/",t),t}scanDir(t,s){let n=this.toRealPath(t);try{let r=B.readdirSync(n);for(let i of r){let a=t==="/"?`/${i}`:`${t}/${i}`;s.push(a);let o=we.join(n,i);B.statSync(o).isDirectory()&&this.scanDir(a,s)}}catch{}}async chmod(t,s){let n=this.toRealPath(t);try{await B.promises.chmod(n,s)}catch(r){throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, chmod '${t}'`):r}}async symlink(t,s){let n=this.toRealPath(s);try{await B.promises.symlink(t,n)}catch(r){throw r.code==="EEXIST"?new Error(`EEXIST: file already exists, symlink '${s}'`):r}}async link(t,s){let n=this.toRealPath(t),r=this.toRealPath(s);try{await B.promises.link(n,r)}catch(i){let a=i;throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, link '${t}'`):a.code==="EEXIST"?new Error(`EEXIST: file already exists, link '${s}'`):a.code==="EPERM"?new Error(`EPERM: operation not permitted, link '${t}'`):i}}async readlink(t){let s=this.toRealPath(t);try{return await B.promises.readlink(s)}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${t}'`):r.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${t}'`):n}}async realpath(t){let s=this.toRealPath(t);try{let n=await B.promises.realpath(s);return n.startsWith(this.root)?n.slice(this.root.length)||"/":n}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, realpath '${t}'`):r.code==="ELOOP"?new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`):n}}async utimes(t,s,n){let r=this.toRealPath(t);try{await B.promises.utimes(r,s,n)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, utimes '${t}'`):i}}};var Ge=class{cmdId;cwd;startedAt;exitCode;bashEnv;cmdLine;env;explicitCwd;resultPromise;constructor(t,s,n,r,i=!1){this.cmdId=crypto.randomUUID(),this.cwd=n,this.startedAt=new Date,this.bashEnv=t,this.cmdLine=s,this.env=r,this.explicitCwd=i,this.resultPromise=this.execute()}async execute(){let t=this.env||this.explicitCwd?{cwd:this.explicitCwd?this.cwd:void 0,env:this.env}:void 0,s=await this.bashEnv.exec(this.cmdLine,t);return this.exitCode=s.exitCode,s}async*logs(){let t=await this.resultPromise;t.stdout&&(yield{type:"stdout",data:t.stdout,timestamp:new Date}),t.stderr&&(yield{type:"stderr",data:t.stderr,timestamp:new Date})}async wait(){return await this.resultPromise,this}async output(){let t=await this.resultPromise;return t.stdout+t.stderr}async stdout(){return(await this.resultPromise).stdout}async stderr(){return(await this.resultPromise).stderr}async kill(){}};var Wt=class e{bashEnv;constructor(t){this.bashEnv=t}static async create(t){let s=t?.fs;if(t?.overlayRoot){if(t?.fs)throw new Error("Cannot specify both 'fs' and 'overlayRoot' options");s=new Ze({root:t.overlayRoot})}let n=new rt({env:t?.env,cwd:t?.cwd,fs:s,maxCallDepth:t?.maxCallDepth,maxCommandCount:t?.maxCommandCount,maxLoopIterations:t?.maxLoopIterations,network:t?.network});return new e(n)}async runCommand(t,s){let n=s?.cwd??this.bashEnv.getCwd(),r=s?.cwd!==void 0;return new Ge(this.bashEnv,t,n,s?.env,r)}async writeFiles(t){for(let[s,n]of Object.entries(t)){let r;typeof n=="string"?r=n:n.encoding==="base64"?r=Buffer.from(n.content,"base64").toString("utf-8"):r=n.content;let i=s.substring(0,s.lastIndexOf("/"))||"/";i!=="/"&&await this.bashEnv.exec(`mkdir -p ${i}`),await this.bashEnv.writeFile(s,r)}}async readFile(t,s){let n=await this.bashEnv.readFile(t);return s==="base64"?Buffer.from(n).toString("base64"):n}async mkDir(t,s){let n=s?.recursive?"-p":"";await this.bashEnv.exec(`mkdir ${n} ${t}`)}async stop(){}async extendTimeout(t){}get domain(){}get bashEnvInstance(){return this.bashEnv}};export{rt as Bash,Se as InMemoryFs,Ft as MountableFs,He as NetworkAccessDeniedError,Ze as OverlayFs,Mt as ReadWriteFs,Ue as RedirectNotAllowedError,Wt as Sandbox,Ge as SandboxCommand,je as TooManyRedirectsError,Wr as defineCommand,Fr as getCommandNames,Mr as getNetworkCommandNames};
|