@jerryan/just-bash 3.6.0 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/CHANGELOG.md +349 -316
  2. package/LICENSE +201 -201
  3. package/README.md +827 -827
  4. package/dist/agent-sandbox.d.ts +5 -0
  5. package/dist/bin/chunks/chmod-G2BCCQGF.js +3 -0
  6. package/dist/bin/chunks/{chunk-B2GCIQI2.js → chunk-2UKTHDUM.js} +1 -1
  7. package/dist/bin/{shell/chunks/chunk-7WBCA2BB.js → chunks/chunk-3DWQCLNP.js} +1 -1
  8. package/dist/bin/chunks/chunk-66UHJFN6.js +11 -0
  9. package/dist/bin/{shell/chunks/chunk-67XYNGRV.js → chunks/chunk-6O4Z6BQT.js} +1 -1
  10. package/dist/bin/chunks/{chunk-QFTZKD5O.js → chunk-6TUILMPB.js} +1 -1
  11. package/dist/bin/chunks/{chunk-M7SIPZZZ.js → chunk-7KMOGI3N.js} +1 -1
  12. package/dist/bin/{shell/chunks/chunk-6ESRNSO7.js → chunks/chunk-ADI36B7X.js} +1 -1
  13. package/dist/bin/chunks/chunk-CN4JKMTR.js +8 -0
  14. package/dist/bin/{shell/chunks/chunk-DZAFUADN.js → chunks/chunk-E26NQEH2.js} +1 -1
  15. package/dist/bin/chunks/chunk-E54Z6VIE.js +12 -0
  16. package/dist/bin/chunks/chunk-F2PYTUMR.js +9 -0
  17. package/dist/bin/chunks/chunk-FO7XJH3J.js +13 -0
  18. package/dist/bin/chunks/chunk-HWK7KFGB.js +3 -0
  19. package/dist/bin/{shell/chunks/chunk-LE2XKKGQ.js → chunks/chunk-HYLF56CC.js} +1 -1
  20. package/dist/bin/chunks/chunk-KNTDFP7X.js +12 -0
  21. package/dist/bin/{shell/chunks/chunk-MF3GVFLC.js → chunks/chunk-L345YZ6R.js} +1 -1
  22. package/dist/bin/chunks/chunk-NBTZL3VS.js +3 -0
  23. package/dist/bin/chunks/chunk-OHFB3M3X.js +3 -0
  24. package/dist/bin/{shell/chunks/chunk-HQ63MFHG.js → chunks/chunk-PEUGMGJJ.js} +1 -1
  25. package/dist/bin/chunks/chunk-QKJAAJ7J.js +3 -0
  26. package/dist/bin/{shell/chunks/chunk-JELR4642.js → chunks/chunk-R76AK3KD.js} +12 -12
  27. package/dist/bin/chunks/{chunk-NLU5LALY.js → chunk-RRECHBUS.js} +1 -1
  28. package/dist/bin/chunks/{chunk-ZMGLTHSU.js → chunk-THFQI5LV.js} +1 -1
  29. package/dist/bin/chunks/{chunk-CL7IYCGG.js → chunk-U7YR5CDD.js} +1 -1
  30. package/dist/bin/chunks/cp-TMDR6USI.js +3 -0
  31. package/dist/bin/chunks/du-UKFUX7KM.js +3 -0
  32. package/dist/bin/chunks/find-W2RZWTOF.js +3 -0
  33. package/dist/bin/chunks/{flag-coverage-C7PB2MO7.js → flag-coverage-QJ5ZQKCF.js} +1 -1
  34. package/dist/bin/{shell/chunks/grep-CVU5V66H.js → chunks/grep-IHDO3L72.js} +1 -1
  35. package/dist/bin/chunks/gzip-WUK63QLL.js +3 -0
  36. package/dist/bin/{shell/chunks/js-exec-DJQLXWCS.js → chunks/js-exec-BE37X4L2.js} +7 -7
  37. package/dist/bin/chunks/js-exec-worker.js +296 -116
  38. package/dist/bin/chunks/ln-XVC53673.js +3 -0
  39. package/dist/bin/chunks/ls-EROTXGTC.js +3 -0
  40. package/dist/bin/chunks/mkdir-YJ3SOVRP.js +3 -0
  41. package/dist/bin/chunks/mv-HDNKXPO6.js +3 -0
  42. package/dist/bin/{shell/chunks/python3-JCJHSX4Z.js → chunks/python3-TJ6DCPIA.js} +1 -1
  43. package/dist/bin/chunks/readlink-ZUIECKQC.js +3 -0
  44. package/dist/bin/chunks/rg-ODJAYIKX.js +3 -0
  45. package/dist/bin/chunks/rm-B4LVIG7A.js +3 -0
  46. package/dist/bin/chunks/rmdir-W5NBOJ7E.js +3 -0
  47. package/dist/bin/{shell/chunks/sleep-DVFE2GSF.js → chunks/sleep-MOJQBZMY.js} +1 -1
  48. package/dist/bin/chunks/split-TVJYLTIJ.js +3 -0
  49. package/dist/bin/chunks/sqlite3-5BGAK7VX.js +3 -0
  50. package/dist/bin/chunks/{timeout-YGFHQJKX.js → timeout-RQOWSWYG.js} +1 -1
  51. package/dist/bin/chunks/worker.js +233 -108
  52. package/dist/bin/just-bash.js +381 -376
  53. package/dist/bin/shell/chunks/chmod-G2BCCQGF.js +3 -0
  54. package/dist/bin/shell/chunks/{chunk-B2GCIQI2.js → chunk-2UKTHDUM.js} +1 -1
  55. package/dist/bin/{chunks/chunk-7WBCA2BB.js → shell/chunks/chunk-3DWQCLNP.js} +1 -1
  56. package/dist/bin/shell/chunks/chunk-66UHJFN6.js +11 -0
  57. package/dist/bin/{chunks/chunk-67XYNGRV.js → shell/chunks/chunk-6O4Z6BQT.js} +1 -1
  58. package/dist/bin/shell/chunks/{chunk-QFTZKD5O.js → chunk-6TUILMPB.js} +1 -1
  59. package/dist/bin/shell/chunks/{chunk-M7SIPZZZ.js → chunk-7KMOGI3N.js} +1 -1
  60. package/dist/bin/{chunks/chunk-6ESRNSO7.js → shell/chunks/chunk-ADI36B7X.js} +1 -1
  61. package/dist/bin/shell/chunks/chunk-CN4JKMTR.js +8 -0
  62. package/dist/bin/{chunks/chunk-DZAFUADN.js → shell/chunks/chunk-E26NQEH2.js} +1 -1
  63. package/dist/bin/shell/chunks/chunk-E54Z6VIE.js +12 -0
  64. package/dist/bin/shell/chunks/chunk-F2PYTUMR.js +9 -0
  65. package/dist/bin/shell/chunks/chunk-FO7XJH3J.js +13 -0
  66. package/dist/bin/shell/chunks/chunk-HWK7KFGB.js +3 -0
  67. package/dist/bin/{chunks/chunk-LE2XKKGQ.js → shell/chunks/chunk-HYLF56CC.js} +1 -1
  68. package/dist/bin/shell/chunks/chunk-KNTDFP7X.js +12 -0
  69. package/dist/bin/{chunks/chunk-MF3GVFLC.js → shell/chunks/chunk-L345YZ6R.js} +1 -1
  70. package/dist/bin/shell/chunks/chunk-NBTZL3VS.js +3 -0
  71. package/dist/bin/shell/chunks/chunk-OHFB3M3X.js +3 -0
  72. package/dist/bin/{chunks/chunk-HQ63MFHG.js → shell/chunks/chunk-PEUGMGJJ.js} +1 -1
  73. package/dist/bin/shell/chunks/chunk-QKJAAJ7J.js +3 -0
  74. package/dist/bin/{chunks/chunk-JELR4642.js → shell/chunks/chunk-R76AK3KD.js} +12 -12
  75. package/dist/bin/shell/chunks/{chunk-NLU5LALY.js → chunk-RRECHBUS.js} +1 -1
  76. package/dist/bin/shell/chunks/{chunk-ZMGLTHSU.js → chunk-THFQI5LV.js} +1 -1
  77. package/dist/bin/shell/chunks/{chunk-CL7IYCGG.js → chunk-U7YR5CDD.js} +1 -1
  78. package/dist/bin/shell/chunks/cp-TMDR6USI.js +3 -0
  79. package/dist/bin/shell/chunks/du-UKFUX7KM.js +3 -0
  80. package/dist/bin/shell/chunks/find-W2RZWTOF.js +3 -0
  81. package/dist/bin/shell/chunks/{flag-coverage-C7PB2MO7.js → flag-coverage-QJ5ZQKCF.js} +1 -1
  82. package/dist/bin/{chunks/grep-CVU5V66H.js → shell/chunks/grep-IHDO3L72.js} +1 -1
  83. package/dist/bin/shell/chunks/gzip-WUK63QLL.js +3 -0
  84. package/dist/bin/{chunks/js-exec-DJQLXWCS.js → shell/chunks/js-exec-BE37X4L2.js} +7 -7
  85. package/dist/bin/shell/chunks/ln-XVC53673.js +3 -0
  86. package/dist/bin/shell/chunks/ls-EROTXGTC.js +3 -0
  87. package/dist/bin/shell/chunks/mkdir-YJ3SOVRP.js +3 -0
  88. package/dist/bin/shell/chunks/mv-HDNKXPO6.js +3 -0
  89. package/dist/bin/{chunks/python3-JCJHSX4Z.js → shell/chunks/python3-TJ6DCPIA.js} +1 -1
  90. package/dist/bin/shell/chunks/readlink-ZUIECKQC.js +3 -0
  91. package/dist/bin/shell/chunks/rg-ODJAYIKX.js +3 -0
  92. package/dist/bin/shell/chunks/rm-B4LVIG7A.js +3 -0
  93. package/dist/bin/shell/chunks/rmdir-W5NBOJ7E.js +3 -0
  94. package/dist/bin/{chunks/sleep-DVFE2GSF.js → shell/chunks/sleep-MOJQBZMY.js} +1 -1
  95. package/dist/bin/shell/chunks/split-TVJYLTIJ.js +3 -0
  96. package/dist/bin/shell/chunks/sqlite3-5BGAK7VX.js +3 -0
  97. package/dist/bin/shell/chunks/{timeout-YGFHQJKX.js → timeout-RQOWSWYG.js} +1 -1
  98. package/dist/bin/shell/shell.js +385 -380
  99. package/dist/bundle/browser.js +643 -638
  100. package/dist/bundle/chunks/chmod-XZNKTJHL.js +2 -0
  101. package/dist/bundle/chunks/{chunk-XVSR5HHH.js → chunk-2T7PBFL4.js} +1 -1
  102. package/dist/bundle/chunks/chunk-3BMWRGU2.js +10 -0
  103. package/dist/bundle/chunks/chunk-3CIDHL5V.js +11 -0
  104. package/dist/bundle/chunks/chunk-4CC3OZPU.js +2 -0
  105. package/dist/bundle/chunks/{chunk-FIMF2TLE.js → chunk-5DMO6LFU.js} +12 -12
  106. package/dist/bundle/chunks/{chunk-N3A4JVFJ.js → chunk-6IA4DXG2.js} +1 -1
  107. package/dist/bundle/chunks/chunk-A257L6QO.js +7 -0
  108. package/dist/bundle/chunks/{chunk-6DDRR56B.js → chunk-ACVD6PQF.js} +1 -1
  109. package/dist/bundle/chunks/chunk-BS6EJR2R.js +11 -0
  110. package/dist/bundle/chunks/chunk-D5FHVW27.js +2 -0
  111. package/dist/bundle/chunks/{chunk-24NLAR7R.js → chunk-E3ABCXE4.js} +1 -1
  112. package/dist/bundle/chunks/{chunk-FSJ6TTCC.js → chunk-HMM3NGUJ.js} +1 -1
  113. package/dist/bundle/chunks/chunk-IYJLVOVE.js +12 -0
  114. package/dist/bundle/chunks/chunk-LRFR25IP.js +8 -0
  115. package/dist/bundle/chunks/{chunk-NBNI7G66.js → chunk-OPYVVD5P.js} +1 -1
  116. package/dist/bundle/chunks/{chunk-F6XU52K3.js → chunk-OR544SGH.js} +1 -1
  117. package/dist/bundle/chunks/{chunk-RPKJJFGZ.js → chunk-PMBXJ3OQ.js} +1 -1
  118. package/dist/bundle/chunks/chunk-PS2RJNZZ.js +2 -0
  119. package/dist/bundle/chunks/{chunk-UC76ZOWM.js → chunk-SBOTR4JQ.js} +1 -1
  120. package/dist/bundle/chunks/chunk-T5ZEIOJ3.js +2 -0
  121. package/dist/bundle/chunks/{chunk-DMWNBCXJ.js → chunk-TLPMB3FO.js} +1 -1
  122. package/dist/bundle/chunks/{chunk-XV2V56NQ.js → chunk-YFFU74KY.js} +1 -1
  123. package/dist/bundle/chunks/{chunk-DAKEIWT3.js → chunk-YNYC232D.js} +1 -1
  124. package/dist/bundle/chunks/{chunk-ZXFELXJH.js → chunk-YUOBBH7P.js} +1 -1
  125. package/dist/bundle/chunks/cp-NWITRTH3.js +2 -0
  126. package/dist/bundle/chunks/du-IFLWEM6M.js +2 -0
  127. package/dist/bundle/chunks/find-EW6OHRPJ.js +2 -0
  128. package/dist/bundle/chunks/{flag-coverage-XTIQGK65.js → flag-coverage-PIF5QRO7.js} +1 -1
  129. package/dist/bundle/chunks/{grep-4AYF3A5J.js → grep-QDFNKAUW.js} +1 -1
  130. package/dist/bundle/chunks/gzip-HBDKZBIP.js +2 -0
  131. package/dist/bundle/chunks/{js-exec-XKF2B7C3.js → js-exec-IREGAOMH.js} +7 -7
  132. package/dist/bundle/chunks/js-exec-worker.js +296 -116
  133. package/dist/bundle/chunks/ln-CEM7GDB5.js +2 -0
  134. package/dist/bundle/chunks/ls-WJ7EIFVM.js +2 -0
  135. package/dist/bundle/chunks/mkdir-Z6MMWH3D.js +2 -0
  136. package/dist/bundle/chunks/mv-E2NFLGRQ.js +2 -0
  137. package/dist/bundle/chunks/{python3-F5S5TYGS.js → python3-W4UMQJAQ.js} +1 -1
  138. package/dist/bundle/chunks/readlink-XCFO7YD2.js +2 -0
  139. package/dist/bundle/chunks/rg-J7XDRV3B.js +2 -0
  140. package/dist/bundle/chunks/rm-IGPLE632.js +2 -0
  141. package/dist/bundle/chunks/rmdir-UMUDM2L2.js +2 -0
  142. package/dist/bundle/chunks/{sleep-PPRBTSVR.js → sleep-25QUPVDK.js} +1 -1
  143. package/dist/bundle/chunks/split-D4HPO4G5.js +2 -0
  144. package/dist/bundle/chunks/sqlite3-3HL2ECCQ.js +2 -0
  145. package/dist/bundle/chunks/{timeout-C6WDYPLV.js → timeout-37GM7IIL.js} +1 -1
  146. package/dist/bundle/chunks/worker.js +233 -108
  147. package/dist/bundle/index.cjs +975 -970
  148. package/dist/bundle/index.js +357 -352
  149. package/dist/commands/js-exec/js-exec.d.ts +4 -0
  150. package/dist/commands/worker-bridge/bridge-handler.d.ts +9 -3
  151. package/dist/commands/worker-bridge/protocol.d.ts +72 -21
  152. package/dist/commands/worker-bridge/sync-backend.d.ts +3 -0
  153. package/dist/fs/fs-error.d.ts +43 -0
  154. package/dist/fs/interface.d.ts +13 -0
  155. package/dist/fs/mountable-fs/mountable-fs.d.ts +20 -0
  156. package/dist/fs/overlay-fs/apply.d.ts +15 -1
  157. package/dist/fs/overlay-fs/index.d.ts +1 -0
  158. package/dist/fs/overlay-fs/overlay-fs.d.ts +31 -0
  159. package/dist/fs/overlay-fs/overlay-tree.d.ts +39 -0
  160. package/dist/fs/path-utils.d.ts +5 -0
  161. package/dist/fs/vfs-template.d.ts +74 -0
  162. package/dist/index.d.cts +3 -1
  163. package/dist/index.d.ts +3 -1
  164. package/dist/interpreter/builtin-dispatch.d.ts +10 -0
  165. package/dist/interpreter/builtin-manifest.d.ts +273 -0
  166. package/dist/interpreter/builtins/help.d.ts +6 -0
  167. package/dist/interpreter/builtins/shopt.d.ts +3 -0
  168. package/dist/interpreter/helpers/shell-constants.d.ts +0 -20
  169. package/dist/timers.d.ts +9 -0
  170. package/package.json +135 -136
  171. package/vendor/cpython-emscripten/python.cjs +2 -2
  172. package/dist/bin/chunks/chmod-WYYTXGVB.js +0 -3
  173. package/dist/bin/chunks/chunk-43E7AR6A.js +0 -3
  174. package/dist/bin/chunks/chunk-6LDOIBU7.js +0 -9
  175. package/dist/bin/chunks/chunk-AI7JUA46.js +0 -13
  176. package/dist/bin/chunks/chunk-GQKQEK5N.js +0 -11
  177. package/dist/bin/chunks/chunk-JQM3DKCH.js +0 -12
  178. package/dist/bin/chunks/chunk-OLEQNRKX.js +0 -8
  179. package/dist/bin/chunks/chunk-PPVF2N6C.js +0 -3
  180. package/dist/bin/chunks/chunk-WEHA3JFD.js +0 -3
  181. package/dist/bin/chunks/chunk-YQEKKZTU.js +0 -12
  182. package/dist/bin/chunks/cp-OMVKM35F.js +0 -3
  183. package/dist/bin/chunks/du-LUFPVLNW.js +0 -3
  184. package/dist/bin/chunks/find-AWH2KOY7.js +0 -3
  185. package/dist/bin/chunks/gzip-FDPA6EKG.js +0 -3
  186. package/dist/bin/chunks/ln-B35EKC2Q.js +0 -3
  187. package/dist/bin/chunks/ls-Q6ZZ6SQ2.js +0 -3
  188. package/dist/bin/chunks/mkdir-74BP5NTG.js +0 -3
  189. package/dist/bin/chunks/mv-76LAHXFR.js +0 -3
  190. package/dist/bin/chunks/readlink-EHXJNW62.js +0 -3
  191. package/dist/bin/chunks/rg-PXNKNIMY.js +0 -3
  192. package/dist/bin/chunks/rm-TF2NJQIA.js +0 -3
  193. package/dist/bin/chunks/rmdir-7ZIVFZJX.js +0 -3
  194. package/dist/bin/chunks/split-ZNNNHKSP.js +0 -3
  195. package/dist/bin/chunks/sqlite3-KP42NNIY.js +0 -3
  196. package/dist/bin/shell/chunks/chmod-WYYTXGVB.js +0 -3
  197. package/dist/bin/shell/chunks/chunk-43E7AR6A.js +0 -3
  198. package/dist/bin/shell/chunks/chunk-6LDOIBU7.js +0 -9
  199. package/dist/bin/shell/chunks/chunk-AI7JUA46.js +0 -13
  200. package/dist/bin/shell/chunks/chunk-GQKQEK5N.js +0 -11
  201. package/dist/bin/shell/chunks/chunk-JQM3DKCH.js +0 -12
  202. package/dist/bin/shell/chunks/chunk-OLEQNRKX.js +0 -8
  203. package/dist/bin/shell/chunks/chunk-PPVF2N6C.js +0 -3
  204. package/dist/bin/shell/chunks/chunk-WEHA3JFD.js +0 -3
  205. package/dist/bin/shell/chunks/chunk-YQEKKZTU.js +0 -12
  206. package/dist/bin/shell/chunks/cp-OMVKM35F.js +0 -3
  207. package/dist/bin/shell/chunks/du-LUFPVLNW.js +0 -3
  208. package/dist/bin/shell/chunks/find-AWH2KOY7.js +0 -3
  209. package/dist/bin/shell/chunks/gzip-FDPA6EKG.js +0 -3
  210. package/dist/bin/shell/chunks/ln-B35EKC2Q.js +0 -3
  211. package/dist/bin/shell/chunks/ls-Q6ZZ6SQ2.js +0 -3
  212. package/dist/bin/shell/chunks/mkdir-74BP5NTG.js +0 -3
  213. package/dist/bin/shell/chunks/mv-76LAHXFR.js +0 -3
  214. package/dist/bin/shell/chunks/readlink-EHXJNW62.js +0 -3
  215. package/dist/bin/shell/chunks/rg-PXNKNIMY.js +0 -3
  216. package/dist/bin/shell/chunks/rm-TF2NJQIA.js +0 -3
  217. package/dist/bin/shell/chunks/rmdir-7ZIVFZJX.js +0 -3
  218. package/dist/bin/shell/chunks/split-ZNNNHKSP.js +0 -3
  219. package/dist/bin/shell/chunks/sqlite3-KP42NNIY.js +0 -3
  220. package/dist/bundle/chunks/chmod-WM2JFFQC.js +0 -2
  221. package/dist/bundle/chunks/chunk-7IJWBG4I.js +0 -2
  222. package/dist/bundle/chunks/chunk-MLIO3BK2.js +0 -7
  223. package/dist/bundle/chunks/chunk-PIRTX3D3.js +0 -8
  224. package/dist/bundle/chunks/chunk-TBVD66LC.js +0 -10
  225. package/dist/bundle/chunks/chunk-W2Z6LYL6.js +0 -11
  226. package/dist/bundle/chunks/chunk-WN54B5NQ.js +0 -12
  227. package/dist/bundle/chunks/chunk-WXPNKIIH.js +0 -2
  228. package/dist/bundle/chunks/chunk-YJKHREBZ.js +0 -11
  229. package/dist/bundle/chunks/chunk-YUSFCOM7.js +0 -2
  230. package/dist/bundle/chunks/cp-2KZIPZJS.js +0 -2
  231. package/dist/bundle/chunks/du-7AZCLKR6.js +0 -2
  232. package/dist/bundle/chunks/find-END3EAHV.js +0 -2
  233. package/dist/bundle/chunks/gzip-RQOBR22H.js +0 -2
  234. package/dist/bundle/chunks/ln-OPY2ZVGQ.js +0 -2
  235. package/dist/bundle/chunks/ls-ZPXGZX63.js +0 -2
  236. package/dist/bundle/chunks/mkdir-WDDKK2P3.js +0 -2
  237. package/dist/bundle/chunks/mv-ZF6UBVRB.js +0 -2
  238. package/dist/bundle/chunks/readlink-U5OM5A3M.js +0 -2
  239. package/dist/bundle/chunks/rg-NAMXBYKS.js +0 -2
  240. package/dist/bundle/chunks/rm-OAZOF7XI.js +0 -2
  241. package/dist/bundle/chunks/rmdir-YJKPQVCK.js +0 -2
  242. package/dist/bundle/chunks/split-JICLAMP6.js +0 -2
  243. package/dist/bundle/chunks/sqlite3-4EZ4GXVD.js +0 -2
