just-bash 2.9.5 → 2.9.7

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 (67) hide show
  1. package/dist/Bash.d.ts +5 -0
  2. package/dist/bin/chunks/{awk2-JBWRWZZH.js → awk2-PWEGD656.js} +1 -1
  3. package/dist/bin/{shell/chunks/base64-OHU2WTUF.js → chunks/base64-YXBFJFHG.js} +1 -1
  4. package/dist/bin/{shell/chunks/bash-RJTQJAKW.js → chunks/bash-WB6O736J.js} +1 -1
  5. package/dist/bin/chunks/chunk-A4442AOC.js +6 -0
  6. package/dist/bin/chunks/chunk-BARKRZDC.js +6 -0
  7. package/dist/bin/chunks/{chunk-CHQBMS62.js → chunk-CHB75QIN.js} +1 -1
  8. package/dist/bin/{shell/chunks/chunk-7FTB27TY.js → chunks/chunk-FEBB4TFH.js} +15 -15
  9. package/dist/bin/{shell/chunks/chunk-ZJSZ2BE5.js → chunks/chunk-K7XSYP4L.js} +11 -11
  10. package/dist/bin/chunks/{chunk-Q4AUWUII.js → chunk-LS25HZNJ.js} +1 -1
  11. package/dist/bin/chunks/{chunk-F26OLHG5.js → chunk-MNNOATCV.js} +1 -1
  12. package/dist/bin/chunks/{chunk-DSNA7727.js → chunk-QEBPVWVB.js} +1 -1
  13. package/dist/bin/chunks/{chunk-OIKCUTTB.js → chunk-RDZMRK5M.js} +1 -1
  14. package/dist/bin/chunks/{expansion-HIAVHGBZ.js → expansion-TL4Q62VX.js} +1 -1
  15. package/dist/bin/chunks/{flag-coverage-FNEHS7AY.js → flag-coverage-SFRIE2LL.js} +1 -1
  16. package/dist/bin/{shell/chunks/jq-3VHS7DR6.js → chunks/jq-CXQ33VMW.js} +1 -1
  17. package/dist/bin/{shell/chunks/sed-XP3QCHIB.js → chunks/sed-WNL6TIIN.js} +1 -1
  18. package/dist/bin/chunks/{xan-EBI2W7YX.js → xan-FMSZPFX4.js} +1 -1
  19. package/dist/bin/chunks/{yq-O56CEX4T.js → yq-WUJ5JNDT.js} +1 -1
  20. package/dist/bin/just-bash.js +52 -52
  21. package/dist/bin/shell/chunks/{awk2-JBWRWZZH.js → awk2-PWEGD656.js} +1 -1
  22. package/dist/bin/{chunks/base64-OHU2WTUF.js → shell/chunks/base64-YXBFJFHG.js} +1 -1
  23. package/dist/bin/{chunks/bash-RJTQJAKW.js → shell/chunks/bash-WB6O736J.js} +1 -1
  24. package/dist/bin/shell/chunks/chunk-A4442AOC.js +6 -0
  25. package/dist/bin/shell/chunks/chunk-BARKRZDC.js +6 -0
  26. package/dist/bin/shell/chunks/{chunk-CHQBMS62.js → chunk-CHB75QIN.js} +1 -1
  27. package/dist/bin/{chunks/chunk-7FTB27TY.js → shell/chunks/chunk-FEBB4TFH.js} +15 -15
  28. package/dist/bin/{chunks/chunk-ZJSZ2BE5.js → shell/chunks/chunk-K7XSYP4L.js} +11 -11
  29. package/dist/bin/shell/chunks/{chunk-Q4AUWUII.js → chunk-LS25HZNJ.js} +1 -1
  30. package/dist/bin/shell/chunks/{chunk-F26OLHG5.js → chunk-MNNOATCV.js} +1 -1
  31. package/dist/bin/shell/chunks/{chunk-DSNA7727.js → chunk-QEBPVWVB.js} +1 -1
  32. package/dist/bin/shell/chunks/{chunk-OIKCUTTB.js → chunk-RDZMRK5M.js} +1 -1
  33. package/dist/bin/shell/chunks/{expansion-HIAVHGBZ.js → expansion-TL4Q62VX.js} +1 -1
  34. package/dist/bin/shell/chunks/{flag-coverage-FNEHS7AY.js → flag-coverage-SFRIE2LL.js} +1 -1
  35. package/dist/bin/{chunks/jq-3VHS7DR6.js → shell/chunks/jq-CXQ33VMW.js} +1 -1
  36. package/dist/bin/{chunks/sed-XP3QCHIB.js → shell/chunks/sed-WNL6TIIN.js} +1 -1
  37. package/dist/bin/shell/chunks/{xan-EBI2W7YX.js → xan-FMSZPFX4.js} +1 -1
  38. package/dist/bin/shell/chunks/{yq-O56CEX4T.js → yq-WUJ5JNDT.js} +1 -1
  39. package/dist/bin/shell/shell.js +4 -4
  40. package/dist/bundle/browser.js +657 -657
  41. package/dist/bundle/chunks/{awk2-M5NFQRYA.js → awk2-BDPR2JPZ.js} +1 -1
  42. package/dist/bundle/chunks/{base64-HYOQ5I2F.js → base64-A3SGWC34.js} +1 -1
  43. package/dist/bundle/chunks/{bash-OVBCDR7G.js → bash-DYXMG247.js} +1 -1
  44. package/dist/bundle/chunks/{chunk-GQ7SJRUH.js → chunk-2OCD45J4.js} +1 -1
  45. package/dist/bundle/chunks/{chunk-WEIVGBP5.js → chunk-3KWUDRIP.js} +11 -11
  46. package/dist/bundle/chunks/chunk-FRDGR5VK.js +5 -0
  47. package/dist/bundle/chunks/chunk-IBFD7QQD.js +5 -0
  48. package/dist/bundle/chunks/{chunk-UAHZJD43.js → chunk-JI3KJ32H.js} +1 -1
  49. package/dist/bundle/chunks/{chunk-HXILPMCG.js → chunk-JP44OYZS.js} +1 -1
  50. package/dist/bundle/chunks/{chunk-CCL4U6Q4.js → chunk-UJXASUXJ.js} +1 -1
  51. package/dist/bundle/chunks/{chunk-VTHR2H5Q.js → chunk-WACZHM4L.js} +15 -15
  52. package/dist/bundle/chunks/{chunk-GOBUJIHS.js → chunk-XMDVFEVC.js} +1 -1
  53. package/dist/bundle/chunks/{expansion-R2VVQUSY.js → expansion-L4NRX44B.js} +1 -1
  54. package/dist/bundle/chunks/{flag-coverage-KDDXWVDJ.js → flag-coverage-MX32DFGQ.js} +1 -1
  55. package/dist/bundle/chunks/{jq-HA6MN2H5.js → jq-OJYNICKX.js} +1 -1
  56. package/dist/bundle/chunks/{sed-MUVA7R2C.js → sed-RXIECPPB.js} +1 -1
  57. package/dist/bundle/chunks/{xan-6DLWA2BW.js → xan-Z6KVJKEE.js} +1 -1
  58. package/dist/bundle/chunks/{yq-LO2NVDTD.js → yq-FD5F3WOJ.js} +1 -1
  59. package/dist/bundle/index.js +4 -4
  60. package/dist/types.d.ts +5 -0
  61. package/package.json +1 -1
  62. package/dist/bin/chunks/chunk-FZNYF2PQ.js +0 -6
  63. package/dist/bin/chunks/chunk-STU6KQN4.js +0 -6
  64. package/dist/bin/shell/chunks/chunk-FZNYF2PQ.js +0 -6
  65. package/dist/bin/shell/chunks/chunk-STU6KQN4.js +0 -6
  66. package/dist/bundle/chunks/chunk-JSZMK2JZ.js +0 -5
  67. package/dist/bundle/chunks/chunk-RSXSWZBQ.js +0 -5
@@ -1,20 +1,20 @@
1
1
  #!/usr/bin/env node
