@jerryan/just-bash 3.6.0 → 3.6.1
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.
- package/CHANGELOG.md +334 -316
- package/LICENSE +201 -201
- package/README.md +827 -827
- package/dist/agent-sandbox.d.ts +5 -0
- package/dist/bin/{shell/chunks/chunk-7WBCA2BB.js → chunks/chunk-3DWQCLNP.js} +1 -1
- package/dist/bin/{shell/chunks/chunk-QFTZKD5O.js → chunks/chunk-6TUILMPB.js} +1 -1
- package/dist/bin/chunks/chunk-JHEAT7AR.js +12 -0
- package/dist/bin/{shell/chunks/chunk-MF3GVFLC.js → chunks/chunk-L345YZ6R.js} +1 -1
- package/dist/bin/chunks/chunk-QKJAAJ7J.js +3 -0
- package/dist/bin/chunks/{chunk-6LDOIBU7.js → chunk-SE7JHGP3.js} +6 -6
- package/dist/bin/chunks/{chunk-NLU5LALY.js → chunk-YCOJCFGU.js} +1 -1
- package/dist/bin/{shell/chunks/flag-coverage-C7PB2MO7.js → chunks/flag-coverage-FYJ2V7J4.js} +1 -1
- package/dist/bin/{shell/chunks/js-exec-DJQLXWCS.js → chunks/js-exec-5QZZCOR7.js} +7 -7
- package/dist/bin/chunks/js-exec-worker.js +155 -33
- package/dist/bin/{shell/chunks/python3-JCJHSX4Z.js → chunks/python3-TMFYDQAP.js} +1 -1
- package/dist/bin/chunks/{rm-TF2NJQIA.js → rm-NLG5344W.js} +1 -1
- package/dist/bin/chunks/{sleep-DVFE2GSF.js → sleep-MOJQBZMY.js} +1 -1
- package/dist/bin/{shell/chunks/sqlite3-KP42NNIY.js → chunks/sqlite3-3EUPHVEZ.js} +1 -1
- package/dist/bin/chunks/{timeout-YGFHQJKX.js → timeout-RQOWSWYG.js} +1 -1
- package/dist/bin/chunks/worker.js +162 -48
- package/dist/bin/just-bash.js +241 -241
- package/dist/bin/{chunks/chunk-7WBCA2BB.js → shell/chunks/chunk-3DWQCLNP.js} +1 -1
- package/dist/bin/{chunks/chunk-QFTZKD5O.js → shell/chunks/chunk-6TUILMPB.js} +1 -1
- package/dist/bin/shell/chunks/chunk-JHEAT7AR.js +12 -0
- package/dist/bin/{chunks/chunk-MF3GVFLC.js → shell/chunks/chunk-L345YZ6R.js} +1 -1
- package/dist/bin/shell/chunks/chunk-QKJAAJ7J.js +3 -0
- package/dist/bin/shell/chunks/{chunk-6LDOIBU7.js → chunk-SE7JHGP3.js} +6 -6
- package/dist/bin/shell/chunks/{chunk-NLU5LALY.js → chunk-YCOJCFGU.js} +1 -1
- package/dist/bin/{chunks/flag-coverage-C7PB2MO7.js → shell/chunks/flag-coverage-FYJ2V7J4.js} +1 -1
- package/dist/bin/{chunks/js-exec-DJQLXWCS.js → shell/chunks/js-exec-5QZZCOR7.js} +7 -7
- package/dist/bin/{chunks/python3-JCJHSX4Z.js → shell/chunks/python3-TMFYDQAP.js} +1 -1
- package/dist/bin/shell/chunks/{rm-TF2NJQIA.js → rm-NLG5344W.js} +1 -1
- package/dist/bin/shell/chunks/{sleep-DVFE2GSF.js → sleep-MOJQBZMY.js} +1 -1
- package/dist/bin/{chunks/sqlite3-KP42NNIY.js → shell/chunks/sqlite3-3EUPHVEZ.js} +1 -1
- package/dist/bin/shell/chunks/{timeout-YGFHQJKX.js → timeout-RQOWSWYG.js} +1 -1
- package/dist/bin/shell/shell.js +3 -3
- package/dist/bundle/browser.js +2 -2
- package/dist/bundle/chunks/{chunk-N3A4JVFJ.js → chunk-6IA4DXG2.js} +1 -1
- package/dist/bundle/chunks/{chunk-PIRTX3D3.js → chunk-G3IRZ4FN.js} +6 -6
- package/dist/bundle/chunks/{chunk-24NLAR7R.js → chunk-KEMO3CBM.js} +1 -1
- package/dist/bundle/chunks/chunk-PS2RJNZZ.js +2 -0
- package/dist/bundle/chunks/{chunk-DMWNBCXJ.js → chunk-TLPMB3FO.js} +1 -1
- package/dist/bundle/chunks/chunk-ULXGGWAD.js +11 -0
- package/dist/bundle/chunks/{chunk-XV2V56NQ.js → chunk-YFFU74KY.js} +1 -1
- package/dist/bundle/chunks/{flag-coverage-XTIQGK65.js → flag-coverage-XSPWRCVG.js} +1 -1
- package/dist/bundle/chunks/{js-exec-XKF2B7C3.js → js-exec-57QMXJG5.js} +7 -7
- package/dist/bundle/chunks/js-exec-worker.js +155 -33
- package/dist/bundle/chunks/{python3-F5S5TYGS.js → python3-NNONJINM.js} +1 -1
- package/dist/bundle/chunks/{rm-OAZOF7XI.js → rm-R2ZENNSN.js} +1 -1
- package/dist/bundle/chunks/{sleep-PPRBTSVR.js → sleep-25QUPVDK.js} +1 -1
- package/dist/bundle/chunks/{sqlite3-4EZ4GXVD.js → sqlite3-M4UZPXDO.js} +1 -1
- package/dist/bundle/chunks/{timeout-C6WDYPLV.js → timeout-37GM7IIL.js} +1 -1
- package/dist/bundle/chunks/worker.js +162 -48
- package/dist/bundle/index.cjs +751 -751
- package/dist/bundle/index.js +298 -298
- package/dist/commands/js-exec/js-exec.d.ts +4 -0
- package/dist/commands/worker-bridge/bridge-handler.d.ts +9 -0
- package/dist/commands/worker-bridge/protocol.d.ts +17 -0
- package/dist/commands/worker-bridge/sync-backend.d.ts +3 -0
- package/dist/fs/overlay-fs/apply.d.ts +13 -0
- package/dist/fs/overlay-fs/index.d.ts +2 -0
- package/dist/fs/overlay-fs/merge.d.ts +24 -0
- package/dist/fs/overlay-fs/overlay-fs.d.ts +17 -0
- package/dist/fs/overlay-fs/overlay-tree.d.ts +39 -0
- package/dist/fs/vfs-template.d.ts +51 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/timers.d.ts +9 -0
- package/package.json +135 -136
- package/vendor/cpython-emscripten/python.cjs +2 -2
- package/dist/bin/chunks/chunk-JQM3DKCH.js +0 -12
- package/dist/bin/chunks/chunk-PPVF2N6C.js +0 -3
- package/dist/bin/shell/chunks/chunk-JQM3DKCH.js +0 -12
- package/dist/bin/shell/chunks/chunk-PPVF2N6C.js +0 -3
- package/dist/bundle/chunks/chunk-WXPNKIIH.js +0 -2
- package/dist/bundle/chunks/chunk-YJKHREBZ.js +0 -11
package/dist/bin/shell/shell.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
3
|
-
import{a as Dn,b as In,c as jt}from"./chunks/chunk-O2BCKSMK.js";import{a as Nr}from"./chunks/chunk-3PCPQIUD.js";import{c as Qs,e as wa}from"./chunks/chunk-TW2IJRUF.js";import{a as ma,b as ya,c as Qn,d as Kn}from"./chunks/chunk-PPVF2N6C.js";import{a as qt}from"./chunks/chunk-K27FY3ES.js";import{a as Ut,b as Ue,c as Zs}from"./chunks/chunk-MROECM42.js";import{a as Xn,b as ga}from"./chunks/chunk-42AMF6EE.js";import{a as he}from"./chunks/chunk-GA5TPRMF.js";import{a as Ir,b as Or}from"./chunks/chunk-GR4ZHKXI.js";import{a as Cr,b as Ge}from"./chunks/chunk-HWI42GQO.js";import"./chunks/chunk-YERKK5B3.js";import{c as zt,d as Pn}from"./chunks/chunk-I57EACSL.js";import"./chunks/chunk-7JZKVC3F.js";import{a as z,b as _t,c as K,d as Cn,e as Nn,f as Lt,g as Rn}from"./chunks/chunk-43E7AR6A.js";import{a as Bt,b as Ze,c as Qe,d as _e,e as Ve,f as ze,g as U,h as ae,i as Ke,j as Wt,k as Rr,l as P,m as Xe,n as Pe,o as Vt,p as Dr,q as rt}from"./chunks/chunk-FUT3X2GJ.js";import{a as M,c as pn,e as xn,f as Mt,g as Gs}from"./chunks/chunk-CPKBPQ2C.js";import{a as St}from"./chunks/chunk-PBOVSFTJ.js";import{a as st}from"./chunks/chunk-I4IRHQDW.js";import"./chunks/chunk-DN2YCFOR.js";import*as Gf from"node:fs";import*as Zf from"node:path";import*as Qf from"node:readline";var On=[{name:"echo",load:async()=>(await import("./chunks/echo-NYDCCFWB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-BQ7FQTN5.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-YXCSED2H.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-Q6ZZ6SQ2.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-74BP5NTG.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-7ZIVFZJX.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-TVQAUQOG.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-TF2NJQIA.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-OMVKM35F.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-76LAHXFR.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-B35EKC2Q.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-WYYTXGVB.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-YKLNXWZI.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-EHXJNW62.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-QKVY3SIO.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-UOTUV25D.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-3KLVOCI2.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-LROLDXHH.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-CVU5V66H.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-CVU5V66H.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-CVU5V66H.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-PXNKNIMY.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-4LVDFHIJ.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-KO7ZE3P7.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-HBOCBBJQ.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-JMHDIJXT.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-URDMZCXL.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-42X6363P.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-DWWA3JTW.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-PVFO6FRY.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-CZTQCNOZ.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-4IZRRT7U.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-YEY7X54W.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-IQRKKT7D.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-JPOQORZF.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-CNUK76JL.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-ZNNNHKSP.js")).split},{name:"column",load:async()=>(await import("./chunks/column-AJFK3TWF.js")).column},{name:"join",load:async()=>(await import("./chunks/join-34DX7YK5.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-L4HKV5PD.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-AWH2KOY7.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-C4CRGDXP.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-TPUFCYF6.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-ZGP6NPGS.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-LUFPVLNW.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-2TSVF4W7.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-2TSVF4W7.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-3R4G6HQY.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-3R4G6HQY.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-3HAU45KT.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-4AMMXFXL.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-OE52K3TM.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-CFCBBWVH.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-CFCBBWVH.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-V7OTAVU5.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-TQ5KOCNW.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-YXZZCUSQ.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-6MQGVWDY.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-DVFE2GSF.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-YGFHQJKX.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-LF7BTSK5.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-X2EAOGV5.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-NNMDHOCN.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-Z6KAYGDK.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-CATBXX76.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-YGSNBVY3.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-4T64QNLS.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-XUMA42ZC.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-HVIDHJ6M.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-4TPGVSBZ.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-DG4BMYM5.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-2I76DUQL.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-B5HDVKW6.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-2GXD4D5K.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-FDPA6EKG.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-FDPA6EKG.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-FDPA6EKG.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(On.push({name:"tar",load:async()=>(await import("./chunks/tar-7HGZIMZD.js")).tarCommand}),On.push({name:"yq",load:async()=>(await import("./chunks/yq-MYZOS2WN.js")).yqCommand}),On.push({name:"xan",load:async()=>(await import("./chunks/xan-WW53ETXT.js")).xanCommand}),On.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-KP42NNIY.js")).sqlite3Command}));var Ks=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ks.push({name:"python3",load:async()=>(await import("./chunks/python3-JCJHSX4Z.js")).python3Command}),Ks.push({name:"python",load:async()=>(await import("./chunks/python3-JCJHSX4Z.js")).pythonCommand}));var Xs=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Xs.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-DJQLXWCS.js")).jsExecCommand}),Xs.push({name:"node",load:async()=>(await import("./chunks/js-exec-DJQLXWCS.js")).nodeStubCommand}));var Xf=[{name:"curl",load:async()=>(await import("./chunks/curl-NHNZ46BU.js")).curlCommand}],Ea=new Map;function _r(e){return{name:e.name,async execute(t,n){let r=Ea.get(e.name);if(r||(r=await Ge.runTrustedAsync(()=>e.load()),Ea.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await import("./chunks/flag-coverage-C7PB2MO7.js");s(n.coverage,e.name,t)}return r.execute(t,n)}}}function ba(e){return(e?On.filter(n=>e.includes(n.name)):On).map(_r)}function Sa(){return Xf.map(_r)}function Aa(){return Ks.map(_r)}function va(){return Xs.map(_r)}var ka=new WeakMap,$a=new WeakSet;function Ys(e){let t=ka.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),ka.set(e,t),$a.add(t)),t}function xa(e){return $a.has(e)}var Pa={maxSourceBytes:67108864,maxExecDepth:64,maxCallDepth:100,maxCommandCount:1e5,maxLoopIterations:1e5,maxAwkIterations:1e5,maxSedIterations:1e5,maxJqIterations:1e7,maxQueryTokens:1e5,maxQueryDepth:1e3,maxQueryElements:1e6,maxAwkParserTokens:1e5,maxAwkParserDepth:256,maxAwkParserOperations:1e6,maxCsvRows:1e6,maxCsvCells:1e7,maxWorkUnits:1e8,maxTraversalEntries:1e6,maxTraversalDepth:1e3,maxTraversalWork:1e6,maxLiveBytes:536870912,maxInputBytes:536870912,maxFileSystemBytes:1073741824,maxDatabaseBytes:1073741824,maxDatabaseResultBytes:268435456,maxArchiveBytes:1073741824,maxArchiveCompressedBytes:536870912,maxArchiveEntryBytes:536870912,maxArchiveEntries:1e6,maxWorkerMessageBytes:67108864,maxExecutionTimeMs:36e5,maxExtensionCleanupTimeMs:100,maxSqliteTimeoutMs:3e4,maxPythonTimeoutMs:3e4,maxJsTimeoutMs:3e4,maxGlobOperations:1e6,maxStringLength:67108864,maxArrayElements:1e6,maxHeredocSize:67108864,maxSubstitutionDepth:50,maxBraceExpansionResults:1e5,maxOutputSize:268435456,maxFileDescriptors:4096,maxSourceDepth:100},Yf={...Pa,maxSourceBytes:8*1024*1024,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,maxExtensionCleanupTimeMs:25,maxGlobOperations:1e5,maxStringLength:10*1024*1024,maxArrayElements:1e5,maxHeredocSize:10*1024*1024,maxBraceExpansionResults:1e4,maxOutputSize:10*1024*1024,maxFileDescriptors:1024,maxQueryTokens:25e3,maxQueryDepth:256,maxQueryElements:1e5,maxAwkParserTokens:25e3,maxAwkParserDepth:128,maxAwkParserOperations:1e5,maxCsvRows:1e5,maxCsvCells:1e6,maxWorkUnits:1e5,maxTraversalEntries:1e5,maxTraversalDepth:256,maxTraversalWork:1e5,maxLiveBytes:64*1024*1024,maxInputBytes:32*1024*1024,maxFileSystemBytes:128*1024*1024,maxDatabaseBytes:64*1024*1024,maxDatabaseResultBytes:16*1024*1024,maxArchiveBytes:128*1024*1024,maxArchiveCompressedBytes:64*1024*1024,maxArchiveEntryBytes:64*1024*1024,maxArchiveEntries:1e5,maxWorkerMessageBytes:16*1024*1024,maxExecutionTimeMs:3e4};function Js(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?Yf:Pa;if(!e)return{...n};let r={maxSourceBytes:e.maxSourceBytes??n.maxSourceBytes,maxExecDepth:e.maxExecDepth??n.maxExecDepth,maxCallDepth:e.maxCallDepth??n.maxCallDepth,maxCommandCount:e.maxCommandCount??n.maxCommandCount,maxLoopIterations:e.maxLoopIterations??n.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??n.maxAwkIterations,maxSedIterations:e.maxSedIterations??n.maxSedIterations,maxJqIterations:e.maxJqIterations??n.maxJqIterations,maxQueryTokens:e.maxQueryTokens??n.maxQueryTokens,maxQueryDepth:e.maxQueryDepth??n.maxQueryDepth,maxQueryElements:e.maxQueryElements??n.maxQueryElements,maxAwkParserTokens:e.maxAwkParserTokens??n.maxAwkParserTokens,maxAwkParserDepth:e.maxAwkParserDepth??n.maxAwkParserDepth,maxAwkParserOperations:e.maxAwkParserOperations??n.maxAwkParserOperations,maxCsvRows:e.maxCsvRows??n.maxCsvRows,maxCsvCells:e.maxCsvCells??n.maxCsvCells,maxWorkUnits:e.maxWorkUnits??n.maxWorkUnits,maxTraversalEntries:e.maxTraversalEntries??n.maxTraversalEntries,maxTraversalDepth:e.maxTraversalDepth??n.maxTraversalDepth,maxTraversalWork:e.maxTraversalWork??n.maxTraversalWork,maxLiveBytes:e.maxLiveBytes??n.maxLiveBytes,maxInputBytes:e.maxInputBytes??n.maxInputBytes,maxFileSystemBytes:e.maxFileSystemBytes??n.maxFileSystemBytes,maxDatabaseBytes:e.maxDatabaseBytes??n.maxDatabaseBytes,maxDatabaseResultBytes:e.maxDatabaseResultBytes??n.maxDatabaseResultBytes,maxArchiveBytes:e.maxArchiveBytes??n.maxArchiveBytes,maxArchiveCompressedBytes:e.maxArchiveCompressedBytes??n.maxArchiveCompressedBytes,maxArchiveEntryBytes:e.maxArchiveEntryBytes??n.maxArchiveEntryBytes,maxArchiveEntries:e.maxArchiveEntries??n.maxArchiveEntries,maxWorkerMessageBytes:e.maxWorkerMessageBytes??n.maxWorkerMessageBytes,maxExecutionTimeMs:e.maxExecutionTimeMs??n.maxExecutionTimeMs,maxExtensionCleanupTimeMs:e.maxExtensionCleanupTimeMs??n.maxExtensionCleanupTimeMs,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??n.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??n.maxPythonTimeoutMs,maxJsTimeoutMs:e.maxJsTimeoutMs??n.maxJsTimeoutMs,maxGlobOperations:e.maxGlobOperations??n.maxGlobOperations,maxStringLength:e.maxStringLength??n.maxStringLength,maxArrayElements:e.maxArrayElements??n.maxArrayElements,maxHeredocSize:e.maxHeredocSize??n.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??n.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??n.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??n.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??n.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??n.maxSourceDepth};for(let s of Object.keys(r)){let i=r[s];if(i!==Number.POSITIVE_INFINITY&&(!Number.isSafeInteger(i)||i<0))throw new RangeError(`${s} must be a non-negative safe integer or positive Infinity`)}return r}function Ca(e){return"load"in e&&typeof e.load=="function"}function Na(e){let t=null,n=null;return{name:e.name,trusted:e.trusted!==!1,async execute(r,s){if(!t){let o=n;o||(o=e.load().then(a=>(t=a,a)),n=o);try{t=await o}catch(a){throw n===o&&(n=null),a}}let i=t;if(!i)throw new Error(`Failed to load command: ${e.name}`);return i.execute(r,s)}}}var Ra=Object.freeze(Object.create(null)),Lr=class{limits;signal;abortOnUnresolvedCommands;commandCount=0;workUnits=0;liveBytes=0;inputBytes=0;outputBytes=0;countersByKind=new Map;bytesByKind=new Map;depthByKind=new Map;cleanupCallbacks=[];poisoned;closed=!1;startedAt=Date.now();unresolvedCommands=new Set;get remainingLiveBytes(){return Math.max(0,this.limits.maxLiveBytes-this.liveBytes)}get outputBytesUsed(){return this.outputBytes}constructor(t,n=void 0,r=!1){this.limits=t,this.signal=n,this.abortOnUnresolvedCommands=r}recordUnresolvedCommand(t){this.unresolvedCommands.add(t)}get unresolvedCommandNames(){return[...this.unresolvedCommands]}fail(t){throw this.poisoned??=t,this.poisoned}poisonAfterAbort(t){this.poisoned??=t}assertUsable(){if(this.poisoned)throw this.poisoned;if(this.closed)throw new Error("execution budget is already closed");this.throwIfAborted()}chargeCommand(){return this.consume("commands",1,"execution")}consumeWork(t=1,n="execution"){return this.consume("work",t,n)}consumeLimited(t,n,r,s=t){this.assertUsable();let i=this.countersByKind.get(t)??0;return(!Number.isSafeInteger(n)||n<0||!Number.isSafeInteger(r)||r<0||n>r-i)&&this.fail(new P(`${s}: ${t} work limit exceeded (${r})`,"iterations")),n>this.limits.maxWorkUnits-this.workUnits&&this.fail(new P(`${s}: aggregate work limit exceeded (${this.limits.maxWorkUnits})`,"iterations")),this.countersByKind.set(t,i+n),this.workUnits+=n,i+n}consumeInput(t,n="execution"){return this.assertUsable(),(!Number.isSafeInteger(t)||t<0||t>this.limits.maxInputBytes-this.inputBytes)&&this.fail(new P(`${n}: aggregate input size limit exceeded (${this.limits.maxInputBytes} bytes)`,"string_length")),this.inputBytes+=t,this.inputBytes}consume(t,n=1,r=t){this.assertUsable();let s=this.countersByKind.get(t)??0,i=t==="commands"?this.commandCount:this.workUnits,o=t==="commands"?this.limits.maxCommandCount:this.limits.maxWorkUnits;(!Number.isSafeInteger(n)||n<0||n>o-i)&&this.fail(new P(t==="commands"?`too many commands executed (>${o}), increase executionLimits.maxCommandCount`:`${r}: ${t} work limit exceeded (${o})`,t==="commands"?"commands":"iterations"));let a=i+n;return t==="commands"?this.commandCount=a:this.workUnits=a,this.countersByKind.set(t,s+n),a}reserveBytes(t,n,r){this.assertUsable();let s=typeof t=="string"?t:"live",i=typeof t=="string"?n:t,o=typeof t=="string"?r??s:n??"execution";(!Number.isSafeInteger(i)||i<0||i>this.limits.maxLiveBytes-this.liveBytes)&&this.fail(new P(`${o}: live byte limit exceeded (${this.limits.maxLiveBytes} bytes)`,"string_length")),this.liveBytes+=i,this.bytesByKind.set(s,(this.bytesByKind.get(s)??0)+i);let a=!1;return{release:()=>{if(a)return;a=!0,this.liveBytes-=i;let l=(this.bytesByKind.get(s)??i)-i;l<=0?this.bytesByKind.delete(s):this.bytesByKind.set(s,l)}}}appendOutput(t,n,r="execution",s=0,i="text"){this.assertUsable();let o=i==="bytes"?n.length:M(n);(!Number.isSafeInteger(s)||s<0||s>o)&&this.fail(new P(`${r}: invalid ${t} accounting`,"output_size"));let a=o-s;return a>this.limits.maxOutputSize-this.outputBytes&&this.fail(new P(`${r}: total output size exceeded (>${this.limits.maxOutputSize} bytes), increase executionLimits.maxOutputSize`,"output_size")),this.outputBytes+=a,o}accountResult(t,n="execution",r=Number.POSITIVE_INFINITY){let s=t.internalOutputAccounting,i=Math.min(s?.stdout??0,r),o=Math.min(s?.stderr??0,Math.max(0,r-i)),a=this.appendOutput("stdout",t.stdout,n,i,t.stdoutKind==="bytes"||t.stdoutEncoding==="binary"?"bytes":"text"),l=this.appendOutput("stderr",t.stderr,n,o);return Object.isExtensible(t)?(t.internalOutputAccounting={stdout:a,stderr:l},t):a===0&&l===0?t:{...t,internalOutputAccounting:{stdout:a,stderr:l}}}relinquishOutput(t,n,r){this.assertUsable(),r!==Ra&&this.fail(new P(`${n}: unauthorized output accounting release`,"output_size")),(!Number.isSafeInteger(t)||t<0||t>this.outputBytes)&&this.fail(new P(`${n}: invalid output accounting release`,"output_size")),this.outputBytes-=t}enterDepth(t,n=this.limits.maxCallDepth,r){this.assertUsable();let s=typeof n=="number"?n:this.limits.maxCallDepth,i=typeof n=="string"?n:r??t,o=this.depthByKind.get(t)??0;o>=s&&this.fail(new P(`${i}: maximum depth (${s}) exceeded`,"recursion")),this.depthByKind.set(t,o+1);let a=!1;return{release:()=>{if(a)return;a=!0;let l=(this.depthByKind.get(t)??1)-1;l<=0?this.depthByKind.delete(t):this.depthByKind.set(t,l)}}}throwIfAborted(t="execution"){this.signal?.aborted&&this.fail(new Xe("",`bash: ${t} aborted
|
|
3
|
+
import{a as Dn,b as In,c as jt}from"./chunks/chunk-O2BCKSMK.js";import{a as Nr}from"./chunks/chunk-3PCPQIUD.js";import{c as Qs,e as wa}from"./chunks/chunk-TW2IJRUF.js";import{a as ma,b as ya,d as Qn,e as Kn}from"./chunks/chunk-QKJAAJ7J.js";import{a as qt}from"./chunks/chunk-K27FY3ES.js";import{a as Ut,b as Ue,c as Zs}from"./chunks/chunk-MROECM42.js";import{a as Xn,b as ga}from"./chunks/chunk-42AMF6EE.js";import{a as he}from"./chunks/chunk-GA5TPRMF.js";import{a as Ir,b as Or}from"./chunks/chunk-GR4ZHKXI.js";import{a as Cr,b as Ge}from"./chunks/chunk-HWI42GQO.js";import"./chunks/chunk-YERKK5B3.js";import{c as zt,d as Pn}from"./chunks/chunk-I57EACSL.js";import"./chunks/chunk-7JZKVC3F.js";import{a as z,b as _t,c as K,d as Cn,e as Nn,f as Lt,g as Rn}from"./chunks/chunk-43E7AR6A.js";import{a as Bt,b as Ze,c as Qe,d as _e,e as Ve,f as ze,g as U,h as ae,i as Ke,j as Wt,k as Rr,l as P,m as Xe,n as Pe,o as Vt,p as Dr,q as rt}from"./chunks/chunk-FUT3X2GJ.js";import{a as M,c as pn,e as xn,f as Mt,g as Gs}from"./chunks/chunk-CPKBPQ2C.js";import{a as St}from"./chunks/chunk-PBOVSFTJ.js";import{a as st}from"./chunks/chunk-I4IRHQDW.js";import"./chunks/chunk-DN2YCFOR.js";import*as Gf from"node:fs";import*as Zf from"node:path";import*as Qf from"node:readline";var On=[{name:"echo",load:async()=>(await import("./chunks/echo-NYDCCFWB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-BQ7FQTN5.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-YXCSED2H.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-Q6ZZ6SQ2.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-74BP5NTG.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-7ZIVFZJX.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-TVQAUQOG.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-NLG5344W.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-OMVKM35F.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-76LAHXFR.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-B35EKC2Q.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-WYYTXGVB.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-YKLNXWZI.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-EHXJNW62.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-QKVY3SIO.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-UOTUV25D.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-3KLVOCI2.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-LROLDXHH.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-CVU5V66H.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-CVU5V66H.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-CVU5V66H.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-PXNKNIMY.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-4LVDFHIJ.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-KO7ZE3P7.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-HBOCBBJQ.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-JMHDIJXT.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-URDMZCXL.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-42X6363P.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-DWWA3JTW.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-PVFO6FRY.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-CZTQCNOZ.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-4IZRRT7U.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-YEY7X54W.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-IQRKKT7D.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-JPOQORZF.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-CNUK76JL.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-ZNNNHKSP.js")).split},{name:"column",load:async()=>(await import("./chunks/column-AJFK3TWF.js")).column},{name:"join",load:async()=>(await import("./chunks/join-34DX7YK5.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-L4HKV5PD.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-AWH2KOY7.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-C4CRGDXP.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-TPUFCYF6.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-ZGP6NPGS.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-LUFPVLNW.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-2TSVF4W7.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-2TSVF4W7.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-3R4G6HQY.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-3R4G6HQY.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-3HAU45KT.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-4AMMXFXL.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-OE52K3TM.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-CFCBBWVH.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-CFCBBWVH.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-V7OTAVU5.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-TQ5KOCNW.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-YXZZCUSQ.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-6MQGVWDY.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-MOJQBZMY.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-RQOWSWYG.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-LF7BTSK5.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-X2EAOGV5.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-NNMDHOCN.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-Z6KAYGDK.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-CATBXX76.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-YGSNBVY3.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-4T64QNLS.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-XUMA42ZC.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-HVIDHJ6M.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-4TPGVSBZ.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-DG4BMYM5.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-2I76DUQL.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-B5HDVKW6.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-2GXD4D5K.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-FDPA6EKG.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-FDPA6EKG.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-FDPA6EKG.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(On.push({name:"tar",load:async()=>(await import("./chunks/tar-7HGZIMZD.js")).tarCommand}),On.push({name:"yq",load:async()=>(await import("./chunks/yq-MYZOS2WN.js")).yqCommand}),On.push({name:"xan",load:async()=>(await import("./chunks/xan-WW53ETXT.js")).xanCommand}),On.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-3EUPHVEZ.js")).sqlite3Command}));var Ks=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ks.push({name:"python3",load:async()=>(await import("./chunks/python3-TMFYDQAP.js")).python3Command}),Ks.push({name:"python",load:async()=>(await import("./chunks/python3-TMFYDQAP.js")).pythonCommand}));var Xs=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Xs.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-5QZZCOR7.js")).jsExecCommand}),Xs.push({name:"node",load:async()=>(await import("./chunks/js-exec-5QZZCOR7.js")).nodeStubCommand}));var Xf=[{name:"curl",load:async()=>(await import("./chunks/curl-NHNZ46BU.js")).curlCommand}],Ea=new Map;function _r(e){return{name:e.name,async execute(t,n){let r=Ea.get(e.name);if(r||(r=await Ge.runTrustedAsync(()=>e.load()),Ea.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await import("./chunks/flag-coverage-FYJ2V7J4.js");s(n.coverage,e.name,t)}return r.execute(t,n)}}}function ba(e){return(e?On.filter(n=>e.includes(n.name)):On).map(_r)}function Sa(){return Xf.map(_r)}function Aa(){return Ks.map(_r)}function va(){return Xs.map(_r)}var ka=new WeakMap,$a=new WeakSet;function Ys(e){let t=ka.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),ka.set(e,t),$a.add(t)),t}function xa(e){return $a.has(e)}var Pa={maxSourceBytes:67108864,maxExecDepth:64,maxCallDepth:100,maxCommandCount:1e5,maxLoopIterations:1e5,maxAwkIterations:1e5,maxSedIterations:1e5,maxJqIterations:1e7,maxQueryTokens:1e5,maxQueryDepth:1e3,maxQueryElements:1e6,maxAwkParserTokens:1e5,maxAwkParserDepth:256,maxAwkParserOperations:1e6,maxCsvRows:1e6,maxCsvCells:1e7,maxWorkUnits:1e8,maxTraversalEntries:1e6,maxTraversalDepth:1e3,maxTraversalWork:1e6,maxLiveBytes:536870912,maxInputBytes:536870912,maxFileSystemBytes:1073741824,maxDatabaseBytes:1073741824,maxDatabaseResultBytes:268435456,maxArchiveBytes:1073741824,maxArchiveCompressedBytes:536870912,maxArchiveEntryBytes:536870912,maxArchiveEntries:1e6,maxWorkerMessageBytes:67108864,maxExecutionTimeMs:36e5,maxExtensionCleanupTimeMs:100,maxSqliteTimeoutMs:3e4,maxPythonTimeoutMs:3e4,maxJsTimeoutMs:3e4,maxGlobOperations:1e6,maxStringLength:67108864,maxArrayElements:1e6,maxHeredocSize:67108864,maxSubstitutionDepth:50,maxBraceExpansionResults:1e5,maxOutputSize:268435456,maxFileDescriptors:4096,maxSourceDepth:100},Yf={...Pa,maxSourceBytes:8*1024*1024,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,maxExtensionCleanupTimeMs:25,maxGlobOperations:1e5,maxStringLength:10*1024*1024,maxArrayElements:1e5,maxHeredocSize:10*1024*1024,maxBraceExpansionResults:1e4,maxOutputSize:10*1024*1024,maxFileDescriptors:1024,maxQueryTokens:25e3,maxQueryDepth:256,maxQueryElements:1e5,maxAwkParserTokens:25e3,maxAwkParserDepth:128,maxAwkParserOperations:1e5,maxCsvRows:1e5,maxCsvCells:1e6,maxWorkUnits:1e5,maxTraversalEntries:1e5,maxTraversalDepth:256,maxTraversalWork:1e5,maxLiveBytes:64*1024*1024,maxInputBytes:32*1024*1024,maxFileSystemBytes:128*1024*1024,maxDatabaseBytes:64*1024*1024,maxDatabaseResultBytes:16*1024*1024,maxArchiveBytes:128*1024*1024,maxArchiveCompressedBytes:64*1024*1024,maxArchiveEntryBytes:64*1024*1024,maxArchiveEntries:1e5,maxWorkerMessageBytes:16*1024*1024,maxExecutionTimeMs:3e4};function Js(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?Yf:Pa;if(!e)return{...n};let r={maxSourceBytes:e.maxSourceBytes??n.maxSourceBytes,maxExecDepth:e.maxExecDepth??n.maxExecDepth,maxCallDepth:e.maxCallDepth??n.maxCallDepth,maxCommandCount:e.maxCommandCount??n.maxCommandCount,maxLoopIterations:e.maxLoopIterations??n.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??n.maxAwkIterations,maxSedIterations:e.maxSedIterations??n.maxSedIterations,maxJqIterations:e.maxJqIterations??n.maxJqIterations,maxQueryTokens:e.maxQueryTokens??n.maxQueryTokens,maxQueryDepth:e.maxQueryDepth??n.maxQueryDepth,maxQueryElements:e.maxQueryElements??n.maxQueryElements,maxAwkParserTokens:e.maxAwkParserTokens??n.maxAwkParserTokens,maxAwkParserDepth:e.maxAwkParserDepth??n.maxAwkParserDepth,maxAwkParserOperations:e.maxAwkParserOperations??n.maxAwkParserOperations,maxCsvRows:e.maxCsvRows??n.maxCsvRows,maxCsvCells:e.maxCsvCells??n.maxCsvCells,maxWorkUnits:e.maxWorkUnits??n.maxWorkUnits,maxTraversalEntries:e.maxTraversalEntries??n.maxTraversalEntries,maxTraversalDepth:e.maxTraversalDepth??n.maxTraversalDepth,maxTraversalWork:e.maxTraversalWork??n.maxTraversalWork,maxLiveBytes:e.maxLiveBytes??n.maxLiveBytes,maxInputBytes:e.maxInputBytes??n.maxInputBytes,maxFileSystemBytes:e.maxFileSystemBytes??n.maxFileSystemBytes,maxDatabaseBytes:e.maxDatabaseBytes??n.maxDatabaseBytes,maxDatabaseResultBytes:e.maxDatabaseResultBytes??n.maxDatabaseResultBytes,maxArchiveBytes:e.maxArchiveBytes??n.maxArchiveBytes,maxArchiveCompressedBytes:e.maxArchiveCompressedBytes??n.maxArchiveCompressedBytes,maxArchiveEntryBytes:e.maxArchiveEntryBytes??n.maxArchiveEntryBytes,maxArchiveEntries:e.maxArchiveEntries??n.maxArchiveEntries,maxWorkerMessageBytes:e.maxWorkerMessageBytes??n.maxWorkerMessageBytes,maxExecutionTimeMs:e.maxExecutionTimeMs??n.maxExecutionTimeMs,maxExtensionCleanupTimeMs:e.maxExtensionCleanupTimeMs??n.maxExtensionCleanupTimeMs,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??n.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??n.maxPythonTimeoutMs,maxJsTimeoutMs:e.maxJsTimeoutMs??n.maxJsTimeoutMs,maxGlobOperations:e.maxGlobOperations??n.maxGlobOperations,maxStringLength:e.maxStringLength??n.maxStringLength,maxArrayElements:e.maxArrayElements??n.maxArrayElements,maxHeredocSize:e.maxHeredocSize??n.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??n.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??n.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??n.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??n.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??n.maxSourceDepth};for(let s of Object.keys(r)){let i=r[s];if(i!==Number.POSITIVE_INFINITY&&(!Number.isSafeInteger(i)||i<0))throw new RangeError(`${s} must be a non-negative safe integer or positive Infinity`)}return r}function Ca(e){return"load"in e&&typeof e.load=="function"}function Na(e){let t=null,n=null;return{name:e.name,trusted:e.trusted!==!1,async execute(r,s){if(!t){let o=n;o||(o=e.load().then(a=>(t=a,a)),n=o);try{t=await o}catch(a){throw n===o&&(n=null),a}}let i=t;if(!i)throw new Error(`Failed to load command: ${e.name}`);return i.execute(r,s)}}}var Ra=Object.freeze(Object.create(null)),Lr=class{limits;signal;abortOnUnresolvedCommands;commandCount=0;workUnits=0;liveBytes=0;inputBytes=0;outputBytes=0;countersByKind=new Map;bytesByKind=new Map;depthByKind=new Map;cleanupCallbacks=[];poisoned;closed=!1;startedAt=Date.now();unresolvedCommands=new Set;get remainingLiveBytes(){return Math.max(0,this.limits.maxLiveBytes-this.liveBytes)}get outputBytesUsed(){return this.outputBytes}constructor(t,n=void 0,r=!1){this.limits=t,this.signal=n,this.abortOnUnresolvedCommands=r}recordUnresolvedCommand(t){this.unresolvedCommands.add(t)}get unresolvedCommandNames(){return[...this.unresolvedCommands]}fail(t){throw this.poisoned??=t,this.poisoned}poisonAfterAbort(t){this.poisoned??=t}assertUsable(){if(this.poisoned)throw this.poisoned;if(this.closed)throw new Error("execution budget is already closed");this.throwIfAborted()}chargeCommand(){return this.consume("commands",1,"execution")}consumeWork(t=1,n="execution"){return this.consume("work",t,n)}consumeLimited(t,n,r,s=t){this.assertUsable();let i=this.countersByKind.get(t)??0;return(!Number.isSafeInteger(n)||n<0||!Number.isSafeInteger(r)||r<0||n>r-i)&&this.fail(new P(`${s}: ${t} work limit exceeded (${r})`,"iterations")),n>this.limits.maxWorkUnits-this.workUnits&&this.fail(new P(`${s}: aggregate work limit exceeded (${this.limits.maxWorkUnits})`,"iterations")),this.countersByKind.set(t,i+n),this.workUnits+=n,i+n}consumeInput(t,n="execution"){return this.assertUsable(),(!Number.isSafeInteger(t)||t<0||t>this.limits.maxInputBytes-this.inputBytes)&&this.fail(new P(`${n}: aggregate input size limit exceeded (${this.limits.maxInputBytes} bytes)`,"string_length")),this.inputBytes+=t,this.inputBytes}consume(t,n=1,r=t){this.assertUsable();let s=this.countersByKind.get(t)??0,i=t==="commands"?this.commandCount:this.workUnits,o=t==="commands"?this.limits.maxCommandCount:this.limits.maxWorkUnits;(!Number.isSafeInteger(n)||n<0||n>o-i)&&this.fail(new P(t==="commands"?`too many commands executed (>${o}), increase executionLimits.maxCommandCount`:`${r}: ${t} work limit exceeded (${o})`,t==="commands"?"commands":"iterations"));let a=i+n;return t==="commands"?this.commandCount=a:this.workUnits=a,this.countersByKind.set(t,s+n),a}reserveBytes(t,n,r){this.assertUsable();let s=typeof t=="string"?t:"live",i=typeof t=="string"?n:t,o=typeof t=="string"?r??s:n??"execution";(!Number.isSafeInteger(i)||i<0||i>this.limits.maxLiveBytes-this.liveBytes)&&this.fail(new P(`${o}: live byte limit exceeded (${this.limits.maxLiveBytes} bytes)`,"string_length")),this.liveBytes+=i,this.bytesByKind.set(s,(this.bytesByKind.get(s)??0)+i);let a=!1;return{release:()=>{if(a)return;a=!0,this.liveBytes-=i;let l=(this.bytesByKind.get(s)??i)-i;l<=0?this.bytesByKind.delete(s):this.bytesByKind.set(s,l)}}}appendOutput(t,n,r="execution",s=0,i="text"){this.assertUsable();let o=i==="bytes"?n.length:M(n);(!Number.isSafeInteger(s)||s<0||s>o)&&this.fail(new P(`${r}: invalid ${t} accounting`,"output_size"));let a=o-s;return a>this.limits.maxOutputSize-this.outputBytes&&this.fail(new P(`${r}: total output size exceeded (>${this.limits.maxOutputSize} bytes), increase executionLimits.maxOutputSize`,"output_size")),this.outputBytes+=a,o}accountResult(t,n="execution",r=Number.POSITIVE_INFINITY){let s=t.internalOutputAccounting,i=Math.min(s?.stdout??0,r),o=Math.min(s?.stderr??0,Math.max(0,r-i)),a=this.appendOutput("stdout",t.stdout,n,i,t.stdoutKind==="bytes"||t.stdoutEncoding==="binary"?"bytes":"text"),l=this.appendOutput("stderr",t.stderr,n,o);return Object.isExtensible(t)?(t.internalOutputAccounting={stdout:a,stderr:l},t):a===0&&l===0?t:{...t,internalOutputAccounting:{stdout:a,stderr:l}}}relinquishOutput(t,n,r){this.assertUsable(),r!==Ra&&this.fail(new P(`${n}: unauthorized output accounting release`,"output_size")),(!Number.isSafeInteger(t)||t<0||t>this.outputBytes)&&this.fail(new P(`${n}: invalid output accounting release`,"output_size")),this.outputBytes-=t}enterDepth(t,n=this.limits.maxCallDepth,r){this.assertUsable();let s=typeof n=="number"?n:this.limits.maxCallDepth,i=typeof n=="string"?n:r??t,o=this.depthByKind.get(t)??0;o>=s&&this.fail(new P(`${i}: maximum depth (${s}) exceeded`,"recursion")),this.depthByKind.set(t,o+1);let a=!1;return{release:()=>{if(a)return;a=!0;let l=(this.depthByKind.get(t)??1)-1;l<=0?this.depthByKind.delete(t):this.depthByKind.set(t,l)}}}throwIfAborted(t="execution"){this.signal?.aborted&&this.fail(new Xe("",`bash: ${t} aborted
|
|
4
4
|
`)),Date.now()-this.startedAt>this.limits.maxExecutionTimeMs&&this.fail(new Xe("",`bash: ${t} exceeded execution deadline (${this.limits.maxExecutionTimeMs}ms)
|
|
5
5
|
`))}remainingTimeMs(){return Math.max(0,this.limits.maxExecutionTimeMs-(Date.now()-this.startedAt))}registerCleanup(t){this.assertUsable(),this.cleanupCallbacks.push(t);let n=!0;return()=>{if(!n)return;n=!1;let r=this.cleanupCallbacks.indexOf(t);r>=0&&this.cleanupCallbacks.splice(r,1)}}async close(){if(this.closed)return;this.closed=!0;let t=[],n=Date.now()+this.limits.maxExtensionCleanupTimeMs;for(let r=this.cleanupCallbacks.length-1;r>=0;r--)try{let s=n-Date.now();if(s<=0){t.push(new Error("execution cleanup grace period exceeded"));break}let i,o=await Promise.race([Promise.resolve().then(this.cleanupCallbacks[r]).then(()=>({ok:!0}),a=>({ok:!1,error:a})),new Promise(a=>{i=Qn(()=>a({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(Kn(i),!o.ok&&(t.push(o.error),Date.now()>=n))break}catch(s){t.push(s)}if(this.cleanupCallbacks.length=0,this.depthByKind.clear(),this.bytesByKind.clear(),this.liveBytes=0,t.length>0)throw new AggregateError(t,"execution cleanup failed")}assertExecDepth(t){this.assertUsable(),t>this.limits.maxExecDepth&&this.fail(new P(`maximum nested execution depth (${this.limits.maxExecDepth}) exceeded`,"recursion"))}};function Da(e){let t=Object.create(null);return Object.defineProperties(t,{remainingLiveBytes:{enumerable:!0,get:()=>e.remainingLiveBytes},consumeWork:{enumerable:!0,value:e.consumeWork.bind(e)},consumeLimited:{enumerable:!0,value:e.consumeLimited.bind(e)},consumeInput:{enumerable:!0,value:e.consumeInput.bind(e)},reserveBytes:{enumerable:!0,value:e.reserveBytes.bind(e)},enterDepth:{enumerable:!0,value:e.enterDepth.bind(e)},throwIfAborted:{enumerable:!0,value:e.throwIfAborted.bind(e)},remainingTimeMs:{enumerable:!0,value:e.remainingTimeMs.bind(e)},registerCleanup:{enumerable:!0,value:e.registerCleanup.bind(e)}}),Object.freeze(t)}function Ia(e,t,n="pipeline"){e.relinquishOutput(t,n,Ra)}var hn=new TextEncoder;function Jf(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var vt=class{data=new Map;entryIdentities=new WeakMap;nextEntryIdentity=1;maxTotalBytes;retainedBytes=0;contentReferences=new WeakMap;materializedContent(t){return t?.type==="file"&&"content"in t?t.content:null}storedByteLength(t){return t===null?0:t instanceof Uint8Array?t.byteLength:M(t)}wouldReleaseBytes(t){let n=this.materializedContent(t);return n===null?0:n instanceof Uint8Array?this.contentReferences.get(n)===1?n.byteLength:0:this.storedByteLength(n)}assertCanAllocate(t,n){let r=this.wouldReleaseBytes(this.data.get(t));if(!Number.isSafeInteger(n)||n<0||n>this.maxTotalBytes-this.retainedBytes+r)throw new Error(`ENOSPC: in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`)}setEntry(t,n){let r=this.data.get(t),s=this.materializedContent(r),i=this.materializedContent(n);if(s===i){this.data.set(t,n);return}let o=this.wouldReleaseBytes(r),a=i instanceof Uint8Array?this.contentReferences.has(i)?0:i.byteLength:this.storedByteLength(i);if(a>this.maxTotalBytes-this.retainedBytes+o)throw new Error(`ENOSPC: in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`);if(s instanceof Uint8Array){let l=this.contentReferences.get(s)??0;l<=1?this.contentReferences.delete(s):this.contentReferences.set(s,l-1)}i instanceof Uint8Array&&this.contentReferences.set(i,(this.contentReferences.get(i)??0)+1),this.retainedBytes+=a-o,this.data.set(t,n)}deleteEntry(t){let n=this.data.get(t);if(!n)return!1;let r=this.materializedContent(n),s=this.wouldReleaseBytes(n);if(r instanceof Uint8Array){let i=this.contentReferences.get(r)??0;i<=1?this.contentReferences.delete(r):this.contentReferences.set(r,i-1)}return this.retainedBytes-=s,this.data.delete(t)}contentByteLength(t,n){if(t instanceof Uint8Array)return t.byteLength;if(n==="hex")return Math.floor(t.length/2);if(n==="base64"){let r=t.endsWith("==")?2:t.endsWith("=")?1:0;return Math.max(0,Math.floor(t.length*3/4)-r)}return n==="binary"||n==="latin1"?t.length:M(t)}identityFor(t){let n=this.entryIdentities.get(t);return n||(n=`memfs:${this.nextEntryIdentity++}`,this.entryIdentities.set(t,n)),n}constructor(t,n={}){if(this.maxTotalBytes=n.maxTotalBytes??1024*1024*1024,!Number.isSafeInteger(this.maxTotalBytes)||this.maxTotalBytes<0)throw new Error("InMemoryFs: invalid maxTotalBytes");if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[r,s]of Object.entries(t))typeof s=="function"?this.writeFileLazy(r,s):Jf(s)?this.writeFileSync(r,s.content,void 0,{mode:s.mode,mtime:s.mtime}):this.writeFileSync(r,s)}ensureParentDirs(t){let n=Cn(t);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,n,r,s){K(t,"write");let i=z(t);this.ensureParentDirs(i);let o=jt(r);this.assertCanAllocate(i,this.contentByteLength(n,o));let a=Dn(n,o);this.setEntry(i,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}writeFileLazy(t,n,r){K(t,"write");let s=z(t);this.ensureParentDirs(s),this.setEntry(s,{type:"file",lazy:n,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,n){let r=await n.lazy(),s=typeof r=="string"?hn.encode(r):r,i={type:"file",content:s,mode:n.mode,mtime:n.mtime};return this.assertCanAllocate(t,s.byteLength),this.setEntry(t,i),i}async readFile(t,n){let r=await this.readFileBuffer(t),s=jt(n);return In(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return In(n,"binary")}async readFileBuffer(t){K(t,"open");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);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 s=await this.materializeLazy(n,r);return s.content instanceof Uint8Array?s.content:hn.encode(s.content)}return r.content instanceof Uint8Array?r.content:hn.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){K(t,"append");let s=z(t),i=this.data.get(s);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=jt(r),a=this.contentByteLength(n,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(s,l));let u="content"in l&&l.content instanceof Uint8Array?l.content:hn.encode("content"in l?l.content:"");this.assertCanAllocate(s,u.byteLength+a);let c=Dn(n,o),f=new Uint8Array(u.length+c.length);f.set(u),f.set(c,u.length),this.setEntry(s,{type:"file",content:f,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,n,r)}async exists(t){if(t.includes("\0"))return!1;try{let n=this.resolvePathWithSymlinks(t);return this.data.has(n)}catch{return!1}}async stat(t){K(t,"stat");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=hn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}async lstat(t){K(t,"lstat");let n=this.resolveIntermediateSymlinks(t),r=this.data.get(n);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(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=hn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}resolveIntermediateSymlinks(t){let n=z(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];s=`${s}/${a}`;let l=this.data.get(s),u=0,c=40;for(;l&&l.type==="symlink"&&u<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(s),s=Rn(s,l.target),l=this.data.get(s),u++}if(u>=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let n=z(t);if(n==="/")return"/";let r=n.slice(1).split("/"),s="",i=new Set;for(let o of r){s=`${s}/${o}`;let a=this.data.get(s),l=0,u=40;for(;a&&a.type==="symlink"&&l<u;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(s),s=Rn(s,a.target),a=this.data.get(s),l++}if(l>=u)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return s}async mkdir(t,n){this.mkdirSync(t,n)}mkdirSync(t,n){K(t,"mkdir");let r=z(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let s=Cn(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){K(t,"scandir");let n=z(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let s=new Set;for(;r&&r.type==="symlink";){if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(n),n=Rn(n,r.target),r=this.data.get(n)}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=n==="/"?"/":`${n}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==n&&a.startsWith(i)){let u=a.slice(i.length),c=u.split("/")[0];c&&!u.includes("/",c.length)&&!o.has(c)&&o.set(c,{name:c,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,n){K(t,"rm");let r=z(t),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(s.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=Lt(r,o);await this.rm(a,n)}}}this.deleteEntry(r)}async cp(t,n,r){K(t,"cp"),K(n,"cp");let s=z(t),i=z(n),o=this.data.get(s);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?o.content.byteLength:hn.encode(o.content).byteLength;this.assertCanAllocate(i,a);let l=o.content instanceof Uint8Array?new Uint8Array(o.content):o.content;this.setEntry(i,{...o,content:l})}else this.setEntry(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}'`);if(_t(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(s);for(let l of a){let u=Lt(s,l),c=Lt(i,l);await this.cp(u,c,r)}}}async mv(t,n){K(t,"mv"),K(n,"mv");let r=z(t),s=z(n);if(r===s)return;let i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(i.type==="directory"&&_t(r,s))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);if(i.type==="directory"){await this.mkdir(s,{recursive:!0});let o=await this.readdir(r);for(let a of o)await this.mv(Lt(r,a),Lt(s,a));this.deleteEntry(r);return}this.ensureParentDirs(s),this.setEntry(s,i),this.deleteEntry(r)}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,n){return Nn(t,n)}async chmod(t,n){K(t,"chmod");let r=z(t),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);s.mode=n}async symlink(t,n){K(n,"symlink");let r=z(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,n){K(t,"link"),K(n,"link");let r=z(t),s=z(n),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(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let o=i;"lazy"in o&&(o=await this.materializeLazy(r,o)),this.ensureParentDirs(s);let a={type:"file",content:o.content,mode:o.mode,mtime:o.mtime};this.entryIdentities.set(a,this.identityFor(o)),this.setEntry(s,a)}async readlink(t){K(t,"readlink");let n=z(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){K(t,"realpath");let n=this.resolvePathWithSymlinks(t);if(!this.data.has(n))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return n}async utimes(t,n,r){K(t,"utimes");let s=z(t),i=this.resolvePathWithSymlinks(s),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=r}};var _a="5.1.0(1)-release",La="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function ti(e){let{pid:t,ppid:n,uid:r,gid:s}=e;return`Name: bash
|
|
6
6
|
State: R (running)
|
|
@@ -793,7 +793,7 @@ sys 0m0.000s
|
|
|
793
793
|
`)}})}async executeConditionalCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),nt(this.ctx,t.redirections,"",async()=>{try{let n=await rn(this.ctx,t.expression),r=ge(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){let r=n instanceof ae?1:2;return _(`bash: conditional expression: ${n.message}
|
|
794
794
|
`,r)}})}};function aa(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function Mm(e){let t=aa(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var Bm=3;function Df(e){let t=e;for(let n=0;n<Bm;n++){if(t.includes("\\")||t.includes(";")||/%(?![0-9a-f]{2})/i.test(t))return!0;let r=t.toLowerCase();if(r.includes("%2f")||r.includes("%2e")||r.includes("%5c")||r.includes("%3b"))return!0;let s;try{s=decodeURIComponent(t)}catch{return!0}if(s===t)return!1;t=s}return t.includes("%")}function Wm(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function la(e,t){let n=aa(e);if(!n)return!1;let r=Mm(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&Df(n.pathname)?!1:Wm(n.pathname,r.pathPrefix)}function If(e){return typeof e=="string"?e:e.url}function Of(e,t){return!t||t.length===0?!1:t.some(n=>la(e,If(n)))}function ua(e){let t=Vm(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=_f(t);if(n)return Bs(n);let r=Um(t);return r?qm(r):!1}function Vm(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function zm(e){if(!e)return null;let t=10,n=e;if(n.startsWith("0x")||n.startsWith("0X")?(t=16,n=n.slice(2)):n.length>1&&n.startsWith("0")&&(t=8),!n||t===16&&!/^[0-9a-fA-F]+$/.test(n)||t===10&&!/^\d+$/.test(n)||t===8&&!/^[0-7]+$/.test(n))return null;let r=Number.parseInt(n,t);return!Number.isFinite(r)||r<0?null:r}function _f(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>zm(l));if(n.some(l=>l===null))return null;let r=n;if(t.length===1){let l=r[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,u]=r;return l>255||u>16777215?null:[l,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[l,u,c]=r;return l>255||u>255||c>65535?null:[l,u,c>>>8&255,c&255]}let[s,i,o,a]=r;return s>255||i>255||o>255||a>255?null:[s,i,o,a]}function Um(e){let t=e,n=null;if(t.includes(".")){let m=t.lastIndexOf(":");if(m<0)return null;let E=t.slice(m+1),S=_f(E);if(!S)return null;n=S,t=t.slice(0,m)}let r=t.includes("::")?t.split("::").length-1:0;if(r>1)return null;let[s,i]=t.split("::"),o=s?s.split(":").filter(Boolean):[],a=i?i.split(":").filter(Boolean):[],l=m=>/^[0-9a-f]{1,4}$/i.test(m)?Number.parseInt(m,16):null,u=o.map(l),c=a.map(l);if(u.some(m=>m===null)||c.some(m=>m===null))return null;let f=n?2:0,d=u.length+c.length+f,p=0;if(r===1){if(p=8-d,p<0)return null}else if(d!==8)return null;let h=[...u,...new Array(p).fill(0),...c];return n&&(h.push(n[0]<<8|n[1]),h.push(n[2]<<8|n[3])),h.length===8?h:null}function Bs(e){let[t,n]=e;return t===127||t===10||t===172&&n>=16&&n<=31||t===192&&n===168||t===169&&n===254||t===0||t===100&&n>=64&&n<=127||t===198&&(n===18||n===19)||t===192&&n===0&&e[2]===0||t===192&&n===0&&e[2]===2||t===198&&n===51&&e[2]===100||t===203&&n===0&&e[2]===113||t>=240}function qm(e){if(e.every(s=>s===0)||e.slice(0,7).every(s=>s===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Bs(s)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Bs(s)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let s=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return Bs(s)}return!1}function Lf(e){let t=[];for(let n of e){if(typeof n!="string"&&(n===null||typeof n!="object"||!("url"in n)||typeof n.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let r=If(n);if(!aa(r)){t.push(`Invalid URL in allow-list: "${r}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(r);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${r}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${r}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&Df(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${r}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${r}"`)}return t}var Et=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},Zn=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},dn=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Ws=class extends Error{constructor(t,n){super(`HTTP method '${t}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}},$n=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var jm=20,Hm=3e4,Gm=10485760,Zm=["GET","HEAD"],Ar;typeof __BROWSER__<"u"&&__BROWSER__?Ar=null:(Ar=import("./chunks/dist-5MWO25Y4.js"),Ar.catch(()=>{}));var Qm=new Set(["GET","HEAD","OPTIONS"]),Km=new Set([301,302,303,307,308]);function vr(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function Xm(e){if(e?.aborted)throw vr(e)}function fa(e){let t=e.allowedUrlPrefixes??[];if(e._dnsResolve)throw new Error("NetworkConfig._dnsResolve is no longer supported: DNS resolution is performed by guarded-fetch and cannot be overridden");if(e._createConnectionOwner)throw new Error("NetworkConfig._createConnectionOwner is no longer supported: connect-time IP pinning is performed by guarded-fetch and cannot be overridden");let n=e._fetch;if(!e.dangerouslyAllowFullInternetAccess){let b=Lf(t);if(b.length>0)throw new Error(`Invalid network allow-list:
|
|
795
795
|
${b.join(`
|
|
796
|
-
`)}`)}let r=[];for(let b of t)typeof b=="object"&&b.transform&&b.transform.length>0&&r.push(b);function s(b){if(r.length===0)return null;let A=null;for(let k of r)if(la(b,k.url)&&k.transform){A||(A=new Headers);for(let v of k.transform)for(let[x,R]of Object.entries(v.headers))A.set(x,R)}return A}if(e.maxRedirects!==void 0&&(!Number.isSafeInteger(e.maxRedirects)||e.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let i=e.maxRedirects??jm,o=e.timeoutMs??Hm,a=e.maxResponseSize??Gm,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Zm,u=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),c=[];for(let b of t){let A=typeof b=="string"?b:b.url;try{c.push(new URL(A).hostname)}catch{}}function f(b){try{return new URL(b).hostname||"localhost.invalid"}catch{return"localhost.invalid"}}function d(b){return e.dangerouslyAllowFullInternetAccess?u?{allowedHosts:void 0,skipSsrfCheckForAllowedHosts:void 0}:{allowedHosts:[f(b)],skipSsrfCheckForAllowedHosts:!0}:{allowedHosts:c,skipSsrfCheckForAllowedHosts:!u}}function p(b){try{return ua(new URL(b).hostname)}catch{return!1}}async function h(b,A){let k={method:A.method,headers:A.headers,signal:A.signal,redirect:"manual"};return A.body!==void 0&&(k.body=A.body),await(n??globalThis.fetch)(b,k)}function m(b){if(!e.dangerouslyAllowFullInternetAccess&&!Of(b,t))throw new Et(b)}function E(b){if(!u)return;let A;try{A=new URL(b)}catch{throw new Et(b,"invalid URL")}if(ua(A.hostname))throw new Et(b,"private/loopback IP address blocked")}function S(b){if(e.dangerouslyAllowFullInternetAccess)return;let A=b.toUpperCase();if(!l.includes(A))throw new Ws(A,l)}function g(b,A,k,v){if(!k.isGuardedFetchError(b))return b;let x=b,{onRedirectHop:R,subReason:$}=v;switch(x.code){case"host_not_allowed":case"protocol_not_allowed":return R?new dn(A):new Et(A);case"hostname_unsafe":return R?new dn(A):new Et(A,$==="dns_resolution_failed"?"DNS resolution failed for private IP check":"hostname resolves to private/loopback IP address");case"redirect_to_unsafe_host":return new dn(A);case"too_many_redirects":return new Zn(i);case"response_too_large":return new $n(a);default:return b}}async function y(b,A={}){let k=A.method?.toUpperCase()??"GET",v=A.followRedirects??!0;if(A.maxRedirects!==void 0&&(!Number.isSafeInteger(A.maxRedirects)||A.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let x=A.maxRedirects??i,R=Math.min(i,x),$=A.timeoutMs!==void 0?Math.min(A.timeoutMs,o):o,C=new AbortController,D=ma(()=>C.abort(new DOMException("The operation was aborted","AbortError")),$),B=Nr(A.signal,C.signal);try{m(b),E(b),S(k);let G=Ar?await Ar:null,N=b,W=0,V=[],I=k,O=A.body,F=A.headers,ne=!1;for(;;){Xm(B.signal);let Q=await Ge.runTrustedAsync(async()=>{let Oe=F;if(ne&&Oe){let Ot=Oe instanceof Headers?new Headers(Oe):new Headers(Oe);Ot.delete("authorization"),Ot.delete("cookie"),Oe=Ot}let ct=s(N),It=Jm(Oe,ct),ft={method:I,headers:It,signal:B.signal,followRedirects:!1,timeoutMs:$,sanitizeHeaders:!1};if(O&&!Qm.has(I)&&(ft.body=O),Object.assign(ft,d(N)),!G||p(N)){if(u)throw new Et(N,"DNS pinning unavailable for private IP enforcement");return await h(N,ft)}u?n&&(ft.fetch=n):(ft.fetch=n??globalThis.fetch,ft.dispatcher=null);let dt;ft.onUrlBlocked=Ot=>{dt=Ot.subReason};try{return await G.guardedFetch(N,ft)}catch(Ot){throw g(Ot,N,G,{onRedirectHop:W>0,subReason:dt})}});if(Km.has(Q.status)&&v){let Oe=Q.headers.get("location");if(!Oe)return await Tf(Q,N,a,B.signal,V);V.push({status:Q.status,statusText:Q.statusText,headers:Ff(Q.headers)});let ct=new URL(Oe,N).href;await ca(Ym(Q),B.signal);try{m(ct),E(ct)}catch(dt){throw B.signal?.aborted?vr(B.signal):dt instanceof Et?new dn(ct):dt}let It=Q.status;if(((It===301||It===302)&&I==="POST"||It===303&&I!=="GET"&&I!=="HEAD")&&(I="GET",O=void 0,S(I)),new URL(ct).origin!==new URL(N).origin&&(ne=!0),W++,W>R)throw new Zn(R);N=ct;continue}return await Tf(Q,N,a,B.signal,V)}}finally{ya(D),B.cleanup()}}return y}async function ca(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),vr(t);let n,r=new Promise((s,i)=>{n=()=>i(vr(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function Ym(e){e.body&&!e.body.locked&&await e.body.cancel()}function Jm(e,t){if(!e&&!t)return;if(!t)return e;let n=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,s]of t)n.set(r,s);return n}function Ff(e){let t=Object.create(null);return e.forEach((n,r)=>{t[r.toLowerCase()]=n}),t}async function Tf(e,t,n,r,s){let i=Ff(e.headers);if(n>0){let l=e.headers.get("content-length");if(l){let u=parseInt(l,10);if(!Number.isNaN(u)&&u>n)throw new $n(n)}}let o;if(n>0&&e.body){let l=e.body.getReader(),u=[],c=0;try{for(;;){let{done:d,value:p}=await ca(l.read(),r);if(d)break;if(p){if(c+=p.byteLength,c>n)throw await l.cancel(),new $n(n);u.push(p)}}}catch(d){throw r?.aborted&&await l.cancel(vr(r)).catch(()=>{}),d}o=new Uint8Array(c);let f=0;for(let d of u)o.set(d,f),f+=d.byteLength}else{let l=await ca(e.arrayBuffer(),r);if(n>0&&l.byteLength>n)throw new $n(n);o=new Uint8Array(l)}let a={status:e.status,statusText:e.statusText,headers:i,body:o,url:t};return s&&s.length>0&&(a.redirectChain=s),a}function Vs(e,t){if(e.length>t||M(e)>t)throw new P(`script input size limit exceeded (${t} bytes)`,"string_length")}var zs=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;abortOnUnresolvedCommands=!1;invokeToolFn;transformPlugins=[];state;constructor(t={}){this.limits=Js({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}},t.executionLimitProfile);let n=t.fs??new vt(t.files,{maxTotalBytes:this.limits.maxFileSystemBytes});this.fs=n,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),s=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
|
|
796
|
+
`)}`)}let r=[];for(let b of t)typeof b=="object"&&b.transform&&b.transform.length>0&&r.push(b);function s(b){if(r.length===0)return null;let A=null;for(let k of r)if(la(b,k.url)&&k.transform){A||(A=new Headers);for(let v of k.transform)for(let[x,R]of Object.entries(v.headers))A.set(x,R)}return A}if(e.maxRedirects!==void 0&&(!Number.isSafeInteger(e.maxRedirects)||e.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let i=e.maxRedirects??jm,o=e.timeoutMs??Hm,a=e.maxResponseSize??Gm,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Zm,u=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),c=[];for(let b of t){let A=typeof b=="string"?b:b.url;try{c.push(new URL(A).hostname)}catch{}}function f(b){try{return new URL(b).hostname||"localhost.invalid"}catch{return"localhost.invalid"}}function d(b){return e.dangerouslyAllowFullInternetAccess?u?{allowedHosts:void 0,skipSsrfCheckForAllowedHosts:void 0}:{allowedHosts:[f(b)],skipSsrfCheckForAllowedHosts:!0}:{allowedHosts:c,skipSsrfCheckForAllowedHosts:!u}}function p(b){try{return ua(new URL(b).hostname)}catch{return!1}}async function h(b,A){let k={method:A.method,headers:A.headers,signal:A.signal,redirect:"manual"};return A.body!==void 0&&(k.body=A.body),await(n??globalThis.fetch)(b,k)}function m(b){if(!e.dangerouslyAllowFullInternetAccess&&!Of(b,t))throw new Et(b)}function E(b){if(!u)return;let A;try{A=new URL(b)}catch{throw new Et(b,"invalid URL")}if(ua(A.hostname))throw new Et(b,"private/loopback IP address blocked")}function S(b){if(e.dangerouslyAllowFullInternetAccess)return;let A=b.toUpperCase();if(!l.includes(A))throw new Ws(A,l)}function g(b,A,k,v){if(!k.isGuardedFetchError(b))return b;let x=b,{onRedirectHop:R,subReason:$}=v;switch(x.code){case"host_not_allowed":case"protocol_not_allowed":return R?new dn(A):new Et(A);case"hostname_unsafe":return R?new dn(A):new Et(A,$==="dns_resolution_failed"?"DNS resolution failed for private IP check":"hostname resolves to private/loopback IP address");case"redirect_to_unsafe_host":return new dn(A);case"too_many_redirects":return new Zn(i);case"response_too_large":return new $n(a);default:return b}}async function y(b,A={}){let k=A.method?.toUpperCase()??"GET",v=A.followRedirects??!0;if(A.maxRedirects!==void 0&&(!Number.isSafeInteger(A.maxRedirects)||A.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let x=A.maxRedirects??i,R=Math.min(i,x),$=A.timeoutMs!==void 0?Math.min(A.timeoutMs,o):o,C=new AbortController,D=ma(()=>C.abort(new DOMException("The operation was aborted","AbortError")),$),B=Nr(A.signal,C.signal);try{m(b),E(b),S(k);let G=Ar?await Ar:null,N=b,W=0,V=[],I=k,O=A.body,F=A.headers,ne=!1;for(;;){Xm(B.signal);let Q=await Ge.runTrustedAsync(async()=>{let Oe=F;if(ne&&Oe){let Ot=Oe instanceof Headers?new Headers(Oe):new Headers(Oe);Ot.delete("authorization"),Ot.delete("cookie"),Oe=Ot}let ct=s(N),It=Jm(Oe,ct),ft={method:I,headers:It,signal:B.signal,followRedirects:!1,timeoutMs:$,sanitizeHeaders:!1};if(O&&!Qm.has(I)&&(ft.body=O),Object.assign(ft,d(N)),!G||p(N)){if(u)throw new Et(N,"DNS pinning unavailable for private IP enforcement");return await h(N,ft)}u?n&&(ft.fetch=n):(ft.fetch=n??globalThis.fetch,ft.dispatcher=null);let dt;ft.onUrlBlocked=Ot=>{dt=Ot.subReason};try{return await G.guardedFetch(N,ft)}catch(Ot){throw g(Ot,N,G,{onRedirectHop:W>0,subReason:dt})}});if(Km.has(Q.status)&&v){let Oe=Q.headers.get("location");if(!Oe)return await Tf(Q,N,a,B.signal,V);V.push({status:Q.status,statusText:Q.statusText,headers:Ff(Q.headers)});let ct=new URL(Oe,N).href;await ca(Ym(Q),B.signal);try{m(ct),E(ct)}catch(dt){throw B.signal?.aborted?vr(B.signal):dt instanceof Et?new dn(ct):dt}let It=Q.status;if(((It===301||It===302)&&I==="POST"||It===303&&I!=="GET"&&I!=="HEAD")&&(I="GET",O=void 0,S(I)),new URL(ct).origin!==new URL(N).origin&&(ne=!0),W++,W>R)throw new Zn(R);N=ct;continue}return await Tf(Q,N,a,B.signal,V)}}finally{ya(D),B.cleanup()}}return y}async function ca(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),vr(t);let n,r=new Promise((s,i)=>{n=()=>i(vr(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function Ym(e){e.body&&!e.body.locked&&await e.body.cancel()}function Jm(e,t){if(!e&&!t)return;if(!t)return e;let n=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,s]of t)n.set(r,s);return n}function Ff(e){let t=Object.create(null);return e.forEach((n,r)=>{t[r.toLowerCase()]=n}),t}async function Tf(e,t,n,r,s){let i=Ff(e.headers);if(n>0){let l=e.headers.get("content-length");if(l){let u=parseInt(l,10);if(!Number.isNaN(u)&&u>n)throw new $n(n)}}let o;if(n>0&&e.body){let l=e.body.getReader(),u=[],c=0;try{for(;;){let{done:d,value:p}=await ca(l.read(),r);if(d)break;if(p){if(c+=p.byteLength,c>n)throw await l.cancel(),new $n(n);u.push(p)}}}catch(d){throw r?.aborted&&await l.cancel(vr(r)).catch(()=>{}),d}o=new Uint8Array(c);let f=0;for(let d of u)o.set(d,f),f+=d.byteLength}else{let l=await ca(e.arrayBuffer(),r);if(n>0&&l.byteLength>n)throw new $n(n);o=new Uint8Array(l)}let a={status:e.status,statusText:e.statusText,headers:i,body:o,url:t};return s&&s.length>0&&(a.redirectChain=s),a}function Vs(e,t){if(e.length>t||M(e)>t)throw new P(`script input size limit exceeded (${t} bytes)`,"string_length")}var zs=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;abortOnUnresolvedCommands=!1;invokeToolFn;transformPlugins=[];state;constructor(t={}){if(this.limits=Js({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}},t.executionLimitProfile),t.fs&&t.files)throw new Error("Bash: options.files is ignored when options.fs is provided; write the files into your filesystem directly or drop options.fs");let n=t.fs??new vt(t.files,{maxTotalBytes:this.limits.maxFileSystemBytes});this.fs=n,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),s=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
|
|
797
797
|
`],["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(t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=fa(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.abortOnUnresolvedCommands=t.abortOnUnresolvedCommands??!1,this.coverageWriter=t.coverage,this.state={env:s,arrays:new Map,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",ii(this.state.options)),this.state.env.set("BASHOPTS",oi(this.state.shoptOptions)),Ta(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&n instanceof vt)try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of ba(t.commands))this.registerBundledCommand(o);if(t.fetch||t.network)for(let o of Sa())this.registerBundledCommand(o);if(t.python)for(let o of Aa())this.registerBundledCommand(o);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let o of va())this.registerBundledCommand(o);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap),i.invokeTool&&(this.invokeToolFn=i.invokeTool)}if(t.customCommands)for(let o of t.customCommands)if(Ca(o)){let a=Na(o);this.registerCommandInternal(a,!0)}else this.registerCommandInternal(o,!0)}registerCommand(t){this.registerCommandInternal(t,!0)}registerBundledCommand(t){this.registerCommandInternal(t,!1)}registerCommandInternal(t,n,r=n?t.trusted??!0:t.trusted){let s=this.commands.get(t.name),i=n?s?.internalOriginalCommand??(s&&!s.internalIsExtension?s:void 0):void 0,o={name:t.name,trusted:r,internalIsExtension:n,internalOriginalCommand:i,execute:(l,u)=>t.execute(l,u)};this.commands.set(t.name,o);let a=this.fs;if(typeof a.writeFileSync=="function"){let l=`#!/bin/bash
|
|
798
798
|
# Built-in command: ${t.name}
|
|
799
799
|
`;try{a.writeFileSync(`/bin/${t.name}`,l)}catch{}try{a.writeFileSync(`/usr/bin/${t.name}`,l)}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=Mf(t.stdout),t.stderr=Mf(t.stderr),t}async exec(t,n){let r=new Lr(this.limits,n?.signal,this.abortOnUnresolvedCommands),s;try{s=await this.execInScope(t,n,r,0,n?.signal,!1,!1)}catch(o){try{await r.close()}catch{}throw o}let i=s;try{await r.close()}catch{i={...s,stderr:`${s.stderr}bash: execution cleanup failed
|
|
@@ -803,7 +803,7 @@ ${b.join(`
|
|
|
803
803
|
`,exitCode:2,env:Ue(this.state.env,c.env)});if(y instanceof RangeError)return l({stdout:"",stderr:`bash: ${St(y.message)}
|
|
804
804
|
`,exitCode:1,env:Ue(this.state.env,c.env)});throw y}finally{g?.deactivate()}}catch(f){if(f instanceof Xe)return l({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:Ue(this.state.env,c.env)});if(f instanceof P)return l({stdout:f.stdout,stderr:St(f.stderr),exitCode:P.EXIT_CODE,internalOutputAccounting:f.internalOutputAccounting,env:Ue(this.state.env,c.env)});throw f}finally{u.cleanup()}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,n){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),n)}getCwd(){return this.state.cwd}getEnv(){return Ut(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){Vs(t,this.limits.maxSourceBytes);let n=da(t),r=ot(n,{maxHeredocSize:this.limits.maxHeredocSize}),s=Object.create(null);for(let i of this.transformPlugins){let o=i.transform({ast:r,metadata:s});r=o.ast,o.metadata&&(s=Zs(s,o.metadata))}return{script:$l(r),ast:r,metadata:s}}async analyzeCommands(t){Vs(t,this.limits.maxSourceBytes);let n=ot(da(t),{maxHeredocSize:this.limits.maxHeredocSize}),{commands:r,definedFunctions:s,definedAliases:i}=Fa(n),o=[];for(let a of r)s.has(a)||i.has(a)||await this.resolvesCommandForAnalysis(a)||o.push(a);return{commands:r,unresolved:o}}async resolvesCommandForAnalysis(t){if((er.has(t)||Zt.has(t))&&!Va.has(t)||this.state.functions.has(t))return!0;let n=await Mr({fs:this.fs,state:{...this.state,hashTable:new Map},commands:this.commands},t);return n!==null&&!("error"in n)}};function ey(e,t){let n=t;for(let r=0;r<e.length;r++){let s=e[r];if(n==="single")s==="'"&&(n="none");else if(n==="double")s==="\\"?r++:s==='"'&&(n="none");else if(s==="'")n="single";else if(s==='"')n="double";else if(s==="\\")r++;else if(s==="#"&&(r===0||/\s/.test(e[r-1])))break}return n}function da(e){let t=e.split(`
|
|
805
805
|
`),n=[],r=[],s="none";for(let i=0;i<t.length;i++){let o=t[i];if(r.length>0){let c=r[r.length-1];if((c.stripTabs?o.replace(/^\t+/,""):o)===c.delimiter){n.push(o.trimStart()),r.pop();continue}n.push(o);continue}let a=s,l=a==="none"?o.trimStart():o;if(n.push(l),s=ey(o,a),a!=="none")continue;let u=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let c of l.matchAll(u)){let f=c[1]==="-",d=c[3];r.push({delimiter:d,stripTabs:f})}}return n.join(`
|
|
806
|
-
`)}var ty=new TextDecoder("utf-8",{fatal:!0});function Mf(e){if(!e)return e;let t=!1;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);if(s>255)return e;s>127&&(t=!0)}if(!t)return e;let n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);try{return ty.decode(n)}catch{return e}}function ny(e,t,n,r,s,i){if(e===void 0)return;let o=t==="bytes"?e.length:M(e);if(o>n||o>r)throw new P(`stdin size limit exceeded (${Math.min(n,r)} bytes)`,"string_length");return i||s.consumeInput(o,"stdin"),t==="bytes"?e:pn(e)}import*as me from"node:fs";import*as Ie from"node:path";import*as We from"node:fs";import*as $e from"node:path";function $r(e,t){let n=/^[A-Za-z]:[\\/]/.test(t)?$e.win32:$e.posix,r=n.relative(t,e);return r===""||r!==".."&&!r.startsWith(`..${n.sep}`)&&!n.isAbsolute(r)}function kr(e,t){try{let n=We.realpathSync(e);return $r(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=$e.dirname(e);if(r===e)return null;let s=kr(r,t);if(s===null)return null;try{if(We.lstatSync(e).isSymbolicLink()){let o=We.readlinkSync(e),a=$e.isAbsolute(o)?o:$e.resolve($e.dirname(e),o),l=kr(a,t);return l===null?null:l}}catch{}return $e.join(s,$e.basename(e))}return null}}function Bf(e,t,n){let r=kr(e,n);if(r===null)return null;let s=$e.resolve(e),i=s.slice(t.length),o=r.slice(n.length);if(i!==o)return null;try{if(We.lstatSync(s).isSymbolicLink())return null}catch{}return r}function Wf(e,t){if(!We.existsSync(e))throw new Error(`${t} root does not exist`);if(!We.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function Vf(e,t){if(!$e.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=We.realpathSync(e)}catch{n=$e.resolve(e)}return $r(n,t)?{withinRoot:!0,relativePath:n.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:$e.basename(e)}}function zf(e,t,n,r){let s=e;if(s.path===void 0){for(let o of r)if(s.message?.includes(o))throw e}let i=s.code||"EIO";throw new Error(`${i}: ${n} '${t}'`)}async function bt(e){return Uf(await We.promises.lstat(e))}function pa(e){return Uf(We.lstatSync(e))}function Uf(e){return process.platform==="win32"&&e.isDirectory()&&(e.mode=e.mode&-512|493),e}function Us(e){let t=e.content.byteLength;for(let n of e.appendChunks??[])t+=n.byteLength;return t}function Hf(e){return Us(e)}function js(e,t){if(!e.appendChunks||e.appendChunks.length===0)return e.content;let n=e.appendChunks.reduce((i,o)=>i+o.byteLength,e.content.byteLength);if(!Number.isSafeInteger(n))throw new Error(`EFBIG: file too large, read '${t}'`);let r=new Uint8Array(n);r.set(e.content);let s=e.content.byteLength;for(let i of e.appendChunks)r.set(i,s),s+=i.byteLength;return e.content=r,e.appendChunks=void 0,r}function qf(e){return!e||e.type!=="file"?0:Us(e)}function xr(){return{type:"directory",children:new Map,mode:493,mtime:new Date}}function Pr(e){return e.split("/").filter(Boolean)}var qs=class e{maxMemoryBytes;rootNode=xr();bytes=0;constructor(t){this.maxMemoryBytes=t}get root(){return this.rootNode}get retainedBytes(){return this.bytes}descend(t){let n=Pr(t),r=[this.rootNode],s=this.rootNode;for(let i=0;i<n.length;i++){let o=s.children.get(n[i]);if(o===void 0)return{kind:"missing",stack:r,missingAt:i};if(i===n.length-1)return{kind:"found",stack:r,node:o};if(o.type==="whiteout")return{kind:"blocked",stack:r,blockedAt:i};if(o.type!=="directory")return{kind:"notdir",stack:r,notdirAt:i};r.push(o),s=o}return{kind:"found",stack:[],node:this.rootNode}}ensureDirs(t,n){let r=this.rootNode,s="";for(let i of Pr(t)){s=`${s}/${i}`;let o=r.children.get(i);if(o===void 0)o=xr(),r.children.set(i,o);else if(o.type==="whiteout")o=this.resurrectDir(r,i,s,n);else if(o.type!=="directory")throw new Error(`ENOTDIR: not a directory, mkdir '${t}'`);r=o}return r}resurrectDir(t,n,r,s){let i=xr();t.children.set(n,i);let o=s?.(r);if(o)for(let a of o)i.children.has(a)||i.children.set(a,{type:"whiteout"});return i}attach(t,n){let r=Pr(t);if(r.length===0)throw new Error(`EINVAL: cannot attach at root, attach '${t}'`);let s=this.parentDirOf(r,t),i=s.children.get(r[r.length-1]);if(i?.type==="directory"&&n.type!=="directory")throw new Error(`EISDIR: cannot replace directory with ${n.type}, attach '${t}'`);if(i!==void 0&&n.type==="directory")throw new Error(`EEXIST: cannot replace ${i.type} with directory, attach '${t}'`);let o=qf(i),a=qf(n);this.assertCapacity(a,o),s.children.set(r[r.length-1],n),this.bytes+=a-o}detach(t){let n=Pr(t);if(n.length===0)return;let r=this.descend(t);return r.kind!=="found"?void 0:(r.stack[r.stack.length-1].children.delete(n[n.length-1]),this.bytes-=e.subtreeBytes(r.node),r.node)}putWhiteout(t){let n=Pr(t);if(n.length===0)throw new Error(`EINVAL: cannot whiteout the root, rm '${t}'`);let r=this.rootNode;for(let o=0;o<n.length-1;o++)r=this.ensureChildDir(r,n[o],t);let s=n[n.length-1],i=r.children.get(s);i?.type!=="whiteout"&&(this.bytes-=e.subtreeBytes(i),r.children.set(s,{type:"whiteout"}))}appendChunk(t,n){this.assertCapacity(n.byteLength),t.appendChunks||(t.appendChunks=[]),t.appendChunks.push(n),this.bytes+=n.byteLength}*preOrder(){let t=[{path:"/",node:this.rootNode}];for(;t.length>0;){let n=t.pop();if(yield n,n.node.type==="directory"){let r=[...n.node.children.entries()];for(let s=r.length-1;s>=0;s--){let[i,o]=r[s];t.push({path:jf(n.path,i),node:o})}}}}*postOrder(){let t=[],n=[{path:"/",node:this.rootNode}];for(;n.length>0;){let r=n.pop();if(t.push(r),r.node.type==="directory")for(let[s,i]of r.node.children)n.push({path:jf(r.path,s),node:i})}for(let r=t.length-1;r>=0;r--)yield t[r]}clear(){this.rootNode=xr(),this.bytes=0}static subtreeBytes(t){if(t===void 0)return 0;if(t.type==="file")return Us(t);if(t.type!=="directory")return 0;let n=0,r=[t];for(;r.length>0;){let s=r.pop();for(let i of s.children.values())i.type==="file"?n+=Us(i):i.type==="directory"&&r.push(i)}return n}parentDirOf(t,n){let r=this.rootNode;for(let s=0;s<t.length-1;s++){let i=r.children.get(t[s]);if(i?.type!=="directory")throw new Error(`ENOTDIR: not a directory, attach '${n}'`);r=i}return r}ensureChildDir(t,n,r){let s=t.children.get(n);if(s===void 0||s.type==="whiteout")s=xr(),t.children.set(n,s);else if(s.type!=="directory")throw new Error(`ENOTDIR: not a directory, rm '${r}'`);return s}assertCapacity(t,n=0){if(!Number.isSafeInteger(t)||t<0||t>this.maxMemoryBytes-this.bytes+n)throw new Error(`ENOSPC: overlay memory byte limit exceeded (${this.maxMemoryBytes} bytes)`)}};function jf(e,t){return e==="/"?`/${t}`:`${e}/${t}`}var ry=["ELOOP","EFBIG","EPERM"],sy="/home/user/project",Hs=class{root;canonicalRoot;mountPoint;readOnly;maxFileReadSize;maxMemoryBytes;allowSymlinks;tree;nextMemoryIdentity=1;identityFor(t){return t.type==="symlink"?"":(t.identity||(t.identity=`overlay:${this.nextMemoryIdentity++}`),t.identity)}constructor(t){this.root=Ie.resolve(t.root);let n=t.mountPoint??sy;if(this.mountPoint=n==="/"?"/":n.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${n}`);if(this.readOnly=t.readOnly??!1,this.maxFileReadSize=t.maxFileReadSize??10485760,this.maxMemoryBytes=t.maxMemoryBytes??1024*1024*1024,!Number.isSafeInteger(this.maxMemoryBytes)||this.maxMemoryBytes<0)throw new Error("OverlayFs: invalid maxMemoryBytes");this.allowSymlinks=t.allowSymlinks??!1,Wf(this.root,"OverlayFs"),this.canonicalRoot=me.realpathSync(this.root),this.tree=new qs(this.maxMemoryBytes),this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){this.tree.ensureDirs(this.mountPoint)}getMountPoint(){return this.mountPoint}diff(){let t=[],n=[];for(let{path:r,node:s}of this.tree.preOrder()){let i=this.getRelativeToMount(r);if(!(i===null||i==="/")){if(s.type==="whiteout"){this.existsOnRealFs(r)&&n.push(i);continue}if(s.type==="file")if(s.metacopy){if(!this.existsOnRealFs(r))continue;t.push({path:i,nodeType:"file",content:new Uint8Array(0),mode:s.mode,mtime:s.mtime,metadataOnly:!0})}else t.push({path:i,nodeType:"file",content:js(s,r),mode:s.mode,mtime:s.mtime});else s.type==="directory"?t.push({path:i,nodeType:"directory",content:new Uint8Array(0),mode:s.mode,mtime:s.mtime}):t.push({path:i,nodeType:"symlink",content:new TextEncoder().encode(s.target),mode:s.mode,mtime:s.mtime})}}return t.sort((r,s)=>r.path<s.path?-1:r.path>s.path?1:0),n.sort(),{writes:t,deletions:n}}async sync(){for(let{path:t,node:n}of this.tree.postOrder()){let r=this.getRelativeToMount(t);if(!(r===null||r==="/")){if(n.type==="whiteout"){this.existsOnRealFs(t)||this.tree.detach(t);continue}n.type==="directory"&&n.children.size>0||await this.nodeMatchesDisk(t,n)&&this.tree.detach(t)}}}reset(){this.tree.clear(),this.createMountPointDirs()}drop(t){let n=t.map(r=>{let s=z(r);if(s==="/")throw new Error(`EINVAL: invalid argument, drop '${r}'`);return this.mountPoint==="/"?s:`${this.mountPoint}${s}`});n.sort((r,s)=>s.length-r.length);for(let r of n){let s=this.tree.descend(r);if(s.kind!=="found")continue;let i=s.node;i.type==="directory"&&i.children.size>0||this.tree.detach(r)}}async lstatLower(t){let n=this.resolveRealPathParent_(this.toRealPath(t));if(!n)return null;try{return{canonical:n,stat:await bt(n)}}catch{return null}}async nodeMatchesDisk(t,n){if(n.type==="directory")return(await this.lstatLower(t))?.stat.isDirectory()??!1;if(n.type==="symlink"){if(!this.allowSymlinks)return!1;let s=await this.lstatLower(t);if(!s?.stat.isSymbolicLink())return!1;try{let i=await me.promises.readlink(s.canonical);return this.realTargetToVirtual(i)===n.target}catch{return!1}}if(n.metacopy){let s=await this.lstatLower(t);if(!s?.stat.isFile())return!1;let{stat:i}=s;return!(i.mtime.getTime()!==n.mtime.getTime()||process.platform!=="win32"&&(i.mode&4095)!==(n.mode&4095))}let r=this.resolveRealPath_(this.toRealPath(t));if(!r)return!1;try{let s=await bt(r);if(!s.isFile())return!1;let i=js(n,t);if(s.size!==i.byteLength)return!1;let o=this.allowSymlinks?me.constants.O_RDONLY:me.constants.O_RDONLY|me.constants.O_NOFOLLOW,a=await me.promises.open(r,o),l;try{l=new Uint8Array(await a.readFile())}finally{await a.close()}for(let u=0;u<l.byteLength;u++)if(l[u]!==i[u])return!1;return!0}catch{return!1}}mkdirSync(t,n){this.tree.ensureDirs(z(t),r=>this.lowerChildren(r))}writeFileSync(t,n){let r=z(t);this.ensureParentDirs(r);let s=n instanceof Uint8Array?n:new TextEncoder().encode(n);this.tree.attach(r,{type:"file",content:s,mode:420,mtime:new Date})}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let n=z(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=Ie.join(this.root,r),i=Ie.resolve(s);return $r(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?kr(t,this.canonicalRoot):Bf(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=Ie.dirname(t),r=this.resolveRealPath_(n);return r===null?null:Ie.join(r,Ie.basename(t))}sanitizeError(t,n,r){zf(t,n,r,ry)}ensureParentDirs(t){let n=Cn(t);n!=="/"&&this.tree.ensureDirs(n,r=>this.lowerChildren(r))}lowerChildren(t){let n=this.resolveRealPath_(this.toRealPath(t));if(!n)return null;try{return me.readdirSync(n)}catch{return null}}async existsInOverlay(t){let n=z(t),r=this.tree.descend(n);if(r.kind==="found")return r.node.type!=="whiteout";if(r.kind==="blocked"||r.kind==="notdir")return!1;let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)return!1;try{return await bt(s),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=jt(n);return In(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return In(n,"binary")}async readFileBuffer(t,n=new Set){K(t,"open");let r=z(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);n.add(r);let s=this.tree.descend(r);if(s.kind==="blocked")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(s.kind==="notdir")throw new Error(`ENOTDIR: not a directory, open '${t}'`);if(s.kind==="found"){let i=s.node;if(i.type==="whiteout")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(i.type==="symlink"){let a=this.resolveSymlink(r,i.target);return this.readFileBuffer(a,n)}if(i.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(!i.metacopy)return js(i,t);let o=await this.readLowerFileBytes(r,t,n);if(process.platform==="win32")try{this.tree.attach(r,{type:"file",content:o,mode:i.mode,mtime:i.mtime})}catch(a){if(!(a instanceof Error)||!a.message.startsWith("ENOSPC"))throw a}return o}return this.readLowerFileBytes(r,t,n)}async readLowerFileBytes(t,n,r){let s=this.resolveRealPath_(this.toRealPath(t));if(!s)throw new Error(`ENOENT: no such file or directory, open '${n}'`);try{let i=await bt(s);if(i.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${n}'`);let l=await me.promises.readlink(s),u=this.realTargetToVirtual(l),c=this.resolveSymlink(t,u);return this.readFileBuffer(c,r)}if(i.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${n}'`);if(this.maxFileReadSize>0&&i.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${n}' (${i.size} bytes, max ${this.maxFileReadSize})`);let o=this.allowSymlinks?me.constants.O_RDONLY:me.constants.O_RDONLY|me.constants.O_NOFOLLOW,a=await me.promises.open(s,o);try{let l=await a.readFile();return new Uint8Array(l)}finally{await a.close()}}catch(i){let o=i.code;if(o==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${n}'`);if(o==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${n}'`);this.sanitizeError(i,n,"open")}}async writeFile(t,n,r){K(t,"write"),this.assertWritable(`write '${t}'`);let s=z(t);this.ensureParentDirs(s);let i=jt(r),o=Dn(n,i);this.tree.attach(s,{type:"file",content:o,mode:await this.inheritedMode(s),mtime:new Date})}async inheritedMode(t){let n=this.entryAt(t);if(n?.type==="file")return n.mode;if(n?.type==="directory")return 420;if(process.platform==="win32")return 420;try{let r=await this.stat(t);if(r.isFile)return r.mode}catch{}return 420}async appendFile(t,n,r){K(t,"append"),this.assertWritable(`append '${t}'`);let s=z(t),i=jt(r),o=Dn(n,i),a=this.tree.descend(s);if(a.kind==="found"&&a.node.type==="file"){let u=a.node;if(u.metacopy){let c=await this.readLowerFileBytes(s,t,new Set);this.tree.attach(s,{type:"file",content:c,appendChunks:[o],mode:u.mode,mtime:new Date});return}this.tree.appendChunk(u,o),u.mtime=new Date;return}if(a.kind==="blocked")throw new Error(`ENOENT: no such file or directory, append '${t}'`);if(a.kind==="notdir")throw new Error(`ENOTDIR: not a directory, append '${t}'`);let l;try{l=await this.readFileBuffer(s)}catch(u){if(!(u instanceof Error)||!u.message.startsWith("ENOENT"))throw u;l=new Uint8Array(0)}this.ensureParentDirs(s),this.tree.attach(s,{type:"file",content:l,appendChunks:[o],mode:await this.inheritedMode(s),mtime:new Date})}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,n=new Set){K(t,"stat");let r=z(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);n.add(r);let s=this.tree.descend(r);if(s.kind==="blocked")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);if(s.kind==="notdir")throw new Error(`ENOTDIR: not a directory, stat '${t}'`);if(s.kind==="found"){let o=s.node;if(o.type==="whiteout")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);if(o.type==="symlink"){let a=this.resolveSymlink(r,o.target);return this.stat(a,n)}return this.memoryEntryStat(o)}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let o=await bt(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let a=await me.promises.readlink(i),l=this.realTargetToVirtual(a),u=this.resolveSymlink(r,l);return this.stat(u,n)}return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:!1,mode:o.mode,size:o.size,mtime:o.mtime,dev:o.dev,ino:o.ino}}catch(o){if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(o,t,"stat")}}async lstat(t){K(t,"lstat");let n=z(t),r=this.tree.descend(n);if(r.kind==="blocked")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.kind==="notdir")throw new Error(`ENOTDIR: not a directory, lstat '${t}'`);if(r.kind==="found"){let i=r.node;if(i.type==="whiteout")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);return this.memoryEntryStat(i)}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await bt(s);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime,dev:i.dev,ino:i.ino}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}memoryEntryStat(t){if(t.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:t.mode,size:t.target.length,mtime:t.mtime};let n=0;return t.type==="file"&&(n=t.metacopy?t.lowerSize??0:Hf(t)),{isFile:t.type==="file",isDirectory:t.type==="directory",isSymbolicLink:!1,mode:t.mode,size:n,mtime:t.mtime,identity:this.identityFor(t)}}resolveSymlink(t,n){return Rn(t,n)}realTargetToVirtual(t){let n=Vf(t,this.canonicalRoot);if(n.withinRoot){if(!Ie.isAbsolute(t))return t;let r=n.relativePath;return this.mountPoint==="/"?r:`${this.mountPoint}${r}`}return n.safeName}async mkdir(t,n){K(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=z(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=Cn(r);if(i!=="/"&&!await this.existsInOverlay(i))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.tree.ensureDirs(r,o=>this.lowerChildren(o))}async readdirCore(t,n){let r=new Map,s=new Set,i=this.tree.descend(n);if(i.kind==="blocked")throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(i.kind==="notdir")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let o;if(i.kind==="found"){let l=i.node;if(l.type==="whiteout")throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(l.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);o=l;for(let[u,c]of l.children){if(c.type==="whiteout"){s.add(u);continue}r.set(u,{name:u,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}}let a=this.resolveRealPath_(this.toRealPath(n));if(a)try{if(!this.allowSymlinks&&(await bt(a)).isSymbolicLink()){if(!o){let c=new Error(`ENOENT: no such file or directory, scandir '${t}'`);throw c.code="ENOENT",c}return r}let l=await me.promises.readdir(a,{withFileTypes:!0});for(let u of l)!s.has(u.name)&&!r.has(u.name)&&r.set(u.name,{name:u.name,isFile:u.isFile(),isDirectory:u.isDirectory(),isSymbolicLink:u.isSymbolicLink()})}catch(l){if(l.code==="ENOENT"){if(!o)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else l.code!=="ENOTDIR"&&this.sanitizeError(l,t,"scandir")}return r}async resolveForReaddir(t,n=!1){let r=z(t),s=new Set,i=n;for(;;){let l=this.tree.descend(r);if(l.kind!=="found")break;let u=l.node;if(u.type!=="symlink")return{normalized:r,outsideOverlay:!1};if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(r),i=!0,r=this.resolveSymlink(r,u.target)}if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let a=this.resolveRealPath_(this.toRealPath(r));if(!a)return{normalized:r,outsideOverlay:!0};try{if((await bt(a)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let u=await me.promises.readlink(a),c=this.realTargetToVirtual(u),f=this.resolveSymlink(r,c);return this.resolveForReaddir(f,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async readdir(t){K(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.keys()).sort((i,o)=>i<o?-1:i>o?1:0)}async readdirWithFileTypes(t){K(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.values()).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async rm(t,n){K(t,"rm"),this.assertWritable(`rm '${t}'`);let r=z(t);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}let i=!1;try{(await this.stat(r)).isDirectory&&(i=(await this.readdir(r)).length>0)}catch{}if(i&&!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);this.existsOnRealFs(r)?this.tree.putWhiteout(r):this.tree.detach(r)}existsOnRealFs(t){let n=this.toRealPath(t),r=this.resolveRealPathParent_(n);if(!r)return!1;try{return pa(r),!0}catch{return!1}}async cp(t,n,r){K(t,"cp"),K(n,"cp"),this.assertWritable(`cp '${n}'`);let s=z(t),i=z(n);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let a=await this.stat(s);if(a.isFile){let l=await this.readFileBuffer(s);await this.writeFile(i,l)}else if(a.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(_t(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(s);for(let u of l){let c=s==="/"?`/${u}`:`${s}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(c,f,r)}}}async mv(t,n){this.assertWritable(`mv '${n}'`),await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return Nn(t,n)}getAllPaths(){let t=new Set;for(let{path:n,node:r}of this.tree.preOrder())r.type!=="whiteout"&&t.add(n);return this.scanRealFs(this.mountPoint,t),Array.from(t)}scanRealFs(t,n){if(this.lowerHidden(t))return;let r=this.resolveRealPath_(this.toRealPath(t));if(r)try{let s=me.readdirSync(r);for(let i of s){let o=t==="/"?`/${i}`:`${t}/${i}`;if(this.lowerHidden(o))continue;n.add(o);let a=Ie.join(r,i);pa(a).isDirectory()&&this.scanRealFs(o,n)}}catch{}}lowerHidden(t){let n=this.tree.descend(t);switch(n.kind){case"blocked":case"notdir":return!0;case"found":return n.node.type!=="directory";default:return!1}}entryAt(t){let n=this.tree.descend(t);if(n.kind==="found"&&n.node.type!=="whiteout")return n.node}async chmod(t,n){K(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=z(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.entryAt(r);if(i){i.mode=n;return}let o=await this.stat(r);this.attachMetacopyShadow(r,o,n,o.isFile?o.mtime:new Date)}attachMetacopyShadow(t,n,r,s){this.ensureParentDirs(t),n.isFile?this.tree.attach(t,{type:"file",content:new Uint8Array(0),metacopy:!0,lowerSize:n.size,mode:r,mtime:s}):n.isDirectory&&this.tree.attach(t,{type:"directory",children:new Map,mode:r,mtime:s})}async symlink(t,n){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${n}'`);K(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=z(n);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.tree.attach(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,n){K(t,"link"),K(n,"link"),this.assertWritable(`link '${n}'`);let r=z(t),s=z(n);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let o=await this.stat(r);if(!o.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let l=await this.readFileBuffer(r);this.ensureParentDirs(s),this.tree.attach(s,{type:"file",content:l,mode:o.mode,mtime:new Date,identity:o.identity??`overlay:${this.nextMemoryIdentity++}`})}async readlink(t){K(t,"readlink");let n=z(t),r=this.tree.descend(n);if(r.kind==="blocked")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.kind==="notdir")throw new Error(`ENOTDIR: not a directory, readlink '${t}'`);if(r.kind==="found"){let i=r.node;if(i.type==="whiteout")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return i.target}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await me.promises.readlink(s);if(!Ie.isAbsolute(i)){let o=Ie.resolve(Ie.dirname(s),i),a;try{a=me.realpathSync(o)}catch{a=o}if(!$r(a,this.canonicalRoot))return Ie.basename(i)}return this.realTargetToVirtual(i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){K(t,"realpath");let n=z(t),r=new Set,s=l=>{let u=this.tree.descend(l);if(u.kind==="blocked"||u.kind==="found"&&u.node.type==="whiteout")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return u.kind==="found"?u.node:void 0},i=async l=>{let u=l==="/"?[]:l.slice(1).split("/"),c="";for(let f of u){if(c=`${c}/${f}`,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);let d=s(c),p=0,h=40;for(;d&&d.type==="symlink"&&p<h;){if(r.add(c),c=this.resolveSymlink(c,d.target),p++,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);d=s(c)}if(p>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!d){let m=this.toRealPath(c),E=this.resolveRealPath_(m);if(E)try{if((await bt(E)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let g=await me.promises.readlink(E),y=this.realTargetToVirtual(g);return r.add(c),c=this.resolveSymlink(c,y),i(c)}}catch(S){if(S.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(S,t,"realpath")}else if(!this.allowSymlinks){let S=this.resolveRealPathParent_(m);if(S)try{if((await bt(S)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch(g){if(g.message?.includes("ENOENT")||g.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(g,t,"realpath")}}}}return c||"/"},o=await i(n);if(!await this.existsInOverlay(o))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return o}async utimes(t,n,r){K(t,"utimes"),this.assertWritable(`utimes '${t}'`);let s=z(t);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let o=this.entryAt(s);if(o){o.mtime=r;return}let a=await this.stat(s);this.attachMetacopyShadow(s,a,a.mode,r)}};var xe={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"},ha=class{env;rl;running=!0;history=[];initialization;isInteractive;constructor(t={}){let n=process.cwd(),r=new Hs({root:n,mountPoint:"/"});this.env=new zs({fs:r,cwd:t.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...t.env},network:t.network===!0?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.initialization=this.seedFiles(r,t.files),this.isInteractive=process.stdin.isTTY===!0,this.rl=Qf.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C
|
|
806
|
+
`)}var ty=new TextDecoder("utf-8",{fatal:!0});function Mf(e){if(!e)return e;let t=!1;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);if(s>255)return e;s>127&&(t=!0)}if(!t)return e;let n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);try{return ty.decode(n)}catch{return e}}function ny(e,t,n,r,s,i){if(e===void 0)return;let o=t==="bytes"?e.length:M(e);if(o>n||o>r)throw new P(`stdin size limit exceeded (${Math.min(n,r)} bytes)`,"string_length");return i||s.consumeInput(o,"stdin"),t==="bytes"?e:pn(e)}import*as me from"node:fs";import*as Ie from"node:path";import*as We from"node:fs";import*as $e from"node:path";function $r(e,t){let n=/^[A-Za-z]:[\\/]/.test(t)?$e.win32:$e.posix,r=n.relative(t,e);return r===""||r!==".."&&!r.startsWith(`..${n.sep}`)&&!n.isAbsolute(r)}function kr(e,t){try{let n=We.realpathSync(e);return $r(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=$e.dirname(e);if(r===e)return null;let s=kr(r,t);if(s===null)return null;try{if(We.lstatSync(e).isSymbolicLink()){let o=We.readlinkSync(e),a=$e.isAbsolute(o)?o:$e.resolve($e.dirname(e),o),l=kr(a,t);return l===null?null:l}}catch{}return $e.join(s,$e.basename(e))}return null}}function Bf(e,t,n){let r=kr(e,n);if(r===null)return null;let s=$e.resolve(e),i=s.slice(t.length),o=r.slice(n.length);if(i!==o)return null;try{if(We.lstatSync(s).isSymbolicLink())return null}catch{}return r}function Wf(e,t){if(!We.existsSync(e))throw new Error(`${t} root does not exist`);if(!We.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function Vf(e,t){if(!$e.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=We.realpathSync(e)}catch{n=$e.resolve(e)}return $r(n,t)?{withinRoot:!0,relativePath:n.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:$e.basename(e)}}function zf(e,t,n,r){let s=e;if(s.path===void 0){for(let o of r)if(s.message?.includes(o))throw e}let i=s.code||"EIO";throw new Error(`${i}: ${n} '${t}'`)}async function bt(e){return Uf(await We.promises.lstat(e))}function pa(e){return Uf(We.lstatSync(e))}function Uf(e){return process.platform==="win32"&&e.isDirectory()&&(e.mode=e.mode&-512|493),e}function Us(e){let t=e.content.byteLength;for(let n of e.appendChunks??[])t+=n.byteLength;return t}function Hf(e){return Us(e)}function js(e,t){if(!e.appendChunks||e.appendChunks.length===0)return e.content;let n=e.appendChunks.reduce((i,o)=>i+o.byteLength,e.content.byteLength);if(!Number.isSafeInteger(n))throw new Error(`EFBIG: file too large, read '${t}'`);let r=new Uint8Array(n);r.set(e.content);let s=e.content.byteLength;for(let i of e.appendChunks)r.set(i,s),s+=i.byteLength;return e.content=r,e.appendChunks=void 0,r}function qf(e){return!e||e.type!=="file"?0:Us(e)}function xr(){return{type:"directory",children:new Map,changedAt:Date.now(),mode:493,mtime:new Date}}function Pr(e){return e.split("/").filter(Boolean)}var qs=class e{maxMemoryBytes;rootNode=xr();bytes=0;mutationSeq_=0;constructor(t){this.maxMemoryBytes=t}get root(){return this.rootNode}get retainedBytes(){return this.bytes}descend(t){let n=Pr(t),r=[this.rootNode],s=this.rootNode;for(let i=0;i<n.length;i++){let o=s.children.get(n[i]);if(o===void 0)return{kind:"missing",stack:r,missingAt:i};if(i===n.length-1)return{kind:"found",stack:r,node:o};if(o.type==="whiteout")return{kind:"blocked",stack:r,blockedAt:i};if(o.type!=="directory")return{kind:"notdir",stack:r,notdirAt:i};r.push(o),s=o}return{kind:"found",stack:[],node:this.rootNode}}ensureDirs(t,n){let r=this.rootNode,s="";for(let i of Pr(t)){s=`${s}/${i}`;let o=r.children.get(i);if(o===void 0)o=xr(),r.children.set(i,o);else if(o.type==="whiteout")o=this.resurrectDir(r,i,s,n);else if(o.type!=="directory")throw new Error(`ENOTDIR: not a directory, mkdir '${t}'`);r=o}return r}resurrectDir(t,n,r,s){let i=xr();t.children.set(n,i);let o=s?.(r);if(o)for(let a of o)i.children.has(a)||i.children.set(a,{type:"whiteout",changedAt:i.changedAt});return i}attach(t,n){n.changedAt=Date.now();let r=Pr(t);if(r.length===0)throw new Error(`EINVAL: cannot attach at root, attach '${t}'`);let s=this.parentDirOf(r,t),i=s.children.get(r[r.length-1]);if(i?.type==="directory"&&n.type!=="directory")throw new Error(`EISDIR: cannot replace directory with ${n.type}, attach '${t}'`);if(i!==void 0&&n.type==="directory")throw new Error(`EEXIST: cannot replace ${i.type} with directory, attach '${t}'`);let o=qf(i),a=qf(n);this.assertCapacity(a,o),s.children.set(r[r.length-1],n),this.bytes+=a-o}detach(t){let n=Pr(t);if(n.length===0)return;let r=this.descend(t);return r.kind!=="found"?void 0:(r.stack[r.stack.length-1].children.delete(n[n.length-1]),this.bytes-=e.subtreeBytes(r.node),r.node)}putWhiteout(t){let n=Pr(t);if(n.length===0)throw new Error(`EINVAL: cannot whiteout the root, rm '${t}'`);let r=this.rootNode;for(let o=0;o<n.length-1;o++)r=this.ensureChildDir(r,n[o],t);let s=n[n.length-1],i=r.children.get(s);i?.type!=="whiteout"&&(this.bytes-=e.subtreeBytes(i),r.children.set(s,{type:"whiteout",changedAt:Date.now()}))}appendChunk(t,n){this.assertCapacity(n.byteLength),t.appendChunks||(t.appendChunks=[]),t.appendChunks.push(n),this.bytes+=n.byteLength,this.touch(t)}touch(t){t.seq=++this.mutationSeq_,t.changedAt=Date.now()}detachIfUnchanged(t,n,r){let s=this.descend(t);return s.kind!=="found"||s.node!==n||n.seq!==r||n.type==="directory"&&n.children.size>0?!1:(this.detach(t),!0)}*preOrder(){let t=[{path:"/",node:this.rootNode}];for(;t.length>0;){let n=t.pop();if(yield n,n.node.type==="directory"){let r=[...n.node.children.entries()];for(let s=r.length-1;s>=0;s--){let[i,o]=r[s];t.push({path:jf(n.path,i),node:o})}}}}*postOrder(){let t=[],n=[{path:"/",node:this.rootNode}];for(;n.length>0;){let r=n.pop();if(t.push(r),r.node.type==="directory")for(let[s,i]of r.node.children)n.push({path:jf(r.path,s),node:i})}for(let r=t.length-1;r>=0;r--)yield t[r]}clear(){this.rootNode=xr(),this.bytes=0}static subtreeBytes(t){if(t===void 0)return 0;if(t.type==="file")return Us(t);if(t.type!=="directory")return 0;let n=0,r=[t];for(;r.length>0;){let s=r.pop();for(let i of s.children.values())i.type==="file"?n+=Us(i):i.type==="directory"&&r.push(i)}return n}parentDirOf(t,n){let r=this.rootNode;for(let s=0;s<t.length-1;s++){let i=r.children.get(t[s]);if(i?.type!=="directory")throw new Error(`ENOTDIR: not a directory, attach '${n}'`);r=i}return r}ensureChildDir(t,n,r){let s=t.children.get(n);if(s===void 0||s.type==="whiteout")s=xr(),t.children.set(n,s);else if(s.type!=="directory")throw new Error(`ENOTDIR: not a directory, rm '${r}'`);return s}assertCapacity(t,n=0){if(!Number.isSafeInteger(t)||t<0||t>this.maxMemoryBytes-this.bytes+n)throw new Error(`ENOSPC: overlay memory byte limit exceeded (${this.maxMemoryBytes} bytes)`)}};function jf(e,t){return e==="/"?`/${t}`:`${e}/${t}`}var ry=["ELOOP","EFBIG","EPERM"],sy="/home/user/project",Hs=class{root;canonicalRoot;mountPoint;readOnly;maxFileReadSize;maxMemoryBytes;allowSymlinks;tree;nextMemoryIdentity=1;identityFor(t){return t.type==="symlink"?"":(t.identity||(t.identity=`overlay:${this.nextMemoryIdentity++}`),t.identity)}constructor(t){this.root=Ie.resolve(t.root);let n=t.mountPoint??sy;if(this.mountPoint=n==="/"?"/":n.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${n}`);if(this.readOnly=t.readOnly??!1,this.maxFileReadSize=t.maxFileReadSize??10485760,this.maxMemoryBytes=t.maxMemoryBytes??1024*1024*1024,!Number.isSafeInteger(this.maxMemoryBytes)||this.maxMemoryBytes<0)throw new Error("OverlayFs: invalid maxMemoryBytes");this.allowSymlinks=t.allowSymlinks??!1,Wf(this.root,"OverlayFs"),this.canonicalRoot=me.realpathSync(this.root),this.tree=new qs(this.maxMemoryBytes),this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){this.tree.ensureDirs(this.mountPoint)}getMountPoint(){return this.mountPoint}diff(){let t=[],n=[],r=[];for(let{path:i,node:o}of this.tree.preOrder()){let a=this.getRelativeToMount(i);if(!(a===null||a==="/")){if(o.type==="whiteout"){this.existsOnRealFs(i)&&(n.push(a),r.push(o.changedAt??0));continue}if(o.type==="file")if(o.metacopy){if(!this.existsOnRealFs(i))continue;t.push({path:a,nodeType:"file",content:new Uint8Array(0),mode:o.mode,mtime:o.mtime,changedAt:o.changedAt??0,metadataOnly:!0})}else t.push({path:a,nodeType:"file",content:js(o,i),mode:o.mode,mtime:o.mtime,changedAt:o.changedAt??0});else o.type==="directory"?t.push({path:a,nodeType:"directory",content:new Uint8Array(0),mode:o.mode,mtime:o.mtime,changedAt:o.changedAt??0}):t.push({path:a,nodeType:"symlink",content:new TextEncoder().encode(o.target),mode:o.mode,mtime:o.mtime,changedAt:o.changedAt??0})}}t.sort((i,o)=>i.path<o.path?-1:i.path>o.path?1:0);let s=n.map((i,o)=>({path:i,changedAt:r[o]}));return s.sort((i,o)=>i.path<o.path?-1:i.path>o.path?1:0),{writes:t,deletions:s.map(i=>i.path),...s.length>0&&{deletionChangedAt:s.map(i=>i.changedAt)}}}async sync(){for(let{path:t,node:n}of this.tree.postOrder()){let r=this.getRelativeToMount(t);if(r===null||r==="/")continue;if(n.type==="whiteout"){this.existsOnRealFs(t)||this.tree.detach(t);continue}if(n.type==="directory"&&n.children.size>0)continue;let s=n.seq;await this.nodeMatchesDisk(t,n)&&this.tree.detachIfUnchanged(t,n,s)}}reset(){this.tree.clear(),this.createMountPointDirs()}drop(t){let n=t.map(r=>{let s=z(r);if(s==="/")throw new Error(`EINVAL: invalid argument, drop '${r}'`);return this.mountPoint==="/"?s:`${this.mountPoint}${s}`});n.sort((r,s)=>s.length-r.length);for(let r of n){let s=this.tree.descend(r);if(s.kind!=="found")continue;let i=s.node;i.type==="directory"&&i.children.size>0||this.tree.detach(r)}}async lstatLower(t){let n=this.resolveRealPathParent_(this.toRealPath(t));if(!n)return null;try{return{canonical:n,stat:await bt(n)}}catch{return null}}async nodeMatchesDisk(t,n){if(n.type==="directory")return(await this.lstatLower(t))?.stat.isDirectory()??!1;if(n.type==="symlink"){if(!this.allowSymlinks)return!1;let s=await this.lstatLower(t);if(!s?.stat.isSymbolicLink())return!1;try{let i=await me.promises.readlink(s.canonical);return this.realTargetToVirtual(i)===n.target}catch{return!1}}if(n.metacopy){let s=await this.lstatLower(t);if(!s?.stat.isFile())return!1;let{stat:i}=s;return!(i.mtime.getTime()!==n.mtime.getTime()||process.platform!=="win32"&&(i.mode&4095)!==(n.mode&4095))}let r=this.resolveRealPath_(this.toRealPath(t));if(!r)return!1;try{let s=await bt(r);if(!s.isFile())return!1;let i=js(n,t);if(s.size!==i.byteLength)return!1;let o=this.allowSymlinks?me.constants.O_RDONLY:me.constants.O_RDONLY|me.constants.O_NOFOLLOW,a=await me.promises.open(r,o),l;try{l=new Uint8Array(await a.readFile())}finally{await a.close()}for(let u=0;u<l.byteLength;u++)if(l[u]!==i[u])return!1;return!0}catch{return!1}}mkdirSync(t,n){this.tree.ensureDirs(z(t),r=>this.lowerChildren(r))}writeFileSync(t,n){let r=z(t);this.ensureParentDirs(r);let s=n instanceof Uint8Array?n:new TextEncoder().encode(n);this.tree.attach(r,{type:"file",content:s,mode:420,mtime:new Date})}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let n=z(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=Ie.join(this.root,r),i=Ie.resolve(s);return $r(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?kr(t,this.canonicalRoot):Bf(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=Ie.dirname(t),r=this.resolveRealPath_(n);return r===null?null:Ie.join(r,Ie.basename(t))}sanitizeError(t,n,r){zf(t,n,r,ry)}ensureParentDirs(t){let n=Cn(t);n!=="/"&&this.tree.ensureDirs(n,r=>this.lowerChildren(r))}lowerChildren(t){let n=this.resolveRealPath_(this.toRealPath(t));if(!n)return null;try{return me.readdirSync(n)}catch{return null}}async existsInOverlay(t){let n=z(t),r=this.tree.descend(n);if(r.kind==="found")return r.node.type!=="whiteout";if(r.kind==="blocked"||r.kind==="notdir")return!1;let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)return!1;try{return await bt(s),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=jt(n);return In(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return In(n,"binary")}async readFileBuffer(t,n=new Set){K(t,"open");let r=z(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);n.add(r);let s=this.tree.descend(r);if(s.kind==="blocked")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(s.kind==="notdir")throw new Error(`ENOTDIR: not a directory, open '${t}'`);if(s.kind==="found"){let i=s.node;if(i.type==="whiteout")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(i.type==="symlink"){let a=this.resolveSymlink(r,i.target);return this.readFileBuffer(a,n)}if(i.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(!i.metacopy)return js(i,t);let o=await this.readLowerFileBytes(r,t,n);if(process.platform==="win32")try{this.tree.attach(r,{type:"file",content:o,mode:i.mode,mtime:i.mtime})}catch(a){if(!(a instanceof Error)||!a.message.startsWith("ENOSPC"))throw a}return o}return this.readLowerFileBytes(r,t,n)}async readLowerFileBytes(t,n,r){let s=this.resolveRealPath_(this.toRealPath(t));if(!s)throw new Error(`ENOENT: no such file or directory, open '${n}'`);try{let i=await bt(s);if(i.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${n}'`);let l=await me.promises.readlink(s),u=this.realTargetToVirtual(l),c=this.resolveSymlink(t,u);return this.readFileBuffer(c,r)}if(i.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${n}'`);if(this.maxFileReadSize>0&&i.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${n}' (${i.size} bytes, max ${this.maxFileReadSize})`);let o=this.allowSymlinks?me.constants.O_RDONLY:me.constants.O_RDONLY|me.constants.O_NOFOLLOW,a=await me.promises.open(s,o);try{let l=await a.readFile();return new Uint8Array(l)}finally{await a.close()}}catch(i){let o=i.code;if(o==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${n}'`);if(o==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${n}'`);this.sanitizeError(i,n,"open")}}async writeFile(t,n,r){K(t,"write"),this.assertWritable(`write '${t}'`);let s=z(t);this.ensureParentDirs(s);let i=jt(r),o=Dn(n,i);this.tree.attach(s,{type:"file",content:o,mode:await this.inheritedMode(s),mtime:new Date})}async inheritedMode(t){let n=this.entryAt(t);if(n?.type==="file")return n.mode;if(n?.type==="directory")return 420;if(process.platform==="win32")return 420;try{let r=await this.stat(t);if(r.isFile)return r.mode}catch{}return 420}async appendFile(t,n,r){K(t,"append"),this.assertWritable(`append '${t}'`);let s=z(t),i=jt(r),o=Dn(n,i),a=this.tree.descend(s);if(a.kind==="found"&&a.node.type==="file"){await this.appendToExisting_(s,a.node,o,t);return}if(a.kind==="blocked")throw new Error(`ENOENT: no such file or directory, append '${t}'`);if(a.kind==="notdir")throw new Error(`ENOTDIR: not a directory, append '${t}'`);let l;try{l=await this.readFileBuffer(s)}catch(f){if(!(f instanceof Error)||!f.message.startsWith("ENOENT"))throw f;l=new Uint8Array(0)}let u=await this.inheritedMode(s),c=this.tree.descend(s);if(c.kind==="found"&&c.node.type==="file"){await this.appendToExisting_(s,c.node,o,t);return}this.ensureParentDirs(s),this.tree.attach(s,{type:"file",content:l,appendChunks:[o],mode:u,mtime:new Date})}async appendToExisting_(t,n,r,s){if(n.metacopy){let i=await this.readLowerFileBytes(t,s,new Set),o=this.tree.descend(t);if(o.kind==="found"&&o.node.type==="file"&&!o.node.metacopy){this.tree.appendChunk(o.node,r),o.node.mtime=new Date;return}this.tree.attach(t,{type:"file",content:i,appendChunks:[r],mode:n.mode,mtime:new Date});return}this.tree.appendChunk(n,r),n.mtime=new Date}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,n=new Set){K(t,"stat");let r=z(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);n.add(r);let s=this.tree.descend(r);if(s.kind==="blocked")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);if(s.kind==="notdir")throw new Error(`ENOTDIR: not a directory, stat '${t}'`);if(s.kind==="found"){let o=s.node;if(o.type==="whiteout")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);if(o.type==="symlink"){let a=this.resolveSymlink(r,o.target);return this.stat(a,n)}return this.memoryEntryStat(o)}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let o=await bt(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let a=await me.promises.readlink(i),l=this.realTargetToVirtual(a),u=this.resolveSymlink(r,l);return this.stat(u,n)}return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:!1,mode:o.mode,size:o.size,mtime:o.mtime,dev:o.dev,ino:o.ino}}catch(o){if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(o,t,"stat")}}async lstat(t){K(t,"lstat");let n=z(t),r=this.tree.descend(n);if(r.kind==="blocked")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.kind==="notdir")throw new Error(`ENOTDIR: not a directory, lstat '${t}'`);if(r.kind==="found"){let i=r.node;if(i.type==="whiteout")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);return this.memoryEntryStat(i)}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await bt(s);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime,dev:i.dev,ino:i.ino}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}memoryEntryStat(t){if(t.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:t.mode,size:t.target.length,mtime:t.mtime};let n=0;return t.type==="file"&&(n=t.metacopy?t.lowerSize??0:Hf(t)),{isFile:t.type==="file",isDirectory:t.type==="directory",isSymbolicLink:!1,mode:t.mode,size:n,mtime:t.mtime,identity:this.identityFor(t)}}resolveSymlink(t,n){return Rn(t,n)}realTargetToVirtual(t){let n=Vf(t,this.canonicalRoot);if(n.withinRoot){if(!Ie.isAbsolute(t))return t;let r=n.relativePath;return this.mountPoint==="/"?r:`${this.mountPoint}${r}`}return n.safeName}async mkdir(t,n){K(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=z(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=Cn(r);if(i!=="/"&&!await this.existsInOverlay(i))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.tree.ensureDirs(r,o=>this.lowerChildren(o))}async readdirCore(t,n){let r=new Map,s=new Set,i=this.tree.descend(n);if(i.kind==="blocked")throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(i.kind==="notdir")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let o;if(i.kind==="found"){let l=i.node;if(l.type==="whiteout")throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(l.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);o=l;for(let[u,c]of l.children){if(c.type==="whiteout"){s.add(u);continue}r.set(u,{name:u,isFile:c.type==="file",isDirectory:c.type==="directory",isSymbolicLink:c.type==="symlink"})}}let a=this.resolveRealPath_(this.toRealPath(n));if(a)try{if(!this.allowSymlinks&&(await bt(a)).isSymbolicLink()){if(!o){let c=new Error(`ENOENT: no such file or directory, scandir '${t}'`);throw c.code="ENOENT",c}return r}let l=await me.promises.readdir(a,{withFileTypes:!0});for(let u of l)!s.has(u.name)&&!r.has(u.name)&&r.set(u.name,{name:u.name,isFile:u.isFile(),isDirectory:u.isDirectory(),isSymbolicLink:u.isSymbolicLink()})}catch(l){if(l.code==="ENOENT"){if(!o)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else l.code!=="ENOTDIR"&&this.sanitizeError(l,t,"scandir")}return r}async resolveForReaddir(t,n=!1){let r=z(t),s=new Set,i=n;for(;;){let l=this.tree.descend(r);if(l.kind!=="found")break;let u=l.node;if(u.type!=="symlink")return{normalized:r,outsideOverlay:!1};if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(r),i=!0,r=this.resolveSymlink(r,u.target)}if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let a=this.resolveRealPath_(this.toRealPath(r));if(!a)return{normalized:r,outsideOverlay:!0};try{if((await bt(a)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let u=await me.promises.readlink(a),c=this.realTargetToVirtual(u),f=this.resolveSymlink(r,c);return this.resolveForReaddir(f,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async readdir(t){K(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.keys()).sort((i,o)=>i<o?-1:i>o?1:0)}async readdirWithFileTypes(t){K(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.values()).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async rm(t,n){K(t,"rm"),this.assertWritable(`rm '${t}'`);let r=z(t);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}let i=!1;try{(await this.stat(r)).isDirectory&&(i=(await this.readdir(r)).length>0)}catch{}if(i&&!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);this.existsOnRealFs(r)?this.tree.putWhiteout(r):this.tree.detach(r)}existsOnRealFs(t){let n=this.toRealPath(t),r=this.resolveRealPathParent_(n);if(!r)return!1;try{return pa(r),!0}catch{return!1}}async cp(t,n,r){K(t,"cp"),K(n,"cp"),this.assertWritable(`cp '${n}'`);let s=z(t),i=z(n);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let a=await this.stat(s);if(a.isFile){let l=await this.readFileBuffer(s);await this.writeFile(i,l)}else if(a.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(_t(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(s);for(let u of l){let c=s==="/"?`/${u}`:`${s}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(c,f,r)}}}async mv(t,n){this.assertWritable(`mv '${n}'`),await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return Nn(t,n)}getAllPaths(){let t=new Set;for(let{path:n,node:r}of this.tree.preOrder())r.type!=="whiteout"&&t.add(n);return this.scanRealFs(this.mountPoint,t),Array.from(t)}scanRealFs(t,n){if(this.lowerHidden(t))return;let r=this.resolveRealPath_(this.toRealPath(t));if(r)try{let s=me.readdirSync(r);for(let i of s){let o=t==="/"?`/${i}`:`${t}/${i}`;if(this.lowerHidden(o))continue;n.add(o);let a=Ie.join(r,i);pa(a).isDirectory()&&this.scanRealFs(o,n)}}catch{}}lowerHidden(t){let n=this.tree.descend(t);switch(n.kind){case"blocked":case"notdir":return!0;case"found":return n.node.type!=="directory";default:return!1}}entryAt(t){let n=this.tree.descend(t);if(n.kind==="found"&&n.node.type!=="whiteout")return n.node}async chmod(t,n){K(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=z(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.entryAt(r);if(i){i.mode=n,this.tree.touch(i);return}let o=await this.stat(r);this.attachMetacopyShadow(r,o,n,o.isFile?o.mtime:new Date)}attachMetacopyShadow(t,n,r,s){this.ensureParentDirs(t),n.isFile?this.tree.attach(t,{type:"file",content:new Uint8Array(0),metacopy:!0,lowerSize:n.size,mode:r,mtime:s}):n.isDirectory&&this.tree.attach(t,{type:"directory",children:new Map,mode:r,mtime:s})}async symlink(t,n){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${n}'`);K(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=z(n);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.tree.attach(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,n){K(t,"link"),K(n,"link"),this.assertWritable(`link '${n}'`);let r=z(t),s=z(n);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let o=await this.stat(r);if(!o.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let l=await this.readFileBuffer(r);this.ensureParentDirs(s),this.tree.attach(s,{type:"file",content:l,mode:o.mode,mtime:new Date,identity:o.identity??`overlay:${this.nextMemoryIdentity++}`})}async readlink(t){K(t,"readlink");let n=z(t),r=this.tree.descend(n);if(r.kind==="blocked")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.kind==="notdir")throw new Error(`ENOTDIR: not a directory, readlink '${t}'`);if(r.kind==="found"){let i=r.node;if(i.type==="whiteout")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return i.target}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await me.promises.readlink(s);if(!Ie.isAbsolute(i)){let o=Ie.resolve(Ie.dirname(s),i),a;try{a=me.realpathSync(o)}catch{a=o}if(!$r(a,this.canonicalRoot))return Ie.basename(i)}return this.realTargetToVirtual(i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){K(t,"realpath");let n=z(t),r=new Set,s=l=>{let u=this.tree.descend(l);if(u.kind==="blocked"||u.kind==="found"&&u.node.type==="whiteout")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return u.kind==="found"?u.node:void 0},i=async l=>{let u=l==="/"?[]:l.slice(1).split("/"),c="";for(let f of u){if(c=`${c}/${f}`,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);let d=s(c),p=0,h=40;for(;d&&d.type==="symlink"&&p<h;){if(r.add(c),c=this.resolveSymlink(c,d.target),p++,r.has(c))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);d=s(c)}if(p>=h)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!d){let m=this.toRealPath(c),E=this.resolveRealPath_(m);if(E)try{if((await bt(E)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let g=await me.promises.readlink(E),y=this.realTargetToVirtual(g);return r.add(c),c=this.resolveSymlink(c,y),i(c)}}catch(S){if(S.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(S,t,"realpath")}else if(!this.allowSymlinks){let S=this.resolveRealPathParent_(m);if(S)try{if((await bt(S)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch(g){if(g.message?.includes("ENOENT")||g.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(g,t,"realpath")}}}}return c||"/"},o=await i(n);if(!await this.existsInOverlay(o))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return o}async utimes(t,n,r){K(t,"utimes"),this.assertWritable(`utimes '${t}'`);let s=z(t);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let o=this.entryAt(s);if(o){o.mtime=r,this.tree.touch(o);return}let a=await this.stat(s);this.attachMetacopyShadow(s,a,a.mode,r)}};var xe={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",cyan:"\x1B[36m"},ha=class{env;rl;running=!0;history=[];initialization;isInteractive;constructor(t={}){let n=process.cwd(),r=new Hs({root:n,mountPoint:"/"});this.env=new zs({fs:r,cwd:t.cwd||"/",env:{HOME:"/",USER:"user",SHELL:"/bin/bash",TERM:"xterm-256color",...t.env},network:t.network===!0?{dangerouslyAllowFullInternetAccess:!0}:void 0}),this.initialization=this.seedFiles(r,t.files),this.isInteractive=process.stdin.isTTY===!0,this.rl=Qf.createInterface({input:process.stdin,output:process.stdout,terminal:this.isInteractive}),this.rl.on("SIGINT",()=>{process.stdout.write(`^C
|
|
807
807
|
`),this.prompt()}),process.stdin.isTTY&&this.rl.on("close",()=>{this.running=!1,console.log(`
|
|
808
808
|
Goodbye!`),process.exit(0)})}async seedFiles(t,n){if(n)for(let[r,s]of Object.entries(n)){if(typeof s!="string")throw new TypeError(`Invalid --files content for ${r}`);let i=t.resolvePath("/",r);await t.mkdir(Zf.posix.dirname(i),{recursive:!0}),await t.writeFile(i,s)}}syncHistory(){let t=this.env.getEnv();t.BASH_HISTORY=JSON.stringify(this.history)}getPrompt(){let t=this.env.getCwd(),n=this.env.getEnv().HOME||"/home/user",r=t;return t===n?r="~":t.startsWith(`${n}/`)&&(r=`~${t.slice(n.length)}`),`${xe.green}${xe.bold}user@virtual${xe.reset}:${xe.blue}${xe.bold}${r}${xe.reset}$ `}async executeCommand(t){let n=t.trim();if(n){if(this.history.push(n),n==="exit"||n.startsWith("exit ")){let r=n.split(/\s+/),s=r[1]?parseInt(r[1],10):0;console.log("exit"),process.exit(s)}this.syncHistory();try{let r=await this.env.exec(n);r.stdout&&process.stdout.write(r.stdout),r.stderr&&process.stderr.write(`${xe.red}${r.stderr}${xe.reset}`)}catch(r){console.error(`${xe.red}Error: ${st(r)}${xe.reset}`)}}}printWelcome(){console.log(`
|
|
809
809
|
${xe.cyan}${xe.bold}\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
|
package/dist/bundle/browser.js
CHANGED
|
@@ -95,7 +95,7 @@ Options:
|
|
|
95
95
|
`,a=1}return{stdout:"",stderr:o,exitCode:a}}},X8={name:"touch",flags:[{flag:"-c",type:"boolean"},{flag:"-a",type:"boolean"},{flag:"-m",type:"boolean"},{flag:"-d",type:"value",valueHint:"string"}],needsArgs:!0}});var Wh={};ae(Wh,{flagsForFuzzing:()=>eb,rmCommand:()=>J8});var Y8,J8,eb,jh=M(()=>{"use strict";_n();kn();It();Y8={recursive:{short:"r",long:"recursive",type:"boolean"},recursiveUpper:{short:"R",type:"boolean"},force:{short:"f",long:"force",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},J8={name:"rm",async execute(e,t){let n=Le("rm",e,Y8);if(!n.ok)return n.error;let r=n.result.flags.recursive||n.result.flags.recursiveUpper,s=n.result.flags.force,i=n.result.flags.verbose,o=n.result.positional;if(o.length===0)return s?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:`rm: missing operand
|
|
96
96
|
`,exitCode:1};let a="",l="",c=0;for(let u of o)try{let f=t.fs.resolvePath(t.cwd,u);if((await t.fs.stat(f)).isDirectory&&!r){l+=`rm: cannot remove '${u}': Is a directory
|
|
97
97
|
`,c=1;continue}await t.fs.rm(f,{recursive:r,force:s}),i&&(a+=`removed '${u}'
|
|
98
|
-
`)}catch(f){let d=mt(f),p=d.
|
|
98
|
+
`)}catch(f){let d=mt(f),p=d.startsWith("ENOENT");if(s&&p)continue;p?l+=`rm: cannot remove '${u}': No such file or directory
|
|
99
99
|
`:d.includes("ENOTEMPTY")||d.includes("not empty")?l+=`rm: cannot remove '${u}': Directory not empty
|
|
100
100
|
`:l+=`rm: cannot remove '${u}': ${Ye(d)}
|
|
101
101
|
`,c=1}return{stdout:a,stderr:l,exitCode:c}}},eb={name:"rm",flags:[{flag:"-r",type:"boolean"},{flag:"-R",type:"boolean"},{flag:"-f",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0}});var Hh={};ae(Hh,{cpCommand:()=>rb,flagsForFuzzing:()=>sb});var tb,nb,rb,sb,Vh=M(()=>{"use strict";ai();Bn();Z();kn();It();de();tb={name:"cp",summary:"copy files and directories",usage:"cp [OPTION]... SOURCE... DEST",options:["-r, -R, --recursive copy directories recursively","-n, --no-clobber do not overwrite an existing file","-p, --preserve preserve file attributes","-v, --verbose explain what is being done"," --help display this help and exit"]},nb={recursive:{short:"r",long:"recursive",type:"boolean"},recursiveUpper:{short:"R",type:"boolean"},noClobber:{short:"n",long:"no-clobber",type:"boolean"},preserve:{short:"p",long:"preserve",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},rb={name:"cp",async execute(e,t){if(q(e))return G(tb);let n=Le("cp",e,nb);if(!n.ok)return n.error;let r=n.result.flags.recursive||n.result.flags.recursiveUpper,s=n.result.flags.noClobber,i=n.result.flags.preserve,o=n.result.flags.verbose,a=n.result.positional;if(a.length<2)return{stdout:"",stderr:`cp: missing destination file operand
|
|
@@ -1546,7 +1546,7 @@ sys 0m0.000s
|
|
|
1546
1546
|
`)}})}async executeConditionalCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),Dn(this.ctx,t.redirections,"",async()=>{try{let n=await fs(this.ctx,t.expression),r=Ot(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){let r=n instanceof Ve?1:2;return K(`bash: conditional expression: ${n.message}
|
|
1547
1547
|
`,r)}})}};sa();vn();xs();function Hp(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function WO(e){let t=Hp(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var jO=3;function P3(e){let t=e;for(let n=0;n<jO;n++){if(t.includes("\\")||t.includes(";")||/%(?![0-9a-f]{2})/i.test(t))return!0;let r=t.toLowerCase();if(r.includes("%2f")||r.includes("%2e")||r.includes("%5c")||r.includes("%3b"))return!0;let s;try{s=decodeURIComponent(t)}catch{return!0}if(s===t)return!1;t=s}return t.includes("%")}function HO(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function Vp(e,t){let n=Hp(e);if(!n)return!1;let r=WO(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&P3(n.pathname)?!1:HO(n.pathname,r.pathPrefix)}function D3(e){return typeof e=="string"?e:e.url}function L3(e,t){return!t||t.length===0?!1:t.some(n=>Vp(e,D3(n)))}function Gp(e){let t=VO(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=F3(t);if(n)return Ac(n);let r=qO(t);return r?ZO(r):!1}function VO(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function GO(e){if(!e)return null;let t=10,n=e;if(n.startsWith("0x")||n.startsWith("0X")?(t=16,n=n.slice(2)):n.length>1&&n.startsWith("0")&&(t=8),!n||t===16&&!/^[0-9a-fA-F]+$/.test(n)||t===10&&!/^\d+$/.test(n)||t===8&&!/^[0-7]+$/.test(n))return null;let r=Number.parseInt(n,t);return!Number.isFinite(r)||r<0?null:r}function F3(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>GO(l));if(n.some(l=>l===null))return null;let r=n;if(t.length===1){let l=r[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,c]=r;return l>255||c>16777215?null:[l,c>>>16&255,c>>>8&255,c&255]}if(t.length===3){let[l,c,u]=r;return l>255||c>255||u>65535?null:[l,c,u>>>8&255,u&255]}let[s,i,o,a]=r;return s>255||i>255||o>255||a>255?null:[s,i,o,a]}function qO(e){let t=e,n=null;if(t.includes(".")){let m=t.lastIndexOf(":");if(m<0)return null;let g=t.slice(m+1),b=F3(g);if(!b)return null;n=b,t=t.slice(0,m)}let r=t.includes("::")?t.split("::").length-1:0;if(r>1)return null;let[s,i]=t.split("::"),o=s?s.split(":").filter(Boolean):[],a=i?i.split(":").filter(Boolean):[],l=m=>/^[0-9a-f]{1,4}$/i.test(m)?Number.parseInt(m,16):null,c=o.map(l),u=a.map(l);if(c.some(m=>m===null)||u.some(m=>m===null))return null;let f=n?2:0,d=c.length+u.length+f,p=0;if(r===1){if(p=8-d,p<0)return null}else if(d!==8)return null;let h=[...c,...new Array(p).fill(0),...u];return n&&(h.push(n[0]<<8|n[1]),h.push(n[2]<<8|n[3])),h.length===8?h:null}function Ac(e){let[t,n]=e;return t===127||t===10||t===172&&n>=16&&n<=31||t===192&&n===168||t===169&&n===254||t===0||t===100&&n>=64&&n<=127||t===198&&(n===18||n===19)||t===192&&n===0&&e[2]===0||t===192&&n===0&&e[2]===2||t===198&&n===51&&e[2]===100||t===203&&n===0&&e[2]===113||t>=240}function ZO(e){if(e.every(s=>s===0)||e.slice(0,7).every(s=>s===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Ac(s)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Ac(s)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let s=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return Ac(s)}return!1}function M3(e){let t=[];for(let n of e){if(typeof n!="string"&&(n===null||typeof n!="object"||!("url"in n)||typeof n.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let r=D3(n);if(!Hp(r)){t.push(`Invalid URL in allow-list: "${r}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(r);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${r}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${r}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&P3(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${r}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${r}"`)}return t}var Jn=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},Xs=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},jr=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Cc=class extends Error{constructor(t,n){super(`HTTP method '${t}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}},Ys=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var KO=20,QO=3e4,XO=10485760,YO=["GET","HEAD"],qp;qp=null;var JO=new Set(["GET","HEAD","OPTIONS"]),eT=new Set([301,302,303,307,308]);function ta(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function tT(e){if(e?.aborted)throw ta(e)}function Kp(e){let t=e.allowedUrlPrefixes??[];if(e._dnsResolve)throw new Error("NetworkConfig._dnsResolve is no longer supported: DNS resolution is performed by guarded-fetch and cannot be overridden");if(e._createConnectionOwner)throw new Error("NetworkConfig._createConnectionOwner is no longer supported: connect-time IP pinning is performed by guarded-fetch and cannot be overridden");let n=e._fetch;if(!e.dangerouslyAllowFullInternetAccess){let x=M3(t);if(x.length>0)throw new Error(`Invalid network allow-list:
|
|
1548
1548
|
${x.join(`
|
|
1549
|
-
`)}`)}let r=[];for(let x of t)typeof x=="object"&&x.transform&&x.transform.length>0&&r.push(x);function s(x){if(r.length===0)return null;let S=null;for(let E of r)if(Vp(x,E.url)&&E.transform){S||(S=new Headers);for(let A of E.transform)for(let[I,$]of Object.entries(A.headers))S.set(I,$)}return S}if(e.maxRedirects!==void 0&&(!Number.isSafeInteger(e.maxRedirects)||e.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let i=e.maxRedirects??KO,o=e.timeoutMs??QO,a=e.maxResponseSize??XO,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??YO,c=e.denyPrivateRanges??(typeof process<"u"&&!0),u=[];for(let x of t){let S=typeof x=="string"?x:x.url;try{u.push(new URL(S).hostname)}catch{}}function f(x){try{return new URL(x).hostname||"localhost.invalid"}catch{return"localhost.invalid"}}function d(x){return e.dangerouslyAllowFullInternetAccess?c?{allowedHosts:void 0,skipSsrfCheckForAllowedHosts:void 0}:{allowedHosts:[f(x)],skipSsrfCheckForAllowedHosts:!0}:{allowedHosts:u,skipSsrfCheckForAllowedHosts:!c}}function p(x){try{return Gp(new URL(x).hostname)}catch{return!1}}async function h(x,S){let E={method:S.method,headers:S.headers,signal:S.signal,redirect:"manual"};return S.body!==void 0&&(E.body=S.body),await(n??globalThis.fetch)(x,E)}function m(x){if(!e.dangerouslyAllowFullInternetAccess&&!L3(x,t))throw new Jn(x)}function g(x){if(!c)return;let S;try{S=new URL(x)}catch{throw new Jn(x,"invalid URL")}if(Gp(S.hostname))throw new Jn(x,"private/loopback IP address blocked")}function b(x){if(e.dangerouslyAllowFullInternetAccess)return;let S=x.toUpperCase();if(!l.includes(S))throw new Cc(S,l)}function w(x,S,E,A){if(!E.isGuardedFetchError(x))return x;let I=x,{onRedirectHop:$,subReason:N}=A;switch(I.code){case"host_not_allowed":case"protocol_not_allowed":return $?new jr(S):new Jn(S);case"hostname_unsafe":return $?new jr(S):new Jn(S,N==="dns_resolution_failed"?"DNS resolution failed for private IP check":"hostname resolves to private/loopback IP address");case"redirect_to_unsafe_host":return new jr(S);case"too_many_redirects":return new Xs(i);case"response_too_large":return new Ys(a);default:return x}}async function y(x,S={}){let E=S.method?.toUpperCase()??"GET",A=S.followRedirects??!0;if(S.maxRedirects!==void 0&&(!Number.isSafeInteger(S.maxRedirects)||S.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let I=S.maxRedirects??i,$=Math.min(i,I),N=S.timeoutMs!==void 0?Math.min(S.timeoutMs,o):o,R=new AbortController,O=bs(()=>R.abort(new DOMException("The operation was aborted","AbortError")),N),B=ei(S.signal,R.signal);try{m(x),g(x),b(E);let L=qp?await qp:null,T=x,W=0,_=[],F=E,z=S.body,D=S.headers,X=!1;for(;;){tT(B.signal);let V=await $t.runTrustedAsync(async()=>{let Y=D;if(X&&Y){let pe=Y instanceof Headers?new Headers(Y):new Headers(Y);pe.delete("authorization"),pe.delete("cookie"),Y=pe}let J=s(T),ge=rT(Y,J),Oe={method:F,headers:ge,signal:B.signal,followRedirects:!1,timeoutMs:N,sanitizeHeaders:!1};if(z&&!JO.has(F)&&(Oe.body=z),Object.assign(Oe,d(T)),!L||p(T)){if(c)throw new Jn(T,"DNS pinning unavailable for private IP enforcement");return await h(T,Oe)}c?n&&(Oe.fetch=n):(Oe.fetch=n??globalThis.fetch,Oe.dispatcher=null);let Ee;Oe.onUrlBlocked=pe=>{Ee=pe.subReason};try{return await L.guardedFetch(T,Oe)}catch(pe){throw w(pe,T,L,{onRedirectHop:W>0,subReason:Ee})}});if(eT.has(V.status)&&A){let Y=V.headers.get("location");if(!Y)return await _3(V,T,a,B.signal,_);_.push({status:V.status,statusText:V.statusText,headers:B3(V.headers)});let J=new URL(Y,T).href;await Zp(nT(V),B.signal);try{m(J),g(J)}catch(Ee){throw B.signal?.aborted?ta(B.signal):Ee instanceof Jn?new jr(J):Ee}let ge=V.status;if(((ge===301||ge===302)&&F==="POST"||ge===303&&F!=="GET"&&F!=="HEAD")&&(F="GET",z=void 0,b(F)),new URL(J).origin!==new URL(T).origin&&(X=!0),W++,W>$)throw new Xs($);T=J;continue}return await _3(V,T,a,B.signal,_)}}finally{Js(O),B.cleanup()}}return y}async function Zp(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),ta(t);let n,r=new Promise((s,i)=>{n=()=>i(ta(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function nT(e){e.body&&!e.body.locked&&await e.body.cancel()}function rT(e,t){if(!e&&!t)return;if(!t)return e;let n=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,s]of t)n.set(r,s);return n}function B3(e){let t=Object.create(null);return e.forEach((n,r)=>{t[r.toLowerCase()]=n}),t}async function _3(e,t,n,r,s){let i=B3(e.headers);if(n>0){let l=e.headers.get("content-length");if(l){let c=parseInt(l,10);if(!Number.isNaN(c)&&c>n)throw new Ys(n)}}let o;if(n>0&&e.body){let l=e.body.getReader(),c=[],u=0;try{for(;;){let{done:d,value:p}=await Zp(l.read(),r);if(d)break;if(p){if(u+=p.byteLength,u>n)throw await l.cancel(),new Ys(n);c.push(p)}}}catch(d){throw r?.aborted&&await l.cancel(ta(r)).catch(()=>{}),d}o=new Uint8Array(u);let f=0;for(let d of c)o.set(d,f),f+=d.byteLength}else{let l=await Zp(e.arrayBuffer(),r);if(n>0&&l.byteLength>n)throw new Ys(n);o=new Uint8Array(l)}let a={status:e.status,statusText:e.statusText,headers:i,body:o,url:t};return s&&s.length>0&&(a.redirectChain=s),a}vn();St();Z();function vc(e,t){if(e.length>t||U(e)>t)throw new C(`script input size limit exceeded (${t} bytes)`,"string_length")}var Xp=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;abortOnUnresolvedCommands=!1;invokeToolFn;transformPlugins=[];state;constructor(t={}){this.limits=bl({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}},t.executionLimitProfile);let n=t.fs??new lr(t.files,{maxTotalBytes:this.limits.maxFileSystemBytes});this.fs=n,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),s=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
|
|
1549
|
+
`)}`)}let r=[];for(let x of t)typeof x=="object"&&x.transform&&x.transform.length>0&&r.push(x);function s(x){if(r.length===0)return null;let S=null;for(let E of r)if(Vp(x,E.url)&&E.transform){S||(S=new Headers);for(let A of E.transform)for(let[I,$]of Object.entries(A.headers))S.set(I,$)}return S}if(e.maxRedirects!==void 0&&(!Number.isSafeInteger(e.maxRedirects)||e.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let i=e.maxRedirects??KO,o=e.timeoutMs??QO,a=e.maxResponseSize??XO,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??YO,c=e.denyPrivateRanges??(typeof process<"u"&&!0),u=[];for(let x of t){let S=typeof x=="string"?x:x.url;try{u.push(new URL(S).hostname)}catch{}}function f(x){try{return new URL(x).hostname||"localhost.invalid"}catch{return"localhost.invalid"}}function d(x){return e.dangerouslyAllowFullInternetAccess?c?{allowedHosts:void 0,skipSsrfCheckForAllowedHosts:void 0}:{allowedHosts:[f(x)],skipSsrfCheckForAllowedHosts:!0}:{allowedHosts:u,skipSsrfCheckForAllowedHosts:!c}}function p(x){try{return Gp(new URL(x).hostname)}catch{return!1}}async function h(x,S){let E={method:S.method,headers:S.headers,signal:S.signal,redirect:"manual"};return S.body!==void 0&&(E.body=S.body),await(n??globalThis.fetch)(x,E)}function m(x){if(!e.dangerouslyAllowFullInternetAccess&&!L3(x,t))throw new Jn(x)}function g(x){if(!c)return;let S;try{S=new URL(x)}catch{throw new Jn(x,"invalid URL")}if(Gp(S.hostname))throw new Jn(x,"private/loopback IP address blocked")}function b(x){if(e.dangerouslyAllowFullInternetAccess)return;let S=x.toUpperCase();if(!l.includes(S))throw new Cc(S,l)}function w(x,S,E,A){if(!E.isGuardedFetchError(x))return x;let I=x,{onRedirectHop:$,subReason:N}=A;switch(I.code){case"host_not_allowed":case"protocol_not_allowed":return $?new jr(S):new Jn(S);case"hostname_unsafe":return $?new jr(S):new Jn(S,N==="dns_resolution_failed"?"DNS resolution failed for private IP check":"hostname resolves to private/loopback IP address");case"redirect_to_unsafe_host":return new jr(S);case"too_many_redirects":return new Xs(i);case"response_too_large":return new Ys(a);default:return x}}async function y(x,S={}){let E=S.method?.toUpperCase()??"GET",A=S.followRedirects??!0;if(S.maxRedirects!==void 0&&(!Number.isSafeInteger(S.maxRedirects)||S.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let I=S.maxRedirects??i,$=Math.min(i,I),N=S.timeoutMs!==void 0?Math.min(S.timeoutMs,o):o,R=new AbortController,O=bs(()=>R.abort(new DOMException("The operation was aborted","AbortError")),N),B=ei(S.signal,R.signal);try{m(x),g(x),b(E);let L=qp?await qp:null,T=x,W=0,_=[],F=E,z=S.body,D=S.headers,X=!1;for(;;){tT(B.signal);let V=await $t.runTrustedAsync(async()=>{let Y=D;if(X&&Y){let pe=Y instanceof Headers?new Headers(Y):new Headers(Y);pe.delete("authorization"),pe.delete("cookie"),Y=pe}let J=s(T),ge=rT(Y,J),Oe={method:F,headers:ge,signal:B.signal,followRedirects:!1,timeoutMs:N,sanitizeHeaders:!1};if(z&&!JO.has(F)&&(Oe.body=z),Object.assign(Oe,d(T)),!L||p(T)){if(c)throw new Jn(T,"DNS pinning unavailable for private IP enforcement");return await h(T,Oe)}c?n&&(Oe.fetch=n):(Oe.fetch=n??globalThis.fetch,Oe.dispatcher=null);let Ee;Oe.onUrlBlocked=pe=>{Ee=pe.subReason};try{return await L.guardedFetch(T,Oe)}catch(pe){throw w(pe,T,L,{onRedirectHop:W>0,subReason:Ee})}});if(eT.has(V.status)&&A){let Y=V.headers.get("location");if(!Y)return await _3(V,T,a,B.signal,_);_.push({status:V.status,statusText:V.statusText,headers:B3(V.headers)});let J=new URL(Y,T).href;await Zp(nT(V),B.signal);try{m(J),g(J)}catch(Ee){throw B.signal?.aborted?ta(B.signal):Ee instanceof Jn?new jr(J):Ee}let ge=V.status;if(((ge===301||ge===302)&&F==="POST"||ge===303&&F!=="GET"&&F!=="HEAD")&&(F="GET",z=void 0,b(F)),new URL(J).origin!==new URL(T).origin&&(X=!0),W++,W>$)throw new Xs($);T=J;continue}return await _3(V,T,a,B.signal,_)}}finally{Js(O),B.cleanup()}}return y}async function Zp(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),ta(t);let n,r=new Promise((s,i)=>{n=()=>i(ta(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function nT(e){e.body&&!e.body.locked&&await e.body.cancel()}function rT(e,t){if(!e&&!t)return;if(!t)return e;let n=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,s]of t)n.set(r,s);return n}function B3(e){let t=Object.create(null);return e.forEach((n,r)=>{t[r.toLowerCase()]=n}),t}async function _3(e,t,n,r,s){let i=B3(e.headers);if(n>0){let l=e.headers.get("content-length");if(l){let c=parseInt(l,10);if(!Number.isNaN(c)&&c>n)throw new Ys(n)}}let o;if(n>0&&e.body){let l=e.body.getReader(),c=[],u=0;try{for(;;){let{done:d,value:p}=await Zp(l.read(),r);if(d)break;if(p){if(u+=p.byteLength,u>n)throw await l.cancel(),new Ys(n);c.push(p)}}}catch(d){throw r?.aborted&&await l.cancel(ta(r)).catch(()=>{}),d}o=new Uint8Array(u);let f=0;for(let d of c)o.set(d,f),f+=d.byteLength}else{let l=await Zp(e.arrayBuffer(),r);if(n>0&&l.byteLength>n)throw new Ys(n);o=new Uint8Array(l)}let a={status:e.status,statusText:e.statusText,headers:i,body:o,url:t};return s&&s.length>0&&(a.redirectChain=s),a}vn();St();Z();function vc(e,t){if(e.length>t||U(e)>t)throw new C(`script input size limit exceeded (${t} bytes)`,"string_length")}var Xp=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;abortOnUnresolvedCommands=!1;invokeToolFn;transformPlugins=[];state;constructor(t={}){if(this.limits=bl({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}},t.executionLimitProfile),t.fs&&t.files)throw new Error("Bash: options.files is ignored when options.fs is provided; write the files into your filesystem directly or drop options.fs");let n=t.fs??new lr(t.files,{maxTotalBytes:this.limits.maxFileSystemBytes});this.fs=n,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),s=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
|
|
1550
1550
|
`],["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(t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=Kp(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.abortOnUnresolvedCommands=t.abortOnUnresolvedCommands??!1,this.coverageWriter=t.coverage,this.state={env:s,arrays:new Map,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",jf(this.state.options)),this.state.env.set("BASHOPTS",Hf(this.state.shoptOptions)),B6(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&n instanceof lr)try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of S6(t.commands))this.registerBundledCommand(o);if(t.fetch||t.network)for(let o of A6())this.registerBundledCommand(o);if(t.python)for(let o of C6())this.registerBundledCommand(o);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let o of v6())this.registerBundledCommand(o);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap),i.invokeTool&&(this.invokeToolFn=i.invokeTool)}if(t.customCommands)for(let o of t.customCommands)if(T6(o)){let a=R6(o);this.registerCommandInternal(a,!0)}else this.registerCommandInternal(o,!0)}registerCommand(t){this.registerCommandInternal(t,!0)}registerBundledCommand(t){this.registerCommandInternal(t,!1)}registerCommandInternal(t,n,r=n?t.trusted??!0:t.trusted){let s=this.commands.get(t.name),i=n?s?.internalOriginalCommand??(s&&!s.internalIsExtension?s:void 0):void 0,o={name:t.name,trusted:r,internalIsExtension:n,internalOriginalCommand:i,execute:(l,c)=>t.execute(l,c)};this.commands.set(t.name,o);let a=this.fs;if(typeof a.writeFileSync=="function"){let l=`#!/bin/bash
|
|
1551
1551
|
# Built-in command: ${t.name}
|
|
1552
1552
|
`;try{a.writeFileSync(`/bin/${t.name}`,l)}catch{}try{a.writeFileSync(`/usr/bin/${t.name}`,l)}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=U3(t.stdout),t.stderr=U3(t.stderr),t}async exec(t,n){let r=new xl(this.limits,n?.signal,this.abortOnUnresolvedCommands),s;try{s=await this.execInScope(t,n,r,0,n?.signal,!1,!1)}catch(o){try{await r.close()}catch{}throw o}let i=s;try{await r.close()}catch{i={...s,stderr:`${s.stderr}bash: execution cleanup failed
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
2
|
-
import{
|
|
2
|
+
import{d as l,e as u}from"./chunk-PS2RJNZZ.js";import{randomBytes as h}from"node:crypto";var d=class{options;protocolToken=h(16).toString("hex");deadline;cleanups=[];cancelHandler;canceledReason;closed=!1;constructor(t){this.options=t,this.deadline=Date.now()+t.timeoutMs}arm(t){if(this.cancelHandler)throw new Error("worker request is already armed");this.cancelHandler=t;let a=this.options.signal;if(a){let i=()=>this.cancel("abort");a.addEventListener("abort",i,{once:!0}),this.cleanups.push(()=>a.removeEventListener("abort",i)),a.aborted&&this.cancel("abort")}if(!this.canceledReason){let i=l(()=>this.cancel("timeout"),Math.max(0,this.options.timeoutMs));i!==void 0&&this.cleanups.push(()=>u(i))}}get isCanceled(){return this.canceledReason!==void 0}remainingTimeMs(){return Math.max(0,this.deadline-Date.now())}timeoutMessage(t="Execution"){return`${t} timeout: exceeded ${this.options.timeoutMs}ms limit`}abortMessage(){return"Execution aborted"}assertMessageSize(t,a){if(f(t,this.options.maxMessageBytes)>this.options.maxMessageBytes)throw new Error(`${this.options.commandName}: worker ${a} exceeds ${this.options.maxMessageBytes} byte limit`)}async terminate(t){if(!t)return!0;try{return await t.terminate(),!0}catch{return!1}}close(){if(!this.closed){this.closed=!0;for(let t=this.cleanups.length-1;t>=0;t--)this.cleanups[t]();this.cleanups.length=0,this.cancelHandler=void 0}}cancel(t){this.closed||this.canceledReason||(this.canceledReason=t,this.cancelHandler?.(t))}};function f(o,t){let a=function*(n){for(let e in n)Object.hasOwn(n,e)&&(yield[e,n[e]])},i=[{kind:"value",value:o}],c=new WeakSet,s=0;for(;i.length>0&&s<=t;){let n=i.pop();if(!n)break;if(n.kind==="array"){n.index<n.value.length&&(i.push({...n,index:n.index+1}),i.push({kind:"value",value:n.value[n.index]}));continue}if(n.kind==="object"){let r=n.iterator.next();r.done||(s+=8+Buffer.byteLength(r.value[0],"utf8"),i.push(n),i.push({kind:"value",value:r.value[1]}));continue}let e=n.value;if(e==null)s+=4;else if(typeof e=="string")s+=Buffer.byteLength(e,"utf8");else if(typeof e=="number"||typeof e=="bigint")s+=8;else if(typeof e=="boolean")s+=1;else if(typeof e=="object"){if(c.has(e))continue;if(c.add(e),ArrayBuffer.isView(e))s+=e.byteLength;else if(e instanceof ArrayBuffer||e instanceof SharedArrayBuffer)s+=e.byteLength;else if(Array.isArray(e)){if(e.length>Math.floor((t-s)/8))return t+1;s+=e.length*8,i.push({kind:"array",value:e,index:0})}else i.push({kind:"object",iterator:a(e)})}}return s}export{d as a};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
2
|
-
import{a as g}from"./chunk-FOCWZZDE.js";import{a as
|
|
3
|
-
`,exitCode:1};let f="",
|
|
2
|
+
import{a as g}from"./chunk-FOCWZZDE.js";import{a as u}from"./chunk-QIQMJJZ4.js";import{a as p}from"./chunk-W5DWRFSU.js";var y={recursive:{short:"r",long:"recursive",type:"boolean"},recursiveUpper:{short:"R",type:"boolean"},force:{short:"f",long:"force",type:"boolean"},verbose:{short:"v",long:"verbose",type:"boolean"}},$={name:"rm",async execute(d,s){let e=u("rm",d,y);if(!e.ok)return e.error;let l=e.result.flags.recursive||e.result.flags.recursiveUpper,a=e.result.flags.force,v=e.result.flags.verbose,c=e.result.positional;if(c.length===0)return a?{stdout:"",stderr:"",exitCode:0}:{stdout:"",stderr:`rm: missing operand
|
|
3
|
+
`,exitCode:1};let f="",o="",i=0;for(let r of c)try{let n=s.fs.resolvePath(s.cwd,r);if((await s.fs.stat(n)).isDirectory&&!l){o+=`rm: cannot remove '${r}': Is a directory
|
|
4
4
|
`,i=1;continue}await s.fs.rm(n,{recursive:l,force:a}),v&&(f+=`removed '${r}'
|
|
5
|
-
`)}catch(n){let
|
|
6
|
-
`:
|
|
7
|
-
`:
|
|
8
|
-
`,i=1}return{stdout:f,stderr:
|
|
5
|
+
`)}catch(n){let t=p(n),m=t.startsWith("ENOENT");if(a&&m)continue;m?o+=`rm: cannot remove '${r}': No such file or directory
|
|
6
|
+
`:t.includes("ENOTEMPTY")||t.includes("not empty")?o+=`rm: cannot remove '${r}': Directory not empty
|
|
7
|
+
`:o+=`rm: cannot remove '${r}': ${g(t)}
|
|
8
|
+
`,i=1}return{stdout:f,stderr:o,exitCode:i}}},C={name:"rm",flags:[{flag:"-r",type:"boolean"},{flag:"-R",type:"boolean"},{flag:"-f",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0};export{$ as a,C as b};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
2
|
-
import{a as W}from"./chunk-
|
|
2
|
+
import{a as W}from"./chunk-6IA4DXG2.js";import{c as $}from"./chunk-BKUWXPEM.js";import{b as C}from"./chunk-ZBUZKIPX.js";import{a as V}from"./chunk-7IJWBG4I.js";import{d as I}from"./chunk-GN6CQ3J4.js";import{a as B,b}from"./chunk-FOCWZZDE.js";import{a as x}from"./chunk-W5DWRFSU.js";import{a as N,b as R}from"./chunk-QAYAQNCG.js";import{existsSync as ce}from"node:fs";import{dirname as de,join as T,sep as Q}from"node:path";import{fileURLToPath as me}from"node:url";import{Worker as he}from"node:worker_threads";import pe from"sql.js";function K(e,t){return e==null?Buffer.byteLength(t,"utf8"):e instanceof Uint8Array||Buffer.isBuffer(e)?e.byteLength:Buffer.byteLength(String(e),"utf8")}function X(e,t,r){let n=r.maxOutputSize??Number.MAX_SAFE_INTEGER,s=Buffer.byteLength(r.separator,"utf8");s+=Buffer.byteLength(r.newline,"utf8");for(let a of e)s+=Buffer.byteLength(a,"utf8");for(let a of t){s+=a.length*16;for(let i of a)s+=K(i,r.nullValue);if(s>n)break}let o=s*8+(t.length+3)*(e.length+3)*16;if(!Number.isSafeInteger(o)||o>n)throw new Error(`formatted output exceeds ${n} byte limit`);return n}function _(e,t,r){let n=X(e,t,r),s;switch(r.mode){case"list":s=Y(e,t,r);break;case"csv":s=Z(e,t,r);break;case"json":s=te(e,t);break;case"line":s=re(e,t,r);break;case"column":s=ne(e,t,r);break;case"table":s=se(e,t,r);break;case"markdown":s=oe(e,t,r);break;case"tabs":s=ie(e,t,r);break;case"box":s=ae(e,t,r);break;case"quote":s=le(e,t,r);break;case"html":s=fe(e,t,r);break;case"ascii":s=ue(e,t,r);break}if(Buffer.byteLength(s,"utf8")>n)throw new Error(`formatted output exceeds ${n} byte limit`);return s}function m(e,t){return e==null?t:e instanceof Uint8Array||Buffer.isBuffer(e)?Buffer.from(e).toString("utf8"):typeof e=="number"&&!Number.isInteger(e)?e.toPrecision(17).replace(/\.?0+$/,""):String(e)}function Y(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.join(r.separator));for(let s of t)n.push(s.map(o=>m(o,r.nullValue)).join(r.separator));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function Z(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.map(v).join(","));for(let s of t)n.push(s.map(o=>v(m(o,r.nullValue))).join(","));return n.length>0?`${n.join(`
|
|
3
3
|
`)}
|
|
4
4
|
`:""}function v(e){return e.includes(",")||e.includes('"')||e.includes("'")||e.includes(`
|
|
5
5
|
`)?`"${e.replace(/"/g,'""')}"`:e}function F(e){return e.toPrecision(17).replace(/\.?0+$/,"")}function ee(e){return e===null?"null":typeof e=="number"?Number.isInteger(e)?String(e):F(e):JSON.stringify(e)}function te(e,t){return t.length===0?"":`[${t.map(n=>`{${e.map((o,a)=>`${JSON.stringify(o)}:${ee(n[a])}`).join(",")}}`).join(`,
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
2
|
+
import{b as a}from"./chunk-ZBUZKIPX.js";var r=globalThis.setTimeout.bind(globalThis),l=globalThis.clearTimeout.bind(globalThis),T=globalThis.setInterval.bind(globalThis),f=globalThis.clearInterval.bind(globalThis);function u(e){return typeof e!="function"?e:a.bindCurrentContext(e)}var b=((e,n,...i)=>r(u(e),n,...i)),d=l,I=((e,n,...i)=>r(e,n,...i)),c=2147483647;function _(e,n){if(n===Number.POSITIVE_INFINITY)return;let i=u(e),t={cleared:!1,remainingMs:Math.max(0,n),timer:void 0},o=()=>{if(t.cleared)return;let s=Math.min(t.remainingMs,c);t.timer=r(()=>{t.cleared||(t.remainingMs-=s,t.remainingMs>0?o():i())},s)};return o(),t}function g(e){e&&(e.cleared=!0,e.timer!==void 0&&l(e.timer))}export{b as a,d as b,I as c,_ as d,g as e};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
2
|
-
import{a as p}from"./chunk-SX2HC7SO.js";import{a as n,b as l}from"./chunk-
|
|
2
|
+
import{a as p}from"./chunk-SX2HC7SO.js";import{a as n,b as l}from"./chunk-PS2RJNZZ.js";import{a as m,b as d}from"./chunk-QAYAQNCG.js";var f={name:"sleep",summary:"delay for a specified amount of time",usage:"sleep NUMBER[SUFFIX]",description:`Pause for NUMBER seconds. SUFFIX may be:
|
|
3
3
|
s - seconds (default)
|
|
4
4
|
m - minutes
|
|
5
5
|
h - hours
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{createRequire} from"node:module";const require=createRequire(import.meta.url);
|
|
2
|
+
import{b as f}from"./chunk-WNH3HOQA.js";import{a as O,b as h}from"./chunk-KIGPB52X.js";import{d as F,e as g}from"./chunk-PS2RJNZZ.js";import{a as A}from"./chunk-L2UW7DWF.js";import{b as m}from"./chunk-ZBUZKIPX.js";import{a as T,b as w}from"./chunk-FOCWZZDE.js";var n={NOOP:0,READ_FILE:1,WRITE_FILE:2,STAT:3,READDIR:4,MKDIR:5,RM:6,EXISTS:7,APPEND_FILE:8,SYMLINK:9,READLINK:10,LSTAT:11,CHMOD:12,REALPATH:13,RENAME:14,COPY_FILE:15,WRITE_FILE_RANGE:17,READ_RESULT_RANGE:18,WRITE_STDOUT:100,WRITE_STDERR:101,EXIT:102,HTTP_REQUEST:200,EXEC_COMMAND:300,INVOKE_TOOL:400},a={PENDING:0,READY:1,SUCCESS:2,ERROR:3},l={NONE:0,NOT_FOUND:1,IS_DIRECTORY:2,NOT_DIRECTORY:3,EXISTS:4,PERMISSION_DENIED:5,INVALID_PATH:6,IO_ERROR:7,TIMEOUT:8,NETWORK_ERROR:9,NETWORK_NOT_CONFIGURED:10,NOT_EMPTY:11},i={OP_CODE:0,STATUS:4,PATH_LENGTH:8,DATA_LENGTH:12,RESULT_LENGTH:16,ERROR_CODE:20,FLAGS:24,MODE:28,PATH_BUFFER:32,DATA_BUFFER:4128},E={CONTROL_REGION:32,PATH_BUFFER:4096,DATA_BUFFER:8388608,TOTAL:8392736},R={NONE:0,RECURSIVE:1,FORCE:2,MKDIR_RECURSIVE:1},u={IS_FILE:0,IS_DIRECTORY:1,IS_SYMLINK:2,MODE:4,SIZE:8,MTIME:16,TOTAL:24};function x(){return new O(E.TOTAL)}var S=class{int32View;uint8View;dataView;constructor(t){this.int32View=new Int32Array(t),this.uint8View=new Uint8Array(t),this.dataView=new DataView(t)}getOpCode(){return h.load(this.int32View,i.OP_CODE/4)}setOpCode(t){h.store(this.int32View,i.OP_CODE/4,t)}getStatus(){return h.load(this.int32View,i.STATUS/4)}setStatus(t){h.store(this.int32View,i.STATUS/4,t)}getPathLength(){return h.load(this.int32View,i.PATH_LENGTH/4)}setPathLength(t){h.store(this.int32View,i.PATH_LENGTH/4,t)}getDataLength(){return h.load(this.int32View,i.DATA_LENGTH/4)}setDataLength(t){h.store(this.int32View,i.DATA_LENGTH/4,t)}getResultLength(){return h.load(this.int32View,i.RESULT_LENGTH/4)}setResultLength(t){h.store(this.int32View,i.RESULT_LENGTH/4,t)}getErrorCode(){return h.load(this.int32View,i.ERROR_CODE/4)}setErrorCode(t){h.store(this.int32View,i.ERROR_CODE/4,t)}getFlags(){return h.load(this.int32View,i.FLAGS/4)}setFlags(t){h.store(this.int32View,i.FLAGS/4,t)}getMode(){return h.load(this.int32View,i.MODE/4)}setMode(t){h.store(this.int32View,i.MODE/4,t)}getPath(){let t=this.getPathLength(),e=this.uint8View.slice(i.PATH_BUFFER,i.PATH_BUFFER+t);return new TextDecoder().decode(e)}setPath(t){let e=new TextEncoder().encode(t);if(e.length>E.PATH_BUFFER)throw new Error(`Path too long: ${e.length} > ${E.PATH_BUFFER}`);this.uint8View.set(e,i.PATH_BUFFER),this.setPathLength(e.length)}getData(){let t=this.getDataLength();return this.uint8View.slice(i.DATA_BUFFER,i.DATA_BUFFER+t)}setData(t){if(t.length>E.DATA_BUFFER)throw new Error(`Data too large: ${t.length} > ${E.DATA_BUFFER}`);this.uint8View.set(t,i.DATA_BUFFER),this.setDataLength(t.length)}getDataAsString(){let t=this.getData();return new TextDecoder().decode(t)}setDataFromString(t){let e=new TextEncoder().encode(t);this.setData(e)}getResult(){let t=this.getResultLength();return this.uint8View.slice(i.DATA_BUFFER,i.DATA_BUFFER+t)}setResult(t){if(t.length>E.DATA_BUFFER)throw new Error(`Result too large: ${t.length} > ${E.DATA_BUFFER}`);this.uint8View.set(t,i.DATA_BUFFER),this.setResultLength(t.length)}setResultPrefix(t){if(t.length>2147483647)throw new Error(`Result too large: ${t.length} exceeds int32`);let e=Math.min(t.length,E.DATA_BUFFER);this.uint8View.set(t.subarray(0,e),i.DATA_BUFFER),this.setResultLength(t.length)}getResultAsString(){let t=this.getResult();return new TextDecoder().decode(t)}setResultFromString(t){let e=new TextEncoder().encode(t);this.setResult(e)}encodeStat(t){this.uint8View[i.DATA_BUFFER+u.IS_FILE]=t.isFile?1:0,this.uint8View[i.DATA_BUFFER+u.IS_DIRECTORY]=t.isDirectory?1:0,this.uint8View[i.DATA_BUFFER+u.IS_SYMLINK]=t.isSymbolicLink?1:0,this.dataView.setInt32(i.DATA_BUFFER+u.MODE,t.mode,!0);let e=Math.min(t.size,Number.MAX_SAFE_INTEGER);this.dataView.setFloat64(i.DATA_BUFFER+u.SIZE,e,!0),this.dataView.setFloat64(i.DATA_BUFFER+u.MTIME,t.mtime.getTime(),!0),this.setResultLength(u.TOTAL)}decodeStat(){return{isFile:this.uint8View[i.DATA_BUFFER+u.IS_FILE]===1,isDirectory:this.uint8View[i.DATA_BUFFER+u.IS_DIRECTORY]===1,isSymbolicLink:this.uint8View[i.DATA_BUFFER+u.IS_SYMLINK]===1,mode:this.dataView.getInt32(i.DATA_BUFFER+u.MODE,!0),size:this.dataView.getFloat64(i.DATA_BUFFER+u.SIZE,!0),mtime:new Date(this.dataView.getFloat64(i.DATA_BUFFER+u.MTIME,!0))}}waitForReady(t){return h.wait(this.int32View,i.STATUS/4,a.PENDING,t)}waitForReadyAsync(t){return h.waitAsync(this.int32View,i.STATUS/4,a.PENDING,t)}async waitUntilReady(t){let e=Date.now();for(;;){let o=this.getStatus();if(o===a.READY)return!0;let s=Date.now()-e;if(s>=t)return!1;let r=t-s,c=h.waitAsync(this.int32View,i.STATUS/4,o,r);if(c.async&&await c.value==="timed-out")return!1}}waitForResult(t){return h.wait(this.int32View,i.STATUS/4,a.READY,t)}notify(){return h.notify(this.int32View,i.STATUS/4)}reset(){this.setOpCode(n.NOOP),this.setStatus(a.PENDING),this.setPathLength(0),this.setDataLength(0),this.setResultLength(0),this.setErrorCode(l.NONE),this.setFlags(R.NONE),this.setMode(0)}};var D=class{fs;cwd;commandName;secureFetch;maxOutputSize;exec;invokeTool;protocol;running=!1;output={stdout:"",stderr:"",exitCode:0};outputLimitExceeded=!1;startTime=0;timeoutMs=0;lastResult=null;constructor(t,e,o,s,r=void 0,c=0,d=void 0,p=void 0){this.fs=e,this.cwd=o,this.commandName=s,this.secureFetch=r,this.maxOutputSize=c,this.exec=d,this.invokeTool=p,this.protocol=new S(t)}remainingMs(){return Math.max(0,this.timeoutMs-(Date.now()-this.startTime))}raceDeadline(t){let e=this.remainingMs();if(e<=0)return this.running=!1,this.output.exitCode=124,this.output.stderr+=`
|
|
3
|
+
${this.commandName}: execution timeout exceeded
|
|
4
|
+
`,Promise.reject(new Error("Operation timed out"));let o=t();return e===Number.POSITIVE_INFINITY?o:new Promise((s,r)=>{let c=F(()=>{this.running=!1,this.output.exitCode=124,this.output.stderr+=`
|
|
5
|
+
${this.commandName}: execution timeout exceeded
|
|
6
|
+
`,r(new Error("Operation timed out"))},e);o.then(d=>{g(c),s(d)},d=>{g(c),r(d)})})}async run(t){for(this.running=!0,this.startTime=Date.now(),this.timeoutMs=t;this.running;){if(Date.now()-this.startTime>=t){this.output.stderr+=`
|
|
7
|
+
${this.commandName}: execution timeout exceeded
|
|
8
|
+
`,this.output.exitCode=124;break}let o=this.remainingMs();if(!await this.protocol.waitUntilReady(o)){this.output.stderr+=`
|
|
9
|
+
${this.commandName}: execution timeout exceeded
|
|
10
|
+
`,this.output.exitCode=124;break}if(!this.running)break;let r=this.protocol.getOpCode();await this.handleOperation(r),this.protocol.notify()}return this.output}stop(){this.running=!1,this.lastResult=null,this.protocol.setStatus(a.READY),this.protocol.notify()}async handleOperation(t){try{switch(t){case n.READ_FILE:await this.handleReadFile();break;case n.WRITE_FILE:await this.handleWriteFile();break;case n.STAT:await this.handleStat();break;case n.LSTAT:await this.handleLstat();break;case n.READDIR:await this.handleReaddir();break;case n.MKDIR:await this.handleMkdir();break;case n.READ_RESULT_RANGE:this.handleReadResultRange();break;case n.WRITE_FILE_RANGE:await this.handleWriteFileRange();break;case n.RM:await this.handleRm();break;case n.EXISTS:await this.handleExists();break;case n.APPEND_FILE:await this.handleAppendFile();break;case n.SYMLINK:await this.handleSymlink();break;case n.READLINK:await this.handleReadlink();break;case n.CHMOD:await this.handleChmod();break;case n.REALPATH:await this.handleRealpath();break;case n.RENAME:await this.handleRename();break;case n.COPY_FILE:await this.handleCopyFile();break;case n.WRITE_STDOUT:this.handleWriteStdout();break;case n.WRITE_STDERR:this.handleWriteStderr();break;case n.EXIT:this.handleExit();break;case n.HTTP_REQUEST:await this.handleHttpRequest();break;case n.EXEC_COMMAND:await this.handleExecCommand();break;case n.INVOKE_TOOL:await this.handleInvokeTool();break;default:this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setStatus(a.ERROR)}}catch(e){this.setErrorFromException(e)}}publishResult(t){let e=typeof t=="string"?new TextEncoder().encode(t):t;this.lastResult=e,this.protocol.setResultPrefix(e),this.protocol.setStatus(a.SUCCESS)}handleReadResultRange(){let t=this.protocol.getFlags(),e=this.protocol.getMode(),o=this.lastResult;if(!o||t>o.length){this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setResultFromString("No retained result for range read"),this.protocol.setStatus(a.ERROR);return}this.protocol.setResult(o.subarray(t,t+e)),this.protocol.setStatus(a.SUCCESS)}resolvePath(t){return this.fs.resolvePath(this.cwd,t)}async handleReadFile(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readFileBuffer(t);this.publishResult(e)}catch(e){this.setErrorFromException(e)}}async handleWriteFileRange(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getFlags(),o=this.protocol.getData();try{if(e===0)await this.fs.writeFile(t,o);else{let s=await this.fs.stat(t);if(s.size!==e)throw new Error(`EIO: non-sequential range write to '${t}': offset ${e} != size ${s.size}`);await this.fs.appendFile(t,o)}this.protocol.setStatus(a.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleWriteFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getData();try{await this.fs.writeFile(t,e),this.protocol.setStatus(a.SUCCESS)}catch(o){this.setErrorFromException(o)}}async handleStat(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.stat(t);this.protocol.encodeStat(e),this.protocol.setStatus(a.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleLstat(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.lstat(t);this.protocol.encodeStat(e),this.protocol.setStatus(a.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleReaddir(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readdir(t);this.publishResult(JSON.stringify(e))}catch(e){this.setErrorFromException(e)}}async handleMkdir(){let t=this.resolvePath(this.protocol.getPath()),o=(this.protocol.getFlags()&R.MKDIR_RECURSIVE)!==0;try{await this.fs.mkdir(t,{recursive:o}),this.protocol.setStatus(a.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleRm(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getFlags(),o=(e&R.RECURSIVE)!==0,s=(e&R.FORCE)!==0;try{await this.fs.rm(t,{recursive:o,force:s}),this.protocol.setStatus(a.SUCCESS)}catch(r){this.setErrorFromException(r)}}async handleExists(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.exists(t);this.protocol.setResult(new Uint8Array([e?1:0])),this.protocol.setStatus(a.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleAppendFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getData();try{await this.fs.appendFile(t,e),this.protocol.setStatus(a.SUCCESS)}catch(o){this.setErrorFromException(o)}}async handleSymlink(){let t=this.protocol.getPath(),e=this.protocol.getDataAsString(),o=this.resolvePath(t);try{await this.fs.symlink(e,o),this.protocol.setStatus(a.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleReadlink(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readlink(t);this.protocol.setResultFromString(e),this.protocol.setStatus(a.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleChmod(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getMode();try{await this.fs.chmod(t,e),this.protocol.setStatus(a.SUCCESS)}catch(o){this.setErrorFromException(o)}}async handleRealpath(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.realpath(t);this.protocol.setResultFromString(e),this.protocol.setStatus(a.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleRename(){let t=this.resolvePath(this.protocol.getPath()),e=this.resolvePath(this.protocol.getDataAsString());try{await this.fs.mv(t,e),this.protocol.setStatus(a.SUCCESS)}catch(o){this.setErrorFromException(o)}}async handleCopyFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.resolvePath(this.protocol.getDataAsString());try{await this.fs.cp(t,e),this.protocol.setStatus(a.SUCCESS)}catch(o){this.setErrorFromException(o)}}handleWriteStdout(){let t=this.protocol.getDataAsString();if(!this.tryAppendOutput("stdout",t)){this.outputLimitExceeded=!0,this.output.exitCode=1,this.appendOutputLimitError(),this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setResultFromString("Output size limit exceeded"),this.protocol.setStatus(a.ERROR);return}this.protocol.setStatus(a.SUCCESS)}handleWriteStderr(){let t=this.protocol.getDataAsString();if(!this.tryAppendOutput("stderr",t)){this.outputLimitExceeded=!0,this.output.exitCode=1,this.appendOutputLimitError(),this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setResultFromString("Output size limit exceeded"),this.protocol.setStatus(a.ERROR);return}this.protocol.setStatus(a.SUCCESS)}handleExit(){let t=this.protocol.getFlags();this.outputLimitExceeded?this.output.exitCode===0&&(this.output.exitCode=1):this.output.exitCode=t,this.protocol.setStatus(a.SUCCESS),this.running=!1}tryAppendOutput(t,e){return this.outputLimitExceeded?!1:this.maxOutputSize<=0?(t==="stdout"?this.output.stdout+=e:this.output.stderr+=e,!0):this.output.stdout.length+this.output.stderr.length+e.length>this.maxOutputSize?!1:(t==="stdout"?this.output.stdout+=e:this.output.stderr+=e,!0)}appendOutputLimitError(){if(this.maxOutputSize<=0)return;let t=`${this.commandName}: total output size exceeded (>${this.maxOutputSize} bytes), increase executionLimits.maxOutputSize
|
|
11
|
+
`,e=t.length>this.maxOutputSize?t.slice(0,this.maxOutputSize):t;if(this.output.stderr.includes("total output size exceeded"))return;let s=this.output.stdout.length+this.output.stderr.length+e.length-this.maxOutputSize;if(s>0)if(this.output.stdout.length>=s)this.output.stdout=this.output.stdout.slice(0,this.output.stdout.length-s);else{let r=s-this.output.stdout.length;this.output.stdout="",r>=this.output.stderr.length?this.output.stderr="":this.output.stderr=this.output.stderr.slice(0,this.output.stderr.length-r)}this.output.stderr+=e}async handleHttpRequest(){let t=this.secureFetch;if(!t){this.protocol.setErrorCode(l.NETWORK_NOT_CONFIGURED),this.protocol.setResultFromString("Network access not configured. Enable network in Bash options."),this.protocol.setStatus(a.ERROR);return}let e=this.protocol.getPath(),o=this.protocol.getDataAsString();try{let s=o?JSON.parse(o):{},r=this.remainingMs(),c=await this.raceDeadline(()=>t(e,{method:s.method,headers:s.headers,body:s.body,timeoutMs:r})),d=JSON.stringify({status:c.status,statusText:c.statusText,headers:c.headers,bodyBase64:f(c.body,"base64"),url:c.url});this.publishResult(d)}catch(s){let r=T(s instanceof Error?s.message:String(s));this.protocol.setErrorCode(l.NETWORK_ERROR),this.protocol.setResultFromString(r),this.protocol.setStatus(a.ERROR)}}async handleExecCommand(){let t=this.exec;if(!t){this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setResultFromString("Command execution not available in this context."),this.protocol.setStatus(a.ERROR);return}let e=this.protocol.getPath(),o=this.protocol.getDataAsString(),s=new AbortController;try{let r={cwd:this.cwd,signal:s.signal};if(o){let p=JSON.parse(o);p.stdin&&(r.stdin=p.stdin),p.args&&Array.isArray(p.args)&&(r.args=p.args.map(C=>String(C)),e=A([e]))}let c=await this.raceDeadline(()=>t(e,r)),d=JSON.stringify({stdout:c.stdout,stderr:c.stderr,exitCode:c.exitCode});this.publishResult(d)}catch(r){s.abort();let c=r instanceof Error?r.message:String(r);this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setResultFromString(c),this.protocol.setStatus(a.ERROR)}}async handleInvokeTool(){let t=this.invokeTool;if(!t){this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setResultFromString("Tool invocation not available in this context."),this.protocol.setStatus(a.ERROR);return}let e=this.protocol.getPath(),o=this.protocol.getDataAsString();try{let s=await this.raceDeadline(()=>m.runTrustedAsync(()=>t(e,o)));this.publishResult(s)}catch(s){let r=w(s instanceof Error?s.message:String(s));this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setResultFromString(r),this.protocol.setStatus(a.ERROR)}}setErrorFromException(t){let e=t instanceof Error?t.message:String(t),o=T(e),s=l.IO_ERROR,r=e.toLowerCase();r.includes("no such file")||r.includes("not found")||r.includes("enoent")?s=l.NOT_FOUND:r.includes("is a directory")||r.includes("eisdir")?s=l.IS_DIRECTORY:r.includes("not a directory")||r.includes("enotdir")?s=l.NOT_DIRECTORY:r.includes("not empty")||r.includes("enotempty")?s=l.NOT_EMPTY:r.includes("already exists")||r.includes("eexist")?s=l.EXISTS:(r.includes("permission")||r.includes("eperm")||r.includes("eacces"))&&(s=l.PERMISSION_DENIED),this.protocol.setErrorCode(s),this.protocol.setResultFromString(o),this.protocol.setStatus(a.ERROR)}};export{x as a,D as b};
|