@@ -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,
@@ -1663,11 +1673,18 @@ var OpCode = {
1663
1673
  // Tool invocation (executor mode)
1664
1674
  INVOKE_TOOL: 400
1665
1675
  };
1666
- var Status = {
1667
- PENDING: 0,
1668
- READY: 1,
1669
- SUCCESS: 2,
1670
- ERROR: 3
1676
+ var RequestState = {
1677
+ IDLE: 0,
1678
+ /** Worker has published an op. */
1679
+ REQUEST: 1,
1680
+ /** stop() cancellation wake. The host treats any non-REQUEST wake as
1681
+ * loop-abort (stop() also flips its `running` flag). */
1682
+ CANCELLED: 2
1683
+ };
1684
+ var ResultState = {
1685
+ NONE: 0,
1686
+ SUCCESS: 1,
1687
+ ERROR: 2
1671
1688
  };
1672
1689
  var ErrorCode = {
1673
1690
  NONE: 0,
@@ -1678,32 +1695,65 @@ var ErrorCode = {
1678
1695
  PERMISSION_DENIED: 5,
1679
1696
  INVALID_PATH: 6,
1680
1697
  IO_ERROR: 7,
1681
- TIMEOUT: 8,
1682
1698
  NETWORK_ERROR: 9,
1683
- NETWORK_NOT_CONFIGURED: 10
1699
+ NETWORK_NOT_CONFIGURED: 10,
1700
+ NOT_EMPTY: 11,
1701
+ LOOP: 12,
1702
+ FILE_TOO_LARGE: 13,
1703
+ NO_SPACE: 14,
1704
+ BUSY: 15,
1705
+ READ_ONLY: 16,
1706
+ CROSS_DEVICE: 17
1684
1707
  };
1708
+ var ERRNO_TO_WIRE = Object.assign(
1709
+ /* @__PURE__ */ Object.create(null),
1710
+ {
1711
+ ENOENT: ErrorCode.NOT_FOUND,
1712
+ EISDIR: ErrorCode.IS_DIRECTORY,
1713
+ ENOTDIR: ErrorCode.NOT_DIRECTORY,
1714
+ ENOTEMPTY: ErrorCode.NOT_EMPTY,
1715
+ EEXIST: ErrorCode.EXISTS,
1716
+ EPERM: ErrorCode.PERMISSION_DENIED,
1717
+ EACCES: ErrorCode.PERMISSION_DENIED,
1718
+ EINVAL: ErrorCode.INVALID_PATH,
1719
+ ELOOP: ErrorCode.LOOP,
1720
+ EFBIG: ErrorCode.FILE_TOO_LARGE,
1721
+ ENOSPC: ErrorCode.NO_SPACE,
1722
+ EBUSY: ErrorCode.BUSY,
1723
+ EROFS: ErrorCode.READ_ONLY,
1724
+ EXDEV: ErrorCode.CROSS_DEVICE
1725
+ }
1726
+ );
1727
+ var WIRE_TO_ERRNO = /* @__PURE__ */ Object.create(null);
1728
+ for (const [name, code] of Object.entries(ERRNO_TO_WIRE)) {
1729
+ WIRE_TO_ERRNO[code] = name;
1730
+ }
1731
+ function wireToErrnoName(code) {
1732
+ return Object.hasOwn(WIRE_TO_ERRNO, code) ? WIRE_TO_ERRNO[code] : void 0;
1733
+ }
1685
1734
  var Offset = {
1686
1735
  OP_CODE: 0,
1687
- STATUS: 4,
1736
+ REQUEST: 4,
1688
1737
  PATH_LENGTH: 8,
1689
1738
  DATA_LENGTH: 12,
1690
1739
  RESULT_LENGTH: 16,
1691
1740
  ERROR_CODE: 20,
1692
1741
  FLAGS: 24,
1693
1742
  MODE: 28,
1694
- PATH_BUFFER: 32,
1695
- DATA_BUFFER: 4128
1696
- // 32 + 4096
1743
+ RESULT_STATE: 32,
1744
+ PATH_BUFFER: 36,
1745
+ DATA_BUFFER: 4132
1746
+ // 36 + 4096
1697
1747
  };
1698
1748
  var Size = {
1699
- CONTROL_REGION: 32,
1700
1749
  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.
1750
+ // 8MB transfer CHUNK size — not a semantic cap. Results larger than
1751
+ // this are assembled transparently (READ_RESULT_RANGE), and large
1752
+ // writes stream as WRITE_FILE_RANGE chunks. Sized to keep ordinary
1753
+ // ops single-transfer while bounding per-transfer copies.
1704
1754
  DATA_BUFFER: 8388608,
1705
- TOTAL: 8392736
1706
- // 32 + 4096 + 8MB
1755
+ TOTAL: 8392740
1756
+ // 36 + 4096 + 8MB
1707
1757
  };
1708
1758
  var Flags = {
1709
1759
  NONE: 0,
@@ -1735,11 +1785,23 @@ var ProtocolBuffer = class {
1735
1785
  setOpCode(code) {
1736
1786
  _Atomics.store(this.int32View, Offset.OP_CODE / 4, code);
1737
1787
  }
1738
- getStatus() {
1739
- return _Atomics.load(this.int32View, Offset.STATUS / 4);
1788
+ getRequest() {
1789
+ return _Atomics.load(
1790
+ this.int32View,
1791
+ Offset.REQUEST / 4
1792
+ );
1793
+ }
1794
+ setRequest(request) {
1795
+ _Atomics.store(this.int32View, Offset.REQUEST / 4, request);
1796
+ }
1797
+ getResultState() {
1798
+ return _Atomics.load(
1799
+ this.int32View,
1800
+ Offset.RESULT_STATE / 4
1801
+ );
1740
1802
  }
1741
- setStatus(status) {
1742
- _Atomics.store(this.int32View, Offset.STATUS / 4, status);
1803
+ setResultState(state) {
1804
+ _Atomics.store(this.int32View, Offset.RESULT_STATE / 4, state);
1743
1805
  }
1744
1806
  getPathLength() {
1745
1807
  return _Atomics.load(this.int32View, Offset.PATH_LENGTH / 4);
@@ -1832,6 +1894,20 @@ var ProtocolBuffer = class {
1832
1894
  this.uint8View.set(data, Offset.DATA_BUFFER);
1833
1895
  this.setResultLength(data.length);
1834
1896
  }
1897
+ /**
1898
+ * Publish a result of ANY size: the first DATA_BUFFER bytes land in
1899
+ * the data region and RESULT_LENGTH carries the FULL length. The
1900
+ * worker detects the overflow and fetches the rest with
1901
+ * READ_RESULT_RANGE ops (served from the host's retained buffer).
1902
+ */
1903
+ setResultPrefix(data) {
1904
+ if (data.length > 2147483647) {
1905
+ throw new Error(`Result too large: ${data.length} exceeds int32`);
1906
+ }
1907
+ const n = Math.min(data.length, Size.DATA_BUFFER);
1908
+ this.uint8View.set(data.subarray(0, n), Offset.DATA_BUFFER);
1909
+ this.setResultLength(data.length);
1910
+ }
1835
1911
  getResultAsString() {
1836
1912
  const result = this.getResult();
1837
1913
  return new TextDecoder().decode(result);
@@ -1873,33 +1949,21 @@ var ProtocolBuffer = class {
1873
1949
  )
1874
1950
  };
1875
1951
  }
1876
- waitForReady(timeout) {
1877
- return _Atomics.wait(
1878
- this.int32View,
1879
- Offset.STATUS / 4,
1880
- Status.PENDING,
1881
- timeout
1882
- );
1883
- }
1884
- waitForReadyAsync(timeout) {
1885
- return _Atomics.waitAsync(
1886
- this.int32View,
1887
- Offset.STATUS / 4,
1888
- Status.PENDING,
1889
- timeout
1890
- );
1891
- }
1892
1952
  /**
1893
- * Wait for status to become READY.
1894
- * Returns immediately if status is already READY, or waits until it changes.
1953
+ * Wait for the request word to become REQUEST.
1954
+ * Returns immediately if already REQUEST; CANCELLED or any unexpected
1955
+ * state returns false (the caller's running-flag check aborts the loop).
1895
1956
  */
1896
1957
  async waitUntilReady(timeout) {
1897
1958
  const startTime = Date.now();
1898
1959
  while (true) {
1899
- const status = this.getStatus();
1900
- if (status === Status.READY) {
1960
+ const request = this.getRequest();
1961
+ if (request === RequestState.REQUEST) {
1901
1962
  return true;
1902
1963
  }
1964
+ if (request !== RequestState.IDLE) {
1965
+ return false;
1966
+ }
1903
1967
  const elapsed = Date.now() - startTime;
1904
1968
  if (elapsed >= timeout) {
1905
1969
  return false;
@@ -1907,8 +1971,8 @@ var ProtocolBuffer = class {
1907
1971
  const remainingMs = timeout - elapsed;
1908
1972
  const result = _Atomics.waitAsync(
1909
1973
  this.int32View,
1910
- Offset.STATUS / 4,
1911
- status,
1974
+ Offset.REQUEST / 4,
1975
+ RequestState.IDLE,
1912
1976
  remainingMs
1913
1977
  );
1914
1978
  if (result.async) {
@@ -1919,20 +1983,25 @@ var ProtocolBuffer = class {
1919
1983
  }
1920
1984
  }
1921
1985
  }
1986
+ /** Worker-side blocking wait on the RESULT word (host writes). */
1922
1987
  waitForResult(timeout) {
1923
1988
  return _Atomics.wait(
1924
1989
  this.int32View,
1925
- Offset.STATUS / 4,
1926
- Status.READY,
1990
+ Offset.RESULT_STATE / 4,
1991
+ ResultState.NONE,
1927
1992
  timeout
1928
1993
  );
1929
1994
  }
1930
- notify() {
1931
- return _Atomics.notify(this.int32View, Offset.STATUS / 4);
1995
+ notifyRequest() {
1996
+ return _Atomics.notify(this.int32View, Offset.REQUEST / 4);
1997
+ }
1998
+ notifyResult() {
1999
+ return _Atomics.notify(this.int32View, Offset.RESULT_STATE / 4);
1932
2000
  }
1933
2001
  reset() {
1934
2002
  this.setOpCode(OpCode.NOOP);
1935
- this.setStatus(Status.PENDING);
2003
+ this.setRequest(RequestState.IDLE);
2004
+ this.setResultState(ResultState.NONE);
1936
2005
  this.setPathLength(0);
1937
2006
  this.setDataLength(0);
1938
2007
  this.setResultLength(0);
@@ -1959,52 +2028,117 @@ var SyncBackend = class {
1959
2028
  if (data) {
1960
2029
  this.protocol.setData(data);
1961
2030
  }
1962
- this.protocol.setStatus(Status.READY);
1963
- this.protocol.notify();
2031
+ this.protocol.setRequest(RequestState.REQUEST);
2032
+ this.protocol.notifyRequest();
1964
2033
  const waitResult = this.protocol.waitForResult(this.operationTimeoutMs);
1965
2034
  if (waitResult === "timed-out") {
1966
2035
  return { success: false, error: "Operation timed out" };
1967
2036
  }
1968
- const status = this.protocol.getStatus();
1969
- if (status === Status.SUCCESS) {
1970
- return { success: true, result: this.protocol.getResult() };
2037
+ const resultState = this.protocol.getResultState();
2038
+ if (resultState === ResultState.SUCCESS) {
2039
+ const totalLength = this.protocol.getResultLength();
2040
+ if (totalLength <= Size.DATA_BUFFER) {
2041
+ return { success: true, result: this.protocol.getResult() };
2042
+ }
2043
+ const content = new Uint8Array(totalLength);
2044
+ content.set(this.protocol.getResult().subarray(0, Size.DATA_BUFFER), 0);
2045
+ let offset = Size.DATA_BUFFER;
2046
+ while (offset < totalLength) {
2047
+ const length = Math.min(Size.DATA_BUFFER, totalLength - offset);
2048
+ const slice = this.execSync(
2049
+ OpCode.READ_RESULT_RANGE,
2050
+ "",
2051
+ void 0,
2052
+ offset,
2053
+ length
2054
+ );
2055
+ if (!slice.success) {
2056
+ throw this.opError_("Failed to read result range", slice);
2057
+ }
2058
+ const chunk = slice.result ?? new Uint8Array(0);
2059
+ content.set(chunk, offset);
2060
+ offset += chunk.length;
2061
+ if (chunk.length === 0) {
2062
+ throw this.opError_("bridge returned an empty result slice", slice);
2063
+ }
2064
+ }
2065
+ return { success: true, result: content };
2066
+ }
2067
+ if (resultState === ResultState.ERROR) {
2068
+ return {
2069
+ success: false,
2070
+ error: this.protocol.getResultAsString() || // Impossible by construction: every host error path publishes a
2071
+ // code and message. If this ever fires, the diagnostic payload
2072
+ // must identify the exact protocol state.
2073
+ `bridge protocol violation: op ${opCode} ERROR with empty message (wait=${waitResult}, errorCode=${this.protocol.getErrorCode()})`,
2074
+ errorCode: this.protocol.getErrorCode()
2075
+ };
1971
2076
  }
1972
2077
  return {
1973
2078
  success: false,
1974
- error: this.protocol.getResultAsString() || `Error code: ${this.protocol.getErrorCode()}`
2079
+ error: `bridge protocol violation: op ${opCode} woke with resultState ${resultState} (wait=${waitResult}, errorCode=${this.protocol.getErrorCode()})`,
2080
+ errorCode: this.protocol.getErrorCode()
1975
2081
  };
1976
2082
  }
2083
+ /** Build an op failure that preserves the bridge's numeric error code,
2084
+ * so downstream errno mapping prefers it over substring matching. */
2085
+ opError_(fallback, result) {
2086
+ const err = new Error(result.error || fallback);
2087
+ err.bridgeErrorCode = result.errorCode;
2088
+ if (result.errorCode !== void 0) {
2089
+ const name = wireToErrnoName(result.errorCode);
2090
+ if (name !== void 0) err.code = name;
2091
+ }
2092
+ return err;
2093
+ }
1977
2094
  readFile(path) {
1978
2095
  const result = this.execSync(OpCode.READ_FILE, path);
1979
2096
  if (!result.success) {
1980
- throw new Error(result.error || "Failed to read file");
2097
+ throw this.opError_("Failed to read file", result);
1981
2098
  }
1982
2099
  return result.result ?? new Uint8Array(0);
1983
2100
  }
1984
2101
  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");
2102
+ if (data.length <= Size.DATA_BUFFER) {
2103
+ const result = this.execSync(OpCode.WRITE_FILE, path, data);
2104
+ if (!result.success) {
2105
+ throw this.opError_("Failed to write file", result);
2106
+ }
2107
+ return;
2108
+ }
2109
+ let offset = 0;
2110
+ while (offset < data.length) {
2111
+ const chunk = data.subarray(offset, offset + Size.DATA_BUFFER);
2112
+ const result = this.execSync(
2113
+ OpCode.WRITE_FILE_RANGE,
2114
+ path,
2115
+ chunk,
2116
+ offset
2117
+ );
2118
+ if (!result.success) {
2119
+ throw this.opError_("Failed to write file", result);
2120
+ }
2121
+ offset += chunk.length;
1988
2122
  }
1989
2123
  }
1990
2124
  stat(path) {
1991
2125
  const result = this.execSync(OpCode.STAT, path);
1992
2126
  if (!result.success) {
1993
- throw new Error(result.error || "Failed to stat");
2127
+ throw this.opError_("Failed to stat", result);
1994
2128
  }
1995
2129
  return this.protocol.decodeStat();
1996
2130
  }
1997
2131
  lstat(path) {
1998
2132
  const result = this.execSync(OpCode.LSTAT, path);
1999
2133
  if (!result.success) {
2000
- throw new Error(result.error || "Failed to lstat");
2134
+ throw this.opError_("Failed to lstat", result);
2001
2135
  }
2002
2136
  return this.protocol.decodeStat();
2003
2137
  }
2004
2138
  readdir(path) {
2005
2139
  const result = this.execSync(OpCode.READDIR, path);
2006
2140
  if (!result.success) {
2007
- throw new Error(result.error || "Failed to readdir");
2141
+ throw this.opError_("Failed to readdir", result);
2008
2142
  }
2009
2143
  return JSON.parse(this.protocol.getResultAsString());
2010
2144
  }
@@ -2012,7 +2146,7 @@ var SyncBackend = class {
2012
2146
  const flags = recursive ? Flags.MKDIR_RECURSIVE : 0;
2013
2147
  const result = this.execSync(OpCode.MKDIR, path, void 0, flags);
2014
2148
  if (!result.success) {
2015
- throw new Error(result.error || "Failed to mkdir");
2149
+ throw this.opError_("Failed to mkdir", result);
2016
2150
  }
2017
2151
  }
2018
2152
  rm(path, recursive = false, force = false) {
@@ -2021,7 +2155,7 @@ var SyncBackend = class {
2021
2155
  if (force) flags |= Flags.FORCE;
2022
2156
  const result = this.execSync(OpCode.RM, path, void 0, flags);
2023
2157
  if (!result.success) {
2024
- throw new Error(result.error || "Failed to rm");
2158
+ throw this.opError_("Failed to rm", result);
2025
2159
  }
2026
2160
  }
2027
2161
  exists(path) {
@@ -2034,33 +2168,33 @@ var SyncBackend = class {
2034
2168
  appendFile(path, data) {
2035
2169
  const result = this.execSync(OpCode.APPEND_FILE, path, data);
2036
2170
  if (!result.success) {
2037
- throw new Error(result.error || "Failed to append file");
2171
+ throw this.opError_("Failed to append file", result);
2038
2172
  }
2039
2173
  }
2040
2174
  symlink(target, linkPath) {
2041
2175
  const targetData = new TextEncoder().encode(target);
2042
2176
  const result = this.execSync(OpCode.SYMLINK, linkPath, targetData);
2043
2177
  if (!result.success) {
2044
- throw new Error(result.error || "Failed to symlink");
2178
+ throw this.opError_("Failed to symlink", result);
2045
2179
  }
2046
2180
  }
2047
2181
  readlink(path) {
2048
2182
  const result = this.execSync(OpCode.READLINK, path);
2049
2183
  if (!result.success) {
2050
- throw new Error(result.error || "Failed to readlink");
2184
+ throw this.opError_("Failed to readlink", result);
2051
2185
  }
2052
2186
  return this.protocol.getResultAsString();
2053
2187
  }
2054
2188
  chmod(path, mode) {
2055
2189
  const result = this.execSync(OpCode.CHMOD, path, void 0, 0, mode);
2056
2190
  if (!result.success) {
2057
- throw new Error(result.error || "Failed to chmod");
2191
+ throw this.opError_("Failed to chmod", result);
2058
2192
  }
2059
2193
  }
2060
2194
  realpath(path) {
2061
2195
  const result = this.execSync(OpCode.REALPATH, path);
2062
2196
  if (!result.success) {
2063
- throw new Error(result.error || "Failed to realpath");
2197
+ throw this.opError_("Failed to realpath", result);
2064
2198
  }
2065
2199
  return this.protocol.getResultAsString();
2066
2200
  }
@@ -2068,28 +2202,28 @@ var SyncBackend = class {
2068
2202
  const newPathData = new TextEncoder().encode(newPath);
2069
2203
  const result = this.execSync(OpCode.RENAME, oldPath, newPathData);
2070
2204
  if (!result.success) {
2071
- throw new Error(result.error || "Failed to rename");
2205
+ throw this.opError_("Failed to rename", result);
2072
2206
  }
2073
2207
  }
2074
2208
  copyFile(src, dest) {
2075
2209
  const destData = new TextEncoder().encode(dest);
2076
2210
  const result = this.execSync(OpCode.COPY_FILE, src, destData);
2077
2211
  if (!result.success) {
2078
- throw new Error(result.error || "Failed to copyFile");
2212
+ throw this.opError_("Failed to copyFile", result);
2079
2213
  }
2080
2214
  }
2081
2215
  writeStdout(data) {
2082
2216
  const encoded = new TextEncoder().encode(data);
2083
2217
  const result = this.execSync(OpCode.WRITE_STDOUT, "", encoded);
2084
2218
  if (!result.success) {
2085
- throw new Error(result.error || "Failed to write stdout");
2219
+ throw this.opError_("Failed to write stdout", result);
2086
2220
  }
2087
2221
  }
2088
2222
  writeStderr(data) {
2089
2223
  const encoded = new TextEncoder().encode(data);
2090
2224
  const result = this.execSync(OpCode.WRITE_STDERR, "", encoded);
2091
2225
  if (!result.success) {
2092
- throw new Error(result.error || "Failed to write stderr");
2226
+ throw this.opError_("Failed to write stderr", result);
2093
2227
  }
2094
2228
  }
2095
2229
  exit(code) {
@@ -2103,7 +2237,7 @@ var SyncBackend = class {
2103
2237
  const requestData = options ? new TextEncoder().encode(JSON.stringify(options)) : void 0;
2104
2238
  const result = this.execSync(OpCode.HTTP_REQUEST, url, requestData);
2105
2239
  if (!result.success) {
2106
- throw new Error(result.error || "HTTP request failed");
2240
+ throw this.opError_("HTTP request failed", result);
2107
2241
  }
2108
2242
  const responseJson = new TextDecoder().decode(result.result);
2109
2243
  const parsed = JSON.parse(responseJson);
@@ -2126,7 +2260,7 @@ var SyncBackend = class {
2126
2260
  const requestData = stdin ? new TextEncoder().encode(JSON.stringify({ stdin })) : void 0;
2127
2261
  const result = this.execSync(OpCode.EXEC_COMMAND, command, requestData);
2128
2262
  if (!result.success) {
2129
- throw new Error(result.error || "Command execution failed");
2263
+ throw this.opError_("Command execution failed", result);
2130
2264
  }
2131
2265
  const responseJson = new TextDecoder().decode(result.result);
2132
2266
  return JSON.parse(responseJson);
@@ -2139,7 +2273,7 @@ var SyncBackend = class {
2139
2273
  const requestData = new TextEncoder().encode(JSON.stringify({ args }));
2140
2274
  const result = this.execSync(OpCode.EXEC_COMMAND, command, requestData);
2141
2275
  if (!result.success) {
2142
- throw new Error(result.error || "Command execution failed");
2276
+ throw this.opError_("Command execution failed", result);
2143
2277
  }
2144
2278
  const responseJson = new TextDecoder().decode(result.result);
2145
2279
  return JSON.parse(responseJson);
@@ -2152,7 +2286,7 @@ var SyncBackend = class {
2152
2286
  const requestData = argsJson ? new TextEncoder().encode(argsJson) : void 0;
2153
2287
  const result = this.execSync(OpCode.INVOKE_TOOL, path, requestData);
2154
2288
  if (!result.success) {
2155
- throw new Error(result.error || "Tool invocation failed");
2289
+ throw this.opError_("Tool invocation failed", result);
2156
2290
  }
2157
2291
  return new TextDecoder().decode(result.result);
2158
2292
  }
@@ -3571,8 +3705,18 @@ function formatError(errorVal) {
3571
3705
  }
3572
3706
  return String(errorVal);
3573
3707
  }
3574
- function throwError(context, message) {
3575
- return { error: context.newError(message) };
3708
+ function throwError(context, message, code) {
3709
+ const err = context.newError(message);
3710
+ if (code !== void 0) {
3711
+ const codeHandle = context.newString(code);
3712
+ context.setProp(err, "code", codeHandle);
3713
+ codeHandle.dispose();
3714
+ }
3715
+ return { error: err };
3716
+ }
3717
+ function throwGuestError_(context, e, fallback) {
3718
+ const err = e;
3719
+ return throwError(context, err?.message || fallback, err?.code);
3576
3720
  }
3577
3721
  function isProcessExit(context, error, processExitMarker) {
3578
3722
  const marker = context.getProp(error, PROCESS_EXIT_MARKER);
@@ -3816,7 +3960,7 @@ function setupContext(context, backend, input, processExitMarker) {
3816
3960
  backend.writeStdout(`${parts.join(" ")}
3817
3961
  `);
3818
3962
  } catch (e) {
3819
- return throwError(context, e.message || "write failed");
3963
+ return throwGuestError_(context, e, "write failed");
3820
3964
  }
3821
3965
  return context.undefined;
3822
3966
  });
@@ -3831,7 +3975,7 @@ function setupContext(context, backend, input, processExitMarker) {
3831
3975
  backend.writeStderr(`${parts.join(" ")}
3832
3976
  `);
3833
3977
  } catch (e) {
3834
- return throwError(context, e.message || "write failed");
3978
+ return throwGuestError_(context, e, "write failed");
3835
3979
  }
3836
3980
  return context.undefined;
3837
3981
  });
@@ -3846,7 +3990,7 @@ function setupContext(context, backend, input, processExitMarker) {
3846
3990
  backend.writeStderr(`${parts.join(" ")}
3847
3991
  `);
3848
3992
  } catch (e) {
3849
- return throwError(context, e.message || "write failed");
3993
+ return throwGuestError_(context, e, "write failed");
3850
3994
  }
3851
3995
  return context.undefined;
3852
3996
  });
@@ -3863,7 +4007,7 @@ function setupContext(context, backend, input, processExitMarker) {
3863
4007
  const data = backend.readFile(path);
3864
4008
  return context.newString(new TextDecoder().decode(data));
3865
4009
  } catch (e) {
3866
- return throwError(context, e.message || "readFile failed");
4010
+ return throwGuestError_(context, e, "readFile failed");
3867
4011
  }
3868
4012
  }
3869
4013
  );
@@ -3879,25 +4023,56 @@ function setupContext(context, backend, input, processExitMarker) {
3879
4023
  data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)
3880
4024
  );
3881
4025
  } catch (e) {
3882
- return throwError(
3883
- context,
3884
- e.message || "readFileBuffer failed"
3885
- );
4026
+ return throwGuestError_(context, e, "readFileBuffer failed");
3886
4027
  }
3887
4028
  }
3888
4029
  );
3889
4030
  context.setProp(fsObj, "readFileBuffer", readFileBufferFn);
3890
4031
  readFileBufferFn.dispose();
4032
+ const marshalWriteData = (dataHandle) => {
4033
+ if (context.typeof(dataHandle) === "string") {
4034
+ return new TextEncoder().encode(context.getString(dataHandle));
4035
+ }
4036
+ if (context.typeof(dataHandle) === "object") {
4037
+ const bufferHandle = context.getProp(dataHandle, "buffer");
4038
+ if (bufferHandle && context.typeof(bufferHandle) === "object") {
4039
+ const offsetHandle = context.getProp(dataHandle, "byteOffset");
4040
+ const lengthHandle = context.getProp(dataHandle, "byteLength");
4041
+ try {
4042
+ const raw = context.getArrayBuffer(bufferHandle).value;
4043
+ const view = raw instanceof Uint8Array ? raw : new Uint8Array(raw);
4044
+ const offset = offsetHandle && context.typeof(offsetHandle) === "number" ? context.getNumber(offsetHandle) : 0;
4045
+ const length = lengthHandle && context.typeof(lengthHandle) === "number" ? context.getNumber(lengthHandle) : view.byteLength - offset;
4046
+ if (offset < 0 || length < 0 || offset + length > view.byteLength) {
4047
+ throw new TypeError("writeFile data has an invalid byte window");
4048
+ }
4049
+ return view.slice(offset, offset + length);
4050
+ } finally {
4051
+ bufferHandle.dispose();
4052
+ offsetHandle?.dispose();
4053
+ lengthHandle?.dispose();
4054
+ }
4055
+ }
4056
+ bufferHandle?.dispose();
4057
+ try {
4058
+ const raw = context.getArrayBuffer(dataHandle).value;
4059
+ return raw instanceof Uint8Array ? raw : new Uint8Array(raw);
4060
+ } catch {
4061
+ }
4062
+ }
4063
+ throw new TypeError(
4064
+ "writeFile data must be a string, Buffer, TypedArray, or DataView"
4065
+ );
4066
+ };
3891
4067
  const writeFileFn = context.newFunction(
3892
4068
  "writeFile",
3893
4069
  (pathHandle, dataHandle) => {
3894
4070
  const path = context.getString(pathHandle);
3895
- const data = context.getString(dataHandle);
3896
4071
  try {
3897
- backend.writeFile(path, new TextEncoder().encode(data));
4072
+ backend.writeFile(path, marshalWriteData(dataHandle));
3898
4073
  return context.undefined;
3899
4074
  } catch (e) {
3900
- return throwError(context, e.message || "writeFile failed");
4075
+ return throwGuestError_(context, e, "writeFile failed");
3901
4076
  }
3902
4077
  }
3903
4078
  );
@@ -3916,7 +4091,7 @@ function setupContext(context, backend, input, processExitMarker) {
3916
4091
  mtime: stat.mtime.toISOString()
3917
4092
  });
3918
4093
  } catch (e) {
3919
- return throwError(context, e.message || "stat failed");
4094
+ return throwGuestError_(context, e, "stat failed");
3920
4095
  }
3921
4096
  });
3922
4097
  context.setProp(fsObj, "stat", statFn);
@@ -3929,7 +4104,7 @@ function setupContext(context, backend, input, processExitMarker) {
3929
4104
  const entries = backend.readdir(path);
3930
4105
  return jsToHandle(context, entries);
3931
4106
  } catch (e) {
3932
- return throwError(context, e.message || "readdir failed");
4107
+ return throwGuestError_(context, e, "readdir failed");
3933
4108
  }
3934
4109
  }
3935
4110
  );
@@ -3950,7 +4125,7 @@ function setupContext(context, backend, input, processExitMarker) {
3950
4125
  backend.mkdir(path, recursive);
3951
4126
  return context.undefined;
3952
4127
  } catch (e) {
3953
- return throwError(context, e.message || "mkdir failed");
4128
+ return throwGuestError_(context, e, "mkdir failed");
3954
4129
  }
3955
4130
  }
3956
4131
  );