2
- import{B as ln,C as cn,D as re,E as De,F as K,G as me,H as ht,I as un,J as T,K as fn,L as dn,M as we,N as Gt,O as pt,P as z,a as Qs,b as Js,c as en,d as ft,e as q,f as W,g as ye,h as Y,i as ge,j as Ce,k as jt,l as dt,m as tn,n as Ht,o as sn,p as fe,q as $e,r as nn,s as rn,t as Ut,u as qt,v as Pe,w as on,x as an,y as pe,z as Zt}from"./chunks/chunk-Q4AUWUII.js";import{a as _e,b as he}from"./chunks/chunk-4PRVMER6.js";import{a as Ze}from"./chunks/chunk-SE4C7FJY.js";import{a as le,b as ce,c as ne,d as ue,e as Xs,f as V,g as xe,h as lt,i as ct,j as Ys,k as ee,l as Ae,m as ut,n as de}from"./chunks/chunk-K5IXNHO5.js";import"./chunks/chunk-OBH7XN5N.js";import{a as Ee}from"./chunks/chunk-4VDEBYW7.js";import{a as at}from"./chunks/chunk-KGOUQS5A.js";import{resolve as Br}from"node:path";var Le=[{name:"echo",load:async()=>(await import("./chunks/echo-2MUAOGUE.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-3J7U3HHI.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-TZC5BRAY.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-ZXYOL67L.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-6OKMS3KO.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-5KLM4EA6.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-DWKSZGOQ.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-5QIBTLJG.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-XH2ZB7WT.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-OY7X62QC.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-5TCJXDGY.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-4O2C4V42.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-6VBAPL3Y.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-YNOUXNUY.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-YMNRW3F3.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-V537TDFR.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-ZIV3TFVG.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-XH7E4E2C.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-FRIPZKKT.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-FRIPZKKT.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-FRIPZKKT.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-3R5G2XL4.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-XP3QCHIB.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-JBWRWZZH.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-NZSEYCI6.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-FZWFZEN5.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-R3F3Z5DX.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-HDHQDWRG.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-3UVLMQ2K.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-GDDRKGRB.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-UHEPS2UL.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-XH3L75DR.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-XSVNTAWH.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-26XPP5KB.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-OYZ7KOYR.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-XXKZCWY5.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-NOZ7FFXW.js")).split},{name:"column",load:async()=>(await import("./chunks/column-XGV32UPN.js")).column},{name:"join",load:async()=>(await import("./chunks/join-Y4Q5WVVE.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-HK2SYCAR.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-K777TRNA.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-KBUKWB2E.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-5FAOMLBL.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-HEKABARE.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-66BNA4IN.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-EVLPSWFF.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-EVLPSWFF.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-3GODYSFD.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-3GODYSFD.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-UUKG55YW.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-YWPEV2QC.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-DP5UZP52.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-DP5UZP52.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-KRGKPFOI.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-RJTQJAKW.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-RJTQJAKW.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-3VHS7DR6.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-OHU2WTUF.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-LE7GMFZD.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-6VDN5QZ5.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-PICQVS6Q.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-RS7REDYT.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-4C3A4THJ.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-V7KBLSQ7.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-MLHUWFYI.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-NCLXV2S3.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-BHNJ5ALF.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-HJJ3NJ5L.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-D5YKS5NV.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-WVZA3MCP.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-JF5TTAKQ.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-67WZ6OMV.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-TZBNTR4K.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-WY6RKE32.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-E7PN2UWC.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-52FBC34W.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-EENEW6WQ.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-EENEW6WQ.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-EENEW6WQ.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Le.push({name:"tar",load:async()=>(await import("./chunks/tar-7B5KH3QG.js")).tarCommand}),Le.push({name:"yq",load:async()=>(await import("./chunks/yq-O56CEX4T.js")).yqCommand}),Le.push({name:"xan",load:async()=>(await import("./chunks/xan-EBI2W7YX.js")).xanCommand}),Le.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-4SEIR46P.js")).sqlite3Command}));var Kt=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Kt.push({name:"python3",load:async()=>(await import("./chunks/python3-ZWX5SFJ3.js")).python3Command}),Kt.push({name:"python",load:async()=>(await import("./chunks/python3-ZWX5SFJ3.js")).pythonCommand}));var Zr=[{name:"curl",load:async()=>(await import("./chunks/curl-RWQO3SBN.js")).curlCommand}],hn=new Map;function Xt(e){return{name:e.name,async execute(t,s){let n=hn.get(e.name);if(n||(n=await e.load(),hn.set(e.name,n)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:r}=await import("./chunks/flag-coverage-FNEHS7AY.js");r(s.coverage,e.name,t)}return n.execute(t,s)}}}function pn(e){return(e?Le.filter(s=>e.includes(s.name)):Le).map(Xt)}function mn(){return Zr.map(Xt)}function yn(){return Kt.map(Xt)}function gn(e){return"load"in e&&typeof e.load=="function"}function wn(e){let t=null;return{name:e.name,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}var Gr=new TextEncoder,Kr=new TextDecoder;function Fe(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)s[n/2]=parseInt(e.slice(n,n+2),16);return s}return t==="binary"||t==="latin1"?Uint8Array.from(e,s=>s.charCodeAt(0)):Gr.encode(e)}function mt(e,t){return t==="base64"?btoa(String.fromCharCode(...e)):t==="hex"?Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join(""):t==="binary"||t==="latin1"?String.fromCharCode(...e):Kr.decode(e)}function ke(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var yt=new TextEncoder;function Xr(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}function te(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}var Ge=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))Xr(n)?this.writeFileSync(s,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(s,n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,n,r){te(t,"write");let i=this.normalizePath(t);this.ensureParentDirs(i);let o=ke(n),a=Fe(s,o);this.data.set(i,{type:"file",content:a,mode:r?.mode??420,mtime:r?.mtime??new Date})}async readFile(t,s){let n=await this.readFileBuffer(t),r=ke(s);return mt(n,r)}async readFileBuffer(t){te(t,"open");let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content instanceof Uint8Array?n.content:yt.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){te(t,"append");let r=this.normalizePath(t),i=this.data.get(r);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=ke(n),a=Fe(s,o);if(i?.type==="file"){let c=i.content instanceof Uint8Array?i.content:yt.encode(i.content),l=new Uint8Array(c.length+a.length);l.set(c),l.set(a,c.length),this.data.set(r,{type:"file",content:l,mode:i.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){te(t,"stat");let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=yt.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){te(t,"lstat");let s=this.resolveIntermediateSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=yt.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}resolveIntermediateSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/");if(n.length<=1)return s;let r="",i=new Set;for(let o=0;o<n.length-1;o++){let a=n[o];r=`${r}/${a}`;let c=this.data.get(r),l=0,u=40;for(;c&&c.type==="symlink"&&l<u;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(r),r=this.resolveSymlink(r,c.target),c=this.data.get(r),l++}if(l>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${r}/${n[n.length-1]}`}resolvePathWithSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/"),r="",i=new Set;for(let o of n){r=`${r}/${o}`;let a=this.data.get(r),c=0,l=40;for(;a&&a.type==="symlink"&&c<l;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(r),r=this.resolveSymlink(r,a.target),a=this.data.get(r),c++}if(c>=l)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return r}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){te(t,"mkdir");let n=this.normalizePath(t);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let r=this.dirname(n);if(r!=="/"&&!this.data.has(r))if(s?.recursive)this.mkdirSync(r,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){te(t,"scandir");let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Set;for(;n&&n.type==="symlink";){if(r.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(s),s=this.resolveSymlink(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,o=new Map;for(let[a,c]of this.data.entries())if(a!==s&&a.startsWith(i)){let l=a.slice(i.length),u=l.split("/")[0];u&&!l.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}return Array.from(o.values()).sort((a,c)=>a.name<c.name?-1:a.name>c.name?1:0)}async rm(t,s){te(t,"rm");let n=this.normalizePath(t),r=this.data.get(n);if(!r){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(r.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(a,s)}}}this.data.delete(n)}async cp(t,s,n){te(t,"cp"),te(s,"cp");let r=this.normalizePath(t),i=this.normalizePath(s),o=this.data.get(r);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(r);for(let c of a){let l=r==="/"?`/${c}`:`${r}/${c}`,u=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(l,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){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}async chmod(t,s){te(t,"chmod");let n=this.normalizePath(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);r.mode=s}async symlink(t,s){te(s,"symlink");let n=this.normalizePath(s);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){te(t,"link"),te(s,"link");let n=this.normalizePath(t),r=this.normalizePath(s),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(r))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(t){te(t,"readlink");let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}async realpath(t){te(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){te(t,"utimes");let r=this.normalizePath(t),i=this.resolvePathWithSymlinks(r),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=n}};function Yr(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Qr(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function Jr(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function ei(e){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Qs}
2
+ import{B as ln,C as cn,D as re,E as De,F as K,G as me,H as ht,I as un,J as T,K as fn,L as dn,M as we,N as Gt,O as pt,P as z,a as Qs,b as Js,c as en,d as ft,e as q,f as W,g as ye,h as Y,i as ge,j as Ce,k as jt,l as dt,m as tn,n as Ht,o as sn,p as fe,q as Se,r as nn,s as rn,t as Ut,u as qt,v as Pe,w as on,x as an,y as pe,z as Zt}from"./chunks/chunk-LS25HZNJ.js";import{a as _e,b as he}from"./chunks/chunk-4PRVMER6.js";import{a as Ze}from"./chunks/chunk-SE4C7FJY.js";import{a as le,b as ce,c as ne,d as ue,e as Xs,f as V,g as xe,h as lt,i as ct,j as Ys,k as ee,l as Ae,m as ut,n as de}from"./chunks/chunk-K5IXNHO5.js";import"./chunks/chunk-OBH7XN5N.js";import{a as Ee}from"./chunks/chunk-4VDEBYW7.js";import{a as at}from"./chunks/chunk-KGOUQS5A.js";import{resolve as Br}from"node:path";var Le=[{name:"echo",load:async()=>(await import("./chunks/echo-2MUAOGUE.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-3J7U3HHI.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-TZC5BRAY.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-ZXYOL67L.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-6OKMS3KO.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-5KLM4EA6.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-DWKSZGOQ.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-5QIBTLJG.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-XH2ZB7WT.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-OY7X62QC.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-5TCJXDGY.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-4O2C4V42.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-6VBAPL3Y.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-YNOUXNUY.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-YMNRW3F3.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-V537TDFR.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-ZIV3TFVG.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-XH7E4E2C.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-FRIPZKKT.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-FRIPZKKT.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-FRIPZKKT.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-3R5G2XL4.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-WNL6TIIN.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-PWEGD656.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-NZSEYCI6.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-FZWFZEN5.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-R3F3Z5DX.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-HDHQDWRG.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-3UVLMQ2K.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-GDDRKGRB.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-UHEPS2UL.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-XH3L75DR.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-XSVNTAWH.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-26XPP5KB.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-OYZ7KOYR.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-XXKZCWY5.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-NOZ7FFXW.js")).split},{name:"column",load:async()=>(await import("./chunks/column-XGV32UPN.js")).column},{name:"join",load:async()=>(await import("./chunks/join-Y4Q5WVVE.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-HK2SYCAR.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-K777TRNA.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-KBUKWB2E.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-5FAOMLBL.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-HEKABARE.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-66BNA4IN.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-EVLPSWFF.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-EVLPSWFF.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-3GODYSFD.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-3GODYSFD.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-UUKG55YW.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-YWPEV2QC.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-DP5UZP52.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-DP5UZP52.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-KRGKPFOI.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-WB6O736J.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-WB6O736J.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-CXQ33VMW.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-YXBFJFHG.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-LE7GMFZD.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-6VDN5QZ5.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-PICQVS6Q.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-RS7REDYT.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-4C3A4THJ.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-V7KBLSQ7.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-MLHUWFYI.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-NCLXV2S3.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-BHNJ5ALF.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-HJJ3NJ5L.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-D5YKS5NV.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-WVZA3MCP.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-JF5TTAKQ.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-67WZ6OMV.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-TZBNTR4K.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-WY6RKE32.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-E7PN2UWC.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-52FBC34W.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-EENEW6WQ.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-EENEW6WQ.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-EENEW6WQ.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Le.push({name:"tar",load:async()=>(await import("./chunks/tar-7B5KH3QG.js")).tarCommand}),Le.push({name:"yq",load:async()=>(await import("./chunks/yq-WUJ5JNDT.js")).yqCommand}),Le.push({name:"xan",load:async()=>(await import("./chunks/xan-FMSZPFX4.js")).xanCommand}),Le.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-4SEIR46P.js")).sqlite3Command}));var Kt=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Kt.push({name:"python3",load:async()=>(await import("./chunks/python3-ZWX5SFJ3.js")).python3Command}),Kt.push({name:"python",load:async()=>(await import("./chunks/python3-ZWX5SFJ3.js")).pythonCommand}));var Zr=[{name:"curl",load:async()=>(await import("./chunks/curl-RWQO3SBN.js")).curlCommand}],hn=new Map;function Xt(e){return{name:e.name,async execute(t,s){let n=hn.get(e.name);if(n||(n=await e.load(),hn.set(e.name,n)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:r}=await import("./chunks/flag-coverage-SFRIE2LL.js");r(s.coverage,e.name,t)}return n.execute(t,s)}}}function pn(e){return(e?Le.filter(s=>e.includes(s.name)):Le).map(Xt)}function mn(){return Zr.map(Xt)}function yn(){return Kt.map(Xt)}function gn(e){return"load"in e&&typeof e.load=="function"}function wn(e){let t=null;return{name:e.name,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}var Gr=new TextEncoder,Kr=new TextDecoder;function Fe(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)s[n/2]=parseInt(e.slice(n,n+2),16);return s}if(t==="binary"||t==="latin1"){if(e.length<=65536)return Uint8Array.from(e,r=>r.charCodeAt(0));let n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return n}return Gr.encode(e)}function mt(e,t){if(t==="base64")return btoa(String.fromCharCode(...e));if(t==="hex")return Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join("");if(t==="binary"||t==="latin1"){if(typeof Buffer<"u")return Buffer.from(e).toString(t);let s=65536;if(e.length<=s)return String.fromCharCode(...e);let n="";for(let r=0;r<e.length;r+=s){let i=e.subarray(r,r+s);n+=String.fromCharCode(...i)}return n}return Kr.decode(e)}function ke(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var yt=new TextEncoder;function Xr(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}function te(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}var Ge=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))Xr(n)?this.writeFileSync(s,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(s,n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,n,r){te(t,"write");let i=this.normalizePath(t);this.ensureParentDirs(i);let o=ke(n),a=Fe(s,o);this.data.set(i,{type:"file",content:a,mode:r?.mode??420,mtime:r?.mtime??new Date})}async readFile(t,s){let n=await this.readFileBuffer(t),r=ke(s);return mt(n,r)}async readFileBuffer(t){te(t,"open");let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content instanceof Uint8Array?n.content:yt.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){te(t,"append");let r=this.normalizePath(t),i=this.data.get(r);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=ke(n),a=Fe(s,o);if(i?.type==="file"){let c=i.content instanceof Uint8Array?i.content:yt.encode(i.content),l=new Uint8Array(c.length+a.length);l.set(c),l.set(a,c.length),this.data.set(r,{type:"file",content:l,mode:i.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){te(t,"stat");let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=yt.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){te(t,"lstat");let s=this.resolveIntermediateSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=yt.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}resolveIntermediateSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/");if(n.length<=1)return s;let r="",i=new Set;for(let o=0;o<n.length-1;o++){let a=n[o];r=`${r}/${a}`;let c=this.data.get(r),l=0,u=40;for(;c&&c.type==="symlink"&&l<u;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(r),r=this.resolveSymlink(r,c.target),c=this.data.get(r),l++}if(l>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${r}/${n[n.length-1]}`}resolvePathWithSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/"),r="",i=new Set;for(let o of n){r=`${r}/${o}`;let a=this.data.get(r),c=0,l=40;for(;a&&a.type==="symlink"&&c<l;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(r),r=this.resolveSymlink(r,a.target),a=this.data.get(r),c++}if(c>=l)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return r}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){te(t,"mkdir");let n=this.normalizePath(t);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let r=this.dirname(n);if(r!=="/"&&!this.data.has(r))if(s?.recursive)this.mkdirSync(r,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){te(t,"scandir");let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Set;for(;n&&n.type==="symlink";){if(r.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(s),s=this.resolveSymlink(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,o=new Map;for(let[a,c]of this.data.entries())if(a!==s&&a.startsWith(i)){let l=a.slice(i.length),u=l.split("/")[0];u&&!l.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}return Array.from(o.values()).sort((a,c)=>a.name<c.name?-1:a.name>c.name?1:0)}async rm(t,s){te(t,"rm");let n=this.normalizePath(t),r=this.data.get(n);if(!r){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(r.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(a,s)}}}this.data.delete(n)}async cp(t,s,n){te(t,"cp"),te(s,"cp");let r=this.normalizePath(t),i=this.normalizePath(s),o=this.data.get(r);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(r);for(let c of a){let l=r==="/"?`/${c}`:`${r}/${c}`,u=i==="/"?`/${c}`:`${i}/${c}`;await this.cp(l,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){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}async chmod(t,s){te(t,"chmod");let n=this.normalizePath(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);r.mode=s}async symlink(t,s){te(s,"symlink");let n=this.normalizePath(s);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){te(t,"link"),te(s,"link");let n=this.normalizePath(t),r=this.normalizePath(s),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(r))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(t){te(t,"readlink");let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}async realpath(t){te(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){te(t,"utimes");let r=this.normalizePath(t),i=this.resolvePathWithSymlinks(r),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=n}};function Yr(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Qr(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function Jr(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function ei(e){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Qs}
3
3
  `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
4
- `),e.writeFileSync("/proc/self/status",Js()),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function vn(e,t){Yr(e)&&(Qr(e,t),Jr(e),ei(e))}var ti=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],si=["braceexpand","hashall","interactive-comments"];function Yt(e){let t=[],s=[...si.map(n=>({name:n,enabled:!0})),...ti.map(n=>({name:n,enabled:e[n]}))].sort((n,r)=>n.name.localeCompare(r.name));for(let n of s)n.enabled&&t.push(n.name);return t.join(":")}function Me(e){e.state.env.set("SHELLOPTS",Yt(e.state.options))}var ni=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Qt(e){let t=[];for(let s of ni)e[s]&&t.push(s);return t.join(":")}function Jt(e){e.state.env.set("BASHOPTS",Qt(e.state.shoptOptions))}var ri="BASH_ALIAS_";function bn(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function En(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function $n(e,t){return e.env.get(`${ri}${t}`)}function es(e,t,s){if(!t.name||!bn(t.name))return t;let n=En(t.name);if(!n)return t;let r=$n(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new W,o=r,a=r.endsWith(" ");if(!a)for(let f of t.args){let d=An(f);o+=` ${d}`}let c;try{c=i.parse(o)}catch(f){if(f instanceof ft)throw f;return t}if(c.statements.length!==1||c.statements[0].pipelines.length!==1||c.statements[0].pipelines[0].commands.length!==1)return Sn(t,r);let l=c.statements[0].pipelines[0].commands[0];if(l.type!=="SimpleCommand")return Sn(t,r);let u={...l,assignments:[...t.assignments,...l.assignments],redirections:[...l.redirections,...t.redirections],line:t.line};if(a&&t.args.length>0&&(u={...u,args:[...u.args,...t.args]},u.args.length>0)){let f=u.args[0];if(bn(f)){let d=En(f);if(d&&$n(e,d)){let h={type:"SimpleCommand",name:f,args:u.args.slice(1),assignments:[],redirections:[]},m=es(e,h,s);m!==h&&(u={...u,name:m.name,args:[...m.args]})}}}return u}catch(i){throw s.delete(n),i}}function Sn(e,t){let s=t;for(let o of e.args){let a=An(o);s+=` ${a}`}let n=new W,r=n.parseWordFromString("eval",!1,!1),i=n.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:r,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function An(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 _n(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=[],o=!1,a="",c=!1;for(let u of t.parts)if(u.type==="Literal"){let f=u.value;if(!o){let d=f.indexOf("=(");d!==-1&&(o=!0,f=f.slice(d+2))}if(o){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(a||c)&&(i.push(a),a="",c=!1):h&&(a+=h)}}else if(o)if(u.type==="BraceExpansion")if(/^\[.+\]=/.test(a))a+=dt({type:"Word",parts:[u]});else{(a||c)&&(i.push(a),a="",c=!1);let d=await we(e,{type:"Word",parts:[u]});i.push(...d.values)}else{(u.type==="SingleQuoted"||u.type==="DoubleQuoted"||u.type==="Escaped")&&(c=!0);let f=await T(e,{type:"Word",parts:[u]});a+=f}(a||c)&&i.push(a);let l=i.map(u=>/^\[.+\]=/.test(u)?u:u===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(u)&&!u.startsWith("'")&&!u.startsWith('"')?`'${u.replace(/'/g,"'\\''")}'`:u);return`${r}=(${l.join(" ")})`}async function Cn(e,t){let s=-1,n=-1,r=!1;for(let p=0;p<t.parts.length;p++){let g=t.parts[p];if(g.type==="Literal"){let S=g.value.indexOf("+=");if(S!==-1){let P=g.value.slice(0,S);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(P)){s=p,n=S,r=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(P)){s=p,n=S,r=!0;break}}let v=g.value.indexOf("=");if(v!==-1&&(v===0||g.value[v-1]!=="+")){let P=g.value.slice(0,v);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(P)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(P)){s=p,n=v;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),o=t.parts[s];if(o.type!=="Literal")return null;let a=r?2:1,c=o.value.slice(0,n),l=o.value.slice(n+a),u=t.parts.slice(s+1),f="";for(let p of i)f+=await T(e,{type:"Word",parts:[p]});f+=c;let d={type:"Word",parts:l!==""?[{type:"Literal",value:l},...u]:u},h=d.parts.length>0?await T(e,d):"";return`${f}${r?"+=":"="}${h}`}var ii=["tar","yq","xan","sqlite3","python3","python"];function Pn(e){return ii.includes(e)}var L=Object.freeze({stdout:"",stderr:"",exitCode:0});function F(e=""){return{stdout:e,stderr:"",exitCode:0}}function A(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function C(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function U(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function Se(e,t,s="",n=""){throw new ee(e,t,s,n)}function ts(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Ae;return L}if(t.length>1)throw new V(1,"",`bash: break: too many arguments
4
+ `),e.writeFileSync("/proc/self/status",Js()),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function vn(e,t){Yr(e)&&(Qr(e,t),Jr(e),ei(e))}var ti=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],si=["braceexpand","hashall","interactive-comments"];function Yt(e){let t=[],s=[...si.map(n=>({name:n,enabled:!0})),...ti.map(n=>({name:n,enabled:e[n]}))].sort((n,r)=>n.name.localeCompare(r.name));for(let n of s)n.enabled&&t.push(n.name);return t.join(":")}function Me(e){e.state.env.set("SHELLOPTS",Yt(e.state.options))}var ni=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Qt(e){let t=[];for(let s of ni)e[s]&&t.push(s);return t.join(":")}function Jt(e){e.state.env.set("BASHOPTS",Qt(e.state.shoptOptions))}var ri="BASH_ALIAS_";function bn(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function En(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function Sn(e,t){return e.env.get(`${ri}${t}`)}function es(e,t,s){if(!t.name||!bn(t.name))return t;let n=En(t.name);if(!n)return t;let r=Sn(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new W,o=r,a=r.endsWith(" ");if(!a)for(let f of t.args){let d=An(f);o+=` ${d}`}let c;try{c=i.parse(o)}catch(f){if(f instanceof ft)throw f;return t}if(c.statements.length!==1||c.statements[0].pipelines.length!==1||c.statements[0].pipelines[0].commands.length!==1)return $n(t,r);let l=c.statements[0].pipelines[0].commands[0];if(l.type!=="SimpleCommand")return $n(t,r);let u={...l,assignments:[...t.assignments,...l.assignments],redirections:[...l.redirections,...t.redirections],line:t.line};if(a&&t.args.length>0&&(u={...u,args:[...u.args,...t.args]},u.args.length>0)){let f=u.args[0];if(bn(f)){let d=En(f);if(d&&Sn(e,d)){let h={type:"SimpleCommand",name:f,args:u.args.slice(1),assignments:[],redirections:[]},m=es(e,h,s);m!==h&&(u={...u,name:m.name,args:[...m.args]})}}}return u}catch(i){throw s.delete(n),i}}function $n(e,t){let s=t;for(let o of e.args){let a=An(o);s+=` ${a}`}let n=new W,r=n.parseWordFromString("eval",!1,!1),i=n.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:r,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function An(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 _n(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=[],o=!1,a="",c=!1;for(let u of t.parts)if(u.type==="Literal"){let f=u.value;if(!o){let d=f.indexOf("=(");d!==-1&&(o=!0,f=f.slice(d+2))}if(o){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(a||c)&&(i.push(a),a="",c=!1):h&&(a+=h)}}else if(o)if(u.type==="BraceExpansion")if(/^\[.+\]=/.test(a))a+=dt({type:"Word",parts:[u]});else{(a||c)&&(i.push(a),a="",c=!1);let d=await we(e,{type:"Word",parts:[u]});i.push(...d.values)}else{(u.type==="SingleQuoted"||u.type==="DoubleQuoted"||u.type==="Escaped")&&(c=!0);let f=await T(e,{type:"Word",parts:[u]});a+=f}(a||c)&&i.push(a);let l=i.map(u=>/^\[.+\]=/.test(u)?u:u===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(u)&&!u.startsWith("'")&&!u.startsWith('"')?`'${u.replace(/'/g,"'\\''")}'`:u);return`${r}=(${l.join(" ")})`}async function Cn(e,t){let s=-1,n=-1,r=!1;for(let p=0;p<t.parts.length;p++){let g=t.parts[p];if(g.type==="Literal"){let $=g.value.indexOf("+=");if($!==-1){let P=g.value.slice(0,$);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(P)){s=p,n=$,r=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(P)){s=p,n=$,r=!0;break}}let v=g.value.indexOf("=");if(v!==-1&&(v===0||g.value[v-1]!=="+")){let P=g.value.slice(0,v);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(P)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(P)){s=p,n=v;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),o=t.parts[s];if(o.type!=="Literal")return null;let a=r?2:1,c=o.value.slice(0,n),l=o.value.slice(n+a),u=t.parts.slice(s+1),f="";for(let p of i)f+=await T(e,{type:"Word",parts:[p]});f+=c;let d={type:"Word",parts:l!==""?[{type:"Literal",value:l},...u]:u},h=d.parts.length>0?await T(e,d):"";return`${f}${r?"+=":"="}${h}`}var ii=["tar","yq","xan","sqlite3","python3","python"];function Pn(e){return ii.includes(e)}var L=Object.freeze({stdout:"",stderr:"",exitCode:0});function F(e=""){return{stdout:e,stderr:"",exitCode:0}}function A(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function C(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function U(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function $e(e,t,s="",n=""){throw new ee(e,t,s,n)}function ts(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Ae;return L}if(t.length>1)throw new V(1,"",`bash: break: too many arguments
5
5
  `);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new V(128,"",`bash: break: ${t[0]}: numeric argument required
6
6
  `);s=n}throw new le(s)}async function ss(e,t){let s,n=!1,r=!1,i=0;for(;i<t.length;)if(t[i]==="--"){i++;break}else if(t[i]==="-L")r=!1,i++;else if(t[i]==="-P")r=!0,i++;else if(t[i].startsWith("-")&&t[i]!=="-")i++;else break;let o=t.slice(i);if(o.length===0||o[0]==="~"?s=e.state.env.get("HOME")||"/":o[0]==="-"?(s=e.state.previousDir,n=!0):s=o[0],!s.startsWith("/")&&!s.startsWith("./")&&!s.startsWith("../")&&s!=="."&&s!==".."){let f=e.state.env.get("CDPATH");if(f){let d=f.split(":").filter(h=>h);for(let h of d){let m=h.startsWith("/")?`${h}/${s}`:`${e.state.cwd}/${h}/${s}`;try{if((await e.fs.stat(m)).isDirectory){s=m,n=!0;break}}catch{}}}}let c=(s.startsWith("/")?s:`${e.state.cwd}/${s}`).split("/").filter(f=>f&&f!=="."),l="";for(let f of c)if(f==="..")l=l.split("/").slice(0,-1).join("/")||"/";else{l=l?`${l}/${f}`:`/${f}`;try{if(!(await e.fs.stat(l)).isDirectory)return A(`bash: cd: ${s}: Not a directory
7
7
  `)}catch{return A(`bash: cd: ${s}: No such file or directory
8
8
  `)}}let u=l||"/";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}
9
- `:"")}function ns(e,t){return e.fs.resolvePath(e.state.cwd,t)}var oi=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function gt(e){return oi.includes(e)}async function wt(e,t,s){let n=ns(e,s);switch(t){case"-e":case"-a":return e.fs.exists(n);case"-f":return await e.fs.exists(n)?(await e.fs.stat(n)).isFile:!1;case"-d":return await e.fs.exists(n)?(await e.fs.stat(n)).isDirectory:!1;case"-r":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&256)!==0:!1;case"-w":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&128)!==0:!1;case"-x":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&64)!==0:!1;case"-s":return await e.fs.exists(n)?(await e.fs.stat(n)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(n)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&512)!==0:!1;case"-g":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(n);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].some(i=>n===i||n.endsWith(i));case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(n);default:return!1}}var ai=["-nt","-ot","-ef"];function vt(e){return ai.includes(e)}async function bt(e,t,s,n){let r=ns(e,s),i=ns(e,n);switch(t){case"-nt":try{let o=await e.fs.stat(r),a=await e.fs.stat(i);return o.mtime>a.mtime}catch{return!1}case"-ot":try{let o=await e.fs.stat(r),a=await e.fs.stat(i);return o.mtime<a.mtime}catch{return!1}case"-ef":try{if(!await e.fs.exists(r)||!await e.fs.exists(i))return!1;let o=e.fs.resolvePath(e.state.cwd,r),a=e.fs.resolvePath(e.state.cwd,i);return o===a}catch{return!1}default:return!1}}var li=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function Et(e){return li.has(e)}function $t(e,t,s){switch(e){case"-eq":return t===s;case"-ne":return t!==s;case"-lt":return t<s;case"-le":return t<=s;case"-gt":return t>s;case"-ge":return t>=s}}function Ke(e){return e==="="||e==="=="||e==="!="}function St(e,t,s,n=!1,r=!1,i=!1){if(n){let a=We(t,s,r,i);return e==="!="?!a:a}if(r){let a=t.toLowerCase()===s.toLowerCase();return e==="!="?!a:a}let o=t===s;return e==="!="?!o:o}var ci=new Set(["-z","-n"]);function At(e){return ci.has(e)}function _t(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Ct(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],r=s[2];if(e.state.associativeArrays?.has(n)){let a=r;return(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1)),a=a.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(c,l)=>e.state.env.get(l)||""),e.state.env.has(`${n}_${a}`)}let o;try{let a=new W,c=q(a,r);o=await z(e,c.expression)}catch{if(/^-?\d+$/.test(r))o=Number.parseInt(r,10);else{let a=e.state.env.get(r);o=a?Number.parseInt(a,10):0}}if(o<0){let a=Y(e,n),c=e.state.currentLine;if(a.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${c}: ${n}: bad array subscript
9
+ `:"")}function ns(e,t){return e.fs.resolvePath(e.state.cwd,t)}var oi=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function gt(e){return oi.includes(e)}async function wt(e,t,s){let n=ns(e,s);switch(t){case"-e":case"-a":return e.fs.exists(n);case"-f":return await e.fs.exists(n)?(await e.fs.stat(n)).isFile:!1;case"-d":return await e.fs.exists(n)?(await e.fs.stat(n)).isDirectory:!1;case"-r":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&256)!==0:!1;case"-w":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&128)!==0:!1;case"-x":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&64)!==0:!1;case"-s":return await e.fs.exists(n)?(await e.fs.stat(n)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(n)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&512)!==0:!1;case"-g":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(n)?((await e.fs.stat(n)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(n);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].some(i=>n===i||n.endsWith(i));case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(n);default:return!1}}var ai=["-nt","-ot","-ef"];function vt(e){return ai.includes(e)}async function bt(e,t,s,n){let r=ns(e,s),i=ns(e,n);switch(t){case"-nt":try{let o=await e.fs.stat(r),a=await e.fs.stat(i);return o.mtime>a.mtime}catch{return!1}case"-ot":try{let o=await e.fs.stat(r),a=await e.fs.stat(i);return o.mtime<a.mtime}catch{return!1}case"-ef":try{if(!await e.fs.exists(r)||!await e.fs.exists(i))return!1;let o=e.fs.resolvePath(e.state.cwd,r),a=e.fs.resolvePath(e.state.cwd,i);return o===a}catch{return!1}default:return!1}}var li=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function Et(e){return li.has(e)}function St(e,t,s){switch(e){case"-eq":return t===s;case"-ne":return t!==s;case"-lt":return t<s;case"-le":return t<=s;case"-gt":return t>s;case"-ge":return t>=s}}function Ke(e){return e==="="||e==="=="||e==="!="}function $t(e,t,s,n=!1,r=!1,i=!1){if(n){let a=We(t,s,r,i);return e==="!="?!a:a}if(r){let a=t.toLowerCase()===s.toLowerCase();return e==="!="?!a:a}let o=t===s;return e==="!="?!o:o}var ci=new Set(["-z","-n"]);function At(e){return ci.has(e)}function _t(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function Ct(e,t){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],r=s[2];if(e.state.associativeArrays?.has(n)){let a=r;return(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1)),a=a.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(c,l)=>e.state.env.get(l)||""),e.state.env.has(`${n}_${a}`)}let o;try{let a=new W,c=q(a,r);o=await z(e,c.expression)}catch{if(/^-?\d+$/.test(r))o=Number.parseInt(r,10);else{let a=e.state.env.get(r);o=a?Number.parseInt(a,10):0}}if(o<0){let a=Y(e,n),c=e.state.currentLine;if(a.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${c}: ${n}: bad array subscript
10
10
  `,!1;if(o=Math.max(...a)+1+o,o<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${c}: ${n}: bad array subscript
11
- `,!1}return e.state.env.has(`${n}_${o}`)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?Ce(e,t).length>0:Y(e,t).length>0}async function Ne(e,t){switch(t.type){case"CondBinary":{let s=await T(e,t.left),n=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),r;if(t.operator==="=~")if(n){let i=await T(e,t.right);r=cn(i)}else r=await fn(e,t.right);else Ke(t.operator)&&!n?r=await dn(e,t.right):r=await T(e,t.right);if(Ke(t.operator)){let i=e.state.shoptOptions.nocasematch;return St(t.operator,s,r,!n,i,!0)}if(Et(t.operator))return $t(t.operator,await Nn(e,s),await Nn(e,r));if(vt(t.operator))return bt(e,t.operator,s,r);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=hi(r),c=Ze(o,i?"i":"").match(s);if(ge(e,"BASH_REMATCH"),c)for(let l=0;l<c.length;l++)e.state.env.set(`BASH_REMATCH_${l}`,c[l]||"");return c!==null}catch{throw new Error("syntax error in regular expression")}case"<":return s<r;case">":return s>r;default:return!1}}case"CondUnary":{let s=await T(e,t.operand);return gt(t.operator)?wt(e,t.operator,s):At(t.operator)?_t(t.operator,s):t.operator==="-v"?await Ct(e,s):t.operator==="-o"?is(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await T(e,t.operand.expression.word)})`!=="":!await Ne(e,t.operand);case"CondAnd":return await Ne(e,t.left)?await Ne(e,t.right):!1;case"CondOr":return await Ne(e,t.left)?!0:await Ne(e,t.right);case"CondGroup":return await Ne(e,t.expression);case"CondWord":return await T(e,t.word)!=="";default:return!1}}async function Xe(e,t){if(t.length===0)return C("","",1);if(t.length===1)return U(!!t[0]);if(t.length===2){let n=t[0],r=t[1];return n==="("?A(`test: '(' without matching ')'
11
+ `,!1}return e.state.env.has(`${n}_${o}`)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?Ce(e,t).length>0:Y(e,t).length>0}async function Ne(e,t){switch(t.type){case"CondBinary":{let s=await T(e,t.left),n=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),r;if(t.operator==="=~")if(n){let i=await T(e,t.right);r=cn(i)}else r=await fn(e,t.right);else Ke(t.operator)&&!n?r=await dn(e,t.right):r=await T(e,t.right);if(Ke(t.operator)){let i=e.state.shoptOptions.nocasematch;return $t(t.operator,s,r,!n,i,!0)}if(Et(t.operator))return St(t.operator,await Nn(e,s),await Nn(e,r));if(vt(t.operator))return bt(e,t.operator,s,r);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=hi(r),c=Ze(o,i?"i":"").match(s);if(ge(e,"BASH_REMATCH"),c)for(let l=0;l<c.length;l++)e.state.env.set(`BASH_REMATCH_${l}`,c[l]||"");return c!==null}catch{throw new Error("syntax error in regular expression")}case"<":return s<r;case">":return s>r;default:return!1}}case"CondUnary":{let s=await T(e,t.operand);return gt(t.operator)?wt(e,t.operator,s):At(t.operator)?_t(t.operator,s):t.operator==="-v"?await Ct(e,s):t.operator==="-o"?is(e,s):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await T(e,t.operand.expression.word)})`!=="":!await Ne(e,t.operand);case"CondAnd":return await Ne(e,t.left)?await Ne(e,t.right):!1;case"CondOr":return await Ne(e,t.left)?!0:await Ne(e,t.right);case"CondGroup":return await Ne(e,t.expression);case"CondWord":return await T(e,t.word)!=="";default:return!1}}async function Xe(e,t){if(t.length===0)return C("","",1);if(t.length===1)return U(!!t[0]);if(t.length===2){let n=t[0],r=t[1];return n==="("?A(`test: '(' without matching ')'
12
12
  `,2):gt(n)?U(await wt(e,n,r)):At(n)?U(_t(n,r)):n==="!"?U(!r):n==="-v"?U(await Ct(e,r)):n==="-o"?U(is(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"?A(`test: ${n}: unary operator expected
13
- `,2):C("","",1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(Ke(r))return U(St(r,n,i));if(Et(r)){let o=Pt(n),a=Pt(i);return!o.valid||!a.valid?C("","",2):U($t(r,o.value,a.value))}if(vt(r))return U(await bt(e,r,n,i));switch(r){case"-a":return U(n!==""&&i!=="");case"-o":return U(n!==""||i!=="");case">":return U(n>i);case"<":return U(n<i)}if(n==="!"){let o=await Xe(e,[r,i]);return C("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(n==="("&&i===")")return U(r!=="")}if(t.length===4){if(t[0]==="!"){let n=await Xe(e,t.slice(1));return C("",n.stderr,n.exitCode===0?1:n.exitCode===1?0:n.exitCode)}if(t[0]==="("&&t[3]===")")return Xe(e,[t[1],t[2]])}let s=await xn(e,t,0);return s.pos<t.length?A(`test: too many arguments
14
- `,2):U(s.value)}async function xn(e,t,s){return ui(e,t,s)}async function ui(e,t,s){let{value:n,pos:r}=await kn(e,t,s);for(;t[r]==="-o";){let i=await kn(e,t,r+1);n=n||i.value,r=i.pos}return{value:n,pos:r}}async function kn(e,t,s){let{value:n,pos:r}=await rs(e,t,s);for(;t[r]==="-a";){let i=await rs(e,t,r+1);n=n&&i.value,r=i.pos}return{value:n,pos:r}}async function rs(e,t,s){if(t[s]==="!"){let{value:n,pos:r}=await rs(e,t,s+1);return{value:!n,pos:r}}return fi(e,t,s)}async function fi(e,t,s){let n=t[s];if(n==="("){let{value:i,pos:o}=await xn(e,t,s+1);return{value:i,pos:t[o]===")"?o+1:o}}let r=t[s+1];if(Ke(r)){let i=n,o=t[s+2]??"";return{value:St(r,i,o),pos:s+3}}if(Et(r)){let i=Pt(n),o=Pt(t[s+2]??"0");return!i.valid||!o.valid?{value:!1,pos:s+3}:{value:$t(r,i.value,o.value),pos:s+3}}if(vt(r)){let i=n,o=t[s+2]??"";return{value:await bt(e,r,i,o),pos:s+3}}if(gt(n)){let i=t[s+1]??"";return{value:await wt(e,n,i),pos:s+2}}if(At(n)){let i=t[s+1]??"";return{value:_t(n,i),pos:s+2}}if(n==="-v"){let i=t[s+1]??"";return{value:await Ct(e,i),pos:s+2}}if(n==="-o"){let i=t[s+1]??"";return{value:is(e,i),pos:s+2}}return{value:n!==void 0&&n!=="",pos:s+1}}function We(e,t,s=!1,n=!1){let r=`^${Dn(t,n)}$`;return Ze(r,s?"is":"s").test(e)}function Dn(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=Tn(e,n+1);if(i!==-1){let o=e.slice(n+2,i),a=In(o),c=a.map(u=>Dn(u,t)),l=c.length>0?c.join("|"):"(?:)";if(r==="@")s+=`(?:${l})`;else if(r==="*")s+=`(?:${l})*`;else if(r==="+")s+=`(?:${l})+`;else if(r==="?")s+=`(?:${l})?`;else if(r==="!")if(i<e.length-1){let f=a.map(h=>Rn(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 m=[];h>0&&m.push(`.{0,${h-1}}`),m.push(`.{${h+1},}`),m.push(`(?!(?:${l})).{${h}}`),s+=`(?:${m.join("|")})`}}else s+=`(?:(?!(?:${l})).)*?`}else s+=`(?!(?:${l})$).*`;n=i;continue}}if(r==="\\")if(n+1<e.length){let i=e[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,n++}else s+="\\\\";else if(r==="*")s+=".*";else if(r==="?")s+=".";else if(r==="["){let i=e.indexOf("]",n+1);i!==-1?(s+=e.slice(n,i+1),n=i):s+="\\["}else/[\\^$.|+(){}]/.test(r)?s+=`\\${r}`:s+=r}return s}function Tn(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 In(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 Rn(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=Tn(e,n+1);if(i!==-1){if(r==="@"){let o=e.slice(n+2,i),c=In(o).map(l=>Rn(l,t));if(c.every(l=>l!==null)&&c.every(l=>l===c[0])){s+=c[0],n=i+1;continue}return null}return null}}if(r==="*")return null;if(r==="?"){s+=1,n++;continue}if(r==="["){let i=e.indexOf("]",n+1);if(i!==-1){s+=1,n=i+1;continue}s+=1,n++;continue}if(r==="\\"){s+=1,n+=2;continue}s+=1,n++}return s}function is(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 Nn(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 On(t);try{let s=new W,n=q(s,t);return await z(e,n.expression)}catch{return On(t)}}function di(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 On(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=di(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 Pt(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 hi(e){let t="",s=0;for(;s<e.length;)if(e[s]==="\\"&&s+1<e.length)t+=e[s]+e[s+1],s+=2;else if(e[s]==="["){let n=pi(e,s);t+=n.converted,s=n.endIndex}else t+=e[s],s++;return t}function pi(e,t){let s=t+1,n="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(n+="^",s++);let r=!1;s<e.length&&e[s]==="]"&&(r=!0,s++);let i=!1;s<e.length&&e[s]==="["&&s+1<e.length&&e[s+1]!==":"&&(i=!0,s++);let o="",a=!1;for(;s<e.length;){let c=e[s];if(c==="]"){a=!0,s++;break}if(c==="["&&s+1<e.length&&e[s+1]===":"){let l=e.indexOf(":]",s+2);if(l!==-1){let u=e.slice(s+2,l);o+=mi(u),s=l+2;continue}}if(c==="["&&s+1<e.length){let l=e[s+1];if(l==="."||l==="="){let u=`${l}]`,f=e.indexOf(u,s+2);if(f!==-1){let d=e.slice(s+2,f);o+=d,s=f+2;continue}}}if(c==="\\"&&s+1<e.length){o+=c+e[s+1],s+=2;continue}o+=c,s++}return a?(r&&(n+="\\]"),i&&(n+="\\["),n+=o,n+="]",{converted:n,endIndex:s}):{converted:"\\[",endIndex:t+1}}function mi(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 ve(e){let t=[],s="",n=!1,r=!1,i=!1,o=!1;for(let a of e){if(i){s+=a,i=!1,o=!0;continue}if(a==="\\"){i=!0;continue}if(a==="'"&&!r){n||(o=!0),n=!n;continue}if(a==='"'&&!n){r||(o=!0),r=!r;continue}if((a===" "||a===" "||a===`
13
+ `,2):C("","",1)}if(t.length===3){let n=t[0],r=t[1],i=t[2];if(Ke(r))return U($t(r,n,i));if(Et(r)){let o=Pt(n),a=Pt(i);return!o.valid||!a.valid?C("","",2):U(St(r,o.value,a.value))}if(vt(r))return U(await bt(e,r,n,i));switch(r){case"-a":return U(n!==""&&i!=="");case"-o":return U(n!==""||i!=="");case">":return U(n>i);case"<":return U(n<i)}if(n==="!"){let o=await Xe(e,[r,i]);return C("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(n==="("&&i===")")return U(r!=="")}if(t.length===4){if(t[0]==="!"){let n=await Xe(e,t.slice(1));return C("",n.stderr,n.exitCode===0?1:n.exitCode===1?0:n.exitCode)}if(t[0]==="("&&t[3]===")")return Xe(e,[t[1],t[2]])}let s=await xn(e,t,0);return s.pos<t.length?A(`test: too many arguments
14
+ `,2):U(s.value)}async function xn(e,t,s){return ui(e,t,s)}async function ui(e,t,s){let{value:n,pos:r}=await kn(e,t,s);for(;t[r]==="-o";){let i=await kn(e,t,r+1);n=n||i.value,r=i.pos}return{value:n,pos:r}}async function kn(e,t,s){let{value:n,pos:r}=await rs(e,t,s);for(;t[r]==="-a";){let i=await rs(e,t,r+1);n=n&&i.value,r=i.pos}return{value:n,pos:r}}async function rs(e,t,s){if(t[s]==="!"){let{value:n,pos:r}=await rs(e,t,s+1);return{value:!n,pos:r}}return fi(e,t,s)}async function fi(e,t,s){let n=t[s];if(n==="("){let{value:i,pos:o}=await xn(e,t,s+1);return{value:i,pos:t[o]===")"?o+1:o}}let r=t[s+1];if(Ke(r)){let i=n,o=t[s+2]??"";return{value:$t(r,i,o),pos:s+3}}if(Et(r)){let i=Pt(n),o=Pt(t[s+2]??"0");return!i.valid||!o.valid?{value:!1,pos:s+3}:{value:St(r,i.value,o.value),pos:s+3}}if(vt(r)){let i=n,o=t[s+2]??"";return{value:await bt(e,r,i,o),pos:s+3}}if(gt(n)){let i=t[s+1]??"";return{value:await wt(e,n,i),pos:s+2}}if(At(n)){let i=t[s+1]??"";return{value:_t(n,i),pos:s+2}}if(n==="-v"){let i=t[s+1]??"";return{value:await Ct(e,i),pos:s+2}}if(n==="-o"){let i=t[s+1]??"";return{value:is(e,i),pos:s+2}}return{value:n!==void 0&&n!=="",pos:s+1}}function We(e,t,s=!1,n=!1){let r=`^${Dn(t,n)}$`;return Ze(r,s?"is":"s").test(e)}function Dn(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=Tn(e,n+1);if(i!==-1){let o=e.slice(n+2,i),a=In(o),c=a.map(u=>Dn(u,t)),l=c.length>0?c.join("|"):"(?:)";if(r==="@")s+=`(?:${l})`;else if(r==="*")s+=`(?:${l})*`;else if(r==="+")s+=`(?:${l})+`;else if(r==="?")s+=`(?:${l})?`;else if(r==="!")if(i<e.length-1){let f=a.map(h=>Rn(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 m=[];h>0&&m.push(`.{0,${h-1}}`),m.push(`.{${h+1},}`),m.push(`(?!(?:${l})).{${h}}`),s+=`(?:${m.join("|")})`}}else s+=`(?:(?!(?:${l})).)*?`}else s+=`(?!(?:${l})$).*`;n=i;continue}}if(r==="\\")if(n+1<e.length){let i=e[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,n++}else s+="\\\\";else if(r==="*")s+=".*";else if(r==="?")s+=".";else if(r==="["){let i=e.indexOf("]",n+1);i!==-1?(s+=e.slice(n,i+1),n=i):s+="\\["}else/[\\^$.|+(){}]/.test(r)?s+=`\\${r}`:s+=r}return s}function Tn(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 In(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 Rn(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=Tn(e,n+1);if(i!==-1){if(r==="@"){let o=e.slice(n+2,i),c=In(o).map(l=>Rn(l,t));if(c.every(l=>l!==null)&&c.every(l=>l===c[0])){s+=c[0],n=i+1;continue}return null}return null}}if(r==="*")return null;if(r==="?"){s+=1,n++;continue}if(r==="["){let i=e.indexOf("]",n+1);if(i!==-1){s+=1,n=i+1;continue}s+=1,n++;continue}if(r==="\\"){s+=1,n+=2;continue}s+=1,n++}return s}function is(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 Nn(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 On(t);try{let s=new W,n=q(s,t);return await z(e,n.expression)}catch{return On(t)}}function di(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 On(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=di(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 Pt(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 hi(e){let t="",s=0;for(;s<e.length;)if(e[s]==="\\"&&s+1<e.length)t+=e[s]+e[s+1],s+=2;else if(e[s]==="["){let n=pi(e,s);t+=n.converted,s=n.endIndex}else t+=e[s],s++;return t}function pi(e,t){let s=t+1,n="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(n+="^",s++);let r=!1;s<e.length&&e[s]==="]"&&(r=!0,s++);let i=!1;s<e.length&&e[s]==="["&&s+1<e.length&&e[s+1]!==":"&&(i=!0,s++);let o="",a=!1;for(;s<e.length;){let c=e[s];if(c==="]"){a=!0,s++;break}if(c==="["&&s+1<e.length&&e[s+1]===":"){let l=e.indexOf(":]",s+2);if(l!==-1){let u=e.slice(s+2,l);o+=mi(u),s=l+2;continue}}if(c==="["&&s+1<e.length){let l=e[s+1];if(l==="."||l==="="){let u=`${l}]`,f=e.indexOf(u,s+2);if(f!==-1){let d=e.slice(s+2,f);o+=d,s=f+2;continue}}}if(c==="\\"&&s+1<e.length){o+=c+e[s+1],s+=2;continue}o+=c,s++}return a?(r&&(n+="\\]"),i&&(n+="\\["),n+=o,n+="]",{converted:n,endIndex:s}):{converted:"\\[",endIndex:t+1}}function mi(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 ve(e){let t=[],s="",n=!1,r=!1,i=!1,o=!1;for(let a of e){if(i){s+=a,i=!1,o=!0;continue}if(a==="\\"){i=!0;continue}if(a==="'"&&!r){n||(o=!0),n=!n;continue}if(a==='"'&&!n){r||(o=!0),r=!r;continue}if((a===" "||a===" "||a===`
15
15
  `)&&!n&&!r){o&&(t.push(s),s="",o=!1);continue}s+=a,o=!0}return o&&t.push(s),t}function kt(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 Ln(e){let t=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(t)return{name:t[1],isArray:!0,arrayElements:ve(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 yi(e,t){try{let s=new W,n=q(s,t);return await z(e,n.expression)}catch{let s=parseInt(t,10);return Number.isNaN(s)?0:s}}async function Fn(e,t,s={}){let{name:n,isArray:r,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:c=!1,checkReadonly:l=!0}=s;if(l){let u=K(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(a!==void 0&&o!==void 0){let u=await yi(e,a);e.state.env.set(`${n}_${u}`,o);let f=parseInt(e.state.env.get(`${n}__length`)??"0",10);u>=f&&e.state.env.set(`${n}__length`,String(u+1))}else o!==void 0&&e.state.env.set(n,o);return c&&re(e,n),null}function Oe(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function Ve(e,t){return e.state.localVarDepth?.get(t)}function Nt(e,t){e.state.localVarDepth?.delete(t)}function Mn(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 Ot(e,t){let s=e.state.localVarStack?.get(t);if(!(!s||s.length===0))return s.pop()}function Wn(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 os=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function Vn(e){return os.has(e)}var as=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),ze=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);async function Te(e,t,s,n){try{if((await e.fs.stat(t)).isDirectory)return`bash: ${s}: Is a directory
16
16
  `;if(n.checkNoclobber&&e.state.options.noclobber&&!n.isClobber&&s!=="/dev/null")return`bash: ${s}: cannot overwrite existing file
17
- `}catch{}return null}function X(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return"utf8";return"binary"}function gi(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),o=r+n+1,a=t.slice(o),c=a.indexOf(":");if(c===-1)return null;let l=Number.parseInt(a.slice(0,c),10);if(Number.isNaN(l)||l<0)return null;let u=a.slice(c+1);return{path:i,position:l,content:u}}async function zn(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(Gt(e,r.target))return{targets:s,error:`bash: $@: ambiguous redirect
17
+ `}catch{}return null}function X(e){let s=Math.min(e.length,8192);for(let n=0;n<s;n++)if(e.charCodeAt(n)>255)return"utf8";return"binary"}function gi(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),o=r+n+1,a=t.slice(o),c=a.indexOf(":");if(c===-1)return null;let l=Number.parseInt(a.slice(0,c),10);if(Number.isNaN(l)||l<0)return null;let u=a.slice(c+1);return{path:i,position:l,content:u}}async function zn(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(Gt(e,r.target))return{targets:s,error:`bash: $@: ambiguous redirect
18
18
  `};s.set(n,await T(e,r.target))}else{let o=await pt(e,r.target);if("error"in o)return{targets:s,error:o.error};s.set(n,o.target)}}return{targets:s}}function wi(e){e.state.nextFd===void 0&&(e.state.nextFd=10);let t=e.state.nextFd;return e.state.nextFd++,t}async function xt(e,t){for(let s of t){if(!s.fdVariable)continue;if(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),(s.operator===">&"||s.operator==="<&")&&s.target.type==="Word"&&await T(e,s.target)==="-"){let i=e.state.env.get(s.fdVariable);if(i!==void 0){let o=Number.parseInt(i,10);Number.isNaN(o)||e.state.fileDescriptors.delete(o)}continue}let n=wi(e);if(e.state.env.set(s.fdVariable,String(n)),s.target.type==="Word"){let r=await T(e,s.target);if(s.operator===">&"||s.operator==="<&"){let i=Number.parseInt(r,10);if(!Number.isNaN(i)){let o=e.state.fileDescriptors.get(i);o!==void 0&&e.state.fileDescriptors.set(n,o);continue}}if(s.operator===">"||s.operator===">>"||s.operator===">|"||s.operator==="&>"||s.operator==="&>>"){let i=e.fs.resolvePath(e.state.cwd,r);(s.operator===">"||s.operator===">|"||s.operator==="&>")&&await e.fs.writeFile(i,"","binary"),e.state.fileDescriptors.set(n,`__file__:${i}`)}else if(s.operator==="<<<")e.state.fileDescriptors.set(n,`${r}
19
19
  `);else if(s.operator==="<"||s.operator==="<>")try{let i=e.fs.resolvePath(e.state.cwd,r),o=await e.fs.readFile(i);e.state.fileDescriptors.set(n,o)}catch{return C("",`bash: ${r}: No such file or directory
20
20
  `,1)}}}return null}async function be(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 T(e,s.target),r==="-"||!Number.isNaN(Number.parseInt(r,10))||s.fd!=null)continue}else{let a=await pt(e,s.target);if("error"in a)return C("",a.error,1);r=a.target}let i=e.fs.resolvePath(e.state.cwd,r),o=s.operator===">|";if(i.includes("\0"))return C("",`bash: ${r}: No such file or directory
@@ -28,7 +28,7 @@ import{B as ln,C as cn,D as re,E as De,F as K,G as me,H as ht,I as un,J as T,K a
28
28
  `,o=1;break}if(f==="/dev/null")i="";else{let p=e.fs.resolvePath(e.state.cwd,f),g=await Te(e,p,f,{checkNoclobber:!0,isClobber:m});if(g){i+=g,o=1;break}await e.fs.writeFile(p,i,X(i)),i=""}}break}case">>":{let h=u.fd??1;if(h===1){if(f==="/dev/stdout")break;if(f==="/dev/stderr"){i+=r,r="";break}if(f==="/dev/full"){i+=`bash: echo: write error: No space left on device
29
29
  `,o=1,r="";break}let m=e.fs.resolvePath(e.state.cwd,f),p=await Te(e,m,f,{});if(p){i+=p,o=1,r="";break}await e.fs.appendFile(m,r,X(r)),r=""}else if(h===2){if(f==="/dev/stderr")break;if(f==="/dev/stdout"){r+=i,i="";break}if(f==="/dev/full"){i+=`bash: echo: write error: No space left on device
30
30
  `,o=1;break}let m=e.fs.resolvePath(e.state.cwd,f),p=await Te(e,m,f,{});if(p){i+=p,o=1;break}await e.fs.appendFile(m,i,X(i)),i=""}break}case">&":case"<&":{let h=u.fd??1;if(f==="-")break;if(f.endsWith("-")){let m=f.slice(0,-1),p=Number.parseInt(m,10);if(!Number.isNaN(p)){let g=e.state.fileDescriptors?.get(p);g!==void 0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,g),p>=3&&e.state.fileDescriptors?.delete(p)):p===1||p===2?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,`__dupout__:${p}`)):p===0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(h,`__dupin__:${p}`)):p>=3&&(i+=`bash: ${p}: Bad file descriptor
31
- `,o=1)}break}if(f==="2"||f==="&2")h===1&&(i+=r,r="");else if(f==="1"||f==="&1")r+=i,i="";else{let m=Number.parseInt(f,10);if(Number.isNaN(m)){if(u.operator===">&"){let p=e.fs.resolvePath(e.state.cwd,f),g=await Te(e,p,f,{checkNoclobber:!0});if(g){i=g,o=1,r="";break}if(u.fd==null){let S=r+i;await e.fs.writeFile(p,S,X(S)),r="",i=""}else h===1?(await e.fs.writeFile(p,r,X(r)),r=""):h===2&&(await e.fs.writeFile(p,i,X(i)),i="")}}else{let p=e.state.fileDescriptors?.get(m);if(p?.startsWith("__file__:")){let g=p.slice(9);h===1?(await e.fs.appendFile(g,r,X(r)),r=""):h===2&&(await e.fs.appendFile(g,i,X(i)),i="")}else if(p?.startsWith("__rw__:")){let g=gi(p);g&&(h===1?(await e.fs.appendFile(g.path,r,X(r)),r=""):h===2&&(await e.fs.appendFile(g.path,i,X(i)),i=""))}else if(p?.startsWith("__dupout__:")){let g=Number.parseInt(p.slice(11),10);if(g!==1)if(g===2)h===1&&(i+=r,r="");else{let S=e.state.fileDescriptors?.get(g);if(S?.startsWith("__file__:")){let v=S.slice(9);h===1?(await e.fs.appendFile(v,r,X(r)),r=""):h===2&&(await e.fs.appendFile(v,i,X(i)),i="")}}}else p?.startsWith("__dupin__:")?(i+=`bash: ${m}: Bad file descriptor
31
+ `,o=1)}break}if(f==="2"||f==="&2")h===1&&(i+=r,r="");else if(f==="1"||f==="&1")r+=i,i="";else{let m=Number.parseInt(f,10);if(Number.isNaN(m)){if(u.operator===">&"){let p=e.fs.resolvePath(e.state.cwd,f),g=await Te(e,p,f,{checkNoclobber:!0});if(g){i=g,o=1,r="";break}if(u.fd==null){let $=r+i;await e.fs.writeFile(p,$,X($)),r="",i=""}else h===1?(await e.fs.writeFile(p,r,X(r)),r=""):h===2&&(await e.fs.writeFile(p,i,X(i)),i="")}}else{let p=e.state.fileDescriptors?.get(m);if(p?.startsWith("__file__:")){let g=p.slice(9);h===1?(await e.fs.appendFile(g,r,X(r)),r=""):h===2&&(await e.fs.appendFile(g,i,X(i)),i="")}else if(p?.startsWith("__rw__:")){let g=gi(p);g&&(h===1?(await e.fs.appendFile(g.path,r,X(r)),r=""):h===2&&(await e.fs.appendFile(g.path,i,X(i)),i=""))}else if(p?.startsWith("__dupout__:")){let g=Number.parseInt(p.slice(11),10);if(g!==1)if(g===2)h===1&&(i+=r,r="");else{let $=e.state.fileDescriptors?.get(g);if($?.startsWith("__file__:")){let v=$.slice(9);h===1?(await e.fs.appendFile(v,r,X(r)),r=""):h===2&&(await e.fs.appendFile(v,i,X(i)),i="")}}}else p?.startsWith("__dupin__:")?(i+=`bash: ${m}: Bad file descriptor
32
32
  `,o=1,r=""):m>=3&&(i+=`bash: ${m}: Bad file descriptor
33
33
  `,o=1,r="")}}break}case"&>":{if(f==="/dev/full"){i=`bash: echo: write error: No space left on device
34
34
  `,o=1,r="";break}let h=e.fs.resolvePath(e.state.cwd,f),m=await Te(e,h,f,{checkNoclobber:!0});if(m){i=m,o=1,r="";break}let p=r+i;await e.fs.writeFile(h,p,X(p)),r="",i="";break}case"&>>":{if(f==="/dev/full"){i=`bash: echo: write error: No space left on device
@@ -36,7 +36,7 @@ import{B as ln,C as cn,D as re,E as De,F as K,G as me,H as ht,I as un,J as T,K a
36
36
  `;throw new V(2,"",n)}let s={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,s),L}async function vi(e,t){let s="";for(let n of t)if((n.operator==="<<"||n.operator==="<<-")&&n.target.type==="HereDoc"){let r=n.target,i=await T(e,r.content);r.stripTabs&&(i=i.split(`
37
37
  `).map(a=>a.replace(/^\t+/,"")).join(`
38
38
  `)),(n.fd??0)===0&&(s=i)}else if(n.operator==="<<<"&&n.target.type==="Word")s=`${await T(e,n.target)}
39
- `;else if(n.operator==="<"&&n.target.type==="Word"){let r=await T(e,n.target),i=e.fs.resolvePath(e.state.cwd,r);try{s=await e.fs.readFile(i)}catch{}}return s}async function Dt(e,t,s,n="",r){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,Se(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(r??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i=new Map;for(let l=0;l<s.length;l++)i.set(String(l+1),e.state.env.get(String(l+1))),e.state.env.set(String(l+1),s[l]);i.set("@",e.state.env.get("@")),i.set("#",e.state.env.get("#")),e.state.env.set("@",s.join(" ")),e.state.env.set("#",String(s.length));let o=()=>{let l=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(Wn(e,l),e.state.fullyUnsetLocals)for(let[f,d]of e.state.fullyUnsetLocals.entries())d===l&&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:a,error:c}=await zn(e,t.redirections);if(c)return o(),C("",c,1);try{let l=await vi(e,t.redirections),u=n||l,f=await e.executeCommand(t.body,u);return o(),B(e,f,t.redirections,a)}catch(l){if(o(),l instanceof ne){let u=C(l.stdout,l.stderr,l.exitCode);return B(e,u,t.redirections,a)}throw l}}var Hn=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],cs=[".",":","[","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"],bi=["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"],Ei=cs;async function us(e,t){let s=[],n=null,r="",i="",o=null,a=!1,c=!1,l=!1,u=null,f=null,d=null,h=[],m=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let y=0;y<t.length;y++){let w=t[y];if(w==="-v")s.push("variable");else if(w==="-e")s.push("export");else if(w==="-f")s.push("file");else if(w==="-d")s.push("directory");else if(w==="-k")s.push("keyword");else if(w==="-A"){if(y++,y>=t.length)return A(`compgen: -A: option requires an argument
39
+ `;else if(n.operator==="<"&&n.target.type==="Word"){let r=await T(e,n.target),i=e.fs.resolvePath(e.state.cwd,r);try{s=await e.fs.readFile(i)}catch{}}return s}async function Dt(e,t,s,n="",r){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,$e(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(r??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let i=new Map;for(let l=0;l<s.length;l++)i.set(String(l+1),e.state.env.get(String(l+1))),e.state.env.set(String(l+1),s[l]);i.set("@",e.state.env.get("@")),i.set("#",e.state.env.get("#")),e.state.env.set("@",s.join(" ")),e.state.env.set("#",String(s.length));let o=()=>{let l=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(Wn(e,l),e.state.fullyUnsetLocals)for(let[f,d]of e.state.fullyUnsetLocals.entries())d===l&&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:a,error:c}=await zn(e,t.redirections);if(c)return o(),C("",c,1);try{let l=await vi(e,t.redirections),u=n||l,f=await e.executeCommand(t.body,u);return o(),B(e,f,t.redirections,a)}catch(l){if(o(),l instanceof ne){let u=C(l.stdout,l.stderr,l.exitCode);return B(e,u,t.redirections,a)}throw l}}var Hn=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],cs=[".",":","[","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"],bi=["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"],Ei=cs;async function us(e,t){let s=[],n=null,r="",i="",o=null,a=!1,c=!1,l=!1,u=null,f=null,d=null,h=[],m=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let y=0;y<t.length;y++){let w=t[y];if(w==="-v")s.push("variable");else if(w==="-e")s.push("export");else if(w==="-f")s.push("file");else if(w==="-d")s.push("directory");else if(w==="-k")s.push("keyword");else if(w==="-A"){if(y++,y>=t.length)return A(`compgen: -A: option requires an argument
40
40
  `,2);let b=t[y];if(!m.includes(b))return A(`compgen: ${b}: invalid action name
41
41
  `,2);s.push(b)}else if(w==="-W"){if(y++,y>=t.length)return A(`compgen: -W: option requires an argument
42
42
  `,2);n=t[y]}else if(w==="-P"){if(y++,y>=t.length)return A(`compgen: -P: option requires an argument
@@ -47,11 +47,11 @@ import{B as ln,C as cn,D as re,E as De,F as K,G as me,H as ht,I as un,J as T,K a
47
47
  `,2);f=t[y]}else if(w==="-C"){if(y++,y>=t.length)return A(`compgen: -C: option requires an argument
48
48
  `,2);d=t[y]}else if(w==="-X"){if(y++,y>=t.length)return A(`compgen: -X: option requires an argument
49
49
  `,2);u=t[y]}else if(w==="-G"){if(y++,y>=t.length)return A(`compgen: -G: option requires an argument
50
- `,2)}else if(w==="--"){h.push(...t.slice(y+1));break}else w.startsWith("-")||h.push(w)}o=h[0]??null;let p=[];if(c){let y=await ls(e,o);p.push(...y)}if(l){let y=await jn(e,o);p.push(...y)}for(let y of s)if(y==="variable"){let w=$i(e,o);p.push(...w)}else if(y==="export"){let w=Si(e,o);p.push(...w)}else if(y==="function"){let w=Ai(e,o);p.push(...w)}else if(y==="builtin"){let w=_i(o);p.push(...w)}else if(y==="keyword"){let w=Ci(o);p.push(...w)}else if(y==="alias"){let w=Pi(e,o);p.push(...w)}else if(y==="shopt"){let w=ki(o);p.push(...w)}else if(y==="helptopic"){let w=Ni(o);p.push(...w)}else if(y==="directory"){let w=await ls(e,o);p.push(...w)}else if(y==="file"){let w=await jn(e,o);p.push(...w)}else if(y==="user"){let w=Oi(o);p.push(...w)}else if(y==="command"){let w=await xi(e,o);p.push(...w)}if(n!==null)try{let y=await Di(e,n),w=Ti(e,y);for(let b of w)(o===null||b.startsWith(o))&&p.push(b)}catch{return C("","",1)}if(a){let y=await ls(e,o);for(let w of y)p.includes(w)||p.push(w)}let g="";if(f!==null){let y=e.state.functions.get(f);if(y){let w=new Map;w.set("COMP_WORDS__length",e.state.env.get("COMP_WORDS__length")),e.state.env.set("COMP_WORDS__length","0"),w.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),w.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),w.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let b=new Map;for(let D of e.state.env.keys())(D==="COMPREPLY"||D.startsWith("COMPREPLY_")||D==="COMPREPLY__length")&&(b.set(D,e.state.env.get(D)),e.state.env.delete(D));let E=["compgen",h[0]??"",""];try{let D=await Dt(e,y,E,"");if(D.exitCode!==0)return Be(e,w),Be(e,b),C("",D.stderr,1);g=D.stdout;let N=Ii(e);p.push(...N)}catch{return Be(e,w),Be(e,b),C("","",1)}Be(e,w),Be(e,b)}}if(d!==null)try{let y=ye(d),w=await e.executeScript(y);if(w.exitCode!==0)return C("",w.stderr,w.exitCode);if(w.stdout){let b=w.stdout.split(`
50
+ `,2)}else if(w==="--"){h.push(...t.slice(y+1));break}else w.startsWith("-")||h.push(w)}o=h[0]??null;let p=[];if(c){let y=await ls(e,o);p.push(...y)}if(l){let y=await jn(e,o);p.push(...y)}for(let y of s)if(y==="variable"){let w=Si(e,o);p.push(...w)}else if(y==="export"){let w=$i(e,o);p.push(...w)}else if(y==="function"){let w=Ai(e,o);p.push(...w)}else if(y==="builtin"){let w=_i(o);p.push(...w)}else if(y==="keyword"){let w=Ci(o);p.push(...w)}else if(y==="alias"){let w=Pi(e,o);p.push(...w)}else if(y==="shopt"){let w=ki(o);p.push(...w)}else if(y==="helptopic"){let w=Ni(o);p.push(...w)}else if(y==="directory"){let w=await ls(e,o);p.push(...w)}else if(y==="file"){let w=await jn(e,o);p.push(...w)}else if(y==="user"){let w=Oi(o);p.push(...w)}else if(y==="command"){let w=await xi(e,o);p.push(...w)}if(n!==null)try{let y=await Di(e,n),w=Ti(e,y);for(let b of w)(o===null||b.startsWith(o))&&p.push(b)}catch{return C("","",1)}if(a){let y=await ls(e,o);for(let w of y)p.includes(w)||p.push(w)}let g="";if(f!==null){let y=e.state.functions.get(f);if(y){let w=new Map;w.set("COMP_WORDS__length",e.state.env.get("COMP_WORDS__length")),e.state.env.set("COMP_WORDS__length","0"),w.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),w.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),w.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let b=new Map;for(let D of e.state.env.keys())(D==="COMPREPLY"||D.startsWith("COMPREPLY_")||D==="COMPREPLY__length")&&(b.set(D,e.state.env.get(D)),e.state.env.delete(D));let E=["compgen",h[0]??"",""];try{let D=await Dt(e,y,E,"");if(D.exitCode!==0)return Be(e,w),Be(e,b),C("",D.stderr,1);g=D.stdout;let N=Ii(e);p.push(...N)}catch{return Be(e,w),Be(e,b),C("","",1)}Be(e,w),Be(e,b)}}if(d!==null)try{let y=ye(d),w=await e.executeScript(y);if(w.exitCode!==0)return C("",w.stderr,w.exitCode);if(w.stdout){let b=w.stdout.split(`
51
51
  `);for(let E of b)E.length>0&&p.push(E)}}catch(y){if(y.name==="ParseException")return A(`compgen: -C: ${y.message}
52
- `,2);throw y}let S=p;if(u!==null){let y=u.startsWith("!"),w=y?u.slice(1):u;S=p.filter(b=>{let E=We(b,w,!1,!0);return y?E:!E})}if(S.length===0&&o!==null)return C(g,"",1);let v=S.map(y=>`${r}${y}${i}`).join(`
52
+ `,2);throw y}let $=p;if(u!==null){let y=u.startsWith("!"),w=y?u.slice(1):u;$=p.filter(b=>{let E=We(b,w,!1,!0);return y?E:!E})}if($.length===0&&o!==null)return C(g,"",1);let v=$.map(y=>`${r}${y}${i}`).join(`
53
53
  `),P=g+(v?`${v}
54
- `:"");return F(P)}function $i(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 Si(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 Ai(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(n=>n.startsWith(t))),s.sort()}function _i(e){let t=[...cs];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Ci(e){let t=[...Hn];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Pi(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 ki(e){let t=[...bi];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Ni(e){let t=[...Ei];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function ls(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let o=t.lastIndexOf("/");if(o!==-1){let a=t.slice(0,o)||"/";r=t.slice(o+1),a.startsWith("/")?n=a:n=`${e.state.cwd}/${a}`}}let i=await e.fs.readdir(n);for(let o of i){let a=`${n}/${o}`;try{if((await e.fs.stat(a)).isDirectory&&(!r||o.startsWith(r)))if(t?.includes("/")){let l=t.lastIndexOf("/"),u=t.slice(0,l+1);s.push(u+o)}else s.push(o)}catch{}}}catch{}return s.sort()}async function jn(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let o=t.lastIndexOf("/");if(o!==-1){let a=t.slice(0,o)||"/";r=t.slice(o+1),a.startsWith("/")?n=a:n=`${e.state.cwd}/${a}`}}let i=await e.fs.readdir(n);for(let o of i)if(!r||o.startsWith(r))if(t?.includes("/")){let a=t.lastIndexOf("/"),c=t.slice(0,a+1);s.push(c+o)}else s.push(o)}catch{}return s.sort()}function Oi(e){return["root","nobody"]}async function xi(e,t){let s=new Set;for(let i of cs)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 Hn)s.add(i);let n=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of n.split(":"))if(i)try{let o=await e.fs.readdir(i);for(let a of o)s.add(a)}catch{}let r=Array.from(s);return t!==null&&(r=r.filter(i=>i.startsWith(t))),r.sort()}async function Di(e,t){let n=new W().parseWordFromString(t,!1,!1);return await T(e,n)}function Ti(e,t){let s=e.state.env.get("IFS")??`
54
+ `:"");return F(P)}function Si(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 $i(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 Ai(e,t){let s=Array.from(e.state.functions.keys());return t!==null&&(s=s.filter(n=>n.startsWith(t))),s.sort()}function _i(e){let t=[...cs];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Ci(e){let t=[...Hn];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Pi(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 ki(e){let t=[...bi];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}function Ni(e){let t=[...Ei];return e!==null&&(t=t.filter(s=>s.startsWith(e))),t.sort()}async function ls(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let o=t.lastIndexOf("/");if(o!==-1){let a=t.slice(0,o)||"/";r=t.slice(o+1),a.startsWith("/")?n=a:n=`${e.state.cwd}/${a}`}}let i=await e.fs.readdir(n);for(let o of i){let a=`${n}/${o}`;try{if((await e.fs.stat(a)).isDirectory&&(!r||o.startsWith(r)))if(t?.includes("/")){let l=t.lastIndexOf("/"),u=t.slice(0,l+1);s.push(u+o)}else s.push(o)}catch{}}}catch{}return s.sort()}async function jn(e,t){let s=[];try{let n=e.state.cwd,r=t??"";if(t){let o=t.lastIndexOf("/");if(o!==-1){let a=t.slice(0,o)||"/";r=t.slice(o+1),a.startsWith("/")?n=a:n=`${e.state.cwd}/${a}`}}let i=await e.fs.readdir(n);for(let o of i)if(!r||o.startsWith(r))if(t?.includes("/")){let a=t.lastIndexOf("/"),c=t.slice(0,a+1);s.push(c+o)}else s.push(o)}catch{}return s.sort()}function Oi(e){return["root","nobody"]}async function xi(e,t){let s=new Set;for(let i of cs)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 Hn)s.add(i);let n=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of n.split(":"))if(i)try{let o=await e.fs.readdir(i);for(let a of o)s.add(a)}catch{}let r=Array.from(s);return t!==null&&(r=r.filter(i=>i.startsWith(t))),r.sort()}async function Di(e,t){let n=new W().parseWordFromString(t,!1,!1);return await T(e,n)}function Ti(e,t){let s=e.state.env.get("IFS")??`
55
55
  `;if(s.length===0)return[t];let n=new Set(s.split("")),r=[],i="",o=0;for(;o<t.length;){let a=t[o];if(a==="\\"&&o+1<t.length){let c=t[o+1];i+=c,o+=2}else n.has(a)?(i.length>0&&(r.push(i),i=""),o++):(i+=a,o++)}return i.length>0&&r.push(i),r}function Be(e,t){for(let[s,n]of t)n===void 0?e.state.env.delete(s):e.state.env.set(s,n)}function Ii(e){let t=[];if(e.state.env.get("COMPREPLY__length")!==void 0){let r=pe(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 Ri=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function ds(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let s=!1,n=!1,r=!1,i,o,a,c=[],l=[],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 A(`complete: -W: option requires an argument
56
56
  `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return A(`complete: -F: option requires an argument
57
57
  `,2);o=t[f]}else if(d==="-o"){if(f++,f>=t.length)return A(`complete: -o: option requires an argument
@@ -83,9 +83,9 @@ import{B as ln,C as cn,D as re,E as De,F as K,G as me,H as ht,I as un,J as T,K a
83
83
  `;continue}let l=e.state.env.get(i);if(l!==void 0)s+=`declare ${o} ${i}=${gs(l)}
84
84
  `;else{let u=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);u||f?s+=`declare ${o} ${i}
85
85
  `:(n+=`bash: declare: ${i}: not found
86
- `,r=!0)}}return C(s,n,r?1:0)}function Gn(e,t){let{filterExport:s,filterReadonly:n,filterNameref:r,filterIndexedArray:i,filterAssocArray:o}=t,a=s||n||r||i||o,c="",l=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);l.add(h);continue}let d=f.lastIndexOf("_");if(d>0){let h=f.slice(0,d),m=f.slice(d+1);if(/^\d+$/.test(m)||e.state.associativeArrays?.has(h)){l.add(h);continue}}l.add(f)}if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())l.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)l.add(f);let u=Array.from(l).sort();for(let f of u){let d=qn(e,f),h=e.state.associativeArrays?.has(f),m=Y(e,f),p=!h&&(m.length>0||e.state.env.has(`${f}__length`));if(a&&(o&&!h||i&&!p||s&&!e.state.exportedVars?.has(f)||n&&!e.state.readonlyVars?.has(f)||r&&!fe(e,f)))continue;if(h){let S=Ce(e,f);if(S.length===0)c+=`declare -A ${f}=()
87
- `;else{let v=S.map(P=>{let y=e.state.env.get(`${f}_${P}`)??"",w=ws(y);return`['${P}']=${w}`});c+=`declare -A ${f}=(${v.join(" ")})
88
- `}continue}if(m.length>0){let S=m.map(v=>{let P=e.state.env.get(`${f}_${v}`)??"";return`[${v}]=${Ie(P)}`});c+=`declare -a ${f}=(${S.join(" ")})
86
+ `,r=!0)}}return C(s,n,r?1:0)}function Gn(e,t){let{filterExport:s,filterReadonly:n,filterNameref:r,filterIndexedArray:i,filterAssocArray:o}=t,a=s||n||r||i||o,c="",l=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);l.add(h);continue}let d=f.lastIndexOf("_");if(d>0){let h=f.slice(0,d),m=f.slice(d+1);if(/^\d+$/.test(m)||e.state.associativeArrays?.has(h)){l.add(h);continue}}l.add(f)}if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())l.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)l.add(f);let u=Array.from(l).sort();for(let f of u){let d=qn(e,f),h=e.state.associativeArrays?.has(f),m=Y(e,f),p=!h&&(m.length>0||e.state.env.has(`${f}__length`));if(a&&(o&&!h||i&&!p||s&&!e.state.exportedVars?.has(f)||n&&!e.state.readonlyVars?.has(f)||r&&!fe(e,f)))continue;if(h){let $=Ce(e,f);if($.length===0)c+=`declare -A ${f}=()
87
+ `;else{let v=$.map(P=>{let y=e.state.env.get(`${f}_${P}`)??"",w=ws(y);return`['${P}']=${w}`});c+=`declare -A ${f}=(${v.join(" ")})
88
+ `}continue}if(m.length>0){let $=m.map(v=>{let P=e.state.env.get(`${f}_${v}`)??"";return`[${v}]=${Ie(P)}`});c+=`declare -a ${f}=(${$.join(" ")})
89
89
  `;continue}if(e.state.env.has(`${f}__length`)){c+=`declare -a ${f}=()
90
90
  `;continue}let g=e.state.env.get(f);g!==void 0&&(c+=`declare ${d} ${f}=${gs(g)}
91
91
  `)}return F(c)}function Kn(e){let t="",s=Array.from(e.state.associativeArrays??[]).sort();for(let n of s){let r=Ce(e,n);if(r.length===0)t+=`declare -A ${n}=()
@@ -93,22 +93,22 @@ import{B as ln,C as cn,D as re,E as De,F as K,G as me,H as ht,I as un,J as T,K a
93
93
  `}}return F(t)}function Xn(e){let t="",s=new Set;for(let r of e.state.env.keys()){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let o=r.slice(0,-8);e.state.associativeArrays?.has(o)||s.add(o);continue}let i=r.lastIndexOf("_");if(i>0){let o=r.slice(0,i),a=r.slice(i+1);/^\d+$/.test(a)&&(e.state.associativeArrays?.has(o)||s.add(o))}}let n=Array.from(s).sort();for(let r of n){let i=Y(e,r);if(i.length===0)t+=`declare -a ${r}=()
94
94
  `;else{let o=i.map(a=>{let c=e.state.env.get(`${r}_${a}`)??"";return`[${a}]=${Ie(c)}`});t+=`declare -a ${r}=(${o.join(" ")})
95
95
  `}}return F(t)}function Yn(e){let t="",s=new Set;for(let r of e.state.env.keys()){if(r.startsWith("BASH_"))continue;if(r.endsWith("__length")){let o=r.slice(0,-8);s.add(o);continue}let i=r.lastIndexOf("_");if(i>0){let o=r.slice(0,i),a=r.slice(i+1);if(/^\d+$/.test(a)||e.state.associativeArrays?.has(o)){s.add(o);continue}}s.add(r)}let n=Array.from(s).sort();for(let r of n){if(e.state.associativeArrays?.has(r)||Y(e,r).length>0||e.state.env.has(`${r}__length`))continue;let a=e.state.env.get(r);a!==void 0&&(t+=`${r}=${Tt(a)}
96
- `)}return F(t)}function vs(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function Ye(e,t){return e.state.integerVars?.has(t)??!1}function bs(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Li(e,t){return e.state.lowercaseVars?.has(t)??!1}function Es(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Fi(e,t){return e.state.uppercaseVars?.has(t)??!1}function je(e,t,s){return Li(e,t)?s.toLowerCase():Fi(e,t)?s.toUpperCase():s}async function Qn(e,t){try{let s=new W,n=q(s,t),r=await z(e,n.expression);return String(r)}catch{return"0"}}function Mi(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let s=t[0],n=s.length;if(e[n]!=="[")return null;let r=0,i=n+1;for(;n<e.length;n++)if(e[n]==="[")r++;else if(e[n]==="]"&&(r--,r===0))break;if(r!==0)return null;let o=e.slice(i,n);if(n++,e[n]!=="=")return null;n++;let a=e.slice(n);return{name:s,indexExpr:o,value:a}}async function $s(e,t){let s=!1,n=!1,r=!1,i=!1,o=!1,a=!1,c=!1,l=!1,u=!1,f=!1,d=!1,h=!1,m=!1,p=!1,g=!1,S=[];for(let N=0;N<t.length;N++){let I=t[N];if(I==="-a")s=!0;else if(I==="-A")n=!0;else if(I==="-r")r=!0;else if(I==="-x")i=!0;else if(I==="-p")o=!0;else if(I==="-n")a=!0;else if(I==="+n")c=!0;else if(I==="+a")l=!0;else if(I==="+x")u=!0;else if(I==="--"){S.push(...t.slice(N+1));break}else if(I.startsWith("+")){for(let _ of I.slice(1))if(_==="n")c=!0;else if(_==="a")l=!0;else if(_==="x")u=!0;else if(_!=="r"){if(_!=="i"){if(!(_==="f"||_==="F"))return C("",`bash: typeset: +${_}: invalid option
96
+ `)}return F(t)}function vs(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function Ye(e,t){return e.state.integerVars?.has(t)??!1}function bs(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Li(e,t){return e.state.lowercaseVars?.has(t)??!1}function Es(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Fi(e,t){return e.state.uppercaseVars?.has(t)??!1}function je(e,t,s){return Li(e,t)?s.toLowerCase():Fi(e,t)?s.toUpperCase():s}async function Qn(e,t){try{let s=new W,n=q(s,t),r=await z(e,n.expression);return String(r)}catch{return"0"}}function Mi(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let s=t[0],n=s.length;if(e[n]!=="[")return null;let r=0,i=n+1;for(;n<e.length;n++)if(e[n]==="[")r++;else if(e[n]==="]"&&(r--,r===0))break;if(r!==0)return null;let o=e.slice(i,n);if(n++,e[n]!=="=")return null;n++;let a=e.slice(n);return{name:s,indexExpr:o,value:a}}async function Ss(e,t){let s=!1,n=!1,r=!1,i=!1,o=!1,a=!1,c=!1,l=!1,u=!1,f=!1,d=!1,h=!1,m=!1,p=!1,g=!1,$=[];for(let N=0;N<t.length;N++){let I=t[N];if(I==="-a")s=!0;else if(I==="-A")n=!0;else if(I==="-r")r=!0;else if(I==="-x")i=!0;else if(I==="-p")o=!0;else if(I==="-n")a=!0;else if(I==="+n")c=!0;else if(I==="+a")l=!0;else if(I==="+x")u=!0;else if(I==="--"){$.push(...t.slice(N+1));break}else if(I.startsWith("+")){for(let _ of I.slice(1))if(_==="n")c=!0;else if(_==="a")l=!0;else if(_==="x")u=!0;else if(_!=="r"){if(_!=="i"){if(!(_==="f"||_==="F"))return C("",`bash: typeset: +${_}: invalid option
97
97
  `,2)}}}else if(I==="-i")f=!0;else if(I==="-l")d=!0;else if(I==="-u")h=!0;else if(I==="-f")m=!0;else if(I==="-F")p=!0;else if(I==="-g")g=!0;else if(I.startsWith("-"))for(let _ of I.slice(1))if(_==="a")s=!0;else if(_==="A")n=!0;else if(_==="r")r=!0;else if(_==="x")i=!0;else if(_==="p")o=!0;else if(_==="n")a=!0;else if(_==="i")f=!0;else if(_==="l")d=!0;else if(_==="u")h=!0;else if(_==="f")m=!0;else if(_==="F")p=!0;else if(_==="g")g=!0;else return C("",`bash: typeset: -${_}: invalid option
98
- `,2);else S.push(I)}let P=e.state.localScopes.length>0&&!g,y=N=>{if(!P)return;let I=e.state.localScopes[e.state.localScopes.length-1];I.has(N)||I.set(N,e.state.env.get(N))},w=N=>{if(!P)return;let I=e.state.localScopes[e.state.localScopes.length-1];I.has(N)||I.set(N,e.state.env.get(N));let _=`${N}_`;for(let O of e.state.env.keys())O.startsWith(_)&&!O.includes("__")&&(I.has(O)||I.set(O,e.state.env.get(O)));let k=`${N}__length`;e.state.env.has(k)&&!I.has(k)&&I.set(k,e.state.env.get(k))},b=N=>{P&&Oe(e,N)};if(p){if(S.length===0){let _=Array.from(e.state.functions.keys()).sort(),k="";for(let O of _)k+=`declare -f ${O}
99
- `;return F(k)}let N=!0,I="";for(let _ of S)e.state.functions.has(_)?I+=`${_}
100
- `:N=!1;return C(I,"",N?0:1)}if(m){if(S.length===0){let I="",_=Array.from(e.state.functions.keys()).sort();for(let k of _)I+=`${k} ()
98
+ `,2);else $.push(I)}let P=e.state.localScopes.length>0&&!g,y=N=>{if(!P)return;let I=e.state.localScopes[e.state.localScopes.length-1];I.has(N)||I.set(N,e.state.env.get(N))},w=N=>{if(!P)return;let I=e.state.localScopes[e.state.localScopes.length-1];I.has(N)||I.set(N,e.state.env.get(N));let _=`${N}_`;for(let O of e.state.env.keys())O.startsWith(_)&&!O.includes("__")&&(I.has(O)||I.set(O,e.state.env.get(O)));let k=`${N}__length`;e.state.env.has(k)&&!I.has(k)&&I.set(k,e.state.env.get(k))},b=N=>{P&&Oe(e,N)};if(p){if($.length===0){let _=Array.from(e.state.functions.keys()).sort(),k="";for(let O of _)k+=`declare -f ${O}
99
+ `;return F(k)}let N=!0,I="";for(let _ of $)e.state.functions.has(_)?I+=`${_}
100
+ `:N=!1;return C(I,"",N?0:1)}if(m){if($.length===0){let I="",_=Array.from(e.state.functions.keys()).sort();for(let k of _)I+=`${k} ()
101
101
  {
102
102
  # function body
103
103
  }
104
- `;return F(I)}let N=!0;for(let I of S)e.state.functions.has(I)||(N=!1);return C("","",N?0:1)}if(o&&S.length>0)return Zn(e,S);if(o&&S.length===0)return Gn(e,{filterExport:i,filterReadonly:r,filterNameref:a,filterIndexedArray:s,filterAssocArray:n});if(S.length===0&&n&&!o)return Kn(e);if(S.length===0&&s&&!o)return Xn(e);if(S.length===0&&!o)return Yn(e);let E="",D=0;for(let N of S){let I=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(I&&!l){let $=I[1],x=I[2];if(n&&Y(e,$).length>0){E+=`bash: declare: ${$}: cannot convert indexed to associative array
105
- `,D=1;continue}if((s||!n&&!s)&&e.state.associativeArrays?.has($)){E+=`bash: declare: ${$}: cannot convert associative to indexed array
106
- `,D=1;continue}if(w($),n&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add($)),ge(e,$),e.state.env.delete($),e.state.env.delete(`${$}__length`),n&&x.includes("[")){let R=kt(x);for(let[G,M]of R){let H=j(e,M);e.state.env.set(`${$}_${G}`,H)}}else if(n){let R=ve(x);for(let G=0;G<R.length;G+=2){let M=R[G],H=G+1<R.length?j(e,R[G+1]):"";e.state.env.set(`${$}_${M}`,H)}}else{let R=ve(x);if(R.some(M=>/^\[[^\]]+\]=/.test(M))){let M=0;for(let H of R){let J=H.match(/^\[([^\]]+)\]=(.*)$/);if(J){let ae=J[1],Re=J[2],Hr=j(e,Re),qe;if(/^-?\d+$/.test(ae))qe=Number.parseInt(ae,10);else try{let Ur=new W,qr=q(Ur,ae);qe=await z(e,qr.expression)}catch{qe=0}e.state.env.set(`${$}_${qe}`,Hr),M=qe+1}else{let ae=j(e,H);e.state.env.set(`${$}_${M}`,ae),M++}}}else{for(let M=0;M<R.length;M++)e.state.env.set(`${$}_${M}`,R[M]);e.state.env.set(`${$}__length`,String(R.length))}}b($),r&&re(e,$),i&&me(e,$);continue}if(c){let $=N.includes("=")?N.slice(0,N.indexOf("=")):N;if(nn(e,$),!N.includes("="))continue}if(u){let $=N.includes("=")?N.slice(0,N.indexOf("=")):N;if(ht(e,$),!N.includes("="))continue}let _=Mi(N);if(_){let{name:$,indexExpr:x,value:R}=_,G=K(e,$);if(G)return G;w($);let M;try{let J=new W,ae=q(J,x);M=await z(e,ae.expression)}catch{let J=parseInt(x,10);M=Number.isNaN(J)?0:J}e.state.env.set(`${$}_${M}`,R);let H=parseInt(e.state.env.get(`${$}__length`)??"0",10);M>=H&&e.state.env.set(`${$}__length`,String(M+1)),b($),r&&re(e,$),i&&me(e,$);continue}let k=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(k&&!l){let $=k[1],x=k[2],R=K(e,$);if(R)return R;w($);let G=ve(x);if(e.state.associativeArrays?.has($)){let M=kt(x);for(let[H,J]of M){let ae=j(e,J);e.state.env.set(`${$}_${H}`,ae)}}else{let M=Y(e,$),H=0,J=e.state.env.get($);M.length===0&&J!==void 0?(e.state.env.set(`${$}_0`,J),e.state.env.delete($),H=1):M.length>0&&(H=Math.max(...M)+1);for(let Re=0;Re<G.length;Re++)e.state.env.set(`${$}_${H+Re}`,j(e,G[Re]));let ae=H+G.length;e.state.env.set(`${$}__length`,String(ae))}b($),r&&re(e,$),i&&me(e,$);continue}let O=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(O){let $=O[1],x=j(e,O[2]),R=K(e,$);if(R)return R;y($),f&&vs(e,$),d&&bs(e,$),h&&Es(e,$);let M=Y(e,$).length>0||e.state.associativeArrays?.has($);if(Ye(e,$)){let H=e.state.env.get($)??"0",J=parseInt(H,10)||0,ae=parseInt(await Qn(e,x),10)||0;x=String(J+ae),e.state.env.set($,x)}else if(M){x=je(e,$,x);let H=`${$}_0`,J=e.state.env.get(H)??"";e.state.env.set(H,J+x)}else{x=je(e,$,x);let H=e.state.env.get($)??"";e.state.env.set($,H+x)}b($),r&&re(e,$),i&&me(e,$),e.state.options.allexport&&!u&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add($));continue}if(N.includes("=")){let $=N.indexOf("="),x=N.slice(0,$),R=N.slice($+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(x)){E+=`bash: typeset: \`${x}': not a valid identifier
104
+ `;return F(I)}let N=!0;for(let I of $)e.state.functions.has(I)||(N=!1);return C("","",N?0:1)}if(o&&$.length>0)return Zn(e,$);if(o&&$.length===0)return Gn(e,{filterExport:i,filterReadonly:r,filterNameref:a,filterIndexedArray:s,filterAssocArray:n});if($.length===0&&n&&!o)return Kn(e);if($.length===0&&s&&!o)return Xn(e);if($.length===0&&!o)return Yn(e);let E="",D=0;for(let N of $){let I=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(I&&!l){let S=I[1],x=I[2];if(n&&Y(e,S).length>0){E+=`bash: declare: ${S}: cannot convert indexed to associative array
105
+ `,D=1;continue}if((s||!n&&!s)&&e.state.associativeArrays?.has(S)){E+=`bash: declare: ${S}: cannot convert associative to indexed array
106
+ `,D=1;continue}if(w(S),n&&(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(S)),ge(e,S),e.state.env.delete(S),e.state.env.delete(`${S}__length`),n&&x.includes("[")){let R=kt(x);for(let[G,M]of R){let H=j(e,M);e.state.env.set(`${S}_${G}`,H)}}else if(n){let R=ve(x);for(let G=0;G<R.length;G+=2){let M=R[G],H=G+1<R.length?j(e,R[G+1]):"";e.state.env.set(`${S}_${M}`,H)}}else{let R=ve(x);if(R.some(M=>/^\[[^\]]+\]=/.test(M))){let M=0;for(let H of R){let J=H.match(/^\[([^\]]+)\]=(.*)$/);if(J){let ae=J[1],Re=J[2],Hr=j(e,Re),qe;if(/^-?\d+$/.test(ae))qe=Number.parseInt(ae,10);else try{let Ur=new W,qr=q(Ur,ae);qe=await z(e,qr.expression)}catch{qe=0}e.state.env.set(`${S}_${qe}`,Hr),M=qe+1}else{let ae=j(e,H);e.state.env.set(`${S}_${M}`,ae),M++}}}else{for(let M=0;M<R.length;M++)e.state.env.set(`${S}_${M}`,R[M]);e.state.env.set(`${S}__length`,String(R.length))}}b(S),r&&re(e,S),i&&me(e,S);continue}if(c){let S=N.includes("=")?N.slice(0,N.indexOf("=")):N;if(nn(e,S),!N.includes("="))continue}if(u){let S=N.includes("=")?N.slice(0,N.indexOf("=")):N;if(ht(e,S),!N.includes("="))continue}let _=Mi(N);if(_){let{name:S,indexExpr:x,value:R}=_,G=K(e,S);if(G)return G;w(S);let M;try{let J=new W,ae=q(J,x);M=await z(e,ae.expression)}catch{let J=parseInt(x,10);M=Number.isNaN(J)?0:J}e.state.env.set(`${S}_${M}`,R);let H=parseInt(e.state.env.get(`${S}__length`)??"0",10);M>=H&&e.state.env.set(`${S}__length`,String(M+1)),b(S),r&&re(e,S),i&&me(e,S);continue}let k=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(k&&!l){let S=k[1],x=k[2],R=K(e,S);if(R)return R;w(S);let G=ve(x);if(e.state.associativeArrays?.has(S)){let M=kt(x);for(let[H,J]of M){let ae=j(e,J);e.state.env.set(`${S}_${H}`,ae)}}else{let M=Y(e,S),H=0,J=e.state.env.get(S);M.length===0&&J!==void 0?(e.state.env.set(`${S}_0`,J),e.state.env.delete(S),H=1):M.length>0&&(H=Math.max(...M)+1);for(let Re=0;Re<G.length;Re++)e.state.env.set(`${S}_${H+Re}`,j(e,G[Re]));let ae=H+G.length;e.state.env.set(`${S}__length`,String(ae))}b(S),r&&re(e,S),i&&me(e,S);continue}let O=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(O){let S=O[1],x=j(e,O[2]),R=K(e,S);if(R)return R;y(S),f&&vs(e,S),d&&bs(e,S),h&&Es(e,S);let M=Y(e,S).length>0||e.state.associativeArrays?.has(S);if(Ye(e,S)){let H=e.state.env.get(S)??"0",J=parseInt(H,10)||0,ae=parseInt(await Qn(e,x),10)||0;x=String(J+ae),e.state.env.set(S,x)}else if(M){x=je(e,S,x);let H=`${S}_0`,J=e.state.env.get(H)??"";e.state.env.set(H,J+x)}else{x=je(e,S,x);let H=e.state.env.get(S)??"";e.state.env.set(S,H+x)}b(S),r&&re(e,S),i&&me(e,S),e.state.options.allexport&&!u&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(S));continue}if(N.includes("=")){let S=N.indexOf("="),x=N.slice(0,S),R=N.slice(S+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(x)){E+=`bash: typeset: \`${x}': not a valid identifier
107
107
  `,D=1;continue}let G=K(e,x);if(G)return G;if(y(x),a){if(R!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(R)){E+=`bash: declare: \`${R}': invalid variable name for name reference
108
- `,D=1;continue}e.state.env.set(x,R),$e(e,x),R!==""&&qt(e,R)&&Ut(e,x),b(x),r&&re(e,x),i&&me(e,x);continue}if(f&&vs(e,x),d&&bs(e,x),h&&Es(e,x),Ye(e,x)&&(R=await Qn(e,R)),R=je(e,x,R),fe(e,x)){let M=Pe(e,x);M&&M!==x?e.state.env.set(M,R):e.state.env.set(x,R)}else e.state.env.set(x,R);b(x),r&&re(e,x),i&&me(e,x),e.state.options.allexport&&!u&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(x))}else{let $=N;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test($)){E+=`bash: typeset: \`${$}': not a valid identifier
109
- `,D=1;continue}if(s||n?w($):y($),a){$e(e,$);let R=e.state.env.get($);R!==void 0&&R!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(R)?rn(e,$):R&&qt(e,R)&&Ut(e,$),b($),r&&re(e,$),i&&me(e,$);continue}if(f&&vs(e,$),d&&bs(e,$),h&&Es(e,$),n){if(Y(e,$).length>0){E+=`bash: declare: ${$}: cannot convert indexed to associative array
110
- `,D=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add($)}let x=Array.from(e.state.env.keys()).some(R=>R.startsWith(`${$}_`)&&!R.startsWith(`${$}__length`));!e.state.env.has($)&&!x&&(s||n?e.state.env.set(`${$}__length`,"0"):(e.state.declaredVars??=new Set,e.state.declaredVars.add($))),b($),r&&re(e,$),i&&me(e,$)}}return C("",E,D)}async function Ss(e,t){let s=!1,n=!1,r=!1,i=[];for(let o=0;o<t.length;o++){let a=t[o];if(a==="-a")s=!0;else if(a==="-A")n=!0;else if(a==="-p")r=!0;else if(a==="--"){i.push(...t.slice(o+1));break}else a.startsWith("-")||i.push(a)}if(i.length===0){let o="",a=Array.from(e.state.readonlyVars||[]).sort();for(let c of a){let l=e.state.env.get(c);if(l!==void 0){let u=l.replace(/\\/g,"\\\\").replace(/"/g,'\\"');o+=`declare -r ${c}="${u}"
111
- `}}return F(o)}for(let o of i){let a=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(a){let f=a[1],d=a[2],h=K(e,f);if(h)return h;let m=ve(d);if(e.state.associativeArrays?.has(f)){let p=kt(d);for(let[g,S]of p){let v=j(e,S);e.state.env.set(`${f}_${g}`,v)}}else{let p=Y(e,f),g=0,S=e.state.env.get(f);p.length===0&&S!==void 0?(e.state.env.set(`${f}_0`,S),e.state.env.delete(f),g=1):p.length>0&&(g=Math.max(...p)+1);for(let P=0;P<m.length;P++)e.state.env.set(`${f}_${g+P}`,j(e,m[P]));let v=g+m.length;e.state.env.set(`${f}__length`,String(v))}re(e,f);continue}let c=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c){let f=c[1],d=j(e,c[2]),h=K(e,f);if(h)return h;let m=e.state.env.get(f)??"";e.state.env.set(f,m+d),re(e,f);continue}let l=Ln(o);if(l.value===void 0&&!l.isArray){re(e,l.name);continue}let u=await Fn(e,l,{makeReadonly:!0});if(u)return u}return L}function As(e){return e.state.directoryStack??=[],e.state.directoryStack}function Qe(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function Wi(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 _s(e,t){let s=As(e),n;for(let a=0;a<t.length;a++){let c=t[a];if(c==="--"){if(a+1<t.length){if(n!==void 0)return A(`bash: pushd: too many arguments
108
+ `,D=1;continue}e.state.env.set(x,R),Se(e,x),R!==""&&qt(e,R)&&Ut(e,x),b(x),r&&re(e,x),i&&me(e,x);continue}if(f&&vs(e,x),d&&bs(e,x),h&&Es(e,x),Ye(e,x)&&(R=await Qn(e,R)),R=je(e,x,R),fe(e,x)){let M=Pe(e,x);M&&M!==x?e.state.env.set(M,R):e.state.env.set(x,R)}else e.state.env.set(x,R);b(x),r&&re(e,x),i&&me(e,x),e.state.options.allexport&&!u&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(x))}else{let S=N;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(S)){E+=`bash: typeset: \`${S}': not a valid identifier
109
+ `,D=1;continue}if(s||n?w(S):y(S),a){Se(e,S);let R=e.state.env.get(S);R!==void 0&&R!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(R)?rn(e,S):R&&qt(e,R)&&Ut(e,S),b(S),r&&re(e,S),i&&me(e,S);continue}if(f&&vs(e,S),d&&bs(e,S),h&&Es(e,S),n){if(Y(e,S).length>0){E+=`bash: declare: ${S}: cannot convert indexed to associative array
110
+ `,D=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(S)}let x=Array.from(e.state.env.keys()).some(R=>R.startsWith(`${S}_`)&&!R.startsWith(`${S}__length`));!e.state.env.has(S)&&!x&&(s||n?e.state.env.set(`${S}__length`,"0"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(S))),b(S),r&&re(e,S),i&&me(e,S)}}return C("",E,D)}async function $s(e,t){let s=!1,n=!1,r=!1,i=[];for(let o=0;o<t.length;o++){let a=t[o];if(a==="-a")s=!0;else if(a==="-A")n=!0;else if(a==="-p")r=!0;else if(a==="--"){i.push(...t.slice(o+1));break}else a.startsWith("-")||i.push(a)}if(i.length===0){let o="",a=Array.from(e.state.readonlyVars||[]).sort();for(let c of a){let l=e.state.env.get(c);if(l!==void 0){let u=l.replace(/\\/g,"\\\\").replace(/"/g,'\\"');o+=`declare -r ${c}="${u}"
111
+ `}}return F(o)}for(let o of i){let a=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(a){let f=a[1],d=a[2],h=K(e,f);if(h)return h;let m=ve(d);if(e.state.associativeArrays?.has(f)){let p=kt(d);for(let[g,$]of p){let v=j(e,$);e.state.env.set(`${f}_${g}`,v)}}else{let p=Y(e,f),g=0,$=e.state.env.get(f);p.length===0&&$!==void 0?(e.state.env.set(`${f}_0`,$),e.state.env.delete(f),g=1):p.length>0&&(g=Math.max(...p)+1);for(let P=0;P<m.length;P++)e.state.env.set(`${f}_${g+P}`,j(e,m[P]));let v=g+m.length;e.state.env.set(`${f}__length`,String(v))}re(e,f);continue}let c=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c){let f=c[1],d=j(e,c[2]),h=K(e,f);if(h)return h;let m=e.state.env.get(f)??"";e.state.env.set(f,m+d),re(e,f);continue}let l=Ln(o);if(l.value===void 0&&!l.isArray){re(e,l.name);continue}let u=await Fn(e,l,{makeReadonly:!0});if(u)return u}return L}function As(e){return e.state.directoryStack??=[],e.state.directoryStack}function Qe(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function Wi(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 _s(e,t){let s=As(e),n;for(let a=0;a<t.length;a++){let c=t[a];if(c==="--"){if(a+1<t.length){if(n!==void 0)return A(`bash: pushd: too many arguments
112
112
  `,2);n=t[a+1],a++}}else{if(c.startsWith("-")&&c!=="-")return A(`bash: pushd: ${c}: invalid option
113
113
  `,2);if(n!==void 0)return A(`bash: pushd: too many arguments
114
114
  `,2);n=c}}if(n===void 0){if(s.length<2)return A(`bash: pushd: no other directory
@@ -142,16 +142,16 @@ eval: usage: eval [arg ...]
142
142
  `,1);l++}else c.push(m),l++}if(s)return e.state.hashTable.clear(),L;if(n){if(c.length===0)return A(`bash: hash: -d: option requires an argument
143
143
  `,1);let m=!1,p="";for(let g of c)e.state.hashTable.has(g)?e.state.hashTable.delete(g):(p+=`bash: hash: ${g}: not found
144
144
  `,m=!0);return m?A(p,1):L}if(o){if(c.length===0)return A(`bash: hash: -t: option requires an argument
145
- `,1);let m="",p=!1,g="";for(let S of c){let v=e.state.hashTable.get(S);v?c.length>1?m+=`${S} ${v}
145
+ `,1);let m="",p=!1,g="";for(let $ of c){let v=e.state.hashTable.get($);v?c.length>1?m+=`${$} ${v}
146
146
  `:m+=`${v}
147
- `:(g+=`bash: hash: ${S}: not found
147
+ `:(g+=`bash: hash: ${$}: not found
148
148
  `,p=!0)}return p?{exitCode:1,stdout:m,stderr:g}:F(m)}if(i){if(c.length===0)return A(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
149
149
  `,1);let m=c[0];return e.state.hashTable.set(m,a),L}if(c.length===0){if(e.state.hashTable.size===0)return F(`hash: hash table empty
150
150
  `);let m="";if(r)for(let[p,g]of e.state.hashTable)m+=`builtin hash -p ${g} ${p}
151
151
  `;else{m=`hits command
152
152
  `;for(let[,p]of e.state.hashTable)m+=` 1 ${p}
153
153
  `}return F(m)}let u=!1,f="",h=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let m of c){if(m.includes("/")){f+=`bash: hash: ${m}: cannot use / in name
154
- `,u=!0;continue}let p=!1;for(let g of h){if(!g)continue;let S=`${g}/${m}`;if(await e.fs.exists(S)){e.state.hashTable.set(m,S),p=!0;break}}p||(f+=`bash: hash: ${m}: not found
154
+ `,u=!0;continue}let p=!1;for(let g of h){if(!g)continue;let $=`${g}/${m}`;if(await e.fs.exists($)){e.state.hashTable.set(m,$),p=!0;break}}p||(f+=`bash: hash: ${m}: not found
155
155
  `,u=!0)}return u?A(f,1):L}var Jn=new Map([[":",[": [arguments]",`Null command.
156
156
  No effect; the command does nothing.
157
157
  Exit Status:
@@ -508,17 +508,17 @@ ${h}
508
508
  `);let s=Bi(t),n=0;for(let r of s)try{let o=ye(`(( ${r} ))`).statements[0];if(o&&o.pipelines.length>0&&o.pipelines[0].commands.length>0){let a=o.pipelines[0].commands[0];a.type==="ArithmeticCommand"&&(n=await z(e,a.expression.expression))}}catch(i){return A(`bash: let: ${r}: ${i.message}
509
509
  `)}return C("","",n===0?1:0)}async function Ts(e,t){if(e.state.localScopes.length===0)return A(`bash: local: can only be used in a function
510
510
  `);let s=e.state.localScopes[e.state.localScopes.length-1],n="",r=0,i=!1,o=!1,a=!1,c=[];for(let l of t)if(l==="-n")i=!0;else if(l==="-a")o=!0;else if(l==="-p")a=!0;else if(l.startsWith("-")&&!l.includes("="))for(let u of l.slice(1))u==="n"?i=!0:u==="a"?o=!0:u==="p"&&(a=!0);else c.push(l);if(c.length===0){let l="",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&&(l+=`${f}=${d}
511
- `)}return C(l,"",0)}for(let l of c){let u,f,d=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(d){u=d[1];let S=d[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){n+=`bash: local: \`${l}': not a valid identifier
512
- `,r=1;continue}if(K(e,u,"bash"),!s.has(u)){s.set(u,e.state.env.get(u));let y=`${u}_`;for(let w of e.state.env.keys())w.startsWith(y)&&!w.includes("__")&&(s.has(w)||s.set(w,e.state.env.get(w)))}let v=`${u}_`;for(let y of e.state.env.keys())y.startsWith(v)&&!y.includes("__")&&e.state.env.delete(y);let P=ve(S);for(let y=0;y<P.length;y++)e.state.env.set(`${u}_${y}`,P[y]);e.state.env.set(`${u}__length`,String(P.length)),Oe(e,u),i&&$e(e,u);continue}let h=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(h){u=h[1];let S=h[2];if(K(e,u,"bash"),!s.has(u)){s.set(u,e.state.env.get(u));let E=`${u}_`;for(let N of e.state.env.keys())N.startsWith(E)&&!N.includes("__")&&(s.has(N)||s.set(N,e.state.env.get(N)));let D=`${u}__length`;e.state.env.has(D)&&!s.has(D)&&s.set(D,e.state.env.get(D))}let v=ve(S),P=Y(e,u),y=0,w=e.state.env.get(u);P.length===0&&w!==void 0?(e.state.env.set(`${u}_0`,w),e.state.env.delete(u),y=1):P.length>0&&(y=Math.max(...P)+1);for(let E=0;E<v.length;E++)e.state.env.set(`${u}_${y+E}`,j(e,v[E]));let b=y+v.length;e.state.env.set(`${u}__length`,String(b)),Oe(e,u),i&&$e(e,u);continue}let m=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(m){u=m[1];let S=j(e,m[2]);K(e,u,"bash"),s.has(u)||s.set(u,e.state.env.get(u));let v=e.state.env.get(u)??"";e.state.env.set(u,v+S),Oe(e,u),i&&$e(e,u);continue}let p=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(p){u=p[1];let S=p[2],v=j(e,p[3]);if(K(e,u,"bash"),!s.has(u)){s.set(u,e.state.env.get(u));let w=`${u}_`;for(let E of e.state.env.keys())E.startsWith(w)&&!E.includes("__")&&(s.has(E)||s.set(E,e.state.env.get(E)));let b=`${u}__length`;e.state.env.has(b)&&!s.has(b)&&s.set(b,e.state.env.get(b))}let P;try{let w=new W,b=q(w,S);P=await z(e,b.expression)}catch{let w=parseInt(S,10);P=Number.isNaN(w)?0:w}e.state.env.set(`${u}_${P}`,v);let y=parseInt(e.state.env.get(`${u}__length`)??"0",10);P>=y&&e.state.env.set(`${u}__length`,String(P+1)),Oe(e,u),i&&$e(e,u);continue}if(l.includes("=")){let S=l.indexOf("=");u=l.slice(0,S),f=j(e,l.slice(S+1))}else u=l;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){n+=`bash: local: \`${l}': not a valid identifier
513
- `,r=1;continue}let g=s.has(u);if(f!==void 0){let S=e.state.env.get(u);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(u),P=e.state.mutatedTempEnvVars?.has(u);if(!v&&!P)for(let y=e.state.tempEnvBindings.length-1;y>=0;y--){let w=e.state.tempEnvBindings[y];if(w.has(u)){S=w.get(u);break}}}Mn(e,u,S)}if(!g){let S=e.state.env.get(u);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let P=e.state.tempEnvBindings[v];if(P.has(u)){S=P.get(u);break}}if(s.set(u,S),o){let v=`${u}_`;for(let y of e.state.env.keys())y.startsWith(v)&&!y.includes("__")&&(s.has(y)||s.set(y,e.state.env.get(y)));let P=`${u}__length`;e.state.env.has(P)&&!s.has(P)&&s.set(P,e.state.env.get(P))}}if(o&&f===void 0){let S=`${u}_`;for(let v of e.state.env.keys())v.startsWith(S)&&!v.includes("__")&&e.state.env.delete(v);e.state.env.set(`${u}__length`,"0")}else if(f!==void 0){if(K(e,u,"bash"),i&&f!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(f)){n+=`bash: local: \`${f}': invalid variable name for name reference
514
- `,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 S=e.state.tempEnvBindings?.some(v=>v.has(u));!g&&!S&&e.state.env.delete(u)}Oe(e,u),i&&$e(e,u)}return C("",n,r)}function Is(e,t,s){let n=`
511
+ `)}return C(l,"",0)}for(let l of c){let u,f,d=l.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: \`${l}': not a valid identifier
512
+ `,r=1;continue}if(K(e,u,"bash"),!s.has(u)){s.set(u,e.state.env.get(u));let y=`${u}_`;for(let w of e.state.env.keys())w.startsWith(y)&&!w.includes("__")&&(s.has(w)||s.set(w,e.state.env.get(w)))}let v=`${u}_`;for(let y of e.state.env.keys())y.startsWith(v)&&!y.includes("__")&&e.state.env.delete(y);let P=ve($);for(let y=0;y<P.length;y++)e.state.env.set(`${u}_${y}`,P[y]);e.state.env.set(`${u}__length`,String(P.length)),Oe(e,u),i&&Se(e,u);continue}let h=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(h){u=h[1];let $=h[2];if(K(e,u,"bash"),!s.has(u)){s.set(u,e.state.env.get(u));let E=`${u}_`;for(let N of e.state.env.keys())N.startsWith(E)&&!N.includes("__")&&(s.has(N)||s.set(N,e.state.env.get(N)));let D=`${u}__length`;e.state.env.has(D)&&!s.has(D)&&s.set(D,e.state.env.get(D))}let v=ve($),P=Y(e,u),y=0,w=e.state.env.get(u);P.length===0&&w!==void 0?(e.state.env.set(`${u}_0`,w),e.state.env.delete(u),y=1):P.length>0&&(y=Math.max(...P)+1);for(let E=0;E<v.length;E++)e.state.env.set(`${u}_${y+E}`,j(e,v[E]));let b=y+v.length;e.state.env.set(`${u}__length`,String(b)),Oe(e,u),i&&Se(e,u);continue}let m=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(m){u=m[1];let $=j(e,m[2]);K(e,u,"bash"),s.has(u)||s.set(u,e.state.env.get(u));let v=e.state.env.get(u)??"";e.state.env.set(u,v+$),Oe(e,u),i&&Se(e,u);continue}let p=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(p){u=p[1];let $=p[2],v=j(e,p[3]);if(K(e,u,"bash"),!s.has(u)){s.set(u,e.state.env.get(u));let w=`${u}_`;for(let E of e.state.env.keys())E.startsWith(w)&&!E.includes("__")&&(s.has(E)||s.set(E,e.state.env.get(E)));let b=`${u}__length`;e.state.env.has(b)&&!s.has(b)&&s.set(b,e.state.env.get(b))}let P;try{let w=new W,b=q(w,$);P=await z(e,b.expression)}catch{let w=parseInt($,10);P=Number.isNaN(w)?0:w}e.state.env.set(`${u}_${P}`,v);let y=parseInt(e.state.env.get(`${u}__length`)??"0",10);P>=y&&e.state.env.set(`${u}__length`,String(P+1)),Oe(e,u),i&&Se(e,u);continue}if(l.includes("=")){let $=l.indexOf("=");u=l.slice(0,$),f=j(e,l.slice($+1))}else u=l;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(u)){n+=`bash: local: \`${l}': not a valid identifier
513
+ `,r=1;continue}let g=s.has(u);if(f!==void 0){let $=e.state.env.get(u);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(u),P=e.state.mutatedTempEnvVars?.has(u);if(!v&&!P)for(let y=e.state.tempEnvBindings.length-1;y>=0;y--){let w=e.state.tempEnvBindings[y];if(w.has(u)){$=w.get(u);break}}}Mn(e,u,$)}if(!g){let $=e.state.env.get(u);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let P=e.state.tempEnvBindings[v];if(P.has(u)){$=P.get(u);break}}if(s.set(u,$),o){let v=`${u}_`;for(let y of e.state.env.keys())y.startsWith(v)&&!y.includes("__")&&(s.has(y)||s.set(y,e.state.env.get(y)));let P=`${u}__length`;e.state.env.has(P)&&!s.has(P)&&s.set(P,e.state.env.get(P))}}if(o&&f===void 0){let $=`${u}_`;for(let v of e.state.env.keys())v.startsWith($)&&!v.includes("__")&&e.state.env.delete(v);e.state.env.set(`${u}__length`,"0")}else if(f!==void 0){if(K(e,u,"bash"),i&&f!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(f)){n+=`bash: local: \`${f}': invalid variable name for name reference
514
+ `,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(v=>v.has(u));!g&&!$&&e.state.env.delete(u)}Oe(e,u),i&&Se(e,u)}return C("",n,r)}function Is(e,t,s){let n=`
515
515
  `,r=0,i=0,o=0,a=!1,c="MAPFILE",l=0;for(;l<t.length;){let v=t[l];v==="-d"&&l+1<t.length?(n=t[l+1]===""?"\0":t[l+1]||`
516
516
  `,l+=2):v==="-n"&&l+1<t.length?(r=Number.parseInt(t[l+1],10)||0,l+=2):v==="-O"&&l+1<t.length?(i=Number.parseInt(t[l+1],10)||0,l+=2):v==="-s"&&l+1<t.length?(o=Number.parseInt(t[l+1],10)||0,l+=2):v==="-t"?(a=!0,l++):v==="-u"||v==="-C"||v==="-c"?l+=2:(v.startsWith("-")||(c=v),l++)}let u=s;!u&&e.state.groupStdin!==void 0&&(u=e.state.groupStdin);let f=[],d=u,h=0,m=0,p=e.limits?.maxArrayElements??1e5;for(;d.length>0;){let v=d.indexOf(n);if(v===-1){if(d.length>0){if(m<o)m++;else if(r===0||h<r){if(i+h>=p)return C("",`mapfile: array element limit exceeded (${p})
517
517
  `,1);let w=d,b=w.indexOf("\0");b!==-1&&(w=w.substring(0,b)),f.push(w),h++}}break}let P=d.substring(0,v),y=P.indexOf("\0");if(y!==-1&&(P=P.substring(0,y)),!a&&n!=="\0"&&(P+=n),d=d.substring(v+n.length),m<o){m++;continue}if(r>0&&h>=r)break;if(i+h>=p)return C("",`mapfile: array element limit exceeded (${p})
518
- `,1);f.push(P),h++}i===0&&ge(e,c);for(let v=0;v<f.length;v++)e.state.env.set(`${c}_${i+v}`,f[v]);let g=parseInt(e.state.env.get(`${c}__length`)||"0",10),S=i+f.length;return e.state.env.set(`${c}__length`,String(Math.max(g,S))),e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=""),C("","",0)}function ji(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),o=r+n+1,a=t.slice(o),c=a.indexOf(":");if(c===-1)return null;let l=Number.parseInt(a.slice(0,c),10);if(Number.isNaN(l)||l<0)return null;let u=a.slice(c+1);return{path:i,position:l,content:u}}function Hi(e,t,s){return`__rw__:${e.length}:${e}:${t}:${s}`}function Rs(e,t,s,n=-1){let r=!1,i=`
519
- `,o="",a=-1,c=-1,l=null,u=-1,f=-1,d=[],h=0,m=!1,p=(_,k)=>{let O=1;for(;O<_.length;){let $=_[O];if($==="r")r=!0,O++;else if($==="s")O++;else{if($==="d")return O+1<_.length?(i=_.substring(O+1),{nextArgIndex:k+1}):k+1<t.length?(i=t[k+1],{nextArgIndex:k+2}):{nextArgIndex:k+1};if($==="n"){if(O+1<_.length){let x=_.substring(O+1);return a=Number.parseInt(x,10),(Number.isNaN(a)||a<0)&&(m=!0,a=0),{nextArgIndex:k+1}}else if(k+1<t.length)return a=Number.parseInt(t[k+1],10),(Number.isNaN(a)||a<0)&&(m=!0,a=0),{nextArgIndex:k+2};return{nextArgIndex:k+1}}else if($==="N"){if(O+1<_.length){let x=_.substring(O+1);return c=Number.parseInt(x,10),(Number.isNaN(c)||c<0)&&(m=!0,c=0),{nextArgIndex:k+1}}else if(k+1<t.length)return c=Number.parseInt(t[k+1],10),(Number.isNaN(c)||c<0)&&(m=!0,c=0),{nextArgIndex:k+2};return{nextArgIndex:k+1}}else{if($==="a")return O+1<_.length?(l=_.substring(O+1),{nextArgIndex:k+1}):k+1<t.length?(l=t[k+1],{nextArgIndex:k+2}):{nextArgIndex:k+1};if($==="p")return O+1<_.length?(o=_.substring(O+1),{nextArgIndex:k+1}):k+1<t.length?(o=t[k+1],{nextArgIndex:k+2}):{nextArgIndex:k+1};if($==="u"){if(O+1<_.length){let x=_.substring(O+1);return u=Number.parseInt(x,10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:k+1}}else if(k+1<t.length)return u=Number.parseInt(t[k+1],10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:k+2};return{nextArgIndex:k+1}}else if($==="t"){if(O+1<_.length){let x=_.substring(O+1);return f=Number.parseFloat(x),Number.isNaN(f)&&(f=0),{nextArgIndex:k+1}}else if(k+1<t.length)return f=Number.parseFloat(t[k+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:k+2};return{nextArgIndex:k+1}}else if($==="e"||$==="i"||$==="P"){if($==="i"&&k+1<t.length)return{nextArgIndex:k+2};O++}else O++}}}return{nextArgIndex:k+1}};for(;h<t.length;){let _=t[h];if(_.startsWith("-")&&_.length>1&&_!=="--"){let k=p(_,h);if(k.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(k.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=k.nextArgIndex}else if(_==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push(_),h++}if(m)return C("","",1);if(d.length===0&&l===null&&d.push("REPLY"),f===0){if(l)ge(e,l);else{for(let _ of d)e.state.env.set(_,"");d.length===0&&e.state.env.set("REPLY","")}return C("","",0)}if(f<0&&f!==-1)return C("","",1);let g=s;u>=0?e.state.fileDescriptors?g=e.state.fileDescriptors.get(u)||"":g="":!g&&e.state.groupStdin!==void 0&&(g=e.state.groupStdin);let S=i===""?"\0":i,v="",P=0,y=!0,w=_=>{if(u>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(u,g.substring(_));else if(n>=0&&e.state.fileDescriptors){let k=e.state.fileDescriptors.get(n);if(k?.startsWith("__rw__:")){let O=ji(k);if(O){let $=O.position+_;e.state.fileDescriptors.set(n,Hi(O.path,$,O.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=g.substring(_))};if(c>=0){let _=Math.min(c,g.length);v=g.substring(0,_),P=_,y=_>=c,w(P);let k=d[0]||"REPLY";e.state.env.set(k,v);for(let O=1;O<d.length;O++)e.state.env.set(d[O],"");return C("","",y?0:1)}else if(a>=0){let _=0,k=0,O=!1;for(;k<g.length&&_<a;){let $=g[k];if($===S){P=k+1,O=!0;break}if(!r&&$==="\\"&&k+1<g.length){let x=g[k+1];if(x===S&&S===`
520
- `){k+=2,P=k;continue}if(x===S){k+=2,_++,v+=x,P=k;continue}v+=x,k+=2,_++,P=k}else v+=$,k++,_++,P=k}y=_>=a||O,w(P)}else{P=0;let _=0;for(;_<g.length;){let k=g[_];if(k===S){P=_+S.length,y=!0;break}if(!r&&k==="\\"&&_+1<g.length){let O=g[_+1];if(O===`
521
- `){_+=2;continue}if(O===S){v+=O,_+=2;continue}v+=k,v+=O,_+=2;continue}v+=k,_++}if(_>=g.length&&(y=!1,P=_,v.length===0&&g.length===0)){for(let k of d)e.state.env.set(k,"");return l&&ge(e,l),C("","",1)}w(P)}S===`
518
+ `,1);f.push(P),h++}i===0&&ge(e,c);for(let v=0;v<f.length;v++)e.state.env.set(`${c}_${i+v}`,f[v]);let g=parseInt(e.state.env.get(`${c}__length`)||"0",10),$=i+f.length;return e.state.env.set(`${c}__length`,String(Math.max(g,$))),e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=""),C("","",0)}function ji(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),o=r+n+1,a=t.slice(o),c=a.indexOf(":");if(c===-1)return null;let l=Number.parseInt(a.slice(0,c),10);if(Number.isNaN(l)||l<0)return null;let u=a.slice(c+1);return{path:i,position:l,content:u}}function Hi(e,t,s){return`__rw__:${e.length}:${e}:${t}:${s}`}function Rs(e,t,s,n=-1){let r=!1,i=`
519
+ `,o="",a=-1,c=-1,l=null,u=-1,f=-1,d=[],h=0,m=!1,p=(_,k)=>{let O=1;for(;O<_.length;){let S=_[O];if(S==="r")r=!0,O++;else if(S==="s")O++;else{if(S==="d")return O+1<_.length?(i=_.substring(O+1),{nextArgIndex:k+1}):k+1<t.length?(i=t[k+1],{nextArgIndex:k+2}):{nextArgIndex:k+1};if(S==="n"){if(O+1<_.length){let x=_.substring(O+1);return a=Number.parseInt(x,10),(Number.isNaN(a)||a<0)&&(m=!0,a=0),{nextArgIndex:k+1}}else if(k+1<t.length)return a=Number.parseInt(t[k+1],10),(Number.isNaN(a)||a<0)&&(m=!0,a=0),{nextArgIndex:k+2};return{nextArgIndex:k+1}}else if(S==="N"){if(O+1<_.length){let x=_.substring(O+1);return c=Number.parseInt(x,10),(Number.isNaN(c)||c<0)&&(m=!0,c=0),{nextArgIndex:k+1}}else if(k+1<t.length)return c=Number.parseInt(t[k+1],10),(Number.isNaN(c)||c<0)&&(m=!0,c=0),{nextArgIndex:k+2};return{nextArgIndex:k+1}}else{if(S==="a")return O+1<_.length?(l=_.substring(O+1),{nextArgIndex:k+1}):k+1<t.length?(l=t[k+1],{nextArgIndex:k+2}):{nextArgIndex:k+1};if(S==="p")return O+1<_.length?(o=_.substring(O+1),{nextArgIndex:k+1}):k+1<t.length?(o=t[k+1],{nextArgIndex:k+2}):{nextArgIndex:k+1};if(S==="u"){if(O+1<_.length){let x=_.substring(O+1);return u=Number.parseInt(x,10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:k+1}}else if(k+1<t.length)return u=Number.parseInt(t[k+1],10),Number.isNaN(u)||u<0?{nextArgIndex:-2}:{nextArgIndex:k+2};return{nextArgIndex:k+1}}else if(S==="t"){if(O+1<_.length){let x=_.substring(O+1);return f=Number.parseFloat(x),Number.isNaN(f)&&(f=0),{nextArgIndex:k+1}}else if(k+1<t.length)return f=Number.parseFloat(t[k+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:k+2};return{nextArgIndex:k+1}}else if(S==="e"||S==="i"||S==="P"){if(S==="i"&&k+1<t.length)return{nextArgIndex:k+2};O++}else O++}}}return{nextArgIndex:k+1}};for(;h<t.length;){let _=t[h];if(_.startsWith("-")&&_.length>1&&_!=="--"){let k=p(_,h);if(k.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(k.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};h=k.nextArgIndex}else if(_==="--")for(h++;h<t.length;)d.push(t[h]),h++;else d.push(_),h++}if(m)return C("","",1);if(d.length===0&&l===null&&d.push("REPLY"),f===0){if(l)ge(e,l);else{for(let _ of d)e.state.env.set(_,"");d.length===0&&e.state.env.set("REPLY","")}return C("","",0)}if(f<0&&f!==-1)return C("","",1);let g=s;u>=0?e.state.fileDescriptors?g=e.state.fileDescriptors.get(u)||"":g="":!g&&e.state.groupStdin!==void 0&&(g=e.state.groupStdin);let $=i===""?"\0":i,v="",P=0,y=!0,w=_=>{if(u>=0&&e.state.fileDescriptors)e.state.fileDescriptors.set(u,g.substring(_));else if(n>=0&&e.state.fileDescriptors){let k=e.state.fileDescriptors.get(n);if(k?.startsWith("__rw__:")){let O=ji(k);if(O){let S=O.position+_;e.state.fileDescriptors.set(n,Hi(O.path,S,O.content))}}}else e.state.groupStdin!==void 0&&!s&&(e.state.groupStdin=g.substring(_))};if(c>=0){let _=Math.min(c,g.length);v=g.substring(0,_),P=_,y=_>=c,w(P);let k=d[0]||"REPLY";e.state.env.set(k,v);for(let O=1;O<d.length;O++)e.state.env.set(d[O],"");return C("","",y?0:1)}else if(a>=0){let _=0,k=0,O=!1;for(;k<g.length&&_<a;){let S=g[k];if(S===$){P=k+1,O=!0;break}if(!r&&S==="\\"&&k+1<g.length){let x=g[k+1];if(x===$&&$===`
520
+ `){k+=2,P=k;continue}if(x===$){k+=2,_++,v+=x,P=k;continue}v+=x,k+=2,_++,P=k}else v+=S,k++,_++,P=k}y=_>=a||O,w(P)}else{P=0;let _=0;for(;_<g.length;){let k=g[_];if(k===$){P=_+$.length,y=!0;break}if(!r&&k==="\\"&&_+1<g.length){let O=g[_+1];if(O===`
521
+ `){_+=2;continue}if(O===$){v+=O,_+=2;continue}v+=k,v+=O,_+=2;continue}v+=k,_++}if(_>=g.length&&(y=!1,P=_,v.length===0&&g.length===0)){for(let k of d)e.state.env.set(k,"");return l&&ge(e,l),C("","",1)}w(P)}$===`
522
522
  `&&v.endsWith(`
523
523
  `)&&(v=v.slice(0,-1));let b=_=>r?_:_.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",b(v)),C("","",y?0:1);let E=tn(e.state.env);if(l){let{words:_}=Ht(v,E,void 0,r),k=e.limits?.maxArrayElements??1e5;if(_.length>k)return C("",`read: array element limit exceeded (${k})
524
524
  `,1);ge(e,l);for(let O=0;O<_.length;O++)e.state.env.set(`${l}_${O}`,b(_[O]));return C("","",y?0:1)}let D=d.length,{words:N,wordStarts:I}=Ht(v,E,D,r);for(let _=0;_<d.length;_++){let k=d[_];if(_<d.length-1)e.state.env.set(k,b(N[_]??""));else if(_<I.length){let O=v.substring(I[_]);O=sn(O,E,r),O=b(O),e.state.env.set(k,O)}else e.state.env.set(k,"")}return C("","",y?0:1)}function Ls(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return A("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 A(`bash: return: ${n}: numeric argument required
@@ -560,8 +560,8 @@ ${Lt}`;if(e.state.options.posix)throw new de(1,"",r);return A(r)}return Fs(e,t.s
560
560
  `,r=1;continue}let u=i;if(fe(e,i)){let d=Pe(e,i);d&&d!==i&&(u=d)}if(De(e,u)){n+=`bash: unset: ${u}: cannot unset: readonly variable
561
561
  `,r=1;continue}let f=Ve(e,u);if(f!==void 0&&f!==e.state.callDepth)lr(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 m=Ot(e,u);m?m.value===void 0?e.state.env.delete(u):e.state.env.set(u,m.value):e.state.env.delete(u)}else e.state.env.delete(u)}else zs(e,u)||e.state.env.delete(u);e.state.exportedVars?.delete(u);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let l=o[1],u=o[2];if(u==="@"||u==="*"){let p=pe(e,l);for(let[g]of p)e.state.env.delete(`${l}_${g}`);e.state.env.delete(l);continue}let f=e.state.associativeArrays?.has(l);if(f){let p=await cr(e,u);e.state.env.delete(`${l}_${p}`);continue}let d=Zt(e,l);if(e.state.env.has(l)&&!d&&!f){n+=`bash: unset: ${l}: not an array variable
562
562
  `,r=1;continue}let m=await ar(e,u);if(m===null&&d){n+=`bash: unset: ${u}: not a valid identifier
563
- `,r=1;continue}if(m===null)continue;if(m<0){let p=pe(e,l),g=p.length,S=e.state.currentLine;if(g===0){n+=`bash: line ${S}: unset: [${m}]: bad array subscript
564
- `,r=1;continue}let v=g+m;if(v<0){n+=`bash: line ${S}: unset: [${m}]: bad array subscript
563
+ `,r=1;continue}if(m===null)continue;if(m<0){let p=pe(e,l),g=p.length,$=e.state.currentLine;if(g===0){n+=`bash: line ${$}: unset: [${m}]: bad array subscript
564
+ `,r=1;continue}let v=g+m;if(v<0){n+=`bash: line ${$}: unset: [${m}]: bad array subscript
565
565
  `,r=1;continue}let P=p[v][0];e.state.env.delete(`${l}_${P}`);continue}e.state.env.delete(`${l}_${m}`);continue}if(!or(i)){n+=`bash: unset: \`${i}': not a valid identifier
566
566
  `,r=1;continue}let a=i;if(fe(e,i)){let l=Pe(e,i);l&&l!==i&&(a=l)}if(De(e,a)){n+=`bash: unset: ${a}: cannot unset: readonly variable
567
567
  `,r=1;continue}let c=Ve(e,a);if(c!==void 0&&c!==e.state.callDepth)lr(e,a);else if(e.state.fullyUnsetLocals?.has(a))e.state.env.delete(a);else if(c!==void 0){let l=e.state.accessedTempEnvVars?.has(a),u=e.state.mutatedTempEnvVars?.has(a);if((l||u)&&e.state.localVarStack?.has(a)){let f=Ot(e,a);f?f.value===void 0?e.state.env.delete(a):e.state.env.set(a,f.value):e.state.env.delete(a)}else e.state.env.delete(a)}else zs(e,a)||e.state.env.delete(a);e.state.exportedVars?.delete(a),e.state.functions.delete(i)}return C("",n,r)}var js=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],Qi=["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 Ft(e){return js.includes(e)}function Ji(e){return Qi.includes(e)}function ur(e,t){let s=!1,n=!1,r=!1,i=!1,o=!1,a=[],c=0;for(;c<t.length;){let d=t[c];if(d==="--"){c++;break}if(d.startsWith("-")&&d.length>1){for(let h=1;h<d.length;h++){let m=d[h];switch(m){case"s":s=!0;break;case"u":n=!0;break;case"p":r=!0;break;case"q":i=!0;break;case"o":o=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${m}: invalid option
@@ -580,13 +580,13 @@ ${Lt}`;if(e.state.options.posix)throw new de(1,"",r);return A(r)}return Fs(e,t.s
580
580
  `)}
581
581
  `:"",stderr:u}}async function fr(e,t,s){if(t.includes("/")){let o=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(o))return{error:"not_found",path:o};let a=o.split("/").pop()||t,c=e.commands.get(a);try{let l=await e.fs.stat(o);return l.isDirectory?{error:"permission_denied",path:o}:c?{cmd:c,path:o}:(l.mode&73)!==0?{script:!0,path:o}:{error:"permission_denied",path:o}}catch{return{error:"not_found",path:o}}}if(!s&&e.state.hashTable){let o=e.state.hashTable.get(t);if(o)if(await e.fs.exists(o)){let a=e.commands.get(t);if(a)return{cmd:a,path:o};try{let c=await e.fs.stat(o);if(!c.isDirectory&&(c.mode&73)!==0)return{script:!0,path:o}}catch{}}else e.state.hashTable.delete(t)}let r=(s??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let o of r){if(!o)continue;let c=`${o.startsWith("/")?o:e.fs.resolvePath(e.state.cwd,o)}/${t}`;if(await e.fs.exists(c))try{let l=await e.fs.stat(c);if(l.isDirectory)continue;let u=(l.mode&73)!==0,f=e.commands.get(t),d=o==="/bin"||o==="/usr/bin";if(f&&d)return{cmd:f,path:c};if(u){if(f&&!d)return{script:!0,path:c};if(!f)return{script:!0,path:c}}}catch{}}if(!await e.fs.exists("/usr/bin")){let o=e.commands.get(t);if(o)return{cmd:o,path:`/usr/bin/${t}`}}return null}async function Mt(e,t){let s=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let o=await e.fs.stat(i);o.isDirectory||(o.mode&73)!==0&&s.push(t)}catch{}return s}let r=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of r){if(!i)continue;let a=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(await e.fs.exists(a)){try{if((await e.fs.stat(a)).isDirectory)continue}catch{continue}s.push(i.startsWith("/")?a:`${i}/${t}`)}}return s}async function mr(e,t,s,n){let r=!1,i=!1,o=!1,a=!1,c=!1,l=[];for(let p of t)if(p.startsWith("-")&&p.length>1)for(let g of p.slice(1))g==="t"?r=!0:g==="p"?i=!0:g==="P"?o=!0:g==="a"?a=!0:g==="f"&&(c=!0);else l.push(p);let u="",f="",d=0,h=!1,m=!1;for(let p of l){let g=!1;if(o){if(a){let b=await n(p);if(b.length>0){for(let E of b)u+=`${E}
582
582
  `;h=!0,g=!0}}else{let b=await s(p);b&&(u+=`${b}
583
- `,h=!0,g=!0)}g||(m=!0);continue}let S=!c&&e.state.functions.has(p);if(a&&S){if(!i)if(r)u+=`function
583
+ `,h=!0,g=!0)}g||(m=!0);continue}let $=!c&&e.state.functions.has(p);if(a&&$){if(!i)if(r)u+=`function
584
584
  `;else{let b=e.state.functions.get(p),E=b?dr(p,b):`${p} is a function
585
585
  `;u+=E}g=!0}let v=e.state.env.get(`BASH_ALIAS_${p}`);if(v!==void 0&&(a||!g)&&(i||(r?u+=`alias
586
586
  `:u+=`${p} is aliased to \`${v}'
587
587
  `),g=!0,!a)||as.has(p)&&(a||!g)&&(i||(r?u+=`keyword
588
588
  `:u+=`${p} is a shell keyword
589
- `),g=!0,!a))continue;if(!a&&S&&!g){if(!i)if(r)u+=`function
589
+ `),g=!0,!a))continue;if(!a&&$&&!g){if(!i)if(r)u+=`function
590
590
  `;else{let b=e.state.functions.get(p),E=b?dr(p,b):`${p} is a function
591
591
  `;u+=E}g=!0;continue}if(!(ze.has(p)&&(a||!g)&&(i||(r?u+=`builtin
592
592
  `:u+=`${p} is a shell builtin
@@ -616,7 +616,7 @@ ${e} ()
616
616
  `),o=1)}else if(e.commands.has(a)){let u=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of u){if(!d)continue;let h=`${d}/${a}`;try{let m=await e.fs.stat(h);if(!m.isDirectory&&(m.mode&73)!==0){f=h;break}}catch{}}f||(f=`/usr/bin/${a}`),n?r+=`${a} is ${f}
617
617
  `:r+=`${f}
618
618
  `}else n&&(i+=`${a}: not found
619
- `),o=1}return C(r,i,o)}async function gr(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 o=`${r.startsWith("/")?r:e.fs.resolvePath(e.state.cwd,r)}/${t}`;if(await e.fs.exists(o)){try{if((await e.fs.stat(o)).isDirectory)continue}catch{continue}return`${r}/${t}`}}if(e.commands.has(t)){for(let r of n)if(r==="/usr/bin"||r==="/bin")return`${r}/${t}`;return`/usr/bin/${t}`}return null}async function wr(e,t,s,n,r,i,o,a){let{ctx:c,runCommand:l}=e;if(c.coverage&&ze.has(t)&&c.coverage.hit(`bash:builtin:${t}`),t==="export")return Ns(c,s);if(t==="unset")return Bs(c,s);if(t==="exit")return ks(c,s);if(t==="local")return Ts(c,s);if(t==="set")return Ms(c,s);if(t==="break")return ts(c,s);if(t==="continue")return ps(c,s);if(t==="return")return Ls(c,s);if(t==="eval"&&c.state.options.posix)return It(c,s,r);if(t==="shift")return Ws(c,s);if(t==="getopts")return Rt(c,s);if(t==="compgen")return us(c,s);if(t==="complete")return ds(c,s);if(t==="compopt")return hs(c,s);if(t==="pushd")return await _s(c,s);if(t==="popd")return Cs(c,s);if(t==="dirs")return Ps(c,s);if(t==="source"||t===".")return Vs(c,s);if(t==="read")return Rs(c,s,r,a);if(t==="mapfile"||t==="readarray")return Is(c,s,r);if(t==="declare"||t==="typeset")return $s(c,s);if(t==="readonly")return Ss(c,s);if(!i){let u=c.state.functions.get(t);if(u)return Dt(c,u,s,r)}if(t==="eval")return It(c,s,r);if(t==="cd")return await ss(c,s);if(t===":"||t==="true")return L;if(t==="false")return U(!1);if(t==="let")return Ds(c,s);if(t==="command")return so(e,s,r);if(t==="builtin")return no(e,s,r);if(t==="shopt")return ur(c,s);if(t==="exec"){if(s.length===0)return L;let[u,...f]=s;return l(u,f,[],r,!1,!1,-1)}if(t==="wait")return L;if(t==="type")return await mr(c,s,u=>gr(c,u),u=>Mt(c,u));if(t==="hash")return Os(c,s);if(t==="help")return xs(c,s);if(t==="["||t==="test"){let u=s;if(t==="["){if(s[s.length-1]!=="]")return A("[: missing `]'\n",2);u=s.slice(0,-1)}return Xe(c,u)}return null}async function so(e,t,s){let{ctx:n,runCommand:r}=e;if(t.length===0)return L;let i=!1,o=!1,a=!1,c=t;for(;c.length>0&&c[0].startsWith("-");){let f=c[0];if(f==="--"){c=c.slice(1);break}for(let d of f.slice(1))d==="p"?i=!0:d==="V"?o=!0:d==="v"&&(a=!0);c=c.slice(1)}if(c.length===0)return L;if(a||o)return await yr(n,c,a,o);let[l,...u]=c;return r(l,u,[],s,!0,i,-1)}async function no(e,t,s){let{runCommand:n}=e;if(t.length===0)return L;let r=t;if(r[0]==="--"&&(r=r.slice(1),r.length===0))return L;let i=r[0];if(!ze.has(i))return A(`bash: builtin: ${i}: not a shell builtin
619
+ `),o=1}return C(r,i,o)}async function gr(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 o=`${r.startsWith("/")?r:e.fs.resolvePath(e.state.cwd,r)}/${t}`;if(await e.fs.exists(o)){try{if((await e.fs.stat(o)).isDirectory)continue}catch{continue}return`${r}/${t}`}}if(e.commands.has(t)){for(let r of n)if(r==="/usr/bin"||r==="/bin")return`${r}/${t}`;return`/usr/bin/${t}`}return null}async function wr(e,t,s,n,r,i,o,a){let{ctx:c,runCommand:l}=e;if(c.coverage&&ze.has(t)&&c.coverage.hit(`bash:builtin:${t}`),t==="export")return Ns(c,s);if(t==="unset")return Bs(c,s);if(t==="exit")return ks(c,s);if(t==="local")return Ts(c,s);if(t==="set")return Ms(c,s);if(t==="break")return ts(c,s);if(t==="continue")return ps(c,s);if(t==="return")return Ls(c,s);if(t==="eval"&&c.state.options.posix)return It(c,s,r);if(t==="shift")return Ws(c,s);if(t==="getopts")return Rt(c,s);if(t==="compgen")return us(c,s);if(t==="complete")return ds(c,s);if(t==="compopt")return hs(c,s);if(t==="pushd")return await _s(c,s);if(t==="popd")return Cs(c,s);if(t==="dirs")return Ps(c,s);if(t==="source"||t===".")return Vs(c,s);if(t==="read")return Rs(c,s,r,a);if(t==="mapfile"||t==="readarray")return Is(c,s,r);if(t==="declare"||t==="typeset")return Ss(c,s);if(t==="readonly")return $s(c,s);if(!i){let u=c.state.functions.get(t);if(u)return Dt(c,u,s,r)}if(t==="eval")return It(c,s,r);if(t==="cd")return await ss(c,s);if(t===":"||t==="true")return L;if(t==="false")return U(!1);if(t==="let")return Ds(c,s);if(t==="command")return so(e,s,r);if(t==="builtin")return no(e,s,r);if(t==="shopt")return ur(c,s);if(t==="exec"){if(s.length===0)return L;let[u,...f]=s;return l(u,f,[],r,!1,!1,-1)}if(t==="wait")return L;if(t==="type")return await mr(c,s,u=>gr(c,u),u=>Mt(c,u));if(t==="hash")return Os(c,s);if(t==="help")return xs(c,s);if(t==="["||t==="test"){let u=s;if(t==="["){if(s[s.length-1]!=="]")return A("[: missing `]'\n",2);u=s.slice(0,-1)}return Xe(c,u)}return null}async function so(e,t,s){let{ctx:n,runCommand:r}=e;if(t.length===0)return L;let i=!1,o=!1,a=!1,c=t;for(;c.length>0&&c[0].startsWith("-");){let f=c[0];if(f==="--"){c=c.slice(1);break}for(let d of f.slice(1))d==="p"?i=!0:d==="V"?o=!0:d==="v"&&(a=!0);c=c.slice(1)}if(c.length===0)return L;if(a||o)return await yr(n,c,a,o);let[l,...u]=c;return r(l,u,[],s,!0,i,-1)}async function no(e,t,s){let{runCommand:n}=e;if(t.length===0)return L;let r=t;if(r[0]==="--"&&(r=r.slice(1),r.length===0))return L;let i=r[0];if(!ze.has(i))return A(`bash: builtin: ${i}: not a shell builtin
620
620
  `);let[,...o]=r;return n(i,o,[],s,!0,!1,-1)}async function vr(e,t,s,n,r){let{ctx:i,buildExportedEnv:o,executeUserScript:a}=e,l=await fr(i,t,r?"/usr/bin:/bin":void 0);if(!l)return Pn(t)?A(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
621
621
  `,127):A(`bash: ${t}: command not found
622
622
  `,127);if("error"in l)return l.error==="permission_denied"?A(`bash: ${t}: Permission denied
@@ -625,16 +625,16 @@ ${e} ()
625
625
  `)}}async function Hs(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let n="",r="",i=0;try{for(let o of t){let a=await e.executeStatement(o);n+=a.stdout,r+=a.stderr,i=a.exitCode}}finally{e.state.inCondition=s}return{stdout:n,stderr:r,exitCode:i}}function et(e,t,s,n){if(e instanceof le)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 ce)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 ne||e instanceof ue||e instanceof V||e instanceof ee)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let r=Ee(e);return{action:"error",stdout:t,stderr:`${s}${r}
626
626
  `,exitCode:1}}async function Wt(e,t,s="",n=""){let r=s,i=n,o=0;try{for(let a of t){let c=await e.executeStatement(a);r+=c.stdout,i+=c.stderr,o=c.exitCode}}catch(a){if(ut(a)||a instanceof ue||a instanceof V||a instanceof ee||a instanceof Ae)throw a.prependOutput(r,i),a;return{stdout:r,stderr:`${i}${Ee(a)}
627
627
  `,exitCode:1}}return{stdout:r,stderr:i,exitCode:o}}async function br(e,t){let s="",n="";for(let r of t.clauses){let i=await Hs(e,r.condition);if(s+=i.stdout,n+=i.stderr,i.exitCode===0)return Wt(e,r.body,s,n)}return t.elseBody?Wt(e,t.elseBody,s,n):C(s,n,0)}async function Er(e,t){let s=await be(e,t.redirections);if(s)return s;let n="",r="",i=0,o=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return A(`bash: \`${t.variable}': not a valid identifier
628
- `);let a=[];if(t.words===null)a=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)a=[];else try{for(let l of t.words){let u=await we(e,l);a.push(...u.values)}}catch(l){if(l instanceof ct)return{stdout:"",stderr:l.stderr,exitCode:1};throw l}e.state.loopDepth++;try{for(let l of a){o++,o>e.limits.maxLoopIterations&&Se(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),e.state.env.set(t.variable,l);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=et(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=C(n,r,f.exitCode??1);return B(e,d,t.redirections)}throw f.error}}}finally{e.state.loopDepth--}let c=C(n,r,i);return B(e,c,t.redirections)}async function $r(e,t){let s=await be(e,t.redirections);if(s)return s;let n=t.line;n!==void 0&&(e.state.currentLine=n);let r="",i="",o=0,a=0;t.init&&await z(e,t.init.expression),e.state.loopDepth++;try{for(;a++,a>e.limits.maxLoopIterations&&Se(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,i),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await z(e,t.condition.expression)===0));){try{for(let l of t.body){let u=await e.executeStatement(l);r+=u.stdout,i+=u.stderr,o=u.exitCode}}catch(l){let u=et(l,r,i,e.state.loopDepth);if(r=u.stdout,i=u.stderr,u.action==="break")break;if(u.action==="continue"){t.update&&await z(e,t.update.expression);continue}if(u.action==="error"){let f=C(r,i,u.exitCode??1);return B(e,f,t.redirections)}throw u.error}t.update&&await z(e,t.update.expression)}}finally{e.state.loopDepth--}let c=C(r,i,o);return B(e,c,t.redirections)}async function Sr(e,t,s=""){let n="",r="",i=0,o=0,a=s;for(let l of t.redirections)if((l.operator==="<<"||l.operator==="<<-")&&l.target.type==="HereDoc"){let u=l.target,f=await T(e,u.content);u.stripTabs&&(f=f.split(`
628
+ `);let a=[];if(t.words===null)a=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)a=[];else try{for(let l of t.words){let u=await we(e,l);a.push(...u.values)}}catch(l){if(l instanceof ct)return{stdout:"",stderr:l.stderr,exitCode:1};throw l}e.state.loopDepth++;try{for(let l of a){o++,o>e.limits.maxLoopIterations&&$e(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r),e.state.env.set(t.variable,l);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=et(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=C(n,r,f.exitCode??1);return B(e,d,t.redirections)}throw f.error}}}finally{e.state.loopDepth--}let c=C(n,r,i);return B(e,c,t.redirections)}async function Sr(e,t){let s=await be(e,t.redirections);if(s)return s;let n=t.line;n!==void 0&&(e.state.currentLine=n);let r="",i="",o=0,a=0;t.init&&await z(e,t.init.expression),e.state.loopDepth++;try{for(;a++,a>e.limits.maxLoopIterations&&$e(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r,i),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await z(e,t.condition.expression)===0));){try{for(let l of t.body){let u=await e.executeStatement(l);r+=u.stdout,i+=u.stderr,o=u.exitCode}}catch(l){let u=et(l,r,i,e.state.loopDepth);if(r=u.stdout,i=u.stderr,u.action==="break")break;if(u.action==="continue"){t.update&&await z(e,t.update.expression);continue}if(u.action==="error"){let f=C(r,i,u.exitCode??1);return B(e,f,t.redirections)}throw u.error}t.update&&await z(e,t.update.expression)}}finally{e.state.loopDepth--}let c=C(r,i,o);return B(e,c,t.redirections)}async function $r(e,t,s=""){let n="",r="",i=0,o=0,a=s;for(let l of t.redirections)if((l.operator==="<<"||l.operator==="<<-")&&l.target.type==="HereDoc"){let u=l.target,f=await T(e,u.content);u.stripTabs&&(f=f.split(`
629
629
  `).map(d=>d.replace(/^\t+/,"")).join(`
630
630
  `)),a=f}else if(l.operator==="<<<"&&l.target.type==="Word")a=`${await T(e,l.target)}
631
631
  `;else if(l.operator==="<"&&l.target.type==="Word")try{let u=await T(e,l.target),f=e.fs.resolvePath(e.state.cwd,u);a=await e.fs.readFile(f)}catch{let u=await T(e,l.target);return A(`bash: ${u}: No such file or directory
632
- `)}let c=e.state.groupStdin;a&&(e.state.groupStdin=a),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&Se(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r);let l=0,u=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let m=await e.executeStatement(h);n+=m.stdout,r+=m.stderr,l=m.exitCode}}catch(h){if(h instanceof le){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 ce){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(l!==0)break;try{for(let h of t.body){let m=await e.executeStatement(h);n+=m.stdout,r+=m.stderr,i=m.exitCode}}catch(h){let m=et(h,n,r,e.state.loopDepth);if(n=m.stdout,r=m.stderr,m.action==="break")break;if(m.action==="continue")continue;if(m.action==="error")return C(n,r,m.exitCode??1);throw m.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=c}return C(n,r,i)}async function Ar(e,t){let s="",n="",r=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&Se(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,n);let o=await Hs(e,t.condition);if(s+=o.stdout,n+=o.stderr,o.exitCode===0)break;try{for(let a of t.body){let c=await e.executeStatement(a);s+=c.stdout,n+=c.stderr,r=c.exitCode}}catch(a){let c=et(a,s,n,e.state.loopDepth);if(s=c.stdout,n=c.stderr,c.action==="break")break;if(c.action==="continue")continue;if(c.action==="error")return C(s,n,c.exitCode??1);throw c.error}}}finally{e.state.loopDepth--}return C(s,n,r)}async function _r(e,t){let s=await be(e,t.redirections);if(s)return s;let n="",r="",i=0,o=await T(e,t.word),a=!1;for(let l=0;l<t.items.length;l++){let u=t.items[l],f=a;if(!a)for(let d of u.patterns){let h=await T(e,d);un(d)&&(h=ln(h));let m=e.state.shoptOptions.nocasematch,p=e.state.shoptOptions.extglob;if(We(o,h,m,p)){f=!0;break}}if(f){let d=await Wt(e,u.body,n,r);if(n=d.stdout,r=d.stderr,i=d.exitCode,u.terminator===";;")break;u.terminator===";&"?a=!0:a=!1}else a=!1}let c=C(n,r,i);return B(e,c,t.redirections)}function Us(e,t){if(e.parts.length!==1)return!1;let s=e.parts[0];return s.type!=="Literal"?!1:t.includes(s.value)}function Cr(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),o=r+n+1,a=t.slice(o),c=a.indexOf(":");if(c===-1)return null;let l=Number.parseInt(a.slice(0,c),10);if(Number.isNaN(l)||l<0)return null;let u=a.slice(c+1);return{path:i,position:l,content:u}}var Pr="+ ";async function kr(e){let t=e.state.env.get("PS4");if(t===void 0)return Pr;if(t==="")return"";try{let n=new W().parseWordFromString(t,!1,!1);return await T(e,n)}catch{return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
632
+ `)}let c=e.state.groupStdin;a&&(e.state.groupStdin=a),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&$e(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n,r);let l=0,u=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let h of t.condition){let m=await e.executeStatement(h);n+=m.stdout,r+=m.stderr,l=m.exitCode}}catch(h){if(h instanceof le){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 ce){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(l!==0)break;try{for(let h of t.body){let m=await e.executeStatement(h);n+=m.stdout,r+=m.stderr,i=m.exitCode}}catch(h){let m=et(h,n,r,e.state.loopDepth);if(n=m.stdout,r=m.stderr,m.action==="break")break;if(m.action==="continue")continue;if(m.action==="error")return C(n,r,m.exitCode??1);throw m.error}}}}finally{e.state.loopDepth--,e.state.groupStdin=c}return C(n,r,i)}async function Ar(e,t){let s="",n="",r=0,i=0;e.state.loopDepth++;try{for(;;){i++,i>e.limits.maxLoopIterations&&$e(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s,n);let o=await Hs(e,t.condition);if(s+=o.stdout,n+=o.stderr,o.exitCode===0)break;try{for(let a of t.body){let c=await e.executeStatement(a);s+=c.stdout,n+=c.stderr,r=c.exitCode}}catch(a){let c=et(a,s,n,e.state.loopDepth);if(s=c.stdout,n=c.stderr,c.action==="break")break;if(c.action==="continue")continue;if(c.action==="error")return C(s,n,c.exitCode??1);throw c.error}}}finally{e.state.loopDepth--}return C(s,n,r)}async function _r(e,t){let s=await be(e,t.redirections);if(s)return s;let n="",r="",i=0,o=await T(e,t.word),a=!1;for(let l=0;l<t.items.length;l++){let u=t.items[l],f=a;if(!a)for(let d of u.patterns){let h=await T(e,d);un(d)&&(h=ln(h));let m=e.state.shoptOptions.nocasematch,p=e.state.shoptOptions.extglob;if(We(o,h,m,p)){f=!0;break}}if(f){let d=await Wt(e,u.body,n,r);if(n=d.stdout,r=d.stderr,i=d.exitCode,u.terminator===";;")break;u.terminator===";&"?a=!0:a=!1}else a=!1}let c=C(n,r,i);return B(e,c,t.redirections)}function Us(e,t){if(e.parts.length!==1)return!1;let s=e.parts[0];return s.type!=="Literal"?!1:t.includes(s.value)}function Cr(e){if(!e.startsWith("__rw__:"))return null;let t=e.slice(7),s=t.indexOf(":");if(s===-1)return null;let n=Number.parseInt(t.slice(0,s),10);if(Number.isNaN(n)||n<0)return null;let r=s+1,i=t.slice(r,r+n),o=r+n+1,a=t.slice(o),c=a.indexOf(":");if(c===-1)return null;let l=Number.parseInt(a.slice(0,c),10);if(Number.isNaN(l)||l<0)return null;let u=a.slice(c+1);return{path:i,position:l,content:u}}var Pr="+ ";async function kr(e){let t=e.state.env.get("PS4");if(t===void 0)return Pr;if(t==="")return"";try{let n=new W().parseWordFromString(t,!1,!1);return await T(e,n)}catch{return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
633
633
  `,t||Pr}}function ro(e){return e.map(t=>io(t)).join(" ")}function io(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let s=/[\x00-\x1f\x7f]/.test(e),n=e.includes(`
634
634
  `),r=e.includes(" "),i=e.includes("\\"),o=e.includes("'");if(s||n||r||i){let c="";for(let l of e){let u=l.charCodeAt(0);l===`
635
635
  `?c+="\\n":l===" "?c+="\\t":l==="\\"?c+="\\\\":l==="'"?c+="'":l==='"'?c+='"':u<32||u===127?u<256?c+=`\\x${u.toString(16).padStart(2,"0")}`:c+=`\\u${u.toString(16).padStart(4,"0")}`:c+=l}return`$'${c}'`}return o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function Nr(e,t,s){if(!e.state.options.xtrace)return"";let n=await kr(e),r=[t,...s],i=ro(r);return`${n}${i}
636
636
  `}async function Or(e,t,s){return e.state.options.xtrace?`${await kr(e)}${t}=${s}
637
- `:""}async function xr(e,t,s){let n=t.timed?performance.now():0,r="",i=L,o=0,a=[],c=t.commands.length>1,l=e.state.lastArg;for(let f=0;f<t.commands.length;f++){let d=t.commands[f],h=f===t.commands.length-1;c&&(e.state.lastArg="");let p=c&&(!h||!e.state.shoptOptions.lastpipe)?new Map(e.state.env):null,g;try{g=await s(d,r)}catch(S){if(S instanceof lt)g={stdout:S.stdout,stderr:S.stderr,exitCode:1};else if(S instanceof V&&t.commands.length>1)g={stdout:S.stdout,stderr:S.stderr,exitCode:S.exitCode};else if(S instanceof ue&&t.commands.length>1)g={stdout:S.stdout,stderr:S.stderr,exitCode:S.exitCode};else throw p&&(e.state.env=p),S}p&&(e.state.env=p),a.push(g.exitCode),g.exitCode!==0&&(o=g.exitCode),h?i=g:t.pipeStderr?.[f]??!1?(r=g.stderr+g.stdout,i={stdout:"",stderr:"",exitCode:g.exitCode}):(r=g.stdout,i={stdout:"",stderr:g.stderr,exitCode:g.exitCode})}if(t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let f of e.state.env.keys())f.startsWith("PIPESTATUS_")&&e.state.env.delete(f);for(let f=0;f<a.length;f++)e.state.env.set(`PIPESTATUS_${f}`,String(a[f]));e.state.env.set("PIPESTATUS__length",String(a.length))}if(e.state.options.pipefail&&o!==0&&(i={...i,exitCode:o}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let d=(performance.now()-n)/1e3,h=Math.floor(d/60),m=d%60,p;t.timePosix?p=`real ${d.toFixed(2)}
637
+ `:""}async function xr(e,t,s){let n=t.timed?performance.now():0,r="",i=L,o=0,a=[],c=t.commands.length>1,l=e.state.lastArg;for(let f=0;f<t.commands.length;f++){let d=t.commands[f],h=f===t.commands.length-1;c&&(e.state.lastArg="");let p=c&&(!h||!e.state.shoptOptions.lastpipe)?new Map(e.state.env):null,g;try{g=await s(d,r)}catch($){if($ instanceof lt)g={stdout:$.stdout,stderr:$.stderr,exitCode:1};else if($ instanceof V&&t.commands.length>1)g={stdout:$.stdout,stderr:$.stderr,exitCode:$.exitCode};else if($ instanceof ue&&t.commands.length>1)g={stdout:$.stdout,stderr:$.stderr,exitCode:$.exitCode};else throw p&&(e.state.env=p),$}p&&(e.state.env=p),a.push(g.exitCode),g.exitCode!==0&&(o=g.exitCode),h?i=g:t.pipeStderr?.[f]??!1?(r=g.stderr+g.stdout,i={stdout:"",stderr:"",exitCode:g.exitCode}):(r=g.stdout,i={stdout:"",stderr:g.stderr,exitCode:g.exitCode})}if(t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand"){for(let f of e.state.env.keys())f.startsWith("PIPESTATUS_")&&e.state.env.delete(f);for(let f=0;f<a.length;f++)e.state.env.set(`PIPESTATUS_${f}`,String(a[f]));e.state.env.set("PIPESTATUS__length",String(a.length))}if(e.state.options.pipefail&&o!==0&&(i={...i,exitCode:o}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let d=(performance.now()-n)/1e3,h=Math.floor(d/60),m=d%60,p;t.timePosix?p=`real ${d.toFixed(2)}
638
638
  user 0.00
639
639
  sys 0.00
640
640
  `:p=`
@@ -652,7 +652,7 @@ sys 0m0.000s
652
652
  `,1)}}if(r=Math.max(...i.map(([a])=>typeof a=="number"?a:0))+1+r,r<0){let a=e.state.currentLine;return{index:0,error:C("",`bash: line ${a}: ${t}[${s}]: bad array subscript
653
653
  `,1)}}}return{index:r}}async function po(e,t,s,n,r,i){let o="",a=s,c=null;if(fe(e,s)){let f=an(e,s,n);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:C("",`bash: ${s}: circular name reference
654
654
  `,1)};if(f===null)return{continueToNext:!0,xtraceOutput:""};a=f;let d=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(c={arrayName:d[1],subscriptExpr:d[2]},a=d[1])}if(De(e,a)){if(t.name)return o+=`bash: ${a}: readonly variable
655
- `,{continueToNext:!0,xtraceOutput:o};let f=K(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l;if(Ye(e,a))try{let f=new W;if(r){let h=`(${e.state.env.get(a)||"0"}) + (${n})`,m=q(f,h);l=String(await z(e,m.expression))}else{let d=q(f,n);l=String(await z(e,d.expression))}}catch{l="0"}else{let{isArray:f}=await import("./chunks/expansion-HIAVHGBZ.js"),d=f(e,a)?`${a}_0`:a;l=r?(e.state.env.get(d)||"")+n:n}l=je(e,a,l),o+=await Or(e,a,l);let u=a;if(c)u=await mo(e,c);else{let{isArray:f}=await import("./chunks/expansion-HIAVHGBZ.js");f(e,a)&&(u=`${a}_0`)}return t.name?(i.set(u,e.state.env.get(u)),e.state.env.set(u,l)):(e.state.env.set(u,l),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(a)),e.state.tempEnvBindings?.some(f=>f.has(a))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(a))),{continueToNext:!1,xtraceOutput:o}}async function mo(e,t){let{arrayName:s,subscriptExpr:n}=t;if(e.state.associativeArrays?.has(s))return Tr(e,s,n);let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else{try{let o=new W,a=q(o,n);i=await z(e,a.expression,!1)}catch{let o=e.state.env.get(n);i=o?Number.parseInt(o,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let o=pe(e,s);o.length>0&&(i=Math.max(...o.map(c=>c[0]))+1+i)}return`${s}_${i}`}async function Ir(e,t,s,n){let r=await be(e,t.redirections);if(r)return r;let i=new Map(e.state.env),o=e.state.cwd,a={...e.state.options},c=new Map(e.state.functions),l=e.state.localScopes,u=e.state.localVarStack,f=e.state.localVarDepth,d=e.state.fullyUnsetLocals;if(e.state.localScopes=l.map(E=>new Map(E)),u){e.state.localVarStack=new Map;for(let[E,D]of u.entries())e.state.localVarStack.set(E,D.map(N=>({...N})))}f&&(e.state.localVarDepth=new Map(f)),d&&(e.state.fullyUnsetLocals=new Map(d));let h=e.state.loopDepth,m=e.state.parentHasLoopContext;e.state.parentHasLoopContext=h>0,e.state.loopDepth=0;let p=e.state.lastArg,g=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let S=e.state.groupStdin;s&&(e.state.groupStdin=s);let v="",P="",y=0,w=()=>{e.state.env=i,e.state.cwd=o,e.state.options=a,e.state.functions=c,e.state.localScopes=l,e.state.localVarStack=u,e.state.localVarDepth=f,e.state.fullyUnsetLocals=d,e.state.loopDepth=h,e.state.parentHasLoopContext=m,e.state.groupStdin=S,e.state.bashPid=g,e.state.lastArg=p};try{for(let E of t.body){let D=await n(E);v+=D.stdout,P+=D.stderr,y=D.exitCode}}catch(E){if(w(),E instanceof ee)throw E;if(E instanceof Ae){v+=E.stdout,P+=E.stderr;let N=C(v,P,0);return B(e,N,t.redirections)}if(E instanceof le||E instanceof ce){v+=E.stdout,P+=E.stderr;let N=C(v,P,0);return B(e,N,t.redirections)}if(E instanceof V){v+=E.stdout,P+=E.stderr;let N=C(v,P,E.exitCode);return B(e,N,t.redirections)}if(E instanceof ne){v+=E.stdout,P+=E.stderr;let N=C(v,P,E.exitCode);return B(e,N,t.redirections)}if(E instanceof ue){let N=C(v+E.stdout,P+E.stderr,E.exitCode);return B(e,N,t.redirections)}let D=C(v,`${P}${Ee(E)}
655
+ `,{continueToNext:!0,xtraceOutput:o};let f=K(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l;if(Ye(e,a))try{let f=new W;if(r){let h=`(${e.state.env.get(a)||"0"}) + (${n})`,m=q(f,h);l=String(await z(e,m.expression))}else{let d=q(f,n);l=String(await z(e,d.expression))}}catch{l="0"}else{let{isArray:f}=await import("./chunks/expansion-TL4Q62VX.js"),d=f(e,a)?`${a}_0`:a;l=r?(e.state.env.get(d)||"")+n:n}l=je(e,a,l),o+=await Or(e,a,l);let u=a;if(c)u=await mo(e,c);else{let{isArray:f}=await import("./chunks/expansion-TL4Q62VX.js");f(e,a)&&(u=`${a}_0`)}return t.name?(i.set(u,e.state.env.get(u)),e.state.env.set(u,l)):(e.state.env.set(u,l),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(a)),e.state.tempEnvBindings?.some(f=>f.has(a))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(a))),{continueToNext:!1,xtraceOutput:o}}async function mo(e,t){let{arrayName:s,subscriptExpr:n}=t;if(e.state.associativeArrays?.has(s))return Tr(e,s,n);let i;if(/^-?\d+$/.test(n))i=Number.parseInt(n,10);else{try{let o=new W,a=q(o,n);i=await z(e,a.expression,!1)}catch{let o=e.state.env.get(n);i=o?Number.parseInt(o,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let o=pe(e,s);o.length>0&&(i=Math.max(...o.map(c=>c[0]))+1+i)}return`${s}_${i}`}async function Ir(e,t,s,n){let r=await be(e,t.redirections);if(r)return r;let i=new Map(e.state.env),o=e.state.cwd,a={...e.state.options},c=new Map(e.state.functions),l=e.state.localScopes,u=e.state.localVarStack,f=e.state.localVarDepth,d=e.state.fullyUnsetLocals;if(e.state.localScopes=l.map(E=>new Map(E)),u){e.state.localVarStack=new Map;for(let[E,D]of u.entries())e.state.localVarStack.set(E,D.map(N=>({...N})))}f&&(e.state.localVarDepth=new Map(f)),d&&(e.state.fullyUnsetLocals=new Map(d));let h=e.state.loopDepth,m=e.state.parentHasLoopContext;e.state.parentHasLoopContext=h>0,e.state.loopDepth=0;let p=e.state.lastArg,g=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let $=e.state.groupStdin;s&&(e.state.groupStdin=s);let v="",P="",y=0,w=()=>{e.state.env=i,e.state.cwd=o,e.state.options=a,e.state.functions=c,e.state.localScopes=l,e.state.localVarStack=u,e.state.localVarDepth=f,e.state.fullyUnsetLocals=d,e.state.loopDepth=h,e.state.parentHasLoopContext=m,e.state.groupStdin=$,e.state.bashPid=g,e.state.lastArg=p};try{for(let E of t.body){let D=await n(E);v+=D.stdout,P+=D.stderr,y=D.exitCode}}catch(E){if(w(),E instanceof ee)throw E;if(E instanceof Ae){v+=E.stdout,P+=E.stderr;let N=C(v,P,0);return B(e,N,t.redirections)}if(E instanceof le||E instanceof ce){v+=E.stdout,P+=E.stderr;let N=C(v,P,0);return B(e,N,t.redirections)}if(E instanceof V){v+=E.stdout,P+=E.stderr;let N=C(v,P,E.exitCode);return B(e,N,t.redirections)}if(E instanceof ne){v+=E.stdout,P+=E.stderr;let N=C(v,P,E.exitCode);return B(e,N,t.redirections)}if(E instanceof ue){let N=C(v+E.stdout,P+E.stderr,E.exitCode);return B(e,N,t.redirections)}let D=C(v,`${P}${Ee(E)}
656
656
  `,1);return B(e,D,t.redirections)}w();let b=C(v,P,y);return B(e,b,t.redirections)}async function Rr(e,t,s,n){let r="",i="",o=0,a=await xt(e,t.redirections);if(a)return a;let c=s;for(let f of t.redirections)if((f.operator==="<<"||f.operator==="<<-")&&f.target.type==="HereDoc"){let d=f.target,h=await T(e,d.content);d.stripTabs&&(h=h.split(`
657
657
  `).map(p=>p.replace(/^\t+/,"")).join(`
658
658
  `));let m=f.fd??0;m!==0?(e.state.fileDescriptors||(e.state.fileDescriptors=new Map),e.state.fileDescriptors.set(m,h)):c=h}else if(f.operator==="<<<"&&f.target.type==="Word")c=`${await T(e,f.target)}
@@ -660,23 +660,23 @@ sys 0m0.000s
660
660
  `,1)}let l=e.state.groupStdin;c&&(e.state.groupStdin=c);try{for(let f of t.body){let d=await n(f);r+=d.stdout,i+=d.stderr,o=d.exitCode}}catch(f){if(e.state.groupStdin=l,f instanceof ee)throw f;if(ut(f)||f instanceof ue||f instanceof V)throw f.prependOutput(r,i),f;return C(r,`${i}${Ee(f)}
661
661
  `,1)}e.state.groupStdin=l;let u=C(r,i,o);return B(e,u,t.redirections)}async function Lr(e,t,s,n,r){let i;try{i=await e.fs.readFile(t)}catch{return A(`bash: ${t}: No such file or directory
662
662
  `,127)}if(i.startsWith("#!")){let g=i.indexOf(`
663
- `);g!==-1&&(i=i.slice(g+1))}let o=new Map(e.state.env),a=e.state.cwd,c={...e.state.options},l=e.state.loopDepth,u=e.state.parentHasLoopContext,f=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,m=e.state.currentSource;e.state.parentHasLoopContext=l>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,n&&(e.state.groupStdin=n),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(s.length)),e.state.env.set("@",s.join(" ")),e.state.env.set("*",s.join(" "));for(let g=0;g<s.length&&g<9;g++)e.state.env.set(String(g+1),s[g]);for(let g=s.length+1;g<=9;g++)e.state.env.delete(String(g));let p=()=>{e.state.env=o,e.state.cwd=a,e.state.options=c,e.state.loopDepth=l,e.state.parentHasLoopContext=u,e.state.lastArg=f,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=m};try{let S=new W().parse(i),v=await r(S);return p(),v}catch(g){if(p(),g instanceof V||g instanceof ee)throw g;if(g.name==="ParseException")return A(`bash: ${t}: ${g.message}
664
- `);throw g}}var tt=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage}}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,n=new Set;if(t)for(let i of t)n.add(i);if(s)for(let i of s)n.add(i);if(n.size===0)return Object.create(null);let r=Object.create(null);for(let i of n){let o=this.ctx.state.env.get(i);o!==void 0&&(r[i]=o)}return r}async executeScript(t){let s="",n="",r=0;for(let i of t.statements)try{let o=await this.executeStatement(i);s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}catch(o){if(o instanceof V)throw o.prependOutput(s,n),o;if(o instanceof de)return s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:_e(this.ctx.state.env)};if(o instanceof ee)throw o;if(o instanceof ue)return s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:_e(this.ctx.state.env)};if(o instanceof Xs)return s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:_e(this.ctx.state.env)};if(o instanceof lt)return s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:_e(this.ctx.state.env)};if(o instanceof xe){s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(o instanceof Ys){s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(o instanceof le||o instanceof ce){if(this.ctx.state.loopDepth>0)throw o.prependOutput(s,n),o;s+=o.stdout,n+=o.stderr;continue}throw o instanceof ne&&o.prependOutput(s,n),o}return{stdout:s,stderr:n,exitCode:r,env:_e(this.ctx.state.env)}}async executeUserScript(t,s,n=""){return Lr(this.ctx,t,s,n,r=>this.executeScript(r))}async executeStatement(t){if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&Se(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new ft(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return L;this.ctx.state.errexitSafe=!1;let s="",n="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(n+=`${t.sourceText}
665
- `);let r=0,i=-1,o=!1;for(let l=0;l<t.pipelines.length;l++){let u=t.pipelines[l],f=l>0?t.operators[l-1]:null;if(f==="&&"&&r!==0||f==="||"&&r===0)continue;let d=await this.executePipeline(u);s+=d.stdout,n+=d.stderr,r=d.exitCode,i=l,o=u.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}let a=i<t.pipelines.length-1,c=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=a||o||c,this.ctx.state.options.errexit&&r!==0&&i===t.pipelines.length-1&&!o&&!this.ctx.state.inCondition&&!c)throw new ue(r,s,n);return C(s,n,r)}async executePipeline(t){return xr(this.ctx,t,(s,n)=>this.executeCommand(s,n))}async executeCommand(t,s){switch(this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return br(this.ctx,t);case"For":return Er(this.ctx,t);case"CStyleFor":return $r(this.ctx,t);case"While":return Sr(this.ctx,t,s);case"Until":return Ar(this.ctx,t);case"Case":return _r(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return Bn(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return L}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(n){if(n instanceof ct)return A(n.stderr);throw n}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let y=t,w=100;for(;w>0;){let b=this.expandAlias(y);if(b===y)break;y=b,w--}this.aliasExpansionStack.clear(),y!==t&&(t=y)}this.ctx.state.expansionStderr="";let n=await Dr(this.ctx,t);if(n.error)return n.error;let r=n.tempAssignments,i=n.xtraceOutput;if(!t.name){if(t.redirections.length>0){let w=await be(this.ctx,t.redirections);if(w)return w;let b=C("",i,0);return B(this.ctx,b,t.redirections)}this.ctx.state.lastArg="";let y=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",C("",y,this.ctx.state.lastExitCode)}let o=t.name&&Us(t.name,["local","declare","typeset","export","readonly"]),a=Array.from(r.keys());if(a.length>0&&!o){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let y of a)this.ctx.state.tempExportedVars.add(y)}let c=await xt(this.ctx,t.redirections);if(c){for(let[y,w]of r)w===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,w);return c}let l=-1;for(let y of t.redirections){if((y.operator==="<<"||y.operator==="<<-")&&y.target.type==="HereDoc"){let w=y.target,b=await T(this.ctx,w.content);w.stripTabs&&(b=b.split(`
663
+ `);g!==-1&&(i=i.slice(g+1))}let o=new Map(e.state.env),a=e.state.cwd,c={...e.state.options},l=e.state.loopDepth,u=e.state.parentHasLoopContext,f=e.state.lastArg,d=e.state.bashPid,h=e.state.groupStdin,m=e.state.currentSource;e.state.parentHasLoopContext=l>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,n&&(e.state.groupStdin=n),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(s.length)),e.state.env.set("@",s.join(" ")),e.state.env.set("*",s.join(" "));for(let g=0;g<s.length&&g<9;g++)e.state.env.set(String(g+1),s[g]);for(let g=s.length+1;g<=9;g++)e.state.env.delete(String(g));let p=()=>{e.state.env=o,e.state.cwd=a,e.state.options=c,e.state.loopDepth=l,e.state.parentHasLoopContext=u,e.state.lastArg=f,e.state.bashPid=d,e.state.groupStdin=h,e.state.currentSource=m};try{let $=new W().parse(i),v=await r($);return p(),v}catch(g){if(p(),g instanceof V||g instanceof ee)throw g;if(g.name==="ParseException")return A(`bash: ${t}: ${g.message}
664
+ `);throw g}}var tt=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage}}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,n=new Set;if(t)for(let i of t)n.add(i);if(s)for(let i of s)n.add(i);if(n.size===0)return Object.create(null);let r=Object.create(null);for(let i of n){let o=this.ctx.state.env.get(i);o!==void 0&&(r[i]=o)}return r}async executeScript(t){let s="",n="",r=0;for(let i of t.statements)try{let o=await this.executeStatement(i);s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}catch(o){if(o instanceof V)throw o.prependOutput(s,n),o;if(o instanceof de)return s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:_e(this.ctx.state.env)};if(o instanceof ee)throw o;if(o instanceof ue)return s+=o.stdout,n+=o.stderr,r=o.exitCode,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:_e(this.ctx.state.env)};if(o instanceof Xs)return s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:_e(this.ctx.state.env)};if(o instanceof lt)return s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r)),{stdout:s,stderr:n,exitCode:r,env:_e(this.ctx.state.env)};if(o instanceof xe){s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(o instanceof Ys){s+=o.stdout,n+=o.stderr,r=1,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r));continue}if(o instanceof le||o instanceof ce){if(this.ctx.state.loopDepth>0)throw o.prependOutput(s,n),o;s+=o.stdout,n+=o.stderr;continue}throw o instanceof ne&&o.prependOutput(s,n),o}return{stdout:s,stderr:n,exitCode:r,env:_e(this.ctx.state.env)}}async executeUserScript(t,s,n=""){return Lr(this.ctx,t,s,n,r=>this.executeScript(r))}async executeStatement(t){if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&$e(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new ft(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return L;this.ctx.state.errexitSafe=!1;let s="",n="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(n+=`${t.sourceText}
665
+ `);let r=0,i=-1,o=!1;for(let l=0;l<t.pipelines.length;l++){let u=t.pipelines[l],f=l>0?t.operators[l-1]:null;if(f==="&&"&&r!==0||f==="||"&&r===0)continue;let d=await this.executePipeline(u);s+=d.stdout,n+=d.stderr,r=d.exitCode,i=l,o=u.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}let a=i<t.pipelines.length-1,c=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=a||o||c,this.ctx.state.options.errexit&&r!==0&&i===t.pipelines.length-1&&!o&&!this.ctx.state.inCondition&&!c)throw new ue(r,s,n);return C(s,n,r)}async executePipeline(t){return xr(this.ctx,t,(s,n)=>this.executeCommand(s,n))}async executeCommand(t,s){switch(this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return br(this.ctx,t);case"For":return Er(this.ctx,t);case"CStyleFor":return Sr(this.ctx,t);case"While":return $r(this.ctx,t,s);case"Until":return Ar(this.ctx,t);case"Case":return _r(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return Bn(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return L}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(n){if(n instanceof ct)return A(n.stderr);throw n}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let y=t,w=100;for(;w>0;){let b=this.expandAlias(y);if(b===y)break;y=b,w--}this.aliasExpansionStack.clear(),y!==t&&(t=y)}this.ctx.state.expansionStderr="";let n=await Dr(this.ctx,t);if(n.error)return n.error;let r=n.tempAssignments,i=n.xtraceOutput;if(!t.name){if(t.redirections.length>0){let w=await be(this.ctx,t.redirections);if(w)return w;let b=C("",i,0);return B(this.ctx,b,t.redirections)}this.ctx.state.lastArg="";let y=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",C("",y,this.ctx.state.lastExitCode)}let o=t.name&&Us(t.name,["local","declare","typeset","export","readonly"]),a=Array.from(r.keys());if(a.length>0&&!o){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let y of a)this.ctx.state.tempExportedVars.add(y)}let c=await xt(this.ctx,t.redirections);if(c){for(let[y,w]of r)w===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,w);return c}let l=-1;for(let y of t.redirections){if((y.operator==="<<"||y.operator==="<<-")&&y.target.type==="HereDoc"){let w=y.target,b=await T(this.ctx,w.content);w.stripTabs&&(b=b.split(`
666
666
  `).map(D=>D.replace(/^\t+/,"")).join(`
667
667
  `));let E=y.fd??0;E!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),this.ctx.state.fileDescriptors.set(E,b)):s=b;continue}if(y.operator==="<<<"&&y.target.type==="Word"){s=`${await T(this.ctx,y.target)}
668
668
  `;continue}if(y.operator==="<"&&y.target.type==="Word")try{let w=await T(this.ctx,y.target),b=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);s=await this.ctx.fs.readFile(b)}catch{let w=await T(this.ctx,y.target);for(let[b,E]of r)E===void 0?this.ctx.state.env.delete(b):this.ctx.state.env.set(b,E);return A(`bash: ${w}: No such file or directory
669
669
  `)}if(y.operator==="<&"&&y.target.type==="Word"){let w=await T(this.ctx,y.target),b=Number.parseInt(w,10);if(!Number.isNaN(b)&&this.ctx.state.fileDescriptors){let E=this.ctx.state.fileDescriptors.get(b);if(E!==void 0)if(E.startsWith("__rw__:")){let D=Cr(E);D&&(s=D.content.slice(D.position),l=b)}else E.startsWith("__file__:")||E.startsWith("__file_append__:")||(s=E)}}}let u=await T(this.ctx,t.name),f=[],d=[];if(Us(t.name,["local","declare","typeset","export","readonly"])&&(u==="local"||u==="declare"||u==="typeset"||u==="export"||u==="readonly"))for(let y of t.args){let w=await _n(this.ctx,y);if(w)f.push(w),d.push(!0);else{let b=await Cn(this.ctx,y);if(b!==null)f.push(b),d.push(!0);else{let E=await we(this.ctx,y);for(let D of E.values)f.push(D),d.push(E.quoted)}}}else for(let y of t.args){let w=await we(this.ctx,y);for(let b of w.values)f.push(b),d.push(w.quoted)}if(!u){if(t.name.parts.every(w=>w.type==="CommandSubstitution"||w.type==="ParameterExpansion"||w.type==="ArithmeticExpansion")){if(f.length>0){let w=f.shift();return d.shift(),await this.runCommand(w,f,d,s,!1,!1,l)}return C("","",this.ctx.state.lastExitCode)}return A(`bash: : command not found
670
670
  `,127)}if(u==="exec"&&(f.length===0||f[0]==="--")){for(let y of t.redirections){if(y.target.type==="HereDoc"||y.fdVariable)continue;let w=await T(this.ctx,y.target),b=y.fd??(y.operator==="<"||y.operator==="<>"?0:1);switch(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),y.operator){case">":case">|":{let E=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);await this.ctx.fs.writeFile(E,"","utf8"),this.ctx.state.fileDescriptors.set(b,`__file__:${E}`);break}case">>":{let E=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);this.ctx.state.fileDescriptors.set(b,`__file_append__:${E}`);break}case"<":{let E=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);try{let D=await this.ctx.fs.readFile(E);this.ctx.state.fileDescriptors.set(b,D)}catch{return A(`bash: ${w}: No such file or directory
671
- `)}break}case"<>":{let E=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);try{let D=await this.ctx.fs.readFile(E);this.ctx.state.fileDescriptors.set(b,`__rw__:${E.length}:${E}:0:${D}`)}catch{await this.ctx.fs.writeFile(E,"","utf8"),this.ctx.state.fileDescriptors.set(b,`__rw__:${E.length}:${E}:0:`)}break}case">&":{if(w==="-")this.ctx.state.fileDescriptors.delete(b);else if(w.endsWith("-")){let E=w.slice(0,-1),D=Number.parseInt(E,10);if(!Number.isNaN(D)){let N=this.ctx.state.fileDescriptors.get(D);N!==void 0?this.ctx.state.fileDescriptors.set(b,N):this.ctx.state.fileDescriptors.set(b,`__dupout__:${D}`),this.ctx.state.fileDescriptors.delete(D)}}else{let E=Number.parseInt(w,10);Number.isNaN(E)||this.ctx.state.fileDescriptors.set(b,`__dupout__:${E}`)}break}case"<&":{if(w==="-")this.ctx.state.fileDescriptors.delete(b);else if(w.endsWith("-")){let E=w.slice(0,-1),D=Number.parseInt(E,10);if(!Number.isNaN(D)){let N=this.ctx.state.fileDescriptors.get(D);N!==void 0?this.ctx.state.fileDescriptors.set(b,N):this.ctx.state.fileDescriptors.set(b,`__dupin__:${D}`),this.ctx.state.fileDescriptors.delete(D)}}else{let E=Number.parseInt(w,10);Number.isNaN(E)||this.ctx.state.fileDescriptors.set(b,`__dupin__:${E}`)}break}}}for(let[y,w]of r)w===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,w);if(this.ctx.state.tempExportedVars)for(let y of r.keys())this.ctx.state.tempExportedVars.delete(y);return L}let m=await Nr(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,g=null;try{p=await this.runCommand(u,f,d,s,!1,!1,l)}catch(y){if(y instanceof le||y instanceof ce)g=y,p=L;else throw y}let S=i+m;if(S&&(p={...p,stderr:S+p.stderr}),p=await B(this.ctx,p,t.redirections),g)throw g;if(f.length>0){let y=f[f.length-1];if((u==="declare"||u==="local"||u==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(y)){let w=y.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);w&&(y=w[1])}this.ctx.state.lastArg=y}else this.ctx.state.lastArg=u;let v=Vn(u)&&u!=="unset"&&u!=="eval";if(!this.ctx.state.options.posix||!v)for(let[y,w]of r)this.ctx.state.fullyUnsetLocals?.has(y)||(w===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,w));if(this.ctx.state.tempExportedVars)for(let y of r.keys())this.ctx.state.tempExportedVars.delete(y);return r.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(p={...p,stderr:this.ctx.state.expansionStderr+p.stderr},this.ctx.state.expansionStderr=""),p}async runCommand(t,s,n,r,i=!1,o=!1,a=-1){let c={ctx:this.ctx,runCommand:(u,f,d,h,m,p,g)=>this.runCommand(u,f,d,h,m,p,g),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(u,f,d)=>this.executeUserScript(u,f,d)},l=await wr(c,t,s,n,r,i,o,a);return l!==null?l:vr(c,t,s,r,o)}aliasExpansionStack=new Set;expandAlias(t){return es(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return Mt(this.ctx,t)}async executeSubshell(t,s=""){return Ir(this.ctx,t,s,n=>this.executeStatement(n))}async executeGroup(t,s=""){return Rr(this.ctx,t,s,n=>this.executeStatement(n))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await be(this.ctx,t.redirections);if(s)return s;try{let n=await z(this.ctx,t.expression.expression),r=U(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),B(this.ctx,r,t.redirections)}catch(n){let r=A(`bash: arithmetic expression: ${n.message}
671
+ `)}break}case"<>":{let E=this.ctx.fs.resolvePath(this.ctx.state.cwd,w);try{let D=await this.ctx.fs.readFile(E);this.ctx.state.fileDescriptors.set(b,`__rw__:${E.length}:${E}:0:${D}`)}catch{await this.ctx.fs.writeFile(E,"","utf8"),this.ctx.state.fileDescriptors.set(b,`__rw__:${E.length}:${E}:0:`)}break}case">&":{if(w==="-")this.ctx.state.fileDescriptors.delete(b);else if(w.endsWith("-")){let E=w.slice(0,-1),D=Number.parseInt(E,10);if(!Number.isNaN(D)){let N=this.ctx.state.fileDescriptors.get(D);N!==void 0?this.ctx.state.fileDescriptors.set(b,N):this.ctx.state.fileDescriptors.set(b,`__dupout__:${D}`),this.ctx.state.fileDescriptors.delete(D)}}else{let E=Number.parseInt(w,10);Number.isNaN(E)||this.ctx.state.fileDescriptors.set(b,`__dupout__:${E}`)}break}case"<&":{if(w==="-")this.ctx.state.fileDescriptors.delete(b);else if(w.endsWith("-")){let E=w.slice(0,-1),D=Number.parseInt(E,10);if(!Number.isNaN(D)){let N=this.ctx.state.fileDescriptors.get(D);N!==void 0?this.ctx.state.fileDescriptors.set(b,N):this.ctx.state.fileDescriptors.set(b,`__dupin__:${D}`),this.ctx.state.fileDescriptors.delete(D)}}else{let E=Number.parseInt(w,10);Number.isNaN(E)||this.ctx.state.fileDescriptors.set(b,`__dupin__:${E}`)}break}}}for(let[y,w]of r)w===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,w);if(this.ctx.state.tempExportedVars)for(let y of r.keys())this.ctx.state.tempExportedVars.delete(y);return L}let m=await Nr(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,g=null;try{p=await this.runCommand(u,f,d,s,!1,!1,l)}catch(y){if(y instanceof le||y instanceof ce)g=y,p=L;else throw y}let $=i+m;if($&&(p={...p,stderr:$+p.stderr}),p=await B(this.ctx,p,t.redirections),g)throw g;if(f.length>0){let y=f[f.length-1];if((u==="declare"||u==="local"||u==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(y)){let w=y.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);w&&(y=w[1])}this.ctx.state.lastArg=y}else this.ctx.state.lastArg=u;let v=Vn(u)&&u!=="unset"&&u!=="eval";if(!this.ctx.state.options.posix||!v)for(let[y,w]of r)this.ctx.state.fullyUnsetLocals?.has(y)||(w===void 0?this.ctx.state.env.delete(y):this.ctx.state.env.set(y,w));if(this.ctx.state.tempExportedVars)for(let y of r.keys())this.ctx.state.tempExportedVars.delete(y);return r.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(p={...p,stderr:this.ctx.state.expansionStderr+p.stderr},this.ctx.state.expansionStderr=""),p}async runCommand(t,s,n,r,i=!1,o=!1,a=-1){let c={ctx:this.ctx,runCommand:(u,f,d,h,m,p,g)=>this.runCommand(u,f,d,h,m,p,g),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(u,f,d)=>this.executeUserScript(u,f,d)},l=await wr(c,t,s,n,r,i,o,a);return l!==null?l:vr(c,t,s,r,o)}aliasExpansionStack=new Set;expandAlias(t){return es(this.ctx.state,t,this.aliasExpansionStack)}async findCommandInPath(t){return Mt(this.ctx,t)}async executeSubshell(t,s=""){return Ir(this.ctx,t,s,n=>this.executeStatement(n))}async executeGroup(t,s=""){return Rr(this.ctx,t,s,n=>this.executeStatement(n))}async executeArithmeticCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await be(this.ctx,t.redirections);if(s)return s;try{let n=await z(this.ctx,t.expression.expression),r=U(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),B(this.ctx,r,t.redirections)}catch(n){let r=A(`bash: arithmetic expression: ${n.message}
672
672
  `);return B(this.ctx,r,t.redirections)}}async executeConditionalCommand(t){t.line!==void 0&&(this.ctx.state.currentLine=t.line);let s=await be(this.ctx,t.redirections);if(s)return s;try{let n=await Ne(this.ctx,t.expression),r=U(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),B(this.ctx,r,t.redirections)}catch(n){let r=n instanceof xe?1:2,i=A(`bash: conditional expression: ${n.message}
673
- `,r);return B(this.ctx,i,t.redirections)}}};var ie={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:3e4,maxGlobOperations:1e5,maxStringLength:10485760,maxArrayElements:1e5,maxHeredocSize:10485760,maxSubstitutionDepth:50};function Fr(e){return e?{maxCallDepth:e.maxCallDepth??ie.maxCallDepth,maxCommandCount:e.maxCommandCount??ie.maxCommandCount,maxLoopIterations:e.maxLoopIterations??ie.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??ie.maxAwkIterations,maxSedIterations:e.maxSedIterations??ie.maxSedIterations,maxJqIterations:e.maxJqIterations??ie.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??ie.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??ie.maxPythonTimeoutMs,maxGlobOperations:e.maxGlobOperations??ie.maxGlobOperations,maxStringLength:e.maxStringLength??ie.maxStringLength,maxArrayElements:e.maxArrayElements??ie.maxArrayElements,maxHeredocSize:e.maxHeredocSize??ie.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??ie.maxSubstitutionDepth}:{...ie}}function Mr(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function yo(e){let t=Mr(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function go(e,t){let s=Mr(e);if(!s)return!1;let n=yo(t);return!n||s.origin!==n.origin?!1:n.pathPrefix==="/"||n.pathPrefix===""?!0:s.pathname.startsWith(n.pathPrefix)}function qs(e,t){return!t||t.length===0?!1:t.some(s=>go(e,s))}var st=class extends Error{constructor(t){super(`Network access denied: URL not in allow-list: ${t}`),this.name="NetworkAccessDeniedError"}},nt=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},rt=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Vt=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}},it=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var wo=20,vo=3e4,bo=10485760,Eo=["GET","HEAD"],$o=new Set(["GET","HEAD","OPTIONS"]),So=new Set([301,302,303,307,308]);function Zs(e){let t=e.maxRedirects??wo,s=e.timeoutMs??vo,n=e.maxResponseSize??bo,r=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Eo;function i(c){if(!e.dangerouslyAllowFullInternetAccess&&!qs(c,e.allowedUrlPrefixes??[]))throw new st(c)}function o(c){if(e.dangerouslyAllowFullInternetAccess)return;let l=c.toUpperCase();if(!r.includes(l))throw new Vt(l,r)}async function a(c,l={}){let u=l.method?.toUpperCase()??"GET";i(c),o(u);let f=c,d=0,h=l.followRedirects??!0,m=l.timeoutMs!==void 0?Math.min(l.timeoutMs,s):s;for(;;){let p=new AbortController,g=setTimeout(()=>p.abort(),m);try{let S={method:u,headers:l.headers,signal:p.signal,redirect:"manual"};l.body&&!$o.has(u)&&(S.body=l.body);let v=await fetch(f,S);if(So.has(v.status)&&h){let P=v.headers.get("location");if(!P)return await Wr(v,f,n);let y=new URL(P,f).href;if(!e.dangerouslyAllowFullInternetAccess&&!qs(y,e.allowedUrlPrefixes??[]))throw new rt(y);if(d++,d>t)throw new nt(t);f=y;continue}return await Wr(v,f,n)}finally{clearTimeout(g)}}}return a}async function Wr(e,t,s){let n=Object.create(null);if(e.headers.forEach((i,o)=>{n[o.toLowerCase()]=i}),s>0){let i=e.headers.get("content-length");if(i){let o=parseInt(i,10);if(!Number.isNaN(o)&&o>s)throw new it(s)}}let r;if(s>0&&e.body){let i=e.body.getReader(),o=new TextDecoder,a=[],c=0;for(;;){let{done:l,value:u}=await i.read();if(l)break;if(c+=u.byteLength,c>s)throw i.cancel(),new it(s);a.push(o.decode(u,{stream:!0}))}a.push(o.decode()),r=a.join("")}else r=await e.text();return{status:e.status,statusText:e.statusText,headers:n,body:r,url:t}}function Vr(){let e=[{prop:"Function",target:globalThis,violationType:"function_constructor",strategy:"throw",reason:"Function constructor allows arbitrary code execution"},{prop:"eval",target:globalThis,violationType:"eval",strategy:"throw",reason:"eval() allows arbitrary code execution"},{prop:"setTimeout",target:globalThis,violationType:"setTimeout",strategy:"throw",reason:"setTimeout with string argument allows code execution"},{prop:"setInterval",target:globalThis,violationType:"setInterval",strategy:"throw",reason:"setInterval with string argument allows code execution"},{prop:"setImmediate",target:globalThis,violationType:"setImmediate",strategy:"throw",reason:"setImmediate could be used to escape sandbox context"},{prop:"env",target:process,violationType:"process_env",strategy:"throw",reason:"process.env could leak sensitive environment variables"},{prop:"binding",target:process,violationType:"process_binding",strategy:"throw",reason:"process.binding provides access to native Node.js modules"},{prop:"_linkedBinding",target:process,violationType:"process_binding",strategy:"throw",reason:"process._linkedBinding provides access to native Node.js modules"},{prop:"dlopen",target:process,violationType:"process_dlopen",strategy:"throw",reason:"process.dlopen allows loading native addons"},{prop:"WeakRef",target:globalThis,violationType:"weak_ref",strategy:"throw",reason:"WeakRef could be used to leak references outside sandbox"},{prop:"FinalizationRegistry",target:globalThis,violationType:"finalization_registry",strategy:"throw",reason:"FinalizationRegistry could be used to leak references outside sandbox"},{prop:"Reflect",target:globalThis,violationType:"reflect",strategy:"freeze",reason:"Reflect provides introspection capabilities"},{prop:"Proxy",target:globalThis,violationType:"proxy",strategy:"throw",reason:"Proxy allows intercepting and modifying object behavior"},{prop:"WebAssembly",target:globalThis,violationType:"webassembly",strategy:"throw",reason:"WebAssembly allows executing arbitrary compiled code"},{prop:"SharedArrayBuffer",target:globalThis,violationType:"shared_array_buffer",strategy:"throw",reason:"SharedArrayBuffer could enable side-channel communication or timing attacks"},{prop:"Atomics",target:globalThis,violationType:"atomics",strategy:"throw",reason:"Atomics could enable side-channel communication or timing attacks"}];try{let t=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&e.push({prop:"constructor",target:Object.getPrototypeOf(async()=>{}),violationType:"async_function_constructor",strategy:"throw",reason:"AsyncFunction constructor allows arbitrary async code execution"})}catch{}try{let t=Object.getPrototypeOf(function*(){}).constructor;t&&t!==Function&&e.push({prop:"constructor",target:Object.getPrototypeOf(function*(){}),violationType:"generator_function_constructor",strategy:"throw",reason:"GeneratorFunction constructor allows arbitrary generator code execution"})}catch{}try{let t=Object.getPrototypeOf(async function*(){}).constructor;t&&t!==Function&&t!==Object.getPrototypeOf(async()=>{}).constructor&&e.push({prop:"constructor",target:Object.getPrototypeOf(async function*(){}),violationType:"async_generator_function_constructor",strategy:"throw",reason:"AsyncGeneratorFunction constructor allows arbitrary async generator code execution"})}catch{}return e.filter(t=>{try{return t.target[t.prop]!==void 0}catch{return!1}})}var ot=typeof __BROWSER__<"u"&&__BROWSER__;function zr(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}var Ks=null;if(!ot)try{let{createRequire:e}=await import("node:module");Ks=e(import.meta.url)("node:async_hooks").AsyncLocalStorage}catch(e){console.debug("[DefenseInDepthBox] AsyncLocalStorage not available, defense-in-depth disabled:",e instanceof Error?e.message:e)}var Ao=`
673
+ `,r);return B(this.ctx,i,t.redirections)}}};var ie={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:3e4,maxGlobOperations:1e5,maxStringLength:10485760,maxArrayElements:1e5,maxHeredocSize:10485760,maxSubstitutionDepth:50};function Fr(e){return e?{maxCallDepth:e.maxCallDepth??ie.maxCallDepth,maxCommandCount:e.maxCommandCount??ie.maxCommandCount,maxLoopIterations:e.maxLoopIterations??ie.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??ie.maxAwkIterations,maxSedIterations:e.maxSedIterations??ie.maxSedIterations,maxJqIterations:e.maxJqIterations??ie.maxJqIterations,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??ie.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??ie.maxPythonTimeoutMs,maxGlobOperations:e.maxGlobOperations??ie.maxGlobOperations,maxStringLength:e.maxStringLength??ie.maxStringLength,maxArrayElements:e.maxArrayElements??ie.maxArrayElements,maxHeredocSize:e.maxHeredocSize??ie.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??ie.maxSubstitutionDepth}:{...ie}}function Mr(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function yo(e){let t=Mr(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}function go(e,t){let s=Mr(e);if(!s)return!1;let n=yo(t);return!n||s.origin!==n.origin?!1:n.pathPrefix==="/"||n.pathPrefix===""?!0:s.pathname.startsWith(n.pathPrefix)}function qs(e,t){return!t||t.length===0?!1:t.some(s=>go(e,s))}var st=class extends Error{constructor(t){super(`Network access denied: URL not in allow-list: ${t}`),this.name="NetworkAccessDeniedError"}},nt=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},rt=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Vt=class extends Error{constructor(t,s){super(`HTTP method '${t}' not allowed. Allowed methods: ${s.join(", ")}`),this.name="MethodNotAllowedError"}},it=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var wo=20,vo=3e4,bo=10485760,Eo=["GET","HEAD"],So=new Set(["GET","HEAD","OPTIONS"]),$o=new Set([301,302,303,307,308]);function Zs(e){let t=e.maxRedirects??wo,s=e.timeoutMs??vo,n=e.maxResponseSize??bo,r=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Eo;function i(c){if(!e.dangerouslyAllowFullInternetAccess&&!qs(c,e.allowedUrlPrefixes??[]))throw new st(c)}function o(c){if(e.dangerouslyAllowFullInternetAccess)return;let l=c.toUpperCase();if(!r.includes(l))throw new Vt(l,r)}async function a(c,l={}){let u=l.method?.toUpperCase()??"GET";i(c),o(u);let f=c,d=0,h=l.followRedirects??!0,m=l.timeoutMs!==void 0?Math.min(l.timeoutMs,s):s;for(;;){let p=new AbortController,g=setTimeout(()=>p.abort(),m);try{let $={method:u,headers:l.headers,signal:p.signal,redirect:"manual"};l.body&&!So.has(u)&&($.body=l.body);let v=await fetch(f,$);if($o.has(v.status)&&h){let P=v.headers.get("location");if(!P)return await Wr(v,f,n);let y=new URL(P,f).href;if(!e.dangerouslyAllowFullInternetAccess&&!qs(y,e.allowedUrlPrefixes??[]))throw new rt(y);if(d++,d>t)throw new nt(t);f=y;continue}return await Wr(v,f,n)}finally{clearTimeout(g)}}}return a}async function Wr(e,t,s){let n=Object.create(null);if(e.headers.forEach((i,o)=>{n[o.toLowerCase()]=i}),s>0){let i=e.headers.get("content-length");if(i){let o=parseInt(i,10);if(!Number.isNaN(o)&&o>s)throw new it(s)}}let r;if(s>0&&e.body){let i=e.body.getReader(),o=new TextDecoder,a=[],c=0;for(;;){let{done:l,value:u}=await i.read();if(l)break;if(c+=u.byteLength,c>s)throw i.cancel(),new it(s);a.push(o.decode(u,{stream:!0}))}a.push(o.decode()),r=a.join("")}else r=await e.text();return{status:e.status,statusText:e.statusText,headers:n,body:r,url:t}}function Vr(){let e=[{prop:"Function",target:globalThis,violationType:"function_constructor",strategy:"throw",reason:"Function constructor allows arbitrary code execution"},{prop:"eval",target:globalThis,violationType:"eval",strategy:"throw",reason:"eval() allows arbitrary code execution"},{prop:"setTimeout",target:globalThis,violationType:"setTimeout",strategy:"throw",reason:"setTimeout with string argument allows code execution"},{prop:"setInterval",target:globalThis,violationType:"setInterval",strategy:"throw",reason:"setInterval with string argument allows code execution"},{prop:"setImmediate",target:globalThis,violationType:"setImmediate",strategy:"throw",reason:"setImmediate could be used to escape sandbox context"},{prop:"env",target:process,violationType:"process_env",strategy:"throw",reason:"process.env could leak sensitive environment variables"},{prop:"binding",target:process,violationType:"process_binding",strategy:"throw",reason:"process.binding provides access to native Node.js modules"},{prop:"_linkedBinding",target:process,violationType:"process_binding",strategy:"throw",reason:"process._linkedBinding provides access to native Node.js modules"},{prop:"dlopen",target:process,violationType:"process_dlopen",strategy:"throw",reason:"process.dlopen allows loading native addons"},{prop:"WeakRef",target:globalThis,violationType:"weak_ref",strategy:"throw",reason:"WeakRef could be used to leak references outside sandbox"},{prop:"FinalizationRegistry",target:globalThis,violationType:"finalization_registry",strategy:"throw",reason:"FinalizationRegistry could be used to leak references outside sandbox"},{prop:"Reflect",target:globalThis,violationType:"reflect",strategy:"freeze",reason:"Reflect provides introspection capabilities"},{prop:"Proxy",target:globalThis,violationType:"proxy",strategy:"throw",reason:"Proxy allows intercepting and modifying object behavior"},{prop:"WebAssembly",target:globalThis,violationType:"webassembly",strategy:"throw",reason:"WebAssembly allows executing arbitrary compiled code"},{prop:"SharedArrayBuffer",target:globalThis,violationType:"shared_array_buffer",strategy:"throw",reason:"SharedArrayBuffer could enable side-channel communication or timing attacks"},{prop:"Atomics",target:globalThis,violationType:"atomics",strategy:"throw",reason:"Atomics could enable side-channel communication or timing attacks"}];try{let t=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&e.push({prop:"constructor",target:Object.getPrototypeOf(async()=>{}),violationType:"async_function_constructor",strategy:"throw",reason:"AsyncFunction constructor allows arbitrary async code execution"})}catch{}try{let t=Object.getPrototypeOf(function*(){}).constructor;t&&t!==Function&&e.push({prop:"constructor",target:Object.getPrototypeOf(function*(){}),violationType:"generator_function_constructor",strategy:"throw",reason:"GeneratorFunction constructor allows arbitrary generator code execution"})}catch{}try{let t=Object.getPrototypeOf(async function*(){}).constructor;t&&t!==Function&&t!==Object.getPrototypeOf(async()=>{}).constructor&&e.push({prop:"constructor",target:Object.getPrototypeOf(async function*(){}),violationType:"async_generator_function_constructor",strategy:"throw",reason:"AsyncGeneratorFunction constructor allows arbitrary async generator code execution"})}catch{}return e.filter(t=>{try{return t.target[t.prop]!==void 0}catch{return!1}})}var ot=typeof __BROWSER__<"u"&&__BROWSER__;function zr(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}var Ks=null;if(!ot)try{let{createRequire:e}=await import("node:module");Ks=e(import.meta.url)("node:async_hooks").AsyncLocalStorage}catch(e){console.debug("[DefenseInDepthBox] AsyncLocalStorage not available, defense-in-depth disabled:",e instanceof Error?e.message:e)}var Ao=`
674
674
 
675
675
  This is a defense-in-depth measure and indicates a bug in just-bash. Please report this at security@vercel.com`,se=class extends Error{violation;constructor(t,s){super(t+Ao),this.violation=s,this.name="SecurityViolationError"}},oe=!ot&&Ks?new Ks:null,_o=1e3,Gs={enabled:!0,auditMode:!1};function Co(e){return e===void 0?{...Gs,enabled:!1}:typeof e=="boolean"?{...Gs,enabled:e}:{...Gs,...e}}var zt=class e{static instance=null;config;refCount=0;originalDescriptors=[];violations=[];activationTime=0;totalActiveTimeMs=0;constructor(t){this.config=t}static getInstance(t){return e.instance||(e.instance=new e(Co(t))),e.instance}static resetInstance(){e.instance&&(e.instance.forceDeactivate(),e.instance=null)}static isInSandboxedContext(){return oe?oe?.getStore()?.sandboxActive===!0:!1}static getCurrentExecutionId(){if(oe)return oe?.getStore()?.executionId}updateConfig(t){this.config={...this.config,...t}}activate(){if(ot||!this.config.enabled){let s=zr();return{run:n=>n(),deactivate:()=>{},executionId:s}}this.refCount++,this.refCount===1&&(this.applyPatches(),this.activationTime=Date.now());let t=zr();return{run:s=>oe.run({sandboxActive:!0,executionId:t},s),deactivate:()=>{this.refCount--,this.refCount===0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount<0&&(this.refCount=0)},executionId:t}}forceDeactivate(){this.refCount>0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount=0}isActive(){return this.refCount>0}getStats(){return{violationsBlocked:this.violations.length,violations:[...this.violations],activeTimeMs:this.totalActiveTimeMs+(this.refCount>0?Date.now()-this.activationTime:0),refCount:this.refCount}}clearViolations(){this.violations=[]}getPathForTarget(t,s){return t===globalThis?`globalThis.${s}`:t===process?`process.${s}`:t===Error?`Error.${s}`:t===Function.prototype?`Function.prototype.${s}`:t===Object.prototype?`Object.prototype.${s}`:`<object>.${s}`}shouldBlock(){return ot||this.config.auditMode||!oe?!1:oe?.getStore()?.sandboxActive===!0}recordViolation(t,s,n){let r={timestamp:Date.now(),type:t,message:n,path:s,stack:new Error().stack,executionId:oe?.getStore()?.executionId};if(this.violations.length<_o&&this.violations.push(r),this.config.onViolation)try{this.config.onViolation(r)}catch(i){console.debug("[DefenseInDepthBox] onViolation callback threw:",i instanceof Error?i.message:i)}return r}createBlockingProxy(t,s,n){let r=this;return new Proxy(t,{apply(i,o,a){if(r.shouldBlock()){let c=`${s} is blocked during script execution`,l=r.recordViolation(n,s,c);throw new se(c,l)}return r.config.auditMode&&oe?.getStore()?.sandboxActive===!0&&r.recordViolation(n,s,`${s} called (audit mode)`),Reflect.apply(i,o,a)},construct(i,o,a){if(r.shouldBlock()){let c=`${s} constructor is blocked during script execution`,l=r.recordViolation(n,s,c);throw new se(c,l)}return r.config.auditMode&&oe?.getStore()?.sandboxActive===!0&&r.recordViolation(n,s,`${s} constructor called (audit mode)`),Reflect.construct(i,o,a)}})}createBlockingObjectProxy(t,s,n){let r=this;return new Proxy(t,{get(i,o,a){if(r.shouldBlock()){let c=`${s}.${String(o)}`,l=`${c} is blocked during script execution`,u=r.recordViolation(n,c,l);throw new se(l,u)}if(r.config.auditMode&&oe?.getStore()?.sandboxActive===!0){let c=`${s}.${String(o)}`;r.recordViolation(n,c,`${c} accessed (audit mode)`)}return Reflect.get(i,o,a)},set(i,o,a,c){if(r.shouldBlock()){let l=`${s}.${String(o)}`,u=`${l} modification is blocked during script execution`,f=r.recordViolation(n,l,u);throw new se(u,f)}return Reflect.set(i,o,a,c)},ownKeys(i){if(r.shouldBlock()){let o=`${s} enumeration is blocked during script execution`,a=r.recordViolation(n,s,o);throw new se(o,a)}return Reflect.ownKeys(i)},getOwnPropertyDescriptor(i,o){if(r.shouldBlock()){let a=`${s}.${String(o)}`,c=`${a} descriptor access is blocked during script execution`,l=r.recordViolation(n,a,c);throw new se(c,l)}return Reflect.getOwnPropertyDescriptor(i,o)},has(i,o){if(r.shouldBlock()){let a=`${s}.${String(o)}`,c=`${a} existence check is blocked during script execution`,l=r.recordViolation(n,a,c);throw new se(c,l)}return Reflect.has(i,o)}})}applyPatches(){let t=Vr();for(let s of t)this.applyPatch(s);this.protectConstructorChain(),this.protectErrorPrepareStackTrace(),this.protectModuleLoad(),this.protectProcessMainModule()}protectConstructorChain(){this.patchPrototypeConstructor(Function.prototype,"Function.prototype.constructor","function_constructor");try{let t=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&this.patchPrototypeConstructor(t.prototype,"AsyncFunction.prototype.constructor","async_function_constructor")}catch(t){console.debug("[DefenseInDepthBox] Could not patch AsyncFunction.prototype.constructor:",t instanceof Error?t.message:t)}try{let t=Object.getPrototypeOf(function*(){}).constructor;t&&t!==Function&&this.patchPrototypeConstructor(t.prototype,"GeneratorFunction.prototype.constructor","generator_function_constructor")}catch(t){console.debug("[DefenseInDepthBox] Could not patch GeneratorFunction.prototype.constructor:",t instanceof Error?t.message:t)}try{let t=Object.getPrototypeOf(async function*(){}).constructor,s=Object.getPrototypeOf(async()=>{}).constructor;t&&t!==Function&&t!==s&&this.patchPrototypeConstructor(t.prototype,"AsyncGeneratorFunction.prototype.constructor","async_generator_function_constructor")}catch(t){console.debug("[DefenseInDepthBox] Could not patch AsyncGeneratorFunction.prototype.constructor:",t instanceof Error?t.message:t)}}protectErrorPrepareStackTrace(){let t=this;try{let s=Object.getOwnPropertyDescriptor(Error,"prepareStackTrace");this.originalDescriptors.push({target:Error,prop:"prepareStackTrace",descriptor:s});let n=s?.value;Object.defineProperty(Error,"prepareStackTrace",{get(){return n},set(r){if(t.shouldBlock()){let i="Error.prepareStackTrace modification is blocked during script execution",o=t.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace",i);throw new se(i,o)}t.config.auditMode&&oe?.getStore()?.sandboxActive===!0&&t.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace","Error.prepareStackTrace set (audit mode)"),n=r},configurable:!0})}catch(s){console.debug("[DefenseInDepthBox] Could not protect Error.prepareStackTrace:",s instanceof Error?s.message:s)}}patchPrototypeConstructor(t,s,n){let r=this;try{let i=Object.getOwnPropertyDescriptor(t,"constructor");this.originalDescriptors.push({target:t,prop:"constructor",descriptor:i});let o=i?.value;Object.defineProperty(t,"constructor",{get(){if(r.shouldBlock()){let a=`${s} access is blocked during script execution`,c=r.recordViolation(n,s,a);throw new se(a,c)}return r.config.auditMode&&oe?.getStore()?.sandboxActive===!0&&r.recordViolation(n,s,`${s} accessed (audit mode)`),o},set(a){if(r.shouldBlock()){let c=`${s} modification is blocked during script execution`,l=r.recordViolation(n,s,c);throw new se(c,l)}Object.defineProperty(this,"constructor",{value:a,writable:!0,configurable:!0})},configurable:!0})}catch(i){console.debug(`[DefenseInDepthBox] Could not patch ${s}:`,i instanceof Error?i.message:i)}}protectProcessMainModule(){if(typeof process>"u")return;let t=this;try{let s=Object.getOwnPropertyDescriptor(process,"mainModule");this.originalDescriptors.push({target:process,prop:"mainModule",descriptor:s});let n=s?.value;n!==void 0&&Object.defineProperty(process,"mainModule",{get(){if(t.shouldBlock()){let r="process.mainModule access is blocked during script execution",i=t.recordViolation("process_main_module","process.mainModule",r);throw new se(r,i)}return t.config.auditMode&&oe?.getStore()?.sandboxActive===!0&&t.recordViolation("process_main_module","process.mainModule","process.mainModule accessed (audit mode)"),n},set(r){if(t.shouldBlock()){let i="process.mainModule modification is blocked during script execution",o=t.recordViolation("process_main_module","process.mainModule",i);throw new se(i,o)}Object.defineProperty(process,"mainModule",{value:r,writable:!0,configurable:!0})},configurable:!0})}catch(s){console.debug("[DefenseInDepthBox] Could not protect process.mainModule:",s instanceof Error?s.message:s)}}protectModuleLoad(){if(!ot)try{let t=null;if(typeof process<"u"){let o=process.mainModule;o&&typeof o=="object"&&(t=o.constructor)}if(!t&&typeof at<"u"&&typeof at.main<"u"&&(t=at.main.constructor),!t||typeof t._load!="function")return;let s=t._load,n=Object.getOwnPropertyDescriptor(t,"_load");this.originalDescriptors.push({target:t,prop:"_load",descriptor:n});let i=this.createBlockingProxy(s,"Module._load","module_load");Object.defineProperty(t,"_load",{value:i,writable:!0,configurable:!0})}catch(t){console.debug("[DefenseInDepthBox] Could not protect Module._load:",t instanceof Error?t.message:t)}}applyPatch(t){let{target:s,prop:n,violationType:r,strategy:i}=t;try{let o=s[n];if(o===void 0)return;let a=Object.getOwnPropertyDescriptor(s,n);if(this.originalDescriptors.push({target:s,prop:n,descriptor:a}),i==="freeze")typeof o=="object"&&o!==null&&Object.freeze(o);else{let c=this.getPathForTarget(s,n),l=typeof o=="function"?this.createBlockingProxy(o,c,r):this.createBlockingObjectProxy(o,c,r);Object.defineProperty(s,n,{value:l,writable:!0,configurable:!0})}}catch(o){let a=this.getPathForTarget(s,n);console.debug(`[DefenseInDepthBox] Could not patch ${a}:`,o instanceof Error?o.message:o)}}restorePatches(){for(let t=this.originalDescriptors.length-1;t>=0;t--){let{target:s,prop:n,descriptor:r}=this.originalDescriptors[t];try{r?Object.defineProperty(s,n,r):delete s[n]}catch(i){let o=this.getPathForTarget(s,n);console.debug(`[DefenseInDepthBox] Could not restore ${o}:`,i instanceof Error?i.message:i)}}this.originalDescriptors=[]}};var Bt=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;state;constructor(t={}){let s=t.fs??new Ge(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",`
676
676
  `],["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=Fr({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}}),t.network&&(this.secureFetch=Zs(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth,this.coverageWriter=t.coverage,this.state={env:r,cwd:n,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,bashPid:process.pid,nextVirtualPid:process.pid+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",Yt(this.state.options)),this.state.env.set("BASHOPTS",Qt(this.state.shoptOptions)),vn(s,this.useDefaultLayout),n!=="/"&&s instanceof Ge)try{s.mkdirSync(n,{recursive:!0})}catch{}for(let i of pn(t.commands))this.registerCommand(i);if(t.network)for(let i of mn())this.registerCommand(i);if(t.python)for(let i of yn())this.registerCommand(i);if(t.customCommands)for(let i of t.customCommands)gn(i)?this.registerCommand(wn(i)):this.registerCommand(i)}registerCommand(t){this.commands.set(t.name,t);let s=this.fs;if(typeof s.writeFileSync=="function"){let n=`#!/bin/bash
677
677
  # Built-in command: ${t.name}
678
678
  `;try{s.writeFileSync(`/bin/${t.name}`,n)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,n)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t}async exec(t,s){if(this.state.callDepth===0&&(this.state.commandCount=0),this.state.commandCount++,this.state.commandCount>this.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option.
679
- `,exitCode:1,env:he(this.state.env,s?.env)};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:he(this.state.env,s?.env)};this.logger?.info("exec",{command:t});let n=s?.cwd??this.state.cwd,r,i=n;if(s?.cwd)if(s.env&&"PWD"in s.env)r=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{r=await this.fs.realpath(n),i=r}catch{r=n}else r=n;let o=new Map(this.state.env);if(s?.env)for(let[f,d]of Object.entries(s.env))o.set(f,d);r!==void 0&&o.set("PWD",r);let a={...this.state,env:o,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable},c=t;s?.rawScript||(c=Po(t));let u=(this.defenseInDepthConfig?zt.getInstance(this.defenseInDepthConfig):null)?.activate();try{let f=async()=>{let d=ye(c),h={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter},p=await new tt(h,a).executeScript(d);return this.logResult(p)};return u?await u.run(f):await f()}catch(f){if(f instanceof V)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:he(this.state.env,s?.env)});if(f instanceof de)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:he(this.state.env,s?.env)});if(f instanceof xe)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:1,env:he(this.state.env,s?.env)});if(f instanceof ee)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:ee.EXIT_CODE,env:he(this.state.env,s?.env)});if(f instanceof se)return this.logResult({stdout:"",stderr:`bash: security violation: ${f.message}
679
+ `,exitCode:1,env:he(this.state.env,s?.env)};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:he(this.state.env,s?.env)};this.logger?.info("exec",{command:t});let n=s?.cwd??this.state.cwd,r,i=n;if(s?.cwd)if(s.env&&"PWD"in s.env)r=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{r=await this.fs.realpath(n),i=r}catch{r=n}else r=n;let o=new Map(this.state.env);if(s?.env)for(let[f,d]of Object.entries(s.env))o.set(f,d);r!==void 0&&o.set("PWD",r);let a={...this.state,env:o,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:s?.stdin},c=t;s?.rawScript||(c=Po(t));let u=(this.defenseInDepthConfig?zt.getInstance(this.defenseInDepthConfig):null)?.activate();try{let f=async()=>{let d=ye(c),h={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter},p=await new tt(h,a).executeScript(d);return this.logResult(p)};return u?await u.run(f):await f()}catch(f){if(f instanceof V)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:he(this.state.env,s?.env)});if(f instanceof de)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:he(this.state.env,s?.env)});if(f instanceof xe)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:1,env:he(this.state.env,s?.env)});if(f instanceof ee)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:ee.EXIT_CODE,env:he(this.state.env,s?.env)});if(f instanceof se)return this.logResult({stdout:"",stderr:`bash: security violation: ${f.message}
680
680
  `,exitCode:1,env:he(this.state.env,s?.env)});if(f.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${f.message}
681
681
  `,exitCode:2,env:he(this.state.env,s?.env)});if(f instanceof en)return this.logResult({stdout:"",stderr:`bash: ${f.message}
682
682
  `,exitCode:2,env:he(this.state.env,s?.env)});if(f instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${f.message}