just-binary 2.9.8 → 2.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/bin/chunks/base64-XCZKQZ7Z.js +2 -0
  2. package/dist/bin/chunks/chunk-RUESYAVK.js +2 -0
  3. package/dist/bin/chunks/chunk-S23TISYL.js +6 -0
  4. package/dist/bin/{shell/chunks/chunk-CRHN4WNQ.js → chunks/chunk-ZD5OTNAU.js} +17 -17
  5. package/dist/bin/{shell/chunks/flag-coverage-DBKGNLJO.js → chunks/flag-coverage-RODPAQVH.js} +1 -1
  6. package/dist/bin/chunks/tar-IQNZQP7E.js +2 -0
  7. package/dist/bin/just-bash.js +97 -97
  8. package/dist/bin/shell/chunks/base64-XCZKQZ7Z.js +2 -0
  9. package/dist/bin/shell/chunks/chunk-RUESYAVK.js +2 -0
  10. package/dist/bin/shell/chunks/chunk-S23TISYL.js +6 -0
  11. package/dist/bin/{chunks/chunk-CRHN4WNQ.js → shell/chunks/chunk-ZD5OTNAU.js} +17 -17
  12. package/dist/bin/{chunks/flag-coverage-DBKGNLJO.js → shell/chunks/flag-coverage-RODPAQVH.js} +1 -1
  13. package/dist/bin/shell/chunks/tar-IQNZQP7E.js +2 -0
  14. package/dist/bin/shell/shell.js +97 -97
  15. package/dist/bundle/browser.js +426 -426
  16. package/dist/bundle/chunks/base64-5E5MPPWD.js +1 -0
  17. package/dist/bundle/chunks/chunk-DQTFPKDH.js +5 -0
  18. package/dist/bundle/chunks/chunk-MIFIRXNI.js +1 -0
  19. package/dist/bundle/chunks/{chunk-3OY3UJDR.js → chunk-ZCZOV2DS.js} +17 -17
  20. package/dist/bundle/chunks/{flag-coverage-FMTW4YWD.js → flag-coverage-LGRO7HFL.js} +1 -1
  21. package/dist/bundle/chunks/tar-K64VDNWF.js +1 -0
  22. package/dist/bundle/index.js +96 -96
  23. package/dist/utils/binary-string.d.ts +1 -0
  24. package/package.json +31 -29
  25. package/dist/bin/chunks/base64-DNX4WCIO.js +0 -2
  26. package/dist/bin/chunks/chunk-6CZOPIZD.js +0 -6
  27. package/dist/bin/chunks/tar-2UVSVD3P.js +0 -2
  28. package/dist/bin/shell/chunks/base64-DNX4WCIO.js +0 -2
  29. package/dist/bin/shell/chunks/chunk-6CZOPIZD.js +0 -6
  30. package/dist/bin/shell/chunks/tar-2UVSVD3P.js +0 -2
  31. package/dist/bundle/chunks/base64-RY5JPAQL.js +0 -1
  32. package/dist/bundle/chunks/chunk-N4GRDEVJ.js +0 -5
  33. package/dist/bundle/chunks/tar-7KN7KZ6S.js +0 -1
@@ -1,21 +1,21 @@
1
1
  #!/usr/bin/env node