@@ -3973,7 +4148,7 @@ function setupContext(context, backend, input, processExitMarker) {
3973
4148
  backend.rm(path, recursive, force);
3974
4149
  return context.undefined;
3975
4150
  } catch (e) {
3976
- return throwError(context, e.message || "rm failed");
4151
+ return throwGuestError_(context, e, "rm failed");
3977
4152
  }
3978
4153
  }
3979
4154
  );
@@ -3992,12 +4167,11 @@ function setupContext(context, backend, input, processExitMarker) {
3992
4167
  "appendFile",
3993
4168
  (pathHandle, dataHandle) => {
3994
4169
  const path = context.getString(pathHandle);
3995
- const data = context.getString(dataHandle);
3996
4170
  try {
3997
- backend.appendFile(path, new TextEncoder().encode(data));
4171
+ backend.appendFile(path, marshalWriteData(dataHandle));
3998
4172
  return context.undefined;
3999
4173
  } catch (e) {
4000
- return throwError(context, e.message || "appendFile failed");
4174
+ return throwGuestError_(context, e, "appendFile failed");
4001
4175
  }
4002
4176
  }
4003
4177
  );
@@ -4016,7 +4190,7 @@ function setupContext(context, backend, input, processExitMarker) {
4016
4190
  mtime: s.mtime.toISOString()
4017
4191
  });
