@jerryan/just-bash 3.5.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 (958) hide show
  1. package/CHANGELOG.md +308 -0
  2. package/LICENSE +201 -0
  3. package/README.md +827 -0
  4. package/dist/AGENTS.md +383 -0
  5. package/dist/Bash.d.ts +317 -0
  6. package/dist/abort-signals.d.ts +10 -0
  7. package/dist/agent-sandbox.d.ts +104 -0
  8. package/dist/ast/types.d.ts +612 -0
  9. package/dist/banned-patterns-test.d.ts +1 -0
  10. package/dist/bin/chunks/alias-3R4G6HQY.js +3 -0
  11. package/dist/bin/chunks/awk2-KO7ZE3P7.js +3 -0
  12. package/dist/bin/chunks/base64-TQ5KOCNW.js +3 -0
  13. package/dist/bin/chunks/basename-C4CRGDXP.js +3 -0
  14. package/dist/bin/chunks/bash-CFCBBWVH.js +3 -0
  15. package/dist/bin/chunks/cat-BQ7FQTN5.js +3 -0
  16. package/dist/bin/chunks/chmod-WYYTXGVB.js +3 -0
  17. package/dist/bin/chunks/chunk-23OI2XDJ.js +20 -0
  18. package/dist/bin/chunks/chunk-2ETT4ELS.js +4 -0
  19. package/dist/bin/chunks/chunk-2UV6ZFHK.js +4 -0
  20. package/dist/bin/chunks/chunk-2YLY6FJA.js +10 -0
  21. package/dist/bin/chunks/chunk-3FQBUEB6.js +3 -0
  22. package/dist/bin/chunks/chunk-3MRB66F4.js +3 -0
  23. package/dist/bin/chunks/chunk-3PCPQIUD.js +3 -0
  24. package/dist/bin/chunks/chunk-42AMF6EE.js +3 -0
  25. package/dist/bin/chunks/chunk-43E7AR6A.js +3 -0
  26. package/dist/bin/chunks/chunk-45DUHCXR.js +7 -0
  27. package/dist/bin/chunks/chunk-472JZJ2D.js +22 -0
  28. package/dist/bin/chunks/chunk-47IFMQYS.js +3 -0
  29. package/dist/bin/chunks/chunk-4JF56A3P.js +15 -0
  30. package/dist/bin/chunks/chunk-5SKEZPTU.js +12 -0
  31. package/dist/bin/chunks/chunk-67XYNGRV.js +9 -0
  32. package/dist/bin/chunks/chunk-6ESRNSO7.js +7 -0
  33. package/dist/bin/chunks/chunk-6KHZX4HU.js +12 -0
  34. package/dist/bin/chunks/chunk-7FGDUBSN.js +14 -0
  35. package/dist/bin/chunks/chunk-7JZKVC3F.js +2 -0
  36. package/dist/bin/chunks/chunk-7PPAWLUI.js +12 -0
  37. package/dist/bin/chunks/chunk-7PUOS2OO.js +143 -0
  38. package/dist/bin/chunks/chunk-7VWOECJ3.js +101 -0
  39. package/dist/bin/chunks/chunk-7WBCA2BB.js +3 -0
  40. package/dist/bin/chunks/chunk-AGKL4LDL.js +4 -0
  41. package/dist/bin/chunks/chunk-AI7JUA46.js +13 -0
  42. package/dist/bin/chunks/chunk-AJF3OBTR.js +4 -0
  43. package/dist/bin/chunks/chunk-B2DRBHGQ.js +3 -0
  44. package/dist/bin/chunks/chunk-B2GCIQI2.js +16 -0
  45. package/dist/bin/chunks/chunk-B6WWC6K3.js +9 -0
  46. package/dist/bin/chunks/chunk-BIJXTWZ4.js +3 -0
  47. package/dist/bin/chunks/chunk-CC2AQ6B7.js +15 -0
  48. package/dist/bin/chunks/chunk-CL7IYCGG.js +20 -0
  49. package/dist/bin/chunks/chunk-CMTQFWZK.js +5 -0
  50. package/dist/bin/chunks/chunk-CPKBPQ2C.js +3 -0
  51. package/dist/bin/chunks/chunk-DJAX3ZRG.js +8 -0
  52. package/dist/bin/chunks/chunk-DN2YCFOR.js +3 -0
  53. package/dist/bin/chunks/chunk-DYIBFLS3.js +17 -0
  54. package/dist/bin/chunks/chunk-DZAFUADN.js +36 -0
  55. package/dist/bin/chunks/chunk-F3UDTTI7.js +13 -0
  56. package/dist/bin/chunks/chunk-FHMIEBRM.js +6 -0
  57. package/dist/bin/chunks/chunk-FONAGXRJ.js +17 -0
  58. package/dist/bin/chunks/chunk-FPWHWWXO.js +8 -0
  59. package/dist/bin/chunks/chunk-FUT3X2GJ.js +9 -0
  60. package/dist/bin/chunks/chunk-G4AUMZUY.js +4 -0
  61. package/dist/bin/chunks/chunk-GA5TPRMF.js +34 -0
  62. package/dist/bin/chunks/chunk-GOWX7VPU.js +7 -0
  63. package/dist/bin/chunks/chunk-GQKQEK5N.js +11 -0
  64. package/dist/bin/chunks/chunk-GR4ZHKXI.js +3 -0
  65. package/dist/bin/chunks/chunk-HDWHYM2T.js +18 -0
  66. package/dist/bin/chunks/chunk-HQ63MFHG.js +34 -0
  67. package/dist/bin/chunks/chunk-HW2VJKFH.js +4 -0
  68. package/dist/bin/chunks/chunk-HWI42GQO.js +7 -0
  69. package/dist/bin/chunks/chunk-HZGHQZSY.js +10 -0
  70. package/dist/bin/chunks/chunk-I4IRHQDW.js +3 -0
  71. package/dist/bin/chunks/chunk-I57EACSL.js +3 -0
  72. package/dist/bin/chunks/chunk-JELR4642.js +21 -0
  73. package/dist/bin/chunks/chunk-JQM3DKCH.js +12 -0
  74. package/dist/bin/chunks/chunk-K27FY3ES.js +3 -0
  75. package/dist/bin/chunks/chunk-KG2KXL4Y.js +3 -0
  76. package/dist/bin/chunks/chunk-KI54R2QB.js +3 -0
  77. package/dist/bin/chunks/chunk-KP2UH5CJ.js +22 -0
  78. package/dist/bin/chunks/chunk-KUMHQGUR.js +3 -0
  79. package/dist/bin/chunks/chunk-LE2XKKGQ.js +7 -0
  80. package/dist/bin/chunks/chunk-LJQIAFWS.js +5 -0
  81. package/dist/bin/chunks/chunk-LXFMIXGA.js +3 -0
  82. package/dist/bin/chunks/chunk-M7SIPZZZ.js +22 -0
  83. package/dist/bin/chunks/chunk-MF3GVFLC.js +11 -0
  84. package/dist/bin/chunks/chunk-MROECM42.js +3 -0
  85. package/dist/bin/chunks/chunk-MUFNRCMY.js +24 -0
  86. package/dist/bin/chunks/chunk-MVBK66TR.js +22 -0
  87. package/dist/bin/chunks/chunk-MYTNZ7MA.js +7 -0
  88. package/dist/bin/chunks/chunk-N26Y42L6.js +10 -0
  89. package/dist/bin/chunks/chunk-NE4R2FVV.js +5 -0
  90. package/dist/bin/chunks/chunk-NLU5LALY.js +37 -0
  91. package/dist/bin/chunks/chunk-NXUXZWS5.js +7 -0
  92. package/dist/bin/chunks/chunk-O2BCKSMK.js +3 -0
  93. package/dist/bin/chunks/chunk-OLEQNRKX.js +8 -0
  94. package/dist/bin/chunks/chunk-OUQKFRVR.js +6 -0
  95. package/dist/bin/chunks/chunk-OXLC2WWX.js +26 -0
  96. package/dist/bin/chunks/chunk-OYXHOZZ4.js +15 -0
  97. package/dist/bin/chunks/chunk-PBOVSFTJ.js +3 -0
  98. package/dist/bin/chunks/chunk-PPVF2N6C.js +3 -0
  99. package/dist/bin/chunks/chunk-PQ2INDRF.js +87 -0
  100. package/dist/bin/chunks/chunk-PXP4YYZA.js +13 -0
  101. package/dist/bin/chunks/chunk-PZQVSQX6.js +4 -0
  102. package/dist/bin/chunks/chunk-Q2GOPGDA.js +6 -0
  103. package/dist/bin/chunks/chunk-Q3LE3Y66.js +13 -0
  104. package/dist/bin/chunks/chunk-QES5OSUC.js +3 -0
  105. package/dist/bin/chunks/chunk-QFTZKD5O.js +13 -0
  106. package/dist/bin/chunks/chunk-QL33F2W6.js +8 -0
  107. package/dist/bin/chunks/chunk-QMPZXXEK.js +8 -0
  108. package/dist/bin/chunks/chunk-QYZN33JA.js +3 -0
  109. package/dist/bin/chunks/chunk-R2J5MJOM.js +20 -0
  110. package/dist/bin/chunks/chunk-RPUFEP5O.js +65 -0
  111. package/dist/bin/chunks/chunk-RVPTAYDS.js +4 -0
  112. package/dist/bin/chunks/chunk-SC5TEGMM.js +12 -0
  113. package/dist/bin/chunks/chunk-SDGPS6XI.js +10 -0
  114. package/dist/bin/chunks/chunk-TW2IJRUF.js +3 -0
  115. package/dist/bin/chunks/chunk-TYBXHT6W.js +10 -0
  116. package/dist/bin/chunks/chunk-V2XF3TTW.js +276 -0
  117. package/dist/bin/chunks/chunk-V4U26ZWL.js +16 -0
  118. package/dist/bin/chunks/chunk-VTAMGD42.js +3 -0
  119. package/dist/bin/chunks/chunk-WAJVRK5B.js +16 -0
  120. package/dist/bin/chunks/chunk-WEHA3JFD.js +3 -0
  121. package/dist/bin/chunks/chunk-WFHYGSLJ.js +6 -0
  122. package/dist/bin/chunks/chunk-WFVCEB5T.js +3 -0
  123. package/dist/bin/chunks/chunk-YERKK5B3.js +4 -0
  124. package/dist/bin/chunks/chunk-YIANER7Y.js +8 -0
  125. package/dist/bin/chunks/chunk-YJ5OCPSK.js +7 -0
  126. package/dist/bin/chunks/chunk-YOIFOOGX.js +9 -0
  127. package/dist/bin/chunks/chunk-YQEKKZTU.js +12 -0
  128. package/dist/bin/chunks/chunk-YUZRUF5F.js +10 -0
  129. package/dist/bin/chunks/chunk-ZMGLTHSU.js +15 -0
  130. package/dist/bin/chunks/clear-OE52K3TM.js +3 -0
  131. package/dist/bin/chunks/column-AJFK3TWF.js +3 -0
  132. package/dist/bin/chunks/comm-URDMZCXL.js +3 -0
  133. package/dist/bin/chunks/cp-OMVKM35F.js +3 -0
  134. package/dist/bin/chunks/curl-NHNZ46BU.js +31 -0
  135. package/dist/bin/chunks/cut-42X6363P.js +3 -0
  136. package/dist/bin/chunks/date-6MQGVWDY.js +3 -0
  137. package/dist/bin/chunks/diff-YXZZCUSQ.js +3 -0
  138. package/dist/bin/chunks/dirname-TPUFCYF6.js +3 -0
  139. package/dist/bin/chunks/dist-5MWO25Y4.js +141 -0
  140. package/dist/bin/chunks/du-LUFPVLNW.js +3 -0
  141. package/dist/bin/chunks/echo-NYDCCFWB.js +3 -0
  142. package/dist/bin/chunks/env-2TSVF4W7.js +3 -0
  143. package/dist/bin/chunks/expand-IQRKKT7D.js +3 -0
  144. package/dist/bin/chunks/expr-NNMDHOCN.js +3 -0
  145. package/dist/bin/chunks/file-4T64QNLS.js +3 -0
  146. package/dist/bin/chunks/find-AWH2KOY7.js +3 -0
  147. package/dist/bin/chunks/flag-coverage-J2ZHA465.js +3 -0
  148. package/dist/bin/chunks/fold-YEY7X54W.js +3 -0
  149. package/dist/bin/chunks/grep-CVU5V66H.js +3 -0
  150. package/dist/bin/chunks/gzip-FDPA6EKG.js +3 -0
  151. package/dist/bin/chunks/head-QKVY3SIO.js +3 -0
  152. package/dist/bin/chunks/help-HVIDHJ6M.js +3 -0
  153. package/dist/bin/chunks/history-3HAU45KT.js +3 -0
  154. package/dist/bin/chunks/hostname-2I76DUQL.js +3 -0
  155. package/dist/bin/chunks/html-to-markdown-XUMA42ZC.js +3 -0
  156. package/dist/bin/chunks/join-34DX7YK5.js +3 -0
  157. package/dist/bin/chunks/jq-V7OTAVU5.js +3 -0
  158. package/dist/bin/chunks/js-exec-DJQLXWCS.js +99 -0
  159. package/dist/bin/chunks/js-exec-worker.js +4809 -0
  160. package/dist/bin/chunks/ln-B35EKC2Q.js +3 -0
  161. package/dist/bin/chunks/ls-Q6ZZ6SQ2.js +3 -0
  162. package/dist/bin/chunks/md5sum-Z6KAYGDK.js +3 -0
  163. package/dist/bin/chunks/mkdir-74BP5NTG.js +3 -0
  164. package/dist/bin/chunks/mv-76LAHXFR.js +3 -0
  165. package/dist/bin/chunks/nl-4IZRRT7U.js +3 -0
  166. package/dist/bin/chunks/od-2GXD4D5K.js +3 -0
  167. package/dist/bin/chunks/paste-DWWA3JTW.js +3 -0
  168. package/dist/bin/chunks/printf-YXCSED2H.js +3 -0
  169. package/dist/bin/chunks/pwd-YKLNXWZI.js +3 -0
  170. package/dist/bin/chunks/python3-JCJHSX4Z.js +14 -0
  171. package/dist/bin/chunks/readlink-EHXJNW62.js +3 -0
  172. package/dist/bin/chunks/rev-CZTQCNOZ.js +3 -0
  173. package/dist/bin/chunks/rg-PXNKNIMY.js +3 -0
  174. package/dist/bin/chunks/rm-3PLW4O4B.js +3 -0
  175. package/dist/bin/chunks/rmdir-7ZIVFZJX.js +3 -0
  176. package/dist/bin/chunks/sed-4LVDFHIJ.js +3 -0
  177. package/dist/bin/chunks/seq-X2EAOGV5.js +3 -0
  178. package/dist/bin/chunks/sha1sum-CATBXX76.js +3 -0
  179. package/dist/bin/chunks/sha256sum-YGSNBVY3.js +3 -0
  180. package/dist/bin/chunks/sleep-DVFE2GSF.js +3 -0
  181. package/dist/bin/chunks/sort-HBOCBBJQ.js +3 -0
  182. package/dist/bin/chunks/split-ZNNNHKSP.js +3 -0
  183. package/dist/bin/chunks/sqlite3-KP42NNIY.js +3 -0
  184. package/dist/bin/chunks/sqlite3-worker.js +1928 -0
  185. package/dist/bin/chunks/stat-LROLDXHH.js +3 -0
  186. package/dist/bin/chunks/strings-CNUK76JL.js +3 -0
  187. package/dist/bin/chunks/tac-DG4BMYM5.js +3 -0
  188. package/dist/bin/chunks/tail-UOTUV25D.js +3 -0
  189. package/dist/bin/chunks/tar-7HGZIMZD.js +3 -0
  190. package/dist/bin/chunks/tee-L4HKV5PD.js +3 -0
  191. package/dist/bin/chunks/time-LF7BTSK5.js +3 -0
  192. package/dist/bin/chunks/timeout-YGFHQJKX.js +3 -0
  193. package/dist/bin/chunks/touch-TVQAUQOG.js +3 -0
  194. package/dist/bin/chunks/tr-PVFO6FRY.js +3 -0
  195. package/dist/bin/chunks/tree-ZGP6NPGS.js +3 -0
  196. package/dist/bin/chunks/true-KFTJGQLQ.js +3 -0
  197. package/dist/bin/chunks/unexpand-JPOQORZF.js +3 -0
  198. package/dist/bin/chunks/uniq-JMHDIJXT.js +3 -0
  199. package/dist/bin/chunks/wc-3KLVOCI2.js +3 -0
  200. package/dist/bin/chunks/which-4TPGVSBZ.js +3 -0
  201. package/dist/bin/chunks/whoami-B5HDVKW6.js +3 -0
  202. package/dist/bin/chunks/worker.js +3330 -0
  203. package/dist/bin/chunks/xan-WW53ETXT.js +3 -0
  204. package/dist/bin/chunks/xan-view-PD26QEFN.js +3 -0
  205. package/dist/bin/chunks/xargs-4AMMXFXL.js +3 -0
  206. package/dist/bin/chunks/yq-MYZOS2WN.js +3 -0
  207. package/dist/bin/just-bash.js +858 -0
  208. package/dist/bin/shell/chunks/alias-3R4G6HQY.js +3 -0
  209. package/dist/bin/shell/chunks/awk2-KO7ZE3P7.js +3 -0
  210. package/dist/bin/shell/chunks/base64-TQ5KOCNW.js +3 -0
  211. package/dist/bin/shell/chunks/basename-C4CRGDXP.js +3 -0
  212. package/dist/bin/shell/chunks/bash-CFCBBWVH.js +3 -0
  213. package/dist/bin/shell/chunks/cat-BQ7FQTN5.js +3 -0
  214. package/dist/bin/shell/chunks/chmod-WYYTXGVB.js +3 -0
  215. package/dist/bin/shell/chunks/chunk-23OI2XDJ.js +20 -0
  216. package/dist/bin/shell/chunks/chunk-2ETT4ELS.js +4 -0
  217. package/dist/bin/shell/chunks/chunk-2UV6ZFHK.js +4 -0
  218. package/dist/bin/shell/chunks/chunk-2YLY6FJA.js +10 -0
  219. package/dist/bin/shell/chunks/chunk-3FQBUEB6.js +3 -0
  220. package/dist/bin/shell/chunks/chunk-3MRB66F4.js +3 -0
  221. package/dist/bin/shell/chunks/chunk-3PCPQIUD.js +3 -0
  222. package/dist/bin/shell/chunks/chunk-42AMF6EE.js +3 -0
  223. package/dist/bin/shell/chunks/chunk-43E7AR6A.js +3 -0
  224. package/dist/bin/shell/chunks/chunk-45DUHCXR.js +7 -0
  225. package/dist/bin/shell/chunks/chunk-472JZJ2D.js +22 -0
  226. package/dist/bin/shell/chunks/chunk-47IFMQYS.js +3 -0
  227. package/dist/bin/shell/chunks/chunk-4JF56A3P.js +15 -0
  228. package/dist/bin/shell/chunks/chunk-5SKEZPTU.js +12 -0
  229. package/dist/bin/shell/chunks/chunk-67XYNGRV.js +9 -0
  230. package/dist/bin/shell/chunks/chunk-6ESRNSO7.js +7 -0
  231. package/dist/bin/shell/chunks/chunk-6KHZX4HU.js +12 -0
  232. package/dist/bin/shell/chunks/chunk-7FGDUBSN.js +14 -0
  233. package/dist/bin/shell/chunks/chunk-7JZKVC3F.js +2 -0
  234. package/dist/bin/shell/chunks/chunk-7PPAWLUI.js +12 -0
  235. package/dist/bin/shell/chunks/chunk-7PUOS2OO.js +143 -0
  236. package/dist/bin/shell/chunks/chunk-7VWOECJ3.js +101 -0
  237. package/dist/bin/shell/chunks/chunk-7WBCA2BB.js +3 -0
  238. package/dist/bin/shell/chunks/chunk-AGKL4LDL.js +4 -0
  239. package/dist/bin/shell/chunks/chunk-AI7JUA46.js +13 -0
  240. package/dist/bin/shell/chunks/chunk-AJF3OBTR.js +4 -0
  241. package/dist/bin/shell/chunks/chunk-B2DRBHGQ.js +3 -0
  242. package/dist/bin/shell/chunks/chunk-B2GCIQI2.js +16 -0
  243. package/dist/bin/shell/chunks/chunk-B6WWC6K3.js +9 -0
  244. package/dist/bin/shell/chunks/chunk-BIJXTWZ4.js +3 -0
  245. package/dist/bin/shell/chunks/chunk-CC2AQ6B7.js +15 -0
  246. package/dist/bin/shell/chunks/chunk-CL7IYCGG.js +20 -0
  247. package/dist/bin/shell/chunks/chunk-CMTQFWZK.js +5 -0
  248. package/dist/bin/shell/chunks/chunk-CPKBPQ2C.js +3 -0
  249. package/dist/bin/shell/chunks/chunk-DJAX3ZRG.js +8 -0
  250. package/dist/bin/shell/chunks/chunk-DN2YCFOR.js +3 -0
  251. package/dist/bin/shell/chunks/chunk-DYIBFLS3.js +17 -0
  252. package/dist/bin/shell/chunks/chunk-DZAFUADN.js +36 -0
  253. package/dist/bin/shell/chunks/chunk-F3UDTTI7.js +13 -0
  254. package/dist/bin/shell/chunks/chunk-FHMIEBRM.js +6 -0
  255. package/dist/bin/shell/chunks/chunk-FONAGXRJ.js +17 -0
  256. package/dist/bin/shell/chunks/chunk-FPWHWWXO.js +8 -0
  257. package/dist/bin/shell/chunks/chunk-FUT3X2GJ.js +9 -0
  258. package/dist/bin/shell/chunks/chunk-G4AUMZUY.js +4 -0
  259. package/dist/bin/shell/chunks/chunk-GA5TPRMF.js +34 -0
  260. package/dist/bin/shell/chunks/chunk-GOWX7VPU.js +7 -0
  261. package/dist/bin/shell/chunks/chunk-GQKQEK5N.js +11 -0
  262. package/dist/bin/shell/chunks/chunk-GR4ZHKXI.js +3 -0
  263. package/dist/bin/shell/chunks/chunk-HDWHYM2T.js +18 -0
  264. package/dist/bin/shell/chunks/chunk-HQ63MFHG.js +34 -0
  265. package/dist/bin/shell/chunks/chunk-HW2VJKFH.js +4 -0
  266. package/dist/bin/shell/chunks/chunk-HWI42GQO.js +7 -0
  267. package/dist/bin/shell/chunks/chunk-HZGHQZSY.js +10 -0
  268. package/dist/bin/shell/chunks/chunk-I4IRHQDW.js +3 -0
  269. package/dist/bin/shell/chunks/chunk-I57EACSL.js +3 -0
  270. package/dist/bin/shell/chunks/chunk-JELR4642.js +21 -0
  271. package/dist/bin/shell/chunks/chunk-JQM3DKCH.js +12 -0
  272. package/dist/bin/shell/chunks/chunk-K27FY3ES.js +3 -0
  273. package/dist/bin/shell/chunks/chunk-KG2KXL4Y.js +3 -0
  274. package/dist/bin/shell/chunks/chunk-KI54R2QB.js +3 -0
  275. package/dist/bin/shell/chunks/chunk-KP2UH5CJ.js +22 -0
  276. package/dist/bin/shell/chunks/chunk-KUMHQGUR.js +3 -0
  277. package/dist/bin/shell/chunks/chunk-LE2XKKGQ.js +7 -0
  278. package/dist/bin/shell/chunks/chunk-LJQIAFWS.js +5 -0
  279. package/dist/bin/shell/chunks/chunk-LXFMIXGA.js +3 -0
  280. package/dist/bin/shell/chunks/chunk-M7SIPZZZ.js +22 -0
  281. package/dist/bin/shell/chunks/chunk-MF3GVFLC.js +11 -0
  282. package/dist/bin/shell/chunks/chunk-MROECM42.js +3 -0
  283. package/dist/bin/shell/chunks/chunk-MUFNRCMY.js +24 -0
  284. package/dist/bin/shell/chunks/chunk-MVBK66TR.js +22 -0
  285. package/dist/bin/shell/chunks/chunk-MYTNZ7MA.js +7 -0
  286. package/dist/bin/shell/chunks/chunk-N26Y42L6.js +10 -0
  287. package/dist/bin/shell/chunks/chunk-NE4R2FVV.js +5 -0
  288. package/dist/bin/shell/chunks/chunk-NLU5LALY.js +37 -0
  289. package/dist/bin/shell/chunks/chunk-NXUXZWS5.js +7 -0
  290. package/dist/bin/shell/chunks/chunk-O2BCKSMK.js +3 -0
  291. package/dist/bin/shell/chunks/chunk-OLEQNRKX.js +8 -0
  292. package/dist/bin/shell/chunks/chunk-OUQKFRVR.js +6 -0
  293. package/dist/bin/shell/chunks/chunk-OXLC2WWX.js +26 -0
  294. package/dist/bin/shell/chunks/chunk-OYXHOZZ4.js +15 -0
  295. package/dist/bin/shell/chunks/chunk-PBOVSFTJ.js +3 -0
  296. package/dist/bin/shell/chunks/chunk-PPVF2N6C.js +3 -0
  297. package/dist/bin/shell/chunks/chunk-PQ2INDRF.js +87 -0
  298. package/dist/bin/shell/chunks/chunk-PXP4YYZA.js +13 -0
  299. package/dist/bin/shell/chunks/chunk-PZQVSQX6.js +4 -0
  300. package/dist/bin/shell/chunks/chunk-Q2GOPGDA.js +6 -0
  301. package/dist/bin/shell/chunks/chunk-Q3LE3Y66.js +13 -0
  302. package/dist/bin/shell/chunks/chunk-QES5OSUC.js +3 -0
  303. package/dist/bin/shell/chunks/chunk-QFTZKD5O.js +13 -0
  304. package/dist/bin/shell/chunks/chunk-QL33F2W6.js +8 -0
  305. package/dist/bin/shell/chunks/chunk-QMPZXXEK.js +8 -0
  306. package/dist/bin/shell/chunks/chunk-QYZN33JA.js +3 -0
  307. package/dist/bin/shell/chunks/chunk-R2J5MJOM.js +20 -0
  308. package/dist/bin/shell/chunks/chunk-RPUFEP5O.js +65 -0
  309. package/dist/bin/shell/chunks/chunk-RVPTAYDS.js +4 -0
  310. package/dist/bin/shell/chunks/chunk-SC5TEGMM.js +12 -0
  311. package/dist/bin/shell/chunks/chunk-SDGPS6XI.js +10 -0
  312. package/dist/bin/shell/chunks/chunk-TW2IJRUF.js +3 -0
  313. package/dist/bin/shell/chunks/chunk-TYBXHT6W.js +10 -0
  314. package/dist/bin/shell/chunks/chunk-V2XF3TTW.js +276 -0
  315. package/dist/bin/shell/chunks/chunk-V4U26ZWL.js +16 -0
  316. package/dist/bin/shell/chunks/chunk-VTAMGD42.js +3 -0
  317. package/dist/bin/shell/chunks/chunk-WAJVRK5B.js +16 -0
  318. package/dist/bin/shell/chunks/chunk-WEHA3JFD.js +3 -0
  319. package/dist/bin/shell/chunks/chunk-WFHYGSLJ.js +6 -0
  320. package/dist/bin/shell/chunks/chunk-WFVCEB5T.js +3 -0
  321. package/dist/bin/shell/chunks/chunk-YERKK5B3.js +4 -0
  322. package/dist/bin/shell/chunks/chunk-YIANER7Y.js +8 -0
  323. package/dist/bin/shell/chunks/chunk-YJ5OCPSK.js +7 -0
  324. package/dist/bin/shell/chunks/chunk-YOIFOOGX.js +9 -0
  325. package/dist/bin/shell/chunks/chunk-YQEKKZTU.js +12 -0
  326. package/dist/bin/shell/chunks/chunk-YUZRUF5F.js +10 -0
  327. package/dist/bin/shell/chunks/chunk-ZMGLTHSU.js +15 -0
  328. package/dist/bin/shell/chunks/clear-OE52K3TM.js +3 -0
  329. package/dist/bin/shell/chunks/column-AJFK3TWF.js +3 -0
  330. package/dist/bin/shell/chunks/comm-URDMZCXL.js +3 -0
  331. package/dist/bin/shell/chunks/cp-OMVKM35F.js +3 -0
  332. package/dist/bin/shell/chunks/curl-NHNZ46BU.js +31 -0
  333. package/dist/bin/shell/chunks/cut-42X6363P.js +3 -0
  334. package/dist/bin/shell/chunks/date-6MQGVWDY.js +3 -0
  335. package/dist/bin/shell/chunks/diff-YXZZCUSQ.js +3 -0
  336. package/dist/bin/shell/chunks/dirname-TPUFCYF6.js +3 -0
  337. package/dist/bin/shell/chunks/dist-5MWO25Y4.js +141 -0
  338. package/dist/bin/shell/chunks/du-LUFPVLNW.js +3 -0
  339. package/dist/bin/shell/chunks/echo-NYDCCFWB.js +3 -0
  340. package/dist/bin/shell/chunks/env-2TSVF4W7.js +3 -0
  341. package/dist/bin/shell/chunks/expand-IQRKKT7D.js +3 -0
  342. package/dist/bin/shell/chunks/expr-NNMDHOCN.js +3 -0
  343. package/dist/bin/shell/chunks/file-4T64QNLS.js +3 -0
  344. package/dist/bin/shell/chunks/find-AWH2KOY7.js +3 -0
  345. package/dist/bin/shell/chunks/flag-coverage-J2ZHA465.js +3 -0
  346. package/dist/bin/shell/chunks/fold-YEY7X54W.js +3 -0
  347. package/dist/bin/shell/chunks/grep-CVU5V66H.js +3 -0
  348. package/dist/bin/shell/chunks/gzip-FDPA6EKG.js +3 -0
  349. package/dist/bin/shell/chunks/head-QKVY3SIO.js +3 -0
  350. package/dist/bin/shell/chunks/help-HVIDHJ6M.js +3 -0
  351. package/dist/bin/shell/chunks/history-3HAU45KT.js +3 -0
  352. package/dist/bin/shell/chunks/hostname-2I76DUQL.js +3 -0
  353. package/dist/bin/shell/chunks/html-to-markdown-XUMA42ZC.js +3 -0
  354. package/dist/bin/shell/chunks/join-34DX7YK5.js +3 -0
  355. package/dist/bin/shell/chunks/jq-V7OTAVU5.js +3 -0
  356. package/dist/bin/shell/chunks/js-exec-DJQLXWCS.js +99 -0
  357. package/dist/bin/shell/chunks/ln-B35EKC2Q.js +3 -0
  358. package/dist/bin/shell/chunks/ls-Q6ZZ6SQ2.js +3 -0
  359. package/dist/bin/shell/chunks/md5sum-Z6KAYGDK.js +3 -0
  360. package/dist/bin/shell/chunks/mkdir-74BP5NTG.js +3 -0
  361. package/dist/bin/shell/chunks/mv-76LAHXFR.js +3 -0
  362. package/dist/bin/shell/chunks/nl-4IZRRT7U.js +3 -0
  363. package/dist/bin/shell/chunks/od-2GXD4D5K.js +3 -0
  364. package/dist/bin/shell/chunks/paste-DWWA3JTW.js +3 -0
  365. package/dist/bin/shell/chunks/printf-YXCSED2H.js +3 -0
  366. package/dist/bin/shell/chunks/pwd-YKLNXWZI.js +3 -0
  367. package/dist/bin/shell/chunks/python3-JCJHSX4Z.js +14 -0
  368. package/dist/bin/shell/chunks/readlink-EHXJNW62.js +3 -0
  369. package/dist/bin/shell/chunks/rev-CZTQCNOZ.js +3 -0
  370. package/dist/bin/shell/chunks/rg-PXNKNIMY.js +3 -0
  371. package/dist/bin/shell/chunks/rm-3PLW4O4B.js +3 -0
  372. package/dist/bin/shell/chunks/rmdir-7ZIVFZJX.js +3 -0
  373. package/dist/bin/shell/chunks/sed-4LVDFHIJ.js +3 -0
  374. package/dist/bin/shell/chunks/seq-X2EAOGV5.js +3 -0
  375. package/dist/bin/shell/chunks/sha1sum-CATBXX76.js +3 -0
  376. package/dist/bin/shell/chunks/sha256sum-YGSNBVY3.js +3 -0
  377. package/dist/bin/shell/chunks/sleep-DVFE2GSF.js +3 -0
  378. package/dist/bin/shell/chunks/sort-HBOCBBJQ.js +3 -0
  379. package/dist/bin/shell/chunks/split-ZNNNHKSP.js +3 -0
  380. package/dist/bin/shell/chunks/sqlite3-KP42NNIY.js +3 -0
  381. package/dist/bin/shell/chunks/stat-LROLDXHH.js +3 -0
  382. package/dist/bin/shell/chunks/strings-CNUK76JL.js +3 -0
  383. package/dist/bin/shell/chunks/tac-DG4BMYM5.js +3 -0
  384. package/dist/bin/shell/chunks/tail-UOTUV25D.js +3 -0
  385. package/dist/bin/shell/chunks/tar-7HGZIMZD.js +3 -0
  386. package/dist/bin/shell/chunks/tee-L4HKV5PD.js +3 -0
  387. package/dist/bin/shell/chunks/time-LF7BTSK5.js +3 -0
  388. package/dist/bin/shell/chunks/timeout-YGFHQJKX.js +3 -0
  389. package/dist/bin/shell/chunks/touch-TVQAUQOG.js +3 -0
  390. package/dist/bin/shell/chunks/tr-PVFO6FRY.js +3 -0
  391. package/dist/bin/shell/chunks/tree-ZGP6NPGS.js +3 -0
  392. package/dist/bin/shell/chunks/true-KFTJGQLQ.js +3 -0
  393. package/dist/bin/shell/chunks/unexpand-JPOQORZF.js +3 -0
  394. package/dist/bin/shell/chunks/uniq-JMHDIJXT.js +3 -0
  395. package/dist/bin/shell/chunks/wc-3KLVOCI2.js +3 -0
  396. package/dist/bin/shell/chunks/which-4TPGVSBZ.js +3 -0
  397. package/dist/bin/shell/chunks/whoami-B5HDVKW6.js +3 -0
  398. package/dist/bin/shell/chunks/xan-WW53ETXT.js +3 -0
  399. package/dist/bin/shell/chunks/xan-view-PD26QEFN.js +3 -0
  400. package/dist/bin/shell/chunks/xargs-4AMMXFXL.js +3 -0
  401. package/dist/bin/shell/chunks/yq-MYZOS2WN.js +3 -0
  402. package/dist/bin/shell/shell.js +834 -0
  403. package/dist/bounded-builder.d.ts +37 -0
  404. package/dist/browser.d.ts +23 -0
  405. package/dist/bundle/browser.js +1576 -0
  406. package/dist/bundle/chunks/alias-T5TO5GWK.js +2 -0
  407. package/dist/bundle/chunks/awk2-W6BNZEJN.js +2 -0
  408. package/dist/bundle/chunks/base64-MHVQ5XHI.js +2 -0
  409. package/dist/bundle/chunks/basename-SJZQ5W65.js +2 -0
  410. package/dist/bundle/chunks/bash-HIEWVHJ2.js +2 -0
  411. package/dist/bundle/chunks/cat-VZBWBIJB.js +2 -0
  412. package/dist/bundle/chunks/chmod-WM2JFFQC.js +2 -0
  413. package/dist/bundle/chunks/chunk-24NLAR7R.js +36 -0
  414. package/dist/bundle/chunks/chunk-26GP3ACY.js +12 -0
  415. package/dist/bundle/chunks/chunk-2KNTH3KH.js +9 -0
  416. package/dist/bundle/chunks/chunk-2SMD2AUA.js +3 -0
  417. package/dist/bundle/chunks/chunk-2TSZPVPI.js +21 -0
  418. package/dist/bundle/chunks/chunk-2VWG4LDT.js +11 -0
  419. package/dist/bundle/chunks/chunk-3WASQYTF.js +11 -0
  420. package/dist/bundle/chunks/chunk-44YCJWNC.js +6 -0
  421. package/dist/bundle/chunks/chunk-4EDQZIAN.js +5 -0
  422. package/dist/bundle/chunks/chunk-4MJ7VJG4.js +21 -0
  423. package/dist/bundle/chunks/chunk-4MZPEZTU.js +3 -0
  424. package/dist/bundle/chunks/chunk-57LGFT4S.js +3 -0
  425. package/dist/bundle/chunks/chunk-5I5U6IYI.js +142 -0
  426. package/dist/bundle/chunks/chunk-6DDRR56B.js +33 -0
  427. package/dist/bundle/chunks/chunk-6QF3PCMO.js +8 -0
  428. package/dist/bundle/chunks/chunk-6RK4AAB7.js +21 -0
  429. package/dist/bundle/chunks/chunk-6WGIZV3E.js +13 -0
  430. package/dist/bundle/chunks/chunk-73JQKNZT.js +33 -0
  431. package/dist/bundle/chunks/chunk-7AISL3XV.js +12 -0
  432. package/dist/bundle/chunks/chunk-7EUWTCWK.js +2 -0
  433. package/dist/bundle/chunks/chunk-7IJWBG4I.js +2 -0
  434. package/dist/bundle/chunks/chunk-7O2RDO2R.js +14 -0
  435. package/dist/bundle/chunks/chunk-A4R2GWRF.js +9 -0
  436. package/dist/bundle/chunks/chunk-AGH5UJJI.js +4 -0
  437. package/dist/bundle/chunks/chunk-ANCQ4SCV.js +2 -0
  438. package/dist/bundle/chunks/chunk-ASE6AYV3.js +17 -0
  439. package/dist/bundle/chunks/chunk-AYSZ5MAE.js +2 -0
  440. package/dist/bundle/chunks/chunk-BKUWXPEM.js +2 -0
  441. package/dist/bundle/chunks/chunk-BRJERIF4.js +2 -0
  442. package/dist/bundle/chunks/chunk-DAKEIWT3.js +21 -0
  443. package/dist/bundle/chunks/chunk-DLL7UR66.js +2 -0
  444. package/dist/bundle/chunks/chunk-DMWNBCXJ.js +10 -0
  445. package/dist/bundle/chunks/chunk-DVSA72LH.js +2 -0
  446. package/dist/bundle/chunks/chunk-EJFBIRMD.js +6 -0
  447. package/dist/bundle/chunks/chunk-EZNS4GF7.js +9 -0
  448. package/dist/bundle/chunks/chunk-F6XU52K3.js +35 -0
  449. package/dist/bundle/chunks/chunk-FHC24QSK.js +7 -0
  450. package/dist/bundle/chunks/chunk-FIMF2TLE.js +20 -0
  451. package/dist/bundle/chunks/chunk-FOCWZZDE.js +2 -0
  452. package/dist/bundle/chunks/chunk-FQUVK4Q5.js +11 -0
  453. package/dist/bundle/chunks/chunk-FSJ6TTCC.js +19 -0
  454. package/dist/bundle/chunks/chunk-FT6ODGOU.js +2 -0
  455. package/dist/bundle/chunks/chunk-FTET43KM.js +2 -0
  456. package/dist/bundle/chunks/chunk-FX4RBUYU.js +5 -0
  457. package/dist/bundle/chunks/chunk-FZRQOL3C.js +7 -0
  458. package/dist/bundle/chunks/chunk-FZZL53S2.js +275 -0
  459. package/dist/bundle/chunks/chunk-GN6CQ3J4.js +2 -0
  460. package/dist/bundle/chunks/chunk-HDRAUQK2.js +2 -0
  461. package/dist/bundle/chunks/chunk-HP7HWZ2S.js +15 -0
  462. package/dist/bundle/chunks/chunk-HRIJVWZS.js +14 -0
  463. package/dist/bundle/chunks/chunk-HXWB4Z5X.js +7 -0
  464. package/dist/bundle/chunks/chunk-ICLA3MUR.js +3 -0
  465. package/dist/bundle/chunks/chunk-IXFQXNL4.js +7 -0
  466. package/dist/bundle/chunks/chunk-KIGPB52X.js +2 -0
  467. package/dist/bundle/chunks/chunk-L2UW7DWF.js +2 -0
  468. package/dist/bundle/chunks/chunk-LI6PTSPD.js +9 -0
  469. package/dist/bundle/chunks/chunk-LPJEKUCB.js +8 -0
  470. package/dist/bundle/chunks/chunk-LSLPJOYM.js +3 -0
  471. package/dist/bundle/chunks/chunk-LVDUF74R.js +7 -0
  472. package/dist/bundle/chunks/chunk-MLIO3BK2.js +7 -0
  473. package/dist/bundle/chunks/chunk-MQKGGNPS.js +16 -0
  474. package/dist/bundle/chunks/chunk-N3A4JVFJ.js +2 -0
  475. package/dist/bundle/chunks/chunk-NBNI7G66.js +8 -0
  476. package/dist/bundle/chunks/chunk-NCUTH6QL.js +2 -0
  477. package/dist/bundle/chunks/chunk-OQ7C4FYO.js +2 -0
  478. package/dist/bundle/chunks/chunk-P57S6Z6R.js +6 -0
  479. package/dist/bundle/chunks/chunk-PCPW54JH.js +7 -0
  480. package/dist/bundle/chunks/chunk-PJM5C3HZ.js +25 -0
  481. package/dist/bundle/chunks/chunk-PPEXVPHR.js +19 -0
  482. package/dist/bundle/chunks/chunk-Q4JSJ3KQ.js +4 -0
  483. package/dist/bundle/chunks/chunk-QAYAQNCG.js +23 -0
  484. package/dist/bundle/chunks/chunk-QHDBQA5N.js +9 -0
  485. package/dist/bundle/chunks/chunk-QIQMJJZ4.js +4 -0
  486. package/dist/bundle/chunks/chunk-QJ7OXJAZ.js +6 -0
  487. package/dist/bundle/chunks/chunk-QJFYYEFV.js +11 -0
  488. package/dist/bundle/chunks/chunk-R2FBRMDU.js +14 -0
  489. package/dist/bundle/chunks/chunk-ROAWFE6V.js +5 -0
  490. package/dist/bundle/chunks/chunk-RPKJJFGZ.js +14 -0
  491. package/dist/bundle/chunks/chunk-S3ENGQML.js +15 -0
  492. package/dist/bundle/chunks/chunk-SBBYKIYU.js +3 -0
  493. package/dist/bundle/chunks/chunk-SGX4WOAM.js +2 -0
  494. package/dist/bundle/chunks/chunk-SHKOQWO4.js +3 -0
  495. package/dist/bundle/chunks/chunk-SIOONII3.js +2 -0
  496. package/dist/bundle/chunks/chunk-STHBFACM.js +1 -0
  497. package/dist/bundle/chunks/chunk-SX2HC7SO.js +2 -0
  498. package/dist/bundle/chunks/chunk-T6DNSPYO.js +100 -0
  499. package/dist/bundle/chunks/chunk-TBVD66LC.js +10 -0
  500. package/dist/bundle/chunks/chunk-TDD4NFYE.js +2 -0
  501. package/dist/bundle/chunks/chunk-TVCZIH6M.js +8 -0
  502. package/dist/bundle/chunks/chunk-U4K5ZDWK.js +9 -0
  503. package/dist/bundle/chunks/chunk-UC76ZOWM.js +15 -0
  504. package/dist/bundle/chunks/chunk-UIJUTQPH.js +3 -0
  505. package/dist/bundle/chunks/chunk-ULXTDFQC.js +2 -0
  506. package/dist/bundle/chunks/chunk-UTKGYVUZ.js +7 -0
  507. package/dist/bundle/chunks/chunk-UUIYAOD4.js +2 -0
  508. package/dist/bundle/chunks/chunk-VJ6UXG2R.js +64 -0
  509. package/dist/bundle/chunks/chunk-W2Z6LYL6.js +11 -0
  510. package/dist/bundle/chunks/chunk-W5DWRFSU.js +2 -0
  511. package/dist/bundle/chunks/chunk-WN54B5NQ.js +12 -0
  512. package/dist/bundle/chunks/chunk-WNH3HOQA.js +2 -0
  513. package/dist/bundle/chunks/chunk-WXPNKIIH.js +2 -0
  514. package/dist/bundle/chunks/chunk-WZQNMEQW.js +2 -0
  515. package/dist/bundle/chunks/chunk-XV2V56NQ.js +12 -0
  516. package/dist/bundle/chunks/chunk-XVSR5HHH.js +6 -0
  517. package/dist/bundle/chunks/chunk-XXBIOG4R.js +5 -0
  518. package/dist/bundle/chunks/chunk-Y62SXZKJ.js +12 -0
  519. package/dist/bundle/chunks/chunk-YEYSCLSJ.js +3 -0
  520. package/dist/bundle/chunks/chunk-YJKHREBZ.js +11 -0
  521. package/dist/bundle/chunks/chunk-YUSFCOM7.js +2 -0
  522. package/dist/bundle/chunks/chunk-ZBUZKIPX.js +6 -0
  523. package/dist/bundle/chunks/chunk-ZDPFA4L3.js +6 -0
  524. package/dist/bundle/chunks/chunk-ZT3WF5R7.js +16 -0
  525. package/dist/bundle/chunks/chunk-ZXFELXJH.js +6 -0
  526. package/dist/bundle/chunks/clear-KPIUNI6K.js +2 -0
  527. package/dist/bundle/chunks/column-QJI65SH2.js +2 -0
  528. package/dist/bundle/chunks/comm-DTWKU2MC.js +2 -0
  529. package/dist/bundle/chunks/cp-2KZIPZJS.js +2 -0
  530. package/dist/bundle/chunks/curl-K4WT7UPN.js +30 -0
  531. package/dist/bundle/chunks/cut-FMDNVWQN.js +2 -0
  532. package/dist/bundle/chunks/date-7OEDRA27.js +2 -0
  533. package/dist/bundle/chunks/diff-CSARC7WF.js +2 -0
  534. package/dist/bundle/chunks/dirname-Z2ZMOOW2.js +2 -0
  535. package/dist/bundle/chunks/du-7AZCLKR6.js +2 -0
  536. package/dist/bundle/chunks/echo-PLLZYM2L.js +2 -0
  537. package/dist/bundle/chunks/env-VUUMB47B.js +2 -0
  538. package/dist/bundle/chunks/expand-J3VOSOMK.js +2 -0
  539. package/dist/bundle/chunks/expr-XSBELPAC.js +2 -0
  540. package/dist/bundle/chunks/file-URNAD6FQ.js +2 -0
  541. package/dist/bundle/chunks/find-END3EAHV.js +2 -0
  542. package/dist/bundle/chunks/flag-coverage-DPSAPFXA.js +2 -0
  543. package/dist/bundle/chunks/fold-QJBPHRFJ.js +2 -0
  544. package/dist/bundle/chunks/grep-4AYF3A5J.js +2 -0
  545. package/dist/bundle/chunks/gzip-RQOBR22H.js +2 -0
  546. package/dist/bundle/chunks/head-6UIPFWVJ.js +2 -0
  547. package/dist/bundle/chunks/help-QDDMBDU7.js +2 -0
  548. package/dist/bundle/chunks/history-3N762S3K.js +2 -0
  549. package/dist/bundle/chunks/hostname-CESD3CQR.js +2 -0
  550. package/dist/bundle/chunks/html-to-markdown-PE6BPRPA.js +2 -0
  551. package/dist/bundle/chunks/join-C2B6NGXH.js +2 -0
  552. package/dist/bundle/chunks/jq-NY7PCVMH.js +2 -0
  553. package/dist/bundle/chunks/js-exec-XKF2B7C3.js +98 -0
  554. package/dist/bundle/chunks/js-exec-worker.js +4809 -0
  555. package/dist/bundle/chunks/ln-OPY2ZVGQ.js +2 -0
  556. package/dist/bundle/chunks/ls-ZPXGZX63.js +2 -0
  557. package/dist/bundle/chunks/md5sum-JEDX55KS.js +2 -0
  558. package/dist/bundle/chunks/mkdir-WDDKK2P3.js +2 -0
  559. package/dist/bundle/chunks/mv-ZF6UBVRB.js +2 -0
  560. package/dist/bundle/chunks/nl-IELOWYJG.js +2 -0
  561. package/dist/bundle/chunks/od-Z4AIL3P4.js +2 -0
  562. package/dist/bundle/chunks/paste-ZNHNSRBW.js +2 -0
  563. package/dist/bundle/chunks/printf-B2NSYQ3N.js +2 -0
  564. package/dist/bundle/chunks/pwd-76BPYV5F.js +2 -0
  565. package/dist/bundle/chunks/python3-F5S5TYGS.js +13 -0
  566. package/dist/bundle/chunks/readlink-U5OM5A3M.js +2 -0
  567. package/dist/bundle/chunks/rev-EPOS3MFH.js +2 -0
  568. package/dist/bundle/chunks/rg-NAMXBYKS.js +2 -0
  569. package/dist/bundle/chunks/rm-JQ4GDKDD.js +2 -0
  570. package/dist/bundle/chunks/rmdir-YJKPQVCK.js +2 -0
  571. package/dist/bundle/chunks/sed-LIRH26EA.js +2 -0
  572. package/dist/bundle/chunks/seq-B6KDLMYQ.js +2 -0
  573. package/dist/bundle/chunks/sha1sum-BLPZJ6MP.js +2 -0
  574. package/dist/bundle/chunks/sha256sum-VJZ4PHQ4.js +2 -0
  575. package/dist/bundle/chunks/sleep-PPRBTSVR.js +2 -0
  576. package/dist/bundle/chunks/sort-CB5GO7XH.js +2 -0
  577. package/dist/bundle/chunks/split-JICLAMP6.js +2 -0
  578. package/dist/bundle/chunks/sqlite3-4EZ4GXVD.js +2 -0
  579. package/dist/bundle/chunks/sqlite3-worker.js +1928 -0
  580. package/dist/bundle/chunks/stat-LXFZND2P.js +2 -0
  581. package/dist/bundle/chunks/strings-VLFTYX2Z.js +2 -0
  582. package/dist/bundle/chunks/tac-YXC4HBTR.js +2 -0
  583. package/dist/bundle/chunks/tail-UBGSN4JF.js +2 -0
  584. package/dist/bundle/chunks/tar-B72KU357.js +2 -0
  585. package/dist/bundle/chunks/tee-OOWSWHRQ.js +2 -0
  586. package/dist/bundle/chunks/time-NERE2JJ2.js +2 -0
  587. package/dist/bundle/chunks/timeout-C6WDYPLV.js +2 -0
  588. package/dist/bundle/chunks/touch-W4DF6Z4T.js +2 -0
  589. package/dist/bundle/chunks/tr-UI2LA3GA.js +2 -0
  590. package/dist/bundle/chunks/tree-7OOL2MH6.js +2 -0
  591. package/dist/bundle/chunks/true-QUBPEGGU.js +2 -0
  592. package/dist/bundle/chunks/unexpand-YD5BWFH4.js +2 -0
  593. package/dist/bundle/chunks/uniq-PAEPA27E.js +2 -0
  594. package/dist/bundle/chunks/wc-7WVM7GV4.js +2 -0
  595. package/dist/bundle/chunks/which-UWVKETYW.js +2 -0
  596. package/dist/bundle/chunks/whoami-KR6E7UIR.js +2 -0
  597. package/dist/bundle/chunks/worker.js +3330 -0
  598. package/dist/bundle/chunks/xan-UIGVJCMA.js +2 -0
  599. package/dist/bundle/chunks/xan-view-FOCYCKZQ.js +2 -0
  600. package/dist/bundle/chunks/xargs-VQEXRD3C.js +2 -0
  601. package/dist/bundle/chunks/yq-FGNXZCGX.js +2 -0
  602. package/dist/bundle/index.cjs +2237 -0
  603. package/dist/bundle/index.js +809 -0
  604. package/dist/commands/alias/alias.d.ts +6 -0
  605. package/dist/commands/awk/ast.d.ts +202 -0
  606. package/dist/commands/awk/awk2.d.ts +9 -0
  607. package/dist/commands/awk/builtins.d.ts +17 -0
  608. package/dist/commands/awk/interpreter/context.d.ts +88 -0
  609. package/dist/commands/awk/interpreter/expressions.d.ts +17 -0
  610. package/dist/commands/awk/interpreter/fields.d.ts +25 -0
  611. package/dist/commands/awk/interpreter/index.d.ts +8 -0
  612. package/dist/commands/awk/interpreter/interpreter.d.ts +54 -0
  613. package/dist/commands/awk/interpreter/statements.d.ts +11 -0
  614. package/dist/commands/awk/interpreter/type-coercion.d.ts +32 -0
  615. package/dist/commands/awk/interpreter/types.d.ts +13 -0
  616. package/dist/commands/awk/interpreter/variables.d.ts +35 -0
  617. package/dist/commands/awk/lexer.d.ts +101 -0
  618. package/dist/commands/awk/parser2-print.d.ts +38 -0
  619. package/dist/commands/awk/parser2.d.ts +96 -0
  620. package/dist/commands/base64/base64.d.ts +7 -0
  621. package/dist/commands/basename/basename.d.ts +4 -0
  622. package/dist/commands/bash/bash.d.ts +6 -0
  623. package/dist/commands/browser-excluded.d.ts +16 -0
  624. package/dist/commands/cat/cat.d.ts +4 -0
  625. package/dist/commands/chmod/chmod.d.ts +4 -0
  626. package/dist/commands/clear/clear.d.ts +4 -0
  627. package/dist/commands/column/column.d.ts +11 -0
  628. package/dist/commands/comm/comm.d.ts +12 -0
  629. package/dist/commands/compression/codec-budget.d.ts +35 -0
  630. package/dist/commands/cp/cp.d.ts +4 -0
  631. package/dist/commands/curl/curl.d.ts +8 -0
  632. package/dist/commands/curl/form.d.ts +23 -0
  633. package/dist/commands/curl/help.d.ts +9 -0
  634. package/dist/commands/curl/parse.d.ts +9 -0
  635. package/dist/commands/curl/response-formatting.d.ts +20 -0
  636. package/dist/commands/curl/types.d.ts +70 -0
  637. package/dist/commands/cut/cut.d.ts +4 -0
  638. package/dist/commands/date/date.d.ts +7 -0
  639. package/dist/commands/diff/diff.d.ts +7 -0
  640. package/dist/commands/dirname/dirname.d.ts +4 -0
  641. package/dist/commands/du/du.d.ts +4 -0
  642. package/dist/commands/duration.d.ts +5 -0
  643. package/dist/commands/echo/echo.d.ts +4 -0
  644. package/dist/commands/env/env.d.ts +6 -0
  645. package/dist/commands/expand/expand.d.ts +12 -0
  646. package/dist/commands/expand/unexpand.d.ts +12 -0
  647. package/dist/commands/expr/expr.d.ts +9 -0
  648. package/dist/commands/file/file.d.ts +9 -0
  649. package/dist/commands/find/find.d.ts +4 -0
  650. package/dist/commands/find/matcher.d.ts +53 -0
  651. package/dist/commands/find/parser.d.ts +2 -0
  652. package/dist/commands/find/types.d.ts +89 -0
  653. package/dist/commands/flag-coverage.d.ts +2 -0
  654. package/dist/commands/fold/fold.d.ts +12 -0
  655. package/dist/commands/format-mode.d.ts +4 -0
  656. package/dist/commands/fuzz-flags-types.d.ts +17 -0
  657. package/dist/commands/fuzz-flags.d.ts +8 -0
  658. package/dist/commands/grep/grep.d.ts +8 -0
  659. package/dist/commands/gzip/gzip.d.ts +13 -0
  660. package/dist/commands/head/head-tail-shared.d.ts +38 -0
  661. package/dist/commands/head/head.d.ts +4 -0
  662. package/dist/commands/help/help.d.ts +4 -0
  663. package/dist/commands/help.d.ts +16 -0
  664. package/dist/commands/history/history.d.ts +4 -0
  665. package/dist/commands/hostname/hostname.d.ts +11 -0
  666. package/dist/commands/html-to-markdown/html-to-markdown.d.ts +9 -0
  667. package/dist/commands/join/join.d.ts +12 -0
  668. package/dist/commands/jq/jq.d.ts +9 -0
  669. package/dist/commands/js-exec/fetch-polyfill.d.ts +6 -0
  670. package/dist/commands/js-exec/js-exec-worker.d.ts +33 -0
  671. package/dist/commands/js-exec/js-exec.d.ts +13 -0
  672. package/dist/commands/js-exec/module-shims.d.ts +29 -0
  673. package/dist/commands/js-exec/path-polyfill.d.ts +6 -0
  674. package/dist/commands/ln/ln.d.ts +4 -0
  675. package/dist/commands/ls/ls.d.ts +4 -0
  676. package/dist/commands/md5sum/checksum.d.ts +7 -0
  677. package/dist/commands/md5sum/md5sum.d.ts +4 -0
  678. package/dist/commands/md5sum/sha1sum.d.ts +4 -0
  679. package/dist/commands/md5sum/sha256sum.d.ts +4 -0
  680. package/dist/commands/mkdir/mkdir.d.ts +4 -0
  681. package/dist/commands/mv/mv.d.ts +4 -0
  682. package/dist/commands/nl/nl.d.ts +12 -0
  683. package/dist/commands/od/od.d.ts +12 -0
  684. package/dist/commands/paste/paste.d.ts +4 -0
  685. package/dist/commands/printf/escapes.d.ts +27 -0
  686. package/dist/commands/printf/printf.d.ts +4 -0
  687. package/dist/commands/printf/strftime.d.ts +14 -0
  688. package/dist/commands/pwd/pwd.d.ts +4 -0
  689. package/dist/commands/python3/python3.d.ts +16 -0
  690. package/dist/commands/python3/worker.d.ts +31 -0
  691. package/dist/commands/query-engine/builtins/array-builtins.d.ts +20 -0
  692. package/dist/commands/query-engine/builtins/control-builtins.d.ts +18 -0
  693. package/dist/commands/query-engine/builtins/date-builtins.d.ts +15 -0
  694. package/dist/commands/query-engine/builtins/format-builtins.d.ts +11 -0
  695. package/dist/commands/query-engine/builtins/index-builtins.d.ts +16 -0
  696. package/dist/commands/query-engine/builtins/index.d.ts +17 -0
  697. package/dist/commands/query-engine/builtins/math-builtins.d.ts +15 -0
  698. package/dist/commands/query-engine/builtins/navigation-builtins.d.ts +18 -0
  699. package/dist/commands/query-engine/builtins/object-builtins.d.ts +15 -0
  700. package/dist/commands/query-engine/builtins/path-builtins.d.ts +20 -0
  701. package/dist/commands/query-engine/builtins/sql-builtins.d.ts +16 -0
  702. package/dist/commands/query-engine/builtins/string-builtins.d.ts +15 -0
  703. package/dist/commands/query-engine/builtins/type-builtins.d.ts +11 -0
  704. package/dist/commands/query-engine/evaluator.d.ts +62 -0
  705. package/dist/commands/query-engine/index.d.ts +8 -0
  706. package/dist/commands/query-engine/json-output.d.ts +11 -0
  707. package/dist/commands/query-engine/parser-types.d.ts +171 -0
  708. package/dist/commands/query-engine/parser.d.ts +14 -0
  709. package/dist/commands/query-engine/path-operations.d.ts +15 -0
  710. package/dist/commands/query-engine/safe-object.d.ts +84 -0
  711. package/dist/commands/query-engine/value-operations.d.ts +44 -0
  712. package/dist/commands/readlink/readlink.d.ts +4 -0
  713. package/dist/commands/registry.d.ts +56 -0
  714. package/dist/commands/rev/rev.d.ts +13 -0
  715. package/dist/commands/rg/file-types.d.ts +49 -0
  716. package/dist/commands/rg/gitignore.d.ts +98 -0
  717. package/dist/commands/rg/rg-options.d.ts +61 -0
  718. package/dist/commands/rg/rg-parser.d.ts +20 -0
  719. package/dist/commands/rg/rg-search.d.ts +15 -0
  720. package/dist/commands/rg/rg.d.ts +14 -0
  721. package/dist/commands/rm/rm.d.ts +4 -0
  722. package/dist/commands/rmdir/rmdir.d.ts +4 -0
  723. package/dist/commands/search-engine/index.d.ts +10 -0
  724. package/dist/commands/search-engine/matcher.d.ts +72 -0
  725. package/dist/commands/search-engine/regex.d.ts +46 -0
  726. package/dist/commands/sed/executor.d.ts +7 -0
  727. package/dist/commands/sed/lexer.d.ts +88 -0
  728. package/dist/commands/sed/parser.d.ts +21 -0
  729. package/dist/commands/sed/sed-regex.d.ts +23 -0
  730. package/dist/commands/sed/sed.d.ts +4 -0
  731. package/dist/commands/sed/types.d.ts +216 -0
  732. package/dist/commands/seq/seq.d.ts +16 -0
  733. package/dist/commands/sleep/sleep.d.ts +4 -0
  734. package/dist/commands/sort/comparator.d.ts +9 -0
  735. package/dist/commands/sort/parser.d.ts +11 -0
  736. package/dist/commands/sort/sort.d.ts +4 -0
  737. package/dist/commands/sort/types.d.ts +30 -0
  738. package/dist/commands/split/split.d.ts +12 -0
  739. package/dist/commands/sqlite3/formatters.d.ts +17 -0
  740. package/dist/commands/sqlite3/sqlite3.d.ts +24 -0
  741. package/dist/commands/sqlite3/worker.d.ts +50 -0
  742. package/dist/commands/sqlite3/worker.js +1928 -0
  743. package/dist/commands/stat/stat.d.ts +4 -0
  744. package/dist/commands/strings/strings.d.ts +12 -0
  745. package/dist/commands/tac/tac.d.ts +11 -0
  746. package/dist/commands/tail/tail.d.ts +4 -0
  747. package/dist/commands/tar/archive.d.ts +150 -0
  748. package/dist/commands/tar/bzip2-compress.d.ts +18 -0
  749. package/dist/commands/tar/tar-options.d.ts +37 -0
  750. package/dist/commands/tar/tar.d.ts +10 -0
  751. package/dist/commands/tee/tee.d.ts +4 -0
  752. package/dist/commands/time/time.d.ts +27 -0
  753. package/dist/commands/timeout/timeout.d.ts +4 -0
  754. package/dist/commands/touch/touch.d.ts +4 -0
  755. package/dist/commands/tr/tr.d.ts +4 -0
  756. package/dist/commands/tree/tree.d.ts +4 -0
  757. package/dist/commands/true/true.d.ts +6 -0
  758. package/dist/commands/uniq/uniq.d.ts +4 -0
  759. package/dist/commands/wc/wc.d.ts +4 -0
  760. package/dist/commands/which/which.d.ts +4 -0
  761. package/dist/commands/whoami/whoami.d.ts +11 -0
  762. package/dist/commands/worker-bridge/bridge-handler.d.ts +73 -0
  763. package/dist/commands/worker-bridge/protocol.d.ts +141 -0
  764. package/dist/commands/worker-bridge/sync-backend.d.ts +86 -0
  765. package/dist/commands/worker-request-controller.d.ts +36 -0
  766. package/dist/commands/xan/aggregation.d.ts +30 -0
  767. package/dist/commands/xan/bounded-output.d.ts +4 -0
  768. package/dist/commands/xan/column-selection.d.ts +20 -0
  769. package/dist/commands/xan/csv.d.ts +62 -0
  770. package/dist/commands/xan/moonblade-parser.d.ts +89 -0
  771. package/dist/commands/xan/moonblade-to-jq.d.ts +12 -0
  772. package/dist/commands/xan/moonblade-tokenizer.d.ts +32 -0
  773. package/dist/commands/xan/subcommands.d.ts +15 -0
  774. package/dist/commands/xan/xan-agg.d.ts +8 -0
  775. package/dist/commands/xan/xan-columns.d.ts +8 -0
  776. package/dist/commands/xan/xan-core.d.ts +10 -0
  777. package/dist/commands/xan/xan-data.d.ts +52 -0
  778. package/dist/commands/xan/xan-filter.d.ts +8 -0
  779. package/dist/commands/xan/xan-map.d.ts +11 -0
  780. package/dist/commands/xan/xan-reshape.d.ts +40 -0
  781. package/dist/commands/xan/xan-simple.d.ts +40 -0
  782. package/dist/commands/xan/xan-view.d.ts +12 -0
  783. package/dist/commands/xan/xan.d.ts +10 -0
  784. package/dist/commands/xargs/xargs.d.ts +4 -0
  785. package/dist/commands/yq/formats.d.ts +65 -0
  786. package/dist/commands/yq/yq.d.ts +13 -0
  787. package/dist/custom-commands.d.ts +65 -0
  788. package/dist/encoding.d.ts +131 -0
  789. package/dist/execution-output.d.ts +28 -0
  790. package/dist/execution-scope.d.ts +110 -0
  791. package/dist/fatal-execution-error.d.ts +27 -0
  792. package/dist/fs/encoding.d.ts +17 -0
  793. package/dist/fs/identity.d.ts +9 -0
  794. package/dist/fs/in-memory-fs/in-memory-fs.d.ts +98 -0
  795. package/dist/fs/in-memory-fs/index.d.ts +1 -0
  796. package/dist/fs/init.d.ts +22 -0
  797. package/dist/fs/interface.d.ts +255 -0
  798. package/dist/fs/mountable-fs/index.d.ts +1 -0
  799. package/dist/fs/mountable-fs/mountable-fs.d.ts +118 -0
  800. package/dist/fs/overlay-fs/apply.d.ts +22 -0
  801. package/dist/fs/overlay-fs/index.d.ts +1 -0
  802. package/dist/fs/overlay-fs/overlay-fs.d.ts +360 -0
  803. package/dist/fs/overlay-fs/overlay-tree.d.ts +188 -0
  804. package/dist/fs/path-utils.d.ts +48 -0
  805. package/dist/fs/read-write-fs/index.d.ts +1 -0
  806. package/dist/fs/read-write-fs/read-write-fs.d.ts +150 -0
  807. package/dist/fs/real-fs-utils.d.ts +90 -0
  808. package/dist/fs/sanitize-error.d.ts +19 -0
  809. package/dist/fs/traversal.d.ts +98 -0
  810. package/dist/index.d.cts +30 -0
  811. package/dist/index.d.ts +30 -0
  812. package/dist/interpreter/alias-expansion.d.ts +27 -0
  813. package/dist/interpreter/arithmetic.d.ts +24 -0
  814. package/dist/interpreter/assignment-expansion.d.ts +24 -0
  815. package/dist/interpreter/builtin-dispatch.d.ts +46 -0
  816. package/dist/interpreter/builtins/break.d.ts +6 -0
  817. package/dist/interpreter/builtins/cd.d.ts +6 -0
  818. package/dist/interpreter/builtins/compgen.d.ts +26 -0
  819. package/dist/interpreter/builtins/complete.d.ts +17 -0
  820. package/dist/interpreter/builtins/compopt.d.ts +28 -0
  821. package/dist/interpreter/builtins/continue.d.ts +6 -0
  822. package/dist/interpreter/builtins/declare-array-parsing.d.ts +18 -0
  823. package/dist/interpreter/builtins/declare-print.d.ts +39 -0
  824. package/dist/interpreter/builtins/declare.d.ts +35 -0
  825. package/dist/interpreter/builtins/dirs.d.ts +29 -0
  826. package/dist/interpreter/builtins/eval.d.ts +15 -0
  827. package/dist/interpreter/builtins/exit.d.ts +5 -0
  828. package/dist/interpreter/builtins/export.d.ts +14 -0
  829. package/dist/interpreter/builtins/getopts.d.ts +18 -0
  830. package/dist/interpreter/builtins/hash.d.ts +19 -0
  831. package/dist/interpreter/builtins/help.d.ts +12 -0
  832. package/dist/interpreter/builtins/index.d.ts +44 -0
  833. package/dist/interpreter/builtins/let.d.ts +18 -0
  834. package/dist/interpreter/builtins/local.d.ts +6 -0
  835. package/dist/interpreter/builtins/mapfile.d.ts +17 -0
  836. package/dist/interpreter/builtins/read.d.ts +6 -0
  837. package/dist/interpreter/builtins/return.d.ts +6 -0
  838. package/dist/interpreter/builtins/set.d.ts +9 -0
  839. package/dist/interpreter/builtins/shift.d.ts +15 -0
  840. package/dist/interpreter/builtins/shopt.d.ts +7 -0
  841. package/dist/interpreter/builtins/source.d.ts +6 -0
  842. package/dist/interpreter/builtins/unset.d.ts +16 -0
  843. package/dist/interpreter/builtins/variable-assignment.d.ts +69 -0
  844. package/dist/interpreter/command-analysis.d.ts +30 -0
  845. package/dist/interpreter/command-resolution.d.ts +43 -0
  846. package/dist/interpreter/conditionals.d.ts +17 -0
  847. package/dist/interpreter/control-flow.d.ts +21 -0
  848. package/dist/interpreter/defense-aware-command-context.d.ts +6 -0
  849. package/dist/interpreter/errors.d.ts +161 -0
  850. package/dist/interpreter/expansion/analysis.d.ts +37 -0
  851. package/dist/interpreter/expansion/arith-text-expansion.d.ts +20 -0
  852. package/dist/interpreter/expansion/array-pattern-ops.d.ts +21 -0
  853. package/dist/interpreter/expansion/array-prefix-suffix.d.ts +46 -0
  854. package/dist/interpreter/expansion/array-slice-transform.d.ts +36 -0
  855. package/dist/interpreter/expansion/array-word-expansion.d.ts +39 -0
  856. package/dist/interpreter/expansion/brace-range.d.ts +24 -0
  857. package/dist/interpreter/expansion/command-substitution.d.ts +23 -0
  858. package/dist/interpreter/expansion/glob-escape.d.ts +32 -0
  859. package/dist/interpreter/expansion/indirect-expansion.d.ts +42 -0
  860. package/dist/interpreter/expansion/parameter-ops.d.ts +113 -0
  861. package/dist/interpreter/expansion/pattern-expansion.d.ts +23 -0
  862. package/dist/interpreter/expansion/pattern-removal.d.ts +17 -0
  863. package/dist/interpreter/expansion/pattern-replacement.d.ts +4 -0
  864. package/dist/interpreter/expansion/pattern.d.ts +23 -0
  865. package/dist/interpreter/expansion/positional-params.d.ts +59 -0
  866. package/dist/interpreter/expansion/prompt.d.ts +39 -0
  867. package/dist/interpreter/expansion/quoting.d.ts +13 -0
  868. package/dist/interpreter/expansion/tilde.d.ts +14 -0
  869. package/dist/interpreter/expansion/unquoted-expansion.d.ts +76 -0
  870. package/dist/interpreter/expansion/variable-attrs.d.ts +19 -0
  871. package/dist/interpreter/expansion/variable.d.ts +36 -0
  872. package/dist/interpreter/expansion/word-glob-expansion.d.ts +33 -0
  873. package/dist/interpreter/expansion/word-split.d.ts +29 -0
  874. package/dist/interpreter/expansion.d.ts +53 -0
  875. package/dist/interpreter/fd-table.d.ts +130 -0
  876. package/dist/interpreter/functions.d.ts +14 -0
  877. package/dist/interpreter/helpers/array.d.ts +56 -0
  878. package/dist/interpreter/helpers/bounded-array.d.ts +2 -0
  879. package/dist/interpreter/helpers/condition.d.ts +19 -0
  880. package/dist/interpreter/helpers/errors.d.ts +8 -0
  881. package/dist/interpreter/helpers/file-tests.d.ts +33 -0
  882. package/dist/interpreter/helpers/ifs.d.ts +104 -0
  883. package/dist/interpreter/helpers/loop.d.ts +24 -0
  884. package/dist/interpreter/helpers/nameref.d.ts +65 -0
  885. package/dist/interpreter/helpers/numeric-compare.d.ts +13 -0
  886. package/dist/interpreter/helpers/quoting.d.ts +26 -0
  887. package/dist/interpreter/helpers/readonly.d.ts +45 -0
  888. package/dist/interpreter/helpers/regex.d.ts +8 -0
  889. package/dist/interpreter/helpers/result.d.ts +60 -0
  890. package/dist/interpreter/helpers/shell-constants.d.ts +41 -0
  891. package/dist/interpreter/helpers/shellopts.d.ts +28 -0
  892. package/dist/interpreter/helpers/string-compare.d.ts +24 -0
  893. package/dist/interpreter/helpers/string-tests.d.ts +13 -0
  894. package/dist/interpreter/helpers/variable-tests.d.ts +9 -0
  895. package/dist/interpreter/helpers/word-matching.d.ts +16 -0
  896. package/dist/interpreter/helpers/word-parts.d.ts +22 -0
  897. package/dist/interpreter/helpers/xtrace.d.ts +18 -0
  898. package/dist/interpreter/index.d.ts +3 -0
  899. package/dist/interpreter/interpreter.d.ts +82 -0
  900. package/dist/interpreter/numeric-fd-redirects.d.ts +8 -0
  901. package/dist/interpreter/pipeline-execution.d.ts +16 -0
  902. package/dist/interpreter/process-substitution.d.ts +62 -0
  903. package/dist/interpreter/redirections.d.ts +50 -0
  904. package/dist/interpreter/simple-command-assignments.d.ts +36 -0
  905. package/dist/interpreter/state-transaction.d.ts +7 -0
  906. package/dist/interpreter/subshell-group.d.ts +40 -0
  907. package/dist/interpreter/type-command.d.ts +37 -0
  908. package/dist/interpreter/types.d.ts +402 -0
  909. package/dist/limits.d.ts +111 -0
  910. package/dist/network/allow-list/shared.d.ts +49 -0
  911. package/dist/network/allow-list.d.ts +59 -0
  912. package/dist/network/dns-pin.d.ts +42 -0
  913. package/dist/network/fetch.d.ts +27 -0
  914. package/dist/network/index.d.ts +7 -0
  915. package/dist/network/types.d.ts +182 -0
  916. package/dist/parser/arithmetic-parser.d.ts +23 -0
  917. package/dist/parser/arithmetic-primaries.d.ts +45 -0
  918. package/dist/parser/command-parser.d.ts +10 -0
  919. package/dist/parser/compound-parser.d.ts +28 -0
  920. package/dist/parser/conditional-parser.d.ts +8 -0
  921. package/dist/parser/expansion-parser.d.ts +18 -0
  922. package/dist/parser/lexer.d.ts +195 -0
  923. package/dist/parser/parser-substitution.d.ts +85 -0
  924. package/dist/parser/parser.d.ts +152 -0
  925. package/dist/parser/types.d.ts +40 -0
  926. package/dist/parser/word-parser.d.ts +35 -0
  927. package/dist/sandbox/Command.d.ts +35 -0
  928. package/dist/sandbox/Sandbox.d.ts +121 -0
  929. package/dist/sandbox/index.d.ts +2 -0
  930. package/dist/security/blocked-globals.d.ts +60 -0
  931. package/dist/security/defense-context.d.ts +13 -0
  932. package/dist/security/defense-in-depth-box.d.ts +354 -0
  933. package/dist/security/index.d.ts +33 -0
  934. package/dist/security/safe-timestamp.d.ts +1 -0
  935. package/dist/security/security-violation-logger.d.ts +99 -0
  936. package/dist/security/trusted-globals.d.ts +17 -0
  937. package/dist/security/types.d.ts +151 -0
  938. package/dist/security/violation-error-message.d.ts +3 -0
  939. package/dist/security/wasm-callback.d.ts +6 -0
  940. package/dist/security/worker-defense-in-depth.d.ts +228 -0
  941. package/dist/shell-metadata.d.ts +25 -0
  942. package/dist/source-limit.d.ts +2 -0
  943. package/dist/timers.d.ts +16 -0
  944. package/dist/transform/pipeline.d.ts +8 -0
  945. package/dist/transform/plugins/command-collector.d.ts +8 -0
  946. package/dist/transform/plugins/tee-plugin.d.ts +40 -0
  947. package/dist/transform/serialize.d.ts +4 -0
  948. package/dist/transform/types.d.ts +18 -0
  949. package/dist/types.d.ts +319 -0
  950. package/dist/utils/args.d.ts +55 -0
  951. package/dist/utils/constants.d.ts +15 -0
  952. package/dist/utils/file-reader.d.ts +76 -0
  953. package/dist/utils/glob.d.ts +25 -0
  954. package/dist/vitest-setup.d.ts +1 -0
  955. package/package.json +136 -0
  956. package/vendor/cpython-emscripten/python.cjs +2 -0
  957. package/vendor/cpython-emscripten/python.wasm +0 -0
  958. package/vendor/cpython-emscripten/python313.zip +0 -0
