just-bash 2.14.0 → 2.15.0-executor.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 (36) hide show
  1. package/dist/Bash.d.ts +86 -0
  2. package/dist/bin/chunks/chunk-MNMRGJJM.js +11 -0
  3. package/dist/bin/chunks/{js-exec-BDQGEAU6.js → js-exec-6UJKEL4G.js} +9 -9
  4. package/dist/bin/chunks/js-exec-worker.js +233 -1
  5. package/dist/bin/chunks/{python3-VCIXXAXF.js → python3-QOJU2POC.js} +1 -1
  6. package/dist/bin/chunks/worker.js +15 -1
  7. package/dist/bin/just-bash.js +236 -236
  8. package/dist/bin/shell/chunks/chunk-MNMRGJJM.js +11 -0
  9. package/dist/bin/shell/chunks/{js-exec-HPXZV7UJ.js → js-exec-H26D5H6V.js} +9 -9
  10. package/dist/bin/shell/chunks/{python3-KFZH67GD.js → python3-O4VTP6TD.js} +1 -1
  11. package/dist/bin/shell/shell.js +101 -101
  12. package/dist/bundle/browser.js +6 -6
  13. package/dist/bundle/chunks/chunk-B6O2PIY4.js +10 -0
  14. package/dist/bundle/chunks/{js-exec-4CW5N6RM.js → js-exec-OOPTBRNB.js} +9 -9
  15. package/dist/bundle/chunks/js-exec-worker.js +233 -1
  16. package/dist/bundle/chunks/{python3-SG3DOKBZ.js → python3-5F2XPEW4.js} +1 -1
  17. package/dist/bundle/chunks/worker.js +15 -1
  18. package/dist/bundle/index.cjs +663 -663
  19. package/dist/bundle/index.js +7 -7
  20. package/dist/commands/js-exec/executor-adapter.d.ts +66 -0
  21. package/dist/commands/js-exec/js-exec.d.ts +19 -1
  22. package/dist/commands/js-exec/worker.d.ts +8 -0
  23. package/dist/commands/worker-bridge/bridge-handler.d.ts +3 -1
  24. package/dist/commands/worker-bridge/protocol.d.ts +1 -0
  25. package/dist/commands/worker-bridge/sync-backend.d.ts +5 -0
  26. package/dist/executor-init.d.ts +10 -0
  27. package/dist/interpreter/interpreter.d.ts +2 -0
  28. package/dist/interpreter/types.d.ts +5 -0
  29. package/dist/types.d.ts +6 -0
  30. package/package.json +37 -34
  31. package/vendor/cpython-emscripten/python.wasm +0 -0
  32. package/vendor/executor/executor-sdk-bundle.d.mts +18 -0
  33. package/vendor/executor/executor-sdk-bundle.mjs +972 -0
  34. package/dist/bin/chunks/chunk-3KAVXQP4.js +0 -11
  35. package/dist/bin/shell/chunks/chunk-3KAVXQP4.js +0 -11
  36. package/dist/bundle/chunks/chunk-S4EYC6T6.js +0 -10