4018
4192
  } catch (e) {
4019
- return throwError(context, e.message || "lstat failed");
4193
+ return throwGuestError_(context, e, "lstat failed");
4020
4194
  }
4021
4195
  });
4022
4196
  context.setProp(fsObj, "lstat", lstatFn);
@@ -4030,7 +4204,7 @@ function setupContext(context, backend, input, processExitMarker) {
4030
4204
  backend.symlink(target, linkPath);
4031
4205
  return context.undefined;
4032
4206
  } catch (e) {
4033
- return throwError(context, e.message || "symlink failed");
4207
+ return throwGuestError_(context, e, "symlink failed");
4034
4208
  }
4035
4209
  }
4036
4210
  );
@@ -4044,7 +4218,7 @@ function setupContext(context, backend, input, processExitMarker) {
4044
4218
  const target = backend.readlink(path);
4045
4219
  return context.newString(target);
4046
4220
  } catch (e) {
4047
- return throwError(context, e.message || "readlink failed");
4221
+ return throwGuestError_(context, e, "readlink failed");
4048
4222
  }
4049
4223
  }
4050
4224
  );
@@ -4059,7 +4233,7 @@ function setupContext(context, backend, input, processExitMarker) {
4059
4233
  backend.chmod(path, typeof mode === "number" ? mode : 0);
4060
4234
  return context.undefined;
4061
4235
  } catch (e) {
4062
- return throwError(context, e.message || "chmod failed");
4236
+ return throwGuestError_(context, e, "chmod failed");
4063
4237
  }