@@ -0,0 +1,3330 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/commands/python3/worker.ts
9
+ import { createRequire } from "node:module";
10
+ import { dirname } from "node:path";
11
+ import { parentPort, workerData } from "node:worker_threads";
12
+
13
+ // src/fs/sanitize-error.ts
14
+ function sanitizeWithUnixPrefixes(message, includeHostRuntimePrefixes, includeFileUrls) {
15
+ if (!message) return message;
16
+ let sanitized = message.replace(/\n\s+at\s.*/g, "");
17
+ if (includeFileUrls) {
18
+ sanitized = sanitized.replace(/\bfile:\/\/\/?[^\s'",)}\]:]+/g, "<path>");
19
+ }
20
+ sanitized = sanitized.replace(
21
+ includeHostRuntimePrefixes ? /(?:\/(?:Users|home|private|var|opt|Library|System|usr|etc|tmp|nix|snap|workspace|root|srv|mnt|app))\b[^\s'",)}\]:]*/g : /(?:\/(?:Users|home|private|var|opt|Library|System|usr|etc|tmp|nix|snap))\b[^\s'",)}\]:]*/g,
22
+ "<path>"
23
+ );
24
+ sanitized = sanitized.replace(/node:internal\/[^\s'",)}\]:]+/g, "<internal>");
25
+ sanitized = sanitized.replace(/[A-Z]:\\[^\s'",)}\]:]+/g, "<path>");
26
+ if (includeFileUrls) {
27
+ sanitized = sanitized.replace(/\\\\[^\s\\]+\\[^\s'",)}\]:]+/g, "<path>");
28
+ }
29
+ return sanitized;
30
+ }
31
+ function sanitizeErrorMessage(message) {
32
+ return sanitizeWithUnixPrefixes(message, false, false);
33
+ }
34
+ function sanitizeHostErrorMessage(message) {
35
+ return sanitizeWithUnixPrefixes(message, true, true);
36
+ }
37
+
38
+ // src/security/defense-in-depth-box.ts
39
+ import * as nodeAsyncHooks from "node:async_hooks";
40
+ import * as nodeModule from "node:module";
41
+
42
+ // src/security/blocked-globals.ts
43
+ var blockedGlobalViolationTypes;
44
+ function getBlockedGlobalViolationTypes() {
45
+ if (!blockedGlobalViolationTypes) getBlockedGlobals();
46
+ return blockedGlobalViolationTypes;
47
+ }
48
+ function getBlockedGlobals() {
49
+ const globals = [
50
+ // Direct code execution vectors
51
+ {
52
+ prop: "Function",
53
+ target: globalThis,
54
+ violationType: "function_constructor",
55
+ strategy: "throw",
56
+ reason: "Function constructor allows arbitrary code execution"
57
+ },
58
+ {
59
+ prop: "eval",
60
+ target: globalThis,
61
+ violationType: "eval",
62
+ strategy: "throw",
63
+ reason: "eval() allows arbitrary code execution"
64
+ },
65
+ // Timer functions with string argument allow code execution
66
+ {
67
+ prop: "setTimeout",
68
+ target: globalThis,
69
+ violationType: "setTimeout",
70
+ strategy: "throw",
71
+ reason: "setTimeout with string argument allows code execution"
72
+ },
73
+ {
74
+ prop: "setInterval",
75
+ target: globalThis,
76
+ violationType: "setInterval",
77
+ strategy: "throw",
78
+ reason: "setInterval with string argument allows code execution"
79
+ },
80
+ {
81
+ prop: "setImmediate",
82
+ target: globalThis,
83
+ violationType: "setImmediate",
84
+ strategy: "throw",
85
+ reason: "setImmediate could be used to escape sandbox context"
86
+ },
87
+ // Note: We intentionally do NOT block `process` entirely because:
88
+ // 1. Node.js internals (Promise resolution, etc.) use process.nextTick
89
+ // 2. Blocking process entirely breaks normal async operation
90
+ // 3. The primary code execution vectors (Function, eval) are already blocked
91
+ // However, we DO block specific dangerous process properties.
92
+ {
93
+ prop: "env",
94
+ target: process,
95
+ violationType: "process_env",
96
+ strategy: "throw",
97
+ reason: "process.env could leak sensitive environment variables",
98
+ // Node.js internals and bundled dependencies read these env vars
99
+ // during module loading, file watching, and I/O within the
100
+ // AsyncLocalStorage context. None are user secrets.
101
+ allowedKeys: /* @__PURE__ */ new Set([
102
+ // Node.js core
103
+ "NODE_V8_COVERAGE",
104
+ "NODE_DEBUG",
105
+ "NODE_DEBUG_NATIVE",
106
+ "NODE_COMPILE_CACHE",
107
+ "NODE_ENV",
108
+ "WATCH_REPORT_DEPENDENCIES",
109
+ // Dependencies
110
+ "FORCE_COLOR",
111
+ // chalk/supports-color
112
+ "DEBUG",
113
+ // debug package
114
+ "UNDICI_NO_FG",
115
+ // undici (Node.js fetch)
116
+ "JEST_WORKER_ID",
117
+ // jest/vitest worker detection
118
+ "__MINIMATCH_TESTING_PLATFORM__",
119
+ // minimatch
120
+ "LOG_TOKENS",
121
+ // query engine debug logging
122
+ "LOG_STREAM"
123
+ // query engine debug logging
124
+ ])
125
+ },
126
+ {
127
+ prop: "binding",
128
+ target: process,
129
+ violationType: "process_binding",
130
+ strategy: "throw",
131
+ reason: "process.binding provides access to native Node.js modules"
132
+ },
133
+ {
134
+ prop: "_linkedBinding",
135
+ target: process,
136
+ violationType: "process_binding",
137
+ strategy: "throw",
138
+ reason: "process._linkedBinding provides access to native Node.js modules"
139
+ },
140
+ {
141
+ prop: "dlopen",
142
+ target: process,
143
+ violationType: "process_dlopen",
144
+ strategy: "throw",
145
+ reason: "process.dlopen allows loading native addons"
146
+ },
147
+ {
148
+ prop: "getBuiltinModule",
149
+ target: process,
150
+ violationType: "process_get_builtin_module",
151
+ strategy: "throw",
152
+ reason: "process.getBuiltinModule allows loading native Node.js modules (fs, child_process, vm)"
153
+ },
154
+ // Note: process.mainModule is handled specially in defense-in-depth-box.ts
155
+ // and worker-defense-in-depth.ts because it may be undefined in ESM contexts
156
+ // but we still want to block both reading and setting it.
157
+ // Process control vectors
158
+ {
159
+ prop: "exit",
160
+ target: process,
161
+ violationType: "process_exit",
162
+ strategy: "throw",
163
+ reason: "process.exit could terminate the interpreter"
164
+ },
165
+ {
166
+ prop: "abort",
167
+ target: process,
168
+ violationType: "process_exit",
169
+ strategy: "throw",
170
+ reason: "process.abort could crash the interpreter"
171
+ },
172
+ {
173
+ prop: "kill",
174
+ target: process,
175
+ violationType: "process_kill",
176
+ strategy: "throw",
177
+ reason: "process.kill could signal other processes"
178
+ },
179
+ // Privilege escalation vectors
180
+ {
181
+ prop: "setuid",
182
+ target: process,
183
+ violationType: "process_setuid",
184
+ strategy: "throw",
185
+ reason: "process.setuid could escalate privileges"
186
+ },
187
+ {
188
+ prop: "setgid",
189
+ target: process,
190
+ violationType: "process_setuid",
191
+ strategy: "throw",
192
+ reason: "process.setgid could escalate privileges"
193
+ },
194
+ {
195
+ prop: "seteuid",
196
+ target: process,
197
+ violationType: "process_setuid",
198
+ strategy: "throw",
199
+ reason: "process.seteuid could escalate effective user privileges"
200
+ },
201
+ {
202
+ prop: "setegid",
203
+ target: process,
204
+ violationType: "process_setuid",
205
+ strategy: "throw",
206
+ reason: "process.setegid could escalate effective group privileges"
207
+ },
208
+ {
209
+ prop: "initgroups",
210
+ target: process,
211
+ violationType: "process_setuid",
212
+ strategy: "throw",
213
+ reason: "process.initgroups could modify supplementary group IDs"
214
+ },
215
+ {
216
+ prop: "setgroups",
217
+ target: process,
218
+ violationType: "process_setuid",
219
+ strategy: "throw",
220
+ reason: "process.setgroups could modify supplementary group IDs"
221
+ },
222
+ // File permission manipulation
223
+ {
224
+ prop: "umask",
225
+ target: process,
226
+ violationType: "process_umask",
227
+ strategy: "throw",
228
+ reason: "process.umask could modify file creation permissions"
229
+ },
230
+ // Information disclosure vectors
231
+ // Note: process.argv is an array (object) so gets an object proxy
232
+ {
233
+ prop: "argv",
234
+ target: process,
235
+ violationType: "process_argv",
236
+ strategy: "throw",
237
+ reason: "process.argv may contain secrets in CLI arguments"
238
+ },
239
+ // Note: process.execPath is a string primitive, handled specially
240
+ // in defense-in-depth-box.ts and worker-defense-in-depth.ts
241
+ // Note: process.connected is a boolean primitive, handled specially
242
+ // in defense-in-depth-box.ts and worker-defense-in-depth.ts
243
+ // Working directory access/manipulation
244
+ {
245
+ prop: "cwd",
246
+ target: process,
247
+ violationType: "process_chdir",
248
+ strategy: "throw",
249
+ reason: "process.cwd could disclose real host working directory path"
250
+ },
251
+ {
252
+ prop: "chdir",
253
+ target: process,
254
+ violationType: "process_chdir",
255
+ strategy: "throw",
256
+ reason: "process.chdir could confuse the interpreter's CWD tracking"
257
+ },
258
+ // Diagnostic report (leaks full environment, host paths, system info)
259
+ {
260
+ prop: "report",
261
+ target: process,
262
+ violationType: "process_report",
263
+ strategy: "throw",
264
+ reason: "process.report could disclose full environment, host paths, and system info"
265
+ },
266
+ // Environment file loading (Node 21.7+)
267
+ {
268
+ prop: "loadEnvFile",
269
+ target: process,
270
+ violationType: "process_env",
271
+ strategy: "throw",
272
+ reason: "process.loadEnvFile could load env files bypassing env proxy"
273
+ },
274
+ // Exception handler manipulation
275
+ {
276
+ prop: "setUncaughtExceptionCaptureCallback",
277
+ target: process,
278
+ violationType: "process_exception_handler",
279
+ strategy: "throw",
280
+ reason: "setUncaughtExceptionCaptureCallback could intercept security errors"
281
+ },
282
+ ...[
283
+ "on",
284
+ "once",
285
+ "addListener",
286
+ "prependListener",
287
+ "prependOnceListener"
288
+ ].map(
289
+ (prop) => ({
290
+ prop,
291
+ target: process,
292
+ violationType: "process_exception_handler",
293
+ strategy: "throw",
294
+ reason: "process-global listeners can outlive the sandbox and lose its security context"
295
+ })
296
+ ),
297
+ // IPC communication vectors (may be undefined in non-IPC contexts)
298
+ {
299
+ prop: "send",
300
+ target: process,
301
+ violationType: "process_send",
302
+ strategy: "throw",
303
+ reason: "process.send could communicate with parent process in IPC contexts"
304
+ },
305
+ {
306
+ prop: "channel",
307
+ target: process,
308
+ violationType: "process_channel",
309
+ strategy: "throw",
310
+ reason: "process.channel could access IPC channel to parent process"
311
+ },
312
+ // Timing side-channel vectors
313
+ {
314
+ prop: "cpuUsage",
315
+ target: process,
316
+ violationType: "process_timing",
317
+ strategy: "throw",
318
+ reason: "process.cpuUsage could enable timing side-channel attacks"
319
+ },
320
+ {
321
+ prop: "memoryUsage",
322
+ target: process,
323
+ violationType: "process_timing",
324
+ strategy: "throw",
325
+ reason: "process.memoryUsage could enable timing side-channel attacks"
326
+ },
327
+ {
328
+ prop: "hrtime",
329
+ target: process,
330
+ violationType: "process_timing",
331
+ strategy: "throw",
332
+ reason: "process.hrtime could enable timing side-channel attacks"
333
+ },
334
+ // We also don't block `require` because:
335
+ // 1. It may not exist in all environments (ESM)
336
+ // 2. import() is the modern escape vector and can't be blocked this way
337
+ // Reference leak vectors
338
+ {
339
+ prop: "WeakRef",
340
+ target: globalThis,
341
+ violationType: "weak_ref",
342
+ strategy: "throw",
343
+ reason: "WeakRef could be used to leak references outside sandbox"
344
+ },
345
+ {
346
+ prop: "FinalizationRegistry",
347
+ target: globalThis,
348
+ violationType: "finalization_registry",
349
+ strategy: "throw",
350
+ reason: "FinalizationRegistry could be used to leak references outside sandbox"
351
+ },
352
+ // Introspection/interception vectors (freeze instead of throw)
353
+ // SECURITY RATIONALE: Reflect is frozen (not blocked) because:
354
+ // 1. Defense infrastructure uses Reflect.apply/get/set/construct internally
355
+ // 2. Frozen Reflect cannot be mutated but remains fully functional
356
+ // 3. Reflect.construct(Function, ['code']) IS safe because globalThis.Function
357
+ // is replaced with a blocking proxy — Reflect.construct receives the proxy
358
+ // 4. Security depends on NEVER leaking original Function/eval references.
359
+ // If an unpatched Function ref leaked, Reflect.construct would bypass defense.
360
+ {
361
+ prop: "Reflect",
362
+ target: globalThis,
363
+ violationType: "reflect",
364
+ strategy: "freeze",
365
+ reason: "Reflect provides introspection capabilities"
366
+ },
367
+ {
368
+ prop: "Proxy",
369
+ target: globalThis,
370
+ violationType: "proxy",
371
+ strategy: "throw",
372
+ reason: "Proxy allows intercepting and modifying object behavior"
373
+ },
374
+ // WebAssembly allows arbitrary code execution
375
+ {
376
+ prop: "WebAssembly",
377
+ target: globalThis,
378
+ violationType: "webassembly",
379
+ strategy: "throw",
380
+ reason: "WebAssembly allows executing arbitrary compiled code"
381
+ },
382
+ // SharedArrayBuffer and Atomics can enable side-channel attacks
383
+ {
384
+ prop: "SharedArrayBuffer",
385
+ target: globalThis,
386
+ violationType: "shared_array_buffer",
387
+ strategy: "throw",
388
+ reason: "SharedArrayBuffer could enable side-channel communication or timing attacks"
389
+ },
390
+ {
391
+ prop: "Atomics",
392
+ target: globalThis,
393
+ violationType: "atomics",
394
+ strategy: "throw",
395
+ reason: "Atomics could enable side-channel communication or timing attacks"
396
+ },
397
+ // Note: Error.prepareStackTrace is handled specially in defense-in-depth-box.ts
398
+ // because we only want to block SETTING it, not reading (V8 reads it internally)
399
+ // Timing side-channel: performance.now() provides sub-millisecond resolution
400
+ // Note: Date.now() is intentionally NOT blocked — it's used for $SECONDS,
401
+ // date command, and has only ~1ms resolution (vs process.hrtime at ns).
402
+ {
403
+ prop: "performance",
404
+ target: globalThis,
405
+ violationType: "performance_timing",
406
+ strategy: "throw",
407
+ reason: "performance.now() provides sub-millisecond timing for side-channel attacks"
408
+ },
409
+ // Block direct access to process.stdout and process.stderr to prevent
410
+ // writing to the host's actual stdout/stderr, bypassing the interpreter's
411
+ // output accumulation.
412
+ {
413
+ prop: "stdout",
414
+ target: process,
415
+ violationType: "process_stdout",
416
+ strategy: "throw",
417
+ reason: "process.stdout could bypass interpreter output to write to host stdout"
418
+ },
419
+ {
420
+ prop: "stderr",
421
+ target: process,
422
+ violationType: "process_stderr",
423
+ strategy: "throw",
424
+ reason: "process.stderr could bypass interpreter output to write to host stderr"
425
+ },
426
+ // Prototype pollution vectors
427
+ {
428
+ prop: "__defineGetter__",
429
+ target: Object.prototype,
430
+ violationType: "prototype_mutation",
431
+ strategy: "throw",
432
+ reason: "__defineGetter__ allows prototype pollution via getter injection"
433
+ },
434
+ {
435
+ prop: "__defineSetter__",
436
+ target: Object.prototype,
437
+ violationType: "prototype_mutation",
438
+ strategy: "throw",
439
+ reason: "__defineSetter__ allows prototype pollution via setter injection"
440
+ },
441
+ {
442
+ prop: "__lookupGetter__",
443
+ target: Object.prototype,
444
+ violationType: "prototype_mutation",
445
+ strategy: "throw",
446
+ reason: "__lookupGetter__ enables introspection for prototype pollution attacks"
447
+ },
448
+ {
449
+ prop: "__lookupSetter__",
450
+ target: Object.prototype,
451
+ violationType: "prototype_mutation",
452
+ strategy: "throw",
453
+ reason: "__lookupSetter__ enables introspection for prototype pollution attacks"
454
+ },
455
+ // Freeze JSON and Math to prevent mutation of built-in utility objects
456
+ {
457
+ prop: "JSON",
458
+ target: globalThis,
459
+ violationType: "json_mutation",
460
+ strategy: "freeze",
461
+ reason: "Freeze JSON to prevent mutation of parsing/serialization"
462
+ },
463
+ {
464
+ prop: "Math",
465
+ target: globalThis,
466
+ violationType: "math_mutation",
467
+ strategy: "freeze",
468
+ reason: "Freeze Math to prevent mutation of math utilities"
469
+ }
470
+ ];
471
+ try {
472
+ const AsyncFunction = Object.getPrototypeOf(async () => {
473
+ }).constructor;
474
+ if (AsyncFunction && AsyncFunction !== Function) {
475
+ globals.push({
476
+ prop: "constructor",
477
+ target: Object.getPrototypeOf(async () => {
478
+ }),
479
+ violationType: "async_function_constructor",
480
+ strategy: "throw",
481
+ reason: "AsyncFunction constructor allows arbitrary async code execution"
482
+ });
483
+ }
484
+ } catch {
485
+ }
486
+ try {
487
+ const GeneratorFunction = Object.getPrototypeOf(
488
+ function* () {
489
+ }
490
+ ).constructor;
491
+ if (GeneratorFunction && GeneratorFunction !== Function) {
492
+ globals.push({
493
+ prop: "constructor",
494
+ target: Object.getPrototypeOf(function* () {
495
+ }),
496
+ violationType: "generator_function_constructor",
497
+ strategy: "throw",
498
+ reason: "GeneratorFunction constructor allows arbitrary generator code execution"
499
+ });
500
+ }
501
+ } catch {
502
+ }
503
+ try {
504
+ const AsyncGeneratorFunction = Object.getPrototypeOf(
505
+ async function* () {
506
+ }
507
+ ).constructor;
508
+ if (AsyncGeneratorFunction && AsyncGeneratorFunction !== Function && AsyncGeneratorFunction !== Object.getPrototypeOf(async () => {
509
+ }).constructor) {
510
+ globals.push({
511
+ prop: "constructor",
512
+ target: Object.getPrototypeOf(async function* () {
513
+ }),
514
+ violationType: "async_generator_function_constructor",
515
+ strategy: "throw",
516
+ reason: "AsyncGeneratorFunction constructor allows arbitrary async generator code execution"
517
+ });
518
+ }
519
+ } catch {
520
+ }
521
+ const availableGlobals = globals.filter((g) => {
522
+ try {
523
+ return g.target[g.prop] !== void 0;
524
+ } catch {
525
+ return false;
526
+ }
527
+ });
528
+ blockedGlobalViolationTypes ??= new Set(
529
+ availableGlobals.map(({ violationType }) => violationType)
530
+ );
531
+ return availableGlobals;
532
+ }
533
+
534
+ // src/security/safe-timestamp.ts
535
+ var performanceTimeOrigin = performance.timeOrigin;
536
+ var performanceNow = performance.now.bind(performance);
537
+ function getSafeTimestamp() {
538
+ return Math.floor(performanceTimeOrigin + performanceNow());
539
+ }
540
+
541
+ // src/security/violation-error-message.ts
542
+ var NON_EXCLUDABLE_VIOLATION_TYPES = /* @__PURE__ */ new Set([
543
+ "function_constructor",
544
+ "async_function_constructor",
545
+ "generator_function_constructor",
546
+ "async_generator_function_constructor"
547
+ ]);
548
+ function assertExcludableViolationTypes(violationTypes) {
549
+ const nonExcludable = violationTypes?.find(
550
+ (type) => NON_EXCLUDABLE_VIOLATION_TYPES.has(type)
551
+ );
552
+ if (nonExcludable) {
553
+ throw new RangeError(
554
+ `defenseInDepth.excludeViolationTypes cannot disable the non-excludable "${nonExcludable}" protection`
555
+ );
556
+ }
557
+ }
558
+ var DEFENSE_IN_DEPTH_NOTICE = "\n\nThis is a defense-in-depth measure and indicates a bug in just-bash. Please report this at security@vercel.com";
559
+ function formatViolationErrorMessage(message, violationType, canExclude) {
560
+ const exclusionHint = canExclude && !NON_EXCLUDABLE_VIOLATION_TYPES.has(violationType) ? `
561
+
562
+ If this access is required by trusted host-runtime code, add "${violationType}" to defenseInDepth.excludeViolationTypes.` : "";
563
+ return message + DEFENSE_IN_DEPTH_NOTICE + exclusionHint;
564
+ }
565
+
566
+ // src/security/defense-in-depth-box.ts
567
+ var IS_BROWSER = typeof __BROWSER__ !== "undefined" && __BROWSER__;
568
+ var AsyncLocalStorageClass = null;
569
+ var nodeModuleApi = null;
570
+ var nodeModuleClass = null;
571
+ if (!IS_BROWSER) {
572
+ try {
573
+ AsyncLocalStorageClass = nodeAsyncHooks.AsyncLocalStorage;
574
+ nodeModuleApi = nodeModule;
575
+ nodeModuleClass = nodeModuleApi.Module ?? nodeModuleApi.default ?? null;
576
+ } catch {
577
+ }
578
+ }
579
+ var executionContext = !IS_BROWSER && AsyncLocalStorageClass ? new AsyncLocalStorageClass() : null;
580
+
581
+ // src/security/worker-defense-in-depth.ts
582
+ var WORKER_SPECIAL_EXCLUDABLE_VIOLATION_TYPES = /* @__PURE__ */ new Set([
583
+ "error_prepare_stack_trace",
584
+ "module_load",
585
+ "module_resolve_filename",
586
+ "process_main_module",
587
+ "process_exec_path",
588
+ "process_connected"
589
+ ]);
590
+ var WorkerSecurityViolationError = class extends Error {
591
+ constructor(message, violation) {
592
+ super(
593
+ formatViolationErrorMessage(
594
+ message,
595
+ violation.type,
596
+ WORKER_SPECIAL_EXCLUDABLE_VIOLATION_TYPES.has(violation.type) || getBlockedGlobalViolationTypes().has(violation.type)
597
+ )
598
+ );
599
+ this.violation = violation;
600
+ this.name = "WorkerSecurityViolationError";
601
+ }
602
+ violation;
603
+ };
604
+ var MAX_STORED_VIOLATIONS = 1e3;
605
+ var nodeModuleClass2 = null;
606
+ try {
607
+ const getBuiltinModule = process.getBuiltinModule;
608
+ const moduleApi = typeof getBuiltinModule === "function" ? getBuiltinModule("module") : typeof __require === "function" ? (
609
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
610
+ __require("node:module")
611
+ ) : null;
612
+ nodeModuleClass2 = moduleApi?.Module ?? moduleApi?.default ?? null;
613
+ if (typeof getBuiltinModule === "function") {
614
+ const workerThreads = getBuiltinModule("worker_threads");
615
+ const isWorkerThread = workerThreads?.isMainThread === false;
616
+ if (isWorkerThread) {
617
+ const cryptoApi = getBuiltinModule("crypto");
618
+ cryptoApi?.randomUUID?.();
619
+ }
620
+ }
621
+ } catch {
622
+ nodeModuleClass2 = null;
623
+ }
624
+ function generateExecutionId() {
625
+ if (typeof crypto !== "undefined" && crypto.randomUUID) {
626
+ return crypto.randomUUID();
627
+ }
628
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
629
+ const r = Math.random() * 16 | 0;
630
+ const v = c === "x" ? r : r & 3 | 8;
631
+ return v.toString(16);
632
+ });
633
+ }
634
+ var WorkerDefenseInDepth = class {
635
+ config;
636
+ isActivated = false;
637
+ originalDescriptors = [];
638
+ patchFailures = [];
639
+ violations = [];
640
+ executionId;
641
+ /**
642
+ * Original Proxy constructor, captured before patching.
643
+ * This is captured at instance creation time to ensure we get the unpatched version.
644
+ */
645
+ originalProxy;
646
+ /**
647
+ * Recursion guard to prevent infinite loops when proxy traps trigger
648
+ * code that accesses the same proxied object (e.g., process.env).
649
+ */
650
+ inTrap = false;
651
+ /**
652
+ * Create and activate the worker defense layer.
653
+ *
654
+ * @param config - Configuration for the defense layer
655
+ */
656
+ constructor(config) {
657
+ assertExcludableViolationTypes(config.excludeViolationTypes);
658
+ this.originalProxy = Proxy;
659
+ this.config = config;
660
+ this.executionId = generateExecutionId();
661
+ if (config.enabled !== false) {
662
+ this.activate();
663
+ }
664
+ }
665
+ /**
666
+ * Get statistics about the defense layer.
667
+ */
668
+ getStats() {
669
+ return {
670
+ violationsBlocked: this.violations.length,
671
+ violations: [...this.violations],
672
+ isActive: this.isActivated
673
+ };
674
+ }
675
+ /**
676
+ * Clear stored violations. Useful for testing.
677
+ */
678
+ clearViolations() {
679
+ this.violations = [];
680
+ }
681
+ /**
682
+ * Get the execution ID for this worker.
683
+ */
684
+ getExecutionId() {
685
+ return this.executionId;
686
+ }
687
+ /**
688
+ * Deactivate the defense layer and restore original globals.
689
+ * Typically only needed for testing.
690
+ */
691
+ deactivate() {
692
+ if (!this.isActivated) {
693
+ return;
694
+ }
695
+ this.restorePatches();
696
+ this.isActivated = false;
697
+ }
698
+ /**
699
+ * Activate the defense layer by applying patches.
700
+ */
701
+ activate() {
702
+ if (this.isActivated) {
703
+ return;
704
+ }
705
+ try {
706
+ this.applyPatches();
707
+ this.isActivated = true;
708
+ } catch (error) {
709
+ this.restorePatches();
710
+ this.isActivated = false;
711
+ throw error;
712
+ }
713
+ }
714
+ /**
715
+ * Get a human-readable path for a target object and property.
716
+ */
717
+ getPathForTarget(target, prop) {
718
+ if (target === globalThis) {
719
+ return `globalThis.${prop}`;
720
+ }
721
+ if (typeof process !== "undefined" && target === process) {
722
+ return `process.${prop}`;
723
+ }
724
+ if (target === Error) {
725
+ return `Error.${prop}`;
726
+ }
727
+ if (target === Function.prototype) {
728
+ return `Function.prototype.${prop}`;
729
+ }
730
+ if (target === Object.prototype) {
731
+ return `Object.prototype.${prop}`;
732
+ }
733
+ return `<object>.${prop}`;
734
+ }
735
+ /**
736
+ * Record a violation and invoke the callback.
737
+ * In worker context, blocking always happens (no audit mode context check).
738
+ */
739
+ recordViolation(type, path, message) {
740
+ const violation = {
741
+ timestamp: getSafeTimestamp(),
742
+ type,
743
+ message,
744
+ path,
745
+ stack: new Error().stack,
746
+ executionId: this.executionId
747
+ };
748
+ if (this.violations.length < MAX_STORED_VIOLATIONS) {
749
+ this.violations.push(violation);
750
+ }
751
+ if (this.config.onViolation) {
752
+ try {
753
+ this.config.onViolation(violation);
754
+ } catch (e) {
755
+ console.debug(
756
+ "[WorkerDefenseInDepth] onViolation callback threw:",
757
+ e instanceof Error ? e.message : e
758
+ );
759
+ }
760
+ }
761
+ return violation;
762
+ }
763
+ /**
764
+ * Create a blocking proxy for a function.
765
+ * In worker context, always blocks (no context check needed).
766
+ */
767
+ createBlockingProxy(original, path, violationType) {
768
+ const self = this;
769
+ const auditMode = this.config.auditMode;
770
+ return new this.originalProxy(original, {
771
+ apply(target, thisArg, args) {
772
+ const message = `${path} is blocked in worker context`;
773
+ const violation = self.recordViolation(violationType, path, message);
774
+ if (!auditMode) {
775
+ throw new WorkerSecurityViolationError(message, violation);
776
+ }
777
+ return Reflect.apply(target, thisArg, args);
778
+ },
779
+ construct(target, args, newTarget) {
780
+ const message = `${path} constructor is blocked in worker context`;
781
+ const violation = self.recordViolation(violationType, path, message);
782
+ if (!auditMode) {
783
+ throw new WorkerSecurityViolationError(message, violation);
784
+ }
785
+ return Reflect.construct(target, args, newTarget);
786
+ }
787
+ });
788
+ }
789
+ /**
790
+ * Create a blocking proxy for an object (blocks all property access).
791
+ */
792
+ createBlockingObjectProxy(original, path, violationType, allowedKeys) {
793
+ const self = this;
794
+ const auditMode = this.config.auditMode;
795
+ return new this.originalProxy(original, {
796
+ get(target, prop, receiver) {
797
+ if (self.inTrap) {
798
+ return Reflect.get(target, prop, receiver);
799
+ }
800
+ if (allowedKeys && typeof prop === "string" && allowedKeys.has(prop)) {
801
+ return Reflect.get(target, prop, receiver);
802
+ }
803
+ self.inTrap = true;
804
+ try {
805
+ const fullPath = `${path}.${String(prop)}`;
806
+ const message = `${fullPath} is blocked in worker context`;
807
+ const violation = self.recordViolation(
808
+ violationType,
809
+ fullPath,
810
+ message
811
+ );
812
+ if (!auditMode) {
813
+ throw new WorkerSecurityViolationError(message, violation);
814
+ }
815
+ return Reflect.get(target, prop, receiver);
816
+ } finally {
817
+ self.inTrap = false;
818
+ }
819
+ },
820
+ set(target, prop, value, receiver) {
821
+ const setValue = () => path === "process.env" && prop === "DEBUG" ? Reflect.set(target, prop, value) : Reflect.set(target, prop, value, receiver);
822
+ if (self.inTrap) {
823
+ return setValue();
824
+ }
825
+ self.inTrap = true;
826
+ try {
827
+ const fullPath = `${path}.${String(prop)}`;
828
+ const message = `${fullPath} modification is blocked in worker context`;
829
+ const violation = self.recordViolation(
830
+ violationType,
831
+ fullPath,
832
+ message
833
+ );
834
+ if (!auditMode) {
835
+ throw new WorkerSecurityViolationError(message, violation);
836
+ }
837
+ return setValue();
838
+ } finally {
839
+ self.inTrap = false;
840
+ }
841
+ },
842
+ ownKeys(target) {
843
+ if (self.inTrap) {
844
+ return Reflect.ownKeys(target);
845
+ }
846
+ self.inTrap = true;
847
+ try {
848
+ const message = `${path} enumeration is blocked in worker context`;
849
+ const violation = self.recordViolation(violationType, path, message);
850
+ if (!auditMode) {
851
+ throw new WorkerSecurityViolationError(message, violation);
852
+ }
853
+ return Reflect.ownKeys(target);
854
+ } finally {
855
+ self.inTrap = false;
856
+ }
857
+ },
858
+ getOwnPropertyDescriptor(target, prop) {
859
+ if (self.inTrap) {
860
+ return Reflect.getOwnPropertyDescriptor(target, prop);
861
+ }
862
+ self.inTrap = true;
863
+ try {
864
+ const fullPath = `${path}.${String(prop)}`;
865
+ const message = `${fullPath} descriptor access is blocked in worker context`;
866
+ const violation = self.recordViolation(
867
+ violationType,
868
+ fullPath,
869
+ message
870
+ );
871
+ if (!auditMode) {
872
+ throw new WorkerSecurityViolationError(message, violation);
873
+ }
874
+ return Reflect.getOwnPropertyDescriptor(target, prop);
875
+ } finally {
876
+ self.inTrap = false;
877
+ }
878
+ },
879
+ has(target, prop) {
880
+ if (self.inTrap) {
881
+ return Reflect.has(target, prop);
882
+ }
883
+ self.inTrap = true;
884
+ try {
885
+ const fullPath = `${path}.${String(prop)}`;
886
+ const message = `${fullPath} existence check is blocked in worker context`;
887
+ const violation = self.recordViolation(
888
+ violationType,
889
+ fullPath,
890
+ message
891
+ );
892
+ if (!auditMode) {
893
+ throw new WorkerSecurityViolationError(message, violation);
894
+ }
895
+ return Reflect.has(target, prop);
896
+ } finally {
897
+ self.inTrap = false;
898
+ }
899
+ },
900
+ deleteProperty(target, prop) {
901
+ if (self.inTrap) {
902
+ return Reflect.deleteProperty(target, prop);
903
+ }
904
+ self.inTrap = true;
905
+ try {
906
+ const fullPath = `${path}.${String(prop)}`;
907
+ const message = `${fullPath} deletion is blocked in worker context`;
908
+ const violation = self.recordViolation(
909
+ violationType,
910
+ fullPath,
911
+ message
912
+ );
913
+ if (!auditMode) {
914
+ throw new WorkerSecurityViolationError(message, violation);
915
+ }
916
+ return Reflect.deleteProperty(target, prop);
917
+ } finally {
918
+ self.inTrap = false;
919
+ }
920
+ },
921
+ setPrototypeOf(target, proto) {
922
+ if (self.inTrap) {
923
+ return Reflect.setPrototypeOf(target, proto);
924
+ }
925
+ self.inTrap = true;
926
+ try {
927
+ const message = `${path} setPrototypeOf is blocked in worker context`;
928
+ const violation = self.recordViolation(violationType, path, message);
929
+ if (!auditMode) {
930
+ throw new WorkerSecurityViolationError(message, violation);
931
+ }
932
+ return Reflect.setPrototypeOf(target, proto);
933
+ } finally {
934
+ self.inTrap = false;
935
+ }
936
+ },
937
+ defineProperty(target, prop, descriptor) {
938
+ if (self.inTrap) {
939
+ return Reflect.defineProperty(target, prop, descriptor);
940
+ }
941
+ self.inTrap = true;
942
+ try {
943
+ const fullPath = `${path}.${String(prop)}`;
944
+ const message = `${fullPath} defineProperty is blocked in worker context`;
945
+ const violation = self.recordViolation(
946
+ violationType,
947
+ fullPath,
948
+ message
949
+ );
950
+ if (!auditMode) {
951
+ throw new WorkerSecurityViolationError(message, violation);
952
+ }
953
+ return Reflect.defineProperty(target, prop, descriptor);
954
+ } finally {
955
+ self.inTrap = false;
956
+ }
957
+ }
958
+ });
959
+ }
960
+ createReadonlyObjectProxy(original, path, violationType) {
961
+ const auditMode = this.config.auditMode;
962
+ const allowOrThrow = (operation) => {
963
+ const message = `${path} ${operation} is blocked in worker context`;
964
+ const violation = this.recordViolation(violationType, path, message);
965
+ if (!auditMode) {
966
+ throw new WorkerSecurityViolationError(message, violation);
967
+ }
968
+ };
969
+ return new this.originalProxy(original, {
970
+ set(target, prop, value, receiver) {
971
+ allowOrThrow("modification");
972
+ return Reflect.set(target, prop, value, receiver);
973
+ },
974
+ defineProperty(target, prop, descriptor) {
975
+ allowOrThrow("defineProperty");
976
+ return Reflect.defineProperty(target, prop, descriptor);
977
+ },
978
+ deleteProperty(target, prop) {
979
+ allowOrThrow("deletion");
980
+ return Reflect.deleteProperty(target, prop);
981
+ },
982
+ setPrototypeOf(target, prototype) {
983
+ allowOrThrow("setPrototypeOf");
984
+ return Reflect.setPrototypeOf(target, prototype);
985
+ },
986
+ preventExtensions(target) {
987
+ allowOrThrow("preventExtensions");
988
+ return Reflect.preventExtensions(target);
989
+ }
990
+ });
991
+ }
992
+ /**
993
+ * Apply security patches to dangerous globals.
994
+ */
995
+ applyPatches() {
996
+ this.patchFailures = [];
997
+ const blockedGlobals = getBlockedGlobals();
998
+ const excludeTypes = new Set(this.config.excludeViolationTypes ?? []);
999
+ const workerInfrastructureListenerMethods = /* @__PURE__ */ new Set([
1000
+ "on",
1001
+ "once",
1002
+ "addListener",
1003
+ "prependListener",
1004
+ "prependOnceListener"
1005
+ ]);
1006
+ const permanentIntrinsicPatches = [];
1007
+ for (const blocked of blockedGlobals) {
1008
+ if (excludeTypes.has(blocked.violationType)) {
1009
+ continue;
1010
+ }
1011
+ if (blocked.target === process && workerInfrastructureListenerMethods.has(blocked.prop)) {
1012
+ continue;
1013
+ }
1014
+ if (blocked.strategy === "freeze") {
1015
+ permanentIntrinsicPatches.push(blocked);
1016
+ continue;
1017
+ }
1018
+ this.applyPatch(blocked);
1019
+ }
1020
+ if (!excludeTypes.has("function_constructor")) {
1021
+ this.protectConstructorChain(excludeTypes);
1022
+ }
1023
+ if (!excludeTypes.has("error_prepare_stack_trace")) {
1024
+ this.protectErrorPrepareStackTrace();
1025
+ }
1026
+ if (!excludeTypes.has("module_load")) {
1027
+ this.protectModuleLoad();
1028
+ }
1029
+ if (!excludeTypes.has("module_resolve_filename")) {
1030
+ this.protectModuleResolveFilename();
1031
+ }
1032
+ if (!excludeTypes.has("process_main_module")) {
1033
+ this.protectProcessMainModule();
1034
+ }
1035
+ if (!excludeTypes.has("process_exec_path")) {
1036
+ this.protectProcessExecPath();
1037
+ }
1038
+ if (!excludeTypes.has("process_connected")) {
1039
+ this.protectProcessConnected();
1040
+ }
1041
+ if (!excludeTypes.has("proxy")) {
1042
+ this.protectProxyRevocable();
1043
+ }
1044
+ const criticalPaths = [
1045
+ "Function.prototype.constructor",
1046
+ "Module._load",
1047
+ "Module._resolveFilename"
1048
+ ];
1049
+ const criticalFailures = this.patchFailures.filter(
1050
+ (path) => criticalPaths.includes(path)
1051
+ );
1052
+ if (criticalFailures.length > 0) {
1053
+ this.restorePatches();
1054
+ throw new Error(
1055
+ `WorkerDefenseInDepth: critical patches failed: ${criticalFailures.join(", ")}`
1056
+ );
1057
+ }
1058
+ for (const blocked of permanentIntrinsicPatches) {
1059
+ this.applyPatch(blocked);
1060
+ }
1061
+ this.lockWellKnownSymbols();
1062
+ }
1063
+ /**
1064
+ * Lock well-known Symbol properties on built-in constructors/prototypes.
1065
+ */
1066
+ lockWellKnownSymbols() {
1067
+ const lock = (obj, sym) => {
1068
+ try {
1069
+ const desc = Object.getOwnPropertyDescriptor(obj, sym);
1070
+ if (desc?.configurable) {
1071
+ if ("value" in desc) {
1072
+ Object.defineProperty(obj, sym, {
1073
+ ...desc,
1074
+ configurable: false,
1075
+ writable: false
1076
+ });
1077
+ return;
1078
+ }
1079
+ Object.defineProperty(obj, sym, { ...desc, configurable: false });
1080
+ }
1081
+ } catch {
1082
+ }
1083
+ };
1084
+ for (const ctor of [Array, Map, Set, RegExp, Promise]) {
1085
+ lock(ctor, Symbol.species);
1086
+ }
1087
+ for (const proto of [
1088
+ Array.prototype,
1089
+ String.prototype,
1090
+ Map.prototype,
1091
+ Set.prototype
1092
+ ]) {
1093
+ lock(proto, Symbol.iterator);
1094
+ }
1095
+ lock(Symbol.prototype, Symbol.toPrimitive);
1096
+ lock(Date.prototype, Symbol.toPrimitive);
1097
+ for (const sym of [
1098
+ Symbol.match,
1099
+ Symbol.matchAll,
1100
+ Symbol.replace,
1101
+ Symbol.search,
1102
+ Symbol.split
1103
+ ]) {
1104
+ lock(RegExp.prototype, sym);
1105
+ }
1106
+ lock(Function.prototype, Symbol.hasInstance);
1107
+ lock(Array.prototype, Symbol.unscopables);
1108
+ for (const proto of [
1109
+ Map.prototype,
1110
+ Set.prototype,
1111
+ Promise.prototype,
1112
+ ArrayBuffer.prototype
1113
+ ]) {
1114
+ lock(proto, Symbol.toStringTag);
1115
+ }
1116
+ }
1117
+ /**
1118
+ * Block Proxy.revocable to prevent bypassing Proxy constructor blocking.
1119
+ *
1120
+ * Proxy.revocable internally uses the real Proxy constructor, so it bypasses
1121
+ * our blocking proxy on globalThis.Proxy. We replace it with a wrapper that
1122
+ * always blocks in worker context.
1123
+ */
1124
+ protectProxyRevocable() {
1125
+ const self = this;
1126
+ const auditMode = this.config.auditMode;
1127
+ try {
1128
+ const originalRevocable = this.originalProxy.revocable;
1129
+ if (typeof originalRevocable !== "function") return;
1130
+ const descriptor = Object.getOwnPropertyDescriptor(
1131
+ this.originalProxy,
1132
+ "revocable"
1133
+ );
1134
+ this.originalDescriptors.push({
1135
+ target: this.originalProxy,
1136
+ prop: "revocable",
1137
+ descriptor
1138
+ });
1139
+ Object.defineProperty(this.originalProxy, "revocable", {
1140
+ value: function revocable(_target, _handler) {
1141
+ const message = "Proxy.revocable is blocked in worker context";
1142
+ const violation = self.recordViolation(
1143
+ "proxy",
1144
+ "Proxy.revocable",
1145
+ message
1146
+ );
1147
+ if (!auditMode) {
1148
+ throw new WorkerSecurityViolationError(message, violation);
1149
+ }
1150
+ return originalRevocable(_target, _handler);
1151
+ },
1152
+ writable: false,
1153
+ configurable: true
1154
+ // Must be configurable for restoration
1155
+ });
1156
+ } catch {
1157
+ }
1158
+ }
1159
+ /**
1160
+ * Protect against .constructor.constructor escape vector.
1161
+ * @param excludeTypes - Set of violation types to skip
1162
+ */
1163
+ protectConstructorChain(excludeTypes) {
1164
+ let AsyncFunction = null;
1165
+ let GeneratorFunction = null;
1166
+ let AsyncGeneratorFunction = null;
1167
+ try {
1168
+ AsyncFunction = Object.getPrototypeOf(async () => {
1169
+ }).constructor;
1170
+ } catch {
1171
+ }
1172
+ try {
1173
+ GeneratorFunction = Object.getPrototypeOf(function* () {
1174
+ }).constructor;
1175
+ } catch {
1176
+ }
1177
+ try {
1178
+ AsyncGeneratorFunction = Object.getPrototypeOf(
1179
+ async function* () {
1180
+ }
1181
+ ).constructor;
1182
+ } catch {
1183
+ }
1184
+ this.patchPrototypeConstructor(
1185
+ Function.prototype,
1186
+ "Function.prototype.constructor",
1187
+ "function_constructor"
1188
+ );
1189
+ if (!excludeTypes.has("async_function_constructor") && AsyncFunction && AsyncFunction !== Function) {
1190
+ this.patchPrototypeConstructor(
1191
+ AsyncFunction.prototype,
1192
+ "AsyncFunction.prototype.constructor",
1193
+ "async_function_constructor"
1194
+ );
1195
+ }
1196
+ if (!excludeTypes.has("generator_function_constructor") && GeneratorFunction && GeneratorFunction !== Function) {
1197
+ this.patchPrototypeConstructor(
1198
+ GeneratorFunction.prototype,
1199
+ "GeneratorFunction.prototype.constructor",
1200
+ "generator_function_constructor"
1201
+ );
1202
+ }
1203
+ if (!excludeTypes.has("async_generator_function_constructor") && AsyncGeneratorFunction && AsyncGeneratorFunction !== Function && AsyncGeneratorFunction !== AsyncFunction) {
1204
+ this.patchPrototypeConstructor(
1205
+ AsyncGeneratorFunction.prototype,
1206
+ "AsyncGeneratorFunction.prototype.constructor",
1207
+ "async_generator_function_constructor"
1208
+ );
1209
+ }
1210
+ }
1211
+ /**
1212
+ * Protect Error.prepareStackTrace from being set.
1213
+ */
1214
+ protectErrorPrepareStackTrace() {
1215
+ const self = this;
1216
+ const auditMode = this.config.auditMode;
1217
+ try {
1218
+ const originalDescriptor = Object.getOwnPropertyDescriptor(
1219
+ Error,
1220
+ "prepareStackTrace"
1221
+ );
1222
+ this.originalDescriptors.push({
1223
+ target: Error,
1224
+ prop: "prepareStackTrace",
1225
+ descriptor: originalDescriptor
1226
+ });
1227
+ let currentValue = originalDescriptor?.value;
1228
+ Object.defineProperty(Error, "prepareStackTrace", {
1229
+ get() {
1230
+ return currentValue;
1231
+ },
1232
+ set(value) {
1233
+ const message = "Error.prepareStackTrace modification is blocked in worker context";
1234
+ const violation = self.recordViolation(
1235
+ "error_prepare_stack_trace",
1236
+ "Error.prepareStackTrace",
1237
+ message
1238
+ );
1239
+ if (!auditMode) {
1240
+ throw new WorkerSecurityViolationError(message, violation);
1241
+ }
1242
+ currentValue = value;
1243
+ },
1244
+ configurable: true
1245
+ });
1246
+ } catch {
1247
+ }
1248
+ }
1249
+ /**
1250
+ * Patch a prototype's constructor property.
1251
+ *
1252
+ * Returns a proxy that allows reading properties (like .name) but blocks
1253
+ * calling the constructor as a function (which would allow code execution).
1254
+ */
1255
+ patchPrototypeConstructor(prototype, path, violationType) {
1256
+ const self = this;
1257
+ const auditMode = this.config.auditMode;
1258
+ try {
1259
+ const originalDescriptor = Object.getOwnPropertyDescriptor(
1260
+ prototype,
1261
+ "constructor"
1262
+ );
1263
+ this.originalDescriptors.push({
1264
+ target: prototype,
1265
+ prop: "constructor",
1266
+ descriptor: originalDescriptor
1267
+ });
1268
+ const originalValue = originalDescriptor?.value;
1269
+ const constructorProxy = originalValue && typeof originalValue === "function" ? new this.originalProxy(originalValue, {
1270
+ apply(_target, _thisArg, _args) {
1271
+ const message = `${path} invocation is blocked in worker context`;
1272
+ const violation = self.recordViolation(
1273
+ violationType,
1274
+ path,
1275
+ message
1276
+ );
1277
+ if (!auditMode) {
1278
+ throw new WorkerSecurityViolationError(message, violation);
1279
+ }
1280
+ return void 0;
1281
+ },
1282
+ construct(_target, _args, _newTarget) {
1283
+ const message = `${path} construction is blocked in worker context`;
1284
+ const violation = self.recordViolation(
1285
+ violationType,
1286
+ path,
1287
+ message
1288
+ );
1289
+ if (!auditMode) {
1290
+ throw new WorkerSecurityViolationError(message, violation);
1291
+ }
1292
+ return {};
1293
+ },
1294
+ // Allow all property access (like .name, .prototype, etc.)
1295
+ get(target, prop, receiver) {
1296
+ return Reflect.get(target, prop, receiver);
1297
+ },
1298
+ getPrototypeOf(target) {
1299
+ return Reflect.getPrototypeOf(target);
1300
+ },
1301
+ has(target, prop) {
1302
+ return Reflect.has(target, prop);
1303
+ },
1304
+ ownKeys(target) {
1305
+ return Reflect.ownKeys(target);
1306
+ },
1307
+ getOwnPropertyDescriptor(target, prop) {
1308
+ return Reflect.getOwnPropertyDescriptor(target, prop);
1309
+ }
1310
+ }) : originalValue;
1311
+ Object.defineProperty(prototype, "constructor", {
1312
+ get() {
1313
+ return constructorProxy;
1314
+ },
1315
+ set(value) {
1316
+ const message = `${path} modification is blocked in worker context`;
1317
+ const violation = self.recordViolation(violationType, path, message);
1318
+ if (!auditMode) {
1319
+ throw new WorkerSecurityViolationError(message, violation);
1320
+ }
1321
+ Object.defineProperty(this, "constructor", {
1322
+ value,
1323
+ writable: true,
1324
+ configurable: true
1325
+ });
1326
+ },
1327
+ configurable: true
1328
+ });
1329
+ } catch {
1330
+ this.patchFailures.push(path);
1331
+ }
1332
+ }
1333
+ /**
1334
+ * Protect process.mainModule from being accessed or set.
1335
+ *
1336
+ * The attack vector is:
1337
+ * ```
1338
+ * process.mainModule.require('child_process').execSync('whoami')
1339
+ * process.mainModule.constructor._load('vm')
1340
+ * ```
1341
+ *
1342
+ * process.mainModule may be undefined in ESM contexts but could exist in
1343
+ * CommonJS workers. We block both reading and setting.
1344
+ */
1345
+ protectProcessMainModule() {
1346
+ if (typeof process === "undefined") return;
1347
+ const self = this;
1348
+ const auditMode = this.config.auditMode;
1349
+ try {
1350
+ const originalDescriptor = Object.getOwnPropertyDescriptor(
1351
+ process,
1352
+ "mainModule"
1353
+ );
1354
+ this.originalDescriptors.push({
1355
+ target: process,
1356
+ prop: "mainModule",
1357
+ descriptor: originalDescriptor
1358
+ });
1359
+ const currentValue = originalDescriptor?.value;
1360
+ if (currentValue !== void 0) {
1361
+ Object.defineProperty(process, "mainModule", {
1362
+ get() {
1363
+ const message = "process.mainModule access is blocked in worker context";
1364
+ const violation = self.recordViolation(
1365
+ "process_main_module",
1366
+ "process.mainModule",
1367
+ message
1368
+ );
1369
+ if (!auditMode) {
1370
+ throw new WorkerSecurityViolationError(message, violation);
1371
+ }
1372
+ return currentValue;
1373
+ },
1374
+ set(value) {
1375
+ const message = "process.mainModule modification is blocked in worker context";
1376
+ const violation = self.recordViolation(
1377
+ "process_main_module",
1378
+ "process.mainModule",
1379
+ message
1380
+ );
1381
+ if (!auditMode) {
1382
+ throw new WorkerSecurityViolationError(message, violation);
1383
+ }
1384
+ Object.defineProperty(process, "mainModule", {
1385
+ value,
1386
+ writable: true,
1387
+ configurable: true
1388
+ });
1389
+ },
1390
+ configurable: true
1391
+ });
1392
+ }
1393
+ } catch {
1394
+ }
1395
+ }
1396
+ /**
1397
+ * Protect process.execPath from being read or set in worker context.
1398
+ *
1399
+ * process.execPath is a string primitive (not an object), so it cannot be
1400
+ * proxied via the normal blocked globals mechanism. We use Object.defineProperty
1401
+ * with getter/setter (same pattern as protectProcessMainModule).
1402
+ */
1403
+ protectProcessExecPath() {
1404
+ if (typeof process === "undefined") return;
1405
+ const self = this;
1406
+ const auditMode = this.config.auditMode;
1407
+ try {
1408
+ const originalDescriptor = Object.getOwnPropertyDescriptor(
1409
+ process,
1410
+ "execPath"
1411
+ );
1412
+ this.originalDescriptors.push({
1413
+ target: process,
1414
+ prop: "execPath",
1415
+ descriptor: originalDescriptor
1416
+ });
1417
+ const currentValue = originalDescriptor?.value ?? process.execPath;
1418
+ Object.defineProperty(process, "execPath", {
1419
+ get() {
1420
+ const message = "process.execPath access is blocked in worker context";
1421
+ const violation = self.recordViolation(
1422
+ "process_exec_path",
1423
+ "process.execPath",
1424
+ message
1425
+ );
1426
+ if (!auditMode) {
1427
+ throw new WorkerSecurityViolationError(message, violation);
1428
+ }
1429
+ return currentValue;
1430
+ },
1431
+ set(value) {
1432
+ const message = "process.execPath modification is blocked in worker context";
1433
+ const violation = self.recordViolation(
1434
+ "process_exec_path",
1435
+ "process.execPath",
1436
+ message
1437
+ );
1438
+ if (!auditMode) {
1439
+ throw new WorkerSecurityViolationError(message, violation);
1440
+ }
1441
+ Object.defineProperty(process, "execPath", {
1442
+ value,
1443
+ writable: true,
1444
+ configurable: true
1445
+ });
1446
+ },
1447
+ configurable: true
1448
+ });
1449
+ } catch {
1450
+ }
1451
+ }
1452
+ /**
1453
+ * Protect process.connected from being read or set in worker context.
1454
+ *
1455
+ * process.connected is a boolean primitive (not an object), so it cannot be
1456
+ * proxied via the normal blocked globals mechanism. We use Object.defineProperty
1457
+ * with getter/setter (same pattern as protectProcessExecPath).
1458
+ *
1459
+ * Only protects if process.connected exists (IPC contexts).
1460
+ */
1461
+ protectProcessConnected() {
1462
+ if (typeof process === "undefined") return;
1463
+ if (process.connected === void 0) return;
1464
+ const self = this;
1465
+ const auditMode = this.config.auditMode;
1466
+ try {
1467
+ const originalDescriptor = Object.getOwnPropertyDescriptor(
1468
+ process,
1469
+ "connected"
1470
+ );
1471
+ this.originalDescriptors.push({
1472
+ target: process,
1473
+ prop: "connected",
1474
+ descriptor: originalDescriptor
1475
+ });
1476
+ const currentValue = originalDescriptor?.value ?? process.connected;
1477
+ Object.defineProperty(process, "connected", {
1478
+ get() {
1479
+ const message = "process.connected access is blocked in worker context";
1480
+ const violation = self.recordViolation(
1481
+ "process_connected",
1482
+ "process.connected",
1483
+ message
1484
+ );
1485
+ if (!auditMode) {
1486
+ throw new WorkerSecurityViolationError(message, violation);
1487
+ }
1488
+ return currentValue;
1489
+ },
1490
+ set(value) {
1491
+ const message = "process.connected modification is blocked in worker context";
1492
+ const violation = self.recordViolation(
1493
+ "process_connected",
1494
+ "process.connected",
1495
+ message
1496
+ );
1497
+ if (!auditMode) {
1498
+ throw new WorkerSecurityViolationError(message, violation);
1499
+ }
1500
+ Object.defineProperty(process, "connected", {
1501
+ value,
1502
+ writable: true,
1503
+ configurable: true
1504
+ });
1505
+ },
1506
+ configurable: true
1507
+ });
1508
+ } catch {
1509
+ }
1510
+ }
1511
+ /**
1512
+ * Protect Module._load from being called.
1513
+ *
1514
+ * The attack vector is:
1515
+ * ```
1516
+ * module.constructor._load('child_process')
1517
+ * require.main.constructor._load('vm')
1518
+ * ```
1519
+ *
1520
+ * We access the Module class and replace _load with a blocking proxy.
1521
+ */
1522
+ protectModuleLoad() {
1523
+ this.protectModuleMethod("_load", "module_load");
1524
+ }
1525
+ /**
1526
+ * Protect Module._resolveFilename from being called in worker context.
1527
+ *
1528
+ * Module._resolveFilename is called for both require() and import() resolution.
1529
+ * Blocking it catches file-based import() specifiers.
1530
+ *
1531
+ * data: and blob: URLs are handled by ESM loader hooks registered
1532
+ * in the main thread (DefenseInDepthBox.protectDynamicImport).
1533
+ */
1534
+ protectModuleResolveFilename() {
1535
+ this.protectModuleMethod("_resolveFilename", "module_resolve_filename");
1536
+ }
1537
+ protectModuleMethod(prop, violationType) {
1538
+ const path = `Module.${prop}`;
1539
+ const self = this;
1540
+ const auditMode = this.config.auditMode;
1541
+ try {
1542
+ const ModuleClass = nodeModuleClass2;
1543
+ const original = ModuleClass?.[prop];
1544
+ if (!ModuleClass || typeof original !== "function") {
1545
+ throw new Error("node:module Module class or method is unavailable");
1546
+ }
1547
+ const descriptor = Object.getOwnPropertyDescriptor(ModuleClass, prop);
1548
+ if (!descriptor) throw new Error("method descriptor is unavailable");
1549
+ if (descriptor.configurable === false && descriptor.writable === false) {
1550
+ throw new Error("method is non-configurable and non-writable");
1551
+ }
1552
+ const proxy = new this.originalProxy(
1553
+ original,
1554
+ {
1555
+ apply(target, thisArg, args) {
1556
+ const message = `${path} is blocked in worker context`;
1557
+ const violation = self.recordViolation(
1558
+ violationType,
1559
+ path,
1560
+ message
1561
+ );
1562
+ if (!auditMode) {
1563
+ throw new WorkerSecurityViolationError(message, violation);
1564
+ }
1565
+ return Reflect.apply(target, thisArg, args);
1566
+ }
1567
+ }
1568
+ );
1569
+ this.originalDescriptors.push({
1570
+ target: ModuleClass,
1571
+ prop,
1572
+ descriptor
1573
+ });
1574
+ Object.defineProperty(ModuleClass, prop, {
1575
+ ...descriptor,
1576
+ value: proxy
1577
+ });
1578
+ const installed = Object.getOwnPropertyDescriptor(ModuleClass, prop);
1579
+ if (ModuleClass[prop] !== proxy || installed?.value !== proxy) {
1580
+ throw new Error("installed patch failed verification");
1581
+ }
1582
+ } catch {
1583
+ this.patchFailures.push(path);
1584
+ }
1585
+ }
1586
+ /**
1587
+ * Apply a single patch to a blocked global.
1588
+ */
1589
+ applyPatch(blocked) {
1590
+ const { target, prop, violationType, strategy } = blocked;
1591
+ try {
1592
+ const original = target[prop];
1593
+ if (original === void 0) {
1594
+ return;
1595
+ }
1596
+ const descriptor = Object.getOwnPropertyDescriptor(target, prop);
1597
+ this.originalDescriptors.push({ target, prop, descriptor });
1598
+ if (strategy === "freeze") {
1599
+ if (typeof original === "object" && original !== null) {
1600
+ Object.freeze(original);
1601
+ const path = this.getPathForTarget(target, prop);
1602
+ const proxy = this.createReadonlyObjectProxy(
1603
+ original,
1604
+ path,
1605
+ violationType
1606
+ );
1607
+ Object.defineProperty(target, prop, {
1608
+ ...descriptor,
1609
+ value: proxy
1610
+ });
1611
+ }
1612
+ } else {
1613
+ const path = this.getPathForTarget(target, prop);
1614
+ const proxy = typeof original === "function" ? this.createBlockingProxy(
1615
+ original,
1616
+ path,
1617
+ violationType
1618
+ ) : this.createBlockingObjectProxy(
1619
+ original,
1620
+ path,
1621
+ violationType,
1622
+ blocked.allowedKeys
1623
+ );
1624
+ Object.defineProperty(target, prop, {
1625
+ value: proxy,
1626
+ writable: true,
1627
+ configurable: true
1628
+ });
1629
+ }
1630
+ } catch {
1631
+ }
1632
+ }
1633
+ /**
1634
+ * Restore all original values.
1635
+ */
1636
+ restorePatches() {
1637
+ for (let i = this.originalDescriptors.length - 1; i >= 0; i--) {
1638
+ const { target, prop, descriptor } = this.originalDescriptors[i];
1639
+ try {
1640
+ if (descriptor) {
1641
+ Object.defineProperty(target, prop, descriptor);
1642
+ } else {
1643
+ delete target[prop];
1644
+ }
1645
+ } catch {
1646
+ }
1647
+ }
1648
+ this.originalDescriptors = [];
1649
+ }
1650
+ };
1651
+
1652
+ // src/security/wasm-callback.ts
1653
+ function sanitizeUnknownError(error) {
1654
+ const message = error instanceof Error ? error.message : String(error);
1655
+ return sanitizeErrorMessage(message);
1656
+ }
1657
+ function wrapWasmCallback(component, phase, callback) {
1658
+ return (...args) => {
1659
+ try {
1660
+ return callback(...args);
1661
+ } catch (error) {
1662
+ const message = sanitizeUnknownError(error);
1663
+ throw new Error(`${component} ${phase} callback failed: ${message}`);
1664
+ }
1665
+ };
1666
+ }
1667
+
1668
+ // src/security/trusted-globals.ts
1669
+ var _SharedArrayBuffer = globalThis.SharedArrayBuffer;
1670
+ var _Atomics = globalThis.Atomics;
1671
+ var _performanceNow = performance.now.bind(performance);
1672
+ var _Headers = globalThis.Headers;
1673
+ var _Proxy = globalThis.Proxy;
1674
+
1675
+ // src/commands/worker-bridge/protocol.ts
1676
+ var OpCode = {
1677
+ NOOP: 0,
1678
+ READ_FILE: 1,
1679
+ WRITE_FILE: 2,
1680
+ STAT: 3,
1681
+ READDIR: 4,
1682
+ MKDIR: 5,
1683
+ RM: 6,
1684
+ EXISTS: 7,
1685
+ APPEND_FILE: 8,
1686
+ SYMLINK: 9,
1687
+ READLINK: 10,
1688
+ LSTAT: 11,
1689
+ CHMOD: 12,
1690
+ REALPATH: 13,
1691
+ RENAME: 14,
1692
+ COPY_FILE: 15,
1693
+ // Special operations for I/O
1694
+ WRITE_STDOUT: 100,
1695
+ WRITE_STDERR: 101,
1696
+ EXIT: 102,
1697
+ // HTTP operations
1698
+ HTTP_REQUEST: 200,
1699
+ // Sub-shell execution
1700
+ EXEC_COMMAND: 300,
1701
+ // Tool invocation (executor mode)
1702
+ INVOKE_TOOL: 400
1703
+ };
1704
+ var Status = {
1705
+ PENDING: 0,
1706
+ READY: 1,
1707
+ SUCCESS: 2,
1708
+ ERROR: 3
1709
+ };
1710
+ var ErrorCode = {
1711
+ NONE: 0,
1712
+ NOT_FOUND: 1,
1713
+ IS_DIRECTORY: 2,
1714
+ NOT_DIRECTORY: 3,
1715
+ EXISTS: 4,
1716
+ PERMISSION_DENIED: 5,
1717
+ INVALID_PATH: 6,
1718
+ IO_ERROR: 7,
1719
+ TIMEOUT: 8,
1720
+ NETWORK_ERROR: 9,
1721
+ NETWORK_NOT_CONFIGURED: 10
1722
+ };
1723
+ var Offset = {
1724
+ OP_CODE: 0,
1725
+ STATUS: 4,
1726
+ PATH_LENGTH: 8,
1727
+ DATA_LENGTH: 12,
1728
+ RESULT_LENGTH: 16,
1729
+ ERROR_CODE: 20,
1730
+ FLAGS: 24,
1731
+ MODE: 28,
1732
+ PATH_BUFFER: 32,
1733
+ DATA_BUFFER: 4128
1734
+ // 32 + 4096
1735
+ };
1736
+ var Size = {
1737
+ CONTROL_REGION: 32,
1738
+ PATH_BUFFER: 4096,
1739
+ // 8MB limit for FS read/write, HTTP responses, and tool invocation results.
1740
+ // Sized to handle typical OpenAPI/GraphQL responses (paginated lists, batch queries).
1741
+ // Still well under the 64MB QuickJS memory limit per execution.
1742
+ DATA_BUFFER: 8388608,
1743
+ TOTAL: 8392736
1744
+ // 32 + 4096 + 8MB
1745
+ };
1746
+ var Flags = {
1747
+ NONE: 0,
1748
+ RECURSIVE: 1,
1749
+ FORCE: 2,
1750
+ MKDIR_RECURSIVE: 1
1751
+ };
1752
+ var StatLayout = {
1753
+ IS_FILE: 0,
1754
+ IS_DIRECTORY: 1,
1755
+ IS_SYMLINK: 2,
1756
+ MODE: 4,
1757
+ SIZE: 8,
1758
+ MTIME: 16,
1759
+ TOTAL: 24
1760
+ };
1761
+ var ProtocolBuffer = class {
1762
+ int32View;
1763
+ uint8View;
1764
+ dataView;
1765
+ constructor(buffer) {
1766
+ this.int32View = new Int32Array(buffer);
1767
+ this.uint8View = new Uint8Array(buffer);
1768
+ this.dataView = new DataView(buffer);
1769
+ }
1770
+ getOpCode() {
1771
+ return _Atomics.load(this.int32View, Offset.OP_CODE / 4);
1772
+ }
1773
+ setOpCode(code) {
1774
+ _Atomics.store(this.int32View, Offset.OP_CODE / 4, code);
1775
+ }
1776
+ getStatus() {
1777
+ return _Atomics.load(this.int32View, Offset.STATUS / 4);
1778
+ }
1779
+ setStatus(status) {
1780
+ _Atomics.store(this.int32View, Offset.STATUS / 4, status);
1781
+ }
1782
+ getPathLength() {
1783
+ return _Atomics.load(this.int32View, Offset.PATH_LENGTH / 4);
1784
+ }
1785
+ setPathLength(length) {
1786
+ _Atomics.store(this.int32View, Offset.PATH_LENGTH / 4, length);
1787
+ }
1788
+ getDataLength() {
1789
+ return _Atomics.load(this.int32View, Offset.DATA_LENGTH / 4);
1790
+ }
1791
+ setDataLength(length) {
1792
+ _Atomics.store(this.int32View, Offset.DATA_LENGTH / 4, length);
1793
+ }
1794
+ getResultLength() {
1795
+ return _Atomics.load(this.int32View, Offset.RESULT_LENGTH / 4);
1796
+ }
1797
+ setResultLength(length) {
1798
+ _Atomics.store(this.int32View, Offset.RESULT_LENGTH / 4, length);
1799
+ }
1800
+ getErrorCode() {
1801
+ return _Atomics.load(
1802
+ this.int32View,
1803
+ Offset.ERROR_CODE / 4
1804
+ );
1805
+ }
1806
+ setErrorCode(code) {
1807
+ _Atomics.store(this.int32View, Offset.ERROR_CODE / 4, code);
1808
+ }
1809
+ getFlags() {
1810
+ return _Atomics.load(this.int32View, Offset.FLAGS / 4);
1811
+ }
1812
+ setFlags(flags) {
1813
+ _Atomics.store(this.int32View, Offset.FLAGS / 4, flags);
1814
+ }
1815
+ getMode() {
1816
+ return _Atomics.load(this.int32View, Offset.MODE / 4);
1817
+ }
1818
+ setMode(mode) {
1819
+ _Atomics.store(this.int32View, Offset.MODE / 4, mode);
1820
+ }
1821
+ getPath() {
1822
+ const length = this.getPathLength();
1823
+ const bytes = this.uint8View.slice(
1824
+ Offset.PATH_BUFFER,
1825
+ Offset.PATH_BUFFER + length
1826
+ );
1827
+ return new TextDecoder().decode(bytes);
1828
+ }
1829
+ setPath(path) {
1830
+ const encoded = new TextEncoder().encode(path);
1831
+ if (encoded.length > Size.PATH_BUFFER) {
1832
+ throw new Error(`Path too long: ${encoded.length} > ${Size.PATH_BUFFER}`);
1833
+ }
1834
+ this.uint8View.set(encoded, Offset.PATH_BUFFER);
1835
+ this.setPathLength(encoded.length);
1836
+ }
1837
+ getData() {
1838
+ const length = this.getDataLength();
1839
+ return this.uint8View.slice(
1840
+ Offset.DATA_BUFFER,
1841
+ Offset.DATA_BUFFER + length
1842
+ );
1843
+ }
1844
+ setData(data) {
1845
+ if (data.length > Size.DATA_BUFFER) {
1846
+ throw new Error(`Data too large: ${data.length} > ${Size.DATA_BUFFER}`);
1847
+ }
1848
+ this.uint8View.set(data, Offset.DATA_BUFFER);
1849
+ this.setDataLength(data.length);
1850
+ }
1851
+ getDataAsString() {
1852
+ const data = this.getData();
1853
+ return new TextDecoder().decode(data);
1854
+ }
1855
+ setDataFromString(str) {
1856
+ const encoded = new TextEncoder().encode(str);
1857
+ this.setData(encoded);
1858
+ }
1859
+ getResult() {
1860
+ const length = this.getResultLength();
1861
+ return this.uint8View.slice(
1862
+ Offset.DATA_BUFFER,
1863
+ Offset.DATA_BUFFER + length
1864
+ );
1865
+ }
1866
+ setResult(data) {
1867
+ if (data.length > Size.DATA_BUFFER) {
1868
+ throw new Error(`Result too large: ${data.length} > ${Size.DATA_BUFFER}`);
1869
+ }
1870
+ this.uint8View.set(data, Offset.DATA_BUFFER);
1871
+ this.setResultLength(data.length);
1872
+ }
1873
+ getResultAsString() {
1874
+ const result = this.getResult();
1875
+ return new TextDecoder().decode(result);
1876
+ }
1877
+ setResultFromString(str) {
1878
+ const encoded = new TextEncoder().encode(str);
1879
+ this.setResult(encoded);
1880
+ }
1881
+ encodeStat(stat) {
1882
+ this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_FILE] = stat.isFile ? 1 : 0;
1883
+ this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_DIRECTORY] = stat.isDirectory ? 1 : 0;
1884
+ this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_SYMLINK] = stat.isSymbolicLink ? 1 : 0;
1885
+ this.dataView.setInt32(
1886
+ Offset.DATA_BUFFER + StatLayout.MODE,
1887
+ stat.mode,
1888
+ true
1889
+ );
1890
+ const size = Math.min(stat.size, Number.MAX_SAFE_INTEGER);
1891
+ this.dataView.setFloat64(Offset.DATA_BUFFER + StatLayout.SIZE, size, true);
1892
+ this.dataView.setFloat64(
1893
+ Offset.DATA_BUFFER + StatLayout.MTIME,
1894
+ stat.mtime.getTime(),
1895
+ true
1896
+ );
1897
+ this.setResultLength(StatLayout.TOTAL);
1898
+ }
1899
+ decodeStat() {
1900
+ return {
1901
+ isFile: this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_FILE] === 1,
1902
+ isDirectory: this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_DIRECTORY] === 1,
1903
+ isSymbolicLink: this.uint8View[Offset.DATA_BUFFER + StatLayout.IS_SYMLINK] === 1,
1904
+ mode: this.dataView.getInt32(Offset.DATA_BUFFER + StatLayout.MODE, true),
1905
+ size: this.dataView.getFloat64(
1906
+ Offset.DATA_BUFFER + StatLayout.SIZE,
1907
+ true
1908
+ ),
1909
+ mtime: new Date(
1910
+ this.dataView.getFloat64(Offset.DATA_BUFFER + StatLayout.MTIME, true)
1911
+ )
1912
+ };
1913
+ }
1914
+ waitForReady(timeout) {
1915
+ return _Atomics.wait(
1916
+ this.int32View,
1917
+ Offset.STATUS / 4,
1918
+ Status.PENDING,
1919
+ timeout
1920
+ );
1921
+ }
1922
+ waitForReadyAsync(timeout) {
1923
+ return _Atomics.waitAsync(
1924
+ this.int32View,
1925
+ Offset.STATUS / 4,
1926
+ Status.PENDING,
1927
+ timeout
1928
+ );
1929
+ }
1930
+ /**
1931
+ * Wait for status to become READY.
1932
+ * Returns immediately if status is already READY, or waits until it changes.
1933
+ */
1934
+ async waitUntilReady(timeout) {
1935
+ const startTime = Date.now();
1936
+ while (true) {
1937
+ const status = this.getStatus();
1938
+ if (status === Status.READY) {
1939
+ return true;
1940
+ }
1941
+ const elapsed = Date.now() - startTime;
1942
+ if (elapsed >= timeout) {
1943
+ return false;
1944
+ }
1945
+ const remainingMs = timeout - elapsed;
1946
+ const result = _Atomics.waitAsync(
1947
+ this.int32View,
1948
+ Offset.STATUS / 4,
1949
+ status,
1950
+ remainingMs
1951
+ );
1952
+ if (result.async) {
1953
+ const waitResult = await result.value;
1954
+ if (waitResult === "timed-out") {
1955
+ return false;
1956
+ }
1957
+ }
1958
+ }
1959
+ }
1960
+ waitForResult(timeout) {
1961
+ return _Atomics.wait(
1962
+ this.int32View,
1963
+ Offset.STATUS / 4,
1964
+ Status.READY,
1965
+ timeout
1966
+ );
1967
+ }
1968
+ notify() {
1969
+ return _Atomics.notify(this.int32View, Offset.STATUS / 4);
1970
+ }
1971
+ reset() {
1972
+ this.setOpCode(OpCode.NOOP);
1973
+ this.setStatus(Status.PENDING);
1974
+ this.setPathLength(0);
1975
+ this.setDataLength(0);
1976
+ this.setResultLength(0);
1977
+ this.setErrorCode(ErrorCode.NONE);
1978
+ this.setFlags(Flags.NONE);
1979
+ this.setMode(0);
1980
+ }
1981
+ };
1982
+
1983
+ // src/commands/worker-bridge/sync-backend.ts
1984
+ var SyncBackend = class {
1985
+ protocol;
1986
+ operationTimeoutMs;
1987
+ constructor(sharedBuffer, operationTimeoutMs = 3e4) {
1988
+ this.protocol = new ProtocolBuffer(sharedBuffer);
1989
+ this.operationTimeoutMs = operationTimeoutMs;
1990
+ }
1991
+ execSync(opCode, path, data, flags = 0, mode = 0) {
1992
+ this.protocol.reset();
1993
+ this.protocol.setOpCode(opCode);
1994
+ this.protocol.setPath(path);
1995
+ this.protocol.setFlags(flags);
1996
+ this.protocol.setMode(mode);
1997
+ if (data) {
1998
+ this.protocol.setData(data);
1999
+ }
2000
+ this.protocol.setStatus(Status.READY);
2001
+ this.protocol.notify();
2002
+ const waitResult = this.protocol.waitForResult(this.operationTimeoutMs);
2003
+ if (waitResult === "timed-out") {
2004
+ return { success: false, error: "Operation timed out" };
2005
+ }
2006
+ const status = this.protocol.getStatus();
2007
+ if (status === Status.SUCCESS) {
2008
+ return { success: true, result: this.protocol.getResult() };
2009
+ }
2010
+ return {
2011
+ success: false,
2012
+ error: this.protocol.getResultAsString() || `Error code: ${this.protocol.getErrorCode()}`
2013
+ };
2014
+ }
2015
+ readFile(path) {
2016
+ const result = this.execSync(OpCode.READ_FILE, path);
2017
+ if (!result.success) {
2018
+ throw new Error(result.error || "Failed to read file");
2019
+ }
2020
+ return result.result ?? new Uint8Array(0);
2021
+ }
2022
+ writeFile(path, data) {
2023
+ const result = this.execSync(OpCode.WRITE_FILE, path, data);
2024
+ if (!result.success) {
2025
+ throw new Error(result.error || "Failed to write file");
2026
+ }
2027
+ }
2028
+ stat(path) {
2029
+ const result = this.execSync(OpCode.STAT, path);
2030
+ if (!result.success) {
2031
+ throw new Error(result.error || "Failed to stat");
2032
+ }
2033
+ return this.protocol.decodeStat();
2034
+ }
2035
+ lstat(path) {
2036
+ const result = this.execSync(OpCode.LSTAT, path);
2037
+ if (!result.success) {
2038
+ throw new Error(result.error || "Failed to lstat");
2039
+ }
2040
+ return this.protocol.decodeStat();
2041
+ }
2042
+ readdir(path) {
2043
+ const result = this.execSync(OpCode.READDIR, path);
2044
+ if (!result.success) {
2045
+ throw new Error(result.error || "Failed to readdir");
2046
+ }
2047
+ return JSON.parse(this.protocol.getResultAsString());
2048
+ }
2049
+ mkdir(path, recursive = false) {
2050
+ const flags = recursive ? Flags.MKDIR_RECURSIVE : 0;
2051
+ const result = this.execSync(OpCode.MKDIR, path, void 0, flags);
2052
+ if (!result.success) {
2053
+ throw new Error(result.error || "Failed to mkdir");
2054
+ }
2055
+ }
2056
+ rm(path, recursive = false, force = false) {
2057
+ let flags = 0;
2058
+ if (recursive) flags |= Flags.RECURSIVE;
2059
+ if (force) flags |= Flags.FORCE;
2060
+ const result = this.execSync(OpCode.RM, path, void 0, flags);
2061
+ if (!result.success) {
2062
+ throw new Error(result.error || "Failed to rm");
2063
+ }
2064
+ }
2065
+ exists(path) {
2066
+ const result = this.execSync(OpCode.EXISTS, path);
2067
+ if (!result.success) {
2068
+ return false;
2069
+ }
2070
+ return result.result?.[0] === 1;
2071
+ }
2072
+ appendFile(path, data) {
2073
+ const result = this.execSync(OpCode.APPEND_FILE, path, data);
2074
+ if (!result.success) {
2075
+ throw new Error(result.error || "Failed to append file");
2076
+ }
2077
+ }
2078
+ symlink(target, linkPath) {
2079
+ const targetData = new TextEncoder().encode(target);
2080
+ const result = this.execSync(OpCode.SYMLINK, linkPath, targetData);
2081
+ if (!result.success) {
2082
+ throw new Error(result.error || "Failed to symlink");
2083
+ }
2084
+ }
2085
+ readlink(path) {
2086
+ const result = this.execSync(OpCode.READLINK, path);
2087
+ if (!result.success) {
2088
+ throw new Error(result.error || "Failed to readlink");
2089
+ }
2090
+ return this.protocol.getResultAsString();
2091
+ }
2092
+ chmod(path, mode) {
2093
+ const result = this.execSync(OpCode.CHMOD, path, void 0, 0, mode);
2094
+ if (!result.success) {
2095
+ throw new Error(result.error || "Failed to chmod");
2096
+ }
2097
+ }
2098
+ realpath(path) {
2099
+ const result = this.execSync(OpCode.REALPATH, path);
2100
+ if (!result.success) {
2101
+ throw new Error(result.error || "Failed to realpath");
2102
+ }
2103
+ return this.protocol.getResultAsString();
2104
+ }
2105
+ rename(oldPath, newPath) {
2106
+ const newPathData = new TextEncoder().encode(newPath);
2107
+ const result = this.execSync(OpCode.RENAME, oldPath, newPathData);
2108
+ if (!result.success) {
2109
+ throw new Error(result.error || "Failed to rename");
2110
+ }
2111
+ }
2112
+ copyFile(src, dest) {
2113
+ const destData = new TextEncoder().encode(dest);
2114
+ const result = this.execSync(OpCode.COPY_FILE, src, destData);
2115
+ if (!result.success) {
2116
+ throw new Error(result.error || "Failed to copyFile");
2117
+ }
2118
+ }
2119
+ writeStdout(data) {
2120
+ const encoded = new TextEncoder().encode(data);
2121
+ const result = this.execSync(OpCode.WRITE_STDOUT, "", encoded);
2122
+ if (!result.success) {
2123
+ throw new Error(result.error || "Failed to write stdout");
2124
+ }
2125
+ }
2126
+ writeStderr(data) {
2127
+ const encoded = new TextEncoder().encode(data);
2128
+ const result = this.execSync(OpCode.WRITE_STDERR, "", encoded);
2129
+ if (!result.success) {
2130
+ throw new Error(result.error || "Failed to write stderr");
2131
+ }
2132
+ }
2133
+ exit(code) {
2134
+ this.execSync(OpCode.EXIT, "", void 0, code);
2135
+ }
2136
+ /**
2137
+ * Make an HTTP request through the main thread's secureFetch.
2138
+ * Returns the response as a parsed object.
2139
+ */
2140
+ httpRequest(url, options) {
2141
+ const requestData = options ? new TextEncoder().encode(JSON.stringify(options)) : void 0;
2142
+ const result = this.execSync(OpCode.HTTP_REQUEST, url, requestData);
2143
+ if (!result.success) {
2144
+ throw new Error(result.error || "HTTP request failed");
2145
+ }
2146
+ const responseJson = new TextDecoder().decode(result.result);
2147
+ const parsed = JSON.parse(responseJson);
2148
+ const bodyBase64 = parsed.bodyBase64 ?? "";
2149
+ const body = atob(bodyBase64);
2150
+ return {
2151
+ status: parsed.status,
2152
+ statusText: parsed.statusText,
2153
+ headers: parsed.headers,
2154
+ url: parsed.url,
2155
+ body,
2156
+ bodyBase64
2157
+ };
2158
+ }
2159
+ /**
2160
+ * Execute a shell command through the main thread's exec function.
2161
+ * Returns the result as { stdout, stderr, exitCode }.
2162
+ */
2163
+ execCommand(command, stdin) {
2164
+ const requestData = stdin ? new TextEncoder().encode(JSON.stringify({ stdin })) : void 0;
2165
+ const result = this.execSync(OpCode.EXEC_COMMAND, command, requestData);
2166
+ if (!result.success) {
2167
+ throw new Error(result.error || "Command execution failed");
2168
+ }
2169
+ const responseJson = new TextDecoder().decode(result.result);
2170
+ return JSON.parse(responseJson);
2171
+ }
2172
+ /**
2173
+ * Execute a shell command with structured args (shell-escaped on the main thread).
2174
+ * Prevents command injection from unsanitized args.
2175
+ */
2176
+ execCommandArgs(command, args) {
2177
+ const requestData = new TextEncoder().encode(JSON.stringify({ args }));
2178
+ const result = this.execSync(OpCode.EXEC_COMMAND, command, requestData);
2179
+ if (!result.success) {
2180
+ throw new Error(result.error || "Command execution failed");
2181
+ }
2182
+ const responseJson = new TextDecoder().decode(result.result);
2183
+ return JSON.parse(responseJson);
2184
+ }
2185
+ /**
2186
+ * Invoke a tool through the main thread's invokeTool hook.
2187
+ * Returns the JSON-serialized result.
2188
+ */
2189
+ invokeTool(path, argsJson) {
2190
+ const requestData = argsJson ? new TextEncoder().encode(argsJson) : void 0;
2191
+ const result = this.execSync(OpCode.INVOKE_TOOL, path, requestData);
2192
+ if (!result.success) {
2193
+ throw new Error(result.error || "Tool invocation failed");
2194
+ }
2195
+ return new TextDecoder().decode(result.result);
2196
+ }
2197
+ };
2198
+
2199
+ // src/commands/python3/worker.ts
2200
+ import { readFileSync } from "node:fs";
2201
+ var require2 = createRequire(import.meta.url);
2202
+ var CPYTHON_ENTRY_BASENAME = "/vendor/cpython-emscripten/python.cjs";
2203
+ var CPYTHON_STDLIB_BASENAME = "/vendor/cpython-emscripten/python313.zip";
2204
+ var moduleLoadGuardInstalled = false;
2205
+ function normalizePath(path) {
2206
+ return path.replace(/\\/g, "/");
2207
+ }
2208
+ function isApprovedCpythonEntryPath(path) {
2209
+ return normalizePath(path).endsWith(CPYTHON_ENTRY_BASENAME);
2210
+ }
2211
+ function isApprovedStdlibZipPath(path) {
2212
+ return normalizePath(path).endsWith(CPYTHON_STDLIB_BASENAME);
2213
+ }
2214
+ function assertApprovedPath(path, kind) {
2215
+ const ok = kind === "cpython-entry" ? isApprovedCpythonEntryPath(path) : isApprovedStdlibZipPath(path);
2216
+ if (!ok) {
2217
+ throw new Error(
2218
+ `[Defense-in-depth] rejected ${kind} path outside approved vendor bundle: ${path}`
2219
+ );
2220
+ }
2221
+ }
2222
+ try {
2223
+ const NodeModule = require2("node:module");
2224
+ if (typeof NodeModule._load === "function" && typeof NodeModule._resolveFilename === "function") {
2225
+ const originalLoad = NodeModule._load;
2226
+ const originalResolveFilename = NodeModule._resolveFilename;
2227
+ const blockedModules = /* @__PURE__ */ new Set([
2228
+ "child_process",
2229
+ "node:child_process",
2230
+ "cluster",
2231
+ "node:cluster",
2232
+ "dgram",
2233
+ "node:dgram",
2234
+ "dns",
2235
+ "node:dns",
2236
+ "net",
2237
+ "node:net",
2238
+ "tls",
2239
+ "node:tls",
2240
+ "vm",
2241
+ "node:vm",
2242
+ "v8",
2243
+ "node:v8",
2244
+ "inspector",
2245
+ "node:inspector",
2246
+ "inspector/promises",
2247
+ "node:inspector/promises",
2248
+ "trace_events",
2249
+ "node:trace_events",
2250
+ "perf_hooks",
2251
+ "node:perf_hooks",
2252
+ "worker_threads",
2253
+ "node:worker_threads"
2254
+ ]);
2255
+ NodeModule._load = function(request, ...rest) {
2256
+ if (blockedModules.has(request)) {
2257
+ throw new Error(
2258
+ `[Defense-in-depth] require('${request}') is blocked in worker context`
2259
+ );
2260
+ }
2261
+ return originalLoad.apply(this, [request, ...rest]);
2262
+ };
2263
+ NodeModule._resolveFilename = function(request, ...rest) {
2264
+ if (blockedModules.has(request)) {
2265
+ throw new Error(
2266
+ `[Defense-in-depth] resolving '${request}' is blocked in worker context`
2267
+ );
2268
+ }
2269
+ return originalResolveFilename.apply(this, [request, ...rest]);
2270
+ };
2271
+ moduleLoadGuardInstalled = true;
2272
+ }
2273
+ } catch {
2274
+ }
2275
+ var cpythonEntryPath;
2276
+ try {
2277
+ cpythonEntryPath = require2.resolve(
2278
+ "../../../vendor/cpython-emscripten/python.cjs"
2279
+ );
2280
+ } catch (_e) {
2281
+ cpythonEntryPath = dirname(import.meta.url).replace("file://", "") + "/../../../vendor/cpython-emscripten/python.cjs";
2282
+ }
2283
+ assertApprovedPath(cpythonEntryPath, "cpython-entry");
2284
+ var cpythonDir = dirname(cpythonEntryPath);
2285
+ var stdlibZipPath = `${cpythonDir}/python313.zip`;
2286
+ assertApprovedPath(stdlibZipPath, "cpython-stdlib");
2287
+ function createHOSTFS(backend, FS, PATH, configuredMaxFileSize) {
2288
+ const maxFileSize = Number.isSafeInteger(configuredMaxFileSize) && configuredMaxFileSize >= 0 ? configuredMaxFileSize : 0;
2289
+ const ERRNO_CODES = Object.assign(
2290
+ /* @__PURE__ */ Object.create(null),
2291
+ {
2292
+ EPERM: 63,
2293
+ ENOENT: 44,
2294
+ EIO: 29,
2295
+ EBADF: 8,
2296
+ EAGAIN: 6,
2297
+ EACCES: 2,
2298
+ EBUSY: 10,
2299
+ EEXIST: 20,
2300
+ ENOTDIR: 54,
2301
+ EISDIR: 31,
2302
+ EINVAL: 28,
2303
+ EFBIG: 27,
2304
+ EMFILE: 33,
2305
+ ENOSPC: 51,
2306
+ ESPIPE: 70,
2307
+ EROFS: 69,
2308
+ ENOTEMPTY: 55,
2309
+ ENOSYS: 52,
2310
+ ENOTSUP: 138,
2311
+ ENODATA: 42
2312
+ }
2313
+ );
2314
+ function realPath(node) {
2315
+ const parts = [];
2316
+ while (node.parent !== node) {
2317
+ parts.push(node.name);
2318
+ node = node.parent;
2319
+ }
2320
+ parts.push(node.mount.opts.root);
2321
+ parts.reverse();
2322
+ return PATH.join(...parts);
2323
+ }
2324
+ function tryFSOperation(f) {
2325
+ try {
2326
+ return f();
2327
+ } catch (e) {
2328
+ const msg = e?.message?.toLowerCase() || (typeof e === "string" ? e.toLowerCase() : "");
2329
+ let code = ERRNO_CODES.EIO;
2330
+ if (msg.includes("no such file") || msg.includes("not found")) {
2331
+ code = ERRNO_CODES.ENOENT;
2332
+ } else if (msg.includes("is a directory")) {
2333
+ code = ERRNO_CODES.EISDIR;
2334
+ } else if (msg.includes("not a directory")) {
2335
+ code = ERRNO_CODES.ENOTDIR;
2336
+ } else if (msg.includes("already exists")) {
2337
+ code = ERRNO_CODES.EEXIST;
2338
+ } else if (msg.includes("permission")) {
2339
+ code = ERRNO_CODES.EACCES;
2340
+ } else if (msg.includes("not empty")) {
2341
+ code = ERRNO_CODES.ENOTEMPTY;
2342
+ }
2343
+ throw new FS.ErrnoError(code);
2344
+ }
2345
+ }
2346
+ function getMode(path) {
2347
+ return tryFSOperation(() => {
2348
+ const stat = backend.stat(path);
2349
+ let mode = stat.mode & 511;
2350
+ if (stat.isDirectory) {
2351
+ mode |= 16384;
2352
+ } else if (stat.isSymbolicLink) {
2353
+ mode |= 40960;
2354
+ } else {
2355
+ mode |= 32768;
2356
+ }
2357
+ return mode;
2358
+ });
2359
+ }
2360
+ const HOSTFS = {
2361
+ mount(_mount) {
2362
+ return HOSTFS.createNode(null, "/", 16877, 0);
2363
+ },
2364
+ createNode(parent, name, mode, dev) {
2365
+ if (!FS.isDir(mode) && !FS.isFile(mode) && !FS.isLink(mode)) {
2366
+ throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
2367
+ }
2368
+ const node = FS.createNode(parent, name, mode, dev);
2369
+ node.node_ops = HOSTFS.node_ops;
2370
+ node.stream_ops = HOSTFS.stream_ops;
2371
+ return node;
2372
+ },
2373
+ node_ops: {
2374
+ getattr(node) {
2375
+ const path = realPath(node);
2376
+ return tryFSOperation(() => {
2377
+ const stat = backend.stat(path);
2378
+ let mode = stat.mode & 511;
2379
+ if (stat.isDirectory) {
2380
+ mode |= 16384;
2381
+ } else if (stat.isSymbolicLink) {
2382
+ mode |= 40960;
2383
+ } else {
2384
+ mode |= 32768;
2385
+ }
2386
+ return {
2387
+ dev: 1,
2388
+ ino: node.id,
2389
+ mode,
2390
+ nlink: 1,
2391
+ uid: 0,
2392
+ gid: 0,
2393
+ rdev: 0,
2394
+ size: stat.size,
2395
+ atime: stat.mtime,
2396
+ mtime: stat.mtime,
2397
+ ctime: stat.mtime,
2398
+ blksize: 4096,
2399
+ blocks: Math.ceil(stat.size / 512)
2400
+ };
2401
+ });
2402
+ },
2403
+ setattr(node, attr) {
2404
+ const path = realPath(node);
2405
+ const mode = attr.mode;
2406
+ if (mode !== void 0) {
2407
+ tryFSOperation(() => backend.chmod(path, mode));
2408
+ node.mode = mode;
2409
+ }
2410
+ if (attr.size !== void 0) {
2411
+ if (!Number.isSafeInteger(attr.size) || attr.size < 0 || attr.size > maxFileSize) {
2412
+ throw new FS.ErrnoError(ERRNO_CODES.EFBIG);
2413
+ }
2414
+ tryFSOperation(() => {
2415
+ const content = backend.readFile(path);
2416
+ const newContent = new Uint8Array(attr.size);
2417
+ newContent.set(content.subarray(0, attr.size));
2418
+ backend.writeFile(path, newContent);
2419
+ });
2420
+ }
2421
+ },
2422
+ lookup(parent, name) {
2423
+ const path = PATH.join2(realPath(parent), name);
2424
+ const mode = getMode(path);
2425
+ return HOSTFS.createNode(parent, name, mode);
2426
+ },
2427
+ mknod(parent, name, mode, _dev) {
2428
+ const node = HOSTFS.createNode(parent, name, mode, _dev);
2429
+ const path = realPath(node);
2430
+ tryFSOperation(() => {
2431
+ if (FS.isDir(node.mode)) {
2432
+ backend.mkdir(path, false);
2433
+ } else {
2434
+ backend.writeFile(path, new Uint8Array(0));
2435
+ }
2436
+ });
2437
+ return node;
2438
+ },
2439
+ rename(oldNode, newDir, newName) {
2440
+ const oldPath = realPath(oldNode);
2441
+ const newPath = PATH.join2(realPath(newDir), newName);
2442
+ tryFSOperation(() => {
2443
+ const content = backend.readFile(oldPath);
2444
+ backend.writeFile(newPath, content);
2445
+ backend.rm(oldPath, false, false);
2446
+ });
2447
+ oldNode.name = newName;
2448
+ },
2449
+ unlink(parent, name) {
2450
+ const path = PATH.join2(realPath(parent), name);
2451
+ tryFSOperation(() => backend.rm(path, false, false));
2452
+ },
2453
+ rmdir(parent, name) {
2454
+ const path = PATH.join2(realPath(parent), name);
2455
+ tryFSOperation(() => backend.rm(path, false, false));
2456
+ },
2457
+ readdir(node) {
2458
+ const path = realPath(node);
2459
+ return tryFSOperation(() => backend.readdir(path));
2460
+ },
2461
+ symlink(parent, newName, oldPath) {
2462
+ const newPath = PATH.join2(realPath(parent), newName);
2463
+ tryFSOperation(() => backend.symlink(oldPath, newPath));
2464
+ },
2465
+ readlink(node) {
2466
+ const path = realPath(node);
2467
+ return tryFSOperation(() => backend.readlink(path));
2468
+ }
2469
+ },
2470
+ stream_ops: {
2471
+ open(stream) {
2472
+ const path = realPath(stream.node);
2473
+ const flags = stream.flags;
2474
+ const O_WRONLY = 1;
2475
+ const O_RDWR = 2;
2476
+ const O_CREAT = 64;
2477
+ const O_TRUNC = 512;
2478
+ const O_APPEND = 1024;
2479
+ const accessMode = flags & 3;
2480
+ const isWrite = accessMode === O_WRONLY || accessMode === O_RDWR;
2481
+ const isCreate = (flags & O_CREAT) !== 0;
2482
+ const isTruncate = (flags & O_TRUNC) !== 0;
2483
+ const isAppend = (flags & O_APPEND) !== 0;
2484
+ if (FS.isDir(stream.node.mode)) {
2485
+ return;
2486
+ }
2487
+ let content;
2488
+ try {
2489
+ if (isTruncate && isWrite) {
2490
+ content = new Uint8Array(0);
2491
+ } else {
2492
+ content = backend.readFile(path);
2493
+ }
2494
+ } catch (_e) {
2495
+ if (isCreate && isWrite) {
2496
+ content = new Uint8Array(0);
2497
+ } else {
2498
+ throw new FS.ErrnoError(ERRNO_CODES.ENOENT);
2499
+ }
2500
+ }
2501
+ if (content.length > maxFileSize) {
2502
+ throw new FS.ErrnoError(ERRNO_CODES.EFBIG);
2503
+ }
2504
+ stream.hostContent = content;
2505
+ stream.hostModified = isTruncate && isWrite;
2506
+ stream.hostPath = path;
2507
+ if (isAppend) {
2508
+ stream.position = content.length;
2509
+ }
2510
+ },
2511
+ close(stream) {
2512
+ const hostPath = stream.hostPath;
2513
+ const hostContent = stream.hostContent;
2514
+ if (stream.hostModified && hostContent && hostPath) {
2515
+ tryFSOperation(() => backend.writeFile(hostPath, hostContent));
2516
+ }
2517
+ delete stream.hostContent;
2518
+ delete stream.hostModified;
2519
+ delete stream.hostPath;
2520
+ },
2521
+ read(stream, buffer, offset, length, position) {
2522
+ const content = stream.hostContent;
2523
+ if (!content) return 0;
2524
+ const size = content.length;
2525
+ if (position >= size) return 0;
2526
+ const bytesToRead = Math.min(length, size - position);
2527
+ buffer.set(content.subarray(position, position + bytesToRead), offset);
2528
+ return bytesToRead;
2529
+ },
2530
+ write(stream, buffer, offset, length, position) {
2531
+ if (!Number.isSafeInteger(position) || !Number.isSafeInteger(length) || !Number.isSafeInteger(offset) || position < 0 || length < 0 || offset < 0 || length > buffer.length - offset || position > maxFileSize - length) {
2532
+ throw new FS.ErrnoError(ERRNO_CODES.EFBIG);
2533
+ }
2534
+ let content = stream.hostContent || new Uint8Array(0);
2535
+ const newSize = Math.max(content.length, position + length);
2536
+ if (newSize > content.length) {
2537
+ const newContent = new Uint8Array(newSize);
2538
+ newContent.set(content);
2539
+ content = newContent;
2540
+ stream.hostContent = content;
2541
+ }
2542
+ content.set(buffer.subarray(offset, offset + length), position);
2543
+ stream.hostModified = true;
2544
+ return length;
2545
+ },
2546
+ llseek(stream, offset, whence) {
2547
+ const SEEK_SET = 0;
2548
+ const SEEK_CUR = 1;
2549
+ const SEEK_END = 2;
2550
+ if (whence !== SEEK_SET && whence !== SEEK_CUR && whence !== SEEK_END) {
2551
+ throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
2552
+ }
2553
+ let position = offset;
2554
+ if (whence === SEEK_CUR) {
2555
+ position += stream.position;
2556
+ } else if (whence === SEEK_END) {
2557
+ if (FS.isFile(stream.node.mode)) {
2558
+ const content = stream.hostContent;
2559
+ position += content ? content.length : 0;
2560
+ }
2561
+ }
2562
+ if (!Number.isSafeInteger(position) || position < 0 || position > maxFileSize) {
2563
+ throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
2564
+ }
2565
+ return position;
2566
+ }
2567
+ }
2568
+ };
2569
+ return HOSTFS;
2570
+ }
2571
+ function generateSetupCode(input) {
2572
+ const envSetup = Object.entries(input.env).map(([key, value]) => {
2573
+ return `os.environ[${JSON.stringify(key)}] = ${JSON.stringify(value)}`;
2574
+ }).join("\n");
2575
+ const argv0 = input.scriptPath || "python3";
2576
+ const argvList = [argv0, ...input.args].map((arg) => JSON.stringify(arg)).join(", ");
2577
+ return `
2578
+ import os
2579
+ import sys
2580
+ import json
2581
+
2582
+ ${envSetup}
2583
+
2584
+ sys.argv = [${argvList}]
2585
+
2586
+ # Path redirection: redirect /absolute paths to /host mount
2587
+ def _should_redirect(path):
2588
+ return (isinstance(path, str) and
2589
+ path.startswith('/') and
2590
+ not path.startswith('/lib') and
2591
+ not path.startswith('/proc') and
2592
+ not path.startswith('/host') and
2593
+ not path.startswith('/_jb_http'))
2594
+
2595
+ # builtins.open
2596
+ import builtins
2597
+ _orig_open = builtins.open
2598
+ def _redir_open(path, mode='r', *args, **kwargs):
2599
+ if _should_redirect(path):
2600
+ path = '/host' + path
2601
+ return _orig_open(path, mode, *args, **kwargs)
2602
+ builtins.open = _redir_open
2603
+
2604
+ # os file operations
2605
+ _orig_listdir = os.listdir
2606
+ def _redir_listdir(path='.'):
2607
+ if _should_redirect(path):
2608
+ path = '/host' + path
2609
+ return _orig_listdir(path)
2610
+ os.listdir = _redir_listdir
2611
+
2612
+ _orig_exists = os.path.exists
2613
+ def _redir_exists(path):
2614
+ if _should_redirect(path):
2615
+ path = '/host' + path
2616
+ return _orig_exists(path)
2617
+ os.path.exists = _redir_exists
2618
+
2619
+ _orig_isfile = os.path.isfile
2620
+ def _redir_isfile(path):
2621
+ if _should_redirect(path):
2622
+ path = '/host' + path
2623
+ return _orig_isfile(path)
2624
+ os.path.isfile = _redir_isfile
2625
+
2626
+ _orig_isdir = os.path.isdir
2627
+ def _redir_isdir(path):
2628
+ if _should_redirect(path):
2629
+ path = '/host' + path
2630
+ return _orig_isdir(path)
2631
+ os.path.isdir = _redir_isdir
2632
+
2633
+ _orig_stat = os.stat
2634
+ def _redir_stat(path, *args, **kwargs):
2635
+ if _should_redirect(path):
2636
+ path = '/host' + path
2637
+ return _orig_stat(path, *args, **kwargs)
2638
+ os.stat = _redir_stat
2639
+
2640
+ _orig_mkdir = os.mkdir
2641
+ def _redir_mkdir(path, *args, **kwargs):
2642
+ if _should_redirect(path):
2643
+ path = '/host' + path
2644
+ return _orig_mkdir(path, *args, **kwargs)
2645
+ os.mkdir = _redir_mkdir
2646
+
2647
+ _orig_makedirs = os.makedirs
2648
+ def _redir_makedirs(path, *args, **kwargs):
2649
+ if _should_redirect(path):
2650
+ path = '/host' + path
2651
+ return _orig_makedirs(path, *args, **kwargs)
2652
+ os.makedirs = _redir_makedirs
2653
+
2654
+ _orig_remove = os.remove
2655
+ def _redir_remove(path, *args, **kwargs):
2656
+ if _should_redirect(path):
2657
+ path = '/host' + path
2658
+ return _orig_remove(path, *args, **kwargs)
2659
+ os.remove = _redir_remove
2660
+
2661
+ _orig_rmdir = os.rmdir
2662
+ def _redir_rmdir(path, *args, **kwargs):
2663
+ if _should_redirect(path):
2664
+ path = '/host' + path
2665
+ return _orig_rmdir(path, *args, **kwargs)
2666
+ os.rmdir = _redir_rmdir
2667
+
2668
+ _orig_getcwd = os.getcwd
2669
+ def _redir_getcwd():
2670
+ cwd = _orig_getcwd()
2671
+ if cwd.startswith('/host'):
2672
+ return cwd[5:]
2673
+ return cwd
2674
+ os.getcwd = _redir_getcwd
2675
+
2676
+ _orig_chdir = os.chdir
2677
+ def _redir_chdir(path):
2678
+ if _should_redirect(path):
2679
+ path = '/host' + path
2680
+ return _orig_chdir(path)
2681
+ os.chdir = _redir_chdir
2682
+
2683
+ # glob
2684
+ import glob as _glob_module
2685
+ _orig_glob = _glob_module.glob
2686
+ def _redir_glob(pathname, *args, **kwargs):
2687
+ if _should_redirect(pathname):
2688
+ pathname = '/host' + pathname
2689
+ return _orig_glob(pathname, *args, **kwargs)
2690
+ _glob_module.glob = _redir_glob
2691
+
2692
+ _orig_iglob = _glob_module.iglob
2693
+ def _redir_iglob(pathname, *args, **kwargs):
2694
+ if _should_redirect(pathname):
2695
+ pathname = '/host' + pathname
2696
+ return _orig_iglob(pathname, *args, **kwargs)
2697
+ _glob_module.iglob = _redir_iglob
2698
+
2699
+ # os.walk
2700
+ _orig_walk = os.walk
2701
+ def _redir_walk(top, *args, **kwargs):
2702
+ redirected = False
2703
+ if _should_redirect(top):
2704
+ top = '/host' + top
2705
+ redirected = True
2706
+ for dirpath, dirnames, filenames in _orig_walk(top, *args, **kwargs):
2707
+ if redirected and dirpath.startswith('/host'):
2708
+ dirpath = dirpath[5:] if len(dirpath) > 5 else '/'
2709
+ yield dirpath, dirnames, filenames
2710
+ os.walk = _redir_walk
2711
+
2712
+ # os.scandir
2713
+ _orig_scandir = os.scandir
2714
+ def _redir_scandir(path='.'):
2715
+ if _should_redirect(path):
2716
+ path = '/host' + path
2717
+ return _orig_scandir(path)
2718
+ os.scandir = _redir_scandir
2719
+
2720
+ # io.open and io.open_code
2721
+ import io as _io_module
2722
+ _io_module.open = builtins.open
2723
+
2724
+ # runpy uses io.open_code rather than builtins.open/io.open. Redirect it
2725
+ # separately so code loading keeps the logical path in __file__ and argv.
2726
+ _orig_open_code = _io_module.open_code
2727
+ def _redir_open_code(path):
2728
+ if _should_redirect(path):
2729
+ path = '/host' + path
2730
+ return _orig_open_code(path)
2731
+ _io_module.open_code = _redir_open_code
2732
+
2733
+ # shutil
2734
+ import shutil as _shutil_module
2735
+
2736
+ _orig_shutil_copy = _shutil_module.copy
2737
+ def _redir_shutil_copy(src, dst, *args, **kwargs):
2738
+ if _should_redirect(src): src = '/host' + src
2739
+ if _should_redirect(dst): dst = '/host' + dst
2740
+ return _orig_shutil_copy(src, dst, *args, **kwargs)
2741
+ _shutil_module.copy = _redir_shutil_copy
2742
+
2743
+ _orig_shutil_copy2 = _shutil_module.copy2
2744
+ def _redir_shutil_copy2(src, dst, *args, **kwargs):
2745
+ if _should_redirect(src): src = '/host' + src
2746
+ if _should_redirect(dst): dst = '/host' + dst
2747
+ return _orig_shutil_copy2(src, dst, *args, **kwargs)
2748
+ _shutil_module.copy2 = _redir_shutil_copy2
2749
+
2750
+ _orig_shutil_copyfile = _shutil_module.copyfile
2751
+ def _redir_shutil_copyfile(src, dst, *args, **kwargs):
2752
+ if _should_redirect(src): src = '/host' + src
2753
+ if _should_redirect(dst): dst = '/host' + dst
2754
+ return _orig_shutil_copyfile(src, dst, *args, **kwargs)
2755
+ _shutil_module.copyfile = _redir_shutil_copyfile
2756
+
2757
+ _orig_shutil_copytree = _shutil_module.copytree
2758
+ def _redir_shutil_copytree(src, dst, *args, **kwargs):
2759
+ if _should_redirect(src): src = '/host' + src
2760
+ if _should_redirect(dst): dst = '/host' + dst
2761
+ return _orig_shutil_copytree(src, dst, *args, **kwargs)
2762
+ _shutil_module.copytree = _redir_shutil_copytree
2763
+
2764
+ _orig_shutil_move = _shutil_module.move
2765
+ def _redir_shutil_move(src, dst, *args, **kwargs):
2766
+ if _should_redirect(src): src = '/host' + src
2767
+ if _should_redirect(dst): dst = '/host' + dst
2768
+ return _orig_shutil_move(src, dst, *args, **kwargs)
2769
+ _shutil_module.move = _redir_shutil_move
2770
+
2771
+ _orig_shutil_rmtree = _shutil_module.rmtree
2772
+ def _redir_shutil_rmtree(path, *args, **kwargs):
2773
+ if _should_redirect(path): path = '/host' + path
2774
+ return _orig_shutil_rmtree(path, *args, **kwargs)
2775
+ _shutil_module.rmtree = _redir_shutil_rmtree
2776
+
2777
+ # pathlib.Path
2778
+ from pathlib import Path
2779
+
2780
+ def _redirect_path(p):
2781
+ s = str(p)
2782
+ if _should_redirect(s):
2783
+ return Path('/host' + s)
2784
+ return p
2785
+
2786
+ Path._orig_stat = Path.stat
2787
+ def _path_stat(self, *args, **kwargs):
2788
+ return _redirect_path(self)._orig_stat(*args, **kwargs)
2789
+ Path.stat = _path_stat
2790
+
2791
+ Path._orig_exists = Path.exists
2792
+ def _path_exists(self):
2793
+ return _redirect_path(self)._orig_exists()
2794
+ Path.exists = _path_exists
2795
+
2796
+ Path._orig_is_file = Path.is_file
2797
+ def _path_is_file(self):
2798
+ return _redirect_path(self)._orig_is_file()
2799
+ Path.is_file = _path_is_file
2800
+
2801
+ Path._orig_is_dir = Path.is_dir
2802
+ def _path_is_dir(self):
2803
+ return _redirect_path(self)._orig_is_dir()
2804
+ Path.is_dir = _path_is_dir
2805
+
2806
+ Path._orig_open = Path.open
2807
+ def _path_open(self, *args, **kwargs):
2808
+ return _redirect_path(self)._orig_open(*args, **kwargs)
2809
+ Path.open = _path_open
2810
+
2811
+ Path._orig_read_text = Path.read_text
2812
+ def _path_read_text(self, *args, **kwargs):
2813
+ return _redirect_path(self)._orig_read_text(*args, **kwargs)
2814
+ Path.read_text = _path_read_text
2815
+
2816
+ Path._orig_read_bytes = Path.read_bytes
2817
+ def _path_read_bytes(self):
2818
+ return _redirect_path(self)._orig_read_bytes()
2819
+ Path.read_bytes = _path_read_bytes
2820
+
2821
+ Path._orig_write_text = Path.write_text
2822
+ def _path_write_text(self, *args, **kwargs):
2823
+ return _redirect_path(self)._orig_write_text(*args, **kwargs)
2824
+ Path.write_text = _path_write_text
2825
+
2826
+ Path._orig_write_bytes = Path.write_bytes
2827
+ def _path_write_bytes(self, data):
2828
+ return _redirect_path(self)._orig_write_bytes(data)
2829
+ Path.write_bytes = _path_write_bytes
2830
+
2831
+ Path._orig_mkdir = Path.mkdir
2832
+ def _path_mkdir(self, *args, **kwargs):
2833
+ return _redirect_path(self)._orig_mkdir(*args, **kwargs)
2834
+ Path.mkdir = _path_mkdir
2835
+
2836
+ Path._orig_rmdir = Path.rmdir
2837
+ def _path_rmdir(self):
2838
+ return _redirect_path(self)._orig_rmdir()
2839
+ Path.rmdir = _path_rmdir
2840
+
2841
+ Path._orig_unlink = Path.unlink
2842
+ def _path_unlink(self, *args, **kwargs):
2843
+ return _redirect_path(self)._orig_unlink(*args, **kwargs)
2844
+ Path.unlink = _path_unlink
2845
+
2846
+ Path._orig_iterdir = Path.iterdir
2847
+ def _path_iterdir(self):
2848
+ redirected = _redirect_path(self)
2849
+ for p in redirected._orig_iterdir():
2850
+ s = str(p)
2851
+ if s.startswith('/host'):
2852
+ yield Path(s[5:])
2853
+ else:
2854
+ yield p
2855
+ Path.iterdir = _path_iterdir
2856
+
2857
+ Path._orig_glob = Path.glob
2858
+ def _path_glob(self, pattern):
2859
+ redirected = _redirect_path(self)
2860
+ for p in redirected._orig_glob(pattern):
2861
+ s = str(p)
2862
+ if s.startswith('/host'):
2863
+ yield Path(s[5:])
2864
+ else:
2865
+ yield p
2866
+ Path.glob = _path_glob
2867
+
2868
+ Path._orig_rglob = Path.rglob
2869
+ def _path_rglob(self, pattern):
2870
+ redirected = _redirect_path(self)
2871
+ for p in redirected._orig_rglob(pattern):
2872
+ s = str(p)
2873
+ if s.startswith('/host'):
2874
+ yield Path(s[5:])
2875
+ else:
2876
+ yield p
2877
+ Path.rglob = _path_rglob
2878
+
2879
+ # Set cwd to host mount
2880
+ os.chdir('/host' + ${JSON.stringify(input.cwd)})
2881
+ `;
2882
+ }
2883
+ function createHTTPFS(backend, FS) {
2884
+ let lastResponse = null;
2885
+ const encoder = new TextEncoder();
2886
+ const decoder = new TextDecoder();
2887
+ const HTTPFS = {
2888
+ mount(_mount) {
2889
+ return HTTPFS.createNode(null, "/", 16877, 0);
2890
+ },
2891
+ createNode(parent, name, mode, dev) {
2892
+ const node = FS.createNode(parent, name, mode, dev);
2893
+ node.node_ops = HTTPFS.node_ops;
2894
+ node.stream_ops = HTTPFS.stream_ops;
2895
+ return node;
2896
+ },
2897
+ node_ops: {
2898
+ getattr(node) {
2899
+ const isDir = node.name === "/" || node.parent === node;
2900
+ return {
2901
+ dev: 1,
2902
+ ino: node.id,
2903
+ mode: isDir ? 16877 : 33206,
2904
+ nlink: 1,
2905
+ uid: 0,
2906
+ gid: 0,
2907
+ rdev: 0,
2908
+ size: lastResponse ? lastResponse.length : 0,
2909
+ atime: /* @__PURE__ */ new Date(),
2910
+ mtime: /* @__PURE__ */ new Date(),
2911
+ ctime: /* @__PURE__ */ new Date(),
2912
+ blksize: 4096,
2913
+ blocks: 0
2914
+ };
2915
+ },
2916
+ setattr(_node, _attr) {
2917
+ },
2918
+ lookup(parent, name) {
2919
+ return HTTPFS.createNode(parent, name, 33206);
2920
+ },
2921
+ mknod(parent, name, mode, _dev) {
2922
+ return HTTPFS.createNode(parent, name, mode);
2923
+ },
2924
+ rename() {
2925
+ },
2926
+ unlink() {
2927
+ },
2928
+ rmdir() {
2929
+ },
2930
+ readdir(_node) {
2931
+ return ["request"];
2932
+ },
2933
+ symlink() {
2934
+ },
2935
+ readlink(_node) {
2936
+ return "";
2937
+ }
2938
+ },
2939
+ stream_ops: {
2940
+ open(stream) {
2941
+ delete stream.hostContent;
2942
+ stream.hostModified = false;
2943
+ const accessMode = stream.flags & 3;
2944
+ const isRead = accessMode === 0;
2945
+ if (isRead && lastResponse) {
2946
+ stream.hostContent = lastResponse;
2947
+ }
2948
+ },
2949
+ close(stream) {
2950
+ if (stream.hostModified && stream.hostContent) {
2951
+ const reqJson = decoder.decode(stream.hostContent);
2952
+ try {
2953
+ const req = JSON.parse(reqJson);
2954
+ const result = backend.httpRequest(req.url, {
2955
+ method: req.method || "GET",
2956
+ headers: req.headers || void 0,
2957
+ body: req.body || void 0
2958
+ });
2959
+ lastResponse = encoder.encode(JSON.stringify(result));
2960
+ } catch (e) {
2961
+ const message = sanitizeHostErrorMessage(e.message);
2962
+ lastResponse = encoder.encode(JSON.stringify({ error: message }));
2963
+ }
2964
+ }
2965
+ delete stream.hostContent;
2966
+ delete stream.hostModified;
2967
+ },
2968
+ read(stream, buffer, offset, length, position) {
2969
+ const content = stream.hostContent;
2970
+ if (!content) return 0;
2971
+ const size = content.length;
2972
+ if (position >= size) return 0;
2973
+ const bytesToRead = Math.min(length, size - position);
2974
+ buffer.set(content.subarray(position, position + bytesToRead), offset);
2975
+ return bytesToRead;
2976
+ },
2977
+ write(stream, buffer, offset, length, position) {
2978
+ let content = stream.hostContent || new Uint8Array(0);
2979
+ const newSize = Math.max(content.length, position + length);
2980
+ if (newSize > content.length) {
2981
+ const newContent = new Uint8Array(newSize);
2982
+ newContent.set(content);
2983
+ content = newContent;
2984
+ stream.hostContent = content;
2985
+ }
2986
+ content.set(buffer.subarray(offset, offset + length), position);
2987
+ stream.hostModified = true;
2988
+ return length;
2989
+ },
2990
+ llseek(stream, offset, whence) {
2991
+ let position = offset;
2992
+ if (whence === 1)
2993
+ position += stream.position;
2994
+ else if (whence === 2) {
2995
+ const content = stream.hostContent;
2996
+ position += content ? content.length : 0;
2997
+ }
2998
+ if (position < 0) throw new FS.ErrnoError(28);
2999
+ return position;
3000
+ }
3001
+ }
3002
+ };
3003
+ return HTTPFS;
3004
+ }
3005
+ function generateHttpBridgeCode() {
3006
+ return `
3007
+ # HTTP bridge: jb_http module
3008
+ # Write request JSON to /_jb_http/request (custom FS triggers HTTP via SharedArrayBuffer)
3009
+ # Then read response JSON from same path.
3010
+
3011
+ import base64 as _base64
3012
+
3013
+ class _JbHttpResponse:
3014
+ """HTTP response object similar to requests.Response"""
3015
+ def __init__(self, data):
3016
+ self.status_code = data.get('status', 0)
3017
+ self.reason = data.get('statusText', '')
3018
+ # @banned-pattern-ignore: Python code, not JavaScript
3019
+ self.headers = data.get('headers', {})
3020
+ self.url = data.get('url', '')
3021
+ self._error = data.get('error')
3022
+ b64 = data.get('bodyBase64')
3023
+ if b64 is not None:
3024
+ self.content = _base64.b64decode(b64)
3025
+ self.text = self.content.decode('utf-8', errors='replace')
3026
+ else:
3027
+ self.content = b''
3028
+ self.text = data.get('body', '')
3029
+
3030
+ @property
3031
+ def ok(self):
3032
+ return 200 <= self.status_code < 300
3033
+
3034
+ def json(self):
3035
+ return json.loads(self.text)
3036
+
3037
+ def raise_for_status(self):
3038
+ if self._error:
3039
+ raise Exception(self._error)
3040
+ if not self.ok:
3041
+ raise Exception(f"HTTP {self.status_code}: {self.reason}")
3042
+
3043
+ class _JbHttp:
3044
+ """HTTP client that bridges to just-bash's secureFetch via custom FS"""
3045
+ def _do_request(self, method, url, headers=None, body=None):
3046
+ import json as _json
3047
+ req = _json.dumps({'url': url, 'method': method, 'headers': headers, 'body': body})
3048
+ # Write request to HTTPFS \u2014 close triggers the HTTP call synchronously
3049
+ with _orig_open('/_jb_http/request', 'w') as f:
3050
+ f.write(req)
3051
+ # Read response (cached by HTTPFS from the HTTP call above)
3052
+ with _orig_open('/_jb_http/request', 'r') as f:
3053
+ return _json.loads(f.read())
3054
+
3055
+ def request(self, method, url, headers=None, data=None, json_data=None):
3056
+ if json_data is not None:
3057
+ data = json.dumps(json_data)
3058
+ headers = headers or {}
3059
+ headers['Content-Type'] = 'application/json'
3060
+ result = self._do_request(method, url, headers, data)
3061
+ if 'error' in result and result.get('status') is None:
3062
+ raise Exception(result['error'])
3063
+ return _JbHttpResponse(result)
3064
+
3065
+ def get(self, url, headers=None, **kwargs):
3066
+ return self.request('GET', url, headers=headers, **kwargs)
3067
+
3068
+ def post(self, url, headers=None, data=None, json=None, **kwargs):
3069
+ return self.request('POST', url, headers=headers, data=data, json_data=json, **kwargs)
3070
+
3071
+ def put(self, url, headers=None, data=None, json=None, **kwargs):
3072
+ return self.request('PUT', url, headers=headers, data=data, json_data=json, **kwargs)
3073
+
3074
+ def delete(self, url, headers=None, **kwargs):
3075
+ return self.request('DELETE', url, headers=headers, **kwargs)
3076
+
3077
+ def head(self, url, headers=None, **kwargs):
3078
+ return self.request('HEAD', url, headers=headers, **kwargs)
3079
+
3080
+ def patch(self, url, headers=None, data=None, json=None, **kwargs):
3081
+ return self.request('PATCH', url, headers=headers, data=data, json_data=json, **kwargs)
3082
+
3083
+ import types
3084
+ jb_http = types.ModuleType('jb_http')
3085
+ jb_http._client = _JbHttp()
3086
+ jb_http.get = jb_http._client.get
3087
+ jb_http.post = jb_http._client.post
3088
+ jb_http.put = jb_http._client.put
3089
+ jb_http.delete = jb_http._client.delete
3090
+ jb_http.head = jb_http._client.head
3091
+ jb_http.patch = jb_http._client.patch
3092
+ jb_http.request = jb_http._client.request
3093
+ jb_http.Response = _JbHttpResponse
3094
+ sys.modules['jb_http'] = jb_http
3095
+ `;
3096
+ }
3097
+ var cachedStdlibZip = new Uint8Array(readFileSync(stdlibZipPath));
3098
+ function wrapWorkerMessage(protocolToken, message) {
3099
+ const wrapped = /* @__PURE__ */ Object.create(null);
3100
+ if (!message || typeof message !== "object") {
3101
+ wrapped.success = false;
3102
+ wrapped.error = "Worker attempted to post non-object message";
3103
+ wrapped.protocolToken = protocolToken;
3104
+ return wrapped;
3105
+ }
3106
+ for (const [key, value] of Object.entries(message))
3107
+ wrapped[key] = value;
3108
+ wrapped.protocolToken = protocolToken;
3109
+ return wrapped;
3110
+ }
3111
+ function postWorkerMessage(protocolToken, message) {
3112
+ try {
3113
+ parentPort?.postMessage(wrapWorkerMessage(protocolToken, message));
3114
+ } catch (error) {
3115
+ console.debug(
3116
+ "[python3-worker] failed to post worker message:",
3117
+ sanitizeUnknownError(error)
3118
+ );
3119
+ }
3120
+ }
3121
+ async function runPython(input) {
3122
+ if (!moduleLoadGuardInstalled) {
3123
+ return {
3124
+ success: false,
3125
+ error: "Defense-in-depth module-loader guard failed to initialize; refusing to execute Python worker"
3126
+ };
3127
+ }
3128
+ const backend = new SyncBackend(input.sharedBuffer, input.timeoutMs);
3129
+ assertApprovedPath(cpythonEntryPath, "cpython-entry");
3130
+ const createPythonModule = require2(cpythonEntryPath);
3131
+ let moduleReady = false;
3132
+ const pendingStdout = [];
3133
+ const pendingStderr = [];
3134
+ let Module;
3135
+ try {
3136
+ let stdinOffset = 0;
3137
+ const readStdin = wrapWasmCallback(
3138
+ "python3-worker",
3139
+ "stdin",
3140
+ () => stdinOffset < input.stdin.length ? input.stdin.charCodeAt(stdinOffset++) : null
3141
+ );
3142
+ const onPreRun = wrapWasmCallback(
3143
+ "python3-worker",
3144
+ "preRun",
3145
+ (mod) => {
3146
+ mod.FS.init(readStdin);
3147
+ mod.FS.mkdirTree("/lib");
3148
+ mod.FS.writeFile("/lib/python313.zip", cachedStdlibZip);
3149
+ mod.ENV.PYTHONHOME = "/";
3150
+ mod.ENV.PYTHONPATH = "/lib/python313.zip";
3151
+ }
3152
+ );
3153
+ const onPrint = wrapWasmCallback(
3154
+ "python3-worker",
3155
+ "print",
3156
+ (text) => {
3157
+ if (moduleReady) {
3158
+ backend.writeStdout(`${text}
3159
+ `);
3160
+ } else {
3161
+ pendingStdout.push(`${text}
3162
+ `);
3163
+ }
3164
+ }
3165
+ );
3166
+ const onPrintErr = wrapWasmCallback(
3167
+ "python3-worker",
3168
+ "printErr",
3169
+ (text) => {
3170
+ if (typeof text === "string" && (text.includes("Could not find platform") || text.includes("LLVM Profile Error"))) {
3171
+ return;
3172
+ }
3173
+ if (moduleReady) {
3174
+ backend.writeStderr(`${text}
3175
+ `);
3176
+ } else {
3177
+ pendingStderr.push(`${text}
3178
+ `);
3179
+ }
3180
+ }
3181
+ );
3182
+ Module = await createPythonModule({
3183
+ noInitialRun: true,
3184
+ preRun: [onPreRun],
3185
+ print: onPrint,
3186
+ printErr: onPrintErr
3187
+ });
3188
+ } catch (e) {
3189
+ const message = sanitizeHostErrorMessage(e.message);
3190
+ return {
3191
+ success: false,
3192
+ error: `Failed to load CPython: ${message}`
3193
+ };
3194
+ }
3195
+ moduleReady = true;
3196
+ for (const text of pendingStdout) backend.writeStdout(text);
3197
+ for (const text of pendingStderr) backend.writeStderr(text);
3198
+ const HOSTFS = createHOSTFS(
3199
+ backend,
3200
+ Module.FS,
3201
+ Module.PATH,
3202
+ input.maxFileSize ?? 8 * 1024 * 1024
3203
+ );
3204
+ try {
3205
+ Module.FS.mkdir("/host");
3206
+ Module.FS.mount(HOSTFS, { root: "/" }, "/host");
3207
+ } catch (e) {
3208
+ const message = sanitizeHostErrorMessage(e.message);
3209
+ return {
3210
+ success: false,
3211
+ error: `Failed to mount HOSTFS: ${message}`
3212
+ };
3213
+ }
3214
+ const HTTPFS = createHTTPFS(backend, Module.FS);
3215
+ try {
3216
+ Module.FS.mkdir("/_jb_http");
3217
+ Module.FS.mount(HTTPFS, { root: "/" }, "/_jb_http");
3218
+ } catch (e) {
3219
+ const message = sanitizeHostErrorMessage(e.message);
3220
+ return {
3221
+ success: false,
3222
+ error: `Failed to mount HTTPFS: ${message}`
3223
+ };
3224
+ }
3225
+ const setupCode = generateSetupCode(input);
3226
+ const httpBridgeCode = generateHttpBridgeCode();
3227
+ const wrappedCode = `
3228
+ import sys
3229
+ _jb_exit_code = 0
3230
+ try:
3231
+ ${setupCode.split("\n").map((line) => ` ${line}`).join("\n")}
3232
+ ${httpBridgeCode.split("\n").map((line) => ` ${line}`).join("\n")}
3233
+ ${input.pythonCode.split("\n").map((line) => ` ${line}`).join("\n")}
3234
+ except SystemExit as e:
3235
+ _jb_exit_code = e.code if isinstance(e.code, int) else (1 if e.code else 0)
3236
+ except Exception as e:
3237
+ import traceback
3238
+ traceback.print_exc()
3239
+ _jb_exit_code = 1
3240
+ sys.exit(_jb_exit_code)
3241
+ `;
3242
+ try {
3243
+ Module.FS.mkdir("/tmp");
3244
+ } catch (_e) {
3245
+ }
3246
+ const encoder = new TextEncoder();
3247
+ const scriptPath = "/tmp/_jb_script.py";
3248
+ const scriptData = encoder.encode(wrappedCode);
3249
+ Module.FS.writeFile(scriptPath, scriptData);
3250
+ try {
3251
+ activateDefense(input.protocolToken);
3252
+ const ret = Module.callMain([scriptPath]);
3253
+ const exitCode = (typeof ret === "number" ? ret : 0) || process.exitCode || 0;
3254
+ backend.exit(exitCode);
3255
+ return { success: true };
3256
+ } catch (e) {
3257
+ const error = e;
3258
+ const exitCode = error.status ?? process.exitCode ?? 1;
3259
+ backend.exit(exitCode);
3260
+ return { success: true };
3261
+ }
3262
+ }
3263
+ var defense = null;
3264
+ function activateDefense(protocolToken) {
3265
+ if (defense) return;
3266
+ const _DateNow = Date.now;
3267
+ const degraded = { now: () => _DateNow(), timeOrigin: _DateNow() };
3268
+ Object.defineProperty(globalThis, "performance", {
3269
+ value: degraded,
3270
+ writable: true,
3271
+ configurable: true
3272
+ });
3273
+ const onViolation = wrapWasmCallback(
3274
+ "python3-worker",
3275
+ "onViolation",
3276
+ (v) => {
3277
+ postWorkerMessage(protocolToken, {
3278
+ type: "security-violation",
3279
+ violation: v
3280
+ });
3281
+ }
3282
+ );
3283
+ defense = new WorkerDefenseInDepth({
3284
+ excludeViolationTypes: [
3285
+ // SharedArrayBuffer/Atomics: Used by sync-fs-backend.ts for synchronous
3286
+ // filesystem communication between the WASM thread and the main thread.
3287
+ "shared_array_buffer",
3288
+ "atomics",
3289
+ // performance: Excluded because we replaced it above with a ms-precision
3290
+ // stub. Defense doesn't need to block it — it's already degraded.
3291
+ "performance_timing",
3292
+ // CPython's Emscripten runtime performs lazy CJS loads during callMain.
3293
+ // A worker-entry guard installed before CPython loads rejects the exact
3294
+ // dangerous builtin set without relying on loader stack text. CPython
3295
+ // exposes no JS bridge to guest Python, so this compatibility exclusion
3296
+ // does not make Module methods guest-reachable.
3297
+ "module_load",
3298
+ "module_resolve_filename"
3299
+ ],
3300
+ onViolation
3301
+ });
3302
+ }
3303
+ process.on("uncaughtException", (e) => {
3304
+ if (!activeProtocolToken) {
3305
+ return;
3306
+ }
3307
+ const message = sanitizeHostErrorMessage(e.message);
3308
+ postWorkerMessage(activeProtocolToken, {
3309
+ success: false,
3310
+ error: `Worker uncaught exception: ${message}`
3311
+ });
3312
+ });
3313
+ var activeProtocolToken = null;
3314
+ if (parentPort) {
3315
+ if (workerData) {
3316
+ const input = workerData;
3317
+ activeProtocolToken = input.protocolToken;
3318
+ runPython(input).then((result) => {
3319
+ result.defenseStats = defense?.getStats();
3320
+ postWorkerMessage(input.protocolToken, result);
3321
+ }).catch((e) => {
3322
+ const message = sanitizeUnknownError(e);
3323
+ postWorkerMessage(input.protocolToken, {
3324
+ success: false,
3325
+ error: message,
3326
+ defenseStats: defense?.getStats()
3327
+ });
3328
+ });
3329
+ }
3330
+ }