@nimbus-sh/worker 0.1.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 (408) hide show
  1. package/README.md +219 -0
  2. package/dist/_shared/bytes.d.ts +18 -0
  3. package/dist/_shared/bytes.d.ts.map +1 -0
  4. package/dist/_shared/bytes.js +17 -0
  5. package/dist/_shared/cache-stats.d.ts +146 -0
  6. package/dist/_shared/cache-stats.d.ts.map +1 -0
  7. package/dist/_shared/cache-stats.js +162 -0
  8. package/dist/_shared/exports-resolver.d.ts +76 -0
  9. package/dist/_shared/exports-resolver.d.ts.map +1 -0
  10. package/dist/_shared/exports-resolver.js +284 -0
  11. package/dist/_shared/install-phase.d.ts +47 -0
  12. package/dist/_shared/install-phase.d.ts.map +1 -0
  13. package/dist/_shared/install-phase.js +1 -0
  14. package/dist/_shared/real-node-imports.d.ts +38 -0
  15. package/dist/_shared/real-node-imports.d.ts.map +1 -0
  16. package/dist/_shared/real-node-imports.js +46 -0
  17. package/dist/_shared/retry.d.ts +93 -0
  18. package/dist/_shared/retry.d.ts.map +1 -0
  19. package/dist/_shared/retry.js +161 -0
  20. package/dist/_shared/session-id.d.ts +39 -0
  21. package/dist/_shared/session-id.d.ts.map +1 -0
  22. package/dist/_shared/session-id.js +127 -0
  23. package/dist/_shared/session-router.d.ts +104 -0
  24. package/dist/_shared/session-router.d.ts.map +1 -0
  25. package/dist/_shared/session-router.js +165 -0
  26. package/dist/_shared/w7-frame.d.ts +93 -0
  27. package/dist/_shared/w7-frame.d.ts.map +1 -0
  28. package/dist/_shared/w7-frame.js +402 -0
  29. package/dist/auth/index.d.ts +16 -0
  30. package/dist/auth/index.d.ts.map +1 -0
  31. package/dist/auth/index.js +15 -0
  32. package/dist/auth/middleware.d.ts +85 -0
  33. package/dist/auth/middleware.d.ts.map +1 -0
  34. package/dist/auth/middleware.js +150 -0
  35. package/dist/auth/token.d.ts +96 -0
  36. package/dist/auth/token.d.ts.map +1 -0
  37. package/dist/auth/token.js +226 -0
  38. package/dist/auth/types.d.ts +141 -0
  39. package/dist/auth/types.d.ts.map +1 -0
  40. package/dist/auth/types.js +114 -0
  41. package/dist/bindings/d1.d.ts +102 -0
  42. package/dist/bindings/d1.d.ts.map +1 -0
  43. package/dist/bindings/d1.js +549 -0
  44. package/dist/bindings/kv.d.ts +82 -0
  45. package/dist/bindings/kv.d.ts.map +1 -0
  46. package/dist/bindings/kv.js +290 -0
  47. package/dist/bindings/r2.d.ts +137 -0
  48. package/dist/bindings/r2.d.ts.map +1 -0
  49. package/dist/bindings/r2.js +379 -0
  50. package/dist/cirrus-npm-cjs.generated.d.ts +17 -0
  51. package/dist/cirrus-npm-cjs.generated.d.ts.map +1 -0
  52. package/dist/cirrus-npm-cjs.generated.js +41 -0
  53. package/dist/cirrus-plugin-react.generated.d.ts +34 -0
  54. package/dist/cirrus-plugin-react.generated.d.ts.map +1 -0
  55. package/dist/cirrus-plugin-react.generated.js +33 -0
  56. package/dist/constants.d.ts +34 -0
  57. package/dist/constants.d.ts.map +1 -0
  58. package/dist/constants.js +116 -0
  59. package/dist/esbuild-wasm-bundle.generated.d.ts +41 -0
  60. package/dist/esbuild-wasm-bundle.generated.d.ts.map +1 -0
  61. package/dist/esbuild-wasm-bundle.generated.js +40 -0
  62. package/dist/facets/cirrus-real.d.ts +147 -0
  63. package/dist/facets/cirrus-real.d.ts.map +1 -0
  64. package/dist/facets/cirrus-real.js +981 -0
  65. package/dist/facets/inner-do-registry.d.ts +41 -0
  66. package/dist/facets/inner-do-registry.d.ts.map +1 -0
  67. package/dist/facets/inner-do-registry.js +51 -0
  68. package/dist/facets/manager.d.ts +314 -0
  69. package/dist/facets/manager.d.ts.map +1 -0
  70. package/dist/facets/manager.js +2681 -0
  71. package/dist/facets/process.d.ts +318 -0
  72. package/dist/facets/process.d.ts.map +1 -0
  73. package/dist/facets/process.js +567 -0
  74. package/dist/facets/real-vite-fs-shim.d.ts +151 -0
  75. package/dist/facets/real-vite-fs-shim.d.ts.map +1 -0
  76. package/dist/facets/real-vite-fs-shim.js +1279 -0
  77. package/dist/facets/real-vite-hmr.d.ts +142 -0
  78. package/dist/facets/real-vite-hmr.d.ts.map +1 -0
  79. package/dist/facets/real-vite-hmr.js +476 -0
  80. package/dist/facets/vite-dev-server.d.ts +293 -0
  81. package/dist/facets/vite-dev-server.d.ts.map +1 -0
  82. package/dist/facets/vite-dev-server.js +2580 -0
  83. package/dist/facets/wasm-swap-registry.d.ts +261 -0
  84. package/dist/facets/wasm-swap-registry.d.ts.map +1 -0
  85. package/dist/facets/wasm-swap-registry.js +551 -0
  86. package/dist/facets/ws-terminal.d.ts +107 -0
  87. package/dist/facets/ws-terminal.d.ts.map +1 -0
  88. package/dist/facets/ws-terminal.js +207 -0
  89. package/dist/git/commands.d.ts +13 -0
  90. package/dist/git/commands.d.ts.map +1 -0
  91. package/dist/git/commands.js +633 -0
  92. package/dist/git/network-facet.d.ts +61 -0
  93. package/dist/git/network-facet.d.ts.map +1 -0
  94. package/dist/git/network-facet.js +700 -0
  95. package/dist/git-bundle.generated.d.ts +16 -0
  96. package/dist/git-bundle.generated.d.ts.map +1 -0
  97. package/dist/git-bundle.generated.js +15 -0
  98. package/dist/index.d.ts +41 -0
  99. package/dist/index.d.ts.map +1 -0
  100. package/dist/index.js +73 -0
  101. package/dist/loaders/child-process/spawn-facet.d.ts +90 -0
  102. package/dist/loaders/child-process/spawn-facet.d.ts.map +1 -0
  103. package/dist/loaders/child-process/spawn-facet.js +103 -0
  104. package/dist/loaders/child-process/spawn-pool.d.ts +110 -0
  105. package/dist/loaders/child-process/spawn-pool.d.ts.map +1 -0
  106. package/dist/loaders/child-process/spawn-pool.js +161 -0
  107. package/dist/loaders/fanout-pool.d.ts +195 -0
  108. package/dist/loaders/fanout-pool.d.ts.map +1 -0
  109. package/dist/loaders/fanout-pool.js +326 -0
  110. package/dist/loaders/generated-workers.d.ts +26 -0
  111. package/dist/loaders/generated-workers.d.ts.map +1 -0
  112. package/dist/loaders/generated-workers.js +25 -0
  113. package/dist/loaders/index.d.ts +15 -0
  114. package/dist/loaders/index.d.ts.map +1 -0
  115. package/dist/loaders/index.js +13 -0
  116. package/dist/loaders/loader-pool.d.ts +273 -0
  117. package/dist/loaders/loader-pool.d.ts.map +1 -0
  118. package/dist/loaders/loader-pool.js +624 -0
  119. package/dist/loaders/npm-resolve-preamble.d.ts +34 -0
  120. package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -0
  121. package/dist/loaders/npm-resolve-preamble.js +237 -0
  122. package/dist/loaders/pre-bundle-preamble.d.ts +41 -0
  123. package/dist/loaders/pre-bundle-preamble.d.ts.map +1 -0
  124. package/dist/loaders/pre-bundle-preamble.js +114 -0
  125. package/dist/loaders/vendor/codegen.d.ts +24 -0
  126. package/dist/loaders/vendor/codegen.d.ts.map +1 -0
  127. package/dist/loaders/vendor/codegen.js +44 -0
  128. package/dist/loaders/vendor/errors.d.ts +24 -0
  129. package/dist/loaders/vendor/errors.d.ts.map +1 -0
  130. package/dist/loaders/vendor/errors.js +46 -0
  131. package/dist/loaders/vendor/index.d.ts +16 -0
  132. package/dist/loaders/vendor/index.d.ts.map +1 -0
  133. package/dist/loaders/vendor/index.js +11 -0
  134. package/dist/loaders/vendor/pool.d.ts +88 -0
  135. package/dist/loaders/vendor/pool.d.ts.map +1 -0
  136. package/dist/loaders/vendor/pool.js +353 -0
  137. package/dist/loaders/vendor/primitives.d.ts +11 -0
  138. package/dist/loaders/vendor/primitives.d.ts.map +1 -0
  139. package/dist/loaders/vendor/primitives.js +33 -0
  140. package/dist/loaders/vendor/serialize.d.ts +3 -0
  141. package/dist/loaders/vendor/serialize.d.ts.map +1 -0
  142. package/dist/loaders/vendor/serialize.js +25 -0
  143. package/dist/loaders/vendor/types.d.ts +60 -0
  144. package/dist/loaders/vendor/types.d.ts.map +1 -0
  145. package/dist/loaders/vendor/types.js +4 -0
  146. package/dist/npm/cache.d.ts +136 -0
  147. package/dist/npm/cache.d.ts.map +1 -0
  148. package/dist/npm/cache.js +429 -0
  149. package/dist/npm/install-batch-facet.d.ts +129 -0
  150. package/dist/npm/install-batch-facet.d.ts.map +1 -0
  151. package/dist/npm/install-batch-facet.js +598 -0
  152. package/dist/npm/install-facet.d.ts +29 -0
  153. package/dist/npm/install-facet.d.ts.map +1 -0
  154. package/dist/npm/install-facet.js +9 -0
  155. package/dist/npm/installer.d.ts +239 -0
  156. package/dist/npm/installer.d.ts.map +1 -0
  157. package/dist/npm/installer.js +2022 -0
  158. package/dist/npm/npx-install.d.ts +74 -0
  159. package/dist/npm/npx-install.d.ts.map +1 -0
  160. package/dist/npm/npx-install.js +302 -0
  161. package/dist/npm/pre-bundle-facet.d.ts +168 -0
  162. package/dist/npm/pre-bundle-facet.d.ts.map +1 -0
  163. package/dist/npm/pre-bundle-facet.js +653 -0
  164. package/dist/npm/r2-cache.d.ts +286 -0
  165. package/dist/npm/r2-cache.d.ts.map +1 -0
  166. package/dist/npm/r2-cache.js +506 -0
  167. package/dist/npm/resolve-facet.d.ts +202 -0
  168. package/dist/npm/resolve-facet.d.ts.map +1 -0
  169. package/dist/npm/resolve-facet.js +833 -0
  170. package/dist/npm/resolve-one-facet.d.ts +204 -0
  171. package/dist/npm/resolve-one-facet.d.ts.map +1 -0
  172. package/dist/npm/resolve-one-facet.js +437 -0
  173. package/dist/npm/resolver.d.ts +109 -0
  174. package/dist/npm/resolver.d.ts.map +1 -0
  175. package/dist/npm/resolver.js +899 -0
  176. package/dist/npm/tarball-stream.d.ts +85 -0
  177. package/dist/npm/tarball-stream.d.ts.map +1 -0
  178. package/dist/npm/tarball-stream.js +205 -0
  179. package/dist/npm/tarball.d.ts +51 -0
  180. package/dist/npm/tarball.d.ts.map +1 -0
  181. package/dist/npm/tarball.js +185 -0
  182. package/dist/observability/diag-counters.d.ts +292 -0
  183. package/dist/observability/diag-counters.d.ts.map +1 -0
  184. package/dist/observability/diag-counters.js +302 -0
  185. package/dist/observability/heap-estimate.d.ts +166 -0
  186. package/dist/observability/heap-estimate.d.ts.map +1 -0
  187. package/dist/observability/heap-estimate.js +192 -0
  188. package/dist/observability/heavy-alloc-coord.d.ts +95 -0
  189. package/dist/observability/heavy-alloc-coord.d.ts.map +1 -0
  190. package/dist/observability/heavy-alloc-coord.js +149 -0
  191. package/dist/observability/oom-classify.d.ts +56 -0
  192. package/dist/observability/oom-classify.d.ts.map +1 -0
  193. package/dist/observability/oom-classify.js +118 -0
  194. package/dist/observability/oom-discriminator.d.ts +192 -0
  195. package/dist/observability/oom-discriminator.d.ts.map +1 -0
  196. package/dist/observability/oom-discriminator.js +233 -0
  197. package/dist/real-vite-bundle.generated.d.ts +46 -0
  198. package/dist/real-vite-bundle.generated.d.ts.map +1 -0
  199. package/dist/real-vite-bundle.generated.js +53 -0
  200. package/dist/replica/routing.d.ts +171 -0
  201. package/dist/replica/routing.d.ts.map +1 -0
  202. package/dist/replica/routing.js +288 -0
  203. package/dist/replica/suspension.d.ts +36 -0
  204. package/dist/replica/suspension.d.ts.map +1 -0
  205. package/dist/replica/suspension.js +49 -0
  206. package/dist/router/index.d.ts +156 -0
  207. package/dist/router/index.d.ts.map +1 -0
  208. package/dist/router/index.js +220 -0
  209. package/dist/runtime/assets-loader.d.ts +71 -0
  210. package/dist/runtime/assets-loader.d.ts.map +1 -0
  211. package/dist/runtime/assets-loader.js +128 -0
  212. package/dist/runtime/barrel-detect.d.ts +46 -0
  213. package/dist/runtime/barrel-detect.d.ts.map +1 -0
  214. package/dist/runtime/barrel-detect.js +73 -0
  215. package/dist/runtime/barrel-synthesizer.d.ts +181 -0
  216. package/dist/runtime/barrel-synthesizer.d.ts.map +1 -0
  217. package/dist/runtime/barrel-synthesizer.js +541 -0
  218. package/dist/runtime/bun-repl.d.ts +46 -0
  219. package/dist/runtime/bun-repl.d.ts.map +1 -0
  220. package/dist/runtime/bun-repl.js +326 -0
  221. package/dist/runtime/bun-runner.d.ts +66 -0
  222. package/dist/runtime/bun-runner.d.ts.map +1 -0
  223. package/dist/runtime/bun-runner.js +219 -0
  224. package/dist/runtime/clang-runner.d.ts +38 -0
  225. package/dist/runtime/clang-runner.d.ts.map +1 -0
  226. package/dist/runtime/clang-runner.js +1033 -0
  227. package/dist/runtime/comment-strip.d.ts +37 -0
  228. package/dist/runtime/comment-strip.d.ts.map +1 -0
  229. package/dist/runtime/comment-strip.js +74 -0
  230. package/dist/runtime/esbuild-service.d.ts +201 -0
  231. package/dist/runtime/esbuild-service.d.ts.map +1 -0
  232. package/dist/runtime/esbuild-service.js +1444 -0
  233. package/dist/runtime/esbuild-wasm-bytes.d.ts +87 -0
  234. package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -0
  235. package/dist/runtime/esbuild-wasm-bytes.js +131 -0
  236. package/dist/runtime/framework-detect.d.ts +71 -0
  237. package/dist/runtime/framework-detect.d.ts.map +1 -0
  238. package/dist/runtime/framework-detect.js +178 -0
  239. package/dist/runtime/long-running-handle.d.ts +133 -0
  240. package/dist/runtime/long-running-handle.d.ts.map +1 -0
  241. package/dist/runtime/long-running-handle.js +192 -0
  242. package/dist/runtime/node-repl.d.ts +36 -0
  243. package/dist/runtime/node-repl.d.ts.map +1 -0
  244. package/dist/runtime/node-repl.js +293 -0
  245. package/dist/runtime/node-runner.d.ts +111 -0
  246. package/dist/runtime/node-runner.d.ts.map +1 -0
  247. package/dist/runtime/node-runner.js +194 -0
  248. package/dist/runtime/node-shims.d.ts +24 -0
  249. package/dist/runtime/node-shims.d.ts.map +1 -0
  250. package/dist/runtime/node-shims.js +3019 -0
  251. package/dist/runtime/package-manager.d.ts +118 -0
  252. package/dist/runtime/package-manager.d.ts.map +1 -0
  253. package/dist/runtime/package-manager.js +420 -0
  254. package/dist/runtime/port-registry.d.ts +80 -0
  255. package/dist/runtime/port-registry.d.ts.map +1 -0
  256. package/dist/runtime/port-registry.js +166 -0
  257. package/dist/runtime/process-logs-api.d.ts +102 -0
  258. package/dist/runtime/process-logs-api.d.ts.map +1 -0
  259. package/dist/runtime/process-logs-api.js +253 -0
  260. package/dist/runtime/process-logs.d.ts +311 -0
  261. package/dist/runtime/process-logs.d.ts.map +1 -0
  262. package/dist/runtime/process-logs.js +656 -0
  263. package/dist/runtime/process-table.d.ts +65 -0
  264. package/dist/runtime/process-table.d.ts.map +1 -0
  265. package/dist/runtime/process-table.js +107 -0
  266. package/dist/runtime/project-detect.d.ts +21 -0
  267. package/dist/runtime/project-detect.d.ts.map +1 -0
  268. package/dist/runtime/project-detect.js +46 -0
  269. package/dist/runtime/python-repl.d.ts +66 -0
  270. package/dist/runtime/python-repl.d.ts.map +1 -0
  271. package/dist/runtime/python-repl.js +563 -0
  272. package/dist/runtime/python-runner.d.ts +50 -0
  273. package/dist/runtime/python-runner.d.ts.map +1 -0
  274. package/dist/runtime/python-runner.js +870 -0
  275. package/dist/runtime/repl-session.d.ts +160 -0
  276. package/dist/runtime/repl-session.d.ts.map +1 -0
  277. package/dist/runtime/repl-session.js +393 -0
  278. package/dist/runtime/require-resolver.d.ts +52 -0
  279. package/dist/runtime/require-resolver.d.ts.map +1 -0
  280. package/dist/runtime/require-resolver.js +690 -0
  281. package/dist/runtime/router-basename.d.ts +36 -0
  282. package/dist/runtime/router-basename.d.ts.map +1 -0
  283. package/dist/runtime/router-basename.js +310 -0
  284. package/dist/runtime/ruby-repl.d.ts +43 -0
  285. package/dist/runtime/ruby-repl.d.ts.map +1 -0
  286. package/dist/runtime/ruby-repl.js +229 -0
  287. package/dist/runtime/ruby-runner.d.ts +62 -0
  288. package/dist/runtime/ruby-runner.d.ts.map +1 -0
  289. package/dist/runtime/ruby-runner.js +737 -0
  290. package/dist/runtime/runtime-catalog.d.ts +99 -0
  291. package/dist/runtime/runtime-catalog.d.ts.map +1 -0
  292. package/dist/runtime/runtime-catalog.js +183 -0
  293. package/dist/runtime/runtime-registry.d.ts +136 -0
  294. package/dist/runtime/runtime-registry.d.ts.map +1 -0
  295. package/dist/runtime/runtime-registry.js +318 -0
  296. package/dist/runtime/streams.d.ts +13 -0
  297. package/dist/runtime/streams.d.ts.map +1 -0
  298. package/dist/runtime/streams.js +402 -0
  299. package/dist/runtime/wasi-instance.d.ts +190 -0
  300. package/dist/runtime/wasi-instance.d.ts.map +1 -0
  301. package/dist/runtime/wasi-instance.js +2044 -0
  302. package/dist/runtime/wasm-runner.d.ts +117 -0
  303. package/dist/runtime/wasm-runner.d.ts.map +1 -0
  304. package/dist/runtime/wasm-runner.js +705 -0
  305. package/dist/session/bindings.d.ts +168 -0
  306. package/dist/session/bindings.d.ts.map +1 -0
  307. package/dist/session/bindings.js +524 -0
  308. package/dist/session/ctx-exports.d.ts +16 -0
  309. package/dist/session/ctx-exports.d.ts.map +1 -0
  310. package/dist/session/ctx-exports.js +22 -0
  311. package/dist/session/diag.d.ts +62 -0
  312. package/dist/session/diag.d.ts.map +1 -0
  313. package/dist/session/diag.js +118 -0
  314. package/dist/session/fs-watch.d.ts +132 -0
  315. package/dist/session/fs-watch.d.ts.map +1 -0
  316. package/dist/session/fs-watch.js +255 -0
  317. package/dist/session/helpers.d.ts +150 -0
  318. package/dist/session/helpers.d.ts.map +1 -0
  319. package/dist/session/helpers.js +472 -0
  320. package/dist/session/hibernation.d.ts +145 -0
  321. package/dist/session/hibernation.d.ts.map +1 -0
  322. package/dist/session/hibernation.js +385 -0
  323. package/dist/session/init-phases.d.ts +87 -0
  324. package/dist/session/init-phases.d.ts.map +1 -0
  325. package/dist/session/init-phases.js +137 -0
  326. package/dist/session/init.d.ts +46 -0
  327. package/dist/session/init.d.ts.map +1 -0
  328. package/dist/session/init.js +3579 -0
  329. package/dist/session/keys.d.ts +56 -0
  330. package/dist/session/keys.d.ts.map +1 -0
  331. package/dist/session/keys.js +55 -0
  332. package/dist/session/nimbus-session.d.ts +434 -0
  333. package/dist/session/nimbus-session.d.ts.map +1 -0
  334. package/dist/session/nimbus-session.js +1084 -0
  335. package/dist/session/programmatic.d.ts +105 -0
  336. package/dist/session/programmatic.d.ts.map +1 -0
  337. package/dist/session/programmatic.js +326 -0
  338. package/dist/session/replica-routes.d.ts +68 -0
  339. package/dist/session/replica-routes.d.ts.map +1 -0
  340. package/dist/session/replica-routes.js +77 -0
  341. package/dist/session/routes.d.ts +29 -0
  342. package/dist/session/routes.d.ts.map +1 -0
  343. package/dist/session/routes.js +1331 -0
  344. package/dist/session/rpc.d.ts +323 -0
  345. package/dist/session/rpc.d.ts.map +1 -0
  346. package/dist/session/rpc.js +808 -0
  347. package/dist/session/state-store.d.ts +210 -0
  348. package/dist/session/state-store.d.ts.map +1 -0
  349. package/dist/session/state-store.js +459 -0
  350. package/dist/session/supervisor-rpc.d.ts +269 -0
  351. package/dist/session/supervisor-rpc.d.ts.map +1 -0
  352. package/dist/session/supervisor-rpc.js +437 -0
  353. package/dist/session/ws-hibernation-config.d.ts +64 -0
  354. package/dist/session/ws-hibernation-config.d.ts.map +1 -0
  355. package/dist/session/ws-hibernation-config.js +89 -0
  356. package/dist/session/ws.d.ts +95 -0
  357. package/dist/session/ws.d.ts.map +1 -0
  358. package/dist/session/ws.js +395 -0
  359. package/dist/shell/features.d.ts +410 -0
  360. package/dist/shell/features.d.ts.map +1 -0
  361. package/dist/shell/features.js +1885 -0
  362. package/dist/shell/unix-commands.d.ts +15 -0
  363. package/dist/shell/unix-commands.d.ts.map +1 -0
  364. package/dist/shell/unix-commands.js +3703 -0
  365. package/dist/stubs/lifo-ui.d.ts +10 -0
  366. package/dist/stubs/lifo-ui.d.ts.map +1 -0
  367. package/dist/stubs/lifo-ui.js +1 -0
  368. package/dist/tailwind-play.generated.d.ts +19 -0
  369. package/dist/tailwind-play.generated.d.ts.map +1 -0
  370. package/dist/tailwind-play.generated.js +18 -0
  371. package/dist/vfs/dev-provider.d.ts +64 -0
  372. package/dist/vfs/dev-provider.d.ts.map +1 -0
  373. package/dist/vfs/dev-provider.js +191 -0
  374. package/dist/vfs/events.d.ts +51 -0
  375. package/dist/vfs/events.d.ts.map +1 -0
  376. package/dist/vfs/events.js +127 -0
  377. package/dist/vfs/path.d.ts +30 -0
  378. package/dist/vfs/path.d.ts.map +1 -0
  379. package/dist/vfs/path.js +41 -0
  380. package/dist/vfs/seed-project.d.ts +62 -0
  381. package/dist/vfs/seed-project.d.ts.map +1 -0
  382. package/dist/vfs/seed-project.js +1045 -0
  383. package/dist/vfs/sqlite-vfs.d.ts +435 -0
  384. package/dist/vfs/sqlite-vfs.d.ts.map +1 -0
  385. package/dist/vfs/sqlite-vfs.js +1670 -0
  386. package/dist/vfs/symlink-registry.d.ts +64 -0
  387. package/dist/vfs/symlink-registry.d.ts.map +1 -0
  388. package/dist/vfs/symlink-registry.js +137 -0
  389. package/dist/wrangler/nimbus-wrangler.d.ts +157 -0
  390. package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -0
  391. package/dist/wrangler/nimbus-wrangler.js +931 -0
  392. package/package.json +77 -0
  393. package/public/_assets/cirrus-plugin-react.bundle.js +70740 -0
  394. package/public/_assets/esbuild-0.24.2.wasm +0 -0
  395. package/public/_assets/real-vite-bundle.js +101478 -0
  396. package/public/_assets/rollup.wasm +0 -0
  397. package/public/favicon.svg +8 -0
  398. package/public/index.html +565 -0
  399. package/public/s/index.html +2379 -0
  400. package/scripts/bundle-esbuild-wasm.mjs +244 -0
  401. package/scripts/bundle-facet-workers.mjs +137 -0
  402. package/scripts/bundle-git.mjs +118 -0
  403. package/scripts/bundle-npm-cjs.mjs +363 -0
  404. package/scripts/bundle-plugin-react.mjs +480 -0
  405. package/scripts/bundle-real-vite.mjs +959 -0
  406. package/scripts/bundle-runtime.mjs +600 -0
  407. package/scripts/bundle-tailwind-play.mjs +130 -0
  408. package/scripts/patch-lifo-ui.mjs +131 -0