4064
4238
  }
4065
4239
  );
@@ -4073,7 +4247,7 @@ function setupContext(context, backend, input, processExitMarker) {
4073
4247
  const resolved = backend.realpath(path);
4074
4248
  return context.newString(resolved);
4075
4249
  } catch (e) {
4076
- return throwError(context, e.message || "realpath failed");
4250
+ return throwGuestError_(context, e, "realpath failed");
4077
4251
  }
4078
4252
  }
4079
4253
  );
@@ -4088,7 +4262,7 @@ function setupContext(context, backend, input, processExitMarker) {
4088
4262
  backend.rename(oldPath, newPath);
4089
4263
  return context.undefined;
4090
4264
  } catch (e) {
4091
- return throwError(context, e.message || "rename failed");
4265
+ return throwGuestError_(context, e, "rename failed");
4092
4266
  }
4093
4267
  }
4094
4268
  );
@@ -4103,7 +4277,7 @@ function setupContext(context, backend, input, processExitMarker) {
4103
4277
  backend.copyFile(src, dest);
4104
4278
  return context.undefined;
4105
4279
  } catch (e) {
4106
- return throwError(context, e.message || "copyFile failed");
4280
+ return throwGuestError_(context, e, "copyFile failed");
4107
4281
  }
4108
4282
  }
