@jerryan/just-bash 3.5.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +334 -308
  2. package/LICENSE +201 -201
  3. package/README.md +827 -827
  4. package/dist/agent-sandbox.d.ts +27 -0
  5. package/dist/bin/chunks/{chunk-7WBCA2BB.js → chunk-3DWQCLNP.js} +1 -1
  6. package/dist/bin/chunks/{chunk-QFTZKD5O.js → chunk-6TUILMPB.js} +1 -1
  7. package/dist/bin/chunks/chunk-JHEAT7AR.js +12 -0
  8. package/dist/bin/chunks/{chunk-MF3GVFLC.js → chunk-L345YZ6R.js} +1 -1
  9. package/dist/bin/chunks/chunk-QKJAAJ7J.js +3 -0
  10. package/dist/bin/chunks/chunk-SE7JHGP3.js +9 -0
  11. package/dist/bin/{shell/chunks/chunk-NLU5LALY.js → chunks/chunk-YCOJCFGU.js} +1 -1
  12. package/dist/bin/{shell/chunks/flag-coverage-J2ZHA465.js → chunks/flag-coverage-FYJ2V7J4.js} +1 -1
  13. package/dist/bin/chunks/{js-exec-DJQLXWCS.js → js-exec-5QZZCOR7.js} +7 -7
  14. package/dist/bin/chunks/js-exec-worker.js +155 -33
  15. package/dist/bin/{shell/chunks/python3-JCJHSX4Z.js → chunks/python3-TMFYDQAP.js} +1 -1
  16. package/dist/bin/chunks/{rm-3PLW4O4B.js → rm-NLG5344W.js} +1 -1
  17. package/dist/bin/chunks/{sleep-DVFE2GSF.js → sleep-MOJQBZMY.js} +1 -1
  18. package/dist/bin/{shell/chunks/sqlite3-KP42NNIY.js → chunks/sqlite3-3EUPHVEZ.js} +1 -1
  19. package/dist/bin/chunks/{timeout-YGFHQJKX.js → timeout-RQOWSWYG.js} +1 -1
  20. package/dist/bin/chunks/worker.js +162 -48
  21. package/dist/bin/just-bash.js +307 -307
  22. package/dist/bin/shell/chunks/{chunk-7WBCA2BB.js → chunk-3DWQCLNP.js} +1 -1
  23. package/dist/bin/shell/chunks/{chunk-QFTZKD5O.js → chunk-6TUILMPB.js} +1 -1
  24. package/dist/bin/shell/chunks/chunk-JHEAT7AR.js +12 -0
  25. package/dist/bin/shell/chunks/{chunk-MF3GVFLC.js → chunk-L345YZ6R.js} +1 -1
  26. package/dist/bin/shell/chunks/chunk-QKJAAJ7J.js +3 -0
  27. package/dist/bin/shell/chunks/chunk-SE7JHGP3.js +9 -0
  28. package/dist/bin/{chunks/chunk-NLU5LALY.js → shell/chunks/chunk-YCOJCFGU.js} +1 -1
  29. package/dist/bin/{chunks/flag-coverage-J2ZHA465.js → shell/chunks/flag-coverage-FYJ2V7J4.js} +1 -1
  30. package/dist/bin/shell/chunks/{js-exec-DJQLXWCS.js → js-exec-5QZZCOR7.js} +7 -7
  31. package/dist/bin/{chunks/python3-JCJHSX4Z.js → shell/chunks/python3-TMFYDQAP.js} +1 -1
  32. package/dist/bin/shell/chunks/{rm-3PLW4O4B.js → rm-NLG5344W.js} +1 -1
  33. package/dist/bin/shell/chunks/{sleep-DVFE2GSF.js → sleep-MOJQBZMY.js} +1 -1
  34. package/dist/bin/{chunks/sqlite3-KP42NNIY.js → shell/chunks/sqlite3-3EUPHVEZ.js} +1 -1
  35. package/dist/bin/shell/chunks/{timeout-YGFHQJKX.js → timeout-RQOWSWYG.js} +1 -1
  36. package/dist/bin/shell/shell.js +237 -237
  37. package/dist/bundle/browser.js +240 -240
  38. package/dist/bundle/chunks/{chunk-N3A4JVFJ.js → chunk-6IA4DXG2.js} +1 -1
  39. package/dist/bundle/chunks/chunk-G3IRZ4FN.js +8 -0
  40. package/dist/bundle/chunks/{chunk-24NLAR7R.js → chunk-KEMO3CBM.js} +1 -1
  41. package/dist/bundle/chunks/chunk-PS2RJNZZ.js +2 -0
  42. package/dist/bundle/chunks/{chunk-DMWNBCXJ.js → chunk-TLPMB3FO.js} +1 -1
  43. package/dist/bundle/chunks/chunk-ULXGGWAD.js +11 -0
  44. package/dist/bundle/chunks/{chunk-XV2V56NQ.js → chunk-YFFU74KY.js} +1 -1
  45. package/dist/bundle/chunks/{flag-coverage-DPSAPFXA.js → flag-coverage-XSPWRCVG.js} +1 -1
  46. package/dist/bundle/chunks/{js-exec-XKF2B7C3.js → js-exec-57QMXJG5.js} +7 -7
  47. package/dist/bundle/chunks/js-exec-worker.js +155 -33
  48. package/dist/bundle/chunks/{python3-F5S5TYGS.js → python3-NNONJINM.js} +1 -1
  49. package/dist/bundle/chunks/{rm-JQ4GDKDD.js → rm-R2ZENNSN.js} +1 -1
  50. package/dist/bundle/chunks/{sleep-PPRBTSVR.js → sleep-25QUPVDK.js} +1 -1
  51. package/dist/bundle/chunks/{sqlite3-4EZ4GXVD.js → sqlite3-M4UZPXDO.js} +1 -1
  52. package/dist/bundle/chunks/{timeout-C6WDYPLV.js → timeout-37GM7IIL.js} +1 -1
  53. package/dist/bundle/chunks/worker.js +162 -48
  54. package/dist/bundle/index.cjs +760 -760
  55. package/dist/bundle/index.js +306 -306
  56. package/dist/commands/js-exec/js-exec.d.ts +4 -0
  57. package/dist/commands/worker-bridge/bridge-handler.d.ts +9 -0
  58. package/dist/commands/worker-bridge/protocol.d.ts +17 -0
  59. package/dist/commands/worker-bridge/sync-backend.d.ts +3 -0
  60. package/dist/fs/overlay-fs/apply.d.ts +13 -0
  61. package/dist/fs/overlay-fs/index.d.ts +2 -0
  62. package/dist/fs/overlay-fs/merge.d.ts +24 -0
  63. package/dist/fs/overlay-fs/overlay-fs.d.ts +17 -0
  64. package/dist/fs/overlay-fs/overlay-tree.d.ts +39 -0
  65. package/dist/fs/real-fs-utils.d.ts +15 -0
  66. package/dist/fs/vfs-template.d.ts +51 -0
  67. package/dist/index.d.cts +2 -1
  68. package/dist/index.d.ts +2 -1
  69. package/dist/timers.d.ts +9 -0
  70. package/package.json +32 -33
  71. package/vendor/cpython-emscripten/python.cjs +2 -2
  72. package/dist/bin/chunks/chunk-JQM3DKCH.js +0 -12
  73. package/dist/bin/chunks/chunk-PPVF2N6C.js +0 -3
  74. package/dist/bin/chunks/chunk-YOIFOOGX.js +0 -9
  75. package/dist/bin/shell/chunks/chunk-JQM3DKCH.js +0 -12
  76. package/dist/bin/shell/chunks/chunk-PPVF2N6C.js +0 -3
  77. package/dist/bin/shell/chunks/chunk-YOIFOOGX.js +0 -9
  78. package/dist/bundle/chunks/chunk-LPJEKUCB.js +0 -8
  79. package/dist/bundle/chunks/chunk-WXPNKIIH.js +0 -2
  80. package/dist/bundle/chunks/chunk-YJKHREBZ.js +0 -11
