just-bash 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/AGENTS.md +1 -1
- package/dist/bin/chunks/python3-JGT65AEB.js +14 -0
- package/dist/bin/chunks/worker.js +1038 -0
- package/dist/bin/just-bash.js +37 -37
- package/dist/bin/shell/chunks/python3-JGT65AEB.js +14 -0
- package/dist/bin/shell/shell.js +37 -37
- package/dist/bundle/browser.js +27 -27
- package/dist/bundle/chunks/python3-3OP7EKER.js +13 -0
- package/dist/bundle/chunks/worker.js +1038 -0
- package/dist/bundle/index.js +31 -31
- package/dist/commands/python3/fs-bridge-handler.d.ts +50 -0
- package/dist/commands/python3/protocol.d.ts +138 -0
- package/dist/commands/python3/python3.d.ts +11 -0
- package/dist/commands/python3/sync-fs-backend.d.ts +59 -0
- package/dist/commands/python3/worker.d.ts +16 -0
- package/dist/commands/registry.d.ts +1 -1
- package/dist/limits.d.ts +2 -0
- package/package.json +7 -5
package/dist/bundle/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import{B as Ys,C as Qs,D as ne,E as Oe,F as K,G as ue,H as at,I as Js,J as T,K as en,L as tn,M as pe,N as Bt,O as lt,P as V,a as Bs,b as js,c as Hs,d as it,e as Z,f as W,g as de,h as J,i as he,j as Ae,k as Ft,l as ot,m as Us,n as Mt,o as qs,p as ae,q as ve,r as Zs,s as Gs,t as Wt,u as zt,v as Pe,w as Xs,x as Ks,y as fe,z as Vt}from"./chunks/chunk-3AWP5CWK.js";import{a as re,b as ie,c as se,d as oe,e as zs,f as z,g as ke,h as st,i as nt,j as Vs,k as te,l as Se,m as rt,n as ce}from"./chunks/chunk-PSW6BMXW.js";import"./chunks/chunk-NUFRM6SI.js";import{a as ge}from"./chunks/chunk-44UOCSGV.js";import"./chunks/chunk-DXB73IDG.js";var De=[{name:"echo",load:async()=>(await import("./chunks/echo-6S7WE7XB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-MV4K6AUA.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-66XGXFCD.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-5W3NU5OJ.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-7UKY4B3B.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-XFQE4ZYV.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-TDTEBHHI.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-I2SRVF7H.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-PBJT3GBF.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-FXHEKRTB.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-Y7YB677N.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-ODWUR7E6.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-S4NVAMC4.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-EM4O3U4P.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-SA7P5NJ7.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-52LRAWXT.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-HE5XARI4.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-IVQBBOKN.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-NIC6JNLH.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-NIC6JNLH.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-NIC6JNLH.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-SRMB7L6G.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-IV6HLDXU.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-6FBZTP57.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-EJUT5LXD.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-47QVBRNC.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-AXQM7FFF.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-NVKWEAZF.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-QTGVEPH5.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-EDGW5FG6.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-FKUV5GH5.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-KWQGFZH5.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-6CFXIPYZ.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-VSTNOVF5.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-I7A2VXFD.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-LRU5XCFP.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-YBTFW7MT.js")).split},{name:"column",load:async()=>(await import("./chunks/column-XPDNNO5Y.js")).column},{name:"join",load:async()=>(await import("./chunks/join-X3QYPZUA.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-2QU4NRSJ.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-YGMSVGUV.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-CFA5ZIGT.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-YPJLCQYA.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-MEM64BW3.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-NQXEC3EF.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-2UI6XINU.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-2UI6XINU.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-ATFBB6D2.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-ATFBB6D2.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-MQDK2OPD.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-4FRA6OJ7.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-CNJ54NE6.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-CNJ54NE6.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-VT2LJIDX.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-OLRNM52U.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-OLRNM52U.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-RLRYRPOJ.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-3BME25ON.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-ZLJYSBRK.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-PN3CMG7K.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-AK4QE4WR.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-X3X3N6IE.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-UWXBG6CS.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-5VRIVQYP.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-DG4E7SIS.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-KLHZSRUA.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-WKWTIZGQ.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-IUVNMBTA.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-NQP3CKRV.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-ZK6GQVSL.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-75YOGKM4.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-UBLRBDHN.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-2X4JLF4W.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-NWR32CGF.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-YUDAIS32.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-3FPDPLWJ.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-L3NDJG3F.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-L3NDJG3F.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-L3NDJG3F.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(De.push({name:"tar",load:async()=>(await import("./chunks/tar-LWIHPMT6.js")).tarCommand}),De.push({name:"yq",load:async()=>(await import("./chunks/yq-L665QPQU.js")).yqCommand}),De.push({name:"xan",load:async()=>(await import("./chunks/xan-A6VPI4HJ.js")).xanCommand}),De.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-5QVZOGER.js")).sqlite3Command}));var nn=[{name:"curl",load:async()=>(await import("./chunks/curl-XLP4VABU.js")).curlCommand}],sn=new Map;function rn(e){return{name:e.name,async execute(t,s){let n=sn.get(e.name);return n||(n=await e.load(),sn.set(e.name,n)),n.execute(t,s)}}}function xr(){return De.map(e=>e.name)}function Lr(){return nn.map(e=>e.name)}function on(e){return(e?De.filter(s=>e.includes(s.name)):De).map(rn)}function an(){return nn.map(rn)}function ln(e){return"load"in e&&typeof e.load=="function"}function Fr(e,t){return{name:e,execute:t}}function cn(e){let t=null;return{name:e.name,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}var Mr=new TextEncoder,Wr=new TextDecoder;function be(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)s[n/2]=parseInt(e.slice(n,n+2),16);return s}return t==="binary"||t==="latin1"?Uint8Array.from(e,s=>s.charCodeAt(0)):Mr.encode(e)}function Re(e,t){return t==="base64"?btoa(String.fromCharCode(...e)):t==="hex"?Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join(""):t==="binary"||t==="latin1"?String.fromCharCode(...e):Wr.decode(e)}function le(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var ct=new TextEncoder;function zr(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Ee=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,n]of Object.entries(t))zr(n)?this.writeFileSync(s,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(s,n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,n,r){let i=this.normalizePath(t);this.ensureParentDirs(i);let o=le(n),a=be(s,o);this.data.set(i,{type:"file",content:a,mode:r?.mode??420,mtime:r?.mtime??new Date})}async readFile(t,s){let n=await this.readFileBuffer(t),r=le(s);return Re(n,r)}async readFileBuffer(t){let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content instanceof Uint8Array?n.content:ct.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){let r=this.normalizePath(t),i=this.data.get(r);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=le(n),a=be(s,o);if(i?.type==="file"){let l=i.content instanceof Uint8Array?i.content:ct.encode(i.content),c=new Uint8Array(l.length+a.length);c.set(l),c.set(a,l.length),this.data.set(r,{type:"file",content:c,mode:i.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=ct.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}async lstat(t){let s=this.resolveIntermediateSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=ct.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}resolveIntermediateSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/");if(n.length<=1)return s;let r="",i=new Set;for(let o=0;o<n.length-1;o++){let a=n[o];r=`${r}/${a}`;let l=this.data.get(r),c=0,f=40;for(;l&&l.type==="symlink"&&c<f;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(r),r=this.resolveSymlink(r,l.target),l=this.data.get(r),c++}if(c>=f)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${r}/${n[n.length-1]}`}resolvePathWithSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/"),r="",i=new Set;for(let o of n){r=`${r}/${o}`;let a=this.data.get(r),l=0,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(r),r=this.resolveSymlink(r,a.target),a=this.data.get(r),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return r}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){let n=this.normalizePath(t);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let r=this.dirname(n);if(r!=="/"&&!this.data.has(r))if(s?.recursive)this.mkdirSync(r,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Set;for(;n&&n.type==="symlink";){if(r.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(s),s=this.resolveSymlink(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==s&&a.startsWith(i)){let c=a.slice(i.length),f=c.split("/")[0];f&&!c.includes("/",f.length)&&!o.has(f)&&o.set(f,{name:f,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,s){let n=this.normalizePath(t),r=this.data.get(n);if(!r){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(r.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(a,s)}}}this.data.delete(n)}async cp(t,s,n){let r=this.normalizePath(t),i=this.normalizePath(s),o=this.data.get(r);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(r);for(let l of a){let c=r==="/"?`/${l}`:`${r}/${l}`,f=i==="/"?`/${l}`:`${i}/${l}`;await this.cp(c,f,n)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}async chmod(t,s){let n=this.normalizePath(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);r.mode=s}async symlink(t,s){let n=this.normalizePath(s);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){let n=this.normalizePath(t),r=this.normalizePath(s),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(r))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(t){let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}async realpath(t){let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,n){let r=this.normalizePath(t),i=this.resolvePathWithSymlinks(r),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=n}};function Vr(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Br(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function jr(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function Hr(e){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Bs}
|
|
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}
|
|
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",js()),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function fn(e,t){Vr(e)&&(Br(e,t),jr(e),Hr(e))}var Ur=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],qr=["braceexpand","hashall","interactive-comments"];function jt(e){let t=[],s=[...qr.map(n=>({name:n,enabled:!0})),...Ur.map(n=>({name:n,enabled:e[n]}))].sort((n,r)=>n.name.localeCompare(r.name));for(let n of s)n.enabled&&t.push(n.name);return t.join(":")}function xe(e){e.state.env.SHELLOPTS=jt(e.state.options)}var Zr=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Ht(e){let t=[];for(let s of Zr)e[s]&&t.push(s);return t.join(":")}function Ut(e){e.state.env.BASHOPTS=Ht(e.state.shoptOptions)}var Gr="BASH_ALIAS_";function un(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function dn(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function hn(e,t){return e.env[`${Gr}${t}`]}function qt(e,t,s){if(!t.name||!un(t.name))return t;let n=dn(t.name);if(!n)return t;let r=hn(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new W,o=r,a=r.endsWith(" ");if(!a)for(let u of t.args){let d=mn(u);o+=` ${d}`}let l;try{l=i.parse(o)}catch(u){if(u instanceof it)throw u;return t}if(l.statements.length!==1||l.statements[0].pipelines.length!==1||l.statements[0].pipelines[0].commands.length!==1)return pn(t,r);let c=l.statements[0].pipelines[0].commands[0];if(c.type!=="SimpleCommand")return pn(t,r);let f={...c,assignments:[...t.assignments,...c.assignments],redirections:[...c.redirections,...t.redirections],line:t.line};if(a&&t.args.length>0&&(f={...f,args:[...f.args,...t.args]},f.args.length>0)){let u=f.args[0];if(un(u)){let d=dn(u);if(d&&hn(e,d)){let h={type:"SimpleCommand",name:u,args:f.args.slice(1),assignments:[],redirections:[]},m=qt(e,h,s);m!==h&&(f={...f,name:m.name,args:[...m.args]})}}}return f}catch(i){throw s.delete(n),i}}function pn(e,t){let s=t;for(let o of e.args){let a=mn(o);s+=` ${a}`}let n=new W,r=n.parseWordFromString("eval",!1,!1),i=n.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:r,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function mn(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${s.value}'`;break;case"DoubleQuoted":t+=`"${s.parts.map(n=>n.type==="Literal"?n.value:`$${n.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${s.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${s.expression}))`;break;case"Glob":t+=s.pattern;break;default:break}return t}async function yn(e,t){let s=t.parts.map(f=>f.type==="Literal"?f.value:"\0").join(""),n=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!n||!s.endsWith(")"))return null;let r=n[1],i=[],o=!1,a="",l=!1;for(let f of t.parts)if(f.type==="Literal"){let u=f.value;if(!o){let d=u.indexOf("=(");d!==-1&&(o=!0,u=u.slice(d+2))}if(o){u.endsWith(")")&&(u=u.slice(0,-1));let d=u.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(a||l)&&(i.push(a),a="",l=!1):h&&(a+=h)}}else if(o)if(f.type==="BraceExpansion")if(/^\[.+\]=/.test(a))a+=ot({type:"Word",parts:[f]});else{(a||l)&&(i.push(a),a="",l=!1);let d=await pe(e,{type:"Word",parts:[f]});i.push(...d.values)}else{(f.type==="SingleQuoted"||f.type==="DoubleQuoted"||f.type==="Escaped")&&(l=!0);let u=await T(e,{type:"Word",parts:[f]});a+=u}(a||l)&&i.push(a);let c=i.map(f=>/^\[.+\]=/.test(f)?f:f===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(f)&&!f.startsWith("'")&&!f.startsWith('"')?`'${f.replace(/'/g,"'\\''")}'`:f);return`${r}=(${c.join(" ")})`}async function wn(e,t){let s=-1,n=-1,r=!1;for(let p=0;p<t.parts.length;p++){let w=t.parts[p];if(w.type==="Literal"){let b=w.value.indexOf("+=");if(b!==-1){let C=w.value.slice(0,b);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(C)){s=p,n=b,r=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(C)){s=p,n=b,r=!0;break}}let $=w.value.indexOf("=");if($!==-1&&($===0||w.value[$-1]!=="+")){let C=w.value.slice(0,$);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(C)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(C)){s=p,n=$;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),o=t.parts[s];if(o.type!=="Literal")return null;let a=r?2:1,l=o.value.slice(0,n),c=o.value.slice(n+a),f=t.parts.slice(s+1),u="";for(let p of i)u+=await T(e,{type:"Word",parts:[p]});u+=l;let d={type:"Word",parts:c!==""?[{type:"Literal",value:c},...f]:f},h=d.parts.length>0?await T(e,d):"";return`${u}${r?"+=":"="}${h}`}var Xr=["tar","yq","xan","sqlite3"];function gn(e){return Xr.includes(e)}var L=Object.freeze({stdout:"",stderr:"",exitCode:0});function F(e=""){return{stdout:e,stderr:"",exitCode:0}}function S(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function P(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function q(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function
|
|
3
|
+
`),e.writeFileSync("/proc/self/status",js()),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function fn(e,t){Vr(e)&&(Br(e,t),jr(e),Hr(e))}var Ur=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],qr=["braceexpand","hashall","interactive-comments"];function jt(e){let t=[],s=[...qr.map(n=>({name:n,enabled:!0})),...Ur.map(n=>({name:n,enabled:e[n]}))].sort((n,r)=>n.name.localeCompare(r.name));for(let n of s)n.enabled&&t.push(n.name);return t.join(":")}function xe(e){e.state.env.SHELLOPTS=jt(e.state.options)}var Zr=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Ht(e){let t=[];for(let s of Zr)e[s]&&t.push(s);return t.join(":")}function Ut(e){e.state.env.BASHOPTS=Ht(e.state.shoptOptions)}var Gr="BASH_ALIAS_";function un(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function dn(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function hn(e,t){return e.env[`${Gr}${t}`]}function qt(e,t,s){if(!t.name||!un(t.name))return t;let n=dn(t.name);if(!n)return t;let r=hn(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new W,o=r,a=r.endsWith(" ");if(!a)for(let u of t.args){let d=mn(u);o+=` ${d}`}let l;try{l=i.parse(o)}catch(u){if(u instanceof it)throw u;return t}if(l.statements.length!==1||l.statements[0].pipelines.length!==1||l.statements[0].pipelines[0].commands.length!==1)return pn(t,r);let c=l.statements[0].pipelines[0].commands[0];if(c.type!=="SimpleCommand")return pn(t,r);let f={...c,assignments:[...t.assignments,...c.assignments],redirections:[...c.redirections,...t.redirections],line:t.line};if(a&&t.args.length>0&&(f={...f,args:[...f.args,...t.args]},f.args.length>0)){let u=f.args[0];if(un(u)){let d=dn(u);if(d&&hn(e,d)){let h={type:"SimpleCommand",name:u,args:f.args.slice(1),assignments:[],redirections:[]},m=qt(e,h,s);m!==h&&(f={...f,name:m.name,args:[...m.args]})}}}return f}catch(i){throw s.delete(n),i}}function pn(e,t){let s=t;for(let o of e.args){let a=mn(o);s+=` ${a}`}let n=new W,r=n.parseWordFromString("eval",!1,!1),i=n.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:r,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function mn(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${s.value}'`;break;case"DoubleQuoted":t+=`"${s.parts.map(n=>n.type==="Literal"?n.value:`$${n.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${s.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${s.expression}))`;break;case"Glob":t+=s.pattern;break;default:break}return t}async function yn(e,t){let s=t.parts.map(f=>f.type==="Literal"?f.value:"\0").join(""),n=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!n||!s.endsWith(")"))return null;let r=n[1],i=[],o=!1,a="",l=!1;for(let f of t.parts)if(f.type==="Literal"){let u=f.value;if(!o){let d=u.indexOf("=(");d!==-1&&(o=!0,u=u.slice(d+2))}if(o){u.endsWith(")")&&(u=u.slice(0,-1));let d=u.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(a||l)&&(i.push(a),a="",l=!1):h&&(a+=h)}}else if(o)if(f.type==="BraceExpansion")if(/^\[.+\]=/.test(a))a+=ot({type:"Word",parts:[f]});else{(a||l)&&(i.push(a),a="",l=!1);let d=await pe(e,{type:"Word",parts:[f]});i.push(...d.values)}else{(f.type==="SingleQuoted"||f.type==="DoubleQuoted"||f.type==="Escaped")&&(l=!0);let u=await T(e,{type:"Word",parts:[f]});a+=u}(a||l)&&i.push(a);let c=i.map(f=>/^\[.+\]=/.test(f)?f:f===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(f)&&!f.startsWith("'")&&!f.startsWith('"')?`'${f.replace(/'/g,"'\\''")}'`:f);return`${r}=(${c.join(" ")})`}async function wn(e,t){let s=-1,n=-1,r=!1;for(let p=0;p<t.parts.length;p++){let w=t.parts[p];if(w.type==="Literal"){let b=w.value.indexOf("+=");if(b!==-1){let C=w.value.slice(0,b);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(C)){s=p,n=b,r=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(C)){s=p,n=b,r=!0;break}}let $=w.value.indexOf("=");if($!==-1&&($===0||w.value[$-1]!=="+")){let C=w.value.slice(0,$);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(C)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(C)){s=p,n=$;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),o=t.parts[s];if(o.type!=="Literal")return null;let a=r?2:1,l=o.value.slice(0,n),c=o.value.slice(n+a),f=t.parts.slice(s+1),u="";for(let p of i)u+=await T(e,{type:"Word",parts:[p]});u+=l;let d={type:"Word",parts:c!==""?[{type:"Literal",value:c},...f]:f},h=d.parts.length>0?await T(e,d):"";return`${u}${r?"+=":"="}${h}`}var Xr=["tar","yq","xan","sqlite3","python3","python"];function gn(e){return Xr.includes(e)}var L=Object.freeze({stdout:"",stderr:"",exitCode:0});function F(e=""){return{stdout:e,stderr:"",exitCode:0}}function S(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function P(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function q(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function Se(e,t,s="",n=""){throw new te(e,t,s,n)}function Zt(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Pe;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
5
|
`);s=n}throw new re(s)}async function Gt(e,t){let s,n=!1,r=!1,i=0;for(;i<t.length;)if(t[i]==="--"){i++;break}else if(t[i]==="-L")r=!1,i++;else if(t[i]==="-P")r=!0,i++;else if(t[i].startsWith("-")&&t[i]!=="-")i++;else break;let o=t.slice(i);if(o.length===0||o[0]==="~"?s=e.state.env.HOME||"/":o[0]==="-"?(s=e.state.previousDir,n=!0):s=o[0],!s.startsWith("/")&&!s.startsWith("./")&&!s.startsWith("../")&&s!=="."&&s!==".."){let u=e.state.env.CDPATH;if(u){let d=u.split(":").filter(h=>h);for(let h of d){let m=h.startsWith("/")?`${h}/${s}`:`${e.state.cwd}/${h}/${s}`;try{if((await e.fs.stat(m)).isDirectory){s=m,n=!0;break}}catch{}}}}let l=(s.startsWith("/")?s:`${e.state.cwd}/${s}`).split("/").filter(u=>u&&u!=="."),c="";for(let u of l)if(u==="..")c=c.split("/").slice(0,-1).join("/")||"/";else{c=c?`${c}/${u}`:`/${u}`;try{if(!(await e.fs.stat(c)).isDirectory)return S(`bash: cd: ${s}: Not a directory
|
|
6
6
|
`)}catch{return S(`bash: cd: ${s}: No such file or directory
|
|
7
7
|
`)}}let f=c||"/";if(r)try{f=await e.fs.realpath(f)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=f,e.state.env.PWD=e.state.cwd,e.state.env.OLDPWD=e.state.previousDir,F(n?`${f}
|
|
8
8
|
`:"")}function Xt(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Kr=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function ft(e){return Kr.includes(e)}async function ut(e,t,s){let n=Xt(e,s);switch(t){case"-e":case"-a":return e.fs.exists(n);case"-f":return await e.fs.exists(n)?(await e.fs.stat(n)).isFile:!1;case"-d":return await e.fs.exists(n)?(await e.fs.stat(n)).isDirectory:!1;case"-r":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&256)!==0:!1;case"-w":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&128)!==0:!1;case"-x":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&64)!==0:!1;case"-s":return await e.fs.exists(n)?(await e.fs.stat(n)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(n)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&512)!==0:!1;case"-g":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(n);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].some(i=>n===i||n.endsWith(i));case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(n);default:return!1}}var Yr=["-nt","-ot","-ef"];function dt(e){return Yr.includes(e)}async function ht(e,t,s,n){let r=Xt(e,s),i=Xt(e,n);switch(t){case"-nt":try{let o=await e.fs.stat(r),a=await e.fs.stat(i);return o.mtime>a.mtime}catch{return!1}case"-ot":try{let o=await e.fs.stat(r),a=await e.fs.stat(i);return o.mtime<a.mtime}catch{return!1}case"-ef":try{if(!await e.fs.exists(r)||!await e.fs.exists(i))return!1;let o=e.fs.resolvePath(e.state.cwd,r),a=e.fs.resolvePath(e.state.cwd,i);return o===a}catch{return!1}default:return!1}}var Qr=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function pt(e){return Qr.has(e)}function mt(e,t,s){switch(e){case"-eq":return t===s;case"-ne":return t!==s;case"-lt":return t<s;case"-le":return t<=s;case"-gt":return t>s;case"-ge":return t>=s}}function Ze(e){return e==="="||e==="=="||e==="!="}function yt(e,t,s,n=!1,r=!1,i=!1){if(n){let a=Le(t,s,r,i);return e==="!="?!a:a}if(r){let a=t.toLowerCase()===s.toLowerCase();return e==="!="?!a:a}let o=t===s;return e==="!="?!o:o}var Jr=new Set(["-z","-n"]);function wt(e){return Jr.has(e)}function gt(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function vt(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],r=s[2];if(e.state.associativeArrays?.has(n)){let a=r;return(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1)),a=a.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(l,c)=>e.state.env[c]||""),`${n}_${a}`in e.state.env}let o;try{let a=new W,l=Z(a,r);o=await V(e,l.expression)}catch{if(/^-?\d+$/.test(r))o=Number.parseInt(r,10);else{let a=e.state.env[r];o=a?Number.parseInt(a,10):0}}if(o<0){let a=J(e,n),l=e.state.currentLine;if(a.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${n}: bad array subscript
|
|
9
9
|
`,!1;if(o=Math.max(...a)+1+o,o<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${n}: bad array subscript
|
|
10
|
-
`,!1}return`${n}_${o}`in e.state.env}return t in e.state.env?!0:e.state.associativeArrays?.has(t)?
|
|
10
|
+
`,!1}return`${n}_${o}`in e.state.env}return t in e.state.env?!0:e.state.associativeArrays?.has(t)?_e(e,t).length>0:J(e,t).length>0}async function Ce(e,t){switch(t.type){case"CondBinary":{let s=await T(e,t.left),n=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),r;if(t.operator==="=~")if(n){let i=await T(e,t.right);r=Qs(i)}else r=await en(e,t.right);else Ze(t.operator)&&!n?r=await tn(e,t.right):r=await T(e,t.right);if(Ze(t.operator)){let i=e.state.shoptOptions.nocasematch;return yt(t.operator,s,r,!n,i,!0)}if(pt(t.operator))return mt(t.operator,await bn(e,s),await bn(e,r));if(dt(t.operator))return ht(e,t.operator,s,r);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=ni(r),a=new RegExp(o,i?"i":""),l=s.match(a);if(he(e,"BASH_REMATCH"),l)for(let c=0;c<l.length;c++)e.state.env[`BASH_REMATCH_${c}`]=l[c]||"";return l!==null}catch{throw new Error("syntax error in regular expression")}case"<":return s<r;case">":return s>r;default:return!1}}case"CondUnary":{let s=await T(e,t.operand);return ft(t.operator)?ut(e,t.operator,s):wt(t.operator)?gt(t.operator,s):t.operator==="-v"?await vt(e,s):t.operator==="-o"?Yt(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await T(e,t.operand.expression.word)})`!=="":!await Ce(e,t.operand);case"CondAnd":return await Ce(e,t.left)?await Ce(e,t.right):!1;case"CondOr":return await Ce(e,t.left)?!0:await Ce(e,t.right);case"CondGroup":return await Ce(e,t.expression);case"CondWord":return await T(e,t.word)!=="";default:return!1}}async function Ge(e,t){if(t.length===0)return P("","",1);if(t.length===1)return q(!!t[0]);if(t.length===2){let n=t[0],r=t[1];return n==="("?S(`test: '(' without matching ')'
|
|
11
11
|
`,2):ft(n)?q(await ut(e,n,r)):wt(n)?q(gt(n,r)):n==="!"?q(!r):n==="-v"?q(await vt(e,r)):n==="-o"?q(Yt(e,r)):n==="="||n==="=="||n==="!="||n==="<"||n===">"||n==="-eq"||n==="-ne"||n==="-lt"||n==="-le"||n==="-gt"||n==="-ge"||n==="-nt"||n==="-ot"||n==="-ef"?S(`test: ${n}: unary operator expected
|
|
12
12
|
`,2):P("","",1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(Ze(r))return q(yt(r,n,i));if(pt(r)){let o=bt(n),a=bt(i);return!o.valid||!a.valid?P("","",2):q(mt(r,o.value,a.value))}if(dt(r))return q(await ht(e,r,n,i));switch(r){case"-a":return q(n!==""&&i!=="");case"-o":return q(n!==""||i!=="");case">":return q(n>i);case"<":return q(n<i)}if(n==="!"){let o=await Ge(e,[r,i]);return P("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(n==="("&&i===")")return q(r!=="")}if(t.length===4){if(t[0]==="!"){let n=await Ge(e,t.slice(1));return P("",n.stderr,n.exitCode===0?1:n.exitCode===1?0:n.exitCode)}if(t[0]==="("&&t[3]===")")return Ge(e,[t[1],t[2]])}let s=await $n(e,t,0);return s.pos<t.length?S(`test: too many arguments
|
|
13
13
|
`,2):q(s.value)}async function $n(e,t,s){return ei(e,t,s)}async function ei(e,t,s){let{value:n,pos:r}=await vn(e,t,s);for(;t[r]==="-o";){let i=await vn(e,t,r+1);n=n||i.value,r=i.pos}return{value:n,pos:r}}async function vn(e,t,s){let{value:n,pos:r}=await Kt(e,t,s);for(;t[r]==="-a";){let i=await Kt(e,t,r+1);n=n&&i.value,r=i.pos}return{value:n,pos:r}}async function Kt(e,t,s){if(t[s]==="!"){let{value:n,pos:r}=await Kt(e,t,s+1);return{value:!n,pos:r}}return ti(e,t,s)}async function ti(e,t,s){let n=t[s];if(n==="("){let{value:i,pos:o}=await $n(e,t,s+1);return{value:i,pos:t[o]===")"?o+1:o}}let r=t[s+1];if(Ze(r)){let i=n,o=t[s+2]??"";return{value:yt(r,i,o),pos:s+3}}if(pt(r)){let i=bt(n),o=bt(t[s+2]??"0");return!i.valid||!o.valid?{value:!1,pos:s+3}:{value:mt(r,i.value,o.value),pos:s+3}}if(dt(r)){let i=n,o=t[s+2]??"";return{value:await ht(e,r,i,o),pos:s+3}}if(ft(n)){let i=t[s+1]??"";return{value:await ut(e,n,i),pos:s+2}}if(wt(n)){let i=t[s+1]??"";return{value:gt(n,i),pos:s+2}}if(n==="-v"){let i=t[s+1]??"";return{value:await vt(e,i),pos:s+2}}if(n==="-o"){let i=t[s+1]??"";return{value:Yt(e,i),pos:s+2}}return{value:n!==void 0&&n!=="",pos:s+1}}function Le(e,t,s=!1,n=!1){let r=`^${Sn(t,n)}$`,i=s?"is":"s";return new RegExp(r,i).test(e)}function Sn(e,t){let s="";for(let n=0;n<e.length;n++){let r=e[n];if(t&&(r==="@"||r==="*"||r==="+"||r==="?"||r==="!")&&n+1<e.length&&e[n+1]==="("){let i=An(e,n+1);if(i!==-1){let o=e.slice(n+2,i),a=Pn(o),l=a.map(f=>Sn(f,t)),c=l.length>0?l.join("|"):"(?:)";if(r==="@")s+=`(?:${c})`;else if(r==="*")s+=`(?:${c})*`;else if(r==="+")s+=`(?:${c})+`;else if(r==="?")s+=`(?:${c})?`;else if(r==="!")if(i<e.length-1){let u=a.map(h=>_n(h,t));if(u.every(h=>h!==null)&&u.every(h=>h===u[0])&&u[0]!==null){let h=u[0];if(h===0)s+="(?:.+)";else{let m=[];h>0&&m.push(`.{0,${h-1}}`),m.push(`.{${h+1},}`),m.push(`(?!(?:${c})).{${h}}`),s+=`(?:${m.join("|")})`}}else s+=`(?:(?!(?:${c})).)*?`}else s+=`(?!(?:${c})$).*`;n=i;continue}}if(r==="\\")if(n+1<e.length){let i=e[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,n++}else s+="\\\\";else if(r==="*")s+=".*";else if(r==="?")s+=".";else if(r==="["){let i=e.indexOf("]",n+1);i!==-1?(s+=e.slice(n,i+1),n=i):s+="\\["}else/[\\^$.|+(){}]/.test(r)?s+=`\\${r}`:s+=r}return s}function An(e,t){let s=1,n=t+1;for(;n<e.length&&s>0;){let r=e[n];if(r==="\\"){n+=2;continue}if(r==="(")s++;else if(r===")"&&(s--,s===0))return n;n++}return-1}function Pn(e){let t=[],s="",n=0,r=0;for(;r<e.length;){let i=e[r];if(i==="\\"){s+=i,r+1<e.length?(s+=e[r+1],r+=2):r++;continue}i==="("?(n++,s+=i):i===")"?(n--,s+=i):i==="|"&&n===0?(t.push(s),s=""):s+=i,r++}return t.push(s),t}function _n(e,t){let s=0,n=0;for(;n<e.length;){let r=e[n];if(t&&(r==="@"||r==="*"||r==="+"||r==="?"||r==="!")&&n+1<e.length&&e[n+1]==="("){let i=An(e,n+1);if(i!==-1){if(r==="@"){let o=e.slice(n+2,i),l=Pn(o).map(c=>_n(c,t));if(l.every(c=>c!==null)&&l.every(c=>c===l[0])){s+=l[0],n=i+1;continue}return null}return null}}if(r==="*")return null;if(r==="?"){s+=1,n++;continue}if(r==="["){let i=e.indexOf("]",n+1);if(i!==-1){s+=1,n=i+1;continue}s+=1,n++;continue}if(r==="\\"){s+=1,n+=2;continue}s+=1,n++}return s}function Yt(e,t){let n={errexit:()=>e.state.options.errexit===!0,nounset:()=>e.state.options.nounset===!0,pipefail:()=>e.state.options.pipefail===!0,xtrace:()=>e.state.options.xtrace===!0,e:()=>e.state.options.errexit===!0,u:()=>e.state.options.nounset===!0,x:()=>e.state.options.xtrace===!0}[t];return n?n():!1}async function bn(e,t){if(t=t.trim(),t==="")return 0;if(/^[+-]?(\d+#[a-zA-Z0-9@_]+|0[xX][0-9a-fA-F]+|0[0-7]+|\d+)$/.test(t))return En(t);try{let s=new W,n=Z(s,t);return await V(e,n.expression)}catch{return En(t)}}function si(e,t){let s=0;for(let n of e){let r;if(n>="0"&&n<="9")r=n.charCodeAt(0)-48;else if(n>="a"&&n<="z")r=n.charCodeAt(0)-97+10;else if(n>="A"&&n<="Z")r=n.charCodeAt(0)-65+36;else if(n==="@")r=62;else if(n==="_")r=63;else return Number.NaN;if(r>=t)return Number.NaN;s=s*t+r}return s}function En(e){if(e=e.trim(),e==="")return 0;let t=!1;e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1));let s,n=e.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(n){let r=Number.parseInt(n[1],10);r>=2&&r<=64?s=si(n[2],r):s=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?s=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?s=Number.parseInt(e,8):s=Number.parseInt(e,10);return Number.isNaN(s)&&(s=0),t?-s:s}function bt(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let s=Number.parseInt(e,10);return Number.isNaN(s)?{value:0,valid:!1}:{value:t?-s:s,valid:!0}}function ni(e){let t="",s=0;for(;s<e.length;)if(e[s]==="\\"&&s+1<e.length)t+=e[s]+e[s+1],s+=2;else if(e[s]==="["){let n=ri(e,s);t+=n.converted,s=n.endIndex}else t+=e[s],s++;return t}function ri(e,t){let s=t+1,n="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(n+="^",s++);let r=!1;s<e.length&&e[s]==="]"&&(r=!0,s++);let i=!1;s<e.length&&e[s]==="["&&s+1<e.length&&e[s+1]!==":"&&(i=!0,s++);let o="",a=!1;for(;s<e.length;){let l=e[s];if(l==="]"){a=!0,s++;break}if(l==="["&&s+1<e.length&&e[s+1]===":"){let c=e.indexOf(":]",s+2);if(c!==-1){let f=e.slice(s+2,c);o+=ii(f),s=c+2;continue}}if(l==="["&&s+1<e.length){let c=e[s+1];if(c==="."||c==="="){let f=`${c}]`,u=e.indexOf(f,s+2);if(u!==-1){let d=e.slice(s+2,u);o+=d,s=u+2;continue}}}if(l==="\\"&&s+1<e.length){o+=l+e[s+1],s+=2;continue}o+=l,s++}return a?(r&&(n+="\\]"),i&&(n+="\\["),n+=o,n+="]",{converted:n,endIndex:s}):{converted:"\\[",endIndex:t+1}}function ii(e){return{alnum:"a-zA-Z0-9",alpha:"a-zA-Z",ascii:"\\x00-\\x7F",blank:" \\t",cntrl:"\\x00-\\x1F\\x7F",digit:"0-9",graph:"!-~",lower:"a-z",print:" -~",punct:"!-/:-@\\[-`{-~",space:" \\t\\n\\r\\f\\v",upper:"A-Z",word:"a-zA-Z0-9_",xdigit:"0-9A-Fa-f"}[e]??""}function me(e){let t=[],s="",n=!1,r=!1,i=!1,o=!1;for(let a of e){if(i){s+=a,i=!1,o=!0;continue}if(a==="\\"){i=!0;continue}if(a==="'"&&!r){n||(o=!0),n=!n;continue}if(a==='"'&&!n){r||(o=!0),r=!r;continue}if((a===" "||a===" "||a===`
|
|
14
|
-
`)&&!n&&!r){o&&(t.push(s),s="",o=!1);continue}s+=a,o=!0}return o&&t.push(s),t}function Et(e){let t=[],s=0;for(;s<e.length;){for(;s<e.length&&/\s/.test(e[s]);)s++;if(s>=e.length)break;if(e[s]!=="["){s++;continue}s++;let n="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)n+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&e[s]!=="]"&&e[s]!=="=";)n+=e[s],s++;for(;s<e.length&&e[s]!=="]";)s++;if(e[s]==="]"&&s++,e[s]!=="=")continue;s++;let r="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)e[s]==="\\"&&s+1<e.length&&s++,r+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&!/\s/.test(e[s]);)r+=e[s],s++;t.push([n,r])}return t}function Nn(e){let t=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(t)return{name:t[1],isArray:!0,arrayElements:me(t[2])};let s=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(s)return{name:s[1],isArray:!1,arrayIndex:s[2],value:s[3]};if(e.includes("=")){let n=e.indexOf("=");return{name:e.slice(0,n),isArray:!1,value:e.slice(n+1)}}return{name:e,isArray:!1}}async function oi(e,t){try{let s=new W,n=Z(s,t);return await V(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}async function Cn(e,t,s={}){let{name:n,isArray:r,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:l=!1,checkReadonly:c=!0}=s;if(c){let f=K(e,n);if(f)return f}if(r&&i){for(let f=0;f<i.length;f++)e.state.env[`${n}_${f}`]=i[f];e.state.env[`${n}__length`]=String(i.length)}else if(a!==void 0&&o!==void 0){let f=await oi(e,a);e.state.env[`${n}_${f}`]=o;let u=parseInt(e.state.env[`${n}__length`]??"0",10);f>=u&&(e.state.env[`${n}__length`]=String(f+1))}else o!==void 0&&(e.state.env[n]=o);return l&&ne(e,n),null}function
|
|
14
|
+
`)&&!n&&!r){o&&(t.push(s),s="",o=!1);continue}s+=a,o=!0}return o&&t.push(s),t}function Et(e){let t=[],s=0;for(;s<e.length;){for(;s<e.length&&/\s/.test(e[s]);)s++;if(s>=e.length)break;if(e[s]!=="["){s++;continue}s++;let n="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)n+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&e[s]!=="]"&&e[s]!=="=";)n+=e[s],s++;for(;s<e.length&&e[s]!=="]";)s++;if(e[s]==="]"&&s++,e[s]!=="=")continue;s++;let r="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)e[s]==="\\"&&s+1<e.length&&s++,r+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&!/\s/.test(e[s]);)r+=e[s],s++;t.push([n,r])}return t}function Nn(e){let t=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(t)return{name:t[1],isArray:!0,arrayElements:me(t[2])};let s=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(s)return{name:s[1],isArray:!1,arrayIndex:s[2],value:s[3]};if(e.includes("=")){let n=e.indexOf("=");return{name:e.slice(0,n),isArray:!1,value:e.slice(n+1)}}return{name:e,isArray:!1}}async function oi(e,t){try{let s=new W,n=Z(s,t);return await V(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}async function Cn(e,t,s={}){let{name:n,isArray:r,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:l=!1,checkReadonly:c=!0}=s;if(c){let f=K(e,n);if(f)return f}if(r&&i){for(let f=0;f<i.length;f++)e.state.env[`${n}_${f}`]=i[f];e.state.env[`${n}__length`]=String(i.length)}else if(a!==void 0&&o!==void 0){let f=await oi(e,a);e.state.env[`${n}_${f}`]=o;let u=parseInt(e.state.env[`${n}__length`]??"0",10);f>=u&&(e.state.env[`${n}__length`]=String(f+1))}else o!==void 0&&(e.state.env[n]=o);return l&&ne(e,n),null}function ke(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function Fe(e,t){return e.state.localVarDepth?.get(t)}function $t(e,t){e.state.localVarDepth?.delete(t)}function kn(e,t,s){e.state.localVarStack=e.state.localVarStack||new Map;let n=e.state.localVarStack.get(t)||[];n.push({value:s,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,n)}function St(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function On(e,t){if(e.state.localVarStack)for(let[s,n]of e.state.localVarStack.entries()){for(;n.length>0&&n[n.length-1].scopeIndex===t;)n.pop();n.length===0&&e.state.localVarStack.delete(s)}}var Qt=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Dn(e){return Qt.has(e)}var Jt=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Xe=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);async function Te(e,t,s,n){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory
|
|
15
15
|
`;if(n.checkNoclobber&&e.state.options.noclobber&&!n.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file
|
|
16
16
|
`}catch{}return null}function Y(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return"utf8";return"binary"}function ai(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),o=r+n+1,a=t.slice(o),l=a.indexOf(":");if(l===-1)return null;let c=Number.parseInt(a.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let f=a.slice(l+1);return{path:i,position:c,content:f}}async function Tn(e,t){let s=new Map;for(let n=0;n<t.length;n++){let r=t[n];if(r.target.type==="HereDoc")continue;if(r.operator===">&"||r.operator==="<&"){if(Bt(e,r.target))return{targets:s,error:`bash: $@: ambiguous redirect
|
|
17
17
|
`};s.set(n,await T(e,r.target))}else{let o=await lt(e,r.target);if("error"in o)return{targets:s,error:o.error};s.set(n,o.target)}}return{targets:s}}function li(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd;return e.state.nextFd++,t}async function At(e,t){for(let s of t){if(!s.fdVariable)continue;if(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),(s.operator===">&"||s.operator==="<&")&&s.target.type==="Word"&&await T(e,s.target)==="-"){let i=e.state.env[s.fdVariable];if(i!==void 0){let o=Number.parseInt(i,10);Number.isNaN(o)||e.state.fileDescriptors.delete(o)}continue}let n=li(e);if(e.state.env[s.fdVariable]=String(n),s.target.type==="Word"){let r=await T(e,s.target);if(s.operator===">&"||s.operator==="<&"){let i=Number.parseInt(r,10);if(!Number.isNaN(i)){let o=e.state.fileDescriptors.get(i);o!==void 0&&e.state.fileDescriptors.set(n,o);continue}}if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let i=e.fs.resolvePath(e.state.cwd,r);(s.operator===">"||s.operator===">|"||s.operator==="&>")&&await e.fs.writeFile(i,"","binary"),e.state.fileDescriptors.set(n,`__file__:${i}`)}else if(s.operator==="<<<")e.state.fileDescriptors.set(n,`${r}
|
|
@@ -33,7 +33,7 @@ import{B as Ys,C as Qs,D as ne,E as Oe,F as K,G as ue,H as at,I as Js,J as T,K a
|
|
|
33
33
|
`;throw new z(2,"",n)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),L}async function ci(e,t){let s="";for(let n of t)if((n.operator==="<<"||n.operator==="<<-")&&n.target.type==="HereDoc"){let r=n.target,i=await T(e,r.content);r.stripTabs&&(i=i.split(`
|
|
34
34
|
`).map(a=>a.replace(/^\t+/,"")).join(`
|
|
35
35
|
`)),(n.fd??0)===0&&(s=i)}else if(n.operator==="<<<"&&n.target.type==="Word")s=`${await T(e,n.target)}
|
|
36
|
-
`;else if(n.operator==="<"&&n.target.type==="Word"){let r=await T(e,n.target),i=e.fs.resolvePath(e.state.cwd,r);try{s=await e.fs.readFile(i)}catch{}}return s}async function Pt(e,t,s,n="",r){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth
|
|
36
|
+
`;else if(n.operator==="<"&&n.target.type==="Word"){let r=await T(e,n.target),i=e.fs.resolvePath(e.state.cwd,r);try{s=await e.fs.readFile(i)}catch{}}return s}async function Pt(e,t,s,n="",r){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,Se(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(r??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i={};for(let c=0;c<s.length;c++)i[String(c+1)]=e.state.env[String(c+1)],e.state.env[String(c+1)]=s[c];i["@"]=e.state.env["@"],i["#"]=e.state.env["#"],e.state.env["@"]=s.join(" "),e.state.env["#"]=String(s.length);let o=()=>{let c=e.state.localScopes.length-1,f=e.state.localScopes.pop();if(f)for(let[u,d]of f)d===void 0?delete e.state.env[u]:e.state.env[u]=d;if(On(e,c),e.state.fullyUnsetLocals)for(let[u,d]of e.state.fullyUnsetLocals.entries())d===c&&e.state.fullyUnsetLocals.delete(u);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let u=e.state.localExportedVars.pop();if(u)for(let d of u)e.state.exportedVars?.delete(d)}for(let[u,d]of Object.entries(i))d===void 0?delete e.state.env[u]:e.state.env[u]=d;e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},{targets:a,error:l}=await Tn(e,t.redirections);if(l)return o(),P("",l,1);try{let c=await ci(e,t.redirections),f=n||c,u=await e.executeCommand(t.body,f);return o(),j(e,u,t.redirections,a)}catch(c){if(o(),c instanceof se){let f=P(c.stdout,c.stderr,c.exitCode);return j(e,f,t.redirections,a)}throw c}}var xn=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],ts=[".",":","[","alias","bg","bind","break","builtin","caller","cd","command","compgen","complete","compopt","continue","declare","dirs","disown","echo","enable","eval","exec","exit","export","false","fc","fg","getopts","hash","help","history","jobs","kill","let","local","logout","mapfile","popd","printf","pushd","pwd","read","readarray","readonly","return","set","shift","shopt","source","suspend","test","times","trap","true","type","typeset","ulimit","umask","unalias","unset","wait"],fi=["autocd","assoc_expand_once","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","dotglob","execfail","expand_aliases","extdebug","extglob","extquote","failglob","force_fignore","globasciiranges","globstar","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lastpipe","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","nocaseglob","nocasematch","nullglob","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath","xpg_echo"],ui=ts;async function ss(e,t){let s=[],n=null,r="",i="",o=null,a=!1,l=!1,c=!1,f=null,u=null,d=null,h=[],m=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let y=0;y<t.length;y++){let g=t[y];if(g==="-v")s.push("variable");else if(g==="-e")s.push("export");else if(g==="-f")s.push("file");else if(g==="-d")s.push("directory");else if(g==="-k")s.push("keyword");else if(g==="-A"){if(y++,y>=t.length)return S(`compgen: -A: option requires an argument
|
|
37
37
|
`,2);let v=t[y];if(!m.includes(v))return S(`compgen: ${v}: invalid action name
|
|
38
38
|
`,2);s.push(v)}else if(g==="-W"){if(y++,y>=t.length)return S(`compgen: -W: option requires an argument
|
|
39
39
|
`,2);n=t[y]}else if(g==="-P"){if(y++,y>=t.length)return S(`compgen: -P: option requires an argument
|
|
@@ -71,28 +71,28 @@ import{B as Ys,C as Qs,D as ne,E as Oe,F as K,G as ue,H as at,I as Js,J as T,K a
|
|
|
71
71
|
`,2);r.push(c)}else if(l==="+o"){if(a++,a>=t.length)return S(`compopt: +o: option requires an argument
|
|
72
72
|
`,2);let c=t[a];if(!Ln.includes(c))return S(`compopt: ${c}: invalid option name
|
|
73
73
|
`,2);i.push(c)}else if(l==="--"){o.push(...t.slice(a+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&o.push(l)}if(s){let a=e.state.completionSpecs.get("__default__")??{isDefault:!0},l=new Set(a.options??[]);for(let c of r)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set("__default__",a),F("")}if(n){let a=e.state.completionSpecs.get("__empty__")??{},l=new Set(a.options??[]);for(let c of r)l.add(c);for(let c of i)l.delete(c);return a.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set("__empty__",a),F("")}if(o.length>0){for(let a of o){let l=e.state.completionSpecs.get(a)??{},c=new Set(l.options??[]);for(let f of r)c.add(f);for(let f of i)c.delete(f);l.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set(a,l)}return F("")}return S(`compopt: not currently executing completion function
|
|
74
|
-
`,1)}function os(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new
|
|
74
|
+
`,1)}function os(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Pe;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 H(e,t){let s=e.state.env.HOME||"/home/user";return t.split(":").map(i=>i==="~"?s:i==="~root"?"/root":i.startsWith("~/")?s+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function as(e){for(let t=0;t<e.length;t++){let s=e.charCodeAt(t);if(s<32||s===127)return!0}return!1}function ls(e){let t="$'";for(let s=0;s<e.length;s++){let n=e[s],r=e.charCodeAt(s);r===7?t+="\\a":r===8?t+="\\b":r===9?t+="\\t":r===10?t+="\\n":r===11?t+="\\v":r===12?t+="\\f":r===13?t+="\\r":r===27?t+="\\e":r===39?t+="\\'":r===92?t+="\\\\":r<32||r===127?t+=`\\${r.toString(8).padStart(3,"0")}`:t+=n}return t+="'",t}function _t(e){return as(e)?ls(e):/^[a-zA-Z0-9_/.:\-@%+,=]*$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Ie(e){return as(e)?ls(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function cs(e){return as(e)?ls(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Fn(e,t){let s="";return e.state.integerVars?.has(t)&&(s+="i"),e.state.lowercaseVars?.has(t)&&(s+="l"),ae(e,t)&&(s+="n"),e.state.readonlyVars?.has(t)&&(s+="r"),e.state.uppercaseVars?.has(t)&&(s+="u"),e.state.exportedVars?.has(t)&&(s+="x"),s===""?"--":`-${s}`}function fs(e){return e===""?"''":/[\s'\\]/.test(e)?`'${e.replace(/'/g,"'\\''")}'`:e}function Mn(e,t){let s="",n="",r=!1;for(let i of t){let o=Fn(e,i);if(e.state.associativeArrays?.has(i)){let f=
|
|
76
|
+
`);s=n}throw new ie(s)}function H(e,t){let s=e.state.env.HOME||"/home/user";return t.split(":").map(i=>i==="~"?s:i==="~root"?"/root":i.startsWith("~/")?s+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function as(e){for(let t=0;t<e.length;t++){let s=e.charCodeAt(t);if(s<32||s===127)return!0}return!1}function ls(e){let t="$'";for(let s=0;s<e.length;s++){let n=e[s],r=e.charCodeAt(s);r===7?t+="\\a":r===8?t+="\\b":r===9?t+="\\t":r===10?t+="\\n":r===11?t+="\\v":r===12?t+="\\f":r===13?t+="\\r":r===27?t+="\\e":r===39?t+="\\'":r===92?t+="\\\\":r<32||r===127?t+=`\\${r.toString(8).padStart(3,"0")}`:t+=n}return t+="'",t}function _t(e){return as(e)?ls(e):/^[a-zA-Z0-9_/.:\-@%+,=]*$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Ie(e){return as(e)?ls(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function cs(e){return as(e)?ls(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Fn(e,t){let s="";return e.state.integerVars?.has(t)&&(s+="i"),e.state.lowercaseVars?.has(t)&&(s+="l"),ae(e,t)&&(s+="n"),e.state.readonlyVars?.has(t)&&(s+="r"),e.state.uppercaseVars?.has(t)&&(s+="u"),e.state.exportedVars?.has(t)&&(s+="x"),s===""?"--":`-${s}`}function fs(e){return e===""?"''":/[\s'\\]/.test(e)?`'${e.replace(/'/g,"'\\''")}'`:e}function Mn(e,t){let s="",n="",r=!1;for(let i of t){let o=Fn(e,i);if(e.state.associativeArrays?.has(i)){let f=_e(e,i);if(f.length===0)s+=`declare -A ${i}=()
|
|
77
77
|
`;else{let u=f.map(d=>{let h=e.state.env[`${i}_${d}`]??"",m=fs(h);return`['${d}']=${m}`});s+=`declare -A ${i}=(${u.join(" ")})
|
|
78
78
|
`}continue}let l=J(e,i);if(l.length>0){let f=l.map(u=>{let d=e.state.env[`${i}_${u}`]??"";return`[${u}]=${Ie(d)}`});s+=`declare -a ${i}=(${f.join(" ")})
|
|
79
79
|
`;continue}if(e.state.env[`${i}__length`]!==void 0){s+=`declare -a ${i}=()
|
|
80
80
|
`;continue}let c=e.state.env[i];if(c!==void 0)s+=`declare ${o} ${i}=${cs(c)}
|
|
81
81
|
`;else{let f=e.state.declaredVars?.has(i),u=e.state.localVarDepth?.has(i);f||u?s+=`declare ${o} ${i}
|
|
82
82
|
`:(n+=`bash: declare: ${i}: not found
|
|
83
|
-
`,r=!0)}}return P(s,n,r?1:0)}function Wn(e,t){let{filterExport:s,filterReadonly:n,filterNameref:r,filterIndexedArray:i,filterAssocArray:o}=t,a=s||n||r||i||o,l="",c=new Set;for(let u of Object.keys(e.state.env)){if(u.startsWith("BASH_"))continue;if(u.endsWith("__length")){let h=u.slice(0,-8);c.add(h);continue}let d=u.lastIndexOf("_");if(d>0){let h=u.slice(0,d),m=u.slice(d+1);if(/^\d+$/.test(m)||e.state.associativeArrays?.has(h)){c.add(h);continue}}c.add(u)}if(e.state.localVarDepth)for(let u of e.state.localVarDepth.keys())c.add(u);if(e.state.associativeArrays)for(let u of e.state.associativeArrays)c.add(u);let f=Array.from(c).sort();for(let u of f){let d=Fn(e,u),h=e.state.associativeArrays?.has(u),m=J(e,u),p=!h&&(m.length>0||e.state.env[`${u}__length`]!==void 0);if(a&&(o&&!h||i&&!p||s&&!e.state.exportedVars?.has(u)||n&&!e.state.readonlyVars?.has(u)||r&&!ae(e,u)))continue;if(h){let b=
|
|
83
|
+
`,r=!0)}}return P(s,n,r?1:0)}function Wn(e,t){let{filterExport:s,filterReadonly:n,filterNameref:r,filterIndexedArray:i,filterAssocArray:o}=t,a=s||n||r||i||o,l="",c=new Set;for(let u of Object.keys(e.state.env)){if(u.startsWith("BASH_"))continue;if(u.endsWith("__length")){let h=u.slice(0,-8);c.add(h);continue}let d=u.lastIndexOf("_");if(d>0){let h=u.slice(0,d),m=u.slice(d+1);if(/^\d+$/.test(m)||e.state.associativeArrays?.has(h)){c.add(h);continue}}c.add(u)}if(e.state.localVarDepth)for(let u of e.state.localVarDepth.keys())c.add(u);if(e.state.associativeArrays)for(let u of e.state.associativeArrays)c.add(u);let f=Array.from(c).sort();for(let u of f){let d=Fn(e,u),h=e.state.associativeArrays?.has(u),m=J(e,u),p=!h&&(m.length>0||e.state.env[`${u}__length`]!==void 0);if(a&&(o&&!h||i&&!p||s&&!e.state.exportedVars?.has(u)||n&&!e.state.readonlyVars?.has(u)||r&&!ae(e,u)))continue;if(h){let b=_e(e,u);if(b.length===0)l+=`declare -A ${u}=()
|
|
84
84
|
`;else{let $=b.map(C=>{let y=e.state.env[`${u}_${C}`]??"",g=fs(y);return`['${C}']=${g}`});l+=`declare -A ${u}=(${$.join(" ")})
|
|
85
85
|
`}continue}if(m.length>0){let b=m.map($=>{let C=e.state.env[`${u}_${$}`]??"";return`[${$}]=${Ie(C)}`});l+=`declare -a ${u}=(${b.join(" ")})
|
|
86
86
|
`;continue}if(e.state.env[`${u}__length`]!==void 0){l+=`declare -a ${u}=()
|
|
87
87
|
`;continue}let w=e.state.env[u];w!==void 0&&(l+=`declare ${d} ${u}=${cs(w)}
|
|
88
|
-
`)}return F(l)}function zn(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let n of s){let r=
|
|
88
|
+
`)}return F(l)}function zn(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let n of s){let r=_e(e,n);if(r.length===0)t+=`declare -A ${n}=()
|
|
89
89
|
`;else{let i=r.map(o=>{let a=e.state.env[`${n}_${o}`]??"",l=fs(a);return`['${o}']=${l}`});t+=`declare -A ${n}=(${i.join(" ")})
|
|
90
90
|
`}}return F(t)}function Vn(e){let t="",s=new Set;for(let r of Object.keys(e.state.env)){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let o=r.slice(0,-8);e.state.associativeArrays?.has(o)||s.add(o);continue}let i=r.lastIndexOf("_");if(i>0){let o=r.slice(0,i),a=r.slice(i+1);/^\d+$/.test(a)&&(e.state.associativeArrays?.has(o)||s.add(o))}}let n=Array.from(s).sort();for(let r of n){let i=J(e,r);if(i.length===0)t+=`declare -a ${r}=()
|
|
91
91
|
`;else{let o=i.map(a=>{let l=e.state.env[`${r}_${a}`]??"";return`[${a}]=${Ie(l)}`});t+=`declare -a ${r}=(${o.join(" ")})
|
|
92
92
|
`}}return F(t)}function Bn(e){let t="",s=new Set;for(let r of Object.keys(e.state.env)){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let o=r.slice(0,-8);s.add(o);continue}let i=r.lastIndexOf("_");if(i>0){let o=r.slice(0,i),a=r.slice(i+1);if(/^\d+$/.test(a)||e.state.associativeArrays?.has(o)){s.add(o);continue}}s.add(r)}let n=Array.from(s).sort();for(let r of n){if(e.state.associativeArrays?.has(r)||J(e,r).length>0||e.state.env[`${r}__length`]!==void 0)continue;let a=e.state.env[r];a!==void 0&&(t+=`${r}=${_t(a)}
|
|
93
93
|
`)}return F(t)}function us(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function Ke(e,t){return e.state.integerVars?.has(t)??!1}function ds(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function _i(e,t){return e.state.lowercaseVars?.has(t)??!1}function hs(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Ni(e,t){return e.state.uppercaseVars?.has(t)??!1}function We(e,t,s){return _i(e,t)?s.toLowerCase():Ni(e,t)?s.toUpperCase():s}async function jn(e,t){try{let s=new W,n=Z(s,t),r=await V(e,n.expression);return String(r)}catch{return"0"}}function Ci(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let s=t[0],n=s.length;if(e[n]!=="[")return null;let r=0,i=n+1;for(;n<e.length;n++)if(e[n]==="[")r++;else if(e[n]==="]"&&(r--,r===0))break;if(r!==0)return null;let o=e.slice(i,n);if(n++,e[n]!=="=")return null;n++;let a=e.slice(n);return{name:s,indexExpr:o,value:a}}async function ps(e,t){let s=!1,n=!1,r=!1,i=!1,o=!1,a=!1,l=!1,c=!1,f=!1,u=!1,d=!1,h=!1,m=!1,p=!1,w=!1,b=[];for(let I=0;I<t.length;I++){let R=t[I];if(R==="-a")s=!0;else if(R==="-A")n=!0;else if(R==="-r")r=!0;else if(R==="-x")i=!0;else if(R==="-p")o=!0;else if(R==="-n")a=!0;else if(R==="+n")l=!0;else if(R==="+a")c=!0;else if(R==="+x")f=!0;else if(R==="--"){b.push(...t.slice(I+1));break}else if(R.startsWith("+")){for(let A of R.slice(1))if(A==="n")l=!0;else if(A==="a")c=!0;else if(A==="x")f=!0;else if(A!=="r"){if(A!=="i"){if(!(A==="f"||A==="F"))return P("",`bash: typeset: +${A}: invalid option
|
|
94
94
|
`,2)}}}else if(R==="-i")u=!0;else if(R==="-l")d=!0;else if(R==="-u")h=!0;else if(R==="-f")m=!0;else if(R==="-F")p=!0;else if(R==="-g")w=!0;else if(R.startsWith("-"))for(let A of R.slice(1))if(A==="a")s=!0;else if(A==="A")n=!0;else if(A==="r")r=!0;else if(A==="x")i=!0;else if(A==="p")o=!0;else if(A==="n")a=!0;else if(A==="i")u=!0;else if(A==="l")d=!0;else if(A==="u")h=!0;else if(A==="f")m=!0;else if(A==="F")p=!0;else if(A==="g")w=!0;else return P("",`bash: typeset: -${A}: invalid option
|
|
95
|
-
`,2);else b.push(R)}let C=e.state.localScopes.length>0&&!w,y=I=>{if(!C)return;let R=e.state.localScopes[e.state.localScopes.length-1];R.has(I)||R.set(I,e.state.env[I])},g=I=>{if(!C)return;let R=e.state.localScopes[e.state.localScopes.length-1];R.has(I)||R.set(I,e.state.env[I]);let A=`${I}_`;for(let D of Object.keys(e.state.env))D.startsWith(A)&&!D.includes("__")&&(R.has(D)||R.set(D,e.state.env[D]));let N=`${I}__length`;e.state.env[N]!==void 0&&!R.has(N)&&R.set(N,e.state.env[N])},v=I=>{C&&
|
|
95
|
+
`,2);else b.push(R)}let C=e.state.localScopes.length>0&&!w,y=I=>{if(!C)return;let R=e.state.localScopes[e.state.localScopes.length-1];R.has(I)||R.set(I,e.state.env[I])},g=I=>{if(!C)return;let R=e.state.localScopes[e.state.localScopes.length-1];R.has(I)||R.set(I,e.state.env[I]);let A=`${I}_`;for(let D of Object.keys(e.state.env))D.startsWith(A)&&!D.includes("__")&&(R.has(D)||R.set(D,e.state.env[D]));let N=`${I}__length`;e.state.env[N]!==void 0&&!R.has(N)&&R.set(N,e.state.env[N])},v=I=>{C&&ke(e,I)};if(p){if(b.length===0){let A=Array.from(e.state.functions.keys()).sort(),N="";for(let D of A)N+=`declare -f ${D}
|
|
96
96
|
`;return F(N)}let I=!0,R="";for(let A of b)e.state.functions.has(A)?R+=`${A}
|
|
97
97
|
`:I=!1;return P(R,"",I?0:1)}if(m){if(b.length===0){let R="",A=Array.from(e.state.functions.keys()).sort();for(let N of A)R+=`${N} ()
|
|
98
98
|
{
|
|
@@ -102,7 +102,7 @@ import{B as Ys,C as Qs,D as ne,E as Oe,F as K,G as ue,H as at,I as Js,J as T,K a
|
|
|
102
102
|
`,k=1;continue}if((s||!n&&!s)&&e.state.associativeArrays?.has(E)){_+=`bash: declare: ${E}: cannot convert associative to indexed array
|
|
103
103
|
`,k=1;continue}if(g(E),n&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(E)),he(e,E),delete e.state.env[E],delete e.state.env[`${E}__length`],n&&O.includes("[")){let x=Et(O);for(let[X,M]of x){let U=H(e,M);e.state.env[`${E}_${X}`]=U}}else if(n){let x=me(O);for(let X=0;X<x.length;X+=2){let M=x[X],U=X+1<x.length?H(e,x[X+1]):"";e.state.env[`${E}_${M}`]=U}}else{let x=me(O);if(x.some(M=>/^\[[^\]]+\]=/.test(M))){let M=0;for(let U of x){let ee=U.match(/^\[([^\]]+)\]=(.*)$/);if(ee){let Q=ee[1],Dr=ee[2],Tr=H(e,Dr),qe;if(/^-?\d+$/.test(Q))qe=Number.parseInt(Q,10);else try{let Ir=new W,Rr=Z(Ir,Q);qe=await V(e,Rr.expression)}catch{qe=0}e.state.env[`${E}_${qe}`]=Tr,M=qe+1}else{let Q=H(e,U);e.state.env[`${E}_${M}`]=Q,M++}}}else{for(let M=0;M<x.length;M++)e.state.env[`${E}_${M}`]=x[M];e.state.env[`${E}__length`]=String(x.length)}}v(E),r&&ne(e,E),i&&ue(e,E);continue}if(l){let E=I.includes("=")?I.slice(0,I.indexOf("=")):I;if(Zs(e,E),!I.includes("="))continue}if(f){let E=I.includes("=")?I.slice(0,I.indexOf("=")):I;if(at(e,E),!I.includes("="))continue}let A=Ci(I);if(A){let{name:E,indexExpr:O,value:x}=A,X=K(e,E);if(X)return X;g(E);let M;try{let ee=new W,Q=Z(ee,O);M=await V(e,Q.expression)}catch{let ee=parseInt(O,10);M=Number.isNaN(ee)?0:ee}e.state.env[`${E}_${M}`]=x;let U=parseInt(e.state.env[`${E}__length`]??"0",10);M>=U&&(e.state.env[`${E}__length`]=String(M+1)),v(E),r&&ne(e,E),i&&ue(e,E);continue}let N=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(N&&!c){let E=N[1],O=N[2],x=K(e,E);if(x)return x;g(E);let X=me(O);if(e.state.associativeArrays?.has(E)){let M=Et(O);for(let[U,ee]of M){let Q=H(e,ee);e.state.env[`${E}_${U}`]=Q}}else{let M=J(e,E),U=0;if(M.length===0&&e.state.env[E]!==void 0){let Q=e.state.env[E];e.state.env[`${E}_0`]=Q,delete e.state.env[E],U=1}else M.length>0&&(U=Math.max(...M)+1);for(let Q=0;Q<X.length;Q++)e.state.env[`${E}_${U+Q}`]=H(e,X[Q]);let ee=U+X.length;e.state.env[`${E}__length`]=String(ee)}v(E),r&&ne(e,E),i&&ue(e,E);continue}let D=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(D){let E=D[1],O=H(e,D[2]),x=K(e,E);if(x)return x;y(E),u&&us(e,E),d&&ds(e,E),h&&hs(e,E);let M=J(e,E).length>0||e.state.associativeArrays?.has(E);if(Ke(e,E)){let U=e.state.env[E]??"0",ee=parseInt(U,10)||0,Q=parseInt(await jn(e,O),10)||0;O=String(ee+Q),e.state.env[E]=O}else if(M){O=We(e,E,O);let U=`${E}_0`,ee=e.state.env[U]??"";e.state.env[U]=ee+O}else{O=We(e,E,O);let U=e.state.env[E]??"";e.state.env[E]=U+O}v(E),r&&ne(e,E),i&&ue(e,E),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(E));continue}if(I.includes("=")){let E=I.indexOf("="),O=I.slice(0,E),x=I.slice(E+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(O)){_+=`bash: typeset: \`${O}': not a valid identifier
|
|
104
104
|
`,k=1;continue}let X=K(e,O);if(X)return X;if(y(O),a){if(x!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(x)){_+=`bash: declare: \`${x}': invalid variable name for name reference
|
|
105
|
-
`,k=1;continue}e.state.env[O]=x,ve(e,O),x!==""&&zt(e,x)&&Wt(e,O),v(O),r&&ne(e,O),i&&ue(e,O);continue}if(u&&us(e,O),d&&ds(e,O),h&&hs(e,O),Ke(e,O)&&(x=await jn(e,x)),x=We(e,O,x),ae(e,O)){let M=
|
|
105
|
+
`,k=1;continue}e.state.env[O]=x,ve(e,O),x!==""&&zt(e,x)&&Wt(e,O),v(O),r&&ne(e,O),i&&ue(e,O);continue}if(u&&us(e,O),d&&ds(e,O),h&&hs(e,O),Ke(e,O)&&(x=await jn(e,x)),x=We(e,O,x),ae(e,O)){let M=Ne(e,O);M&&M!==O?e.state.env[M]=x:e.state.env[O]=x}else e.state.env[O]=x;v(O),r&&ne(e,O),i&&ue(e,O),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(O))}else{let E=I;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(E)){_+=`bash: typeset: \`${E}': not a valid identifier
|
|
106
106
|
`,k=1;continue}if(s||n?g(E):y(E),a){ve(e,E);let x=e.state.env[E];x!==void 0&&x!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(x)?Gs(e,E):x&&zt(e,x)&&Wt(e,E),v(E),r&&ne(e,E),i&&ue(e,E);continue}if(u&&us(e,E),d&&ds(e,E),h&&hs(e,E),n){if(J(e,E).length>0){_+=`bash: declare: ${E}: cannot convert indexed to associative array
|
|
107
107
|
`,k=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(E)}let O=Object.keys(e.state.env).some(x=>x.startsWith(`${E}_`)&&!x.startsWith(`${E}__length`));!(E in e.state.env)&&!O&&(s||n?e.state.env[`${E}__length`]="0":(e.state.declaredVars??=new Set,e.state.declaredVars.add(E))),v(E),r&&ne(e,E),i&&ue(e,E)}}return P("",_,k)}async function ms(e,t){let s=!1,n=!1,r=!1,i=[];for(let o=0;o<t.length;o++){let a=t[o];if(a==="-a")s=!0;else if(a==="-A")n=!0;else if(a==="-p")r=!0;else if(a==="--"){i.push(...t.slice(o+1));break}else a.startsWith("-")||i.push(a)}if(i.length===0){let o="",a=Array.from(e.state.readonlyVars||[]).sort();for(let l of a){let c=e.state.env[l];if(c!==void 0){let f=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');o+=`declare -r ${l}="${f}"
|
|
108
108
|
`}}return F(o)}for(let o of i){let a=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(a){let u=a[1],d=a[2],h=K(e,u);if(h)return h;let m=me(d);if(e.state.associativeArrays?.has(u)){let p=Et(d);for(let[w,b]of p){let $=H(e,b);e.state.env[`${u}_${w}`]=$}}else{let p=J(e,u),w=0;if(p.length===0&&e.state.env[u]!==void 0){let $=e.state.env[u];e.state.env[`${u}_0`]=$,delete e.state.env[u],w=1}else p.length>0&&(w=Math.max(...p)+1);for(let $=0;$<m.length;$++)e.state.env[`${u}_${w+$}`]=H(e,m[$]);let b=w+m.length;e.state.env[`${u}__length`]=String(b)}ne(e,u);continue}let l=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(l){let u=l[1],d=H(e,l[2]),h=K(e,u);if(h)return h;let m=e.state.env[u]??"";e.state.env[u]=m+d,ne(e,u);continue}let c=Nn(o);if(c.value===void 0&&!c.isArray){ne(e,c.name);continue}let f=await Cn(e,c,{makeReadonly:!0});if(f)return f}return L}function ys(e){return e.state.directoryStack??=[],e.state.directoryStack}function Ye(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function ki(e){let t=e.split("/").filter(n=>n&&n!=="."),s=[];for(let n of t)n===".."?s.pop():s.push(n);return`/${s.join("/")}`}async function ws(e,t){let s=ys(e),n;for(let a=0;a<t.length;a++){let l=t[a];if(l==="--"){if(a+1<t.length){if(n!==void 0)return S(`bash: pushd: too many arguments
|
|
@@ -506,9 +506,9 @@ ${d}
|
|
|
506
506
|
`)}return P("","",n===0?1:0)}async function Ps(e,t){if(e.state.localScopes.length===0)return S(`bash: local: can only be used in a function
|
|
507
507
|
`);let s=e.state.localScopes[e.state.localScopes.length-1],n="",r=0,i=!1,o=!1,a=!1,l=[];for(let c of t)if(c==="-n")i=!0;else if(c==="-a")o=!0;else if(c==="-p")a=!0;else if(c.startsWith("-")&&!c.includes("="))for(let f of c.slice(1))f==="n"?i=!0:f==="a"?o=!0:f==="p"&&(a=!0);else l.push(c);if(l.length===0){let c="",f=Array.from(s.keys()).filter(u=>!u.includes("_")||!u.match(/_\d+$/)).filter(u=>!u.includes("__length")).sort();for(let u of f){let d=e.state.env[u];d!==void 0&&(c+=`${u}=${d}
|
|
508
508
|
`)}return P(c,"",0)}for(let c of l){let f,u,d=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){f=d[1];let b=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(f)){n+=`bash: local: \`${c}': not a valid identifier
|
|
509
|
-
`,r=1;continue}if(K(e,f,"bash"),!s.has(f)){s.set(f,e.state.env[f]);let y=`${f}_`;for(let g of Object.keys(e.state.env))g.startsWith(y)&&!g.includes("__")&&(s.has(g)||s.set(g,e.state.env[g]))}let $=`${f}_`;for(let y of Object.keys(e.state.env))y.startsWith($)&&!y.includes("__")&&delete e.state.env[y];let C=me(b);for(let y=0;y<C.length;y++)e.state.env[`${f}_${y}`]=C[y];e.state.env[`${f}__length`]=String(C.length),
|
|
509
|
+
`,r=1;continue}if(K(e,f,"bash"),!s.has(f)){s.set(f,e.state.env[f]);let y=`${f}_`;for(let g of Object.keys(e.state.env))g.startsWith(y)&&!g.includes("__")&&(s.has(g)||s.set(g,e.state.env[g]))}let $=`${f}_`;for(let y of Object.keys(e.state.env))y.startsWith($)&&!y.includes("__")&&delete e.state.env[y];let C=me(b);for(let y=0;y<C.length;y++)e.state.env[`${f}_${y}`]=C[y];e.state.env[`${f}__length`]=String(C.length),ke(e,f),i&&ve(e,f);continue}let h=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(h){f=h[1];let b=h[2];if(K(e,f,"bash"),!s.has(f)){s.set(f,e.state.env[f]);let v=`${f}_`;for(let k of Object.keys(e.state.env))k.startsWith(v)&&!k.includes("__")&&(s.has(k)||s.set(k,e.state.env[k]));let _=`${f}__length`;e.state.env[_]!==void 0&&!s.has(_)&&s.set(_,e.state.env[_])}let $=me(b),C=J(e,f),y=0;if(C.length===0&&e.state.env[f]!==void 0){let v=e.state.env[f];e.state.env[`${f}_0`]=v,delete e.state.env[f],y=1}else C.length>0&&(y=Math.max(...C)+1);for(let v=0;v<$.length;v++)e.state.env[`${f}_${y+v}`]=H(e,$[v]);let g=y+$.length;e.state.env[`${f}__length`]=String(g),ke(e,f),i&&ve(e,f);continue}let m=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(m){f=m[1];let b=H(e,m[2]);K(e,f,"bash"),s.has(f)||s.set(f,e.state.env[f]);let $=e.state.env[f]??"";e.state.env[f]=$+b,ke(e,f),i&&ve(e,f);continue}let p=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(p){f=p[1];let b=p[2],$=H(e,p[3]);if(K(e,f,"bash"),!s.has(f)){s.set(f,e.state.env[f]);let g=`${f}_`;for(let _ of Object.keys(e.state.env))_.startsWith(g)&&!_.includes("__")&&(s.has(_)||s.set(_,e.state.env[_]));let v=`${f}__length`;e.state.env[v]!==void 0&&!s.has(v)&&s.set(v,e.state.env[v])}let C;try{let g=new W,v=Z(g,b);C=await V(e,v.expression)}catch{let g=parseInt(b,10);C=Number.isNaN(g)?0:g}e.state.env[`${f}_${C}`]=$;let y=parseInt(e.state.env[`${f}__length`]??"0",10);C>=y&&(e.state.env[`${f}__length`]=String(C+1)),ke(e,f),i&&ve(e,f);continue}if(c.includes("=")){let b=c.indexOf("=");f=c.slice(0,b),u=H(e,c.slice(b+1))}else f=c;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(f)){n+=`bash: local: \`${c}': not a valid identifier
|
|
510
510
|
`,r=1;continue}let w=s.has(f);if(u!==void 0){let b=e.state.env[f];if(e.state.tempEnvBindings){let $=e.state.accessedTempEnvVars?.has(f),C=e.state.mutatedTempEnvVars?.has(f);if(!$&&!C)for(let y=e.state.tempEnvBindings.length-1;y>=0;y--){let g=e.state.tempEnvBindings[y];if(g.has(f)){b=g.get(f);break}}}kn(e,f,b)}if(!w){let b=e.state.env[f];if(e.state.tempEnvBindings)for(let $=e.state.tempEnvBindings.length-1;$>=0;$--){let C=e.state.tempEnvBindings[$];if(C.has(f)){b=C.get(f);break}}if(s.set(f,b),o){let $=`${f}_`;for(let y of Object.keys(e.state.env))y.startsWith($)&&!y.includes("__")&&(s.has(y)||s.set(y,e.state.env[y]));let C=`${f}__length`;e.state.env[C]!==void 0&&!s.has(C)&&s.set(C,e.state.env[C])}}if(o&&u===void 0){let b=`${f}_`;for(let $ of Object.keys(e.state.env))$.startsWith(b)&&!$.includes("__")&&delete e.state.env[$];e.state.env[`${f}__length`]="0"}else if(u!==void 0){if(K(e,f,"bash"),i&&u!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(u)){n+=`bash: local: \`${u}': invalid variable name for name reference
|
|
511
|
-
`,r=1;continue}e.state.env[f]=u,e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(f))}else{let b=e.state.tempEnvBindings?.some($=>$.has(f));!w&&!b&&delete e.state.env[f]}
|
|
511
|
+
`,r=1;continue}e.state.env[f]=u,e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(f))}else{let b=e.state.tempEnvBindings?.some($=>$.has(f));!w&&!b&&delete e.state.env[f]}ke(e,f),i&&ve(e,f)}return P("",n,r)}function _s(e,t,s){let n=`
|
|
512
512
|
`,r=0,i=0,o=0,a=!1,l="MAPFILE",c=0;for(;c<t.length;){let b=t[c];b==="-d"&&c+1<t.length?(n=t[c+1]===""?"\0":t[c+1]||`
|
|
513
513
|
`,c+=2):b==="-n"&&c+1<t.length?(r=Number.parseInt(t[c+1],10)||0,c+=2):b==="-O"&&c+1<t.length?(i=Number.parseInt(t[c+1],10)||0,c+=2):b==="-s"&&c+1<t.length?(o=Number.parseInt(t[c+1],10)||0,c+=2):b==="-t"?(a=!0,c++):b==="-u"||b==="-C"||b==="-c"?c+=2:(b.startsWith("-")||(l=b),c++)}let f=s;!f&&e.state.groupStdin!==void 0&&(f=e.state.groupStdin);let u=[],d=f,h=0,m=0;for(;d.length>0;){let b=d.indexOf(n);if(b===-1){if(d.length>0){if(m<o)m++;else if(r===0||h<r){let y=d,g=y.indexOf("\0");g!==-1&&(y=y.substring(0,g)),u.push(y),h++}}break}let $=d.substring(0,b),C=$.indexOf("\0");if(C!==-1&&($=$.substring(0,C)),!a&&n!=="\0"&&($+=n),d=d.substring(b+n.length),m<o){m++;continue}if(r>0&&h>=r)break;u.push($),h++}i===0&&he(e,l);for(let b=0;b<u.length;b++)e.state.env[`${l}_${i+b}`]=u[b];let p=parseInt(e.state.env[`${l}__length`]||"0",10),w=i+u.length;return e.state.env[`${l}__length`]=String(Math.max(p,w)),e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=""),P("","",0)}function Ii(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),o=r+n+1,a=t.slice(o),l=a.indexOf(":");if(l===-1)return null;let c=Number.parseInt(a.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let f=a.slice(l+1);return{path:i,position:c,content:f}}function Ri(e,t,s){return`__rw__:${e.length}:${e}:${t}:${s}`}function Ns(e,t,s,n=-1){let r=!1,i=`
|
|
514
514
|
`,o="",a=-1,l=-1,c=null,f=-1,u=-1,d=[],h=0,m=!1,p=(A,N)=>{let D=1;for(;D<A.length;){let E=A[D];if(E==="r")r=!0,D++;else if(E==="s")D++;else{if(E==="d")return D+1<A.length?(i=A.substring(D+1),{nextArgIndex:N+1}):N+1<t.length?(i=t[N+1],{nextArgIndex:N+2}):{nextArgIndex:N+1};if(E==="n"){if(D+1<A.length){let O=A.substring(D+1);return a=Number.parseInt(O,10),(Number.isNaN(a)||a<0)&&(m=!0,a=0),{nextArgIndex:N+1}}else if(N+1<t.length)return a=Number.parseInt(t[N+1],10),(Number.isNaN(a)||a<0)&&(m=!0,a=0),{nextArgIndex:N+2};return{nextArgIndex:N+1}}else if(E==="N"){if(D+1<A.length){let O=A.substring(D+1);return l=Number.parseInt(O,10),(Number.isNaN(l)||l<0)&&(m=!0,l=0),{nextArgIndex:N+1}}else if(N+1<t.length)return l=Number.parseInt(t[N+1],10),(Number.isNaN(l)||l<0)&&(m=!0,l=0),{nextArgIndex:N+2};return{nextArgIndex:N+1}}else{if(E==="a")return D+1<A.length?(c=A.substring(D+1),{nextArgIndex:N+1}):N+1<t.length?(c=t[N+1],{nextArgIndex:N+2}):{nextArgIndex:N+1};if(E==="p")return D+1<A.length?(o=A.substring(D+1),{nextArgIndex:N+1}):N+1<t.length?(o=t[N+1],{nextArgIndex:N+2}):{nextArgIndex:N+1};if(E==="u"){if(D+1<A.length){let O=A.substring(D+1);return f=Number.parseInt(O,10),Number.isNaN(f)||f<0?{nextArgIndex:-2}:{nextArgIndex:N+1}}else if(N+1<t.length)return f=Number.parseInt(t[N+1],10),Number.isNaN(f)||f<0?{nextArgIndex:-2}:{nextArgIndex:N+2};return{nextArgIndex:N+1}}else if(E==="t"){if(D+1<A.length){let O=A.substring(D+1);return u=Number.parseFloat(O),Number.isNaN(u)&&(u=0),{nextArgIndex:N+1}}else if(N+1<t.length)return u=Number.parseFloat(t[N+1]),Number.isNaN(u)&&(u=0),{nextArgIndex:N+2};return{nextArgIndex:N+1}}else if(E==="e"||E==="i"||E==="P"){if(E==="i"&&N+1<t.length)return{nextArgIndex:N+2};D++}else D++}}}return{nextArgIndex:N+1}};for(;h<t.length;){let A=t[h];if(A.startsWith("-")&&A.length>1&&A!=="--"){let N=p(A,h);if(N.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(N.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=N.nextArgIndex}else if(A==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push(A),h++}if(m)return P("","",1);if(d.length===0&&c===null&&d.push("REPLY"),u===0){if(c)he(e,c);else{for(let A of d)e.state.env[A]="";d.length===0&&(e.state.env.REPLY="")}return P("","",0)}if(u<0&&u!==-1)return P("","",1);let w=s;f>=0?e.state.fileDescriptors?w=e.state.fileDescriptors.get(f)||"":w="":!w&&e.state.groupStdin!==void 0&&(w=e.state.groupStdin);let b=i===""?"\0":i,$="",C=0,y=!0,g=A=>{if(f>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(f,w.substring(A));else if(n>=0&&e.state.fileDescriptors){let N=e.state.fileDescriptors.get(n);if(N?.startsWith("__rw__:")){let D=Ii(N);if(D){let E=D.position+A;e.state.fileDescriptors.set(n,Ri(D.path,E,D.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=w.substring(A))};if(l>=0){let A=Math.min(l,w.length);$=w.substring(0,A),C=A,y=A>=l,g(C);let N=d[0]||"REPLY";e.state.env[N]=$;for(let D=1;D<d.length;D++)e.state.env[d[D]]="";return P("","",y?0:1)}else if(a>=0){let A=0,N=0,D=!1;for(;N<w.length&&A<a;){let E=w[N];if(E===b){C=N+1,D=!0;break}if(!r&&E==="\\"&&N+1<w.length){let O=w[N+1];if(O===b&&b===`
|
|
@@ -532,7 +532,7 @@ Options:
|
|
|
532
532
|
+o pipefail Disable pipefail
|
|
533
533
|
-o xtrace Same as -x
|
|
534
534
|
+o xtrace Disable xtrace
|
|
535
|
-
`,qn={e:"errexit",u:"nounset",x:"xtrace",v:"verbose",f:"noglob",C:"noclobber",a:"allexport",n:"noexec",h:null,b:null,m:null,B:null,H:null,P:null,T:null,E:null,p:null},Zn={errexit:"errexit",pipefail:"pipefail",nounset:"nounset",xtrace:"xtrace",verbose:"verbose",noclobber:"noclobber",noglob:"noglob",allexport:"allexport",noexec:"noexec",posix:"posix",vi:"vi",emacs:"emacs",notify:null,monitor:null,braceexpand:null,histexpand:null,physical:null,functrace:null,errtrace:null,privileged:null,hashall:null,ignoreeof:null,"interactive-comments":null,keyword:null,onecmd:null},Gn=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],Xn=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Kn(e,t,s){t!==null&&(s&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=s,xe(e))}function xi(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Li(e,t){let s=J(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env[`${t}_${r}`]??"";return`[${r}]=${Ie(i)}`});return`${t}=(${n.join(" ")})`}function Fi(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Mi(e,t){let s=
|
|
535
|
+
`,qn={e:"errexit",u:"nounset",x:"xtrace",v:"verbose",f:"noglob",C:"noclobber",a:"allexport",n:"noexec",h:null,b:null,m:null,B:null,H:null,P:null,T:null,E:null,p:null},Zn={errexit:"errexit",pipefail:"pipefail",nounset:"nounset",xtrace:"xtrace",verbose:"verbose",noclobber:"noclobber",noglob:"noglob",allexport:"allexport",noexec:"noexec",posix:"posix",vi:"vi",emacs:"emacs",notify:null,monitor:null,braceexpand:null,histexpand:null,physical:null,functrace:null,errtrace:null,privileged:null,hashall:null,ignoreeof:null,"interactive-comments":null,keyword:null,onecmd:null},Gn=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],Xn=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Kn(e,t,s){t!==null&&(s&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=s,xe(e))}function xi(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Li(e,t){let s=J(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env[`${t}_${r}`]??"";return`[${r}]=${Ie(i)}`});return`${t}=(${n.join(" ")})`}function Fi(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Mi(e,t){let s=_e(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env[`${t}_${r}`]??"";return`[${Fi(r)}]=${Ie(i)}`});return`${t}=(${n.join(" ")} )`}function Wi(e){let t=new Set,s=e.state.associativeArrays??new Set;for(let n of Object.keys(e.state.env)){let r=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(r){let i=r[1];s.has(i)||t.add(i)}}return t}function zi(e){return e.state.associativeArrays??new Set}function Os(e,t){if(t.includes("--help"))return F(kt);if(t.length===0){let n=Wi(e),r=zi(e),i=l=>{for(let c of r){let f=`${c}_`,u=`${c}__length`;if(l!==u&&l.startsWith(f)){if(l.slice(f.length).startsWith("_length"))continue;return!0}}return!1},o=[];for(let[l,c]of Object.entries(e.state.env)){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l)||n.has(l)||r.has(l))continue;let f=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(f&&n.has(f[1]))continue;let u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);u&&n.has(u[1])||i(l)||u&&r.has(u[1])||o.push([l,c])}let a=[];for(let[l,c]of o.sort(([f],[u])=>f<u?-1:f>u?1:0))a.push(`${l}=${_t(c)}`);for(let l of[...n].sort((c,f)=>c<f?-1:c>f?1:0))a.push(Li(e,l));for(let l of[...r].sort((c,f)=>c<f?-1:c>f?1:0))a.push(Mi(e,l));return a.sort((l,c)=>{let f=l.split("=")[0],u=c.split("=")[0];return f<u?-1:f>u?1:0}),F(a.length>0?`${a.join(`
|
|
536
536
|
`)}
|
|
537
537
|
`:"")}let s=0;for(;s<t.length;){let n=t[s];if((n==="-o"||n==="+o")&&xi(t,s)){let r=t[s+1];if(!(r in Zn)){let i=`bash: set: ${r}: invalid option name
|
|
538
538
|
${kt}`;if(e.state.options.posix)throw new ce(1,"",i);return S(i)}Kn(e,Zn[r],n==="-o"),s+=2;continue}if(n==="-o"){let r=Gn.map(a=>`${a.padEnd(16)}${e.state.options[a]?"on":"off"}`),i=Xn.map(a=>`${a.padEnd(16)}off`),o=[...r,...i].sort();return F(`${o.join(`
|
|
@@ -551,13 +551,13 @@ ${kt}`;if(e.state.options.posix)throw new ce(1,"",r);return S(r)}return ks(e,t.s
|
|
|
551
551
|
`,r=1;continue}if($===null)continue;if($<0){let C=fe(e,d),y=C.length,g=e.state.currentLine;if(y===0){n+=`bash: line ${g}: unset: [${$}]: bad array subscript
|
|
552
552
|
`,r=1;continue}let v=y+$;if(v<0){n+=`bash: line ${g}: unset: [${$}]: bad array subscript
|
|
553
553
|
`,r=1;continue}let _=C[v][0];delete e.state.env[`${d}_${_}`];continue}delete e.state.env[`${d}_${$}`];continue}if(!Yn(i)){n+=`bash: unset: \`${i}': not a valid identifier
|
|
554
|
-
`,r=1;continue}let f=i;if(ae(e,i)){let d=
|
|
554
|
+
`,r=1;continue}let f=i;if(ae(e,i)){let d=Ne(e,i);d&&d!==i&&(f=d)}if(De(e,f)){n+=`bash: unset: ${f}: cannot unset: readonly variable
|
|
555
555
|
`,r=1;continue}let u=Fe(e,f);if(u!==void 0&&u!==e.state.callDepth)Jn(e,f);else if(e.state.fullyUnsetLocals?.has(f))delete e.state.env[f];else if(u!==void 0){let d=e.state.accessedTempEnvVars?.has(f),h=e.state.mutatedTempEnvVars?.has(f);if((d||h)&&e.state.localVarStack?.has(f)){let m=St(e,f);m?m.value===void 0?delete e.state.env[f]:e.state.env[f]=m.value:delete e.state.env[f]}else delete e.state.env[f]}else Is(e,f)||delete e.state.env[f];e.state.exportedVars?.delete(f);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let c=o[1],f=o[2];if(f==="@"||f==="*"){let p=fe(e,c);for(let[w]of p)delete e.state.env[`${c}_${w}`];delete e.state.env[c];continue}let u=e.state.associativeArrays?.has(c);if(u){let p=await er(e,f);delete e.state.env[`${c}_${p}`];continue}let d=Vt(e,c);if(c in e.state.env&&!d&&!u){n+=`bash: unset: ${c}: not an array variable
|
|
556
556
|
`,r=1;continue}let m=await Qn(e,f);if(m===null&&d){n+=`bash: unset: ${f}: not a valid identifier
|
|
557
557
|
`,r=1;continue}if(m===null)continue;if(m<0){let p=fe(e,c),w=p.length,b=e.state.currentLine;if(w===0){n+=`bash: line ${b}: unset: [${m}]: bad array subscript
|
|
558
558
|
`,r=1;continue}let $=w+m;if($<0){n+=`bash: line ${b}: unset: [${m}]: bad array subscript
|
|
559
559
|
`,r=1;continue}let C=p[$][0];delete e.state.env[`${c}_${C}`];continue}delete e.state.env[`${c}_${m}`];continue}if(!Yn(i)){n+=`bash: unset: \`${i}': not a valid identifier
|
|
560
|
-
`,r=1;continue}let a=i;if(ae(e,i)){let c=
|
|
560
|
+
`,r=1;continue}let a=i;if(ae(e,i)){let c=Ne(e,i);c&&c!==i&&(a=c)}if(De(e,a)){n+=`bash: unset: ${a}: cannot unset: readonly variable
|
|
561
561
|
`,r=1;continue}let l=Fe(e,a);if(l!==void 0&&l!==e.state.callDepth)Jn(e,a);else if(e.state.fullyUnsetLocals?.has(a))delete e.state.env[a];else if(l!==void 0){let c=e.state.accessedTempEnvVars?.has(a),f=e.state.mutatedTempEnvVars?.has(a);if((c||f)&&e.state.localVarStack?.has(a)){let u=St(e,a);u?u.value===void 0?delete e.state.env[a]:e.state.env[a]=u.value:delete e.state.env[a]}else delete e.state.env[a]}else Is(e,a)||delete e.state.env[a];e.state.exportedVars?.delete(a),e.state.functions.delete(i)}return P("",n,r)}var xs=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],Bi=["autocd","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","execfail","extdebug","extquote","force_fignore","globasciiranges","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath"];function Ot(e){return xs.includes(e)}function ji(e){return Bi.includes(e)}function tr(e,t){let s=!1,n=!1,r=!1,i=!1,o=!1,a=[],l=0;for(;l<t.length;){let d=t[l];if(d==="--"){l++;break}if(d.startsWith("-")&&d.length>1){for(let h=1;h<d.length;h++){let m=d[h];switch(m){case"s":s=!0;break;case"u":n=!0;break;case"p":r=!0;break;case"q":i=!0;break;case"o":o=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${m}: invalid option
|
|
562
562
|
`}}}l++}else break}for(;l<t.length;)a.push(t[l]),l++;if(o)return Hi(e,a,s,n,r,i);if(s&&n)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
|
|
563
563
|
`};if(a.length===0){if(s||n){let h=[];for(let m of xs){let p=e.state.shoptOptions[m];s&&p?h.push(r?`shopt -s ${m}`:`${m} on`):n&&!p&&h.push(r?`shopt -u ${m}`:`${m} off`)}return{exitCode:0,stdout:h.length>0?`${h.join(`
|
|
@@ -617,13 +617,13 @@ ${e} ()
|
|
|
617
617
|
`,126):S(`bash: ${t}: No such file or directory
|
|
618
618
|
`,127);if("script"in c)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,c.path)),await a(c.path,s,n);let{cmd:f,path:u}=c;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u));let d=n||i.state.groupStdin||"",h=o(),m={fs:i.fs,cwd:i.state.cwd,env:i.state.env,exportedEnv:h,stdin:d,limits:i.limits,exec:i.execFn,fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo};try{return await f.execute(s,m)}catch(p){return S(`${t}: ${ge(p)}
|
|
619
619
|
`)}}async function Ls(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let n="",r="",i=0;try{for(let o of t){let a=await e.executeStatement(o);n+=a.stdout,r+=a.stderr,i=a.exitCode}}finally{e.state.inCondition=s}return{stdout:n,stderr:r,exitCode:i}}function Je(e,t,s,n){if(e instanceof re)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"break",stdout:t,stderr:s};if(e instanceof ie)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"continue",stdout:t,stderr:s};if(e instanceof se||e instanceof oe||e instanceof z||e instanceof te)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let r=ge(e);return{action:"error",stdout:t,stderr:`${s}${r}
|
|
620
|
-
`,exitCode:1}}async function Tt(e,t,s="",n=""){let r=s,i=n,o=0;try{for(let a of t){let l=await e.executeStatement(a);r+=l.stdout,i+=l.stderr,o=l.exitCode}}catch(a){if(rt(a)||a instanceof oe||a instanceof z||a instanceof te||a instanceof
|
|
620
|
+
`,exitCode:1}}async function Tt(e,t,s="",n=""){let r=s,i=n,o=0;try{for(let a of t){let l=await e.executeStatement(a);r+=l.stdout,i+=l.stderr,o=l.exitCode}}catch(a){if(rt(a)||a instanceof oe||a instanceof z||a instanceof te||a instanceof Pe)throw a.prependOutput(r,i),a;return{stdout:r,stderr:`${i}${ge(a)}
|
|
621
621
|
`,exitCode:1}}return{stdout:r,stderr:i,exitCode:o}}async function ur(e,t){let s="",n="";for(let r of t.clauses){let i=await Ls(e,r.condition);if(s+=i.stdout,n+=i.stderr,i.exitCode===0)return Tt(e,r.body,s,n)}return t.elseBody?Tt(e,t.elseBody,s,n):P(s,n,0)}async function dr(e,t){let s=await ye(e,t.redirections);if(s)return s;let n="",r="",i=0,o=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return S(`bash: \`${t.variable}': not a valid identifier
|
|
622
|
-
`);let a=[];if(t.words===null)a=(e.state.env["@"]||"").split(" ").filter(Boolean);else if(t.words.length===0)a=[];else try{for(let c of t.words){let f=await pe(e,c);a.push(...f.values)}}catch(c){if(c instanceof nt)return{stdout:"",stderr:c.stderr,exitCode:1};throw c}e.state.loopDepth++;try{for(let c of a){o++,o>e.limits.maxLoopIterations
|
|
622
|
+
`);let a=[];if(t.words===null)a=(e.state.env["@"]||"").split(" ").filter(Boolean);else if(t.words.length===0)a=[];else try{for(let c of t.words){let f=await pe(e,c);a.push(...f.values)}}catch(c){if(c instanceof nt)return{stdout:"",stderr:c.stderr,exitCode:1};throw c}e.state.loopDepth++;try{for(let c of a){o++,o>e.limits.maxLoopIterations&&Se(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),e.state.env[t.variable]=c;try{for(let f of t.body){let u=await e.executeStatement(f);n+=u.stdout,r+=u.stderr,i=u.exitCode}}catch(f){let u=Je(f,n,r,e.state.loopDepth);if(n=u.stdout,r=u.stderr,u.action==="break")break;if(u.action==="continue")continue;if(u.action==="error"){let d=P(n,r,u.exitCode??1);return j(e,d,t.redirections)}throw u.error}}}finally{e.state.loopDepth--}let l=P(n,r,i);return j(e,l,t.redirections)}async function hr(e,t){let s=await ye(e,t.redirections);if(s)return s;let n=t.line;n!==void 0&&(e.state.currentLine=n);let r="",i="",o=0,a=0;t.init&&await V(e,t.init.expression),e.state.loopDepth++;try{for(;a++,a>e.limits.maxLoopIterations&&Se(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,i),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await V(e,t.condition.expression)===0));){try{for(let c of t.body){let f=await e.executeStatement(c);r+=f.stdout,i+=f.stderr,o=f.exitCode}}catch(c){let f=Je(c,r,i,e.state.loopDepth);if(r=f.stdout,i=f.stderr,f.action==="break")break;if(f.action==="continue"){t.update&&await V(e,t.update.expression);continue}if(f.action==="error"){let u=P(r,i,f.exitCode??1);return j(e,u,t.redirections)}throw f.error}t.update&&await V(e,t.update.expression)}}finally{e.state.loopDepth--}let l=P(r,i,o);return j(e,l,t.redirections)}async function pr(e,t,s=""){let n="",r="",i=0,o=0,a=s;for(let c of t.redirections)if((c.operator==="<<"||c.operator==="<<-")&&c.target.type==="HereDoc"){let f=c.target,u=await T(e,f.content);f.stripTabs&&(u=u.split(`
|
|
623
623
|
`).map(d=>d.replace(/^\t+/,"")).join(`
|
|
624
624
|
`)),a=u}else if(c.operator==="<<<"&&c.target.type==="Word")a=`${await T(e,c.target)}
|
|
625
625
|
`;else if(c.operator==="<"&&c.target.type==="Word")try{let f=await T(e,c.target),u=e.fs.resolvePath(e.state.cwd,f);a=await e.fs.readFile(u)}catch{let f=await T(e,c.target);return S(`bash: ${f}: No such file or directory
|
|
626
|
-
`)}let l=e.state.groupStdin;a&&(e.state.groupStdin=a),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations
|
|
626
|
+
`)}let l=e.state.groupStdin;a&&(e.state.groupStdin=a),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&Se(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r);let c=0,f=!1,u=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let m=await e.executeStatement(h);n+=m.stdout,r+=m.stderr,c=m.exitCode}}catch(h){if(h instanceof re){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;f=!0}else if(h instanceof ie){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;u=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if(f)break;if(!u){if(c!==0)break;try{for(let h of t.body){let m=await e.executeStatement(h);n+=m.stdout,r+=m.stderr,i=m.exitCode}}catch(h){let m=Je(h,n,r,e.state.loopDepth);if(n=m.stdout,r=m.stderr,m.action==="break")break;if(m.action==="continue")continue;if(m.action==="error")return P(n,r,m.exitCode??1);throw m.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=l}return P(n,r,i)}async function mr(e,t){let s="",n="",r=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&Se(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,n);let o=await Ls(e,t.condition);if(s+=o.stdout,n+=o.stderr,o.exitCode===0)break;try{for(let a of t.body){let l=await e.executeStatement(a);s+=l.stdout,n+=l.stderr,r=l.exitCode}}catch(a){let l=Je(a,s,n,e.state.loopDepth);if(s=l.stdout,n=l.stderr,l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return P(s,n,l.exitCode??1);throw l.error}}}finally{e.state.loopDepth--}return P(s,n,r)}async function yr(e,t){let s=await ye(e,t.redirections);if(s)return s;let n="",r="",i=0,o=await T(e,t.word),a=!1;for(let c=0;c<t.items.length;c++){let f=t.items[c],u=a;if(!a)for(let d of f.patterns){let h=await T(e,d);Js(d)&&(h=Ys(h));let m=e.state.shoptOptions.nocasematch,p=e.state.shoptOptions.extglob;if(Le(o,h,m,p)){u=!0;break}}if(u){let d=await Tt(e,f.body,n,r);if(n=d.stdout,r=d.stderr,i=d.exitCode,f.terminator===";;")break;f.terminator===";&"?a=!0:a=!1}else a=!1}let l=P(n,r,i);return j(e,l,t.redirections)}function Fs(e,t){if(e.parts.length!==1)return!1;let s=e.parts[0];return s.type!=="Literal"?!1:t.includes(s.value)}function wr(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),o=r+n+1,a=t.slice(o),l=a.indexOf(":");if(l===-1)return null;let c=Number.parseInt(a.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let f=a.slice(l+1);return{path:i,position:c,content:f}}var gr="+ ";async function vr(e){let t=e.state.env.PS4;if(t===void 0)return gr;if(t==="")return"";try{let n=new W().parseWordFromString(t,!1,!1);return await T(e,n)}catch{return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
|
|
627
627
|
`,t||gr}}function Gi(e){return e.map(t=>Xi(t)).join(" ")}function Xi(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),n=e.includes(`
|
|
628
628
|
`),r=e.includes(" "),i=e.includes("\\"),o=e.includes("'");if(s||n||r||i){let l="";for(let c of e){let f=c.charCodeAt(0);c===`
|
|
629
629
|
`?l+="\\n":c===" "?l+="\\t":c==="\\"?l+="\\\\":c==="'"?l+="'":c==='"'?l+='"':f<32||f===127?f<256?l+=`\\x${f.toString(16).padStart(2,"0")}`:l+=`\\u${f.toString(16).padStart(4,"0")}`:l+=c}return`$'${l}'`}return o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function br(e,t,s){if(!e.state.options.xtrace)return"";let n=await vr(e),r=[t,...s],i=Gi(r);return`${n}${i}
|
|
@@ -637,16 +637,16 @@ user 0m0.000s
|
|
|
637
637
|
sys 0m0.000s
|
|
638
638
|
`,i={...i,stderr:i.stderr+p}}return l&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=c),i}async function Sr(e,t){let s={},n="";for(let r of t.assignments){let i=r.name;if(r.array){let f=await Ki(e,t,i,r.array,r.append,s);if(f.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:f.error};if(n+=f.xtraceOutput,f.continueToNext)continue}let o=r.value?await T(e,r.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:P("",`bash: ${i}: bad array subscript
|
|
639
639
|
`,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let f=await to(e,t,l[1],l[2],o,r.append,s);if(f.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:f.error};if(f.continueToNext)continue}let c=await no(e,t,i,o,r.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:c.error};n+=c.xtraceOutput,c.continueToNext}return{continueToNext:!1,xtraceOutput:n,tempAssignments:s}}async function Ki(e,t,s,n,r,i){let o="";if(/\[.+\]$/.test(s))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: cannot assign list to array member
|
|
640
|
-
`,1)};if(ae(e,s)){let f=Xs(e,s);if(f===void 0||f==="")throw new z(1,"","");let u=
|
|
641
|
-
`,1)}}if(
|
|
640
|
+
`,1)};if(ae(e,s)){let f=Xs(e,s);if(f===void 0||f==="")throw new z(1,"","");let u=Ne(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(De(e,s)){if(t.name)return o+=`bash: ${s}: readonly variable
|
|
642
642
|
`,{continueToNext:!0,xtraceOutput:o};let f=K(e,s);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let a=e.state.associativeArrays?.has(s),l=Yi(n),c=()=>{let f=`${s}_`;for(let u of Object.keys(e.state.env))u.startsWith(f)&&!u.includes("__")&&delete e.state.env[u];delete e.state.env[s]};if(a&&l?await Qi(e,t,s,n,r,c,f=>{o+=f}):l?await Ji(e,s,n,r,c):await eo(e,s,n,r,c),t.name){i[s]=e.state.env[s];let u=`(${n.map(d=>ot(d)).join(" ")})`;e.state.env[s]=u}return{continueToNext:!0,xtraceOutput:o}}function Yi(e){return e.some(t=>{if(t.parts.length>=2){let s=t.parts[0],n=t.parts[1];if(s.type!=="Glob"||!s.pattern.startsWith("["))return!1;if(s.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(t.parts.length<3)return!1;let r=t.parts[2];return r.type!=="Literal"?!1:r.value.startsWith("]=")||r.value.startsWith("]+=")}return n.type!=="Literal"?!1:n.value.startsWith("]")?n.value.startsWith("]=")||n.value.startsWith("]+="):s.pattern.endsWith("]")?n.value.startsWith("=")||n.value.startsWith("+="):!1}return!1})}async function Qi(e,t,s,n,r,i,o){let a=[];for(let l of n){let c=Ft(l);if(c){let{key:f,valueParts:u,append:d}=c,h;u.length>0?h=await T(e,{type:"Word",parts:u}):h="",h=H(e,h),a.push({type:"keyed",key:f,value:h,append:d})}else{let f=await T(e,l);a.push({type:"invalid",expandedValue:f})}}r||i();for(let l of a)if(l.type==="keyed")if(l.append){let c=e.state.env[`${s}_${l.key}`]??"";e.state.env[`${s}_${l.key}`]=c+l.value}else e.state.env[`${s}_${l.key}`]=l.value;else{let c=t.line??e.state.currentLine??1;o(`bash: line ${c}: ${s}: ${l.expandedValue}: must use subscript when assigning associative array
|
|
643
|
-
`)}}async function Ji(e,t,s,n,r){let i=[];for(let a of s){let l=Ft(a);if(l){let{key:c,valueParts:f,append:u}=l,d;f.length>0?d=await T(e,{type:"Word",parts:f}):d="",d=H(e,d),i.push({type:"keyed",indexExpr:c,value:d,append:u})}else{let c=await pe(e,a);i.push({type:"non-keyed",values:c.values})}}n||r();let o=0;for(let a of i)if(a.type==="keyed"){let l;try{let c=new W,f=Z(c,a.indexExpr);l=await V(e,f.expression,!1)}catch{if(/^-?\d+$/.test(a.indexExpr))l=Number.parseInt(a.indexExpr,10);else{let c=e.state.env[a.indexExpr];l=c?Number.parseInt(c,10):0,Number.isNaN(l)&&(l=0)}}if(a.append){let c=e.state.env[`${t}_${l}`]??"";e.state.env[`${t}_${l}`]=c+a.value}else e.state.env[`${t}_${l}`]=a.value;o=l+1}else for(let l of a.values)e.state.env[`${t}_${o++}`]=l}async function eo(e,t,s,n,r){let i=[];for(let a of s){let l=await pe(e,a);i.push(...l.values)}let o=0;if(n){let a=fe(e,t);if(a.length>0)o=Math.max(...a.map(([c])=>typeof c=="number"?c:0))+1;else if(e.state.env[t]!==void 0){let l=e.state.env[t];e.state.env[`${t}_0`]=l,delete e.state.env[t],o=1}}else r();for(let a=0;a<i.length;a++)e.state.env[`${t}_${o+a}`]=i[a];n||(e.state.env[`${t}__length`]=String(i.length))}async function to(e,t,s,n,r,i,o){let a=s;if(ae(e,s)){let u=
|
|
644
|
-
`,1)};a=u}}if(
|
|
643
|
+
`)}}async function Ji(e,t,s,n,r){let i=[];for(let a of s){let l=Ft(a);if(l){let{key:c,valueParts:f,append:u}=l,d;f.length>0?d=await T(e,{type:"Word",parts:f}):d="",d=H(e,d),i.push({type:"keyed",indexExpr:c,value:d,append:u})}else{let c=await pe(e,a);i.push({type:"non-keyed",values:c.values})}}n||r();let o=0;for(let a of i)if(a.type==="keyed"){let l;try{let c=new W,f=Z(c,a.indexExpr);l=await V(e,f.expression,!1)}catch{if(/^-?\d+$/.test(a.indexExpr))l=Number.parseInt(a.indexExpr,10);else{let c=e.state.env[a.indexExpr];l=c?Number.parseInt(c,10):0,Number.isNaN(l)&&(l=0)}}if(a.append){let c=e.state.env[`${t}_${l}`]??"";e.state.env[`${t}_${l}`]=c+a.value}else e.state.env[`${t}_${l}`]=a.value;o=l+1}else for(let l of a.values)e.state.env[`${t}_${o++}`]=l}async function eo(e,t,s,n,r){let i=[];for(let a of s){let l=await pe(e,a);i.push(...l.values)}let o=0;if(n){let a=fe(e,t);if(a.length>0)o=Math.max(...a.map(([c])=>typeof c=="number"?c:0))+1;else if(e.state.env[t]!==void 0){let l=e.state.env[t];e.state.env[`${t}_0`]=l,delete e.state.env[t],o=1}}else r();for(let a=0;a<i.length;a++)e.state.env[`${t}_${o+a}`]=i[a];n||(e.state.env[`${t}__length`]=String(i.length))}async function to(e,t,s,n,r,i,o){let a=s;if(ae(e,s)){let u=Ne(e,s);if(u&&u!==s){if(u.includes("["))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: \`${u}': not a valid identifier
|
|
644
|
+
`,1)};a=u}}if(De(e,a)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let u=K(e,a);if(u)return{continueToNext:!1,xtraceOutput:"",error:u}}let l=e.state.associativeArrays?.has(a),c;if(l)c=await Ar(e,a,n);else{let u=await so(e,a,n);if(u.error)return{continueToNext:!1,xtraceOutput:"",error:u.error};c=`${a}_${u.index}`}let f=i?(e.state.env[c]||"")+r:r;if(t.name)o[c]=e.state.env[c],e.state.env[c]=f;else{let u=Fe(e,a);if(u!==void 0&&u===e.state.callDepth&&e.state.localScopes.length>0){let d=e.state.localScopes[e.state.localScopes.length-1];d.has(c)||d.set(c,e.state.env[c])}e.state.env[c]=f}return{continueToNext:!0,xtraceOutput:""}}async function Ar(e,t,s){let n;if(s.startsWith("'")&&s.endsWith("'"))n=s.slice(1,-1);else if(s.startsWith('"')&&s.endsWith('"')){let r=s.slice(1,-1),o=new W().parseWordFromString(r,!0,!1);n=await T(e,o)}else if(s.includes("$")){let i=new W().parseWordFromString(s,!1,!1);n=await T(e,i)}else n=s;return`${t}_${n}`}async function so(e,t,s){let n=s;s.startsWith('"')&&s.endsWith('"')&&s.length>=2&&(n=s.slice(1,-1));let r;if(/^-?\d+$/.test(n))r=Number.parseInt(n,10);else{try{let i=new W,o=Z(i,n);r=await V(e,o.expression,!1)}catch(i){if(i instanceof Oe){let l=`bash: line ${e.state.currentLine}: ${s}: ${i.message}
|
|
645
645
|
`;if(i.fatal)throw new z(1,"",l);return{index:0,error:P("",l,1)}}let o=e.state.env[s];r=o?Number.parseInt(o,10):0}Number.isNaN(r)&&(r=0)}if(r<0){let i=fe(e,t);if(i.length===0){let a=e.state.currentLine;return{index:0,error:P("",`bash: line ${a}: ${t}[${s}]: bad array subscript
|
|
646
646
|
`,1)}}if(r=Math.max(...i.map(([a])=>typeof a=="number"?a:0))+1+r,r<0){let a=e.state.currentLine;return{index:0,error:P("",`bash: line ${a}: ${t}[${s}]: bad array subscript
|
|
647
647
|
`,1)}}}return{index:r}}async function no(e,t,s,n,r,i){let o="",a=s,l=null;if(ae(e,s)){let u=Ks(e,s,n);if(u===void 0)return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: circular name reference
|
|
648
|
-
`,1)};if(u===null)return{continueToNext:!0,xtraceOutput:""};a=u;let d=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(l={arrayName:d[1],subscriptExpr:d[2]},a=d[1])}if(
|
|
649
|
-
`,{continueToNext:!0,xtraceOutput:o};let u=K(e,a);if(u)return{continueToNext:!1,xtraceOutput:"",error:u}}let c;if(Ke(e,a))try{let u=new W;if(r){let h=`(${e.state.env[a]||"0"}) + (${n})`,m=Z(u,h);c=String(await V(e,m.expression))}else{let d=Z(u,n);c=String(await V(e,d.expression))}}catch{c="0"}else{let{isArray:u}=await import("./chunks/expansion-RIGCFEMA.js"),d=u(e,a)?`${a}_0`:a;c=r?(e.state.env[d]||"")+n:n}c=We(e,a,c),o+=await Er(e,a,c);let f=a;if(l)f=await ro(e,l);else{let{isArray:u}=await import("./chunks/expansion-RIGCFEMA.js");u(e,a)&&(f=`${a}_0`)}return t.name?(i[f]=e.state.env[f],e.state.env[f]=c):(e.state.env[f]=c,e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(a)),e.state.tempEnvBindings?.some(u=>u.has(a))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(a))),{continueToNext:!1,xtraceOutput:o}}async function ro(e,t){let{arrayName:s,subscriptExpr:n}=t;if(e.state.associativeArrays?.has(s))return Ar(e,s,n);let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else{try{let o=new W,a=Z(o,n);i=await V(e,a.expression,!1)}catch{let o=e.state.env[n];i=o?Number.parseInt(o,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let o=fe(e,s);o.length>0&&(i=Math.max(...o.map(l=>l[0]))+1+i)}return`${s}_${i}`}async function Pr(e,t,s,n){let r=await ye(e,t.redirections);if(r)return r;let i={...e.state.env},o=e.state.cwd,a={...e.state.options},l=e.state.localScopes,c=e.state.localVarStack,f=e.state.localVarDepth,u=e.state.fullyUnsetLocals;if(e.state.localScopes=l.map(v=>new Map(v)),c){e.state.localVarStack=new Map;for(let[v,_]of c.entries())e.state.localVarStack.set(v,_.map(k=>({...k})))}f&&(e.state.localVarDepth=new Map(f)),u&&(e.state.fullyUnsetLocals=new Map(u));let d=e.state.loopDepth,h=e.state.parentHasLoopContext;e.state.parentHasLoopContext=d>0,e.state.loopDepth=0;let m=e.state.lastArg,p=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let w=e.state.groupStdin;s&&(e.state.groupStdin=s);let b="",$="",C=0,y=()=>{e.state.env=i,e.state.cwd=o,e.state.options=a,e.state.localScopes=l,e.state.localVarStack=c,e.state.localVarDepth=f,e.state.fullyUnsetLocals=u,e.state.loopDepth=d,e.state.parentHasLoopContext=h,e.state.groupStdin=w,e.state.bashPid=p,e.state.lastArg=m};try{for(let v of t.body){let _=await n(v);b+=_.stdout,$+=_.stderr,C=_.exitCode}}catch(v){if(y(),v instanceof te)throw v;if(v instanceof
|
|
648
|
+
`,1)};if(u===null)return{continueToNext:!0,xtraceOutput:""};a=u;let d=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(l={arrayName:d[1],subscriptExpr:d[2]},a=d[1])}if(De(e,a)){if(t.name)return o+=`bash: ${a}: readonly variable
|
|
649
|
+
`,{continueToNext:!0,xtraceOutput:o};let u=K(e,a);if(u)return{continueToNext:!1,xtraceOutput:"",error:u}}let c;if(Ke(e,a))try{let u=new W;if(r){let h=`(${e.state.env[a]||"0"}) + (${n})`,m=Z(u,h);c=String(await V(e,m.expression))}else{let d=Z(u,n);c=String(await V(e,d.expression))}}catch{c="0"}else{let{isArray:u}=await import("./chunks/expansion-RIGCFEMA.js"),d=u(e,a)?`${a}_0`:a;c=r?(e.state.env[d]||"")+n:n}c=We(e,a,c),o+=await Er(e,a,c);let f=a;if(l)f=await ro(e,l);else{let{isArray:u}=await import("./chunks/expansion-RIGCFEMA.js");u(e,a)&&(f=`${a}_0`)}return t.name?(i[f]=e.state.env[f],e.state.env[f]=c):(e.state.env[f]=c,e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(a)),e.state.tempEnvBindings?.some(u=>u.has(a))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(a))),{continueToNext:!1,xtraceOutput:o}}async function ro(e,t){let{arrayName:s,subscriptExpr:n}=t;if(e.state.associativeArrays?.has(s))return Ar(e,s,n);let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else{try{let o=new W,a=Z(o,n);i=await V(e,a.expression,!1)}catch{let o=e.state.env[n];i=o?Number.parseInt(o,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let o=fe(e,s);o.length>0&&(i=Math.max(...o.map(l=>l[0]))+1+i)}return`${s}_${i}`}async function Pr(e,t,s,n){let r=await ye(e,t.redirections);if(r)return r;let i={...e.state.env},o=e.state.cwd,a={...e.state.options},l=e.state.localScopes,c=e.state.localVarStack,f=e.state.localVarDepth,u=e.state.fullyUnsetLocals;if(e.state.localScopes=l.map(v=>new Map(v)),c){e.state.localVarStack=new Map;for(let[v,_]of c.entries())e.state.localVarStack.set(v,_.map(k=>({...k})))}f&&(e.state.localVarDepth=new Map(f)),u&&(e.state.fullyUnsetLocals=new Map(u));let d=e.state.loopDepth,h=e.state.parentHasLoopContext;e.state.parentHasLoopContext=d>0,e.state.loopDepth=0;let m=e.state.lastArg,p=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let w=e.state.groupStdin;s&&(e.state.groupStdin=s);let b="",$="",C=0,y=()=>{e.state.env=i,e.state.cwd=o,e.state.options=a,e.state.localScopes=l,e.state.localVarStack=c,e.state.localVarDepth=f,e.state.fullyUnsetLocals=u,e.state.loopDepth=d,e.state.parentHasLoopContext=h,e.state.groupStdin=w,e.state.bashPid=p,e.state.lastArg=m};try{for(let v of t.body){let _=await n(v);b+=_.stdout,$+=_.stderr,C=_.exitCode}}catch(v){if(y(),v instanceof te)throw v;if(v instanceof Pe){b+=v.stdout,$+=v.stderr;let k=P(b,$,0);return j(e,k,t.redirections)}if(v instanceof re||v instanceof ie){b+=v.stdout,$+=v.stderr;let k=P(b,$,0);return j(e,k,t.redirections)}if(v instanceof z){b+=v.stdout,$+=v.stderr;let k=P(b,$,v.exitCode);return j(e,k,t.redirections)}if(v instanceof se){b+=v.stdout,$+=v.stderr;let k=P(b,$,v.exitCode);return j(e,k,t.redirections)}if(v instanceof oe){let k=P(b+v.stdout,$+v.stderr,v.exitCode);return j(e,k,t.redirections)}let _=P(b,`${$}${ge(v)}
|
|
650
650
|
`,1);return j(e,_,t.redirections)}y();let g=P(b,$,C);return j(e,g,t.redirections)}async function _r(e,t,s,n){let r="",i="",o=0,a=await At(e,t.redirections);if(a)return a;let l=s;for(let u of t.redirections)if((u.operator==="<<"||u.operator==="<<-")&&u.target.type==="HereDoc"){let d=u.target,h=await T(e,d.content);d.stripTabs&&(h=h.split(`
|
|
651
651
|
`).map(p=>p.replace(/^\t+/,"")).join(`
|
|
652
652
|
`));let m=u.fd??0;m!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(m,h)):l=h}else if(u.operator==="<<<"&&u.target.type==="Word")l=`${await T(e,u.target)}
|
|
@@ -655,7 +655,7 @@ sys 0m0.000s
|
|
|
655
655
|
`,1)}e.state.groupStdin=c;let f=P(r,i,o);return j(e,f,t.redirections)}async function Nr(e,t,s,n,r){let i;try{i=await e.fs.readFile(t)}catch{return S(`bash: ${t}: No such file or directory
|
|
656
656
|
`,127)}if(i.startsWith("#!")){let w=i.indexOf(`
|
|
657
657
|
`);w!==-1&&(i=i.slice(w+1))}let o={...e.state.env},a=e.state.cwd,l={...e.state.options},c=e.state.loopDepth,f=e.state.parentHasLoopContext,u=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,m=e.state.currentSource;e.state.parentHasLoopContext=c>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,n&&(e.state.groupStdin=n),e.state.currentSource=t,e.state.env[0]=t,e.state.env["#"]=String(s.length),e.state.env["@"]=s.join(" "),e.state.env["*"]=s.join(" ");for(let w=0;w<s.length&&w<9;w++)e.state.env[String(w+1)]=s[w];for(let w=s.length+1;w<=9;w++)delete e.state.env[String(w)];let p=()=>{e.state.env=o,e.state.cwd=a,e.state.options=l,e.state.loopDepth=c,e.state.parentHasLoopContext=f,e.state.lastArg=u,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=m};try{let b=new W().parse(i),$=await r(b);return p(),$}catch(w){if(p(),w instanceof z||w instanceof te)throw w;if(w.name==="ParseException")return S(`bash: ${t}: ${w.message}
|
|
658
|
-
`);throw w}}var et=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace}}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,n=new Set;if(t)for(let i of t)n.add(i);if(s)for(let i of s)n.add(i);if(n.size===0)return{};let r={};for(let i of n){let o=this.ctx.state.env[i];o!==void 0&&(r[i]=o)}return r}async executeScript(t){let s="",n="",r=0;for(let i of t.statements)try{let o=await this.executeStatement(i);s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r)}catch(o){if(o instanceof z)throw o.prependOutput(s,n),o;if(o instanceof ce)return s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(o instanceof te)throw o;if(o instanceof oe)return s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(o instanceof zs)return s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(o instanceof st)return s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(o instanceof
|
|
658
|
+
`);throw w}}var et=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace}}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,n=new Set;if(t)for(let i of t)n.add(i);if(s)for(let i of s)n.add(i);if(n.size===0)return{};let r={};for(let i of n){let o=this.ctx.state.env[i];o!==void 0&&(r[i]=o)}return r}async executeScript(t){let s="",n="",r=0;for(let i of t.statements)try{let o=await this.executeStatement(i);s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r)}catch(o){if(o instanceof z)throw o.prependOutput(s,n),o;if(o instanceof ce)return s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(o instanceof te)throw o;if(o instanceof oe)return s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(o instanceof zs)return s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(o instanceof st)return s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r),{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}};if(o instanceof Oe){s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r);continue}if(o instanceof Vs){s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r);continue}if(o instanceof re||o instanceof ie){if(this.ctx.state.loopDepth>0)throw o.prependOutput(s,n),o;s+=o.stdout,n+=o.stderr;continue}throw o instanceof se&&o.prependOutput(s,n),o}return{stdout:s,stderr:n,exitCode:r,env:{...this.ctx.state.env}}}async executeUserScript(t,s,n=""){return Nr(this.ctx,t,s,n,r=>this.executeScript(r))}async executeStatement(t){if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&Se(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new it(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return L;this.ctx.state.errexitSafe=!1;let s="",n="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(n+=`${t.sourceText}
|
|
659
659
|
`);let r=0,i=-1,o=!1;for(let c=0;c<t.pipelines.length;c++){let f=t.pipelines[c],u=c>0?t.operators[c-1]:null;if(u==="&&"&&r!==0||u==="||"&&r===0)continue;let d=await this.executePipeline(f);s+=d.stdout,n+=d.stderr,r=d.exitCode,i=c,o=f.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env["?"]=String(r)}let a=i<t.pipelines.length-1,l=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=a||o||l,this.ctx.state.options.errexit&&r!==0&&i===t.pipelines.length-1&&!o&&!this.ctx.state.inCondition&&!l)throw new oe(r,s,n);return P(s,n,r)}async executePipeline(t){return $r(this.ctx,t,(s,n)=>this.executeCommand(s,n))}async executeCommand(t,s){switch(t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return ur(this.ctx,t);case"For":return dr(this.ctx,t);case"CStyleFor":return hr(this.ctx,t);case"While":return pr(this.ctx,t,s);case"Until":return mr(this.ctx,t);case"Case":return yr(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return In(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return L}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(n){if(n instanceof nt)return S(n.stderr);throw n}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let y=t,g=100;for(;g>0;){let v=this.expandAlias(y);if(v===y)break;y=v,g--}this.aliasExpansionStack.clear(),y!==t&&(t=y)}this.ctx.state.expansionStderr="";let n=await Sr(this.ctx,t);if(n.error)return n.error;let r=n.tempAssignments,i=n.xtraceOutput;if(!t.name){if(t.redirections.length>0){let g=await ye(this.ctx,t.redirections);if(g)return g;let v=P("",i,0);return j(this.ctx,v,t.redirections)}this.ctx.state.lastArg="";let y=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",P("",y,this.ctx.state.lastExitCode)}let o=t.name&&Fs(t.name,["local","declare","typeset","export","readonly"]),a=Object.keys(r);if(a.length>0&&!o){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let y of a)this.ctx.state.tempExportedVars.add(y)}let l=await At(this.ctx,t.redirections);if(l){for(let[y,g]of Object.entries(r))g===void 0?delete this.ctx.state.env[y]:this.ctx.state.env[y]=g;return l}let c=-1;for(let y of t.redirections){if((y.operator==="<<"||y.operator==="<<-")&&y.target.type==="HereDoc"){let g=y.target,v=await T(this.ctx,g.content);g.stripTabs&&(v=v.split(`
|
|
660
660
|
`).map(k=>k.replace(/^\t+/,"")).join(`
|
|
661
661
|
`));let _=y.fd??0;_!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),this.ctx.state.fileDescriptors.set(_,v)):s=v;continue}if(y.operator==="<<<"&&y.target.type==="Word"){s=`${await T(this.ctx,y.target)}
|
|
@@ -663,14 +663,14 @@ sys 0m0.000s
|
|
|
663
663
|
`)}if(y.operator==="<&"&&y.target.type==="Word"){let g=await T(this.ctx,y.target),v=Number.parseInt(g,10);if(!Number.isNaN(v)&&this.ctx.state.fileDescriptors){let _=this.ctx.state.fileDescriptors.get(v);if(_!==void 0)if(_.startsWith("__rw__:")){let k=wr(_);k&&(s=k.content.slice(k.position),c=v)}else _.startsWith("__file__:")||_.startsWith("__file_append__:")||(s=_)}}}let f=await T(this.ctx,t.name),u=[],d=[];if(Fs(t.name,["local","declare","typeset","export","readonly"])&&(f==="local"||f==="declare"||f==="typeset"||f==="export"||f==="readonly"))for(let y of t.args){let g=await yn(this.ctx,y);if(g)u.push(g),d.push(!0);else{let v=await wn(this.ctx,y);if(v!==null)u.push(v),d.push(!0);else{let _=await pe(this.ctx,y);for(let k of _.values)u.push(k),d.push(_.quoted)}}}else for(let y of t.args){let g=await pe(this.ctx,y);for(let v of g.values)u.push(v),d.push(g.quoted)}if(!f){if(t.name.parts.every(g=>g.type==="CommandSubstitution"||g.type==="ParameterExpansion"||g.type==="ArithmeticExpansion")){if(u.length>0){let g=u.shift();return d.shift(),await this.runCommand(g,u,d,s,!1,!1,c)}return P("","",this.ctx.state.lastExitCode)}return S(`bash: : command not found
|
|
664
664
|
`,127)}if(f==="exec"&&(u.length===0||u[0]==="--")){for(let y of t.redirections){if(y.target.type==="HereDoc"||y.fdVariable)continue;let g=await T(this.ctx,y.target),v=y.fd??(y.operator==="<"||y.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),y.operator){case">":case">|":{let _=this.ctx.fs.resolvePath(this.ctx.state.cwd,g);await this.ctx.fs.writeFile(_,"","utf8"),this.ctx.state.fileDescriptors.set(v,`__file__:${_}`);break}case">>":{let _=this.ctx.fs.resolvePath(this.ctx.state.cwd,g);this.ctx.state.fileDescriptors.set(v,`__file_append__:${_}`);break}case"<":{let _=this.ctx.fs.resolvePath(this.ctx.state.cwd,g);try{let k=await this.ctx.fs.readFile(_);this.ctx.state.fileDescriptors.set(v,k)}catch{return S(`bash: ${g}: No such file or directory
|
|
665
665
|
`)}break}case"<>":{let _=this.ctx.fs.resolvePath(this.ctx.state.cwd,g);try{let k=await this.ctx.fs.readFile(_);this.ctx.state.fileDescriptors.set(v,`__rw__:${_.length}:${_}:0:${k}`)}catch{await this.ctx.fs.writeFile(_,"","utf8"),this.ctx.state.fileDescriptors.set(v,`__rw__:${_.length}:${_}:0:`)}break}case">&":{if(g==="-")this.ctx.state.fileDescriptors.delete(v);else if(g.endsWith("-")){let _=g.slice(0,-1),k=Number.parseInt(_,10);if(!Number.isNaN(k)){let I=this.ctx.state.fileDescriptors.get(k);I!==void 0?this.ctx.state.fileDescriptors.set(v,I):this.ctx.state.fileDescriptors.set(v,`__dupout__:${k}`),this.ctx.state.fileDescriptors.delete(k)}}else{let _=Number.parseInt(g,10);Number.isNaN(_)||this.ctx.state.fileDescriptors.set(v,`__dupout__:${_}`)}break}case"<&":{if(g==="-")this.ctx.state.fileDescriptors.delete(v);else if(g.endsWith("-")){let _=g.slice(0,-1),k=Number.parseInt(_,10);if(!Number.isNaN(k)){let I=this.ctx.state.fileDescriptors.get(k);I!==void 0?this.ctx.state.fileDescriptors.set(v,I):this.ctx.state.fileDescriptors.set(v,`__dupin__:${k}`),this.ctx.state.fileDescriptors.delete(k)}}else{let _=Number.parseInt(g,10);Number.isNaN(_)||this.ctx.state.fileDescriptors.set(v,`__dupin__:${_}`)}break}}}for(let[y,g]of Object.entries(r))g===void 0?delete this.ctx.state.env[y]:this.ctx.state.env[y]=g;if(this.ctx.state.tempExportedVars)for(let y of Object.keys(r))this.ctx.state.tempExportedVars.delete(y);return L}let m=await br(this.ctx,f,u);Object.keys(r).length>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(Object.entries(r))));let p,w=null;try{p=await this.runCommand(f,u,d,s,!1,!1,c)}catch(y){if(y instanceof re||y instanceof ie)w=y,p=L;else throw y}let b=i+m;if(b&&(p={...p,stderr:b+p.stderr}),p=await j(this.ctx,p,t.redirections),w)throw w;if(u.length>0){let y=u[u.length-1];if((f==="declare"||f==="local"||f==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(y)){let g=y.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);g&&(y=g[1])}this.ctx.state.lastArg=y}else this.ctx.state.lastArg=f;let $=Dn(f)&&f!=="unset"&&f!=="eval";if(!this.ctx.state.options.posix||!$)for(let[y,g]of Object.entries(r))this.ctx.state.fullyUnsetLocals?.has(y)||(g===void 0?delete this.ctx.state.env[y]:this.ctx.state.env[y]=g);if(this.ctx.state.tempExportedVars)for(let y of Object.keys(r))this.ctx.state.tempExportedVars.delete(y);return Object.keys(r).length>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(p={...p,stderr:this.ctx.state.expansionStderr+p.stderr},this.ctx.state.expansionStderr=""),p}async runCommand(t,s,n,r,i=!1,o=!1,a=-1){let l={ctx:this.ctx,runCommand:(f,u,d,h,m,p,w)=>this.runCommand(f,u,d,h,m,p,w),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(f,u,d)=>this.executeUserScript(f,u,d)},c=await cr(l,t,s,n,r,i,o,a);return c!==null?c:fr(l,t,s,r,o)}aliasExpansionStack=new Set;expandAlias(t){return qt(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return Dt(this.ctx,t)}async executeSubshell(t,s=""){return Pr(this.ctx,t,s,n=>this.executeStatement(n))}async executeGroup(t,s=""){return _r(this.ctx,t,s,n=>this.executeStatement(n))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await ye(this.ctx,t.redirections);if(s)return s;try{let n=await V(this.ctx,t.expression.expression),r=q(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),j(this.ctx,r,t.redirections)}catch(n){let r=S(`bash: arithmetic expression: ${n.message}
|
|
666
|
-
`);return j(this.ctx,r,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await ye(this.ctx,t.redirections);if(s)return s;try{let n=await
|
|
667
|
-
`,r);return j(this.ctx,i,t.redirections)}}};var
|
|
668
|
-
`,OSTYPE:"linux-gnu",MACHTYPE:"x86_64-pc-linux-gnu",HOSTTYPE:"x86_64",HOSTNAME:"localhost",PWD:n,OLDPWD:n,OPTIND:"1",...t.env};if(this.limits=Cr({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}}),t.network&&(this.secureFetch=Ws(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.state={env:r,cwd:n,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,bashPid:process.pid,nextVirtualPid:process.pid+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.SHELLOPTS=jt(this.state.options),this.state.env.BASHOPTS=Ht(this.state.shoptOptions),fn(s,this.useDefaultLayout),n!=="/"&&s instanceof
|
|
666
|
+
`);return j(this.ctx,r,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await ye(this.ctx,t.redirections);if(s)return s;try{let n=await Ce(this.ctx,t.expression),r=q(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),j(this.ctx,r,t.redirections)}catch(n){let r=n instanceof Oe?1:2,i=S(`bash: conditional expression: ${n.message}
|
|
667
|
+
`,r);return j(this.ctx,i,t.redirections)}}};var Ae={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:3e4};function Cr(e){return e?{maxCallDepth:e.maxCallDepth??Ae.maxCallDepth,maxCommandCount:e.maxCommandCount??Ae.maxCommandCount,maxLoopIterations:e.maxLoopIterations??Ae.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??Ae.maxAwkIterations,maxSedIterations:e.maxSedIterations??Ae.maxSedIterations,maxJqIterations:e.maxJqIterations??Ae.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??Ae.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??Ae.maxPythonTimeoutMs}:{...Ae}}function kr(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function io(e){let t=kr(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function oo(e,t){let s=kr(e);if(!s)return!1;let n=io(t);return!n||s.origin!==n.origin?!1:n.pathPrefix==="/"||n.pathPrefix===""?!0:s.pathname.startsWith(n.pathPrefix)}function Ms(e,t){return!t||t.length===0?!1:t.some(s=>oo(e,s))}var ze=class extends Error{constructor(t){super(`Network access denied: URL not in allow-list: ${t}`),this.name="NetworkAccessDeniedError"}},Ve=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},Be=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},It=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}};var ao=20,lo=3e4,co=["GET","HEAD"],fo=new Set(["GET","HEAD","OPTIONS"]),uo=new Set([301,302,303,307,308]);function Ws(e){let t=e.maxRedirects??ao,s=e.timeoutMs??lo,n=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??co;function r(a){if(!e.dangerouslyAllowFullInternetAccess&&!Ms(a,e.allowedUrlPrefixes??[]))throw new ze(a)}function i(a){if(e.dangerouslyAllowFullInternetAccess)return;let l=a.toUpperCase();if(!n.includes(l))throw new It(l,n)}async function o(a,l={}){let c=l.method?.toUpperCase()??"GET";r(a),i(c);let f=a,u=0,d=l.followRedirects??!0,h=l.timeoutMs!==void 0?Math.min(l.timeoutMs,s):s;for(;;){let m=new AbortController,p=setTimeout(()=>m.abort(),h);try{let w={method:c,headers:l.headers,signal:m.signal,redirect:"manual"};l.body&&!fo.has(c)&&(w.body=l.body);let b=await fetch(f,w);if(uo.has(b.status)&&d){let $=b.headers.get("location");if(!$)return await Or(b,f);let C=new URL($,f).href;if(!e.dangerouslyAllowFullInternetAccess&&!Ms(C,e.allowedUrlPrefixes??[]))throw new Be(C);if(u++,u>t)throw new Ve(t);f=C;continue}return await Or(b,f)}finally{clearTimeout(p)}}}return o}async function Or(e,t){let s={};return e.headers.forEach((n,r)=>{s[r.toLowerCase()]=n}),{status:e.status,statusText:e.statusText,headers:s,body:await e.text(),url:t}}var tt=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;state;constructor(t={}){let s=t.fs??new $e(t.files);this.fs=s,this.useDefaultLayout=!t.cwd&&!t.files;let n=t.cwd||(this.useDefaultLayout?"/home/user":"/"),r={HOME:this.useDefaultLayout?"/home/user":"/",PATH:"/usr/bin:/bin",IFS:`
|
|
668
|
+
`,OSTYPE:"linux-gnu",MACHTYPE:"x86_64-pc-linux-gnu",HOSTTYPE:"x86_64",HOSTNAME:"localhost",PWD:n,OLDPWD:n,OPTIND:"1",...t.env};if(this.limits=Cr({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}}),t.network&&(this.secureFetch=Ws(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.state={env:r,cwd:n,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,bashPid:process.pid,nextVirtualPid:process.pid+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.SHELLOPTS=jt(this.state.options),this.state.env.BASHOPTS=Ht(this.state.shoptOptions),fn(s,this.useDefaultLayout),n!=="/"&&s instanceof $e)try{s.mkdirSync(n,{recursive:!0})}catch{}for(let i of on(t.commands))this.registerCommand(i);if(t.network)for(let i of an())this.registerCommand(i);if(t.customCommands)for(let i of t.customCommands)ln(i)?this.registerCommand(cn(i)):this.registerCommand(i)}registerCommand(t){this.commands.set(t.name,t);let s=this.fs;if(typeof s.writeFileSync=="function"){let n=`#!/bin/bash
|
|
669
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:{...this.state.env,...s?.env}};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:{...this.state.env,...s?.env}};this.logger?.info("exec",{command:t});let n=s?.cwd??this.state.cwd,r,i=n;if(s?.cwd)if(s.env&&"PWD"in s.env)r=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{r=await this.fs.realpath(n),i=r}catch{r=n}else r=n;let o={...this.state,env:{...this.state.env,...s?.env,...r!==void 0?{PWD:r}:{}},cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable},a=t;s?.rawScript||(a=ho(t));try{let l=de(a),c={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn},u=await new et(c,o).executeScript(l);return this.logResult(u)}catch(l){if(l instanceof z)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode,env:{...this.state.env,...s?.env}});if(l instanceof ce)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode,env:{...this.state.env,...s?.env}});if(l instanceof
|
|
671
|
+
`,exitCode:1,env:{...this.state.env,...s?.env}};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:{...this.state.env,...s?.env}};this.logger?.info("exec",{command:t});let n=s?.cwd??this.state.cwd,r,i=n;if(s?.cwd)if(s.env&&"PWD"in s.env)r=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{r=await this.fs.realpath(n),i=r}catch{r=n}else r=n;let o={...this.state,env:{...this.state.env,...s?.env,...r!==void 0?{PWD:r}:{}},cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable},a=t;s?.rawScript||(a=ho(t));try{let l=de(a),c={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn},u=await new et(c,o).executeScript(l);return this.logResult(u)}catch(l){if(l instanceof z)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode,env:{...this.state.env,...s?.env}});if(l instanceof ce)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode,env:{...this.state.env,...s?.env}});if(l instanceof Oe)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:1,env:{...this.state.env,...s?.env}});if(l instanceof te)return this.logResult({stdout:l.stdout,stderr:l.stderr,exitCode:te.EXIT_CODE,env:{...this.state.env,...s?.env}});if(l.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${l.message}
|
|
672
672
|
`,exitCode:2,env:{...this.state.env,...s?.env}});if(l instanceof Hs)return this.logResult({stdout:"",stderr:`bash: ${l.message}
|
|
673
673
|
`,exitCode:2,env:{...this.state.env,...s?.env}});if(l instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${l.message}
|
|
674
674
|
`,exitCode:1,env:{...this.state.env,...s?.env}});throw l}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,s){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),s)}getCwd(){return this.state.cwd}getEnv(){return{...this.state.env}}};function ho(e){let t=e.split(`
|
|
675
675
|
`),s=[],n=[];for(let r=0;r<t.length;r++){let i=t[r];if(n.length>0){let l=n[n.length-1];if((l.stripTabs?i.replace(/^\t+/,""):i)===l.delimiter){s.push(i.trimStart()),n.pop();continue}s.push(i);continue}let o=i.trimStart();s.push(o);let a=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let l of o.matchAll(a)){let c=l[1]==="-",f=l[3];n.push({delimiter:f,stripTabs:c})}}return s.join(`
|
|
676
|
-
`)}var Rt=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new Ee,t?.mounts)for(let{mountPoint:s,filesystem:n}of t.mounts)this.mount(s,n)}mount(t,s){this.validateMountPath(t);let n=this.normalizePath(t);this.validateMount(n),this.mounts.set(n,{mountPoint:n,filesystem:s})}unmount(t){let s=this.normalizePath(t);if(!this.mounts.has(s))throw new Error(`No filesystem mounted at '${t}'`);this.mounts.delete(s)}getMounts(){return Array.from(this.mounts.values()).map(t=>({mountPoint:t.mountPoint,filesystem:t.filesystem}))}isMountPoint(t){let s=this.normalizePath(t);return this.mounts.has(s)}validateMountPath(t){let s=t.split("/");for(let n of s)if(n==="."||n==="..")throw new Error(`Invalid mount point '${t}': contains '.' or '..' segments`)}validateMount(t){if(t==="/")throw new Error("Cannot mount at root '/'");for(let s of this.mounts.keys())if(s!==t){if(t.startsWith(`${s}/`))throw new Error(`Cannot mount at '${t}': inside existing mount '${s}'`);if(s.startsWith(`${t}/`))throw new Error(`Cannot mount at '${t}': would contain existing mount '${s}'`)}}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`}routePath(t){let s=this.normalizePath(t),n=null,r=0;for(let i of this.mounts.values()){let o=i.mountPoint;if(s===o)return{fs:i.filesystem,relativePath:"/"};s.startsWith(`${o}/`)&&o.length>r&&(n=i,r=o.length)}if(n){let i=s.slice(r);return{fs:n.filesystem,relativePath:i||"/"}}return{fs:this.baseFs,relativePath:s}}getChildMountPoints(t){let s=this.normalizePath(t),n=s==="/"?"/":`${s}/`,r=[];for(let i of this.mounts.keys())if(i.startsWith(n)){let a=i.slice(n.length).split("/")[0];a&&!r.includes(a)&&r.push(a)}return r}async readFile(t,s){let{fs:n,relativePath:r}=this.routePath(t);return n.readFile(r,s)}async readFileBuffer(t){let{fs:s,relativePath:n}=this.routePath(t);return s.readFileBuffer(n)}async writeFile(t,s,n){let{fs:r,relativePath:i}=this.routePath(t);return r.writeFile(i,s,n)}async appendFile(t,s,n){let{fs:r,relativePath:i}=this.routePath(t);return r.appendFile(i,s,n)}async exists(t){let s=this.normalizePath(t);if(this.mounts.has(s)||this.getChildMountPoints(s).length>0)return!0;let{fs:r,relativePath:i}=this.routePath(t);return r.exists(i)}async stat(t){let s=this.normalizePath(t),n=this.mounts.get(s);if(n)try{return await n.filesystem.stat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(s).length>0)try{return await this.baseFs.stat(s)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.stat(o)}async lstat(t){let s=this.normalizePath(t),n=this.mounts.get(s);if(n)try{return await n.filesystem.lstat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(s).length>0)try{return await this.baseFs.lstat(s)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.lstat(o)}async mkdir(t,s){let n=this.normalizePath(t);if(this.mounts.has(n)){if(s?.recursive)return;throw new Error(`EEXIST: directory already exists, mkdir '${t}'`)}if(this.getChildMountPoints(n).length>0&&s?.recursive)return;let{fs:i,relativePath:o}=this.routePath(t);return i.mkdir(o,s)}async readdir(t){let s=this.normalizePath(t),n=new Set,r=null,{fs:i,relativePath:o}=this.routePath(t);try{let l=await i.readdir(o);for(let c of l)n.add(c)}catch(l){let c=l.code,f=l.message||"";if(c!=="ENOENT"&&!f.includes("ENOENT"))throw l;r=l}let a=this.getChildMountPoints(s);for(let l of a)n.add(l);if(n.size===0&&r&&!this.mounts.has(s))throw r;return Array.from(n).sort()}async rm(t,s){let n=this.normalizePath(t);if(this.mounts.has(n))throw new Error(`EBUSY: mount point, cannot remove '${t}'`);if(this.getChildMountPoints(n).length>0)throw new Error(`EBUSY: contains mount points, cannot remove '${t}'`);let{fs:i,relativePath:o}=this.routePath(t);return i.rm(o,s)}async cp(t,s,n){let r=this.routePath(t),i=this.routePath(s);return r.fs===i.fs?r.fs.cp(r.relativePath,i.relativePath,n):this.crossMountCopy(t,s,n)}async mv(t,s){let n=this.normalizePath(t);if(this.mounts.has(n))throw new Error(`EBUSY: mount point, cannot move '${t}'`);let r=this.routePath(t),i=this.routePath(s);if(r.fs===i.fs)return r.fs.mv(r.relativePath,i.relativePath);await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=new Set;for(let s of this.baseFs.getAllPaths())t.add(s);for(let s of this.mounts.keys()){let n=s.split("/").filter(Boolean),r="";for(let o of n)r=`${r}/${o}`,t.add(r);let i=this.mounts.get(s);if(i)for(let o of i.filesystem.getAllPaths())o==="/"?t.add(s):t.add(`${s}${o}`)}return Array.from(t).sort()}async chmod(t,s){let n=this.normalizePath(t),r=this.mounts.get(n);if(r)return r.filesystem.chmod("/",s);let{fs:i,relativePath:o}=this.routePath(t);return i.chmod(o,s)}async symlink(t,s){let{fs:n,relativePath:r}=this.routePath(s);return n.symlink(t,r)}async link(t,s){let n=this.routePath(t),r=this.routePath(s);if(n.fs!==r.fs)throw new Error(`EXDEV: cross-device link not permitted, link '${t}' -> '${s}'`);return n.fs.link(n.relativePath,r.relativePath)}async readlink(t){let{fs:s,relativePath:n}=this.routePath(t);return s.readlink(n)}async realpath(t){let s=this.normalizePath(t);if(this.mounts.get(s))return s;let{fs:r,relativePath:i}=this.routePath(t),o=await r.realpath(i);for(let[a,l]of this.mounts)if(s===a||s.startsWith(`${a}/`))return o==="/"?a:`${a}${o}`;return o}async crossMountCopy(t,s,n){let r=await this.lstat(t);if(r.isFile){let i=await this.readFileBuffer(t);await this.writeFile(s,i),await this.chmod(s,r.mode)}else if(r.isDirectory){if(!n?.recursive)throw new Error(`cp: ${t} is a directory (not copied)`);await this.mkdir(s,{recursive:!0});let i=await this.readdir(t);for(let o of i){let a=t==="/"?`/${o}`:`${t}/${o}`,l=s==="/"?`/${o}`:`${s}/${o}`;await this.crossMountCopy(a,l,n)}}else if(r.isSymbolicLink){let i=await this.readlink(t);await this.symlink(i,s)}}async utimes(t,s,n){let{fs:r,relativePath:i}=this.routePath(t);return r.utimes(i,s,n)}};import*as G from"node:fs";import*as je from"node:path";var po="/home/user/project",He=class{root;mountPoint;readOnly;memory=new Map;deleted=new Set;constructor(t){this.root=je.resolve(t.root);let s=t.mountPoint??po;if(this.mountPoint=s==="/"?"/":s.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${s}`);if(this.readOnly=t.readOnly??!1,!G.existsSync(this.root))throw new Error(`OverlayFs root does not exist: ${this.root}`);if(!G.statSync(this.root).isDirectory())throw new Error(`OverlayFs root is not a directory: ${this.root}`);this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){let t=this.mountPoint.split("/").filter(Boolean),s="";for(let n of t)s+=`/${n}`,this.memory.has(s)||this.memory.set(s,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.memory.set("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}mkdirSync(t,s){let r=this.normalizePath(t).split("/").filter(Boolean),i="";for(let o of r)i+=`/${o}`,this.memory.has(i)||this.memory.set(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,s){let n=this.normalizePath(t),r=this.getDirname(n);r!=="/"&&this.mkdirSync(r);let i=s instanceof Uint8Array?s:new TextEncoder().encode(s);this.memory.set(n,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let s=this.normalizePath(t),n=this.getRelativeToMount(s);if(n===null)return null;let r=je.join(this.root,n),i=je.resolve(r);return!i.startsWith(this.root)&&i!==this.root.replace(/\/$/,"")?null:i}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.memory.has(s)||(this.ensureParentDirs(s),this.memory.set(s,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(s))}async existsInOverlay(t){let s=this.normalizePath(t);if(this.deleted.has(s))return!1;if(this.memory.has(s))return!0;let n=this.toRealPath(s);if(!n)return!1;try{return await G.promises.access(n),!0}catch{return!1}}async readFile(t,s){let n=await this.readFileBuffer(t),r=le(s);return Re(n,r)}async readFileBuffer(t,s=new Set){let n=this.normalizePath(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let o=this.resolveSymlink(n,r.target);return this.readFileBuffer(o,s)}if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return r.content}let i=this.toRealPath(n);if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let o=await G.promises.lstat(i);if(o.isSymbolicLink()){let l=await G.promises.readlink(i),c=this.resolveSymlink(n,l);return this.readFileBuffer(c,s)}if(o.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);let a=await G.promises.readFile(i);return new Uint8Array(a)}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${t}'`):o}}async writeFile(t,s,n){this.assertWritable(`write '${t}'`);let r=this.normalizePath(t);this.ensureParentDirs(r);let i=le(n),o=be(s,i);this.memory.set(r,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(r)}async appendFile(t,s,n){this.assertWritable(`append '${t}'`);let r=this.normalizePath(t),i=le(n),o=be(s,i),a;try{a=await this.readFileBuffer(r)}catch{a=new Uint8Array(0)}let l=new Uint8Array(a.length+o.length);l.set(a),l.set(o,a.length),this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:420,mtime:new Date}),this.deleted.delete(r)}async exists(t){return this.existsInOverlay(t)}async stat(t,s=new Set){let n=this.normalizePath(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let a=this.resolveSymlink(n,r.target);return this.stat(a,s)}let o=0;return r.type==="file"&&(o=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:o,mtime:r.mtime}}let i=this.toRealPath(n);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let o=await G.promises.stat(i);return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:!1,mode:o.mode,size:o.size,mtime:o.mtime}}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${t}'`):o}}async lstat(t){let s=this.normalizePath(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let n=this.memory.get(s);if(n){if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime};let i=0;return n.type==="file"&&(i=n.content.length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:i,mtime:n.mtime}}let r=this.toRealPath(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await G.promises.lstat(r);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${t}'`):i}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}async mkdir(t,s){this.assertWritable(`mkdir '${t}'`);let n=this.normalizePath(t);if(await this.existsInOverlay(n)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=this.dirname(n);if(i!=="/"&&!await this.existsInOverlay(i))if(s?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.memory.set(n,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(n)}async readdirCore(t,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Map,r=new Set,i=s==="/"?"/":`${s}/`;for(let a of this.deleted)if(a.startsWith(i)){let l=a.slice(i.length),c=l.split("/")[0];c&&!l.includes("/",c.length)&&r.add(c)}for(let[a,l]of this.memory)if(a!==s&&a.startsWith(i)){let c=a.slice(i.length),f=c.split("/")[0];f&&!r.has(f)&&!c.includes("/",1)&&n.set(f,{name:f,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let o=this.toRealPath(s);if(o)try{let a=await G.promises.readdir(o,{withFileTypes:!0});for(let l of a)!r.has(l.name)&&!n.has(l.name)&&n.set(l.name,{name:l.name,isFile:l.isFile(),isDirectory:l.isDirectory(),isSymbolicLink:l.isSymbolicLink()})}catch(a){if(a.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else if(a.code!=="ENOTDIR")throw a}return n}async resolveForReaddir(t,s=!1){let n=this.normalizePath(t),r=new Set,i=s,o=this.memory.get(n);for(;o&&o.type==="symlink";){if(r.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(n),i=!0,n=this.resolveSymlink(n,o.target),o=this.memory.get(n)}if(o)return{normalized:n,outsideOverlay:!1};if(this.getRelativeToMount(n)===null)return{normalized:n,outsideOverlay:!0};let l=this.toRealPath(n);if(!l)return{normalized:n,outsideOverlay:!0};try{if((await G.promises.lstat(l)).isSymbolicLink()){let f=await G.promises.readlink(l),u=this.resolveSymlink(n,f);return this.resolveForReaddir(u,!0)}return{normalized:n,outsideOverlay:!1}}catch{return i?{normalized:n,outsideOverlay:!0}:{normalized:n,outsideOverlay:!1}}}async readdir(t){let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.keys()).sort((i,o)=>i<o?-1:i>o?1:0)}async readdirWithFileTypes(t){let{normalized:s,outsideOverlay:n}=await this.resolveForReaddir(t);if(n)return[];let r=await this.readdirCore(t,s);return Array.from(r.values()).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async rm(t,s){this.assertWritable(`rm '${t}'`);let n=this.normalizePath(t);if(!await this.existsInOverlay(n)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(n)).isDirectory){let o=await this.readdir(n);if(o.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of o){let l=n==="/"?`/${a}`:`${n}/${a}`;await this.rm(l,s)}}}}catch{}this.deleted.add(n),this.memory.delete(n)}async cp(t,s,n){this.assertWritable(`cp '${s}'`);let r=this.normalizePath(t),i=this.normalizePath(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let a=await this.stat(r);if(a.isFile){let l=await this.readFileBuffer(r);await this.writeFile(i,l)}else if(a.isDirectory){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(r);for(let c of l){let f=r==="/"?`/${c}`:`${r}/${c}`,u=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(f,u,n)}}}async mv(t,s){this.assertWritable(`mv '${s}'`),await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=new Set(this.memory.keys());for(let s of this.deleted)t.delete(s);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,s){if(this.deleted.has(t))return;let n=this.toRealPath(t);if(n)try{let r=G.readdirSync(n);for(let i of r){let o=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(o))continue;s.add(o);let a=je.join(n,i);G.statSync(a).isDirectory()&&this.scanRealFs(o,s)}}catch{}}async chmod(t,s){this.assertWritable(`chmod '${t}'`);let n=this.normalizePath(t);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(n);if(i){i.mode=s;return}let o=await this.stat(n);if(o.isFile){let a=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:a,mode:s,mtime:new Date})}else o.isDirectory&&this.memory.set(n,{type:"directory",mode:s,mtime:new Date})}async symlink(t,s){this.assertWritable(`symlink '${s}'`);let n=this.normalizePath(s);if(await this.existsInOverlay(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.memory.set(n,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(n)}async link(t,s){this.assertWritable(`link '${s}'`);let n=this.normalizePath(t),r=this.normalizePath(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let o=await this.stat(n);if(!o.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, link '${s}'`);let l=await this.readFileBuffer(n);this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:o.mode,mtime:new Date}),this.deleted.delete(r)}async readlink(t){let s=this.normalizePath(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let n=this.memory.get(s);if(n){if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}let r=this.toRealPath(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{return await G.promises.readlink(r)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${t}'`):i.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${t}'`):i}}async realpath(t){let s=this.normalizePath(t),n=new Set,r=async a=>{let l=a==="/"?[]:a.slice(1).split("/"),c="";for(let f of l){if(c=`${c}/${f}`,n.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let u=this.memory.get(c),d=0,h=40;for(;u&&u.type==="symlink"&&d<h;){if(n.add(c),c=this.resolveSymlink(c,u.target),d++,n.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);u=this.memory.get(c)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!u){let m=this.toRealPath(c);if(m)try{if((await G.promises.lstat(m)).isSymbolicLink()){let w=await G.promises.readlink(m);return n.add(c),c=this.resolveSymlink(c,w),r(c)}}catch(p){throw p.code==="ENOENT"?new Error(`ENOENT: no such file or directory, realpath '${t}'`):p}}}return c||"/"},i=await r(s);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,s,n){this.assertWritable(`utimes '${t}'`);let r=this.normalizePath(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let o=this.memory.get(r);if(o){o.mtime=n;return}let a=await this.stat(r);if(a.isFile){let l=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:l,mode:a.mode,mtime:n})}else a.isDirectory&&this.memory.set(r,{type:"directory",mode:a.mode,mtime:n})}};import*as B from"node:fs";import*as we from"node:path";var xt=class{root;constructor(t){if(this.root=we.resolve(t.root),!B.existsSync(this.root))throw new Error(`ReadWriteFs root does not exist: ${this.root}`);if(!B.statSync(this.root).isDirectory())throw new Error(`ReadWriteFs root is not a directory: ${this.root}`)}toRealPath(t){let s=this.normalizePath(t),n=we.join(this.root,s);return we.resolve(n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}async readFile(t,s){let n=await this.readFileBuffer(t),r=le(s);return Re(n,r)}async readFileBuffer(t){let s=this.toRealPath(t);try{let n=await B.promises.readFile(s);return new Uint8Array(n)}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${t}'`):r.code==="EISDIR"?new Error(`EISDIR: illegal operation on a directory, read '${t}'`):n}}async writeFile(t,s,n){let r=this.toRealPath(t),i=le(n),o=be(s,i),a=we.dirname(r);await B.promises.mkdir(a,{recursive:!0}),await B.promises.writeFile(r,o)}async appendFile(t,s,n){let r=this.toRealPath(t),i=le(n),o=be(s,i),a=we.dirname(r);await B.promises.mkdir(a,{recursive:!0}),await B.promises.appendFile(r,o)}async exists(t){let s=this.toRealPath(t);try{return await B.promises.access(s),!0}catch{return!1}}async stat(t){let s=this.toRealPath(t);try{let n=await B.promises.stat(s);return{isFile:n.isFile(),isDirectory:n.isDirectory(),isSymbolicLink:!1,mode:n.mode,size:n.size,mtime:n.mtime}}catch(n){throw n.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${t}'`):n}}async lstat(t){let s=this.toRealPath(t);try{let n=await B.promises.lstat(s);return{isFile:n.isFile(),isDirectory:n.isDirectory(),isSymbolicLink:n.isSymbolicLink(),mode:n.mode,size:n.size,mtime:n.mtime}}catch(n){throw n.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${t}'`):n}}async mkdir(t,s){let n=this.toRealPath(t);try{await B.promises.mkdir(n,{recursive:s?.recursive})}catch(r){let i=r;throw i.code==="EEXIST"?new Error(`EEXIST: file already exists, mkdir '${t}'`):i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, mkdir '${t}'`):r}}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){let s=this.toRealPath(t);try{return(await B.promises.readdir(s,{withFileTypes:!0})).map(r=>({name:r.name,isFile:r.isFile(),isDirectory:r.isDirectory(),isSymbolicLink:r.isSymbolicLink()})).sort((r,i)=>r.name<i.name?-1:r.name>i.name?1:0)}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, scandir '${t}'`):r.code==="ENOTDIR"?new Error(`ENOTDIR: not a directory, scandir '${t}'`):n}}async rm(t,s){let n=this.toRealPath(t);try{await B.promises.rm(n,{recursive:s?.recursive??!1,force:s?.force??!1})}catch(r){let i=r;throw i.code==="ENOENT"&&!s?.force?new Error(`ENOENT: no such file or directory, rm '${t}'`):i.code==="ENOTEMPTY"?new Error(`ENOTEMPTY: directory not empty, rm '${t}'`):r}}async cp(t,s,n){let r=this.toRealPath(t),i=this.toRealPath(s);try{await B.promises.cp(r,i,{recursive:n?.recursive??!1})}catch(o){let a=o;throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, cp '${t}'`):a.code==="EISDIR"?new Error(`EISDIR: is a directory, cp '${t}'`):o}}async mv(t,s){let n=this.toRealPath(t),r=this.toRealPath(s),i=we.dirname(r);await B.promises.mkdir(i,{recursive:!0});try{await B.promises.rename(n,r)}catch(o){let a=o;if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(a.code==="EXDEV"){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0});return}throw o}}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}getAllPaths(){let t=[];return this.scanDir("/",t),t}scanDir(t,s){let n=this.toRealPath(t);try{let r=B.readdirSync(n);for(let i of r){let o=t==="/"?`/${i}`:`${t}/${i}`;s.push(o);let a=we.join(n,i);B.statSync(a).isDirectory()&&this.scanDir(o,s)}}catch{}}async chmod(t,s){let n=this.toRealPath(t);try{await B.promises.chmod(n,s)}catch(r){throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, chmod '${t}'`):r}}async symlink(t,s){let n=this.toRealPath(s);try{await B.promises.symlink(t,n)}catch(r){throw r.code==="EEXIST"?new Error(`EEXIST: file already exists, symlink '${s}'`):r}}async link(t,s){let n=this.toRealPath(t),r=this.toRealPath(s);try{await B.promises.link(n,r)}catch(i){let o=i;throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, link '${t}'`):o.code==="EEXIST"?new Error(`EEXIST: file already exists, link '${s}'`):o.code==="EPERM"?new Error(`EPERM: operation not permitted, link '${t}'`):i}}async readlink(t){let s=this.toRealPath(t);try{return await B.promises.readlink(s)}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${t}'`):r.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${t}'`):n}}async realpath(t){let s=this.toRealPath(t);try{let n=await B.promises.realpath(s);return n.startsWith(this.root)?n.slice(this.root.length)||"/":n}catch(n){let r=n;throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, realpath '${t}'`):r.code==="ELOOP"?new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`):n}}async utimes(t,s,n){let r=this.toRealPath(t);try{await B.promises.utimes(r,s,n)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, utimes '${t}'`):i}}};var Ue=class{cmdId;cwd;startedAt;exitCode;bashEnv;cmdLine;env;explicitCwd;resultPromise;constructor(t,s,n,r,i=!1){this.cmdId=crypto.randomUUID(),this.cwd=n,this.startedAt=new Date,this.bashEnv=t,this.cmdLine=s,this.env=r,this.explicitCwd=i,this.resultPromise=this.execute()}async execute(){let t=this.env||this.explicitCwd?{cwd:this.explicitCwd?this.cwd:void 0,env:this.env}:void 0,s=await this.bashEnv.exec(this.cmdLine,t);return this.exitCode=s.exitCode,s}async*logs(){let t=await this.resultPromise;t.stdout&&(yield{type:"stdout",data:t.stdout,timestamp:new Date}),t.stderr&&(yield{type:"stderr",data:t.stderr,timestamp:new Date})}async wait(){return await this.resultPromise,this}async output(){let t=await this.resultPromise;return t.stdout+t.stderr}async stdout(){return(await this.resultPromise).stdout}async stderr(){return(await this.resultPromise).stderr}async kill(){}};var Lt=class e{bashEnv;constructor(t){this.bashEnv=t}static async create(t){let s=t?.fs;if(t?.overlayRoot){if(t?.fs)throw new Error("Cannot specify both 'fs' and 'overlayRoot' options");s=new He({root:t.overlayRoot})}let n=new tt({env:t?.env,cwd:t?.cwd,fs:s,maxCallDepth:t?.maxCallDepth,maxCommandCount:t?.maxCommandCount,maxLoopIterations:t?.maxLoopIterations,network:t?.network});return new e(n)}async runCommand(t,s){let n=s?.cwd??this.bashEnv.getCwd(),r=s?.cwd!==void 0;return new Ue(this.bashEnv,t,n,s?.env,r)}async writeFiles(t){for(let[s,n]of Object.entries(t)){let r;typeof n=="string"?r=n:n.encoding==="base64"?r=Buffer.from(n.content,"base64").toString("utf-8"):r=n.content;let i=s.substring(0,s.lastIndexOf("/"))||"/";i!=="/"&&await this.bashEnv.exec(`mkdir -p ${i}`),await this.bashEnv.writeFile(s,r)}}async readFile(t,s){let n=await this.bashEnv.readFile(t);return s==="base64"?Buffer.from(n).toString("base64"):n}async mkDir(t,s){let n=s?.recursive?"-p":"";await this.bashEnv.exec(`mkdir ${n} ${t}`)}async stop(){}async extendTimeout(t){}get domain(){}get bashEnvInstance(){return this.bashEnv}};export{tt as Bash,Ee as InMemoryFs,Rt as MountableFs,ze as NetworkAccessDeniedError,He as OverlayFs,xt as ReadWriteFs,Be as RedirectNotAllowedError,Lt as Sandbox,Ue as SandboxCommand,Ve as TooManyRedirectsError,Fr as defineCommand,xr as getCommandNames,Lr as getNetworkCommandNames};
|
|
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};
|