brsh 3.10.1 → 3.10.2

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/dist/wbt.min.js CHANGED
@@ -2,7 +2,7 @@
2
2
  `&&r++,r++;continue}if(i===127||i===8){n.push(`Backspace`),r++;continue}if(i===9){n.push(`Tab`),r++;continue}if(i>=1&&i<=26){n.push(`^`+String.fromCharCode(i+64)),r++;continue}n.push(e),r++}return n}var a=class extends r{constructor(e={}){super(),this.isTTY=e.isTTY!==!1,this.readable=!0,this.writable=!0,this.columns=e.columns||80,this.rows=e.rows||24,this.isRaw=!1,this._encoding=null,this._onWrite=e.onWrite||null}write(e,t,n){if(e==null)return!0;typeof this._onWrite==`function`&&this._onWrite(e),this._isPushing=!0;try{this.emit(`data`,this._formatChunk(e))}finally{this._isPushing=!1}return typeof t==`function`?t():typeof n==`function`&&n(),!0}pushData(e){if(e!=null){this._isPushing=!0;try{this.emit(`data`,this._formatChunk(e))}finally{this._isPushing=!1}}}_formatChunk(e){return this._encoding?typeof e==`string`?e:e instanceof Uint8Array||v!==void 0&&v.isBuffer(e)?new TextDecoder().decode(e):String(e):e}setRawMode(e){return this.isRaw=!!e,this}setEncoding(e){return this._encoding=e,this}getWindowSize(){return[this.columns,this.rows]}resize(e,t){this.columns=e,this.rows=t,this.emit(`resize`)}resume(){return this}pause(){return this}pipe(e){return this.on(`data`,t=>e.write(t)),e}unpipe(){return this}end(e,t,n){return e!=null&&this.write(e,typeof t==`string`?t:void 0),this.emit(`end`),typeof t==`function`?t():typeof n==`function`&&n(),this}destroy(){this.removeAllListeners()}toString(){return``}valueOf(){return``}};function o(e){if(!e||e._managesOwnStdinCapture||!e.stdinStream||typeof e.stdinStream.listenerCount!=`function`)return!1;let t=e.stdinStream.listenerCount(`data`);return t===0?!1:e._onStdinStreamData&&typeof e.stdinStream.listeners==`function`?t>+!!e.stdinStream.listeners(`data`).includes(e._onStdinStreamData):t>0}t.exports={TtyStream:a,parseVtKeys:i,hasCustomStdinListener:o}})),U=t(((e,t)=>{var n=z(),r=V(),{TtyStream:i,parseVtKeys:a}=H(),o=n.EventEmitter||n.default||n;t.exports=class extends o{constructor(e,t){super(),this.arguments=e,this.result=new r,this.context=t||null;let n=this.context&&typeof this.context.getVar==`function`&&parseInt(this.context.getVar(`COLUMNS`),10)||80,o=this.context&&typeof this.context.getVar==`function`&&parseInt(this.context.getVar(`LINES`),10)||24;this.stdinStream=new i({columns:n,rows:o}),this.stdin=this.stdinStream,this.stdout=new i({columns:n,rows:o,onWrite:e=>this.emit(`stdout`,e)}),this.stderr=new i({columns:n,rows:o,onWrite:e=>this.emit(`stderr`,e)}),this._onStdinStreamData=e=>{if(!this.captureInput)return;let t=a(e);for(let e of t){if(e===`^C`&&!(this.stdinStream&&this.stdinStream.isRaw)){this.kill(`SIGINT`);return}!this.interactive&&!this.stdinStream.isRaw&&(e===`Enter`?this.stdout.write(`\r
3
3
  `):e===`Backspace`?this.stdout.write(`\b \b`):e.length===1&&this.stdout.write(e)),this.onInput(e)}},this.stdinStream.on(`data`,this._onStdinStreamData)}get name(){return`unnamed`}run(){return Promise.reject(`Command not implemented...`)}kill(e=`SIGINT`){let t=typeof e==`number`?e:{SIGHUP:129,SIGINT:130,SIGQUIT:131,SIGKILL:137,SIGTERM:143,SIGWINCH:156}[e]||130;this.exitCode=t,this.emit(`signal`,e),(e===`SIGINT`||e===`SIGTERM`||e===`SIGKILL`||e===`SIGQUIT`)&&(this.emit(`abort`),this._abortController&&this._abortController.abort())}runCommand(){return new Promise(e=>{let t=!1,n=()=>{t||(t=!0,e(this.result))};this.once(`abort`,n),Promise.resolve().then(()=>this.run()).then(r=>{t||(t=!0,this.removeListener(`abort`,n),r&&r.split(/\r?\n/).forEach(e=>this.stdOut=e),e(this.result))}).catch(r=>{if(!t){if(t=!0,this.removeListener(`abort`,n),r&&r.__type)throw r;r&&(this.stdErr=r.message||r),this.result.getExitCode()===0&&(this.exitCode=127),e(this.result)}})})}onInput(e){}set exitCode(e){this.result.exitCode=e}set stdOut(e){this.result.addStdOutLine(e)}set stdErr(e){this.result.addStdErrLine(e)}flush(){this.emit(`flush`,this.result.flush())}}})),W=t(((e,t)=>{var n=U();t.exports=class extends n{constructor(e,t){super(e,t)}}})),ne=t(((e,t)=>{var n=W(),{parseVtKeys:r,hasCustomStdinListener:i}=H();function a(e){return/^#!\/(sh\.js|bin\/(sh|brsh))/.test(e)}t.exports=class extends n{constructor(e,t,n,r=!1){super(t,n),this.script=e,this.source=r}get captureInput(){if(!this.sandbox||!this.sandbox.runningCommand)return!1;let e=this.sandbox.runningCommand;return!!(e.captureInput||e.interactive||e._inAltScreen||i(e))}get interactive(){return!!(this.sandbox&&this.sandbox.runningCommand&&this.sandbox.runningCommand.interactive)}get isRaw(){return!!(this.stdinStream&&this.stdinStream.isRaw||this.sandbox&&this.sandbox.runningCommand&&(this.sandbox.runningCommand.isRaw||this.sandbox.runningCommand.stdinStream&&this.sandbox.runningCommand.stdinStream.isRaw))}get _inAltScreen(){return!!(this.__inAltScreen||this.sandbox&&this.sandbox.runningCommand&&this.sandbox.runningCommand._inAltScreen)}set _inAltScreen(e){this.__inAltScreen=!!e}onInput(e){this.sandbox&&this.sandbox.onInput(e)}kill(e=`SIGINT`){this.sandbox&&this.sandbox.runningCommand&&typeof this.sandbox.runningCommand.kill==`function`&&this.sandbox.runningCommand.kill(e),this.sandbox&&typeof this.sandbox.destroy==`function`&&this.sandbox.destroy(130),super.kill(e)}run(){this._managesOwnStdinCapture=!0;let e=this.context&&this.context.fs||this.fs,t=e&&e[Symbol.for(`brsh.fs.target`)]||e,n=t&&t.isRealFilesystem?{useRealFilesystem:!0}:{filesystem:t&&t.getRaw()||{},permissions:t&&t.getRawPermissions()||{}};this.sandbox=new globalThis.shell({cwd:t&&t.cwd||`/`,...n,subshell:!0}),this.sandbox.context.source(this.context);let o=this.stdout&&this.stdout.columns||this.stdinStream&&this.stdinStream.columns||this.context&&typeof this.context.getVar==`function`&&parseInt(this.context.getVar(`COLUMNS`),10)||80,s=this.stdout&&this.stdout.rows||this.stdinStream&&this.stdinStream.rows||this.context&&typeof this.context.getVar==`function`&&parseInt(this.context.getVar(`LINES`),10)||24;typeof this.sandbox.setTerminalSize==`function`&&this.sandbox.setTerminalSize(o,s),Array.isArray(this.arguments)&&(this.arguments.forEach((e,t)=>this.sandbox.context.setVar(String(t+1),e)),this.sandbox.context.setVar(`#`,String(this.arguments.length)),this.sandbox.context.setVar(`@`,this.arguments.join(` `)),this.sandbox.context.setVar(`*`,this.arguments.join(` `))),this._onStdinStreamData&&this.stdinStream&&typeof this.stdinStream.off==`function`&&this.stdinStream.off(`data`,this._onStdinStreamData);let c=e=>{if(!this.sandbox||!this.sandbox.runningCommand)return;let t=this.sandbox.runningCommand,n=i(t);if(t.interactive||t._inAltScreen||n){t.stdinStream&&t.stdinStream.pushData(e);return}if(t.captureInput&&typeof t.onInput==`function`){let n=!!(t.isRaw||t.stdinStream&&t.stdinStream.isRaw);for(let i of r(e)){if(i===`^C`&&!n){this.kill(`SIGINT`);return}n||(i===`Enter`?this.stdout.write(`\r
4
4
  `):i===`Backspace`?this.stdout.write(`\b \b`):i.length===1&&this.stdout.write(i)),t.onInput(i)}}},l=()=>{this.sandbox&&typeof this.sandbox.setTerminalSize==`function`&&this.stdinStream&&this.sandbox.setTerminalSize(this.stdinStream.columns,this.stdinStream.rows)},u=()=>{this.sandbox&&typeof this.sandbox.setTerminalSize==`function`&&this.stdout&&this.sandbox.setTerminalSize(this.stdout.columns,this.stdout.rows)},d=()=>{this.stdinStream&&typeof this.stdinStream.off==`function`&&(this.stdinStream.off(`data`,c),this.stdinStream.off(`resize`,l)),this.stdout&&typeof this.stdout.off==`function`&&this.stdout.off(`resize`,u)};this.stdinStream&&typeof this.stdinStream.on==`function`&&(this.stdinStream.on(`data`,c),this.stdinStream.on(`resize`,l)),this.stdout&&this.stdout!==this.stdinStream&&typeof this.stdout.on==`function`&&this.stdout.on(`resize`,u),this.sandbox.on(`stdOut`,e=>{this.stdOut=e,this.flush()}),this.sandbox.on(`stdErr`,e=>{this.stdErr=e,this.flush()}),this.sandbox.stdout&&typeof this.sandbox.stdout.on==`function`&&this.sandbox.stdout.on(`data`,e=>{this.stdout&&typeof this.stdout.write==`function`&&this.stdout.write(e)}),this.sandbox.stderr&&typeof this.sandbox.stderr.on==`function`&&this.sandbox.stderr.on(`data`,e=>{this.stderr&&typeof this.stderr.write==`function`&&this.stderr.write(e)}),this._scriptFunctions={};let f=this.script.split(/\r?\n/);if(!a(f[0])){let e=f[0].startsWith(`#!`)?f[0].slice(2).split(/\s/)[0]:f[0];return d(),Promise.reject(`${e}: bad interpreter: No such file or directory`)}let p=this._parseLines(f.slice(1));return this._executeNodes(p).catch(e=>{if(e&&e.__type===`return`)this.sandbox.lastCode=e.code;else if(e&&e.__type===`errexit`)this.sandbox.lastCode=e.code;else if(e&&(e.__type===`break`||e.__type===`continue`))this.stdErr=`${e.__type}: only meaningful in a for or while loop`,this.sandbox.lastCode=1;else return Promise.reject(e)}).finally(()=>{d()}).then(()=>{this.exitCode=this.sandbox.lastCode,this.source&&this.context.source(this.sandbox.context)})}_accumulateLines(e){let t=[],n=null,r=!1,i=!1,a=!1;for(let o=0;o<e.length;o++){let s=e[o];n===null?n=s:a?n+=s:r||i?n+=`