@@ -1,4 +1,4 @@
1
- import{B as Xr,C as Yr,D as fe,E as Xe,F as se,G as Ae,H as Ut,I as Qr,J as L,K as Jr,L as en,M as Ce,N as Rs,O as Ht,P as H,a as Br,b as Cs,c as jr,d as Bt,e as ee,f as B,g as ue,h as ne,i as _e,j as je,k as Ns,l as jt,m as Ur,n as Os,o as Hr,p as ve,q as Re,r as Zr,s as qr,t as xs,u as Ts,v as Ue,w as Gr,x as Kr,y as Se,z as Ds}from"./chunks/chunk-FEIOJCZD.js";import{a as x,b as R,c as rt,d as Be,e as Ke,f as nt,g as De,h as Mt,i as Wt,j as zt,k as Vr,l as Vt}from"./chunks/chunk-XHM67O4N.js";import{c as _s}from"./chunks/chunk-CWQS3NFK.js";import{a as Tt,b as Dt}from"./chunks/chunk-A5O5YHGN.js";import{a as ks}from"./chunks/chunk-IPJHKYVM.js";import{a as Ve,b as we,c as Et}from"./chunks/chunk-OJDRYQWQ.js";import{a as bt,b as zr}from"./chunks/chunk-24IMIIXA.js";import{a as Me,b as pe}from"./chunks/chunk-5QMZ5MUS.js";import{a as vt}from"./chunks/chunk-YNYSPYQ5.js";import{a as me,b as ye,c as ce,d as ge,e as Mr,f as j,g as Ge,h as Rt,i as It,j as Wr,k as J,l as Lt,m as We,n as Ft,o as $e}from"./chunks/chunk-GFQRA5P5.js";import"./chunks/chunk-NUFRM6SI.js";import{a as ze}from"./chunks/chunk-3THT3N7L.js";import{a as Te}from"./chunks/chunk-44UOCSGV.js";import"./chunks/chunk-DXB73IDG.js";var Ye=[{name:"echo",load:async()=>(await import("./chunks/echo-O45JWWI2.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-RDUMLXKC.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-CX64KX2P.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-KSXFZCWH.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-TDEMSB6C.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-XTQXT7RK.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-DX2IJOQ4.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-RTZG23RL.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-XOYR4ABJ.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-Z6MORUFL.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-4TRFBYAT.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-SYMGL4JA.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-D4OZ7N27.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-MI4GCHJF.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-HT2B6D2J.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-S5ULNTJU.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-TQB3VNOX.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-BT5A227F.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-3AIAIJVR.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-3AIAIJVR.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-3AIAIJVR.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-FOQSCCX3.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-VFTTATXJ.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-POPGKRAI.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-DCNRDA7U.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-SUNANL47.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-5SLSESQG.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-OPC3VAGB.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-7N6AFSDS.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-2HXZRDSW.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-XOSYPP45.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-U5YJDM32.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-LDSORVYE.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-DTNXU4LQ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-RGTMIGZM.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-7PLOGTPD.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-SITCSYCZ.js")).split},{name:"column",load:async()=>(await import("./chunks/column-WLPMMSTS.js")).column},{name:"join",load:async()=>(await import("./chunks/join-GG2LDHE5.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-O7VXZDCO.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-TPUOAIUQ.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-AA2KJYZQ.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-LEMTZZFS.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-LYXBS7DC.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-WO2ENHXQ.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-5EPCWSXR.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-5EPCWSXR.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-JE7RI5QX.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-JE7RI5QX.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-J4QRNGRO.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-I6EZUCYF.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-WHJNXCHG.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-WHJNXCHG.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-5CZ5X4YR.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-IJWYRKFO.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-IJWYRKFO.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-ODXZBPLY.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-4YMZCVJ5.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-HJF2MPDN.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-DD7FVA2V.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-VZFPZFWA.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-VRKMCG72.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-DEUO3QV2.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-RN5ZUASB.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-5T3UU5KE.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-INMIK4DX.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-VJPNLNU6.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-PI32XWXY.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-ZIGAJ4YS.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-TFCECAGV.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-VVWX7SA5.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-XZHEH76L.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-SJGXQ4T2.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-BK6HG2DE.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-DGKU3D2X.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-VJEF2UR5.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-AQXSGOVS.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-AQXSGOVS.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-AQXSGOVS.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ye.push({name:"tar",load:async()=>(await import("./chunks/tar-232RCEFK.js")).tarCommand}),Ye.push({name:"yq",load:async()=>(await import("./chunks/yq-MJMAR36V.js")).yqCommand}),Ye.push({name:"xan",load:async()=>(await import("./chunks/xan-BXDXYEIB.js")).xanCommand}),Ye.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-56UMWEY3.js")).sqlite3Command}));var Zt=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Zt.push({name:"python3",load:async()=>(await import("./chunks/python3-SG3DOKBZ.js")).python3Command}),Zt.push({name:"python",load:async()=>(await import("./chunks/python3-SG3DOKBZ.js")).pythonCommand}));var qt=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(qt.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-4CW5N6RM.js")).jsExecCommand}),qt.push({name:"node",load:async()=>(await import("./chunks/js-exec-4CW5N6RM.js")).nodeStubCommand}));var sn=[{name:"curl",load:async()=>(await import("./chunks/curl-COE4TZE6.js")).curlCommand}],tn=new Map;function Gt(e){return{name:e.name,async execute(t,s){let r=tn.get(e.name);if(r||(r=await pe.runTrustedAsync(()=>e.load()),tn.set(e.name,r)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:n}=await import("./chunks/flag-coverage-LMTH7T5F.js");n(s.coverage,e.name,t)}return r.execute(t,s)}}}function qi(){return Ye.map(e=>e.name)}function Gi(){return sn.map(e=>e.name)}function rn(e){return(e?Ye.filter(s=>e.includes(s.name)):Ye).map(Gt)}function nn(){return sn.map(Gt)}function Ki(){return Zt.map(e=>e.name)}function on(){return Zt.map(Gt)}function Xi(){return qt.map(e=>e.name)}function an(){return qt.map(Gt)}function ln(e){return"load"in e&&typeof e.load=="function"}function Yi(e,t){return{name:e,trusted:!0,execute:t}}function cn(e){let t=null;return{name:e.name,trusted:!0,async execute(s,r){return t||(t=await e.load()),t.execute(s,r)}}}var Qi=new TextEncoder,Ji=new TextDecoder;function Ie(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let r=0;r<e.length;r+=2)s[r/2]=parseInt(e.slice(r,r+2),16);return s}if(t==="binary"||t==="latin1"){if(e.length<=65536)return Uint8Array.from(e,n=>n.charCodeAt(0));let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r}return Qi.encode(e)}function it(e,t){if(t==="base64"){if(typeof Buffer<"u")return Buffer.from(e).toString("base64");let s=65536,r="";for(let n=0;n<e.length;n+=s){let i=e.subarray(n,n+s);r+=String.fromCharCode(...i)}return btoa(r)}if(t==="hex")return Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join("");if(t==="binary"||t==="latin1"){if(typeof Buffer<"u")return Buffer.from(e).toString(t);let s=65536;if(e.length<=s)return String.fromCharCode(...e);let r="";for(let n=0;n<e.length;n+=s){let i=e.subarray(n,n+s);r+=String.fromCharCode(...i)}return r}return Ji.decode(e)}function be(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var ot=new TextEncoder;function eo(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Le=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,r]of Object.entries(t))typeof r=="function"?this.writeFileLazy(s,r):eo(r)?this.writeFileSync(s,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(s,r)}ensureParentDirs(t){let s=rt(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,r,n){R(t,"write");let i=x(t);this.ensureParentDirs(i);let o=be(r),a=Ie(s,o);this.data.set(i,{type:"file",content:a,mode:n?.mode??420,mtime:n?.mtime??new Date})}writeFileLazy(t,s,r){R(t,"write");let n=x(t);this.ensureParentDirs(n),this.data.set(n,{type:"file",lazy:s,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,s){let r=await s.lazy(),i={type:"file",content:typeof r=="string"?ot.encode(r):r,mode:s.mode,mtime:s.mtime};return this.data.set(t,i),i}async readFile(t,s){let r=await this.readFileBuffer(t),n=be(s);return it(r,n)}async readFileBuffer(t){R(t,"open");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in r){let n=await this.materializeLazy(s,r);return n.content instanceof Uint8Array?n.content:ot.encode(n.content)}return r.content instanceof Uint8Array?r.content:ot.encode(r.content)}async writeFile(t,s,r){this.writeFileSync(t,s,r)}async appendFile(t,s,r){R(t,"append");let n=x(t),i=this.data.get(n);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=be(r),a=Ie(s,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(n,l));let c="content"in l&&l.content instanceof Uint8Array?l.content:ot.encode("content"in l?l.content:""),u=new Uint8Array(c.length+a.length);u.set(c),u.set(a,c.length),this.data.set(n,{type:"file",content:u,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,s,r)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){R(t,"stat");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=ot.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}async lstat(t){R(t,"lstat");let s=this.resolveIntermediateSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=ot.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}resolveIntermediateSymlinks(t){let s=x(t);if(s==="/")return"/";let r=s.slice(1).split("/");if(r.length<=1)return s;let n="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];n=`${n}/${a}`;let l=this.data.get(n),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(n),n=nt(n,l.target),l=this.data.get(n),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${n}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let s=x(t);if(s==="/")return"/";let r=s.slice(1).split("/"),n="",i=new Set;for(let o of r){n=`${n}/${o}`;let a=this.data.get(n),l=0,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(n),n=nt(n,a.target),a=this.data.get(n),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return n}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){R(t,"mkdir");let r=x(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let n=rt(r);if(n!=="/"&&!this.data.has(n))if(s?.recursive)this.mkdirSync(n,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){R(t,"scandir");let s=x(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Set;for(;r&&r.type==="symlink";){if(n.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);n.add(s),s=nt(s,r.target),r=this.data.get(s)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==s&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,s){R(t,"rm");let r=x(t),n=this.data.get(r);if(!n){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(n.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=Ke(r,o);await this.rm(a,s)}}}this.data.delete(r)}async cp(t,s,r){R(t,"cp"),R(s,"cp");let n=x(t),i=x(s),o=this.data.get(n);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")if(this.ensureParentDirs(i),"content"in o){let a=o.content instanceof Uint8Array?new Uint8Array(o.content):o.content;this.data.set(i,{...o,content:a})}else this.data.set(i,{...o});else if(o.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(n);for(let l of a){let c=Ke(n,l),u=Ke(i,l);await this.cp(c,u,r)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){return Be(t,s)}async chmod(t,s){R(t,"chmod");let r=x(t),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);n.mode=s}async symlink(t,s){R(s,"symlink");let r=x(s);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){R(t,"link"),R(s,"link");let r=x(t),n=x(s),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(n))throw new Error(`EEXIST: file already exists, link '${s}'`);let o=i;"lazy"in o&&(o=await this.materializeLazy(r,o)),this.ensureParentDirs(n),this.data.set(n,{type:"file",content:o.content,mode:o.mode,mtime:o.mtime})}async readlink(t){R(t,"readlink");let s=x(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){R(t,"realpath");let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,r){R(t,"utimes");let n=x(t),i=this.resolvePathWithSymlinks(n),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=r}};function to(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function so(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function ro(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function no(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Br}
1
+ import{B as Xr,C as Yr,D as fe,E as Xe,F as se,G as Ae,H as Ut,I as Qr,J as L,K as Jr,L as en,M as Ce,N as Rs,O as Ht,P as H,a as Br,b as Cs,c as jr,d as Bt,e as ee,f as B,g as ue,h as ne,i as _e,j as je,k as Ns,l as jt,m as Ur,n as Os,o as Hr,p as ve,q as Re,r as Zr,s as qr,t as xs,u as Ts,v as Ue,w as Gr,x as Kr,y as Se,z as Ds}from"./chunks/chunk-FEIOJCZD.js";import{a as x,b as R,c as rt,d as Be,e as Ke,f as nt,g as De,h as Mt,i as Wt,j as zt,k as Vr,l as Vt}from"./chunks/chunk-XHM67O4N.js";import{c as _s}from"./chunks/chunk-CWQS3NFK.js";import{a as Tt,b as Dt}from"./chunks/chunk-A5O5YHGN.js";import{a as ks}from"./chunks/chunk-IPJHKYVM.js";import{a as Ve,b as we,c as Et}from"./chunks/chunk-OJDRYQWQ.js";import{a as bt,b as zr}from"./chunks/chunk-24IMIIXA.js";import{a as Me,b as pe}from"./chunks/chunk-5QMZ5MUS.js";import{a as vt}from"./chunks/chunk-YNYSPYQ5.js";import{a as me,b as ye,c as ce,d as ge,e as Mr,f as j,g as Ge,h as Rt,i as It,j as Wr,k as J,l as Lt,m as We,n as Ft,o as $e}from"./chunks/chunk-GFQRA5P5.js";import"./chunks/chunk-NUFRM6SI.js";import{a as ze}from"./chunks/chunk-3THT3N7L.js";import{a as Te}from"./chunks/chunk-44UOCSGV.js";import"./chunks/chunk-DXB73IDG.js";var Ye=[{name:"echo",load:async()=>(await import("./chunks/echo-O45JWWI2.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-RDUMLXKC.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-CX64KX2P.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-KSXFZCWH.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-TDEMSB6C.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-XTQXT7RK.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-DX2IJOQ4.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-RTZG23RL.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-XOYR4ABJ.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-Z6MORUFL.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-4TRFBYAT.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-SYMGL4JA.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-D4OZ7N27.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-MI4GCHJF.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-HT2B6D2J.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-S5ULNTJU.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-TQB3VNOX.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-BT5A227F.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-3AIAIJVR.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-3AIAIJVR.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-3AIAIJVR.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-FOQSCCX3.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-VFTTATXJ.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-POPGKRAI.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-DCNRDA7U.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-SUNANL47.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-5SLSESQG.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-OPC3VAGB.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-7N6AFSDS.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-2HXZRDSW.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-XOSYPP45.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-U5YJDM32.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-LDSORVYE.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-DTNXU4LQ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-RGTMIGZM.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-7PLOGTPD.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-SITCSYCZ.js")).split},{name:"column",load:async()=>(await import("./chunks/column-WLPMMSTS.js")).column},{name:"join",load:async()=>(await import("./chunks/join-GG2LDHE5.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-O7VXZDCO.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-TPUOAIUQ.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-AA2KJYZQ.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-LEMTZZFS.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-LYXBS7DC.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-WO2ENHXQ.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-5EPCWSXR.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-5EPCWSXR.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-JE7RI5QX.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-JE7RI5QX.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-J4QRNGRO.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-I6EZUCYF.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-WHJNXCHG.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-WHJNXCHG.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-5CZ5X4YR.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-IJWYRKFO.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-IJWYRKFO.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-ODXZBPLY.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-4YMZCVJ5.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-HJF2MPDN.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-DD7FVA2V.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-VZFPZFWA.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-VRKMCG72.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-DEUO3QV2.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-RN5ZUASB.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-5T3UU5KE.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-INMIK4DX.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-VJPNLNU6.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-PI32XWXY.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-ZIGAJ4YS.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-TFCECAGV.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-VVWX7SA5.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-XZHEH76L.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-SJGXQ4T2.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-BK6HG2DE.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-DGKU3D2X.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-VJEF2UR5.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-AQXSGOVS.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-AQXSGOVS.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-AQXSGOVS.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ye.push({name:"tar",load:async()=>(await import("./chunks/tar-232RCEFK.js")).tarCommand}),Ye.push({name:"yq",load:async()=>(await import("./chunks/yq-MJMAR36V.js")).yqCommand}),Ye.push({name:"xan",load:async()=>(await import("./chunks/xan-BXDXYEIB.js")).xanCommand}),Ye.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-56UMWEY3.js")).sqlite3Command}));var Zt=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Zt.push({name:"python3",load:async()=>(await import("./chunks/python3-5F2XPEW4.js")).python3Command}),Zt.push({name:"python",load:async()=>(await import("./chunks/python3-5F2XPEW4.js")).pythonCommand}));var qt=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(qt.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-OOPTBRNB.js")).jsExecCommand}),qt.push({name:"node",load:async()=>(await import("./chunks/js-exec-OOPTBRNB.js")).nodeStubCommand}));var sn=[{name:"curl",load:async()=>(await import("./chunks/curl-COE4TZE6.js")).curlCommand}],tn=new Map;function Gt(e){return{name:e.name,async execute(t,s){let r=tn.get(e.name);if(r||(r=await pe.runTrustedAsync(()=>e.load()),tn.set(e.name,r)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:n}=await import("./chunks/flag-coverage-LMTH7T5F.js");n(s.coverage,e.name,t)}return r.execute(t,s)}}}function qi(){return Ye.map(e=>e.name)}function Gi(){return sn.map(e=>e.name)}function rn(e){return(e?Ye.filter(s=>e.includes(s.name)):Ye).map(Gt)}function nn(){return sn.map(Gt)}function Ki(){return Zt.map(e=>e.name)}function on(){return Zt.map(Gt)}function Xi(){return qt.map(e=>e.name)}function an(){return qt.map(Gt)}function ln(e){return"load"in e&&typeof e.load=="function"}function Yi(e,t){return{name:e,trusted:!0,execute:t}}function cn(e){let t=null;return{name:e.name,trusted:!0,async execute(s,r){return t||(t=await e.load()),t.execute(s,r)}}}var Qi=new TextEncoder,Ji=new TextDecoder;function Ie(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let r=0;r<e.length;r+=2)s[r/2]=parseInt(e.slice(r,r+2),16);return s}if(t==="binary"||t==="latin1"){if(e.length<=65536)return Uint8Array.from(e,n=>n.charCodeAt(0));let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r}return Qi.encode(e)}function it(e,t){if(t==="base64"){if(typeof Buffer<"u")return Buffer.from(e).toString("base64");let s=65536,r="";for(let n=0;n<e.length;n+=s){let i=e.subarray(n,n+s);r+=String.fromCharCode(...i)}return btoa(r)}if(t==="hex")return Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join("");if(t==="binary"||t==="latin1"){if(typeof Buffer<"u")return Buffer.from(e).toString(t);let s=65536;if(e.length<=s)return String.fromCharCode(...e);let r="";for(let n=0;n<e.length;n+=s){let i=e.subarray(n,n+s);r+=String.fromCharCode(...i)}return r}return Ji.decode(e)}function be(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var ot=new TextEncoder;function eo(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Le=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,r]of Object.entries(t))typeof r=="function"?this.writeFileLazy(s,r):eo(r)?this.writeFileSync(s,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(s,r)}ensureParentDirs(t){let s=rt(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,r,n){R(t,"write");let i=x(t);this.ensureParentDirs(i);let o=be(r),a=Ie(s,o);this.data.set(i,{type:"file",content:a,mode:n?.mode??420,mtime:n?.mtime??new Date})}writeFileLazy(t,s,r){R(t,"write");let n=x(t);this.ensureParentDirs(n),this.data.set(n,{type:"file",lazy:s,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,s){let r=await s.lazy(),i={type:"file",content:typeof r=="string"?ot.encode(r):r,mode:s.mode,mtime:s.mtime};return this.data.set(t,i),i}async readFile(t,s){let r=await this.readFileBuffer(t),n=be(s);return it(r,n)}async readFileBuffer(t){R(t,"open");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in r){let n=await this.materializeLazy(s,r);return n.content instanceof Uint8Array?n.content:ot.encode(n.content)}return r.content instanceof Uint8Array?r.content:ot.encode(r.content)}async writeFile(t,s,r){this.writeFileSync(t,s,r)}async appendFile(t,s,r){R(t,"append");let n=x(t),i=this.data.get(n);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=be(r),a=Ie(s,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(n,l));let c="content"in l&&l.content instanceof Uint8Array?l.content:ot.encode("content"in l?l.content:""),u=new Uint8Array(c.length+a.length);u.set(c),u.set(a,c.length),this.data.set(n,{type:"file",content:u,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,s,r)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){R(t,"stat");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=ot.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}async lstat(t){R(t,"lstat");let s=this.resolveIntermediateSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=ot.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}resolveIntermediateSymlinks(t){let s=x(t);if(s==="/")return"/";let r=s.slice(1).split("/");if(r.length<=1)return s;let n="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];n=`${n}/${a}`;let l=this.data.get(n),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(n),n=nt(n,l.target),l=this.data.get(n),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${n}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let s=x(t);if(s==="/")return"/";let r=s.slice(1).split("/"),n="",i=new Set;for(let o of r){n=`${n}/${o}`;let a=this.data.get(n),l=0,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(n),n=nt(n,a.target),a=this.data.get(n),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return n}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){R(t,"mkdir");let r=x(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let n=rt(r);if(n!=="/"&&!this.data.has(n))if(s?.recursive)this.mkdirSync(n,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){R(t,"scandir");let s=x(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Set;for(;r&&r.type==="symlink";){if(n.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);n.add(s),s=nt(s,r.target),r=this.data.get(s)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==s&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,s){R(t,"rm");let r=x(t),n=this.data.get(r);if(!n){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(n.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=Ke(r,o);await this.rm(a,s)}}}this.data.delete(r)}async cp(t,s,r){R(t,"cp"),R(s,"cp");let n=x(t),i=x(s),o=this.data.get(n);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")if(this.ensureParentDirs(i),"content"in o){let a=o.content instanceof Uint8Array?new Uint8Array(o.content):o.content;this.data.set(i,{...o,content:a})}else this.data.set(i,{...o});else if(o.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(n);for(let l of a){let c=Ke(n,l),u=Ke(i,l);await this.cp(c,u,r)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){return Be(t,s)}async chmod(t,s){R(t,"chmod");let r=x(t),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);n.mode=s}async symlink(t,s){R(s,"symlink");let r=x(s);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){R(t,"link"),R(s,"link");let r=x(t),n=x(s),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(n))throw new Error(`EEXIST: file already exists, link '${s}'`);let o=i;"lazy"in o&&(o=await this.materializeLazy(r,o)),this.ensureParentDirs(n),this.data.set(n,{type:"file",content:o.content,mode:o.mode,mtime:o.mtime})}async readlink(t){R(t,"readlink");let s=x(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){R(t,"realpath");let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,r){R(t,"utimes");let n=x(t),i=this.resolvePathWithSymlinks(n),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=r}};function to(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function so(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function ro(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function no(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Br}
2
2
  `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
3
3
  `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>Cs(t)):e.writeFileSync("/proc/self/status",Cs(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function un(e,t,s={pid:1,ppid:0,uid:1e3,gid:1e3}){to(e)&&(so(e,t),ro(e),no(e,s))}var io=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],oo=["braceexpand","hashall","interactive-comments"];function Ls(e){let t=[],s=[...oo.map(r=>({name:r,enabled:!0})),...io.map(r=>({name:r,enabled:e[r]}))].sort((r,n)=>r.name.localeCompare(n.name));for(let r of s)r.enabled&&t.push(r.name);return t.join(":")}function lt(e){e.state.env.set("SHELLOPTS",Ls(e.state.options))}var ao=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Fs(e){let t=[];for(let s of ao)e[s]&&t.push(s);return t.join(":")}function Ms(e){e.state.env.set("BASHOPTS",Fs(e.state.shoptOptions))}var lo="BASH_ALIAS_";function fn(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function dn(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function hn(e,t){return e.env.get(`${lo}${t}`)}function Ws(e,t,s){if(!t.name||!fn(t.name))return t;let r=dn(t.name);if(!r)return t;let n=hn(e,r);if(!n||s.has(r))return t;try{s.add(r);let i=new B,o=n,a=n.endsWith(" ");if(!a)for(let f of t.args){let d=mn(f);o+=` ${d}`}let l;try{l=i.parse(o)}catch(f){if(f instanceof Bt)throw f;return t}if(l.statements.length!==1||l.statements[0].pipelines.length!==1||l.statements[0].pipelines[0].commands.length!==1)return pn(t,n);let c=l.statements[0].pipelines[0].commands[0];if(c.type!=="SimpleCommand")return pn(t,n);let u={...c,assignments:[...t.assignments,...c.assignments],redirections:[...c.redirections,...t.redirections],line:t.line};if(a&&t.args.length>0&&(u={...u,args:[...u.args,...t.args]},u.args.length>0)){let f=u.args[0];if(fn(f)){let d=dn(f);if(d&&hn(e,d)){let p={type:"SimpleCommand",name:f,args:u.args.slice(1),assignments:[],redirections:[]},m=Ws(e,p,s);m!==p&&(u={...u,name:m.name,args:[...m.args]})}}}return u}catch(i){throw s.delete(r),i}}function pn(e,t){let s=t;for(let o of e.args){let a=mn(o);s+=` ${a}`}let r=new B,n=r.parseWordFromString("eval",!1,!1),i=r.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:n,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function mn(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${s.value}'`;break;case"DoubleQuoted":t+=`"${s.parts.map(r=>r.type==="Literal"?r.value:`$${r.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${s.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${s.expression}))`;break;case"Glob":t+=s.pattern;break;default:break}return t}async function yn(e,t){let s=t.parts.map(u=>u.type==="Literal"?u.value:"\0").join(""),r=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!r||!s.endsWith(")"))return null;let n=r[1],i=[],o=!1,a="",l=!1;for(let u of t.parts)if(u.type==="Literal"){let f=u.value;if(!o){let d=f.indexOf("=(");d!==-1&&(o=!0,f=f.slice(d+2))}if(o){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let p of d)/^\s+$/.test(p)?(a||l)&&(i.push(a),a="",l=!1):p&&(a+=p)}}else if(o)if(u.type==="BraceExpansion")if(/^\[.+\]=/.test(a))a+=jt({type:"Word",parts:[u]});else{(a||l)&&(i.push(a),a="",l=!1);let d=await Ce(e,{type:"Word",parts:[u]});i.push(...d.values)}else{(u.type==="SingleQuoted"||u.type==="DoubleQuoted"||u.type==="Escaped")&&(l=!0);let f=await L(e,{type:"Word",parts:[u]});a+=f}(a||l)&&i.push(a);let c=i.map(u=>/^\[.+\]=/.test(u)?u:u===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(u)&&!u.startsWith("'")&&!u.startsWith('"')?`'${u.replace(/'/g,"'\\''")}'`:u);return`${n}=(${c.join(" ")})`}async function gn(e,t){let s=-1,r=-1,n=!1;for(let h=0;h<t.parts.length;h++){let y=t.parts[h];if(y.type==="Literal"){let b=y.value.indexOf("+=");if(b!==-1){let A=y.value.slice(0,b);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(A)){s=h,r=b,n=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(A)){s=h,r=b,n=!0;break}}let v=y.value.indexOf("=");if(v!==-1&&(v===0||y.value[v-1]!=="+")){let A=y.value.slice(0,v);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(A)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(A)){s=h,r=v;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),o=t.parts[s];if(o.type!=="Literal")return null;let a=n?2:1,l=o.value.slice(0,r),c=o.value.slice(r+a),u=t.parts.slice(s+1),f="";for(let h of i)f+=await L(e,{type:"Word",parts:[h]});f+=l;let d={type:"Word",parts:c!==""?[{type:"Literal",value:c},...u]:u},p=d.parts.length>0?await L(e,d):"";return`${f}${n?"+=":"="}${p}`}var co=["tar","yq","xan","sqlite3","python3","python"];function wn(e){return co.includes(e)}var W=Object.freeze({stdout:"",stderr:"",exitCode:0});function z(e=""){return{stdout:e,stderr:"",exitCode:0}}function P(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function _(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function Q(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function Ne(e,t,s="",r=""){throw new J(e,t,s,r)}function le(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new J(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function zs(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new We;return W}if(t.length>1)throw new j(1,"",`bash: break: too many arguments
4
4
  `);let s=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new j(128,"",`bash: break: ${t[0]}: numeric argument required
@@ -620,7 +620,7 @@ ${e} ()
620
620
  `,127):P(`bash: ${t}: command not found
621
621
  `,127);if("error"in c)return c.error==="permission_denied"?P(`bash: ${t}: Permission denied
622
622
  `,126):P(`bash: ${t}: No such file or directory
623
- `,127);if("script"in c)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,c.path)),await a(c.path,s,r);let{cmd:u,path:f}=c;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",p=o(),m={fs:i.fs,cwd:i.state.cwd,env:i.state.env,exportedEnv:p,stdin:d,limits:i.limits,exec:i.execFn,fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo,coverage:i.coverage,signal:i.state.signal,requireDefenseContext:i.requireDefenseContext,jsBootstrapCode:i.jsBootstrapCode},h=ri(m,t);try{let y=()=>zr(i.requireDefenseContext,"command",`${t} execution`,()=>u.execute(s,h));return u.trusted?await pe.runTrustedAsync(()=>y()):await y()}catch(y){if(y instanceof J||y instanceof Me)throw y;return P(`${t}: ${ze(Te(y))}
623
+ `,127);if("script"in c)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,c.path)),await a(c.path,s,r);let{cmd:u,path:f}=c;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",p=o(),m={fs:i.fs,cwd:i.state.cwd,env:i.state.env,exportedEnv:p,stdin:d,limits:i.limits,exec:i.execFn,fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo,coverage:i.coverage,signal:i.state.signal,requireDefenseContext:i.requireDefenseContext,jsBootstrapCode:i.jsBootstrapCode,executorInvokeTool:i.executorInvokeTool},h=ri(m,t);try{let y=()=>zr(i.requireDefenseContext,"command",`${t} execution`,()=>u.execute(s,h));return u.trusted?await pe.runTrustedAsync(()=>y()):await y()}catch(y){if(y instanceof J||y instanceof Me)throw y;return P(`${t}: ${ze(Te(y))}
624
624
  `)}}async function Nr(e,t){let s=e.state.inCondition;e.state.inCondition=!0;let r="",n="",i=0;try{for(let o of t){let a=await e.executeStatement(o);r+=a.stdout,n+=a.stderr,i=a.exitCode}}finally{e.state.inCondition=s}return{stdout:r,stderr:n,exitCode:i}}function _t(e,t,s,r){if(e instanceof me)return t+=e.stdout,s+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"break",stdout:t,stderr:s};if(e instanceof ye)return t+=e.stdout,s+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=s,{action:"rethrow",stdout:t,stderr:s,error:e}):{action:"continue",stdout:t,stderr:s};if(e instanceof ce||e instanceof ge||e instanceof j||e instanceof J)return e.prependOutput(t,s),{action:"rethrow",stdout:t,stderr:s,error:e};let n=Te(e);return{action:"error",stdout:t,stderr:`${s}${n}
625
625
  `,exitCode:1}}async function ws(e,t,s="",r=""){let n=s,i=r,o=0;try{for(let a of t){let l=await e.executeStatement(a);n+=l.stdout,i+=l.stderr,o=l.exitCode}}catch(a){if(Ft(a)||a instanceof ge||a instanceof j||a instanceof J||a instanceof We)throw a.prependOutput(n,i),a;return{stdout:n,stderr:`${i}${Te(a)}
626
626
  `,exitCode:1}}return{stdout:n,stderr:i,exitCode:o}}async function di(e,t){let s="",r="";for(let n of t.clauses){let i=await Nr(e,n.condition);if(s+=i.stdout,r+=i.stderr,i.exitCode===0)return ws(e,n.body,s,r)}return t.elseBody?ws(e,t.elseBody,s,r):_(s,r,0)}async function hi(e,t){let s=await xe(e,t.redirections);if(s)return s;let r="",n="",i=0,o=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return P(`bash: \`${t.variable}': not a valid identifier
@@ -660,7 +660,7 @@ sys 0m0.000s
660
660
  `,1)}e.state.groupStdin=c;let u=_(n,i,o);return G(e,u,t.redirections)}async function Ci(e,t,s,r,n){let i;try{i=await e.fs.readFile(t)}catch{return P(`bash: ${t}: No such file or directory
661
661
  `,127)}if(i.startsWith("#!")){let y=i.indexOf(`
662
662
  `);y!==-1&&(i=i.slice(y+1))}let o=new Map(e.state.env),a=e.state.cwd,l={...e.state.options},c=e.state.loopDepth,u=e.state.parentHasLoopContext,f=e.state.lastArg,d=e.state.bashPid,p=e.state.groupStdin,m=e.state.currentSource;e.state.parentHasLoopContext=c>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,r&&(e.state.groupStdin=r),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(s.length)),e.state.env.set("@",s.join(" ")),e.state.env.set("*",s.join(" "));for(let y=0;y<s.length&&y<9;y++)e.state.env.set(String(y+1),s[y]);for(let y=s.length+1;y<=9;y++)e.state.env.delete(String(y));let h=()=>{e.state.env=o,e.state.cwd=a,e.state.options=l,e.state.loopDepth=c,e.state.parentHasLoopContext=u,e.state.lastArg=f,e.state.bashPid=d,e.state.groupStdin=p,e.state.currentSource=m};try{let b=new B().parse(i),v=await n(b);return h(),v}catch(y){if(h(),y instanceof j||y instanceof J)throw y;if(y.name==="ParseException")return P(`bash: ${t}: ${y.message}
663
- `);throw y}}var Ct=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||pe.isInSandboxedContext())return;let s=`interpreter ${t} attempted outside defense context`;throw new Me(s,{timestamp:Date.now(),type:"missing_defense_context",message:s,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:pe.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,r=new Set;if(t)for(let i of t)r.add(i);if(s)for(let i of s)r.add(i);if(r.size===0)return Object.create(null);let n=Object.create(null);for(let i of r){let o=this.ctx.state.env.get(i);o!==void 0&&(n[i]=o)}return n}async executeScript(t){this.assertDefenseContext("execution");let s="",r="",n=0,i=this.ctx.limits.maxOutputSize,o=(a,l)=>{s.length+r.length+a.length+l.length>i&&Ne(`total output size exceeded (>${i} bytes), increase executionLimits.maxOutputSize`,"output_size"),s+=a,r+=l};for(let a of t.statements)try{let l=await this.executeStatement(a);o(l.stdout,l.stderr),n=l.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(l){if(l instanceof j)throw l.prependOutput(s,r),l;if(l instanceof $e)return o(l.stdout,l.stderr),n=l.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:Ve(this.ctx.state.env)};if(l instanceof J)throw l;if(l instanceof ge)return o(l.stdout,l.stderr),n=l.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:Ve(this.ctx.state.env)};if(l instanceof Mr)return o(l.stdout,l.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:Ve(this.ctx.state.env)};if(l instanceof Rt)return o(l.stdout,l.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:Ve(this.ctx.state.env)};if(l instanceof Ge){o(l.stdout,l.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(l instanceof Wr){o(l.stdout,l.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(l instanceof me||l instanceof ye){if(this.ctx.state.loopDepth>0)throw l.prependOutput(s,r),l;o(l.stdout,l.stderr);continue}throw l instanceof ce&&l.prependOutput(s,r),l}return{stdout:s,stderr:r,exitCode:n,env:Ve(this.ctx.state.env)}}async executeUserScript(t,s,r=""){return Ci(this.ctx,t,s,r,n=>this.executeScript(n))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Lt;if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&Ne(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new Bt(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return W;this.ctx.state.errexitSafe=!1;let s="",r="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(r+=`${t.sourceText}
663
+ `);throw y}}var Ct=class{ctx;constructor(t,s){this.ctx={state:s,fs:t.fs,commands:t.commands,limits:t.limits,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode,executorInvokeTool:t.executorInvokeTool}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||pe.isInSandboxedContext())return;let s=`interpreter ${t} attempted outside defense context`;throw new Me(s,{timestamp:Date.now(),type:"missing_defense_context",message:s,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:pe.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,s=this.ctx.state.tempExportedVars,r=new Set;if(t)for(let i of t)r.add(i);if(s)for(let i of s)r.add(i);if(r.size===0)return Object.create(null);let n=Object.create(null);for(let i of r){let o=this.ctx.state.env.get(i);o!==void 0&&(n[i]=o)}return n}async executeScript(t){this.assertDefenseContext("execution");let s="",r="",n=0,i=this.ctx.limits.maxOutputSize,o=(a,l)=>{s.length+r.length+a.length+l.length>i&&Ne(`total output size exceeded (>${i} bytes), increase executionLimits.maxOutputSize`,"output_size"),s+=a,r+=l};for(let a of t.statements)try{let l=await this.executeStatement(a);o(l.stdout,l.stderr),n=l.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(l){if(l instanceof j)throw l.prependOutput(s,r),l;if(l instanceof $e)return o(l.stdout,l.stderr),n=l.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:Ve(this.ctx.state.env)};if(l instanceof J)throw l;if(l instanceof ge)return o(l.stdout,l.stderr),n=l.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:Ve(this.ctx.state.env)};if(l instanceof Mr)return o(l.stdout,l.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:Ve(this.ctx.state.env)};if(l instanceof Rt)return o(l.stdout,l.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{stdout:s,stderr:r,exitCode:n,env:Ve(this.ctx.state.env)};if(l instanceof Ge){o(l.stdout,l.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(l instanceof Wr){o(l.stdout,l.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(l instanceof me||l instanceof ye){if(this.ctx.state.loopDepth>0)throw l.prependOutput(s,r),l;o(l.stdout,l.stderr);continue}throw l instanceof ce&&l.prependOutput(s,r),l}return{stdout:s,stderr:r,exitCode:n,env:Ve(this.ctx.state.env)}}async executeUserScript(t,s,r=""){return Ci(this.ctx,t,s,r,n=>this.executeScript(n))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new Lt;if(this.ctx.state.commandCount++,this.ctx.state.commandCount>this.ctx.limits.maxCommandCount&&Ne(`too many commands executed (>${this.ctx.limits.maxCommandCount}), increase executionLimits.maxCommandCount`,"commands"),t.deferredError)throw new Bt(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return W;this.ctx.state.errexitSafe=!1;let s="",r="";this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&(r+=`${t.sourceText}
664
664
  `);let n=0,i=-1,o=!1;for(let c=0;c<t.pipelines.length;c++){let u=t.pipelines[c],f=c>0?t.operators[c-1]:null;if(f==="&&"&&n!==0||f==="||"&&n===0)continue;let d=await this.executePipeline(u);s+=d.stdout,r+=d.stderr,n=d.exitCode,i=c,o=u.negated,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}let a=i<t.pipelines.length-1,l=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=a||o||l,this.ctx.state.options.errexit&&n!==0&&i===t.pipelines.length-1&&!o&&!this.ctx.state.inCondition&&!l)throw new ge(n,s,r);return _(s,r,n)}async executePipeline(t){return Si(this.ctx,t,(s,r)=>this.executeCommand(s,r))}async executeCommand(t,s){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,s);case"If":return di(this.ctx,t);case"For":return hi(this.ctx,t);case"CStyleFor":return pi(this.ctx,t);case"While":return mi(this.ctx,t,s);case"Until":return yi(this.ctx,t);case"Case":return gi(this.ctx,t);case"Subshell":return this.executeSubshell(t,s);case"Group":return this.executeGroup(t,s);case"FunctionDef":return Dn(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return W}}async executeSimpleCommand(t,s){try{return await this.executeSimpleCommandInner(t,s)}catch(r){if(r instanceof It)return P(r.stderr);throw r}}async executeSimpleCommandInner(t,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let g=t,w=100;for(;w>0;){let E=this.expandAlias(g);if(E===g)break;g=E,w--}this.aliasExpansionStack.clear(),g!==t&&(t=g)}this.ctx.state.expansionStderr="";let r=await Ai(this.ctx,t);if(r.error)return r.error;let n=r.tempAssignments,i=r.xtraceOutput;if(!t.name){if(t.redirections.length>0){let w=await xe(this.ctx,t.redirections);if(w)return w;let E=_("",i,0);return G(this.ctx,E,t.redirections)}this.ctx.state.lastArg="";let g=(this.ctx.state.expansionStderr||"")+i;return this.ctx.state.expansionStderr="",_("",g,this.ctx.state.lastExitCode)}let o=t.name&&Or(t.name,["local","declare","typeset","export","readonly"]),a=Array.from(n.keys());if(a.length>0&&!o){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let g of a)this.ctx.state.tempExportedVars.add(g)}let l=await us(this.ctx,t.redirections);if(l){for(let[g,w]of n)w===void 0?this.ctx.state.env.delete(g):this.ctx.state.env.set(g,w);return l}let c=-1;for(let g of t.redirections){if((g.operator==="<<"||g.operator==="<<-")&&g.target.type==="HereDoc"){let w=g.target,E=await L(this.ctx,w.content);w.stripTabs&&(E=E.split(`
665
665
  `).map(O=>O.replace(/^\t+/,"")).join(`
666
666
  `));let $=g.fd??0;$!==0?(this.ctx.state.fileDescriptors||(this.ctx.state.fileDescriptors=new Map),le(this.ctx),this.ctx.state.fileDescriptors.set($,E)):s=E;continue}if(g.operator==="<<<"&&g.target.type==="Word"){s=`${await L(this.ctx,g.target)}
@@ -692,11 +692,11 @@ ${t}
692
692
  esac${ke(e.redirections)}`}function Ja(e){let t=e.patterns.map(ie).join(" | "),s=Ee(e.body);return s?`${t})
693
693
  ${s}
694
694
  ${e.terminator}`:`${t})
695
- ${e.terminator}`}function el(e){return`(${Ee(e.body)})${ke(e.redirections)}`}function tl(e){return`{ ${Ee(e.body)}; }${ke(e.redirections)}`}function sl(e){return`((${Z(e.expression.expression)}))${ke(e.redirections)}`}function rl(e){return`[[ ${et(e.expression)} ]]${ke(e.redirections)}`}function nl(e){let t=Fi(e.body);return`${e.name}() ${t}${ke(e.redirections)}`}function Z(e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return e.hasDollarPrefix?`$${e.name}`:e.name;case"ArithSpecialVar":return`$${e.name}`;case"ArithBinary":return`${Z(e.left)} ${e.operator} ${Z(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${Z(e.operand)}`:`${Z(e.operand)}${e.operator}`;case"ArithTernary":return`${Z(e.condition)} ? ${Z(e.consequent)} : ${Z(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${Z(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${Z(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${Z(e.target)}[${Z(e.subscript)}]`:Z(e.target)} ${e.operator} ${Z(e.value)}`;case"ArithDynamicElement":return`${Z(e.nameExpr)}[${Z(e.subscript)}]`;case"ArithGroup":return`(${Z(e.expression)})`;case"ArithNested":return`$((${Z(e.expression)}))`;case"ArithCommandSubst":return`$(${e.command})`;case"ArithBracedExpansion":return`\${${e.content}}`;case"ArithArrayElement":return e.stringKey!==void 0?`${e.array}[${e.stringKey}]`:e.index?`${e.array}[${Z(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(Z).join("");case"ArithDoubleSubscript":return`${e.array}[${Z(e.index)}]`;case"ArithNumberSubscript":return`${e.number}[${e.errorToken}]`;case"ArithSyntaxError":return e.errorToken;case"ArithSingleQuote":return`'${e.content}'`;default:{let t=e;throw new Error(`Unsupported arithmetic expression type: ${t.type}`)}}}function et(e){switch(e.type){case"CondBinary":return`${ie(e.left)} ${e.operator} ${ie(e.right)}`;case"CondUnary":return`${e.operator} ${ie(e.operand)}`;case"CondNot":return`! ${et(e.operand)}`;case"CondAnd":return`${et(e.left)} && ${et(e.right)}`;case"CondOr":return`${et(e.left)} || ${et(e.right)}`;case"CondGroup":return`( ${et(e.expression)} )`;case"CondWord":return ie(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var xt=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;transformPlugins=[];state;constructor(t={}){let s=t.fs??new Le(t.files);this.fs=s,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),n=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
696
- `],["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"],["PWD",r],["OLDPWD",r],["OPTIND","1"],...Object.entries(t.env??{})]);if(this.limits=Ni({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}}),t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=Rr(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.coverageWriter=t.coverage,this.state={env:n,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,virtualPid:t.processInfo?.pid??1,virtualPpid:t.processInfo?.ppid??0,virtualUid:t.processInfo?.uid??1e3,virtualGid:t.processInfo?.gid??1e3,bashPid:t.processInfo?.pid??1,nextVirtualPid:(t.processInfo?.pid??1)+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",Ls(this.state.options)),this.state.env.set("BASHOPTS",Fs(this.state.shoptOptions)),un(s,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&s instanceof Le)try{s.mkdirSync(r,{recursive:!0})}catch{}for(let i of rn(t.commands))this.registerCommand(i);if(t.fetch||t.network)for(let i of nn())this.registerCommand(i);if(t.python)for(let i of on())this.registerCommand(i);if(t.javascript){for(let o of an())this.registerCommand(o);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap)}if(t.customCommands)for(let i of t.customCommands)ln(i)?this.registerCommand(cn(i)):this.registerCommand({...i,trusted:i.trusted??!0})}registerCommand(t){this.commands.set(t.name,t);let s=this.fs;if(typeof s.writeFileSync=="function"){let r=`#!/bin/bash
695
+ ${e.terminator}`}function el(e){return`(${Ee(e.body)})${ke(e.redirections)}`}function tl(e){return`{ ${Ee(e.body)}; }${ke(e.redirections)}`}function sl(e){return`((${Z(e.expression.expression)}))${ke(e.redirections)}`}function rl(e){return`[[ ${et(e.expression)} ]]${ke(e.redirections)}`}function nl(e){let t=Fi(e.body);return`${e.name}() ${t}${ke(e.redirections)}`}function Z(e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return e.hasDollarPrefix?`$${e.name}`:e.name;case"ArithSpecialVar":return`$${e.name}`;case"ArithBinary":return`${Z(e.left)} ${e.operator} ${Z(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${Z(e.operand)}`:`${Z(e.operand)}${e.operator}`;case"ArithTernary":return`${Z(e.condition)} ? ${Z(e.consequent)} : ${Z(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${Z(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${Z(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${Z(e.target)}[${Z(e.subscript)}]`:Z(e.target)} ${e.operator} ${Z(e.value)}`;case"ArithDynamicElement":return`${Z(e.nameExpr)}[${Z(e.subscript)}]`;case"ArithGroup":return`(${Z(e.expression)})`;case"ArithNested":return`$((${Z(e.expression)}))`;case"ArithCommandSubst":return`$(${e.command})`;case"ArithBracedExpansion":return`\${${e.content}}`;case"ArithArrayElement":return e.stringKey!==void 0?`${e.array}[${e.stringKey}]`:e.index?`${e.array}[${Z(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(Z).join("");case"ArithDoubleSubscript":return`${e.array}[${Z(e.index)}]`;case"ArithNumberSubscript":return`${e.number}[${e.errorToken}]`;case"ArithSyntaxError":return e.errorToken;case"ArithSingleQuote":return`'${e.content}'`;default:{let t=e;throw new Error(`Unsupported arithmetic expression type: ${t.type}`)}}}function et(e){switch(e.type){case"CondBinary":return`${ie(e.left)} ${e.operator} ${ie(e.right)}`;case"CondUnary":return`${e.operator} ${ie(e.operand)}`;case"CondNot":return`! ${et(e.operand)}`;case"CondAnd":return`${et(e.left)} && ${et(e.right)}`;case"CondOr":return`${et(e.left)} || ${et(e.right)}`;case"CondGroup":return`( ${et(e.expression)} )`;case"CondWord":return ie(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var xt=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;executorInvokeTool;executorSetup;executorApproval;executorSDK;executorInitPromise;transformPlugins=[];state;constructor(t={}){let s=t.fs??new Le(t.files);this.fs=s,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),n=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
696
+ `],["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"],["PWD",r],["OLDPWD",r],["OPTIND","1"],...Object.entries(t.env??{})]);if(this.limits=Ni({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}}),t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=Rr(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.coverageWriter=t.coverage,this.state={env:n,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,virtualPid:t.processInfo?.pid??1,virtualPpid:t.processInfo?.ppid??0,virtualUid:t.processInfo?.uid??1e3,virtualGid:t.processInfo?.gid??1e3,bashPid:t.processInfo?.pid??1,nextVirtualPid:(t.processInfo?.pid??1)+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",Ls(this.state.options)),this.state.env.set("BASHOPTS",Fs(this.state.shoptOptions)),un(s,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&s instanceof Le)try{s.mkdirSync(r,{recursive:!0})}catch{}for(let i of rn(t.commands))this.registerCommand(i);if(t.fetch||t.network)for(let i of nn())this.registerCommand(i);if(t.python)for(let i of on())this.registerCommand(i);if(t.javascript||t.executor){for(let o of an())this.registerCommand(o);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap)}if(t.executor?.tools){let i=t.executor.tools;this.executorInvokeTool=async(o,a)=>{if(!Object.hasOwn(i,o))throw new Error(`Unknown tool: ${o}`);let l=i[o],c;try{c=a?JSON.parse(a):void 0}catch{c=void 0}let u=await l.execute(c);return u!==void 0?JSON.stringify(u):""}}if(t.executor?.setup&&(this.executorSetup=t.executor.setup),t.executor?.onToolApproval&&(this.executorApproval=t.executor.onToolApproval),t.customCommands)for(let i of t.customCommands)ln(i)?this.registerCommand(cn(i)):this.registerCommand({...i,trusted:i.trusted??!0})}registerCommand(t){this.commands.set(t.name,t);let s=this.fs;if(typeof s.writeFileSync=="function"){let r=`#!/bin/bash
697
697
  # Built-in command: ${t.name}
698
- `;try{s.writeFileSync(`/bin/${t.name}`,r)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,r)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=Bi(t.stdout),t.stderr=Bi(t.stderr),t}async exec(t,s){if(this.state.callDepth===0&&(this.state.commandCount=0),this.state.commandCount++,this.state.commandCount>this.limits.maxCommandCount)return{stdout:"",stderr:`bash: maximum command count (${this.limits.maxCommandCount}) exceeded (possible infinite loop). Increase with executionLimits.maxCommandCount option.
699
- `,exitCode:1,env:we(this.state.env,s?.env)};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:we(this.state.env,s?.env)};this.logger?.info("exec",{command:t});let r=s?.cwd??this.state.cwd,n,i=r;if(s?.cwd)if(s.env&&"PWD"in s.env)n=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{n=await this.fs.realpath(r),i=n}catch{n=r}else n=r;let o=s?.replaceEnv?new Map:new Map(this.state.env);if(s?.env)for(let[f,d]of Object.entries(s.env))o.set(f,d);n!==void 0&&o.set("PWD",n);let a={...this.state,env:o,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:s?.stdin,signal:s?.signal,extraArgs:s?.args},l=t;s?.rawScript||(l=Vi(t));let c=this.defenseInDepthConfig?pe.getInstance(this.defenseInDepthConfig):null,u=c?.activate();try{let f=async()=>{let d=ue(l,{maxHeredocSize:this.limits.maxHeredocSize}),p;if(this.transformPlugins.length>0){let v=Object.create(null);for(let A of this.transformPlugins){let g=A.transform({ast:d,metadata:v});d=g.ast,g.metadata&&(v=Et(v,g.metadata))}p=v}let m={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:c?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode},b=await new Ct(m,a).executeScript(d);return p&&(b.metadata=p),this.logResult(b)};return u?await u.run(f):await f()}catch(f){if(f instanceof j)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:we(this.state.env,s?.env)});if(f instanceof $e)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:we(this.state.env,s?.env)});if(f instanceof Ge)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:1,env:we(this.state.env,s?.env)});if(f instanceof Lt)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:we(this.state.env,s?.env)});if(f instanceof J)return this.logResult({stdout:f.stdout,stderr:ze(f.stderr),exitCode:J.EXIT_CODE,env:we(this.state.env,s?.env)});if(f instanceof Me)return this.logResult({stdout:"",stderr:`bash: security violation: ${ze(f.message)}
698
+ `;try{s.writeFileSync(`/bin/${t.name}`,r)}catch{}try{s.writeFileSync(`/usr/bin/${t.name}`,r)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=Bi(t.stdout),t.stderr=Bi(t.stderr),t}async ensureExecutorReady(){if(!(!this.executorSetup||this.executorSDK)){if(this.executorInitPromise){await this.executorInitPromise;return}this.executorInitPromise=(async()=>{let t="./executor-init.js",{initExecutorSDK:s}=await import(t),r=this.executorSetup;if(!r)return;let{sdk:n,invokeTool:i}=await s(r,this.executorApproval,this.fs,()=>this.state.cwd,()=>this.state.env,()=>this.limits);this.executorSDK=n,this.executorInvokeTool=i})(),await this.executorInitPromise}}async exec(t,s){if(await this.ensureExecutorReady(),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.
699
+ `,exitCode:1,env:we(this.state.env,s?.env)};if(!t.trim())return{stdout:"",stderr:"",exitCode:0,env:we(this.state.env,s?.env)};this.logger?.info("exec",{command:t});let r=s?.cwd??this.state.cwd,n,i=r;if(s?.cwd)if(s.env&&"PWD"in s.env)n=s.env.PWD;else if(s?.env&&!("PWD"in s.env))try{n=await this.fs.realpath(r),i=n}catch{n=r}else n=r;let o=s?.replaceEnv?new Map:new Map(this.state.env);if(s?.env)for(let[f,d]of Object.entries(s.env))o.set(f,d);n!==void 0&&o.set("PWD",n);let a={...this.state,env:o,cwd:i,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:s?.stdin,signal:s?.signal,extraArgs:s?.args},l=t;s?.rawScript||(l=Vi(t));let c=this.defenseInDepthConfig?pe.getInstance(this.defenseInDepthConfig):null,u=c?.activate();try{let f=async()=>{let d=ue(l,{maxHeredocSize:this.limits.maxHeredocSize}),p;if(this.transformPlugins.length>0){let v=Object.create(null);for(let A of this.transformPlugins){let g=A.transform({ast:d,metadata:v});d=g.ast,g.metadata&&(v=Et(v,g.metadata))}p=v}let m={fs:this.fs,commands:this.commands,limits:this.limits,exec:this.exec.bind(this),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:c?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,executorInvokeTool:this.executorInvokeTool},b=await new Ct(m,a).executeScript(d);return p&&(b.metadata=p),this.logResult(b)};return u?await u.run(f):await f()}catch(f){if(f instanceof j)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:we(this.state.env,s?.env)});if(f instanceof $e)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode,env:we(this.state.env,s?.env)});if(f instanceof Ge)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:1,env:we(this.state.env,s?.env)});if(f instanceof Lt)return this.logResult({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:we(this.state.env,s?.env)});if(f instanceof J)return this.logResult({stdout:f.stdout,stderr:ze(f.stderr),exitCode:J.EXIT_CODE,env:we(this.state.env,s?.env)});if(f instanceof Me)return this.logResult({stdout:"",stderr:`bash: security violation: ${ze(f.message)}
700
700
  `,exitCode:1,env:we(this.state.env,s?.env)});if(f.name==="ParseException")return this.logResult({stdout:"",stderr:`bash: syntax error: ${ze(f.message)}
701
701
  `,exitCode:2,env:we(this.state.env,s?.env)});if(f instanceof jr)return this.logResult({stdout:"",stderr:`bash: ${ze(f.message)}
702
702
  `,exitCode:2,env:we(this.state.env,s?.env)});if(f instanceof RangeError)return this.logResult({stdout:"",stderr:`bash: ${ze(f.message)}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Adapter for using js-exec as a CodeExecutor runtime for @executor/sdk.
3
+ *
4
+ * This module exports a Promise-based executor that can be wrapped with
5
+ * Effect.tryPromise() to satisfy the CodeExecutor interface.
6
+ *
7
+ * Usage with @executor/sdk:
8
+ *
9
+ * ```ts
10
+ * import { createJustBashCodeExecutor } from 'just-bash/executor';
11
+ * import { createExecutor } from '@executor/sdk';
12
+ * import type { CodeExecutor } from '@executor/sdk';
13
+ * import * as Effect from 'effect/Effect';
14
+ *
15
+ * const jb = createJustBashCodeExecutor();
16
+ *
17
+ * const codeExecutor: CodeExecutor = {
18
+ * execute: (code, toolInvoker) =>
19
+ * Effect.tryPromise(() =>
20
+ * jb.execute(code, (path, args) =>
21
+ * Effect.runPromise(toolInvoker.invoke({ path, args }))
22
+ * )
23
+ * ),
24
+ * };
25
+ *
26
+ * const executor = await createExecutor({
27
+ * runtime: codeExecutor,
28
+ * tools: { ... },
29
+ * });
30
+ * ```
31
+ */
32
+ import type { IFileSystem } from "../../fs/interface.js";
33
+ import type { SecureFetch } from "../../network/index.js";
34
+ import { type ExecutorResult } from "./js-exec.js";
35
+ export interface JustBashExecutorOptions {
36
+ /** Virtual filesystem for code to access. Defaults to an empty InMemoryFs. */
37
+ fs?: IFileSystem;
38
+ /** Working directory inside the sandbox. Defaults to /home/user. */
39
+ cwd?: string;
40
+ /** Environment variables available to code. Defaults to empty. */
41
+ env?: Record<string, string>;
42
+ /** Network fetch function. Defaults to undefined (no network). */
43
+ fetch?: SecureFetch;
44
+ }
45
+ export interface JustBashCodeExecutor {
46
+ /**
47
+ * Execute code with tool invocation support.
48
+ *
49
+ * @param code - JavaScript code to execute. Can use `await` and `return`.
50
+ * Tools are available as `tools.namespace.method(args)`.
51
+ * @param invokeTool - Callback to handle tool invocations.
52
+ * Receives (path, args) and should return the tool result.
53
+ * @returns ExecutorResult with result, error, and captured logs.
54
+ */
55
+ execute(code: string, invokeTool: (path: string, args: unknown) => Promise<unknown>): Promise<ExecutorResult>;
56
+ }
57
+ /**
58
+ * Create a js-exec based code executor for use with @executor/sdk.
59
+ *
60
+ * The executor runs JavaScript code in a QuickJS sandbox with:
61
+ * - A `tools` proxy for invoking registered tools
62
+ * - Console output captured to `logs` array
63
+ * - Return value captured in `result`
64
+ * - Full Node.js-compatible module system (fs, path, etc.)
65
+ */
66
+ export declare function createJustBashCodeExecutor(options?: JustBashExecutorOptions): JustBashCodeExecutor;
@@ -6,6 +6,24 @@
6
6
  *
7
7
  * This command is Node.js only (uses worker_threads).
8
8
  */
9
- import type { Command } from "../../types.js";
9
+ import type { Command, CommandContext } from "../../types.js";
10
+ /**
11
+ * Result from executing code in executor mode.
12
+ * Compatible with @executor/sdk's ExecuteResult shape.
13
+ */
14
+ export interface ExecutorResult {
15
+ result: unknown;
16
+ error?: string;
17
+ logs?: string[];
18
+ }
19
+ /**
20
+ * Execute JavaScript code in executor mode with tool invocation support.
21
+ * Used as the runtime for @executor/sdk's CodeExecutor interface.
22
+ *
23
+ * - Console output is captured to `logs` instead of stdout/stderr
24
+ * - Tool calls via `tools.x.y(args)` are routed through `invokeTool`
25
+ * - The return value of the code is captured in `result`
26
+ */
27
+ export declare function executeForExecutor(code: string, ctx: CommandContext, invokeTool: (path: string, argsJson: string) => Promise<string>): Promise<ExecutorResult>;
10
28
  export declare const jsExecCommand: Command;
11
29
  export declare const nodeStubCommand: Command;
@@ -21,10 +21,18 @@ export interface JsExecWorkerInput {
21
21
  isModule?: boolean;
22
22
  stripTypes?: boolean;
23
23
  timeoutMs?: number;
24
+ /** When true, tools proxy is available (console still goes to stdout/stderr) */
25
+ hasExecutorTools?: boolean;
26
+ /** When true, runs in full executor mode: tools proxy, log capture, result capture */
27
+ executorMode?: boolean;
24
28
  }
25
29
  export interface JsExecWorkerOutput {
26
30
  protocolToken?: string;
27
31
  success: boolean;
28
32
  error?: string;
29
33
  defenseStats?: WorkerDefenseStats;
34
+ /** JSON-serialized return value (executor mode only) */
35
+ executorResult?: string;
36
+ /** Captured console logs (executor mode only) */
37
+ executorLogs?: string[];
30
38
  }
@@ -22,13 +22,14 @@ export declare class BridgeHandler {
22
22
  private secureFetch;
23
23
  private maxOutputSize;
24
24
  private exec;
25
+ private invokeTool;
25
26
  private protocol;
26
27
  private running;
27
28
  private output;
28
29
  private outputLimitExceeded;
29
30
  private startTime;
30
31
  private timeoutMs;
31
- constructor(sharedBuffer: SharedArrayBuffer, fs: IFileSystem, cwd: string, commandName: string, secureFetch?: SecureFetch | undefined, maxOutputSize?: number, exec?: ((command: string, options: CommandExecOptions) => Promise<ExecResult>) | undefined);
32
+ constructor(sharedBuffer: SharedArrayBuffer, fs: IFileSystem, cwd: string, commandName: string, secureFetch?: SecureFetch | undefined, maxOutputSize?: number, exec?: ((command: string, options: CommandExecOptions) => Promise<ExecResult>) | undefined, invokeTool?: ((path: string, argsJson: string) => Promise<string>) | undefined);
32
33
  /**
33
34
  * Returns remaining milliseconds before the overall execution deadline.
34
35
  */
@@ -67,5 +68,6 @@ export declare class BridgeHandler {
67
68
  private appendOutputLimitError;
68
69
  private handleHttpRequest;
69
70
  private handleExecCommand;
71
+ private handleInvokeTool;
70
72
  private setErrorFromException;
71
73
  }
@@ -38,6 +38,7 @@ export declare const OpCode: {
38
38
  readonly EXIT: 102;
39
39
  readonly HTTP_REQUEST: 200;
40
40
  readonly EXEC_COMMAND: 300;
41
+ readonly INVOKE_TOOL: 400;
41
42
  };
42
43
  export type OpCodeType = (typeof OpCode)[keyof typeof OpCode];
43
44
  /** Status codes for synchronization */
@@ -77,4 +77,9 @@ export declare class SyncBackend {
77
77
  stderr: string;
78
78
  exitCode: number;
79
79
  };
80
+ /**
81
+ * Invoke a tool through the main thread's tool invoker (executor mode).
82
+ * Returns the JSON-serialized result.
83
+ */
84
+ invokeTool(path: string, argsJson: string): string;
80
85
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Executor SDK lazy initialization.
3
+ * Separated from Bash.ts so the browser bundle never sees these imports.
4
+ * Only loaded at runtime behind a __BROWSER__ guard.
5
+ */
6
+ import type { ExecutorConfig, ExecutorSDKHandle } from "./Bash.js";
7
+ export declare function initExecutorSDK(setup: (sdk: ExecutorSDKHandle) => Promise<void>, approval: ExecutorConfig["onToolApproval"] | undefined, fs: import("./fs/interface.js").IFileSystem, getCwd: () => string, getEnv: () => Map<string, string>, getLimits: () => import("./limits.js").ExecutionLimits | undefined): Promise<{
8
+ sdk: ExecutorSDKHandle;
9
+ invokeTool: (path: string, argsJson: string) => Promise<string>;
10
+ }>;
@@ -41,6 +41,8 @@ export interface InterpreterOptions {
41
41
  requireDefenseContext?: boolean;
42
42
  /** Bootstrap JavaScript code for js-exec */
43
43
  jsBootstrapCode?: string;
44
+ /** Tool invoker for executor mode (js-exec) */
45
+ executorInvokeTool?: (path: string, argsJson: string) => Promise<string>;
44
46
  }
45
47
  export declare class Interpreter {
46
48
  private ctx;
@@ -341,4 +341,9 @@ export interface InterpreterContext {
341
341
  * Threaded through the context chain instead of shell env.
342
342
  */
343
343
  jsBootstrapCode?: string;
344
+ /**
345
+ * Tool invoker for executor mode (js-exec).
346
+ * When present, js-exec sets up a `tools` proxy.
347
+ */
348
+ executorInvokeTool?: (path: string, argsJson: string) => Promise<string>;
344
349
  }
package/dist/types.d.ts CHANGED
@@ -182,6 +182,12 @@ export interface CommandContext {
182
182
  * user access/injection via environment variables.
183
183
  */
184
184
  jsBootstrapCode?: string;
185
+ /**
186
+ * Tool invoker for executor mode (js-exec).
187
+ * When present, js-exec sets up a `tools` proxy that routes calls through this.
188
+ * The function receives (path, argsJson) and returns a JSON result string.
189
+ */
190
+ executorInvokeTool?: (path: string, argsJson: string) => Promise<string>;
185
191
  }
186
192
  export interface Command {
187
193
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-bash",
3
- "version": "2.14.0",
3
+ "version": "2.15.0-executor.0",
4
4
  "description": "A simulated bash environment with virtual filesystem",
5
5
  "repository": {
6
6
  "type": "git",
@@ -44,6 +44,7 @@
44
44
  "dist/sandbox/*.d.ts",
45
45
  "dist/utils/*.d.ts",
46
46
  "vendor/cpython-emscripten/",
47
+ "vendor/executor/",
47
48
  "README.md",
48
49
  "dist/AGENTS.md"
49
50
  ],
@@ -54,6 +55,38 @@
54
55
  "publishConfig": {
55
56
  "access": "public"
56
57
  },
58
+ "scripts": {
59
+ "build": "rm -rf dist && tsc && pnpm build:lib && pnpm build:lib:cjs && pnpm build:browser && pnpm build:cli && pnpm build:shell && pnpm build:worker && pnpm build:clean && cp dist/index.d.ts dist/index.d.cts && sed '1,/^-->/d' AGENTS.npm.md > dist/AGENTS.md",
60
+ "build:clean": "find dist -name '*.test.js' -delete && find dist -name '*.test.d.ts' -delete",
61
+ "build:worker": "esbuild src/commands/python3/worker.ts --bundle --platform=node --format=esm --outfile=src/commands/python3/worker.js --external:../../../vendor/cpython-emscripten/* && cp src/commands/python3/worker.js dist/commands/python3/worker.js && mkdir -p dist/bin/chunks && cp src/commands/python3/worker.js dist/bin/chunks/worker.js && mkdir -p dist/bundle/chunks && cp src/commands/python3/worker.js dist/bundle/chunks/worker.js && esbuild src/commands/js-exec/worker.ts --bundle --platform=node --format=esm --outfile=src/commands/js-exec/worker.js --external:quickjs-emscripten && cp src/commands/js-exec/worker.js dist/commands/js-exec/worker.js && cp src/commands/js-exec/worker.js dist/bin/chunks/js-exec-worker.js && cp src/commands/js-exec/worker.js dist/bundle/chunks/js-exec-worker.js",
62
+ "build:lib": "esbuild dist/index.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bundle --chunk-names=chunks/[name]-[hash] --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs --external:effect --external:@effect/platform --external:@effect/platform-node --external:../vendor/executor/*",
63
+ "build:lib:cjs": "esbuild dist/index.js --bundle --platform=node --format=cjs --minify --outfile=dist/bundle/index.cjs --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs --external:effect --external:@effect/platform --external:@effect/platform-node --external:../vendor/executor/*",
64
+ "build:browser": "esbuild dist/browser.js --bundle --platform=browser --format=esm --minify --outfile=dist/bundle/browser.js --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:node:zlib --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs --define:__BROWSER__=true --alias:node:dns=./src/shims/browser-unsupported.js",
65
+ "build:cli": "esbuild dist/cli/just-bash.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bin --entry-names=[name] --chunk-names=chunks/[name]-[hash] --banner:js='#!/usr/bin/env node' --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs --external:effect --external:@effect/platform --external:@effect/platform-node --external:../vendor/executor/*",
66
+ "build:shell": "esbuild dist/cli/shell.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bin/shell --entry-names=[name] --chunk-names=chunks/[name]-[hash] --banner:js='#!/usr/bin/env node' --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
67
+ "prepublishOnly": "pnpm validate",
68
+ "validate": "pnpm lint && pnpm knip && pnpm typecheck && pnpm build && pnpm check:worker-sync && pnpm test:run && pnpm test:wasm && pnpm test:dist && pnpm test:examples",
69
+ "test:examples": "cd examples/cjs-consumer && pnpm install --no-frozen-lockfile && npx tsc --noEmit",
70
+ "typecheck": "tsc --noEmit",
71
+ "lint": "biome check . && pnpm lint:banned",
72
+ "check:worker-sync": "node scripts/check-worker-sync.js",
73
+ "lint:banned": "node scripts/check-banned-patterns.js",
74
+ "lint:fix": "biome check --write .",
75
+ "knip": "knip",
76
+ "test": "vitest",
77
+ "test:run": "vitest run --exclude src/security/fuzzing/ --exclude src/commands/python3/ --exclude src/commands/sqlite3/ --exclude src/commands/js-exec/ --exclude src/agent-examples/python-scripting.test.ts",
78
+ "test:dist": "vitest run src/cli/just-bash.bundle.test.ts",
79
+ "test:unit": "vitest run --config vitest.unit.config.ts",
80
+ "test:wasm": "vitest run --config vitest.wasm.config.ts",
81
+ "test:comparison": "vitest run --config vitest.comparison.config.ts",
82
+ "test:comparison:record": "RECORD_FIXTURES=1 vitest run --config vitest.comparison.config.ts",
83
+ "test:coverage": "vitest run --coverage",
84
+ "test:coverage:unit": "vitest run --config vitest.unit.config.ts --coverage",
85
+ "test:fuzz": "vitest run src/security/fuzzing/",
86
+ "test:fuzz:long": "FUZZ_RUNS=10000 vitest run src/security/fuzzing/",
87
+ "shell": "npx tsx src/cli/shell.ts",
88
+ "dev:exec": "npx tsx src/cli/exec.ts"
89
+ },
57
90
  "keywords": [],
58
91
  "author": "Malte and Claude",
59
92
  "license": "Apache-2.0",
@@ -75,6 +108,7 @@
75
108
  "dependencies": {
76
109
  "compressjs": "^1.0.3",
77
110
  "diff": "^8.0.2",
111
+ "effect": "^3.21.0",
78
112
  "fast-xml-parser": "^5.3.3",
79
113
  "file-type": "^21.2.0",
80
114
  "ini": "^6.0.0",
@@ -93,36 +127,5 @@
93
127
  "@mongodb-js/zstd": "^7.0.0",
94
128
  "node-liblzma": "^2.0.3"
95
129
  },
96
- "packageManager": "pnpm@8.15.9+sha512.499434c9d8fdd1a2794ebf4552b3b25c0a633abcee5bb15e7b5de90f32f47b513aca98cd5cfd001c31f0db454bc3804edccd578501e4ca293a6816166bbd9f81",
97
- "scripts": {
98
- "build": "rm -rf dist && tsc && pnpm build:lib && pnpm build:lib:cjs && pnpm build:browser && pnpm build:cli && pnpm build:shell && pnpm build:worker && pnpm build:clean && cp dist/index.d.ts dist/index.d.cts && sed '1,/^-->/d' AGENTS.npm.md > dist/AGENTS.md",
99
- "build:clean": "find dist -name '*.test.js' -delete && find dist -name '*.test.d.ts' -delete",
100
- "build:worker": "esbuild src/commands/python3/worker.ts --bundle --platform=node --format=esm --outfile=src/commands/python3/worker.js --external:../../../vendor/cpython-emscripten/* && cp src/commands/python3/worker.js dist/commands/python3/worker.js && mkdir -p dist/bin/chunks && cp src/commands/python3/worker.js dist/bin/chunks/worker.js && mkdir -p dist/bundle/chunks && cp src/commands/python3/worker.js dist/bundle/chunks/worker.js && esbuild src/commands/js-exec/worker.ts --bundle --platform=node --format=esm --outfile=src/commands/js-exec/worker.js --external:quickjs-emscripten && cp src/commands/js-exec/worker.js dist/commands/js-exec/worker.js && cp src/commands/js-exec/worker.js dist/bin/chunks/js-exec-worker.js && cp src/commands/js-exec/worker.js dist/bundle/chunks/js-exec-worker.js",
101
- "build:lib": "esbuild dist/index.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bundle --chunk-names=chunks/[name]-[hash] --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
102
- "build:lib:cjs": "esbuild dist/index.js --bundle --platform=node --format=cjs --minify --outfile=dist/bundle/index.cjs --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
103
- "build:browser": "esbuild dist/browser.js --bundle --platform=browser --format=esm --minify --outfile=dist/bundle/browser.js --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:node:zlib --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs --define:__BROWSER__=true --alias:node:dns=./src/shims/browser-unsupported.js",
104
- "build:cli": "esbuild dist/cli/just-bash.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bin --entry-names=[name] --chunk-names=chunks/[name]-[hash] --banner:js='#!/usr/bin/env node' --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
105
- "build:shell": "esbuild dist/cli/shell.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bin/shell --entry-names=[name] --chunk-names=chunks/[name]-[hash] --banner:js='#!/usr/bin/env node' --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
106
- "validate": "pnpm lint && pnpm knip && pnpm typecheck && pnpm build && pnpm check:worker-sync && pnpm test:run && pnpm test:wasm && pnpm test:dist && pnpm test:examples",
107
- "test:examples": "cd examples/cjs-consumer && pnpm install --no-frozen-lockfile && npx tsc --noEmit",
108
- "typecheck": "tsc --noEmit",
109
- "lint": "biome check . && pnpm lint:banned",
110
- "check:worker-sync": "node scripts/check-worker-sync.js",
111
- "lint:banned": "node scripts/check-banned-patterns.js",
112
- "lint:fix": "biome check --write .",
113
- "knip": "knip",
114
- "test": "vitest",
115
- "test:run": "vitest run --exclude src/security/fuzzing/ --exclude src/commands/python3/ --exclude src/commands/sqlite3/ --exclude src/commands/js-exec/ --exclude src/agent-examples/python-scripting.test.ts",
116
- "test:dist": "vitest run src/cli/just-bash.bundle.test.ts",
117
- "test:unit": "vitest run --config vitest.unit.config.ts",
118
- "test:wasm": "vitest run --config vitest.wasm.config.ts",
119
- "test:comparison": "vitest run --config vitest.comparison.config.ts",
120
- "test:comparison:record": "RECORD_FIXTURES=1 vitest run --config vitest.comparison.config.ts",
121
- "test:coverage": "vitest run --coverage",
122
- "test:coverage:unit": "vitest run --config vitest.unit.config.ts --coverage",
123
- "test:fuzz": "vitest run src/security/fuzzing/",
124
- "test:fuzz:long": "FUZZ_RUNS=10000 vitest run src/security/fuzzing/",
125
- "shell": "npx tsx src/cli/shell.ts",
126
- "dev:exec": "npx tsx src/cli/exec.ts"
127
- }
128
- }
130
+ "packageManager": "pnpm@8.15.9+sha512.499434c9d8fdd1a2794ebf4552b3b25c0a633abcee5bb15e7b5de90f32f47b513aca98cd5cfd001c31f0db454bc3804edccd578501e4ca293a6816166bbd9f81"
131
+ }
File without changes
@@ -0,0 +1,18 @@
1
+ /** Vendored @executor/sdk bundle — re-exports createExecutor and types */
2
+ export declare function createExecutor(options: {
3
+ runtime?: unknown;
4
+ storage?: unknown;
5
+ tools?: Record<string, { description?: string; execute: (...args: unknown[]) => unknown }>;
6
+ onToolApproval?: unknown;
7
+ onInteraction?: unknown;
8
+ resolveSecret?: unknown;
9
+ }): Promise<{
10
+ execute: (code: string) => Promise<{ result: unknown; error?: string; logs?: string[] }>;
11
+ sources: {
12
+ add: (input: Record<string, unknown>, options?: Record<string, unknown>) => Promise<unknown>;
13
+ list: () => Promise<unknown[]>;
14
+ [key: string]: unknown;
15
+ };
16
+ close: () => Promise<void>;
17
+ [key: string]: unknown;
18
+ }>;