@@ -33,6 +33,11 @@ export interface SandboxChangeSet {
33
33
  writes: SandboxWrite[];
34
34
  /** Pending deletions (top-most only), as real absolute paths, sorted. */
35
35
  deletions: string[];
36
+ /**
37
+ * Wall-clock creation time of each whiteout, aligned with `deletions`
38
+ * (same order). Optional so hand-built change sets keep working.
39
+ */
40
+ deletionChangedAt?: number[];
36
41
  }
37
42
  /**
38
43
  * A ready-made agent sandbox: InMemoryFs virtual root, copy-on-write
@@ -88,7 +93,29 @@ export declare class AgentSandbox {
88
93
  */
89
94
  applyChanges(changes?: SandboxChangeSet): Promise<void>;
90
95
  /** Longest-prefix match of a real path onto a mounted overlay. */
96
+ private findOverlayEntry;
97
+ /** Longest-prefix match of a real path onto a mounted overlay. */
91
98
  private findOverlay;
99
+ /**
100
+ * Map a real host path onto the overlay that shadows it: the virtual
101
+ * mount point, the OverlayFs, and the overlay-relative path (usable
102
+ * with overlay.exists/stat/readFile/diff). Returns null when the path
103
+ * is not under any mounted overlay's root. For the most robust match,
104
+ * pass a canonical path (e.g. from canonicalizeRealPath) — matching is
105
+ * by path prefix.
106
+ */
107
+ resolveRealPath(realPath: string): {
108
+ mountPoint: string;
109
+ overlay: OverlayFs;
110
+ path: string;
111
+ } | null;
112
+ /**
113
+ * Map a VFS path (as used with bash.fs, e.g. "/project/src/app.ts")
114
+ * onto the real host path it resolves to. Returns null when the path
115
+ * is not under any overlay mount (plain memory-backed VFS regions
116
+ * have no real counterpart).
117
+ */
118
+ toRealPath(vfsPath: string): string | null;
92
119
  /**
93
120
  * Reconcile all overlays with disk: drop pending entries that now match,
94
121
  * keep the rest. Also the supported re-baseline after intentional
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{c as l,d as u}from"./chunk-PPVF2N6C.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};
3
+ import{d as l,e as u}from"./chunk-QKJAAJ7J.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,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 w}from"./chunk-B2DRBHGQ.js";import{a as y}from"./chunk-3MRB66F4.js";import{a as b}from"./chunk-3PCPQIUD.js";import{a as h,b as A}from"./chunk-PPVF2N6C.js";import{a as v,b as O,c as d}from"./chunk-MUFNRCMY.js";var x={name:"timeout",summary:"run a command with a time limit",usage:"timeout [OPTION] DURATION COMMAND [ARG]...",description:`Start COMMAND, and kill it if still running after DURATION.
3
+ import{a as w}from"./chunk-B2DRBHGQ.js";import{a as y}from"./chunk-3MRB66F4.js";import{a as b}from"./chunk-3PCPQIUD.js";import{a as h,b as A}from"./chunk-QKJAAJ7J.js";import{a as v,b as O,c as d}from"./chunk-MUFNRCMY.js";var x={name:"timeout",summary:"run a command with a time limit",usage:"timeout [OPTION] DURATION COMMAND [ARG]...",description:`Start COMMAND, and kill it if still running after DURATION.
4
4
 
5
5
  DURATION is a number with optional suffix:
6
6
  s - seconds (default)
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
+ import{a as A}from"./chunk-3MRB66F4.js";import{b as f}from"./chunk-O2BCKSMK.js";import{a as O,b as h}from"./chunk-TW2IJRUF.js";import{d as F,e as g}from"./chunk-QKJAAJ7J.js";import{b as m}from"./chunk-HWI42GQO.js";import{a as T,b as w}from"./chunk-PBOVSFTJ.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+=`
4
+ ${this.commandName}: execution timeout exceeded
5
+ `,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+=`
6
+ ${this.commandName}: execution timeout exceeded
7
+ `,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+=`
8
+ ${this.commandName}: execution timeout exceeded
9
+ `,this.output.exitCode=124;break}let o=this.remainingMs();if(!await this.protocol.waitUntilReady(o)){this.output.stderr+=`
10
+ ${this.commandName}: execution timeout exceeded
11
+ `,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
12
+ `,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};
@@ -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 p}from"./chunk-B2DRBHGQ.js";import{a as n,b as l}from"./chunk-PPVF2N6C.js";import{a as m,b as d}from"./chunk-MUFNRCMY.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
+ import{a as p}from"./chunk-B2DRBHGQ.js";import{a as n,b as l}from"./chunk-QKJAAJ7J.js";import{a as m,b as d}from"./chunk-MUFNRCMY.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:
4
4
  s - seconds (default)
5
5
  m - minutes
6
6
  h - hours
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
+ import{b as a}from"./chunk-HWI42GQO.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};
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
+ import{a as g}from"./chunk-PBOVSFTJ.js";import{a as u}from"./chunk-NE4R2FVV.js";import{a as p}from"./chunk-I4IRHQDW.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
4
+ `,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
5
+ `,i=1;continue}await s.fs.rm(n,{recursive:l,force:a}),v&&(f+=`removed '${r}'
6
+ `)}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
7
+ `:t.includes("ENOTEMPTY")||t.includes("not empty")?o+=`rm: cannot remove '${r}': Directory not empty
8
+ `:o+=`rm: cannot remove '${r}': ${g(t)}
9
+ `,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,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 W}from"./chunk-7WBCA2BB.js";import{c as $}from"./chunk-42AMF6EE.js";import{b as C}from"./chunk-HWI42GQO.js";import{a as V}from"./chunk-WEHA3JFD.js";import{b as I}from"./chunk-CPKBPQ2C.js";import{a as B,b}from"./chunk-PBOVSFTJ.js";import{a as x}from"./chunk-I4IRHQDW.js";import{a as N,b as R}from"./chunk-MUFNRCMY.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
+ import{a as W}from"./chunk-3DWQCLNP.js";import{c as $}from"./chunk-42AMF6EE.js";import{b as C}from"./chunk-HWI42GQO.js";import{a as V}from"./chunk-WEHA3JFD.js";import{b as I}from"./chunk-CPKBPQ2C.js";import{a as B,b}from"./chunk-PBOVSFTJ.js";import{a as x}from"./chunk-I4IRHQDW.js";import{a as N,b as R}from"./chunk-MUFNRCMY.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(`
4
4
  `)}
5
5
  `:""}function v(e){return e.includes(",")||e.includes('"')||e.includes("'")||e.includes(`
6
6
  `)?`"${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(`,
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{b as yr}from"./chunk-RPUFEP5O.js";import{b as Ar}from"./chunk-V2XF3TTW.js";import{b as $r}from"./chunk-7PUOS2OO.js";import"./chunk-V4U26ZWL.js";import"./chunk-KP2UH5CJ.js";import{c as Sr}from"./chunk-NLU5LALY.js";import"./chunk-7WBCA2BB.js";import{b as wr}from"./chunk-PQ2INDRF.js";import{b as xr}from"./chunk-DYIBFLS3.js";import{b as vr}from"./chunk-RVPTAYDS.js";import{b as kr}from"./chunk-TYBXHT6W.js";import{b as qr}from"./chunk-AJF3OBTR.js";import{b as Cr}from"./chunk-2ETT4ELS.js";import{b as br}from"./chunk-OUQKFRVR.js";import{d as Ir,e as Mr,f as jr}from"./chunk-HQ63MFHG.js";import"./chunk-QES5OSUC.js";import{b as tr}from"./chunk-QFTZKD5O.js";import{b as lr}from"./chunk-CC2AQ6B7.js";import{b as ur}from"./chunk-QMPZXXEK.js";import{b as pr}from"./chunk-WFHYGSLJ.js";import{b as er}from"./chunk-LXFMIXGA.js";import{b as dr}from"./chunk-WFVCEB5T.js";import{b as cr}from"./chunk-KG2KXL4Y.js";import"./chunk-2YLY6FJA.js";import{b as hr}from"./chunk-OXLC2WWX.js";import{c as or,d as ar}from"./chunk-KI54R2QB.js";import{b as sr}from"./chunk-KUMHQGUR.js";import{c as ir,d as gr}from"./chunk-MYTNZ7MA.js";import{b as mr}from"./chunk-7PPAWLUI.js";import"./chunk-F3UDTTI7.js";import{b as Fr}from"./chunk-FPWHWWXO.js";import{b as zr}from"./chunk-23OI2XDJ.js";import{b as fr}from"./chunk-LJQIAFWS.js";import{b as nr}from"./chunk-MF3GVFLC.js";import"./chunk-B2DRBHGQ.js";import{b as R}from"./chunk-YJ5OCPSK.js";import{b as U}from"./chunk-Q2GOPGDA.js";import{b as V}from"./chunk-PXP4YYZA.js";import{b as W}from"./chunk-6ESRNSO7.js";import{c as X,d as Y}from"./chunk-YUZRUF5F.js";import{c as Z,d as _}from"./chunk-DJAX3ZRG.js";import{b as N}from"./chunk-PZQVSQX6.js";import{b as rr}from"./chunk-SDGPS6XI.js";import{b as G}from"./chunk-SC5TEGMM.js";import{b as H}from"./chunk-5SKEZPTU.js";import{b as J}from"./chunk-OYXHOZZ4.js";import{b as K}from"./chunk-M7SIPZZZ.js";import{b as L}from"./chunk-N26Y42L6.js";import{b as O}from"./chunk-4JF56A3P.js";import{b as P}from"./chunk-AGKL4LDL.js";import{b as Q}from"./chunk-B2GCIQI2.js";import{b as y}from"./chunk-FHMIEBRM.js";import{b as A}from"./chunk-7FGDUBSN.js";import{b as $}from"./chunk-GOWX7VPU.js";import{b as S}from"./chunk-B6WWC6K3.js";import{b as T}from"./chunk-MVBK66TR.js";import{b as B}from"./chunk-YIANER7Y.js";import{b as D}from"./chunk-HDWHYM2T.js";import{b as E}from"./chunk-Q3LE3Y66.js";import{b as w}from"./chunk-3FQBUEB6.js";import{b as x}from"./chunk-45DUHCXR.js";import{b as v}from"./chunk-HZGHQZSY.js";import"./chunk-BIJXTWZ4.js";import{d as k,e as q,f as C}from"./chunk-JELR4642.js";import"./chunk-QYZN33JA.js";import{b}from"./chunk-DZAFUADN.js";import"./chunk-47IFMQYS.js";import"./chunk-3MRB66F4.js";import"./chunk-R2J5MJOM.js";import{b as I}from"./chunk-7VWOECJ3.js";import{b as M}from"./chunk-472JZJ2D.js";import{b as j}from"./chunk-FONAGXRJ.js";import{b as t}from"./chunk-YOIFOOGX.js";import{b as l}from"./chunk-AI7JUA46.js";import{b as u}from"./chunk-GQKQEK5N.js";import{b as p}from"./chunk-YQEKKZTU.js";import{b as e}from"./chunk-67XYNGRV.js";import{b as d}from"./chunk-G4AUMZUY.js";import{b as c}from"./chunk-LE2XKKGQ.js";import{b as h}from"./chunk-VTAMGD42.js";import"./chunk-6KHZX4HU.js";import"./chunk-3PCPQIUD.js";import"./chunk-TW2IJRUF.js";import"./chunk-PPVF2N6C.js";import"./chunk-K27FY3ES.js";import"./chunk-MROECM42.js";import"./chunk-42AMF6EE.js";import"./chunk-GA5TPRMF.js";import{b as i}from"./chunk-CMTQFWZK.js";import{b as g}from"./chunk-NXUXZWS5.js";import"./chunk-2UV6ZFHK.js";import"./chunk-GR4ZHKXI.js";import"./chunk-HWI42GQO.js";import{b as m}from"./chunk-WAJVRK5B.js";import"./chunk-HW2VJKFH.js";import"./chunk-YERKK5B3.js";import{b as F}from"./chunk-CL7IYCGG.js";import"./chunk-I57EACSL.js";import"./chunk-7JZKVC3F.js";import{b as z}from"./chunk-OLEQNRKX.js";import{b as f}from"./chunk-ZMGLTHSU.js";import"./chunk-WEHA3JFD.js";import"./chunk-43E7AR6A.js";import"./chunk-FUT3X2GJ.js";import"./chunk-CPKBPQ2C.js";import"./chunk-PBOVSFTJ.js";import"./chunk-NE4R2FVV.js";import{b as n}from"./chunk-QL33F2W6.js";import"./chunk-I4IRHQDW.js";import"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";var Er=[i,g,m,F,z,f,n,t,l,u,p,e,d,c,h,w,x,v,k,q,C,b,I,M,j,y,A,$,S,T,B,D,E,G,H,J,K,L,O,P,Q,R,U,V,W,X,Y,Z,_,N,rr,or,ar,sr,ir,gr,mr,Fr,zr,fr,nr,tr,lr,ur,pr,er,dr,cr,hr,wr,xr,vr,kr,qr,Cr,br,Ir,Mr,jr,yr,Ar,$r,Sr];function Tr(){return Er}var Br=new Map;for(let r of Tr())Br.set(r.name,new Set(r.flags.map(o=>o.flag)));function Fa(r,o,Dr){let a=Br.get(o);if(!(!a||a.size===0))for(let s of Dr)a.has(s)&&r.hit(`cmd:flag:${o}:${s}`)}export{Fa as emitFlagCoverage};
3
+ import{b as yr}from"./chunk-RPUFEP5O.js";import{b as Ar}from"./chunk-V2XF3TTW.js";import{b as $r}from"./chunk-7PUOS2OO.js";import"./chunk-V4U26ZWL.js";import"./chunk-KP2UH5CJ.js";import{c as Sr}from"./chunk-YCOJCFGU.js";import"./chunk-3DWQCLNP.js";import{b as wr}from"./chunk-PQ2INDRF.js";import{b as xr}from"./chunk-DYIBFLS3.js";import{b as vr}from"./chunk-RVPTAYDS.js";import{b as kr}from"./chunk-TYBXHT6W.js";import{b as qr}from"./chunk-AJF3OBTR.js";import{b as Cr}from"./chunk-2ETT4ELS.js";import{b as br}from"./chunk-OUQKFRVR.js";import{d as Ir,e as Mr,f as jr}from"./chunk-HQ63MFHG.js";import"./chunk-QES5OSUC.js";import{b as tr}from"./chunk-6TUILMPB.js";import{b as lr}from"./chunk-CC2AQ6B7.js";import{b as ur}from"./chunk-QMPZXXEK.js";import{b as pr}from"./chunk-WFHYGSLJ.js";import{b as er}from"./chunk-LXFMIXGA.js";import{b as dr}from"./chunk-WFVCEB5T.js";import{b as cr}from"./chunk-KG2KXL4Y.js";import"./chunk-2YLY6FJA.js";import{b as hr}from"./chunk-OXLC2WWX.js";import{c as or,d as ar}from"./chunk-KI54R2QB.js";import{b as sr}from"./chunk-KUMHQGUR.js";import{c as ir,d as gr}from"./chunk-MYTNZ7MA.js";import{b as mr}from"./chunk-7PPAWLUI.js";import"./chunk-F3UDTTI7.js";import{b as Fr}from"./chunk-FPWHWWXO.js";import{b as zr}from"./chunk-23OI2XDJ.js";import{b as fr}from"./chunk-LJQIAFWS.js";import{b as nr}from"./chunk-L345YZ6R.js";import"./chunk-B2DRBHGQ.js";import{b as R}from"./chunk-YJ5OCPSK.js";import{b as U}from"./chunk-Q2GOPGDA.js";import{b as V}from"./chunk-PXP4YYZA.js";import{b as W}from"./chunk-6ESRNSO7.js";import{c as X,d as Y}from"./chunk-YUZRUF5F.js";import{c as Z,d as _}from"./chunk-DJAX3ZRG.js";import{b as N}from"./chunk-PZQVSQX6.js";import{b as rr}from"./chunk-SDGPS6XI.js";import{b as G}from"./chunk-SC5TEGMM.js";import{b as H}from"./chunk-5SKEZPTU.js";import{b as J}from"./chunk-OYXHOZZ4.js";import{b as K}from"./chunk-M7SIPZZZ.js";import{b as L}from"./chunk-N26Y42L6.js";import{b as O}from"./chunk-4JF56A3P.js";import{b as P}from"./chunk-AGKL4LDL.js";import{b as Q}from"./chunk-B2GCIQI2.js";import{b as y}from"./chunk-FHMIEBRM.js";import{b as A}from"./chunk-7FGDUBSN.js";import{b as $}from"./chunk-GOWX7VPU.js";import{b as S}from"./chunk-B6WWC6K3.js";import{b as T}from"./chunk-MVBK66TR.js";import{b as B}from"./chunk-YIANER7Y.js";import{b as D}from"./chunk-HDWHYM2T.js";import{b as E}from"./chunk-Q3LE3Y66.js";import{b as w}from"./chunk-3FQBUEB6.js";import{b as x}from"./chunk-45DUHCXR.js";import{b as v}from"./chunk-HZGHQZSY.js";import"./chunk-BIJXTWZ4.js";import{d as k,e as q,f as C}from"./chunk-JELR4642.js";import"./chunk-QYZN33JA.js";import{b}from"./chunk-DZAFUADN.js";import"./chunk-47IFMQYS.js";import"./chunk-3MRB66F4.js";import"./chunk-R2J5MJOM.js";import{b as I}from"./chunk-7VWOECJ3.js";import{b as M}from"./chunk-472JZJ2D.js";import{b as j}from"./chunk-FONAGXRJ.js";import{b as t}from"./chunk-SE7JHGP3.js";import{b as l}from"./chunk-AI7JUA46.js";import{b as u}from"./chunk-GQKQEK5N.js";import{b as p}from"./chunk-YQEKKZTU.js";import{b as e}from"./chunk-67XYNGRV.js";import{b as d}from"./chunk-G4AUMZUY.js";import{b as c}from"./chunk-LE2XKKGQ.js";import{b as h}from"./chunk-VTAMGD42.js";import"./chunk-6KHZX4HU.js";import"./chunk-3PCPQIUD.js";import"./chunk-TW2IJRUF.js";import"./chunk-QKJAAJ7J.js";import"./chunk-K27FY3ES.js";import"./chunk-MROECM42.js";import"./chunk-42AMF6EE.js";import"./chunk-GA5TPRMF.js";import{b as i}from"./chunk-CMTQFWZK.js";import{b as g}from"./chunk-NXUXZWS5.js";import"./chunk-2UV6ZFHK.js";import"./chunk-GR4ZHKXI.js";import"./chunk-HWI42GQO.js";import{b as m}from"./chunk-WAJVRK5B.js";import"./chunk-HW2VJKFH.js";import"./chunk-YERKK5B3.js";import{b as F}from"./chunk-CL7IYCGG.js";import"./chunk-I57EACSL.js";import"./chunk-7JZKVC3F.js";import{b as z}from"./chunk-OLEQNRKX.js";import{b as f}from"./chunk-ZMGLTHSU.js";import"./chunk-WEHA3JFD.js";import"./chunk-43E7AR6A.js";import"./chunk-FUT3X2GJ.js";import"./chunk-CPKBPQ2C.js";import"./chunk-PBOVSFTJ.js";import"./chunk-NE4R2FVV.js";import{b as n}from"./chunk-QL33F2W6.js";import"./chunk-I4IRHQDW.js";import"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";var Er=[i,g,m,F,z,f,n,t,l,u,p,e,d,c,h,w,x,v,k,q,C,b,I,M,j,y,A,$,S,T,B,D,E,G,H,J,K,L,O,P,Q,R,U,V,W,X,Y,Z,_,N,rr,or,ar,sr,ir,gr,mr,Fr,zr,fr,nr,tr,lr,ur,pr,er,dr,cr,hr,wr,xr,vr,kr,qr,Cr,br,Ir,Mr,jr,yr,Ar,$r,Sr];function Tr(){return Er}var Br=new Map;for(let r of Tr())Br.set(r.name,new Set(r.flags.map(o=>o.flag)));function Fa(r,o,Dr){let a=Br.get(o);if(!(!a||a.size===0))for(let s of Dr)a.has(s)&&r.hit(`cmd:flag:${o}:${s}`)}export{Fa as emitFlagCoverage};
@@ -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 A,b as B}from"./chunk-JQM3DKCH.js";import{a as F}from"./chunk-7WBCA2BB.js";import"./chunk-3MRB66F4.js";import"./chunk-O2BCKSMK.js";import"./chunk-TW2IJRUF.js";import{a as j,b as v}from"./chunk-PPVF2N6C.js";import{a as q}from"./chunk-MROECM42.js";import{b as C}from"./chunk-HWI42GQO.js";import{b as E}from"./chunk-CPKBPQ2C.js";import{a as W,b as h}from"./chunk-PBOVSFTJ.js";import{a as S}from"./chunk-I4IRHQDW.js";import{b as M}from"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";import{AsyncLocalStorage as H}from"node:async_hooks";import{fileURLToPath as I}from"node:url";import{Worker as L}from"node:worker_threads";var O=new H,P=`js-exec - Sandboxed JavaScript/TypeScript runtime with Node.js-compatible APIs
3
+ import{a as A,b as B}from"./chunk-JHEAT7AR.js";import{a as q}from"./chunk-3DWQCLNP.js";import"./chunk-3MRB66F4.js";import"./chunk-O2BCKSMK.js";import"./chunk-TW2IJRUF.js";import{b as v,c as j}from"./chunk-QKJAAJ7J.js";import{a as F}from"./chunk-MROECM42.js";import{b as C}from"./chunk-HWI42GQO.js";import{b as E}from"./chunk-CPKBPQ2C.js";import{a as W,b as h}from"./chunk-PBOVSFTJ.js";import{a as S}from"./chunk-I4IRHQDW.js";import{b as M}from"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";import{AsyncLocalStorage as H}from"node:async_hooks";import{fileURLToPath as J}from"node:url";import{Worker as L}from"node:worker_threads";var O=new H,P=`js-exec - Sandboxed JavaScript/TypeScript runtime with Node.js-compatible APIs
4
4
 
5
5
  Usage: js-exec [OPTIONS] [-c CODE | FILE] [ARGS...]
6
6
 
@@ -87,13 +87,13 @@ Limits:
87
87
  Engine: QuickJS (compiled to WebAssembly)
88
88
  `;function N(r){let e={code:null,scriptFile:null,showVersion:!1,scriptArgs:[],isModule:!1,stripTypes:!1};if(r.length===0)return e;for(let t=0;t<r.length;t++){let s=r[t];if(s==="-m"||s==="--module"){e.isModule=!0;continue}if(s==="--strip-types"){e.stripTypes=!0;continue}if(s==="-c")return t+1>=r.length?{stdout:"",stderr:`js-exec: option requires an argument -- 'c'
89
89
  `,exitCode:2}:(e.code=r[t+1],e.scriptArgs=r.slice(t+2),e);if(s==="--version"||s==="-V")return e.showVersion=!0,e;if(s.startsWith("-")&&s!=="-"&&s!=="--")return{stdout:"",stderr:`js-exec: unrecognized option '${s}'
90
- `,exitCode:2};if(s==="--")return t+1<r.length&&(e.scriptFile=r[t+1],e.scriptArgs=r.slice(t+2)),e;if(!s.startsWith("-"))return e.scriptFile=s,e.scriptArgs=r.slice(t+1),e}return e}var l=null,y=null,c=[],n=null,x=null,J=1e3;function R(r,e,t){r.controller.close();let s=!1,o=()=>{if(!s&&(s=!0,v(i),n===r)){x="worker termination was not acknowledged";for(let a of c)a.bridgeHandler.stop(),a.resolve({success:!1,error:x});c.length=0,r.resolve(t)}},u=()=>{s||(s=!0,v(i),n===r&&(r.resolve(t),n=null,g()))},i=j(()=>{o()},J);r.controller.terminate(e).then(a=>a?u():o(),o)}function de(){y&&(v(y),y=null),n?.bridgeHandler.stop(),n=null;for(let e of c)e.bridgeHandler.stop();c.length=0;let r=l;l=null,r&&r.terminate(),x=null}var U=I(new URL("./js-exec-worker.js",import.meta.url));function g(){if(n||c.length===0)return;let r=c.shift();if(!r)return;n=r;let e=null;try{e=$(),e.postMessage(r.input)}catch(t){r.bridgeHandler.stop();let s={success:!1,error:h(S(t))},o=e??l;l===o&&(l=null),o?R(r,o,s):(r.resolve(s),n===r&&(n=null),g())}}function D(r,e){if(!r||typeof r!="object")return{success:!1,error:"Malformed worker response"};let t=r;return typeof t.protocolToken!="string"||t.protocolToken!==e?{success:!1,error:"Malformed worker response: invalid protocol token"}:typeof t.success!="boolean"?{success:!1,error:"Malformed worker response: missing success flag"}:t.success?{success:!0}:{success:!1,type:t.type==="initialization-failure"?"initialization-failure":void 0,error:typeof t.error=="string"&&t.error.length>0?t.error:"Worker execution failed"}}function $(){if(y&&(v(y),y=null),l)return l;let r=C.runTrusted(()=>new L(U));return l=r,r.on("message",e=>{if(l===r){if(n){let t;try{n.controller.assertMessageSize(e,"response"),t=D(e,n.input.protocolToken)}catch(s){t={success:!1,error:h(S(s))}}if(t.type==="initialization-failure"){x=t.error??"Worker initialization failed",n.bridgeHandler.stop(),n.resolve(t),n=null;for(let s of c)s.bridgeHandler.stop(),s.resolve({success:!1,type:"initialization-failure",error:x});c.length=0,l=null,r.terminate();return}n.resolve(t),n=null}c.length>0?g():V()}}),r.on("error",e=>{if(l===r){if(n){let t=h(S(e));n.resolve({success:!1,error:t}),n=null}for(let t of c)t.resolve({success:!1,error:"Worker crashed"});c.length=0,l=null}}),r.on("exit",()=>{l===r&&(l=null,n&&(n.resolve({success:!1,error:"Worker exited unexpectedly"}),n=null),c.length>0&&g())}),r}function V(){y=j(()=>{l&&!n&&c.length===0&&(l.terminate(),l=null)},5e3)}async function Q(r,e,t,s=[],o,u,i){return O.getStore()?{stdout:"",stderr:`js-exec: recursive invocation is not supported
91
- `,exitCode:1}:X(r,e,t,s,o,u,i)}async function G(r,e,t,s){let o,u=new Promise(d=>{o=d}),i={input:r,bridgeHandler:e,resolve:()=>{},controller:s};s.assertMessageSize({...r,sharedBuffer:void 0},"request");let a=d=>{e.stop();let f={success:!1,error:d==="abort"?i.controller.abortMessage():i.controller.timeoutMessage()};if(n===i){let p=l;l=null,p?R(i,p,f):(i.resolve(f),n=null,g())}else{let p=c.indexOf(i);p!==-1&&c.splice(p,1),i.resolve(f),n||g()}};if(i.resolve=d=>{i.controller.close(),o(d)},i.controller.arm(a),!i.controller.isCanceled){c.push(i);try{g()}catch(d){let f=c.indexOf(i);throw f!==-1&&c.splice(f,1),i.controller.close(),d}}let[m,k]=await Promise.all([e.run(t),u.catch(d=>({success:!1,error:h(S(d))}))]);return{bridgeOutput:m,workerResult:k}}function K(r){return r.limits.maxJsTimeoutMs}async function X(r,e,t,s=[],o,u,i){if(x!==null)return{stdout:"",stderr:`js-exec: ${h(x)}
92
- `,exitCode:1};let a=A(),m=e.exec,k=m?(T,_)=>O.run(!0,()=>m(T,_)):void 0,d=new B(a,e.fs,e.cwd,"js-exec",e.fetch,e.limits.maxOutputSize,k,e.invokeTool),f=K(e),p=new F({commandName:"js-exec",timeoutMs:f,signal:e.signal,maxMessageBytes:e.limits.maxWorkerMessageBytes}),z={protocolToken:p.protocolToken,sharedBuffer:a,jsCode:r,cwd:e.cwd,env:q(e.env),args:s,scriptPath:t,bootstrapCode:o,isModule:u,stripTypes:i,timeoutMs:f,hasInvokeTool:e.invokeTool!==void 0},{bridgeOutput:b,workerResult:w}=await G(z,d,f,p);if(!w.success&&w.error){let T=w.error===p.timeoutMessage()||w.error===p.abortMessage();return{stdout:b.stdout,stderr:`${b.stderr}js-exec: ${h(w.error)}
93
- `,exitCode:b.exitCode||(T?124:1)}}return{...b}}var fe={name:"js-exec",async execute(r,e){if(M(r))return{stdout:P,stderr:"",exitCode:0};let t=N(r);if("exitCode"in t)return t;if(t.showVersion)return{stdout:`QuickJS (quickjs-emscripten)
90
+ `,exitCode:2};if(s==="--")return t+1<r.length&&(e.scriptFile=r[t+1],e.scriptArgs=r.slice(t+2)),e;if(!s.startsWith("-"))return e.scriptFile=s,e.scriptArgs=r.slice(t+1),e}return e}var l=null,y=null,c=[],n=null,x=null,U=1e3,R=5e3;function fe(r){R=r}function pe(){return l!==null}function _(r,e,t){r.controller.close();let s=!1,o=()=>{if(!s&&(s=!0,v(i),n===r)){x="worker termination was not acknowledged";for(let a of c)a.bridgeHandler.stop(),a.resolve({success:!1,error:x});c.length=0,r.resolve(t)}},u=()=>{s||(s=!0,v(i),n===r&&(r.resolve(t),n=null,g()))},i=j(()=>{o()},U);r.controller.terminate(e).then(a=>a?u():o(),o)}function me(){y&&(v(y),y=null),n?.bridgeHandler.stop(),n=null;for(let e of c)e.bridgeHandler.stop();c.length=0;let r=l;l=null,r&&r.terminate(),x=null}var D=J(new URL("./js-exec-worker.js",import.meta.url));function g(){if(n||c.length===0)return;let r=c.shift();if(!r)return;n=r;let e=null;try{e=V(),e.postMessage(r.input)}catch(t){r.bridgeHandler.stop();let s={success:!1,error:h(S(t))},o=e??l;l===o&&(l=null),o?_(r,o,s):(r.resolve(s),n===r&&(n=null),g())}}function $(r,e){if(!r||typeof r!="object")return{success:!1,error:"Malformed worker response"};let t=r;return typeof t.protocolToken!="string"||t.protocolToken!==e?{success:!1,error:"Malformed worker response: invalid protocol token"}:typeof t.success!="boolean"?{success:!1,error:"Malformed worker response: missing success flag"}:t.success?{success:!0}:{success:!1,type:t.type==="initialization-failure"?"initialization-failure":void 0,error:typeof t.error=="string"&&t.error.length>0?t.error:"Worker execution failed"}}function V(){if(y&&(v(y),y=null),l)return l;let r=C.runTrusted(()=>new L(D));return l=r,r.on("message",e=>{if(l===r){if(n){let t;try{n.controller.assertMessageSize(e,"response"),t=$(e,n.input.protocolToken)}catch(s){t={success:!1,error:h(S(s))}}if(t.type==="initialization-failure"){x=t.error??"Worker initialization failed",n.bridgeHandler.stop(),n.resolve(t),n=null;for(let s of c)s.bridgeHandler.stop(),s.resolve({success:!1,type:"initialization-failure",error:x});c.length=0,l=null,r.terminate();return}n.resolve(t),n=null}c.length>0?g():Q()}}),r.on("error",e=>{if(l===r){if(n){let t=h(S(e));n.resolve({success:!1,error:t}),n=null}for(let t of c)t.resolve({success:!1,error:"Worker crashed"});c.length=0,l=null}}),r.on("exit",()=>{l===r&&(l=null,n&&(n.resolve({success:!1,error:"Worker exited unexpectedly"}),n=null),c.length>0&&g())}),r}function Q(){y=j(()=>{l&&!n&&c.length===0&&(l.terminate(),l=null)},R)}async function G(r,e,t,s=[],o,u,i){return O.getStore()?{stdout:"",stderr:`js-exec: recursive invocation is not supported
91
+ `,exitCode:1}:Y(r,e,t,s,o,u,i)}async function K(r,e,t,s){let o,u=new Promise(d=>{o=d}),i={input:r,bridgeHandler:e,resolve:()=>{},controller:s};s.assertMessageSize({...r,sharedBuffer:void 0},"request");let a=d=>{e.stop();let f={success:!1,error:d==="abort"?i.controller.abortMessage():i.controller.timeoutMessage()};if(n===i){let p=l;l=null,p?_(i,p,f):(i.resolve(f),n=null,g())}else{let p=c.indexOf(i);p!==-1&&c.splice(p,1),i.resolve(f),n||g()}};if(i.resolve=d=>{i.controller.close(),o(d)},i.controller.arm(a),!i.controller.isCanceled){c.push(i);try{g()}catch(d){let f=c.indexOf(i);throw f!==-1&&c.splice(f,1),i.controller.close(),d}}let[m,k]=await Promise.all([e.run(t),u.catch(d=>({success:!1,error:h(S(d))}))]);return{bridgeOutput:m,workerResult:k}}function X(r){return r.limits.maxJsTimeoutMs}async function Y(r,e,t,s=[],o,u,i){if(x!==null)return{stdout:"",stderr:`js-exec: ${h(x)}
92
+ `,exitCode:1};let a=A(),m=e.exec,k=m?(b,I)=>O.run(!0,()=>m(b,I)):void 0,d=new B(a,e.fs,e.cwd,"js-exec",e.fetch,e.limits.maxOutputSize,k,e.invokeTool),f=X(e),p=new q({commandName:"js-exec",timeoutMs:f,signal:e.signal,maxMessageBytes:e.limits.maxWorkerMessageBytes}),z={protocolToken:p.protocolToken,sharedBuffer:a,jsCode:r,cwd:e.cwd,env:F(e.env),args:s,scriptPath:t,bootstrapCode:o,isModule:u,stripTypes:i,timeoutMs:f,hasInvokeTool:e.invokeTool!==void 0},{bridgeOutput:T,workerResult:w}=await K(z,d,f,p);if(!w.success&&w.error){let b=w.error===p.timeoutMessage()||w.error===p.abortMessage();return{stdout:T.stdout,stderr:`${T.stderr}js-exec: ${h(w.error)}
93
+ `,exitCode:T.exitCode||(b?124:1)}}return{...T}}var he={name:"js-exec",async execute(r,e){if(M(r))return{stdout:P,stderr:"",exitCode:0};let t=N(r);if("exitCode"in t)return t;if(t.showVersion)return{stdout:`QuickJS (quickjs-emscripten)
94
94
  `,stderr:"",exitCode:0};let s,o;if(t.code!==null)s=t.code,o="-c";else if(t.scriptFile!==null){let m=e.fs.resolvePath(e.cwd,t.scriptFile);if(!await e.fs.exists(m))return{stdout:"",stderr:`js-exec: can't open file '${t.scriptFile}': No such file or directory
95
95
  `,exitCode:2};try{s=await e.fs.readFile(m),o=m}catch(k){return{stdout:"",stderr:`js-exec: can't open file '${t.scriptFile}': ${W(k.message)}
96
96
  `,exitCode:2}}}else if(E(e.stdin).trim())s=E(e.stdin),o="<stdin>";else return{stdout:"",stderr:`js-exec: no input provided (use -c CODE or provide a script file)
97
- `,exitCode:2};let u=t.isModule,i=t.stripTypes;o&&o!=="-c"&&o!=="<stdin>"&&((o.endsWith(".mjs")||o.endsWith(".mts")||o.endsWith(".ts"))&&(u=!0),(o.endsWith(".ts")||o.endsWith(".mts"))&&(i=!0)),!u&&/\bawait\s+[\w([`]/.test(s)&&(u=!0);let a=e.jsBootstrapCode;return Q(s,e,o,t.scriptArgs,a,u,i)}},pe={name:"node",async execute(){return{stdout:"",stderr:`node: this sandbox uses js-exec instead of node
97
+ `,exitCode:2};let u=t.isModule,i=t.stripTypes;o&&o!=="-c"&&o!=="<stdin>"&&((o.endsWith(".mjs")||o.endsWith(".mts")||o.endsWith(".ts"))&&(u=!0),(o.endsWith(".ts")||o.endsWith(".mts"))&&(i=!0)),!u&&/\bawait\s+[\w([`]/.test(s)&&(u=!0);let a=e.jsBootstrapCode;return G(s,e,o,t.scriptArgs,a,u,i)}},ye={name:"node",async execute(){return{stdout:"",stderr:`node: this sandbox uses js-exec instead of node
98
98
 
99
- ${P}`,exitCode:1}}};export{de as _resetJsExecWorkerForTests,fe as jsExecCommand,pe as nodeStubCommand};
99
+ ${P}`,exitCode:1}}};export{pe as _hasSharedJsExecWorkerForTests,me as _resetJsExecWorkerForTests,fe as _setJsExecWorkerIdleTimeoutMsForTests,he as jsExecCommand,ye as nodeStubCommand};
@@ -1652,6 +1652,16 @@ var OpCode = {
1652
1652
  REALPATH: 13,
1653
1653
  RENAME: 14,
1654
1654
  COPY_FILE: 15,
1655
+ // Ranged variant for write payloads larger than the data buffer.
1656
+ // FLAGS carries the file offset (uint32); the chunk length is its
1657
+ // DATA_LENGTH. (Reads use plain READ_FILE plus the generic
1658
+ // READ_RESULT_RANGE assembly; only the write direction needs this.)
1659
+ WRITE_FILE_RANGE: 17,
1660
+ // Fetch the next slice of an oversized result (any op). The host
1661
+ // publishes the first DATA_BUFFER bytes with the FULL length in
1662
+ // RESULT_LENGTH and retains the complete buffer; the worker loops
1663
+ // this op (FLAGS = offset, MODE = length) to assemble the rest.
1664
+ READ_RESULT_RANGE: 18,
1655
1665
  // Special operations for I/O
1656
1666
  WRITE_STDOUT: 100,
1657
1667
  WRITE_STDERR: 101,
@@ -1680,7 +1690,8 @@ var ErrorCode = {
1680
1690
  IO_ERROR: 7,
1681
1691
  TIMEOUT: 8,
1682
1692
  NETWORK_ERROR: 9,
1683
- NETWORK_NOT_CONFIGURED: 10
1693
+ NETWORK_NOT_CONFIGURED: 10,
1694
+ NOT_EMPTY: 11
1684
1695
  };
1685
1696
  var Offset = {
1686
1697
  OP_CODE: 0,
@@ -1698,9 +1709,10 @@ var Offset = {
1698
1709
  var Size = {
1699
1710
  CONTROL_REGION: 32,
1700
1711
  PATH_BUFFER: 4096,
1701
- // 8MB limit for FS read/write, HTTP responses, and tool invocation results.
1702
- // Sized to handle typical OpenAPI/GraphQL responses (paginated lists, batch queries).
1703
- // Still well under the 64MB QuickJS memory limit per execution.
1712
+ // 8MB transfer CHUNK size — not a semantic cap. Results larger than
1713
+ // this are assembled transparently (READ_RESULT_RANGE), and large
1714
+ // writes stream as WRITE_FILE_RANGE chunks. Sized to keep ordinary
1715
+ // ops single-transfer while bounding per-transfer copies.
1704
1716
  DATA_BUFFER: 8388608,
1705
1717
  TOTAL: 8392736
1706
1718
  // 32 + 4096 + 8MB
@@ -1832,6 +1844,20 @@ var ProtocolBuffer = class {
1832
1844
  this.uint8View.set(data, Offset.DATA_BUFFER);
1833
1845
  this.setResultLength(data.length);
1834
1846
  }
1847
+ /**
1848
+ * Publish a result of ANY size: the first DATA_BUFFER bytes land in
1849
+ * the data region and RESULT_LENGTH carries the FULL length. The
1850
+ * worker detects the overflow and fetches the rest with
1851
+ * READ_RESULT_RANGE ops (served from the host's retained buffer).
1852
+ */
1853
+ setResultPrefix(data) {
1854
+ if (data.length > 2147483647) {
1855
+ throw new Error(`Result too large: ${data.length} exceeds int32`);
1856
+ }
1857
+ const n = Math.min(data.length, Size.DATA_BUFFER);
1858
+ this.uint8View.set(data.subarray(0, n), Offset.DATA_BUFFER);
1859
+ this.setResultLength(data.length);
1860
+ }
1835
1861
  getResultAsString() {
1836
1862
  const result = this.getResult();
1837
1863
  return new TextDecoder().decode(result);
@@ -1961,50 +1987,113 @@ var SyncBackend = class {
1961
1987
  }
1962
1988
  this.protocol.setStatus(Status.READY);
1963
1989
  this.protocol.notify();
1964
- const waitResult = this.protocol.waitForResult(this.operationTimeoutMs);
1990
+ const deadline = Date.now() + this.operationTimeoutMs;
1991
+ let waitResult = this.protocol.waitForResult(this.operationTimeoutMs);
1992
+ while (waitResult !== "timed-out" && this.protocol.getStatus() === Status.READY) {
1993
+ const remaining = deadline - Date.now();
1994
+ if (remaining <= 0) {
1995
+ waitResult = "timed-out";
1996
+ break;
1997
+ }
1998
+ waitResult = this.protocol.waitForResult(remaining);
1999
+ }
1965
2000
  if (waitResult === "timed-out") {
1966
2001
  return { success: false, error: "Operation timed out" };
1967
2002
  }
1968
2003
  const status = this.protocol.getStatus();
1969
2004
  if (status === Status.SUCCESS) {
1970
- return { success: true, result: this.protocol.getResult() };
2005
+ const totalLength = this.protocol.getResultLength();
2006
+ if (totalLength <= Size.DATA_BUFFER) {
2007
+ return { success: true, result: this.protocol.getResult() };
2008
+ }
2009
+ const content = new Uint8Array(totalLength);
2010
+ content.set(this.protocol.getResult().subarray(0, Size.DATA_BUFFER), 0);
2011
+ let offset = Size.DATA_BUFFER;
2012
+ while (offset < totalLength) {
2013
+ const length = Math.min(Size.DATA_BUFFER, totalLength - offset);
2014
+ const slice = this.execSync(
2015
+ OpCode.READ_RESULT_RANGE,
2016
+ "",
2017
+ void 0,
2018
+ offset,
2019
+ length
2020
+ );
2021
+ if (!slice.success) {
2022
+ throw this.opError_("Failed to read result range", slice);
2023
+ }
2024
+ const chunk = slice.result ?? new Uint8Array(0);
2025
+ content.set(chunk, offset);
2026
+ offset += chunk.length;
2027
+ if (chunk.length === 0) {
2028
+ throw this.opError_("bridge returned an empty result slice", slice);
2029
+ }
2030
+ }
2031
+ return { success: true, result: content };
1971
2032
  }
1972
2033
  return {
1973
2034
  success: false,
1974
- error: this.protocol.getResultAsString() || `Error code: ${this.protocol.getErrorCode()}`
2035
+ error: this.protocol.getResultAsString() || // Impossible by construction: every host error path publishes a
2036
+ // code and message. If this ever fires, the diagnostic payload
2037
+ // must identify the exact protocol state.
2038
+ `bridge protocol violation: op ${opCode} woke with status ${status} (wait=${waitResult}, errorCode=${this.protocol.getErrorCode()})`,
2039
+ errorCode: this.protocol.getErrorCode()
1975
2040
  };
1976
2041
  }
