@jerryan/just-bash 3.7.0 → 3.8.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 (215) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +15 -5
  3. package/dist/AGENTS.md +2 -2
  4. package/dist/Bash.d.ts +4 -2
  5. package/dist/bin/chunks/{awk2-KO7ZE3P7.js → awk2-NTRVFXRA.js} +1 -1
  6. package/dist/bin/chunks/{chmod-G2BCCQGF.js → chmod-GX5SYTRL.js} +1 -1
  7. package/dist/bin/chunks/chunk-2NJJXU4K.js +27 -0
  8. package/dist/bin/{shell/chunks/chunk-THFQI5LV.js → chunks/chunk-3ROYEBJI.js} +1 -1
  9. package/dist/bin/chunks/chunk-6FGMEZZP.js +20 -0
  10. package/dist/bin/chunks/{chunk-FO7XJH3J.js → chunk-6JUPBMCR.js} +1 -1
  11. package/dist/bin/chunks/{chunk-3DWQCLNP.js → chunk-7WBCA2BB.js} +1 -1
  12. package/dist/bin/{shell/chunks/chunk-HYLF56CC.js → chunks/chunk-ABP4OLJV.js} +1 -1
  13. package/dist/bin/{shell/chunks/chunk-7PUOS2OO.js → chunks/chunk-ANX7U57Q.js} +1 -1
  14. package/dist/bin/{shell/chunks/chunk-2UKTHDUM.js → chunks/chunk-BB5VTPMQ.js} +1 -1
  15. package/dist/bin/chunks/{chunk-WFHYGSLJ.js → chunk-CNVNOT67.js} +1 -1
  16. package/dist/bin/{shell/chunks/chunk-ADI36B7X.js → chunks/chunk-DRPHNXG7.js} +1 -1
  17. package/dist/bin/{shell/chunks/chunk-OXLC2WWX.js → chunks/chunk-H7PD6FLC.js} +10 -10
  18. package/dist/bin/{shell/chunks/chunk-QYZN33JA.js → chunks/chunk-IOKQFPM6.js} +1 -1
  19. package/dist/bin/chunks/{chunk-7KMOGI3N.js → chunk-KMYJMEON.js} +1 -1
  20. package/dist/bin/{shell/chunks/chunk-RPUFEP5O.js → chunks/chunk-M3Z5NZXT.js} +1 -1
  21. package/dist/bin/chunks/{chunk-NBTZL3VS.js → chunk-MBREBDZQ.js} +1 -1
  22. package/dist/bin/chunks/{chunk-L345YZ6R.js → chunk-MF3GVFLC.js} +1 -1
  23. package/dist/bin/{shell/chunks/chunk-RRECHBUS.js → chunks/chunk-MPFNZYEA.js} +1 -1
  24. package/dist/bin/{shell/chunks/chunk-F3UDTTI7.js → chunks/chunk-ONF4KUYV.js} +1 -1
  25. package/dist/bin/chunks/chunk-PPVF2N6C.js +3 -0
  26. package/dist/bin/chunks/{chunk-V2XF3TTW.js → chunk-PRVPFKTC.js} +1 -1
  27. package/dist/bin/{shell/chunks/chunk-7VWOECJ3.js → chunks/chunk-PTUQEN6I.js} +1 -1
  28. package/dist/bin/chunks/{chunk-R2J5MJOM.js → chunk-QFOXSCOD.js} +1 -1
  29. package/dist/bin/{shell/chunks/chunk-6TUILMPB.js → chunks/chunk-QFTZKD5O.js} +1 -1
  30. package/dist/bin/chunks/{chunk-PEUGMGJJ.js → chunk-QJWFCA7P.js} +1 -1
  31. package/dist/bin/{shell/chunks/chunk-66UHJFN6.js → chunks/chunk-RTN6X652.js} +1 -1
  32. package/dist/bin/{shell/chunks/chunk-6O4Z6BQT.js → chunks/chunk-T6OIISUC.js} +1 -1
  33. package/dist/bin/{shell/chunks/chunk-R76AK3KD.js → chunks/chunk-U5JLGI56.js} +1 -1
  34. package/dist/bin/chunks/{chunk-7PPAWLUI.js → chunk-V4S4A7M6.js} +1 -1
  35. package/dist/bin/{shell/chunks/chunk-E26NQEH2.js → chunks/chunk-VPSBWWXM.js} +1 -1
  36. package/dist/bin/chunks/{chunk-GA5TPRMF.js → chunk-YXPSX3SI.js} +11 -11
  37. package/dist/bin/chunks/{chunk-472JZJ2D.js → chunk-ZVG47PYA.js} +1 -1
  38. package/dist/bin/{shell/chunks/cp-TMDR6USI.js → chunks/cp-YLP7ULVT.js} +1 -1
  39. package/dist/bin/{shell/chunks/diff-YXZZCUSQ.js → chunks/diff-JSJ56EOK.js} +1 -1
  40. package/dist/bin/{shell/chunks/du-UKFUX7KM.js → chunks/du-DH76GZJ3.js} +1 -1
  41. package/dist/bin/chunks/{expr-NNMDHOCN.js → expr-PQEPO5TE.js} +1 -1
  42. package/dist/bin/chunks/{file-4T64QNLS.js → file-JA7QI2YT.js} +1 -1
  43. package/dist/bin/chunks/{find-W2RZWTOF.js → find-MHC4QV6H.js} +1 -1
  44. package/dist/bin/chunks/{flag-coverage-QJ5ZQKCF.js → flag-coverage-2H5CPEM6.js} +1 -1
  45. package/dist/bin/chunks/{grep-IHDO3L72.js → grep-VXWNMIDD.js} +1 -1
  46. package/dist/bin/chunks/{gzip-WUK63QLL.js → gzip-UQZL4R74.js} +1 -1
  47. package/dist/bin/{shell/chunks/jq-V7OTAVU5.js → chunks/jq-YS4PR46D.js} +1 -1
  48. package/dist/bin/chunks/js-exec-T3SAB2B6.js +1651 -0
  49. package/dist/bin/{shell/chunks/ls-EROTXGTC.js → chunks/ls-5Z45FV4U.js} +1 -1
  50. package/dist/bin/chunks/{mv-HDNKXPO6.js → mv-EOOP2TO3.js} +1 -1
  51. package/dist/bin/chunks/python3-3ERN3L6S.js +23 -0
  52. package/dist/bin/{shell/chunks/readlink-ZUIECKQC.js → chunks/readlink-EJ3IKLWW.js} +1 -1
  53. package/dist/bin/{shell/chunks/rg-ODJAYIKX.js → chunks/rg-WHVR3YDT.js} +1 -1
  54. package/dist/bin/{shell/chunks/rmdir-W5NBOJ7E.js → chunks/rmdir-PRNISPBA.js} +1 -1
  55. package/dist/bin/{shell/chunks/sed-4LVDFHIJ.js → chunks/sed-SY63U2YX.js} +1 -1
  56. package/dist/bin/chunks/{sleep-MOJQBZMY.js → sleep-DVFE2GSF.js} +1 -1
  57. package/dist/bin/chunks/{split-TVJYLTIJ.js → split-HIFKSV2A.js} +1 -1
  58. package/dist/bin/chunks/{sqlite3-5BGAK7VX.js → sqlite3-KNN6V2W6.js} +1 -1
  59. package/dist/bin/chunks/{tar-7HGZIMZD.js → tar-7XOP7VOX.js} +1 -1
  60. package/dist/bin/chunks/{timeout-RQOWSWYG.js → timeout-YGFHQJKX.js} +1 -1
  61. package/dist/bin/chunks/{xan-WW53ETXT.js → xan-RMH6JEXM.js} +1 -1
  62. package/dist/bin/chunks/{yq-MYZOS2WN.js → yq-CWBZMGUV.js} +1 -1
  63. package/dist/bin/just-bash.js +262 -262
  64. package/dist/bin/shell/chunks/{awk2-KO7ZE3P7.js → awk2-NTRVFXRA.js} +1 -1
  65. package/dist/bin/shell/chunks/{chmod-G2BCCQGF.js → chmod-GX5SYTRL.js} +1 -1
  66. package/dist/bin/shell/chunks/chunk-2NJJXU4K.js +27 -0
  67. package/dist/bin/{chunks/chunk-THFQI5LV.js → shell/chunks/chunk-3ROYEBJI.js} +1 -1
  68. package/dist/bin/shell/chunks/chunk-6FGMEZZP.js +20 -0
  69. package/dist/bin/shell/chunks/{chunk-FO7XJH3J.js → chunk-6JUPBMCR.js} +1 -1
  70. package/dist/bin/shell/chunks/{chunk-3DWQCLNP.js → chunk-7WBCA2BB.js} +1 -1
  71. package/dist/bin/{chunks/chunk-HYLF56CC.js → shell/chunks/chunk-ABP4OLJV.js} +1 -1
  72. package/dist/bin/{chunks/chunk-7PUOS2OO.js → shell/chunks/chunk-ANX7U57Q.js} +1 -1
  73. package/dist/bin/{chunks/chunk-2UKTHDUM.js → shell/chunks/chunk-BB5VTPMQ.js} +1 -1
  74. package/dist/bin/shell/chunks/{chunk-WFHYGSLJ.js → chunk-CNVNOT67.js} +1 -1
  75. package/dist/bin/{chunks/chunk-ADI36B7X.js → shell/chunks/chunk-DRPHNXG7.js} +1 -1
  76. package/dist/bin/{chunks/chunk-OXLC2WWX.js → shell/chunks/chunk-H7PD6FLC.js} +10 -10
  77. package/dist/bin/{chunks/chunk-QYZN33JA.js → shell/chunks/chunk-IOKQFPM6.js} +1 -1
  78. package/dist/bin/shell/chunks/{chunk-7KMOGI3N.js → chunk-KMYJMEON.js} +1 -1
  79. package/dist/bin/{chunks/chunk-RPUFEP5O.js → shell/chunks/chunk-M3Z5NZXT.js} +1 -1
  80. package/dist/bin/shell/chunks/{chunk-NBTZL3VS.js → chunk-MBREBDZQ.js} +1 -1
  81. package/dist/bin/shell/chunks/{chunk-L345YZ6R.js → chunk-MF3GVFLC.js} +1 -1
  82. package/dist/bin/{chunks/chunk-RRECHBUS.js → shell/chunks/chunk-MPFNZYEA.js} +1 -1
  83. package/dist/bin/{chunks/chunk-F3UDTTI7.js → shell/chunks/chunk-ONF4KUYV.js} +1 -1
  84. package/dist/bin/shell/chunks/chunk-PPVF2N6C.js +3 -0
  85. package/dist/bin/shell/chunks/{chunk-V2XF3TTW.js → chunk-PRVPFKTC.js} +1 -1
  86. package/dist/bin/{chunks/chunk-7VWOECJ3.js → shell/chunks/chunk-PTUQEN6I.js} +1 -1
  87. package/dist/bin/shell/chunks/{chunk-R2J5MJOM.js → chunk-QFOXSCOD.js} +1 -1
  88. package/dist/bin/{chunks/chunk-6TUILMPB.js → shell/chunks/chunk-QFTZKD5O.js} +1 -1
  89. package/dist/bin/shell/chunks/{chunk-PEUGMGJJ.js → chunk-QJWFCA7P.js} +1 -1
  90. package/dist/bin/{chunks/chunk-66UHJFN6.js → shell/chunks/chunk-RTN6X652.js} +1 -1
  91. package/dist/bin/{chunks/chunk-6O4Z6BQT.js → shell/chunks/chunk-T6OIISUC.js} +1 -1
  92. package/dist/bin/{chunks/chunk-R76AK3KD.js → shell/chunks/chunk-U5JLGI56.js} +1 -1
  93. package/dist/bin/shell/chunks/{chunk-7PPAWLUI.js → chunk-V4S4A7M6.js} +1 -1
  94. package/dist/bin/{chunks/chunk-E26NQEH2.js → shell/chunks/chunk-VPSBWWXM.js} +1 -1
  95. package/dist/bin/shell/chunks/{chunk-GA5TPRMF.js → chunk-YXPSX3SI.js} +11 -11
  96. package/dist/bin/shell/chunks/{chunk-472JZJ2D.js → chunk-ZVG47PYA.js} +1 -1
  97. package/dist/bin/{chunks/cp-TMDR6USI.js → shell/chunks/cp-YLP7ULVT.js} +1 -1
  98. package/dist/bin/{chunks/diff-YXZZCUSQ.js → shell/chunks/diff-JSJ56EOK.js} +1 -1
  99. package/dist/bin/{chunks/du-UKFUX7KM.js → shell/chunks/du-DH76GZJ3.js} +1 -1
  100. package/dist/bin/shell/chunks/{expr-NNMDHOCN.js → expr-PQEPO5TE.js} +1 -1
  101. package/dist/bin/shell/chunks/{file-4T64QNLS.js → file-JA7QI2YT.js} +1 -1
  102. package/dist/bin/shell/chunks/{find-W2RZWTOF.js → find-MHC4QV6H.js} +1 -1
  103. package/dist/bin/shell/chunks/{flag-coverage-QJ5ZQKCF.js → flag-coverage-2H5CPEM6.js} +1 -1
  104. package/dist/bin/shell/chunks/{grep-IHDO3L72.js → grep-VXWNMIDD.js} +1 -1
  105. package/dist/bin/shell/chunks/{gzip-WUK63QLL.js → gzip-UQZL4R74.js} +1 -1
  106. package/dist/bin/{chunks/jq-V7OTAVU5.js → shell/chunks/jq-YS4PR46D.js} +1 -1
  107. package/dist/bin/shell/chunks/js-exec-T3SAB2B6.js +1651 -0
  108. package/dist/bin/{chunks/ls-EROTXGTC.js → shell/chunks/ls-5Z45FV4U.js} +1 -1
  109. package/dist/bin/shell/chunks/{mv-HDNKXPO6.js → mv-EOOP2TO3.js} +1 -1
  110. package/dist/bin/shell/chunks/python3-3ERN3L6S.js +23 -0
  111. package/dist/bin/{chunks/readlink-ZUIECKQC.js → shell/chunks/readlink-EJ3IKLWW.js} +1 -1
  112. package/dist/bin/{chunks/rg-ODJAYIKX.js → shell/chunks/rg-WHVR3YDT.js} +1 -1
  113. package/dist/bin/{chunks/rmdir-W5NBOJ7E.js → shell/chunks/rmdir-PRNISPBA.js} +1 -1
  114. package/dist/bin/{chunks/sed-4LVDFHIJ.js → shell/chunks/sed-SY63U2YX.js} +1 -1
  115. package/dist/bin/shell/chunks/{sleep-MOJQBZMY.js → sleep-DVFE2GSF.js} +1 -1
  116. package/dist/bin/shell/chunks/{split-TVJYLTIJ.js → split-HIFKSV2A.js} +1 -1
  117. package/dist/bin/shell/chunks/{sqlite3-5BGAK7VX.js → sqlite3-KNN6V2W6.js} +1 -1
  118. package/dist/bin/shell/chunks/{tar-7HGZIMZD.js → tar-7XOP7VOX.js} +1 -1
  119. package/dist/bin/shell/chunks/{timeout-RQOWSWYG.js → timeout-YGFHQJKX.js} +1 -1
  120. package/dist/bin/shell/chunks/{xan-WW53ETXT.js → xan-RMH6JEXM.js} +1 -1
  121. package/dist/bin/shell/chunks/{yq-MYZOS2WN.js → yq-CWBZMGUV.js} +1 -1
  122. package/dist/bin/shell/shell.js +263 -263
  123. package/dist/bundle/browser.js +598 -579
  124. package/dist/bundle/chunks/{awk2-W6BNZEJN.js → awk2-VS5QVYHU.js} +1 -1
  125. package/dist/bundle/chunks/{chmod-XZNKTJHL.js → chmod-TEY5MD2W.js} +1 -1
  126. package/dist/bundle/chunks/{chunk-26GP3ACY.js → chunk-35MBA3VY.js} +1 -1
  127. package/dist/bundle/chunks/{chunk-IYJLVOVE.js → chunk-3OBCZP7T.js} +1 -1
  128. package/dist/bundle/chunks/{chunk-OR544SGH.js → chunk-45QZRGYF.js} +1 -1
  129. package/dist/bundle/chunks/{chunk-73JQKNZT.js → chunk-4KZT23KR.js} +11 -11
  130. package/dist/bundle/chunks/{chunk-PJM5C3HZ.js → chunk-5EI7WSRV.js} +10 -10
  131. package/dist/bundle/chunks/{chunk-T6DNSPYO.js → chunk-6BSOPPZH.js} +1 -1
  132. package/dist/bundle/chunks/{chunk-YNYC232D.js → chunk-6HO6HX7V.js} +1 -1
  133. package/dist/bundle/chunks/{chunk-2T7PBFL4.js → chunk-6QAM55HM.js} +1 -1
  134. package/dist/bundle/chunks/{chunk-SBOTR4JQ.js → chunk-ATGOUOX2.js} +1 -1
  135. package/dist/bundle/chunks/chunk-B6OSJB22.js +26 -0
  136. package/dist/bundle/chunks/{chunk-2TSZPVPI.js → chunk-BLPYR4TN.js} +1 -1
  137. package/dist/bundle/chunks/{chunk-VJ6UXG2R.js → chunk-CH7SUFFO.js} +1 -1
  138. package/dist/bundle/chunks/{chunk-FQUVK4Q5.js → chunk-DDPD7SIB.js} +1 -1
  139. package/dist/bundle/chunks/{chunk-TLPMB3FO.js → chunk-DMWNBCXJ.js} +1 -1
  140. package/dist/bundle/chunks/{chunk-YUOBBH7P.js → chunk-FSKXIFYT.js} +1 -1
  141. package/dist/bundle/chunks/{chunk-E3ABCXE4.js → chunk-GNPLDVBD.js} +1 -1
  142. package/dist/bundle/chunks/{chunk-FZZL53S2.js → chunk-GRUZ4SBY.js} +1 -1
  143. package/dist/bundle/chunks/{chunk-PMBXJ3OQ.js → chunk-HCKTU6IR.js} +1 -1
  144. package/dist/bundle/chunks/{chunk-4EDQZIAN.js → chunk-LGIJSCWH.js} +1 -1
  145. package/dist/bundle/chunks/chunk-MWL2I5BV.js +19 -0
  146. package/dist/bundle/chunks/{chunk-6IA4DXG2.js → chunk-N3A4JVFJ.js} +1 -1
  147. package/dist/bundle/chunks/{chunk-PPEXVPHR.js → chunk-O452S4KX.js} +1 -1
  148. package/dist/bundle/chunks/{chunk-3BMWRGU2.js → chunk-RWQWFXMH.js} +1 -1
  149. package/dist/bundle/chunks/{chunk-D5FHVW27.js → chunk-S6DNKKUL.js} +1 -1
  150. package/dist/bundle/chunks/{chunk-OPYVVD5P.js → chunk-SE23TEGG.js} +1 -1
  151. package/dist/bundle/chunks/{chunk-ULXTDFQC.js → chunk-U57DSHID.js} +1 -1
  152. package/dist/bundle/chunks/{chunk-ACVD6PQF.js → chunk-WE7BJ7YU.js} +1 -1
  153. package/dist/bundle/chunks/chunk-WXPNKIIH.js +2 -0
  154. package/dist/bundle/chunks/{chunk-5I5U6IYI.js → chunk-XQ2ZZFO6.js} +1 -1
  155. package/dist/bundle/chunks/{chunk-YFFU74KY.js → chunk-XV2V56NQ.js} +1 -1
  156. package/dist/bundle/chunks/{chunk-5DMO6LFU.js → chunk-Y6JBSHCM.js} +1 -1
  157. package/dist/bundle/chunks/{cp-NWITRTH3.js → cp-UR762VVT.js} +1 -1
  158. package/dist/bundle/chunks/{diff-CSARC7WF.js → diff-VDB6RXHO.js} +1 -1
  159. package/dist/bundle/chunks/{du-IFLWEM6M.js → du-EQKH3UNA.js} +1 -1
  160. package/dist/bundle/chunks/{expr-XSBELPAC.js → expr-A5XITHQD.js} +1 -1
  161. package/dist/bundle/chunks/{file-URNAD6FQ.js → file-6AYYTULJ.js} +1 -1
  162. package/dist/bundle/chunks/{find-EW6OHRPJ.js → find-RLKBCGJR.js} +1 -1
  163. package/dist/bundle/chunks/{flag-coverage-PIF5QRO7.js → flag-coverage-UMQ3BWDP.js} +1 -1
  164. package/dist/bundle/chunks/{grep-QDFNKAUW.js → grep-Q2O5EIXQ.js} +1 -1
  165. package/dist/bundle/chunks/{gzip-HBDKZBIP.js → gzip-KC5ENBD2.js} +1 -1
  166. package/dist/bundle/chunks/{jq-NY7PCVMH.js → jq-UKAA3QWU.js} +1 -1
  167. package/dist/bundle/chunks/js-exec-ZQMIYQTH.js +1650 -0
  168. package/dist/bundle/chunks/{ls-WJ7EIFVM.js → ls-WH5S4PPL.js} +1 -1
  169. package/dist/bundle/chunks/{mv-E2NFLGRQ.js → mv-WE7DBLEK.js} +1 -1
  170. package/dist/bundle/chunks/python3-QB7OE256.js +22 -0
  171. package/dist/bundle/chunks/{readlink-XCFO7YD2.js → readlink-JSRKXLLQ.js} +1 -1
  172. package/dist/bundle/chunks/{rg-J7XDRV3B.js → rg-JKB7DR66.js} +1 -1
  173. package/dist/bundle/chunks/{rmdir-UMUDM2L2.js → rmdir-3WTXMVKI.js} +1 -1
  174. package/dist/bundle/chunks/{sed-LIRH26EA.js → sed-6G32B25J.js} +1 -1
  175. package/dist/bundle/chunks/{sleep-25QUPVDK.js → sleep-PPRBTSVR.js} +1 -1
  176. package/dist/bundle/chunks/{split-D4HPO4G5.js → split-HUKVGJTW.js} +1 -1
  177. package/dist/bundle/chunks/{sqlite3-3HL2ECCQ.js → sqlite3-KB3MXTTM.js} +1 -1
  178. package/dist/bundle/chunks/{tar-B72KU357.js → tar-LE7LAAIX.js} +1 -1
  179. package/dist/bundle/chunks/{timeout-37GM7IIL.js → timeout-C6WDYPLV.js} +1 -1
  180. package/dist/bundle/chunks/{xan-UIGVJCMA.js → xan-UIL24CGT.js} +1 -1
  181. package/dist/bundle/chunks/{yq-FGNXZCGX.js → yq-ZRNZKDLE.js} +1 -1
  182. package/dist/bundle/index.cjs +2654 -1083
  183. package/dist/bundle/index.js +218 -218
  184. package/dist/commands/diff/format.d.ts +46 -0
  185. package/dist/commands/js-exec/js-exec.d.ts +1 -14
  186. package/dist/commands/js-exec/run-runtime.d.ts +10 -0
  187. package/dist/fs/traversal.d.ts +9 -0
  188. package/dist/interpreter/helpers/substitution-status.d.ts +34 -0
  189. package/dist/interpreter/interpreter.d.ts +1 -1
  190. package/dist/interpreter/types.d.ts +8 -1
  191. package/dist/limits.d.ts +2 -0
  192. package/dist/timers.d.ts +0 -9
  193. package/dist/types.d.ts +4 -3
  194. package/package.json +8 -8
  195. package/dist/bin/chunks/chunk-23OI2XDJ.js +0 -20
  196. package/dist/bin/chunks/chunk-E54Z6VIE.js +0 -12
  197. package/dist/bin/chunks/chunk-QKJAAJ7J.js +0 -3
  198. package/dist/bin/chunks/chunk-U7YR5CDD.js +0 -20
  199. package/dist/bin/chunks/js-exec-BE37X4L2.js +0 -99
  200. package/dist/bin/chunks/js-exec-worker.js +0 -4989
  201. package/dist/bin/chunks/python3-TJ6DCPIA.js +0 -14
  202. package/dist/bin/shell/chunks/chunk-23OI2XDJ.js +0 -20
  203. package/dist/bin/shell/chunks/chunk-E54Z6VIE.js +0 -12
  204. package/dist/bin/shell/chunks/chunk-QKJAAJ7J.js +0 -3
  205. package/dist/bin/shell/chunks/chunk-U7YR5CDD.js +0 -20
  206. package/dist/bin/shell/chunks/js-exec-BE37X4L2.js +0 -99
  207. package/dist/bin/shell/chunks/python3-TJ6DCPIA.js +0 -14
  208. package/dist/bundle/chunks/chunk-BS6EJR2R.js +0 -11
  209. package/dist/bundle/chunks/chunk-HMM3NGUJ.js +0 -19
  210. package/dist/bundle/chunks/chunk-PS2RJNZZ.js +0 -2
  211. package/dist/bundle/chunks/chunk-UTKGYVUZ.js +0 -7
  212. package/dist/bundle/chunks/js-exec-IREGAOMH.js +0 -98
  213. package/dist/bundle/chunks/js-exec-worker.js +0 -4989
  214. package/dist/bundle/chunks/python3-W4UMQJAQ.js +0 -13
  215. package/dist/commands/js-exec/js-exec-worker.d.ts +0 -33
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env node
2
- import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{a as Q,b as W}from"./chunk-E54Z6VIE.js";import{a as I}from"./chunk-3DWQCLNP.js";import"./chunk-3MRB66F4.js";import"./chunk-O2BCKSMK.js";import"./chunk-TW2IJRUF.js";import"./chunk-QKJAAJ7J.js";import{a as F}from"./chunk-MROECM42.js";import{c as w}from"./chunk-42AMF6EE.js";import{b as M}from"./chunk-HWI42GQO.js";import{b as C}from"./chunk-CPKBPQ2C.js";import"./chunk-OHFB3M3X.js";import{a as A,b as d}from"./chunk-PBOVSFTJ.js";import{a as E}from"./chunk-I4IRHQDW.js";import{a as P,b as D}from"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";import{fileURLToPath as B}from"node:url";import{Worker as L}from"node:worker_threads";var z={name:"python3",summary:"Execute Python code via CPython Emscripten",usage:"python3 [OPTIONS] [-c CODE | -m MODULE | FILE] [ARGS...]",description:["Execute Python code using CPython compiled to WebAssembly via Emscripten.","","This command runs Python in an isolated environment with access to","the virtual filesystem. Standard library modules are available."],options:["-c CODE Execute CODE as Python script","-m MODULE Run library module as a script","--version Show Python version","--help Show this help"],examples:['python3 -c "print(1 + 2)"','python3 -c "import sys; print(sys.version)"',"python3 script.py","python3 script.py arg1 arg2",`echo 'print("hello")' | python3`],notes:["CPython runs in WebAssembly, so execution may be slower than native Python.","Standard library modules are available (no pip install).","Maximum execution time is 30 seconds by default."]};function _(t){let e={code:null,module:null,scriptFile:null,showVersion:!1,scriptArgs:[]};if(t.length===0)return e;let r=t.findIndex(n=>!n.startsWith("-")||n==="-"||n==="--");for(let n=0;n<(r===-1?t.length:r);n++){let i=t[n];if(i==="-c")return n+1>=t.length?{stdout:"",stderr:`python3: option requires an argument -- 'c'
4
- `,exitCode:2}:(e.code=t[n+1],e.scriptArgs=t.slice(n+2),e);if(i==="-m")return n+1>=t.length?{stdout:"",stderr:`python3: option requires an argument -- 'm'
5
- `,exitCode:2}:(e.module=t[n+1],e.scriptArgs=t.slice(n+2),e);if(i==="--version"||i==="-V")return e.showVersion=!0,e;if(i.startsWith("-")&&i!=="-")return{stdout:"",stderr:`python3: unrecognized option '${i}'
6
- `,exitCode:2}}if(r!==-1){let n=t[r];n==="--"?r+1<t.length&&(e.scriptFile=t[r+1],e.scriptArgs=t.slice(r+2)):(e.scriptFile=n,e.scriptArgs=t.slice(r+1))}return e}var b=new WeakMap;function R(t){let e=b.get(t);return e||(e={executionQueue:[],activeExecution:null,poisonedError:null},b.set(t,e)),e}function ne(){b=new WeakMap}var H=B(new URL("./worker.js",import.meta.url));function U(t,e){if(!t||typeof t!="object")return{success:!1,error:"Malformed worker response"};let r=t;return typeof r.protocolToken!="string"||r.protocolToken!==e?{success:!1,error:"Malformed worker response: invalid protocol token"}:r.type==="security-violation"?{success:!1,error:`Security violation: ${typeof r.violation?.type=="string"?r.violation.type:"unknown"}`}:typeof r.success!="boolean"?{success:!1,error:"Malformed worker response: missing success flag"}:r.success?{success:!0}:{success:!1,error:typeof r.error=="string"&&r.error.length>0?r.error:"Worker execution failed"}}function k(t){if(t.poisonedError!==null){for(let o of t.executionQueue.splice(0))o.state==="queued"&&(o.state="settled",o.stopBridge(),o.settle({success:!1,error:t.poisonedError}));return}if(t.activeExecution!==null||t.executionQueue.length===0)return;for(;t.executionQueue.length>0&&t.executionQueue[0]?.state!=="queued";)t.executionQueue.shift();if(t.executionQueue.length===0)return;let e=t.executionQueue.shift();if(!e)return;e.state="running",t.activeExecution=e;let r;try{r=M.runTrusted(()=>new L(H,{workerData:e.input}))}catch(o){let s=o instanceof Error?o.message:String(o);e.state="settled",e.settle({success:!1,error:d(s)}),t.activeExecution===e&&(t.activeExecution=null,k(t));return}e.worker=r;let n=!0,i=()=>{n&&(n=!1,r.removeListener("message",u),r.removeListener("error",g),r.removeListener("exit",v))},c=async(o,s)=>{if(!(t.activeExecution?.executionId!==e.executionId||e.state!=="running")){if(e.state="terminating",i(),e.settle(o),s&&!await e.controller.terminate(r)){let f="Worker termination was not acknowledged";e.worker=null,e.state="settled",t.poisonedError=f,t.activeExecution?.executionId===e.executionId&&(t.activeExecution=null),k(t);return}e.worker=null,e.state="settled",t.activeExecution?.executionId===e.executionId&&(t.activeExecution=null,k(t))}};e.cancel=o=>{c(o,!0)};let p=w(e.requireDefenseContext,"python3","worker message callback",o=>{try{e.controller.assertMessageSize(o,"response")}catch(s){c({success:!1,error:d(E(s))},!0);return}c(U(o,e.input.protocolToken),!0)}),h=w(e.requireDefenseContext,"python3","worker error callback",o=>{let s=d(E(o));c({success:!1,error:s},!0)}),a=w(e.requireDefenseContext,"python3","worker exit callback",()=>{c({success:!1,error:"Worker exited unexpectedly"},!1)}),u=o=>{try{p(o)}catch(s){let l=s instanceof Error?s.message:String(s);c({success:!1,error:d(l)},!0)}},g=o=>{try{h(o)}catch(s){let l=s instanceof Error?s.message:String(s);c({success:!1,error:d(l)},!0)}},v=()=>{try{a()}catch(o){let s=o instanceof Error?o.message:String(o);c({success:!1,error:d(s)},!0)}};r.on("message",u),r.on("error",g),r.on("exit",v)}async function N(t,e,r,n,i=[]){let c=Q(),p=new W(c,r.fs,r.cwd,"python3",r.fetch,r.limits.maxOutputSize),h=r.limits.maxPythonTimeoutMs,a=R(r.fs);if(a.poisonedError!==null)return{stdout:"",stderr:`python3: ${a.poisonedError}
7
- `,exitCode:1};let u=new I({commandName:"python3",timeoutMs:h,signal:r.signal,maxMessageBytes:r.limits.maxWorkerMessageBytes}),g={protocolToken:u.protocolToken,sharedBuffer:c,pythonCode:t,stdin:e,cwd:r.cwd,env:F(r.env),args:i,scriptPath:n,timeoutMs:h,maxFileSize:r.limits.maxStringLength};u.assertMessageSize({...g,sharedBuffer:void 0},"request");let v=new Promise(l=>{let f=!1,m={executionId:Symbol("python3 execution"),input:g,settle:y=>{f||(f=!0,u.close(),l(y))},requireDefenseContext:r.requireDefenseContext,state:"queued",worker:null,controller:u,stopBridge:()=>p.stop?.(),cancel:()=>{}};m.cancel=y=>{if(m.state!=="queued")return;m.state="settled";let x=a.executionQueue.indexOf(m);x!==-1&&a.executionQueue.splice(x,1),m.settle(y),k(a)};let O=w(r.requireDefenseContext,"python3","worker cancellation callback",y=>{p.stop?.(),m.cancel({success:!1,error:y==="abort"?u.abortMessage():u.timeoutMessage()})}),T=y=>{try{O(y)}catch(x){let $=x instanceof Error?x.message:String(x);m.cancel({success:!1,error:d($)})}};u.arm(T),u.isCanceled||(a.executionQueue.push(m),k(a))}),[o,s]=await Promise.all([p.run(h).catch(l=>({stdout:"",stderr:`python3: bridge error: ${d(E(l))}
8
- `,exitCode:1})),v.catch(l=>({success:!1,error:d(E(l))}))]);if(!s.success&&s.error){let l=d(s.error),f=s.error===u.timeoutMessage()||s.error===u.abortMessage();return{stdout:o.stdout,stderr:`${o.stderr}python3: ${l}
9
- `,exitCode:o.exitCode||(f?124:1)}}return{...o}}var V={name:"python3",async execute(t,e){if(D(t))return P(z);let r=_(t);if("exitCode"in r)return r;if(r.showVersion)return{stdout:`Python 3.13.2 (Emscripten)
10
- `,stderr:"",exitCode:0};let n,i,c=e.stdin;if(r.code!==null)n=r.code,i="-c";else if(r.module!==null){if(!/^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(r.module))return{stdout:"",stderr:`python3: No module named '${r.module.slice(0,200)}'
11
- `,exitCode:1};n=`import runpy; runpy.run_module('${r.module}', run_name='__main__')`,i=r.module}else if(r.scriptFile==="-")n=C(e.stdin),c="",i="-";else if(r.scriptFile!==null){let p=e.fs.resolvePath(e.cwd,r.scriptFile);if(!await e.fs.exists(p))return{stdout:"",stderr:`python3: can't open file '${r.scriptFile}': [Errno 2] No such file or directory
12
- `,exitCode:2};try{n=await e.fs.readFile(p),i=r.scriptFile}catch(h){let a=A(h.message);return{stdout:"",stderr:`python3: can't open file '${r.scriptFile}': ${a}
13
- `,exitCode:2}}}else if(C(e.stdin).trim())n=C(e.stdin),c="",i="<stdin>";else return{stdout:"",stderr:`python3: no input provided (use -c CODE, -m MODULE, or provide a script file)
14
- `,exitCode:2};return N(n,c,e,i,r.scriptArgs)}},se={name:"python",async execute(t,e){return V.execute(t,e)}};export{ne as _resetExecutionQueue,V as python3Command,se as pythonCommand};
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env node
2
- import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{b as D}from"./chunk-CPKBPQ2C.js";import{a as N}from"./chunk-NE4R2FVV.js";import{a as H,b as A}from"./chunk-MUFNRCMY.js";var b=class{diff(e,n,t={}){let i;typeof t=="function"?(i=t,t={}):"callback"in t&&(i=t.callback);let d=this.castInput(e,t),o=this.castInput(n,t),s=this.removeEmpty(this.tokenize(d,t)),a=this.removeEmpty(this.tokenize(o,t));return this.diffWithOptionsObj(s,a,t,i)}diffWithOptionsObj(e,n,t,i){var d;let o=l=>{if(l=this.postProcess(l,t),i){setTimeout(function(){i(l)},0);return}else return l},s=n.length,a=e.length,u=1,r=s+a;t.maxEditLength!=null&&(r=Math.min(r,t.maxEditLength));let g=(d=t.timeout)!==null&&d!==void 0?d:1/0,w=Date.now()+g,m=[{oldPos:-1,lastComponent:void 0}],C=this.extractCommon(m[0],n,e,0,t);if(m[0].oldPos+1>=a&&C+1>=s)return o(this.buildValues(m[0].lastComponent,n,e));let P=-1/0,x=1/0,L=()=>{for(let l=Math.max(P,-u);l<=Math.min(x,u);l+=2){let c,h=m[l-1],p=m[l+1];h&&(m[l-1]=void 0);let y=!1;if(p){let S=p.oldPos-l;y=p&&0<=S&&S<s}let v=h&&h.oldPos+1<a;if(!y&&!v){m[l]=void 0;continue}if(!v||y&&h.oldPos<p.oldPos?c=this.addToPath(p,!0,!1,0,t):c=this.addToPath(h,!1,!0,1,t),C=this.extractCommon(c,n,e,l,t),c.oldPos+1>=a&&C+1>=s)return o(this.buildValues(c.lastComponent,n,e))||!0;m[l]=c,c.oldPos+1>=a&&(x=Math.min(x,l-1)),C+1>=s&&(P=Math.max(P,l+1))}u++};if(i)(function l(){setTimeout(function(){if(u>r||Date.now()>w)return i(void 0);L()||l()},0)})();else for(;u<=r&&Date.now()<=w;){let l=L();if(l)return l}}addToPath(e,n,t,i,d){let o=e.lastComponent;return o&&!d.oneChangePerToken&&o.added===n&&o.removed===t?{oldPos:e.oldPos+i,lastComponent:{count:o.count+1,added:n,removed:t,previousComponent:o.previousComponent}}:{oldPos:e.oldPos+i,lastComponent:{count:1,added:n,removed:t,previousComponent:o}}}extractCommon(e,n,t,i,d){let o=n.length,s=t.length,a=e.oldPos,u=a-i,r=0;for(;u+1<o&&a+1<s&&this.equals(t[a+1],n[u+1],d);)u++,a++,r++,d.oneChangePerToken&&(e.lastComponent={count:1,previousComponent:e.lastComponent,added:!1,removed:!1});return r&&!d.oneChangePerToken&&(e.lastComponent={count:r,previousComponent:e.lastComponent,added:!1,removed:!1}),e.oldPos=a,u}equals(e,n,t){return t.comparator?t.comparator(e,n):e===n||!!t.ignoreCase&&e.toLowerCase()===n.toLowerCase()}removeEmpty(e){let n=[];for(let t=0;t<e.length;t++)e[t]&&n.push(e[t]);return n}castInput(e,n){return e}tokenize(e,n){return Array.from(e)}join(e){return e.join("")}postProcess(e,n){return e}get useLongestToken(){return!1}buildValues(e,n,t){let i=[],d;for(;e;)i.push(e),d=e.previousComponent,delete e.previousComponent,e=d;i.reverse();let o=i.length,s=0,a=0,u=0;for(;s<o;s++){let r=i[s];if(r.removed)r.value=this.join(t.slice(u,u+r.count)),u+=r.count;else{if(!r.added&&this.useLongestToken){let g=n.slice(a,a+r.count);g=g.map(function(w,m){let C=t[u+m];return C.length>w.length?C:w}),r.value=this.join(g)}else r.value=this.join(n.slice(a,a+r.count));a+=r.count,r.added||(u+=r.count)}}return i}};var I=class extends b{constructor(){super(...arguments),this.tokenize=W}equals(e,n,t){return t.ignoreWhitespace?((!t.newlineIsToken||!e.includes(`
4
- `))&&(e=e.trim()),(!t.newlineIsToken||!n.includes(`
5
- `))&&(n=n.trim())):t.ignoreNewlineAtEof&&!t.newlineIsToken&&(e.endsWith(`
6
- `)&&(e=e.slice(0,-1)),n.endsWith(`
7
- `)&&(n=n.slice(0,-1))),super.equals(e,n,t)}},O=new I;function T(f,e,n){return O.diff(f,e,n)}function W(f,e){e.stripTrailingCr&&(f=f.replace(/\r\n/g,`
8
- `));let n=[],t=f.split(/(\n|\r\n)/);t[t.length-1]||t.pop();for(let i=0;i<t.length;i++){let d=t[i];i%2&&!e.newlineIsToken?n[n.length-1]+=d:n.push(d)}return n}var j={includeIndex:!0,includeUnderline:!0,includeFileHeaders:!0};function F(f,e,n,t,i,d,o){let s;o?typeof o=="function"?s={callback:o}:s=o:s={},typeof s.context>"u"&&(s.context=4);let a=s.context;if(s.newlineIsToken)throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");if(s.callback){let{callback:r}=s;T(n,t,Object.assign(Object.assign({},s),{callback:g=>{let w=u(g);r(w)}}))}else return u(T(n,t,s));function u(r){if(!r)return;r.push({value:"",lines:[]});function g(l){return l.map(function(c){return" "+c})}let w=[],m=0,C=0,P=[],x=1,L=1;for(let l=0;l<r.length;l++){let c=r[l],h=c.lines||R(c.value);if(c.lines=h,c.added||c.removed){if(!m){let p=r[l-1];m=x,C=L,p&&(P=a>0?g(p.lines.slice(-a)):[],m-=P.length,C-=P.length)}for(let p of h)P.push((c.added?"+":"-")+p);c.added?L+=h.length:x+=h.length}else{if(m)if(h.length<=a*2&&l<r.length-2)for(let p of g(h))P.push(p);else{let p=Math.min(h.length,a);for(let v of g(h.slice(0,p)))P.push(v);let y={oldStart:m,oldLines:x-m+p,newStart:C,newLines:L-C+p,lines:P};w.push(y),m=0,C=0,P=[]}x+=h.length,L+=h.length}}for(let l of w)for(let c=0;c<l.lines.length;c++)l.lines[c].endsWith(`
9
- `)?l.lines[c]=l.lines[c].slice(0,-1):(l.lines.splice(c+1,0,"\"),c++);return{oldFileName:f,newFileName:e,oldHeader:i,newHeader:d,hunks:w}}}function E(f,e){if(e||(e=j),Array.isArray(f)){if(f.length>1&&!e.includeFileHeaders)throw new Error("Cannot omit file headers on a multi-file patch. (The result would be unparseable; how would a tool trying to apply the patch know which changes are to which file?)");return f.map(t=>E(t,e)).join(`
10
- `)}let n=[];e.includeIndex&&f.oldFileName==f.newFileName&&n.push("Index: "+f.oldFileName),e.includeUnderline&&n.push("==================================================================="),e.includeFileHeaders&&(n.push("--- "+f.oldFileName+(typeof f.oldHeader>"u"?"":" "+f.oldHeader)),n.push("+++ "+f.newFileName+(typeof f.newHeader>"u"?"":" "+f.newHeader)));for(let t=0;t<f.hunks.length;t++){let i=f.hunks[t];i.oldLines===0&&(i.oldStart-=1),i.newLines===0&&(i.newStart-=1),n.push("@@ -"+i.oldStart+","+i.oldLines+" +"+i.newStart+","+i.newLines+" @@");for(let d of i.lines)n.push(d)}return n.join(`
11
- `)+`
12
- `}function k(f,e,n,t,i,d,o){if(typeof o=="function"&&(o={callback:o}),o?.callback){let{callback:s}=o;F(f,e,n,t,i,d,Object.assign(Object.assign({},o),{callback:a=>{s(a?E(a,o.headerOptions):void 0)}}))}else{let s=F(f,e,n,t,i,d,o);return s?E(s,o?.headerOptions):void 0}}function R(f){let e=f.endsWith(`
13
- `),n=f.split(`
14
- `).map(t=>t+`
15
- `);return e?n.pop():n.push(n.pop().slice(0,-1)),n}var z={name:"diff",summary:"compare files line by line",usage:"diff [OPTION]... FILE1 FILE2",options:["-u, --unified output unified diff format (default)","-q, --brief report only whether files differ","-s, --report-identical-files report when files are the same","-i, --ignore-case ignore case differences"," --help display this help and exit"]},_={unified:{short:"u",long:"unified",type:"boolean"},brief:{short:"q",long:"brief",type:"boolean"},reportSame:{short:"s",long:"report-identical-files",type:"boolean"},ignoreCase:{short:"i",long:"ignore-case",type:"boolean"}},ee={name:"diff",async execute(f,e){if(A(f))return H(z);let n=N("diff",f,_);if(!n.ok)return n.error;let t=n.result.flags.brief,i=n.result.flags.reportSame,d=n.result.flags.ignoreCase,o=n.result.positional;if(n.result.flags.unified,o.length<2)return{stdout:"",stderr:`diff: missing operand
16
- `,exitCode:2};let s,a,[u,r]=o;try{s=u==="-"?D(e.stdin):await e.fs.readFile(e.fs.resolvePath(e.cwd,u))}catch{return{stdout:"",stderr:`diff: ${u}: No such file or directory
17
- `,exitCode:2}}try{a=r==="-"?D(e.stdin):await e.fs.readFile(e.fs.resolvePath(e.cwd,r))}catch{return{stdout:"",stderr:`diff: ${r}: No such file or directory
18
- `,exitCode:2}}let g=s,w=a;return d&&(g=g.toLowerCase(),w=w.toLowerCase()),g===w?i?{stdout:`Files ${u} and ${r} are identical
19
- `,stderr:"",exitCode:0}:{stdout:"",stderr:"",exitCode:0}:t?{stdout:`Files ${u} and ${r} differ
20
- `,stderr:"",exitCode:1}:{stdout:k(u,r,s,a,"","",{context:3}),stderr:"",exitCode:1}}},ne={name:"diff",flags:[{flag:"-u",type:"boolean"},{flag:"-q",type:"boolean"},{flag:"-s",type:"boolean"},{flag:"-i",type:"boolean"}],needsArgs:!0,minArgs:2};export{ee as a,ne as b};
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env node
2
- import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{a as C}from"./chunk-3MRB66F4.js";import{b as L}from"./chunk-O2BCKSMK.js";import{a as I,b as l}from"./chunk-TW2IJRUF.js";import{d as A,e as m}from"./chunk-QKJAAJ7J.js";import{b as w}from"./chunk-HWI42GQO.js";import{a as _,b as f}from"./chunk-OHFB3M3X.js";import{a as F,b as D}from"./chunk-PBOVSFTJ.js";var h={NOOP:0,READ_FILE:1,WRITE_FILE:2,STAT:3,READDIR:4,MKDIR:5,RM:6,EXISTS:7,APPEND_FILE:8,SYMLINK:9,READLINK:10,LSTAT:11,CHMOD:12,REALPATH:13,RENAME:14,COPY_FILE:15,WRITE_FILE_RANGE:17,READ_RESULT_RANGE:18,WRITE_STDOUT:100,WRITE_STDERR:101,EXIT:102,HTTP_REQUEST:200,EXEC_COMMAND:300,INVOKE_TOOL:400},S={IDLE:0,REQUEST:1,CANCELLED:2},r={NONE:0,SUCCESS:1,ERROR:2},a={NONE:0,NOT_FOUND:1,IS_DIRECTORY:2,NOT_DIRECTORY:3,EXISTS:4,PERMISSION_DENIED:5,INVALID_PATH:6,IO_ERROR:7,NETWORK_ERROR:9,NETWORK_NOT_CONFIGURED:10,NOT_EMPTY:11,LOOP:12,FILE_TOO_LARGE:13,NO_SPACE:14,BUSY:15,READ_ONLY:16,CROSS_DEVICE:17},O=Object.assign(Object.create(null),{ENOENT:a.NOT_FOUND,EISDIR:a.IS_DIRECTORY,ENOTDIR:a.NOT_DIRECTORY,ENOTEMPTY:a.NOT_EMPTY,EEXIST:a.EXISTS,EPERM:a.PERMISSION_DENIED,EACCES:a.PERMISSION_DENIED,EINVAL:a.INVALID_PATH,ELOOP:a.LOOP,EFBIG:a.FILE_TOO_LARGE,ENOSPC:a.NO_SPACE,EBUSY:a.BUSY,EROFS:a.READ_ONLY,EXDEV:a.CROSS_DEVICE}),P=Object.create(null);for(let[d,t]of Object.entries(O))P[t]=d;var o={OP_CODE:0,REQUEST:4,PATH_LENGTH:8,DATA_LENGTH:12,RESULT_LENGTH:16,ERROR_CODE:20,FLAGS:24,MODE:28,RESULT_STATE:32,PATH_BUFFER:36,DATA_BUFFER:4132},R={PATH_BUFFER:4096,DATA_BUFFER:8388608,TOTAL:8392740},g={NONE:0,RECURSIVE:1,FORCE:2,MKDIR_RECURSIVE:1},u={IS_FILE:0,IS_DIRECTORY:1,IS_SYMLINK:2,MODE:4,SIZE:8,MTIME:16,TOTAL:24};function M(){return new I(R.TOTAL)}var T=class{int32View;uint8View;dataView;constructor(t){this.int32View=new Int32Array(t),this.uint8View=new Uint8Array(t),this.dataView=new DataView(t)}getOpCode(){return l.load(this.int32View,o.OP_CODE/4)}setOpCode(t){l.store(this.int32View,o.OP_CODE/4,t)}getRequest(){return l.load(this.int32View,o.REQUEST/4)}setRequest(t){l.store(this.int32View,o.REQUEST/4,t)}getResultState(){return l.load(this.int32View,o.RESULT_STATE/4)}setResultState(t){l.store(this.int32View,o.RESULT_STATE/4,t)}getPathLength(){return l.load(this.int32View,o.PATH_LENGTH/4)}setPathLength(t){l.store(this.int32View,o.PATH_LENGTH/4,t)}getDataLength(){return l.load(this.int32View,o.DATA_LENGTH/4)}setDataLength(t){l.store(this.int32View,o.DATA_LENGTH/4,t)}getResultLength(){return l.load(this.int32View,o.RESULT_LENGTH/4)}setResultLength(t){l.store(this.int32View,o.RESULT_LENGTH/4,t)}getErrorCode(){return l.load(this.int32View,o.ERROR_CODE/4)}setErrorCode(t){l.store(this.int32View,o.ERROR_CODE/4,t)}getFlags(){return l.load(this.int32View,o.FLAGS/4)}setFlags(t){l.store(this.int32View,o.FLAGS/4,t)}getMode(){return l.load(this.int32View,o.MODE/4)}setMode(t){l.store(this.int32View,o.MODE/4,t)}getPath(){let t=this.getPathLength(),e=this.uint8View.slice(o.PATH_BUFFER,o.PATH_BUFFER+t);return new TextDecoder().decode(e)}setPath(t){let e=new TextEncoder().encode(t);if(e.length>R.PATH_BUFFER)throw new Error(`Path too long: ${e.length} > ${R.PATH_BUFFER}`);this.uint8View.set(e,o.PATH_BUFFER),this.setPathLength(e.length)}getData(){let t=this.getDataLength();return this.uint8View.slice(o.DATA_BUFFER,o.DATA_BUFFER+t)}setData(t){if(t.length>R.DATA_BUFFER)throw new Error(`Data too large: ${t.length} > ${R.DATA_BUFFER}`);this.uint8View.set(t,o.DATA_BUFFER),this.setDataLength(t.length)}getDataAsString(){let t=this.getData();return new TextDecoder().decode(t)}setDataFromString(t){let e=new TextEncoder().encode(t);this.setData(e)}getResult(){let t=this.getResultLength();return this.uint8View.slice(o.DATA_BUFFER,o.DATA_BUFFER+t)}setResult(t){if(t.length>R.DATA_BUFFER)throw new Error(`Result too large: ${t.length} > ${R.DATA_BUFFER}`);this.uint8View.set(t,o.DATA_BUFFER),this.setResultLength(t.length)}setResultPrefix(t){if(t.length>2147483647)throw new Error(`Result too large: ${t.length} exceeds int32`);let e=Math.min(t.length,R.DATA_BUFFER);this.uint8View.set(t.subarray(0,e),o.DATA_BUFFER),this.setResultLength(t.length)}getResultAsString(){let t=this.getResult();return new TextDecoder().decode(t)}setResultFromString(t){let e=new TextEncoder().encode(t);this.setResult(e)}encodeStat(t){this.uint8View[o.DATA_BUFFER+u.IS_FILE]=t.isFile?1:0,this.uint8View[o.DATA_BUFFER+u.IS_DIRECTORY]=t.isDirectory?1:0,this.uint8View[o.DATA_BUFFER+u.IS_SYMLINK]=t.isSymbolicLink?1:0,this.dataView.setInt32(o.DATA_BUFFER+u.MODE,t.mode,!0);let e=Math.min(t.size,Number.MAX_SAFE_INTEGER);this.dataView.setFloat64(o.DATA_BUFFER+u.SIZE,e,!0),this.dataView.setFloat64(o.DATA_BUFFER+u.MTIME,t.mtime.getTime(),!0),this.setResultLength(u.TOTAL)}decodeStat(){return{isFile:this.uint8View[o.DATA_BUFFER+u.IS_FILE]===1,isDirectory:this.uint8View[o.DATA_BUFFER+u.IS_DIRECTORY]===1,isSymbolicLink:this.uint8View[o.DATA_BUFFER+u.IS_SYMLINK]===1,mode:this.dataView.getInt32(o.DATA_BUFFER+u.MODE,!0),size:this.dataView.getFloat64(o.DATA_BUFFER+u.SIZE,!0),mtime:new Date(this.dataView.getFloat64(o.DATA_BUFFER+u.MTIME,!0))}}async waitUntilReady(t){let e=Date.now();for(;;){let s=this.getRequest();if(s===S.REQUEST)return!0;if(s!==S.IDLE)return!1;let i=Date.now()-e;if(i>=t)return!1;let n=t-i,c=l.waitAsync(this.int32View,o.REQUEST/4,S.IDLE,n);if(c.async&&await c.value==="timed-out")return!1}}waitForResult(t){return l.wait(this.int32View,o.RESULT_STATE/4,r.NONE,t)}notifyRequest(){return l.notify(this.int32View,o.REQUEST/4)}notifyResult(){return l.notify(this.int32View,o.RESULT_STATE/4)}reset(){this.setOpCode(h.NOOP),this.setRequest(S.IDLE),this.setResultState(r.NONE),this.setPathLength(0),this.setDataLength(0),this.setResultLength(0),this.setErrorCode(a.NONE),this.setFlags(g.NONE),this.setMode(0)}};function U(d){return d!==void 0&&Object.hasOwn(O,d)?O[d]:a.IO_ERROR}var N=class{fs;cwd;commandName;secureFetch;maxOutputSize;exec;invokeTool;protocol;running=!1;output={stdout:"",stderr:"",exitCode:0};outputLimitExceeded=!1;startTime=0;timeoutMs=0;lastResult=null;constructor(t,e,s,i,n=void 0,c=0,E=void 0,p=void 0){this.fs=e,this.cwd=s,this.commandName=i,this.secureFetch=n,this.maxOutputSize=c,this.exec=E,this.invokeTool=p,this.protocol=new T(t)}remainingMs(){return Math.max(0,this.timeoutMs-(Date.now()-this.startTime))}raceDeadline(t){let e=this.remainingMs();if(e<=0)return this.running=!1,this.output.exitCode=124,this.output.stderr+=`
4
- ${this.commandName}: execution timeout exceeded
5
- `,Promise.reject(new Error("Operation timed out"));let s=t();return e===Number.POSITIVE_INFINITY?s:new Promise((i,n)=>{let c=A(()=>{this.running=!1,this.output.exitCode=124,this.output.stderr+=`
6
- ${this.commandName}: execution timeout exceeded
7
- `,n(new Error("Operation timed out"))},e);s.then(E=>{m(c),i(E)},E=>{m(c),n(E)})})}async run(t){for(this.running=!0,this.startTime=Date.now(),this.timeoutMs=t;this.running;){if(Date.now()-this.startTime>=t){this.output.stderr+=`
8
- ${this.commandName}: execution timeout exceeded
9
- `,this.output.exitCode=124;break}let s=this.remainingMs();if(!await this.protocol.waitUntilReady(s)){if(!this.running)break;this.output.stderr+=`
10
- ${this.commandName}: execution timeout exceeded
11
- `,this.output.exitCode=124;break}if(!this.running)break;this.protocol.setRequest(S.IDLE);let n=this.protocol.getOpCode();await this.handleOperation(n),this.protocol.notifyResult()}return this.output}stop(){this.running=!1,this.lastResult=null,this.protocol.setRequest(S.CANCELLED),this.protocol.notifyRequest()}async handleOperation(t){try{switch(t){case h.READ_FILE:await this.handleReadFile();break;case h.WRITE_FILE:await this.handleWriteFile();break;case h.STAT:await this.handleStat();break;case h.LSTAT:await this.handleLstat();break;case h.READDIR:await this.handleReaddir();break;case h.MKDIR:await this.handleMkdir();break;case h.READ_RESULT_RANGE:this.handleReadResultRange();break;case h.WRITE_FILE_RANGE:await this.handleWriteFileRange();break;case h.RM:await this.handleRm();break;case h.EXISTS:await this.handleExists();break;case h.APPEND_FILE:await this.handleAppendFile();break;case h.SYMLINK:await this.handleSymlink();break;case h.READLINK:await this.handleReadlink();break;case h.CHMOD:await this.handleChmod();break;case h.REALPATH:await this.handleRealpath();break;case h.RENAME:await this.handleRename();break;case h.COPY_FILE:await this.handleCopyFile();break;case h.WRITE_STDOUT:this.handleWriteStdout();break;case h.WRITE_STDERR:this.handleWriteStderr();break;case h.EXIT:this.handleExit();break;case h.HTTP_REQUEST:await this.handleHttpRequest();break;case h.EXEC_COMMAND:await this.handleExecCommand();break;case h.INVOKE_TOOL:await this.handleInvokeTool();break;default:this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultState(r.ERROR)}}catch(e){this.setErrorFromException(e)}}publishResult(t){let e=typeof t=="string"?new TextEncoder().encode(t):t;this.lastResult=e,this.protocol.setResultPrefix(e),this.protocol.setResultState(r.SUCCESS)}handleReadResultRange(){let t=this.protocol.getFlags(),e=this.protocol.getMode(),s=this.lastResult;if(!s||t>=s.length){this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString(`No retained result for range read (offset=${t}, length=${e}, retained=${s?.length??"none"})`),this.protocol.setResultState(r.ERROR);return}this.protocol.setResult(s.subarray(t,t+e)),this.protocol.setResultState(r.SUCCESS)}resolvePath(t){return this.fs.resolvePath(this.cwd,t)}async handleReadFile(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readFileBuffer(t);this.publishResult(e)}catch(e){this.setErrorFromException(e)}}async handleWriteFileRange(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getFlags(),s=this.protocol.getData();try{if(e===0)await this.fs.writeFile(t,s);else{let i=await this.fs.stat(t);if(i.size!==e)throw new _("EIO",`non-sequential range write to '${t}': offset ${e} != size ${i.size}`);await this.fs.appendFile(t,s)}this.protocol.setResultState(r.SUCCESS)}catch(i){this.setErrorFromException(i)}}async handleWriteFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getData();try{await this.fs.writeFile(t,e),this.protocol.setResultState(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleStat(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.stat(t);this.protocol.encodeStat(e),this.protocol.setResultState(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleLstat(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.lstat(t);this.protocol.encodeStat(e),this.protocol.setResultState(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleReaddir(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readdir(t);this.publishResult(JSON.stringify(e))}catch(e){this.setErrorFromException(e)}}async handleMkdir(){let t=this.resolvePath(this.protocol.getPath()),s=(this.protocol.getFlags()&g.MKDIR_RECURSIVE)!==0;try{await this.fs.mkdir(t,{recursive:s}),this.protocol.setResultState(r.SUCCESS)}catch(i){this.setErrorFromException(i)}}async handleRm(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getFlags(),s=(e&g.RECURSIVE)!==0,i=(e&g.FORCE)!==0;try{await this.fs.rm(t,{recursive:s,force:i}),this.protocol.setResultState(r.SUCCESS)}catch(n){this.setErrorFromException(n)}}async handleExists(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.exists(t);this.protocol.setResult(new Uint8Array([e?1:0])),this.protocol.setResultState(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleAppendFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getData();try{await this.fs.appendFile(t,e),this.protocol.setResultState(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleSymlink(){let t=this.protocol.getPath(),e=this.protocol.getDataAsString(),s=this.resolvePath(t);try{await this.fs.symlink(e,s),this.protocol.setResultState(r.SUCCESS)}catch(i){this.setErrorFromException(i)}}async handleReadlink(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readlink(t);this.protocol.setResultFromString(e),this.protocol.setResultState(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleChmod(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getMode();try{await this.fs.chmod(t,e),this.protocol.setResultState(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleRealpath(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.realpath(t);this.protocol.setResultFromString(e),this.protocol.setResultState(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleRename(){let t=this.resolvePath(this.protocol.getPath()),e=this.resolvePath(this.protocol.getDataAsString());try{await this.fs.mv(t,e),this.protocol.setResultState(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleCopyFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.resolvePath(this.protocol.getDataAsString());try{await this.fs.cp(t,e),this.protocol.setResultState(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}handleWriteStdout(){let t=this.protocol.getDataAsString();if(!this.tryAppendOutput("stdout",t)){this.outputLimitExceeded=!0,this.output.exitCode=1,this.appendOutputLimitError(),this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString("Output size limit exceeded"),this.protocol.setResultState(r.ERROR);return}this.protocol.setResultState(r.SUCCESS)}handleWriteStderr(){let t=this.protocol.getDataAsString();if(!this.tryAppendOutput("stderr",t)){this.outputLimitExceeded=!0,this.output.exitCode=1,this.appendOutputLimitError(),this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString("Output size limit exceeded"),this.protocol.setResultState(r.ERROR);return}this.protocol.setResultState(r.SUCCESS)}handleExit(){let t=this.protocol.getFlags();this.outputLimitExceeded?this.output.exitCode===0&&(this.output.exitCode=1):this.output.exitCode=t,this.protocol.setResultState(r.SUCCESS),this.running=!1}tryAppendOutput(t,e){return this.outputLimitExceeded?!1:this.maxOutputSize<=0?(t==="stdout"?this.output.stdout+=e:this.output.stderr+=e,!0):this.output.stdout.length+this.output.stderr.length+e.length>this.maxOutputSize?!1:(t==="stdout"?this.output.stdout+=e:this.output.stderr+=e,!0)}appendOutputLimitError(){if(this.maxOutputSize<=0)return;let t=`${this.commandName}: total output size exceeded (>${this.maxOutputSize} bytes), increase executionLimits.maxOutputSize
12
- `,e=t.length>this.maxOutputSize?t.slice(0,this.maxOutputSize):t;if(this.output.stderr.includes("total output size exceeded"))return;let i=this.output.stdout.length+this.output.stderr.length+e.length-this.maxOutputSize;if(i>0)if(this.output.stdout.length>=i)this.output.stdout=this.output.stdout.slice(0,this.output.stdout.length-i);else{let n=i-this.output.stdout.length;this.output.stdout="",n>=this.output.stderr.length?this.output.stderr="":this.output.stderr=this.output.stderr.slice(0,this.output.stderr.length-n)}this.output.stderr+=e}async handleHttpRequest(){let t=this.secureFetch;if(!t){this.protocol.setErrorCode(a.NETWORK_NOT_CONFIGURED),this.protocol.setResultFromString("Network access not configured. Enable network in Bash options."),this.protocol.setResultState(r.ERROR);return}let e=this.protocol.getPath(),s=this.protocol.getDataAsString();try{let i=s?JSON.parse(s):{},n=this.remainingMs(),c=await this.raceDeadline(()=>t(e,{method:i.method,headers:i.headers,body:i.body,timeoutMs:n})),E=JSON.stringify({status:c.status,statusText:c.statusText,headers:c.headers,bodyBase64:L(c.body,"base64"),url:c.url});this.publishResult(E)}catch(i){let n=F(i instanceof Error?i.message:String(i));this.protocol.setErrorCode(a.NETWORK_ERROR),this.protocol.setResultFromString(n),this.protocol.setResultState(r.ERROR)}}async handleExecCommand(){let t=this.exec;if(!t){this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString("Command execution not available in this context."),this.protocol.setResultState(r.ERROR);return}let e=this.protocol.getPath(),s=this.protocol.getDataAsString(),i=new AbortController;try{let n={cwd:this.cwd,signal:i.signal};if(s){let p=JSON.parse(s);p.stdin&&(n.stdin=p.stdin),p.args&&Array.isArray(p.args)&&(n.args=p.args.map(x=>String(x)),e=C([e]))}let c=await this.raceDeadline(()=>t(e,n)),E=JSON.stringify({stdout:c.stdout,stderr:c.stderr,exitCode:c.exitCode});this.publishResult(E)}catch(n){i.abort();let c=n instanceof Error?n.message:String(n);this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString(c),this.protocol.setResultState(r.ERROR)}}async handleInvokeTool(){let t=this.invokeTool;if(!t){this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString("Tool invocation not available in this context."),this.protocol.setResultState(r.ERROR);return}let e=this.protocol.getPath(),s=this.protocol.getDataAsString();try{let i=await this.raceDeadline(()=>w.runTrustedAsync(()=>t(e,s)));this.publishResult(i)}catch(i){let n=D(i instanceof Error?i.message:String(i));this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString(n),this.protocol.setResultState(r.ERROR)}}setErrorFromException(t){let e=t instanceof Error?t.message:String(t),s=F(e);this.protocol.setErrorCode(U(f(t))),this.protocol.setResultFromString(s),this.protocol.setResultState(r.ERROR)}};export{M as a,N as b};
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{b as a}from"./chunk-HWI42GQO.js";var r=globalThis.setTimeout.bind(globalThis),l=globalThis.clearTimeout.bind(globalThis),T=globalThis.setInterval.bind(globalThis),f=globalThis.clearInterval.bind(globalThis);function u(e){return typeof e!="function"?e:a.bindCurrentContext(e)}var b=((e,n,...i)=>r(u(e),n,...i)),d=l,I=((e,n,...i)=>r(e,n,...i)),c=2147483647;function _(e,n){if(n===Number.POSITIVE_INFINITY)return;let i=u(e),t={cleared:!1,remainingMs:Math.max(0,n),timer:void 0},o=()=>{if(t.cleared)return;let s=Math.min(t.remainingMs,c);t.timer=r(()=>{t.cleared||(t.remainingMs-=s,t.remainingMs>0?o():i())},s)};return o(),t}function g(e){e&&(e.cleared=!0,e.timer!==void 0&&l(e.timer))}export{b as a,d as b,I as c,_ as d,g as e};
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env node
2
- import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{d as V}from"./chunk-I57EACSL.js";import{d as B}from"./chunk-NBTZL3VS.js";import{l as _,m as Y}from"./chunk-FUT3X2GJ.js";import{a as J}from"./chunk-CPKBPQ2C.js";import{a as Q}from"./chunk-NE4R2FVV.js";import{a as Z,b as q}from"./chunk-MUFNRCMY.js";function h(s,t,e){if(J(e)>s.limits.maxOutputSize-J(t))throw new _(`ls: output size limit exceeded (${s.limits.maxOutputSize} bytes)`,"output_size");return t+e}function X(s,t){let e=new V(s.limits.maxOutputSize,"ls");for(let l=0;l<t.length;l++)l>0&&e.append(`
4
- `),e.append(t[l]);return t.length>0&&e.append(`
5
- `),e.build()}function I(s){if(s<1024)return String(s);if(s<1024*1024){let e=s/1024;return e<10?`${e.toFixed(1)}K`:`${Math.round(e)}K`}if(s<1024*1024*1024){let e=s/1048576;return e<10?`${e.toFixed(1)}M`:`${Math.round(e)}M`}let t=s/(1024*1024*1024);return t<10?`${t.toFixed(1)}G`:`${Math.round(t)}G`}function K(s){let e=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][s.getMonth()],l=String(s.getDate()).padStart(2," "),p=new Date,g=new Date(p.getTime()-4320*60*60*1e3);if(s>g){let z=String(s.getHours()).padStart(2,"0"),d=String(s.getMinutes()).padStart(2,"0");return`${e} ${l} ${z}:${d}`}let b=s.getFullYear();return`${e} ${l} ${b}`}function W(s){return s.isDirectory?"/":s.isSymbolicLink?"@":(s.mode&73)!==0?"*":""}var nt={name:"ls",summary:"list directory contents",usage:"ls [OPTION]... [FILE]...",options:["-a, --all do not ignore entries starting with .","-A, --almost-all do not list . and ..","-d, --directory list directories themselves, not their contents","-F, --classify append indicator (one of */=>@) to entries","-h, --human-readable with -l, print sizes like 1K 234M 2G etc.","-l use a long listing format","-r, --reverse reverse order while sorting","-R, --recursive list subdirectories recursively","-S sort by file size, largest first","-t sort by time, newest first","-1 list one file per line"," --help display this help and exit"]},ot={showAll:{short:"a",long:"all",type:"boolean"},showAlmostAll:{short:"A",long:"almost-all",type:"boolean"},longFormat:{short:"l",type:"boolean"},humanReadable:{short:"h",long:"human-readable",type:"boolean"},recursive:{short:"R",long:"recursive",type:"boolean"},reverse:{short:"r",long:"reverse",type:"boolean"},sortBySize:{short:"S",type:"boolean"},classifyFiles:{short:"F",long:"classify",type:"boolean"},directoryOnly:{short:"d",long:"directory",type:"boolean"},sortByTime:{short:"t",type:"boolean"},onePerLine:{short:"1",type:"boolean"}},pt={name:"ls",async execute(s,t){if(q(s))return Z(nt);let e=Q("ls",s,ot);if(!e.ok)return e.error;let l=e.result.flags.showAll,p=e.result.flags.showAlmostAll,g=e.result.flags.longFormat,b=e.result.flags.humanReadable,z=e.result.flags.recursive,d=e.result.flags.reverse,$=e.result.flags.classifyFiles,O=e.result.flags.directoryOnly,R=it(s,e.result.flags.sortBySize,e.result.flags.sortByTime);e.result.flags.onePerLine;let F=e.result.positional;F.length===0&&F.push(".");let S="",P="",C=0,M=new B({limits:t.limits,signal:t.signal,executionScope:t.executionScope,site:"ls"});if(O){for(let n of await G(F,t,R,d,M)){M.visit(0);let i=t.fs.resolvePath(t.cwd,n);try{let D=await t.fs.stat(i);if(g){let L=D.isDirectory?"drwxr-xr-x":"-rw-r--r--",c=$?W(await t.fs.lstat(i)):"",u=D.size??0,A=b?I(u).padStart(5):String(u).padStart(5),a=D.mtime??new Date(0),o=K(a);S=h(t,S,`${L} 1 user user ${A} ${o} ${n}${c}
6
- `)}else{let L=$?W(await t.fs.lstat(i)):"";S=h(t,S,`${n}${L}
7
- `)}}catch{P=h(t,P,`ls: cannot access '${n}': No such file or directory
8
- `),C=2}}return{stdout:S,stderr:P,exitCode:C}}let m=[],y=[];for(let n of F){M.visit(0);try{((await t.fs.stat(t.fs.resolvePath(t.cwd,n))).isDirectory?y:m).push(n)}catch{P=h(t,P,`ls: ${n}: No such file or directory
9
- `),C=2}}let T=async(n,i)=>{let D=await x(n,t,l,p,g,z,i,d,b,R,$,!1,M,0,new Set,!0);S=h(t,S,D.stdout),P=h(t,P,D.stderr),D.exitCode!==0&&(C=D.exitCode)};for(let n of await G(m,t,R,d,M))await T(n,!1);let N=F.length>1;for(let n of await G(y,t,R,d,M))S&&(S=h(t,S,`
10
- `)),await T(n,N);return{stdout:S,stderr:P,exitCode:C}}};function it(s,t,e){if(!t&&!e)return"name";if(t!==e)return t?"size":"time";let l="name";for(let p of s){if(p==="--")break;if(!(!p.startsWith("-")||p.startsWith("--")))for(let g of p.slice(1))g==="S"?l="size":g==="t"&&(l="time")}return l}async function G(s,t,e,l,p){return await j(s,g=>t.fs.resolvePath(t.cwd,g),t,e,l,p)}async function j(s,t,e,l,p,g){let b=[...s];if(l==="name")b.sort();else{g?.checkpoint(b.length);let z=new Map;for(let d of b)try{let $=await e.fs.lstat(t(d));z.set(d,l==="size"?$.size??0:($.mtime??new Date(0)).getTime())}catch{z.set(d,0)}b.sort((d,$)=>{let O=(z.get($)??0)-(z.get(d)??0);return O!==0?O:d<$?-1:d>$?1:0})}return p&&b.reverse(),b}async function x(s,t,e,l,p,g,b,z=!1,d=!1,$="name",O=!1,R=!1,F=new B({limits:t.limits,signal:t.signal,executionScope:t.executionScope,site:"ls"}),S=0,P=new Set,C=!1){let M=e||l,m=t.fs.resolvePath(t.cwd,s);try{C||F.visit(S);let y=await t.fs.stat(m);if(!y.isDirectory){let c=O?W(await t.fs.lstat(m)):"";if(p){let u=y.size??0,A=d?I(u).padStart(5):String(u).padStart(5),a=y.mtime??new Date(0),o=K(a);return{stdout:`-rw-r--r-- 1 user user ${A} ${o} ${s}${c}
11
- `,stderr:"",exitCode:0}}return{stdout:`${s}${c}
12
- `,stderr:"",exitCode:0}}let T=y.identity??(y.dev!==void 0&&y.ino!==void 0?`${String(y.dev)}:${String(y.ino)}`:await t.fs.realpath(m).catch(()=>{}));if(T!==void 0&&P.has(T))return{stdout:"",stderr:`ls: ${s}: symbolic link cycle detected
13
- `,exitCode:2};let N=new Set(P);T!==void 0&&N.add(T);let n=await t.fs.readdir(m);F.checkpoint(),M||(n=n.filter(c=>!c.startsWith("."))),n=await j(n,c=>m==="/"?`/${c}`:`${m}/${c}`,t,$,!1,F),e&&(n=[".","..",...n]),z&&n.reverse();let i="",D="",L=0;if((g||b)&&(i=h(t,i,`${s}:
14
- `)),p){i=h(t,i,`total ${n.length}
15
- `);let c=n.filter(o=>o==="."||o===".."),u=n.filter(o=>o!=="."&&o!=="..");for(let o of c)i=h(t,i,`drwxr-xr-x 1 user user 0 Jan 1 00:00 ${o}
16
- `);let A=[];for(let o=0;o<u.length;o+=100){let r=u.slice(o,o+100),f=await Promise.all(r.map(async v=>{let w=m==="/"?`/${v}`:`${m}/${v}`;try{let k=await t.fs.stat(w),H=k.isDirectory?"drwxr-xr-x":"-rw-r--r--",tt=O?W(await t.fs.lstat(w)):"",U=k.size??0,et=d?I(U).padStart(5):String(U).padStart(5),st=k.mtime??new Date(0),rt=K(st);return{name:v,line:`${H} 1 user user ${et} ${rt} ${v}${tt}
17
- `}}catch{return{name:v,line:`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${v}
18
- `}}}));A.push(...f)}let a=new Map(u.map((o,r)=>[o,r]));A.sort((o,r)=>(a.get(o.name)??0)-(a.get(r.name)??0));for(let{line:o}of A)i=h(t,i,o)}else if(O){let c=[],u=n.filter(a=>a!=="."&&a!==".."),A=n.filter(a=>a==="."||a==="..");for(let a of A)c.push(`${a}/`);for(let a=0;a<u.length;a+=100){let o=u.slice(a,a+100),r=await Promise.all(o.map(async f=>{let v=m==="/"?`/${f}`:`${m}/${f}`;try{let w=await t.fs.lstat(v);return`${f}${W(w)}`}catch{return f}}));c.push(...r)}i=h(t,i,X(t,c))}else i=h(t,i,X(t,n));if(g){let c=n.filter(r=>r!=="."&&r!==".."),u=[];if(t.fs.readdirWithFileTypes)u=(await t.fs.readdirWithFileTypes(m)).filter(f=>f.isDirectory&&c.includes(f.name)).map(f=>({name:f.name,isDirectory:!0}));else for(let r=0;r<c.length;r+=100){let f=c.slice(r,r+100),v=await Promise.all(f.map(async w=>{let k=m==="/"?`/${w}`:`${m}/${w}`;try{let H=await t.fs.stat(k);return{name:w,isDirectory:H.isDirectory}}catch{return{name:w,isDirectory:!1}}}));u.push(...v.filter(w=>w.isDirectory))}let A=await j(u.map(r=>r.name),r=>m==="/"?`/${r}`:`${m}/${r}`,t,$,z,F),a=new Map(A.map((r,f)=>[r,f]));u.sort((r,f)=>(a.get(r.name)??0)-(a.get(f.name)??0));let o=[];for(let r=0;r<u.length;r+=100){let f=u.slice(r,r+100),v=await Promise.all(f.map(async w=>{let k=s==="."?`./${w.name}`:`${s}/${w.name}`,H=await x(k,t,e,l,p,g,!1,z,d,$,O,!0,F,S+1,N);return{name:w.name,result:H}}));o.push(...v)}o.sort((r,f)=>(a.get(r.name)??0)-(a.get(f.name)??0));for(let{result:r}of o)i=h(t,i,`
19
- `),i=h(t,i,r.stdout),D=h(t,D,r.stderr),r.exitCode!==0&&(L=r.exitCode)}return{stdout:i,stderr:D,exitCode:L}}catch(y){if(y instanceof _||y instanceof Y)throw y;return{stdout:"",stderr:`ls: ${s}: No such file or directory
20
- `,exitCode:2}}}var ht={name:"ls",flags:[{flag:"-a",type:"boolean"},{flag:"-A",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-h",type:"boolean"},{flag:"-R",type:"boolean"},{flag:"-r",type:"boolean"},{flag:"-S",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-d",type:"boolean"},{flag:"-t",type:"boolean"},{flag:"-1",type:"boolean"}],needsFiles:!0};export{pt as a,ht as b};
@@ -1,99 +0,0 @@
1
- #!/usr/bin/env node
2
- import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{a as A,b as B}from"./chunk-E54Z6VIE.js";import{a as q}from"./chunk-3DWQCLNP.js";import"./chunk-3MRB66F4.js";import"./chunk-O2BCKSMK.js";import"./chunk-TW2IJRUF.js";import{b as v,c as j}from"./chunk-QKJAAJ7J.js";import{a as F}from"./chunk-MROECM42.js";import{b as C}from"./chunk-HWI42GQO.js";import{b as E}from"./chunk-CPKBPQ2C.js";import"./chunk-OHFB3M3X.js";import{a as W,b as h}from"./chunk-PBOVSFTJ.js";import{a as S}from"./chunk-I4IRHQDW.js";import{b as M}from"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";import{AsyncLocalStorage as H}from"node:async_hooks";import{fileURLToPath as J}from"node:url";import{Worker as L}from"node:worker_threads";var O=new H,P=`js-exec - Sandboxed JavaScript/TypeScript runtime with Node.js-compatible APIs
4
-
5
- Usage: js-exec [OPTIONS] [-c CODE | FILE] [ARGS...]
6
-
7
- Options:
8
- -c CODE Execute inline code
9
- -m, --module Enable ES module mode (import/export)
10
- --strip-types Strip TypeScript type annotations
11
- --version, -V Show version
12
- --help Show this help
13
-
14
- Examples:
15
- js-exec -c "console.log(1 + 2)"
16
- js-exec script.js
17
- js-exec app.ts
18
- echo 'console.log("hello")' | js-exec
19
-
20
- File Extension Auto-Detection:
21
- .js script mode (module mode if top-level await detected)
22
- .mjs ES module mode
23
- .ts, .mts ES module mode + TypeScript stripping
24
-
25
- Node.js Compatibility:
26
- Code written for Node.js largely works here. Both require and import
27
- are supported, the node: prefix works, and standard globals like process,
28
- console, and fetch are available. All I/O is synchronous.
29
-
30
- Available modules:
31
- fs, path, child_process, process, console,
32
- os, url, assert, util, events, buffer, stream,
33
- string_decoder, querystring
34
-
35
- fs (global, require('fs'), or import from 'node:fs'):
36
- readFileSync, writeFileSync, appendFileSync, copyFileSync, renameSync
37
- readdirSync, mkdirSync, rmSync, unlinkSync, rmdirSync
38
- statSync, lstatSync, existsSync, realpathSync, chmodSync
39
- symlinkSync, readlinkSync, readFileBuffer
40
- fs.promises.readFile, fs.promises.writeFile, fs.promises.access, ...
41
-
42
- path: join, resolve, dirname, basename, extname, normalize,
43
- relative, isAbsolute, parse, format, sep, delimiter
44
-
45
- child_process:
46
- execSync(cmd) throws on non-zero exit, returns stdout
47
- spawnSync(cmd, args) returns { stdout, stderr, status }
48
-
49
- process (also global): argv, cwd(), exit(), env, platform, arch,
50
- version, versions
51
-
52
- os: platform(), arch(), homedir(), tmpdir(), type(), hostname(),
53
- EOL, cpus(), endianness()
54
-
55
- url: URL, URLSearchParams, parse(), format()
56
-
57
- assert: ok(), equal(), strictEqual(), deepEqual(), throws(),
58
- doesNotThrow(), fail()
59
-
60
- util: format(), inspect(), promisify(), types, inherits()
61
-
62
- events: EventEmitter (on, once, emit, off, removeListener, ...)
63
-
64
- buffer: Buffer.from(), Buffer.alloc(), Buffer.concat(),
65
- Buffer.isBuffer(), toString(), slice(), equals()
66
-
67
- stream: Readable, Writable, Duplex, Transform, PassThrough, pipeline
68
-
69
- string_decoder: StringDecoder (write, end)
70
-
71
- querystring: parse(), stringify(), escape(), unescape()
72
-
73
- Other Globals:
74
- console log (stdout), error/warn (stderr)
75
- fetch(url, opts) HTTP; returns Promise<Response> (Web Fetch API)
76
- URL, URLSearchParams, Headers, Request, Response
77
- Buffer Buffer.from(), Buffer.alloc(), etc.
78
-
79
- Not Available:
80
- http, https, net, tls, crypto, zlib, dns, cluster, worker_threads,
81
- vm, v8, readline, and other Node.js built-in modules that require
82
- native bindings. Use fetch() for HTTP requests.
83
-
84
- Limits:
85
- Memory: 64 MB per execution
86
- Timeout: 10 s by default; configurable via maxJsTimeoutMs
87
- Engine: QuickJS (compiled to WebAssembly)
88
- `;function N(r){let e={code:null,scriptFile:null,showVersion:!1,scriptArgs:[],isModule:!1,stripTypes:!1};if(r.length===0)return e;for(let t=0;t<r.length;t++){let s=r[t];if(s==="-m"||s==="--module"){e.isModule=!0;continue}if(s==="--strip-types"){e.stripTypes=!0;continue}if(s==="-c")return t+1>=r.length?{stdout:"",stderr:`js-exec: option requires an argument -- 'c'
89
- `,exitCode:2}:(e.code=r[t+1],e.scriptArgs=r.slice(t+2),e);if(s==="--version"||s==="-V")return e.showVersion=!0,e;if(s.startsWith("-")&&s!=="-"&&s!=="--")return{stdout:"",stderr:`js-exec: unrecognized option '${s}'
90
- `,exitCode:2};if(s==="--")return t+1<r.length&&(e.scriptFile=r[t+1],e.scriptArgs=r.slice(t+2)),e;if(!s.startsWith("-"))return e.scriptFile=s,e.scriptArgs=r.slice(t+1),e}return e}var l=null,y=null,c=[],n=null,x=null,U=1e3,R=5e3;function fe(r){R=r}function pe(){return l!==null}function _(r,e,t){r.controller.close();let s=!1,o=()=>{if(!s&&(s=!0,v(i),n===r)){x="worker termination was not acknowledged";for(let a of c)a.bridgeHandler.stop(),a.resolve({success:!1,error:x});c.length=0,r.resolve(t)}},u=()=>{s||(s=!0,v(i),n===r&&(r.resolve(t),n=null,g()))},i=j(()=>{o()},U);r.controller.terminate(e).then(a=>a?u():o(),o)}function me(){y&&(v(y),y=null),n?.bridgeHandler.stop(),n=null;for(let e of c)e.bridgeHandler.stop();c.length=0;let r=l;l=null,r&&r.terminate(),x=null}var D=J(new URL("./js-exec-worker.js",import.meta.url));function g(){if(n||c.length===0)return;let r=c.shift();if(!r)return;n=r;let e=null;try{e=V(),e.postMessage(r.input)}catch(t){r.bridgeHandler.stop();let s={success:!1,error:h(S(t))},o=e??l;l===o&&(l=null),o?_(r,o,s):(r.resolve(s),n===r&&(n=null),g())}}function $(r,e){if(!r||typeof r!="object")return{success:!1,error:"Malformed worker response"};let t=r;return typeof t.protocolToken!="string"||t.protocolToken!==e?{success:!1,error:"Malformed worker response: invalid protocol token"}:typeof t.success!="boolean"?{success:!1,error:"Malformed worker response: missing success flag"}:t.success?{success:!0}:{success:!1,type:t.type==="initialization-failure"?"initialization-failure":void 0,error:typeof t.error=="string"&&t.error.length>0?t.error:"Worker execution failed"}}function V(){if(y&&(v(y),y=null),l)return l;let r=C.runTrusted(()=>new L(D));return l=r,r.on("message",e=>{if(l===r){if(n){let t;try{n.controller.assertMessageSize(e,"response"),t=$(e,n.input.protocolToken)}catch(s){t={success:!1,error:h(S(s))}}if(t.type==="initialization-failure"){x=t.error??"Worker initialization failed",n.bridgeHandler.stop(),n.resolve(t),n=null;for(let s of c)s.bridgeHandler.stop(),s.resolve({success:!1,type:"initialization-failure",error:x});c.length=0,l=null,r.terminate();return}n.resolve(t),n=null}c.length>0?g():Q()}}),r.on("error",e=>{if(l===r){if(n){let t=h(S(e));n.resolve({success:!1,error:t}),n=null}for(let t of c)t.resolve({success:!1,error:"Worker crashed"});c.length=0,l=null}}),r.on("exit",()=>{l===r&&(l=null,n&&(n.resolve({success:!1,error:"Worker exited unexpectedly"}),n=null),c.length>0&&g())}),r}function Q(){y=j(()=>{l&&!n&&c.length===0&&(l.terminate(),l=null)},R)}async function G(r,e,t,s=[],o,u,i){return O.getStore()?{stdout:"",stderr:`js-exec: recursive invocation is not supported
91
- `,exitCode:1}:Y(r,e,t,s,o,u,i)}async function K(r,e,t,s){let o,u=new Promise(d=>{o=d}),i={input:r,bridgeHandler:e,resolve:()=>{},controller:s};s.assertMessageSize({...r,sharedBuffer:void 0},"request");let a=d=>{e.stop();let f={success:!1,error:d==="abort"?i.controller.abortMessage():i.controller.timeoutMessage()};if(n===i){let p=l;l=null,p?_(i,p,f):(i.resolve(f),n=null,g())}else{let p=c.indexOf(i);p!==-1&&c.splice(p,1),i.resolve(f),n||g()}};if(i.resolve=d=>{i.controller.close(),o(d)},i.controller.arm(a),!i.controller.isCanceled){c.push(i);try{g()}catch(d){let f=c.indexOf(i);throw f!==-1&&c.splice(f,1),i.controller.close(),d}}let[m,k]=await Promise.all([e.run(t),u.catch(d=>({success:!1,error:h(S(d))}))]);return{bridgeOutput:m,workerResult:k}}function X(r){return r.limits.maxJsTimeoutMs}async function Y(r,e,t,s=[],o,u,i){if(x!==null)return{stdout:"",stderr:`js-exec: ${h(x)}
92
- `,exitCode:1};let a=A(),m=e.exec,k=m?(b,I)=>O.run(!0,()=>m(b,I)):void 0,d=new B(a,e.fs,e.cwd,"js-exec",e.fetch,e.limits.maxOutputSize,k,e.invokeTool),f=X(e),p=new q({commandName:"js-exec",timeoutMs:f,signal:e.signal,maxMessageBytes:e.limits.maxWorkerMessageBytes}),z={protocolToken:p.protocolToken,sharedBuffer:a,jsCode:r,cwd:e.cwd,env:F(e.env),args:s,scriptPath:t,bootstrapCode:o,isModule:u,stripTypes:i,timeoutMs:f,hasInvokeTool:e.invokeTool!==void 0},{bridgeOutput:T,workerResult:w}=await K(z,d,f,p);if(!w.success&&w.error){let b=w.error===p.timeoutMessage()||w.error===p.abortMessage();return{stdout:T.stdout,stderr:`${T.stderr}js-exec: ${h(w.error)}
93
- `,exitCode:T.exitCode||(b?124:1)}}return{...T}}var he={name:"js-exec",async execute(r,e){if(M(r))return{stdout:P,stderr:"",exitCode:0};let t=N(r);if("exitCode"in t)return t;if(t.showVersion)return{stdout:`QuickJS (quickjs-emscripten)
94
- `,stderr:"",exitCode:0};let s,o;if(t.code!==null)s=t.code,o="-c";else if(t.scriptFile!==null){let m=e.fs.resolvePath(e.cwd,t.scriptFile);if(!await e.fs.exists(m))return{stdout:"",stderr:`js-exec: can't open file '${t.scriptFile}': No such file or directory
95
- `,exitCode:2};try{s=await e.fs.readFile(m),o=m}catch(k){return{stdout:"",stderr:`js-exec: can't open file '${t.scriptFile}': ${W(k.message)}
96
- `,exitCode:2}}}else if(E(e.stdin).trim())s=E(e.stdin),o="<stdin>";else return{stdout:"",stderr:`js-exec: no input provided (use -c CODE or provide a script file)
97
- `,exitCode:2};let u=t.isModule,i=t.stripTypes;o&&o!=="-c"&&o!=="<stdin>"&&((o.endsWith(".mjs")||o.endsWith(".mts")||o.endsWith(".ts"))&&(u=!0),(o.endsWith(".ts")||o.endsWith(".mts"))&&(i=!0)),!u&&/\bawait\s+[\w([`]/.test(s)&&(u=!0);let a=e.jsBootstrapCode;return G(s,e,o,t.scriptArgs,a,u,i)}},ye={name:"node",async execute(){return{stdout:"",stderr:`node: this sandbox uses js-exec instead of node
98
-
99
- ${P}`,exitCode:1}}};export{pe as _hasSharedJsExecWorkerForTests,me as _resetJsExecWorkerForTests,fe as _setJsExecWorkerIdleTimeoutMsForTests,he as jsExecCommand,ye as nodeStubCommand};
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env node
2
- import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{a as Q,b as W}from"./chunk-E54Z6VIE.js";import{a as I}from"./chunk-3DWQCLNP.js";import"./chunk-3MRB66F4.js";import"./chunk-O2BCKSMK.js";import"./chunk-TW2IJRUF.js";import"./chunk-QKJAAJ7J.js";import{a as F}from"./chunk-MROECM42.js";import{c as w}from"./chunk-42AMF6EE.js";import{b as M}from"./chunk-HWI42GQO.js";import{b as C}from"./chunk-CPKBPQ2C.js";import"./chunk-OHFB3M3X.js";import{a as A,b as d}from"./chunk-PBOVSFTJ.js";import{a as E}from"./chunk-I4IRHQDW.js";import{a as P,b as D}from"./chunk-MUFNRCMY.js";import"./chunk-DN2YCFOR.js";import{fileURLToPath as B}from"node:url";import{Worker as L}from"node:worker_threads";var z={name:"python3",summary:"Execute Python code via CPython Emscripten",usage:"python3 [OPTIONS] [-c CODE | -m MODULE | FILE] [ARGS...]",description:["Execute Python code using CPython compiled to WebAssembly via Emscripten.","","This command runs Python in an isolated environment with access to","the virtual filesystem. Standard library modules are available."],options:["-c CODE Execute CODE as Python script","-m MODULE Run library module as a script","--version Show Python version","--help Show this help"],examples:['python3 -c "print(1 + 2)"','python3 -c "import sys; print(sys.version)"',"python3 script.py","python3 script.py arg1 arg2",`echo 'print("hello")' | python3`],notes:["CPython runs in WebAssembly, so execution may be slower than native Python.","Standard library modules are available (no pip install).","Maximum execution time is 30 seconds by default."]};function _(t){let e={code:null,module:null,scriptFile:null,showVersion:!1,scriptArgs:[]};if(t.length===0)return e;let r=t.findIndex(n=>!n.startsWith("-")||n==="-"||n==="--");for(let n=0;n<(r===-1?t.length:r);n++){let i=t[n];if(i==="-c")return n+1>=t.length?{stdout:"",stderr:`python3: option requires an argument -- 'c'
4
- `,exitCode:2}:(e.code=t[n+1],e.scriptArgs=t.slice(n+2),e);if(i==="-m")return n+1>=t.length?{stdout:"",stderr:`python3: option requires an argument -- 'm'
5
- `,exitCode:2}:(e.module=t[n+1],e.scriptArgs=t.slice(n+2),e);if(i==="--version"||i==="-V")return e.showVersion=!0,e;if(i.startsWith("-")&&i!=="-")return{stdout:"",stderr:`python3: unrecognized option '${i}'
6
- `,exitCode:2}}if(r!==-1){let n=t[r];n==="--"?r+1<t.length&&(e.scriptFile=t[r+1],e.scriptArgs=t.slice(r+2)):(e.scriptFile=n,e.scriptArgs=t.slice(r+1))}return e}var b=new WeakMap;function R(t){let e=b.get(t);return e||(e={executionQueue:[],activeExecution:null,poisonedError:null},b.set(t,e)),e}function ne(){b=new WeakMap}var H=B(new URL("./worker.js",import.meta.url));function U(t,e){if(!t||typeof t!="object")return{success:!1,error:"Malformed worker response"};let r=t;return typeof r.protocolToken!="string"||r.protocolToken!==e?{success:!1,error:"Malformed worker response: invalid protocol token"}:r.type==="security-violation"?{success:!1,error:`Security violation: ${typeof r.violation?.type=="string"?r.violation.type:"unknown"}`}:typeof r.success!="boolean"?{success:!1,error:"Malformed worker response: missing success flag"}:r.success?{success:!0}:{success:!1,error:typeof r.error=="string"&&r.error.length>0?r.error:"Worker execution failed"}}function k(t){if(t.poisonedError!==null){for(let o of t.executionQueue.splice(0))o.state==="queued"&&(o.state="settled",o.stopBridge(),o.settle({success:!1,error:t.poisonedError}));return}if(t.activeExecution!==null||t.executionQueue.length===0)return;for(;t.executionQueue.length>0&&t.executionQueue[0]?.state!=="queued";)t.executionQueue.shift();if(t.executionQueue.length===0)return;let e=t.executionQueue.shift();if(!e)return;e.state="running",t.activeExecution=e;let r;try{r=M.runTrusted(()=>new L(H,{workerData:e.input}))}catch(o){let s=o instanceof Error?o.message:String(o);e.state="settled",e.settle({success:!1,error:d(s)}),t.activeExecution===e&&(t.activeExecution=null,k(t));return}e.worker=r;let n=!0,i=()=>{n&&(n=!1,r.removeListener("message",u),r.removeListener("error",g),r.removeListener("exit",v))},c=async(o,s)=>{if(!(t.activeExecution?.executionId!==e.executionId||e.state!=="running")){if(e.state="terminating",i(),e.settle(o),s&&!await e.controller.terminate(r)){let f="Worker termination was not acknowledged";e.worker=null,e.state="settled",t.poisonedError=f,t.activeExecution?.executionId===e.executionId&&(t.activeExecution=null),k(t);return}e.worker=null,e.state="settled",t.activeExecution?.executionId===e.executionId&&(t.activeExecution=null,k(t))}};e.cancel=o=>{c(o,!0)};let p=w(e.requireDefenseContext,"python3","worker message callback",o=>{try{e.controller.assertMessageSize(o,"response")}catch(s){c({success:!1,error:d(E(s))},!0);return}c(U(o,e.input.protocolToken),!0)}),h=w(e.requireDefenseContext,"python3","worker error callback",o=>{let s=d(E(o));c({success:!1,error:s},!0)}),a=w(e.requireDefenseContext,"python3","worker exit callback",()=>{c({success:!1,error:"Worker exited unexpectedly"},!1)}),u=o=>{try{p(o)}catch(s){let l=s instanceof Error?s.message:String(s);c({success:!1,error:d(l)},!0)}},g=o=>{try{h(o)}catch(s){let l=s instanceof Error?s.message:String(s);c({success:!1,error:d(l)},!0)}},v=()=>{try{a()}catch(o){let s=o instanceof Error?o.message:String(o);c({success:!1,error:d(s)},!0)}};r.on("message",u),r.on("error",g),r.on("exit",v)}async function N(t,e,r,n,i=[]){let c=Q(),p=new W(c,r.fs,r.cwd,"python3",r.fetch,r.limits.maxOutputSize),h=r.limits.maxPythonTimeoutMs,a=R(r.fs);if(a.poisonedError!==null)return{stdout:"",stderr:`python3: ${a.poisonedError}
7
- `,exitCode:1};let u=new I({commandName:"python3",timeoutMs:h,signal:r.signal,maxMessageBytes:r.limits.maxWorkerMessageBytes}),g={protocolToken:u.protocolToken,sharedBuffer:c,pythonCode:t,stdin:e,cwd:r.cwd,env:F(r.env),args:i,scriptPath:n,timeoutMs:h,maxFileSize:r.limits.maxStringLength};u.assertMessageSize({...g,sharedBuffer:void 0},"request");let v=new Promise(l=>{let f=!1,m={executionId:Symbol("python3 execution"),input:g,settle:y=>{f||(f=!0,u.close(),l(y))},requireDefenseContext:r.requireDefenseContext,state:"queued",worker:null,controller:u,stopBridge:()=>p.stop?.(),cancel:()=>{}};m.cancel=y=>{if(m.state!=="queued")return;m.state="settled";let x=a.executionQueue.indexOf(m);x!==-1&&a.executionQueue.splice(x,1),m.settle(y),k(a)};let O=w(r.requireDefenseContext,"python3","worker cancellation callback",y=>{p.stop?.(),m.cancel({success:!1,error:y==="abort"?u.abortMessage():u.timeoutMessage()})}),T=y=>{try{O(y)}catch(x){let $=x instanceof Error?x.message:String(x);m.cancel({success:!1,error:d($)})}};u.arm(T),u.isCanceled||(a.executionQueue.push(m),k(a))}),[o,s]=await Promise.all([p.run(h).catch(l=>({stdout:"",stderr:`python3: bridge error: ${d(E(l))}
8
- `,exitCode:1})),v.catch(l=>({success:!1,error:d(E(l))}))]);if(!s.success&&s.error){let l=d(s.error),f=s.error===u.timeoutMessage()||s.error===u.abortMessage();return{stdout:o.stdout,stderr:`${o.stderr}python3: ${l}
9
- `,exitCode:o.exitCode||(f?124:1)}}return{...o}}var V={name:"python3",async execute(t,e){if(D(t))return P(z);let r=_(t);if("exitCode"in r)return r;if(r.showVersion)return{stdout:`Python 3.13.2 (Emscripten)
10
- `,stderr:"",exitCode:0};let n,i,c=e.stdin;if(r.code!==null)n=r.code,i="-c";else if(r.module!==null){if(!/^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(r.module))return{stdout:"",stderr:`python3: No module named '${r.module.slice(0,200)}'
11
- `,exitCode:1};n=`import runpy; runpy.run_module('${r.module}', run_name='__main__')`,i=r.module}else if(r.scriptFile==="-")n=C(e.stdin),c="",i="-";else if(r.scriptFile!==null){let p=e.fs.resolvePath(e.cwd,r.scriptFile);if(!await e.fs.exists(p))return{stdout:"",stderr:`python3: can't open file '${r.scriptFile}': [Errno 2] No such file or directory
12
- `,exitCode:2};try{n=await e.fs.readFile(p),i=r.scriptFile}catch(h){let a=A(h.message);return{stdout:"",stderr:`python3: can't open file '${r.scriptFile}': ${a}
13
- `,exitCode:2}}}else if(C(e.stdin).trim())n=C(e.stdin),c="",i="<stdin>";else return{stdout:"",stderr:`python3: no input provided (use -c CODE, -m MODULE, or provide a script file)
14
- `,exitCode:2};return N(n,c,e,i,r.scriptArgs)}},se={name:"python",async execute(t,e){return V.execute(t,e)}};export{ne as _resetExecutionQueue,V as python3Command,se as pythonCommand};
@@ -1,11 +0,0 @@
1
- import{createRequire} from"node:module";const require=createRequire(import.meta.url);
2
- import{b as L}from"./chunk-WNH3HOQA.js";import{a as I,b as l}from"./chunk-KIGPB52X.js";import{d as A,e as m}from"./chunk-PS2RJNZZ.js";import{a as C}from"./chunk-L2UW7DWF.js";import{b as w}from"./chunk-ZBUZKIPX.js";import{a as _,b as f}from"./chunk-T5ZEIOJ3.js";import{a as F,b as D}from"./chunk-FOCWZZDE.js";var h={NOOP:0,READ_FILE:1,WRITE_FILE:2,STAT:3,READDIR:4,MKDIR:5,RM:6,EXISTS:7,APPEND_FILE:8,SYMLINK:9,READLINK:10,LSTAT:11,CHMOD:12,REALPATH:13,RENAME:14,COPY_FILE:15,WRITE_FILE_RANGE:17,READ_RESULT_RANGE:18,WRITE_STDOUT:100,WRITE_STDERR:101,EXIT:102,HTTP_REQUEST:200,EXEC_COMMAND:300,INVOKE_TOOL:400},S={IDLE:0,REQUEST:1,CANCELLED:2},r={NONE:0,SUCCESS:1,ERROR:2},a={NONE:0,NOT_FOUND:1,IS_DIRECTORY:2,NOT_DIRECTORY:3,EXISTS:4,PERMISSION_DENIED:5,INVALID_PATH:6,IO_ERROR:7,NETWORK_ERROR:9,NETWORK_NOT_CONFIGURED:10,NOT_EMPTY:11,LOOP:12,FILE_TOO_LARGE:13,NO_SPACE:14,BUSY:15,READ_ONLY:16,CROSS_DEVICE:17},O=Object.assign(Object.create(null),{ENOENT:a.NOT_FOUND,EISDIR:a.IS_DIRECTORY,ENOTDIR:a.NOT_DIRECTORY,ENOTEMPTY:a.NOT_EMPTY,EEXIST:a.EXISTS,EPERM:a.PERMISSION_DENIED,EACCES:a.PERMISSION_DENIED,EINVAL:a.INVALID_PATH,ELOOP:a.LOOP,EFBIG:a.FILE_TOO_LARGE,ENOSPC:a.NO_SPACE,EBUSY:a.BUSY,EROFS:a.READ_ONLY,EXDEV:a.CROSS_DEVICE}),P=Object.create(null);for(let[d,t]of Object.entries(O))P[t]=d;var o={OP_CODE:0,REQUEST:4,PATH_LENGTH:8,DATA_LENGTH:12,RESULT_LENGTH:16,ERROR_CODE:20,FLAGS:24,MODE:28,RESULT_STATE:32,PATH_BUFFER:36,DATA_BUFFER:4132},R={PATH_BUFFER:4096,DATA_BUFFER:8388608,TOTAL:8392740},g={NONE:0,RECURSIVE:1,FORCE:2,MKDIR_RECURSIVE:1},u={IS_FILE:0,IS_DIRECTORY:1,IS_SYMLINK:2,MODE:4,SIZE:8,MTIME:16,TOTAL:24};function M(){return new I(R.TOTAL)}var T=class{int32View;uint8View;dataView;constructor(t){this.int32View=new Int32Array(t),this.uint8View=new Uint8Array(t),this.dataView=new DataView(t)}getOpCode(){return l.load(this.int32View,o.OP_CODE/4)}setOpCode(t){l.store(this.int32View,o.OP_CODE/4,t)}getRequest(){return l.load(this.int32View,o.REQUEST/4)}setRequest(t){l.store(this.int32View,o.REQUEST/4,t)}getResultState(){return l.load(this.int32View,o.RESULT_STATE/4)}setResultState(t){l.store(this.int32View,o.RESULT_STATE/4,t)}getPathLength(){return l.load(this.int32View,o.PATH_LENGTH/4)}setPathLength(t){l.store(this.int32View,o.PATH_LENGTH/4,t)}getDataLength(){return l.load(this.int32View,o.DATA_LENGTH/4)}setDataLength(t){l.store(this.int32View,o.DATA_LENGTH/4,t)}getResultLength(){return l.load(this.int32View,o.RESULT_LENGTH/4)}setResultLength(t){l.store(this.int32View,o.RESULT_LENGTH/4,t)}getErrorCode(){return l.load(this.int32View,o.ERROR_CODE/4)}setErrorCode(t){l.store(this.int32View,o.ERROR_CODE/4,t)}getFlags(){return l.load(this.int32View,o.FLAGS/4)}setFlags(t){l.store(this.int32View,o.FLAGS/4,t)}getMode(){return l.load(this.int32View,o.MODE/4)}setMode(t){l.store(this.int32View,o.MODE/4,t)}getPath(){let t=this.getPathLength(),e=this.uint8View.slice(o.PATH_BUFFER,o.PATH_BUFFER+t);return new TextDecoder().decode(e)}setPath(t){let e=new TextEncoder().encode(t);if(e.length>R.PATH_BUFFER)throw new Error(`Path too long: ${e.length} > ${R.PATH_BUFFER}`);this.uint8View.set(e,o.PATH_BUFFER),this.setPathLength(e.length)}getData(){let t=this.getDataLength();return this.uint8View.slice(o.DATA_BUFFER,o.DATA_BUFFER+t)}setData(t){if(t.length>R.DATA_BUFFER)throw new Error(`Data too large: ${t.length} > ${R.DATA_BUFFER}`);this.uint8View.set(t,o.DATA_BUFFER),this.setDataLength(t.length)}getDataAsString(){let t=this.getData();return new TextDecoder().decode(t)}setDataFromString(t){let e=new TextEncoder().encode(t);this.setData(e)}getResult(){let t=this.getResultLength();return this.uint8View.slice(o.DATA_BUFFER,o.DATA_BUFFER+t)}setResult(t){if(t.length>R.DATA_BUFFER)throw new Error(`Result too large: ${t.length} > ${R.DATA_BUFFER}`);this.uint8View.set(t,o.DATA_BUFFER),this.setResultLength(t.length)}setResultPrefix(t){if(t.length>2147483647)throw new Error(`Result too large: ${t.length} exceeds int32`);let e=Math.min(t.length,R.DATA_BUFFER);this.uint8View.set(t.subarray(0,e),o.DATA_BUFFER),this.setResultLength(t.length)}getResultAsString(){let t=this.getResult();return new TextDecoder().decode(t)}setResultFromString(t){let e=new TextEncoder().encode(t);this.setResult(e)}encodeStat(t){this.uint8View[o.DATA_BUFFER+u.IS_FILE]=t.isFile?1:0,this.uint8View[o.DATA_BUFFER+u.IS_DIRECTORY]=t.isDirectory?1:0,this.uint8View[o.DATA_BUFFER+u.IS_SYMLINK]=t.isSymbolicLink?1:0,this.dataView.setInt32(o.DATA_BUFFER+u.MODE,t.mode,!0);let e=Math.min(t.size,Number.MAX_SAFE_INTEGER);this.dataView.setFloat64(o.DATA_BUFFER+u.SIZE,e,!0),this.dataView.setFloat64(o.DATA_BUFFER+u.MTIME,t.mtime.getTime(),!0),this.setResultLength(u.TOTAL)}decodeStat(){return{isFile:this.uint8View[o.DATA_BUFFER+u.IS_FILE]===1,isDirectory:this.uint8View[o.DATA_BUFFER+u.IS_DIRECTORY]===1,isSymbolicLink:this.uint8View[o.DATA_BUFFER+u.IS_SYMLINK]===1,mode:this.dataView.getInt32(o.DATA_BUFFER+u.MODE,!0),size:this.dataView.getFloat64(o.DATA_BUFFER+u.SIZE,!0),mtime:new Date(this.dataView.getFloat64(o.DATA_BUFFER+u.MTIME,!0))}}async waitUntilReady(t){let e=Date.now();for(;;){let s=this.getRequest();if(s===S.REQUEST)return!0;if(s!==S.IDLE)return!1;let i=Date.now()-e;if(i>=t)return!1;let n=t-i,c=l.waitAsync(this.int32View,o.REQUEST/4,S.IDLE,n);if(c.async&&await c.value==="timed-out")return!1}}waitForResult(t){return l.wait(this.int32View,o.RESULT_STATE/4,r.NONE,t)}notifyRequest(){return l.notify(this.int32View,o.REQUEST/4)}notifyResult(){return l.notify(this.int32View,o.RESULT_STATE/4)}reset(){this.setOpCode(h.NOOP),this.setRequest(S.IDLE),this.setResultState(r.NONE),this.setPathLength(0),this.setDataLength(0),this.setResultLength(0),this.setErrorCode(a.NONE),this.setFlags(g.NONE),this.setMode(0)}};function U(d){return d!==void 0&&Object.hasOwn(O,d)?O[d]:a.IO_ERROR}var N=class{fs;cwd;commandName;secureFetch;maxOutputSize;exec;invokeTool;protocol;running=!1;output={stdout:"",stderr:"",exitCode:0};outputLimitExceeded=!1;startTime=0;timeoutMs=0;lastResult=null;constructor(t,e,s,i,n=void 0,c=0,E=void 0,p=void 0){this.fs=e,this.cwd=s,this.commandName=i,this.secureFetch=n,this.maxOutputSize=c,this.exec=E,this.invokeTool=p,this.protocol=new T(t)}remainingMs(){return Math.max(0,this.timeoutMs-(Date.now()-this.startTime))}raceDeadline(t){let e=this.remainingMs();if(e<=0)return this.running=!1,this.output.exitCode=124,this.output.stderr+=`
3
- ${this.commandName}: execution timeout exceeded
4
- `,Promise.reject(new Error("Operation timed out"));let s=t();return e===Number.POSITIVE_INFINITY?s:new Promise((i,n)=>{let c=A(()=>{this.running=!1,this.output.exitCode=124,this.output.stderr+=`
5
- ${this.commandName}: execution timeout exceeded
6
- `,n(new Error("Operation timed out"))},e);s.then(E=>{m(c),i(E)},E=>{m(c),n(E)})})}async run(t){for(this.running=!0,this.startTime=Date.now(),this.timeoutMs=t;this.running;){if(Date.now()-this.startTime>=t){this.output.stderr+=`
7
- ${this.commandName}: execution timeout exceeded
8
- `,this.output.exitCode=124;break}let s=this.remainingMs();if(!await this.protocol.waitUntilReady(s)){if(!this.running)break;this.output.stderr+=`
9
- ${this.commandName}: execution timeout exceeded
10
- `,this.output.exitCode=124;break}if(!this.running)break;this.protocol.setRequest(S.IDLE);let n=this.protocol.getOpCode();await this.handleOperation(n),this.protocol.notifyResult()}return this.output}stop(){this.running=!1,this.lastResult=null,this.protocol.setRequest(S.CANCELLED),this.protocol.notifyRequest()}async handleOperation(t){try{switch(t){case h.READ_FILE:await this.handleReadFile();break;case h.WRITE_FILE:await this.handleWriteFile();break;case h.STAT:await this.handleStat();break;case h.LSTAT:await this.handleLstat();break;case h.READDIR:await this.handleReaddir();break;case h.MKDIR:await this.handleMkdir();break;case h.READ_RESULT_RANGE:this.handleReadResultRange();break;case h.WRITE_FILE_RANGE:await this.handleWriteFileRange();break;case h.RM:await this.handleRm();break;case h.EXISTS:await this.handleExists();break;case h.APPEND_FILE:await this.handleAppendFile();break;case h.SYMLINK:await this.handleSymlink();break;case h.READLINK:await this.handleReadlink();break;case h.CHMOD:await this.handleChmod();break;case h.REALPATH:await this.handleRealpath();break;case h.RENAME:await this.handleRename();break;case h.COPY_FILE:await this.handleCopyFile();break;case h.WRITE_STDOUT:this.handleWriteStdout();break;case h.WRITE_STDERR:this.handleWriteStderr();break;case h.EXIT:this.handleExit();break;case h.HTTP_REQUEST:await this.handleHttpRequest();break;case h.EXEC_COMMAND:await this.handleExecCommand();break;case h.INVOKE_TOOL:await this.handleInvokeTool();break;default:this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultState(r.ERROR)}}catch(e){this.setErrorFromException(e)}}publishResult(t){let e=typeof t=="string"?new TextEncoder().encode(t):t;this.lastResult=e,this.protocol.setResultPrefix(e),this.protocol.setResultState(r.SUCCESS)}handleReadResultRange(){let t=this.protocol.getFlags(),e=this.protocol.getMode(),s=this.lastResult;if(!s||t>=s.length){this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString(`No retained result for range read (offset=${t}, length=${e}, retained=${s?.length??"none"})`),this.protocol.setResultState(r.ERROR);return}this.protocol.setResult(s.subarray(t,t+e)),this.protocol.setResultState(r.SUCCESS)}resolvePath(t){return this.fs.resolvePath(this.cwd,t)}async handleReadFile(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readFileBuffer(t);this.publishResult(e)}catch(e){this.setErrorFromException(e)}}async handleWriteFileRange(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getFlags(),s=this.protocol.getData();try{if(e===0)await this.fs.writeFile(t,s);else{let i=await this.fs.stat(t);if(i.size!==e)throw new _("EIO",`non-sequential range write to '${t}': offset ${e} != size ${i.size}`);await this.fs.appendFile(t,s)}this.protocol.setResultState(r.SUCCESS)}catch(i){this.setErrorFromException(i)}}async handleWriteFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getData();try{await this.fs.writeFile(t,e),this.protocol.setResultState(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleStat(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.stat(t);this.protocol.encodeStat(e),this.protocol.setResultState(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleLstat(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.lstat(t);this.protocol.encodeStat(e),this.protocol.setResultState(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleReaddir(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readdir(t);this.publishResult(JSON.stringify(e))}catch(e){this.setErrorFromException(e)}}async handleMkdir(){let t=this.resolvePath(this.protocol.getPath()),s=(this.protocol.getFlags()&g.MKDIR_RECURSIVE)!==0;try{await this.fs.mkdir(t,{recursive:s}),this.protocol.setResultState(r.SUCCESS)}catch(i){this.setErrorFromException(i)}}async handleRm(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getFlags(),s=(e&g.RECURSIVE)!==0,i=(e&g.FORCE)!==0;try{await this.fs.rm(t,{recursive:s,force:i}),this.protocol.setResultState(r.SUCCESS)}catch(n){this.setErrorFromException(n)}}async handleExists(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.exists(t);this.protocol.setResult(new Uint8Array([e?1:0])),this.protocol.setResultState(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleAppendFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getData();try{await this.fs.appendFile(t,e),this.protocol.setResultState(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleSymlink(){let t=this.protocol.getPath(),e=this.protocol.getDataAsString(),s=this.resolvePath(t);try{await this.fs.symlink(e,s),this.protocol.setResultState(r.SUCCESS)}catch(i){this.setErrorFromException(i)}}async handleReadlink(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readlink(t);this.protocol.setResultFromString(e),this.protocol.setResultState(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleChmod(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getMode();try{await this.fs.chmod(t,e),this.protocol.setResultState(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleRealpath(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.realpath(t);this.protocol.setResultFromString(e),this.protocol.setResultState(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleRename(){let t=this.resolvePath(this.protocol.getPath()),e=this.resolvePath(this.protocol.getDataAsString());try{await this.fs.mv(t,e),this.protocol.setResultState(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleCopyFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.resolvePath(this.protocol.getDataAsString());try{await this.fs.cp(t,e),this.protocol.setResultState(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}handleWriteStdout(){let t=this.protocol.getDataAsString();if(!this.tryAppendOutput("stdout",t)){this.outputLimitExceeded=!0,this.output.exitCode=1,this.appendOutputLimitError(),this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString("Output size limit exceeded"),this.protocol.setResultState(r.ERROR);return}this.protocol.setResultState(r.SUCCESS)}handleWriteStderr(){let t=this.protocol.getDataAsString();if(!this.tryAppendOutput("stderr",t)){this.outputLimitExceeded=!0,this.output.exitCode=1,this.appendOutputLimitError(),this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString("Output size limit exceeded"),this.protocol.setResultState(r.ERROR);return}this.protocol.setResultState(r.SUCCESS)}handleExit(){let t=this.protocol.getFlags();this.outputLimitExceeded?this.output.exitCode===0&&(this.output.exitCode=1):this.output.exitCode=t,this.protocol.setResultState(r.SUCCESS),this.running=!1}tryAppendOutput(t,e){return this.outputLimitExceeded?!1:this.maxOutputSize<=0?(t==="stdout"?this.output.stdout+=e:this.output.stderr+=e,!0):this.output.stdout.length+this.output.stderr.length+e.length>this.maxOutputSize?!1:(t==="stdout"?this.output.stdout+=e:this.output.stderr+=e,!0)}appendOutputLimitError(){if(this.maxOutputSize<=0)return;let t=`${this.commandName}: total output size exceeded (>${this.maxOutputSize} bytes), increase executionLimits.maxOutputSize
11
- `,e=t.length>this.maxOutputSize?t.slice(0,this.maxOutputSize):t;if(this.output.stderr.includes("total output size exceeded"))return;let i=this.output.stdout.length+this.output.stderr.length+e.length-this.maxOutputSize;if(i>0)if(this.output.stdout.length>=i)this.output.stdout=this.output.stdout.slice(0,this.output.stdout.length-i);else{let n=i-this.output.stdout.length;this.output.stdout="",n>=this.output.stderr.length?this.output.stderr="":this.output.stderr=this.output.stderr.slice(0,this.output.stderr.length-n)}this.output.stderr+=e}async handleHttpRequest(){let t=this.secureFetch;if(!t){this.protocol.setErrorCode(a.NETWORK_NOT_CONFIGURED),this.protocol.setResultFromString("Network access not configured. Enable network in Bash options."),this.protocol.setResultState(r.ERROR);return}let e=this.protocol.getPath(),s=this.protocol.getDataAsString();try{let i=s?JSON.parse(s):{},n=this.remainingMs(),c=await this.raceDeadline(()=>t(e,{method:i.method,headers:i.headers,body:i.body,timeoutMs:n})),E=JSON.stringify({status:c.status,statusText:c.statusText,headers:c.headers,bodyBase64:L(c.body,"base64"),url:c.url});this.publishResult(E)}catch(i){let n=F(i instanceof Error?i.message:String(i));this.protocol.setErrorCode(a.NETWORK_ERROR),this.protocol.setResultFromString(n),this.protocol.setResultState(r.ERROR)}}async handleExecCommand(){let t=this.exec;if(!t){this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString("Command execution not available in this context."),this.protocol.setResultState(r.ERROR);return}let e=this.protocol.getPath(),s=this.protocol.getDataAsString(),i=new AbortController;try{let n={cwd:this.cwd,signal:i.signal};if(s){let p=JSON.parse(s);p.stdin&&(n.stdin=p.stdin),p.args&&Array.isArray(p.args)&&(n.args=p.args.map(x=>String(x)),e=C([e]))}let c=await this.raceDeadline(()=>t(e,n)),E=JSON.stringify({stdout:c.stdout,stderr:c.stderr,exitCode:c.exitCode});this.publishResult(E)}catch(n){i.abort();let c=n instanceof Error?n.message:String(n);this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString(c),this.protocol.setResultState(r.ERROR)}}async handleInvokeTool(){let t=this.invokeTool;if(!t){this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString("Tool invocation not available in this context."),this.protocol.setResultState(r.ERROR);return}let e=this.protocol.getPath(),s=this.protocol.getDataAsString();try{let i=await this.raceDeadline(()=>w.runTrustedAsync(()=>t(e,s)));this.publishResult(i)}catch(i){let n=D(i instanceof Error?i.message:String(i));this.protocol.setErrorCode(a.IO_ERROR),this.protocol.setResultFromString(n),this.protocol.setResultState(r.ERROR)}}setErrorFromException(t){let e=t instanceof Error?t.message:String(t),s=F(e);this.protocol.setErrorCode(U(f(t))),this.protocol.setResultFromString(s),this.protocol.setResultState(r.ERROR)}};export{M as a,N as b};
@@ -1,19 +0,0 @@
1
- import{createRequire} from"node:module";const require=createRequire(import.meta.url);
2
- import{d as V}from"./chunk-FTET43KM.js";import{d as B}from"./chunk-D5FHVW27.js";import{l as _,m as Y}from"./chunk-TVCZIH6M.js";import{a as J}from"./chunk-GN6CQ3J4.js";import{a as Q}from"./chunk-QIQMJJZ4.js";import{a as Z,b as q}from"./chunk-QAYAQNCG.js";function h(s,t,e){if(J(e)>s.limits.maxOutputSize-J(t))throw new _(`ls: output size limit exceeded (${s.limits.maxOutputSize} bytes)`,"output_size");return t+e}function X(s,t){let e=new V(s.limits.maxOutputSize,"ls");for(let l=0;l<t.length;l++)l>0&&e.append(`
3
- `),e.append(t[l]);return t.length>0&&e.append(`
4
- `),e.build()}function I(s){if(s<1024)return String(s);if(s<1024*1024){let e=s/1024;return e<10?`${e.toFixed(1)}K`:`${Math.round(e)}K`}if(s<1024*1024*1024){let e=s/1048576;return e<10?`${e.toFixed(1)}M`:`${Math.round(e)}M`}let t=s/(1024*1024*1024);return t<10?`${t.toFixed(1)}G`:`${Math.round(t)}G`}function K(s){let e=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][s.getMonth()],l=String(s.getDate()).padStart(2," "),p=new Date,g=new Date(p.getTime()-4320*60*60*1e3);if(s>g){let z=String(s.getHours()).padStart(2,"0"),d=String(s.getMinutes()).padStart(2,"0");return`${e} ${l} ${z}:${d}`}let b=s.getFullYear();return`${e} ${l} ${b}`}function W(s){return s.isDirectory?"/":s.isSymbolicLink?"@":(s.mode&73)!==0?"*":""}var nt={name:"ls",summary:"list directory contents",usage:"ls [OPTION]... [FILE]...",options:["-a, --all do not ignore entries starting with .","-A, --almost-all do not list . and ..","-d, --directory list directories themselves, not their contents","-F, --classify append indicator (one of */=>@) to entries","-h, --human-readable with -l, print sizes like 1K 234M 2G etc.","-l use a long listing format","-r, --reverse reverse order while sorting","-R, --recursive list subdirectories recursively","-S sort by file size, largest first","-t sort by time, newest first","-1 list one file per line"," --help display this help and exit"]},ot={showAll:{short:"a",long:"all",type:"boolean"},showAlmostAll:{short:"A",long:"almost-all",type:"boolean"},longFormat:{short:"l",type:"boolean"},humanReadable:{short:"h",long:"human-readable",type:"boolean"},recursive:{short:"R",long:"recursive",type:"boolean"},reverse:{short:"r",long:"reverse",type:"boolean"},sortBySize:{short:"S",type:"boolean"},classifyFiles:{short:"F",long:"classify",type:"boolean"},directoryOnly:{short:"d",long:"directory",type:"boolean"},sortByTime:{short:"t",type:"boolean"},onePerLine:{short:"1",type:"boolean"}},pt={name:"ls",async execute(s,t){if(q(s))return Z(nt);let e=Q("ls",s,ot);if(!e.ok)return e.error;let l=e.result.flags.showAll,p=e.result.flags.showAlmostAll,g=e.result.flags.longFormat,b=e.result.flags.humanReadable,z=e.result.flags.recursive,d=e.result.flags.reverse,$=e.result.flags.classifyFiles,O=e.result.flags.directoryOnly,R=it(s,e.result.flags.sortBySize,e.result.flags.sortByTime);e.result.flags.onePerLine;let F=e.result.positional;F.length===0&&F.push(".");let S="",P="",C=0,M=new B({limits:t.limits,signal:t.signal,executionScope:t.executionScope,site:"ls"});if(O){for(let n of await G(F,t,R,d,M)){M.visit(0);let i=t.fs.resolvePath(t.cwd,n);try{let D=await t.fs.stat(i);if(g){let L=D.isDirectory?"drwxr-xr-x":"-rw-r--r--",c=$?W(await t.fs.lstat(i)):"",u=D.size??0,A=b?I(u).padStart(5):String(u).padStart(5),a=D.mtime??new Date(0),o=K(a);S=h(t,S,`${L} 1 user user ${A} ${o} ${n}${c}
5
- `)}else{let L=$?W(await t.fs.lstat(i)):"";S=h(t,S,`${n}${L}
6
- `)}}catch{P=h(t,P,`ls: cannot access '${n}': No such file or directory
7
- `),C=2}}return{stdout:S,stderr:P,exitCode:C}}let m=[],y=[];for(let n of F){M.visit(0);try{((await t.fs.stat(t.fs.resolvePath(t.cwd,n))).isDirectory?y:m).push(n)}catch{P=h(t,P,`ls: ${n}: No such file or directory
8
- `),C=2}}let T=async(n,i)=>{let D=await x(n,t,l,p,g,z,i,d,b,R,$,!1,M,0,new Set,!0);S=h(t,S,D.stdout),P=h(t,P,D.stderr),D.exitCode!==0&&(C=D.exitCode)};for(let n of await G(m,t,R,d,M))await T(n,!1);let N=F.length>1;for(let n of await G(y,t,R,d,M))S&&(S=h(t,S,`
9
- `)),await T(n,N);return{stdout:S,stderr:P,exitCode:C}}};function it(s,t,e){if(!t&&!e)return"name";if(t!==e)return t?"size":"time";let l="name";for(let p of s){if(p==="--")break;if(!(!p.startsWith("-")||p.startsWith("--")))for(let g of p.slice(1))g==="S"?l="size":g==="t"&&(l="time")}return l}async function G(s,t,e,l,p){return await j(s,g=>t.fs.resolvePath(t.cwd,g),t,e,l,p)}async function j(s,t,e,l,p,g){let b=[...s];if(l==="name")b.sort();else{g?.checkpoint(b.length);let z=new Map;for(let d of b)try{let $=await e.fs.lstat(t(d));z.set(d,l==="size"?$.size??0:($.mtime??new Date(0)).getTime())}catch{z.set(d,0)}b.sort((d,$)=>{let O=(z.get($)??0)-(z.get(d)??0);return O!==0?O:d<$?-1:d>$?1:0})}return p&&b.reverse(),b}async function x(s,t,e,l,p,g,b,z=!1,d=!1,$="name",O=!1,R=!1,F=new B({limits:t.limits,signal:t.signal,executionScope:t.executionScope,site:"ls"}),S=0,P=new Set,C=!1){let M=e||l,m=t.fs.resolvePath(t.cwd,s);try{C||F.visit(S);let y=await t.fs.stat(m);if(!y.isDirectory){let c=O?W(await t.fs.lstat(m)):"";if(p){let u=y.size??0,A=d?I(u).padStart(5):String(u).padStart(5),a=y.mtime??new Date(0),o=K(a);return{stdout:`-rw-r--r-- 1 user user ${A} ${o} ${s}${c}
10
- `,stderr:"",exitCode:0}}return{stdout:`${s}${c}
11
- `,stderr:"",exitCode:0}}let T=y.identity??(y.dev!==void 0&&y.ino!==void 0?`${String(y.dev)}:${String(y.ino)}`:await t.fs.realpath(m).catch(()=>{}));if(T!==void 0&&P.has(T))return{stdout:"",stderr:`ls: ${s}: symbolic link cycle detected
12
- `,exitCode:2};let N=new Set(P);T!==void 0&&N.add(T);let n=await t.fs.readdir(m);F.checkpoint(),M||(n=n.filter(c=>!c.startsWith("."))),n=await j(n,c=>m==="/"?`/${c}`:`${m}/${c}`,t,$,!1,F),e&&(n=[".","..",...n]),z&&n.reverse();let i="",D="",L=0;if((g||b)&&(i=h(t,i,`${s}:
13
- `)),p){i=h(t,i,`total ${n.length}
14
- `);let c=n.filter(o=>o==="."||o===".."),u=n.filter(o=>o!=="."&&o!=="..");for(let o of c)i=h(t,i,`drwxr-xr-x 1 user user 0 Jan 1 00:00 ${o}
15
- `);let A=[];for(let o=0;o<u.length;o+=100){let r=u.slice(o,o+100),f=await Promise.all(r.map(async v=>{let w=m==="/"?`/${v}`:`${m}/${v}`;try{let k=await t.fs.stat(w),H=k.isDirectory?"drwxr-xr-x":"-rw-r--r--",tt=O?W(await t.fs.lstat(w)):"",U=k.size??0,et=d?I(U).padStart(5):String(U).padStart(5),st=k.mtime??new Date(0),rt=K(st);return{name:v,line:`${H} 1 user user ${et} ${rt} ${v}${tt}
16
- `}}catch{return{name:v,line:`-rw-r--r-- 1 user user 0 Jan 1 00:00 ${v}
17
- `}}}));A.push(...f)}let a=new Map(u.map((o,r)=>[o,r]));A.sort((o,r)=>(a.get(o.name)??0)-(a.get(r.name)??0));for(let{line:o}of A)i=h(t,i,o)}else if(O){let c=[],u=n.filter(a=>a!=="."&&a!==".."),A=n.filter(a=>a==="."||a==="..");for(let a of A)c.push(`${a}/`);for(let a=0;a<u.length;a+=100){let o=u.slice(a,a+100),r=await Promise.all(o.map(async f=>{let v=m==="/"?`/${f}`:`${m}/${f}`;try{let w=await t.fs.lstat(v);return`${f}${W(w)}`}catch{return f}}));c.push(...r)}i=h(t,i,X(t,c))}else i=h(t,i,X(t,n));if(g){let c=n.filter(r=>r!=="."&&r!==".."),u=[];if(t.fs.readdirWithFileTypes)u=(await t.fs.readdirWithFileTypes(m)).filter(f=>f.isDirectory&&c.includes(f.name)).map(f=>({name:f.name,isDirectory:!0}));else for(let r=0;r<c.length;r+=100){let f=c.slice(r,r+100),v=await Promise.all(f.map(async w=>{let k=m==="/"?`/${w}`:`${m}/${w}`;try{let H=await t.fs.stat(k);return{name:w,isDirectory:H.isDirectory}}catch{return{name:w,isDirectory:!1}}}));u.push(...v.filter(w=>w.isDirectory))}let A=await j(u.map(r=>r.name),r=>m==="/"?`/${r}`:`${m}/${r}`,t,$,z,F),a=new Map(A.map((r,f)=>[r,f]));u.sort((r,f)=>(a.get(r.name)??0)-(a.get(f.name)??0));let o=[];for(let r=0;r<u.length;r+=100){let f=u.slice(r,r+100),v=await Promise.all(f.map(async w=>{let k=s==="."?`./${w.name}`:`${s}/${w.name}`,H=await x(k,t,e,l,p,g,!1,z,d,$,O,!0,F,S+1,N);return{name:w.name,result:H}}));o.push(...v)}o.sort((r,f)=>(a.get(r.name)??0)-(a.get(f.name)??0));for(let{result:r}of o)i=h(t,i,`
18
- `),i=h(t,i,r.stdout),D=h(t,D,r.stderr),r.exitCode!==0&&(L=r.exitCode)}return{stdout:i,stderr:D,exitCode:L}}catch(y){if(y instanceof _||y instanceof Y)throw y;return{stdout:"",stderr:`ls: ${s}: No such file or directory
19
- `,exitCode:2}}}var ht={name:"ls",flags:[{flag:"-a",type:"boolean"},{flag:"-A",type:"boolean"},{flag:"-l",type:"boolean"},{flag:"-h",type:"boolean"},{flag:"-R",type:"boolean"},{flag:"-r",type:"boolean"},{flag:"-S",type:"boolean"},{flag:"-F",type:"boolean"},{flag:"-d",type:"boolean"},{flag:"-t",type:"boolean"},{flag:"-1",type:"boolean"}],needsFiles:!0};export{pt as a,ht as b};
@@ -1,2 +0,0 @@
1
- import{createRequire} from"node:module";const require=createRequire(import.meta.url);
2
- import{b as a}from"./chunk-ZBUZKIPX.js";var r=globalThis.setTimeout.bind(globalThis),l=globalThis.clearTimeout.bind(globalThis),T=globalThis.setInterval.bind(globalThis),f=globalThis.clearInterval.bind(globalThis);function u(e){return typeof e!="function"?e:a.bindCurrentContext(e)}var b=((e,n,...i)=>r(u(e),n,...i)),d=l,I=((e,n,...i)=>r(e,n,...i)),c=2147483647;function _(e,n){if(n===Number.POSITIVE_INFINITY)return;let i=u(e),t={cleared:!1,remainingMs:Math.max(0,n),timer:void 0},o=()=>{if(t.cleared)return;let s=Math.min(t.remainingMs,c);t.timer=r(()=>{t.cleared||(t.remainingMs-=s,t.remainingMs>0?o():i())},s)};return o(),t}function g(e){e&&(e.cleared=!0,e.timer!==void 0&&l(e.timer))}export{b as a,d as b,I as c,_ as d,g as e};
@@ -1,7 +0,0 @@
1
- import{createRequire} from"node:module";const require=createRequire(import.meta.url);
2
- import{d as a}from"./chunk-GN6CQ3J4.js";import{a as c}from"./chunk-QIQMJJZ4.js";import{a as u,b as p}from"./chunk-QAYAQNCG.js";import*as g from"diff";var b={name:"diff",summary:"compare files line by line",usage:"diff [OPTION]... FILE1 FILE2",options:["-u, --unified output unified diff format (default)","-q, --brief report only whether files differ","-s, --report-identical-files report when files are the same","-i, --ignore-case ignore case differences"," --help display this help and exit"]},C={unified:{short:"u",long:"unified",type:"boolean"},brief:{short:"q",long:"brief",type:"boolean"},reportSame:{short:"s",long:"report-identical-files",type:"boolean"},ignoreCase:{short:"i",long:"ignore-case",type:"boolean"}},L={name:"diff",async execute(d,e){if(p(d))return u(b);let t=c("diff",d,C);if(!t.ok)return t.error;let m=t.result.flags.brief,h=t.result.flags.reportSame,y=t.result.flags.ignoreCase,l=t.result.positional;if(t.result.flags.unified,l.length<2)return{stdout:"",stderr:`diff: missing operand
3
- `,exitCode:2};let i,s,[r,o]=l;try{i=r==="-"?a(e.stdin):await e.fs.readFile(e.fs.resolvePath(e.cwd,r))}catch{return{stdout:"",stderr:`diff: ${r}: No such file or directory
4
- `,exitCode:2}}try{s=o==="-"?a(e.stdin):await e.fs.readFile(e.fs.resolvePath(e.cwd,o))}catch{return{stdout:"",stderr:`diff: ${o}: No such file or directory
5
- `,exitCode:2}}let f=i,n=s;return y&&(f=f.toLowerCase(),n=n.toLowerCase()),f===n?h?{stdout:`Files ${r} and ${o} are identical
6
- `,stderr:"",exitCode:0}:{stdout:"",stderr:"",exitCode:0}:m?{stdout:`Files ${r} and ${o} differ
7
- `,stderr:"",exitCode:1}:{stdout:g.createTwoFilesPatch(r,o,i,s,"","",{context:3}),stderr:"",exitCode:1}}},P={name:"diff",flags:[{flag:"-u",type:"boolean"},{flag:"-q",type:"boolean"},{flag:"-s",type:"boolean"},{flag:"-i",type:"boolean"}],needsArgs:!0,minArgs:2};export{L as a,P as b};
@@ -1,98 +0,0 @@
1
- import{createRequire} from"node:module";const require=createRequire(import.meta.url);
2
- import{a as A,b as B}from"./chunk-BS6EJR2R.js";import{a as q}from"./chunk-6IA4DXG2.js";import"./chunk-WNH3HOQA.js";import"./chunk-KIGPB52X.js";import{b as v,c as j}from"./chunk-PS2RJNZZ.js";import"./chunk-L2UW7DWF.js";import{a as F}from"./chunk-DLL7UR66.js";import{b as C}from"./chunk-ZBUZKIPX.js";import{d as E}from"./chunk-GN6CQ3J4.js";import"./chunk-T5ZEIOJ3.js";import{a as W,b as h}from"./chunk-FOCWZZDE.js";import{a as S}from"./chunk-W5DWRFSU.js";import{b as M}from"./chunk-QAYAQNCG.js";import"./chunk-NCUTH6QL.js";import{AsyncLocalStorage as H}from"node:async_hooks";import{fileURLToPath as J}from"node:url";import{Worker as L}from"node:worker_threads";var O=new H,P=`js-exec - Sandboxed JavaScript/TypeScript runtime with Node.js-compatible APIs
3
-
4
- Usage: js-exec [OPTIONS] [-c CODE | FILE] [ARGS...]
5
-
6
- Options:
7
- -c CODE Execute inline code
8
- -m, --module Enable ES module mode (import/export)
9
- --strip-types Strip TypeScript type annotations
10
- --version, -V Show version
11
- --help Show this help
12
-
13
- Examples:
14
- js-exec -c "console.log(1 + 2)"
15
- js-exec script.js
16
- js-exec app.ts
17
- echo 'console.log("hello")' | js-exec
18
-
19
- File Extension Auto-Detection:
20
- .js script mode (module mode if top-level await detected)
21
- .mjs ES module mode
22
- .ts, .mts ES module mode + TypeScript stripping
23
-
24
- Node.js Compatibility:
25
- Code written for Node.js largely works here. Both require and import
26
- are supported, the node: prefix works, and standard globals like process,
27
- console, and fetch are available. All I/O is synchronous.
28
-
29
- Available modules:
30
- fs, path, child_process, process, console,
31
- os, url, assert, util, events, buffer, stream,
32
- string_decoder, querystring
33
-
34
- fs (global, require('fs'), or import from 'node:fs'):
35
- readFileSync, writeFileSync, appendFileSync, copyFileSync, renameSync
36
- readdirSync, mkdirSync, rmSync, unlinkSync, rmdirSync
37
- statSync, lstatSync, existsSync, realpathSync, chmodSync
38
- symlinkSync, readlinkSync, readFileBuffer
39
- fs.promises.readFile, fs.promises.writeFile, fs.promises.access, ...
40
-
41
- path: join, resolve, dirname, basename, extname, normalize,
42
- relative, isAbsolute, parse, format, sep, delimiter
43
-
44
- child_process:
45
- execSync(cmd) throws on non-zero exit, returns stdout
46
- spawnSync(cmd, args) returns { stdout, stderr, status }
47
-
48
- process (also global): argv, cwd(), exit(), env, platform, arch,
49
- version, versions
50
-
51
- os: platform(), arch(), homedir(), tmpdir(), type(), hostname(),
52
- EOL, cpus(), endianness()
53
-
54
- url: URL, URLSearchParams, parse(), format()
55
-
56
- assert: ok(), equal(), strictEqual(), deepEqual(), throws(),
57
- doesNotThrow(), fail()
58
-
59
- util: format(), inspect(), promisify(), types, inherits()
60
-
61
- events: EventEmitter (on, once, emit, off, removeListener, ...)
62
-
63
- buffer: Buffer.from(), Buffer.alloc(), Buffer.concat(),
64
- Buffer.isBuffer(), toString(), slice(), equals()
65
-
66
- stream: Readable, Writable, Duplex, Transform, PassThrough, pipeline
67
-
68
- string_decoder: StringDecoder (write, end)
69
-
70
- querystring: parse(), stringify(), escape(), unescape()
71
-
72
- Other Globals:
73
- console log (stdout), error/warn (stderr)
74
- fetch(url, opts) HTTP; returns Promise<Response> (Web Fetch API)
75
- URL, URLSearchParams, Headers, Request, Response
76
- Buffer Buffer.from(), Buffer.alloc(), etc.
77
-
78
- Not Available:
79
- http, https, net, tls, crypto, zlib, dns, cluster, worker_threads,
80
- vm, v8, readline, and other Node.js built-in modules that require
81
- native bindings. Use fetch() for HTTP requests.
82
-
83
- Limits:
84
- Memory: 64 MB per execution
85
- Timeout: 10 s by default; configurable via maxJsTimeoutMs
86
- Engine: QuickJS (compiled to WebAssembly)
87
- `;function N(r){let e={code:null,scriptFile:null,showVersion:!1,scriptArgs:[],isModule:!1,stripTypes:!1};if(r.length===0)return e;for(let t=0;t<r.length;t++){let s=r[t];if(s==="-m"||s==="--module"){e.isModule=!0;continue}if(s==="--strip-types"){e.stripTypes=!0;continue}if(s==="-c")return t+1>=r.length?{stdout:"",stderr:`js-exec: option requires an argument -- 'c'
88
- `,exitCode:2}:(e.code=r[t+1],e.scriptArgs=r.slice(t+2),e);if(s==="--version"||s==="-V")return e.showVersion=!0,e;if(s.startsWith("-")&&s!=="-"&&s!=="--")return{stdout:"",stderr:`js-exec: unrecognized option '${s}'
89
- `,exitCode:2};if(s==="--")return t+1<r.length&&(e.scriptFile=r[t+1],e.scriptArgs=r.slice(t+2)),e;if(!s.startsWith("-"))return e.scriptFile=s,e.scriptArgs=r.slice(t+1),e}return e}var l=null,y=null,c=[],n=null,x=null,U=1e3,R=5e3;function fe(r){R=r}function pe(){return l!==null}function _(r,e,t){r.controller.close();let s=!1,o=()=>{if(!s&&(s=!0,v(i),n===r)){x="worker termination was not acknowledged";for(let a of c)a.bridgeHandler.stop(),a.resolve({success:!1,error:x});c.length=0,r.resolve(t)}},u=()=>{s||(s=!0,v(i),n===r&&(r.resolve(t),n=null,g()))},i=j(()=>{o()},U);r.controller.terminate(e).then(a=>a?u():o(),o)}function me(){y&&(v(y),y=null),n?.bridgeHandler.stop(),n=null;for(let e of c)e.bridgeHandler.stop();c.length=0;let r=l;l=null,r&&r.terminate(),x=null}var D=J(new URL("./js-exec-worker.js",import.meta.url));function g(){if(n||c.length===0)return;let r=c.shift();if(!r)return;n=r;let e=null;try{e=V(),e.postMessage(r.input)}catch(t){r.bridgeHandler.stop();let s={success:!1,error:h(S(t))},o=e??l;l===o&&(l=null),o?_(r,o,s):(r.resolve(s),n===r&&(n=null),g())}}function $(r,e){if(!r||typeof r!="object")return{success:!1,error:"Malformed worker response"};let t=r;return typeof t.protocolToken!="string"||t.protocolToken!==e?{success:!1,error:"Malformed worker response: invalid protocol token"}:typeof t.success!="boolean"?{success:!1,error:"Malformed worker response: missing success flag"}:t.success?{success:!0}:{success:!1,type:t.type==="initialization-failure"?"initialization-failure":void 0,error:typeof t.error=="string"&&t.error.length>0?t.error:"Worker execution failed"}}function V(){if(y&&(v(y),y=null),l)return l;let r=C.runTrusted(()=>new L(D));return l=r,r.on("message",e=>{if(l===r){if(n){let t;try{n.controller.assertMessageSize(e,"response"),t=$(e,n.input.protocolToken)}catch(s){t={success:!1,error:h(S(s))}}if(t.type==="initialization-failure"){x=t.error??"Worker initialization failed",n.bridgeHandler.stop(),n.resolve(t),n=null;for(let s of c)s.bridgeHandler.stop(),s.resolve({success:!1,type:"initialization-failure",error:x});c.length=0,l=null,r.terminate();return}n.resolve(t),n=null}c.length>0?g():Q()}}),r.on("error",e=>{if(l===r){if(n){let t=h(S(e));n.resolve({success:!1,error:t}),n=null}for(let t of c)t.resolve({success:!1,error:"Worker crashed"});c.length=0,l=null}}),r.on("exit",()=>{l===r&&(l=null,n&&(n.resolve({success:!1,error:"Worker exited unexpectedly"}),n=null),c.length>0&&g())}),r}function Q(){y=j(()=>{l&&!n&&c.length===0&&(l.terminate(),l=null)},R)}async function G(r,e,t,s=[],o,u,i){return O.getStore()?{stdout:"",stderr:`js-exec: recursive invocation is not supported
90
- `,exitCode:1}:Y(r,e,t,s,o,u,i)}async function K(r,e,t,s){let o,u=new Promise(d=>{o=d}),i={input:r,bridgeHandler:e,resolve:()=>{},controller:s};s.assertMessageSize({...r,sharedBuffer:void 0},"request");let a=d=>{e.stop();let f={success:!1,error:d==="abort"?i.controller.abortMessage():i.controller.timeoutMessage()};if(n===i){let p=l;l=null,p?_(i,p,f):(i.resolve(f),n=null,g())}else{let p=c.indexOf(i);p!==-1&&c.splice(p,1),i.resolve(f),n||g()}};if(i.resolve=d=>{i.controller.close(),o(d)},i.controller.arm(a),!i.controller.isCanceled){c.push(i);try{g()}catch(d){let f=c.indexOf(i);throw f!==-1&&c.splice(f,1),i.controller.close(),d}}let[m,k]=await Promise.all([e.run(t),u.catch(d=>({success:!1,error:h(S(d))}))]);return{bridgeOutput:m,workerResult:k}}function X(r){return r.limits.maxJsTimeoutMs}async function Y(r,e,t,s=[],o,u,i){if(x!==null)return{stdout:"",stderr:`js-exec: ${h(x)}
91
- `,exitCode:1};let a=A(),m=e.exec,k=m?(b,I)=>O.run(!0,()=>m(b,I)):void 0,d=new B(a,e.fs,e.cwd,"js-exec",e.fetch,e.limits.maxOutputSize,k,e.invokeTool),f=X(e),p=new q({commandName:"js-exec",timeoutMs:f,signal:e.signal,maxMessageBytes:e.limits.maxWorkerMessageBytes}),z={protocolToken:p.protocolToken,sharedBuffer:a,jsCode:r,cwd:e.cwd,env:F(e.env),args:s,scriptPath:t,bootstrapCode:o,isModule:u,stripTypes:i,timeoutMs:f,hasInvokeTool:e.invokeTool!==void 0},{bridgeOutput:T,workerResult:w}=await K(z,d,f,p);if(!w.success&&w.error){let b=w.error===p.timeoutMessage()||w.error===p.abortMessage();return{stdout:T.stdout,stderr:`${T.stderr}js-exec: ${h(w.error)}
92
- `,exitCode:T.exitCode||(b?124:1)}}return{...T}}var he={name:"js-exec",async execute(r,e){if(M(r))return{stdout:P,stderr:"",exitCode:0};let t=N(r);if("exitCode"in t)return t;if(t.showVersion)return{stdout:`QuickJS (quickjs-emscripten)
93
- `,stderr:"",exitCode:0};let s,o;if(t.code!==null)s=t.code,o="-c";else if(t.scriptFile!==null){let m=e.fs.resolvePath(e.cwd,t.scriptFile);if(!await e.fs.exists(m))return{stdout:"",stderr:`js-exec: can't open file '${t.scriptFile}': No such file or directory
94
- `,exitCode:2};try{s=await e.fs.readFile(m),o=m}catch(k){return{stdout:"",stderr:`js-exec: can't open file '${t.scriptFile}': ${W(k.message)}
95
- `,exitCode:2}}}else if(E(e.stdin).trim())s=E(e.stdin),o="<stdin>";else return{stdout:"",stderr:`js-exec: no input provided (use -c CODE or provide a script file)
96
- `,exitCode:2};let u=t.isModule,i=t.stripTypes;o&&o!=="-c"&&o!=="<stdin>"&&((o.endsWith(".mjs")||o.endsWith(".mts")||o.endsWith(".ts"))&&(u=!0),(o.endsWith(".ts")||o.endsWith(".mts"))&&(i=!0)),!u&&/\bawait\s+[\w([`]/.test(s)&&(u=!0);let a=e.jsBootstrapCode;return G(s,e,o,t.scriptArgs,a,u,i)}},ye={name:"node",async execute(){return{stdout:"",stderr:`node: this sandbox uses js-exec instead of node
97
-
98
- ${P}`,exitCode:1}}};export{pe as _hasSharedJsExecWorkerForTests,me as _resetJsExecWorkerForTests,fe as _setJsExecWorkerIdleTimeoutMsForTests,he as jsExecCommand,ye as nodeStubCommand};