4109
4283
  );
@@ -4127,7 +4301,7 @@ function setupContext(context, backend, input, processExitMarker) {
4127
4301
  });
4128
4302
  return jsToHandle(context, result);
4129
4303
  } catch (e) {
4130
- return throwError(context, e.message || "fetch failed");
4304
+ return throwGuestError_(context, e, "fetch failed");
4131
4305
  }
4132
4306
  }
4133
4307
  );
@@ -4148,7 +4322,7 @@ function setupContext(context, backend, input, processExitMarker) {
4148
4322
  const result = backend.execCommand(command, stdin);
4149
4323
  return jsToHandle(context, result);
4150
4324
  } catch (e) {
4151
- return throwError(context, e.message || "exec failed");
4325
+ return throwGuestError_(context, e, "exec failed");
4152
4326
  }
4153
4327
  }
4154
4328
  );
@@ -4163,7 +4337,7 @@ function setupContext(context, backend, input, processExitMarker) {
4163
4337
  const result = backend.execCommandArgs(command, args);
4164
4338
  return jsToHandle(context, result);
4165
4339
  } catch (e) {
4166
- return throwError(context, e.message || "exec failed");
4340
+ return throwGuestError_(context, e, "exec failed");
4167
4341
  }
4168
4342
  }
4169
4343
  );
