just-bash 3.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/dist/bin/chunks/{chunk-4J4UC7OD.js → chunk-63LSI3D6.js} +1 -1
  3. package/dist/bin/chunks/chunk-BKQLXMS6.js +36 -0
  4. package/dist/bin/{shell/chunks/chunk-J7XTZ47D.js → chunks/chunk-HZR3FOJM.js} +1 -1
  5. package/dist/bin/chunks/chunk-ISLENKSH.js +7 -0
  6. package/dist/bin/chunks/{chunk-FJABJBIW.js → chunk-RO3XCUVQ.js} +1 -1
  7. package/dist/bin/chunks/{flag-coverage-H6NG6ZQL.js → flag-coverage-CAST5CDE.js} +1 -1
  8. package/dist/bin/chunks/{jq-33GJJXTL.js → jq-3V5HDGLJ.js} +1 -1
  9. package/dist/bin/{shell/chunks/rg-2YWJS6TE.js → chunks/rg-DZKA632H.js} +1 -1
  10. package/dist/bin/{shell/chunks/xan-TSDTZVY3.js → chunks/xan-TCTFON2Q.js} +1 -1
  11. package/dist/bin/chunks/{yq-KU5YTNAK.js → yq-OB6PB5GY.js} +1 -1
  12. package/dist/bin/just-bash.js +378 -304
  13. package/dist/bin/shell/chunks/{chunk-4J4UC7OD.js → chunk-63LSI3D6.js} +1 -1
  14. package/dist/bin/shell/chunks/chunk-BKQLXMS6.js +36 -0
  15. package/dist/bin/{chunks/chunk-J7XTZ47D.js → shell/chunks/chunk-HZR3FOJM.js} +1 -1
  16. package/dist/bin/shell/chunks/chunk-ISLENKSH.js +7 -0
  17. package/dist/bin/shell/chunks/{chunk-FJABJBIW.js → chunk-RO3XCUVQ.js} +1 -1
  18. package/dist/bin/shell/chunks/{flag-coverage-H6NG6ZQL.js → flag-coverage-CAST5CDE.js} +1 -1
  19. package/dist/bin/shell/chunks/{jq-33GJJXTL.js → jq-3V5HDGLJ.js} +1 -1
  20. package/dist/bin/{chunks/rg-2YWJS6TE.js → shell/chunks/rg-DZKA632H.js} +1 -1
  21. package/dist/bin/{chunks/xan-TSDTZVY3.js → shell/chunks/xan-TCTFON2Q.js} +1 -1
  22. package/dist/bin/shell/chunks/{yq-KU5YTNAK.js → yq-OB6PB5GY.js} +1 -1
  23. package/dist/bin/shell/shell.js +383 -309
  24. package/dist/bundle/browser.js +580 -581
  25. package/dist/bundle/chunks/{chunk-DJ7QC6LC.js → chunk-6Y4TGEZL.js} +1 -1
  26. package/dist/bundle/chunks/chunk-J3LJZWL2.js +6 -0
  27. package/dist/bundle/chunks/{chunk-AFQAPVZ3.js → chunk-JA7M2FXG.js} +1 -1
  28. package/dist/bundle/chunks/chunk-JNYYVLEL.js +35 -0
  29. package/dist/bundle/chunks/{chunk-EUCNMMRD.js → chunk-QM4DZQWX.js} +1 -1
  30. package/dist/bundle/chunks/{flag-coverage-TRYUZMPS.js → flag-coverage-OHLSWDU5.js} +1 -1
  31. package/dist/bundle/chunks/{jq-3FAAQVR6.js → jq-OPEF5OPR.js} +1 -1
  32. package/dist/bundle/chunks/{rg-N5WLPMSA.js → rg-EBMD72T4.js} +1 -1
  33. package/dist/bundle/chunks/{xan-U6654PZR.js → xan-LKYWG2QQ.js} +1 -1
  34. package/dist/bundle/chunks/{yq-ZBXLBSXV.js → yq-TVZ7R3O7.js} +1 -1
  35. package/dist/bundle/index.cjs +755 -756
  36. package/dist/bundle/index.js +382 -308
  37. package/dist/sandbox/Sandbox.d.ts +33 -2
  38. package/package.json +1 -1
  39. package/dist/bin/chunks/chunk-GXX3QUMM.js +0 -34
  40. package/dist/bin/chunks/chunk-LMA4D2KK.js +0 -7
  41. package/dist/bin/chunks/chunk-PDS5TEMS.js +0 -80
  42. package/dist/bin/chunks/expansion-PCODPDNZ.js +0 -3
  43. package/dist/bin/shell/chunks/chunk-GXX3QUMM.js +0 -34
  44. package/dist/bin/shell/chunks/chunk-LMA4D2KK.js +0 -7
  45. package/dist/bin/shell/chunks/chunk-PDS5TEMS.js +0 -80
  46. package/dist/bin/shell/chunks/expansion-PCODPDNZ.js +0 -3
  47. package/dist/bundle/chunks/chunk-LZUPLYFM.js +0 -6
  48. package/dist/bundle/chunks/chunk-STFC2ZJT.js +0 -79
  49. package/dist/bundle/chunks/chunk-Z3KJQD7F.js +0 -33
  50. package/dist/bundle/chunks/expansion-CDGKP4VC.js +0 -2
@@ -1,159 +1,233 @@
1
1
  #!/usr/bin/env node
2
2
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{B as Gn,C as Kn,D as ue,E as Ze,F as ee,G as Ae,H as Ft,I as Xn,J as I,K as Yn,L as Qn,M as ke,N as ks,O as Mt,P as j,a as zn,b as $s,c as Vn,d as Rt,e as Q,f as V,g as Ee,h as ne,i as Ce,j as Me,k as Es,l as Lt,m as Bn,n as Ss,o as jn,p as ge,q as Ie,r as Hn,s as Un,t as As,u as _s,v as We,w as Zn,x as qn,y as Se,z as Cs}from"./chunks/chunk-PDS5TEMS.js";import{a as et,b as tt,c as Fe}from"./chunks/chunk-O2BCKSMK.js";import{c as bs}from"./chunks/chunk-NYIPFY36.js";import{a as xn,b as Rn}from"./chunks/chunk-UNWZQG7U.js";import{a as Le,b as ye,c as vs}from"./chunks/chunk-MROECM42.js";import{a as yt,b as Wn}from"./chunks/chunk-AZH64XMJ.js";import{a as Je,b as be}from"./chunks/chunk-LX2H4DPL.js";import{a as mt}from"./chunks/chunk-52FZYTIX.js";import{b as He,d as Ln,e as gs,f as ws}from"./chunks/chunk-DHIKZU63.js";import{a as de,b as he,c as ce,d as pe,e as Fn,f as B,g as Ue,h as Dt,i as Tt,j as Mn,k as Y,l as It,m as Re,n as xt,o as me}from"./chunks/chunk-47WZ2U6M.js";import"./chunks/chunk-7JZKVC3F.js";import{a as Te}from"./chunks/chunk-PBOVSFTJ.js";import{a as $e}from"./chunks/chunk-I4IRHQDW.js";import{a as In}from"./chunks/chunk-LNVSXNT7.js";import*as Gi from"node:fs";import*as Ki from"node:readline";var st=[{name:"echo",load:async()=>(await import("./chunks/echo-KCOHTNDF.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-NBL6MU5H.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-MR3FXCDE.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-KBNHNZWQ.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-P4DKRCDX.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-DLOHIA7Q.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-DFGSVIX7.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-ECNUFR66.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-HYXTMN3D.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-QQK4FQX6.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-LP4HMCSM.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-S564JCJW.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-FCNDA467.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-25V57VOL.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-B6GFQHKF.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-24F643A4.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-4HXNTHY3.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-BD6KT3BP.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-2YWJS6TE.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-IGRH7EGG.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-UFCNQFCV.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-HQPAFL76.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-Q5UH5NL3.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-PLYUTVP3.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-JNQTCQY7.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-LYNFXXCM.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-QQZYZ3CH.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-AJECDD4L.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-6TVYE4ZB.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-7YEITA5L.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-CB7FG7LQ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-3JWOSSBQ.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-6PE3YMPO.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-F6FSB5KI.js")).split},{name:"column",load:async()=>(await import("./chunks/column-QLGOK3XM.js")).column},{name:"join",load:async()=>(await import("./chunks/join-WRM6S6CO.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-5B7P2QRJ.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-5OZWMYCV.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-F3AQ4KAQ.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-VCINTLPD.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-6D7SMPUR.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-4LRQIGRG.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-FNVYNLGB.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-FNVYNLGB.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-YRVAW27Y.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-YRVAW27Y.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-AQQWW3QB.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-VTFN762K.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-SKL4L7JP.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-SKL4L7JP.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-FGNEKYDU.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-BEG4JB7K.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-BEG4JB7K.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-33GJJXTL.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-EGKVQIBC.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-LZ4WRLIF.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-OFYBOAUE.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-RPGCUUGX.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-ZARIAF3K.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-FN6VJGRS.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-UXDJE6FB.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-6A2XZORA.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-ZNYCDRQL.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-5QZSNFY3.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-DI7JAVAU.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-GRZLWDVH.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-3HJ7L7NL.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-CGUEOGXQ.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-LCXKCLFC.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-NERJXVOM.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-USNWOQCK.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-TZDZDU7T.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-Y3E3QXOL.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(st.push({name:"tar",load:async()=>(await import("./chunks/tar-5HK3VMV2.js")).tarCommand}),st.push({name:"yq",load:async()=>(await import("./chunks/yq-KU5YTNAK.js")).yqCommand}),st.push({name:"xan",load:async()=>(await import("./chunks/xan-TSDTZVY3.js")).xanCommand}),st.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-7TRACAE7.js")).sqlite3Command}));var Ps=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ps.push({name:"python3",load:async()=>(await import("./chunks/python3-R5OFWJIH.js")).python3Command}),Ps.push({name:"python",load:async()=>(await import("./chunks/python3-R5OFWJIH.js")).pythonCommand}));var Ns=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ns.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-F7JAZ4ZQ.js")).jsExecCommand}),Ns.push({name:"node",load:async()=>(await import("./chunks/js-exec-F7JAZ4ZQ.js")).nodeStubCommand}));var Ji=[{name:"curl",load:async()=>(await import("./chunks/curl-DCSPNPEW.js")).curlCommand}],Jn=new Map;function Wt(e){return{name:e.name,async execute(t,s){let n=Jn.get(e.name);if(n||(n=await be.runTrustedAsync(()=>e.load()),Jn.set(e.name,n)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:r}=await import("./chunks/flag-coverage-H6NG6ZQL.js");r(s.coverage,e.name,t)}return n.execute(t,s)}}}function er(e){return(e?st.filter(s=>e.includes(s.name)):st).map(Wt)}function tr(){return Ji.map(Wt)}function sr(){return Ps.map(Wt)}function nr(){return Ns.map(Wt)}function rr(e){return"load"in e&&typeof e.load=="function"}function ir(e){let t=null;return{name:e.name,trusted:!0,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}function L(e){if(!e||e==="/")return"/";let t=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;t.startsWith("/")||(t=`/${t}`);let s=t.split("/").filter(r=>r&&r!=="."),n=[];for(let r of s)r===".."?n.pop():n.push(r);return`/${n.join("/")}`||"/"}function W(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}function qe(e){let t=L(e);if(t==="/")return"/";let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}function zt(e,t){if(t.startsWith("/"))return L(t);let s=e==="/"?`/${t}`:`${e}/${t}`;return L(s)}function gt(e,t){return e==="/"?`/${t}`:`${e}/${t}`}function nt(e,t){if(t.startsWith("/"))return L(t);let s=qe(e);return L(gt(s,t))}var rt=new TextEncoder;function ea(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var wt=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))typeof n=="function"?this.writeFileLazy(s,n):ea(n)?this.writeFileSync(s,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(s,n)}ensureParentDirs(t){let s=qe(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){W(t,"write");let i=L(t);this.ensureParentDirs(i);let a=Fe(n),o=et(s,a);this.data.set(i,{type:"file",content:o,mode:r?.mode??420,mtime:r?.mtime??new Date})}writeFileLazy(t,s,n){W(t,"write");let r=L(t);this.ensureParentDirs(r),this.data.set(r,{type:"file",lazy:s,mode:n?.mode??420,mtime:n?.mtime??new Date})}async materializeLazy(t,s){let n=await s.lazy(),i={type:"file",content:typeof n=="string"?rt.encode(n):n,mode:s.mode,mtime:s.mtime};return this.data.set(t,i),i}async readFile(t,s){let n=await this.readFileBuffer(t),r=Fe(s);return tt(n,r)}async readFileBytes(t){let s=await this.readFileBuffer(t);return tt(s,"binary")}async readFileBuffer(t){W(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}'`);if("lazy"in n){let r=await this.materializeLazy(s,n);return r.content instanceof Uint8Array?r.content:rt.encode(r.content)}return n.content instanceof Uint8Array?n.content:rt.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){W(t,"append");let r=L(t),i=this.data.get(r);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let a=Fe(n),o=et(s,a);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(r,l));let c="content"in l&&l.content instanceof Uint8Array?l.content:rt.encode("content"in l?l.content:""),u=new Uint8Array(c.length+o.length);u.set(c),u.set(o,c.length),this.data.set(r,{type:"file",content:u,mode:l.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){W(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}'`);n.type==="file"&&"lazy"in n&&(n=await this.materializeLazy(s,n));let r=0;return n.type==="file"&&"content"in n&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=rt.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){W(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};n.type==="file"&&"lazy"in n&&(n=await this.materializeLazy(s,n));let r=0;return n.type==="file"&&"content"in n&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=rt.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}resolveIntermediateSymlinks(t){let s=L(t);if(s==="/")return"/";let n=s.slice(1).split("/");if(n.length<=1)return s;let r="",i=new Set;for(let a=0;a<n.length-1;a++){let o=n[a];r=`${r}/${o}`;let l=this.data.get(r),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(r),r=nt(r,l.target),l=this.data.get(r),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${r}/${n[n.length-1]}`}resolvePathWithSymlinks(t){let s=L(t);if(s==="/")return"/";let n=s.slice(1).split("/"),r="",i=new Set;for(let a of n){r=`${r}/${a}`;let o=this.data.get(r),l=0,c=40;for(;o&&o.type==="symlink"&&l<c;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(r),r=nt(r,o.target),o=this.data.get(r),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return r}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){W(t,"mkdir");let n=L(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=qe(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){W(t,"scandir");let s=L(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=nt(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,a=new Map;for(let[o,l]of this.data.entries())if(o!==s&&o.startsWith(i)){let c=o.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!a.has(u)&&a.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(a.values()).sort((o,l)=>o.name<l.name?-1:o.name>l.name?1:0)}async rm(t,s){W(t,"rm");let n=L(t),r=this.data.get(n);if(!r){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(r.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of i){let o=gt(n,a);await this.rm(o,s)}}}this.data.delete(n)}async cp(t,s,n){W(t,"cp"),W(s,"cp");let r=L(t),i=L(s),a=this.data.get(r);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(a.type==="file")if(this.ensureParentDirs(i),"content"in a){let o=a.content instanceof Uint8Array?new Uint8Array(a.content):a.content;this.data.set(i,{...a,content:o})}else this.data.set(i,{...a});else if(a.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(r);for(let l of o){let c=gt(r,l),u=gt(i,l);await this.cp(c,u,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){return zt(t,s)}async chmod(t,s){W(t,"chmod");let n=L(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){W(s,"symlink");let n=L(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){W(t,"link"),W(s,"link");let n=L(t),r=L(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}'`);let a=i;"lazy"in a&&(a=await this.materializeLazy(n,a)),this.ensureParentDirs(r),this.data.set(r,{type:"file",content:a.content,mode:a.mode,mtime:a.mtime})}async readlink(t){W(t,"readlink");let s=L(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){W(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){W(t,"utimes");let r=L(t),i=this.resolvePathWithSymlinks(r),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=n}};function ta(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function sa(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 na(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 ra(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${zn}
3
+ import{a as Rt,b as xt,c as ht}from"./chunks/chunk-O2BCKSMK.js";import{c as An}from"./chunks/chunk-NYIPFY36.js";import{a as hi,b as pi}from"./chunks/chunk-UNWZQG7U.js";import{a as dt,b as Fe,c as Sn}from"./chunks/chunk-MROECM42.js";import{a as Xt,b as gi}from"./chunks/chunk-AZH64XMJ.js";import{a as Ct,b as Be}from"./chunks/chunk-LX2H4DPL.js";import{a as ae}from"./chunks/chunk-52FZYTIX.js";import{b as At,d as mi,e as bn,f as vn}from"./chunks/chunk-DHIKZU63.js";import{a as Ie,b as Ce,c as Ne,d as We,e as Re,f as U,g as te,h as xe,i as ut,j as ws,k as Q,l as Es,m as ft,n as bs,o as Me}from"./chunks/chunk-47WZ2U6M.js";import"./chunks/chunk-7JZKVC3F.js";import{a as at}from"./chunks/chunk-PBOVSFTJ.js";import{a as qe}from"./chunks/chunk-I4IRHQDW.js";import{a as di}from"./chunks/chunk-LNVSXNT7.js";import*as mc from"node:fs";import*as gc from"node:readline";var Ot=[{name:"echo",load:async()=>(await import("./chunks/echo-KCOHTNDF.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-NBL6MU5H.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-MR3FXCDE.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-KBNHNZWQ.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-P4DKRCDX.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-DLOHIA7Q.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-DFGSVIX7.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-ECNUFR66.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-HYXTMN3D.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-QQK4FQX6.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-LP4HMCSM.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-S564JCJW.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-FCNDA467.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-25V57VOL.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-B6GFQHKF.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-24F643A4.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-4HXNTHY3.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-BD6KT3BP.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-KKBXRB73.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-DZKA632H.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-IGRH7EGG.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-UFCNQFCV.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-HQPAFL76.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-Q5UH5NL3.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-PLYUTVP3.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-JNQTCQY7.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-LYNFXXCM.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-QQZYZ3CH.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-AJECDD4L.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-6TVYE4ZB.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-7YEITA5L.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-CB7FG7LQ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-3JWOSSBQ.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-6PE3YMPO.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-F6FSB5KI.js")).split},{name:"column",load:async()=>(await import("./chunks/column-QLGOK3XM.js")).column},{name:"join",load:async()=>(await import("./chunks/join-WRM6S6CO.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-5B7P2QRJ.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-5OZWMYCV.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-F3AQ4KAQ.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-VCINTLPD.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-6D7SMPUR.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-4LRQIGRG.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-FNVYNLGB.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-FNVYNLGB.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-YRVAW27Y.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-YRVAW27Y.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-AQQWW3QB.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-VTFN762K.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-SKL4L7JP.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-SKL4L7JP.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-FGNEKYDU.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-BEG4JB7K.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-BEG4JB7K.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-3V5HDGLJ.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-EGKVQIBC.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-LZ4WRLIF.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-OFYBOAUE.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-RPGCUUGX.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-ZARIAF3K.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-FN6VJGRS.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-UXDJE6FB.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-6A2XZORA.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-ZNYCDRQL.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-5QZSNFY3.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-DI7JAVAU.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-GRZLWDVH.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-3HJ7L7NL.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-CGUEOGXQ.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-LCXKCLFC.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-NERJXVOM.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-USNWOQCK.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-TZDZDU7T.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-Y3E3QXOL.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-ZJP5VIAQ.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ot.push({name:"tar",load:async()=>(await import("./chunks/tar-5HK3VMV2.js")).tarCommand}),Ot.push({name:"yq",load:async()=>(await import("./chunks/yq-OB6PB5GY.js")).yqCommand}),Ot.push({name:"xan",load:async()=>(await import("./chunks/xan-TCTFON2Q.js")).xanCommand}),Ot.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-7TRACAE7.js")).sqlite3Command}));var $n=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&($n.push({name:"python3",load:async()=>(await import("./chunks/python3-R5OFWJIH.js")).python3Command}),$n.push({name:"python",load:async()=>(await import("./chunks/python3-R5OFWJIH.js")).pythonCommand}));var Nn=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Nn.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-F7JAZ4ZQ.js")).jsExecCommand}),Nn.push({name:"node",load:async()=>(await import("./chunks/js-exec-F7JAZ4ZQ.js")).nodeStubCommand}));var bc=[{name:"curl",load:async()=>(await import("./chunks/curl-DCSPNPEW.js")).curlCommand}],yi=new Map;function vs(e){return{name:e.name,async execute(t,s){let r=yi.get(e.name);if(r||(r=await Be.runTrustedAsync(()=>e.load()),yi.set(e.name,r)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:n}=await import("./chunks/flag-coverage-CAST5CDE.js");n(s.coverage,e.name,t)}return r.execute(t,s)}}}function wi(e){return(e?Ot.filter(s=>e.includes(s.name)):Ot).map(vs)}function Ei(){return bc.map(vs)}function bi(){return $n.map(vs)}function vi(){return Nn.map(vs)}function Si(e){return"load"in e&&typeof e.load=="function"}function Ai(e){let t=null;return{name:e.name,trusted:!0,async execute(s,r){return t||(t=await e.load()),t.execute(s,r)}}}function B(e){if(!e||e==="/")return"/";let t=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;t.startsWith("/")||(t=`/${t}`);let s=t.split("/").filter(n=>n&&n!=="."),r=[];for(let n of s)n===".."?r.pop():r.push(n);return`/${r.join("/")}`||"/"}function K(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}function $t(e){let t=B(e);if(t==="/")return"/";let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}function Ss(e,t){if(t.startsWith("/"))return B(t);let s=e==="/"?`/${t}`:`${e}/${t}`;return B(s)}function Yt(e,t){return e==="/"?`/${t}`:`${e}/${t}`}function Tt(e,t){if(t.startsWith("/"))return B(t);let s=$t(e);return B(Yt(s,t))}var Lt=new TextEncoder;function vc(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Jt=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,r]of Object.entries(t))typeof r=="function"?this.writeFileLazy(s,r):vc(r)?this.writeFileSync(s,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(s,r)}ensureParentDirs(t){let s=$t(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,r,n){K(t,"write");let i=B(t);this.ensureParentDirs(i);let a=ht(r),l=Rt(s,a);this.data.set(i,{type:"file",content:l,mode:n?.mode??420,mtime:n?.mtime??new Date})}writeFileLazy(t,s,r){K(t,"write");let n=B(t);this.ensureParentDirs(n),this.data.set(n,{type:"file",lazy:s,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,s){let r=await s.lazy(),i={type:"file",content:typeof r=="string"?Lt.encode(r):r,mode:s.mode,mtime:s.mtime};return this.data.set(t,i),i}async readFile(t,s){let r=await this.readFileBuffer(t),n=ht(s);return xt(r,n)}async readFileBytes(t){let s=await this.readFileBuffer(t);return xt(s,"binary")}async readFileBuffer(t){K(t,"open");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in r){let n=await this.materializeLazy(s,r);return n.content instanceof Uint8Array?n.content:Lt.encode(n.content)}return r.content instanceof Uint8Array?r.content:Lt.encode(r.content)}async writeFile(t,s,r){this.writeFileSync(t,s,r)}async appendFile(t,s,r){K(t,"append");let n=B(t),i=this.data.get(n);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let a=ht(r),l=Rt(s,a);if(i?.type==="file"){let o=i;"lazy"in o&&(o=await this.materializeLazy(n,o));let u="content"in o&&o.content instanceof Uint8Array?o.content:Lt.encode("content"in o?o.content:""),c=new Uint8Array(u.length+l.length);c.set(u),c.set(l,u.length),this.data.set(n,{type:"file",content:c,mode:o.mode,mtime:new Date})}else this.writeFileSync(t,s,r)}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){K(t,"stat");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Lt.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}async lstat(t){K(t,"lstat");let s=this.resolveIntermediateSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=Lt.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}resolveIntermediateSymlinks(t){let s=B(t);if(s==="/")return"/";let r=s.slice(1).split("/");if(r.length<=1)return s;let n="",i=new Set;for(let a=0;a<r.length-1;a++){let l=r[a];n=`${n}/${l}`;let o=this.data.get(n),u=0,c=40;for(;o&&o.type==="symlink"&&u<c;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(n),n=Tt(n,o.target),o=this.data.get(n),u++}if(u>=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${n}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let s=B(t);if(s==="/")return"/";let r=s.slice(1).split("/"),n="",i=new Set;for(let a of r){n=`${n}/${a}`;let l=this.data.get(n),o=0,u=40;for(;l&&l.type==="symlink"&&o<u;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(n),n=Tt(n,l.target),l=this.data.get(n),o++}if(o>=u)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return n}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){K(t,"mkdir");let r=B(t);if(this.data.has(r)){if(this.data.get(r)?.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 n=$t(r);if(n!=="/"&&!this.data.has(n))if(s?.recursive)this.mkdirSync(n,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){K(t,"scandir");let s=B(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Set;for(;r&&r.type==="symlink";){if(n.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);n.add(s),s=Tt(s,r.target),r=this.data.get(s)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,a=new Map;for(let[l,o]of this.data.entries())if(l!==s&&l.startsWith(i)){let u=l.slice(i.length),c=u.split("/")[0];c&&!u.includes("/",c.length)&&!a.has(c)&&a.set(c,{name:c,isFile:o.type==="file",isDirectory:o.type==="directory",isSymbolicLink:o.type==="symlink"})}return Array.from(a.values()).sort((l,o)=>l.name<o.name?-1:l.name>o.name?1:0)}async rm(t,s){K(t,"rm");let r=B(t),n=this.data.get(r);if(!n){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(n.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of i){let l=Yt(r,a);await this.rm(l,s)}}}this.data.delete(r)}async cp(t,s,r){K(t,"cp"),K(s,"cp");let n=B(t),i=B(s),a=this.data.get(n);if(!a)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(a.type==="file")if(this.ensureParentDirs(i),"content"in a){let l=a.content instanceof Uint8Array?new Uint8Array(a.content):a.content;this.data.set(i,{...a,content:l})}else this.data.set(i,{...a});else if(a.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...a});else if(a.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(n);for(let o of l){let u=Yt(n,o),c=Yt(i,o);await this.cp(u,c,r)}}}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){return Ss(t,s)}async chmod(t,s){K(t,"chmod");let r=B(t),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);n.mode=s}async symlink(t,s){K(s,"symlink");let r=B(s);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){K(t,"link"),K(s,"link");let r=B(t),n=B(s),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(n))throw new Error(`EEXIST: file already exists, link '${s}'`);let a=i;"lazy"in a&&(a=await this.materializeLazy(r,a)),this.ensureParentDirs(n),this.data.set(n,{type:"file",content:a.content,mode:a.mode,mtime:a.mtime})}async readlink(t){K(t,"readlink");let s=B(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){K(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,r){K(t,"utimes");let n=B(t),i=this.resolvePathWithSymlinks(n),a=this.data.get(i);if(!a)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);a.mtime=r}};var Ni="5.1.0(1)-release",ki="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function _n(e){let{pid:t,ppid:s,uid:r,gid:n}=e;return`Name: bash
4
+ State: R (running)
5
+ Pid: ${t}
6
+ PPid: ${s}
7
+ Uid: ${r} ${r} ${r} ${r}
8
+ Gid: ${n} ${n} ${n} ${n}
9
+ `}function Sc(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Ac(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 $c(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 Nc(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${ki}
4
10
  `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
5
- `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>$s(t)):e.writeFileSync("/proc/self/status",$s(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function or(e,t,s={pid:1,ppid:0,uid:1e3,gid:1e3}){ta(e)&&(sa(e,t),na(e),ra(e,s))}var ia=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],aa=["braceexpand","hashall","interactive-comments"];function Ds(e){let t=[],s=[...aa.map(n=>({name:n,enabled:!0})),...ia.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 at(e){e.state.env.set("SHELLOPTS",Ds(e.state.options))}var oa=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Ts(e){let t=[];for(let s of oa)e[s]&&t.push(s);return t.join(":")}function Is(e){e.state.env.set("BASHOPTS",Ts(e.state.shoptOptions))}var la="BASH_ALIAS_";function lr(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function cr(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function ur(e,t){return e.env.get(`${la}${t}`)}function xs(e,t,s){if(!t.name||!lr(t.name))return t;let n=cr(t.name);if(!n)return t;let r=ur(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new V,a=r,o=r.endsWith(" ");if(!o)for(let f of t.args){let d=dr(f);a+=` ${d}`}let l;try{l=i.parse(a)}catch(f){if(f instanceof Rt)throw f;return t}if(l.statements.length!==1||l.statements[0].pipelines.length!==1||l.statements[0].pipelines[0].commands.length!==1)return fr(t,r);let c=l.statements[0].pipelines[0].commands[0];if(c.type!=="SimpleCommand")return fr(t,r);let u={...c,assignments:[...t.assignments,...c.assignments],redirections:[...c.redirections,...t.redirections],line:t.line};if(o&&t.args.length>0&&(u={...u,args:[...u.args,...t.args]},u.args.length>0)){let f=u.args[0];if(lr(f)){let d=cr(f);if(d&&ur(e,d)){let h={type:"SimpleCommand",name:f,args:u.args.slice(1),assignments:[],redirections:[]},y=xs(e,h,s);y!==h&&(u={...u,name:y.name,args:[...y.args]})}}}return u}catch(i){throw s.delete(n),i}}function fr(e,t){let s=t;for(let a of e.args){let o=dr(a);s+=` ${o}`}let n=new V,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 dr(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 hr(e,t){let s=t.parts.map(u=>u.type==="Literal"?u.value:"\0").join(""),n=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!n||!s.endsWith(")"))return null;let r=n[1],i=[],a=!1,o="",l=!1;for(let u of t.parts)if(u.type==="Literal"){let f=u.value;if(!a){let d=f.indexOf("=(");d!==-1&&(a=!0,f=f.slice(d+2))}if(a){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(o||l)&&(i.push(o),o="",l=!1):h&&(o+=h)}}else if(a)if(u.type==="BraceExpansion")if(/^\[.+\]=/.test(o))o+=Lt({type:"Word",parts:[u]});else{(o||l)&&(i.push(o),o="",l=!1);let d=await ke(e,{type:"Word",parts:[u]});i.push(...d.values)}else{(u.type==="SingleQuoted"||u.type==="DoubleQuoted"||u.type==="Escaped")&&(l=!0);let f=await I(e,{type:"Word",parts:[u]});o+=f}(o||l)&&i.push(o);let c=i.map(u=>/^\[.+\]=/.test(u)?u:u===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(u)&&!u.startsWith("'")&&!u.startsWith('"')?`'${u.replace(/'/g,"'\\''")}'`:u);return`${r}=(${c.join(" ")})`}async function pr(e,t){let s=-1,n=-1,r=!1;for(let p=0;p<t.parts.length;p++){let w=t.parts[p];if(w.type==="Literal"){let $=w.value.indexOf("+=");if($!==-1){let b=w.value.slice(0,$);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(b)){s=p,n=$,r=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(b)){s=p,n=$,r=!0;break}}let g=w.value.indexOf("=");if(g!==-1&&(g===0||w.value[g-1]!=="+")){let b=w.value.slice(0,g);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(b)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(b)){s=p,n=g;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),a=t.parts[s];if(a.type!=="Literal")return null;let o=r?2:1,l=a.value.slice(0,n),c=a.value.slice(n+o),u=t.parts.slice(s+1),f="";for(let p of i)f+=await I(e,{type:"Word",parts:[p]});f+=l;let d={type:"Word",parts:c!==""?[{type:"Literal",value:c},...u]:u},h=d.parts.length>0?await I(e,d):"";return`${f}${r?"+=":"="}${h}`}var ca=["tar","yq","xan","sqlite3","python3","python"];function mr(e){return ca.includes(e)}var M=Object.freeze({stdout:"",stderr:"",exitCode:0});function F(e=""){return{stdout:e,stderr:"",exitCode:0}}function _(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function k(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function X(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function Pe(e,t,s="",n=""){throw new Y(e,t,s,n)}function ae(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new Y(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function Rs(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Re;return M}if(t.length>1)throw new B(1,"",`bash: break: too many arguments
6
- `);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new B(128,"",`bash: break: ${t[0]}: numeric argument required
7
- `);s=n}throw new de(s)}async function Ls(e,t){let s,n=!1,r=!1,i=0;for(;i<t.length;)if(t[i]==="--"){i++;break}else if(t[i]==="-L")r=!1,i++;else if(t[i]==="-P")r=!0,i++;else if(t[i].startsWith("-")&&t[i]!=="-")i++;else break;let a=t.slice(i);if(a.length===0||a[0]==="~"?s=e.state.env.get("HOME")||"/":a[0]==="-"?(s=e.state.previousDir,n=!0):s=a[0],!s.startsWith("/")&&!s.startsWith("./")&&!s.startsWith("../")&&s!=="."&&s!==".."){let f=e.state.env.get("CDPATH");if(f){let d=f.split(":").filter(h=>h);for(let h of d){let y=h.startsWith("/")?`${h}/${s}`:`${e.state.cwd}/${h}/${s}`;try{if((await e.fs.stat(y)).isDirectory){s=y,n=!0;break}}catch{}}}}let l=(s.startsWith("/")?s:`${e.state.cwd}/${s}`).split("/").filter(f=>f&&f!=="."),c="";for(let f of l)if(f==="..")c=c.split("/").slice(0,-1).join("/")||"/";else{c=c?`${c}/${f}`:`/${f}`;try{if(!(await e.fs.stat(c)).isDirectory)return _(`bash: cd: ${s}: Not a directory
11
+ `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>_n(t)):e.writeFileSync("/proc/self/status",_n(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function _i(e,t,s={pid:1,ppid:0,uid:1e3,gid:1e3}){Sc(e)&&(Ac(e,t),$c(e),Nc(e,s))}var kc=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],_c=["braceexpand","hashall","interactive-comments"];function Pn(e){let t=[],s=[..._c.map(r=>({name:r,enabled:!0})),...kc.map(r=>({name:r,enabled:e[r]}))].sort((r,n)=>r.name.localeCompare(n.name));for(let r of s)r.enabled&&t.push(r.name);return t.join(":")}function Mt(e){e.state.env.set("SHELLOPTS",Pn(e.state.options))}var Pc=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Dn(e){let t=[];for(let s of Pc)e[s]&&t.push(s);return t.join(":")}function In(e){e.state.env.set("BASHOPTS",Dn(e.state.shoptOptions))}var x={script(e){return{type:"Script",statements:e}},statement(e,t=[],s=!1,r,n){let i={type:"Statement",pipelines:e,operators:t,background:s};return r&&(i.deferredError=r),n!==void 0&&(i.sourceText=n),i},pipeline(e,t=!1,s=!1,r=!1,n){return{type:"Pipeline",commands:e,negated:t,timed:s,timePosix:r,pipeStderr:n}},simpleCommand(e,t=[],s=[],r=[]){return{type:"SimpleCommand",name:e,args:t,assignments:s,redirections:r}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},assignment(e,t,s=!1,r=null){return{type:"Assignment",name:e,value:t,append:s,array:r}},redirection(e,t,s=null,r){let n={type:"Redirection",fd:s,operator:e,target:t};return r&&(n.fdVariable=r),n},hereDoc(e,t,s=!1,r=!1){return{type:"HereDoc",delimiter:e,content:t,stripTabs:s,quoted:r}},ifNode(e,t=null,s=[]){return{type:"If",clauses:e,elseBody:t,redirections:s}},forNode(e,t,s,r=[]){return{type:"For",variable:e,words:t,body:s,redirections:r}},whileNode(e,t,s=[]){return{type:"While",condition:e,body:t,redirections:s}},untilNode(e,t,s=[]){return{type:"Until",condition:e,body:t,redirections:s}},caseNode(e,t,s=[]){return{type:"Case",word:e,items:t,redirections:s}},caseItem(e,t,s=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:s}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,s=[],r){return{type:"FunctionDef",name:e,body:t,redirections:s,sourceFile:r}},conditionalCommand(e,t=[],s){return{type:"ConditionalCommand",expression:e,redirections:t,line:s}},arithmeticCommand(e,t=[],s){return{type:"ArithmeticCommand",expression:e,redirections:t,line:s}}};function Pi(e,t){let s=e.length,r=t+3,n=2,i=!1,a=!1;for(;r<s&&n>0;){let l=e[r];if(i){l==="'"&&(i=!1),r++;continue}if(a){if(l==="\\"){r+=2;continue}l==='"'&&(a=!1),r++;continue}if(l==="'"){i=!0,r++;continue}if(l==='"'){a=!0,r++;continue}if(l==="\\"){r+=2;continue}if(l==="("){n++,r++;continue}if(l===")"){if(n--,n===1){let o=r+1;return!(o<s&&e[o]===")")}if(n===0)return!1;r++;continue}if(n===1&&(l==="|"&&r+1<s&&e[r+1]==="|"||l==="&"&&r+1<s&&e[r+1]==="&"||l==="|"&&r+1<s&&e[r+1]!=="|"))return!0;r++}return!1}function Cn(e,t){let s="",r=t,n=i=>i===" "||i===" "||i===`
12
+ `||i===";"||i==="&"||i==="|"||i==="<"||i===">"||i==="("||i===")";for(;r<e.length;){let i=e[r];if(i==="'"){for(r++;r<e.length&&e[r]!=="'";)s+=e[r],r++;r<e.length&&r++;continue}if(i==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length&&r++,s+=e[r],r++;r<e.length&&r++;continue}if(i==="\\"&&r+1<e.length){s+=e[r+1],r+=2;continue}if(n(i))break;s+=i,r++}return{delim:s,endPos:r}}function Dc(e,t,s){let r=t+1;for(let{delim:n,stripTabs:i}of s)for(;;){if(r>=e.length)return e.length;let a=e.indexOf(`
13
+ `,r);a===-1&&(a=e.length);let l=e.slice(r,a);if(i&&(l=l.replace(/^\t+/,"")),l===n){r=a+1;break}if(a>=e.length)return e.length;r=a+1}return Math.min(r,e.length)}function Di(e,t,s,r){let n=t+2,i=1,a=n,l=!1,o=!1,u=0,c=!1,f="",d=[],h=0;for(;a<e.length&&i>0;){let b=e[a];if(l)b==="'"&&(l=!1);else if(o)b==="\\"&&a+1<e.length?a++:b==='"'&&(o=!1);else{if(b==="("&&e[a+1]==="("?h++:b===")"&&e[a+1]===")"&&h>0&&h--,h===0&&b==="<"&&e[a+1]==="<"&&e[a+2]!=="<"){let v=a+2,E=!1;for(e[v]==="-"&&(E=!0,v++);e[v]===" "||e[v]===" ";)v++;let{delim:w,endPos:S}=Cn(e,v);if(w.length>0){d.push({delim:w,stripTabs:E}),f="",a=S;continue}}if(b===`
14
+ `&&d.length>0){let v=Dc(e,a,d);d.length=0,f="",a=v;continue}b==="'"?(l=!0,f=""):b==='"'?(o=!0,f=""):b==="\\"&&a+1<e.length?(a++,f=""):/[a-zA-Z_]/.test(b)?f+=b:(f==="case"?(u++,c=!1):f==="in"&&u>0?c=!0:f==="esac"&&u>0&&(u--,c=!1),f="",b==="("?a>0&&e[a-1]==="$"?i++:c||i++:b===")"?c?c=!1:i--:b===";"&&u>0&&a+1<e.length&&e[a+1]===";"&&(c=!0))}i>0&&a++}i>0&&r("unexpected EOF while looking for matching `)'");let p=e.slice(n,a),y=s().parse(p);return{part:x.commandSubstitution(y,!1),endIndex:a+1}}function Ii(e,t,s,r,n){let a=t+1,l="";for(;a<e.length&&e[a]!=="`";)if(e[a]==="\\"){let c=e[a+1];c==="$"||c==="`"||c==="\\"||c===`
15
+ `||s&&c==='"'?(c!==`
16
+ `&&(l+=c),a+=2):(l+=e[a],a++)}else l+=e[a],a++;a>=e.length&&n("unexpected EOF while looking for matching ``'");let u=r().parse(l);return{part:x.commandSubstitution(u,!0),endIndex:a+1}}var Ic=10485760,g;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(g||(g={}));var pt=class extends Error{line;column;constructor(t,s,r){super(`line ${s}: ${t}`),this.line=s,this.column=r,this.name="LexerError"}},Ci=new Map([["if",g.IF],["then",g.THEN],["else",g.ELSE],["elif",g.ELIF],["fi",g.FI],["for",g.FOR],["while",g.WHILE],["until",g.UNTIL],["do",g.DO],["done",g.DONE],["case",g.CASE],["esac",g.ESAC],["in",g.IN],["function",g.FUNCTION],["select",g.SELECT],["time",g.TIME],["coproc",g.COPROC]]);function Ri(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return!1;let s=e.slice(t[0].length);if(s===""||s==="+")return!0;if(s[0]==="["){let r=0,n=0;for(;n<s.length;n++)if(s[n]==="[")r++;else if(s[n]==="]"&&(r--,r===0))break;if(r!==0||n>=s.length)return!1;let i=s.slice(n+1);return i===""||i==="+"}return!1}function xi(e){let t=0;for(let s=0;s<e.length;s++){let r=e[s];if(r==="[")t++;else if(r==="]")t--;else{if(t===0&&r==="=")return s;if(t===0&&r==="+"&&e[s+1]==="=")return s+1}}return-1}var Cc=[[";",";","&",g.SEMI_SEMI_AND],["<","<","<",g.TLESS],["&",">",">",g.AND_DGREAT]],Rc=[["[","[",g.DBRACK_START],["]","]",g.DBRACK_END],["(","(",g.DPAREN_START],[")",")",g.DPAREN_END],["&","&",g.AND_AND],["|","|",g.OR_OR],[";",";",g.DSEMI],[";","&",g.SEMI_AND],["|","&",g.PIPE_AMP],[">",">",g.DGREAT],["<","&",g.LESSAND],[">","&",g.GREATAND],["<",">",g.LESSGREAT],[">","|",g.CLOBBER],["&",">",g.AND_GREAT]],xc=new Map([["|",g.PIPE],["&",g.AMP],[";",g.SEMICOLON],["(",g.LPAREN],[")",g.RPAREN],["<",g.LESS],[">",g.GREAT]]);function Oc(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Oi(e){return e===" "||e===" "||e===`
17
+ `||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var $s=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];dparenDepth=0;maxHeredocSize;constructor(t,s){this.input=t,this.maxHeredocSize=s?.maxHeredocSize??Ic}tokenize(){let s=this.input.length,r=this.tokens,n=this.pendingHeredocs;for(;this.pos<s;){if(n.length>0&&r.length>0&&r[r.length-1].type===g.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=s)break;let i=this.nextToken();i&&r.push(i)}return r.push({type:g.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let t=this.input,s=t.length,r=this.pos,n=this.column,i=this.line;for(;r<s;){let a=t[r];if(a===" "||a===" ")r++,n++;else if(a==="\\"&&t[r+1]===`
18
+ `)r+=2,i++,n=1;else break}this.pos=r,this.column=n,this.line=i}nextToken(){let t=this.input,s=this.pos,r=this.line,n=this.column,i=t[s],a=t[s+1],l=t[s+2];if(i==="#"&&this.dparenDepth===0)return this.readComment(s,r,n);if(i===`
19
+ `)return this.pos=s+1,this.line++,this.column=1,{type:g.NEWLINE,value:`
20
+ `,start:s,end:s+1,line:r,column:n};if(i==="<"&&a==="<"&&l==="-")return this.pos=s+3,this.column=n+3,this.registerHeredocFromLookahead(!0),this.makeToken(g.DLESSDASH,"<<-",s,r,n);for(let[u,c,f,d]of Cc)if(i===u&&a===c&&l===f)return this.pos=s+3,this.column=n+3,this.makeToken(d,u+c+f,s,r,n);if(i==="<"&&a==="<")return this.pos=s+2,this.column=n+2,this.registerHeredocFromLookahead(!1),this.makeToken(g.DLESS,"<<",s,r,n);if(i==="("&&a==="(")return this.dparenDepth>0?(this.pos=s+1,this.column=n+1,this.dparenDepth++,this.makeToken(g.LPAREN,"(",s,r,n)):this.looksLikeNestedSubshells(s+2)||this.dparenClosesWithSpacedParens(s+2)?(this.pos=s+1,this.column=n+1,this.makeToken(g.LPAREN,"(",s,r,n)):(this.pos=s+2,this.column=n+2,this.dparenDepth=1,this.makeToken(g.DPAREN_START,"((",s,r,n));if(i===")"&&a===")")return this.dparenDepth===1?(this.pos=s+2,this.column=n+2,this.dparenDepth=0,this.makeToken(g.DPAREN_END,"))",s,r,n)):this.dparenDepth>1?(this.pos=s+1,this.column=n+1,this.dparenDepth--,this.makeToken(g.RPAREN,")",s,r,n)):(this.pos=s+1,this.column=n+1,this.makeToken(g.RPAREN,")",s,r,n));for(let[u,c,f]of Rc)if(!(u==="("&&c==="("||u===")"&&c===")")&&!(this.dparenDepth>0&&u===";"&&(f===g.DSEMI||f===g.SEMI_AND||f===g.SEMI_SEMI_AND))&&i===u&&a===c){if(f===g.DBRACK_START||f===g.DBRACK_END){let d=t[s+2];if(d!==void 0&&d!==" "&&d!==" "&&d!==`
21
+ `&&d!==";"&&d!=="&"&&d!=="|"&&d!=="("&&d!==")"&&d!=="<"&&d!==">")break}return this.pos=s+2,this.column=n+2,this.makeToken(f,u+c,s,r,n)}if(i==="("&&this.dparenDepth>0)return this.pos=s+1,this.column=n+1,this.dparenDepth++,this.makeToken(g.LPAREN,"(",s,r,n);if(i===")"&&this.dparenDepth>1)return this.pos=s+1,this.column=n+1,this.dparenDepth--,this.makeToken(g.RPAREN,")",s,r,n);let o=xc.get(i);if(o!==void 0)return this.pos=s+1,this.column=n+1,this.makeToken(o,i,s,r,n);if(i==="{"){let u=this.scanFdVariable(s);return u!==null?(this.pos=u.end,this.column=n+(u.end-s),{type:g.FD_VARIABLE,value:u.varname,start:s,end:u.end,line:r,column:n}):a==="}"?(this.pos=s+2,this.column=n+2,{type:g.WORD,value:"{}",start:s,end:s+2,line:r,column:n,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(s)!==null?this.readWordWithBraceExpansion(s,r,n):this.scanLiteralBraceWord(s)!==null?this.readWordWithBraceExpansion(s,r,n):a!==void 0&&a!==" "&&a!==" "&&a!==`
22
+ `?this.readWord(s,r,n):(this.pos=s+1,this.column=n+1,this.makeToken(g.LBRACE,"{",s,r,n))}return i==="}"?this.isWordCharFollowing(s+1)?this.readWord(s,r,n):(this.pos=s+1,this.column=n+1,this.makeToken(g.RBRACE,"}",s,r,n)):i==="!"?a==="="?(this.pos=s+2,this.column=n+2,this.makeToken(g.WORD,"!=",s,r,n)):(this.pos=s+1,this.column=n+1,this.makeToken(g.BANG,"!",s,r,n)):this.readWord(s,r,n)}looksLikeNestedSubshells(t){let s=this.input,r=s.length,n=t;for(;n<r&&(s[n]===" "||s[n]===" ");)n++;if(n>=r)return!1;let i=s[n];if(i==="(")return this.looksLikeNestedSubshells(n+1);let a=/[a-zA-Z_]/.test(i),l=i==="!"||i==="[";if(!a&&!l)return!1;let o=n;for(;o<r&&/[a-zA-Z0-9_\-.]/.test(s[o]);)o++;if(o===n)return l;let u=o;for(;u<r&&(s[u]===" "||s[u]===" ");)u++;if(u>=r)return!1;let c=s[u];if(c==="="&&s[u+1]!=="="||c===`
23
+ `||o===u&&/[+\-*/%<>&|^!~?:]/.test(c)&&c!=="-"||c===")"&&s[u+1]===")")return!1;if(u>o&&(c==="-"||c==='"'||c==="'"||c==="$"||/[a-zA-Z_/.]/.test(c))){let f=u;for(;f<r&&s[f]!==`
24
+ `;){if(s[f]===")")return!0;f++}return!1}if(c===")"){let f=u+1;for(;f<r&&(s[f]===" "||s[f]===" ");)f++;if(s[f]==="|"&&s[f+1]==="|"||s[f]==="&"&&s[f+1]==="&"||s[f]===";"||s[f]==="|"&&s[f+1]!=="|")return!0}return!1}makeToken(t,s,r,n,i){return{type:t,value:s,start:r,end:this.pos,line:n,column:i}}readComment(t,s,r){let n=this.input,i=n.length,a=this.pos;for(;a<i&&n[a]!==`
25
+ `;)a++;let l=n.slice(t,a);return this.pos=a,this.column=r+(a-t),{type:g.COMMENT,value:l,start:t,end:a,line:s,column:r}}readWord(t,s,r){let n=this.input,i=n.length,a=this.pos,l=a;for(;a<i;){let E=n[a];if(E===" "||E===" "||E===`
26
+ `||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">"||E==="'"||E==='"'||E==="\\"||E==="$"||E==="`"||E==="{"||E==="}"||E==="~"||E==="*"||E==="?"||E==="[")break;a++}if(a>l){let E=n[a];if(!(E==="("&&a>l&&"@*+?!".includes(n[a-1]))){if(a>=i||E===" "||E===" "||E===`
27
+ `||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">"){let w=n.slice(l,a);this.pos=a,this.column=r+(a-l);let S=Ci.get(w);if(S!==void 0)return{type:S,value:w,start:t,end:a,line:s,column:r};let A=xi(w);return A>0&&Ri(w.slice(0,A))?{type:g.ASSIGNMENT_WORD,value:w,start:t,end:a,line:s,column:r}:/^[0-9]+$/.test(w)?{type:g.NUMBER,value:w,start:t,end:a,line:s,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(w)?{type:g.NAME,value:w,start:t,end:a,line:s,column:r,quoted:!1,singleQuoted:!1}:{type:g.WORD,value:w,start:t,end:a,line:s,column:r,quoted:!1,singleQuoted:!1}}}}a=this.pos;let o=this.column,u=this.line,c="",f=!1,d=!1,h=!1,p=!1,m=n[a]==='"'||n[a]==="'",y=!1,b=0;for(;a<i;){let E=n[a];if(!h&&!p){if(E==="("&&c.length>0&&"@*+?!".includes(c[c.length-1])){let w=this.scanExtglobPattern(a);if(w!==null){c+=w.content,a=w.end,o+=w.content.length;continue}}if(E==="["&&b===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){let w=a+1<i?n[a+1]:"";if(w==="^"||w==="!"){c+=E,a++,o++;continue}b=1,c+=E,a++,o++;continue}}else if(E==="["&&b>0){c.length>0&&c[c.length-1]!=="\\"&&b++,c+=E,a++,o++;continue}else if(E==="]"&&b>0){c.length>0&&c[c.length-1]!=="\\"&&b--,c+=E,a++,o++;continue}if(b>0){if(E===`
28
+ `)break;c+=E,a++,o++;continue}if(E===" "||E===" "||E===`
29
+ `||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">")break}if(E==="$"&&a+1<i&&n[a+1]==="'"&&!h&&!p){for(c+="$'",a+=2,o+=2;a<i&&n[a]!=="'";)n[a]==="\\"&&a+1<i?(c+=n[a]+n[a+1],a+=2,o+=2):(c+=n[a],a++,o++);a<i&&(c+="'",a++,o++);continue}if(E==="$"&&a+1<i&&n[a+1]==='"'&&!h&&!p){a++,o++,p=!0,f=!0,c===""&&(m=!0),a++,o++;continue}if(E==="'"&&!p){if(h)if(h=!1,!m||y)c+=E;else{let w=a+1<i?n[a+1]:"";w&&!Oi(w)&&w!=="'"&&(w==='"'?(y=!0,c+=E,d=!1,f=!1):(y=!0,c+=E))}else h=!0,m&&!y?(d=!0,f=!0):c+=E;a++,o++;continue}if(E==='"'&&!h){if(p)if(p=!1,!m||y)c+=E;else{let w=a+1<i?n[a+1]:"";w&&!Oi(w)&&w!=='"'&&(w==="'"?(y=!0,c+=E,d=!1,f=!1):(y=!0,c+=E))}else p=!0,m&&!y?f=!0:c+=E;a++,o++;continue}if(E==="\\"&&!h&&a+1<i){let w=n[a+1];if(w===`
30
+ `){a+=2,u++,o=1;continue}if(p){if(w==='"'||w==="\\"||w==="$"||w==="`"||w===`
31
+ `){if(w===`
32
+ `){a+=2,o=1,u++;continue}c+=E+w,a+=2,o+=2;continue}}else{w==="\\"||w==='"'||w==="'"||w==="`"||w==="*"||w==="?"||w==="["||w==="]"||w==="("||w===")"||w==="$"||w==="-"||w==="."||w==="^"||w==="+"||w==="{"||w==="}"?c+=E+w:c+=w,a+=2,o+=2;continue}}if(E==="$"&&a+1<i&&n[a+1]==="("&&!h){c+=E,a++,o++,c+=n[a],a++,o++;let w=1,S=!1,A=!1,$=0,R=!1,I="",L=[],k=n[a]==="("&&!this.dollarDparenIsSubshell(a),D=k?1:0;for(;w>0&&a<i;){let C=n[a];if(c+=C,S)C==="'"&&(S=!1);else if(A)C==="\\"&&a+1<i?(c+=n[a+1],a++,o++):C==='"'&&(A=!1);else{if(C==="("&&n[a+1]==="("?D++:C===")"&&n[a+1]===")"&&D>0&&D--,D===0&&C==="<"&&n[a+1]==="<"&&n[a+2]!=="<"){let N=a+2,O=!1;for(n[N]==="-"&&(O=!0,N++);n[N]===" "||n[N]===" ";)N++;let{delim:M,endPos:q}=Cn(n,N);if(M.length>0){c+=n.slice(a+1,q),o+=q-a,L.push({delim:M,stripTabs:O}),a=q;continue}}if(C===`
33
+ `&&L.length>0){u++,o=0;let N=a+1;for(let{delim:O,stripTabs:M}of L)for(;!(N>=i);){let q=n.indexOf(`
34
+ `,N);q===-1&&(q=i);let J=n.slice(N,q),ce=M?J.replace(/^\t+/,""):J;c+=n.slice(N,Math.min(q+1,i)),q<i&&u++;let pe=q>=i;if(N=q+1,ce===O||pe)break}L.length=0,o=0,a=Math.min(N,i);continue}if(C==="'")S=!0,I="";else if(C==='"')A=!0,I="";else if(C==="\\"&&a+1<i)c+=n[a+1],a++,o++,I="";else if(C==="$"&&a+1<i&&n[a+1]==="{"){a++,o++,c+=n[a],a++,o++;let N=1,O=!1,M=!1;for(;N>0&&a<i;){let q=n[a];if(q==="\\"&&a+1<i&&!O){c+=q,a++,o++,c+=n[a],a++,o++;continue}c+=q,O?q==="'"&&(O=!1):M?q==='"'&&(M=!1):q==="'"?O=!0:q==='"'?M=!0:q==="{"?N++:q==="}"&&N--,q===`
35
+ `?(u++,o=0):o++,a++}I="";continue}else if(C==="#"&&!k&&(I===""||/\s/.test(n[a-1]||""))){for(;a+1<i&&n[a+1]!==`
36
+ `;)a++,o++,c+=n[a];I=""}else/[a-zA-Z_]/.test(C)?I+=C:(I==="case"?($++,R=!1):I==="in"&&$>0?R=!0:I==="esac"&&$>0&&($--,R=!1),I="",C==="("?a>0&&n[a-1]==="$"?w++:R||w++:C===")"?R?R=!1:w--:C===";"&&$>0&&(a+1<i&&n[a+1]===";"||a+1<i&&n[a+1]==="&")&&(R=!0))}C===`
37
+ `&&(u++,o=0,I=""),a++,o++}continue}if(E==="$"&&a+1<i&&n[a+1]==="["&&!h){c+=E,a++,o++,c+=n[a],a++,o++;let w=1;for(;w>0&&a<i;){let S=n[a];c+=S,S==="["?w++:S==="]"?w--:S===`
38
+ `&&(u++,o=0),a++,o++}continue}if(E==="$"&&a+1<i&&n[a+1]==="{"&&!h){c+=E,a++,o++,c+=n[a],a++,o++;let w=1,S=!1,A=!1,$=u,R=o,I=u,L=o;for(;w>0&&a<i;){let k=n[a];if(k==="\\"&&a+1<i&&n[a+1]===`
39
+ `){a+=2,u++,o=1;continue}if(k==="\\"&&a+1<i&&!S){c+=k,a++,o++,c+=n[a],a++,o++;continue}c+=k,S?k==="'"&&(S=!1):A?k==='"'&&(A=!1):k==="'"?(S=!0,$=u,R=o):k==='"'?(A=!0,I=u,L=o):k==="{"?w++:k==="}"&&w--,k===`
40
+ `&&(u++,o=0),a++,o++}if(S)throw new pt("unexpected EOF while looking for matching `''",$,R);if(A)throw new pt("unexpected EOF while looking for matching `\"'",I,L);continue}if(E==="$"&&a+1<i&&!h){let w=n[a+1];if(w==="#"||w==="?"||w==="$"||w==="!"||w==="@"||w==="*"||w==="-"||w>="0"&&w<="9"){c+=E+w,a+=2,o+=2;continue}}if(E==="`"&&!h){for(c+=E,a++,o++;a<i&&n[a]!=="`";){let w=n[a];c+=w,w==="\\"&&a+1<i&&(c+=n[a+1],a++,o++),w===`
41
+ `&&(u++,o=0),a++,o++}a<i&&(c+=n[a],a++,o++);continue}c+=E,a++,E===`
42
+ `?(u++,o=1):o++}if(this.pos=a,this.column=o,this.line=u,y&&m&&(c=n[t]+c,f=!1,d=!1),h||p){let E=h?"'":'"';throw new pt(`unexpected EOF while looking for matching \`${E}'`,s,r)}if(!m&&c.length>=2){if(c[0]==="'"&&c[c.length-1]==="'"){let E=c.slice(1,-1);!E.includes("'")&&!E.includes('"')&&(c=E,f=!0,d=!0)}else if(c[0]==='"'&&c[c.length-1]==='"'){let E=c.slice(1,-1),w=!1;for(let S=0;S<E.length;S++){if(E[S]==='"'){w=!0;break}E[S]==="\\"&&S+1<E.length&&S++}w||(c=E,f=!0,d=!1)}}if(c==="")return{type:g.WORD,value:"",start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d};let v=Ci.get(c);if(!f&&v!==void 0)return{type:v,value:c,start:t,end:a,line:s,column:r};if(!m){let E=xi(c);if(E>0&&Ri(c.slice(0,E)))return{type:g.ASSIGNMENT_WORD,value:c,start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(c)?{type:g.NUMBER,value:c,start:t,end:a,line:s,column:r}:Oc(c)?{type:g.NAME,value:c,start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d}:{type:g.WORD,value:c,start:t,end:a,line:s,column:r,quoted:f,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let s=this.pos,r=this.line,n=this.column,i="";for(;this.pos<this.input.length;){let a="";for(;this.pos<this.input.length&&this.input[this.pos]!==`
43
+ `;)a+=this.input[this.pos],this.pos++,this.column++;if((t.stripTabs?a.replace(/^\t+/,""):a)===t.delimiter){this.pos<this.input.length&&this.input[this.pos]===`
44
+ `&&(this.pos++,this.line++,this.column=1);break}if(i+=a,i.length>this.maxHeredocSize)throw new pt(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,n);this.pos<this.input.length&&this.input[this.pos]===`
45
+ `&&(i+=`
46
+ `,this.pos++,this.line++,this.column=1)}this.tokens.push({type:g.HEREDOC_CONTENT,value:i,start:s,end:this.pos,line:r,column:n})}}addPendingHeredoc(t,s,r){this.pendingHeredocs.push({delimiter:t,stripTabs:s,quoted:r})}registerHeredocFromLookahead(t){let s=this.pos,r=this.column;for(;this.pos<this.input.length&&(this.input[this.pos]===" "||this.input[this.pos]===" ");)this.pos++,this.column++;let n="",i=!1;for(;this.pos<this.input.length;){let a=this.input[this.pos];if(/[\s;<>&|()]/.test(a))break;if(a==="'"||a==='"'){i=!0;let l=a;for(this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]!==l;)n+=this.input[this.pos],this.pos++,this.column++;this.pos<this.input.length&&this.input[this.pos]===l&&(this.pos++,this.column++)}else a==="\\"?(i=!0,this.pos++,this.column++,this.pos<this.input.length&&(n+=this.input[this.pos],this.pos++,this.column++)):(n+=a,this.pos++,this.column++)}this.pos=s,this.column=r,n&&this.pendingHeredocs.push({delimiter:n,stripTabs:t,quoted:i})}isWordCharFollowing(t){if(t>=this.input.length)return!1;let s=this.input[t];return!(s===" "||s===" "||s===`
47
+ `||s===";"||s==="&"||s==="|"||s==="("||s===")"||s==="<"||s===">")}readWordWithBraceExpansion(t,s,r){let n=this.input,i=n.length,a=t,l=r;for(;a<i;){let u=n[a];if(u===" "||u===" "||u===`
48
+ `||u===";"||u==="&"||u==="|"||u==="("||u===")"||u==="<"||u===">")break;if(u==="{"){if(this.scanBraceExpansion(a)!==null){let f=1;for(a++,l++;a<i&&f>0;)n[a]==="{"?f++:n[a]==="}"&&f--,a++,l++;continue}a++,l++;continue}if(u==="}"){a++,l++;continue}if(u==="$"&&a+1<i&&n[a+1]==="("){a++,l++,a++,l++;let c=1;for(;c>0&&a<i;)n[a]==="("?c++:n[a]===")"&&c--,a++,l++;continue}if(u==="$"&&a+1<i&&n[a+1]==="{"){a++,l++,a++,l++;let c=1;for(;c>0&&a<i;)n[a]==="{"?c++:n[a]==="}"&&c--,a++,l++;continue}if(u==="`"){for(a++,l++;a<i&&n[a]!=="`";)n[a]==="\\"&&a+1<i?(a+=2,l+=2):(a++,l++);a<i&&(a++,l++);continue}a++,l++}let o=n.slice(t,a);return this.pos=a,this.column=l,{type:g.WORD,value:o,start:t,end:a,line:s,column:r,quoted:!1,singleQuoted:!1}}scanBraceExpansion(t){let s=this.input,r=s.length,n=t+1,i=1,a=!1,l=!1;for(;n<r&&i>0;){let o=s[n];if(o==="{")i++,n++;else if(o==="}")i--,n++;else if(o===","&&i===1)a=!0,n++;else if(o==="."&&n+1<r&&s[n+1]===".")l=!0,n+=2;else{if(o===" "||o===" "||o===`
49
+ `||o===";"||o==="&"||o==="|")return null;n++}}return i===0&&(a||l)?s.slice(t,n):null}scanLiteralBraceWord(t){let s=this.input,r=s.length,n=t+1,i=1;for(;n<r&&i>0;){let a=s[n];if(a==="{")i++,n++;else if(a==="}"){if(i--,i===0)return s.slice(t,n+1);n++}else{if(a===" "||a===" "||a===`
50
+ `||a===";"||a==="&"||a==="|")return null;n++}}return null}scanExtglobPattern(t){let s=this.input,r=s.length,n=t+1,i=1;for(;n<r&&i>0;){let a=s[n];if(a==="\\"&&n+1<r){n+=2;continue}if("@*+?!".includes(a)&&n+1<r&&s[n+1]==="("){n++,i++,n++;continue}if(a==="(")i++,n++;else if(a===")")i--,n++;else{if(a===`
51
+ `)return null;n++}}return i===0?{content:s.slice(t,n),end:n}:null}scanFdVariable(t){let s=this.input,r=s.length,n=t+1,i=n;for(;n<r;){let c=s[n];if(n===i){if(!(c>="a"&&c<="z"||c>="A"&&c<="Z"||c==="_"))return null}else if(!(c>="a"&&c<="z"||c>="A"&&c<="Z"||c>="0"&&c<="9"||c==="_"))break;n++}if(n===i)return null;let a=s.slice(i,n);if(n>=r||s[n]!=="}"||(n++,n>=r))return null;let l=s[n],o=n+1<r?s[n+1]:"";return l===">"||l==="<"||l==="&"&&(o===">"||o==="<")?{varname:a,end:n}:null}dollarDparenIsSubshell(t){let s=this.input,r=s.length,n=t+1,i=2,a=!1,l=!1,o=!1;for(;n<r&&i>0;){let u=s[n];if(a){u==="'"&&(a=!1),u===`
52
+ `&&(o=!0),n++;continue}if(l){if(u==="\\"){n+=2;continue}u==='"'&&(l=!1),u===`
53
+ `&&(o=!0),n++;continue}if(u==="'"){a=!0,n++;continue}if(u==='"'){l=!0,n++;continue}if(u==="\\"){n+=2;continue}if(u===`
54
+ `&&(o=!0),u==="("){i++,n++;continue}if(u===")"){if(i--,i===1){let c=n+1;if(c<r&&s[c]===")")return!1;let f=c,d=!1;for(;f<r&&(s[f]===" "||s[f]===" "||s[f]===`
55
+ `);)d=!0,f++;if(d&&f<r&&s[f]===")"||o)return!0}if(i===0)return!1;n++;continue}n++}return!1}dparenClosesWithSpacedParens(t){let s=this.input,r=s.length,n=t,i=2,a=!1,l=!1;for(;n<r&&i>0;){let o=s[n];if(a){o==="'"&&(a=!1),n++;continue}if(l){if(o==="\\"){n+=2;continue}o==='"'&&(l=!1),n++;continue}if(o==="'"){a=!0,n++;continue}if(o==='"'){l=!0,n++;continue}if(o==="\\"){n+=2;continue}if(o==="("){i++,n++;continue}if(o===")"){if(i--,i===1){let u=n+1;if(u<r&&s[u]===")")return!1;let c=u,f=!1;for(;c<r&&(s[c]===" "||s[c]===" "||s[c]===`
56
+ `);)f=!0,c++;if(f&&c<r&&s[c]===")")return!0}if(i===0)return!1;n++;continue}if(i===1&&(o==="|"&&n+1<r&&s[n+1]==="|"||o==="&"&&n+1<r&&s[n+1]==="&"||o==="|"&&n+1<r&&s[n+1]!=="|"))return!0;n++}return!1}};var Rn=1e6,xn=1e5,Ti=1e6,On=200,Li=new Set([g.LESS,g.GREAT,g.DLESS,g.DGREAT,g.LESSAND,g.GREATAND,g.LESSGREAT,g.DLESSDASH,g.CLOBBER,g.TLESS,g.AND_GREAT,g.AND_DGREAT]),Wi=new Set([g.LESS,g.GREAT,g.DLESS,g.DGREAT,g.LESSAND,g.GREATAND,g.LESSGREAT,g.DLESSDASH,g.CLOBBER,g.TLESS]),Mi=new Set([g.LESS,g.GREAT,g.DLESS,g.DGREAT,g.LESSAND,g.GREATAND,g.LESSGREAT,g.DLESSDASH,g.CLOBBER,g.TLESS,g.AND_GREAT,g.AND_DGREAT]),we=class extends Error{line;column;token;constructor(t,s,r,n=void 0){super(`Parse error at ${s}:${r}: ${t}`),this.line=s,this.column=r,this.token=n,this.name="ParseException"}};function oe(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
57
+ `){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var Ns=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function es(e){if(e.includes("#")){let[s,r]=e.split("#"),n=Number.parseInt(s,10);if(n<2||n>64)return Number.NaN;if(n<=36){let a=Number.parseInt(r,n);return a>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:a}let i=0;for(let a of r){let l;if(/[0-9]/.test(a))l=a.charCodeAt(0)-48;else if(/[a-z]/.test(a))l=a.charCodeAt(0)-97+10;else if(/[A-Z]/.test(a))l=a.charCodeAt(0)-65+36;else if(a==="@")l=62;else if(a==="_")l=63;else return Number.NaN;if(l>=n)return Number.NaN;if(i=i*n+l,i>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return i}if(e.startsWith("0x")||e.startsWith("0X")){let s=Number.parseInt(e.slice(2),16);return s>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:s}if(e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)){if(/[89]/.test(e))return Number.NaN;let s=Number.parseInt(e,8);return s>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:s}let t=Number.parseInt(e,10);return t>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t}function Fi(e,t,s,r){if(s.slice(r,r+3)!=="$((")return null;let n=r+3,i=1,a=n;for(;n<s.length-1&&i>0;)s[n]==="("&&s[n+1]==="("?(i++,n+=2):s[n]===")"&&s[n+1]===")"?(i--,i>0&&(n+=2)):n++;let l=s.slice(a,n),{expr:o}=e(t,l,0);return n+=2,{expr:{type:"ArithNested",expression:o},pos:n}}function Vi(e,t){if(e.slice(t,t+2)!=="$'")return null;let s=t+2,r="";for(;s<e.length&&e[s]!=="'";)if(e[s]==="\\"&&s+1<e.length){let i=e[s+1];switch(i){case"n":r+=`
58
+ `;break;case"t":r+=" ";break;case"r":r+="\r";break;case"\\":r+="\\";break;case"'":r+="'";break;default:r+=i}s+=2}else r+=e[s],s++;e[s]==="'"&&s++;let n=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(n)?0:n},pos:s}}function zi(e,t){if(e.slice(t,t+2)!=='$"')return null;let s=t+2,r="";for(;s<e.length&&e[s]!=='"';)e[s]==="\\"&&s+1<e.length?(r+=e[s+1],s+=2):(r+=e[s],s++);e[s]==='"'&&s++;let n=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(n)?0:n},pos:s}}function Tc(e){let t="",s=0;for(;s<e.length;)if(e[s]==='"'){for(s++;s<e.length&&e[s]!=='"';)e[s]==="\\"&&s+1<e.length?(t+=e[s+1],s+=2):(t+=e[s],s++);s<e.length&&s++}else t+=e[s],s++;return t}function X(e,t){let s=Tc(t),{expr:r,pos:n}=Oe(e,s,0),i=oe(s,n);if(i<s.length){let a=t.slice(i).trim();if(a)return{type:"ArithmeticExpression",originalText:t,expression:{type:"ArithSyntaxError",errorToken:a,message:`${a}: syntax error: invalid arithmetic operator (error token is "${a}")`}}}return{type:"ArithmeticExpression",expression:r,originalText:t}}function ke(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function _e(e,t){return oe(e,t)>=e.length}function Oe(e,t,s){return Lc(e,t,s)}function Lc(e,t,s){let{expr:r,pos:n}=ts(e,t,s);for(n=oe(t,n);t[n]===",";){if(n++,_e(t,n))return ke(",",n);let{expr:a,pos:l}=ts(e,t,n);r={type:"ArithBinary",operator:",",left:r,right:a},n=oe(t,l)}return{expr:r,pos:n}}function ts(e,t,s){let{expr:r,pos:n}=Wc(e,t,s);if(n=oe(t,n),t[n]==="?"){n++;let{expr:i,pos:a}=Oe(e,t,n);if(n=oe(t,a),t[n]===":"){n++;let{expr:l,pos:o}=Oe(e,t,n);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:l},pos:o}}}return{expr:r,pos:n}}function Wc(e,t,s){let{expr:r,pos:n}=Bi(e,t,s);for(;n=oe(t,n),t.slice(n,n+2)==="||";){if(n+=2,_e(t,n))return ke("||",n);let{expr:a,pos:l}=Bi(e,t,n);r={type:"ArithBinary",operator:"||",left:r,right:a},n=l}return{expr:r,pos:n}}function Bi(e,t,s){let{expr:r,pos:n}=qi(e,t,s);for(;n=oe(t,n),t.slice(n,n+2)==="&&";){if(n+=2,_e(t,n))return ke("&&",n);let{expr:a,pos:l}=qi(e,t,n);r={type:"ArithBinary",operator:"&&",left:r,right:a},n=l}return{expr:r,pos:n}}function qi(e,t,s){let{expr:r,pos:n}=Ui(e,t,s);for(;n=oe(t,n),t[n]==="|"&&t[n+1]!=="|";){if(n++,_e(t,n))return ke("|",n);let{expr:a,pos:l}=Ui(e,t,n);r={type:"ArithBinary",operator:"|",left:r,right:a},n=l}return{expr:r,pos:n}}function Ui(e,t,s){let{expr:r,pos:n}=Zi(e,t,s);for(;n=oe(t,n),t[n]==="^";){if(n++,_e(t,n))return ke("^",n);let{expr:a,pos:l}=Zi(e,t,n);r={type:"ArithBinary",operator:"^",left:r,right:a},n=l}return{expr:r,pos:n}}function Zi(e,t,s){let{expr:r,pos:n}=Hi(e,t,s);for(;n=oe(t,n),t[n]==="&"&&t[n+1]!=="&";){if(n++,_e(t,n))return ke("&",n);let{expr:a,pos:l}=Hi(e,t,n);r={type:"ArithBinary",operator:"&",left:r,right:a},n=l}return{expr:r,pos:n}}function Hi(e,t,s){let{expr:r,pos:n}=ji(e,t,s);for(;n=oe(t,n),t.slice(n,n+2)==="=="||t.slice(n,n+2)==="!=";){let i=t.slice(n,n+2);if(n+=2,_e(t,n))return ke(i,n);let{expr:a,pos:l}=ji(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}return{expr:r,pos:n}}function ji(e,t,s){let{expr:r,pos:n}=Tn(e,t,s);for(;;)if(n=oe(t,n),t.slice(n,n+2)==="<="||t.slice(n,n+2)===">="){let i=t.slice(n,n+2);if(n+=2,_e(t,n))return ke(i,n);let{expr:a,pos:l}=Tn(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}else if(t[n]==="<"||t[n]===">"){let i=t[n];if(n++,_e(t,n))return ke(i,n);let{expr:a,pos:l}=Tn(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}else break;return{expr:r,pos:n}}function Tn(e,t,s){let{expr:r,pos:n}=Gi(e,t,s);for(;n=oe(t,n),t.slice(n,n+2)==="<<"||t.slice(n,n+2)===">>";){let i=t.slice(n,n+2);if(n+=2,_e(t,n))return ke(i,n);let{expr:a,pos:l}=Gi(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}return{expr:r,pos:n}}function Gi(e,t,s){let{expr:r,pos:n}=Qi(e,t,s);for(;n=oe(t,n),(t[n]==="+"||t[n]==="-")&&t[n+1]!==t[n];){let i=t[n];if(n++,_e(t,n))return ke(i,n);let{expr:a,pos:l}=Qi(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}return{expr:r,pos:n}}function Qi(e,t,s){let{expr:r,pos:n}=ks(e,t,s);for(;;)if(n=oe(t,n),t[n]==="*"&&t[n+1]!=="*"){if(n++,_e(t,n))return ke("*",n);let{expr:a,pos:l}=ks(e,t,n);r={type:"ArithBinary",operator:"*",left:r,right:a},n=l}else if(t[n]==="/"||t[n]==="%"){let i=t[n];if(n++,_e(t,n))return ke(i,n);let{expr:a,pos:l}=ks(e,t,n);r={type:"ArithBinary",operator:i,left:r,right:a},n=l}else break;return{expr:r,pos:n}}function ks(e,t,s){let{expr:r,pos:n}=Ln(e,t,s),i=oe(t,n);if(t.slice(i,i+2)==="**"){if(i+=2,_e(t,i))return ke("**",i);let{expr:l,pos:o}=ks(e,t,i);return{expr:{type:"ArithBinary",operator:"**",left:r,right:l},pos:o}}return{expr:r,pos:n}}function Ln(e,t,s){let r=oe(t,s);if(t.slice(r,r+2)==="++"||t.slice(r,r+2)==="--"){let n=t.slice(r,r+2);r+=2;let{expr:i,pos:a}=Ln(e,t,r);return{expr:{type:"ArithUnary",operator:n,operand:i,prefix:!0},pos:a}}if(t[r]==="+"||t[r]==="-"||t[r]==="!"||t[r]==="~"){let n=t[r];r++;let{expr:i,pos:a}=Ln(e,t,r);return{expr:{type:"ArithUnary",operator:n,operand:i,prefix:!0},pos:a}}return Fc(e,t,r)}function Mc(e,t){let s=e[t];return s==="$"||s==="`"}function Fc(e,t,s){let{expr:r,pos:n}=Ki(e,t,s,!1),i=[r];for(;Mc(t,n);){let{expr:l,pos:o}=Ki(e,t,n,!0);i.push(l),n=o}i.length>1&&(r={type:"ArithConcat",parts:i});let a;if(t[n]==="["&&r.type==="ArithConcat"){n++;let{expr:l,pos:o}=Oe(e,t,n);a=l,n=o,t[n]==="]"&&n++}if(a&&r.type==="ArithConcat"&&(r={type:"ArithDynamicElement",nameExpr:r,subscript:a},a=void 0),n=oe(t,n),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let l of Ns)if(t.slice(n,n+l.length)===l&&t.slice(n,n+l.length+1)!=="=="){n+=l.length;let{expr:o,pos:u}=ts(e,t,n);return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:l,target:r.nameExpr,subscript:r.subscript,value:o},pos:u}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:l,target:r,value:o},pos:u}:{expr:{type:"ArithAssignment",operator:l,variable:r.name,value:o},pos:u}}}if(t.slice(n,n+2)==="++"||t.slice(n,n+2)==="--"){let l=t.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:l,operand:r,prefix:!1},pos:n}}return{expr:r,pos:n}}function Ki(e,t,s,r=!1){let n=oe(t,s),i=Fi(Oe,e,t,n);if(i)return i;let a=Vi(t,n);if(a)return a;let l=zi(t,n);if(l)return l;if(t.slice(n,n+2)==="$("&&t[n+2]!=="("){n+=2;let u=1,c=n;for(;n<t.length&&u>0;)t[n]==="("?u++:t[n]===")"&&u--,u>0&&n++;let f=t.slice(c,n);return n++,{expr:{type:"ArithCommandSubst",command:f},pos:n}}if(t[n]==="`"){n++;let u=n;for(;n<t.length&&t[n]!=="`";)n++;let c=t.slice(u,n);return t[n]==="`"&&n++,{expr:{type:"ArithCommandSubst",command:c},pos:n}}if(t[n]==="("){n++;let{expr:u,pos:c}=Oe(e,t,n);return n=oe(t,c),t[n]===")"&&n++,{expr:{type:"ArithGroup",expression:u},pos:n}}if(t[n]==="'"){n++;let u="";for(;n<t.length&&t[n]!=="'";)u+=t[n],n++;t[n]==="'"&&n++;let c=Number.parseInt(u,10);return{expr:{type:"ArithSingleQuote",content:u,value:Number.isNaN(c)?0:c},pos:n}}if(t[n]==='"'){n++;let u="";for(;n<t.length&&t[n]!=='"';)t[n]==="\\"&&n+1<t.length?(u+=t[n+1],n+=2):(u+=t[n],n++);t[n]==='"'&&n++;let c=u.trim();if(!c)return{expr:{type:"ArithNumber",value:0},pos:n};let{expr:f}=Oe(e,c,0);return{expr:f,pos:n}}if(/[0-9]/.test(t[n])){let u="",c=!1,f=!1;for(;n<t.length;){let h=t[n];if(c)if(/[0-9a-zA-Z@_]/.test(h))u+=h,n++;else break;else if(h==="#")c=!0,u+=h,n++;else if(u==="0"&&(h==="x"||h==="X")&&n+1<t.length&&/[0-9a-fA-F]/.test(t[n+1]))f=!0,u+=h,n++;else if(f&&/[0-9a-fA-F]/.test(h))u+=h,n++;else if(!f&&/[0-9]/.test(h))u+=h,n++;else break}if(n<t.length&&/[a-zA-Z_]/.test(t[n])){let h=u;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)h+=t[n],n++;return{expr:{type:"ArithSyntaxError",errorToken:h,message:`${h}: value too great for base (error token is "${h}")`},pos:n}}if(t[n]==="."&&/[0-9]/.test(t[n+1]))throw new te(`${u}.${t[n+1]}...: syntax error: invalid arithmetic operator`);if(t[n]==="["){let h=t.slice(n).trim();return{expr:{type:"ArithNumberSubscript",number:u,errorToken:h},pos:t.length}}return{expr:{type:"ArithNumber",value:es(u)},pos:n}}if(t[n]==="$"&&t[n+1]==="{"){let u=n+2,c=1,f=u;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;let d=t.slice(u,f),h=f+1;if(t[h]==="#"){let p=h+1;for(;p<t.length&&/[0-9a-zA-Z@_]/.test(t[p]);)p++;let m=t.slice(h+1,p);return{expr:{type:"ArithDynamicBase",baseExpr:d,value:m},pos:p}}if(/[0-9]/.test(t[h])||t[h]==="x"||t[h]==="X"){let p=h;if(t[h]==="x"||t[h]==="X")for(p++;p<t.length&&/[0-9a-fA-F]/.test(t[p]);)p++;else for(;p<t.length&&/[0-9]/.test(t[p]);)p++;let m=t.slice(h,p);return{expr:{type:"ArithDynamicNumber",prefix:d,suffix:m},pos:p}}return n=h,{expr:{type:"ArithBracedExpansion",content:d},pos:n}}if(t[n]==="$"&&n+1<t.length&&/[0-9]/.test(t[n+1])){n++;let u="";for(;n<t.length&&/[0-9]/.test(t[n]);)u+=t[n],n++;return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:!0},pos:n}}if(t[n]==="$"&&n+1<t.length&&/[*@#?\-!$]/.test(t[n+1])){let u=t[n+1];return n+=2,{expr:{type:"ArithSpecialVar",name:u},pos:n}}let o=!1;if(t[n]==="$"&&n+1<t.length&&/[a-zA-Z_]/.test(t[n+1])&&(o=!0,n++),n<t.length&&/[a-zA-Z_]/.test(t[n])){let u="";for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)u+=t[n],n++;if(t[n]==="["&&!r){n++;let c;if(t[n]==="'"||t[n]==='"'){let d=t[n];for(n++,c="";n<t.length&&t[n]!==d;)c+=t[n],n++;t[n]===d&&n++,n=oe(t,n),t[n]==="]"&&n++}let f;if(c===void 0){let{expr:d,pos:h}=Oe(e,t,n);f=d,n=h,t[n]==="]"&&n++}if(n=oe(t,n),t[n]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:u,index:f},pos:n};if(!r){for(let d of Ns)if(t.slice(n,n+d.length)===d&&t.slice(n,n+d.length+1)!=="=="){n+=d.length;let{expr:h,pos:p}=ts(e,t,n);return{expr:{type:"ArithAssignment",operator:d,variable:u,subscript:f,stringKey:c,value:h},pos:p}}}return{expr:{type:"ArithArrayElement",array:u,index:f,stringKey:c},pos:n}}if(n=oe(t,n),!r){for(let c of Ns)if(t.slice(n,n+c.length)===c&&t.slice(n,n+c.length+1)!=="=="){n+=c.length;let{expr:f,pos:d}=ts(e,t,n);return{expr:{type:"ArithAssignment",operator:c,variable:u,value:f},pos:d}}}return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:o},pos:n}}if(t[n]==="#"){let u=n+1;for(;u<t.length&&t[u]!==`
59
+ `;)u++;let c=t.slice(n,u).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:c,message:`${c}: syntax error: invalid arithmetic operator (error token is "${c}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:n}}function Vc(e){let t="",s=0;for(;s<e.length;){let r=e[s];if(r<128){t+=String.fromCharCode(r),s++;continue}if((r&224)===192){if(s+1<e.length&&(e[s+1]&192)===128&&r>=194){let n=(r&31)<<6|e[s+1]&63;t+=String.fromCharCode(n),s+=2;continue}t+=String.fromCharCode(r),s++;continue}if((r&240)===224){if(s+2<e.length&&(e[s+1]&192)===128&&(e[s+2]&192)===128){if(r===224&&e[s+1]<160){t+=String.fromCharCode(r),s++;continue}let n=(r&15)<<12|(e[s+1]&63)<<6|e[s+2]&63;if(n>=55296&&n<=57343){t+=String.fromCharCode(r),s++;continue}t+=String.fromCharCode(n),s+=3;continue}t+=String.fromCharCode(r),s++;continue}if((r&248)===240&&r<=244){if(s+3<e.length&&(e[s+1]&192)===128&&(e[s+2]&192)===128&&(e[s+3]&192)===128){if(r===240&&e[s+1]<144){t+=String.fromCharCode(r),s++;continue}let n=(r&7)<<18|(e[s+1]&63)<<12|(e[s+2]&63)<<6|e[s+3]&63;if(n>1114111){t+=String.fromCharCode(r),s++;continue}t+=String.fromCodePoint(n),s+=4;continue}t+=String.fromCharCode(r),s++;continue}t+=String.fromCharCode(r),s++}return t}function Ji(e,t,s){let r=s+1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;return r}function Wn(e,t,s,r,n){let i=1,a=s+1;for(;a<t.length&&i>0;)t[a]===r?i++:t[a]===n&&i--,i>0&&a++;return i===0?a:-1}function Nt(e,t,s){let r=s,n=1;for(;r<t.length&&n>0;){let i=t[r];if(i==="\\"&&r+1<t.length){r+=2;continue}if(i==="'"){let a=t.indexOf("'",r+1);if(a!==-1){r=a+1;continue}}if(i==='"'){for(r++;r<t.length&&t[r]!=='"';)t[r]==="\\"&&r+1<t.length?r+=2:r++;r<t.length&&r++;continue}i==="{"?n++:i==="}"&&n--,n>0&&r++}return r}function ea(e,t,s){let r=s,n=!1;for(;r<t.length;){let i=t[r];if(i==="/"&&n||i==="}")break;if(i==="'"){let a=t.indexOf("'",r+1);if(a!==-1){r=a+1,n=!0;continue}}if(i==='"'){for(r++;r<t.length&&t[r]!=='"';)t[r]==="\\"&&r+1<t.length?r+=2:r++;r<t.length&&r++,n=!0;continue}i==="\\"?(r+=2,n=!0):(r++,n=!0)}return r}function ta(e,t,s){let r=s,n="";for(;r<t.length;){let i=t[r];if(i==="*"||i==="?")n+=i,r++;else if(i==="["){let a=zc(t,r);a===-1?(n+=i,r++):(n+=t.slice(r,a+1),r=a+1)}else break}return{pattern:n,endIndex:r}}function zc(e,t){let s=t+1;for(s<e.length&&e[s]==="^"&&s++,s<e.length&&e[s]==="]"&&s++;s<e.length;){let r=e[s];if(r==="\\"&&s+1<e.length){let n=e[s+1];if(n==='"'||n==="'")return-1;s+=2;continue}if(r==="]")return s;if(r==='"'||r==="$"||r==="`")return-1;if(r==="'"){let n=e.indexOf("'",s+1);if(n!==-1){s=n+1;continue}}if(r==="["&&s+1<e.length&&e[s+1]===":"){let n=e.indexOf(":]",s+2);if(n!==-1){s=n+2;continue}}if(r==="["&&s+1<e.length&&(e[s+1]==="."||e[s+1]==="=")){let i=`${e[s+1]}]`,a=e.indexOf(i,s+2);if(a!==-1){s=a+2;continue}}s++}return-1}function sa(e,t,s){let r="",n=s;for(;n<t.length&&t[n]!=="'";){let i=t[n];if(i==="\\"&&n+1<t.length)switch(t[n+1]){case"n":r+=`
60
+ `,n+=2;break;case"t":r+=" ",n+=2;break;case"r":r+="\r",n+=2;break;case"\\":r+="\\",n+=2;break;case"'":r+="'",n+=2;break;case'"':r+='"',n+=2;break;case"a":r+="\x07",n+=2;break;case"b":r+="\b",n+=2;break;case"e":case"E":r+="\x1B",n+=2;break;case"f":r+="\f",n+=2;break;case"v":r+="\v",n+=2;break;case"x":{let l=[],o=n;for(;o+1<t.length&&t[o]==="\\"&&t[o+1]==="x";){let u=t.slice(o+2,o+4),c=parseInt(u,16);if(!Number.isNaN(c)&&u.length>0)l.push(c),o+=2+u.length;else break}l.length>0?(r+=Vc(l),n=o):(r+="\\x",n+=2);break}case"u":{let l=t.slice(n+2,n+6),o=parseInt(l,16);Number.isNaN(o)?(r+="\\u",n+=2):(r+=String.fromCharCode(o),n+=6);break}case"c":{if(n+2<t.length){let o=t[n+2].charCodeAt(0)&31;r+=String.fromCharCode(o),n+=3}else r+="\\c",n+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let l="",o=n+1;for(;o<t.length&&o<n+4&&/[0-7]/.test(t[o]);)l+=t[o],o++;let u=parseInt(l,8);r+=String.fromCharCode(u),n=o;break}default:r+=i,n++}else r+=i,n++}return n<t.length&&t[n]==="'"&&n++,{part:x.literal(r),endIndex:n}}function Mn(e,t){let s=t.trim();return s===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:X(e,s)}function Yi(e){let t=[],s="",r=0;for(let n=0;n<e.length;n++){let i=e[n];i==="{"?(r++,s+=i):i==="}"?(r--,s+=i):i===","&&r===0?(t.push(s),s=""):s+=i}return t.push(s),t}function na(e,t,s,r){let n=Wn(e,t,s,"{","}");if(n===-1)return null;let i=t.slice(s+1,n),a=i.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(a)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(a[1],10),end:Number.parseInt(a[2],10),step:a[3]?Number.parseInt(a[3],10):void 0,startStr:a[1],endStr:a[2]}]},endIndex:n+1};let l=i.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return l?{part:{type:"BraceExpansion",items:[{type:"Range",start:l[1],end:l[2],step:l[3]?Number.parseInt(l[3],10):void 0}]},endIndex:n+1}:i.includes(",")&&r?{part:{type:"BraceExpansion",items:Yi(i).map(c=>({type:"Word",word:x.word(r(e,c,!1,!1,!1))}))},endIndex:n+1}:i.includes(",")?{part:{type:"BraceExpansion",items:Yi(i).map(c=>({type:"Word",word:x.word([x.literal(c)])}))},endIndex:n+1}:null}function Fn(e,t){let s="";for(let r of t.parts)switch(r.type){case"Literal":s+=r.value;break;case"SingleQuoted":s+=`'${r.value}'`;break;case"Escaped":s+=r.value;break;case"DoubleQuoted":s+='"';for(let n of r.parts)n.type==="Literal"||n.type==="Escaped"?s+=n.value:n.type==="ParameterExpansion"&&(s+=`\${${n.parameter}}`);s+='"';break;case"ParameterExpansion":s+=`\${${r.parameter}}`;break;case"Glob":s+=r.pattern;break;case"TildeExpansion":s+="~",r.user&&(s+=r.user);break;case"BraceExpansion":{s+="{";let n=[];for(let i of r.items)if(i.type==="Range"){let a=i.startStr??String(i.start),l=i.endStr??String(i.end);i.step!==void 0?n.push(`${a}..${l}..${i.step}`):n.push(`${a}..${l}`)}else n.push(Fn(e,i.word));n.length===1&&r.items[0].type==="Range"?s+=n[0]:s+=n.join(","),s+="}";break}default:s+=r.type}return s}function ra(e,t){return{[g.LESS]:"<",[g.GREAT]:">",[g.DGREAT]:">>",[g.LESSAND]:"<&",[g.GREATAND]:">&",[g.LESSGREAT]:"<>",[g.CLOBBER]:">|",[g.TLESS]:"<<<",[g.AND_GREAT]:"&>",[g.AND_DGREAT]:"&>>",[g.DLESS]:"<",[g.DLESSDASH]:"<"}[t]||">"}function _s(e){let t=e.current(),s=t.type;if(s===g.NUMBER){let r=e.peek(1);return t.end!==r.start?!1:Wi.has(r.type)}if(s===g.FD_VARIABLE){let r=e.peek(1);return Mi.has(r.type)}return Li.has(s)}function Ps(e){let t=null,s;e.check(g.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(g.FD_VARIABLE)&&(s=e.advance().value);let r=e.advance(),n=ra(e,r.type);if(r.type===g.DLESS||r.type===g.DLESSDASH)return Bc(e,n,t,r.type===g.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return x.redirection(n,i,t,s)}function Bc(e,t,s,r){e.isWord()||e.error("Expected here-document delimiter");let n=e.advance(),i=n.value,a=n.quoted||!1;(i.startsWith("'")&&i.endsWith("'")||i.startsWith('"')&&i.endsWith('"'))&&(i=i.slice(1,-1));let l=x.redirection(r?"<<-":"<<",x.hereDoc(i,x.word([]),r,a),s);return e.addPendingHeredoc(l,i,r,a),l}function aa(e){let t=e.current().line,s=[],r=null,n=[],i=[];for(;e.check(g.ASSIGNMENT_WORD)||_s(e);)e.checkIterationLimit(),e.check(g.ASSIGNMENT_WORD)?s.push(qc(e)):i.push(Ps(e));if(e.isWord())r=e.parseWord();else if(s.length>0&&(e.check(g.DBRACK_START)||e.check(g.DPAREN_START))){let l=e.advance();r=x.word([x.literal(l.value)])}for(;(!e.isStatementEnd()||e.check(g.RBRACE))&&!e.check(g.PIPE,g.PIPE_AMP);)if(e.checkIterationLimit(),_s(e))i.push(Ps(e));else if(e.check(g.RBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(g.LBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(g.DBRACK_END)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.isWord())n.push(e.parseWord());else if(e.check(g.ASSIGNMENT_WORD)){let l=e.advance(),o=l.value,u=o.endsWith("="),c=o.endsWith("=(");if((u||c)&&(c||e.check(g.LPAREN))){let f=c?o.slice(0,-2):o.slice(0,-1);c||e.expect(g.LPAREN);let d=Vn(e);e.expect(g.RPAREN);let h=d.map(m=>Fn(e,m)),p=`${f}=(${h.join(" ")})`;n.push(e.parseWordFromString(p,!1,!1))}else n.push(e.parseWordFromString(o,l.quoted,l.singleQuoted))}else if(e.check(g.LPAREN))e.error("syntax error near unexpected token `('");else break;let a=x.simpleCommand(r,n,s,i);return a.line=t,a}function qc(e){let t=e.expect(g.ASSIGNMENT_WORD),s=t.value,r=s.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||e.error(`Invalid assignment: ${s}`);let n=r[0],i,a=n.length;if(s[a]==="["){let f=0,d=a+1;for(;a<s.length;a++)if(s[a]==="[")f++;else if(s[a]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${s}`),i=s.slice(d,a),a++}let l=s[a]==="+";l&&a++,s[a]!=="="&&e.error(`Invalid assignment: ${s}`),a++;let o=s.slice(a);if(o==="("){let f=Vn(e);e.expect(g.RPAREN);let d=i!==void 0?`${n}[${i}]`:n;return x.assignment(d,null,l,f)}if(o===""&&e.check(g.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=Vn(e);e.expect(g.RPAREN);let h=i!==void 0?`${n}[${i}]`:n;return x.assignment(h,null,l,d)}}let u=o?e.parseWordFromString(o,t.quoted,t.singleQuoted,!0):null,c=i!==void 0?`${n}[${i}]`:n;return x.assignment(c,u,l,null)}var Uc=new Set([g.AMP,g.PIPE,g.PIPE_AMP,g.SEMICOLON,g.AND_AND,g.OR_OR,g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND]);function Vn(e){let t=[];for(e.skipNewlines();!e.check(g.RPAREN,g.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):Uc.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function zn(e,t){e.expect(g.IF);let s=[],r=e.parseCompoundList();e.expect(g.THEN);let n=e.parseCompoundList();if(n.length===0){let l=e.check(g.FI)?"fi":e.check(g.ELSE)?"else":e.check(g.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${l}'`)}for(s.push({condition:r,body:n});e.check(g.ELIF);){e.advance();let l=e.parseCompoundList();e.expect(g.THEN);let o=e.parseCompoundList();if(o.length===0){let u=e.check(g.FI)?"fi":e.check(g.ELSE)?"else":e.check(g.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${u}'`)}s.push({condition:l,body:o})}let i=null;e.check(g.ELSE)&&(e.advance(),i=e.parseCompoundList(),i.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(g.FI);let a=t?.skipRedirections?[]:e.parseOptionalRedirections();return x.ifNode(s,i,a)}function Bn(e,t){let s=e.expect(g.FOR);if(e.check(g.DPAREN_START))return Hc(e,t,s.line);e.isWord()||e.error("Expected variable name in for loop");let n=e.advance().value,i=null;if(e.skipNewlines(),e.check(g.IN))for(e.advance(),i=[];!e.check(g.SEMICOLON,g.NEWLINE,g.DO,g.EOF)&&e.isWord();)i.push(e.parseWord());e.check(g.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(g.DO);let a=e.parseCompoundList();e.expect(g.DONE);let l=t?.skipRedirections?[]:e.parseOptionalRedirections();return x.forNode(n,i,a,l)}function Hc(e,t,s){e.expect(g.DPAREN_START);let r=null,n=null,i=null,a=["","",""],l=0,o=0;for(;!e.check(g.DPAREN_END,g.EOF);){let f=e.advance();if(f.type===g.SEMICOLON&&o===0){if(l++,l>2)break}else f.value==="("&&o++,f.value===")"&&o--,a[l]+=f.value}e.expect(g.DPAREN_END),a[0].trim()&&(r=X(e,a[0].trim())),a[1].trim()&&(n=X(e,a[1].trim())),a[2].trim()&&(i=X(e,a[2].trim())),e.skipNewlines(),e.check(g.SEMICOLON)&&e.advance(),e.skipNewlines();let u;e.check(g.LBRACE)?(e.advance(),u=e.parseCompoundList(),e.expect(g.RBRACE)):(e.expect(g.DO),u=e.parseCompoundList(),e.expect(g.DONE));let c=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:n,update:i,body:u,redirections:c,line:s}}function qn(e,t){e.expect(g.WHILE);let s=e.parseCompoundList();e.expect(g.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(g.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return x.whileNode(s,r,n)}function Un(e,t){e.expect(g.UNTIL);let s=e.parseCompoundList();e.expect(g.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(g.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return x.untilNode(s,r,n)}function Zn(e,t){e.expect(g.CASE),e.isWord()||e.error("Expected word after 'case'");let s=e.parseWord();e.skipNewlines(),e.expect(g.IN),e.skipNewlines();let r=[];for(;!e.check(g.ESAC,g.EOF);){e.checkIterationLimit();let i=e.getPos(),a=jc(e);if(a&&r.push(a),e.skipNewlines(),e.getPos()===i&&!a)break}e.expect(g.ESAC);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return x.caseNode(s,r,n)}function jc(e){e.check(g.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(g.PIPE));)e.advance();if(t.length===0)return null;e.expect(g.RPAREN),e.skipNewlines();let s=[];for(;!e.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND,g.ESAC,g.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===g.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(g.LPAREN)&&e.peek(1).type===g.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let n=e.getPos(),i=e.parseStatement();if(i&&s.push(i),e.skipSeparators(!1),e.getPos()===n&&!i)break}let r=";;";return e.check(g.DSEMI)?(e.advance(),r=";;"):e.check(g.SEMI_AND)?(e.advance(),r=";&"):e.check(g.SEMI_SEMI_AND)&&(e.advance(),r=";;&"),x.caseItem(t,s,r)}function Hn(e,t){e.expect(g.LPAREN);let s=e.parseCompoundList();e.expect(g.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return x.subshell(s,r)}function jn(e,t){e.expect(g.LBRACE);let s=e.parseCompoundList();e.expect(g.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return x.group(s,r)}var Qc=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],Kc=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function oa(e){return e.isWord()||e.check(g.LBRACE)||e.check(g.RBRACE)||e.check(g.ASSIGNMENT_WORD)}function la(e){if(e.check(g.BANG)&&e.peek(1).type===g.LPAREN){e.advance(),e.advance();let t=1,s="!(";for(;t>0&&!e.check(g.EOF);)if(e.check(g.LPAREN))t++,s+="(",e.advance();else if(e.check(g.RPAREN))t--,t>0&&(s+=")"),e.advance();else if(e.isWord())s+=e.advance().value;else if(e.check(g.PIPE))s+="|",e.advance();else break;return s+=")",e.parseWordFromString(s,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function Qn(e){return e.skipNewlines(),Xc(e)}function Xc(e){let t=ca(e);for(e.skipNewlines();e.check(g.OR_OR);){e.advance(),e.skipNewlines();let s=ca(e);t={type:"CondOr",left:t,right:s},e.skipNewlines()}return t}function ca(e){let t=Gn(e);for(e.skipNewlines();e.check(g.AND_AND);){e.advance(),e.skipNewlines();let s=Gn(e);t={type:"CondAnd",left:t,right:s},e.skipNewlines()}return t}function Gn(e){return e.skipNewlines(),e.check(g.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:Gn(e)}):Yc(e)}function Yc(e){if(e.check(g.LPAREN)){e.advance();let t=Qn(e);return e.expect(g.RPAREN),{type:"CondGroup",expression:t}}if(oa(e)){let t=e.current(),s=t.value;if(Qc.includes(s)&&!t.quoted){if(e.advance(),e.check(g.DBRACK_END)&&e.error(`Expected operand after ${s}`),oa(e)){let i=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:s,operand:i}}let n=e.current();e.error(`unexpected argument \`${n.value}' to conditional unary operator`)}let r=e.parseWordNoBraceExpansion();if(e.isWord()&&Kc.includes(e.current().value)){let n=e.advance().value,i;return n==="=~"?i=Jc(e):n==="=="||n==="!="?i=la(e):i=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:n,left:r,right:i}}if(e.check(g.LESS)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:r,right:n}}if(e.check(g.GREAT)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:r,right:n}}if(e.isWord()&&e.current().value==="="){e.advance();let n=la(e);return{type:"CondBinary",operator:"==",left:r,right:n}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function Jc(e){let t=[],s=0,r=-1,n=e.getInput(),i=()=>e.check(g.DBRACK_END)||e.check(g.AND_AND)||e.check(g.OR_OR)||e.check(g.NEWLINE)||e.check(g.EOF);for(;!i();){let a=e.current(),l=r>=0&&a.start>r;if(s===0&&l)break;if(s>0&&l){let o=n.slice(r,a.start);t.push({type:"Literal",value:o})}if(e.isWord()||e.check(g.ASSIGNMENT_WORD)){let o=e.parseWordForRegex();t.push(...o.parts),r=e.peek(-1).end}else if(e.check(g.LPAREN)){let o=e.advance();t.push({type:"Literal",value:"("}),s++,r=o.end}else if(e.check(g.DPAREN_START)){let o=e.advance();t.push({type:"Literal",value:"(("}),s+=2,r=o.end}else if(e.check(g.DPAREN_END))if(s>=2){let o=e.advance();t.push({type:"Literal",value:"))"}),s-=2,r=o.end}else{if(s===1)break;break}else if(e.check(g.RPAREN))if(s>0){let o=e.advance();t.push({type:"Literal",value:")"}),s--,r=o.end}else break;else if(e.check(g.PIPE)){let o=e.advance();t.push({type:"Literal",value:"|"}),r=o.end}else if(e.check(g.SEMICOLON))if(s>0){let o=e.advance();t.push({type:"Literal",value:";"}),r=o.end}else break;else if(s>0&&e.check(g.LESS)){let o=e.advance();t.push({type:"Literal",value:"<"}),r=o.end}else if(s>0&&e.check(g.GREAT)){let o=e.advance();t.push({type:"Literal",value:">"}),r=o.end}else if(s>0&&e.check(g.DGREAT)){let o=e.advance();t.push({type:"Literal",value:">>"}),r=o.end}else if(s>0&&e.check(g.DLESS)){let o=e.advance();t.push({type:"Literal",value:"<<"}),r=o.end}else if(s>0&&e.check(g.LESSAND)){let o=e.advance();t.push({type:"Literal",value:"<&"}),r=o.end}else if(s>0&&e.check(g.GREATAND)){let o=e.advance();t.push({type:"Literal",value:">&"}),r=o.end}else if(s>0&&e.check(g.LESSGREAT)){let o=e.advance();t.push({type:"Literal",value:"<>"}),r=o.end}else if(s>0&&e.check(g.CLOBBER)){let o=e.advance();t.push({type:"Literal",value:">|"}),r=o.end}else if(s>0&&e.check(g.TLESS)){let o=e.advance();t.push({type:"Literal",value:"<<<"}),r=o.end}else if(s>0&&e.check(g.AMP)){let o=e.advance();t.push({type:"Literal",value:"&"}),r=o.end}else if(s>0&&e.check(g.LBRACE)){let o=e.advance();t.push({type:"Literal",value:"{"}),r=o.end}else if(s>0&&e.check(g.RBRACE)){let o=e.advance();t.push({type:"Literal",value:"}"}),r=o.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function ss(e){return e.length>0?e:[x.literal("")]}function tu(e,t){let s=1,r=t+1;for(;r<e.length&&s>0;){let n=e[r];if(n==="\\"){r+=2;continue}if("@*+?!".includes(n)&&r+1<e.length&&e[r+1]==="("){r++,s++,r++;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function su(e,t,s){let r=s+1,n=t[r];if("@*#?$!-0123456789".includes(n))return{part:x.parameterExpansion(n),endIndex:r+1};let i="";for(;r<t.length&&/[a-zA-Z0-9_]/.test(t[r]);)i+=t[r],r++;return{part:x.parameterExpansion(i),endIndex:r}}function nu(e,t,s,r=!1){let n=s+2,i=!1;t[n]==="!"&&(i=!0,n++);let a=!1;t[n]==="#"&&!/[}:#%/^,]/.test(t[n+1]||"}")&&(a=!0,n++);let l="",o=t[n];if(/[@*#?$!-]/.test(o)&&!/[a-zA-Z0-9_]/.test(t[n+1]||""))l=o,n++;else for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)l+=t[n],n++;if(t[n]==="["){let c=Wn(e,t,n,"[","]");if(l+=t.slice(n,c+1),n=c+1,t[n]==="["){let f=1,d=n;for(;d<t.length&&f>0;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let h=t.slice(s+2,d);return{part:x.parameterExpansion("",{type:"BadSubstitution",text:h}),endIndex:d+1}}}if(l===""&&!i&&!a&&t[n]!=="}"){let c=1,f=n;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;if(c>0)throw new we("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(s+2,f);return{part:x.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let u=null;if(i){let c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(c)if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=Kn(e,t,n,l,r);f.operation?(u={type:"Indirection",innerOp:f.operation},n=f.endIndex):(u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},l="")}else u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},l="";else if(t[n]==="*"||t[n]==="@"&&!/[QPaAEKkuUL]/.test(t[n+1]||"")){let f=t[n];n++,u={type:"VarNamePrefix",prefix:l,star:f==="*"},l=""}else if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=Kn(e,t,n,l,r);f.operation?(u={type:"Indirection",innerOp:f.operation},n=f.endIndex):u={type:"Indirection"}}else u={type:"Indirection"}}else if(a)if(t[n]===":")for(u={type:"LengthSliceError"};n<t.length&&t[n]!=="}";)n++;else t[n]!=="}"&&/[-+=?]/.test(t[n])?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):t[n]==="/"?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):u={type:"Length"};if(!u&&n<t.length&&t[n]!=="}"){let c=Kn(e,t,n,l,r);u=c.operation,n=c.endIndex}if(n<t.length&&t[n]!=="}"){let c=t[n];if(!/[:\-+=?#%/^,@[]/.test(c)){let f=n;for(;f<t.length&&t[f]!=="}";)f++;let d=t.slice(s,f+1);e.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;n<t.length&&t[n]!=="}";)n++;if(n>=t.length)throw new we("unexpected EOF while looking for matching '}'",0,0);return{part:x.parameterExpansion(l,u),endIndex:n+1}}function Kn(e,t,s,r,n=!1){let i=s,a=t[i],l=t[i+1]||"";if(a===":"){let o=l;if("-=?+".includes(o)){i+=2;let b=Nt(e,t,i),v=t.slice(i,b),E=mt(e,v,!1,!1,!0,!1,n,!1,!1,!0),w=x.word(ss(E));if(o==="-")return{operation:{type:"DefaultValue",word:w,checkEmpty:!0},endIndex:b};if(o==="=")return{operation:{type:"AssignDefault",word:w,checkEmpty:!0},endIndex:b};if(o==="?")return{operation:{type:"ErrorIfUnset",word:w,checkEmpty:!0},endIndex:b};if(o==="+")return{operation:{type:"UseAlternative",word:w,checkEmpty:!0},endIndex:b}}i++;let u=Nt(e,t,i),c=t.slice(i,u),f=-1,d=0,h=0;for(let y=0;y<c.length;y++){let b=c[y];if(b==="("||b==="[")d++;else if(b===")"||b==="]")d--;else if(b==="?"&&d===0)h++;else if(b===":"&&d===0)if(h>0)h--;else{f=y;break}}let p=f>=0?c.slice(0,f):c,m=f>=0?c.slice(f+1):null;return{operation:{type:"Substring",offset:Mn(e,p),length:m!==null?Mn(e,m):null},endIndex:u}}if("-=?+".includes(a)){i++;let o=Nt(e,t,i),u=t.slice(i,o),c=mt(e,u,!1,!1,!0,!1,n,!1,!1,!0),f=x.word(ss(c));if(a==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:o};if(a==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:o};if(a==="?")return{operation:{type:"ErrorIfUnset",word:u?f:null,checkEmpty:!1},endIndex:o};if(a==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:o}}if(a==="#"||a==="%"){let o=l===a,u=a==="#"?"prefix":"suffix";i+=o?2:1;let c=Nt(e,t,i),f=t.slice(i,c),d=mt(e,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:x.word(ss(d)),side:u,greedy:o},endIndex:c}}if(a==="/"){let o=l==="/";i+=o?2:1;let u=null;t[i]==="#"?(u="start",i++):t[i]==="%"&&(u="end",i++);let c;u!==null&&(t[i]==="/"||t[i]==="}")?c=i:c=ea(e,t,i);let f=t.slice(i,c),d=mt(e,f,!1,!1,!1),h=x.word(ss(d)),p=null,m=c;if(t[c]==="/"){let y=c+1,b=Nt(e,t,y),v=t.slice(y,b),E=mt(e,v,!1,!1,!1);p=x.word(ss(E)),m=b}return{operation:{type:"PatternReplacement",pattern:h,replacement:p,all:o,anchor:u},endIndex:m}}if(a==="^"||a===","){let o=l===a,u=a==="^"?"upper":"lower";i+=o?2:1;let c=Nt(e,t,i),f=t.slice(i,c),d=f?x.word([x.literal(f)]):null;return{operation:{type:"CaseModification",direction:u,all:o,pattern:d},endIndex:c}}return a==="@"&&/[QPaAEKkuUL]/.test(l)?{operation:{type:"Transform",operator:l},endIndex:i+2}:{operation:null,endIndex:i}}function Xn(e,t,s,r=!1){let n=s+1;if(n>=t.length)return{part:x.literal("$"),endIndex:n};let i=t[n];if(i==="("&&t[n+1]==="(")return e.isDollarDparenSubshell(t,s)?e.parseCommandSubstitution(t,s):e.parseArithmeticExpansion(t,s);if(i==="["){let a=1,l=n+1;for(;l<t.length&&a>0;)t[l]==="["?a++:t[l]==="]"&&a--,a>0&&l++;if(a===0){let o=t.slice(n+1,l),u=X(e,o);return{part:x.arithmeticExpansion(u),endIndex:l+1}}}return i==="("?e.parseCommandSubstitution(t,s):i==="{"?nu(e,t,s,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?su(e,t,s):{part:x.literal("$"),endIndex:n}}function ua(e,t){let s=[],r=0,n="",i=()=>{n&&(s.push(x.literal(n)),n="")};for(;r<t.length;){let a=t[r];if(a==="\\"&&r+1<t.length){let l=t[r+1];if(l==="$"||l==="`"||l==='"'||l==="\\"){n+=l,r+=2;continue}n+=a,r++;continue}if(a==="$"){i();let{part:l,endIndex:o}=Xn(e,t,r,!0);l&&s.push(l),r=o;continue}if(a==="`"){i();let{part:l,endIndex:o}=e.parseBacktickSubstitution(t,r,!0);s.push(l),r=o;continue}n+=a,r++}return i(),s}function ru(e,t,s){let r=[],n=s,i="",a=()=>{i&&(r.push(x.literal(i)),i="")};for(;n<t.length&&t[n]!=='"';){let l=t[n];if(l==="\\"&&n+1<t.length){let o=t[n+1];if('"\\$`\n'.includes(o)){i+=o,n+=2;continue}i+=l,n++;continue}if(l==="$"){a();let{part:o,endIndex:u}=Xn(e,t,n,!0);o&&r.push(o),n=u;continue}if(l==="`"){a();let{part:o,endIndex:u}=e.parseBacktickSubstitution(t,n,!0);r.push(o),n=u;continue}i+=l,n++}return a(),{part:x.doubleQuoted(r),endIndex:n}}function mt(e,t,s=!1,r=!1,n=!1,i=!1,a=!1,l=!1,o=!1,u=!1){if(r)return[x.singleQuoted(t)];if(s){let p=ua(e,t);return[x.doubleQuoted(p)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let p=t.slice(1,-1),m=!1;for(let y=0;y<p.length;y++){if(p[y]==='"'){m=!0;break}p[y]==="\\"&&y+1<p.length&&y++}if(!m){let y=ua(e,p);return[x.doubleQuoted(y)]}}let c=[],f=0,d="",h=()=>{d&&(c.push(x.literal(d)),d="")};for(;f<t.length;){let p=t[f];if(p==="\\"&&f+1<t.length){let m=t[f+1];if(o){h(),c.push(x.escaped(m)),f+=2;continue}let y=i?m==="$"||m==="`"||m===`
61
+ `:m==="$"||m==="`"||m==='"'||m==="'"||m===`
62
+ `||u&&m==="}",b=a?"*?[]\\".includes(m):"*?[]\\(){}.^+".includes(m);y?d+=m:b?(h(),c.push(x.escaped(m))):d+=`\\${m}`,f+=2;continue}if(p==="'"&&!a&&!i){h();let m=t.indexOf("'",f+1);if(m===-1){d+=t.slice(f);break}c.push(x.singleQuoted(t.slice(f+1,m))),f=m+1;continue}if(p==='"'&&!i){h();let{part:m,endIndex:y}=ru(e,t,f+1);c.push(m),f=y+1;continue}if(p==="$"&&t[f+1]==="'"){h();let{part:m,endIndex:y}=sa(e,t,f+2);c.push(m),f=y;continue}if(p==="$"){h();let{part:m,endIndex:y}=Xn(e,t,f);m&&c.push(m),f=y;continue}if(p==="`"){h();let{part:m,endIndex:y}=e.parseBacktickSubstitution(t,f);c.push(m),f=y;continue}if(p==="~"){let m=f>0?t[f-1]:"";if(f===0||m==="="||n&&m===":"){let b=Ji(e,t,f),v=t[b];if(v===void 0||v==="/"||v===":"){h();let E=t.slice(f+1,b)||null;c.push({type:"TildeExpansion",user:E}),f=b;continue}}}if("@*+?!".includes(p)&&f+1<t.length&&t[f+1]==="("){let m=tu(t,f+1);if(m!==-1){h();let y=t.slice(f,m+1);c.push({type:"Glob",pattern:y}),f=m+1;continue}}if(p==="*"||p==="?"||p==="["){h();let{pattern:m,endIndex:y}=ta(e,t,f);c.push({type:"Glob",pattern:m}),f=y;continue}if(p==="{"&&!n&&!l&&!i){let m=na(e,t,f,mt);if(m){h(),c.push(m.part),f=m.endIndex;continue}}d+=p,f++}return h(),c}var V=class e{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;parseDepth=0;_input="";getInput(){return this._input}checkIterationLimit(){if(this.parseIterations++,this.parseIterations>Ti)throw new we("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}enterDepth(){if(this.parseDepth++,this.parseDepth>On)throw new we(`Maximum parser nesting depth exceeded (${On})`,this.current().line,this.current().column);return()=>{this.parseDepth--}}parse(t,s){if(t.length>Rn)throw new we(`Input too large: ${t.length} bytes exceeds limit of ${Rn}`,1,1);this._input=t;let r=new $s(t,s);if(this.tokens=r.tokenize(),this.tokens.length>xn)throw new we(`Too many tokens: ${this.tokens.length} exceeds limit of ${xn}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}parseTokens(t){return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}check(t,s,r,n,...i){let a=this.tokens[this.pos]?.type;return a===t||s!==void 0&&a===s||r!==void 0&&a===r||n!==void 0&&a===n?!0:i.length>0?i.includes(a):!1}expect(t,s){if(this.check(t))return this.advance();let r=this.current();throw new we(s||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let s=this.current();throw new we(t,s.line,s.column,s)}skipNewlines(){for(;this.check(g.NEWLINE,g.COMMENT);)this.check(g.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(g.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(g.SEMICOLON,g.COMMENT)){this.advance();continue}if(t&&this.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,s,r,n){this.pendingHeredocs.push({redirect:t,delimiter:s,stripTabs:r,quoted:n})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(g.HEREDOC_CONTENT)){let s=this.advance(),r;t.quoted?r=x.word([x.literal(s.value)]):r=this.parseWordFromString(s.value,!1,!1,!1,!0),t.redirect.target=x.hereDoc(t.delimiter,r,t.stripTabs,t.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(g.EOF,g.NEWLINE,g.SEMICOLON,g.AMP,g.AND_AND,g.OR_OR,g.RPAREN,g.RBRACE,g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return t===g.WORD||t===g.NAME||t===g.NUMBER||t===g.ASSIGNMENT_WORD||t===g.IF||t===g.FOR||t===g.WHILE||t===g.UNTIL||t===g.CASE||t===g.LPAREN||t===g.LBRACE||t===g.DPAREN_START||t===g.DBRACK_START||t===g.FUNCTION||t===g.BANG||t===g.TIME||t===g.IN||t===g.LESS||t===g.GREAT||t===g.DLESS||t===g.DGREAT||t===g.LESSAND||t===g.GREATAND||t===g.LESSGREAT||t===g.DLESSDASH||t===g.CLOBBER||t===g.TLESS||t===g.AND_GREAT||t===g.AND_DGREAT}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(g.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)");let n=this.checkUnexpectedToken();if(n){t.push(n),this.skipSeparators(!1);continue}let i=this.pos,a=this.parseStatement();a&&t.push(a),this.skipSeparators(!1),this.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(g.EOF)&&this.advance()}return x.script(t)}checkUnexpectedToken(){let t=this.current().type,s=this.current().value;if((t===g.DO||t===g.DONE||t===g.THEN||t===g.ELSE||t===g.ELIF||t===g.FI||t===g.ESAC)&&this.error(`syntax error near unexpected token \`${s}'`),t===g.RBRACE||t===g.RPAREN){let r=`syntax error near unexpected token \`${s}'`;return this.advance(),x.statement([x.pipeline([x.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:s})}return(t===g.DSEMI||t===g.SEMI_AND||t===g.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${s}'`),t===g.SEMICOLON&&this.error(`syntax error near unexpected token \`${s}'`),(t===g.PIPE||t===g.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${s}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,s=[],r=[],n=!1,i=this.parsePipeline();for(s.push(i);this.check(g.AND_AND,g.OR_OR);){let o=this.advance();r.push(o.type===g.AND_AND?"&&":"||"),this.skipNewlines();let u=this.parsePipeline();s.push(u)}this.check(g.AMP)&&(this.advance(),n=!0);let a=this.pos>0?this.tokens[this.pos-1].end:t,l=this._input.slice(t,a);return x.statement(s,r,n,void 0,l)}parsePipeline(){let t=!1,s=!1;this.check(g.TIME)&&(this.advance(),t=!0,this.check(g.WORD,g.NAME)&&this.current().value==="-p"&&(this.advance(),s=!0));let r=0;for(;this.check(g.BANG);)this.advance(),r++;let n=r%2===1,i=[],a=[],l=this.parseCommand();for(i.push(l);this.check(g.PIPE,g.PIPE_AMP);){let o=this.advance();this.skipNewlines(),a.push(o.type===g.PIPE_AMP);let u=this.parseCommand();i.push(u)}return x.pipeline(i,n,t,s,a.length>0?a:void 0)}parseCommand(){return this.check(g.IF)?zn(this):this.check(g.FOR)?Bn(this):this.check(g.WHILE)?qn(this):this.check(g.UNTIL)?Un(this):this.check(g.CASE)?Zn(this):this.check(g.LPAREN)?Hn(this):this.check(g.LBRACE)?jn(this):this.check(g.DPAREN_START)?this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand():this.check(g.DBRACK_START)?this.parseConditionalCommand():this.check(g.FUNCTION)?this.parseFunctionDef():this.check(g.NAME,g.WORD)&&this.peek(1).type===g.LPAREN&&this.peek(2).type===g.RPAREN?this.parseFunctionDef():aa(this)}dparenClosesWithSpacedParens(){let t=1,s=1;for(;s<this.tokens.length-this.pos;){let r=this.peek(s);if(r.type===g.EOF)return!1;if(r.type===g.DPAREN_START||r.type===g.LPAREN)t++;else if(r.type===g.DPAREN_END){if(t-=2,t<=0)return!1}else if(r.type===g.RPAREN&&(t--,t===0&&this.peek(s+1).type===g.RPAREN))return!0;s++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(g.RPAREN),this.expect(g.RPAREN);let s=this.parseOptionalRedirections(),r=x.subshell(t,[]);return x.subshell([x.statement([x.pipeline([r],!1,!1,!1)])],s)}isWord(){let t=this.current().type;return t===g.WORD||t===g.NAME||t===g.NUMBER||t===g.IF||t===g.FOR||t===g.WHILE||t===g.UNTIL||t===g.CASE||t===g.FUNCTION||t===g.ELSE||t===g.ELIF||t===g.FI||t===g.THEN||t===g.DO||t===g.DONE||t===g.ESAC||t===g.IN||t===g.SELECT||t===g.TIME||t===g.COPROC||t===g.BANG}parseWord(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted)}parseWordNoBraceExpansion(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0)}parseWordForRegex(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0,!0)}parseWordFromString(t,s=!1,r=!1,n=!1,i=!1,a=!1,l=!1){let o=mt(this,t,s,r,n,i,!1,a,l);return x.word(o)}parseCommandSubstitution(t,s){return Di(t,s,()=>new e,r=>this.error(r))}parseBacktickSubstitution(t,s,r=!1){return Ii(t,s,r,()=>new e,n=>this.error(n))}isDollarDparenSubshell(t,s){return Pi(t,s)}parseArithmeticExpansion(t,s){let r=s+3,n=1,i=0,a=r;for(;a<t.length-1&&n>0;)t[a]==="$"&&t[a+1]==="("?t[a+2]==="("?(n++,a+=3):(i++,a+=2):t[a]==="("&&t[a+1]==="("?(n++,a+=2):t[a]===")"&&t[a+1]===")"?i>0?(i--,a++):(n--,n>0&&(a+=2)):t[a]==="("?(i++,a++):(t[a]===")"&&i>0&&i--,a++);let l=t.slice(r,a),o=this.parseArithmeticExpression(l);return{part:x.arithmeticExpansion(o),endIndex:a+2}}parseArithmeticCommand(){let t=this.expect(g.DPAREN_START),s="",r=1,n=0,i=!1,a=!1;for(;r>0&&!this.check(g.EOF);){if(i){if(i=!1,n>0){n--,s+=")";continue}if(this.check(g.RPAREN)){r--,a=!0,this.advance();continue}if(this.check(g.DPAREN_END)){r--,a=!0;continue}s+=")";continue}if(this.check(g.DPAREN_START))r++,s+="((",this.advance();else if(this.check(g.DPAREN_END))n>=2?(n-=2,s+="))",this.advance()):n===1?(n--,s+=")",i=!0,this.advance()):(r--,a=!0,r>0&&(s+="))"),this.advance());else if(this.check(g.LPAREN))n++,s+="(",this.advance();else if(this.check(g.RPAREN))n>0&&n--,s+=")",this.advance();else{let u=this.current().value,c=s.length>0?s[s.length-1]:"";s.length>0&&!s.endsWith(" ")&&!(u==="="&&/[|&^+\-*/%<>]$/.test(s))&&!(u==="<"&&c==="<")&&!(u===">"&&c===">")&&(s+=" "),s+=u,this.advance()}}a||this.expect(g.DPAREN_END);let l=this.parseArithmeticExpression(s.trim()),o=this.parseOptionalRedirections();return x.arithmeticCommand(l,o,t.line)}parseConditionalCommand(){let t=this.expect(g.DBRACK_START),s=Qn(this);this.expect(g.DBRACK_END);let r=this.parseOptionalRedirections();return x.conditionalCommand(s,r,t.line)}parseFunctionDef(){let t;if(this.check(g.FUNCTION)){if(this.advance(),this.check(g.NAME)||this.check(g.WORD))t=this.advance().value;else{let n=this.current();throw new we("Expected function name",n.line,n.column,n)}this.check(g.LPAREN)&&(this.advance(),this.expect(g.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(g.LPAREN),this.expect(g.RPAREN);this.skipNewlines();let s=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return x.functionDef(t,s,r)}parseCompoundCommandBody(t){let s=t?.forFunctionBody;if(this.check(g.LBRACE))return jn(this,{skipRedirections:s});if(this.check(g.LPAREN))return Hn(this,{skipRedirections:s});if(this.check(g.IF))return zn(this,{skipRedirections:s});if(this.check(g.FOR))return Bn(this,{skipRedirections:s});if(this.check(g.WHILE))return qn(this,{skipRedirections:s});if(this.check(g.UNTIL))return Un(this,{skipRedirections:s});if(this.check(g.CASE))return Zn(this,{skipRedirections:s});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth(),s=[];for(this.skipNewlines();!this.check(g.EOF,g.FI,g.ELSE,g.ELIF,g.THEN,g.DO,g.DONE,g.ESAC,g.RPAREN,g.RBRACE,g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,n=this.parseStatement();if(n&&s.push(n),this.skipSeparators(),this.pos===r&&!n)break}return t(),s}parseOptionalRedirections(){let t=[];for(;_s(this);){this.checkIterationLimit();let s=this.pos;if(t.push(Ps(this)),this.pos===s)break}return t}parseArithmeticExpression(t){return X(this,t)}};function Ue(e,t){return new V().parse(e,t)}var au="BASH_ALIAS_";function fa(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function da(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function ha(e,t){return e.env.get(`${au}${t}`)}function Yn(e,t,s){if(!t.name||!fa(t.name))return t;let r=da(t.name);if(!r)return t;let n=ha(e,r);if(!n||s.has(r))return t;try{s.add(r);let i=new V,a=n,l=n.endsWith(" ");if(!l)for(let f of t.args){let d=ma(f);a+=` ${d}`}let o;try{o=i.parse(a)}catch(f){if(f instanceof we)throw f;return t}if(o.statements.length!==1||o.statements[0].pipelines.length!==1||o.statements[0].pipelines[0].commands.length!==1)return pa(t,n);let u=o.statements[0].pipelines[0].commands[0];if(u.type!=="SimpleCommand")return pa(t,n);let c={...u,assignments:[...t.assignments,...u.assignments],redirections:[...u.redirections,...t.redirections],line:t.line};if(l&&t.args.length>0&&(c={...c,args:[...c.args,...t.args]},c.args.length>0)){let f=c.args[0];if(fa(f)){let d=da(f);if(d&&ha(e,d)){let h={type:"SimpleCommand",name:f,args:c.args.slice(1),assignments:[],redirections:[]},p=Yn(e,h,s);p!==h&&(c={...c,name:p.name,args:[...p.args]})}}}return c}catch(i){throw s.delete(r),i}}function pa(e,t){let s=t;for(let a of e.args){let l=ma(a);s+=` ${l}`}let r=new V,n=r.parseWordFromString("eval",!1,!1),i=r.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:n,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function ma(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(r=>r.type==="Literal"?r.value:`$${r.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}var ou=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function Jn(e){return ou.get(e)??""}function ga(e){let t=[],s="",r=0;for(;r<e.length;){let n=e[r];if(n==="["){for(s+=n,r++,r<e.length&&(e[r]==="!"||e[r]==="^")&&(s+=e[r],r++),r<e.length&&e[r]==="]"&&(s+=e[r],r++);r<e.length&&e[r]!=="]";){if(e[r]==="["&&r+1<e.length&&e[r+1]===":"){let i=e.indexOf(":]",r+2);if(i!==-1){s+=e.slice(r,i+2),r=i+2;continue}}if(e[r]==="\\"&&r+1<e.length){s+=e[r]+e[r+1],r+=2;continue}s+=e[r],r++}r<e.length&&e[r]==="]"&&(s+=e[r],r++)}else n===":"?(s!==""&&t.push(s),s="",r++):n==="\\"&&r+1<e.length?(s+=n+e[r+1],r+=2):(s+=n,r++)}return s!==""&&t.push(s),t}function ya(e){let t="^";for(let s=0;s<e.length;s++){let r=e[s];if(r==="*")t+="[^/]*";else if(r==="?")t+="[^/]";else if(r==="["){let n=s+1,i="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(i+="^",n++),n<e.length&&e[n]==="]"&&(i+="\\]",n++);let a=n;for(;a<e.length;){if(e[a]==="\\"&&a+1<e.length){a+=2;continue}if(e[a]==="["&&a+1<e.length&&e[a+1]===":"){let o=e.indexOf(":]",a+2);if(o!==-1){a=o+2;continue}}if(e[a]==="]")break;a++}let l=n;for(;n<e.length&&e[n]!=="]";){if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let o=e.indexOf(":]",n+2);if(o!==-1){let u=e.slice(n+2,o),c=Jn(u);i+=c,n=o+2;continue}}if(e[n]==="\\"&&n+1<e.length){i+=`\\${e[n+1]}`,n+=2;continue}if(e[n]==="-"){let o=n===l,u=n+1===a;o||u?i+="\\-":i+="-"}else i+=e[n];n++}i+="]",t+=i,s=n}else if(r==="\\"&&s+1<e.length){let n=e[s+1];/[.+^${}()|\\*?[\]]/.test(n)?t+=`\\${n}`:t+=n,s++}else/[.+^${}()|]/.test(r)?t+=`\\${r}`:t+=r}return t+="$",ae(t)}function er(e,t){let s=1,r=t+1;for(;r<e.length&&s>0;){let n=e[r];if(n==="\\"){r+=2;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function tr(e){let t=[],s="",r=0,n=!1,i=0;for(;i<e.length;){let a=e[i];if(a==="'"&&!n){n=!0,s+="\0QUOTE_START\0",i++;continue}if(a==="'"&&n){n=!1,s+="\0QUOTE_END\0",i++;continue}if(n){s+=a,i++;continue}if(a==="\\"){s+=a,i+1<e.length?(s+=e[i+1],i+=2):i++;continue}a==="("?(r++,s+=a):a===")"?(r--,s+=a):a==="|"&&r===0?(t.push(s),s=""):s+=a,i++}return t.push(s),t}var wa=5,gt=class{fs;cwd;globignorePatterns=[];hasGlobignore=!1;globstar=!1;nullglob=!1;failglob=!1;dotglob=!1;extglob=!1;globskipdots=!0;ops={count:0};maxOps;constructor(t,s,r,n){this.fs=t,this.cwd=s,typeof n=="boolean"?(this.globstar=n,this.maxOps=1e5):n?(this.globstar=n.globstar??!1,this.nullglob=n.nullglob??!1,this.failglob=n.failglob??!1,this.dotglob=n.dotglob??!1,this.extglob=n.extglob??!1,this.globskipdots=n.globskipdots??!0,this.maxOps=n.maxGlobOperations??1e5):this.maxOps=1e5;let i=r?.get("GLOBIGNORE");i!==void 0&&i!==""&&(this.hasGlobignore=!0,this.globignorePatterns=ga(i))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new Q(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations")}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(s=>{let r=s.split("/").pop()||s;if((this.hasGlobignore||this.globskipdots)&&(r==="."||r===".."))return!1;if(this.hasGlobignore){for(let n of this.globignorePatterns)if(this.matchGlobignorePattern(s,n))return!1}return!0})}matchGlobignorePattern(t,s){return ya(s).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,s){let r=t.map((a,l)=>(s?.[l]??!1)||!this.isGlobPattern(a)?null:this.expand(a)),n=await Promise.all(r.map(a=>a||Promise.resolve(null))),i=[];for(let a=0;a<t.length;a++){let l=n[a];l===null?i.push(t[a]):l.length>0?i.push(...l):i.push(t[a])}return i}async expand(t){if(this.globstar){let r=t.split("/"),n=0;for(let i of r)if(i==="**"&&(n++,n>wa))throw new Q(`Glob pattern has too many ** segments (max ${wa})`,"glob_operations")}let s;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))s=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");s=await this.expandSimple(r)}return this.filterGlobignore(s)}isGlobstarValid(t){let s=t.split("/");for(let r of s)if(r.includes("**")&&r!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let s=t.startsWith("/"),r=t.split("/").filter(u=>u!==""),n=-1;for(let u=0;u<r.length;u++)if(this.hasGlobChars(r[u])){n=u;break}if(n===-1)return[t];let i,a;if(n===0)s?(i="/",a="/"):(i=this.cwd,a="");else{let u=r.slice(0,n);s?(i=`/${u.join("/")}`,a=`/${u.join("/")}`):(i=this.fs.resolvePath(this.cwd,u.join("/")),a=u.join("/"))}let l=r.slice(n);return(await this.expandSegments(i,a,l)).sort()}async expandSegments(t,s,r){if(this.checkOpsLimit(),r.length===0)return[s];let[n,...i]=r,a=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let l=await this.fs.readdirWithFileTypes(t),o=[],u=[...l],c=this.dotglob||this.hasGlobignore;if(n.startsWith(".")||this.dotglob){let d=l.some(p=>p.name==="."),h=l.some(p=>p.name==="..");d||u.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),h||u.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of u)if(!(d.name.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(d.name,n)){let h=t==="/"?`/${d.name}`:`${t}/${d.name}`,p;s===""?p=d.name:s==="/"?p=`/${d.name}`:p=`${s}/${d.name}`,i.length===0?o.push(Promise.resolve([p])):d.isDirectory&&o.push(this.expandSegments(h,p,i))}let f=await Promise.all(o);for(let d of f)a.push(...d)}else{this.checkOpsLimit();let l=await this.fs.readdir(t),o=[],u=[...l],c=this.dotglob||this.hasGlobignore;(n.startsWith(".")||this.dotglob)&&(l.includes(".")||u.push("."),l.includes("..")||u.push(".."));for(let d of u)if(!(d.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(d,n)){let h=t==="/"?`/${d}`:`${t}/${d}`,p;s===""?p=d:s==="/"?p=`/${d}`:p=`${s}/${d}`,i.length===0?o.push(Promise.resolve([p])):o.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(h)).isDirectory)return this.expandSegments(h,p,i)}catch(m){if(m instanceof Q)throw m}return[]})())}let f=await Promise.all(o);for(let d of f)a.push(...d)}}catch(l){if(l instanceof Q)throw l}return a}async expandRecursive(t){let s=[],r=t.indexOf("**"),n=t.slice(0,r).replace(/\/$/,"")||".",a=t.slice(r+2).replace(/^\//,"");return a.includes("**")&&this.isGlobstarValid(a)?(await this.walkDirectoryMultiGlobstar(n,a,s),[...new Set(s)].sort()):(await this.walkDirectory(n,a,s),s.sort())}async walkDirectoryMultiGlobstar(t,s,r){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let i=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(n):null;if(i){let a=[];for(let u of i){let c=t==="."?u.name:`${t}/${u.name}`;u.isDirectory&&a.push(c)}let l=t==="."?s:`${t}/${s}`,o=await this.expandRecursive(l);r.push(...o);for(let u=0;u<a.length;u+=100){let c=a.slice(u,u+100);await Promise.all(c.map(f=>this.walkDirectoryMultiGlobstar(f,s,r)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(n),l=[];for(let c of a){let f=t==="."?c:`${t}/${c}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&l.push(f)}catch(h){if(h instanceof Q)throw h}}let o=t==="."?s:`${t}/${s}`,u=await this.expandRecursive(o);r.push(...u);for(let c=0;c<l.length;c+=100){let f=l.slice(c,c+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,s,r)))}}}catch(i){if(i instanceof Q)throw i}}async walkDirectory(t,s,r){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let i=await this.fs.readdirWithFileTypes(n),a=[],l=[];for(let o of i){let u=t==="."?o.name:`${t}/${o.name}`;o.isDirectory?l.push(u):s&&this.matchPattern(o.name,s)&&a.push(u)}r.push(...a);for(let o=0;o<l.length;o+=100){let u=l.slice(o,o+100);await Promise.all(u.map(c=>this.walkDirectory(c,s,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(n),a=[];for(let o=0;o<i.length;o+=100){let u=i.slice(o,o+100),c=await Promise.all(u.map(async f=>{let d=t==="."?f:`${t}/${f}`,h=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let p=await this.fs.stat(h);return{name:f,path:d,isDirectory:p.isDirectory}}catch(p){if(p instanceof Q)throw p;return null}}));a.push(...c.filter(f=>f!==null))}for(let o of a)!o.isDirectory&&s&&this.matchPattern(o.name,s)&&r.push(o.path);let l=a.filter(o=>o.isDirectory);for(let o=0;o<l.length;o+=100){let u=l.slice(o,o+100);await Promise.all(u.map(c=>this.walkDirectory(c.path,s,r)))}}}catch(i){if(i instanceof Q)throw i}}matchPattern(t,s){return this.patternToRegex(s).test(t)}patternToRegex(t){let s=this.patternToRegexStr(t);return ae(`^${s}$`)}patternToRegexStr(t){let s="",r=!1;for(let n=0;n<t.length;n++){if(t.slice(n,n+13)==="\0QUOTE_START\0"){r=!0,n+=12;continue}if(t.slice(n,n+11)==="\0QUOTE_END\0"){r=!1,n+=10;continue}let i=t[n];if(r){/[.+^${}()|\\*?[\]]/.test(i)?s+=`\\${i}`:s+=i;continue}if(this.extglob&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&n+1<t.length&&t[n+1]==="("){let a=er(t,n+1);if(a!==-1){let l=t.slice(n+2,a),o=tr(l),u=o.map(f=>this.patternToRegexStr(f)),c=u.length>0?u.join("|"):"(?:)";if(i==="@")s+=`(?:${c})`;else if(i==="*")s+=`(?:${c})*`;else if(i==="+")s+=`(?:${c})+`;else if(i==="?")s+=`(?:${c})?`;else if(i==="!")if(a<t.length-1){let d=o.map(p=>this.computePatternLength(p));if(d.every(p=>p!==null)&&d.every(p=>p===d[0])&&d[0]!==null){let p=d[0];if(p===0)s+="(?:.+)";else{let m=[];p>0&&m.push(`.{0,${p-1}}`),m.push(`.{${p+1},}`),m.push(`(?!(?:${c})).{${p}}`),s+=`(?:${m.join("|")})`}}else s+=`(?:(?!(?:${c})).)*?`}else s+=`(?!(?:${c})$).*`;n=a;continue}}if(i==="*")s+=".*";else if(i==="?")s+=".";else if(i==="["){let a=n+1,l="[";a<t.length&&(t[a]==="^"||t[a]==="!")&&(l+="^",a++),a<t.length&&t[a]==="]"&&(l+="\\]",a++);let o=a;for(;o<t.length;){if(t[o]==="\\"&&o+1<t.length){o+=2;continue}if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let c=t.indexOf(":]",o+2);if(c!==-1){o=c+2;continue}}if(t[o]==="]")break;o++}let u=a;for(;a<t.length&&t[a]!=="]";){if(t[a]==="["&&a+1<t.length&&t[a+1]===":"){let c=t.indexOf(":]",a+2);if(c!==-1){let f=t.slice(a+2,c),d=Jn(f);l+=d,a=c+2;continue}}if(t[a]==="\\"&&a+1<t.length){l+=`\\${t[a+1]}`,a+=2;continue}if(t[a]==="-"){let c=a===u,f=a+1===o;c||f?l+="\\-":l+="-"}else l+=t[a];a++}l+="]",s+=l,n=a}else if(i==="\\"&&n+1<t.length){let a=t[n+1];/[.+^${}()|\\*?[\]]/.test(a)?s+=`\\${a}`:s+=a,n++}else/[.+^${}()|]/.test(i)?s+=`\\${i}`:s+=i}return s}computePatternLength(t){let s=0,r=0,n=!1;for(;r<t.length;){if(t.slice(r,r+13)==="\0QUOTE_START\0"){n=!0,r+=13;continue}if(t.slice(r,r+11)==="\0QUOTE_END\0"){n=!1,r+=11;continue}let i=t[r];if(n){s+=1,r++;continue}if((i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&r+1<t.length&&t[r+1]==="("){let a=er(t,r+1);if(a!==-1){if(i==="@"){let l=t.slice(r+2,a),u=tr(l).map(c=>this.computePatternLength(c));if(u.every(c=>c!==null)&&u.every(c=>c===u[0])){s+=u[0],r=a+1;continue}return null}return null}}if(i==="*")return null;if(i==="?"){s+=1,r++;continue}if(i==="["){let a=t.indexOf("]",r+1);if(a!==-1){s+=1,r=a+1;continue}s+=1,r++;continue}if(i==="\\"){s+=1,r+=2;continue}s+=1,r++}return s}};function sr(e){for(let t=0;t<e.length;t++){if(e[t]==="\\"){t++;continue}if(e[t]==="$"){let s=e[t+1];if(s==="{"||s&&/[a-zA-Z_]/.test(s))return!0}}return!1}function lu(e){if(!e.operation)return!1;let t=e.operation,s;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(s=t.word?.parts),!s)return!1;for(let r of s)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function Ea(e){if(!e.operation)return!1;let t=e.operation,s;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(s=t.word?.parts),!s||s.length===0)return!1;for(let r of s)if(r.type!=="DoubleQuoted"&&r.type!=="SingleQuoted")return!1;return!0}function ns(e){let t=!1,s=!1,r=!1,n=!1,i=!1,a=!1,l=!1;for(let o of e){if((o.type==="SingleQuoted"||o.type==="DoubleQuoted")&&(t=!0,o.type==="DoubleQuoted"))for(let u of o.parts)u.type==="ParameterExpansion"&&(u.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!u.operation||u.operation.type==="PatternRemoval"||u.operation.type==="PatternReplacement")&&(n=!0),(u.operation?.type==="VarNamePrefix"||u.operation?.type==="ArrayKeys")&&(a=!0),u.operation?.type==="Indirection"&&(l=!0));o.type==="CommandSubstitution"&&(s=!0),o.type==="ParameterExpansion"&&(i=!0,(o.parameter==="@"||o.parameter==="*")&&(r=!0),lu(o)&&(t=!0),(o.operation?.type==="VarNamePrefix"||o.operation?.type==="ArrayKeys")&&(a=!0),o.operation?.type==="Indirection"&&(l=!0)),o.type==="Glob"&&sr(o.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:s,hasArrayVar:r,hasArrayAtExpansion:n,hasParamExpansion:i,hasVarNamePrefixExpansion:a,hasIndirection:l}}function fe(e,t){let s=`${t}_`,r=[];for(let n of e.state.env.keys())if(n.startsWith(s)){let i=n.slice(s.length),a=Number.parseInt(i,10);!Number.isNaN(a)&&String(a)===i&&r.push(a)}return r.sort((n,i)=>n-i)}function Xe(e,t){let s=`${t}_`;for(let r of e.state.env.keys())r.startsWith(s)&&e.state.env.delete(r)}function Ze(e,t){let s=`${t}_`,r=`${t}__length`,n=[];for(let i of e.state.env.keys())if(i!==r&&i.startsWith(s)){let a=i.slice(s.length);if(a.startsWith("_length"))continue;n.push(a)}return n.sort()}function Ds(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function nr(e){if(e.parts.length<2)return null;let t=e.parts[0],s=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let r,n=s,i=1;if(s.type==="Literal"&&s.value.startsWith("]")){let f=s.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))r=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let d=e.parts[2];if(d.type!=="Literal"||!d.value.startsWith("=")&&!d.value.startsWith("+="))return null;r=t.pattern.slice(1),n=d,i=2}else return null}else if(t.pattern==="["&&(s.type==="DoubleQuoted"||s.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(s.type==="SingleQuoted")r=s.value;else{r="";for(let d of s.parts)(d.type==="Literal"||d.type==="Escaped")&&(r+=d.value)}n=f,i=2}else if(t.pattern.endsWith("]")){if(s.type!=="Literal"||!s.value.startsWith("=")&&!s.value.startsWith("+="))return null;r=t.pattern.slice(1,-1)}else return null;r=Ds(r);let a;if(n.type!=="Literal")return null;n.value.startsWith("]=")||n.value.startsWith("]+=")?a=n.value.slice(1):a=n.value;let l=a.startsWith("+=");if(!l&&!a.startsWith("="))return null;let o=[],u=l?2:1,c=a.slice(u);c&&o.push({type:"Literal",value:c});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?o.push({type:"Literal",value:cu(d)}):o.push(d)}return{key:r,valueParts:o,append:l}}function cu(e){return`{${e.items.map(s=>{if(s.type==="Range"){let r=s.startStr??String(s.start),n=s.endStr??String(s.end),i=`${r}..${n}`;return s.step&&(i+=`..${s.step}`),i}return Ft(s.word)}).join(",")}}`}function Ft(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value;break;case"Glob":t+=s.pattern;break;case"SingleQuoted":t+=s.value;break;case"DoubleQuoted":for(let r of s.parts)(r.type==="Literal"||r.type==="Escaped")&&(t+=r.value);break;case"Escaped":t+=s.value;break;case"BraceExpansion":t+="{",t+=s.items.map(r=>r.type==="Range"?`${r.startStr}..${r.endStr}${r.step?`..${r.step}`:""}`:Ft(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",s.user&&(t+=s.user);break}return t}function he(e){return e.get("IFS")??`
63
+ `}function Ee(e){return e.get("IFS")===""}function Is(e){let t=he(e);if(t==="")return!0;for(let s of t)if(s!==" "&&s!==" "&&s!==`
64
+ `)return!1;return!0}function ba(e){let t=!1,s=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?s.push(`\\${r}`):r===" "?s.push("\\t"):r===`
65
+ `?s.push("\\n"):s.push(r);return t&&s.push("\\-"),s.join("")}function z(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var uu=`
66
+ `;function fu(e){return uu.includes(e)}function rr(e){let t=new Set,s=new Set;for(let r of e)fu(r)?t.add(r):s.add(r);return{whitespace:t,nonWhitespace:s}}function ir(e,t,s,r){if(t==="")return e===""?{words:[],wordStarts:[]}:{words:[e],wordStarts:[0]};let{whitespace:n,nonWhitespace:i}=rr(t),a=[],l=[],o=0;for(;o<e.length&&n.has(e[o]);)o++;if(o>=e.length)return{words:[],wordStarts:[]};if(i.has(e[o]))for(a.push(""),l.push(o),o++;o<e.length&&n.has(e[o]);)o++;for(;o<e.length&&!(s!==void 0&&a.length>=s);){let u=o;for(l.push(u);o<e.length;){let c=e[o];if(!r&&c==="\\"){o++,o<e.length&&o++;continue}if(n.has(c)||i.has(c))break;o++}if(a.push(e.substring(u,o)),o>=e.length)break;for(;o<e.length&&n.has(e[o]);)o++;if(o<e.length&&i.has(e[o])){for(o++;o<e.length&&n.has(e[o]);)o++;for(;o<e.length&&i.has(e[o])&&!(s!==void 0&&a.length>=s);)for(a.push(""),l.push(o),o++;o<e.length&&n.has(e[o]);)o++}}return{words:a,wordStarts:l}}function Cs(e,t){if(t==="")return{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:s,nonWhitespace:r}=rr(t),n=[],i=0,a=!1,l=!1,o=i;for(;i<e.length&&s.has(e[i]);)i++;if(i>o&&(a=!0),i>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(r.has(e[i]))for(n.push(""),i++;i<e.length&&s.has(e[i]);)i++;for(;i<e.length;){let u=i;for(;i<e.length;){let f=e[i];if(s.has(f)||r.has(f))break;i++}if(n.push(e.substring(u,i)),i>=e.length){l=!1;break}let c=i;for(;i<e.length&&s.has(e[i]);)i++;if(i<e.length&&r.has(e[i])){for(i++;i<e.length&&s.has(e[i]);)i++;for(;i<e.length&&r.has(e[i]);)for(n.push(""),i++;i<e.length&&s.has(e[i]);)i++}i>=e.length&&i>c&&(l=!0)}return{words:n,hadLeadingDelimiter:a,hadTrailingDelimiter:l}}function se(e,t){return Cs(e,t).words}function du(e,t){for(let s of e)if(t.has(s))return!0;return!1}function va(e,t,s){if(t==="")return e;let{whitespace:r,nonWhitespace:n}=rr(t),i=e.length;for(;i>0&&r.has(e[i-1]);){if(!s&&i>=2){let l=0,o=i-2;for(;o>=0&&e[o]==="\\";)l++,o--;if(l%2===1)break}i--}let a=e.substring(0,i);if(a.length>=1&&n.has(a[a.length-1])){if(!s&&a.length>=2){let o=0,u=a.length-2;for(;u>=0&&a[u]==="\\";)o++,u--;if(o%2===1)return a}let l=a.substring(0,a.length-1);if(!du(l,n))return l}return a}function ee(e,t){return e.state.namerefs?.has(t)??!1}function lt(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function Sa(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Aa(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function $a(e,t){return e.state.invalidNamerefs?.has(t)??!1}function ar(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function Rs(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],i=Array.from(e.state.env.keys()).some(l=>l.startsWith(`${n}_`)&&!l.includes("__")),a=e.state.associativeArrays?.has(n)??!1;return i||a}return Array.from(e.state.env.keys()).some(n=>n.startsWith(`${t}_`)&&!n.includes("__"))?!0:e.state.env.has(t)}function Se(e,t,s=100){if(!ee(e,t)||$a(e,t))return t;let r=new Set,n=t;for(;s-- >0;){if(r.has(n))return;if(r.add(n),!ee(e,n))return n;let i=e.state.env.get(n);if(i===void 0||i===""||!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(i))return n;n=i}}function kt(e,t){if(ee(e,t))return e.state.env.get(t)}function Na(e,t,s,r=100){if(!ee(e,t)||$a(e,t))return t;let n=new Set,i=t;for(;r-- >0;){if(n.has(i))return;if(n.add(i),!ee(e,i))return i;let a=e.state.env.get(i);if(a===void 0||a==="")return s!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&Rs(e,s)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(a))return i;i=a}}function hu(e,t){let s=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(r,n)=>e.state.env.get(n)??"");return s=s.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(r,n)=>e.state.env.get(n)??""),s}function F(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((i,a)=>[a,i]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((i,a)=>[a,String(i)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((i,a)=>[a,i]):e.state.associativeArrays?.has(t)?Ze(e,t).map(i=>[i,e.state.env.get(`${t}_${i}`)??""]):fe(e,t).map(n=>[n,e.state.env.get(`${t}_${n}`)??""])}function He(e,t){return t==="FUNCNAME"?(e.state.funcNameStack?.length??0)>0:t==="BASH_LINENO"?(e.state.callLineStack?.length??0)>0:t==="BASH_SOURCE"?(e.state.sourceStack?.length??0)>0:e.state.associativeArrays?.has(t)?Ze(e,t).length>0:fe(e,t).length>0}async function Y(e,t,s=!0,r=!1){switch(t){case"?":return String(e.state.lastExitCode);case"$":return String(e.state.virtualPid);case"#":return e.state.env.get("#")||"0";case"@":return e.state.env.get("@")||"";case"_":return e.state.lastArg;case"-":{let a="";return a+="h",e.state.options.errexit&&(a+="e"),e.state.options.noglob&&(a+="f"),e.state.options.nounset&&(a+="u"),e.state.options.verbose&&(a+="v"),e.state.options.xtrace&&(a+="x"),a+="B",e.state.options.noclobber&&(a+="C"),a+="s",a}case"*":{let a=Number.parseInt(e.state.env.get("#")||"0",10);if(a===0)return"";let l=[];for(let o=1;o<=a;o++)l.push(e.state.env.get(String(o))||"");return l.join(z(e.state.env))}case"0":return e.state.env.get("0")||"bash";case"PWD":return e.state.env.get("PWD")??"";case"OLDPWD":return e.state.env.get("OLDPWD")??"";case"PPID":return String(e.state.virtualPpid);case"UID":return String(e.state.virtualUid);case"EUID":return String(e.state.virtualUid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-e.state.startTime)/1e3));case"BASH_VERSION":return Ni;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let a=e.state.funcNameStack?.[0];if(a!==void 0)return a;if(s&&e.state.options.nounset)throw new Re("FUNCNAME");return""}case"BASH_LINENO":{let a=e.state.callLineStack?.[0];if(a!==void 0)return String(a);if(s&&e.state.options.nounset)throw new Re("BASH_LINENO");return""}case"BASH_SOURCE":{let a=e.state.sourceStack?.[0];if(a!==void 0)return a;if(s&&e.state.options.nounset)throw new Re("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new xe(`\${${t}}`);let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let a=n[1],l=n[2];if(ee(e,a)){let f=Se(e,a);if(f&&f!==a){if(f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";a=f}}if(l==="@"||l==="*"){let f=F(e,a);if(f.length>0)return f.map(([,h])=>h).join(" ");let d=e.state.env.get(a);return d!==void 0?d:""}if(a==="FUNCNAME"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.funcNameStack?.[f]??"":""}if(a==="BASH_LINENO"){let f=Number.parseInt(l,10);if(!Number.isNaN(f)&&f>=0){let d=e.state.callLineStack?.[f];return d!==void 0?String(d):""}return""}if(a==="BASH_SOURCE"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.sourceStack?.[f]??"":""}if(e.state.associativeArrays?.has(a)){let f=Ds(l);f=hu(e,f);let d=e.state.env.get(`${a}_${f}`);if(d===void 0&&s&&e.state.options.nounset)throw new Re(`${a}[${l}]`);return d||""}let u;if(/^-?\d+$/.test(l))u=Number.parseInt(l,10);else try{let f=new V,d=X(f,l);u=await T(e,d.expression)}catch{let f=e.state.env.get(l);u=f?Number.parseInt(f,10):0,Number.isNaN(u)&&(u=0)}if(u<0){let f=F(e,a),d=e.state.currentLine;if(f.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${a}: bad array subscript
67
+ `,"";let p=Math.max(...f.map(([y])=>typeof y=="number"?y:0))+1+u;return p<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${d}: ${a}: bad array subscript
68
+ `,""):e.state.env.get(`${a}_${p}`)||""}let c=e.state.env.get(`${a}_${u}`);if(c!==void 0)return c;if(u===0){let f=e.state.env.get(a);if(f!==void 0)return f}if(s&&e.state.options.nounset)throw new Re(`${a}[${u}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let a=e.state.env.get(t);if(a===void 0&&s&&e.state.options.nounset)throw new Re(t);return a||""}if(ee(e,t)){let a=Se(e,t);if(a===void 0)return"";if(a!==t)return await Y(e,a,s,r);let l=e.state.env.get(t);if((l===void 0||l==="")&&s&&e.state.options.nounset)throw new Re(t);return l||""}let i=e.state.env.get(t);if(i!==void 0)return e.state.tempEnvBindings?.some(a=>a.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),i;if(He(e,t)){let a=e.state.env.get(`${t}_0`);return a!==void 0?a:""}if(s&&e.state.options.nounset)throw new Re(t);return""}async function Ye(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let n=r[1],i=r[2];if(ee(e,n)){let o=Se(e,n);if(o&&o!==n){if(o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;n=o}}if(i==="@"||i==="*")return F(e,n).length>0?!0:e.state.env.has(n);if(e.state.associativeArrays?.has(n)){let o=Ds(i);return e.state.env.has(`${n}_${o}`)}let l;if(/^-?\d+$/.test(i))l=Number.parseInt(i,10);else try{let o=new V,u=X(o,i);l=await T(e,u.expression)}catch{let o=e.state.env.get(i);l=o?Number.parseInt(o,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let o=F(e,n);if(o.length===0)return!1;let c=Math.max(...o.map(([f])=>typeof f=="number"?f:0))+1+l;return c<0?!1:e.state.env.has(`${n}_${c}`)}return e.state.env.has(`${n}_${l}`)}if(ee(e,t)){let n=Se(e,t);return n===void 0||n===t?e.state.env.has(t):Ye(e,n)}return!!(e.state.env.has(t)||He(e,t))}async function ka(e,t){let s="",r=0;for(;r<t.length;){if(t[r]==="$"){if(t[r+1]==="{"){let n=1,i=r+2;for(;i<t.length&&n>0;)t[i]==="{"?n++:t[i]==="}"&&n--,i++;s+=t.slice(r,i),r=i;continue}if(t[r+1]==="("){let n=1,i=r+2;for(;i<t.length&&n>0;)t[i]==="("?n++:t[i]===")"&&n--,i++;s+=t.slice(r,i),r=i;continue}if(/[a-zA-Z_]/.test(t[r+1]||"")){let n=r+1;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)n++;let i=t.slice(r+1,n),a=await Y(e,i);s+=a,r=n;continue}if(/[0-9]/.test(t[r+1]||"")){let n=r+1;for(;n<t.length&&/[0-9]/.test(t[n]);)n++;let i=t.slice(r+1,n),a=await Y(e,i);s+=a,r=n;continue}if(/[*@#?\-!$]/.test(t[r+1]||"")){let n=t[r+1],i=await Y(e,n);s+=i,r+=2;continue}}if(t[r]==='"'){for(s+='"',r++;r<t.length&&t[r]!=='"';)if(t[r]==="$"&&/[a-zA-Z_]/.test(t[r+1]||"")){let n=r+1;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)n++;let i=t.slice(r+1,n),a=await Y(e,i);s+=a,r=n}else t[r]==="\\"?(s+=t[r],r++,r<t.length&&(s+=t[r],r++)):(s+=t[r],r++);r<t.length&&(s+='"',r++);continue}s+=t[r],r++}return s}async function or(e,t){let s=t,r=t.startsWith('"')&&t.endsWith('"'),n=t.startsWith("'")&&t.endsWith("'");if((r||n)&&(s=t.slice(1,-1)),n)return s;let i="",a=0;for(;a<s.length;)if(s[a]==="$")if(s[a+1]==="("){let l=1,o=a+2;for(;o<s.length&&l>0;)s[o]==="("&&s[o-1]==="$"||s[o]==="("?l++:s[o]===")"&&l--,o++;let u=s.slice(a+2,o-1);if(e.execFn){let c=await e.execFn(u,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}a=o}else if(s[a+1]==="{"){let l=1,o=a+2;for(;o<s.length&&l>0;)s[o]==="{"?l++:s[o]==="}"&&l--,o++;let u=s.slice(a+2,o-1),c=await Y(e,u);i+=c,a=o}else if(/[a-zA-Z_]/.test(s[a+1]||"")){let l=a+1;for(;l<s.length&&/[a-zA-Z0-9_]/.test(s[l]);)l++;let o=s.slice(a+1,l),u=await Y(e,o);i+=u,a=l}else i+=s[a],a++;else if(s[a]==="`"){let l=a+1;for(;l<s.length&&s[l]!=="`";)l++;let o=s.slice(a+1,l);if(e.execFn){let u=await e.execFn(o,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}a=l+1}else i+=s[a],a++;return i}var xs=1e4;function pu(e,t,s,r,n){let i=s??1;i===0&&(i=1);let a=Math.abs(i),l=[],o=0;r?.match(/^-?0\d/)&&(o=Math.max(o,r.replace(/^-/,"").length)),n?.match(/^-?0\d/)&&(o=Math.max(o,n.replace(/^-/,"").length));let u=c=>{if(o>0){let f=c<0,d=String(Math.abs(c)).padStart(o,"0");return f?`-${d}`:d}return String(c)};if(e<=t)for(let c=e,f=0;c<=t&&f<xs;c+=a,f++)l.push(u(c));else for(let c=e,f=0;c>=t&&f<xs;c-=a,f++)l.push(u(c));return l}function mu(e,t,s){let r=s??1;r===0&&(r=1);let n=e.charCodeAt(0),i=t.charCodeAt(0),a=Math.abs(r),l=e>="A"&&e<="Z",o=e>="a"&&e<="z",u=t>="A"&&t<="Z",c=t>="a"&&t<="z";if(l&&c||o&&u){let d=s!==void 0?`..${s}`:"";throw new ws(`{${e}..${t}${d}}: invalid sequence`)}let f=[];if(n<=i)for(let d=n,h=0;d<=i&&h<xs;d+=a,h++)f.push(String.fromCharCode(d));else for(let d=n,h=0;d>=i&&h<xs;d-=a,h++)f.push(String.fromCharCode(d));return f}function lr(e,t,s,r,n){let i=s!==void 0?`..${s}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:pu(e,t,s,r,n),literal:`{${e}..${t}${i}}`}:typeof e=="string"&&typeof t=="string"?{expanded:mu(e,t,s),literal:`{${e}..${t}${i}}`}:{expanded:null,literal:`{${e}..${t}${i}}`}}function _a(e){if(e.statements.length!==1)return null;let t=e.statements[0];if(t.operators.length!==0||t.pipelines.length!==1)return null;let s=t.pipelines[0];if(s.negated||s.commands.length!==1)return null;let r=s.commands[0];if(r.type!=="SimpleCommand")return null;let n=r;if(n.name!==null||n.args.length!==0||n.assignments.length!==0||n.redirections.length!==1)return null;let i=n.redirections[0];return i.operator!=="<"||i.target.type!=="Word"?null:{target:i.target}}function Je(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function cr(e){let t="",s=0;for(;s<e.length;)e[s]==="\\"&&s+1<e.length?(t+=e[s+1],s+=2):(t+=e[s],s++);return t}function Te(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function rs(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function j(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Z(e,t,s=!1){let r="",n=0;for(;n<e.length;){let i=e[n];if(s&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&n+1<e.length&&e[n+1]==="("){let a=gu(e,n+1);if(a!==-1){let l=e.slice(n+2,a),u=yu(l).map(f=>Z(f,t,s)),c=u.length>0?u.join("|"):"(?:)";i==="@"?r+=`(?:${c})`:i==="*"?r+=`(?:${c})*`:i==="+"?r+=`(?:${c})+`:i==="?"?r+=`(?:${c})?`:i==="!"&&(r+=`(?!(?:${c})$).*`),n=a+1;continue}}if(i==="\\")if(n+1<e.length){let a=e[n+1];/[\\^$.|+(){}[\]*?]/.test(a)?r+=`\\${a}`:r+=a,n+=2}else r+="\\\\",n++;else if(i==="*")r+=t?".*":".*?",n++;else if(i==="?")r+=".",n++;else if(i==="["){let a=wu(e,n);if(a===-1)r+="\\[",n++;else{let l=e.slice(n+1,a);r+=Eu(l),n=a+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,n++):(r+=i,n++)}return r}function gu(e,t){let s=1,r=t+1;for(;r<e.length&&s>0;){let n=e[r];if(n==="\\"){r+=2;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function yu(e){let t=[],s="",r=0,n=0;for(;n<e.length;){let i=e[n];if(i==="\\"){s+=i,n+1<e.length?(s+=e[n+1],n+=2):n++;continue}i==="("?(r++,s+=i):i===")"?(r--,s+=i):i==="|"&&r===0?(t.push(s),s=""):s+=i,n++}return t.push(s),t}function wu(e,t){let s=t+1;for(s<e.length&&e[s]==="^"&&s++,s<e.length&&e[s]==="]"&&s++;s<e.length;){if(e[s]==="\\"&&s+1<e.length){s+=2;continue}if(e[s]==="]")return s;if(e[s]==="'"){let r=e.indexOf("'",s+1);if(r!==-1){s=r+1;continue}}if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let r=e.indexOf(":]",s+2);if(r!==-1){s=r+2;continue}}s++}return-1}function Eu(e){let t="[",s=0;for((e[0]==="^"||e[0]==="!")&&(t+="^",s++);s<e.length;){if(e[s]==="'"){let n=e.indexOf("'",s+1);if(n!==-1){let i=e.slice(s+1,n);for(let a of i)a==="\\"?t+="\\\\":a==="]"?t+="\\]":a==="^"&&t==="["?t+="\\^":t+=a;s=n+1;continue}}if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let n=e.indexOf(":]",s+2);if(n!==-1){let i=e.slice(s+2,n);t+=vu(i),s=n+2;continue}}let r=e[s];r==="\\"?s+1<e.length?(t+=`\\${e[s+1]}`,s+=2):(t+="\\\\",s++):r==="-"&&s>0&&s<e.length-1?(t+="-",s++):r==="^"&&s===0?(t+="^",s++):(r==="]"&&s===0?t+="\\]":t+=r,s++)}return t+="]",t}var bu=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]);function vu(e){return bu.get(e)??""}function ct(e,t,s,r){if(s==="prefix")return ae(`^${t}`,"s").replace(e,"");let n=ae(`${t}$`,"s");if(r)return n.replace(e,"");for(let i=e.length;i>=0;i--){let a=e.slice(i);if(n.test(a))return e.slice(0,i)}return e}function Vt(e,t){let s=Array.from(e.state.env.keys()),r=new Set,n=e.state.associativeArrays??new Set,i=new Set;for(let l of s){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o&&i.add(o[1]);let u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);u&&i.add(u[1])}let a=l=>{for(let o of n){let u=`${o}_`;if(l.startsWith(u)&&l!==o)return!0}return!1};for(let l of s)if(l.startsWith(t))if(l.includes("__")){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);o?.[1].startsWith(t)&&r.add(o[1])}else if(/_\d+$/.test(l)){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o?.[1].startsWith(t)&&r.add(o[1])}else a(l)||r.add(l);return[...r].sort()}function Su(e,t){let s=(i,a=2)=>String(i).padStart(a,"0");if(e===""){let i=s(t.getHours()),a=s(t.getMinutes()),l=s(t.getSeconds());return`${i}:${a}:${l}`}let r="",n=0;for(;n<e.length;)if(e[n]==="%"){if(n+1>=e.length){r+="%",n++;continue}let i=e[n+1];switch(i){case"H":r+=s(t.getHours());break;case"M":r+=s(t.getMinutes());break;case"S":r+=s(t.getSeconds());break;case"d":r+=s(t.getDate());break;case"m":r+=s(t.getMonth()+1);break;case"Y":r+=t.getFullYear();break;case"y":r+=s(t.getFullYear()%100);break;case"I":{let a=t.getHours()%12;a===0&&(a=12),r+=s(a);break}case"p":r+=t.getHours()<12?"AM":"PM";break;case"P":r+=t.getHours()<12?"am":"pm";break;case"%":r+="%";break;case"a":{r+=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][t.getDay()];break}case"b":{r+=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()];break}default:r+=`%${i}`}n+=2}else r+=e[n],n++;return r}function is(e,t){let s="",r=0,n=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",i=e.state.env.get("HOSTNAME")||"localhost",a=i.split(".")[0],l=e.state.env.get("PWD")||"/",o=e.state.env.get("HOME")||"/",u=l.startsWith(o)?`~${l.slice(o.length)}`:l,c=l.split("/").pop()||l,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],p=e.state.env.get("__COMMAND_NUMBER")||"1";for(;r<t.length;){let m=t[r];if(m==="\\"){if(r+1>=t.length){s+="\\",r++;continue}let y=t[r+1];if(y>="0"&&y<="7"){let b="",v=r+1;for(;v<t.length&&v<r+4&&t[v]>="0"&&t[v]<="7";)b+=t[v],v++;let E=Number.parseInt(b,8)%256;s+=String.fromCharCode(E),r=v;continue}switch(y){case"\\":s+="\\",r+=2;break;case"a":s+="\x07",r+=2;break;case"e":s+="\x1B",r+=2;break;case"n":s+=`
69
+ `,r+=2;break;case"r":s+="\r",r+=2;break;case"$":s+="$",r+=2;break;case"[":case"]":r+=2;break;case"u":s+=n,r+=2;break;case"h":s+=a,r+=2;break;case"H":s+=i,r+=2;break;case"w":s+=u,r+=2;break;case"W":s+=c,r+=2;break;case"d":{let b=String(f.getDate()).padStart(2," ");s+=`${d[f.getDay()]} ${h[f.getMonth()]} ${b}`,r+=2;break}case"t":{let b=String(f.getHours()).padStart(2,"0"),v=String(f.getMinutes()).padStart(2,"0"),E=String(f.getSeconds()).padStart(2,"0");s+=`${b}:${v}:${E}`,r+=2;break}case"T":{let b=f.getHours()%12;b===0&&(b=12);let v=String(b).padStart(2,"0"),E=String(f.getMinutes()).padStart(2,"0"),w=String(f.getSeconds()).padStart(2,"0");s+=`${v}:${E}:${w}`,r+=2;break}case"@":{let b=f.getHours()%12;b===0&&(b=12);let v=String(b).padStart(2,"0"),E=String(f.getMinutes()).padStart(2,"0"),w=f.getHours()<12?"AM":"PM";s+=`${v}:${E} ${w}`,r+=2;break}case"A":{let b=String(f.getHours()).padStart(2,"0"),v=String(f.getMinutes()).padStart(2,"0");s+=`${b}:${v}`,r+=2;break}case"D":if(r+2<t.length&&t[r+2]==="{"){let b=t.indexOf("}",r+3);if(b!==-1){let v=t.slice(r+3,b);s+=Su(v,f),r=b+1}else s+="\\D",r+=2}else s+="\\D",r+=2;break;case"s":s+="bash",r+=2;break;case"v":s+="5.0",r+=2;break;case"V":s+="5.0.0",r+=2;break;case"j":s+="0",r+=2;break;case"l":s+="tty",r+=2;break;case"#":s+=p,r+=2;break;case"!":s+=p,r+=2;break;case"x":s+="\\x",r+=2;break;default:s+=`\\${y}`,r+=2}}else s+=m,r++}return s}function yt(e){if(e==="")return"''";if(/[\n\r\t\x00-\x1f\x7f']/.test(e)){let s="$'";for(let r of e)switch(r){case"'":s+="\\'";break;case"\\":s+="\\\\";break;case`
70
+ `:s+="\\n";break;case"\r":s+="\\r";break;case" ":s+="\\t";break;default:{let n=r.charCodeAt(0);n<32||n===127?s+=`\\${n.toString(8).padStart(3,"0")}`:s+=r}}return`${s}'`}return`'${e}'`}function Pe(e,t){e.state.readonlyVars=e.state.readonlyVars||new Set,e.state.readonlyVars.add(t)}function et(e,t){return e.state.readonlyVars?.has(t)??!1}function me(e,t,s="bash"){if(et(e,t)){let r=`${s}: ${t}: readonly variable
71
+ `;throw new U(1,"",r)}return null}function je(e,t){let s=e.state.exportedVars?.has(t)??!1;if(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(t),e.state.localScopes.length>0&&e.state.localScopes[e.state.localScopes.length-1].has(t)&&!s){for(e.state.localExportedVars||(e.state.localExportedVars=[]);e.state.localExportedVars.length<e.state.localScopes.length;)e.state.localExportedVars.push(new Set);e.state.localExportedVars[e.state.localExportedVars.length-1].add(t)}}function Os(e,t){e.state.exportedVars?.delete(t)}function wt(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let s="",r=e.state.env.has(`${t}__length`)||Array.from(e.state.env.keys()).some(i=>i.startsWith(`${t}_`)&&/^[0-9]+$/.test(i.slice(t.length+1))),n=e.state.associativeArrays?.has(t)??!1;return r&&!n&&(s+="a"),n&&(s+="A"),e.state.integerVars?.has(t)&&(s+="i"),ee(e,t)&&(s+="n"),et(e,t)&&(s+="r"),e.state.exportedVars?.has(t)&&(s+="x"),s}async function Pa(e,t,s,r){return e.coverage?.hit("bash:expansion:default_value"),(s.isUnset||t.checkEmpty&&s.isEmpty)&&t.word?r(e,t.word.parts,s.inDoubleQuotes):s.effectiveValue}async function Da(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:assign_default"),(r.isUnset||s.checkEmpty&&r.isEmpty)&&s.word){let a=await n(e,s.word.parts,r.inDoubleQuotes),l=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let[,o,u]=l,c;if(/^\d+$/.test(u))c=Number.parseInt(u,10);else{try{let d=new V,h=X(d,u);c=await T(e,h.expression)}catch{let d=e.state.env.get(u);c=d?Number.parseInt(d,10):0}Number.isNaN(c)&&(c=0)}e.state.env.set(`${o}_${c}`,a);let f=Number.parseInt(e.state.env.get(`${o}__length`)||"0",10);c>=f&&e.state.env.set(`${o}__length`,String(c+1))}else e.state.env.set(t,a);return a}return r.effectiveValue}async function Ia(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:error_if_unset"),r.isUnset||s.checkEmpty&&r.isEmpty){let a=s.word?await n(e,s.word.parts,r.inDoubleQuotes):`${t}: parameter null or not set`;throw new U(1,"",`bash: ${a}
72
+ `)}return r.effectiveValue}async function Ca(e,t,s,r){return e.coverage?.hit("bash:expansion:use_alternative"),!(s.isUnset||t.checkEmpty&&s.isEmpty)&&t.word?r(e,t.word.parts,s.inDoubleQuotes):""}async function Ra(e,t,s,r,n){e.coverage?.hit("bash:expansion:pattern_removal");let i="",a=e.state.shoptOptions.extglob;if(s.pattern)for(let o of s.pattern.parts)if(o.type==="Glob")i+=Z(o.pattern,s.greedy,a);else if(o.type==="Literal")i+=Z(o.value,s.greedy,a);else if(o.type==="SingleQuoted"||o.type==="Escaped")i+=j(o.value);else if(o.type==="DoubleQuoted"){let u=await r(e,o.parts);i+=j(u)}else if(o.type==="ParameterExpansion"){let u=await n(e,o);i+=Z(u,s.greedy,a)}else{let u=await n(e,o);i+=j(u)}if(s.side==="prefix")return ae(`^${i}`,"s").replace(t,"");let l=ae(`${i}$`,"s");if(s.greedy)return l.replace(t,"");for(let o=t.length;o>=0;o--){let u=t.slice(o);if(l.test(u))return t.slice(0,o)}return t}async function xa(e,t,s,r,n){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",a=e.state.shoptOptions.extglob;if(s.pattern)for(let u of s.pattern.parts)if(u.type==="Glob")i+=Z(u.pattern,!0,a);else if(u.type==="Literal")i+=Z(u.value,!0,a);else if(u.type==="SingleQuoted"||u.type==="Escaped")i+=j(u.value);else if(u.type==="DoubleQuoted"){let c=await r(e,u.parts);i+=j(c)}else if(u.type==="ParameterExpansion"){let c=await n(e,u);i+=Z(c,!0,a)}else{let c=await n(e,u);i+=j(c)}let l=s.replacement?await r(e,s.replacement.parts):"";if(s.anchor==="start"?i=`^${i}`:s.anchor==="end"&&(i=`${i}$`),i==="")return t;let o=s.all?"gs":"s";try{let u=ae(i,o);if(s.all){let c="",f=0,d=0,h=e.limits.maxStringLength,p=u.exec(t);for(;p!==null&&!(p[0].length===0&&p.index===t.length);){if(c+=t.slice(f,p.index)+l,f=p.index+p[0].length,p[0].length===0&&f++,d++,d%100===0&&c.length>h)throw new Q(`pattern replacement: string length limit exceeded (${h} bytes)`,"string_length");p=u.exec(t)}return c+=t.slice(f),c}return u.replace(t,l)}catch(u){if(u instanceof Q)throw u;return t}}function Oa(e,t,s){e.coverage?.hit("bash:expansion:length");let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(r){let n=r[1],i=F(e,n);return i.length>0?String(i.length):e.state.env.get(n)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&He(e,t)){if(t==="FUNCNAME"){let i=e.state.funcNameStack?.[0]||"";return String([...i].length)}if(t==="BASH_LINENO"){let i=e.state.callLineStack?.[0];return String(i!==void 0?[...String(i)].length:0)}let n=e.state.env.get(`${t}_0`)||"";return String([...n].length)}return String([...s].length)}async function Ta(e,t,s,r){e.coverage?.hit("bash:expansion:substring");let n=await T(e,r.offset.expression),i=r.length?await T(e,r.length.expression):void 0;if(t==="@"||t==="*"){let u=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let p=1;p<=u;p++)c.push(e.state.env.get(String(p))||"");let f=e.state.env.get("0")||"bash",d,h;if(n<=0)if(d=[f,...c],n<0){if(h=d.length+n,h<0)return""}else h=0;else d=c,h=n-1;if(h<0||h>=d.length)return"";if(i!==void 0){let p=i<0?d.length+i:h+i;return d.slice(h,Math.max(h,p)).join(" ")}return d.slice(h).join(" ")}let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(a){let u=a[1];if(e.state.associativeArrays?.has(u))throw new U(1,"",`bash: \${${u}[@]: 0: 3}: bad substitution
73
+ `);let c=F(e,u),f=0;if(n<0){if(c.length>0){let d=c[c.length-1][0],p=(typeof d=="number"?d:0)+1+n;if(p<0||(f=c.findIndex(([m])=>typeof m=="number"&&m>=p),f<0))return""}}else if(f=c.findIndex(([d])=>typeof d=="number"&&d>=n),f<0)return"";if(i!==void 0){if(i<0)throw new te(`${a[1]}[@]: substring expression < 0`);return c.slice(f,f+i).map(([,d])=>d).join(" ")}return c.slice(f).map(([,d])=>d).join(" ")}let l=[...s],o=n;if(o<0&&(o=Math.max(0,l.length+o)),i!==void 0){if(i<0){let u=l.length+i;return l.slice(o,Math.max(o,u)).join("")}return l.slice(o,o+i).join("")}return l.slice(o).join("")}async function La(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:case_modification"),s.pattern){let i=e.state.shoptOptions.extglob,a="";for(let f of s.pattern.parts)if(f.type==="Glob")a+=Z(f.pattern,!0,i);else if(f.type==="Literal")a+=Z(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")a+=j(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);a+=j(d)}else if(f.type==="ParameterExpansion"){let d=await n(e,f);a+=Z(d,!0,i)}let l=ae(`^(?:${a})$`),o=s.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),u="",c=!1;for(let f of t)!s.all&&c?u+=f:l.test(f)?(u+=o(f),c=!0):u+=f;return u}return s.direction==="upper"?s.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):s.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function Wa(e,t,s,r,n){e.coverage?.hit("bash:expansion:transform");let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i&&n.operator==="Q")return F(e,i[1]).map(([,u])=>yt(u)).join(" ");if(i&&n.operator==="a")return wt(e,i[1]);let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(a&&n.operator==="a")return wt(e,a[1]);switch(n.operator){case"Q":return r?"":yt(s);case"P":return is(e,s);case"a":return wt(e,t);case"A":return r?"":`${t}=${yt(s)}`;case"E":return s.replace(/\\([\\abefnrtv'"?])/g,(l,o)=>{switch(o){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
74
+ `;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return o}});case"K":case"k":return r?"":yt(s);case"u":return s.charAt(0).toUpperCase()+s.slice(1);case"U":return s.toUpperCase();case"L":return s.toLowerCase();default:return s}}async function Ma(e,t,s,r,n,i,a=!1){if(e.coverage?.hit("bash:expansion:indirection"),ee(e,t))return kt(e,t)||"";let l=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(n.innerOp?.type==="UseAlternative")return"";throw new xe(`\${!${t}}`)}let o=s;if(l&&(o===""||o.includes(" ")))throw new xe(`\${!${t}}`);let u=o.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new xe(`\${!${t}}`);if(n.innerOp){let c={type:"ParameterExpansion",parameter:o,operation:n.innerOp};return i(e,c,a)}return await Y(e,o)}function Fa(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=F(e,t.array).map(([n])=>String(n));return t.star?r.join(z(e.state.env)):r.join(" ")}function Va(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let s=Vt(e,t.prefix);return t.star?s.join(z(e.state.env)):s.join(" ")}function za(e,t,s,r){let n=Number.parseInt(e.state.env.get("#")||"0",10),i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:n===0,effectiveValue:s};if(t==="@")return{isEmpty:n===0||n===1&&e.state.env.get("1")==="",effectiveValue:s};if(i){let[,a,l]=i,o=F(e,a);if(o.length===0)return{isEmpty:!0,effectiveValue:""};if(l==="*"){let u=z(e.state.env),c=o.map(([,f])=>f).join(u);return{isEmpty:r?c==="":!1,effectiveValue:c}}return{isEmpty:o.length===1&&o.every(([,u])=>u===""),effectiveValue:o.map(([,u])=>u).join(" ")}}return{isEmpty:s==="",effectiveValue:s}}function Ba(e){let t=0;for(;t<e.length;){let s=e[t];if(s==="\\"&&t+1<e.length){t+=2;continue}if(s==="'"){let r=e.indexOf("'",t+1);if(r!==-1){t=r+1;continue}}if(s==="$"&&t+1<e.length&&e[t+1]==="("||s==="`")return!0;t++}return!1}function qa(e,t){let s=1,r=t,n=!1,i=!1;for(;r<e.length&&s>0;){let a=e[r];if(a==="\\"&&!n&&r+1<e.length){r+=2;continue}if(a==="'"&&!i){n=!n,r++;continue}if(a==='"'&&!n){i=!i,r++;continue}if(!n&&!i){if(a==="(")s++;else if(a===")"&&(s--,s===0))return r}r++}return-1}async function Ts(e,t){let s=new V,r;try{r=s.parse(t)}catch{return""}let n=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let i=new Map(e.state.env),a=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let o=await e.executeScript(r),u=o.exitCode;return e.state.env=i,e.state.cwd=a,e.state.suppressVerbose=l,e.state.lastExitCode=u,e.state.env.set("?",String(u)),o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),e.state.bashPid=n,o.stdout.replace(/\n+$/,"")}catch(o){if(e.state.env=i,e.state.cwd=a,e.state.bashPid=n,e.state.suppressVerbose=l,o instanceof Q)throw o;return o instanceof U?(e.state.lastExitCode=o.exitCode,e.state.env.set("?",String(o.exitCode)),o.stdout?.replace(/\n+$/,"")??""):""}}function ur(e,t){let s="",r=0;for(;r<t.length;){let n=t[r];if(n==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let a=t.slice(r+1,i);s+=Te(a),r=i+1;continue}}if(n==='"'){let i=-1,a=r+1;for(;a<t.length;){if(t[a]==="\\"){a+=2;continue}if(t[a]==='"'){i=a;break}a++}if(i!==-1){let l=t.slice(r+1,i),o=Au(e,l);s+=Te(o),r=i+1;continue}}if(n==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let a=t.indexOf("}",r+2);if(a!==-1){let l=t.slice(r+2,a);s+=e.state.env.get(l)??"",r=a+1;continue}}else if(/[a-zA-Z_]/.test(i)){let a=r+1;for(;a<t.length&&/[a-zA-Z0-9_]/.test(t[a]);)a++;let l=t.slice(r+1,a);s+=e.state.env.get(l)??"",r=a;continue}}if(n==="\\"&&r+1<t.length){s+=n+t[r+1],r+=2;continue}s+=n,r++}return s}function Au(e,t){let s="",r=0;for(;r<t.length;){let n=t[r];if(n==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){s+=i,r+=2;continue}s+=n,r++;continue}if(n==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let a=t.indexOf("}",r+2);if(a!==-1){let l=t.slice(r+2,a);s+=e.state.env.get(l)??"",r=a+1;continue}}else if(/[a-zA-Z_]/.test(i)){let a=r+1;for(;a<t.length&&/[a-zA-Z0-9_]/.test(t[a]);)a++;let l=t.slice(r+1,a);s+=e.state.env.get(l)??"",r=a;continue}}s+=n,r++}return s}async function Ua(e,t){let s="",r=0;for(;r<t.length;){let n=t[r];if(n==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let a=t.slice(r+1,i);s+=Te(a),r=i+1;continue}}if(n==='"'){let i=-1,a=r+1;for(;a<t.length;){if(t[a]==="\\"){a+=2;continue}if(t[a]==='"'){i=a;break}a++}if(i!==-1){let l=t.slice(r+1,i),o=await $u(e,l);s+=Te(o),r=i+1;continue}}if(n==="$"&&r+1<t.length&&t[r+1]==="("){let i=qa(t,r+2);if(i!==-1){let a=t.slice(r+2,i),l=await Ts(e,a);s+=l,r=i+1;continue}}if(n==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let a=t.slice(r+1,i),l=await Ts(e,a);s+=l,r=i+1;continue}}if(n==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let a=t.indexOf("}",r+2);if(a!==-1){let l=t.slice(r+2,a);s+=e.state.env.get(l)??"",r=a+1;continue}}else if(/[a-zA-Z_]/.test(i)){let a=r+1;for(;a<t.length&&/[a-zA-Z0-9_]/.test(t[a]);)a++;let l=t.slice(r+1,a);s+=e.state.env.get(l)??"",r=a;continue}}if(n==="\\"&&r+1<t.length){s+=n+t[r+1],r+=2;continue}s+=n,r++}return s}async function $u(e,t){let s="",r=0;for(;r<t.length;){let n=t[r];if(n==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){s+=i,r+=2;continue}s+=n,r++;continue}if(n==="$"&&r+1<t.length&&t[r+1]==="("){let i=qa(t,r+2);if(i!==-1){let a=t.slice(r+2,i),l=await Ts(e,a);s+=l,r=i+1;continue}}if(n==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let a=t.slice(r+1,i),l=await Ts(e,a);s+=l,r=i+1;continue}}if(n==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let a=t.indexOf("}",r+2);if(a!==-1){let l=t.slice(r+2,a);s+=e.state.env.get(l)??"",r=a+1;continue}}else if(/[a-zA-Z_]/.test(i)){let a=r+1;for(;a<t.length&&/[a-zA-Z0-9_]/.test(t[a]);)a++;let l=t.slice(r+1,a);s+=e.state.env.get(l)??"",r=a;continue}}s+=n,r++}return s}function Za(e,t){if(!t.startsWith("~"))return t;e.coverage?.hit("bash:expansion:tilde");let s=e.state.env.get("HOME")!==void 0?e.state.env.get("HOME"):"/home/user";if(t==="~"||t.startsWith("~/"))return s+t.slice(1);let r=1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;let n=t.slice(1,r),i=t.slice(r);return i!==""&&!i.startsWith("/")?t:n==="root"?`/root${i}`:t}async function Nu(e,t,s,r){let n="";for(let i of t.parts)if(i.type==="Glob")n+=Z(i.pattern,!0,e.state.shoptOptions.extglob);else if(i.type==="Literal")n+=Z(i.value,!0,e.state.shoptOptions.extglob);else if(i.type==="SingleQuoted"||i.type==="Escaped")n+=j(i.value);else if(i.type==="DoubleQuoted"){let a=await s(e,i.parts);n+=j(a)}else if(i.type==="ParameterExpansion"){let a=await r(e,i);n+=Z(a,!0,e.state.shoptOptions.extglob)}else{let a=await r(e,i);n+=j(a)}return n}async function Ha(e,t,s,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternReplacement")return null;let i=n.parts[0],a=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let l=a[1],o=a[2]==="*",u=i.operation,c=F(e,l),f=c.map(([,y])=>y);if(c.length===0){let y=e.state.env.get(l);y!==void 0&&f.push(y)}if(f.length===0)return{values:[],quoted:!0};let d="";u.pattern&&(d=await Nu(e,u.pattern,s,r));let h=u.replacement?await s(e,u.replacement.parts):"",p=d;u.anchor==="start"?p=`^${d}`:u.anchor==="end"&&(p=`${d}$`);let m=[];try{let y=ae(p,u.all?"g":"");for(let b of f)m.push(y.replace(b,h))}catch{m.push(...f)}if(o){let y=z(e.state.env);return{values:[m.join(y)],quoted:!0}}return{values:m,quoted:!0}}async function ja(e,t,s,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternRemoval")return null;let i=n.parts[0],a=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let l=a[1],o=a[2]==="*",u=i.operation,c=F(e,l),f=c.map(([,m])=>m);if(c.length===0){let m=e.state.env.get(l);m!==void 0&&f.push(m)}if(f.length===0)return{values:[],quoted:!0};let d="",h=e.state.shoptOptions.extglob;if(u.pattern)for(let m of u.pattern.parts)if(m.type==="Glob")d+=Z(m.pattern,u.greedy,h);else if(m.type==="Literal")d+=Z(m.value,u.greedy,h);else if(m.type==="SingleQuoted"||m.type==="Escaped")d+=j(m.value);else if(m.type==="DoubleQuoted"){let y=await s(e,m.parts);d+=j(y)}else if(m.type==="ParameterExpansion"){let y=await r(e,m);d+=Z(y,u.greedy,h)}else{let y=await r(e,m);d+=j(y)}let p=[];for(let m of f)p.push(ct(m,d,u.side,u.greedy));if(o){let m=z(e.state.env);return{values:[p.join(m)],quoted:!0}}return{values:p,quoted:!0}}async function Ga(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="DefaultValue"&&s.parts[0].operation?.type!=="UseAlternative"&&s.parts[0].operation?.type!=="AssignDefault")return null;let r=s.parts[0],n=r.operation,i=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/),a,l=!1;if(i){let o=i[1];l=i[2]==="*";let u=F(e,o),c=u.length>0||e.state.env.has(o),f=u.length===0||u.length===1&&u.every(([,h])=>h===""),d=n.checkEmpty??!1;if(n.type==="UseAlternative"?a=c&&!(d&&f):a=!c||d&&f,!a){if(u.length>0){let p=u.map(([,m])=>m);if(l){let m=z(e.state.env);return{values:[p.join(m)],quoted:!0}}return{values:p,quoted:!0}}let h=e.state.env.get(o);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}}else{let o=r.parameter,u=await Ye(e,o),c=await Y(e,o),f=c==="",d=n.checkEmpty??!1;if(n.type==="UseAlternative"?a=u&&!(d&&f):a=!u||d&&f,!a)return{values:[c],quoted:!0}}if(a&&n.word){let o=n.word.parts,u=null,c=!1;for(let f of o)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){u=d[1],c=d[2]==="*";break}}if(u){let f=F(e,u);if(f.length>0){let h=f.map(([,p])=>p);if(c||l){let p=z(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}let d=e.state.env.get(u);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}return null}async function Qa(e,t,s,r,n){if(!s||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0],a=-1,l="",o=!1,u=null;for(let m=0;m<i.parts.length;m++){let y=i.parts[m];if(y.type==="ParameterExpansion"&&(y.operation?.type==="PatternRemoval"||y.operation?.type==="PatternReplacement")){let b=y.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){a=m,l=b[1],o=b[2]==="*",u=y.operation;break}}}if(a===-1||a===0&&a===i.parts.length-1)return null;let c="";for(let m=0;m<a;m++)c+=await r(e,i.parts[m]);let f="";for(let m=a+1;m<i.parts.length;m++)f+=await r(e,i.parts[m]);let d=F(e,l),h=d.map(([,m])=>m);if(d.length===0){let m=e.state.env.get(l);if(m!==void 0)h=[m];else{if(o)return{values:[c+f],quoted:!0};let y=c+f;return{values:y?[y]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let m=u,y="",b=e.state.shoptOptions.extglob;if(m.pattern)for(let v of m.pattern.parts)if(v.type==="Glob")y+=Z(v.pattern,m.greedy,b);else if(v.type==="Literal")y+=Z(v.value,m.greedy,b);else if(v.type==="SingleQuoted"||v.type==="Escaped")y+=j(v.value);else if(v.type==="DoubleQuoted"){let E=await n(e,v.parts);y+=j(E)}else if(v.type==="ParameterExpansion"){let E=await r(e,v);y+=Z(E,m.greedy,b)}else{let E=await r(e,v);y+=j(E)}h=h.map(v=>ct(v,y,m.side,m.greedy))}else if(u?.type==="PatternReplacement"){let m=u,y="";if(m.pattern)for(let E of m.pattern.parts)if(E.type==="Glob")y+=Z(E.pattern,!0,e.state.shoptOptions.extglob);else if(E.type==="Literal")y+=Z(E.value,!0,e.state.shoptOptions.extglob);else if(E.type==="SingleQuoted"||E.type==="Escaped")y+=j(E.value);else if(E.type==="DoubleQuoted"){let w=await n(e,E.parts);y+=j(w)}else if(E.type==="ParameterExpansion"){let w=await r(e,E);y+=Z(w,!0,e.state.shoptOptions.extglob)}else{let w=await r(e,E);y+=j(w)}let b=m.replacement?await n(e,m.replacement.parts):"",v=y;m.anchor==="start"?v=`^${y}`:m.anchor==="end"&&(v=`${y}$`);try{let E=ae(v,m.all?"g":"");h=h.map(w=>E.replace(w,b))}catch{}}if(o){let m=z(e.state.env);return{values:[c+h.join(m)+f],quoted:!0}}return h.length===1?{values:[c+h[0]+f],quoted:!0}:{values:[c+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function Ka(e,t,s,r){if(!s||t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],i=-1,a="",l=!1;for(let h=0;h<n.parts.length;h++){let p=n.parts[h];if(p.type==="ParameterExpansion"&&!p.operation){let m=p.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(m){i=h,a=m[1],l=m[2]==="*";break}}}if(i===-1)return null;let o="";for(let h=0;h<i;h++)o+=await r(e,n.parts[h]);let u="";for(let h=i+1;h<n.parts.length;h++)u+=await r(e,n.parts[h]);let c=F(e,a),f=c.map(([,h])=>h);if(c.length===0){let h=e.state.env.get(a);if(h!==void 0)return{values:[o+h+u],quoted:!0};if(l)return{values:[o+u],quoted:!0};let p=o+u;return{values:p?[p]:[],quoted:!0}}if(l){let h=z(e.state.env);return{values:[o+f.join(h)+u],quoted:!0}}return f.length===1?{values:[o+f[0]+u],quoted:!0}:{values:[o+f[0],...f.slice(1,-1),f[f.length-1]+u],quoted:!0}}async function Xa(e,t,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Substring")return null;let n=r.parts[0],i=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let a=i[1],l=i[2]==="*",o=n.operation;if(e.state.associativeArrays?.has(a))throw new U(1,"",`bash: \${${a}[@]: 0: 3}: bad substitution
75
+ `);let u=o.offset?await s(e,o.offset.expression):0,c=o.length?await s(e,o.length.expression):void 0,f=F(e,a),d=0;if(u<0){if(f.length>0){let p=f[f.length-1][0],y=(typeof p=="number"?p:0)+1+u;if(y<0)return{values:[],quoted:!0};d=f.findIndex(([b])=>typeof b=="number"&&b>=y),d<0&&(d=f.length)}}else d=f.findIndex(([p])=>typeof p=="number"&&p>=u),d<0&&(d=f.length);let h;if(c!==void 0){if(c<0)throw new te(`${a}[@]: substring expression < 0`);h=f.slice(d,d+c).map(([,p])=>p)}else h=f.slice(d).map(([,p])=>p);if(h.length===0)return{values:[],quoted:!0};if(l){let p=z(e.state.env);return{values:[h.join(p)],quoted:!0}}return{values:h,quoted:!0}}function Ya(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="Transform")return null;let r=s.parts[0],n=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let i=n[1],a=n[2]==="*",l=r.operation,o=F(e,i);if(o.length===0){let f=e.state.env.get(i);if(f!==void 0){let d;switch(l.operator){case"a":d="";break;case"P":d=is(e,f);break;case"Q":d=yt(f);break;default:d=f}return{values:[d],quoted:!0}}return a?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=wt(e,i),c;switch(l.operator){case"a":c=o.map(()=>u);break;case"P":c=o.map(([,f])=>is(e,f));break;case"Q":c=o.map(([,f])=>yt(f));break;case"u":c=o.map(([,f])=>f.charAt(0).toUpperCase()+f.slice(1));break;case"U":c=o.map(([,f])=>f.toUpperCase());break;case"L":c=o.map(([,f])=>f.toLowerCase());break;default:c=o.map(([,f])=>f)}if(a){let f=z(e.state.env);return{values:[c.join(f)],quoted:!0}}return{values:c,quoted:!0}}function Ja(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion")return null;let r=s.parts[0];if(r.operation)return null;let n=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!n)return null;let i=n[1];if(ee(e,i)){let o=kt(e,i);if(o?.endsWith("[@]")||o?.endsWith("[*]"))return{values:[],quoted:!0}}let a=F(e,i);if(a.length>0)return{values:a.map(([,o])=>o),quoted:!0};let l=e.state.env.get(i);return l!==void 0?{values:[l],quoted:!0}:{values:[],quoted:!0}}function eo(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation)return null;let n=s.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||!ee(e,n))return null;let i=kt(e,n);if(!i)return null;let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!a)return null;let l=a[1],o=F(e,l);if(o.length>0)return{values:o.map(([,c])=>c),quoted:!0};let u=e.state.env.get(l);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function to(e,t,s,r,n){if(!s||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let a=i.parts[0],l=a.operation,o=await Y(e,a.parameter),u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!l.innerOp&&(o==="@"||o==="*")){let p=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let y=1;y<=p;y++)m.push(e.state.env.get(String(y))||"");return o==="*"?{values:[m.join(z(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let c=u[1],f=u[2]==="*",d=F(e,c);if(l.innerOp){if(l.innerOp.type==="Substring")return ku(e,d,c,f,l.innerOp);if(l.innerOp.type==="DefaultValue"||l.innerOp.type==="UseAlternative"||l.innerOp.type==="AssignDefault"||l.innerOp.type==="ErrorIfUnset")return _u(e,d,c,f,l.innerOp,n);if(l.innerOp.type==="Transform"&&l.innerOp.operator==="a"){let m=wt(e,c),y=d.map(()=>m);return f?{values:[y.join(z(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let p=[];for(let[,m]of d){let y={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:l.innerOp},b=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",m);try{let v=await r(e,y,!0);p.push(v)}finally{b!==void 0?e.state.env.set("_indirect_elem_",b):e.state.env.delete("_indirect_elem_")}}return f?{values:[p.join(z(e.state.env))],quoted:!0}:{values:p,quoted:!0}}if(d.length>0){let p=d.map(([,m])=>m);return f?{values:[p.join(z(e.state.env))],quoted:!0}:{values:p,quoted:!0}}let h=e.state.env.get(c);return h!==void 0?{values:[h],quoted:!0}:{values:[],quoted:!0}}async function ku(e,t,s,r,n){let i=n.offset?await T(e,n.offset.expression):0,a=n.length?await T(e,n.length.expression):void 0,l=0;if(i<0){if(t.length>0){let c=t[t.length-1][0],d=(typeof c=="number"?c:0)+1+i;if(d<0)return{values:[],quoted:!0};if(l=t.findIndex(([h])=>typeof h=="number"&&h>=d),l<0)return{values:[],quoted:!0}}}else if(l=t.findIndex(([c])=>typeof c=="number"&&c>=i),l<0)return{values:[],quoted:!0};let o;if(a!==void 0){if(a<0)throw new te(`${s}[@]: substring expression < 0`);o=t.slice(l,l+a)}else o=t.slice(l);let u=o.map(([,c])=>c);return r?{values:[u.join(z(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function _u(e,t,s,r,n,i){let a=n.checkEmpty??!1,l=t.map(([,c])=>c),o=t.length===0,u=t.length===0;if(n.type==="UseAlternative")return!u&&!(a&&o)&&n.word?{values:[await i(e,n.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(n.type==="DefaultValue")return(u||a&&o)&&n.word?{values:[await i(e,n.word.parts,!0)],quoted:!0}:r?{values:[l.join(z(e.state.env))],quoted:!0}:{values:l,quoted:!0};if(n.type==="AssignDefault"){if((u||a&&o)&&n.word){let f=await i(e,n.word.parts,!0);return e.state.env.set(`${s}_0`,f),e.state.env.set(`${s}__length`,"1"),{values:[f],quoted:!0}}return r?{values:[l.join(z(e.state.env))],quoted:!0}:{values:l,quoted:!0}}return r?{values:[l.join(z(e.state.env))],quoted:!0}:{values:l,quoted:!0}}async function so(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let s=t[0],r=s.operation,n=r?.word;if(!n||n.parts.length!==1||n.parts[0].type!=="DoubleQuoted")return null;let i=n.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let a=i.parts[0],o=(await Y(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let u=await Ye(e,s.parameter),c=await Y(e,s.parameter)==="",f=r.checkEmpty??!1,d;if(r.type==="UseAlternative"?d=u&&!(f&&c):d=!u||f&&c,d){let h=o[1],p=o[2]==="*",m=F(e,h);if(m.length>0){let b=m.map(([,v])=>v);return p?{values:[b.join(z(e.state.env))],quoted:!0}:{values:b,quoted:!0}}let y=e.state.env.get(h);return y!==void 0?{values:[y],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function no(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let s=t[0],n=s.operation.innerOp;if(!n||n.type!=="UseAlternative"&&n.type!=="DefaultValue")return null;let i=n.word;if(!i||i.parts.length!==1||i.parts[0].type!=="DoubleQuoted")return null;let a=i.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let l=a.parts[0],u=(await Y(e,l.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await Y(e,s.parameter),f=await Ye(e,s.parameter),d=c==="",h=n.checkEmpty??!1,p;if(n.type==="UseAlternative"?p=f&&!(h&&d):p=!f||h&&d,p){let m=u[1],y=u[2]==="*",b=F(e,m);if(b.length>0){let E=b.map(([,w])=>w);return y?{values:[E.join(z(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let v=e.state.env.get(m);return v!==void 0?{values:[v],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function ro(e){let t=Number.parseInt(e.state.env.get("#")||"0",10),s=[];for(let r=1;r<=t;r++)s.push(e.state.env.get(String(r))||"");return s}async function io(e,t,s,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],i=-1,a=!1;for(let v=0;v<n.parts.length;v++){let E=n.parts[v];if(E.type==="ParameterExpansion"&&(E.parameter==="@"||E.parameter==="*")&&E.operation?.type==="Substring"){i=v,a=E.parameter==="*";break}}if(i===-1)return null;let o=n.parts[i].operation,u=o.offset?await s(e,o.offset.expression):0,c=o.length?await s(e,o.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),d=[];for(let v=1;v<=f;v++)d.push(e.state.env.get(String(v))||"");let h=e.state.env.get("0")||"bash",p;if(u<=0){let v=[h,...d],E=v.length+u;if(E<0)p=[];else{let w=u<0?E:0;if(c!==void 0){let S=c<0?v.length+c:w+c;p=v.slice(w,Math.max(w,S))}else p=v.slice(w)}}else{let v=u-1;if(v>=d.length)p=[];else if(c!==void 0){let E=c<0?d.length+c:v+c;p=d.slice(v,Math.max(v,E))}else p=d.slice(v)}let m="";for(let v=0;v<i;v++)m+=await r(e,n.parts[v]);let y="";for(let v=i+1;v<n.parts.length;v++)y+=await r(e,n.parts[v]);if(p.length===0){let v=m+y;return{values:v?[v]:[],quoted:!0}}if(a){let v=z(e.state.env);return{values:[m+p.join(v)+y],quoted:!0}}return p.length===1?{values:[m+p[0]+y],quoted:!0}:{values:[m+p[0],...p.slice(1,-1),p[p.length-1]+y],quoted:!0}}async function ao(e,t,s,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],i=-1,a=!1;for(let b=0;b<n.parts.length;b++){let v=n.parts[b];if(v.type==="ParameterExpansion"&&(v.parameter==="@"||v.parameter==="*")&&v.operation?.type==="PatternReplacement"){i=b,a=v.parameter==="*";break}}if(i===-1)return null;let o=n.parts[i].operation,u=ro(e),c="";for(let b=0;b<i;b++)c+=await s(e,n.parts[b]);let f="";for(let b=i+1;b<n.parts.length;b++)f+=await s(e,n.parts[b]);if(u.length===0){let b=c+f;return{values:b?[b]:[],quoted:!0}}let d="";if(o.pattern)for(let b of o.pattern.parts)if(b.type==="Glob")d+=Z(b.pattern,!0,e.state.shoptOptions.extglob);else if(b.type==="Literal")d+=Z(b.value,!0,e.state.shoptOptions.extglob);else if(b.type==="SingleQuoted"||b.type==="Escaped")d+=j(b.value);else if(b.type==="DoubleQuoted"){let v=await r(e,b.parts);d+=j(v)}else if(b.type==="ParameterExpansion"){let v=await s(e,b);d+=Z(v,!0,e.state.shoptOptions.extglob)}else{let v=await s(e,b);d+=j(v)}let h=o.replacement?await r(e,o.replacement.parts):"",p=d;o.anchor==="start"?p=`^${d}`:o.anchor==="end"&&(p=`${d}$`);let m=[];try{let b=ae(p,o.all?"g":"");for(let v of u)m.push(b.replace(v,h))}catch{m.push(...u)}if(a){let b=z(e.state.env);return{values:[c+m.join(b)+f],quoted:!0}}return m.length===1?{values:[c+m[0]+f],quoted:!0}:{values:[c+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function oo(e,t,s,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],i=-1,a=!1;for(let y=0;y<n.parts.length;y++){let b=n.parts[y];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="PatternRemoval"){i=y,a=b.parameter==="*";break}}if(i===-1)return null;let o=n.parts[i].operation,u=ro(e),c="";for(let y=0;y<i;y++)c+=await s(e,n.parts[y]);let f="";for(let y=i+1;y<n.parts.length;y++)f+=await s(e,n.parts[y]);if(u.length===0){let y=c+f;return{values:y?[y]:[],quoted:!0}}let d="",h=e.state.shoptOptions.extglob;if(o.pattern)for(let y of o.pattern.parts)if(y.type==="Glob")d+=Z(y.pattern,o.greedy,h);else if(y.type==="Literal")d+=Z(y.value,o.greedy,h);else if(y.type==="SingleQuoted"||y.type==="Escaped")d+=j(y.value);else if(y.type==="DoubleQuoted"){let b=await r(e,y.parts);d+=j(b)}else if(y.type==="ParameterExpansion"){let b=await s(e,y);d+=Z(b,o.greedy,h)}else{let b=await s(e,y);d+=j(b)}let p=[];for(let y of u)p.push(ct(y,d,o.side,o.greedy));if(a){let y=z(e.state.env);return{values:[c+p.join(y)+f],quoted:!0}}return p.length===1?{values:[c+p[0]+f],quoted:!0}:{values:[c+p[0],...p.slice(1,-1),p[p.length-1]+f],quoted:!0}}async function lo(e,t,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0],n=-1,i=!1;for(let d=0;d<r.parts.length;d++){let h=r.parts[d];if(h.type==="ParameterExpansion"&&(h.parameter==="@"||h.parameter==="*")){n=d,i=h.parameter==="*";break}}if(n===-1)return null;let a=r.parts[n];if(a.type==="ParameterExpansion"&&a.operation)return null;let l=Number.parseInt(e.state.env.get("#")||"0",10),o="";for(let d=0;d<n;d++)o+=await s(e,r.parts[d]);let u="";for(let d=n+1;d<r.parts.length;d++)u+=await s(e,r.parts[d]);if(l===0){if(i)return{values:[o+u],quoted:!0};let d=o+u;return{values:d?[d]:[],quoted:!0}}let c=[];for(let d=1;d<=l;d++)c.push(e.state.env.get(String(d))||"");if(i){let d=z(e.state.env);return{values:[o+c.join(d)+u],quoted:!0}}return c.length===1?{values:[o+c[0]+u],quoted:!0}:{values:[o+c[0],...c.slice(1,-1),c[c.length-1]+u],quoted:!0}}function Pu(e){return new gt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations})}async function Ls(e,t){if(e.state.options.noglob)return t;let s=Pu(e),r=[];for(let n of t)if(Je(n,e.state.shoptOptions.extglob)){let i=await s.expand(n);if(i.length>0)r.push(...i);else{if(s.hasFailglob())throw new ut(n);s.hasNullglob()||r.push(n)}}else r.push(n);return r}async function co(e,t,s,r){let n=-1,i="",a=!1;for(let v=0;v<t.length;v++){let E=t[v];if(E.type==="ParameterExpansion"&&E.operation?.type==="PatternReplacement"){let w=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(w){n=v,i=w[1],a=w[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,u=F(e,i),c=u.map(([,v])=>v);if(u.length===0){let v=e.state.env.get(i);v!==void 0&&(c=[v])}if(c.length===0)return{values:[],quoted:!1};let f="";if(o.pattern)for(let v of o.pattern.parts)if(v.type==="Glob")f+=Z(v.pattern,!0,e.state.shoptOptions.extglob);else if(v.type==="Literal")f+=Z(v.value,!0,e.state.shoptOptions.extglob);else if(v.type==="SingleQuoted"||v.type==="Escaped")f+=j(v.value);else if(v.type==="DoubleQuoted"){let E=await s(e,v.parts);f+=j(E)}else if(v.type==="ParameterExpansion"){let E=await r(e,v);f+=Z(E,!0,e.state.shoptOptions.extglob)}else{let E=await r(e,v);f+=j(E)}let d=o.replacement?await s(e,o.replacement.parts):"",h=f;o.anchor==="start"?h=`^${f}`:o.anchor==="end"&&(h=`${f}$`);let p=[];try{let v=ae(h,o.all?"g":"");for(let E of c)p.push(v.replace(E,d))}catch{p.push(...c)}let m=he(e.state.env),y=Ee(e.state.env);if(a){let v=z(e.state.env),E=p.join(v);return y?{values:E?[E]:[],quoted:!1}:{values:se(E,m),quoted:!1}}if(y)return{values:p,quoted:!1};let b=[];for(let v of p)v===""?b.push(""):b.push(...se(v,m));return{values:b,quoted:!1}}async function uo(e,t,s,r){let n=-1,i="",a=!1;for(let b=0;b<t.length;b++){let v=t[b];if(v.type==="ParameterExpansion"&&v.operation?.type==="PatternRemoval"){let E=v.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(E){n=b,i=E[1],a=E[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,u=F(e,i),c=u.map(([,b])=>b);if(u.length===0){let b=e.state.env.get(i);b!==void 0&&(c=[b])}if(c.length===0)return{values:[],quoted:!1};let f="",d=e.state.shoptOptions.extglob;if(o.pattern)for(let b of o.pattern.parts)if(b.type==="Glob")f+=Z(b.pattern,o.greedy,d);else if(b.type==="Literal")f+=Z(b.value,o.greedy,d);else if(b.type==="SingleQuoted"||b.type==="Escaped")f+=j(b.value);else if(b.type==="DoubleQuoted"){let v=await s(e,b.parts);f+=j(v)}else if(b.type==="ParameterExpansion"){let v=await r(e,b);f+=Z(v,o.greedy,d)}else{let v=await r(e,b);f+=j(v)}let h=[];for(let b of c)h.push(ct(b,f,o.side,o.greedy));let p=he(e.state.env),m=Ee(e.state.env);if(a){let b=z(e.state.env),v=h.join(b);return m?{values:v?[v]:[],quoted:!1}:{values:se(v,p),quoted:!1}}if(m)return{values:h,quoted:!1};let y=[];for(let b of h)b===""?y.push(""):y.push(...se(b,p));return{values:y,quoted:!1}}async function fo(e,t,s,r){let n=-1,i=!1;for(let y=0;y<t.length;y++){let b=t[y];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="PatternRemoval"){n=y,i=b.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let y=1;y<=o;y++)u.push(e.state.env.get(String(y))||"");if(u.length===0)return{values:[],quoted:!1};let c="",f=e.state.shoptOptions.extglob;if(l.pattern)for(let y of l.pattern.parts)if(y.type==="Glob")c+=Z(y.pattern,l.greedy,f);else if(y.type==="Literal")c+=Z(y.value,l.greedy,f);else if(y.type==="SingleQuoted"||y.type==="Escaped")c+=j(y.value);else if(y.type==="DoubleQuoted"){let b=await s(e,y.parts);c+=j(b)}else if(y.type==="ParameterExpansion"){let b=await r(e,y);c+=Z(b,l.greedy,f)}else{let b=await r(e,y);c+=j(b)}let d=[];for(let y of u)d.push(ct(y,c,l.side,l.greedy));let h=he(e.state.env),p=Ee(e.state.env);if(i){let y=z(e.state.env),b=d.join(y);return p?{values:b?[b]:[],quoted:!1}:{values:se(b,h),quoted:!1}}if(p)return{values:d,quoted:!1};let m=[];for(let y of d)y===""?m.push(""):m.push(...se(y,h));return{values:m,quoted:!1}}async function ho(e,t,s,r){let n=-1,i=!1;for(let E=0;E<t.length;E++){let w=t[E];if(w.type==="ParameterExpansion"&&(w.parameter==="@"||w.parameter==="*")&&w.operation?.type==="Substring"){n=E,i=w.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=l.offset?await s(e,l.offset.expression):0,u=l.length?await s(e,l.length.expression):void 0,c=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let E=1;E<=c;E++)f.push(e.state.env.get(String(E))||"");let d=e.state.env.get("0")||"bash",h;if(o<=0){let E=[d,...f],w=E.length+o;if(w<0)h=[];else{let S=o<0?w:0;if(u!==void 0){let A=u<0?E.length+u:S+u;h=E.slice(S,Math.max(S,A))}else h=E.slice(S)}}else{let E=o-1;if(E>=f.length)h=[];else if(u!==void 0){let w=u<0?f.length+u:E+u;h=f.slice(E,Math.max(E,w))}else h=f.slice(E)}let p="";for(let E=0;E<n;E++)p+=await r(e,t[E]);let m="";for(let E=n+1;E<t.length;E++)m+=await r(e,t[E]);let y=he(e.state.env),b=Ee(e.state.env);if(h.length===0){let E=p+m;return E?b?{values:[E],quoted:!1}:{values:se(E,y),quoted:!1}:{values:[],quoted:!1}}let v;if(i){let E=z(e.state.env),w=p+h.join(E)+m;b?v=w?[w]:[]:v=se(w,y)}else if(b)h.length===1?v=[p+h[0]+m]:v=[p+h[0],...h.slice(1,-1),h[h.length-1]+m];else{v=[];for(let E=0;E<h.length;E++){let w=h[E];if(E===0&&(w=p+w),E===h.length-1&&(w=w+m),w==="")v.push("");else{let S=se(w,y);v.push(...S)}}}return{values:await Ls(e,v),quoted:!1}}async function po(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let s=t[0].parameter==="*",r=Number.parseInt(e.state.env.get("#")||"0",10);if(r===0)return{values:[],quoted:!1};let n=[];for(let u=1;u<=r;u++)n.push(e.state.env.get(String(u))||"");let i=he(e.state.env),a=Ee(e.state.env),l=Is(e.state.env),o;if(s)if(a)o=n.filter(u=>u!=="");else{let u=z(e.state.env),c=n.join(u);o=se(c,i)}else if(a)o=n.filter(u=>u!=="");else if(l){o=[];for(let u of n){if(u==="")continue;let c=se(u,i);o.push(...c)}}else{o=[];for(let u of n)if(u==="")o.push("");else{let c=se(u,i);o.push(...c)}for(;o.length>0&&o[o.length-1]==="";)o.pop()}return{values:await Ls(e,o),quoted:!1}}async function mo(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let s=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!s)return null;let r=s[1],n=s[2]==="*",i=F(e,r),a;if(i.length===0){let f=e.state.env.get(r);if(f!==void 0)a=[f];else return{values:[],quoted:!1}}else a=i.map(([,f])=>f);let l=he(e.state.env),o=Ee(e.state.env),u=Is(e.state.env),c;if(n)if(o)c=a.filter(f=>f!=="");else{let f=z(e.state.env),d=a.join(f);c=se(d,l)}else if(o)c=a.filter(f=>f!=="");else if(u){c=[];for(let f of a){if(f==="")continue;let d=se(f,l);c.push(...d)}}else{c=[];for(let f of a)if(f==="")c.push("");else{let d=se(f,l);c.push(...d)}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Ls(e,c),quoted:!1}}function go(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let s=t[0].operation,r=Vt(e,s.prefix);if(r.length===0)return{values:[],quoted:!1};let n=he(e.state.env),i=Ee(e.state.env),a;if(s.star)if(i)a=r;else{let l=z(e.state.env),o=r.join(l);a=se(o,n)}else if(i)a=r;else{a=[];for(let l of r){let o=se(l,n);a.push(...o)}}return{values:a,quoted:!1}}function yo(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let s=t[0].operation,n=F(e,s.array).map(([o])=>String(o));if(n.length===0)return{values:[],quoted:!1};let i=he(e.state.env),a=Ee(e.state.env),l;if(s.star)if(a)l=n;else{let o=z(e.state.env),u=n.join(o);l=se(u,i)}else if(a)l=n;else{l=[];for(let o of n){let u=se(o,i);l.push(...u)}}return{values:l,quoted:!1}}async function wo(e,t,s){let r=-1;for(let d=0;d<t.length;d++){let h=t[d];if(h.type==="ParameterExpansion"&&(h.parameter==="@"||h.parameter==="*")&&!h.operation){r=d;break}}if(r===-1||t.length<=1)return null;let n=Number.parseInt(e.state.env.get("#")||"0",10),i=[];for(let d=1;d<=n;d++)i.push(e.state.env.get(String(d))||"");let a="";for(let d=0;d<r;d++)a+=await s(e,t[d]);let l="";for(let d=r+1;d<t.length;d++)l+=await s(e,t[d]);let o=he(e.state.env),u=Ee(e.state.env),c=Is(e.state.env);if(n===0){let d=a+l;return{values:d?[d]:[],quoted:!1}}let f;{let d=[];for(let h=0;h<i.length;h++){let p=i[h];h===0&&(p=a+p),h===i.length-1&&(p=p+l),d.push(p)}if(u)f=d.filter(h=>h!=="");else if(c){f=[];for(let h of d){if(h==="")continue;let p=se(h,o);f.push(...p)}}else{f=[];for(let h of d)if(h==="")f.push("");else{let p=se(h,o);f.push(...p)}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Ls(e,f),quoted:!1}}async function vo(e,t,s){e.coverage?.hit("bash:expansion:word_glob");let r=t.parts,{hasQuoted:n,hasCommandSub:i,hasArrayVar:a,hasArrayAtExpansion:l,hasParamExpansion:o,hasVarNamePrefixExpansion:u,hasIndirection:c}=ns(r),d=s.hasBraceExpansion(r)?await s.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return Du(e,d,n);let h=await Iu(e,r,l,u,c,s);if(h!==null)return h;let p=await Ru(e,r,s);if(p!==null)return p;let m=await xu(e,r,s);if(m!==null)return m;let y=await Tu(e,r,s.expandPart);if(y!==null)return bo(e,y);if((i||a||o)&&!Ee(e.state.env)){let v=he(e.state.env),E=s.buildIfsCharClassPattern(v),w=await s.smartWordSplit(e,r,v,E,s.expandPart);return bo(e,w)}let b=await s.expandWordAsync(e,t);return Lu(e,t,r,b,n,s.expandWordForGlobbing)}async function Du(e,t,s){let r=[];for(let n of t)if(!(!s&&n===""))if(!s&&!e.state.options.noglob&&Je(n,e.state.shoptOptions.extglob)){let i=await Ws(e,n);r.push(...i)}else r.push(n);return{values:r,quoted:!1}}async function Iu(e,t,s,r,n,i){if(s){let a=Ja(e,t);if(a!==null)return a}{let a=eo(e,t);if(a!==null)return a}{let a=await Ga(e,t);if(a!==null)return a}{let a=await Qa(e,t,s,i.expandPart,i.expandWordPartsAsync);if(a!==null)return a}{let a=await Ka(e,t,s,i.expandPart);if(a!==null)return a}{let a=await Xa(e,t,i.evaluateArithmetic);if(a!==null)return a}{let a=Ya(e,t);if(a!==null)return a}{let a=await Ha(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}{let a=await ja(e,t,i.expandWordPartsAsync,i.expandPart);if(a!==null)return a}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let a=Cu(e,t);if(a!==null)return a}{let a=await to(e,t,n,i.expandParameterAsync,i.expandWordPartsAsync);if(a!==null)return a}{let a=await so(e,t);if(a!==null)return a}{let a=await no(e,t);if(a!==null)return a}return null}function Cu(e,t){let s=t[0];if(s.type!=="DoubleQuoted")return null;if(s.parts.length===1&&s.parts[0].type==="ParameterExpansion"&&s.parts[0].operation?.type==="VarNamePrefix"){let r=s.parts[0].operation,n=Vt(e,r.prefix);return r.star?{values:[n.join(z(e.state.env))],quoted:!0}:{values:n,quoted:!0}}if(s.parts.length===1&&s.parts[0].type==="ParameterExpansion"&&s.parts[0].operation?.type==="ArrayKeys"){let r=s.parts[0].operation,i=F(e,r.array).map(([a])=>String(a));return r.star?{values:[i.join(z(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function Ru(e,t,s){{let r=await io(e,t,s.evaluateArithmetic,s.expandPart);if(r!==null)return r}{let r=await ao(e,t,s.expandPart,s.expandWordPartsAsync);if(r!==null)return r}{let r=await oo(e,t,s.expandPart,s.expandWordPartsAsync);if(r!==null)return r}{let r=await lo(e,t,s.expandPart);if(r!==null)return r}return null}async function xu(e,t,s){{let r=await co(e,t,s.expandWordPartsAsync,s.expandPart);if(r!==null)return r}{let r=await uo(e,t,s.expandWordPartsAsync,s.expandPart);if(r!==null)return r}{let r=await fo(e,t,s.expandWordPartsAsync,s.expandPart);if(r!==null)return r}{let r=await ho(e,t,s.evaluateArithmetic,s.expandPart);if(r!==null)return r}{let r=await po(e,t);if(r!==null)return r}{let r=await mo(e,t);if(r!==null)return r}{let r=go(e,t);if(r!==null)return r}{let r=yo(e,t);if(r!==null)return r}{let r=await wo(e,t,s.expandPart);if(r!==null)return r}return null}function Eo(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;t<e.parts.length;t++){let s=e.parts[t];if(s.type!=="ParameterExpansion"||s.operation)continue;let r=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(r)return{type:"array",name:r[1],atIndex:t,isStar:r[2]==="*"};if(s.parameter==="@"||s.parameter==="*")return{type:"positional",atIndex:t,isStar:s.parameter==="*"}}return null}async function Ou(e,t,s,r){let n="";for(let l=0;l<s.atIndex;l++)n+=await r(e,t.parts[l]);let i="";for(let l=s.atIndex+1;l<t.parts.length;l++)i+=await r(e,t.parts[l]);let a;if(s.type==="array"){if(a=F(e,s.name).map(([,o])=>o),a.length===0){let o=e.state.env.get(s.name);o!==void 0&&(a=[o])}}else{let l=Number.parseInt(e.state.env.get("#")||"0",10);a=[];for(let o=1;o<=l;o++)a.push(e.state.env.get(String(o))||"")}if(s.isStar){let l=z(e.state.env),o=a.join(l);return[n+o+i]}if(a.length===0){let l=n+i;return l?[l]:[]}return a.length===1?[n+a[0]+i]:[n+a[0],...a.slice(1,-1),a[a.length-1]+i]}async function Tu(e,t,s){if(t.length<2)return null;let r=!1;for(let o of t)if(Eo(o)){r=!0;break}if(!r)return null;let n=he(e.state.env),i=Ee(e.state.env),a=[];for(let o of t){let u=Eo(o);if(u&&o.type==="DoubleQuoted"){let c=await Ou(e,o,u,s);a.push(c)}else if(o.type==="DoubleQuoted"||o.type==="SingleQuoted"){let c=await s(e,o);a.push([c])}else if(o.type==="Literal")a.push([o.value]);else if(o.type==="ParameterExpansion"){let c=await s(e,o);if(i)a.push(c?[c]:[]);else{let f=se(c,n);a.push(f)}}else{let c=await s(e,o);if(i)a.push(c?[c]:[]);else{let f=se(c,n);a.push(f)}}}let l=[];for(let o of a)if(o.length!==0)if(l.length===0)l.push(...o);else{let u=l.length-1;l[u]=l[u]+o[0];for(let c=1;c<o.length;c++)l.push(o[c])}return l}async function bo(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let s=[];for(let r of t)if(Je(r,e.state.shoptOptions.extglob)){let n=await Ws(e,r);s.push(...n)}else s.push(r);return{values:s,quoted:!1}}async function Ws(e,t){let s=new gt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),r=await s.expand(t);if(r.length>0)return r;if(s.hasFailglob())throw new ut(t);return s.hasNullglob()?[]:[t]}async function Lu(e,t,s,r,n,i){let a=s.some(l=>l.type==="Glob");if(!e.state.options.noglob&&a){let l=await i(e,t);if(Je(l,e.state.shoptOptions.extglob)){let u=await Ws(e,l);if(u.length>0&&u[0]!==l)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let o=cr(r);if(!Ee(e.state.env)){let u=he(e.state.env);return{values:se(o,u),quoted:!1}}return{values:[o],quoted:!1}}if(!n&&!e.state.options.noglob&&Je(r,e.state.shoptOptions.extglob)){let l=await i(e,t);if(Je(l,e.state.shoptOptions.extglob)){let o=await Ws(e,l);if(o.length>0&&o[0]!==l)return{values:o,quoted:!1}}}if(r===""&&!n)return{values:[],quoted:!1};if(a&&!n){let l=cr(r);if(!Ee(e.state.env)){let o=he(e.state.env);return{values:se(l,o),quoted:!1}}return{values:[l],quoted:!1}}return{values:[r],quoted:n}}async function Ao(e,t){let s=t.operation;if(!s||s.type!=="DefaultValue"&&s.type!=="AssignDefault"&&s.type!=="UseAlternative")return null;let r=s.word;if(!r||r.parts.length===0)return null;let n=await Ye(e,t.parameter),a=await Y(e,t.parameter,!1)==="",l=s.checkEmpty??!1,o;return s.type==="UseAlternative"?o=n&&!(l&&a):o=!n||l&&a,o?r.parts:null}function Wu(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(s=>s.type==="Literal"):!1}async function Mu(e,t){if(t.type!=="ParameterExpansion")return null;let s=await Ao(e,t);if(!s||s.length<=1)return null;let r=s.some(i=>Wu(i)),n=s.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&n?s:null}function Fu(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?sr(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&Ea(e))}async function $o(e,t,s,r,n){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let d=t[0],h=await Ao(e,d);if(h&&h.length>0&&h.length>1&&h.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&h.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return So(e,h,s,r,n)}let i=[],a=!1;for(let d of t){let h=Fu(d),p=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=h?await Mu(e,d):null,y=await n(e,d);i.push({value:y,isSplittable:h,isQuoted:p,mixedDefaultParts:m??void 0}),h&&(a=!0)}if(!a){let d=i.map(h=>h.value).join("");return d?[d]:[]}let l=[],o="",u=!1,c=!1,f=!1;for(let d of i)if(!d.isSplittable)c?d.isQuoted&&d.value===""?(o!==""&&l.push(o),l.push(""),u=!0,o="",c=!1,f=!0):d.value!==""?(o!==""&&l.push(o),o=d.value,c=!1,f=!1):(o+=d.value,f=!1):(o+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let h=await So(e,d.mixedDefaultParts,s,r,n);if(h.length!==0)if(h.length===1)o+=h[0],u=!0;else{o+=h[0],l.push(o),u=!0;for(let p=1;p<h.length-1;p++)l.push(h[p]);o=h[h.length-1]}c=!1,f=!1}else{let{words:h,hadLeadingDelimiter:p,hadTrailingDelimiter:m}=Cs(d.value,s);if(f&&p&&o===""&&(l.push(""),u=!0),h.length===0)m&&(c=!0);else if(h.length===1)o+=h[0],u=!0,c=m;else{o+=h[0],l.push(o),u=!0;for(let y=1;y<h.length-1;y++)l.push(h[y]);o=h[h.length-1],c=m}f=!1}return o!==""?l.push(o):l.length===0&&u&&l.push(""),l}function Vu(e,t){return e.length>0&&t.includes(e[0])}async function So(e,t,s,r,n){let i=[];for(let c of t){let d=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),h=await n(e,c);i.push({value:h,isSplittable:d})}let a=[],l="",o=!1,u=!1;for(let c of i)if(!c.isSplittable)u&&c.value!==""?(l!==""&&a.push(l),l=c.value,u=!1):l+=c.value;else{Vu(c.value,s)&&l!==""&&(a.push(l),l="",o=!0);let{words:d,hadTrailingDelimiter:h}=Cs(c.value,s);if(d.length===0)h&&(u=!0);else if(d.length===1)l+=d[0],o=!0,u=h;else{l+=d[0],a.push(l),o=!0;for(let p=1;p<d.length-1;p++)a.push(d[p]);l=d[d.length-1],u=h}}return l!==""?a.push(l):a.length===0&&o&&a.push(""),a}function No(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function ko(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}function Et(e,t,s){if(e.length>t)throw new Q(`${s}: string length limit exceeded (${t} bytes)`,"string_length")}async function Ge(e,t,s=!1){let r=[];for(let n of t)r.push(await Le(e,n,s));return r.join("")}function zu(e){return ko(e)}function _o(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!zu(t))return!1;return!0}function Bu(e,t,s=!1){let r=No(t);if(r!==null)return r;switch(t.type){case"TildeExpansion":return s?t.user===null?"~":`~${t.user}`:(e.coverage?.hit("bash:expansion:tilde"),t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`);case"Glob":return ur(e,t.pattern);default:return null}}async function W(e,t){return dr(e,t)}async function Po(e,t){let s=[];for(let r of t.parts)if(r.type==="Escaped")s.push(`\\${r.value}`);else if(r.type==="SingleQuoted")s.push(r.value);else if(r.type==="DoubleQuoted"){let n=await Ge(e,r.parts);s.push(n)}else if(r.type==="TildeExpansion"){let n=await Le(e,r);s.push(rs(n))}else s.push(await Le(e,r));return s.join("")}async function Do(e,t){let s=[];for(let r of t.parts)if(r.type==="Escaped"){let n=r.value;"()|*?[]".includes(n)?s.push(`\\${n}`):s.push(n)}else if(r.type==="SingleQuoted")s.push(Te(r.value));else if(r.type==="DoubleQuoted"){let n=await Ge(e,r.parts);s.push(Te(n))}else s.push(await Le(e,r));return s.join("")}async function Io(e,t){let s=[];for(let r of t.parts)if(r.type==="SingleQuoted")s.push(Te(r.value));else if(r.type==="Escaped"){let n=r.value;"*?[]\\()|".includes(n)?s.push(`\\${n}`):s.push(n)}else if(r.type==="DoubleQuoted"){let n=await Ge(e,r.parts);s.push(Te(n))}else r.type==="Glob"?Ba(r.pattern)?s.push(await Ua(e,r.pattern)):s.push(ur(e,r.pattern)):r.type==="Literal"?s.push(r.value):s.push(await Le(e,r));return s.join("")}function Fs(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&Fs(t.parts))return!0;return!1}var fr=1e5;async function Co(e,t,s={count:0}){if(s.count>fr)return[[]];let r=[[]];for(let n of t)if(n.type==="BraceExpansion"){let i=[],a=!1,l="";for(let c of n.items)if(c.type==="Range"){let f=lr(c.start,c.end,c.step,c.startStr,c.endStr);if(f.expanded)for(let d of f.expanded)s.count++,i.push(d);else{a=!0,l=f.literal;break}}else{let f=await Co(e,c.word.parts,s);for(let d of f){s.count++;let h=[];for(let p of d)typeof p=="string"?h.push(p):h.push(await Le(e,p));i.push(h.join(""))}}if(a){for(let c of r)s.count++,c.push(l);continue}if(r.length*i.length>e.limits.maxBraceExpansionResults||s.count>fr)return r;let u=[];for(let c of r)for(let f of i){if(s.count++,s.count>fr)return u.length>0?u:r;u.push([...c,f])}r=u}else for(let i of r)s.count++,i.push(n);return r}async function Ro(e,t){let s=t.parts;if(!Fs(s))return[await W(e,t)];let r=await Co(e,s),n=[];for(let i of r){let a=[];for(let l of i)typeof l=="string"?a.push(l):a.push(await Le(e,l));n.push(Za(e,a.join("")))}return n}function qu(){return{expandWordAsync:dr,expandWordForGlobbing:Io,expandWordWithBracesAsync:Ro,expandWordPartsAsync:Ge,expandPart:Le,expandParameterAsync:Ms,hasBraceExpansion:Fs,evaluateArithmetic:T,buildIfsCharClassPattern:ba,smartWordSplit:$o}}async function tt(e,t){return vo(e,t,qu())}function Uu(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Vs(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function r(n){for(let i of n)if(i.type==="DoubleQuoted"){for(let a of i.parts)if(a.type==="ParameterExpansion"&&a.parameter==="@"&&!a.operation)return!0}return!1}return r(t.parts)}async function zs(e,t){if(Vs(e,t))return{error:`bash: $@: ambiguous redirect
76
+ `};let s=t.parts,{hasQuoted:r}=ns(s);if(Fs(s)&&(await Ro(e,t)).length>1)return{error:`bash: ${s.map(h=>h.type==="Literal"?h.value:h.type==="BraceExpansion"?`{${h.items.map(m=>{if(m.type==="Range"){let y=m.step?`..${m.step}`:"";return`${m.startStr??m.start}..${m.endStr??m.end}${y}`}return m.word.parts.map(y=>y.type==="Literal"?y.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect
77
+ `};let n=await dr(e,t),{hasParamExpansion:i,hasCommandSub:a}=ns(s);if((i||a)&&!r&&!Ee(e.state.env)){let f=he(e.state.env);if(se(n,f).length>1)return{error:`bash: $${Uu(s)}: ambiguous redirect
78
+ `}}if(r||e.state.options.noglob)return{target:n};let o=await Io(e,t);if(!Je(o,e.state.shoptOptions.extglob))return{target:n};let u=new gt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),c=await u.expand(o);return c.length===0?u.hasFailglob()?{error:`bash: no match: ${n}
79
+ `}:{target:n}:c.length===1?{target:c[0]}:{error:`bash: ${n}: ambiguous redirect
80
+ `}}async function dr(e,t){let s=t.parts,r=s.length;if(r===1){let a=await Le(e,s[0]);return Et(a,e.limits.maxStringLength,"word expansion"),a}let n=[];for(let a=0;a<r;a++)n.push(await Le(e,s[a]));let i=n.join("");return Et(i,e.limits.maxStringLength,"word expansion"),i}async function Le(e,t,s=!1){if(t.type==="ParameterExpansion")return Ms(e,t,s);let r=Bu(e,t,s);if(r!==null)return r;switch(t.type){case"DoubleQuoted":{let n=[];for(let i of t.parts)n.push(await Le(e,i,!0));return n.join("")}case"CommandSubstitution":{let n=_a(t.body);if(n)try{let d=await W(e,n.target),h=d.startsWith("/")?d:`${e.state.cwd}/${d}`,p=await e.fs.readFile(h);e.state.lastExitCode=0,e.state.env.set("?","0");let m=p.replace(/\n+$/,"");return Et(m,e.limits.maxStringLength,"command substitution"),m}catch(d){if(d instanceof Q)throw d;return e.state.lastExitCode=1,e.state.env.set("?","1"),""}let i=e.substitutionDepth??0,a=e.limits.maxSubstitutionDepth;if(i>=a)throw new Q(`Command substitution nesting limit exceeded (${a})`,"substitution_depth");let l=e.substitutionDepth;e.substitutionDepth=i+1;let o=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let u=new Map(e.state.env),c=e.state.cwd,f=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let d=await e.executeScript(t.body),h=d.exitCode;e.state.env=u,e.state.cwd=c,e.state.suppressVerbose=f,e.state.lastExitCode=h,e.state.env.set("?",String(h)),d.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+d.stderr),e.state.bashPid=o,e.substitutionDepth=l;let p=d.stdout.replace(/\n+$/,"");return Et(p,e.limits.maxStringLength,"command substitution"),p}catch(d){if(e.state.env=u,e.state.cwd=c,e.state.bashPid=o,e.substitutionDepth=l,e.state.suppressVerbose=f,d instanceof Q)throw d;if(d instanceof U){e.state.lastExitCode=d.exitCode,e.state.env.set("?",String(d.exitCode)),d.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+d.stderr);let h=d.stdout.replace(/\n+$/,"");return Et(h,e.limits.maxStringLength,"command substitution"),h}throw d}}case"ArithmeticExpansion":{let n=t.expression.originalText;if(n&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(n)){let a=await ka(e,n),l=new V,o=X(l,a);return String(await T(e,o.expression,!0))}return String(await T(e,t.expression.expression,!0))}case"BraceExpansion":{let n=[];for(let i of t.items)if(i.type==="Range"){let a=lr(i.start,i.end,i.step,i.startStr,i.endStr);if(a.expanded)n.push(...a.expanded);else return a.literal}else n.push(await W(e,i.word));return n.join(" ")}default:return""}}async function Ms(e,t,s=!1){let{parameter:r}=t,{operation:n}=t,i=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(i){let[,d,h]=i;if(e.state.associativeArrays?.has(d)||h.includes("$(")||h.includes("`")||h.includes("${")){let m=await or(e,h);r=`${d}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ee(e,r)){let d=Se(e,r);if(d&&d!==r){let h=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(h){let[,p,m]=h;if(e.state.associativeArrays?.has(p)||m.includes("$(")||m.includes("`")||m.includes("${")){let b=await or(e,m);r=`${p}[${b}]`}}}}let a=n&&(n.type==="DefaultValue"||n.type==="AssignDefault"||n.type==="UseAlternative"||n.type==="ErrorIfUnset"),l=await Y(e,r,!a);if(!n)return l;let o=!await Ye(e,r),{isEmpty:u,effectiveValue:c}=za(e,r,l,s),f={value:l,isUnset:o,isEmpty:u,effectiveValue:c,inDoubleQuotes:s};switch(n.type){case"DefaultValue":return Pa(e,n,f,Ge);case"AssignDefault":return Da(e,r,n,f,Ge);case"ErrorIfUnset":return Ia(e,r,n,f,Ge);case"UseAlternative":return Ca(e,n,f,Ge);case"PatternRemoval":{let d=await Ra(e,l,n,Ge,Le);return Et(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await xa(e,l,n,Ge,Le);return Et(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return Oa(e,r,l);case"LengthSliceError":throw new xe(r);case"BadSubstitution":throw new xe(n.text);case"Substring":return Ta(e,r,l,n);case"CaseModification":{let d=await La(e,l,n,Ge,Ms);return Et(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return Wa(e,r,l,o,n);case"Indirection":return Ma(e,r,l,o,n,Ms,s);case"ArrayKeys":return Fa(e,n);case"VarNamePrefix":return Va(e,n);default:return l}}function Zu(e,t,s){switch(s){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new te("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new te("division by 0");return e%t;case"**":if(t<0)throw new te("exponent less than 0");return e**t;case"<<":return e<<t;case">>":return e>>t;case"<":return e<t?1:0;case"<=":return e<=t?1:0;case">":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function xo(e,t,s){switch(s){case"=":return t;case"+=":return e+t;case"-=":return e-t;case"*=":return e*t;case"/=":return t!==0?Math.trunc(e/t):0;case"%=":return t!==0?e%t:0;case"<<=":return e<<t;case">>=":return e>>t;case"&=":return e&t;case"|=":return e|t;case"^=":return e^t;default:return t}}function Hu(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function ju(e,t){let s=e.state.env.get(t);if(s!==void 0)return s;let r=e.state.env.get(`${t}_0`);return r!==void 0?r:await Y(e,t)}function Gu(e){if(!e)return 0;let t=Number.parseInt(e,10);if(!Number.isNaN(t)&&/^-?\d+$/.test(e.trim()))return t;let s=e.trim();if(!s)return 0;try{let r=new V,{expr:n,pos:i}=Oe(r,s,0);if(i<s.length){let a=s.slice(i).trim().split(/\s+/)[0];throw new te(`${s}: syntax error in expression (error token is "${a}")`)}return n.type==="ArithNumber"?n.value:t||0}catch(r){if(r instanceof te)throw r;let n=s.split(/\s+/).slice(1)[0]||s;throw new te(`${s}: syntax error in expression (error token is "${n}")`)}}async function hr(e,t){if(!t)return 0;let s=Number.parseInt(t,10);if(!Number.isNaN(s)&&/^-?\d+$/.test(t.trim()))return s;let r=t.trim();if(!r)return 0;let n=new V,{expr:i,pos:a}=Oe(n,r,0);if(a<r.length){let l=r.slice(a).trim(),o=l.split(/\s+/)[0]||l;throw new te(`syntax error in expression (error token is "${o}")`,"","")}return await T(e,i)}async function pr(e,t,s=new Set,r=0){if(r>100)throw new te("maximum variable indirection depth exceeded");if(s.has(t))return 0;s.add(t);let n=await ju(e,t);if(!n)return 0;let i=Number.parseInt(n,10);if(!Number.isNaN(i)&&/^-?\d+$/.test(n.trim()))return i;let a=n.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return await pr(e,a,s,r+1);let l=new V,{expr:o,pos:u}=Oe(l,a,0);if(u<a.length){let c=a.slice(u).trim(),f=c.split(/\s+/)[0]||c;throw new te(`${a}: syntax error in expression (error token is "${f}")`)}return await T(e,o)}async function Bs(e,t){if(t.startsWith("#")){let f=t.slice(1),d=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(d){let p=d[1],m=F(e,p);return String(m.length)}let h=e.state.env.get(f)||"";return String(h.length)}if(t.startsWith("!")){let f=t.slice(1),d=e.state.env.get(f)||"";return e.state.env.get(d)||""}let s=[":-",":=",":?",":+","-","=","?","+"],r=-1,n="";for(let f of s){let d=t.indexOf(f);d>0&&(r===-1||d<r)&&(r=d,n=f)}if(r===-1)return await Y(e,t);let i=t.slice(0,r),a=t.slice(r+n.length),l=e.state.env.get(i),o=l===void 0,u=l==="",c=n.startsWith(":");switch(n){case":-":case"-":return o||c&&u?a:l||"";case":=":case"=":return o||c&&u?(e.state.env.set(i,a),a):l||"";case":+":case"+":return!(o||c&&u)?a:"";case":?":case"?":{if(o||c&&u)throw new Error(a||`${i}: parameter null or not set`);return l||""}default:return l||""}}async function T(e,t,s=!1){switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new te("value too great for base");return t.value;case"ArithVariable":return await pr(e,t.name);case"ArithSpecialVar":{let n=(await Y(e,t.name)).trim();if(!n)return 0;let i=Number.parseInt(n,10);if(!Number.isNaN(i)&&/^-?\d+$/.test(n))return i;let a=new V,{expr:l}=Oe(a,n,0);return await T(e,l)}case"ArithNested":return await T(e,t.expression);case"ArithCommandSubst":{if(e.execFn){let r=await e.execFn(t.command,{signal:e.state.signal});r.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+r.stderr);let n=r.stdout.trim();return Number.parseInt(n,10)||0}return 0}case"ArithBracedExpansion":{let r=await Bs(e,t.content);return Number.parseInt(r,10)||0}case"ArithDynamicBase":{let r=await Bs(e,t.baseExpr),n=Number.parseInt(r,10);if(n<2||n>64)return 0;let i=`${n}#${t.value}`;return es(i)}case"ArithDynamicNumber":{let n=await Bs(e,t.prefix)+t.suffix;return es(n)}case"ArithArrayElement":{let r=e.state.associativeArrays?.has(t.array),n=async i=>{let a=e.state.env.get(i);return a!==void 0?await hr(e,a):0};if(t.stringKey!==void 0)return await n(`${t.array}_${t.stringKey}`);if(r&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await n(`${t.array}_${t.index.name}`);if(r&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let i=await Y(e,t.index.name);return await n(`${t.array}_${i}`)}if(t.index){let i=await T(e,t.index,s);if(i<0){let o=F(e,t.array),u=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript
81
+ `,0;let f=Math.max(...o.map(([d])=>typeof d=="number"?d:0))+1+i;if(f<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript
82
+ `,0;i=f}let a=`${t.array}_${i}`,l=e.state.env.get(a);if(l!==void 0)return hr(e,l);if(i===0){let o=e.state.env.get(t.array);if(o!==void 0)return hr(e,o)}if(e.state.options.nounset&&!Array.from(e.state.env.keys()).some(u=>u===t.array||u.startsWith(`${t.array}_`)))throw new Re(`${t.array}[${i}]`);return 0}return 0}case"ArithDoubleSubscript":throw new te("double subscript","","");case"ArithNumberSubscript":throw new te(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new te(t.message,"","",!0);case"ArithSingleQuote":{if(s)throw new te(`syntax error: operand expected (error token is "'${t.content}'")`);return t.value}case"ArithBinary":{if(t.operator==="||")return await T(e,t.left,s)||await T(e,t.right,s)?1:0;if(t.operator==="&&")return await T(e,t.left,s)&&await T(e,t.right,s)?1:0;let r=await T(e,t.left,s),n=await T(e,t.right,s);return Zu(r,n,t.operator)}case"ArithUnary":{let r=await T(e,t.operand,s);if(t.operator==="++"||t.operator==="--"){if(t.operand.type==="ArithVariable"){let n=t.operand.name,i=Number.parseInt(await Y(e,n),10)||0,a=t.operator==="++"?i+1:i-1;return e.state.env.set(n,String(a)),t.prefix?a:i}if(t.operand.type==="ArithArrayElement"){let n=t.operand.array,i=e.state.associativeArrays?.has(n),a;if(t.operand.stringKey!==void 0)a=`${n}_${t.operand.stringKey}`;else if(i&&t.operand.index?.type==="ArithVariable"&&!t.operand.index.hasDollarPrefix)a=`${n}_${t.operand.index.name}`;else if(i&&t.operand.index?.type==="ArithVariable"&&t.operand.index.hasDollarPrefix){let u=await Y(e,t.operand.index.name);a=`${n}_${u}`}else if(t.operand.index){let u=await T(e,t.operand.index,s);a=`${n}_${u}`}else return r;let l=Number.parseInt(e.state.env.get(a)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(a,String(o)),t.prefix?o:l}if(t.operand.type==="ArithConcat"){let n="";for(let i of t.operand.parts)n+=await zt(e,i,s);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let i=Number.parseInt(e.state.env.get(n)||"0",10)||0,a=t.operator==="++"?i+1:i-1;return e.state.env.set(n,String(a)),t.prefix?a:i}}if(t.operand.type==="ArithDynamicElement"){let n="";if(t.operand.nameExpr.type==="ArithConcat")for(let i of t.operand.nameExpr.parts)n+=await zt(e,i,s);else t.operand.nameExpr.type==="ArithVariable"&&(n=t.operand.nameExpr.hasDollarPrefix?await Y(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let i=await T(e,t.operand.subscript,s),a=`${n}_${i}`,l=Number.parseInt(e.state.env.get(a)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(a,String(o)),t.prefix?o:l}}return r}return Hu(r,t.operator)}case"ArithTernary":return await T(e,t.condition,s)?await T(e,t.consequent,s):await T(e,t.alternate,s);case"ArithAssignment":{let r=t.variable,n=r;if(t.stringKey!==void 0)n=`${r}_${t.stringKey}`;else if(t.subscript){let o=e.state.associativeArrays?.has(r);if(o&&t.subscript.type==="ArithVariable"&&!t.subscript.hasDollarPrefix)n=`${r}_${t.subscript.name}`;else if(o&&t.subscript.type==="ArithVariable"&&t.subscript.hasDollarPrefix){let u=await Y(e,t.subscript.name);n=`${r}_${u||"\\"}`}else if(o){let u=await T(e,t.subscript,s);n=`${r}_${u}`}else{let u=await T(e,t.subscript,s);if(u<0){let c=F(e,r);c.length>0&&(u=Math.max(...c.map(([d])=>typeof d=="number"?d:0))+1+u)}n=`${r}_${u}`}}let i=Number.parseInt(e.state.env.get(n)||"0",10)||0,a=await T(e,t.value,s),l=xo(i,a,t.operator);return e.state.env.set(n,String(l)),l}case"ArithGroup":return await T(e,t.expression,s);case"ArithConcat":{let r="";for(let n of t.parts)r+=await zt(e,n,s);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)?await pr(e,r):Number.parseInt(r,10)||0}case"ArithDynamicAssignment":{let r="";if(t.target.type==="ArithConcat")for(let o of t.target.parts)r+=await zt(e,o,s);else t.target.type==="ArithVariable"&&(r=t.target.hasDollarPrefix?await Y(e,t.target.name):t.target.name);if(!r||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r))return 0;let n=r;if(t.subscript){let o=await T(e,t.subscript,s);n=`${r}_${o}`}let i=Number.parseInt(e.state.env.get(n)||"0",10)||0,a=await T(e,t.value,s),l=xo(i,a,t.operator);return e.state.env.set(n,String(l)),l}case"ArithDynamicElement":{let r="";if(t.nameExpr.type==="ArithConcat")for(let l of t.nameExpr.parts)r+=await zt(e,l,s);else t.nameExpr.type==="ArithVariable"&&(r=t.nameExpr.hasDollarPrefix?await Y(e,t.nameExpr.name):t.nameExpr.name);if(!r||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r))return 0;let n=await T(e,t.subscript,s),i=`${r}_${n}`,a=e.state.env.get(i);return a!==void 0?Gu(a):0}default:return 0}}async function zt(e,t,s=!1){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await T(e,t,s));case"ArithVariable":return t.hasDollarPrefix?await Y(e,t.name):t.name;case"ArithSpecialVar":return await Y(e,t.name);case"ArithBracedExpansion":return await Bs(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command,{signal:e.state.signal})).stdout.trim():"0";case"ArithConcat":{let r="";for(let n of t.parts)r+=await zt(e,n,s);return r}default:return String(await T(e,t,s))}}async function Oo(e,t){let s=t.parts.map(c=>c.type==="Literal"?c.value:"\0").join(""),r=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!r||!s.endsWith(")"))return null;let n=r[1],i=[],a=!1,l="",o=!1;for(let c of t.parts)if(c.type==="Literal"){let f=c.value;if(!a){let d=f.indexOf("=(");d!==-1&&(a=!0,f=f.slice(d+2))}if(a){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(l||o)&&(i.push(l),l="",o=!1):h&&(l+=h)}}else if(a)if(c.type==="BraceExpansion")if(/^\[.+\]=/.test(l))l+=Ft({type:"Word",parts:[c]});else{(l||o)&&(i.push(l),l="",o=!1);let d=await tt(e,{type:"Word",parts:[c]});i.push(...d.values)}else{(c.type==="SingleQuoted"||c.type==="DoubleQuoted"||c.type==="Escaped")&&(o=!0);let f=await W(e,{type:"Word",parts:[c]});l+=f}(l||o)&&i.push(l);let u=i.map(c=>/^\[.+\]=/.test(c)?c:c===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(c)&&!c.startsWith("'")&&!c.startsWith('"')?`'${c.replace(/'/g,"'\\''")}'`:c);return`${n}=(${u.join(" ")})`}async function To(e,t){let s=-1,r=-1,n=!1;for(let m=0;m<t.parts.length;m++){let y=t.parts[m];if(y.type==="Literal"){let b=y.value.indexOf("+=");if(b!==-1){let E=y.value.slice(0,b);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(E)){s=m,r=b,n=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(E)){s=m,r=b,n=!0;break}}let v=y.value.indexOf("=");if(v!==-1&&(v===0||y.value[v-1]!=="+")){let E=y.value.slice(0,v);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(E)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(E)){s=m,r=v;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),a=t.parts[s];if(a.type!=="Literal")return null;let l=n?2:1,o=a.value.slice(0,r),u=a.value.slice(r+l),c=t.parts.slice(s+1),f="";for(let m of i)f+=await W(e,{type:"Word",parts:[m]});f+=o;let d={type:"Word",parts:u!==""?[{type:"Literal",value:u},...c]:c},h=d.parts.length>0?await W(e,d):"";return`${f}${n?"+=":"="}${h}`}var Qu=["tar","yq","xan","sqlite3","python3","python"];function Lo(e){return Qu.includes(e)}var G=Object.freeze({stdout:"",stderr:"",exitCode:0});function H(e=""){return{stdout:e,stderr:"",exitCode:0}}function _(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function P(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function de(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function st(e,t,s="",r=""){throw new Q(e,t,s,r)}function ve(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new Q(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function mr(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new ft;return G}if(t.length>1)throw new U(1,"",`bash: break: too many arguments
83
+ `);let s=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new U(128,"",`bash: break: ${t[0]}: numeric argument required
84
+ `);s=r}throw new Ie(s)}async function gr(e,t){let s,r=!1,n=!1,i=0;for(;i<t.length;)if(t[i]==="--"){i++;break}else if(t[i]==="-L")n=!1,i++;else if(t[i]==="-P")n=!0,i++;else if(t[i].startsWith("-")&&t[i]!=="-")i++;else break;let a=t.slice(i);if(a.length===0||a[0]==="~"?s=e.state.env.get("HOME")||"/":a[0]==="-"?(s=e.state.previousDir,r=!0):s=a[0],!s.startsWith("/")&&!s.startsWith("./")&&!s.startsWith("../")&&s!=="."&&s!==".."){let f=e.state.env.get("CDPATH");if(f){let d=f.split(":").filter(h=>h);for(let h of d){let p=h.startsWith("/")?`${h}/${s}`:`${e.state.cwd}/${h}/${s}`;try{if((await e.fs.stat(p)).isDirectory){s=p,r=!0;break}}catch{}}}}let o=(s.startsWith("/")?s:`${e.state.cwd}/${s}`).split("/").filter(f=>f&&f!=="."),u="";for(let f of o)if(f==="..")u=u.split("/").slice(0,-1).join("/")||"/";else{u=u?`${u}/${f}`:`/${f}`;try{if(!(await e.fs.stat(u)).isDirectory)return _(`bash: cd: ${s}: Not a directory
8
85
  `)}catch{return _(`bash: cd: ${s}: No such file or directory
9
- `)}}let u=c||"/";if(r)try{u=await e.fs.realpath(u)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=u,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),F(n?`${u}
10
- `:"")}function Fs(e,t){return e.fs.resolvePath(e.state.cwd,t)}var ua=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function Bt(e){return ua.includes(e)}async function jt(e,t,s){let n=Fs(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"].includes(n);case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(n);default:return!1}}var fa=["-nt","-ot","-ef"];function Ht(e){return fa.includes(e)}async function Ut(e,t,s,n){let r=Fs(e,s),i=Fs(e,n);switch(t){case"-nt":try{let a=await e.fs.stat(r),o=await e.fs.stat(i);return a.mtime>o.mtime}catch{return!1}case"-ot":try{let a=await e.fs.stat(r),o=await e.fs.stat(i);return a.mtime<o.mtime}catch{return!1}case"-ef":try{if(!await e.fs.exists(r)||!await e.fs.exists(i))return!1;let a=e.fs.resolvePath(e.state.cwd,r),o=e.fs.resolvePath(e.state.cwd,i);return a===o}catch{return!1}default:return!1}}var da=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function Zt(e){return da.has(e)}function qt(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 vt(e){return e==="="||e==="=="||e==="!="}function Gt(e,t,s,n=!1,r=!1,i=!1){if(n){let o=ot(t,s,r,i);return e==="!="?!o:o}if(r){let o=t.toLowerCase()===s.toLowerCase();return e==="!="?!o:o}let a=t===s;return e==="!="?!a:a}var ha=new Set(["-z","-n"]);function Kt(e){return ha.has(e)}function Xt(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Yt(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],r=s[2];if(e.state.associativeArrays?.has(n)){let o=r;return(o.startsWith("'")&&o.endsWith("'")||o.startsWith('"')&&o.endsWith('"'))&&(o=o.slice(1,-1)),o=o.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(l,c)=>e.state.env.get(c)||""),e.state.env.has(`${n}_${o}`)}let a;try{let o=new V,l=Q(o,r);a=await j(e,l.expression)}catch{if(/^-?\d+$/.test(r))a=Number.parseInt(r,10);else{let o=e.state.env.get(r);a=o?Number.parseInt(o,10):0}}if(a<0){let o=ne(e,n),l=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${n}: bad array subscript
11
- `,!1;if(a=Math.max(...o)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${n}: bad array subscript
12
- `,!1}return e.state.env.has(`${n}_${a}`)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?Me(e,t).length>0:ne(e,t).length>0}async function ze(e,t){switch(t.type){case"CondBinary":{let s=await I(e,t.left),n=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),r;if(t.operator==="=~")if(n){let i=await I(e,t.right);r=Kn(i)}else r=await Yn(e,t.right);else vt(t.operator)&&!n?r=await Qn(e,t.right):r=await I(e,t.right);if(vt(t.operator)){let i=e.state.shoptOptions.nocasematch;return Gt(t.operator,s,r,!n,i,!0)}if(Zt(t.operator))return qt(t.operator,await gr(e,s),await gr(e,r));if(Ht(t.operator))return Ut(e,t.operator,s,r);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=ga(r),l=mt(a,i?"i":"").match(s);if(Ce(e,"BASH_REMATCH"),l)for(let c=0;c<l.length;c++)e.state.env.set(`BASH_REMATCH_${c}`,l[c]||"");return l!==null}catch{throw new Error("syntax error in regular expression")}case"<":return s<r;case">":return s>r;default:return!1}}case"CondUnary":{let s=await I(e,t.operand);return Bt(t.operator)?jt(e,t.operator,s):Kt(t.operator)?Xt(t.operator,s):t.operator==="-v"?await Yt(e,s):t.operator==="-o"?Ws(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await I(e,t.operand.expression.word)})`!=="":!await ze(e,t.operand);case"CondAnd":return await ze(e,t.left)?await ze(e,t.right):!1;case"CondOr":return await ze(e,t.left)?!0:await ze(e,t.right);case"CondGroup":return await ze(e,t.expression);case"CondWord":return await I(e,t.word)!=="";default:return!1}}async function bt(e,t){if(t.length===0)return k("","",1);if(t.length===1)return X(!!t[0]);if(t.length===2){let n=t[0],r=t[1];return n==="("?_(`test: '(' without matching ')'
13
- `,2):Bt(n)?X(await jt(e,n,r)):Kt(n)?X(Xt(n,r)):n==="!"?X(!r):n==="-v"?X(await Yt(e,r)):n==="-o"?X(Ws(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"?_(`test: ${n}: unary operator expected
14
- `,2):k("","",1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(vt(r))return X(Gt(r,n,i));if(Zt(r)){let a=Qt(n),o=Qt(i);return!a.valid||!o.valid?k("","",2):X(qt(r,a.value,o.value))}if(Ht(r))return X(await Ut(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 a=await bt(e,[r,i]);return k("",a.stderr,a.exitCode===0?1:a.exitCode===1?0:a.exitCode)}if(n==="("&&i===")")return X(r!=="")}if(t.length===4){if(t[0]==="!"){let n=await bt(e,t.slice(1));return k("",n.stderr,n.exitCode===0?1:n.exitCode===1?0:n.exitCode)}if(t[0]==="("&&t[3]===")")return bt(e,[t[1],t[2]])}let s=await vr(e,t,0);return s.pos<t.length?_(`test: too many arguments
15
- `,2):X(s.value)}async function vr(e,t,s){return pa(e,t,s)}async function pa(e,t,s){let{value:n,pos:r}=await yr(e,t,s);for(;t[r]==="-o";){let i=await yr(e,t,r+1);n=n||i.value,r=i.pos}return{value:n,pos:r}}async function yr(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 ma(e,t,s)}async function ma(e,t,s){let n=t[s];if(n==="("){let{value:i,pos:a}=await vr(e,t,s+1);return{value:i,pos:t[a]===")"?a+1:a}}let r=t[s+1];if(vt(r)){let i=n,a=t[s+2]??"";return{value:Gt(r,i,a),pos:s+3}}if(Zt(r)){let i=Qt(n),a=Qt(t[s+2]??"0");return!i.valid||!a.valid?{value:!1,pos:s+3}:{value:qt(r,i.value,a.value),pos:s+3}}if(Ht(r)){let i=n,a=t[s+2]??"";return{value:await Ut(e,r,i,a),pos:s+3}}if(Bt(n)){let i=t[s+1]??"";return{value:await jt(e,n,i),pos:s+2}}if(Kt(n)){let i=t[s+1]??"";return{value:Xt(n,i),pos:s+2}}if(n==="-v"){let i=t[s+1]??"";return{value:await Yt(e,i),pos:s+2}}if(n==="-o"){let i=t[s+1]??"";return{value:Ws(e,i),pos:s+2}}return{value:n!==void 0&&n!=="",pos:s+1}}function ot(e,t,s=!1,n=!1){let r=`^${br(t,n)}$`;return mt(r,s?"is":"s").test(e)}function br(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=$r(e,n+1);if(i!==-1){let a=e.slice(n+2,i),o=Er(a),l=o.map(u=>br(u,t)),c=l.length>0?l.join("|"):"(?:)";if(r==="@")s+=`(?:${c})`;else if(r==="*")s+=`(?:${c})*`;else if(r==="+")s+=`(?:${c})+`;else if(r==="?")s+=`(?:${c})?`;else if(r==="!")if(i<e.length-1){let f=o.map(h=>Sr(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 y=[];h>0&&y.push(`.{0,${h-1}}`),y.push(`.{${h+1},}`),y.push(`(?!(?:${c})).{${h}}`),s+=`(?:${y.join("|")})`}}else s+=`(?:(?!(?:${c})).)*?`}else s+=`(?!(?:${c})$).*`;n=i;continue}}if(r==="\\")if(n+1<e.length){let i=e[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,n++}else s+="\\\\";else if(r==="*")s+=".*";else if(r==="?")s+=".";else if(r==="["){let i=e.indexOf("]",n+1);i!==-1?(s+=e.slice(n,i+1),n=i):s+="\\["}else/[\\^$.|+(){}]/.test(r)?s+=`\\${r}`:s+=r}return s}function $r(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 Er(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 Sr(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=$r(e,n+1);if(i!==-1){if(r==="@"){let a=e.slice(n+2,i),l=Er(a).map(c=>Sr(c,t));if(l.every(c=>c!==null)&&l.every(c=>c===l[0])){s+=l[0],n=i+1;continue}return null}return null}}if(r==="*")return null;if(r==="?"){s+=1,n++;continue}if(r==="["){let i=e.indexOf("]",n+1);if(i!==-1){s+=1,n=i+1;continue}s+=1,n++;continue}if(r==="\\"){s+=1,n+=2;continue}s+=1,n++}return s}function Ws(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 gr(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 wr(t);try{let s=new V,n=Q(s,t);return await j(e,n.expression)}catch{return wr(t)}}function ya(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 wr(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=ya(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 Qt(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 ga(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=wa(e,s);t+=n.converted,s=n.endIndex}else t+=e[s],s++;return t}function wa(e,t){let s=t+1,n="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(n+="^",s++);let r=!1;s<e.length&&e[s]==="]"&&(r=!0,s++);let i=!1;s<e.length&&e[s]==="["&&s+1<e.length&&e[s+1]!==":"&&(i=!0,s++);let a="",o=!1;for(;s<e.length;){let l=e[s];if(l==="]"){o=!0,s++;break}if(l==="["&&s+1<e.length&&e[s+1]===":"){let c=e.indexOf(":]",s+2);if(c!==-1){let u=e.slice(s+2,c);a+=va(u),s=c+2;continue}}if(l==="["&&s+1<e.length){let c=e[s+1];if(c==="."||c==="="){let u=`${c}]`,f=e.indexOf(u,s+2);if(f!==-1){let d=e.slice(s+2,f);a+=d,s=f+2;continue}}}if(l==="\\"&&s+1<e.length){a+=l+e[s+1],s+=2;continue}a+=l,s++}return o?(r&&(n+="\\]"),i&&(n+="\\["),n+=a,n+="]",{converted:n,endIndex:s}):{converted:"\\[",endIndex:t+1}}function va(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 Ne(e){let t=[],s="",n=!1,r=!1,i=!1,a=!1;for(let o of e){if(i){s+=o,i=!1,a=!0;continue}if(o==="\\"){i=!0;continue}if(o==="'"&&!r){n||(a=!0),n=!n;continue}if(o==='"'&&!n){r||(a=!0),r=!r;continue}if((o===" "||o===" "||o===`
16
- `)&&!n&&!r){a&&(t.push(s),s="",a=!1);continue}s+=o,a=!0}return a&&t.push(s),t}function Jt(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 Ar(e){let t=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(t)return{name:t[1],isArray:!0,arrayElements:Ne(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 ba(e,t){try{let s=new V,n=Q(s,t);return await j(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}async function _r(e,t,s={}){let{name:n,isArray:r,arrayElements:i,value:a,arrayIndex:o}=t,{makeReadonly:l=!1,checkReadonly:c=!0}=s;if(c){let u=ee(e,n);if(u)return u}if(r&&i){for(let u=0;u<i.length;u++)e.state.env.set(`${n}_${u}`,i[u]);e.state.env.set(`${n}__length`,String(i.length))}else if(o!==void 0&&a!==void 0){let u=await ba(e,o);e.state.env.set(`${n}_${u}`,a);let f=parseInt(e.state.env.get(`${n}__length`)??"0",10);u>=f&&e.state.env.set(`${n}__length`,String(u+1))}else a!==void 0&&e.state.env.set(n,a);return l&&ue(e,n),null}function Ve(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function lt(e,t){return e.state.localVarDepth?.get(t)}function es(e,t){e.state.localVarDepth?.delete(t)}function Cr(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 ts(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function kr(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 zs=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Pr(e){return zs.has(e)}var Vs=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),ct=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 Ge(e,t,s,n){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory
17
- `;if(n.checkNoclobber&&e.state.options.noclobber&&!n.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file
18
- `}catch{}return null}function Be(e){let s=Math.min(e.length,8192);for(let n=0;n<s;n++)if(e.charCodeAt(n)>127)return"utf8";return"binary"}function $a(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),a=r+n+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let c=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let u=o.slice(l+1);return{path:i,position:c,content:u}}async function Nr(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(ks(e,r.target))return{targets:s,error:`bash: $@: ambiguous redirect
19
- `};s.set(n,await I(e,r.target))}else{let a=await Mt(e,r.target);if("error"in a)return{targets:s,error:a.error};s.set(n,a.target)}}return{targets:s}}function Ea(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd,s=e.limits.maxFileDescriptors;if(t>=s)throw new Error(`bash: cannot allocate file descriptor: too many open files (max ${s})`);return e.state.nextFd++,t}async function ss(e,t){for(let s of t){if(!s.fdVariable)continue;if(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),(s.operator===">&"||s.operator==="<&")&&s.target.type==="Word"&&await I(e,s.target)==="-"){let i=e.state.env.get(s.fdVariable);if(i!==void 0){let a=Number.parseInt(i,10);Number.isNaN(a)||e.state.fileDescriptors.delete(a)}continue}let n=Ea(e);if(e.state.env.set(s.fdVariable,String(n)),s.target.type==="Word"){let r=await I(e,s.target);if(s.operator===">&"||s.operator==="<&"){let i=Number.parseInt(r,10);if(!Number.isNaN(i)){let a=e.state.fileDescriptors.get(i);a!==void 0&&(ae(e),e.state.fileDescriptors.set(n,a));continue}}if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let i=e.fs.resolvePath(e.state.cwd,r);(s.operator===">"||s.operator===">|"||s.operator==="&>")&&await e.fs.writeFile(i,"","binary"),ae(e),e.state.fileDescriptors.set(n,`__file__:${i}`)}else if(s.operator==="<<<")ae(e),e.state.fileDescriptors.set(n,`${r}
20
- `);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,r),a=await e.fs.readFile(i);ae(e),e.state.fileDescriptors.set(n,a)}catch{return k("",`bash: ${r}: No such file or directory
21
- `,1)}}}return null}async function Oe(e,t){for(let s of t){if(s.target.type==="HereDoc")continue;let n=s.operator===">&";if(s.operator!==">"&&s.operator!==">|"&&s.operator!=="&>"&&!n)continue;let r;if(n){if(r=await I(e,s.target),r==="-"||!Number.isNaN(Number.parseInt(r,10))||s.fd!=null)continue}else{let o=await Mt(e,s.target);if("error"in o)return k("",o.error,1);r=o.target}let i=e.fs.resolvePath(e.state.cwd,r),a=s.operator===">|";if(i.includes("\0"))return k("",`bash: ${r}: No such file or directory
22
- `,1);try{let o=await e.fs.stat(i);if(o.isDirectory)return k("",`bash: ${r}: Is a directory
23
- `,1);if(e.state.options.noclobber&&!a&&!o.isDirectory&&r!=="/dev/null")return k("",`bash: ${r}: cannot overwrite existing file
24
- `,1)}catch{}if(r!=="/dev/null"&&r!=="/dev/stdout"&&r!=="/dev/stderr"&&r!=="/dev/full"&&await e.fs.writeFile(i,"","binary"),r==="/dev/full")return k("",`bash: /dev/full: No space left on device
25
- `,1)}return null}async function q(e,t,s,n){let{stdout:r,stderr:i,exitCode:a}=t,l=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",c=h=>l;for(let h=0;h<s.length;h++){let y=s[h];if(y.target.type==="HereDoc")continue;let p,w=n?.get(h);if(w!==void 0)p=w;else if(y.operator===">&"||y.operator==="<&"){if(ks(e,y.target)){i+=`bash: $@: ambiguous redirect
26
- `,a=1,r="";continue}p=await I(e,y.target)}else{let g=await Mt(e,y.target);if("error"in g){i+=g.error,a=1,r="";continue}p=g.target}if(!y.fdVariable){if(p.includes("\0")){i+=`bash: ${p.replace(/\0/g,"")}: No such file or directory
27
- `,a=1,r="";continue}switch(y.operator){case">":case">|":{let $=y.fd??1,g=y.operator===">|";if($===1){if(p==="/dev/stdout")break;if(p==="/dev/stderr"){i+=r,r="";break}if(p==="/dev/full"){i+=`bash: echo: write error: No space left on device
28
- `,a=1,r="";break}let b=e.fs.resolvePath(e.state.cwd,p),m=await Ge(e,b,p,{checkNoclobber:!0,isClobber:g});if(m){i+=m,a=1,r="";break}await e.fs.writeFile(b,r,c(r)),r=""}else if($===2){if(p==="/dev/stderr")break;if(p==="/dev/stdout"){r+=i,i="";break}if(p==="/dev/full"){i+=`bash: echo: write error: No space left on device
29
- `,a=1;break}if(p==="/dev/null")i="";else{let b=e.fs.resolvePath(e.state.cwd,p),m=await Ge(e,b,p,{checkNoclobber:!0,isClobber:g});if(m){i+=m,a=1;break}await e.fs.writeFile(b,i,Be(i)),i=""}}break}case">>":{let $=y.fd??1;if($===1){if(p==="/dev/stdout")break;if(p==="/dev/stderr"){i+=r,r="";break}if(p==="/dev/full"){i+=`bash: echo: write error: No space left on device
30
- `,a=1,r="";break}let g=e.fs.resolvePath(e.state.cwd,p),b=await Ge(e,g,p,{});if(b){i+=b,a=1,r="";break}await e.fs.appendFile(g,r,c(r)),r=""}else if($===2){if(p==="/dev/stderr")break;if(p==="/dev/stdout"){r+=i,i="";break}if(p==="/dev/full"){i+=`bash: echo: write error: No space left on device
31
- `,a=1;break}let g=e.fs.resolvePath(e.state.cwd,p),b=await Ge(e,g,p,{});if(b){i+=b,a=1;break}await e.fs.appendFile(g,i,Be(i)),i=""}break}case">&":case"<&":{let $=y.fd??1;if(p==="-")break;if(p.endsWith("-")){let g=p.slice(0,-1),b=Number.parseInt(g,10);if(!Number.isNaN(b)){let m=e.state.fileDescriptors?.get(b);m!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set($,m),b>=3&&e.state.fileDescriptors?.delete(b)):b===1||b===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set($,`__dupout__:${b}`)):b===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set($,`__dupin__:${b}`)):b>=3&&(i+=`bash: ${b}: Bad file descriptor
32
- `,a=1)}break}if(p==="2"||p==="&2")$===1&&(i+=r,r="");else if(p==="1"||p==="&1")r+=i,i="";else{let g=Number.parseInt(p,10);if(Number.isNaN(g)){if(y.operator===">&"){let b=e.fs.resolvePath(e.state.cwd,p),m=await Ge(e,b,p,{checkNoclobber:!0});if(m){i=m,a=1,r="";break}if(y.fd==null){let v=r+i;await e.fs.writeFile(b,v,c(v)),r="",i=""}else $===1?(await e.fs.writeFile(b,r,c(r)),r=""):$===2&&(await e.fs.writeFile(b,i,Be(i)),i="")}}else{let b=e.state.fileDescriptors?.get(g);if(b?.startsWith("__file__:")){let m=b.slice(9);$===1?(await e.fs.appendFile(m,r,c(r)),r=""):$===2&&(await e.fs.appendFile(m,i,Be(i)),i="")}else if(b?.startsWith("__rw__:")){let m=$a(b);m&&($===1?(await e.fs.appendFile(m.path,r,c(r)),r=""):$===2&&(await e.fs.appendFile(m.path,i,Be(i)),i=""))}else if(b?.startsWith("__dupout__:")){let m=Number.parseInt(b.slice(11),10);if(m!==1)if(m===2)$===1&&(i+=r,r="");else{let v=e.state.fileDescriptors?.get(m);if(v?.startsWith("__file__:")){let E=v.slice(9);$===1?(await e.fs.appendFile(E,r,c(r)),r=""):$===2&&(await e.fs.appendFile(E,i,Be(i)),i="")}}}else b?.startsWith("__dupin__:")?(i+=`bash: ${g}: Bad file descriptor
33
- `,a=1,r=""):g>=3&&(i+=`bash: ${g}: Bad file descriptor
34
- `,a=1,r="")}}break}case"&>":{if(p==="/dev/full"){i=`bash: echo: write error: No space left on device
35
- `,a=1,r="";break}let $=e.fs.resolvePath(e.state.cwd,p),g=await Ge(e,$,p,{checkNoclobber:!0});if(g){i=g,a=1,r="";break}let b=r+i;await e.fs.writeFile($,b,c(b)),r="",i="";break}case"&>>":{if(p==="/dev/full"){i=`bash: echo: write error: No space left on device
36
- `,a=1,r="";break}let $=e.fs.resolvePath(e.state.cwd,p),g=await Ge(e,$,p,{});if(g){i=g,a=1,r="";break}let b=r+i;await e.fs.appendFile($,b,c(b)),r="",i="";break}}}}let u=e.state.fileDescriptors?.get(1);if(u){if(u==="__dupout__:2")i+=r,r="";else if(u.startsWith("__file__:")){let h=u.slice(9);await e.fs.appendFile(h,r,c(r)),r=""}else if(u.startsWith("__file_append__:")){let h=u.slice(16);await e.fs.appendFile(h,r,c(r)),r=""}}let f=e.state.fileDescriptors?.get(2);if(f){if(f==="__dupout__:1")r+=i,i="";else if(f.startsWith("__file__:")){let h=f.slice(9);await e.fs.appendFile(h,i,Be(i)),i=""}else if(f.startsWith("__file_append__:")){let h=f.slice(16);await e.fs.appendFile(h,i,Be(i)),i=""}}let d=k(r,i,a);return t.stdoutKind&&(d.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(d.stdoutEncoding="binary"),d}function Or(e,t){if(e.state.options.posix&&zs.has(t.name)){let n=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
37
- `;throw new B(2,"",n)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),M}async function Sa(e,t){let s="";for(let n of t)if((n.operator==="<<"||n.operator==="<<-")&&n.target.type==="HereDoc"){let r=n.target,i=await I(e,r.content);r.stripTabs&&(i=i.split(`
38
- `).map(o=>o.replace(/^\t+/,"")).join(`
39
- `)),(n.fd??0)===0&&(s=i)}else if(n.operator==="<<<"&&n.target.type==="Word")s=`${await I(e,n.target)}
40
- `;else if(n.operator==="<"&&n.target.type==="Word"){let r=await I(e,n.target),i=e.fs.resolvePath(e.state.cwd,r);try{s=await e.fs.readFile(i)}catch{}}return s}async function ns(e,t,s,n="",r){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,Pe(`${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 c=0;c<s.length;c++)i.set(String(c+1),e.state.env.get(String(c+1))),e.state.env.set(String(c+1),s[c]);i.set("@",e.state.env.get("@")),i.set("#",e.state.env.get("#")),e.state.env.set("@",s.join(" ")),e.state.env.set("#",String(s.length));let a=()=>{let c=e.state.localScopes.length-1,u=e.state.localScopes.pop();if(u)for(let[f,d]of u)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);if(kr(e,c),e.state.fullyUnsetLocals)for(let[f,d]of e.state.fullyUnsetLocals.entries())d===c&&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):e.state.env.set(f,d);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},{targets:o,error:l}=await Nr(e,t.redirections);if(l)return a(),k("",l,1);try{let c=await Sa(e,t.redirections),u=n||c,f=await e.executeCommand(t.body,u);return a(),q(e,f,t.redirections,o)}catch(c){if(a(),c instanceof ce){let u=k(c.stdout,c.stderr,c.exitCode);return q(e,u,t.redirections,o)}throw c}}var Tr=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],js=[".",":","[","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"],Aa=["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"],_a=js;async function Hs(e,t){let s=[],n=null,r="",i="",a=null,o=!1,l=!1,c=!1,u=null,f=null,d=null,h=[],y=["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 m=0;m<t.length;m++){let v=t[m];if(v==="-v")s.push("variable");else if(v==="-e")s.push("export");else if(v==="-f")s.push("file");else if(v==="-d")s.push("directory");else if(v==="-k")s.push("keyword");else if(v==="-A"){if(m++,m>=t.length)return _(`compgen: -A: option requires an argument
41
- `,2);let E=t[m];if(!y.includes(E))return _(`compgen: ${E}: invalid action name
42
- `,2);s.push(E)}else if(v==="-W"){if(m++,m>=t.length)return _(`compgen: -W: option requires an argument
43
- `,2);n=t[m]}else if(v==="-P"){if(m++,m>=t.length)return _(`compgen: -P: option requires an argument
44
- `,2);r=t[m]}else if(v==="-S"){if(m++,m>=t.length)return _(`compgen: -S: option requires an argument
45
- `,2);i=t[m]}else if(v==="-o"){if(m++,m>=t.length)return _(`compgen: -o: option requires an argument
46
- `,2);let E=t[m];if(E==="plusdirs")o=!0;else if(E==="dirnames")l=!0;else if(E==="default")c=!0;else if(!(E==="filenames"||E==="nospace"||E==="bashdefault"||E==="noquote"))return _(`compgen: ${E}: invalid option name
47
- `,2)}else if(v==="-F"){if(m++,m>=t.length)return _(`compgen: -F: option requires an argument
48
- `,2);f=t[m]}else if(v==="-C"){if(m++,m>=t.length)return _(`compgen: -C: option requires an argument
49
- `,2);d=t[m]}else if(v==="-X"){if(m++,m>=t.length)return _(`compgen: -X: option requires an argument
50
- `,2);u=t[m]}else if(v==="-G"){if(m++,m>=t.length)return _(`compgen: -G: option requires an argument
51
- `,2)}else if(v==="--"){h.push(...t.slice(m+1));break}else v.startsWith("-")||h.push(v)}a=h[0]??null;let p=[];if(l){let m=await Bs(e,a);p.push(...m)}if(c){let m=await Dr(e,a);p.push(...m)}for(let m of s)if(m==="variable"){let v=Ca(e,a);p.push(...v)}else if(m==="export"){let v=ka(e,a);p.push(...v)}else if(m==="function"){let v=Pa(e,a);p.push(...v)}else if(m==="builtin"){let v=Na(a);p.push(...v)}else if(m==="keyword"){let v=Oa(a);p.push(...v)}else if(m==="alias"){let v=Da(e,a);p.push(...v)}else if(m==="shopt"){let v=Ta(a);p.push(...v)}else if(m==="helptopic"){let v=Ia(a);p.push(...v)}else if(m==="directory"){let v=await Bs(e,a);p.push(...v)}else if(m==="file"){let v=await Dr(e,a);p.push(...v)}else if(m==="user"){let v=xa(a);p.push(...v)}else if(m==="command"){let v=await Ra(e,a);p.push(...v)}if(n!==null)try{let m=await La(e,n),v=Fa(e,m);for(let E of v)(a===null||E.startsWith(a))&&p.push(E)}catch{return k("","",1)}if(o){let m=await Bs(e,a);for(let v of m)p.includes(v)||p.push(v)}let w="";if(f!==null){let m=e.state.functions.get(f);if(m){let v=new Map;v.set("COMP_WORDS__length",e.state.env.get("COMP_WORDS__length")),e.state.env.set("COMP_WORDS__length","0"),v.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),v.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),v.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let E=new Map;for(let O of e.state.env.keys())(O==="COMPREPLY"||O.startsWith("COMPREPLY_")||O==="COMPREPLY__length")&&(E.set(O,e.state.env.get(O)),e.state.env.delete(O));let S=["compgen",h[0]??"",""];try{let O=await ns(e,m,S,"");if(O.exitCode!==0)return ut(e,v),ut(e,E),k("",O.stderr,1);w=O.stdout;let N=Ma(e);p.push(...N)}catch{return ut(e,v),ut(e,E),k("","",1)}ut(e,v),ut(e,E)}}if(d!==null)try{let m=Ee(d),v=await e.executeScript(m);if(v.exitCode!==0)return k("",v.stderr,v.exitCode);if(v.stdout){let E=v.stdout.split(`
52
- `);for(let S of E)S.length>0&&p.push(S)}}catch(m){if(m.name==="ParseException")return _(`compgen: -C: ${m.message}
53
- `,2);throw m}let $=p;if(u!==null){let m=u.startsWith("!"),v=m?u.slice(1):u;$=p.filter(E=>{let S=ot(E,v,!1,!0);return m?S:!S})}if($.length===0&&a!==null)return k(w,"",1);let g=$.map(m=>`${r}${m}${i}`).join(`
54
- `),b=w+(g?`${g}
55
- `:"");return F(b)}function Ca(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 ka(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 Pa(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(n=>n.startsWith(t))),s.sort()}function Na(e){let t=[...js];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Oa(e){let t=[...Tr];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Da(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 Ta(e){let t=[...Aa];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Ia(e){let t=[..._a];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function Bs(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let o=t.slice(0,a)||"/";r=t.slice(a+1),o.startsWith("/")?n=o:n=`${e.state.cwd}/${o}`}}let i=await e.fs.readdir(n);for(let a of i){let o=`${n}/${a}`;try{if((await e.fs.stat(o)).isDirectory&&(!r||a.startsWith(r)))if(t?.includes("/")){let c=t.lastIndexOf("/"),u=t.slice(0,c+1);s.push(u+a)}else s.push(a)}catch{}}}catch{}return s.sort()}async function Dr(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let o=t.slice(0,a)||"/";r=t.slice(a+1),o.startsWith("/")?n=o:n=`${e.state.cwd}/${o}`}}let i=await e.fs.readdir(n);for(let a of i)if(!r||a.startsWith(r))if(t?.includes("/")){let o=t.lastIndexOf("/"),l=t.slice(0,o+1);s.push(l+a)}else s.push(a)}catch{}return s.sort()}function xa(e){return["root","nobody"]}async function Ra(e,t){let s=new Set;for(let i of js)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 Tr)s.add(i);let n=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of n.split(":"))if(i)try{let a=await e.fs.readdir(i);for(let o of a)s.add(o)}catch{}let r=Array.from(s);return t!==null&&(r=r.filter(i=>i.startsWith(t))),r.sort()}async function La(e,t){let n=new V().parseWordFromString(t,!1,!1);return await I(e,n)}function Fa(e,t){let s=e.state.env.get("IFS")??`
56
- `;if(s.length===0)return[t];let n=new Set(s.split("")),r=[],i="",a=0;for(;a<t.length;){let o=t[a];if(o==="\\"&&a+1<t.length){let l=t[a+1];i+=l,a+=2}else n.has(o)?(i.length>0&&(r.push(i),i=""),a++):(i+=o,a++)}return i.length>0&&r.push(i),r}function ut(e,t){for(let[s,n]of t)n===void 0?e.state.env.delete(s):e.state.env.set(s,n)}function Ma(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{let r=e.state.env.get("COMPREPLY");r!==void 0&&t.push(r)}return t}var Wa=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Zs(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=!1,i,a,o,l=[],c=[],u=[];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 _(`complete: -W: option requires an argument
86
+ `)}}let c=u||"/";if(n)try{c=await e.fs.realpath(c)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=c,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),H(r?`${c}
87
+ `:"")}function yr(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Ku=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function qs(e){return Ku.includes(e)}async function Us(e,t,s){let r=yr(e,s);switch(t){case"-e":case"-a":return e.fs.exists(r);case"-f":return await e.fs.exists(r)?(await e.fs.stat(r)).isFile:!1;case"-d":return await e.fs.exists(r)?(await e.fs.stat(r)).isDirectory:!1;case"-r":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&256)!==0:!1;case"-w":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&128)!==0:!1;case"-x":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&64)!==0:!1;case"-s":return await e.fs.exists(r)?(await e.fs.stat(r)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(r)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&512)!==0:!1;case"-g":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(r);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].includes(r);case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(r);default:return!1}}var Xu=["-nt","-ot","-ef"];function Zs(e){return Xu.includes(e)}async function Hs(e,t,s,r){let n=yr(e,s),i=yr(e,r);switch(t){case"-nt":try{let a=await e.fs.stat(n),l=await e.fs.stat(i);return a.mtime>l.mtime}catch{return!1}case"-ot":try{let a=await e.fs.stat(n),l=await e.fs.stat(i);return a.mtime<l.mtime}catch{return!1}case"-ef":try{if(!await e.fs.exists(n)||!await e.fs.exists(i))return!1;let a=e.fs.resolvePath(e.state.cwd,n),l=e.fs.resolvePath(e.state.cwd,i);return a===l}catch{return!1}default:return!1}}var Yu=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function js(e){return Yu.has(e)}function Gs(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 as(e){return e==="="||e==="=="||e==="!="}function Qs(e,t,s,r=!1,n=!1,i=!1){if(r){let l=Bt(t,s,n,i);return e==="!="?!l:l}if(n){let l=t.toLowerCase()===s.toLowerCase();return e==="!="?!l:l}let a=t===s;return e==="!="?!a:a}var Ju=new Set(["-z","-n"]);function Ks(e){return Ju.has(e)}function Xs(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Ys(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let r=s[1],n=s[2];if(e.state.associativeArrays?.has(r)){let l=n;return(l.startsWith("'")&&l.endsWith("'")||l.startsWith('"')&&l.endsWith('"'))&&(l=l.slice(1,-1)),l=l.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(o,u)=>e.state.env.get(u)||""),e.state.env.has(`${r}_${l}`)}let a;try{let l=new V,o=X(l,n);a=await T(e,o.expression)}catch{if(/^-?\d+$/.test(n))a=Number.parseInt(n,10);else{let l=e.state.env.get(n);a=l?Number.parseInt(l,10):0}}if(a<0){let l=fe(e,r),o=e.state.currentLine;if(l.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${o}: ${r}: bad array subscript
88
+ `,!1;if(a=Math.max(...l)+1+a,a<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${o}: ${r}: bad array subscript
89
+ `,!1}return e.state.env.has(`${r}_${a}`)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?Ze(e,t).length>0:fe(e,t).length>0}async function bt(e,t){switch(t.type){case"CondBinary":{let s=await W(e,t.left),r=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),n;if(t.operator==="=~")if(r){let i=await W(e,t.right);n=rs(i)}else n=await Po(e,t.right);else as(t.operator)&&!r?n=await Do(e,t.right):n=await W(e,t.right);if(as(t.operator)){let i=e.state.shoptOptions.nocasematch;return Qs(t.operator,s,n,!r,i,!0)}if(js(t.operator))return Gs(t.operator,await Mo(e,s),await Mo(e,n));if(Zs(t.operator))return Hs(e,t.operator,s,n);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,a=nf(n),o=ae(a,i?"i":"").match(s);if(Xe(e,"BASH_REMATCH"),o)for(let u=0;u<o.length;u++)e.state.env.set(`BASH_REMATCH_${u}`,o[u]||"");return o!==null}catch{throw new Error("syntax error in regular expression")}case"<":return s<n;case">":return s>n;default:return!1}}case"CondUnary":{let s=await W(e,t.operand);return qs(t.operator)?Us(e,t.operator,s):Ks(t.operator)?Xs(t.operator,s):t.operator==="-v"?await Ys(e,s):t.operator==="-o"?Er(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await W(e,t.operand.expression.word)})`!=="":!await bt(e,t.operand);case"CondAnd":return await bt(e,t.left)?await bt(e,t.right):!1;case"CondOr":return await bt(e,t.left)?!0:await bt(e,t.right);case"CondGroup":return await bt(e,t.expression);case"CondWord":return await W(e,t.word)!=="";default:return!1}}async function os(e,t){if(t.length===0)return P("","",1);if(t.length===1)return de(!!t[0]);if(t.length===2){let r=t[0],n=t[1];return r==="("?_(`test: '(' without matching ')'
90
+ `,2):qs(r)?de(await Us(e,r,n)):Ks(r)?de(Xs(r,n)):r==="!"?de(!n):r==="-v"?de(await Ys(e,n)):r==="-o"?de(Er(e,n)):r==="="||r==="=="||r==="!="||r==="<"||r===">"||r==="-eq"||r==="-ne"||r==="-lt"||r==="-le"||r==="-gt"||r==="-ge"||r==="-nt"||r==="-ot"||r==="-ef"?_(`test: ${r}: unary operator expected
91
+ `,2):P("","",1)}if(t.length===3){let r=t[0],n=t[1],i=t[2];if(as(n))return de(Qs(n,r,i));if(js(n)){let a=Js(r),l=Js(i);return!a.valid||!l.valid?P("","",2):de(Gs(n,a.value,l.value))}if(Zs(n))return de(await Hs(e,n,r,i));switch(n){case"-a":return de(r!==""&&i!=="");case"-o":return de(r!==""||i!=="");case">":return de(r>i);case"<":return de(r<i)}if(r==="!"){let a=await os(e,[n,i]);return P("",a.stderr,a.exitCode===0?1:a.exitCode===1?0:a.exitCode)}if(r==="("&&i===")")return de(n!=="")}if(t.length===4){if(t[0]==="!"){let r=await os(e,t.slice(1));return P("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(t[0]==="("&&t[3]===")")return os(e,[t[1],t[2]])}let s=await Vo(e,t,0);return s.pos<t.length?_(`test: too many arguments
92
+ `,2):de(s.value)}async function Vo(e,t,s){return ef(e,t,s)}async function ef(e,t,s){let{value:r,pos:n}=await Wo(e,t,s);for(;t[n]==="-o";){let i=await Wo(e,t,n+1);r=r||i.value,n=i.pos}return{value:r,pos:n}}async function Wo(e,t,s){let{value:r,pos:n}=await wr(e,t,s);for(;t[n]==="-a";){let i=await wr(e,t,n+1);r=r&&i.value,n=i.pos}return{value:r,pos:n}}async function wr(e,t,s){if(t[s]==="!"){let{value:r,pos:n}=await wr(e,t,s+1);return{value:!r,pos:n}}return tf(e,t,s)}async function tf(e,t,s){let r=t[s];if(r==="("){let{value:i,pos:a}=await Vo(e,t,s+1);return{value:i,pos:t[a]===")"?a+1:a}}let n=t[s+1];if(as(n)){let i=r,a=t[s+2]??"";return{value:Qs(n,i,a),pos:s+3}}if(js(n)){let i=Js(r),a=Js(t[s+2]??"0");return!i.valid||!a.valid?{value:!1,pos:s+3}:{value:Gs(n,i.value,a.value),pos:s+3}}if(Zs(n)){let i=r,a=t[s+2]??"";return{value:await Hs(e,n,i,a),pos:s+3}}if(qs(r)){let i=t[s+1]??"";return{value:await Us(e,r,i),pos:s+2}}if(Ks(r)){let i=t[s+1]??"";return{value:Xs(r,i),pos:s+2}}if(r==="-v"){let i=t[s+1]??"";return{value:await Ys(e,i),pos:s+2}}if(r==="-o"){let i=t[s+1]??"";return{value:Er(e,i),pos:s+2}}return{value:r!==void 0&&r!=="",pos:s+1}}function Bt(e,t,s=!1,r=!1){let n=`^${zo(t,r)}$`;return ae(n,s?"is":"s").test(e)}function zo(e,t){let s="";for(let r=0;r<e.length;r++){let n=e[r];if(t&&(n==="@"||n==="*"||n==="+"||n==="?"||n==="!")&&r+1<e.length&&e[r+1]==="("){let i=Bo(e,r+1);if(i!==-1){let a=e.slice(r+2,i),l=qo(a),o=l.map(c=>zo(c,t)),u=o.length>0?o.join("|"):"(?:)";if(n==="@")s+=`(?:${u})`;else if(n==="*")s+=`(?:${u})*`;else if(n==="+")s+=`(?:${u})+`;else if(n==="?")s+=`(?:${u})?`;else if(n==="!")if(i<e.length-1){let f=l.map(h=>Uo(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 p=[];h>0&&p.push(`.{0,${h-1}}`),p.push(`.{${h+1},}`),p.push(`(?!(?:${u})).{${h}}`),s+=`(?:${p.join("|")})`}}else s+=`(?:(?!(?:${u})).)*?`}else s+=`(?!(?:${u})$).*`;r=i;continue}}if(n==="\\")if(r+1<e.length){let i=e[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,r++}else s+="\\\\";else if(n==="*")s+=".*";else if(n==="?")s+=".";else if(n==="["){let i=e.indexOf("]",r+1);i!==-1?(s+=e.slice(r,i+1),r=i):s+="\\["}else/[\\^$.|+(){}]/.test(n)?s+=`\\${n}`:s+=n}return s}function Bo(e,t){let s=1,r=t+1;for(;r<e.length&&s>0;){let n=e[r];if(n==="\\"){r+=2;continue}if(n==="(")s++;else if(n===")"&&(s--,s===0))return r;r++}return-1}function qo(e){let t=[],s="",r=0,n=0;for(;n<e.length;){let i=e[n];if(i==="\\"){s+=i,n+1<e.length?(s+=e[n+1],n+=2):n++;continue}i==="("?(r++,s+=i):i===")"?(r--,s+=i):i==="|"&&r===0?(t.push(s),s=""):s+=i,n++}return t.push(s),t}function Uo(e,t){let s=0,r=0;for(;r<e.length;){let n=e[r];if(t&&(n==="@"||n==="*"||n==="+"||n==="?"||n==="!")&&r+1<e.length&&e[r+1]==="("){let i=Bo(e,r+1);if(i!==-1){if(n==="@"){let a=e.slice(r+2,i),o=qo(a).map(u=>Uo(u,t));if(o.every(u=>u!==null)&&o.every(u=>u===o[0])){s+=o[0],r=i+1;continue}return null}return null}}if(n==="*")return null;if(n==="?"){s+=1,r++;continue}if(n==="["){let i=e.indexOf("]",r+1);if(i!==-1){s+=1,r=i+1;continue}s+=1,r++;continue}if(n==="\\"){s+=1,r+=2;continue}s+=1,r++}return s}function Er(e,t){let r=new Map([["errexit",()=>e.state.options.errexit===!0],["nounset",()=>e.state.options.nounset===!0],["pipefail",()=>e.state.options.pipefail===!0],["xtrace",()=>e.state.options.xtrace===!0],["e",()=>e.state.options.errexit===!0],["u",()=>e.state.options.nounset===!0],["x",()=>e.state.options.xtrace===!0]]).get(t);return r?r():!1}async function Mo(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 Fo(t);try{let s=new V,r=X(s,t);return await T(e,r.expression)}catch{return Fo(t)}}function sf(e,t){let s=0;for(let r of e){let n;if(r>="0"&&r<="9")n=r.charCodeAt(0)-48;else if(r>="a"&&r<="z")n=r.charCodeAt(0)-97+10;else if(r>="A"&&r<="Z")n=r.charCodeAt(0)-65+36;else if(r==="@")n=62;else if(r==="_")n=63;else return Number.NaN;if(n>=t)return Number.NaN;s=s*t+n}return s}function Fo(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,r=e.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(r){let n=Number.parseInt(r[1],10);n>=2&&n<=64?s=sf(r[2],n):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 Js(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 nf(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 r=rf(e,s);t+=r.converted,s=r.endIndex}else t+=e[s],s++;return t}function rf(e,t){let s=t+1,r="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(r+="^",s++);let n=!1;s<e.length&&e[s]==="]"&&(n=!0,s++);let i=!1;s<e.length&&e[s]==="["&&s+1<e.length&&e[s+1]!==":"&&(i=!0,s++);let a="",l=!1;for(;s<e.length;){let o=e[s];if(o==="]"){l=!0,s++;break}if(o==="["&&s+1<e.length&&e[s+1]===":"){let u=e.indexOf(":]",s+2);if(u!==-1){let c=e.slice(s+2,u);a+=af(c),s=u+2;continue}}if(o==="["&&s+1<e.length){let u=e[s+1];if(u==="."||u==="="){let c=`${u}]`,f=e.indexOf(c,s+2);if(f!==-1){let d=e.slice(s+2,f);a+=d,s=f+2;continue}}}if(o==="\\"&&s+1<e.length){a+=o+e[s+1],s+=2;continue}a+=o,s++}return l?(n&&(r+="\\]"),i&&(r+="\\["),r+=a,r+="]",{converted:r,endIndex:s}):{converted:"\\[",endIndex:t+1}}function af(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 nt(e){let t=[],s="",r=!1,n=!1,i=!1,a=!1;for(let l of e){if(i){s+=l,i=!1,a=!0;continue}if(l==="\\"){i=!0;continue}if(l==="'"&&!n){r||(a=!0),r=!r;continue}if(l==='"'&&!r){n||(a=!0),n=!n;continue}if((l===" "||l===" "||l===`
93
+ `)&&!r&&!n){a&&(t.push(s),s="",a=!1);continue}s+=l,a=!0}return a&&t.push(s),t}function en(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 r="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)r+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&e[s]!=="]"&&e[s]!=="=";)r+=e[s],s++;for(;s<e.length&&e[s]!=="]";)s++;if(e[s]==="]"&&s++,e[s]!=="=")continue;s++;let n="";if(e[s]==="'"||e[s]==='"'){let i=e[s];for(s++;s<e.length&&e[s]!==i;)e[s]==="\\"&&s+1<e.length&&s++,n+=e[s],s++;e[s]===i&&s++}else for(;s<e.length&&!/\s/.test(e[s]);)n+=e[s],s++;t.push([r,n])}return t}function Zo(e){let t=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(t)return{name:t[1],isArray:!0,arrayElements:nt(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 r=e.indexOf("=");return{name:e.slice(0,r),isArray:!1,value:e.slice(r+1)}}return{name:e,isArray:!1}}async function of(e,t){try{let s=new V,r=X(s,t);return await T(e,r.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}async function Ho(e,t,s={}){let{name:r,isArray:n,arrayElements:i,value:a,arrayIndex:l}=t,{makeReadonly:o=!1,checkReadonly:u=!0}=s;if(u){let c=me(e,r);if(c)return c}if(n&&i){for(let c=0;c<i.length;c++)e.state.env.set(`${r}_${c}`,i[c]);e.state.env.set(`${r}__length`,String(i.length))}else if(l!==void 0&&a!==void 0){let c=await of(e,l);e.state.env.set(`${r}_${c}`,a);let f=parseInt(e.state.env.get(`${r}__length`)??"0",10);c>=f&&e.state.env.set(`${r}__length`,String(c+1))}else a!==void 0&&e.state.env.set(r,a);return o&&Pe(e,r),null}function vt(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function qt(e,t){return e.state.localVarDepth?.get(t)}function tn(e,t){e.state.localVarDepth?.delete(t)}function jo(e,t,s){e.state.localVarStack=e.state.localVarStack||new Map;let r=e.state.localVarStack.get(t)||[];r.push({value:s,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,r)}function sn(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function Go(e,t){if(e.state.localVarStack)for(let[s,r]of e.state.localVarStack.entries()){for(;r.length>0&&r[r.length-1].scopeIndex===t;)r.pop();r.length===0&&e.state.localVarStack.delete(s)}}var br=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Qo(e){return br.has(e)}var vr=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Ut=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 nn(e,t,s,r){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory
94
+ `;if(r.checkNoclobber&&e.state.options.noclobber&&!r.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file
95
+ `}catch{}return null}function Zt(e){let s=Math.min(e.length,8192);for(let r=0;r<s;r++)if(e.charCodeAt(r)>127)return"utf8";return"binary"}function lf(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let r=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(r)||r<0)return null;let n=s+1,i=t.slice(n,n+r),a=n+r+1,l=t.slice(a),o=l.indexOf(":");if(o===-1)return null;let u=Number.parseInt(l.slice(0,o),10);if(Number.isNaN(u)||u<0)return null;let c=l.slice(o+1);return{path:i,position:u,content:c}}async function Ko(e,t){let s=new Map;for(let r=0;r<t.length;r++){let n=t[r];if(n.target.type==="HereDoc")continue;if(n.operator===">&"||n.operator==="<&"){if(Vs(e,n.target))return{targets:s,error:`bash: $@: ambiguous redirect
96
+ `};s.set(r,await W(e,n.target))}else{let a=await zs(e,n.target);if("error"in a)return{targets:s,error:a.error};s.set(r,a.target)}}return{targets:s}}function cf(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd,s=e.limits.maxFileDescriptors;if(t>=s)throw new Error(`bash: cannot allocate file descriptor: too many open files (max ${s})`);return e.state.nextFd++,t}async function rn(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 W(e,s.target)==="-"){let i=e.state.env.get(s.fdVariable);if(i!==void 0){let a=Number.parseInt(i,10);Number.isNaN(a)||e.state.fileDescriptors.delete(a)}continue}let r=cf(e);if(e.state.env.set(s.fdVariable,String(r)),s.target.type==="Word"){let n=await W(e,s.target);if(s.operator===">&"||s.operator==="<&"){let i=Number.parseInt(n,10);if(!Number.isNaN(i)){let a=e.state.fileDescriptors.get(i);a!==void 0&&(ve(e),e.state.fileDescriptors.set(r,a));continue}}if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let i=e.fs.resolvePath(e.state.cwd,n);(s.operator===">"||s.operator===">|"||s.operator==="&>")&&await e.fs.writeFile(i,"","binary"),ve(e),e.state.fileDescriptors.set(r,`__file__:${i}`)}else if(s.operator==="<<<")ve(e),e.state.fileDescriptors.set(r,`${n}
97
+ `);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,n),a=await e.fs.readFile(i);ve(e),e.state.fileDescriptors.set(r,a)}catch{return P("",`bash: ${n}: No such file or directory
98
+ `,1)}}}return null}async function rt(e,t){for(let s of t){if(s.target.type==="HereDoc")continue;let r=s.operator===">&";if(s.operator!==">"&&s.operator!==">|"&&s.operator!=="&>"&&!r)continue;let n;if(r){if(n=await W(e,s.target),n==="-"||!Number.isNaN(Number.parseInt(n,10))||s.fd!=null)continue}else{let l=await zs(e,s.target);if("error"in l)return P("",l.error,1);n=l.target}let i=e.fs.resolvePath(e.state.cwd,n),a=s.operator===">|";if(i.includes("\0"))return P("",`bash: ${n}: No such file or directory
99
+ `,1);try{let l=await e.fs.stat(i);if(l.isDirectory)return P("",`bash: ${n}: Is a directory
100
+ `,1);if(e.state.options.noclobber&&!a&&!l.isDirectory&&n!=="/dev/null")return P("",`bash: ${n}: cannot overwrite existing file
101
+ `,1)}catch{}if(n!=="/dev/null"&&n!=="/dev/stdout"&&n!=="/dev/stderr"&&n!=="/dev/full"&&await e.fs.writeFile(i,"","binary"),n==="/dev/full")return P("",`bash: /dev/full: No space left on device
102
+ `,1)}return null}async function le(e,t,s,r){let{stdout:n,stderr:i,exitCode:a}=t,o=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",u=m=>o,c={kind:"live-stdout"},f={kind:"live-stderr"};for(let m=0;m<s.length;m++){let y=s[m];if(y.target.type==="HereDoc")continue;let b,v=r?.get(m);if(v!==void 0)b=v;else if(y.operator===">&"||y.operator==="<&"){if(Vs(e,y.target)){i+=`bash: $@: ambiguous redirect
103
+ `,a=1,n="";continue}b=await W(e,y.target)}else{let w=await zs(e,y.target);if("error"in w){i+=w.error,a=1,n="";continue}b=w.target}if(!y.fdVariable){if(b.includes("\0")){i+=`bash: ${b.replace(/\0/g,"")}: No such file or directory
104
+ `,a=1,n="";continue}switch(y.operator){case">":case">|":case">>":{let E=y.fd??1;if(E!==1&&E!==2)break;let w=y.operator===">>",S=y.operator===">|";if(b==="/dev/stdout"){E===2&&(f=c);break}if(b==="/dev/stderr"){E===1&&(c=f);break}if(b==="/dev/full"){i+=`bash: echo: write error: No space left on device
105
+ `,a=1,E===1&&(n="");break}if(b==="/dev/null"&&E===2){f={kind:"discard"};break}let A=e.fs.resolvePath(e.state.cwd,b),$=await nn(e,A,b,{...w?{}:{checkNoclobber:!0,isClobber:S}});if($){i+=$,a=1,E===1&&(n="");break}w?await e.fs.appendFile(A,"","binary"):await e.fs.writeFile(A,"","binary"),E===1?c={kind:"file",path:A,append:w}:f={kind:"file",path:A,append:w};break}case">&":case"<&":{let E=y.fd??1;if(b==="-")break;if(b.endsWith("-")){let w=b.slice(0,-1),S=Number.parseInt(w,10);if(!Number.isNaN(S)){let A=e.state.fileDescriptors?.get(S);A!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(E,A),S>=3&&e.state.fileDescriptors?.delete(S)):S===1||S===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(E,`__dupout__:${S}`)):S===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(E,`__dupin__:${S}`)):S>=3&&(i+=`bash: ${S}: Bad file descriptor
106
+ `,a=1)}break}if(b==="2"||b==="&2")E===1&&(c=f);else if(b==="1"||b==="&1")E===2?f=c:(n+=i,i="");else{let w=Number.parseInt(b,10);if(Number.isNaN(w)){if(y.operator===">&"){let S=e.fs.resolvePath(e.state.cwd,b),A=await nn(e,S,b,{checkNoclobber:!0});if(A){i=A,a=1,n="";break}await e.fs.writeFile(S,"","binary"),y.fd==null?(c={kind:"file",path:S,append:!1},f=c):E===1?c={kind:"file",path:S,append:!1}:E===2&&(f={kind:"file",path:S,append:!1})}}else{let S=e.state.fileDescriptors?.get(w);if(S?.startsWith("__file__:")){let A=S.slice(9);E===1?(await e.fs.appendFile(A,n,u(n)),n=""):E===2&&(await e.fs.appendFile(A,i,Zt(i)),i="")}else if(S?.startsWith("__rw__:")){let A=lf(S);A&&(E===1?(await e.fs.appendFile(A.path,n,u(n)),n=""):E===2&&(await e.fs.appendFile(A.path,i,Zt(i)),i=""))}else if(S?.startsWith("__dupout__:")){let A=Number.parseInt(S.slice(11),10);if(A!==1)if(A===2)E===1&&(i+=n,n="");else{let $=e.state.fileDescriptors?.get(A);if($?.startsWith("__file__:")){let R=$.slice(9);E===1?(await e.fs.appendFile(R,n,u(n)),n=""):E===2&&(await e.fs.appendFile(R,i,Zt(i)),i="")}}}else S?.startsWith("__dupin__:")?(i+=`bash: ${w}: Bad file descriptor
107
+ `,a=1,n=""):w>=3&&(i+=`bash: ${w}: Bad file descriptor
108
+ `,a=1,n="")}}break}case"&>":{if(b==="/dev/full"){i=`bash: echo: write error: No space left on device
109
+ `,a=1,n="";break}let E=e.fs.resolvePath(e.state.cwd,b),w=await nn(e,E,b,{checkNoclobber:!0});if(w){i=w,a=1,n="";break}await e.fs.writeFile(E,"","binary"),c={kind:"file",path:E,append:!1},f=c;break}case"&>>":{if(b==="/dev/full"){i=`bash: echo: write error: No space left on device
110
+ `,a=1,n="";break}let E=e.fs.resolvePath(e.state.cwd,b),w=await nn(e,E,b,{});if(w){i=w,a=1,n="";break}await e.fs.appendFile(E,"","binary"),c={kind:"file",path:E,append:!0},f=c;break}}}}if(n!==""||i!==""){let m=n,y=i;n="",i="";let b=async(v,E,w)=>{v.append?await e.fs.appendFile(v.path,E,w):await e.fs.writeFile(v.path,E,w)};if(c===f&&c.kind==="file"){let v=m+y;v!==""&&await b(c,v,u(v))}else for(let[v,E,w]of[[m,c,!0],[y,f,!1]])if(v!=="")switch(E.kind){case"live-stdout":n+=v;break;case"live-stderr":i+=v;break;case"file":await b(E,v,w?u(v):Zt(v));break;case"discard":break}}let d=e.state.fileDescriptors?.get(1);if(d){if(d==="__dupout__:2")i+=n,n="";else if(d.startsWith("__file__:")){let m=d.slice(9);await e.fs.appendFile(m,n,u(n)),n=""}else if(d.startsWith("__file_append__:")){let m=d.slice(16);await e.fs.appendFile(m,n,u(n)),n=""}}let h=e.state.fileDescriptors?.get(2);if(h){if(h==="__dupout__:1")n+=i,i="";else if(h.startsWith("__file__:")){let m=h.slice(9);await e.fs.appendFile(m,i,Zt(i)),i=""}else if(h.startsWith("__file_append__:")){let m=h.slice(16);await e.fs.appendFile(m,i,Zt(i)),i=""}}let p=P(n,i,a);return t.stdoutKind&&(p.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(p.stdoutEncoding="binary"),p}function Xo(e,t){if(e.state.options.posix&&br.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
111
+ `;throw new U(2,"",r)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),G}async function uf(e,t){let s="";for(let r of t)if((r.operator==="<<"||r.operator==="<<-")&&r.target.type==="HereDoc"){let n=r.target,i=await W(e,n.content);n.stripTabs&&(i=i.split(`
112
+ `).map(l=>l.replace(/^\t+/,"")).join(`
113
+ `)),(r.fd??0)===0&&(s=i)}else if(r.operator==="<<<"&&r.target.type==="Word")s=`${await W(e,r.target)}
114
+ `;else if(r.operator==="<"&&r.target.type==="Word"){let n=await W(e,r.target),i=e.fs.resolvePath(e.state.cwd,n);try{s=await e.fs.readFile(i)}catch{}}return s}async function an(e,t,s,r="",n){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,st(`${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(n??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),e.state.env.get(String(u+1))),e.state.env.set(String(u+1),s[u]);i.set("@",e.state.env.get("@")),i.set("#",e.state.env.get("#")),e.state.env.set("@",s.join(" ")),e.state.env.set("#",String(s.length));let a=()=>{let u=e.state.localScopes.length-1,c=e.state.localScopes.pop();if(c)for(let[f,d]of c)d===void 0?e.state.env.delete(f):e.state.env.set(f,d);if(Go(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):e.state.env.set(f,d);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},{targets:l,error:o}=await Ko(e,t.redirections);if(o)return a(),P("",o,1);try{let u=await uf(e,t.redirections),c=r||u,f=await e.executeCommand(t.body,c);return a(),le(e,f,t.redirections,l)}catch(u){if(a(),u instanceof Ne){let c=P(u.stdout,u.stderr,u.exitCode);return le(e,c,t.redirections,l)}throw u}}var Jo=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],Ar=[".",":","[","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"],ff=["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"],df=Ar;async function $r(e,t){let s=[],r=null,n="",i="",a=null,l=!1,o=!1,u=!1,c=null,f=null,d=null,h=[],p=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let w=0;w<t.length;w++){let S=t[w];if(S==="-v")s.push("variable");else if(S==="-e")s.push("export");else if(S==="-f")s.push("file");else if(S==="-d")s.push("directory");else if(S==="-k")s.push("keyword");else if(S==="-A"){if(w++,w>=t.length)return _(`compgen: -A: option requires an argument
115
+ `,2);let A=t[w];if(!p.includes(A))return _(`compgen: ${A}: invalid action name
116
+ `,2);s.push(A)}else if(S==="-W"){if(w++,w>=t.length)return _(`compgen: -W: option requires an argument
117
+ `,2);r=t[w]}else if(S==="-P"){if(w++,w>=t.length)return _(`compgen: -P: option requires an argument
118
+ `,2);n=t[w]}else if(S==="-S"){if(w++,w>=t.length)return _(`compgen: -S: option requires an argument
119
+ `,2);i=t[w]}else if(S==="-o"){if(w++,w>=t.length)return _(`compgen: -o: option requires an argument
120
+ `,2);let A=t[w];if(A==="plusdirs")l=!0;else if(A==="dirnames")o=!0;else if(A==="default")u=!0;else if(!(A==="filenames"||A==="nospace"||A==="bashdefault"||A==="noquote"))return _(`compgen: ${A}: invalid option name
121
+ `,2)}else if(S==="-F"){if(w++,w>=t.length)return _(`compgen: -F: option requires an argument
122
+ `,2);f=t[w]}else if(S==="-C"){if(w++,w>=t.length)return _(`compgen: -C: option requires an argument
123
+ `,2);d=t[w]}else if(S==="-X"){if(w++,w>=t.length)return _(`compgen: -X: option requires an argument
124
+ `,2);c=t[w]}else if(S==="-G"){if(w++,w>=t.length)return _(`compgen: -G: option requires an argument
125
+ `,2)}else if(S==="--"){h.push(...t.slice(w+1));break}else S.startsWith("-")||h.push(S)}a=h[0]??null;let m=[];if(o){let w=await Sr(e,a);m.push(...w)}if(u){let w=await Yo(e,a);m.push(...w)}for(let w of s)if(w==="variable"){let S=hf(e,a);m.push(...S)}else if(w==="export"){let S=pf(e,a);m.push(...S)}else if(w==="function"){let S=mf(e,a);m.push(...S)}else if(w==="builtin"){let S=gf(a);m.push(...S)}else if(w==="keyword"){let S=yf(a);m.push(...S)}else if(w==="alias"){let S=wf(e,a);m.push(...S)}else if(w==="shopt"){let S=Ef(a);m.push(...S)}else if(w==="helptopic"){let S=bf(a);m.push(...S)}else if(w==="directory"){let S=await Sr(e,a);m.push(...S)}else if(w==="file"){let S=await Yo(e,a);m.push(...S)}else if(w==="user"){let S=vf(a);m.push(...S)}else if(w==="command"){let S=await Sf(e,a);m.push(...S)}if(r!==null)try{let w=await Af(e,r),S=$f(e,w);for(let A of S)(a===null||A.startsWith(a))&&m.push(A)}catch{return P("","",1)}if(l){let w=await Sr(e,a);for(let S of w)m.includes(S)||m.push(S)}let y="";if(f!==null){let w=e.state.functions.get(f);if(w){let S=new Map;S.set("COMP_WORDS__length",e.state.env.get("COMP_WORDS__length")),e.state.env.set("COMP_WORDS__length","0"),S.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),S.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),S.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let A=new Map;for(let R of e.state.env.keys())(R==="COMPREPLY"||R.startsWith("COMPREPLY_")||R==="COMPREPLY__length")&&(A.set(R,e.state.env.get(R)),e.state.env.delete(R));let $=["compgen",h[0]??"",""];try{let R=await an(e,w,$,"");if(R.exitCode!==0)return Ht(e,S),Ht(e,A),P("",R.stderr,1);y=R.stdout;let I=Nf(e);m.push(...I)}catch{return Ht(e,S),Ht(e,A),P("","",1)}Ht(e,S),Ht(e,A)}}if(d!==null)try{let w=Ue(d),S=await e.executeScript(w);if(S.exitCode!==0)return P("",S.stderr,S.exitCode);if(S.stdout){let A=S.stdout.split(`
126
+ `);for(let $ of A)$.length>0&&m.push($)}}catch(w){if(w.name==="ParseException")return _(`compgen: -C: ${w.message}
127
+ `,2);throw w}let b=m;if(c!==null){let w=c.startsWith("!"),S=w?c.slice(1):c;b=m.filter(A=>{let $=Bt(A,S,!1,!0);return w?$:!$})}if(b.length===0&&a!==null)return P(y,"",1);let v=b.map(w=>`${n}${w}${i}`).join(`
128
+ `),E=y+(v?`${v}
129
+ `:"");return H(E)}function hf(e,t){let s=new Set;for(let n of e.state.env.keys()){if(n.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(n)||n.endsWith("__length"))continue;let i=n.split("_")[0];/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)?s.add(n):i&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)&&e.state.env.has(`${i}__length`)&&s.add(i)}let r=Array.from(s);return t!==null&&(r=r.filter(n=>n.startsWith(t))),r.sort()}function pf(e,t){let s=e.state.exportedVars??new Set,r=Array.from(s);return t!==null&&(r=r.filter(n=>n.startsWith(t))),r=r.filter(n=>n.includes("_")&&/^[a-zA-Z_][a-zA-Z0-9_]*_\d+$/.test(n)||n.endsWith("__length")?!1:e.state.env.has(n)),r.sort()}function mf(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(r=>r.startsWith(t))),s.sort()}function gf(e){let t=[...Ar];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function yf(e){let t=[...Jo];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function wf(e,t){let s=[];for(let n of e.state.env.keys())if(n.startsWith("BASH_ALIAS_")){let i=n.slice(11);s.push(i)}let r=s;return t!==null&&(r=r.filter(n=>n.startsWith(t))),r.sort()}function Ef(e){let t=[...ff];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function bf(e){let t=[...df];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function Sr(e,t){let s=[];try{let r=e.state.cwd,n=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";n=t.slice(a+1),l.startsWith("/")?r=l:r=`${e.state.cwd}/${l}`}}let i=await e.fs.readdir(r);for(let a of i){let l=`${r}/${a}`;try{if((await e.fs.stat(l)).isDirectory&&(!n||a.startsWith(n)))if(t?.includes("/")){let u=t.lastIndexOf("/"),c=t.slice(0,u+1);s.push(c+a)}else s.push(a)}catch{}}}catch{}return s.sort()}async function Yo(e,t){let s=[];try{let r=e.state.cwd,n=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";n=t.slice(a+1),l.startsWith("/")?r=l:r=`${e.state.cwd}/${l}`}}let i=await e.fs.readdir(r);for(let a of i)if(!n||a.startsWith(n))if(t?.includes("/")){let l=t.lastIndexOf("/"),o=t.slice(0,l+1);s.push(o+a)}else s.push(a)}catch{}return s.sort()}function vf(e){return["root","nobody"]}async function Sf(e,t){let s=new Set;for(let i of Ar)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 Jo)s.add(i);let r=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of r.split(":"))if(i)try{let a=await e.fs.readdir(i);for(let l of a)s.add(l)}catch{}let n=Array.from(s);return t!==null&&(n=n.filter(i=>i.startsWith(t))),n.sort()}async function Af(e,t){let r=new V().parseWordFromString(t,!1,!1);return await W(e,r)}function $f(e,t){let s=e.state.env.get("IFS")??`
130
+ `;if(s.length===0)return[t];let r=new Set(s.split("")),n=[],i="",a=0;for(;a<t.length;){let l=t[a];if(l==="\\"&&a+1<t.length){let o=t[a+1];i+=o,a+=2}else r.has(l)?(i.length>0&&(n.push(i),i=""),a++):(i+=l,a++)}return i.length>0&&n.push(i),n}function Ht(e,t){for(let[s,r]of t)r===void 0?e.state.env.delete(s):e.state.env.set(s,r)}function Nf(e){let t=[];if(e.state.env.get("COMPREPLY__length")!==void 0){let n=F(e,"COMPREPLY");for(let[,i]of n)t.push(i)}else{let n=e.state.env.get("COMPREPLY");n!==void 0&&t.push(n)}return t}var kf=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function kr(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,r=!1,n=!1,i,a,l,o=[],u=[],c=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-p")s=!0;else if(d==="-r")r=!0;else if(d==="-D")n=!0;else if(d==="-W"){if(f++,f>=t.length)return _(`complete: -W: option requires an argument
57
131
  `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return _(`complete: -F: option requires an argument
58
132
  `,2);a=t[f]}else if(d==="-o"){if(f++,f>=t.length)return _(`complete: -o: option requires an argument
59
- `,2);let h=t[f];if(!Wa.includes(h))return _(`complete: ${h}: invalid option name
60
- `,2);l.push(h)}else if(d==="-A"){if(f++,f>=t.length)return _(`complete: -A: option requires an argument
61
- `,2);c.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return _(`complete: -C: option requires an argument
62
- `,2);o=t[f]}else if(d==="-G"){if(f++,f>=t.length)return _(`complete: -G: option requires an argument
133
+ `,2);let h=t[f];if(!kf.includes(h))return _(`complete: ${h}: invalid option name
134
+ `,2);o.push(h)}else if(d==="-A"){if(f++,f>=t.length)return _(`complete: -A: option requires an argument
135
+ `,2);u.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return _(`complete: -C: option requires an argument
136
+ `,2);l=t[f]}else if(d==="-G"){if(f++,f>=t.length)return _(`complete: -G: option requires an argument
63
137
  `,2)}else if(d==="-P"){if(f++,f>=t.length)return _(`complete: -P: option requires an argument
64
138
  `,2)}else if(d==="-S"){if(f++,f>=t.length)return _(`complete: -S: option requires an argument
65
139
  `,2)}else if(d==="-X"){if(f++,f>=t.length)return _(`complete: -X: option requires an argument
66
- `,2)}else if(d==="--"){u.push(...t.slice(f+1));break}else d.startsWith("-")||u.push(d)}if(n){if(u.length===0)return e.state.completionSpecs.clear(),F("");for(let f of u)e.state.completionSpecs.delete(f);return F("")}if(s)return u.length===0?Us(e):Us(e,u);if(t.length===0||u.length===0&&!i&&!a&&!o&&l.length===0&&c.length===0&&!r)return Us(e);if(a&&u.length===0&&!r)return _(`complete: -F: option requires a command name
67
- `,2);if(r){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),a!==void 0&&(f.function=a),o!==void 0&&(f.command=o),l.length>0&&(f.options=l),c.length>0&&(f.actions=c),e.state.completionSpecs.set("__default__",f),F("")}for(let f of u){let d=Object.create(null);i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),o!==void 0&&(d.command=o),l.length>0&&(d.options=l),c.length>0&&(d.actions=c),e.state.completionSpecs.set(f,d)}return F("")}function Us(e,t){let s=e.state.completionSpecs;if(!s||s.size===0){if(t&&t.length>0){let i="";for(let a of t)i+=`complete: ${a}: no completion specification
68
- `;return k("",i,1)}return F("")}let n=[],r=t||Array.from(s.keys());for(let i of r){if(i==="__default__")continue;let a=s.get(i);if(!a){if(t)return k(n.join(`
69
- `)+(n.length>0?`
140
+ `,2)}else if(d==="--"){c.push(...t.slice(f+1));break}else d.startsWith("-")||c.push(d)}if(r){if(c.length===0)return e.state.completionSpecs.clear(),H("");for(let f of c)e.state.completionSpecs.delete(f);return H("")}if(s)return c.length===0?Nr(e):Nr(e,c);if(t.length===0||c.length===0&&!i&&!a&&!l&&o.length===0&&u.length===0&&!n)return Nr(e);if(a&&c.length===0&&!n)return _(`complete: -F: option requires a command name
141
+ `,2);if(n){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),a!==void 0&&(f.function=a),l!==void 0&&(f.command=l),o.length>0&&(f.options=o),u.length>0&&(f.actions=u),e.state.completionSpecs.set("__default__",f),H("")}for(let f of c){let d=Object.create(null);i!==void 0&&(d.wordlist=i),a!==void 0&&(d.function=a),l!==void 0&&(d.command=l),o.length>0&&(d.options=o),u.length>0&&(d.actions=u),e.state.completionSpecs.set(f,d)}return H("")}function Nr(e,t){let s=e.state.completionSpecs;if(!s||s.size===0){if(t&&t.length>0){let i="";for(let a of t)i+=`complete: ${a}: no completion specification
142
+ `;return P("",i,1)}return H("")}let r=[],n=t||Array.from(s.keys());for(let i of n){if(i==="__default__")continue;let a=s.get(i);if(!a){if(t)return P(r.join(`
143
+ `)+(r.length>0?`
70
144
  `:""),`complete: ${i}: no completion specification
71
- `,1);continue}let o="complete";if(a.options)for(let l of a.options)o+=` -o ${l}`;if(a.actions)for(let l of a.actions)o+=` -A ${l}`;a.wordlist!==void 0&&(a.wordlist.includes(" ")||a.wordlist.includes("'")?o+=` -W '${a.wordlist}'`:o+=` -W ${a.wordlist}`),a.function!==void 0&&(o+=` -F ${a.function}`),a.isDefault&&(o+=" -D"),o+=` ${i}`,n.push(o)}return n.length===0?F(""):F(`${n.join(`
145
+ `,1);continue}let l="complete";if(a.options)for(let o of a.options)l+=` -o ${o}`;if(a.actions)for(let o of a.actions)l+=` -A ${o}`;a.wordlist!==void 0&&(a.wordlist.includes(" ")||a.wordlist.includes("'")?l+=` -W '${a.wordlist}'`:l+=` -W ${a.wordlist}`),a.function!==void 0&&(l+=` -F ${a.function}`),a.isDefault&&(l+=" -D"),l+=` ${i}`,r.push(l)}return r.length===0?H(""):H(`${r.join(`
72
146
  `)}
73
- `)}var Ir=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function qs(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=[],i=[],a=[];for(let o=0;o<t.length;o++){let l=t[o];if(l==="-D")s=!0;else if(l==="-E")n=!0;else if(l==="-o"){if(o++,o>=t.length)return _(`compopt: -o: option requires an argument
74
- `,2);let c=t[o];if(!Ir.includes(c))return _(`compopt: ${c}: invalid option name
75
- `,2);r.push(c)}else if(l==="+o"){if(o++,o>=t.length)return _(`compopt: +o: option requires an argument
76
- `,2);let c=t[o];if(!Ir.includes(c))return _(`compopt: ${c}: invalid option name
77
- `,2);i.push(c)}else if(l==="--"){a.push(...t.slice(o+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&a.push(l)}if(s){let o=e.state.completionSpecs.get("__default__")??{isDefault:!0},l=new Set(o.options??[]);for(let c of r)l.add(c);for(let c of i)l.delete(c);return o.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set("__default__",o),F("")}if(n){let o=e.state.completionSpecs.get("__empty__")??{},l=new Set(o.options??[]);for(let c of r)l.add(c);for(let c of i)l.delete(c);return o.options=l.size>0?Array.from(l):void 0,e.state.completionSpecs.set("__empty__",o),F("")}if(a.length>0){for(let o of a){let l=e.state.completionSpecs.get(o)??{},c=new Set(l.options??[]);for(let u of r)c.add(u);for(let u of i)c.delete(u);l.options=c.size>0?Array.from(c):void 0,e.state.completionSpecs.set(o,l)}return F("")}return _(`compopt: not currently executing completion function
78
- `,1)}function Gs(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Re;return M}if(t.length>1)throw new B(1,"",`bash: continue: too many arguments
79
- `);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new B(1,"",`bash: continue: ${t[0]}: numeric argument required
80
- `);s=n}throw new he(s)}function G(e,t){let s=e.state.env.get("HOME")||"/home/user";return t.split(":").map(i=>i==="~"?s:i==="~root"?"/root":i.startsWith("~/")?s+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function Ks(e){for(let t=0;t<e.length;t++){let s=e.charCodeAt(t);if(s<32||s===127)return!0}return!1}function Xs(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 rs(e){return Ks(e)?Xs(e):/^[a-zA-Z0-9_/.:\-@%+,=]*$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Ke(e){return Ks(e)?Xs(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Ys(e){return Ks(e)?Xs(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function xr(e,t){let s="";return e.state.integerVars?.has(t)&&(s+="i"),e.state.lowercaseVars?.has(t)&&(s+="l"),ge(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 Qs(e){return e===""?"''":/[\s'\\]/.test(e)?`'${e.replace(/'/g,"'\\''")}'`:e}function Rr(e,t){let s="",n="",r=!1;for(let i of t){let a=xr(e,i);if(e.state.associativeArrays?.has(i)){let u=Me(e,i);if(u.length===0)s+=`declare -A ${i}=()
81
- `;else{let f=u.map(d=>{let h=e.state.env.get(`${i}_${d}`)??"",y=Qs(h);return`['${d}']=${y}`});s+=`declare -A ${i}=(${f.join(" ")})
82
- `}continue}let l=ne(e,i);if(l.length>0){let u=l.map(f=>{let d=e.state.env.get(`${i}_${f}`)??"";return`[${f}]=${Ke(d)}`});s+=`declare -a ${i}=(${u.join(" ")})
147
+ `)}var el=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function _r(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,r=!1,n=[],i=[],a=[];for(let l=0;l<t.length;l++){let o=t[l];if(o==="-D")s=!0;else if(o==="-E")r=!0;else if(o==="-o"){if(l++,l>=t.length)return _(`compopt: -o: option requires an argument
148
+ `,2);let u=t[l];if(!el.includes(u))return _(`compopt: ${u}: invalid option name
149
+ `,2);n.push(u)}else if(o==="+o"){if(l++,l>=t.length)return _(`compopt: +o: option requires an argument
150
+ `,2);let u=t[l];if(!el.includes(u))return _(`compopt: ${u}: invalid option name
151
+ `,2);i.push(u)}else if(o==="--"){a.push(...t.slice(l+1));break}else!o.startsWith("-")&&!o.startsWith("+")&&a.push(o)}if(s){let l=e.state.completionSpecs.get("__default__")??{isDefault:!0},o=new Set(l.options??[]);for(let u of n)o.add(u);for(let u of i)o.delete(u);return l.options=o.size>0?Array.from(o):void 0,e.state.completionSpecs.set("__default__",l),H("")}if(r){let l=e.state.completionSpecs.get("__empty__")??{},o=new Set(l.options??[]);for(let u of n)o.add(u);for(let u of i)o.delete(u);return l.options=o.size>0?Array.from(o):void 0,e.state.completionSpecs.set("__empty__",l),H("")}if(a.length>0){for(let l of a){let o=e.state.completionSpecs.get(l)??{},u=new Set(o.options??[]);for(let c of n)u.add(c);for(let c of i)u.delete(c);o.options=u.size>0?Array.from(u):void 0,e.state.completionSpecs.set(l,o)}return H("")}return _(`compopt: not currently executing completion function
152
+ `,1)}function Pr(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new ft;return G}if(t.length>1)throw new U(1,"",`bash: continue: too many arguments
153
+ `);let s=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new U(1,"",`bash: continue: ${t[0]}: numeric argument required
154
+ `);s=r}throw new Ce(s)}function ue(e,t){let s=e.state.env.get("HOME")||"/home/user";return t.split(":").map(i=>i==="~"?s:i==="~root"?"/root":i.startsWith("~/")?s+i.slice(1):i.startsWith("~root/")?`/root${i.slice(5)}`:i).join(":")}function Dr(e){for(let t=0;t<e.length;t++){let s=e.charCodeAt(t);if(s<32||s===127)return!0}return!1}function Ir(e){let t="$'";for(let s=0;s<e.length;s++){let r=e[s],n=e.charCodeAt(s);n===7?t+="\\a":n===8?t+="\\b":n===9?t+="\\t":n===10?t+="\\n":n===11?t+="\\v":n===12?t+="\\f":n===13?t+="\\r":n===27?t+="\\e":n===39?t+="\\'":n===92?t+="\\\\":n<32||n===127?t+=`\\${n.toString(8).padStart(3,"0")}`:t+=r}return t+="'",t}function on(e){return Dr(e)?Ir(e):/^[a-zA-Z0-9_/.:\-@%+,=]*$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function _t(e){return Dr(e)?Ir(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Cr(e){return Dr(e)?Ir(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function tl(e,t){let s="";return e.state.integerVars?.has(t)&&(s+="i"),e.state.lowercaseVars?.has(t)&&(s+="l"),ee(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 Rr(e){return e===""?"''":/[\s'\\]/.test(e)?`'${e.replace(/'/g,"'\\''")}'`:e}function sl(e,t){let s="",r="",n=!1;for(let i of t){let a=tl(e,i);if(e.state.associativeArrays?.has(i)){let c=Ze(e,i);if(c.length===0)s+=`declare -A ${i}=()
155
+ `;else{let f=c.map(d=>{let h=e.state.env.get(`${i}_${d}`)??"",p=Rr(h);return`['${d}']=${p}`});s+=`declare -A ${i}=(${f.join(" ")})
156
+ `}continue}let o=fe(e,i);if(o.length>0){let c=o.map(f=>{let d=e.state.env.get(`${i}_${f}`)??"";return`[${f}]=${_t(d)}`});s+=`declare -a ${i}=(${c.join(" ")})
83
157
  `;continue}if(e.state.env.has(`${i}__length`)){s+=`declare -a ${i}=()
84
- `;continue}let c=e.state.env.get(i);if(c!==void 0)s+=`declare ${a} ${i}=${Ys(c)}
85
- `;else{let u=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);u||f?s+=`declare ${a} ${i}
86
- `:(n+=`bash: declare: ${i}: not found
87
- `,r=!0)}}return k(s,n,r?1:0)}function Lr(e,t){let{filterExport:s,filterReadonly:n,filterNameref:r,filterIndexedArray:i,filterAssocArray:a}=t,o=s||n||r||i||a,l="",c=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);c.add(h);continue}let d=f.lastIndexOf("_");if(d>0){let h=f.slice(0,d),y=f.slice(d+1);if(/^\d+$/.test(y)||e.state.associativeArrays?.has(h)){c.add(h);continue}}c.add(f)}if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())c.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)c.add(f);let u=Array.from(c).sort();for(let f of u){let d=xr(e,f),h=e.state.associativeArrays?.has(f),y=ne(e,f),p=!h&&(y.length>0||e.state.env.has(`${f}__length`));if(o&&(a&&!h||i&&!p||s&&!e.state.exportedVars?.has(f)||n&&!e.state.readonlyVars?.has(f)||r&&!ge(e,f)))continue;if(h){let $=Me(e,f);if($.length===0)l+=`declare -A ${f}=()
88
- `;else{let g=$.map(b=>{let m=e.state.env.get(`${f}_${b}`)??"",v=Qs(m);return`['${b}']=${v}`});l+=`declare -A ${f}=(${g.join(" ")})
89
- `}continue}if(y.length>0){let $=y.map(g=>{let b=e.state.env.get(`${f}_${g}`)??"";return`[${g}]=${Ke(b)}`});l+=`declare -a ${f}=(${$.join(" ")})
90
- `;continue}if(e.state.env.has(`${f}__length`)){l+=`declare -a ${f}=()
91
- `;continue}let w=e.state.env.get(f);w!==void 0&&(l+=`declare ${d} ${f}=${Ys(w)}
92
- `)}return F(l)}function Fr(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let n of s){let r=Me(e,n);if(r.length===0)t+=`declare -A ${n}=()
93
- `;else{let i=r.map(a=>{let o=e.state.env.get(`${n}_${a}`)??"",l=Qs(o);return`['${a}']=${l}`});t+=`declare -A ${n}=(${i.join(" ")})
94
- `}}return F(t)}function Mr(e){let t="",s=new Set;for(let r of e.state.env.keys()){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let a=r.slice(0,-8);e.state.associativeArrays?.has(a)||s.add(a);continue}let i=r.lastIndexOf("_");if(i>0){let a=r.slice(0,i),o=r.slice(i+1);/^\d+$/.test(o)&&(e.state.associativeArrays?.has(a)||s.add(a))}}let n=Array.from(s).sort();for(let r of n){let i=ne(e,r);if(i.length===0)t+=`declare -a ${r}=()
95
- `;else{let a=i.map(o=>{let l=e.state.env.get(`${r}_${o}`)??"";return`[${o}]=${Ke(l)}`});t+=`declare -a ${r}=(${a.join(" ")})
96
- `}}return F(t)}function Wr(e){let t="",s=new Set;for(let r of e.state.env.keys()){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let a=r.slice(0,-8);s.add(a);continue}let i=r.lastIndexOf("_");if(i>0){let a=r.slice(0,i),o=r.slice(i+1);if(/^\d+$/.test(o)||e.state.associativeArrays?.has(a)){s.add(a);continue}}s.add(r)}let n=Array.from(s).sort();for(let r of n){if(e.state.associativeArrays?.has(r)||ne(e,r).length>0||e.state.env.has(`${r}__length`))continue;let o=e.state.env.get(r);o!==void 0&&(t+=`${r}=${rs(o)}
97
- `)}return F(t)}function Js(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function $t(e,t){return e.state.integerVars?.has(t)??!1}function en(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function za(e,t){return e.state.lowercaseVars?.has(t)??!1}function tn(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Va(e,t){return e.state.uppercaseVars?.has(t)??!1}function ft(e,t,s){return za(e,t)?s.toLowerCase():Va(e,t)?s.toUpperCase():s}async function zr(e,t){try{let s=new V,n=Q(s,t),r=await j(e,n.expression);return String(r)}catch{return"0"}}function Ba(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let s=t[0],n=s.length;if(e[n]!=="[")return null;let r=0,i=n+1;for(;n<e.length;n++)if(e[n]==="[")r++;else if(e[n]==="]"&&(r--,r===0))break;if(r!==0)return null;let a=e.slice(i,n);if(n++,e[n]!=="=")return null;n++;let o=e.slice(n);return{name:s,indexExpr:a,value:o}}async function sn(e,t){let s=!1,n=!1,r=!1,i=!1,a=!1,o=!1,l=!1,c=!1,u=!1,f=!1,d=!1,h=!1,y=!1,p=!1,w=!1,$=[];for(let N=0;N<t.length;N++){let x=t[N];if(x==="-a")s=!0;else if(x==="-A")n=!0;else if(x==="-r")r=!0;else if(x==="-x")i=!0;else if(x==="-p")a=!0;else if(x==="-n")o=!0;else if(x==="+n")l=!0;else if(x==="+a")c=!0;else if(x==="+x")u=!0;else if(x==="--"){$.push(...t.slice(N+1));break}else if(x.startsWith("+")){for(let C of x.slice(1))if(C==="n")l=!0;else if(C==="a")c=!0;else if(C==="x")u=!0;else if(C!=="r"){if(C!=="i"){if(!(C==="f"||C==="F"))return k("",`bash: typeset: +${C}: invalid option
98
- `,2)}}}else if(x==="-i")f=!0;else if(x==="-l")d=!0;else if(x==="-u")h=!0;else if(x==="-f")y=!0;else if(x==="-F")p=!0;else if(x==="-g")w=!0;else if(x.startsWith("-"))for(let C of x.slice(1))if(C==="a")s=!0;else if(C==="A")n=!0;else if(C==="r")r=!0;else if(C==="x")i=!0;else if(C==="p")a=!0;else if(C==="n")o=!0;else if(C==="i")f=!0;else if(C==="l")d=!0;else if(C==="u")h=!0;else if(C==="f")y=!0;else if(C==="F")p=!0;else if(C==="g")w=!0;else return k("",`bash: typeset: -${C}: invalid option
99
- `,2);else $.push(x)}let b=e.state.localScopes.length>0&&!w,m=N=>{if(!b)return;let x=e.state.localScopes[e.state.localScopes.length-1];x.has(N)||x.set(N,e.state.env.get(N))},v=N=>{if(!b)return;let x=e.state.localScopes[e.state.localScopes.length-1];x.has(N)||x.set(N,e.state.env.get(N));let C=`${N}_`;for(let D of e.state.env.keys())D.startsWith(C)&&!D.includes("__")&&(x.has(D)||x.set(D,e.state.env.get(D)));let P=`${N}__length`;e.state.env.has(P)&&!x.has(P)&&x.set(P,e.state.env.get(P))},E=N=>{b&&Ve(e,N)};if(p){if($.length===0){let C=Array.from(e.state.functions.keys()).sort(),P="";for(let D of C)P+=`declare -f ${D}
100
- `;return F(P)}let N=!0,x="";for(let C of $)e.state.functions.has(C)?x+=`${C}
101
- `:N=!1;return k(x,"",N?0:1)}if(y){if($.length===0){let x="",C=Array.from(e.state.functions.keys()).sort();for(let P of C)x+=`${P} ()
158
+ `;continue}let u=e.state.env.get(i);if(u!==void 0)s+=`declare ${a} ${i}=${Cr(u)}
159
+ `;else{let c=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);c||f?s+=`declare ${a} ${i}
160
+ `:(r+=`bash: declare: ${i}: not found
161
+ `,n=!0)}}return P(s,r,n?1:0)}function nl(e,t){let{filterExport:s,filterReadonly:r,filterNameref:n,filterIndexedArray:i,filterAssocArray:a}=t,l=s||r||n||i||a,o="",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),p=f.slice(d+1);if(/^\d+$/.test(p)||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 c=Array.from(u).sort();for(let f of c){let d=tl(e,f),h=e.state.associativeArrays?.has(f),p=fe(e,f),m=!h&&(p.length>0||e.state.env.has(`${f}__length`));if(l&&(a&&!h||i&&!m||s&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||n&&!ee(e,f)))continue;if(h){let b=Ze(e,f);if(b.length===0)o+=`declare -A ${f}=()
162
+ `;else{let v=b.map(E=>{let w=e.state.env.get(`${f}_${E}`)??"",S=Rr(w);return`['${E}']=${S}`});o+=`declare -A ${f}=(${v.join(" ")})
163
+ `}continue}if(p.length>0){let b=p.map(v=>{let E=e.state.env.get(`${f}_${v}`)??"";return`[${v}]=${_t(E)}`});o+=`declare -a ${f}=(${b.join(" ")})
164
+ `;continue}if(e.state.env.has(`${f}__length`)){o+=`declare -a ${f}=()
165
+ `;continue}let y=e.state.env.get(f);y!==void 0&&(o+=`declare ${d} ${f}=${Cr(y)}
166
+ `)}return H(o)}function rl(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let r of s){let n=Ze(e,r);if(n.length===0)t+=`declare -A ${r}=()
167
+ `;else{let i=n.map(a=>{let l=e.state.env.get(`${r}_${a}`)??"",o=Rr(l);return`['${a}']=${o}`});t+=`declare -A ${r}=(${i.join(" ")})
168
+ `}}return H(t)}function il(e){let t="",s=new Set;for(let n of e.state.env.keys()){if(n.startsWith("BASH_"))continue;if(n.endsWith("__length")){let a=n.slice(0,-8);e.state.associativeArrays?.has(a)||s.add(a);continue}let i=n.lastIndexOf("_");if(i>0){let a=n.slice(0,i),l=n.slice(i+1);/^\d+$/.test(l)&&(e.state.associativeArrays?.has(a)||s.add(a))}}let r=Array.from(s).sort();for(let n of r){let i=fe(e,n);if(i.length===0)t+=`declare -a ${n}=()
169
+ `;else{let a=i.map(l=>{let o=e.state.env.get(`${n}_${l}`)??"";return`[${l}]=${_t(o)}`});t+=`declare -a ${n}=(${a.join(" ")})
170
+ `}}return H(t)}function al(e){let t="",s=new Set;for(let n of e.state.env.keys()){if(n.startsWith("BASH_"))continue;if(n.endsWith("__length")){let a=n.slice(0,-8);s.add(a);continue}let i=n.lastIndexOf("_");if(i>0){let a=n.slice(0,i),l=n.slice(i+1);if(/^\d+$/.test(l)||e.state.associativeArrays?.has(a)){s.add(a);continue}}s.add(n)}let r=Array.from(s).sort();for(let n of r){if(e.state.associativeArrays?.has(n)||fe(e,n).length>0||e.state.env.has(`${n}__length`))continue;let l=e.state.env.get(n);l!==void 0&&(t+=`${n}=${on(l)}
171
+ `)}return H(t)}function xr(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function ls(e,t){return e.state.integerVars?.has(t)??!1}function Or(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function _f(e,t){return e.state.lowercaseVars?.has(t)??!1}function Tr(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Pf(e,t){return e.state.uppercaseVars?.has(t)??!1}function jt(e,t,s){return _f(e,t)?s.toLowerCase():Pf(e,t)?s.toUpperCase():s}async function ol(e,t){try{let s=new V,r=X(s,t),n=await T(e,r.expression);return String(n)}catch{return"0"}}function Df(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let s=t[0],r=s.length;if(e[r]!=="[")return null;let n=0,i=r+1;for(;r<e.length;r++)if(e[r]==="[")n++;else if(e[r]==="]"&&(n--,n===0))break;if(n!==0)return null;let a=e.slice(i,r);if(r++,e[r]!=="=")return null;r++;let l=e.slice(r);return{name:s,indexExpr:a,value:l}}async function Lr(e,t){let s=!1,r=!1,n=!1,i=!1,a=!1,l=!1,o=!1,u=!1,c=!1,f=!1,d=!1,h=!1,p=!1,m=!1,y=!1,b=[];for(let I=0;I<t.length;I++){let L=t[I];if(L==="-a")s=!0;else if(L==="-A")r=!0;else if(L==="-r")n=!0;else if(L==="-x")i=!0;else if(L==="-p")a=!0;else if(L==="-n")l=!0;else if(L==="+n")o=!0;else if(L==="+a")u=!0;else if(L==="+x")c=!0;else if(L==="--"){b.push(...t.slice(I+1));break}else if(L.startsWith("+")){for(let k of L.slice(1))if(k==="n")o=!0;else if(k==="a")u=!0;else if(k==="x")c=!0;else if(k!=="r"){if(k!=="i"){if(!(k==="f"||k==="F"))return P("",`bash: typeset: +${k}: invalid option
172
+ `,2)}}}else if(L==="-i")f=!0;else if(L==="-l")d=!0;else if(L==="-u")h=!0;else if(L==="-f")p=!0;else if(L==="-F")m=!0;else if(L==="-g")y=!0;else if(L.startsWith("-"))for(let k of L.slice(1))if(k==="a")s=!0;else if(k==="A")r=!0;else if(k==="r")n=!0;else if(k==="x")i=!0;else if(k==="p")a=!0;else if(k==="n")l=!0;else if(k==="i")f=!0;else if(k==="l")d=!0;else if(k==="u")h=!0;else if(k==="f")p=!0;else if(k==="F")m=!0;else if(k==="g")y=!0;else return P("",`bash: typeset: -${k}: invalid option
173
+ `,2);else b.push(L)}let E=e.state.localScopes.length>0&&!y,w=I=>{if(!E)return;let L=e.state.localScopes[e.state.localScopes.length-1];L.has(I)||L.set(I,e.state.env.get(I))},S=I=>{if(!E)return;let L=e.state.localScopes[e.state.localScopes.length-1];L.has(I)||L.set(I,e.state.env.get(I));let k=`${I}_`;for(let C of e.state.env.keys())C.startsWith(k)&&!C.includes("__")&&(L.has(C)||L.set(C,e.state.env.get(C)));let D=`${I}__length`;e.state.env.has(D)&&!L.has(D)&&L.set(D,e.state.env.get(D))},A=I=>{E&&vt(e,I)};if(m){if(b.length===0){let k=Array.from(e.state.functions.keys()).sort(),D="";for(let C of k)D+=`declare -f ${C}
174
+ `;return H(D)}let I=!0,L="";for(let k of b)e.state.functions.has(k)?L+=`${k}
175
+ `:I=!1;return P(L,"",I?0:1)}if(p){if(b.length===0){let L="",k=Array.from(e.state.functions.keys()).sort();for(let D of k)L+=`${D} ()
102
176
  {
103
177
  # function body
104
178
  }
105
- `;return F(x)}let N=!0;for(let x of $)e.state.functions.has(x)||(N=!1);return k("","",N?0:1)}if(a&&$.length>0)return Rr(e,$);if(a&&$.length===0)return Lr(e,{filterExport:i,filterReadonly:r,filterNameref:o,filterIndexedArray:s,filterAssocArray:n});if($.length===0&&n&&!a)return Fr(e);if($.length===0&&s&&!a)return Mr(e);if($.length===0&&!a)return Wr(e);let S="",O=0;for(let N of $){let x=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(x&&!c){let A=x[1],T=x[2];if(n&&ne(e,A).length>0){S+=`bash: declare: ${A}: cannot convert indexed to associative array
106
- `,O=1;continue}if((s||!n&&!s)&&e.state.associativeArrays?.has(A)){S+=`bash: declare: ${A}: cannot convert associative to indexed array
107
- `,O=1;continue}if(v(A),n&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(A)),Ce(e,A),e.state.env.delete(A),e.state.env.delete(`${A}__length`),n&&T.includes("[")){let R=Jt(T);for(let[J,z]of R){let K=G(e,z);e.state.env.set(`${A}_${J}`,K)}}else if(n){let R=Ne(T);for(let J=0;J<R.length;J+=2){let z=R[J],K=J+1<R.length?G(e,R[J+1]):"";e.state.env.set(`${A}_${z}`,K)}}else{let R=Ne(T);if(R.some(z=>/^\[[^\]]+\]=/.test(z))){let z=0;for(let K of R){let re=K.match(/^\[([^\]]+)\]=(.*)$/);if(re){let fe=re[1],Qe=re[2],Xi=G(e,Qe),pt;if(/^-?\d+$/.test(fe))pt=Number.parseInt(fe,10);else try{let Yi=new V,Qi=Q(Yi,fe);pt=await j(e,Qi.expression)}catch{pt=0}e.state.env.set(`${A}_${pt}`,Xi),z=pt+1}else{let fe=G(e,K);e.state.env.set(`${A}_${z}`,fe),z++}}}else{for(let z=0;z<R.length;z++)e.state.env.set(`${A}_${z}`,R[z]);e.state.env.set(`${A}__length`,String(R.length))}}E(A),r&&ue(e,A),i&&Ae(e,A);continue}if(l){let A=N.includes("=")?N.slice(0,N.indexOf("=")):N;if(Hn(e,A),!N.includes("="))continue}if(u){let A=N.includes("=")?N.slice(0,N.indexOf("=")):N;if(Ft(e,A),!N.includes("="))continue}let C=Ba(N);if(C){let{name:A,indexExpr:T,value:R}=C,J=ee(e,A);if(J)return J;v(A);let z;try{let re=new V,fe=Q(re,T);z=await j(e,fe.expression)}catch{let re=parseInt(T,10);z=Number.isNaN(re)?0:re}e.state.env.set(`${A}_${z}`,R);let K=parseInt(e.state.env.get(`${A}__length`)??"0",10);z>=K&&e.state.env.set(`${A}__length`,String(z+1)),E(A),r&&ue(e,A),i&&Ae(e,A);continue}let P=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(P&&!c){let A=P[1],T=P[2],R=ee(e,A);if(R)return R;v(A);let J=Ne(T);if(e.state.associativeArrays?.has(A)){let z=Jt(T);for(let[K,re]of z){let fe=G(e,re);e.state.env.set(`${A}_${K}`,fe)}}else{let z=ne(e,A),K=0,re=e.state.env.get(A);z.length===0&&re!==void 0?(e.state.env.set(`${A}_0`,re),e.state.env.delete(A),K=1):z.length>0&&(K=Math.max(...z)+1);for(let Qe=0;Qe<J.length;Qe++)e.state.env.set(`${A}_${K+Qe}`,G(e,J[Qe]));let fe=K+J.length;e.state.env.set(`${A}__length`,String(fe))}E(A),r&&ue(e,A),i&&Ae(e,A);continue}let D=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(D){let A=D[1],T=G(e,D[2]),R=ee(e,A);if(R)return R;m(A),f&&Js(e,A),d&&en(e,A),h&&tn(e,A);let z=ne(e,A).length>0||e.state.associativeArrays?.has(A);if($t(e,A)){let K=e.state.env.get(A)??"0",re=parseInt(K,10)||0,fe=parseInt(await zr(e,T),10)||0;T=String(re+fe),e.state.env.set(A,T)}else if(z){T=ft(e,A,T);let K=`${A}_0`,re=e.state.env.get(K)??"";e.state.env.set(K,re+T)}else{T=ft(e,A,T);let K=e.state.env.get(A)??"";e.state.env.set(A,K+T)}E(A),r&&ue(e,A),i&&Ae(e,A),e.state.options.allexport&&!u&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(A));continue}if(N.includes("=")){let A=N.indexOf("="),T=N.slice(0,A),R=N.slice(A+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(T)){S+=`bash: typeset: \`${T}': not a valid identifier
108
- `,O=1;continue}let J=ee(e,T);if(J)return J;if(m(T),o){if(R!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(R)){S+=`bash: declare: \`${R}': invalid variable name for name reference
109
- `,O=1;continue}e.state.env.set(T,R),Ie(e,T),R!==""&&_s(e,R)&&As(e,T),E(T),r&&ue(e,T),i&&Ae(e,T);continue}if(f&&Js(e,T),d&&en(e,T),h&&tn(e,T),$t(e,T)&&(R=await zr(e,R)),R=ft(e,T,R),ge(e,T)){let z=We(e,T);z&&z!==T?e.state.env.set(z,R):e.state.env.set(T,R)}else e.state.env.set(T,R);E(T),r&&ue(e,T),i&&Ae(e,T),e.state.options.allexport&&!u&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(T))}else{let A=N;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(A)){S+=`bash: typeset: \`${A}': not a valid identifier
110
- `,O=1;continue}if(s||n?v(A):m(A),o){Ie(e,A);let R=e.state.env.get(A);R!==void 0&&R!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(R)?Un(e,A):R&&_s(e,R)&&As(e,A),E(A),r&&ue(e,A),i&&Ae(e,A);continue}if(f&&Js(e,A),d&&en(e,A),h&&tn(e,A),n){if(ne(e,A).length>0){S+=`bash: declare: ${A}: cannot convert indexed to associative array
111
- `,O=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(A)}let T=Array.from(e.state.env.keys()).some(R=>R.startsWith(`${A}_`)&&!R.startsWith(`${A}__length`));!e.state.env.has(A)&&!T&&(s||n?e.state.env.set(`${A}__length`,"0"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(A))),E(A),r&&ue(e,A),i&&Ae(e,A)}}return k("",S,O)}async function nn(e,t){let s=!1,n=!1,r=!1,i=[];for(let a=0;a<t.length;a++){let o=t[a];if(o==="-a")s=!0;else if(o==="-A")n=!0;else if(o==="-p")r=!0;else if(o==="--"){i.push(...t.slice(a+1));break}else o.startsWith("-")||i.push(o)}if(i.length===0){let a="",o=Array.from(e.state.readonlyVars||[]).sort();for(let l of o){let c=e.state.env.get(l);if(c!==void 0){let u=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${l}="${u}"
112
- `}}return F(a)}for(let a of i){let o=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(o){let f=o[1],d=o[2],h=ee(e,f);if(h)return h;let y=Ne(d);if(e.state.associativeArrays?.has(f)){let p=Jt(d);for(let[w,$]of p){let g=G(e,$);e.state.env.set(`${f}_${w}`,g)}}else{let p=ne(e,f),w=0,$=e.state.env.get(f);p.length===0&&$!==void 0?(e.state.env.set(`${f}_0`,$),e.state.env.delete(f),w=1):p.length>0&&(w=Math.max(...p)+1);for(let b=0;b<y.length;b++)e.state.env.set(`${f}_${w+b}`,G(e,y[b]));let g=w+y.length;e.state.env.set(`${f}__length`,String(g))}ue(e,f);continue}let l=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(l){let f=l[1],d=G(e,l[2]),h=ee(e,f);if(h)return h;let y=e.state.env.get(f)??"";e.state.env.set(f,y+d),ue(e,f);continue}let c=Ar(a);if(c.value===void 0&&!c.isArray){ue(e,c.name);continue}let u=await _r(e,c,{makeReadonly:!0});if(u)return u}return M}function rn(e){return e.state.directoryStack??=[],e.state.directoryStack}function Et(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function ja(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 an(e,t){let s=rn(e),n;for(let o=0;o<t.length;o++){let l=t[o];if(l==="--"){if(o+1<t.length){if(n!==void 0)return _(`bash: pushd: too many arguments
113
- `,2);n=t[o+1],o++}}else{if(l.startsWith("-")&&l!=="-")return _(`bash: pushd: ${l}: invalid option
114
- `,2);if(n!==void 0)return _(`bash: pushd: too many arguments
115
- `,2);n=l}}if(n===void 0){if(s.length<2)return _(`bash: pushd: no other directory
116
- `,1);let o=s[0];s[0]=s[1],s[1]=o,n=s[0]}let r;if(n.startsWith("/"))r=n;else if(n===".."){let o=e.state.cwd.split("/").filter(l=>l);o.pop(),r=`/${o.join("/")}`}else n==="."?r=e.state.cwd:n.startsWith("~")?r=(e.state.env.get("HOME")||"/")+n.slice(1):r=`${e.state.cwd}/${n}`;r=ja(r);try{if(!(await e.fs.stat(r)).isDirectory)return _(`bash: pushd: ${n}: Not a directory
117
- `,1)}catch{return _(`bash: pushd: ${n}: No such file or directory
118
- `,1)}s.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.set("PWD",r),e.state.env.set("OLDPWD",e.state.previousDir);let i=e.state.env.get("HOME")||"",a=`${[r,...s].map(o=>Et(o,i)).join(" ")}
119
- `;return F(a)}function on(e,t){let s=rn(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?_(`bash: popd: ${a}: invalid option
179
+ `;return H(L)}let I=!0;for(let L of b)e.state.functions.has(L)||(I=!1);return P("","",I?0:1)}if(a&&b.length>0)return sl(e,b);if(a&&b.length===0)return nl(e,{filterExport:i,filterReadonly:n,filterNameref:l,filterIndexedArray:s,filterAssocArray:r});if(b.length===0&&r&&!a)return rl(e);if(b.length===0&&s&&!a)return il(e);if(b.length===0&&!a)return al(e);let $="",R=0;for(let I of b){let L=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(L&&!u){let N=L[1],O=L[2];if(r&&fe(e,N).length>0){$+=`bash: declare: ${N}: cannot convert indexed to associative array
180
+ `,R=1;continue}if((s||!r&&!s)&&e.state.associativeArrays?.has(N)){$+=`bash: declare: ${N}: cannot convert associative to indexed array
181
+ `,R=1;continue}if(S(N),r&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(N)),Xe(e,N),e.state.env.delete(N),e.state.env.delete(`${N}__length`),r&&O.includes("[")){let M=en(O);for(let[q,J]of M){let ce=ue(e,J);e.state.env.set(`${N}_${q}`,ce)}}else if(r){let M=nt(O);for(let q=0;q<M.length;q+=2){let J=M[q],ce=q+1<M.length?ue(e,M[q+1]):"";e.state.env.set(`${N}_${J}`,ce)}}else{let M=nt(O);if(M.some(J=>/^\[[^\]]+\]=/.test(J))){let J=0;for(let ce of M){let pe=ce.match(/^\[([^\]]+)\]=(.*)$/);if(pe){let De=pe[1],It=pe[2],yc=ue(e,It),Kt;if(/^-?\d+$/.test(De))Kt=Number.parseInt(De,10);else try{let wc=new V,Ec=X(wc,De);Kt=await T(e,Ec.expression)}catch{Kt=0}e.state.env.set(`${N}_${Kt}`,yc),J=Kt+1}else{let De=ue(e,ce);e.state.env.set(`${N}_${J}`,De),J++}}}else{for(let J=0;J<M.length;J++)e.state.env.set(`${N}_${J}`,M[J]);e.state.env.set(`${N}__length`,String(M.length))}}A(N),n&&Pe(e,N),i&&je(e,N);continue}if(o){let N=I.includes("=")?I.slice(0,I.indexOf("=")):I;if(Sa(e,N),!I.includes("="))continue}if(c){let N=I.includes("=")?I.slice(0,I.indexOf("=")):I;if(Os(e,N),!I.includes("="))continue}let k=Df(I);if(k){let{name:N,indexExpr:O,value:M}=k,q=me(e,N);if(q)return q;S(N);let J;try{let pe=new V,De=X(pe,O);J=await T(e,De.expression)}catch{let pe=parseInt(O,10);J=Number.isNaN(pe)?0:pe}e.state.env.set(`${N}_${J}`,M);let ce=parseInt(e.state.env.get(`${N}__length`)??"0",10);J>=ce&&e.state.env.set(`${N}__length`,String(J+1)),A(N),n&&Pe(e,N),i&&je(e,N);continue}let D=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(D&&!u){let N=D[1],O=D[2],M=me(e,N);if(M)return M;S(N);let q=nt(O);if(e.state.associativeArrays?.has(N)){let J=en(O);for(let[ce,pe]of J){let De=ue(e,pe);e.state.env.set(`${N}_${ce}`,De)}}else{let J=fe(e,N),ce=0,pe=e.state.env.get(N);J.length===0&&pe!==void 0?(e.state.env.set(`${N}_0`,pe),e.state.env.delete(N),ce=1):J.length>0&&(ce=Math.max(...J)+1);for(let It=0;It<q.length;It++)e.state.env.set(`${N}_${ce+It}`,ue(e,q[It]));let De=ce+q.length;e.state.env.set(`${N}__length`,String(De))}A(N),n&&Pe(e,N),i&&je(e,N);continue}let C=I.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(C){let N=C[1],O=ue(e,C[2]),M=me(e,N);if(M)return M;w(N),f&&xr(e,N),d&&Or(e,N),h&&Tr(e,N);let J=fe(e,N).length>0||e.state.associativeArrays?.has(N);if(ls(e,N)){let ce=e.state.env.get(N)??"0",pe=parseInt(ce,10)||0,De=parseInt(await ol(e,O),10)||0;O=String(pe+De),e.state.env.set(N,O)}else if(J){O=jt(e,N,O);let ce=`${N}_0`,pe=e.state.env.get(ce)??"";e.state.env.set(ce,pe+O)}else{O=jt(e,N,O);let ce=e.state.env.get(N)??"";e.state.env.set(N,ce+O)}A(N),n&&Pe(e,N),i&&je(e,N),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(N));continue}if(I.includes("=")){let N=I.indexOf("="),O=I.slice(0,N),M=I.slice(N+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(O)){$+=`bash: typeset: \`${O}': not a valid identifier
182
+ `,R=1;continue}let q=me(e,O);if(q)return q;if(w(O),l){if(M!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(M)){$+=`bash: declare: \`${M}': invalid variable name for name reference
183
+ `,R=1;continue}e.state.env.set(O,M),lt(e,O),M!==""&&Rs(e,M)&&ar(e,O),A(O),n&&Pe(e,O),i&&je(e,O);continue}if(f&&xr(e,O),d&&Or(e,O),h&&Tr(e,O),ls(e,O)&&(M=await ol(e,M)),M=jt(e,O,M),ee(e,O)){let J=Se(e,O);J&&J!==O?e.state.env.set(J,M):e.state.env.set(O,M)}else e.state.env.set(O,M);A(O),n&&Pe(e,O),i&&je(e,O),e.state.options.allexport&&!c&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(O))}else{let N=I;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(N)){$+=`bash: typeset: \`${N}': not a valid identifier
184
+ `,R=1;continue}if(s||r?S(N):w(N),l){lt(e,N);let M=e.state.env.get(N);M!==void 0&&M!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(M)?Aa(e,N):M&&Rs(e,M)&&ar(e,N),A(N),n&&Pe(e,N),i&&je(e,N);continue}if(f&&xr(e,N),d&&Or(e,N),h&&Tr(e,N),r){if(fe(e,N).length>0){$+=`bash: declare: ${N}: cannot convert indexed to associative array
185
+ `,R=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(N)}let O=Array.from(e.state.env.keys()).some(M=>M.startsWith(`${N}_`)&&!M.startsWith(`${N}__length`));!e.state.env.has(N)&&!O&&(s||r?e.state.env.set(`${N}__length`,"0"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(N))),A(N),n&&Pe(e,N),i&&je(e,N)}}return P("",$,R)}async function Wr(e,t){let s=!1,r=!1,n=!1,i=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-a")s=!0;else if(l==="-A")r=!0;else if(l==="-p")n=!0;else if(l==="--"){i.push(...t.slice(a+1));break}else l.startsWith("-")||i.push(l)}if(i.length===0){let a="",l=Array.from(e.state.readonlyVars||[]).sort();for(let o of l){let u=e.state.env.get(o);if(u!==void 0){let c=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${o}="${c}"
186
+ `}}return H(a)}for(let a of i){let l=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(l){let f=l[1],d=l[2],h=me(e,f);if(h)return h;let p=nt(d);if(e.state.associativeArrays?.has(f)){let m=en(d);for(let[y,b]of m){let v=ue(e,b);e.state.env.set(`${f}_${y}`,v)}}else{let m=fe(e,f),y=0,b=e.state.env.get(f);m.length===0&&b!==void 0?(e.state.env.set(`${f}_0`,b),e.state.env.delete(f),y=1):m.length>0&&(y=Math.max(...m)+1);for(let E=0;E<p.length;E++)e.state.env.set(`${f}_${y+E}`,ue(e,p[E]));let v=y+p.length;e.state.env.set(`${f}__length`,String(v))}Pe(e,f);continue}let o=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(o){let f=o[1],d=ue(e,o[2]),h=me(e,f);if(h)return h;let p=e.state.env.get(f)??"";e.state.env.set(f,p+d),Pe(e,f);continue}let u=Zo(a);if(u.value===void 0&&!u.isArray){Pe(e,u.name);continue}let c=await Ho(e,u,{makeReadonly:!0});if(c)return c}return G}function Mr(e){return e.state.directoryStack??=[],e.state.directoryStack}function cs(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function If(e){let t=e.split("/").filter(r=>r&&r!=="."),s=[];for(let r of t)r===".."?s.pop():s.push(r);return`/${s.join("/")}`}async function Fr(e,t){let s=Mr(e),r;for(let l=0;l<t.length;l++){let o=t[l];if(o==="--"){if(l+1<t.length){if(r!==void 0)return _(`bash: pushd: too many arguments
187
+ `,2);r=t[l+1],l++}}else{if(o.startsWith("-")&&o!=="-")return _(`bash: pushd: ${o}: invalid option
188
+ `,2);if(r!==void 0)return _(`bash: pushd: too many arguments
189
+ `,2);r=o}}if(r===void 0){if(s.length<2)return _(`bash: pushd: no other directory
190
+ `,1);let l=s[0];s[0]=s[1],s[1]=l,r=s[0]}let n;if(r.startsWith("/"))n=r;else if(r===".."){let l=e.state.cwd.split("/").filter(o=>o);l.pop(),n=`/${l.join("/")}`}else r==="."?n=e.state.cwd:r.startsWith("~")?n=(e.state.env.get("HOME")||"/")+r.slice(1):n=`${e.state.cwd}/${r}`;n=If(n);try{if(!(await e.fs.stat(n)).isDirectory)return _(`bash: pushd: ${r}: Not a directory
191
+ `,1)}catch{return _(`bash: pushd: ${r}: No such file or directory
192
+ `,1)}s.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=n,e.state.env.set("PWD",n),e.state.env.set("OLDPWD",e.state.previousDir);let i=e.state.env.get("HOME")||"",a=`${[n,...s].map(l=>cs(l,i)).join(" ")}
193
+ `;return H(a)}function Vr(e,t){let s=Mr(e);for(let a of t)if(a!=="--")return a.startsWith("-")&&a!=="-"?_(`bash: popd: ${a}: invalid option
120
194
  `,2):_(`bash: popd: too many arguments
121
195
  `,2);if(s.length===0)return _(`bash: popd: directory stack empty
122
- `,1);let n=s.shift();if(!n)return _(`bash: popd: directory stack empty
123
- `,1);e.state.previousDir=e.state.cwd,e.state.cwd=n,e.state.env.set("PWD",n),e.state.env.set("OLDPWD",e.state.previousDir);let r=e.state.env.get("HOME")||"",i=`${[n,...s].map(a=>Et(a,r)).join(" ")}
124
- `;return F(i)}function ln(e,t){let s=rn(e),n=!1,r=!1,i=!1,a=!1;for(let u of t)if(u!=="--")if(u.startsWith("-"))for(let f of u.slice(1))if(f==="c")n=!0;else if(f==="l")r=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,a=!0;else return _(`bash: dirs: -${f}: invalid option
196
+ `,1);let r=s.shift();if(!r)return _(`bash: popd: directory stack empty
197
+ `,1);e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.set("PWD",r),e.state.env.set("OLDPWD",e.state.previousDir);let n=e.state.env.get("HOME")||"",i=`${[r,...s].map(a=>cs(a,n)).join(" ")}
198
+ `;return H(i)}function zr(e,t){let s=Mr(e),r=!1,n=!1,i=!1,a=!1;for(let c of t)if(c!=="--")if(c.startsWith("-"))for(let f of c.slice(1))if(f==="c")r=!0;else if(f==="l")n=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,a=!0;else return _(`bash: dirs: -${f}: invalid option
125
199
  `,2);else return _(`bash: dirs: too many arguments
126
- `,1);if(n)return e.state.directoryStack=[],M;let o=[e.state.cwd,...s],l=e.state.env.get("HOME")||"",c;return a?(c=o.map((u,f)=>{let d=r?u:Et(u,l);return` ${f} ${d}`}).join(`
127
- `),c+=`
128
- `):i?c=o.map(u=>r?u:Et(u,l)).join(`
200
+ `,1);if(r)return e.state.directoryStack=[],G;let l=[e.state.cwd,...s],o=e.state.env.get("HOME")||"",u;return a?(u=l.map((c,f)=>{let d=n?c:cs(c,o);return` ${f} ${d}`}).join(`
201
+ `),u+=`
202
+ `):i?u=l.map(c=>n?c:cs(c,o)).join(`
129
203
  `)+`
130
- `:c=o.map(u=>r?u:Et(u,l)).join(" ")+`
131
- `,F(c)}async function is(e,t,s){let n=t;if(n.length>0){let o=n[0];if(o==="--")n=n.slice(1);else if(o.startsWith("-")&&o!=="-"&&o.length>1)return _(`bash: eval: ${o}: invalid option
204
+ `:u=l.map(c=>n?c:cs(c,o)).join(" ")+`
205
+ `,H(u)}async function ln(e,t,s){let r=t;if(r.length>0){let l=r[0];if(l==="--")r=r.slice(1);else if(l.startsWith("-")&&l!=="-"&&l.length>1)return _(`bash: eval: ${l}: invalid option
132
206
  eval: usage: eval [arg ...]
133
- `,2)}if(n.length===0)return M;let r=n.join(" ");if(r.trim()==="")return M;let i=e.state.groupStdin,a=s??e.state.groupStdin;a!==void 0&&(e.state.groupStdin=a);try{let o=Ee(r);return await e.executeScript(o)}catch(o){if(o instanceof de||o instanceof he||o instanceof ce||o instanceof B)throw o;if(o.name==="ParseException")return _(`bash: eval: ${o.message}
134
- `);throw o}finally{e.state.groupStdin=i}}function cn(e,t){let s,n="";if(t.length===0)s=e.state.lastExitCode;else{let r=t[0],i=Number.parseInt(r,10);r===""||Number.isNaN(i)||!/^-?\d+$/.test(r)?(n=`bash: exit: ${r}: numeric argument required
135
- `,s=2):s=(i%256+256)%256}throw new B(s,"",n)}function un(e,t){let s=!1,n=[];for(let a of t)a==="-n"?s=!0:a==="-p"||a==="--"||n.push(a);if(n.length===0&&!s){let a="",o=e.state.exportedVars??new Set,l=Array.from(o).sort();for(let c of l){let u=e.state.env.get(c);if(u!==void 0){let f=u.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -x ${c}="${f}"
136
- `}}return F(a)}if(s){for(let a of n){let o,l;if(a.includes("=")){let c=a.indexOf("=");o=a.slice(0,c),l=G(e,a.slice(c+1)),e.state.env.set(o,l)}else o=a;Ft(e,o)}return M}let r="",i=0;for(let a of n){let o,l,c=!1,u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(u)o=u[1],l=G(e,u[2]),c=!0;else if(a.includes("=")){let f=a.indexOf("=");o=a.slice(0,f),l=G(e,a.slice(f+1))}else o=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){r+=`bash: export: \`${a}': not a valid identifier
137
- `,i=1;continue}if(l!==void 0)if(c){let f=e.state.env.get(o)??"";e.state.env.set(o,f+l)}else e.state.env.set(o,l);else e.state.env.has(o)||e.state.env.set(o,"");Ae(e,o)}return k("",r,i)}function as(e,t){if(t.length<2)return _(`bash: getopts: usage: getopts optstring name [arg ...]
138
- `);let s=t[0],n=t[1],r=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n),i=s.startsWith(":"),a=i?s.slice(1):s,o;if(t.length>2)o=t.slice(2);else{let p=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let w=1;w<=p;w++)o.push(e.state.env.get(String(w))||"")}let l=Number.parseInt(e.state.env.get("OPTIND")||"1",10);l<1&&(l=1);let c=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),l>o.length)return r||e.state.env.set(n,"?"),e.state.env.set("OPTIND",String(o.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:r?2:1,stdout:"",stderr:""};let u=o[l-1];if(!u||u==="-"||!u.startsWith("-"))return r||e.state.env.set(n,"?"),{exitCode:r?2:1,stdout:"",stderr:""};if(u==="--")return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),r||e.state.env.set(n,"?"),{exitCode:r?2:1,stdout:"",stderr:""};let f=c===0?1:c,d=u[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),as(e,t);let h=a.indexOf(d);if(h===-1){let p="";return i?e.state.env.set("OPTARG",d):p=`bash: illegal option -- ${d}
139
- `,r||e.state.env.set(n,"?"),f+1<u.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0")),{exitCode:r?2:0,stdout:"",stderr:p}}if(h+1<a.length&&a[h+1]===":")if(f+1<u.length)e.state.env.set("OPTARG",u.slice(f+1)),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0");else{if(l>=o.length){let p="";return i?(e.state.env.set("OPTARG",d),r||e.state.env.set(n,":")):(p=`bash: option requires an argument -- ${d}
140
- `,r||e.state.env.set(n,"?")),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:r?2:0,stdout:"",stderr:p}}e.state.env.set("OPTARG",o[l]),e.state.env.set("OPTIND",String(l+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1<u.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return r||e.state.env.set(n,d),{exitCode:r?2:0,stdout:"",stderr:""}}async function fn(e,t){e.state.hashTable||(e.state.hashTable=new Map);let s=!1,n=!1,r=!1,i=!1,a=!1,o="",l=[],c=0;for(;c<t.length;){let y=t[c];if(y==="--"){c++,l.push(...t.slice(c));break}if(y==="-r")s=!0,c++;else if(y==="-d")n=!0,c++;else if(y==="-l")r=!0,c++;else if(y==="-t")a=!0,c++;else if(y==="-p"){if(i=!0,c++,c>=t.length)return _(`bash: hash: -p: option requires an argument
141
- `,1);o=t[c],c++}else if(y.startsWith("-")&&y.length>1){for(let p of y.slice(1))if(p==="r")s=!0;else if(p==="d")n=!0;else if(p==="l")r=!0;else if(p==="t")a=!0;else return p==="p"?_(`bash: hash: -p: option requires an argument
142
- `,1):_(`bash: hash: -${p}: invalid option
143
- `,1);c++}else l.push(y),c++}if(s)return e.state.hashTable.clear(),M;if(n){if(l.length===0)return _(`bash: hash: -d: option requires an argument
144
- `,1);let y=!1,p="";for(let w of l)e.state.hashTable.has(w)?e.state.hashTable.delete(w):(p+=`bash: hash: ${w}: not found
145
- `,y=!0);return y?_(p,1):M}if(a){if(l.length===0)return _(`bash: hash: -t: option requires an argument
146
- `,1);let y="",p=!1,w="";for(let $ of l){let g=e.state.hashTable.get($);g?l.length>1?y+=`${$} ${g}
147
- `:y+=`${g}
148
- `:(w+=`bash: hash: ${$}: not found
149
- `,p=!0)}return p?{exitCode:1,stdout:y,stderr:w}:F(y)}if(i){if(l.length===0)return _(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
150
- `,1);let y=l[0];return e.state.hashTable.set(y,o),M}if(l.length===0){if(e.state.hashTable.size===0)return F(`hash: hash table empty
151
- `);let y="";if(r)for(let[p,w]of e.state.hashTable)y+=`builtin hash -p ${w} ${p}
152
- `;else{y=`hits command
153
- `;for(let[,p]of e.state.hashTable)y+=` 1 ${p}
154
- `}return F(y)}let u=!1,f="",h=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let y of l){if(y.includes("/")){f+=`bash: hash: ${y}: cannot use / in name
155
- `,u=!0;continue}let p=!1;for(let w of h){if(!w)continue;let $=`${w}/${y}`;if(await e.fs.exists($)){e.state.hashTable.set(y,$),p=!0;break}}p||(f+=`bash: hash: ${y}: not found
156
- `,u=!0)}return u?_(f,1):M}var Vr=new Map([[":",[": [arguments]",`Null command.
207
+ `,2)}if(r.length===0)return G;let n=r.join(" ");if(n.trim()==="")return G;let i=e.state.groupStdin,a=s??e.state.groupStdin;a!==void 0&&(e.state.groupStdin=a);try{let l=Ue(n);return await e.executeScript(l)}catch(l){if(l instanceof Ie||l instanceof Ce||l instanceof Ne||l instanceof U)throw l;if(l.name==="ParseException")return _(`bash: eval: ${l.message}
208
+ `);throw l}finally{e.state.groupStdin=i}}function Br(e,t){let s,r="";if(t.length===0)s=e.state.lastExitCode;else{let n=t[0],i=Number.parseInt(n,10);n===""||Number.isNaN(i)||!/^-?\d+$/.test(n)?(r=`bash: exit: ${n}: numeric argument required
209
+ `,s=2):s=(i%256+256)%256}throw new U(s,"",r)}function qr(e,t){let s=!1,r=[];for(let a of t)a==="-n"?s=!0:a==="-p"||a==="--"||r.push(a);if(r.length===0&&!s){let a="",l=e.state.exportedVars??new Set,o=Array.from(l).sort();for(let u of o){let c=e.state.env.get(u);if(c!==void 0){let f=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -x ${u}="${f}"
210
+ `}}return H(a)}if(s){for(let a of r){let l,o;if(a.includes("=")){let u=a.indexOf("=");l=a.slice(0,u),o=ue(e,a.slice(u+1)),e.state.env.set(l,o)}else l=a;Os(e,l)}return G}let n="",i=0;for(let a of r){let l,o,u=!1,c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c)l=c[1],o=ue(e,c[2]),u=!0;else if(a.includes("=")){let f=a.indexOf("=");l=a.slice(0,f),o=ue(e,a.slice(f+1))}else l=a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l)){n+=`bash: export: \`${a}': not a valid identifier
211
+ `,i=1;continue}if(o!==void 0)if(u){let f=e.state.env.get(l)??"";e.state.env.set(l,f+o)}else e.state.env.set(l,o);else e.state.env.has(l)||e.state.env.set(l,"");je(e,l)}return P("",n,i)}function cn(e,t){if(t.length<2)return _(`bash: getopts: usage: getopts optstring name [arg ...]
212
+ `);let s=t[0],r=t[1],n=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r),i=s.startsWith(":"),a=i?s.slice(1):s,l;if(t.length>2)l=t.slice(2);else{let m=Number.parseInt(e.state.env.get("#")||"0",10);l=[];for(let y=1;y<=m;y++)l.push(e.state.env.get(String(y))||"")}let o=Number.parseInt(e.state.env.get("OPTIND")||"1",10);o<1&&(o=1);let u=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),o>l.length)return n||e.state.env.set(r,"?"),e.state.env.set("OPTIND",String(l.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:n?2:1,stdout:"",stderr:""};let c=l[o-1];if(!c||c==="-"||!c.startsWith("-"))return n||e.state.env.set(r,"?"),{exitCode:n?2:1,stdout:"",stderr:""};if(c==="--")return e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),n||e.state.env.set(r,"?"),{exitCode:n?2:1,stdout:"",stderr:""};let f=u===0?1:u,d=c[f];if(!d)return e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),cn(e,t);let h=a.indexOf(d);if(h===-1){let m="";return i?e.state.env.set("OPTARG",d):m=`bash: illegal option -- ${d}
213
+ `,n||e.state.env.set(r,"?"),f+1<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(o))):(e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0")),{exitCode:n?2:0,stdout:"",stderr:m}}if(h+1<a.length&&a[h+1]===":")if(f+1<c.length)e.state.env.set("OPTARG",c.slice(f+1)),e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0");else{if(o>=l.length){let m="";return i?(e.state.env.set("OPTARG",d),n||e.state.env.set(r,":")):(m=`bash: option requires an argument -- ${d}
214
+ `,n||e.state.env.set(r,"?")),e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:n?2:0,stdout:"",stderr:m}}e.state.env.set("OPTARG",l[o]),e.state.env.set("OPTIND",String(o+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(o))):(e.state.env.set("OPTIND",String(o+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return n||e.state.env.set(r,d),{exitCode:n?2:0,stdout:"",stderr:""}}async function Ur(e,t){e.state.hashTable||(e.state.hashTable=new Map);let s=!1,r=!1,n=!1,i=!1,a=!1,l="",o=[],u=0;for(;u<t.length;){let p=t[u];if(p==="--"){u++,o.push(...t.slice(u));break}if(p==="-r")s=!0,u++;else if(p==="-d")r=!0,u++;else if(p==="-l")n=!0,u++;else if(p==="-t")a=!0,u++;else if(p==="-p"){if(i=!0,u++,u>=t.length)return _(`bash: hash: -p: option requires an argument
215
+ `,1);l=t[u],u++}else if(p.startsWith("-")&&p.length>1){for(let m of p.slice(1))if(m==="r")s=!0;else if(m==="d")r=!0;else if(m==="l")n=!0;else if(m==="t")a=!0;else return m==="p"?_(`bash: hash: -p: option requires an argument
216
+ `,1):_(`bash: hash: -${m}: invalid option
217
+ `,1);u++}else o.push(p),u++}if(s)return e.state.hashTable.clear(),G;if(r){if(o.length===0)return _(`bash: hash: -d: option requires an argument
218
+ `,1);let p=!1,m="";for(let y of o)e.state.hashTable.has(y)?e.state.hashTable.delete(y):(m+=`bash: hash: ${y}: not found
219
+ `,p=!0);return p?_(m,1):G}if(a){if(o.length===0)return _(`bash: hash: -t: option requires an argument
220
+ `,1);let p="",m=!1,y="";for(let b of o){let v=e.state.hashTable.get(b);v?o.length>1?p+=`${b} ${v}
221
+ `:p+=`${v}
222
+ `:(y+=`bash: hash: ${b}: not found
223
+ `,m=!0)}return m?{exitCode:1,stdout:p,stderr:y}:H(p)}if(i){if(o.length===0)return _(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
224
+ `,1);let p=o[0];return e.state.hashTable.set(p,l),G}if(o.length===0){if(e.state.hashTable.size===0)return H(`hash: hash table empty
225
+ `);let p="";if(n)for(let[m,y]of e.state.hashTable)p+=`builtin hash -p ${y} ${m}
226
+ `;else{p=`hits command
227
+ `;for(let[,m]of e.state.hashTable)p+=` 1 ${m}
228
+ `}return H(p)}let c=!1,f="",h=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let p of o){if(p.includes("/")){f+=`bash: hash: ${p}: cannot use / in name
229
+ `,c=!0;continue}let m=!1;for(let y of h){if(!y)continue;let b=`${y}/${p}`;if(await e.fs.exists(b)){e.state.hashTable.set(p,b),m=!0;break}}m||(f+=`bash: hash: ${p}: not found
230
+ `,c=!0)}return c?_(f,1):G}var ll=new Map([[":",[": [arguments]",`Null command.
157
231
  No effect; the command does nothing.
158
232
  Exit Status:
159
233
  Always succeeds.`]],[".",[". filename [arguments]",`Execute commands from a file in the current shell.
@@ -498,32 +572,32 @@ eval: usage: eval [arg ...]
498
572
  job specification, and reports its termination status.
499
573
  Exit Status:
500
574
  Returns the status of the last ID; fails if ID is invalid or an invalid
501
- option is given.`]]]),Br=[...Vr.keys()].sort();function dn(e,t){let s=!1,n=[],r=0;for(;r<t.length;){let l=t[r];if(l==="--"){for(r++;r<t.length;)n.push(t[r]),r++;break}if(l.startsWith("-")&&l.length>1){for(let c=1;c<l.length;c++){let u=l[c];if(u==="s")s=!0;else return _(`bash: help: -${u}: invalid option
502
- `,2)}r++}else n.push(l),r++}if(n.length===0)return Ua();let i="",a=!1,o="";for(let l of n){let c=Ha(l);if(c.length===0){o+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
503
- `,a=!0;continue}for(let u of c){let f=Vr.get(u);if(!f)continue;let[d,h]=f;s?i+=`${u}: ${d}
504
- `:i+=`${u}: ${d}
575
+ option is given.`]]]),cl=[...ll.keys()].sort();function Zr(e,t){let s=!1,r=[],n=0;for(;n<t.length;){let o=t[n];if(o==="--"){for(n++;n<t.length;)r.push(t[n]),n++;break}if(o.startsWith("-")&&o.length>1){for(let u=1;u<o.length;u++){let c=o[u];if(c==="s")s=!0;else return _(`bash: help: -${c}: invalid option
576
+ `,2)}n++}else r.push(o),n++}if(r.length===0)return Rf();let i="",a=!1,l="";for(let o of r){let u=Cf(o);if(u.length===0){l+=`bash: help: no help topics match \`${o}'. Try \`help help' or \`man -k ${o}' or \`info ${o}'.
577
+ `,a=!0;continue}for(let c of u){let f=ll.get(c);if(!f)continue;let[d,h]=f;s?i+=`${c}: ${d}
578
+ `:i+=`${c}: ${d}
505
579
  ${h}
506
- `}}return{exitCode:a?1:0,stdout:i,stderr:o}}function Ha(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),s=mt(`^${t}$`);return Br.filter(n=>s.test(n))}function Ua(){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=Br.slice(),n=Math.ceil(s.length/2);for(let r=0;r<n;r++){let i=s[r]||"",a=s[r+n]||"",o=i.padEnd(t);e.push(a?`${o}${a}`:i)}return F(`${e.join(`
580
+ `}}return{exitCode:a?1:0,stdout:i,stderr:l}}function Cf(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),s=ae(`^${t}$`);return cl.filter(r=>s.test(r))}function Rf(){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=cl.slice(),r=Math.ceil(s.length/2);for(let n=0;n<r;n++){let i=s[n]||"",a=s[n+r]||"",l=i.padEnd(t);e.push(a?`${l}${a}`:i)}return H(`${e.join(`
507
581
  `)}
508
- `)}function Za(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 hn(e,t){if(t.length===0)return _(`bash: let: expression expected
509
- `);let s=Za(t),n=0;for(let r of s)try{let a=Ee(`(( ${r} ))`).statements[0];if(a&&a.pipelines.length>0&&a.pipelines[0].commands.length>0){let o=a.pipelines[0].commands[0];o.type==="ArithmeticCommand"&&(n=await j(e,o.expression.expression))}}catch(i){return _(`bash: let: ${r}: ${i.message}
510
- `)}return k("","",n===0?1:0)}async function pn(e,t){if(e.state.localScopes.length===0)return _(`bash: local: can only be used in a function
511
- `);let s=e.state.localScopes[e.state.localScopes.length-1],n="",r=0,i=!1,a=!1,o=!1,l=[];for(let c of t)if(c==="-n")i=!0;else if(c==="-a")a=!0;else if(c==="-p")o=!0;else if(c.startsWith("-")&&!c.includes("="))for(let u of c.slice(1))u==="n"?i=!0:u==="a"?a=!0:u==="p"&&(o=!0);else l.push(c);if(l.length===0){let c="",u=Array.from(s.keys()).filter(f=>!f.includes("_")||!f.match(/_\d+$/)).filter(f=>!f.includes("__length")).sort();for(let f of u){let d=e.state.env.get(f);d!==void 0&&(c+=`${f}=${d}
512
- `)}return k(c,"",0)}for(let c of l){let u,f,d=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){u=d[1];let $=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){n+=`bash: local: \`${c}': not a valid identifier
513
- `,r=1;continue}if(ee(e,u,"bash"),!s.has(u)){s.set(u,e.state.env.get(u));let m=`${u}_`;for(let v of e.state.env.keys())v.startsWith(m)&&!v.includes("__")&&(s.has(v)||s.set(v,e.state.env.get(v)))}let g=`${u}_`;for(let m of e.state.env.keys())m.startsWith(g)&&!m.includes("__")&&e.state.env.delete(m);let b=Ne($);for(let m=0;m<b.length;m++)e.state.env.set(`${u}_${m}`,b[m]);e.state.env.set(`${u}__length`,String(b.length)),Ve(e,u),i&&Ie(e,u);continue}let h=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(h){u=h[1];let $=h[2];if(ee(e,u,"bash"),!s.has(u)){s.set(u,e.state.env.get(u));let S=`${u}_`;for(let N of e.state.env.keys())N.startsWith(S)&&!N.includes("__")&&(s.has(N)||s.set(N,e.state.env.get(N)));let O=`${u}__length`;e.state.env.has(O)&&!s.has(O)&&s.set(O,e.state.env.get(O))}let g=Ne($),b=ne(e,u),m=0,v=e.state.env.get(u);b.length===0&&v!==void 0?(e.state.env.set(`${u}_0`,v),e.state.env.delete(u),m=1):b.length>0&&(m=Math.max(...b)+1);for(let S=0;S<g.length;S++)e.state.env.set(`${u}_${m+S}`,G(e,g[S]));let E=m+g.length;e.state.env.set(`${u}__length`,String(E)),Ve(e,u),i&&Ie(e,u);continue}let y=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(y){u=y[1];let $=G(e,y[2]);ee(e,u,"bash"),s.has(u)||s.set(u,e.state.env.get(u));let g=e.state.env.get(u)??"";e.state.env.set(u,g+$),Ve(e,u),i&&Ie(e,u);continue}let p=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(p){u=p[1];let $=p[2],g=G(e,p[3]);if(ee(e,u,"bash"),!s.has(u)){s.set(u,e.state.env.get(u));let v=`${u}_`;for(let S of e.state.env.keys())S.startsWith(v)&&!S.includes("__")&&(s.has(S)||s.set(S,e.state.env.get(S)));let E=`${u}__length`;e.state.env.has(E)&&!s.has(E)&&s.set(E,e.state.env.get(E))}let b;try{let v=new V,E=Q(v,$);b=await j(e,E.expression)}catch{let v=parseInt($,10);b=Number.isNaN(v)?0:v}e.state.env.set(`${u}_${b}`,g);let m=parseInt(e.state.env.get(`${u}__length`)??"0",10);b>=m&&e.state.env.set(`${u}__length`,String(b+1)),Ve(e,u),i&&Ie(e,u);continue}if(c.includes("=")){let $=c.indexOf("=");u=c.slice(0,$),f=G(e,c.slice($+1))}else u=c;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){n+=`bash: local: \`${c}': not a valid identifier
514
- `,r=1;continue}let w=s.has(u);if(f!==void 0){let $=e.state.env.get(u);if(e.state.tempEnvBindings){let g=e.state.accessedTempEnvVars?.has(u),b=e.state.mutatedTempEnvVars?.has(u);if(!g&&!b)for(let m=e.state.tempEnvBindings.length-1;m>=0;m--){let v=e.state.tempEnvBindings[m];if(v.has(u)){$=v.get(u);break}}}Cr(e,u,$)}if(!w){let $=e.state.env.get(u);if(e.state.tempEnvBindings)for(let g=e.state.tempEnvBindings.length-1;g>=0;g--){let b=e.state.tempEnvBindings[g];if(b.has(u)){$=b.get(u);break}}if(s.set(u,$),a){let g=`${u}_`;for(let m of e.state.env.keys())m.startsWith(g)&&!m.includes("__")&&(s.has(m)||s.set(m,e.state.env.get(m)));let b=`${u}__length`;e.state.env.has(b)&&!s.has(b)&&s.set(b,e.state.env.get(b))}}if(a&&f===void 0){let $=`${u}_`;for(let g of e.state.env.keys())g.startsWith($)&&!g.includes("__")&&e.state.env.delete(g);e.state.env.set(`${u}__length`,"0")}else if(f!==void 0){if(ee(e,u,"bash"),i&&f!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(f)){n+=`bash: local: \`${f}': invalid variable name for name reference
515
- `,r=1;continue}e.state.env.set(u,f),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(u))}else{let $=e.state.tempEnvBindings?.some(g=>g.has(u));!w&&!$&&e.state.env.delete(u)}Ve(e,u),i&&Ie(e,u)}return k("",n,r)}function mn(e,t,s){let n=`
516
- `,r=0,i=0,a=0,o=!1,l="MAPFILE",c=0;for(;c<t.length;){let g=t[c];g==="-d"&&c+1<t.length?(n=t[c+1]===""?"\0":t[c+1]||`
517
- `,c+=2):g==="-n"&&c+1<t.length?(r=Number.parseInt(t[c+1],10)||0,c+=2):g==="-O"&&c+1<t.length?(i=Number.parseInt(t[c+1],10)||0,c+=2):g==="-s"&&c+1<t.length?(a=Number.parseInt(t[c+1],10)||0,c+=2):g==="-t"?(o=!0,c++):g==="-u"||g==="-C"||g==="-c"?c+=2:(g.startsWith("-")||(l=g),c++)}let u=s;!u&&e.state.groupStdin!==void 0&&(u=e.state.groupStdin);let f=[],d=u,h=0,y=0,p=e.limits?.maxArrayElements??1e5;for(;d.length>0;){let g=d.indexOf(n);if(g===-1){if(d.length>0){if(y<a)y++;else if(r===0||h<r){if(i+h>=p)return k("",`mapfile: array element limit exceeded (${p})
518
- `,1);let v=d,E=v.indexOf("\0");E!==-1&&(v=v.substring(0,E)),f.push(v),h++}}break}let b=d.substring(0,g),m=b.indexOf("\0");if(m!==-1&&(b=b.substring(0,m)),!o&&n!=="\0"&&(b+=n),d=d.substring(g+n.length),y<a){y++;continue}if(r>0&&h>=r)break;if(i+h>=p)return k("",`mapfile: array element limit exceeded (${p})
519
- `,1);f.push(b),h++}i===0&&Ce(e,l);for(let g=0;g<f.length;g++)e.state.env.set(`${l}_${i+g}`,f[g]);let w=parseInt(e.state.env.get(`${l}__length`)||"0",10),$=i+f.length;return e.state.env.set(`${l}__length`,String(Math.max(w,$))),e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=""),k("","",0)}function qa(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),a=r+n+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let c=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let u=o.slice(l+1);return{path:i,position:c,content:u}}function Ga(e,t,s){return`__rw__:${e.length}:${e}:${t}:${s}`}function yn(e,t,s,n=-1){let r=!1,i=`
520
- `,a="",o=-1,l=-1,c=null,u=-1,f=-1,d=[],h=0,y=!1,p=(C,P)=>{let D=1;for(;D<C.length;){let A=C[D];if(A==="r")r=!0,D++;else if(A==="s")D++;else{if(A==="d")return D+1<C.length?(i=C.substring(D+1),{nextArgIndex:P+1}):P+1<t.length?(i=t[P+1],{nextArgIndex:P+2}):{nextArgIndex:P+1};if(A==="n"){if(D+1<C.length){let T=C.substring(D+1);return o=Number.parseInt(T,10),(Number.isNaN(o)||o<0)&&(y=!0,o=0),{nextArgIndex:P+1}}else if(P+1<t.length)return o=Number.parseInt(t[P+1],10),(Number.isNaN(o)||o<0)&&(y=!0,o=0),{nextArgIndex:P+2};return{nextArgIndex:P+1}}else if(A==="N"){if(D+1<C.length){let T=C.substring(D+1);return l=Number.parseInt(T,10),(Number.isNaN(l)||l<0)&&(y=!0,l=0),{nextArgIndex:P+1}}else if(P+1<t.length)return l=Number.parseInt(t[P+1],10),(Number.isNaN(l)||l<0)&&(y=!0,l=0),{nextArgIndex:P+2};return{nextArgIndex:P+1}}else{if(A==="a")return D+1<C.length?(c=C.substring(D+1),{nextArgIndex:P+1}):P+1<t.length?(c=t[P+1],{nextArgIndex:P+2}):{nextArgIndex:P+1};if(A==="p")return D+1<C.length?(a=C.substring(D+1),{nextArgIndex:P+1}):P+1<t.length?(a=t[P+1],{nextArgIndex:P+2}):{nextArgIndex:P+1};if(A==="u"){if(D+1<C.length){let T=C.substring(D+1);return u=Number.parseInt(T,10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:P+1}}else if(P+1<t.length)return u=Number.parseInt(t[P+1],10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:P+2};return{nextArgIndex:P+1}}else if(A==="t"){if(D+1<C.length){let T=C.substring(D+1);return f=Number.parseFloat(T),Number.isNaN(f)&&(f=0),{nextArgIndex:P+1}}else if(P+1<t.length)return f=Number.parseFloat(t[P+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:P+2};return{nextArgIndex:P+1}}else if(A==="e"||A==="i"||A==="P"){if(A==="i"&&P+1<t.length)return{nextArgIndex:P+2};D++}else D++}}}return{nextArgIndex:P+1}};for(;h<t.length;){let C=t[h];if(C.startsWith("-")&&C.length>1&&C!=="--"){let P=p(C,h);if(P.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(P.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=P.nextArgIndex}else if(C==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push(C),h++}if(y)return k("","",1);if(d.length===0&&c===null&&d.push("REPLY"),f===0){if(c)Ce(e,c);else{for(let C of d)e.state.env.set(C,"");d.length===0&&e.state.env.set("REPLY","")}return k("","",0)}if(f<0&&f!==-1)return k("","",1);let w=s;u>=0?e.state.fileDescriptors?w=e.state.fileDescriptors.get(u)||"":w="":!w&&e.state.groupStdin!==void 0&&(w=e.state.groupStdin);let $=i===""?"\0":i,g="",b=0,m=!0,v=C=>{if(u>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(u,w.substring(C));else if(n>=0&&e.state.fileDescriptors){let P=e.state.fileDescriptors.get(n);if(P?.startsWith("__rw__:")){let D=qa(P);if(D){let A=D.position+C;e.state.fileDescriptors.set(n,Ga(D.path,A,D.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=w.substring(C))};if(l>=0){let C=Math.min(l,w.length);g=w.substring(0,C),b=C,m=C>=l,v(b);let P=d[0]||"REPLY";e.state.env.set(P,g);for(let D=1;D<d.length;D++)e.state.env.set(d[D],"");return k("","",m?0:1)}else if(o>=0){let C=0,P=0,D=!1;for(;P<w.length&&C<o;){let A=w[P];if(A===$){b=P+1,D=!0;break}if(!r&&A==="\\"&&P+1<w.length){let T=w[P+1];if(T===$&&$===`
521
- `){P+=2,b=P;continue}if(T===$){P+=2,C++,g+=T,b=P;continue}g+=T,P+=2,C++,b=P}else g+=A,P++,C++,b=P}m=C>=o||D,v(b)}else{b=0;let C=0;for(;C<w.length;){let P=w[C];if(P===$){b=C+$.length,m=!0;break}if(!r&&P==="\\"&&C+1<w.length){let D=w[C+1];if(D===`
522
- `){C+=2;continue}if(D===$){g+=D,C+=2;continue}g+=P,g+=D,C+=2;continue}g+=P,C++}if(C>=w.length&&(m=!1,b=C,g.length===0&&w.length===0)){for(let P of d)e.state.env.set(P,"");return c&&Ce(e,c),k("","",1)}v(b)}$===`
523
- `&&g.endsWith(`
524
- `)&&(g=g.slice(0,-1));let E=C=>r?C:C.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",E(g)),k("","",m?0:1);let S=Bn(e.state.env);if(c){let{words:C}=Ss(g,S,void 0,r),P=e.limits?.maxArrayElements??1e5;if(C.length>P)return k("",`read: array element limit exceeded (${P})
525
- `,1);Ce(e,c);for(let D=0;D<C.length;D++)e.state.env.set(`${c}_${D}`,E(C[D]));return k("","",m?0:1)}let O=d.length,{words:N,wordStarts:x}=Ss(g,S,O,r);for(let C=0;C<d.length;C++){let P=d[C];if(C<d.length-1)e.state.env.set(P,E(N[C]??""));else if(C<x.length){let D=g.substring(x[C]);D=jn(D,S,r),D=E(D),e.state.env.set(P,D)}else e.state.env.set(P,"")}return k("","",m?0:1)}function gn(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return _("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 _(`bash: return: ${n}: numeric argument required
526
- `,2);s=(r%256+256)%256}throw new ce(s)}var St=`set: usage: set [-eux] [+eux] [-o option] [+o option]
582
+ `)}function xf(e){let t=[],s="",r=0;for(let n of e){for(let i of n)i==="("?r++:i===")"&&r--;s?s+=` ${n}`:s=n,r===0&&(t.push(s),s="")}return s&&t.push(s),t}async function Hr(e,t){if(t.length===0)return _(`bash: let: expression expected
583
+ `);let s=xf(t),r=0;for(let n of s)try{let a=Ue(`(( ${n} ))`).statements[0];if(a&&a.pipelines.length>0&&a.pipelines[0].commands.length>0){let l=a.pipelines[0].commands[0];l.type==="ArithmeticCommand"&&(r=await T(e,l.expression.expression))}}catch(i){return _(`bash: let: ${n}: ${i.message}
584
+ `)}return P("","",r===0?1:0)}async function jr(e,t){if(e.state.localScopes.length===0)return _(`bash: local: can only be used in a function
585
+ `);let s=e.state.localScopes[e.state.localScopes.length-1],r="",n=0,i=!1,a=!1,l=!1,o=[];for(let u of t)if(u==="-n")i=!0;else if(u==="-a")a=!0;else if(u==="-p")l=!0;else if(u.startsWith("-")&&!u.includes("="))for(let c of u.slice(1))c==="n"?i=!0:c==="a"?a=!0:c==="p"&&(l=!0);else o.push(u);if(o.length===0){let u="",c=Array.from(s.keys()).filter(f=>!f.includes("_")||!f.match(/_\d+$/)).filter(f=>!f.includes("__length")).sort();for(let f of c){let d=e.state.env.get(f);d!==void 0&&(u+=`${f}=${d}
586
+ `)}return P(u,"",0)}for(let u of o){let c,f,d=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){c=d[1];let b=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){r+=`bash: local: \`${u}': not a valid identifier
587
+ `,n=1;continue}if(me(e,c,"bash"),!s.has(c)){s.set(c,e.state.env.get(c));let w=`${c}_`;for(let S of e.state.env.keys())S.startsWith(w)&&!S.includes("__")&&(s.has(S)||s.set(S,e.state.env.get(S)))}let v=`${c}_`;for(let w of e.state.env.keys())w.startsWith(v)&&!w.includes("__")&&e.state.env.delete(w);let E=nt(b);for(let w=0;w<E.length;w++)e.state.env.set(`${c}_${w}`,E[w]);e.state.env.set(`${c}__length`,String(E.length)),vt(e,c),i&&lt(e,c);continue}let h=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(h){c=h[1];let b=h[2];if(me(e,c,"bash"),!s.has(c)){s.set(c,e.state.env.get(c));let $=`${c}_`;for(let I of e.state.env.keys())I.startsWith($)&&!I.includes("__")&&(s.has(I)||s.set(I,e.state.env.get(I)));let R=`${c}__length`;e.state.env.has(R)&&!s.has(R)&&s.set(R,e.state.env.get(R))}let v=nt(b),E=fe(e,c),w=0,S=e.state.env.get(c);E.length===0&&S!==void 0?(e.state.env.set(`${c}_0`,S),e.state.env.delete(c),w=1):E.length>0&&(w=Math.max(...E)+1);for(let $=0;$<v.length;$++)e.state.env.set(`${c}_${w+$}`,ue(e,v[$]));let A=w+v.length;e.state.env.set(`${c}__length`,String(A)),vt(e,c),i&&lt(e,c);continue}let p=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(p){c=p[1];let b=ue(e,p[2]);me(e,c,"bash"),s.has(c)||s.set(c,e.state.env.get(c));let v=e.state.env.get(c)??"";e.state.env.set(c,v+b),vt(e,c),i&&lt(e,c);continue}let m=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(m){c=m[1];let b=m[2],v=ue(e,m[3]);if(me(e,c,"bash"),!s.has(c)){s.set(c,e.state.env.get(c));let S=`${c}_`;for(let $ of e.state.env.keys())$.startsWith(S)&&!$.includes("__")&&(s.has($)||s.set($,e.state.env.get($)));let A=`${c}__length`;e.state.env.has(A)&&!s.has(A)&&s.set(A,e.state.env.get(A))}let E;try{let S=new V,A=X(S,b);E=await T(e,A.expression)}catch{let S=parseInt(b,10);E=Number.isNaN(S)?0:S}e.state.env.set(`${c}_${E}`,v);let w=parseInt(e.state.env.get(`${c}__length`)??"0",10);E>=w&&e.state.env.set(`${c}__length`,String(E+1)),vt(e,c),i&&lt(e,c);continue}if(u.includes("=")){let b=u.indexOf("=");c=u.slice(0,b),f=ue(e,u.slice(b+1))}else c=u;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){r+=`bash: local: \`${u}': not a valid identifier
588
+ `,n=1;continue}let y=s.has(c);if(f!==void 0){let b=e.state.env.get(c);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(c),E=e.state.mutatedTempEnvVars?.has(c);if(!v&&!E)for(let w=e.state.tempEnvBindings.length-1;w>=0;w--){let S=e.state.tempEnvBindings[w];if(S.has(c)){b=S.get(c);break}}}jo(e,c,b)}if(!y){let b=e.state.env.get(c);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let E=e.state.tempEnvBindings[v];if(E.has(c)){b=E.get(c);break}}if(s.set(c,b),a){let v=`${c}_`;for(let w of e.state.env.keys())w.startsWith(v)&&!w.includes("__")&&(s.has(w)||s.set(w,e.state.env.get(w)));let E=`${c}__length`;e.state.env.has(E)&&!s.has(E)&&s.set(E,e.state.env.get(E))}}if(a&&f===void 0){let b=`${c}_`;for(let v of e.state.env.keys())v.startsWith(b)&&!v.includes("__")&&e.state.env.delete(v);e.state.env.set(`${c}__length`,"0")}else if(f!==void 0){if(me(e,c,"bash"),i&&f!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(f)){r+=`bash: local: \`${f}': invalid variable name for name reference
589
+ `,n=1;continue}e.state.env.set(c,f),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(c))}else{let b=e.state.tempEnvBindings?.some(v=>v.has(c));!y&&!b&&e.state.env.delete(c)}vt(e,c),i&&lt(e,c)}return P("",r,n)}function Gr(e,t,s){let r=`
590
+ `,n=0,i=0,a=0,l=!1,o="MAPFILE",u=0;for(;u<t.length;){let v=t[u];v==="-d"&&u+1<t.length?(r=t[u+1]===""?"\0":t[u+1]||`
591
+ `,u+=2):v==="-n"&&u+1<t.length?(n=Number.parseInt(t[u+1],10)||0,u+=2):v==="-O"&&u+1<t.length?(i=Number.parseInt(t[u+1],10)||0,u+=2):v==="-s"&&u+1<t.length?(a=Number.parseInt(t[u+1],10)||0,u+=2):v==="-t"?(l=!0,u++):v==="-u"||v==="-C"||v==="-c"?u+=2:(v.startsWith("-")||(o=v),u++)}let c=s;!c&&e.state.groupStdin!==void 0&&(c=e.state.groupStdin);let f=[],d=c,h=0,p=0,m=e.limits?.maxArrayElements??1e5;for(;d.length>0;){let v=d.indexOf(r);if(v===-1){if(d.length>0){if(p<a)p++;else if(n===0||h<n){if(i+h>=m)return P("",`mapfile: array element limit exceeded (${m})
592
+ `,1);let S=d,A=S.indexOf("\0");A!==-1&&(S=S.substring(0,A)),f.push(S),h++}}break}let E=d.substring(0,v),w=E.indexOf("\0");if(w!==-1&&(E=E.substring(0,w)),!l&&r!=="\0"&&(E+=r),d=d.substring(v+r.length),p<a){p++;continue}if(n>0&&h>=n)break;if(i+h>=m)return P("",`mapfile: array element limit exceeded (${m})
593
+ `,1);f.push(E),h++}i===0&&Xe(e,o);for(let v=0;v<f.length;v++)e.state.env.set(`${o}_${i+v}`,f[v]);let y=parseInt(e.state.env.get(`${o}__length`)||"0",10),b=i+f.length;return e.state.env.set(`${o}__length`,String(Math.max(y,b))),e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=""),P("","",0)}function Of(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let r=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(r)||r<0)return null;let n=s+1,i=t.slice(n,n+r),a=n+r+1,l=t.slice(a),o=l.indexOf(":");if(o===-1)return null;let u=Number.parseInt(l.slice(0,o),10);if(Number.isNaN(u)||u<0)return null;let c=l.slice(o+1);return{path:i,position:u,content:c}}function Tf(e,t,s){return`__rw__:${e.length}:${e}:${t}:${s}`}function Qr(e,t,s,r=-1){let n=!1,i=`
594
+ `,a="",l=-1,o=-1,u=null,c=-1,f=-1,d=[],h=0,p=!1,m=(k,D)=>{let C=1;for(;C<k.length;){let N=k[C];if(N==="r")n=!0,C++;else if(N==="s")C++;else{if(N==="d")return C+1<k.length?(i=k.substring(C+1),{nextArgIndex:D+1}):D+1<t.length?(i=t[D+1],{nextArgIndex:D+2}):{nextArgIndex:D+1};if(N==="n"){if(C+1<k.length){let O=k.substring(C+1);return l=Number.parseInt(O,10),(Number.isNaN(l)||l<0)&&(p=!0,l=0),{nextArgIndex:D+1}}else if(D+1<t.length)return l=Number.parseInt(t[D+1],10),(Number.isNaN(l)||l<0)&&(p=!0,l=0),{nextArgIndex:D+2};return{nextArgIndex:D+1}}else if(N==="N"){if(C+1<k.length){let O=k.substring(C+1);return o=Number.parseInt(O,10),(Number.isNaN(o)||o<0)&&(p=!0,o=0),{nextArgIndex:D+1}}else if(D+1<t.length)return o=Number.parseInt(t[D+1],10),(Number.isNaN(o)||o<0)&&(p=!0,o=0),{nextArgIndex:D+2};return{nextArgIndex:D+1}}else{if(N==="a")return C+1<k.length?(u=k.substring(C+1),{nextArgIndex:D+1}):D+1<t.length?(u=t[D+1],{nextArgIndex:D+2}):{nextArgIndex:D+1};if(N==="p")return C+1<k.length?(a=k.substring(C+1),{nextArgIndex:D+1}):D+1<t.length?(a=t[D+1],{nextArgIndex:D+2}):{nextArgIndex:D+1};if(N==="u"){if(C+1<k.length){let O=k.substring(C+1);return c=Number.parseInt(O,10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:D+1}}else if(D+1<t.length)return c=Number.parseInt(t[D+1],10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:D+2};return{nextArgIndex:D+1}}else if(N==="t"){if(C+1<k.length){let O=k.substring(C+1);return f=Number.parseFloat(O),Number.isNaN(f)&&(f=0),{nextArgIndex:D+1}}else if(D+1<t.length)return f=Number.parseFloat(t[D+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:D+2};return{nextArgIndex:D+1}}else if(N==="e"||N==="i"||N==="P"){if(N==="i"&&D+1<t.length)return{nextArgIndex:D+2};C++}else C++}}}return{nextArgIndex:D+1}};for(;h<t.length;){let k=t[h];if(k.startsWith("-")&&k.length>1&&k!=="--"){let D=m(k,h);if(D.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(D.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=D.nextArgIndex}else if(k==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push(k),h++}if(p)return P("","",1);if(d.length===0&&u===null&&d.push("REPLY"),f===0){if(u)Xe(e,u);else{for(let k of d)e.state.env.set(k,"");d.length===0&&e.state.env.set("REPLY","")}return P("","",0)}if(f<0&&f!==-1)return P("","",1);let y=s;c>=0?e.state.fileDescriptors?y=e.state.fileDescriptors.get(c)||"":y="":!y&&e.state.groupStdin!==void 0&&(y=e.state.groupStdin);let b=i===""?"\0":i,v="",E=0,w=!0,S=k=>{if(c>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(c,y.substring(k));else if(r>=0&&e.state.fileDescriptors){let D=e.state.fileDescriptors.get(r);if(D?.startsWith("__rw__:")){let C=Of(D);if(C){let N=C.position+k;e.state.fileDescriptors.set(r,Tf(C.path,N,C.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=y.substring(k))};if(o>=0){let k=Math.min(o,y.length);v=y.substring(0,k),E=k,w=k>=o,S(E);let D=d[0]||"REPLY";e.state.env.set(D,v);for(let C=1;C<d.length;C++)e.state.env.set(d[C],"");return P("","",w?0:1)}else if(l>=0){let k=0,D=0,C=!1;for(;D<y.length&&k<l;){let N=y[D];if(N===b){E=D+1,C=!0;break}if(!n&&N==="\\"&&D+1<y.length){let O=y[D+1];if(O===b&&b===`
595
+ `){D+=2,E=D;continue}if(O===b){D+=2,k++,v+=O,E=D;continue}v+=O,D+=2,k++,E=D}else v+=N,D++,k++,E=D}w=k>=l||C,S(E)}else{E=0;let k=0;for(;k<y.length;){let D=y[k];if(D===b){E=k+b.length,w=!0;break}if(!n&&D==="\\"&&k+1<y.length){let C=y[k+1];if(C===`
596
+ `){k+=2;continue}if(C===b){v+=C,k+=2;continue}v+=D,v+=C,k+=2;continue}v+=D,k++}if(k>=y.length&&(w=!1,E=k,v.length===0&&y.length===0)){for(let D of d)e.state.env.set(D,"");return u&&Xe(e,u),P("","",1)}S(E)}b===`
597
+ `&&v.endsWith(`
598
+ `)&&(v=v.slice(0,-1));let A=k=>n?k:k.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",A(v)),P("","",w?0:1);let $=he(e.state.env);if(u){let{words:k}=ir(v,$,void 0,n),D=e.limits?.maxArrayElements??1e5;if(k.length>D)return P("",`read: array element limit exceeded (${D})
599
+ `,1);Xe(e,u);for(let C=0;C<k.length;C++)e.state.env.set(`${u}_${C}`,A(k[C]));return P("","",w?0:1)}let R=d.length,{words:I,wordStarts:L}=ir(v,$,R,n);for(let k=0;k<d.length;k++){let D=d[k];if(k<d.length-1)e.state.env.set(D,A(I[k]??""));else if(k<L.length){let C=v.substring(L[k]);C=va(C,$,n),C=A(C),e.state.env.set(D,C)}else e.state.env.set(D,"")}return P("","",w?0:1)}function Kr(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return _("bash: return: can only `return' from a function or sourced script\n");let s=e.state.lastExitCode;if(t.length>0){let r=t[0],n=Number.parseInt(r,10);if(r===""||Number.isNaN(n)||!/^-?\d+$/.test(r))return _(`bash: return: ${r}: numeric argument required
600
+ `,2);s=(n%256+256)%256}throw new Ne(s)}var us=`set: usage: set [-eux] [+eux] [-o option] [+o option]
527
601
  Options:
528
602
  -e Exit immediately if a command exits with non-zero status
529
603
  +e Disable -e
@@ -539,185 +613,185 @@ Options:
539
613
  +o pipefail Disable pipefail
540
614
  -o xtrace Same as -x
541
615
  +o xtrace Disable xtrace
542
- `,jr=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]]),os=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]]),Zr=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],qr=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function wn(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,at(e))}function Ka(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Xa(e,t){let s=ne(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env.get(`${t}_${r}`)??"";return`[${r}]=${Ke(i)}`});return`${t}=(${n.join(" ")})`}function Ya(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Qa(e,t){let s=Me(e,t);if(s.length===0)return`${t}=()`;let n=s.map(r=>{let i=e.state.env.get(`${t}_${r}`)??"";return`[${Ya(r)}]=${Ke(i)}`});return`${t}=(${n.join(" ")} )`}function Ja(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 eo(e){return e.state.associativeArrays??new Set}function Hr(e){let t=Zr.map(n=>`${n.padEnd(16)}${e.state.options[n]?"on":"off"}`),s=qr.map(n=>`${n.padEnd(16)}off`);return`${[...t,...s].sort().join(`
616
+ `,ul=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]]),un=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]]),hl=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],pl=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Xr(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,Mt(e))}function Lf(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Wf(e,t){let s=fe(e,t);if(s.length===0)return`${t}=()`;let r=s.map(n=>{let i=e.state.env.get(`${t}_${n}`)??"";return`[${n}]=${_t(i)}`});return`${t}=(${r.join(" ")})`}function Mf(e){return/^[a-zA-Z0-9_]+$/.test(e)?e:`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}function Ff(e,t){let s=Ze(e,t);if(s.length===0)return`${t}=()`;let r=s.map(n=>{let i=e.state.env.get(`${t}_${n}`)??"";return`[${Mf(n)}]=${_t(i)}`});return`${t}=(${r.join(" ")} )`}function Vf(e){let t=new Set,s=e.state.associativeArrays??new Set;for(let r of e.state.env.keys()){let n=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(n){let i=n[1];s.has(i)||t.add(i)}}return t}function zf(e){return e.state.associativeArrays??new Set}function fl(e){let t=hl.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),s=pl.map(r=>`${r.padEnd(16)}off`);return`${[...t,...s].sort().join(`
543
617
  `)}
544
- `}function Ur(e){let t=Zr.map(n=>`set ${e.state.options[n]?"-o":"+o"} ${n}`),s=qr.map(n=>`set +o ${n}`);return`${[...t,...s].sort().join(`
618
+ `}function dl(e){let t=hl.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),s=pl.map(r=>`set +o ${r}`);return`${[...t,...s].sort().join(`
545
619
  `)}
546
- `}function bn(e,t){if(t.includes("--help"))return F(St);if(t.length===0){let i=Ja(e),a=eo(e),o=u=>{for(let f of a){let d=`${f}_`,h=`${f}__length`;if(u!==h&&u.startsWith(d)){if(u.slice(d.length).startsWith("_length"))continue;return!0}}return!1},l=[];for(let[u,f]of e.state.env){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)||i.has(u)||a.has(u))continue;let d=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(d&&i.has(d[1]))continue;let h=u.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);h&&i.has(h[1])||o(u)||h&&a.has(h[1])||l.push([u,f])}let c=[];for(let[u,f]of l.sort(([d],[h])=>d<h?-1:d>h?1:0))c.push(`${u}=${rs(f)}`);for(let u of[...i].sort((f,d)=>f<d?-1:f>d?1:0))c.push(Xa(e,u));for(let u of[...a].sort((f,d)=>f<d?-1:f>d?1:0))c.push(Qa(e,u));return c.sort((u,f)=>{let d=u.split("=")[0],h=f.split("=")[0];return d<h?-1:d>h?1:0}),F(c.length>0?`${c.join(`
620
+ `}function Jr(e,t){if(t.includes("--help"))return H(us);if(t.length===0){let i=Vf(e),a=zf(e),l=c=>{for(let f of a){let d=`${f}_`,h=`${f}__length`;if(c!==h&&c.startsWith(d)){if(c.slice(d.length).startsWith("_length"))continue;return!0}}return!1},o=[];for(let[c,f]of e.state.env){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)||i.has(c)||a.has(c))continue;let d=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_(\d+)$/);if(d&&i.has(d[1]))continue;let h=c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);h&&i.has(h[1])||l(c)||h&&a.has(h[1])||o.push([c,f])}let u=[];for(let[c,f]of o.sort(([d],[h])=>d<h?-1:d>h?1:0))u.push(`${c}=${on(f)}`);for(let c of[...i].sort((f,d)=>f<d?-1:f>d?1:0))u.push(Wf(e,c));for(let c of[...a].sort((f,d)=>f<d?-1:f>d?1:0))u.push(Ff(e,c));return u.sort((c,f)=>{let d=c.split("=")[0],h=f.split("=")[0];return d<h?-1:d>h?1:0}),H(u.length>0?`${u.join(`
547
621
  `)}
548
- `:"")}let s=[],n=()=>s.length>0?F(s.join("")):M,r=0;for(;r<t.length;){let i=t[r];if((i==="-o"||i==="+o")&&Ka(t,r)){let a=t[r+1];if(!os.has(a)){let o=`bash: set: ${a}: invalid option name
549
- ${St}`;if(e.state.options.posix)throw new me(1,"",o);return _(o)}wn(e,os.get(a)??null,i==="-o"),r+=2;continue}if(i==="-o"){s.push(Hr(e)),r++;continue}if(i==="+o"){s.push(Ur(e)),r++;continue}if(i.length>1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let a=i[0]==="-",o=0;for(let l=1;l<i.length;l++){let c=i[l];if(c==="o"){let u=r+1+o;if(u<t.length&&!t[u].startsWith("-")&&!t[u].startsWith("+")){let d=t[u];if(!os.has(d)){let h=`bash: set: ${d}: invalid option name
550
- ${St}`;if(e.state.options.posix)throw new me(1,"",h);return _(h)}wn(e,os.get(d)??null,a),o++;continue}s.push(a?Hr(e):Ur(e));continue}if(!jr.has(c)){let u=`bash: set: ${i[0]}${c}: invalid option
551
- ${St}`;if(e.state.options.posix)throw new me(1,"",u);return _(u)}wn(e,jr.get(c)??null,a)}r+=1+o;continue}if(i==="--")return vn(e,t.slice(r+1)),n();if(i==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,at(e),r+1<t.length)return vn(e,t.slice(r+1)),n();r++;continue}if(i==="+"){r++;continue}if(i.startsWith("-")||i.startsWith("+")){let a=`bash: set: ${i}: invalid option
552
- ${St}`;if(e.state.options.posix)throw new me(1,"",a);return _(a)}return vn(e,t.slice(r)),n()}return n()}function vn(e,t){let s=1;for(;e.state.env.has(String(s));)e.state.env.delete(String(s)),s++;for(let n=0;n<t.length;n++)e.state.env.set(String(n+1),t[n]);e.state.env.set("#",String(t.length)),e.state.env.set("@",t.join(" ")),e.state.env.set("*",t.join(" "))}function $n(e,t){let s=1;if(t.length>0){let a=Number.parseInt(t[0],10);if(Number.isNaN(a)||a<0){let o=`bash: shift: ${t[0]}: numeric argument required
553
- `;if(e.state.options.posix)throw new me(1,"",o);return _(o)}s=a}let n=Number.parseInt(e.state.env.get("#")||"0",10);if(s>n){let a=`bash: shift: shift count out of range
554
- `;if(e.state.options.posix)throw new me(1,"",a);return _(a)}if(s===0)return M;let r=[];for(let a=1;a<=n;a++)r.push(e.state.env.get(String(a))||"");let i=r.slice(s);for(let a=1;a<=n;a++)e.state.env.delete(String(a));for(let a=0;a<i.length;a++)e.state.env.set(String(a+1),i[a]);return e.state.env.set("#",String(i.length)),e.state.env.set("@",i.join(" ")),M}async function En(e,t){let s=t;if(s.length>0&&s[0]==="--"&&(s=s.slice(1)),s.length===0)return k("",`bash: source: filename argument required
555
- `,2);let n=s[0],r=null,i=null;if(n.includes("/")){let c=e.fs.resolvePath(e.state.cwd,n);try{i=await e.fs.readFile(c),r=c}catch{}}else{let u=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of u){let d=e.fs.resolvePath(e.state.cwd,`${f}/${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 _(`bash: ${n}: No such file or directory
556
- `);let a=new Map;if(s.length>1){for(let u=1;u<=9;u++)a.set(String(u),e.state.env.get(String(u)));a.set("#",e.state.env.get("#")),a.set("@",e.state.env.get("@"));let c=s.slice(1);e.state.env.set("#",String(c.length)),e.state.env.set("@",c.join(" "));for(let u=0;u<c.length&&u<9;u++)e.state.env.set(String(u+1),c[u]);for(let u=c.length+1;u<=9;u++)e.state.env.delete(String(u))}let o=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=o,s.length>1)for(let[c,u]of a)u===void 0?e.state.env.delete(c):e.state.env.set(c,u)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new Y(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=n;try{let c=Ee(i),u=await e.executeScript(c);return l(),u}catch(c){if(l(),c instanceof B)throw c;if(c instanceof ce)return k(c.stdout,c.stderr,c.exitCode);if(c.name==="ParseException")return _(`bash: ${n}: ${c.message}
557
- `);throw c}}function Gr(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function to(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function Kr(e,t){if(to(t))return null;try{let s=new V,n=Q(s,t);return await j(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}function Xr(e,t){if(e.state.localVarStack?.has(t)){let n=ts(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)es(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,n.scopeIndex),Sn(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),es(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let n=e.state.localScopes.length-1;n>=0;n--){let r=e.state.localScopes[n];if(r.has(t)){let i=r.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),r.delete(t);let a=!1;for(let o=n-1;o>=0;o--)if(e.state.localScopes[o].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,o+1),a=!0;break}return a||es(e,t),!0}}return!1}function Sn(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 Yr(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 V().parseWordFromString(s,!0,!1);return I(e,r)}if(t.includes("$")){let n=new V().parseWordFromString(t,!1,!1);return I(e,n)}return t}async function An(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 c=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(c){let d=c[1],h=c[2];if(h==="@"||h==="*"){let b=Se(e,d);for(let[m]of b)e.state.env.delete(`${d}_${m}`);e.state.env.delete(d);continue}let y=e.state.associativeArrays?.has(d);if(y){let b=await Yr(e,h);e.state.env.delete(`${d}_${b}`);continue}let p=Cs(e,d),w=e.state.declaredVars?.has(d);if((e.state.env.has(d)||w)&&!p&&!y){n+=`bash: unset: ${d}: not an array variable
558
- `,r=1;continue}let g=await Kr(e,h);if(g===null&&p){n+=`bash: unset: ${h}: not a valid identifier
559
- `,r=1;continue}if(g===null)continue;if(g<0){let b=Se(e,d),m=b.length,v=e.state.currentLine;if(m===0){n+=`bash: line ${v}: unset: [${g}]: bad array subscript
560
- `,r=1;continue}let E=m+g;if(E<0){n+=`bash: line ${v}: unset: [${g}]: bad array subscript
561
- `,r=1;continue}let S=b[E][0];e.state.env.delete(`${d}_${S}`);continue}e.state.env.delete(`${d}_${g}`);continue}if(!Gr(i)){n+=`bash: unset: \`${i}': not a valid identifier
562
- `,r=1;continue}let u=i;if(ge(e,i)){let d=We(e,i);d&&d!==i&&(u=d)}if(Ze(e,u)){n+=`bash: unset: ${u}: cannot unset: readonly variable
563
- `,r=1;continue}let f=lt(e,u);if(f!==void 0&&f!==e.state.callDepth)Xr(e,u);else if(e.state.fullyUnsetLocals?.has(u))e.state.env.delete(u);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(u),h=e.state.mutatedTempEnvVars?.has(u);if((d||h)&&e.state.localVarStack?.has(u)){let y=ts(e,u);y?y.value===void 0?e.state.env.delete(u):e.state.env.set(u,y.value):e.state.env.delete(u)}else e.state.env.delete(u)}else Sn(e,u)||e.state.env.delete(u);e.state.exportedVars?.delete(u);continue}let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let c=a[1],u=a[2];if(u==="@"||u==="*"){let p=Se(e,c);for(let[w]of p)e.state.env.delete(`${c}_${w}`);e.state.env.delete(c);continue}let f=e.state.associativeArrays?.has(c);if(f){let p=await Yr(e,u);e.state.env.delete(`${c}_${p}`);continue}let d=Cs(e,c);if(e.state.env.has(c)&&!d&&!f){n+=`bash: unset: ${c}: not an array variable
564
- `,r=1;continue}let y=await Kr(e,u);if(y===null&&d){n+=`bash: unset: ${u}: not a valid identifier
565
- `,r=1;continue}if(y===null)continue;if(y<0){let p=Se(e,c),w=p.length,$=e.state.currentLine;if(w===0){n+=`bash: line ${$}: unset: [${y}]: bad array subscript
566
- `,r=1;continue}let g=w+y;if(g<0){n+=`bash: line ${$}: unset: [${y}]: bad array subscript
567
- `,r=1;continue}let b=p[g][0];e.state.env.delete(`${c}_${b}`);continue}e.state.env.delete(`${c}_${y}`);continue}if(!Gr(i)){n+=`bash: unset: \`${i}': not a valid identifier
568
- `,r=1;continue}let o=i;if(ge(e,i)){let c=We(e,i);c&&c!==i&&(o=c)}if(Ze(e,o)){n+=`bash: unset: ${o}: cannot unset: readonly variable
569
- `,r=1;continue}let l=lt(e,o);if(l!==void 0&&l!==e.state.callDepth)Xr(e,o);else if(e.state.fullyUnsetLocals?.has(o))e.state.env.delete(o);else if(l!==void 0){let c=e.state.accessedTempEnvVars?.has(o),u=e.state.mutatedTempEnvVars?.has(o);if((c||u)&&e.state.localVarStack?.has(o)){let f=ts(e,o);f?f.value===void 0?e.state.env.delete(o):e.state.env.set(o,f.value):e.state.env.delete(o)}else e.state.env.delete(o)}else Sn(e,o)||e.state.env.delete(o);e.state.exportedVars?.delete(o),e.state.functions.delete(i)}return k("",n,r)}var _n=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],so=["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 ls(e){return _n.includes(e)}function no(e){return so.includes(e)}function Qr(e,t){let s=!1,n=!1,r=!1,i=!1,a=!1,o=[],l=0;for(;l<t.length;){let d=t[l];if(d==="--"){l++;break}if(d.startsWith("-")&&d.length>1){for(let h=1;h<d.length;h++){let y=d[h];switch(y){case"s":s=!0;break;case"u":n=!0;break;case"p":r=!0;break;case"q":i=!0;break;case"o":a=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${y}: invalid option
570
- `}}}l++}else break}for(;l<t.length;)o.push(t[l]),l++;if(a)return ro(e,o,s,n,r,i);if(s&&n)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
571
- `};if(o.length===0){if(s||n){let h=[];for(let y of _n){let p=e.state.shoptOptions[y];s&&p?h.push(r?`shopt -s ${y}`:`${y} on`):n&&!p&&h.push(r?`shopt -u ${y}`:`${y} off`)}return{exitCode:0,stdout:h.length>0?`${h.join(`
622
+ `:"")}let s=[],r=()=>s.length>0?H(s.join("")):G,n=0;for(;n<t.length;){let i=t[n];if((i==="-o"||i==="+o")&&Lf(t,n)){let a=t[n+1];if(!un.has(a)){let l=`bash: set: ${a}: invalid option name
623
+ ${us}`;if(e.state.options.posix)throw new Me(1,"",l);return _(l)}Xr(e,un.get(a)??null,i==="-o"),n+=2;continue}if(i==="-o"){s.push(fl(e)),n++;continue}if(i==="+o"){s.push(dl(e)),n++;continue}if(i.length>1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let a=i[0]==="-",l=0;for(let o=1;o<i.length;o++){let u=i[o];if(u==="o"){let c=n+1+l;if(c<t.length&&!t[c].startsWith("-")&&!t[c].startsWith("+")){let d=t[c];if(!un.has(d)){let h=`bash: set: ${d}: invalid option name
624
+ ${us}`;if(e.state.options.posix)throw new Me(1,"",h);return _(h)}Xr(e,un.get(d)??null,a),l++;continue}s.push(a?fl(e):dl(e));continue}if(!ul.has(u)){let c=`bash: set: ${i[0]}${u}: invalid option
625
+ ${us}`;if(e.state.options.posix)throw new Me(1,"",c);return _(c)}Xr(e,ul.get(u)??null,a)}n+=1+l;continue}if(i==="--")return Yr(e,t.slice(n+1)),r();if(i==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,Mt(e),n+1<t.length)return Yr(e,t.slice(n+1)),r();n++;continue}if(i==="+"){n++;continue}if(i.startsWith("-")||i.startsWith("+")){let a=`bash: set: ${i}: invalid option
626
+ ${us}`;if(e.state.options.posix)throw new Me(1,"",a);return _(a)}return Yr(e,t.slice(n)),r()}return r()}function Yr(e,t){let s=1;for(;e.state.env.has(String(s));)e.state.env.delete(String(s)),s++;for(let r=0;r<t.length;r++)e.state.env.set(String(r+1),t[r]);e.state.env.set("#",String(t.length)),e.state.env.set("@",t.join(" ")),e.state.env.set("*",t.join(" "))}function ei(e,t){let s=1;if(t.length>0){let a=Number.parseInt(t[0],10);if(Number.isNaN(a)||a<0){let l=`bash: shift: ${t[0]}: numeric argument required
627
+ `;if(e.state.options.posix)throw new Me(1,"",l);return _(l)}s=a}let r=Number.parseInt(e.state.env.get("#")||"0",10);if(s>r){let a=`bash: shift: shift count out of range
628
+ `;if(e.state.options.posix)throw new Me(1,"",a);return _(a)}if(s===0)return G;let n=[];for(let a=1;a<=r;a++)n.push(e.state.env.get(String(a))||"");let i=n.slice(s);for(let a=1;a<=r;a++)e.state.env.delete(String(a));for(let a=0;a<i.length;a++)e.state.env.set(String(a+1),i[a]);return e.state.env.set("#",String(i.length)),e.state.env.set("@",i.join(" ")),G}async function ti(e,t){let s=t;if(s.length>0&&s[0]==="--"&&(s=s.slice(1)),s.length===0)return P("",`bash: source: filename argument required
629
+ `,2);let r=s[0],n=null,i=null;if(r.includes("/")){let u=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(u),n=u}catch{}}else{let c=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of c){let d=e.fs.resolvePath(e.state.cwd,`${f}/${r}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),n=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(f),n=f}catch{}}}if(i===null)return _(`bash: ${r}: No such file or directory
630
+ `);let a=new Map;if(s.length>1){for(let c=1;c<=9;c++)a.set(String(c),e.state.env.get(String(c)));a.set("#",e.state.env.get("#")),a.set("@",e.state.env.get("@"));let u=s.slice(1);e.state.env.set("#",String(u.length)),e.state.env.set("@",u.join(" "));for(let c=0;c<u.length&&c<9;c++)e.state.env.set(String(c+1),u[c]);for(let c=u.length+1;c<=9;c++)e.state.env.delete(String(c))}let l=e.state.currentSource,o=()=>{if(e.state.sourceDepth--,e.state.currentSource=l,s.length>1)for(let[u,c]of a)c===void 0?e.state.env.delete(u):e.state.env.set(u,c)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new Q(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let u=Ue(i),c=await e.executeScript(u);return o(),c}catch(u){if(o(),u instanceof U)throw u;if(u instanceof Ne)return P(u.stdout,u.stderr,u.exitCode);if(u.name==="ParseException")return _(`bash: ${r}: ${u.message}
631
+ `);throw u}}function ml(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Bf(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function gl(e,t){if(Bf(t))return null;try{let s=new V,r=X(s,t);return await T(e,r.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}function yl(e,t){if(e.state.localVarStack?.has(t)){let r=sn(e,t);if(r){r.value===void 0?e.state.env.delete(t):e.state.env.set(t,r.value);let n=e.state.localVarStack?.get(t);if(!n||n.length===0)tn(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),si(e,t);else{let i=n[n.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),tn(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let r=e.state.localScopes.length-1;r>=0;r--){let n=e.state.localScopes[r];if(n.has(t)){let i=n.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),n.delete(t);let a=!1;for(let l=r-1;l>=0;l--)if(e.state.localScopes[l].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,l+1),a=!0;break}return a||tn(e,t),!0}}return!1}function si(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 r=e.state.tempEnvBindings[s];if(r.has(t)){let n=r.get(t);return n===void 0?e.state.env.delete(t):e.state.env.set(t,n),r.delete(t),!0}}return!1}async function wl(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let s=t.slice(1,-1),n=new V().parseWordFromString(s,!0,!1);return W(e,n)}if(t.includes("$")){let r=new V().parseWordFromString(t,!1,!1);return W(e,r)}return t}async function ni(e,t){let s="both",r="",n=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 E=F(e,d);for(let[w]of E)e.state.env.delete(`${d}_${w}`);e.state.env.delete(d);continue}let p=e.state.associativeArrays?.has(d);if(p){let E=await wl(e,h);e.state.env.delete(`${d}_${E}`);continue}let m=He(e,d),y=e.state.declaredVars?.has(d);if((e.state.env.has(d)||y)&&!m&&!p){r+=`bash: unset: ${d}: not an array variable
632
+ `,n=1;continue}let v=await gl(e,h);if(v===null&&m){r+=`bash: unset: ${h}: not a valid identifier
633
+ `,n=1;continue}if(v===null)continue;if(v<0){let E=F(e,d),w=E.length,S=e.state.currentLine;if(w===0){r+=`bash: line ${S}: unset: [${v}]: bad array subscript
634
+ `,n=1;continue}let A=w+v;if(A<0){r+=`bash: line ${S}: unset: [${v}]: bad array subscript
635
+ `,n=1;continue}let $=E[A][0];e.state.env.delete(`${d}_${$}`);continue}e.state.env.delete(`${d}_${v}`);continue}if(!ml(i)){r+=`bash: unset: \`${i}': not a valid identifier
636
+ `,n=1;continue}let c=i;if(ee(e,i)){let d=Se(e,i);d&&d!==i&&(c=d)}if(et(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable
637
+ `,n=1;continue}let f=qt(e,c);if(f!==void 0&&f!==e.state.callDepth)yl(e,c);else if(e.state.fullyUnsetLocals?.has(c))e.state.env.delete(c);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(c),h=e.state.mutatedTempEnvVars?.has(c);if((d||h)&&e.state.localVarStack?.has(c)){let p=sn(e,c);p?p.value===void 0?e.state.env.delete(c):e.state.env.set(c,p.value):e.state.env.delete(c)}else e.state.env.delete(c)}else si(e,c)||e.state.env.delete(c);e.state.exportedVars?.delete(c);continue}let a=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let u=a[1],c=a[2];if(c==="@"||c==="*"){let m=F(e,u);for(let[y]of m)e.state.env.delete(`${u}_${y}`);e.state.env.delete(u);continue}let f=e.state.associativeArrays?.has(u);if(f){let m=await wl(e,c);e.state.env.delete(`${u}_${m}`);continue}let d=He(e,u);if(e.state.env.has(u)&&!d&&!f){r+=`bash: unset: ${u}: not an array variable
638
+ `,n=1;continue}let p=await gl(e,c);if(p===null&&d){r+=`bash: unset: ${c}: not a valid identifier
639
+ `,n=1;continue}if(p===null)continue;if(p<0){let m=F(e,u),y=m.length,b=e.state.currentLine;if(y===0){r+=`bash: line ${b}: unset: [${p}]: bad array subscript
640
+ `,n=1;continue}let v=y+p;if(v<0){r+=`bash: line ${b}: unset: [${p}]: bad array subscript
641
+ `,n=1;continue}let E=m[v][0];e.state.env.delete(`${u}_${E}`);continue}e.state.env.delete(`${u}_${p}`);continue}if(!ml(i)){r+=`bash: unset: \`${i}': not a valid identifier
642
+ `,n=1;continue}let l=i;if(ee(e,i)){let u=Se(e,i);u&&u!==i&&(l=u)}if(et(e,l)){r+=`bash: unset: ${l}: cannot unset: readonly variable
643
+ `,n=1;continue}let o=qt(e,l);if(o!==void 0&&o!==e.state.callDepth)yl(e,l);else if(e.state.fullyUnsetLocals?.has(l))e.state.env.delete(l);else if(o!==void 0){let u=e.state.accessedTempEnvVars?.has(l),c=e.state.mutatedTempEnvVars?.has(l);if((u||c)&&e.state.localVarStack?.has(l)){let f=sn(e,l);f?f.value===void 0?e.state.env.delete(l):e.state.env.set(l,f.value):e.state.env.delete(l)}else e.state.env.delete(l)}else si(e,l)||e.state.env.delete(l);e.state.exportedVars?.delete(l),e.state.functions.delete(i)}return P("",r,n)}var ri=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],qf=["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 fn(e){return ri.includes(e)}function Uf(e){return qf.includes(e)}function El(e,t){let s=!1,r=!1,n=!1,i=!1,a=!1,l=[],o=0;for(;o<t.length;){let d=t[o];if(d==="--"){o++;break}if(d.startsWith("-")&&d.length>1){for(let h=1;h<d.length;h++){let p=d[h];switch(p){case"s":s=!0;break;case"u":r=!0;break;case"p":n=!0;break;case"q":i=!0;break;case"o":a=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${p}: invalid option
644
+ `}}}o++}else break}for(;o<t.length;)l.push(t[o]),o++;if(a)return Zf(e,l,s,r,n,i);if(s&&r)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
645
+ `};if(l.length===0){if(s||r){let h=[];for(let p of ri){let m=e.state.shoptOptions[p];s&&m?h.push(n?`shopt -s ${p}`:`${p} on`):r&&!m&&h.push(n?`shopt -u ${p}`:`${p} off`)}return{exitCode:0,stdout:h.length>0?`${h.join(`
572
646
  `)}
573
- `:"",stderr:""}}let d=[];for(let h of _n){let y=e.state.shoptOptions[h];d.push(r?`shopt ${y?"-s":"-u"} ${h}`:`${h} ${y?"on":"off"}`)}return{exitCode:0,stdout:`${d.join(`
647
+ `:"",stderr:""}}let d=[];for(let h of ri){let p=e.state.shoptOptions[h];d.push(n?`shopt ${p?"-s":"-u"} ${h}`:`${h} ${p?"on":"off"}`)}return{exitCode:0,stdout:`${d.join(`
574
648
  `)}
575
- `,stderr:""}}let c=!1,u="",f=[];for(let d of o){if(!ls(d)&&!no(d)){u+=`shopt: ${d}: invalid shell option name
576
- `,c=!0;continue}if(s)ls(d)&&(e.state.shoptOptions[d]=!0,Is(e));else if(n)ls(d)&&(e.state.shoptOptions[d]=!1,Is(e));else if(ls(d)){let h=e.state.shoptOptions[d];i?h||(c=!0):r?(f.push(`shopt ${h?"-s":"-u"} ${d}`),h||(c=!0)):(f.push(`${d} ${h?"on":"off"}`),h||(c=!0))}else i?c=!0:r?(f.push(`shopt -u ${d}`),c=!0):(f.push(`${d} off`),c=!0)}return{exitCode:c?1:0,stdout:f.length>0?`${f.join(`
649
+ `,stderr:""}}let u=!1,c="",f=[];for(let d of l){if(!fn(d)&&!Uf(d)){c+=`shopt: ${d}: invalid shell option name
650
+ `,u=!0;continue}if(s)fn(d)&&(e.state.shoptOptions[d]=!0,In(e));else if(r)fn(d)&&(e.state.shoptOptions[d]=!1,In(e));else if(fn(d)){let h=e.state.shoptOptions[d];i?h||(u=!0):n?(f.push(`shopt ${h?"-s":"-u"} ${d}`),h||(u=!0)):(f.push(`${d} ${h?"on":"off"}`),h||(u=!0))}else i?u=!0:n?(f.push(`shopt -u ${d}`),u=!0):(f.push(`${d} off`),u=!0)}return{exitCode:u?1:0,stdout:f.length>0?`${f.join(`
577
651
  `)}
578
- `:"",stderr:u}}function ro(e,t,s,n,r,i){let a=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),o=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],l=[...a.keys(),...o].sort();if(t.length===0){let d=[];for(let h of l){let y=o.includes(h),p=a.get(h),w=y||!p?!1:e.state.options[p];s&&!w||n&&w||d.push(r?`set ${w?"-o":"+o"} ${h}`:`${h} ${w?"on":"off"}`)}return{exitCode:0,stdout:d.length>0?`${d.join(`
652
+ `:"",stderr:c}}function Zf(e,t,s,r,n,i){let a=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),l=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],o=[...a.keys(),...l].sort();if(t.length===0){let d=[];for(let h of o){let p=l.includes(h),m=a.get(h),y=p||!m?!1:e.state.options[m];s&&!y||r&&y||d.push(n?`set ${y?"-o":"+o"} ${h}`:`${h} ${y?"on":"off"}`)}return{exitCode:0,stdout:d.length>0?`${d.join(`
579
653
  `)}
580
- `:"",stderr:""}}let c=!1,u="",f=[];for(let d of t){let h=a.has(d),y=o.includes(d);if(!h&&!y){u+=`shopt: ${d}: invalid option name
581
- `,c=!0;continue}if(y){s||n||(i?c=!0:r?(f.push(`set +o ${d}`),c=!0):(f.push(`${d} off`),c=!0));continue}let p=a.get(d);if(p)if(s)p==="vi"?e.state.options.emacs=!1:p==="emacs"&&(e.state.options.vi=!1),e.state.options[p]=!0,at(e);else if(n)e.state.options[p]=!1,at(e);else{let w=e.state.options[p];i?w||(c=!0):r?(f.push(`set ${w?"-o":"+o"} ${d}`),w||(c=!0)):(f.push(`${d} ${w?"on":"off"}`),w||(c=!0))}}return{exitCode:c?1:0,stdout:f.length>0?`${f.join(`
654
+ `:"",stderr:""}}let u=!1,c="",f=[];for(let d of t){let h=a.has(d),p=l.includes(d);if(!h&&!p){c+=`shopt: ${d}: invalid option name
655
+ `,u=!0;continue}if(p){s||r||(i?u=!0:n?(f.push(`set +o ${d}`),u=!0):(f.push(`${d} off`),u=!0));continue}let m=a.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,Mt(e);else if(r)e.state.options[m]=!1,Mt(e);else{let y=e.state.options[m];i?y||(u=!0):n?(f.push(`set ${y?"-o":"+o"} ${d}`),y||(u=!0)):(f.push(`${d} ${y?"on":"off"}`),y||(u=!0))}}return{exitCode:u?1:0,stdout:f.length>0?`${f.join(`
582
656
  `)}
583
- `:"",stderr:u}}async function Jr(e,t,s){if(t.includes("/")){let a=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(a))return{error:"not_found",path:a};let o=a.split("/").pop()||t,l=e.commands.get(o);try{let c=await e.fs.stat(a);return c.isDirectory?{error:"permission_denied",path:a}:l?{cmd:l,path:a}:(c.mode&73)!==0?{script:!0,path:a}:{error:"permission_denied",path:a}}catch{return{error:"not_found",path:a}}}if(!s&&e.state.hashTable){let a=e.state.hashTable.get(t);if(a)if(await e.fs.exists(a)){let o=e.commands.get(t);if(o)return{cmd:o,path:a};try{let l=await e.fs.stat(a);if(!l.isDirectory&&(l.mode&73)!==0)return{script:!0,path:a}}catch{}}else e.state.hashTable.delete(t)}let r=(s??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let a of r){if(!a)continue;let l=`${a.startsWith("/")?a:e.fs.resolvePath(e.state.cwd,a)}/${t}`;if(await e.fs.exists(l))try{let c=await e.fs.stat(l);if(c.isDirectory)continue;let u=(c.mode&73)!==0,f=e.commands.get(t),d=a==="/bin"||a==="/usr/bin";if(f&&d)return{cmd:f,path:l};if(u){if(f&&!d)return{script:!0,path:l};if(!f)return{script:!0,path:l}}}catch{}}if(!await e.fs.exists("/usr/bin")){let a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function cs(e,t){let s=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let a=await e.fs.stat(i);a.isDirectory||(a.mode&73)!==0&&s.push(t)}catch{}return s}let r=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of r){if(!i)continue;let o=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(o)){try{if((await e.fs.stat(o)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?o:`${i}/${t}`)}}return s}function io(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function Z(e,t,s,n){return((...r)=>{yt(t,s,`${n} call`);let i=e(...r);return io(i)?i.then(a=>(yt(t,s,`${n} post-await`),a),a=>{throw yt(t,s,`${n} post-await`),a}):(yt(t,s,`${n} return`),i)})}function ao(e,t,s){let n={readFile:Z(e.readFile.bind(e),t,s,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:Z(e.readFileBytes.bind(e),t,s,"fs.readFileBytes")}:Object.create(null),readFileBuffer:Z(e.readFileBuffer.bind(e),t,s,"fs.readFileBuffer"),writeFile:Z(e.writeFile.bind(e),t,s,"fs.writeFile"),appendFile:Z(e.appendFile.bind(e),t,s,"fs.appendFile"),exists:Z(e.exists.bind(e),t,s,"fs.exists"),stat:Z(e.stat.bind(e),t,s,"fs.stat"),mkdir:Z(e.mkdir.bind(e),t,s,"fs.mkdir"),readdir:Z(e.readdir.bind(e),t,s,"fs.readdir"),rm:Z(e.rm.bind(e),t,s,"fs.rm"),cp:Z(e.cp.bind(e),t,s,"fs.cp"),mv:Z(e.mv.bind(e),t,s,"fs.mv"),resolvePath:Z(e.resolvePath.bind(e),t,s,"fs.resolvePath"),getAllPaths:Z(e.getAllPaths.bind(e),t,s,"fs.getAllPaths"),chmod:Z(e.chmod.bind(e),t,s,"fs.chmod"),symlink:Z(e.symlink.bind(e),t,s,"fs.symlink"),link:Z(e.link.bind(e),t,s,"fs.link"),readlink:Z(e.readlink.bind(e),t,s,"fs.readlink"),lstat:Z(e.lstat.bind(e),t,s,"fs.lstat"),realpath:Z(e.realpath.bind(e),t,s,"fs.realpath"),utimes:Z(e.utimes.bind(e),t,s,"fs.utimes")};return e.readdirWithFileTypes&&(n.readdirWithFileTypes=Z(e.readdirWithFileTypes.bind(e),t,s,"fs.readdirWithFileTypes")),n}function ei(e,t){if(!e.requireDefenseContext)return e;let s=`command:${t}`,n={...e,fs:ao(e.fs,e.requireDefenseContext,s)};return e.exec&&(n.exec=Z(e.exec,e.requireDefenseContext,s,"exec")),e.fetch&&(n.fetch=Z(e.fetch,e.requireDefenseContext,s,"fetch")),e.sleep&&(n.sleep=Z(e.sleep,e.requireDefenseContext,s,"sleep")),e.getRegisteredCommands&&(n.getRegisteredCommands=Z(e.getRegisteredCommands,e.requireDefenseContext,s,"getRegisteredCommands")),n}async function ri(e,t,s,n){let r=!1,i=!1,a=!1,o=!1,l=!1,c=[];for(let p of t)if(p.startsWith("-")&&p.length>1)for(let w of p.slice(1))w==="t"?r=!0:w==="p"?i=!0:w==="P"?a=!0:w==="a"?o=!0:w==="f"&&(l=!0);else c.push(p);let u="",f="",d=0,h=!1,y=!1;for(let p of c){let w=!1;if(a){if(o){let E=await n(p);if(E.length>0){for(let S of E)u+=`${S}
584
- `;h=!0,w=!0}}else{let E=await s(p);E&&(u+=`${E}
585
- `,h=!0,w=!0)}w||(y=!0);continue}let $=!l&&e.state.functions.has(p);if(o&&$){if(!i)if(r)u+=`function
586
- `;else{let E=e.state.functions.get(p),S=E?ti(p,E):`${p} is a function
587
- `;u+=S}w=!0}let g=e.state.env.get(`BASH_ALIAS_${p}`);if(g!==void 0&&(o||!w)&&(i||(r?u+=`alias
588
- `:u+=`${p} is aliased to \`${g}'
589
- `),w=!0,!o)||Vs.has(p)&&(o||!w)&&(i||(r?u+=`keyword
590
- `:u+=`${p} is a shell keyword
591
- `),w=!0,!o))continue;if(!o&&$&&!w){if(!i)if(r)u+=`function
592
- `;else{let E=e.state.functions.get(p),S=E?ti(p,E):`${p} is a function
593
- `;u+=S}w=!0;continue}if(!(ct.has(p)&&(o||!w)&&(i||(r?u+=`builtin
594
- `:u+=`${p} is a shell builtin
595
- `),w=!0,!o))){if(o){let E=await n(p);for(let S of E)i?u+=`${S}
596
- `:r?u+=`file
597
- `:u+=`${p} is ${S}
598
- `,h=!0,w=!0}else if(!w){let E=await s(p);E&&(i?u+=`${E}
599
- `:r?u+=`file
600
- `:u+=`${p} is ${E}
601
- `,h=!0,w=!0)}if(!w&&(y=!0,!r&&!i)){let E=!0;if(p.includes("/")){let S=e.fs.resolvePath(e.state.cwd,p);await e.fs.exists(S)&&(E=!1)}E&&(f+=`bash: type: ${p}: not found
602
- `)}}}return i?d=y&&!h?1:0:d=y?1:0,k(u,f,d)}function ti(e,t){let s;return t.body.type==="Group"?s=t.body.body.map(r=>At(r)).join("; "):s=At(t.body),`${e} is a function
657
+ `:"",stderr:c}}async function bl(e,t,s){if(t.includes("/")){let a=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(a))return{error:"not_found",path:a};let l=a.split("/").pop()||t,o=e.commands.get(l);try{let u=await e.fs.stat(a);return u.isDirectory?{error:"permission_denied",path:a}:o?{cmd:o,path:a}:(u.mode&73)!==0?{script:!0,path:a}:{error:"permission_denied",path:a}}catch{return{error:"not_found",path:a}}}if(!s&&e.state.hashTable){let a=e.state.hashTable.get(t);if(a)if(await e.fs.exists(a)){let l=e.commands.get(t);if(l)return{cmd:l,path:a};try{let o=await e.fs.stat(a);if(!o.isDirectory&&(o.mode&73)!==0)return{script:!0,path:a}}catch{}}else e.state.hashTable.delete(t)}let n=(s??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let a of n){if(!a)continue;let o=`${a.startsWith("/")?a:e.fs.resolvePath(e.state.cwd,a)}/${t}`;if(await e.fs.exists(o))try{let u=await e.fs.stat(o);if(u.isDirectory)continue;let c=(u.mode&73)!==0,f=e.commands.get(t),d=a==="/bin"||a==="/usr/bin";if(f&&d)return{cmd:f,path:o};if(c){if(f&&!d)return{script:!0,path:o};if(!f)return{script:!0,path:o}}}catch{}}if(!await e.fs.exists("/usr/bin")){let a=e.commands.get(t);if(a)return{cmd:a,path:`/usr/bin/${t}`}}return null}async function dn(e,t){let s=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let a=await e.fs.stat(i);a.isDirectory||(a.mode&73)!==0&&s.push(t)}catch{}return s}let n=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of n){if(!i)continue;let l=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(l)){try{if((await e.fs.stat(l)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?l:`${i}/${t}`)}}return s}function Hf(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function ie(e,t,s,r){return((...n)=>{Xt(t,s,`${r} call`);let i=e(...n);return Hf(i)?i.then(a=>(Xt(t,s,`${r} post-await`),a),a=>{throw Xt(t,s,`${r} post-await`),a}):(Xt(t,s,`${r} return`),i)})}function jf(e,t,s){let r={readFile:ie(e.readFile.bind(e),t,s,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:ie(e.readFileBytes.bind(e),t,s,"fs.readFileBytes")}:Object.create(null),readFileBuffer:ie(e.readFileBuffer.bind(e),t,s,"fs.readFileBuffer"),writeFile:ie(e.writeFile.bind(e),t,s,"fs.writeFile"),appendFile:ie(e.appendFile.bind(e),t,s,"fs.appendFile"),exists:ie(e.exists.bind(e),t,s,"fs.exists"),stat:ie(e.stat.bind(e),t,s,"fs.stat"),mkdir:ie(e.mkdir.bind(e),t,s,"fs.mkdir"),readdir:ie(e.readdir.bind(e),t,s,"fs.readdir"),rm:ie(e.rm.bind(e),t,s,"fs.rm"),cp:ie(e.cp.bind(e),t,s,"fs.cp"),mv:ie(e.mv.bind(e),t,s,"fs.mv"),resolvePath:ie(e.resolvePath.bind(e),t,s,"fs.resolvePath"),getAllPaths:ie(e.getAllPaths.bind(e),t,s,"fs.getAllPaths"),chmod:ie(e.chmod.bind(e),t,s,"fs.chmod"),symlink:ie(e.symlink.bind(e),t,s,"fs.symlink"),link:ie(e.link.bind(e),t,s,"fs.link"),readlink:ie(e.readlink.bind(e),t,s,"fs.readlink"),lstat:ie(e.lstat.bind(e),t,s,"fs.lstat"),realpath:ie(e.realpath.bind(e),t,s,"fs.realpath"),utimes:ie(e.utimes.bind(e),t,s,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=ie(e.readdirWithFileTypes.bind(e),t,s,"fs.readdirWithFileTypes")),r}function vl(e,t){if(!e.requireDefenseContext)return e;let s=`command:${t}`,r={...e,fs:jf(e.fs,e.requireDefenseContext,s)};return e.exec&&(r.exec=ie(e.exec,e.requireDefenseContext,s,"exec")),e.fetch&&(r.fetch=ie(e.fetch,e.requireDefenseContext,s,"fetch")),e.sleep&&(r.sleep=ie(e.sleep,e.requireDefenseContext,s,"sleep")),e.getRegisteredCommands&&(r.getRegisteredCommands=ie(e.getRegisteredCommands,e.requireDefenseContext,s,"getRegisteredCommands")),r}async function Nl(e,t,s,r){let n=!1,i=!1,a=!1,l=!1,o=!1,u=[];for(let m of t)if(m.startsWith("-")&&m.length>1)for(let y of m.slice(1))y==="t"?n=!0:y==="p"?i=!0:y==="P"?a=!0:y==="a"?l=!0:y==="f"&&(o=!0);else u.push(m);let c="",f="",d=0,h=!1,p=!1;for(let m of u){let y=!1;if(a){if(l){let A=await r(m);if(A.length>0){for(let $ of A)c+=`${$}
658
+ `;h=!0,y=!0}}else{let A=await s(m);A&&(c+=`${A}
659
+ `,h=!0,y=!0)}y||(p=!0);continue}let b=!o&&e.state.functions.has(m);if(l&&b){if(!i)if(n)c+=`function
660
+ `;else{let A=e.state.functions.get(m),$=A?Sl(m,A):`${m} is a function
661
+ `;c+=$}y=!0}let v=e.state.env.get(`BASH_ALIAS_${m}`);if(v!==void 0&&(l||!y)&&(i||(n?c+=`alias
662
+ `:c+=`${m} is aliased to \`${v}'
663
+ `),y=!0,!l)||vr.has(m)&&(l||!y)&&(i||(n?c+=`keyword
664
+ `:c+=`${m} is a shell keyword
665
+ `),y=!0,!l))continue;if(!l&&b&&!y){if(!i)if(n)c+=`function
666
+ `;else{let A=e.state.functions.get(m),$=A?Sl(m,A):`${m} is a function
667
+ `;c+=$}y=!0;continue}if(!(Ut.has(m)&&(l||!y)&&(i||(n?c+=`builtin
668
+ `:c+=`${m} is a shell builtin
669
+ `),y=!0,!l))){if(l){let A=await r(m);for(let $ of A)i?c+=`${$}
670
+ `:n?c+=`file
671
+ `:c+=`${m} is ${$}
672
+ `,h=!0,y=!0}else if(!y){let A=await s(m);A&&(i?c+=`${A}
673
+ `:n?c+=`file
674
+ `:c+=`${m} is ${A}
675
+ `,h=!0,y=!0)}if(!y&&(p=!0,!n&&!i)){let A=!0;if(m.includes("/")){let $=e.fs.resolvePath(e.state.cwd,m);await e.fs.exists($)&&(A=!1)}A&&(f+=`bash: type: ${m}: not found
676
+ `)}}}return i?d=p&&!h?1:0:d=p?1:0,P(c,f,d)}function Sl(e,t){let s;return t.body.type==="Group"?s=t.body.body.map(n=>fs(n)).join("; "):s=fs(t.body),`${e} is a function
603
677
  ${e} ()
604
678
  {
605
679
  ${s}
606
680
  }
607
- `}function At(e){if(Array.isArray(e))return e.map(t=>At(t)).join("; ");if(e.type==="Statement"){let t=[];for(let s=0;s<e.pipelines.length;s++){let n=e.pipelines[s];t.push(oo(n)),e.operators[s]&&t.push(e.operators[s])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,s=[];t.name&&s.push(si(t.name));for(let n of t.args)s.push(si(n));return s.join(" ")}return e.type==="Group"?`{ ${e.body.map(n=>At(n)).join("; ")}; }`:"..."}function oo(e){let t=e.commands.map(s=>At(s));return(e.negated?"! ":"")+t.join(" | ")}function si(e){let t="";for(let s of e.parts)s.type==="Literal"?t+=s.value:s.type==="DoubleQuoted"?t+=`"${s.parts.map(n=>ni(n)).join("")}"`:s.type==="SingleQuoted"?t+=`'${s.value}'`:t+=ni(s);return t}function ni(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function ii(e,t,s,n){let r="",i="",a=0;for(let o of t){if(!o){a=1;continue}let l=e.state.env.get(`BASH_ALIAS_${o}`);if(l!==void 0)n?r+=`${o} is an alias for "${l}"
608
- `:r+=`alias ${o}='${l}'
609
- `;else if(Vs.has(o))n?r+=`${o} is a shell keyword
610
- `:r+=`${o}
611
- `;else if(ct.has(o))n?r+=`${o} is a shell builtin
612
- `:r+=`${o}
613
- `;else if(e.state.functions.has(o))n?r+=`${o} is a function
614
- `:r+=`${o}
615
- `;else if(o.includes("/")){let c=e.fs.resolvePath(e.state.cwd,o),u=!1;if(await e.fs.exists(c))try{let f=await e.fs.stat(c);f.isDirectory||(f.mode&73)!==0&&(n?r+=`${o} is ${o}
616
- `:r+=`${o}
617
- `,u=!0)}catch{}u||(n&&(i+=`${o}: not found
618
- `),a=1)}else if(e.commands.has(o)){let u=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of u){if(!d)continue;let h=`${d}/${o}`;try{let y=await e.fs.stat(h);if(!y.isDirectory&&(y.mode&73)!==0){f=h;break}}catch{}}f||(f=`/usr/bin/${o}`),n?r+=`${o} is ${f}
619
- `:r+=`${f}
620
- `}else n&&(i+=`${o}: not found
621
- `),a=1}return k(r,i,a)}async function ai(e,t){if(t.includes("/")){let r=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(r)){try{let i=await e.fs.stat(r);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let n=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let r of n){if(!r)continue;let a=`${r.startsWith("/")?r:e.fs.resolvePath(e.state.cwd,r)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).isDirectory)continue}catch{continue}return`${r}/${t}`}}if(e.commands.has(t)){for(let r of n)if(r==="/usr/bin"||r==="/bin")return`${r}/${t}`;return`/usr/bin/${t}`}return null}async function oi(e,t,s,n,r,i,a,o){let{ctx:l,runCommand:c}=e;if(l.coverage&&ct.has(t)&&l.coverage.hit(`bash:builtin:${t}`),t==="export")return un(l,s);if(t==="unset")return An(l,s);if(t==="exit")return cn(l,s);if(t==="local")return pn(l,s);if(t==="set")return bn(l,s);if(t==="break")return Rs(l,s);if(t==="continue")return Gs(l,s);if(t==="return")return gn(l,s);if(t==="eval"&&l.state.options.posix)return is(l,s,r);if(t==="shift")return $n(l,s);if(t==="getopts")return as(l,s);if(t==="compgen")return Hs(l,s);if(t==="complete")return Zs(l,s);if(t==="compopt")return qs(l,s);if(t==="pushd")return await an(l,s);if(t==="popd")return on(l,s);if(t==="dirs")return ln(l,s);if(t==="source"||t===".")return En(l,s);if(t==="read")return yn(l,s,r,o);if(t==="mapfile"||t==="readarray")return mn(l,s,r);if(t==="declare"||t==="typeset")return sn(l,s);if(t==="readonly")return nn(l,s);if(!i){let u=l.state.functions.get(t);if(u)return ns(l,u,s,r)}if(t==="eval")return is(l,s,r);if(t==="cd")return await Ls(l,s);if(t===":"||t==="true")return M;if(t==="false")return X(!1);if(t==="let")return hn(l,s);if(t==="command")return lo(e,s,r);if(t==="builtin")return co(e,s,r);if(t==="shopt")return Qr(l,s);if(t==="exec"){if(s.length===0)return M;let[u,...f]=s;return c(u,f,[],r,!1,!1,-1)}if(t==="wait")return M;if(t==="type")return await ri(l,s,u=>ai(l,u),u=>cs(l,u));if(t==="hash")return fn(l,s);if(t==="help")return dn(l,s);if(t==="["||t==="test"){let u=s;if(t==="["){if(s[s.length-1]!=="]")return _("[: missing `]'\n",2);u=s.slice(0,-1)}return bt(l,u)}return null}async function lo(e,t,s){let{ctx:n,runCommand:r}=e;if(t.length===0)return M;let i=!1,a=!1,o=!1,l=t;for(;l.length>0&&l[0].startsWith("-");){let f=l[0];if(f==="--"){l=l.slice(1);break}for(let d of f.slice(1))d==="p"?i=!0:d==="V"?a=!0:d==="v"&&(o=!0);l=l.slice(1)}if(l.length===0)return M;if(o||a)return await ii(n,l,o,a);let[c,...u]=l;return r(c,u,[],s,!0,i,-1)}async function co(e,t,s){let{runCommand:n}=e;if(t.length===0)return M;let r=t;if(r[0]==="--"&&(r=r.slice(1),r.length===0))return M;let i=r[0];if(!ct.has(i))return _(`bash: builtin: ${i}: not a shell builtin
622
- `);let[,...a]=r;return n(i,a,[],s,!0,!1,-1)}async function li(e,t,s,n,r){let{ctx:i,buildExportedEnv:a,executeUserScript:o}=e,c=await Jr(i,t,r?"/usr/bin:/bin":void 0);if(!c)return mr(t)?_(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
681
+ `}function fs(e){if(Array.isArray(e))return e.map(t=>fs(t)).join("; ");if(e.type==="Statement"){let t=[];for(let s=0;s<e.pipelines.length;s++){let r=e.pipelines[s];t.push(Gf(r)),e.operators[s]&&t.push(e.operators[s])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,s=[];t.name&&s.push(Al(t.name));for(let r of t.args)s.push(Al(r));return s.join(" ")}return e.type==="Group"?`{ ${e.body.map(r=>fs(r)).join("; ")}; }`:"..."}function Gf(e){let t=e.commands.map(s=>fs(s));return(e.negated?"! ":"")+t.join(" | ")}function Al(e){let t="";for(let s of e.parts)s.type==="Literal"?t+=s.value:s.type==="DoubleQuoted"?t+=`"${s.parts.map(r=>$l(r)).join("")}"`:s.type==="SingleQuoted"?t+=`'${s.value}'`:t+=$l(s);return t}function $l(e){let t=e;return t.type==="Literal"?t.value??"":t.type==="Variable"?`$${t.name}`:""}async function kl(e,t,s,r){let n="",i="",a=0;for(let l of t){if(!l){a=1;continue}let o=e.state.env.get(`BASH_ALIAS_${l}`);if(o!==void 0)r?n+=`${l} is an alias for "${o}"
682
+ `:n+=`alias ${l}='${o}'
683
+ `;else if(vr.has(l))r?n+=`${l} is a shell keyword
684
+ `:n+=`${l}
685
+ `;else if(Ut.has(l))r?n+=`${l} is a shell builtin
686
+ `:n+=`${l}
687
+ `;else if(e.state.functions.has(l))r?n+=`${l} is a function
688
+ `:n+=`${l}
689
+ `;else if(l.includes("/")){let u=e.fs.resolvePath(e.state.cwd,l),c=!1;if(await e.fs.exists(u))try{let f=await e.fs.stat(u);f.isDirectory||(f.mode&73)!==0&&(r?n+=`${l} is ${l}
690
+ `:n+=`${l}
691
+ `,c=!0)}catch{}c||(r&&(i+=`${l}: not found
692
+ `),a=1)}else if(e.commands.has(l)){let c=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of c){if(!d)continue;let h=`${d}/${l}`;try{let p=await e.fs.stat(h);if(!p.isDirectory&&(p.mode&73)!==0){f=h;break}}catch{}}f||(f=`/usr/bin/${l}`),r?n+=`${l} is ${f}
693
+ `:n+=`${f}
694
+ `}else r&&(i+=`${l}: not found
695
+ `),a=1}return P(n,i,a)}async function _l(e,t){if(t.includes("/")){let n=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(n)){try{let i=await e.fs.stat(n);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let r=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let n of r){if(!n)continue;let a=`${n.startsWith("/")?n:e.fs.resolvePath(e.state.cwd,n)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).isDirectory)continue}catch{continue}return`${n}/${t}`}}if(e.commands.has(t)){for(let n of r)if(n==="/usr/bin"||n==="/bin")return`${n}/${t}`;return`/usr/bin/${t}`}return null}async function Pl(e,t,s,r,n,i,a,l){let{ctx:o,runCommand:u}=e;if(o.coverage&&Ut.has(t)&&o.coverage.hit(`bash:builtin:${t}`),t==="export")return qr(o,s);if(t==="unset")return ni(o,s);if(t==="exit")return Br(o,s);if(t==="local")return jr(o,s);if(t==="set")return Jr(o,s);if(t==="break")return mr(o,s);if(t==="continue")return Pr(o,s);if(t==="return")return Kr(o,s);if(t==="eval"&&o.state.options.posix)return ln(o,s,n);if(t==="shift")return ei(o,s);if(t==="getopts")return cn(o,s);if(t==="compgen")return $r(o,s);if(t==="complete")return kr(o,s);if(t==="compopt")return _r(o,s);if(t==="pushd")return await Fr(o,s);if(t==="popd")return Vr(o,s);if(t==="dirs")return zr(o,s);if(t==="source"||t===".")return ti(o,s);if(t==="read")return Qr(o,s,n,l);if(t==="mapfile"||t==="readarray")return Gr(o,s,n);if(t==="declare"||t==="typeset")return Lr(o,s);if(t==="readonly")return Wr(o,s);if(!i){let c=o.state.functions.get(t);if(c)return an(o,c,s,n)}if(t==="eval")return ln(o,s,n);if(t==="cd")return await gr(o,s);if(t===":"||t==="true")return G;if(t==="false")return de(!1);if(t==="let")return Hr(o,s);if(t==="command")return Qf(e,s,n);if(t==="builtin")return Kf(e,s,n);if(t==="shopt")return El(o,s);if(t==="exec"){if(s.length===0)return G;let[c,...f]=s;return u(c,f,[],n,!1,!1,-1)}if(t==="wait")return G;if(t==="type")return await Nl(o,s,c=>_l(o,c),c=>dn(o,c));if(t==="hash")return Ur(o,s);if(t==="help")return Zr(o,s);if(t==="["||t==="test"){let c=s;if(t==="["){if(s[s.length-1]!=="]")return _("[: missing `]'\n",2);c=s.slice(0,-1)}return os(o,c)}return null}async function Qf(e,t,s){let{ctx:r,runCommand:n}=e;if(t.length===0)return G;let i=!1,a=!1,l=!1,o=t;for(;o.length>0&&o[0].startsWith("-");){let f=o[0];if(f==="--"){o=o.slice(1);break}for(let d of f.slice(1))d==="p"?i=!0:d==="V"?a=!0:d==="v"&&(l=!0);o=o.slice(1)}if(o.length===0)return G;if(l||a)return await kl(r,o,l,a);let[u,...c]=o;return n(u,c,[],s,!0,i,-1)}async function Kf(e,t,s){let{runCommand:r}=e;if(t.length===0)return G;let n=t;if(n[0]==="--"&&(n=n.slice(1),n.length===0))return G;let i=n[0];if(!Ut.has(i))return _(`bash: builtin: ${i}: not a shell builtin
696
+ `);let[,...a]=n;return r(i,a,[],s,!0,!1,-1)}async function Dl(e,t,s,r,n){let{ctx:i,buildExportedEnv:a,executeUserScript:l}=e,u=await bl(i,t,n?"/usr/bin:/bin":void 0);if(!u)return Lo(t)?_(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
623
697
  `,127):_(`bash: ${t}: command not found
624
- `,127);if("error"in c)return c.error==="permission_denied"?_(`bash: ${t}: Permission denied
698
+ `,127);if("error"in u)return u.error==="permission_denied"?_(`bash: ${t}: Permission denied
625
699
  `,126):_(`bash: ${t}: No such file or directory
626
- `,127);if("script"in c)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,c.path)),await o(c.path,s,n);let{cmd:u,path:f}=c;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=n||i.state.groupStdin||"",h=a(),y={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,signal:i.state.signal,requireDefenseContext:i.requireDefenseContext,jsBootstrapCode:i.jsBootstrapCode,invokeTool:i.invokeTool},p=ei(y,t);try{let w=()=>Wn(i.requireDefenseContext,"command",`${t} execution`,()=>u.execute(s,p));return u.trusted?await be.runTrustedAsync(()=>w()):await w()}catch(w){if(w instanceof Y||w instanceof Je)throw w;return _(`${t}: ${Te($e(w))}
627
- `)}}async function Cn(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let n="",r="",i=0;try{for(let a of t){let o=await e.executeStatement(a);n+=o.stdout,r+=o.stderr,i=o.exitCode}}finally{e.state.inCondition=s}return{stdout:n,stderr:r,exitCode:i}}function _t(e,t,s,n){if(e instanceof de)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"break",stdout:t,stderr:s};if(e instanceof he)return t+=e.stdout,s+=e.stderr,e.levels>1&&n>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"continue",stdout:t,stderr:s};if(e instanceof ce||e instanceof pe||e instanceof B||e instanceof Y)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let r=$e(e);return{action:"error",stdout:t,stderr:`${s}${r}
628
- `,exitCode:1}}async function us(e,t,s="",n=""){let r=s,i=n,a=0;try{for(let o of t){let l=await e.executeStatement(o);r+=l.stdout,i+=l.stderr,a=l.exitCode}}catch(o){if(xt(o)||o instanceof pe||o instanceof B||o instanceof Y||o instanceof Re)throw o.prependOutput(r,i),o;return{stdout:r,stderr:`${i}${$e(o)}
629
- `,exitCode:1}}return{stdout:r,stderr:i,exitCode:a}}async function ci(e,t){let s="",n="";for(let r of t.clauses){let i=await Cn(e,r.condition);if(s+=i.stdout,n+=i.stderr,i.exitCode===0)return us(e,r.body,s,n)}return t.elseBody?us(e,t.elseBody,s,n):k(s,n,0)}async function ui(e,t){let s=await Oe(e,t.redirections);if(s)return s;let n="",r="",i=0,a=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return _(`bash: \`${t.variable}': not a valid identifier
630
- `);let o=[];if(t.words===null)o=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)o=[];else try{for(let c of t.words){let u=await ke(e,c);o.push(...u.values)}}catch(c){if(c instanceof Tt)return{stdout:"",stderr:c.stderr,exitCode:1};throw c}e.state.loopDepth++;try{for(let c of o){a++,a>e.limits.maxLoopIterations&&Pe(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),e.state.env.set(t.variable,c);try{for(let u of t.body){let f=await e.executeStatement(u);n+=f.stdout,r+=f.stderr,i=f.exitCode}}catch(u){let f=_t(u,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=k(n,r,f.exitCode??1);return q(e,d,t.redirections)}throw f.error}}}finally{e.state.loopDepth--}let l=k(n,r,i);return q(e,l,t.redirections)}async function fi(e,t){let s=await Oe(e,t.redirections);if(s)return s;let n=t.line;n!==void 0&&(e.state.currentLine=n);let r="",i="",a=0,o=0;t.init&&await j(e,t.init.expression),e.state.loopDepth++;try{for(;o++,o>e.limits.maxLoopIterations&&Pe(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,i),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await j(e,t.condition.expression)===0));){try{for(let c of t.body){let u=await e.executeStatement(c);r+=u.stdout,i+=u.stderr,a=u.exitCode}}catch(c){let u=_t(c,r,i,e.state.loopDepth);if(r=u.stdout,i=u.stderr,u.action==="break")break;if(u.action==="continue"){t.update&&await j(e,t.update.expression);continue}if(u.action==="error"){let f=k(r,i,u.exitCode??1);return q(e,f,t.redirections)}throw u.error}t.update&&await j(e,t.update.expression)}}finally{e.state.loopDepth--}let l=k(r,i,a);return q(e,l,t.redirections)}async function di(e,t,s=""){let n="",r="",i=0,a=0,o=s;for(let c of t.redirections)if((c.operator==="<<"||c.operator==="<<-")&&c.target.type==="HereDoc"){let u=c.target,f=await I(e,u.content);u.stripTabs&&(f=f.split(`
700
+ `,127);if("script"in u)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u.path)),await l(u.path,s,r);let{cmd:c,path:f}=u;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",h=a(),p={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,signal:i.state.signal,requireDefenseContext:i.requireDefenseContext,jsBootstrapCode:i.jsBootstrapCode,invokeTool:i.invokeTool},m=vl(p,t);try{let y=()=>gi(i.requireDefenseContext,"command",`${t} execution`,()=>c.execute(s,m));return c.trusted?await Be.runTrustedAsync(()=>y()):await y()}catch(y){if(y instanceof Q||y instanceof Ct)throw y;return _(`${t}: ${at(qe(y))}
701
+ `)}}async function ii(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let r="",n="",i=0;try{for(let a of t){let l=await e.executeStatement(a);r+=l.stdout,n+=l.stderr,i=l.exitCode}}finally{e.state.inCondition=s}return{stdout:r,stderr:n,exitCode:i}}function ds(e,t,s,r){if(e instanceof Ie)return t+=e.stdout,s+=e.stderr,e.levels>1&&r>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 Ce)return t+=e.stdout,s+=e.stderr,e.levels>1&&r>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 Ne||e instanceof We||e instanceof U||e instanceof Q)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let n=qe(e);return{action:"error",stdout:t,stderr:`${s}${n}
702
+ `,exitCode:1}}async function hn(e,t,s="",r=""){let n=s,i=r,a=0;try{for(let l of t){let o=await e.executeStatement(l);n+=o.stdout,i+=o.stderr,a=o.exitCode}}catch(l){if(bs(l)||l instanceof We||l instanceof U||l instanceof Q||l instanceof ft)throw l.prependOutput(n,i),l;return{stdout:n,stderr:`${i}${qe(l)}
703
+ `,exitCode:1}}return{stdout:n,stderr:i,exitCode:a}}async function Il(e,t){let s="",r="";for(let n of t.clauses){let i=await ii(e,n.condition);if(s+=i.stdout,r+=i.stderr,i.exitCode===0)return hn(e,n.body,s,r)}return t.elseBody?hn(e,t.elseBody,s,r):P(s,r,0)}async function Cl(e,t){let s=await rt(e,t.redirections);if(s)return s;let r="",n="",i=0,a=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return _(`bash: \`${t.variable}': not a valid identifier
704
+ `);let l=[];if(t.words===null)l=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)l=[];else try{for(let u of t.words){let c=await tt(e,u);l.push(...c.values)}}catch(u){if(u instanceof ut)return{stdout:"",stderr:u.stderr,exitCode:1};throw u}e.state.loopDepth++;try{for(let u of l){a++,a>e.limits.maxLoopIterations&&st(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n),e.state.env.set(t.variable,u);try{for(let c of t.body){let f=await e.executeStatement(c);r+=f.stdout,n+=f.stderr,i=f.exitCode}}catch(c){let f=ds(c,r,n,e.state.loopDepth);if(r=f.stdout,n=f.stderr,f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error"){let d=P(r,n,f.exitCode??1);return le(e,d,t.redirections)}throw f.error}}}finally{e.state.loopDepth--}let o=P(r,n,i);return le(e,o,t.redirections)}async function Rl(e,t){let s=await rt(e,t.redirections);if(s)return s;let r=t.line;r!==void 0&&(e.state.currentLine=r);let n="",i="",a=0,l=0;t.init&&await T(e,t.init.expression),e.state.loopDepth++;try{for(;l++,l>e.limits.maxLoopIterations&&st(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,i),!(t.condition&&(r!==void 0&&(e.state.currentLine=r),await T(e,t.condition.expression)===0));){try{for(let u of t.body){let c=await e.executeStatement(u);n+=c.stdout,i+=c.stderr,a=c.exitCode}}catch(u){let c=ds(u,n,i,e.state.loopDepth);if(n=c.stdout,i=c.stderr,c.action==="break")break;if(c.action==="continue"){t.update&&await T(e,t.update.expression);continue}if(c.action==="error"){let f=P(n,i,c.exitCode??1);return le(e,f,t.redirections)}throw c.error}t.update&&await T(e,t.update.expression)}}finally{e.state.loopDepth--}let o=P(n,i,a);return le(e,o,t.redirections)}async function xl(e,t,s=""){let r="",n="",i=0,a=0,l=s;for(let u of t.redirections)if((u.operator==="<<"||u.operator==="<<-")&&u.target.type==="HereDoc"){let c=u.target,f=await W(e,c.content);c.stripTabs&&(f=f.split(`
631
705
  `).map(d=>d.replace(/^\t+/,"")).join(`
632
- `)),o=f}else if(c.operator==="<<<"&&c.target.type==="Word")o=`${await I(e,c.target)}
633
- `;else if(c.operator==="<"&&c.target.type==="Word")try{let u=await I(e,c.target),f=e.fs.resolvePath(e.state.cwd,u);o=await e.fs.readFile(f)}catch{let u=await I(e,c.target);return _(`bash: ${u}: No such file or directory
634
- `)}let l=e.state.groupStdin;o&&(e.state.groupStdin=o),e.state.loopDepth++;try{for(;;){a++,a>e.limits.maxLoopIterations&&Pe(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r);let c=0,u=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let y=await e.executeStatement(h);n+=y.stdout,r+=y.stderr,c=y.exitCode}}catch(h){if(h instanceof de){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;u=!0}else if(h instanceof he){if(n+=h.stdout,r+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=n,h.stderr=r,e.state.inCondition=d,h;f=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if(u)break;if(!f){if(c!==0)break;try{for(let h of t.body){let y=await e.executeStatement(h);n+=y.stdout,r+=y.stderr,i=y.exitCode}}catch(h){let y=_t(h,n,r,e.state.loopDepth);if(n=y.stdout,r=y.stderr,y.action==="break")break;if(y.action==="continue")continue;if(y.action==="error")return k(n,r,y.exitCode??1);throw y.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=l}return k(n,r,i)}async function hi(e,t){let s="",n="",r=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&Pe(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,n);let a=await Cn(e,t.condition);if(s+=a.stdout,n+=a.stderr,a.exitCode===0)break;try{for(let o of t.body){let l=await e.executeStatement(o);s+=l.stdout,n+=l.stderr,r=l.exitCode}}catch(o){let l=_t(o,s,n,e.state.loopDepth);if(s=l.stdout,n=l.stderr,l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return k(s,n,l.exitCode??1);throw l.error}}}finally{e.state.loopDepth--}return k(s,n,r)}async function pi(e,t){let s=await Oe(e,t.redirections);if(s)return s;let n="",r="",i=0,a=await I(e,t.word),o=!1;for(let c=0;c<t.items.length;c++){let u=t.items[c],f=o;if(!o)for(let d of u.patterns){let h=await I(e,d);Xn(d)&&(h=Gn(h));let y=e.state.shoptOptions.nocasematch,p=e.state.shoptOptions.extglob;if(ot(a,h,y,p)){f=!0;break}}if(f){let d=await us(e,u.body,n,r);if(n=d.stdout,r=d.stderr,i=d.exitCode,u.terminator===";;")break;u.terminator===";&"?o=!0:o=!1}else o=!1}let l=k(n,r,i);return q(e,l,t.redirections)}function kn(e,t){if(e.parts.length!==1)return!1;let s=e.parts[0];return s.type!=="Literal"?!1:t.includes(s.value)}function mi(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),a=r+n+1,o=t.slice(a),l=o.indexOf(":");if(l===-1)return null;let c=Number.parseInt(o.slice(0,l),10);if(Number.isNaN(c)||c<0)return null;let u=o.slice(l+1);return{path:i,position:c,content:u}}var yi="+ ";async function gi(e){let t=e.state.env.get("PS4");if(t===void 0)return yi;if(t==="")return"";try{let n=new V().parseWordFromString(t,!1,!1);return await I(e,n)}catch{return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
635
- `,t||yi}}function uo(e){return e.map(t=>fo(t)).join(" ")}function fo(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),n=e.includes(`
636
- `),r=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(s||n||r||i){let l="";for(let c of e){let u=c.charCodeAt(0);c===`
637
- `?l+="\\n":c===" "?l+="\\t":c==="\\"?l+="\\\\":c==="'"?l+="'":c==='"'?l+='"':u<32||u===127?u<256?l+=`\\x${u.toString(16).padStart(2,"0")}`:l+=`\\u${u.toString(16).padStart(4,"0")}`:l+=c}return`$'${l}'`}return a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function wi(e,t,s){if(!e.state.options.xtrace)return"";let n=await gi(e),r=[t,...s],i=uo(r);return`${n}${i}
638
- `}async function vi(e,t,s){return e.state.options.xtrace?`${await gi(e)}${t}=${s}
639
- `:""}async function $i(e,t,s){let n=t.timed?bs():0,r="",i=M,a=0,o=[],l="",c=t.commands.length>1,u=e.state.lastArg;for(let d=0;d<t.commands.length;d++){let h=t.commands[d],y=d===t.commands.length-1,p=d===0;c&&(e.state.lastArg="",p||(e.state.groupStdin=void 0));let $=c&&(!y||!e.state.shoptOptions.lastpipe)?new Map(e.state.env):null,g;try{g=await s(h,r)}catch(b){if(b instanceof Dt)g={stdout:b.stdout,stderr:b.stderr,exitCode:1};else if(b instanceof B&&t.commands.length>1)g={stdout:b.stdout,stderr:b.stderr,exitCode:b.exitCode};else if(b instanceof pe&&t.commands.length>1)g={stdout:b.stdout,stderr:b.stderr,exitCode:b.exitCode};else throw $&&(e.state.env=$),b}$&&(e.state.env=$),o.push(g.exitCode),g.exitCode!==0&&(a=g.exitCode),y?i=g:(t.pipeStderr?.[d]??!1?r=He(g.stderr)+gs(g):(r=gs(g),l+=g.stderr),i={stdout:"",stderr:"",exitCode:g.exitCode})}if(l&&(i={...i,stderr:l+i.stderr}),t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let d of e.state.env.keys())d.startsWith("PIPESTATUS_")&&e.state.env.delete(d);for(let d=0;d<o.length;d++)e.state.env.set(`PIPESTATUS_${d}`,String(o[d]));e.state.env.set("PIPESTATUS__length",String(o.length))}if(e.state.options.pipefail&&a!==0&&(i={...i,exitCode:a}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let h=(bs()-n)/1e3,y=Math.floor(h/60),p=h%60,w;t.timePosix?w=`real ${h.toFixed(2)}
706
+ `)),l=f}else if(u.operator==="<<<"&&u.target.type==="Word")l=`${await W(e,u.target)}
707
+ `;else if(u.operator==="<"&&u.target.type==="Word")try{let c=await W(e,u.target),f=e.fs.resolvePath(e.state.cwd,c);l=await e.fs.readFile(f)}catch{let c=await W(e,u.target);return _(`bash: ${c}: No such file or directory
708
+ `)}let o=e.state.groupStdin;l&&(e.state.groupStdin=l),e.state.loopDepth++;try{for(;;){a++,a>e.limits.maxLoopIterations&&st(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,n);let u=0,c=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let p=await e.executeStatement(h);r+=p.stdout,n+=p.stderr,u=p.exitCode}}catch(h){if(h instanceof Ie){if(r+=h.stdout,n+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=r,h.stderr=n,e.state.inCondition=d,h;c=!0}else if(h instanceof Ce){if(r+=h.stdout,n+=h.stderr,h.levels>1&&e.state.loopDepth>1)throw h.levels--,h.stdout=r,h.stderr=n,e.state.inCondition=d,h;f=!0}else throw e.state.inCondition=d,h}finally{e.state.inCondition=d}if(c)break;if(!f){if(u!==0)break;try{for(let h of t.body){let p=await e.executeStatement(h);r+=p.stdout,n+=p.stderr,i=p.exitCode}}catch(h){let p=ds(h,r,n,e.state.loopDepth);if(r=p.stdout,n=p.stderr,p.action==="break")break;if(p.action==="continue")continue;if(p.action==="error")return P(r,n,p.exitCode??1);throw p.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=o}return P(r,n,i)}async function Ol(e,t){let s="",r="",n=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&st(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,r);let a=await ii(e,t.condition);if(s+=a.stdout,r+=a.stderr,a.exitCode===0)break;try{for(let l of t.body){let o=await e.executeStatement(l);s+=o.stdout,r+=o.stderr,n=o.exitCode}}catch(l){let o=ds(l,s,r,e.state.loopDepth);if(s=o.stdout,r=o.stderr,o.action==="break")break;if(o.action==="continue")continue;if(o.action==="error")return P(s,r,o.exitCode??1);throw o.error}}}finally{e.state.loopDepth--}return P(s,r,n)}async function Tl(e,t){let s=await rt(e,t.redirections);if(s)return s;let r="",n="",i=0,a=await W(e,t.word),l=!1;for(let u=0;u<t.items.length;u++){let c=t.items[u],f=l;if(!l)for(let d of c.patterns){let h=await W(e,d);_o(d)&&(h=Te(h));let p=e.state.shoptOptions.nocasematch,m=e.state.shoptOptions.extglob;if(Bt(a,h,p,m)){f=!0;break}}if(f){let d=await hn(e,c.body,r,n);if(r=d.stdout,n=d.stderr,i=d.exitCode,c.terminator===";;")break;c.terminator===";&"?l=!0:l=!1}else l=!1}let o=P(r,n,i);return le(e,o,t.redirections)}function ai(e,t){if(e.parts.length!==1)return!1;let s=e.parts[0];return s.type!=="Literal"?!1:t.includes(s.value)}function Ll(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let r=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(r)||r<0)return null;let n=s+1,i=t.slice(n,n+r),a=n+r+1,l=t.slice(a),o=l.indexOf(":");if(o===-1)return null;let u=Number.parseInt(l.slice(0,o),10);if(Number.isNaN(u)||u<0)return null;let c=l.slice(o+1);return{path:i,position:u,content:c}}var Wl="+ ";async function Ml(e){let t=e.state.env.get("PS4");if(t===void 0)return Wl;if(t==="")return"";try{let r=new V().parseWordFromString(t,!1,!1);return await W(e,r)}catch{return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
709
+ `,t||Wl}}function Xf(e){return e.map(t=>Yf(t)).join(" ")}function Yf(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
710
+ `),n=e.includes(" "),i=e.includes("\\"),a=e.includes("'");if(s||r||n||i){let o="";for(let u of e){let c=u.charCodeAt(0);u===`
711
+ `?o+="\\n":u===" "?o+="\\t":u==="\\"?o+="\\\\":u==="'"?o+="'":u==='"'?o+='"':c<32||c===127?c<256?o+=`\\x${c.toString(16).padStart(2,"0")}`:o+=`\\u${c.toString(16).padStart(4,"0")}`:o+=u}return`$'${o}'`}return a?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function Fl(e,t,s){if(!e.state.options.xtrace)return"";let r=await Ml(e),n=[t,...s],i=Xf(n);return`${r}${i}
712
+ `}async function Vl(e,t,s){return e.state.options.xtrace?`${await Ml(e)}${t}=${s}
713
+ `:""}async function Bl(e,t,s){let r=t.timed?An():0,n="",i=G,a=0,l=[],o="",u=t.commands.length>1,c=e.state.lastArg;for(let d=0;d<t.commands.length;d++){let h=t.commands[d],p=d===t.commands.length-1,m=d===0;u&&(e.state.lastArg="",m||(e.state.groupStdin=void 0));let b=u&&(!p||!e.state.shoptOptions.lastpipe)?new Map(e.state.env):null,v;try{v=await s(h,n)}catch(E){if(E instanceof xe)v={stdout:E.stdout,stderr:E.stderr,exitCode:1};else if(E instanceof U&&t.commands.length>1)v={stdout:E.stdout,stderr:E.stderr,exitCode:E.exitCode};else if(E instanceof We&&t.commands.length>1)v={stdout:E.stdout,stderr:E.stderr,exitCode:E.exitCode};else throw b&&(e.state.env=b),E}b&&(e.state.env=b),l.push(v.exitCode),v.exitCode!==0&&(a=v.exitCode),p?i=v:(t.pipeStderr?.[d]??!1?n=At(v.stderr)+bn(v):(n=bn(v),o+=v.stderr),i={stdout:"",stderr:"",exitCode:v.exitCode})}if(o&&(i={...i,stderr:o+i.stderr}),t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let d of e.state.env.keys())d.startsWith("PIPESTATUS_")&&e.state.env.delete(d);for(let d=0;d<l.length;d++)e.state.env.set(`PIPESTATUS_${d}`,String(l[d]));e.state.env.set("PIPESTATUS__length",String(l.length))}if(e.state.options.pipefail&&a!==0&&(i={...i,exitCode:a}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let h=(An()-r)/1e3,p=Math.floor(h/60),m=h%60,y;t.timePosix?y=`real ${h.toFixed(2)}
640
714
  user 0.00
641
715
  sys 0.00
642
- `:w=`
643
- real ${`${y}m${p.toFixed(3)}s`}
716
+ `:y=`
717
+ real ${`${p}m${m.toFixed(3)}s`}
644
718
  user 0m0.000s
645
719
  sys 0m0.000s
646
- `,i={...i,stderr:i.stderr+w}}return c&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=u),i}async function Ei(e,t){let s=new Map,n="";for(let r of t.assignments){let i=r.name;if(r.array){let u=await ho(e,t,i,r.array,r.append,s);if(u.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:u.error};if(n+=u.xtraceOutput,u.continueToNext)continue}let a=r.value?await I(e,r.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:k("",`bash: ${i}: bad array subscript
647
- `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let u=await wo(e,t,l[1],l[2],a,r.append,s);if(u.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:u.error};if(u.continueToNext)continue}let c=await bo(e,t,i,a,r.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:n,tempAssignments:s,error:c.error};n+=c.xtraceOutput,c.continueToNext}return{continueToNext:!1,xtraceOutput:n,tempAssignments:s}}async function ho(e,t,s,n,r,i){let a="";if(/\[.+\]$/.test(s))return{continueToNext:!1,xtraceOutput:"",error:k("",`bash: ${s}: cannot assign list to array member
648
- `,1)};if(ge(e,s)){let u=Zn(e,s);if(u===void 0||u==="")throw new B(1,"","");let f=We(e,s);if(f&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(f))return{continueToNext:!1,xtraceOutput:"",error:k("",`bash: ${s}: cannot assign list to array member
649
- `,1)}}if(Ze(e,s)){if(t.name)return a+=`bash: ${s}: readonly variable
650
- `,{continueToNext:!0,xtraceOutput:a};let u=ee(e,s);if(u)return{continueToNext:!1,xtraceOutput:"",error:u}}let o=e.state.associativeArrays?.has(s),l=po(n),c=()=>{let u=`${s}_`;for(let f of e.state.env.keys())f.startsWith(u)&&!f.includes("__")&&e.state.env.delete(f);e.state.env.delete(s)};if(o&&l?await mo(e,t,s,n,r,c,u=>{a+=u}):l?await yo(e,s,n,r,c):await go(e,s,n,r,c),t.name){i.set(s,e.state.env.get(s));let f=`(${n.map(d=>Lt(d)).join(" ")})`;e.state.env.set(s,f)}return{continueToNext:!0,xtraceOutput:a}}function po(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 mo(e,t,s,n,r,i,a){let o=[];for(let l of n){let c=Es(l);if(c){let{key:u,valueParts:f,append:d}=c,h;f.length>0?h=await I(e,{type:"Word",parts:f}):h="",h=G(e,h),o.push({type:"keyed",key:u,value:h,append:d})}else{let u=await I(e,l);o.push({type:"invalid",expandedValue:u})}}r||i();for(let l of o)if(l.type==="keyed")if(l.append){let c=e.state.env.get(`${s}_${l.key}`)??"";e.state.env.set(`${s}_${l.key}`,c+l.value)}else e.state.env.set(`${s}_${l.key}`,l.value);else{let c=t.line??e.state.currentLine??1;a(`bash: line ${c}: ${s}: ${l.expandedValue}: must use subscript when assigning associative array
651
- `)}}async function yo(e,t,s,n,r){let i=[];for(let o of s){let l=Es(o);if(l){let{key:c,valueParts:u,append:f}=l,d;u.length>0?d=await I(e,{type:"Word",parts:u}):d="",d=G(e,d),i.push({type:"keyed",indexExpr:c,value:d,append:f})}else{let c=await ke(e,o);i.push({type:"non-keyed",values:c.values})}}n||r();let a=0;for(let o of i)if(o.type==="keyed"){let l;try{let c=new V,u=Q(c,o.indexExpr);l=await j(e,u.expression,!1)}catch{if(/^-?\d+$/.test(o.indexExpr))l=Number.parseInt(o.indexExpr,10);else{let c=e.state.env.get(o.indexExpr);l=c?Number.parseInt(c,10):0,Number.isNaN(l)&&(l=0)}}if(o.append){let c=e.state.env.get(`${t}_${l}`)??"";e.state.env.set(`${t}_${l}`,c+o.value)}else e.state.env.set(`${t}_${l}`,o.value);a=l+1}else for(let l of o.values)e.state.env.set(`${t}_${a++}`,l)}async function go(e,t,s,n,r){let i=[];for(let o of s){let l=await ke(e,o);i.push(...l.values)}let a=0;if(n){let o=Se(e,t);if(o.length>0)a=Math.max(...o.map(([c])=>typeof c=="number"?c:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(e.state.env.set(`${t}_0`,l),e.state.env.delete(t),a=1)}}else r();for(let o=0;o<i.length;o++)e.state.env.set(`${t}_${a+o}`,i[o]);n||e.state.env.set(`${t}__length`,String(i.length))}async function wo(e,t,s,n,r,i,a){let o=s;if(ge(e,s)){let f=We(e,s);if(f&&f!==s){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:k("",`bash: \`${f}': not a valid identifier
652
- `,1)};o=f}}if(Ze(e,o)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=ee(e,o);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l=e.state.associativeArrays?.has(o),c;if(l)c=await Si(e,o,n);else{let f=await vo(e,o,n);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};c=`${o}_${f.index}`}let u=i?(e.state.env.get(c)||"")+r:r;if(t.name)a.set(c,e.state.env.get(c)),e.state.env.set(c,u);else{let f=lt(e,o);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(c)||d.set(c,e.state.env.get(c))}e.state.env.set(c,u)}return{continueToNext:!0,xtraceOutput:""}}async function Si(e,t,s){let n;if(s.startsWith("'")&&s.endsWith("'"))n=s.slice(1,-1);else if(s.startsWith('"')&&s.endsWith('"')){let r=s.slice(1,-1),a=new V().parseWordFromString(r,!0,!1);n=await I(e,a)}else if(s.includes("$")){let i=new V().parseWordFromString(s,!1,!1);n=await I(e,i)}else n=s;return`${t}_${n}`}async function vo(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 V,a=Q(i,n);r=await j(e,a.expression,!1)}catch(i){if(i instanceof Ue){let l=`bash: line ${e.state.currentLine}: ${s}: ${i.message}
653
- `;if(i.fatal)throw new B(1,"",l);return{index:0,error:k("",l,1)}}let a=e.state.env.get(s);r=a?Number.parseInt(a,10):0}Number.isNaN(r)&&(r=0)}if(r<0){let i=Se(e,t);if(i.length===0){let o=e.state.currentLine;return{index:0,error:k("",`bash: line ${o}: ${t}[${s}]: bad array subscript
654
- `,1)}}if(r=Math.max(...i.map(([o])=>typeof o=="number"?o:0))+1+r,r<0){let o=e.state.currentLine;return{index:0,error:k("",`bash: line ${o}: ${t}[${s}]: bad array subscript
655
- `,1)}}}return{index:r}}async function bo(e,t,s,n,r,i){let a="",o=s,l=null;if(ge(e,s)){let f=qn(e,s,n);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:k("",`bash: ${s}: circular name reference
656
- `,1)};if(f===null)return{continueToNext:!0,xtraceOutput:""};o=f;let d=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(l={arrayName:d[1],subscriptExpr:d[2]},o=d[1])}if(Ze(e,o)){if(t.name)return a+=`bash: ${o}: readonly variable
657
- `,{continueToNext:!0,xtraceOutput:a};let f=ee(e,o);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let c;if($t(e,o))try{let f=new V;if(r){let h=`(${e.state.env.get(o)||"0"}) + (${n})`,y=Q(f,h);c=String(await j(e,y.expression))}else{let d=Q(f,n);c=String(await j(e,d.expression))}}catch{c="0"}else{let{isArray:f}=await import("./chunks/expansion-PCODPDNZ.js"),d=f(e,o)?`${o}_0`:o;c=r?(e.state.env.get(d)||"")+n:n}c=ft(e,o,c),a+=await vi(e,o,c);let u=o;if(l)u=await $o(e,l);else{let{isArray:f}=await import("./chunks/expansion-PCODPDNZ.js");f(e,o)&&(u=`${o}_0`)}return t.name?(i.set(u,e.state.env.get(u)),e.state.env.set(u,c)):(e.state.env.set(u,c),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(o)),e.state.tempEnvBindings?.some(f=>f.has(o))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(o))),{continueToNext:!1,xtraceOutput:a}}async function $o(e,t){let{arrayName:s,subscriptExpr:n}=t;if(e.state.associativeArrays?.has(s))return Si(e,s,n);let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else{try{let a=new V,o=Q(a,n);i=await j(e,o.expression,!1)}catch{let a=e.state.env.get(n);i=a?Number.parseInt(a,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let a=Se(e,s);a.length>0&&(i=Math.max(...a.map(l=>l[0]))+1+i)}return`${s}_${i}`}async function Ai(e,t,s,n){let r=await Oe(e,t.redirections);if(r)return r;let i=new Map(e.state.env),a=e.state.cwd,o={...e.state.options},l=new Map(e.state.functions),c=e.state.localScopes,u=e.state.localVarStack,f=e.state.localVarDepth,d=e.state.fullyUnsetLocals;if(e.state.localScopes=c.map(S=>new Map(S)),u){e.state.localVarStack=new Map;for(let[S,O]of u.entries())e.state.localVarStack.set(S,O.map(N=>({...N})))}f&&(e.state.localVarDepth=new Map(f)),d&&(e.state.fullyUnsetLocals=new Map(d));let h=e.state.loopDepth,y=e.state.parentHasLoopContext;e.state.parentHasLoopContext=h>0,e.state.loopDepth=0;let p=e.state.lastArg,w=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let $=e.state.groupStdin;s&&(e.state.groupStdin=s);let g="",b="",m=0,v=()=>{e.state.env=i,e.state.cwd=a,e.state.options=o,e.state.functions=l,e.state.localScopes=c,e.state.localVarStack=u,e.state.localVarDepth=f,e.state.fullyUnsetLocals=d,e.state.loopDepth=h,e.state.parentHasLoopContext=y,e.state.groupStdin=$,e.state.bashPid=w,e.state.lastArg=p};try{for(let S of t.body){let O=await n(S);g+=O.stdout,b+=O.stderr,m=O.exitCode}}catch(S){if(v(),S instanceof Y)throw S;if(S instanceof Re){g+=S.stdout,b+=S.stderr;let N=k(g,b,0);return q(e,N,t.redirections)}if(S instanceof de||S instanceof he){g+=S.stdout,b+=S.stderr;let N=k(g,b,0);return q(e,N,t.redirections)}if(S instanceof B){g+=S.stdout,b+=S.stderr;let N=k(g,b,S.exitCode);return q(e,N,t.redirections)}if(S instanceof ce){g+=S.stdout,b+=S.stderr;let N=k(g,b,S.exitCode);return q(e,N,t.redirections)}if(S instanceof pe){let N=k(g+S.stdout,b+S.stderr,S.exitCode);return q(e,N,t.redirections)}let O=k(g,`${b}${$e(S)}
658
- `,1);return q(e,O,t.redirections)}v();let E=k(g,b,m);return q(e,E,t.redirections)}async function _i(e,t,s,n){let r="",i="",a=0,o=await ss(e,t.redirections);if(o)return o;let l=s;for(let f of t.redirections)if((f.operator==="<<"||f.operator==="<<-")&&f.target.type==="HereDoc"){let d=f.target,h=await I(e,d.content);d.stripTabs&&(h=h.split(`
659
- `).map(p=>p.replace(/^\t+/,"")).join(`
660
- `));let y=f.fd??0;y!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),ae(e),e.state.fileDescriptors.set(y,h)):l=h}else if(f.operator==="<<<"&&f.target.type==="Word")l=`${await I(e,f.target)}
661
- `;else if(f.operator==="<"&&f.target.type==="Word")try{let d=await I(e,f.target),h=e.fs.resolvePath(e.state.cwd,d);l=await e.fs.readFile(h)}catch{let d=await I(e,f.target);return k("",`bash: ${d}: No such file or directory
662
- `,1)}let c=e.state.groupStdin;l&&(e.state.groupStdin=l);try{for(let f of t.body){let d=await n(f);r+=d.stdout,i+=d.stderr,a=d.exitCode}}catch(f){if(e.state.groupStdin=c,f instanceof Y)throw f;if(xt(f)||f instanceof pe||f instanceof B)throw f.prependOutput(r,i),f;return k(r,`${i}${$e(f)}
663
- `,1)}e.state.groupStdin=c;let u=k(r,i,a);return q(e,u,t.redirections)}async function Ci(e,t,s,n,r){let i;try{i=await e.fs.readFile(t)}catch{return _(`bash: ${t}: No such file or directory
664
- `,127)}if(i.startsWith("#!")){let w=i.indexOf(`
665
- `);w!==-1&&(i=i.slice(w+1))}let a=new Map(e.state.env),o=e.state.cwd,l={...e.state.options},c=e.state.loopDepth,u=e.state.parentHasLoopContext,f=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,y=e.state.currentSource;e.state.parentHasLoopContext=c>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,n&&(e.state.groupStdin=n),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(s.length)),e.state.env.set("@",s.join(" ")),e.state.env.set("*",s.join(" "));for(let w=0;w<s.length&&w<9;w++)e.state.env.set(String(w+1),s[w]);for(let w=s.length+1;w<=9;w++)e.state.env.delete(String(w));let p=()=>{e.state.env=a,e.state.cwd=o,e.state.options=l,e.state.loopDepth=c,e.state.parentHasLoopContext=u,e.state.lastArg=f,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=y};try{let $=new V().parse(i),g=await r($);return p(),g}catch(w){if(p(),w instanceof B||w instanceof Y)throw w;if(w.name==="ParseException")return _(`bash: ${t}: ${w.message}
666
- `);throw w}}var Ct=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,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode,invokeTool:t.invokeTool}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||be.isInSandboxedContext())return;let s=`interpreter ${t} attempted outside defense context`;throw new Je(s,{timestamp:Date.now(),type:"missing_defense_context",message:s,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:be.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,n=new Set;if(t)for(let i of t)n.add(i);if(s)for(let i of s)n.add(i);if(n.size===0)return Object.create(null);let r=Object.create(null);for(let i of n){let a=this.ctx.state.env.get(i);a!==void 0&&(r[i]=a)}return r}async executeScript(t){this.assertDefenseContext("execution");let s="",n="",r=0,i=this.ctx.limits.maxOutputSize,a=(o,l)=>{s.length+n.length+o.length+l.length>i&&Pe(`total output size exceeded (>${i} bytes), increase executionLimits.maxOutputSize`,"output_size"),s+=o,n+=l};for(let o of t.statements)try{let l=await this.executeStatement(o);a(ws(l),l.stderr),r=l.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}catch(l){if(l instanceof B)throw l.prependOutput(s,n),l;if(l instanceof me)return a(l.stdout,l.stderr),r=l.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Le(this.ctx.state.env)};if(l instanceof Y)throw l;if(l instanceof pe)return a(l.stdout,l.stderr),r=l.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Le(this.ctx.state.env)};if(l instanceof Fn)return a(l.stdout,l.stderr),r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Le(this.ctx.state.env)};if(l instanceof Dt)return a(l.stdout,l.stderr),r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:Le(this.ctx.state.env)};if(l instanceof Ue){a(l.stdout,l.stderr),r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(l instanceof Mn){a(l.stdout,l.stderr),r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(l instanceof de||l instanceof he){if(this.ctx.state.loopDepth>0)throw l.prependOutput(s,n),l;a(l.stdout,l.stderr);continue}throw l instanceof ce&&l.prependOutput(s,n),l}return{stdout:s,stderr:n,exitCode:r,env:Le(this.ctx.state.env)}}async executeUserScript(t,s,n=""){return Ci(this.ctx,t,s,n,r=>this.executeScript(r))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new It;if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&Pe(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new Rt(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return M;this.ctx.state.errexitSafe=!1;let s="",n="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(n+=`${t.sourceText}
667
- `);let r=0,i=-1,a=!1;for(let c=0;c<t.pipelines.length;c++){let u=t.pipelines[c],f=c>0?t.operators[c-1]:null;if(f==="&&"&&r!==0||f==="||"&&r===0)continue;let d=await this.executePipeline(u);s+=ws(d),n+=d.stderr,r=d.exitCode,i=c,a=u.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}let o=i<t.pipelines.length-1,l=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=o||a||l,this.ctx.state.options.errexit&&r!==0&&i===t.pipelines.length-1&&!a&&!this.ctx.state.inCondition&&!l)throw new pe(r,s,n);return k(s,n,r)}async executePipeline(t){return $i(this.ctx,t,(s,n)=>this.executeCommand(s,n))}async executeCommand(t,s){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return ci(this.ctx,t);case"For":return ui(this.ctx,t);case"CStyleFor":return fi(this.ctx,t);case"While":return di(this.ctx,t,s);case"Until":return hi(this.ctx,t);case"Case":return pi(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return Or(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return M}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(n){if(n instanceof Tt)return _(n.stderr);throw n}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let m=t,v=100;for(;v>0;){let E=this.expandAlias(m);if(E===m)break;m=E,v--}this.aliasExpansionStack.clear(),m!==t&&(t=m)}this.ctx.state.expansionStderr="";let n=await Ei(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 v=await Oe(this.ctx,t.redirections);if(v)return v;let E=k("",i,0);return q(this.ctx,E,t.redirections)}this.ctx.state.lastArg="";let m=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",k("",m,this.ctx.state.lastExitCode)}let a=t.name&&kn(t.name,["local","declare","typeset","export","readonly"]),o=Array.from(r.keys());if(o.length>0&&!a){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let m of o)this.ctx.state.tempExportedVars.add(m)}let l=await ss(this.ctx,t.redirections);if(l){for(let[m,v]of r)v===void 0?this.ctx.state.env.delete(m):this.ctx.state.env.set(m,v);return l}let c=-1;for(let m of t.redirections){if((m.operator==="<<"||m.operator==="<<-")&&m.target.type==="HereDoc"){let v=m.target,E=await I(this.ctx,v.content);v.stripTabs&&(E=E.split(`
668
- `).map(O=>O.replace(/^\t+/,"")).join(`
669
- `)),E=He(E);let S=m.fd??0;S!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),ae(this.ctx),this.ctx.state.fileDescriptors.set(S,E)):s=E;continue}if(m.operator==="<<<"&&m.target.type==="Word"){s=He(`${await I(this.ctx,m.target)}
670
- `);continue}if(m.operator==="<"&&m.target.type==="Word")try{let v=await I(this.ctx,m.target),E=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);s=await Ln(this.ctx.fs,E)}catch{let v=await I(this.ctx,m.target);for(let[E,S]of r)S===void 0?this.ctx.state.env.delete(E):this.ctx.state.env.set(E,S);return _(`bash: ${v}: No such file or directory
671
- `)}if(m.operator==="<&"&&m.target.type==="Word"){let v=await I(this.ctx,m.target),E=Number.parseInt(v,10);if(!Number.isNaN(E)&&this.ctx.state.fileDescriptors){let S=this.ctx.state.fileDescriptors.get(E);if(S!==void 0)if(S.startsWith("__rw__:")){let O=mi(S);O&&(s=O.content.slice(O.position),c=E)}else S.startsWith("__file__:")||S.startsWith("__file_append__:")||(s=S)}}}let u=await I(this.ctx,t.name),f=[],d=[];if(kn(t.name,["local","declare","typeset","export","readonly"])&&(u==="local"||u==="declare"||u==="typeset"||u==="export"||u==="readonly"))for(let m of t.args){let v=await hr(this.ctx,m);if(v)f.push(v),d.push(!0);else{let E=await pr(this.ctx,m);if(E!==null)f.push(E),d.push(!0);else{let S=await ke(this.ctx,m);for(let O of S.values)f.push(O),d.push(S.quoted)}}}else for(let m of t.args){let v=await ke(this.ctx,m);for(let E of v.values)f.push(E),d.push(v.quoted)}if(!u){if(t.name.parts.every(v=>v.type==="CommandSubstitution"||v.type==="ParameterExpansion"||v.type==="ArithmeticExpansion")){if(f.length>0){let v=f.shift();return d.shift(),await this.runCommand(v,f,d,s,!1,!1,c)}return k("","",this.ctx.state.lastExitCode)}return _(`bash: : command not found
672
- `,127)}if(u==="exec"&&(f.length===0||f[0]==="--")){for(let m of t.redirections){if(m.target.type==="HereDoc"||m.fdVariable)continue;let v=await I(this.ctx,m.target),E=m.fd??(m.operator==="<"||m.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),m.operator){case">":case">|":{let S=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);await this.ctx.fs.writeFile(S,"","utf8"),ae(this.ctx),this.ctx.state.fileDescriptors.set(E,`__file__:${S}`);break}case">>":{let S=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);ae(this.ctx),this.ctx.state.fileDescriptors.set(E,`__file_append__:${S}`);break}case"<":{let S=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);try{let O=await this.ctx.fs.readFile(S);ae(this.ctx),this.ctx.state.fileDescriptors.set(E,O)}catch{return _(`bash: ${v}: No such file or directory
673
- `)}break}case"<>":{let S=this.ctx.fs.resolvePath(this.ctx.state.cwd,v);try{let O=await this.ctx.fs.readFile(S);ae(this.ctx),this.ctx.state.fileDescriptors.set(E,`__rw__:${S.length}:${S}:0:${O}`)}catch{await this.ctx.fs.writeFile(S,"","utf8"),ae(this.ctx),this.ctx.state.fileDescriptors.set(E,`__rw__:${S.length}:${S}:0:`)}break}case">&":{if(v==="-")this.ctx.state.fileDescriptors.delete(E);else if(v.endsWith("-")){let S=v.slice(0,-1),O=Number.parseInt(S,10);if(!Number.isNaN(O)){let N=this.ctx.state.fileDescriptors.get(O);N!==void 0?this.ctx.state.fileDescriptors.set(E,N):this.ctx.state.fileDescriptors.set(E,`__dupout__:${O}`),this.ctx.state.fileDescriptors.delete(O)}}else{let S=Number.parseInt(v,10);Number.isNaN(S)||(ae(this.ctx),this.ctx.state.fileDescriptors.set(E,`__dupout__:${S}`))}break}case"<&":{if(v==="-")this.ctx.state.fileDescriptors.delete(E);else if(v.endsWith("-")){let S=v.slice(0,-1),O=Number.parseInt(S,10);if(!Number.isNaN(O)){let N=this.ctx.state.fileDescriptors.get(O);N!==void 0?this.ctx.state.fileDescriptors.set(E,N):this.ctx.state.fileDescriptors.set(E,`__dupin__:${O}`),this.ctx.state.fileDescriptors.delete(O)}}else{let S=Number.parseInt(v,10);Number.isNaN(S)||(ae(this.ctx),this.ctx.state.fileDescriptors.set(E,`__dupin__:${S}`))}break}}}for(let[m,v]of r)v===void 0?this.ctx.state.env.delete(m):this.ctx.state.env.set(m,v);if(this.ctx.state.tempExportedVars)for(let m of r.keys())this.ctx.state.tempExportedVars.delete(m);return M}if(this.ctx.state.extraArgs){f.push(...this.ctx.state.extraArgs);for(let m=0;m<this.ctx.state.extraArgs.length;m++)d.push(!0);this.ctx.state.extraArgs=void 0}let y=await wi(this.ctx,u,f);r.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(r)));let p,w=null;try{p=await this.runCommand(u,f,d,s,!1,!1,c)}catch(m){if(m instanceof de||m instanceof he)w=m,p=M;else throw m}let $=i+y;if($&&(p={...p,stderr:$+p.stderr}),p=await q(this.ctx,p,t.redirections),w)throw w;if(f.length>0){let m=f[f.length-1];if((u==="declare"||u==="local"||u==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(m)){let v=m.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);v&&(m=v[1])}this.ctx.state.lastArg=m}else this.ctx.state.lastArg=u;let g=Pr(u)&&u!=="unset"&&u!=="eval";if(!this.ctx.state.options.posix||!g)for(let[m,v]of r)this.ctx.state.fullyUnsetLocals?.has(m)||(v===void 0?this.ctx.state.env.delete(m):this.ctx.state.env.set(m,v));if(this.ctx.state.tempExportedVars)for(let m of r.keys())this.ctx.state.tempExportedVars.delete(m);return r.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(p={...p,stderr:this.ctx.state.expansionStderr+p.stderr},this.ctx.state.expansionStderr=""),p}async runCommand(t,s,n,r,i=!1,a=!1,o=-1){let l={ctx:this.ctx,runCommand:(u,f,d,h,y,p,w)=>this.runCommand(u,f,d,h,y,p,w),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(u,f,d)=>this.executeUserScript(u,f,d)},c=await oi(l,t,s,n,r,i,a,o);return c!==null?c:li(l,t,s,r,a)}aliasExpansionStack=new Set;expandAlias(t){return xs(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return cs(this.ctx,t)}async executeSubshell(t,s=""){return Ai(this.ctx,t,s,n=>this.executeStatement(n))}async executeGroup(t,s=""){return _i(this.ctx,t,s,n=>this.executeStatement(n))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await Oe(this.ctx,t.redirections);if(s)return s;try{let n=await j(this.ctx,t.expression.expression),r=X(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),q(this.ctx,r,t.redirections)}catch(n){let r=_(`bash: arithmetic expression: ${n.message}
674
- `);return q(this.ctx,r,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await Oe(this.ctx,t.redirections);if(s)return s;try{let n=await ze(this.ctx,t.expression),r=X(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),q(this.ctx,r,t.redirections)}catch(n){let r=n instanceof Ue?1:2,i=_(`bash: conditional expression: ${n.message}
675
- `,r);return q(this.ctx,i,t.redirections)}}};var te={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,maxGlobOperations:1e5,maxStringLength:10485760,maxArrayElements:1e5,maxHeredocSize:10485760,maxSubstitutionDepth:50,maxBraceExpansionResults:1e4,maxOutputSize:10485760,maxFileDescriptors:1024,maxSourceDepth:100};function ki(e){return e?{maxCallDepth:e.maxCallDepth??te.maxCallDepth,maxCommandCount:e.maxCommandCount??te.maxCommandCount,maxLoopIterations:e.maxLoopIterations??te.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??te.maxAwkIterations,maxSedIterations:e.maxSedIterations??te.maxSedIterations,maxJqIterations:e.maxJqIterations??te.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??te.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??te.maxPythonTimeoutMs,maxJsTimeoutMs:e.maxJsTimeoutMs??te.maxJsTimeoutMs,maxGlobOperations:e.maxGlobOperations??te.maxGlobOperations,maxStringLength:e.maxStringLength??te.maxStringLength,maxArrayElements:e.maxArrayElements??te.maxArrayElements,maxHeredocSize:e.maxHeredocSize??te.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??te.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??te.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??te.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??te.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??te.maxSourceDepth}:{...te}}import{lookup as Do}from"node:dns";function Pn(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function Eo(e){let t=Pn(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function Pi(e){if(e.includes("\\"))return!0;let t=e.toLowerCase();return t.includes("%2f")||t.includes("%5c")}function So(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function Nn(e,t){let s=Pn(e);if(!s)return!1;let n=Eo(t);return!n||s.origin!==n.origin||n.pathPrefix!=="/"&&n.pathPrefix!==""&&Pi(s.pathname)?!1:So(s.pathname,n.pathPrefix)}function Ni(e){return typeof e=="string"?e:e.url}function Oi(e,t){return!t||t.length===0?!1:t.some(s=>Nn(e,Ni(s)))}function On(e){let t=Ao(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let s=Di(t);if(s)return fs(s);let n=Co(t);return n?ko(n):!1}function Ao(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function _o(e){if(!e)return null;let t=10,s=e;if(s.startsWith("0x")||s.startsWith("0X")?(t=16,s=s.slice(2)):s.length>1&&s.startsWith("0")&&(t=8),!s||t===16&&!/^[0-9a-fA-F]+$/.test(s)||t===10&&!/^\d+$/.test(s)||t===8&&!/^[0-7]+$/.test(s))return null;let n=Number.parseInt(s,t);return!Number.isFinite(n)||n<0?null:n}function Di(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let s=t.map(l=>_o(l));if(s.some(l=>l===null))return null;let n=s;if(t.length===1){let l=n[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,c]=n;return l>255||c>16777215?null:[l,c>>>16&255,c>>>8&255,c&255]}if(t.length===3){let[l,c,u]=n;return l>255||c>255||u>65535?null:[l,c,u>>>8&255,u&255]}let[r,i,a,o]=n;return r>255||i>255||a>255||o>255?null:[r,i,a,o]}function Co(e){let t=e,s=null;if(t.includes(".")){let p=t.lastIndexOf(":");if(p<0)return null;let w=t.slice(p+1),$=Di(w);if(!$)return null;s=$,t=t.slice(0,p)}let n=t.includes("::")?t.split("::").length-1:0;if(n>1)return null;let[r,i]=t.split("::"),a=r?r.split(":").filter(Boolean):[],o=i?i.split(":").filter(Boolean):[],l=p=>/^[0-9a-f]{1,4}$/i.test(p)?Number.parseInt(p,16):null,c=a.map(l),u=o.map(l);if(c.some(p=>p===null)||u.some(p=>p===null))return null;let f=s?2:0,d=c.length+u.length+f,h=0;if(n===1){if(h=8-d,h<0)return null}else if(d!==8)return null;let y=[...c,...new Array(h).fill(0),...u];return s&&(y.push(s[0]<<8|s[1]),y.push(s[2]<<8|s[3])),y.length===8?y:null}function fs(e){let[t,s]=e;return t===127||t===10||t===172&&s>=16&&s<=31||t===192&&s===168||t===169&&s===254||t===0||t===100&&s>=64&&s<=127||t===198&&(s===18||s===19)||t===192&&s===0&&e[2]===0||t===192&&s===0&&e[2]===2||t===198&&s===51&&e[2]===100||t===203&&s===0&&e[2]===113||t>=240}function ko(e){if(e.every(r=>r===0)||e.slice(0,7).every(r=>r===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let r=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return fs(r)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let r=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return fs(r)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let r=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return fs(r)}return!1}function Ti(e){let t=[];for(let s of e){if(typeof s!="string"&&(s===null||typeof s!="object"||!("url"in s)||typeof s.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let n=Ni(s);if(!Pn(n)){t.push(`Invalid URL in allow-list: "${n}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(n);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${n}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${n}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&Pi(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${n}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${n}"`)}return t}var Po=typeof __BROWSER__<"u"&&__BROWSER__,dt=null,ds=null,Ii=!1;function No(){if(dt===null&&!Po)try{let e=In("node:async_hooks");ds=In("node:dns"),dt=new e.AsyncLocalStorage}catch{}}function Oo(){if(Ii||(No(),!dt||!ds))return;Ii=!0;let e=dt,t=ds.lookup;function s(...n){let r=n[0],i=e.getStore();if(typeof r!="string"||!i||i.hostname.toLowerCase()!==r.toLowerCase())return t.apply(this,n);let a={},o;if(n.length===2)o=n[1];else if(n.length>=3){let c=n[1];typeof c=="number"?a={family:c}:c&&typeof c=="object"&&(a=c),o=n[2]}if(typeof o!="function")return t.apply(this,n);let l=o;if(a.family!==void 0&&a.family!==0&&a.family!==i.family){let c=new Error(`ENOTFOUND ${r}`);c.code="ENOTFOUND",c.errno=-3008,c.syscall="getaddrinfo",c.hostname=r,process.nextTick(()=>l(c));return}process.nextTick(()=>{a.all?l(null,[{address:i.address,family:i.family}]):l(null,i.address,i.family)})}Object.defineProperty(ds,"lookup",{value:s,writable:!0,configurable:!0})}function xi(e,t){return Oo(),dt?dt.run(e,t):t()}var De=class extends Error{constructor(t,s){let n=s??"URL not in allow-list";super(`Network access denied: ${n}: ${t}`),this.name="NetworkAccessDeniedError"}},kt=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},Pt=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},hs=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}},ht=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};function To(e){return new Promise((t,s)=>{Do(e,{all:!0},(n,r)=>{n?s(n):t(r)})})}var Io=20,xo=3e4,Ro=10485760,Lo=["GET","HEAD"],Fo=new Set(["GET","HEAD","OPTIONS"]),Mo=new Set([301,302,303,307,308]);function Dn(e){let t=e.allowedUrlPrefixes??[];if(!e.dangerouslyAllowFullInternetAccess){let h=Ti(t);if(h.length>0)throw new Error(`Invalid network allow-list:
720
+ `,i={...i,stderr:i.stderr+y}}return u&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=c),i}async function ql(e,t){let s=new Map,r="";for(let n of t.assignments){let i=n.name;if(n.array){let c=await Jf(e,t,i,n.array,n.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:c.error};if(r+=c.xtraceOutput,c.continueToNext)continue}let a=n.value?await W(e,n.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:P("",`bash: ${i}: bad array subscript
721
+ `,1)};let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let c=await rd(e,t,o[1],o[2],a,n.append,s);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:c.error};if(c.continueToNext)continue}let u=await ad(e,t,i,a,n.append,s);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:s,error:u.error};r+=u.xtraceOutput,u.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:s}}async function Jf(e,t,s,r,n,i){let a="";if(/\[.+\]$/.test(s))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: cannot assign list to array member
722
+ `,1)};if(ee(e,s)){let c=kt(e,s);if(c===void 0||c==="")throw new U(1,"","");let f=Se(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
723
+ `,1)}}if(et(e,s)){if(t.name)return a+=`bash: ${s}: readonly variable
724
+ `,{continueToNext:!0,xtraceOutput:a};let c=me(e,s);if(c)return{continueToNext:!1,xtraceOutput:"",error:c}}let l=e.state.associativeArrays?.has(s),o=ed(r),u=()=>{let c=`${s}_`;for(let f of e.state.env.keys())f.startsWith(c)&&!f.includes("__")&&e.state.env.delete(f);e.state.env.delete(s)};if(l&&o?await td(e,t,s,r,n,u,c=>{a+=c}):o?await sd(e,s,r,n,u):await nd(e,s,r,n,u),t.name){i.set(s,e.state.env.get(s));let f=`(${r.map(d=>Ft(d)).join(" ")})`;e.state.env.set(s,f)}return{continueToNext:!0,xtraceOutput:a}}function ed(e){return e.some(t=>{if(t.parts.length>=2){let s=t.parts[0],r=t.parts[1];if(s.type!=="Glob"||!s.pattern.startsWith("["))return!1;if(s.pattern==="["&&(r.type==="DoubleQuoted"||r.type==="SingleQuoted")){if(t.parts.length<3)return!1;let n=t.parts[2];return n.type!=="Literal"?!1:n.value.startsWith("]=")||n.value.startsWith("]+=")}return r.type!=="Literal"?!1:r.value.startsWith("]")?r.value.startsWith("]=")||r.value.startsWith("]+="):s.pattern.endsWith("]")?r.value.startsWith("=")||r.value.startsWith("+="):!1}return!1})}async function td(e,t,s,r,n,i,a){let l=[];for(let o of r){let u=nr(o);if(u){let{key:c,valueParts:f,append:d}=u,h;f.length>0?h=await W(e,{type:"Word",parts:f}):h="",h=ue(e,h),l.push({type:"keyed",key:c,value:h,append:d})}else{let c=await W(e,o);l.push({type:"invalid",expandedValue:c})}}n||i();for(let o of l)if(o.type==="keyed")if(o.append){let u=e.state.env.get(`${s}_${o.key}`)??"";e.state.env.set(`${s}_${o.key}`,u+o.value)}else e.state.env.set(`${s}_${o.key}`,o.value);else{let u=t.line??e.state.currentLine??1;a(`bash: line ${u}: ${s}: ${o.expandedValue}: must use subscript when assigning associative array
725
+ `)}}async function sd(e,t,s,r,n){let i=[];for(let l of s){let o=nr(l);if(o){let{key:u,valueParts:c,append:f}=o,d;c.length>0?d=await W(e,{type:"Word",parts:c}):d="",d=ue(e,d),i.push({type:"keyed",indexExpr:u,value:d,append:f})}else{let u=await tt(e,l);i.push({type:"non-keyed",values:u.values})}}r||n();let a=0;for(let l of i)if(l.type==="keyed"){let o;try{let u=new V,c=X(u,l.indexExpr);o=await T(e,c.expression,!1)}catch{if(/^-?\d+$/.test(l.indexExpr))o=Number.parseInt(l.indexExpr,10);else{let u=e.state.env.get(l.indexExpr);o=u?Number.parseInt(u,10):0,Number.isNaN(o)&&(o=0)}}if(l.append){let u=e.state.env.get(`${t}_${o}`)??"";e.state.env.set(`${t}_${o}`,u+l.value)}else e.state.env.set(`${t}_${o}`,l.value);a=o+1}else for(let o of l.values)e.state.env.set(`${t}_${a++}`,o)}async function nd(e,t,s,r,n){let i=[];for(let l of s){let o=await tt(e,l);i.push(...o.values)}let a=0;if(r){let l=F(e,t);if(l.length>0)a=Math.max(...l.map(([u])=>typeof u=="number"?u:0))+1;else{let o=e.state.env.get(t);o!==void 0&&(e.state.env.set(`${t}_0`,o),e.state.env.delete(t),a=1)}}else n();for(let l=0;l<i.length;l++)e.state.env.set(`${t}_${a+l}`,i[l]);r||e.state.env.set(`${t}__length`,String(i.length))}async function rd(e,t,s,r,n,i,a){let l=s;if(ee(e,s)){let f=Se(e,s);if(f&&f!==s){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: \`${f}': not a valid identifier
726
+ `,1)};l=f}}if(et(e,l)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=me(e,l);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let o=e.state.associativeArrays?.has(l),u;if(o)u=await Ul(e,l,r);else{let f=await id(e,l,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};u=`${l}_${f.index}`}let c=i?(e.state.env.get(u)||"")+n:n;if(t.name)a.set(u,e.state.env.get(u)),e.state.env.set(u,c);else{let f=qt(e,l);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))}e.state.env.set(u,c)}return{continueToNext:!0,xtraceOutput:""}}async function Ul(e,t,s){let r;if(s.startsWith("'")&&s.endsWith("'"))r=s.slice(1,-1);else if(s.startsWith('"')&&s.endsWith('"')){let n=s.slice(1,-1),a=new V().parseWordFromString(n,!0,!1);r=await W(e,a)}else if(s.includes("$")){let i=new V().parseWordFromString(s,!1,!1);r=await W(e,i)}else r=s;return`${t}_${r}`}async function id(e,t,s){let r=s;s.startsWith('"')&&s.endsWith('"')&&s.length>=2&&(r=s.slice(1,-1));let n;if(/^-?\d+$/.test(r))n=Number.parseInt(r,10);else{try{let i=new V,a=X(i,r);n=await T(e,a.expression,!1)}catch(i){if(i instanceof te){let o=`bash: line ${e.state.currentLine}: ${s}: ${i.message}
727
+ `;if(i.fatal)throw new U(1,"",o);return{index:0,error:P("",o,1)}}let a=e.state.env.get(s);n=a?Number.parseInt(a,10):0}Number.isNaN(n)&&(n=0)}if(n<0){let i=F(e,t);if(i.length===0){let l=e.state.currentLine;return{index:0,error:P("",`bash: line ${l}: ${t}[${s}]: bad array subscript
728
+ `,1)}}if(n=Math.max(...i.map(([l])=>typeof l=="number"?l:0))+1+n,n<0){let l=e.state.currentLine;return{index:0,error:P("",`bash: line ${l}: ${t}[${s}]: bad array subscript
729
+ `,1)}}}return{index:n}}async function ad(e,t,s,r,n,i){let a="",l=s,o=null;if(ee(e,s)){let f=Na(e,s,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:P("",`bash: ${s}: circular name reference
730
+ `,1)};if(f===null)return{continueToNext:!0,xtraceOutput:""};l=f;let d=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(o={arrayName:d[1],subscriptExpr:d[2]},l=d[1])}if(et(e,l)){if(t.name)return a+=`bash: ${l}: readonly variable
731
+ `,{continueToNext:!0,xtraceOutput:a};let f=me(e,l);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let u;if(ls(e,l))try{let f=new V;if(n){let h=`(${e.state.env.get(l)||"0"}) + (${r})`,p=X(f,h);u=String(await T(e,p.expression))}else{let d=X(f,r);u=String(await T(e,d.expression))}}catch{u="0"}else{let f=He(e,l)?`${l}_0`:l;u=n?(e.state.env.get(f)||"")+r:r}u=jt(e,l,u),a+=await Vl(e,l,u);let c=l;return o?c=await od(e,o):He(e,l)&&(c=`${l}_0`),t.name?(i.set(c,e.state.env.get(c)),e.state.env.set(c,u)):(e.state.env.set(c,u),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(l)),e.state.tempEnvBindings?.some(f=>f.has(l))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(l))),{continueToNext:!1,xtraceOutput:a}}async function od(e,t){let{arrayName:s,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(s))return Ul(e,s,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let a=new V,l=X(a,r);i=await T(e,l.expression,!1)}catch{let a=e.state.env.get(r);i=a?Number.parseInt(a,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let a=F(e,s);a.length>0&&(i=Math.max(...a.map(o=>o[0]))+1+i)}return`${s}_${i}`}async function Zl(e,t,s,r){let n=await rt(e,t.redirections);if(n)return n;let i=new Map(e.state.env),a=e.state.cwd,l={...e.state.options},o=new Map(e.state.functions),u=e.state.localScopes,c=e.state.localVarStack,f=e.state.localVarDepth,d=e.state.fullyUnsetLocals;if(e.state.localScopes=u.map($=>new Map($)),c){e.state.localVarStack=new Map;for(let[$,R]of c.entries())e.state.localVarStack.set($,R.map(I=>({...I})))}f&&(e.state.localVarDepth=new Map(f)),d&&(e.state.fullyUnsetLocals=new Map(d));let h=e.state.loopDepth,p=e.state.parentHasLoopContext;e.state.parentHasLoopContext=h>0,e.state.loopDepth=0;let m=e.state.lastArg,y=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let b=e.state.groupStdin;s&&(e.state.groupStdin=s);let v="",E="",w=0,S=()=>{e.state.env=i,e.state.cwd=a,e.state.options=l,e.state.functions=o,e.state.localScopes=u,e.state.localVarStack=c,e.state.localVarDepth=f,e.state.fullyUnsetLocals=d,e.state.loopDepth=h,e.state.parentHasLoopContext=p,e.state.groupStdin=b,e.state.bashPid=y,e.state.lastArg=m};try{for(let $ of t.body){let R=await r($);v+=R.stdout,E+=R.stderr,w=R.exitCode}}catch($){if(S(),$ instanceof Q)throw $;if($ instanceof ft){v+=$.stdout,E+=$.stderr;let I=P(v,E,0);return le(e,I,t.redirections)}if($ instanceof Ie||$ instanceof Ce){v+=$.stdout,E+=$.stderr;let I=P(v,E,0);return le(e,I,t.redirections)}if($ instanceof U){v+=$.stdout,E+=$.stderr;let I=P(v,E,$.exitCode);return le(e,I,t.redirections)}if($ instanceof Ne){v+=$.stdout,E+=$.stderr;let I=P(v,E,$.exitCode);return le(e,I,t.redirections)}if($ instanceof We){let I=P(v+$.stdout,E+$.stderr,$.exitCode);return le(e,I,t.redirections)}let R=P(v,`${E}${qe($)}
732
+ `,1);return le(e,R,t.redirections)}S();let A=P(v,E,w);return le(e,A,t.redirections)}async function Hl(e,t,s,r){let n="",i="",a=0,l=await rn(e,t.redirections);if(l)return l;let o=s;for(let f of t.redirections)if((f.operator==="<<"||f.operator==="<<-")&&f.target.type==="HereDoc"){let d=f.target,h=await W(e,d.content);d.stripTabs&&(h=h.split(`
733
+ `).map(m=>m.replace(/^\t+/,"")).join(`
734
+ `));let p=f.fd??0;p!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),ve(e),e.state.fileDescriptors.set(p,h)):o=h}else if(f.operator==="<<<"&&f.target.type==="Word")o=`${await W(e,f.target)}
735
+ `;else if(f.operator==="<"&&f.target.type==="Word")try{let d=await W(e,f.target),h=e.fs.resolvePath(e.state.cwd,d);o=await e.fs.readFile(h)}catch{let d=await W(e,f.target);return P("",`bash: ${d}: No such file or directory
736
+ `,1)}let u=e.state.groupStdin;o&&(e.state.groupStdin=o);try{for(let f of t.body){let d=await r(f);n+=d.stdout,i+=d.stderr,a=d.exitCode}}catch(f){if(e.state.groupStdin=u,f instanceof Q)throw f;if(bs(f)||f instanceof We||f instanceof U)throw f.prependOutput(n,i),f;return P(n,`${i}${qe(f)}
737
+ `,1)}e.state.groupStdin=u;let c=P(n,i,a);return le(e,c,t.redirections)}async function jl(e,t,s,r,n){let i;try{i=await e.fs.readFile(t)}catch{return _(`bash: ${t}: No such file or directory
738
+ `,127)}if(i.startsWith("#!")){let y=i.indexOf(`
739
+ `);y!==-1&&(i=i.slice(y+1))}let a=new Map(e.state.env),l=e.state.cwd,o={...e.state.options},u=e.state.loopDepth,c=e.state.parentHasLoopContext,f=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,p=e.state.currentSource;e.state.parentHasLoopContext=u>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,r&&(e.state.groupStdin=r),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(s.length)),e.state.env.set("@",s.join(" ")),e.state.env.set("*",s.join(" "));for(let y=0;y<s.length&&y<9;y++)e.state.env.set(String(y+1),s[y]);for(let y=s.length+1;y<=9;y++)e.state.env.delete(String(y));let m=()=>{e.state.env=a,e.state.cwd=l,e.state.options=o,e.state.loopDepth=u,e.state.parentHasLoopContext=c,e.state.lastArg=f,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=p};try{let b=new V().parse(i),v=await n(b);return m(),v}catch(y){if(m(),y instanceof U||y instanceof Q)throw y;if(y.name==="ParseException")return _(`bash: ${t}: ${y.message}
740
+ `);throw y}}var hs=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,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode,invokeTool:t.invokeTool}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||Be.isInSandboxedContext())return;let s=`interpreter ${t} attempted outside defense context`;throw new Ct(s,{timestamp:Date.now(),type:"missing_defense_context",message:s,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:Be.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,r=new Set;if(t)for(let i of t)r.add(i);if(s)for(let i of s)r.add(i);if(r.size===0)return Object.create(null);let n=Object.create(null);for(let i of r){let a=this.ctx.state.env.get(i);a!==void 0&&(n[i]=a)}return n}async executeScript(t){this.assertDefenseContext("execution");let s="",r="",n=0,i=this.ctx.limits.maxOutputSize,a=(l,o)=>{s.length+r.length+l.length+o.length>i&&st(`total output size exceeded (>${i} bytes), increase executionLimits.maxOutputSize`,"output_size"),s+=l,r+=o};for(let l of t.statements)try{let o=await this.executeStatement(l);a(vn(o),o.stderr),n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(o){if(o instanceof U)throw o.prependOutput(s,r),o;if(o instanceof Me)return a(o.stdout,o.stderr),n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:dt(this.ctx.state.env)};if(o instanceof Q)throw o;if(o instanceof We)return a(o.stdout,o.stderr),n=o.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:dt(this.ctx.state.env)};if(o instanceof Re)return a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:dt(this.ctx.state.env)};if(o instanceof xe)return a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:dt(this.ctx.state.env)};if(o instanceof te){a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(o instanceof ws){a(o.stdout,o.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(o instanceof Ie||o instanceof Ce){if(this.ctx.state.loopDepth>0)throw o.prependOutput(s,r),o;a(o.stdout,o.stderr);continue}throw o instanceof Ne&&o.prependOutput(s,r),o}return{stdout:s,stderr:r,exitCode:n,env:dt(this.ctx.state.env)}}async executeUserScript(t,s,r=""){return jl(this.ctx,t,s,r,n=>this.executeScript(n))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Es;if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&st(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new we(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return G;this.ctx.state.errexitSafe=!1;let s="",r="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(r+=`${t.sourceText}
741
+ `);let n=0,i=-1,a=!1;for(let u=0;u<t.pipelines.length;u++){let c=t.pipelines[u],f=u>0?t.operators[u-1]:null;if(f==="&&"&&n!==0||f==="||"&&n===0)continue;let d=await this.executePipeline(c);s+=vn(d),r+=d.stderr,n=d.exitCode,i=u,a=c.negated,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}let l=i<t.pipelines.length-1,o=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=l||a||o,this.ctx.state.options.errexit&&n!==0&&i===t.pipelines.length-1&&!a&&!this.ctx.state.inCondition&&!o)throw new We(n,s,r);return P(s,r,n)}async executePipeline(t){return Bl(this.ctx,t,(s,r)=>this.executeCommand(s,r))}async executeCommand(t,s){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return Il(this.ctx,t);case"For":return Cl(this.ctx,t);case"CStyleFor":return Rl(this.ctx,t);case"While":return xl(this.ctx,t,s);case"Until":return Ol(this.ctx,t);case"Case":return Tl(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return Xo(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return G}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(r){if(r instanceof ut)return _(r.stderr);throw r}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let w=t,S=100;for(;S>0;){let A=this.expandAlias(w);if(A===w)break;w=A,S--}this.aliasExpansionStack.clear(),w!==t&&(t=w)}this.ctx.state.expansionStderr="";let r=await ql(this.ctx,t);if(r.error)return r.error;let n=r.tempAssignments,i=r.xtraceOutput;if(!t.name){if(t.redirections.length>0){let S=await rt(this.ctx,t.redirections);if(S)return S;let A=P("",i,0);return le(this.ctx,A,t.redirections)}this.ctx.state.lastArg="";let w=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",P("",w,this.ctx.state.lastExitCode)}let a=t.name&&ai(t.name,["local","declare","typeset","export","readonly"]),l=Array.from(n.keys());if(l.length>0&&!a){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let w of l)this.ctx.state.tempExportedVars.add(w)}let o=await rn(this.ctx,t.redirections);if(o){for(let[w,S]of n)S===void 0?this.ctx.state.env.delete(w):this.ctx.state.env.set(w,S);return o}let u=-1;for(let w of t.redirections){if((w.operator==="<<"||w.operator==="<<-")&&w.target.type==="HereDoc"){let S=w.target,A=await W(this.ctx,S.content);S.stripTabs&&(A=A.split(`
742
+ `).map(R=>R.replace(/^\t+/,"")).join(`
743
+ `)),A=At(A);let $=w.fd??0;$!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),ve(this.ctx),this.ctx.state.fileDescriptors.set($,A)):s=A;continue}if(w.operator==="<<<"&&w.target.type==="Word"){s=At(`${await W(this.ctx,w.target)}
744
+ `);continue}if(w.operator==="<"&&w.target.type==="Word")try{let S=await W(this.ctx,w.target),A=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);s=await mi(this.ctx.fs,A)}catch{let S=await W(this.ctx,w.target);for(let[A,$]of n)$===void 0?this.ctx.state.env.delete(A):this.ctx.state.env.set(A,$);return _(`bash: ${S}: No such file or directory
745
+ `)}if(w.operator==="<&"&&w.target.type==="Word"){let S=await W(this.ctx,w.target),A=Number.parseInt(S,10);if(!Number.isNaN(A)&&this.ctx.state.fileDescriptors){let $=this.ctx.state.fileDescriptors.get(A);if($!==void 0)if($.startsWith("__rw__:")){let R=Ll($);R&&(s=R.content.slice(R.position),u=A)}else $.startsWith("__file__:")||$.startsWith("__file_append__:")||(s=$)}}}let c=await W(this.ctx,t.name),f=[],d=[];if(ai(t.name,["local","declare","typeset","export","readonly"])&&(c==="local"||c==="declare"||c==="typeset"||c==="export"||c==="readonly"))for(let w of t.args){let S=await Oo(this.ctx,w);if(S)f.push(S),d.push(!0);else{let A=await To(this.ctx,w);if(A!==null)f.push(A),d.push(!0);else{let $=await tt(this.ctx,w);for(let R of $.values)f.push(R),d.push($.quoted)}}}else for(let w of t.args){let S=await tt(this.ctx,w);for(let A of S.values)f.push(A),d.push(S.quoted)}if(!c){if(t.name.parts.every(S=>S.type==="CommandSubstitution"||S.type==="ParameterExpansion"||S.type==="ArithmeticExpansion")){if(f.length>0){let S=f.shift();return d.shift(),await this.runCommand(S,f,d,s,!1,!1,u)}return P("","",this.ctx.state.lastExitCode)}return _(`bash: : command not found
746
+ `,127)}if(c==="exec"&&(f.length===0||f[0]==="--")){for(let w of t.redirections){if(w.target.type==="HereDoc"||w.fdVariable)continue;let S=await W(this.ctx,w.target),A=w.fd??(w.operator==="<"||w.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),w.operator){case">":case">|":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);await this.ctx.fs.writeFile($,"","utf8"),ve(this.ctx),this.ctx.state.fileDescriptors.set(A,`__file__:${$}`);break}case">>":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);ve(this.ctx),this.ctx.state.fileDescriptors.set(A,`__file_append__:${$}`);break}case"<":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);try{let R=await this.ctx.fs.readFile($);ve(this.ctx),this.ctx.state.fileDescriptors.set(A,R)}catch{return _(`bash: ${S}: No such file or directory
747
+ `)}break}case"<>":{let $=this.ctx.fs.resolvePath(this.ctx.state.cwd,S);try{let R=await this.ctx.fs.readFile($);ve(this.ctx),this.ctx.state.fileDescriptors.set(A,`__rw__:${$.length}:${$}:0:${R}`)}catch{await this.ctx.fs.writeFile($,"","utf8"),ve(this.ctx),this.ctx.state.fileDescriptors.set(A,`__rw__:${$.length}:${$}:0:`)}break}case">&":{if(S==="-")this.ctx.state.fileDescriptors.delete(A);else if(S.endsWith("-")){let $=S.slice(0,-1),R=Number.parseInt($,10);if(!Number.isNaN(R)){let I=this.ctx.state.fileDescriptors.get(R);I!==void 0?this.ctx.state.fileDescriptors.set(A,I):this.ctx.state.fileDescriptors.set(A,`__dupout__:${R}`),this.ctx.state.fileDescriptors.delete(R)}}else{let $=Number.parseInt(S,10);Number.isNaN($)||(ve(this.ctx),this.ctx.state.fileDescriptors.set(A,`__dupout__:${$}`))}break}case"<&":{if(S==="-")this.ctx.state.fileDescriptors.delete(A);else if(S.endsWith("-")){let $=S.slice(0,-1),R=Number.parseInt($,10);if(!Number.isNaN(R)){let I=this.ctx.state.fileDescriptors.get(R);I!==void 0?this.ctx.state.fileDescriptors.set(A,I):this.ctx.state.fileDescriptors.set(A,`__dupin__:${R}`),this.ctx.state.fileDescriptors.delete(R)}}else{let $=Number.parseInt(S,10);Number.isNaN($)||(ve(this.ctx),this.ctx.state.fileDescriptors.set(A,`__dupin__:${$}`))}break}}}for(let[w,S]of n)S===void 0?this.ctx.state.env.delete(w):this.ctx.state.env.set(w,S);if(this.ctx.state.tempExportedVars)for(let w of n.keys())this.ctx.state.tempExportedVars.delete(w);return G}if(this.ctx.state.extraArgs){f.push(...this.ctx.state.extraArgs);for(let w=0;w<this.ctx.state.extraArgs.length;w++)d.push(!0);this.ctx.state.extraArgs=void 0}let p=await Fl(this.ctx,c,f);n.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(n)));let m,y=null;try{m=await this.runCommand(c,f,d,s,!1,!1,u)}catch(w){if(w instanceof Ie||w instanceof Ce)y=w,m=G;else throw w}let b=i+p;if(b&&(m={...m,stderr:b+m.stderr}),m=await le(this.ctx,m,t.redirections),y)throw y;if(f.length>0){let w=f[f.length-1];if((c==="declare"||c==="local"||c==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(w)){let S=w.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);S&&(w=S[1])}this.ctx.state.lastArg=w}else this.ctx.state.lastArg=c;let v=Qo(c)&&c!=="unset"&&c!=="eval";if(!this.ctx.state.options.posix||!v)for(let[w,S]of n)this.ctx.state.fullyUnsetLocals?.has(w)||(S===void 0?this.ctx.state.env.delete(w):this.ctx.state.env.set(w,S));if(this.ctx.state.tempExportedVars)for(let w of n.keys())this.ctx.state.tempExportedVars.delete(w);return n.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(m={...m,stderr:this.ctx.state.expansionStderr+m.stderr},this.ctx.state.expansionStderr=""),m}async runCommand(t,s,r,n,i=!1,a=!1,l=-1){let o={ctx:this.ctx,runCommand:(c,f,d,h,p,m,y)=>this.runCommand(c,f,d,h,p,m,y),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(c,f,d)=>this.executeUserScript(c,f,d)},u=await Pl(o,t,s,r,n,i,a,l);return u!==null?u:Dl(o,t,s,n,a)}aliasExpansionStack=new Set;expandAlias(t){return Yn(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return dn(this.ctx,t)}async executeSubshell(t,s=""){return Zl(this.ctx,t,s,r=>this.executeStatement(r))}async executeGroup(t,s=""){return Hl(this.ctx,t,s,r=>this.executeStatement(r))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await rt(this.ctx,t.redirections);if(s)return s;try{let r=await T(this.ctx,t.expression.expression),n=de(r!==0);return this.ctx.state.expansionStderr&&(n={...n,stderr:this.ctx.state.expansionStderr+n.stderr},this.ctx.state.expansionStderr=""),le(this.ctx,n,t.redirections)}catch(r){let n=_(`bash: arithmetic expression: ${r.message}
748
+ `);return le(this.ctx,n,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await rt(this.ctx,t.redirections);if(s)return s;try{let r=await bt(this.ctx,t.expression),n=de(r);return this.ctx.state.expansionStderr&&(n={...n,stderr:this.ctx.state.expansionStderr+n.stderr},this.ctx.state.expansionStderr=""),le(this.ctx,n,t.redirections)}catch(r){let n=r instanceof te?1:2,i=_(`bash: conditional expression: ${r.message}
749
+ `,n);return le(this.ctx,i,t.redirections)}}};var ge={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,maxGlobOperations:1e5,maxStringLength:10485760,maxArrayElements:1e5,maxHeredocSize:10485760,maxSubstitutionDepth:50,maxBraceExpansionResults:1e4,maxOutputSize:10485760,maxFileDescriptors:1024,maxSourceDepth:100};function Gl(e){return e?{maxCallDepth:e.maxCallDepth??ge.maxCallDepth,maxCommandCount:e.maxCommandCount??ge.maxCommandCount,maxLoopIterations:e.maxLoopIterations??ge.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??ge.maxAwkIterations,maxSedIterations:e.maxSedIterations??ge.maxSedIterations,maxJqIterations:e.maxJqIterations??ge.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??ge.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??ge.maxPythonTimeoutMs,maxJsTimeoutMs:e.maxJsTimeoutMs??ge.maxJsTimeoutMs,maxGlobOperations:e.maxGlobOperations??ge.maxGlobOperations,maxStringLength:e.maxStringLength??ge.maxStringLength,maxArrayElements:e.maxArrayElements??ge.maxArrayElements,maxHeredocSize:e.maxHeredocSize??ge.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??ge.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??ge.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??ge.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??ge.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??ge.maxSourceDepth}:{...ge}}import{lookup as yd}from"node:dns";function oi(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function ld(e){let t=oi(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function Ql(e){if(e.includes("\\"))return!0;let t=e.toLowerCase();return t.includes("%2f")||t.includes("%5c")}function cd(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function li(e,t){let s=oi(e);if(!s)return!1;let r=ld(t);return!r||s.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&Ql(s.pathname)?!1:cd(s.pathname,r.pathPrefix)}function Kl(e){return typeof e=="string"?e:e.url}function Xl(e,t){return!t||t.length===0?!1:t.some(s=>li(e,Kl(s)))}function ci(e){let t=ud(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let s=Yl(t);if(s)return pn(s);let r=dd(t);return r?hd(r):!1}function ud(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function fd(e){if(!e)return null;let t=10,s=e;if(s.startsWith("0x")||s.startsWith("0X")?(t=16,s=s.slice(2)):s.length>1&&s.startsWith("0")&&(t=8),!s||t===16&&!/^[0-9a-fA-F]+$/.test(s)||t===10&&!/^\d+$/.test(s)||t===8&&!/^[0-7]+$/.test(s))return null;let r=Number.parseInt(s,t);return!Number.isFinite(r)||r<0?null:r}function Yl(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let s=t.map(o=>fd(o));if(s.some(o=>o===null))return null;let r=s;if(t.length===1){let o=r[0];return o>4294967295?null:[o>>>24&255,o>>>16&255,o>>>8&255,o&255]}if(t.length===2){let[o,u]=r;return o>255||u>16777215?null:[o,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[o,u,c]=r;return o>255||u>255||c>65535?null:[o,u,c>>>8&255,c&255]}let[n,i,a,l]=r;return n>255||i>255||a>255||l>255?null:[n,i,a,l]}function dd(e){let t=e,s=null;if(t.includes(".")){let m=t.lastIndexOf(":");if(m<0)return null;let y=t.slice(m+1),b=Yl(y);if(!b)return null;s=b,t=t.slice(0,m)}let r=t.includes("::")?t.split("::").length-1:0;if(r>1)return null;let[n,i]=t.split("::"),a=n?n.split(":").filter(Boolean):[],l=i?i.split(":").filter(Boolean):[],o=m=>/^[0-9a-f]{1,4}$/i.test(m)?Number.parseInt(m,16):null,u=a.map(o),c=l.map(o);if(u.some(m=>m===null)||c.some(m=>m===null))return null;let f=s?2:0,d=u.length+c.length+f,h=0;if(r===1){if(h=8-d,h<0)return null}else if(d!==8)return null;let p=[...u,...new Array(h).fill(0),...c];return s&&(p.push(s[0]<<8|s[1]),p.push(s[2]<<8|s[3])),p.length===8?p:null}function pn(e){let[t,s]=e;return t===127||t===10||t===172&&s>=16&&s<=31||t===192&&s===168||t===169&&s===254||t===0||t===100&&s>=64&&s<=127||t===198&&(s===18||s===19)||t===192&&s===0&&e[2]===0||t===192&&s===0&&e[2]===2||t===198&&s===51&&e[2]===100||t===203&&s===0&&e[2]===113||t>=240}function hd(e){if(e.every(n=>n===0)||e.slice(0,7).every(n=>n===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let n=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return pn(n)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let n=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return pn(n)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let n=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return pn(n)}return!1}function Jl(e){let t=[];for(let s of e){if(typeof s!="string"&&(s===null||typeof s!="object"||!("url"in s)||typeof s.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let r=Kl(s);if(!oi(r)){t.push(`Invalid URL in allow-list: "${r}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(r);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${r}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${r}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&Ql(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${r}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${r}"`)}return t}var pd=typeof __BROWSER__<"u"&&__BROWSER__,Gt=null,mn=null,ec=!1;function md(){if(Gt===null&&!pd)try{let e=di("node:async_hooks");mn=di("node:dns"),Gt=new e.AsyncLocalStorage}catch{}}function gd(){if(ec||(md(),!Gt||!mn))return;ec=!0;let e=Gt,t=mn.lookup;function s(...r){let n=r[0],i=e.getStore();if(typeof n!="string"||!i||i.hostname.toLowerCase()!==n.toLowerCase())return t.apply(this,r);let a={},l;if(r.length===2)l=r[1];else if(r.length>=3){let u=r[1];typeof u=="number"?a={family:u}:u&&typeof u=="object"&&(a=u),l=r[2]}if(typeof l!="function")return t.apply(this,r);let o=l;if(a.family!==void 0&&a.family!==0&&a.family!==i.family){let u=new Error(`ENOTFOUND ${n}`);u.code="ENOTFOUND",u.errno=-3008,u.syscall="getaddrinfo",u.hostname=n,process.nextTick(()=>o(u));return}process.nextTick(()=>{a.all?o(null,[{address:i.address,family:i.family}]):o(null,i.address,i.family)})}Object.defineProperty(mn,"lookup",{value:s,writable:!0,configurable:!0})}function tc(e,t){return gd(),Gt?Gt.run(e,t):t()}var it=class extends Error{constructor(t,s){let r=s??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},ps=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},ms=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},gn=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}},Qt=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};function wd(e){return new Promise((t,s)=>{yd(e,{all:!0},(r,n)=>{r?s(r):t(n)})})}var Ed=20,bd=3e4,vd=10485760,Sd=["GET","HEAD"],Ad=new Set(["GET","HEAD","OPTIONS"]),$d=new Set([301,302,303,307,308]);function ui(e){let t=e.allowedUrlPrefixes??[];if(!e.dangerouslyAllowFullInternetAccess){let h=Jl(t);if(h.length>0)throw new Error(`Invalid network allow-list:
676
750
  ${h.join(`
677
- `)}`)}let s=[];for(let h of t)typeof h=="object"&&h.transform&&h.transform.length>0&&s.push(h);function n(h){if(s.length===0)return null;let y=null;for(let p of s)if(Nn(h,p.url)&&p.transform){y||(y=new Headers);for(let w of p.transform)for(let[$,g]of Object.entries(w.headers))y.set($,g)}return y}let r=e.maxRedirects??Io,i=e.timeoutMs??xo,a=e.maxResponseSize??Ro,o=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Lo,l=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),c=e._dnsResolve??To;async function u(h){if(!e.dangerouslyAllowFullInternetAccess&&!Oi(h,t))throw new De(h);if(l)try{let y=new URL(h);if(On(y.hostname))throw new De(h,"private/loopback IP address blocked");let p=y.hostname;if(/[a-zA-Z]/.test(p))try{let $=await c(p);for(let{address:b}of $)if(On(b))throw new De(h,"hostname resolves to private/loopback IP address");let g=$[0];if(g)return{hostname:p,address:g.address,family:g.family===6?6:4}}catch($){if($ instanceof De)throw $;let g=$?.code;if(!(g==="ENOTFOUND"||g==="ENODATA"))throw new De(h,"DNS resolution failed for private IP check")}}catch(y){if(y instanceof De)throw y}return null}function f(h){if(e.dangerouslyAllowFullInternetAccess)return;let y=h.toUpperCase();if(!o.includes(y))throw new hs(y,o)}async function d(h,y={}){let p=y.method?.toUpperCase()??"GET",w=await u(h);f(p);let $=h,g=0,b=y.followRedirects??!0,m=y.timeoutMs!==void 0?Math.min(y.timeoutMs,i):i;for(;;){let v=new AbortController,E=xn(()=>v.abort(),m);try{let S=await be.runTrustedAsync(()=>{let O=n($),N=Wo(y.headers,O),x={method:p,headers:N,signal:v.signal,redirect:"manual"};return y.body&&!Fo.has(p)&&(x.body=y.body),w?xi(w,()=>fetch($,x)):fetch($,x)});if(Mo.has(S.status)&&b){let O=S.headers.get("location");if(!O)return await Ri(S,$,a);let N=new URL(O,$).href;try{w=await u(N)}catch{throw new Pt(N)}if(g++,g>r)throw new kt(r);$=N;continue}return await Ri(S,$,a)}finally{Rn(E)}}}return d}function Wo(e,t){if(!e&&!t)return;if(!t)return e;let s=e instanceof Headers?new Headers(e):new Headers(e);for(let[n,r]of t)s.set(n,r);return s}async function Ri(e,t,s){let n=Object.create(null);if(e.headers.forEach((i,a)=>{n[a.toLowerCase()]=i}),s>0){let i=e.headers.get("content-length");if(i){let a=parseInt(i,10);if(!Number.isNaN(a)&&a>s)throw new ht(s)}}let r;if(s>0&&e.body){let i=e.body.getReader(),a=[],o=0;for(;;){let{done:c,value:u}=await i.read();if(c)break;if(u){if(o+=u.byteLength,o>s)throw i.cancel(),new ht(s);a.push(u)}}r=new Uint8Array(o);let l=0;for(let c of a)r.set(c,l),l+=c.byteLength}else{let i=await e.arrayBuffer();if(s>0&&i.byteLength>s)throw new ht(s);r=new Uint8Array(i)}return{status:e.status,statusText:e.statusText,headers:n,body:r,url:t}}function Li(e){return Ye(e)}function Ye(e){return e.statements.map(Fi).join(`
678
- `)}function Fi(e){let t=[];for(let n=0;n<e.pipelines.length;n++)t.push(zo(e.pipelines[n])),n<e.operators.length&&t.push(e.operators[n]);let s=t.join(" ");return e.background&&(s+=" &"),s}function zo(e){let t=[];e.timed&&t.push(e.timePosix?"time -p":"time"),e.negated&&t.push("!");let s=[];for(let r=0;r<e.commands.length;r++)if(s.push(Mi(e.commands[r])),r<e.commands.length-1){let i=e.pipeStderr?.[r];s.push(i?"|&":"|")}return(t.length>0?`${t.join(" ")} `:"")+s.join(" ")}function Mi(e){switch(e.type){case"SimpleCommand":return Vo(e);case"If":return Xo(e);case"For":return Yo(e);case"CStyleFor":return Qo(e);case"While":return Jo(e);case"Until":return el(e);case"Case":return tl(e);case"Subshell":return nl(e);case"Group":return rl(e);case"ArithmeticCommand":return il(e);case"ConditionalCommand":return al(e);case"FunctionDef":return ol(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function Vo(e){let t=[];for(let s of e.assignments)t.push(Bo(s));e.name&&t.push(oe(e.name));for(let s of e.args)t.push(oe(s));for(let s of e.redirections)t.push(Vi(s));return t.join(" ")}function Bo(e){let t=e.append?"+=":"=";if(e.array){let s=e.array.map(oe).join(" ");return`${e.name}${t}(${s})`}return e.value?`${e.name}${t}${oe(e.value)}`:`${e.name}${t}`}function oe(e){return e.parts.map(t=>ps(t,!1)).join("")}function je(e){return e.parts.map(t=>ps(t,!0)).join("")}function ps(e,t){switch(e.type){case"Literal":return t?Ho(e.value):jo(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(s=>ps(s,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Wi(e);case"CommandSubstitution":return e.legacy?`\`${Ye(e.body)}\``:`$(${Ye(e.body)})`;case"ArithmeticExpansion":return`$((${H(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${Ye(e.body)})`:`>(${Ye(e.body)})`;case"BraceExpansion":return Go(e);case"TildeExpansion":return e.user!==null?`~${e.user}`:"~";case"Glob":return e.pattern;default:{let s=e;throw new Error(`Unsupported word part type: ${s.type}`)}}}function jo(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function Ho(e){return e.replace(/[$`"\\]/g,"\\$&")}function Uo(e,t){return e.parts.map(s=>Zo(s,t)).join("")}function Zo(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return Wi(e);case"CommandSubstitution":return e.legacy?`\`${Ye(e.body)}\``:`$(${Ye(e.body)})`;case"ArithmeticExpansion":return`$((${H(e.expression.expression)}))`;default:return ps(e,!1)}}function Wi(e){return e.operation?`\${${zi(e.parameter,e.operation)}}`:qo(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function qo(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function zi(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${je(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${je(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?je(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${je(t.word)}`;case"Substring":{let s=H(t.offset.expression);return t.length?`${e}:${s}:${H(t.length.expression)}`:`${e}:${s}`}case"PatternRemoval":{let s=t.side==="prefix"?"#":"%",n=t.greedy?`${s}${s}`:s;return`${e}${n}${je(t.pattern)}`}case"PatternReplacement":{let s="/";t.all?s="//":t.anchor==="start"?s="/#":t.anchor==="end"&&(s="/%");let n=t.replacement?`/${je(t.replacement)}`:"";return`${e}${s}${je(t.pattern)}${n}`}case"CaseModification":{let s=t.direction==="upper"?"^":",",n=t.all?`${s}${s}`:s,r=t.pattern?je(t.pattern):"";return`${e}${n}${r}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${zi(e,t.innerOp)}`:`!${e}`;case"ArrayKeys":return`!${t.array}[${t.star?"*":"@"}]`;case"VarNamePrefix":return`!${t.prefix}${t.star?"*":"@"}`;default:{let s=t;throw new Error(`Unsupported parameter operation type: ${s.type}`)}}}function Go(e){return`{${e.items.map(Ko).join(",")}}`}function Ko(e){if(e.type==="Word")return oe(e.word);let t=e.startStr??String(e.start),s=e.endStr??String(e.end);return e.step!==void 0?`${t}..${s}..${e.step}`:`${t}..${s}`}function Vi(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let s=e.target,n=s.quoted?`'${s.delimiter}'`:s.delimiter,r=Uo(s.content,s.quoted);return`${t}${e.operator}${n}
679
- ${r}${s.delimiter}`}return e.operator==="<<<"?`${t}<<< ${oe(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${oe(e.target)}`:`${t}${e.operator} ${oe(e.target)}`}function _e(e){return e.length===0?"":` ${e.map(Vi).join(" ")}`}function we(e){return e.map(Fi).join(`
680
- `)}function Xo(e){let t=[];for(let s=0;s<e.clauses.length;s++){let n=e.clauses[s],r=s===0?"if":"elif";t.push(`${r} ${we(n.condition)}; then
681
- ${we(n.body)}`)}return e.elseBody&&t.push(`else
682
- ${we(e.elseBody)}`),`${t.join(`
751
+ `)}`)}let s=[];for(let h of t)typeof h=="object"&&h.transform&&h.transform.length>0&&s.push(h);function r(h){if(s.length===0)return null;let p=null;for(let m of s)if(li(h,m.url)&&m.transform){p||(p=new Headers);for(let y of m.transform)for(let[b,v]of Object.entries(y.headers))p.set(b,v)}return p}let n=e.maxRedirects??Ed,i=e.timeoutMs??bd,a=e.maxResponseSize??vd,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Sd,o=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),u=e._dnsResolve??wd;async function c(h){if(!e.dangerouslyAllowFullInternetAccess&&!Xl(h,t))throw new it(h);if(o)try{let p=new URL(h);if(ci(p.hostname))throw new it(h,"private/loopback IP address blocked");let m=p.hostname;if(/[a-zA-Z]/.test(m))try{let b=await u(m);for(let{address:E}of b)if(ci(E))throw new it(h,"hostname resolves to private/loopback IP address");let v=b[0];if(v)return{hostname:m,address:v.address,family:v.family===6?6:4}}catch(b){if(b instanceof it)throw b;let v=b?.code;if(!(v==="ENOTFOUND"||v==="ENODATA"))throw new it(h,"DNS resolution failed for private IP check")}}catch(p){if(p instanceof it)throw p}return null}function f(h){if(e.dangerouslyAllowFullInternetAccess)return;let p=h.toUpperCase();if(!l.includes(p))throw new gn(p,l)}async function d(h,p={}){let m=p.method?.toUpperCase()??"GET",y=await c(h);f(m);let b=h,v=0,E=p.followRedirects??!0,w=p.timeoutMs!==void 0?Math.min(p.timeoutMs,i):i;for(;;){let S=new AbortController,A=hi(()=>S.abort(),w);try{let $=await Be.runTrustedAsync(()=>{let R=r(b),I=Nd(p.headers,R),L={method:m,headers:I,signal:S.signal,redirect:"manual"};return p.body&&!Ad.has(m)&&(L.body=p.body),y?tc(y,()=>fetch(b,L)):fetch(b,L)});if($d.has($.status)&&E){let R=$.headers.get("location");if(!R)return await sc($,b,a);let I=new URL(R,b).href;try{y=await c(I)}catch{throw new ms(I)}if(v++,v>n)throw new ps(n);b=I;continue}return await sc($,b,a)}finally{pi(A)}}}return d}function Nd(e,t){if(!e&&!t)return;if(!t)return e;let s=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,n]of t)s.set(r,n);return s}async function sc(e,t,s){let r=Object.create(null);if(e.headers.forEach((i,a)=>{r[a.toLowerCase()]=i}),s>0){let i=e.headers.get("content-length");if(i){let a=parseInt(i,10);if(!Number.isNaN(a)&&a>s)throw new Qt(s)}}let n;if(s>0&&e.body){let i=e.body.getReader(),a=[],l=0;for(;;){let{done:u,value:c}=await i.read();if(u)break;if(c){if(l+=c.byteLength,l>s)throw i.cancel(),new Qt(s);a.push(c)}}n=new Uint8Array(l);let o=0;for(let u of a)n.set(u,o),o+=u.byteLength}else{let i=await e.arrayBuffer();if(s>0&&i.byteLength>s)throw new Qt(s);n=new Uint8Array(i)}return{status:e.status,statusText:e.statusText,headers:r,body:n,url:t}}function nc(e){return Dt(e)}function Dt(e){return e.statements.map(rc).join(`
752
+ `)}function rc(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(kd(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let s=t.join(" ");return e.background&&(s+=" &"),s}function kd(e){let t=[];e.timed&&t.push(e.timePosix?"time -p":"time"),e.negated&&t.push("!");let s=[];for(let n=0;n<e.commands.length;n++)if(s.push(ic(e.commands[n])),n<e.commands.length-1){let i=e.pipeStderr?.[n];s.push(i?"|&":"|")}return(t.length>0?`${t.join(" ")} `:"")+s.join(" ")}function ic(e){switch(e.type){case"SimpleCommand":return _d(e);case"If":return Ld(e);case"For":return Wd(e);case"CStyleFor":return Md(e);case"While":return Fd(e);case"Until":return Vd(e);case"Case":return zd(e);case"Subshell":return qd(e);case"Group":return Ud(e);case"ArithmeticCommand":return Zd(e);case"ConditionalCommand":return Hd(e);case"FunctionDef":return jd(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function _d(e){let t=[];for(let s of e.assignments)t.push(Pd(s));e.name&&t.push(Ae(e.name));for(let s of e.args)t.push(Ae(s));for(let s of e.redirections)t.push(lc(s));return t.join(" ")}function Pd(e){let t=e.append?"+=":"=";if(e.array){let s=e.array.map(Ae).join(" ");return`${e.name}${t}(${s})`}return e.value?`${e.name}${t}${Ae(e.value)}`:`${e.name}${t}`}function Ae(e){return e.parts.map(t=>yn(t,!1)).join("")}function St(e){return e.parts.map(t=>yn(t,!0)).join("")}function yn(e,t){switch(e.type){case"Literal":return t?Id(e.value):Dd(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(s=>yn(s,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return ac(e);case"CommandSubstitution":return e.legacy?`\`${Dt(e.body)}\``:`$(${Dt(e.body)})`;case"ArithmeticExpansion":return`$((${ne(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${Dt(e.body)})`:`>(${Dt(e.body)})`;case"BraceExpansion":return Od(e);case"TildeExpansion":return e.user!==null?`~${e.user}`:"~";case"Glob":return e.pattern;default:{let s=e;throw new Error(`Unsupported word part type: ${s.type}`)}}}function Dd(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function Id(e){return e.replace(/[$`"\\]/g,"\\$&")}function Cd(e,t){return e.parts.map(s=>Rd(s,t)).join("")}function Rd(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return ac(e);case"CommandSubstitution":return e.legacy?`\`${Dt(e.body)}\``:`$(${Dt(e.body)})`;case"ArithmeticExpansion":return`$((${ne(e.expression.expression)}))`;default:return yn(e,!1)}}function ac(e){return e.operation?`\${${oc(e.parameter,e.operation)}}`:xd(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function xd(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function oc(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${St(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${St(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?St(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${St(t.word)}`;case"Substring":{let s=ne(t.offset.expression);return t.length?`${e}:${s}:${ne(t.length.expression)}`:`${e}:${s}`}case"PatternRemoval":{let s=t.side==="prefix"?"#":"%",r=t.greedy?`${s}${s}`:s;return`${e}${r}${St(t.pattern)}`}case"PatternReplacement":{let s="/";t.all?s="//":t.anchor==="start"?s="/#":t.anchor==="end"&&(s="/%");let r=t.replacement?`/${St(t.replacement)}`:"";return`${e}${s}${St(t.pattern)}${r}`}case"CaseModification":{let s=t.direction==="upper"?"^":",",r=t.all?`${s}${s}`:s,n=t.pattern?St(t.pattern):"";return`${e}${r}${n}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${oc(e,t.innerOp)}`:`!${e}`;case"ArrayKeys":return`!${t.array}[${t.star?"*":"@"}]`;case"VarNamePrefix":return`!${t.prefix}${t.star?"*":"@"}`;default:{let s=t;throw new Error(`Unsupported parameter operation type: ${s.type}`)}}}function Od(e){return`{${e.items.map(Td).join(",")}}`}function Td(e){if(e.type==="Word")return Ae(e.word);let t=e.startStr??String(e.start),s=e.endStr??String(e.end);return e.step!==void 0?`${t}..${s}..${e.step}`:`${t}..${s}`}function lc(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let s=e.target,r=s.quoted?`'${s.delimiter}'`:s.delimiter,n=Cd(s.content,s.quoted);return`${t}${e.operator}${r}
753
+ ${n}${s.delimiter}`}return e.operator==="<<<"?`${t}<<< ${Ae(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${Ae(e.target)}`:`${t}${e.operator} ${Ae(e.target)}`}function Qe(e){return e.length===0?"":` ${e.map(lc).join(" ")}`}function Ve(e){return e.map(rc).join(`
754
+ `)}function Ld(e){let t=[];for(let s=0;s<e.clauses.length;s++){let r=e.clauses[s],n=s===0?"if":"elif";t.push(`${n} ${Ve(r.condition)}; then
755
+ ${Ve(r.body)}`)}return e.elseBody&&t.push(`else
756
+ ${Ve(e.elseBody)}`),`${t.join(`
683
757
  `)}
684
- fi${_e(e.redirections)}`}function Yo(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let s=e.words.map(oe).join(" ");t=`for ${e.variable} in ${s}`}return`${t}; do
685
- ${we(e.body)}
686
- done${_e(e.redirections)}`}function Qo(e){let t=e.init?H(e.init.expression):"",s=e.condition?H(e.condition.expression):"",n=e.update?H(e.update.expression):"";return`for ((${t}; ${s}; ${n})); do
687
- ${we(e.body)}
688
- done${_e(e.redirections)}`}function Jo(e){return`while ${we(e.condition)}; do
689
- ${we(e.body)}
690
- done${_e(e.redirections)}`}function el(e){return`until ${we(e.condition)}; do
691
- ${we(e.body)}
692
- done${_e(e.redirections)}`}function tl(e){let t=e.items.map(sl).join(`
693
- `);return`case ${oe(e.word)} in
758
+ fi${Qe(e.redirections)}`}function Wd(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let s=e.words.map(Ae).join(" ");t=`for ${e.variable} in ${s}`}return`${t}; do
759
+ ${Ve(e.body)}
760
+ done${Qe(e.redirections)}`}function Md(e){let t=e.init?ne(e.init.expression):"",s=e.condition?ne(e.condition.expression):"",r=e.update?ne(e.update.expression):"";return`for ((${t}; ${s}; ${r})); do
761
+ ${Ve(e.body)}
762
+ done${Qe(e.redirections)}`}function Fd(e){return`while ${Ve(e.condition)}; do
763
+ ${Ve(e.body)}
764
+ done${Qe(e.redirections)}`}function Vd(e){return`until ${Ve(e.condition)}; do
765
+ ${Ve(e.body)}
766
+ done${Qe(e.redirections)}`}function zd(e){let t=e.items.map(Bd).join(`
767
+ `);return`case ${Ae(e.word)} in
694
768
  ${t}
695
- esac${_e(e.redirections)}`}function sl(e){let t=e.patterns.map(oe).join(" | "),s=we(e.body);return s?`${t})
769
+ esac${Qe(e.redirections)}`}function Bd(e){let t=e.patterns.map(Ae).join(" | "),s=Ve(e.body);return s?`${t})
696
770
  ${s}
697
771
  ${e.terminator}`:`${t})
698
- ${e.terminator}`}function nl(e){return`(${we(e.body)})${_e(e.redirections)}`}function rl(e){return`{ ${we(e.body)}; }${_e(e.redirections)}`}function il(e){return`((${H(e.expression.expression)}))${_e(e.redirections)}`}function al(e){return`[[ ${Xe(e.expression)} ]]${_e(e.redirections)}`}function ol(e){let t=Mi(e.body);return`${e.name}() ${t}${_e(e.redirections)}`}function H(e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return e.hasDollarPrefix?`$${e.name}`:e.name;case"ArithSpecialVar":return`$${e.name}`;case"ArithBinary":return`${H(e.left)} ${e.operator} ${H(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${H(e.operand)}`:`${H(e.operand)}${e.operator}`;case"ArithTernary":return`${H(e.condition)} ? ${H(e.consequent)} : ${H(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${H(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${H(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${H(e.target)}[${H(e.subscript)}]`:H(e.target)} ${e.operator} ${H(e.value)}`;case"ArithDynamicElement":return`${H(e.nameExpr)}[${H(e.subscript)}]`;case"ArithGroup":return`(${H(e.expression)})`;case"ArithNested":return`$((${H(e.expression)}))`;case"ArithCommandSubst":return`$(${e.command})`;case"ArithBracedExpansion":return`\${${e.content}}`;case"ArithArrayElement":return e.stringKey!==void 0?`${e.array}[${e.stringKey}]`:e.index?`${e.array}[${H(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(H).join("");case"ArithDoubleSubscript":return`${e.array}[${H(e.index)}]`;case"ArithNumberSubscript":return`${e.number}[${e.errorToken}]`;case"ArithSyntaxError":return e.errorToken;case"ArithSingleQuote":return`'${e.content}'`;default:{let t=e;throw new Error(`Unsupported arithmetic expression type: ${t.type}`)}}}function Xe(e){switch(e.type){case"CondBinary":return`${oe(e.left)} ${e.operator} ${oe(e.right)}`;case"CondUnary":return`${e.operator} ${oe(e.operand)}`;case"CondNot":return`! ${Xe(e.operand)}`;case"CondAnd":return`${Xe(e.left)} && ${Xe(e.right)}`;case"CondOr":return`${Xe(e.left)} || ${Xe(e.right)}`;case"CondGroup":return`( ${Xe(e.expression)} )`;case"CondWord":return oe(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var ms=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;invokeToolFn;transformPlugins=[];state;constructor(t={}){let s=t.fs??new wt(t.files);this.fs=s,this.useDefaultLayout=!t.cwd&&!t.files;let n=t.cwd||(this.useDefaultLayout?"/home/user":"/"),r=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
699
- `],["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"],["PWD",n],["OLDPWD",n],["OPTIND","1"],...Object.entries(t.env??{})]);if(this.limits=ki({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}}),t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=Dn(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.coverageWriter=t.coverage,this.state={env:r,cwd:n,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,virtualPid:t.processInfo?.pid??1,virtualPpid:t.processInfo?.ppid??0,virtualUid:t.processInfo?.uid??1e3,virtualGid:t.processInfo?.gid??1e3,bashPid:t.processInfo?.pid??1,nextVirtualPid:(t.processInfo?.pid??1)+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",Ds(this.state.options)),this.state.env.set("BASHOPTS",Ts(this.state.shoptOptions)),or(s,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),n!=="/"&&s instanceof wt)try{s.mkdirSync(n,{recursive:!0})}catch{}for(let a of er(t.commands))this.registerCommand(a);if(t.fetch||t.network)for(let a of tr())this.registerCommand(a);if(t.python)for(let a of sr())this.registerCommand(a);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let a of nr())this.registerCommand(a);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap),i.invokeTool&&(this.invokeToolFn=i.invokeTool)}if(t.customCommands)for(let a of t.customCommands)rr(a)?this.registerCommand(ir(a)):this.registerCommand({...a,trusted:a.trusted??!0})}registerCommand(t){this.commands.set(t.name,t);let s=this.fs;if(typeof s.writeFileSync=="function"){let n=`#!/bin/bash
772
+ ${e.terminator}`}function qd(e){return`(${Ve(e.body)})${Qe(e.redirections)}`}function Ud(e){return`{ ${Ve(e.body)}; }${Qe(e.redirections)}`}function Zd(e){return`((${ne(e.expression.expression)}))${Qe(e.redirections)}`}function Hd(e){return`[[ ${Pt(e.expression)} ]]${Qe(e.redirections)}`}function jd(e){let t=ic(e.body);return`${e.name}() ${t}${Qe(e.redirections)}`}function ne(e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return e.hasDollarPrefix?`$${e.name}`:e.name;case"ArithSpecialVar":return`$${e.name}`;case"ArithBinary":return`${ne(e.left)} ${e.operator} ${ne(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${ne(e.operand)}`:`${ne(e.operand)}${e.operator}`;case"ArithTernary":return`${ne(e.condition)} ? ${ne(e.consequent)} : ${ne(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${ne(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${ne(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${ne(e.target)}[${ne(e.subscript)}]`:ne(e.target)} ${e.operator} ${ne(e.value)}`;case"ArithDynamicElement":return`${ne(e.nameExpr)}[${ne(e.subscript)}]`;case"ArithGroup":return`(${ne(e.expression)})`;case"ArithNested":return`$((${ne(e.expression)}))`;case"ArithCommandSubst":return`$(${e.command})`;case"ArithBracedExpansion":return`\${${e.content}}`;case"ArithArrayElement":return e.stringKey!==void 0?`${e.array}[${e.stringKey}]`:e.index?`${e.array}[${ne(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(ne).join("");case"ArithDoubleSubscript":return`${e.array}[${ne(e.index)}]`;case"ArithNumberSubscript":return`${e.number}[${e.errorToken}]`;case"ArithSyntaxError":return e.errorToken;case"ArithSingleQuote":return`'${e.content}'`;default:{let t=e;throw new Error(`Unsupported arithmetic expression type: ${t.type}`)}}}function Pt(e){switch(e.type){case"CondBinary":return`${Ae(e.left)} ${e.operator} ${Ae(e.right)}`;case"CondUnary":return`${e.operator} ${Ae(e.operand)}`;case"CondNot":return`! ${Pt(e.operand)}`;case"CondAnd":return`${Pt(e.left)} && ${Pt(e.right)}`;case"CondOr":return`${Pt(e.left)} || ${Pt(e.right)}`;case"CondGroup":return`( ${Pt(e.expression)} )`;case"CondWord":return Ae(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var wn=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;invokeToolFn;transformPlugins=[];state;constructor(t={}){let s=t.fs??new Jt(t.files);this.fs=s,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),n=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
773
+ `],["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"],["PWD",r],["OLDPWD",r],["OPTIND","1"],...Object.entries(t.env??{})]);if(this.limits=Gl({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}}),t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=ui(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.coverageWriter=t.coverage,this.state={env:n,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,virtualPid:t.processInfo?.pid??1,virtualPpid:t.processInfo?.ppid??0,virtualUid:t.processInfo?.uid??1e3,virtualGid:t.processInfo?.gid??1e3,bashPid:t.processInfo?.pid??1,nextVirtualPid:(t.processInfo?.pid??1)+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",Pn(this.state.options)),this.state.env.set("BASHOPTS",Dn(this.state.shoptOptions)),_i(s,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&s instanceof Jt)try{s.mkdirSync(r,{recursive:!0})}catch{}for(let a of wi(t.commands))this.registerCommand(a);if(t.fetch||t.network)for(let a of Ei())this.registerCommand(a);if(t.python)for(let a of bi())this.registerCommand(a);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let a of vi())this.registerCommand(a);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap),i.invokeTool&&(this.invokeToolFn=i.invokeTool)}if(t.customCommands)for(let a of t.customCommands)Si(a)?this.registerCommand(Ai(a)):this.registerCommand({...a,trusted:a.trusted??!0})}registerCommand(t){this.commands.set(t.name,t);let s=this.fs;if(typeof s.writeFileSync=="function"){let r=`#!/bin/bash
700
774
  # Built-in command: ${t.name}
701
- `;try{s.writeFileSync(`/bin/${t.name}`,n)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,n)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=ji(t.stdout),t.stderr=ji(t.stderr),t}async exec(t,s){if(this.state.callDepth===0&&(this.state.commandCount=0),this.state.commandCount++,this.state.commandCount>this.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option.
702
- `,exitCode:1,env:ye(this.state.env,s?.env)};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:ye(this.state.env,s?.env)};this.logger?.info("exec",{command:t});let n=s?.cwd??this.state.cwd,r,i=n;if(s?.cwd)if(s.env&&"PWD"in s.env)r=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{r=await this.fs.realpath(n),i=r}catch{r=n}else r=n;let a=s?.replaceEnv?new Map:new Map(this.state.env);if(s?.env)for(let[f,d]of Object.entries(s.env))a.set(f,d);r!==void 0&&a.set("PWD",r);let o={...this.state,env:a,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:cl(s?.stdin,s?.stdinKind),signal:s?.signal,extraArgs:s?.args},l=t;s?.rawScript||(l=Bi(t));let c=this.defenseInDepthConfig?be.getInstance(this.defenseInDepthConfig):null,u=c?.activate();try{let f=async()=>{let d=Ee(l,{maxHeredocSize:this.limits.maxHeredocSize}),h;if(this.transformPlugins.length>0){let g=Object.create(null);for(let b of this.transformPlugins){let m=b.transform({ast:d,metadata:g});d=m.ast,m.metadata&&(g=vs(g,m.metadata))}h=g}let y={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,requireDefenseContext:c?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},$=await new Ct(y,o).executeScript(d);return h&&($.metadata=h),this.logResult($)};return u?await u.run(f):await f()}catch(f){if(f instanceof B)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:ye(this.state.env,s?.env)});if(f instanceof me)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:ye(this.state.env,s?.env)});if(f instanceof Ue)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:1,env:ye(this.state.env,s?.env)});if(f instanceof It)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:ye(this.state.env,s?.env)});if(f instanceof Y)return this.logResult({stdout:f.stdout,stderr:Te(f.stderr),exitCode:Y.EXIT_CODE,env:ye(this.state.env,s?.env)});if(f instanceof Je)return this.logResult({stdout:"",stderr:`bash: security violation: ${Te(f.message)}
703
- `,exitCode:1,env:ye(this.state.env,s?.env)});if(f.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${Te(f.message)}
704
- `,exitCode:2,env:ye(this.state.env,s?.env)});if(f instanceof Vn)return this.logResult({stdout:"",stderr:`bash: ${Te(f.message)}
705
- `,exitCode:2,env:ye(this.state.env,s?.env)});if(f instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${Te(f.message)}
706
- `,exitCode:1,env:ye(this.state.env,s?.env)});throw f}finally{u?.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 Le(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){let s=Bi(t),n=Ee(s,{maxHeredocSize:this.limits.maxHeredocSize}),r=Object.create(null);for(let i of this.transformPlugins){let a=i.transform({ast:n,metadata:r});n=a.ast,a.metadata&&(r=vs(r,a.metadata))}return{script:Li(n),ast:n,metadata:r}}};function Bi(e){let t=e.split(`
707
- `),s=[],n=[];for(let r=0;r<t.length;r++){let i=t[r];if(n.length>0){let l=n[n.length-1];if((l.stripTabs?i.replace(/^\t+/,""):i)===l.delimiter){s.push(i.trimStart()),n.pop();continue}s.push(i);continue}let a=i.trimStart();s.push(a);let o=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let l of a.matchAll(o)){let c=l[1]==="-",u=l[3];n.push({delimiter:u,stripTabs:c})}}return s.join(`
708
- `)}var ll=new TextDecoder("utf-8",{fatal:!0});function ji(e){if(!e)return e;let t=!1;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r>255)return e;r>127&&(t=!0)}if(!t)return e;let s=new Uint8Array(e.length);for(let n=0;n<e.length;n++)s[n]=e.charCodeAt(n);try{return ll.decode(s)}catch{return e}}function cl(e,t){if(e!==void 0)return t==="bytes"?e:He(e)}import*as U from"node:fs";import*as ie from"node:path";import*as ve from"node:fs";import*as le from"node:path";function Ot(e,t){if(e===t)return!0;let s=e[t.length];return(s==="/"||s==="\\")&&e.startsWith(t)}function Nt(e,t){try{let s=ve.realpathSync(e);return Ot(s,t)?s:null}catch(s){if(s.code==="ENOENT"){let n=le.dirname(e);if(n===e)return null;let r=Nt(n,t);if(r===null)return null;try{if(ve.lstatSync(e).isSymbolicLink()){let a=ve.readlinkSync(e),o=le.isAbsolute(a)?a:le.resolve(le.dirname(e),a);if(Nt(o,t)===null)return null}}catch{}return le.join(r,le.basename(e))}return null}}function Hi(e,t,s){let n=Nt(e,s);if(n===null)return null;let r=le.resolve(e),i=r.slice(t.length),a=n.slice(s.length);if(i!==a)return null;try{if(ve.lstatSync(r).isSymbolicLink())return null}catch{}return n}function Ui(e,t){if(!ve.existsSync(e))throw new Error(`${t} root does not exist`);if(!ve.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function Zi(e,t){if(!le.isAbsolute(e))return{withinRoot:!0,relativePath:e};let s;try{s=ve.realpathSync(e)}catch{s=le.resolve(e)}return Ot(s,t)?{withinRoot:!0,relativePath:s.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:le.basename(e)}}function qi(e,t,s,n){let r=e;if(r.path===void 0){for(let a of n)if(r.message?.includes(a))throw e}let i=r.code||"EIO";throw new Error(`${i}: ${s} '${t}'`)}var ul=["ELOOP","EFBIG","EPERM"],fl="/home/user/project",ys=class{root;canonicalRoot;mountPoint;readOnly;maxFileReadSize;allowSymlinks;memory=new Map;deleted=new Set;constructor(t){this.root=ie.resolve(t.root);let s=t.mountPoint??fl;if(this.mountPoint=s==="/"?"/":s.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${s}`);this.readOnly=t.readOnly??!1,this.maxFileReadSize=t.maxFileReadSize??10485760,this.allowSymlinks=t.allowSymlinks??!1,Ui(this.root,"OverlayFs"),this.canonicalRoot=U.realpathSync(this.root),this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){let t=this.mountPoint.split("/").filter(Boolean),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=L(t).split("/").filter(Boolean),i="";for(let a of r)i+=`/${a}`,this.memory.has(i)||this.memory.set(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,s){let n=L(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)}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let s=L(t),n=this.getRelativeToMount(s);if(n===null)return null;let r=ie.join(this.root,n),i=ie.resolve(r);return Ot(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?Nt(t,this.canonicalRoot):Hi(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let s=ie.dirname(t),n=this.resolveRealPath_(s);return n===null?null:ie.join(n,ie.basename(t))}sanitizeError(t,s,n){qi(t,s,n,ul)}ensureParentDirs(t){let s=qe(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=L(t);if(this.deleted.has(s))return!1;if(this.memory.has(s))return!0;let n=this.resolveRealPathParent_(this.toRealPath(s));if(!n)return!1;try{return await U.promises.lstat(n),!0}catch{return!1}}async readFile(t,s){let n=await this.readFileBuffer(t),r=Fe(s);return tt(n,r)}async readFileBytes(t){let s=await this.readFileBuffer(t);return tt(s,"binary")}async readFileBuffer(t,s=new Set){W(t,"open");let n=L(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let a=this.resolveSymlink(n,r.target);return this.readFileBuffer(a,s)}if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return r.content}let i=this.resolveRealPath_(this.toRealPath(n));if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let a=await U.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${t}'`);let c=await U.promises.readlink(i),u=this.realTargetToVirtual(n,c),f=this.resolveSymlink(n,u);return this.readFileBuffer(f,s)}if(a.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(this.maxFileReadSize>0&&a.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${a.size} bytes, max ${this.maxFileReadSize})`);let o=this.allowSymlinks?U.constants.O_RDONLY:U.constants.O_RDONLY|U.constants.O_NOFOLLOW,l=await U.promises.open(i,o);try{let c=await l.readFile();return new Uint8Array(c)}finally{await l.close()}}catch(a){let o=a.code;if(o==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(o==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(a,t,"open")}}async writeFile(t,s,n){W(t,"write"),this.assertWritable(`write '${t}'`);let r=L(t);this.ensureParentDirs(r);let i=Fe(n),a=et(s,i);this.memory.set(r,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(r)}async appendFile(t,s,n){W(t,"append"),this.assertWritable(`append '${t}'`);let r=L(t),i=Fe(n),a=et(s,i),o;try{o=await this.readFileBuffer(r)}catch{o=new Uint8Array(0)}let l=new Uint8Array(o.length+a.length);l.set(o),l.set(a,o.length),this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:420,mtime:new Date}),this.deleted.delete(r)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,s=new Set){W(t,"stat");let n=L(t);if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(s.add(n),this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink"){let o=this.resolveSymlink(n,r.target);return this.stat(o,s)}let a=0;return r.type==="file"&&(a=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:a,mtime:r.mtime}}let i=this.resolveRealPath_(this.toRealPath(n));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let a=await U.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let o=await U.promises.readlink(i),l=this.realTargetToVirtual(n,o),c=this.resolveSymlink(n,l);return this.stat(c,s)}return{isFile:a.isFile(),isDirectory:a.isDirectory(),isSymbolicLink:!1,mode:a.mode,size:a.size,mtime:a.mtime}}catch(a){if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(a,t,"stat")}}async lstat(t){W(t,"lstat");let s=L(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.resolveRealPathParent_(this.toRealPath(s));if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await U.promises.lstat(r);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}resolveSymlink(t,s){return nt(t,s)}realTargetToVirtual(t,s){let n=Zi(s,this.canonicalRoot);if(n.withinRoot){if(!ie.isAbsolute(s))return s;let r=n.relativePath;return this.mountPoint==="/"?r:`${this.mountPoint}${r}`}return n.safeName}async mkdir(t,s){W(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let n=L(t);if(await this.existsInOverlay(n)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=qe(n);if(i!=="/"&&!await this.existsInOverlay(i))if(s?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.memory.set(n,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(n)}async readdirCore(t,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Map,r=new Set,i=s==="/"?"/":`${s}/`;for(let o of this.deleted)if(o.startsWith(i)){let l=o.slice(i.length),c=l.split("/")[0];c&&!l.includes("/",c.length)&&r.add(c)}for(let[o,l]of this.memory)if(o!==s&&o.startsWith(i)){let c=o.slice(i.length),u=c.split("/")[0];u&&!r.has(u)&&!c.includes("/",1)&&n.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let a=this.resolveRealPath_(this.toRealPath(s));if(a)try{if(!this.allowSymlinks&&(await U.promises.lstat(a)).isSymbolicLink()){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);return n}let o=await U.promises.readdir(a,{withFileTypes:!0});for(let l of o)!r.has(l.name)&&!n.has(l.name)&&n.set(l.name,{name:l.name,isFile:l.isFile(),isDirectory:l.isDirectory(),isSymbolicLink:l.isSymbolicLink()})}catch(o){if(o.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else o.code!=="ENOTDIR"&&this.sanitizeError(o,t,"scandir")}return n}async resolveForReaddir(t,s=!1){let n=L(t),r=new Set,i=s,a=this.memory.get(n);for(;a&&a.type==="symlink";){if(r.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(n),i=!0,n=this.resolveSymlink(n,a.target),a=this.memory.get(n)}if(a)return{normalized:n,outsideOverlay:!1};if(this.getRelativeToMount(n)===null)return{normalized:n,outsideOverlay:!0};let l=this.resolveRealPath_(this.toRealPath(n));if(!l)return{normalized:n,outsideOverlay:!0};try{if((await U.promises.lstat(l)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:n,outsideOverlay:!0};let u=await U.promises.readlink(l),f=this.realTargetToVirtual(n,u),d=this.resolveSymlink(n,f);return this.resolveForReaddir(d,!0)}return{normalized:n,outsideOverlay:!1}}catch{return i?{normalized:n,outsideOverlay:!0}:{normalized:n,outsideOverlay:!1}}}async readdir(t){W(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,a)=>i<a?-1:i>a?1:0)}async readdirWithFileTypes(t){W(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,a)=>i.name<a.name?-1:i.name>a.name?1:0)}async rm(t,s){W(t,"rm"),this.assertWritable(`rm '${t}'`);let n=L(t);if(!await this.existsInOverlay(n)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(n)).isDirectory){let a=await this.readdir(n);if(a.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of a){let l=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(l,s)}}}}catch(i){if(i instanceof Error&&(i.message.includes("ENOTEMPTY")||i.message.includes("EISDIR")))throw i}this.memory.delete(n),this.existsOnRealFs(n)&&this.deleted.add(n)}existsOnRealFs(t){let s=this.toRealPath(t),n=this.resolveRealPathParent_(s);if(!n)return!1;try{return U.lstatSync(n),!0}catch{return!1}}async cp(t,s,n){W(t,"cp"),W(s,"cp"),this.assertWritable(`cp '${s}'`);let r=L(t),i=L(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let o=await this.stat(r);if(o.isFile){let l=await this.readFileBuffer(r);await this.writeFile(i,l)}else if(o.isDirectory){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(r);for(let c of l){let u=r==="/"?`/${c}`:`${r}/${c}`,f=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(u,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){return zt(t,s)}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.resolveRealPath_(this.toRealPath(t));if(n)try{let r=U.readdirSync(n);for(let i of r){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;s.add(a);let o=ie.join(n,i);U.lstatSync(o).isDirectory()&&this.scanRealFs(a,s)}}catch{}}async chmod(t,s){W(t,"chmod"),this.assertWritable(`chmod '${t}'`);let n=L(t);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(n);if(i){i.mode=s;return}let a=await this.stat(n);if(a.isFile){let o=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:o,mode:s,mtime:new Date})}else a.isDirectory&&this.memory.set(n,{type:"directory",mode:s,mtime:new Date})}async symlink(t,s){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${s}'`);W(s,"symlink"),this.assertWritable(`symlink '${s}'`);let n=L(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){W(t,"link"),W(s,"link"),this.assertWritable(`link '${s}'`);let n=L(t),r=L(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let a=await this.stat(n);if(!a.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, link '${s}'`);let l=await this.readFileBuffer(n);this.ensureParentDirs(r),this.memory.set(r,{type:"file",content:l,mode:a.mode,mtime:new Date}),this.deleted.delete(r)}async readlink(t){W(t,"readlink");let s=L(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.resolveRealPathParent_(this.toRealPath(s));if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await U.promises.readlink(r);if(!ie.isAbsolute(i)){let a=ie.resolve(ie.dirname(r),i),o;try{o=U.realpathSync(a)}catch{o=a}if(!Ot(o,this.canonicalRoot))return ie.basename(i)}return this.realTargetToVirtual(s,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){W(t,"realpath");let s=L(t),n=new Set,r=async o=>{let l=o==="/"?[]:o.slice(1).split("/"),c="";for(let u of l){if(c=`${c}/${u}`,n.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(c),d=0,h=40;for(;f&&f.type==="symlink"&&d<h;){if(n.add(c),c=this.resolveSymlink(c,f.target),d++,n.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(c))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(c)}if(d>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let y=this.toRealPath(c),p=this.resolveRealPath_(y);if(p)try{if((await U.promises.lstat(p)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let $=await U.promises.readlink(p),g=this.realTargetToVirtual(c,$);return n.add(c),c=this.resolveSymlink(c,g),r(c)}}catch(w){if(w.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(w,t,"realpath")}else if(!this.allowSymlinks){let w=this.resolveRealPathParent_(y);if(w)try{if((await U.promises.lstat(w)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch($){if($.message?.includes("ENOENT")||$.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError($,t,"realpath")}}}}return c||"/"},i=await r(s);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,s,n){W(t,"utimes"),this.assertWritable(`utimes '${t}'`);let r=L(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let a=this.memory.get(r);if(a){a.mtime=n;return}let o=await this.stat(r);if(o.isFile){let l=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:l,mode:o.mode,mtime:n})}else o.isDirectory&&this.memory.set(r,{type:"directory",mode:o.mode,mtime:n})}};var 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"},Tn=class{env;rl;running=!0;history=[];isInteractive;constructor(t={}){let s=process.cwd(),n=new ys({root:s,mountPoint:"/"});this.env=new ms({fs:n,cwd:t.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...t.env},network:t.network===!0?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.isInteractive=process.stdin.isTTY===!0,this.rl=Ki.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C
775
+ `;try{s.writeFileSync(`/bin/${t.name}`,r)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,r)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=uc(t.stdout),t.stderr=uc(t.stderr),t}async exec(t,s){if(this.state.callDepth===0&&(this.state.commandCount=0),this.state.commandCount++,this.state.commandCount>this.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option.
776
+ `,exitCode:1,env:Fe(this.state.env,s?.env)};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:Fe(this.state.env,s?.env)};this.logger?.info("exec",{command:t});let r=s?.cwd??this.state.cwd,n,i=r;if(s?.cwd)if(s.env&&"PWD"in s.env)n=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{n=await this.fs.realpath(r),i=n}catch{n=r}else n=r;let a=s?.replaceEnv?new Map:new Map(this.state.env);if(s?.env)for(let[f,d]of Object.entries(s.env))a.set(f,d);n!==void 0&&a.set("PWD",n);let l={...this.state,env:a,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:Kd(s?.stdin,s?.stdinKind),signal:s?.signal,extraArgs:s?.args},o=t;s?.rawScript||(o=cc(t));let u=this.defenseInDepthConfig?Be.getInstance(this.defenseInDepthConfig):null,c=u?.activate();try{let f=async()=>{let d=Ue(o,{maxHeredocSize:this.limits.maxHeredocSize}),h;if(this.transformPlugins.length>0){let v=Object.create(null);for(let E of this.transformPlugins){let w=E.transform({ast:d,metadata:v});d=w.ast,w.metadata&&(v=Sn(v,w.metadata))}h=v}let p={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,requireDefenseContext:u?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},b=await new hs(p,l).executeScript(d);return h&&(b.metadata=h),this.logResult(b)};return c?await c.run(f):await f()}catch(f){if(f instanceof U)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:Fe(this.state.env,s?.env)});if(f instanceof Me)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:Fe(this.state.env,s?.env)});if(f instanceof te)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:1,env:Fe(this.state.env,s?.env)});if(f instanceof Es)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:Fe(this.state.env,s?.env)});if(f instanceof Q)return this.logResult({stdout:f.stdout,stderr:at(f.stderr),exitCode:Q.EXIT_CODE,env:Fe(this.state.env,s?.env)});if(f instanceof Ct)return this.logResult({stdout:"",stderr:`bash: security violation: ${at(f.message)}
777
+ `,exitCode:1,env:Fe(this.state.env,s?.env)});if(f.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${at(f.message)}
778
+ `,exitCode:2,env:Fe(this.state.env,s?.env)});if(f instanceof pt)return this.logResult({stdout:"",stderr:`bash: ${at(f.message)}
779
+ `,exitCode:2,env:Fe(this.state.env,s?.env)});if(f instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${at(f.message)}
780
+ `,exitCode:1,env:Fe(this.state.env,s?.env)});throw f}finally{c?.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 dt(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){let s=cc(t),r=Ue(s,{maxHeredocSize:this.limits.maxHeredocSize}),n=Object.create(null);for(let i of this.transformPlugins){let a=i.transform({ast:r,metadata:n});r=a.ast,a.metadata&&(n=Sn(n,a.metadata))}return{script:nc(r),ast:r,metadata:n}}};function Gd(e,t){let s=t;for(let r=0;r<e.length;r++){let n=e[r];if(s==="single")n==="'"&&(s="none");else if(s==="double")n==="\\"?r++:n==='"'&&(s="none");else if(n==="'")s="single";else if(n==='"')s="double";else if(n==="\\")r++;else if(n==="#"&&(r===0||/\s/.test(e[r-1])))break}return s}function cc(e){let t=e.split(`
781
+ `),s=[],r=[],n="none";for(let i=0;i<t.length;i++){let a=t[i];if(r.length>0){let c=r[r.length-1];if((c.stripTabs?a.replace(/^\t+/,""):a)===c.delimiter){s.push(a.trimStart()),r.pop();continue}s.push(a);continue}let l=n,o=l==="none"?a.trimStart():a;if(s.push(o),n=Gd(a,l),l!=="none")continue;let u=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let c of o.matchAll(u)){let f=c[1]==="-",d=c[3];r.push({delimiter:d,stripTabs:f})}}return s.join(`
782
+ `)}var Qd=new TextDecoder("utf-8",{fatal:!0});function uc(e){if(!e)return e;let t=!1;for(let r=0;r<e.length;r++){let n=e.charCodeAt(r);if(n>255)return e;n>127&&(t=!0)}if(!t)return e;let s=new Uint8Array(e.length);for(let r=0;r<e.length;r++)s[r]=e.charCodeAt(r);try{return Qd.decode(s)}catch{return e}}function Kd(e,t){if(e!==void 0)return t==="bytes"?e:At(e)}import*as re from"node:fs";import*as be from"node:path";import*as ze from"node:fs";import*as $e from"node:path";function ys(e,t){if(e===t)return!0;let s=e[t.length];return(s==="/"||s==="\\")&&e.startsWith(t)}function gs(e,t){try{let s=ze.realpathSync(e);return ys(s,t)?s:null}catch(s){if(s.code==="ENOENT"){let r=$e.dirname(e);if(r===e)return null;let n=gs(r,t);if(n===null)return null;try{if(ze.lstatSync(e).isSymbolicLink()){let a=ze.readlinkSync(e),l=$e.isAbsolute(a)?a:$e.resolve($e.dirname(e),a);if(gs(l,t)===null)return null}}catch{}return $e.join(n,$e.basename(e))}return null}}function fc(e,t,s){let r=gs(e,s);if(r===null)return null;let n=$e.resolve(e),i=n.slice(t.length),a=r.slice(s.length);if(i!==a)return null;try{if(ze.lstatSync(n).isSymbolicLink())return null}catch{}return r}function dc(e,t){if(!ze.existsSync(e))throw new Error(`${t} root does not exist`);if(!ze.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function hc(e,t){if(!$e.isAbsolute(e))return{withinRoot:!0,relativePath:e};let s;try{s=ze.realpathSync(e)}catch{s=$e.resolve(e)}return ys(s,t)?{withinRoot:!0,relativePath:s.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:$e.basename(e)}}function pc(e,t,s,r){let n=e;if(n.path===void 0){for(let a of r)if(n.message?.includes(a))throw e}let i=n.code||"EIO";throw new Error(`${i}: ${s} '${t}'`)}var Xd=["ELOOP","EFBIG","EPERM"],Yd="/home/user/project",En=class{root;canonicalRoot;mountPoint;readOnly;maxFileReadSize;allowSymlinks;memory=new Map;deleted=new Set;constructor(t){this.root=be.resolve(t.root);let s=t.mountPoint??Yd;if(this.mountPoint=s==="/"?"/":s.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${s}`);this.readOnly=t.readOnly??!1,this.maxFileReadSize=t.maxFileReadSize??10485760,this.allowSymlinks=t.allowSymlinks??!1,dc(this.root,"OverlayFs"),this.canonicalRoot=re.realpathSync(this.root),this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){let t=this.mountPoint.split("/").filter(Boolean),s="";for(let r of t)s+=`/${r}`,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 n=B(t).split("/").filter(Boolean),i="";for(let a of n)i+=`/${a}`,this.memory.has(i)||this.memory.set(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,s){let r=B(t),n=this.getDirname(r);n!=="/"&&this.mkdirSync(n);let i=s instanceof Uint8Array?s:new TextEncoder().encode(s);this.memory.set(r,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let s=t.lastIndexOf("/");return s===0?"/":t.slice(0,s)}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let s=B(t),r=this.getRelativeToMount(s);if(r===null)return null;let n=be.join(this.root,r),i=be.resolve(n);return ys(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?gs(t,this.canonicalRoot):fc(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let s=be.dirname(t),r=this.resolveRealPath_(s);return r===null?null:be.join(r,be.basename(t))}sanitizeError(t,s,r){pc(t,s,r,Xd)}ensureParentDirs(t){let s=$t(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=B(t);if(this.deleted.has(s))return!1;if(this.memory.has(s))return!0;let r=this.resolveRealPathParent_(this.toRealPath(s));if(!r)return!1;try{return await re.promises.lstat(r),!0}catch{return!1}}async readFile(t,s){let r=await this.readFileBuffer(t),n=ht(s);return xt(r,n)}async readFileBytes(t){let s=await this.readFileBuffer(t);return xt(s,"binary")}async readFileBuffer(t,s=new Set){K(t,"open");let r=B(t);if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(s.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let n=this.memory.get(r);if(n){if(n.type==="symlink"){let a=this.resolveSymlink(r,n.target);return this.readFileBuffer(a,s)}if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let a=await re.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${t}'`);let u=await re.promises.readlink(i),c=this.realTargetToVirtual(r,u),f=this.resolveSymlink(r,c);return this.readFileBuffer(f,s)}if(a.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(this.maxFileReadSize>0&&a.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${a.size} bytes, max ${this.maxFileReadSize})`);let l=this.allowSymlinks?re.constants.O_RDONLY:re.constants.O_RDONLY|re.constants.O_NOFOLLOW,o=await re.promises.open(i,l);try{let u=await o.readFile();return new Uint8Array(u)}finally{await o.close()}}catch(a){let l=a.code;if(l==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(l==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(a,t,"open")}}async writeFile(t,s,r){K(t,"write"),this.assertWritable(`write '${t}'`);let n=B(t);this.ensureParentDirs(n);let i=ht(r),a=Rt(s,i);this.memory.set(n,{type:"file",content:a,mode:420,mtime:new Date}),this.deleted.delete(n)}async appendFile(t,s,r){K(t,"append"),this.assertWritable(`append '${t}'`);let n=B(t),i=ht(r),a=Rt(s,i),l;try{l=await this.readFileBuffer(n)}catch{l=new Uint8Array(0)}let o=new Uint8Array(l.length+a.length);o.set(l),o.set(a,l.length),this.ensureParentDirs(n),this.memory.set(n,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(n)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,s=new Set){K(t,"stat");let r=B(t);if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(s.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let n=this.memory.get(r);if(n){if(n.type==="symlink"){let l=this.resolveSymlink(r,n.target);return this.stat(l,s)}let a=0;return n.type==="file"&&(a=n.content.length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:a,mtime:n.mtime}}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let a=await re.promises.lstat(i);if(a.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let l=await re.promises.readlink(i),o=this.realTargetToVirtual(r,l),u=this.resolveSymlink(r,o);return this.stat(u,s)}return{isFile:a.isFile(),isDirectory:a.isDirectory(),isSymbolicLink:!1,mode:a.mode,size:a.size,mtime:a.mtime}}catch(a){if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(a,t,"stat")}}async lstat(t){K(t,"lstat");let s=B(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let r=this.memory.get(s);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let i=0;return r.type==="file"&&(i=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:i,mtime:r.mtime}}let n=this.resolveRealPathParent_(this.toRealPath(s));if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await re.promises.lstat(n);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}resolveSymlink(t,s){return Tt(t,s)}realTargetToVirtual(t,s){let r=hc(s,this.canonicalRoot);if(r.withinRoot){if(!be.isAbsolute(s))return s;let n=r.relativePath;return this.mountPoint==="/"?n:`${this.mountPoint}${n}`}return r.safeName}async mkdir(t,s){K(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=B(t);if(await this.existsInOverlay(r)){if(!s?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=$t(r);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(r,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(r)}async readdirCore(t,s){if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Map,n=new Set,i=s==="/"?"/":`${s}/`;for(let l of this.deleted)if(l.startsWith(i)){let o=l.slice(i.length),u=o.split("/")[0];u&&!o.includes("/",u.length)&&n.add(u)}for(let[l,o]of this.memory)if(l!==s&&l.startsWith(i)){let u=l.slice(i.length),c=u.split("/")[0];c&&!n.has(c)&&!u.includes("/",1)&&r.set(c,{name:c,isFile:o.type==="file",isDirectory:o.type==="directory",isSymbolicLink:o.type==="symlink"})}let a=this.resolveRealPath_(this.toRealPath(s));if(a)try{if(!this.allowSymlinks&&(await re.promises.lstat(a)).isSymbolicLink()){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);return r}let l=await re.promises.readdir(a,{withFileTypes:!0});for(let o of l)!n.has(o.name)&&!r.has(o.name)&&r.set(o.name,{name:o.name,isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:o.isSymbolicLink()})}catch(l){if(l.code==="ENOENT"){if(!this.memory.has(s))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else l.code!=="ENOTDIR"&&this.sanitizeError(l,t,"scandir")}return r}async resolveForReaddir(t,s=!1){let r=B(t),n=new Set,i=s,a=this.memory.get(r);for(;a&&a.type==="symlink";){if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);n.add(r),i=!0,r=this.resolveSymlink(r,a.target),a=this.memory.get(r)}if(a)return{normalized:r,outsideOverlay:!1};if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let o=this.resolveRealPath_(this.toRealPath(r));if(!o)return{normalized:r,outsideOverlay:!0};try{if((await re.promises.lstat(o)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let c=await re.promises.readlink(o),f=this.realTargetToVirtual(r,c),d=this.resolveSymlink(r,f);return this.resolveForReaddir(d,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async readdir(t){K(t,"scandir");let{normalized:s,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let n=await this.readdirCore(t,s);return Array.from(n.keys()).sort((i,a)=>i<a?-1:i>a?1:0)}async readdirWithFileTypes(t){K(t,"scandir");let{normalized:s,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let n=await this.readdirCore(t,s);return Array.from(n.values()).sort((i,a)=>i.name<a.name?-1:i.name>a.name?1:0)}async rm(t,s){K(t,"rm"),this.assertWritable(`rm '${t}'`);let r=B(t);if(!await this.existsInOverlay(r)){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(r)).isDirectory){let a=await this.readdir(r);if(a.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let l of a){let o=r==="/"?`/${l}`:`${r}/${l}`;await this.rm(o,s)}}}}catch(i){if(i instanceof Error&&(i.message.includes("ENOTEMPTY")||i.message.includes("EISDIR")))throw i}this.memory.delete(r),this.existsOnRealFs(r)&&this.deleted.add(r)}existsOnRealFs(t){let s=this.toRealPath(t),r=this.resolveRealPathParent_(s);if(!r)return!1;try{return re.lstatSync(r),!0}catch{return!1}}async cp(t,s,r){K(t,"cp"),K(s,"cp"),this.assertWritable(`cp '${s}'`);let n=B(t),i=B(s);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let l=await this.stat(n);if(l.isFile){let o=await this.readFileBuffer(n);await this.writeFile(i,o)}else if(l.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let o=await this.readdir(n);for(let u of o){let c=n==="/"?`/${u}`:`${n}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(c,f,r)}}}async mv(t,s){this.assertWritable(`mv '${s}'`),await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,s){return Ss(t,s)}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 r=this.resolveRealPath_(this.toRealPath(t));if(r)try{let n=re.readdirSync(r);for(let i of n){let a=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(a))continue;s.add(a);let l=be.join(r,i);re.lstatSync(l).isDirectory()&&this.scanRealFs(a,s)}}catch{}}async chmod(t,s){K(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=B(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(r);if(i){i.mode=s;return}let a=await this.stat(r);if(a.isFile){let l=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:l,mode:s,mtime:new Date})}else a.isDirectory&&this.memory.set(r,{type:"directory",mode:s,mtime:new Date})}async symlink(t,s){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${s}'`);K(s,"symlink"),this.assertWritable(`symlink '${s}'`);let r=B(s);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.memory.set(r,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(t,s){K(t,"link"),K(s,"link"),this.assertWritable(`link '${s}'`);let r=B(t),n=B(s);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let a=await this.stat(r);if(!a.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(n))throw new Error(`EEXIST: file already exists, link '${s}'`);let o=await this.readFileBuffer(r);this.ensureParentDirs(n),this.memory.set(n,{type:"file",content:o,mode:a.mode,mtime:new Date}),this.deleted.delete(n)}async readlink(t){K(t,"readlink");let s=B(t);if(this.deleted.has(s))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let r=this.memory.get(s);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}let n=this.resolveRealPathParent_(this.toRealPath(s));if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await re.promises.readlink(n);if(!be.isAbsolute(i)){let a=be.resolve(be.dirname(n),i),l;try{l=re.realpathSync(a)}catch{l=a}if(!ys(l,this.canonicalRoot))return be.basename(i)}return this.realTargetToVirtual(s,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){K(t,"realpath");let s=B(t),r=new Set,n=async l=>{let o=l==="/"?[]:l.slice(1).split("/"),u="";for(let c of o){if(u=`${u}/${c}`,r.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(r.add(u),u=this.resolveSymlink(u,f.target),d++,r.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 p=this.toRealPath(u),m=this.resolveRealPath_(p);if(m)try{if((await re.promises.lstat(m)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let b=await re.promises.readlink(m),v=this.realTargetToVirtual(u,b);return r.add(u),u=this.resolveSymlink(u,v),n(u)}}catch(y){if(y.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(y,t,"realpath")}else if(!this.allowSymlinks){let y=this.resolveRealPathParent_(p);if(y)try{if((await re.promises.lstat(y)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch(b){if(b.message?.includes("ENOENT")||b.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(b,t,"realpath")}}}}return u||"/"},i=await n(s);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,s,r){K(t,"utimes"),this.assertWritable(`utimes '${t}'`);let n=B(t);if(!await this.existsInOverlay(n))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let a=this.memory.get(n);if(a){a.mtime=r;return}let l=await this.stat(n);if(l.isFile){let o=await this.readFileBuffer(n);this.memory.set(n,{type:"file",content:o,mode:l.mode,mtime:r})}else l.isDirectory&&this.memory.set(n,{type:"directory",mode:l.mode,mtime:r})}};var ye={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"},fi=class{env;rl;running=!0;history=[];isInteractive;constructor(t={}){let s=process.cwd(),r=new En({root:s,mountPoint:"/"});this.env=new wn({fs:r,cwd:t.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...t.env},network:t.network===!0?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.isInteractive=process.stdin.isTTY===!0,this.rl=gc.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C
709
783
  `),this.prompt()}),process.stdin.isTTY&&this.rl.on("close",()=>{this.running=!1,console.log(`
710
- 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&&process.stdout.write(n.stdout),n.stderr&&process.stderr.write(`${se.red}${n.stderr}${se.reset}`)}catch(n){console.error(`${se.red}Error: ${$e(n)}${se.reset}`)}}}printWelcome(){console.log(`
711
- ${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
784
+ 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",r=t;return t===s?r="~":t.startsWith(`${s}/`)&&(r=`~${t.slice(s.length)}`),`${ye.green}${ye.bold}user@virtual${ye.reset}:${ye.blue}${ye.bold}${r}${ye.reset}$ `}async executeCommand(t){let s=t.trim();if(s){if(this.history.push(s),s==="exit"||s.startsWith("exit ")){let r=s.split(/\s+/),n=r[1]?parseInt(r[1],10):0;console.log("exit"),process.exit(n)}this.syncHistory();try{let r=await this.env.exec(s);r.stdout&&process.stdout.write(r.stdout),r.stderr&&process.stderr.write(`${ye.red}${r.stderr}${ye.reset}`)}catch(r){console.error(`${ye.red}Error: ${qe(r)}${ye.reset}`)}}}printWelcome(){console.log(`
785
+ ${ye.cyan}${ye.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
712
786
  \u2551 Virtual Shell v1.0 \u2551
713
787
  \u2551 A simulated bash environment in TypeScript \u2551
714
- \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D${se.reset}
788
+ \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D${ye.reset}
715
789
 
716
- ${se.dim}Exploring: ${process.cwd()}${se.reset}
790
+ ${ye.dim}Exploring: ${process.cwd()}${ye.reset}
717
791
 
718
- Type ${se.green}help${se.reset} for available commands, ${se.green}exit${se.reset} to quit.
792
+ Type ${ye.green}help${ye.reset} for available commands, ${ye.green}exit${ye.reset} to quit.
719
793
  Reads from real filesystem, writes stay in memory (OverlayFs).
720
- `)}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 dl(){let e=process.argv.slice(2),t={};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=Gi.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]==="--network"?t.network=!0:e[s]==="--no-network"?t.network=!1:(e[s]==="--help"||e[s]==="-h")&&(console.log(`
794
+ `)}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 Jd(){let e=process.argv.slice(2),t={};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 r=e[++s];try{let n=mc.readFileSync(r,"utf-8");t.files=JSON.parse(n)}catch(n){console.error(`Error reading files from ${r}:`,n),process.exit(1)}}else e[s]==="--network"?t.network=!0:e[s]==="--no-network"?t.network=!1:(e[s]==="--help"||e[s]==="-h")&&(console.log(`
721
795
  Usage: pnpm shell [options]
722
796
 
723
797
  Interactive shell using OverlayFs - reads from the current directory,
@@ -732,4 +806,4 @@ Options:
732
806
  Example:
733
807
  pnpm shell
734
808
  pnpm shell --network
735
- `),process.exit(0));return t}var hl=dl(),pl=new Tn(hl);pl.run();
809
+ `),process.exit(0));return t}var eh=Jd(),th=new fi(eh);th.run();