just-bash 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/Bash.d.ts +18 -0
  2. package/dist/ai/index.d.ts +6 -1
  3. package/dist/bin/chunks/awk2-6XCE67AX.js +20 -0
  4. package/dist/bin/chunks/awk2-DKAZ7LPG.js +20 -0
  5. package/dist/bin/chunks/awk2-GAJ72X3Z.js +20 -0
  6. package/dist/bin/chunks/awk2-HJAPWU2N.js +18 -0
  7. package/dist/bin/chunks/awk2-LVXC5OAC.js +20 -0
  8. package/dist/bin/chunks/awk2-T6HR4EYO.js +20 -0
  9. package/dist/bin/chunks/awk2-UYU2UYZ2.js +20 -0
  10. package/dist/bin/chunks/awk2-W64AZN7P.js +20 -0
  11. package/dist/bin/chunks/find-7BUNQZX4.js +11 -0
  12. package/dist/bin/chunks/find-YATLECXJ.js +11 -0
  13. package/dist/bin/chunks/grep-PHBFGJCV.js +15 -0
  14. package/dist/bin/chunks/sed-B6FXUN7R.js +80 -0
  15. package/dist/bin/chunks/sed-RHLDIXPL.js +76 -0
  16. package/dist/bin/chunks/sed-SYSATJXR.js +75 -0
  17. package/dist/bin/just-bash.js +102 -102
  18. package/dist/bin/shell/chunks/awk2-6XCE67AX.js +20 -0
  19. package/dist/bin/shell/chunks/awk2-DKAZ7LPG.js +20 -0
  20. package/dist/bin/shell/chunks/awk2-GAJ72X3Z.js +20 -0
  21. package/dist/bin/shell/chunks/awk2-HJAPWU2N.js +18 -0
  22. package/dist/bin/shell/chunks/awk2-LVXC5OAC.js +20 -0
  23. package/dist/bin/shell/chunks/awk2-T6HR4EYO.js +20 -0
  24. package/dist/bin/shell/chunks/awk2-UYU2UYZ2.js +20 -0
  25. package/dist/bin/shell/chunks/awk2-W64AZN7P.js +20 -0
  26. package/dist/bin/shell/chunks/find-7BUNQZX4.js +11 -0
  27. package/dist/bin/shell/chunks/find-YATLECXJ.js +11 -0
  28. package/dist/bin/shell/chunks/grep-PHBFGJCV.js +15 -0
  29. package/dist/bin/shell/chunks/sed-B6FXUN7R.js +80 -0
  30. package/dist/bin/shell/chunks/sed-RHLDIXPL.js +76 -0
  31. package/dist/bin/shell/chunks/sed-SYSATJXR.js +75 -0
  32. package/dist/bin/shell/shell.js +124 -128
  33. package/dist/bundle/ai/index.js +423 -386
  34. package/dist/bundle/chunks/awk2-365HINHI.js +19 -0
  35. package/dist/bundle/chunks/awk2-7YCFY7D2.js +19 -0
  36. package/dist/bundle/chunks/awk2-7YL3P4KU.js +19 -0
  37. package/dist/bundle/chunks/awk2-ETXZHQQ4.js +19 -0
  38. package/dist/bundle/chunks/awk2-FMEL7ESV.js +19 -0
  39. package/dist/bundle/chunks/awk2-LE4QUFGK.js +19 -0
  40. package/dist/bundle/chunks/awk2-MGHA6JPJ.js +17 -0
  41. package/dist/bundle/chunks/awk2-XEAK5PBN.js +19 -0
  42. package/dist/bundle/chunks/find-KP4M5DWC.js +10 -0
  43. package/dist/bundle/chunks/find-WM6ZETA7.js +10 -0
  44. package/dist/bundle/chunks/grep-CZTYKNEE.js +14 -0
  45. package/dist/bundle/chunks/sed-2WWCANZT.js +79 -0
  46. package/dist/bundle/chunks/sed-5LZHAGFR.js +74 -0
  47. package/dist/bundle/chunks/sed-V7XSBPTD.js +75 -0
  48. package/dist/bundle/index.js +8 -8
  49. package/dist/commands/awk/ast.d.ts +201 -0
  50. package/dist/commands/awk/awk2.d.ts +7 -0
  51. package/dist/commands/awk/builtins.d.ts +17 -0
  52. package/dist/commands/awk/interpreter/context.d.ts +53 -0
  53. package/dist/commands/awk/interpreter/expressions.d.ts +17 -0
  54. package/dist/commands/awk/interpreter/fields.d.ts +25 -0
  55. package/dist/commands/awk/interpreter/helpers.d.ts +29 -0
  56. package/dist/commands/awk/interpreter/index.d.ts +8 -0
  57. package/dist/commands/awk/interpreter/interpreter.d.ts +50 -0
  58. package/dist/commands/awk/interpreter/statements.d.ts +11 -0
  59. package/dist/commands/awk/interpreter/types.d.ts +13 -0
  60. package/dist/commands/awk/interpreter/variables.d.ts +35 -0
  61. package/dist/commands/awk/interpreter2.d.ts +90 -0
  62. package/dist/commands/awk/lexer.d.ts +100 -0
  63. package/dist/commands/awk/parser2.d.ts +73 -0
  64. package/dist/commands/find/matcher.d.ts +6 -2
  65. package/dist/commands/find/types.d.ts +13 -0
  66. package/dist/commands/sed/executor.d.ts +1 -1
  67. package/dist/commands/sed/lexer.d.ts +74 -0
  68. package/dist/commands/sed/parser.d.ts +4 -0
  69. package/dist/commands/sed/types.d.ts +66 -2
  70. package/dist/index.d.ts +1 -1
  71. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import{a as U,b as X,c as V,d as te,e as Y,f as k,g as F,h as ye,i as z,j as Ue}from"./chunks/chunk-JYYFSUWP.js";import{a as le}from"./chunks/chunk-44UOCSGV.js";var gt=[{name:"echo",load:async()=>(await import("./chunks/echo-W2TA2N7Y.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-5KESXK2M.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-3ZT5XOIZ.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-B7C35UDO.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-WYI2LJ6H.js")).mkdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-Z5XRYFYY.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-5X2XSQQ6.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-BLHAPLQZ.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-GN23UIZU.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-UTUVIAFP.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-VLKWIL3N.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-ZVX5RTL4.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-HHC33N5C.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-7H5R4WKO.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-BLGGG2VX.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-OXLYBRUE.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-TM5F5YO4.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-3D2INI4S.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-3D2INI4S.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-3D2INI4S.js")).egrepCommand},{name:"sed",load:async()=>(await import("./chunks/sed-UZJSXYQZ.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk-V4C3GTJI.js")).awkCommand},{name:"sort",load:async()=>(await import("./chunks/sort-LHMQWYH2.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-IIOQKNTS.js")).uniqCommand},{name:"cut",load:async()=>(await import("./chunks/cut-7RHEYJ7Y.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-L4TYPVSP.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-UV4V27RJ.js")).trCommand},{name:"tee",load:async()=>(await import("./chunks/tee-VCNOG5VI.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-K3NO35MZ.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-SB5JXIY3.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-Q5HDZLH2.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-75UXQ4XJ.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-I5HYAKTQ.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-OORA5GFS.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-OORA5GFS.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-7ZSTROM7.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-7ZSTROM7.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-7Z2STZ6Y.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-E5JPQL24.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-OD7ZXH3O.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-OD7ZXH3O.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-ZBD2DMXN.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-T4PXVRYX.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-T4PXVRYX.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-7R2XGLLH.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-WATI5PWI.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-IVJFQANX.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-YOOSNZVA.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-QJBQD6VS.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-THAT7IOO.js")).timeoutCommand},{name:"seq",load:async()=>(await import("./chunks/seq-TFPZQZPJ.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-A4LJAGVP.js")).exprCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-XMBYO6FD.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-SDCRRU2F.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-ONWH3TNF.js")).whichCommand}],pr=[{name:"curl",load:async()=>(await import("./chunks/curl-PA2MWGKN.js")).curlCommand}],mr=new Map;function yr(t){return{name:t.name,async execute(e,n){let r=mr.get(t.name);return r||(r=await t.load(),mr.set(t.name,r)),r.execute(e,n)}}}function Tn(){return gt.map(t=>t.name)}function Wn(){return pr.map(t=>t.name)}function Er(t){return(t?gt.filter(n=>t.includes(n.name)):gt).map(yr)}function wr(){return pr.map(yr)}function gr(t){return"load"in t&&typeof t.load=="function"}function Fn(t,e){return{name:t,execute:e}}function Ar(t){let e=null;return{name:t.name,async execute(n,r){return e||(e=await t.load()),e.execute(n,r)}}}var Mn=new TextEncoder,Bn=new TextDecoder;function re(t,e){if(t instanceof Uint8Array)return t;switch(e){case"base64":return Uint8Array.from(atob(t),n=>n.charCodeAt(0));case"hex":{let n=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)n[r/2]=parseInt(t.slice(r,r+2),16);return n}case"binary":case"latin1":return Uint8Array.from(t,n=>n.charCodeAt(0));default:return Mn.encode(t)}}function xe(t,e){switch(e){case"base64":return btoa(String.fromCharCode(...t));case"hex":return Array.from(t).map(n=>n.toString(16).padStart(2,"0")).join("");case"binary":case"latin1":return String.fromCharCode(...t);default:return Bn.decode(t)}}function Z(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var Ve=new TextEncoder;function zn(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var ne=class{data=new Map;constructor(e){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),e)for(let[n,r]of Object.entries(e))zn(r)?this.writeFileSync(n,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(n,r)}normalizePath(e){if(!e||e==="/")return"/";let n=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;n.startsWith("/")||(n=`/${n}`);let r=n.split("/").filter(o=>o&&o!=="."),s=[];for(let o of r)o===".."?s.pop():s.push(o);return`/${s.join("/")}`||"/"}dirname(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.lastIndexOf("/");return r===0?"/":n.slice(0,r)}ensureParentDirs(e){let n=this.dirname(e);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,n,r,s){let o=this.normalizePath(e);this.ensureParentDirs(o);let i=Z(r),a=re(n,i);this.data.set(o,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}async readFile(e,n){let r=await this.readFileBuffer(e),s=Z(n);return xe(r,s)}async readFileBuffer(e){let n=this.normalizePath(e),r=this.data.get(n),s=n;if(!r)throw new Error(`ENOENT: no such file or directory, open '${e}'`);let o=new Set;for(;r&&r.type==="symlink";){if(o.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);o.add(s),s=this.resolveSymlink(s,r.target),r=this.data.get(s)}if(!r)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content instanceof Uint8Array?r.content:Ve.encode(r.content)}async writeFile(e,n,r){this.writeFileSync(e,n,r)}async appendFile(e,n,r){let s=this.normalizePath(e),o=this.data.get(s);if(o&&o.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${e}'`);let i=Z(r),a=re(n,i);if(o?.type==="file"){let c=o.content instanceof Uint8Array?o.content:Ve.encode(o.content),l=new Uint8Array(c.length+a.length);l.set(c),l.set(a,c.length),this.data.set(s,{type:"file",content:l,mode:o.mode,mtime:new Date})}else this.writeFileSync(e,n,r)}async exists(e){return this.data.has(this.normalizePath(e))}async stat(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(r.type==="symlink"){let o=this.resolveSymlink(n,r.target),i=this.data.get(o);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);r=i}let s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=Ve.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}async lstat(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};let s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=Ve.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}resolveSymlink(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${n}`:`${r}/${n}`)}async mkdir(e,n){this.mkdirSync(e,n)}mkdirSync(e,n){let r=this.normalizePath(e);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.dirname(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${e}'`);let s=n==="/"?"/":`${n}/`,o=[];for(let i of this.data.keys())if(i!==n&&i.startsWith(s)){let c=i.slice(s.length).split("/")[0];c&&!o.includes(c)&&o.push(c)}return o.sort()}async rm(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(s.type==="directory"){let o=await this.readdir(r);if(o.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let i of o){let a=r==="/"?`/${i}`:`${r}/${i}`;await this.rm(a,n)}}}this.data.delete(r)}async cp(e,n,r){let s=this.normalizePath(e),o=this.normalizePath(n),i=this.data.get(s);if(!i)throw new Error(`ENOENT: no such file or directory, cp '${e}'`);if(i.type==="file")this.ensureParentDirs(o),this.data.set(o,{...i});else if(i.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(o,{recursive:!0});let a=await this.readdir(s);for(let c of a){let l=s==="/"?`/${c}`:`${s}/${c}`,f=o==="/"?`/${c}`:`${o}/${c}`;await this.cp(l,f,r)}}}async mv(e,n){await this.cp(e,n,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=e==="/"?`/${n}`:`${e}/${n}`;return this.normalizePath(r)}async chmod(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);s.mode=n}async symlink(e,n){let r=this.normalizePath(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,n){let r=this.normalizePath(e),s=this.normalizePath(n),o=this.data.get(r);if(!o)throw new Error(`ENOENT: no such file or directory, link '${e}'`);if(o.type!=="file")throw new Error(`EPERM: operation not permitted, link '${e}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${n}'`);this.ensureParentDirs(s),this.data.set(s,{type:"file",content:o.content,mode:o.mode,mtime:o.mtime})}async readlink(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}};function T(t,e){return{type:"ArithmeticExpression",expression:se(t,e,0).expr}}function se(t,e,n){return Un(t,e,n)}function Un(t,e,n){let{expr:r,pos:s}=He(t,e,n);for(s=O(e,s);e[s]===",";){s++;let{expr:o,pos:i}=He(t,e,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=O(e,i)}return{expr:r,pos:s}}function He(t,e,n){let{expr:r,pos:s}=Vn(t,e,n);if(s=O(e,s),e[s]==="?"){s++;let{expr:o,pos:i}=se(t,e,s);if(s=O(e,i),e[s]===":"){s++;let{expr:a,pos:c}=se(t,e,s);return{expr:{type:"ArithTernary",condition:r,consequent:o,alternate:a},pos:c}}}return{expr:r,pos:s}}function Vn(t,e,n){let{expr:r,pos:s}=xr(t,e,n);for(;s=O(e,s),e.slice(s,s+2)==="||";){s+=2;let{expr:o,pos:i}=xr(t,e,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=i}return{expr:r,pos:s}}function xr(t,e,n){let{expr:r,pos:s}=Sr(t,e,n);for(;s=O(e,s),e.slice(s,s+2)==="&&";){s+=2;let{expr:o,pos:i}=Sr(t,e,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=i}return{expr:r,pos:s}}function Sr(t,e,n){let{expr:r,pos:s}=br(t,e,n);for(;s=O(e,s),e[s]==="|"&&e[s+1]!=="|";){s++;let{expr:o,pos:i}=br(t,e,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=i}return{expr:r,pos:s}}function br(t,e,n){let{expr:r,pos:s}=Nr(t,e,n);for(;s=O(e,s),e[s]==="^";){s++;let{expr:o,pos:i}=Nr(t,e,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=i}return{expr:r,pos:s}}function Nr(t,e,n){let{expr:r,pos:s}=Cr(t,e,n);for(;s=O(e,s),e[s]==="&"&&e[s+1]!=="&";){s++;let{expr:o,pos:i}=Cr(t,e,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=i}return{expr:r,pos:s}}function Cr(t,e,n){let{expr:r,pos:s}=$r(t,e,n);for(;s=O(e,s),e.slice(s,s+2)==="=="||e.slice(s,s+2)==="!=";){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=$r(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function $r(t,e,n){let{expr:r,pos:s}=At(t,e,n);for(;;)if(s=O(e,s),e.slice(s,s+2)==="<="||e.slice(s,s+2)===">="){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=At(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else if(e[s]==="<"||e[s]===">"){let o=e[s];s++;let{expr:i,pos:a}=At(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else break;return{expr:r,pos:s}}function At(t,e,n){let{expr:r,pos:s}=Pr(t,e,n);for(;s=O(e,s),e.slice(s,s+2)==="<<"||e.slice(s,s+2)===">>";){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=Pr(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function Pr(t,e,n){let{expr:r,pos:s}=vr(t,e,n);for(;s=O(e,s),(e[s]==="+"||e[s]==="-")&&e[s+1]!==e[s];){let o=e[s];s++;let{expr:i,pos:a}=vr(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function vr(t,e,n){let{expr:r,pos:s}=Ge(t,e,n);for(;;)if(s=O(e,s),e[s]==="*"&&e[s+1]!=="*"){s++;let{expr:o,pos:i}=Ge(t,e,s);r={type:"ArithBinary",operator:"*",left:r,right:o},s=i}else if(e[s]==="/"||e[s]==="%"){let o=e[s];s++;let{expr:i,pos:a}=Ge(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else break;return{expr:r,pos:s}}function Ge(t,e,n){let{expr:r,pos:s}=xt(t,e,n),o=O(e,s);if(e.slice(o,o+2)==="**"){o+=2;let{expr:i,pos:a}=Ge(t,e,o);return{expr:{type:"ArithBinary",operator:"**",left:r,right:i},pos:a}}return{expr:r,pos:s}}function xt(t,e,n){let r=O(e,n);if(e.slice(r,r+2)==="++"||e.slice(r,r+2)==="--"){let s=e.slice(r,r+2);r+=2;let{expr:o,pos:i}=xt(t,e,r);return{expr:{type:"ArithUnary",operator:s,operand:o,prefix:!0},pos:i}}if(e[r]==="+"||e[r]==="-"||e[r]==="!"||e[r]==="~"){let s=e[r];r++;let{expr:o,pos:i}=xt(t,e,r);return{expr:{type:"ArithUnary",operator:s,operand:o,prefix:!0},pos:i}}return Hn(t,e,r)}function Gn(t,e){let n=t[e];return n==="$"||n==="`"}function Hn(t,e,n){let{expr:r,pos:s}=Ir(t,e,n),o=[r];for(;Gn(e,s);){let{expr:i,pos:a}=Ir(t,e,s);o.push(i),s=a}if(o.length>1&&(r={type:"ArithConcat",parts:o}),s=O(e,s),e.slice(s,s+2)==="++"||e.slice(s,s+2)==="--"){let i=e.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:i,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function Ir(t,e,n){let r=O(e,n);if(e.slice(r,r+3)==="$(("){r+=3;let s=1,o=r;for(;r<e.length-1&&s>0;)e[r]==="("&&e[r+1]==="("?(s++,r+=2):e[r]===")"&&e[r+1]===")"?(s--,s>0&&(r+=2)):r++;let i=e.slice(o,r),{expr:a}=se(t,i,0);return r+=2,{expr:{type:"ArithNested",expression:a},pos:r}}if(e.slice(r,r+2)==="$("&&e[r+2]!=="("){r+=2;let s=1,o=r;for(;r<e.length&&s>0;)e[r]==="("?s++:e[r]===")"&&s--,s>0&&r++;let i=e.slice(o,r);return r++,{expr:{type:"ArithCommandSubst",command:i},pos:r}}if(e[r]==="`"){r++;let s=r;for(;r<e.length&&e[r]!=="`";)r++;let o=e.slice(s,r);return e[r]==="`"&&r++,{expr:{type:"ArithCommandSubst",command:o},pos:r}}if(e[r]==="("){r++;let{expr:s,pos:o}=se(t,e,r);return r=O(e,o),e[r]===")"&&r++,{expr:{type:"ArithGroup",expression:s},pos:r}}if(/[0-9]/.test(e[r])){let s="",o=!1;for(;r<e.length;){let a=e[r];if(o)if(/[0-9a-zA-Z@_]/.test(a))s+=a,r++;else break;else if(a==="#")o=!0,s+=a,r++;else if(/[0-9a-fA-FxX]/.test(a))s+=a,r++;else break}if(e[r]==="."&&/[0-9]/.test(e[r+1]))throw new F(`${s}.${e[r+1]}...: syntax error: invalid arithmetic operator`);if(e[r]==="["){let a=e.slice(r).trim();return{expr:{type:"ArithNumberSubscript",number:s,errorToken:a},pos:e.length}}return{expr:{type:"ArithNumber",value:Se(s)},pos:r}}if(e[r]==="$"&&e[r+1]==="{"){let s=r+2,o=1,i=s;for(;i<e.length&&o>0;)e[i]==="{"?o++:e[i]==="}"&&o--,o>0&&i++;let a=e.slice(s,i),c=i+1;if(e[c]==="#"){let l=c+1;for(;l<e.length&&/[0-9a-zA-Z@_]/.test(e[l]);)l++;let f=e.slice(c+1,l);return{expr:{type:"ArithDynamicBase",baseExpr:a,value:f},pos:l}}if(/[0-9]/.test(e[c])||e[c]==="x"||e[c]==="X"){let l=c;if(e[c]==="x"||e[c]==="X")for(l++;l<e.length&&/[0-9a-fA-F]/.test(e[l]);)l++;else for(;l<e.length&&/[0-9]/.test(e[l]);)l++;let f=e.slice(c,l);return{expr:{type:"ArithDynamicNumber",prefix:a,suffix:f},pos:l}}return r=c,{expr:{type:"ArithBracedExpansion",content:a},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[0-9]/.test(e[r+1])){r++;let s="";for(;r<e.length&&/[0-9]/.test(e[r]);)s+=e[r],r++;return{expr:{type:"ArithVariable",name:s},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[a-zA-Z_]/.test(e[r+1])&&r++,/[a-zA-Z_]/.test(e[r])){let s="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)s+=e[r],r++;if(e[r]==="["){r++;let i;if(e[r]==="'"||e[r]==='"'){let l=e[r];for(r++,i="";r<e.length&&e[r]!==l;)i+=e[r],r++;e[r]===l&&r++,r=O(e,r),e[r]==="]"&&r++}let a;if(i===void 0){let{expr:l,pos:f}=se(t,e,r);a=l,r=f,e[r]==="]"&&r++}if(r=O(e,r),e[r]==="["&&a)return{expr:{type:"ArithDoubleSubscript",array:s,index:a},pos:r};let c=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let l of c)if(e.slice(r,r+l.length)===l&&e.slice(r,r+l.length+1)!=="=="){r+=l.length;let{expr:f,pos:h}=He(t,e,r);return{expr:{type:"ArithAssignment",operator:l,variable:s,subscript:a,stringKey:i,value:f},pos:h}}return{expr:{type:"ArithArrayElement",array:s,index:a,stringKey:i},pos:r}}r=O(e,r);let o=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let i of o)if(e.slice(r,r+i.length)===i&&e.slice(r,r+i.length+1)!=="=="){r+=i.length;let{expr:a,pos:c}=He(t,e,r);return{expr:{type:"ArithAssignment",operator:i,variable:s,value:a},pos:c}}return{expr:{type:"ArithVariable",name:s},pos:r}}return{expr:{type:"ArithNumber",value:0},pos:r}}function Se(t){if(t.includes("#")){let[e,n]=t.split("#"),r=Number.parseInt(e,10);if(r<2||r>64)return Number.NaN;if(r<=36)return Number.parseInt(n,r);let s=0;for(let o of n){let i;if(o>="0"&&o<="9")i=o.charCodeAt(0)-48;else if(o>="a"&&o<="z")i=o.charCodeAt(0)-97+10;else if(o>="A"&&o<="Z")i=o.charCodeAt(0)-65+36;else if(o==="@")i=62;else if(o==="_")i=63;else return Number.NaN;if(i>=r)return Number.NaN;s=s*r+i}return s}return t.startsWith("0x")||t.startsWith("0X")?Number.parseInt(t.slice(2),16):t.startsWith("0")&&t.length>1&&/^[0-9]+$/.test(t)?/[89]/.test(t)?Number.NaN:Number.parseInt(t,8):Number.parseInt(t,10)}function O(t,e){for(;e<t.length;){if(t[e]==="\\"&&t[e+1]===`
1
+ import{a as U,b as X,c as V,d as te,e as Y,f as k,g as F,h as ye,i as z,j as Ue}from"./chunks/chunk-JYYFSUWP.js";import{a as le}from"./chunks/chunk-44UOCSGV.js";var gt=[{name:"echo",load:async()=>(await import("./chunks/echo-W2TA2N7Y.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-5KESXK2M.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-3ZT5XOIZ.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-B7C35UDO.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-WYI2LJ6H.js")).mkdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-Z5XRYFYY.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-5X2XSQQ6.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-BLHAPLQZ.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-GN23UIZU.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-UTUVIAFP.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-VLKWIL3N.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-ZVX5RTL4.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-HHC33N5C.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-7H5R4WKO.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-BLGGG2VX.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-OXLYBRUE.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-TM5F5YO4.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-CZTYKNEE.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-CZTYKNEE.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-CZTYKNEE.js")).egrepCommand},{name:"sed",load:async()=>(await import("./chunks/sed-2WWCANZT.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-FMEL7ESV.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-LHMQWYH2.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-IIOQKNTS.js")).uniqCommand},{name:"cut",load:async()=>(await import("./chunks/cut-7RHEYJ7Y.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-L4TYPVSP.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-UV4V27RJ.js")).trCommand},{name:"tee",load:async()=>(await import("./chunks/tee-VCNOG5VI.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-WM6ZETA7.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-SB5JXIY3.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-Q5HDZLH2.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-75UXQ4XJ.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-I5HYAKTQ.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-OORA5GFS.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-OORA5GFS.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-7ZSTROM7.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-7ZSTROM7.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-7Z2STZ6Y.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-E5JPQL24.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-OD7ZXH3O.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-OD7ZXH3O.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-ZBD2DMXN.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-T4PXVRYX.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-T4PXVRYX.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-7R2XGLLH.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-WATI5PWI.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-IVJFQANX.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-YOOSNZVA.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-QJBQD6VS.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-THAT7IOO.js")).timeoutCommand},{name:"seq",load:async()=>(await import("./chunks/seq-TFPZQZPJ.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-A4LJAGVP.js")).exprCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-XMBYO6FD.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-SDCRRU2F.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-ONWH3TNF.js")).whichCommand}],pr=[{name:"curl",load:async()=>(await import("./chunks/curl-PA2MWGKN.js")).curlCommand}],mr=new Map;function yr(t){return{name:t.name,async execute(e,n){let r=mr.get(t.name);return r||(r=await t.load(),mr.set(t.name,r)),r.execute(e,n)}}}function Tn(){return gt.map(t=>t.name)}function Wn(){return pr.map(t=>t.name)}function Er(t){return(t?gt.filter(n=>t.includes(n.name)):gt).map(yr)}function wr(){return pr.map(yr)}function gr(t){return"load"in t&&typeof t.load=="function"}function Fn(t,e){return{name:t,execute:e}}function Ar(t){let e=null;return{name:t.name,async execute(n,r){return e||(e=await t.load()),e.execute(n,r)}}}var Mn=new TextEncoder,Bn=new TextDecoder;function re(t,e){if(t instanceof Uint8Array)return t;switch(e){case"base64":return Uint8Array.from(atob(t),n=>n.charCodeAt(0));case"hex":{let n=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)n[r/2]=parseInt(t.slice(r,r+2),16);return n}case"binary":case"latin1":return Uint8Array.from(t,n=>n.charCodeAt(0));default:return Mn.encode(t)}}function xe(t,e){switch(e){case"base64":return btoa(String.fromCharCode(...t));case"hex":return Array.from(t).map(n=>n.toString(16).padStart(2,"0")).join("");case"binary":case"latin1":return String.fromCharCode(...t);default:return Bn.decode(t)}}function Z(t){if(t!=null)return typeof t=="string"?t:t.encoding??void 0}var Ve=new TextEncoder;function zn(t){return typeof t=="object"&&t!==null&&!(t instanceof Uint8Array)&&"content"in t}var ne=class{data=new Map;constructor(e){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),e)for(let[n,r]of Object.entries(e))zn(r)?this.writeFileSync(n,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(n,r)}normalizePath(e){if(!e||e==="/")return"/";let n=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;n.startsWith("/")||(n=`/${n}`);let r=n.split("/").filter(o=>o&&o!=="."),s=[];for(let o of r)o===".."?s.pop():s.push(o);return`/${s.join("/")}`||"/"}dirname(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.lastIndexOf("/");return r===0?"/":n.slice(0,r)}ensureParentDirs(e){let n=this.dirname(e);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(e,n,r,s){let o=this.normalizePath(e);this.ensureParentDirs(o);let i=Z(r),a=re(n,i);this.data.set(o,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}async readFile(e,n){let r=await this.readFileBuffer(e),s=Z(n);return xe(r,s)}async readFileBuffer(e){let n=this.normalizePath(e),r=this.data.get(n),s=n;if(!r)throw new Error(`ENOENT: no such file or directory, open '${e}'`);let o=new Set;for(;r&&r.type==="symlink";){if(o.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);o.add(s),s=this.resolveSymlink(s,r.target),r=this.data.get(s)}if(!r)throw new Error(`ENOENT: no such file or directory, open '${e}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return r.content instanceof Uint8Array?r.content:Ve.encode(r.content)}async writeFile(e,n,r){this.writeFileSync(e,n,r)}async appendFile(e,n,r){let s=this.normalizePath(e),o=this.data.get(s);if(o&&o.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${e}'`);let i=Z(r),a=re(n,i);if(o?.type==="file"){let c=o.content instanceof Uint8Array?o.content:Ve.encode(o.content),l=new Uint8Array(c.length+a.length);l.set(c),l.set(a,c.length),this.data.set(s,{type:"file",content:l,mode:o.mode,mtime:new Date})}else this.writeFileSync(e,n,r)}async exists(e){return this.data.has(this.normalizePath(e))}async stat(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);if(r.type==="symlink"){let o=this.resolveSymlink(n,r.target),i=this.data.get(o);if(!i)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);r=i}let s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=Ve.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}async lstat(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};let s=0;return r.type==="file"&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=Ve.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date}}resolveSymlink(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${n}`:`${r}/${n}`)}async mkdir(e,n){this.mkdirSync(e,n)}mkdirSync(e,n){let r=this.normalizePath(e);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${e}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${e}'`);return}let s=this.dirname(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${e}'`);let s=n==="/"?"/":`${n}/`,o=[];for(let i of this.data.keys())if(i!==n&&i.startsWith(s)){let c=i.slice(s.length).split("/")[0];c&&!o.includes(c)&&o.push(c)}return o.sort()}async rm(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}if(s.type==="directory"){let o=await this.readdir(r);if(o.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let i of o){let a=r==="/"?`/${i}`:`${r}/${i}`;await this.rm(a,n)}}}this.data.delete(r)}async cp(e,n,r){let s=this.normalizePath(e),o=this.normalizePath(n),i=this.data.get(s);if(!i)throw new Error(`ENOENT: no such file or directory, cp '${e}'`);if(i.type==="file")this.ensureParentDirs(o),this.data.set(o,{...i});else if(i.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(o,{recursive:!0});let a=await this.readdir(s);for(let c of a){let l=s==="/"?`/${c}`:`${s}/${c}`,f=o==="/"?`/${c}`:`${o}/${c}`;await this.cp(l,f,r)}}}async mv(e,n){await this.cp(e,n,{recursive:!0}),await this.rm(e,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=e==="/"?`/${n}`:`${e}/${n}`;return this.normalizePath(r)}async chmod(e,n){let r=this.normalizePath(e),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);s.mode=n}async symlink(e,n){let r=this.normalizePath(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:e,mode:511,mtime:new Date})}async link(e,n){let r=this.normalizePath(e),s=this.normalizePath(n),o=this.data.get(r);if(!o)throw new Error(`ENOENT: no such file or directory, link '${e}'`);if(o.type!=="file")throw new Error(`EPERM: operation not permitted, link '${e}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${n}'`);this.ensureParentDirs(s),this.data.set(s,{type:"file",content:o.content,mode:o.mode,mtime:o.mtime})}async readlink(e){let n=this.normalizePath(e),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}};function T(t,e){return{type:"ArithmeticExpression",expression:se(t,e,0).expr}}function se(t,e,n){return Un(t,e,n)}function Un(t,e,n){let{expr:r,pos:s}=He(t,e,n);for(s=O(e,s);e[s]===",";){s++;let{expr:o,pos:i}=He(t,e,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=O(e,i)}return{expr:r,pos:s}}function He(t,e,n){let{expr:r,pos:s}=Vn(t,e,n);if(s=O(e,s),e[s]==="?"){s++;let{expr:o,pos:i}=se(t,e,s);if(s=O(e,i),e[s]===":"){s++;let{expr:a,pos:c}=se(t,e,s);return{expr:{type:"ArithTernary",condition:r,consequent:o,alternate:a},pos:c}}}return{expr:r,pos:s}}function Vn(t,e,n){let{expr:r,pos:s}=xr(t,e,n);for(;s=O(e,s),e.slice(s,s+2)==="||";){s+=2;let{expr:o,pos:i}=xr(t,e,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=i}return{expr:r,pos:s}}function xr(t,e,n){let{expr:r,pos:s}=Sr(t,e,n);for(;s=O(e,s),e.slice(s,s+2)==="&&";){s+=2;let{expr:o,pos:i}=Sr(t,e,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=i}return{expr:r,pos:s}}function Sr(t,e,n){let{expr:r,pos:s}=br(t,e,n);for(;s=O(e,s),e[s]==="|"&&e[s+1]!=="|";){s++;let{expr:o,pos:i}=br(t,e,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=i}return{expr:r,pos:s}}function br(t,e,n){let{expr:r,pos:s}=Nr(t,e,n);for(;s=O(e,s),e[s]==="^";){s++;let{expr:o,pos:i}=Nr(t,e,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=i}return{expr:r,pos:s}}function Nr(t,e,n){let{expr:r,pos:s}=Cr(t,e,n);for(;s=O(e,s),e[s]==="&"&&e[s+1]!=="&";){s++;let{expr:o,pos:i}=Cr(t,e,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=i}return{expr:r,pos:s}}function Cr(t,e,n){let{expr:r,pos:s}=$r(t,e,n);for(;s=O(e,s),e.slice(s,s+2)==="=="||e.slice(s,s+2)==="!=";){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=$r(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function $r(t,e,n){let{expr:r,pos:s}=At(t,e,n);for(;;)if(s=O(e,s),e.slice(s,s+2)==="<="||e.slice(s,s+2)===">="){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=At(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else if(e[s]==="<"||e[s]===">"){let o=e[s];s++;let{expr:i,pos:a}=At(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else break;return{expr:r,pos:s}}function At(t,e,n){let{expr:r,pos:s}=Pr(t,e,n);for(;s=O(e,s),e.slice(s,s+2)==="<<"||e.slice(s,s+2)===">>";){let o=e.slice(s,s+2);s+=2;let{expr:i,pos:a}=Pr(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function Pr(t,e,n){let{expr:r,pos:s}=vr(t,e,n);for(;s=O(e,s),(e[s]==="+"||e[s]==="-")&&e[s+1]!==e[s];){let o=e[s];s++;let{expr:i,pos:a}=vr(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}return{expr:r,pos:s}}function vr(t,e,n){let{expr:r,pos:s}=Ge(t,e,n);for(;;)if(s=O(e,s),e[s]==="*"&&e[s+1]!=="*"){s++;let{expr:o,pos:i}=Ge(t,e,s);r={type:"ArithBinary",operator:"*",left:r,right:o},s=i}else if(e[s]==="/"||e[s]==="%"){let o=e[s];s++;let{expr:i,pos:a}=Ge(t,e,s);r={type:"ArithBinary",operator:o,left:r,right:i},s=a}else break;return{expr:r,pos:s}}function Ge(t,e,n){let{expr:r,pos:s}=xt(t,e,n),o=O(e,s);if(e.slice(o,o+2)==="**"){o+=2;let{expr:i,pos:a}=Ge(t,e,o);return{expr:{type:"ArithBinary",operator:"**",left:r,right:i},pos:a}}return{expr:r,pos:s}}function xt(t,e,n){let r=O(e,n);if(e.slice(r,r+2)==="++"||e.slice(r,r+2)==="--"){let s=e.slice(r,r+2);r+=2;let{expr:o,pos:i}=xt(t,e,r);return{expr:{type:"ArithUnary",operator:s,operand:o,prefix:!0},pos:i}}if(e[r]==="+"||e[r]==="-"||e[r]==="!"||e[r]==="~"){let s=e[r];r++;let{expr:o,pos:i}=xt(t,e,r);return{expr:{type:"ArithUnary",operator:s,operand:o,prefix:!0},pos:i}}return Hn(t,e,r)}function Gn(t,e){let n=t[e];return n==="$"||n==="`"}function Hn(t,e,n){let{expr:r,pos:s}=Ir(t,e,n),o=[r];for(;Gn(e,s);){let{expr:i,pos:a}=Ir(t,e,s);o.push(i),s=a}if(o.length>1&&(r={type:"ArithConcat",parts:o}),s=O(e,s),e.slice(s,s+2)==="++"||e.slice(s,s+2)==="--"){let i=e.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:i,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function Ir(t,e,n){let r=O(e,n);if(e.slice(r,r+3)==="$(("){r+=3;let s=1,o=r;for(;r<e.length-1&&s>0;)e[r]==="("&&e[r+1]==="("?(s++,r+=2):e[r]===")"&&e[r+1]===")"?(s--,s>0&&(r+=2)):r++;let i=e.slice(o,r),{expr:a}=se(t,i,0);return r+=2,{expr:{type:"ArithNested",expression:a},pos:r}}if(e.slice(r,r+2)==="$("&&e[r+2]!=="("){r+=2;let s=1,o=r;for(;r<e.length&&s>0;)e[r]==="("?s++:e[r]===")"&&s--,s>0&&r++;let i=e.slice(o,r);return r++,{expr:{type:"ArithCommandSubst",command:i},pos:r}}if(e[r]==="`"){r++;let s=r;for(;r<e.length&&e[r]!=="`";)r++;let o=e.slice(s,r);return e[r]==="`"&&r++,{expr:{type:"ArithCommandSubst",command:o},pos:r}}if(e[r]==="("){r++;let{expr:s,pos:o}=se(t,e,r);return r=O(e,o),e[r]===")"&&r++,{expr:{type:"ArithGroup",expression:s},pos:r}}if(/[0-9]/.test(e[r])){let s="",o=!1;for(;r<e.length;){let a=e[r];if(o)if(/[0-9a-zA-Z@_]/.test(a))s+=a,r++;else break;else if(a==="#")o=!0,s+=a,r++;else if(/[0-9a-fA-FxX]/.test(a))s+=a,r++;else break}if(e[r]==="."&&/[0-9]/.test(e[r+1]))throw new F(`${s}.${e[r+1]}...: syntax error: invalid arithmetic operator`);if(e[r]==="["){let a=e.slice(r).trim();return{expr:{type:"ArithNumberSubscript",number:s,errorToken:a},pos:e.length}}return{expr:{type:"ArithNumber",value:Se(s)},pos:r}}if(e[r]==="$"&&e[r+1]==="{"){let s=r+2,o=1,i=s;for(;i<e.length&&o>0;)e[i]==="{"?o++:e[i]==="}"&&o--,o>0&&i++;let a=e.slice(s,i),c=i+1;if(e[c]==="#"){let l=c+1;for(;l<e.length&&/[0-9a-zA-Z@_]/.test(e[l]);)l++;let f=e.slice(c+1,l);return{expr:{type:"ArithDynamicBase",baseExpr:a,value:f},pos:l}}if(/[0-9]/.test(e[c])||e[c]==="x"||e[c]==="X"){let l=c;if(e[c]==="x"||e[c]==="X")for(l++;l<e.length&&/[0-9a-fA-F]/.test(e[l]);)l++;else for(;l<e.length&&/[0-9]/.test(e[l]);)l++;let f=e.slice(c,l);return{expr:{type:"ArithDynamicNumber",prefix:a,suffix:f},pos:l}}return r=c,{expr:{type:"ArithBracedExpansion",content:a},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[0-9]/.test(e[r+1])){r++;let s="";for(;r<e.length&&/[0-9]/.test(e[r]);)s+=e[r],r++;return{expr:{type:"ArithVariable",name:s},pos:r}}if(e[r]==="$"&&r+1<e.length&&/[a-zA-Z_]/.test(e[r+1])&&r++,/[a-zA-Z_]/.test(e[r])){let s="";for(;r<e.length&&/[a-zA-Z0-9_]/.test(e[r]);)s+=e[r],r++;if(e[r]==="["){r++;let i;if(e[r]==="'"||e[r]==='"'){let l=e[r];for(r++,i="";r<e.length&&e[r]!==l;)i+=e[r],r++;e[r]===l&&r++,r=O(e,r),e[r]==="]"&&r++}let a;if(i===void 0){let{expr:l,pos:f}=se(t,e,r);a=l,r=f,e[r]==="]"&&r++}if(r=O(e,r),e[r]==="["&&a)return{expr:{type:"ArithDoubleSubscript",array:s,index:a},pos:r};let c=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let l of c)if(e.slice(r,r+l.length)===l&&e.slice(r,r+l.length+1)!=="=="){r+=l.length;let{expr:f,pos:h}=He(t,e,r);return{expr:{type:"ArithAssignment",operator:l,variable:s,subscript:a,stringKey:i,value:f},pos:h}}return{expr:{type:"ArithArrayElement",array:s,index:a,stringKey:i},pos:r}}r=O(e,r);let o=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];for(let i of o)if(e.slice(r,r+i.length)===i&&e.slice(r,r+i.length+1)!=="=="){r+=i.length;let{expr:a,pos:c}=He(t,e,r);return{expr:{type:"ArithAssignment",operator:i,variable:s,value:a},pos:c}}return{expr:{type:"ArithVariable",name:s},pos:r}}return{expr:{type:"ArithNumber",value:0},pos:r}}function Se(t){if(t.includes("#")){let[e,n]=t.split("#"),r=Number.parseInt(e,10);if(r<2||r>64)return Number.NaN;if(r<=36)return Number.parseInt(n,r);let s=0;for(let o of n){let i;if(o>="0"&&o<="9")i=o.charCodeAt(0)-48;else if(o>="a"&&o<="z")i=o.charCodeAt(0)-97+10;else if(o>="A"&&o<="Z")i=o.charCodeAt(0)-65+36;else if(o==="@")i=62;else if(o==="_")i=63;else return Number.NaN;if(i>=r)return Number.NaN;s=s*r+i}return s}return t.startsWith("0x")||t.startsWith("0X")?Number.parseInt(t.slice(2),16):t.startsWith("0")&&t.length>1&&/^[0-9]+$/.test(t)?/[89]/.test(t)?Number.NaN:Number.parseInt(t,8):Number.parseInt(t,10)}function O(t,e){for(;e<t.length;){if(t[e]==="\\"&&t[e+1]===`
2
2
  `){e+=2;continue}if(/\s/.test(t[e])){e++;continue}break}return e}var A={script(t){return{type:"Script",statements:t}},statement(t,e=[],n=!1){return{type:"Statement",pipelines:t,operators:e,background:n}},pipeline(t,e=!1){return{type:"Pipeline",commands:t,negated:e}},simpleCommand(t,e=[],n=[],r=[]){return{type:"SimpleCommand",name:t,args:e,assignments:n,redirections:r}},word(t){return{type:"Word",parts:t}},literal(t){return{type:"Literal",value:t}},singleQuoted(t){return{type:"SingleQuoted",value:t}},doubleQuoted(t){return{type:"DoubleQuoted",parts:t}},escaped(t){return{type:"Escaped",value:t}},parameterExpansion(t,e=null){return{type:"ParameterExpansion",parameter:t,operation:e}},commandSubstitution(t,e=!1){return{type:"CommandSubstitution",body:t,legacy:e}},arithmeticExpansion(t){return{type:"ArithmeticExpansion",expression:t}},assignment(t,e,n=!1,r=null){return{type:"Assignment",name:t,value:e,append:n,array:r}},redirection(t,e,n=null){return{type:"Redirection",fd:n,operator:t,target:e}},hereDoc(t,e,n=!1,r=!1){return{type:"HereDoc",delimiter:t,content:e,stripTabs:n,quoted:r}},ifNode(t,e=null,n=[]){return{type:"If",clauses:t,elseBody:e,redirections:n}},forNode(t,e,n,r=[]){return{type:"For",variable:t,words:e,body:n,redirections:r}},whileNode(t,e,n=[]){return{type:"While",condition:t,body:e,redirections:n}},untilNode(t,e,n=[]){return{type:"Until",condition:t,body:e,redirections:n}},caseNode(t,e,n=[]){return{type:"Case",word:t,items:e,redirections:n}},caseItem(t,e,n=";;"){return{type:"CaseItem",patterns:t,body:e,terminator:n}},subshell(t,e=[]){return{type:"Subshell",body:t,redirections:e}},group(t,e=[]){return{type:"Group",body:t,redirections:e}},functionDef(t,e,n=[]){return{type:"FunctionDef",name:t,body:e,redirections:n}},conditionalCommand(t,e=[]){return{type:"ConditionalCommand",expression:t,redirections:e}},arithmeticCommand(t,e=[]){return{type:"ArithmeticCommand",expression:t,redirections:e}}};var u;(function(t){t.EOF="EOF",t.NEWLINE="NEWLINE",t.SEMICOLON="SEMICOLON",t.AMP="AMP",t.PIPE="PIPE",t.PIPE_AMP="PIPE_AMP",t.AND_AND="AND_AND",t.OR_OR="OR_OR",t.BANG="BANG",t.LESS="LESS",t.GREAT="GREAT",t.DLESS="DLESS",t.DGREAT="DGREAT",t.LESSAND="LESSAND",t.GREATAND="GREATAND",t.LESSGREAT="LESSGREAT",t.DLESSDASH="DLESSDASH",t.CLOBBER="CLOBBER",t.TLESS="TLESS",t.AND_GREAT="AND_GREAT",t.AND_DGREAT="AND_DGREAT",t.LPAREN="LPAREN",t.RPAREN="RPAREN",t.LBRACE="LBRACE",t.RBRACE="RBRACE",t.DSEMI="DSEMI",t.SEMI_AND="SEMI_AND",t.SEMI_SEMI_AND="SEMI_SEMI_AND",t.DBRACK_START="DBRACK_START",t.DBRACK_END="DBRACK_END",t.DPAREN_START="DPAREN_START",t.DPAREN_END="DPAREN_END",t.IF="IF",t.THEN="THEN",t.ELSE="ELSE",t.ELIF="ELIF",t.FI="FI",t.FOR="FOR",t.WHILE="WHILE",t.UNTIL="UNTIL",t.DO="DO",t.DONE="DONE",t.CASE="CASE",t.ESAC="ESAC",t.IN="IN",t.FUNCTION="FUNCTION",t.SELECT="SELECT",t.TIME="TIME",t.COPROC="COPROC",t.WORD="WORD",t.NAME="NAME",t.NUMBER="NUMBER",t.ASSIGNMENT_WORD="ASSIGNMENT_WORD",t.COMMENT="COMMENT",t.HEREDOC_CONTENT="HEREDOC_CONTENT"})(u||(u={}));var je={if:u.IF,then:u.THEN,else:u.ELSE,elif:u.ELIF,fi:u.FI,for:u.FOR,while:u.WHILE,until:u.UNTIL,do:u.DO,done:u.DONE,case:u.CASE,esac:u.ESAC,in:u.IN,function:u.FUNCTION,select:u.SELECT,time:u.TIME,coproc:u.COPROC};function kr(t){let e=t.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!e)return!1;let n=t.slice(e[0].length);if(n===""||n==="+")return!0;if(n[0]==="["){let r=0,s=0;for(;s<n.length;s++)if(n[s]==="[")r++;else if(n[s]==="]"&&(r--,r===0))break;if(r!==0||s>=n.length)return!1;let o=n.slice(s+1);return o===""||o==="+"}return!1}var jn=[[";",";","&",u.SEMI_SEMI_AND],["<","<","<",u.TLESS],["&",">",">",u.AND_DGREAT]],Zn=[["[","[",u.DBRACK_START],["]","]",u.DBRACK_END],["(","(",u.DPAREN_START],[")",")",u.DPAREN_END],["&","&",u.AND_AND],["|","|",u.OR_OR],[";",";",u.DSEMI],[";","&",u.SEMI_AND],["|","&",u.PIPE_AMP],[">",">",u.DGREAT],["<","&",u.LESSAND],[">","&",u.GREATAND],["<",">",u.LESSGREAT],[">","|",u.CLOBBER],["&",">",u.AND_GREAT]],qn={"|":u.PIPE,"&":u.AMP,";":u.SEMICOLON,"(":u.LPAREN,")":u.RPAREN,"<":u.LESS,">":u.GREAT};function Qn(t){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)}var Ze=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];constructor(e){this.input=e}tokenize(){let n=this.input.length,r=this.tokens,s=this.pendingHeredocs;for(;this.pos<n&&(this.skipWhitespace(),!(this.pos>=n));){if(s.length>0&&r.length>0&&r[r.length-1].type===u.NEWLINE){this.readHeredocContent();continue}let o=this.nextToken();o&&r.push(o)}return r.push({type:u.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let e=this.input,n=e.length,r=this.pos,s=this.column,o=this.line;for(;r<n;){let i=e[r];if(i===" "||i===" ")r++,s++;else if(i==="\\"&&e[r+1]===`
3
3
  `)r+=2,o++,s=1;else break}this.pos=r,this.column=s,this.line=o}nextToken(){let e=this.input,n=this.pos,r=this.line,s=this.column,o=e[n],i=e[n+1],a=e[n+2];if(o==="#")return this.readComment(n,r,s);if(o===`
4
4
  `)return this.pos=n+1,this.line++,this.column=1,{type:u.NEWLINE,value:`
@@ -130,12 +130,12 @@ ${tt}`):(nr(t,e.slice(n)),N)}return N}function nr(t,e){let n=1;for(;t.state.env[
130
130
  `,1)}return this.ctx.state.env=r,this.ctx.state.cwd=s,this.ctx.state.loopDepth=o,this.ctx.state.groupStdin=i,x(a,c,l)}async executeGroup(e,n=""){let r="",s="",o=0,i=this.ctx.state.groupStdin;n&&(this.ctx.state.groupStdin=n);try{for(let a of e.body){let c=await this.executeStatement(a);r+=c.stdout,s+=c.stderr,o=c.exitCode}}catch(a){if(this.ctx.state.groupStdin=i,a instanceof z)throw a;if(Ue(a)||a instanceof te||a instanceof k)throw a.prependOutput(r,s),a;return x(r,`${s}${le(a)}
131
131
  `,1)}return this.ctx.state.groupStdin=i,x(r,s,o)}async executeArithmeticCommand(e){try{let n=await $(this.ctx,e.expression.expression);return _(n!==0)}catch(n){return S(`bash: arithmetic expression: ${n.message}
132
132
  `)}}async executeConditionalCommand(e){try{let n=await me(this.ctx,e.expression);return _(n)}catch(n){return S(`bash: conditional expression: ${n.message}
133
- `,2)}}};var Pe={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4};function On(t){return t?{maxCallDepth:t.maxCallDepth??Pe.maxCallDepth,maxCommandCount:t.maxCommandCount??Pe.maxCommandCount,maxLoopIterations:t.maxLoopIterations??Pe.maxLoopIterations,maxAwkIterations:t.maxAwkIterations??Pe.maxAwkIterations,maxSedIterations:t.maxSedIterations??Pe.maxSedIterations}:{...Pe}}function _n(t){try{let e=new URL(t);return{origin:e.origin,pathname:e.pathname,href:e.href}}catch{return null}}function Us(t){let e=_n(t);return e?{origin:e.origin,pathPrefix:e.pathname}:null}function Vs(t,e){let n=_n(t);if(!n)return!1;let r=Us(e);return!r||n.origin!==r.origin?!1:r.pathPrefix==="/"||r.pathPrefix===""?!0:n.pathname.startsWith(r.pathPrefix)}function hr(t,e){return!e||e.length===0?!1:e.some(n=>Vs(t,n))}var ve=class extends Error{constructor(e){super(`Network access denied: URL not in allow-list: ${e}`),this.name="NetworkAccessDeniedError"}},Ie=class extends Error{constructor(e){super(`Too many redirects (max: ${e})`),this.name="TooManyRedirectsError"}},Re=class extends Error{constructor(e){super(`Redirect target not in allow-list: ${e}`),this.name="RedirectNotAllowedError"}},yt=class extends Error{constructor(e,n){super(`HTTP method '${e}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}};var Gs=20,Hs=3e4,js=["GET","HEAD"],Zs=new Set(["GET","HEAD","OPTIONS"]),qs=new Set([301,302,303,307,308]);function dr(t){let e=t.maxRedirects??Gs,n=t.timeoutMs??Hs,r=t.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:t.allowedMethods??js;function s(a){if(!t.dangerouslyAllowFullInternetAccess&&!hr(a,t.allowedUrlPrefixes??[]))throw new ve(a)}function o(a){if(t.dangerouslyAllowFullInternetAccess)return;let c=a.toUpperCase();if(!r.includes(c))throw new yt(c,r)}async function i(a,c={}){let l=c.method?.toUpperCase()??"GET";s(a),o(l);let f=a,h=0,d=c.followRedirects??!0,m=c.timeoutMs!==void 0?Math.min(c.timeoutMs,n):n;for(;;){let y=new AbortController,g=setTimeout(()=>y.abort(),m);try{let p={method:l,headers:c.headers,signal:y.signal,redirect:"manual"};c.body&&!Zs.has(l)&&(p.body=c.body);let E=await fetch(f,p);if(qs.has(E.status)&&d){let w=E.headers.get("location");if(!w)return await Ln(E,f);let b=new URL(w,f).href;if(!t.dangerouslyAllowFullInternetAccess&&!hr(b,t.allowedUrlPrefixes??[]))throw new Re(b);if(h++,h>e)throw new Ie(e);f=b;continue}return await Ln(E,f)}finally{clearTimeout(g)}}}return i}async function Ln(t,e){let n={};return t.headers.forEach((r,s)=>{n[s.toLowerCase()]=r}),{status:t.status,statusText:t.statusText,headers:n,body:await t.text(),url:e}}var ze=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;state;constructor(e={}){let n=e.fs??new ne(e.files);this.fs=n,this.useDefaultLayout=!e.cwd&&!e.files;let r=e.cwd||(this.useDefaultLayout?"/home/user":"/"),s={HOME:this.useDefaultLayout?"/home/user":"/",PATH:"/bin:/usr/bin",IFS:`
134
- `,OSTYPE:"linux-gnu",MACHTYPE:"x86_64-pc-linux-gnu",HOSTTYPE:"x86_64",PWD:r,OLDPWD:r,...e.env};if(this.limits=On({...e.executionLimits,...e.maxCallDepth!==void 0&&{maxCallDepth:e.maxCallDepth},...e.maxCommandCount!==void 0&&{maxCommandCount:e.maxCommandCount},...e.maxLoopIterations!==void 0&&{maxLoopIterations:e.maxLoopIterations}}),e.network&&(this.secureFetch=dr(e.network)),this.sleepFn=e.sleep,this.state={env:s,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1},inCondition:!1,loopDepth:0},n instanceof ne)try{n.mkdirSync("/bin",{recursive:!0}),n.mkdirSync("/usr/bin",{recursive:!0}),this.useDefaultLayout&&(n.mkdirSync("/home/user",{recursive:!0}),n.mkdirSync("/tmp",{recursive:!0}))}catch{}if(r!=="/"&&n instanceof ne)try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of Er(e.commands))this.registerCommand(o);if(e.network)for(let o of wr())this.registerCommand(o);if(e.customCommands)for(let o of e.customCommands)gr(o)?this.registerCommand(Ar(o)):this.registerCommand(o)}registerCommand(e){if(this.commands.set(e.name,e),this.fs instanceof ne)try{this.fs.writeFileSync(`/bin/${e.name}`,`#!/bin/bash
133
+ `,2)}}};var Pe={maxCallDepth:100,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4};function On(t){return t?{maxCallDepth:t.maxCallDepth??Pe.maxCallDepth,maxCommandCount:t.maxCommandCount??Pe.maxCommandCount,maxLoopIterations:t.maxLoopIterations??Pe.maxLoopIterations,maxAwkIterations:t.maxAwkIterations??Pe.maxAwkIterations,maxSedIterations:t.maxSedIterations??Pe.maxSedIterations}:{...Pe}}function _n(t){try{let e=new URL(t);return{origin:e.origin,pathname:e.pathname,href:e.href}}catch{return null}}function Us(t){let e=_n(t);return e?{origin:e.origin,pathPrefix:e.pathname}:null}function Vs(t,e){let n=_n(t);if(!n)return!1;let r=Us(e);return!r||n.origin!==r.origin?!1:r.pathPrefix==="/"||r.pathPrefix===""?!0:n.pathname.startsWith(r.pathPrefix)}function hr(t,e){return!e||e.length===0?!1:e.some(n=>Vs(t,n))}var ve=class extends Error{constructor(e){super(`Network access denied: URL not in allow-list: ${e}`),this.name="NetworkAccessDeniedError"}},Ie=class extends Error{constructor(e){super(`Too many redirects (max: ${e})`),this.name="TooManyRedirectsError"}},Re=class extends Error{constructor(e){super(`Redirect target not in allow-list: ${e}`),this.name="RedirectNotAllowedError"}},yt=class extends Error{constructor(e,n){super(`HTTP method '${e}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}};var Gs=20,Hs=3e4,js=["GET","HEAD"],Zs=new Set(["GET","HEAD","OPTIONS"]),qs=new Set([301,302,303,307,308]);function dr(t){let e=t.maxRedirects??Gs,n=t.timeoutMs??Hs,r=t.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:t.allowedMethods??js;function s(a){if(!t.dangerouslyAllowFullInternetAccess&&!hr(a,t.allowedUrlPrefixes??[]))throw new ve(a)}function o(a){if(t.dangerouslyAllowFullInternetAccess)return;let c=a.toUpperCase();if(!r.includes(c))throw new yt(c,r)}async function i(a,c={}){let l=c.method?.toUpperCase()??"GET";s(a),o(l);let f=a,h=0,d=c.followRedirects??!0,m=c.timeoutMs!==void 0?Math.min(c.timeoutMs,n):n;for(;;){let y=new AbortController,g=setTimeout(()=>y.abort(),m);try{let p={method:l,headers:c.headers,signal:y.signal,redirect:"manual"};c.body&&!Zs.has(l)&&(p.body=c.body);let E=await fetch(f,p);if(qs.has(E.status)&&d){let w=E.headers.get("location");if(!w)return await Ln(E,f);let b=new URL(w,f).href;if(!t.dangerouslyAllowFullInternetAccess&&!hr(b,t.allowedUrlPrefixes??[]))throw new Re(b);if(h++,h>e)throw new Ie(e);f=b;continue}return await Ln(E,f)}finally{clearTimeout(g)}}}return i}async function Ln(t,e){let n={};return t.headers.forEach((r,s)=>{n[s.toLowerCase()]=r}),{status:t.status,statusText:t.statusText,headers:n,body:await t.text(),url:e}}var ze=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;logger;state;constructor(e={}){let n=e.fs??new ne(e.files);this.fs=n,this.useDefaultLayout=!e.cwd&&!e.files;let r=e.cwd||(this.useDefaultLayout?"/home/user":"/"),s={HOME:this.useDefaultLayout?"/home/user":"/",PATH:"/bin:/usr/bin",IFS:`
134
+ `,OSTYPE:"linux-gnu",MACHTYPE:"x86_64-pc-linux-gnu",HOSTTYPE:"x86_64",PWD:r,OLDPWD:r,...e.env};if(this.limits=On({...e.executionLimits,...e.maxCallDepth!==void 0&&{maxCallDepth:e.maxCallDepth},...e.maxCommandCount!==void 0&&{maxCommandCount:e.maxCommandCount},...e.maxLoopIterations!==void 0&&{maxLoopIterations:e.maxLoopIterations}}),e.network&&(this.secureFetch=dr(e.network)),this.sleepFn=e.sleep,this.logger=e.logger,this.state={env:s,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1},inCondition:!1,loopDepth:0},n instanceof ne)try{n.mkdirSync("/bin",{recursive:!0}),n.mkdirSync("/usr/bin",{recursive:!0}),this.useDefaultLayout&&(n.mkdirSync("/home/user",{recursive:!0}),n.mkdirSync("/tmp",{recursive:!0}))}catch{}if(r!=="/"&&n instanceof ne)try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of Er(e.commands))this.registerCommand(o);if(e.network)for(let o of wr())this.registerCommand(o);if(e.customCommands)for(let o of e.customCommands)gr(o)?this.registerCommand(Ar(o)):this.registerCommand(o)}registerCommand(e){if(this.commands.set(e.name,e),this.fs instanceof ne)try{this.fs.writeFileSync(`/bin/${e.name}`,`#!/bin/bash
135
135
  # Built-in command: ${e.name}
136
- `)}catch{}}async exec(e,n){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.
137
- `,exitCode:1,env:{...this.state.env,...n?.env}};if(!e.trim())return{stdout:"",stderr:"",exitCode:0,env:{...this.state.env,...n?.env}};let r=n?.cwd??this.state.cwd,s={...this.state,env:{...this.state.env,...n?.env,...n?.cwd?{PWD:n.cwd}:{}},cwd:r,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options}},o=e;n?.rawScript||(o=e.split(`
136
+ `)}catch{}}logResult(e){return this.logger&&(e.stdout&&this.logger.debug("stdout",{output:e.stdout}),e.stderr&&this.logger.info("stderr",{output:e.stderr}),this.logger.info("exit",{exitCode:e.exitCode})),e}async exec(e,n){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.
137
+ `,exitCode:1,env:{...this.state.env,...n?.env}};if(!e.trim())return{stdout:"",stderr:"",exitCode:0,env:{...this.state.env,...n?.env}};this.logger?.info("exec",{command:e});let r=n?.cwd??this.state.cwd,s={...this.state,env:{...this.state.env,...n?.env,...n?.cwd?{PWD:n.cwd}:{}},cwd:r,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options}},o=e;n?.rawScript||(o=e.split(`
138
138
  `).map(a=>a.trimStart()).join(`
139
- `));try{let i=ue(o),a={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn};return await new Be(a,s).executeScript(i)}catch(i){if(i instanceof k)return{stdout:i.stdout,stderr:i.stderr,exitCode:i.exitCode,env:{...this.state.env,...n?.env}};if(i instanceof F)return{stdout:i.stdout,stderr:i.stderr,exitCode:1,env:{...this.state.env,...n?.env}};if(i instanceof z)return{stdout:i.stdout,stderr:i.stderr,exitCode:z.EXIT_CODE,env:{...this.state.env,...n?.env}};if(i.name==="ParseException")return{stdout:"",stderr:`bash: syntax error: ${i.message}
140
- `,exitCode:2,env:{...this.state.env,...n?.env}};if(i instanceof RangeError)return{stdout:"",stderr:`bash: ${i.message}
141
- `,exitCode:1,env:{...this.state.env,...n?.env}};throw i}}async readFile(e){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,e))}async writeFile(e,n){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,e),n)}getCwd(){return this.state.cwd}getEnv(){return{...this.state.env}}};import*as B from"node:fs";import*as ke from"node:path";var Qs="/home/user/project",De=class{root;mountPoint;readOnly;memory=new Map;deleted=new Set;constructor(e){this.root=ke.resolve(e.root);let n=e.mountPoint??Qs;if(this.mountPoint=n==="/"?"/":n.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${n}`);if(this.readOnly=e.readOnly??!1,!B.existsSync(this.root))throw new Error(`OverlayFs root does not exist: ${this.root}`);if(!B.statSync(this.root).isDirectory())throw new Error(`OverlayFs root is not a directory: ${this.root}`);this.createMountPointDirs()}assertWritable(e){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${e}`)}createMountPointDirs(){let e=this.mountPoint.split("/").filter(Boolean),n="";for(let r of e)n+=`/${r}`,this.memory.has(n)||this.memory.set(n,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.memory.set("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}normalizePath(e){if(!e||e==="/")return"/";let n=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;n.startsWith("/")||(n=`/${n}`);let r=n.split("/").filter(o=>o&&o!=="."),s=[];for(let o of r)o===".."?s.pop():s.push(o);return`/${s.join("/")}`||"/"}getRelativeToMount(e){return this.mountPoint==="/"?e:e===this.mountPoint?"/":e.startsWith(`${this.mountPoint}/`)?e.slice(this.mountPoint.length):null}toRealPath(e){let n=this.normalizePath(e),r=this.getRelativeToMount(n);if(r===null)return null;let s=ke.join(this.root,r),o=ke.resolve(s);return!o.startsWith(this.root)&&o!==this.root.replace(/\/$/,"")?null:o}dirname(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.lastIndexOf("/");return r===0?"/":n.slice(0,r)}ensureParentDirs(e){let n=this.dirname(e);n!=="/"&&(this.memory.has(n)||(this.ensureParentDirs(n),this.memory.set(n,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(n))}async existsInOverlay(e){let n=this.normalizePath(e);if(this.deleted.has(n))return!1;if(this.memory.has(n))return!0;let r=this.toRealPath(n);if(!r)return!1;try{return await B.promises.access(r),!0}catch{return!1}}async readFile(e,n){let r=await this.readFileBuffer(e),s=Z(n);return xe(r,s)}async readFileBuffer(e,n=new Set){let r=this.normalizePath(e);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${e}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let i=this.resolveSymlink(r,s.target);return this.readFileBuffer(i,n)}if(s.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return s.content}let o=this.toRealPath(r);if(!o)throw new Error(`ENOENT: no such file or directory, open '${e}'`);try{let i=await B.promises.lstat(o);if(i.isSymbolicLink()){let c=await B.promises.readlink(o),l=this.resolveSymlink(r,c);return this.readFileBuffer(l,n)}if(i.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);let a=await B.promises.readFile(o);return new Uint8Array(a)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${e}'`):i}}async writeFile(e,n,r){this.assertWritable(`write '${e}'`);let s=this.normalizePath(e);this.ensureParentDirs(s);let o=Z(r),i=re(n,o);this.memory.set(s,{type:"file",content:i,mode:420,mtime:new Date}),this.deleted.delete(s)}async appendFile(e,n,r){this.assertWritable(`append '${e}'`);let s=this.normalizePath(e),o=Z(r),i=re(n,o),a;try{a=await this.readFileBuffer(s)}catch{a=new Uint8Array(0)}let c=new Uint8Array(a.length+i.length);c.set(a),c.set(i,a.length),this.ensureParentDirs(s),this.memory.set(s,{type:"file",content:c,mode:420,mtime:new Date}),this.deleted.delete(s)}async exists(e){return this.existsInOverlay(e)}async stat(e,n=new Set){let r=this.normalizePath(e);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${e}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let a=this.resolveSymlink(r,s.target);return this.stat(a,n)}let i=0;return s.type==="file"&&(i=s.content.length),{isFile:s.type==="file",isDirectory:s.type==="directory",isSymbolicLink:!1,mode:s.mode,size:i,mtime:s.mtime}}let o=this.toRealPath(r);if(!o)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);try{let i=await B.promises.stat(o);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:!1,mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${e}'`):i}}async lstat(e){let n=this.normalizePath(e);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let o=0;return r.type==="file"&&(o=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:o,mtime:r.mtime}}let s=this.toRealPath(n);if(!s)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);try{let o=await B.promises.lstat(s);return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:o.isSymbolicLink(),mode:o.mode,size:o.size,mtime:o.mtime}}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${e}'`):o}}resolveSymlink(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${n}`:`${r}/${n}`)}async mkdir(e,n){this.assertWritable(`mkdir '${e}'`);let r=this.normalizePath(e);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${e}'`);return}let o=this.dirname(r);if(o!=="/"&&!await this.existsInOverlay(o))if(n?.recursive)await this.mkdir(o,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.memory.set(r,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(r)}async readdir(e){let n=this.normalizePath(e);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let r=new Set,s=new Set,o=n==="/"?"/":`${n}/`;for(let a of this.deleted)if(a.startsWith(o)){let c=a.slice(o.length),l=c.split("/")[0];l&&!c.includes("/",l.length)&&s.add(l)}for(let a of this.memory.keys())if(a!==n&&a.startsWith(o)){let l=a.slice(o.length).split("/")[0];l&&!s.has(l)&&r.add(l)}let i=this.toRealPath(n);if(i)try{let a=await B.promises.readdir(i);for(let c of a)s.has(c)||r.add(c)}catch(a){if(a.code==="ENOENT"){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`)}else if(a.code!=="ENOTDIR")throw a}return Array.from(r).sort()}async rm(e,n){this.assertWritable(`rm '${e}'`);let r=this.normalizePath(e);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}try{if((await this.stat(r)).isDirectory){let i=await this.readdir(r);if(i.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let a of i){let c=r==="/"?`/${a}`:`${r}/${a}`;await this.rm(c,n)}}}}catch{}this.deleted.add(r),this.memory.delete(r)}async cp(e,n,r){this.assertWritable(`cp '${n}'`);let s=this.normalizePath(e),o=this.normalizePath(n);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, cp '${e}'`);let a=await this.stat(s);if(a.isFile){let c=await this.readFileBuffer(s);await this.writeFile(o,c)}else if(a.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(o,{recursive:!0});let c=await this.readdir(s);for(let l of c){let f=s==="/"?`/${l}`:`${s}/${l}`,h=o==="/"?`/${l}`:`${o}/${l}`;await this.cp(f,h,r)}}}async mv(e,n){this.assertWritable(`mv '${n}'`),await this.cp(e,n,{recursive:!0}),await this.rm(e,{recursive:!0})}resolvePath(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=e==="/"?`/${n}`:`${e}/${n}`;return this.normalizePath(r)}getAllPaths(){let e=new Set(this.memory.keys());for(let n of this.deleted)e.delete(n);return this.scanRealFs("/",e),Array.from(e)}scanRealFs(e,n){if(this.deleted.has(e))return;let r=this.toRealPath(e);if(r)try{let s=B.readdirSync(r);for(let o of s){let i=e==="/"?`/${o}`:`${e}/${o}`;if(this.deleted.has(i))continue;n.add(i);let a=ke.join(r,o);B.statSync(a).isDirectory()&&this.scanRealFs(i,n)}}catch{}}async chmod(e,n){this.assertWritable(`chmod '${e}'`);let r=this.normalizePath(e);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);let o=this.memory.get(r);if(o){o.mode=n;return}let i=await this.stat(r);if(i.isFile){let a=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:a,mode:n,mtime:new Date})}else i.isDirectory&&this.memory.set(r,{type:"directory",mode:n,mtime:new Date})}async symlink(e,n){this.assertWritable(`symlink '${n}'`);let r=this.normalizePath(n);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.memory.set(r,{type:"symlink",target:e,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(e,n){this.assertWritable(`link '${n}'`);let r=this.normalizePath(e),s=this.normalizePath(n);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${e}'`);let i=await this.stat(r);if(!i.isFile)throw new Error(`EPERM: operation not permitted, link '${e}'`);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let c=await this.readFileBuffer(r);this.ensureParentDirs(s),this.memory.set(s,{type:"file",content:c,mode:i.mode,mtime:new Date}),this.deleted.delete(s)}async readlink(e){let n=this.normalizePath(e);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);let r=this.memory.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}let s=this.toRealPath(n);if(!s)throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);try{return await B.promises.readlink(s)}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${e}'`):o.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${e}'`):o}}};import*as P from"node:fs";import*as ee from"node:path";var Et=class{root;constructor(e){if(this.root=ee.resolve(e.root),!P.existsSync(this.root))throw new Error(`ReadWriteFs root does not exist: ${this.root}`);if(!P.statSync(this.root).isDirectory())throw new Error(`ReadWriteFs root is not a directory: ${this.root}`)}toRealPath(e){let n=this.normalizePath(e),r=ee.join(this.root,n);return ee.resolve(r)}normalizePath(e){if(!e||e==="/")return"/";let n=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;n.startsWith("/")||(n=`/${n}`);let r=n.split("/").filter(o=>o&&o!=="."),s=[];for(let o of r)o===".."?s.pop():s.push(o);return`/${s.join("/")}`||"/"}async readFile(e,n){let r=await this.readFileBuffer(e),s=Z(n);return xe(r,s)}async readFileBuffer(e){let n=this.toRealPath(e);try{let r=await P.promises.readFile(n);return new Uint8Array(r)}catch(r){let s=r;throw s.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${e}'`):s.code==="EISDIR"?new Error(`EISDIR: illegal operation on a directory, read '${e}'`):r}}async writeFile(e,n,r){let s=this.toRealPath(e),o=Z(r),i=re(n,o),a=ee.dirname(s);await P.promises.mkdir(a,{recursive:!0}),await P.promises.writeFile(s,i)}async appendFile(e,n,r){let s=this.toRealPath(e),o=Z(r),i=re(n,o),a=ee.dirname(s);await P.promises.mkdir(a,{recursive:!0}),await P.promises.appendFile(s,i)}async exists(e){let n=this.toRealPath(e);try{return await P.promises.access(n),!0}catch{return!1}}async stat(e){let n=this.toRealPath(e);try{let r=await P.promises.stat(n);return{isFile:r.isFile(),isDirectory:r.isDirectory(),isSymbolicLink:!1,mode:r.mode,size:r.size,mtime:r.mtime}}catch(r){throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${e}'`):r}}async lstat(e){let n=this.toRealPath(e);try{let r=await P.promises.lstat(n);return{isFile:r.isFile(),isDirectory:r.isDirectory(),isSymbolicLink:r.isSymbolicLink(),mode:r.mode,size:r.size,mtime:r.mtime}}catch(r){throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${e}'`):r}}async mkdir(e,n){let r=this.toRealPath(e);try{await P.promises.mkdir(r,{recursive:n?.recursive})}catch(s){let o=s;throw o.code==="EEXIST"?new Error(`EEXIST: file already exists, mkdir '${e}'`):o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, mkdir '${e}'`):s}}async readdir(e){let n=this.toRealPath(e);try{return(await P.promises.readdir(n)).sort()}catch(r){let s=r;throw s.code==="ENOENT"?new Error(`ENOENT: no such file or directory, scandir '${e}'`):s.code==="ENOTDIR"?new Error(`ENOTDIR: not a directory, scandir '${e}'`):r}}async rm(e,n){let r=this.toRealPath(e);try{await P.promises.rm(r,{recursive:n?.recursive??!1,force:n?.force??!1})}catch(s){let o=s;throw o.code==="ENOENT"&&!n?.force?new Error(`ENOENT: no such file or directory, rm '${e}'`):o.code==="ENOTEMPTY"?new Error(`ENOTEMPTY: directory not empty, rm '${e}'`):s}}async cp(e,n,r){let s=this.toRealPath(e),o=this.toRealPath(n);try{await P.promises.cp(s,o,{recursive:r?.recursive??!1})}catch(i){let a=i;throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, cp '${e}'`):a.code==="EISDIR"?new Error(`EISDIR: is a directory, cp '${e}'`):i}}async mv(e,n){let r=this.toRealPath(e),s=this.toRealPath(n),o=ee.dirname(s);await P.promises.mkdir(o,{recursive:!0});try{await P.promises.rename(r,s)}catch(i){let a=i;if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${e}'`);if(a.code==="EXDEV"){await this.cp(e,n,{recursive:!0}),await this.rm(e,{recursive:!0});return}throw i}}resolvePath(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=e==="/"?`/${n}`:`${e}/${n}`;return this.normalizePath(r)}getAllPaths(){let e=[];return this.scanDir("/",e),e}scanDir(e,n){let r=this.toRealPath(e);try{let s=P.readdirSync(r);for(let o of s){let i=e==="/"?`/${o}`:`${e}/${o}`;n.push(i);let a=ee.join(r,o);P.statSync(a).isDirectory()&&this.scanDir(i,n)}}catch{}}async chmod(e,n){let r=this.toRealPath(e);try{await P.promises.chmod(r,n)}catch(s){throw s.code==="ENOENT"?new Error(`ENOENT: no such file or directory, chmod '${e}'`):s}}async symlink(e,n){let r=this.toRealPath(n);try{await P.promises.symlink(e,r)}catch(s){throw s.code==="EEXIST"?new Error(`EEXIST: file already exists, symlink '${n}'`):s}}async link(e,n){let r=this.toRealPath(e),s=this.toRealPath(n);try{await P.promises.link(r,s)}catch(o){let i=o;throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, link '${e}'`):i.code==="EEXIST"?new Error(`EEXIST: file already exists, link '${n}'`):i.code==="EPERM"?new Error(`EPERM: operation not permitted, link '${e}'`):o}}async readlink(e){let n=this.toRealPath(e);try{return await P.promises.readlink(n)}catch(r){let s=r;throw s.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${e}'`):s.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${e}'`):r}}};var Oe=class{cmdId;cwd;startedAt;exitCode;bashEnv;cmdLine;env;explicitCwd;resultPromise;constructor(e,n,r,s,o=!1){this.cmdId=crypto.randomUUID(),this.cwd=r,this.startedAt=new Date,this.bashEnv=e,this.cmdLine=n,this.env=s,this.explicitCwd=o,this.resultPromise=this.execute()}async execute(){let e=this.env||this.explicitCwd?{cwd:this.explicitCwd?this.cwd:void 0,env:this.env}:void 0,n=await this.bashEnv.exec(this.cmdLine,e);return this.exitCode=n.exitCode,n}async*logs(){let e=await this.resultPromise;e.stdout&&(yield{type:"stdout",data:e.stdout,timestamp:new Date}),e.stderr&&(yield{type:"stderr",data:e.stderr,timestamp:new Date})}async wait(){return await this.resultPromise,this}async output(){let e=await this.resultPromise;return e.stdout+e.stderr}async stdout(){return(await this.resultPromise).stdout}async stderr(){return(await this.resultPromise).stderr}async kill(){}};var wt=class t{bashEnv;constructor(e){this.bashEnv=e}static async create(e){let n=e?.fs;if(e?.overlayRoot){if(e?.fs)throw new Error("Cannot specify both 'fs' and 'overlayRoot' options");n=new De({root:e.overlayRoot})}let r=new ze({env:e?.env,cwd:e?.cwd,fs:n,maxCallDepth:e?.maxCallDepth,maxCommandCount:e?.maxCommandCount,maxLoopIterations:e?.maxLoopIterations,network:e?.network});return new t(r)}async runCommand(e,n){let r=n?.cwd??this.bashEnv.getCwd(),s=n?.cwd!==void 0;return new Oe(this.bashEnv,e,r,n?.env,s)}async writeFiles(e){for(let[n,r]of Object.entries(e)){let s;typeof r=="string"?s=r:r.encoding==="base64"?s=Buffer.from(r.content,"base64").toString("utf-8"):s=r.content;let o=n.substring(0,n.lastIndexOf("/"))||"/";o!=="/"&&await this.bashEnv.exec(`mkdir -p ${o}`),await this.bashEnv.writeFile(n,s)}}async readFile(e,n){let r=await this.bashEnv.readFile(e);return n==="base64"?Buffer.from(r).toString("base64"):r}async mkDir(e,n){let r=n?.recursive?"-p":"";await this.bashEnv.exec(`mkdir ${r} ${e}`)}async stop(){}async extendTimeout(e){}get domain(){}get bashEnvInstance(){return this.bashEnv}};export{ze as Bash,ne as InMemoryFs,ve as NetworkAccessDeniedError,De as OverlayFs,Et as ReadWriteFs,Re as RedirectNotAllowedError,wt as Sandbox,Oe as SandboxCommand,Ie as TooManyRedirectsError,Fn as defineCommand,Tn as getCommandNames,Wn as getNetworkCommandNames};
139
+ `));try{let i=ue(o),a={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn},l=await new Be(a,s).executeScript(i);return this.logResult(l)}catch(i){if(i instanceof k)return this.logResult({stdout:i.stdout,stderr:i.stderr,exitCode:i.exitCode,env:{...this.state.env,...n?.env}});if(i instanceof F)return this.logResult({stdout:i.stdout,stderr:i.stderr,exitCode:1,env:{...this.state.env,...n?.env}});if(i instanceof z)return this.logResult({stdout:i.stdout,stderr:i.stderr,exitCode:z.EXIT_CODE,env:{...this.state.env,...n?.env}});if(i.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${i.message}
140
+ `,exitCode:2,env:{...this.state.env,...n?.env}});if(i instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${i.message}
141
+ `,exitCode:1,env:{...this.state.env,...n?.env}});throw i}}async readFile(e){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,e))}async writeFile(e,n){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,e),n)}getCwd(){return this.state.cwd}getEnv(){return{...this.state.env}}};import*as B from"node:fs";import*as ke from"node:path";var Qs="/home/user/project",De=class{root;mountPoint;readOnly;memory=new Map;deleted=new Set;constructor(e){this.root=ke.resolve(e.root);let n=e.mountPoint??Qs;if(this.mountPoint=n==="/"?"/":n.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${n}`);if(this.readOnly=e.readOnly??!1,!B.existsSync(this.root))throw new Error(`OverlayFs root does not exist: ${this.root}`);if(!B.statSync(this.root).isDirectory())throw new Error(`OverlayFs root is not a directory: ${this.root}`);this.createMountPointDirs()}assertWritable(e){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${e}`)}createMountPointDirs(){let e=this.mountPoint.split("/").filter(Boolean),n="";for(let r of e)n+=`/${r}`,this.memory.has(n)||this.memory.set(n,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.memory.set("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}normalizePath(e){if(!e||e==="/")return"/";let n=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;n.startsWith("/")||(n=`/${n}`);let r=n.split("/").filter(o=>o&&o!=="."),s=[];for(let o of r)o===".."?s.pop():s.push(o);return`/${s.join("/")}`||"/"}getRelativeToMount(e){return this.mountPoint==="/"?e:e===this.mountPoint?"/":e.startsWith(`${this.mountPoint}/`)?e.slice(this.mountPoint.length):null}toRealPath(e){let n=this.normalizePath(e),r=this.getRelativeToMount(n);if(r===null)return null;let s=ke.join(this.root,r),o=ke.resolve(s);return!o.startsWith(this.root)&&o!==this.root.replace(/\/$/,"")?null:o}dirname(e){let n=this.normalizePath(e);if(n==="/")return"/";let r=n.lastIndexOf("/");return r===0?"/":n.slice(0,r)}ensureParentDirs(e){let n=this.dirname(e);n!=="/"&&(this.memory.has(n)||(this.ensureParentDirs(n),this.memory.set(n,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(n))}async existsInOverlay(e){let n=this.normalizePath(e);if(this.deleted.has(n))return!1;if(this.memory.has(n))return!0;let r=this.toRealPath(n);if(!r)return!1;try{return await B.promises.access(r),!0}catch{return!1}}async readFile(e,n){let r=await this.readFileBuffer(e),s=Z(n);return xe(r,s)}async readFileBuffer(e,n=new Set){let r=this.normalizePath(e);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${e}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${e}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let i=this.resolveSymlink(r,s.target);return this.readFileBuffer(i,n)}if(s.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);return s.content}let o=this.toRealPath(r);if(!o)throw new Error(`ENOENT: no such file or directory, open '${e}'`);try{let i=await B.promises.lstat(o);if(i.isSymbolicLink()){let c=await B.promises.readlink(o),l=this.resolveSymlink(r,c);return this.readFileBuffer(l,n)}if(i.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${e}'`);let a=await B.promises.readFile(o);return new Uint8Array(a)}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${e}'`):i}}async writeFile(e,n,r){this.assertWritable(`write '${e}'`);let s=this.normalizePath(e);this.ensureParentDirs(s);let o=Z(r),i=re(n,o);this.memory.set(s,{type:"file",content:i,mode:420,mtime:new Date}),this.deleted.delete(s)}async appendFile(e,n,r){this.assertWritable(`append '${e}'`);let s=this.normalizePath(e),o=Z(r),i=re(n,o),a;try{a=await this.readFileBuffer(s)}catch{a=new Uint8Array(0)}let c=new Uint8Array(a.length+i.length);c.set(a),c.set(i,a.length),this.ensureParentDirs(s),this.memory.set(s,{type:"file",content:c,mode:420,mtime:new Date}),this.deleted.delete(s)}async exists(e){return this.existsInOverlay(e)}async stat(e,n=new Set){let r=this.normalizePath(e);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${e}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${e}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let a=this.resolveSymlink(r,s.target);return this.stat(a,n)}let i=0;return s.type==="file"&&(i=s.content.length),{isFile:s.type==="file",isDirectory:s.type==="directory",isSymbolicLink:!1,mode:s.mode,size:i,mtime:s.mtime}}let o=this.toRealPath(r);if(!o)throw new Error(`ENOENT: no such file or directory, stat '${e}'`);try{let i=await B.promises.stat(o);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:!1,mode:i.mode,size:i.size,mtime:i.mtime}}catch(i){throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${e}'`):i}}async lstat(e){let n=this.normalizePath(e);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let o=0;return r.type==="file"&&(o=r.content.length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:o,mtime:r.mtime}}let s=this.toRealPath(n);if(!s)throw new Error(`ENOENT: no such file or directory, lstat '${e}'`);try{let o=await B.promises.lstat(s);return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:o.isSymbolicLink(),mode:o.mode,size:o.size,mtime:o.mtime}}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${e}'`):o}}resolveSymlink(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=this.dirname(e);return this.normalizePath(r==="/"?`/${n}`:`${r}/${n}`)}async mkdir(e,n){this.assertWritable(`mkdir '${e}'`);let r=this.normalizePath(e);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${e}'`);return}let o=this.dirname(r);if(o!=="/"&&!await this.existsInOverlay(o))if(n?.recursive)await this.mkdir(o,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${e}'`);this.memory.set(r,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(r)}async readdir(e){let n=this.normalizePath(e);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`);let r=new Set,s=new Set,o=n==="/"?"/":`${n}/`;for(let a of this.deleted)if(a.startsWith(o)){let c=a.slice(o.length),l=c.split("/")[0];l&&!c.includes("/",l.length)&&s.add(l)}for(let a of this.memory.keys())if(a!==n&&a.startsWith(o)){let l=a.slice(o.length).split("/")[0];l&&!s.has(l)&&r.add(l)}let i=this.toRealPath(n);if(i)try{let a=await B.promises.readdir(i);for(let c of a)s.has(c)||r.add(c)}catch(a){if(a.code==="ENOENT"){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${e}'`)}else if(a.code!=="ENOTDIR")throw a}return Array.from(r).sort()}async rm(e,n){this.assertWritable(`rm '${e}'`);let r=this.normalizePath(e);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${e}'`)}try{if((await this.stat(r)).isDirectory){let i=await this.readdir(r);if(i.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${e}'`);for(let a of i){let c=r==="/"?`/${a}`:`${r}/${a}`;await this.rm(c,n)}}}}catch{}this.deleted.add(r),this.memory.delete(r)}async cp(e,n,r){this.assertWritable(`cp '${n}'`);let s=this.normalizePath(e),o=this.normalizePath(n);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, cp '${e}'`);let a=await this.stat(s);if(a.isFile){let c=await this.readFileBuffer(s);await this.writeFile(o,c)}else if(a.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${e}'`);await this.mkdir(o,{recursive:!0});let c=await this.readdir(s);for(let l of c){let f=s==="/"?`/${l}`:`${s}/${l}`,h=o==="/"?`/${l}`:`${o}/${l}`;await this.cp(f,h,r)}}}async mv(e,n){this.assertWritable(`mv '${n}'`),await this.cp(e,n,{recursive:!0}),await this.rm(e,{recursive:!0})}resolvePath(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=e==="/"?`/${n}`:`${e}/${n}`;return this.normalizePath(r)}getAllPaths(){let e=new Set(this.memory.keys());for(let n of this.deleted)e.delete(n);return this.scanRealFs("/",e),Array.from(e)}scanRealFs(e,n){if(this.deleted.has(e))return;let r=this.toRealPath(e);if(r)try{let s=B.readdirSync(r);for(let o of s){let i=e==="/"?`/${o}`:`${e}/${o}`;if(this.deleted.has(i))continue;n.add(i);let a=ke.join(r,o);B.statSync(a).isDirectory()&&this.scanRealFs(i,n)}}catch{}}async chmod(e,n){this.assertWritable(`chmod '${e}'`);let r=this.normalizePath(e);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${e}'`);let o=this.memory.get(r);if(o){o.mode=n;return}let i=await this.stat(r);if(i.isFile){let a=await this.readFileBuffer(r);this.memory.set(r,{type:"file",content:a,mode:n,mtime:new Date})}else i.isDirectory&&this.memory.set(r,{type:"directory",mode:n,mtime:new Date})}async symlink(e,n){this.assertWritable(`symlink '${n}'`);let r=this.normalizePath(n);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.memory.set(r,{type:"symlink",target:e,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(e,n){this.assertWritable(`link '${n}'`);let r=this.normalizePath(e),s=this.normalizePath(n);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${e}'`);let i=await this.stat(r);if(!i.isFile)throw new Error(`EPERM: operation not permitted, link '${e}'`);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let c=await this.readFileBuffer(r);this.ensureParentDirs(s),this.memory.set(s,{type:"file",content:c,mode:i.mode,mtime:new Date}),this.deleted.delete(s)}async readlink(e){let n=this.normalizePath(e);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);let r=this.memory.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${e}'`);return r.target}let s=this.toRealPath(n);if(!s)throw new Error(`ENOENT: no such file or directory, readlink '${e}'`);try{return await B.promises.readlink(s)}catch(o){throw o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${e}'`):o.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${e}'`):o}}};import*as P from"node:fs";import*as ee from"node:path";var Et=class{root;constructor(e){if(this.root=ee.resolve(e.root),!P.existsSync(this.root))throw new Error(`ReadWriteFs root does not exist: ${this.root}`);if(!P.statSync(this.root).isDirectory())throw new Error(`ReadWriteFs root is not a directory: ${this.root}`)}toRealPath(e){let n=this.normalizePath(e),r=ee.join(this.root,n);return ee.resolve(r)}normalizePath(e){if(!e||e==="/")return"/";let n=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;n.startsWith("/")||(n=`/${n}`);let r=n.split("/").filter(o=>o&&o!=="."),s=[];for(let o of r)o===".."?s.pop():s.push(o);return`/${s.join("/")}`||"/"}async readFile(e,n){let r=await this.readFileBuffer(e),s=Z(n);return xe(r,s)}async readFileBuffer(e){let n=this.toRealPath(e);try{let r=await P.promises.readFile(n);return new Uint8Array(r)}catch(r){let s=r;throw s.code==="ENOENT"?new Error(`ENOENT: no such file or directory, open '${e}'`):s.code==="EISDIR"?new Error(`EISDIR: illegal operation on a directory, read '${e}'`):r}}async writeFile(e,n,r){let s=this.toRealPath(e),o=Z(r),i=re(n,o),a=ee.dirname(s);await P.promises.mkdir(a,{recursive:!0}),await P.promises.writeFile(s,i)}async appendFile(e,n,r){let s=this.toRealPath(e),o=Z(r),i=re(n,o),a=ee.dirname(s);await P.promises.mkdir(a,{recursive:!0}),await P.promises.appendFile(s,i)}async exists(e){let n=this.toRealPath(e);try{return await P.promises.access(n),!0}catch{return!1}}async stat(e){let n=this.toRealPath(e);try{let r=await P.promises.stat(n);return{isFile:r.isFile(),isDirectory:r.isDirectory(),isSymbolicLink:!1,mode:r.mode,size:r.size,mtime:r.mtime}}catch(r){throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, stat '${e}'`):r}}async lstat(e){let n=this.toRealPath(e);try{let r=await P.promises.lstat(n);return{isFile:r.isFile(),isDirectory:r.isDirectory(),isSymbolicLink:r.isSymbolicLink(),mode:r.mode,size:r.size,mtime:r.mtime}}catch(r){throw r.code==="ENOENT"?new Error(`ENOENT: no such file or directory, lstat '${e}'`):r}}async mkdir(e,n){let r=this.toRealPath(e);try{await P.promises.mkdir(r,{recursive:n?.recursive})}catch(s){let o=s;throw o.code==="EEXIST"?new Error(`EEXIST: file already exists, mkdir '${e}'`):o.code==="ENOENT"?new Error(`ENOENT: no such file or directory, mkdir '${e}'`):s}}async readdir(e){let n=this.toRealPath(e);try{return(await P.promises.readdir(n)).sort()}catch(r){let s=r;throw s.code==="ENOENT"?new Error(`ENOENT: no such file or directory, scandir '${e}'`):s.code==="ENOTDIR"?new Error(`ENOTDIR: not a directory, scandir '${e}'`):r}}async rm(e,n){let r=this.toRealPath(e);try{await P.promises.rm(r,{recursive:n?.recursive??!1,force:n?.force??!1})}catch(s){let o=s;throw o.code==="ENOENT"&&!n?.force?new Error(`ENOENT: no such file or directory, rm '${e}'`):o.code==="ENOTEMPTY"?new Error(`ENOTEMPTY: directory not empty, rm '${e}'`):s}}async cp(e,n,r){let s=this.toRealPath(e),o=this.toRealPath(n);try{await P.promises.cp(s,o,{recursive:r?.recursive??!1})}catch(i){let a=i;throw a.code==="ENOENT"?new Error(`ENOENT: no such file or directory, cp '${e}'`):a.code==="EISDIR"?new Error(`EISDIR: is a directory, cp '${e}'`):i}}async mv(e,n){let r=this.toRealPath(e),s=this.toRealPath(n),o=ee.dirname(s);await P.promises.mkdir(o,{recursive:!0});try{await P.promises.rename(r,s)}catch(i){let a=i;if(a.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, mv '${e}'`);if(a.code==="EXDEV"){await this.cp(e,n,{recursive:!0}),await this.rm(e,{recursive:!0});return}throw i}}resolvePath(e,n){if(n.startsWith("/"))return this.normalizePath(n);let r=e==="/"?`/${n}`:`${e}/${n}`;return this.normalizePath(r)}getAllPaths(){let e=[];return this.scanDir("/",e),e}scanDir(e,n){let r=this.toRealPath(e);try{let s=P.readdirSync(r);for(let o of s){let i=e==="/"?`/${o}`:`${e}/${o}`;n.push(i);let a=ee.join(r,o);P.statSync(a).isDirectory()&&this.scanDir(i,n)}}catch{}}async chmod(e,n){let r=this.toRealPath(e);try{await P.promises.chmod(r,n)}catch(s){throw s.code==="ENOENT"?new Error(`ENOENT: no such file or directory, chmod '${e}'`):s}}async symlink(e,n){let r=this.toRealPath(n);try{await P.promises.symlink(e,r)}catch(s){throw s.code==="EEXIST"?new Error(`EEXIST: file already exists, symlink '${n}'`):s}}async link(e,n){let r=this.toRealPath(e),s=this.toRealPath(n);try{await P.promises.link(r,s)}catch(o){let i=o;throw i.code==="ENOENT"?new Error(`ENOENT: no such file or directory, link '${e}'`):i.code==="EEXIST"?new Error(`EEXIST: file already exists, link '${n}'`):i.code==="EPERM"?new Error(`EPERM: operation not permitted, link '${e}'`):o}}async readlink(e){let n=this.toRealPath(e);try{return await P.promises.readlink(n)}catch(r){let s=r;throw s.code==="ENOENT"?new Error(`ENOENT: no such file or directory, readlink '${e}'`):s.code==="EINVAL"?new Error(`EINVAL: invalid argument, readlink '${e}'`):r}}};var Oe=class{cmdId;cwd;startedAt;exitCode;bashEnv;cmdLine;env;explicitCwd;resultPromise;constructor(e,n,r,s,o=!1){this.cmdId=crypto.randomUUID(),this.cwd=r,this.startedAt=new Date,this.bashEnv=e,this.cmdLine=n,this.env=s,this.explicitCwd=o,this.resultPromise=this.execute()}async execute(){let e=this.env||this.explicitCwd?{cwd:this.explicitCwd?this.cwd:void 0,env:this.env}:void 0,n=await this.bashEnv.exec(this.cmdLine,e);return this.exitCode=n.exitCode,n}async*logs(){let e=await this.resultPromise;e.stdout&&(yield{type:"stdout",data:e.stdout,timestamp:new Date}),e.stderr&&(yield{type:"stderr",data:e.stderr,timestamp:new Date})}async wait(){return await this.resultPromise,this}async output(){let e=await this.resultPromise;return e.stdout+e.stderr}async stdout(){return(await this.resultPromise).stdout}async stderr(){return(await this.resultPromise).stderr}async kill(){}};var wt=class t{bashEnv;constructor(e){this.bashEnv=e}static async create(e){let n=e?.fs;if(e?.overlayRoot){if(e?.fs)throw new Error("Cannot specify both 'fs' and 'overlayRoot' options");n=new De({root:e.overlayRoot})}let r=new ze({env:e?.env,cwd:e?.cwd,fs:n,maxCallDepth:e?.maxCallDepth,maxCommandCount:e?.maxCommandCount,maxLoopIterations:e?.maxLoopIterations,network:e?.network});return new t(r)}async runCommand(e,n){let r=n?.cwd??this.bashEnv.getCwd(),s=n?.cwd!==void 0;return new Oe(this.bashEnv,e,r,n?.env,s)}async writeFiles(e){for(let[n,r]of Object.entries(e)){let s;typeof r=="string"?s=r:r.encoding==="base64"?s=Buffer.from(r.content,"base64").toString("utf-8"):s=r.content;let o=n.substring(0,n.lastIndexOf("/"))||"/";o!=="/"&&await this.bashEnv.exec(`mkdir -p ${o}`),await this.bashEnv.writeFile(n,s)}}async readFile(e,n){let r=await this.bashEnv.readFile(e);return n==="base64"?Buffer.from(r).toString("base64"):r}async mkDir(e,n){let r=n?.recursive?"-p":"";await this.bashEnv.exec(`mkdir ${r} ${e}`)}async stop(){}async extendTimeout(e){}get domain(){}get bashEnvInstance(){return this.bashEnv}};export{ze as Bash,ne as InMemoryFs,ve as NetworkAccessDeniedError,De as OverlayFs,Et as ReadWriteFs,Re as RedirectNotAllowedError,wt as Sandbox,Oe as SandboxCommand,Ie as TooManyRedirectsError,Fn as defineCommand,Tn as getCommandNames,Wn as getNetworkCommandNames};
@@ -0,0 +1,201 @@
1
+ /**
2
+ * AWK Abstract Syntax Tree Types
3
+ *
4
+ * Follows the same discriminated union pattern as the main bash AST.
5
+ */
6
+ export type AwkExpr = AwkNumberLiteral | AwkStringLiteral | AwkRegexLiteral | AwkFieldRef | AwkVariable | AwkArrayAccess | AwkBinaryOp | AwkUnaryOp | AwkTernaryOp | AwkFunctionCall | AwkAssignment | AwkPreIncrement | AwkPreDecrement | AwkPostIncrement | AwkPostDecrement | AwkGetline | AwkInExpr | AwkTuple;
7
+ export interface AwkNumberLiteral {
8
+ type: "number";
9
+ value: number;
10
+ }
11
+ export interface AwkStringLiteral {
12
+ type: "string";
13
+ value: string;
14
+ }
15
+ export interface AwkRegexLiteral {
16
+ type: "regex";
17
+ pattern: string;
18
+ }
19
+ export interface AwkFieldRef {
20
+ type: "field";
21
+ index: AwkExpr;
22
+ }
23
+ export interface AwkVariable {
24
+ type: "variable";
25
+ name: string;
26
+ }
27
+ export interface AwkArrayAccess {
28
+ type: "array_access";
29
+ array: string;
30
+ key: AwkExpr;
31
+ }
32
+ export interface AwkBinaryOp {
33
+ type: "binary";
34
+ operator: "+" | "-" | "*" | "/" | "%" | "^" | "==" | "!=" | "<" | ">" | "<=" | ">=" | "~" | "!~" | "&&" | "||" | " ";
35
+ left: AwkExpr;
36
+ right: AwkExpr;
37
+ }
38
+ export interface AwkUnaryOp {
39
+ type: "unary";
40
+ operator: "!" | "-" | "+";
41
+ operand: AwkExpr;
42
+ }
43
+ export interface AwkPreIncrement {
44
+ type: "pre_increment";
45
+ operand: AwkVariable | AwkArrayAccess | AwkFieldRef;
46
+ }
47
+ export interface AwkPreDecrement {
48
+ type: "pre_decrement";
49
+ operand: AwkVariable | AwkArrayAccess | AwkFieldRef;
50
+ }
51
+ export interface AwkPostIncrement {
52
+ type: "post_increment";
53
+ operand: AwkVariable | AwkArrayAccess | AwkFieldRef;
54
+ }
55
+ export interface AwkPostDecrement {
56
+ type: "post_decrement";
57
+ operand: AwkVariable | AwkArrayAccess | AwkFieldRef;
58
+ }
59
+ export interface AwkTernaryOp {
60
+ type: "ternary";
61
+ condition: AwkExpr;
62
+ consequent: AwkExpr;
63
+ alternate: AwkExpr;
64
+ }
65
+ export interface AwkFunctionCall {
66
+ type: "call";
67
+ name: string;
68
+ args: AwkExpr[];
69
+ }
70
+ export interface AwkAssignment {
71
+ type: "assignment";
72
+ operator: "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "^=";
73
+ target: AwkFieldRef | AwkVariable | AwkArrayAccess;
74
+ value: AwkExpr;
75
+ }
76
+ export interface AwkInExpr {
77
+ type: "in";
78
+ key: AwkExpr;
79
+ array: string;
80
+ }
81
+ export interface AwkGetline {
82
+ type: "getline";
83
+ variable?: string;
84
+ file?: AwkExpr;
85
+ }
86
+ export interface AwkTuple {
87
+ type: "tuple";
88
+ elements: AwkExpr[];
89
+ }
90
+ export type AwkStmt = AwkExpressionStmt | AwkPrintStmt | AwkPrintfStmt | AwkIfStmt | AwkWhileStmt | AwkDoWhileStmt | AwkForStmt | AwkForInStmt | AwkBreakStmt | AwkContinueStmt | AwkNextStmt | AwkNextFileStmt | AwkExitStmt | AwkReturnStmt | AwkDeleteStmt | AwkBlock;
91
+ export interface AwkExpressionStmt {
92
+ type: "expr_stmt";
93
+ expression: AwkExpr;
94
+ }
95
+ export interface AwkPrintStmt {
96
+ type: "print";
97
+ args: AwkExpr[];
98
+ output?: {
99
+ redirect: ">" | ">>";
100
+ file: AwkExpr;
101
+ };
102
+ }
103
+ export interface AwkPrintfStmt {
104
+ type: "printf";
105
+ format: AwkExpr;
106
+ args: AwkExpr[];
107
+ output?: {
108
+ redirect: ">" | ">>";
109
+ file: AwkExpr;
110
+ };
111
+ }
112
+ export interface AwkIfStmt {
113
+ type: "if";
114
+ condition: AwkExpr;
115
+ consequent: AwkStmt;
116
+ alternate?: AwkStmt;
117
+ }
118
+ export interface AwkWhileStmt {
119
+ type: "while";
120
+ condition: AwkExpr;
121
+ body: AwkStmt;
122
+ }
123
+ export interface AwkDoWhileStmt {
124
+ type: "do_while";
125
+ body: AwkStmt;
126
+ condition: AwkExpr;
127
+ }
128
+ export interface AwkForStmt {
129
+ type: "for";
130
+ init?: AwkExpr;
131
+ condition?: AwkExpr;
132
+ update?: AwkExpr;
133
+ body: AwkStmt;
134
+ }
135
+ export interface AwkForInStmt {
136
+ type: "for_in";
137
+ variable: string;
138
+ array: string;
139
+ body: AwkStmt;
140
+ }
141
+ export interface AwkBlock {
142
+ type: "block";
143
+ statements: AwkStmt[];
144
+ }
145
+ export interface AwkBreakStmt {
146
+ type: "break";
147
+ }
148
+ export interface AwkContinueStmt {
149
+ type: "continue";
150
+ }
151
+ export interface AwkNextStmt {
152
+ type: "next";
153
+ }
154
+ export interface AwkNextFileStmt {
155
+ type: "nextfile";
156
+ }
157
+ export interface AwkExitStmt {
158
+ type: "exit";
159
+ code?: AwkExpr;
160
+ }
161
+ export interface AwkReturnStmt {
162
+ type: "return";
163
+ value?: AwkExpr;
164
+ }
165
+ export interface AwkDeleteStmt {
166
+ type: "delete";
167
+ target: AwkArrayAccess | AwkVariable;
168
+ }
169
+ export type AwkPattern = AwkBeginPattern | AwkEndPattern | AwkExprPattern | AwkRegexPattern | AwkRangePattern;
170
+ export interface AwkBeginPattern {
171
+ type: "begin";
172
+ }
173
+ export interface AwkEndPattern {
174
+ type: "end";
175
+ }
176
+ export interface AwkExprPattern {
177
+ type: "expr_pattern";
178
+ expression: AwkExpr;
179
+ }
180
+ export interface AwkRegexPattern {
181
+ type: "regex_pattern";
182
+ pattern: string;
183
+ }
184
+ export interface AwkRangePattern {
185
+ type: "range";
186
+ start: AwkPattern;
187
+ end: AwkPattern;
188
+ }
189
+ export interface AwkRule {
190
+ pattern?: AwkPattern;
191
+ action: AwkBlock;
192
+ }
193
+ export interface AwkFunctionDef {
194
+ name: string;
195
+ params: string[];
196
+ body: AwkBlock;
197
+ }
198
+ export interface AwkProgram {
199
+ functions: AwkFunctionDef[];
200
+ rules: AwkRule[];
201
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * AWK Command - New AST-based Implementation
3
+ *
4
+ * This is the new implementation using proper lexer/parser/interpreter architecture.
5
+ */
6
+ import type { Command } from "../../types.js";
7
+ export declare const awkCommand2: Command;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * AWK Built-in Functions
3
+ *
4
+ * Implementation of AWK built-in functions for the AST-based interpreter.
5
+ */
6
+ import type { AwkExpr } from "./ast.js";
7
+ import type { AwkRuntimeContext } from "./interpreter/context.js";
8
+ import type { AwkValue } from "./interpreter/types.js";
9
+ /**
10
+ * Interface for evaluating expressions (passed from interpreter)
11
+ */
12
+ export interface AwkEvaluator {
13
+ evalExpr: (expr: AwkExpr) => Promise<AwkValue>;
14
+ }
15
+ export type AwkBuiltinFn = (args: AwkExpr[], ctx: AwkRuntimeContext, evaluator: AwkEvaluator) => AwkValue | Promise<AwkValue>;
16
+ export declare function formatPrintf(format: string, values: AwkValue[]): string;
17
+ export declare const awkBuiltins: Record<string, AwkBuiltinFn>;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * AWK Runtime Context
3
+ *
4
+ * Holds all state for AWK program execution.
5
+ */
6
+ import type { AwkFunctionDef } from "../ast.js";
7
+ import type { AwkFileSystem, AwkValue } from "./types.js";
8
+ export interface AwkRuntimeContext {
9
+ FS: string;
10
+ OFS: string;
11
+ ORS: string;
12
+ NR: number;
13
+ NF: number;
14
+ FNR: number;
15
+ FILENAME: string;
16
+ RSTART: number;
17
+ RLENGTH: number;
18
+ SUBSEP: string;
19
+ fields: string[];
20
+ line: string;
21
+ vars: Record<string, AwkValue>;
22
+ arrays: Record<string, Record<string, AwkValue>>;
23
+ ARGC: number;
24
+ ARGV: Record<string, string>;
25
+ functions: Map<string, AwkFunctionDef>;
26
+ lines?: string[];
27
+ lineIndex?: number;
28
+ fieldSep: RegExp;
29
+ maxIterations: number;
30
+ maxRecursionDepth: number;
31
+ currentRecursionDepth: number;
32
+ exitCode: number;
33
+ shouldExit: boolean;
34
+ shouldNext: boolean;
35
+ shouldNextFile: boolean;
36
+ loopBreak: boolean;
37
+ loopContinue: boolean;
38
+ returnValue?: AwkValue;
39
+ hasReturn: boolean;
40
+ output: string;
41
+ fs?: AwkFileSystem;
42
+ cwd?: string;
43
+ openedFiles: Set<string>;
44
+ random?: () => number;
45
+ }
46
+ export interface CreateContextOptions {
47
+ fieldSep?: RegExp;
48
+ maxIterations?: number;
49
+ maxRecursionDepth?: number;
50
+ fs?: AwkFileSystem;
51
+ cwd?: string;
52
+ }
53
+ export declare function createRuntimeContext(options?: CreateContextOptions): AwkRuntimeContext;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * AWK Expression Evaluation
3
+ *
4
+ * Async expression evaluator supporting file I/O operations.
5
+ */
6
+ import type { AwkExpr } from "../ast.js";
7
+ import type { AwkRuntimeContext } from "./context.js";
8
+ import type { AwkValue } from "./types.js";
9
+ export type BlockExecutor = (ctx: AwkRuntimeContext, statements: import("../ast.js").AwkStmt[]) => Promise<void>;
10
+ /**
11
+ * Set the block executor function (called from statements.ts to avoid circular deps)
12
+ */
13
+ export declare function setBlockExecutor(fn: BlockExecutor): void;
14
+ /**
15
+ * Evaluate an AWK expression asynchronously.
16
+ */
17
+ export declare function evalExpr(ctx: AwkRuntimeContext, expr: AwkExpr): Promise<AwkValue>;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * AWK Field Operations
3
+ *
4
+ * Handles $0, $1, $2, etc. field access and modification.
5
+ */
6
+ import type { AwkRuntimeContext } from "./context.js";
7
+ import type { AwkValue } from "./types.js";
8
+ /**
9
+ * Get a field value by index.
10
+ * $0 is the whole line, $1 is first field, etc.
11
+ */
12
+ export declare function getField(ctx: AwkRuntimeContext, index: number): AwkValue;
13
+ /**
14
+ * Set a field value by index.
15
+ * Setting $0 re-splits the line. Setting other fields rebuilds $0.
16
+ */
17
+ export declare function setField(ctx: AwkRuntimeContext, index: number, value: AwkValue): void;
18
+ /**
19
+ * Update context with a new line (used when processing input).
20
+ */
21
+ export declare function setCurrentLine(ctx: AwkRuntimeContext, line: string): void;
22
+ /**
23
+ * Update field separator and recompile regex.
24
+ */
25
+ export declare function setFieldSeparator(ctx: AwkRuntimeContext, fs: string): void;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * AWK Type Conversion Helpers
3
+ *
4
+ * Pure functions for type conversion and truthiness checking.
5
+ */
6
+ import type { AwkValue } from "./types.js";
7
+ /**
8
+ * Check if a value is truthy in AWK.
9
+ * Numbers are truthy if non-zero, strings if non-empty.
10
+ */
11
+ export declare function isTruthy(val: AwkValue): boolean;
12
+ /**
13
+ * Convert an AWK value to a number.
14
+ * Strings are parsed as floats, empty/non-numeric strings become 0.
15
+ */
16
+ export declare function toNumber(val: AwkValue): number;
17
+ /**
18
+ * Convert an AWK value to a string.
19
+ * Numbers are formatted without trailing zeros.
20
+ */
21
+ export declare function toAwkString(val: AwkValue): string;
22
+ /**
23
+ * Check if a value looks like a number for comparison purposes.
24
+ */
25
+ export declare function looksLikeNumber(val: AwkValue): boolean;
26
+ /**
27
+ * Test if a string matches a regex pattern.
28
+ */
29
+ export declare function matchRegex(pattern: string, text: string): boolean;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * AWK Interpreter Module
3
+ *
4
+ * Re-exports the public API for the AWK interpreter.
5
+ */
6
+ export { type AwkRuntimeContext, type CreateContextOptions, createRuntimeContext, } from "./context.js";
7
+ export { AwkInterpreter } from "./interpreter.js";
8
+ export type { AwkFileSystem, AwkValue } from "./types.js";