5
- `+s:n+=s;let c=0,l=!1,u=!1;for(;c<s.length;){let e=s[c];if(r)e===`'`&&(r=!1),c++;else if(i)e===`\\`&&c+1<s.length?c+=2:e===`\\`&&c+1===s.length?(l=!0,c++):(e===`"`&&(i=!1),c++);else{if(e===`#`&&(c===0||/\s/.test(s[c-1]))){u=!0;break}e===`\\`&&c+1<s.length?c+=2:e===`\\`&&c+1===s.length?(l=!0,c++):e===`'`?(r=!0,c++):(e===`"`&&(i=!0),c++)}}if(!r&&!l&&!u){let e=s.match(/(\\+)\s*$/);e&&e[1].length%2==1&&(l=!0)}a=l,l&&(n=n.replace(/\\\s*$/,``)),!r&&!i&&!l&&(t.push(n),n=null,a=!1)}return n!==null&&t.push(n),t}_parseLines(e){e=this._accumulateLines(e);let t=[],n=0;for(;n<e.length;){let r=e[n].trim();if(!r||r.startsWith(`#`)){n++;continue}if(r.startsWith(`if `)||r===`if`){let r=this._parseIf(e,n);t.push(r.node),n+=r.consumed;continue}if(r.startsWith(`while `)){let r=this._parseWhile(e,n);t.push(r.node),n+=r.consumed;continue}if(r.startsWith(`for `)){let r=this._parseFor(e,n);t.push(r.node),n+=r.consumed;continue}if(r.startsWith(`case `)||r===`case`){let r=this._parseCase(e,n);t.push(r.node),n+=r.consumed;continue}if(/^(?:function\s+[\w\d_]+|[\w\d_]+\s*\(\s*\))\s*(?:\{.*)?$/.test(r)){let r=this._parseFunction(e,n);t.push(r.node),n+=r.consumed;continue}t.push({type:`command`,line:r}),n++}return t}_parseIf(e,t){let n=e=>e.replace(/^(?:if|elif)\s+/,``).replace(/\s*;\s*then\s*$/,``).replace(/\s+then\s*$/,``).trim(),r=[{condition:n(e[t].trim()),bodyLines:[]}],i=[],a=r[0],o=!1,s=1,c=t+1;for(c<e.length&&e[c].trim()===`then`&&c++;c<e.length;){let t=e[c].trim();if((t.startsWith(`if `)||t===`if`)&&s++,t===`fi`&&(s--,s===0)){c++;break}if(s===1&&t.startsWith(`elif `)){let i={condition:n(t),bodyLines:[]};r.push(i),a=i,c++,c<e.length&&e[c].trim()===`then`&&c++;continue}if(s===1&&t===`else`){o=!0,c++;continue}o?i.push(e[c]):a.bodyLines.push(e[c]),c++}return{node:{type:`if`,clauses:r,elseLines:i},consumed:c-t}}_parseWhile(e,t){let n=e[t].trim().replace(/^while\s+/,``).replace(/\s*;\s*do\s*$/,``).replace(/\s+do\s*$/,``).trim(),r=t+1;r<e.length&&e[r].trim()===`do`&&r++;let i=[],a=1;for(;r<e.length;){let t=e[r].trim();if((t.startsWith(`while `)||t.startsWith(`for `))&&a++,t===`done`&&(a--,a===0)){r++;break}i.push(e[r]),r++}return{node:{type:`while`,condition:n,bodyLines:i},consumed:r-t}}_parseFor(e,t){let n=e[t].trim().replace(/\s*;\s*do\s*$/,``).replace(/\s+do\s*$/,``).match(/^for\s+(\w+)\s+in\s+(.+)$/),r=n?n[1]:``,i=n?n[2].trim():``,a=t+1;a<e.length&&e[a].trim()===`do`&&a++;let o=[],s=1;for(;a<e.length;){let t=e[a].trim();if((t.startsWith(`while `)||t.startsWith(`for `))&&s++,t===`done`&&(s--,s===0)){a++;break}o.push(e[a]),a++}return{node:{type:`for`,variable:r,list:i,bodyLines:o},consumed:a-t}}async _executeNodes(e){for(let t of e)await this._executeNode(t)}_executeNode(e){if(e.type===`function`){let t=e.name,n=e.bodyLines,r=this,i=W(),a=class extends i{static get name(){return t}run(){let e=this.arguments.map((e,t)=>({key:String(t+1),prev:r.sandbox.context.getVar(String(t+1))}));this.arguments.forEach((e,t)=>r.sandbox.context.setVar(String(t+1),e));let t=()=>e.forEach(({key:e,prev:t})=>t?r.sandbox.context.setVar(e,t):r.sandbox.context.unsetVar(e));return r._executeFunctionBody(n).then(()=>{t()}).catch(e=>{if(t(),e&&e.__type===`return`){this.exitCode=e.code;return}return Promise.reject(e)})}};return this.sandbox.context.setCommand(a),Promise.resolve()}if(e.type===`command`){if(/^return(\s+\d+)?\s*$/.test(e.line.trim())){let t=e.line.trim().match(/^return\s+(\d+)/),n=t?parseInt(t[1],10):0;return Promise.reject({__type:`return`,code:n})}if(/^break(\s+\d+)?\s*$/.test(e.line.trim())){let t=e.line.trim().match(/^break\s+(\d+)/),n=t?parseInt(t[1],10):1;return Promise.reject({__type:`break`,count:n})}if(/^continue(\s+\d+)?\s*$/.test(e.line.trim())){let t=e.line.trim().match(/^continue\s+(\d+)/),n=t?parseInt(t[1],10):1;return Promise.reject({__type:`continue`,count:n})}return(this.sandbox.context.getVar(`-`)||``).includes(`x`)&&(this.stdErr=`+ ${e.line.trim()}`,this.flush()),this.sandbox.onCommand(e.line,!1).then(()=>{if((this.sandbox.context.getVar(`-`)||``).includes(`e`)&&this.sandbox.lastCode!==0)return Promise.reject({__type:`errexit`,code:this.sandbox.lastCode})})}return e.type===`if`?this._executeIf(e):e.type===`while`?this._executeWhile(e):e.type===`for`?this._executeFor(e):e.type===`case`?this._executeCase(e):Promise.resolve()}async _executeIf(e){for(let t of e.clauses)if(await this.sandbox.onCommand(t.condition,!1),this.sandbox.lastCode===0)return this._executeNodes(this._parseLines(t.bodyLines));if(e.elseLines.length>0)return this._executeNodes(this._parseLines(e.elseLines))}async _executeWhile(e){for(;await this.sandbox.onCommand(e.condition,!1),this.sandbox.lastCode===0;)try{await this._executeNodes(this._parseLines(e.bodyLines))}catch(e){if(e&&e.__type===`break`){if(e.count<=1)break;throw{__type:`break`,count:e.count-1}}if(e&&e.__type===`continue`){if(e.count<=1)continue;throw{__type:`continue`,count:e.count-1}}throw e}}async _executeFor(e){let t;if(e.list.trim()===`"$@"`){let e=parseInt(this.sandbox.context.getVar(`#`)||`0`,10);t=[];for(let n=1;n<=e;n++)t.push(this.sandbox.context.getVar(String(n))||``)}else t=(await this.sandbox._replaceVariables(e.list)).split(/\s+/).filter(Boolean);for(let n of t){this.sandbox.context.setVar(e.variable,n);try{await this._executeNodes(this._parseLines(e.bodyLines))}catch(e){if(e&&e.__type===`break`){if(e.count<=1)break;throw{__type:`break`,count:e.count-1}}if(e&&e.__type===`continue`){if(e.count<=1)continue;throw{__type:`continue`,count:e.count-1}}throw e}}}_parseFunction(e,t){let n=e[t].trim(),r=n.match(/^function\s+([\w\d_]+)/)||n.match(/^([\w\d_]+)\s*\(/),i=r?r[1]:``,a=t+1;if(!n.includes(`{`)){for(;a<e.length&&!e[a].includes(`{`);)a++;a++}let o=[],s=1;for(;a<e.length;){if(e[a].trim()===`}`){a++;break}let t=(e[a].match(/\{/g)||[]).length,n=(e[a].match(/\}/g)||[]).length;if(s+=t-n,s<=0){a++;break}o.push(e[a]),a++}return{node:{type:`function`,name:i,bodyLines:o},consumed:a-t}}_parseCase(e,t){let n=e[t].trim().match(/^case\s+(.+?)\s+in\s*$/),r=n?n[1]:``,i=t+1,a=[],o=null,s=[];for(;i<e.length;){let t=e[i],n=t.trim();if(i++,!(!n||n.startsWith(`#`))){if(n===`esac`)break;if(o===null){let e=n.match(/^(.+?)\)\s*(.*)$/);if(e){o=e[1].trim();let t=e[2].trim();if(t===`;;`)a.push({pattern:o,bodyLines:[]}),o=null;else if(t.endsWith(`;;`)){let e=t.slice(0,-2).trim();a.push({pattern:o,bodyLines:e?[e]:[]}),o=null}else s=t?[t]:[]}}else n===`;;`?(a.push({pattern:o,bodyLines:s}),o=null,s=[]):n.endsWith(`;;`)?(s.push(n.slice(0,-2).trim()),a.push({pattern:o,bodyLines:s}),o=null,s=[]):s.push(t)}}return o!==null&&a.push({pattern:o,bodyLines:s}),{node:{type:`case`,word:r,clauses:a},consumed:i-t}}_executeFunctionBody(e){return this._executeNodes(this._parseLines(e))}async _executeCase(e){let t=await this.sandbox._replaceVariables(e.word),n=t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1):t;for(let t of e.clauses)if(t.pattern.replace(/^\(\s*/,``).split(`|`).map(e=>e.trim()).some(e=>this._matchPattern(e,n)))return this._executeNodes(this._parseLines(t.bodyLines))}_matchPattern(e,t){let n=``,r=0;for(;r<e.length;){let t=e[r];if(t===`[`){let t=e.indexOf(`]`,r+1);t===-1?(n+=`\\[`,r++):(n+=e.slice(r,t+1),r=t+1)}else t===`*`?(n+=`.*`,r++):t===`?`?(n+=`.`,r++):/[.+^${}()|\\]/.test(t)?(n+=`\\`+t,r++):(n+=t,r++)}try{return RegExp(`^`+n+`$`).test(t)}catch{return!1}}},t.exports.isKnownInterpreter=a})),re=t(((e,t)=>{var n=U();t.exports=class extends n{get captureInput(){return!0}get interactive(){return!0}get terminalSize(){return{cols:this.stdout&&this.stdout.columns||this.stdinStream&&this.stdinStream.columns||this.context&&typeof this.context.getVar==`function`&&parseInt(this.context.getVar(`COLUMNS`),10)||80,rows:this.stdout&&this.stdout.rows||this.stdinStream&&this.stdinStream.rows||this.context&&typeof this.context.getVar==`function`&&parseInt(this.context.getVar(`LINES`),10)||24}}_enterAltScreen(){this._inAltScreen||(this._inAltScreen=!0,this.stdinStream&&this.stdinStream.setRawMode(!0),this.stdout&&this.stdout.write(`\x1B[?1049h\x1B[2J\x1B[H`))}_exitAltScreen(){this._inAltScreen&&(this._inAltScreen=!1,this.stdinStream&&this.stdinStream.setRawMode(!1),this.stdout&&this.stdout.write(`\x1B[0m\x1B[?1l\x1B[?1000l\x1B[?1002l\x1B[?1003l\x1B[?1006l\x1B[?1049l\x1B[?25h`))}kill(e=`SIGINT`){this._exitAltScreen(),super.kill(e)}runCommand(){return this.interactive&&this._enterAltScreen(),super.runCommand().finally(()=>{this._exitAltScreen()})}}})),G=t(((e,t)=>{var n=re(),{createGenericWasmCommand:r}=X(),i=`\x1B[2J\x1B[H`,a=`\x1B[0m`,o=`\x1B[7m`,s=`\x1B[1m`,c=`\x1B[2m`,l=`\x1B[36m`,u=`\x1B[31m`,d=`\x1B[32m`,f=class extends n{get requiresFilesystem(){return!0}get interactive(){return this.shouldBeInteractive()}get captureInput(){return this.shouldBeInteractive()}shouldBeInteractive(){return!!this._dynamicReplActive}getReplTitle(){return this._dynamicReplOpts&&this._dynamicReplOpts.title||`${this.name} interactive shell`}getReplPrompt(){return this._dynamicReplMultiline&&this._dynamicReplOpts&&this._dynamicReplOpts.continuePrompt?this._dynamicReplOpts.continuePrompt:this._dynamicReplOpts&&this._dynamicReplOpts.prompt||`${this.name}> `}getReplWelcome(){return this._dynamicReplOpts&&this._dynamicReplOpts.banner||[`Welcome to ${this.name}. Type .exit or Ctrl+D to quit.`]}async initRepl(){}async evaluateReplLine(e){if(this._dynamicReplOpts&&typeof this._dynamicReplOpts.onEvaluate==`function`){let t=await this._dynamicReplOpts.onEvaluate(e);return{output:Array.isArray(t)?t:t==null?[]:[String(t)]}}return{output:[]}}async cleanupRepl(){this._dynamicReplOpts&&typeof this._dynamicReplOpts.onClose==`function`&&await this._dynamicReplOpts.onClose()}async runNonInteractive(){}startRepl(e={}){return this._dynamicReplActive=!0,this._dynamicReplOpts=e,this._dynamicReplBuffer=``,this._dynamicReplMultiline=!1,typeof this._enterAltScreen==`function`&&this._enterAltScreen(),this._launchInteractiveReplLoop()}run(){return this.shouldBeInteractive()?this._launchInteractiveReplLoop():Promise.resolve(this.runNonInteractive())}_launchInteractiveReplLoop(){return this._replHistory=[],this._replHistoryIdx=null,this._replInput=``,this._replCursor=0,this._replLog=[],this._replBusy=!0,this._replStatus=`Initializing WASM runtime...`,this._scrollOffset=0,this._renderRepl(),new Promise(e=>{this._replResolve=e,Promise.resolve().then(()=>this.initRepl()).then(()=>{this._replBusy=!1,this._replStatus=`^D / .exit: Quit | ^L: Clear | Up/Down: History`;for(let e of this.getReplWelcome())this._appendReplLog(e,`info`);this._renderRepl()}).catch(e=>{this._replBusy=!1,this.stdErr=e.message||String(e),this.exitCode=1,this._exitRepl()})})}_appendReplLog(e,t=`out`){let n=String(e??``).split(/\r?\n/);for(let e of n)this._replLog.push({text:e,type:t});this._scrollOffset=0}streamReplChunk(e,t=`out`){if(!e)return;(this._replLog.length===0||this._replLog[this._replLog.length-1].type!==t||!this._replStreamingActive)&&(this._replLog.push({text:``,type:t}),this._replStreamingActive=!0);let n=this._replLog[this._replLog.length-1],r=(n.text+e).split(/\r?\n/);n.text=r[0];for(let e=1;e<r.length;e++)this._replLog.push({text:r[e],type:t});this._scrollOffset=0,this._renderRepl()}onInput(e){if(this.shouldBeInteractive()){if(e===`^D`||e===`^X`){this._exitRepl();return}if(e===`^C`){this._replInput.length>0||this._dynamicReplBuffer?(this._appendReplLog(`${this.getReplPrompt()}${this._replInput}^C`,`prompt`),this._replInput=``,this._replCursor=0,this._dynamicReplBuffer=``,this._dynamicReplMultiline=!1,this._renderRepl()):this._exitRepl();return}if(!this._replBusy){if(e===`^L`){this._replLog=[],this._scrollOffset=0,this._renderRepl();return}if(e===`Enter`){let e=this._replInput;this._replInput=``,this._replCursor=0,this._replHistoryIdx=null,e.trim()&&this._replHistory.push(e),this._appendReplLog(`${this.getReplPrompt()}${e}`,`prompt`);let t=e.trim();if(this._dynamicReplOpts&&typeof this._dynamicReplOpts.isExitCommand==`function`&&this._dynamicReplOpts.isExitCommand(t)||t===`.exit`||t===`.quit`||t===`\\q`||t===`exit`||t===`quit`||t===`exit()`||t===`quit()`){this._exitRepl();return}if(t===`.clear`||t===`\\! clear`){this._replLog=[],this._renderRepl();return}if(this._dynamicReplOpts&&typeof this._dynamicReplOpts.needsMoreInput==`function`&&(this._dynamicReplBuffer=this._dynamicReplBuffer?`${this._dynamicReplBuffer}\n${e}`:e,this._dynamicReplOpts.needsMoreInput(this._dynamicReplBuffer))){this._dynamicReplMultiline=!0,this._renderRepl();return}let n=this._dynamicReplBuffer||e;this._dynamicReplBuffer=``,this._dynamicReplMultiline=!1,this._replBusy=!0,this._replStatus=`Running...`,this._renderRepl(),Promise.resolve().then(()=>this.evaluateReplLine(n)).then(e=>{if(this._replBusy=!1,this._replStreamingActive=!1,this._replStatus=`^D / .exit: Quit | ^L: Clear | Up/Down: History`,e){if(e.clear&&(this._replLog=[]),!e.streamed)if(Array.isArray(e.output))for(let t of e.output)this._appendReplLog(t,`out`);else typeof e.output==`string`&&e.output.length>0&&this._appendReplLog(e.output,`out`);if(e.error&&this._appendReplLog(e.error,`err`),e.exit){this._exitRepl();return}}this._renderRepl()}).catch(e=>{this._replBusy=!1,this._replStatus=`^D / .exit: Quit | ^L: Clear | Up/Down: History`,this._appendReplLog(`Error: ${e.message||e}`,`err`),this._renderRepl()});return}if(e===`Backspace`){this._replCursor>0&&(this._replInput=this._replInput.slice(0,this._replCursor-1)+this._replInput.slice(this._replCursor),this._replCursor--,this._renderRepl());return}if(e===`^W`){let e=this._replCursor;for(;e>0&&this._replInput[e-1]===` `;)e--;for(;e>0&&this._replInput[e-1]!==` `;)e--;this._replInput=this._replInput.slice(0,e)+this._replInput.slice(this._replCursor),this._replCursor=e,this._renderRepl();return}if(e===`Delete`){this._replCursor<this._replInput.length&&(this._replInput=this._replInput.slice(0,this._replCursor)+this._replInput.slice(this._replCursor+1),this._renderRepl());return}if(e===`ArrowLeft`){this._replCursor>0&&(this._replCursor--,this._renderRepl());return}if(e===`ArrowRight`){this._replCursor<this._replInput.length&&(this._replCursor++,this._renderRepl());return}if(e===`Home`||e===`^A`){this._replCursor=0,this._renderRepl();return}if(e===`End`||e===`^E`){this._replCursor=this._replInput.length,this._renderRepl();return}if(e===`ArrowUp`){if(this._replHistory.length===0)return;this._replHistoryIdx===null?this._replHistoryIdx=this._replHistory.length-1:this._replHistoryIdx>0&&this._replHistoryIdx--,this._replInput=this._replHistory[this._replHistoryIdx],this._replCursor=this._replInput.length,this._renderRepl();return}if(e===`ArrowDown`){if(this._replHistoryIdx===null)return;this._replHistoryIdx<this._replHistory.length-1?(this._replHistoryIdx++,this._replInput=this._replHistory[this._replHistoryIdx]):(this._replHistoryIdx=null,this._replInput=``),this._replCursor=this._replInput.length,this._renderRepl();return}if(e===`PageUp`){let e=Math.max(0,this._replLog.length-5);this._scrollOffset=Math.min(e,this._scrollOffset+5),this._renderRepl();return}if(e===`PageDown`){this._scrollOffset=Math.max(0,this._scrollOffset-5),this._renderRepl();return}e.length===1&&!e.startsWith(`^`)&&(this._replInput=this._replInput.slice(0,this._replCursor)+e+this._replInput.slice(this._replCursor),this._replCursor++,this._renderRepl())}}}_renderRepl(){let{cols:e,rows:t}=this.terminalSize,n=Math.max(3,t-3),r=`${o}${s}${` ${this.getReplTitle()} `.padEnd(e).slice(0,e)}${a}`,f=this._replLog.length,p=Math.max(0,f-this._scrollOffset),m=Math.max(0,p-n),h=this._replLog.slice(m,p),g=[];for(let e=0;e<n;e++){let t=h[e];if(!t){g.push(``);continue}t.type===`prompt`?g.push(`${l}${t.text}${a}`):t.type===`err`?g.push(`${u}${t.text}${a}`):t.type===`info`?g.push(`${c}${t.text}${a}`):g.push(t.text)}let _=this.getReplPrompt(),v=this._replInput.slice(0,this._replCursor),y=this._replCursor<this._replInput.length?this._replInput[this._replCursor]:` `,b=this._replCursor<this._replInput.length?this._replInput.slice(this._replCursor+1):``,x=this._replBusy?`${c}${this._replStatus}${a}`:`${d}${s}${_}${a}${v}${o}${y}${a}${b}`,S=`${o}${` ${this._replStatus} `.padEnd(e).slice(0,e)}${a}`,C=[i+r,...g,x,S].join(`
5
+ `+s:n+=s;let c=0,l=!1,u=!1;for(;c<s.length;){let e=s[c];if(r)e===`'`&&(r=!1),c++;else if(i)e===`\\`&&c+1<s.length?c+=2:e===`\\`&&c+1===s.length?(l=!0,c++):(e===`"`&&(i=!1),c++);else{if(e===`#`&&(c===0||/\s/.test(s[c-1]))){u=!0;break}e===`\\`&&c+1<s.length?c+=2:e===`\\`&&c+1===s.length?(l=!0,c++):e===`'`?(r=!0,c++):(e===`"`&&(i=!0),c++)}}if(!r&&!l&&!u){let e=s.match(/(\\+)\s*$/);e&&e[1].length%2==1&&(l=!0)}a=l,l&&(n=n.replace(/\\\s*$/,``)),!r&&!i&&!l&&(t.push(n),n=null,a=!1)}return n!==null&&t.push(n),t}_parseLines(e){e=this._accumulateLines(e);let t=[],n=0;for(;n<e.length;){let r=e[n].trim();if(!r||r.startsWith(`#`)){n++;continue}if(r.startsWith(`if `)||r===`if`){let r=this._parseIf(e,n);t.push(r.node),n+=r.consumed;continue}if(r.startsWith(`while `)){let r=this._parseWhile(e,n);t.push(r.node),n+=r.consumed;continue}if(r.startsWith(`for `)){let r=this._parseFor(e,n);t.push(r.node),n+=r.consumed;continue}if(r.startsWith(`case `)||r===`case`){let r=this._parseCase(e,n);t.push(r.node),n+=r.consumed;continue}if(/^(?:function\s+[\w\d_]+|[\w\d_]+\s*\(\s*\))\s*(?:\{.*)?$/.test(r)){let r=this._parseFunction(e,n);t.push(r.node),n+=r.consumed;continue}t.push({type:`command`,line:r}),n++}return t}_parseIf(e,t){let n=e=>e.replace(/^(?:if|elif)\s+/,``).replace(/\s*;\s*then\s*$/,``).replace(/\s+then\s*$/,``).trim(),r=[{condition:n(e[t].trim()),bodyLines:[]}],i=[],a=r[0],o=!1,s=1,c=t+1;for(c<e.length&&e[c].trim()===`then`&&c++;c<e.length;){let t=e[c].trim();if((t.startsWith(`if `)||t===`if`)&&s++,t===`fi`&&(s--,s===0)){c++;break}if(s===1&&t.startsWith(`elif `)){let i={condition:n(t),bodyLines:[]};r.push(i),a=i,c++,c<e.length&&e[c].trim()===`then`&&c++;continue}if(s===1&&t===`else`){o=!0,c++;continue}o?i.push(e[c]):a.bodyLines.push(e[c]),c++}return{node:{type:`if`,clauses:r,elseLines:i},consumed:c-t}}_parseWhile(e,t){let n=e[t].trim().replace(/^while\s+/,``).replace(/\s*;\s*do\s*$/,``).replace(/\s+do\s*$/,``).trim(),r=t+1;r<e.length&&e[r].trim()===`do`&&r++;let i=[],a=1;for(;r<e.length;){let t=e[r].trim();if((t.startsWith(`while `)||t.startsWith(`for `))&&a++,t===`done`&&(a--,a===0)){r++;break}i.push(e[r]),r++}return{node:{type:`while`,condition:n,bodyLines:i},consumed:r-t}}_parseFor(e,t){let n=e[t].trim().replace(/\s*;\s*do\s*$/,``).replace(/\s+do\s*$/,``).match(/^for\s+(\w+)\s+in\s+(.+)$/),r=n?n[1]:``,i=n?n[2].trim():``,a=t+1;a<e.length&&e[a].trim()===`do`&&a++;let o=[],s=1;for(;a<e.length;){let t=e[a].trim();if((t.startsWith(`while `)||t.startsWith(`for `))&&s++,t===`done`&&(s--,s===0)){a++;break}o.push(e[a]),a++}return{node:{type:`for`,variable:r,list:i,bodyLines:o},consumed:a-t}}async _executeNodes(e){for(let t of e)await this._executeNode(t)}_executeNode(e){if(e.type===`function`){let t=e.name,n=e.bodyLines,r=this,i=W(),a=class extends i{static get name(){return t}run(){let e=parseInt(r.sandbox.context.getVar(`#`)||`0`,10)||0,t=Math.max(e,this.arguments.length),i=[];for(let e=1;e<=t;e++){let t=String(e);i.push({key:t,prev:r.sandbox.context.getVar(t)}),e<=this.arguments.length?r.sandbox.context.setVar(t,this.arguments[e-1]):r.sandbox.context.unsetVar(t)}for(let e of[`#`,`@`,`*`])i.push({key:e,prev:r.sandbox.context.getVar(e)});r.sandbox.context.setVar(`#`,String(this.arguments.length)),r.sandbox.context.setVar(`@`,this.arguments.join(` `)),r.sandbox.context.setVar(`*`,this.arguments.join(` `));let a=()=>i.forEach(({key:e,prev:t})=>t?r.sandbox.context.setVar(e,t):r.sandbox.context.unsetVar(e));return r._executeFunctionBody(n).then(()=>{a()}).catch(e=>{if(a(),e&&e.__type===`return`){this.exitCode=e.code;return}return Promise.reject(e)})}};return this.sandbox.context.setCommand(a),Promise.resolve()}if(e.type===`command`){if(/^return(\s+\d+)?\s*$/.test(e.line.trim())){let t=e.line.trim().match(/^return\s+(\d+)/),n=t?parseInt(t[1],10):0;return Promise.reject({__type:`return`,code:n})}if(/^break(\s+\d+)?\s*$/.test(e.line.trim())){let t=e.line.trim().match(/^break\s+(\d+)/),n=t?parseInt(t[1],10):1;return Promise.reject({__type:`break`,count:n})}if(/^continue(\s+\d+)?\s*$/.test(e.line.trim())){let t=e.line.trim().match(/^continue\s+(\d+)/),n=t?parseInt(t[1],10):1;return Promise.reject({__type:`continue`,count:n})}return(this.sandbox.context.getVar(`-`)||``).includes(`x`)&&(this.stdErr=`+ ${e.line.trim()}`,this.flush()),this.sandbox.onCommand(e.line,!1).then(()=>{if((this.sandbox.context.getVar(`-`)||``).includes(`e`)&&this.sandbox.lastCode!==0)return Promise.reject({__type:`errexit`,code:this.sandbox.lastCode})})}return e.type===`if`?this._executeIf(e):e.type===`while`?this._executeWhile(e):e.type===`for`?this._executeFor(e):e.type===`case`?this._executeCase(e):Promise.resolve()}async _executeIf(e){for(let t of e.clauses)if(await this.sandbox.onCommand(t.condition,!1),this.sandbox.lastCode===0)return this._executeNodes(this._parseLines(t.bodyLines));if(e.elseLines.length>0)return this._executeNodes(this._parseLines(e.elseLines))}async _executeWhile(e){for(;await this.sandbox.onCommand(e.condition,!1),this.sandbox.lastCode===0;)try{await this._executeNodes(this._parseLines(e.bodyLines))}catch(e){if(e&&e.__type===`break`){if(e.count<=1)break;throw{__type:`break`,count:e.count-1}}if(e&&e.__type===`continue`){if(e.count<=1)continue;throw{__type:`continue`,count:e.count-1}}throw e}}async _executeFor(e){let t;if(e.list.trim()===`"$@"`){let e=parseInt(this.sandbox.context.getVar(`#`)||`0`,10);t=[];for(let n=1;n<=e;n++)t.push(this.sandbox.context.getVar(String(n))||``)}else t=(await this.sandbox._replaceVariables(e.list)).split(/\s+/).filter(Boolean);for(let n of t){this.sandbox.context.setVar(e.variable,n);try{await this._executeNodes(this._parseLines(e.bodyLines))}catch(e){if(e&&e.__type===`break`){if(e.count<=1)break;throw{__type:`break`,count:e.count-1}}if(e&&e.__type===`continue`){if(e.count<=1)continue;throw{__type:`continue`,count:e.count-1}}throw e}}}_parseFunction(e,t){let n=e[t].trim(),r=n.match(/^function\s+([\w\d_]+)/)||n.match(/^([\w\d_]+)\s*\(/),i=r?r[1]:``,a=t+1;if(!n.includes(`{`)){for(;a<e.length&&!e[a].includes(`{`);)a++;a++}let o=[],s=1;for(;a<e.length;){if(e[a].trim()===`}`){a++;break}let t=(e[a].match(/\{/g)||[]).length,n=(e[a].match(/\}/g)||[]).length;if(s+=t-n,s<=0){a++;break}o.push(e[a]),a++}return{node:{type:`function`,name:i,bodyLines:o},consumed:a-t}}_parseCase(e,t){let n=e[t].trim().match(/^case\s+(.+?)\s+in\s*$/),r=n?n[1]:``,i=t+1,a=[],o=null,s=[];for(;i<e.length;){let t=e[i],n=t.trim();if(i++,!(!n||n.startsWith(`#`))){if(n===`esac`)break;if(o===null){let e=n.match(/^(.+?)\)\s*(.*)$/);if(e){o=e[1].trim();let t=e[2].trim();if(t===`;;`)a.push({pattern:o,bodyLines:[]}),o=null;else if(t.endsWith(`;;`)){let e=t.slice(0,-2).trim();a.push({pattern:o,bodyLines:e?[e]:[]}),o=null}else s=t?[t]:[]}}else n===`;;`?(a.push({pattern:o,bodyLines:s}),o=null,s=[]):n.endsWith(`;;`)?(s.push(n.slice(0,-2).trim()),a.push({pattern:o,bodyLines:s}),o=null,s=[]):s.push(t)}}return o!==null&&a.push({pattern:o,bodyLines:s}),{node:{type:`case`,word:r,clauses:a},consumed:i-t}}_executeFunctionBody(e){return this._executeNodes(this._parseLines(e))}async _executeCase(e){let t=await this.sandbox._replaceVariables(e.word),n=t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1):t;for(let t of e.clauses)if(t.pattern.replace(/^\(\s*/,``).split(`|`).map(e=>e.trim()).some(e=>this._matchPattern(e,n)))return this._executeNodes(this._parseLines(t.bodyLines))}_matchPattern(e,t){let n=``,r=0;for(;r<e.length;){let t=e[r];if(t===`[`){let t=e.indexOf(`]`,r+1);t===-1?(n+=`\\[`,r++):(n+=e.slice(r,t+1),r=t+1)}else t===`*`?(n+=`.*`,r++):t===`?`?(n+=`.`,r++):/[.+^${}()|\\]/.test(t)?(n+=`\\`+t,r++):(n+=t,r++)}try{return RegExp(`^`+n+`$`).test(t)}catch{return!1}}},t.exports.isKnownInterpreter=a})),re=t(((e,t)=>{var n=U();t.exports=class extends n{get captureInput(){return!0}get interactive(){return!0}get terminalSize(){return{cols:this.stdout&&this.stdout.columns||this.stdinStream&&this.stdinStream.columns||this.context&&typeof this.context.getVar==`function`&&parseInt(this.context.getVar(`COLUMNS`),10)||80,rows:this.stdout&&this.stdout.rows||this.stdinStream&&this.stdinStream.rows||this.context&&typeof this.context.getVar==`function`&&parseInt(this.context.getVar(`LINES`),10)||24}}_enterAltScreen(){this._inAltScreen||(this._inAltScreen=!0,this.stdinStream&&this.stdinStream.setRawMode(!0),this.stdout&&this.stdout.write(`\x1B[?1049h\x1B[2J\x1B[H`))}_exitAltScreen(){this._inAltScreen&&(this._inAltScreen=!1,this.stdinStream&&this.stdinStream.setRawMode(!1),this.stdout&&this.stdout.write(`\x1B[0m\x1B[?1l\x1B[?1000l\x1B[?1002l\x1B[?1003l\x1B[?1006l\x1B[?1049l\x1B[?25h`))}kill(e=`SIGINT`){this._exitAltScreen(),super.kill(e)}runCommand(){return this.interactive&&this._enterAltScreen(),super.runCommand().finally(()=>{this._exitAltScreen()})}}})),G=t(((e,t)=>{var n=re(),{createGenericWasmCommand:r}=X(),i=`\x1B[2J\x1B[H`,a=`\x1B[0m`,o=`\x1B[7m`,s=`\x1B[1m`,c=`\x1B[2m`,l=`\x1B[36m`,u=`\x1B[31m`,d=`\x1B[32m`,f=class extends n{get requiresFilesystem(){return!0}get interactive(){return this.shouldBeInteractive()}get captureInput(){return this.shouldBeInteractive()}shouldBeInteractive(){return!!this._dynamicReplActive}getReplTitle(){return this._dynamicReplOpts&&this._dynamicReplOpts.title||`${this.name} interactive shell`}getReplPrompt(){return this._dynamicReplMultiline&&this._dynamicReplOpts&&this._dynamicReplOpts.continuePrompt?this._dynamicReplOpts.continuePrompt:this._dynamicReplOpts&&this._dynamicReplOpts.prompt||`${this.name}> `}getReplWelcome(){return this._dynamicReplOpts&&this._dynamicReplOpts.banner||[`Welcome to ${this.name}. Type .exit or Ctrl+D to quit.`]}async initRepl(){}async evaluateReplLine(e){if(this._dynamicReplOpts&&typeof this._dynamicReplOpts.onEvaluate==`function`){let t=await this._dynamicReplOpts.onEvaluate(e);return{output:Array.isArray(t)?t:t==null?[]:[String(t)]}}return{output:[]}}async cleanupRepl(){this._dynamicReplOpts&&typeof this._dynamicReplOpts.onClose==`function`&&await this._dynamicReplOpts.onClose()}async runNonInteractive(){}startRepl(e={}){return this._dynamicReplActive=!0,this._dynamicReplOpts=e,this._dynamicReplBuffer=``,this._dynamicReplMultiline=!1,typeof this._enterAltScreen==`function`&&this._enterAltScreen(),this._launchInteractiveReplLoop()}run(){return this.shouldBeInteractive()?this._launchInteractiveReplLoop():Promise.resolve(this.runNonInteractive())}_launchInteractiveReplLoop(){return this._replHistory=[],this._replHistoryIdx=null,this._replInput=``,this._replCursor=0,this._replLog=[],this._replBusy=!0,this._replStatus=`Initializing WASM runtime...`,this._scrollOffset=0,this._renderRepl(),new Promise(e=>{this._replResolve=e,Promise.resolve().then(()=>this.initRepl()).then(()=>{this._replBusy=!1,this._replStatus=`^D / .exit: Quit | ^L: Clear | Up/Down: History`;for(let e of this.getReplWelcome())this._appendReplLog(e,`info`);this._renderRepl()}).catch(e=>{this._replBusy=!1,this.stdErr=e.message||String(e),this.exitCode=1,this._exitRepl()})})}_appendReplLog(e,t=`out`){let n=String(e??``).split(/\r?\n/);for(let e of n)this._replLog.push({text:e,type:t});this._scrollOffset=0}streamReplChunk(e,t=`out`){if(!e)return;(this._replLog.length===0||this._replLog[this._replLog.length-1].type!==t||!this._replStreamingActive)&&(this._replLog.push({text:``,type:t}),this._replStreamingActive=!0);let n=this._replLog[this._replLog.length-1],r=(n.text+e).split(/\r?\n/);n.text=r[0];for(let e=1;e<r.length;e++)this._replLog.push({text:r[e],type:t});this._scrollOffset=0,this._renderRepl()}onInput(e){if(this.shouldBeInteractive()){if(e===`^D`||e===`^X`){this._exitRepl();return}if(e===`^C`){this._replInput.length>0||this._dynamicReplBuffer?(this._appendReplLog(`${this.getReplPrompt()}${this._replInput}^C`,`prompt`),this._replInput=``,this._replCursor=0,this._dynamicReplBuffer=``,this._dynamicReplMultiline=!1,this._renderRepl()):this._exitRepl();return}if(!this._replBusy){if(e===`^L`){this._replLog=[],this._scrollOffset=0,this._renderRepl();return}if(e===`Enter`){let e=this._replInput;this._replInput=``,this._replCursor=0,this._replHistoryIdx=null,e.trim()&&this._replHistory.push(e),this._appendReplLog(`${this.getReplPrompt()}${e}`,`prompt`);let t=e.trim();if(this._dynamicReplOpts&&typeof this._dynamicReplOpts.isExitCommand==`function`&&this._dynamicReplOpts.isExitCommand(t)||t===`.exit`||t===`.quit`||t===`\\q`||t===`exit`||t===`quit`||t===`exit()`||t===`quit()`){this._exitRepl();return}if(t===`.clear`||t===`\\! clear`){this._replLog=[],this._renderRepl();return}if(this._dynamicReplOpts&&typeof this._dynamicReplOpts.needsMoreInput==`function`&&(this._dynamicReplBuffer=this._dynamicReplBuffer?`${this._dynamicReplBuffer}\n${e}`:e,this._dynamicReplOpts.needsMoreInput(this._dynamicReplBuffer))){this._dynamicReplMultiline=!0,this._renderRepl();return}let n=this._dynamicReplBuffer||e;this._dynamicReplBuffer=``,this._dynamicReplMultiline=!1,this._replBusy=!0,this._replStatus=`Running...`,this._renderRepl(),Promise.resolve().then(()=>this.evaluateReplLine(n)).then(e=>{if(this._replBusy=!1,this._replStreamingActive=!1,this._replStatus=`^D / .exit: Quit | ^L: Clear | Up/Down: History`,e){if(e.clear&&(this._replLog=[]),!e.streamed)if(Array.isArray(e.output))for(let t of e.output)this._appendReplLog(t,`out`);else typeof e.output==`string`&&e.output.length>0&&this._appendReplLog(e.output,`out`);if(e.error&&this._appendReplLog(e.error,`err`),e.exit){this._exitRepl();return}}this._renderRepl()}).catch(e=>{this._replBusy=!1,this._replStatus=`^D / .exit: Quit | ^L: Clear | Up/Down: History`,this._appendReplLog(`Error: ${e.message||e}`,`err`),this._renderRepl()});return}if(e===`Backspace`){this._replCursor>0&&(this._replInput=this._replInput.slice(0,this._replCursor-1)+this._replInput.slice(this._replCursor),this._replCursor--,this._renderRepl());return}if(e===`^W`){let e=this._replCursor;for(;e>0&&this._replInput[e-1]===` `;)e--;for(;e>0&&this._replInput[e-1]!==` `;)e--;this._replInput=this._replInput.slice(0,e)+this._replInput.slice(this._replCursor),this._replCursor=e,this._renderRepl();return}if(e===`Delete`){this._replCursor<this._replInput.length&&(this._replInput=this._replInput.slice(0,this._replCursor)+this._replInput.slice(this._replCursor+1),this._renderRepl());return}if(e===`ArrowLeft`){this._replCursor>0&&(this._replCursor--,this._renderRepl());return}if(e===`ArrowRight`){this._replCursor<this._replInput.length&&(this._replCursor++,this._renderRepl());return}if(e===`Home`||e===`^A`){this._replCursor=0,this._renderRepl();return}if(e===`End`||e===`^E`){this._replCursor=this._replInput.length,this._renderRepl();return}if(e===`ArrowUp`){if(this._replHistory.length===0)return;this._replHistoryIdx===null?this._replHistoryIdx=this._replHistory.length-1:this._replHistoryIdx>0&&this._replHistoryIdx--,this._replInput=this._replHistory[this._replHistoryIdx],this._replCursor=this._replInput.length,this._renderRepl();return}if(e===`ArrowDown`){if(this._replHistoryIdx===null)return;this._replHistoryIdx<this._replHistory.length-1?(this._replHistoryIdx++,this._replInput=this._replHistory[this._replHistoryIdx]):(this._replHistoryIdx=null,this._replInput=``),this._replCursor=this._replInput.length,this._renderRepl();return}if(e===`PageUp`){let e=Math.max(0,this._replLog.length-5);this._scrollOffset=Math.min(e,this._scrollOffset+5),this._renderRepl();return}if(e===`PageDown`){this._scrollOffset=Math.max(0,this._scrollOffset-5),this._renderRepl();return}e.length===1&&!e.startsWith(`^`)&&(this._replInput=this._replInput.slice(0,this._replCursor)+e+this._replInput.slice(this._replCursor),this._replCursor++,this._renderRepl())}}}_renderRepl(){let{cols:e,rows:t}=this.terminalSize,n=Math.max(3,t-3),r=`${o}${s}${` ${this.getReplTitle()} `.padEnd(e).slice(0,e)}${a}`,f=this._replLog.length,p=Math.max(0,f-this._scrollOffset),m=Math.max(0,p-n),h=this._replLog.slice(m,p),g=[];for(let e=0;e<n;e++){let t=h[e];if(!t){g.push(``);continue}t.type===`prompt`?g.push(`${l}${t.text}${a}`):t.type===`err`?g.push(`${u}${t.text}${a}`):t.type===`info`?g.push(`${c}${t.text}${a}`):g.push(t.text)}let _=this.getReplPrompt(),v=this._replInput.slice(0,this._replCursor),y=this._replCursor<this._replInput.length?this._replInput[this._replCursor]:` `,b=this._replCursor<this._replInput.length?this._replInput.slice(this._replCursor+1):``,x=this._replBusy?`${c}${this._replStatus}${a}`:`${d}${s}${_}${a}${v}${o}${y}${a}${b}`,S=`${o}${` ${this._replStatus} `.padEnd(e).slice(0,e)}${a}`,C=[i+r,...g,x,S].join(`
6
6
  `);this.stdOut=C,this.flush()}_exitRepl(){Promise.resolve().then(()=>this.cleanupRepl()).catch(()=>{}).finally(()=>{if(this._replResolve){let e=this._replResolve;this._replResolve=null,e()}})}};function p(e,t={},n=null){let i=(n||e.bin||e.name).toLowerCase(),a=r(e,t,i),o=e&&typeof e.repl==`object`?e.repl:{};class s extends f{static get name(){return i}get name(){return i}constructor(e,t){super(e,t),this._sessionArgs=[],this._isInteractiveMode=this._detectInteractiveMode(e||[])}_detectInteractiveMode(e){if(e.includes(`--help`)||e.includes(`-h`)||e.includes(`--version`)||e.includes(`-V`)||e.includes(`-v`))return!1;if(e.length===0)return!0;if(o.sessionArg&&e.length===1&&!e[0].startsWith(`-`)){let t=e[0].trim();if(!/^\s*(SELECT|INSERT|UPDATE|DELETE|CREATE|DROP|PRAGMA|WITH|BEGIN|EXPLAIN|\.)\b/i.test(t))return this._sessionArgs=[e[0]],!0}return!1}shouldBeInteractive(){return this._dynamicReplActive?!0:this.stdin!==void 0&&this.stdin!==null&&String(this.stdin).trim().length>0?!1:this._isInteractiveMode}getReplTitle(){let t=this._sessionArgs.length>0?` — ${this._sessionArgs.join(` `)}`:``;return o.title||`${i} (${e.name} ${e.version||`wasm`})${t}`}getReplPrompt(){return this._dynamicReplMultiline&&o.continuePrompt?o.continuePrompt:o.prompt||`${i}> `}getReplWelcome(){return o.banner||[`${e.name} (${e.version||`wasm`}) interactive shell`,`Type ".exit" or Ctrl+D to quit.`]}async evaluateReplLine(e){let t=o.evalFlag,n=t?[...this._sessionArgs,t,e]:[...this._sessionArgs,e],r=t?void 0:e,{out:i,err:a}=await this._captureBaseWasmOutput(n,r);return{output:i,error:a.length>0?a.join(`