2042
+ /** Build an op failure that preserves the bridge's numeric error code,
2043
+ * so downstream errno mapping prefers it over substring matching. */
2044
+ opError_(fallback, result) {
2045
+ const err = new Error(result.error || fallback);
2046
+ err.bridgeErrorCode = result.errorCode;
2047
+ return err;
2048
+ }
1977
2049
  readFile(path) {
1978
2050
  const result = this.execSync(OpCode.READ_FILE, path);
1979
2051
  if (!result.success) {
1980
- throw new Error(result.error || "Failed to read file");
2052
+ throw this.opError_("Failed to read file", result);
1981
2053
  }
1982
2054
  return result.result ?? new Uint8Array(0);
1983
2055
  }
1984
2056
  writeFile(path, data) {
1985
- const result = this.execSync(OpCode.WRITE_FILE, path, data);
1986
- if (!result.success) {
1987
- throw new Error(result.error || "Failed to write file");
2057
+ if (data.length <= Size.DATA_BUFFER) {
2058
+ const result = this.execSync(OpCode.WRITE_FILE, path, data);
2059
+ if (!result.success) {
2060
+ throw this.opError_("Failed to write file", result);
2061
+ }
2062
+ return;
2063
+ }
2064
+ let offset = 0;
2065
+ while (offset < data.length) {
2066
+ const chunk = data.subarray(offset, offset + Size.DATA_BUFFER);
2067
+ const result = this.execSync(
2068
+ OpCode.WRITE_FILE_RANGE,
2069
+ path,
2070
+ chunk,
2071
+ offset
2072
+ );
2073
+ if (!result.success) {
2074
+ throw this.opError_("Failed to write file", result);
2075
+ }
2076
+ offset += chunk.length;
1988
2077
  }
1989
2078
  }
1990
2079
  stat(path) {
1991
2080
  const result = this.execSync(OpCode.STAT, path);
1992
2081
  if (!result.success) {
1993
- throw new Error(result.error || "Failed to stat");
2082
+ throw this.opError_("Failed to stat", result);
1994
2083
  }
1995
2084
  return this.protocol.decodeStat();
1996
2085
  }
1997
2086
  lstat(path) {
1998
2087
  const result = this.execSync(OpCode.LSTAT, path);
1999
2088
  if (!result.success) {
2000
- throw new Error(result.error || "Failed to lstat");
2089
+ throw this.opError_("Failed to lstat", result);
2001
2090
  }
2002
2091
  return this.protocol.decodeStat();
2003
2092
  }
2004
2093
  readdir(path) {
2005
2094
  const result = this.execSync(OpCode.READDIR, path);
2006
2095
  if (!result.success) {
2007
- throw new Error(result.error || "Failed to readdir");
2096
+ throw this.opError_("Failed to readdir", result);
2008
2097
  }
2009
2098
  return JSON.parse(this.protocol.getResultAsString());
2010
2099
  }
@@ -2012,7 +2101,7 @@ var SyncBackend = class {
2012
2101
  const flags = recursive ? Flags.MKDIR_RECURSIVE : 0;
2013
2102
  const result = this.execSync(OpCode.MKDIR, path, void 0, flags);
2014
2103
  if (!result.success) {
2015
- throw new Error(result.error || "Failed to mkdir");
2104
+ throw this.opError_("Failed to mkdir", result);
2016
2105
  }
2017
2106
  }
2018
2107
  rm(path, recursive = false, force = false) {
@@ -2021,7 +2110,7 @@ var SyncBackend = class {
2021
2110
  if (force) flags |= Flags.FORCE;
2022
2111
  const result = this.execSync(OpCode.RM, path, void 0, flags);
2023
2112
  if (!result.success) {
2024
- throw new Error(result.error || "Failed to rm");
2113
+ throw this.opError_("Failed to rm", result);
2025
2114
  }
2026
2115
  }
2027
2116
  exists(path) {
@@ -2034,33 +2123,33 @@ var SyncBackend = class {
2034
2123
  appendFile(path, data) {
2035
2124
  const result = this.execSync(OpCode.APPEND_FILE, path, data);
2036
2125
  if (!result.success) {
2037
- throw new Error(result.error || "Failed to append file");
2126
+ throw this.opError_("Failed to append file", result);
2038
2127
  }
2039
2128
  }
2040
2129
  symlink(target, linkPath) {
2041
2130
  const targetData = new TextEncoder().encode(target);
2042
2131
  const result = this.execSync(OpCode.SYMLINK, linkPath, targetData);
2043
2132
  if (!result.success) {
2044
- throw new Error(result.error || "Failed to symlink");
2133
+ throw this.opError_("Failed to symlink", result);
2045
2134
  }
2046
2135
  }
2047
2136
  readlink(path) {
2048
2137
  const result = this.execSync(OpCode.READLINK, path);
2049
2138
  if (!result.success) {
2050
- throw new Error(result.error || "Failed to readlink");
2139
+ throw this.opError_("Failed to readlink", result);
2051
2140
  }
2052
2141
  return this.protocol.getResultAsString();
2053
2142
  }
2054
2143
  chmod(path, mode) {
2055
2144
  const result = this.execSync(OpCode.CHMOD, path, void 0, 0, mode);
2056
2145
  if (!result.success) {
2057
- throw new Error(result.error || "Failed to chmod");
2146
+ throw this.opError_("Failed to chmod", result);
2058
2147
  }
2059
2148
  }
2060
2149
  realpath(path) {
2061
2150
  const result = this.execSync(OpCode.REALPATH, path);
2062
2151
  if (!result.success) {
2063
- throw new Error(result.error || "Failed to realpath");
2152
+ throw this.opError_("Failed to realpath", result);
2064
2153
  }
2065
2154
  return this.protocol.getResultAsString();
2066
2155
  }
@@ -2068,28 +2157,28 @@ var SyncBackend = class {
2068
2157
  const newPathData = new TextEncoder().encode(newPath);
2069
2158
  const result = this.execSync(OpCode.RENAME, oldPath, newPathData);
2070
2159
  if (!result.success) {
2071
- throw new Error(result.error || "Failed to rename");
2160
+ throw this.opError_("Failed to rename", result);
2072
2161
  }
2073
2162
  }
2074
2163
  copyFile(src, dest) {
2075
2164
  const destData = new TextEncoder().encode(dest);
2076
2165
  const result = this.execSync(OpCode.COPY_FILE, src, destData);
2077
2166
  if (!result.success) {
2078
- throw new Error(result.error || "Failed to copyFile");
2167
+ throw this.opError_("Failed to copyFile", result);
2079
2168
  }
2080
2169
  }
2081
2170
  writeStdout(data) {
2082
2171
  const encoded = new TextEncoder().encode(data);
2083
2172
  const result = this.execSync(OpCode.WRITE_STDOUT, "", encoded);
2084
2173
  if (!result.success) {
2085
- throw new Error(result.error || "Failed to write stdout");
2174
+ throw this.opError_("Failed to write stdout", result);
2086
2175
  }
2087
2176
  }
2088
2177
  writeStderr(data) {
2089
2178
  const encoded = new TextEncoder().encode(data);
2090
2179
  const result = this.execSync(OpCode.WRITE_STDERR, "", encoded);
2091
2180
  if (!result.success) {
2092
- throw new Error(result.error || "Failed to write stderr");
2181
+ throw this.opError_("Failed to write stderr", result);
2093
2182
  }
2094
2183
  }
2095
2184
  exit(code) {
@@ -2103,7 +2192,7 @@ var SyncBackend = class {
2103
2192
  const requestData = options ? new TextEncoder().encode(JSON.stringify(options)) : void 0;
2104
2193
  const result = this.execSync(OpCode.HTTP_REQUEST, url, requestData);
2105
2194
  if (!result.success) {
2106
- throw new Error(result.error || "HTTP request failed");
2195
+ throw this.opError_("HTTP request failed", result);
2107
2196
  }
2108
2197
  const responseJson = new TextDecoder().decode(result.result);
2109
2198
  const parsed = JSON.parse(responseJson);
@@ -2126,7 +2215,7 @@ var SyncBackend = class {
2126
2215
  const requestData = stdin ? new TextEncoder().encode(JSON.stringify({ stdin })) : void 0;
2127
2216
  const result = this.execSync(OpCode.EXEC_COMMAND, command, requestData);
2128
2217
  if (!result.success) {
2129
- throw new Error(result.error || "Command execution failed");
2218
+ throw this.opError_("Command execution failed", result);
2130
2219
  }
2131
2220
  const responseJson = new TextDecoder().decode(result.result);
2132
2221
  return JSON.parse(responseJson);
@@ -2139,7 +2228,7 @@ var SyncBackend = class {
2139
2228
  const requestData = new TextEncoder().encode(JSON.stringify({ args }));
2140
2229
  const result = this.execSync(OpCode.EXEC_COMMAND, command, requestData);
2141
2230
  if (!result.success) {
2142
- throw new Error(result.error || "Command execution failed");
2231
+ throw this.opError_("Command execution failed", result);
2143
2232
  }
2144
2233
  const responseJson = new TextDecoder().decode(result.result);
2145
2234
  return JSON.parse(responseJson);
@@ -2152,7 +2241,7 @@ var SyncBackend = class {
2152
2241
  const requestData = argsJson ? new TextEncoder().encode(argsJson) : void 0;
2153
2242
  const result = this.execSync(OpCode.INVOKE_TOOL, path, requestData);
2154
2243
  if (!result.success) {
2155
- throw new Error(result.error || "Tool invocation failed");
2244
+ throw this.opError_("Tool invocation failed", result);
2156
2245
  }
2157
2246
  return new TextDecoder().decode(result.result);
2158
2247
  }
@@ -3888,13 +3977,47 @@ function setupContext(context, backend, input, processExitMarker) {
3888
3977
  );
3889
3978
  context.setProp(fsObj, "readFileBuffer", readFileBufferFn);
3890
3979
  readFileBufferFn.dispose();
3980
+ const marshalWriteData = (dataHandle) => {
3981
+ if (context.typeof(dataHandle) === "string") {
3982
+ return new TextEncoder().encode(context.getString(dataHandle));
3983
+ }
3984
+ if (context.typeof(dataHandle) === "object") {
3985
+ const bufferHandle = context.getProp(dataHandle, "buffer");
3986
+ if (bufferHandle && context.typeof(bufferHandle) === "object") {
3987
+ const offsetHandle = context.getProp(dataHandle, "byteOffset");
3988
+ const lengthHandle = context.getProp(dataHandle, "byteLength");
3989
+ try {
3990
+ const raw = context.getArrayBuffer(bufferHandle).value;
3991
+ const view = raw instanceof Uint8Array ? raw : new Uint8Array(raw);
3992
+ const offset = offsetHandle && context.typeof(offsetHandle) === "number" ? context.getNumber(offsetHandle) : 0;
3993
+ const length = lengthHandle && context.typeof(lengthHandle) === "number" ? context.getNumber(lengthHandle) : view.byteLength - offset;
3994
+ if (offset < 0 || length < 0 || offset + length > view.byteLength) {
3995
+ throw new TypeError("writeFile data has an invalid byte window");
3996
+ }
3997
+ return view.slice(offset, offset + length);
3998
+ } finally {
3999
+ bufferHandle.dispose();
4000
+ offsetHandle?.dispose();
4001
+ lengthHandle?.dispose();
4002
+ }
4003
+ }
4004
+ bufferHandle?.dispose();
4005
+ try {
4006
+ const raw = context.getArrayBuffer(dataHandle).value;
4007
+ return raw instanceof Uint8Array ? raw : new Uint8Array(raw);
4008
+ } catch {
4009
+ }
4010
+ }
4011
+ throw new TypeError(
4012
+ "writeFile data must be a string, Buffer, TypedArray, or DataView"
4013
+ );
4014
+ };
3891
4015
  const writeFileFn = context.newFunction(
3892
4016
  "writeFile",
3893
4017
  (pathHandle, dataHandle) => {
3894
4018
  const path = context.getString(pathHandle);
3895
- const data = context.getString(dataHandle);
3896
4019
  try {
3897
- backend.writeFile(path, new TextEncoder().encode(data));
4020
+ backend.writeFile(path, marshalWriteData(dataHandle));
3898
4021
  return context.undefined;
3899
4022
  } catch (e) {
3900
4023
  return throwError(context, e.message || "writeFile failed");
@@ -3992,9 +4115,8 @@ function setupContext(context, backend, input, processExitMarker) {
3992
4115
  "appendFile",
3993
4116
  (pathHandle, dataHandle) => {
3994
4117
  const path = context.getString(pathHandle);
3995
- const data = context.getString(dataHandle);
3996
4118
  try {
3997
- backend.appendFile(path, new TextEncoder().encode(data));
4119
+ backend.appendFile(path, marshalWriteData(dataHandle));
3998
4120
  return context.undefined;
3999
4121
  } catch (e) {
4000
4122
  return throwError(context, e.message || "appendFile failed");