@@ -0,0 +1,737 @@
1
+ /**
2
+ * ruby-runner.ts — ruby.wasm (Ruby 3.3.x) runner.
3
+ *
4
+ * Mirror of python-runner.ts patterns adapted to Ruby's wasi-vfs +
5
+ * canonical-abi binding. v1 scope:
6
+ * - `ruby --version` / `ruby -e '<code>'` / `ruby <file.rb>`
7
+ * - stdout/stderr → processLogs (Process tab integration)
8
+ * - exit code via `exit N` / unhandled exception → 1
9
+ * - argv passed through to ARGV; $PROGRAM_NAME / $0 set
10
+ * - stdlib loaded from the packed wasi-vfs inside the wasm
11
+ *
12
+ * Out of v1:
13
+ * - REPL mode (`ruby` with no args)
14
+ * - require_relative for non-bundled files (basic require for
15
+ * stdlib works since stdlib is wasi-vfs-packed inside the wasm)
16
+ * - gems, bundler
17
+ * - js-runtime bindings (gem "js") — those imports are stubbed
18
+ * and will raise NotImplementedError if Ruby code tries to use
19
+ * them
20
+ *
21
+ * Architecture: SAME LOADER-modules transport as python-runner / wasm-
22
+ * runner. ruby+stdlib.wasm bytes ship via the LOADER `modules` map
23
+ * (workerd compiles at child-facet module-init time, where CSP
24
+ * permits). Per-user-VFS path: ~/.nimbus/runtimes/ruby/3.3.4/share/ruby/.
25
+ *
26
+ * Per /workspace/.seal-internal/2026-05-11-ruby-v1/audit.md:
27
+ * - Wasm size 34.3 MiB (well under empirical 32 MiB-ish per-call
28
+ * ceiling we cleared with Pyodide + clang).
29
+ * - 35 wasi_snapshot_preview1 imports (provided by wasi-instance.ts).
30
+ * - 21 rb-js-abi-host imports (stubbed throw-when-called — none fire
31
+ * for v1 `puts "hi"`).
32
+ * - 3 canonical_abi imports (resource lifecycle — implemented as
33
+ * a minimal Slab<number,object>).
34
+ * - Exports: _initialize, __wasi_vfs_rt_init, ruby-init,
35
+ * ruby-init-loadpath, rb-eval-string-protect, cabi_realloc,
36
+ * canonical_abi_drop_rb-abi-value, memory.
37
+ */
38
+ import { WASI_INSTANCE_PREAMBLE_SRC } from './wasi-instance.js';
39
+ /**
40
+ * Build the ruby-runner factory. Called once at session init; the
41
+ * returned factory binds the manifest + install root for each
42
+ * registered entrypoint (`ruby`, `ruby3`).
43
+ */
44
+ export function makeRubyRunnerFactory(deps) {
45
+ const { facetMgr, vfs } = deps;
46
+ return function rubyRunnerFactory(manifest, installRoot, binName, _binKind) {
47
+ const findFile = (rel) => {
48
+ const entry = manifest.files.find((f) => f.path === rel);
49
+ return entry ? `${installRoot}/${entry.path}` : null;
50
+ };
51
+ const wasmVfs = findFile('share/ruby/ruby+stdlib.wasm');
52
+ return async function rubyBinHandler(ctx) {
53
+ const argv = ctx.args || [];
54
+ const cwd = ctx.cwd || '/home/user';
55
+ // --version / --help fast paths (no wasm boot).
56
+ if (argv.includes('--version') || argv.includes('-v')) {
57
+ // 3.3.x — ruby.wasm 2.9.3-2.9.4 ships Ruby 3.3.4 per upstream
58
+ // release notes. The string format matches `ruby --version`
59
+ // shape (parsed by tooling like rbenv).
60
+ ctx.stdout.write(`ruby 3.3.4 (2024-04-23 revision wasm) [wasm32-wasi]\n`);
61
+ return 0;
62
+ }
63
+ if (argv.includes('--help') || argv.includes('-h')) {
64
+ ctx.stdout.write(`Usage: ${binName} [switches] [--] [programfile] [arguments]\n`);
65
+ ctx.stdout.write(`Nimbus Ruby 3.3.4 runtime (ruby.wasm 2.9.3-2.9.4).\n`);
66
+ ctx.stdout.write(`Supported v1: -e <code>, <file.rb>, -r <lib>\n`);
67
+ ctx.stdout.write(`Not supported: REPL (no args), gem, bundler, js-runtime\n`);
68
+ return 0;
69
+ }
70
+ // Resolve install bytes.
71
+ if (!wasmVfs || !vfs.exists(wasmVfs)) {
72
+ ctx.stderr.write(`${binName}: ruby+stdlib.wasm missing (re-run 'nimbus install ruby')\n`);
73
+ return 127;
74
+ }
75
+ const wasmBytes = vfs.readFile(wasmVfs);
76
+ // Parse argv.
77
+ const parsed = parseRubyArgv(argv);
78
+ if (parsed.error) {
79
+ ctx.stderr.write(`${binName}: ${parsed.error}\n`);
80
+ return parsed.exitCode;
81
+ }
82
+ // Build user program text + ARGV per mode.
83
+ let userCode = '';
84
+ let progName = binName;
85
+ let rbArgv = [binName];
86
+ if (parsed.mode === 'inline') {
87
+ userCode = parsed.inlineCode;
88
+ progName = '-e';
89
+ rbArgv = ['-e', ...parsed.scriptArgs];
90
+ }
91
+ else if (parsed.mode === 'script') {
92
+ const absPath = resolveVfsPath(parsed.scriptPath, cwd);
93
+ if (!vfs.exists(absPath)) {
94
+ ctx.stderr.write(`${binName}: No such file or directory -- ${parsed.scriptPath} (LoadError)\n`);
95
+ return 1;
96
+ }
97
+ try {
98
+ userCode = new TextDecoder('utf-8').decode(vfs.readFile(absPath));
99
+ }
100
+ catch (e) {
101
+ ctx.stderr.write(`${binName}: ${parsed.scriptPath}: ${e?.message || e}\n`);
102
+ return 1;
103
+ }
104
+ progName = parsed.scriptPath;
105
+ rbArgv = [parsed.scriptPath, ...parsed.scriptArgs];
106
+ }
107
+ // -r flags add prelude `require '<lib>'` lines (stdlib only).
108
+ const preludeRequires = parsed.requires.map((r) => `require ${JSON.stringify(r)}`).join('\n');
109
+ if (preludeRequires) {
110
+ userCode = preludeRequires + '\n' + userCode;
111
+ }
112
+ const userEnv = { ...(ctx.env || {}) };
113
+ if (!userEnv.HOME)
114
+ userEnv.HOME = '/home/ruby';
115
+ if (!userEnv.LANG)
116
+ userEnv.LANG = 'C.UTF-8';
117
+ // Ruby looks for charset hints via these vars; set sensible
118
+ // defaults so puts of non-ASCII strings doesn't trip on the
119
+ // wasi default of "ASCII-8BIT".
120
+ if (!userEnv.LC_ALL)
121
+ userEnv.LC_ALL = 'C.UTF-8';
122
+ // Dispatch the facet.
123
+ const result = await dispatchRubyFacet(facetMgr, {
124
+ wasmBytes,
125
+ userCode,
126
+ rbArgv,
127
+ userEnv,
128
+ progName,
129
+ });
130
+ if (result.stdout)
131
+ ctx.stdout.write(result.stdout);
132
+ if (result.stderr)
133
+ ctx.stderr.write(result.stderr);
134
+ if (result.error) {
135
+ ctx.stderr.write(`${binName}: ${result.error}\n`);
136
+ return 1;
137
+ }
138
+ return result.exitCode;
139
+ };
140
+ };
141
+ }
142
+ function parseRubyArgv(argv) {
143
+ // Ruby's CLI is rich; v1 handles -e, -r, and positional script.
144
+ const requires = [];
145
+ let i = 0;
146
+ while (i < argv.length) {
147
+ const a = argv[i];
148
+ if (a === '-e') {
149
+ const code = argv[i + 1];
150
+ if (code === undefined) {
151
+ return { mode: 'inline', inlineCode: '', scriptPath: '', scriptArgs: [],
152
+ requires, exitCode: 2, error: "no code specified for -e (RuntimeError)" };
153
+ }
154
+ // -e <code> [args...] — code into program, rest into ARGV.
155
+ // Note: Ruby allows multiple -e; concatenated with \n.
156
+ let concat = code;
157
+ let j = i + 2;
158
+ while (j < argv.length && argv[j] === '-e') {
159
+ const more = argv[j + 1];
160
+ if (more === undefined) {
161
+ return { mode: 'inline', inlineCode: '', scriptPath: '', scriptArgs: [],
162
+ requires, exitCode: 2, error: "no code specified for -e (RuntimeError)" };
163
+ }
164
+ concat = concat + '\n' + more;
165
+ j += 2;
166
+ }
167
+ return {
168
+ mode: 'inline',
169
+ inlineCode: concat,
170
+ scriptPath: '',
171
+ scriptArgs: argv.slice(j),
172
+ requires,
173
+ exitCode: 0,
174
+ };
175
+ }
176
+ if (a === '-r') {
177
+ const lib = argv[i + 1];
178
+ if (lib === undefined) {
179
+ return { mode: 'inline', inlineCode: '', scriptPath: '', scriptArgs: [],
180
+ requires, exitCode: 2, error: "missing argument for -r" };
181
+ }
182
+ requires.push(lib);
183
+ i += 2;
184
+ continue;
185
+ }
186
+ if (a.startsWith('-r') && a.length > 2) {
187
+ // -rjson form (no space).
188
+ requires.push(a.slice(2));
189
+ i++;
190
+ continue;
191
+ }
192
+ if (!a.startsWith('-')) {
193
+ return {
194
+ mode: 'script',
195
+ inlineCode: '',
196
+ scriptPath: a,
197
+ scriptArgs: argv.slice(i + 1),
198
+ requires,
199
+ exitCode: 0,
200
+ };
201
+ }
202
+ // Unknown flag — v1 silently ignores common harmless ones, errors on others.
203
+ if (/^-[wWdEKUI]+$/.test(a)) {
204
+ i++;
205
+ continue;
206
+ }
207
+ if (a === '--disable-gems' || a === '--enable-gems') {
208
+ i++;
209
+ continue;
210
+ }
211
+ return { mode: 'inline', inlineCode: '', scriptPath: '', scriptArgs: [],
212
+ requires, exitCode: 2, error: `invalid option: ${a}` };
213
+ }
214
+ return { mode: 'inline', inlineCode: '', scriptPath: '', scriptArgs: [],
215
+ requires, exitCode: 2, error: "REPL not supported in v1. Use 'ruby -e \"code\"' or 'ruby script.rb'." };
216
+ }
217
+ function resolveVfsPath(rel, cwd) {
218
+ const cwdN = cwd.replace(/^\/+/, '').replace(/\/+$/, '');
219
+ if (rel.startsWith('/'))
220
+ return rel.replace(/^\/+/, '');
221
+ if (rel === '.')
222
+ return cwdN;
223
+ return `${cwdN}/${rel}`;
224
+ }
225
+ async function dispatchRubyFacet(facetMgr, args) {
226
+ const toAB = (u8) => u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength);
227
+ // The Ruby preamble runs the entire bootstrap at child-facet module-
228
+ // init time (same architecture as Pyodide v2). The wasm Module is
229
+ // instantiated synchronously where workerd permits, _initialize +
230
+ // ruby-init-loadpath + ruby-init run, and the live instance is
231
+ // cached on globalThis.__rubyInstance for per-call use.
232
+ //
233
+ // The preamble also includes WASI_INSTANCE_PREAMBLE_SRC so
234
+ // __wasiMakeImports / __wasiInitFS / __wasiRunStart are in scope.
235
+ const preamble = buildRubyPreamble();
236
+ const { NimbusLoaderPool } = await import('../loaders/loader-pool.js');
237
+ const env = facetMgr.env;
238
+ const ctx = facetMgr.ctx;
239
+ const pool = new NimbusLoaderPool(env, ctx, {
240
+ tag: 'ruby-runner',
241
+ concurrency: 1,
242
+ omitSupervisor: true,
243
+ preamble,
244
+ });
245
+ const facetFn = async function rubyFacetCall(inArgs) {
246
+ const fn = globalThis.__rubyRun;
247
+ if (typeof fn !== 'function') {
248
+ return { exitCode: 127, stdout: '', stderr: '',
249
+ error: 'ruby-runner preamble missing: __rubyRun not in scope' };
250
+ }
251
+ return await fn({
252
+ userCode: inArgs.userCode,
253
+ rbArgv: inArgs.rbArgv,
254
+ userEnv: inArgs.userEnv,
255
+ progName: inArgs.progName,
256
+ });
257
+ };
258
+ try {
259
+ const result = await pool.submit(facetFn, {
260
+ userCode: args.userCode,
261
+ rbArgv: args.rbArgv,
262
+ userEnv: args.userEnv,
263
+ progName: args.progName,
264
+ }, {
265
+ wasmModules: {
266
+ 'ruby+stdlib.wasm': toAB(args.wasmBytes),
267
+ },
268
+ timeoutMs: 300_000,
269
+ });
270
+ return {
271
+ exitCode: result.exitCode,
272
+ stdout: result.stdout || '',
273
+ stderr: result.stderr || '',
274
+ error: result.error,
275
+ };
276
+ }
277
+ catch (e) {
278
+ return {
279
+ exitCode: 1,
280
+ stdout: '',
281
+ stderr: '',
282
+ error: `ruby-runner dispatch failed: ${e?.message || e}`,
283
+ };
284
+ }
285
+ }
286
+ /**
287
+ * Compose the per-call preamble. The preamble runs at child-facet
288
+ * module-init time; it instantiates ruby+stdlib.wasm via the LOADER-
289
+ * provided WebAssembly.Module and bootstraps the Ruby VM. Per-call
290
+ * __rubyRun then drives `rb-eval-string-protect` for each request.
291
+ */
292
+ function buildRubyPreamble() {
293
+ return [
294
+ '// ── WASI shim preamble (wasi-instance.ts) ─────────────────────',
295
+ WASI_INSTANCE_PREAMBLE_SRC,
296
+ '',
297
+ '// ── FinalizationRegistry shim ─────────────────────────────────',
298
+ '// Ruby ABI guest uses FinalizationRegistry for resource cleanup.',
299
+ '// workerd does not always expose it (compat-flag gated). Same',
300
+ '// no-op pattern as python-runner v2 — leaky but acceptable for',
301
+ '// per-call facet lifetime (each invocation spawns a fresh facet).',
302
+ 'if (typeof globalThis.FinalizationRegistry === "undefined") {',
303
+ ' globalThis.FinalizationRegistry = class FinalizationRegistry {',
304
+ ' constructor(_cleanup) {}',
305
+ ' register(_target, _heldValue, _token) {}',
306
+ ' unregister(_token) {}',
307
+ ' };',
308
+ '}',
309
+ '',
310
+ RUBY_RUNNER_PREAMBLE_TAIL,
311
+ ].join('\n');
312
+ }
313
+ /**
314
+ * The Ruby-specific portion of the preamble. Wires the wasm imports
315
+ * (wasi_snapshot_preview1 from __wasiMakeImports, canonical_abi from a
316
+ * tiny Slab implementation, rb-js-abi-host as stubs that throw on
317
+ * call), instantiates the wasm Module from __NIMBUS_WASM at module-
318
+ * init, and runs Ruby's bootstrap sequence.
319
+ *
320
+ * Per-call __rubyRun then mutates WASI argv/env, clears the stdout/
321
+ * stderr capture buffers, and invokes rb-eval-string-protect with a
322
+ * wrapper that captures SystemExit to extract the exit code.
323
+ */
324
+ export const RUBY_RUNNER_PREAMBLE_TAIL = `
325
+ // ── BEGIN: ruby-runner preamble (Ruby 3.3.4, Nimbus v1) ─────────────
326
+
327
+ // Capture buffers shared across the bootstrap and per-call paths. The
328
+ // preamble's WASI imports route fd_write stdout/stderr into these via
329
+ // __wasiMakeImports({stdoutWrite, stderrWrite}). Per-call __rubyRun
330
+ // slices from these to isolate output per invocation.
331
+ globalThis.__nimbusRubyStdout = globalThis.__nimbusRubyStdout || [];
332
+ globalThis.__nimbusRubyStderr = globalThis.__nimbusRubyStderr || [];
333
+
334
+ // ── Canonical-ABI resource Slab ────────────────────────────────────
335
+ // Pyodide-style minimal resource manager. Ruby's rb-abi-guest.js uses
336
+ // these 4 functions for resource_drop / resource_new / resource_get /
337
+ // resource_clone, but the wasm itself only imports 3:
338
+ // resource_drop_js-abi-value, resource_new_rb-abi-value, resource_get_rb-abi-value
339
+ class __NimbusRubySlab {
340
+ constructor() { this._map = new Map(); this._next = 1; }
341
+ insert(obj) { const id = this._next++; this._map.set(id, obj); return id; }
342
+ get(id) { return this._map.get(id); }
343
+ remove(id) { const v = this._map.get(id); this._map.delete(id); return v; }
344
+ }
345
+
346
+ // ── Bootstrap promise: runs at child-facet module-init time ────────
347
+ //
348
+ // Mirrors pyodide v2's __pyodideBootstrap pattern. The synchronous
349
+ // portion (WebAssembly.instantiate + _initialize + ruby-init-loadpath
350
+ // + ruby-init) all completes before the first await — so it executes
351
+ // in module-init CSP context where workerd permits wasm code-gen
352
+ // from the LOADER-provided Module.
353
+ globalThis.__rubyBootstrap = (async function nimbusRubyBootstrap() {
354
+ const wasmTable = globalThis.__NIMBUS_WASM || {};
355
+ const rubyMod = wasmTable['ruby+stdlib.wasm'];
356
+ if (!rubyMod) {
357
+ return { ok: false, error: '__NIMBUS_WASM missing ruby+stdlib.wasm' };
358
+ }
359
+
360
+ // WASI init — empty preopens initially. Per-call __rubyRun can mount
361
+ // a cwd preopen if needed (for ruby <file.rb> reading via WASI).
362
+ // For v1 (-e mode) we just need stdout/stderr capture + a minimal
363
+ // FS so Ruby's stdlib init (which probes /tmp + $HOME) doesn't crash.
364
+ __wasiInitFS({
365
+ root: '',
366
+ preopens: [
367
+ // Preopen / so Ruby can resolve all FS paths through WASI.
368
+ // Ruby's __wasi_vfs_rt_init mounts its packed stdlib under /usr
369
+ // inside the wasm's internal VFS — these preopens are for the
370
+ // OUTER (host-visible) FS that wasi_snapshot_preview1 exposes.
371
+ { wasiPath: '/', vfsPath: '' },
372
+ { wasiPath: '/tmp', vfsPath: 'tmp' },
373
+ { wasiPath: '/home', vfsPath: 'home' },
374
+ ],
375
+ files: {},
376
+ dirs: ['tmp', 'home'],
377
+ });
378
+
379
+ // Initial argv/env (bootstrap defaults). Per-call __rubyRun re-
380
+ // initializes WASI with the actual user argv/env before evaluating
381
+ // user code.
382
+ let memRef = null;
383
+ const wasi = __wasiMakeImports({
384
+ argv: ['ruby'],
385
+ env: { HOME: '/home/ruby', LANG: 'C.UTF-8', LC_ALL: 'C.UTF-8' },
386
+ getMemory: () => memRef,
387
+ stdoutWrite: (s) => { globalThis.__nimbusRubyStdout.push(s); },
388
+ stderrWrite: (s) => { globalThis.__nimbusRubyStderr.push(s); },
389
+ });
390
+
391
+ // canonical_abi imports — 3 resource lifecycle fns. The Slab is
392
+ // shared across the lifetime of the facet (single call, then the
393
+ // facet is reaped).
394
+ const rbValueSlab = new __NimbusRubySlab();
395
+ const jsValueSlab = new __NimbusRubySlab();
396
+ const canonical_abi = {
397
+ 'resource_drop_js-abi-value': (i) => { jsValueSlab.remove(i); },
398
+ 'resource_new_rb-abi-value': (i) => rbValueSlab.insert({ _wasm_val: i }),
399
+ 'resource_get_rb-abi-value': (i) => {
400
+ const r = rbValueSlab.get(i);
401
+ return r ? r._wasm_val : 0;
402
+ },
403
+ };
404
+
405
+ // rb-js-abi-host imports — 21 fns. Ruby only calls these when user
406
+ // code interacts with JS (gem "js"). For v1 (puts "hi") none fire.
407
+ // We stub each to throw a clear error so any future user code that
408
+ // needs JS interop gets a recognizable diagnostic instead of a
409
+ // wasm trap.
410
+ const _stub = (name) => () => { throw new Error('ruby-runner v1: rb-js-abi-host.' + name + ' not implemented (gem "js" not supported)'); };
411
+ const rb_js_abi_host = {
412
+ rb_wasm_throw_prohibit_rewind_exception: () => {
413
+ // This one CAN fire from Ruby internals (Fiber rewind guard).
414
+ // Make it a no-op so Ruby's continuation machinery proceeds.
415
+ },
416
+ 'eval-js: func(code: string) -> variant { success(handle<js-abi-value>), failure(handle<js-abi-value>) }': _stub('eval-js'),
417
+ 'is-js: func(value: handle<js-abi-value>) -> bool': _stub('is-js'),
418
+ 'instance-of: func(value: handle<js-abi-value>, klass: handle<js-abi-value>) -> bool': _stub('instance-of'),
419
+ 'global-this: func() -> handle<js-abi-value>': _stub('global-this'),
420
+ 'int-to-js-number: func(value: s32) -> handle<js-abi-value>': _stub('int-to-js-number'),
421
+ 'float-to-js-number: func(value: float64) -> handle<js-abi-value>': _stub('float-to-js-number'),
422
+ 'string-to-js-string: func(value: string) -> handle<js-abi-value>': _stub('string-to-js-string'),
423
+ 'bool-to-js-bool: func(value: bool) -> handle<js-abi-value>': _stub('bool-to-js-bool'),
424
+ 'proc-to-js-function: func(value: u32) -> handle<js-abi-value>': _stub('proc-to-js-function'),
425
+ 'rb-object-to-js-rb-value: func(raw-rb-abi-value: u32) -> handle<js-abi-value>': _stub('rb-object-to-js-rb-value'),
426
+ 'js-value-to-string: func(value: handle<js-abi-value>) -> string': _stub('js-value-to-string'),
427
+ 'js-value-to-integer: func(value: handle<js-abi-value>) -> variant { as-float(float64), bignum(string) }': _stub('js-value-to-integer'),
428
+ 'export-js-value-to-host: func(value: handle<js-abi-value>) -> ()': _stub('export-js-value-to-host'),
429
+ 'import-js-value-from-host: func() -> handle<js-abi-value>': _stub('import-js-value-from-host'),
430
+ 'js-value-typeof: func(value: handle<js-abi-value>) -> string': _stub('js-value-typeof'),
431
+ 'js-value-equal: func(lhs: handle<js-abi-value>, rhs: handle<js-abi-value>) -> bool': _stub('js-value-equal'),
432
+ 'js-value-strictly-equal: func(lhs: handle<js-abi-value>, rhs: handle<js-abi-value>) -> bool': _stub('js-value-strictly-equal'),
433
+ 'reflect-apply: func(target: handle<js-abi-value>, this-argument: handle<js-abi-value>, arguments: list<handle<js-abi-value>>) -> variant { success(handle<js-abi-value>), failure(handle<js-abi-value>) }': _stub('reflect-apply'),
434
+ 'reflect-get: func(target: handle<js-abi-value>, property-key: string) -> variant { success(handle<js-abi-value>), failure(handle<js-abi-value>) }': _stub('reflect-get'),
435
+ 'reflect-set: func(target: handle<js-abi-value>, property-key: string, value: handle<js-abi-value>) -> variant { success(handle<js-abi-value>), failure(handle<js-abi-value>) }': _stub('reflect-set'),
436
+ };
437
+
438
+ const imports = {
439
+ wasi_snapshot_preview1: wasi.wasiImport,
440
+ canonical_abi,
441
+ 'rb-js-abi-host': rb_js_abi_host,
442
+ };
443
+
444
+ let instance;
445
+ try {
446
+ const result = await WebAssembly.instantiate(rubyMod, imports);
447
+ instance = (result instanceof WebAssembly.Instance ? result : result.instance);
448
+ } catch (e) {
449
+ return { ok: false, error: 'WebAssembly.instantiate failed: ' + (e && e.message), stack: e && e.stack };
450
+ }
451
+ memRef = instance.exports.memory;
452
+
453
+ // ── Ruby bootstrap sequence ────────────────────────────────────
454
+ // Order matters (per ruby.wasm DefaultRubyVM):
455
+ // 1. _initialize (reactor entry; runs static initializers)
456
+ // 2. __wasi_vfs_rt_init (mount packed stdlib at the wasi-vfs's
457
+ // internal FS — needed for require to find Ruby's *.rb files)
458
+ // 3. ruby-init([progName]) — initialize VM with argv[0]
459
+ // 4. ruby-init-loadpath() — set $LOAD_PATH from packed stdlib
460
+ try {
461
+ if (typeof instance.exports._initialize === 'function') {
462
+ instance.exports._initialize();
463
+ }
464
+ if (typeof instance.exports.__wasi_vfs_rt_init === 'function') {
465
+ instance.exports.__wasi_vfs_rt_init();
466
+ }
467
+ } catch (e) {
468
+ return { ok: false, error: '_initialize/wasi_vfs_rt_init failed: ' + (e && e.message), stack: e && e.stack };
469
+ }
470
+
471
+ // Locate the canonical Ruby ABI exports. Names embed the WIT
472
+ // signature literal (e.g. 'ruby-init: func(args: list<string>) -> ()')
473
+ // because rb-abi-guest is wit-bindgen-generated.
474
+ const rubyInit = instance.exports['ruby-init: func(args: list<string>) -> ()'];
475
+ const rubyInitLoadpath = instance.exports['ruby-init-loadpath: func() -> ()'];
476
+ const rbEvalStringProtect = instance.exports['rb-eval-string-protect: func(str: string) -> tuple<handle<rb-abi-value>, s32>'];
477
+ const rubyShowVersion = instance.exports['ruby-show-version: func() -> ()'];
478
+ const cabiRealloc = instance.exports.cabi_realloc;
479
+ if (!rubyInit || !rubyInitLoadpath || !rbEvalStringProtect || !cabiRealloc) {
480
+ return { ok: false, error: 'Required Ruby ABI exports missing (ruby-init/init-loadpath/eval-string-protect/cabi_realloc)' };
481
+ }
482
+
483
+ // Encode a list<string> argument for ruby-init. WIT canonical-ABI
484
+ // shape: caller allocates list buffer; each element is (ptr, len).
485
+ // Strings are UTF-8 encoded into separately-allocated buffers.
486
+ function writeListString(strings) {
487
+ const memory = instance.exports.memory;
488
+ const enc = new TextEncoder();
489
+ const len = strings.length;
490
+ const listBufPtr = cabiRealloc(0, 0, 4, len * 8); // align=4, size=len*8
491
+ const encoded = strings.map((s) => enc.encode(s));
492
+ for (let i = 0; i < len; i++) {
493
+ const bytes = encoded[i];
494
+ const strPtr = cabiRealloc(0, 0, 1, bytes.length);
495
+ new Uint8Array(memory.buffer).set(bytes, strPtr);
496
+ const dv = new DataView(memory.buffer);
497
+ dv.setUint32(listBufPtr + i * 8 + 0, strPtr, true);
498
+ dv.setUint32(listBufPtr + i * 8 + 4, bytes.length, true);
499
+ }
500
+ return { ptr: listBufPtr, len };
501
+ }
502
+
503
+ function writeString(s) {
504
+ const memory = instance.exports.memory;
505
+ const enc = new TextEncoder();
506
+ const bytes = enc.encode(s);
507
+ const ptr = cabiRealloc(0, 0, 1, bytes.length);
508
+ new Uint8Array(memory.buffer).set(bytes, ptr);
509
+ return { ptr, len: bytes.length };
510
+ }
511
+
512
+ // NOTE: We DO NOT call ruby-init or ruby-init-loadpath here. Both
513
+ // invoke CPython-like random-seed initialization (random_get via
514
+ // wasi_snapshot_preview1.random_get), which workerd blocks in the
515
+ // global-scope (module-init) context. Same constraint that bit us
516
+ // for Pyodide v2 P21. The per-call __rubyRun runs them at request-
517
+ // handler time where crypto.getRandomValues is permitted.
518
+ //
519
+ // _initialize and __wasi_vfs_rt_init are safe at module-init because
520
+ // they only do static initialization (no entropy reads).
521
+
522
+ return {
523
+ ok: true,
524
+ instance,
525
+ wasi,
526
+ rubyInit,
527
+ rubyInitLoadpath,
528
+ rbEvalStringProtect,
529
+ rubyShowVersion,
530
+ writeListString,
531
+ writeString,
532
+ rubyInitialized: false, // mutated to true by __rubyRun on first call
533
+ };
534
+ })();
535
+
536
+ // ── Per-call entry point ───────────────────────────────────────────
537
+ //
538
+ // Invoked from the LOADER child facet's execute() (which calls the
539
+ // serialized facetFn that does globalThis.__rubyRun(args)).
540
+ //
541
+ // At this point the bootstrap promise has resolved (since it's
542
+ // awaited inside the child facet's module-init context — the
543
+ // instantiate finishes before the request handler runs). We:
544
+ // 1. Update Ruby's $0 / $PROGRAM_NAME / ARGV via rb-eval-string-protect
545
+ // 2. Wrap the user code in a begin/rescue SystemExit/StandardError
546
+ // handler so we can extract exit code without losing stdout
547
+ // 3. Read stdout/stderr buffers and slice from the per-call start
548
+ globalThis.__rubyRun = async function __rubyRun(args) {
549
+ const stdoutStart = globalThis.__nimbusRubyStdout.length;
550
+ const stderrStart = globalThis.__nimbusRubyStderr.length;
551
+
552
+ const boot = await globalThis.__rubyBootstrap;
553
+ if (!boot.ok) {
554
+ return {
555
+ exitCode: 1,
556
+ stdout: globalThis.__nimbusRubyStdout.slice(stdoutStart).join(''),
557
+ stderr: globalThis.__nimbusRubyStderr.slice(stderrStart).join(''),
558
+ error: 'ruby bootstrap failed: ' + (boot.error || 'unknown') + (boot.stack ? ' [stack=' + boot.stack + ']' : ''),
559
+ };
560
+ }
561
+
562
+ // First call into __rubyRun: complete Ruby VM init (ruby-init +
563
+ // ruby-init-loadpath) now that we're in request-handler context
564
+ // where crypto.getRandomValues is permitted. Subsequent calls skip.
565
+ if (!boot.rubyInitialized) {
566
+ try {
567
+ const initArgs = boot.writeListString(['ruby', '-e_=0']);
568
+ boot.rubyInit(initArgs.ptr, initArgs.len);
569
+ boot.rubyInitLoadpath();
570
+ boot.rubyInitialized = true;
571
+ } catch (e) {
572
+ return {
573
+ exitCode: 1,
574
+ stdout: globalThis.__nimbusRubyStdout.slice(stdoutStart).join(''),
575
+ stderr: globalThis.__nimbusRubyStderr.slice(stderrStart).join(''),
576
+ error: 'ruby-init / ruby-init-loadpath failed at request time: ' + (e && e.message),
577
+ };
578
+ }
579
+ }
580
+
581
+ // Wrapper code: set $0/$PROGRAM_NAME/ARGV/ENV, run user code,
582
+ // capture SystemExit. We embed the user code as a Ruby string
583
+ // literal via JSON.stringify (Ruby's double-quote strings accept
584
+ // \\n \\t etc which JSON also emits — safe round-trip).
585
+ //
586
+ // The wrapper sets __NIMBUS_RUBY_EXIT to the desired exit code so
587
+ // we can read it via a second rb-eval-string-protect call. Failing
588
+ // SystemExit (raise) ends up with __NIMBUS_RUBY_EXIT = 1 + stderr
589
+ // message.
590
+ const userCodeRb = JSON.stringify(args.userCode);
591
+ const argvRb = JSON.stringify(args.rbArgv.slice(1)); // exclude argv[0]
592
+ const envRb = JSON.stringify(args.userEnv || {});
593
+ const progNameRb = JSON.stringify(args.progName);
594
+
595
+ // STAGED execution: we split the prelude (stdout sync + ARGV/ENV/$0
596
+ // setup) from the user-code eval. The prelude has no failure modes
597
+ // we care about; user-code is wrapped in begin/rescue for SystemExit
598
+ // and Exception. If the wrapper itself trips a syntax/runtime error,
599
+ // we surface it via the __NIMBUS_RUBY_DIAG side channel.
600
+ // Build env list as string-keyed Ruby hash via the rocket-syntax.
601
+ // Ruby treats colon-style hash literals as Symbol-keyed; we need
602
+ // String keys so ENV[k] = v works without TypeError.
603
+ const envEntries = Object.entries(args.userEnv || {})
604
+ .map(([k, v]) => JSON.stringify(k) + ' => ' + JSON.stringify(v))
605
+ .join(', ');
606
+ const envHashRb = '{' + envEntries + '}';
607
+
608
+ const preludeRb = [
609
+ // Reset exit state FIRST so partial prelude failures still
610
+ // surface a clean exit code (previously: exit 7 left $__nimbus_exit
611
+ // = 7 → next call's prelude could fail before resetting → second
612
+ // exit 0 returned 7).
613
+ '$__nimbus_exit = 0',
614
+ '$stdout.sync = true',
615
+ '$stderr.sync = true',
616
+ '$0 = ' + progNameRb,
617
+ '$PROGRAM_NAME = ' + progNameRb,
618
+ 'ARGV.replace(' + argvRb + ')',
619
+ envHashRb + '.each_pair { |k, v| ENV[k] = v }',
620
+ ].join('; ');
621
+
622
+ const userWrapper = [
623
+ 'begin',
624
+ ' ' + 'eval(' + userCodeRb + ', TOPLEVEL_BINDING, ' + progNameRb + ', 1)',
625
+ 'rescue SystemExit => e',
626
+ ' $__nimbus_exit = e.status',
627
+ 'rescue Exception => e',
628
+ ' $stderr.write(e.full_message(highlight: false, order: :top))',
629
+ ' $__nimbus_exit = 1',
630
+ 'ensure',
631
+ ' $stdout.flush rescue nil',
632
+ ' $stderr.flush rescue nil',
633
+ 'end',
634
+ ].join("\\n");
635
+
636
+ const memory = boot.instance.exports.memory;
637
+
638
+ function callEvalStringProtect(rubyCode) {
639
+ const enc = new TextEncoder();
640
+ const bytes = enc.encode(rubyCode);
641
+ const cabiRealloc = boot.instance.exports.cabi_realloc;
642
+ const codePtr = cabiRealloc(0, 0, 1, bytes.length);
643
+ new Uint8Array(memory.buffer).set(bytes, codePtr);
644
+ const retPtr = boot.rbEvalStringProtect(codePtr, bytes.length);
645
+ // Return is a tuple: (rb-abi-value handle u32, status s32) — 8 bytes
646
+ const dv = new DataView(memory.buffer);
647
+ const handle = dv.getUint32(retPtr + 0, true);
648
+ const status = dv.getInt32(retPtr + 4, true);
649
+ return { handle, status };
650
+ }
651
+
652
+ // Stage 1: run the prelude (sync flags, ARGV, ENV, $0/$PROGRAM_NAME).
653
+ let preludeStatus;
654
+ try {
655
+ preludeStatus = callEvalStringProtect(preludeRb);
656
+ } catch (e) {
657
+ return {
658
+ exitCode: 1,
659
+ stdout: globalThis.__nimbusRubyStdout.slice(stdoutStart).join(''),
660
+ stderr: globalThis.__nimbusRubyStderr.slice(stderrStart).join(''),
661
+ error: 'ruby prelude threw: ' + (e && e.message),
662
+ };
663
+ }
664
+ if (preludeStatus && preludeStatus.status !== 0) {
665
+ globalThis.__nimbusRubyStderr.push('[ruby-runner-diag] prelude returned non-zero status: ' + preludeStatus.status + '\\n');
666
+ }
667
+
668
+ // Stage 2: run user code wrapped for SystemExit/Exception capture.
669
+ let evalStatus;
670
+ try {
671
+ evalStatus = callEvalStringProtect(userWrapper);
672
+ } catch (e) {
673
+ return {
674
+ exitCode: 1,
675
+ stdout: globalThis.__nimbusRubyStdout.slice(stdoutStart).join(''),
676
+ stderr: globalThis.__nimbusRubyStderr.slice(stderrStart).join(''),
677
+ error: 'rb-eval-string-protect threw: ' + (e && e.message),
678
+ };
679
+ }
680
+ if (evalStatus && evalStatus.status !== 0) {
681
+ globalThis.__nimbusRubyStderr.push('[ruby-runner-diag] user wrapper returned non-zero status: ' + evalStatus.status + '\\n');
682
+ }
683
+
684
+ // Read $__nimbus_exit by evaluating it and inspecting the result
685
+ // via Ruby's puts (captured into stderr). Simpler: call exit through
686
+ // rb-eval-string-protect and parse the status code from there.
687
+ //
688
+ // Actually rbEvalStringProtect already returns a status (second
689
+ // tuple element). When the wrapper completes normally, status is 0
690
+ // and we read $__nimbus_exit. We use a follow-up eval that prints
691
+ // the exit code to a sentinel marker on stderr we can scrape, but
692
+ // a cleaner approach: have the wrapper's last expression BE the
693
+ // exit code (so it's the return value of eval).
694
+ //
695
+ // Re-do: eval $__nimbus_exit and read it from a marker line we
696
+ // emit to a side channel — easiest is to call $stdout via a unique
697
+ // marker that we then strip from output.
698
+ const NIMBUS_EXIT_MARKER = '__NIMBUS_RUBY_EXIT_';
699
+ let exitCode = 0;
700
+ try {
701
+ // Print the marker + exit code to stderr (a side channel separate
702
+ // from user-visible stdout). We strip it before returning.
703
+ callEvalStringProtect(
704
+ '$stderr.write(' + JSON.stringify(NIMBUS_EXIT_MARKER) + ' + $__nimbus_exit.to_s + "\\\\n")'
705
+ );
706
+ // Scrape the marker from stderr buffer — using ONLY this call's
707
+ // slice (from stderrStart). The same facet can be reused across
708
+ // multiple __rubyRun invocations (loader-pool dedup by tag), so
709
+ // a previous call's marker would otherwise be matched first.
710
+ const callStderr = globalThis.__nimbusRubyStderr.slice(stderrStart).join('');
711
+ // Match the LAST marker in this slice (the one our just-completed
712
+ // call emitted; if the user wrapper also emitted writes, the
713
+ // marker is appended after them).
714
+ const markerRe = new RegExp(NIMBUS_EXIT_MARKER + '(-?\\\\d+)', 'g');
715
+ let lastMatch = null;
716
+ let mit;
717
+ while ((mit = markerRe.exec(callStderr)) !== null) lastMatch = mit;
718
+ if (lastMatch) exitCode = parseInt(lastMatch[1], 10);
719
+ } catch (e) {
720
+ // Failure to read exit code → assume 0 if no errors observed.
721
+ exitCode = 0;
722
+ }
723
+
724
+ // Slice + scrub the marker from stderr output before returning.
725
+ const stdoutOut = globalThis.__nimbusRubyStdout.slice(stdoutStart).join('');
726
+ let stderrOut = globalThis.__nimbusRubyStderr.slice(stderrStart).join('');
727
+ stderrOut = stderrOut.replace(new RegExp(NIMBUS_EXIT_MARKER + '-?\\\\d+\\\\n?', 'g'), '');
728
+
729
+ return {
730
+ exitCode: exitCode,
731
+ stdout: stdoutOut,
732
+ stderr: stderrOut,
733
+ };
734
+ };
735
+
736
+ // ── END: ruby-runner preamble ──────────────────────────────────────
737
+ `;