7
7
  `):void 0}}async runNonInteractive(){await this._delegateToBaseWasm([...this.arguments||[]])}async _delegateToBaseWasm(e){let t=new a(e,this.context);t.fs=this.fs,this.stdin!==void 0&&(t.stdin=this.stdin),await t.run();for(let e of t.result.getStdOutput())e.type===`out`?this.stdOut=e.string:e.type===`err`&&(this.stdErr=e.string);this.exitCode=t.exitCode||t.result.getExitCode()}async _captureBaseWasmOutput(e,t){let n=new a(e,this.context);n.fs=this.fs,t!==void 0&&(n.stdin=t),await n.run();let r=[],i=[];for(let e of n.result.getStdOutput())e.type===`err`?i.push(e.string):r.push(e.string);return{out:r,err:i}}}return s}f.createReplWasmCommand=p,f.createCommand=p,t.exports=f})),K=t(((e,t)=>{y();function n(e){if(!e||e.length===0)return!0;let t=e instanceof Uint8Array?e:v!==void 0&&v.isBuffer(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e instanceof ArrayBuffer||ArrayBuffer.isView(e)?new Uint8Array(e.buffer||e,e.byteOffset||0,e.byteLength):null;if(!t)return!1;let n=Math.min(t.length,8192);for(let e=0;e<n;e++){let n=t[e];if(n===0||n<32&&n!==9&&n!==10&&n!==13&&n!==27)return!1}try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(t),!0}catch{return!1}}t.exports=n,t.exports.isUtf8Text=n})),q=t(((e,t)=>{y();var n=new Set([`cwd`,`getFileByPath`,`setFileByPath`,`deleteFileByPath`,`exists`,`stat`,`absolutePath`,`getMode`,`setMode`,`isReadable`,`isWritable`,`isExecutable`,`getSize`,`autoComplete`,`isRealFilesystem`,`isSymlink`,`readSymlink`,`createSymlink`,`realpath`,`setTtyDevice`,`loadModule`]),r=class{loadModule(e){let t=this.getFileByPath(e);if(t==null)throw Error(`${e}: No such file or directory`);if(typeof t==`function`)return t;let n=typeof t==`string`?t:new TextDecoder().decode(t);/^\s*export\s+default\s+/m.test(n)&&(n=n.replace(/^\s*export\s+default\s+/m,`module.exports = `));let r={exports:{}},i=U(),a=W(),o=X(),s=re(),c=G();return Function(`module`,`exports`,`require`,`Command`,`LocalCommand`,`WasmCommand`,`InteractiveCommand`,`ReplCommand`,n)(r,r.exports,require,i,a,o,s,c),r.exports.default===void 0?r.exports:r.exports.default}isReadable(e){let t=this.getMode(e);return t===null?!1:(t&256)!=0}isWritable(e){let t=this.getMode(e);return t===null?!1:(t&128)!=0}isExecutable(e){let t=this.getMode(e);return t===null?!1:(t&64)!=0}realpath(e,t=10){let n=this.absolutePath(e),r=0;for(;r++<t&&typeof this.isSymlink==`function`&&this.isSymlink(n);){let e=this.readSymlink(n);if(!e)break;n=e.startsWith(`/`)?this.absolutePath(e):this.absolutePath(`${n.split(`/`).slice(0,-1).join(`/`)}/${e}`)}return n}sandbox(){let e=this,t=Symbol.for(`brsh.fs.target`);return new Proxy(Object.create(null),{get(r,i){if(i===t)return e;if(!n.has(i))return;let a=e[i];return typeof a==`function`?a.bind(e):a},set(){return!1},has(e,t){return n.has(t)}})}_triggerChange(){!this._onChange||this._changeScheduled||(this._changeScheduled=!0,Promise.resolve().then(()=>{this._changeScheduled=!1,typeof this._onChange==`function`&&this._onChange(this.getRaw(),this.getRawPermissions())}))}},i=class extends Uint8Array{constructor(e,t){super(e),Object.defineProperty(this,"mimeType",{value:t,enumerable:!1,configurable:!1,writable:!1})}toString(){if(v!==void 0)return`data:${this.mimeType};base64,${v.from(this).toString(`base64`)}`;let e=``,t=8192;for(let n=0;n<this.length;n+=t)e+=String.fromCharCode(...this.subarray(n,n+t));return`data:${this.mimeType};base64,${btoa(e)}`}},a=class{constructor(e){this.target=e}toJSON(){return{$l:this.target}}},o=class{constructor(e,t={}){this.name=e,this.read=typeof t.read==`function`?t.read:(()=>``),this.write=typeof t.write==`function`?t.write:(()=>{}),this.mode=t.mode===void 0?438:t.mode,this.isCharacterDevice=!0}toString(){let e=this.read();return e==null?``:typeof e==`string`?e:e.toString()}},s=K();t.exports=r,t.exports.BinaryFile=i,t.exports.SymlinkRef=a,t.exports.DeviceFile=o,t.exports.isUtf8Text=s})),J=t(((e,t)=>{y(),ee();var{BinaryFile:n,SymlinkRef:r,DeviceFile:i}=q(),a=new Uint8Array([66,82,70,83]),o=2;function s(e){if(!e)return!1;let t=e instanceof Uint8Array?e:e instanceof ArrayBuffer||ArrayBuffer.isView(e)?new Uint8Array(e.buffer||e,e.byteOffset||0,e.byteLength):null;return!t||t.length<12?!1:t[0]===a[0]&&t[1]===a[1]&&t[2]===a[2]&&t[3]===a[3]}function c(e={},t={},n={}){let s=new TextEncoder,c=[],l=0,u=e=>{let t=e instanceof Uint8Array?e:new Uint8Array(e),n=l;return c.push(t),l+=t.byteLength,[n,t.byteLength]},d={},f=(e,t)=>{if(e==null)return null;if(e instanceof r)return{$l:e.target};if(e instanceof i)return null;if(e instanceof Uint8Array||v!==void 0&&v.isBuffer(e)){let n=e instanceof Uint8Array?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e),r=e.mimeType||(t.endsWith(`.wasm`)?`application/wasm`:`application/octet-stream`),[i,a]=u(n);return{$b:[i,a,r]}}if(typeof e==`function`)return n.commandsBundle||(d[t]=e.__source||e.toString()),{$c:t};if(typeof e==`string`){if(e.startsWith(`data:`)){let t=e.indexOf(`;`),n=e.indexOf(`,`,t);if(t!==-1&&n!==-1&&e.slice(t+1,n)===`base64`){let r=e.slice(5,t),i=e.slice(n+1),a;if(v!==void 0)a=new Uint8Array(v.from(i,`base64`));else{let e=atob(i);a=new Uint8Array(e.length);for(let t=0;t<e.length;t++)a[t]=e.charCodeAt(t)}let[o,s]=u(a);return{$b:[o,s,r]}}}let[t,n]=u(s.encode(e));return{$t:[t,n]}}if(typeof e==`object`){let n={};for(let r of Object.keys(e)){let i=`${t}/${r}`,a=f(e[r],i);a!==null&&(n[r]=a)}return{$d:n}}return null},p=f(e,``)||{$d:{}},m=null;n.commandsBundle&&typeof n.commandsBundle==`string`&&(m=u(s.encode(n.commandsBundle)));let h={v:o,tree:p,permissions:Object.assign({},t)};m&&(h.commandsSlice=m),Object.keys(d).length>0&&(h.inlineCommands=d);let g=s.encode(JSON.stringify(h)),_=12+g.byteLength+l,y=new Uint8Array(_);y.set(a,0);let b=new DataView(y.buffer,y.byteOffset,y.byteLength);b.setUint32(4,o,!0),b.setUint32(8,g.byteLength,!0),y.set(g,12);let x=12+g.byteLength;for(let e of c)y.set(e,x),x+=e.byteLength;return y}function l(e,t={}){let a=e instanceof Uint8Array?e:new Uint8Array(e.buffer||e,e.byteOffset||0,e.byteLength);if(!s(a))throw Error(`Invalid BRFS binary container (missing BRFS magic header)`);let c=new DataView(a.buffer,a.byteOffset,a.byteLength),l=c.getUint32(4,!0);if(l>o)throw Error(`Unsupported BRFS container version: ${l}`);let u=12+c.getUint32(8,!0);if(u>a.byteLength)throw Error(`Corrupt BRFS binary container (header length exceeds buffer)`);let d=new TextDecoder,f=d.decode(a.subarray(12,u)),p=JSON.parse(f),m=a.subarray(u),h=Object.assign({},t);if(Array.isArray(p.commandsSlice)){let[e,t]=p.commandsSlice,n=d.decode(m.subarray(e,e+t));try{let e=Function(n)();e&&typeof e==`object`&&Object.assign(h,e)}catch{}}let g=e=>{if(!e||typeof e!=`object`)return e;if(`$t`in e){let[t,n]=e.$t;return d.decode(m.subarray(t,t+n))}if(`$b`in e){let[t,r,i]=e.$b;return new n(m.slice(t,t+r).buffer,i||`application/octet-stream`)}if(`$l`in e)return new r(e.$l);if(`$dev`in e)return new i(e.$dev);if(`$c`in e){let t=e.$c;if(h[t])return h[t];if(p.inlineCommands&&p.inlineCommands[t])try{let e=U(),n=re();return Function(`Command`,`InteractiveCommand`,`return (${p.inlineCommands[t]});`)(e,n)}catch{return null}return null}if(`$d`in e){let t={};for(let[n,r]of Object.entries(e.$d)){let e=g(r);e!==null&&(t[n]=e)}return t}return e};return{filesystem:g(p.tree)||{},permissions:Object.assign({},p.permissions||{})}}function u(e){if(!e)return!1;let t=e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):null;return!!(t&&t.byteLength>=2&&t[0]===31&&t[1]===139)}async function d(e){if(typeof DecompressionStream<`u`&&typeof Response<`u`){let t=new DecompressionStream(`gzip`),n=new Blob([e]).stream().pipeThrough(t),r=await new Response(n).arrayBuffer();return new Uint8Array(r)}if(R!==void 0&&typeof R.getBuiltinModule==`function`){let t=R.getBuiltinModule(`zlib`);if(t)return new Uint8Array(t.gunzipSync(v.from(e.buffer,e.byteOffset,e.byteLength)))}throw Error(`Gzip decompression is not supported in this environment`)}function f(e){return e?!!(typeof e==`string`||typeof e.then==`function`||typeof e.arrayBuffer==`function`||u(e)):!1}async function p(e,t={}){if(!e)return{filesystem:{},permissions:t};if(typeof e.then==`function`)return p(await e,t);if(typeof e.arrayBuffer==`function`){let n=await e.arrayBuffer();return p(new Uint8Array(n),t)}if(typeof e==`string`){if(!/^https?:\/\//i.test(e)&&R!==void 0&&typeof R.getBuiltinModule==`function`&&typeof window>`u`)try{let n=R.getBuiltinModule(`fs`);if(n&&n.existsSync(e)){let r=await n.promises.readFile(e);return p(new Uint8Array(r.buffer,r.byteOffset,r.byteLength),t)}}catch{}let n=await fetch(e);if(!n.ok)throw Error(`Failed to load filesystem from ${e}: HTTP ${n.status}`);let r=await n.arrayBuffer();return p(new Uint8Array(r),t)}if(e instanceof ArrayBuffer||ArrayBuffer.isView(e)){let n=e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength);if(u(n)&&(n=await d(n)),s(n)){let e=l(n);return{filesystem:e.filesystem,permissions:Object.assign({},e.permissions,t)}}let r=new TextDecoder(`utf-8`).decode(n);try{let e=JSON.parse(r);return e&&typeof e==`object`&&e.filesystem&&typeof e.permissions==`object`?{filesystem:e.filesystem,permissions:Object.assign({},e.permissions,t)}:{filesystem:e,permissions:t}}catch{let e=Function(`return `+r)();return e&&typeof e==`object`&&e.filesystem&&typeof e.permissions==`object`?{filesystem:e.filesystem,permissions:Object.assign({},e.permissions,t)}:{filesystem:e||{},permissions:t}}}return typeof e==`object`&&e.filesystem&&typeof e.permissions==`object`?f(e.filesystem)||s(e.filesystem)?p(e.filesystem,Object.assign({},e.permissions,t)):{filesystem:e.filesystem,permissions:Object.assign({},e.permissions,t)}:{filesystem:e,permissions:t}}t.exports={MAGIC:a,FORMAT_VERSION:o,isBinaryContainer:s,isGzipBytes:u,isAsyncFilesystemSource:f,resolveFilesystemSource:p,serializeBinaryFilesystem:c,deserializeBinaryFilesystem:l,FilesystemStorage:class{static async save(e,t=`brsh-rootfs`){let n=e.context?e.context.fs:e,r=c(n.getRaw(),n.getRawPermissions());return typeof indexedDB<`u`&&await this._idbPut(t,r),r}static async load(e=`brsh-rootfs`){if(e instanceof Uint8Array||e instanceof ArrayBuffer||typeof e==`string`&&(/^https?:\/\//i.test(e)||e.endsWith(`.brfs`)))return p(e);if(typeof indexedDB<`u`&&typeof e==`string`){let t=await this._idbGet(e);if(t&&s(t))return l(t)}return null}static async loadOrFetch(e=`brsh-rootfs`,t={}){return await this.load(e)||p(t)}static createAutoSave(e=`brsh-rootfs`,t=null){return(n,r)=>{let i=c(n,r);typeof indexedDB<`u`&&this._idbPut(e,i).catch(()=>{}),typeof t==`function`&&t(i,n,r)}}static _openIdb(){return new Promise((e,t)=>{let n=indexedDB.open(`brsh_fs_storage`,1);n.onupgradeneeded=()=>{n.result.createObjectStore(`snapshots`)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}static async _idbPut(e,t){let n=await this._openIdb();return new Promise((r,i)=>{let a=n.transaction(`snapshots`,`readwrite`);a.objectStore(`snapshots`).put(t,e),a.oncomplete=()=>{n.close(),r()},a.onerror=()=>{n.close(),i(a.error)}})}static async _idbGet(e){let t=await this._openIdb();return new Promise((n,r)=>{let i=t.transaction(`snapshots`,`readonly`).objectStore(`snapshots`).get(e);i.onsuccess=()=>{t.close(),n(i.result||null)},i.onerror=()=>{t.close(),r(i.error)}})}}}})),ie=t(((e,t)=>{y();var n=q(),{BinaryFile:r,SymlinkRef:i,DeviceFile:a}=n;function o(e){for(let t of Object.keys(e)){let n=e[t];if(n&&typeof n==`object`&&`$l`in n)e[t]=new i(n.$l);else if(typeof n==`object`&&n&&!(n instanceof Uint8Array)&&!(n instanceof i)&&!(n instanceof a))o(n);else if(typeof n==`string`&&n.startsWith(`data:`)){let i=n.indexOf(`;`),a=n.indexOf(`,`,i);if(i!==-1&&a!==-1&&n.slice(i+1,a)===`base64`){let o=n.slice(5,i),s=n.slice(a+1),c;if(v!==void 0)c=new Uint8Array(v.from(s,`base64`));else{let e=atob(s);c=new Uint8Array(e.length);for(let t=0;t<e.length;t++)c[t]=e.charCodeAt(t)}e[t]=new r(c.buffer,o)}}}}t.exports=class extends n{constructor(e=`/`,t={},n={},r=null){if(super(),t instanceof Uint8Array||t instanceof ArrayBuffer){let{deserializeBinaryFilesystem:e}=J(),r=e(t);t=r.filesystem,n=Object.assign({},r.permissions,n)}else if(t&&typeof t==`object`&&t.filesystem&&(t.filesystem instanceof Uint8Array||typeof t.filesystem==`object`)&&(n=Object.assign({},t.permissions||{},n),t=t.filesystem,t instanceof Uint8Array||t instanceof ArrayBuffer)){let{deserializeBinaryFilesystem:e}=J(),r=e(t);t=r.filesystem,n=Object.assign({},r.permissions,n)}o(t),this.fileSystem=t,this.permissions=Object.assign({},n),this.cwd=e.endsWith(`/`)?e:e+`/`,this._onChange=r,this._changeScheduled=!1,this._initDevices()}_initDevices(){this._devices={};let e=this._devices;e.null=new a(`null`,{read:()=>``,write:()=>{}}),e.zero=new a(`zero`,{read:()=>new Uint8Array(4096),write:()=>{}}),e.urandom=new a(`urandom`,{read:()=>{let e=new Uint8Array(256);if(typeof crypto<`u`&&crypto.getRandomValues)crypto.getRandomValues(e);else for(let t=0;t<e.length;t++)e[t]=Math.floor(Math.random()*256);return e},write:()=>{}}),e.random=e.urandom,e.tty=new a(`tty`,{read:()=>``,write:()=>{}}),e.stdin=new i(`/dev/tty`),e.stdout=new i(`/dev/tty`),e.stderr=new i(`/dev/tty`)}_getDevDir(){return this._devices||this._initDevices(),this.fileSystem&&this.fileSystem.dev&&typeof this.fileSystem.dev==`object`&&!(this.fileSystem.dev instanceof i)&&!(this.fileSystem.dev instanceof Uint8Array)?Object.assign({},this.fileSystem.dev,this._devices):this._devices}_getRootOverlay(){let e=Object.assign({},this.fileSystem);return e.dev=this._getDevDir(),e}setTtyDevice(e={}){this._devices||this._initDevices(),this._devices.tty=new a(`tty`,{read:e.read||(()=>``),write:e.write||(()=>{}),mode:438}),this._devices.stdin=new i(`/dev/tty`),this._devices.stdout=new i(`/dev/tty`),this._devices.stderr=new i(`/dev/tty`)}toBinaryContainer(e={}){let{serializeBinaryFilesystem:t}=J();return t(this.fileSystem,this.permissions,e)}static fromBinaryContainer(e,t={}){let{deserializeBinaryFilesystem:n}=J();return n(e,t)}getFileByPath(e){let t=this._resolveByAbsolutePath(this._pathToAbsolute(e),!0);return t==null||!this.isReadable(e)?null:t instanceof a?t.read():t}_getFileRaw(e){let t=this._getFileByAbsolutePath(this._pathToAbsolute(e));return t instanceof a?t.read():t}exists(e){return this._resolveByAbsolutePath(this._pathToAbsolute(e),!0)!=null}isSymlink(e){return this._resolveByAbsolutePath(this._pathToAbsolute(e),!1)instanceof i}readSymlink(e){let t=this._resolveByAbsolutePath(this._pathToAbsolute(e),!1);return t instanceof i?t.target:null}createSymlink(e,t){this._setFileRaw(t,new i(e),!0)}stat(e){let t=this._resolveByAbsolutePath(this._pathToAbsolute(e),!1);return t==null?null:t instanceof i?{isDirectory:!1,isFile:!1,isCommand:!1,isBinary:!1,isSymlink:!0,isDevice:!1,isCharacterDevice:!1}:t instanceof a?{isDirectory:!1,isFile:!0,isCommand:!1,isBinary:t.read()instanceof Uint8Array,isSymlink:!1,isDevice:!0,isCharacterDevice:!0}:{isDirectory:t.constructor===Object,isFile:typeof t==`string`||t instanceof Uint8Array,isCommand:typeof t==`function`,isBinary:t instanceof Uint8Array,isSymlink:!1,isDevice:!1,isCharacterDevice:!1}}_pathToAbsolute(e){return e.startsWith(`./`)&&(e=e.substring(2)),e.startsWith(`/`)||(e=(this.cwd&&this.cwd.endsWith(`/`)?this.cwd:this.cwd?this.cwd+`/`:`/`)+e),this._traverseComplexAbsolutePath(e)}_traverseComplexAbsolutePath(e){let t=e.split(`/`);for(;t.includes(`..`);){let e=t.indexOf(`..`)-1;t.splice(e,2)}return t.join(`/`)}absolutePath(e){return this._pathToAbsolute(e)}setFileByPath(e,t,n=!1){let r=this._pathToAbsolute(e),i=this._getFileByAbsolutePath(r);if(i!=null){if(!this.isWritable(e))throw Error(`Permission denied`);if(i instanceof a){i.write(t),this._triggerChange();return}}else{let e=r.split(`/`);e.pop();let t=e.join(`/`)||`/`,n=this.getMode(t);if(n!==null&&!(n&128))throw Error(`Permission denied`)}this._setFileByAbsolutePath(r,t,n),this._triggerChange()}_setFileRaw(e,t,n=!1){let r=this._pathToAbsolute(e);this._setFileByAbsolutePath(r,t,n),this._triggerChange()}_setFileByAbsolutePath(e,t,n=!0){let r=e.split(`/`);r.shift();let o=r.pop();if(r.length>0&&r[0]===`dev`){let e=this._getDevDir(),i=r.slice(1);for(let t of i){if(!Object.prototype.hasOwnProperty.call(e,t)){if(!n)throw Error(`${t}: No such file or directory`);e[t]={}}e=e[t]}if(e[o]instanceof a){e[o].write(t);return}e[o]=t;return}if(r.length===0&&o===`dev`)throw Error(`dev: File exists`);let s=this.fileSystem,c=[];for(let e of r){if(c.push(e),!Object.prototype.hasOwnProperty.call(s,e)){if(!n)throw Error(`${e}: No such file or directory`);s[e]={}}let t=s[e];if(t instanceof i){let n=`/`+c.slice(0,-1).join(`/`),r=t.target.startsWith(`/`)?this._traverseComplexAbsolutePath(t.target):this._traverseComplexAbsolutePath(n+`/`+t.target);if(t=this._resolveByAbsolutePath(r,!0),typeof t!=`object`||!t||t instanceof i)throw Error(`${e}: Not a directory`)}s=t}if(s[o]instanceof a){s[o].write(t);return}s[o]=t}_resolveByAbsolutePath(e,t=!0,n=0){if(n>10)return null;let r=e.split(`/`);if(r.shift(),r.length>0&&r[r.length-1].length<1&&r.pop(),r.length===0)return this._getRootOverlay();let a=this.fileSystem,o=[];for(let e=0;e<r.length;e++){let s=r[e],c=e===r.length-1;if(e===0&&s===`dev`){a=this._getDevDir(),o.push(s);continue}if(typeof a!=`object`||!a||a instanceof i||!Object.prototype.hasOwnProperty.call(a,s))return null;if(a=a[s],o.push(s),a instanceof i&&(!c||t)){let e=`/`+o.slice(0,-1).join(`/`),t=a.target.startsWith(`/`)?this._traverseComplexAbsolutePath(a.target):this._traverseComplexAbsolutePath(e+`/`+a.target);if(a=this._resolveByAbsolutePath(t,!0,n+1),a==null)return null}}return a}_getFileByAbsolutePath(e){let t=e.split(`/`);if(t.shift(),t.length>0&&t[t.length-1].length<1&&t.pop(),t.length===0)return this._getRootOverlay();if(t[0]===`dev`){let e=this._getDevDir();for(let n=1;n<t.length;n++){if(typeof e!=`object`||!e||!Object.prototype.hasOwnProperty.call(e,t[n]))return null;e=e[t[n]]}return e}return t.reduce((e,t)=>typeof e!=`object`||!e||!Object.prototype.hasOwnProperty.call(e,t)?null:e[t],this.fileSystem)}deleteFileByPath(e){let t=this._pathToAbsolute(e),n=t.split(`/`);n.pop();let r=n.join(`/`)||`/`,i=this.getMode(r);if(i!==null&&!(i&128))throw Error(`${e}: Permission denied`);this._deleteByAbsolutePath(t);let a=t+`/`;Object.keys(this.permissions).forEach(e=>{(e===t||e.startsWith(a))&&delete this.permissions[e]}),this._triggerChange()}_deleteByAbsolutePath(e){let t=e.split(`/`);t.shift(),t[t.length-1]===``&&t.pop();let n=t.pop();if(!n)return;if(t.length>0&&t[0]===`dev`){let e=this._getDevDir();for(let n=1;n<t.length;n++){if(!e||typeof e!=`object`)return;e=e[t[n]]}e&&n in e&&delete e[n];return}if(t.length===0&&n===`dev`)return;let r=this.fileSystem,a=[];for(let e of t){if(a.push(e),!Object.prototype.hasOwnProperty.call(r,e))return;let t=r[e];if(t instanceof i){let e=`/`+a.slice(0,-1).join(`/`),n=t.target.startsWith(`/`)?this._traverseComplexAbsolutePath(t.target):this._traverseComplexAbsolutePath(e+`/`+t.target);if(t=this._resolveByAbsolutePath(n,!0),typeof t!=`object`||!t||t instanceof i)return}r=t}r&&n in r&&delete r[n]}getMode(e){let t=this._pathToAbsolute(e);if(this.permissions[t]!==void 0)return this.permissions[t];let n=this._resolveByAbsolutePath(t,!0);return n==null?null:n instanceof a?n.mode||438:n.constructor===Object?493:typeof n==`function`?365:420}setMode(e,t){let n=this._pathToAbsolute(e);this.permissions[n]=t,this._triggerChange()}getSize(e){let t=this._pathToAbsolute(e),n=this._resolveByAbsolutePath(t,!0);if(n==null)return 0;if(n instanceof a){let e=n.read();return e instanceof Uint8Array||typeof e==`string`?e.length:0}return n.constructor===Object?JSON.stringify(n).length:n instanceof Uint8Array?n.length:n.toString().length}getRawPermissions(){return Object.assign({},this.permissions)}setCwd(e){this.cwd=this._pathToAbsolute(e.endsWith(`/`)?e:e+`/`)}getRaw(){return this.fileSystem}addFiles(e){Object.entries(e).forEach(([e,t])=>{this._setFileRaw(e,t,!0)})}autoComplete(e,t){let n=this._pathToAbsolute(e).split(`/`),r=n.pop(),i=this._getFileRaw(n.length>1?n.join(`/`):`/`),a=this._getFileRaw(t);if(i&&i.constructor===Object){let t=Object.keys(i).filter(e=>e.startsWith(r));r.length<1&&(t=t.filter(e=>!e.startsWith(`.`)));let n=e.split(`/`);n.pop();let o=i;if(t.length<1&&n.length<1&&a&&(t=Object.keys(a).filter(e=>e.startsWith(r)),o=a),t.length)return{path:n.length?n.join(`/`):null,options:t.map(e=>o[e]&&o[e].constructor===Object?e.concat(`/`):e)}}return null}},t.exports.BinaryFile=r,t.exports.SymlinkRef=i})),Y=t(((e,t)=>{t.exports=null})),X=t(((e,t)=>{y();var n=ne(),{BinaryFile:r}=ie(),i=0,a=6,o=8,s=20,c=27,l=28,u=31,d=44,f=54,p=70,m=0,h=2,g=3,_=4,b=1,x=2,S=4,C=8,w=1,T=4,E=class extends n{constructor(e,t,n){super(e,t,n),this._ensurePkgMeta()}_ensurePkgMeta(){if(this._pkgMeta===void 0&&this.script){let e=this.context&&this.context.fs||this.fs;e&&(this._pkgMeta=I(e,this.script))}return this._pkgMeta||null}get name(){let e=this._ensurePkgMeta();return e&&e.bin?String(e.bin).toLowerCase():this.script?this.script.split(`/`).pop().replace(/\.(wasm|wat)$/i,``).toLowerCase():`wasm`}get requiresFilesystem(){return!0}get interactive(){if((this.arguments||[]).some(e=>e===`--help`||e===`-h`||e===`--version`||e===`-V`||e===`-v`))return!1;if(this._isInteractive!==void 0)return!!this._isInteractive;let e=this._ensurePkgMeta();return!!(e&&(e.interactive||e.wasm?.interactive)||this._inspectedWasm&&this._inspectedWasm.isInteractive)}get captureInput(){return this.interactive}kill(e=`SIGINT`){if(this._killed=!0,this.exitCode=130,this._exitAltScreen(),this._asyncifyReject){try{this._asyncifyReject(Error(`Interrupted by SIGINT`))}catch{}this._asyncifyReject=null}if(this._pendingReadResolve){let e=this._pendingReadResolve;this._pendingReadResolve=null;try{e()}catch{}}super.kill(e)}_enterAltScreen(){this._inAltScreen||(this._inAltScreen=!0,this.stdinStream&&typeof this.stdinStream.setRawMode==`function`&&this.stdinStream.setRawMode(!0),this.stdout&&typeof this.stdout.write==`function`&&this.stdout.write(`\x1B[?1049h\x1B[2J\x1B[H`))}_exitAltScreen(){this._inAltScreen&&(this._inAltScreen=!1,this.stdinStream&&typeof this.stdinStream.setRawMode==`function`&&this.stdinStream.setRawMode(!1),this.stdout&&typeof this.stdout.write==`function`&&this.stdout.write(`\x1B[0m\x1B[?1l\x1B[?1000l\x1B[?1002l\x1B[?1003l\x1B[?1006l\x1B[?1049l\x1B[?25h`))}_keyToBytes(e){if(!e)return null;if(typeof e!=`string`)return e instanceof Uint8Array?e:new Uint8Array([Number(e)&255]);if([`Control`,`Alt`,`Shift`,`Meta`,`CapsLock`,`NumLock`,`ScrollLock`,`Dead`,`Unidentified`].includes(e))return null;let t=e.match(/^\^([A-Za-z@\[\\\]^_?])$/);if(t){let e=t[1].toUpperCase();return e===`?`?new Uint8Array([127]):new Uint8Array([e.charCodeAt(0)-64])}let n={Enter:`\r`,Return:`\r`,Space:` `,Spacebar:` `,Backspace:``,Tab:` `,BackTab:`\x1B[Z`,Escape:`\x1B`,Esc:`\x1B`,ArrowUp:`\x1B[A`,Up:`\x1B[A`,ArrowDown:`\x1B[B`,Down:`\x1B[B`,ArrowRight:`\x1B[C`,Right:`\x1B[C`,ArrowLeft:`\x1B[D`,Left:`\x1B[D`,Home:`\x1B[H`,End:`\x1B[F`,PageUp:`\x1B[5~`,PageDown:`\x1B[6~`,Delete:`\x1B[3~`,Del:`\x1B[3~`,Insert:`\x1B[2~`,F1:`\x1BOP`,F2:`\x1BOQ`,F3:`\x1BOR`,F4:`\x1BOS`,F5:`\x1B[15~`,F6:`\x1B[17~`,F7:`\x1B[18~`,F8:`\x1B[19~`,F9:`\x1B[20~`,F10:`\x1B[21~`,F11:`\x1B[23~`,F12:`\x1B[24~`};return n[e]?new TextEncoder().encode(n[e]):new TextEncoder().encode(e)}onInput(e){if(!this._handlingStreamData&&!(this.stdinStream&&this.stdinStream._isPushing)){if(typeof this._externalKeyHandler==`function`){this._externalKeyHandler(e);return}this.stdinStream&&this.stdinStream.isRaw}}runCommand(){return super.runCommand().finally(()=>{this._inAltScreen&&this._exitAltScreen()})}run(){let e=this.script,t=(()=>{try{return Y()}catch{return null}})();return this._loadBytes(e,t).then(({bytes:e,isWat:t})=>(this.interactive&&(this.emit(`interactive`),this.context&&typeof this.context.emit==`function`&&this.context.emit(`interactive`)),t?this._runWat(e):this._runWasm(e))).catch(e=>{this.stdErr=e.message||String(e),this.exitCode=1})}_loadBytes(e,t){let n=this.context&&this.context.fs||this.fs;if(!n)return Promise.reject(Error(`${e}: Filesystem is not available`));let r;if(n.isRealFilesystem&&t)try{let i=t.readFileSync(n.absolutePath(e)),a=new Uint8Array(i);r=Promise.resolve({bytes:a,isWat:this._isWat(e,a)})}catch(t){return Promise.reject(Error(`${e}: ${t.message}`))}else{let t=n.getFileByPath(e);if(t==null)return Promise.reject(Error(`${e}: No such file or directory`));let i=this._contentToBytes(t);r=Promise.resolve({bytes:i,isWat:this._isWat(e,i)})}return r.then(e=>(!e.isWat&&e.bytes&&(this._inspectedWasm=M(e.bytes),this._inspectedWasm.isInteractive&&(this._isInteractive=!0)),e))}_isWat(e,t){return e.endsWith(`.wat`)?!0:t.length>0&&t[0]===40}_contentToBytes(e){if(e instanceof Uint8Array)return e;if(v!==void 0&&v.isBuffer(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);if(e instanceof ArrayBuffer)return new Uint8Array(e);let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t}async _runWat(e){let t=new TextDecoder().decode(e),n,r;try{r=await import(`wabt`)}catch{this.stdErr=`${this.script}: WAT execution requires the 'wabt' package\nInstall it with: npm install wabt`,this.exitCode=1;return}try{let e=r.default??r,{buffer:i}=(typeof e==`function`?await e():e).parseWat(this.script,t,{mutable_globals:!0}).toBinary({});n=new Uint8Array(i)}catch(e){this.stdErr=`${this.script}: WAT compilation error: ${e.message}`,this.exitCode=1;return}return this._runWasm(n)}async _runWasm(e){if(typeof WebAssembly>`u`){this.stdErr=`${this.script}: WebAssembly is not available in this environment`,this.exitCode=1;return}let t={1:``,2:``},n=new TextDecoder,y=new TextEncoder,E=null,D=null,O=!1,k=0,A=null,j=null,P=null,F=!1,I=!1,L=!1,R=null,ee=null,te=null,z=this.stdin===void 0||this.stdin===null||this.stdin===this.stdinStream||this.stdin&&this.stdin.isTTY,B=!!(this.interactive&&z);B&&(this.emit(`interactive`),this.context&&typeof this.context.emit==`function`&&this.context.emit(`interactive`));let V=()=>{B||!z||(B=!0,this._isInteractive=!0,this.emit(`interactive`),this.context&&typeof this.context.emit==`function`&&this.context.emit(`interactive`),this._enterAltScreen(),t[1]&&=(this.stdout&&typeof this.stdout.write==`function`&&this.stdout.write(t[1]),``),t[2]&&=(this.stderr&&typeof this.stderr.write==`function`&&this.stderr.write(t[2]),``),this.stdinStream&&typeof this.stdinStream.setRawMode==`function`&&this.stdinStream.setRawMode(!0))},H=(e,n)=>{if(B&&(e===1||e===2)){if(e===1&&this.stdout){this.stdout.write(n);return}if(e===2&&this.stderr){this.stderr.write(n);return}}t[e]=(t[e]||``)+n;let r=t[e].split(`
8
8
  `);t[e]=r.pop();for(let t of r)e===1?this.stdOut=t:this.stdErr=t},U=()=>{t[1]&&=(B&&this.stdout?this.stdout.write(t[1]):this.stdOut=t[1],``),t[2]&&=(B&&this.stderr?this.stderr.write(t[2]):this.stdErr=t[2],``)},W=[],ne=e=>{if(!(!e||e.length===0)){for(let t=0;t<e.length;t++)W.push(e[t]);if(j){let e=j;j=null,e()}}};te=e=>{this._handlingStreamData=!0;try{ne(typeof e==`string`?y.encode(e):e instanceof Uint8Array?e:v!==void 0&&v.isBuffer(e)?new Uint8Array(e):y.encode(String(e??``)))}finally{this._handlingStreamData=!1}},this._externalKeyHandler=e=>{if(this._handlingStreamData)return;let t=this._keyToBytes(e);t&&ne(t)};let re=!!(this._onStdinStreamData&&this.stdinStream&&typeof this.stdinStream.listeners==`function`&&this.stdinStream.listeners(`data`).includes(this._onStdinStreamData));re&&typeof this.stdinStream.off==`function`&&this.stdinStream.off(`data`,this._onStdinStreamData),z&&this.stdinStream&&typeof this.stdinStream.on==`function`&&this.stdinStream.on(`data`,te),z&&this.stdin&&this.stdin!==this.stdinStream&&typeof this.stdin.on==`function`&&this.stdin.on(`data`,te);let G=!z&&typeof this.stdin==`string`?y.encode(this.stdin):!z&&this.stdin instanceof Uint8Array?this.stdin:!z&&v!==void 0&&v.isBuffer(this.stdin)?new Uint8Array(this.stdin):new Uint8Array,K=0,q=this.context&&this.context.fs?this.context.fs:this.fs,J=this.context&&this.context.fs&&this.context.fs.cwd||this.fs&&this.fs.cwd||this.context&&typeof this.context.getVar==`function`&&this.context.getVar(`PWD`)||q&&q.cwd||`/`,ie=J.length>1&&J.endsWith(`/`)?J.slice(0,-1):J,Y=5,X=new Map([[3,{type:`preopen`,path:`/`,guestName:`/`}],[4,{type:`preopen`,path:ie,guestName:`.`}]]),ae=new Map([[0,0],[1,0],[2,0]]),oe=e=>{let t=e.split(`/`).filter(Boolean);return t.pop(),`/`+t.join(`/`)},Z=(e,t)=>{let n=X.get(e);if(!n||n.type!==`preopen`&&n.type!==`dir`)return null;if(t.startsWith(`/`))return q.absolutePath(t);if(!t||t===`.`)return q.absolutePath(n.path);let r=n.path.endsWith(`/`)?n.path:n.path+`/`,i=q.absolutePath(r+t),a=q.absolutePath(`/`+t);if(n.path!==`/`){if(q.exists(i))return i;if(q.exists(a))return a;let e=q.exists(oe(i));return q.exists(oe(a))&&!e?a:i}if(q.exists(i))return i;let o=q.absolutePath(t);return q.exists(o)?o:i},se=e=>{if(!(!e||e.type!==`file`||!e.dirty||!q))try{let t=!0;for(let n=0;n<e.bytes.length;n++)if(e.bytes[n]===0){t=!1;break}if(t){let t=n.decode(e.bytes);q.setFileByPath(e.path,t,!0)}else{let t=new Uint8Array(e.bytes.length);t.set(e.bytes),q.setFileByPath(e.path,new r(t.buffer,`application/octet-stream`),!0)}e.dirty=!1}catch{}},ce=this.stdout&&this.stdout.columns||this.stdinStream&&this.stdinStream.columns||this.context&&typeof this.context.getVar==`function`&&parseInt(this.context.getVar(`COLUMNS`),10)||80,le=this.stdout&&this.stdout.rows||this.stdinStream&&this.stdinStream.rows||this.context&&typeof this.context.getVar==`function`&&parseInt(this.context.getVar(`LINES`),10)||24,ue={TERM:`xterm-256color`,COLORTERM:`truecolor`,...this.context&&this.context.vars||{},COLUMNS:String(ce),LINES:String(le)},Q=Object.entries(ue).map(([e,t])=>`${e}=${t}`),de=new Proxy({fd_write:(e,t,r,a)=>{if(!E)return o;let s=new DataView(E.buffer);if(e===1||e===2){let o=0;for(let i=0;i<r;i++){let r=s.getUint32(t+i*8,!0),a=s.getUint32(t+i*8+4,!0);a>0&&H(e,n.decode(new Uint8Array(E.buffer,r,a))),o+=a}return s.setUint32(a,o,!0),i}let c=X.get(e);if(!c)return o;if(c.type===`dev_null`||c.type===`dev_zero`){let e=0;for(let n=0;n<r;n++)e+=s.getUint32(t+n*8+4,!0);return s.setUint32(a,e,!0),i}if(c.type===`dev_tty`){let e=0;for(let i=0;i<r;i++){let r=s.getUint32(t+i*8,!0),a=s.getUint32(t+i*8+4,!0);a>0&&H(1,n.decode(new Uint8Array(E.buffer,r,a))),e+=a}return s.setUint32(a,e,!0),i}if(c.type!==`file`)return o;let l=0;for(let e=0;e<r;e++){let n=s.getUint32(t+e*8,!0),r=s.getUint32(t+e*8+4,!0);if(r>0){let e=new Uint8Array(E.buffer,n,r),t=c.append?c.bytes.length:c.pos,i=t+r;if(i>c.bytes.length){let e=new Uint8Array(i);e.set(c.bytes),c.bytes=e}c.bytes.set(e,t),c.pos=t+r,c.dirty=!0,l+=r}}return s.setUint32(a,l,!0),i},fd_read:(e,t,n,r)=>{if(!E)return o;let s=new DataView(E.buffer),l=X.get(e),u=!!(l&&l.type===`dev_tty`);if(e===0||B&&e===2||u){(u||e===2)&&V();let o=!!((ae.get(e)||0)&T);if(O){if((typeof D?.exports?.asyncify_get_state==`function`?D.exports.asyncify_get_state():0)===2){if(D.exports.asyncify_stop_rewind(),L&&W.length===0)return L=!1,s.setUint32(r,0,!0),c;L=!1;let e=0;for(let r=0;r<n&&W.length>0;r++){let n=s.getUint32(t+r*8,!0),i=s.getUint32(t+r*8+4,!0),a=Math.min(i,W.length),o=W.splice(0,a);new Uint8Array(E.buffer).set(o,n),e+=a}return s.setUint32(r,e,!0),i}if(W.length>0){let e=0;for(let r=0;r<n&&W.length>0;r++){let n=s.getUint32(t+r*8,!0),i=s.getUint32(t+r*8+4,!0),a=Math.min(i,W.length),o=W.splice(0,a);new Uint8Array(E.buffer).set(o,n),e+=a}return s.setUint32(r,e,!0),i}return o?(s.setUint32(r,0,!0),a):(L=!1,D.exports.asyncify_start_unwind(k),A=new Promise((e,t)=>{let n=()=>{L=!1,j=null,P=null,this._pendingReadResolve=null,this._asyncifyReject=null,e()};j=n,this._pendingReadResolve=n,P=()=>{L=!0,j=null,P=null,this._pendingReadResolve=null,this._asyncifyReject=null,e()},this._asyncifyReject=t}),s.setUint32(r,0,!0),i)}if(W.length>0){let e=0;for(let r=0;r<n&&W.length>0;r++){let n=s.getUint32(t+r*8,!0),i=s.getUint32(t+r*8+4,!0),a=Math.min(i,W.length),o=W.splice(0,a);new Uint8Array(E.buffer).set(o,n),e+=a}return s.setUint32(r,e,!0),i}let l=0;for(let e=0;e<n&&K<G.length;e++){let n=s.getUint32(t+e*8,!0),r=s.getUint32(t+e*8+4,!0),i=Math.min(r,G.length-K);new Uint8Array(E.buffer).set(G.slice(K,K+i),n),K+=i,l+=i}return l===0&&o&&K>=G.length?(s.setUint32(r,0,!0),a):(s.setUint32(r,l,!0),i)}if(!l)return o;if(l.type===`dev_null`)return s.setUint32(r,0,!0),i;if(l.type===`dev_zero`){let e=0;for(let r=0;r<n;r++){let n=s.getUint32(t+r*8,!0),i=s.getUint32(t+r*8+4,!0);new Uint8Array(E.buffer,n,i).fill(0),e+=i}return s.setUint32(r,e,!0),i}if(l.type===`dev_urandom`){let e=0;for(let r=0;r<n;r++){let n=s.getUint32(t+r*8,!0),i=s.getUint32(t+r*8+4,!0),a=new Uint8Array(E.buffer,n,i);if(typeof crypto<`u`&&crypto.getRandomValues)crypto.getRandomValues(a);else for(let e=0;e<i;e++)a[e]=Math.floor(Math.random()*256);e+=i}return s.setUint32(r,e,!0),i}if(l.type!==`file`)return o;let d=0;for(let e=0;e<n&&l.pos<l.bytes.length;e++){let n=s.getUint32(t+e*8,!0),r=s.getUint32(t+e*8+4,!0),i=Math.min(r,l.bytes.length-l.pos);new Uint8Array(E.buffer).set(l.bytes.subarray(l.pos,l.pos+i),n),l.pos+=i,d+=i}return s.setUint32(r,d,!0),i},fd_seek:(e,t,n,r,a)=>{if(!E)return o;if(e<=2)return p;let s=X.get(e);if(!s)return o;if(s.type===`dev_tty`||s.type===`dev_null`||s.type===`dev_zero`||s.type===`dev_urandom`)return p;if(s.type!==`file`)return o;let c,u,d;typeof t==`bigint`?(c=Number(t),u=n,d=r):(c=t,u=r,d=a);let f=s.pos;if(u===0)f=c;else if(u===1)f=s.pos+c;else if(u===2)f=s.bytes.length+c;else return l;return f<0?l:(s.pos=f,d&&new DataView(E.buffer).setBigUint64(d,BigInt(s.pos),!0),i)},fd_tell:(e,t)=>{if(!E)return o;let n=X.get(e);return!n||n.type!==`file`?o:(new DataView(E.buffer).setBigUint64(t,BigInt(n.pos),!0),i)},fd_close:e=>{if(e<=2)return i;let t=X.get(e);return t?(t.type===`file`&&se(t),X.delete(e),ae.delete(e),i):o},fd_sync:e=>{let t=X.get(e);return t&&se(t),i},fd_datasync:e=>{let t=X.get(e);return t&&se(t),i},fd_prestat_get:(e,t)=>{if(!E)return o;let n=X.get(e);if(!n||n.type!==`preopen`)return o;let r=new DataView(E.buffer),a=y.encode(n.guestName);return r.setUint8(t,0),r.setUint32(t+4,a.length,!0),i},fd_prestat_dir_name:(e,t,n)=>{if(!E)return o;let r=X.get(e);if(!r||r.type!==`preopen`)return o;let a=y.encode(r.guestName);return new Uint8Array(E.buffer,t,Math.min(n,a.length)).set(a.subarray(0,n)),i},fd_fdstat_get:(e,t)=>{if(!E)return o;let n=new DataView(E.buffer),r=m;if(e<=2)r=h;else{let t=X.get(e);if(!t)return o;r=t.type===`dev_null`||t.type===`dev_zero`||t.type===`dev_urandom`||t.type===`dev_tty`?h:t.type===`preopen`||t.type===`dir`?g:_}for(let e=0;e<24;e++)n.setUint8(t+e,0);n.setUint8(t,r);let a=ae.get(e)||(X.get(e)?.append?w:0);return n.setUint16(t+2,a,!0),n.setBigUint64(t+8,18446744073709551615n,!0),n.setBigUint64(t+16,18446744073709551615n,!0),i},fd_fdstat_set_flags:(e,t)=>{if(!E||e>2&&!X.has(e))return o;ae.set(e,t);let n=X.get(e);return n&&(n.append=!!(t&w)),(e===0||e===2||n&&n.type===`dev_tty`)&&t&T&&V(),i},fd_filestat_get:(e,t)=>{if(!E)return o;let n=new DataView(E.buffer);for(let e=0;e<64;e++)n.setUint8(t+e,0);if(e<=2)return n.setUint8(t+16,h),i;let r=X.get(e);if(!r)return o;if(r.type===`dev_null`||r.type===`dev_zero`||r.type===`dev_urandom`||r.type===`dev_tty`)return n.setUint8(t+16,h),n.setBigUint64(t+24,1n,!0),i;let a=r.type===`preopen`||r.type===`dir`;return n.setUint8(t+16,a?g:_),n.setBigUint64(t+24,1n,!0),n.setBigUint64(t+32,BigInt(r.bytes?r.bytes.length:0),!0),i},path_open:(e,t,r,a,c,l,p,m,h)=>{if(!E||!q)return o;let g=Z(e,n.decode(new Uint8Array(E.buffer,r,a)));if(!g)return o;let _=g.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`;if(_===`/dev/null`){let e=Y++;return X.set(e,{type:`dev_null`,path:`/dev/null`}),new DataView(E.buffer).setUint32(h,e,!0),i}if(_===`/dev/zero`){let e=Y++;return X.set(e,{type:`dev_zero`,path:`/dev/zero`}),new DataView(E.buffer).setUint32(h,e,!0),i}if(_===`/dev/urandom`||_===`/dev/random`){let e=Y++;return X.set(e,{type:`dev_urandom`,path:_}),new DataView(E.buffer).setUint32(h,e,!0),i}if(_===`/dev/tty`||_===`/dev/stdin`){V();let e=Y++;return X.set(e,{type:`dev_tty`,path:_}),new DataView(E.buffer).setUint32(h,e,!0),i}if(_===`/dev/stdout`)return new DataView(E.buffer).setUint32(h,1,!0),i;if(_===`/dev/stderr`)return new DataView(E.buffer).setUint32(h,2,!0),i;let v=q.stat(g),T=v!==null;if(c&S&&c&b&&T)return s;if(c&x){if(!T)return d;if(!v.isDirectory)return f;let e=Y++;return X.set(e,{type:`dir`,path:g}),new DataView(E.buffer).setUint32(h,e,!0),i}if(T&&v.isDirectory)return u;if(!T&&!(c&b))return d;let D=new Uint8Array,O=!1;if(T&&!(c&C)){let e=q.getFileByPath(g);e!=null&&(D=typeof e==`string`?y.encode(e):new Uint8Array(this._contentToBytes(e)))}else O=!0;let k=Y++;return X.set(k,{type:`file`,path:g,bytes:D,pos:m&w?D.length:0,append:!!(m&w),dirty:O}),new DataView(E.buffer).setUint32(h,k,!0),i},path_filestat_get:(e,t,r,a,s)=>{if(!E||!q)return o;let c=Z(e,n.decode(new Uint8Array(E.buffer,r,a)));if(!c)return o;let l=c.replace(/\/+/g,`/`).replace(/\/$/,``)||`/`,u=q.stat(c);if(l===`/dev/null`||l===`/dev/zero`||l===`/dev/urandom`||l===`/dev/random`||l===`/dev/tty`||l===`/dev/stdin`||l===`/dev/stdout`||l===`/dev/stderr`||u&&(u.isDevice||u.isCharacterDevice)){let e=new DataView(E.buffer);for(let t=0;t<64;t++)e.setUint8(s+t,0);return e.setUint8(s+16,h),e.setBigUint64(s+24,1n,!0),i}if(!u)return d;let f=new DataView(E.buffer);for(let e=0;e<64;e++)f.setUint8(s+e,0);return f.setUint8(s+16,u.isDirectory?g:_),f.setBigUint64(s+24,1n,!0),f.setBigUint64(s+32,BigInt(q.getSize(c)||0),!0),i},path_create_directory:(e,t,r)=>{if(!E||!q)return o;let a=Z(e,n.decode(new Uint8Array(E.buffer,t,r)));if(!a)return o;if(q.exists(a))return s;try{return q.setFileByPath(a,{},!0),i}catch{return l}},path_unlink_file:(e,t,r)=>{if(!E||!q)return o;let a=Z(e,n.decode(new Uint8Array(E.buffer,t,r)));if(!a||!q.exists(a))return d;try{return q.deleteFileByPath(a),i}catch{return l}},path_remove_directory:(e,t,r)=>{if(!E||!q)return o;let a=Z(e,n.decode(new Uint8Array(E.buffer,t,r)));if(!a||!q.exists(a))return d;try{return q.deleteFileByPath(a),i}catch{return l}},path_rename:(e,t,r,a,s,c)=>{if(!E||!q)return o;let u=n.decode(new Uint8Array(E.buffer,t,r)),f=n.decode(new Uint8Array(E.buffer,s,c)),p=Z(e,u),m=Z(a,f);if(!p||!m)return o;if(!q.exists(p))return d;for(let e of X.values())e.path===p&&(se(e),e.path=m);try{let e=q.getFileByPath(p);return q.setFileByPath(m,e,!0),q.deleteFileByPath(p),i}catch{return l}},proc_exit:e=>{throw e!==0&&(this.exitCode=e),{_wasmExit:!0,code:e}},args_sizes_get:(e,t)=>{if(!E)return l;let n=[this.script,...this.arguments||[]],r=new DataView(E.buffer);return r.setUint32(e,n.length,!0),r.setUint32(t,n.reduce((e,t)=>e+y.encode(t).length+1,0),!0),i},args_get:(e,t)=>{if(!E)return l;let n=[this.script,...this.arguments||[]],r=new DataView(E.buffer),a=t;for(let t=0;t<n.length;t++){r.setUint32(e+t*4,a,!0);let i=y.encode(n[t]+`\0`);new Uint8Array(E.buffer).set(i,a),a+=i.length}return i},environ_sizes_get:(e,t)=>{if(!E)return l;let n=new DataView(E.buffer);n.setUint32(e,Q.length,!0);let r=Q.reduce((e,t)=>e+y.encode(t).length+1,0);return n.setUint32(t,r,!0),i},environ_get:(e,t)=>{if(!E)return l;let n=new DataView(E.buffer),r=t;for(let t=0;t<Q.length;t++){n.setUint32(e+t*4,r,!0);let i=y.encode(Q[t]+`\0`);new Uint8Array(E.buffer).set(i,r),r+=i.length}return i},clock_time_get:(e,t,n)=>{if(E){let t=e===1&&typeof performance<`u`&&typeof performance.now==`function`?BigInt(Math.round(performance.now()*1e6)):BigInt(Date.now())*1000000n;new DataView(E.buffer).setBigUint64(n,t,!0)}return i},random_get:(e,t)=>{if(E){let n=new Uint8Array(E.buffer,e,t);for(let e=0;e<t;e++)n[e]=Math.random()*256|0}return i},clock_nanosleep:(e,t,n,r,a)=>{if(!E)return o;let s=new DataView(E.buffer).getBigUint64(n,!0),c=0;if(t&1){let e=BigInt(Date.now())*1000000n;c=s>e?Number((s-e)/1000000n):0}else c=Number(s/1000000n);return O&&c>0?(typeof D?.exports?.asyncify_get_state==`function`?D.exports.asyncify_get_state():0)===2?(D.exports.asyncify_stop_rewind(),i):(D.exports.asyncify_start_unwind(k),A=new Promise(e=>setTimeout(e,Math.max(1,c))),i):i},poll_oneoff:(e,t,n,r)=>{if(!E)return o;let a=new DataView(E.buffer);if(O){if((typeof D?.exports?.asyncify_get_state==`function`?D.exports.asyncify_get_state():0)===2){if(D.exports.asyncify_stop_rewind(),I&&W.length===0)return I=!1,a.setUint32(r,0,!0),c;I=!1;let o=0;for(let r=0;r<n;r++){let n=e+r*48,s=a.getBigUint64(n,!0),c=a.getUint8(n+8),l=!1;if(c===0)l=F;else if(c===1){let e=a.getUint32(n+16,!0),t=X.get(e),r=!!(t&&t.type===`dev_tty`);(e===0||B&&e===2||r)&&W.length>0&&(l=!0)}else c===2&&(l=!0);if(l){let e=t+o*32;a.setBigUint64(e,s,!0),a.setUint16(e+8,i,!0),a.setUint8(e+10,c);for(let t=11;t<32;t++)a.setUint8(e+t,0);c===1&&a.setBigUint64(e+16,BigInt(W.length),!0),o++}}return a.setUint32(r,o,!0),i}let o=0,s=!1,l=1/0;for(let t=0;t<n;t++){let n=e+t*48,r=a.getUint8(n+8);if(r===0){let e=a.getBigUint64(n+24,!0),t=a.getUint16(n+40,!0),r=0;if(t&1){let t=BigInt(Date.now())*1000000n;r=e>t?Number((e-t)/1000000n):0}else r=Number(e/1000000n);r<l&&(l=r)}else if(r===1){s=!0;let e=a.getUint32(n+16,!0),t=X.get(e),r=!!(t&&t.type===`dev_tty`);(e===0||e===2||r)&&V(),(e===0||B&&e===2||r)&&W.length>0&&o++}else r===2&&o++}if(o>0||l===0){let o=0;for(let r=0;r<n;r++){let n=e+r*48,s=a.getBigUint64(n,!0),c=a.getUint8(n+8),u=!1;if(c===0&&l===0)u=!0;else if(c===1){let e=a.getUint32(n+16,!0),t=X.get(e),r=!!(t&&t.type===`dev_tty`);(e===0||B&&e===2||r)&&W.length>0&&(u=!0)}else c===2&&(u=!0);if(u){let e=t+o*32;a.setBigUint64(e,s,!0),a.setUint16(e+8,i,!0),a.setUint8(e+10,c);for(let t=11;t<32;t++)a.setUint8(e+t,0);c===1&&a.setBigUint64(e+16,BigInt(W.length),!0),o++}}return a.setUint32(r,o,!0),i}return F=!1,I=!1,D.exports.asyncify_start_unwind(k),A=new Promise((e,t)=>{let n=null;this._asyncifyReject=t;let r=()=>{n&&clearTimeout(n),F=!1,I=!1,j=null,P=null,this._pendingReadResolve=null,this._asyncifyReject=null,e()};s&&(j=r,this._pendingReadResolve=r,P=()=>{n&&clearTimeout(n),F=!1,I=!0,j=null,P=null,this._pendingReadResolve=null,this._asyncifyReject=null,e()}),l!==1/0&&(n=setTimeout(()=>{F=!0,I=!1,j=null,P=null,this._pendingReadResolve=null,this._asyncifyReject=null,e()},Math.max(1,l)))}),a.setUint32(r,0,!0),i}return a.setUint32(r,0,!0),i}},{get(e,t){return t in e?e[t]:()=>0}}),fe=e=>{if(!E||!e)return``;try{let t=new DataView(E.buffer).getUint32(e-4,!0),n=new Uint16Array(E.buffer,e,t>>>1);return String.fromCharCode(...n)}catch{return``}},$={wasi_snapshot_preview1:de,wasi_unstable:de,env:new Proxy({print:(e,t)=>{E&&H(1,n.decode(new Uint8Array(E.buffer,e,t)))},eprint:(e,t)=>{E&&H(2,n.decode(new Uint8Array(E.buffer,e,t)))},log:e=>{H(1,fe(e)+`