2
- import{A as rs,C as bn,D as En,E as fe,F as We,G as te,H as $e,I as St,J as Sn,K as F,L as $n,M as An,N as Ce,O as is,P as $t,Q as He,R as q,a as fn,b as Jt,c as dn,d as hn,e as bt,f as Q,g as H,h as Ae,i as ne,j as _e,k as Ie,l as es,m as Et,n as pn,o as ts,p as mn,q as ue,r as Oe,s as yn,t as gn,u as ss,v as ns,w as Pe,x as vn,y as wn,z as Se}from"./chunks/chunk-OKQ6RACF.js";import{a as De,b as Ee}from"./chunks/chunk-F46CSMUF.js";import{a as st}from"./chunks/chunk-SE4C7FJY.js";import{a as me,b as ye,c as ce,d as ve,e as cn,f as G,g as Fe,h as gt,i as vt,j as un,k as oe,l as Te,m as wt,n as we}from"./chunks/chunk-QT2GMJRJ.js";import"./chunks/chunk-OBH7XN5N.js";import{a as be}from"./chunks/chunk-4VDEBYW7.js";import{a as yt,g as p,h as E,i as z,j as N,k as je,l as tt,m as O,n as v}from"./chunks/chunk-RQSPCXDR.js";import*as ei from"node:fs";import*as ti from"node:readline";var Ue=[{name:"echo",load:async()=>(await import("./chunks/echo-HBXOI5TQ.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-CL5ISR5P.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-XUGNJ3QM.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-IJLTWVOI.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-KYFAO2SF.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-CSK7CGH5.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-5ECNQNBP.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-3PFOF4E3.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-LVKHKFHQ.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-TWM2PA7Q.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-BSEVUP2J.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-R6IWRSKZ.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-RZG6GZEU.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-4SOSIDHE.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-TBQETLQX.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-JOQASWMV.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-2R4RS2SX.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-Q2TZRKO3.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-I63BWUKL.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-I63BWUKL.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-I63BWUKL.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-4YJSQZN7.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-XBCUZMEP.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-Z6VRXKAK.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-ELAGZUES.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-IKBUNAMN.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-5FNEJE7X.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-UXU6PNTT.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-FUGXVGJX.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-AVALLN54.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-5E5UGSUZ.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-XLF2HFST.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-AE57YLOS.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-F4FM4ML2.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-TDRWZW5F.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-IGEGP5QX.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-QGXYUWBC.js")).split},{name:"column",load:async()=>(await import("./chunks/column-FJNKONCJ.js")).column},{name:"join",load:async()=>(await import("./chunks/join-TRRWQBEU.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-IQLEDZOQ.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-W4BCEJEC.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-MPQ7M4RF.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-455JDV2M.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-UFM5EDXS.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-WUEAQO2W.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-MXFHTVHS.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-MXFHTVHS.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-23G4Q2RS.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-23G4Q2RS.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-2DYRIL3U.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-4MYN4U3C.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-BU5JSAAW.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-BU5JSAAW.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-27OP2FQZ.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-OQ32Y5I6.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-OQ32Y5I6.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-NFKKH27D.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-DNX4WCIO.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-3V3FOITV.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-GGPTXVUT.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-PNT7KILS.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-A36YWZWR.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-VRCJK2LI.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-H7ID4VMK.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-5ZKR5ER5.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-ZIQHOC4K.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-EDQNYXXH.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-APTG6DO2.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-BFN7BKUR.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-2VQWCEKU.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-HGMKZ2GW.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-6UVGMXDF.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-VOEDJLLG.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-RWEPTCXH.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-N6TLTETT.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-BOM6JPTH.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-X5IDXWZE.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-X5IDXWZE.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-X5IDXWZE.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ue.push({name:"tar",load:async()=>(await import("./chunks/tar-2UVSVD3P.js")).tarCommand}),Ue.push({name:"yq",load:async()=>(await import("./chunks/yq-EHDQVD7S.js")).yqCommand}),Ue.push({name:"xan",load:async()=>(await import("./chunks/xan-JX5QUK32.js")).xanCommand}),Ue.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-ELLMKNNJ.js")).sqlite3Command}));var os=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(os.push({name:"python3",load:async()=>(await import("./chunks/python3-PIXJS3YM.js")).python3Command}),os.push({name:"python",load:async()=>(await import("./chunks/python3-PIXJS3YM.js")).pythonCommand}));var ii=[{name:"curl",load:async()=>(await import("./chunks/curl-S4FJSZA5.js")).curlCommand}],_n=new Map;function as(e){return{name:e.name,async execute(t,s){let n=_n.get(e.name);if(n||(n=await e.load(),_n.set(e.name,n)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:r}=await import("./chunks/flag-coverage-DBKGNLJO.js"),{decodeArgs:i}=await import("./chunks/bytes-6YUZMX3P.js");r(s.coverage,e.name,i(t))}return n.execute(t,s)}}}function Pn(e){return(e?Ue.filter(s=>e.includes(s.name)):Ue).map(as)}function Cn(){return ii.map(as)}function kn(){return os.map(as)}function Nn(e){return"load"in e&&typeof e.load=="function"}function On(e){let t=null;return{name:e.name,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}var oi=new TextEncoder,ai=new TextDecoder;function Ge(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}if(t==="binary"||t==="latin1"){if(e.length<=65536)return Uint8Array.from(e,r=>r.charCodeAt(0));let n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return n}return oi.encode(e)}function At(e,t){if(t==="base64")return btoa(String.fromCharCode(...e));if(t==="hex")return Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join("");if(t==="binary"||t==="latin1"){if(typeof Buffer<"u")return Buffer.from(e).toString(t);let s=65536;if(e.length<=s)return String.fromCharCode(...e);let n="";for(let r=0;r<e.length;r+=s){let i=e.subarray(r,r+s);n+=String.fromCharCode(...i)}return n}return ai.decode(e)}function Re(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var _t=new TextEncoder;function li(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}function ae(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}var nt=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))li(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){ae(t,"write");let i=this.normalizePath(t);this.ensureParentDirs(i);let o=Re(n),a=Ge(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=Re(s);return At(n,r)}async readFileBuffer(t){ae(t,"open");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:_t.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){ae(t,"append");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=Re(n),a=Ge(s,o);if(i?.type==="file"){let c=i.content instanceof Uint8Array?i.content:_t.encode(i.content),u=new Uint8Array(c.length+a.length);u.set(c),u.set(a,c.length),this.data.set(r,{type:"file",content:u,mode:i.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){ae(t,"stat");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=_t.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){ae(t,"lstat");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=_t.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 c=this.data.get(r),u=0,l=40;for(;c&&c.type==="symlink"&&u<l;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(r),r=this.resolveSymlink(r,c.target),c=this.data.get(r),u++}if(u>=l)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),c=0,u=40;for(;a&&a.type==="symlink"&&c<u;){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),c++}if(c>=u)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){ae(t,"mkdir");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){ae(t,"scandir");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,c]of this.data.entries())if(a!==s&&a.startsWith(i)){let u=a.slice(i.length),l=u.split("/")[0];l&&!u.includes("/",l.length)&&!o.has(l)&&o.set(l,{name:l,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}return Array.from(o.values()).sort((a,c)=>a.name<c.name?-1:a.name>c.name?1:0)}async rm(t,s){ae(t,"rm");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){ae(t,"cp"),ae(s,"cp");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 c of a){let u=r==="/"?`/${c}`:`${r}/${c}`,l=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(u,l,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){ae(t,"chmod");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){ae(s,"symlink");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){ae(t,"link"),ae(s,"link");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){ae(t,"readlink");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){ae(t,"realpath");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){ae(t,"utimes");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 ci(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function ui(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 fi(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 di(e){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${fn}
2
+ import{A as rs,C as En,D as Sn,E as fe,F as We,G as te,H as $e,I as St,J as $n,K as F,L as An,M as _n,N as Ce,O as is,P as $t,Q as He,R as q,a as dn,b as Jt,c as hn,d as pn,e as bt,f as Q,g as H,h as Ae,i as ne,j as _e,k as Ie,l as es,m as Et,n as mn,o as ts,p as yn,q as ue,r as Oe,s as gn,t as vn,u as ss,v as ns,w as Pe,x as wn,y as bn,z as Se}from"./chunks/chunk-OKQ6RACF.js";import{a as fn}from"./chunks/chunk-RUESYAVK.js";import{a as De,b as Ee}from"./chunks/chunk-F46CSMUF.js";import{a as st}from"./chunks/chunk-SE4C7FJY.js";import{a as me,b as ye,c as ce,d as ve,e as cn,f as G,g as Fe,h as gt,i as vt,j as un,k as oe,l as Te,m as wt,n as we}from"./chunks/chunk-QT2GMJRJ.js";import"./chunks/chunk-OBH7XN5N.js";import{a as be}from"./chunks/chunk-4VDEBYW7.js";import{a as yt,g as p,h as E,i as z,j as N,k as je,l as tt,m as O,n as v}from"./chunks/chunk-RQSPCXDR.js";import*as ti from"node:fs";import*as si from"node:readline";var Ue=[{name:"echo",load:async()=>(await import("./chunks/echo-HBXOI5TQ.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-CL5ISR5P.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-XUGNJ3QM.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-IJLTWVOI.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-KYFAO2SF.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-CSK7CGH5.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-5ECNQNBP.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-3PFOF4E3.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-LVKHKFHQ.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-TWM2PA7Q.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-BSEVUP2J.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-R6IWRSKZ.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-RZG6GZEU.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-4SOSIDHE.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-TBQETLQX.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-JOQASWMV.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-2R4RS2SX.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-Q2TZRKO3.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-I63BWUKL.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-I63BWUKL.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-I63BWUKL.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-4YJSQZN7.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-XBCUZMEP.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-Z6VRXKAK.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-ELAGZUES.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-IKBUNAMN.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-5FNEJE7X.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-UXU6PNTT.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-FUGXVGJX.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-AVALLN54.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-5E5UGSUZ.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-XLF2HFST.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-AE57YLOS.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-F4FM4ML2.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-TDRWZW5F.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-IGEGP5QX.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-QGXYUWBC.js")).split},{name:"column",load:async()=>(await import("./chunks/column-FJNKONCJ.js")).column},{name:"join",load:async()=>(await import("./chunks/join-TRRWQBEU.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-IQLEDZOQ.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-W4BCEJEC.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-MPQ7M4RF.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-455JDV2M.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-UFM5EDXS.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-WUEAQO2W.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-MXFHTVHS.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-MXFHTVHS.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-23G4Q2RS.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-23G4Q2RS.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-2DYRIL3U.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-4MYN4U3C.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-BU5JSAAW.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-BU5JSAAW.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-27OP2FQZ.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-OQ32Y5I6.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-OQ32Y5I6.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-NFKKH27D.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-XCZKQZ7Z.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-3V3FOITV.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-GGPTXVUT.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-PNT7KILS.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-A36YWZWR.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-VRCJK2LI.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-H7ID4VMK.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-5ZKR5ER5.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-ZIQHOC4K.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-EDQNYXXH.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-APTG6DO2.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-BFN7BKUR.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-2VQWCEKU.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-HGMKZ2GW.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-6UVGMXDF.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-VOEDJLLG.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-RWEPTCXH.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-N6TLTETT.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-BOM6JPTH.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-X5IDXWZE.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-X5IDXWZE.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-X5IDXWZE.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ue.push({name:"tar",load:async()=>(await import("./chunks/tar-IQNZQP7E.js")).tarCommand}),Ue.push({name:"yq",load:async()=>(await import("./chunks/yq-EHDQVD7S.js")).yqCommand}),Ue.push({name:"xan",load:async()=>(await import("./chunks/xan-JX5QUK32.js")).xanCommand}),Ue.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-ELLMKNNJ.js")).sqlite3Command}));var os=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(os.push({name:"python3",load:async()=>(await import("./chunks/python3-PIXJS3YM.js")).python3Command}),os.push({name:"python",load:async()=>(await import("./chunks/python3-PIXJS3YM.js")).pythonCommand}));var oi=[{name:"curl",load:async()=>(await import("./chunks/curl-S4FJSZA5.js")).curlCommand}],Pn=new Map;function as(e){return{name:e.name,async execute(t,s){let n=Pn.get(e.name);if(n||(n=await e.load(),Pn.set(e.name,n)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:r}=await import("./chunks/flag-coverage-RODPAQVH.js"),{decodeArgs:i}=await import("./chunks/bytes-6YUZMX3P.js");r(s.coverage,e.name,i(t))}return n.execute(t,s)}}}function Cn(e){return(e?Ue.filter(s=>e.includes(s.name)):Ue).map(as)}function kn(){return oi.map(as)}function Nn(){return os.map(as)}function On(e){return"load"in e&&typeof e.load=="function"}function xn(e){let t=null;return{name:e.name,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}var ai=new TextEncoder,li=new TextDecoder;function Ge(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}if(t==="binary"||t==="latin1"){if(e.length<=65536)return Uint8Array.from(e,r=>r.charCodeAt(0));let n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return n}return ai.encode(e)}function At(e,t){if(t==="base64")return btoa(fn(e));if(t==="hex")return Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join("");if(t==="binary"||t==="latin1"){if(typeof Buffer<"u")return Buffer.from(e).toString(t);let s=65536;if(e.length<=s)return String.fromCharCode(...e);let n="";for(let r=0;r<e.length;r+=s){let i=e.subarray(r,r+s);n+=String.fromCharCode(...i)}return n}return li.decode(e)}function Re(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var _t=new TextEncoder;function ci(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}function ae(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}var nt=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))ci(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){ae(t,"write");let i=this.normalizePath(t);this.ensureParentDirs(i);let o=Re(n),a=Ge(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=Re(s);return At(n,r)}async readFileBuffer(t){ae(t,"open");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:_t.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){ae(t,"append");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=Re(n),a=Ge(s,o);if(i?.type==="file"){let c=i.content instanceof Uint8Array?i.content:_t.encode(i.content),u=new Uint8Array(c.length+a.length);u.set(c),u.set(a,c.length),this.data.set(r,{type:"file",content:u,mode:i.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){ae(t,"stat");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=_t.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){ae(t,"lstat");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=_t.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 c=this.data.get(r),u=0,l=40;for(;c&&c.type==="symlink"&&u<l;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(r),r=this.resolveSymlink(r,c.target),c=this.data.get(r),u++}if(u>=l)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),c=0,u=40;for(;a&&a.type==="symlink"&&c<u;){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),c++}if(c>=u)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){ae(t,"mkdir");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){ae(t,"scandir");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,c]of this.data.entries())if(a!==s&&a.startsWith(i)){let u=a.slice(i.length),l=u.split("/")[0];l&&!u.includes("/",l.length)&&!o.has(l)&&o.set(l,{name:l,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}return Array.from(o.values()).sort((a,c)=>a.name<c.name?-1:a.name>c.name?1:0)}async rm(t,s){ae(t,"rm");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){ae(t,"cp"),ae(s,"cp");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 c of a){let u=r==="/"?`/${c}`:`${r}/${c}`,l=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(u,l,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){ae(t,"chmod");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){ae(s,"symlink");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){ae(t,"link"),ae(s,"link");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){ae(t,"readlink");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){ae(t,"realpath");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){ae(t,"utimes");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 ui(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function fi(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 di(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 hi(e){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${dn}
3
3
  `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
4
- `),e.writeFileSync("/proc/self/status",dn()),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 xn(e,t){ci(e)&&(ui(e,t),fi(e),di(e))}var hi=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],pi=["braceexpand","hashall","interactive-comments"];function ls(e){let t=[],s=[...pi.map(n=>({name:n,enabled:!0})),...hi.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 qe(e){v(e.state.env,"SHELLOPTS",ls(e.state.options))}var mi=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function cs(e){let t=[];for(let s of mi)e[s]&&t.push(s);return t.join(":")}function us(e){v(e.state.env,"BASHOPTS",cs(e.state.shoptOptions))}var yi="BASH_ALIAS_";function Tn(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 In(e,t){let s=e.env.get(`${yi}${t}`);return s!==void 0?z(s):void 0}function fs(e,t,s){if(!t.name||!Tn(t.name))return t;let n=Dn(t.name);if(!n)return t;let r=In(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new H,o=r,a=r.endsWith(" ");if(!a)for(let f of t.args){let d=Ln(f);o+=` ${d}`}let c;try{c=i.parse(o)}catch(f){if(f instanceof bt)throw f;return t}if(c.statements.length!==1||c.statements[0].pipelines.length!==1||c.statements[0].pipelines[0].commands.length!==1)return Rn(t,r);let u=c.statements[0].pipelines[0].commands[0];if(u.type!=="SimpleCommand")return Rn(t,r);let l={...u,assignments:[...t.assignments,...u.assignments],redirections:[...u.redirections,...t.redirections],line:t.line};if(a&&t.args.length>0&&(l={...l,args:[...l.args,...t.args]},l.args.length>0)){let f=l.args[0];if(Tn(f)){let d=Dn(f);if(d&&In(e,d)){let h={type:"SimpleCommand",name:f,args:l.args.slice(1),assignments:[],redirections:[]},g=fs(e,h,s);g!==h&&(l={...l,name:g.name,args:[...g.args]})}}}return l}catch(i){throw s.delete(n),i}}function Rn(e,t){let s=t;for(let o of e.args){let a=Ln(o);s+=` ${a}`}let n=new H,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 Ln(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 Mn(e,t){let s=t.parts.map(l=>l.type==="Literal"?l.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="",c=!1;for(let l of t.parts)if(l.type==="Literal"){let f=l.value;if(!o){let d=f.indexOf("=(");d!==-1&&(o=!0,f=f.slice(d+2))}if(o){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(a||c)&&(i.push(a),a="",c=!1):h&&(a+=h)}}else if(o)if(l.type==="BraceExpansion")if(/^\[.+\]=/.test(a))a+=Et({type:"Word",parts:[l]});else{(a||c)&&(i.push(a),a="",c=!1);let d=await Ce(e,{type:"Word",parts:[l]});i.push(...d.values)}else{(l.type==="SingleQuoted"||l.type==="DoubleQuoted"||l.type==="Escaped")&&(c=!0);let f=await F(e,{type:"Word",parts:[l]});a+=f}(a||c)&&i.push(a);let u=i.map(l=>/^\[.+\]=/.test(l)?l:l===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(l)&&!l.startsWith("'")&&!l.startsWith('"')?`'${l.replace(/'/g,"'\\''")}'`:l);return`${r}=(${u.join(" ")})`}async function Fn(e,t){let s=-1,n=-1,r=!1;for(let m=0;m<t.parts.length;m++){let w=t.parts[m];if(w.type==="Literal"){let $=w.value.indexOf("+=");if($!==-1){let k=w.value.slice(0,$);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(k)){s=m,n=$,r=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(k)){s=m,n=$,r=!0;break}}let _=w.value.indexOf("=");if(_!==-1&&(_===0||w.value[_-1]!=="+")){let k=w.value.slice(0,_);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(k)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(k)){s=m,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,c=o.value.slice(0,n),u=o.value.slice(n+a),l=t.parts.slice(s+1),f="";for(let m of i)f+=await F(e,{type:"Word",parts:[m]});f+=c;let d={type:"Word",parts:u!==""?[{type:"Literal",value:u},...l]:l},h=d.parts.length>0?await F(e,d):"";return`${f}${r?"+=":"="}${h}`}var gi=["tar","yq","xan","sqlite3","python3","python"];function Wn(e){return gi.includes(e)}var V=Object.freeze({stdout:p,stderr:p,exitCode:0});function ge(e=p){return{stdout:e,stderr:p,exitCode:0}}function U(e){return{stdout:E(e),stderr:p,exitCode:0}}function P(e,t=1){return{stdout:p,stderr:E(e),exitCode:t}}function T(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function X(e){return{stdout:p,stderr:p,exitCode:e?0:1}}function xe(e,t,s=p,n=p){throw new oe(e,t,s,n)}function ds(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Te;return V}if(t.length>1)throw new G(1,p,E(`bash: break: too many arguments
4
+ `),e.writeFileSync("/proc/self/status",hn()),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 Tn(e,t){ui(e)&&(fi(e,t),di(e),hi(e))}var pi=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],mi=["braceexpand","hashall","interactive-comments"];function ls(e){let t=[],s=[...mi.map(n=>({name:n,enabled:!0})),...pi.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 qe(e){v(e.state.env,"SHELLOPTS",ls(e.state.options))}var yi=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function cs(e){let t=[];for(let s of yi)e[s]&&t.push(s);return t.join(":")}function us(e){v(e.state.env,"BASHOPTS",cs(e.state.shoptOptions))}var gi="BASH_ALIAS_";function Dn(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function In(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function Rn(e,t){let s=e.env.get(`${gi}${t}`);return s!==void 0?z(s):void 0}function fs(e,t,s){if(!t.name||!Dn(t.name))return t;let n=In(t.name);if(!n)return t;let r=Rn(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new H,o=r,a=r.endsWith(" ");if(!a)for(let f of t.args){let d=Mn(f);o+=` ${d}`}let c;try{c=i.parse(o)}catch(f){if(f instanceof bt)throw f;return t}if(c.statements.length!==1||c.statements[0].pipelines.length!==1||c.statements[0].pipelines[0].commands.length!==1)return Ln(t,r);let u=c.statements[0].pipelines[0].commands[0];if(u.type!=="SimpleCommand")return Ln(t,r);let l={...u,assignments:[...t.assignments,...u.assignments],redirections:[...u.redirections,...t.redirections],line:t.line};if(a&&t.args.length>0&&(l={...l,args:[...l.args,...t.args]},l.args.length>0)){let f=l.args[0];if(Dn(f)){let d=In(f);if(d&&Rn(e,d)){let h={type:"SimpleCommand",name:f,args:l.args.slice(1),assignments:[],redirections:[]},g=fs(e,h,s);g!==h&&(l={...l,name:g.name,args:[...g.args]})}}}return l}catch(i){throw s.delete(n),i}}function Ln(e,t){let s=t;for(let o of e.args){let a=Mn(o);s+=` ${a}`}let n=new H,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 Fn(e,t){let s=t.parts.map(l=>l.type==="Literal"?l.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="",c=!1;for(let l of t.parts)if(l.type==="Literal"){let f=l.value;if(!o){let d=f.indexOf("=(");d!==-1&&(o=!0,f=f.slice(d+2))}if(o){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(a||c)&&(i.push(a),a="",c=!1):h&&(a+=h)}}else if(o)if(l.type==="BraceExpansion")if(/^\[.+\]=/.test(a))a+=Et({type:"Word",parts:[l]});else{(a||c)&&(i.push(a),a="",c=!1);let d=await Ce(e,{type:"Word",parts:[l]});i.push(...d.values)}else{(l.type==="SingleQuoted"||l.type==="DoubleQuoted"||l.type==="Escaped")&&(c=!0);let f=await F(e,{type:"Word",parts:[l]});a+=f}(a||c)&&i.push(a);let u=i.map(l=>/^\[.+\]=/.test(l)?l:l===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(l)&&!l.startsWith("'")&&!l.startsWith('"')?`'${l.replace(/'/g,"'\\''")}'`:l);return`${r}=(${u.join(" ")})`}async function Wn(e,t){let s=-1,n=-1,r=!1;for(let m=0;m<t.parts.length;m++){let w=t.parts[m];if(w.type==="Literal"){let $=w.value.indexOf("+=");if($!==-1){let k=w.value.slice(0,$);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(k)){s=m,n=$,r=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(k)){s=m,n=$,r=!0;break}}let _=w.value.indexOf("=");if(_!==-1&&(_===0||w.value[_-1]!=="+")){let k=w.value.slice(0,_);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(k)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(k)){s=m,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,c=o.value.slice(0,n),u=o.value.slice(n+a),l=t.parts.slice(s+1),f="";for(let m of i)f+=await F(e,{type:"Word",parts:[m]});f+=c;let d={type:"Word",parts:u!==""?[{type:"Literal",value:u},...l]:l},h=d.parts.length>0?await F(e,d):"";return`${f}${r?"+=":"="}${h}`}var vi=["tar","yq","xan","sqlite3","python3","python"];function Vn(e){return vi.includes(e)}var V=Object.freeze({stdout:p,stderr:p,exitCode:0});function ge(e=p){return{stdout:e,stderr:p,exitCode:0}}function U(e){return{stdout:E(e),stderr:p,exitCode:0}}function P(e,t=1){return{stdout:p,stderr:E(e),exitCode:t}}function T(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function X(e){return{stdout:p,stderr:p,exitCode:e?0:1}}function xe(e,t,s=p,n=p){throw new oe(e,t,s,n)}function ds(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Te;return V}if(t.length>1)throw new G(1,p,E(`bash: break: too many arguments
5
5
  `));let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new G(128,p,E(`bash: break: ${t[0]}: numeric argument required
6
6
  `));s=n}throw new me(s)}async function hs(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?s=O(e.state.env,"HOME","/"):o[0]==="~"?s=O(e.state.env,"HOME","/"):o[0]==="-"?(s=e.state.previousDir,n=!0):s=o[0],!s.startsWith("/")&&!s.startsWith("./")&&!s.startsWith("../")&&s!=="."&&s!==".."){let f=e.state.env.get("CDPATH");if(f){let d=z(f??p).split(":").filter(h=>h);for(let h of d){let g=h.startsWith("/")?`${h}/${s}`:`${e.state.cwd}/${h}/${s}`;try{if((await e.fs.stat(g)).isDirectory){s=g,n=!0;break}}catch{}}}}let c=(s.startsWith("/")?s:`${e.state.cwd}/${s}`).split("/").filter(f=>f&&f!=="."),u="";for(let f of c)if(f==="..")u=u.split("/").slice(0,-1).join("/")||"/";else{u=u?`${u}/${f}`:`/${f}`;try{if(!(await e.fs.stat(u)).isDirectory)return P(`bash: cd: ${s}: Not a directory
7
7
  `)}catch{return P(`bash: cd: ${s}: No such file or directory
8
8
  `)}}let l=u||"/";if(r)try{l=await e.fs.realpath(l)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=l,v(e.state.env,"PWD",e.state.cwd),v(e.state.env,"OLDPWD",e.state.previousDir),n?U(`${l}
9
- `):ge()}function ps(e,t){return e.fs.resolvePath(e.state.cwd,t)}var vi=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function Pt(e){return vi.includes(e)}async function Ct(e,t,s){let n=ps(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 wi=["-nt","-ot","-ef"];function kt(e){return wi.includes(e)}async function Nt(e,t,s,n){let r=ps(e,s),i=ps(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 bi=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function Ot(e){return bi.has(e)}function xt(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 rt(e){return e==="="||e==="=="||e==="!="}function Tt(e,t,s,n=!1,r=!1,i=!1){if(n){let a=Ze(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 Ei=new Set(["-z","-n"]);function Dt(e){return Ei.has(e)}function It(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Rt(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,(c,u)=>O(e.state.env,u)),e.state.env.has(`${n}_${a}`)}let o;try{let a=new H,c=Q(a,r);o=await q(e,c.expression)}catch{if(/^-?\d+$/.test(r))o=Number.parseInt(r,10);else{let a=O(e.state.env,r);o=a?Number.parseInt(a,10):0}}if(o<0){let a=ne(e,n),c=e.state.currentLine;if(a.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${c}: ${n}: bad array subscript
9
+ `):ge()}function ps(e,t){return e.fs.resolvePath(e.state.cwd,t)}var wi=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function Pt(e){return wi.includes(e)}async function Ct(e,t,s){let n=ps(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 bi=["-nt","-ot","-ef"];function kt(e){return bi.includes(e)}async function Nt(e,t,s,n){let r=ps(e,s),i=ps(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 Ei=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function Ot(e){return Ei.has(e)}function xt(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 rt(e){return e==="="||e==="=="||e==="!="}function Tt(e,t,s,n=!1,r=!1,i=!1){if(n){let a=Ze(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 Si=new Set(["-z","-n"]);function Dt(e){return Si.has(e)}function It(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Rt(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,(c,u)=>O(e.state.env,u)),e.state.env.has(`${n}_${a}`)}let o;try{let a=new H,c=Q(a,r);o=await q(e,c.expression)}catch{if(/^-?\d+$/.test(r))o=Number.parseInt(r,10);else{let a=O(e.state.env,r);o=a?Number.parseInt(a,10):0}}if(o<0){let a=ne(e,n),c=e.state.currentLine;if(a.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${c}: ${n}: bad array subscript
10
10
  `,!1;if(o=Math.max(...a)+1+o,o<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${c}: ${n}: bad array subscript
11
- `,!1}return e.state.env.has(`${n}_${o}`)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?Ie(e,t).length>0:ne(e,t).length>0}async function Le(e,t){switch(t.type){case"CondBinary":{let s=await F(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 F(e,t.right);r=En(i)}else r=await $n(e,t.right);else rt(t.operator)&&!n?r=await An(e,t.right):r=await F(e,t.right);if(rt(t.operator)){let i=e.state.shoptOptions.nocasematch;return Tt(t.operator,s,r,!n,i,!0)}if(Ot(t.operator))return xt(t.operator,await zn(e,s),await zn(e,r));if(kt(t.operator))return Nt(e,t.operator,s,r);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=_i(r),c=st(o,i?"i":"").match(s);if(_e(e,"BASH_REMATCH"),c)for(let u=0;u<c.length;u++)v(e.state.env,`BASH_REMATCH_${u}`,c[u]||"");return c!==null}catch{throw new Error("syntax error in regular expression")}case"<":return s<r;case">":return s>r;default:return!1}}case"CondUnary":{let s=await F(e,t.operand);return Pt(t.operator)?Ct(e,t.operator,s):Dt(t.operator)?It(t.operator,s):t.operator==="-v"?await Rt(e,s):t.operator==="-o"?ys(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await F(e,t.operand.expression.word)})`!=="":!await Le(e,t.operand);case"CondAnd":return await Le(e,t.left)?await Le(e,t.right):!1;case"CondOr":return await Le(e,t.left)?!0:await Le(e,t.right);case"CondGroup":return await Le(e,t.expression);case"CondWord":return await F(e,t.word)!=="";default:return!1}}async function it(e,t){if(t.length===0)return T(p,p,1);if(t.length===1)return X(!!t[0]);if(t.length===2){let n=t[0],r=t[1];return n==="("?P(`test: '(' without matching ')'
11
+ `,!1}return e.state.env.has(`${n}_${o}`)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?Ie(e,t).length>0:ne(e,t).length>0}async function Le(e,t){switch(t.type){case"CondBinary":{let s=await F(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 F(e,t.right);r=Sn(i)}else r=await An(e,t.right);else rt(t.operator)&&!n?r=await _n(e,t.right):r=await F(e,t.right);if(rt(t.operator)){let i=e.state.shoptOptions.nocasematch;return Tt(t.operator,s,r,!n,i,!0)}if(Ot(t.operator))return xt(t.operator,await Bn(e,s),await Bn(e,r));if(kt(t.operator))return Nt(e,t.operator,s,r);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=Pi(r),c=st(o,i?"i":"").match(s);if(_e(e,"BASH_REMATCH"),c)for(let u=0;u<c.length;u++)v(e.state.env,`BASH_REMATCH_${u}`,c[u]||"");return c!==null}catch{throw new Error("syntax error in regular expression")}case"<":return s<r;case">":return s>r;default:return!1}}case"CondUnary":{let s=await F(e,t.operand);return Pt(t.operator)?Ct(e,t.operator,s):Dt(t.operator)?It(t.operator,s):t.operator==="-v"?await Rt(e,s):t.operator==="-o"?ys(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await F(e,t.operand.expression.word)})`!=="":!await Le(e,t.operand);case"CondAnd":return await Le(e,t.left)?await Le(e,t.right):!1;case"CondOr":return await Le(e,t.left)?!0:await Le(e,t.right);case"CondGroup":return await Le(e,t.expression);case"CondWord":return await F(e,t.word)!=="";default:return!1}}async function it(e,t){if(t.length===0)return T(p,p,1);if(t.length===1)return X(!!t[0]);if(t.length===2){let n=t[0],r=t[1];return n==="("?P(`test: '(' without matching ')'
12
12
  `,2):Pt(n)?X(await Ct(e,n,r)):Dt(n)?X(It(n,r)):n==="!"?X(!r):n==="-v"?X(await Rt(e,r)):n==="-o"?X(ys(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"?P(`test: ${n}: unary operator expected
13
- `,2):T(p,p,1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(rt(r))return X(Tt(r,n,i));if(Ot(r)){let o=Lt(n),a=Lt(i);return!o.valid||!a.valid?T(p,p,2):X(xt(r,o.value,a.value))}if(kt(r))return X(await Nt(e,r,n,i));switch(r){case"-a":return X(n!==""&&i!=="");case"-o":return X(n!==""||i!=="");case">":return X(n>i);case"<":return X(n<i)}if(n==="!"){let o=await it(e,[r,i]);return T(p,o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(n==="("&&i===")")return X(r!=="")}if(t.length===4){if(t[0]==="!"){let n=await it(e,t.slice(1));return T(p,n.stderr,n.exitCode===0?1:n.exitCode===1?0:n.exitCode)}if(t[0]==="("&&t[3]===")")return it(e,[t[1],t[2]])}let s=await jn(e,t,0);return s.pos<t.length?P(`test: too many arguments
14
- `,2):X(s.value)}async function jn(e,t,s){return Si(e,t,s)}async function Si(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 ms(e,t,s);for(;t[r]==="-a";){let i=await ms(e,t,r+1);n=n&&i.value,r=i.pos}return{value:n,pos:r}}async function ms(e,t,s){if(t[s]==="!"){let{value:n,pos:r}=await ms(e,t,s+1);return{value:!n,pos:r}}return $i(e,t,s)}async function $i(e,t,s){let n=t[s];if(n==="("){let{value:i,pos:o}=await jn(e,t,s+1);return{value:i,pos:t[o]===")"?o+1:o}}let r=t[s+1];if(rt(r)){let i=n,o=t[s+2]??"";return{value:Tt(r,i,o),pos:s+3}}if(Ot(r)){let i=Lt(n),o=Lt(t[s+2]??"0");return!i.valid||!o.valid?{value:!1,pos:s+3}:{value:xt(r,i.value,o.value),pos:s+3}}if(kt(r)){let i=n,o=t[s+2]??"";return{value:await Nt(e,r,i,o),pos:s+3}}if(Pt(n)){let i=t[s+1]??"";return{value:await Ct(e,n,i),pos:s+2}}if(Dt(n)){let i=t[s+1]??"";return{value:It(n,i),pos:s+2}}if(n==="-v"){let i=t[s+1]??"";return{value:await Rt(e,i),pos:s+2}}if(n==="-o"){let i=t[s+1]??"";return{value:ys(e,i),pos:s+2}}return{value:n!==void 0&&n!=="",pos:s+1}}function Ze(e,t,s=!1,n=!1){let r=`^${Hn(t,n)}$`;return st(r,s?"is":"s").test(e)}function Hn(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=Un(e,n+1);if(i!==-1){let o=e.slice(n+2,i),a=Gn(o),c=a.map(l=>Hn(l,t)),u=c.length>0?c.join("|"):"(?:)";if(r==="@")s+=`(?:${u})`;else if(r==="*")s+=`(?:${u})*`;else if(r==="+")s+=`(?:${u})+`;else if(r==="?")s+=`(?:${u})?`;else if(r==="!")if(i<e.length-1){let f=a.map(h=>qn(h,t));if(f.every(h=>h!==null)&&f.every(h=>h===f[0])&&f[0]!==null){let h=f[0];if(h===0)s+="(?:.+)";else{let g=[];h>0&&g.push(`.{0,${h-1}}`),g.push(`.{${h+1},}`),g.push(`(?!(?:${u})).{${h}}`),s+=`(?:${g.join("|")})`}}else s+=`(?:(?!(?:${u})).)*?`}else s+=`(?!(?:${u})$).*`;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 Un(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 Gn(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 qn(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=Un(e,n+1);if(i!==-1){if(r==="@"){let o=e.slice(n+2,i),c=Gn(o).map(u=>qn(u,t));if(c.every(u=>u!==null)&&c.every(u=>u===c[0])){s+=c[0],n=i+1;continue}return null}return null}}if(r==="*")return null;if(r==="?"){s+=1,n++;continue}if(r==="["){let i=e.indexOf("]",n+1);if(i!==-1){s+=1,n=i+1;continue}s+=1,n++;continue}if(r==="\\"){s+=1,n+=2;continue}s+=1,n++}return s}function ys(e,t){let n=new Map([["errexit",()=>e.state.options.errexit===!0],["nounset",()=>e.state.options.nounset===!0],["pipefail",()=>e.state.options.pipefail===!0],["xtrace",()=>e.state.options.xtrace===!0],["e",()=>e.state.options.errexit===!0],["u",()=>e.state.options.nounset===!0],["x",()=>e.state.options.xtrace===!0]]).get(t);return n?n():!1}async function zn(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 Bn(t);try{let s=new H,n=Q(s,t);return await q(e,n.expression)}catch{return Bn(t)}}function Ai(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 Bn(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=Ai(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 Lt(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 _i(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=Pi(e,s);t+=n.converted,s=n.endIndex}else t+=e[s],s++;return t}function Pi(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 c=e[s];if(c==="]"){a=!0,s++;break}if(c==="["&&s+1<e.length&&e[s+1]===":"){let u=e.indexOf(":]",s+2);if(u!==-1){let l=e.slice(s+2,u);o+=Ci(l),s=u+2;continue}}if(c==="["&&s+1<e.length){let u=e[s+1];if(u==="."||u==="="){let l=`${u}]`,f=e.indexOf(l,s+2);if(f!==-1){let d=e.slice(s+2,f);o+=d,s=f+2;continue}}}if(c==="\\"&&s+1<e.length){o+=c+e[s+1],s+=2;continue}o+=c,s++}return a?(r&&(n+="\\]"),i&&(n+="\\["),n+=o,n+="]",{converted:n,endIndex:s}):{converted:"\\[",endIndex:t+1}}function Ci(e){return new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]).get(e)??""}function ke(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===`
15
- `)&&!n&&!r){o&&(t.push(s),s="",o=!1);continue}s+=a,o=!0}return o&&t.push(s),t}function Mt(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 Zn(e){let t=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(t)return{name:t[1],isArray:!0,arrayElements:ke(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 ki(e,t){try{let s=new H,n=Q(s,t);return await q(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}async function Yn(e,t,s={}){let{name:n,isArray:r,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:c=!1,checkReadonly:u=!0}=s;if(u){let l=te(e,n);if(l)return l}if(r&&i){for(let l=0;l<i.length;l++)v(e.state.env,`${n}_${l}`,i[l]);v(e.state.env,`${n}__length`,String(i.length))}else if(a!==void 0&&o!==void 0){let l=await ki(e,a);v(e.state.env,`${n}_${l}`,o);let f=parseInt(O(e.state.env,`${n}__length`,"0"),10);l>=f&&v(e.state.env,`${n}__length`,String(l+1))}else o!==void 0&&v(e.state.env,n,o);return c&&fe(e,n),null}function Me(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function Ye(e,t){return e.state.localVarDepth?.get(t)}function Ft(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 Wt(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function Xn(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 gs=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Qn(e){return gs.has(e)}var vs=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Ke=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 Ve(e,t,s,n){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory
13
+ `,2):T(p,p,1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(rt(r))return X(Tt(r,n,i));if(Ot(r)){let o=Lt(n),a=Lt(i);return!o.valid||!a.valid?T(p,p,2):X(xt(r,o.value,a.value))}if(kt(r))return X(await Nt(e,r,n,i));switch(r){case"-a":return X(n!==""&&i!=="");case"-o":return X(n!==""||i!=="");case">":return X(n>i);case"<":return X(n<i)}if(n==="!"){let o=await it(e,[r,i]);return T(p,o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(n==="("&&i===")")return X(r!=="")}if(t.length===4){if(t[0]==="!"){let n=await it(e,t.slice(1));return T(p,n.stderr,n.exitCode===0?1:n.exitCode===1?0:n.exitCode)}if(t[0]==="("&&t[3]===")")return it(e,[t[1],t[2]])}let s=await Hn(e,t,0);return s.pos<t.length?P(`test: too many arguments
14
+ `,2):X(s.value)}async function Hn(e,t,s){return $i(e,t,s)}async function $i(e,t,s){let{value:n,pos:r}=await zn(e,t,s);for(;t[r]==="-o";){let i=await zn(e,t,r+1);n=n||i.value,r=i.pos}return{value:n,pos:r}}async function zn(e,t,s){let{value:n,pos:r}=await ms(e,t,s);for(;t[r]==="-a";){let i=await ms(e,t,r+1);n=n&&i.value,r=i.pos}return{value:n,pos:r}}async function ms(e,t,s){if(t[s]==="!"){let{value:n,pos:r}=await ms(e,t,s+1);return{value:!n,pos:r}}return Ai(e,t,s)}async function Ai(e,t,s){let n=t[s];if(n==="("){let{value:i,pos:o}=await Hn(e,t,s+1);return{value:i,pos:t[o]===")"?o+1:o}}let r=t[s+1];if(rt(r)){let i=n,o=t[s+2]??"";return{value:Tt(r,i,o),pos:s+3}}if(Ot(r)){let i=Lt(n),o=Lt(t[s+2]??"0");return!i.valid||!o.valid?{value:!1,pos:s+3}:{value:xt(r,i.value,o.value),pos:s+3}}if(kt(r)){let i=n,o=t[s+2]??"";return{value:await Nt(e,r,i,o),pos:s+3}}if(Pt(n)){let i=t[s+1]??"";return{value:await Ct(e,n,i),pos:s+2}}if(Dt(n)){let i=t[s+1]??"";return{value:It(n,i),pos:s+2}}if(n==="-v"){let i=t[s+1]??"";return{value:await Rt(e,i),pos:s+2}}if(n==="-o"){let i=t[s+1]??"";return{value:ys(e,i),pos:s+2}}return{value:n!==void 0&&n!=="",pos:s+1}}function Ze(e,t,s=!1,n=!1){let r=`^${Un(t,n)}$`;return st(r,s?"is":"s").test(e)}function Un(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=Gn(e,n+1);if(i!==-1){let o=e.slice(n+2,i),a=qn(o),c=a.map(l=>Un(l,t)),u=c.length>0?c.join("|"):"(?:)";if(r==="@")s+=`(?:${u})`;else if(r==="*")s+=`(?:${u})*`;else if(r==="+")s+=`(?:${u})+`;else if(r==="?")s+=`(?:${u})?`;else if(r==="!")if(i<e.length-1){let f=a.map(h=>Zn(h,t));if(f.every(h=>h!==null)&&f.every(h=>h===f[0])&&f[0]!==null){let h=f[0];if(h===0)s+="(?:.+)";else{let g=[];h>0&&g.push(`.{0,${h-1}}`),g.push(`.{${h+1},}`),g.push(`(?!(?:${u})).{${h}}`),s+=`(?:${g.join("|")})`}}else s+=`(?:(?!(?:${u})).)*?`}else s+=`(?!(?:${u})$).*`;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 Gn(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 qn(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 Zn(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=Gn(e,n+1);if(i!==-1){if(r==="@"){let o=e.slice(n+2,i),c=qn(o).map(u=>Zn(u,t));if(c.every(u=>u!==null)&&c.every(u=>u===c[0])){s+=c[0],n=i+1;continue}return null}return null}}if(r==="*")return null;if(r==="?"){s+=1,n++;continue}if(r==="["){let i=e.indexOf("]",n+1);if(i!==-1){s+=1,n=i+1;continue}s+=1,n++;continue}if(r==="\\"){s+=1,n+=2;continue}s+=1,n++}return s}function ys(e,t){let n=new Map([["errexit",()=>e.state.options.errexit===!0],["nounset",()=>e.state.options.nounset===!0],["pipefail",()=>e.state.options.pipefail===!0],["xtrace",()=>e.state.options.xtrace===!0],["e",()=>e.state.options.errexit===!0],["u",()=>e.state.options.nounset===!0],["x",()=>e.state.options.xtrace===!0]]).get(t);return n?n():!1}async function 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 jn(t);try{let s=new H,n=Q(s,t);return await q(e,n.expression)}catch{return jn(t)}}function _i(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 jn(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=_i(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 Lt(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 Pi(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=Ci(e,s);t+=n.converted,s=n.endIndex}else t+=e[s],s++;return t}function Ci(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 c=e[s];if(c==="]"){a=!0,s++;break}if(c==="["&&s+1<e.length&&e[s+1]===":"){let u=e.indexOf(":]",s+2);if(u!==-1){let l=e.slice(s+2,u);o+=ki(l),s=u+2;continue}}if(c==="["&&s+1<e.length){let u=e[s+1];if(u==="."||u==="="){let l=`${u}]`,f=e.indexOf(l,s+2);if(f!==-1){let d=e.slice(s+2,f);o+=d,s=f+2;continue}}}if(c==="\\"&&s+1<e.length){o+=c+e[s+1],s+=2;continue}o+=c,s++}return a?(r&&(n+="\\]"),i&&(n+="\\["),n+=o,n+="]",{converted:n,endIndex:s}):{converted:"\\[",endIndex:t+1}}function ki(e){return new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]).get(e)??""}function ke(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===`
15
+ `)&&!n&&!r){o&&(t.push(s),s="",o=!1);continue}s+=a,o=!0}return o&&t.push(s),t}function Mt(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 Yn(e){let t=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(t)return{name:t[1],isArray:!0,arrayElements:ke(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 Ni(e,t){try{let s=new H,n=Q(s,t);return await q(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}async function Kn(e,t,s={}){let{name:n,isArray:r,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:c=!1,checkReadonly:u=!0}=s;if(u){let l=te(e,n);if(l)return l}if(r&&i){for(let l=0;l<i.length;l++)v(e.state.env,`${n}_${l}`,i[l]);v(e.state.env,`${n}__length`,String(i.length))}else if(a!==void 0&&o!==void 0){let l=await Ni(e,a);v(e.state.env,`${n}_${l}`,o);let f=parseInt(O(e.state.env,`${n}__length`,"0"),10);l>=f&&v(e.state.env,`${n}__length`,String(l+1))}else o!==void 0&&v(e.state.env,n,o);return c&&fe(e,n),null}function Me(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function Ye(e,t){return e.state.localVarDepth?.get(t)}function Ft(e,t){e.state.localVarDepth?.delete(t)}function Xn(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 Wt(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function Qn(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 gs=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Jn(e){return gs.has(e)}var vs=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Ke=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 Ve(e,t,s,n){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory
16
16
  `;if(n.checkNoclobber&&e.state.options.noclobber&&!n.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file
17
- `}catch{}return null}function Ni(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),o=r+n+1,a=t.slice(o),c=a.indexOf(":");if(c===-1)return null;let u=Number.parseInt(a.slice(0,c),10);if(Number.isNaN(u)||u<0)return null;let l=a.slice(c+1);return{path:i,position:u,content:l}}async function Jn(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(is(e,r.target))return{targets:s,error:`bash: $@: ambiguous redirect
18
- `};s.set(n,await F(e,r.target))}else{let o=await $t(e,r.target);if("error"in o)return{targets:s,error:o.error};s.set(n,o.target)}}return{targets:s}}function Oi(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd;return e.state.nextFd++,t}async function Vt(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 F(e,s.target)==="-"){if(e.state.env.has(s.fdVariable)){let i=Number.parseInt(O(e.state.env,s.fdVariable),10);Number.isNaN(i)||e.state.fileDescriptors.delete(i)}continue}let n=Oi(e);if(v(e.state.env,s.fdVariable,String(n)),s.target.type==="Word"){let r=await F(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,p),e.state.fileDescriptors.set(n,`__file__:${i}`)}else if(s.operator==="<<<")e.state.fileDescriptors.set(n,`${r}
17
+ `}catch{}return null}function Oi(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),c=a.indexOf(":");if(c===-1)return null;let u=Number.parseInt(a.slice(0,c),10);if(Number.isNaN(u)||u<0)return null;let l=a.slice(c+1);return{path:i,position:u,content:l}}async function er(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(is(e,r.target))return{targets:s,error:`bash: $@: ambiguous redirect
18
+ `};s.set(n,await F(e,r.target))}else{let o=await $t(e,r.target);if("error"in o)return{targets:s,error:o.error};s.set(n,o.target)}}return{targets:s}}function xi(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd;return e.state.nextFd++,t}async function Vt(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 F(e,s.target)==="-"){if(e.state.env.has(s.fdVariable)){let i=Number.parseInt(O(e.state.env,s.fdVariable),10);Number.isNaN(i)||e.state.fileDescriptors.delete(i)}continue}let n=xi(e);if(v(e.state.env,s.fdVariable,String(n)),s.target.type==="Word"){let r=await F(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,p),e.state.fileDescriptors.set(n,`__file__:${i}`)}else if(s.operator==="<<<")e.state.fileDescriptors.set(n,`${r}
19
19
  `);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,r),o=await e.fs.readFile(i);e.state.fileDescriptors.set(n,o)}catch{return T(p,E(`bash: ${r}: No such file or directory
20
20
  `),1)}}}return null}async function Ne(e,t){for(let s of t){if(s.target.type==="HereDoc")continue;let n=s.operator===">&";if(s.operator!==">"&&s.operator!==">|"&&s.operator!=="&>"&&!n)continue;let r;if(n){if(r=await F(e,s.target),r==="-"||!Number.isNaN(Number.parseInt(r,10))||s.fd!=null)continue}else{let a=await $t(e,s.target);if("error"in a)return T(p,E(a.error),1);r=a.target}let i=e.fs.resolvePath(e.state.cwd,r),o=s.operator===">|";if(i.includes("\0"))return T(p,E(`bash: ${r}: No such file or directory
21
21
  `),1);try{let a=await e.fs.stat(i);if(a.isDirectory)return T(p,E(`bash: ${r}: Is a directory
@@ -28,15 +28,15 @@ import{A as rs,C as bn,D as En,E as fe,F as We,G as te,H as $e,I as St,J as Sn,K
28
28
  `)),o=1;break}if(f==="/dev/null")i=p;else{let m=e.fs.resolvePath(e.state.cwd,f),w=await Ve(e,m,f,{checkNoclobber:!0,isClobber:g});if(w){i=N(i,E(w)),o=1;break}await e.fs.writeFile(m,i),i=p}}break}case">>":{let h=l.fd??1;if(h===1){if(f==="/dev/stdout")break;if(f==="/dev/stderr"){i=N(i,r),r=p;break}if(f==="/dev/full"){i=N(i,E(`bash: echo: write error: No space left on device
29
29
  `)),o=1,r=p;break}let g=e.fs.resolvePath(e.state.cwd,f),m=await Ve(e,g,f,{});if(m){i=N(i,E(m)),o=1,r=p;break}await e.fs.appendFile(g,r),r=p}else if(h===2){if(f==="/dev/stderr")break;if(f==="/dev/stdout"){r=N(r,i),i=p;break}if(f==="/dev/full"){i=N(i,E(`bash: echo: write error: No space left on device
30
30
  `)),o=1;break}let g=e.fs.resolvePath(e.state.cwd,f),m=await Ve(e,g,f,{});if(m){i=N(i,E(m)),o=1;break}await e.fs.appendFile(g,i),i=p}break}case">&":case"<&":{let h=l.fd??1;if(f==="-")break;if(f.endsWith("-")){let g=f.slice(0,-1),m=Number.parseInt(g,10);if(!Number.isNaN(m)){let w=e.state.fileDescriptors?.get(m);w!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,w),m>=3&&e.state.fileDescriptors?.delete(m)):m===1||m===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,`__dupout__:${m}`)):m===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,`__dupin__:${m}`)):m>=3&&(i=N(i,E(`bash: ${m}: Bad file descriptor
31
- `)),o=1)}break}if(f==="2"||f==="&2")h===1&&(i=N(i,r),r=p);else if(f==="1"||f==="&1")h===2?(r=N(r,i),i=p):(r=N(r,i),i=p);else{let g=Number.parseInt(f,10);if(Number.isNaN(g)){if(l.operator===">&"){let m=e.fs.resolvePath(e.state.cwd,f),w=await Ve(e,m,f,{checkNoclobber:!0});if(w){i=E(w),o=1,r=p;break}if(l.fd==null){let $=N(r,i);await e.fs.writeFile(m,$),r=p,i=p}else h===1?(await e.fs.writeFile(m,r),r=p):h===2&&(await e.fs.writeFile(m,i),i=p)}}else{let m=e.state.fileDescriptors?.get(g);if(m?.startsWith("__file__:")){let w=m.slice(9);h===1?(await e.fs.appendFile(w,r),r=p):h===2&&(await e.fs.appendFile(w,i),i=p)}else if(m?.startsWith("__rw__:")){let w=Ni(m);w&&(h===1?(await e.fs.appendFile(w.path,r),r=p):h===2&&(await e.fs.appendFile(w.path,i),i=p))}else if(m?.startsWith("__dupout__:")){let w=Number.parseInt(m.slice(11),10);if(w!==1)if(w===2)h===1&&(i=N(i,r),r=p);else{let $=e.state.fileDescriptors?.get(w);if($?.startsWith("__file__:")){let _=$.slice(9);h===1?(await e.fs.appendFile(_,r),r=p):h===2&&(await e.fs.appendFile(_,i),i=p)}}}else m?.startsWith("__dupin__:")?(i=N(i,E(`bash: ${g}: Bad file descriptor
31
+ `)),o=1)}break}if(f==="2"||f==="&2")h===1&&(i=N(i,r),r=p);else if(f==="1"||f==="&1")h===2?(r=N(r,i),i=p):(r=N(r,i),i=p);else{let g=Number.parseInt(f,10);if(Number.isNaN(g)){if(l.operator===">&"){let m=e.fs.resolvePath(e.state.cwd,f),w=await Ve(e,m,f,{checkNoclobber:!0});if(w){i=E(w),o=1,r=p;break}if(l.fd==null){let $=N(r,i);await e.fs.writeFile(m,$),r=p,i=p}else h===1?(await e.fs.writeFile(m,r),r=p):h===2&&(await e.fs.writeFile(m,i),i=p)}}else{let m=e.state.fileDescriptors?.get(g);if(m?.startsWith("__file__:")){let w=m.slice(9);h===1?(await e.fs.appendFile(w,r),r=p):h===2&&(await e.fs.appendFile(w,i),i=p)}else if(m?.startsWith("__rw__:")){let w=Oi(m);w&&(h===1?(await e.fs.appendFile(w.path,r),r=p):h===2&&(await e.fs.appendFile(w.path,i),i=p))}else if(m?.startsWith("__dupout__:")){let w=Number.parseInt(m.slice(11),10);if(w!==1)if(w===2)h===1&&(i=N(i,r),r=p);else{let $=e.state.fileDescriptors?.get(w);if($?.startsWith("__file__:")){let _=$.slice(9);h===1?(await e.fs.appendFile(_,r),r=p):h===2&&(await e.fs.appendFile(_,i),i=p)}}}else m?.startsWith("__dupin__:")?(i=N(i,E(`bash: ${g}: Bad file descriptor
32
32
  `)),o=1,r=p):g>=3&&(i=N(i,E(`bash: ${g}: Bad file descriptor
33
33
  `)),o=1,r=p)}}break}case"&>":{if(f==="/dev/full"){i=E(`bash: echo: write error: No space left on device
34
34
  `),o=1,r=p;break}let h=e.fs.resolvePath(e.state.cwd,f),g=await Ve(e,h,f,{checkNoclobber:!0});if(g){i=E(g),o=1,r=p;break}let m=N(r,i);await e.fs.writeFile(h,m),r=p,i=p;break}case"&>>":{if(f==="/dev/full"){i=E(`bash: echo: write error: No space left on device
35
- `),o=1,r=p;break}let h=e.fs.resolvePath(e.state.cwd,f),g=await Ve(e,h,f,{});if(g){i=E(g),o=1,r=p;break}let m=N(r,i);await e.fs.appendFile(h,m),r=p,i=p;break}}}}let a=e.state.fileDescriptors?.get(1);if(a){if(a==="__dupout__:2")i=N(i,r),r=p;else if(a.startsWith("__file__:")){let u=a.slice(9);await e.fs.appendFile(u,r),r=p}else if(a.startsWith("__file_append__:")){let u=a.slice(16);await e.fs.appendFile(u,r),r=p}}let c=e.state.fileDescriptors?.get(2);if(c){if(c==="__dupout__:1")r=N(r,i),i=p;else if(c.startsWith("__file__:")){let u=c.slice(9);await e.fs.appendFile(u,i),i=p}else if(c.startsWith("__file_append__:")){let u=c.slice(16);await e.fs.appendFile(u,i),i=p}}return T(r,i,o)}function er(e,t){if(e.state.options.posix&&gs.has(t.name)){let n=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
36
- `;throw new G(2,p,E(n))}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),V}async function xi(e,t){let s=p;for(let n of t)if((n.operator==="<<"||n.operator==="<<-")&&n.target.type==="HereDoc"){let r=n.target,i=await F(e,r.content);r.stripTabs&&(i=i.split(`
35
+ `),o=1,r=p;break}let h=e.fs.resolvePath(e.state.cwd,f),g=await Ve(e,h,f,{});if(g){i=E(g),o=1,r=p;break}let m=N(r,i);await e.fs.appendFile(h,m),r=p,i=p;break}}}}let a=e.state.fileDescriptors?.get(1);if(a){if(a==="__dupout__:2")i=N(i,r),r=p;else if(a.startsWith("__file__:")){let u=a.slice(9);await e.fs.appendFile(u,r),r=p}else if(a.startsWith("__file_append__:")){let u=a.slice(16);await e.fs.appendFile(u,r),r=p}}let c=e.state.fileDescriptors?.get(2);if(c){if(c==="__dupout__:1")r=N(r,i),i=p;else if(c.startsWith("__file__:")){let u=c.slice(9);await e.fs.appendFile(u,i),i=p}else if(c.startsWith("__file_append__:")){let u=c.slice(16);await e.fs.appendFile(u,i),i=p}}return T(r,i,o)}function tr(e,t){if(e.state.options.posix&&gs.has(t.name)){let n=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
36
+ `;throw new G(2,p,E(n))}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),V}async function Ti(e,t){let s=p;for(let n of t)if((n.operator==="<<"||n.operator==="<<-")&&n.target.type==="HereDoc"){let r=n.target,i=await F(e,r.content);r.stripTabs&&(i=i.split(`
37
37
  `).map(a=>a.replace(/^\t+/,"")).join(`
38
38
  `)),(n.fd??0)===0&&(s=E(i))}else if(n.operator==="<<<"&&n.target.type==="Word")s=E(`${await F(e,n.target)}
39
- `);else if(n.operator==="<"&&n.target.type==="Word"){let r=await F(e,n.target),i=e.fs.resolvePath(e.state.cwd,r);try{s=E(await e.fs.readFile(i))}catch{}}return s}async function zt(e,t,s,n=p,r){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,xe(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(r??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i=new Map;for(let u=0;u<s.length;u++)i.set(String(u+1),O(e.state.env,String(u+1))),v(e.state.env,String(u+1),s[u]);i.set("@",O(e.state.env,"@")),i.set("#",O(e.state.env,"#")),v(e.state.env,"@",s.join(" ")),v(e.state.env,"#",String(s.length));let o=()=>{let u=e.state.localScopes.length-1,l=e.state.localScopes.pop();if(l)for(let[f,d]of l)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);if(Xn(e,u),e.state.fullyUnsetLocals)for(let[f,d]of e.state.fullyUnsetLocals.entries())d===u&&e.state.fullyUnsetLocals.delete(f);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let f=e.state.localExportedVars.pop();if(f)for(let d of f)e.state.exportedVars?.delete(d)}for(let[f,d]of i)d===void 0?e.state.env.delete(f):v(e.state.env,f,d);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},{targets:a,error:c}=await Jn(e,t.redirections);if(c)return o(),T(p,E(c),1);try{let u=await xi(e,t.redirections),l=n.length>0?n:u,f=await e.executeCommand(t.body,l);return o(),Z(e,f,t.redirections,a)}catch(u){if(o(),u instanceof ce){let l=T(u.stdout,u.stderr,u.exitCode);return Z(e,l,t.redirections,a)}throw u}}var sr=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],bs=[".",":","[","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"],Ti=["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"],Di=bs;async function Es(e,t){let s=[],n=null,r="",i="",o=null,a=!1,c=!1,u=!1,l=null,f=null,d=null,h=[],g=["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 b=t[y];if(b==="-v")s.push("variable");else if(b==="-e")s.push("export");else if(b==="-f")s.push("file");else if(b==="-d")s.push("directory");else if(b==="-k")s.push("keyword");else if(b==="-A"){if(y++,y>=t.length)return P(`compgen: -A: option requires an argument
39
+ `);else if(n.operator==="<"&&n.target.type==="Word"){let r=await F(e,n.target),i=e.fs.resolvePath(e.state.cwd,r);try{s=E(await e.fs.readFile(i))}catch{}}return s}async function zt(e,t,s,n=p,r){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,xe(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(r??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i=new Map;for(let u=0;u<s.length;u++)i.set(String(u+1),O(e.state.env,String(u+1))),v(e.state.env,String(u+1),s[u]);i.set("@",O(e.state.env,"@")),i.set("#",O(e.state.env,"#")),v(e.state.env,"@",s.join(" ")),v(e.state.env,"#",String(s.length));let o=()=>{let u=e.state.localScopes.length-1,l=e.state.localScopes.pop();if(l)for(let[f,d]of l)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);if(Qn(e,u),e.state.fullyUnsetLocals)for(let[f,d]of e.state.fullyUnsetLocals.entries())d===u&&e.state.fullyUnsetLocals.delete(f);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let f=e.state.localExportedVars.pop();if(f)for(let d of f)e.state.exportedVars?.delete(d)}for(let[f,d]of i)d===void 0?e.state.env.delete(f):v(e.state.env,f,d);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},{targets:a,error:c}=await er(e,t.redirections);if(c)return o(),T(p,E(c),1);try{let u=await Ti(e,t.redirections),l=n.length>0?n:u,f=await e.executeCommand(t.body,l);return o(),Z(e,f,t.redirections,a)}catch(u){if(o(),u instanceof ce){let l=T(u.stdout,u.stderr,u.exitCode);return Z(e,l,t.redirections,a)}throw u}}var nr=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],bs=[".",":","[","alias","bg","bind","break","builtin","caller","cd","command","compgen","complete","compopt","continue","declare","dirs","disown","echo","enable","eval","exec","exit","export","false","fc","fg","getopts","hash","help","history","jobs","kill","let","local","logout","mapfile","popd","printf","pushd","pwd","read","readarray","readonly","return","set","shift","shopt","source","suspend","test","times","trap","true","type","typeset","ulimit","umask","unalias","unset","wait"],Di=["autocd","assoc_expand_once","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","dotglob","execfail","expand_aliases","extdebug","extglob","extquote","failglob","force_fignore","globasciiranges","globstar","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lastpipe","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","nocaseglob","nocasematch","nullglob","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath","xpg_echo"],Ii=bs;async function Es(e,t){let s=[],n=null,r="",i="",o=null,a=!1,c=!1,u=!1,l=null,f=null,d=null,h=[],g=["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 b=t[y];if(b==="-v")s.push("variable");else if(b==="-e")s.push("export");else if(b==="-f")s.push("file");else if(b==="-d")s.push("directory");else if(b==="-k")s.push("keyword");else if(b==="-A"){if(y++,y>=t.length)return P(`compgen: -A: option requires an argument
40
40
  `,2);let C=t[y];if(!g.includes(C))return P(`compgen: ${C}: invalid action name
41
41
  `,2);s.push(C)}else if(b==="-W"){if(y++,y>=t.length)return P(`compgen: -W: option requires an argument
42
42
  `,2);n=t[y]}else if(b==="-P"){if(y++,y>=t.length)return P(`compgen: -P: option requires an argument
@@ -47,15 +47,15 @@ import{A as rs,C as bn,D as En,E as fe,F as We,G as te,H as $e,I as St,J as Sn,K
47
47
  `,2);f=t[y]}else if(b==="-C"){if(y++,y>=t.length)return P(`compgen: -C: option requires an argument
48
48
  `,2);d=t[y]}else if(b==="-X"){if(y++,y>=t.length)return P(`compgen: -X: option requires an argument
49
49
  `,2);l=t[y]}else if(b==="-G"){if(y++,y>=t.length)return P(`compgen: -G: option requires an argument
50
- `,2)}else if(b==="--"){h.push(...t.slice(y+1));break}else b.startsWith("-")||h.push(b)}o=h[0]??null;let m=[];if(c){let y=await ws(e,o);m.push(...y)}if(u){let y=await tr(e,o);m.push(...y)}for(let y of s)if(y==="variable"){let b=Ii(e,o);m.push(...b)}else if(y==="export"){let b=Ri(e,o);m.push(...b)}else if(y==="function"){let b=Li(e,o);m.push(...b)}else if(y==="builtin"){let b=Mi(o);m.push(...b)}else if(y==="keyword"){let b=Fi(o);m.push(...b)}else if(y==="alias"){let b=Wi(e,o);m.push(...b)}else if(y==="shopt"){let b=Vi(o);m.push(...b)}else if(y==="helptopic"){let b=zi(o);m.push(...b)}else if(y==="directory"){let b=await ws(e,o);m.push(...b)}else if(y==="file"){let b=await tr(e,o);m.push(...b)}else if(y==="user"){let b=Bi(o);m.push(...b)}else if(y==="command"){let b=await ji(e,o);m.push(...b)}if(n!==null)try{let y=await Hi(e,n),b=Ui(e,y);for(let C of b)(o===null||C.startsWith(o))&&m.push(C)}catch{return T(p,p,1)}if(a){let y=await ws(e,o);for(let b of y)m.includes(b)||m.push(b)}let w="";if(f!==null){let y=e.state.functions.get(f);if(y){let b=new Map;b.set("COMP_WORDS__length",O(e.state.env,"COMP_WORDS__length")),v(e.state.env,"COMP_WORDS__length","0"),b.set("COMP_CWORD",O(e.state.env,"COMP_CWORD")),v(e.state.env,"COMP_CWORD","-1"),b.set("COMP_LINE",O(e.state.env,"COMP_LINE")),v(e.state.env,"COMP_LINE",""),b.set("COMP_POINT",O(e.state.env,"COMP_POINT")),v(e.state.env,"COMP_POINT","0");let C=new Map;for(let L of e.state.env.keys())(L==="COMPREPLY"||L.startsWith("COMPREPLY_")||L==="COMPREPLY__length")&&(C.set(L,O(e.state.env,L)),e.state.env.delete(L));let A=["compgen",h[0]??"",""];try{let L=await zt(e,y,A,p);if(L.exitCode!==0)return Xe(e,b),Xe(e,C),T(p,L.stderr,1);w=z(L.stdout);let I=Gi(e);m.push(...I)}catch{return Xe(e,b),Xe(e,C),T(p,p,1)}Xe(e,b),Xe(e,C)}}if(d!==null)try{let y=Ae(d),b=await e.executeScript(y);if(b.exitCode!==0)return T(p,b.stderr,b.exitCode);if(b.stdout.length>0){let C=z(b.stdout).split(`
50
+ `,2)}else if(b==="--"){h.push(...t.slice(y+1));break}else b.startsWith("-")||h.push(b)}o=h[0]??null;let m=[];if(c){let y=await ws(e,o);m.push(...y)}if(u){let y=await sr(e,o);m.push(...y)}for(let y of s)if(y==="variable"){let b=Ri(e,o);m.push(...b)}else if(y==="export"){let b=Li(e,o);m.push(...b)}else if(y==="function"){let b=Mi(e,o);m.push(...b)}else if(y==="builtin"){let b=Fi(o);m.push(...b)}else if(y==="keyword"){let b=Wi(o);m.push(...b)}else if(y==="alias"){let b=Vi(e,o);m.push(...b)}else if(y==="shopt"){let b=zi(o);m.push(...b)}else if(y==="helptopic"){let b=Bi(o);m.push(...b)}else if(y==="directory"){let b=await ws(e,o);m.push(...b)}else if(y==="file"){let b=await sr(e,o);m.push(...b)}else if(y==="user"){let b=ji(o);m.push(...b)}else if(y==="command"){let b=await Hi(e,o);m.push(...b)}if(n!==null)try{let y=await Ui(e,n),b=Gi(e,y);for(let C of b)(o===null||C.startsWith(o))&&m.push(C)}catch{return T(p,p,1)}if(a){let y=await ws(e,o);for(let b of y)m.includes(b)||m.push(b)}let w="";if(f!==null){let y=e.state.functions.get(f);if(y){let b=new Map;b.set("COMP_WORDS__length",O(e.state.env,"COMP_WORDS__length")),v(e.state.env,"COMP_WORDS__length","0"),b.set("COMP_CWORD",O(e.state.env,"COMP_CWORD")),v(e.state.env,"COMP_CWORD","-1"),b.set("COMP_LINE",O(e.state.env,"COMP_LINE")),v(e.state.env,"COMP_LINE",""),b.set("COMP_POINT",O(e.state.env,"COMP_POINT")),v(e.state.env,"COMP_POINT","0");let C=new Map;for(let L of e.state.env.keys())(L==="COMPREPLY"||L.startsWith("COMPREPLY_")||L==="COMPREPLY__length")&&(C.set(L,O(e.state.env,L)),e.state.env.delete(L));let A=["compgen",h[0]??"",""];try{let L=await zt(e,y,A,p);if(L.exitCode!==0)return Xe(e,b),Xe(e,C),T(p,L.stderr,1);w=z(L.stdout);let I=qi(e);m.push(...I)}catch{return Xe(e,b),Xe(e,C),T(p,p,1)}Xe(e,b),Xe(e,C)}}if(d!==null)try{let y=Ae(d),b=await e.executeScript(y);if(b.exitCode!==0)return T(p,b.stderr,b.exitCode);if(b.stdout.length>0){let C=z(b.stdout).split(`
51
51
  `);for(let A of C)A.length>0&&m.push(A)}}catch(y){if(y.name==="ParseException")return P(`compgen: -C: ${y.message}
52
52
  `,2);throw y}let $=m;if(l!==null){let y=l.startsWith("!"),b=y?l.slice(1):l;$=m.filter(C=>{let A=Ze(C,b,!1,!0);return y?A:!A})}if($.length===0&&o!==null)return T(E(w),p,1);let _=$.map(y=>`${r}${y}${i}`).join(`
53
53
  `),k=w+(_?`${_}
54
- `:"");return U(k)}function Ii(e,t){let s=new Set;for(let r of e.state.env.keys()){if(r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length"))continue;let i=r.split("_")[0];/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)?s.add(r):i&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)&&e.state.env.has(`${i}__length`)&&s.add(i)}let n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function Ri(e,t){let s=e.state.exportedVars??new Set,n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n=n.filter(r=>r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length")?!1:e.state.env.has(r)),n.sort()}function Li(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(n=>n.startsWith(t))),s.sort()}function Mi(e){let t=[...bs];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Fi(e){let t=[...sr];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Wi(e,t){let s=[];for(let r of e.state.env.keys())if(r.startsWith("BASH_ALIAS_")){let i=r.slice(11);s.push(i)}let n=s;return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function Vi(e){let t=[...Ti];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function zi(e){let t=[...Di];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function ws(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let o=t.lastIndexOf("/");if(o!==-1){let a=t.slice(0,o)||"/";r=t.slice(o+1),a.startsWith("/")?n=a:n=`${e.state.cwd}/${a}`}}let i=await e.fs.readdir(n);for(let o of i){let a=`${n}/${o}`;try{if((await e.fs.stat(a)).isDirectory&&(!r||o.startsWith(r)))if(t?.includes("/")){let u=t.lastIndexOf("/"),l=t.slice(0,u+1);s.push(l+o)}else s.push(o)}catch{}}}catch{}return s.sort()}async function tr(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let o=t.lastIndexOf("/");if(o!==-1){let a=t.slice(0,o)||"/";r=t.slice(o+1),a.startsWith("/")?n=a:n=`${e.state.cwd}/${a}`}}let i=await e.fs.readdir(n);for(let o of i)if(!r||o.startsWith(r))if(t?.includes("/")){let a=t.lastIndexOf("/"),c=t.slice(0,a+1);s.push(c+o)}else s.push(o)}catch{}return s.sort()}function Bi(e){return["root","nobody"]}async function ji(e,t){let s=new Set;for(let i of bs)s.add(i);for(let i of e.state.functions.keys())s.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&s.add(i.slice(11));for(let i of sr)s.add(i);let n=O(e.state.env,"PATH","/usr/bin:/bin");for(let i of n.split(":"))if(i)try{let o=await e.fs.readdir(i);for(let a of o)s.add(a)}catch{}let r=Array.from(s);return t!==null&&(r=r.filter(i=>i.startsWith(t))),r.sort()}async function Hi(e,t){let n=new H().parseWordFromString(t,!1,!1);return await F(e,n)}function Ui(e,t){let s=O(e.state.env,"IFS",`
55
- `);if(s.length===0)return[t];let n=new Set(s.split("")),r=[],i="",o=0;for(;o<t.length;){let a=t[o];if(a==="\\"&&o+1<t.length){let c=t[o+1];i+=c,o+=2}else n.has(a)?(i.length>0&&(r.push(i),i=""),o++):(i+=a,o++)}return i.length>0&&r.push(i),r}function Xe(e,t){for(let[s,n]of t)n===void 0?e.state.env.delete(s):v(e.state.env,s,n)}function Gi(e){let t=[];if(e.state.env.get("COMPREPLY__length")!==void 0){let r=Se(e,"COMPREPLY");for(let[,i]of r)t.push(i)}else e.state.env.has("COMPREPLY")&&t.push(O(e.state.env,"COMPREPLY"));return t}var qi=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function $s(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=!1,i,o,a,c=[],u=[],l=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-p")s=!0;else if(d==="-r")n=!0;else if(d==="-D")r=!0;else if(d==="-W"){if(f++,f>=t.length)return P(`complete: -W: option requires an argument
54
+ `:"");return U(k)}function Ri(e,t){let s=new Set;for(let r of e.state.env.keys()){if(r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length"))continue;let i=r.split("_")[0];/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)?s.add(r):i&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)&&e.state.env.has(`${i}__length`)&&s.add(i)}let n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function Li(e,t){let s=e.state.exportedVars??new Set,n=Array.from(s);return t!==null&&(n=n.filter(r=>r.startsWith(t))),n=n.filter(r=>r.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(r)||r.endsWith("__length")?!1:e.state.env.has(r)),n.sort()}function Mi(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(n=>n.startsWith(t))),s.sort()}function Fi(e){let t=[...bs];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Wi(e){let t=[...nr];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Vi(e,t){let s=[];for(let r of e.state.env.keys())if(r.startsWith("BASH_ALIAS_")){let i=r.slice(11);s.push(i)}let n=s;return t!==null&&(n=n.filter(r=>r.startsWith(t))),n.sort()}function zi(e){let t=[...Di];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Bi(e){let t=[...Ii];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function ws(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let o=t.lastIndexOf("/");if(o!==-1){let a=t.slice(0,o)||"/";r=t.slice(o+1),a.startsWith("/")?n=a:n=`${e.state.cwd}/${a}`}}let i=await e.fs.readdir(n);for(let o of i){let a=`${n}/${o}`;try{if((await e.fs.stat(a)).isDirectory&&(!r||o.startsWith(r)))if(t?.includes("/")){let u=t.lastIndexOf("/"),l=t.slice(0,u+1);s.push(l+o)}else s.push(o)}catch{}}}catch{}return s.sort()}async function sr(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let o=t.lastIndexOf("/");if(o!==-1){let a=t.slice(0,o)||"/";r=t.slice(o+1),a.startsWith("/")?n=a:n=`${e.state.cwd}/${a}`}}let i=await e.fs.readdir(n);for(let o of i)if(!r||o.startsWith(r))if(t?.includes("/")){let a=t.lastIndexOf("/"),c=t.slice(0,a+1);s.push(c+o)}else s.push(o)}catch{}return s.sort()}function ji(e){return["root","nobody"]}async function Hi(e,t){let s=new Set;for(let i of bs)s.add(i);for(let i of e.state.functions.keys())s.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&s.add(i.slice(11));for(let i of nr)s.add(i);let n=O(e.state.env,"PATH","/usr/bin:/bin");for(let i of n.split(":"))if(i)try{let o=await e.fs.readdir(i);for(let a of o)s.add(a)}catch{}let r=Array.from(s);return t!==null&&(r=r.filter(i=>i.startsWith(t))),r.sort()}async function Ui(e,t){let n=new H().parseWordFromString(t,!1,!1);return await F(e,n)}function Gi(e,t){let s=O(e.state.env,"IFS",`
55
+ `);if(s.length===0)return[t];let n=new Set(s.split("")),r=[],i="",o=0;for(;o<t.length;){let a=t[o];if(a==="\\"&&o+1<t.length){let c=t[o+1];i+=c,o+=2}else n.has(a)?(i.length>0&&(r.push(i),i=""),o++):(i+=a,o++)}return i.length>0&&r.push(i),r}function Xe(e,t){for(let[s,n]of t)n===void 0?e.state.env.delete(s):v(e.state.env,s,n)}function qi(e){let t=[];if(e.state.env.get("COMPREPLY__length")!==void 0){let r=Se(e,"COMPREPLY");for(let[,i]of r)t.push(i)}else e.state.env.has("COMPREPLY")&&t.push(O(e.state.env,"COMPREPLY"));return t}var Zi=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function $s(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=!1,i,o,a,c=[],u=[],l=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-p")s=!0;else if(d==="-r")n=!0;else if(d==="-D")r=!0;else if(d==="-W"){if(f++,f>=t.length)return P(`complete: -W: option requires an argument
56
56
  `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return P(`complete: -F: option requires an argument
57
57
  `,2);o=t[f]}else if(d==="-o"){if(f++,f>=t.length)return P(`complete: -o: option requires an argument
58
- `,2);let h=t[f];if(!qi.includes(h))return P(`complete: ${h}: invalid option name
58
+ `,2);let h=t[f];if(!Zi.includes(h))return P(`complete: ${h}: invalid option name
59
59
  `,2);c.push(h)}else if(d==="-A"){if(f++,f>=t.length)return P(`complete: -A: option requires an argument
60
60
  `,2);u.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return P(`complete: -C: option requires an argument
61
61
  `,2);a=t[f]}else if(d==="-G"){if(f++,f>=t.length)return P(`complete: -G: option requires an argument
@@ -69,31 +69,31 @@ import{A as rs,C as bn,D as En,E as fe,F as We,G as te,H as $e,I as St,J as Sn,K
69
69
  `:"")),E(`complete: ${i}: no completion specification
70
70
  `),1);continue}let a="complete";if(o.options)for(let c of o.options)a+=` -o ${c}`;if(o.actions)for(let c of o.actions)a+=` -A ${c}`;o.wordlist!==void 0&&(o.wordlist.includes(" ")||o.wordlist.includes("'")?a+=` -W '${o.wordlist}'`:a+=` -W ${o.wordlist}`),o.function!==void 0&&(a+=` -F ${o.function}`),o.isDefault&&(a+=" -D"),a+=` ${i}`,n.push(a)}return n.length===0?ge():U(`${n.join(`
71
71
  `)}
72
- `)}var nr=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function As(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=[],i=[],o=[];for(let a=0;a<t.length;a++){let c=t[a];if(c==="-D")s=!0;else if(c==="-E")n=!0;else if(c==="-o"){if(a++,a>=t.length)return P(`compopt: -o: option requires an argument
73
- `,2);let u=t[a];if(!nr.includes(u))return P(`compopt: ${u}: invalid option name
72
+ `)}var rr=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function As(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=[],i=[],o=[];for(let a=0;a<t.length;a++){let c=t[a];if(c==="-D")s=!0;else if(c==="-E")n=!0;else if(c==="-o"){if(a++,a>=t.length)return P(`compopt: -o: option requires an argument
73
+ `,2);let u=t[a];if(!rr.includes(u))return P(`compopt: ${u}: invalid option name
74
74
  `,2);r.push(u)}else if(c==="+o"){if(a++,a>=t.length)return P(`compopt: +o: option requires an argument
75
- `,2);let u=t[a];if(!nr.includes(u))return P(`compopt: ${u}: invalid option name
75
+ `,2);let u=t[a];if(!rr.includes(u))return P(`compopt: ${u}: invalid option name
76
76
  `,2);i.push(u)}else if(c==="--"){o.push(...t.slice(a+1));break}else!c.startsWith("-")&&!c.startsWith("+")&&o.push(c)}if(s){let a=e.state.completionSpecs.get("__default__")??{isDefault:!0},c=new Set(a.options??[]);for(let u of r)c.add(u);for(let u of i)c.delete(u);return a.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set("__default__",a),ge()}if(n){let a=e.state.completionSpecs.get("__empty__")??{},c=new Set(a.options??[]);for(let u of r)c.add(u);for(let u of i)c.delete(u);return a.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set("__empty__",a),ge()}if(o.length>0){for(let a of o){let c=e.state.completionSpecs.get(a)??{},u=new Set(c.options??[]);for(let l of r)u.add(l);for(let l of i)u.delete(l);c.options=u.size>0?Array.from(u):void 0,e.state.completionSpecs.set(a,c)}return ge()}return P(`compopt: not currently executing completion function
77
77
  `,1)}function _s(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Te;return V}if(t.length>1)throw new G(1,p,E(`bash: continue: too many arguments
78
78
  `));let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new G(1,p,E(`bash: continue: ${t[0]}: numeric argument required
79
- `));s=n}throw new ye(s)}function Y(e,t){let s=O(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 Ps(e){for(let t=0;t<e.length;t++){let s=e.charCodeAt(t);if(s<32||s===127)return!0}return!1}function Cs(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 Bt(e){return Ps(e)?Cs(e):/^[a-zA-Z0-9_/.:\-@%+,=]*$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function ze(e){return Ps(e)?Cs(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function ks(e){return Ps(e)?Cs(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function rr(e,t){let s="";return e.state.integerVars?.has(t)&&(s+="i"),e.state.lowercaseVars?.has(t)&&(s+="l"),ue(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 Ns(e){return e===""?"''":/[\s'\\]/.test(e)?`'${e.replace(/'/g,"'\\''")}'`:e}function ir(e,t){let s="",n="",r=!1;for(let i of t){let o=rr(e,i);if(e.state.associativeArrays?.has(i)){let u=Ie(e,i);if(u.length===0)s+=`declare -A ${i}=()
79
+ `));s=n}throw new ye(s)}function Y(e,t){let s=O(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 Ps(e){for(let t=0;t<e.length;t++){let s=e.charCodeAt(t);if(s<32||s===127)return!0}return!1}function Cs(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 Bt(e){return Ps(e)?Cs(e):/^[a-zA-Z0-9_/.:\-@%+,=]*$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function ze(e){return Ps(e)?Cs(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function ks(e){return Ps(e)?Cs(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function ir(e,t){let s="";return e.state.integerVars?.has(t)&&(s+="i"),e.state.lowercaseVars?.has(t)&&(s+="l"),ue(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 Ns(e){return e===""?"''":/[\s'\\]/.test(e)?`'${e.replace(/'/g,"'\\''")}'`:e}function or(e,t){let s="",n="",r=!1;for(let i of t){let o=ir(e,i);if(e.state.associativeArrays?.has(i)){let u=Ie(e,i);if(u.length===0)s+=`declare -A ${i}=()
80
80
  `;else{let l=u.map(f=>{let d=O(e.state.env,`${i}_${f}`,""),h=Ns(d);return`['${f}']=${h}`});s+=`declare -A ${i}=(${l.join(" ")})
81
81
  `}continue}let c=ne(e,i);if(c.length>0){let u=c.map(l=>{let f=O(e.state.env,`${i}_${l}`,"");return`[${l}]=${ze(f)}`});s+=`declare -a ${i}=(${u.join(" ")})
82
82
  `;continue}if(e.state.env.has(`${i}__length`)){s+=`declare -a ${i}=()
83
83
  `;continue}if(e.state.env.has(i)){let u=O(e.state.env,i);s+=`declare ${o} ${i}=${ks(u)}
84
84
  `}else{let u=e.state.declaredVars?.has(i),l=e.state.localVarDepth?.has(i);u||l?s+=`declare ${o} ${i}
85
85
  `:(n+=`bash: declare: ${i}: not found
86
- `,r=!0)}}return T(E(s),E(n),r?1:0)}function or(e,t){let{filterExport:s,filterReadonly:n,filterNameref:r,filterIndexedArray:i,filterAssocArray:o}=t,a=s||n||r||i||o,c="",u=new Set;for(let f of e.state.env.keys()){if(f.startsWith("BASH_"))continue;if(f.endsWith("__length")){let h=f.slice(0,-8);u.add(h);continue}let d=f.lastIndexOf("_");if(d>0){let h=f.slice(0,d),g=f.slice(d+1);if(/^\d+$/.test(g)||e.state.associativeArrays?.has(h)){u.add(h);continue}}u.add(f)}if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())u.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)u.add(f);let l=Array.from(u).sort();for(let f of l){let d=rr(e,f),h=e.state.associativeArrays?.has(f),g=ne(e,f),m=!h&&(g.length>0||e.state.env.has(`${f}__length`));if(!(a&&(o&&!h||i&&!m||s&&!e.state.exportedVars?.has(f)||n&&!e.state.readonlyVars?.has(f)||r&&!ue(e,f)))){if(h){let w=Ie(e,f);if(w.length===0)c+=`declare -A ${f}=()
86
+ `,r=!0)}}return T(E(s),E(n),r?1:0)}function ar(e,t){let{filterExport:s,filterReadonly:n,filterNameref:r,filterIndexedArray:i,filterAssocArray:o}=t,a=s||n||r||i||o,c="",u=new Set;for(let f of e.state.env.keys()){if(f.startsWith("BASH_"))continue;if(f.endsWith("__length")){let h=f.slice(0,-8);u.add(h);continue}let d=f.lastIndexOf("_");if(d>0){let h=f.slice(0,d),g=f.slice(d+1);if(/^\d+$/.test(g)||e.state.associativeArrays?.has(h)){u.add(h);continue}}u.add(f)}if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())u.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)u.add(f);let l=Array.from(u).sort();for(let f of l){let d=ir(e,f),h=e.state.associativeArrays?.has(f),g=ne(e,f),m=!h&&(g.length>0||e.state.env.has(`${f}__length`));if(!(a&&(o&&!h||i&&!m||s&&!e.state.exportedVars?.has(f)||n&&!e.state.readonlyVars?.has(f)||r&&!ue(e,f)))){if(h){let w=Ie(e,f);if(w.length===0)c+=`declare -A ${f}=()
87
87
  `;else{let $=w.map(_=>{let k=O(e.state.env,`${f}_${_}`,""),y=Ns(k);return`['${_}']=${y}`});c+=`declare -A ${f}=(${$.join(" ")})
88
88
  `}continue}if(g.length>0){let w=g.map($=>{let _=O(e.state.env,`${f}_${$}`,"");return`[${$}]=${ze(_)}`});c+=`declare -a ${f}=(${w.join(" ")})
89
89
  `;continue}if(e.state.env.has(`${f}__length`)){c+=`declare -a ${f}=()
90
90
  `;continue}if(e.state.env.has(f)){let w=O(e.state.env,f);c+=`declare ${d} ${f}=${ks(w)}
91
- `}}}return U(c)}function ar(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let n of s){let r=Ie(e,n);if(r.length===0)t+=`declare -A ${n}=()
91
+ `}}}return U(c)}function lr(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let n of s){let r=Ie(e,n);if(r.length===0)t+=`declare -A ${n}=()
92
92
  `;else{let i=r.map(o=>{let a=O(e.state.env,`${n}_${o}`,""),c=Ns(a);return`['${o}']=${c}`});t+=`declare -A ${n}=(${i.join(" ")})
93
- `}}return U(t)}function lr(e){let t="",s=new Set;for(let r of e.state.env.keys()){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=ne(e,r);if(i.length===0)t+=`declare -a ${r}=()
93
+ `}}return U(t)}function cr(e){let t="",s=new Set;for(let r of e.state.env.keys()){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=ne(e,r);if(i.length===0)t+=`declare -a ${r}=()
94
94
  `;else{let o=i.map(a=>{let c=O(e.state.env,`${r}_${a}`,"");return`[${a}]=${ze(c)}`});t+=`declare -a ${r}=(${o.join(" ")})
95
- `}}return U(t)}function cr(e){let t="",s=new Set;for(let r of e.state.env.keys()){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)e.state.associativeArrays?.has(r)||ne(e,r).length>0||e.state.env.has(`${r}__length`)||e.state.env.has(r)&&(t+=`${r}=${Bt(O(e.state.env,r))}
96
- `);return U(t)}function Os(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function ot(e,t){return e.state.integerVars?.has(t)??!1}function xs(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Zi(e,t){return e.state.lowercaseVars?.has(t)??!1}function Ts(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Yi(e,t){return e.state.uppercaseVars?.has(t)??!1}function Qe(e,t,s){return Zi(e,t)?s.toLowerCase():Yi(e,t)?s.toUpperCase():s}async function ur(e,t){try{let s=new H,n=Q(s,t),r=await q(e,n.expression);return String(r)}catch{return"0"}}function Ki(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 Ds(e,t){let s=!1,n=!1,r=!1,i=!1,o=!1,a=!1,c=!1,u=!1,l=!1,f=!1,d=!1,h=!1,g=!1,m=!1,w=!1,$=[];for(let I=0;I<t.length;I++){let W=t[I];if(W==="-a")s=!0;else if(W==="-A")n=!0;else if(W==="-r")r=!0;else if(W==="-x")i=!0;else if(W==="-p")o=!0;else if(W==="-n")a=!0;else if(W==="+n")c=!0;else if(W==="+a")u=!0;else if(W==="+x")l=!0;else if(W==="--"){$.push(...t.slice(I+1));break}else if(W.startsWith("+")){for(let B of W.slice(1))if(B==="n")c=!0;else if(B==="a")u=!0;else if(B==="x")l=!0;else if(B!=="r"){if(B!=="i"){if(!(B==="f"||B==="F"))return T(p,E(`bash: typeset: +${B}: invalid option
95
+ `}}return U(t)}function ur(e){let t="",s=new Set;for(let r of e.state.env.keys()){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)e.state.associativeArrays?.has(r)||ne(e,r).length>0||e.state.env.has(`${r}__length`)||e.state.env.has(r)&&(t+=`${r}=${Bt(O(e.state.env,r))}
96
+ `);return U(t)}function Os(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function ot(e,t){return e.state.integerVars?.has(t)??!1}function xs(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Yi(e,t){return e.state.lowercaseVars?.has(t)??!1}function Ts(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Ki(e,t){return e.state.uppercaseVars?.has(t)??!1}function Qe(e,t,s){return Yi(e,t)?s.toLowerCase():Ki(e,t)?s.toUpperCase():s}async function fr(e,t){try{let s=new H,n=Q(s,t),r=await q(e,n.expression);return String(r)}catch{return"0"}}function Xi(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 Ds(e,t){let s=!1,n=!1,r=!1,i=!1,o=!1,a=!1,c=!1,u=!1,l=!1,f=!1,d=!1,h=!1,g=!1,m=!1,w=!1,$=[];for(let I=0;I<t.length;I++){let W=t[I];if(W==="-a")s=!0;else if(W==="-A")n=!0;else if(W==="-r")r=!0;else if(W==="-x")i=!0;else if(W==="-p")o=!0;else if(W==="-n")a=!0;else if(W==="+n")c=!0;else if(W==="+a")u=!0;else if(W==="+x")l=!0;else if(W==="--"){$.push(...t.slice(I+1));break}else if(W.startsWith("+")){for(let B of W.slice(1))if(B==="n")c=!0;else if(B==="a")u=!0;else if(B==="x")l=!0;else if(B!=="r"){if(B!=="i"){if(!(B==="f"||B==="F"))return T(p,E(`bash: typeset: +${B}: invalid option
97
97
  `),2)}}}else if(W==="-i")f=!0;else if(W==="-l")d=!0;else if(W==="-u")h=!0;else if(W==="-f")g=!0;else if(W==="-F")m=!0;else if(W==="-g")w=!0;else if(W.startsWith("-"))for(let B of W.slice(1))if(B==="a")s=!0;else if(B==="A")n=!0;else if(B==="r")r=!0;else if(B==="x")i=!0;else if(B==="p")o=!0;else if(B==="n")a=!0;else if(B==="i")f=!0;else if(B==="l")d=!0;else if(B==="u")h=!0;else if(B==="f")g=!0;else if(B==="F")m=!0;else if(B==="g")w=!0;else return T(p,E(`bash: typeset: -${B}: invalid option
98
98
  `),2);else $.push(W)}let k=e.state.localScopes.length>0&&!w,y=I=>{if(!k)return;let W=e.state.localScopes[e.state.localScopes.length-1];W.has(I)||W.set(I,e.state.env.get(I))},b=I=>{if(!k)return;let W=e.state.localScopes[e.state.localScopes.length-1];W.has(I)||W.set(I,e.state.env.get(I));let B=`${I}_`;for(let x of e.state.env.keys())x.startsWith(B)&&!x.includes("__")&&(W.has(x)||W.set(x,e.state.env.get(x)));let D=`${I}__length`;e.state.env.has(D)&&!W.has(D)&&W.set(D,e.state.env.get(D))},C=I=>{k&&Me(e,I)};if(m){if($.length===0){let B=Array.from(e.state.functions.keys()).sort(),D="";for(let x of B)D+=`declare -f ${x}
99
99
  `;return U(D)}let I=!0,W="";for(let B of $)e.state.functions.has(B)?W+=`${B}
@@ -101,18 +101,18 @@ import{A as rs,C as bn,D as En,E as fe,F as We,G as te,H as $e,I as St,J as Sn,K
101
101
  {
102
102
  # function body
103
103
  }
104
- `;return U(W)}let I=!0;for(let W of $)e.state.functions.has(W)||(I=!1);return T(p,p,I?0:1)}if(o&&$.length>0)return ir(e,$);if(o&&$.length===0)return or(e,{filterExport:i,filterReadonly:r,filterNameref:a,filterIndexedArray:s,filterAssocArray:n});if($.length===0&&n&&!o)return ar(e);if($.length===0&&s&&!o)return lr(e);if($.length===0&&!o)return cr(e);let A="",L=0;for(let I of $){let W=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(W&&!u){let S=W[1],R=W[2];if(n&&ne(e,S).length>0){A+=`bash: declare: ${S}: cannot convert indexed to associative array
104
+ `;return U(W)}let I=!0;for(let W of $)e.state.functions.has(W)||(I=!1);return T(p,p,I?0:1)}if(o&&$.length>0)return or(e,$);if(o&&$.length===0)return ar(e,{filterExport:i,filterReadonly:r,filterNameref:a,filterIndexedArray:s,filterAssocArray:n});if($.length===0&&n&&!o)return lr(e);if($.length===0&&s&&!o)return cr(e);if($.length===0&&!o)return ur(e);let A="",L=0;for(let I of $){let W=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(W&&!u){let S=W[1],R=W[2];if(n&&ne(e,S).length>0){A+=`bash: declare: ${S}: cannot convert indexed to associative array
105
105
  `,L=1;continue}if((s||!n&&!s)&&e.state.associativeArrays?.has(S)){A+=`bash: declare: ${S}: cannot convert associative to indexed array
106
- `,L=1;continue}if(b(S),n&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(S)),_e(e,S),e.state.env.delete(S),e.state.env.delete(`${S}__length`),n&&R.includes("[")){let M=Mt(R);for(let[ee,j]of M){let K=Y(e,j);v(e.state.env,`${S}_${ee}`,K)}}else if(n){let M=ke(R);for(let ee=0;ee<M.length;ee+=2){let j=M[ee],K=ee+1<M.length?Y(e,M[ee+1]):"";v(e.state.env,`${S}_${j}`,K)}}else{let M=ke(R);if(M.some(j=>/^\[[^\]]+\]=/.test(j))){let j=0;for(let K of M){let ie=K.match(/^\[([^\]]+)\]=(.*)$/);if(ie){let pe=ie[1],Be=ie[2],si=Y(e,Be),et;if(/^-?\d+$/.test(pe))et=Number.parseInt(pe,10);else try{let ni=new H,ri=Q(ni,pe);et=await q(e,ri.expression)}catch{et=0}v(e.state.env,`${S}_${et}`,si),j=et+1}else{let pe=Y(e,K);v(e.state.env,`${S}_${j}`,pe),j++}}}else{for(let j=0;j<M.length;j++)v(e.state.env,`${S}_${j}`,M[j]);v(e.state.env,`${S}__length`,String(M.length))}}C(S),r&&fe(e,S),i&&$e(e,S);continue}if(c){let S=I.includes("=")?I.slice(0,I.indexOf("=")):I;if(yn(e,S),!I.includes("="))continue}if(l){let S=I.includes("=")?I.slice(0,I.indexOf("=")):I;if(St(e,S),!I.includes("="))continue}let B=Ki(I);if(B){let{name:S,indexExpr:R,value:M}=B,ee=te(e,S);if(ee)return ee;b(S);let j;try{let ie=new H,pe=Q(ie,R);j=await q(e,pe.expression)}catch{let ie=parseInt(R,10);j=Number.isNaN(ie)?0:ie}v(e.state.env,`${S}_${j}`,M);let K=parseInt(O(e.state.env,`${S}__length`,"0"),10);j>=K&&v(e.state.env,`${S}__length`,String(j+1)),C(S),r&&fe(e,S),i&&$e(e,S);continue}let D=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(D&&!u){let S=D[1],R=D[2],M=te(e,S);if(M)return M;b(S);let ee=ke(R);if(e.state.associativeArrays?.has(S)){let j=Mt(R);for(let[K,ie]of j){let pe=Y(e,ie);v(e.state.env,`${S}_${K}`,pe)}}else{let j=ne(e,S),K=0,ie=e.state.env.get(S);j.length===0&&ie!==void 0?(e.state.env.set(`${S}_0`,ie),e.state.env.delete(S),K=1):j.length>0&&(K=Math.max(...j)+1);for(let Be=0;Be<ee.length;Be++)v(e.state.env,`${S}_${K+Be}`,Y(e,ee[Be]));let pe=K+ee.length;v(e.state.env,`${S}__length`,String(pe))}C(S),r&&fe(e,S),i&&$e(e,S);continue}let x=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(x){let S=x[1],R=Y(e,x[2]),M=te(e,S);if(M)return M;y(S),f&&Os(e,S),d&&xs(e,S),h&&Ts(e,S);let j=ne(e,S).length>0||e.state.associativeArrays?.has(S);if(ot(e,S)){let K=O(e.state.env,S,"0"),ie=parseInt(K,10)||0,pe=parseInt(await ur(e,R),10)||0;R=String(ie+pe),v(e.state.env,S,R)}else if(j){R=Qe(e,S,R);let K=`${S}_0`,ie=O(e.state.env,K);v(e.state.env,K,ie+R)}else{R=Qe(e,S,R);let K=O(e.state.env,S);v(e.state.env,S,K+R)}C(S),r&&fe(e,S),i&&$e(e,S),e.state.options.allexport&&!l&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(S));continue}if(I.includes("=")){let S=I.indexOf("="),R=I.slice(0,S),M=I.slice(S+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(R)){A+=`bash: typeset: \`${R}': not a valid identifier
106
+ `,L=1;continue}if(b(S),n&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(S)),_e(e,S),e.state.env.delete(S),e.state.env.delete(`${S}__length`),n&&R.includes("[")){let M=Mt(R);for(let[ee,j]of M){let K=Y(e,j);v(e.state.env,`${S}_${ee}`,K)}}else if(n){let M=ke(R);for(let ee=0;ee<M.length;ee+=2){let j=M[ee],K=ee+1<M.length?Y(e,M[ee+1]):"";v(e.state.env,`${S}_${j}`,K)}}else{let M=ke(R);if(M.some(j=>/^\[[^\]]+\]=/.test(j))){let j=0;for(let K of M){let ie=K.match(/^\[([^\]]+)\]=(.*)$/);if(ie){let pe=ie[1],Be=ie[2],ni=Y(e,Be),et;if(/^-?\d+$/.test(pe))et=Number.parseInt(pe,10);else try{let ri=new H,ii=Q(ri,pe);et=await q(e,ii.expression)}catch{et=0}v(e.state.env,`${S}_${et}`,ni),j=et+1}else{let pe=Y(e,K);v(e.state.env,`${S}_${j}`,pe),j++}}}else{for(let j=0;j<M.length;j++)v(e.state.env,`${S}_${j}`,M[j]);v(e.state.env,`${S}__length`,String(M.length))}}C(S),r&&fe(e,S),i&&$e(e,S);continue}if(c){let S=I.includes("=")?I.slice(0,I.indexOf("=")):I;if(gn(e,S),!I.includes("="))continue}if(l){let S=I.includes("=")?I.slice(0,I.indexOf("=")):I;if(St(e,S),!I.includes("="))continue}let B=Xi(I);if(B){let{name:S,indexExpr:R,value:M}=B,ee=te(e,S);if(ee)return ee;b(S);let j;try{let ie=new H,pe=Q(ie,R);j=await q(e,pe.expression)}catch{let ie=parseInt(R,10);j=Number.isNaN(ie)?0:ie}v(e.state.env,`${S}_${j}`,M);let K=parseInt(O(e.state.env,`${S}__length`,"0"),10);j>=K&&v(e.state.env,`${S}__length`,String(j+1)),C(S),r&&fe(e,S),i&&$e(e,S);continue}let D=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(D&&!u){let S=D[1],R=D[2],M=te(e,S);if(M)return M;b(S);let ee=ke(R);if(e.state.associativeArrays?.has(S)){let j=Mt(R);for(let[K,ie]of j){let pe=Y(e,ie);v(e.state.env,`${S}_${K}`,pe)}}else{let j=ne(e,S),K=0,ie=e.state.env.get(S);j.length===0&&ie!==void 0?(e.state.env.set(`${S}_0`,ie),e.state.env.delete(S),K=1):j.length>0&&(K=Math.max(...j)+1);for(let Be=0;Be<ee.length;Be++)v(e.state.env,`${S}_${K+Be}`,Y(e,ee[Be]));let pe=K+ee.length;v(e.state.env,`${S}__length`,String(pe))}C(S),r&&fe(e,S),i&&$e(e,S);continue}let x=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(x){let S=x[1],R=Y(e,x[2]),M=te(e,S);if(M)return M;y(S),f&&Os(e,S),d&&xs(e,S),h&&Ts(e,S);let j=ne(e,S).length>0||e.state.associativeArrays?.has(S);if(ot(e,S)){let K=O(e.state.env,S,"0"),ie=parseInt(K,10)||0,pe=parseInt(await fr(e,R),10)||0;R=String(ie+pe),v(e.state.env,S,R)}else if(j){R=Qe(e,S,R);let K=`${S}_0`,ie=O(e.state.env,K);v(e.state.env,K,ie+R)}else{R=Qe(e,S,R);let K=O(e.state.env,S);v(e.state.env,S,K+R)}C(S),r&&fe(e,S),i&&$e(e,S),e.state.options.allexport&&!l&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(S));continue}if(I.includes("=")){let S=I.indexOf("="),R=I.slice(0,S),M=I.slice(S+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(R)){A+=`bash: typeset: \`${R}': not a valid identifier
107
107
  `,L=1;continue}let ee=te(e,R);if(ee)return ee;if(y(R),a){if(M!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(M)){A+=`bash: declare: \`${M}': invalid variable name for name reference
108
- `,L=1;continue}v(e.state.env,R,M),Oe(e,R),M!==""&&ns(e,M)&&ss(e,R),C(R),r&&fe(e,R),i&&$e(e,R);continue}if(f&&Os(e,R),d&&xs(e,R),h&&Ts(e,R),ot(e,R)&&(M=await ur(e,M)),M=Qe(e,R,M),ue(e,R)){let j=Pe(e,R);j&&j!==R?v(e.state.env,j,M):v(e.state.env,R,M)}else v(e.state.env,R,M);C(R),r&&fe(e,R),i&&$e(e,R),e.state.options.allexport&&!l&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(R))}else{let S=I;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(S)){A+=`bash: typeset: \`${S}': not a valid identifier
109
- `,L=1;continue}if(s||n?b(S):y(S),a){Oe(e,S);let M=O(e.state.env,S);M!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(M)?gn(e,S):M&&ns(e,M)&&ss(e,S),C(S),r&&fe(e,S),i&&$e(e,S);continue}if(f&&Os(e,S),d&&xs(e,S),h&&Ts(e,S),n){if(ne(e,S).length>0){A+=`bash: declare: ${S}: cannot convert indexed to associative array
108
+ `,L=1;continue}v(e.state.env,R,M),Oe(e,R),M!==""&&ns(e,M)&&ss(e,R),C(R),r&&fe(e,R),i&&$e(e,R);continue}if(f&&Os(e,R),d&&xs(e,R),h&&Ts(e,R),ot(e,R)&&(M=await fr(e,M)),M=Qe(e,R,M),ue(e,R)){let j=Pe(e,R);j&&j!==R?v(e.state.env,j,M):v(e.state.env,R,M)}else v(e.state.env,R,M);C(R),r&&fe(e,R),i&&$e(e,R),e.state.options.allexport&&!l&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(R))}else{let S=I;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(S)){A+=`bash: typeset: \`${S}': not a valid identifier
109
+ `,L=1;continue}if(s||n?b(S):y(S),a){Oe(e,S);let M=O(e.state.env,S);M!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(M)?vn(e,S):M&&ns(e,M)&&ss(e,S),C(S),r&&fe(e,S),i&&$e(e,S);continue}if(f&&Os(e,S),d&&xs(e,S),h&&Ts(e,S),n){if(ne(e,S).length>0){A+=`bash: declare: ${S}: cannot convert indexed to associative array
110
110
  `,L=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(S)}let R=Array.from(e.state.env.keys()).some(M=>M.startsWith(`${S}_`)&&!M.startsWith(`${S}__length`));!e.state.env.has(S)&&!R&&(s||n?v(e.state.env,`${S}__length`,"0"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(S))),C(S),r&&fe(e,S),i&&$e(e,S)}}return T(p,E(A),L)}async function Is(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 c of a){let u=e.state.env.get(c);if(u!==void 0){let l=z(u??p).replace(/\\/g,"\\\\").replace(/"/g,'\\"');o+=`declare -r ${c}="${l}"
111
- `}}return U(o)}for(let o of i){let a=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(a){let f=a[1],d=a[2],h=te(e,f);if(h)return h;let g=ke(d);if(e.state.associativeArrays?.has(f)){let m=Mt(d);for(let[w,$]of m){let _=Y(e,$);v(e.state.env,`${f}_${w}`,_)}}else{let m=ne(e,f),w=0,$=e.state.env.get(f);m.length===0&&$!==void 0?(e.state.env.set(`${f}_0`,$),e.state.env.delete(f),w=1):m.length>0&&(w=Math.max(...m)+1);for(let k=0;k<g.length;k++)v(e.state.env,`${f}_${w+k}`,Y(e,g[k]));let _=w+g.length;v(e.state.env,`${f}__length`,String(_))}fe(e,f);continue}let c=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c){let f=c[1],d=Y(e,c[2]),h=te(e,f);if(h)return h;let g=O(e.state.env,f);v(e.state.env,f,g+d),fe(e,f);continue}let u=Zn(o);if(u.value===void 0&&!u.isArray){fe(e,u.name);continue}let l=await Yn(e,u,{makeReadonly:!0});if(l)return l}return V}function Rs(e){return e.state.directoryStack??=[],e.state.directoryStack}function at(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function Xi(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 Ls(e,t){let s=Rs(e),n;for(let a=0;a<t.length;a++){let c=t[a];if(c==="--"){if(a+1<t.length){if(n!==void 0)return P(`bash: pushd: too many arguments
111
+ `}}return U(o)}for(let o of i){let a=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(a){let f=a[1],d=a[2],h=te(e,f);if(h)return h;let g=ke(d);if(e.state.associativeArrays?.has(f)){let m=Mt(d);for(let[w,$]of m){let _=Y(e,$);v(e.state.env,`${f}_${w}`,_)}}else{let m=ne(e,f),w=0,$=e.state.env.get(f);m.length===0&&$!==void 0?(e.state.env.set(`${f}_0`,$),e.state.env.delete(f),w=1):m.length>0&&(w=Math.max(...m)+1);for(let k=0;k<g.length;k++)v(e.state.env,`${f}_${w+k}`,Y(e,g[k]));let _=w+g.length;v(e.state.env,`${f}__length`,String(_))}fe(e,f);continue}let c=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c){let f=c[1],d=Y(e,c[2]),h=te(e,f);if(h)return h;let g=O(e.state.env,f);v(e.state.env,f,g+d),fe(e,f);continue}let u=Yn(o);if(u.value===void 0&&!u.isArray){fe(e,u.name);continue}let l=await Kn(e,u,{makeReadonly:!0});if(l)return l}return V}function Rs(e){return e.state.directoryStack??=[],e.state.directoryStack}function at(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function Qi(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 Ls(e,t){let s=Rs(e),n;for(let a=0;a<t.length;a++){let c=t[a];if(c==="--"){if(a+1<t.length){if(n!==void 0)return P(`bash: pushd: too many arguments
112
112
  `,2);n=t[a+1],a++}}else{if(c.startsWith("-")&&c!=="-")return P(`bash: pushd: ${c}: invalid option
113
113
  `,2);if(n!==void 0)return P(`bash: pushd: too many arguments
114
114
  `,2);n=c}}if(n===void 0){if(s.length<2)return P(`bash: pushd: no other directory
115
- `,1);let a=s[0];s[0]=s[1],s[1]=a,n=s[0]}let r;if(n.startsWith("/"))r=n;else if(n===".."){let a=e.state.cwd.split("/").filter(c=>c);a.pop(),r=`/${a.join("/")}`}else n==="."?r=e.state.cwd:n.startsWith("~")?r=O(e.state.env,"HOME","/")+n.slice(1):r=`${e.state.cwd}/${n}`;r=Xi(r);try{if(!(await e.fs.stat(r)).isDirectory)return P(`bash: pushd: ${n}: Not a directory
115
+ `,1);let a=s[0];s[0]=s[1],s[1]=a,n=s[0]}let r;if(n.startsWith("/"))r=n;else if(n===".."){let a=e.state.cwd.split("/").filter(c=>c);a.pop(),r=`/${a.join("/")}`}else n==="."?r=e.state.cwd:n.startsWith("~")?r=O(e.state.env,"HOME","/")+n.slice(1):r=`${e.state.cwd}/${n}`;r=Qi(r);try{if(!(await e.fs.stat(r)).isDirectory)return P(`bash: pushd: ${n}: Not a directory
116
116
  `,1)}catch{return P(`bash: pushd: ${n}: No such file or directory
117
117
  `,1)}s.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=r,v(e.state.env,"PWD",r),v(e.state.env,"OLDPWD",e.state.previousDir);let i=O(e.state.env,"HOME",""),o=`${[r,...s].map(a=>at(a,i)).join(" ")}
118
118
  `;return U(o)}function Ms(e,t){let s=Rs(e);for(let o of t)if(o!=="--")return o.startsWith("-")&&o!=="-"?P(`bash: popd: ${o}: invalid option
@@ -152,7 +152,7 @@ eval: usage: eval [arg ...]
152
152
  `;for(let[,m]of e.state.hashTable)g+=` 1 ${m}
153
153
  `}return U(g)}let l=!1,f="",h=O(e.state.env,"PATH","/usr/bin:/bin").split(":");for(let g of c){if(g.includes("/")){f+=`bash: hash: ${g}: cannot use / in name
154
154
  `,l=!0;continue}let m=!1;for(let w of h){if(!w)continue;let $=`${w}/${g}`;if(await e.fs.exists($)){e.state.hashTable.set(g,$),m=!0;break}}m||(f+=`bash: hash: ${g}: not found
155
- `,l=!0)}return l?P(f,1):V}var fr=new Map([[":",[": [arguments]",`Null command.
155
+ `,l=!0)}return l?P(f,1):V}var dr=new Map([[":",[": [arguments]",`Null command.
156
156
  No effect; the command does nothing.
157
157
  Exit Status:
158
158
  Always succeeds.`]],[".",[". filename [arguments]",`Execute commands from a file in the current shell.
@@ -497,31 +497,31 @@ eval: usage: eval [arg ...]
497
497
  job specification, and reports its termination status.
498
498
  Exit Status:
499
499
  Returns the status of the last ID; fails if ID is invalid or an invalid
500
- option is given.`]]]),dr=[...fr.keys()].sort();function Bs(e,t){let s=!1,n=[],r=0;for(;r<t.length;){let c=t[r];if(c==="--"){for(r++;r<t.length;)n.push(t[r]),r++;break}if(c.startsWith("-")&&c.length>1){for(let u=1;u<c.length;u++){let l=c[u];if(l==="s")s=!0;else return P(`bash: help: -${l}: invalid option
501
- `,2)}r++}else n.push(c),r++}if(n.length===0)return Ji();let i="",o=!1,a="";for(let c of n){let u=Qi(c);if(u.length===0){a+=`bash: help: no help topics match \`${c}'. Try \`help help' or \`man -k ${c}' or \`info ${c}'.
502
- `,o=!0;continue}for(let l of u){let f=fr.get(l);if(!f)continue;let[d,h]=f;s?i+=`${l}: ${d}
500
+ option is given.`]]]),hr=[...dr.keys()].sort();function Bs(e,t){let s=!1,n=[],r=0;for(;r<t.length;){let c=t[r];if(c==="--"){for(r++;r<t.length;)n.push(t[r]),r++;break}if(c.startsWith("-")&&c.length>1){for(let u=1;u<c.length;u++){let l=c[u];if(l==="s")s=!0;else return P(`bash: help: -${l}: invalid option
501
+ `,2)}r++}else n.push(c),r++}if(n.length===0)return eo();let i="",o=!1,a="";for(let c of n){let u=Ji(c);if(u.length===0){a+=`bash: help: no help topics match \`${c}'. Try \`help help' or \`man -k ${c}' or \`info ${c}'.
502
+ `,o=!0;continue}for(let l of u){let f=dr.get(l);if(!f)continue;let[d,h]=f;s?i+=`${l}: ${d}
503
503
  `:i+=`${l}: ${d}
504
504
  ${h}
505
- `}}return{exitCode:o?1:0,stdout:E(i),stderr:E(a)}}function Qi(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),s=st(`^${t}$`);return dr.filter(n=>s.test(n))}function Ji(){let e=[];e.push("just-bash shell builtins"),e.push("These shell commands are defined internally. Type `help' to see this list."),e.push("Type `help name' to find out more about the function `name'."),e.push("");let t=36,s=dr.slice(),n=Math.ceil(s.length/2);for(let r=0;r<n;r++){let i=s[r]||"",o=s[r+n]||"",a=i.padEnd(t);e.push(o?`${a}${o}`:i)}return U(`${e.join(`
505
+ `}}return{exitCode:o?1:0,stdout:E(i),stderr:E(a)}}function Ji(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),s=st(`^${t}$`);return hr.filter(n=>s.test(n))}function eo(){let e=[];e.push("just-bash shell builtins"),e.push("These shell commands are defined internally. Type `help' to see this list."),e.push("Type `help name' to find out more about the function `name'."),e.push("");let t=36,s=hr.slice(),n=Math.ceil(s.length/2);for(let r=0;r<n;r++){let i=s[r]||"",o=s[r+n]||"",a=i.padEnd(t);e.push(o?`${a}${o}`:i)}return U(`${e.join(`
506
506
  `)}
507
- `)}function eo(e){let t=[],s="",n=0;for(let r of e){for(let i of r)i==="("?n++:i===")"&&n--;s?s+=` ${r}`:s=r,n===0&&(t.push(s),s="")}return s&&t.push(s),t}async function js(e,t){if(t.length===0)return P(`bash: let: expression expected
508
- `);let s=eo(t),n=0;for(let r of s)try{let o=Ae(`(( ${r} ))`).statements[0];if(o&&o.pipelines.length>0&&o.pipelines[0].commands.length>0){let a=o.pipelines[0].commands[0];a.type==="ArithmeticCommand"&&(n=await q(e,a.expression.expression))}}catch(i){return P(`bash: let: ${r}: ${i.message}
507
+ `)}function to(e){let t=[],s="",n=0;for(let r of e){for(let i of r)i==="("?n++:i===")"&&n--;s?s+=` ${r}`:s=r,n===0&&(t.push(s),s="")}return s&&t.push(s),t}async function js(e,t){if(t.length===0)return P(`bash: let: expression expected
508
+ `);let s=to(t),n=0;for(let r of s)try{let o=Ae(`(( ${r} ))`).statements[0];if(o&&o.pipelines.length>0&&o.pipelines[0].commands.length>0){let a=o.pipelines[0].commands[0];a.type==="ArithmeticCommand"&&(n=await q(e,a.expression.expression))}}catch(i){return P(`bash: let: ${r}: ${i.message}
509
509
  `)}return T(p,p,n===0?1:0)}async function Hs(e,t){if(e.state.localScopes.length===0)return P(`bash: local: can only be used in a function
510
510
  `);let s=e.state.localScopes[e.state.localScopes.length-1],n="",r=0,i=!1,o=!1,a=!1,c=[];for(let u of t)if(u==="-n")i=!0;else if(u==="-a")o=!0;else if(u==="-p")a=!0;else if(u.startsWith("-")&&!u.includes("="))for(let l of u.slice(1))l==="n"?i=!0:l==="a"?o=!0:l==="p"&&(a=!0);else c.push(u);if(c.length===0){let u="",l=Array.from(s.keys()).filter(f=>!f.includes("_")||!f.match(/_\d+$/)).filter(f=>!f.includes("__length")).sort();for(let f of l){let d=e.state.env.get(f);if(d!==void 0){let h=z(d);u+=`${f}=${h}
511
511
  `}}return T(E(u),p,0)}for(let u of c){let l,f,d=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){l=d[1];let $=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l)){n+=`bash: local: \`${u}': not a valid identifier
512
512
  `,r=1;continue}if(te(e,l,"bash"),!s.has(l)){s.set(l,e.state.env.get(l));let y=`${l}_`;for(let b of e.state.env.keys())b.startsWith(y)&&!b.includes("__")&&(s.has(b)||s.set(b,e.state.env.get(b)))}let _=`${l}_`;for(let y of e.state.env.keys())y.startsWith(_)&&!y.includes("__")&&e.state.env.delete(y);let k=ke($);for(let y=0;y<k.length;y++)v(e.state.env,`${l}_${y}`,k[y]);v(e.state.env,`${l}__length`,String(k.length)),Me(e,l),i&&Oe(e,l);continue}let h=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(h){l=h[1];let $=h[2];if(te(e,l,"bash"),!s.has(l)){s.set(l,e.state.env.get(l));let A=`${l}_`;for(let I of e.state.env.keys())I.startsWith(A)&&!I.includes("__")&&(s.has(I)||s.set(I,e.state.env.get(I)));let L=`${l}__length`;e.state.env.has(L)&&!s.has(L)&&s.set(L,e.state.env.get(L))}let _=ke($),k=ne(e,l),y=0,b=e.state.env.get(l);k.length===0&&b!==void 0?(e.state.env.set(`${l}_0`,b),e.state.env.delete(l),y=1):k.length>0&&(y=Math.max(...k)+1);for(let A=0;A<_.length;A++)v(e.state.env,`${l}_${y+A}`,Y(e,_[A]));let C=y+_.length;v(e.state.env,`${l}__length`,String(C)),Me(e,l),i&&Oe(e,l);continue}let g=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(g){l=g[1];let $=Y(e,g[2]);te(e,l,"bash"),s.has(l)||s.set(l,e.state.env.get(l));let _=O(e.state.env,l);v(e.state.env,l,_+$),Me(e,l),i&&Oe(e,l);continue}let m=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(m){l=m[1];let $=m[2],_=Y(e,m[3]);if(te(e,l,"bash"),!s.has(l)){s.set(l,e.state.env.get(l));let b=`${l}_`;for(let A of e.state.env.keys())A.startsWith(b)&&!A.includes("__")&&(s.has(A)||s.set(A,e.state.env.get(A)));let C=`${l}__length`;e.state.env.has(C)&&!s.has(C)&&s.set(C,e.state.env.get(C))}let k;try{let b=new H,C=Q(b,$);k=await q(e,C.expression)}catch{let b=parseInt($,10);k=Number.isNaN(b)?0:b}v(e.state.env,`${l}_${k}`,_);let y=parseInt(O(e.state.env,`${l}__length`,"0"),10);k>=y&&v(e.state.env,`${l}__length`,String(k+1)),Me(e,l),i&&Oe(e,l);continue}if(u.includes("=")){let $=u.indexOf("=");l=u.slice(0,$),f=Y(e,u.slice($+1))}else l=u;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l)){n+=`bash: local: \`${u}': not a valid identifier
513
- `,r=1;continue}let w=s.has(l);if(f!==void 0){let $=e.state.env.get(l);if(e.state.tempEnvBindings){let _=e.state.accessedTempEnvVars?.has(l),k=e.state.mutatedTempEnvVars?.has(l);if(!_&&!k)for(let y=e.state.tempEnvBindings.length-1;y>=0;y--){let b=e.state.tempEnvBindings[y];if(b.has(l)){$=b.get(l);break}}}Kn(e,l,$)}if(!w){let $=e.state.env.get(l);if(e.state.tempEnvBindings)for(let _=e.state.tempEnvBindings.length-1;_>=0;_--){let k=e.state.tempEnvBindings[_];if(k.has(l)){$=k.get(l);break}}if(s.set(l,$),o){let _=`${l}_`;for(let y of e.state.env.keys())y.startsWith(_)&&!y.includes("__")&&(s.has(y)||s.set(y,e.state.env.get(y)));let k=`${l}__length`;e.state.env.has(k)&&!s.has(k)&&s.set(k,e.state.env.get(k))}}if(o&&f===void 0){let $=`${l}_`;for(let _ of e.state.env.keys())_.startsWith($)&&!_.includes("__")&&e.state.env.delete(_);v(e.state.env,`${l}__length`,"0")}else if(f!==void 0){if(te(e,l,"bash"),i&&f!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(f)){n+=`bash: local: \`${f}': invalid variable name for name reference
513
+ `,r=1;continue}let w=s.has(l);if(f!==void 0){let $=e.state.env.get(l);if(e.state.tempEnvBindings){let _=e.state.accessedTempEnvVars?.has(l),k=e.state.mutatedTempEnvVars?.has(l);if(!_&&!k)for(let y=e.state.tempEnvBindings.length-1;y>=0;y--){let b=e.state.tempEnvBindings[y];if(b.has(l)){$=b.get(l);break}}}Xn(e,l,$)}if(!w){let $=e.state.env.get(l);if(e.state.tempEnvBindings)for(let _=e.state.tempEnvBindings.length-1;_>=0;_--){let k=e.state.tempEnvBindings[_];if(k.has(l)){$=k.get(l);break}}if(s.set(l,$),o){let _=`${l}_`;for(let y of e.state.env.keys())y.startsWith(_)&&!y.includes("__")&&(s.has(y)||s.set(y,e.state.env.get(y)));let k=`${l}__length`;e.state.env.has(k)&&!s.has(k)&&s.set(k,e.state.env.get(k))}}if(o&&f===void 0){let $=`${l}_`;for(let _ of e.state.env.keys())_.startsWith($)&&!_.includes("__")&&e.state.env.delete(_);v(e.state.env,`${l}__length`,"0")}else if(f!==void 0){if(te(e,l,"bash"),i&&f!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(f)){n+=`bash: local: \`${f}': invalid variable name for name reference
514
514
  `,r=1;continue}v(e.state.env,l,f),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(l))}else{let $=e.state.tempEnvBindings?.some(_=>_.has(l));!w&&!$&&e.state.env.delete(l)}Me(e,l),i&&Oe(e,l)}return T(p,E(n),r)}function Us(e,t,s){let n=z(s),r=`
515
515
  `,i=0,o=0,a=0,c=!1,u="MAPFILE",l=0;for(;l<t.length;){let k=t[l];k==="-d"&&l+1<t.length?(r=t[l+1]===""?"\0":t[l+1]||`
516
516
  `,l+=2):k==="-n"&&l+1<t.length?(i=Number.parseInt(t[l+1],10)||0,l+=2):k==="-O"&&l+1<t.length?(o=Number.parseInt(t[l+1],10)||0,l+=2):k==="-s"&&l+1<t.length?(a=Number.parseInt(t[l+1],10)||0,l+=2):k==="-t"?(c=!0,l++):k==="-u"||k==="-C"||k==="-c"?l+=2:(k.startsWith("-")||(u=k),l++)}let f=n;!f&&e.state.groupStdin!==void 0&&(f=z(e.state.groupStdin));let d=[],h=f,g=0,m=0,w=e.limits?.maxArrayElements??1e5;for(;h.length>0;){let k=h.indexOf(r);if(k===-1){if(h.length>0){if(m<a)m++;else if(i===0||g<i){if(o+g>=w)return T(p,E(`mapfile: array element limit exceeded (${w})
517
517
  `),1);let C=h,A=C.indexOf("\0");A!==-1&&(C=C.substring(0,A)),d.push(C),g++}}break}let y=h.substring(0,k),b=y.indexOf("\0");if(b!==-1&&(y=y.substring(0,b)),!c&&r!=="\0"&&(y+=r),h=h.substring(k+r.length),m<a){m++;continue}if(i>0&&g>=i)break;if(o+g>=w)return T(p,E(`mapfile: array element limit exceeded (${w})
518
- `),1);d.push(y),g++}o===0&&_e(e,u);for(let k=0;k<d.length;k++)v(e.state.env,`${u}_${o+k}`,d[k]);let $=parseInt(O(e.state.env,`${u}__length`,"0"),10),_=o+d.length;return v(e.state.env,`${u}__length`,String(Math.max($,_))),e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=p),T(p,p,0)}function to(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),c=a.indexOf(":");if(c===-1)return null;let u=Number.parseInt(a.slice(0,c),10);if(Number.isNaN(u)||u<0)return null;let l=a.slice(c+1);return{path:i,position:u,content:l}}function so(e,t,s){return`__rw__:${e.length}:${e}:${t}:${s}`}function Gs(e,t,s,n=-1){let r=z(s),i=!1,o=`
519
- `,a="",c=-1,u=-1,l=null,f=-1,d=-1,h=[],g=0,m=!1,w=(D,x)=>{let S=1;for(;S<D.length;){let R=D[S];if(R==="r")i=!0,S++;else if(R==="s")S++;else{if(R==="d")return S+1<D.length?(o=D.substring(S+1),{nextArgIndex:x+1}):x+1<t.length?(o=t[x+1],{nextArgIndex:x+2}):{nextArgIndex:x+1};if(R==="n"){if(S+1<D.length){let M=D.substring(S+1);return c=Number.parseInt(M,10),(Number.isNaN(c)||c<0)&&(m=!0,c=0),{nextArgIndex:x+1}}else if(x+1<t.length)return c=Number.parseInt(t[x+1],10),(Number.isNaN(c)||c<0)&&(m=!0,c=0),{nextArgIndex:x+2};return{nextArgIndex:x+1}}else if(R==="N"){if(S+1<D.length){let M=D.substring(S+1);return u=Number.parseInt(M,10),(Number.isNaN(u)||u<0)&&(m=!0,u=0),{nextArgIndex:x+1}}else if(x+1<t.length)return u=Number.parseInt(t[x+1],10),(Number.isNaN(u)||u<0)&&(m=!0,u=0),{nextArgIndex:x+2};return{nextArgIndex:x+1}}else{if(R==="a")return S+1<D.length?(l=D.substring(S+1),{nextArgIndex:x+1}):x+1<t.length?(l=t[x+1],{nextArgIndex:x+2}):{nextArgIndex:x+1};if(R==="p")return S+1<D.length?(a=D.substring(S+1),{nextArgIndex:x+1}):x+1<t.length?(a=t[x+1],{nextArgIndex:x+2}):{nextArgIndex:x+1};if(R==="u"){if(S+1<D.length){let M=D.substring(S+1);return f=Number.parseInt(M,10),Number.isNaN(f)||f<0?{nextArgIndex:-2}:{nextArgIndex:x+1}}else if(x+1<t.length)return f=Number.parseInt(t[x+1],10),Number.isNaN(f)||f<0?{nextArgIndex:-2}:{nextArgIndex:x+2};return{nextArgIndex:x+1}}else if(R==="t"){if(S+1<D.length){let M=D.substring(S+1);return d=Number.parseFloat(M),Number.isNaN(d)&&(d=0),{nextArgIndex:x+1}}else if(x+1<t.length)return d=Number.parseFloat(t[x+1]),Number.isNaN(d)&&(d=0),{nextArgIndex:x+2};return{nextArgIndex:x+1}}else if(R==="e"||R==="i"||R==="P"){if(R==="i"&&x+1<t.length)return{nextArgIndex:x+2};S++}else S++}}}return{nextArgIndex:x+1}};for(;g<t.length;){let D=t[g];if(D.startsWith("-")&&D.length>1&&D!=="--"){let x=w(D,g);if(x.nextArgIndex===-1)return{stdout:p,stderr:p,exitCode:2};if(x.nextArgIndex===-2)return{stdout:p,stderr:p,exitCode:1};g=x.nextArgIndex}else if(D==="--")for(g++;g<t.length;)h.push(t[g]),g++;else h.push(D),g++}if(m)return T(p,p,1);if(h.length===0&&l===null&&h.push("REPLY"),d===0){if(l)_e(e,l);else{for(let D of h)v(e.state.env,D,"");h.length===0&&v(e.state.env,"REPLY","")}return T(p,p,0)}if(d<0&&d!==-1)return T(p,p,1);let $=r;f>=0?e.state.fileDescriptors?$=e.state.fileDescriptors.get(f)||"":$="":!$&&e.state.groupStdin!==void 0&&($=z(e.state.groupStdin));let _=o===""?"\0":o,k="",y=0,b=!0,C=D=>{if(f>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(f,$.substring(D));else if(n>=0&&e.state.fileDescriptors){let x=e.state.fileDescriptors.get(n);if(x?.startsWith("__rw__:")){let S=to(x);if(S){let R=S.position+D;e.state.fileDescriptors.set(n,so(S.path,R,S.content))}}}else e.state.groupStdin!==void 0&&!r&&(e.state.groupStdin=E($.substring(D)))};if(u>=0){let D=Math.min(u,$.length);k=$.substring(0,D),y=D,b=D>=u,C(y);let x=h[0]||"REPLY";v(e.state.env,x,k);for(let S=1;S<h.length;S++)v(e.state.env,h[S],"");return T(p,p,b?0:1)}else if(c>=0){let D=0,x=0,S=!1;for(;x<$.length&&D<c;){let R=$[x];if(R===_){y=x+1,S=!0;break}if(!i&&R==="\\"&&x+1<$.length){let M=$[x+1];if(M===_&&_===`
518
+ `),1);d.push(y),g++}o===0&&_e(e,u);for(let k=0;k<d.length;k++)v(e.state.env,`${u}_${o+k}`,d[k]);let $=parseInt(O(e.state.env,`${u}__length`,"0"),10),_=o+d.length;return v(e.state.env,`${u}__length`,String(Math.max($,_))),e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=p),T(p,p,0)}function so(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),c=a.indexOf(":");if(c===-1)return null;let u=Number.parseInt(a.slice(0,c),10);if(Number.isNaN(u)||u<0)return null;let l=a.slice(c+1);return{path:i,position:u,content:l}}function no(e,t,s){return`__rw__:${e.length}:${e}:${t}:${s}`}function Gs(e,t,s,n=-1){let r=z(s),i=!1,o=`
519
+ `,a="",c=-1,u=-1,l=null,f=-1,d=-1,h=[],g=0,m=!1,w=(D,x)=>{let S=1;for(;S<D.length;){let R=D[S];if(R==="r")i=!0,S++;else if(R==="s")S++;else{if(R==="d")return S+1<D.length?(o=D.substring(S+1),{nextArgIndex:x+1}):x+1<t.length?(o=t[x+1],{nextArgIndex:x+2}):{nextArgIndex:x+1};if(R==="n"){if(S+1<D.length){let M=D.substring(S+1);return c=Number.parseInt(M,10),(Number.isNaN(c)||c<0)&&(m=!0,c=0),{nextArgIndex:x+1}}else if(x+1<t.length)return c=Number.parseInt(t[x+1],10),(Number.isNaN(c)||c<0)&&(m=!0,c=0),{nextArgIndex:x+2};return{nextArgIndex:x+1}}else if(R==="N"){if(S+1<D.length){let M=D.substring(S+1);return u=Number.parseInt(M,10),(Number.isNaN(u)||u<0)&&(m=!0,u=0),{nextArgIndex:x+1}}else if(x+1<t.length)return u=Number.parseInt(t[x+1],10),(Number.isNaN(u)||u<0)&&(m=!0,u=0),{nextArgIndex:x+2};return{nextArgIndex:x+1}}else{if(R==="a")return S+1<D.length?(l=D.substring(S+1),{nextArgIndex:x+1}):x+1<t.length?(l=t[x+1],{nextArgIndex:x+2}):{nextArgIndex:x+1};if(R==="p")return S+1<D.length?(a=D.substring(S+1),{nextArgIndex:x+1}):x+1<t.length?(a=t[x+1],{nextArgIndex:x+2}):{nextArgIndex:x+1};if(R==="u"){if(S+1<D.length){let M=D.substring(S+1);return f=Number.parseInt(M,10),Number.isNaN(f)||f<0?{nextArgIndex:-2}:{nextArgIndex:x+1}}else if(x+1<t.length)return f=Number.parseInt(t[x+1],10),Number.isNaN(f)||f<0?{nextArgIndex:-2}:{nextArgIndex:x+2};return{nextArgIndex:x+1}}else if(R==="t"){if(S+1<D.length){let M=D.substring(S+1);return d=Number.parseFloat(M),Number.isNaN(d)&&(d=0),{nextArgIndex:x+1}}else if(x+1<t.length)return d=Number.parseFloat(t[x+1]),Number.isNaN(d)&&(d=0),{nextArgIndex:x+2};return{nextArgIndex:x+1}}else if(R==="e"||R==="i"||R==="P"){if(R==="i"&&x+1<t.length)return{nextArgIndex:x+2};S++}else S++}}}return{nextArgIndex:x+1}};for(;g<t.length;){let D=t[g];if(D.startsWith("-")&&D.length>1&&D!=="--"){let x=w(D,g);if(x.nextArgIndex===-1)return{stdout:p,stderr:p,exitCode:2};if(x.nextArgIndex===-2)return{stdout:p,stderr:p,exitCode:1};g=x.nextArgIndex}else if(D==="--")for(g++;g<t.length;)h.push(t[g]),g++;else h.push(D),g++}if(m)return T(p,p,1);if(h.length===0&&l===null&&h.push("REPLY"),d===0){if(l)_e(e,l);else{for(let D of h)v(e.state.env,D,"");h.length===0&&v(e.state.env,"REPLY","")}return T(p,p,0)}if(d<0&&d!==-1)return T(p,p,1);let $=r;f>=0?e.state.fileDescriptors?$=e.state.fileDescriptors.get(f)||"":$="":!$&&e.state.groupStdin!==void 0&&($=z(e.state.groupStdin));let _=o===""?"\0":o,k="",y=0,b=!0,C=D=>{if(f>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(f,$.substring(D));else if(n>=0&&e.state.fileDescriptors){let x=e.state.fileDescriptors.get(n);if(x?.startsWith("__rw__:")){let S=so(x);if(S){let R=S.position+D;e.state.fileDescriptors.set(n,no(S.path,R,S.content))}}}else e.state.groupStdin!==void 0&&!r&&(e.state.groupStdin=E($.substring(D)))};if(u>=0){let D=Math.min(u,$.length);k=$.substring(0,D),y=D,b=D>=u,C(y);let x=h[0]||"REPLY";v(e.state.env,x,k);for(let S=1;S<h.length;S++)v(e.state.env,h[S],"");return T(p,p,b?0:1)}else if(c>=0){let D=0,x=0,S=!1;for(;x<$.length&&D<c;){let R=$[x];if(R===_){y=x+1,S=!0;break}if(!i&&R==="\\"&&x+1<$.length){let M=$[x+1];if(M===_&&_===`
520
520
  `){x+=2,y=x;continue}if(M===_){x+=2,D++,k+=M,y=x;continue}k+=M,x+=2,D++,y=x}else k+=R,x++,D++,y=x}b=D>=c||S,C(y)}else{y=0;let D=0;for(;D<$.length;){let x=$[D];if(x===_){y=D+_.length,b=!0;break}if(!i&&x==="\\"&&D+1<$.length){let S=$[D+1];if(S===`
521
521
  `){D+=2;continue}if(S===_){k+=S,D+=2;continue}k+=x,k+=S,D+=2;continue}k+=x,D++}if(D>=$.length&&(b=!1,y=D,k.length===0&&$.length===0)){for(let x of h)v(e.state.env,x,"");return l&&_e(e,l),T(p,p,1)}C(y)}_===`
522
522
  `&&k.endsWith(`
523
- `)&&(k=k.slice(0,-1));let A=D=>i?D:D.replace(/\\(.)/g,"$1");if(h.length===1&&h[0]==="REPLY")return v(e.state.env,"REPLY",A(k)),T(p,p,b?0:1);let L=pn(e.state.env);if(l){let{words:D}=ts(k,L,void 0,i),x=e.limits?.maxArrayElements??1e5;if(D.length>x)return T(p,E(`read: array element limit exceeded (${x})
524
- `),1);_e(e,l);for(let S=0;S<D.length;S++)v(e.state.env,`${l}_${S}`,A(D[S]));return T(p,p,b?0:1)}let I=h.length,{words:W,wordStarts:B}=ts(k,L,I,i);for(let D=0;D<h.length;D++){let x=h[D];if(D<h.length-1)v(e.state.env,x,A(W[D]??""));else if(D<B.length){let S=k.substring(B[D]);S=mn(S,L,i),S=A(S),v(e.state.env,x,S)}else v(e.state.env,x,"")}return T(p,p,b?0:1)}function qs(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return P("bash: return: can only `return' from a function or sourced script\n");let s=e.state.lastExitCode;if(t.length>0){let n=t[0],r=Number.parseInt(n,10);if(n===""||Number.isNaN(r)||!/^-?\d+$/.test(n))return P(`bash: return: ${n}: numeric argument required
523
+ `)&&(k=k.slice(0,-1));let A=D=>i?D:D.replace(/\\(.)/g,"$1");if(h.length===1&&h[0]==="REPLY")return v(e.state.env,"REPLY",A(k)),T(p,p,b?0:1);let L=mn(e.state.env);if(l){let{words:D}=ts(k,L,void 0,i),x=e.limits?.maxArrayElements??1e5;if(D.length>x)return T(p,E(`read: array element limit exceeded (${x})
524
+ `),1);_e(e,l);for(let S=0;S<D.length;S++)v(e.state.env,`${l}_${S}`,A(D[S]));return T(p,p,b?0:1)}let I=h.length,{words:W,wordStarts:B}=ts(k,L,I,i);for(let D=0;D<h.length;D++){let x=h[D];if(D<h.length-1)v(e.state.env,x,A(W[D]??""));else if(D<B.length){let S=k.substring(B[D]);S=yn(S,L,i),S=A(S),v(e.state.env,x,S)}else v(e.state.env,x,"")}return T(p,p,b?0:1)}function qs(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return P("bash: return: can only `return' from a function or sourced script\n");let s=e.state.lastExitCode;if(t.length>0){let n=t[0],r=Number.parseInt(n,10);if(n===""||Number.isNaN(r)||!/^-?\d+$/.test(n))return P(`bash: return: ${n}: numeric argument required
525
525
  `,2);s=(r%256+256)%256}throw new ce(s)}var Ut=`set: usage: set [-eux] [+eux] [-o option] [+o option]
526
526
  Options:
527
527
  -e Exit immediately if a command exits with non-zero status
@@ -538,56 +538,56 @@ Options:
538
538
  +o pipefail Disable pipefail
539
539
  -o xtrace Same as -x
540
540
  +o xtrace Disable xtrace
541
- `,hr=new Map([["e","errexit"],["u","nounset"],["x","xtrace"],["v","verbose"],["f","noglob"],["C","noclobber"],["a","allexport"],["n","noexec"],["h",null],["b",null],["m",null],["B",null],["H",null],["P",null],["T",null],["E",null],["p",null]]),pr=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["noclobber","noclobber"],["noglob","noglob"],["allexport","allexport"],["noexec","noexec"],["posix","posix"],["vi","vi"],["emacs","emacs"],["notify",null],["monitor",null],["braceexpand",null],["histexpand",null],["physical",null],["functrace",null],["errtrace",null],["privileged",null],["hashall",null],["ignoreeof",null],["interactive-comments",null],["keyword",null],["onecmd",null]]),mr=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],yr=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function gr(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,qe(e))}function no(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function ro(e,t){let s=ne(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=O(e.state.env,`${t}_${r}`,"");return`[${r}]=${ze(i)}`});return`${t}=(${n.join(" ")})`}function io(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function oo(e,t){let s=Ie(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=O(e.state.env,`${t}_${r}`,"");return`[${io(r)}]=${ze(i)}`});return`${t}=(${n.join(" ")} )`}function ao(e){let t=new Set,s=e.state.associativeArrays??new Set;for(let n of e.state.env.keys()){let r=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(r){let i=r[1];s.has(i)||t.add(i)}}return t}function lo(e){return e.state.associativeArrays??new Set}function Ys(e,t){if(t.includes("--help"))return U(Ut);if(t.length===0){let n=ao(e),r=lo(e),i=c=>{for(let u of r){let l=`${u}_`,f=`${u}__length`;if(c!==f&&c.startsWith(l)){if(c.slice(l.length).startsWith("_length"))continue;return!0}}return!1},o=[];for(let[c,u]of e.state.env){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)||n.has(c)||r.has(c))continue;let l=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(l&&n.has(l[1]))continue;let f=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);f&&n.has(f[1])||i(c)||f&&r.has(f[1])||o.push([c,z(u)])}let a=[];for(let[c,u]of o.sort(([l],[f])=>l<f?-1:l>f?1:0))a.push(`${c}=${Bt(u)}`);for(let c of[...n].sort((u,l)=>u<l?-1:u>l?1:0))a.push(ro(e,c));for(let c of[...r].sort((u,l)=>u<l?-1:u>l?1:0))a.push(oo(e,c));return a.sort((c,u)=>{let l=c.split("=")[0],f=u.split("=")[0];return l<f?-1:l>f?1:0}),U(a.length>0?`${a.join(`
541
+ `,pr=new Map([["e","errexit"],["u","nounset"],["x","xtrace"],["v","verbose"],["f","noglob"],["C","noclobber"],["a","allexport"],["n","noexec"],["h",null],["b",null],["m",null],["B",null],["H",null],["P",null],["T",null],["E",null],["p",null]]),mr=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["noclobber","noclobber"],["noglob","noglob"],["allexport","allexport"],["noexec","noexec"],["posix","posix"],["vi","vi"],["emacs","emacs"],["notify",null],["monitor",null],["braceexpand",null],["histexpand",null],["physical",null],["functrace",null],["errtrace",null],["privileged",null],["hashall",null],["ignoreeof",null],["interactive-comments",null],["keyword",null],["onecmd",null]]),yr=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],gr=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function vr(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,qe(e))}function ro(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function io(e,t){let s=ne(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=O(e.state.env,`${t}_${r}`,"");return`[${r}]=${ze(i)}`});return`${t}=(${n.join(" ")})`}function oo(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function ao(e,t){let s=Ie(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=O(e.state.env,`${t}_${r}`,"");return`[${oo(r)}]=${ze(i)}`});return`${t}=(${n.join(" ")} )`}function lo(e){let t=new Set,s=e.state.associativeArrays??new Set;for(let n of e.state.env.keys()){let r=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(r){let i=r[1];s.has(i)||t.add(i)}}return t}function co(e){return e.state.associativeArrays??new Set}function Ys(e,t){if(t.includes("--help"))return U(Ut);if(t.length===0){let n=lo(e),r=co(e),i=c=>{for(let u of r){let l=`${u}_`,f=`${u}__length`;if(c!==f&&c.startsWith(l)){if(c.slice(l.length).startsWith("_length"))continue;return!0}}return!1},o=[];for(let[c,u]of e.state.env){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)||n.has(c)||r.has(c))continue;let l=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(l&&n.has(l[1]))continue;let f=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);f&&n.has(f[1])||i(c)||f&&r.has(f[1])||o.push([c,z(u)])}let a=[];for(let[c,u]of o.sort(([l],[f])=>l<f?-1:l>f?1:0))a.push(`${c}=${Bt(u)}`);for(let c of[...n].sort((u,l)=>u<l?-1:u>l?1:0))a.push(io(e,c));for(let c of[...r].sort((u,l)=>u<l?-1:u>l?1:0))a.push(ao(e,c));return a.sort((c,u)=>{let l=c.split("=")[0],f=u.split("=")[0];return l<f?-1:l>f?1:0}),U(a.length>0?`${a.join(`
542
542
  `)}
543
- `:"")}let s=0;for(;s<t.length;){let n=t[s];if((n==="-o"||n==="+o")&&no(t,s)){let r=t[s+1];if(!pr.has(r)){let i=`bash: set: ${r}: invalid option name
544
- ${Ut}`;if(e.state.options.posix)throw new we(1,p,E(i));return P(i)}gr(e,pr.get(r)??null,n==="-o"),s+=2;continue}if(n==="-o"){let r=mr.map(a=>`${a.padEnd(16)}${e.state.options[a]?"on":"off"}`),i=yr.map(a=>`${a.padEnd(16)}off`),o=[...r,...i].sort();return U(`${o.join(`
543
+ `:"")}let s=0;for(;s<t.length;){let n=t[s];if((n==="-o"||n==="+o")&&ro(t,s)){let r=t[s+1];if(!mr.has(r)){let i=`bash: set: ${r}: invalid option name
544
+ ${Ut}`;if(e.state.options.posix)throw new we(1,p,E(i));return P(i)}vr(e,mr.get(r)??null,n==="-o"),s+=2;continue}if(n==="-o"){let r=yr.map(a=>`${a.padEnd(16)}${e.state.options[a]?"on":"off"}`),i=gr.map(a=>`${a.padEnd(16)}off`),o=[...r,...i].sort();return U(`${o.join(`
545
545
  `)}
546
- `)}if(n==="+o"){let r=mr.map(a=>`set ${e.state.options[a]?"-o":"+o"} ${a}`),i=yr.map(a=>`set +o ${a}`),o=[...r,...i].sort();return U(`${o.join(`
546
+ `)}if(n==="+o"){let r=yr.map(a=>`set ${e.state.options[a]?"-o":"+o"} ${a}`),i=gr.map(a=>`set +o ${a}`),o=[...r,...i].sort();return U(`${o.join(`
547
547
  `)}
548
- `)}if(n.length>1&&(n[0]==="-"||n[0]==="+")&&n[1]!=="-"){let r=n[0]==="-";for(let i=1;i<n.length;i++){let o=n[i];if(!hr.has(o)){let a=`bash: set: ${n[0]}${o}: invalid option
549
- ${Ut}`;if(e.state.options.posix)throw new we(1,p,E(a));return P(a)}gr(e,hr.get(o)??null,r)}s++;continue}if(n==="--")return Zs(e,t.slice(s+1)),V;if(n==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,qe(e),s+1<t.length)return Zs(e,t.slice(s+1)),V;s++;continue}if(n==="+"){s++;continue}if(n.startsWith("-")||n.startsWith("+")){let r=`bash: set: ${n}: invalid option
548
+ `)}if(n.length>1&&(n[0]==="-"||n[0]==="+")&&n[1]!=="-"){let r=n[0]==="-";for(let i=1;i<n.length;i++){let o=n[i];if(!pr.has(o)){let a=`bash: set: ${n[0]}${o}: invalid option
549
+ ${Ut}`;if(e.state.options.posix)throw new we(1,p,E(a));return P(a)}vr(e,pr.get(o)??null,r)}s++;continue}if(n==="--")return Zs(e,t.slice(s+1)),V;if(n==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,qe(e),s+1<t.length)return Zs(e,t.slice(s+1)),V;s++;continue}if(n==="+"){s++;continue}if(n.startsWith("-")||n.startsWith("+")){let r=`bash: set: ${n}: invalid option
550
550
  ${Ut}`;if(e.state.options.posix)throw new we(1,p,E(r));return P(r)}return Zs(e,t.slice(s)),V}return V}function Zs(e,t){let s=1;for(;e.state.env.has(String(s));)e.state.env.delete(String(s)),s++;for(let n=0;n<t.length;n++)v(e.state.env,String(n+1),t[n]);v(e.state.env,"#",String(t.length)),v(e.state.env,"@",t.join(" ")),v(e.state.env,"*",t.join(" "))}function Ks(e,t){let s=1;if(t.length>0){let o=Number.parseInt(t[0],10);if(Number.isNaN(o)||o<0){let a=`bash: shift: ${t[0]}: numeric argument required
551
551
  `;if(e.state.options.posix)throw new we(1,p,E(a));return P(a)}s=o}let n=Number.parseInt(O(e.state.env,"#","0"),10);if(s>n){let o=`bash: shift: shift count out of range
552
552
  `;if(e.state.options.posix)throw new we(1,p,E(o));return P(o)}if(s===0)return V;let r=[];for(let o=1;o<=n;o++)r.push(O(e.state.env,String(o))||"");let i=r.slice(s);for(let o=1;o<=n;o++)e.state.env.delete(String(o));for(let o=0;o<i.length;o++)v(e.state.env,String(o+1),i[o]);return v(e.state.env,"#",String(i.length)),v(e.state.env,"@",i.join(" ")),V}async function Xs(e,t){let s=t;if(s.length>0&&s[0]==="--"&&(s=s.slice(1)),s.length===0)return T(p,E(`bash: source: filename argument required
553
553
  `),2);let n=s[0],r=null,i=null;if(n.includes("/")){let u=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(u),r=u}catch{}}else{let l=O(e.state.env,"PATH","").split(":").filter(f=>f);for(let f of l){let d=e.fs.resolvePath(e.state.cwd,`${f}/${n}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),r=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(f),r=f}catch{}}}if(i===null)return P(`bash: ${n}: No such file or directory
554
554
  `);let o=new Map;if(s.length>1){for(let l=1;l<=9;l++)o.set(String(l),O(e.state.env,String(l)));o.set("#",O(e.state.env,"#")),o.set("@",O(e.state.env,"@"));let u=s.slice(1);v(e.state.env,"#",String(u.length)),v(e.state.env,"@",u.join(" "));for(let l=0;l<u.length&&l<9;l++)v(e.state.env,String(l+1),u[l]);for(let l=u.length+1;l<=9;l++)e.state.env.delete(String(l))}let a=e.state.currentSource,c=()=>{if(e.state.sourceDepth--,e.state.currentSource=a,s.length>1)for(let[u,l]of o)l===void 0?e.state.env.delete(u):v(e.state.env,u,l)};e.state.sourceDepth++,e.state.currentSource=n;try{let u=Ae(i),l=await e.executeScript(u);return c(),l}catch(u){if(c(),u instanceof G)throw u;if(u instanceof ce)return T(u.stdout,u.stderr,u.exitCode);if(u.name==="ParseException")return P(`bash: ${n}: ${u.message}
555
- `);throw u}}function vr(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function co(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function wr(e,t){if(co(t))return null;try{let s=new H,n=Q(s,t);return await q(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}function br(e,t){if(e.state.localVarStack?.has(t)){let n=Wt(e,t);if(n){n.value===void 0?e.state.env.delete(t):e.state.env.set(t,n.value);let r=e.state.localVarStack?.get(t);if(!r||r.length===0)Ft(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,n.scopeIndex),Qs(e,t);else{let i=r[r.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return e.state.env.delete(t),Ft(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let n=e.state.localScopes.length-1;n>=0;n--){let r=e.state.localScopes[n];if(r.has(t)){let i=r.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),r.delete(t);let o=!1;for(let a=n-1;a>=0;a--)if(e.state.localScopes[a].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,a+1),o=!0;break}return o||Ft(e,t),!0}}return!1}function Qs(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let s=e.state.tempEnvBindings.length-1;s>=0;s--){let n=e.state.tempEnvBindings[s];if(n.has(t)){let r=n.get(t);return r===void 0?e.state.env.delete(t):e.state.env.set(t,r),n.delete(t),!0}}return!1}async function Er(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let s=t.slice(1,-1),r=new H().parseWordFromString(s,!0,!1);return F(e,r)}if(t.includes("$")){let n=new H().parseWordFromString(t,!1,!1);return F(e,n)}return t}async function Js(e,t){let s="both",n="",r=0;for(let i of t){if(i==="-v"){s="variable";continue}if(i==="-f"){s="function";continue}if(s==="function"){e.state.functions.delete(i);continue}if(s==="variable"){let u=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(u){let d=u[1],h=u[2];if(h==="@"||h==="*"){let k=Se(e,d);for(let[y]of k)e.state.env.delete(`${d}_${y}`);e.state.env.delete(d);continue}let g=e.state.associativeArrays?.has(d);if(g){let k=await Er(e,h);e.state.env.delete(`${d}_${k}`);continue}let m=rs(e,d),w=e.state.declaredVars?.has(d);if((e.state.env.has(d)||w)&&!m&&!g){n+=`bash: unset: ${d}: not an array variable
556
- `,r=1;continue}let _=await wr(e,h);if(_===null&&m){n+=`bash: unset: ${h}: not a valid identifier
555
+ `);throw u}}function wr(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function uo(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function br(e,t){if(uo(t))return null;try{let s=new H,n=Q(s,t);return await q(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}function Er(e,t){if(e.state.localVarStack?.has(t)){let n=Wt(e,t);if(n){n.value===void 0?e.state.env.delete(t):e.state.env.set(t,n.value);let r=e.state.localVarStack?.get(t);if(!r||r.length===0)Ft(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,n.scopeIndex),Qs(e,t);else{let i=r[r.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return e.state.env.delete(t),Ft(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let n=e.state.localScopes.length-1;n>=0;n--){let r=e.state.localScopes[n];if(r.has(t)){let i=r.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),r.delete(t);let o=!1;for(let a=n-1;a>=0;a--)if(e.state.localScopes[a].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,a+1),o=!0;break}return o||Ft(e,t),!0}}return!1}function Qs(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let s=e.state.tempEnvBindings.length-1;s>=0;s--){let n=e.state.tempEnvBindings[s];if(n.has(t)){let r=n.get(t);return r===void 0?e.state.env.delete(t):e.state.env.set(t,r),n.delete(t),!0}}return!1}async function Sr(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let s=t.slice(1,-1),r=new H().parseWordFromString(s,!0,!1);return F(e,r)}if(t.includes("$")){let n=new H().parseWordFromString(t,!1,!1);return F(e,n)}return t}async function Js(e,t){let s="both",n="",r=0;for(let i of t){if(i==="-v"){s="variable";continue}if(i==="-f"){s="function";continue}if(s==="function"){e.state.functions.delete(i);continue}if(s==="variable"){let u=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(u){let d=u[1],h=u[2];if(h==="@"||h==="*"){let k=Se(e,d);for(let[y]of k)e.state.env.delete(`${d}_${y}`);e.state.env.delete(d);continue}let g=e.state.associativeArrays?.has(d);if(g){let k=await Sr(e,h);e.state.env.delete(`${d}_${k}`);continue}let m=rs(e,d),w=e.state.declaredVars?.has(d);if((e.state.env.has(d)||w)&&!m&&!g){n+=`bash: unset: ${d}: not an array variable
556
+ `,r=1;continue}let _=await br(e,h);if(_===null&&m){n+=`bash: unset: ${h}: not a valid identifier
557
557
  `,r=1;continue}if(_===null)continue;if(_<0){let k=Se(e,d),y=k.length,b=e.state.currentLine;if(y===0){n+=`bash: line ${b}: unset: [${_}]: bad array subscript
558
558
  `,r=1;continue}let C=y+_;if(C<0){n+=`bash: line ${b}: unset: [${_}]: bad array subscript
559
- `,r=1;continue}let A=k[C][0];e.state.env.delete(`${d}_${A}`);continue}e.state.env.delete(`${d}_${_}`);continue}if(!vr(i)){n+=`bash: unset: \`${i}': not a valid identifier
559
+ `,r=1;continue}let A=k[C][0];e.state.env.delete(`${d}_${A}`);continue}e.state.env.delete(`${d}_${_}`);continue}if(!wr(i)){n+=`bash: unset: \`${i}': not a valid identifier
560
560
  `,r=1;continue}let l=i;if(ue(e,i)){let d=Pe(e,i);d&&d!==i&&(l=d)}if(We(e,l)){n+=`bash: unset: ${l}: cannot unset: readonly variable
561
- `,r=1;continue}let f=Ye(e,l);if(f!==void 0&&f!==e.state.callDepth)br(e,l);else if(e.state.fullyUnsetLocals?.has(l))e.state.env.delete(l);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(l),h=e.state.mutatedTempEnvVars?.has(l);if((d||h)&&e.state.localVarStack?.has(l)){let g=Wt(e,l);g?g.value===void 0?e.state.env.delete(l):e.state.env.set(l,g.value):e.state.env.delete(l)}else e.state.env.delete(l)}else Qs(e,l)||e.state.env.delete(l);e.state.exportedVars?.delete(l);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let u=o[1],l=o[2];if(l==="@"||l==="*"){let m=Se(e,u);for(let[w]of m)e.state.env.delete(`${u}_${w}`);e.state.env.delete(u);continue}let f=e.state.associativeArrays?.has(u);if(f){let m=await Er(e,l);e.state.env.delete(`${u}_${m}`);continue}let d=rs(e,u);if(e.state.env.has(u)&&!d&&!f){n+=`bash: unset: ${u}: not an array variable
562
- `,r=1;continue}let g=await wr(e,l);if(g===null&&d){n+=`bash: unset: ${l}: not a valid identifier
561
+ `,r=1;continue}let f=Ye(e,l);if(f!==void 0&&f!==e.state.callDepth)Er(e,l);else if(e.state.fullyUnsetLocals?.has(l))e.state.env.delete(l);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(l),h=e.state.mutatedTempEnvVars?.has(l);if((d||h)&&e.state.localVarStack?.has(l)){let g=Wt(e,l);g?g.value===void 0?e.state.env.delete(l):e.state.env.set(l,g.value):e.state.env.delete(l)}else e.state.env.delete(l)}else Qs(e,l)||e.state.env.delete(l);e.state.exportedVars?.delete(l);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let u=o[1],l=o[2];if(l==="@"||l==="*"){let m=Se(e,u);for(let[w]of m)e.state.env.delete(`${u}_${w}`);e.state.env.delete(u);continue}let f=e.state.associativeArrays?.has(u);if(f){let m=await Sr(e,l);e.state.env.delete(`${u}_${m}`);continue}let d=rs(e,u);if(e.state.env.has(u)&&!d&&!f){n+=`bash: unset: ${u}: not an array variable
562
+ `,r=1;continue}let g=await br(e,l);if(g===null&&d){n+=`bash: unset: ${l}: not a valid identifier
563
563
  `,r=1;continue}if(g===null)continue;if(g<0){let m=Se(e,u),w=m.length,$=e.state.currentLine;if(w===0){n+=`bash: line ${$}: unset: [${g}]: bad array subscript
564
564
  `,r=1;continue}let _=w+g;if(_<0){n+=`bash: line ${$}: unset: [${g}]: bad array subscript
565
- `,r=1;continue}let k=m[_][0];e.state.env.delete(`${u}_${k}`);continue}e.state.env.delete(`${u}_${g}`);continue}if(!vr(i)){n+=`bash: unset: \`${i}': not a valid identifier
565
+ `,r=1;continue}let k=m[_][0];e.state.env.delete(`${u}_${k}`);continue}e.state.env.delete(`${u}_${g}`);continue}if(!wr(i)){n+=`bash: unset: \`${i}': not a valid identifier
566
566
  `,r=1;continue}let a=i;if(ue(e,i)){let u=Pe(e,i);u&&u!==i&&(a=u)}if(We(e,a)){n+=`bash: unset: ${a}: cannot unset: readonly variable
567
- `,r=1;continue}let c=Ye(e,a);if(c!==void 0&&c!==e.state.callDepth)br(e,a);else if(e.state.fullyUnsetLocals?.has(a))e.state.env.delete(a);else if(c!==void 0){let u=e.state.accessedTempEnvVars?.has(a),l=e.state.mutatedTempEnvVars?.has(a);if((u||l)&&e.state.localVarStack?.has(a)){let f=Wt(e,a);f?f.value===void 0?e.state.env.delete(a):e.state.env.set(a,f.value):e.state.env.delete(a)}else e.state.env.delete(a)}else Qs(e,a)||e.state.env.delete(a);e.state.exportedVars?.delete(a),e.state.functions.delete(i)}return T(p,E(n),r)}var en=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],uo=["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 Gt(e){return en.includes(e)}function fo(e){return uo.includes(e)}function Sr(e,t){let s=!1,n=!1,r=!1,i=!1,o=!1,a=[],c=0;for(;c<t.length;){let d=t[c];if(d==="--"){c++;break}if(d.startsWith("-")&&d.length>1){for(let h=1;h<d.length;h++){let g=d[h];switch(g){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:p,stderr:E(`shopt: -${g}: invalid option
568
- `)}}}c++}else break}for(;c<t.length;)a.push(t[c]),c++;if(o)return ho(e,a,s,n,r,i);if(s&&n)return{exitCode:1,stdout:p,stderr:E(`shopt: cannot set and unset shell options simultaneously
567
+ `,r=1;continue}let c=Ye(e,a);if(c!==void 0&&c!==e.state.callDepth)Er(e,a);else if(e.state.fullyUnsetLocals?.has(a))e.state.env.delete(a);else if(c!==void 0){let u=e.state.accessedTempEnvVars?.has(a),l=e.state.mutatedTempEnvVars?.has(a);if((u||l)&&e.state.localVarStack?.has(a)){let f=Wt(e,a);f?f.value===void 0?e.state.env.delete(a):e.state.env.set(a,f.value):e.state.env.delete(a)}else e.state.env.delete(a)}else Qs(e,a)||e.state.env.delete(a);e.state.exportedVars?.delete(a),e.state.functions.delete(i)}return T(p,E(n),r)}var en=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],fo=["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 Gt(e){return en.includes(e)}function ho(e){return fo.includes(e)}function $r(e,t){let s=!1,n=!1,r=!1,i=!1,o=!1,a=[],c=0;for(;c<t.length;){let d=t[c];if(d==="--"){c++;break}if(d.startsWith("-")&&d.length>1){for(let h=1;h<d.length;h++){let g=d[h];switch(g){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:p,stderr:E(`shopt: -${g}: invalid option
568
+ `)}}}c++}else break}for(;c<t.length;)a.push(t[c]),c++;if(o)return po(e,a,s,n,r,i);if(s&&n)return{exitCode:1,stdout:p,stderr:E(`shopt: cannot set and unset shell options simultaneously
569
569
  `)};if(a.length===0){if(s||n){let h=[];for(let g of en){let m=e.state.shoptOptions[g];s&&m?h.push(r?`shopt -s ${g}`:`${g} on`):n&&!m&&h.push(r?`shopt -u ${g}`:`${g} off`)}return{exitCode:0,stdout:h.length>0?E(`${h.join(`
570
570
  `)}
571
571
  `):p,stderr:p}}let d=[];for(let h of en){let g=e.state.shoptOptions[h];d.push(r?`shopt ${g?"-s":"-u"} ${h}`:`${h} ${g?"on":"off"}`)}return{exitCode:0,stdout:E(`${d.join(`
572
572
  `)}
573
- `),stderr:p}}let u=!1,l="",f=[];for(let d of a){if(!Gt(d)&&!fo(d)){l+=`shopt: ${d}: invalid shell option name
573
+ `),stderr:p}}let u=!1,l="",f=[];for(let d of a){if(!Gt(d)&&!ho(d)){l+=`shopt: ${d}: invalid shell option name
574
574
  `,u=!0;continue}if(s)Gt(d)&&(e.state.shoptOptions[d]=!0,us(e));else if(n)Gt(d)&&(e.state.shoptOptions[d]=!1,us(e));else if(Gt(d)){let h=e.state.shoptOptions[d];i?h||(u=!0):r?(f.push(`shopt ${h?"-s":"-u"} ${d}`),h||(u=!0)):(f.push(`${d} ${h?"on":"off"}`),h||(u=!0))}else i?u=!0:r?(f.push(`shopt -u ${d}`),u=!0):(f.push(`${d} off`),u=!0)}return{exitCode:u?1:0,stdout:f.length>0?E(`${f.join(`
575
575
  `)}
576
- `):p,stderr:E(l)}}function ho(e,t,s,n,r,i){let o=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),a=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],c=[...o.keys(),...a].sort();if(t.length===0){let d=[];for(let h of c){let g=a.includes(h),m=o.get(h),w=g||!m?!1:e.state.options[m];s&&!w||n&&w||d.push(r?`set ${w?"-o":"+o"} ${h}`:`${h} ${w?"on":"off"}`)}return{exitCode:0,stdout:d.length>0?E(`${d.join(`
576
+ `):p,stderr:E(l)}}function po(e,t,s,n,r,i){let o=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),a=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],c=[...o.keys(),...a].sort();if(t.length===0){let d=[];for(let h of c){let g=a.includes(h),m=o.get(h),w=g||!m?!1:e.state.options[m];s&&!w||n&&w||d.push(r?`set ${w?"-o":"+o"} ${h}`:`${h} ${w?"on":"off"}`)}return{exitCode:0,stdout:d.length>0?E(`${d.join(`
577
577
  `)}
578
578
  `):p,stderr:p}}let u=!1,l="",f=[];for(let d of t){let h=o.has(d),g=a.includes(d);if(!h&&!g){l+=`shopt: ${d}: invalid option name
579
579
  `,u=!0;continue}if(g){s||n||(i?u=!0:r?(f.push(`set +o ${d}`),u=!0):(f.push(`${d} off`),u=!0));continue}let m=o.get(d);if(m)if(s)m==="vi"?e.state.options.emacs=!1:m==="emacs"&&(e.state.options.vi=!1),e.state.options[m]=!0,qe(e);else if(n)e.state.options[m]=!1,qe(e);else{let w=e.state.options[m];i?w||(u=!0):r?(f.push(`set ${w?"-o":"+o"} ${d}`),w||(u=!0)):(f.push(`${d} ${w?"on":"off"}`),w||(u=!0))}}return{exitCode:u?1:0,stdout:f.length>0?E(`${f.join(`
580
580
  `)}
581
- `):p,stderr:E(l)}}async function $r(e,t,s){if(t.includes("/")){let o=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(o))return{error:"not_found",path:o};let a=o.split("/").pop()||t,c=e.commands.get(a);try{let u=await e.fs.stat(o);return u.isDirectory?{error:"permission_denied",path:o}:c?{cmd:c,path:o}:(u.mode&73)!==0?{script:!0,path:o}:{error:"permission_denied",path:o}}catch{return{error:"not_found",path:o}}}if(!s&&e.state.hashTable){let o=e.state.hashTable.get(t);if(o)if(await e.fs.exists(o)){let a=e.commands.get(t);if(a)return{cmd:a,path:o};try{let c=await e.fs.stat(o);if(!c.isDirectory&&(c.mode&73)!==0)return{script:!0,path:o}}catch{}}else e.state.hashTable.delete(t)}let r=(s??O(e.state.env,"PATH","/usr/bin:/bin")).split(":");for(let o of r){if(!o)continue;let c=`${o.startsWith("/")?o:e.fs.resolvePath(e.state.cwd,o)}/${t}`;if(await e.fs.exists(c))try{let u=await e.fs.stat(c);if(u.isDirectory)continue;let l=(u.mode&73)!==0,f=e.commands.get(t),d=o==="/bin"||o==="/usr/bin";if(f&&d)return{cmd:f,path:c};if(l){if(f&&!d)return{script:!0,path:c};if(!f)return{script:!0,path:c}}}catch{}}if(!await e.fs.exists("/usr/bin")){let o=e.commands.get(t);if(o)return{cmd:o,path:`/usr/bin/${t}`}}return null}async function qt(e,t){let s=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let o=await e.fs.stat(i);o.isDirectory||(o.mode&73)!==0&&s.push(t)}catch{}return s}let r=O(e.state.env,"PATH","/usr/bin:/bin").split(":");for(let i of r){if(!i)continue;let a=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?a:`${i}/${t}`)}}return s}async function Cr(e,t,s,n){let r=!1,i=!1,o=!1,a=!1,c=!1,u=[];for(let m of t)if(m.startsWith("-")&&m.length>1)for(let w of m.slice(1))w==="t"?r=!0:w==="p"?i=!0:w==="P"?o=!0:w==="a"?a=!0:w==="f"&&(c=!0);else u.push(m);let l="",f="",d=0,h=!1,g=!1;for(let m of u){let w=!1;if(o){if(a){let C=await n(m);if(C.length>0){for(let A of C)l+=`${A}
581
+ `):p,stderr:E(l)}}async function Ar(e,t,s){if(t.includes("/")){let o=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(o))return{error:"not_found",path:o};let a=o.split("/").pop()||t,c=e.commands.get(a);try{let u=await e.fs.stat(o);return u.isDirectory?{error:"permission_denied",path:o}:c?{cmd:c,path:o}:(u.mode&73)!==0?{script:!0,path:o}:{error:"permission_denied",path:o}}catch{return{error:"not_found",path:o}}}if(!s&&e.state.hashTable){let o=e.state.hashTable.get(t);if(o)if(await e.fs.exists(o)){let a=e.commands.get(t);if(a)return{cmd:a,path:o};try{let c=await e.fs.stat(o);if(!c.isDirectory&&(c.mode&73)!==0)return{script:!0,path:o}}catch{}}else e.state.hashTable.delete(t)}let r=(s??O(e.state.env,"PATH","/usr/bin:/bin")).split(":");for(let o of r){if(!o)continue;let c=`${o.startsWith("/")?o:e.fs.resolvePath(e.state.cwd,o)}/${t}`;if(await e.fs.exists(c))try{let u=await e.fs.stat(c);if(u.isDirectory)continue;let l=(u.mode&73)!==0,f=e.commands.get(t),d=o==="/bin"||o==="/usr/bin";if(f&&d)return{cmd:f,path:c};if(l){if(f&&!d)return{script:!0,path:c};if(!f)return{script:!0,path:c}}}catch{}}if(!await e.fs.exists("/usr/bin")){let o=e.commands.get(t);if(o)return{cmd:o,path:`/usr/bin/${t}`}}return null}async function qt(e,t){let s=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let o=await e.fs.stat(i);o.isDirectory||(o.mode&73)!==0&&s.push(t)}catch{}return s}let r=O(e.state.env,"PATH","/usr/bin:/bin").split(":");for(let i of r){if(!i)continue;let a=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?a:`${i}/${t}`)}}return s}async function kr(e,t,s,n){let r=!1,i=!1,o=!1,a=!1,c=!1,u=[];for(let m of t)if(m.startsWith("-")&&m.length>1)for(let w of m.slice(1))w==="t"?r=!0:w==="p"?i=!0:w==="P"?o=!0:w==="a"?a=!0:w==="f"&&(c=!0);else u.push(m);let l="",f="",d=0,h=!1,g=!1;for(let m of u){let w=!1;if(o){if(a){let C=await n(m);if(C.length>0){for(let A of C)l+=`${A}
582
582
  `;h=!0,w=!0}}else{let C=await s(m);C&&(l+=`${C}
583
583
  `,h=!0,w=!0)}w||(g=!0);continue}let $=!c&&e.state.functions.has(m);if(a&&$){if(!i)if(r)l+=`function
584
- `;else{let C=e.state.functions.get(m),A=C?Ar(m,C):`${m} is a function
584
+ `;else{let C=e.state.functions.get(m),A=C?_r(m,C):`${m} is a function
585
585
  `;l+=A}w=!0}let _=e.state.env.get(`BASH_ALIAS_${m}`);if(_!==void 0&&(a||!w)&&(i||(r?l+=`alias
586
586
  `:l+=`${m} is aliased to \`${z(_)}'
587
587
  `),w=!0,!a)||vs.has(m)&&(a||!w)&&(i||(r?l+=`keyword
588
588
  `:l+=`${m} is a shell keyword
589
589
  `),w=!0,!a))continue;if(!a&&$&&!w){if(!i)if(r)l+=`function
590
- `;else{let C=e.state.functions.get(m),A=C?Ar(m,C):`${m} is a function
590
+ `;else{let C=e.state.functions.get(m),A=C?_r(m,C):`${m} is a function
591
591
  `;l+=A}w=!0;continue}if(!(Ke.has(m)&&(a||!w)&&(i||(r?l+=`builtin
592
592
  `:l+=`${m} is a shell builtin
593
593
  `),w=!0,!a))){if(a){let C=await n(m);for(let A of C)i?l+=`${A}
@@ -597,12 +597,12 @@ ${Ut}`;if(e.state.options.posix)throw new we(1,p,E(r));return P(r)}return Zs(e,t
597
597
  `:r?l+=`file
598
598
  `:l+=`${m} is ${C}
599
599
  `,h=!0,w=!0)}if(!w&&(g=!0,!r&&!i)){let C=!0;if(m.includes("/")){let A=e.fs.resolvePath(e.state.cwd,m);await e.fs.exists(A)&&(C=!1)}C&&(f+=`bash: type: ${m}: not found
600
- `)}}}return i?d=g&&!h?1:0:d=g?1:0,T(E(l),E(f),d)}function Ar(e,t){let s;return t.body.type==="Group"?s=t.body.body.map(r=>lt(r)).join("; "):s=lt(t.body),`${e} is a function
600
+ `)}}}return i?d=g&&!h?1:0:d=g?1:0,T(E(l),E(f),d)}function _r(e,t){let s;return t.body.type==="Group"?s=t.body.body.map(r=>lt(r)).join("; "):s=lt(t.body),`${e} is a function
601
601
  ${e} ()
602
602
  {
603
603
  ${s}
604
604
  }
605
- `}function lt(e){if(Array.isArray(e))return e.map(t=>lt(t)).join("; ");if(e.type==="Statement"){let t=[];for(let s=0;s<e.pipelines.length;s++){let n=e.pipelines[s];t.push(po(n)),e.operators[s]&&t.push(e.operators[s])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,s=[];t.name&&s.push(_r(t.name));for(let n of t.args)s.push(_r(n));return s.join(" ")}return e.type==="Group"?`{ ${e.body.map(n=>lt(n)).join("; ")}; }`:"..."}function po(e){let t=e.commands.map(s=>lt(s));return(e.negated?"! ":"")+t.join(" | ")}function _r(e){let t="";for(let s of e.parts)s.type==="Literal"?t+=s.value:s.type==="DoubleQuoted"?t+=`"${s.parts.map(n=>Pr(n)).join("")}"`:s.type==="SingleQuoted"?t+=`'${s.value}'`:t+=Pr(s);return t}function Pr(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function kr(e,t,s,n){let r="",i="",o=0;for(let a of t){if(!a){o=1;continue}let c=e.state.env.get(`BASH_ALIAS_${a}`);if(c!==void 0)n?r+=`${a} is an alias for "${z(c)}"
605
+ `}function lt(e){if(Array.isArray(e))return e.map(t=>lt(t)).join("; ");if(e.type==="Statement"){let t=[];for(let s=0;s<e.pipelines.length;s++){let n=e.pipelines[s];t.push(mo(n)),e.operators[s]&&t.push(e.operators[s])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,s=[];t.name&&s.push(Pr(t.name));for(let n of t.args)s.push(Pr(n));return s.join(" ")}return e.type==="Group"?`{ ${e.body.map(n=>lt(n)).join("; ")}; }`:"..."}function mo(e){let t=e.commands.map(s=>lt(s));return(e.negated?"! ":"")+t.join(" | ")}function Pr(e){let t="";for(let s of e.parts)s.type==="Literal"?t+=s.value:s.type==="DoubleQuoted"?t+=`"${s.parts.map(n=>Cr(n)).join("")}"`:s.type==="SingleQuoted"?t+=`'${s.value}'`:t+=Cr(s);return t}function Cr(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function Nr(e,t,s,n){let r="",i="",o=0;for(let a of t){if(!a){o=1;continue}let c=e.state.env.get(`BASH_ALIAS_${a}`);if(c!==void 0)n?r+=`${a} is an alias for "${z(c)}"
606
606
  `:r+=`alias ${a}='${z(c)}'
607
607
  `;else if(vs.has(a))n?r+=`${a} is a shell keyword
608
608
  `:r+=`${a}
@@ -616,73 +616,73 @@ ${e} ()
616
616
  `),o=1)}else if(e.commands.has(a)){let l=O(e.state.env,"PATH","/usr/bin:/bin").split(":"),f=null;for(let d of l){if(!d)continue;let h=`${d}/${a}`;try{let g=await e.fs.stat(h);if(!g.isDirectory&&(g.mode&73)!==0){f=h;break}}catch{}}f||(f=`/usr/bin/${a}`),n?r+=`${a} is ${f}
617
617
  `:r+=`${f}
618
618
  `}else n&&(i+=`${a}: not found
619
- `),o=1}return T(E(r),E(i),o)}async function Nr(e,t){if(t.includes("/")){let r=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(r)){try{let i=await e.fs.stat(r);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let n=O(e.state.env,"PATH","/usr/bin:/bin").split(":");for(let r of n){if(!r)continue;let o=`${r.startsWith("/")?r:e.fs.resolvePath(e.state.cwd,r)}/${t}`;if(await e.fs.exists(o)){try{if((await e.fs.stat(o)).isDirectory)continue}catch{continue}return`${r}/${t}`}}if(e.commands.has(t)){for(let r of n)if(r==="/usr/bin"||r==="/bin")return`${r}/${t}`;return`/usr/bin/${t}`}return null}async function Or(e,t,s,n,r,i,o,a){let{ctx:c,runCommand:u}=e,l=tt(s);if(c.coverage&&Ke.has(t)&&c.coverage.hit(`bash:builtin:${t}`),t==="export")return Vs(c,l);if(t==="unset")return Js(c,l);if(t==="exit")return Ws(c,l);if(t==="local")return Hs(c,l);if(t==="set")return Ys(c,l);if(t==="break")return ds(c,l);if(t==="continue")return _s(c,l);if(t==="return")return qs(c,l);if(t==="eval"&&c.state.options.posix)return jt(c,l,r);if(t==="shift")return Ks(c,l);if(t==="getopts")return Ht(c,l);if(t==="compgen")return Es(c,l);if(t==="complete")return $s(c,l);if(t==="compopt")return As(c,l);if(t==="pushd")return await Ls(c,l);if(t==="popd")return Ms(c,l);if(t==="dirs")return Fs(c,l);if(t==="source"||t===".")return Xs(c,l);if(t==="read")return Gs(c,l,r,a);if(t==="mapfile"||t==="readarray")return Us(c,l,r);if(t==="declare"||t==="typeset")return Ds(c,l);if(t==="readonly")return Is(c,l);if(!i){let f=c.state.functions.get(t);if(f)return zt(c,f,l,r)}if(t==="eval")return jt(c,l,r);if(t==="cd")return await hs(c,l);if(t===":"||t==="true")return V;if(t==="false")return X(!1);if(t==="let")return js(c,l);if(t==="command")return mo(e,l,r);if(t==="builtin")return yo(e,l,r);if(t==="shopt")return Sr(c,l);if(t==="exec"){if(s.length===0)return V;let[f,...d]=s;return u(z(f),d,[],r,!1,!1,-1)}if(t==="wait")return V;if(t==="type")return await Cr(c,l,f=>Nr(c,f),f=>qt(c,f));if(t==="hash")return zs(c,l);if(t==="help")return Bs(c,l);if(t==="["||t==="test"){let f=l;if(t==="["){if(l[l.length-1]!=="]")return P("[: missing `]'\n",2);f=l.slice(0,-1)}return it(c,f)}return null}async function mo(e,t,s){let{ctx:n,runCommand:r}=e;if(t.length===0)return V;let i=!1,o=!1,a=!1,c=t;for(;c.length>0&&c[0].startsWith("-");){let f=c[0];if(f==="--"){c=c.slice(1);break}for(let d of f.slice(1))d==="p"?i=!0:d==="V"?o=!0:d==="v"&&(a=!0);c=c.slice(1)}if(c.length===0)return V;if(a||o)return await kr(n,c,a,o);let[u,...l]=c;return r(u,l.map(f=>E(f)),[],s,!0,i,-1)}async function yo(e,t,s){let{runCommand:n}=e;if(t.length===0)return V;let r=t;if(r[0]==="--"&&(r=r.slice(1),r.length===0))return V;let i=r[0];if(!Ke.has(i))return P(`bash: builtin: ${i}: not a shell builtin
620
- `);let[,...o]=r;return n(i,o.map(a=>E(a)),[],s,!0,!1,-1)}async function xr(e,t,s,n,r){let{ctx:i,buildExportedEnv:o,executeUserScript:a}=e,u=await $r(i,t,r?"/usr/bin:/bin":void 0);if(!u)return Wn(t)?P(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
619
+ `),o=1}return T(E(r),E(i),o)}async function Or(e,t){if(t.includes("/")){let r=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(r)){try{let i=await e.fs.stat(r);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let n=O(e.state.env,"PATH","/usr/bin:/bin").split(":");for(let r of n){if(!r)continue;let o=`${r.startsWith("/")?r:e.fs.resolvePath(e.state.cwd,r)}/${t}`;if(await e.fs.exists(o)){try{if((await e.fs.stat(o)).isDirectory)continue}catch{continue}return`${r}/${t}`}}if(e.commands.has(t)){for(let r of n)if(r==="/usr/bin"||r==="/bin")return`${r}/${t}`;return`/usr/bin/${t}`}return null}async function xr(e,t,s,n,r,i,o,a){let{ctx:c,runCommand:u}=e,l=tt(s);if(c.coverage&&Ke.has(t)&&c.coverage.hit(`bash:builtin:${t}`),t==="export")return Vs(c,l);if(t==="unset")return Js(c,l);if(t==="exit")return Ws(c,l);if(t==="local")return Hs(c,l);if(t==="set")return Ys(c,l);if(t==="break")return ds(c,l);if(t==="continue")return _s(c,l);if(t==="return")return qs(c,l);if(t==="eval"&&c.state.options.posix)return jt(c,l,r);if(t==="shift")return Ks(c,l);if(t==="getopts")return Ht(c,l);if(t==="compgen")return Es(c,l);if(t==="complete")return $s(c,l);if(t==="compopt")return As(c,l);if(t==="pushd")return await Ls(c,l);if(t==="popd")return Ms(c,l);if(t==="dirs")return Fs(c,l);if(t==="source"||t===".")return Xs(c,l);if(t==="read")return Gs(c,l,r,a);if(t==="mapfile"||t==="readarray")return Us(c,l,r);if(t==="declare"||t==="typeset")return Ds(c,l);if(t==="readonly")return Is(c,l);if(!i){let f=c.state.functions.get(t);if(f)return zt(c,f,l,r)}if(t==="eval")return jt(c,l,r);if(t==="cd")return await hs(c,l);if(t===":"||t==="true")return V;if(t==="false")return X(!1);if(t==="let")return js(c,l);if(t==="command")return yo(e,l,r);if(t==="builtin")return go(e,l,r);if(t==="shopt")return $r(c,l);if(t==="exec"){if(s.length===0)return V;let[f,...d]=s;return u(z(f),d,[],r,!1,!1,-1)}if(t==="wait")return V;if(t==="type")return await kr(c,l,f=>Or(c,f),f=>qt(c,f));if(t==="hash")return zs(c,l);if(t==="help")return Bs(c,l);if(t==="["||t==="test"){let f=l;if(t==="["){if(l[l.length-1]!=="]")return P("[: missing `]'\n",2);f=l.slice(0,-1)}return it(c,f)}return null}async function yo(e,t,s){let{ctx:n,runCommand:r}=e;if(t.length===0)return V;let i=!1,o=!1,a=!1,c=t;for(;c.length>0&&c[0].startsWith("-");){let f=c[0];if(f==="--"){c=c.slice(1);break}for(let d of f.slice(1))d==="p"?i=!0:d==="V"?o=!0:d==="v"&&(a=!0);c=c.slice(1)}if(c.length===0)return V;if(a||o)return await Nr(n,c,a,o);let[u,...l]=c;return r(u,l.map(f=>E(f)),[],s,!0,i,-1)}async function go(e,t,s){let{runCommand:n}=e;if(t.length===0)return V;let r=t;if(r[0]==="--"&&(r=r.slice(1),r.length===0))return V;let i=r[0];if(!Ke.has(i))return P(`bash: builtin: ${i}: not a shell builtin
620
+ `);let[,...o]=r;return n(i,o.map(a=>E(a)),[],s,!0,!1,-1)}async function Tr(e,t,s,n,r){let{ctx:i,buildExportedEnv:o,executeUserScript:a}=e,u=await Ar(i,t,r?"/usr/bin:/bin":void 0);if(!u)return Vn(t)?P(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
621
621
  `,127):P(`bash: ${t}: command not found
622
622
  `,127);if("error"in u)return u.error==="permission_denied"?P(`bash: ${t}: Permission denied
623
623
  `,126):P(`bash: ${t}: No such file or directory
624
624
  `,127);if("script"in u)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u.path)),await a(u.path,s,n);let{cmd:l,path:f}=u;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=je(n)?i.state.groupStdin??p:n,h=o(),g={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,coverage:i.coverage};try{return await l.execute(s,g)}catch(m){if(m instanceof oe)throw m;return P(`${t}: ${be(m)}
625
625
  `)}}async function tn(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let n=p,r=p,i=0;try{for(let o of t){let a=await e.executeStatement(o);n=N(n,a.stdout),r=N(r,a.stderr),i=a.exitCode}}finally{e.state.inCondition=s}return{stdout:n,stderr:r,exitCode:i}}function ct(e,t,s,n){if(e instanceof me)return t=N(t,e.stdout),s=N(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 ye)return t=N(t,e.stdout),s=N(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 ce||e instanceof ve||e instanceof G||e instanceof oe)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let r=be(e);return{action:"error",stdout:t,stderr:N(s,E(`${r}
626
626
  `)),exitCode:1}}async function Zt(e,t,s=p,n=p){let r=s,i=n,o=0;try{for(let a of t){let c=await e.executeStatement(a);r=N(r,c.stdout),i=N(i,c.stderr),o=c.exitCode}}catch(a){if(wt(a)||a instanceof ve||a instanceof G||a instanceof oe||a instanceof Te)throw a.prependOutput(r,i),a;return{stdout:r,stderr:N(i,E(`${be(a)}
627
- `)),exitCode:1}}return{stdout:r,stderr:i,exitCode:o}}async function Tr(e,t){let s=p,n=p;for(let r of t.clauses){let i=await tn(e,r.condition);if(s=N(s,i.stdout),n=N(n,i.stderr),i.exitCode===0)return Zt(e,r.body,s,n)}return t.elseBody?Zt(e,t.elseBody,s,n):{stdout:s,stderr:n,exitCode:0}}async function Dr(e,t){let s=await Ne(e,t.redirections);if(s)return s;let n=p,r=p,i=0,o=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return P(`bash: \`${t.variable}': not a valid identifier
628
- `);let a=[];if(t.words===null)a=O(e.state.env,"@","").split(" ").filter(Boolean);else if(t.words.length===0)a=[];else try{for(let u of t.words){let l=await Ce(e,u);a.push(...l.values)}}catch(u){if(u instanceof vt)return{stdout:p,stderr:u.stderr,exitCode:1};throw u}e.state.loopDepth++;try{for(let u of a){o++,o>e.limits.maxLoopIterations&&xe(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),v(e.state.env,t.variable,u);try{for(let l of t.body){let f=await e.executeStatement(l);n=N(n,f.stdout),r=N(r,f.stderr),i=f.exitCode}}catch(l){let f=ct(l,n,r,e.state.loopDepth);if(n=f.stdout,r=f.stderr,f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error"){let d=T(n,r,f.exitCode??1);return Z(e,d,t.redirections)}throw f.error}}}finally{e.state.loopDepth--}let c=T(n,r,i);return Z(e,c,t.redirections)}async function Ir(e,t){let s=await Ne(e,t.redirections);if(s)return s;let n=t.line;n!==void 0&&(e.state.currentLine=n);let r=p,i=p,o=0,a=0;t.init&&await q(e,t.init.expression),e.state.loopDepth++;try{for(;a++,a>e.limits.maxLoopIterations&&xe(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,i),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await q(e,t.condition.expression)===0));){try{for(let u of t.body){let l=await e.executeStatement(u);r=N(r,l.stdout),i=N(i,l.stderr),o=l.exitCode}}catch(u){let l=ct(u,r,i,e.state.loopDepth);if(r=l.stdout,i=l.stderr,l.action==="break")break;if(l.action==="continue"){t.update&&await q(e,t.update.expression);continue}if(l.action==="error"){let f=T(r,i,l.exitCode??1);return Z(e,f,t.redirections)}throw l.error}t.update&&await q(e,t.update.expression)}}finally{e.state.loopDepth--}let c=T(r,i,o);return Z(e,c,t.redirections)}async function Rr(e,t,s=p){let n=p,r=p,i=0,o=0,a=s;for(let u of t.redirections)if((u.operator==="<<"||u.operator==="<<-")&&u.target.type==="HereDoc"){let l=u.target,f=await F(e,l.content);l.stripTabs&&(f=f.split(`
627
+ `)),exitCode:1}}return{stdout:r,stderr:i,exitCode:o}}async function Dr(e,t){let s=p,n=p;for(let r of t.clauses){let i=await tn(e,r.condition);if(s=N(s,i.stdout),n=N(n,i.stderr),i.exitCode===0)return Zt(e,r.body,s,n)}return t.elseBody?Zt(e,t.elseBody,s,n):{stdout:s,stderr:n,exitCode:0}}async function Ir(e,t){let s=await Ne(e,t.redirections);if(s)return s;let n=p,r=p,i=0,o=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return P(`bash: \`${t.variable}': not a valid identifier
628
+ `);let a=[];if(t.words===null)a=O(e.state.env,"@","").split(" ").filter(Boolean);else if(t.words.length===0)a=[];else try{for(let u of t.words){let l=await Ce(e,u);a.push(...l.values)}}catch(u){if(u instanceof vt)return{stdout:p,stderr:u.stderr,exitCode:1};throw u}e.state.loopDepth++;try{for(let u of a){o++,o>e.limits.maxLoopIterations&&xe(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),v(e.state.env,t.variable,u);try{for(let l of t.body){let f=await e.executeStatement(l);n=N(n,f.stdout),r=N(r,f.stderr),i=f.exitCode}}catch(l){let f=ct(l,n,r,e.state.loopDepth);if(n=f.stdout,r=f.stderr,f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error"){let d=T(n,r,f.exitCode??1);return Z(e,d,t.redirections)}throw f.error}}}finally{e.state.loopDepth--}let c=T(n,r,i);return Z(e,c,t.redirections)}async function Rr(e,t){let s=await Ne(e,t.redirections);if(s)return s;let n=t.line;n!==void 0&&(e.state.currentLine=n);let r=p,i=p,o=0,a=0;t.init&&await q(e,t.init.expression),e.state.loopDepth++;try{for(;a++,a>e.limits.maxLoopIterations&&xe(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,i),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await q(e,t.condition.expression)===0));){try{for(let u of t.body){let l=await e.executeStatement(u);r=N(r,l.stdout),i=N(i,l.stderr),o=l.exitCode}}catch(u){let l=ct(u,r,i,e.state.loopDepth);if(r=l.stdout,i=l.stderr,l.action==="break")break;if(l.action==="continue"){t.update&&await q(e,t.update.expression);continue}if(l.action==="error"){let f=T(r,i,l.exitCode??1);return Z(e,f,t.redirections)}throw l.error}t.update&&await q(e,t.update.expression)}}finally{e.state.loopDepth--}let c=T(r,i,o);return Z(e,c,t.redirections)}async function Lr(e,t,s=p){let n=p,r=p,i=0,o=0,a=s;for(let u of t.redirections)if((u.operator==="<<"||u.operator==="<<-")&&u.target.type==="HereDoc"){let l=u.target,f=await F(e,l.content);l.stripTabs&&(f=f.split(`
629
629
  `).map(d=>d.replace(/^\t+/,"")).join(`
630
630
  `)),a=E(f)}else if(u.operator==="<<<"&&u.target.type==="Word")a=E(`${await F(e,u.target)}
631
631
  `);else if(u.operator==="<"&&u.target.type==="Word")try{let l=await F(e,u.target),f=e.fs.resolvePath(e.state.cwd,l);a=E(await e.fs.readFile(f))}catch{let l=await F(e,u.target);return P(`bash: ${l}: No such file or directory
632
- `)}let c=e.state.groupStdin;a.length>0&&(e.state.groupStdin=a),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&xe(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r);let u=0,l=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let g=await e.executeStatement(h);n=N(n,g.stdout),r=N(r,g.stderr),u=g.exitCode}}catch(h){if(h instanceof me){if(n=N(n,h.stdout),r=N(r,h.stderr),h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;l=!0}else if(h instanceof ye){if(n=N(n,h.stdout),r=N(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 throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if(l)break;if(!f){if(u!==0)break;try{for(let h of t.body){let g=await e.executeStatement(h);n=N(n,g.stdout),r=N(r,g.stderr),i=g.exitCode}}catch(h){let g=ct(h,n,r,e.state.loopDepth);if(n=g.stdout,r=g.stderr,g.action==="break")break;if(g.action==="continue")continue;if(g.action==="error")return T(n,r,g.exitCode??1);throw g.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=c}return T(n,r,i)}async function Lr(e,t){let s=p,n=p,r=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&xe(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,n);let o=await tn(e,t.condition);if(s=N(s,o.stdout),n=N(n,o.stderr),o.exitCode===0)break;try{for(let a of t.body){let c=await e.executeStatement(a);s=N(s,c.stdout),n=N(n,c.stderr),r=c.exitCode}}catch(a){let c=ct(a,s,n,e.state.loopDepth);if(s=c.stdout,n=c.stderr,c.action==="break")break;if(c.action==="continue")continue;if(c.action==="error")return T(s,n,c.exitCode??1);throw c.error}}}finally{e.state.loopDepth--}return T(s,n,r)}async function Mr(e,t){let s=await Ne(e,t.redirections);if(s)return s;let n=p,r=p,i=0,o=await F(e,t.word),a=!1;for(let u=0;u<t.items.length;u++){let l=t.items[u],f=a;if(!a)for(let d of l.patterns){let h=await F(e,d);Sn(d)&&(h=bn(h));let g=e.state.shoptOptions.nocasematch,m=e.state.shoptOptions.extglob;if(Ze(o,h,g,m)){f=!0;break}}if(f){let d=await Zt(e,l.body,n,r);if(n=d.stdout,r=d.stderr,i=d.exitCode,l.terminator===";;")break;l.terminator===";&"?a=!0:a=!1}else a=!1}let c=T(n,r,i);return Z(e,c,t.redirections)}function sn(e,t){if(e.parts.length!==1)return!1;let s=e.parts[0];return s.type!=="Literal"?!1:t.includes(s.value)}function Fr(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),c=a.indexOf(":");if(c===-1)return null;let u=Number.parseInt(a.slice(0,c),10);if(Number.isNaN(u)||u<0)return null;let l=a.slice(c+1);return{path:i,position:u,content:l}}var Wr="+ ";async function Vr(e){let t=e.state.env.get("PS4");if(t===void 0)return Wr;let s=z(t);if(s==="")return"";try{let r=new H().parseWordFromString(s,!1,!1);return await F(e,r)}catch{return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${s}: bad substitution
633
- `,s||Wr}}function go(e){return e.map(t=>vo(t)).join(" ")}function vo(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),n=e.includes(`
632
+ `)}let c=e.state.groupStdin;a.length>0&&(e.state.groupStdin=a),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&xe(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r);let u=0,l=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let g=await e.executeStatement(h);n=N(n,g.stdout),r=N(r,g.stderr),u=g.exitCode}}catch(h){if(h instanceof me){if(n=N(n,h.stdout),r=N(r,h.stderr),h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;l=!0}else if(h instanceof ye){if(n=N(n,h.stdout),r=N(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 throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if(l)break;if(!f){if(u!==0)break;try{for(let h of t.body){let g=await e.executeStatement(h);n=N(n,g.stdout),r=N(r,g.stderr),i=g.exitCode}}catch(h){let g=ct(h,n,r,e.state.loopDepth);if(n=g.stdout,r=g.stderr,g.action==="break")break;if(g.action==="continue")continue;if(g.action==="error")return T(n,r,g.exitCode??1);throw g.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=c}return T(n,r,i)}async function Mr(e,t){let s=p,n=p,r=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&xe(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,n);let o=await tn(e,t.condition);if(s=N(s,o.stdout),n=N(n,o.stderr),o.exitCode===0)break;try{for(let a of t.body){let c=await e.executeStatement(a);s=N(s,c.stdout),n=N(n,c.stderr),r=c.exitCode}}catch(a){let c=ct(a,s,n,e.state.loopDepth);if(s=c.stdout,n=c.stderr,c.action==="break")break;if(c.action==="continue")continue;if(c.action==="error")return T(s,n,c.exitCode??1);throw c.error}}}finally{e.state.loopDepth--}return T(s,n,r)}async function Fr(e,t){let s=await Ne(e,t.redirections);if(s)return s;let n=p,r=p,i=0,o=await F(e,t.word),a=!1;for(let u=0;u<t.items.length;u++){let l=t.items[u],f=a;if(!a)for(let d of l.patterns){let h=await F(e,d);$n(d)&&(h=En(h));let g=e.state.shoptOptions.nocasematch,m=e.state.shoptOptions.extglob;if(Ze(o,h,g,m)){f=!0;break}}if(f){let d=await Zt(e,l.body,n,r);if(n=d.stdout,r=d.stderr,i=d.exitCode,l.terminator===";;")break;l.terminator===";&"?a=!0:a=!1}else a=!1}let c=T(n,r,i);return Z(e,c,t.redirections)}function sn(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),c=a.indexOf(":");if(c===-1)return null;let u=Number.parseInt(a.slice(0,c),10);if(Number.isNaN(u)||u<0)return null;let l=a.slice(c+1);return{path:i,position:u,content:l}}var Vr="+ ";async function zr(e){let t=e.state.env.get("PS4");if(t===void 0)return Vr;let s=z(t);if(s==="")return"";try{let r=new H().parseWordFromString(s,!1,!1);return await F(e,r)}catch{return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${s}: bad substitution
633
+ `,s||Vr}}function vo(e){return e.map(t=>wo(t)).join(" ")}function wo(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),n=e.includes(`
634
634
  `),r=e.includes(" "),i=e.includes("\\"),o=e.includes("'");if(s||n||r||i){let c="";for(let u of e){let l=u.charCodeAt(0);u===`
635
- `?c+="\\n":u===" "?c+="\\t":u==="\\"?c+="\\\\":u==="'"?c+="'":u==='"'?c+='"':l<32||l===127?l<256?c+=`\\x${l.toString(16).padStart(2,"0")}`:c+=`\\u${l.toString(16).padStart(4,"0")}`:c+=u}return`$'${c}'`}return o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function zr(e,t,s){if(!e.state.options.xtrace)return"";let n=await Vr(e),r=[t,...s],i=go(r);return`${n}${i}
636
- `}async function Br(e,t,s){return e.state.options.xtrace?`${await Vr(e)}${t}=${s}
637
- `:""}async function jr(e,t,s){let n=t.timed?performance.now():0,r=p,i=V,o=0,a=[],c=t.commands.length>1,u=e.state.lastArg;for(let f=0;f<t.commands.length;f++){let d=t.commands[f],h=f===t.commands.length-1,g=f===0;c&&(e.state.lastArg=E(""),g||(e.state.groupStdin=void 0));let w=c&&(!h||!e.state.shoptOptions.lastpipe)?new Map(e.state.env):null,$;try{$=await s(d,r)}catch(_){if(_ instanceof gt)$={stdout:_.stdout,stderr:_.stderr,exitCode:1};else if(_ instanceof G&&t.commands.length>1)$={stdout:_.stdout,stderr:_.stderr,exitCode:_.exitCode};else if(_ instanceof ve&&t.commands.length>1)$={stdout:_.stdout,stderr:_.stderr,exitCode:_.exitCode};else throw w&&(e.state.env=w),_}w&&(e.state.env=w),a.push($.exitCode),$.exitCode!==0&&(o=$.exitCode),h?i=$:t.pipeStderr?.[f]??!1?(r=N($.stderr,$.stdout),i={stdout:p,stderr:p,exitCode:$.exitCode}):(r=$.stdout,i={stdout:p,stderr:$.stderr,exitCode:$.exitCode})}if(t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let f of e.state.env.keys())f.startsWith("PIPESTATUS_")&&e.state.env.delete(f);for(let f=0;f<a.length;f++)v(e.state.env,`PIPESTATUS_${f}`,String(a[f]));v(e.state.env,"PIPESTATUS__length",String(a.length))}if(e.state.options.pipefail&&o!==0&&(i={...i,exitCode:o}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let d=(performance.now()-n)/1e3,h=Math.floor(d/60),g=d%60,m;t.timePosix?m=`real ${d.toFixed(2)}
635
+ `?c+="\\n":u===" "?c+="\\t":u==="\\"?c+="\\\\":u==="'"?c+="'":u==='"'?c+='"':l<32||l===127?l<256?c+=`\\x${l.toString(16).padStart(2,"0")}`:c+=`\\u${l.toString(16).padStart(4,"0")}`:c+=u}return`$'${c}'`}return o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function Br(e,t,s){if(!e.state.options.xtrace)return"";let n=await zr(e),r=[t,...s],i=vo(r);return`${n}${i}
636
+ `}async function jr(e,t,s){return e.state.options.xtrace?`${await zr(e)}${t}=${s}
637
+ `:""}async function Hr(e,t,s){let n=t.timed?performance.now():0,r=p,i=V,o=0,a=[],c=t.commands.length>1,u=e.state.lastArg;for(let f=0;f<t.commands.length;f++){let d=t.commands[f],h=f===t.commands.length-1,g=f===0;c&&(e.state.lastArg=E(""),g||(e.state.groupStdin=void 0));let w=c&&(!h||!e.state.shoptOptions.lastpipe)?new Map(e.state.env):null,$;try{$=await s(d,r)}catch(_){if(_ instanceof gt)$={stdout:_.stdout,stderr:_.stderr,exitCode:1};else if(_ instanceof G&&t.commands.length>1)$={stdout:_.stdout,stderr:_.stderr,exitCode:_.exitCode};else if(_ instanceof ve&&t.commands.length>1)$={stdout:_.stdout,stderr:_.stderr,exitCode:_.exitCode};else throw w&&(e.state.env=w),_}w&&(e.state.env=w),a.push($.exitCode),$.exitCode!==0&&(o=$.exitCode),h?i=$:t.pipeStderr?.[f]??!1?(r=N($.stderr,$.stdout),i={stdout:p,stderr:p,exitCode:$.exitCode}):(r=$.stdout,i={stdout:p,stderr:$.stderr,exitCode:$.exitCode})}if(t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let f of e.state.env.keys())f.startsWith("PIPESTATUS_")&&e.state.env.delete(f);for(let f=0;f<a.length;f++)v(e.state.env,`PIPESTATUS_${f}`,String(a[f]));v(e.state.env,"PIPESTATUS__length",String(a.length))}if(e.state.options.pipefail&&o!==0&&(i={...i,exitCode:o}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let d=(performance.now()-n)/1e3,h=Math.floor(d/60),g=d%60,m;t.timePosix?m=`real ${d.toFixed(2)}
638
638
  user 0.00
639
639
  sys 0.00
640
640
  `:m=`
641
641
  real ${`${h}m${g.toFixed(3)}s`}
642
642
  user 0m0.000s
643
643
  sys 0m0.000s
644
- `,i={...i,stderr:N(i.stderr,E(m))}}return c&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=u),i}async function Hr(e,t){let s=new Map,n="";for(let r of t.assignments){let i=r.name;if(r.array){let f=await wo(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 F(e,r.value):"",a=r.value?await He(e,r.value):p;if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:P(`bash: ${i}: bad array subscript
645
- `)};let u=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(u){let f=await Ao(e,t,u[1],u[2],o,r.append,s);if(f.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:f.error};if(f.continueToNext)continue}let l=await Po(e,t,i,o,r.append,s,a);if(l.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:l.error};n+=l.xtraceOutput,l.continueToNext}return{continueToNext:!1,xtraceOutput:n,tempAssignments:s}}async function wo(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
646
- `)};if(ue(e,s)){let l=vn(e,s);if(l===void 0||l==="")throw new G(1,p,p);let f=Pe(e,s);if(f&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(f))return{continueToNext:!1,xtraceOutput:"",error:P(`bash: ${s}: cannot assign list to array member
644
+ `,i={...i,stderr:N(i.stderr,E(m))}}return c&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=u),i}async function Ur(e,t){let s=new Map,n="";for(let r of t.assignments){let i=r.name;if(r.array){let f=await bo(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 F(e,r.value):"",a=r.value?await He(e,r.value):p;if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:P(`bash: ${i}: bad array subscript
645
+ `)};let u=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(u){let f=await _o(e,t,u[1],u[2],o,r.append,s);if(f.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:f.error};if(f.continueToNext)continue}let l=await Co(e,t,i,o,r.append,s,a);if(l.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:l.error};n+=l.xtraceOutput,l.continueToNext}return{continueToNext:!1,xtraceOutput:n,tempAssignments:s}}async function bo(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
646
+ `)};if(ue(e,s)){let l=wn(e,s);if(l===void 0||l==="")throw new G(1,p,p);let f=Pe(e,s);if(f&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(f))return{continueToNext:!1,xtraceOutput:"",error:P(`bash: ${s}: cannot assign list to array member
647
647
  `)}}if(We(e,s)){if(t.name)return o+=`bash: ${s}: readonly variable
648
- `,{continueToNext:!0,xtraceOutput:o};let l=te(e,s);if(l)return{continueToNext:!1,xtraceOutput:"",error:l}}let a=e.state.associativeArrays?.has(s),c=bo(n),u=()=>{let l=`${s}_`;for(let f of e.state.env.keys())f.startsWith(l)&&!f.includes("__")&&e.state.env.delete(f);e.state.env.delete(s)};if(a&&c?await Eo(e,t,s,n,r,u,l=>{o+=l}):c?await So(e,s,n,r,u):await $o(e,s,n,r,u),t.name){i.set(s,e.state.env.get(s));let f=`(${n.map(d=>Et(d)).join(" ")})`;v(e.state.env,s,f)}return{continueToNext:!0,xtraceOutput:o}}function bo(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 Eo(e,t,s,n,r,i,o){let a=[];for(let c of n){let u=es(c);if(u){let{key:l,valueParts:f,append:d}=u,h;f.length>0?h=await F(e,{type:"Word",parts:f}):h="",h=Y(e,h),a.push({type:"keyed",key:l,value:h,append:d})}else{let l=await F(e,c);a.push({type:"invalid",expandedValue:l})}}r||i();for(let c of a)if(c.type==="keyed")if(c.append){let u=O(e.state.env,`${s}_${c.key}`,"");v(e.state.env,`${s}_${c.key}`,u+c.value)}else v(e.state.env,`${s}_${c.key}`,c.value);else{let u=t.line??e.state.currentLine??1;o(`bash: line ${u}: ${s}: ${c.expandedValue}: must use subscript when assigning associative array
649
- `)}}async function So(e,t,s,n,r){let i=[];for(let a of s){let c=es(a);if(c){let{key:u,valueParts:l,append:f}=c,d;l.length>0?d=await F(e,{type:"Word",parts:l}):d="",d=Y(e,d),i.push({type:"keyed",indexExpr:u,value:d,append:f})}else{let u=await Ce(e,a);i.push({type:"non-keyed",values:u.values})}}n||r();let o=0;for(let a of i)if(a.type==="keyed"){let c;try{let u=new H,l=Q(u,a.indexExpr);c=await q(e,l.expression,!1)}catch{if(/^-?\d+$/.test(a.indexExpr))c=Number.parseInt(a.indexExpr,10);else{let u=O(e.state.env,a.indexExpr);c=u?Number.parseInt(u,10):0,Number.isNaN(c)&&(c=0)}}if(a.append){let u=O(e.state.env,`${t}_${c}`,"");v(e.state.env,`${t}_${c}`,u+a.value)}else v(e.state.env,`${t}_${c}`,a.value);o=c+1}else for(let c of a.values)v(e.state.env,`${t}_${o++}`,c)}async function $o(e,t,s,n,r){let i=[];for(let a of s){let c=await Ce(e,a);i.push(...c.values)}let o=0;if(n){let a=Se(e,t);if(a.length>0)o=Math.max(...a.map(([u])=>typeof u=="number"?u:0))+1;else{let c=e.state.env.get(t);c!==void 0&&(e.state.env.set(`${t}_0`,c),e.state.env.delete(t),o=1)}}else r();for(let a=0;a<i.length;a++)v(e.state.env,`${t}_${o+a}`,i[a]);n||v(e.state.env,`${t}__length`,String(i.length))}async function Ao(e,t,s,n,r,i,o){let a=s;if(ue(e,s)){let f=Pe(e,s);if(f&&f!==s){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:P(`bash: \`${f}': not a valid identifier
650
- `)};a=f}}if(We(e,a)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=te(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let c=e.state.associativeArrays?.has(a),u;if(c)u=await Ur(e,a,n);else{let f=await _o(e,a,n);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};u=`${a}_${f.index}`}let l=i?O(e.state.env,u)+r:r;if(t.name)o.set(u,e.state.env.get(u)),v(e.state.env,u,l);else{let f=Ye(e,a);if(f!==void 0&&f===e.state.callDepth&&e.state.localScopes.length>0){let d=e.state.localScopes[e.state.localScopes.length-1];d.has(u)||d.set(u,e.state.env.get(u))}v(e.state.env,u,l)}return{continueToNext:!0,xtraceOutput:""}}async function Ur(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 H().parseWordFromString(r,!0,!1);n=await F(e,o)}else if(s.includes("$")){let i=new H().parseWordFromString(s,!1,!1);n=await F(e,i)}else n=s;return`${t}_${n}`}async function _o(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 H,o=Q(i,n);r=await q(e,o.expression,!1)}catch(i){if(i instanceof Fe){let c=`bash: line ${e.state.currentLine}: ${s}: ${i.message}
648
+ `,{continueToNext:!0,xtraceOutput:o};let l=te(e,s);if(l)return{continueToNext:!1,xtraceOutput:"",error:l}}let a=e.state.associativeArrays?.has(s),c=Eo(n),u=()=>{let l=`${s}_`;for(let f of e.state.env.keys())f.startsWith(l)&&!f.includes("__")&&e.state.env.delete(f);e.state.env.delete(s)};if(a&&c?await So(e,t,s,n,r,u,l=>{o+=l}):c?await $o(e,s,n,r,u):await Ao(e,s,n,r,u),t.name){i.set(s,e.state.env.get(s));let f=`(${n.map(d=>Et(d)).join(" ")})`;v(e.state.env,s,f)}return{continueToNext:!0,xtraceOutput:o}}function Eo(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 So(e,t,s,n,r,i,o){let a=[];for(let c of n){let u=es(c);if(u){let{key:l,valueParts:f,append:d}=u,h;f.length>0?h=await F(e,{type:"Word",parts:f}):h="",h=Y(e,h),a.push({type:"keyed",key:l,value:h,append:d})}else{let l=await F(e,c);a.push({type:"invalid",expandedValue:l})}}r||i();for(let c of a)if(c.type==="keyed")if(c.append){let u=O(e.state.env,`${s}_${c.key}`,"");v(e.state.env,`${s}_${c.key}`,u+c.value)}else v(e.state.env,`${s}_${c.key}`,c.value);else{let u=t.line??e.state.currentLine??1;o(`bash: line ${u}: ${s}: ${c.expandedValue}: must use subscript when assigning associative array
649
+ `)}}async function $o(e,t,s,n,r){let i=[];for(let a of s){let c=es(a);if(c){let{key:u,valueParts:l,append:f}=c,d;l.length>0?d=await F(e,{type:"Word",parts:l}):d="",d=Y(e,d),i.push({type:"keyed",indexExpr:u,value:d,append:f})}else{let u=await Ce(e,a);i.push({type:"non-keyed",values:u.values})}}n||r();let o=0;for(let a of i)if(a.type==="keyed"){let c;try{let u=new H,l=Q(u,a.indexExpr);c=await q(e,l.expression,!1)}catch{if(/^-?\d+$/.test(a.indexExpr))c=Number.parseInt(a.indexExpr,10);else{let u=O(e.state.env,a.indexExpr);c=u?Number.parseInt(u,10):0,Number.isNaN(c)&&(c=0)}}if(a.append){let u=O(e.state.env,`${t}_${c}`,"");v(e.state.env,`${t}_${c}`,u+a.value)}else v(e.state.env,`${t}_${c}`,a.value);o=c+1}else for(let c of a.values)v(e.state.env,`${t}_${o++}`,c)}async function Ao(e,t,s,n,r){let i=[];for(let a of s){let c=await Ce(e,a);i.push(...c.values)}let o=0;if(n){let a=Se(e,t);if(a.length>0)o=Math.max(...a.map(([u])=>typeof u=="number"?u:0))+1;else{let c=e.state.env.get(t);c!==void 0&&(e.state.env.set(`${t}_0`,c),e.state.env.delete(t),o=1)}}else r();for(let a=0;a<i.length;a++)v(e.state.env,`${t}_${o+a}`,i[a]);n||v(e.state.env,`${t}__length`,String(i.length))}async function _o(e,t,s,n,r,i,o){let a=s;if(ue(e,s)){let f=Pe(e,s);if(f&&f!==s){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:P(`bash: \`${f}': not a valid identifier
650
+ `)};a=f}}if(We(e,a)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=te(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let c=e.state.associativeArrays?.has(a),u;if(c)u=await Gr(e,a,n);else{let f=await Po(e,a,n);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};u=`${a}_${f.index}`}let l=i?O(e.state.env,u)+r:r;if(t.name)o.set(u,e.state.env.get(u)),v(e.state.env,u,l);else{let f=Ye(e,a);if(f!==void 0&&f===e.state.callDepth&&e.state.localScopes.length>0){let d=e.state.localScopes[e.state.localScopes.length-1];d.has(u)||d.set(u,e.state.env.get(u))}v(e.state.env,u,l)}return{continueToNext:!0,xtraceOutput:""}}async function Gr(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 H().parseWordFromString(r,!0,!1);n=await F(e,o)}else if(s.includes("$")){let i=new H().parseWordFromString(s,!1,!1);n=await F(e,i)}else n=s;return`${t}_${n}`}async function Po(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 H,o=Q(i,n);r=await q(e,o.expression,!1)}catch(i){if(i instanceof Fe){let c=`bash: line ${e.state.currentLine}: ${s}: ${i.message}
651
651
  `;if(i.fatal)throw new G(1,p,E(c));return{index:0,error:P(c)}}let o=O(e.state.env,s);r=o?Number.parseInt(o,10):0}Number.isNaN(r)&&(r=0)}if(r<0){let i=Se(e,t);if(i.length===0){let a=e.state.currentLine;return{index:0,error:P(`bash: line ${a}: ${t}[${s}]: bad array subscript
652
652
  `)}}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
653
- `)}}}return{index:r}}async function Po(e,t,s,n,r,i,o){let a="",c=s,u=null;if(ue(e,s)){let m=wn(e,s,n);if(m===void 0)return{continueToNext:!1,xtraceOutput:"",error:P(`bash: ${s}: circular name reference
653
+ `)}}}return{index:r}}async function Co(e,t,s,n,r,i,o){let a="",c=s,u=null;if(ue(e,s)){let m=bn(e,s,n);if(m===void 0)return{continueToNext:!1,xtraceOutput:"",error:P(`bash: ${s}: circular name reference
654
654
  `)};if(m===null)return{continueToNext:!0,xtraceOutput:""};c=m;let w=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);w&&(u={arrayName:w[1],subscriptExpr:w[2]},c=w[1])}if(We(e,c)){if(t.name)return a+=`bash: ${c}: readonly variable
655
- `,{continueToNext:!0,xtraceOutput:a};let m=te(e,c);if(m)return{continueToNext:!1,xtraceOutput:"",error:m}}let l,f=!!o&&!r&&!u;if(ot(e,c)){f=!1;try{let m=new H;if(r){let $=`(${O(e.state.env,c,"0")}) + (${n})`,_=Q(m,$);l=String(await q(e,_.expression))}else{let w=Q(m,n);l=String(await q(e,w.expression))}}catch{l="0"}}else{let{isArray:m}=await import("./chunks/expansion-7AYBVOIQ.js"),w=m(e,c);w&&(f=!1);let $=w?`${c}_0`:c;l=r?O(e.state.env,$)+n:n}let d=Qe(e,c,l);d!==l&&(f=!1),l=d,a+=await Br(e,c,l);let h=c;if(u)h=await Co(e,u);else{let{isArray:m}=await import("./chunks/expansion-7AYBVOIQ.js");m(e,c)&&(h=`${c}_0`,f=!1)}let g=f?()=>e.state.env.set(h,o):()=>v(e.state.env,h,l);return t.name?(i.set(h,e.state.env.get(h)),g()):(g(),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(c)),e.state.tempEnvBindings?.some(m=>m.has(c))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(c))),{continueToNext:!1,xtraceOutput:a}}async function Co(e,t){let{arrayName:s,subscriptExpr:n}=t;if(e.state.associativeArrays?.has(s))return Ur(e,s,n);let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else{try{let o=new H,a=Q(o,n);i=await q(e,a.expression,!1)}catch{let o=O(e.state.env,n);i=o?Number.parseInt(o,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let o=Se(e,s);o.length>0&&(i=Math.max(...o.map(c=>c[0]))+1+i)}return`${s}_${i}`}async function Gr(e,t,s,n){let r=await Ne(e,t.redirections);if(r)return r;let i=new Map(e.state.env),o=e.state.cwd,a={...e.state.options},c=new Map(e.state.functions),u=e.state.localScopes,l=e.state.localVarStack,f=e.state.localVarDepth,d=e.state.fullyUnsetLocals;if(e.state.localScopes=u.map(A=>new Map(A)),l){e.state.localVarStack=new Map;for(let[A,L]of l.entries())e.state.localVarStack.set(A,L.map(I=>({...I})))}f&&(e.state.localVarDepth=new Map(f)),d&&(e.state.fullyUnsetLocals=new Map(d));let h=e.state.loopDepth,g=e.state.parentHasLoopContext;e.state.parentHasLoopContext=h>0,e.state.loopDepth=0;let m=e.state.lastArg,w=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let $=e.state.groupStdin;je(s)||(e.state.groupStdin=s);let _=p,k=p,y=0,b=()=>{e.state.env=i,e.state.cwd=o,e.state.options=a,e.state.functions=c,e.state.localScopes=u,e.state.localVarStack=l,e.state.localVarDepth=f,e.state.fullyUnsetLocals=d,e.state.loopDepth=h,e.state.parentHasLoopContext=g,e.state.groupStdin=$,e.state.bashPid=w,e.state.lastArg=m};try{for(let A of t.body){let L=await n(A);_=N(_,L.stdout),k=N(k,L.stderr),y=L.exitCode}}catch(A){if(b(),A instanceof oe)throw A;if(A instanceof Te){_=N(_,A.stdout),k=N(k,A.stderr);let I=T(_,k,0);return Z(e,I,t.redirections)}if(A instanceof me||A instanceof ye){_=N(_,A.stdout),k=N(k,A.stderr);let I=T(_,k,0);return Z(e,I,t.redirections)}if(A instanceof G){_=N(_,A.stdout),k=N(k,A.stderr);let I=T(_,k,A.exitCode);return Z(e,I,t.redirections)}if(A instanceof ce){_=N(_,A.stdout),k=N(k,A.stderr);let I=T(_,k,A.exitCode);return Z(e,I,t.redirections)}if(A instanceof ve){let I=T(N(_,A.stdout),N(k,A.stderr),A.exitCode);return Z(e,I,t.redirections)}let L=T(_,N(k,E(`${be(A)}
656
- `)),1);return Z(e,L,t.redirections)}b();let C=T(_,k,y);return Z(e,C,t.redirections)}async function qr(e,t,s,n){let r=p,i=p,o=0,a=await Vt(e,t.redirections);if(a)return a;let c=s;for(let f of t.redirections)if((f.operator==="<<"||f.operator==="<<-")&&f.target.type==="HereDoc"){let d=f.target,h=await F(e,d.content);d.stripTabs&&(h=h.split(`
655
+ `,{continueToNext:!0,xtraceOutput:a};let m=te(e,c);if(m)return{continueToNext:!1,xtraceOutput:"",error:m}}let l,f=!!o&&!r&&!u;if(ot(e,c)){f=!1;try{let m=new H;if(r){let $=`(${O(e.state.env,c,"0")}) + (${n})`,_=Q(m,$);l=String(await q(e,_.expression))}else{let w=Q(m,n);l=String(await q(e,w.expression))}}catch{l="0"}}else{let{isArray:m}=await import("./chunks/expansion-7AYBVOIQ.js"),w=m(e,c);w&&(f=!1);let $=w?`${c}_0`:c;l=r?O(e.state.env,$)+n:n}let d=Qe(e,c,l);d!==l&&(f=!1),l=d,a+=await jr(e,c,l);let h=c;if(u)h=await ko(e,u);else{let{isArray:m}=await import("./chunks/expansion-7AYBVOIQ.js");m(e,c)&&(h=`${c}_0`,f=!1)}let g=f?()=>e.state.env.set(h,o):()=>v(e.state.env,h,l);return t.name?(i.set(h,e.state.env.get(h)),g()):(g(),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(c)),e.state.tempEnvBindings?.some(m=>m.has(c))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(c))),{continueToNext:!1,xtraceOutput:a}}async function ko(e,t){let{arrayName:s,subscriptExpr:n}=t;if(e.state.associativeArrays?.has(s))return Gr(e,s,n);let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else{try{let o=new H,a=Q(o,n);i=await q(e,a.expression,!1)}catch{let o=O(e.state.env,n);i=o?Number.parseInt(o,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let o=Se(e,s);o.length>0&&(i=Math.max(...o.map(c=>c[0]))+1+i)}return`${s}_${i}`}async function qr(e,t,s,n){let r=await Ne(e,t.redirections);if(r)return r;let i=new Map(e.state.env),o=e.state.cwd,a={...e.state.options},c=new Map(e.state.functions),u=e.state.localScopes,l=e.state.localVarStack,f=e.state.localVarDepth,d=e.state.fullyUnsetLocals;if(e.state.localScopes=u.map(A=>new Map(A)),l){e.state.localVarStack=new Map;for(let[A,L]of l.entries())e.state.localVarStack.set(A,L.map(I=>({...I})))}f&&(e.state.localVarDepth=new Map(f)),d&&(e.state.fullyUnsetLocals=new Map(d));let h=e.state.loopDepth,g=e.state.parentHasLoopContext;e.state.parentHasLoopContext=h>0,e.state.loopDepth=0;let m=e.state.lastArg,w=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let $=e.state.groupStdin;je(s)||(e.state.groupStdin=s);let _=p,k=p,y=0,b=()=>{e.state.env=i,e.state.cwd=o,e.state.options=a,e.state.functions=c,e.state.localScopes=u,e.state.localVarStack=l,e.state.localVarDepth=f,e.state.fullyUnsetLocals=d,e.state.loopDepth=h,e.state.parentHasLoopContext=g,e.state.groupStdin=$,e.state.bashPid=w,e.state.lastArg=m};try{for(let A of t.body){let L=await n(A);_=N(_,L.stdout),k=N(k,L.stderr),y=L.exitCode}}catch(A){if(b(),A instanceof oe)throw A;if(A instanceof Te){_=N(_,A.stdout),k=N(k,A.stderr);let I=T(_,k,0);return Z(e,I,t.redirections)}if(A instanceof me||A instanceof ye){_=N(_,A.stdout),k=N(k,A.stderr);let I=T(_,k,0);return Z(e,I,t.redirections)}if(A instanceof G){_=N(_,A.stdout),k=N(k,A.stderr);let I=T(_,k,A.exitCode);return Z(e,I,t.redirections)}if(A instanceof ce){_=N(_,A.stdout),k=N(k,A.stderr);let I=T(_,k,A.exitCode);return Z(e,I,t.redirections)}if(A instanceof ve){let I=T(N(_,A.stdout),N(k,A.stderr),A.exitCode);return Z(e,I,t.redirections)}let L=T(_,N(k,E(`${be(A)}
656
+ `)),1);return Z(e,L,t.redirections)}b();let C=T(_,k,y);return Z(e,C,t.redirections)}async function Zr(e,t,s,n){let r=p,i=p,o=0,a=await Vt(e,t.redirections);if(a)return a;let c=s;for(let f of t.redirections)if((f.operator==="<<"||f.operator==="<<-")&&f.target.type==="HereDoc"){let d=f.target,h=await F(e,d.content);d.stripTabs&&(h=h.split(`
657
657
  `).map(m=>m.replace(/^\t+/,"")).join(`
658
658
  `));let g=f.fd??0;g!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(g,h)):c=E(h)}else if(f.operator==="<<<"&&f.target.type==="Word")c=E(`${await F(e,f.target)}
659
659
  `);else if(f.operator==="<"&&f.target.type==="Word")try{let d=await F(e,f.target),h=e.fs.resolvePath(e.state.cwd,d);c=E(await e.fs.readFile(h))}catch{let d=await F(e,f.target);return P(`bash: ${d}: No such file or directory
660
660
  `)}let u=e.state.groupStdin;je(c)||(e.state.groupStdin=c);try{for(let f of t.body){let d=await n(f);r=N(r,d.stdout),i=N(i,d.stderr),o=d.exitCode}}catch(f){if(e.state.groupStdin=u,f instanceof oe)throw f;if(wt(f)||f instanceof ve||f instanceof G)throw f.prependOutput(r,i),f;return T(r,N(i,E(`${be(f)}
661
- `)),1)}e.state.groupStdin=u;let l=T(r,i,o);return Z(e,l,t.redirections)}async function Zr(e,t,s,n,r){let i;try{i=await e.fs.readFile(t)}catch{return P(`bash: ${t}: No such file or directory
661
+ `)),1)}e.state.groupStdin=u;let l=T(r,i,o);return Z(e,l,t.redirections)}async function Yr(e,t,s,n,r){let i;try{i=await e.fs.readFile(t)}catch{return P(`bash: ${t}: No such file or directory
662
662
  `,127)}if(i.startsWith("#!")){let w=i.indexOf(`
663
663
  `);w!==-1&&(i=i.slice(w+1))}let o=new Map(e.state.env),a=e.state.cwd,c={...e.state.options},u=e.state.loopDepth,l=e.state.parentHasLoopContext,f=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,g=e.state.currentSource;e.state.parentHasLoopContext=u>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,je(n)||(e.state.groupStdin=n),e.state.currentSource=t,v(e.state.env,"0",t),v(e.state.env,"#",String(s.length)),v(e.state.env,"@",s.join(" ")),v(e.state.env,"*",s.join(" "));for(let w=0;w<s.length&&w<9;w++)v(e.state.env,String(w+1),s[w]);for(let w=s.length+1;w<=9;w++)e.state.env.delete(String(w));let m=()=>{e.state.env=o,e.state.cwd=a,e.state.options=c,e.state.loopDepth=u,e.state.parentHasLoopContext=l,e.state.lastArg=f,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=g};try{let $=new H().parse(i),_=await r($);return m(),_}catch(w){if(m(),w instanceof G||w instanceof oe)throw w;if(w.name==="ParseException")return P(`bash: ${t}: ${w.message}
664
- `);throw w}}function ko(e,t){for(let s of t.parts)switch(s.type){case"Bytes":case"Literal":case"SingleQuoted":case"Escaped":continue;case"DoubleQuoted":for(let n of s.parts)switch(n.type){case"Bytes":case"Literal":case"SingleQuoted":case"Escaped":continue;case"ParameterExpansion":if(n.operation||n.parameter==="@"||n.parameter==="*"||n.parameter.endsWith("[@]")||n.parameter.endsWith("[*]"))return!1;if(ue(e,n.parameter)){let r=Pe(e,n.parameter);if(r&&(r.endsWith("[@]")||r.endsWith("[*]")))return!1}continue;case"CommandSubstitution":continue;default:return!1}continue;case"ParameterExpansion":return!1;default:return!1}return t.parts.length>0}var ut=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,coverage:t.coverage}}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,n=new Set;if(t)for(let i of t)n.add(i);if(s)for(let i of s)n.add(i);if(n.size===0)return Object.create(null);let r=Object.create(null);for(let i of n)this.ctx.state.env.has(i)&&(r[i]=O(this.ctx.state.env,i));return r}async executeScript(t){let s=p,n=p,r=0;for(let i of t.statements)try{let o=await this.executeStatement(i);s=N(s,o.stdout),n=N(n,o.stderr),r=o.exitCode,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r))}catch(o){if(o instanceof G)throw o.prependOutput(s,n),o;if(o instanceof we)return s=N(s,o.stdout),n=N(n,o.stderr),r=o.exitCode,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r)),{stdout:s,stderr:n,exitCode:r,env:De(this.ctx.state.env)};if(o instanceof oe)throw o;if(o instanceof ve)return s=N(s,o.stdout),n=N(n,o.stderr),r=o.exitCode,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r)),{stdout:s,stderr:n,exitCode:r,env:De(this.ctx.state.env)};if(o instanceof cn)return s=N(s,o.stdout),n=N(n,o.stderr),r=1,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r)),{stdout:s,stderr:n,exitCode:r,env:De(this.ctx.state.env)};if(o instanceof gt)return s=N(s,o.stdout),n=N(n,o.stderr),r=1,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r)),{stdout:s,stderr:n,exitCode:r,env:De(this.ctx.state.env)};if(o instanceof Fe){s=N(s,o.stdout),n=N(n,o.stderr),r=1,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r));continue}if(o instanceof un){s=N(s,o.stdout),n=N(n,o.stderr),r=1,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r));continue}if(o instanceof me||o instanceof ye){if(this.ctx.state.loopDepth>0)throw o.prependOutput(s,n),o;s=N(s,o.stdout),n=N(n,o.stderr);continue}throw o instanceof ce&&o.prependOutput(s,n),o}return{stdout:s,stderr:n,exitCode:r,env:De(this.ctx.state.env)}}async executeUserScript(t,s,n=p){return Zr(this.ctx,t,tt(s),n,r=>this.executeScript(r))}async executeStatement(t){if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&xe(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new bt(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return V;this.ctx.state.errexitSafe=!1;let s=p,n=p;this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(n=N(n,E(`${t.sourceText}
665
- `)));let r=0,i=-1,o=!1;for(let u=0;u<t.pipelines.length;u++){let l=t.pipelines[u],f=u>0?t.operators[u-1]:null;if(f==="&&"&&r!==0||f==="||"&&r===0)continue;let d=await this.executePipeline(l);s=N(s,d.stdout),n=N(n,d.stderr),r=d.exitCode,i=u,o=l.negated,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r))}let a=i<t.pipelines.length-1,c=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=a||o||c,this.ctx.state.options.errexit&&r!==0&&i===t.pipelines.length-1&&!o&&!this.ctx.state.inCondition&&!c)throw new ve(r,s,n);return{stdout:s,stderr:n,exitCode:r}}async executePipeline(t){return jr(this.ctx,t,(s,n)=>this.executeCommand(s,n))}async executeCommand(t,s){switch(this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return Tr(this.ctx,t);case"For":return Dr(this.ctx,t);case"CStyleFor":return Ir(this.ctx,t);case"While":return Rr(this.ctx,t,s);case"Until":return Lr(this.ctx,t);case"Case":return Mr(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return er(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return V}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(n){if(n instanceof vt)return{stdout:p,stderr:n.stderr,exitCode:1};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,b=100;for(;b>0;){let C=this.expandAlias(y);if(C===y)break;y=C,b--}this.aliasExpansionStack.clear(),y!==t&&(t=y)}this.ctx.state.expansionStderr="";let n=await Hr(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 b=await Ne(this.ctx,t.redirections);if(b)return b;let C={stdout:p,stderr:E(i),exitCode:0};return Z(this.ctx,C,t.redirections)}this.ctx.state.lastArg=E("");let y=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",{stdout:p,stderr:E(y),exitCode:this.ctx.state.lastExitCode}}let o=t.name&&sn(t.name,["local","declare","typeset","export","readonly"]),a=Array.from(r.keys());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 c=await Vt(this.ctx,t.redirections);if(c){for(let[y,b]of r)b===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,b);return c}let u=-1;for(let y of t.redirections){if((y.operator==="<<"||y.operator==="<<-")&&y.target.type==="HereDoc"){let b=y.target,C=y.fd??0;if(C===0&&!b.stripTabs)s=await He(this.ctx,b.content);else{let A=await F(this.ctx,b.content);b.stripTabs&&(A=A.split(`
664
+ `);throw w}}function No(e,t){for(let s of t.parts)switch(s.type){case"Bytes":case"Literal":case"SingleQuoted":case"Escaped":continue;case"DoubleQuoted":for(let n of s.parts)switch(n.type){case"Bytes":case"Literal":case"SingleQuoted":case"Escaped":continue;case"ParameterExpansion":if(n.operation||n.parameter==="@"||n.parameter==="*"||n.parameter.endsWith("[@]")||n.parameter.endsWith("[*]"))return!1;if(ue(e,n.parameter)){let r=Pe(e,n.parameter);if(r&&(r.endsWith("[@]")||r.endsWith("[*]")))return!1}continue;case"CommandSubstitution":continue;default:return!1}continue;case"ParameterExpansion":return!1;default:return!1}return t.parts.length>0}var ut=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,coverage:t.coverage}}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,n=new Set;if(t)for(let i of t)n.add(i);if(s)for(let i of s)n.add(i);if(n.size===0)return Object.create(null);let r=Object.create(null);for(let i of n)this.ctx.state.env.has(i)&&(r[i]=O(this.ctx.state.env,i));return r}async executeScript(t){let s=p,n=p,r=0;for(let i of t.statements)try{let o=await this.executeStatement(i);s=N(s,o.stdout),n=N(n,o.stderr),r=o.exitCode,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r))}catch(o){if(o instanceof G)throw o.prependOutput(s,n),o;if(o instanceof we)return s=N(s,o.stdout),n=N(n,o.stderr),r=o.exitCode,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r)),{stdout:s,stderr:n,exitCode:r,env:De(this.ctx.state.env)};if(o instanceof oe)throw o;if(o instanceof ve)return s=N(s,o.stdout),n=N(n,o.stderr),r=o.exitCode,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r)),{stdout:s,stderr:n,exitCode:r,env:De(this.ctx.state.env)};if(o instanceof cn)return s=N(s,o.stdout),n=N(n,o.stderr),r=1,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r)),{stdout:s,stderr:n,exitCode:r,env:De(this.ctx.state.env)};if(o instanceof gt)return s=N(s,o.stdout),n=N(n,o.stderr),r=1,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r)),{stdout:s,stderr:n,exitCode:r,env:De(this.ctx.state.env)};if(o instanceof Fe){s=N(s,o.stdout),n=N(n,o.stderr),r=1,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r));continue}if(o instanceof un){s=N(s,o.stdout),n=N(n,o.stderr),r=1,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r));continue}if(o instanceof me||o instanceof ye){if(this.ctx.state.loopDepth>0)throw o.prependOutput(s,n),o;s=N(s,o.stdout),n=N(n,o.stderr);continue}throw o instanceof ce&&o.prependOutput(s,n),o}return{stdout:s,stderr:n,exitCode:r,env:De(this.ctx.state.env)}}async executeUserScript(t,s,n=p){return Yr(this.ctx,t,tt(s),n,r=>this.executeScript(r))}async executeStatement(t){if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&xe(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new bt(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return V;this.ctx.state.errexitSafe=!1;let s=p,n=p;this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(n=N(n,E(`${t.sourceText}
665
+ `)));let r=0,i=-1,o=!1;for(let u=0;u<t.pipelines.length;u++){let l=t.pipelines[u],f=u>0?t.operators[u-1]:null;if(f==="&&"&&r!==0||f==="||"&&r===0)continue;let d=await this.executePipeline(l);s=N(s,d.stdout),n=N(n,d.stderr),r=d.exitCode,i=u,o=l.negated,this.ctx.state.lastExitCode=r,v(this.ctx.state.env,"?",String(r))}let a=i<t.pipelines.length-1,c=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=a||o||c,this.ctx.state.options.errexit&&r!==0&&i===t.pipelines.length-1&&!o&&!this.ctx.state.inCondition&&!c)throw new ve(r,s,n);return{stdout:s,stderr:n,exitCode:r}}async executePipeline(t){return Hr(this.ctx,t,(s,n)=>this.executeCommand(s,n))}async executeCommand(t,s){switch(this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return Dr(this.ctx,t);case"For":return Ir(this.ctx,t);case"CStyleFor":return Rr(this.ctx,t);case"While":return Lr(this.ctx,t,s);case"Until":return Mr(this.ctx,t);case"Case":return Fr(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return tr(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return V}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(n){if(n instanceof vt)return{stdout:p,stderr:n.stderr,exitCode:1};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,b=100;for(;b>0;){let C=this.expandAlias(y);if(C===y)break;y=C,b--}this.aliasExpansionStack.clear(),y!==t&&(t=y)}this.ctx.state.expansionStderr="";let n=await Ur(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 b=await Ne(this.ctx,t.redirections);if(b)return b;let C={stdout:p,stderr:E(i),exitCode:0};return Z(this.ctx,C,t.redirections)}this.ctx.state.lastArg=E("");let y=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",{stdout:p,stderr:E(y),exitCode:this.ctx.state.lastExitCode}}let o=t.name&&sn(t.name,["local","declare","typeset","export","readonly"]),a=Array.from(r.keys());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 c=await Vt(this.ctx,t.redirections);if(c){for(let[y,b]of r)b===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,b);return c}let u=-1;for(let y of t.redirections){if((y.operator==="<<"||y.operator==="<<-")&&y.target.type==="HereDoc"){let b=y.target,C=y.fd??0;if(C===0&&!b.stripTabs)s=await He(this.ctx,b.content);else{let A=await F(this.ctx,b.content);b.stripTabs&&(A=A.split(`
666
666
  `).map(L=>L.replace(/^\t+/,"")).join(`
667
667
  `)),C!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),this.ctx.state.fileDescriptors.set(C,A)):s=E(A)}continue}if(y.operator==="<<<"&&y.target.type==="Word"){let b=await He(this.ctx,y.target);s=N(b,E(`
668
668
  `));continue}if(y.operator==="<"&&y.target.type==="Word")try{let b=await F(this.ctx,y.target),C=this.ctx.fs.resolvePath(this.ctx.state.cwd,b);s=await this.ctx.fs.readFileBuffer(C)}catch{let b=await F(this.ctx,y.target);for(let[C,A]of r)A===void 0?this.ctx.state.env.delete(C):this.ctx.state.env.set(C,A);return P(`bash: ${b}: No such file or directory
669
- `)}if(y.operator==="<&"&&y.target.type==="Word"){let b=await F(this.ctx,y.target),C=Number.parseInt(b,10);if(!Number.isNaN(C)&&this.ctx.state.fileDescriptors){let A=this.ctx.state.fileDescriptors.get(C);if(A!==void 0)if(A.startsWith("__rw__:")){let L=Fr(A);L&&(s=E(L.content.slice(L.position)),u=C)}else A.startsWith("__file__:")||A.startsWith("__file_append__:")||(s=E(A))}}}let l=await F(this.ctx,t.name),f=[],d=[];if(sn(t.name,["local","declare","typeset","export","readonly"])&&(l==="local"||l==="declare"||l==="typeset"||l==="export"||l==="readonly"))for(let y of t.args){let b=await Mn(this.ctx,y);if(b)f.push(E(b)),d.push(!0);else{let C=await Fn(this.ctx,y);if(C!==null)f.push(E(C)),d.push(!0);else{let A=await Ce(this.ctx,y);for(let L of A.values)f.push(E(L)),d.push(A.quoted)}}}else for(let y of t.args)if(ko(this.ctx,y))f.push(await He(this.ctx,y)),d.push(!0);else{let b=await Ce(this.ctx,y);for(let C of b.values)f.push(E(C)),d.push(b.quoted)}if(!l){if(t.name.parts.every(b=>b.type==="CommandSubstitution"||b.type==="ParameterExpansion"||b.type==="ArithmeticExpansion")){if(f.length>0){let b=z(f.shift());return d.shift(),await this.runCommand(b,f,d,s,!1,!1,u)}return{stdout:p,stderr:p,exitCode:this.ctx.state.lastExitCode}}return P(`bash: : command not found
669
+ `)}if(y.operator==="<&"&&y.target.type==="Word"){let b=await F(this.ctx,y.target),C=Number.parseInt(b,10);if(!Number.isNaN(C)&&this.ctx.state.fileDescriptors){let A=this.ctx.state.fileDescriptors.get(C);if(A!==void 0)if(A.startsWith("__rw__:")){let L=Wr(A);L&&(s=E(L.content.slice(L.position)),u=C)}else A.startsWith("__file__:")||A.startsWith("__file_append__:")||(s=E(A))}}}let l=await F(this.ctx,t.name),f=[],d=[];if(sn(t.name,["local","declare","typeset","export","readonly"])&&(l==="local"||l==="declare"||l==="typeset"||l==="export"||l==="readonly"))for(let y of t.args){let b=await Fn(this.ctx,y);if(b)f.push(E(b)),d.push(!0);else{let C=await Wn(this.ctx,y);if(C!==null)f.push(E(C)),d.push(!0);else{let A=await Ce(this.ctx,y);for(let L of A.values)f.push(E(L)),d.push(A.quoted)}}}else for(let y of t.args)if(No(this.ctx,y))f.push(await He(this.ctx,y)),d.push(!0);else{let b=await Ce(this.ctx,y);for(let C of b.values)f.push(E(C)),d.push(b.quoted)}if(!l){if(t.name.parts.every(b=>b.type==="CommandSubstitution"||b.type==="ParameterExpansion"||b.type==="ArithmeticExpansion")){if(f.length>0){let b=z(f.shift());return d.shift(),await this.runCommand(b,f,d,s,!1,!1,u)}return{stdout:p,stderr:p,exitCode:this.ctx.state.lastExitCode}}return P(`bash: : command not found
670
670
  `,127)}if(l==="exec"&&(f.length===0||z(f[0])==="--")){for(let y of t.redirections){if(y.target.type==="HereDoc"||y.fdVariable)continue;let b=await F(this.ctx,y.target),C=y.fd??(y.operator==="<"||y.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),y.operator){case">":case">|":{let A=this.ctx.fs.resolvePath(this.ctx.state.cwd,b);await this.ctx.fs.writeFile(A,"","utf8"),this.ctx.state.fileDescriptors.set(C,`__file__:${A}`);break}case">>":{let A=this.ctx.fs.resolvePath(this.ctx.state.cwd,b);this.ctx.state.fileDescriptors.set(C,`__file_append__:${A}`);break}case"<":{let A=this.ctx.fs.resolvePath(this.ctx.state.cwd,b);try{let L=await this.ctx.fs.readFile(A);this.ctx.state.fileDescriptors.set(C,L)}catch{return P(`bash: ${b}: No such file or directory
671
- `)}break}case"<>":{let A=this.ctx.fs.resolvePath(this.ctx.state.cwd,b);try{let L=await this.ctx.fs.readFile(A);this.ctx.state.fileDescriptors.set(C,`__rw__:${A.length}:${A}:0:${L}`)}catch{await this.ctx.fs.writeFile(A,"","utf8"),this.ctx.state.fileDescriptors.set(C,`__rw__:${A.length}:${A}:0:`)}break}case">&":{if(b==="-")this.ctx.state.fileDescriptors.delete(C);else if(b.endsWith("-")){let A=b.slice(0,-1),L=Number.parseInt(A,10);if(!Number.isNaN(L)){let I=this.ctx.state.fileDescriptors.get(L);I!==void 0?this.ctx.state.fileDescriptors.set(C,I):this.ctx.state.fileDescriptors.set(C,`__dupout__:${L}`),this.ctx.state.fileDescriptors.delete(L)}}else{let A=Number.parseInt(b,10);Number.isNaN(A)||this.ctx.state.fileDescriptors.set(C,`__dupout__:${A}`)}break}case"<&":{if(b==="-")this.ctx.state.fileDescriptors.delete(C);else if(b.endsWith("-")){let A=b.slice(0,-1),L=Number.parseInt(A,10);if(!Number.isNaN(L)){let I=this.ctx.state.fileDescriptors.get(L);I!==void 0?this.ctx.state.fileDescriptors.set(C,I):this.ctx.state.fileDescriptors.set(C,`__dupin__:${L}`),this.ctx.state.fileDescriptors.delete(L)}}else{let A=Number.parseInt(b,10);Number.isNaN(A)||this.ctx.state.fileDescriptors.set(C,`__dupin__:${A}`)}break}}}for(let[y,b]of r)b===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,b);if(this.ctx.state.tempExportedVars)for(let y of r.keys())this.ctx.state.tempExportedVars.delete(y);return V}let g=await zr(this.ctx,l,f.map(y=>z(y)));r.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(r)));let m,w=null;try{m=await this.runCommand(l,f,d,s,!1,!1,u)}catch(y){if(y instanceof me||y instanceof ye)w=y,m=V;else throw y}let $=i+g;if($&&(m={...m,stderr:N(E($),m.stderr)}),m=await Z(this.ctx,m,t.redirections),w)throw w;if(f.length>0){let y=z(f[f.length-1]);if((l==="declare"||l==="local"||l==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(y)){let b=y.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);b&&(y=b[1])}this.ctx.state.lastArg=E(y)}else this.ctx.state.lastArg=E(l);let _=Qn(l)&&l!=="unset"&&l!=="eval";if(!this.ctx.state.options.posix||!_)for(let[y,b]of r)this.ctx.state.fullyUnsetLocals?.has(y)||(b===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,b));if(this.ctx.state.tempExportedVars)for(let y of r.keys())this.ctx.state.tempExportedVars.delete(y);return r.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(m={...m,stderr:N(E(this.ctx.state.expansionStderr),m.stderr)},this.ctx.state.expansionStderr=""),m}async runCommand(t,s,n,r,i=!1,o=!1,a=-1){let c={ctx:this.ctx,runCommand:(l,f,d,h,g,m,w)=>this.runCommand(l,f,d,h,g,m,w),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(l,f,d)=>this.executeUserScript(l,f,d)},u=await Or(c,t,s,n,r,i,o,a);return u!==null?u:xr(c,t,s,r,o)}aliasExpansionStack=new Set;expandAlias(t){return fs(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return qt(this.ctx,t)}async executeSubshell(t,s=p){return Gr(this.ctx,t,s,n=>this.executeStatement(n))}async executeGroup(t,s=p){return qr(this.ctx,t,s,n=>this.executeStatement(n))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await Ne(this.ctx,t.redirections);if(s)return s;try{let n=await q(this.ctx,t.expression.expression),r=X(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:N(E(this.ctx.state.expansionStderr),r.stderr)},this.ctx.state.expansionStderr=""),Z(this.ctx,r,t.redirections)}catch(n){let r=P(`bash: arithmetic expression: ${n.message}
671
+ `)}break}case"<>":{let A=this.ctx.fs.resolvePath(this.ctx.state.cwd,b);try{let L=await this.ctx.fs.readFile(A);this.ctx.state.fileDescriptors.set(C,`__rw__:${A.length}:${A}:0:${L}`)}catch{await this.ctx.fs.writeFile(A,"","utf8"),this.ctx.state.fileDescriptors.set(C,`__rw__:${A.length}:${A}:0:`)}break}case">&":{if(b==="-")this.ctx.state.fileDescriptors.delete(C);else if(b.endsWith("-")){let A=b.slice(0,-1),L=Number.parseInt(A,10);if(!Number.isNaN(L)){let I=this.ctx.state.fileDescriptors.get(L);I!==void 0?this.ctx.state.fileDescriptors.set(C,I):this.ctx.state.fileDescriptors.set(C,`__dupout__:${L}`),this.ctx.state.fileDescriptors.delete(L)}}else{let A=Number.parseInt(b,10);Number.isNaN(A)||this.ctx.state.fileDescriptors.set(C,`__dupout__:${A}`)}break}case"<&":{if(b==="-")this.ctx.state.fileDescriptors.delete(C);else if(b.endsWith("-")){let A=b.slice(0,-1),L=Number.parseInt(A,10);if(!Number.isNaN(L)){let I=this.ctx.state.fileDescriptors.get(L);I!==void 0?this.ctx.state.fileDescriptors.set(C,I):this.ctx.state.fileDescriptors.set(C,`__dupin__:${L}`),this.ctx.state.fileDescriptors.delete(L)}}else{let A=Number.parseInt(b,10);Number.isNaN(A)||this.ctx.state.fileDescriptors.set(C,`__dupin__:${A}`)}break}}}for(let[y,b]of r)b===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,b);if(this.ctx.state.tempExportedVars)for(let y of r.keys())this.ctx.state.tempExportedVars.delete(y);return V}let g=await Br(this.ctx,l,f.map(y=>z(y)));r.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(r)));let m,w=null;try{m=await this.runCommand(l,f,d,s,!1,!1,u)}catch(y){if(y instanceof me||y instanceof ye)w=y,m=V;else throw y}let $=i+g;if($&&(m={...m,stderr:N(E($),m.stderr)}),m=await Z(this.ctx,m,t.redirections),w)throw w;if(f.length>0){let y=z(f[f.length-1]);if((l==="declare"||l==="local"||l==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(y)){let b=y.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);b&&(y=b[1])}this.ctx.state.lastArg=E(y)}else this.ctx.state.lastArg=E(l);let _=Jn(l)&&l!=="unset"&&l!=="eval";if(!this.ctx.state.options.posix||!_)for(let[y,b]of r)this.ctx.state.fullyUnsetLocals?.has(y)||(b===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,b));if(this.ctx.state.tempExportedVars)for(let y of r.keys())this.ctx.state.tempExportedVars.delete(y);return r.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(m={...m,stderr:N(E(this.ctx.state.expansionStderr),m.stderr)},this.ctx.state.expansionStderr=""),m}async runCommand(t,s,n,r,i=!1,o=!1,a=-1){let c={ctx:this.ctx,runCommand:(l,f,d,h,g,m,w)=>this.runCommand(l,f,d,h,g,m,w),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(l,f,d)=>this.executeUserScript(l,f,d)},u=await xr(c,t,s,n,r,i,o,a);return u!==null?u:Tr(c,t,s,r,o)}aliasExpansionStack=new Set;expandAlias(t){return fs(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return qt(this.ctx,t)}async executeSubshell(t,s=p){return qr(this.ctx,t,s,n=>this.executeStatement(n))}async executeGroup(t,s=p){return Zr(this.ctx,t,s,n=>this.executeStatement(n))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await Ne(this.ctx,t.redirections);if(s)return s;try{let n=await q(this.ctx,t.expression.expression),r=X(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:N(E(this.ctx.state.expansionStderr),r.stderr)},this.ctx.state.expansionStderr=""),Z(this.ctx,r,t.redirections)}catch(n){let r=P(`bash: arithmetic expression: ${n.message}
672
672
  `);return Z(this.ctx,r,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await Ne(this.ctx,t.redirections);if(s)return s;try{let n=await Le(this.ctx,t.expression),r=X(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:N(E(this.ctx.state.expansionStderr),r.stderr)},this.ctx.state.expansionStderr=""),Z(this.ctx,r,t.redirections)}catch(n){let r=n instanceof Fe?1:2,i=P(`bash: conditional expression: ${n.message}
673
- `,r);return Z(this.ctx,i,t.redirections)}}};var de={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:3e4,maxGlobOperations:1e5,maxStringLength:10485760,maxArrayElements:1e5,maxHeredocSize:10485760,maxSubstitutionDepth:50};function Yr(e){return e?{maxCallDepth:e.maxCallDepth??de.maxCallDepth,maxCommandCount:e.maxCommandCount??de.maxCommandCount,maxLoopIterations:e.maxLoopIterations??de.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??de.maxAwkIterations,maxSedIterations:e.maxSedIterations??de.maxSedIterations,maxJqIterations:e.maxJqIterations??de.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??de.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??de.maxPythonTimeoutMs,maxGlobOperations:e.maxGlobOperations??de.maxGlobOperations,maxStringLength:e.maxStringLength??de.maxStringLength,maxArrayElements:e.maxArrayElements??de.maxArrayElements,maxHeredocSize:e.maxHeredocSize??de.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??de.maxSubstitutionDepth}:{...de}}function Kr(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function No(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=No(t);return!n||s.origin!==n.origin?!1:n.pathPrefix==="/"||n.pathPrefix===""?!0:s.pathname.startsWith(n.pathPrefix)}function nn(e,t){return!t||t.length===0?!1:t.some(s=>Oo(e,s))}var ft=class extends Error{constructor(t){super(`Network access denied: URL not in allow-list: ${t}`),this.name="NetworkAccessDeniedError"}},dt=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},ht=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Yt=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}},pt=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var xo=20,To=3e4,Do=10485760,Io=["GET","HEAD"],Ro=new Set(["GET","HEAD","OPTIONS"]),Lo=new Set([301,302,303,307,308]);function rn(e){let t=e.maxRedirects??xo,s=e.timeoutMs??To,n=e.maxResponseSize??Do,r=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Io;function i(c){if(!e.dangerouslyAllowFullInternetAccess&&!nn(c,e.allowedUrlPrefixes??[]))throw new ft(c)}function o(c){if(e.dangerouslyAllowFullInternetAccess)return;let u=c.toUpperCase();if(!r.includes(u))throw new Yt(u,r)}async function a(c,u={}){let l=u.method?.toUpperCase()??"GET";i(c),o(l);let f=c,d=0,h=u.followRedirects??!0,g=u.timeoutMs!==void 0?Math.min(u.timeoutMs,s):s;for(;;){let m=new AbortController,w=setTimeout(()=>m.abort(),g);try{let $={method:l,headers:u.headers,signal:m.signal,redirect:"manual"};u.body&&!Ro.has(l)&&($.body=u.body);let _=await fetch(f,$);if(Lo.has(_.status)&&h){let k=_.headers.get("location");if(!k)return await Xr(_,f,n);let y=new URL(k,f).href;if(!e.dangerouslyAllowFullInternetAccess&&!nn(y,e.allowedUrlPrefixes??[]))throw new ht(y);if(d++,d>t)throw new dt(t);f=y;continue}return await Xr(_,f,n)}finally{clearTimeout(w)}}}return a}async function Xr(e,t,s){let n=Object.create(null);if(e.headers.forEach((i,o)=>{n[o.toLowerCase()]=i}),s>0){let i=e.headers.get("content-length");if(i){let o=parseInt(i,10);if(!Number.isNaN(o)&&o>s)throw new pt(s)}}let r;if(s>0&&e.body){let i=e.body.getReader(),o=new TextDecoder,a=[],c=0;for(;;){let{done:u,value:l}=await i.read();if(u)break;if(c+=l.byteLength,c>s)throw i.cancel(),new pt(s);a.push(o.decode(l,{stream:!0}))}a.push(o.decode()),r=a.join("")}else r=await e.text();return{status:e.status,statusText:e.statusText,headers:n,body:r,url:t}}function Qr(){let e=[{prop:"Function",target:globalThis,violationType:"function_constructor",strategy:"throw",reason:"Function constructor allows arbitrary code execution"},{prop:"eval",target:globalThis,violationType:"eval",strategy:"throw",reason:"eval() allows arbitrary code execution"},{prop:"setTimeout",target:globalThis,violationType:"setTimeout",strategy:"throw",reason:"setTimeout with string argument allows code execution"},{prop:"setInterval",target:globalThis,violationType:"setInterval",strategy:"throw",reason:"setInterval with string argument allows code execution"},{prop:"setImmediate",target:globalThis,violationType:"setImmediate",strategy:"throw",reason:"setImmediate could be used to escape sandbox context"},{prop:"env",target:process,violationType:"process_env",strategy:"throw",reason:"process.env could leak sensitive environment variables"},{prop:"binding",target:process,violationType:"process_binding",strategy:"throw",reason:"process.binding provides access to native Node.js modules"},{prop:"_linkedBinding",target:process,violationType:"process_binding",strategy:"throw",reason:"process._linkedBinding provides access to native Node.js modules"},{prop:"dlopen",target:process,violationType:"process_dlopen",strategy:"throw",reason:"process.dlopen allows loading native addons"},{prop:"WeakRef",target:globalThis,violationType:"weak_ref",strategy:"throw",reason:"WeakRef could be used to leak references outside sandbox"},{prop:"FinalizationRegistry",target:globalThis,violationType:"finalization_registry",strategy:"throw",reason:"FinalizationRegistry could be used to leak references outside sandbox"},{prop:"Reflect",target:globalThis,violationType:"reflect",strategy:"freeze",reason:"Reflect provides introspection capabilities"},{prop:"Proxy",target:globalThis,violationType:"proxy",strategy:"throw",reason:"Proxy allows intercepting and modifying object behavior"},{prop:"WebAssembly",target:globalThis,violationType:"webassembly",strategy:"throw",reason:"WebAssembly allows executing arbitrary compiled code"},{prop:"SharedArrayBuffer",target:globalThis,violationType:"shared_array_buffer",strategy:"throw",reason:"SharedArrayBuffer could enable side-channel communication or timing attacks"},{prop:"Atomics",target:globalThis,violationType:"atomics",strategy:"throw",reason:"Atomics could enable side-channel communication or timing attacks"}];try{let t=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&e.push({prop:"constructor",target:Object.getPrototypeOf(async()=>{}),violationType:"async_function_constructor",strategy:"throw",reason:"AsyncFunction constructor allows arbitrary async code execution"})}catch{}try{let t=Object.getPrototypeOf(function*(){}).constructor;t&&t!==Function&&e.push({prop:"constructor",target:Object.getPrototypeOf(function*(){}),violationType:"generator_function_constructor",strategy:"throw",reason:"GeneratorFunction constructor allows arbitrary generator code execution"})}catch{}try{let t=Object.getPrototypeOf(async function*(){}).constructor;t&&t!==Function&&t!==Object.getPrototypeOf(async()=>{}).constructor&&e.push({prop:"constructor",target:Object.getPrototypeOf(async function*(){}),violationType:"async_generator_function_constructor",strategy:"throw",reason:"AsyncGeneratorFunction constructor allows arbitrary async generator code execution"})}catch{}return e.filter(t=>{try{return t.target[t.prop]!==void 0}catch{return!1}})}var mt=typeof __BROWSER__<"u"&&__BROWSER__;function Jr(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}var an=null;if(!mt)try{let{createRequire:e}=await import("node:module");an=e(import.meta.url)("node:async_hooks").AsyncLocalStorage}catch(e){console.debug("[DefenseInDepthBox] AsyncLocalStorage not available, defense-in-depth disabled:",e instanceof Error?e.message:e)}var Mo=`
673
+ `,r);return Z(this.ctx,i,t.redirections)}}};var de={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:3e4,maxGlobOperations:1e5,maxStringLength:10485760,maxArrayElements:1e5,maxHeredocSize:10485760,maxSubstitutionDepth:50};function Kr(e){return e?{maxCallDepth:e.maxCallDepth??de.maxCallDepth,maxCommandCount:e.maxCommandCount??de.maxCommandCount,maxLoopIterations:e.maxLoopIterations??de.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??de.maxAwkIterations,maxSedIterations:e.maxSedIterations??de.maxSedIterations,maxJqIterations:e.maxJqIterations??de.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??de.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??de.maxPythonTimeoutMs,maxGlobOperations:e.maxGlobOperations??de.maxGlobOperations,maxStringLength:e.maxStringLength??de.maxStringLength,maxArrayElements:e.maxArrayElements??de.maxArrayElements,maxHeredocSize:e.maxHeredocSize??de.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??de.maxSubstitutionDepth}:{...de}}function Xr(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function Oo(e){let t=Xr(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function xo(e,t){let s=Xr(e);if(!s)return!1;let n=Oo(t);return!n||s.origin!==n.origin?!1:n.pathPrefix==="/"||n.pathPrefix===""?!0:s.pathname.startsWith(n.pathPrefix)}function nn(e,t){return!t||t.length===0?!1:t.some(s=>xo(e,s))}var ft=class extends Error{constructor(t){super(`Network access denied: URL not in allow-list: ${t}`),this.name="NetworkAccessDeniedError"}},dt=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},ht=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Yt=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}},pt=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var To=20,Do=3e4,Io=10485760,Ro=["GET","HEAD"],Lo=new Set(["GET","HEAD","OPTIONS"]),Mo=new Set([301,302,303,307,308]);function rn(e){let t=e.maxRedirects??To,s=e.timeoutMs??Do,n=e.maxResponseSize??Io,r=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Ro;function i(c){if(!e.dangerouslyAllowFullInternetAccess&&!nn(c,e.allowedUrlPrefixes??[]))throw new ft(c)}function o(c){if(e.dangerouslyAllowFullInternetAccess)return;let u=c.toUpperCase();if(!r.includes(u))throw new Yt(u,r)}async function a(c,u={}){let l=u.method?.toUpperCase()??"GET";i(c),o(l);let f=c,d=0,h=u.followRedirects??!0,g=u.timeoutMs!==void 0?Math.min(u.timeoutMs,s):s;for(;;){let m=new AbortController,w=setTimeout(()=>m.abort(),g);try{let $={method:l,headers:u.headers,signal:m.signal,redirect:"manual"};u.body&&!Lo.has(l)&&($.body=u.body);let _=await fetch(f,$);if(Mo.has(_.status)&&h){let k=_.headers.get("location");if(!k)return await Qr(_,f,n);let y=new URL(k,f).href;if(!e.dangerouslyAllowFullInternetAccess&&!nn(y,e.allowedUrlPrefixes??[]))throw new ht(y);if(d++,d>t)throw new dt(t);f=y;continue}return await Qr(_,f,n)}finally{clearTimeout(w)}}}return a}async function Qr(e,t,s){let n=Object.create(null);if(e.headers.forEach((i,o)=>{n[o.toLowerCase()]=i}),s>0){let i=e.headers.get("content-length");if(i){let o=parseInt(i,10);if(!Number.isNaN(o)&&o>s)throw new pt(s)}}let r;if(s>0&&e.body){let i=e.body.getReader(),o=new TextDecoder,a=[],c=0;for(;;){let{done:u,value:l}=await i.read();if(u)break;if(c+=l.byteLength,c>s)throw i.cancel(),new pt(s);a.push(o.decode(l,{stream:!0}))}a.push(o.decode()),r=a.join("")}else r=await e.text();return{status:e.status,statusText:e.statusText,headers:n,body:r,url:t}}function Jr(){let e=[{prop:"Function",target:globalThis,violationType:"function_constructor",strategy:"throw",reason:"Function constructor allows arbitrary code execution"},{prop:"eval",target:globalThis,violationType:"eval",strategy:"throw",reason:"eval() allows arbitrary code execution"},{prop:"setTimeout",target:globalThis,violationType:"setTimeout",strategy:"throw",reason:"setTimeout with string argument allows code execution"},{prop:"setInterval",target:globalThis,violationType:"setInterval",strategy:"throw",reason:"setInterval with string argument allows code execution"},{prop:"setImmediate",target:globalThis,violationType:"setImmediate",strategy:"throw",reason:"setImmediate could be used to escape sandbox context"},{prop:"env",target:process,violationType:"process_env",strategy:"throw",reason:"process.env could leak sensitive environment variables"},{prop:"binding",target:process,violationType:"process_binding",strategy:"throw",reason:"process.binding provides access to native Node.js modules"},{prop:"_linkedBinding",target:process,violationType:"process_binding",strategy:"throw",reason:"process._linkedBinding provides access to native Node.js modules"},{prop:"dlopen",target:process,violationType:"process_dlopen",strategy:"throw",reason:"process.dlopen allows loading native addons"},{prop:"WeakRef",target:globalThis,violationType:"weak_ref",strategy:"throw",reason:"WeakRef could be used to leak references outside sandbox"},{prop:"FinalizationRegistry",target:globalThis,violationType:"finalization_registry",strategy:"throw",reason:"FinalizationRegistry could be used to leak references outside sandbox"},{prop:"Reflect",target:globalThis,violationType:"reflect",strategy:"freeze",reason:"Reflect provides introspection capabilities"},{prop:"Proxy",target:globalThis,violationType:"proxy",strategy:"throw",reason:"Proxy allows intercepting and modifying object behavior"},{prop:"WebAssembly",target:globalThis,violationType:"webassembly",strategy:"throw",reason:"WebAssembly allows executing arbitrary compiled code"},{prop:"SharedArrayBuffer",target:globalThis,violationType:"shared_array_buffer",strategy:"throw",reason:"SharedArrayBuffer could enable side-channel communication or timing attacks"},{prop:"Atomics",target:globalThis,violationType:"atomics",strategy:"throw",reason:"Atomics could enable side-channel communication or timing attacks"}];try{let t=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&e.push({prop:"constructor",target:Object.getPrototypeOf(async()=>{}),violationType:"async_function_constructor",strategy:"throw",reason:"AsyncFunction constructor allows arbitrary async code execution"})}catch{}try{let t=Object.getPrototypeOf(function*(){}).constructor;t&&t!==Function&&e.push({prop:"constructor",target:Object.getPrototypeOf(function*(){}),violationType:"generator_function_constructor",strategy:"throw",reason:"GeneratorFunction constructor allows arbitrary generator code execution"})}catch{}try{let t=Object.getPrototypeOf(async function*(){}).constructor;t&&t!==Function&&t!==Object.getPrototypeOf(async()=>{}).constructor&&e.push({prop:"constructor",target:Object.getPrototypeOf(async function*(){}),violationType:"async_generator_function_constructor",strategy:"throw",reason:"AsyncGeneratorFunction constructor allows arbitrary async generator code execution"})}catch{}return e.filter(t=>{try{return t.target[t.prop]!==void 0}catch{return!1}})}var mt=typeof __BROWSER__<"u"&&__BROWSER__;function ei(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}var an=null;if(!mt)try{let{createRequire:e}=await import("node:module");an=e(import.meta.url)("node:async_hooks").AsyncLocalStorage}catch(e){console.debug("[DefenseInDepthBox] AsyncLocalStorage not available, defense-in-depth disabled:",e instanceof Error?e.message:e)}var Fo=`
674
674
 
675
- This is a defense-in-depth measure and indicates a bug in just-bash. Please report this at security@vercel.com`,le=class extends Error{violation;constructor(t,s){super(t+Mo),this.violation=s,this.name="SecurityViolationError"}},he=!mt&&an?new an:null,Fo=1e3,on={enabled:!0,auditMode:!1};function Wo(e){return e===void 0?{...on,enabled:!1}:typeof e=="boolean"?{...on,enabled:e}:{...on,...e}}var Kt=class e{static instance=null;config;refCount=0;originalDescriptors=[];violations=[];activationTime=0;totalActiveTimeMs=0;constructor(t){this.config=t}static getInstance(t){return e.instance||(e.instance=new e(Wo(t))),e.instance}static resetInstance(){e.instance&&(e.instance.forceDeactivate(),e.instance=null)}static isInSandboxedContext(){return he?he?.getStore()?.sandboxActive===!0:!1}static getCurrentExecutionId(){if(he)return he?.getStore()?.executionId}updateConfig(t){this.config={...this.config,...t}}activate(){if(mt||!this.config.enabled){let s=Jr();return{run:n=>n(),deactivate:()=>{},executionId:s}}this.refCount++,this.refCount===1&&(this.applyPatches(),this.activationTime=Date.now());let t=Jr();return{run:s=>he.run({sandboxActive:!0,executionId:t},s),deactivate:()=>{this.refCount--,this.refCount===0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount<0&&(this.refCount=0)},executionId:t}}forceDeactivate(){this.refCount>0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount=0}isActive(){return this.refCount>0}getStats(){return{violationsBlocked:this.violations.length,violations:[...this.violations],activeTimeMs:this.totalActiveTimeMs+(this.refCount>0?Date.now()-this.activationTime:0),refCount:this.refCount}}clearViolations(){this.violations=[]}getPathForTarget(t,s){return t===globalThis?`globalThis.${s}`:t===process?`process.${s}`:t===Error?`Error.${s}`:t===Function.prototype?`Function.prototype.${s}`:t===Object.prototype?`Object.prototype.${s}`:`<object>.${s}`}shouldBlock(){return mt||this.config.auditMode||!he?!1:he?.getStore()?.sandboxActive===!0}recordViolation(t,s,n){let r={timestamp:Date.now(),type:t,message:n,path:s,stack:new Error().stack,executionId:he?.getStore()?.executionId};if(this.violations.length<Fo&&this.violations.push(r),this.config.onViolation)try{this.config.onViolation(r)}catch(i){console.debug("[DefenseInDepthBox] onViolation callback threw:",i instanceof Error?i.message:i)}return r}createBlockingProxy(t,s,n){let r=this;return new Proxy(t,{apply(i,o,a){if(r.shouldBlock()){let c=`${s} is blocked during script execution`,u=r.recordViolation(n,s,c);throw new le(c,u)}return r.config.auditMode&&he?.getStore()?.sandboxActive===!0&&r.recordViolation(n,s,`${s} called (audit mode)`),Reflect.apply(i,o,a)},construct(i,o,a){if(r.shouldBlock()){let c=`${s} constructor is blocked during script execution`,u=r.recordViolation(n,s,c);throw new le(c,u)}return r.config.auditMode&&he?.getStore()?.sandboxActive===!0&&r.recordViolation(n,s,`${s} constructor called (audit mode)`),Reflect.construct(i,o,a)}})}createBlockingObjectProxy(t,s,n){let r=this;return new Proxy(t,{get(i,o,a){if(r.shouldBlock()){let c=`${s}.${String(o)}`,u=`${c} is blocked during script execution`,l=r.recordViolation(n,c,u);throw new le(u,l)}if(r.config.auditMode&&he?.getStore()?.sandboxActive===!0){let c=`${s}.${String(o)}`;r.recordViolation(n,c,`${c} accessed (audit mode)`)}return Reflect.get(i,o,a)},set(i,o,a,c){if(r.shouldBlock()){let u=`${s}.${String(o)}`,l=`${u} modification is blocked during script execution`,f=r.recordViolation(n,u,l);throw new le(l,f)}return Reflect.set(i,o,a,c)},ownKeys(i){if(r.shouldBlock()){let o=`${s} enumeration is blocked during script execution`,a=r.recordViolation(n,s,o);throw new le(o,a)}return Reflect.ownKeys(i)},getOwnPropertyDescriptor(i,o){if(r.shouldBlock()){let a=`${s}.${String(o)}`,c=`${a} descriptor access is blocked during script execution`,u=r.recordViolation(n,a,c);throw new le(c,u)}return Reflect.getOwnPropertyDescriptor(i,o)},has(i,o){if(r.shouldBlock()){let a=`${s}.${String(o)}`,c=`${a} existence check is blocked during script execution`,u=r.recordViolation(n,a,c);throw new le(c,u)}return Reflect.has(i,o)}})}applyPatches(){let t=Qr();for(let s of t)this.applyPatch(s);this.protectConstructorChain(),this.protectErrorPrepareStackTrace(),this.protectModuleLoad(),this.protectProcessMainModule()}protectConstructorChain(){this.patchPrototypeConstructor(Function.prototype,"Function.prototype.constructor","function_constructor");try{let t=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&this.patchPrototypeConstructor(t.prototype,"AsyncFunction.prototype.constructor","async_function_constructor")}catch(t){console.debug("[DefenseInDepthBox] Could not patch AsyncFunction.prototype.constructor:",t instanceof Error?t.message:t)}try{let t=Object.getPrototypeOf(function*(){}).constructor;t&&t!==Function&&this.patchPrototypeConstructor(t.prototype,"GeneratorFunction.prototype.constructor","generator_function_constructor")}catch(t){console.debug("[DefenseInDepthBox] Could not patch GeneratorFunction.prototype.constructor:",t instanceof Error?t.message:t)}try{let t=Object.getPrototypeOf(async function*(){}).constructor,s=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&t!==s&&this.patchPrototypeConstructor(t.prototype,"AsyncGeneratorFunction.prototype.constructor","async_generator_function_constructor")}catch(t){console.debug("[DefenseInDepthBox] Could not patch AsyncGeneratorFunction.prototype.constructor:",t instanceof Error?t.message:t)}}protectErrorPrepareStackTrace(){let t=this;try{let s=Object.getOwnPropertyDescriptor(Error,"prepareStackTrace");this.originalDescriptors.push({target:Error,prop:"prepareStackTrace",descriptor:s});let n=s?.value;Object.defineProperty(Error,"prepareStackTrace",{get(){return n},set(r){if(t.shouldBlock()){let i="Error.prepareStackTrace modification is blocked during script execution",o=t.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace",i);throw new le(i,o)}t.config.auditMode&&he?.getStore()?.sandboxActive===!0&&t.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace","Error.prepareStackTrace set (audit mode)"),n=r},configurable:!0})}catch(s){console.debug("[DefenseInDepthBox] Could not protect Error.prepareStackTrace:",s instanceof Error?s.message:s)}}patchPrototypeConstructor(t,s,n){let r=this;try{let i=Object.getOwnPropertyDescriptor(t,"constructor");this.originalDescriptors.push({target:t,prop:"constructor",descriptor:i});let o=i?.value;Object.defineProperty(t,"constructor",{get(){if(r.shouldBlock()){let a=`${s} access is blocked during script execution`,c=r.recordViolation(n,s,a);throw new le(a,c)}return r.config.auditMode&&he?.getStore()?.sandboxActive===!0&&r.recordViolation(n,s,`${s} accessed (audit mode)`),o},set(a){if(r.shouldBlock()){let c=`${s} modification is blocked during script execution`,u=r.recordViolation(n,s,c);throw new le(c,u)}Object.defineProperty(this,"constructor",{value:a,writable:!0,configurable:!0})},configurable:!0})}catch(i){console.debug(`[DefenseInDepthBox] Could not patch ${s}:`,i instanceof Error?i.message:i)}}protectProcessMainModule(){if(typeof process>"u")return;let t=this;try{let s=Object.getOwnPropertyDescriptor(process,"mainModule");this.originalDescriptors.push({target:process,prop:"mainModule",descriptor:s});let n=s?.value;n!==void 0&&Object.defineProperty(process,"mainModule",{get(){if(t.shouldBlock()){let r="process.mainModule access is blocked during script execution",i=t.recordViolation("process_main_module","process.mainModule",r);throw new le(r,i)}return t.config.auditMode&&he?.getStore()?.sandboxActive===!0&&t.recordViolation("process_main_module","process.mainModule","process.mainModule accessed (audit mode)"),n},set(r){if(t.shouldBlock()){let i="process.mainModule modification is blocked during script execution",o=t.recordViolation("process_main_module","process.mainModule",i);throw new le(i,o)}Object.defineProperty(process,"mainModule",{value:r,writable:!0,configurable:!0})},configurable:!0})}catch(s){console.debug("[DefenseInDepthBox] Could not protect process.mainModule:",s instanceof Error?s.message:s)}}protectModuleLoad(){if(!mt)try{let t=null;if(typeof process<"u"){let o=process.mainModule;o&&typeof o=="object"&&(t=o.constructor)}if(!t&&typeof yt<"u"&&typeof yt.main<"u"&&(t=yt.main.constructor),!t||typeof t._load!="function")return;let s=t._load,n=Object.getOwnPropertyDescriptor(t,"_load");this.originalDescriptors.push({target:t,prop:"_load",descriptor:n});let i=this.createBlockingProxy(s,"Module._load","module_load");Object.defineProperty(t,"_load",{value:i,writable:!0,configurable:!0})}catch(t){console.debug("[DefenseInDepthBox] Could not protect Module._load:",t instanceof Error?t.message:t)}}applyPatch(t){let{target:s,prop:n,violationType:r,strategy:i}=t;try{let o=s[n];if(o===void 0)return;let a=Object.getOwnPropertyDescriptor(s,n);if(this.originalDescriptors.push({target:s,prop:n,descriptor:a}),i==="freeze")typeof o=="object"&&o!==null&&Object.freeze(o);else{let c=this.getPathForTarget(s,n),u=typeof o=="function"?this.createBlockingProxy(o,c,r):this.createBlockingObjectProxy(o,c,r);Object.defineProperty(s,n,{value:u,writable:!0,configurable:!0})}}catch(o){let a=this.getPathForTarget(s,n);console.debug(`[DefenseInDepthBox] Could not patch ${a}:`,o instanceof Error?o.message:o)}}restorePatches(){for(let t=this.originalDescriptors.length-1;t>=0;t--){let{target:s,prop:n,descriptor:r}=this.originalDescriptors[t];try{r?Object.defineProperty(s,n,r):delete s[n]}catch(i){let o=this.getPathForTarget(s,n);console.debug(`[DefenseInDepthBox] Could not restore ${o}:`,i instanceof Error?i.message:i)}}this.originalDescriptors=[]}};var Xt=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;state;constructor(t={}){let s=t.fs??new nt(t.files);this.fs=s,this.useDefaultLayout=!t.cwd&&!t.files;let n=t.cwd||(this.useDefaultLayout?"/home/user":"/"),r=new Map,i=[["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
676
- `],["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"],["PWD",n],["OLDPWD",n],["OPTIND","1"]];for(let[o,a]of i)v(r,o,a);for(let[o,a]of Object.entries(t.env??{}))v(r,o,a);if(this.limits=Yr({...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=rn(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth,this.coverageWriter=t.coverage,this.state={env:r,cwd:n,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:p,startTime:Date.now(),lastBackgroundPid:0,bashPid:Jt().pid,nextVirtualPid:Jt().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},v(this.state.env,"SHELLOPTS",ls(this.state.options)),v(this.state.env,"BASHOPTS",cs(this.state.shoptOptions)),xn(s,this.useDefaultLayout),n!=="/"&&s instanceof nt)try{s.mkdirSync(n,{recursive:!0})}catch{}for(let o of Pn(t.commands))this.registerCommand(o);if(t.network)for(let o of Cn())this.registerCommand(o);if(t.python)for(let o of kn())this.registerCommand(o);if(t.customCommands)for(let o of t.customCommands)Nn(o)?this.registerCommand(On(o)):this.registerCommand(o)}registerCommand(t){this.commands.set(t.name,t);let s=this.fs;if(typeof s.writeFileSync=="function"){let n=`#!/bin/bash
675
+ This is a defense-in-depth measure and indicates a bug in just-bash. Please report this at security@vercel.com`,le=class extends Error{violation;constructor(t,s){super(t+Fo),this.violation=s,this.name="SecurityViolationError"}},he=!mt&&an?new an:null,Wo=1e3,on={enabled:!0,auditMode:!1};function Vo(e){return e===void 0?{...on,enabled:!1}:typeof e=="boolean"?{...on,enabled:e}:{...on,...e}}var Kt=class e{static instance=null;config;refCount=0;originalDescriptors=[];violations=[];activationTime=0;totalActiveTimeMs=0;constructor(t){this.config=t}static getInstance(t){return e.instance||(e.instance=new e(Vo(t))),e.instance}static resetInstance(){e.instance&&(e.instance.forceDeactivate(),e.instance=null)}static isInSandboxedContext(){return he?he?.getStore()?.sandboxActive===!0:!1}static getCurrentExecutionId(){if(he)return he?.getStore()?.executionId}updateConfig(t){this.config={...this.config,...t}}activate(){if(mt||!this.config.enabled){let s=ei();return{run:n=>n(),deactivate:()=>{},executionId:s}}this.refCount++,this.refCount===1&&(this.applyPatches(),this.activationTime=Date.now());let t=ei();return{run:s=>he.run({sandboxActive:!0,executionId:t},s),deactivate:()=>{this.refCount--,this.refCount===0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount<0&&(this.refCount=0)},executionId:t}}forceDeactivate(){this.refCount>0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount=0}isActive(){return this.refCount>0}getStats(){return{violationsBlocked:this.violations.length,violations:[...this.violations],activeTimeMs:this.totalActiveTimeMs+(this.refCount>0?Date.now()-this.activationTime:0),refCount:this.refCount}}clearViolations(){this.violations=[]}getPathForTarget(t,s){return t===globalThis?`globalThis.${s}`:t===process?`process.${s}`:t===Error?`Error.${s}`:t===Function.prototype?`Function.prototype.${s}`:t===Object.prototype?`Object.prototype.${s}`:`<object>.${s}`}shouldBlock(){return mt||this.config.auditMode||!he?!1:he?.getStore()?.sandboxActive===!0}recordViolation(t,s,n){let r={timestamp:Date.now(),type:t,message:n,path:s,stack:new Error().stack,executionId:he?.getStore()?.executionId};if(this.violations.length<Wo&&this.violations.push(r),this.config.onViolation)try{this.config.onViolation(r)}catch(i){console.debug("[DefenseInDepthBox] onViolation callback threw:",i instanceof Error?i.message:i)}return r}createBlockingProxy(t,s,n){let r=this;return new Proxy(t,{apply(i,o,a){if(r.shouldBlock()){let c=`${s} is blocked during script execution`,u=r.recordViolation(n,s,c);throw new le(c,u)}return r.config.auditMode&&he?.getStore()?.sandboxActive===!0&&r.recordViolation(n,s,`${s} called (audit mode)`),Reflect.apply(i,o,a)},construct(i,o,a){if(r.shouldBlock()){let c=`${s} constructor is blocked during script execution`,u=r.recordViolation(n,s,c);throw new le(c,u)}return r.config.auditMode&&he?.getStore()?.sandboxActive===!0&&r.recordViolation(n,s,`${s} constructor called (audit mode)`),Reflect.construct(i,o,a)}})}createBlockingObjectProxy(t,s,n){let r=this;return new Proxy(t,{get(i,o,a){if(r.shouldBlock()){let c=`${s}.${String(o)}`,u=`${c} is blocked during script execution`,l=r.recordViolation(n,c,u);throw new le(u,l)}if(r.config.auditMode&&he?.getStore()?.sandboxActive===!0){let c=`${s}.${String(o)}`;r.recordViolation(n,c,`${c} accessed (audit mode)`)}return Reflect.get(i,o,a)},set(i,o,a,c){if(r.shouldBlock()){let u=`${s}.${String(o)}`,l=`${u} modification is blocked during script execution`,f=r.recordViolation(n,u,l);throw new le(l,f)}return Reflect.set(i,o,a,c)},ownKeys(i){if(r.shouldBlock()){let o=`${s} enumeration is blocked during script execution`,a=r.recordViolation(n,s,o);throw new le(o,a)}return Reflect.ownKeys(i)},getOwnPropertyDescriptor(i,o){if(r.shouldBlock()){let a=`${s}.${String(o)}`,c=`${a} descriptor access is blocked during script execution`,u=r.recordViolation(n,a,c);throw new le(c,u)}return Reflect.getOwnPropertyDescriptor(i,o)},has(i,o){if(r.shouldBlock()){let a=`${s}.${String(o)}`,c=`${a} existence check is blocked during script execution`,u=r.recordViolation(n,a,c);throw new le(c,u)}return Reflect.has(i,o)}})}applyPatches(){let t=Jr();for(let s of t)this.applyPatch(s);this.protectConstructorChain(),this.protectErrorPrepareStackTrace(),this.protectModuleLoad(),this.protectProcessMainModule()}protectConstructorChain(){this.patchPrototypeConstructor(Function.prototype,"Function.prototype.constructor","function_constructor");try{let t=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&this.patchPrototypeConstructor(t.prototype,"AsyncFunction.prototype.constructor","async_function_constructor")}catch(t){console.debug("[DefenseInDepthBox] Could not patch AsyncFunction.prototype.constructor:",t instanceof Error?t.message:t)}try{let t=Object.getPrototypeOf(function*(){}).constructor;t&&t!==Function&&this.patchPrototypeConstructor(t.prototype,"GeneratorFunction.prototype.constructor","generator_function_constructor")}catch(t){console.debug("[DefenseInDepthBox] Could not patch GeneratorFunction.prototype.constructor:",t instanceof Error?t.message:t)}try{let t=Object.getPrototypeOf(async function*(){}).constructor,s=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&t!==s&&this.patchPrototypeConstructor(t.prototype,"AsyncGeneratorFunction.prototype.constructor","async_generator_function_constructor")}catch(t){console.debug("[DefenseInDepthBox] Could not patch AsyncGeneratorFunction.prototype.constructor:",t instanceof Error?t.message:t)}}protectErrorPrepareStackTrace(){let t=this;try{let s=Object.getOwnPropertyDescriptor(Error,"prepareStackTrace");this.originalDescriptors.push({target:Error,prop:"prepareStackTrace",descriptor:s});let n=s?.value;Object.defineProperty(Error,"prepareStackTrace",{get(){return n},set(r){if(t.shouldBlock()){let i="Error.prepareStackTrace modification is blocked during script execution",o=t.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace",i);throw new le(i,o)}t.config.auditMode&&he?.getStore()?.sandboxActive===!0&&t.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace","Error.prepareStackTrace set (audit mode)"),n=r},configurable:!0})}catch(s){console.debug("[DefenseInDepthBox] Could not protect Error.prepareStackTrace:",s instanceof Error?s.message:s)}}patchPrototypeConstructor(t,s,n){let r=this;try{let i=Object.getOwnPropertyDescriptor(t,"constructor");this.originalDescriptors.push({target:t,prop:"constructor",descriptor:i});let o=i?.value;Object.defineProperty(t,"constructor",{get(){if(r.shouldBlock()){let a=`${s} access is blocked during script execution`,c=r.recordViolation(n,s,a);throw new le(a,c)}return r.config.auditMode&&he?.getStore()?.sandboxActive===!0&&r.recordViolation(n,s,`${s} accessed (audit mode)`),o},set(a){if(r.shouldBlock()){let c=`${s} modification is blocked during script execution`,u=r.recordViolation(n,s,c);throw new le(c,u)}Object.defineProperty(this,"constructor",{value:a,writable:!0,configurable:!0})},configurable:!0})}catch(i){console.debug(`[DefenseInDepthBox] Could not patch ${s}:`,i instanceof Error?i.message:i)}}protectProcessMainModule(){if(typeof process>"u")return;let t=this;try{let s=Object.getOwnPropertyDescriptor(process,"mainModule");this.originalDescriptors.push({target:process,prop:"mainModule",descriptor:s});let n=s?.value;n!==void 0&&Object.defineProperty(process,"mainModule",{get(){if(t.shouldBlock()){let r="process.mainModule access is blocked during script execution",i=t.recordViolation("process_main_module","process.mainModule",r);throw new le(r,i)}return t.config.auditMode&&he?.getStore()?.sandboxActive===!0&&t.recordViolation("process_main_module","process.mainModule","process.mainModule accessed (audit mode)"),n},set(r){if(t.shouldBlock()){let i="process.mainModule modification is blocked during script execution",o=t.recordViolation("process_main_module","process.mainModule",i);throw new le(i,o)}Object.defineProperty(process,"mainModule",{value:r,writable:!0,configurable:!0})},configurable:!0})}catch(s){console.debug("[DefenseInDepthBox] Could not protect process.mainModule:",s instanceof Error?s.message:s)}}protectModuleLoad(){if(!mt)try{let t=null;if(typeof process<"u"){let o=process.mainModule;o&&typeof o=="object"&&(t=o.constructor)}if(!t&&typeof yt<"u"&&typeof yt.main<"u"&&(t=yt.main.constructor),!t||typeof t._load!="function")return;let s=t._load,n=Object.getOwnPropertyDescriptor(t,"_load");this.originalDescriptors.push({target:t,prop:"_load",descriptor:n});let i=this.createBlockingProxy(s,"Module._load","module_load");Object.defineProperty(t,"_load",{value:i,writable:!0,configurable:!0})}catch(t){console.debug("[DefenseInDepthBox] Could not protect Module._load:",t instanceof Error?t.message:t)}}applyPatch(t){let{target:s,prop:n,violationType:r,strategy:i}=t;try{let o=s[n];if(o===void 0)return;let a=Object.getOwnPropertyDescriptor(s,n);if(this.originalDescriptors.push({target:s,prop:n,descriptor:a}),i==="freeze")typeof o=="object"&&o!==null&&Object.freeze(o);else{let c=this.getPathForTarget(s,n),u=typeof o=="function"?this.createBlockingProxy(o,c,r):this.createBlockingObjectProxy(o,c,r);Object.defineProperty(s,n,{value:u,writable:!0,configurable:!0})}}catch(o){let a=this.getPathForTarget(s,n);console.debug(`[DefenseInDepthBox] Could not patch ${a}:`,o instanceof Error?o.message:o)}}restorePatches(){for(let t=this.originalDescriptors.length-1;t>=0;t--){let{target:s,prop:n,descriptor:r}=this.originalDescriptors[t];try{r?Object.defineProperty(s,n,r):delete s[n]}catch(i){let o=this.getPathForTarget(s,n);console.debug(`[DefenseInDepthBox] Could not restore ${o}:`,i instanceof Error?i.message:i)}}this.originalDescriptors=[]}};var Xt=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;state;constructor(t={}){let s=t.fs??new nt(t.files);this.fs=s,this.useDefaultLayout=!t.cwd&&!t.files;let n=t.cwd||(this.useDefaultLayout?"/home/user":"/"),r=new Map,i=[["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
676
+ `],["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"],["PWD",n],["OLDPWD",n],["OPTIND","1"]];for(let[o,a]of i)v(r,o,a);for(let[o,a]of Object.entries(t.env??{}))v(r,o,a);if(this.limits=Kr({...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=rn(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth,this.coverageWriter=t.coverage,this.state={env:r,cwd:n,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:p,startTime:Date.now(),lastBackgroundPid:0,bashPid:Jt().pid,nextVirtualPid:Jt().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},v(this.state.env,"SHELLOPTS",ls(this.state.options)),v(this.state.env,"BASHOPTS",cs(this.state.shoptOptions)),Tn(s,this.useDefaultLayout),n!=="/"&&s instanceof nt)try{s.mkdirSync(n,{recursive:!0})}catch{}for(let o of Cn(t.commands))this.registerCommand(o);if(t.network)for(let o of kn())this.registerCommand(o);if(t.python)for(let o of Nn())this.registerCommand(o);if(t.customCommands)for(let o of t.customCommands)On(o)?this.registerCommand(xn(o)):this.registerCommand(o)}registerCommand(t){this.commands.set(t.name,t);let s=this.fs;if(typeof s.writeFileSync=="function"){let n=`#!/bin/bash
677
677
  # Built-in command: ${t.name}
678
678
  `;try{s.writeFileSync(`/bin/${t.name}`,n)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,n)}catch{}}}logResult(t){return this.logger&&(t.stdout.length>0&&this.logger.debug("stdout",{output:z(t.stdout)}),t.stderr.length>0&&this.logger.info("stderr",{output:z(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:p,stderr:E(`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option.
679
- `),exitCode:1,env:Ee(this.state.env,s?.env)};if(!t.trim())return{stdout:p,stderr:p,exitCode:0,env:Ee(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=new Map(this.state.env);if(s?.env)for(let[f,d]of Object.entries(s.env))v(o,f,d);r!==void 0&&v(o,"PWD",r);let a={...this.state,env:o,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:s?.stdin||void 0},c=t;s?.rawScript||(c=Vo(t));let l=(this.defenseInDepthConfig?Kt.getInstance(this.defenseInDepthConfig):null)?.activate();try{let f=async()=>{let d=Ae(c),h={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter},m=await new ut(h,a).executeScript(d);return this.logResult(m)};return l?await l.run(f):await f()}catch(f){if(f instanceof G)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:Ee(this.state.env,s?.env)});if(f instanceof we)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:Ee(this.state.env,s?.env)});if(f instanceof Fe)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:1,env:Ee(this.state.env,s?.env)});if(f instanceof oe)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:oe.EXIT_CODE,env:Ee(this.state.env,s?.env)});if(f instanceof le)return this.logResult({stdout:p,stderr:E(`bash: security violation: ${f.message}
679
+ `),exitCode:1,env:Ee(this.state.env,s?.env)};if(!t.trim())return{stdout:p,stderr:p,exitCode:0,env:Ee(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=new Map(this.state.env);if(s?.env)for(let[f,d]of Object.entries(s.env))v(o,f,d);r!==void 0&&v(o,"PWD",r);let a={...this.state,env:o,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:s?.stdin||void 0},c=t;s?.rawScript||(c=zo(t));let l=(this.defenseInDepthConfig?Kt.getInstance(this.defenseInDepthConfig):null)?.activate();try{let f=async()=>{let d=Ae(c),h={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter},m=await new ut(h,a).executeScript(d);return this.logResult(m)};return l?await l.run(f):await f()}catch(f){if(f instanceof G)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:Ee(this.state.env,s?.env)});if(f instanceof we)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:Ee(this.state.env,s?.env)});if(f instanceof Fe)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:1,env:Ee(this.state.env,s?.env)});if(f instanceof oe)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:oe.EXIT_CODE,env:Ee(this.state.env,s?.env)});if(f instanceof le)return this.logResult({stdout:p,stderr:E(`bash: security violation: ${f.message}
680
680
  `),exitCode:1,env:Ee(this.state.env,s?.env)});if(f.name==="ParseException")return this.logResult({stdout:p,stderr:E(`bash: syntax error: ${f.message}
681
- `),exitCode:2,env:Ee(this.state.env,s?.env)});if(f instanceof hn)return this.logResult({stdout:p,stderr:E(`bash: ${f.message}
681
+ `),exitCode:2,env:Ee(this.state.env,s?.env)});if(f instanceof pn)return this.logResult({stdout:p,stderr:E(`bash: ${f.message}
682
682
  `),exitCode:2,env:Ee(this.state.env,s?.env)});if(f instanceof RangeError)return this.logResult({stdout:p,stderr:E(`bash: ${f.message}
683
- `),exitCode:1,env:Ee(this.state.env,s?.env)});throw f}finally{l?.deactivate()}}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 De(this.state.env)}};function Vo(e){let t=e.split(`
683
+ `),exitCode:1,env:Ee(this.state.env,s?.env)});throw f}finally{l?.deactivate()}}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 De(this.state.env)}};function zo(e){let t=e.split(`
684
684
  `),s=[],n=[];for(let r=0;r<t.length;r++){let i=t[r];if(n.length>0){let c=n[n.length-1];if((c.stripTabs?i.replace(/^\t+/,""):i)===c.delimiter){s.push(i.trimStart()),n.pop();continue}s.push(i);continue}let o=i.trimStart();s.push(o);let a=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let c of o.matchAll(a)){let u=c[1]==="-",l=c[3];n.push({delimiter:l,stripTabs:u})}}return s.join(`
685
- `)}import*as J from"node:fs";import*as Je from"node:path";var zo="/home/user/project";function re(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}var Qt=class{root;mountPoint;readOnly;maxFileReadSize;memory=new Map;deleted=new Set;constructor(t){this.root=Je.resolve(t.root);let s=t.mountPoint??zo;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,this.maxFileReadSize=t.maxFileReadSize??10485760,!J.existsSync(this.root))throw new Error(`OverlayFs root does not exist: ${this.root}`);if(!J.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 J.promises.access(n),!0}catch{return!1}}async readFile(t,s){let n=await this.readFileBuffer(t),r=Re(s);return At(n,r)}async readFileBuffer(t,s=new Set){re(t,"open");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 J.promises.lstat(i);if(o.isSymbolicLink()){let c=await J.promises.readlink(i),u=this.resolveSymlink(n,c);return this.readFileBuffer(u,s)}if(o.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(this.maxFileReadSize>0&&o.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${o.size} bytes, max ${this.maxFileReadSize})`);let a=await J.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){re(t,"write"),this.assertWritable(`write '${t}'`);let r=this.normalizePath(t);this.ensureParentDirs(r);let i=Re(n),o=Ge(s,i);this.memory.set(r,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(r)}async appendFile(t,s,n){re(t,"append"),this.assertWritable(`append '${t}'`);let r=this.normalizePath(t),i=Re(n),o=Ge(s,i),a;try{a=await this.readFileBuffer(r)}catch{a=new Uint8Array(0)}let c=new Uint8Array(a.length+o.length);c.set(a),c.set(o,a.length),this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:c,mode:420,mtime:new Date}),this.deleted.delete(r)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,s=new Set){re(t,"stat");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 J.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){re(t,"lstat");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 J.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){re(t,"mkdir"),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 c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&r.add(u)}for(let[a,c]of this.memory)if(a!==s&&a.startsWith(i)){let u=a.slice(i.length),l=u.split("/")[0];l&&!r.has(l)&&!u.includes("/",1)&&n.set(l,{name:l,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}let o=this.toRealPath(s);if(o)try{let a=await J.promises.readdir(o,{withFileTypes:!0});for(let c of a)!r.has(c.name)&&!n.has(c.name)&&n.set(c.name,{name:c.name,isFile:c.isFile(),isDirectory:c.isDirectory(),isSymbolicLink:c.isSymbolicLink()})}catch(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 c=this.toRealPath(n);if(!c)return{normalized:n,outsideOverlay:!0};try{if((await J.promises.lstat(c)).isSymbolicLink()){let l=await J.promises.readlink(c),f=this.resolveSymlink(n,l);return this.resolveForReaddir(f,!0)}return{normalized:n,outsideOverlay:!1}}catch{return i?{normalized:n,outsideOverlay:!0}:{normalized:n,outsideOverlay:!1}}}async readdir(t){re(t,"scandir");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){re(t,"scandir");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){re(t,"rm"),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 c=n==="/"?`/${a}`:`${n}/${a}`;await this.rm(c,s)}}}}catch{}this.deleted.add(n),this.memory.delete(n)}async cp(t,s,n){re(t,"cp"),re(s,"cp"),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 c=await this.readFileBuffer(r);await this.writeFile(i,c)}else if(a.isDirectory){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let c=await this.readdir(r);for(let u of c){let l=r==="/"?`/${u}`:`${r}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(l,f,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=J.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);J.statSync(a).isDirectory()&&this.scanRealFs(o,s)}}catch{}}async chmod(t,s){re(t,"chmod"),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){re(s,"symlink"),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){re(t,"link"),re(s,"link"),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 c=await this.readFileBuffer(n);this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:c,mode:o.mode,mtime:new Date}),this.deleted.delete(r)}async readlink(t){re(t,"readlink");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 J.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){re(t,"realpath");let s=this.normalizePath(t),n=new Set,r=async a=>{let c=a==="/"?[]:a.slice(1).split("/"),u="";for(let l of c){if(u=`${u}/${l}`,n.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(u),d=0,h=40;for(;f&&f.type==="symlink"&&d<h;){if(n.add(u),u=this.resolveSymlink(u,f.target),d++,n.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(u)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let g=this.toRealPath(u);if(g)try{if((await J.promises.lstat(g)).isSymbolicLink()){let w=await J.promises.readlink(g);return n.add(u),u=this.resolveSymlink(u,w),r(u)}}catch(m){throw m.code==="ENOENT"?new Error(`ENOENT: no such file or directory, realpath '${t}'`):m}}}return u||"/"},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){re(t,"utimes"),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 c=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:c,mode:a.mode,mtime:n})}else a.isDirectory&&this.memory.set(r,{type:"directory",mode:a.mode,mtime:n})}};var se={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"},ln=class{env;rl;running=!0;history=[];isInteractive;constructor(t={}){let s=process.cwd(),n=new Qt({root:s,mountPoint:"/"});this.env=new Xt({fs:n,cwd:t.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...t.env},network:t.network!==!1?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.isInteractive=process.stdin.isTTY===!0,this.rl=ti.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C
685
+ `)}import*as J from"node:fs";import*as Je from"node:path";var Bo="/home/user/project";function re(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}var Qt=class{root;mountPoint;readOnly;maxFileReadSize;memory=new Map;deleted=new Set;constructor(t){this.root=Je.resolve(t.root);let s=t.mountPoint??Bo;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,this.maxFileReadSize=t.maxFileReadSize??10485760,!J.existsSync(this.root))throw new Error(`OverlayFs root does not exist: ${this.root}`);if(!J.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 J.promises.access(n),!0}catch{return!1}}async readFile(t,s){let n=await this.readFileBuffer(t),r=Re(s);return At(n,r)}async readFileBuffer(t,s=new Set){re(t,"open");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 J.promises.lstat(i);if(o.isSymbolicLink()){let c=await J.promises.readlink(i),u=this.resolveSymlink(n,c);return this.readFileBuffer(u,s)}if(o.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(this.maxFileReadSize>0&&o.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${o.size} bytes, max ${this.maxFileReadSize})`);let a=await J.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){re(t,"write"),this.assertWritable(`write '${t}'`);let r=this.normalizePath(t);this.ensureParentDirs(r);let i=Re(n),o=Ge(s,i);this.memory.set(r,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(r)}async appendFile(t,s,n){re(t,"append"),this.assertWritable(`append '${t}'`);let r=this.normalizePath(t),i=Re(n),o=Ge(s,i),a;try{a=await this.readFileBuffer(r)}catch{a=new Uint8Array(0)}let c=new Uint8Array(a.length+o.length);c.set(a),c.set(o,a.length),this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:c,mode:420,mtime:new Date}),this.deleted.delete(r)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,s=new Set){re(t,"stat");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 J.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){re(t,"lstat");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 J.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){re(t,"mkdir"),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 c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&r.add(u)}for(let[a,c]of this.memory)if(a!==s&&a.startsWith(i)){let u=a.slice(i.length),l=u.split("/")[0];l&&!r.has(l)&&!u.includes("/",1)&&n.set(l,{name:l,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}let o=this.toRealPath(s);if(o)try{let a=await J.promises.readdir(o,{withFileTypes:!0});for(let c of a)!r.has(c.name)&&!n.has(c.name)&&n.set(c.name,{name:c.name,isFile:c.isFile(),isDirectory:c.isDirectory(),isSymbolicLink:c.isSymbolicLink()})}catch(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 c=this.toRealPath(n);if(!c)return{normalized:n,outsideOverlay:!0};try{if((await J.promises.lstat(c)).isSymbolicLink()){let l=await J.promises.readlink(c),f=this.resolveSymlink(n,l);return this.resolveForReaddir(f,!0)}return{normalized:n,outsideOverlay:!1}}catch{return i?{normalized:n,outsideOverlay:!0}:{normalized:n,outsideOverlay:!1}}}async readdir(t){re(t,"scandir");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){re(t,"scandir");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){re(t,"rm"),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 c=n==="/"?`/${a}`:`${n}/${a}`;await this.rm(c,s)}}}}catch{}this.deleted.add(n),this.memory.delete(n)}async cp(t,s,n){re(t,"cp"),re(s,"cp"),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 c=await this.readFileBuffer(r);await this.writeFile(i,c)}else if(a.isDirectory){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let c=await this.readdir(r);for(let u of c){let l=r==="/"?`/${u}`:`${r}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(l,f,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=J.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);J.statSync(a).isDirectory()&&this.scanRealFs(o,s)}}catch{}}async chmod(t,s){re(t,"chmod"),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){re(s,"symlink"),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){re(t,"link"),re(s,"link"),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 c=await this.readFileBuffer(n);this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:c,mode:o.mode,mtime:new Date}),this.deleted.delete(r)}async readlink(t){re(t,"readlink");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 J.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){re(t,"realpath");let s=this.normalizePath(t),n=new Set,r=async a=>{let c=a==="/"?[]:a.slice(1).split("/"),u="";for(let l of c){if(u=`${u}/${l}`,n.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(u),d=0,h=40;for(;f&&f.type==="symlink"&&d<h;){if(n.add(u),u=this.resolveSymlink(u,f.target),d++,n.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(u)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let g=this.toRealPath(u);if(g)try{if((await J.promises.lstat(g)).isSymbolicLink()){let w=await J.promises.readlink(g);return n.add(u),u=this.resolveSymlink(u,w),r(u)}}catch(m){throw m.code==="ENOENT"?new Error(`ENOENT: no such file or directory, realpath '${t}'`):m}}}return u||"/"},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){re(t,"utimes"),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 c=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:c,mode:a.mode,mtime:n})}else a.isDirectory&&this.memory.set(r,{type:"directory",mode:a.mode,mtime:n})}};var se={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"},ln=class{env;rl;running=!0;history=[];isInteractive;constructor(t={}){let s=process.cwd(),n=new Qt({root:s,mountPoint:"/"});this.env=new Xt({fs:n,cwd:t.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...t.env},network:t.network!==!1?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.isInteractive=process.stdin.isTTY===!0,this.rl=si.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C
686
686
  `),this.prompt()}),process.stdin.isTTY&&this.rl.on("close",()=>{this.running=!1,console.log(`
687
687
  Goodbye!`),process.exit(0)})}syncHistory(){let t=this.env.getEnv();t.BASH_HISTORY=JSON.stringify(this.history)}getPrompt(){let t=this.env.getCwd(),s=this.env.getEnv().HOME||"/home/user",n=t;return t===s?n="~":t.startsWith(`${s}/`)&&(n=`~${t.slice(s.length)}`),`${se.green}${se.bold}user@virtual${se.reset}:${se.blue}${se.bold}${n}${se.reset}$ `}async executeCommand(t){let s=t.trim();if(s){if(this.history.push(s),s==="exit"||s.startsWith("exit ")){let n=s.split(/\s+/),r=n[1]?parseInt(n[1],10):0;console.log("exit"),process.exit(r)}this.syncHistory();try{let n=await this.env.exec(s);n.stdout.length>0&&process.stdout.write(n.stdout),n.stderr.length>0&&process.stderr.write(`${se.red}${z(n.stderr)}${se.reset}`)}catch(n){console.error(`${se.red}Error: ${be(n)}${se.reset}`)}}}printWelcome(){console.log(`
688
688
  ${se.cyan}${se.bold}\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
@@ -694,7 +694,7 @@ ${se.dim}Exploring: ${process.cwd()}${se.reset}
694
694
 
695
695
  Type ${se.green}help${se.reset} for available commands, ${se.green}exit${se.reset} to quit.
696
696
  Reads from real filesystem, writes stay in memory (OverlayFs).
697
- `)}prompt(){this.rl.question(this.getPrompt(),async t=>{this.running&&(await this.executeCommand(t),this.prompt())})}async run(){if(this.isInteractive)this.printWelcome(),this.prompt();else{let t=[];this.rl.on("line",s=>{t.push(s)}),await new Promise(s=>{this.rl.on("close",s)});for(let s of t)await this.executeCommand(s)}}};function Bo(){let e=process.argv.slice(2),t={network:!0};for(let s=0;s<e.length;s++)if(e[s]==="--cwd"&&e[s+1])t.cwd=e[++s];else if(e[s]==="--files"&&e[s+1]){let n=e[++s];try{let r=ei.readFileSync(n,"utf-8");t.files=JSON.parse(r)}catch(r){console.error(`Error reading files from ${n}:`,r),process.exit(1)}}else e[s]==="--no-network"?t.network=!1:(e[s]==="--help"||e[s]==="-h")&&(console.log(`
697
+ `)}prompt(){this.rl.question(this.getPrompt(),async t=>{this.running&&(await this.executeCommand(t),this.prompt())})}async run(){if(this.isInteractive)this.printWelcome(),this.prompt();else{let t=[];this.rl.on("line",s=>{t.push(s)}),await new Promise(s=>{this.rl.on("close",s)});for(let s of t)await this.executeCommand(s)}}};function jo(){let e=process.argv.slice(2),t={network:!0};for(let s=0;s<e.length;s++)if(e[s]==="--cwd"&&e[s+1])t.cwd=e[++s];else if(e[s]==="--files"&&e[s+1]){let n=e[++s];try{let r=ti.readFileSync(n,"utf-8");t.files=JSON.parse(r)}catch(r){console.error(`Error reading files from ${n}:`,r),process.exit(1)}}else e[s]==="--no-network"?t.network=!1:(e[s]==="--help"||e[s]==="-h")&&(console.log(`
698
698
  Usage: pnpm shell [options]
699
699
 
700
700
  Interactive shell using OverlayFs - reads from the current directory,
@@ -708,4 +708,4 @@ Options:
708
708
  Example:
709
709
  pnpm shell
710
710
  pnpm shell --no-network
711
- `),process.exit(0));return t}var jo=Bo(),Ho=new ln(jo);Ho.run();
711
+ `),process.exit(0));return t}var Ho=jo(),Uo=new ln(Ho);Uo.run();