@@ -4179,10 +4353,7 @@ function setupContext(context, backend, input, processExitMarker) {
4179
4353
  const resultJson = backend.invokeTool(path, argsJson);
4180
4354
  return context.newString(resultJson);
4181
4355
  } catch (e) {
4182
- return throwError(
4183
- context,
4184
- e.message || "tool invocation failed"
4185
- );
4356
+ return throwGuestError_(context, e, "tool invocation failed");
4186
4357
  }
4187
4358
  }
4188
4359
  );
@@ -4310,7 +4481,13 @@ function setupContext(context, backend, input, processExitMarker) {
4310
4481
  _fs.promises.unlink = _fs.promises.rm;
4311
4482
  _fs.promises.rmdir = _fs.promises.rm;
4312
4483
  _fs.promises.access = function(p) {
4313
- return orig.exists(p) ? Promise.resolve() : Promise.reject(new Error('ENOENT: no such file or directory: ' + p));
4484
+ if (orig.exists(p)) return Promise.resolve();
4485
+ // Node-style error: prefixed message AND structured .code (the
4486
+ // sanctioned pattern \u2014 no errno literal at the Error call site).
4487
+ var msg = 'ENOENT: no such file or directory: ' + p;
4488
+ var e = new Error(msg);
4489
+ e.code = 'ENOENT';
4490
+ return Promise.reject(e);
4314
4491
  };
4315
4492
 
4316
4493
  // process enhancements
@@ -4640,11 +4817,14 @@ async function executeCode(input) {
4640
4817
  }
4641
4818
  return source;
4642
4819
  } catch (e) {
4643
- return {
4644
- error: new Error(
4645
- `Cannot find module '${moduleName}': ${e.message}`
4646
- )
4647
- };
4820
+ const err = new Error(
4821
+ `Cannot find module '${moduleName}': ${e.message}`
4822
+ );
4823
+ const code = e.code;
4824
+ if (code !== void 0) {
4825
+ err.code = code;
4826
+ }
4827
+ return { error: err };
4648
4828
  }
4649
4829
  },
4650
4830
  (baseModuleName, requestedName) => {